adl_ctxSuspend not suspending?

First of all, thanks to all who have answered my previous questions.

I have an app with a main task & a download task. The download task does an adl_adSubscribe and gets a -22. So I initiate a recompact. But I want to wait until the recompact finishes before continuing. My most recent attempt is to set a global variable for the main task, then have the download task adl_ctxSuspend itself. The main program’s timer handler sees the change in the global, sets up an event handler for the recompact, then starts the recompact. The event handler does the adl_ctxResume on receiving ADL_AD_EVENT_RECOMPACT_DONE.
However, the adl_ctxSuspend never suspends the task. Nor does it return an error. Seems like adl_ctxSuspend doesn’t work on its own task.

How can one wait in one task for the completion of an asynchronous operation in another task?
Thx.

For example, use a sempahore or Event Service to synchronize tasks - depending on what suits you best.

Why do you need to suspend any task at all?

Why not just have the A&D Storage Event Handler set the global on the ADL_AD_EVENT_RECOMPACT_DONE event itself?

Well, I was trying to accomplish a ‘yield’ which this OS doesn’t seem to have. I wanted the main task to do the recompact (and its other duties) and when done, have the second task continue on with the rest of the download (make an FTP client, etc.). Seemed like suspend/resume was the simplest. I could have the event handler kick off the rest of the download, but then my code would be kinda ‘spaghetti-ish’.

(I’m afraid that my notion of tasks/threads & SiWi’s (or Wavecom’s) idea of tasks aren’t the same. pthreads I can manage. IMHO, these tasks seem less useful.)

I switched over to using events. The eventWait in the download task failed with ADL_RET_ERR_BAD_STATE, that is, it was called in task 0’s context. I apparently missed the fine print that says that, even if a command is subscribed in another task, it is handled in task 0’s context. I was initiating the download with a command subscribed in the download task, yet all the event processing & scheduling was happening in the main task. Sob.

Open-AT is Event-Driven - so, in most cases, it doesn’t need to “yield”.

This lends itself to a State Machine approach - trying to write “linear” code is not appropriate.

See: Good paper on Event-Driven Programming

Indeed. Or, at least, SiWi’s explanation of them leaves us none the wiser as to how to use them effectively. :unamused:

Hello,

I have two littles doubts about the functions adl_ctxSuspend() and adl_ctxResume() :question: :question: :question:

The first one is if I can “suspend” and resume a handler. For example, if I subscibe to the UART bus, can i do adl_ctxSuspend(HandlerUART) and adl_ctxResume(HandlerUART) :question:

The other question is if pending my UART is suspended, if I try to write or read from my UART, I will write and read or I will do anything :question:

Thank you

Why would you want to suspend a handler :question: :confused:

catb.org/~esr/faqs/smart-questions.html#goal

Hello,

Thanks for your answer :slight_smile:

I want to suspend the handler because i’m doing a SPI communication between my WMP and a PIC. The SPI communication has this requeriment:

:arrow_right: If the WMP wants transmit and isn’t currently receiving data, it will write in SPI bus (for this reason i want to suspend the interruption that does that my WMP writes in the SPI bus when my PIC is sending info by the SPI bus)

I want to send a message from the WMP to the PIC and afther the PIC has to send me a answer. My problem is that i send the message from WMP, the PIC receive it correctly, but when WMP reads the info from the SPI bus, I start to made interruptions that i don’t want and i can’t read from SPI bus. FOr this reason disenable the interrupcion from PIC and I want disenable the SPI task. It’s right my presumption :question:

Thank you