IoT Supervisor 0.0
Loading...
Searching...
No Matches
Configuration State Machine

The configuration state machine starts and maintains the system configuration. More...

Data Structures

struct  cfg_t
 This struct is a storage type for flash memory. More...
 

Macros

#define C_FLASH_CONF   (0x1E00)
 
#define pFLASH_CONF   ((uint8_t code*)C_FLASH_CONF)
 
#define C_PW_DEFAULT   (0xDEFA)
 
#define C_FOUND_PROG_END   (0x12A9)
 
#define C_CFG_HEADER_LEN   (sizeof(ex_cfg_header))
 
#define C_CFG_DATA_LEN   (sizeof(cfg_t))
 
#define C_CFG_C_CRC_LEN   (2)
 
#define C_CFG_P_CRC_LEN   (2)
 
#define C_CFG_DATA_END   (C_CFG_HEADER_LEN + C_CFG_DATA_LEN)
 
#define C_CFG_C_CRC_END   (C_CFG_DATA_END + C_CFG_C_CRC_LEN)
 
#define C_CFG_P_CRC_END   (C_CFG_C_CRC_END + C_CFG_P_CRC_LEN)
 
#define C_CMD_COMMIT   0x5FAF
 
#define C_CMD_CANCEL   0x0000
 
#define C_SID_MIN   1
 
#define C_SID_MAX   247
 

Enumerations

enum  VerifSt_t { eVS_Norm = 0 , eVS_Cfg , eVS_Prog , eVS_Setup }
 
enum  CfgSM_t {
  eCFG_Idle = 0 , eCFG_Load , eCFG_Cache , eCFG_Commit ,
  eCFG_Erase , eCFG_Write
}
 

Functions

bool ccfg_check (void)
 
bool dcfg_check ()
 
void cfg_load ()
 
void cfg_write (void)
 
void CFGsm ()
 

Variables

code const uint8_t ex_cfg_header []
 
code const cfg_t default_cfg
 
CfgSM_t cfgSmS = eCFG_Load
 
bool pw_flag = false
 
bool dir_tx = false
 
bool run_petitmodbus = false
 
uint16_t pw
 
cfg_t cfg
 
uint8_t cfg_write_idx = 0
 
uint16_t calc_cfg_crc = 0xFFFF
 
uint16_t calc_prog_crc = 0xFFFF
 

Detailed Description

The configuration state machine starts and maintains the system configuration.

stateDiagram-v2 direction LR [*] --> Load Load --> Idle Idle --> Cache: Correct Password Cache --> Commit: Commit CMD Cache --> Idle: Cancel CMD Commit --> Erase: Correct Password Commit --> Idle: Cancel CMD Erase --> Write Write --> [*]
The configuration state machine implements the startup and configuration tasks of this application. On startup, the configuration is read from memory and the program memory is checked against a stored CRC. On configuration commit, a cached configuration from modbus is applied to the application. On configuration write, the committed configuration is written into flash along with the newly calculated CRC.

Macro Definition Documentation

◆ C_CFG_C_CRC_END

#define C_CFG_C_CRC_END   (C_CFG_DATA_END + C_CFG_C_CRC_LEN)

End of configuration CRC offset in configuration page.

Definition at line 448 of file IoT Supervisor_main.c.

◆ C_CFG_C_CRC_LEN

#define C_CFG_C_CRC_LEN   (2)

configuration CRC length (16 bits)

Definition at line 438 of file IoT Supervisor_main.c.

◆ C_CFG_DATA_END

#define C_CFG_DATA_END   (C_CFG_HEADER_LEN + C_CFG_DATA_LEN)

End of configuration data offset in configuration page.

Definition at line 444 of file IoT Supervisor_main.c.

◆ C_CFG_DATA_LEN

#define C_CFG_DATA_LEN   (sizeof(cfg_t))

Configuration data length

The password is stored in two bytes.

Definition at line 436 of file IoT Supervisor_main.c.

◆ C_CFG_HEADER_LEN

#define C_CFG_HEADER_LEN   (sizeof(ex_cfg_header))

Configuration header length

Definition at line 417 of file IoT Supervisor_main.c.

◆ C_CFG_P_CRC_END

#define C_CFG_P_CRC_END   (C_CFG_C_CRC_END + C_CFG_P_CRC_LEN)

End of program CRC offset in configuration page. Total configuration length.

Definition at line 453 of file IoT Supervisor_main.c.

◆ C_CFG_P_CRC_LEN

#define C_CFG_P_CRC_LEN   (2)

program CRC length (16 bits)

Definition at line 440 of file IoT Supervisor_main.c.

◆ C_CMD_CANCEL

#define C_CMD_CANCEL   0x0000

Definition at line 29 of file IoT_Supervisor.h.

◆ C_CMD_COMMIT

#define C_CMD_COMMIT   0x5FAF

Definition at line 28 of file IoT_Supervisor.h.

◆ C_FLASH_CONF

#define C_FLASH_CONF   (0x1E00)

Configuration page start address in program memory (code memory).

Definition at line 382 of file IoT Supervisor_main.c.

◆ C_FOUND_PROG_END

#define C_FOUND_PROG_END   (0x12A9)

Definition at line 398 of file IoT Supervisor_main.c.

◆ C_PW_DEFAULT

#define C_PW_DEFAULT   (0xDEFA)

The default password used to enter configuration cache or configuration page erase and write.

