Feature/make pretty apps and ports (#80)
* Added pretty-apps and pretty-ports make targets * pretty-fied apps folder C files * Pretty-fied ports folder C and H files Co-authored-by: Steve Karg <skarg@users.sourceforge.net>
This commit is contained in:
+124
-142
@@ -1,27 +1,27 @@
|
||||
/**************************************************************************
|
||||
*
|
||||
* Copyright (C) 2010 Steve Karg <skarg@users.sourceforge.net>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included
|
||||
* in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*********************************************************************/
|
||||
*
|
||||
* Copyright (C) 2010 Steve Karg <skarg@users.sourceforge.net>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included
|
||||
* in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*
|
||||
*********************************************************************/
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
@@ -37,14 +37,14 @@
|
||||
/* table to track tokens and poll-for-master frames */
|
||||
typedef struct {
|
||||
/* Poll For Master indicates empty slot */
|
||||
bool pfm:1;
|
||||
bool pfm : 1;
|
||||
/* a device that emits a frame indicates a used slot */
|
||||
bool emitter:1;
|
||||
bool emitter : 1;
|
||||
/* token - indicates a token was passed from this slot */
|
||||
/* important to know who the Next Station is */
|
||||
bool token:1;
|
||||
bool token : 1;
|
||||
/* reserve some slots for fixed addresses */
|
||||
bool reserved:1;
|
||||
bool reserved : 1;
|
||||
} AUTO_MAC_DATA;
|
||||
/* starting number available for AutoMAC */
|
||||
#define MAC_SLOTS_OFFSET 32
|
||||
@@ -61,45 +61,41 @@ static bool PFM_Cycle_Complete;
|
||||
static bool Auto_Mode_Enabled;
|
||||
|
||||
/****************************************************************************
|
||||
* DESCRIPTION: Indication that we are an automode node
|
||||
* RETURN: true if automode enabled
|
||||
* NOTES: none
|
||||
*****************************************************************************/
|
||||
bool automac_enabled(
|
||||
void)
|
||||
* DESCRIPTION: Indication that we are an automode node
|
||||
* RETURN: true if automode enabled
|
||||
* NOTES: none
|
||||
*****************************************************************************/
|
||||
bool automac_enabled(void)
|
||||
{
|
||||
return Auto_Mode_Enabled;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* DESCRIPTION: Sets the automode status
|
||||
* RETURN: nothing
|
||||
* NOTES: none
|
||||
*****************************************************************************/
|
||||
void automac_enabled_set(
|
||||
bool status)
|
||||
* DESCRIPTION: Sets the automode status
|
||||
* RETURN: nothing
|
||||
* NOTES: none
|
||||
*****************************************************************************/
|
||||
void automac_enabled_set(bool status)
|
||||
{
|
||||
Auto_Mode_Enabled = status;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* DESCRIPTION: Indication that PFM has happened for a full cycle
|
||||
* RETURN: true if full
|
||||
* NOTES: none
|
||||
*****************************************************************************/
|
||||
bool automac_pfm_cycle_complete(
|
||||
void)
|
||||
* DESCRIPTION: Indication that PFM has happened for a full cycle
|
||||
* RETURN: true if full
|
||||
* NOTES: none
|
||||
*****************************************************************************/
|
||||
bool automac_pfm_cycle_complete(void)
|
||||
{
|
||||
return PFM_Cycle_Complete;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* DESCRIPTION: Indicates that an address is used or taken
|
||||
* RETURN: true if used
|
||||
* NOTES: none
|
||||
*****************************************************************************/
|
||||
static bool automac_address_used(
|
||||
uint8_t mac)
|
||||
* DESCRIPTION: Indicates that an address is used or taken
|
||||
* RETURN: true if used
|
||||
* NOTES: none
|
||||
*****************************************************************************/
|
||||
static bool automac_address_used(uint8_t mac)
|
||||
{
|
||||
bool status = false;
|
||||
|
||||
@@ -114,12 +110,11 @@ static bool automac_address_used(
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* DESCRIPTION: Validates an address as available, not taken, and within bounds
|
||||
* RETURN: true if valid
|
||||
* NOTES: none
|
||||
*****************************************************************************/
|
||||
bool automac_free_address_valid(
|
||||
uint8_t mac)
|
||||
* DESCRIPTION: Validates an address as available, not taken, and within bounds
|
||||
* RETURN: true if valid
|
||||
* NOTES: none
|
||||
*****************************************************************************/
|
||||
bool automac_free_address_valid(uint8_t mac)
|
||||
{
|
||||
bool status = false;
|
||||
|
||||
@@ -133,16 +128,15 @@ bool automac_free_address_valid(
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* DESCRIPTION: Determines the next station address to send the token
|
||||
* RETURN: Next_Station, or 255 if there are no next stations
|
||||
* NOTES: none
|
||||
*****************************************************************************/
|
||||
uint8_t automac_next_station(
|
||||
uint8_t mac)
|
||||
* DESCRIPTION: Determines the next station address to send the token
|
||||
* RETURN: Next_Station, or 255 if there are no next stations
|
||||
* NOTES: none
|
||||
*****************************************************************************/
|
||||
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,12 +151,11 @@ uint8_t automac_next_station(
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* DESCRIPTION: Determines the number of free MAC addresses
|
||||
* RETURN: Number of free MAC addresses
|
||||
* NOTES: none
|
||||
*****************************************************************************/
|
||||
uint8_t automac_free_address_count(
|
||||
void)
|
||||
* DESCRIPTION: Determines the number of free MAC addresses
|
||||
* RETURN: Number of free MAC addresses
|
||||
* NOTES: none
|
||||
*****************************************************************************/
|
||||
uint8_t automac_free_address_count(void)
|
||||
{
|
||||
uint8_t i = 0;
|
||||
uint8_t slots = 0;
|
||||
@@ -177,12 +170,11 @@ uint8_t automac_free_address_count(
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* DESCRIPTION: Determines the number of free MAC addresses
|
||||
* RETURN: Number of free MAC addresses
|
||||
* NOTES: none
|
||||
*****************************************************************************/
|
||||
uint8_t automac_free_address_mac(
|
||||
uint8_t count)
|
||||
* DESCRIPTION: Determines the number of free MAC addresses
|
||||
* RETURN: Number of free MAC addresses
|
||||
* NOTES: none
|
||||
*****************************************************************************/
|
||||
uint8_t automac_free_address_mac(uint8_t count)
|
||||
{
|
||||
uint8_t i = 0;
|
||||
uint8_t slots = 0;
|
||||
@@ -202,12 +194,11 @@ uint8_t automac_free_address_mac(
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* DESCRIPTION: Gets a free random address to use
|
||||
* RETURN: free MAC addresses
|
||||
* NOTES: none
|
||||
*****************************************************************************/
|
||||
uint8_t automac_free_address_random(
|
||||
void)
|
||||
* DESCRIPTION: Gets a free random address to use
|
||||
* RETURN: free MAC addresses
|
||||
* NOTES: none
|
||||
*****************************************************************************/
|
||||
uint8_t automac_free_address_random(void)
|
||||
{
|
||||
uint8_t count = 0;
|
||||
uint8_t random_count = 0;
|
||||
@@ -215,7 +206,7 @@ uint8_t automac_free_address_random(
|
||||
|
||||
count = automac_free_address_count();
|
||||
if (count) {
|
||||
random_count =(uint8_t)(rand() % count);
|
||||
random_count = (uint8_t)(rand() % count);
|
||||
mac = automac_free_address_mac(random_count);
|
||||
}
|
||||
|
||||
@@ -223,60 +214,55 @@ uint8_t automac_free_address_random(
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* DESCRIPTION: Gets the address stored.
|
||||
* RETURN: MAC addresses
|
||||
* NOTES: none
|
||||
*****************************************************************************/
|
||||
uint8_t automac_address(
|
||||
void)
|
||||
* DESCRIPTION: Gets the address stored.
|
||||
* RETURN: MAC addresses
|
||||
* NOTES: none
|
||||
*****************************************************************************/
|
||||
uint8_t automac_address(void)
|
||||
{
|
||||
return My_MAC_Address;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* DESCRIPTION: Sets the MAC address
|
||||
* RETURN: MAC addresses
|
||||
* NOTES: none
|
||||
*****************************************************************************/
|
||||
void automac_address_set(
|
||||
uint8_t mac)
|
||||
* DESCRIPTION: Sets the MAC address
|
||||
* RETURN: MAC addresses
|
||||
* NOTES: none
|
||||
*****************************************************************************/
|
||||
void automac_address_set(uint8_t mac)
|
||||
{
|
||||
My_MAC_Address = mac;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* DESCRIPTION: Gets the address stored.
|
||||
* RETURN: MAC addresses
|
||||
* NOTES: none
|
||||
*****************************************************************************/
|
||||
uint16_t automac_time_slot(
|
||||
void)
|
||||
* DESCRIPTION: Gets the address stored.
|
||||
* RETURN: MAC addresses
|
||||
* NOTES: none
|
||||
*****************************************************************************/
|
||||
uint16_t automac_time_slot(void)
|
||||
{
|
||||
return My_Time_Slot;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* DESCRIPTION: Sets the MAC address
|
||||
* RETURN: MAC addresses
|
||||
* NOTES: none
|
||||
*****************************************************************************/
|
||||
void automac_address_init(
|
||||
void)
|
||||
* DESCRIPTION: Sets the MAC address
|
||||
* RETURN: MAC addresses
|
||||
* NOTES: none
|
||||
*****************************************************************************/
|
||||
void automac_address_init(void)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* DESCRIPTION: Sets an open address slot
|
||||
* RETURN: nothing
|
||||
* NOTES: none
|
||||
*****************************************************************************/
|
||||
void automac_pfm_set(
|
||||
uint8_t mac)
|
||||
* DESCRIPTION: Sets an open address slot
|
||||
* RETURN: nothing
|
||||
* NOTES: none
|
||||
*****************************************************************************/
|
||||
void automac_pfm_set(uint8_t mac)
|
||||
{
|
||||
if (mac < MAC_SLOTS_MAX) {
|
||||
if (Auto_MAC_Data[mac].pfm) {
|
||||
@@ -290,12 +276,11 @@ void automac_pfm_set(
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* DESCRIPTION: Sets a used address slot
|
||||
* RETURN: nothing
|
||||
* NOTES: none
|
||||
*****************************************************************************/
|
||||
void automac_token_set(
|
||||
uint8_t mac)
|
||||
* DESCRIPTION: Sets a used address slot
|
||||
* RETURN: nothing
|
||||
* NOTES: none
|
||||
*****************************************************************************/
|
||||
void automac_token_set(uint8_t mac)
|
||||
{
|
||||
if (mac < MAC_SLOTS_MAX) {
|
||||
Auto_MAC_Data[mac].token = true;
|
||||
@@ -303,12 +288,11 @@ void automac_token_set(
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* DESCRIPTION: Sets a used address slot
|
||||
* RETURN: nothing
|
||||
* NOTES: none
|
||||
*****************************************************************************/
|
||||
void automac_emitter_set(
|
||||
uint8_t mac)
|
||||
* DESCRIPTION: Sets a used address slot
|
||||
* RETURN: nothing
|
||||
* NOTES: none
|
||||
*****************************************************************************/
|
||||
void automac_emitter_set(uint8_t mac)
|
||||
{
|
||||
if (mac < MAC_SLOTS_MAX) {
|
||||
Auto_MAC_Data[mac].emitter = true;
|
||||
@@ -316,12 +300,11 @@ void automac_emitter_set(
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* DESCRIPTION: Initializes the auto MAC module
|
||||
* RETURN: nothing
|
||||
* NOTES: none
|
||||
*****************************************************************************/
|
||||
void automac_init(
|
||||
void)
|
||||
* DESCRIPTION: Initializes the auto MAC module
|
||||
* RETURN: nothing
|
||||
* NOTES: none
|
||||
*****************************************************************************/
|
||||
void automac_init(void)
|
||||
{
|
||||
uint8_t i = 0;
|
||||
|
||||
@@ -346,8 +329,7 @@ void automac_init(
|
||||
#include "ctest.h"
|
||||
|
||||
/* test the ring buffer */
|
||||
void test_Auto_MAC(
|
||||
Test * pTest)
|
||||
void test_Auto_MAC(Test *pTest)
|
||||
{
|
||||
uint8_t mac = 255;
|
||||
|
||||
@@ -387,8 +369,8 @@ void test_Auto_MAC(
|
||||
mac = automac_free_address_mac(1);
|
||||
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);
|
||||
@@ -398,8 +380,9 @@ void test_Auto_MAC(
|
||||
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);
|
||||
@@ -414,8 +397,7 @@ void test_Auto_MAC(
|
||||
}
|
||||
|
||||
#ifdef TEST_AUTOMAC
|
||||
int main(
|
||||
void)
|
||||
int main(void)
|
||||
{
|
||||
Test *pTest;
|
||||
bool rc;
|
||||
@@ -428,7 +410,7 @@ int main(
|
||||
|
||||
ct_setStream(pTest, stdout);
|
||||
ct_run(pTest);
|
||||
(void) ct_report(pTest);
|
||||
(void)ct_report(pTest);
|
||||
|
||||
ct_destroy(pTest);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user