Compare commits
2 Commits
37fef28911
...
7f17e56e34
| Author | SHA1 | Date | |
|---|---|---|---|
| 7f17e56e34 | |||
| ae53d7f7f3 |
@@ -11,11 +11,14 @@ project(app LANGUAGES C)
|
|||||||
|
|
||||||
target_sources(app
|
target_sources(app
|
||||||
PRIVATE
|
PRIVATE
|
||||||
|
src/FirmwareManager.cpp
|
||||||
|
src/FirmwareManager.hpp
|
||||||
src/main.cpp
|
src/main.cpp
|
||||||
src/SensorDataProcessor.cpp
|
src/SensorDataProcessor.cpp
|
||||||
src/SensorDataProcessor.hpp
|
src/SensorDataProcessor.hpp
|
||||||
src/SensorSampler.cpp
|
src/SensorSampler.cpp
|
||||||
src/SensorSampler.hpp
|
src/SensorSampler.hpp
|
||||||
|
src/ThreadWrapper.hpp
|
||||||
)
|
)
|
||||||
|
|
||||||
# The code below locates the git index file for this repository and adds it as a dependency for
|
# The code below locates the git index file for this repository and adds it as a dependency for
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
#include "FirmwareManager.hpp"
|
||||||
|
#include <zephyr/kernel.h>
|
||||||
|
|
||||||
|
void app::FirmwareManager::init() {}
|
||||||
|
|
||||||
|
void app::FirmwareManager::run() {
|
||||||
|
printk("app::FirmwareManager::run - Running...\n");
|
||||||
|
k_sleep(K_SECONDS(5));
|
||||||
|
}
|
||||||
|
|
||||||
|
void app::FirmwareManager::finalize() {}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
#ifndef FIRMWARE_MANAGER_HPP
|
||||||
|
#define FIRMWARE_MANAGER_HPP
|
||||||
|
|
||||||
|
#include "ThreadWrapper.hpp"
|
||||||
|
|
||||||
|
namespace app {
|
||||||
|
|
||||||
|
class FirmwareManager : public ThreadWrapper<FirmwareManager> {
|
||||||
|
public:
|
||||||
|
FirmwareManager() = default;
|
||||||
|
~FirmwareManager() = default;
|
||||||
|
|
||||||
|
void init();
|
||||||
|
|
||||||
|
void run();
|
||||||
|
|
||||||
|
void finalize();
|
||||||
|
|
||||||
|
private:
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace app
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -1,9 +1,11 @@
|
|||||||
#include "SensorDataProcessor.hpp"
|
#include "SensorDataProcessor.hpp"
|
||||||
#include <zephyr/kernel.h>
|
#include <zephyr/kernel.h>
|
||||||
|
|
||||||
void app::SensorDataProcessor::entryPoint(void *, void *, void *) {
|
void app::SensorDataProcessor::init() {}
|
||||||
while (true) {
|
|
||||||
printk("app::SensorDataProcessor::entryPoint - Running...\n");
|
void app::SensorDataProcessor::run() {
|
||||||
|
printk("app::SensorDataProcessor::run - Running...\n");
|
||||||
k_sleep(K_SECONDS(5));
|
k_sleep(K_SECONDS(5));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void app::SensorDataProcessor::finalize() {}
|
||||||
|
|||||||
@@ -1,15 +1,20 @@
|
|||||||
#ifndef SENSOR_DATA_PROCESSOR_HPP
|
#ifndef SENSOR_DATA_PROCESSOR_HPP
|
||||||
#define SENSOR_DATA_PROCESSOR_HPP
|
#define SENSOR_DATA_PROCESSOR_HPP
|
||||||
|
|
||||||
|
#include "ThreadWrapper.hpp"
|
||||||
|
|
||||||
namespace app {
|
namespace app {
|
||||||
|
|
||||||
class SensorDataProcessor {
|
class SensorDataProcessor : public ThreadWrapper<SensorDataProcessor> {
|
||||||
public:
|
public:
|
||||||
SensorDataProcessor() = default;
|
SensorDataProcessor() = default;
|
||||||
~SensorDataProcessor() = default;
|
~SensorDataProcessor() = default;
|
||||||
|
|
||||||
// Thread entry
|
void init();
|
||||||
static void entryPoint(void *, void *, void *);
|
|
||||||
|
void run();
|
||||||
|
|
||||||
|
void finalize();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,9 +1,11 @@
|
|||||||
#include "SensorSampler.hpp"
|
#include "SensorSampler.hpp"
|
||||||
#include <zephyr/kernel.h>
|
#include <zephyr/kernel.h>
|
||||||
|
|
||||||
void app::SensorSampler::entryPoint(void *, void *, void *) {
|
void app::SensorSampler::init() {}
|
||||||
while (true) {
|
|
||||||
printk("app::SensorSampler::entryPoint - Running...\n");
|
void app::SensorSampler::run() {
|
||||||
|
printk("app::SensorSampler::run - Running...\n");
|
||||||
k_sleep(K_SECONDS(5));
|
k_sleep(K_SECONDS(5));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void app::SensorSampler::finalize() {}
|
||||||
|
|||||||
@@ -1,15 +1,20 @@
|
|||||||
#ifndef SENSOR_SAMPLER_HPP
|
#ifndef SENSOR_SAMPLER_HPP
|
||||||
#define SENSOR_SAMPLER_HPP
|
#define SENSOR_SAMPLER_HPP
|
||||||
|
|
||||||
|
#include "ThreadWrapper.hpp"
|
||||||
|
|
||||||
namespace app {
|
namespace app {
|
||||||
|
|
||||||
class SensorSampler {
|
class SensorSampler : public ThreadWrapper<SensorSampler> {
|
||||||
public:
|
public:
|
||||||
SensorSampler() = default;
|
SensorSampler() = default;
|
||||||
~SensorSampler() = default;
|
~SensorSampler() = default;
|
||||||
|
|
||||||
// Thread entry
|
void init();
|
||||||
static void entryPoint(void *, void *, void *);
|
|
||||||
|
void run();
|
||||||
|
|
||||||
|
void finalize();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -0,0 +1,36 @@
|
|||||||
|
#ifndef THREAD_WRAPPER_HPP
|
||||||
|
#define THREAD_WRAPPER_HPP
|
||||||
|
|
||||||
|
#include <cstddef>
|
||||||
|
|
||||||
|
namespace app {
|
||||||
|
|
||||||
|
template <typename ThreadType> class ThreadWrapper {
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* @brief Entry point to thread. Must define init(), run(), and finalize() for
|
||||||
|
* thread type.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
inline static void entryPoint(void *, void *, void *) {
|
||||||
|
auto thread = ThreadType();
|
||||||
|
thread.init();
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
thread.run();
|
||||||
|
thread.incrementRunCount();
|
||||||
|
}
|
||||||
|
|
||||||
|
// NOTE: Maybe one day I'll add logic to be able to finalize a thread...
|
||||||
|
thread.finalize();
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
inline void incrementRunCount() { ++runCounter_; }
|
||||||
|
|
||||||
|
std::size_t runCounter_ = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace app
|
||||||
|
|
||||||
|
#endif
|
||||||
+8
-5
@@ -1,8 +1,4 @@
|
|||||||
/*
|
#include "FirmwareManager.hpp"
|
||||||
* Copyright (c) 2021 Nordic Semiconductor ASA
|
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "SensorDataProcessor.hpp"
|
#include "SensorDataProcessor.hpp"
|
||||||
#include "SensorSampler.hpp"
|
#include "SensorSampler.hpp"
|
||||||
#include <app_version.h>
|
#include <app_version.h>
|
||||||
@@ -11,6 +7,13 @@
|
|||||||
|
|
||||||
LOG_MODULE_REGISTER(main, CONFIG_APP_LOG_LEVEL);
|
LOG_MODULE_REGISTER(main, CONFIG_APP_LOG_LEVEL);
|
||||||
|
|
||||||
|
// Firmware Manager
|
||||||
|
static constexpr size_t FirmwareManagerStackSize = 1024;
|
||||||
|
static constexpr size_t FirmwareManagerPriority = 5;
|
||||||
|
K_THREAD_DEFINE(FirmwareManagerThreadId, FirmwareManagerStackSize,
|
||||||
|
app::FirmwareManager::entryPoint, NULL, NULL, NULL,
|
||||||
|
FirmwareManagerPriority, 0, 0);
|
||||||
|
|
||||||
// Sensor Data Processor
|
// Sensor Data Processor
|
||||||
static constexpr size_t SensorDataProcessorStackSize = 1024;
|
static constexpr size_t SensorDataProcessorStackSize = 1024;
|
||||||
static constexpr size_t SensorDataProcessorPriority = 5;
|
static constexpr size_t SensorDataProcessorPriority = 5;
|
||||||
|
|||||||
Reference in New Issue
Block a user