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
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 6 additions & 4 deletions app/os/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,7 @@ namespace watchdog {
static auto battery_level = uint8_t {};
static auto charging_status = uint8_t {};

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

Expand All @@ -489,6 +490,7 @@ namespace watchdog {

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)));
Expand All @@ -508,11 +510,11 @@ namespace watchdog {
heap_used_ratio = static_cast<uint8_t>((heap_used_size * 100) / heap_reserved_size);

log_info(
"dt: %i, kck: %u, ble: %u, lvl: %u%%, chr: %u, slp: %u%%, dsl: %u%%, sur: %u%% (%+i)[%u/"
"dt: %i, kck: %u, ble: %u, lvl: %u%%, chr: %u, idl: %u%%, slp: %u%%, dsl: %u%%, sur: %u%% (%+i)[%u/"
"%u], hur: %u%% (%+i)[%u/%u]",
delta, kick_count, ble_connected, battery_level, charging_status, 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);
delta, kick_count, ble_connected, battery_level, charging_status, 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);
Expand Down
2 changes: 1 addition & 1 deletion libs/RobotKit/include/RobotController.h
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ class RobotController : public interface::RobotController

interface::Timeout &_timeout_state_internal;

std::chrono::seconds _sleep_timeout_duration {60};
std::chrono::seconds _sleep_timeout_duration {5};
std::chrono::seconds _idle_timeout_duration {600};
std::chrono::seconds _deep_sleep_timeout_duration {600};
interface::Timeout &_timeout_state_transition;
Expand Down
1 change: 1 addition & 0 deletions spikes/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ add_subdirectory(${SPIKES_DIR}/lk_imu_kit)
add_subdirectory(${SPIKES_DIR}/lk_lcd)
add_subdirectory(${SPIKES_DIR}/lk_led_kit)
add_subdirectory(${SPIKES_DIR}/lk_log_kit)
add_subdirectory(${SPIKES_DIR}/lk_logs)
add_subdirectory(${SPIKES_DIR}/lk_motion_kit)
add_subdirectory(${SPIKES_DIR}/lk_motors)
add_subdirectory(${SPIKES_DIR}/lk_qdac)
Expand Down
106 changes: 105 additions & 1 deletion spikes/lk_activity_kit/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -262,6 +353,7 @@ auto activitykit = ActivityKit {videokit};
auto main() -> int
{
logger::init();
watchdog::start();

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

Expand Down Expand Up @@ -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
Expand Up @@ -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"};

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

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

Expand All @@ -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);
}
}
Loading
Loading