ADC, threading & mutexes?
Posted: Mon Oct 29, 2012 3:29 am
I have started with stm32f407_discovery demo code which works with ADC conversion callback. I am trying to save ADC state into a global data structure, so I have started to use mutexes. Thing is my code started to hang up after some random period of time, I have isolated it to locking/unlocking within ADC callback:
void adccb(ADCDriver *adcp, adcsample_t *buffer, size_t n) {
....
chSysLockFromIsr();
chMtxLock(&osc_mtx);
int i ;
for (i=0;i<100;i++) {
}
chMtxUnlock();
chSysUnlockFromIsr();
and my main thread does
while(1) {
someUIcode();
chMtxLock(&osc_mtx);
for (i=0;i<100;i++) {
}
chMtxUnlock();
}
I have tried both with and without 'chSysLockFromIsr/chSysUnlockFromIsr'.
So, what thread executed ADC callbacks? Is is allowed to use mutexes from within ADC callback? If it is not, how can I protect my data?
void adccb(ADCDriver *adcp, adcsample_t *buffer, size_t n) {
....
chSysLockFromIsr();
chMtxLock(&osc_mtx);
int i ;
for (i=0;i<100;i++) {
}
chMtxUnlock();
chSysUnlockFromIsr();
and my main thread does
while(1) {
someUIcode();
chMtxLock(&osc_mtx);
for (i=0;i<100;i++) {
}
chMtxUnlock();
}
I have tried both with and without 'chSysLockFromIsr/chSysUnlockFromIsr'.
So, what thread executed ADC callbacks? Is is allowed to use mutexes from within ADC callback? If it is not, how can I protect my data?