Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Yann/exploration/get deep sleep stats for every spikes #1396

Draft
wants to merge 5 commits into
base: develop
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Add watchdog for every spike
YannLocatelli committed Feb 9, 2024

Verified

This commit was signed with the committer’s verified signature.
commit 185a052e553b19459686d7168efa81827f20b1b0
106 changes: 105 additions & 1 deletion spikes/lk_activity_kit/main.cpp
Original file line number Diff line number Diff line change
@@ -59,8 +59,99 @@
using namespace leka;
using namespace std::chrono;

#include "mbed_stats.h"

#include "drivers/Watchdog.h"
namespace {

namespace watchdog {

namespace internal {

auto &instance = mbed::Watchdog::get_instance();
constexpr auto timeout = 30000ms;
auto thread = rtos::Thread {osPriorityLow};

namespace stats {

auto cpu = mbed_stats_cpu_t {};
auto stack = mbed_stats_stack_t {};
auto heap = mbed_stats_heap_t {};

} // namespace stats

__attribute__((noreturn)) void watchdog_kick()
{
static auto kick_count = uint32_t {0};

static auto start = rtos::Kernel::Clock::now();
static auto stop = rtos::Kernel::Clock::now();
static auto delta = static_cast<int>((stop - start).count());

static auto idle_ratio = uint8_t {};
static auto sleep_ratio = uint8_t {};
static auto deep_sleep_ratio = uint8_t {};

static auto stack_used_delta = int32_t {};
static auto stack_used_size = uint32_t {};
static auto stack_reserved_size = uint32_t {};
static auto stack_used_ratio = uint8_t {};

static auto heap_used_delta = int32_t {};
static auto heap_used_size = uint32_t {};
static auto heap_reserved_size = uint32_t {};
static auto heap_used_ratio = uint8_t {};

while (true) {
internal::instance.kick();
++kick_count;

stop = rtos::Kernel::Clock::now();
delta = static_cast<int>((stop - start).count());

mbed_stats_cpu_get(&stats::cpu);

idle_ratio = static_cast<uint8_t>(((stats::cpu.idle_time / 1000 * 100) / (stats::cpu.uptime / 1000)));
sleep_ratio = static_cast<uint8_t>(((stats::cpu.sleep_time / 1000 * 100) / (stats::cpu.uptime / 1000)));
deep_sleep_ratio =
static_cast<uint8_t>(((stats::cpu.deep_sleep_time / 1000 * 100) / (stats::cpu.uptime / 1000)));

mbed_stats_stack_get(&stats::stack);

stack_used_delta = static_cast<int32_t>(stats::stack.max_size - stack_used_size);
stack_used_size = stats::stack.max_size;
stack_reserved_size = stats::stack.reserved_size;
stack_used_ratio = static_cast<uint8_t>((stack_used_size * 100) / stack_reserved_size);

mbed_stats_heap_get(&stats::heap);

heap_used_delta = static_cast<int32_t>(stats::heap.current_size - heap_used_size);
heap_used_size = stats::heap.current_size;
heap_reserved_size = stats::heap.reserved_size;
heap_used_ratio = static_cast<uint8_t>((heap_used_size * 100) / heap_reserved_size);

log_info(
"dt: %i, kck: %u, idl: %u%%, slp: %u%%, dsl: %u%%, sur: %u%% (%+i)[%u/"
"%u], hur: %u%% (%+i)[%u/%u]",
delta, kick_count, idle_ratio, sleep_ratio, deep_sleep_ratio, stack_used_ratio, stack_used_delta,
stack_used_size, stack_reserved_size, heap_used_ratio, heap_used_delta, heap_used_size,
heap_reserved_size);

start = rtos::Kernel::Clock::now();
rtos::ThisThread::sleep_for(5s);
}
}

} // namespace internal

void start()
{
internal::instance.start(internal::timeout.count());
internal::thread.start(watchdog::internal::watchdog_kick);
}

} // namespace watchdog

namespace sd {

namespace internal {
@@ -262,6 +353,7 @@ auto activitykit = ActivityKit {videokit};
auto main() -> int
{
logger::init();
watchdog::start();

log_info("Hello, World!\n\n");

@@ -293,8 +385,20 @@ auto main() -> int
activitykit.start(card);
});

while (true) {
{
log_info("Still alive");
rtos::ThisThread::sleep_for(10s);
}

activitykit.stop();
rtos::ThisThread::sleep_for(1s);

rfidkit.enableDeepSleep();
display::internal::corelcd.enableDeepSleep();
motors::left::motor.enableDeepSleep();
motors::right::motor.enableDeepSleep();

while (true) {
rtos::ThisThread::sleep_for(10min);
}
}
105 changes: 103 additions & 2 deletions spikes/lk_audio/main.cpp
Original file line number Diff line number Diff line change
@@ -19,6 +19,101 @@
using namespace leka;
using namespace std::chrono_literals;

#include "mbed_stats.h"

#include "drivers/Watchdog.h"
namespace {

namespace watchdog {

namespace internal {

auto &instance = mbed::Watchdog::get_instance();
constexpr auto timeout = 30000ms;
auto thread = rtos::Thread {osPriorityLow};

namespace stats {

auto cpu = mbed_stats_cpu_t {};
auto stack = mbed_stats_stack_t {};
auto heap = mbed_stats_heap_t {};

} // namespace stats

__attribute__((noreturn)) void watchdog_kick()
{
static auto kick_count = uint32_t {0};

static auto start = rtos::Kernel::Clock::now();
static auto stop = rtos::Kernel::Clock::now();
static auto delta = static_cast<int>((stop - start).count());

static auto idle_ratio = uint8_t {};
static auto sleep_ratio = uint8_t {};
static auto deep_sleep_ratio = uint8_t {};

static auto stack_used_delta = int32_t {};
static auto stack_used_size = uint32_t {};
static auto stack_reserved_size = uint32_t {};
static auto stack_used_ratio = uint8_t {};

static auto heap_used_delta = int32_t {};
static auto heap_used_size = uint32_t {};
static auto heap_reserved_size = uint32_t {};
static auto heap_used_ratio = uint8_t {};

while (true) {
internal::instance.kick();
++kick_count;

stop = rtos::Kernel::Clock::now();
delta = static_cast<int>((stop - start).count());

mbed_stats_cpu_get(&stats::cpu);

idle_ratio = static_cast<uint8_t>(((stats::cpu.idle_time / 1000 * 100) / (stats::cpu.uptime / 1000)));
sleep_ratio = static_cast<uint8_t>(((stats::cpu.sleep_time / 1000 * 100) / (stats::cpu.uptime / 1000)));
deep_sleep_ratio =
static_cast<uint8_t>(((stats::cpu.deep_sleep_time / 1000 * 100) / (stats::cpu.uptime / 1000)));

mbed_stats_stack_get(&stats::stack);

stack_used_delta = static_cast<int32_t>(stats::stack.max_size - stack_used_size);
stack_used_size = stats::stack.max_size;
stack_reserved_size = stats::stack.reserved_size;
stack_used_ratio = static_cast<uint8_t>((stack_used_size * 100) / stack_reserved_size);

mbed_stats_heap_get(&stats::heap);

heap_used_delta = static_cast<int32_t>(stats::heap.current_size - heap_used_size);
heap_used_size = stats::heap.current_size;
heap_reserved_size = stats::heap.reserved_size;
heap_used_ratio = static_cast<uint8_t>((heap_used_size * 100) / heap_reserved_size);

log_info(
"dt: %i, kck: %u, idl: %u%%, slp: %u%%, dsl: %u%%, sur: %u%% (%+i)[%u/"
"%u], hur: %u%% (%+i)[%u/%u]",
delta, kick_count, idle_ratio, sleep_ratio, deep_sleep_ratio, stack_used_ratio, stack_used_delta,
stack_used_size, stack_reserved_size, heap_used_ratio, heap_used_delta, heap_used_size,
heap_reserved_size);

start = rtos::Kernel::Clock::now();
rtos::ThisThread::sleep_for(5s);
}
}

} // namespace internal

void start()
{
internal::instance.start(internal::timeout.count());
internal::thread.start(watchdog::internal::watchdog_kick);
}

} // namespace watchdog

} // namespace

auto sd_bd = SDBlockDevice {SD_SPI_MOSI, SD_SPI_MISO, SD_SPI_SCK};
auto fatfs = FATFileSystem {"fs"};

@@ -68,6 +163,7 @@ void playSound()
auto main() -> int
{
logger::init();
watchdog::start();

log_info("Hello, World!\n\n");

@@ -77,11 +173,16 @@ auto main() -> int
return 1;
}

while (true) {
{
file.open(sound_file_path);
playSound();
// playSound();
audio_output.write_u16(0xFFFF);
file.close();

rtos::ThisThread::sleep_for(1s);
}

while (true) {
rtos::ThisThread::sleep_for(10min);
}
}
103 changes: 102 additions & 1 deletion spikes/lk_behavior_kit/main.cpp
Original file line number Diff line number Diff line change
@@ -41,8 +41,98 @@ using namespace std::chrono;
// MARK: - Global definitions
//

#include "mbed_stats.h"

#include "drivers/Watchdog.h"
namespace {

namespace watchdog {

namespace internal {

auto &instance = mbed::Watchdog::get_instance();
constexpr auto timeout = 30000ms;
auto thread = rtos::Thread {osPriorityLow};

namespace stats {

auto cpu = mbed_stats_cpu_t {};
auto stack = mbed_stats_stack_t {};
auto heap = mbed_stats_heap_t {};

} // namespace stats

__attribute__((noreturn)) void watchdog_kick()
{
static auto kick_count = uint32_t {0};

static auto start = rtos::Kernel::Clock::now();
static auto stop = rtos::Kernel::Clock::now();
static auto delta = static_cast<int>((stop - start).count());

static auto idle_ratio = uint8_t {};
static auto sleep_ratio = uint8_t {};
static auto deep_sleep_ratio = uint8_t {};

static auto stack_used_delta = int32_t {};
static auto stack_used_size = uint32_t {};
static auto stack_reserved_size = uint32_t {};
static auto stack_used_ratio = uint8_t {};

static auto heap_used_delta = int32_t {};
static auto heap_used_size = uint32_t {};
static auto heap_reserved_size = uint32_t {};
static auto heap_used_ratio = uint8_t {};

while (true) {
internal::instance.kick();
++kick_count;

stop = rtos::Kernel::Clock::now();
delta = static_cast<int>((stop - start).count());

mbed_stats_cpu_get(&stats::cpu);

idle_ratio = static_cast<uint8_t>(((stats::cpu.idle_time / 1000 * 100) / (stats::cpu.uptime / 1000)));
sleep_ratio = static_cast<uint8_t>(((stats::cpu.sleep_time / 1000 * 100) / (stats::cpu.uptime / 1000)));
deep_sleep_ratio =
static_cast<uint8_t>(((stats::cpu.deep_sleep_time / 1000 * 100) / (stats::cpu.uptime / 1000)));

mbed_stats_stack_get(&stats::stack);

stack_used_delta = static_cast<int32_t>(stats::stack.max_size - stack_used_size);
stack_used_size = stats::stack.max_size;
stack_reserved_size = stats::stack.reserved_size;
stack_used_ratio = static_cast<uint8_t>((stack_used_size * 100) / stack_reserved_size);

mbed_stats_heap_get(&stats::heap);

heap_used_delta = static_cast<int32_t>(stats::heap.current_size - heap_used_size);
heap_used_size = stats::heap.current_size;
heap_reserved_size = stats::heap.reserved_size;
heap_used_ratio = static_cast<uint8_t>((heap_used_size * 100) / heap_reserved_size);

log_info(
"dt: %i, kck: %u, idl: %u%%, slp: %u%%, dsl: %u%%, sur: %u%% (%+i)[%u/"
"%u], hur: %u%% (%+i)[%u/%u]",
delta, kick_count, idle_ratio, sleep_ratio, deep_sleep_ratio, stack_used_ratio, stack_used_delta,
stack_used_size, stack_reserved_size, heap_used_ratio, heap_used_delta, heap_used_size,
heap_reserved_size);

start = rtos::Kernel::Clock::now();
rtos::ThisThread::sleep_for(5s);
}
}

} // namespace internal

void start()
{
internal::instance.start(internal::timeout.count());
internal::thread.start(watchdog::internal::watchdog_kick);
}

} // namespace watchdog
namespace sd {

namespace internal {
@@ -180,6 +270,7 @@ auto hello = HelloWorld {};
auto main() -> int
{
logger::init();
watchdog::start();

leds::turnOff();
motors::turnOff();
@@ -193,7 +284,7 @@ auto main() -> int

hello.start();

while (true) {
{
behaviorkit.launching();
rtos::ThisThread::sleep_for(10s);
behaviorkit.stop();
@@ -204,4 +295,14 @@ auto main() -> int
behaviorkit.stop();
rtos::ThisThread::sleep_for(3s);
}

behaviorkit.stop();

display::internal::corelcd.enableDeepSleep();
motors::left::motor.enableDeepSleep();
motors::right::motor.enableDeepSleep();

while (true) {
rtos::ThisThread::sleep_for(10min);
}
}
112 changes: 101 additions & 11 deletions spikes/lk_ble/main.cpp
Original file line number Diff line number Diff line change
@@ -22,6 +22,101 @@
using namespace leka;
using namespace std::chrono;

#include "mbed_stats.h"

#include "drivers/Watchdog.h"
namespace {

namespace watchdog {

namespace internal {

auto &instance = mbed::Watchdog::get_instance();
constexpr auto timeout = 30000ms;
auto thread = rtos::Thread {osPriorityLow};

namespace stats {

auto cpu = mbed_stats_cpu_t {};
auto stack = mbed_stats_stack_t {};
auto heap = mbed_stats_heap_t {};

} // namespace stats

__attribute__((noreturn)) void watchdog_kick()
{
static auto kick_count = uint32_t {0};

static auto start = rtos::Kernel::Clock::now();
static auto stop = rtos::Kernel::Clock::now();
static auto delta = static_cast<int>((stop - start).count());

static auto idle_ratio = uint8_t {};
static auto sleep_ratio = uint8_t {};
static auto deep_sleep_ratio = uint8_t {};

static auto stack_used_delta = int32_t {};
static auto stack_used_size = uint32_t {};
static auto stack_reserved_size = uint32_t {};
static auto stack_used_ratio = uint8_t {};

static auto heap_used_delta = int32_t {};
static auto heap_used_size = uint32_t {};
static auto heap_reserved_size = uint32_t {};
static auto heap_used_ratio = uint8_t {};

while (true) {
internal::instance.kick();
++kick_count;

stop = rtos::Kernel::Clock::now();
delta = static_cast<int>((stop - start).count());

mbed_stats_cpu_get(&stats::cpu);

idle_ratio = static_cast<uint8_t>(((stats::cpu.idle_time / 1000 * 100) / (stats::cpu.uptime / 1000)));
sleep_ratio = static_cast<uint8_t>(((stats::cpu.sleep_time / 1000 * 100) / (stats::cpu.uptime / 1000)));
deep_sleep_ratio =
static_cast<uint8_t>(((stats::cpu.deep_sleep_time / 1000 * 100) / (stats::cpu.uptime / 1000)));

mbed_stats_stack_get(&stats::stack);

stack_used_delta = static_cast<int32_t>(stats::stack.max_size - stack_used_size);
stack_used_size = stats::stack.max_size;
stack_reserved_size = stats::stack.reserved_size;
stack_used_ratio = static_cast<uint8_t>((stack_used_size * 100) / stack_reserved_size);

mbed_stats_heap_get(&stats::heap);

heap_used_delta = static_cast<int32_t>(stats::heap.current_size - heap_used_size);
heap_used_size = stats::heap.current_size;
heap_reserved_size = stats::heap.reserved_size;
heap_used_ratio = static_cast<uint8_t>((heap_used_size * 100) / heap_reserved_size);

log_info(
"dt: %i, kck: %u, idl: %u%%, slp: %u%%, dsl: %u%%, sur: %u%% (%+i)[%u/"
"%u], hur: %u%% (%+i)[%u/%u]",
delta, kick_count, idle_ratio, sleep_ratio, deep_sleep_ratio, stack_used_ratio, stack_used_delta,
stack_used_size, stack_reserved_size, heap_used_ratio, heap_used_delta, heap_used_size,
heap_reserved_size);

start = rtos::Kernel::Clock::now();
rtos::ThisThread::sleep_for(5s);
}
}

} // namespace internal

void start()
{
internal::instance.start(internal::timeout.count());
internal::thread.start(watchdog::internal::watchdog_kick);
}

} // namespace watchdog

} // namespace

auto level = uint8_t {0};
auto charging_status = bool {false};

@@ -53,6 +148,7 @@ void initializeSD()
auto main() -> int
{
logger::init();
watchdog::start();

log_info("Hello, World!\n\n");

@@ -81,9 +177,9 @@ auto main() -> int
service_file_exchange.onFileDataReceived(
[](std::span<const uint8_t> buffer) { file_reception_handler.onPacketReceived(buffer); });

while (true) {
{
log_info("Main thread running...");
rtos::ThisThread::sleep_for(5s);
rtos::ThisThread::sleep_for(1s);

log_info("Is connected: %d", blekit.isConnected());

@@ -97,15 +193,9 @@ auto main() -> int

auto version = service_update.getVersion();
log_info("Requested version: %d.%d.%d", version.major, version.minor, version.revision);
}

auto advertising_data = blekit.getAdvertisingData();
advertising_data.name = "NewLeka";
advertising_data.battery = level;
advertising_data.is_charging = charging_status;
advertising_data.version_major = uint8_t {0x01};
advertising_data.version_minor = uint8_t {0x02};
advertising_data.version_revision = uint16_t {0x0304};

blekit.setAdvertisingData(advertising_data);
while (true) {
rtos::ThisThread::sleep_for(10min);
}
}
98 changes: 97 additions & 1 deletion spikes/lk_bluetooth/main.cpp
Original file line number Diff line number Diff line change
@@ -12,11 +12,107 @@
using namespace leka;
using namespace std::chrono;

#include "mbed_stats.h"

#include "drivers/Watchdog.h"
namespace {

namespace watchdog {

namespace internal {

auto &instance = mbed::Watchdog::get_instance();
constexpr auto timeout = 30000ms;
auto thread = rtos::Thread {osPriorityLow};

namespace stats {

auto cpu = mbed_stats_cpu_t {};
auto stack = mbed_stats_stack_t {};
auto heap = mbed_stats_heap_t {};

} // namespace stats

__attribute__((noreturn)) void watchdog_kick()
{
static auto kick_count = uint32_t {0};

static auto start = rtos::Kernel::Clock::now();
static auto stop = rtos::Kernel::Clock::now();
static auto delta = static_cast<int>((stop - start).count());

static auto idle_ratio = uint8_t {};
static auto sleep_ratio = uint8_t {};
static auto deep_sleep_ratio = uint8_t {};

static auto stack_used_delta = int32_t {};
static auto stack_used_size = uint32_t {};
static auto stack_reserved_size = uint32_t {};
static auto stack_used_ratio = uint8_t {};

static auto heap_used_delta = int32_t {};
static auto heap_used_size = uint32_t {};
static auto heap_reserved_size = uint32_t {};
static auto heap_used_ratio = uint8_t {};

while (true) {
internal::instance.kick();
++kick_count;

stop = rtos::Kernel::Clock::now();
delta = static_cast<int>((stop - start).count());

mbed_stats_cpu_get(&stats::cpu);

idle_ratio = static_cast<uint8_t>(((stats::cpu.idle_time / 1000 * 100) / (stats::cpu.uptime / 1000)));
sleep_ratio = static_cast<uint8_t>(((stats::cpu.sleep_time / 1000 * 100) / (stats::cpu.uptime / 1000)));
deep_sleep_ratio =
static_cast<uint8_t>(((stats::cpu.deep_sleep_time / 1000 * 100) / (stats::cpu.uptime / 1000)));

mbed_stats_stack_get(&stats::stack);

stack_used_delta = static_cast<int32_t>(stats::stack.max_size - stack_used_size);
stack_used_size = stats::stack.max_size;
stack_reserved_size = stats::stack.reserved_size;
stack_used_ratio = static_cast<uint8_t>((stack_used_size * 100) / stack_reserved_size);

mbed_stats_heap_get(&stats::heap);

heap_used_delta = static_cast<int32_t>(stats::heap.current_size - heap_used_size);
heap_used_size = stats::heap.current_size;
heap_reserved_size = stats::heap.reserved_size;
heap_used_ratio = static_cast<uint8_t>((heap_used_size * 100) / heap_reserved_size);

log_info(
"dt: %i, kck: %u, idl: %u%%, slp: %u%%, dsl: %u%%, sur: %u%% (%+i)[%u/"
"%u], hur: %u%% (%+i)[%u/%u]",
delta, kick_count, idle_ratio, sleep_ratio, deep_sleep_ratio, stack_used_ratio, stack_used_delta,
stack_used_size, stack_reserved_size, heap_used_ratio, heap_used_delta, heap_used_size,
heap_reserved_size);

start = rtos::Kernel::Clock::now();
rtos::ThisThread::sleep_for(5s);
}
}

} // namespace internal

void start()
{
internal::instance.start(internal::timeout.count());
internal::thread.start(watchdog::internal::watchdog_kick);
}

} // namespace watchdog

} // namespace

auto audio_enable = mbed::DigitalOut {SOUND_ENABLE, 1};

auto main() -> int
{
logger::init();
watchdog::start();

log_info("Hello, World!\n\n");

@@ -30,6 +126,6 @@ auto main() -> int
bluetooth.start();

while (true) {
rtos::ThisThread::sleep_for(10s);
rtos::ThisThread::sleep_for(10min);
}
}
104 changes: 103 additions & 1 deletion spikes/lk_cg_animations/main.cpp
Original file line number Diff line number Diff line change
@@ -34,6 +34,101 @@
using namespace leka;
using namespace std::chrono;

#include "mbed_stats.h"

#include "drivers/Watchdog.h"
namespace {

namespace watchdog {

namespace internal {

auto &instance = mbed::Watchdog::get_instance();
constexpr auto timeout = 30000ms;
auto thread = rtos::Thread {osPriorityLow};

namespace stats {

auto cpu = mbed_stats_cpu_t {};
auto stack = mbed_stats_stack_t {};
auto heap = mbed_stats_heap_t {};

} // namespace stats

__attribute__((noreturn)) void watchdog_kick()
{
static auto kick_count = uint32_t {0};

static auto start = rtos::Kernel::Clock::now();
static auto stop = rtos::Kernel::Clock::now();
static auto delta = static_cast<int>((stop - start).count());

static auto idle_ratio = uint8_t {};
static auto sleep_ratio = uint8_t {};
static auto deep_sleep_ratio = uint8_t {};

static auto stack_used_delta = int32_t {};
static auto stack_used_size = uint32_t {};
static auto stack_reserved_size = uint32_t {};
static auto stack_used_ratio = uint8_t {};

static auto heap_used_delta = int32_t {};
static auto heap_used_size = uint32_t {};
static auto heap_reserved_size = uint32_t {};
static auto heap_used_ratio = uint8_t {};

while (true) {
internal::instance.kick();
++kick_count;

stop = rtos::Kernel::Clock::now();
delta = static_cast<int>((stop - start).count());

mbed_stats_cpu_get(&stats::cpu);

idle_ratio = static_cast<uint8_t>(((stats::cpu.idle_time / 1000 * 100) / (stats::cpu.uptime / 1000)));
sleep_ratio = static_cast<uint8_t>(((stats::cpu.sleep_time / 1000 * 100) / (stats::cpu.uptime / 1000)));
deep_sleep_ratio =
static_cast<uint8_t>(((stats::cpu.deep_sleep_time / 1000 * 100) / (stats::cpu.uptime / 1000)));

mbed_stats_stack_get(&stats::stack);

stack_used_delta = static_cast<int32_t>(stats::stack.max_size - stack_used_size);
stack_used_size = stats::stack.max_size;
stack_reserved_size = stats::stack.reserved_size;
stack_used_ratio = static_cast<uint8_t>((stack_used_size * 100) / stack_reserved_size);

mbed_stats_heap_get(&stats::heap);

heap_used_delta = static_cast<int32_t>(stats::heap.current_size - heap_used_size);
heap_used_size = stats::heap.current_size;
heap_reserved_size = stats::heap.reserved_size;
heap_used_ratio = static_cast<uint8_t>((heap_used_size * 100) / heap_reserved_size);

log_info(
"dt: %i, kck: %u, idl: %u%%, slp: %u%%, dsl: %u%%, sur: %u%% (%+i)[%u/"
"%u], hur: %u%% (%+i)[%u/%u]",
delta, kick_count, idle_ratio, sleep_ratio, deep_sleep_ratio, stack_used_ratio, stack_used_delta,
stack_used_size, stack_reserved_size, heap_used_ratio, heap_used_delta, heap_used_size,
heap_reserved_size);

start = rtos::Kernel::Clock::now();
rtos::ThisThread::sleep_for(5s);
}
}

} // namespace internal

void start()
{
internal::instance.start(internal::timeout.count());
internal::thread.start(watchdog::internal::watchdog_kick);
}

} // namespace watchdog

} // namespace

HelloWorld hello;

SDBlockDevice sd_blockdevice(SD_SPI_MOSI, SD_SPI_MISO, SD_SPI_SCK);
@@ -65,6 +160,7 @@ UIAnimationKit animationkit(animation_thread, animation_event_queue);
auto main() -> int
{
logger::init();
watchdog::start();

log_info("Hello, World!\n\n");

@@ -76,7 +172,7 @@ auto main() -> int

hello.start();

while (true) {
{
auto t = rtos::Kernel::Clock::now() - start;
log_info("A message from your board %s --> \"%s\" at %i s\n", MBED_CONF_APP_TARGET_NAME, hello.world,
int(t.count() / 1000));
@@ -87,4 +183,10 @@ auto main() -> int
animationkit.stop();
rtos::ThisThread::sleep_for(1s);
}

corelcd.enableDeepSleep();

while (true) {
rtos::ThisThread::sleep_for(10min);
}
}
98 changes: 97 additions & 1 deletion spikes/lk_color_kit/main.cpp
Original file line number Diff line number Diff line change
@@ -21,8 +21,99 @@ using namespace std::chrono;
// MARK: - Global definitions
//

#include "mbed_stats.h"

#include "drivers/Watchdog.h"
namespace {

namespace watchdog {

namespace internal {

auto &instance = mbed::Watchdog::get_instance();
constexpr auto timeout = 30000ms;
auto thread = rtos::Thread {osPriorityLow};

namespace stats {

auto cpu = mbed_stats_cpu_t {};
auto stack = mbed_stats_stack_t {};
auto heap = mbed_stats_heap_t {};

} // namespace stats

__attribute__((noreturn)) void watchdog_kick()
{
static auto kick_count = uint32_t {0};

static auto start = rtos::Kernel::Clock::now();
static auto stop = rtos::Kernel::Clock::now();
static auto delta = static_cast<int>((stop - start).count());

static auto idle_ratio = uint8_t {};
static auto sleep_ratio = uint8_t {};
static auto deep_sleep_ratio = uint8_t {};

static auto stack_used_delta = int32_t {};
static auto stack_used_size = uint32_t {};
static auto stack_reserved_size = uint32_t {};
static auto stack_used_ratio = uint8_t {};

static auto heap_used_delta = int32_t {};
static auto heap_used_size = uint32_t {};
static auto heap_reserved_size = uint32_t {};
static auto heap_used_ratio = uint8_t {};

while (true) {
internal::instance.kick();
++kick_count;

stop = rtos::Kernel::Clock::now();
delta = static_cast<int>((stop - start).count());

mbed_stats_cpu_get(&stats::cpu);

idle_ratio = static_cast<uint8_t>(((stats::cpu.idle_time / 1000 * 100) / (stats::cpu.uptime / 1000)));
sleep_ratio = static_cast<uint8_t>(((stats::cpu.sleep_time / 1000 * 100) / (stats::cpu.uptime / 1000)));
deep_sleep_ratio =
static_cast<uint8_t>(((stats::cpu.deep_sleep_time / 1000 * 100) / (stats::cpu.uptime / 1000)));

mbed_stats_stack_get(&stats::stack);

stack_used_delta = static_cast<int32_t>(stats::stack.max_size - stack_used_size);
stack_used_size = stats::stack.max_size;
stack_reserved_size = stats::stack.reserved_size;
stack_used_ratio = static_cast<uint8_t>((stack_used_size * 100) / stack_reserved_size);

mbed_stats_heap_get(&stats::heap);

heap_used_delta = static_cast<int32_t>(stats::heap.current_size - heap_used_size);
heap_used_size = stats::heap.current_size;
heap_reserved_size = stats::heap.reserved_size;
heap_used_ratio = static_cast<uint8_t>((heap_used_size * 100) / heap_reserved_size);

log_info(
"dt: %i, kck: %u, idl: %u%%, slp: %u%%, dsl: %u%%, sur: %u%% (%+i)[%u/"
"%u], hur: %u%% (%+i)[%u/%u]",
delta, kick_count, idle_ratio, sleep_ratio, deep_sleep_ratio, stack_used_ratio, stack_used_delta,
stack_used_size, stack_reserved_size, heap_used_ratio, heap_used_delta, heap_used_size,
heap_reserved_size);

start = rtos::Kernel::Clock::now();
rtos::ThisThread::sleep_for(5s);
}
}

} // namespace internal

void start()
{
internal::instance.start(internal::timeout.count());
internal::thread.start(watchdog::internal::watchdog_kick);
}

} // namespace watchdog

namespace leds {

namespace internal {
@@ -80,17 +171,22 @@ auto hello = HelloWorld {};
auto main() -> int
{
logger::init();
watchdog::start();
leds::turnOff();

hello.start();
log_info("Hello, World!\n\n");

rtos::ThisThread::sleep_for(2s);

while (true) {
{
leds::changeColors();
rtos::ThisThread::sleep_for(1s);
leds::turnOff();
rtos::ThisThread::sleep_for(1s);
}

while (true) {
rtos::ThisThread::sleep_for(10min);
}
}
106 changes: 105 additions & 1 deletion spikes/lk_command_kit/main.cpp
Original file line number Diff line number Diff line change
@@ -48,6 +48,101 @@
using namespace leka;
using namespace std::chrono;

#include "mbed_stats.h"

#include "drivers/Watchdog.h"
namespace {

namespace watchdog {

namespace internal {

auto &instance = mbed::Watchdog::get_instance();
constexpr auto timeout = 30000ms;
auto thread = rtos::Thread {osPriorityLow};

namespace stats {

auto cpu = mbed_stats_cpu_t {};
auto stack = mbed_stats_stack_t {};
auto heap = mbed_stats_heap_t {};

} // namespace stats

__attribute__((noreturn)) void watchdog_kick()
{
static auto kick_count = uint32_t {0};

static auto start = rtos::Kernel::Clock::now();
static auto stop = rtos::Kernel::Clock::now();
static auto delta = static_cast<int>((stop - start).count());

static auto idle_ratio = uint8_t {};
static auto sleep_ratio = uint8_t {};
static auto deep_sleep_ratio = uint8_t {};

static auto stack_used_delta = int32_t {};
static auto stack_used_size = uint32_t {};
static auto stack_reserved_size = uint32_t {};
static auto stack_used_ratio = uint8_t {};

static auto heap_used_delta = int32_t {};
static auto heap_used_size = uint32_t {};
static auto heap_reserved_size = uint32_t {};
static auto heap_used_ratio = uint8_t {};

while (true) {
internal::instance.kick();
++kick_count;

stop = rtos::Kernel::Clock::now();
delta = static_cast<int>((stop - start).count());

mbed_stats_cpu_get(&stats::cpu);

idle_ratio = static_cast<uint8_t>(((stats::cpu.idle_time / 1000 * 100) / (stats::cpu.uptime / 1000)));
sleep_ratio = static_cast<uint8_t>(((stats::cpu.sleep_time / 1000 * 100) / (stats::cpu.uptime / 1000)));
deep_sleep_ratio =
static_cast<uint8_t>(((stats::cpu.deep_sleep_time / 1000 * 100) / (stats::cpu.uptime / 1000)));

mbed_stats_stack_get(&stats::stack);

stack_used_delta = static_cast<int32_t>(stats::stack.max_size - stack_used_size);
stack_used_size = stats::stack.max_size;
stack_reserved_size = stats::stack.reserved_size;
stack_used_ratio = static_cast<uint8_t>((stack_used_size * 100) / stack_reserved_size);

mbed_stats_heap_get(&stats::heap);

heap_used_delta = static_cast<int32_t>(stats::heap.current_size - heap_used_size);
heap_used_size = stats::heap.current_size;
heap_reserved_size = stats::heap.reserved_size;
heap_used_ratio = static_cast<uint8_t>((heap_used_size * 100) / heap_reserved_size);

log_info(
"dt: %i, kck: %u, idl: %u%%, slp: %u%%, dsl: %u%%, sur: %u%% (%+i)[%u/"
"%u], hur: %u%% (%+i)[%u/%u]",
delta, kick_count, idle_ratio, sleep_ratio, deep_sleep_ratio, stack_used_ratio, stack_used_delta,
stack_used_size, stack_reserved_size, heap_used_ratio, heap_used_delta, heap_used_size,
heap_reserved_size);

start = rtos::Kernel::Clock::now();
rtos::ThisThread::sleep_for(5s);
}
}

} // namespace internal

void start()
{
internal::instance.start(internal::timeout.count());
internal::thread.start(watchdog::internal::watchdog_kick);
}

} // namespace watchdog

} // namespace

namespace leds {

namespace spi {
@@ -246,6 +341,7 @@ HelloWorld hello;
auto main() -> int
{
logger::init();
watchdog::start();

initializeSD();
display::videokit.initializeScreen();
@@ -267,7 +363,7 @@ auto main() -> int

hello.start();

while (true) {
{
log_debug("A message from your board %s --> \"%s\" at %ims", MBED_CONF_APP_TARGET_NAME, hello.world,
int(rtos::Kernel::Clock::now().time_since_epoch().count()));

@@ -278,4 +374,12 @@ auto main() -> int
turnOff();
}
}

display::internal::corelcd.enableDeepSleep();
motor::left.enableDeepSleep();
motor::right.enableDeepSleep();

while (true) {
rtos::ThisThread::sleep_for(10min);
}
}
104 changes: 102 additions & 2 deletions spikes/lk_config_kit/main.cpp
Original file line number Diff line number Diff line change
@@ -19,6 +19,101 @@
using namespace leka;
using namespace std::chrono_literals;

#include "mbed_stats.h"

#include "drivers/Watchdog.h"
namespace {

namespace watchdog {

namespace internal {

auto &instance = mbed::Watchdog::get_instance();
constexpr auto timeout = 30000ms;
auto thread = rtos::Thread {osPriorityLow};

namespace stats {

auto cpu = mbed_stats_cpu_t {};
auto stack = mbed_stats_stack_t {};
auto heap = mbed_stats_heap_t {};

} // namespace stats

__attribute__((noreturn)) void watchdog_kick()
{
static auto kick_count = uint32_t {0};

static auto start = rtos::Kernel::Clock::now();
static auto stop = rtos::Kernel::Clock::now();
static auto delta = static_cast<int>((stop - start).count());

static auto idle_ratio = uint8_t {};
static auto sleep_ratio = uint8_t {};
static auto deep_sleep_ratio = uint8_t {};

static auto stack_used_delta = int32_t {};
static auto stack_used_size = uint32_t {};
static auto stack_reserved_size = uint32_t {};
static auto stack_used_ratio = uint8_t {};

static auto heap_used_delta = int32_t {};
static auto heap_used_size = uint32_t {};
static auto heap_reserved_size = uint32_t {};
static auto heap_used_ratio = uint8_t {};

while (true) {
internal::instance.kick();
++kick_count;

stop = rtos::Kernel::Clock::now();
delta = static_cast<int>((stop - start).count());

mbed_stats_cpu_get(&stats::cpu);

idle_ratio = static_cast<uint8_t>(((stats::cpu.idle_time / 1000 * 100) / (stats::cpu.uptime / 1000)));
sleep_ratio = static_cast<uint8_t>(((stats::cpu.sleep_time / 1000 * 100) / (stats::cpu.uptime / 1000)));
deep_sleep_ratio =
static_cast<uint8_t>(((stats::cpu.deep_sleep_time / 1000 * 100) / (stats::cpu.uptime / 1000)));

mbed_stats_stack_get(&stats::stack);

stack_used_delta = static_cast<int32_t>(stats::stack.max_size - stack_used_size);
stack_used_size = stats::stack.max_size;
stack_reserved_size = stats::stack.reserved_size;
stack_used_ratio = static_cast<uint8_t>((stack_used_size * 100) / stack_reserved_size);

mbed_stats_heap_get(&stats::heap);

heap_used_delta = static_cast<int32_t>(stats::heap.current_size - heap_used_size);
heap_used_size = stats::heap.current_size;
heap_reserved_size = stats::heap.reserved_size;
heap_used_ratio = static_cast<uint8_t>((heap_used_size * 100) / heap_reserved_size);

log_info(
"dt: %i, kck: %u, idl: %u%%, slp: %u%%, dsl: %u%%, sur: %u%% (%+i)[%u/"
"%u], hur: %u%% (%+i)[%u/%u]",
delta, kick_count, idle_ratio, sleep_ratio, deep_sleep_ratio, stack_used_ratio, stack_used_delta,
stack_used_size, stack_reserved_size, heap_used_ratio, heap_used_delta, heap_used_size,
heap_reserved_size);

start = rtos::Kernel::Clock::now();
rtos::ThisThread::sleep_for(5s);
}
}

} // namespace internal

void start()
{
internal::instance.start(internal::timeout.count());
internal::thread.start(watchdog::internal::watchdog_kick);
}

} // namespace watchdog

} // namespace

SDBlockDevice sd_blockdevice(SD_SPI_MOSI, SD_SPI_MISO, SD_SPI_SCK);
FATFileSystem fatfs("fs");

@@ -38,6 +133,7 @@ void initializeSD()
auto main() -> int
{
logger::init();
watchdog::start();

log_info("Hello, World!\n\n");

@@ -55,7 +151,7 @@ auto main() -> int

rtos::ThisThread::sleep_for(1s);

while (true) {
{
auto t = rtos::Kernel::Clock::now() - start;
log_info("A message from your board %s --> \"%s\" at %i s", MBED_CONF_APP_TARGET_NAME, hello.world,
int(t.count() / 1000));
@@ -68,6 +164,10 @@ auto main() -> int
auto config_value = configkit.read(config_to_edit);
log_info("Config value : %d", config_value);

rtos::ThisThread::sleep_for(10s);
rtos::ThisThread::sleep_for(1s);
}

while (true) {
rtos::ThisThread::sleep_for(10min);
}
}
102 changes: 101 additions & 1 deletion spikes/lk_core_touch_sensor/main.cpp
Original file line number Diff line number Diff line change
@@ -21,6 +21,101 @@
using namespace leka;
using namespace std::chrono;

#include "mbed_stats.h"

#include "drivers/Watchdog.h"
namespace {

namespace watchdog {

namespace internal {

auto &instance = mbed::Watchdog::get_instance();
constexpr auto timeout = 30000ms;
auto thread = rtos::Thread {osPriorityLow};

namespace stats {

auto cpu = mbed_stats_cpu_t {};
auto stack = mbed_stats_stack_t {};
auto heap = mbed_stats_heap_t {};

} // namespace stats

__attribute__((noreturn)) void watchdog_kick()
{
static auto kick_count = uint32_t {0};

static auto start = rtos::Kernel::Clock::now();
static auto stop = rtos::Kernel::Clock::now();
static auto delta = static_cast<int>((stop - start).count());

static auto idle_ratio = uint8_t {};
static auto sleep_ratio = uint8_t {};
static auto deep_sleep_ratio = uint8_t {};

static auto stack_used_delta = int32_t {};
static auto stack_used_size = uint32_t {};
static auto stack_reserved_size = uint32_t {};
static auto stack_used_ratio = uint8_t {};

static auto heap_used_delta = int32_t {};
static auto heap_used_size = uint32_t {};
static auto heap_reserved_size = uint32_t {};
static auto heap_used_ratio = uint8_t {};

while (true) {
internal::instance.kick();
++kick_count;

stop = rtos::Kernel::Clock::now();
delta = static_cast<int>((stop - start).count());

mbed_stats_cpu_get(&stats::cpu);

idle_ratio = static_cast<uint8_t>(((stats::cpu.idle_time / 1000 * 100) / (stats::cpu.uptime / 1000)));
sleep_ratio = static_cast<uint8_t>(((stats::cpu.sleep_time / 1000 * 100) / (stats::cpu.uptime / 1000)));
deep_sleep_ratio =
static_cast<uint8_t>(((stats::cpu.deep_sleep_time / 1000 * 100) / (stats::cpu.uptime / 1000)));

mbed_stats_stack_get(&stats::stack);

stack_used_delta = static_cast<int32_t>(stats::stack.max_size - stack_used_size);
stack_used_size = stats::stack.max_size;
stack_reserved_size = stats::stack.reserved_size;
stack_used_ratio = static_cast<uint8_t>((stack_used_size * 100) / stack_reserved_size);

mbed_stats_heap_get(&stats::heap);

heap_used_delta = static_cast<int32_t>(stats::heap.current_size - heap_used_size);
heap_used_size = stats::heap.current_size;
heap_reserved_size = stats::heap.reserved_size;
heap_used_ratio = static_cast<uint8_t>((heap_used_size * 100) / heap_reserved_size);

log_info(
"dt: %i, kck: %u, idl: %u%%, slp: %u%%, dsl: %u%%, sur: %u%% (%+i)[%u/"
"%u], hur: %u%% (%+i)[%u/%u]",
delta, kick_count, idle_ratio, sleep_ratio, deep_sleep_ratio, stack_used_ratio, stack_used_delta,
stack_used_size, stack_reserved_size, heap_used_ratio, heap_used_delta, heap_used_size,
heap_reserved_size);

start = rtos::Kernel::Clock::now();
rtos::ThisThread::sleep_for(5s);
}
}

} // namespace internal

void start()
{
internal::instance.start(internal::timeout.count());
internal::thread.start(watchdog::internal::watchdog_kick);
}

} // namespace watchdog

} // namespace

namespace touch {

auto corei2c = CoreI2C {PinName::SENSOR_PROXIMITY_MUX_I2C_SDA, PinName::SENSOR_PROXIMITY_MUX_I2C_SCL};
@@ -141,6 +236,7 @@ void calibration()
auto main() -> int
{
logger::init();
watchdog::start();

HelloWorld hello;
hello.start();
@@ -162,7 +258,7 @@ auto main() -> int

rtos::ThisThread::sleep_for(1s);

while (true) {
{
if (auto is_touched = sensor.read(); is_touched) {
log_info("Sensor touched");
} else {
@@ -171,4 +267,8 @@ auto main() -> int

rtos::ThisThread::sleep_for(100ms);
}

while (true) {
rtos::ThisThread::sleep_for(10min);
}
}
102 changes: 101 additions & 1 deletion spikes/lk_coreled/main.cpp
Original file line number Diff line number Diff line change
@@ -16,6 +16,101 @@
using namespace leka;
using namespace std::chrono;

#include "mbed_stats.h"

#include "drivers/Watchdog.h"
namespace {

namespace watchdog {

namespace internal {

auto &instance = mbed::Watchdog::get_instance();
constexpr auto timeout = 30000ms;
auto thread = rtos::Thread {osPriorityLow};

namespace stats {

auto cpu = mbed_stats_cpu_t {};
auto stack = mbed_stats_stack_t {};
auto heap = mbed_stats_heap_t {};

} // namespace stats

__attribute__((noreturn)) void watchdog_kick()
{
static auto kick_count = uint32_t {0};

static auto start = rtos::Kernel::Clock::now();
static auto stop = rtos::Kernel::Clock::now();
static auto delta = static_cast<int>((stop - start).count());

static auto idle_ratio = uint8_t {};
static auto sleep_ratio = uint8_t {};
static auto deep_sleep_ratio = uint8_t {};

static auto stack_used_delta = int32_t {};
static auto stack_used_size = uint32_t {};
static auto stack_reserved_size = uint32_t {};
static auto stack_used_ratio = uint8_t {};

static auto heap_used_delta = int32_t {};
static auto heap_used_size = uint32_t {};
static auto heap_reserved_size = uint32_t {};
static auto heap_used_ratio = uint8_t {};

while (true) {
internal::instance.kick();
++kick_count;

stop = rtos::Kernel::Clock::now();
delta = static_cast<int>((stop - start).count());

mbed_stats_cpu_get(&stats::cpu);

idle_ratio = static_cast<uint8_t>(((stats::cpu.idle_time / 1000 * 100) / (stats::cpu.uptime / 1000)));
sleep_ratio = static_cast<uint8_t>(((stats::cpu.sleep_time / 1000 * 100) / (stats::cpu.uptime / 1000)));
deep_sleep_ratio =
static_cast<uint8_t>(((stats::cpu.deep_sleep_time / 1000 * 100) / (stats::cpu.uptime / 1000)));

mbed_stats_stack_get(&stats::stack);

stack_used_delta = static_cast<int32_t>(stats::stack.max_size - stack_used_size);
stack_used_size = stats::stack.max_size;
stack_reserved_size = stats::stack.reserved_size;
stack_used_ratio = static_cast<uint8_t>((stack_used_size * 100) / stack_reserved_size);

mbed_stats_heap_get(&stats::heap);

heap_used_delta = static_cast<int32_t>(stats::heap.current_size - heap_used_size);
heap_used_size = stats::heap.current_size;
heap_reserved_size = stats::heap.reserved_size;
heap_used_ratio = static_cast<uint8_t>((heap_used_size * 100) / heap_reserved_size);

log_info(
"dt: %i, kck: %u, idl: %u%%, slp: %u%%, dsl: %u%%, sur: %u%% (%+i)[%u/"
"%u], hur: %u%% (%+i)[%u/%u]",
delta, kick_count, idle_ratio, sleep_ratio, deep_sleep_ratio, stack_used_ratio, stack_used_delta,
stack_used_size, stack_reserved_size, heap_used_ratio, heap_used_delta, heap_used_size,
heap_reserved_size);

start = rtos::Kernel::Clock::now();
rtos::ThisThread::sleep_for(5s);
}
}

} // namespace internal

void start()
{
internal::instance.start(internal::timeout.count());
internal::thread.start(watchdog::internal::watchdog_kick);
}

} // namespace watchdog

} // namespace

auto constexpr NUM_BELT_LEDS = 20;
auto constexpr NUM_EARS_LEDS = 2;

@@ -75,15 +170,20 @@ void changeColor(interface::LED &e, interface::LED &b)
auto main() -> int
{
logger::init();
watchdog::start();

HelloWorld hello;
hello.start();
log_info("Hello, World!\n\n");

rtos::ThisThread::sleep_for(2s);

while (true) {
{
changeColor(ears, belt);
rtos::ThisThread::sleep_for(1s);
}

while (true) {
rtos::ThisThread::sleep_for(10min);
}
}
102 changes: 101 additions & 1 deletion spikes/lk_event_queue/main.cpp
Original file line number Diff line number Diff line change
@@ -11,6 +11,101 @@
using namespace leka;
using namespace std::chrono;

#include "mbed_stats.h"

#include "drivers/Watchdog.h"
namespace {

namespace watchdog {

namespace internal {

auto &instance = mbed::Watchdog::get_instance();
constexpr auto timeout = 30000ms;
auto thread = rtos::Thread {osPriorityLow};

namespace stats {

auto cpu = mbed_stats_cpu_t {};
auto stack = mbed_stats_stack_t {};
auto heap = mbed_stats_heap_t {};

} // namespace stats

__attribute__((noreturn)) void watchdog_kick()
{
static auto kick_count = uint32_t {0};

static auto start = rtos::Kernel::Clock::now();
static auto stop = rtos::Kernel::Clock::now();
static auto delta = static_cast<int>((stop - start).count());

static auto idle_ratio = uint8_t {};
static auto sleep_ratio = uint8_t {};
static auto deep_sleep_ratio = uint8_t {};

static auto stack_used_delta = int32_t {};
static auto stack_used_size = uint32_t {};
static auto stack_reserved_size = uint32_t {};
static auto stack_used_ratio = uint8_t {};

static auto heap_used_delta = int32_t {};
static auto heap_used_size = uint32_t {};
static auto heap_reserved_size = uint32_t {};
static auto heap_used_ratio = uint8_t {};

while (true) {
internal::instance.kick();
++kick_count;

stop = rtos::Kernel::Clock::now();
delta = static_cast<int>((stop - start).count());

mbed_stats_cpu_get(&stats::cpu);

idle_ratio = static_cast<uint8_t>(((stats::cpu.idle_time / 1000 * 100) / (stats::cpu.uptime / 1000)));
sleep_ratio = static_cast<uint8_t>(((stats::cpu.sleep_time / 1000 * 100) / (stats::cpu.uptime / 1000)));
deep_sleep_ratio =
static_cast<uint8_t>(((stats::cpu.deep_sleep_time / 1000 * 100) / (stats::cpu.uptime / 1000)));

mbed_stats_stack_get(&stats::stack);

stack_used_delta = static_cast<int32_t>(stats::stack.max_size - stack_used_size);
stack_used_size = stats::stack.max_size;
stack_reserved_size = stats::stack.reserved_size;
stack_used_ratio = static_cast<uint8_t>((stack_used_size * 100) / stack_reserved_size);

mbed_stats_heap_get(&stats::heap);

heap_used_delta = static_cast<int32_t>(stats::heap.current_size - heap_used_size);
heap_used_size = stats::heap.current_size;
heap_reserved_size = stats::heap.reserved_size;
heap_used_ratio = static_cast<uint8_t>((heap_used_size * 100) / heap_reserved_size);

log_info(
"dt: %i, kck: %u, idl: %u%%, slp: %u%%, dsl: %u%%, sur: %u%% (%+i)[%u/"
"%u], hur: %u%% (%+i)[%u/%u]",
delta, kick_count, idle_ratio, sleep_ratio, deep_sleep_ratio, stack_used_ratio, stack_used_delta,
stack_used_size, stack_reserved_size, heap_used_ratio, heap_used_delta, heap_used_size,
heap_reserved_size);

start = rtos::Kernel::Clock::now();
rtos::ThisThread::sleep_for(5s);
}
}

} // namespace internal

void start()
{
internal::instance.start(internal::timeout.count());
internal::thread.start(watchdog::internal::watchdog_kick);
}

} // namespace watchdog

} // namespace

mbed::DigitalOut blinky(LED1, 0);

class LEDManager
@@ -90,12 +185,13 @@ CoreEventQueue equeue {};
auto main() -> int
{
logger::init();
watchdog::start();

log_info("Hello, World!\n\n");

manager.init();

while (true) {
{
log_info("Turn on ref");
manager.turnOnRef(blinky);
rtos::ThisThread::sleep_for(1s);
@@ -132,4 +228,8 @@ auto main() -> int
equeue.call(lambda);
equeue.call(int_function_with_multiple_params, 42, std::string {"Hello, World"}, true);
}

while (true) {
rtos::ThisThread::sleep_for(10min);
}
}
115 changes: 114 additions & 1 deletion spikes/lk_file_manager_kit/main.cpp
Original file line number Diff line number Diff line change
@@ -17,6 +17,101 @@
using namespace leka;
using namespace std::chrono_literals;

#include "mbed_stats.h"

#include "drivers/Watchdog.h"
namespace {

namespace watchdog {

namespace internal {

auto &instance = mbed::Watchdog::get_instance();
constexpr auto timeout = 30000ms;
auto thread = rtos::Thread {osPriorityLow};

namespace stats {

auto cpu = mbed_stats_cpu_t {};
auto stack = mbed_stats_stack_t {};
auto heap = mbed_stats_heap_t {};

} // namespace stats

__attribute__((noreturn)) void watchdog_kick()
{
static auto kick_count = uint32_t {0};

static auto start = rtos::Kernel::Clock::now();
static auto stop = rtos::Kernel::Clock::now();
static auto delta = static_cast<int>((stop - start).count());

static auto idle_ratio = uint8_t {};
static auto sleep_ratio = uint8_t {};
static auto deep_sleep_ratio = uint8_t {};

static auto stack_used_delta = int32_t {};
static auto stack_used_size = uint32_t {};
static auto stack_reserved_size = uint32_t {};
static auto stack_used_ratio = uint8_t {};

static auto heap_used_delta = int32_t {};
static auto heap_used_size = uint32_t {};
static auto heap_reserved_size = uint32_t {};
static auto heap_used_ratio = uint8_t {};

while (true) {
internal::instance.kick();
++kick_count;

stop = rtos::Kernel::Clock::now();
delta = static_cast<int>((stop - start).count());

mbed_stats_cpu_get(&stats::cpu);

idle_ratio = static_cast<uint8_t>(((stats::cpu.idle_time / 1000 * 100) / (stats::cpu.uptime / 1000)));
sleep_ratio = static_cast<uint8_t>(((stats::cpu.sleep_time / 1000 * 100) / (stats::cpu.uptime / 1000)));
deep_sleep_ratio =
static_cast<uint8_t>(((stats::cpu.deep_sleep_time / 1000 * 100) / (stats::cpu.uptime / 1000)));

mbed_stats_stack_get(&stats::stack);

stack_used_delta = static_cast<int32_t>(stats::stack.max_size - stack_used_size);
stack_used_size = stats::stack.max_size;
stack_reserved_size = stats::stack.reserved_size;
stack_used_ratio = static_cast<uint8_t>((stack_used_size * 100) / stack_reserved_size);

mbed_stats_heap_get(&stats::heap);

heap_used_delta = static_cast<int32_t>(stats::heap.current_size - heap_used_size);
heap_used_size = stats::heap.current_size;
heap_reserved_size = stats::heap.reserved_size;
heap_used_ratio = static_cast<uint8_t>((heap_used_size * 100) / heap_reserved_size);

log_info(
"dt: %i, kck: %u, idl: %u%%, slp: %u%%, dsl: %u%%, sur: %u%% (%+i)[%u/"
"%u], hur: %u%% (%+i)[%u/%u]",
delta, kick_count, idle_ratio, sleep_ratio, deep_sleep_ratio, stack_used_ratio, stack_used_delta,
stack_used_size, stack_reserved_size, heap_used_ratio, heap_used_delta, heap_used_size,
heap_reserved_size);

start = rtos::Kernel::Clock::now();
rtos::ThisThread::sleep_for(5s);
}
}

} // namespace internal

void start()
{
internal::instance.start(internal::timeout.count());
internal::thread.start(watchdog::internal::watchdog_kick);
}

} // namespace watchdog

} // namespace

auto file = FileManagerKit::File {};
const auto seek_temp = uint8_t {7};
const std::filesystem::path tmp_dir = "/fs/tmp/";
@@ -55,6 +150,7 @@ void printSHA256(std::span<uint8_t> array)
auto main() -> int
{
logger::init();
watchdog::start();

log_info("Hello, World!\n\n");

@@ -76,45 +172,52 @@ auto main() -> int
printSHA256(sha256);
}

while (true) {
{
auto t = rtos::Kernel::Clock::now() - start;
log_info("A message from your board %s --> \"%s\" at %i s", MBED_CONF_APP_TARGET_NAME, hello.world,
int(t.count() / 1000));
rtos::ThisThread::sleep_for(1s);

if (auto removed = std::filesystem::remove(test_filename); !removed) {
log_error("The file or directory '%s' doesn't exist or fails to be removed", test_filename.c_str());
} else {
log_info("File or directory '%s' removed", test_filename.c_str());
}
rtos::ThisThread::sleep_for(1s);

if (auto removed = std::filesystem::remove(sub_test_dir); !removed) {
log_error("The file or directory '%s' doesn't exist or fails to be removed", sub_test_dir.c_str());
} else {
log_info("File or directory '%s' removed", sub_test_dir.c_str());
}
rtos::ThisThread::sleep_for(1s);

if (auto removed = std::filesystem::remove(test_dir); !removed) {
log_error("The file or directory '%s' doesn't exist or fails to be removed", test_dir.c_str());
} else {
log_info("File or directory '%s' removed", test_dir.c_str());
}
rtos::ThisThread::sleep_for(1s);

if (auto created = FileManagerKit::create_directory(test_dir); !created) {
log_error("The directory '%s' already exists or fails to be created ", test_dir.c_str());
} else {
log_info("Directory '%s' created", test_dir.c_str());
}
rtos::ThisThread::sleep_for(1s);

if (auto created = FileManagerKit::create_directory(sub_test_dir); !created) {
log_error("The directory '%s' already exists or fails to be created ", sub_test_dir.c_str());
} else {
log_info("Directory '%s' created", sub_test_dir.c_str());
}
rtos::ThisThread::sleep_for(1s);

if (auto open = file.open(test_filename, "w"); !open) {
log_error("Fail to open file");
return EXIT_FAILURE;
}
rtos::ThisThread::sleep_for(1s);

log_info("File opened in mode 'w'");

@@ -124,6 +227,7 @@ auto main() -> int
log_error("Fail to set buffer");
return EXIT_FAILURE;
}
rtos::ThisThread::sleep_for(1s);

log_info("Setting buffer");

@@ -134,13 +238,15 @@ auto main() -> int
return EXIT_FAILURE;
}
log_info("File edited");
rtos::ThisThread::sleep_for(1s);

auto size = file.size();
if (size != std::size(input_data)) {
log_error("Size error");
return EXIT_FAILURE;
}
log_info("Size : %d", size);
rtos::ThisThread::sleep_for(1s);

auto output_data = std::array<char, 1024> {};

@@ -149,6 +255,7 @@ auto main() -> int
return EXIT_FAILURE;
}
log_info("File re-opened in mode 'r'");
rtos::ThisThread::sleep_for(1s);

file.rewind();
log_info("Reading...");
@@ -158,6 +265,7 @@ auto main() -> int
}
log_info("File read");
log_info("Data : %s", output_data.data());
rtos::ThisThread::sleep_for(1s);

file.seek(seek_temp);
log_info("Position indicator set to %d", file.tell());
@@ -168,10 +276,15 @@ auto main() -> int
}
log_info("File read");
log_info("Data : %s", output_data.data());
rtos::ThisThread::sleep_for(1s);

file.close();
log_info("File closed");
log_info("\n\n");
rtos::ThisThread::sleep_for(10s);
}

while (true) {
rtos::ThisThread::sleep_for(10min);
}
}
103 changes: 101 additions & 2 deletions spikes/lk_file_reception/main.cpp
Original file line number Diff line number Diff line change
@@ -16,6 +16,101 @@
using namespace leka;
using namespace std::chrono;

#include "mbed_stats.h"

#include "drivers/Watchdog.h"
namespace {

namespace watchdog {

namespace internal {

auto &instance = mbed::Watchdog::get_instance();
constexpr auto timeout = 30000ms;
auto thread = rtos::Thread {osPriorityLow};

namespace stats {

auto cpu = mbed_stats_cpu_t {};
auto stack = mbed_stats_stack_t {};
auto heap = mbed_stats_heap_t {};

} // namespace stats

__attribute__((noreturn)) void watchdog_kick()
{
static auto kick_count = uint32_t {0};

static auto start = rtos::Kernel::Clock::now();
static auto stop = rtos::Kernel::Clock::now();
static auto delta = static_cast<int>((stop - start).count());

static auto idle_ratio = uint8_t {};
static auto sleep_ratio = uint8_t {};
static auto deep_sleep_ratio = uint8_t {};

static auto stack_used_delta = int32_t {};
static auto stack_used_size = uint32_t {};
static auto stack_reserved_size = uint32_t {};
static auto stack_used_ratio = uint8_t {};

static auto heap_used_delta = int32_t {};
static auto heap_used_size = uint32_t {};
static auto heap_reserved_size = uint32_t {};
static auto heap_used_ratio = uint8_t {};

while (true) {
internal::instance.kick();
++kick_count;

stop = rtos::Kernel::Clock::now();
delta = static_cast<int>((stop - start).count());

mbed_stats_cpu_get(&stats::cpu);

idle_ratio = static_cast<uint8_t>(((stats::cpu.idle_time / 1000 * 100) / (stats::cpu.uptime / 1000)));
sleep_ratio = static_cast<uint8_t>(((stats::cpu.sleep_time / 1000 * 100) / (stats::cpu.uptime / 1000)));
deep_sleep_ratio =
static_cast<uint8_t>(((stats::cpu.deep_sleep_time / 1000 * 100) / (stats::cpu.uptime / 1000)));

mbed_stats_stack_get(&stats::stack);

stack_used_delta = static_cast<int32_t>(stats::stack.max_size - stack_used_size);
stack_used_size = stats::stack.max_size;
stack_reserved_size = stats::stack.reserved_size;
stack_used_ratio = static_cast<uint8_t>((stack_used_size * 100) / stack_reserved_size);

mbed_stats_heap_get(&stats::heap);

heap_used_delta = static_cast<int32_t>(stats::heap.current_size - heap_used_size);
heap_used_size = stats::heap.current_size;
heap_reserved_size = stats::heap.reserved_size;
heap_used_ratio = static_cast<uint8_t>((heap_used_size * 100) / heap_reserved_size);

log_info(
"dt: %i, kck: %u, idl: %u%%, slp: %u%%, dsl: %u%%, sur: %u%% (%+i)[%u/"
"%u], hur: %u%% (%+i)[%u/%u]",
delta, kick_count, idle_ratio, sleep_ratio, deep_sleep_ratio, stack_used_ratio, stack_used_delta,
stack_used_size, stack_reserved_size, heap_used_ratio, heap_used_delta, heap_used_size,
heap_reserved_size);

start = rtos::Kernel::Clock::now();
rtos::ThisThread::sleep_for(5s);
}
}

} // namespace internal

void start()
{
internal::instance.start(internal::timeout.count());
internal::thread.start(watchdog::internal::watchdog_kick);
}

} // namespace watchdog

} // namespace

auto web_access = CoreNetwork {};
auto web_file_handle = FileManagerKit::File {};
auto web_kit = WebKit(web_access, web_file_handle);
@@ -74,10 +169,14 @@ auto main() -> int
}
}

while (true) {
{
auto t = rtos::Kernel::Clock::now() - start;
log_info("A message from your board %s --> \"%s\" at %i s", MBED_CONF_APP_TARGET_NAME, hello.world,
int(t.count() / 1000));
rtos::ThisThread::sleep_for(10s);
rtos::ThisThread::sleep_for(1s);
}

while (true) {
rtos::ThisThread::sleep_for(10min);
}
}
102 changes: 101 additions & 1 deletion spikes/lk_flash_memory/main.cpp
Original file line number Diff line number Diff line change
@@ -16,9 +16,105 @@
using namespace leka;
using namespace std::chrono;

#include "mbed_stats.h"

#include "drivers/Watchdog.h"
namespace {

namespace watchdog {

namespace internal {

auto &instance = mbed::Watchdog::get_instance();
constexpr auto timeout = 30000ms;
auto thread = rtos::Thread {osPriorityLow};

namespace stats {

auto cpu = mbed_stats_cpu_t {};
auto stack = mbed_stats_stack_t {};
auto heap = mbed_stats_heap_t {};

} // namespace stats

__attribute__((noreturn)) void watchdog_kick()
{
static auto kick_count = uint32_t {0};

static auto start = rtos::Kernel::Clock::now();
static auto stop = rtos::Kernel::Clock::now();
static auto delta = static_cast<int>((stop - start).count());

static auto idle_ratio = uint8_t {};
static auto sleep_ratio = uint8_t {};
static auto deep_sleep_ratio = uint8_t {};

static auto stack_used_delta = int32_t {};
static auto stack_used_size = uint32_t {};
static auto stack_reserved_size = uint32_t {};
static auto stack_used_ratio = uint8_t {};

static auto heap_used_delta = int32_t {};
static auto heap_used_size = uint32_t {};
static auto heap_reserved_size = uint32_t {};
static auto heap_used_ratio = uint8_t {};

while (true) {
internal::instance.kick();
++kick_count;

stop = rtos::Kernel::Clock::now();
delta = static_cast<int>((stop - start).count());

mbed_stats_cpu_get(&stats::cpu);

idle_ratio = static_cast<uint8_t>(((stats::cpu.idle_time / 1000 * 100) / (stats::cpu.uptime / 1000)));
sleep_ratio = static_cast<uint8_t>(((stats::cpu.sleep_time / 1000 * 100) / (stats::cpu.uptime / 1000)));
deep_sleep_ratio =
static_cast<uint8_t>(((stats::cpu.deep_sleep_time / 1000 * 100) / (stats::cpu.uptime / 1000)));

mbed_stats_stack_get(&stats::stack);

stack_used_delta = static_cast<int32_t>(stats::stack.max_size - stack_used_size);
stack_used_size = stats::stack.max_size;
stack_reserved_size = stats::stack.reserved_size;
stack_used_ratio = static_cast<uint8_t>((stack_used_size * 100) / stack_reserved_size);

mbed_stats_heap_get(&stats::heap);

heap_used_delta = static_cast<int32_t>(stats::heap.current_size - heap_used_size);
heap_used_size = stats::heap.current_size;
heap_reserved_size = stats::heap.reserved_size;
heap_used_ratio = static_cast<uint8_t>((heap_used_size * 100) / heap_reserved_size);

log_info(
"dt: %i, kck: %u, idl: %u%%, slp: %u%%, dsl: %u%%, sur: %u%% (%+i)[%u/"
"%u], hur: %u%% (%+i)[%u/%u]",
delta, kick_count, idle_ratio, sleep_ratio, deep_sleep_ratio, stack_used_ratio, stack_used_delta,
stack_used_size, stack_reserved_size, heap_used_ratio, heap_used_delta, heap_used_size,
heap_reserved_size);

start = rtos::Kernel::Clock::now();
rtos::ThisThread::sleep_for(5s);
}
}

} // namespace internal

void start()
{
internal::instance.start(internal::timeout.count());
internal::thread.start(watchdog::internal::watchdog_kick);
}

} // namespace watchdog

} // namespace

auto main() -> int
{
logger::init();
watchdog::start();

auto start = rtos::Kernel::Clock::now();

@@ -46,7 +142,7 @@ auto main() -> int

coreis25lp.erase();

while (true) {
{
auto t = rtos::Kernel::Clock::now() - start;
log_info("A message from your board %s --> \"%s\" at %i s\n", MBED_CONF_APP_TARGET_NAME, hello.world,
int(t.count() / 1000));
@@ -64,4 +160,8 @@ auto main() -> int
address = new_address;
}
}

while (true) {
rtos::ThisThread::sleep_for(10min);
}
}
107 changes: 100 additions & 7 deletions spikes/lk_fs/main.cpp
Original file line number Diff line number Diff line change
@@ -35,6 +35,10 @@
using namespace leka;
using namespace std::chrono;

#include "mbed_stats.h"

#include "drivers/Watchdog.h"

namespace {

namespace sd {
@@ -90,8 +94,91 @@ auto hello = HelloWorld {};
auto com_utils_flag = rtos::EventFlags {};
auto com = ComUtils {com_utils_flag};

namespace watchdog {

namespace internal {

auto &instance = mbed::Watchdog::get_instance();
constexpr auto timeout = 30000ms;
auto thread = rtos::Thread {osPriorityLow};

namespace stats {

auto cpu = mbed_stats_cpu_t {};
auto stack = mbed_stats_stack_t {};
auto heap = mbed_stats_heap_t {};

} // namespace stats

__attribute__((noreturn)) void watchdog_kick()
{
static auto kick_count = uint32_t {0};

static auto start = rtos::Kernel::Clock::now();
static auto stop = rtos::Kernel::Clock::now();
static auto delta = static_cast<int>((stop - start).count());

static auto idle_ratio = uint8_t {};
static auto sleep_ratio = uint8_t {};
static auto deep_sleep_ratio = uint8_t {};

static auto stack_used_delta = int32_t {};
static auto stack_used_size = uint32_t {};
static auto stack_reserved_size = uint32_t {};
static auto stack_used_ratio = uint8_t {};

static auto heap_used_delta = int32_t {};
static auto heap_used_size = uint32_t {};
static auto heap_reserved_size = uint32_t {};
static auto heap_used_ratio = uint8_t {};

while (true) {
internal::instance.kick();
++kick_count;

stop = rtos::Kernel::Clock::now();
delta = static_cast<int>((stop - start).count());

mbed_stats_cpu_get(&stats::cpu);

idle_ratio = static_cast<uint8_t>(((stats::cpu.idle_time / 1000 * 100) / (stats::cpu.uptime / 1000)));
sleep_ratio = static_cast<uint8_t>(((stats::cpu.sleep_time / 1000 * 100) / (stats::cpu.uptime / 1000)));
deep_sleep_ratio =
static_cast<uint8_t>(((stats::cpu.deep_sleep_time / 1000 * 100) / (stats::cpu.uptime / 1000)));

mbed_stats_stack_get(&stats::stack);

stack_used_delta = static_cast<int32_t>(stats::stack.max_size - stack_used_size);
stack_used_size = stats::stack.max_size;
stack_reserved_size = stats::stack.reserved_size;
stack_used_ratio = static_cast<uint8_t>((stack_used_size * 100) / stack_reserved_size);

mbed_stats_heap_get(&stats::heap);

heap_used_delta = static_cast<int32_t>(stats::heap.current_size - heap_used_size);
heap_used_size = stats::heap.current_size;
heap_reserved_size = stats::heap.reserved_size;
heap_used_ratio = static_cast<uint8_t>((heap_used_size * 100) / heap_reserved_size);

start = rtos::Kernel::Clock::now();
rtos::ThisThread::sleep_for(5s);
}
}

} // namespace internal

void start()
{
internal::instance.start(internal::timeout.count());
internal::thread.start(watchdog::internal::watchdog_kick);
}

} // namespace watchdog

auto main() -> int
{
watchdog::start();

sd::init();

display::internal::corelcd.turnOn();
@@ -101,7 +188,7 @@ auto main() -> int

hello.start();

while (true) {
{
com_utils_flag.wait_any(ComUtils::flags::data_available);

auto path = com.getPath();
@@ -114,19 +201,19 @@ auto main() -> int

if (auto is_missing = !(std::filesystem::exists(path)); is_missing) {
com.write("NOK_MISSING:" + path.string());
continue;
// continue;
}

if (auto is_empty = std::filesystem::is_empty(path); is_empty) {
com.write("NOK_EMPTY:" + path.string());
continue;
// continue;
}

if (path.string().ends_with(".jpg")) {
videokit.displayImage(path);
rtos::ThisThread::sleep_for(100ms);
com.write("ACK_IMAGE:" + path.string());
continue;
// continue;
}

if (path.string().ends_with(".avi")) {
@@ -137,7 +224,7 @@ auto main() -> int
videokit.stopVideo();
rtos::ThisThread::sleep_for(5ms);
com.write("ACK_VIDEO:" + path.string());
continue;
// continue;
}

if (auto *file = std::fopen(path.c_str(), "r"); file != nullptr) {
@@ -148,13 +235,19 @@ auto main() -> int

if (buf.empty()) {
com.write("NOK_EMPTY:" + path.string());
continue;
// continue;
}

com.write("ACK_FILE:" + path.string());
continue;
// continue;
}

com.write("NOK_NOT_OPEN:" + path.string());
}

display::internal::corelcd.enableDeepSleep();

while (true) {
rtos::ThisThread::sleep_for(10min);
}
}
99 changes: 98 additions & 1 deletion spikes/lk_imu_kit/main.cpp
Original file line number Diff line number Diff line change
@@ -13,8 +13,100 @@
using namespace std::chrono;
using namespace leka;

#include "mbed_stats.h"

#include "drivers/Watchdog.h"

namespace {

namespace watchdog {

namespace internal {

auto &instance = mbed::Watchdog::get_instance();
constexpr auto timeout = 30000ms;
auto thread = rtos::Thread {osPriorityLow};

namespace stats {

auto cpu = mbed_stats_cpu_t {};
auto stack = mbed_stats_stack_t {};
auto heap = mbed_stats_heap_t {};

} // namespace stats

__attribute__((noreturn)) void watchdog_kick()
{
static auto kick_count = uint32_t {0};

static auto start = rtos::Kernel::Clock::now();
static auto stop = rtos::Kernel::Clock::now();
static auto delta = static_cast<int>((stop - start).count());

static auto idle_ratio = uint8_t {};
static auto sleep_ratio = uint8_t {};
static auto deep_sleep_ratio = uint8_t {};

static auto stack_used_delta = int32_t {};
static auto stack_used_size = uint32_t {};
static auto stack_reserved_size = uint32_t {};
static auto stack_used_ratio = uint8_t {};

static auto heap_used_delta = int32_t {};
static auto heap_used_size = uint32_t {};
static auto heap_reserved_size = uint32_t {};
static auto heap_used_ratio = uint8_t {};

while (true) {
internal::instance.kick();
++kick_count;

stop = rtos::Kernel::Clock::now();
delta = static_cast<int>((stop - start).count());

mbed_stats_cpu_get(&stats::cpu);

idle_ratio = static_cast<uint8_t>(((stats::cpu.idle_time / 1000 * 100) / (stats::cpu.uptime / 1000)));
sleep_ratio = static_cast<uint8_t>(((stats::cpu.sleep_time / 1000 * 100) / (stats::cpu.uptime / 1000)));
deep_sleep_ratio =
static_cast<uint8_t>(((stats::cpu.deep_sleep_time / 1000 * 100) / (stats::cpu.uptime / 1000)));

mbed_stats_stack_get(&stats::stack);

stack_used_delta = static_cast<int32_t>(stats::stack.max_size - stack_used_size);
stack_used_size = stats::stack.max_size;
stack_reserved_size = stats::stack.reserved_size;
stack_used_ratio = static_cast<uint8_t>((stack_used_size * 100) / stack_reserved_size);

mbed_stats_heap_get(&stats::heap);

heap_used_delta = static_cast<int32_t>(stats::heap.current_size - heap_used_size);
heap_used_size = stats::heap.current_size;
heap_reserved_size = stats::heap.reserved_size;
heap_used_ratio = static_cast<uint8_t>((heap_used_size * 100) / heap_reserved_size);

log_info(
"dt: %i, kck: %u, idl: %u%%, slp: %u%%, dsl: %u%%, sur: %u%% (%+i)[%u/"
"%u], hur: %u%% (%+i)[%u/%u]",
delta, kick_count, idle_ratio, sleep_ratio, deep_sleep_ratio, stack_used_ratio, stack_used_delta,
stack_used_size, stack_reserved_size, heap_used_ratio, heap_used_delta, heap_used_size,
heap_reserved_size);

start = rtos::Kernel::Clock::now();
rtos::ThisThread::sleep_for(5s);
}
}

} // namespace internal

void start()
{
internal::instance.start(internal::timeout.count());
internal::thread.start(watchdog::internal::watchdog_kick);
}

} // namespace watchdog

namespace imu {

namespace internal {
@@ -36,6 +128,7 @@ auto main() -> int
{
rtos::ThisThread::sleep_for(140ms);
logger::init();
watchdog::start();

HelloWorld hello;
hello.start();
@@ -46,9 +139,13 @@ auto main() -> int
imukit.init();
imukit.start();

while (true) {
{
const auto [pitch, roll, yaw] = imukit.getEulerAngles();
log_info("Pitch : %7.2f, Roll : %7.2f Yaw : %7.2f", pitch, roll, yaw);
rtos::ThisThread::sleep_for(140ms);
}

while (true) {
rtos::ThisThread::sleep_for(10min);
}
}
132 changes: 102 additions & 30 deletions spikes/lk_lcd/main.cpp
Original file line number Diff line number Diff line change
@@ -35,6 +35,101 @@
using namespace leka;
using namespace std::chrono;

#include "mbed_stats.h"

#include "drivers/Watchdog.h"
namespace {

namespace watchdog {

namespace internal {

auto &instance = mbed::Watchdog::get_instance();
constexpr auto timeout = 30000ms;
auto thread = rtos::Thread {osPriorityLow};

namespace stats {

auto cpu = mbed_stats_cpu_t {};
auto stack = mbed_stats_stack_t {};
auto heap = mbed_stats_heap_t {};

} // namespace stats

__attribute__((noreturn)) void watchdog_kick()
{
static auto kick_count = uint32_t {0};

static auto start = rtos::Kernel::Clock::now();
static auto stop = rtos::Kernel::Clock::now();
static auto delta = static_cast<int>((stop - start).count());

static auto idle_ratio = uint8_t {};
static auto sleep_ratio = uint8_t {};
static auto deep_sleep_ratio = uint8_t {};

static auto stack_used_delta = int32_t {};
static auto stack_used_size = uint32_t {};
static auto stack_reserved_size = uint32_t {};
static auto stack_used_ratio = uint8_t {};

static auto heap_used_delta = int32_t {};
static auto heap_used_size = uint32_t {};
static auto heap_reserved_size = uint32_t {};
static auto heap_used_ratio = uint8_t {};

while (true) {
internal::instance.kick();
++kick_count;

stop = rtos::Kernel::Clock::now();
delta = static_cast<int>((stop - start).count());

mbed_stats_cpu_get(&stats::cpu);

idle_ratio = static_cast<uint8_t>(((stats::cpu.idle_time / 1000 * 100) / (stats::cpu.uptime / 1000)));
sleep_ratio = static_cast<uint8_t>(((stats::cpu.sleep_time / 1000 * 100) / (stats::cpu.uptime / 1000)));
deep_sleep_ratio =
static_cast<uint8_t>(((stats::cpu.deep_sleep_time / 1000 * 100) / (stats::cpu.uptime / 1000)));

mbed_stats_stack_get(&stats::stack);

stack_used_delta = static_cast<int32_t>(stats::stack.max_size - stack_used_size);
stack_used_size = stats::stack.max_size;
stack_reserved_size = stats::stack.reserved_size;
stack_used_ratio = static_cast<uint8_t>((stack_used_size * 100) / stack_reserved_size);

mbed_stats_heap_get(&stats::heap);

heap_used_delta = static_cast<int32_t>(stats::heap.current_size - heap_used_size);
heap_used_size = stats::heap.current_size;
heap_reserved_size = stats::heap.reserved_size;
heap_used_ratio = static_cast<uint8_t>((heap_used_size * 100) / heap_reserved_size);

log_info(
"dt: %i, kck: %u, idl: %u%%, slp: %u%%, dsl: %u%%, sur: %u%% (%+i)[%u/"
"%u], hur: %u%% (%+i)[%u/%u]",
delta, kick_count, idle_ratio, sleep_ratio, deep_sleep_ratio, stack_used_ratio, stack_used_delta,
stack_used_size, stack_reserved_size, heap_used_ratio, heap_used_delta, heap_used_size,
heap_reserved_size);

start = rtos::Kernel::Clock::now();
rtos::ThisThread::sleep_for(5s);
}
}

} // namespace internal

void start()
{
internal::instance.start(internal::timeout.count());
internal::thread.start(watchdog::internal::watchdog_kick);
}

} // namespace watchdog

} // namespace

SDBlockDevice sd_blockdevice(SD_SPI_MOSI, SD_SPI_MISO, SD_SPI_SCK);
FATFileSystem fatfs("fs");

@@ -81,6 +176,7 @@ auto main() -> int
auto start = rtos::Kernel::Clock::now();

logger::init();
watchdog::start();

log_info("Hello, World!\n\n");

@@ -96,36 +192,7 @@ auto main() -> int
display::internal::corevideo.clearScreen();
rtos::ThisThread::sleep_for(1s);

static auto line = 1;
static CGColor foreground;
static CGColor background = CGColor::white;

leka::logger::set_sink_function([](const char *str, std::size_t size) {
display::internal::corevideo.displayText(str, size, line, foreground, background);
});

for (int i = 1; i <= 10; i++) {
foreground = (i % 2 == 0) ? CGColor::black : CGColor::pure_red;
line = i * 2;
log_info("Line #%i", i);
rtos::ThisThread::sleep_for(100ms);
}

rtos::ThisThread::sleep_for(500ms);

leka::logger::set_sink_function([](const char *str, std::size_t size) {
display::internal::corevideo.displayText(str, size, 10, {0x00, 0x00, 0xFF}, CGColor::white); // write in blue
});

log_info(
"This sentence is supposed to be on multiple lines because it is too long to be displayed on "
"only one line of the screen.");

rtos::ThisThread::sleep_for(1s);

leka::logger::set_sink_function(logger::internal::default_sink_function);

while (true) {
{
auto t = rtos::Kernel::Clock::now() - start;
log_info("A message from your board %s --> \"%s\" at %is", MBED_CONF_APP_TARGET_NAME, hello.world,
int(t.count() / 1000));
@@ -149,4 +216,9 @@ auto main() -> int

display::internal::corelcd.turnOff();
}

display::internal::corelcd.enableDeepSleep();
while (true) {
rtos::ThisThread::sleep_for(10min);
}
}
201 changes: 97 additions & 104 deletions spikes/lk_led_kit/main.cpp
Original file line number Diff line number Diff line change
@@ -18,8 +18,99 @@
using namespace leka;
using namespace std::chrono;

#include "mbed_stats.h"

#include "drivers/Watchdog.h"
namespace {

namespace watchdog {

namespace internal {

auto &instance = mbed::Watchdog::get_instance();
constexpr auto timeout = 30000ms;
auto thread = rtos::Thread {osPriorityLow};

namespace stats {

auto cpu = mbed_stats_cpu_t {};
auto stack = mbed_stats_stack_t {};
auto heap = mbed_stats_heap_t {};

} // namespace stats

__attribute__((noreturn)) void watchdog_kick()
{
static auto kick_count = uint32_t {0};

static auto start = rtos::Kernel::Clock::now();
static auto stop = rtos::Kernel::Clock::now();
static auto delta = static_cast<int>((stop - start).count());

static auto idle_ratio = uint8_t {};
static auto sleep_ratio = uint8_t {};
static auto deep_sleep_ratio = uint8_t {};

static auto stack_used_delta = int32_t {};
static auto stack_used_size = uint32_t {};
static auto stack_reserved_size = uint32_t {};
static auto stack_used_ratio = uint8_t {};

static auto heap_used_delta = int32_t {};
static auto heap_used_size = uint32_t {};
static auto heap_reserved_size = uint32_t {};
static auto heap_used_ratio = uint8_t {};

while (true) {
internal::instance.kick();
++kick_count;

stop = rtos::Kernel::Clock::now();
delta = static_cast<int>((stop - start).count());

mbed_stats_cpu_get(&stats::cpu);

idle_ratio = static_cast<uint8_t>(((stats::cpu.idle_time / 1000 * 100) / (stats::cpu.uptime / 1000)));
sleep_ratio = static_cast<uint8_t>(((stats::cpu.sleep_time / 1000 * 100) / (stats::cpu.uptime / 1000)));
deep_sleep_ratio =
static_cast<uint8_t>(((stats::cpu.deep_sleep_time / 1000 * 100) / (stats::cpu.uptime / 1000)));

mbed_stats_stack_get(&stats::stack);

stack_used_delta = static_cast<int32_t>(stats::stack.max_size - stack_used_size);
stack_used_size = stats::stack.max_size;
stack_reserved_size = stats::stack.reserved_size;
stack_used_ratio = static_cast<uint8_t>((stack_used_size * 100) / stack_reserved_size);

mbed_stats_heap_get(&stats::heap);

heap_used_delta = static_cast<int32_t>(stats::heap.current_size - heap_used_size);
heap_used_size = stats::heap.current_size;
heap_reserved_size = stats::heap.reserved_size;
heap_used_ratio = static_cast<uint8_t>((heap_used_size * 100) / heap_reserved_size);

log_info(
"dt: %i, kck: %u, idl: %u%%, slp: %u%%, dsl: %u%%, sur: %u%% (%+i)[%u/"
"%u], hur: %u%% (%+i)[%u/%u]",
delta, kick_count, idle_ratio, sleep_ratio, deep_sleep_ratio, stack_used_ratio, stack_used_delta,
stack_used_size, stack_reserved_size, heap_used_ratio, heap_used_delta, heap_used_size,
heap_reserved_size);

start = rtos::Kernel::Clock::now();
rtos::ThisThread::sleep_for(5s);
}
}

} // namespace internal

void start()
{
internal::instance.start(internal::timeout.count());
internal::thread.start(watchdog::internal::watchdog_kick);
}

} // namespace watchdog

namespace leds {

namespace internal {
@@ -67,6 +158,7 @@ auto ledkit = LedKit {leds::animations::event_loop, leds::ears, leds::belt};
auto main() -> int
{
logger::init();
watchdog::start();
leds::turnOff();

log_info("Hello, World!\n\n");
@@ -75,113 +167,14 @@ auto main() -> int

hello.start();

while (true) {
{
log_info("animation::ble_connection");
ledkit.start(&led::animation::ble_connection);
rtos::ThisThread::sleep_for(2s);
}

log_info("animation::sleeping");
ledkit.start(&led::animation::sleeping);
rtos::ThisThread::sleep_for(2s);

log_info("animation::afraid_blue");
ledkit.start(&led::animation::afraid_blue);
rtos::ThisThread::sleep_for(2s);

log_info("animation::afraid_red");
ledkit.start(&led::animation::afraid_red);
rtos::ThisThread::sleep_for(2s);

log_info("animation::afraid_red_blue");
ledkit.start(&led::animation::afraid_red_blue);
rtos::ThisThread::sleep_for(2s);

log_info("animation::amazed");
ledkit.start(&led::animation::amazed);
rtos::ThisThread::sleep_for(2s);

log_info("animation::angry");
ledkit.start(&led::animation::angry);
rtos::ThisThread::sleep_for(20s);

log_info("animation::angry_short");
ledkit.start(&led::animation::angry_short);
rtos::ThisThread::sleep_for(2s);

log_info("animation::blink_green");
ledkit.start(&led::animation::blink_green);
rtos::ThisThread::sleep_for(2s);

log_info("animation::bubbles");
ledkit.start(&led::animation::bubbles);
rtos::ThisThread::sleep_for(2s);

log_info("animation::disgusted");
ledkit.start(&led::animation::disgusted);
rtos::ThisThread::sleep_for(2s);

log_info("animation::fire");
ledkit.start(&led::animation::fire);
rtos::ThisThread::sleep_for(2s);

log_info("animation::fly");
ledkit.start(&led::animation::fly);
rtos::ThisThread::sleep_for(2s);

log_info("animation::happy");
ledkit.start(&led::animation::happy);
rtos::ThisThread::sleep_for(2s);

log_info("animation::rainbow");
ledkit.start(&led::animation::rainbow);
rtos::ThisThread::sleep_for(2s);

log_info("animation::sad");
ledkit.start(&led::animation::sad);
rtos::ThisThread::sleep_for(2s);

log_info("animation::sad_cry");
ledkit.start(&led::animation::sad_cry);
rtos::ThisThread::sleep_for(2s);

log_info("animation::sick");
ledkit.start(&led::animation::sick);
rtos::ThisThread::sleep_for(2s);

log_info("animation::singing");
ledkit.start(&led::animation::singing);
rtos::ThisThread::sleep_for(2s);

log_info("animation::sleeping");
ledkit.start(&led::animation::sleeping);
rtos::ThisThread::sleep_for(2s);

log_info("animation::sneeze");
ledkit.start(&led::animation::sneeze);
rtos::ThisThread::sleep_for(2s);

log_info("animation::spin_blink");
ledkit.start(&led::animation::spin_blink);
rtos::ThisThread::sleep_for(2s);

log_info("animation::sprinkles");
ledkit.start(&led::animation::sprinkles);
rtos::ThisThread::sleep_for(2s);

log_info("animation::underwater");
ledkit.start(&led::animation::underwater);
rtos::ThisThread::sleep_for(20s);

log_info("animation::wake_up");
ledkit.start(&led::animation::wake_up);
rtos::ThisThread::sleep_for(2s);

log_info("animation::wink");
ledkit.start(&led::animation::wink);
rtos::ThisThread::sleep_for(2s);

log_info("animation::yawn");
ledkit.start(&led::animation::yawn);
rtos::ThisThread::sleep_for(2s);
ledkit.stop();
while (true) {
rtos::ThisThread::sleep_for(10min);
}
}
102 changes: 101 additions & 1 deletion spikes/lk_log_kit/main.cpp
Original file line number Diff line number Diff line change
@@ -17,6 +17,102 @@ using namespace leka;
using namespace mbed;
using namespace std::chrono;

#include "mbed_stats.h"

#include "drivers/Watchdog.h"

namespace {

namespace watchdog {

namespace internal {

auto &instance = mbed::Watchdog::get_instance();
constexpr auto timeout = 30000ms;
auto thread = rtos::Thread {osPriorityLow};

namespace stats {

auto cpu = mbed_stats_cpu_t {};
auto stack = mbed_stats_stack_t {};
auto heap = mbed_stats_heap_t {};

} // namespace stats

__attribute__((noreturn)) void watchdog_kick()
{
static auto kick_count = uint32_t {0};

static auto start = rtos::Kernel::Clock::now();
static auto stop = rtos::Kernel::Clock::now();
static auto delta = static_cast<int>((stop - start).count());

static auto idle_ratio = uint8_t {};
static auto sleep_ratio = uint8_t {};
static auto deep_sleep_ratio = uint8_t {};

static auto stack_used_delta = int32_t {};
static auto stack_used_size = uint32_t {};
static auto stack_reserved_size = uint32_t {};
static auto stack_used_ratio = uint8_t {};

static auto heap_used_delta = int32_t {};
static auto heap_used_size = uint32_t {};
static auto heap_reserved_size = uint32_t {};
static auto heap_used_ratio = uint8_t {};

while (true) {
internal::instance.kick();
++kick_count;

stop = rtos::Kernel::Clock::now();
delta = static_cast<int>((stop - start).count());

mbed_stats_cpu_get(&stats::cpu);

idle_ratio = static_cast<uint8_t>(((stats::cpu.idle_time / 1000 * 100) / (stats::cpu.uptime / 1000)));
sleep_ratio = static_cast<uint8_t>(((stats::cpu.sleep_time / 1000 * 100) / (stats::cpu.uptime / 1000)));
deep_sleep_ratio =
static_cast<uint8_t>(((stats::cpu.deep_sleep_time / 1000 * 100) / (stats::cpu.uptime / 1000)));

mbed_stats_stack_get(&stats::stack);

stack_used_delta = static_cast<int32_t>(stats::stack.max_size - stack_used_size);
stack_used_size = stats::stack.max_size;
stack_reserved_size = stats::stack.reserved_size;
stack_used_ratio = static_cast<uint8_t>((stack_used_size * 100) / stack_reserved_size);

mbed_stats_heap_get(&stats::heap);

heap_used_delta = static_cast<int32_t>(stats::heap.current_size - heap_used_size);
heap_used_size = stats::heap.current_size;
heap_reserved_size = stats::heap.reserved_size;
heap_used_ratio = static_cast<uint8_t>((heap_used_size * 100) / heap_reserved_size);

log_info(
"dt: %i, kck: %u, idl: %u%%, slp: %u%%, dsl: %u%%, sur: %u%% (%+i)[%u/"
"%u], hur: %u%% (%+i)[%u/%u]",
delta, kick_count, idle_ratio, sleep_ratio, deep_sleep_ratio, stack_used_ratio, stack_used_delta,
stack_used_size, stack_reserved_size, heap_used_ratio, heap_used_delta, heap_used_size,
heap_reserved_size);

start = rtos::Kernel::Clock::now();
rtos::ThisThread::sleep_for(5s);
}
}

} // namespace internal

void start()
{
internal::instance.start(internal::timeout.count());
internal::thread.start(watchdog::internal::watchdog_kick);
}

} // namespace watchdog

} // namespace

auto hello = HelloWorld {};

auto thread_log_debug = rtos::Thread {};
@@ -57,7 +153,7 @@ auto main() -> int

// ticker_log_from_isr.attach(log_isr_lambda, 5s);

while (true) {
{
auto start = rtos::Kernel::Clock::now();
log_debug("A message from your board %s --> \"%s\" at %ims", MBED_CONF_APP_TARGET_NAME, hello.world,
int(rtos::Kernel::Clock::now().time_since_epoch().count()));
@@ -67,4 +163,8 @@ auto main() -> int

rtos::ThisThread::sleep_for(3333ms);
}

while (true) {
rtos::ThisThread::sleep_for(10min);
}
}
103 changes: 102 additions & 1 deletion spikes/lk_motion_kit/main.cpp
Original file line number Diff line number Diff line change
@@ -21,8 +21,100 @@
using namespace std::chrono;
using namespace leka;

#include "mbed_stats.h"

#include "drivers/Watchdog.h"

namespace {

namespace watchdog {

namespace internal {

auto &instance = mbed::Watchdog::get_instance();
constexpr auto timeout = 30000ms;
auto thread = rtos::Thread {osPriorityLow};

namespace stats {

auto cpu = mbed_stats_cpu_t {};
auto stack = mbed_stats_stack_t {};
auto heap = mbed_stats_heap_t {};

} // namespace stats

__attribute__((noreturn)) void watchdog_kick()
{
static auto kick_count = uint32_t {0};

static auto start = rtos::Kernel::Clock::now();
static auto stop = rtos::Kernel::Clock::now();
static auto delta = static_cast<int>((stop - start).count());

static auto idle_ratio = uint8_t {};
static auto sleep_ratio = uint8_t {};
static auto deep_sleep_ratio = uint8_t {};

static auto stack_used_delta = int32_t {};
static auto stack_used_size = uint32_t {};
static auto stack_reserved_size = uint32_t {};
static auto stack_used_ratio = uint8_t {};

static auto heap_used_delta = int32_t {};
static auto heap_used_size = uint32_t {};
static auto heap_reserved_size = uint32_t {};
static auto heap_used_ratio = uint8_t {};

while (true) {
internal::instance.kick();
++kick_count;

stop = rtos::Kernel::Clock::now();
delta = static_cast<int>((stop - start).count());

mbed_stats_cpu_get(&stats::cpu);

idle_ratio = static_cast<uint8_t>(((stats::cpu.idle_time / 1000 * 100) / (stats::cpu.uptime / 1000)));
sleep_ratio = static_cast<uint8_t>(((stats::cpu.sleep_time / 1000 * 100) / (stats::cpu.uptime / 1000)));
deep_sleep_ratio =
static_cast<uint8_t>(((stats::cpu.deep_sleep_time / 1000 * 100) / (stats::cpu.uptime / 1000)));

mbed_stats_stack_get(&stats::stack);

stack_used_delta = static_cast<int32_t>(stats::stack.max_size - stack_used_size);
stack_used_size = stats::stack.max_size;
stack_reserved_size = stats::stack.reserved_size;
stack_used_ratio = static_cast<uint8_t>((stack_used_size * 100) / stack_reserved_size);

mbed_stats_heap_get(&stats::heap);

heap_used_delta = static_cast<int32_t>(stats::heap.current_size - heap_used_size);
heap_used_size = stats::heap.current_size;
heap_reserved_size = stats::heap.reserved_size;
heap_used_ratio = static_cast<uint8_t>((heap_used_size * 100) / heap_reserved_size);

log_info(
"dt: %i, kck: %u, idl: %u%%, slp: %u%%, dsl: %u%%, sur: %u%% (%+i)[%u/"
"%u], hur: %u%% (%+i)[%u/%u]",
delta, kick_count, idle_ratio, sleep_ratio, deep_sleep_ratio, stack_used_ratio, stack_used_delta,
stack_used_size, stack_reserved_size, heap_used_ratio, heap_used_delta, heap_used_size,
heap_reserved_size);

start = rtos::Kernel::Clock::now();
rtos::ThisThread::sleep_for(5s);
}
}

} // namespace internal

void start()
{
internal::instance.start(internal::timeout.count());
internal::thread.start(watchdog::internal::watchdog_kick);
}

} // namespace watchdog

namespace motors {

namespace left {
@@ -127,6 +219,7 @@ void onMagicCardAvailable(const MagicCard &card)
auto main() -> int
{
logger::init();
watchdog::start();

HelloWorld hello;
hello.start();
@@ -137,7 +230,15 @@ auto main() -> int

rfidkit.onTagActivated(onMagicCardAvailable);

while (true) {
{
rtos::ThisThread::sleep_for(100ms);
}

rfidkit.enableDeepSleep();
motors::left::motor.enableDeepSleep();
motors::right::motor.enableDeepSleep();

while (true) {
rtos::ThisThread::sleep_for(10min);
}
}
112 changes: 104 additions & 8 deletions spikes/lk_motors/main.cpp
Original file line number Diff line number Diff line change
@@ -18,6 +18,101 @@
using namespace leka;
using namespace std::chrono;

#include "mbed_stats.h"

#include "drivers/Watchdog.h"
namespace {

namespace watchdog {

namespace internal {

auto &instance = mbed::Watchdog::get_instance();
constexpr auto timeout = 30000ms;
auto thread = rtos::Thread {osPriorityLow};

namespace stats {

auto cpu = mbed_stats_cpu_t {};
auto stack = mbed_stats_stack_t {};
auto heap = mbed_stats_heap_t {};

} // namespace stats

__attribute__((noreturn)) void watchdog_kick()
{
static auto kick_count = uint32_t {0};

static auto start = rtos::Kernel::Clock::now();
static auto stop = rtos::Kernel::Clock::now();
static auto delta = static_cast<int>((stop - start).count());

static auto idle_ratio = uint8_t {};
static auto sleep_ratio = uint8_t {};
static auto deep_sleep_ratio = uint8_t {};

static auto stack_used_delta = int32_t {};
static auto stack_used_size = uint32_t {};
static auto stack_reserved_size = uint32_t {};
static auto stack_used_ratio = uint8_t {};

static auto heap_used_delta = int32_t {};
static auto heap_used_size = uint32_t {};
static auto heap_reserved_size = uint32_t {};
static auto heap_used_ratio = uint8_t {};

while (true) {
internal::instance.kick();
++kick_count;

stop = rtos::Kernel::Clock::now();
delta = static_cast<int>((stop - start).count());

mbed_stats_cpu_get(&stats::cpu);

idle_ratio = static_cast<uint8_t>(((stats::cpu.idle_time / 1000 * 100) / (stats::cpu.uptime / 1000)));
sleep_ratio = static_cast<uint8_t>(((stats::cpu.sleep_time / 1000 * 100) / (stats::cpu.uptime / 1000)));
deep_sleep_ratio =
static_cast<uint8_t>(((stats::cpu.deep_sleep_time / 1000 * 100) / (stats::cpu.uptime / 1000)));

mbed_stats_stack_get(&stats::stack);

stack_used_delta = static_cast<int32_t>(stats::stack.max_size - stack_used_size);
stack_used_size = stats::stack.max_size;
stack_reserved_size = stats::stack.reserved_size;
stack_used_ratio = static_cast<uint8_t>((stack_used_size * 100) / stack_reserved_size);

mbed_stats_heap_get(&stats::heap);

heap_used_delta = static_cast<int32_t>(stats::heap.current_size - heap_used_size);
heap_used_size = stats::heap.current_size;
heap_reserved_size = stats::heap.reserved_size;
heap_used_ratio = static_cast<uint8_t>((heap_used_size * 100) / heap_reserved_size);

log_info(
"dt: %i, kck: %u, idl: %u%%, slp: %u%%, dsl: %u%%, sur: %u%% (%+i)[%u/"
"%u], hur: %u%% (%+i)[%u/%u]",
delta, kick_count, idle_ratio, sleep_ratio, deep_sleep_ratio, stack_used_ratio, stack_used_delta,
stack_used_size, stack_reserved_size, heap_used_ratio, heap_used_delta, heap_used_size,
heap_reserved_size);

start = rtos::Kernel::Clock::now();
rtos::ThisThread::sleep_for(5s);
}
}

} // namespace internal

void start()
{
internal::instance.start(internal::timeout.count());
internal::thread.start(watchdog::internal::watchdog_kick);
}

} // namespace watchdog

} // namespace

void spinLeft(interface::Motor &left, interface::Motor &right)
{
left.spin(Rotation::clockwise, 0.5F);
@@ -39,6 +134,7 @@ void stop(interface::Motor &left, interface::Motor &right)
auto main() -> int
{
logger::init();
watchdog::start();

auto start = rtos::Kernel::Clock::now();

@@ -60,7 +156,7 @@ auto main() -> int
auto motor_left = CoreMotor {motor_left_dir_1, motor_left_dir_2, motor_left_speed};
auto motor_right = CoreMotor {motor_right_dir_1, motor_right_dir_2, motor_right_speed};

while (true) {
{
auto t = rtos::Kernel::Clock::now() - start;
log_info("A message from your board %s --> \"%s\" at %i s\n", MBED_CONF_APP_TARGET_NAME, hello.world,
int(t.count() / 1000));
@@ -70,16 +166,16 @@ auto main() -> int
log_info("Spin left...");
spinLeft(motor_left, motor_right);

rtos::ThisThread::sleep_for(5s);

log_info("Spin right...");
spinRight(motor_left, motor_right);

rtos::ThisThread::sleep_for(5s);
rtos::ThisThread::sleep_for(1s);

log_info("Spin stop...");
stop(motor_left, motor_right);
}

rtos::ThisThread::sleep_for(5s);
motor_left.enableDeepSleep();
motor_right.enableDeepSleep();

while (true) {
rtos::ThisThread::sleep_for(10min);
}
}
100 changes: 100 additions & 0 deletions spikes/lk_qdac/main.cpp
Original file line number Diff line number Diff line change
@@ -19,6 +19,101 @@ using namespace std::chrono;
// MARK: - Global definitions
//

#include "mbed_stats.h"

#include "drivers/Watchdog.h"
namespace {

namespace watchdog {

namespace internal {

auto &instance = mbed::Watchdog::get_instance();
constexpr auto timeout = 30000ms;
auto thread = rtos::Thread {osPriorityLow};

namespace stats {

auto cpu = mbed_stats_cpu_t {};
auto stack = mbed_stats_stack_t {};
auto heap = mbed_stats_heap_t {};

} // namespace stats

__attribute__((noreturn)) void watchdog_kick()
{
static auto kick_count = uint32_t {0};

static auto start = rtos::Kernel::Clock::now();
static auto stop = rtos::Kernel::Clock::now();
static auto delta = static_cast<int>((stop - start).count());

static auto idle_ratio = uint8_t {};
static auto sleep_ratio = uint8_t {};
static auto deep_sleep_ratio = uint8_t {};

static auto stack_used_delta = int32_t {};
static auto stack_used_size = uint32_t {};
static auto stack_reserved_size = uint32_t {};
static auto stack_used_ratio = uint8_t {};

static auto heap_used_delta = int32_t {};
static auto heap_used_size = uint32_t {};
static auto heap_reserved_size = uint32_t {};
static auto heap_used_ratio = uint8_t {};

while (true) {
internal::instance.kick();
++kick_count;

stop = rtos::Kernel::Clock::now();
delta = static_cast<int>((stop - start).count());

mbed_stats_cpu_get(&stats::cpu);

idle_ratio = static_cast<uint8_t>(((stats::cpu.idle_time / 1000 * 100) / (stats::cpu.uptime / 1000)));
sleep_ratio = static_cast<uint8_t>(((stats::cpu.sleep_time / 1000 * 100) / (stats::cpu.uptime / 1000)));
deep_sleep_ratio =
static_cast<uint8_t>(((stats::cpu.deep_sleep_time / 1000 * 100) / (stats::cpu.uptime / 1000)));

mbed_stats_stack_get(&stats::stack);

stack_used_delta = static_cast<int32_t>(stats::stack.max_size - stack_used_size);
stack_used_size = stats::stack.max_size;
stack_reserved_size = stats::stack.reserved_size;
stack_used_ratio = static_cast<uint8_t>((stack_used_size * 100) / stack_reserved_size);

mbed_stats_heap_get(&stats::heap);

heap_used_delta = static_cast<int32_t>(stats::heap.current_size - heap_used_size);
heap_used_size = stats::heap.current_size;
heap_reserved_size = stats::heap.reserved_size;
heap_used_ratio = static_cast<uint8_t>((heap_used_size * 100) / heap_reserved_size);

log_info(
"dt: %i, kck: %u, idl: %u%%, slp: %u%%, dsl: %u%%, sur: %u%% (%+i)[%u/"
"%u], hur: %u%% (%+i)[%u/%u]",
delta, kick_count, idle_ratio, sleep_ratio, deep_sleep_ratio, stack_used_ratio, stack_used_delta,
stack_used_size, stack_reserved_size, heap_used_ratio, heap_used_delta, heap_used_size,
heap_reserved_size);

start = rtos::Kernel::Clock::now();
rtos::ThisThread::sleep_for(5s);
}
}

} // namespace internal

void start()
{
internal::instance.start(internal::timeout.count());
internal::thread.start(watchdog::internal::watchdog_kick);
}

} // namespace watchdog

} // namespace

auto corei2c = CoreI2C {PinName::SENSOR_PROXIMITY_MUX_I2C_SDA, PinName::SENSOR_PROXIMITY_MUX_I2C_SCL};
auto dac = CoreQDACMCP4728 {corei2c, 0xC2};

@@ -39,6 +134,7 @@ void printInputRegisters()
auto main() -> int
{
logger::init();
watchdog::start();

log_info("Hello, World!\n\n");

@@ -73,4 +169,8 @@ auto main() -> int
rtos::ThisThread::sleep_for(100ms);
printInputRegisters();
rtos::ThisThread::sleep_for(1s);

while (true) {
rtos::ThisThread::sleep_for(10min);
}
}
114 changes: 102 additions & 12 deletions spikes/lk_reinforcer/main.cpp
Original file line number Diff line number Diff line change
@@ -45,8 +45,99 @@ using namespace std::chrono;
// MARK: - Global definitions
//

#include "mbed_stats.h"

#include "drivers/Watchdog.h"
namespace {

namespace watchdog {

namespace internal {

auto &instance = mbed::Watchdog::get_instance();
constexpr auto timeout = 30000ms;
auto thread = rtos::Thread {osPriorityLow};

namespace stats {

auto cpu = mbed_stats_cpu_t {};
auto stack = mbed_stats_stack_t {};
auto heap = mbed_stats_heap_t {};

} // namespace stats

__attribute__((noreturn)) void watchdog_kick()
{
static auto kick_count = uint32_t {0};

static auto start = rtos::Kernel::Clock::now();
static auto stop = rtos::Kernel::Clock::now();
static auto delta = static_cast<int>((stop - start).count());

static auto idle_ratio = uint8_t {};
static auto sleep_ratio = uint8_t {};
static auto deep_sleep_ratio = uint8_t {};

static auto stack_used_delta = int32_t {};
static auto stack_used_size = uint32_t {};
static auto stack_reserved_size = uint32_t {};
static auto stack_used_ratio = uint8_t {};

static auto heap_used_delta = int32_t {};
static auto heap_used_size = uint32_t {};
static auto heap_reserved_size = uint32_t {};
static auto heap_used_ratio = uint8_t {};

while (true) {
internal::instance.kick();
++kick_count;

stop = rtos::Kernel::Clock::now();
delta = static_cast<int>((stop - start).count());

mbed_stats_cpu_get(&stats::cpu);

idle_ratio = static_cast<uint8_t>(((stats::cpu.idle_time / 1000 * 100) / (stats::cpu.uptime / 1000)));
sleep_ratio = static_cast<uint8_t>(((stats::cpu.sleep_time / 1000 * 100) / (stats::cpu.uptime / 1000)));
deep_sleep_ratio =
static_cast<uint8_t>(((stats::cpu.deep_sleep_time / 1000 * 100) / (stats::cpu.uptime / 1000)));

mbed_stats_stack_get(&stats::stack);

stack_used_delta = static_cast<int32_t>(stats::stack.max_size - stack_used_size);
stack_used_size = stats::stack.max_size;
stack_reserved_size = stats::stack.reserved_size;
stack_used_ratio = static_cast<uint8_t>((stack_used_size * 100) / stack_reserved_size);

mbed_stats_heap_get(&stats::heap);

heap_used_delta = static_cast<int32_t>(stats::heap.current_size - heap_used_size);
heap_used_size = stats::heap.current_size;
heap_reserved_size = stats::heap.reserved_size;
heap_used_ratio = static_cast<uint8_t>((heap_used_size * 100) / heap_reserved_size);

log_info(
"dt: %i, kck: %u, idl: %u%%, slp: %u%%, dsl: %u%%, sur: %u%% (%+i)[%u/"
"%u], hur: %u%% (%+i)[%u/%u]",
delta, kick_count, idle_ratio, sleep_ratio, deep_sleep_ratio, stack_used_ratio, stack_used_delta,
stack_used_size, stack_reserved_size, heap_used_ratio, heap_used_delta, heap_used_size,
heap_reserved_size);

start = rtos::Kernel::Clock::now();
rtos::ThisThread::sleep_for(5s);
}
}

} // namespace internal

void start()
{
internal::instance.start(internal::timeout.count());
internal::thread.start(watchdog::internal::watchdog_kick);
}

} // namespace watchdog

namespace sd {

namespace internal {
@@ -190,6 +281,7 @@ auto hello = HelloWorld {};
auto main() -> int
{
logger::init();
watchdog::start();
leds::turnOff();

log_info("Hello, World!\n\n");
@@ -207,20 +299,18 @@ auto main() -> int

rtos::ThisThread::sleep_for(3s);

while (true) {
reinforcerkit.play(ReinforcerKit::Reinforcer::Fire);
rtos::ThisThread::sleep_for(10s);

reinforcerkit.play(ReinforcerKit::Reinforcer::BlinkGreen);
rtos::ThisThread::sleep_for(10s);

{
reinforcerkit.play(ReinforcerKit::Reinforcer::SpinBlink);
rtos::ThisThread::sleep_for(10s);
rtos::ThisThread::sleep_for(1s);
}

reinforcerkit.play(ReinforcerKit::Reinforcer::Sprinkles);
rtos::ThisThread::sleep_for(5s);
reinforcerkit.stop();

reinforcerkit.play(ReinforcerKit::Reinforcer::Rainbow);
rtos::ThisThread::sleep_for(5s);
display::internal::corelcd.enableDeepSleep();
motor::left.enableDeepSleep();
motor::right.enableDeepSleep();

while (true) {
rtos::ThisThread::sleep_for(10min);
}
}
Loading