STM32F10x_StdPeriph_Examples/CEC/main.c

Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    CEC/main.c 
00004   * @author  MCD Application Team
00005   * @version V3.4.0
00006   * @date    10/15/2010
00007   * @brief   Main program body
00008   ******************************************************************************
00009   * @copy
00010   *
00011   * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
00012   * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
00013   * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
00014   * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
00015   * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
00016   * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
00017   *
00018   * <h2><center>&copy; COPYRIGHT 2010 STMicroelectronics</center></h2>
00019   */ 
00020 
00021 /* Includes ------------------------------------------------------------------*/
00022 #include "stm32f10x.h"
00023 #include "stm32_eval.h"
00024 
00025 /** @addtogroup STM32F10x_StdPeriph_Examples
00026   * @{
00027   */
00028 
00029 /** @addtogroup CEC_Example
00030   * @{
00031   */  
00032 
00033 
00034 /* Private typedef -----------------------------------------------------------*/
00035 typedef enum {FAILED = 0, PASSED = !FAILED} TestStatus;
00036 
00037 /* Private define ------------------------------------------------------------*/
00038 /* Private macro -------------------------------------------------------------*/
00039 /* Private variables ---------------------------------------------------------*/
00040 CEC_InitTypeDef CEC_InitStructure;
00041 
00042 uint8_t ByteNumber = 10;
00043 volatile TestStatus TransferStatus = FAILED;
00044 extern uint8_t TransmitBuffer[10];
00045 extern uint8_t ReceiveBuffer[10];
00046 extern __IO uint8_t ReceivedFrame;
00047 
00048 /* Private function prototypes -----------------------------------------------*/
00049 void RCC_Configuration(void);
00050 void NVIC_Configuration(void);
00051 void GPIO_Configuration(void);
00052 TestStatus Buffercmp(uint8_t* pBuffer1, uint8_t* pBuffer2, uint16_t BufferLength);
00053   
00054 /* Private functions ---------------------------------------------------------*/
00055 
00056 /**
00057   * @brief  Main program
00058   * @param  None
00059   * @retval None
00060   */
00061 int main(void)
00062 {
00063   /*!< At this stage the microcontroller clock setting is already configured, 
00064        this is done through SystemInit() function which is called from startup
00065        file (startup_stm32f10x_xx.s) before to branch to application main.
00066        To reconfigure the default setting of SystemInit() function, refer to
00067        system_stm32f10x.c file
00068      */     
00069        
00070   /* RCC configuration */
00071   RCC_Configuration();
00072 
00073   /* NVIC configuration */
00074   NVIC_Configuration();
00075 
00076   /* GPIO configuration */
00077   GPIO_Configuration();
00078 
00079   /* Configure the CEC peripheral */
00080   CEC_InitStructure.CEC_BitTimingMode = CEC_BitTimingStdMode;
00081   CEC_InitStructure.CEC_BitPeriodMode = CEC_BitPeriodStdMode;
00082   CEC_Init(&CEC_InitStructure);
00083 
00084   /* Set Prescaler value for APB1 clock PCLK1 = 24MHz */ 
00085   CEC_SetPrescaler(0x4AF);
00086 
00087   /* Set the CEC initiator address */
00088   CEC_OwnAddressConfig(MY_DEVICE_ADDRESS);
00089   
00090   /* Activate CEC interrupts associated to the set of RBTF,RERR, TBTF, TERR flags */
00091   CEC_ITConfig(ENABLE);
00092 
00093   /* Enable CEC */
00094   CEC_Cmd(ENABLE);
00095 
00096   /* If a frame has been received */
00097   while(ReceivedFrame == 0)
00098   {
00099   }
00100   
00101   /* Check the received data with the send ones */
00102   TransferStatus = Buffercmp(TransmitBuffer, ReceiveBuffer, ByteNumber);
00103   /* TransferStatus = PASSED, if the data transmitted from CEC Device1 and  
00104      received by CEC Device2 are the same */
00105   /* TransferStatus = FAILED, if the data transmitted from CEC Device1 and 
00106      received by CEC Device2 are different */
00107  
00108   if (TransferStatus == PASSED)
00109   { 
00110     /* OK */
00111     /* Turn on LED1 */
00112     STM_EVAL_LEDOn(LED1);
00113   }
00114   else
00115   { 
00116     /* KO */
00117     /* Turn on LED2 */
00118     STM_EVAL_LEDOn(LED2);
00119   }
00120   while(1)
00121   {
00122   }
00123 }
00124 
00125 /**
00126   * @brief  Configures the different system clocks.
00127   * @param  None
00128   * @retval None
00129   */
00130 void RCC_Configuration(void)
00131 {
00132   /* Enable CEC clock */
00133   RCC_APB1PeriphClockCmd(RCC_APB1Periph_CEC, ENABLE);
00134 
00135   /* Initialize LEDs and Key Button available on STM32F100B-EVAL board ***/
00136   /* Configure LED1, LED2, LED3 and LED4 */
00137   STM_EVAL_LEDInit(LED1);
00138   STM_EVAL_LEDInit(LED2);
00139   STM_EVAL_LEDInit(LED3);
00140   STM_EVAL_LEDInit(LED4);
00141 
00142   /* Configure the Key Push button and its associated EXTI Line */
00143   STM_EVAL_PBInit(Button_KEY, Mode_EXTI);
00144 }
00145 
00146 /**
00147   * @brief  Configures the different NVIC interrupts.
00148   * @param  None
00149   * @retval None
00150   */
00151 void NVIC_Configuration(void)
00152 {
00153   NVIC_InitTypeDef NVIC_InitStructure;
00154 
00155   /* Configure two bits for preemption priority */
00156   NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
00157 
00158   /* Enable the CEC global Interrupt (with higher priority) */
00159   NVIC_InitStructure.NVIC_IRQChannel = CEC_IRQn;
00160   NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
00161   NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
00162   NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
00163   NVIC_Init(&NVIC_InitStructure);
00164 }
00165 
00166 /**
00167   * @brief  Configures the different GPIO ports.
00168   * @param  None
00169   * @retval None
00170   */
00171 void GPIO_Configuration(void)
00172 {
00173   GPIO_InitTypeDef GPIO_InitStructure;
00174 
00175   /* Enable GPIOB  clocks */
00176   RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
00177  
00178   /* Configure GPIOB Pin 8 (CEC line) as Output open drain */
00179   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
00180   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
00181   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_OD;
00182   GPIO_Init(GPIOB, &GPIO_InitStructure);
00183 }
00184 
00185 /**
00186   * @brief  Compares two buffers.
00187   * @param  pBuffer1, pBuffer2: buffers to be compared.
00188   * @param  BufferLength: buffer's length
00189   * @retval PASSED: pBuffer1 identical to pBuffer2
00190   *         FAILED: pBuffer1 differs from pBuffer2
00191   */
00192 TestStatus Buffercmp(uint8_t* pBuffer1, uint8_t* pBuffer2, uint16_t BufferLength)
00193 {
00194   while(BufferLength--)
00195   {
00196     if(*pBuffer1 != *pBuffer2)
00197     {
00198       return FAILED;
00199     }
00200     
00201     pBuffer1++;
00202     pBuffer2++;
00203   }
00204 
00205   return PASSED;  
00206 }
00207 
00208 #ifdef  USE_FULL_ASSERT
00209 
00210 /**
00211   * @brief  Reports the name of the source file and the source line number
00212   *         where the assert_param error has occurred.
00213   * @param  file: pointer to the source file name
00214   * @param  line: assert_param error line source number
00215   * @retval None
00216   */
00217 void assert_failed(uint8_t* file, uint32_t line)
00218 {
00219   /* User can add his own implementation to report the file name and line number,
00220      ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
00221 
00222   /* Infinite loop */
00223   while (1)
00224   {
00225   }
00226 }
00227 #endif
00228 
00229 /**
00230   * @}
00231   */ 
00232 
00233 /**
00234   * @}
00235   */ 
00236 
00237 /******************* (C) COPYRIGHT 2010 STMicroelectronics *****END OF FILE****/
STM32F10x Standard Peripherals Library: Footer

 

 

 

      For complete documentation on STM32(CORTEX M3) 32-bit Microcontrollers platform visit  www.st.com/STM32