Indented.
This commit is contained in:
@@ -64,25 +64,29 @@ typedef struct BACnet_COV_Subscription {
|
||||
#define MAX_COV_SUBCRIPTIONS 32
|
||||
static BACNET_COV_SUBSCRIPTION COV_Subscriptions[MAX_COV_SUBCRIPTIONS];
|
||||
|
||||
void handler_cov_init(void)
|
||||
void handler_cov_init(
|
||||
void)
|
||||
{
|
||||
unsigned index = 0;
|
||||
|
||||
for (index = 0; index < MAX_COV_SUBCRIPTIONS; index++) {
|
||||
COV_Subscriptions[index].valid = false;
|
||||
COV_Subscriptions[index].subscriberProcessIdentifier = 0;
|
||||
COV_Subscriptions[index].monitoredObjectIdentifier.type = OBJECT_ANALOG_INPUT;
|
||||
COV_Subscriptions[index].monitoredObjectIdentifier.type =
|
||||
OBJECT_ANALOG_INPUT;
|
||||
COV_Subscriptions[index].monitoredObjectIdentifier.instance = 0;
|
||||
COV_Subscriptions[index].issueConfirmedNotifications = false;
|
||||
COV_Subscriptions[index].lifetime = 0;
|
||||
COV_Subscriptions[index].monitoredProperty.propertyIdentifier = PROP_ALL;
|
||||
COV_Subscriptions[index].monitoredProperty.propertyIdentifier =
|
||||
PROP_ALL;
|
||||
COV_Subscriptions[index].monitoredProperty.propertyArrayIndex = -1;
|
||||
COV_Subscriptions[index].covIncrementPresent = false;
|
||||
COV_Subscriptions[index].covIncrement = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void handler_cov_task(void)
|
||||
void handler_cov_task(
|
||||
void)
|
||||
{
|
||||
/* handle timeouts */
|
||||
/* handle COV notifications */
|
||||
@@ -106,9 +110,11 @@ static bool cov_subscribe(
|
||||
return status;
|
||||
}
|
||||
|
||||
void handler_cov_subscribe(uint8_t * service_request,
|
||||
void handler_cov_subscribe(
|
||||
uint8_t * service_request,
|
||||
uint16_t service_len,
|
||||
BACNET_ADDRESS * src, BACNET_CONFIRMED_SERVICE_DATA * service_data)
|
||||
BACNET_ADDRESS * src,
|
||||
BACNET_CONFIRMED_SERVICE_DATA * service_data)
|
||||
{
|
||||
BACNET_SUBSCRIBE_COV_DATA cov_data;
|
||||
int len = 0;
|
||||
@@ -123,27 +129,31 @@ void handler_cov_subscribe(uint8_t * service_request,
|
||||
/* encode the NPDU portion of the packet */
|
||||
datalink_get_my_address(&my_address);
|
||||
npdu_encode_npdu_data(&npdu_data, false, MESSAGE_PRIORITY_NORMAL);
|
||||
pdu_len = npdu_encode_pdu(&Handler_Transmit_Buffer[0], src,
|
||||
&my_address, &npdu_data);
|
||||
pdu_len =
|
||||
npdu_encode_pdu(&Handler_Transmit_Buffer[0], src, &my_address,
|
||||
&npdu_data);
|
||||
if (service_data->segmented_message) {
|
||||
/* we don't support segmentation - send an abort */
|
||||
len = abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
|
||||
service_data->invoke_id,
|
||||
ABORT_REASON_SEGMENTATION_NOT_SUPPORTED, true);
|
||||
len =
|
||||
abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
|
||||
service_data->invoke_id, ABORT_REASON_SEGMENTATION_NOT_SUPPORTED,
|
||||
true);
|
||||
#if PRINT_ENABLED
|
||||
fprintf(stderr, "SubscribeCOV: Segmented message. Sending Abort!\n");
|
||||
#endif
|
||||
goto COV_ABORT;
|
||||
}
|
||||
len = cov_subscribe_decode_service_request(service_request,
|
||||
service_len, &cov_data);
|
||||
len =
|
||||
cov_subscribe_decode_service_request(service_request, service_len,
|
||||
&cov_data);
|
||||
#if PRINT_ENABLED
|
||||
if (len <= 0)
|
||||
fprintf(stderr, "SubscribeCOV: Unable to decode Request!\n");
|
||||
#endif
|
||||
if (len < 0) {
|
||||
/* bad decoding - send an abort */
|
||||
len = abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
|
||||
len =
|
||||
abort_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
|
||||
service_data->invoke_id, ABORT_REASON_OTHER, true);
|
||||
#if PRINT_ENABLED
|
||||
fprintf(stderr, "SubscribeCOV: Bad decoding. Sending Abort!\n");
|
||||
@@ -152,33 +162,30 @@ void handler_cov_subscribe(uint8_t * service_request,
|
||||
}
|
||||
success = cov_subscribe(&cov_data, &error_class, &error_code);
|
||||
if (success) {
|
||||
len = encode_simple_ack(
|
||||
&Handler_Transmit_Buffer[pdu_len],
|
||||
service_data->invoke_id,
|
||||
SERVICE_CONFIRMED_SUBSCRIBE_COV);
|
||||
len =
|
||||
encode_simple_ack(&Handler_Transmit_Buffer[pdu_len],
|
||||
service_data->invoke_id, SERVICE_CONFIRMED_SUBSCRIBE_COV);
|
||||
#if PRINT_ENABLED
|
||||
fprintf(stderr,
|
||||
"SubscribeCOV: Sending Simple Ack!\n");
|
||||
fprintf(stderr, "SubscribeCOV: Sending Simple Ack!\n");
|
||||
#endif
|
||||
} else {
|
||||
len = bacerror_encode_apdu(
|
||||
&Handler_Transmit_Buffer[pdu_len],
|
||||
service_data->invoke_id,
|
||||
SERVICE_CONFIRMED_SUBSCRIBE_COV,
|
||||
error_class,
|
||||
error_code);
|
||||
len =
|
||||
bacerror_encode_apdu(&Handler_Transmit_Buffer[pdu_len],
|
||||
service_data->invoke_id, SERVICE_CONFIRMED_SUBSCRIBE_COV,
|
||||
error_class, error_code);
|
||||
#if PRINT_ENABLED
|
||||
fprintf(stderr,
|
||||
"SubscribeCOV: Sending Error!\n");
|
||||
fprintf(stderr, "SubscribeCOV: Sending Error!\n");
|
||||
#endif
|
||||
}
|
||||
COV_ABORT:
|
||||
pdu_len += len;
|
||||
bytes_sent = datalink_send_pdu(src, &npdu_data,
|
||||
&Handler_Transmit_Buffer[0], pdu_len);
|
||||
bytes_sent =
|
||||
datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0],
|
||||
pdu_len);
|
||||
#if PRINT_ENABLED
|
||||
if (bytes_sent <= 0)
|
||||
fprintf(stderr, "SubscribeCOV: Failed to send PDU (%s)!\n", strerror(errno));
|
||||
fprintf(stderr, "SubscribeCOV: Failed to send PDU (%s)!\n",
|
||||
strerror(errno));
|
||||
#endif
|
||||
|
||||
return;
|
||||
|
||||
@@ -169,7 +169,8 @@ static bool Binary_Input_Out_Of_Service(
|
||||
}
|
||||
|
||||
static void Binary_Input_Present_Value_Set(
|
||||
uint32_t object_instance, BACNET_BINARY_PV value)
|
||||
uint32_t object_instance,
|
||||
BACNET_BINARY_PV value)
|
||||
{
|
||||
unsigned index = 0;
|
||||
|
||||
@@ -182,7 +183,8 @@ static void Binary_Input_Present_Value_Set(
|
||||
}
|
||||
|
||||
static void Binary_Input_Out_Of_Service_Set(
|
||||
uint32_t object_instance, bool value)
|
||||
uint32_t object_instance,
|
||||
bool value)
|
||||
{
|
||||
unsigned index = 0;
|
||||
|
||||
@@ -264,7 +266,8 @@ int Binary_Input_Encode_Property_APDU(
|
||||
encode_application_enumerated(&apdu[0], EVENT_STATE_NORMAL);
|
||||
break;
|
||||
case PROP_OUT_OF_SERVICE:
|
||||
apdu_len = encode_application_boolean(&apdu[0],
|
||||
apdu_len =
|
||||
encode_application_boolean(&apdu[0],
|
||||
Binary_Input_Out_Of_Service(object_instance));
|
||||
break;
|
||||
case PROP_POLARITY:
|
||||
@@ -307,8 +310,7 @@ bool Binary_Input_Write_Property(
|
||||
if (value.tag == BACNET_APPLICATION_TAG_ENUMERATED) {
|
||||
if ((value.type.Enumerated >= MIN_BINARY_PV) &&
|
||||
(value.type.Enumerated <= MAX_BINARY_PV)) {
|
||||
Binary_Input_Present_Value_Set(
|
||||
wp_data->object_instance,
|
||||
Binary_Input_Present_Value_Set(wp_data->object_instance,
|
||||
(BACNET_BINARY_PV) value.type.Enumerated);
|
||||
status = true;
|
||||
} else {
|
||||
@@ -322,8 +324,7 @@ bool Binary_Input_Write_Property(
|
||||
break;
|
||||
case PROP_OUT_OF_SERVICE:
|
||||
if (value.tag == BACNET_APPLICATION_TAG_BOOLEAN) {
|
||||
Binary_Input_Out_Of_Service_Set(
|
||||
wp_data->object_instance,
|
||||
Binary_Input_Out_Of_Service_Set(wp_data->object_instance,
|
||||
value.type.Boolean);
|
||||
status = true;
|
||||
} else {
|
||||
|
||||
@@ -9,7 +9,8 @@
|
||||
|
||||
#if defined(__ZTC__) && !defined(__SC__)
|
||||
|
||||
void FAR * getvect(unsigned intnum)
|
||||
void FAR *getvect(
|
||||
unsigned intnum)
|
||||
{
|
||||
unsigned seg, off;
|
||||
|
||||
@@ -17,7 +18,9 @@ void FAR * getvect(unsigned intnum)
|
||||
return MK_FP(seg, off);
|
||||
}
|
||||
|
||||
void setvect(unsigned intnum, void (INTERRUPT FAR *handler)())
|
||||
void setvect(
|
||||
unsigned intnum,
|
||||
void (INTERRUPT FAR * handler) ())
|
||||
{
|
||||
unsigned seg = FP_SEG(handler), off = FP_OFF(handler);
|
||||
|
||||
@@ -35,7 +38,9 @@ void setvect(unsigned intnum, void (INTERRUPT FAR *handler)())
|
||||
#define MK_FP(seg,off) ((void far *)(((long)(seg) << 16)|(unsigned)(off)))
|
||||
#endif
|
||||
|
||||
unsigned char Peekb(unsigned seg, unsigned ofs)
|
||||
unsigned char Peekb(
|
||||
unsigned seg,
|
||||
unsigned ofs)
|
||||
{
|
||||
unsigned char FAR *ptr;
|
||||
|
||||
@@ -43,7 +48,9 @@ unsigned char Peekb(unsigned seg, unsigned ofs)
|
||||
return *ptr;
|
||||
}
|
||||
|
||||
unsigned short Peekw(unsigned seg, unsigned ofs)
|
||||
unsigned short Peekw(
|
||||
unsigned seg,
|
||||
unsigned ofs)
|
||||
{
|
||||
unsigned FAR *ptr;
|
||||
|
||||
@@ -51,7 +58,10 @@ unsigned short Peekw(unsigned seg, unsigned ofs)
|
||||
return *ptr;
|
||||
}
|
||||
|
||||
void Pokeb(unsigned seg, unsigned ofs, unsigned char ch)
|
||||
void Pokeb(
|
||||
unsigned seg,
|
||||
unsigned ofs,
|
||||
unsigned char ch)
|
||||
{
|
||||
unsigned char FAR *ptr;
|
||||
|
||||
@@ -59,7 +69,10 @@ void Pokeb(unsigned seg, unsigned ofs, unsigned char ch)
|
||||
*ptr = ch;
|
||||
}
|
||||
|
||||
void Pokew(unsigned seg, unsigned ofs, unsigned short num)
|
||||
void Pokew(
|
||||
unsigned seg,
|
||||
unsigned ofs,
|
||||
unsigned short num)
|
||||
{
|
||||
unsigned FAR *ptr;
|
||||
|
||||
|
||||
@@ -29,8 +29,11 @@
|
||||
#define enable int_on
|
||||
#define disable int_off
|
||||
#if !defined(__SC__)
|
||||
void FAR * getvect(unsigned intnum);
|
||||
void setvect(unsigned intnum, void (INTERRUPT FAR *handler)());
|
||||
void FAR *getvect(
|
||||
unsigned intnum);
|
||||
void setvect(
|
||||
unsigned intnum,
|
||||
void (INTERRUPT FAR * handler) ());
|
||||
#else
|
||||
#define getvect _dos_getvect
|
||||
#define setvect _dos_setvect
|
||||
@@ -50,10 +53,20 @@
|
||||
#if defined(_MSC_VER) || defined(__WATCOMC__) || \
|
||||
defined(__ZTC__) || defined(__SC__)
|
||||
|
||||
unsigned char Peekb(unsigned seg, unsigned ofs); /* PCHWIO.C */
|
||||
unsigned short Peekw(unsigned seg, unsigned ofs); /* PCHWIO.C */
|
||||
void Pokeb(unsigned seg, unsigned ofs, unsigned char ch); /* PCHWIO.C */
|
||||
void Pokew(unsigned seg, unsigned ofs, unsigned short num); /* PCHWIO.C */
|
||||
unsigned char Peekb(
|
||||
unsigned seg,
|
||||
unsigned ofs); /* PCHWIO.C */
|
||||
unsigned short Peekw(
|
||||
unsigned seg,
|
||||
unsigned ofs); /* PCHWIO.C */
|
||||
void Pokeb(
|
||||
unsigned seg,
|
||||
unsigned ofs,
|
||||
unsigned char ch); /* PCHWIO.C */
|
||||
void Pokew(
|
||||
unsigned seg,
|
||||
unsigned ofs,
|
||||
unsigned short num); /* PCHWIO.C */
|
||||
|
||||
#elif defined(__TURBOC__)
|
||||
#define Peekw peek
|
||||
|
||||
@@ -20,11 +20,13 @@
|
||||
|
||||
#include "queue.h"
|
||||
|
||||
QUEUE *alloc_queue( int size)
|
||||
{ QUEUE *retval;
|
||||
QUEUE *alloc_queue(
|
||||
int size)
|
||||
{
|
||||
QUEUE *retval;
|
||||
retval = (QUEUE *) malloc(sizeof(QUEUE) + (size_t) size);
|
||||
if ( (QUEUE *) 0 != retval)
|
||||
{ retval->size = size;
|
||||
if ((QUEUE *) 0 != retval) {
|
||||
retval->size = size;
|
||||
retval->head = 0;
|
||||
retval->tail = 0;
|
||||
retval->avail = size;
|
||||
@@ -33,10 +35,13 @@ QUEUE *alloc_queue( int size)
|
||||
return retval;
|
||||
}
|
||||
|
||||
int en_queue( QUEUE *queue, char data)
|
||||
{ int retval = -1;
|
||||
if ( 0 != queue->avail)
|
||||
{ *( queue->buffer + queue->head) = data;
|
||||
int en_queue(
|
||||
QUEUE * queue,
|
||||
char data)
|
||||
{
|
||||
int retval = -1;
|
||||
if (0 != queue->avail) {
|
||||
*(queue->buffer + queue->head) = data;
|
||||
queue->head += 1;
|
||||
if (queue->head == queue->size)
|
||||
queue->head = 0;
|
||||
@@ -46,10 +51,12 @@ int en_queue( QUEUE *queue, char data)
|
||||
return retval;
|
||||
}
|
||||
|
||||
int de_queue( QUEUE *queue)
|
||||
{ int retval = -1;
|
||||
if ( queue->avail != queue->size)
|
||||
{ retval = *( queue->buffer + queue->tail);
|
||||
int de_queue(
|
||||
QUEUE * queue)
|
||||
{
|
||||
int retval = -1;
|
||||
if (queue->avail != queue->size) {
|
||||
retval = *(queue->buffer + queue->tail);
|
||||
queue->tail += 1;
|
||||
if (queue->tail == queue->size)
|
||||
queue->tail = 0;
|
||||
|
||||
@@ -21,8 +21,8 @@
|
||||
|
||||
/* Needed by Serial.C */
|
||||
|
||||
typedef struct
|
||||
{ int size;
|
||||
typedef struct {
|
||||
int size;
|
||||
int head;
|
||||
int tail;
|
||||
int avail;
|
||||
@@ -32,9 +32,13 @@ typedef struct
|
||||
#define queue_empty(queue) (queue)->head == (queue)->tail
|
||||
#define queue_avail(queue) (queue)->avail
|
||||
|
||||
QUEUE *alloc_queue( int size);
|
||||
int en_queue( QUEUE *queue_ptr, char data);
|
||||
int de_queue( QUEUE *queue_ptr);
|
||||
QUEUE *alloc_queue(
|
||||
int size);
|
||||
int en_queue(
|
||||
QUEUE * queue_ptr,
|
||||
char data);
|
||||
int de_queue(
|
||||
QUEUE * queue_ptr);
|
||||
|
||||
/* End of Queue.H */
|
||||
|
||||
|
||||
@@ -37,30 +37,28 @@ QUEUE *Serial_Out_Queue;
|
||||
OLD_COMM_PARAMS old_comm_params;
|
||||
COMM_STATUS comm_status;
|
||||
|
||||
void (INTERRUPT FAR *oldvector_serial )();
|
||||
void (
|
||||
INTERRUPT FAR * oldvector_serial) (
|
||||
);
|
||||
/* save addr for intr handler */
|
||||
|
||||
int ComBase; /* Comm port address */
|
||||
int IrqNum; /* Comm interrupt request */
|
||||
|
||||
void CloseComPort ( void )
|
||||
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 );
|
||||
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(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 */
|
||||
@@ -74,8 +72,9 @@ void CloseComPort ( void )
|
||||
return;
|
||||
}
|
||||
|
||||
int OpenComPort ( char Port ) /* install int. handler */
|
||||
{
|
||||
int OpenComPort(
|
||||
char Port)
|
||||
{ /* install int. handler */
|
||||
unsigned status;
|
||||
int retval = -1;
|
||||
|
||||
@@ -85,8 +84,7 @@ int OpenComPort ( char Port ) /* install int. handler */
|
||||
if ((QUEUE *) 0 == Serial_In_Queue)
|
||||
return retval;
|
||||
Serial_Out_Queue = alloc_queue(SerOutBufSize);
|
||||
if ( (QUEUE *) 0 == Serial_Out_Queue)
|
||||
{
|
||||
if ((QUEUE *) 0 == Serial_Out_Queue) {
|
||||
free(Serial_In_Queue);
|
||||
return retval;
|
||||
}
|
||||
@@ -94,13 +92,27 @@ int OpenComPort ( char Port ) /* install int. handler */
|
||||
|
||||
/* Setup Comm base port address and IRQ number */
|
||||
|
||||
switch ( Port)
|
||||
{
|
||||
case '1': ComBase = 0x3F8; IrqNum = 4; break;
|
||||
case '2': ComBase = 0x2F8; IrqNum = 3; break;
|
||||
case '3': ComBase = 0x3E8; IrqNum = 4; break;
|
||||
case '4': ComBase = 0x2E8; IrqNum = 3; break;
|
||||
default : ComBase = 0x3F8; IrqNum = 4; break;
|
||||
switch (Port) {
|
||||
case '1':
|
||||
ComBase = 0x3F8;
|
||||
IrqNum = 4;
|
||||
break;
|
||||
case '2':
|
||||
ComBase = 0x2F8;
|
||||
IrqNum = 3;
|
||||
break;
|
||||
case '3':
|
||||
ComBase = 0x3E8;
|
||||
IrqNum = 4;
|
||||
break;
|
||||
case '4':
|
||||
ComBase = 0x2E8;
|
||||
IrqNum = 3;
|
||||
break;
|
||||
default:
|
||||
ComBase = 0x3F8;
|
||||
IrqNum = 4;
|
||||
break;
|
||||
}
|
||||
old_comm_params.int_enable = inp(ComBase + INT_EN);
|
||||
outp(ComBase + INT_EN, 0); /* turn off comm interrupts */
|
||||
@@ -134,16 +146,19 @@ int OpenComPort ( char Port ) /* install int. handler */
|
||||
|
||||
/* ok enable comm ints */
|
||||
|
||||
outp ( 0x21, (unsigned char) old_comm_params.int_cntrl &
|
||||
(unsigned char) status );
|
||||
outp(0x21,
|
||||
(unsigned char) old_comm_params.int_cntrl & (unsigned char) status);
|
||||
|
||||
atexit(CloseComPort);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
void InitComPort ( char Baud[], char Databits,
|
||||
char Parity, char Stopbits )
|
||||
void InitComPort(
|
||||
char Baud[],
|
||||
char Databits,
|
||||
char Parity,
|
||||
char Stopbits)
|
||||
{
|
||||
int status;
|
||||
unsigned divisor;
|
||||
@@ -152,43 +167,42 @@ void InitComPort ( char Baud[], char Databits,
|
||||
/* set baud rate */
|
||||
|
||||
status = inp(ComBase + LINE_CNTRL);
|
||||
outp ( ComBase + LINE_CNTRL,
|
||||
(unsigned char) status | 0x80 );
|
||||
outp(ComBase + LINE_CNTRL, (unsigned char) status | 0x80);
|
||||
baudrate = atol(Baud);
|
||||
if (baudrate == 0)
|
||||
baudrate = 2400L;
|
||||
divisor = (unsigned) (115200L / baudrate);
|
||||
outp ( ComBase + BAUD_LSB,
|
||||
(unsigned char) ( divisor & 0x00FF) );
|
||||
outp ( ComBase + BAUD_MSB,
|
||||
(unsigned char) ( ( divisor >> 8) & 0x00FF) );
|
||||
outp(ComBase + BAUD_LSB, (unsigned char) (divisor & 0x00FF));
|
||||
outp(ComBase + BAUD_MSB, (unsigned char) ((divisor >> 8) & 0x00FF));
|
||||
status = 0x00;
|
||||
|
||||
/* set parity */
|
||||
|
||||
switch ( Parity) /* set parity value */
|
||||
{
|
||||
switch (Parity) { /* set parity value */
|
||||
case 'O': /* odd parity */
|
||||
case 'o':
|
||||
status = 0x08; break;
|
||||
status = 0x08;
|
||||
break;
|
||||
|
||||
case 'E': /* even parity */
|
||||
case 'e':
|
||||
status = 0x18; break;
|
||||
status = 0x18;
|
||||
break;
|
||||
|
||||
case 'S': /* stick parity */
|
||||
case 's':
|
||||
status = 0x28; break;
|
||||
status = 0x28;
|
||||
break;
|
||||
|
||||
case 'N': /* no parity */
|
||||
case 'n':
|
||||
default : status = 0x00;
|
||||
default:
|
||||
status = 0x00;
|
||||
}
|
||||
|
||||
/* set number data bits */
|
||||
|
||||
switch ( Databits)
|
||||
{
|
||||
switch (Databits) {
|
||||
case '5':
|
||||
break;
|
||||
|
||||
@@ -207,8 +221,7 @@ void InitComPort ( char Baud[], char Databits,
|
||||
|
||||
/* set number stop bits */
|
||||
|
||||
switch ( Stopbits)
|
||||
{
|
||||
switch (Stopbits) {
|
||||
case '2':
|
||||
status = status | 0x04;
|
||||
break;
|
||||
@@ -227,7 +240,8 @@ void InitComPort ( char Baud[], char Databits,
|
||||
return;
|
||||
}
|
||||
|
||||
void DropDtr ( void )
|
||||
void DropDtr(
|
||||
void)
|
||||
{
|
||||
int status;
|
||||
|
||||
@@ -237,7 +251,8 @@ void DropDtr ( void )
|
||||
return;
|
||||
}
|
||||
|
||||
void RaiseDtr ( void )
|
||||
void RaiseDtr(
|
||||
void)
|
||||
{
|
||||
int status;
|
||||
|
||||
@@ -247,19 +262,20 @@ void RaiseDtr ( void )
|
||||
return;
|
||||
}
|
||||
|
||||
int ComRecChar ( void )
|
||||
int ComRecChar(
|
||||
void)
|
||||
{
|
||||
return de_queue(Serial_In_Queue);
|
||||
}
|
||||
|
||||
int ComSendString ( char *string )
|
||||
int ComSendString(
|
||||
char *string)
|
||||
{
|
||||
int retval;
|
||||
char *pointer;
|
||||
pointer = string;
|
||||
|
||||
while ( *pointer)
|
||||
{
|
||||
while (*pointer) {
|
||||
retval = en_queue(Serial_Out_Queue, *pointer);
|
||||
pointer++;
|
||||
}
|
||||
@@ -269,15 +285,16 @@ int ComSendString ( char *string )
|
||||
return retval;
|
||||
}
|
||||
|
||||
int ComSendData ( char *buffer, unsigned buffer_length )
|
||||
int ComSendData(
|
||||
char *buffer,
|
||||
unsigned buffer_length)
|
||||
{
|
||||
int retval;
|
||||
char *pointer;
|
||||
pointer = buffer;
|
||||
unsigned i;
|
||||
|
||||
for (i = 0; i < buffer_length; i++)
|
||||
{
|
||||
for (i = 0; i < buffer_length; i++) {
|
||||
retval = en_queue(Serial_Out_Queue, *pointer);
|
||||
pointer++;
|
||||
}
|
||||
@@ -287,7 +304,8 @@ int ComSendData ( char *buffer, unsigned buffer_length )
|
||||
return retval;
|
||||
}
|
||||
|
||||
int ComSendChar ( char character )
|
||||
int ComSendChar(
|
||||
char character)
|
||||
{
|
||||
int retval;
|
||||
|
||||
@@ -301,7 +319,8 @@ int ComSendChar ( char character )
|
||||
return retval;
|
||||
}
|
||||
|
||||
int ComStatus ( void )
|
||||
int ComStatus(
|
||||
void)
|
||||
{
|
||||
unsigned status;
|
||||
unsigned retval;
|
||||
@@ -312,21 +331,21 @@ int ComStatus ( void )
|
||||
retval = retval | status;
|
||||
if (queue_empty(Serial_In_Queue))
|
||||
retval &= 0xFEFF;
|
||||
else retval |= 0x0100;
|
||||
else
|
||||
retval |= 0x0100;
|
||||
return (int) retval;
|
||||
}
|
||||
|
||||
void INTERRUPT FAR serial ( void ) /* interrupt handler */
|
||||
{
|
||||
void INTERRUPT FAR serial(
|
||||
void)
|
||||
{ /* interrupt handler */
|
||||
int temp;
|
||||
|
||||
disable();
|
||||
while ( 1)
|
||||
{
|
||||
while (1) {
|
||||
comm_status.intrupt = inp(ComBase + INT_ID);
|
||||
comm_status.intrupt &= 0x0f;
|
||||
switch ( comm_status.intrupt)
|
||||
{
|
||||
switch (comm_status.intrupt) {
|
||||
case 0x00: /* modem interrupt */
|
||||
comm_status.modem = inp(ComBase + MODEM_STATUS);
|
||||
break;
|
||||
@@ -334,8 +353,7 @@ void INTERRUPT FAR serial ( void ) /* interrupt handler */
|
||||
case 0x02: /* xmit interrupt */
|
||||
if (queue_empty(Serial_Out_Queue))
|
||||
outp(ComBase + INT_EN, RX_INT | ERR_INT | RS_INT);
|
||||
else
|
||||
{
|
||||
else {
|
||||
temp = de_queue(Serial_Out_Queue);
|
||||
if (-1 != temp)
|
||||
outp(ComBase + XMIT, temp);
|
||||
@@ -360,4 +378,5 @@ void INTERRUPT FAR serial ( void ) /* interrupt handler */
|
||||
} /* switch */
|
||||
} /* while */
|
||||
}
|
||||
|
||||
/* End of Serial.C */
|
||||
|
||||
@@ -66,13 +66,15 @@
|
||||
#define TRUE !FALSE
|
||||
#endif
|
||||
|
||||
extern void (INTERRUPT FAR *oldvector_serial )( void);
|
||||
extern void (
|
||||
INTERRUPT FAR * oldvector_serial) (
|
||||
void);
|
||||
|
||||
extern int ComBase; /* Comm port address */
|
||||
extern int IrqNum; /* Comm interrupt request */
|
||||
|
||||
typedef struct /* Save existing comm params */
|
||||
{ int int_enable; /* old interrupt enable reg value*/
|
||||
typedef struct { /* Save existing comm params */
|
||||
int int_enable; /* old interrupt enable reg value */
|
||||
int line; /* " line control " " */
|
||||
int modem; /* old modem control " " */
|
||||
int baud_lsb; /* old baud rate divisor LSD */
|
||||
@@ -81,26 +83,41 @@ typedef struct /* Save existing comm params */
|
||||
} OLD_COMM_PARAMS;
|
||||
extern OLD_COMM_PARAMS old_comm_params;
|
||||
|
||||
typedef struct
|
||||
{ int line; /* Uart line status reg. */
|
||||
typedef struct {
|
||||
int line; /* Uart line status reg. */
|
||||
int modem; /* Uart mode status reg. */
|
||||
int intrupt; /* Uart interrupt reg. */
|
||||
int handshake; /* Handshake status */
|
||||
} COMM_STATUS; /* status, updated, handler */
|
||||
extern COMM_STATUS comm_status;
|
||||
|
||||
int OpenComPort ( char Port ); /*setup comm for usage */
|
||||
void InitComPort ( char Baud[], char Databits, char Parity, char Stop );
|
||||
void CloseComPort ( void ); /* Restore comm port */
|
||||
void DropDtr ( void ); /* Lower DTR */
|
||||
void RaiseDtr ( void ); /* Raise DTR */
|
||||
int ComRecChar ( void ); /* Fetch character from rcv buf*/
|
||||
int OpenComPort(
|
||||
char Port); /*setup comm for usage */
|
||||
void InitComPort(
|
||||
char Baud[],
|
||||
char Databits,
|
||||
char Parity,
|
||||
char Stop);
|
||||
void CloseComPort(
|
||||
void); /* Restore comm port */
|
||||
void DropDtr(
|
||||
void); /* Lower DTR */
|
||||
void RaiseDtr(
|
||||
void); /* Raise DTR */
|
||||
int ComRecChar(
|
||||
void); /* Fetch character from rcv buf */
|
||||
|
||||
int ComSendChar ( char character ); /* Put char into xmit buffer */
|
||||
int ComSendString ( char *string );
|
||||
int ComSendData ( char *buffer, unsigned buffer_length );
|
||||
int ComStatus ( void ); /* Fetch comm status */
|
||||
void INTERRUPT FAR serial ( void ); /* interrupt handler */
|
||||
int ComSendChar(
|
||||
char character); /* Put char into xmit buffer */
|
||||
int ComSendString(
|
||||
char *string);
|
||||
int ComSendData(
|
||||
char *buffer,
|
||||
unsigned buffer_length);
|
||||
int ComStatus(
|
||||
void); /* Fetch comm status */
|
||||
void INTERRUPT FAR serial(
|
||||
void); /* interrupt handler */
|
||||
|
||||
/* End of Serial.H */
|
||||
|
||||
|
||||
@@ -64,19 +64,45 @@ static uint8_t RTC_RS_Convert(
|
||||
*/
|
||||
/* FIXME: create a clever formula to replace switch */
|
||||
switch (hertz) {
|
||||
case 8192: RS = 3; break;
|
||||
case 4096: RS = 4; break;
|
||||
case 2048: RS = 5; break;
|
||||
case 1024: RS = 6; break;
|
||||
case 512: RS = 7; break;
|
||||
case 256: RS = 8; break;
|
||||
case 128: RS = 9; break;
|
||||
case 64: RS = 10; break;
|
||||
case 32: RS = 11; break;
|
||||
case 16: RS = 12; break;
|
||||
case 8: RS = 13; break;
|
||||
case 4: RS = 14; break;
|
||||
case 2: RS = 15; break;
|
||||
case 8192:
|
||||
RS = 3;
|
||||
break;
|
||||
case 4096:
|
||||
RS = 4;
|
||||
break;
|
||||
case 2048:
|
||||
RS = 5;
|
||||
break;
|
||||
case 1024:
|
||||
RS = 6;
|
||||
break;
|
||||
case 512:
|
||||
RS = 7;
|
||||
break;
|
||||
case 256:
|
||||
RS = 8;
|
||||
break;
|
||||
case 128:
|
||||
RS = 9;
|
||||
break;
|
||||
case 64:
|
||||
RS = 10;
|
||||
break;
|
||||
case 32:
|
||||
RS = 11;
|
||||
break;
|
||||
case 16:
|
||||
RS = 12;
|
||||
break;
|
||||
case 8:
|
||||
RS = 13;
|
||||
break;
|
||||
case 4:
|
||||
RS = 14;
|
||||
break;
|
||||
case 2:
|
||||
RS = 15;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -122,9 +148,12 @@ static void interrupt Timer_Interrupt_Handler(
|
||||
}
|
||||
|
||||
/* previous interrrupt vector */
|
||||
static void interrupt(*OldVector)();
|
||||
static void interrupt(
|
||||
*OldVector) (
|
||||
);
|
||||
|
||||
void Timer_Cleanup(void)
|
||||
void Timer_Cleanup(
|
||||
void)
|
||||
{
|
||||
setvect(0x70, OldVector);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user