Rev 8 | Rev 12 | Go to most recent revision | 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 | |||
| 10 | mjames | 8 | #pragma once |
| 2 | mjames | 9 | |
| 10 | #include "main.h" |
||
| 10 | mjames | 11 | typedef struct |
| 12 | { |
||
| 13 | UART_HandleTypeDef *Handle; |
||
| 2 | mjames | 14 | |
| 15 | volatile uint8_t tx_usart_buff[TX_USART_BUFF_SIZ]; |
||
| 16 | volatile unsigned int tx_usart_in_Ptr; |
||
| 17 | volatile unsigned int tx_usart_out_Ptr; |
||
| 10 | mjames | 18 | volatile unsigned int tx_usart_overruns; |
| 2 | mjames | 19 | volatile uint8_t tx_usart_running; |
| 10 | mjames | 20 | |
| 2 | mjames | 21 | volatile uint8_t rx_usart_buff[RX_USART_BUFF_SIZ]; |
| 22 | volatile unsigned int rx_usart_in_Ptr; |
||
| 23 | volatile unsigned int rx_usart_out_Ptr; |
||
| 24 | volatile uint8_t rx_usart_buffer_full; |
||
| 25 | } usart_ctl; |
||
| 26 | |||
| 10 | mjames | 27 | |
| 28 | |||
| 2 | mjames | 29 | #if defined SERIAL_UART1 |
| 30 | extern usart_ctl uc1; |
||
| 31 | #endif |
||
| 32 | #if defined SERIAL_UART2 |
||
| 33 | extern usart_ctl uc2; |
||
| 34 | #endif |
||
| 35 | #if defined SERIAL_UART3 |
||
| 36 | extern usart_ctl uc3; |
||
| 37 | #endif |
||
| 7 | mjames | 38 | #if defined SERIAL_UART4 |
| 39 | extern usart_ctl uc4; |
||
| 40 | #endif |
||
| 41 | #if defined SERIAL_UART5 |
||
| 42 | extern usart_ctl uc5; |
||
| 43 | #endif |
||
| 2 | mjames | 44 | |
| 7 | mjames | 45 | ///@brief returns the number of characters in the recieve buffer |
| 10 | mjames | 46 | extern uint16_t SerialCharsReceived(usart_ctl *instance); |
| 47 | ///@brief Get the amount of free space in the transmit buffer. |
||
| 48 | extern uint16_t SerialTransmitSpace(usart_ctl *instance); |
||
| 2 | mjames | 49 | |
| 10 | mjames | 50 | extern uint8_t PollSerial(usart_ctl *instance); |
| 51 | extern uint8_t GetCharSerial(usart_ctl *instance); |
||
| 52 | extern void EnableSerialRxInterrupt(usart_ctl *instance); |
||
| 7 | mjames | 53 | |
| 10 | mjames | 54 | extern void UART_IRQHandler(usart_ctl *instance); |
| 2 | mjames | 55 | |
| 10 | mjames | 56 | extern void PutCharSerial(usart_ctl *instance, uint8_t c); |
| 57 | extern void ResetTxBuffer(usart_ctl *instance); |
||
| 58 | extern void ResetRxBuffer(usart_ctl *instance); |
||
| 59 | extern void FlushSerial(usart_ctl *instance); |
||
| 60 | extern uint8_t TxBufferEmpty(usart_ctl *instance); |
||
| 4 | mjames | 61 | ///@brief wait until the USART buffer is empty and all characters are sent |
| 62 | extern void TxWaitEmpty(usart_ctl *instance); |
||
| 2 | mjames | 63 | |
| 10 | mjames | 64 | extern void init_usart_ctl(usart_ctl *instance, |
| 65 | UART_HandleTypeDef *usart); |
||
| 2 | mjames | 66 | |
| 10 | mjames | 67 | extern void setBaud(usart_ctl *instance, uint32_t baud); |