Indented.

This commit is contained in:
skarg
2007-12-07 20:15:56 +00:00
parent eb72c8cb64
commit 32457a68c0
15 changed files with 691 additions and 581 deletions
+44 -37
View File
@@ -47,7 +47,7 @@
#include "lsp.h" #include "lsp.h"
#include "mso.h" #include "mso.h"
#if defined(BACFILE) #if defined(BACFILE)
#include "bacfile.h" #include "bacfile.h"
#endif #endif
typedef struct BACnet_COV_Subscription { typedef struct BACnet_COV_Subscription {
@@ -55,45 +55,49 @@ typedef struct BACnet_COV_Subscription {
uint32_t subscriberProcessIdentifier; uint32_t subscriberProcessIdentifier;
BACNET_OBJECT_ID monitoredObjectIdentifier; BACNET_OBJECT_ID monitoredObjectIdentifier;
bool issueConfirmedNotifications; /* optional */ bool issueConfirmedNotifications; /* optional */
unsigned lifetime; /* optional */ unsigned lifetime; /* optional */
BACNET_PROPERTY_REFERENCE monitoredProperty; BACNET_PROPERTY_REFERENCE monitoredProperty;
bool covIncrementPresent; /* true if present */ bool covIncrementPresent; /* true if present */
float covIncrement; /* optional */ float covIncrement; /* optional */
} BACNET_COV_SUBSCRIPTION; } 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 */
} }
static bool cov_subscribe( static bool cov_subscribe(
BACNET_SUBSCRIBE_COV_DATA *cov_data, BACNET_SUBSCRIBE_COV_DATA * cov_data,
BACNET_ERROR_CLASS * error_class, BACNET_ERROR_CLASS * error_class,
BACNET_ERROR_CODE * error_code) BACNET_ERROR_CODE * error_code)
{ {
bool status = false; /* return value */ bool status = false; /* return value */
switch (cov_data->monitoredObjectIdentifier.type) { switch (cov_data->monitoredObjectIdentifier.type) {
case OBJECT_BINARY_INPUT: case OBJECT_BINARY_INPUT:
@@ -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;
+8 -7
View File
@@ -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 {
+3 -3
View File
@@ -659,9 +659,9 @@ typedef enum {
LIFE_SAFETY_OP_UNSILENCE = 7, LIFE_SAFETY_OP_UNSILENCE = 7,
LIFE_SAFETY_OP_UNSILENCE_AUDIBLE = 8, LIFE_SAFETY_OP_UNSILENCE_AUDIBLE = 8,
LIFE_SAFETY_OP_UNSILENCE_VISUAL = 9 LIFE_SAFETY_OP_UNSILENCE_VISUAL = 9
/* Enumerated values 0-63 are reserved for definition by ASHRAE. */ /* Enumerated values 0-63 are reserved for definition by ASHRAE. */
/* Enumerated values 64-65535 may be used by others subject to */ /* Enumerated values 64-65535 may be used by others subject to */
/* procedures and constraints described in Clause 23. */ /* procedures and constraints described in Clause 23. */
} BACNET_LIFE_SAFETY_OPERATION; } BACNET_LIFE_SAFETY_OPERATION;
typedef enum { typedef enum {
+84 -84
View File
@@ -25,26 +25,26 @@
#ifndef EXTKWORD__H #ifndef EXTKWORD__H
#define EXTKWORD__H #define EXTKWORD__H
#include <limits.h> /* For INT_MAX, LONG_MAX */ #include <limits.h> /* For INT_MAX, LONG_MAX */
/* /*
** Watcom defines __FLAT__ for 32-bit environments and so will we ** Watcom defines __FLAT__ for 32-bit environments and so will we
*/ */
#if !defined(__FLAT__) && !defined(__WATCOMC__) && !defined(_MSC_VER) #if !defined(__FLAT__) && !defined(__WATCOMC__) && !defined(_MSC_VER)
#if defined(__GNUC__) #if defined(__GNUC__)
#define __FLAT__ 1 #define __FLAT__ 1
#elif defined (_WIN32) || defined(WIN32) || defined(__NT__) #elif defined (_WIN32) || defined(WIN32) || defined(__NT__)
#define __FLAT__ 1 #define __FLAT__ 1
#elif defined(__INTSIZE) #elif defined(__INTSIZE)
#if (4 == __INTSIZE) #if (4 == __INTSIZE)
#define __FLAT__ 1 #define __FLAT__ 1
#endif #endif
#elif (defined(__ZTC__) && !defined(__SC__)) || defined(__TURBOC__) #elif (defined(__ZTC__) && !defined(__SC__)) || defined(__TURBOC__)
#if ((INT_MAX != SHRT_MAX) && (SHRT_MAX == 32767)) #if ((INT_MAX != SHRT_MAX) && (SHRT_MAX == 32767))
#define __FLAT__ 1 #define __FLAT__ 1
#endif #endif
#endif #endif
#endif #endif
/* /*
@@ -52,80 +52,80 @@
*/ */
#if defined(__unix__) #if defined(__unix__)
#if !defined(FAR) #if !defined(FAR)
#define FAR #define FAR
#endif #endif
#if !defined(NEAR) #if !defined(NEAR)
#define NEAR #define NEAR
#endif #endif
#if !defined(HUGE) #if !defined(HUGE)
#define HUGE #define HUGE
#endif #endif
#if !defined(PASCAL) #if !defined(PASCAL)
#define PASCAL #define PASCAL
#endif #endif
#if !defined(CDECL) #if !defined(CDECL)
#define CDECL #define CDECL
#endif #endif
#if !defined(INTERRUPT) #if !defined(INTERRUPT)
#define INTERRUPT #define INTERRUPT
#endif #endif
#elif defined(__OS2__) /* EBB: not sure this works for OS/2 1.x */ #elif defined(__OS2__) /* EBB: not sure this works for OS/2 1.x */
#include <os2def.h> #include <os2def.h>
#define INTERRUPT #define INTERRUPT
#ifndef HUGE #ifndef HUGE
#define HUGE #define HUGE
#endif #endif
#elif defined(_WIN32) || defined(WIN32) || defined(__NT__) #elif defined(_WIN32) || defined(WIN32) || defined(__NT__)
#define WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN
#define NOGDI #define NOGDI
#define NOSERVICE #define NOSERVICE
#undef INC_OLE1 #undef INC_OLE1
#undef INC_OLE2 #undef INC_OLE2
#include <windows.h> #include <windows.h>
#define INTERRUPT #define INTERRUPT
#ifndef HUGE #ifndef HUGE
#define HUGE #define HUGE
#endif #endif
#else /* ! Win 32 or OS/2 */ #else /* ! Win 32 or OS/2 */
#if (defined(__POWERC) || (defined(__TURBOC__) && !defined(__BORLANDC__)) \ #if (defined(__POWERC) || (defined(__TURBOC__) && !defined(__BORLANDC__)) \
|| (defined(__ZTC__) && !defined(__SC__))) && !defined(__FLAT__) || (defined(__ZTC__) && !defined(__SC__))) && !defined(__FLAT__)
#define FAR far #define FAR far
#define NEAR near #define NEAR near
#define PASCAL pascal #define PASCAL pascal
#define CDECL cdecl #define CDECL cdecl
#if (defined(__ZTC__) && !defined(__SC__)) || (defined(__SC__) && \ #if (defined(__ZTC__) && !defined(__SC__)) || (defined(__SC__) && \
(__SC__ < 0x700)) (__SC__ < 0x700))
#ifndef HUGE #ifndef HUGE
#define HUGE far #define HUGE far
#endif #endif
#define INTERRUPT #define INTERRUPT
#else #else
#ifndef HUGE #ifndef HUGE
#define HUGE huge #define HUGE huge
#endif #endif
#define INTERRUPT interrupt #define INTERRUPT interrupt
#endif #endif
#else #else
#if (defined(__MSDOS__) || defined(MSDOS)) && !defined(__FLAT__) #if (defined(__MSDOS__) || defined(MSDOS)) && !defined(__FLAT__)
#define FAR _far #define FAR _far
#define NEAR _near #define NEAR _near
#ifndef HUGE #ifndef HUGE
#define HUGE _huge #define HUGE _huge
#endif #endif
#define PASCAL _pascal #define PASCAL _pascal
#define CDECL _cdecl #define CDECL _cdecl
#define INTERRUPT _interrupt #define INTERRUPT _interrupt
#else #else
#define FAR #define FAR
#define NEAR #define NEAR
#ifndef HUGE #ifndef HUGE
#define HUGE #define HUGE
#endif #endif
#define PASCAL #define PASCAL
#define CDECL #define CDECL
#endif #endif
#endif #endif
#endif #endif
#endif /* EXTKWORD__H */ #endif /* EXTKWORD__H */
+3 -3
View File
@@ -10,13 +10,13 @@
#include "extkword.h" #include "extkword.h"
#if defined(__WATCOMC__) #if defined(__WATCOMC__)
#include <i86.h> #include <i86.h>
#elif !defined(__PACIFIC__) #elif !defined(__PACIFIC__)
#include <dos.h> #include <dos.h>
#endif #endif
#if !defined(MK_FP) #if !defined(MK_FP)
#define MK_FP(seg,off) \ #define MK_FP(seg,off) \
((void FAR *)(((unsigned long)(seg) << 16)|(unsigned)(off))) ((void FAR *)(((unsigned long)(seg) << 16)|(unsigned)(off)))
#endif #endif
+37 -24
View File
@@ -9,19 +9,22 @@
#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;
int_getvector(intnum, &off, &seg); int_getvector(intnum, &off, &seg);
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);
int_setvector(intnum, off, seg); int_setvector(intnum, off, seg);
} }
#endif /* ZTC getvect(), setvect() */ #endif /* ZTC getvect(), setvect() */
@@ -32,39 +35,49 @@ void setvect(unsigned intnum, void (INTERRUPT FAR *handler)())
defined(__ZTC__) || defined(__SC__) defined(__ZTC__) || defined(__SC__)
#if !defined(MK_FP) #if !defined(MK_FP)
#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;
ptr = MK_FP(seg, ofs); ptr = MK_FP(seg, 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;
ptr = MK_FP(seg, ofs); ptr = MK_FP(seg, 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;
ptr = MK_FP(seg, ofs); ptr = MK_FP(seg, ofs);
*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;
ptr = MK_FP(seg, ofs); ptr = MK_FP(seg, ofs);
*ptr = num; *ptr = num;
} }
#endif /* MSC/ZTC/WC Peek(), poke() */ #endif /* MSC/ZTC/WC Peek(), poke() */
+52 -39
View File
@@ -12,54 +12,67 @@
#if defined(__TURBOC__) || defined(__POWERC) #if defined(__TURBOC__) || defined(__POWERC)
#ifndef inp #ifndef inp
#define inp inportb #define inp inportb
#endif #endif
#ifndef outp #ifndef outp
#define outp outportb #define outp outportb
#endif #endif
#ifndef inpw #ifndef inpw
#define inpw inport #define inpw inport
#endif #endif
#ifndef outpw #ifndef outpw
#define outpw outport #define outpw outport
#endif #endif
#elif defined(__ZTC__) #elif defined(__ZTC__)
#include <int.h> #include <int.h>
#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);
#else void setvect(
#define getvect _dos_getvect unsigned intnum,
#define setvect _dos_setvect void (INTERRUPT FAR * handler) ());
#endif #else
#define getvect _dos_getvect
#define setvect _dos_setvect
#endif
#else /* assume MSC/QC/WC */ #else /* assume MSC/QC/WC */
#include <conio.h> #include <conio.h>
#if defined(__WATCOMC__) #if defined(__WATCOMC__)
#include <i86.h> #include <i86.h>
#endif #endif
#define enable _enable #define enable _enable
#define disable _disable #define disable _disable
#define getvect _dos_getvect #define getvect _dos_getvect
#define setvect _dos_setvect #define setvect _dos_setvect
#endif #endif
#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
#define Pokew poke #define Pokew poke
#define Peekb peekb #define Peekb peekb
#define Pokeb pokeb #define Pokeb pokeb
#endif /* peek(), poke() */ #endif /* peek(), poke() */
#endif /* PCHWIO__H */ #endif /* PCHWIO__H */
+39 -32
View File
@@ -20,42 +20,49 @@
#include "queue.h" #include "queue.h"
QUEUE *alloc_queue( int size) QUEUE *alloc_queue(
{ QUEUE *retval; int size)
retval = (QUEUE *) malloc( sizeof( QUEUE) + (size_t) size); {
if ( (QUEUE *) 0 != retval) QUEUE *retval;
{ retval->size = size; retval = (QUEUE *) malloc(sizeof(QUEUE) + (size_t) size);
retval->head = 0; if ((QUEUE *) 0 != retval) {
retval->tail = 0; retval->size = size;
retval->avail = size; retval->head = 0;
retval->buffer = ( (char *) retval) + sizeof( QUEUE); retval->tail = 0;
} retval->avail = size;
return retval; retval->buffer = ((char *) retval) + sizeof(QUEUE);
}
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; {
queue->head += 1; int retval = -1;
if ( queue->head == queue->size) if (0 != queue->avail) {
queue->head = 0; *(queue->buffer + queue->head) = data;
queue->avail -= 1; queue->head += 1;
retval = queue->avail; if (queue->head == queue->size)
} queue->head = 0;
return retval; queue->avail -= 1;
retval = queue->avail;
}
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;
queue->tail += 1; if (queue->avail != queue->size) {
if ( queue->tail == queue->size) retval = *(queue->buffer + queue->tail);
queue->tail = 0; queue->tail += 1;
queue->avail += 1; if (queue->tail == queue->size)
} queue->tail = 0;
return retval; queue->avail += 1;
}
return retval;
} }
/* End of Queue.c */ /* End of Queue.c */
+13 -9
View File
@@ -21,20 +21,24 @@
/* 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;
char *buffer; char *buffer;
} QUEUE; } QUEUE;
#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 */
+2 -2
View File
@@ -68,7 +68,7 @@ void RS485_Initialize(
/* baud rate */ /* baud rate */
OpenComPort(RS485_Port); OpenComPort(RS485_Port);
/* FIXME: change to numeric parameters */ /* FIXME: change to numeric parameters */
InitComPort ( "38400", '8', 'N', '1' ); InitComPort("38400", '8', 'N', '1');
return; return;
} }
@@ -110,7 +110,7 @@ bool RS485_Set_Baud_Rate(
case 76800: case 76800:
case 115200: case 115200:
RS485_Baud = baud; RS485_Baud = baud;
/* FIXME: store the baud rate */ /* FIXME: store the baud rate */
break; break;
default: default:
valid = false; valid = false;
+252 -233
View File
@@ -35,329 +35,348 @@ QUEUE *Serial_In_Queue;
QUEUE *Serial_Out_Queue; 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, (unsigned char) status | 0x80);
outp ( ComBase + LINE_CNTRL, outp(ComBase + BAUD_LSB, (unsigned char) old_comm_params.baud_lsb);
(unsigned char) status | 0x80 ); outp(ComBase + BAUD_MSB, (unsigned char) old_comm_params.baud_msb);
outp ( ComBase + BAUD_LSB, outp(ComBase + LINE_CNTRL, (unsigned char) old_comm_params.line);
(unsigned char) old_comm_params.baud_lsb ); outp(0x21, (unsigned char) old_comm_params.int_cntrl);
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 */ /* restore old interrupt handler */
setvect ( IrqNum + 8, oldvector_serial ); setvect(IrqNum + 8, oldvector_serial);
/* free input and output queues */ /* free input and output queues */
free ( Serial_In_Queue ); free(Serial_In_Queue);
free ( Serial_Out_Queue ); free(Serial_Out_Queue);
return; return;
} }
int OpenComPort ( char Port ) /* install int. handler */ int OpenComPort(
{ char Port)
unsigned status; { /* install int. handler */
int retval = -1; unsigned status;
int retval = -1;
/* allocate input and output queues */
Serial_In_Queue = alloc_queue( SerInBufSize ); /* allocate input and output queues */
if ( (QUEUE *) 0 == Serial_In_Queue)
return retval;
Serial_Out_Queue = alloc_queue( SerOutBufSize );
if ( (QUEUE *) 0 == Serial_Out_Queue)
{
free ( Serial_In_Queue );
return retval;
}
retval = 0;
/* Setup Comm base port address and IRQ number */ Serial_In_Queue = alloc_queue(SerInBufSize);
if ((QUEUE *) 0 == Serial_In_Queue)
return retval;
Serial_Out_Queue = alloc_queue(SerOutBufSize);
if ((QUEUE *) 0 == Serial_Out_Queue) {
free(Serial_In_Queue);
return retval;
}
retval = 0;
switch ( Port) /* Setup Comm base port address and IRQ number */
{
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 */
/* save old comm parameters */ 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 */
old_comm_params.line = inp ( ComBase + LINE_CNTRL ); /* save old comm parameters */
old_comm_params.modem = inp ( ComBase + MODEM_CNTRL );
status = inp ( ComBase + LINE_CNTRL );
outp ( ComBase + LINE_CNTRL, (unsigned char) status | 0x80 );
old_comm_params.baud_lsb = inp ( ComBase + BAUD_LSB );
old_comm_params.baud_msb = inp ( ComBase + BAUD_MSB );
status = inp ( ComBase + LINE_CNTRL );
outp ( ComBase + LINE_CNTRL, (unsigned char) status | 0x7F );
status = OUT2 | DTR; /* DTR/OUT2 must be set! */
outp ( ComBase + MODEM_CNTRL, (unsigned char) status );
/* get serial port address/vector */ old_comm_params.line = inp(ComBase + LINE_CNTRL);
old_comm_params.modem = inp(ComBase + MODEM_CNTRL);
status = inp(ComBase + LINE_CNTRL);
outp(ComBase + LINE_CNTRL, (unsigned char) status | 0x80);
old_comm_params.baud_lsb = inp(ComBase + BAUD_LSB);
old_comm_params.baud_msb = inp(ComBase + BAUD_MSB);
status = inp(ComBase + LINE_CNTRL);
outp(ComBase + LINE_CNTRL, (unsigned char) status | 0x7F);
status = OUT2 | DTR; /* DTR/OUT2 must be set! */
outp(ComBase + MODEM_CNTRL, (unsigned char) status);
oldvector_serial = (void(INTERRUPT FAR *)(void))getvect(IrqNum + 8 ); /* get serial port address/vector */
/* set our interrupt handler */ oldvector_serial = (void (INTERRUPT FAR *) (void)) getvect(IrqNum + 8);
setvect ( IrqNum + 8, serial ); /* set our interrupt handler */
/* save the PIC */ setvect(IrqNum + 8, serial);
old_comm_params.int_cntrl = inp ( 0x21 ); /* save the PIC */
status = ( 1 << IrqNum); /* calculate int enable bit */
status = ~status;
/* ok enable comm ints */ old_comm_params.int_cntrl = inp(0x21);
status = (1 << IrqNum); /* calculate int enable bit */
status = ~status;
outp ( 0x21, (unsigned char) old_comm_params.int_cntrl & /* ok enable comm ints */
(unsigned char) status );
outp(0x21,
atexit(CloseComPort); (unsigned char) old_comm_params.int_cntrl & (unsigned char) status);
return retval; atexit(CloseComPort);
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;
long baudrate; 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); outp(ComBase + BAUD_LSB, (unsigned char) (divisor & 0x00FF));
outp ( ComBase + BAUD_LSB, outp(ComBase + BAUD_MSB, (unsigned char) ((divisor >> 8) & 0x00FF));
(unsigned char) ( divisor & 0x00FF) ); status = 0x00;
outp ( ComBase + BAUD_MSB,
(unsigned char) ( ( divisor >> 8) & 0x00FF) );
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;
status = 0x08; break; 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;
case '6': case '6':
status = status | 0x01; status = status | 0x01;
break; break;
case '7': case '7':
status = status | 0x02; status = status | 0x02;
break; break;
case '8': case '8':
default : default:
status = status | 0x03; status = status | 0x03;
} }
/* set number stop bits */ /* set number stop bits */
switch ( Stopbits) switch (Stopbits) {
{ case '2':
case '2':
status = status | 0x04; status = status | 0x04;
break; break;
case '1': case '1':
default : default:
; ;
} }
outp ( ComBase + LINE_CNTRL, (unsigned char) status ); outp(ComBase + LINE_CNTRL, (unsigned char) status);
status = OUT2 | DTR; /* DTR/OUT2 must be set! */ status = OUT2 | DTR; /* DTR/OUT2 must be set! */
outp ( ComBase + MODEM_CNTRL, (unsigned char) status ); outp(ComBase + MODEM_CNTRL, (unsigned char) status);
/* enable serial interrupts */ /* enable serial interrupts */
outp ( ComBase + INT_EN, RX_INT | ERR_INT | RS_INT ); outp(ComBase + INT_EN, RX_INT | ERR_INT | RS_INT);
return; return;
} }
void DropDtr ( void ) void DropDtr(
void)
{ {
int status; int status;
status = inp ( ComBase + MODEM_CNTRL ); status = inp(ComBase + MODEM_CNTRL);
status &= 0xFE; /* turn off DTR bit */ status &= 0xFE; /* turn off DTR bit */
outp ( ComBase + MODEM_CNTRL, (unsigned char) status ); outp(ComBase + MODEM_CNTRL, (unsigned char) status);
return; return;
} }
void RaiseDtr ( void ) void RaiseDtr(
void)
{ {
int status; int status;
status = inp ( ComBase + MODEM_CNTRL ); status = inp(ComBase + MODEM_CNTRL);
status |= 0x01; /* turn on DTR bit */ status |= 0x01; /* turn on DTR bit */
outp ( ComBase + MODEM_CNTRL, (unsigned char) status ); outp(ComBase + MODEM_CNTRL, (unsigned char) status);
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++; }
} if (0x0 == (comm_status.modem & 0x40))
if ( 0x0 == (comm_status.modem & 0x40)) RaiseDtr();
RaiseDtr (); outp(ComBase + INT_EN, RX_INT | TBE_INT | ERR_INT | RS_INT);
outp ( ComBase + INT_EN, RX_INT | TBE_INT | ERR_INT | RS_INT ); 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++; }
} if (0x0 == (comm_status.modem & 0x40))
if ( 0x0 == (comm_status.modem & 0x40)) RaiseDtr();
RaiseDtr (); outp(ComBase + INT_EN, RX_INT | TBE_INT | ERR_INT | RS_INT);
outp ( ComBase + INT_EN, RX_INT | TBE_INT | ERR_INT | RS_INT ); return retval;
return retval;
} }
int ComSendChar ( char character ) int ComSendChar(
char character)
{ {
int retval; int retval;
/* interrupt driven send */ /* interrupt driven send */
if ( 0x0 == (comm_status.modem & 0x40)) if (0x0 == (comm_status.modem & 0x40))
RaiseDtr (); RaiseDtr();
retval = en_queue ( Serial_Out_Queue, character ); retval = en_queue(Serial_Out_Queue, character);
if ( - 1 != retval) if (-1 != retval)
outp ( ComBase + INT_EN, RX_INT | TBE_INT | ERR_INT | RS_INT ); outp(ComBase + INT_EN, RX_INT | TBE_INT | ERR_INT | RS_INT);
return retval; return retval;
} }
int ComStatus ( void ) int ComStatus(
void)
{ {
unsigned status; unsigned status;
unsigned retval; unsigned retval;
retval = inp ( ComBase + LINE_STATUS ); retval = inp(ComBase + LINE_STATUS);
retval = retval << 8; retval = retval << 8;
status = inp ( ComBase + MODEM_STATUS ); status = inp(ComBase + MODEM_STATUS);
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
return (int) retval; retval |= 0x0100;
return (int) retval;
} }
void INTERRUPT FAR serial ( void ) /* interrupt handler */ void INTERRUPT FAR serial(
{ void)
int temp; { /* interrupt handler */
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 */
{ comm_status.modem = inp(ComBase + MODEM_STATUS);
case 0x00: /* modem interrupt */ break;
comm_status.modem = inp( ComBase + MODEM_STATUS );
break;
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 ); }
} break;
break;
case 0x04: /* receive interrupt */ case 0x04: /* receive interrupt */
en_queue(Serial_In_Queue, (char)inp(ComBase + REC)); en_queue(Serial_In_Queue, (char) inp(ComBase + REC));
break; break;
case 0x06: /* line interrupt */ case 0x06: /* line interrupt */
comm_status.line = inp ( ComBase + LINE_STATUS ); comm_status.line = inp(ComBase + LINE_STATUS);
(void) inp ( ComBase + REC ); (void) inp(ComBase + REC);
en_queue ( Serial_In_Queue, '!' ); en_queue(Serial_In_Queue, '!');
break; break;
default: /* No Mo` Left */ default: /* No Mo` Left */
comm_status.modem = inp ( ComBase + MODEM_STATUS ); comm_status.modem = inp(ComBase + MODEM_STATUS);
outp ( 0x20, 0x20 ); outp(0x20, 0x20);
enable (); enable();
return; return;
} /* switch */ } /* switch */
} /* while */ } /* while */
} }
/* End of Serial.C */ /* End of Serial.C */
+68 -51
View File
@@ -24,83 +24,100 @@
#include "extkword.h" #include "extkword.h"
#include "pchwio.h" #include "pchwio.h"
#define SerInBufSize 4096 /* Size of input buffer */ #define SerInBufSize 4096 /* Size of input buffer */
#define SerOutBufSize 512 /* Size of output buffer */ #define SerOutBufSize 512 /* Size of output buffer */
/* 8250 registers */ /* 8250 registers */
#define REC 0 /* Uart receive reg. */ #define REC 0 /* Uart receive reg. */
#define XMIT 0 /* Uart transmit reg. */ #define XMIT 0 /* Uart transmit reg. */
#define INT_EN 1 /* Uart int. enable reg. */ #define INT_EN 1 /* Uart int. enable reg. */
#define INT_ID 2 /* Uart int. ident. reg. */ #define INT_ID 2 /* Uart int. ident. reg. */
#define LINE_CNTRL 3 /* Uart line control reg. */ #define LINE_CNTRL 3 /* Uart line control reg. */
#define MODEM_CNTRL 4 /* Uart modem control reg. */ #define MODEM_CNTRL 4 /* Uart modem control reg. */
#define LINE_STATUS 5 /* Uart line status reg. */ #define LINE_STATUS 5 /* Uart line status reg. */
#define MODEM_STATUS 6 /* Uart modem status reg. */ #define MODEM_STATUS 6 /* Uart modem status reg. */
#define BAUD_LSB 0 /* Uart baud divisor reg. */ #define BAUD_LSB 0 /* Uart baud divisor reg. */
#define BAUD_MSB 1 /* Uart baud divisor reg. */ #define BAUD_MSB 1 /* Uart baud divisor reg. */
#define NONE 0 /* Handshake param none */ #define NONE 0 /* Handshake param none */
#define HDW 1 /* Handshake param hardware */ #define HDW 1 /* Handshake param hardware */
#define XON 2 /* Handshake param software */ #define XON 2 /* Handshake param software */
/* Interrupt enable register */ /* Interrupt enable register */
#define RX_INT 0x01 /* Receive interrupt mask */ #define RX_INT 0x01 /* Receive interrupt mask */
#define TBE_INT 0x02 /* Transmit buffer empty mask */ #define TBE_INT 0x02 /* Transmit buffer empty mask */
#define ERR_INT 0x04 /* Error interrupt mask */ #define ERR_INT 0x04 /* Error interrupt mask */
#define RS_INT 0x08 /* Line interrupt mask */ #define RS_INT 0x08 /* Line interrupt mask */
/* Interrupt id register */ /* Interrupt id register */
#define OUT2 0x08 /* Out 2 line */ #define OUT2 0x08 /* Out 2 line */
#define DTR 0x01 /* DTR high */ #define DTR 0x01 /* DTR high */
#define RTS 0x02 /* RTS high */ #define RTS 0x02 /* RTS high */
#define CTS 0x10 #define CTS 0x10
#define DSR 0x20 #define DSR 0x20
#define XMTRDY 0x20 #define XMTRDY 0x20
#define TXR 0 /* Transmit register (WRITE) */ #define TXR 0 /* Transmit register (WRITE) */
#if !defined TRUE /* Define boolean true/false */ #if !defined TRUE /* Define boolean true/false */
#define FALSE 0 #define FALSE 0
#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 */
int baud_msb; /* " " " " MSD */ int baud_msb; /* " " " " MSD */
int int_cntrl; /* old PIC interrupt reg value */ int int_cntrl; /* old PIC interrupt reg value */
} 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 */
+1 -1
View File
@@ -11,7 +11,7 @@ typedef signed char int8_t; /* 1 byte -127 to 127 */
typedef unsigned short uint16_t; /* 2 bytes 0 to 65535 */ typedef unsigned short uint16_t; /* 2 bytes 0 to 65535 */
typedef signed short int16_t; /* 2 bytes -32767 to 32767 */ typedef signed short int16_t; /* 2 bytes -32767 to 32767 */
/*typedef unsigned short long uint24_t; // 3 bytes 0 to 16777215 */ /*typedef unsigned short long uint24_t; // 3 bytes 0 to 16777215 */
typedef unsigned long uint32_t; /* 4 bytes 0 to 4294967295 */ typedef unsigned long uint32_t; /* 4 bytes 0 to 4294967295 */
typedef signed long int32_t; /* 4 bytes -2147483647 to 2147483647 */ typedef signed long int32_t; /* 4 bytes -2147483647 to 2147483647 */
/* typedef signed long long int64_t; */ /* typedef signed long long int64_t; */
/* typedef unsigned long long uint64_t; */ /* typedef unsigned long long uint64_t; */
+83 -54
View File
@@ -33,54 +33,80 @@ static volatile int SilenceTime;
/* counts ticks */ /* counts ticks */
volatile unsigned long Timer_Milliseconds; volatile unsigned long Timer_Milliseconds;
#define RTC_CMD_ADDR 0x70 // RTC internal register offset goes here #define RTC_CMD_ADDR 0x70 // RTC internal register offset goes here
#define RTC_DAT_ADDR 0x71 // RTC internal register R/W access here #define RTC_DAT_ADDR 0x71 // RTC internal register R/W access here
static uint8_t RTC_RS_Convert( static uint8_t RTC_RS_Convert(
uint16_t hertz) uint16_t hertz)
{ {
uint8_t RS = 0; uint8_t RS = 0;
/* from DS12887A datasheet /* from DS12887A datasheet
SELECT BITS tPI PERIODIC SELECT BITS tPI PERIODIC
REGISTER A INTERRUPT SQW OUTPUT REGISTER A INTERRUPT SQW OUTPUT
RS3 RS2 RS1 RS0 RATE FREQUENCY RS3 RS2 RS1 RS0 RATE FREQUENCY
--- --- --- --- ------------ ---------- --- --- --- --- ------------ ----------
0 0 0 0 None 0Hz 0 0 0 0 None 0Hz
0 0 0 1 3.90625ms 256Hz 0 0 0 1 3.90625ms 256Hz
0 0 1 0 7.8125ms 128Hz 0 0 1 0 7.8125ms 128Hz
0 0 1 1 122.070µs 8192Hz 0 0 1 1 122.070µs 8192Hz
0 1 0 0 244.141µs 4096Hz 0 1 0 0 244.141µs 4096Hz
0 1 0 1 488.281µs 2048Hz 0 1 0 1 488.281µs 2048Hz
0 1 1 0 976.5625µs 1024Hz 0 1 1 0 976.5625µs 1024Hz
0 1 1 1 1.953125ms 512Hz 0 1 1 1 1.953125ms 512Hz
1 0 0 0 3.90625ms 256Hz 1 0 0 0 3.90625ms 256Hz
1 0 0 1 7.8125ms 128Hz 1 0 0 1 7.8125ms 128Hz
1 0 1 0 15.625ms 64Hz 1 0 1 0 15.625ms 64Hz
1 0 1 1 31.25ms 32Hz 1 0 1 1 31.25ms 32Hz
1 1 0 0 62.5ms 16Hz 1 1 0 0 62.5ms 16Hz
1 1 0 1 125ms 8Hz 1 1 0 1 125ms 8Hz
1 1 1 0 250ms 4Hz 1 1 1 0 250ms 4Hz
1 1 1 1 500ms 2Hz 1 1 1 1 500ms 2Hz
*/ */
/* 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;
} }
return RS; return RS;
} }
@@ -98,7 +124,7 @@ static void interrupt Timer_Interrupt_Handler(
uint8_t temp_reg; uint8_t temp_reg;
Timer_Ticks++; Timer_Ticks++;
milliseconds = (Timer_Ticks * 1000)/INT_FREQ; milliseconds = (Timer_Ticks * 1000) / INT_FREQ;
diff = milliseconds - Elapsed_Milliseconds; diff = milliseconds - Elapsed_Milliseconds;
if (diff >= 1) { if (diff >= 1) {
Elapsed_Milliseconds = milliseconds; Elapsed_Milliseconds = milliseconds;
@@ -112,40 +138,43 @@ static void interrupt Timer_Interrupt_Handler(
Elapsed_Milliseconds = 0; Elapsed_Milliseconds = 0;
} }
/* clear interrupt */ /* clear interrupt */
outportb( RTC_CMD_ADDR, 0x0C ); // select RTC register C outportb(RTC_CMD_ADDR, 0x0C); // select RTC register C
temp_reg = inportb( RTC_DAT_ADDR ); // read RTC register C temp_reg = inportb(RTC_DAT_ADDR); // read RTC register C
/* signal end of interrupt to slave PIC */ /* signal end of interrupt to slave PIC */
outportb( 0xA0, 0x20 ); outportb(0xA0, 0x20);
/* signal end of interrupt to master PIC */ /* signal end of interrupt to master PIC */
outportb( 0x20, 0x20 ); outportb(0x20, 0x20);
} }
/* 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);
} }
void Timer_Init( void Timer_Init(
void) void)
{ {
uint8_t RC = RTC_RS_Convert(INT_FREQ); uint8_t RC = RTC_RS_Convert(INT_FREQ);
/* get old interrupt vector to re-install on exit */ /* get old interrupt vector to re-install on exit */
OldVector = getvect(0x70); OldVector = getvect(0x70);
/* disable interrupts */ /* disable interrupts */
disable(); disable();
/* set RTC int. vector for our routine */ /* set RTC int. vector for our routine */
setvect(0x70,Timer_Interrupt_Handler); setvect(0x70, Timer_Interrupt_Handler);
/* set register B with PIE enabled */ /* set register B with PIE enabled */
outportb( RTC_CMD_ADDR, 0x0B ); outportb(RTC_CMD_ADDR, 0x0B);
outportb( RTC_DAT_ADDR, 0x42 ); outportb(RTC_DAT_ADDR, 0x42);
/* set register A to our frequency */ /* set register A to our frequency */
outportb( RTC_CMD_ADDR, 0x0A ); outportb(RTC_CMD_ADDR, 0x0A);
outportb( RTC_DAT_ADDR, (0x20 | (RC & 0x0F)) ); outportb(RTC_DAT_ADDR, (0x20 | (RC & 0x0F)));
/* re-enable system interrupts */ /* re-enable system interrupts */
enable(); enable();
atexit(Timer_Cleanup); atexit(Timer_Cleanup);
@@ -155,7 +184,7 @@ int Timer_Silence(
void) void)
{ {
uint16_t time_value; uint16_t time_value;
disable(); disable();
time_value = SilenceTime; time_value = SilenceTime;
enable(); enable();
+2 -2
View File
@@ -50,7 +50,7 @@ int rpm_encode_apdu_init(
apdu[0] = PDU_TYPE_CONFIRMED_SERVICE_REQUEST; apdu[0] = PDU_TYPE_CONFIRMED_SERVICE_REQUEST;
apdu[1] = encode_max_segs_max_apdu(0, MAX_APDU); apdu[1] = encode_max_segs_max_apdu(0, MAX_APDU);
apdu[2] = invoke_id; apdu[2] = invoke_id;
apdu[3] = SERVICE_CONFIRMED_READ_PROP_MULTIPLE; /* service choice */ apdu[3] = SERVICE_CONFIRMED_READ_PROP_MULTIPLE; /* service choice */
apdu_len = 4; apdu_len = 4;
} }
@@ -209,7 +209,7 @@ int rpm_ack_encode_apdu_init(
if (apdu) { if (apdu) {
apdu[0] = PDU_TYPE_COMPLEX_ACK; /* complex ACK service */ apdu[0] = PDU_TYPE_COMPLEX_ACK; /* complex ACK service */
apdu[1] = invoke_id; /* original invoke id from request */ apdu[1] = invoke_id; /* original invoke id from request */
apdu[2] = SERVICE_CONFIRMED_READ_PROP_MULTIPLE; /* service choice */ apdu[2] = SERVICE_CONFIRMED_READ_PROP_MULTIPLE; /* service choice */
apdu_len = 3; apdu_len = 3;
} }