Definition at line 389 of file IoT Supervisor_main.c.

◆ C_SID_MAX

#define C_SID_MAX   247

Definition at line 31 of file IoT_Supervisor.h.

◆ C_SID_MIN

#define C_SID_MIN   1

Definition at line 30 of file IoT_Supervisor.h.

◆ pFLASH_CONF

#define pFLASH_CONF   ((uint8_t code*)C_FLASH_CONF)

Pointer to the flash config

Definition at line 384 of file IoT Supervisor_main.c.

Enumeration Type Documentation

◆ CfgSM_t

enum CfgSM_t

Configuration Memory State Machine _ Type

Configuration Memory State Machine _ Type

Enumerator
eCFG_Idle 

Idle State. No configuration state machine activity.

eCFG_Load 

Configuration Loading from memory.

eCFG_Cache 

New Configuration is Caching from Modbus.

eCFG_Commit 

New Configuration is Committed (Active)

eCFG_Erase 

Erase the old Configuration (from Flash)

eCFG_Write 

Write the new Configuration (into Flash)

Definition at line 122 of file IoT_Supervisor.h.

◆ VerifSt_t

enum VerifSt_t

Verification Status _ Type

Verification Status _ Type

Enumerator
eVS_Norm 

Normal Verification Status

No configuration errors or program memory CRC mismatch detected. eVS_Norm

eVS_Cfg 

Configuration Error or CRC Mismatch Detected.

eVS_Prog 

Program Memory Mismatch Detected.

eVS_Setup 

Initial Setup.

Definition at line 103 of file IoT_Supervisor.h.

Function Documentation

◆ ccfg_check()

bool ccfg_check ( void  )

This function performs the code memory configuration checks. It first checks if the values from memory are in-range and then checks if the CRC against the value stored in code memory.

Returns
the validity of the code memory configuration. true if okay.

Definition at line 472 of file IoT Supervisor_main.c.

◆ cfg_load()

void cfg_load ( )

This function performs the tasks in the configuration load state in the configuration state machine. This includes loading the configuration from code memory and checking the CRC of program memory.

flowchart LR subgraph Configuration Flash Section ex_cfg_header subgraph cfg_t sid baud wdto password end c_crc("Configuration CRC") p_crc("Program CRC") end

The verification status is set based on greater than logic. If code memory lacks the correct configuration header, the verification status is "Setup." If the program memory CRC does not match what is stored in the configuration, the verification status is "Program [invalid]." If code memory is invalid or deemed corrupted by an incorrect CRC, the verification status is "Configuration [invalid]."

Definition at line 602 of file IoT Supervisor_main.c.

◆ cfg_write()

void cfg_write ( void  )

This function writes the data memory configuration into code memory. It also calculates the CRC so that later reads can determine the integrity of the configuration data.

Definition at line 663 of file IoT Supervisor_main.c.

◆ CFGsm()

void CFGsm ( )

This function implements the configuration state machine which controls various parts of the supervisor's behavior. It controls the modbus sid, modbus baud rate, watchdog timer, and configuration memory password.

The configuration state machine locks the modbus master out of reading or writing the configuration memory if the state machine is not put into either cache or commit state.

Caches or commits can be escaped from if the modbus user does not want to write data to code memory.

Definition at line 711 of file IoT Supervisor_main.c.

◆ dcfg_check()

bool dcfg_check ( )

This function checks the configuration stored in data memory. It does not perform a CRC.

Returns
the validity of the configuration. true if okay.

Definition at line 561 of file IoT Supervisor_main.c.

Variable Documentation

◆ calc_cfg_crc

uint16_t calc_cfg_crc = 0xFFFF

Definition at line 462 of file IoT Supervisor_main.c.

◆ calc_prog_crc

uint16_t calc_prog_crc = 0xFFFF

Definition at line 463 of file IoT Supervisor_main.c.

◆ cfg

cfg_t cfg

entered password, not necessarily the correct password

Definition at line 460 of file IoT Supervisor_main.c.

◆ cfg_write_idx

uint8_t cfg_write_idx = 0

Definition at line 461 of file IoT Supervisor_main.c.

◆ cfgSmS

CfgSM_t cfgSmS = eCFG_Load

Definition at line 455 of file IoT Supervisor_main.c.

◆ default_cfg

code const cfg_t default_cfg
Initial value:
=
{
255,
}
#define C_PW_DEFAULT
@ eMMW_B_38400
#define C_DEFAULT_MB_WD_TIMEOUT

Stores the default configuration data.

Note
The default modbus sid is 255 because this sid is specifically reserved for devices that have not been configured yet.

Definition at line 424 of file IoT Supervisor_main.c.

◆ dir_tx

bool dir_tx = false

Definition at line 457 of file IoT Supervisor_main.c.

◆ ex_cfg_header

code const uint8_t ex_cfg_header[]
Initial value:
=
{
'M','A','G',
'S','V',
'0',
'0',
'0'
}

Stores the header of the configuration page in FLASH

This is the expected configuration header.

Definition at line 408 of file IoT Supervisor_main.c.

◆ pw

uint16_t pw

Definition at line 459 of file IoT Supervisor_main.c.

◆ pw_flag

bool pw_flag = false

Definition at line 456 of file IoT Supervisor_main.c.

◆ run_petitmodbus

bool run_petitmodbus = false

Definition at line 458 of file IoT Supervisor_main.c.