serial.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * File : serial.h
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2009 - 2010, 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. * 2010-03-29 Bernard remove interrupt tx and DMA rx mode.
  14. */
  15. #ifndef __RT_HW_SERIAL_H__
  16. #define __RT_HW_SERIAL_H__
  17. #include <rthw.h>
  18. #include <rtthread.h>
  19. /* STM32F10x library definitions */
  20. #include <stm32f10x.h>
  21. #define UART_RX_BUFFER_SIZE 64
  22. #define UART_TX_DMA_NODE_SIZE 4
  23. /* data node for Tx Mode */
  24. struct stm32_serial_data_node
  25. {
  26. rt_uint8_t *data_ptr;
  27. rt_size_t data_size;
  28. struct stm32_serial_data_node *next, *prev;
  29. };
  30. struct stm32_serial_dma_tx
  31. {
  32. /* DMA Channel */
  33. DMA_Channel_TypeDef* dma_channel;
  34. /* data list head and tail */
  35. struct stm32_serial_data_node *list_head, *list_tail;
  36. /* data node memory pool */
  37. struct rt_mempool data_node_mp;
  38. rt_uint8_t data_node_mem_pool[UART_TX_DMA_NODE_SIZE *
  39. (sizeof(struct stm32_serial_data_node) + sizeof(void*))];
  40. };
  41. struct stm32_serial_int_rx
  42. {
  43. rt_uint8_t rx_buffer[UART_RX_BUFFER_SIZE];
  44. rt_uint32_t read_index, save_index;
  45. };
  46. struct stm32_serial_device
  47. {
  48. USART_TypeDef* uart_device;
  49. /* rx structure */
  50. struct stm32_serial_int_rx* int_rx;
  51. /* tx structure */
  52. struct stm32_serial_dma_tx* dma_tx;
  53. };
  54. rt_err_t rt_hw_serial_register(rt_device_t device, const char* name, rt_uint32_t flag, struct stm32_serial_device *serial);
  55. void rt_hw_serial_isr(rt_device_t device);
  56. void rt_hw_serial_dma_tx_isr(rt_device_t device);
  57. #endif