diff --git a/apps/utest/test_workq/Kconfig b/apps/utest/test_workq/Kconfig new file mode 100644 index 0000000000..6829919294 --- /dev/null +++ b/apps/utest/test_workq/Kconfig @@ -0,0 +1,6 @@ +menuconfig TEST_WORK_QUEUE + bool "test work queue" + default n + +if TEST_WORK_QUEUE +endif diff --git a/apps/utest/test_workq/SConscript b/apps/utest/test_workq/SConscript new file mode 100644 index 0000000000..15824c83f4 --- /dev/null +++ b/apps/utest/test_workq/SConscript @@ -0,0 +1,22 @@ + +import os +import rtconfig +from building import * + +cwd = GetCurrentDir() +group = [] + + +# 添加当前文件夹下的代码 +src = Glob("*.c") + Glob("*.cpp") +inc = [cwd] + +group += DefineGroup("utest", src, depend = [''], CPPPATH = inc) + +for d in os.listdir(cwd): + path = os.path.join(cwd, d) + if os.path.isfile(os.path.join(path, "SConscript")): + # print(os.path.join(d, 'SConscript')) + group += SConscript(os.path.join(d, "SConscript")) + +Return("group") diff --git a/apps/utest/test_workq/workq_main.cpp b/apps/utest/test_workq/workq_main.cpp new file mode 100644 index 0000000000..179e96c384 --- /dev/null +++ b/apps/utest/test_workq/workq_main.cpp @@ -0,0 +1,55 @@ +#include +#include + +using namespace time_literals; +using namespace nextpilot; + +static wq_config_t sim_rate_ctrl{"wq:sim_rate_ctrl", 4096 * 10, 0}; + +class SimRateControl : public ModuleCommand, public nextpilot::WorkItemScheduled { +public: + SimRateControl() : + WorkItemScheduled(MODULE_NAME, sim_rate_ctrl) { + } + + ~SimRateControl() { + } + + /** @see ModuleCommand */ + static SimRateControl *instantiate(int argc, char *argv[]) { + SimRateControl *instance = new SimRateControl(); + return instance; + } + + /** @see ModuleCommand */ + static int custom_command(int argc, char *argv[]) { + return 0; + } + + /** @see ModuleCommand */ + static int print_usage(const char *reason = nullptr) { + return 0; + } + + int init() override { + ScheduleOnInterval(100_ms); // 8 Hz + return 0; + } + +private: + void Run() override { + static uint32_t cnt = 0; + if (should_exit()) { + } + rt_thread_mdelay(1000); + rt_kprintf("======%ld, %d\n", rt_tick_get(), cnt++); + } +}; + +int sim_rate_ctrl_start() { + const char *argv[] = {"sim_rate_control", "start"}; + int argc = sizeof(argv) / sizeof(argv[0]); + return SimRateControl::main(argc, (char **)argv); +} + +INIT_APP_EXPORT(sim_rate_ctrl_start);