Ext driver example

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: RoccoMarco, lbednarz, tfAteba

User avatar
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

Post by Giovanni »

Are you sure the thread already started before you start sending events to it?

This is more matter of debugging.

Giovanni
User avatar
Tectu
Posts: 1225
Joined: Thu May 10, 2012 9:50 am

Re: Ext driver example

Post 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
User avatar
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

Post by Giovanni »

Take care of priorities or you will be signaling a null pointer. Stepping through the code could confirm that.

Giovanni
User avatar
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

Post 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
User avatar
Tectu
Posts: 1225
Joined: Thu May 10, 2012 9:50 am

Re: Ext driver example

Post 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
User avatar
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

Post 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.
User avatar
barthess
Posts: 861
Joined: Wed Dec 08, 2010 7:55 pm
Been thanked: 7 times

Re: Ext driver example

Post 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
User avatar
Tectu
Posts: 1225
Joined: Thu May 10, 2012 9:50 am

Re: Ext driver example

Post 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-
User avatar
barthess
Posts: 861
Joined: Wed Dec 08, 2010 7:55 pm
Been thanked: 7 times

Re: Ext driver example

Post by barthess »

No. SPIConfig looks initialized correctly. Did you forget to init event source?
User avatar
Tectu
Posts: 1225
Joined: Thu May 10, 2012 9:50 am

Re: Ext driver example

Post 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?
Post Reply