Added timer trigger for continuous ADC, added command to set the ADC read timer interval

This commit is contained in:
Your Name
2026-09-24 14:56:37 +03:00
parent 4066cd3fbe
commit 921796cb6e
4 changed files with 164 additions and 0 deletions
+24
View File
@@ -32,6 +32,14 @@ K_THREAD_STACK_DEFINE(adc_thread_stack, ADC_THREAD_STACK_SIZE);
char adc_mask_msgq_buffer[ADC_MASK_BUFFER_SIZE * sizeof(uint32_t)];
struct k_msgq adc_mask_msgq;
// ADC TIMER
struct k_timer adc_timer;
static void adc_timer_handler(struct k_timer *timer) {
// Timer trigger
adc_add_mask(0b1111111111111111);
}
static void adc_thread(void *p1, void *p2, void *p3) {
ARG_UNUSED(p1);
@@ -65,8 +73,12 @@ static void adc_thread(void *p1, void *p2, void *p3) {
int adc_init_all(void) {
int ret;
// MSGQ
k_msgq_init(&adc_mask_msgq, adc_mask_msgq_buffer, sizeof(uint32_t), ADC_MASK_BUFFER_SIZE);
// TIMER
k_timer_init(&adc_timer, adc_timer_handler, NULL);
// ret = mux_init();
// if (ret != 0) {
// LOG_ERR("Failed to setup multiplexer: %d", ret);
@@ -181,5 +193,17 @@ int adc_read_id(int id) {
int adc_add_mask(uint32_t mask) {
k_msgq_put(&adc_mask_msgq, &mask, K_NO_WAIT);
return 0;
}
int adc_timer_set(int interval_ms) {
if (interval_ms > 0) {
k_timer_start(&adc_timer, K_MSEC(interval_ms), K_MSEC(interval_ms));
}
else {
k_timer_stop(&adc_timer);
}
return 0;
}
+1
View File
@@ -12,6 +12,7 @@
int adc_init_all();
int adc_read_id(int id);
int adc_add_mask(uint32_t mask);
int adc_timer_set(int interval_ms);
#endif // ADC_H
+10
View File
@@ -96,6 +96,7 @@ int command_handler(struct command_message_t *msg) {
break;
}
case ADC_READ_ALL: {
uint32_t mask = 0b1111111111111111;
@@ -104,6 +105,15 @@ int command_handler(struct command_message_t *msg) {
break;
}
case ADC_SET_READ: {
int interval_ms;
memcpy(&interval_ms, &msg->data[0], sizeof(int));
adc_timer_set(interval_ms);
break;
}
default: {
LOG_WRN("Unknown command received: %d", msg->command);
return -EINVAL;