Rev 13 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2 | mjames | 1 | /* |
2 | * serial.h |
||
3 | * |
||
4 | * Created on: 4 Jan 2016 |
||
5 | * Author: Mike |
||
6 | */ |
||
7 | |||
15 | mjames | 8 | |
9 | |||
10 | /* Includes ------------------------------------------------------------------*/ |
||
11 | #include "stm32f1xx_hal.h" |
||
12 | |||
13 | |||
10 | mjames | 14 | #pragma once |
2 | mjames | 15 | |
15 | mjames | 16 | #include <stdint.h> |
12 | mjames | 17 | |
15 | mjames | 18 | #if defined __cplusplus |
19 | extern "C" |
||
20 | { |
||
21 | #endif |
||
12 | mjames | 22 | |
15 | mjames | 23 | |
24 | struct usart_ctl |
||
10 | mjames | 25 | { |
13 | mjames | 26 | /// @brief UART handle |
10 | mjames | 27 | UART_HandleTypeDef *Handle; |
13 | mjames | 28 | /// @brief Locally maintained transmit buffer |
15 | mjames | 29 | |
30 | volatile uint8_t * tx_usart_buff; |
||
31 | uint16_t tx_usart_buff_size; |
||
32 | uint16_t rx_usart_buff_size; |
||
33 | volatile uint16_t tx_usart_in_Ptr; |
||
34 | volatile uint16_t tx_usart_out_Ptr; |
||
35 | volatile uint16_t tx_usart_overruns; |
||
13 | mjames | 36 | /// @brief Set when the usart is transmitting |
2 | mjames | 37 | volatile uint8_t tx_usart_running; |
10 | mjames | 38 | |
13 | mjames | 39 | /// @brief Locally maintained receive buffer |
15 | mjames | 40 | volatile uint8_t * rx_usart_buff; |
41 | volatile uint16_t rx_usart_in_Ptr; |
||
42 | volatile uint16_t rx_usart_out_Ptr; |
||
13 | mjames | 43 | /// @brief Set when the receiver buffer is full |
2 | mjames | 44 | volatile uint8_t rx_usart_buffer_full; |
15 | mjames | 45 | } ; |
2 | mjames | 46 | |
10 | mjames | 47 | |
48 | |||
2 | mjames | 49 | #if defined SERIAL_UART1 |
15 | mjames | 50 | extern struct usart_ctl uc1; |
2 | mjames | 51 | #endif |
52 | #if defined SERIAL_UART2 |
||
15 | mjames | 53 | extern struct usart_ctl uc2; |
2 | mjames | 54 | #endif |
55 | #if defined SERIAL_UART3 |
||
15 | mjames | 56 | extern struct usart_ctl uc3; |
2 | mjames | 57 | #endif |
7 | mjames | 58 | #if defined SERIAL_UART4 |
15 | mjames | 59 | extern struct usart_ctl uc4; |
7 | mjames | 60 | #endif |
61 | #if defined SERIAL_UART5 |
||
15 | mjames | 62 | extern struct usart_ctl uc5; |
7 | mjames | 63 | #endif |
13 | mjames | 64 | /// @brief Establish this instance as being in control of a USART |
65 | /// @param instance Pointer to usart_ctl structure |
||
66 | /// @param usart Handle to usart maintained by HAL |
||
15 | mjames | 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 |
||
71 | extern void init_usart_ctl(struct usart_ctl *instance, |
||
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); |
||
2 | mjames | 77 | |
13 | mjames | 78 | |
79 | |||
15 | mjames | 80 | #if defined __cplusplus |
81 | } |
||
82 | #endif |
||
83 | |||
84 | #include "serialCalls.h" |
||
85 |