ChibiOS public support forum for all topics not covered by a specific support forum.
Moderators: RoccoMarco , lbednarz , tfAteba
Tabulous
Posts: 518 Joined: Fri May 03, 2013 12:02 pm
Has thanked: 7 times
Been thanked: 18 times
Post
by Tabulous » Sat Nov 15, 2014 10:11 am
how can one pass a msg back to the main thread.
i.e. how do i get the pointer to main thread so i can post this to the thread doing the work and then wait for the response ?
Code: Select all
int main(void) { dongmsg.key = &key; dongmsg.tp = *******calling thread pointer********; dongmsg.id = DONG_KEY_REQUEST; dongmsg.imei = md->manu.imei; chMBPost( mbox, ( msg_t )&dongmsg, TIME_INFINITE ); p = chMsgWait(); if( p != NULL ) { } }
Giovanni
Site Admin
Posts: 14895 Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times
Post
by Giovanni » Sat Nov 15, 2014 11:45 am
Hi,
You are mixing mailboxes and synchronous messages.
Code: Select all
static THD_FUNCTION(ServerThread, arg) { while (true) { /* Waiting for a queued message then retrieving it.*/ thread_t *tp = chMsgWait(); msg_t msg = chMsgGet(tp); /* Processing the message.*/ ...; /* Sending back an acknowledge.*/ chMsgRelease(tp, MSG_OK); } }You send messages to the server using chMsgSend(), it returns the answer, MSG_OK in the example.
Giovanni
Tabulous
Posts: 518 Joined: Fri May 03, 2013 12:02 pm
Has thanked: 7 times
Been thanked: 18 times
Post
by Tabulous » Sat Nov 15, 2014 3:29 pm
forget about my code it is misleading, all i want is how do i get a pointer to the main thread structure ? normally when you create a thread you can assign it like this pThread = chThdCreateStatic( ETICKETWA, sizeof(ETICKETWA), NORMALPRIO, ThreadEticket, NULL ); but what about int main(void) ? or does this not have a thread structure ?
Giovanni
Site Admin
Posts: 14895 Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times
Post
by Giovanni » Sat Nov 15, 2014 4:00 pm
You can get the pointer to the current thread from the main (chThdSelf() in 2.6, chThdGetSelfX() in 3.0) and then store it somewhere for other threads to use. Giovanni