os_viewc.c
上传用户:yj_qqy
上传日期:2017-01-28
资源大小:2911k
文件大小:14k
源码类别:

uCOS

开发平台:

C/C++

  1. /*
  2. *********************************************************************************************************
  3. *                                               uC/OS-View
  4. *
  5. *                                 (c) Copyright 2005, Micrium, Weston, FL
  6. *                                           All Rights Reserved
  7. *
  8. *                                            ST STM32 (Cortex-M3)
  9. *                                             IAR C Compiler
  10. *
  11. *
  12. * Filename   : OS_VIEWc.C
  13. * Version    : V1.20
  14. * Programmer : Jean J. Labrosse
  15. *********************************************************************************************************
  16. */
  17. #include <includes.h>
  18. #if OS_VIEW_MODULE == DEF_ENABLED
  19. /*
  20. *********************************************************************************************************
  21. *                                              CONSTANTS
  22. *********************************************************************************************************
  23. */
  24. #define  BIT0      0x01
  25. #define  BIT1      0x02
  26. #define  BIT2      0x04
  27. #define  BIT3      0x08
  28. #define  BIT4      0x10
  29. #define  BIT5      0x20
  30. #define  BIT6      0x40
  31. #define  BIT7      0x80
  32. static void  OSView_RxTxISRHandler (void);
  33. /*$PAGE*/
  34. /*
  35. *********************************************************************************************************
  36. *                                           EXIT uC/OS-View
  37. *
  38. * Description: This function is called if your target needs to 'uninstall' uC/OS-View.
  39. *
  40. * Note(s)    :
  41. *********************************************************************************************************
  42. */
  43. void  OSView_Exit (void)
  44. {
  45. }
  46. /*
  47. *********************************************************************************************************
  48. *                                           Obtain CPU name
  49. *********************************************************************************************************
  50. */
  51. void  OSView_GetCPUName (INT8U *s)
  52. {
  53.     INT8U  cpu_clk_freq;
  54.     cpu_clk_freq = (INT8U)(BSP_CPU_ClkFreq() / 1000000L);
  55.     strcpy((char *)s, "ST STM32 (Cortex-M3) (xx MHz)");
  56.     s[22] = cpu_clk_freq / 10 + '0';
  57.     s[23] = cpu_clk_freq % 10 + '0';
  58. }
  59. /*
  60. *********************************************************************************************************
  61. *                                  Obtain Interrupt Stack information
  62. *********************************************************************************************************
  63. */
  64. INT32U  OSView_GetIntStkBase (void)
  65. {
  66.     return (0);                                       /* We are not using an ISR stack                 */
  67. }
  68. INT32U  OSView_GetIntStkSize (void)
  69. {
  70.     return (0);                                       /* We are not using an ISR stack                 */
  71. }
  72. /*$PAGE*/
  73. /*
  74. *********************************************************************************************************
  75. *                                    INITIALISE uC/OS-View COM PORT
  76. *
  77. * Description: Initialize the hardware required for the OS to run. This will work on any target hardware,
  78. *              but may have to be tailored a little (regarding the clock frequency). Of course the same
  79. *              holds true if for some reason you choose to use another timer.
  80. *
  81. * Note(s)    : 1) This function assumes that a free running timer has been initialized.  The timer can
  82. *                 either be a 16 bits or 32 bits timer.  Your application needs to provide a function
  83. *                 called OSView_TmrRd() that reads the current counts of this timer.  The free running
  84. *                 timer is initialized by the BSP function OSView_TmrInit().
  85. *********************************************************************************************************
  86. */
  87. void  OSView_InitTarget (INT32U baud_rate)
  88. {
  89.     GPIO_InitTypeDef        gpio_init;
  90.     USART_InitTypeDef       usart_init;
  91.     USART_ClockInitTypeDef  usart_clk_init;
  92. OSView_TmrInit();                                    /* Initialize the free running timer          */
  93.                                                                 /* ----------------- INIT USART STRUCT ---------------- */
  94.     usart_init.USART_BaudRate            = baud_rate;
  95.     usart_init.USART_WordLength          = USART_WordLength_8b;
  96.     usart_init.USART_StopBits            = USART_StopBits_1;
  97.     usart_init.USART_Parity              = USART_Parity_No ;
  98.     usart_init.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
  99.     usart_init.USART_Mode                = USART_Mode_Rx | USART_Mode_Tx;
  100.     usart_clk_init.USART_Clock           = USART_Clock_Disable;
  101.     usart_clk_init.USART_CPOL            = USART_CPOL_Low;
  102.     usart_clk_init.USART_CPHA            = USART_CPHA_2Edge;
  103.     usart_clk_init.USART_LastBit         = USART_LastBit_Disable;
  104. #if (OS_VIEW_COMM_SEL == OS_VIEW_UART_1)
  105.     BSP_PeriphEn(BSP_PERIPH_ID_USART1);
  106.                                                                 /* ----------------- SETUP USART1 GPIO ---------------- */
  107.     BSP_PeriphEn(BSP_PERIPH_ID_IOPA);
  108.                                                                 /* Configure GPIOA.9 as push-pull                       */
  109.     gpio_init.GPIO_Pin   = GPIO_Pin_9;
  110.     gpio_init.GPIO_Speed = GPIO_Speed_50MHz;
  111.     gpio_init.GPIO_Mode  = GPIO_Mode_AF_PP;
  112.     GPIO_Init(GPIOA, &gpio_init);
  113.                                                                 /* Configure GPIOA.10 as input floating                 */
  114.     gpio_init.GPIO_Pin   = GPIO_Pin_10;
  115.     gpio_init.GPIO_Mode  = GPIO_Mode_IN_FLOATING;
  116.     GPIO_Init(GPIOA, &gpio_init);
  117.                                                                 /* ------------------ SETUP USART1 -------------------- */
  118.     USART_Init(USART1, &usart_init);
  119.     USART_ClockInit(USART1, &usart_clk_init);
  120.     USART_Cmd(USART1, ENABLE);
  121.     BSP_IntVectSet(BSP_INT_ID_USART1, OSView_RxTxISRHandler);
  122.     BSP_IntEn(BSP_INT_ID_USART1);
  123. #endif
  124. #if (OS_VIEW_COMM_SEL == OS_VIEW_UART_2)
  125.     BSP_PeriphEn(BSP_PERIPH_ID_USART2);
  126.                                                                 /* ----------------- SETUP USART2 GPIO ---------------- */
  127.     BSP_PeriphEn(BSP_PERIPH_ID_IOPA);
  128.                                                                 /* Configure GPIOA.2 as push-pull                       */
  129.     gpio_init.GPIO_Pin   = GPIO_Pin_2;
  130.     gpio_init.GPIO_Speed = GPIO_Speed_50MHz;
  131.     gpio_init.GPIO_Mode  = GPIO_Mode_AF_PP;
  132.     GPIO_Init(GPIOA, &gpio_init);
  133.                                                                 /* Configure GPIOA.3 as input floating                  */
  134.     gpio_init.GPIO_Pin   = GPIO_Pin_3;
  135.     gpio_init.GPIO_Mode  = GPIO_Mode_IN_FLOATING;
  136.     GPIO_Init(GPIOA, &gpio_init);
  137.                                                                 /* ------------------ SETUP USART2 -------------------- */
  138.     USART_Init(USART2, &usart_init);
  139.     USART_ClockInit(USART2, &usart_clk_init);
  140.     USART_Cmd(USART2, ENABLE);
  141.     BSP_IntVectSet(BSP_INT_ID_USART2, OSView_RxTxISRHandler);
  142.     BSP_IntEn(BSP_INT_ID_USART2);
  143. #endif
  144. #if (OS_VIEW_COMM_SEL == OS_VIEW_UART_3)
  145.     BSP_PeriphEn(BSP_PERIPH_ID_USART3);
  146.                                                                 /* ----------------- SETUP USART3 GPIO ---------------- */
  147.     BSP_PeriphEn(BSP_PERIPH_ID_IOPB);
  148.                                                                 /* Configure GPIOB.10 as push-pull                      */
  149.     gpio_init.GPIO_Pin   = GPIO_Pin_10;
  150.     gpio_init.GPIO_Speed = GPIO_Speed_50MHz;
  151.     gpio_init.GPIO_Mode  = GPIO_Mode_AF_PP;
  152.     GPIO_Init(GPIOB, &gpio_init);
  153.                                                                 /* Configure GPIOB.11 as input floating                 */
  154.     gpio_init.GPIO_Pin   = GPIO_Pin_11;
  155.     gpio_init.GPIO_Mode  = GPIO_Mode_IN_FLOATING;
  156.     GPIO_Init(GPIOB, &gpio_init);
  157.                                                                 /* ------------------ SETUP USART3 -------------------- */
  158.     USART_Init(USART3, &usart_init);
  159.     USART_ClockInit(USART3, &usart_clk_init);
  160.     USART_Cmd(USART3, ENABLE);
  161.     BSP_IntVectSet(BSP_INT_ID_USART3, OSView_RxTxISRHandler);
  162.     BSP_IntEn(BSP_INT_ID_USART3);
  163. #endif
  164. }
  165. /*$PAGE*/
  166. /*
  167. *********************************************************************************************************
  168. *                                       Disable Rx Interrupts
  169. *********************************************************************************************************
  170. */
  171. void  OSView_RxIntDis (void)
  172. {
  173. #if (OS_VIEW_COMM_SEL == OS_VIEW_UART_1)
  174.     USART_ITConfig(USART1, USART_IT_RXNE, DISABLE);
  175. #endif
  176. #if (OS_VIEW_COMM_SEL == OS_VIEW_UART_2)
  177.     USART_ITConfig(USART2, USART_IT_RXNE, DISABLE);
  178. #endif
  179. #if (OS_VIEW_COMM_SEL == OS_VIEW_UART_3)
  180.     USART_ITConfig(USART3, USART_IT_RXNE, DISABLE);
  181. #endif
  182. }
  183. /*
  184. *********************************************************************************************************
  185. *                                       Enable Rx Interrupts
  186. *********************************************************************************************************
  187. */
  188. void  OSView_RxIntEn (void)
  189. {
  190. #if (OS_VIEW_COMM_SEL == OS_VIEW_UART_1)
  191.     USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
  192. #endif
  193. #if (OS_VIEW_COMM_SEL == OS_VIEW_UART_2)
  194.     USART_ITConfig(USART2, USART_IT_RXNE, ENABLE);
  195. #endif
  196. #if (OS_VIEW_COMM_SEL == OS_VIEW_UART_3)
  197.     USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);
  198. #endif
  199. }
  200. /*
  201. *********************************************************************************************************
  202. *                                 Rx Communication handler for uC/OS-View
  203. *
  204. * Description: This function is called by OSView_RxISR (see OS_VIEWa.ASM) to process a received
  205. *              character interrupt.
  206. *
  207. * Note(s)    : This adaptation of uC/OS-View assumes that a 'combined' interrupt is generated by the UART
  208. *              and thus this function is not needed.
  209. *********************************************************************************************************
  210. */
  211. void  OSView_RxISRHandler (void)
  212. {
  213. }
  214. /*
  215. *********************************************************************************************************
  216. *                                Rx/Tx Communication handler for uC/OS-View
  217. *
  218. * Description: This function is NOT called because the M16C has a separate Rx and Tx ISR.
  219. *********************************************************************************************************
  220. */
  221. static void  OSView_RxTxISRHandler (void)
  222. {
  223.     USART_TypeDef  *usart;
  224.     CPU_INT08U      rx_data;
  225.     CPU_SR          cpu_sr;
  226.     CPU_CRITICAL_ENTER();                                       /* Tell uC/OS-II that we are starting an ISR            */
  227.     OSIntNesting++;
  228.     CPU_CRITICAL_EXIT();
  229. #if   (OS_VIEW_COMM_SEL == OS_VIEW_UART_1)
  230.     usart = USART1;
  231. #elif (OS_VIEW_COMM_SEL == OS_VIEW_UART_2)
  232.     usart = USART2;
  233. #elif (OS_VIEW_COMM_SEL == OS_VIEW_UART_3)
  234.     usart = USART3;
  235. #else
  236.     OSIntExit();
  237.     return;
  238. #endif
  239.     if (USART_GetITStatus(usart, USART_IT_RXNE) != RESET) {
  240.         rx_data = USART_ReceiveData(usart) & 0xFF;              /* Read one byte from the receive data register         */
  241.         OSView_RxHandler(rx_data);
  242.         USART_ClearITPendingBit(usart, USART_IT_RXNE);          /* Clear the USART1 Receive interrupt                   */
  243.     }
  244.     if (USART_GetITStatus(usart, USART_IT_TXE) != RESET) {
  245.         OSView_TxHandler();
  246.         USART_ClearITPendingBit(usart, USART_IT_TXE);           /* Clear the USART1 transmit interrupt                  */
  247.     }
  248.     OSIntExit();                                                /* Tell uC/OS-II that we are leaving the ISR            */
  249. }
  250. /*$PAGE*/
  251. /*
  252. *********************************************************************************************************
  253. *                                      Communication for uC/OS-View
  254. *
  255. * Description: Send 1 character to COM Port
  256. *********************************************************************************************************
  257. */
  258. void  OSView_Tx1 (INT8U c)
  259. {
  260. #if OS_VIEW_COMM_SEL == OS_VIEW_UART_1
  261. USART_SendData(USART1, c);
  262. #endif
  263. #if OS_VIEW_COMM_SEL == OS_VIEW_UART_2
  264. USART_SendData(USART2, c);
  265. #endif
  266. #if OS_VIEW_COMM_SEL == OS_VIEW_UART_3
  267. USART_SendData(USART3, c);
  268. #endif
  269. }
  270. /*$PAGE*/
  271. /*
  272. *********************************************************************************************************
  273. *                                       Disable Tx Interrupts
  274. *********************************************************************************************************
  275. */
  276. void  OSView_TxIntDis (void)
  277. {
  278. #if (OS_VIEW_COMM_SEL == OS_VIEW_UART_1)
  279.     USART_ITConfig(USART1, USART_IT_TXE, DISABLE);
  280. #endif
  281. #if (OS_VIEW_COMM_SEL == OS_VIEW_UART_2)
  282.     USART_ITConfig(USART2, USART_IT_TXE, DISABLE);
  283. #endif
  284. #if (OS_VIEW_COMM_SEL == OS_VIEW_UART_3)
  285.     USART_ITConfig(USART3, USART_IT_TXE, DISABLE);
  286. #endif
  287. }
  288. /*
  289. *********************************************************************************************************
  290. *                                       Enable Tx Interrupts
  291. *********************************************************************************************************
  292. */
  293. void  OSView_TxIntEn (void)
  294. {
  295. #if (OS_VIEW_COMM_SEL == OS_VIEW_UART_1)
  296.     USART_ITConfig(USART1, USART_IT_TXE, ENABLE);
  297. #endif
  298. #if (OS_VIEW_COMM_SEL == OS_VIEW_UART_2)
  299.     USART_ITConfig(USART2, USART_IT_TXE, ENABLE);
  300. #endif
  301. #if (OS_VIEW_COMM_SEL == OS_VIEW_UART_3)
  302.     USART_ITConfig(USART3, USART_IT_TXE, ENABLE);
  303. #endif
  304. }
  305. #endif