STM32F0xx Standard Peripherals Firmware Library: stm32f0xx_i2c_cpal_usercallback.c Source File

STM32F0xx Standard Peripherals Library

I2C_TwoBoards/stm32f0xx_i2c_cpal_usercallback.c
Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    I2C/I2C_TwoBoards/stm32f0xx_i2c_cpal_usercallback.c
00004   * @author  MCD Application Team
00005   * @version V1.4.0
00006   * @date    24-July-2014
00007   * @brief   This file provides all the CPAL UserCallback functions.
00008   ******************************************************************************
00009   * @attention
00010   *
00011   * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
00012   *
00013   * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
00014   * You may not use this file except in compliance with the License.
00015   * You may obtain a copy of the License at:
00016   *
00017   *        http://www.st.com/software_license_agreement_liberty_v2
00018   *
00019   * Unless required by applicable law or agreed to in writing, software 
00020   * distributed under the License is distributed on an "AS IS" BASIS, 
00021   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00022   * See the License for the specific language governing permissions and
00023   * limitations under the License.
00024   *
00025   ******************************************************************************
00026   */
00027 
00028 /* Includes ------------------------------------------------------------------*/
00029 #include "main.h"
00030 
00031 /* Private typedef -----------------------------------------------------------*/
00032 /* Private defines -----------------------------------------------------------*/
00033 extern const uint8_t tStateSignal[];
00034 extern const uint8_t tSignal1[];
00035 extern const uint8_t tSignal2[];
00036 extern CPAL_TransferTypeDef  sRxStructure, sTxStructure;
00037 extern uint8_t tRxBuffer[];
00038 extern uint32_t BufferSize;
00039 extern __IO uint32_t ActionState;
00040 extern __IO uint32_t RecieverMode;
00041 
00042 /* Private macro -------------------------------------------------------------*/
00043 /* Private function prototypes -----------------------------------------------*/
00044 extern void Switch_Color(void); 
00045 extern void Switch_ErrorColor(void);
00046 extern uint8_t Buffer_Check(uint8_t* pBuffer, uint8_t* pBuffer1, uint8_t* pBuffer2,  uint8_t* pBuffer3, uint16_t BufferLength);
00047 
00048 /* Private functions ---------------------------------------------------------*/
00049 
00050 
00051 
00052 /*------------------------------------------------------------------------------
00053                      CPAL User Callbacks implementations 
00054 ------------------------------------------------------------------------------*/
00055 
00056 
00057 /*=========== Timeout UserCallback ===========*/
00058 
00059 
00060 /**
00061   * @brief  User callback that manages the Timeout error
00062   * @param  pDevInitStruct
00063   * @retval None.
00064   */
00065 uint32_t CPAL_TIMEOUT_UserCallback(CPAL_InitTypeDef* pDevInitStruct)
00066 {
00067   /* Update CPAL states */
00068   pDevInitStruct->CPAL_State = CPAL_STATE_READY;
00069   pDevInitStruct->wCPAL_DevError = CPAL_I2C_ERR_NONE ;
00070   pDevInitStruct->wCPAL_Timeout  = CPAL_I2C_TIMEOUT_DEFAULT;
00071   
00072   /* DeInitialize CPAL device */
00073   CPAL_I2C_DeInit(pDevInitStruct);  
00074   
00075   /* Initialize CPAL device with the selected parameters */
00076   CPAL_I2C_Init(pDevInitStruct);    
00077     
00078   /* Switch the LCD write color */
00079   Switch_ErrorColor();
00080   
00081   LCD_DisplayStringLine(Line9, (uint8_t*)"  Timeout Recovered ");
00082   
00083   ActionState = ACTION_NONE; 
00084   
00085   return CPAL_PASS;  
00086 }
00087 
00088 
00089 /*=========== Transfer UserCallback ===========*/
00090 
00091 
00092 /**
00093   * @brief  Manages the End of Tx transfer event.
00094   * @param  pDevInitStruct 
00095   * @retval None
00096   */
00097 void CPAL_I2C_TXTC_UserCallback(CPAL_InitTypeDef* pDevInitStruct)
00098 {
00099   STM_EVAL_LEDOff(LED3);  
00100   STM_EVAL_LEDToggle(LED2);
00101      
00102   /* Switch the LCD write color */
00103   Switch_Color(); 
00104   
00105   LCD_DisplayStringLine(Line3, (uint8_t*)"TRANSMIT MODE ACTIVE");
00106   LCD_DisplayStringLine(Line5, (uint8_t*)"   Signal Sent OK   ");
00107   LCD_DisplayStringLine(Line9, MEASSAGE_EMPTY);
00108   
00109   ActionState  = ACTION_NONE;
00110 }
00111 
00112 
00113 /**
00114   * @brief  Manages the End of Rx transfer event.
00115   * @param  pDevInitStruct 
00116   * @retval None
00117   */  
00118 void CPAL_I2C_RXTC_UserCallback(CPAL_InitTypeDef* pDevInitStruct)
00119 {
00120   uint8_t result = 0xFF, i = 0;
00121   
00122   /* Activate the mode receiver only */
00123   RecieverMode = 1;
00124   
00125   /* Switch the LCD write color */
00126   Switch_Color(); 
00127   
00128   LCD_DisplayStringLine(Line3, (uint8_t*)"RECEIVER MODE ACTIVE");
00129   LCD_DisplayStringLine(Line5, MEASSAGE_EMPTY);
00130   LCD_DisplayStringLine(Line9, MEASSAGE_EMPTY);
00131   
00132   STM_EVAL_LEDOff(LED2);  
00133   STM_EVAL_LEDToggle(LED3);
00134     
00135   /* Initialize local Reception structures */
00136   sRxStructure.wNumData = BufferSize;       /* Maximum Number of data to be received */
00137   sRxStructure.pbBuffer = tRxBuffer;        /* Common Rx buffer for all received data */
00138       
00139   /* Check the Received Buffer */
00140   result = Buffer_Check(tRxBuffer, (uint8_t*)tStateSignal, (uint8_t*)tSignal1,(uint8_t*)tSignal2, (uint16_t)BufferSize);
00141     
00142   switch(result)
00143   {
00144     case 0: 
00145       LCD_DisplayStringLine(Line7, (uint8_t*)"  State message OK  ");
00146       break;
00147       
00148     case 1: 
00149       /* Display Reception Complete */
00150       LCD_DisplayStringLine(Line5, (uint8_t*)" Signal1 message OK ");
00151       break;
00152     
00153     case 2:
00154       /* Display Reception Complete */
00155       LCD_DisplayStringLine(Line5, (uint8_t*)" Signal2 message OK ");
00156       break;
00157     
00158     default:  
00159       LCD_DisplayStringLine(Line7, (uint8_t*)"       Failure     ");
00160       break;
00161   }
00162   
00163   /* Reinitialize RXBuffer */
00164   for(i = 0; i < MAX_BUFF_SIZE; i++)
00165   {
00166     tRxBuffer[i]=0;
00167   }
00168 }
00169 
00170 
00171 /**
00172   * @brief  Manages Tx transfer event
00173   * @param  pDevInitStruct
00174   * @retval None
00175   */
00176 /*void CPAL_I2C_TX_UserCallback(CPAL_InitTypeDef* pDevInitStruct)
00177 {
00178 
00179 }*/
00180 
00181 
00182 /**
00183   * @brief  Manages Rx transfer event
00184   * @param  pDevInitStruct
00185   * @retval None
00186   */
00187 /*void CPAL_I2C_RX_UserCallback(CPAL_InitTypeDef* pDevInitStruct)
00188 {
00189 
00190 }*/
00191 
00192 
00193 /**
00194   * @brief  Manages the End of DMA Tx transfer event
00195   * @param  pDevInitStruct
00196   * @retval None
00197   */
00198 /*void CPAL_I2C_DMATXTC_UserCallback(CPAL_InitTypeDef* pDevInitStruct)
00199 {
00200 
00201 }*/
00202 
00203 
00204 /**
00205   * @brief  Manages the Half of DMA Tx transfer event
00206   * @param  pDevInitStruct
00207   * @retval None
00208   */
00209 /*void CPAL_I2C_DMATXHT_UserCallback(CPAL_InitTypeDef* pDevInitStruct)
00210 {
00211 
00212 }*/
00213 
00214 
00215 /**
00216   * @brief  Manages Error of DMA Tx transfer event
00217   * @param  pDevInitStruct
00218   * @retval None
00219   */
00220 /*void CPAL_I2C_DMATXTE_UserCallback(CPAL_InitTypeDef* pDevInitStruct)
00221 {
00222 
00223 }*/
00224 
00225 
00226 /**
00227   * @brief  Manages the End of DMA Rx transfer event
00228   * @param  pDevInitStruct
00229   * @retval None
00230   */
00231 /*void CPAL_I2C_DMARXTC_UserCallback(CPAL_InitTypeDef* pDevInitStruct)
00232 {
00233 
00234 }*/
00235 
00236 
00237 /**
00238   * @brief  Manages the Half of DMA Rx transfer event
00239   * @param  pDevInitStruct
00240   * @retval None
00241   */
00242 /*void CPAL_I2C_DMARXHT_UserCallback(CPAL_InitTypeDef* pDevInitStruct)
00243 {
00244 
00245 }*/
00246 
00247 
00248 /**
00249   * @brief  Manages Error of DMA Rx transfer event
00250   * @param  pDevInitStruct
00251   * @retval None
00252   */
00253 /*void CPAL_I2C_DMARXTE_UserCallback(CPAL_InitTypeDef* pDevInitStruct)
00254 {
00255 
00256 }*/
00257 
00258 
00259 /*=========== Error UserCallback ===========*/
00260 
00261 
00262 /**
00263   * @brief  User callback that manages the I2C device errors.
00264   * @note   Make sure that the define USE_SINGLE_ERROR_CALLBACK is uncommented in
00265   *         the cpal_conf.h file, otherwise this callback will not be functional.
00266   * @param  pDevInitStruct. 
00267   * @param  DeviceError.
00268   * @retval None
00269   */ 
00270 void CPAL_I2C_ERR_UserCallback(CPAL_DevTypeDef pDevInstance, uint32_t DeviceError)
00271 {
00272   /* if an Acknowledge failure error occurred */
00273   if (DeviceError == CPAL_I2C_ERR_AF )
00274   {
00275     LCD_DisplayStringLine(Line9, (uint8_t*)" Slave Not yet Ready");
00276   } 
00277   else
00278   {
00279     LCD_DisplayStringLine(Line9, (uint8_t*)" Device Err occurred ");
00280   }
00281   
00282   /* Update CPAL states */
00283   I2C_DevStructures[pDevInstance]->CPAL_State = CPAL_STATE_READY;
00284   I2C_DevStructures[pDevInstance]->wCPAL_DevError = CPAL_I2C_ERR_NONE;
00285   
00286   /* Deinitialize CPAL device */
00287   CPAL_I2C_DeInit(I2C_DevStructures[pDevInstance]);
00288   
00289   /* Initialize CPAL device with the selected parameters */
00290   CPAL_I2C_Init(I2C_DevStructures[pDevInstance]);    
00291   
00292   /* Switch the LCD write color */
00293   Switch_ErrorColor();
00294   
00295   ActionState = ACTION_NONE;
00296 }
00297 
00298 
00299 /**
00300   * @brief  User callback that manages BERR I2C device errors
00301   * @note   Make sure that the define USE_MULTIPLE_ERROR_CALLBACK is uncommented in
00302   *         the cpal_conf.h file, otherwise this callback will not be functional
00303   * @param  pDevInstance
00304   * @retval None
00305   */
00306 /*void CPAL_I2C_BERR_UserCallback(CPAL_DevTypeDef pDevInstance)
00307 {
00308 
00309 }*/
00310 
00311 
00312 /**
00313   * @brief  User callback that manages ARLO I2C device errors
00314   * @note   Make sure that the define USE_MULTIPLE_ERROR_CALLBACK is uncommented in
00315   *         the cpal_conf.h file, otherwise this callback will not be functional
00316   * @param  pDevInstance
00317   * @retval None
00318   */
00319 /*void CPAL_I2C_ARLO_UserCallback(CPAL_DevTypeDef pDevInstance)
00320 {
00321 
00322 }*/
00323 
00324 
00325 /**
00326   * @brief  User callback that manages OVR I2C device errors
00327   * @note   Make sure that the define USE_MULTIPLE_ERROR_CALLBACK is uncommented in
00328   *         the cpal_conf.h file, otherwise this callback will not be functional
00329   * @param  pDevInstance
00330   * @retval None
00331   */
00332 /*void CPAL_I2C_OVR_UserCallback(CPAL_DevTypeDef pDevInstance)
00333 {
00334 
00335 }*/
00336 
00337 
00338 /**
00339   * @brief  User callback that manages AF I2C device errors.
00340   * @note   Make sure that the define USE_MULTIPLE_ERROR_CALLBACK is uncommented in
00341   *         the cpal_conf.h file, otherwise this callback will not be functional
00342   * @param  pDevInstance
00343   * @retval None
00344   */
00345 /*void CPAL_I2C_AF_UserCallback(CPAL_DevTypeDef pDevInstance)
00346 {
00347 
00348 }*/
00349 
00350 
00351 /*=========== Addressing Mode UserCallback ===========*/
00352 
00353 
00354 /**
00355   * @brief  User callback that manage General Call Addressing mode
00356   * @param  pDevInitStruct
00357   * @retval None
00358   */
00359 /*void CPAL_I2C_GENCALL_UserCallback(CPAL_InitTypeDef* pDevInitStruct)
00360 {
00361 
00362 }*/
00363 
00364 
00365 /**
00366   * @brief  User callback that manage Dual Address Addressing mode
00367   * @param  pDevInitStruct
00368   * @retval None
00369   */
00370 /*void CPAL_I2C_DUALF_UserCallback(CPAL_InitTypeDef* pDevInitStruct)
00371 {
00372 
00373 }*/
00374 
00375 
00376 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
STM32L1xx Standard Peripherals Library: Footer

 

 

 For complete documentation on STM32 Microcontrollers visit www.st.com/STM32