Hi all,
I have some sensors who are read by ChibiOS and every sensor is Posting messages. This every 24 seconds. All seems to work well, but after some hours then the mailbox is going into "idle". So the STM is still working (heartbeat led), but the mailboxes seem to go into idle.
How could I best debug this? To find out what is going on?
I am using the GNU-ARM Toolchain (GCC).
Thanks
Debugging Mailboxes ChibiOS
- Giovanni
- Site Admin
- Posts: 14457
- Joined: Wed May 27, 2009 8:48 am
- Location: Salerno, Italy
- Has thanked: 1076 times
- Been thanked: 922 times
- Contact:
Re: Debugging Mailboxes ChibiOS
Hi,
What version are you using? mailboxes have been rewritten recently?
Also, try to describe what "idle" is, is the mailbox that stops working or the thread that stops fetching from the mailbox? do you have debug options enabled?
Giovanni
What version are you using? mailboxes have been rewritten recently?
Also, try to describe what "idle" is, is the mailbox that stops working or the thread that stops fetching from the mailbox? do you have debug options enabled?
Giovanni
Re: Debugging Mailboxes ChibiOS
I am using: ChibiOS_16.1.6 --> transformation to ChibiOS_17.6.0 is planned, but has some impact.
The STM, in gdb (GNU-ARM Tool STM on Linux), is is telling me that the STM is in idle state (esp8266.c thread)
The code I am using is (esp8266.c):
Code in Pastebin
The STM, in gdb (GNU-ARM Tool STM on Linux), is is telling me that the STM is in idle state (esp8266.c thread)
The code I am using is (esp8266.c):
Code in Pastebin
Re: Debugging Mailboxes ChibiOS
I have got ChibiOS Studio working with gdb and openocd. If i "suspend" it will take me in Tread#1
_idle_thread.lto_priv.78() at chsys.c:65 0x8001eb0 --> static void _idle_thread(void *p) in chsys.65
I do not have and variable ch.dbg.panic_msg with a value SV#X
I will keep on searching.
_idle_thread.lto_priv.78() at chsys.c:65 0x8001eb0 --> static void _idle_thread(void *p) in chsys.65
I do not have and variable ch.dbg.panic_msg with a value SV#X
I will keep on searching.
- Giovanni
- Site Admin
- Posts: 14457
- Joined: Wed May 27, 2009 8:48 am
- Location: Salerno, Italy
- Has thanked: 1076 times
- Been thanked: 922 times
- Contact:
Re: Debugging Mailboxes ChibiOS
Hi,
If it is in the idle thread then the application is running. Probably your problem is that some thread is stuck posting/fetching the mailbox because the other side is not posting/fetching so the queue stays full or empty.
Giovanni
If it is in the idle thread then the application is running. Probably your problem is that some thread is stuck posting/fetching the mailbox because the other side is not posting/fetching so the queue stays full or empty.
Giovanni
Re: Debugging Mailboxes ChibiOS
Oke tried everything I can think of. When I implement 2 Threads which are posting and I use no timers or delays. It all seems wel.... seems. But when I put some delays in (because every Thread is representing a sensor) all is going fault. The chMBFetch seems to be the problem.
I expect that the chMBFetch Thread is waiting (even when the queue is empty) for a message to be posted. But it seems like it is going into idle...
This cannot be this difficult..... or are mailboxes not for this purpose? So it seems to work, but I want to put some delays into the Threads ... how can I achieve this?
code Thread1 posting:
Thread 2:
And Fetch Thread:
I expect that the chMBFetch Thread is waiting (even when the queue is empty) for a message to be posted. But it seems like it is going into idle...
This cannot be this difficult..... or are mailboxes not for this purpose? So it seems to work, but I want to put some delays into the Threads ... how can I achieve this?
code Thread1 posting:
Code: Select all
/* The thread continuous which is reading the sensor values and is posting a message in the mailbox */
static THD_WORKING_AREA(waPOSTMESSAGETOMBTEMP, 512);
static THD_FUNCTION(POSTMESSAGETOMBTEMP, arg)
{
(void)arg;
static char charbuf;
chRegSetThreadName("GETMESSAGEFROMSENSORTEMP");
systime_t time = chVTGetSystemTimeX(); // T0
time += MS2ST(500);
while(true) {
msg_t msg, result;
//chprintf((BaseSequentialStream*)&SD6,"print('GMState Thread 2: %d')\r\n",esp_state);
//chThdSleepMilliseconds(100);
DSMessage dsmi = {};
dsmi.state = 26;
dsmi.url = "http://io.adafruit.com/api/v2/url/feeds/cabinet.temperature/data";
chMBPost(&msgs, (msg_t) &dsmi, MS2ST(10));
chThdYield();
//chThdSleepUntil(time);
}
}
Thread 2:
Code: Select all
/* The thread continuous which is reading the sensor values and is posting a message in the mailbox */
static THD_WORKING_AREA(waPOSTMESSAGETOMBHUM, 512);
static THD_FUNCTION(POSTMESSAGETOMBHUM, arg)
{
(void)arg;
static char charbuf;
chRegSetThreadName("GETMESSAGEFROMSENSORHUM");
systime_t time = chVTGetSystemTimeX(); // T0
time += MS2ST(200);;
while(true) {
msg_t msg, result;
//chprintf((BaseSequentialStream*)&SD6,"print('GMState Thread 3: %d')\r\n",esp_state);
//chThdSleepMilliseconds(100);
DSMessage dsm = {};
dsm.state = 62;
dsm.url = "http://io.adafruit.com/api/v2/url/feeds/cabinet.humidity/data";
chMBPost(&msgs, (msg_t) &dsm, MS2ST(10));
chThdYield();
//chThdSleepUntil(time);
}
}
And Fetch Thread:
Code: Select all
/* The thread continuous which is fetching a message */
static THD_WORKING_AREA(waGETMESSAGEFROMMB, 512);
static THD_FUNCTION(GETMESSAGEFROMMB, arg)
{
(void)arg;
chRegSetThreadName("GETMESSAGE");
systime_t time = chVTGetSystemTimeX(); // T0
msg_t current_message;
/* Waiting for a message.*/
chprintf((BaseSequentialStream*)&SD6,"print('GMState: %d')\r\n",esp_state);
chThdSleepMilliseconds(100);
//time += S2ST(5);
while(TRUE) {
msg_t msg, result;
//The ampersand & symbol should be read as "the address of..". The star *
//symbol should be read as "the contents of the address...".
//[A] result = chMBFetch(&msgs, (msg_t *)&msg,TIME_INFINITE);
//result = chMBFetch(&msgs, (msg_t *)&msg ,TIME_IMMEDIATE);
while(chMBFetch(&msgs, (msg_t *)&msg, MS2ST(1))!= MSG_OK);
//if(msg & 1)
chprintf((BaseSequentialStream*)&SD6,"print('Inside loop %d')\r\n",((DSMessage *)msg)->state);
chThdSleepMilliseconds(100);
chprintf((BaseSequentialStream*)&SD6,"print('Inside loop %s')\r\n",((DSMessage *)msg)->url);
chThdSleepMilliseconds(100);
chThdYield();
//chThdSleepUntil(time);
}
}
- Giovanni
- Site Admin
- Posts: 14457
- Joined: Wed May 27, 2009 8:48 am
- Location: Salerno, Italy
- Has thanked: 1076 times
- Been thanked: 922 times
- Contact:
Re: Debugging Mailboxes ChibiOS
Because your use timeouts your threads can use the CPU without releasing it because stuck in an infinite while, this can cause other threads to never execute leading to deadlock.
Giovanni
Giovanni
- Giovanni
- Site Admin
- Posts: 14457
- Joined: Wed May 27, 2009 8:48 am
- Location: Salerno, Italy
- Has thanked: 1076 times
- Been thanked: 922 times
- Contact:
Return to “Development and Feedback”
Who is online
Users browsing this forum: No registered users and 55 guests