PageRenderTime 26ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/paparazzi/sw/airborne/arch/stm32/mcu_periph/uart_arch.h

https://github.com/agreee45/SNUT
C Header | 186 lines | 114 code | 45 blank | 27 comment | 7 complexity | 85304185be3d283b3e49e2eced63205e MD5 | raw file
  1. /*
  2. * $Id$
  3. *
  4. * Copyright (C) 2009-2010 The Paparazzi Team
  5. *
  6. * This file is part of paparazzi.
  7. *
  8. * paparazzi is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2, or (at your option)
  11. * any later version.
  12. *
  13. * paparazzi is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with paparazzi; see the file COPYING. If not, write to
  20. * the Free Software Foundation, 59 Temple Place - Suite 330,
  21. * Boston, MA 02111-1307, USA.
  22. */
  23. /*
  24. *\brief STM32 usart functions
  25. *
  26. */
  27. #ifndef STM32_UART_ARCH_H
  28. #define STM32_UART_ARCH_H
  29. #include "std.h"
  30. #define B9600 9600
  31. #define B38400 38400
  32. #define B57600 57600
  33. #define B115200 115200
  34. /* sort out the problem of UART5 already defined in stm32.h */
  35. #define USART5 ((USART_TypeDef *) UART5_BASE)
  36. #undef UART5
  37. #define UART1_TxPin GPIO_Pin_9
  38. #define UART2_TxPin GPIO_Pin_2
  39. #define UART3_TxPin GPIO_Pin_10
  40. #define UART1_RxPin GPIO_Pin_10
  41. #define UART2_RxPin GPIO_Pin_3
  42. #define UART3_RxPin GPIO_Pin_11
  43. #define UART5_RxPin GPIO_Pin_2
  44. #define UART1_TxPort GPIOA
  45. #define UART2_TxPort GPIOA
  46. #define UART3_TxPort GPIOC
  47. #define UART1_RxPort GPIOA
  48. #define UART2_RxPort GPIOA
  49. #define UART3_RxPort GPIOC
  50. #define UART5_RxPort GPIOD
  51. #define UART1_Periph RCC_APB2Periph_GPIOA
  52. #define UART2_Periph RCC_APB2Periph_GPIOA
  53. #define UART3_Periph RCC_APB2Periph_GPIOC
  54. #define UART5_Periph RCC_APB2Periph_GPIOD
  55. #define UART1_UartPeriph RCC_APB2Periph_USART1
  56. #define UART2_UartPeriph RCC_APB1Periph_USART2
  57. #define UART3_UartPeriph RCC_APB1Periph_USART3
  58. #define UART5_UartPeriph RCC_APB1Periph_UART5
  59. #define UART1_remap {}
  60. #define UART2_remap {}
  61. #define UART3_remap {RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE); \
  62. GPIO_PinRemapConfig(GPIO_PartialRemap_USART3, ENABLE);}
  63. #define UART5_remap {}
  64. #define UART1_clk(_periph, _val) RCC_APB2PeriphClockCmd(_periph, _val)
  65. #define UART2_clk(_periph, _val) RCC_APB1PeriphClockCmd(_periph, _val)
  66. #define UART3_clk(_periph, _val) RCC_APB1PeriphClockCmd(_periph, _val);
  67. #define UART5_clk(_periph, _val) RCC_APB1PeriphClockCmd(_periph, _val)
  68. #define Uart1_init uart1_init()
  69. #define Uart2_init uart2_init()
  70. #define Uart3_init uart3_init()
  71. #define Uart5_init uart5_init()
  72. #define UART1_irq_handler usart1_irq_handler
  73. #define UART2_irq_handler usart2_irq_handler
  74. #define UART3_irq_handler usart3_irq_handler
  75. #define UART5_irq_handler usart5_irq_handler
  76. #define UART1_IRQn USART1_IRQn
  77. #define UART2_IRQn USART2_IRQn
  78. #define UART3_IRQn USART3_IRQn
  79. #define UART1_reg USART1
  80. #define UART2_reg USART2
  81. #define UART3_reg USART3
  82. #define UART5_reg USART5
  83. #if defined USE_UART1 || OVERRIDE_UART1_IRQ_HANDLER
  84. extern void usart1_irq_handler(void);
  85. #endif
  86. #if defined USE_UART2 || OVERRIDE_UART2_IRQ_HANDLER
  87. extern void usart2_irq_handler(void);
  88. #endif
  89. #if defined USE_UART3 || OVERRIDE_UART3_IRQ_HANDLER
  90. extern void usart3_irq_handler(void);
  91. #endif
  92. #if defined USE_UART5 || OVERRIDE_UART5_IRQ_HANDLER
  93. extern void usart5_irq_handler(void);
  94. #endif
  95. #ifdef USE_UART1
  96. #define UART1_RX_BUFFER_SIZE 128
  97. #define UART1_TX_BUFFER_SIZE 128
  98. extern volatile uint16_t uart1_rx_insert_idx, uart1_rx_extract_idx;
  99. extern uint8_t uart1_rx_buffer[UART1_RX_BUFFER_SIZE];
  100. extern volatile uint16_t uart1_tx_insert_idx, uart1_tx_extract_idx;
  101. extern volatile bool_t uart1_tx_running;
  102. extern uint8_t uart1_tx_buffer[UART1_TX_BUFFER_SIZE];
  103. #define Uart1ChAvailable() (uart1_rx_insert_idx != uart1_rx_extract_idx)
  104. #define Uart1Getch() ({ \
  105. uint8_t ret = uart1_rx_buffer[uart1_rx_extract_idx]; \
  106. uart1_rx_extract_idx = (uart1_rx_extract_idx + 1)%UART1_RX_BUFFER_SIZE; \
  107. ret; \
  108. })
  109. #endif /* USE_UART1 */
  110. #ifdef USE_UART2
  111. #define UART2_RX_BUFFER_SIZE 128
  112. #define UART2_TX_BUFFER_SIZE 128
  113. extern volatile uint16_t uart2_rx_insert_idx, uart2_rx_extract_idx;
  114. extern uint8_t uart2_rx_buffer[UART2_RX_BUFFER_SIZE];
  115. extern volatile uint16_t uart2_tx_insert_idx, uart2_tx_extract_idx;
  116. extern volatile bool_t uart2_tx_running;
  117. extern uint8_t uart2_tx_buffer[UART2_TX_BUFFER_SIZE];
  118. #define Uart2ChAvailable() (uart2_rx_insert_idx != uart2_rx_extract_idx)
  119. #define Uart2Getch() ({ \
  120. uint8_t ret = uart2_rx_buffer[uart2_rx_extract_idx]; \
  121. uart2_rx_extract_idx = (uart2_rx_extract_idx + 1)%UART2_RX_BUFFER_SIZE; \
  122. ret; \
  123. })
  124. #endif /* USE_UART2 */
  125. #ifdef USE_UART3
  126. #define UART3_RX_BUFFER_SIZE 128
  127. #define UART3_TX_BUFFER_SIZE 128
  128. extern volatile uint16_t uart3_rx_insert_idx, uart3_rx_extract_idx;
  129. extern uint8_t uart3_rx_buffer[UART3_RX_BUFFER_SIZE];
  130. extern volatile uint16_t uart3_tx_insert_idx, uart3_tx_extract_idx;
  131. extern volatile bool_t uart3_tx_running;
  132. extern uint8_t uart3_tx_buffer[UART3_TX_BUFFER_SIZE];
  133. #define Uart3ChAvailable() (uart3_rx_insert_idx != uart3_rx_extract_idx)
  134. #define Uart3Getch() ({ \
  135. uint8_t ret = uart3_rx_buffer[uart3_rx_extract_idx]; \
  136. uart3_rx_extract_idx = (uart3_rx_extract_idx + 1)%UART3_RX_BUFFER_SIZE; \
  137. ret; \
  138. })
  139. #endif /* USE_UART3 */
  140. void uart_init( void );
  141. #endif /* STM32_UART_ARCH_H */