Adding a DOS port to run on x86 single board computer.

This commit is contained in:
skarg
2007-12-06 22:31:14 +00:00
parent af373fbbfe
commit 64e9b54dbd
23 changed files with 2838 additions and 46 deletions
+2 -2
View File
@@ -104,7 +104,7 @@ void Life_Safety_Point_Init(
Life_Safety_Point_Mode[i] = LIFE_SAFETY_MODE_DEFAULT;
Life_Safety_Point_State[i] = LIFE_SAFETY_STATE_QUIET;
Life_Safety_Point_Silenced_State[i] = SILENCED_STATE_UNSILENCED;
Life_Safety_Point_Operation[i] = LIFE_SAFETY_OPERATION_NONE;
Life_Safety_Point_Operation[i] = LIFE_SAFETY_OP_NONE;
}
}
@@ -202,7 +202,7 @@ int Life_Safety_Point_Encode_Property_APDU(
BACNET_LIFE_SAFETY_STATE present_value = LIFE_SAFETY_STATE_QUIET;
BACNET_LIFE_SAFETY_MODE mode = LIFE_SAFETY_MODE_DEFAULT;
BACNET_SILENCED_STATE silenced_state = SILENCED_STATE_UNSILENCED;
BACNET_LIFE_SAFETY_OPERATION operation = LIFE_SAFETY_OPERATION_NONE;
BACNET_LIFE_SAFETY_OPERATION operation = LIFE_SAFETY_OP_NONE;
unsigned object_index = 0;
bool state = false;
BACNET_RELIABILITY reliability = RELIABILITY_NO_FAULT_DETECTED;
+1 -1
View File
@@ -69,7 +69,7 @@ static void Init_Service_Handlers(
/* We must implement read property - it's required! */
apdu_set_confirmed_handler(SERVICE_CONFIRMED_READ_PROPERTY,
handler_read_property);
apdu_set_confirmed_handler(SERVICE_CONFIRMED_READ_PROPERTY_MULTIPLE,
apdu_set_confirmed_handler(SERVICE_CONFIRMED_READ_PROP_MULTIPLE,
handler_read_property_multiple);
apdu_set_confirmed_handler(SERVICE_CONFIRMED_WRITE_PROPERTY,
handler_write_property);
+25 -25
View File
@@ -516,8 +516,8 @@ typedef enum {
UNITS_DEGREES_FAHRENHEIT_PER_MINUTE = 94,
UNITS_JOULE_SECONDS = 183,
UNITS_KILOGRAMS_PER_CUBIC_METER = 186,
UNITS_KILOWATT_HOURS_PER_SQUARE_METER = 137,
UNITS_KILOWATT_HOURS_PER_SQUARE_FOOT = 138,
UNITS_KW_HOURS_PER_SQUARE_METER = 137,
UNITS_KW_HOURS_PER_SQUARE_FOOT = 138,
UNITS_MEGAJOULES_PER_SQUARE_METER = 139,
UNITS_MEGAJOULES_PER_SQUARE_FOOT = 140,
UNITS_NO_UNITS = 95,
@@ -649,19 +649,19 @@ typedef enum {
} BACNET_LIFE_SAFETY_MODE;
typedef enum {
LIFE_SAFETY_OPERATION_NONE = 0,
LIFE_SAFETY_OPERATION_SILENCE = 1,
LIFE_SAFETY_OPERATION_SILENCE_AUDIBLE = 2,
LIFE_SAFETY_OPERATION_SILENCE_VISUAL = 3,
LIFE_SAFETY_OPERATION_RESET = 4,
LIFE_SAFETY_OPERATION_RESET_ALARM = 5,
LIFE_SAFETY_OPERATION_RESET_FAULT = 6,
LIFE_SAFETY_OPERATION_UNSILENCE = 7,
LIFE_SAFETY_OPERATION_UNSILENCE_AUDIBLE = 8,
LIFE_SAFETY_OPERATION_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. */
LIFE_SAFETY_OP_NONE = 0,
LIFE_SAFETY_OP_SILENCE = 1,
LIFE_SAFETY_OP_SILENCE_AUDIBLE = 2,
LIFE_SAFETY_OP_SILENCE_VISUAL = 3,
LIFE_SAFETY_OP_RESET = 4,
LIFE_SAFETY_OP_RESET_ALARM = 5,
LIFE_SAFETY_OP_RESET_FAULT = 6,
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. */
} BACNET_LIFE_SAFETY_OPERATION;
typedef enum {
@@ -845,11 +845,11 @@ typedef enum {
SERVICE_CONFIRMED_CREATE_OBJECT = 10,
SERVICE_CONFIRMED_DELETE_OBJECT = 11,
SERVICE_CONFIRMED_READ_PROPERTY = 12,
SERVICE_CONFIRMED_READ_PROPERTY_CONDITIONAL = 13,
SERVICE_CONFIRMED_READ_PROPERTY_MULTIPLE = 14,
SERVICE_CONFIRMED_READ_PROP_CONDITIONAL = 13,
SERVICE_CONFIRMED_READ_PROP_MULTIPLE = 14,
SERVICE_CONFIRMED_READ_RANGE = 26,
SERVICE_CONFIRMED_WRITE_PROPERTY = 15,
SERVICE_CONFIRMED_WRITE_PROPERTY_MULTIPLE = 16,
SERVICE_CONFIRMED_WRITE_PROP_MULTIPLE = 16,
/* Remote Device Management Services */
SERVICE_CONFIRMED_DEVICE_COMMUNICATION_CONTROL = 17,
SERVICE_CONFIRMED_PRIVATE_TRANSFER = 18,
@@ -910,11 +910,11 @@ typedef enum {
SERVICE_SUPPORTED_CREATE_OBJECT = 10,
SERVICE_SUPPORTED_DELETE_OBJECT = 11,
SERVICE_SUPPORTED_READ_PROPERTY = 12,
SERVICE_SUPPORTED_READ_PROPERTY_CONDITIONAL = 13,
SERVICE_SUPPORTED_READ_PROPERTY_MULTIPLE = 14,
SERVICE_SUPPORTED_READ_PROP_CONDITIONAL = 13,
SERVICE_SUPPORTED_READ_PROP_MULTIPLE = 14,
SERVICE_SUPPORTED_READ_RANGE = 35,
SERVICE_SUPPORTED_WRITE_PROPERTY = 15,
SERVICE_SUPPORTED_WRITE_PROPERTY_MULTIPLE = 16,
SERVICE_SUPPORTED_WRITE_PROP_MULTIPLE = 16,
/* Remote Device Management Services */
SERVICE_SUPPORTED_DEVICE_COMMUNICATION_CONTROL = 17,
SERVICE_SUPPORTED_PRIVATE_TRANSFER = 18,
@@ -946,8 +946,8 @@ typedef enum {
typedef enum {
BVLC_RESULT = 0,
BVLC_WRITE_BROADCAST_DISTRIBUTION_TABLE = 1,
BVLC_READ_BROADCAST_DISTRIBUTION_TABLE = 2,
BVLC_READ_BROADCAST_DISTRIBUTION_TABLE_ACK = 3,
BVLC_READ_BROADCAST_DIST_TABLE = 2,
BVLC_READ_BROADCAST_DIST_TABLE_ACK = 3,
BVLC_FORWARDED_NPDU = 4,
BVLC_REGISTER_FOREIGN_DEVICE = 5,
BVLC_READ_FOREIGN_DEVICE_TABLE = 6,
@@ -1031,8 +1031,8 @@ typedef enum {
NETWORK_MESSAGE_REJECT_MESSAGE_TO_NETWORK = 3,
NETWORK_MESSAGE_ROUTER_BUSY_TO_NETWORK = 4,
NETWORK_MESSAGE_ROUTER_AVAILABLE_TO_NETWORK = 5,
NETWORK_MESSAGE_INITIALIZE_ROUTING_TABLE = 6,
NETWORK_MESSAGE_INITIALIZE_ROUTING_TABLE_ACK = 7,
NETWORK_MESSAGE_INIT_RT_TABLE = 6,
NETWORK_MESSAGE_INIT_RT_TABLE_ACK = 7,
NETWORK_MESSAGE_ESTABLISH_CONNECTION_TO_NETWORK = 8,
NETWORK_MESSAGE_DISCONNECT_CONNECTION_TO_NETWORK = 9,
/* X'0A' to X'7F': Reserved for use by ASHRAE, */
+15
View File
@@ -67,6 +67,21 @@
/* BACAPP decodes WriteProperty service requests
Choose the datatypes that your application supports */
#if !(defined(BACAPP_NULL) || \
defined(BACAPP_BOOLEAN) || \
defined(BACAPP_UNSIGNED) || \
defined(BACAPP_SIGNED) || \
defined(BACAPP_REAL) || \
defined(BACAPP_OCTET_STRING) || \
defined(BACAPP_CHARACTER_STRING) || \
defined(BACAPP_BIT_STRING) || \
defined(BACAPP_ENUMERATED) || \
defined(BACAPP_DATE) || \
defined(BACAPP_TIME) || \
defined(BACAPP_OBJECT_ID))
#define BACAPP_ALL
#endif
#if defined (BACAPP_ALL)
#define BACAPP_NULL
#define BACAPP_BOOLEAN
File diff suppressed because it is too large Load Diff
+131
View File
@@ -0,0 +1,131 @@
/*====================================================================
_MSC_VER Microsoft C 6.0 and later
_QC Microsoft Quick C 2.51 and later
__TURBOC__ Borland Turbo C, Turbo C++ and BC++
__BORLANDC__ Borland C++
__ZTC__ Zortech C and C++
__SC__ Symantec C++
__WATCOMC__ WATCOM C
__POWERC Mix Power C
__GNUC__ Gnu C
Revised:
25-Sep-95 Bob Stout Original from PC-PORT.H
30-Mar-96 Ed Blackman OS/2 mods for OS/2 ver 2.0 and up
30-May-96 Andrew Clarke Added support for WATCOM C/C++ __NT__ macro.
17-Jun-96 Bob Stout Added __FLAT__ macros support
20-Aug-96 Bob Stout Eliminate Win32 conflicts
======================================================================*/
/* prevent multiple inclusions of this header file */
#ifndef EXTKWORD__H
#define EXTKWORD__H
#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
#endif
/*
** Correct extended keywords syntax
*/
#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
#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
#else /* ! Win 32 or OS/2 */
#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__) && \
(__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
#endif
#endif /* EXTKWORD__H */
+23
View File
@@ -0,0 +1,23 @@
/*
** MK_FP.H
**
** Standard header file making sure this pesky Intel macro is defined!
*/
#ifndef MK_FP__H
#define MK_FP__H
#include "extkword.h"
#if defined(__WATCOMC__)
#include <i86.h>
#elif !defined(__PACIFIC__)
#include <dos.h>
#endif
#if !defined(MK_FP)
#define MK_FP(seg,off) \
((void FAR *)(((unsigned long)(seg) << 16)|(unsigned)(off)))
#endif
#endif /* MK_FP__H */
+70
View File
@@ -0,0 +1,70 @@
/*
** PCHWIO.C - SNIPPETS portable hardware I/O access under DOS
**
** public domain by Bob Stout
*/
#include "pchwio.h"
#include "mk_fp.h"
#if defined(__ZTC__) && !defined(__SC__)
void FAR * getvect(unsigned intnum)
{
unsigned seg, off;
int_getvector(intnum, &off, &seg);
return MK_FP(seg, off);
}
void setvect(unsigned intnum, void (INTERRUPT FAR *handler)())
{
unsigned seg = FP_SEG(handler), off = FP_OFF(handler);
int_setvector(intnum, off, seg);
}
#endif /* ZTC getvect(), setvect() */
#if defined(_MSC_VER) || defined(__WATCOMC__) || \
defined(__ZTC__) || defined(__SC__)
#if !defined(MK_FP)
#define MK_FP(seg,off) ((void far *)(((long)(seg) << 16)|(unsigned)(off)))
#endif
unsigned char Peekb(unsigned seg, unsigned ofs)
{
unsigned char FAR *ptr;
ptr = MK_FP(seg, ofs);
return *ptr;
}
unsigned short Peekw(unsigned seg, unsigned ofs)
{
unsigned FAR *ptr;
ptr = MK_FP(seg, ofs);
return *ptr;
}
void Pokeb(unsigned seg, unsigned ofs, unsigned char ch)
{
unsigned char FAR *ptr;
ptr = MK_FP(seg, ofs);
*ptr = ch;
}
void Pokew(unsigned seg, unsigned ofs, unsigned short num)
{
unsigned FAR *ptr;
ptr = MK_FP(seg, ofs);
*ptr = num;
}
#endif /* MSC/ZTC/WC Peek(), poke() */
+65
View File
@@ -0,0 +1,65 @@
/*
** PCHWIO.H - SNIPPETS header file for portable hardware I/O access under DOS
**
** public domain by Bob Stout
*/
#ifndef PCHWIO__H
#define PCHWIO__H
#include <dos.h>
#include "extkword.h"
#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
#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
#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
#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 */
#elif defined(__TURBOC__)
#define Peekw peek
#define Pokew poke
#define Peekb peekb
#define Pokeb pokeb
#endif /* peek(), poke() */
#endif /* PCHWIO__H */
+61
View File
@@ -0,0 +1,61 @@
/*
+----------------------------------------------------+
| Thunderbird Software |
+----------------------------------------------------+
| Filespec : Queue.c |
| Date : September 29, 1994 |
| Time : 10:16AM |
| Revision : 1.0 |
+----------------------------------------------------+
| Programmer: Scott Andrews |
| Address : 5358 Summit RD SW |
| City/State: Pataskala, Ohio |
| Zip : 43062 |
+----------------------------------------------------+
| Released to the Public Domain |
+----------------------------------------------------+
*/
#include <stdlib.h>
#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;
}
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;
}
/* End of Queue.c */
+41
View File
@@ -0,0 +1,41 @@
/*
+----------------------------------------------------+
| Thunderbird Software |
+----------------------------------------------------+
| Filespec : QUEUE.H |
| Date : August 30, 1994 |
| Time : 5:40 PM |
| Revision : 0.0 |
+----------------------------------------------------+
| Programmer: Scott Andrews |
| Address : 5358 Summit RD SW |
| City/State: Pataskala, Ohio |
| Zip : 43062 |
+----------------------------------------------------+
| Released to the Public Domain |
+----------------------------------------------------+
*/
#ifndef QUEUE__H
#define QUEUE__H
/* Needed by Serial.C */
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);
/* End of Queue.H */
#endif /* QUEUE__H */
+5
View File
@@ -0,0 +1,5 @@
This is a port to DOS using the BACnet MS/TP datalink layer.
It utilizes some serial routines from snippets.org.
It was tested and compiled with Turbo C++ 1.01 which is
freely available from http://dn.codegear.com/article/21751
It was targeting the TS-3100 from Technologic Systems.
+284
View File
@@ -0,0 +1,284 @@
/**************************************************************************
*
* Copyright (C) 2007 Steve Karg <skarg@users.sourceforge.net>
* RS-485 initialization on AT91SAM7S inspired by Keil Eletronik serial.c
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*********************************************************************/
/* The module handles sending data out the RS-485 port */
/* and handles receiving data from the RS-485 port. */
/* Customize this file for your specific hardware */
#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>
#include <stdlib.h>
#include <stdio.h>
#include "timer.h"
/* This file has been customized for use with DOS */
#include "hardware.h"
/* UART */
static volatile AT91S_USART *RS485_Interface = AT91C_BASE_US0;
/* baud rate */
static int RS485_Baud = 38400;
/* The minimum time after the end of the stop bit of the final octet of a */
/* received frame before a node may enable its EIA-485 driver: 40 bit times. */
/* At 9600 baud, 40 bit times would be about 4.166 milliseconds */
/* At 19200 baud, 40 bit times would be about 2.083 milliseconds */
/* At 38400 baud, 40 bit times would be about 1.041 milliseconds */
/* At 57600 baud, 40 bit times would be about 0.694 milliseconds */
/* At 76800 baud, 40 bit times would be about 0.520 milliseconds */
/* At 115200 baud, 40 bit times would be about 0.347 milliseconds */
/* 40 bits is 4 octets including a start and stop bit with each octet */
#define Tturnaround (40UL)
/* turnaround_time_milliseconds = (Tturnaround*1000UL)/RS485_Baud; */
/****************************************************************************
* DESCRIPTION: Initializes the RS485 hardware and variables, and starts in
* receive mode.
* RETURN: none
* ALGORITHM: none
* NOTES: none
*****************************************************************************/
void RS485_Initialize(
void)
{
/* Enable the USART0 clock in the Power Management Controller */
volatile AT91PS_PMC pPMC = AT91C_BASE_PMC;
pPMC->PMC_PCER = pPMC->PMC_PCSR | (1 << AT91C_ID_US0);
/* Disable and clear USART0 interrupt
in AIC Interrupt Disable Command Register */
volatile AT91PS_AIC pAIC = AT91C_BASE_AIC;
pAIC->AIC_IDCR = (1 << AT91C_ID_US0);
pAIC->AIC_ICCR = (1 << AT91C_ID_US0);
/* enable the peripheral by disabling the pin in the PIO controller */
*AT91C_PIOA_PDR = AT91C_PA5_RXD0 | AT91C_PA6_TXD0 | AT91C_PA7_RTS0;
RS485_Interface->US_CR = AT91C_US_RSTRX | /* Reset Receiver */
AT91C_US_RSTTX | /* Reset Transmitter */
AT91C_US_RSTSTA | /* Clear status register */
AT91C_US_RXDIS | /* Receiver Disable */
AT91C_US_TXDIS; /* Transmitter Disable */
RS485_Interface->US_MR = AT91C_US_USMODE_RS485 | /* RS-485 Mode - RTS auto assert */
AT91C_US_CLKS_CLOCK | /* Clock = MCK */
AT91C_US_CHRL_8_BITS | /* 8-bit Data */
AT91C_US_PAR_NONE | /* No Parity */
AT91C_US_NBSTOP_1_BIT; /* 1 Stop Bit */
/* set the Time Guard to release RTS after x bit times */
RS485_Interface->US_TTGR = 1;
/* Receiver Time-out disabled */
RS485_Interface->US_RTOR = 0;
/* baud rate */
RS485_Interface->US_BRGR = MCK / 16 / RS485_Baud;
RS485_Interface->US_CR = AT91C_US_RXEN | /* Receiver Enable */
AT91C_US_TXEN; /* Transmitter Enable */
return;
}
void RS485_Cleanup(
void)
{
}
/****************************************************************************
* DESCRIPTION: Returns the baud rate that we are currently running at
* RETURN: none
* ALGORITHM: none
* NOTES: none
*****************************************************************************/
uint32_t RS485_Get_Baud_Rate(
void)
{
return RS485_Baud;
}
/****************************************************************************
* DESCRIPTION: Sets the baud rate for the chip USART
* RETURN: none
* ALGORITHM: none
* NOTES: none
*****************************************************************************/
bool RS485_Set_Baud_Rate(
uint32_t baud)
{
bool valid = true;
switch (baud) {
case 9600:
case 19200:
case 38400:
case 57600:
case 76800:
case 115200:
RS485_Baud = baud;
RS485_Interface->US_BRGR = MCK / 16 / baud;
/* FIXME: store the baud rate */
break;
default:
valid = false;
break;
}
return valid;
}
/****************************************************************************
* DESCRIPTION: Waits on the SilenceTimer for 40 bits.
* RETURN: none
* ALGORITHM: none
* NOTES: none
*****************************************************************************/
void RS485_Turnaround_Delay(
void)
{
uint16_t turnaround_time;
/* delay after reception before trasmitting - per MS/TP spec */
/* wait a minimum 40 bit times since reception */
/* at least 1 ms for errors: rounding, clock tick */
turnaround_time = 1 + ((Tturnaround * 1000UL) / RS485_Baud);
while (Timer_Silence() < turnaround_time) {
/* do nothing - wait for timer to increment */
};
}
/****************************************************************************
* DESCRIPTION: Enable or disable the transmitter
* RETURN: none
* ALGORITHM: none
* NOTES: The Atmel ARM7 has an automatic enable/disable in RS485 mode.
*****************************************************************************/
void RS485_Transmitter_Enable(
bool enable)
{
(void) enable;
}
/****************************************************************************
* DESCRIPTION: Send some data and wait until it is sent
* RETURN: none
* ALGORITHM: none
* NOTES: none
*****************************************************************************/
void RS485_Send_Data(
uint8_t * buffer, /* data to send */
uint16_t nbytes)
{ /* number of bytes of data */
/* LED on send */
volatile AT91PS_PIO pPIO = AT91C_BASE_PIOA;
/* LED ON */
pPIO->PIO_CODR = LED1;
/* send all the bytes */
while (nbytes) {
while (!(RS485_Interface->US_CSR & AT91C_US_TXRDY)) {
/* do nothing - wait until Tx buffer is empty */
}
RS485_Interface->US_THR = *buffer;
buffer++;
nbytes--;
}
while (!(RS485_Interface->US_CSR & AT91C_US_TXRDY)) {
/* do nothing - wait until Tx buffer is empty */
}
/* per MSTP spec */
Timer_Silence_Reset();
}
/****************************************************************************
* DESCRIPTION: Return true if a framing or overrun error is present
* RETURN: true if error
* ALGORITHM: none
* NOTES: Clears any error flags.
*****************************************************************************/
bool RS485_ReceiveError(
void)
{
bool ReceiveError = false;
/* LED on send */
volatile AT91PS_PIO pPIO = AT91C_BASE_PIOA;
/* check for data or error */
if (RS485_Interface->US_CSR & (AT91C_US_OVRE | AT91C_US_FRAME)) {
/* clear the error flag */
RS485_Interface->US_CR = AT91C_US_RSTSTA;
ReceiveError = true;
/* LED ON */
pPIO->PIO_CODR = LED2;
}
return ReceiveError;
}
/****************************************************************************
* DESCRIPTION: Return true if data is available
* RETURN: true if data is available, with the data in the parameter set
* ALGORITHM: none
* NOTES: none
*****************************************************************************/
bool RS485_DataAvailable(
uint8_t * DataRegister)
{
bool DataAvailable = false;
/* LED on send */
volatile AT91PS_PIO pPIO = AT91C_BASE_PIOA;
if (RS485_Interface->US_CSR & AT91C_US_RXRDY) {
/* data is available */
*DataRegister = RS485_Interface->US_RHR;
DataAvailable = true;
/* LED ON */
pPIO->PIO_CODR = LED2;
}
return DataAvailable;
}
#ifdef TEST_RS485
int main(
void)
{
unsigned i = 0;
uint8_t DataRegister;
RS485_Set_Baud_Rate(38400);
RS485_Initialize();
/* receive task */
for (;;) {
if (RS485_ReceiveError()) {
fprintf(stderr, "ERROR ");
} else if (RS485_DataAvailable(&DataRegister)) {
fprintf(stderr, "%02X ", DataRegister);
}
}
}
#endif
+60
View File
@@ -0,0 +1,60 @@
/**************************************************************************
*
* Copyright (C) 2007 Steve Karg <skarg@users.sourceforge.net>
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*********************************************************************/
#ifndef RS485_H
#define RS485_H
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
void RS485_Initialize(
void);
void RS485_Transmitter_Enable(
bool enable);
void RS485_Send_Data(
uint8_t * buffer, /* data to send */
uint16_t nbytes); /* number of bytes of data */
bool RS485_ReceiveError(
void);
bool RS485_DataAvailable(
uint8_t * data);
void RS485_Turnaround_Delay(
void);
uint32_t RS485_Get_Baud_Rate(
void);
bool RS485_Set_Baud_Rate(
uint32_t baud);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif
+342
View File
@@ -0,0 +1,342 @@
/*
+----------------------------------------------------+
| Thunderbird Software |
+----------------------------------------------------+
| Filespec : Serial.c |
| Date : October 24, 1991 |
| Time : 15:03 |
| Revision : 1.1 |
| Update: August 29, 1994 |
+----------------------------------------------------+
| Programmer: Scott Andrews |
| Address : 5358 Summit RD SW |
| City/State: Pataskala, Ohio |
| Zip : 43062 |
+----------------------------------------------------+
| Released to the Public Domain |
+----------------------------------------------------+
*/
/*
+----------------------------------------------------------+
| Call open_serial to install the interrupt handler |
| You must call close_serial before exiting your program |
| or a machine crash will occur! |
+----------------------------------------------------------+
*/
#include <stdlib.h>
#include <dos.h>
#include <string.h>
#include "serial.h"
#include "queue.h"
QUEUE *Serial_In_Queue;
QUEUE *Serial_Out_Queue;
OLD_COMM_PARAMS old_comm_params;
COMM_STATUS comm_status;
void (INTERRUPT FAR *oldvector_serial )();
/* save addr for intr handler */
int ComBase; /* Comm port address */
int IrqNum; /* Comm interrupt request */
int OpenComPort ( char Port ) /* install int. handler */
{
unsigned status;
int retval = -1;
/* allocate input and output queues */
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;
/* Setup Comm base port address and IRQ number */
switch ( Port)
{
case '1': ComBase = 0x3F8; IrqNum = 4; break;
case '2': ComBase = 0x2F8; IrqNum = 3; break;
case '3': ComBase = 0x3E8; IrqNum = 4; break;
case '4': ComBase = 0x2E8; IrqNum = 3; break;
default : ComBase = 0x3F8; IrqNum = 4; break;
}
old_comm_params.int_enable = inp ( ComBase + INT_EN );
outp ( ComBase + INT_EN, 0 ); /* turn off comm interrupts */
/* save old comm parameters */
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 );
/* get serial port address/vector */
oldvector_serial = (void(INTERRUPT FAR *)(void))getvect(IrqNum + 8 );
/* set our interrupt handler */
setvect ( IrqNum + 8, serial );
/* save the PIC */
old_comm_params.int_cntrl = inp ( 0x21 );
status = ( 1 << IrqNum); /* calculate int enable bit */
status = ~status;
/* ok enable comm ints */
outp ( 0x21, (unsigned char) old_comm_params.int_cntrl &
(unsigned char) status );
return retval;
}
void CloseComPort ( void )
{
int status;
/* restore UART to previous state */
outp ( ComBase + INT_EN, (unsigned char) 0 );
outp ( ComBase + MODEM_CNTRL,
(unsigned char) old_comm_params.modem );
status = inp ( ComBase + LINE_CNTRL );
outp ( ComBase + LINE_CNTRL,
(unsigned char) status | 0x80 );
outp ( ComBase + BAUD_LSB,
(unsigned char) old_comm_params.baud_lsb );
outp ( ComBase + BAUD_MSB,
(unsigned char) old_comm_params.baud_msb );
outp ( ComBase + LINE_CNTRL,
(unsigned char) old_comm_params.line );
outp ( 0x21, (unsigned char) old_comm_params.int_cntrl );
/* restore old interrupt handler */
setvect ( IrqNum + 8, oldvector_serial );
/* free input and output queues */
free ( Serial_In_Queue );
free ( Serial_Out_Queue );
return;
}
void InitComPort ( char Baud[], char Databits,
char Parity, char Stopbits )
{
int status;
long baudrate;
unsigned divisor;
/* 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;
/* set parity */
switch ( Parity) /* set parity value */
{
case 'O': /* odd parity */
case 'o':
status = 0x08; break;
case 'E': /* even parity */
case 'e':
status = 0x18; break;
case 'S': /* stick parity */
case 's':
status = 0x28; break;
case 'N': /* no parity */
case 'n':
default : status = 0x00;
}
/* set number data bits */
switch ( Databits)
{
case '5':
break;
case '6':
status = status | 0x01;
break;
case '7':
status = status | 0x02;
break;
case '8':
default :
status = status | 0x03;
}
/* set number stop bits */
switch ( Stopbits)
{
case '2':
status = status | 0x04;
break;
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 );
/* enable serial interrupts */
outp ( ComBase + INT_EN, RX_INT | ERR_INT | RS_INT );
return;
}
void DropDtr ( void )
{
int status;
status = inp ( ComBase + MODEM_CNTRL );
status &= 0xFE; /* turn off DTR bit */
outp ( ComBase + MODEM_CNTRL, (unsigned char) status );
return;
}
void RaiseDtr ( void )
{
int status;
status = inp ( ComBase + MODEM_CNTRL );
status |= 0x01; /* turn on DTR bit */
outp ( ComBase + MODEM_CNTRL, (unsigned char) status );
return;
}
int ComRecChar ( void )
{
return de_queue ( Serial_In_Queue );
}
int ComSendString ( char *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;
}
int ComSendChar ( char character )
{
int retval;
/* 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;
}
int ComStatus ( void )
{
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;
}
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;
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 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 */
}
/* End of Serial.C */
+106
View File
@@ -0,0 +1,106 @@
/*
+----------------------------------------------------+
| Thunderbird Software |
+----------------------------------------------------+
| Filespec : Serial.c |
| Date : October 24, 1991 |
| Time : 15:03 |
| Revision : 1.1 |
| Update : August 29, 1994 |
| Update : March 12, 1995 by Bob Stout |
+----------------------------------------------------+
| Programmer: Scott Andrews |
| Address : 5358 Summit RD SW |
| City/State: Pataskala, Ohio |
| Zip : 43062 |
+----------------------------------------------------+
| Released to the Public Domain |
+----------------------------------------------------+
*/
#ifndef SERIAL__H
#define SERIAL__H
#include "extkword.h"
#include "pchwio.h"
#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 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 */
/* Interrupt id register */
#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) */
#if !defined TRUE /* Define boolean true/false */
#define FALSE 0
#define TRUE !FALSE
#endif
extern void (INTERRUPT FAR *oldvector_serial )( void);
extern int ComBase; /* Comm port address */
extern int IrqNum; /* Comm interrupt request */
typedef struct /* Save existing comm params */
{ int int_enable; /* old interrupt enable reg value*/
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 */
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 ComSendChar ( char character ); /* Put char into xmit buffer */
int ComSendString ( char *string );
int ComStatus ( void ); /* Fetch comm status */
void INTERRUPT FAR serial ( void ); /* interrupt handler */
/* End of Serial.H */
#endif /* SERIAL__H */
+20
View File
@@ -0,0 +1,20 @@
#ifndef _STDBOOL_H
#define _STDBOOL_H
/* C99 Boolean types for compilers without C99 support */
/* http://www.opengroup.org/onlinepubs/009695399/basedefs/stdbool.h.html */
#if !defined(__cplusplus)
#if !defined(__GNUC__)
/* _Bool builtin type is included in GCC */
typedef enum { _Bool_must_promote_to_int = -1, false = 0, true = 1 } _Bool;
#endif
#define bool _Bool
#define true 1
#define false 0
#define __bool_true_false_are_defined 1
#endif
#endif
+31
View File
@@ -0,0 +1,31 @@
/* Defines the standard integer types that are used in code */
/* for the x86 processor and Borland Compiler */
#ifndef _STDINT_H
#define _STDINT_H
#include <stddef.h>
typedef unsigned char uint8_t; /* 1 byte 0 to 255 */
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 signed long int32_t; /* 4 bytes -2147483647 to 2147483647 */
/* typedef signed long long int64_t; */
/* typedef unsigned long long uint64_t; */
#define INT8_MIN (-128)
#define INT16_MIN (-32768)
#define INT32_MIN (-2147483647 - 1)
#define INT8_MAX 127
#define INT16_MAX 32767
#define INT32_MAX 2147483647
#define UINT8_MAX 0xff /* 255U */
#define UINT16_MAX 0xffff /* 65535U */
#define UINT32_MAX 0xffffffff /* 4294967295U */
#endif /* STDINT_H */
+172
View File
@@ -0,0 +1,172 @@
/**************************************************************************
*
* Copyright (C) 2007 Steve Karg <skarg@users.sourceforge.net>
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*********************************************************************/
#include <stdint.h>
#include <stdio.h>
#include <dos.h>
/* global variable counts milliseconds */
volatile unsigned long Timer_Milliseconds;
/* MS/TP Silence Timer */
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
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
*/
/* 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;
default:
break;
}
return RS;
}
/* setting for 8192 interrupts per second
which is an interrupt every 122uS. */
#define INT_FREQ 8192
static void interrupt Timer_Interrupt_Handler(
void)
{
static uint16_t Timer_Ticks = 0;
static uint16_t Elapsed_Milliseconds = 0;
uint16_t milliseconds = 0;
uint16_t diff = 0;
uint8_t temp_reg;
Timer_Ticks++;
milliseconds = (Timer_Ticks * 1000)/INT_FREQ;
diff = milliseconds - Elapsed_Milliseconds;
if (diff >= 1) {
Elapsed_Milliseconds = milliseconds;
Timer_Milliseconds++;
if (SilenceTime < 60000)
SilenceTime++;
}
/* max resolution */
if (Timer_Ticks >= INT_FREQ) {
Timer_Ticks = 0;
Elapsed_Milliseconds = 0;
}
/* 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 );
/* signal end of interrupt to master PIC */
outportb( 0x20, 0x20 );
}
/* previous interrrupt vector */
static void interrupt(*OldVector)();
void Timer_Cleanup(void)
{
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);
/* disable interrupts */
disable();
/* set RTC int. vector for our routine */
setvect(0x70,Timer_Interrupt_Handler);
/* set register B with PIE enabled */
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)) );
/* re-enable system interrupts */
enable();
atexit(Timer_Cleanup);
}
int Timer_Silence(
void)
{
uint16_t time_value;
disable();
time_value = SilenceTime;
enable();
return time_value;
}
void Timer_Silence_Reset(
void)
{
disable();
SilenceTime = 0;
enable();
}
+47
View File
@@ -0,0 +1,47 @@
/**************************************************************************
*
* Copyright (C) 2007 Steve Karg <skarg@users.sourceforge.net>
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*********************************************************************/
#ifndef TIMER_H
#define TIMER_H
#include <stdint.h>
extern volatile unsigned long Timer_Milliseconds;
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
void Timer_Init(
void);
int Timer_Silence(
void);
void Timer_Silence_Reset(
void);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif
+9 -9
View File
@@ -59,10 +59,10 @@ static BACNET_SERVICES_SUPPORTED
SERVICE_SUPPORTED_CREATE_OBJECT,
SERVICE_SUPPORTED_DELETE_OBJECT,
SERVICE_SUPPORTED_READ_PROPERTY,
SERVICE_SUPPORTED_READ_PROPERTY_CONDITIONAL,
SERVICE_SUPPORTED_READ_PROPERTY_MULTIPLE,
SERVICE_SUPPORTED_READ_PROP_CONDITIONAL,
SERVICE_SUPPORTED_READ_PROP_MULTIPLE,
SERVICE_SUPPORTED_WRITE_PROPERTY,
SERVICE_SUPPORTED_WRITE_PROPERTY_MULTIPLE,
SERVICE_SUPPORTED_WRITE_PROP_MULTIPLE,
SERVICE_SUPPORTED_DEVICE_COMMUNICATION_CONTROL,
SERVICE_SUPPORTED_PRIVATE_TRANSFER,
SERVICE_SUPPORTED_TEXT_MESSAGE,
@@ -178,7 +178,7 @@ void apdu_set_confirmed_simple_ack_handler(
case SERVICE_CONFIRMED_REMOVE_LIST_ELEMENT:
case SERVICE_CONFIRMED_DELETE_OBJECT:
case SERVICE_CONFIRMED_WRITE_PROPERTY:
case SERVICE_CONFIRMED_WRITE_PROPERTY_MULTIPLE:
case SERVICE_CONFIRMED_WRITE_PROP_MULTIPLE:
/* Remote Device Management Services */
case SERVICE_CONFIRMED_DEVICE_COMMUNICATION_CONTROL:
case SERVICE_CONFIRMED_TEXT_MESSAGE:
@@ -208,8 +208,8 @@ void apdu_set_confirmed_ack_handler(
/* Object Access Services */
case SERVICE_CONFIRMED_CREATE_OBJECT:
case SERVICE_CONFIRMED_READ_PROPERTY:
case SERVICE_CONFIRMED_READ_PROPERTY_CONDITIONAL:
case SERVICE_CONFIRMED_READ_PROPERTY_MULTIPLE:
case SERVICE_CONFIRMED_READ_PROP_CONDITIONAL:
case SERVICE_CONFIRMED_READ_PROP_MULTIPLE:
case SERVICE_CONFIRMED_READ_RANGE:
/* Remote Device Management Services */
case SERVICE_CONFIRMED_PRIVATE_TRANSFER:
@@ -350,7 +350,7 @@ void apdu_handler(
case SERVICE_CONFIRMED_REMOVE_LIST_ELEMENT:
case SERVICE_CONFIRMED_DELETE_OBJECT:
case SERVICE_CONFIRMED_WRITE_PROPERTY:
case SERVICE_CONFIRMED_WRITE_PROPERTY_MULTIPLE:
case SERVICE_CONFIRMED_WRITE_PROP_MULTIPLE:
/* Remote Device Management Services */
case SERVICE_CONFIRMED_DEVICE_COMMUNICATION_CONTROL:
case SERVICE_CONFIRMED_REINITIALIZE_DEVICE:
@@ -394,8 +394,8 @@ void apdu_handler(
/* Object Access Services */
case SERVICE_CONFIRMED_CREATE_OBJECT:
case SERVICE_CONFIRMED_READ_PROPERTY:
case SERVICE_CONFIRMED_READ_PROPERTY_CONDITIONAL:
case SERVICE_CONFIRMED_READ_PROPERTY_MULTIPLE:
case SERVICE_CONFIRMED_READ_PROP_CONDITIONAL:
case SERVICE_CONFIRMED_READ_PROP_MULTIPLE:
case SERVICE_CONFIRMED_READ_RANGE:
case SERVICE_CONFIRMED_PRIVATE_TRANSFER:
/* Virtual Terminal Services */
+5 -5
View File
@@ -53,11 +53,11 @@ INDTEXT_DATA bacnet_confirmed_service_names[] = {
{SERVICE_CONFIRMED_CREATE_OBJECT, "Create-Object"},
{SERVICE_CONFIRMED_DELETE_OBJECT, "Delete-Object"},
{SERVICE_CONFIRMED_READ_PROPERTY, "Read-Property"},
{SERVICE_CONFIRMED_READ_PROPERTY_CONDITIONAL,
{SERVICE_CONFIRMED_READ_PROP_CONDITIONAL,
"Read-Property-Conditional"},
{SERVICE_CONFIRMED_READ_PROPERTY_MULTIPLE, "Read-Property-Multiple"},
{SERVICE_CONFIRMED_READ_PROP_MULTIPLE, "Read-Property-Multiple"},
{SERVICE_CONFIRMED_WRITE_PROPERTY, "Write-Property"},
{SERVICE_CONFIRMED_WRITE_PROPERTY_MULTIPLE, "Write-Property-Multiple"},
{SERVICE_CONFIRMED_WRITE_PROP_MULTIPLE, "Write-Property-Multiple"},
{SERVICE_CONFIRMED_DEVICE_COMMUNICATION_CONTROL,
"Device-Communication-Control"},
{SERVICE_CONFIRMED_PRIVATE_TRANSFER, "Private-Transfer"},
@@ -979,10 +979,10 @@ INDTEXT_DATA bacnet_engineering_unit_names[] = {
,
{UNITS_LITERS_PER_HOUR, "liters-per-hour"}
,
{UNITS_KILOWATT_HOURS_PER_SQUARE_METER,
{UNITS_KW_HOURS_PER_SQUARE_METER,
"kilowatt-hours-per-square-meter"}
,
{UNITS_KILOWATT_HOURS_PER_SQUARE_FOOT, "kilowatt-hours-per-square-foot"}
{UNITS_KW_HOURS_PER_SQUARE_FOOT, "kilowatt-hours-per-square-foot"}
,
{UNITS_MEGAJOULES_PER_SQUARE_METER, "megajoules-per-square-meter"}
,
+4 -4
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_PROPERTY_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_PROPERTY_MULTIPLE; /* service choice */
apdu[2] = SERVICE_CONFIRMED_READ_PROP_MULTIPLE; /* service choice */
apdu_len = 3;
}
@@ -415,7 +415,7 @@ int rpm_ack_decode_apdu(
if (apdu[0] != PDU_TYPE_COMPLEX_ACK)
return -1;
*invoke_id = apdu[1];
if (apdu[2] != SERVICE_CONFIRMED_READ_PROPERTY_MULTIPLE)
if (apdu[2] != SERVICE_CONFIRMED_READ_PROP_MULTIPLE)
return -1;
offset = 3;
if (apdu_len > offset) {
@@ -444,7 +444,7 @@ int rpm_decode_apdu(
return -1;
/* apdu[1] = encode_max_segs_max_apdu(0, Device_Max_APDU_Length_Accepted()); */
*invoke_id = apdu[2]; /* invoke id - filled in by net layer */
if (apdu[3] != SERVICE_CONFIRMED_READ_PROPERTY_MULTIPLE)
if (apdu[3] != SERVICE_CONFIRMED_READ_PROP_MULTIPLE)
return -1;
offset = 4;