Subversion Repositories libSerial

Rev

Rev 12 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. /*
  2.  * serial.h
  3.  *
  4.  *  Created on: 4 Jan 2016
  5.  *      Author: Mike
  6.  */
  7.  
  8. #pragma once
  9.  
  10. #include "main.h"
  11.  
  12.  
  13. typedef struct
  14. {
  15.         /// @brief UART handle
  16.         UART_HandleTypeDef *Handle;
  17.         /// @brief Locally maintained transmit buffer
  18.         volatile uint8_t tx_usart_buff[TX_USART_BUFF_SIZ];
  19.         volatile unsigned int tx_usart_in_Ptr;
  20.         volatile unsigned int tx_usart_out_Ptr;
  21.         volatile unsigned int tx_usart_overruns;
  22.         /// @brief Set when the usart is transmitting
  23.         volatile uint8_t tx_usart_running;
  24.        
  25.         /// @brief Locally maintained receive buffer
  26.         volatile uint8_t rx_usart_buff[RX_USART_BUFF_SIZ];
  27.         volatile unsigned int rx_usart_in_Ptr;
  28.         volatile unsigned int rx_usart_out_Ptr;
  29.         /// @brief Set when the receiver buffer is full
  30.         volatile uint8_t rx_usart_buffer_full;
  31. } usart_ctl;
  32.  
  33.  
  34.  
  35. #if defined SERIAL_UART1
  36. extern usart_ctl uc1;
  37. #endif
  38. #if defined SERIAL_UART2
  39. extern usart_ctl uc2;
  40. #endif
  41. #if defined SERIAL_UART3
  42. extern usart_ctl uc3;
  43. #endif
  44. #if defined SERIAL_UART4
  45. extern usart_ctl uc4;
  46. #endif
  47. #if defined SERIAL_UART5
  48. extern usart_ctl uc5;
  49. #endif
  50.  
  51. ///@brief  returns the number of characters in the recieve buffer
  52. ///@param instance Pointer to usart_ctl structure
  53. ///@return Number of characters
  54. extern uint16_t SerialCharsReceived(usart_ctl *instance);
  55.  
  56. ///@brief Get the amount of free space in the transmit buffer.
  57. ///@param instance Pointer to usart_ctl structure
  58. ///@return Free space at time of checking
  59. extern uint16_t SerialTransmitSpace(usart_ctl *instance);
  60.  
  61. /// @brief Return 1 if there are any characters in the receive buffer
  62. /// @param instance Pointer to usart_ctl structure
  63. /// @return 1 if any characters
  64. extern uint8_t PollSerial(usart_ctl *instance);
  65.  
  66. /// @brief return the next character in the Serial input buffer
  67. /// This function will wait until a character arrives.
  68. /// Use PollSerial() or SerialCharsReceived() if you want
  69. /// to ensure you do not block here.
  70. /// @param instance Pointer to usart_ctl structure
  71. /// @return next character
  72. extern uint8_t GetCharSerial(usart_ctl *instance);
  73.  
  74. /// @brief Enable the receive interrupt
  75. /// @param instance
  76. extern void EnableSerialRxInterrupt(usart_ctl *instance);
  77.  
  78. /// @brief Send a character
  79. /// @param instance Pointer to usart_ctl structure
  80. /// @param c character to send
  81. extern void PutCharSerial(usart_ctl *instance, uint8_t c);
  82.  
  83. /// @brief Reset transmit buffer
  84. /// @param instance Pointer to usart_ctl structure
  85. extern void ResetTxBuffer(usart_ctl *instance);
  86.  
  87. /// @brief Reset receive buffer
  88. /// @param instance Pointer to usart_ctl structure
  89. extern void ResetRxBuffer(usart_ctl *instance);
  90.  
  91. /// @brief Reset both transmit and receive buffers
  92. /// @param instance Pointer to usart_ctl structure
  93. extern void FlushSerial(usart_ctl *instance);
  94.  
  95. /// @brief Check if the transmitter buffer is empty
  96. /// @param instance Pointer to usart_ctl structure
  97. /// @return 1 if the buffer is empty
  98. extern uint8_t TxBufferEmpty(usart_ctl *instance);
  99.  
  100. ///@brief  wait until the USART buffer is empty and all characters are sent
  101. /// @param instance Pointer to usart_ctl structure
  102. extern void TxWaitEmpty(usart_ctl *instance);
  103.  
  104. /// @brief Establish this instance as being in control of a USART
  105. /// @param instance  Pointer to usart_ctl structure
  106. /// @param usart Handle to usart maintained by HAL
  107. extern void init_usart_ctl(usart_ctl *instance,
  108.                                                    UART_HandleTypeDef *usart);
  109.  
  110. /// @brief Set the baud rate on this instance
  111. /// @param instance  Pointer to usart_ctl structure
  112. /// @param baud Baud rate in bits per second
  113. extern void setBaud(usart_ctl *instance, uint32_t baud);
  114.  
  115.  
  116. /// @brief Interrupt handler generic wrapper
  117. /// @param instance Pointer to usart_ctl structure
  118. extern void UART_IRQHandler(usart_ctl *instance);
  119.