Can't receive message in other task then task 0

Hi there,

I’ve got a problem with receiving a message. I have running three tasks. 0:Main, 1:Communicator, 2:Radio.
The problem is that when I send a message from task 2 to task 1, I can’t receive it. When I change the id in the send command to 0, I can receive the message in task 0.
This how my send code looks like (task 2):

adl_msgSend(2, 1, 0, NULL));

This how my receive code looks like (task 1):

adl_msgFilter_t packetFilter = { 0, 0, ADL_MSG_ID_COMP_EQUAL, ADL_CTX_ALL };

Could someone point me in the right direction?

Thanks!

void packetMessageCallback(u32 MsgIdentifier,
                           adl_ctxID_e Source,
                           u32 Length,
                           void * Data) {
  TRACE (( 3, "Message received" ));
}

adl_msgSubscribe(&packetFilter, (adl_msgHandler_f)packetMessageCallback);

Hey.

Have a look at the prototype for adl_msgSend

s32 adl_msgSend (adl_ctxID_e DestinationTask,
u32 MessageIdentifier,
u32 Length,
void * Data );

The DestinationTask is the task identifier for your task 2, if you are sending from task 1 to task 2. Your message send function should look like this:

However, if you look in your “generated.h” file, you will find a list of #defines for your task identifiers, and this is a much easier way of working out which task you are sending the message to.

Hope this helps!

Hi,

Thanks for your reply. Although I can’t get it working :frowning:
What I would expect is that I have to fill in the task id if the destination task. So, I want to send a message from task 1 to task 2, the destination is task 2. I tried sending the message with

adl_msgSend(1, 1, 0, NULL)

and

adl_msgSend(2, 1, 0, NULL)

but the result is the same, message succesfully send, no message received.

The strange thing is that I can send messages to task 0, but to another task from any task won’t be received at all.

I have seen the defines in generated.h, I have them in use but posting them here wouldn’t make it more readable :wink:

Hey

My bad, should have been if you are sending from Task 2 to Task 1, so you are correct that the Task ID should be the destination task. Try changing your message filter in task 1 to something different such as:

adl_msgFilter_t packetFilter = {         0xFFFF0000,
        0x00010000,
        ADL_MSG_ID_COMP_EQUAL,
        ADL_CTX_ALL };

and your message subscription to:

adl_msgSubscribe ( ( adl_msgFilter_t * ) &packetFilter , packetMessageCallback);

(Shouldn’t make a difference, but try anyway - this works for me!)

then send the following message from Task 2:

adl_msgSend(0x01, 0x00010000 | 0x00000001, 0, NULL);

I use this code, and It works. Hopefully it will work for you!

Hi,

thanks for your reply again. There must be a difference between your and my code because it is still not working. Could it be something in the generated.c/h settings? This is how the array with tasks looks like in my code:

const adl_InitTasks_t adl_InitTasks [] =
{
  { main_task,  4096, "MainApplication", 3 },
  { packetHandlerMain_task,  4096, "PacketHandler", 2 },
  { packetRadioMain_task,  4096, "PacketRadio", 1 },
  { 0, 0, 0, 0 }
};

The message sender is PacketRadio, the message receiver is PacketHandler.

Have you got the send and receive functions in different code files?

Hi

I normally write my tasks in separate C files. The adl_msgSubscribe and msgFilter declarations are normally in my task function - in your case, it would look like this (in the main task, or one of the other tasks):

void MainApplication(void)
{
    const adl_msgFilter_t mainMsgFilter =
    {
        0xFFFF0000,
        0x00010000,
        ADL_MSG_ID_COMP_EQUAL,
        ADL_CTX_ALL
    };

 adl_msgSubscribe ( ( adl_msgFilter_t * ) &mainMsgFilter, MainTaskMsgHandler );		// Subscribe to Main Messages
}

void MainTaskMsgHandler ( u32 MsgIdentifier, adl_ctxID_e Source, u32 Length, void * Data )
{
TRACE((1, "Message Received"));
}

The function to send a message from another task would then be:

adl_msgSend(TASK_ID_MainApplication , 0x00010000| 0x00000001, 0, NULL);

Hey,

I see a difference between your code an my code. Your message ‘receiver’ is the main task. That’s no problem in my situation. Receiving a message in a non main task is the problem. Could you please give that a try? So create beside the main two other tasks. Let one task send a message to the other task and leave the main empty.

Could you also post your adl_InitTasks array from the generated.c?

Thanks a lot!

I have found the whole Open-AT multitasking very confusing and poorly explained.
There seem to be a lot of restrictions & limitations that are not (well) explained.

IIRC, I think I found that a Task can’t receive messages if it’s suspended?

Task-0 can’t be suspended - so it can always accept messages.

Does this help you?

That sounds like a good explanation. That would also explain why there isn’t an example with two or more tasks…

A bit offtopic, but important:
I found another thing I couldn’t explain. When I set up a GPRS connection(with WIP) from the main everything goes well, but when I create a second task to do the job, wip_bearerOpen returns the undocumented error -28

Hey

Here is a working project based on your code. Every 5 seconds, the packetRadio task sends a message to the packetHandler task, and every 10 seconds the packetHandler task sends a message to the packetRadio Task.

Have tested this on a WMP100,
-“Developer Studio”,“1.2.0.201012171243-R6026”
-“Open AT Embedded Software Suite package”,“2.34.0.201009161320”
-“Open AT OS Package”,“6.34.0.201007281407”
-“Firmware Package”,“7.44.0.201008311212”

Hope it helps!
Test05-Messages.zip (951 KB)

If you look in the WIP user guide, hidden away somewhere it says: You MUST run the bearer in the main task (Highest priority). It does not work if the bearer is opened in another task. All other WIP stuff like TCP clients and FTP clients etc can be run on lower priority tasks, but NOT the bearer.

I found what’s going wrong in my code. I had en endless while loop which was waiting for an event (adl_eventWait).
In the handler for receiving a message I triggered the event. Now I think the message wasn’t received because the task was suspended. I removed the eventWait and let the task ‘end’ and now I’m receiving the messages succesfully.

I think my idea isn’t possible on this way, so I have to do the trick on another way.

thanks for the support!

IMO, it was very unhelpful of Wavecom to overload the meaning of “event” like this.

When you wait for an “Event” (in the specific sense of the ADL Event Service) like this, the task is suspended and cannot handle “events” in the wider ADL sense - such as timer expiry, message arrival, etc.

Well, that’s the way it seems to me, at least - as I said earlier, I don’t find it clearly explained at all.

I think that’s correct.

No - that does not let the task end at all!
The task is now waiting for “events” in the “normal” ADL sense - as it all worked before multitasking was introduced.

error -28 is WIP_BERR_BAD_STATE

Once again, it would be so much more helpful if SiWi would supply a specific, meaningful, clearly-documented error code! :unamused:

This is true.

Now I’m working with the SiWi modules, I see that the documentation is very poor. I bought the Open AT Tutorial but I think I can learn more by browsing the forum then reading the book :wink:

I noticed that your using the ARM_ELF_GCC compiler, I’m using the ARM_EABI_GCC compiler. As I understood the ELF isn’t in use anymore and the EABI is the new one. Is there any reason to keep compiling with the ELF?