107 lines
3.0 KiB
C

/*******************************************************************************
* *
* Copyright 2010 Rheinmetall Canada Inc. *
* *
* No part of this document may be reproduced, stored in *
* a retrieval system, or transmitted, in any form or by any means, *
* electronic, mechanical, photocopying, recording, or otherwise, *
* without the prior written permission of Rheinmetall Canada Inc. *
* *
*******************************************************************************/
/*
Description:
This is a template file for standard C header file.
*/
/* ************************************************************************** */
/* ¤Revision:
000 20100616 JFM,
Original version.
### YYYYMMDD Initial, Bug Identification
Change description.
*/
#ifndef UART_H
#define UART_H
/* ************************************************************************** */
/* Defines */
#define UART_MAX_RX_BUFF_SIZE 512
#define UART_MAX_TX_BUFF_SIZE 1024
/* ************************************************************************** */
/* Type definitions */
//Handles to the Uart ports as mapped physically on the CU board.
//in comment is the physical port assigned to each handle
//
enum eUartHandles
{
UART_1, //(232)
UART_2, //(232)
//UART_3, // !!!EXTERNAL!!! SPI daughter board...
MAX_UART_HANDLE,
INVALID_UART_HANDLE = 0xFF
};
extern const char *gUartStrings[MAX_UART_HANDLE];
enum eUartStopBits
{
UART_ONE_STOP_BIT,
UART_ONE_HALF_STOP_BIT,
UART_TWO_STOP_BITS
};
enum eUartParity
{
UART_NO_PARITY,
UART_EVEN_PARITY,
UART_ODD_PARTIY
};
typedef struct
{
int iIsInternal;
int iPhysicalUartPort;
int iDataPending; //This flag is 0 when : TxPtr == RxPtr OR Uart is transmitting.
char acTxCircularBuffer[UART_MAX_TX_BUFF_SIZE];
char *pcTxInPtr;
char *pcTxOutPtr;
char acRxCircularBuffer[UART_MAX_RX_BUFF_SIZE];
char *pcRxInDataPtr;
char *pcRxOutDataPtr;
int iNbRxFIFOPendingBytes;
}stUartData;
enum eUartReturnValues
{
UART_OK = 1,
UART_PORT_BUSY,
UART_PORT_NOT_OPENED,
UART_BUFFER_FULL,
UART_INVALID_HANDLE,
UART_INVALID_PORT
};
/* ************************************************************************** */
/* Prototypes */
int UartTransmitData(int p_iUartHandle, char *p_pcBuffer, int p_iSize);
int UartReceiveData(int p_iUartHandle, char *p_pcBuffer, int p_iSize);
int DataSentNotification(int p_iUartHandle,int p_iDataSize);
void InitUart(void);
int UartOpenComPort(int p_iUartHandle, int p_iBaudRate, int p_iNbStopBits, int p_iParityEnable);
int UartTick(void);
void UartBlockAndTick(unsigned int TickCount);
int UartBlockUntillBufEmpty(int iUartHandle);
int UartGetPendingDataSize(int iUartHandle);
int UartResetPort(int p_iUartHandle);
#endif
//EOF