drv_usart.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /***************************************************************************//**
  2. * @file drv_usart.h
  3. * @brief USART driver of RT-Thread RTOS for EFM32
  4. * COPYRIGHT (C) 2011, RT-Thread Development Team
  5. * @author onelife
  6. * @version 0.4 beta
  7. *******************************************************************************
  8. * @section License
  9. * The license and distribution terms for this file may be found in the file
  10. * LICENSE in this distribution or at http://www.rt-thread.org/license/LICENSE
  11. *******************************************************************************
  12. * @section Change Logs
  13. * Date Author Notes
  14. * 2010-12-22 onelife Initial creation for EFM32
  15. * 2011-06-27 onelife Fix a bug when using compiler optimization
  16. * 2011-07-26 onelife Add lock (semaphore) to prevent simultaneously
  17. * access
  18. ******************************************************************************/
  19. #ifndef __DRV_USART_H__
  20. #define __DRV_USART_H__
  21. /* Includes ------------------------------------------------------------------*/
  22. /* Exported types ------------------------------------------------------------*/
  23. struct efm32_usart_int_mode_t
  24. {
  25. rt_uint8_t *data_ptr;
  26. rt_uint8_t data_size;
  27. rt_uint32_t read_index, save_index;
  28. };
  29. struct efm32_usart_dma_mode_t
  30. {
  31. /* DMA Channel */
  32. rt_uint32_t dma_channel;
  33. /* buffer info */
  34. rt_uint32_t *data_ptr;
  35. rt_uint8_t data_size;
  36. };
  37. struct efm32_usart_device_t
  38. {
  39. /* Counter */
  40. rt_uint32_t counter;
  41. /* Lock */
  42. struct rt_semaphore *lock;
  43. /* Unit number */
  44. rt_uint8_t unit;
  45. /* State */
  46. volatile rt_uint8_t state;
  47. /* Pointer to USART device structure */
  48. USART_TypeDef *usart_device;
  49. /* Pointer to RX structure */
  50. void *rx_mode;
  51. /* Pointer to TX structure */
  52. void *tx_mode;
  53. };
  54. /* Exported constants --------------------------------------------------------*/
  55. /* Exported macro ------------------------------------------------------------*/
  56. #define USART_WAIT_TIME_TX (RT_TICK_PER_SECOND / 100 * 3)
  57. #define USART_STATE_CONSOLE (1 << 0)
  58. #define USART_STATE_SYNC (1 << 1)
  59. #define USART_STATE_MASTER (1 << 2)
  60. #define USART_STATE_AUTOCS (1 << 3)
  61. #define USART_STATE_TX_BUSY (1 << 4)
  62. #define USART_STATE_RX_BUSY (1 << 5)
  63. /* Exported functions ------------------------------------------------------- */
  64. void rt_hw_usart_init(void);
  65. #endif /* __DRV_USART_H__ */