Feature/add memap cstack usage ports (#661)

* Added memap, avstack, and checkstackusage tools to STM32F4xx Makefile and CMake builds to calculate CSTACK depth and RAM usage

* Added memap, cstack, and ram-usage recipes to stm32f10x port Makefile.  Added Cmake build.

* Removed local dlmstp.c module from stm32f10x port, and used the common datalink dlmstp.c module with MS/TP extended frames and zero-config support.

* Added .nm and .su to .gitignore to skip the analysis file residue.
This commit is contained in:
Steve Karg
2024-05-31 14:39:25 -05:00
committed by GitHub
parent cf7eb7d98d
commit 4a7b7763c2
32 changed files with 3855 additions and 1974 deletions
+95 -118
View File
@@ -45,70 +45,35 @@ static FIFO_BUFFER Receive_Buffer;
static struct mstimer Silence_Timer;
/* baud rate */
static uint32_t Baud_Rate = 38400;
/* flag to track RTS status */
static volatile bool Transmitting;
/* The minimum time after the end of the stop bit of the final octet of a */
/* received frame before a node may enable its EIA-485 driver: 40 bit times. */
/* At 9600 baud, 40 bit times would be about 4.166 milliseconds */
/* At 19200 baud, 40 bit times would be about 2.083 milliseconds */
/* At 38400 baud, 40 bit times would be about 1.041 milliseconds */
/* At 57600 baud, 40 bit times would be about 0.694 milliseconds */
/* 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)
/* statistics */
static volatile uint32_t RS485_Transmit_Bytes;
static volatile uint32_t RS485_Receive_Bytes;
/*************************************************************************
* Description: Reset the silence on the wire timer.
* Returns: nothing
* Notes: none
**************************************************************************/
/**
* @brief Reset the silence on the wire timer.
*/
void rs485_silence_reset(void)
{
mstimer_set(&Silence_Timer, 0);
}
/*************************************************************************
* Description: Determine the amount of silence on the wire from the timer.
* Returns: true if the amount of time has elapsed
* Notes: none
**************************************************************************/
bool rs485_silence_elapsed(uint32_t interval)
/**
* @brief Return the RS-485 silence time in milliseconds
* @return silence time in milliseconds
*/
uint32_t rs485_silence_milliseconds(void)
{
return (mstimer_elapsed(&Silence_Timer) > interval);
return mstimer_elapsed(&Silence_Timer);
}
/*************************************************************************
* Description: Baud rate determines turnaround time.
* Returns: amount of milliseconds
* Notes: none
**************************************************************************/
static uint16_t rs485_turnaround_time(void)
{
/* delay after reception before transmitting - per MS/TP spec */
/* wait a minimum 40 bit times since reception */
/* at least 2 ms for errors: rounding, clock tick */
if (Baud_Rate) {
return (2 + ((Tturnaround * 1000UL) / Baud_Rate));
} else {
return 2;
}
}
/*************************************************************************
* Description: Use the silence timer to determine turnaround time.
* Returns: true if turnaround time has expired.
* Notes: none
**************************************************************************/
bool rs485_turnaround_elapsed(void)
{
return (mstimer_elapsed(&Silence_Timer) > rs485_turnaround_time());
}
/*************************************************************************
* Description: Determines if an error occured while receiving
* Returns: true an error occurred.
* Notes: none
**************************************************************************/
/**
* @brief Determines if an error occured while receiving
* @return true an error occurred
*/
bool rs485_receive_error(void)
{
return false;
@@ -125,6 +90,7 @@ void USART2_IRQHandler(void)
/* Read one byte from the receive data register */
data_byte = USART_ReceiveData(USART2);
(void)FIFO_Put(&Receive_Buffer, data_byte);
RS485_Receive_Bytes++;
}
if (USART_GetFlagStatus(USART2, USART_FLAG_ORE) != RESET) {
/* note: enabling RXNE interrupt also enables the ORE interrupt! */
@@ -134,11 +100,35 @@ void USART2_IRQHandler(void)
}
}
/*************************************************************************
* DESCRIPTION: Return true if a byte is available
* RETURN: true if a byte is available, with the byte in the parameter
* NOTES: none
**************************************************************************/
/**
* @brief Control the DE and /RE pins on the RS-485 transceiver
* @param enable - true to set DE and /RE high, false to set /DE and RE low
*/
void rs485_rts_enable(bool enable)
{
if (enable) {
led_tx_on_interval(10);
GPIO_WriteBit(GPIOA, GPIO_Pin_1, Bit_SET);
} else {
GPIO_WriteBit(GPIOA, GPIO_Pin_1, Bit_RESET);
}
}
/**
* @brief Determine the status of the transmit-enable line on the RS-485
* transceiver
* @return true if RTS is enabled, false if RTS is disabled
*/
bool rs485_rts_enabled(void)
{
return Transmitting;
}
/**
* @brief Return true if a byte is available
* @param data_register - byte in this parameter if there is one available
* @return true if a byte is available, with the byte in the parameter
*/
bool rs485_byte_available(uint8_t *data_register)
{
bool data_available = false; /* return value */
@@ -155,50 +145,37 @@ bool rs485_byte_available(uint8_t *data_register)
return data_available;
}
/*************************************************************************
* DESCRIPTION: Sends a byte of data
* RETURN: nothing
* NOTES: none
**************************************************************************/
void rs485_byte_send(uint8_t tx_byte)
{
led_tx_on_interval(10);
USART_SendData(USART2, tx_byte);
rs485_silence_reset();
}
/*************************************************************************
* Description: Determines if a byte in the USART has been shifted from
* register
* Returns: true if the USART register is empty
* Notes: none
**************************************************************************/
/**
* @brief Determines if a byte in the USART has been shifted from register
* @return true if the USART register is empty
*/
bool rs485_byte_sent(void)
{
return USART_GetFlagStatus(USART2, USART_FLAG_TXE);
}
/*************************************************************************
* Description: Determines if the entire frame is sent from USART FIFO
* Returns: true if the USART FIFO is empty
* Notes: none
**************************************************************************/
/**
* @brief Determines if the entire frame is sent from USART FIFO
* @brief true if the USART FIFO is empty
*/
bool rs485_frame_sent(void)
{
return USART_GetFlagStatus(USART2, USART_FLAG_TC);
}
/*************************************************************************
* DESCRIPTION: Send some data and wait until it is sent
* RETURN: true if a collision or timeout occurred
* NOTES: none
**************************************************************************/
/**
* @brief Transmit one or more bytes on RS-485.
* @param buffer - array of one or more bytes to transmit
* @param nbytes - number of bytes to transmit
* @return true if added to queue
*/
void rs485_bytes_send(uint8_t *buffer, /* data to send */
uint16_t nbytes)
{ /* number of bytes of data */
uint8_t tx_byte;
while (nbytes) {
rs485_rts_enable(true);
/* Send the data byte */
tx_byte = *buffer;
/* Send one byte */
@@ -208,22 +185,22 @@ void rs485_bytes_send(uint8_t *buffer, /* data to send */
}
buffer++;
nbytes--;
RS485_Transmit_Bytes++;
}
/* was the frame sent? */
while (!rs485_frame_sent()) {
/* do nothing - wait until the entire frame in the
Transmit Shift Register has been shifted out */
}
rs485_rts_enable(false);
rs485_silence_reset();
return;
}
/*************************************************************************
* Description: Configures the baud rate of the USART
* Returns: nothing
* Notes: none
**************************************************************************/
/**
* @brief Configures the baud rate of the USART
*/
static void rs485_baud_rate_configure(void)
{
USART_InitTypeDef USART_InitStructure;
@@ -240,11 +217,10 @@ static void rs485_baud_rate_configure(void)
USART_Init(USART2, &USART_InitStructure);
}
/*************************************************************************
* Description: Sets the baud rate to non-volatile storeage and configures USART
* Returns: true if a value baud rate was saved
* Notes: none
**************************************************************************/
/**
* @brief Sets the baud rate to non-volatile storeage and configures USART
* @return true if a value baud rate was saved
*/
bool rs485_baud_rate_set(uint32_t baud)
{
bool valid = true;
@@ -267,35 +243,36 @@ bool rs485_baud_rate_set(uint32_t baud)
return valid;
}
/*************************************************************************
* Description: Determines the baud rate in bps
* Returns: baud rate in bps
* Notes: none
**************************************************************************/
/**
* @brief Return the RS-485 baud rate
* @return baud - RS-485 baud rate in bits per second (bps)
*/
uint32_t rs485_baud_rate(void)
{
return Baud_Rate;
}
/*************************************************************************
* Description: Enable the Request To Send (RTS) aka Transmit Enable pin
* Returns: nothing
* Notes: none
**************************************************************************/
void rs485_rts_enable(bool enable)
/**
* @brief Return the RS-485 statistics for transmit bytes
* @return number of bytes transmitted
*/
uint32_t rs485_bytes_transmitted(void)
{
if (enable) {
GPIO_WriteBit(GPIOA, GPIO_Pin_1, Bit_SET);
} else {
GPIO_WriteBit(GPIOA, GPIO_Pin_1, Bit_RESET);
}
return RS485_Transmit_Bytes;
}
/*************************************************************************
* Description: Initialize the room network USART
* Returns: nothing
* Notes: none
**************************************************************************/
/**
* @brief Return the RS-485 statistics for receive bytes
* @return number of bytes received
*/
uint32_t rs485_bytes_received(void)
{
return RS485_Receive_Bytes;
}
/**
* @brief Initialize the room network USART
*/
void rs485_init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;