kopia lustrzana https://github.com/SP8EBC/ParaTNC
bufix stm32f100: do not read a content of DR register in IDLE state handler within irq handler, callback and pooling callback for KISS_GET_RUNNING_CONFIG
rodzic
9b6f8013ac
commit
641db9ce1e
|
@ -16,8 +16,8 @@ extern const int __config_section_second_crc;
|
|||
extern const uint16_t * config_data_pgm_cntr_first_ptr;
|
||||
extern const uint16_t * config_data_pgm_cntr_second_ptr;
|
||||
|
||||
#define config_data_pgm_cntr_first *(config_data_pgm_cntr_first_ptr)
|
||||
#define config_data_pgm_cntr_second *(config_data_pgm_cntr_second_ptr)
|
||||
extern const uint16_t config_data_pgm_cntr_first;
|
||||
extern const uint16_t config_data_pgm_cntr_second;
|
||||
|
||||
extern const config_data_mode_t * config_data_mode_first_ptr;
|
||||
extern const config_data_basic_t * config_data_basic_first_ptr;
|
||||
|
@ -32,6 +32,9 @@ extern const config_data_umb_t * config_data_umb_second_ptr;
|
|||
extern const config_data_rtu_t * config_data_rtu_second_ptr;
|
||||
|
||||
#ifdef PARAMETEO
|
||||
#define config_data_pgm_cntr_first *(config_data_pgm_cntr_first_ptr)
|
||||
#define config_data_pgm_cntr_second *(config_data_pgm_cntr_second_ptr)
|
||||
|
||||
extern const config_data_gsm_t * config_data_gsm_first_ptr;
|
||||
extern const config_data_gsm_t * config_data_gsm_second_ptr;
|
||||
extern const config_data_gsm_t * config_data_gsm_default_ptr;
|
||||
|
|
|
@ -28,5 +28,6 @@ void configuration_set_bits_register(uint32_t value);
|
|||
void configuration_clear_bits_register(uint32_t value);
|
||||
|
||||
configuration_handler_region_t configuration_get_current(uint32_t * size);
|
||||
const uint32_t * configuration_get_address(configuration_handler_region_t region);
|
||||
|
||||
#endif /* CONFIGURATION_HANDLER_H_ */
|
||||
|
|
|
@ -6,6 +6,6 @@
|
|||
#include <stdint.h>
|
||||
|
||||
int32_t kiss_callback_get_running_config(uint8_t* input_frame_from_host, uint16_t input_len, uint8_t* response_buffer, uint16_t buffer_size);
|
||||
int16_t kiss_pool_callback_get_running_config(uint8_t * output_buffer, uint16_t buffer_size, uint8_t current_segment );
|
||||
int16_t kiss_pool_callback_get_running_config(uint8_t * output_buffer, uint16_t buffer_size );
|
||||
|
||||
#endif
|
||||
|
|
|
@ -18,7 +18,7 @@ _estack = __stack; /* STM specific definition */
|
|||
* for the different modes.
|
||||
*/
|
||||
|
||||
__Main_Stack_Size = 333 ;
|
||||
__Main_Stack_Size = 512 ;
|
||||
|
||||
PROVIDE ( _Main_Stack_Size = __Main_Stack_Size ) ;
|
||||
|
||||
|
@ -32,7 +32,7 @@ PROVIDE ( _Main_Stack_Limit = __Main_Stack_Limit ) ;
|
|||
* There will be a link error if there is not this amount of
|
||||
* RAM free at the end.
|
||||
*/
|
||||
_Minimum_Stack_Size = 333 ;
|
||||
_Minimum_Stack_Size = 512 ;
|
||||
|
||||
/*
|
||||
* Default heap definitions.
|
||||
|
|
|
@ -78,8 +78,8 @@ const config_data_gsm_t * config_data_gsm_default_ptr = (const config_data_gsm_t
|
|||
#endif
|
||||
|
||||
#ifdef STM32F10X_MD_VL
|
||||
const uint16_t * config_data_pgm_cntr_first_ptr = &config_data_pgm_cntr_first_ptr;
|
||||
const uint16_t * config_data_pgm_cntr_second_ptr = &config_data_pgm_cntr_second_ptr;
|
||||
const uint16_t * config_data_pgm_cntr_first_ptr = &config_data_pgm_cntr_first;
|
||||
const uint16_t * config_data_pgm_cntr_second_ptr = &config_data_pgm_cntr_second;
|
||||
|
||||
const config_data_mode_t * config_data_mode_first_ptr = &config_data_mode_first;
|
||||
const config_data_basic_t * config_data_basic_first_ptr = &config_data_basic_first;
|
||||
|
@ -777,3 +777,17 @@ configuration_handler_region_t configuration_get_current(uint32_t * size) {
|
|||
return configuration_handler_loaded;
|
||||
}
|
||||
|
||||
const uint32_t * configuration_get_address(configuration_handler_region_t region) {
|
||||
switch (region) {
|
||||
case REGION_FIRST:
|
||||
return config_section_first_start;
|
||||
break;
|
||||
case REGION_SECOND:
|
||||
return config_section_second_start;
|
||||
break;
|
||||
default:
|
||||
return config_section_default_start;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -8,8 +8,17 @@
|
|||
#include "kiss_communication.h"
|
||||
#include "configuration_handler.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#define KISS_MAX_CONFIG_PAYLOAD_SIZE 0x80
|
||||
#define KISS_LAST_ASYNC_MSG 0xFF
|
||||
|
||||
uint8_t kiss_async_message_counter = 0;
|
||||
|
||||
int32_t kiss_callback_get_running_config(uint8_t* input_frame_from_host, uint16_t input_len, uint8_t* response_buffer, uint16_t buffer_size) {
|
||||
|
||||
#define CALLBACK_GET_RUNNING_CFG_LN 6
|
||||
|
||||
uint32_t conf_size = 0;
|
||||
|
||||
configuration_handler_region_t current_region;
|
||||
|
@ -24,20 +33,67 @@ int32_t kiss_callback_get_running_config(uint8_t* input_frame_from_host, uint16_
|
|||
// get currently used configuration and its size in flash memory
|
||||
current_region = configuration_get_current(&conf_size);
|
||||
|
||||
// reset async message counter
|
||||
kiss_async_message_counter = 0;
|
||||
|
||||
// construct a response
|
||||
response_buffer[0] = FEND;
|
||||
response_buffer[1] = KISS_RUNNING_CONFIG;
|
||||
response_buffer[2] = (uint8_t)(current_region & 0xFF);
|
||||
response_buffer[3] = (uint8_t)(conf_size & 0xFF);
|
||||
response_buffer[4] = (uint8_t)((conf_size & 0xFF00) >> 8);
|
||||
response_buffer[5] = (uint8_t)((conf_size & 0xFF0000) >> 16);
|
||||
response_buffer[6] = (uint8_t)((conf_size & 0xFF000000) >> 24);
|
||||
response_buffer[7] = FEND;
|
||||
response_buffer[1] = CALLBACK_GET_RUNNING_CFG_LN; // message lenght
|
||||
response_buffer[2] = KISS_RUNNING_CONFIG;
|
||||
response_buffer[3] = (uint8_t)(current_region & 0xFF);
|
||||
if ((conf_size % KISS_MAX_CONFIG_PAYLOAD_SIZE) == 0)
|
||||
response_buffer[4] = (uint8_t)(conf_size / KISS_MAX_CONFIG_PAYLOAD_SIZE);
|
||||
else
|
||||
response_buffer[4] = (uint8_t)(conf_size / KISS_MAX_CONFIG_PAYLOAD_SIZE + 1);
|
||||
response_buffer[5] = FEND;
|
||||
|
||||
return 8;
|
||||
return CALLBACK_GET_RUNNING_CFG_LN;
|
||||
|
||||
}
|
||||
|
||||
int16_t kiss_pool_callback_get_running_config(uint8_t * output_buffer, uint16_t buffer_size, uint8_t current_segment){
|
||||
int16_t kiss_pool_callback_get_running_config(uint8_t * output_buffer, uint16_t buffer_size){
|
||||
|
||||
uint32_t conf_size = 0, offset = 0;
|
||||
|
||||
configuration_handler_region_t current_region;
|
||||
|
||||
// terminate if no more packets needs to be send
|
||||
if (kiss_async_message_counter == KISS_LAST_ASYNC_MSG) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// get currently used configuration and its size in flash memory
|
||||
current_region = configuration_get_current(&conf_size);
|
||||
|
||||
uint8_t config_payload_size = 0;
|
||||
|
||||
if (kiss_async_message_counter * KISS_MAX_CONFIG_PAYLOAD_SIZE < conf_size) {
|
||||
config_payload_size = KISS_MAX_CONFIG_PAYLOAD_SIZE;
|
||||
|
||||
// offset in source configuration area
|
||||
offset = kiss_async_message_counter * KISS_MAX_CONFIG_PAYLOAD_SIZE;
|
||||
|
||||
kiss_async_message_counter++;
|
||||
}
|
||||
else {
|
||||
config_payload_size = conf_size - (kiss_async_message_counter * KISS_MAX_CONFIG_PAYLOAD_SIZE);
|
||||
|
||||
// offset in source configuration area
|
||||
offset = kiss_async_message_counter * KISS_MAX_CONFIG_PAYLOAD_SIZE;
|
||||
|
||||
kiss_async_message_counter = KISS_LAST_ASYNC_MSG;
|
||||
}
|
||||
|
||||
// place KISS header
|
||||
output_buffer[0] = FEND;
|
||||
output_buffer[1] = config_payload_size + 4;
|
||||
output_buffer[2] = KISS_RUNNING_CONFIG;
|
||||
output_buffer[3] = 0xAB; // THIS IS A DATA FRAME, not ACK
|
||||
output_buffer[4] = kiss_async_message_counter - 1; // frame sequence number
|
||||
|
||||
memcpy(output_buffer + 5, configuration_get_address(current_region) + offset, config_payload_size);
|
||||
|
||||
output_buffer[config_payload_size + 5] = FEND;
|
||||
|
||||
return config_payload_size + 5;
|
||||
}
|
||||
|
|
|
@ -29,11 +29,6 @@ extern unsigned short tx10m;
|
|||
uint8_t kiss_current_async_message = 0xFF;
|
||||
|
||||
|
||||
/**
|
||||
* This an id of segment of multiframe message, like running config
|
||||
*/
|
||||
uint8_t kiss_current_message_frame_segment = 0;
|
||||
|
||||
uint8_t kiss_async_pooler(uint8_t* output, uint16_t output_len ) {
|
||||
|
||||
int16_t pooling_result = 0;
|
||||
|
@ -45,16 +40,16 @@ uint8_t kiss_async_pooler(uint8_t* output, uint16_t output_len ) {
|
|||
}
|
||||
|
||||
switch(kiss_current_async_message) {
|
||||
case KISS_RUNNING_CONFIG:
|
||||
pooling_result = kiss_pool_callback_get_running_config(output, output_len, kiss_current_message_frame_segment);
|
||||
case KISS_RUNNING_CONFIG:
|
||||
pooling_result = kiss_pool_callback_get_running_config(output, output_len);
|
||||
|
||||
break;
|
||||
break;
|
||||
}
|
||||
|
||||
// positive return value means that there is something to transmit to host
|
||||
// and the value itself points how big the response is
|
||||
if (pooling_result > 0) {
|
||||
|
||||
out = pooling_result;
|
||||
}
|
||||
else if (pooling_result == 0) {
|
||||
// if result equals to zero it means that there is nothing more to send
|
||||
|
@ -170,8 +165,6 @@ int32_t kiss_parse_received(uint8_t* input_frame_from_host, uint16_t input_len,
|
|||
|
||||
case KISS_GET_RUNNING_CONFIG: {
|
||||
output = kiss_callback_get_running_config(input_frame_from_host, input_len, response_buffer, resp_buf_ln);
|
||||
|
||||
kiss_current_message_frame_segment = 0;
|
||||
} break;
|
||||
|
||||
|
||||
|
|
|
@ -295,6 +295,8 @@ static void dupa(uint16_t http_code, char * content, uint16_t content_lenght) {
|
|||
}
|
||||
}
|
||||
|
||||
//#define SERIAL_TX_TEST_MODE
|
||||
|
||||
int main(int argc, char* argv[]){
|
||||
|
||||
int32_t ln = 0;
|
||||
|
@ -780,7 +782,7 @@ int main(int argc, char* argv[]){
|
|||
// infinite loop for testing UART transmission
|
||||
for (;;) {
|
||||
|
||||
retval = srl_receive_data(main_kiss_srl_ctx_ptr, 100, FEND, FEND, 0, 0, 0);
|
||||
retval = srl_receive_data(main_kiss_srl_ctx_ptr, 100, '\r', '\r', 0, 0, 0);
|
||||
#endif
|
||||
retval = srl_start_tx(main_kiss_srl_ctx_ptr, ln);
|
||||
|
||||
|
@ -1124,7 +1126,7 @@ int main(int argc, char* argv[]){
|
|||
}
|
||||
}
|
||||
|
||||
if (main_kiss_srl_ctx_ptr->srl_tx_state == SRL_TX_IDLE && kiss_current_async_message != 0xFF) {
|
||||
if (kiss_current_async_message != 0xFF && main_kiss_srl_ctx_ptr->srl_tx_state == SRL_TX_IDLE) {
|
||||
srl_start_tx(main_kiss_srl_ctx_ptr, kiss_async_pooler(main_kiss_srl_ctx.srl_tx_buf_pointer, main_kiss_srl_ctx.srl_tx_buf_ln));
|
||||
}
|
||||
|
||||
|
|
|
@ -497,7 +497,7 @@ void srl_irq_handler(srl_context_t *ctx) {
|
|||
uint8_t value = 0;
|
||||
|
||||
if ((ctx->port->SR & USART_SR_IDLE) == USART_SR_IDLE) {
|
||||
ctx->srl_garbage_storage = (uint8_t)ctx->port->DR;
|
||||
//ctx->srl_garbage_storage = (uint8_t)ctx->port->DR;
|
||||
|
||||
ctx->total_idle_counter++;
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue