From 6e9d234dc022c2b159286727b9f51c9e4384b70b Mon Sep 17 00:00:00 2001 From: Peter McGoron Date: Mon, 3 Apr 2023 03:29:56 +0000 Subject: [PATCH] logging and error handling --- software/src/access.c | 48 +++++++++++++++++++++++++++---------------- software/src/access.h | 5 ----- 2 files changed, 30 insertions(+), 23 deletions(-) diff --git a/software/src/access.c b/software/src/access.c index 109ed95..c756f40 100644 --- a/software/src/access.c +++ b/software/src/access.c @@ -10,9 +10,12 @@ */ #include +#include #include "converters.h" #include "pin_io.h" +LOG_MODULE_REGISTER(access); + static inline uint32_t sign_extend(uint32_t in, unsigned len) { @@ -325,30 +328,39 @@ waveform_disarm(int slot) void access_release_thread(void) { - while (cloop_release() == 0); + while (cloop_release() == 0) + cloop_locked--; + if (cloop_locked != 0) { + LOG_WRN("cloop mutex counter mismatch"); + cloop_locked = 0; + } - for (int i = 0; i < DAC_NUM; i++) { + for (int i = 0; i < DAC_MAX; i++) { while (dac_release(i) == 0); - while (waveform_release(i) == 0); + dac_locked[i]--; + if (dac_locked[i] != 0) { + LOG_WRN("dac mutex %d counter mismatch", i); + dac_locked[i] = 0; + } + + while (waveform_release(i) == 0) + waveform_locked[i]--; + if (waveform_locked[i] != 0) { + LOG_WRN("waveform mutex %d counter mismatch", i); + waveform_locked[i] = 0; + } } - for (int i = 0; i < ADC_NUM; i++) { - while (adc_release(i) == 0); - } -} - -void -access_thread_init(void) -{ - cloop_locked = 0; - - for (int i = 0; i < DAC_NUM; i++) { - dac_locked[i] = 0; - waveform_locked[i] = 0; + for (int i = 0; i < DAC_MAX; i++) { } - for (int i = 0; i < ADC_NUM; i++) { - adc_locked[i] = 0; + for (int i = 0; i < ADC_MAX; i++) { + while (adc_release(i) == 0) + adc_locked[i]--; + if (adc_locked[i] != 0) { + LOG_WRN("adc mutex %d counter mismatch", i); + adc_locked[i] = 0; + } } } diff --git a/software/src/access.h b/software/src/access.h index 6ba4836..2ac1ab3 100644 --- a/software/src/access.h +++ b/software/src/access.h @@ -27,10 +27,5 @@ int waveform_disarm(int slot); */ void access_release_thread(void); -/* Initialize thread local data, which might be non-zero due - * to reusing threads. - */ -void access_thread_init(void); - /* Called once on initializion. */ int access_init(void);