Semaphore problem?


hi, i have a simple code snippet as this

s32 sem;
bool cmdRspHandler(adl_atResponse_t *rsp) {
	if (strstr(rsp->StrData, "OK") || strstr(rsp->StrData, "ERROR")) {
	return FALSE;

void action ()
    sem = adl_semSubscribe(1);
    int i;
    	TRACE((1,"consume %d",i));

as it, i want execute 10 times of command “at+csq” with adl_atCmdCreate, and it must wait for each command finish (response handler receive “OK” or “ERROR” string) before continue next one. So i use a semaphore (act as a event object), but i don’t know why it’ seem be frozen at line adl_atCmdCreate(…), could anyone show me where i’m wrong?
thanks very much.



I haven’t run your code, but it looks like you have a deadlock occurring.

Don’t forget that the call to adl_atCmdCreate() is non-blocking - that is, it will return immediately but the AT command will be executed sometime later - so your semaphores will be consumed (in the for() loop) before they are produced (in the AT event handler).

Also, reading the API for adl_semConsume() indicates that the calling task will be suspended when the number of remaining semaphores becomes less than zero.

ciao, Dave


oh, yes, that’s my purpose, so next time it’ll need to wait for previous command is finish ( the handler produced semaphore when i reach “OK” or “ERROR” message )
i searched and found this viewtopic.php?f=11&t=1692, is commandHandler a high level interruption?, maybe it is problem :frowning:
thanks you.



If that’s the case, why don’t you just start the next AT command from the AT command event handler? That way you will be sure that the first command has finished.

ciao, Dave