|
ICARUS OS (Intelligent Cooperative Architecture for Real-time Unified Systems) 0.1.0
Preemptive Real-Time Operating System for ARM Cortex-M7
|
Background Checksum integrity monitor implementation. More...
Go to the source code of this file.
Data Structures | |
| struct | cs_entry_t |
| Per-region entry in the monitor table. More... | |
Macros | |
| #define | CS_SELFTEST_EXPECTED 0x29B1u |
| Known CRC16-CCITT test vector. | |
Functions | |
| static bool | cs_selftest (void) |
| Run the CRC engine self-test against a known vector. | |
| void | __cs_init (void) |
| Privileged implementation of cs_init(). | |
| void | __cs_set_callback (cs_mismatch_fn fn) |
| Privileged implementation of cs_set_callback(). | |
| bool | __cs_add_region (uint8_t idx, const uint8_t *addr, uint32_t size) |
| Privileged implementation of cs_add_region(). | |
| bool | __cs_enable (uint8_t idx, bool enabled) |
| Privileged implementation of cs_enable(). | |
| bool | __cs_rebaseline (uint8_t idx) |
| Privileged implementation of cs_rebaseline(). | |
| uint8_t | __cs_check_all (void) |
| Privileged implementation of cs_check_all(). | |
| bool | __cs_get_region (uint8_t idx, cs_region_t *out) |
| Privileged implementation of cs_get_region(). | |
| uint8_t | __cs_region_count (void) |
| Privileged implementation of cs_region_count(). | |
Variables | |
| static cs_entry_t | regions [8] |
| Region table — privileged DTCM, zero wait-state. | |
| static cs_mismatch_fn | mismatch_cb |
| User-supplied mismatch callback. | |
| static bool | cs_hw_ok |
| CRC engine self-test result. | |
Background Checksum integrity monitor implementation.
Maintains a table of up to CS_MAX_REGIONS memory regions, each with a baseline CRC16-CCITT. cs_check_all() recomputes the CRC over each enabled region and invokes the mismatch callback on any discrepancy.
CRC computation uses crc16_ccitt() from icarus/crc.h, which runs on the STM32H7 hardware CRC peripheral on target and falls back to a software loop under HOST_TEST.
cs_init() performs a self-test of the CRC engine against a known test vector ("123456789" → 0x29B1 for CRC16-CCITT). If the self-test fails (e.g. HW CRC peripheral damaged by radiation), the cs_hw_ok flag is cleared and cs_check_all() reports region index 0xFF via the mismatch callback to signal a CRC engine failure.
Definition in file cs.c.
| #define CS_SELFTEST_EXPECTED 0x29B1u |
| bool __cs_add_region | ( | uint8_t | idx, |
| const uint8_t * | addr, | ||
| uint32_t | size | ||
| ) |
Privileged implementation of cs_add_region().
| [in] | idx | Region index. |
| [in] | addr | Start address. |
| [in] | size | Size in bytes. |
| true | Region registered and baseline CRC computed. |
| false | Invalid parameters. |
Computes the baseline CRC immediately from the current memory contents using crc16_ccitt() (HW-accelerated on target, software fallback under HOST_TEST).
Definition at line 118 of file cs.c.
References cs_entry_t::addr, cs_entry_t::baseline, crc16_ccitt(), CS_MAX_REGIONS, cs_entry_t::enabled, regions, cs_entry_t::registered, and cs_entry_t::size.
Referenced by cs_add_region(), and SVC_Handler_C().
| uint8_t __cs_check_all | ( | void | ) |
Privileged implementation of cs_check_all().
First checks cs_hw_ok; if the CRC engine itself is suspect, invokes the callback with region_idx = 0xFF (sentinel) and returns 1 without scanning any regions.
Otherwise iterates all enabled regions, recomputes CRC, and invokes the callback for each mismatch.
Definition at line 172 of file cs.c.
References crc16_ccitt(), cs_hw_ok, CS_MAX_REGIONS, cs_entry_t::enabled, mismatch_cb, and regions.
Referenced by cs_check_all(), and SVC_Handler_C().
| bool __cs_enable | ( | uint8_t | idx, |
| bool | enabled | ||
| ) |
Privileged implementation of cs_enable().
| [in] | idx | Region index. |
| [in] | enabled | Enable/disable flag. |
Definition at line 137 of file cs.c.
References CS_MAX_REGIONS, cs_entry_t::enabled, and regions.
Referenced by cs_enable(), and SVC_Handler_C().
| bool __cs_get_region | ( | uint8_t | idx, |
| cs_region_t * | out | ||
| ) |
Privileged implementation of cs_get_region().
| [in] | idx | Region index. |
| [out] | out | Destination descriptor. |
Definition at line 204 of file cs.c.
References cs_region_t::addr, cs_entry_t::addr, cs_region_t::baseline, cs_entry_t::baseline, CS_MAX_REGIONS, cs_region_t::enabled, cs_entry_t::enabled, regions, cs_region_t::size, and cs_entry_t::size.
Referenced by cs_get_region(), and SVC_Handler_C().
| void __cs_init | ( | void | ) |
Privileged implementation of cs_init().
Clears all regions, runs the CRC self-test, and stores the result in cs_hw_ok.
Definition at line 91 of file cs.c.
References cs_hw_ok, cs_selftest(), mismatch_cb, and regions.
Referenced by cs_init(), and SVC_Handler_C().
| bool __cs_rebaseline | ( | uint8_t | idx | ) |
Privileged implementation of cs_rebaseline().
| [in] | idx | Region index. |
Recomputes the CRC from current memory and stores it as the new baseline. Call after a legitimate write to a monitored region.
Definition at line 152 of file cs.c.
References cs_entry_t::baseline, crc16_ccitt(), CS_MAX_REGIONS, and regions.
Referenced by cs_rebaseline(), and SVC_Handler_C().
| uint8_t __cs_region_count | ( | void | ) |
Privileged implementation of cs_region_count().
Definition at line 222 of file cs.c.
References CS_MAX_REGIONS, and regions.
Referenced by cs_region_count(), and SVC_Handler_C().
| void __cs_set_callback | ( | cs_mismatch_fn | fn | ) |
Privileged implementation of cs_set_callback().
| [in] | fn | Mismatch callback, or NULL to disable. |
Definition at line 101 of file cs.c.
References mismatch_cb.
Referenced by cs_set_callback(), and SVC_Handler_C().
|
static |
Run the CRC engine self-test against a known vector.
| true | CRC engine produces the expected result. |
| false | CRC engine is damaged or misconfigured. |
Definition at line 76 of file cs.c.
References crc16_ccitt(), and CS_SELFTEST_EXPECTED.
Referenced by __cs_init().
|
static |
CRC engine self-test result.
False if HW CRC is suspect.
Definition at line 59 of file cs.c.
Referenced by __cs_check_all(), and __cs_init().
|
static |
User-supplied mismatch callback.
Definition at line 56 of file cs.c.
Referenced by __cs_check_all(), __cs_init(), and __cs_set_callback().
|
static |
Region table — privileged DTCM, zero wait-state.
Definition at line 53 of file cs.c.
Referenced by __cs_add_region(), __cs_check_all(), __cs_enable(), __cs_get_region(), __cs_init(), __cs_rebaseline(), and __cs_region_count().