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