SatNOGS-COMMS  4.1.0
A COMMS subsystem for CubeSats
Loading...
Searching...
No Matches
memory_monitor.hpp
Go to the documentation of this file.
1/*
2 * SatNOGS-COMMS MCU software
3 *
4 * Copyright (C) 2025, Libre Space Foundation <http://libre.space>
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 *
19 * SPDX-License-Identifier: GNU General Public License v3.0 or later
20 */
21
22#pragma once
23
24#include "settings.hpp"
26#include <zephyr/device.h>
27#include <zephyr/drivers/flash.h>
28#include <zephyr/kernel.h>
29#include <zephyr/storage/flash_map.h>
30#include <zephyr/sys/atomic.h>
31#include <zephyr/sys/util.h>
32
33namespace satnogs::comms
34{
36{
37public:
38 static memory_monitor &
40 {
41 static memory_monitor instance;
42 return instance;
43 }
44
45 /* Singleton */
46 memory_monitor(memory_monitor const &) = delete;
47
48 void
49 operator=(memory_monitor const &) = delete;
50
51 void
52 start(int32_t delay = CONFIG_FLASH_MONITOR_BURST_DELAY_SECS);
53
54 void
55 stop();
56
57 static void
58 flash_monitor_hdlr(struct k_work *work);
59
60private:
61 atomic_t m_running;
62 int32_t m_burst_delay_ms;
63 off_t m_scan_off;
64 size_t m_flash_size;
65 off_t m_flash_offset;
66
68};
69
71{
72public:
73 flash_init_exception(const char *file_name, int line)
74 : exception(
75 exception::severity::CRITICAL, file_name, line,
76 error_msg{"Error in FLASH initialization", "flashinit", EFLASHINIT})
77 {
78 }
79};
80
82{
83public:
84 flash_read_exception(const char *file_name, int line)
85 : exception(exception::severity::CRITICAL, file_name, line,
86 error_msg{"Unrecoverable double-bit ECC or other flash fault",
87 "flashfault", EFLASHREAD})
88 {
89 }
90};
91
92} // namespace satnogs::comms
flash_init_exception(const char *file_name, int line)
flash_read_exception(const char *file_name, int line)
A class representing error messages in the SatNOGS-COMMS system.
Definition exception.hpp:83
Exception base class.
Definition exception.hpp:63
severity
Severity levels of exceptions.
Definition exception.hpp:71
@ CRITICAL
Failure causing mission degradation or significant damage.
Definition exception.hpp:73
exception(severity sev, const char *file, int lineno, const error_msg &err_msg)
Constructor for the exception class.
void start(int32_t delay=CONFIG_FLASH_MONITOR_BURST_DELAY_SECS)
Start the flash-monitor task.
static memory_monitor & get_instance()
static void flash_monitor_hdlr(struct k_work *work)
Work-queue handler that scans the active firmware image for unrecoverable flash ECC errors.
memory_monitor(memory_monitor const &)=delete
void stop()
Stop the flash-monitor task.
void operator=(memory_monitor const &)=delete
#define EFLASHREAD
Error in FLASH reading (ECC error / Uncorrectable double error).
#define EFLASHINIT
Error in FLASH initialization.