SatNOGS-COMMS
4.1.0
A COMMS subsystem for CubeSats
Toggle main menu visibility
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
"
25
#include <
satnogs-comms-lib/exception.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
33
namespace
satnogs::comms
34
{
35
class
memory_monitor
36
{
37
public
:
38
static
memory_monitor
&
39
get_instance
()
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
60
private
:
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
67
memory_monitor
();
68
};
69
70
class
flash_init_exception
:
public
lib::exception
71
{
72
public
:
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
81
class
flash_read_exception
:
public
lib::exception
82
{
83
public
:
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
satnogs::comms::flash_init_exception::flash_init_exception
flash_init_exception(const char *file_name, int line)
Definition
memory_monitor.hpp:73
satnogs::comms::flash_read_exception::flash_read_exception
flash_read_exception(const char *file_name, int line)
Definition
memory_monitor.hpp:84
satnogs::comms::lib::exception::error_msg
A class representing error messages in the SatNOGS-COMMS system.
Definition
exception.hpp:83
satnogs::comms::lib::exception
Exception base class.
Definition
exception.hpp:63
satnogs::comms::lib::exception::severity
severity
Severity levels of exceptions.
Definition
exception.hpp:71
satnogs::comms::lib::exception::severity::CRITICAL
@ CRITICAL
Failure causing mission degradation or significant damage.
Definition
exception.hpp:73
satnogs::comms::lib::exception::exception
exception(severity sev, const char *file, int lineno, const error_msg &err_msg)
Constructor for the exception class.
Definition
exception.hpp:102
satnogs::comms::memory_monitor::start
void start(int32_t delay=CONFIG_FLASH_MONITOR_BURST_DELAY_SECS)
Start the flash-monitor task.
Definition
memory_monitor.cpp:53
satnogs::comms::memory_monitor::get_instance
static memory_monitor & get_instance()
Definition
memory_monitor.hpp:39
satnogs::comms::memory_monitor::flash_monitor_hdlr
static void flash_monitor_hdlr(struct k_work *work)
Work-queue handler that scans the active firmware image for unrecoverable flash ECC errors.
Definition
memory_monitor.cpp:117
satnogs::comms::memory_monitor::memory_monitor
memory_monitor(memory_monitor const &)=delete
satnogs::comms::memory_monitor::stop
void stop()
Stop the flash-monitor task.
Definition
memory_monitor.cpp:73
satnogs::comms::memory_monitor::operator=
void operator=(memory_monitor const &)=delete
EFLASHREAD
#define EFLASHREAD
Error in FLASH reading (ECC error / Uncorrectable double error).
Definition
errno_extended.hpp:62
EFLASHINIT
#define EFLASHINIT
Error in FLASH initialization.
Definition
errno_extended.hpp:61
exception.hpp
satnogs::comms
Definition
bsp.cpp:28
settings.hpp
src
memory_monitor.hpp
Generated by
1.17.0