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