Subversion Repositories libSerial

Rev

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