Indented project.

This commit is contained in:
skarg
2011-08-17 02:27:11 +00:00
parent 7e503510c7
commit 3e1cb1847f
125 changed files with 3548 additions and 3353 deletions
+54 -42
View File
@@ -65,7 +65,8 @@ static bool Auto_Mode_Enabled;
* RETURN: true if automode enabled
* NOTES: none
*****************************************************************************/
bool automac_enabled(void)
bool automac_enabled(
void)
{
return Auto_Mode_Enabled;
}
@@ -75,7 +76,8 @@ bool automac_enabled(void)
* RETURN: nothing
* NOTES: none
*****************************************************************************/
void automac_enabled_set(bool status)
void automac_enabled_set(
bool status)
{
Auto_Mode_Enabled = status;
}
@@ -85,7 +87,8 @@ void automac_enabled_set(bool status)
* RETURN: true if full
* NOTES: none
*****************************************************************************/
bool automac_pfm_cycle_complete(void)
bool automac_pfm_cycle_complete(
void)
{
return PFM_Cycle_Complete;
}
@@ -95,13 +98,13 @@ bool automac_pfm_cycle_complete(void)
* RETURN: true if used
* NOTES: none
*****************************************************************************/
static bool automac_address_used(uint8_t mac)
static bool automac_address_used(
uint8_t mac)
{
bool status = false;
if (mac < MAC_SLOTS_MAX) {
if ((Auto_MAC_Data[mac].emitter) ||
(Auto_MAC_Data[mac].reserved) ||
if ((Auto_MAC_Data[mac].emitter) || (Auto_MAC_Data[mac].reserved) ||
(Auto_MAC_Data[mac].token)) {
status = true;
}
@@ -115,13 +118,13 @@ static bool automac_address_used(uint8_t mac)
* RETURN: true if valid
* NOTES: none
*****************************************************************************/
bool automac_free_address_valid(uint8_t mac)
bool automac_free_address_valid(
uint8_t mac)
{
bool status = false;
if (mac < MAC_SLOTS_MAX) {
if ((Auto_MAC_Data[mac].pfm) &&
(!automac_address_used(mac))) {
if ((Auto_MAC_Data[mac].pfm) && (!automac_address_used(mac))) {
status = true;
}
}
@@ -134,11 +137,12 @@ bool automac_free_address_valid(uint8_t mac)
* RETURN: Next_Station, or 255 if there are no next stations
* NOTES: none
*****************************************************************************/
uint8_t automac_next_station(uint8_t mac)
uint8_t automac_next_station(
uint8_t mac)
{
uint8_t i = 0; /* loop counter */
uint8_t i = 0; /* loop counter */
uint8_t next_station = 255; /* return value */
uint8_t test_station = 0; /* station number to test for token */
uint8_t test_station = 0; /* station number to test for token */
test_station = (mac + 1) % 128;
for (i = 0; i < MAC_SLOTS_MAX; i++) {
@@ -157,7 +161,8 @@ uint8_t automac_next_station(uint8_t mac)
* RETURN: Number of free MAC addresses
* NOTES: none
*****************************************************************************/
uint8_t automac_free_address_count(void)
uint8_t automac_free_address_count(
void)
{
uint8_t i = 0;
uint8_t slots = 0;
@@ -176,7 +181,8 @@ uint8_t automac_free_address_count(void)
* RETURN: Number of free MAC addresses
* NOTES: none
*****************************************************************************/
uint8_t automac_free_address_mac(uint8_t count)
uint8_t automac_free_address_mac(
uint8_t count)
{
uint8_t i = 0;
uint8_t slots = 0;
@@ -200,7 +206,8 @@ uint8_t automac_free_address_mac(uint8_t count)
* RETURN: free MAC addresses
* NOTES: none
*****************************************************************************/
uint8_t automac_free_address_random(void)
uint8_t automac_free_address_random(
void)
{
uint8_t count = 0;
uint8_t random_count = 0;
@@ -208,7 +215,7 @@ uint8_t automac_free_address_random(void)
count = automac_free_address_count();
if (count) {
random_count = rand()%count;
random_count = rand() % count;
mac = automac_free_address_mac(random_count);
}
@@ -220,7 +227,8 @@ uint8_t automac_free_address_random(void)
* RETURN: MAC addresses
* NOTES: none
*****************************************************************************/
uint8_t automac_address(void)
uint8_t automac_address(
void)
{
return My_MAC_Address;
}
@@ -230,7 +238,8 @@ uint8_t automac_address(void)
* RETURN: MAC addresses
* NOTES: none
*****************************************************************************/
void automac_address_set(uint8_t mac)
void automac_address_set(
uint8_t mac)
{
My_MAC_Address = mac;
}
@@ -240,7 +249,8 @@ void automac_address_set(uint8_t mac)
* RETURN: MAC addresses
* NOTES: none
*****************************************************************************/
uint16_t automac_time_slot(void)
uint16_t automac_time_slot(
void)
{
return My_Time_Slot;
}
@@ -250,12 +260,14 @@ uint16_t automac_time_slot(void)
* RETURN: MAC addresses
* NOTES: none
*****************************************************************************/
void automac_address_init(void)
void automac_address_init(
void)
{
My_MAC_Address = MAC_SLOTS_OFFSET + rand()%(MAC_SLOTS_MAX-MAC_SLOTS_OFFSET);
My_MAC_Address =
MAC_SLOTS_OFFSET + rand() % (MAC_SLOTS_MAX - MAC_SLOTS_OFFSET);
/* at least as long as a dropped token - worst case */
My_Time_Slot = Tno_token + (MAC_SLOTS_MAX * Tslot);
My_Time_Slot += (uint16_t)My_MAC_Address * Tslot;
My_Time_Slot += (uint16_t) My_MAC_Address *Tslot;
}
/****************************************************************************
@@ -263,7 +275,8 @@ void automac_address_init(void)
* RETURN: nothing
* NOTES: none
*****************************************************************************/
void automac_pfm_set(uint8_t mac)
void automac_pfm_set(
uint8_t mac)
{
if (mac < MAC_SLOTS_MAX) {
if (Auto_MAC_Data[mac].pfm) {
@@ -281,7 +294,8 @@ void automac_pfm_set(uint8_t mac)
* RETURN: nothing
* NOTES: none
*****************************************************************************/
void automac_token_set(uint8_t mac)
void automac_token_set(
uint8_t mac)
{
if (mac < MAC_SLOTS_MAX) {
Auto_MAC_Data[mac].token = true;
@@ -293,7 +307,8 @@ void automac_token_set(uint8_t mac)
* RETURN: nothing
* NOTES: none
*****************************************************************************/
void automac_emitter_set(uint8_t mac)
void automac_emitter_set(
uint8_t mac)
{
if (mac < MAC_SLOTS_MAX) {
Auto_MAC_Data[mac].emitter = true;
@@ -305,7 +320,8 @@ void automac_emitter_set(uint8_t mac)
* RETURN: nothing
* NOTES: none
*****************************************************************************/
void automac_init(void)
void automac_init(
void)
{
uint8_t i = 0;
@@ -359,34 +375,31 @@ void test_Auto_MAC(
srand(42);
mac = automac_free_address_random();
ct_test(pTest, mac == 255);
automac_pfm_set(MAC_SLOTS_OFFSET+1);
automac_pfm_set(MAC_SLOTS_OFFSET + 1);
mac = automac_free_address_mac(0);
ct_test(pTest, mac == (MAC_SLOTS_OFFSET+1));
ct_test(pTest, mac == (MAC_SLOTS_OFFSET + 1));
mac = automac_free_address_random();
ct_test(pTest, mac == (MAC_SLOTS_OFFSET+1));
ct_test(pTest, mac == (MAC_SLOTS_OFFSET + 1));
/* test 2 free addresses */
automac_pfm_set(MAC_SLOTS_OFFSET+2);
automac_pfm_set(MAC_SLOTS_OFFSET + 2);
mac = automac_free_address_mac(0);
ct_test(pTest, mac == (MAC_SLOTS_OFFSET+1));
ct_test(pTest, mac == (MAC_SLOTS_OFFSET + 1));
mac = automac_free_address_mac(1);
ct_test(pTest, mac == (MAC_SLOTS_OFFSET+2));
ct_test(pTest, mac == (MAC_SLOTS_OFFSET + 2));
mac = automac_free_address_random();
ct_test(pTest,
(mac == (MAC_SLOTS_OFFSET+1)) ||
(mac == (MAC_SLOTS_OFFSET+2)));
ct_test(pTest, (mac == (MAC_SLOTS_OFFSET + 1)) ||
(mac == (MAC_SLOTS_OFFSET + 2)));
/* test 3 free addresses */
automac_pfm_set(126);
mac = automac_free_address_mac(0);
ct_test(pTest, mac == (MAC_SLOTS_OFFSET+1));
ct_test(pTest, mac == (MAC_SLOTS_OFFSET + 1));
mac = automac_free_address_mac(1);
ct_test(pTest, mac == (MAC_SLOTS_OFFSET+2));
ct_test(pTest, mac == (MAC_SLOTS_OFFSET + 2));
mac = automac_free_address_mac(2);
ct_test(pTest, mac == 126);
mac = automac_free_address_random();
ct_test(pTest,
(mac == (MAC_SLOTS_OFFSET+1))||
(mac == (MAC_SLOTS_OFFSET+2))||
(mac == 126));
ct_test(pTest, (mac == (MAC_SLOTS_OFFSET + 1)) ||
(mac == (MAC_SLOTS_OFFSET + 2)) || (mac == 126));
/* test the stored address */
mac = automac_address();
ct_test(pTest, mac < MAC_SLOTS_MAX);
@@ -423,4 +436,3 @@ int main(
}
#endif
#endif
+32 -17
View File
@@ -34,26 +34,41 @@
extern "C" {
#endif /* __cplusplus */
void automac_init(void);
void automac_init(
void);
bool automac_free_address_valid(uint8_t mac);
uint8_t automac_free_address_count(void);
uint8_t automac_free_address_mac(uint8_t count);
uint8_t automac_free_address_random(void);
void automac_pfm_set(uint8_t mac);
void automac_token_set(uint8_t mac);
void automac_emitter_set(uint8_t mac);
uint8_t automac_next_station(uint8_t mac);
uint8_t automac_address(void);
void automac_address_set(uint8_t mac);
void automac_address_init(void);
uint16_t automac_time_slot(void);
bool automac_pfm_cycle_complete(void);
bool automac_enabled(void);
void automac_enabled_set(bool status);
bool automac_free_address_valid(
uint8_t mac);
uint8_t automac_free_address_count(
void);
uint8_t automac_free_address_mac(
uint8_t count);
uint8_t automac_free_address_random(
void);
void automac_pfm_set(
uint8_t mac);
void automac_token_set(
uint8_t mac);
void automac_emitter_set(
uint8_t mac);
uint8_t automac_next_station(
uint8_t mac);
uint8_t automac_address(
void);
void automac_address_set(
uint8_t mac);
void automac_address_init(
void);
uint16_t automac_time_slot(
void);
bool automac_pfm_cycle_complete(
void);
bool automac_enabled(
void);
void automac_enabled_set(
bool status);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif
+3 -3
View File
@@ -222,7 +222,7 @@ bool Binary_Output_Out_Of_Service(
/* note: the object name must be unique within this device */
bool Binary_Output_Object_Name(
uint32_t object_instance,
BACNET_CHARACTER_STRING *object_name)
BACNET_CHARACTER_STRING * object_name)
{
static char text_string[16] = "BO-0"; /* okay for single thread */
bool status = false;
@@ -430,8 +430,8 @@ bool Binary_Output_Write_Property(
priority = wp_data->priority;
if (priority && (priority <= BACNET_MAX_PRIORITY)) {
priority--;
Binary_Output_Present_Value_Set(wp_data->
object_instance, level, priority);
Binary_Output_Present_Value_Set
(wp_data->object_instance, level, priority);
} else if (priority == 6) {
status = false;
/* Command priority 6 is reserved for use by Minimum On/Off
+14 -15
View File
@@ -175,8 +175,7 @@ static int Read_Property_Common(
} else {
characterstring_init_ansi(&char_string, "");
if (pObject->Object_Name) {
(void)pObject->Object_Name(
rpdata->object_instance,
(void) pObject->Object_Name(rpdata->object_instance,
&char_string);
}
}
@@ -343,7 +342,7 @@ uint32_t Device_Index_To_Instance(
bool Device_Object_Name(
uint32_t object_instance,
BACNET_CHARACTER_STRING *object_name)
BACNET_CHARACTER_STRING * object_name)
{
bool status = false;
@@ -387,7 +386,7 @@ void Device_Init(
{
struct my_object_functions *pObject = NULL;
(void)object_table;
(void) object_table;
pObject = &Object_Table[0];
while (pObject->Object_Type < MAX_BACNET_OBJECT_TYPE) {
if (pObject->Object_Init) {
@@ -525,7 +524,7 @@ bool Device_Object_List_Identifier(
}
bool Device_Valid_Object_Name(
BACNET_CHARACTER_STRING *object_name1,
BACNET_CHARACTER_STRING * object_name1,
int *object_type,
uint32_t * object_instance)
{
@@ -541,10 +540,10 @@ bool Device_Valid_Object_Name(
for (i = 0; i < max_objects; i++) {
check_id = Device_Object_List_Identifier(i, &type, &instance);
if (check_id) {
pObject = Device_Objects_Find_Functions((BACNET_OBJECT_TYPE)type);
pObject = Device_Objects_Find_Functions((BACNET_OBJECT_TYPE) type);
if ((pObject != NULL) && (pObject->Object_Name != NULL) &&
(pObject->Object_Name(instance, &object_name2) &&
characterstring_same(object_name1, &object_name2))) {
characterstring_same(object_name1, &object_name2))) {
found = true;
if (object_type) {
*object_type = type;
@@ -564,10 +563,10 @@ bool Device_Valid_Object_Id(
int object_type,
uint32_t object_instance)
{
bool status = false; /* return value */
bool status = false; /* return value */
struct my_object_functions *pObject = NULL;
pObject = Device_Objects_Find_Functions((BACNET_OBJECT_TYPE)object_type);
pObject = Device_Objects_Find_Functions((BACNET_OBJECT_TYPE) object_type);
if ((pObject != NULL) && (pObject->Object_Valid_Instance != NULL)) {
status = pObject->Object_Valid_Instance(object_instance);
}
@@ -578,7 +577,7 @@ bool Device_Valid_Object_Id(
bool Device_Object_Name_Copy(
int object_type,
uint32_t object_instance,
BACNET_CHARACTER_STRING *object_name)
BACNET_CHARACTER_STRING * object_name)
{
struct my_object_functions *pObject = NULL;
bool found = false;
@@ -591,7 +590,7 @@ bool Device_Object_Name_Copy(
for (i = 0; i < max_objects; i++) {
check_id = Device_Object_List_Identifier(i, &type, &instance);
if (check_id) {
pObject = Device_Objects_Find_Functions((BACNET_OBJECT_TYPE)type);
pObject = Device_Objects_Find_Functions((BACNET_OBJECT_TYPE) type);
if ((pObject != NULL) && (pObject->Object_Name != NULL)) {
found = pObject->Object_Name(instance, object_name);
break;
@@ -816,8 +815,8 @@ bool Device_Write_Property_Local(
case PROP_OBJECT_IDENTIFIER:
if (value.tag == BACNET_APPLICATION_TAG_OBJECT_ID) {
if ((value.type.Object_Id.type == OBJECT_DEVICE) &&
(Device_Set_Object_Instance_Number(value.type.Object_Id.
instance))) {
(Device_Set_Object_Instance_Number(value.type.
Object_Id.instance))) {
/* we could send an I-Am broadcast to let the world know */
status = true;
} else {
@@ -869,8 +868,8 @@ bool Device_Write_Property_Local(
uint8_t encoding =
characterstring_encoding(&value.type.Character_String);
if (encoding < MAX_CHARACTER_STRING_ENCODING) {
characterstring_copy(&My_Object_Name, &value.type.
Character_String);
characterstring_copy(&My_Object_Name,
&value.type.Character_String);
status = true;
} else {
wp_data->error_class = ERROR_CLASS_PROPERTY;
+45 -57
View File
@@ -206,22 +206,17 @@ static RING_BUFFER PDU_Queue;
/* node, its value shall be 1. */
static uint8_t Nmax_info_frames = MSTP_PDU_PACKET_COUNT;
void dlmstp_automac_hander(void);
void dlmstp_automac_hander(
void);
bool dlmstp_init(
char *ifname)
{
ifname = ifname;
Ringbuf_Init(
&Transmit_Queue,
(uint8_t *)&Transmit_Buffer,
sizeof(struct mstp_tx_packet),
MSTP_TRANSMIT_PACKET_COUNT);
Ringbuf_Init(
&PDU_Queue,
(uint8_t *)&PDU_Buffer,
sizeof(struct mstp_pdu_packet),
MSTP_PDU_PACKET_COUNT);
Ringbuf_Init(&Transmit_Queue, (uint8_t *) & Transmit_Buffer,
sizeof(struct mstp_tx_packet), MSTP_TRANSMIT_PACKET_COUNT);
Ringbuf_Init(&PDU_Queue, (uint8_t *) & PDU_Buffer,
sizeof(struct mstp_pdu_packet), MSTP_PDU_PACKET_COUNT);
rs485_init();
automac_init();
@@ -366,25 +361,26 @@ static bool dlmstp_compare_data_expecting_reply(
return true;
}
typedef enum
{
typedef enum {
MSTP_TX_STATE_IDLE,
MSTP_TX_STATE_SILENCE_WAIT,
MSTP_TX_STATE_SEND_WAIT,
MSTP_TX_STATE_STOP
} MSTP_TX_STATE;
static bool MSTP_Transmit_FSM(void)
static bool MSTP_Transmit_FSM(
void)
{
static MSTP_TX_STATE state = MSTP_TX_STATE_IDLE;
static struct mstp_tx_packet *pkt;
MSTP_TX_START:
MSTP_TX_START:
switch (state) {
case MSTP_TX_STATE_IDLE:
if (!Ringbuf_Empty(&Transmit_Queue)) {
/* get the packet - but don't remove it from queue */
pkt = (struct mstp_tx_packet *)Ringbuf_Get_Front(
&Transmit_Queue);
pkt =
(struct mstp_tx_packet *)
Ringbuf_Get_Front(&Transmit_Queue);
state = MSTP_TX_STATE_SILENCE_WAIT;
}
break;
@@ -415,7 +411,7 @@ static bool MSTP_Transmit_FSM(void)
if (rs485_byte_sent() && rs485_frame_sent()) {
rs485_rts_enable(false);
/* remove the packet from the queue */
(void)Ringbuf_Pop_Front(&Transmit_Queue);
(void) Ringbuf_Pop_Front(&Transmit_Queue);
state = MSTP_TX_STATE_IDLE;
}
break;
@@ -452,8 +448,7 @@ static void MSTP_Send_Frame(
static struct mstp_tx_packet *pkt;
uint16_t i = 0; /* used to calculate CRC for data */
pkt = (struct mstp_tx_packet *)Ringbuf_Alloc(
&Transmit_Queue);
pkt = (struct mstp_tx_packet *) Ringbuf_Alloc(&Transmit_Queue);
if (pkt) {
/* create the MS/TP header */
pkt->buffer[0] = 0x55;
@@ -474,11 +469,11 @@ static void MSTP_Send_Frame(
/* calculate CRC for any data */
for (i = 0; i < data_len; i++) {
crc16 = CRC_Calc_Data(data[i], crc16);
pkt->buffer[8+i] = data[i];
pkt->buffer[8 + i] = data[i];
}
crc16 = ~crc16;
pkt->buffer[8+data_len] = (crc16 & 0x00FF);
pkt->buffer[8+data_len+1] = ((crc16 & 0xFF00) >> 8);
pkt->buffer[8 + data_len] = (crc16 & 0x00FF);
pkt->buffer[8 + data_len + 1] = ((crc16 & 0xFF00) >> 8);
pkt->length += data_len;
pkt->length += 2;
}
@@ -630,13 +625,15 @@ static void MSTP_Receive_Frame_FSM(
} else {
/* receive the data portion of the frame. */
if ((DestinationAddress == This_Station) ||
(DestinationAddress == MSTP_BROADCAST_ADDRESS)) {
(DestinationAddress ==
MSTP_BROADCAST_ADDRESS)) {
if (DataLength <= InputBufferSize) {
/* Data */
Receive_State = MSTP_RECEIVE_STATE_DATA;
} else {
/* FrameTooLong */
Receive_State = MSTP_RECEIVE_STATE_SKIP_DATA;
Receive_State =
MSTP_RECEIVE_STATE_SKIP_DATA;
}
} else {
/* NotForUs */
@@ -877,8 +874,7 @@ static bool MSTP_Master_Node_FSM(
transition_now = true;
} else {
uint8_t frame_type;
pkt = (struct mstp_pdu_packet *)Ringbuf_Pop_Front(
&PDU_Queue);
pkt = (struct mstp_pdu_packet *) Ringbuf_Pop_Front(&PDU_Queue);
if (pkt->data_expecting_reply) {
frame_type = FRAME_TYPE_BACNET_DATA_EXPECTING_REPLY;
} else {
@@ -985,10 +981,9 @@ static bool MSTP_Master_Node_FSM(
(Next_Station == This_Station)) {
/* NextStationUnknown - added in Addendum 135-2008v-1 */
/* then the next station to which the token
should be sent is unknown - so PollForMaster */
should be sent is unknown - so PollForMaster */
Poll_Station = next_this_station;
MSTP_Send_Frame(
FRAME_TYPE_POLL_FOR_MASTER, Poll_Station,
MSTP_Send_Frame(FRAME_TYPE_POLL_FOR_MASTER, Poll_Station,
This_Station, NULL, 0);
RetryCount = 0;
Master_State = MSTP_MASTER_STATE_POLL_FOR_MASTER;
@@ -1214,12 +1209,11 @@ static bool MSTP_Master_Node_FSM(
/* Note: we could wait for up to Treply_delay */
matched = false;
if (!Ringbuf_Empty(&PDU_Queue)) {
pkt = (struct mstp_pdu_packet *)Ringbuf_Get_Front(
&PDU_Queue);
pkt = (struct mstp_pdu_packet *) Ringbuf_Get_Front(&PDU_Queue);
matched =
dlmstp_compare_data_expecting_reply(&InputBuffer[0],
DataLength, SourceAddress, &pkt->buffer[0],
pkt->length, pkt->destination_mac);
DataLength, SourceAddress, &pkt->buffer[0], pkt->length,
pkt->destination_mac);
}
if (matched) {
/* Reply */
@@ -1230,8 +1224,7 @@ static bool MSTP_Master_Node_FSM(
/* then call MSTP_Send_Frame to transmit the reply frame */
/* and enter the IDLE state to wait for the next frame. */
uint8_t frame_type;
pkt = (struct mstp_pdu_packet *)Ringbuf_Pop_Front(
&PDU_Queue);
pkt = (struct mstp_pdu_packet *) Ringbuf_Pop_Front(&PDU_Queue);
if (pkt->data_expecting_reply) {
frame_type = FRAME_TYPE_BACNET_DATA_EXPECTING_REPLY;
} else {
@@ -1276,7 +1269,7 @@ int dlmstp_send_pdu(
struct mstp_pdu_packet *pkt;
uint16_t i = 0;
pkt = (struct mstp_pdu_packet *)Ringbuf_Alloc(&PDU_Queue);
pkt = (struct mstp_pdu_packet *) Ringbuf_Alloc(&PDU_Queue);
if (pkt) {
pkt->data_expecting_reply = npdu_data->data_expecting_reply;
for (i = 0; i < pdu_len; i++) {
@@ -1300,7 +1293,8 @@ typedef enum {
} AUTOMAC_STATE;
/* buffer used to send and validate a response - size is min APDU size */
static uint8_t AutoMAC_Test_Buffer[50];
void dlmstp_automac_hander(void)
void dlmstp_automac_hander(
void)
{
static AUTOMAC_STATE state = AUTOMAC_STATE_IDLE;
uint8_t mac = 0;
@@ -1341,7 +1335,7 @@ void dlmstp_automac_hander(void)
}
} else if (rs485_silence_elapsed(automac_time_slot())) {
/* long silence indicates we are alone or
with other silent devices */
with other silent devices */
SourceAddress = automac_address();
state = AUTOMAC_STATE_TESTING;
}
@@ -1360,7 +1354,8 @@ void dlmstp_automac_hander(void)
automac_init();
state = AUTOMAC_STATE_IDLE;
} else if (mac == DestinationAddress) {
MSTP_Send_Frame(FRAME_TYPE_REPLY_TO_POLL_FOR_MASTER,
MSTP_Send_Frame
(FRAME_TYPE_REPLY_TO_POLL_FOR_MASTER,
SourceAddress, mac, NULL, 0);
state = AUTOMAC_STATE_TOKEN;
}
@@ -1433,9 +1428,8 @@ void dlmstp_automac_hander(void)
encode_unsigned16(&AutoMAC_Test_Buffer[0], vendor_id);
serial_number = Device_Object_Instance_Number();
encode_unsigned32(&AutoMAC_Test_Buffer[2], serial_number);
MSTP_Send_Frame(FRAME_TYPE_TEST_REQUEST,
SourceAddress, mac, &AutoMAC_Test_Buffer[0],
6);
MSTP_Send_Frame(FRAME_TYPE_TEST_REQUEST, SourceAddress, mac,
&AutoMAC_Test_Buffer[0], 6);
state = AUTOMAC_STATE_CONFIRM;
break;
case AUTOMAC_STATE_CONFIRM:
@@ -1448,8 +1442,7 @@ void dlmstp_automac_hander(void)
MSTP_Flag.ReceivedValidFrame = false;
MSTP_Flag.ReceivedValidFrameNotForUs = false;
mac = automac_address();
if ((mac == DestinationAddress) &&
(DataLength >= 6)) {
if ((mac == DestinationAddress) && (DataLength >= 6)) {
decode_unsigned16(&InputBuffer[0], &vendor_id);
decode_unsigned32(&InputBuffer[2], &serial_number);
if ((vendor_id == Device_Vendor_Identifier()) &&
@@ -1511,18 +1504,14 @@ uint16_t dlmstp_receive(
/* only do receive state machine while we don't have a frame */
if ((MSTP_Flag.ReceivedValidFrame == false) &&
(MSTP_Flag.ReceivedValidFrameNotForUs == false) &&
(MSTP_Flag.ReceivedInvalidFrame == false) &&
(transmitting == false)) {
(MSTP_Flag.ReceivedInvalidFrame == false) && (transmitting == false)) {
MSTP_Receive_Frame_FSM();
}
/* only do master state machine while rx is idle */
if ((Receive_State == MSTP_RECEIVE_STATE_IDLE) &&
(transmitting == false)) {
if ((This_Station != 255) &&
(MSTP_Flag.ReceivedValidFrameNotForUs)) {
if ((Receive_State == MSTP_RECEIVE_STATE_IDLE) && (transmitting == false)) {
if ((This_Station != 255) && (MSTP_Flag.ReceivedValidFrameNotForUs)) {
MSTP_Flag.ReceivedValidFrameNotForUs = false;
if ((SourceAddress == This_Station) &&
automac_enabled()) {
if ((SourceAddress == This_Station) && automac_enabled()) {
/* duplicate MAC on the wire */
automac_init();
This_Station = 255;
@@ -1602,8 +1591,7 @@ void dlmstp_set_max_master(
uint8_t max_master)
{
if (max_master <= 127) {
if ((This_Station == 255) ||
(This_Station <= max_master)) {
if ((This_Station == 255) || (This_Station <= max_master)) {
Nmax_master = max_master;
}
}
@@ -1651,7 +1639,8 @@ void dlmstp_get_broadcast_address(
return;
}
bool dlmstp_sole_master(void)
bool dlmstp_sole_master(
void)
{
if (MSTP_Flag.SoleMaster) {
return true;
@@ -1659,4 +1648,3 @@ bool dlmstp_sole_master(void)
return false;
}
+12 -6
View File
@@ -89,7 +89,8 @@ void led_rx_off(
* Returns: true if on, false if off.
* Notes: none
*************************************************************************/
bool led_rx_state(void)
bool led_rx_state(
void)
{
return Rx_State;
}
@@ -99,7 +100,8 @@ bool led_rx_state(void)
* Returns: true if on, false if off.
* Notes: none
*************************************************************************/
bool led_tx_state(void)
bool led_tx_state(
void)
{
return Tx_State;
}
@@ -109,7 +111,8 @@ bool led_tx_state(void)
* Returns: none
* Notes: none
*************************************************************************/
void led_tx_toggle(void)
void led_tx_toggle(
void)
{
if (led_tx_state()) {
led_tx_off();
@@ -123,7 +126,8 @@ void led_tx_toggle(void)
* Returns: none
* Notes: none
*************************************************************************/
void led_rx_toggle(void)
void led_rx_toggle(
void)
{
if (led_rx_state()) {
led_rx_off();
@@ -247,7 +251,8 @@ void led_ld3_off(
* Returns: true if on, false if off.
* Notes: none
*************************************************************************/
bool led_ld3_state(void)
bool led_ld3_state(
void)
{
return LD3_State;
}
@@ -257,7 +262,8 @@ bool led_ld3_state(void)
* Returns: none
* Notes: none
*************************************************************************/
void led_ld3_toggle(void)
void led_ld3_toggle(
void)
{
if (led_ld3_state()) {
led_ld3_off();
+20 -10
View File
@@ -39,30 +39,40 @@ extern "C" {
void);
void led_ld4_off(
void);
bool led_ld3_state(void);
void led_ld3_toggle(void);
bool led_ld3_state(
void);
void led_ld3_toggle(
void);
void led_tx_on(void);
void led_rx_on(void);
void led_tx_on(
void);
void led_rx_on(
void);
void led_tx_on_interval(
uint16_t interval_ms);
void led_rx_on_interval(
uint16_t interval_ms);
void led_tx_off(void);
void led_rx_off(void);
void led_tx_off(
void);
void led_rx_off(
void);
void led_tx_off_delay(
uint32_t delay_ms);
void led_rx_off_delay(
uint32_t delay_ms);
void led_tx_toggle(void);
void led_rx_toggle(void);
void led_tx_toggle(
void);
void led_rx_toggle(
void);
bool led_tx_state(void);
bool led_rx_state(void);
bool led_tx_state(
void);
bool led_rx_state(
void);
void led_task(
void);
+46 -50
View File
@@ -44,15 +44,16 @@ char *BACnet_Version = "1.0";
* @param line: assert_param error line source number
* @retval None
*/
void assert_failed(uint8_t* file, uint32_t line)
void assert_failed(
uint8_t * file,
uint32_t line)
{
/* User can add his own implementation to report the file name and line number,
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
/* User can add his own implementation to report the file name and line number,
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
/* Infinite loop */
while (1)
{
}
/* Infinite loop */
while (1) {
}
}
#endif
@@ -60,7 +61,8 @@ void assert_failed(uint8_t* file, uint32_t line)
#define LSE_FAIL_FLAG 0x80
#define LSE_PASS_FLAG 0x100
void lse_init(void)
void lse_init(
void)
{
uint32_t LSE_Delay = 0;
struct etimer Delay_Timer;
@@ -70,42 +72,37 @@ void lse_init(void)
/* Enable LSE (Low Speed External Oscillation) */
RCC_LSEConfig(RCC_LSE_ON);
/* Check the LSE Status */
while(1)
{
if(LSE_Delay < LSE_FAIL_FLAG)
{
timer_elapsed_start(&Delay_Timer);
while (!timer_elapsed_milliseconds(&Delay_Timer,500)) {
/* do nothing */
}
/* check whether LSE is ready, with 4 seconds timeout */
LSE_Delay += 0x10;
if(RCC_GetFlagStatus(RCC_FLAG_LSERDY) != RESET)
{
/* Set flag: LSE PASS */
LSE_Delay |= LSE_PASS_FLAG;
led_ld4_off();
/* Disable LSE */
RCC_LSEConfig(RCC_LSE_OFF);
break;
}
}
/* Check the LSE Status */
while (1) {
if (LSE_Delay < LSE_FAIL_FLAG) {
timer_elapsed_start(&Delay_Timer);
while (!timer_elapsed_milliseconds(&Delay_Timer, 500)) {
/* do nothing */
}
/* check whether LSE is ready, with 4 seconds timeout */
LSE_Delay += 0x10;
if (RCC_GetFlagStatus(RCC_FLAG_LSERDY) != RESET) {
/* Set flag: LSE PASS */
LSE_Delay |= LSE_PASS_FLAG;
led_ld4_off();
/* Disable LSE */
RCC_LSEConfig(RCC_LSE_OFF);
break;
}
}
/* LSE_FAIL_FLAG = 0x80 */
else if(LSE_Delay >= LSE_FAIL_FLAG)
{
if(RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET)
{
/* Set flag: LSE FAIL */
LSE_Delay |= LSE_FAIL_FLAG;
led_ld4_on();
}
/* Disable LSE */
RCC_LSEConfig(RCC_LSE_OFF);
break;
/* LSE_FAIL_FLAG = 0x80 */
else if (LSE_Delay >= LSE_FAIL_FLAG) {
if (RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET) {
/* Set flag: LSE FAIL */
LSE_Delay |= LSE_FAIL_FLAG;
led_ld4_on();
}
/* Disable LSE */
RCC_LSEConfig(RCC_LSE_OFF);
break;
}
}
}
}
int main(
@@ -114,17 +111,16 @@ int main(
struct itimer Blink_Timer;
/*At this stage the microcontroller clock setting is already configured,
this is done through SystemInit() function which is called from startup
file (startup_stm32f10x_xx.s) before to branch to application main.
To reconfigure the default setting of SystemInit() function, refer to
system_stm32f10x.c file */
this is done through SystemInit() function which is called from startup
file (startup_stm32f10x_xx.s) before to branch to application main.
To reconfigure the default setting of SystemInit() function, refer to
system_stm32f10x.c file */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
led_init();
RCC_APB2PeriphClockCmd(
RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB |
RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD |
RCC_APB2Periph_GPIOE, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB |
RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE,
ENABLE);
timer_init();
lse_init();
led_init();
+23 -18
View File
@@ -58,7 +58,8 @@ static uint32_t Baud_Rate = 38400;
* Returns: nothing
* Notes: none
**************************************************************************/
void rs485_silence_reset(void)
void rs485_silence_reset(
void)
{
timer_elapsed_start(&Silence_Timer);
}
@@ -68,7 +69,8 @@ void rs485_silence_reset(void)
* Returns: true if the amount of time has elapsed
* Notes: none
**************************************************************************/
bool rs485_silence_elapsed(uint32_t interval)
bool rs485_silence_elapsed(
uint32_t interval)
{
return timer_elapsed_milliseconds(&Silence_Timer, interval);
}
@@ -95,9 +97,7 @@ static uint16_t rs485_turnaround_time(
bool rs485_turnaround_elapsed(
void)
{
return timer_elapsed_milliseconds(
&Silence_Timer,
rs485_turnaround_time());
return timer_elapsed_milliseconds(&Silence_Timer, rs485_turnaround_time());
}
@@ -112,20 +112,21 @@ bool rs485_receive_error(
return false;
}
/*********************************************************************//**
/*********************************************************************//**
* @brief USARTx interrupt handler sub-routine
* @param[in] None
* @return None
**********************************************************************/
void USART2_IRQHandler(void)
void USART2_IRQHandler(
void)
{
uint8_t data_byte;
if(USART_GetITStatus(USART2, USART_IT_RXNE) != RESET) {
if (USART_GetITStatus(USART2, USART_IT_RXNE) != RESET) {
/* Read one byte from the receive data register */
data_byte = USART_ReceiveData(USART2);
(void)FIFO_Put(&Receive_Buffer, data_byte);
(void) FIFO_Put(&Receive_Buffer, data_byte);
}
}
@@ -137,7 +138,7 @@ void USART2_IRQHandler(void)
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)) {
*data_register = FIFO_Get(&Receive_Buffer);
@@ -154,7 +155,8 @@ bool rs485_byte_available(
* RETURN: nothing
* NOTES: none
**************************************************************************/
void rs485_byte_send(uint8_t tx_byte)
void rs485_byte_send(
uint8_t tx_byte)
{
led_tx_on_interval(10);
USART_SendData(USART2, tx_byte);
@@ -167,7 +169,8 @@ void rs485_byte_send(uint8_t tx_byte)
* Returns: true if the USART register is empty
* Notes: none
**************************************************************************/
bool rs485_byte_sent(void)
bool rs485_byte_sent(
void)
{
return USART_GetFlagStatus(USART2, USART_FLAG_TXE);
}
@@ -177,7 +180,8 @@ bool rs485_byte_sent(void)
* Returns: true if the USART FIFO is empty
* Notes: none
**************************************************************************/
bool rs485_frame_sent(void)
bool rs485_frame_sent(
void)
{
return USART_GetFlagStatus(USART2, USART_FLAG_TC);
}
@@ -188,9 +192,9 @@ bool rs485_frame_sent(void)
* NOTES: none
**************************************************************************/
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 */
uint8_t tx_byte;
while (nbytes) {
@@ -295,7 +299,8 @@ void rs485_rts_enable(
* Returns: nothing
* Notes: none
**************************************************************************/
void rs485_init(void)
void rs485_init(
void)
{
GPIO_InitTypeDef GPIO_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
@@ -335,6 +340,6 @@ void rs485_init(void)
USART_Cmd(USART2, ENABLE);
FIFO_Init(&Receive_Buffer, &Receive_Buffer_Data[0],
(unsigned)sizeof(Receive_Buffer_Data));
(unsigned) sizeof(Receive_Buffer_Data));
timer_elapsed_start(&Silence_Timer);
}
+8 -4
View File
@@ -52,13 +52,17 @@ extern "C" {
/* a granular approach */
void rs485_byte_send(
uint8_t data_register);
bool rs485_byte_sent(void);
bool rs485_frame_sent(void);
bool rs485_byte_sent(
void);
bool rs485_frame_sent(
void);
bool rs485_turnaround_elapsed(
void);
void rs485_silence_reset(void);
bool rs485_silence_elapsed(uint32_t interval);
void rs485_silence_reset(
void);
bool rs485_silence_elapsed(
uint32_t interval);
#ifdef __cplusplus
}
@@ -46,7 +46,7 @@
#include "stm32f10x_tim.h"
#include "stm32f10x_usart.h"
#include "stm32f10x_wwdg.h"
#include "misc.h" /* High level functions for NVIC and SysTick (add-on to CMSIS functions) */
#include "misc.h" /* High level functions for NVIC and SysTick (add-on to CMSIS functions) */
/* Exported types ------------------------------------------------------------*/
/* Exported constants --------------------------------------------------------*/
@@ -62,11 +62,13 @@
* If expr is true, it returns no value.
* @retval None
*/
#define assert_param(expr) ((expr) ? (void)0 : assert_failed((uint8_t *)__FILE__, __LINE__))
#define assert_param(expr) ((expr) ? (void)0 : assert_failed((uint8_t *)__FILE__, __LINE__))
/* Exported functions ------------------------------------------------------- */
void assert_failed(uint8_t* file, uint32_t line);
void assert_failed(
uint8_t * file,
uint32_t line);
#else
#define assert_param(expr) ((void)0)
#define assert_param(expr) ((void)0)
#endif /* USE_FULL_ASSERT */
#endif /* __STM32F10x_CONF_H */
+28 -24
View File
@@ -47,7 +47,8 @@
* @param None
* @retval None
*/
void NMI_Handler(void)
void NMI_Handler(
void)
{
}
@@ -56,12 +57,12 @@ void NMI_Handler(void)
* @param None
* @retval None
*/
void HardFault_Handler(void)
void HardFault_Handler(
void)
{
/* Go to infinite loop when Hard Fault exception occurs */
while (1)
{
}
/* Go to infinite loop when Hard Fault exception occurs */
while (1) {
}
}
/**
@@ -69,12 +70,12 @@ void HardFault_Handler(void)
* @param None
* @retval None
*/
void MemManage_Handler(void)
void MemManage_Handler(
void)
{
/* Go to infinite loop when Memory Manage exception occurs */
while (1)
{
}
/* Go to infinite loop when Memory Manage exception occurs */
while (1) {
}
}
/**
@@ -82,12 +83,12 @@ void MemManage_Handler(void)
* @param None
* @retval None
*/
void BusFault_Handler(void)
void BusFault_Handler(
void)
{
/* Go to infinite loop when Bus Fault exception occurs */
while (1)
{
}
/* Go to infinite loop when Bus Fault exception occurs */
while (1) {
}
}
/**
@@ -95,12 +96,12 @@ void BusFault_Handler(void)
* @param None
* @retval None
*/
void UsageFault_Handler(void)
void UsageFault_Handler(
void)
{
/* Go to infinite loop when Usage Fault exception occurs */
while (1)
{
}
/* Go to infinite loop when Usage Fault exception occurs */
while (1) {
}
}
/**
@@ -108,7 +109,8 @@ void UsageFault_Handler(void)
* @param None
* @retval None
*/
void SVC_Handler(void)
void SVC_Handler(
void)
{
}
@@ -117,7 +119,8 @@ void SVC_Handler(void)
* @param None
* @retval None
*/
void DebugMon_Handler(void)
void DebugMon_Handler(
void)
{
}
@@ -126,7 +129,8 @@ void DebugMon_Handler(void)
* @param None
* @retval None
*/
void PendSV_Handler(void)
void PendSV_Handler(
void)
{
}
+16 -8
View File
@@ -30,14 +30,22 @@
/* Exported macro ------------------------------------------------------------*/
/* Exported functions ------------------------------------------------------- */
void NMI_Handler(void);
void HardFault_Handler(void);
void MemManage_Handler(void);
void BusFault_Handler(void);
void UsageFault_Handler(void);
void SVC_Handler(void);
void DebugMon_Handler(void);
void PendSV_Handler(void);
void NMI_Handler(
void);
void HardFault_Handler(
void);
void MemManage_Handler(
void);
void BusFault_Handler(
void);
void UsageFault_Handler(
void);
void SVC_Handler(
void);
void DebugMon_Handler(
void);
void PendSV_Handler(
void);
#endif /* __STM32F10x_IT_H */
File diff suppressed because it is too large Load Diff
+8 -4
View File
@@ -61,7 +61,8 @@ static void timer_debug_off(
* Returns: none
* Notes: none
*************************************************************************/
void timer_debug_toggle(void)
void timer_debug_toggle(
void)
{
static bool state = false;
@@ -79,7 +80,8 @@ void timer_debug_toggle(void)
* Returns: nothing
* Notes: reserved name for ISR handlers
*************************************************************************/
void SysTick_Handler(void)
void SysTick_Handler(
void)
{
/* increment the tick count */
Millisecond_Counter++;
@@ -91,7 +93,8 @@ void SysTick_Handler(void)
* Returns: none
* Notes: none
*************************************************************************/
uint32_t timer_milliseconds(void)
uint32_t timer_milliseconds(
void)
{
return Millisecond_Counter;
}
@@ -101,7 +104,8 @@ uint32_t timer_milliseconds(void)
* Returns: none
* Notes: peripheral frequency defined in hardware.h
*************************************************************************/
void timer_init(void)
void timer_init(
void)
{
GPIO_InitTypeDef GPIO_InitStructure;