logging and error handling

This commit is contained in:
Peter McGoron 2023-04-03 03:29:56 +00:00
parent 6b27356820
commit 6e9d234dc0
2 changed files with 30 additions and 23 deletions

View File

@ -10,9 +10,12 @@
*/ */
#include <zephyr/kernel.h> #include <zephyr/kernel.h>
#include <zephyr/logging/log.h>
#include "converters.h" #include "converters.h"
#include "pin_io.h" #include "pin_io.h"
LOG_MODULE_REGISTER(access);
static inline uint32_t static inline uint32_t
sign_extend(uint32_t in, unsigned len) sign_extend(uint32_t in, unsigned len)
{ {
@ -325,30 +328,39 @@ waveform_disarm(int slot)
void void
access_release_thread(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 (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++) { for (int i = 0; i < DAC_MAX; 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 < ADC_NUM; i++) { for (int i = 0; i < ADC_MAX; i++) {
adc_locked[i] = 0; 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;
}
} }
} }

View File

@ -27,10 +27,5 @@ int waveform_disarm(int slot);
*/ */
void access_release_thread(void); 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. */ /* Called once on initializion. */
int access_init(void); int access_init(void);