running the indent on the files.
This commit is contained in:
@@ -40,122 +40,115 @@ static int RS485_Port = COM2;
|
||||
/* baud rate */
|
||||
static long RS485_Baud = 38400;
|
||||
/* io base address */
|
||||
static long RS485_Base = 0;
|
||||
static long RS485_Base = 0;
|
||||
/* hardware IRQ number */
|
||||
static long RS485_IRQ_Number = 0;
|
||||
static long RS485_IRQ_Number = 0;
|
||||
|
||||
static void RS485_Standard_Port_Settings(long port, long *pIRQ, long *pBase)
|
||||
static void RS485_Standard_Port_Settings(long port, long *pIRQ,
|
||||
long *pBase)
|
||||
{
|
||||
switch (port)
|
||||
{
|
||||
switch (port) {
|
||||
case COM1:
|
||||
*pBase = (long)0x3F8;
|
||||
*pIRQ = 4L;
|
||||
break;
|
||||
*pBase = (long) 0x3F8;
|
||||
*pIRQ = 4L;
|
||||
break;
|
||||
case COM2:
|
||||
*pBase = (long)0x2F8;
|
||||
*pIRQ = 3L;
|
||||
break;
|
||||
*pBase = (long) 0x2F8;
|
||||
*pIRQ = 3L;
|
||||
break;
|
||||
case COM3:
|
||||
*pBase = (long)0x3E8;
|
||||
*pIRQ = 4L;
|
||||
break;
|
||||
*pBase = (long) 0x3E8;
|
||||
*pIRQ = 4L;
|
||||
break;
|
||||
case COM4:
|
||||
*pBase = (long)0x2E8;
|
||||
*pIRQ = 3L;
|
||||
break;
|
||||
*pBase = (long) 0x2E8;
|
||||
*pIRQ = 3L;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static RS485_Open_Port(
|
||||
int port, /* COM port number - COM1 = 0 */
|
||||
long baud, /* baud rate */
|
||||
unsigned base, /* io base address */
|
||||
int irq) /* hardware IRQ number */
|
||||
{
|
||||
/* setup the COM IO */
|
||||
SetIOBase(port, base);
|
||||
SetIRQ(port, irq);
|
||||
static RS485_Open_Port(int port, /* COM port number - COM1 = 0 */
|
||||
long baud, /* baud rate */
|
||||
unsigned base, /* io base address */
|
||||
int irq)
|
||||
{ /* hardware IRQ number */
|
||||
/* setup the COM IO */
|
||||
SetIOBase(port, base);
|
||||
SetIRQ(port, irq);
|
||||
|
||||
if (irq < 8)
|
||||
RTKIRQTopPriority(irq,9);
|
||||
if (irq < 8)
|
||||
RTKIRQTopPriority(irq, 9);
|
||||
|
||||
InitPort(port, baud, PARITY_NONE, 1, 8);
|
||||
InitPort(port, baud, PARITY_NONE, 1, 8);
|
||||
|
||||
if (HasFIFO(port))
|
||||
EnableFIFO(port,8);
|
||||
EnableCOMInterrupt(port, 1024*4);
|
||||
if (HasFIFO(port))
|
||||
EnableFIFO(port, 8);
|
||||
EnableCOMInterrupt(port, 1024 * 4);
|
||||
|
||||
/* enable the 485 via the DTR pin */
|
||||
RS485_IO_ENABLE(port);
|
||||
RS485_RECEIVE_ENABLE(port);
|
||||
/* enable the 485 via the DTR pin */
|
||||
RS485_IO_ENABLE(port);
|
||||
RS485_RECEIVE_ENABLE(port);
|
||||
|
||||
return;
|
||||
return;
|
||||
}
|
||||
|
||||
void RS485_Initialize(void)
|
||||
{
|
||||
RS485_Standard_Port_Settings(RS485_Port, &RS485_IRQ_Number, &RS485_Base);
|
||||
RS485_Open_Port(RS485_Port, RS485_Baud, RS485_Base, RS485_IRQ_Number);
|
||||
RS485_Standard_Port_Settings(RS485_Port, &RS485_IRQ_Number,
|
||||
&RS485_Base);
|
||||
RS485_Open_Port(RS485_Port, RS485_Baud, RS485_Base, RS485_IRQ_Number);
|
||||
}
|
||||
|
||||
void RS485_Send_Frame(
|
||||
volatile struct mstp_port_struct_t *mstp_port, // port specific data
|
||||
uint8_t *buffer, // frame to send (up to 501 bytes of data)
|
||||
uint16_t nbytes) // number of bytes of data (up to 501)
|
||||
void RS485_Send_Frame(volatile struct mstp_port_struct_t *mstp_port, // port specific data
|
||||
uint8_t * buffer, // frame to send (up to 501 bytes of data)
|
||||
uint16_t nbytes) // number of bytes of data (up to 501)
|
||||
{
|
||||
bool status = true; // return value
|
||||
bool status = true; // return value
|
||||
|
||||
(void)mstp_port;
|
||||
RS485_TRANSMIT_ENABLE(RS485_Port);
|
||||
SendBlock(RS485_Port, (char *)buffer, nbytes);
|
||||
/* need to wait at least 9600 baud * 512 bytes = 54mS */
|
||||
(void)WaitSendBufferEmpty(RS485_Port,MilliSecsToTicks(200));
|
||||
while (!(LineStatus(RS485_Port) & TX_SHIFT_EMPTY))
|
||||
RTKScheduler();
|
||||
RS485_RECEIVE_ENABLE(RS485_Port);
|
||||
(void) mstp_port;
|
||||
RS485_TRANSMIT_ENABLE(RS485_Port);
|
||||
SendBlock(RS485_Port, (char *) buffer, nbytes);
|
||||
/* need to wait at least 9600 baud * 512 bytes = 54mS */
|
||||
(void) WaitSendBufferEmpty(RS485_Port, MilliSecsToTicks(200));
|
||||
while (!(LineStatus(RS485_Port) & TX_SHIFT_EMPTY))
|
||||
RTKScheduler();
|
||||
RS485_RECEIVE_ENABLE(RS485_Port);
|
||||
|
||||
return;
|
||||
return;
|
||||
}
|
||||
|
||||
void RS485_Check_UART_Data(
|
||||
volatile struct mstp_port_struct_t *mstp_port) // port specific data
|
||||
void RS485_Check_UART_Data(volatile struct mstp_port_struct_t *mstp_port) // port specific data
|
||||
{
|
||||
COMData com_data = 0; /* byte from COM driver */
|
||||
unsigned timeout = 10; // milliseconds to wait for a character
|
||||
Duration ticks; /* duration to wait for data */
|
||||
COMData com_data = 0; /* byte from COM driver */
|
||||
unsigned timeout = 10; // milliseconds to wait for a character
|
||||
Duration ticks; /* duration to wait for data */
|
||||
|
||||
if (mstp_port->ReceiveError)
|
||||
{
|
||||
// wait for state machine to clear this
|
||||
}
|
||||
// wait for state machine to read from the DataRegister
|
||||
else if (!mstp_port->DataAvailable)
|
||||
{
|
||||
// check for data
|
||||
ticks = MilliSecsToTicks(timeout);
|
||||
if (!ticks)
|
||||
ticks = 1;
|
||||
if (RTKGetTimed(ReceiveBuffer[RS485_Port],&com_data,ticks))
|
||||
{
|
||||
// if error,
|
||||
if (com_data & (COM_OVERRUN << 8))
|
||||
mstp_port->ReceiveError = true;
|
||||
else if (com_data & (COM_FRAME << 8))
|
||||
mstp_port->ReceiveError = true;
|
||||
else
|
||||
{
|
||||
mstp_port->DataRegister = com_data & 0x00FF;
|
||||
mstp_port->DataAvailable = true;
|
||||
}
|
||||
if (mstp_port->ReceiveError) {
|
||||
// wait for state machine to clear this
|
||||
}
|
||||
// wait for state machine to read from the DataRegister
|
||||
else if (!mstp_port->DataAvailable) {
|
||||
// check for data
|
||||
ticks = MilliSecsToTicks(timeout);
|
||||
if (!ticks)
|
||||
ticks = 1;
|
||||
if (RTKGetTimed(ReceiveBuffer[RS485_Port], &com_data, ticks)) {
|
||||
// if error,
|
||||
if (com_data & (COM_OVERRUN << 8))
|
||||
mstp_port->ReceiveError = true;
|
||||
else if (com_data & (COM_FRAME << 8))
|
||||
mstp_port->ReceiveError = true;
|
||||
else {
|
||||
mstp_port->DataRegister = com_data & 0x00FF;
|
||||
mstp_port->DataAvailable = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void RS485_Process_Tx_Message(void)
|
||||
{
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user