this is more a general question about threads I guess.
I finished my LCD driver code and can now write a number on the display from my main() program... (
I am using the code from the CHIBIOS example, where the temp sensor and PC1 are constantly read out and PWM the LEDs.
My next step was to display the Temperature (the converted ADC value) on the display from inside the AD conversion callback function ( adccb(ADCDriver *adcp, adcsample_t *buffer, size_t n) ).
(Since the LCD output is slow, I am only doing that once).
The problem is that nothing is written to the LCD and the code never returns from WriteLCD(value, row, col). (Which again works perfect when called from main()).
I tracked down what happens and it seems to come down to chThdSleepMilliseconds(n) which is used to delay the signals to the LCD.
It meanders through:
chThdSleepMilliseconds(50); -> chThdSleep(systime_t time) -> chThdSleepS(time); -> msg_t chSchGoSleepTimeoutS(tstate_t newstate, systime_t time) -> chVTSetI(&vt, time, wakeup, currp);
That's where it stops.
The callback function "wakeup" is never invoked ( Breakpoint never hit).
Now - I do not know if I change certain conditions while single stepping through the code.
The whole ADC conversion is invoked in main() through
Code: Select all
/*
* Initializes the ADC driver 1 and enable the thermal sensor.
* The pin PC1 on the port GPIOC is programmed as analog input.
*/
adcStart(&ADCD1, NULL);
adcSTM32EnableTSVREFE();
palSetPadMode(GPIOC, 1, PAL_MODE_INPUT_ANALOG);
/*
* Initializes the PWM driver 4, routes the TIM4 outputs to the board LEDs.
*/
pwmStart(&PWMD4, &pwmcfg);
palSetPadMode(GPIOD, GPIOD_LED4, PAL_MODE_ALTERNATE(2)); /* Green. */
palSetPadMode(GPIOD, GPIOD_LED6, PAL_MODE_ALTERNATE(2)); /* Blue. */
Is this considered a different thread than the conversion call back function? (probably).
Why would the chThdSleepMilliseconds not work there? What is the solution/workaround?
----
I actually did another quick test: It IS the chThdSleepMilliseconds function!
Code: Select all
void adccb(ADCDriver *adcp, adcsample_t *buffer, size_t n) {
...
...
/* Changes the channels pulse width, the change will be effective
starting from the next cycle.*/
pwmEnableChannelI(&PWMD4, 0, PWM_FRACTION_TO_WIDTH(&PWMD4, 4096, avg_ch1));
pwmEnableChannelI(&PWMD4, 3, PWM_FRACTION_TO_WIDTH(&PWMD4, 4096, avg_ch2));
chThdSleepMilliseconds(50); [color=#FF0000] <- never returns[/color]
/*LCD code: */
...
...
}
As always THANKS a LOT for any clues
chThdSleepMilliseconds(50);
chThdSleep(systime_t time)
chThdSleepS(time);
msg_t chSchGoSleepTimeoutS(tstate_t newstate, systime_t time)
chVTSetI(&vt, time, wakeup, currp);