Fixed up file indent, comments, and eol-type.

This commit is contained in:
skarg
2009-05-13 03:46:02 +00:00
parent 85c9efd2b5
commit 0c4edb33d9
49 changed files with 6758 additions and 6805 deletions
+1 -1
View File
@@ -153,7 +153,7 @@ void Send_Initialize_Routing_Table(
BACNET_NPDU_DATA npdu_data;
uint8_t number_of_ports = 0;
BACNET_ROUTER_PORT *router_port;
uint8_t i = 0; /* counter */
uint8_t i = 0; /* counter */
npdu_encode_npdu_network(&npdu_data, NETWORK_MESSAGE_INIT_RT_TABLE, true,
MESSAGE_PRIORITY_NORMAL);
+2 -1
View File
@@ -325,7 +325,8 @@ static void address_parse(BACNET_ADDRESS * dst,
dst->mac_len = 6;
for (index = 0; index < 4; index++) {
dst->mac[index] = mac[index];
} encode_unsigned16(&dst->mac[4],
}
encode_unsigned16(&dst->mac[4],
port);
} else {
count =
+2 -3
View File
@@ -137,7 +137,7 @@ BACNET_DATE Local_Date; /* rely on OS, if there is one */
If your UTC offset is -5hours of GMT,
then BACnet UTC offset is +5hours.
BACnet UTC offset is expressed in minutes. */
static int32_t UTC_Offset = 5*60;
static int32_t UTC_Offset = 5 * 60;
static bool Daylight_Savings_Status = false; /* rely on OS */
/* List_Of_Session_Keys */
/* Time_Synchronization_Recipients */
@@ -680,8 +680,7 @@ int Device_Encode_Property_APDU(
case PROP_LOCATION:
characterstring_init_ansi(&char_string, Location);
apdu_len =
encode_application_character_string(&apdu[0],
&char_string);
encode_application_character_string(&apdu[0], &char_string);
break;
/* FIXME: if you support time */
case PROP_LOCAL_TIME:
+1 -2
View File
@@ -230,8 +230,7 @@ void cleanup(void) {
old_rpm_property = rpm_property;
rpm_property = rpm_property->next;
free(old_rpm_property);
}
old_rpm_object = rpm_object;
} old_rpm_object = rpm_object;
rpm_object = rpm_object->next;
free(old_rpm_object);
}
+2 -2
View File
@@ -212,8 +212,8 @@ int main(int argc, char *argv[]) {
filename_remove_path(argv[0]), filename_remove_path(argv[0]));
return 0;
}
/* decode the command line parameters */
cov_data.subscriberProcessIdentifier = strtol(argv[1], NULL, 0);
/* decode the command line parameters */ cov_data.
subscriberProcessIdentifier = strtol(argv[1], NULL, 0);
cov_data.initiatingDeviceIdentifier = strtol(argv[2], NULL, 0);
cov_data.monitoredObjectIdentifier.type = strtol(argv[3], NULL, 0);
cov_data.monitoredObjectIdentifier.instance = strtol(argv[4], NULL, 0);
+1 -1
View File
@@ -396,7 +396,7 @@ typedef enum {
BINARY_INACTIVE = 0,
BINARY_ACTIVE = 1,
MAX_BINARY_PV = 1, /* for validating incoming values */
BINARY_NULL = 255 /* our homemade way of storing this info */
BINARY_NULL = 255 /* our homemade way of storing this info */
} BACNET_BINARY_PV;
typedef enum {
+2 -1
View File
@@ -35,7 +35,8 @@
extern "C" {
#endif /* __cplusplus */
void Binary_Output_Init(void);
void Binary_Output_Init(
void);
void Binary_Output_Property_Lists(
const int **pRequired,
+2 -1
View File
@@ -45,7 +45,8 @@ extern "C" {
#endif /* __cplusplus */
void Device_Init(void);
void Device_Init(
void);
void Device_Property_Lists(
const int **pRequired,
+1 -1
View File
@@ -438,7 +438,7 @@ int Device_Encode_Property_APDU(
case PROP_UTC_OFFSET:
/* Note: BACnet Time Zone is offset of local time and UTC,
rather than offset of GMT. It is expressed in minutes */
apdu_len = encode_application_signed(&apdu[0], 5*60 /* EST */ );
apdu_len = encode_application_signed(&apdu[0], 5 * 60 /* EST */ );
break;
case PROP_LOCAL_DATE:
/* FIXME: if you support date */
+6 -3
View File
@@ -57,7 +57,8 @@ void stack_init(
#endif
}
unsigned stack_size(void)
unsigned stack_size(
void)
{
#if defined(__GNUC__)
return (&__stack) - (&_end);
@@ -66,7 +67,8 @@ unsigned stack_size(void)
#endif
}
uint8_t stack_byte(unsigned offset)
uint8_t stack_byte(
unsigned offset)
{
#if defined(__GNUC__)
return *(&_end + offset);
@@ -76,7 +78,8 @@ uint8_t stack_byte(unsigned offset)
#endif
}
unsigned stack_unused(void)
unsigned stack_unused(
void)
{
unsigned count = 0;
#if defined(__GNUC__)
+8 -5
View File
@@ -33,16 +33,19 @@ extern "C" {
#endif /* __cplusplus */
/* C stack checking */
void stack_init(void);
void stack_init(
void);
unsigned stack_size(void);
unsigned stack_size(
void);
uint8_t stack_byte(unsigned offset);
uint8_t stack_byte(
unsigned offset);
unsigned stack_unused(void);
unsigned stack_unused(
void);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif
+21 -34
View File
@@ -45,8 +45,7 @@
/* the Relinquish Default value */
#define RELINQUISH_DEFAULT BINARY_INACTIVE
/* Here is our Priority Array.*/
static uint8_t
Binary_Output_Level[MAX_BINARY_OUTPUTS][BACNET_MAX_PRIORITY];
static uint8_t Binary_Output_Level[MAX_BINARY_OUTPUTS][BACNET_MAX_PRIORITY];
/* Writable out-of-service allows others to play with our Present Value */
/* without changing the physical output */
static uint8_t Out_Of_Service[MAX_BINARY_OUTPUTS];
@@ -101,12 +100,10 @@ void Binary_Output_Level_Set(
{
if (object_index < MAX_BINARY_OUTPUTS) {
if (priority < BACNET_MAX_PRIORITY) {
Binary_Output_Level[object_index][priority] = (uint8_t)level;
seeprom_bytes_write(
NV_SEEPROM_BINARY_OUTPUT(object_index,
NV_SEEPROM_BO_PRIORITY_ARRAY_1+priority),
&Binary_Output_Level[object_index][priority],
1);
Binary_Output_Level[object_index][priority] = (uint8_t) level;
seeprom_bytes_write(NV_SEEPROM_BINARY_OUTPUT(object_index,
NV_SEEPROM_BO_PRIORITY_ARRAY_1 + priority),
&Binary_Output_Level[object_index][priority], 1);
}
}
}
@@ -118,11 +115,8 @@ void Binary_Output_Polarity_Set(
if (object_index < MAX_BINARY_OUTPUTS) {
if (polarity < MAX_POLARITY) {
Polarity[object_index] = POLARITY_NORMAL;
seeprom_bytes_write(
NV_SEEPROM_BINARY_OUTPUT(object_index,
NV_SEEPROM_BO_POLARITY),
&Polarity[object_index],
1);
seeprom_bytes_write(NV_SEEPROM_BINARY_OUTPUT(object_index,
NV_SEEPROM_BO_POLARITY), &Polarity[object_index], 1);
}
}
}
@@ -133,10 +127,8 @@ void Binary_Output_Out_Of_Service_Set(
{
if (object_index < MAX_BINARY_OUTPUTS) {
Out_Of_Service[object_index] = flag;
seeprom_bytes_write(
NV_SEEPROM_BINARY_OUTPUT(object_index,
NV_SEEPROM_BO_OUT_OF_SERVICE),
&Out_Of_Service[object_index],
seeprom_bytes_write(NV_SEEPROM_BINARY_OUTPUT(object_index,
NV_SEEPROM_BO_OUT_OF_SERVICE), &Out_Of_Service[object_index],
1);
}
}
@@ -312,7 +304,8 @@ int Binary_Output_Encode_Property_APDU(
apdu_len = encode_application_boolean(&apdu[0], state);
break;
case PROP_POLARITY:
apdu_len = encode_application_enumerated(&apdu[0],
apdu_len =
encode_application_enumerated(&apdu[0],
Polarity[object_index]);
break;
case PROP_PRIORITY_ARRAY:
@@ -427,7 +420,7 @@ bool Binary_Output_Write_Property(
(value.type.Enumerated <= MAX_BINARY_PV)) {
level = (BACNET_BINARY_PV) value.type.Enumerated;
priority--;
Binary_Output_Level_Set(object_index, priority,level);
Binary_Output_Level_Set(object_index, priority, level);
Binary_Output_Sync(wp_data->object_instance);
status = true;
} else if (priority == 6) {
@@ -445,7 +438,7 @@ bool Binary_Output_Write_Property(
priority = wp_data->priority;
if (priority && (priority <= BACNET_MAX_PRIORITY)) {
priority--;
Binary_Output_Level_Set(object_index, priority,level);
Binary_Output_Level_Set(object_index, priority, level);
Binary_Output_Sync(wp_data->object_instance);
status = true;
} else if (priority == 6) {
@@ -490,7 +483,7 @@ bool Binary_Output_Write_Property(
*error_code = ERROR_CODE_INVALID_DATA_TYPE;
}
break;
default:
default:
*error_class = ERROR_CLASS_PROPERTY;
*error_code = ERROR_CODE_WRITE_ACCESS_DENIED;
break;
@@ -506,26 +499,20 @@ void Binary_Output_Init(
/* initialize all the analog output priority arrays to NULL */
for (i = 0; i < MAX_BINARY_OUTPUTS; i++) {
seeprom_bytes_read(
NV_SEEPROM_BINARY_OUTPUT(i,NV_SEEPROM_BO_POLARITY),
&Polarity[i],
1);
seeprom_bytes_read(NV_SEEPROM_BINARY_OUTPUT(i, NV_SEEPROM_BO_POLARITY),
&Polarity[i], 1);
if (Polarity[i] >= MAX_POLARITY) {
Binary_Output_Polarity_Set(i, POLARITY_NORMAL);
}
seeprom_bytes_read(
NV_SEEPROM_BINARY_OUTPUT(i,NV_SEEPROM_BO_OUT_OF_SERVICE),
&Out_Of_Service[i],
1);
seeprom_bytes_read(NV_SEEPROM_BINARY_OUTPUT(i,
NV_SEEPROM_BO_OUT_OF_SERVICE), &Out_Of_Service[i], 1);
if (Out_Of_Service[i] > 1) {
Binary_Output_Out_Of_Service_Set(i, false);
}
for (j = 0; j < BACNET_MAX_PRIORITY; j++) {
seeprom_bytes_read(
NV_SEEPROM_BINARY_OUTPUT(i,
NV_SEEPROM_BO_PRIORITY_ARRAY_1+j),
&Binary_Output_Level[i][j],
1);
seeprom_bytes_read(NV_SEEPROM_BINARY_OUTPUT(i,
NV_SEEPROM_BO_PRIORITY_ARRAY_1 + j),
&Binary_Output_Level[i][j], 1);
}
Binary_Output_Sync(i);
}
@@ -1,7 +1,7 @@
/* definitions generated by preprocessor, copy into defines.h */
#ifndef PPINC
#define _ATMEGA644P // device select: _ATMEGAxxxx
#define _B2048 // boot size select: _Bxxxx (words), powers of two only
#define _ATMEGA644P /* device select: _ATMEGAxxxx */
#define _B2048 /* boot size select: _Bxxxx (words), powers of two only */
#ifdef __ICCAVR__
#include "iom644.h"
#endif
@@ -33,7 +33,7 @@
#define SPMCR_REG SPMCSR
#define PAGESIZE 256
#define APP_END 61440
//#define LARGE_MEMORY
/*#define LARGE_MEMORY */
/* definitions for device recognition */
#define PARTCODE 0
@@ -31,11 +31,11 @@
/* Uncomment the following to save code space */
//#define REMOVE_AVRPROG_SUPPORT
//#define REMOVE_FUSE_AND_LOCK_BIT_SUPPORT
//#define REMOVE_BLOCK_SUPPORT
//#define REMOVE_EEPROM_BYTE_SUPPORT
//#define REMOVE_FLASH_BYTE_SUPPORT
/*#define REMOVE_AVRPROG_SUPPORT */
/*#define REMOVE_FUSE_AND_LOCK_BIT_SUPPORT */
/*#define REMOVE_BLOCK_SUPPORT */
/*#define REMOVE_EEPROM_BYTE_SUPPORT */
/*#define REMOVE_FLASH_BYTE_SUPPORT */
/*
* GCC doesn't optimize long int arithmetics very clever. As the
@@ -47,13 +47,19 @@
*/
#ifdef LARGE_MEMORY
# define ADDR_T unsigned long
#else /* !LARGE_MEMORY */
#else /* !LARGE_MEMORY */
# define ADDR_T unsigned int
#endif /* LARGE_MEMORY */
#ifndef REMOVE_BLOCK_SUPPORT
unsigned char BlockLoad(unsigned int size, unsigned char mem, ADDR_T *address);
void BlockRead(unsigned int size, unsigned char mem, ADDR_T *address);
unsigned char BlockLoad(
unsigned int size,
unsigned char mem,
ADDR_T * address);
void BlockRead(
unsigned int size,
unsigned char mem,
ADDR_T * address);
/* BLOCKSIZE should be chosen so that the following holds: BLOCKSIZE*n = PAGESIZE, where n=1,2,3... */
#define BLOCKSIZE PAGESIZE
@@ -61,11 +67,12 @@ void BlockRead(unsigned int size, unsigned char mem, ADDR_T *address);
#endif /* REMOVE_BLOCK_SUPPORT */
#ifdef __ICCAVR__
__C_task void main(void)
__C_task void main(
void)
#else /* ! __ICCAVR__ */
int main(void)
int main(
void)
#endif /* __ICCAVR__ */
{
ADDR_T address;
unsigned int temp_int;
@@ -73,268 +80,240 @@ int main(void)
/* Initialization */
void (*funcptr)( void ) = 0x0000; // Set up function pointer to RESET vector.
PROGPORT |= (1<<PROG_NO); // Enable pull-up on PROG_NO line on PROGPORT.
initbootuart(); // Initialize UART.
void (
*funcptr) (
void) = 0x0000; /* Set up function pointer to RESET vector. */
PROGPORT |= (1 << PROG_NO); /* Enable pull-up on PROG_NO line on PROGPORT. */
initbootuart(); /* Initialize UART. */
/* Branch to bootloader or application code? */
if( !(PROGPIN & (1<<PROG_NO)) ) // If PROGPIN is pulled low, enter programmingmode.
{
if (!(PROGPIN & (1 << PROG_NO))) { /* If PROGPIN is pulled low, enter programmingmode. */
/* Main loop */
for(;;)
{
val=recchar(); // Wait for command character.
for (;;) {
val = recchar(); /* Wait for command character. */
// Check autoincrement status.
if(val=='a')
{
sendchar('Y'); // Yes, we do autoincrement.
/* Check autoincrement status. */
if (val == 'a') {
sendchar('Y'); /* Yes, we do autoincrement. */
}
// Set address.
else if(val=='A') // Set address...
{ // NOTE: Flash addresses are given in words, not bytes.
address=(recchar()<<8) | recchar(); // Read address high and low byte.
sendchar('\r'); // Send OK back.
/* Set address. */
else if (val == 'A') { /* Set address... *//* NOTE: Flash addresses are given in words, not bytes. */
address = (recchar() << 8) | recchar(); /* Read address high and low byte. */
sendchar('\r'); /* Send OK back. */
}
// Chip erase.
else if(val=='e')
{
for(address = 0; address < APP_END;address += PAGESIZE)
{ // NOTE: Here we use address as a byte-address, not word-address, for convenience.
/* Chip erase. */
else if (val == 'e') {
for (address = 0; address < APP_END; address += PAGESIZE) { /* NOTE: Here we use address as a byte-address, not word-address, for convenience. */
_WAIT_FOR_SPM();
#ifdef __ICCAVR__
#pragma diag_suppress=Pe1053 // Suppress warning for conversion from long-type address to flash ptr.
#pragma diag_suppress=Pe1053 /* Suppress warning for conversion from long-type address to flash ptr. */
#endif
_PAGE_ERASE( address );
_PAGE_ERASE(address);
#ifdef __ICCAVR__
#pragma diag_default=Pe1053 // Back to default.
#pragma diag_default=Pe1053 /* Back to default. */
#endif
}
sendchar('\r'); // Send OK back.
sendchar('\r'); /* Send OK back. */
}
#ifndef REMOVE_BLOCK_SUPPORT
/* Check block load support. */
else if (val == 'b') {
sendchar('Y'); /* Report block load supported. */
sendchar((BLOCKSIZE >> 8) & 0xFF); /* MSB first. */
sendchar(BLOCKSIZE & 0xFF); /* Report BLOCKSIZE (bytes). */
}
#ifndef REMOVE_BLOCK_SUPPORT
// Check block load support.
else if(val=='b')
{
sendchar('Y'); // Report block load supported.
sendchar((BLOCKSIZE>>8) & 0xFF); // MSB first.
sendchar(BLOCKSIZE&0xFF); // Report BLOCKSIZE (bytes).
}
/* Start block load. */
else if (val == 'B') {
temp_int = (recchar() << 8) | recchar(); /* Get block size. */
val = recchar(); /* Get memtype. */
sendchar(BlockLoad(temp_int, val, &address)); /* Block load. */
}
// Start block load.
else if(val=='B')
{
temp_int = (recchar()<<8) | recchar(); // Get block size.
val = recchar(); // Get memtype.
sendchar( BlockLoad(temp_int,val,&address) ); // Block load.
}
// Start block read.
else if(val=='g')
{
temp_int = (recchar()<<8) | recchar(); // Get block size.
val = recchar(); // Get memtype
BlockRead(temp_int,val,&address); // Block read
}
/* Start block read. */
else if (val == 'g') {
temp_int = (recchar() << 8) | recchar(); /* Get block size. */
val = recchar(); /* Get memtype */
BlockRead(temp_int, val, &address); /* Block read */
}
#endif /* REMOVE_BLOCK_SUPPORT */
#ifndef REMOVE_FLASH_BYTE_SUPPORT
// Read program memory.
else if(val=='R')
{
// Send high byte, then low byte of flash word.
/* Read program memory. */
else if (val == 'R') {
/* Send high byte, then low byte of flash word. */
_WAIT_FOR_SPM();
_ENABLE_RWW_SECTION();
#ifdef __ICCAVR__
#pragma diag_suppress=Pe1053 // Suppress warning for conversion from long-type address to flash ptr.
#pragma diag_suppress=Pe1053 /* Suppress warning for conversion from long-type address to flash ptr. */
#endif
sendchar( _LOAD_PROGRAM_MEMORY( (address << 1)+1 ) );
sendchar( _LOAD_PROGRAM_MEMORY( (address << 1)+0 ) );
sendchar(_LOAD_PROGRAM_MEMORY((address << 1) + 1));
sendchar(_LOAD_PROGRAM_MEMORY((address << 1) + 0));
#ifdef __ICCAVR__
#pragma diag_default=Pe1053 // Back to default.
#pragma diag_default=Pe1053 /* Back to default. */
#endif
address++; // Auto-advance to next Flash word.
address++; /* Auto-advance to next Flash word. */
}
// Write program memory, low byte.
else if(val=='c')
{ // NOTE: Always use this command before sending high byte.
temp_int=recchar(); // Get low byte for later _FILL_TEMP_WORD.
sendchar('\r'); // Send OK back.
/* Write program memory, low byte. */
else if (val == 'c') { /* NOTE: Always use this command before sending high byte. */
temp_int = recchar(); /* Get low byte for later _FILL_TEMP_WORD. */
sendchar('\r'); /* Send OK back. */
}
// Write program memory, high byte.
else if(val=='C')
{
temp_int |= (recchar()<<8); // Get and insert high byte.
/* Write program memory, high byte. */
else if (val == 'C') {
temp_int |= (recchar() << 8); /* Get and insert high byte. */
_WAIT_FOR_SPM();
#ifdef __ICCAVR__
#pragma diag_suppress=Pe1053 // Suppress warning for conversion from long-type address to flash ptr.
#pragma diag_suppress=Pe1053 /* Suppress warning for conversion from long-type address to flash ptr. */
#endif
_FILL_TEMP_WORD( (address << 1), temp_int ); // Convert word-address to byte-address and fill.
_FILL_TEMP_WORD((address << 1), temp_int); /* Convert word-address to byte-address and fill. */
#ifdef __ICCAVR__
#pragma diag_default=Pe1053 // Back to default.
#pragma diag_default=Pe1053 /* Back to default. */
#endif
address++; // Auto-advance to next Flash word.
sendchar('\r'); // Send OK back.
address++; /* Auto-advance to next Flash word. */
sendchar('\r'); /* Send OK back. */
}
// Write page.
else if(val== 'm')
{
if( address >= (APP_END>>1) ) // Protect bootloader area.
{
/* Write page. */
else if (val == 'm') {
if (address >= (APP_END >> 1)) { /* Protect bootloader area. */
sendchar('?');
} else
{
} else {
_WAIT_FOR_SPM();
#ifdef __ICCAVR__
#pragma diag_suppress=Pe1053 // Suppress warning for conversion from long-type address to flash ptr.
#pragma diag_suppress=Pe1053 /* Suppress warning for conversion from long-type address to flash ptr. */
#endif
_PAGE_WRITE( address << 1 ); // Convert word-address to byte-address and write.
_PAGE_WRITE(address << 1); /* Convert word-address to byte-address and write. */
#ifdef __ICCAVR__
#pragma diag_default=Pe1053 // Back to default.
#pragma diag_default=Pe1053 /* Back to default. */
#endif
}
sendchar('\r'); // Send OK back.
sendchar('\r'); /* Send OK back. */
}
#endif /* REMOVE_FLASH_BYTE_SUPPORT */
#ifndef REMOVE_EEPROM_BYTE_SUPPORT
// Write EEPROM memory.
else if (val == 'D')
{
/* Write EEPROM memory. */
else if (val == 'D') {
_WAIT_FOR_SPM();
EEARL = address; // Setup EEPROM address.
EEARL = address; /* Setup EEPROM address. */
EEARH = (address >> 8);
EEDR = recchar(); // Get byte.
EECR |= (1<<EEMWE); // Write byte.
EECR |= (1<<EEWE);
while (EECR & (1<<EEWE)) // Wait for write operation to finish.
EEDR = recchar(); /* Get byte. */
EECR |= (1 << EEMWE); /* Write byte. */
EECR |= (1 << EEWE);
while (EECR & (1 << EEWE)) /* Wait for write operation to finish. */
;
address++; // Auto-advance to next EEPROM byte.
sendchar('\r');// Send OK back.
address++; /* Auto-advance to next EEPROM byte. */
sendchar('\r'); /* Send OK back. */
}
// Read EEPROM memory.
else if (val == 'd')
{
EEARL = address; // Setup EEPROM address.
/* Read EEPROM memory. */
else if (val == 'd') {
EEARL = address; /* Setup EEPROM address. */
EEARH = (address >> 8);
EECR |= (1<<EERE); // Read byte...
sendchar(EEDR); // ...and send it back.
address++; // Auto-advance to next EEPROM byte.
EECR |= (1 << EERE); /* Read byte... */
sendchar(EEDR); /* ...and send it back. */
address++; /* Auto-advance to next EEPROM byte. */
}
#endif /* REMOVE_EEPROM_BYTE_SUPPORT */
#ifndef REMOVE_FUSE_AND_LOCK_BIT_SUPPORT
// Write lockbits.
else if(val=='l')
{
/* Write lockbits. */
else if (val == 'l') {
_WAIT_FOR_SPM();
_SET_LOCK_BITS( recchar() ); // Read and set lock bits.
sendchar('\r'); // Send OK back.
_SET_LOCK_BITS(recchar()); /* Read and set lock bits. */
sendchar('\r'); /* Send OK back. */
}
#if defined(_GET_LOCK_BITS)
// Read lock bits.
else if(val=='r')
{
/* Read lock bits. */
else if (val == 'r') {
_WAIT_FOR_SPM();
sendchar( _GET_LOCK_BITS() );
sendchar(_GET_LOCK_BITS());
}
// Read fuse bits.
else if(val=='F')
{
/* Read fuse bits. */
else if (val == 'F') {
_WAIT_FOR_SPM();
sendchar( _GET_LOW_FUSES() );
sendchar(_GET_LOW_FUSES());
}
// Read high fuse bits.
else if(val=='N')
{
/* Read high fuse bits. */
else if (val == 'N') {
_WAIT_FOR_SPM();
sendchar( _GET_HIGH_FUSES() );
sendchar(_GET_HIGH_FUSES());
}
// Read extended fuse bits.
else if(val=='Q')
{
/* Read extended fuse bits. */
else if (val == 'Q') {
_WAIT_FOR_SPM();
sendchar( _GET_EXTENDED_FUSES() );
sendchar(_GET_EXTENDED_FUSES());
}
#endif /* defined(_GET_LOCK_BITS) */
#endif /* REMOVE_FUSE_AND_LOCK_BIT_SUPPORT */
#ifndef REMOVE_AVRPROG_SUPPORT
// Enter and leave programming mode.
else if((val=='P')||(val=='L'))
{
sendchar('\r'); // Nothing special to do, just answer OK.
/* Enter and leave programming mode. */
else if ((val == 'P') || (val == 'L')) {
sendchar('\r'); /* Nothing special to do, just answer OK. */
}
// Exit bootloader.
else if(val=='E')
{
/* Exit bootloader. */
else if (val == 'E') {
_WAIT_FOR_SPM();
_ENABLE_RWW_SECTION();
sendchar('\r');
funcptr(); // Jump to Reset vector 0x0000 in Application Section.
funcptr(); /* Jump to Reset vector 0x0000 in Application Section. */
}
// Get programmer type.
else if (val=='p')
{
sendchar('S'); // Answer 'SERIAL'.
/* Get programmer type. */
else if (val == 'p') {
sendchar('S'); /* Answer 'SERIAL'. */
}
// Return supported device codes.
else if(val=='t')
{
/* Return supported device codes. */
else if (val == 't') {
#if PARTCODE+0 > 0
sendchar( PARTCODE ); // Supports only this device, of course.
sendchar(PARTCODE); /* Supports only this device, of course. */
#endif /* PARTCODE */
sendchar( 0 ); // Send list terminator.
sendchar(0); /* Send list terminator. */
}
// Set LED, clear LED and set device type.
else if((val=='x')||(val=='y')||(val=='T'))
{
recchar(); // Ignore the command and it's parameter.
sendchar('\r'); // Send OK back.
/* Set LED, clear LED and set device type. */
else if ((val == 'x') || (val == 'y') || (val == 'T')) {
recchar(); /* Ignore the command and it's parameter. */
sendchar('\r'); /* Send OK back. */
}
#endif /* REMOVE_AVRPROG_SUPPORT */
// Return programmer identifier.
else if(val=='S')
{
sendchar('A'); // Return 'AVRBOOT'.
sendchar('V'); // Software identifier (aka programmer signature) is always 7 characters.
/* Return programmer identifier. */
else if (val == 'S') {
sendchar('A'); /* Return 'AVRBOOT'. */
sendchar('V'); /* Software identifier (aka programmer signature) is always 7 characters. */
sendchar('R');
sendchar('B');
sendchar('O');
@@ -343,151 +322,143 @@ int main(void)
}
// Return software version.
else if(val=='V')
{
/* Return software version. */
else if (val == 'V') {
sendchar('1');
sendchar('5');
}
// Return signature bytes.
else if(val=='s')
{
sendchar( SIGNATURE_BYTE_3 );
sendchar( SIGNATURE_BYTE_2 );
sendchar( SIGNATURE_BYTE_1 );
/* Return signature bytes. */
else if (val == 's') {
sendchar(SIGNATURE_BYTE_3);
sendchar(SIGNATURE_BYTE_2);
sendchar(SIGNATURE_BYTE_1);
}
// The last command to accept is ESC (synchronization).
else if(val!=0x1b) // If not ESC, then it is unrecognized...
{
/* The last command to accept is ESC (synchronization). */
else if (val != 0x1b) { /* If not ESC, then it is unrecognized... */
sendchar('?');
}
} // end: for(;;)
}
else
{
} /* end: for(;;) */
} else {
_WAIT_FOR_SPM();
_ENABLE_RWW_SECTION();
funcptr(); // Jump to Reset vector 0x0000 in Application Section.
funcptr(); /* Jump to Reset vector 0x0000 in Application Section. */
}
} // end: main
} /* end: main */
#ifndef REMOVE_BLOCK_SUPPORT
unsigned char BlockLoad(unsigned int size, unsigned char mem, ADDR_T *address)
unsigned char BlockLoad(
unsigned int size,
unsigned char mem,
ADDR_T * address)
{
unsigned char buffer[BLOCKSIZE];
unsigned int data;
ADDR_T tempaddress;
// EEPROM memory type.
if(mem=='E')
{
/* EEPROM memory type. */
if (mem == 'E') {
/* Fill buffer first, as EEPROM is too slow to copy with UART speed */
for(tempaddress=0;tempaddress<size;tempaddress++)
for (tempaddress = 0; tempaddress < size; tempaddress++)
buffer[tempaddress] = recchar();
/* Then program the EEPROM */
_WAIT_FOR_SPM();
for( tempaddress=0; tempaddress < size; tempaddress++)
{
EEARL = *address; // Setup EEPROM address
for (tempaddress = 0; tempaddress < size; tempaddress++) {
EEARL = *address; /* Setup EEPROM address */
EEARH = ((*address) >> 8);
EEDR = buffer[tempaddress]; // Get byte.
EECR |= (1<<EEMWE); // Write byte.
EECR |= (1<<EEWE);
while (EECR & (1<<EEWE)) // Wait for write operation to finish.
EEDR = buffer[tempaddress]; /* Get byte. */
EECR |= (1 << EEMWE); /* Write byte. */
EECR |= (1 << EEWE);
while (EECR & (1 << EEWE)) /* Wait for write operation to finish. */
;
(*address)++; // Select next EEPROM byte
(*address)++; /* Select next EEPROM byte */
}
return '\r'; // Report programming OK
return '\r'; /* Report programming OK */
}
// Flash memory type.
else if(mem=='F')
{ // NOTE: For flash programming, 'address' is given in words.
(*address) <<= 1; // Convert address to bytes temporarily.
tempaddress = (*address); // Store address in page.
/* Flash memory type. */
else if (mem == 'F') { /* NOTE: For flash programming, 'address' is given in words. */
(*address) <<= 1; /* Convert address to bytes temporarily. */
tempaddress = (*address); /* Store address in page. */
do
{
do {
data = recchar();
data |= (recchar() << 8);
#ifdef __ICCAVR__
#pragma diag_suppress=Pe1053 // Suppress warning for conversion from long-type address to flash ptr.
#pragma diag_suppress=Pe1053 /* Suppress warning for conversion from long-type address to flash ptr. */
#endif
_FILL_TEMP_WORD(*address,data);
_FILL_TEMP_WORD(*address, data);
#ifdef __ICCAVR__
#pragma diag_default=Pe1053 // Back to default.
#pragma diag_default=Pe1053 /* Back to default. */
#endif
(*address)+=2; // Select next word in memory.
size -= 2; // Reduce number of bytes to write by two.
} while(size); // Loop until all bytes written.
(*address) += 2; /* Select next word in memory. */
size -= 2; /* Reduce number of bytes to write by two. */
} while (size); /* Loop until all bytes written. */
#ifdef __ICCAVR__
#pragma diag_suppress=Pe1053 // Suppress warning for conversion from long-type address to flash ptr.
#pragma diag_suppress=Pe1053 /* Suppress warning for conversion from long-type address to flash ptr. */
#endif
_PAGE_WRITE(tempaddress);
_PAGE_WRITE(tempaddress);
#ifdef __ICCAVR__
#pragma diag_default=Pe1053 // Back to default.
#pragma diag_default=Pe1053 /* Back to default. */
#endif
_WAIT_FOR_SPM();
_ENABLE_RWW_SECTION();
_WAIT_FOR_SPM();
_ENABLE_RWW_SECTION();
(*address) >>= 1; // Convert address back to Flash words again.
return '\r'; // Report programming OK
(*address) >>= 1; /* Convert address back to Flash words again. */
return '\r'; /* Report programming OK */
}
// Invalid memory type?
else
{
/* Invalid memory type? */
else {
return '?';
}
}
void BlockRead(unsigned int size, unsigned char mem, ADDR_T *address)
void BlockRead(
unsigned int size,
unsigned char mem,
ADDR_T * address)
{
// EEPROM memory type.
if (mem=='E') // Read EEPROM
{
do
{
EEARL = *address; // Setup EEPROM address
/* EEPROM memory type. */
if (mem == 'E') { /* Read EEPROM */
do {
EEARL = *address; /* Setup EEPROM address */
EEARH = ((*address) >> 8);
(*address)++; // Select next EEPROM byte
EECR |= (1<<EERE); // Read EEPROM
sendchar(EEDR); // Transmit EEPROM dat ato PC
(*address)++; /* Select next EEPROM byte */
EECR |= (1 << EERE); /* Read EEPROM */
sendchar(EEDR); /* Transmit EEPROM dat ato PC */
size--; // Decrease number of bytes to read
} while (size); // Repeat until all block has been read
size--; /* Decrease number of bytes to read */
} while (size); /* Repeat until all block has been read */
}
// Flash memory type.
else if(mem=='F')
{
(*address) <<= 1; // Convert address to bytes temporarily.
/* Flash memory type. */
else if (mem == 'F') {
(*address) <<= 1; /* Convert address to bytes temporarily. */
do
{
do {
#ifdef __ICCAVR__
#pragma diag_suppress=Pe1053 // Suppress warning for conversion from long-type address to flash ptr.
#pragma diag_suppress=Pe1053 /* Suppress warning for conversion from long-type address to flash ptr. */
#endif
sendchar( _LOAD_PROGRAM_MEMORY(*address) );
sendchar( _LOAD_PROGRAM_MEMORY((*address)+1) );
sendchar(_LOAD_PROGRAM_MEMORY(*address));
sendchar(_LOAD_PROGRAM_MEMORY((*address) + 1));
#ifdef __ICCAVR__
#pragma diag_default=Pe1053 // Back to default.
#pragma diag_default=Pe1053 /* Back to default. */
#endif
(*address) += 2; // Select next word in memory.
size -= 2; // Subtract two bytes from number of bytes to read
} while (size); // Repeat until all block has been read
(*address) += 2; /* Select next word in memory. */
size -= 2; /* Subtract two bytes from number of bytes to read */
} while (size); /* Repeat until all block has been read */
(*address) >>= 1; // Convert address back to Flash words again.
(*address) >>= 1; /* Convert address back to Flash words again. */
}
}
#endif /* REMOVE_BLOCK_SUPPORT */
@@ -19,24 +19,26 @@
#include "defines.h"
void initbootuart(void)
void initbootuart(
void)
{
BAUD_RATE_LOW_REG = BRREG_VALUE;
UART_CONTROL_REG = (1 << ENABLE_RECEIVER_BIT) |
(1 << ENABLE_TRANSMITTER_BIT); // enable receive and transmit
BAUD_RATE_LOW_REG = BRREG_VALUE;
UART_CONTROL_REG = (1 << ENABLE_RECEIVER_BIT) | (1 << ENABLE_TRANSMITTER_BIT); /* enable receive and transmit */
}
void sendchar(unsigned char c)
void sendchar(
unsigned char c)
{
UART_DATA_REG = c; // prepare transmission
while (!(UART_STATUS_REG & (1 << TRANSMIT_COMPLETE_BIT)));// wait until byte sendt
UART_STATUS_REG |= (1 << TRANSMIT_COMPLETE_BIT); // delete TXCflag
UART_DATA_REG = c; /* prepare transmission */
while (!(UART_STATUS_REG & (1 << TRANSMIT_COMPLETE_BIT))); /* wait until byte sendt */
UART_STATUS_REG |= (1 << TRANSMIT_COMPLETE_BIT); /* delete TXCflag */
}
unsigned char recchar(void)
unsigned char recchar(
void)
{
while(!(UART_STATUS_REG & (1 << RECEIVE_COMPLETE_BIT))); // wait for data
return UART_DATA_REG;
while (!(UART_STATUS_REG & (1 << RECEIVE_COMPLETE_BIT))); /* wait for data */
return UART_DATA_REG;
}
@@ -17,6 +17,9 @@
* Description : Header file for serial.c
****************************************************************************/
void initbootuart( void );
void sendchar( unsigned char );
unsigned char recchar( void );
void initbootuart(
void);
void sendchar(
unsigned char);
unsigned char recchar(
void);
+21 -43
View File
@@ -122,40 +122,26 @@ void Device_Init(
Reinitialize_State = REINITIALIZED_STATE_IDLE;
dcc_set_status_duration(COMMUNICATION_ENABLE, 0);
/* Get the data from the eeprom */
eeprom_bytes_read(
NV_EEPROM_DEVICE_0,
(uint8_t *)&Object_Instance_Number,
eeprom_bytes_read(NV_EEPROM_DEVICE_0, (uint8_t *) & Object_Instance_Number,
sizeof(Object_Instance_Number));
if (Object_Instance_Number >= BACNET_MAX_INSTANCE) {
Object_Instance_Number = 0;
eeprom_bytes_write(
NV_EEPROM_DEVICE_0,
(uint8_t *)&Object_Instance_Number,
eeprom_bytes_write(NV_EEPROM_DEVICE_0,
(uint8_t *) & Object_Instance_Number,
sizeof(Object_Instance_Number));
}
eeprom_bytes_read(
NV_EEPROM_DEVICE_NAME_ENCODING,
&Object_Name_Encoding,
eeprom_bytes_read(NV_EEPROM_DEVICE_NAME_ENCODING, &Object_Name_Encoding,
1);
eeprom_bytes_read(
NV_EEPROM_DEVICE_NAME_LENGTH,
&Object_Name_Length,
1);
eeprom_bytes_read(
NV_EEPROM_DEVICE_NAME_0,
(uint8_t *)&Object_Name[0],
eeprom_bytes_read(NV_EEPROM_DEVICE_NAME_LENGTH, &Object_Name_Length, 1);
eeprom_bytes_read(NV_EEPROM_DEVICE_NAME_0, (uint8_t *) & Object_Name[0],
NV_EEPROM_DEVICE_NAME_SIZE);
if ((Object_Name_Encoding >= MAX_CHARACTER_STRING_ENCODING) ||
(Object_Name_Length > NV_EEPROM_DEVICE_NAME_SIZE)) {
Object_Name_Encoding = CHARACTER_ANSI_X34;
Object_Name_Length = 0;
eeprom_bytes_write(
NV_EEPROM_DEVICE_NAME_ENCODING,
&Object_Name_Encoding,
1);
eeprom_bytes_write(
NV_EEPROM_DEVICE_NAME_LENGTH,
&Object_Name_Length,
eeprom_bytes_write(NV_EEPROM_DEVICE_NAME_ENCODING,
&Object_Name_Encoding, 1);
eeprom_bytes_write(NV_EEPROM_DEVICE_NAME_LENGTH, &Object_Name_Length,
1);
}
}
@@ -174,9 +160,8 @@ bool Device_Set_Object_Instance_Number(
if (object_id <= BACNET_MAX_INSTANCE) {
Object_Instance_Number = object_id;
eeprom_bytes_write(
NV_EEPROM_DEVICE_0,
(uint8_t *)&Object_Instance_Number,
eeprom_bytes_write(NV_EEPROM_DEVICE_0,
(uint8_t *) & Object_Instance_Number,
sizeof(Object_Instance_Number));
} else
status = false;
@@ -334,10 +319,8 @@ int Device_Encode_Property_APDU(
Object_Instance_Number);
break;
case PROP_OBJECT_NAME:
characterstring_init(&char_string,
Object_Name_Encoding,
(char *)&Object_Name[0],
Object_Name_Length);
characterstring_init(&char_string, Object_Name_Encoding,
(char *) &Object_Name[0], Object_Name_Length);
apdu_len =
encode_application_character_string(&apdu[0], &char_string);
break;
@@ -590,23 +573,18 @@ bool Device_Write_Property(
char *pCharString;
Object_Name_Encoding = encoding;
Object_Name_Length = length;
eeprom_bytes_write(
NV_EEPROM_DEVICE_NAME_ENCODING,
&Object_Name_Encoding,
1);
eeprom_bytes_write(
NV_EEPROM_DEVICE_NAME_LENGTH,
&Object_Name_Length,
1);
eeprom_bytes_write(NV_EEPROM_DEVICE_NAME_ENCODING,
&Object_Name_Encoding, 1);
eeprom_bytes_write(NV_EEPROM_DEVICE_NAME_LENGTH,
&Object_Name_Length, 1);
pCharString =
characterstring_value(&value.type.Character_String);
characterstring_value(&value.type.
Character_String);
for (i = 0; i < Object_Name_Length; i++) {
Object_Name[i] = pCharString[i];
}
eeprom_bytes_write(
NV_EEPROM_DEVICE_NAME_0,
(uint8_t *)&Object_Name[0],
length);
eeprom_bytes_write(NV_EEPROM_DEVICE_NAME_0,
(uint8_t *) & Object_Name[0], length);
status = true;
} else {
*error_class = ERROR_CLASS_PROPERTY;
+1 -1
View File
@@ -1063,7 +1063,7 @@ static bool MSTP_Master_Node_FSM(
}
MSTP_Flag.ReceivedValidFrame = false;
} else if ((timer_elapsed_milliseconds(TIMER_SILENCE,
Tusage_timeout)) ||
Tusage_timeout)) ||
(MSTP_Flag.ReceivedInvalidFrame == true)) {
if (MSTP_Flag.SoleMaster == true) {
/* SoleMaster */
+11 -11
View File
@@ -31,16 +31,16 @@
#if defined(__GNUC__)
/* bug in WinAVR - not quite IAR compatible */
#define __EEPUT _EEPUT
#define __EEGET _EEGET
#define __EEPUT _EEPUT
#define __EEGET _EEGET
#endif
int eeprom_bytes_read(
uint16_t eeaddr, /* EEPROM starting memory address (offset of zero) */
uint8_t * buf, /* data to store */
int len) /* number of bytes of data to read */
{
int count = 0; /* return value */
uint16_t eeaddr, /* EEPROM starting memory address (offset of zero) */
uint8_t * buf, /* data to store */
int len)
{ /* number of bytes of data to read */
int count = 0; /* return value */
while (len) {
__EEGET(buf[count], eeaddr);
@@ -53,10 +53,10 @@ int eeprom_bytes_read(
}
int eeprom_bytes_write(
uint16_t eeaddr, /* EEPROM starting memory address */
uint8_t * buf, /* data to send */
int len) /* number of bytes of data */
{
uint16_t eeaddr, /* EEPROM starting memory address */
uint8_t * buf, /* data to send */
int len)
{ /* number of bytes of data */
int count = 0;
while (len) {
+8 -8
View File
@@ -31,14 +31,14 @@
extern "C" {
#endif /* __cplusplus */
int eeprom_bytes_read(
uint16_t ee_address, /* EEPROM starting memory address */
uint8_t * buffer, /* data to store */
int nbytes); /* number of bytes of data to read */
int eeprom_bytes_write(
uint16_t ee_address, /* EEPROM starting memory address */
uint8_t * buffer, /* data to send */
int nbytes); /* number of bytes of data */
int eeprom_bytes_read(
uint16_t ee_address, /* EEPROM starting memory address */
uint8_t * buffer, /* data to store */
int nbytes); /* number of bytes of data to read */
int eeprom_bytes_write(
uint16_t ee_address, /* EEPROM starting memory address */
uint8_t * buffer, /* data to send */
int nbytes); /* number of bytes of data */
#ifdef __cplusplus
}
+1 -1
View File
@@ -103,7 +103,7 @@ void handler_reinitialize_device(
ERROR_CLASS_SERVICES, ERROR_CODE_PASSWORD_FAILURE);
}
}
RD_ABORT:
RD_ABORT:
pdu_len += len;
bytes_sent =
datalink_send_pdu(src, &npdu_data, &Handler_Transmit_Buffer[0],
+6 -6
View File
@@ -35,19 +35,19 @@
#endif
#if defined(__GNUC__)
#if !defined(__AVR_ATmega644P__)
#error Firmware is configured for ATmega644P only (-mmcu=atmega644p)
#endif
#if !defined(__AVR_ATmega644P__)
#error Firmware is configured for ATmega644P only (-mmcu=atmega644p)
#endif
/* GCC specific configuration */
#include <avr/wdt.h>
#include <avr/wdt.h>
#endif
#include "iar2gcc.h"
#include "bits.h"
/* SEEPROM is 24LC128 */
//#define SEEPROM_PAGE_SIZE 128
//#define SEEPROM_WORD_ADDRESS_16BIT 1
/*#define SEEPROM_PAGE_SIZE 128 */
/*#define SEEPROM_WORD_ADDRESS_16BIT 1 */
/* SEEPROM is 24C16 */
#define SEEPROM_PAGE_SIZE 16
#define SEEPROM_WORD_ADDRESS_16BIT 0
+10 -10
View File
@@ -224,16 +224,16 @@ typedef struct {
/* watchdog */
#if defined(__ICCAVR__)
#include <intrinsics.h>
#define watchdog_reset __watchdog_reset
#define WDTO_15MS 0
#define WDTO_30MS 1
#define WDTO_60MS 2
#define WDTO_120MS 3
#define WDTO_250MS 4
#define WDTO_500MS 5
#define WDTO_1S 6
#define WDTO_2S 7
#include <intrinsics.h>
#define watchdog_reset __watchdog_reset
#define WDTO_15MS 0
#define WDTO_30MS 1
#define WDTO_60MS 2
#define WDTO_120MS 3
#define WDTO_250MS 4
#define WDTO_500MS 5
#define WDTO_1S 6
#define WDTO_2S 7
#endif
#endif
+2 -2
View File
@@ -30,10 +30,10 @@
extern "C" {
#endif /* __cplusplus */
void init(void);
void init(
void);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif
+5 -8
View File
@@ -42,21 +42,18 @@ void input_task(
}
}
uint8_t input_address(void)
uint8_t input_address(
void)
{
return Address_Switch;
}
void input_init(void)
void input_init(
void)
{
/* configure the port pins */
BITMASK_CLEAR(DDRA,
_BV(DDA0) |
_BV(DDA1) |
_BV(DDA2) |
_BV(DDA3) |
_BV(DDA4) |
_BV(DDA5) |
_BV(DDA0) | _BV(DDA1) | _BV(DDA2) | _BV(DDA3) | _BV(DDA4) | _BV(DDA5) |
_BV(DDA6)
);
}
+6 -4
View File
@@ -30,12 +30,14 @@
extern "C" {
#endif /* __cplusplus */
void input_init(void);
void input_task(void);
uint8_t input_address(void);
void input_init(
void);
void input_task(
void);
uint8_t input_address(
void);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif
+19 -19
View File
@@ -36,7 +36,8 @@ static uint32_t Off_Delay_Milliseconds_4;
* Returns: none
* Notes: none
*************************************************************************/
void led_on(uint8_t index)
void led_on(
uint8_t index)
{
switch (index) {
case LED_1:
@@ -61,7 +62,8 @@ void led_on(uint8_t index)
* Returns: none
* Notes: none
*************************************************************************/
void led_off(uint8_t index)
void led_off(
uint8_t index)
{
switch (index) {
case LED_1:
@@ -86,7 +88,8 @@ void led_off(uint8_t index)
* Returns: true if on, false if off.
* Notes: none
*************************************************************************/
bool led_state(uint8_t index)
bool led_state(
uint8_t index)
{
switch (index) {
case LED_1:
@@ -113,7 +116,8 @@ bool led_state(uint8_t index)
* Returns: none
* Notes: none
*************************************************************************/
void led_toggle(uint8_t index)
void led_toggle(
uint8_t index)
{
if (led_state(index)) {
led_off(index);
@@ -127,7 +131,9 @@ void led_toggle(uint8_t index)
* Returns: none
* Notes: none
*************************************************************************/
void led_off_delay(uint8_t index, uint32_t delay_ms)
void led_off_delay(
uint8_t index,
uint32_t delay_ms)
{
switch (index) {
case LED_1:
@@ -156,36 +162,29 @@ void led_off_delay(uint8_t index, uint32_t delay_ms)
* Returns: none
* Notes: none
*************************************************************************/
void led_task(void)
void led_task(
void)
{
if (Off_Delay_Milliseconds_1) {
if (timer_elapsed_milliseconds(
TIMER_LED_1,
Off_Delay_Milliseconds_1)) {
if (timer_elapsed_milliseconds(TIMER_LED_1, Off_Delay_Milliseconds_1)) {
Off_Delay_Milliseconds_1 = 0;
led_off(LED_1);
}
}
if (Off_Delay_Milliseconds_2) {
if (timer_elapsed_milliseconds(
TIMER_LED_2,
Off_Delay_Milliseconds_2)) {
if (timer_elapsed_milliseconds(TIMER_LED_2, Off_Delay_Milliseconds_2)) {
Off_Delay_Milliseconds_2 = 0;
led_off(LED_2);
}
}
if (Off_Delay_Milliseconds_3) {
if (timer_elapsed_milliseconds(
TIMER_LED_3,
Off_Delay_Milliseconds_3)) {
if (timer_elapsed_milliseconds(TIMER_LED_3, Off_Delay_Milliseconds_3)) {
Off_Delay_Milliseconds_3 = 0;
led_off(LED_3);
}
}
if (Off_Delay_Milliseconds_4) {
if (timer_elapsed_milliseconds(
TIMER_LED_4,
Off_Delay_Milliseconds_4)) {
if (timer_elapsed_milliseconds(TIMER_LED_4, Off_Delay_Milliseconds_4)) {
Off_Delay_Milliseconds_4 = 0;
led_off(LED_4);
}
@@ -197,7 +196,8 @@ void led_task(void)
* Returns: none
* Notes: none
*************************************************************************/
void led_init(void)
void led_init(
void)
{
/* configure the port pins as outputs */
BIT_SET(DDRC, DDC7);
+15 -8
View File
@@ -37,16 +37,23 @@
extern "C" {
#endif /* __cplusplus */
void led_on(uint8_t index);
void led_off(uint8_t index);
void led_off_delay(uint8_t index, uint32_t delay_ms);
void led_toggle(uint8_t index);
bool led_state(uint8_t index);
void led_task(void);
void led_init(void);
void led_on(
uint8_t index);
void led_off(
uint8_t index);
void led_off_delay(
uint8_t index,
uint32_t delay_ms);
void led_toggle(
uint8_t index);
bool led_state(
uint8_t index);
void led_task(
void);
void led_init(
void);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif
+38 -43
View File
@@ -57,67 +57,59 @@ static uint8_t MSTP_MAC_Address;
#if defined(__GNUC__) && (__GNUC__ > 4)
/* AVR fuse settings */
FUSES =
{
FUSES = {
/* External Ceramic Resonator - configuration */
/* Full Swing Crystal Oscillator Clock Selection */
/* Ceramic resonator, slowly rising power 1K CK 14CK + 65 ms */
/* note: fuses are enabled by clearing the bit, so
any fuses listed below are cleared fuses. */
.low = (FUSE_CKSEL3 &
FUSE_SUT0 &
FUSE_SUT1),
.low = (FUSE_CKSEL3 & FUSE_SUT0 & FUSE_SUT1),
/* BOOTSZ configuration:
BOOTSZ1 BOOTSZ0 Boot Size
------- ------- ---------
1 1 512
1 0 1024
0 1 2048
0 0 4096
*/
/* note: fuses are enabled by clearing the bit, so
any fuses listed below are cleared fuses. */
.high =
(FUSE_BOOTSZ1 & FUSE_BOOTRST & FUSE_EESAVE & FUSE_SPIEN & FUSE_JTAGEN),
/* Brown-out detection VCC=2.7V */
/* BODLEVEL configuration
BODLEVEL2 BODLEVEL1 BODLEVEL0 Voltage
--------- --------- --------- --------
1 1 1 disabled
1 1 0 1.8V
1 0 1 2.7V
1 0 0 4.3V
*/
/* note: fuses are enabled by clearing the bit, so
any fuses listed below are cleared fuses. */
.extended = (FUSE_BODLEVEL1 & FUSE_BODLEVEL0),};
/* BOOTSZ configuration:
BOOTSZ1 BOOTSZ0 Boot Size
------- ------- ---------
1 1 512
1 0 1024
0 1 2048
0 0 4096
*/
/* note: fuses are enabled by clearing the bit, so
any fuses listed below are cleared fuses. */
.high = (
FUSE_BOOTSZ1 &
FUSE_BOOTRST &
FUSE_EESAVE &
FUSE_SPIEN &
FUSE_JTAGEN),
/* Brown-out detection VCC=2.7V */
/* BODLEVEL configuration
BODLEVEL2 BODLEVEL1 BODLEVEL0 Voltage
--------- --------- --------- --------
1 1 1 disabled
1 1 0 1.8V
1 0 1 2.7V
1 0 0 4.3V
*/
/* note: fuses are enabled by clearing the bit, so
any fuses listed below are cleared fuses. */
.extended = (FUSE_BODLEVEL1 & FUSE_BODLEVEL0),
};
/* AVR lock bits - unlocked */
LOCKBITS = LOCKBITS_DEFAULT;
#endif
bool seeprom_version_test(void)
bool seeprom_version_test(
void)
{
uint16_t version = 0;
uint16_t id = 0;
bool status = false;
seeprom_bytes_read(NV_SEEPROM_TYPE_0, (uint8_t *)&id, 2);
seeprom_bytes_read(NV_SEEPROM_VERSION_0, (uint8_t *)&version, 2);
seeprom_bytes_read(NV_SEEPROM_TYPE_0, (uint8_t *) & id, 2);
seeprom_bytes_read(NV_SEEPROM_VERSION_0, (uint8_t *) & version, 2);
if ((id == SEEPROM_ID) && (version == SEEPROM_VERSION)) {
status = true;
} else {
version = SEEPROM_VERSION;
id = SEEPROM_ID;
seeprom_bytes_write(NV_SEEPROM_TYPE_0, (uint8_t *)&id, 2);
seeprom_bytes_write(NV_SEEPROM_VERSION_0, (uint8_t *)&version, 2);
seeprom_bytes_write(NV_SEEPROM_TYPE_0, (uint8_t *) & id, 2);
seeprom_bytes_write(NV_SEEPROM_VERSION_0, (uint8_t *) & version, 2);
}
return status;
@@ -157,7 +149,8 @@ static void bacnet_init(
}
static uint8_t PDUBuffer[MAX_MPDU];
static void bacnet_task(void)
static void bacnet_task(
void)
{
uint8_t mstp_mac_address = 0;
uint16_t pdu_len = 0;
@@ -178,13 +171,15 @@ static void bacnet_task(void)
}
}
void idle_init(void)
void idle_init(
void)
{
timer_reset(TIMER_LED_3);
timer_reset(TIMER_LED_4);
}
void idle_task(void)
void idle_task(
void)
{
#if 0
/* blink the leds */
+25 -27
View File
@@ -49,7 +49,8 @@ static uint32_t Baud_Rate = 9600;
static uint8_t Receive_Buffer_Data[128];
static FIFO_BUFFER Receive_Buffer;
static void rs485_rts_init(void)
static void rs485_rts_init(
void)
{
/* configure the port pin as an output */
BIT_SET(DDRD, DDD4);
@@ -66,7 +67,8 @@ void rs485_rts_enable(
}
}
static void rs485_receiver_enable(void)
static void rs485_receiver_enable(
void)
{
UCSR0B = _BV(TXEN0) | _BV(RXEN0) | _BV(RXCIE0);
}
@@ -92,7 +94,7 @@ ISR(USART0_RX_vect)
if (BIT_CHECK(UCSR0A, RXC0)) {
/* data is available */
data_byte = UDR0;
(void)FIFO_Put(&Receive_Buffer, data_byte);
(void) FIFO_Put(&Receive_Buffer, data_byte);
timer_reset(TIMER_SILENCE);
}
}
@@ -100,7 +102,7 @@ ISR(USART0_RX_vect)
bool rs485_byte_available(
uint8_t * data_register)
{
bool data_available = false; /* return value */
bool data_available = false; /* return value */
if (!FIFO_Empty(&Receive_Buffer)) {
led_on(LED_1);
@@ -112,15 +114,16 @@ bool rs485_byte_available(
return data_available;
}
bool rs485_receive_error(void)
bool rs485_receive_error(
void)
{
return false;
}
void rs485_bytes_send(
uint8_t * buffer, /* data to send */
uint16_t nbytes) /* number of bytes of data */
{
uint8_t * buffer, /* data to send */
uint16_t nbytes)
{ /* number of bytes of data */
led_on(LED_2);
while (!BIT_CHECK(UCSR0A, UDRE0)) {
/* do nothing - wait until Tx buffer is empty */
@@ -153,7 +156,8 @@ uint32_t rs485_baud_rate(
return Baud_Rate;
}
static void rs485_baud_rate_configure(void)
static void rs485_baud_rate_configure(
void)
{
/* 2x speed mode */
BIT_SET(UCSR0A, U2X0);
@@ -177,11 +181,8 @@ bool rs485_baud_rate_set(
Baud_Rate = baud;
rs485_baud_rate_configure();
/* store the baud rate */
baud_k = baud/1000;
eeprom_bytes_write(
NV_EEPROM_BAUD_K,
&baud_k,
1);
baud_k = baud / 1000;
eeprom_bytes_write(NV_EEPROM_BAUD_K, &baud_k, 1);
break;
default:
valid = false;
@@ -191,7 +192,8 @@ bool rs485_baud_rate_set(
return valid;
}
static void rs485_usart_init(void)
static void rs485_usart_init(
void)
{
/* enable Transmit and Receive */
UCSR0B = _BV(TXEN0) | _BV(RXEN0);
@@ -207,14 +209,12 @@ static void rs485_usart_init(void)
BIT_CLEAR(PRR, PRUSART0);
}
static void rs485_init_nvdata(void)
static void rs485_init_nvdata(
void)
{
uint8_t baud_k = 9; /* from EEPROM value */
eeprom_bytes_read(
NV_EEPROM_BAUD_K,
&baud_k,
1);
eeprom_bytes_read(NV_EEPROM_BAUD_K, &baud_k, 1);
switch (baud_k) {
case 9:
Baud_Rate = 9600;
@@ -237,20 +237,18 @@ static void rs485_init_nvdata(void)
default:
/* not configured yet */
Baud_Rate = 38400;
baud_k = 38400/1000;
eeprom_bytes_write(
NV_EEPROM_BAUD_K,
&baud_k,
1);
baud_k = 38400 / 1000;
eeprom_bytes_write(NV_EEPROM_BAUD_K, &baud_k, 1);
break;
}
rs485_baud_rate_configure();
}
void rs485_init(void)
void rs485_init(
void)
{
FIFO_Init(&Receive_Buffer, &Receive_Buffer_Data[0],
(unsigned)sizeof(Receive_Buffer_Data));
(unsigned) sizeof(Receive_Buffer_Data));
rs485_rts_init();
rs485_usart_init();
rs485_init_nvdata();
+8 -5
View File
@@ -42,16 +42,19 @@
extern "C" {
#endif /* __cplusplus */
void rs485_init(void);
void rs485_init(
void);
void rs485_rts_enable(
bool enable);
bool rs485_byte_available(
uint8_t * data_register);
bool rs485_receive_error(void);
bool rs485_receive_error(
void);
void rs485_bytes_send(
uint8_t * buffer, /* data to send */
uint16_t nbytes); /* number of bytes of data */
uint32_t rs485_baud_rate(void);
uint8_t * buffer, /* data to send */
uint16_t nbytes); /* number of bytes of data */
uint32_t rs485_baud_rate(
void);
bool rs485_baud_rate_set(
uint32_t baud);
+42 -40
View File
@@ -100,13 +100,13 @@
* NOTES: none
**************************************************************************/
int seeprom_bytes_read(
uint16_t eeaddr, /* SEEPROM starting memory address */
uint8_t * buf, /* data to store */
int len) /* number of bytes of data to read */
{
uint16_t eeaddr, /* SEEPROM starting memory address */
uint8_t * buf, /* data to store */
int len)
{ /* number of bytes of data to read */
uint8_t sla, twcr, n = 0;
int rv = 0;
uint8_t twst; /* status - only valid while TWINT is set. */
uint8_t twst; /* status - only valid while TWINT is set. */
#if SEEPROM_WORD_ADDRESS_16BIT
/* 16bit address devices need only TWI Device Address */
@@ -116,19 +116,19 @@ int seeprom_bytes_read(
sla = SEEPROM_I2C_ADDRESS | (((eeaddr >> 8) & 0x07) << 1);
#endif
/* Note [8] First cycle: master transmitter mode */
restart:
restart:
if (n++ >= MAX_ITER) {
return -1;
}
begin:
begin:
/* send start condition */
TWCR = _BV(TWINT) | _BV(TWSTA) | _BV(TWEN);
/* wait for transmission */
while ((TWCR & _BV(TWINT)) == 0) ;
while ((TWCR & _BV(TWINT)) == 0);
twst = TWSR & TW_STATUS_MASK;
switch (twst) {
case TW_REP_START:
/* OK, but should not happen */
/* OK, but should not happen */
case TW_START:
break;
case TW_MT_ARB_LOST:
@@ -146,7 +146,7 @@ begin:
/* clear interrupt to start transmission */
TWCR = _BV(TWINT) | _BV(TWEN);
/* wait for transmission */
while ((TWCR & _BV(TWINT)) == 0) ;
while ((TWCR & _BV(TWINT)) == 0);
twst = TWSR & TW_STATUS_MASK;
switch (twst) {
case TW_MT_SLA_ACK:
@@ -164,11 +164,11 @@ begin:
}
#if SEEPROM_WORD_ADDRESS_16BIT
/* 16 bit word address device, send high 8 bits of addr */
TWDR = (eeaddr>>8);
TWDR = (eeaddr >> 8);
/* clear interrupt to start transmission */
TWCR = _BV(TWINT) | _BV(TWEN);
/* wait for transmission */
while ((TWCR & _BV(TWINT)) == 0) ;
while ((TWCR & _BV(TWINT)) == 0);
twst = TWSR & TW_STATUS_MASK;
switch (twst) {
case TW_MT_DATA_ACK:
@@ -187,7 +187,7 @@ begin:
/* clear interrupt to start transmission */
TWCR = _BV(TWINT) | _BV(TWEN);
/* wait for transmission */
while ((TWCR & _BV(TWINT)) == 0) ;
while ((TWCR & _BV(TWINT)) == 0);
twst = TWSR & TW_STATUS_MASK;
switch (twst) {
case TW_MT_DATA_ACK:
@@ -205,11 +205,11 @@ begin:
/* send repeated start condition */
TWCR = _BV(TWINT) | _BV(TWSTA) | _BV(TWEN);
/* wait for transmission */
while ((TWCR & _BV(TWINT)) == 0) ;
while ((TWCR & _BV(TWINT)) == 0);
twst = TWSR & TW_STATUS_MASK;
switch (twst) {
case TW_START:
/* OK, but should not happen */
/* OK, but should not happen */
case TW_REP_START:
break;
case TW_MT_ARB_LOST:
@@ -223,7 +223,7 @@ begin:
/* clear interrupt to start transmission */
TWCR = _BV(TWINT) | _BV(TWEN);
/* wait for transmission */
while ((TWCR & _BV(TWINT)) == 0) ;
while ((TWCR & _BV(TWINT)) == 0);
twst = TWSR & TW_STATUS_MASK;
switch (twst) {
case TW_MR_SLA_ACK:
@@ -237,7 +237,7 @@ begin:
}
/* Note [13] */
twcr = _BV(TWINT) | _BV(TWEN) | _BV(TWEA);
for (;len > 0; len--) {
for (; len > 0; len--) {
if (len == 1) {
/* send NAK this time */
twcr = _BV(TWINT) | _BV(TWEN);
@@ -245,7 +245,7 @@ begin:
/* clear int to start transmission */
TWCR = twcr;
/* wait for transmission */
while ((TWCR & _BV(TWINT)) == 0) ;
while ((TWCR & _BV(TWINT)) == 0);
twst = TWSR & TW_STATUS_MASK;
switch (twst) {
case TW_MR_DATA_NACK:
@@ -253,7 +253,7 @@ begin:
len = 0;
/* FALLTHROUGH */
case TW_MR_DATA_ACK:
*buf= TWDR;
*buf = TWDR;
buf++;
rv++;
break;
@@ -261,12 +261,12 @@ begin:
goto error;
}
}
quit:
quit:
/* Note [14] */
/* send stop condition */
TWCR = _BV(TWINT) | _BV(TWSTO) | _BV(TWEN);
return rv;
error:
error:
rv = -1;
goto quit;
}
@@ -277,14 +277,14 @@ error:
* NOTES: none
**************************************************************************/
int seeprom_bytes_write(
uint16_t eeaddr, /* SEEPROM starting memory address */
uint8_t * buf, /* data to send */
int len) /* number of bytes of data */
{
uint16_t eeaddr, /* SEEPROM starting memory address */
uint8_t * buf, /* data to send */
int len)
{ /* number of bytes of data */
uint8_t sla, n = 0;
int rv = 0;
uint16_t endaddr;
uint8_t twst; /* status - only valid while TWINT is set. */
uint8_t twst; /* status - only valid while TWINT is set. */
if ((eeaddr + len) < (eeaddr | (SEEPROM_PAGE_SIZE - 1))) {
endaddr = eeaddr + len;
@@ -299,14 +299,14 @@ int seeprom_bytes_write(
/* patch high bits of EEPROM address into SLA */
sla = SEEPROM_I2C_ADDRESS | (((eeaddr >> 8) & 0x07) << 1);
#endif
restart:
restart:
if (n++ >= MAX_ITER) {
return -1;
}
begin:
begin:
/* Note [15] */
TWCR = _BV(TWINT) | _BV(TWSTA) | _BV(TWEN); /* send start condition */
while ((TWCR & _BV(TWINT)) == 0) ; /* wait for transmission */
while ((TWCR & _BV(TWINT)) == 0); /* wait for transmission */
twst = TWSR & TW_STATUS_MASK;
switch (twst) {
case TW_REP_START:
@@ -325,7 +325,7 @@ begin:
/* clear interrupt to start transmission */
TWCR = _BV(TWINT) | _BV(TWEN);
/* wait for transmission */
while ((TWCR & _BV(TWINT)) == 0) ;
while ((TWCR & _BV(TWINT)) == 0);
twst = TWSR & TW_STATUS_MASK;
switch (twst) {
case TW_MT_SLA_ACK:
@@ -342,11 +342,11 @@ begin:
}
#if SEEPROM_WORD_ADDRESS_16BIT
/* 16 bit word address device, send high 8 bits of addr */
TWDR = (eeaddr>>8);
TWDR = (eeaddr >> 8);
/* clear interrupt to start transmission */
TWCR = _BV(TWINT) | _BV(TWEN);
/* wait for transmission */
while ((TWCR & _BV(TWINT)) == 0) ;
while ((TWCR & _BV(TWINT)) == 0);
twst = TWSR & TW_STATUS_MASK;
switch (twst) {
case TW_MT_DATA_ACK:
@@ -365,7 +365,8 @@ begin:
/* clear interrupt to start transmission */
TWCR = _BV(TWINT) | _BV(TWEN);
/* wait for transmission */
while ((TWCR & _BV(TWINT)) == 0) {};
while ((TWCR & _BV(TWINT)) == 0) {
};
twst = TWSR & TW_STATUS_MASK;
switch (twst) {
case TW_MT_DATA_ACK:
@@ -383,7 +384,7 @@ begin:
/* start transmission */
TWCR = _BV(TWINT) | _BV(TWEN);
/* wait for transmission */
while ((TWCR & _BV(TWINT)) == 0) ;
while ((TWCR & _BV(TWINT)) == 0);
twst = TWSR & TW_STATUS_MASK;
switch (twst) {
case TW_MT_DATA_NACK:
@@ -396,13 +397,13 @@ begin:
goto error;
}
}
quit:
quit:
/* send stop condition */
TWCR = _BV(TWINT) | _BV(TWSTO) | _BV(TWEN);
return rv;
error:
error:
rv = -1;
goto quit;
}
@@ -412,13 +413,14 @@ error:
* Returns: none
* Notes: none
**************************************************************************/
void seeprom_init(void)
void seeprom_init(
void)
{
/* bit rate prescaler */
TWSR=0;
TWCR=_BV(TWEN) | _BV(TWEA);
TWSR = 0;
TWCR = _BV(TWEN) | _BV(TWEA);
/* bit rate */
TWBR = (F_CPU / SEEPROM_I2C_CLOCK - 16) / 2;
/* my address */
TWAR=0;
TWAR = 0;
}
+10 -10
View File
@@ -31,16 +31,16 @@
extern "C" {
#endif /* __cplusplus */
int seeprom_bytes_read(
uint16_t ee_address, /* SEEPROM starting memory address */
uint8_t * buffer, /* data to store */
int nbytes); /* number of bytes of data to read */
int seeprom_bytes_write(
uint16_t ee_address, /* SEEPROM starting memory address */
uint8_t * buffer, /* data to send */
int nbytes); /* number of bytes of data */
void seeprom_init(
void);
int seeprom_bytes_read(
uint16_t ee_address, /* SEEPROM starting memory address */
uint8_t * buffer, /* data to store */
int nbytes); /* number of bytes of data to read */
int seeprom_bytes_write(
uint16_t ee_address, /* SEEPROM starting memory address */
uint8_t * buffer, /* data to send */
int nbytes); /* number of bytes of data */
void seeprom_init(
void);
#ifdef __cplusplus
}
+15 -11
View File
@@ -35,7 +35,8 @@ static uint32_t Baud_Rate = 9600;
static uint8_t Receive_Buffer_Data[128];
static FIFO_BUFFER Receive_Buffer;
static void serial_receiver_enable(void)
static void serial_receiver_enable(
void)
{
UCSR0B = _BV(TXEN0) | _BV(RXEN0) | _BV(RXCIE0);
}
@@ -47,14 +48,14 @@ ISR(USART1_RX_vect)
if (BIT_CHECK(UCSR1A, RXC1)) {
/* data is available */
data_byte = UDR1;
(void)FIFO_Put(&Receive_Buffer, data_byte);
(void) FIFO_Put(&Receive_Buffer, data_byte);
}
}
bool serial_byte_get(
uint8_t * data_register)
{
bool data_available = false; /* return value */
bool data_available = false; /* return value */
if (!FIFO_Empty(&Receive_Buffer)) {
*data_register = FIFO_Get(&Receive_Buffer);
@@ -67,7 +68,7 @@ bool serial_byte_get(
bool serial_byte_peek(
uint8_t * data_register)
{
bool data_available = false; /* return value */
bool data_available = false; /* return value */
if (!FIFO_Empty(&Receive_Buffer)) {
*data_register = FIFO_Peek(&Receive_Buffer);
@@ -78,9 +79,9 @@ bool serial_byte_peek(
}
void serial_bytes_send(
uint8_t * buffer, /* data to send */
uint16_t nbytes) /* number of bytes of data */
{
uint8_t * buffer, /* data to send */
uint16_t nbytes)
{ /* number of bytes of data */
while (!BIT_CHECK(UCSR1A, UDRE1)) {
/* do nothing - wait until Tx buffer is empty */
}
@@ -104,7 +105,8 @@ void serial_bytes_send(
return;
}
void serial_byte_send(uint8_t ch)
void serial_byte_send(
uint8_t ch)
{
uint8_t buffer[1];
@@ -147,7 +149,8 @@ bool serial_baud_rate_set(
return valid;
}
static void serial_usart_init(void)
static void serial_usart_init(
void)
{
/* enable Transmit and Receive */
UCSR1B = _BV(TXEN1) | _BV(RXEN1);
@@ -163,10 +166,11 @@ static void serial_usart_init(void)
BIT_CLEAR(PRR, PRUSART1);
}
void serial_init(void)
void serial_init(
void)
{
FIFO_Init(&Receive_Buffer, &Receive_Buffer_Data[0],
(unsigned)sizeof(Receive_Buffer_Data));
(unsigned) sizeof(Receive_Buffer_Data));
serial_usart_init();
serial_baud_rate_set(Baud_Rate);
serial_receiver_enable();
+15 -13
View File
@@ -30,24 +30,26 @@
extern "C" {
#endif /* __cplusplus */
bool serial_byte_get(
uint8_t * data_register);
bool serial_byte_peek(
uint8_t * data_register);
bool serial_byte_get(
uint8_t * data_register);
bool serial_byte_peek(
uint8_t * data_register);
void serial_bytes_send(
uint8_t * buffer, /* data to send */
uint16_t nbytes); /* number of bytes of data */
void serial_byte_send(uint8_t ch);
void serial_bytes_send(
uint8_t * buffer, /* data to send */
uint16_t nbytes); /* number of bytes of data */
void serial_byte_send(
uint8_t ch);
uint32_t serial_baud_rate(void);
bool serial_baud_rate_set(
uint32_t baud);
uint32_t serial_baud_rate(
void);
bool serial_baud_rate_set(
uint32_t baud);
void serial_init(void);
void serial_init(
void);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif
+6 -3
View File
@@ -51,17 +51,20 @@ void stack_init(
#endif
}
unsigned stack_size(void)
unsigned stack_size(
void)
{
return (&__stack) - (&_end);
}
uint8_t stack_byte(unsigned offset)
uint8_t stack_byte(
unsigned offset)
{
return *(&_end + offset);
}
unsigned stack_unused(void)
unsigned stack_unused(
void)
{
uint8_t *p = &_end;
unsigned count = 0;
+8 -6
View File
@@ -33,17 +33,19 @@ extern "C" {
#endif /* __cplusplus */
/* C stack checking */
void stack_init(void);
void stack_init(
void);
unsigned stack_size(void);
unsigned stack_size(
void);
uint8_t stack_byte(unsigned offset);
uint8_t stack_byte(
unsigned offset);
unsigned stack_unused(void);
unsigned stack_unused(
void);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif
+10 -9
View File
@@ -48,7 +48,8 @@ static volatile unsigned long Millisecond_Counter[MAX_MILLISECOND_TIMERS];
* Returns: none
* Notes: Global interupts must be enabled
*************************************************************************/
static inline void timer_interrupt_handler(void)
static inline void timer_interrupt_handler(
void)
{
unsigned i; /* loop counter */
@@ -79,8 +80,8 @@ unsigned long timer_milliseconds_set(
unsigned index,
unsigned long value)
{
uint8_t sreg = 0; /* holds interrupts pending */
unsigned long old_value = 0; /* return value */
uint8_t sreg = 0; /* holds interrupts pending */
unsigned long old_value = 0; /* return value */
if (index < MAX_MILLISECOND_TIMERS) {
sreg = SREG;
@@ -101,8 +102,8 @@ unsigned long timer_milliseconds_set(
unsigned long timer_milliseconds(
unsigned index)
{
unsigned long timer_value = 0; /* return value */
uint8_t sreg = 0; /* holds interrupts pending */
unsigned long timer_value = 0; /* return value */
uint8_t sreg = 0; /* holds interrupts pending */
if (index < MAX_MILLISECOND_TIMERS) {
sreg = SREG;
@@ -135,7 +136,7 @@ bool timer_elapsed_seconds(
unsigned index,
unsigned long seconds)
{
return ((timer_milliseconds(index)/1000UL) >= seconds);
return ((timer_milliseconds(index) / 1000UL) >= seconds);
}
/*************************************************************************
@@ -147,7 +148,7 @@ bool timer_elapsed_minutes(
unsigned index,
unsigned long minutes)
{
return ((timer_milliseconds(index)/(1000UL*60UL)) >= minutes);
return ((timer_milliseconds(index) / (1000UL * 60UL)) >= minutes);
}
/*************************************************************************
@@ -158,7 +159,7 @@ bool timer_elapsed_minutes(
unsigned long timer_reset(
unsigned index)
{
return timer_milliseconds_set(index,0);
return timer_milliseconds_set(index, 0);
}
/*************************************************************************
@@ -198,7 +199,7 @@ static void timer2_init(
#elif (TIMER2_PRESCALER==1024)
TCCR2B = _BV(CS22) | _BV(CS21) | _BV(CS20);
#else
#error Timer2 Prescale: Invalid Value
#error Timer2 Prescale: Invalid Value
#endif
/* Clear any TOV Flag set when the timer overflowed */
BIT_CLEAR(TIFR2, TOV2);
+1 -1
View File
@@ -450,7 +450,7 @@ int Device_Encode_Property_APDU(
case PROP_UTC_OFFSET:
/* Note: BACnet Time Zone is offset of local time and UTC,
rather than offset of GMT. It is expressed in minutes */
apdu_len = encode_application_signed(&apdu[0], 5*60 /* EST */ );
apdu_len = encode_application_signed(&apdu[0], 5 * 60 /* EST */ );
break;
case PROP_LOCAL_DATE:
/* FIXME: if you support date */
+4 -10
View File
@@ -98,7 +98,7 @@ void RS485_Set_Interface(
if (ifname) {
if (strncmp("COM", ifname, 3) == 0) {
if (strlen(ifname) > 3) {
sprintf(RS485_Port_Name, "\\\\.\\COM%i", atoi(ifname+3));
sprintf(RS485_Port_Name, "\\\\.\\COM%i", atoi(ifname + 3));
fprintf(stderr, "Adjusted interface name to %s\r\n",
RS485_Port_Name);
}
@@ -119,15 +119,9 @@ static void RS485_Print_Error(
DWORD dwExtSize;
DWORD dwErr;
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
NULL,
GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
(LPTSTR) &lpMsgBuf,
0,
NULL );
MessageBox( NULL, lpMsgBuf, "GetLastError", MB_OK|MB_ICONINFORMATION );
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), /* Default language */
(LPTSTR) & lpMsgBuf, 0, NULL);
MessageBox(NULL, lpMsgBuf, "GetLastError", MB_OK | MB_ICONINFORMATION);
LocalFree(lpMsgBuf);
return;
+5 -10
View File
@@ -809,34 +809,29 @@ bool bacapp_print_value(
if (value->type.Date.day == 255) {
fprintf(stream, "(unspecified), ");
} else {
fprintf(stream, "%u, ",
(unsigned) value->type.Date.day);
fprintf(stream, "%u, ", (unsigned) value->type.Date.day);
}
if (value->type.Date.year == 255) {
fprintf(stream, "(unspecified), ");
} else {
fprintf(stream, "%u",
(unsigned) value->type.Date.year);
fprintf(stream, "%u", (unsigned) value->type.Date.year);
}
break;
case BACNET_APPLICATION_TAG_TIME:
if (value->type.Time.hour == 255) {
fprintf(stream, "**:");
} else {
fprintf(stream, "%02u:",
(unsigned) value->type.Time.hour);
fprintf(stream, "%02u:", (unsigned) value->type.Time.hour);
}
if (value->type.Time.min == 255) {
fprintf(stream, "**:");
} else {
fprintf(stream, "%02u:",
(unsigned) value->type.Time.min);
fprintf(stream, "%02u:", (unsigned) value->type.Time.min);
}
if (value->type.Time.sec == 255) {
fprintf(stream, "**.");
} else {
fprintf(stream, "%02u.",
(unsigned) value->type.Time.sec);
fprintf(stream, "%02u.", (unsigned) value->type.Time.sec);
}
if (value->type.Time.hundredths == 255) {
fprintf(stream, "**");