Added timer trigger for continuous ADC, added command to set the ADC read timer interval
This commit is contained in:
@@ -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;
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user