Subversion Repositories libSerial

Rev

Rev 12 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 12 Rev 13
Line 10... Line 10...
10
#include "main.h"
10
#include "main.h"
11
 
11
 
12
 
12
 
13
typedef struct
13
typedef struct
14
{
14
{
-
 
15
        /// @brief UART handle
15
        UART_HandleTypeDef *Handle;
16
        UART_HandleTypeDef *Handle;
16
 
-
 
-
 
17
        /// @brief Locally maintained transmit buffer
17
        volatile uint8_t tx_usart_buff[TX_USART_BUFF_SIZ];
18
        volatile uint8_t tx_usart_buff[TX_USART_BUFF_SIZ];
18
        volatile unsigned int tx_usart_in_Ptr;
19
        volatile unsigned int tx_usart_in_Ptr;
19
        volatile unsigned int tx_usart_out_Ptr;
20
        volatile unsigned int tx_usart_out_Ptr;
20
        volatile unsigned int tx_usart_overruns;
21
        volatile unsigned int tx_usart_overruns;
-
 
22
        /// @brief Set when the usart is transmitting
21
        volatile uint8_t tx_usart_running;
23
        volatile uint8_t tx_usart_running;
22
       
24
       
-
 
25
        /// @brief Locally maintained receive buffer
23
        volatile uint8_t rx_usart_buff[RX_USART_BUFF_SIZ];
26
        volatile uint8_t rx_usart_buff[RX_USART_BUFF_SIZ];
24
        volatile unsigned int rx_usart_in_Ptr;
27
        volatile unsigned int rx_usart_in_Ptr;
25
        volatile unsigned int rx_usart_out_Ptr;
28
        volatile unsigned int rx_usart_out_Ptr;
-
 
29
        /// @brief Set when the receiver buffer is full
26
        volatile uint8_t rx_usart_buffer_full;
30
        volatile uint8_t rx_usart_buffer_full;
27
} usart_ctl;
31
} usart_ctl;
28
 
32
 
29
 
33
 
30
 
34
 
Line 43... Line 47...
43
#if defined SERIAL_UART5
47
#if defined SERIAL_UART5
44
extern usart_ctl uc5;
48
extern usart_ctl uc5;
45
#endif
49
#endif
46
 
50
 
47
///@brief  returns the number of characters in the recieve buffer
51
///@brief  returns the number of characters in the recieve buffer
-
 
52
///@param instance Pointer to usart_ctl structure
-
 
53
///@return Number of characters
48
extern uint16_t SerialCharsReceived(usart_ctl *instance);
54
extern uint16_t SerialCharsReceived(usart_ctl *instance);
-
 
55
 
49
///@brief Get the amount of free space in the transmit buffer.
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 
50
extern uint16_t SerialTransmitSpace(usart_ctl *instance);
59
extern uint16_t SerialTransmitSpace(usart_ctl *instance);
51
 
60
 
52
/// @brief Return 1 if there are any characters in the receive buffer
61
/// @brief Return 1 if there are any characters in the receive buffer
53
/// @param instance Pointer to usart_ctl structure
62
/// @param instance Pointer to usart_ctl structure
54
/// @return 1 if any characters 
63
/// @return 1 if any characters 
55
extern uint8_t PollSerial(usart_ctl *instance);
64
extern uint8_t PollSerial(usart_ctl *instance);
56
 
65
 
57
/// @brief Return character code
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.
58
/// @param instance 
70
/// @param instance Pointer to usart_ctl structure 
59
/// @return 
71
/// @return next character 
60
extern uint8_t GetCharSerial(usart_ctl *instance);
72
extern uint8_t GetCharSerial(usart_ctl *instance);
61
 
73
 
62
/// @brief Enable the receive interrupt 
74
/// @brief Enable the receive interrupt 
63
/// @param instance 
75
/// @param instance 
64
extern void EnableSerialRxInterrupt(usart_ctl *instance);
76
extern void EnableSerialRxInterrupt(usart_ctl *instance);
65
 
77
 
-
 
78
/// @brief Send a character
66
extern void UART_IRQHandler(usart_ctl *instance);
79
/// @param instance Pointer to usart_ctl structure
67
 
-
 
-
 
80
/// @param c character to send
68
extern void PutCharSerial(usart_ctl *instance, uint8_t c);
81
extern void PutCharSerial(usart_ctl *instance, uint8_t c);
-
 
82
 
-
 
83
/// @brief Reset transmit buffer
-
 
84
/// @param instance Pointer to usart_ctl structure
69
extern void ResetTxBuffer(usart_ctl *instance);
85
extern void ResetTxBuffer(usart_ctl *instance);
-
 
86
 
-
 
87
/// @brief Reset receive buffer
-
 
88
/// @param instance Pointer to usart_ctl structure
70
extern void ResetRxBuffer(usart_ctl *instance);
89
extern void ResetRxBuffer(usart_ctl *instance);
-
 
90
 
-
 
91
/// @brief Reset both transmit and receive buffers
-
 
92
/// @param instance Pointer to usart_ctl structure
71
extern void FlushSerial(usart_ctl *instance);
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
72
extern uint8_t TxBufferEmpty(usart_ctl *instance);
98
extern uint8_t TxBufferEmpty(usart_ctl *instance);
-
 
99
 
73
///@brief  wait until the USART buffer is empty and all characters are sent
100
///@brief  wait until the USART buffer is empty and all characters are sent
-
 
101
/// @param instance Pointer to usart_ctl structure
74
extern void TxWaitEmpty(usart_ctl *instance);
102
extern void TxWaitEmpty(usart_ctl *instance);
75
 
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
76
extern void init_usart_ctl(usart_ctl *instance,
107
extern void init_usart_ctl(usart_ctl *instance,
77
                                                   UART_HandleTypeDef *usart);
108
                                                   UART_HandleTypeDef *usart);
78
 
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
79
extern void setBaud(usart_ctl *instance, uint32_t baud);
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);