Re: Ext driver example
Posted: Mon Jun 04, 2012 7:08 pm
Are you sure the thread already started before you start sending events to it?
This is more matter of debugging.
Giovanni
This is more matter of debugging.
Giovanni
Code: Select all
static Thread *tp;
void mythread(void *p) {
tp = chThdSelf();
while (TRUE) {
chEvtWaitAny((eventmask_t)1);
}
}
static void touchIRQ(EXTDriver *extp, expchannel_t channel) {
(void)extp;
(void)channel;
chSysLockFromIsr();
chEvtSignalFlagI(tp, (eventmask_t)1);
chSysUnlockFromIsr()
}Tectu wrote:How am I supposed to start the Thread before it goes to sleep? With chThdCreateStatic()?
Code: Select all
static WORKING_AREA(waThread3, 128);
static msg_t Thread3(void *arg) {
chRegSetThreadName("touchpad");
(void)arg;
while(TRUE) {
palTogglePad(GPIOD, GPIOD_LED2);
chEvtWaitAny((eventmask_t)1);
}
}
static void touchIRQ(EXTDriver *extp, expchannel_t channel) {
(void)extp;
(void)channel;
chSysLockFromIsr();
chEvtSignalFlagsI(Thread3, (eventmask_t)1);
chSysUnlockFromIsr()
}
int main() {
...
chThdCreateStatic(waThread3, sizeof(waThread3), NORMALPRIO, Thread3, NULL);
...
Code: Select all
337 chEvtSignalFlagsI(Thread3, (eventmask_t)1);
(gdb) step
chEvtSignalFlagsI (tp=0x8010321, mask=1)
at /home/tectu/projects/resources/chibios/os/kernel/src/chevents.c:191
191 tp->p_epending |= mask;
(gdb) step
193 if (((tp->p_state == THD_STATE_WTOREVT) &&
(gdb) step
191 tp->p_epending |= mask;
(gdb) step
193 if (((tp->p_state == THD_STATE_WTOREVT) &&
(gdb) step
191 tp->p_epending |= mask;
(gdb) step
193 if (((tp->p_state == THD_STATE_WTOREVT) &&
(gdb) step
_unhandled_exception ()
at /home/tectu/projects/resources/chibios/os/ports/GCC/ARMCMx/STM32F1xx/vectors.c:194
194 void _unhandled_exception(void) {
(gdb)barthess wrote:If you observe unhandled exception that first of all check that
1) you do not forget to initialize all structures with pointers
Code: Select all
static const SPIConfig spicfg = {
NULL,
GPIOC,
TP_CS,
SPI_CR1_SPE | SPI_CR1_BR_2 | SPI_CR1_BR_1 | SPI_CR1_BR_0,
};
...
spiStart(&SPID1, &spicfg);barthess wrote:No. SPIConfig looks initialized correctly. Did you forget to init event source?
Code: Select all
static const EXTConfig extcfg = {
{
{EXT_CH_MODE_DISABLED, NULL},
{EXT_CH_MODE_DISABLED, NULL},
{EXT_CH_MODE_DISABLED, NULL},
{EXT_CH_MODE_DISABLED, NULL},
{EXT_CH_MODE_FALLING_EDGE | EXT_CH_MODE_AUTOSTART | EXT_MODE_GPIOC, touchIRQ},
{EXT_CH_MODE_DISABLED, NULL},
{EXT_CH_MODE_DISABLED, NULL},
{EXT_CH_MODE_DISABLED, NULL},
{EXT_CH_MODE_FALLING_EDGE | EXT_CH_MODE_AUTOSTART | EXT_MODE_GPIOA, buttonIRQ},
{EXT_CH_MODE_DISABLED, NULL},
{EXT_CH_MODE_DISABLED, NULL},
{EXT_CH_MODE_DISABLED, NULL},
{EXT_CH_MODE_DISABLED, NULL},
{EXT_CH_MODE_DISABLED, NULL},
{EXT_CH_MODE_DISABLED, NULL},
{EXT_CH_MODE_DISABLED, NULL}
}
...
extStart(&EXTD1, &extcfg);
};