serial.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * File : serial.h
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2009, RT-Thread Development Team
  5. *
  6. * The license and distribution terms for this file may be
  7. * found in the file LICENSE in this distribution or at
  8. * http://www.rt-thread.org/license/LICENSE
  9. *
  10. * Change Logs:
  11. * Date Author Notes
  12. * 2009-01-05 Bernard first version
  13. */
  14. #ifndef __RT_HW_SERIAL_H__
  15. #define __RT_HW_SERIAL_H__
  16. #include <rthw.h>
  17. #include <rtthread.h>
  18. /* STM32F10x library definitions */
  19. #include <stm32f10x.h>
  20. #define UART_DMA_RX_DESCRIPTOR 2
  21. #define UART_DMA_RX_BUFFER_SIZE 16
  22. #define UART_RX_BUFFER_SIZE 64
  23. #define UART_TX_BUFFER_SIZE 64
  24. struct stm32_serial_dma_rx
  25. {
  26. DMA_Channel_TypeDef* dma_channel;
  27. rt_uint8_t rx_buffer[UART_DMA_RX_DESCRIPTOR][UART_RX_BUFFER_SIZE];
  28. rt_uint32_t save_descriptor;
  29. rt_uint32_t read_index, read_descriptor;
  30. rt_bool_t is_full;
  31. };
  32. /* data node for Tx Mode */
  33. struct stm32_serial_data_node
  34. {
  35. rt_uint8_t *data_ptr;
  36. rt_size_t data_size;
  37. struct stm32_serial_data_node *next, *prev;
  38. };
  39. struct stm32_serial_dma_tx
  40. {
  41. DMA_Channel_TypeDef* dma_channel;
  42. struct stm32_serial_data_node *list_head, *list_tail;
  43. };
  44. struct stm32_serial_int_rx
  45. {
  46. rt_uint8_t rx_buffer[UART_RX_BUFFER_SIZE];
  47. rt_uint32_t read_index, save_index;
  48. };
  49. struct stm32_serial_int_tx
  50. {
  51. rt_uint8_t tx_buffer[UART_TX_BUFFER_SIZE];
  52. rt_uint32_t write_index, save_index;
  53. };
  54. struct stm32_serial_device
  55. {
  56. USART_TypeDef* uart_device;
  57. /* rx structure */
  58. struct stm32_serial_int_rx* int_rx;
  59. struct stm32_serial_dma_rx* dma_rx;
  60. /* tx structure */
  61. struct stm32_serial_int_tx* int_tx;
  62. struct stm32_serial_dma_tx* dma_tx;
  63. };
  64. rt_err_t rt_hw_serial_register(rt_device_t device, const char* name, rt_uint32_t flag, struct stm32_serial_device *serial);
  65. void rt_hw_serial_isr(rt_device_t device);
  66. void rt_hw_serial_dma_rx_isr(rt_device_t device);
  67. void rt_hw_serial_dma_tx_isr(rt_device_t device);
  68. #endif