Ext driver example
Moderators: RoccoMarco, lbednarz, tfAteba
- Giovanni
- Site Admin
- Posts: 14895
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 997 times
Re: Ext driver example
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
Re: Ext driver example
Not sure how to just "start" a thread?
When I have:
How am I supposed to start the Thread before it goes to sleep? With chThdCreateStatic()?
Thanks for your help.
~ Tectu
When I have:
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()
}How am I supposed to start the Thread before it goes to sleep? With chThdCreateStatic()?
Thanks for your help.
~ Tectu
- Giovanni
- Site Admin
- Posts: 14895
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 997 times
Re: Ext driver example
Take care of priorities or you will be signaling a null pointer. Stepping through the code could confirm that.
Giovanni
Giovanni
- Giovanni
- Site Admin
- Posts: 14895
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 997 times
Re: Ext driver example
Tectu wrote:How am I supposed to start the Thread before it goes to sleep? With chThdCreateStatic()?
Yes, or any other variant of chThdCreate(), you can't signal a thread that is not yet active.
Giovanni
Re: Ext driver example
Yes, starting the thread before sending signals to it makes sense 
I don't assume that you help me here anymore, because you already helped me alot and this really is some debugging related part.
But thank you if you decide to help me anyways
setting breakpoint at line chEvtSignalFlagsi():
I really don't have a clue what's wrong here. I also don't understand what you mean with "care of priorities"
~ Tectu
I don't assume that you help me here anymore, because you already helped me alot and this really is some debugging related part.
But thank you if you decide to help me anyways
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);
...
setting breakpoint at line chEvtSignalFlagsi():
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)I really don't have a clue what's wrong here. I also don't understand what you mean with "care of priorities"
~ Tectu
- Giovanni
- Site Admin
- Posts: 14895
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 997 times
Re: Ext driver example
May be "tp" is null at that point but that log doesn't help much, you should invest some time into building an eclipse environment for debugging.
Re: Ext driver example
If you observe unhandled exception that first of all check that
1) you do not forget to initialize all structures with pointers
2) you handle pointers like a pointers with proper type
1) you do not forget to initialize all structures with pointers
2) you handle pointers like a pointers with proper type
Re: Ext driver example
barthess wrote:If you observe unhandled exception that first of all check that
1) you do not forget to initialize all structures with pointers
Not sure what you mean with that?
Whenever I made some structure, for example a configuration structure for the SPI driver, I did:
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);So the structure is not initialized over a pointer?
~ Tectu-
Re: Ext driver example
No. SPIConfig looks initialized correctly. Did you forget to init event source?
Re: Ext driver example
barthess wrote:No. SPIConfig looks initialized correctly. Did you forget to init event source?
I guess not?
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);
};or do you mean something else?