/*
* serial.h
*
* Created on: 4 Jan 2016
* Author: Mike
*/
#ifndef INC_SERIAL_H_
#define INC_SERIAL_H_
#include "stm32f1xx_hal.h"
#define TX_USART_BUFF_SIZ 256
#define RX_USART_BUFF_SIZ 4096
typedef struct {
USART_TypeDef *Instance;
volatile uint8_t tx_usart_buff[TX_USART_BUFF_SIZ];
volatile unsigned int tx_usart_in_Ptr;
volatile unsigned int tx_usart_out_Ptr;
volatile uint8_t tx_usart_running;
volatile uint16_t tx_usart_count;
volatile uint8_t rx_usart_buff[RX_USART_BUFF_SIZ];
volatile unsigned int rx_usart_in_Ptr;
volatile unsigned int rx_usart_out_Ptr;
volatile uint8_t rx_usart_buffer_full;
} usart_ctl;
extern usart_ctl uc1;
extern usart_ctl uc2;
/* returns the number of characters received by the Rx USART */
extern uint16_t SerialCharsReceived(usart_ctl * instance);
extern inline uint8_t PollSerial(usart_ctl * instance);
extern uint8_t GetCharSerial(usart_ctl * instance);
extern inline void EnableSerialRxInterrupt(usart_ctl * instance);
extern void UART_IRQHandler(usart_ctl * instance);
extern void PutCharSerial(usart_ctl * instance,uint8_t c);
extern void ResetTxBuffer(usart_ctl * instance);
extern void ResetRxBuffer(usart_ctl * instance);
extern void FlushSerial(usart_ctl * instance);
extern uint8_t TxBufferEmpty(usart_ctl * instance);
extern void init_usart_ctl(usart_ctl * instance, USART_TypeDef * hardware);
#endif /* INC_SERIAL_H_ */