From: Nathael Pajani Date: Thu, 31 Oct 2024 13:28:06 +0000 (+0100) Subject: Improve communication with extentions X-Git-Url: http://git.techno-innov.fr/?a=commitdiff_plain;h=b71f51d1c5880fa78ccebb8338c7c13ab55b1f0a;p=soft%2Flpc122x%2Fscialys Improve communication with extentions --- diff --git a/v10/comm.c b/v10/comm.c index 8c2b7a8..ad64205 100644 --- a/v10/comm.c +++ b/v10/comm.c @@ -38,11 +38,12 @@ #include "data.h" -/***************************************************************************** */ -/* USB Uart */ +/***************************************************************************** */ volatile uint8_t usb_logs = 0; -volatile uint8_t usb_send_config = 0; +/* Start with a "request" to send actual config and version */ +volatile uint8_t send_config = 2; +volatile uint8_t send_info = 2; enum comm_states { Idle = 0, /* Waiting for next command */ @@ -50,22 +51,23 @@ enum comm_states { Config, /* Received config command, receiving configuration */ }; -/* Rx interrupt handler for system configuration over USB */ -void config_rx(uint8_t c) -{ - static uint8_t comm_state = 0; - if (comm_state == Command) { +/***************************************************************************** */ +/* Rx command handling */ +/* Note that this is an interrupt handler, do NEVER try to send a reply in here */ +void command_handler(uint8_t c, uint8_t* comm_state, uint8_t uart) +{ + if (*comm_state == Command) { /* Handle command value */ - comm_state = Idle; + *comm_state = Idle; return; } - if (comm_state == Config) { + if (*comm_state == Config) { /* Receive new config */ /* Check received config checksum */ /* If config received, burn to flash and reset */ - comm_state = Idle; + *comm_state = Idle; return; } @@ -87,20 +89,34 @@ void config_rx(uint8_t c) break; /* Enter command mode */ case 'a': - comm_state = Command; + *comm_state = Command; break; /* Enter config mode */ case 'C': - comm_state = Config; + *comm_state = Config; break; /* Get config */ case 'g': - usb_send_config = 1; + send_config = (1 + uart); + break; + /* Get module info */ + case 'i': + send_info = (1 + uart); break; default: } } +/***************************************************************************** */ +/* USB Uart */ + +/* Rx interrupt handler for system configuration over USB */ +void config_rx(uint8_t c) +{ + static uint8_t usb_comm_state = 0; + command_handler(c, &usb_comm_state, UART0); +} + /***************************************************************************** */ /* Communication with slave modules over UART1 */ @@ -108,6 +124,8 @@ void config_rx(uint8_t c) /* Rx interrupt handler */ void comm_rx(uint8_t c) { + static uint8_t ext_comm_state = 0; + command_handler(c, &ext_comm_state, UART1); } diff --git a/v10/comm.h b/v10/comm.h index 6053cd3..c62712f 100644 --- a/v10/comm.h +++ b/v10/comm.h @@ -26,7 +26,12 @@ /***************************************************************************** */ extern volatile uint8_t usb_logs; -extern volatile uint8_t usb_send_config; +extern volatile uint8_t send_config; +extern volatile uint8_t send_info; + + +/***************************************************************************** */ +/* Communication over UART0 to USB bridge */ /* Rx interrupt handler for system configuration over USB */ void config_rx(uint8_t c); @@ -35,11 +40,9 @@ void config_rx(uint8_t c); /***************************************************************************** */ /* Communication with slave modules over UART1 */ - /* Rx interrupt handler */ void comm_rx(uint8_t c); - void comm_tx(struct scialys_data* data); diff --git a/v10/config.h b/v10/config.h index 4fdb31c..fe18e89 100644 --- a/v10/config.h +++ b/v10/config.h @@ -91,7 +91,7 @@ * manual_force_type : * type of termination condition for manual force mode (temp, time, both (first)) * never_force : - * + * if set to 1, prevent entering manual and automatic forced modes */ #define CONFIG_OK 0x4F4B /* "OK" in ASCII */ #define CONFIG_VERSION 0x02 diff --git a/v10/interface.c b/v10/interface.c index 15cc293..c9aed9a 100644 --- a/v10/interface.c +++ b/v10/interface.c @@ -41,6 +41,7 @@ #include "version.h" #include "time.h" #include "param.h" +#include "comm.h" /***************************************************************************** */ /* Buttons inputs on front panel */ @@ -284,6 +285,10 @@ void interface_update(char heat_mode) } else { /* Config mode. Mode entered by button action, which implies that interface board is present. */ interface_mode = config_interface_handle(); + if (interface_mode == MODE_RUN) { + /* Exiting config mode : send new config to external communication module */ + send_config = 2; + } } /* Update Oled display */ ssd130x_display_full_screen(&display); diff --git a/v10/main.c b/v10/main.c index fb77a13..dd98650 100644 --- a/v10/main.c +++ b/v10/main.c @@ -30,6 +30,7 @@ #include "data.h" #include "comm.h" #include "uSD.h" +#include "version.h" #define MODULE_VERSION 0x0A @@ -716,11 +717,30 @@ int main(void) msg = NULL; } } - if (usb_send_config == 1) { + if (send_config != 0) { char* conf = (char*)&sc_conf; - serial_write(UART0, "@", 1); - serial_write(UART0, conf, sizeof(struct scialys_config)); - usb_send_config = 0; + uint32_t uart_num = UART0; + if (send_config == 2) { /* Send on UART 1 (communication to extention module) */ + uart_num = UART1; + } + serial_write(uart_num, "@", 1); + serial_write(uart_num, conf, sizeof(struct scialys_config)); + send_config = 0; + } + if (send_info != 0) { + #define VERSION_BUF_LEN 16 + char version[VERSION_BUF_LEN] = "& " MODULE_VERSION_STR "-" SOFT_VERSION_STR "." COMPILE_VERSION; + uint32_t uart_num = UART0; + uint8_t i = 0, sum = 0; + if (send_info == 2) { /* Send on UART 1 (communication to extention module) */ + uart_num = UART1; + } + for (i = 2; i < VERSION_BUF_LEN; i++) { + sum += (uint8_t)version[i]; + } + version[1] = (char)sum; + serial_write(uart_num, version, VERSION_BUF_LEN); + send_info = 0; } } return 0; diff --git a/v10/version.h b/v10/version.h index 3d07556..cf136ab 100644 --- a/v10/version.h +++ b/v10/version.h @@ -1,3 +1,3 @@ -#define MODULE_VERSION_STR "v1.0" -#define SOFT_VERSION_STR "P" -#define COMPILE_VERSION "04" +#define MODULE_VERSION_STR "v1.0" /* Can be up to 5 chars : "v1.01" */ +#define SOFT_VERSION_STR "T" /* One letter : P : Production - T : Test */ +#define COMPILE_VERSION "06" /* Two digits */