Rev 13 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 13 | Rev 15 | ||
---|---|---|---|
Line 3... | Line 3... | ||
3 | * |
3 | * |
4 | * Created on: 4 Jan 2016 |
4 | * Created on: 4 Jan 2016 |
5 | * Author: Mike |
5 | * Author: Mike |
6 | */ |
6 | */ |
7 | 7 | ||
- | 8 | ||
- | 9 | ||
- | 10 | /* Includes ------------------------------------------------------------------*/ |
|
- | 11 | #include "stm32f1xx_hal.h" |
|
- | 12 | ||
- | 13 | ||
8 | #pragma once |
14 | #pragma once |
9 | 15 | ||
10 | #include "main.h" |
16 | #include <stdint.h> |
- | 17 | ||
- | 18 | #if defined __cplusplus |
|
- | 19 | extern "C" |
|
- | 20 | { |
|
- | 21 | #endif |
|
11 | 22 | ||
12 | 23 | ||
13 | typedef struct |
24 | struct usart_ctl |
14 | { |
25 | { |
15 | /// @brief UART handle |
26 | /// @brief UART handle |
16 | UART_HandleTypeDef *Handle; |
27 | UART_HandleTypeDef *Handle; |
17 | /// @brief Locally maintained transmit buffer |
28 | /// @brief Locally maintained transmit buffer |
- | 29 | ||
18 | volatile uint8_t tx_usart_buff[TX_USART_BUFF_SIZ]; |
30 | volatile uint8_t * tx_usart_buff; |
- | 31 | uint16_t tx_usart_buff_size; |
|
- | 32 | uint16_t rx_usart_buff_size; |
|
19 | volatile unsigned int tx_usart_in_Ptr; |
33 | volatile uint16_t tx_usart_in_Ptr; |
20 | volatile unsigned int tx_usart_out_Ptr; |
34 | volatile uint16_t tx_usart_out_Ptr; |
21 | volatile unsigned int tx_usart_overruns; |
35 | volatile uint16_t tx_usart_overruns; |
22 | /// @brief Set when the usart is transmitting |
36 | /// @brief Set when the usart is transmitting |
23 | volatile uint8_t tx_usart_running; |
37 | volatile uint8_t tx_usart_running; |
24 | 38 | ||
25 | /// @brief Locally maintained receive buffer |
39 | /// @brief Locally maintained receive buffer |
26 | volatile uint8_t rx_usart_buff[RX_USART_BUFF_SIZ]; |
40 | volatile uint8_t * rx_usart_buff; |
27 | volatile unsigned int rx_usart_in_Ptr; |
41 | volatile uint16_t rx_usart_in_Ptr; |
28 | volatile unsigned int rx_usart_out_Ptr; |
42 | volatile uint16_t rx_usart_out_Ptr; |
29 | /// @brief Set when the receiver buffer is full |
43 | /// @brief Set when the receiver buffer is full |
30 | volatile uint8_t rx_usart_buffer_full; |
44 | volatile uint8_t rx_usart_buffer_full; |
31 | } usart_ctl; |
45 | } ; |
32 | 46 | ||
33 | 47 | ||
34 | 48 | ||
35 | #if defined SERIAL_UART1 |
49 | #if defined SERIAL_UART1 |
36 | extern usart_ctl uc1; |
50 | extern struct usart_ctl uc1; |
37 | #endif |
51 | #endif |
38 | #if defined SERIAL_UART2 |
52 | #if defined SERIAL_UART2 |
39 | extern usart_ctl uc2; |
53 | extern struct usart_ctl uc2; |
40 | #endif |
54 | #endif |
41 | #if defined SERIAL_UART3 |
55 | #if defined SERIAL_UART3 |
42 | extern usart_ctl uc3; |
56 | extern struct usart_ctl uc3; |
43 | #endif |
57 | #endif |
44 | #if defined SERIAL_UART4 |
58 | #if defined SERIAL_UART4 |
45 | extern usart_ctl uc4; |
59 | extern struct usart_ctl uc4; |
46 | #endif |
60 | #endif |
47 | #if defined SERIAL_UART5 |
61 | #if defined SERIAL_UART5 |
48 | extern usart_ctl uc5; |
62 | extern struct usart_ctl uc5; |
49 | #endif |
63 | #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 |
64 | /// @brief Establish this instance as being in control of a USART |
105 | /// @param instance Pointer to usart_ctl structure |
65 | /// @param instance Pointer to usart_ctl structure |
106 | /// @param usart Handle to usart maintained by HAL |
66 | /// @param usart Handle to usart maintained by HAL |
- | 67 | /// @param tx_buffer Statically allocated memory for Tx buffer |
|
- | 68 | /// @param rx_buffer Statically allocated memory for Rx buffer |
|
- | 69 | /// @param rx_buffer_size Rx Buffer size |
|
- | 70 | /// @param tx_buffer_size Tx Buffer size |
|
107 | extern void init_usart_ctl(usart_ctl *instance, |
71 | extern void init_usart_ctl(struct usart_ctl *instance, |
108 | UART_HandleTypeDef *usart); |
72 | UART_HandleTypeDef *usart, |
- | 73 | volatile uint8_t * tx_buffer, |
|
- | 74 | volatile uint8_t * rx_buffer, |
|
- | 75 | uint16_t tx_buffer_size, |
|
- | 76 | uint16_t rx_buffer_size); |
|
109 | 77 | ||
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 | 78 | ||
115 | 79 | ||
116 | /// @brief Interrupt handler generic wrapper |
80 | #if defined __cplusplus |
- | 81 | } |
|
- | 82 | #endif |
|
- | 83 | ||
117 | /// @param instance Pointer to usart_ctl structure |
84 | #include "serialCalls.h" |
118 | extern void UART_IRQHandler(usart_ctl *instance); |
- | |
- | 85 |