updated STM32F3 RTICv2 example
This commit is contained in:
@@ -5,7 +5,7 @@ members = [
|
|||||||
"satrs-mib",
|
"satrs-mib",
|
||||||
"satrs-example",
|
"satrs-example",
|
||||||
"satrs-minisim",
|
"satrs-minisim",
|
||||||
"satrs-shared",
|
"satrs-shared", "embedded-examples/embedded-client",
|
||||||
]
|
]
|
||||||
|
|
||||||
exclude = [
|
exclude = [
|
||||||
|
|||||||
17
embedded-examples/embedded-client/Cargo.toml
Normal file
17
embedded-examples/embedded-client/Cargo.toml
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
[package]
|
||||||
|
name = "embedded-client"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2024"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
clap = { version = "4", features = ["derive"] }
|
||||||
|
serialport = "4"
|
||||||
|
toml = "0.9"
|
||||||
|
serde = { version = "1", features = ["derive"] }
|
||||||
|
satrs-stm32f3-disco-rtic = { path = "../stm32f3-disco-rtic" }
|
||||||
|
spacepackets = { git = "https://egit.irs.uni-stuttgart.de/rust/spacepackets.git", version = "0.17" }
|
||||||
|
postcard = { version = "1", features = ["alloc"] }
|
||||||
|
cobs = "0.5"
|
||||||
|
fern = "0.7"
|
||||||
|
humantime = "2"
|
||||||
|
log = "0.4"
|
||||||
2
embedded-examples/embedded-client/config.toml
Normal file
2
embedded-examples/embedded-client/config.toml
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
[interface]
|
||||||
|
serial_port = "/dev/ttyUSB0"
|
||||||
126
embedded-examples/embedded-client/src/main.rs
Normal file
126
embedded-examples/embedded-client/src/main.rs
Normal file
@@ -0,0 +1,126 @@
|
|||||||
|
use std::{
|
||||||
|
fs::File,
|
||||||
|
io::Read,
|
||||||
|
path::Path,
|
||||||
|
time::{Duration, SystemTime},
|
||||||
|
};
|
||||||
|
|
||||||
|
use clap::Parser;
|
||||||
|
use cobs::CobsDecoderOwned;
|
||||||
|
use satrs_stm32f3_disco_rtic::Request;
|
||||||
|
use spacepackets::{CcsdsPacketCreator, CcsdsPacketReader, SpHeader};
|
||||||
|
|
||||||
|
#[derive(Parser, Debug)]
|
||||||
|
struct Cli {
|
||||||
|
#[arg(short, long)]
|
||||||
|
ping: bool,
|
||||||
|
|
||||||
|
/// Set frequency in milliseconds.
|
||||||
|
#[arg(short, long)]
|
||||||
|
set_led_frequency: Option<u32>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, serde::Deserialize)]
|
||||||
|
struct Config {
|
||||||
|
interface: Interface,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, serde::Deserialize)]
|
||||||
|
struct Interface {
|
||||||
|
serial_port: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn setup_logger() -> Result<(), fern::InitError> {
|
||||||
|
fern::Dispatch::new()
|
||||||
|
.format(|out, message, record| {
|
||||||
|
out.finish(format_args!(
|
||||||
|
"[{} {} {}] {}",
|
||||||
|
humantime::format_rfc3339_seconds(SystemTime::now()),
|
||||||
|
record.level(),
|
||||||
|
record.target(),
|
||||||
|
message
|
||||||
|
))
|
||||||
|
})
|
||||||
|
.level(log::LevelFilter::Debug)
|
||||||
|
.chain(std::io::stdout())
|
||||||
|
.chain(fern::log_file("output.log")?)
|
||||||
|
.apply()?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
setup_logger().expect("failed to initialize logger");
|
||||||
|
println!("sat-rs embedded examples TMTC client");
|
||||||
|
|
||||||
|
let cli = Cli::parse();
|
||||||
|
let mut config_file =
|
||||||
|
File::open(Path::new("config.toml")).expect("opening config.toml file failed");
|
||||||
|
let mut toml_str = String::new();
|
||||||
|
config_file
|
||||||
|
.read_to_string(&mut toml_str)
|
||||||
|
.expect("reading config.toml file failed");
|
||||||
|
let config: Config = toml::from_str(&toml_str).expect("parsing config.toml file failed");
|
||||||
|
println!("Connecting to serial port {}", config.interface.serial_port);
|
||||||
|
|
||||||
|
let mut serial = serialport::new(config.interface.serial_port, 115200)
|
||||||
|
.open()
|
||||||
|
.expect("opening serial port failed");
|
||||||
|
|
||||||
|
if cli.ping {
|
||||||
|
let request = Request::Ping;
|
||||||
|
let tc_encoded_raw = create_stm32f3_tc(&request);
|
||||||
|
log::info!("Sending ping request");
|
||||||
|
serial.write_all(&tc_encoded_raw).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(freq_ms) = cli.set_led_frequency {
|
||||||
|
let request = Request::ChangeBlinkFrequency(Duration::from_millis(freq_ms as u64));
|
||||||
|
let tc_encoded_raw = create_stm32f3_tc(&request);
|
||||||
|
log::info!("Sending change blink frequency request: {:?}", request);
|
||||||
|
serial.write_all(&tc_encoded_raw).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut cobs_decoder = CobsDecoderOwned::new(1024);
|
||||||
|
log::info!("Waiting for response...");
|
||||||
|
loop {
|
||||||
|
let mut reception_buffer = [0u8; 1024];
|
||||||
|
let received_bytes = serial.read(&mut reception_buffer);
|
||||||
|
match received_bytes {
|
||||||
|
Ok(0) => {
|
||||||
|
std::thread::sleep(std::time::Duration::from_millis(100));
|
||||||
|
}
|
||||||
|
Ok(n) => {
|
||||||
|
for byte in &reception_buffer[..n] {
|
||||||
|
match cobs_decoder.feed(*byte) {
|
||||||
|
Ok(Some(packet_len)) => {
|
||||||
|
let reader = CcsdsPacketReader::new_with_checksum(
|
||||||
|
&cobs_decoder.dest()[0..packet_len],
|
||||||
|
);
|
||||||
|
log::debug!("Received packet: {:?}", reader);
|
||||||
|
}
|
||||||
|
Ok(None) => (),
|
||||||
|
Err(e) => {
|
||||||
|
log::error!("COBS decoding error {e}, resetting decoder");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
if e.kind() != std::io::ErrorKind::TimedOut
|
||||||
|
&& e.kind() != std::io::ErrorKind::WouldBlock
|
||||||
|
{
|
||||||
|
log::error!("Error reading from serial port: {:?}", e);
|
||||||
|
}
|
||||||
|
std::thread::sleep(std::time::Duration::from_millis(100));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn create_stm32f3_tc(request: &Request) -> Vec<u8> {
|
||||||
|
let req_raw = postcard::to_allocvec(&request).unwrap();
|
||||||
|
let sp_header = SpHeader::new_from_apid(satrs_stm32f3_disco_rtic::APID);
|
||||||
|
let ccsds_tc_packet = CcsdsPacketCreator::new_tc_with_checksum(sp_header, &req_raw).unwrap();
|
||||||
|
let tc_raw = ccsds_tc_packet.to_vec();
|
||||||
|
cobs::encode_vec_including_sentinels(&tc_raw)
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
/target
|
/target
|
||||||
/itm.txt
|
/itm.txt
|
||||||
/.cargo/config*
|
/.cargo/config.toml
|
||||||
/.vscode
|
/.vscode
|
||||||
|
|||||||
1212
embedded-examples/stm32f3-disco-rtic/Cargo.lock
generated
1212
embedded-examples/stm32f3-disco-rtic/Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -9,49 +9,33 @@ default-run = "satrs-stm32f3-disco-rtic"
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
cortex-m = { version = "0.7", features = ["critical-section-single-core"] }
|
cortex-m = { version = "0.7", features = ["critical-section-single-core"] }
|
||||||
cortex-m-rt = "0.7"
|
cortex-m-rt = "0.7"
|
||||||
defmt = "0.3"
|
defmt = "1"
|
||||||
defmt-brtt = { version = "0.1", default-features = false, features = ["rtt"] }
|
defmt-rtt = { version = "1" }
|
||||||
panic-probe = { version = "0.3", features = ["print-defmt"] }
|
panic-probe = { version = "1", features = ["print-defmt"] }
|
||||||
embedded-hal = "0.2.7"
|
embedded-hal = "1"
|
||||||
cortex-m-semihosting = "0.5.0"
|
cortex-m-semihosting = "0.5.0"
|
||||||
|
embassy-stm32 = { version = "0.4", features = ["defmt", "stm32f303vc", "unstable-pac"] }
|
||||||
enumset = "1"
|
enumset = "1"
|
||||||
heapless = "0.8"
|
heapless = "0.9"
|
||||||
|
spacepackets = { version = "0.17", git = "https://egit.irs.uni-stuttgart.de/rust/spacepackets.git", default-features = false, features = ["defmt", "serde"] }
|
||||||
|
static_cell = "2"
|
||||||
|
cobs = { version = "0.5", default-features = false, features = ["defmt"] }
|
||||||
|
postcard = { version = "1" }
|
||||||
|
arbitrary-int = "2"
|
||||||
|
thiserror = { version = "2", default-features = false }
|
||||||
|
serde = { version = "1", default-features = false, features = ["derive"] }
|
||||||
|
|
||||||
[dependencies.rtic]
|
rtic = { version = "2", features = ["thumbv7-backend"] }
|
||||||
version = "2"
|
rtic-sync = { version = "1" }
|
||||||
features = ["thumbv7-backend"]
|
rtic-monotonics = { version = "2", features = ["cortex-m-systick"] }
|
||||||
|
|
||||||
[dependencies.rtic-monotonics]
|
#[dependencies.satrs]
|
||||||
version = "2"
|
# path = "../../satrs"
|
||||||
features = ["cortex-m-systick"]
|
#default-features = false
|
||||||
|
# features = ["defmt"]
|
||||||
[dependencies.cobs]
|
|
||||||
version = "0.3"
|
|
||||||
default-features = false
|
|
||||||
|
|
||||||
[dependencies.stm32f3xx-hal]
|
|
||||||
git = "https://github.com/robamu/stm32f3xx-hal"
|
|
||||||
version = "0.11.0-alpha.0"
|
|
||||||
features = ["stm32f303xc", "rt", "enumset"]
|
|
||||||
branch = "complete-dma-update"
|
|
||||||
# Can be used in workspace to develop and update HAL
|
|
||||||
# path = "../stm32f3xx-hal"
|
|
||||||
|
|
||||||
[dependencies.stm32f3-discovery]
|
|
||||||
git = "https://github.com/robamu/stm32f3-discovery"
|
|
||||||
version = "0.8.0-alpha.0"
|
|
||||||
branch = "complete-dma-update-hal"
|
|
||||||
# Can be used in workspace to develop and update BSP
|
|
||||||
# path = "../stm32f3-discovery"
|
|
||||||
|
|
||||||
[dependencies.satrs]
|
|
||||||
# path = "satrs"
|
|
||||||
version = "0.2"
|
|
||||||
default-features = false
|
|
||||||
features = ["defmt"]
|
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
defmt-test = "0.3"
|
defmt-test = "0.4"
|
||||||
|
|
||||||
# cargo test
|
# cargo test
|
||||||
[profile.test]
|
[profile.test]
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -1,10 +0,0 @@
|
|||||||
target extended-remote localhost:2331
|
|
||||||
|
|
||||||
monitor reset
|
|
||||||
|
|
||||||
# *try* to stop at the user entry point (it might be gone due to inlining)
|
|
||||||
break main
|
|
||||||
|
|
||||||
load
|
|
||||||
|
|
||||||
continue
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
# Sample OpenOCD configuration for the STM32F3DISCOVERY development board
|
|
||||||
|
|
||||||
# Depending on the hardware revision you got you'll have to pick ONE of these
|
|
||||||
# interfaces. At any time only one interface should be commented out.
|
|
||||||
|
|
||||||
# Revision C (newer revision)
|
|
||||||
source [find interface/stlink.cfg]
|
|
||||||
|
|
||||||
# Revision A and B (older revisions)
|
|
||||||
# source [find interface/stlink-v2.cfg]
|
|
||||||
|
|
||||||
source [find target/stm32f3x.cfg]
|
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
target extended-remote :3333
|
|
||||||
|
|
||||||
# print demangled symbols
|
|
||||||
set print asm-demangle on
|
|
||||||
|
|
||||||
# set backtrace limit to not have infinite backtrace loops
|
|
||||||
set backtrace limit 32
|
|
||||||
|
|
||||||
# detect unhandled exceptions, hard faults and panics
|
|
||||||
break DefaultHandler
|
|
||||||
break HardFault
|
|
||||||
break rust_begin_unwind
|
|
||||||
# # run the next few lines so the panic message is printed immediately
|
|
||||||
# # the number needs to be adjusted for your panic handler
|
|
||||||
# commands $bpnum
|
|
||||||
# next 4
|
|
||||||
# end
|
|
||||||
|
|
||||||
# *try* to stop at the user entry point (it might be gone due to inlining)
|
|
||||||
break main
|
|
||||||
|
|
||||||
# monitor arm semihosting enable
|
|
||||||
|
|
||||||
# # send captured ITM to the file itm.fifo
|
|
||||||
# # (the microcontroller SWO pin must be connected to the programmer SWO pin)
|
|
||||||
# # 8000000 must match the core clock frequency
|
|
||||||
# # 2000000 is the frequency of the SWO pin. This was added for newer
|
|
||||||
# openocd versions like v0.12.0.
|
|
||||||
# monitor tpiu config internal itm.txt uart off 8000000 2000000
|
|
||||||
|
|
||||||
# # OR: make the microcontroller SWO pin output compatible with UART (8N1)
|
|
||||||
# # 8000000 must match the core clock frequency
|
|
||||||
# # 2000000 is the frequency of the SWO pin
|
|
||||||
# monitor tpiu config external uart off 8000000 2000000
|
|
||||||
|
|
||||||
# # enable ITM port 0
|
|
||||||
# monitor itm port 0 on
|
|
||||||
|
|
||||||
load
|
|
||||||
|
|
||||||
# start the process but immediately halt the processor
|
|
||||||
stepi
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
/venv
|
|
||||||
/.tmtc-history.txt
|
|
||||||
/log
|
|
||||||
/.idea/*
|
|
||||||
!/.idea/runConfigurations
|
|
||||||
|
|
||||||
/seqcnt.txt
|
|
||||||
/tmtc_conf.json
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
{
|
|
||||||
"com_if": "serial_cobs",
|
|
||||||
"serial_baudrate": 115200
|
|
||||||
}
|
|
||||||
@@ -1,305 +0,0 @@
|
|||||||
#!/usr/bin/env python3
|
|
||||||
"""Example client for the sat-rs example application"""
|
|
||||||
import struct
|
|
||||||
import logging
|
|
||||||
import sys
|
|
||||||
import time
|
|
||||||
from typing import Any, Optional, cast
|
|
||||||
from prompt_toolkit.history import FileHistory, History
|
|
||||||
from spacepackets.ecss.tm import CdsShortTimestamp
|
|
||||||
|
|
||||||
import tmtccmd
|
|
||||||
from spacepackets.ecss import PusTelemetry, PusTelecommand, PusTm, PusVerificator
|
|
||||||
from spacepackets.ecss.pus_17_test import Service17Tm
|
|
||||||
from spacepackets.ecss.pus_1_verification import UnpackParams, Service1Tm
|
|
||||||
|
|
||||||
from tmtccmd import TcHandlerBase, ProcedureParamsWrapper
|
|
||||||
from tmtccmd.core.base import BackendRequest
|
|
||||||
from tmtccmd.core.ccsds_backend import QueueWrapper
|
|
||||||
from tmtccmd.logging import add_colorlog_console_logger
|
|
||||||
from tmtccmd.pus import VerificationWrapper
|
|
||||||
from tmtccmd.tmtc import CcsdsTmHandler, SpecificApidHandlerBase
|
|
||||||
from tmtccmd.com import ComInterface
|
|
||||||
from tmtccmd.config import (
|
|
||||||
CmdTreeNode,
|
|
||||||
default_json_path,
|
|
||||||
SetupParams,
|
|
||||||
HookBase,
|
|
||||||
params_to_procedure_conversion,
|
|
||||||
)
|
|
||||||
from tmtccmd.config.com import SerialCfgWrapper
|
|
||||||
from tmtccmd.config import PreArgsParsingWrapper, SetupWrapper
|
|
||||||
from tmtccmd.logging.pus import (
|
|
||||||
RegularTmtcLogWrapper,
|
|
||||||
RawTmtcTimedLogWrapper,
|
|
||||||
TimedLogWhen,
|
|
||||||
)
|
|
||||||
from tmtccmd.tmtc import (
|
|
||||||
TcQueueEntryType,
|
|
||||||
ProcedureWrapper,
|
|
||||||
TcProcedureType,
|
|
||||||
FeedWrapper,
|
|
||||||
SendCbParams,
|
|
||||||
DefaultPusQueueHelper,
|
|
||||||
)
|
|
||||||
from tmtccmd.pus.s5_fsfw_event import Service5Tm
|
|
||||||
from spacepackets.seqcount import FileSeqCountProvider, PusFileSeqCountProvider
|
|
||||||
from tmtccmd.util.obj_id import ObjectIdDictT
|
|
||||||
|
|
||||||
_LOGGER = logging.getLogger()
|
|
||||||
|
|
||||||
EXAMPLE_PUS_APID = 0x02
|
|
||||||
|
|
||||||
|
|
||||||
class SatRsConfigHook(HookBase):
|
|
||||||
def __init__(self, json_cfg_path: str):
|
|
||||||
super().__init__(json_cfg_path)
|
|
||||||
|
|
||||||
def get_communication_interface(self, com_if_key: str) -> Optional[ComInterface]:
|
|
||||||
from tmtccmd.config.com import (
|
|
||||||
create_com_interface_default,
|
|
||||||
create_com_interface_cfg_default,
|
|
||||||
)
|
|
||||||
|
|
||||||
assert self.cfg_path is not None
|
|
||||||
cfg = create_com_interface_cfg_default(
|
|
||||||
com_if_key=com_if_key,
|
|
||||||
json_cfg_path=self.cfg_path,
|
|
||||||
space_packet_ids=None,
|
|
||||||
)
|
|
||||||
if cfg is None:
|
|
||||||
raise ValueError(
|
|
||||||
f"No valid configuration could be retrieved for the COM IF with key {com_if_key}"
|
|
||||||
)
|
|
||||||
if cfg.com_if_key == "serial_cobs":
|
|
||||||
cfg = cast(SerialCfgWrapper, cfg)
|
|
||||||
cfg.serial_cfg.serial_timeout = 0.5
|
|
||||||
return create_com_interface_default(cfg)
|
|
||||||
|
|
||||||
def get_command_definitions(self) -> CmdTreeNode:
|
|
||||||
"""This function should return the root node of the command definition tree."""
|
|
||||||
return create_cmd_definition_tree()
|
|
||||||
|
|
||||||
def get_cmd_history(self) -> Optional[History]:
|
|
||||||
"""Optionlly return a history class for the past command paths which will be used
|
|
||||||
when prompting a command path from the user in CLI mode."""
|
|
||||||
return FileHistory(".tmtc-history.txt")
|
|
||||||
|
|
||||||
def get_object_ids(self) -> ObjectIdDictT:
|
|
||||||
from tmtccmd.config.objects import get_core_object_ids
|
|
||||||
|
|
||||||
return get_core_object_ids()
|
|
||||||
|
|
||||||
|
|
||||||
def create_cmd_definition_tree() -> CmdTreeNode:
|
|
||||||
root_node = CmdTreeNode.root_node()
|
|
||||||
root_node.add_child(CmdTreeNode("ping", "Send PUS ping TC"))
|
|
||||||
root_node.add_child(CmdTreeNode("change_blink_freq", "Change blink frequency"))
|
|
||||||
return root_node
|
|
||||||
|
|
||||||
|
|
||||||
class PusHandler(SpecificApidHandlerBase):
|
|
||||||
def __init__(
|
|
||||||
self,
|
|
||||||
file_logger: logging.Logger,
|
|
||||||
verif_wrapper: VerificationWrapper,
|
|
||||||
raw_logger: RawTmtcTimedLogWrapper,
|
|
||||||
):
|
|
||||||
super().__init__(EXAMPLE_PUS_APID, None)
|
|
||||||
self.file_logger = file_logger
|
|
||||||
self.raw_logger = raw_logger
|
|
||||||
self.verif_wrapper = verif_wrapper
|
|
||||||
|
|
||||||
def handle_tm(self, packet: bytes, _user_args: Any):
|
|
||||||
try:
|
|
||||||
pus_tm = PusTm.unpack(
|
|
||||||
packet, timestamp_len=CdsShortTimestamp.TIMESTAMP_SIZE
|
|
||||||
)
|
|
||||||
except ValueError as e:
|
|
||||||
_LOGGER.warning("Could not generate PUS TM object from raw data")
|
|
||||||
_LOGGER.warning(f"Raw Packet: [{packet.hex(sep=',')}], REPR: {packet!r}")
|
|
||||||
raise e
|
|
||||||
service = pus_tm.service
|
|
||||||
tm_packet = None
|
|
||||||
if service == 1:
|
|
||||||
tm_packet = Service1Tm.unpack(
|
|
||||||
data=packet, params=UnpackParams(CdsShortTimestamp.TIMESTAMP_SIZE, 1, 2)
|
|
||||||
)
|
|
||||||
res = self.verif_wrapper.add_tm(tm_packet)
|
|
||||||
if res is None:
|
|
||||||
_LOGGER.info(
|
|
||||||
f"Received Verification TM[{tm_packet.service}, {tm_packet.subservice}] "
|
|
||||||
f"with Request ID {tm_packet.tc_req_id.as_u32():#08x}"
|
|
||||||
)
|
|
||||||
_LOGGER.warning(
|
|
||||||
f"No matching telecommand found for {tm_packet.tc_req_id}"
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
self.verif_wrapper.log_to_console(tm_packet, res)
|
|
||||||
self.verif_wrapper.log_to_file(tm_packet, res)
|
|
||||||
if service == 3:
|
|
||||||
_LOGGER.info("No handling for HK packets implemented")
|
|
||||||
_LOGGER.info(f"Raw packet: 0x[{packet.hex(sep=',')}]")
|
|
||||||
pus_tm = PusTelemetry.unpack(packet, CdsShortTimestamp.TIMESTAMP_SIZE)
|
|
||||||
if pus_tm.subservice == 25:
|
|
||||||
if len(pus_tm.source_data) < 8:
|
|
||||||
raise ValueError("No addressable ID in HK packet")
|
|
||||||
json_str = pus_tm.source_data[8:]
|
|
||||||
_LOGGER.info("received JSON string: " + json_str.decode("utf-8"))
|
|
||||||
if service == 5:
|
|
||||||
tm_packet = Service5Tm.unpack(packet, CdsShortTimestamp.TIMESTAMP_SIZE)
|
|
||||||
if service == 17:
|
|
||||||
tm_packet = Service17Tm.unpack(packet, CdsShortTimestamp.TIMESTAMP_SIZE)
|
|
||||||
if tm_packet.subservice == 2:
|
|
||||||
_LOGGER.info("Received Ping Reply TM[17,2]")
|
|
||||||
else:
|
|
||||||
_LOGGER.info(
|
|
||||||
f"Received Test Packet with unknown subservice {tm_packet.subservice}"
|
|
||||||
)
|
|
||||||
if tm_packet is None:
|
|
||||||
_LOGGER.info(
|
|
||||||
f"The service {service} is not implemented in Telemetry Factory"
|
|
||||||
)
|
|
||||||
tm_packet = PusTelemetry.unpack(packet, CdsShortTimestamp.TIMESTAMP_SIZE)
|
|
||||||
self.raw_logger.log_tm(pus_tm)
|
|
||||||
|
|
||||||
|
|
||||||
def make_addressable_id(target_id: int, unique_id: int) -> bytes:
|
|
||||||
byte_string = bytearray(struct.pack("!I", target_id))
|
|
||||||
byte_string.extend(struct.pack("!I", unique_id))
|
|
||||||
return byte_string
|
|
||||||
|
|
||||||
|
|
||||||
class TcHandler(TcHandlerBase):
|
|
||||||
def __init__(
|
|
||||||
self,
|
|
||||||
seq_count_provider: FileSeqCountProvider,
|
|
||||||
verif_wrapper: VerificationWrapper,
|
|
||||||
):
|
|
||||||
super(TcHandler, self).__init__()
|
|
||||||
self.seq_count_provider = seq_count_provider
|
|
||||||
self.verif_wrapper = verif_wrapper
|
|
||||||
self.queue_helper = DefaultPusQueueHelper(
|
|
||||||
queue_wrapper=QueueWrapper.empty(),
|
|
||||||
tc_sched_timestamp_len=7,
|
|
||||||
seq_cnt_provider=seq_count_provider,
|
|
||||||
pus_verificator=verif_wrapper.pus_verificator,
|
|
||||||
default_pus_apid=EXAMPLE_PUS_APID,
|
|
||||||
)
|
|
||||||
|
|
||||||
def send_cb(self, send_params: SendCbParams):
|
|
||||||
entry_helper = send_params.entry
|
|
||||||
if entry_helper.is_tc:
|
|
||||||
if entry_helper.entry_type == TcQueueEntryType.PUS_TC:
|
|
||||||
pus_tc_wrapper = entry_helper.to_pus_tc_entry()
|
|
||||||
pus_tc_wrapper.pus_tc.seq_count = (
|
|
||||||
self.seq_count_provider.get_and_increment()
|
|
||||||
)
|
|
||||||
self.verif_wrapper.add_tc(pus_tc_wrapper.pus_tc)
|
|
||||||
raw_tc = pus_tc_wrapper.pus_tc.pack()
|
|
||||||
_LOGGER.info(f"Sending {pus_tc_wrapper.pus_tc}")
|
|
||||||
send_params.com_if.send(raw_tc)
|
|
||||||
elif entry_helper.entry_type == TcQueueEntryType.LOG:
|
|
||||||
log_entry = entry_helper.to_log_entry()
|
|
||||||
_LOGGER.info(log_entry.log_str)
|
|
||||||
|
|
||||||
def queue_finished_cb(self, info: ProcedureWrapper):
|
|
||||||
if info.proc_type == TcProcedureType.TREE_COMMANDING:
|
|
||||||
def_proc = info.to_tree_commanding_procedure()
|
|
||||||
_LOGGER.info(f"Queue handling finished for command {def_proc.cmd_path}")
|
|
||||||
|
|
||||||
def feed_cb(self, info: ProcedureWrapper, wrapper: FeedWrapper):
|
|
||||||
q = self.queue_helper
|
|
||||||
q.queue_wrapper = wrapper.queue_wrapper
|
|
||||||
if info.proc_type == TcProcedureType.TREE_COMMANDING:
|
|
||||||
def_proc = info.to_tree_commanding_procedure()
|
|
||||||
cmd_path = def_proc.cmd_path
|
|
||||||
if cmd_path == "/ping":
|
|
||||||
q.add_log_cmd("Sending PUS ping telecommand")
|
|
||||||
q.add_pus_tc(PusTelecommand(service=17, subservice=1))
|
|
||||||
if cmd_path == "/change_blink_freq":
|
|
||||||
self.create_change_blink_freq_command(q)
|
|
||||||
|
|
||||||
def create_change_blink_freq_command(self, q: DefaultPusQueueHelper):
|
|
||||||
q.add_log_cmd("Changing blink frequency")
|
|
||||||
while True:
|
|
||||||
blink_freq = int(
|
|
||||||
input(
|
|
||||||
"Please specify new blink frequency in ms. Valid Range [2..10000]: "
|
|
||||||
)
|
|
||||||
)
|
|
||||||
if blink_freq < 2 or blink_freq > 10000:
|
|
||||||
print(
|
|
||||||
"Invalid blink frequency. Please specify a value between 2 and 10000."
|
|
||||||
)
|
|
||||||
continue
|
|
||||||
break
|
|
||||||
app_data = struct.pack("!I", blink_freq)
|
|
||||||
q.add_pus_tc(PusTelecommand(service=8, subservice=1, app_data=app_data))
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
|
||||||
add_colorlog_console_logger(_LOGGER)
|
|
||||||
tmtccmd.init_printout(False)
|
|
||||||
hook_obj = SatRsConfigHook(json_cfg_path=default_json_path())
|
|
||||||
parser_wrapper = PreArgsParsingWrapper()
|
|
||||||
parser_wrapper.create_default_parent_parser()
|
|
||||||
parser_wrapper.create_default_parser()
|
|
||||||
parser_wrapper.add_def_proc_args()
|
|
||||||
params = SetupParams()
|
|
||||||
post_args_wrapper = parser_wrapper.parse(hook_obj, params)
|
|
||||||
proc_wrapper = ProcedureParamsWrapper()
|
|
||||||
if post_args_wrapper.use_gui:
|
|
||||||
post_args_wrapper.set_params_without_prompts(proc_wrapper)
|
|
||||||
else:
|
|
||||||
post_args_wrapper.set_params_with_prompts(proc_wrapper)
|
|
||||||
params.apid = EXAMPLE_PUS_APID
|
|
||||||
setup_args = SetupWrapper(
|
|
||||||
hook_obj=hook_obj, setup_params=params, proc_param_wrapper=proc_wrapper
|
|
||||||
)
|
|
||||||
# Create console logger helper and file loggers
|
|
||||||
tmtc_logger = RegularTmtcLogWrapper()
|
|
||||||
file_logger = tmtc_logger.logger
|
|
||||||
raw_logger = RawTmtcTimedLogWrapper(when=TimedLogWhen.PER_HOUR, interval=1)
|
|
||||||
verificator = PusVerificator()
|
|
||||||
verification_wrapper = VerificationWrapper(verificator, _LOGGER, file_logger)
|
|
||||||
# Create primary TM handler and add it to the CCSDS Packet Handler
|
|
||||||
tm_handler = PusHandler(file_logger, verification_wrapper, raw_logger)
|
|
||||||
ccsds_handler = CcsdsTmHandler(generic_handler=None)
|
|
||||||
ccsds_handler.add_apid_handler(tm_handler)
|
|
||||||
|
|
||||||
# Create TC handler
|
|
||||||
seq_count_provider = PusFileSeqCountProvider()
|
|
||||||
tc_handler = TcHandler(seq_count_provider, verification_wrapper)
|
|
||||||
tmtccmd.setup(setup_args=setup_args)
|
|
||||||
init_proc = params_to_procedure_conversion(setup_args.proc_param_wrapper)
|
|
||||||
tmtc_backend = tmtccmd.create_default_tmtc_backend(
|
|
||||||
setup_wrapper=setup_args,
|
|
||||||
tm_handler=ccsds_handler,
|
|
||||||
tc_handler=tc_handler,
|
|
||||||
init_procedure=init_proc,
|
|
||||||
)
|
|
||||||
tmtccmd.start(tmtc_backend=tmtc_backend, hook_obj=hook_obj)
|
|
||||||
try:
|
|
||||||
while True:
|
|
||||||
state = tmtc_backend.periodic_op(None)
|
|
||||||
if state.request == BackendRequest.TERMINATION_NO_ERROR:
|
|
||||||
sys.exit(0)
|
|
||||||
elif state.request == BackendRequest.DELAY_IDLE:
|
|
||||||
_LOGGER.info("TMTC Client in IDLE mode")
|
|
||||||
time.sleep(3.0)
|
|
||||||
elif state.request == BackendRequest.DELAY_LISTENER:
|
|
||||||
time.sleep(0.8)
|
|
||||||
elif state.request == BackendRequest.DELAY_CUSTOM:
|
|
||||||
if state.next_delay.total_seconds() <= 0.4:
|
|
||||||
time.sleep(state.next_delay.total_seconds())
|
|
||||||
else:
|
|
||||||
time.sleep(0.4)
|
|
||||||
elif state.request == BackendRequest.CALL_NEXT:
|
|
||||||
pass
|
|
||||||
except KeyboardInterrupt:
|
|
||||||
sys.exit(0)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
main()
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
tmtccmd == 8.0.1
|
|
||||||
# -e git+https://github.com/robamu-org/tmtccmd.git@main#egg=tmtccmd
|
|
||||||
@@ -1,76 +1,61 @@
|
|||||||
#![no_std]
|
|
||||||
#![no_main]
|
#![no_main]
|
||||||
use satrs_stm32f3_disco_rtic as _;
|
#![no_std]
|
||||||
|
|
||||||
use stm32f3_discovery::leds::Leds;
|
use panic_probe as _;
|
||||||
use stm32f3_discovery::stm32f3xx_hal::delay::Delay;
|
use rtic::app;
|
||||||
use stm32f3_discovery::stm32f3xx_hal::{pac, prelude::*};
|
|
||||||
use stm32f3_discovery::switch_hal::{OutputSwitch, ToggleableOutputSwitch};
|
|
||||||
|
|
||||||
#[cortex_m_rt::entry]
|
#[app(device = embassy_stm32)]
|
||||||
fn main() -> ! {
|
mod app {
|
||||||
defmt::println!("STM32F3 Discovery Blinky");
|
use rtic_monotonics::fugit::ExtU32;
|
||||||
let dp = pac::Peripherals::take().unwrap();
|
use rtic_monotonics::Monotonic as _;
|
||||||
let mut rcc = dp.RCC.constrain();
|
use satrs_stm32f3_disco_rtic::{Direction, LedPinSet, Leds};
|
||||||
let cp = cortex_m::Peripherals::take().unwrap();
|
|
||||||
let mut flash = dp.FLASH.constrain();
|
|
||||||
let clocks = rcc.cfgr.freeze(&mut flash.acr);
|
|
||||||
let mut delay = Delay::new(cp.SYST, clocks);
|
|
||||||
|
|
||||||
let mut gpioe = dp.GPIOE.split(&mut rcc.ahb);
|
rtic_monotonics::systick_monotonic!(Mono, 1000);
|
||||||
let mut leds = Leds::new(
|
|
||||||
gpioe.pe8,
|
|
||||||
gpioe.pe9,
|
|
||||||
gpioe.pe10,
|
|
||||||
gpioe.pe11,
|
|
||||||
gpioe.pe12,
|
|
||||||
gpioe.pe13,
|
|
||||||
gpioe.pe14,
|
|
||||||
gpioe.pe15,
|
|
||||||
&mut gpioe.moder,
|
|
||||||
&mut gpioe.otyper,
|
|
||||||
);
|
|
||||||
let delay_ms = 200u16;
|
|
||||||
loop {
|
|
||||||
leds.ld3_n.toggle().ok();
|
|
||||||
delay.delay_ms(delay_ms);
|
|
||||||
leds.ld3_n.toggle().ok();
|
|
||||||
delay.delay_ms(delay_ms);
|
|
||||||
|
|
||||||
//explicit on/off
|
#[shared]
|
||||||
leds.ld4_nw.on().ok();
|
struct Shared {}
|
||||||
delay.delay_ms(delay_ms);
|
|
||||||
leds.ld4_nw.off().ok();
|
|
||||||
delay.delay_ms(delay_ms);
|
|
||||||
|
|
||||||
leds.ld5_ne.on().ok();
|
#[local]
|
||||||
delay.delay_ms(delay_ms);
|
struct Local {
|
||||||
leds.ld5_ne.off().ok();
|
leds: Leds,
|
||||||
delay.delay_ms(delay_ms);
|
current_dir: Direction,
|
||||||
|
}
|
||||||
|
|
||||||
leds.ld6_w.on().ok();
|
#[init]
|
||||||
delay.delay_ms(delay_ms);
|
fn init(cx: init::Context) -> (Shared, Local) {
|
||||||
leds.ld6_w.off().ok();
|
let p = embassy_stm32::init(Default::default());
|
||||||
delay.delay_ms(delay_ms);
|
|
||||||
|
|
||||||
leds.ld7_e.on().ok();
|
defmt::info!("Starting sat-rs demo application for the STM32F3-Discovery using RTICv2");
|
||||||
delay.delay_ms(delay_ms);
|
|
||||||
leds.ld7_e.off().ok();
|
|
||||||
delay.delay_ms(delay_ms);
|
|
||||||
|
|
||||||
leds.ld8_sw.on().ok();
|
let led_pin_set = LedPinSet {
|
||||||
delay.delay_ms(delay_ms);
|
pin_n: p.PE8,
|
||||||
leds.ld8_sw.off().ok();
|
pin_ne: p.PE9,
|
||||||
delay.delay_ms(delay_ms);
|
pin_e: p.PE10,
|
||||||
|
pin_se: p.PE11,
|
||||||
|
pin_s: p.PE12,
|
||||||
|
pin_sw: p.PE13,
|
||||||
|
pin_w: p.PE14,
|
||||||
|
pin_nw: p.PE15,
|
||||||
|
};
|
||||||
|
let leds = Leds::new(led_pin_set);
|
||||||
|
|
||||||
leds.ld9_se.on().ok();
|
// Initialize the systick interrupt & obtain the token to prove that we did
|
||||||
delay.delay_ms(delay_ms);
|
Mono::start(cx.core.SYST, 8_000_000);
|
||||||
leds.ld9_se.off().ok();
|
blinky::spawn().expect("failed to spawn blinky task");
|
||||||
delay.delay_ms(delay_ms);
|
(
|
||||||
|
Shared {},
|
||||||
|
Local {
|
||||||
|
leds,
|
||||||
|
current_dir: Direction::North,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
leds.ld10_s.on().ok();
|
#[task(local = [leds, current_dir])]
|
||||||
delay.delay_ms(delay_ms);
|
async fn blinky(cx: blinky::Context) {
|
||||||
leds.ld10_s.off().ok();
|
loop {
|
||||||
delay.delay_ms(delay_ms);
|
cx.local.leds.blink_next(cx.local.current_dir);
|
||||||
|
Mono::delay(200.millis()).await;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,51 +1,196 @@
|
|||||||
#![no_main]
|
#![no_main]
|
||||||
#![no_std]
|
#![no_std]
|
||||||
|
|
||||||
use cortex_m_semihosting::debug;
|
use core::time::Duration;
|
||||||
|
use arbitrary_int::u11;
|
||||||
|
use embassy_stm32::gpio::Output;
|
||||||
|
use spacepackets::{
|
||||||
|
ccsds_packet_len_for_user_data_len_with_checksum, CcsdsPacketCreationError,
|
||||||
|
CcsdsPacketCreatorWithReservedData, PacketId, PacketSequenceControl, SpacePacketHeader,
|
||||||
|
};
|
||||||
|
|
||||||
use defmt_brtt as _; // global logger
|
pub const APID: u11 = u11::new(0x02);
|
||||||
|
|
||||||
use stm32f3xx_hal as _; // memory layout
|
#[derive(defmt::Format, serde::Serialize, serde::Deserialize, PartialEq, Eq, Clone, Copy)]
|
||||||
|
pub enum Direction {
|
||||||
use panic_probe as _;
|
North,
|
||||||
|
NorthEast,
|
||||||
// same panicking *behavior* as `panic-probe` but doesn't print a panic message
|
East,
|
||||||
// this prevents the panic message being printed *twice* when `defmt::panic` is invoked
|
SouthEast,
|
||||||
#[defmt::panic_handler]
|
South,
|
||||||
fn panic() -> ! {
|
SouthWest,
|
||||||
cortex_m::asm::udf()
|
West,
|
||||||
|
NorthWest,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Terminates the application and makes a semihosting-capable debug tool exit
|
impl Direction {
|
||||||
/// with status code 0.
|
pub fn switch_to_next(&mut self) -> (Self, Self) {
|
||||||
pub fn exit() -> ! {
|
let curr = *self;
|
||||||
loop {
|
*self = match self {
|
||||||
debug::exit(debug::EXIT_SUCCESS);
|
Direction::North => Direction::NorthEast,
|
||||||
|
Direction::NorthEast => Direction::East,
|
||||||
|
Direction::East => Direction::SouthEast,
|
||||||
|
Direction::SouthEast => Direction::South,
|
||||||
|
Direction::South => Direction::SouthWest,
|
||||||
|
Direction::SouthWest => Direction::West,
|
||||||
|
Direction::West => Direction::NorthWest,
|
||||||
|
Direction::NorthWest => Direction::North,
|
||||||
|
};
|
||||||
|
(curr, *self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Hardfault handler.
|
#[derive(Copy, Clone, Debug, defmt::Format, serde::Serialize, serde::Deserialize)]
|
||||||
///
|
pub enum Request {
|
||||||
/// Terminates the application and makes a semihosting-capable debug tool exit
|
Ping,
|
||||||
/// with an error. This seems better than the default, which is to spin in a
|
ChangeBlinkFrequency(Duration),
|
||||||
/// loop.
|
}
|
||||||
#[cortex_m_rt::exception]
|
|
||||||
unsafe fn HardFault(_frame: &cortex_m_rt::ExceptionFrame) -> ! {
|
#[derive(Debug, defmt::Format, serde::Serialize, serde::Deserialize)]
|
||||||
loop {
|
pub struct CcsdsPacketId {
|
||||||
debug::exit(debug::EXIT_FAILURE);
|
pub packet_id: PacketId,
|
||||||
|
pub psc: PacketSequenceControl,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, defmt::Format, serde::Serialize, serde::Deserialize)]
|
||||||
|
pub struct TmHeader {
|
||||||
|
pub tc_packet_id: Option<CcsdsPacketId>,
|
||||||
|
pub uptime_millis: u32,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, defmt::Format, serde::Serialize, serde::Deserialize)]
|
||||||
|
pub enum Response {
|
||||||
|
CommandDone,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn tm_size(tm_header: &TmHeader, response: &Response) -> usize {
|
||||||
|
ccsds_packet_len_for_user_data_len_with_checksum(
|
||||||
|
postcard::experimental::serialized_size(tm_header).unwrap()
|
||||||
|
+ postcard::experimental::serialized_size(response).unwrap(),
|
||||||
|
)
|
||||||
|
.unwrap()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn create_tm_packet(
|
||||||
|
buf: &mut [u8],
|
||||||
|
sp_header: SpacePacketHeader,
|
||||||
|
tm_header: TmHeader,
|
||||||
|
response: Response,
|
||||||
|
) -> Result<usize, CcsdsPacketCreationError> {
|
||||||
|
let packet_data_size = postcard::experimental::serialized_size(&tm_header).unwrap()
|
||||||
|
+ postcard::experimental::serialized_size(&response).unwrap();
|
||||||
|
let mut creator =
|
||||||
|
CcsdsPacketCreatorWithReservedData::new_tm_with_checksum(sp_header, packet_data_size, buf)?;
|
||||||
|
|
||||||
|
let current_index = postcard::to_slice(&tm_header, creator.packet_data_mut())
|
||||||
|
.unwrap()
|
||||||
|
.len();
|
||||||
|
postcard::to_slice(&response, &mut creator.packet_data_mut()[current_index..]).unwrap();
|
||||||
|
Ok(creator.finish())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct Leds {
|
||||||
|
pub north: Output<'static>,
|
||||||
|
pub north_east: Output<'static>,
|
||||||
|
pub east: Output<'static>,
|
||||||
|
pub south_east: Output<'static>,
|
||||||
|
pub south: Output<'static>,
|
||||||
|
pub south_west: Output<'static>,
|
||||||
|
pub west: Output<'static>,
|
||||||
|
pub north_west: Output<'static>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Leds {
|
||||||
|
pub fn blink_next(&mut self, current_dir: &mut Direction) {
|
||||||
|
let (prev, curr) = current_dir.switch_to_next();
|
||||||
|
self.set_dir_low(prev);
|
||||||
|
self.set_dir_high(curr);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_dir(&mut self, dir: Direction, level: embassy_stm32::gpio::Level) {
|
||||||
|
match dir {
|
||||||
|
Direction::North => self.north.set_level(level),
|
||||||
|
Direction::NorthEast => self.north_east.set_level(level),
|
||||||
|
Direction::East => self.east.set_level(level),
|
||||||
|
Direction::SouthEast => self.south_east.set_level(level),
|
||||||
|
Direction::South => self.south.set_level(level),
|
||||||
|
Direction::SouthWest => self.south_west.set_level(level),
|
||||||
|
Direction::West => self.west.set_level(level),
|
||||||
|
Direction::NorthWest => self.north_west.set_level(level),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_dir_low(&mut self, dir: Direction) {
|
||||||
|
self.set_dir(dir, embassy_stm32::gpio::Level::Low);
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_dir_high(&mut self, dir: Direction) {
|
||||||
|
self.set_dir(dir, embassy_stm32::gpio::Level::High);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// defmt-test 0.3.0 has the limitation that this `#[tests]` attribute can only be used
|
pub struct LedPinSet {
|
||||||
// once within a crate. the module can be in any file but there can only be at most
|
pub pin_n: embassy_stm32::Peri<'static, embassy_stm32::peripherals::PE8>,
|
||||||
// one `#[tests]` module in this library crate
|
pub pin_ne: embassy_stm32::Peri<'static, embassy_stm32::peripherals::PE9>,
|
||||||
#[cfg(test)]
|
pub pin_e: embassy_stm32::Peri<'static, embassy_stm32::peripherals::PE10>,
|
||||||
#[defmt_test::tests]
|
pub pin_se: embassy_stm32::Peri<'static, embassy_stm32::peripherals::PE11>,
|
||||||
mod unit_tests {
|
pub pin_s: embassy_stm32::Peri<'static, embassy_stm32::peripherals::PE12>,
|
||||||
use defmt::assert;
|
pub pin_sw: embassy_stm32::Peri<'static, embassy_stm32::peripherals::PE13>,
|
||||||
|
pub pin_w: embassy_stm32::Peri<'static, embassy_stm32::peripherals::PE14>,
|
||||||
|
pub pin_nw: embassy_stm32::Peri<'static, embassy_stm32::peripherals::PE15>,
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
impl Leds {
|
||||||
fn it_works() {
|
pub fn new(pin_set: LedPinSet) -> Self {
|
||||||
assert!(true)
|
let led_n = Output::new(
|
||||||
|
pin_set.pin_n,
|
||||||
|
embassy_stm32::gpio::Level::Low,
|
||||||
|
embassy_stm32::gpio::Speed::Medium,
|
||||||
|
);
|
||||||
|
let led_ne = Output::new(
|
||||||
|
pin_set.pin_ne,
|
||||||
|
embassy_stm32::gpio::Level::Low,
|
||||||
|
embassy_stm32::gpio::Speed::Medium,
|
||||||
|
);
|
||||||
|
let led_e = Output::new(
|
||||||
|
pin_set.pin_e,
|
||||||
|
embassy_stm32::gpio::Level::Low,
|
||||||
|
embassy_stm32::gpio::Speed::Medium,
|
||||||
|
);
|
||||||
|
let led_se = Output::new(
|
||||||
|
pin_set.pin_se,
|
||||||
|
embassy_stm32::gpio::Level::Low,
|
||||||
|
embassy_stm32::gpio::Speed::Medium,
|
||||||
|
);
|
||||||
|
let led_s = Output::new(
|
||||||
|
pin_set.pin_s,
|
||||||
|
embassy_stm32::gpio::Level::Low,
|
||||||
|
embassy_stm32::gpio::Speed::Medium,
|
||||||
|
);
|
||||||
|
let led_sw = Output::new(
|
||||||
|
pin_set.pin_sw,
|
||||||
|
embassy_stm32::gpio::Level::Low,
|
||||||
|
embassy_stm32::gpio::Speed::Medium,
|
||||||
|
);
|
||||||
|
let led_w = Output::new(
|
||||||
|
pin_set.pin_w,
|
||||||
|
embassy_stm32::gpio::Level::Low,
|
||||||
|
embassy_stm32::gpio::Speed::Medium,
|
||||||
|
);
|
||||||
|
let led_nw = Output::new(
|
||||||
|
pin_set.pin_nw,
|
||||||
|
embassy_stm32::gpio::Level::Low,
|
||||||
|
embassy_stm32::gpio::Speed::Medium,
|
||||||
|
);
|
||||||
|
Self {
|
||||||
|
north: led_n,
|
||||||
|
north_east: led_ne,
|
||||||
|
east: led_e,
|
||||||
|
south_east: led_se,
|
||||||
|
south: led_s,
|
||||||
|
south_west: led_sw,
|
||||||
|
west: led_w,
|
||||||
|
north_west: led_nw,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,682 +1,349 @@
|
|||||||
#![no_std]
|
#![no_std]
|
||||||
#![no_main]
|
#![no_main]
|
||||||
use satrs::pus::verification::{
|
use arbitrary_int::{u11, u14};
|
||||||
FailParams, TcStateAccepted, VerificationReportCreator, VerificationToken,
|
use cortex_m_semihosting::debug::{self, EXIT_FAILURE, EXIT_SUCCESS};
|
||||||
};
|
use satrs_stm32f3_disco_rtic::{create_tm_packet, tm_size, CcsdsPacketId, Request, Response};
|
||||||
use satrs::spacepackets::ecss::tc::PusTcReader;
|
use spacepackets::{CcsdsPacketCreationError, SpHeader};
|
||||||
use satrs::spacepackets::ecss::tm::{PusTmCreator, PusTmSecondaryHeader};
|
|
||||||
use satrs::spacepackets::ecss::EcssEnumU16;
|
use defmt_rtt as _; // global logger
|
||||||
use satrs::spacepackets::CcsdsPacket;
|
|
||||||
use satrs::spacepackets::{ByteConversionError, SpHeader};
|
use panic_probe as _;
|
||||||
// global logger + panicking-behavior + memory layout
|
|
||||||
use satrs_stm32f3_disco_rtic as _;
|
|
||||||
|
|
||||||
use rtic::app;
|
use rtic::app;
|
||||||
|
|
||||||
use heapless::{mpmc::Q8, Vec};
|
|
||||||
#[allow(unused_imports)]
|
#[allow(unused_imports)]
|
||||||
use rtic_monotonics::fugit::{MillisDurationU32, TimerInstantU32};
|
use rtic_monotonics::fugit::{MillisDurationU32, TimerInstantU32};
|
||||||
use rtic_monotonics::systick::prelude::*;
|
use rtic_monotonics::systick::prelude::*;
|
||||||
use satrs::seq_count::SequenceCountProviderCore;
|
|
||||||
use satrs::spacepackets::{ecss::PusPacket, ecss::WritablePusPacket};
|
use crate::app::Mono;
|
||||||
use stm32f3xx_hal::dma::dma1;
|
|
||||||
use stm32f3xx_hal::gpio::{PushPull, AF7, PA2, PA3};
|
|
||||||
use stm32f3xx_hal::pac::USART2;
|
|
||||||
use stm32f3xx_hal::serial::{Rx, RxEvent, Serial, SerialDmaRx, SerialDmaTx, Tx, TxEvent};
|
|
||||||
|
|
||||||
const UART_BAUD: u32 = 115200;
|
const UART_BAUD: u32 = 115200;
|
||||||
const DEFAULT_BLINK_FREQ_MS: u32 = 1000;
|
const DEFAULT_BLINK_FREQ_MS: u32 = 1000;
|
||||||
const TX_HANDLER_FREQ_MS: u32 = 20;
|
const TX_HANDLER_FREQ_MS: u32 = 20;
|
||||||
const MIN_DELAY_BETWEEN_TX_PACKETS_MS: u32 = 5;
|
|
||||||
const MAX_TC_LEN: usize = 128;
|
const MAX_TC_LEN: usize = 128;
|
||||||
const MAX_TM_LEN: usize = 128;
|
const MAX_TM_LEN: usize = 128;
|
||||||
pub const PUS_APID: u16 = 0x02;
|
|
||||||
|
|
||||||
type TxType = Tx<USART2, PA2<AF7<PushPull>>>;
|
pub const PUS_APID: u11 = u11::new(0x02);
|
||||||
type RxType = Rx<USART2, PA3<AF7<PushPull>>>;
|
|
||||||
type InstantFugit = TimerInstantU32<1000>;
|
|
||||||
type TxDmaTransferType = SerialDmaTx<&'static [u8], dma1::C7, TxType>;
|
|
||||||
type RxDmaTransferType = SerialDmaRx<&'static mut [u8], dma1::C6, RxType>;
|
|
||||||
|
|
||||||
// This is the predictable maximum overhead of the COBS encoding scheme.
|
// This is the predictable maximum overhead of the COBS encoding scheme.
|
||||||
// It is simply the maximum packet lenght dividied by 254 rounded up.
|
// It is simply the maximum packet lenght dividied by 254 rounded up.
|
||||||
const COBS_TC_OVERHEAD: usize = (MAX_TC_LEN + 254 - 1) / 254;
|
const COBS_TM_OVERHEAD: usize = cobs::max_encoding_overhead(MAX_TM_LEN);
|
||||||
const COBS_TM_OVERHEAD: usize = (MAX_TM_LEN + 254 - 1) / 254;
|
|
||||||
|
|
||||||
const TC_BUF_LEN: usize = MAX_TC_LEN + COBS_TC_OVERHEAD;
|
|
||||||
const TM_BUF_LEN: usize = MAX_TC_LEN + COBS_TM_OVERHEAD;
|
const TM_BUF_LEN: usize = MAX_TC_LEN + COBS_TM_OVERHEAD;
|
||||||
|
|
||||||
// This is a static buffer which should ONLY (!) be used as the TX DMA
|
const TC_DMA_BUF_LEN: usize = 512;
|
||||||
// transfer buffer.
|
|
||||||
static mut DMA_TX_BUF: [u8; TM_BUF_LEN] = [0; TM_BUF_LEN];
|
|
||||||
// This is a static buffer which should ONLY (!) be used as the RX DMA
|
|
||||||
// transfer buffer.
|
|
||||||
static mut DMA_RX_BUF: [u8; TC_BUF_LEN] = [0; TC_BUF_LEN];
|
|
||||||
|
|
||||||
type TmPacket = Vec<u8, MAX_TM_LEN>;
|
type TmPacket = heapless::Vec<u8, MAX_TM_LEN>;
|
||||||
type TcPacket = Vec<u8, MAX_TC_LEN>;
|
|
||||||
|
|
||||||
static TM_REQUESTS: Q8<TmPacket> = Q8::new();
|
static TM_QUEUE: heapless::mpmc::Queue<TmPacket, 16> = heapless::mpmc::Queue::new();
|
||||||
|
|
||||||
use core::sync::atomic::{AtomicU16, Ordering};
|
#[derive(Debug, defmt::Format, thiserror::Error)]
|
||||||
|
|
||||||
pub struct SeqCountProviderAtomicRef {
|
|
||||||
atomic: AtomicU16,
|
|
||||||
ordering: Ordering,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl SeqCountProviderAtomicRef {
|
|
||||||
pub const fn new(ordering: Ordering) -> Self {
|
|
||||||
Self {
|
|
||||||
atomic: AtomicU16::new(0),
|
|
||||||
ordering,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl SequenceCountProviderCore<u16> for SeqCountProviderAtomicRef {
|
|
||||||
fn get(&self) -> u16 {
|
|
||||||
self.atomic.load(self.ordering)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn increment(&self) {
|
|
||||||
self.atomic.fetch_add(1, self.ordering);
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get_and_increment(&self) -> u16 {
|
|
||||||
self.atomic.fetch_add(1, self.ordering)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static SEQ_COUNT_PROVIDER: SeqCountProviderAtomicRef =
|
|
||||||
SeqCountProviderAtomicRef::new(Ordering::Relaxed);
|
|
||||||
|
|
||||||
pub struct TxIdle {
|
|
||||||
tx: TxType,
|
|
||||||
dma_channel: dma1::C7,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, defmt::Format)]
|
|
||||||
pub enum TmSendError {
|
pub enum TmSendError {
|
||||||
ByteConversion(ByteConversionError),
|
#[error("packet creation error: {0}")]
|
||||||
|
PacketCreation(#[from] CcsdsPacketCreationError),
|
||||||
|
#[error("queue error")]
|
||||||
Queue,
|
Queue,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<ByteConversionError> for TmSendError {
|
|
||||||
fn from(value: ByteConversionError) -> Self {
|
|
||||||
Self::ByteConversion(value)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn send_tm(tm_creator: PusTmCreator) -> Result<(), TmSendError> {
|
|
||||||
if tm_creator.len_written() > MAX_TM_LEN {
|
|
||||||
return Err(ByteConversionError::ToSliceTooSmall {
|
|
||||||
expected: tm_creator.len_written(),
|
|
||||||
found: MAX_TM_LEN,
|
|
||||||
}
|
|
||||||
.into());
|
|
||||||
}
|
|
||||||
let mut tm_vec = TmPacket::new();
|
|
||||||
tm_vec
|
|
||||||
.resize(tm_creator.len_written(), 0)
|
|
||||||
.expect("vec resize failed");
|
|
||||||
tm_creator.write_to_bytes(tm_vec.as_mut_slice())?;
|
|
||||||
defmt::info!(
|
|
||||||
"Sending TM[{},{}] with size {}",
|
|
||||||
tm_creator.service(),
|
|
||||||
tm_creator.subservice(),
|
|
||||||
tm_creator.len_written()
|
|
||||||
);
|
|
||||||
TM_REQUESTS
|
|
||||||
.enqueue(tm_vec)
|
|
||||||
.map_err(|_| TmSendError::Queue)?;
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn handle_tm_send_error(error: TmSendError) {
|
|
||||||
defmt::warn!("sending tm failed with error {}", error);
|
|
||||||
}
|
|
||||||
|
|
||||||
pub enum UartTxState {
|
|
||||||
// Wrapped in an option because we need an owned type later.
|
|
||||||
Idle(Option<TxIdle>),
|
|
||||||
// Same as above
|
|
||||||
Transmitting(Option<TxDmaTransferType>),
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct UartTxShared {
|
|
||||||
last_completed: Option<InstantFugit>,
|
|
||||||
state: UartTxState,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct RequestWithToken {
|
|
||||||
token: VerificationToken<TcStateAccepted>,
|
|
||||||
request: Request,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, defmt::Format)]
|
#[derive(Debug, defmt::Format)]
|
||||||
pub enum Request {
|
pub struct RequestWithTcId {
|
||||||
Ping,
|
pub request: Request,
|
||||||
ChangeBlinkFrequency(u32),
|
pub tc_id: CcsdsPacketId,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, defmt::Format)]
|
#[app(device = embassy_stm32)]
|
||||||
pub enum RequestError {
|
|
||||||
InvalidApid = 1,
|
|
||||||
InvalidService = 2,
|
|
||||||
InvalidSubservice = 3,
|
|
||||||
NotEnoughAppData = 4,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn convert_pus_tc_to_request(
|
|
||||||
tc: &PusTcReader,
|
|
||||||
verif_reporter: &mut VerificationReportCreator,
|
|
||||||
src_data_buf: &mut [u8],
|
|
||||||
timestamp: &[u8],
|
|
||||||
) -> Result<RequestWithToken, RequestError> {
|
|
||||||
defmt::info!(
|
|
||||||
"Found PUS TC [{},{}] with length {}",
|
|
||||||
tc.service(),
|
|
||||||
tc.subservice(),
|
|
||||||
tc.len_packed()
|
|
||||||
);
|
|
||||||
|
|
||||||
let token = verif_reporter.add_tc(tc);
|
|
||||||
if tc.apid() != PUS_APID {
|
|
||||||
defmt::warn!("Received tc with unknown APID {}", tc.apid());
|
|
||||||
let result = send_tm(
|
|
||||||
verif_reporter
|
|
||||||
.acceptance_failure(
|
|
||||||
src_data_buf,
|
|
||||||
token,
|
|
||||||
SEQ_COUNT_PROVIDER.get_and_increment(),
|
|
||||||
0,
|
|
||||||
FailParams::new(timestamp, &EcssEnumU16::new(0), &[]),
|
|
||||||
)
|
|
||||||
.unwrap(),
|
|
||||||
);
|
|
||||||
if let Err(e) = result {
|
|
||||||
handle_tm_send_error(e);
|
|
||||||
}
|
|
||||||
return Err(RequestError::InvalidApid);
|
|
||||||
}
|
|
||||||
let (tm_creator, accepted_token) = verif_reporter
|
|
||||||
.acceptance_success(
|
|
||||||
src_data_buf,
|
|
||||||
token,
|
|
||||||
SEQ_COUNT_PROVIDER.get_and_increment(),
|
|
||||||
0,
|
|
||||||
timestamp,
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
if let Err(e) = send_tm(tm_creator) {
|
|
||||||
handle_tm_send_error(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
if tc.service() == 17 && tc.subservice() == 1 {
|
|
||||||
if tc.subservice() == 1 {
|
|
||||||
return Ok(RequestWithToken {
|
|
||||||
request: Request::Ping,
|
|
||||||
token: accepted_token,
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
return Err(RequestError::InvalidSubservice);
|
|
||||||
}
|
|
||||||
} else if tc.service() == 8 {
|
|
||||||
if tc.subservice() == 1 {
|
|
||||||
if tc.user_data().len() < 4 {
|
|
||||||
return Err(RequestError::NotEnoughAppData);
|
|
||||||
}
|
|
||||||
let new_freq_ms = u32::from_be_bytes(tc.user_data()[0..4].try_into().unwrap());
|
|
||||||
return Ok(RequestWithToken {
|
|
||||||
request: Request::ChangeBlinkFrequency(new_freq_ms),
|
|
||||||
token: accepted_token,
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
return Err(RequestError::InvalidSubservice);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return Err(RequestError::InvalidService);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[app(device = stm32f3xx_hal::pac, peripherals = true)]
|
|
||||||
mod app {
|
mod app {
|
||||||
use super::*;
|
use core::time::Duration;
|
||||||
use core::slice::Iter;
|
|
||||||
use satrs::pus::verification::{TcStateStarted, VerificationReportCreator};
|
|
||||||
use satrs::spacepackets::{ecss::tc::PusTcReader, time::cds::P_FIELD_BASE};
|
|
||||||
#[allow(unused_imports)]
|
|
||||||
use stm32f3_discovery::leds::Direction;
|
|
||||||
use stm32f3_discovery::leds::Leds;
|
|
||||||
use stm32f3xx_hal::prelude::*;
|
|
||||||
|
|
||||||
use stm32f3_discovery::switch_hal::OutputSwitch;
|
use super::*;
|
||||||
use stm32f3xx_hal::Switch;
|
use arbitrary_int::u14;
|
||||||
#[allow(dead_code)]
|
use rtic::Mutex;
|
||||||
type SerialType = Serial<USART2, (PA2<AF7<PushPull>>, PA3<AF7<PushPull>>)>;
|
use rtic_sync::{
|
||||||
|
channel::{Receiver, Sender},
|
||||||
|
make_channel,
|
||||||
|
};
|
||||||
|
use satrs_stm32f3_disco_rtic::{CcsdsPacketId, LedPinSet, Request, Response};
|
||||||
|
use spacepackets::CcsdsPacketReader;
|
||||||
|
|
||||||
systick_monotonic!(Mono, 1000);
|
systick_monotonic!(Mono, 1000);
|
||||||
|
|
||||||
|
embassy_stm32::bind_interrupts!(struct Irqs {
|
||||||
|
USART2 => embassy_stm32::usart::InterruptHandler<embassy_stm32::peripherals::USART2>;
|
||||||
|
});
|
||||||
|
|
||||||
#[shared]
|
#[shared]
|
||||||
struct Shared {
|
struct Shared {
|
||||||
blink_freq: MillisDurationU32,
|
blink_freq: Duration,
|
||||||
tx_shared: UartTxShared,
|
|
||||||
rx_transfer: Option<RxDmaTransferType>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[local]
|
#[local]
|
||||||
struct Local {
|
struct Local {
|
||||||
verif_reporter: VerificationReportCreator,
|
leds: satrs_stm32f3_disco_rtic::Leds,
|
||||||
leds: Leds,
|
current_dir: satrs_stm32f3_disco_rtic::Direction,
|
||||||
last_dir: Direction,
|
seq_count: u14,
|
||||||
curr_dir: Iter<'static, Direction>,
|
tx: embassy_stm32::usart::UartTx<'static, embassy_stm32::mode::Async>,
|
||||||
|
rx: embassy_stm32::usart::RingBufferedUartRx<'static>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[init]
|
#[init]
|
||||||
fn init(cx: init::Context) -> (Shared, Local) {
|
fn init(cx: init::Context) -> (Shared, Local) {
|
||||||
let mut rcc = cx.device.RCC.constrain();
|
static DMA_BUF: static_cell::ConstStaticCell<[u8; TC_DMA_BUF_LEN]> =
|
||||||
|
static_cell::ConstStaticCell::new([0; TC_DMA_BUF_LEN]);
|
||||||
|
|
||||||
|
let p = embassy_stm32::init(Default::default());
|
||||||
|
|
||||||
|
let (req_sender, req_receiver) = make_channel!(RequestWithTcId, 16);
|
||||||
// Initialize the systick interrupt & obtain the token to prove that we did
|
// Initialize the systick interrupt & obtain the token to prove that we did
|
||||||
Mono::start(cx.core.SYST, 8_000_000);
|
Mono::start(cx.core.SYST, 8_000_000);
|
||||||
|
|
||||||
let mut flash = cx.device.FLASH.constrain();
|
defmt::info!("sat-rs demo application for the STM32F3-Discovery with RTICv2");
|
||||||
let clocks = rcc
|
let led_pin_set = LedPinSet {
|
||||||
.cfgr
|
pin_n: p.PE8,
|
||||||
.use_hse(8.MHz())
|
pin_ne: p.PE9,
|
||||||
.sysclk(8.MHz())
|
pin_e: p.PE10,
|
||||||
.pclk1(8.MHz())
|
pin_se: p.PE11,
|
||||||
.freeze(&mut flash.acr);
|
pin_s: p.PE12,
|
||||||
|
pin_sw: p.PE13,
|
||||||
|
pin_w: p.PE14,
|
||||||
|
pin_nw: p.PE15,
|
||||||
|
};
|
||||||
|
let leds = satrs_stm32f3_disco_rtic::Leds::new(led_pin_set);
|
||||||
|
|
||||||
// Set up monotonic timer.
|
let mut config = embassy_stm32::usart::Config::default();
|
||||||
//let mono_timer = MonoTimer::new(cx.core.DWT, clocks, &mut cx.core.DCB);
|
config.baudrate = UART_BAUD;
|
||||||
|
let uart = embassy_stm32::usart::Uart::new(
|
||||||
|
p.USART2, p.PA3, p.PA2, Irqs, p.DMA1_CH7, p.DMA1_CH6, config,
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
defmt::info!("Starting sat-rs demo application for the STM32F3-Discovery");
|
let (tx, rx) = uart.split();
|
||||||
let mut gpioe = cx.device.GPIOE.split(&mut rcc.ahb);
|
|
||||||
|
|
||||||
let leds = Leds::new(
|
|
||||||
gpioe.pe8,
|
|
||||||
gpioe.pe9,
|
|
||||||
gpioe.pe10,
|
|
||||||
gpioe.pe11,
|
|
||||||
gpioe.pe12,
|
|
||||||
gpioe.pe13,
|
|
||||||
gpioe.pe14,
|
|
||||||
gpioe.pe15,
|
|
||||||
&mut gpioe.moder,
|
|
||||||
&mut gpioe.otyper,
|
|
||||||
);
|
|
||||||
let mut gpioa = cx.device.GPIOA.split(&mut rcc.ahb);
|
|
||||||
// USART2 pins
|
|
||||||
let mut pins = (
|
|
||||||
// TX pin: PA2
|
|
||||||
gpioa
|
|
||||||
.pa2
|
|
||||||
.into_af_push_pull(&mut gpioa.moder, &mut gpioa.otyper, &mut gpioa.afrl),
|
|
||||||
// RX pin: PA3
|
|
||||||
gpioa
|
|
||||||
.pa3
|
|
||||||
.into_af_push_pull(&mut gpioa.moder, &mut gpioa.otyper, &mut gpioa.afrl),
|
|
||||||
);
|
|
||||||
pins.1.internal_pull_up(&mut gpioa.pupdr, true);
|
|
||||||
let mut usart2 = Serial::new(
|
|
||||||
cx.device.USART2,
|
|
||||||
pins,
|
|
||||||
UART_BAUD.Bd(),
|
|
||||||
clocks,
|
|
||||||
&mut rcc.apb1,
|
|
||||||
);
|
|
||||||
usart2.configure_rx_interrupt(RxEvent::Idle, Switch::On);
|
|
||||||
// This interrupt is enabled to re-schedule new transfers in the interrupt handler immediately.
|
|
||||||
usart2.configure_tx_interrupt(TxEvent::TransmissionComplete, Switch::On);
|
|
||||||
|
|
||||||
let dma1 = cx.device.DMA1.split(&mut rcc.ahb);
|
|
||||||
let (mut tx_serial, mut rx_serial) = usart2.split();
|
|
||||||
|
|
||||||
// This interrupt is immediately triggered, clear it. It will only be reset
|
|
||||||
// by the hardware when data is received on RX (RXNE event)
|
|
||||||
rx_serial.clear_event(RxEvent::Idle);
|
|
||||||
// For some reason, this is also immediately triggered..
|
|
||||||
tx_serial.clear_event(TxEvent::TransmissionComplete);
|
|
||||||
let rx_transfer = rx_serial.read_exact(unsafe { DMA_RX_BUF.as_mut_slice() }, dma1.ch6);
|
|
||||||
defmt::info!("Spawning tasks");
|
defmt::info!("Spawning tasks");
|
||||||
blink::spawn().unwrap();
|
blinky::spawn().unwrap();
|
||||||
serial_tx_handler::spawn().unwrap();
|
serial_tx_handler::spawn().unwrap();
|
||||||
|
serial_rx_handler::spawn(req_sender).unwrap();
|
||||||
let verif_reporter = VerificationReportCreator::new(PUS_APID).unwrap();
|
req_handler::spawn(req_receiver).unwrap();
|
||||||
|
|
||||||
(
|
(
|
||||||
Shared {
|
Shared {
|
||||||
blink_freq: MillisDurationU32::from_ticks(DEFAULT_BLINK_FREQ_MS),
|
blink_freq: Duration::from_millis(DEFAULT_BLINK_FREQ_MS as u64),
|
||||||
tx_shared: UartTxShared {
|
|
||||||
last_completed: None,
|
|
||||||
state: UartTxState::Idle(Some(TxIdle {
|
|
||||||
tx: tx_serial,
|
|
||||||
dma_channel: dma1.ch7,
|
|
||||||
})),
|
|
||||||
},
|
|
||||||
rx_transfer: Some(rx_transfer),
|
|
||||||
},
|
},
|
||||||
Local {
|
Local {
|
||||||
verif_reporter,
|
|
||||||
leds,
|
leds,
|
||||||
last_dir: Direction::North,
|
tx,
|
||||||
curr_dir: Direction::iter(),
|
seq_count: u14::new(0),
|
||||||
|
rx: rx.into_ring_buffered(DMA_BUF.take()),
|
||||||
|
current_dir: satrs_stm32f3_disco_rtic::Direction::North,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[task(local = [leds, curr_dir, last_dir], shared=[blink_freq])]
|
#[task(local = [leds, current_dir], shared=[blink_freq])]
|
||||||
async fn blink(mut cx: blink::Context) {
|
async fn blinky(mut cx: blinky::Context) {
|
||||||
let blink::LocalResources {
|
|
||||||
leds,
|
|
||||||
curr_dir,
|
|
||||||
last_dir,
|
|
||||||
..
|
|
||||||
} = cx.local;
|
|
||||||
let mut toggle_leds = |dir: &Direction| {
|
|
||||||
let last_led = leds.for_direction(*last_dir);
|
|
||||||
last_led.off().ok();
|
|
||||||
let led = leds.for_direction(*dir);
|
|
||||||
led.on().ok();
|
|
||||||
*last_dir = *dir;
|
|
||||||
};
|
|
||||||
loop {
|
loop {
|
||||||
match curr_dir.next() {
|
cx.local.leds.blink_next(cx.local.current_dir);
|
||||||
Some(dir) => {
|
|
||||||
toggle_leds(dir);
|
|
||||||
}
|
|
||||||
None => {
|
|
||||||
*curr_dir = Direction::iter();
|
|
||||||
toggle_leds(curr_dir.next().unwrap());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
let current_blink_freq = cx.shared.blink_freq.lock(|current| *current);
|
let current_blink_freq = cx.shared.blink_freq.lock(|current| *current);
|
||||||
Mono::delay(current_blink_freq).await;
|
Mono::delay(MillisDurationU32::from_ticks(
|
||||||
|
current_blink_freq.as_millis() as u32,
|
||||||
|
))
|
||||||
|
.await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[task(
|
#[task(
|
||||||
shared = [tx_shared],
|
local = [
|
||||||
|
tx,
|
||||||
|
encoded_buf: [u8; TM_BUF_LEN] = [0; TM_BUF_LEN]
|
||||||
|
],
|
||||||
|
shared = [],
|
||||||
)]
|
)]
|
||||||
async fn serial_tx_handler(mut cx: serial_tx_handler::Context) {
|
async fn serial_tx_handler(cx: serial_tx_handler::Context) {
|
||||||
loop {
|
loop {
|
||||||
let is_idle = cx.shared.tx_shared.lock(|tx_shared| {
|
while let Some(vec) = TM_QUEUE.dequeue() {
|
||||||
if let UartTxState::Idle(_) = tx_shared.state {
|
let encoded_len =
|
||||||
return true;
|
cobs::encode_including_sentinels(&vec[0..vec.len()], cx.local.encoded_buf);
|
||||||
}
|
defmt::debug!("sending {} bytes over UART", encoded_len);
|
||||||
false
|
cx.local
|
||||||
});
|
.tx
|
||||||
if is_idle {
|
.write(&cx.local.encoded_buf[0..encoded_len])
|
||||||
let last_completed = cx.shared.tx_shared.lock(|shared| shared.last_completed);
|
.await
|
||||||
if let Some(last_completed) = last_completed {
|
.unwrap();
|
||||||
let elapsed_ms = (Mono::now() - last_completed).to_millis();
|
|
||||||
if elapsed_ms < MIN_DELAY_BETWEEN_TX_PACKETS_MS {
|
|
||||||
Mono::delay((MIN_DELAY_BETWEEN_TX_PACKETS_MS - elapsed_ms).millis()).await;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// Check for completion after 1 ms
|
|
||||||
Mono::delay(1.millis()).await;
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if let Some(vec) = TM_REQUESTS.dequeue() {
|
|
||||||
cx.shared
|
|
||||||
.tx_shared
|
|
||||||
.lock(|tx_shared| match &mut tx_shared.state {
|
|
||||||
UartTxState::Idle(tx) => {
|
|
||||||
let encoded_len;
|
|
||||||
//debug!(target: "serial_tx_handler", "bytes: {:x?}", &buf[0..len]);
|
|
||||||
// Safety: We only copy the data into the TX DMA buffer in this task.
|
|
||||||
// If the DMA is active, another branch will be taken.
|
|
||||||
unsafe {
|
|
||||||
// 0 sentinel value as start marker
|
|
||||||
DMA_TX_BUF[0] = 0;
|
|
||||||
encoded_len =
|
|
||||||
cobs::encode(&vec[0..vec.len()], &mut DMA_TX_BUF[1..]);
|
|
||||||
// Should never panic, we accounted for the overhead.
|
|
||||||
// Write into transfer buffer directly, no need for intermediate
|
|
||||||
// encoding buffer.
|
|
||||||
// 0 end marker
|
|
||||||
DMA_TX_BUF[encoded_len + 1] = 0;
|
|
||||||
}
|
|
||||||
//debug!(target: "serial_tx_handler", "Sending {} bytes", encoded_len + 2);
|
|
||||||
//debug!("sent: {:x?}", &mut_tx_dma_buf[0..encoded_len + 2]);
|
|
||||||
let tx_idle = tx.take().unwrap();
|
|
||||||
// Transfer completion and re-scheduling of new TX transfers will be done
|
|
||||||
// by the IRQ handler.
|
|
||||||
// SAFETY: The DMA is the exclusive writer to the DMA buffer now.
|
|
||||||
let transfer = tx_idle.tx.write_all(
|
|
||||||
unsafe { &DMA_TX_BUF[0..encoded_len + 2] },
|
|
||||||
tx_idle.dma_channel,
|
|
||||||
);
|
|
||||||
tx_shared.state = UartTxState::Transmitting(Some(transfer));
|
|
||||||
// The memory block is automatically returned to the pool when it is dropped.
|
|
||||||
}
|
|
||||||
UartTxState::Transmitting(_) => (),
|
|
||||||
});
|
|
||||||
// Check for completion after 1 ms
|
|
||||||
Mono::delay(1.millis()).await;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
// Nothing to do, and we are idle.
|
|
||||||
Mono::delay(TX_HANDLER_FREQ_MS.millis()).await;
|
Mono::delay(TX_HANDLER_FREQ_MS.millis()).await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[task(
|
#[task(
|
||||||
local = [
|
local = [
|
||||||
verif_reporter,
|
rx,
|
||||||
|
read_buf: [u8; 128] = [0; 128],
|
||||||
decode_buf: [u8; MAX_TC_LEN] = [0; MAX_TC_LEN],
|
decode_buf: [u8; MAX_TC_LEN] = [0; MAX_TC_LEN],
|
||||||
src_data_buf: [u8; MAX_TM_LEN] = [0; MAX_TM_LEN],
|
|
||||||
timestamp: [u8; 7] = [0; 7],
|
|
||||||
],
|
],
|
||||||
shared = [blink_freq]
|
shared = [blink_freq]
|
||||||
)]
|
)]
|
||||||
async fn serial_rx_handler(
|
async fn serial_rx_handler(
|
||||||
mut cx: serial_rx_handler::Context,
|
cx: serial_rx_handler::Context,
|
||||||
received_packet: Vec<u8, MAX_TC_LEN>,
|
mut sender: Sender<'static, RequestWithTcId, 16>,
|
||||||
) {
|
) {
|
||||||
cx.local.timestamp[0] = P_FIELD_BASE;
|
let mut decoder = cobs::CobsDecoder::new(cx.local.decode_buf);
|
||||||
defmt::info!("Received packet with {} bytes", received_packet.len());
|
loop {
|
||||||
let decode_buf = cx.local.decode_buf;
|
match cx.local.rx.read(cx.local.read_buf).await {
|
||||||
let packet = received_packet.as_slice();
|
Ok(bytes) => {
|
||||||
let mut start_idx = None;
|
defmt::debug!("received {} bytes over UART", bytes);
|
||||||
for (idx, byte) in packet.iter().enumerate() {
|
for byte in cx.local.read_buf[0..bytes].iter() {
|
||||||
if *byte != 0 {
|
match decoder.feed(*byte) {
|
||||||
start_idx = Some(idx);
|
Ok(None) => (),
|
||||||
break;
|
Ok(Some(packet_size)) => {
|
||||||
}
|
match CcsdsPacketReader::new_with_checksum(
|
||||||
}
|
&decoder.dest()[0..packet_size],
|
||||||
if start_idx.is_none() {
|
) {
|
||||||
defmt::warn!("decoding error, can only process cobs encoded frames, data is all 0");
|
Ok(packet) => {
|
||||||
return;
|
let packet_id = packet.packet_id();
|
||||||
}
|
let psc = packet.psc();
|
||||||
let start_idx = start_idx.unwrap();
|
let tc_packet_id = CcsdsPacketId { packet_id, psc };
|
||||||
match cobs::decode(&received_packet.as_slice()[start_idx..], decode_buf) {
|
if let Ok(request) =
|
||||||
Ok(len) => {
|
postcard::from_bytes::<Request>(packet.packet_data())
|
||||||
defmt::info!("Decoded packet length: {}", len);
|
{
|
||||||
let pus_tc = PusTcReader::new(decode_buf);
|
sender
|
||||||
match pus_tc {
|
.send(RequestWithTcId {
|
||||||
Ok((tc, _tc_len)) => {
|
request,
|
||||||
match convert_pus_tc_to_request(
|
tc_id: tc_packet_id,
|
||||||
&tc,
|
})
|
||||||
cx.local.verif_reporter,
|
.await
|
||||||
cx.local.src_data_buf,
|
.unwrap();
|
||||||
cx.local.timestamp,
|
}
|
||||||
) {
|
|
||||||
Ok(request_with_token) => {
|
|
||||||
let started_token = handle_start_verification(
|
|
||||||
request_with_token.token,
|
|
||||||
cx.local.verif_reporter,
|
|
||||||
cx.local.src_data_buf,
|
|
||||||
cx.local.timestamp,
|
|
||||||
);
|
|
||||||
|
|
||||||
match request_with_token.request {
|
|
||||||
Request::Ping => {
|
|
||||||
handle_ping_request(cx.local.timestamp);
|
|
||||||
}
|
}
|
||||||
Request::ChangeBlinkFrequency(new_freq_ms) => {
|
Err(e) => {
|
||||||
defmt::info!("Received blink frequency change request with new frequncy {}", new_freq_ms);
|
defmt::error!("error unpacking ccsds packet: {}", e);
|
||||||
cx.shared.blink_freq.lock(|blink_freq| {
|
|
||||||
*blink_freq =
|
|
||||||
MillisDurationU32::from_ticks(new_freq_ms);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
handle_completion_verification(
|
|
||||||
started_token,
|
|
||||||
cx.local.verif_reporter,
|
|
||||||
cx.local.src_data_buf,
|
|
||||||
cx.local.timestamp,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
// TODO: Error handling: Send verification failure based on request error.
|
defmt::error!("cobs decoding error: {}", e);
|
||||||
defmt::warn!("request error {}", e);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(e) => {
|
}
|
||||||
defmt::warn!("Error unpacking PUS TC: {}", e);
|
Err(e) => {
|
||||||
}
|
defmt::error!("uart read error: {}", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(_) => {
|
|
||||||
defmt::warn!("decoding error, can only process cobs encoded frames")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handle_ping_request(timestamp: &[u8]) {
|
#[task(shared = [blink_freq], local = [seq_count])]
|
||||||
defmt::info!("Received PUS ping telecommand, sending ping reply TM[17,2]");
|
async fn req_handler(
|
||||||
let sp_header =
|
mut cx: req_handler::Context,
|
||||||
SpHeader::new_for_unseg_tc(PUS_APID, SEQ_COUNT_PROVIDER.get_and_increment(), 0);
|
mut receiver: Receiver<'static, RequestWithTcId, 16>,
|
||||||
let sec_header = PusTmSecondaryHeader::new_simple(17, 2, timestamp);
|
|
||||||
let ping_reply = PusTmCreator::new(sp_header, sec_header, &[], true);
|
|
||||||
let mut tm_packet = TmPacket::new();
|
|
||||||
tm_packet
|
|
||||||
.resize(ping_reply.len_written(), 0)
|
|
||||||
.expect("vec resize failed");
|
|
||||||
ping_reply.write_to_bytes(&mut tm_packet).unwrap();
|
|
||||||
if TM_REQUESTS.enqueue(tm_packet).is_err() {
|
|
||||||
defmt::warn!("TC queue full");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn handle_start_verification(
|
|
||||||
accepted_token: VerificationToken<TcStateAccepted>,
|
|
||||||
verif_reporter: &mut VerificationReportCreator,
|
|
||||||
src_data_buf: &mut [u8],
|
|
||||||
timestamp: &[u8],
|
|
||||||
) -> VerificationToken<TcStateStarted> {
|
|
||||||
let (tm_creator, started_token) = verif_reporter
|
|
||||||
.start_success(
|
|
||||||
src_data_buf,
|
|
||||||
accepted_token,
|
|
||||||
SEQ_COUNT_PROVIDER.get(),
|
|
||||||
0,
|
|
||||||
×tamp,
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
let result = send_tm(tm_creator);
|
|
||||||
if let Err(e) = result {
|
|
||||||
handle_tm_send_error(e);
|
|
||||||
}
|
|
||||||
started_token
|
|
||||||
}
|
|
||||||
|
|
||||||
fn handle_completion_verification(
|
|
||||||
started_token: VerificationToken<TcStateStarted>,
|
|
||||||
verif_reporter: &mut VerificationReportCreator,
|
|
||||||
src_data_buf: &mut [u8],
|
|
||||||
timestamp: &[u8],
|
|
||||||
) {
|
) {
|
||||||
let result = send_tm(
|
loop {
|
||||||
verif_reporter
|
match receiver.recv().await {
|
||||||
.completion_success(
|
Ok(request_with_tc_id) => {
|
||||||
src_data_buf,
|
let tm_send_result = match request_with_tc_id.request {
|
||||||
started_token,
|
Request::Ping => handle_ping_request(&mut cx, request_with_tc_id.tc_id),
|
||||||
SEQ_COUNT_PROVIDER.get(),
|
Request::ChangeBlinkFrequency(duration) => {
|
||||||
0,
|
handle_change_blink_frequency_request(
|
||||||
timestamp,
|
&mut cx,
|
||||||
)
|
request_with_tc_id.tc_id,
|
||||||
.unwrap(),
|
duration,
|
||||||
);
|
)
|
||||||
if let Err(e) = result {
|
}
|
||||||
handle_tm_send_error(e);
|
};
|
||||||
|
if let Err(e) = tm_send_result {
|
||||||
|
defmt::error!("error sending TM response: {}", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(_e) => defmt::error!("request receive error"),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[task(binds = DMA1_CH6, shared = [rx_transfer])]
|
fn handle_ping_request(
|
||||||
fn rx_dma_isr(mut cx: rx_dma_isr::Context) {
|
cx: &mut req_handler::Context,
|
||||||
let mut tc_packet = TcPacket::new();
|
tc_packet_id: CcsdsPacketId,
|
||||||
cx.shared.rx_transfer.lock(|rx_transfer| {
|
) -> Result<(), TmSendError> {
|
||||||
let rx_ref = rx_transfer.as_ref().unwrap();
|
defmt::info!("Received PUS ping telecommand, sending ping reply");
|
||||||
if rx_ref.is_complete() {
|
send_tm(tc_packet_id, Response::CommandDone, *cx.local.seq_count)?;
|
||||||
let uart_rx_owned = rx_transfer.take().unwrap();
|
*cx.local.seq_count = cx.local.seq_count.wrapping_add(u14::new(1));
|
||||||
let (buf, c, rx) = uart_rx_owned.stop();
|
Ok(())
|
||||||
// The received data is transferred to another task now to avoid any processing overhead
|
|
||||||
// during the interrupt. There are multiple ways to do this, we use a stack allocaed vector here
|
|
||||||
// to do this.
|
|
||||||
tc_packet.resize(buf.len(), 0).expect("vec resize failed");
|
|
||||||
tc_packet.copy_from_slice(buf);
|
|
||||||
|
|
||||||
// Start the next transfer as soon as possible.
|
|
||||||
*rx_transfer = Some(rx.read_exact(buf, c));
|
|
||||||
|
|
||||||
// Send the vector to a regular task.
|
|
||||||
serial_rx_handler::spawn(tc_packet).expect("spawning rx handler task failed");
|
|
||||||
// If this happens, there is a high chance that the maximum packet length was
|
|
||||||
// exceeded. Circular mode is not used here, so data might be missed.
|
|
||||||
defmt::warn!(
|
|
||||||
"rx transfer with maximum length {}, might miss data",
|
|
||||||
TC_BUF_LEN
|
|
||||||
);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[task(binds = USART2_EXTI26, shared = [rx_transfer, tx_shared])]
|
fn handle_change_blink_frequency_request(
|
||||||
fn serial_isr(mut cx: serial_isr::Context) {
|
cx: &mut req_handler::Context,
|
||||||
|
tc_packet_id: CcsdsPacketId,
|
||||||
|
duration: Duration,
|
||||||
|
) -> Result<(), TmSendError> {
|
||||||
|
defmt::info!(
|
||||||
|
"Received ChangeBlinkFrequency request, new frequency: {} ms",
|
||||||
|
duration.as_millis()
|
||||||
|
);
|
||||||
cx.shared
|
cx.shared
|
||||||
.tx_shared
|
.blink_freq
|
||||||
.lock(|tx_shared| match &mut tx_shared.state {
|
.lock(|blink_freq| *blink_freq = duration);
|
||||||
UartTxState::Idle(_) => (),
|
send_tm(tc_packet_id, Response::CommandDone, *cx.local.seq_count)?;
|
||||||
UartTxState::Transmitting(transfer) => {
|
*cx.local.seq_count = cx.local.seq_count.wrapping_add(u14::new(1));
|
||||||
let transfer_ref = transfer.as_ref().unwrap();
|
Ok(())
|
||||||
if transfer_ref.is_complete() {
|
}
|
||||||
let transfer = transfer.take().unwrap();
|
}
|
||||||
let (_, dma_channel, mut tx) = transfer.stop();
|
|
||||||
tx.clear_event(TxEvent::TransmissionComplete);
|
fn send_tm(
|
||||||
tx_shared.state = UartTxState::Idle(Some(TxIdle { tx, dma_channel }));
|
tc_packet_id: CcsdsPacketId,
|
||||||
// We cache the last completed time to ensure that there is a minimum delay between consecutive
|
response: Response,
|
||||||
// transferred packets.
|
current_seq_count: u14,
|
||||||
tx_shared.last_completed = Some(Mono::now());
|
) -> Result<(), TmSendError> {
|
||||||
}
|
let sp_header = SpHeader::new_for_unseg_tc(PUS_APID, current_seq_count, 0);
|
||||||
}
|
let tm_header = satrs_stm32f3_disco_rtic::TmHeader {
|
||||||
});
|
tc_packet_id: Some(tc_packet_id),
|
||||||
let mut tc_packet = TcPacket::new();
|
uptime_millis: Mono::now().duration_since_epoch().to_millis(),
|
||||||
cx.shared.rx_transfer.lock(|rx_transfer| {
|
};
|
||||||
let rx_transfer_ref = rx_transfer.as_ref().unwrap();
|
let mut tm_packet = TmPacket::new();
|
||||||
// Received a partial packet.
|
let tm_size = tm_size(&tm_header, &response);
|
||||||
if rx_transfer_ref.is_event_triggered(RxEvent::Idle) {
|
tm_packet.resize(tm_size, 0).expect("vec resize failed");
|
||||||
let rx_transfer_owned = rx_transfer.take().unwrap();
|
create_tm_packet(&mut tm_packet, sp_header, tm_header, response)?;
|
||||||
let (buf, ch, mut rx, rx_len) = rx_transfer_owned.stop_and_return_received_bytes();
|
if TM_QUEUE.enqueue(tm_packet).is_err() {
|
||||||
// The received data is transferred to another task now to avoid any processing overhead
|
defmt::warn!("TC queue full");
|
||||||
// during the interrupt. There are multiple ways to do this, we use a stack
|
return Err(TmSendError::Queue);
|
||||||
// allocated vector to do this.
|
}
|
||||||
tc_packet
|
Ok(())
|
||||||
.resize(rx_len as usize, 0)
|
}
|
||||||
.expect("vec resize failed");
|
|
||||||
tc_packet[0..rx_len as usize].copy_from_slice(&buf[0..rx_len as usize]);
|
// same panicking *behavior* as `panic-probe` but doesn't print a panic message
|
||||||
rx.clear_event(RxEvent::Idle);
|
// this prevents the panic message being printed *twice* when `defmt::panic` is invoked
|
||||||
serial_rx_handler::spawn(tc_packet).expect("spawning rx handler failed");
|
#[defmt::panic_handler]
|
||||||
*rx_transfer = Some(rx.read_exact(buf, ch));
|
fn panic() -> ! {
|
||||||
}
|
cortex_m::asm::udf()
|
||||||
});
|
}
|
||||||
|
|
||||||
|
/// Terminates the application and makes a semihosting-capable debug tool exit
|
||||||
|
/// with status code 0.
|
||||||
|
pub fn exit() -> ! {
|
||||||
|
loop {
|
||||||
|
debug::exit(EXIT_SUCCESS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Hardfault handler.
|
||||||
|
///
|
||||||
|
/// Terminates the application and makes a semihosting-capable debug tool exit
|
||||||
|
/// with an error. This seems better than the default, which is to spin in a
|
||||||
|
/// loop.
|
||||||
|
#[cortex_m_rt::exception]
|
||||||
|
unsafe fn HardFault(_frame: &cortex_m_rt::ExceptionFrame) -> ! {
|
||||||
|
loop {
|
||||||
|
debug::exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// defmt-test 0.3.0 has the limitation that this `#[tests]` attribute can only be used
|
||||||
|
// once within a crate. the module can be in any file but there can only be at most
|
||||||
|
// one `#[tests]` module in this library crate
|
||||||
|
#[cfg(test)]
|
||||||
|
#[defmt_test::tests]
|
||||||
|
mod unit_tests {
|
||||||
|
use defmt::assert;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn it_works() {
|
||||||
|
assert!(true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
641
embedded-examples/stm32h7-nucleo-rtic/Cargo.lock
generated
641
embedded-examples/stm32h7-nucleo-rtic/Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -16,16 +16,17 @@ harness = false
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
cortex-m = { version = "0.7", features = ["critical-section-single-core"] }
|
cortex-m = { version = "0.7", features = ["critical-section-single-core"] }
|
||||||
cortex-m-rt = "0.7"
|
cortex-m-rt = "0.7"
|
||||||
defmt = "0.3"
|
defmt = "1"
|
||||||
defmt-brtt = { version = "0.1", default-features = false, features = ["rtt"] }
|
defmt-brtt = { version = "0.1", default-features = false, features = ["rtt"] }
|
||||||
panic-probe = { version = "0.3", features = ["print-defmt"] }
|
panic-probe = { version = "1", features = ["print-defmt"] }
|
||||||
cortex-m-semihosting = "0.5.0"
|
cortex-m-semihosting = "0.5.0"
|
||||||
|
# TODO: Replace with embassy-hal.
|
||||||
stm32h7xx-hal = { version="0.16", features= ["stm32h743v", "ethernet"] }
|
stm32h7xx-hal = { version="0.16", features= ["stm32h743v", "ethernet"] }
|
||||||
embedded-alloc = "0.6"
|
embedded-alloc = "0.6"
|
||||||
rtic-sync = { version = "1", features = ["defmt-03"] }
|
rtic-sync = { version = "1", features = ["defmt-03"] }
|
||||||
|
|
||||||
[dependencies.smoltcp]
|
[dependencies.smoltcp]
|
||||||
version = "0.11"
|
version = "0.12"
|
||||||
default-features = false
|
default-features = false
|
||||||
features = ["medium-ethernet", "proto-ipv4", "socket-raw", "socket-dhcpv4", "socket-udp", "defmt"]
|
features = ["medium-ethernet", "proto-ipv4", "socket-raw", "socket-dhcpv4", "socket-udp", "defmt"]
|
||||||
|
|
||||||
@@ -39,12 +40,12 @@ features = ["cortex-m-systick"]
|
|||||||
|
|
||||||
[dependencies.satrs]
|
[dependencies.satrs]
|
||||||
path = "../../satrs"
|
path = "../../satrs"
|
||||||
version = "0.2"
|
# version = "0.2"
|
||||||
default-features = false
|
default-features = false
|
||||||
features = ["defmt", "heapless"]
|
features = ["defmt", "heapless"]
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
defmt-test = "0.3"
|
defmt-test = "0.4"
|
||||||
|
|
||||||
# cargo build/run
|
# cargo build/run
|
||||||
[profile.dev]
|
[profile.dev]
|
||||||
|
|||||||
@@ -507,9 +507,7 @@ impl VerificationReportCreator {
|
|||||||
self.dest_id = dest_id;
|
self.dest_id = dest_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Initialize verification handling by passing a TC reference. This returns a token required
|
pub fn read_request_id(&self, pus_tc: &(impl CcsdsPacket + IsPusTelecommand)) -> RequestId {
|
||||||
/// to call the acceptance functions
|
|
||||||
pub fn read_request_id_from_tc(pus_tc: &(impl CcsdsPacket + IsPusTelecommand)) -> RequestId {
|
|
||||||
RequestId::new(pus_tc)
|
RequestId::new(pus_tc)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -897,7 +895,7 @@ pub mod alloc_mod {
|
|||||||
> {
|
> {
|
||||||
owner_id: ComponentId,
|
owner_id: ComponentId,
|
||||||
source_data_buf: RefCell<alloc::vec::Vec<u8>>,
|
source_data_buf: RefCell<alloc::vec::Vec<u8>>,
|
||||||
pub reporter_creator: VerificationReportCreator,
|
pub report_creator: VerificationReportCreator,
|
||||||
pub tm_hook: VerificationHookInstance,
|
pub tm_hook: VerificationHookInstance,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -913,7 +911,7 @@ pub mod alloc_mod {
|
|||||||
+ cfg.fail_code_field_width
|
+ cfg.fail_code_field_width
|
||||||
+ cfg.max_fail_data_len
|
+ cfg.max_fail_data_len
|
||||||
]),
|
]),
|
||||||
reporter_creator: reporter,
|
report_creator: reporter,
|
||||||
tm_hook: DummyVerificationHook::default(),
|
tm_hook: DummyVerificationHook::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -937,7 +935,7 @@ pub mod alloc_mod {
|
|||||||
+ cfg.fail_code_field_width
|
+ cfg.fail_code_field_width
|
||||||
+ cfg.max_fail_data_len
|
+ cfg.max_fail_data_len
|
||||||
]),
|
]),
|
||||||
reporter_creator: reporter,
|
report_creator: reporter,
|
||||||
tm_hook,
|
tm_hook,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -946,9 +944,7 @@ pub mod alloc_mod {
|
|||||||
&self,
|
&self,
|
||||||
pus_tc: &(impl CcsdsPacket + IsPusTelecommand),
|
pus_tc: &(impl CcsdsPacket + IsPusTelecommand),
|
||||||
) -> VerificationToken<TcStateNone> {
|
) -> VerificationToken<TcStateNone> {
|
||||||
VerificationToken::<TcStateNone>::new(
|
VerificationToken::<TcStateNone>::new(self.report_creator.read_request_id(pus_tc))
|
||||||
VerificationReportCreator::read_request_id_from_tc(pus_tc),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn start_verification_with_req_id(
|
pub fn start_verification_with_req_id(
|
||||||
@@ -976,7 +972,7 @@ pub mod alloc_mod {
|
|||||||
for VerificationReporter<VerificationHookInstance>
|
for VerificationReporter<VerificationHookInstance>
|
||||||
{
|
{
|
||||||
delegate!(
|
delegate!(
|
||||||
to self.reporter_creator {
|
to self.report_creator {
|
||||||
fn set_apid(&mut self, apid: Apid);
|
fn set_apid(&mut self, apid: Apid);
|
||||||
fn apid(&self) -> Apid;
|
fn apid(&self) -> Apid;
|
||||||
}
|
}
|
||||||
@@ -1002,7 +998,7 @@ pub mod alloc_mod {
|
|||||||
) -> Result<VerificationToken<TcStateAccepted>, EcssTmtcError> {
|
) -> Result<VerificationToken<TcStateAccepted>, EcssTmtcError> {
|
||||||
let mut source_data_buf = self.source_data_buf.borrow_mut();
|
let mut source_data_buf = self.source_data_buf.borrow_mut();
|
||||||
let mut tm_creator = self
|
let mut tm_creator = self
|
||||||
.reporter_creator
|
.report_creator
|
||||||
.acceptance_success(
|
.acceptance_success(
|
||||||
source_data_buf.as_mut_slice(),
|
source_data_buf.as_mut_slice(),
|
||||||
&token.request_id(),
|
&token.request_id(),
|
||||||
@@ -1102,7 +1098,7 @@ pub mod alloc_mod {
|
|||||||
) -> Result<(), EcssTmtcError> {
|
) -> Result<(), EcssTmtcError> {
|
||||||
let mut buf = self.source_data_buf.borrow_mut();
|
let mut buf = self.source_data_buf.borrow_mut();
|
||||||
let mut tm_creator = self
|
let mut tm_creator = self
|
||||||
.reporter_creator
|
.report_creator
|
||||||
.step_success(
|
.step_success(
|
||||||
buf.as_mut_slice(),
|
buf.as_mut_slice(),
|
||||||
&token.request_id(),
|
&token.request_id(),
|
||||||
|
|||||||
Reference in New Issue
Block a user