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:
Steve Karg
2020-04-30 10:13:11 -05:00
committed by GitHub
parent 0abcbea971
commit fdd49f1791
152 changed files with 9668 additions and 11674 deletions
+106 -121
View File
@@ -1,26 +1,26 @@
/**************************************************************************
*
* Copyright (C) 2009 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) 2009 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>
@@ -44,7 +44,7 @@ static uint32_t Baud_Rate = 9600;
/* At 76800 baud, 40 bit times would be about 0.520 milliseconds */
/* At 115200 baud, 40 bit times would be about 0.347 milliseconds */
/* 40 bits is 4 octets including a start and stop bit with each octet */
#define Tturnaround (40UL)
#define Tturnaround (40UL)
/* turnaround_time_milliseconds = (Tturnaround*1000UL)/Baud_Rate; */
/* buffer for storing received bytes - size must be power of two */
@@ -54,46 +54,42 @@ static FIFO_BUFFER Receive_Buffer;
static struct mstimer Silence_Timer;
/****************************************************************************
* DESCRIPTION: Determines the amount of silence time elapsed
* RETURN: true if the amount of silence time has elapsed
* NOTES: none
*****************************************************************************/
bool rs485_silence_time_elapsed(
uint16_t milliseconds)
* DESCRIPTION: Determines the amount of silence time elapsed
* RETURN: true if the amount of silence time has elapsed
* NOTES: none
*****************************************************************************/
bool rs485_silence_time_elapsed(uint16_t milliseconds)
{
return (mstimer_elapsed(&Silence_Timer) > milliseconds);
}
/****************************************************************************
* DESCRIPTION: Resets the silence timer
* RETURN: nothing
* NOTES: none
*****************************************************************************/
void rs485_silence_time_reset(
void)
* DESCRIPTION: Resets the silence timer
* RETURN: nothing
* NOTES: none
*****************************************************************************/
void rs485_silence_time_reset(void)
{
mstimer_set(&Silence_Timer, 0);
}
/****************************************************************************
* DESCRIPTION: Configures the RTS output
* RETURN: nothing
* NOTES: none
*****************************************************************************/
static void rs485_rts_init(
void)
* DESCRIPTION: Configures the RTS output
* RETURN: nothing
* NOTES: none
*****************************************************************************/
static void rs485_rts_init(void)
{
/* configure the port pin as an output */
BIT_SET(DDRD, DDD4);
}
/****************************************************************************
* DESCRIPTION: enable the transmit-enable line on the RS-485 transceiver
* RETURN: nothing
* NOTES: none
*****************************************************************************/
void rs485_rts_enable(
bool enable)
* DESCRIPTION: enable the transmit-enable line on the RS-485 transceiver
* RETURN: nothing
* NOTES: none
*****************************************************************************/
void rs485_rts_enable(bool enable)
{
if (enable) {
BIT_SET(PORTD, PD4);
@@ -103,23 +99,21 @@ void rs485_rts_enable(
}
/****************************************************************************
* DESCRIPTION: enable the UART receiver and interrupt
* RETURN: nothing
* NOTES: none
*****************************************************************************/
static void rs485_receiver_enable(
void)
* DESCRIPTION: enable the UART receiver and interrupt
* RETURN: nothing
* NOTES: none
*****************************************************************************/
static void rs485_receiver_enable(void)
{
UCSR0B = _BV(TXEN0) | _BV(RXEN0) | _BV(RXCIE0);
}
/****************************************************************************
* DESCRIPTION: delay for 40 bit times
* RETURN: nothing
* NOTES: none
*****************************************************************************/
void rs485_turnaround_delay(
void)
* DESCRIPTION: delay for 40 bit times
* RETURN: nothing
* NOTES: none
*****************************************************************************/
void rs485_turnaround_delay(void)
{
uint8_t nbytes = 4;
@@ -144,10 +138,10 @@ void rs485_turnaround_delay(
}
/****************************************************************************
* DESCRIPTION: Interrupt service routine for UART Receiver
* RETURN: nothing
* NOTES: none
*****************************************************************************/
* DESCRIPTION: Interrupt service routine for UART Receiver
* RETURN: nothing
* NOTES: none
*****************************************************************************/
ISR(USART0_RX_vect)
{
uint8_t data_byte;
@@ -158,19 +152,18 @@ ISR(USART0_RX_vect)
#ifdef MSTP_MONITOR
UDR1 = data_byte;
#endif
(void) FIFO_Put(&Receive_Buffer, data_byte);
(void)FIFO_Put(&Receive_Buffer, data_byte);
}
}
/****************************************************************************
* DESCRIPTION: Checks for data on the receive UART, and handles errors
* RETURN: none
* NOTES: none
*****************************************************************************/
bool rs485_byte_available(
uint8_t * data_register)
* DESCRIPTION: Checks for data on the receive UART, and handles errors
* RETURN: none
* NOTES: none
*****************************************************************************/
bool rs485_byte_available(uint8_t *data_register)
{
bool data_available = false; /* return value */
bool data_available = false; /* return value */
if (!FIFO_Empty(&Receive_Buffer)) {
led_on_interval(LED_4, 1);
@@ -184,25 +177,23 @@ bool rs485_byte_available(
}
/****************************************************************************
* DESCRIPTION: returns an error indication if errors are enabled
* RETURN: nothing
* NOTES: none
*****************************************************************************/
bool rs485_receive_error(
void)
* DESCRIPTION: returns an error indication if errors are enabled
* RETURN: nothing
* NOTES: none
*****************************************************************************/
bool rs485_receive_error(void)
{
return false;
}
/****************************************************************************
* DESCRIPTION: Transmits a frame using the UART
* RETURN: none
* NOTES: none
*****************************************************************************/
void rs485_bytes_send(
uint8_t * buffer, /* data to send */
* DESCRIPTION: Transmits a frame using the UART
* RETURN: none
* NOTES: none
*****************************************************************************/
void rs485_bytes_send(uint8_t *buffer, /* data to send */
uint16_t nbytes)
{ /* number of bytes of data */
{ /* number of bytes of data */
led_on(LED_5);
while (!BIT_CHECK(UCSR0A, UDRE0)) {
/* do nothing - wait until Tx buffer is empty */
@@ -233,23 +224,21 @@ void rs485_bytes_send(
}
/****************************************************************************
* DESCRIPTION: Returns the baud rate that we are currently running at
* RETURN: baud rate in bps
* NOTES: none
*****************************************************************************/
uint32_t rs485_baud_rate(
void)
* DESCRIPTION: Returns the baud rate that we are currently running at
* RETURN: baud rate in bps
* NOTES: none
*****************************************************************************/
uint32_t rs485_baud_rate(void)
{
return Baud_Rate;
}
/****************************************************************************
* DESCRIPTION: configure the UART baud rate
* RETURN: nothing
* NOTES: none
*****************************************************************************/
static void rs485_baud_rate_configure(
void)
* DESCRIPTION: configure the UART baud rate
* RETURN: nothing
* NOTES: none
*****************************************************************************/
static void rs485_baud_rate_configure(void)
{
/* 2x speed mode */
BIT_SET(UCSR0A, U2X0);
@@ -258,12 +247,11 @@ static void rs485_baud_rate_configure(
}
/****************************************************************************
* DESCRIPTION: set the UART baud rate to a standard value
* RETURN: true if the baud rate is valid
* NOTES: none
*****************************************************************************/
bool rs485_baud_rate_set(
uint32_t baud)
* DESCRIPTION: set the UART baud rate to a standard value
* RETURN: true if the baud rate is valid
* NOTES: none
*****************************************************************************/
bool rs485_baud_rate_set(uint32_t baud)
{
bool valid = true;
uint8_t baud_k = 0;
@@ -290,12 +278,11 @@ bool rs485_baud_rate_set(
}
/****************************************************************************
* DESCRIPTION: initialize the hardware UART
* RETURN: nothing
* NOTES: none
*****************************************************************************/
static void rs485_usart_init(
void)
* DESCRIPTION: initialize the hardware UART
* RETURN: nothing
* NOTES: none
*****************************************************************************/
static void rs485_usart_init(void)
{
/* enable the internal pullup on RXD0 */
BIT_CLEAR(DDRD, DDD0);
@@ -314,12 +301,11 @@ static void rs485_usart_init(
}
/****************************************************************************
* DESCRIPTION: read any non-volatile data
* RETURN: nothing
* NOTES: none
*****************************************************************************/
static void rs485_init_nvdata(
void)
* DESCRIPTION: read any non-volatile data
* RETURN: nothing
* NOTES: none
*****************************************************************************/
static void rs485_init_nvdata(void)
{
uint8_t baud_k = 9; /* from EEPROM value */
@@ -354,15 +340,14 @@ static void rs485_init_nvdata(
}
/****************************************************************************
* DESCRIPTION: initialize the module
* RETURN: nothing
* NOTES: none
*****************************************************************************/
void rs485_init(
void)
* DESCRIPTION: initialize the module
* RETURN: nothing
* NOTES: none
*****************************************************************************/
void rs485_init(void)
{
FIFO_Init(&Receive_Buffer, &Receive_Buffer_Data[0],
(unsigned) sizeof(Receive_Buffer_Data));
(unsigned)sizeof(Receive_Buffer_Data));
rs485_silence_time_reset();
rs485_rts_init();
rs485_usart_init();