feat: LED-Treiber, Licht-Task und UART-Testkonsole
This commit is contained in:
+87
-7
@@ -2,21 +2,101 @@
|
||||
|
||||
#include "wm_include.h"
|
||||
|
||||
#define NL_APP_TASK_PRIO 40
|
||||
static u32 s_app_stack[512];
|
||||
#include "board/nl_board.h"
|
||||
#include "config/nl_settings.h"
|
||||
#include "drivers/nl_led.h"
|
||||
#include "light/nl_boot_state.h"
|
||||
#include "light/nl_control.h"
|
||||
#include "light/nl_engine.h"
|
||||
#include "sys/nl_app.h"
|
||||
#include "sys/nl_console.h"
|
||||
|
||||
#define NL_LIGHT_PRIO 30
|
||||
#define NL_APP_PRIO 40
|
||||
|
||||
static tls_os_mutex_t *s_lock;
|
||||
static nl_settings_t s_settings;
|
||||
static volatile uint32_t s_light_beat;
|
||||
static u32 s_app_stack[1024];
|
||||
static u32 s_light_stack[512];
|
||||
|
||||
void nl_app_lock(void) { tls_os_mutex_acquire(s_lock, 0); }
|
||||
void nl_app_unlock(void) { tls_os_mutex_release(s_lock); }
|
||||
|
||||
uint32_t nl_app_now_ms(void)
|
||||
{
|
||||
return (uint32_t)((uint64_t)tls_os_get_time() * 1000u / HZ);
|
||||
}
|
||||
|
||||
nl_settings_t *nl_app_settings(void) { return &s_settings; }
|
||||
|
||||
int nl_app_save_settings(void)
|
||||
{
|
||||
return 0; /* persistence follows in task 12 */
|
||||
}
|
||||
|
||||
void nl_app_factory_reset(void)
|
||||
{
|
||||
printf("factory reset: not implemented yet\r\n");
|
||||
}
|
||||
|
||||
static void led_out(const uint8_t ch[NL_CH_COUNT], void *ctx)
|
||||
{
|
||||
(void)ctx;
|
||||
nl_led_set(ch);
|
||||
}
|
||||
|
||||
static void light_task(void *arg)
|
||||
{
|
||||
uint32_t last = nl_app_now_ms();
|
||||
(void)arg;
|
||||
for (;;) {
|
||||
uint32_t now;
|
||||
tls_os_time_delay(HZ / 100 ? HZ / 100 : 1); /* ~10 ms */
|
||||
now = nl_app_now_ms();
|
||||
nl_app_lock();
|
||||
nl_engine_tick(now - last);
|
||||
nl_app_unlock();
|
||||
last = now;
|
||||
s_light_beat++;
|
||||
}
|
||||
}
|
||||
|
||||
static void app_task(void *arg)
|
||||
{
|
||||
unsigned int n = 0;
|
||||
const nl_board_t *board = nl_board_get();
|
||||
nl_engine_cfg_t cfg;
|
||||
nl_light_state_t initial;
|
||||
|
||||
(void)arg;
|
||||
for (;;) {
|
||||
printf("ninlight %s alive %u\r\n", NINLIGHT_DEVICE_ID, n++);
|
||||
nl_settings_defaults(&s_settings);
|
||||
|
||||
nl_led_init(board);
|
||||
cfg.ct_min = board->ct_min;
|
||||
cfg.ct_max = board->ct_max;
|
||||
cfg.output = led_out;
|
||||
cfg.ctx = NULL;
|
||||
nl_app_lock();
|
||||
nl_engine_init(&cfg);
|
||||
nl_ctrl_init(board, s_settings.fade_in_ms, s_settings.fade_out_ms);
|
||||
initial = nl_boot_default_state(board);
|
||||
nl_ctrl_boot(&initial);
|
||||
nl_app_unlock();
|
||||
|
||||
tls_os_task_create(NULL, "nl_light", light_task, NULL, (u8 *)s_light_stack, sizeof(s_light_stack), NL_LIGHT_PRIO, 0);
|
||||
nl_console_start();
|
||||
|
||||
for (;;)
|
||||
tls_os_time_delay(HZ);
|
||||
}
|
||||
}
|
||||
|
||||
void UserMain(void)
|
||||
{
|
||||
printf("\r\nninlight %s for %s (built %s)\r\n", NINLIGHT_FW_VERSION, NINLIGHT_DEVICE_ID, NINLIGHT_BUILD_DATE);
|
||||
tls_os_task_create(NULL, "nl_app", app_task, NULL, (u8 *)s_app_stack, sizeof(s_app_stack), NL_APP_TASK_PRIO, 0);
|
||||
if (nl_board_get() == NULL) {
|
||||
printf("FATAL: unknown board %s\r\n", NINLIGHT_DEVICE_ID);
|
||||
return;
|
||||
}
|
||||
tls_os_mutex_create(0, &s_lock);
|
||||
tls_os_task_create(NULL, "nl_app", app_task, NULL, (u8 *)s_app_stack, sizeof(s_app_stack), NL_APP_PRIO, 0);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user