Working on DOS port.
This commit is contained in:
Binary file not shown.
@@ -35,10 +35,11 @@
|
|||||||
#include "timer.h"
|
#include "timer.h"
|
||||||
|
|
||||||
/* This file has been customized for use with DOS */
|
/* This file has been customized for use with DOS */
|
||||||
#include "hardware.h"
|
#include <dos.h>
|
||||||
|
#include "serial.h"
|
||||||
|
|
||||||
/* UART */
|
/* UART */
|
||||||
static volatile AT91S_USART *RS485_Interface = AT91C_BASE_US0;
|
static char RS485_Port = '2';
|
||||||
/* baud rate */
|
/* baud rate */
|
||||||
static int RS485_Baud = 38400;
|
static int RS485_Baud = 38400;
|
||||||
|
|
||||||
@@ -64,42 +65,10 @@ static int RS485_Baud = 38400;
|
|||||||
void RS485_Initialize(
|
void RS485_Initialize(
|
||||||
void)
|
void)
|
||||||
{
|
{
|
||||||
/* Enable the USART0 clock in the Power Management Controller */
|
|
||||||
volatile AT91PS_PMC pPMC = AT91C_BASE_PMC;
|
|
||||||
pPMC->PMC_PCER = pPMC->PMC_PCSR | (1 << AT91C_ID_US0);
|
|
||||||
|
|
||||||
/* Disable and clear USART0 interrupt
|
|
||||||
in AIC Interrupt Disable Command Register */
|
|
||||||
volatile AT91PS_AIC pAIC = AT91C_BASE_AIC;
|
|
||||||
pAIC->AIC_IDCR = (1 << AT91C_ID_US0);
|
|
||||||
pAIC->AIC_ICCR = (1 << AT91C_ID_US0);
|
|
||||||
|
|
||||||
/* enable the peripheral by disabling the pin in the PIO controller */
|
|
||||||
*AT91C_PIOA_PDR = AT91C_PA5_RXD0 | AT91C_PA6_TXD0 | AT91C_PA7_RTS0;
|
|
||||||
|
|
||||||
RS485_Interface->US_CR = AT91C_US_RSTRX | /* Reset Receiver */
|
|
||||||
AT91C_US_RSTTX | /* Reset Transmitter */
|
|
||||||
AT91C_US_RSTSTA | /* Clear status register */
|
|
||||||
AT91C_US_RXDIS | /* Receiver Disable */
|
|
||||||
AT91C_US_TXDIS; /* Transmitter Disable */
|
|
||||||
|
|
||||||
RS485_Interface->US_MR = AT91C_US_USMODE_RS485 | /* RS-485 Mode - RTS auto assert */
|
|
||||||
AT91C_US_CLKS_CLOCK | /* Clock = MCK */
|
|
||||||
AT91C_US_CHRL_8_BITS | /* 8-bit Data */
|
|
||||||
AT91C_US_PAR_NONE | /* No Parity */
|
|
||||||
AT91C_US_NBSTOP_1_BIT; /* 1 Stop Bit */
|
|
||||||
|
|
||||||
/* set the Time Guard to release RTS after x bit times */
|
|
||||||
RS485_Interface->US_TTGR = 1;
|
|
||||||
|
|
||||||
/* Receiver Time-out disabled */
|
|
||||||
RS485_Interface->US_RTOR = 0;
|
|
||||||
|
|
||||||
/* baud rate */
|
/* baud rate */
|
||||||
RS485_Interface->US_BRGR = MCK / 16 / RS485_Baud;
|
OpenComPort(RS485_Port);
|
||||||
|
/* FIXME: change to numeric parameters */
|
||||||
RS485_Interface->US_CR = AT91C_US_RXEN | /* Receiver Enable */
|
InitComPort ( "38400", '8', 'N', '1' );
|
||||||
AT91C_US_TXEN; /* Transmitter Enable */
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -141,8 +110,7 @@ bool RS485_Set_Baud_Rate(
|
|||||||
case 76800:
|
case 76800:
|
||||||
case 115200:
|
case 115200:
|
||||||
RS485_Baud = baud;
|
RS485_Baud = baud;
|
||||||
RS485_Interface->US_BRGR = MCK / 16 / baud;
|
/* FIXME: store the baud rate */
|
||||||
/* FIXME: store the baud rate */
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
valid = false;
|
valid = false;
|
||||||
@@ -176,7 +144,7 @@ void RS485_Turnaround_Delay(
|
|||||||
* DESCRIPTION: Enable or disable the transmitter
|
* DESCRIPTION: Enable or disable the transmitter
|
||||||
* RETURN: none
|
* RETURN: none
|
||||||
* ALGORITHM: none
|
* ALGORITHM: none
|
||||||
* NOTES: The Atmel ARM7 has an automatic enable/disable in RS485 mode.
|
* NOTES: none
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
void RS485_Transmitter_Enable(
|
void RS485_Transmitter_Enable(
|
||||||
bool enable)
|
bool enable)
|
||||||
@@ -194,19 +162,8 @@ void RS485_Send_Data(
|
|||||||
uint8_t * buffer, /* data to send */
|
uint8_t * buffer, /* data to send */
|
||||||
uint16_t nbytes)
|
uint16_t nbytes)
|
||||||
{ /* number of bytes of data */
|
{ /* number of bytes of data */
|
||||||
/* LED on send */
|
|
||||||
volatile AT91PS_PIO pPIO = AT91C_BASE_PIOA;
|
|
||||||
/* LED ON */
|
|
||||||
pPIO->PIO_CODR = LED1;
|
|
||||||
/* send all the bytes */
|
/* send all the bytes */
|
||||||
while (nbytes) {
|
ComSendData(buffer, nbytes);
|
||||||
while (!(RS485_Interface->US_CSR & AT91C_US_TXRDY)) {
|
|
||||||
/* do nothing - wait until Tx buffer is empty */
|
|
||||||
}
|
|
||||||
RS485_Interface->US_THR = *buffer;
|
|
||||||
buffer++;
|
|
||||||
nbytes--;
|
|
||||||
}
|
|
||||||
while (!(RS485_Interface->US_CSR & AT91C_US_TXRDY)) {
|
while (!(RS485_Interface->US_CSR & AT91C_US_TXRDY)) {
|
||||||
/* do nothing - wait until Tx buffer is empty */
|
/* do nothing - wait until Tx buffer is empty */
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,6 +43,37 @@ void (INTERRUPT FAR *oldvector_serial )();
|
|||||||
int ComBase; /* Comm port address */
|
int ComBase; /* Comm port address */
|
||||||
int IrqNum; /* Comm interrupt request */
|
int IrqNum; /* Comm interrupt request */
|
||||||
|
|
||||||
|
void CloseComPort ( void )
|
||||||
|
{
|
||||||
|
int status;
|
||||||
|
|
||||||
|
/* restore UART to previous state */
|
||||||
|
|
||||||
|
outp ( ComBase + INT_EN, (unsigned char) 0 );
|
||||||
|
outp ( ComBase + MODEM_CNTRL,
|
||||||
|
(unsigned char) old_comm_params.modem );
|
||||||
|
status = inp ( ComBase + LINE_CNTRL );
|
||||||
|
outp ( ComBase + LINE_CNTRL,
|
||||||
|
(unsigned char) status | 0x80 );
|
||||||
|
outp ( ComBase + BAUD_LSB,
|
||||||
|
(unsigned char) old_comm_params.baud_lsb );
|
||||||
|
outp ( ComBase + BAUD_MSB,
|
||||||
|
(unsigned char) old_comm_params.baud_msb );
|
||||||
|
outp ( ComBase + LINE_CNTRL,
|
||||||
|
(unsigned char) old_comm_params.line );
|
||||||
|
outp ( 0x21, (unsigned char) old_comm_params.int_cntrl );
|
||||||
|
|
||||||
|
/* restore old interrupt handler */
|
||||||
|
|
||||||
|
setvect ( IrqNum + 8, oldvector_serial );
|
||||||
|
|
||||||
|
/* free input and output queues */
|
||||||
|
|
||||||
|
free ( Serial_In_Queue );
|
||||||
|
free ( Serial_Out_Queue );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
int OpenComPort ( char Port ) /* install int. handler */
|
int OpenComPort ( char Port ) /* install int. handler */
|
||||||
{
|
{
|
||||||
unsigned status;
|
unsigned status;
|
||||||
@@ -105,53 +136,25 @@ int OpenComPort ( char Port ) /* install int. handler */
|
|||||||
|
|
||||||
outp ( 0x21, (unsigned char) old_comm_params.int_cntrl &
|
outp ( 0x21, (unsigned char) old_comm_params.int_cntrl &
|
||||||
(unsigned char) status );
|
(unsigned char) status );
|
||||||
|
|
||||||
|
atexit(CloseComPort);
|
||||||
|
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CloseComPort ( void )
|
|
||||||
{
|
|
||||||
int status;
|
|
||||||
|
|
||||||
/* restore UART to previous state */
|
|
||||||
|
|
||||||
outp ( ComBase + INT_EN, (unsigned char) 0 );
|
|
||||||
outp ( ComBase + MODEM_CNTRL,
|
|
||||||
(unsigned char) old_comm_params.modem );
|
|
||||||
status = inp ( ComBase + LINE_CNTRL );
|
|
||||||
outp ( ComBase + LINE_CNTRL,
|
|
||||||
(unsigned char) status | 0x80 );
|
|
||||||
outp ( ComBase + BAUD_LSB,
|
|
||||||
(unsigned char) old_comm_params.baud_lsb );
|
|
||||||
outp ( ComBase + BAUD_MSB,
|
|
||||||
(unsigned char) old_comm_params.baud_msb );
|
|
||||||
outp ( ComBase + LINE_CNTRL,
|
|
||||||
(unsigned char) old_comm_params.line );
|
|
||||||
outp ( 0x21, (unsigned char) old_comm_params.int_cntrl );
|
|
||||||
|
|
||||||
/* restore old interrupt handler */
|
|
||||||
|
|
||||||
setvect ( IrqNum + 8, oldvector_serial );
|
|
||||||
|
|
||||||
/* free input and output queues */
|
|
||||||
|
|
||||||
free ( Serial_In_Queue );
|
|
||||||
free ( Serial_Out_Queue );
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
void InitComPort ( char Baud[], char Databits,
|
void InitComPort ( char Baud[], char Databits,
|
||||||
char Parity, char Stopbits )
|
char Parity, char Stopbits )
|
||||||
{
|
{
|
||||||
int status;
|
int status;
|
||||||
long baudrate;
|
|
||||||
unsigned divisor;
|
unsigned divisor;
|
||||||
|
long baudrate;
|
||||||
|
|
||||||
/* set baud rate */
|
/* set baud rate */
|
||||||
|
|
||||||
status = inp ( ComBase + LINE_CNTRL );
|
status = inp ( ComBase + LINE_CNTRL );
|
||||||
outp ( ComBase + LINE_CNTRL,
|
outp ( ComBase + LINE_CNTRL,
|
||||||
(unsigned char) status | 0x80 );
|
(unsigned char) status | 0x80 );
|
||||||
baudrate = atol ( Baud );
|
baudrate = atol(Baud);
|
||||||
if ( baudrate == 0)
|
if ( baudrate == 0)
|
||||||
baudrate = 2400L;
|
baudrate = 2400L;
|
||||||
divisor = (unsigned) ( 115200L / baudrate);
|
divisor = (unsigned) ( 115200L / baudrate);
|
||||||
@@ -266,6 +269,24 @@ int ComSendString ( char *string )
|
|||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int ComSendData ( char *buffer, unsigned buffer_length )
|
||||||
|
{
|
||||||
|
int retval;
|
||||||
|
char *pointer;
|
||||||
|
pointer = buffer;
|
||||||
|
unsigned i;
|
||||||
|
|
||||||
|
for (i = 0; i < buffer_length; i++)
|
||||||
|
{
|
||||||
|
retval = en_queue ( Serial_Out_Queue, *pointer );
|
||||||
|
pointer++;
|
||||||
|
}
|
||||||
|
if ( 0x0 == (comm_status.modem & 0x40))
|
||||||
|
RaiseDtr ();
|
||||||
|
outp ( ComBase + INT_EN, RX_INT | TBE_INT | ERR_INT | RS_INT );
|
||||||
|
return retval;
|
||||||
|
}
|
||||||
|
|
||||||
int ComSendChar ( char character )
|
int ComSendChar ( char character )
|
||||||
{
|
{
|
||||||
int retval;
|
int retval;
|
||||||
|
|||||||
@@ -98,6 +98,7 @@ int ComRecChar ( void ); /* Fetch character from rcv buf*/
|
|||||||
|
|
||||||
int ComSendChar ( char character ); /* Put char into xmit buffer */
|
int ComSendChar ( char character ); /* Put char into xmit buffer */
|
||||||
int ComSendString ( char *string );
|
int ComSendString ( char *string );
|
||||||
|
int ComSendData ( char *buffer, unsigned buffer_length );
|
||||||
int ComStatus ( void ); /* Fetch comm status */
|
int ComStatus ( void ); /* Fetch comm status */
|
||||||
void INTERRUPT FAR serial ( void ); /* interrupt handler */
|
void INTERRUPT FAR serial ( void ); /* interrupt handler */
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user