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