How to properly reference threads in NIL?

Discussions and support about ChibiOS/NIL, the almost nil RTOS.
ulikoehler
Posts: 71
Joined: Tue Mar 17, 2015 2:32 am
Location: Munich, Germany
Been thanked: 3 times

How to properly reference threads in NIL?

Postby ulikoehler » Sun Aug 02, 2015 3:56 am

Hi,
I'm currently porting some old ChibiOS 2.x code to 3.x with NIL to to uC flash size restrictions.

In nil.c, the standard event functions, most notably chEvtSignalI are defined for the NIL kernel.
However, there is no chThdCreateStatic() that returns a thread_t* in NIL as threads are handled via the thread table.

Therefore, my question is how to properly use chEventSignalI in NIL. My current code is:

Code: Select all

void uartTXend2Callback(UARTDriver *uartp) {
  (void)uartp;
  palClearPad(GPIOA, GPIOA_RS485_DE);
  osalSysLockFromISR();
  chEvtSignalI(&nil.threads[0], EVENT_UART_TX_FINISHED);
  chSchRescheduleS(); //Maybe unneccessary
  osalSysUnlockFromISR();
}


Before using uartSend in the thread code, I use

Code: Select all

chEvtWaitAnyTimeout(EVENT_UART_TX_FINISHED, TIME_INFINITE)


Using this method, the thread never wakes up. I am not sure if this is related to some other part of my source code, but directly using the thread table (I'm using only one thread besides main) via &nil.threads[0] seems somewhat strange to me.

Best regards, Uli

User avatar
Giovanni
Site Admin
Posts: 14444
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 1074 times
Been thanked: 921 times
Contact:

Re: How to properly reference threads in NIL?

Postby Giovanni » Sun Aug 02, 2015 7:20 am

Hi,

Accessing the table is fine, probably having a macro for that would be useful.

Note that you MUST NOT call S-class functions from ISRs, so that call is not just unnecessary, it is forbidden.

Giovanni

mikenick42
Posts: 28
Joined: Tue Mar 10, 2015 4:49 pm
Been thanked: 1 time

Re: How to properly reference threads in NIL?

Postby mikenick42 » Tue Aug 11, 2015 1:40 am

I don't know if it counts as the right way to do it, but I have it working with a global thread pointer and then assigning the result of chThdGetSelfX() to that in the listener.
Last edited by mikenick42 on Tue Aug 11, 2015 3:32 am, edited 1 time in total.

ulikoehler
Posts: 71
Joined: Tue Mar 17, 2015 2:32 am
Location: Munich, Germany
Been thanked: 3 times

Re: How to properly reference threads in NIL?

Postby ulikoehler » Tue Aug 11, 2015 1:46 am

@mikenick42: Nice idea ;-)

Besides being a bit ugly, &nil.threads[0] works well. Maybe we should define a function for that (code has not been checked, might contain errors)?

Code: Select all

static inline thread_t* nilGetThreadByIndex(int n) {
    osalDbgCheck(n < NIL_CFG_NUM_THREADS && n > 0);
    return &nil.threads[n];
}


Return to “ChibiOS/NIL”

Who is online

Users browsing this forum: No registered users and 8 guests