You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

72 lines
3.5 KiB

1 year ago
//#############################################################################################################################################################################################################
#ifndef _INC_USART_COM_H_
#define _INC_USART_COM_H_
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//#include "stm32f4xx.h"
#include <inttypes.h>
#include <string.h>
//#include "SYSTEM.h"
//#include "CUST_GPIO.h"
//#include "TIMERS.h"
#include "Common/IDIBUS_DEFS.h"
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#ifdef _CPU_ATMEGA328PB_ //Maybe move this
#include "m328pb_defs.h"
#endif // #ifdef _CPU_ATMEGA328PB_
#ifdef _CPU_ATMEGA2560_
#include "m2560_defs.h"
#endif // _CPU_ATMEGA2560_
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
typedef struct {
volatile uint8_t *UCRSA;
volatile uint8_t *UCRSB;
volatile uint8_t *UCRSC;
volatile uint16_t *UBRR;
volatile uint8_t *UDR;
} USART_TypeDef;
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
typedef struct {
volatile USART_TypeDef *USART;
//DMA_Stream_TypeDef *DMATX;
uint8_t *TX_BUF;
uint8_t *RX_BUF;
uint16_t TxBufCount;
//uint16_t TxPacketSize;
uint16_t TxSendedCount;
uint16_t RxBufCount;
volatile uint8_t TxComplete;
uint8_t RxError;
uint8_t RxComplete;
uint16_t InterFrameTimeoutTicks; //Currently there are ticks for timer
} USART_HANDLER_TYPE;
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
typedef struct {
void (*SetNewBaudrate)(uint32_t);
void (*SendByteBuf)(uint8_t*, uint16_t);
void (*SendTxBuf)(uint16_t);
uint8_t (*IsNewRxMessage)(void);
uint8_t (*IsTxActive)(void);
uint8_t (*IsRxError)(void);
uint16_t (*getRxBufSize)(void);
void (*copyRxBuf)(uint8_t*, uint16_t, uint16_t);
uint8_t* (*getRxBuf)(void);
uint8_t* (*getTxBuf)(void);
void (*RxTransferRestart)(void);
} USART_INTERFACE_TYPE;
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
typedef struct {
uint8_t TimerMode;
uint16_t ResponseTimeoutUS;
uint16_t AlarmTimeoutUS;
volatile uint8_t ResponseTimeoutComplete;
void (*SetIdiBusBoudrate)(enum IDIBUS_SERIAL_BAUDRATE);
void (*RxAlarmFrameStart)(void);
} USART_IDIBUS_ROUTINE_TYPE;
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#endif //_INC_USART_COM_H_
//#############################################################################################################################################################################################################