Page 2 of 3

Re: Ext driver example

Posted: Mon Jun 04, 2012 7:08 pm
by Giovanni
Are you sure the thread already started before you start sending events to it?

This is more matter of debugging.

Giovanni

Re: Ext driver example

Posted: Mon Jun 04, 2012 9:00 pm
by Tectu
Not sure how to just "start" a thread?

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

Re: Ext driver example

Posted: Mon Jun 04, 2012 9:06 pm
by Giovanni
Take care of priorities or you will be signaling a null pointer. Stepping through the code could confirm that.

Giovanni

Re: Ext driver example

Posted: Mon Jun 04, 2012 9:12 pm
by Giovanni
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

Posted: Mon Jun 04, 2012 9:41 pm
by Tectu
Yes, starting the thread before sending signals to it makes sense :D

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

Re: Ext driver example

Posted: Tue Jun 05, 2012 7:16 am
by Giovanni
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

Posted: Tue Jun 05, 2012 7:21 am
by barthess
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

Re: Ext driver example

Posted: Tue Jun 05, 2012 2:35 pm
by Tectu
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

Posted: Tue Jun 05, 2012 7:11 pm
by barthess
No. SPIConfig looks initialized correctly. Did you forget to init event source?

Re: Ext driver example

Posted: Tue Jun 05, 2012 8:04 pm
by Tectu
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?