AnsweredAssumed Answered

MCAPI and multi-threading

Question asked by habanero on Feb 13, 2017
Latest reply on Dec 1, 2017 by gene.goff

Hi,

I'm working on a SC584-EZLITE evaluation board and I try to achieve the following (on the ARM and SHARC cores):

Have two uCOS III threads, one of them (lets call it RX) waiting for mcapi messages from other processors, the other (lets call it TX) waiting for some internally generated event and sending mcapi messages to other cores.

First thing I tried (pseudo code):

RX:

while(1) {

mcapi_msg_recv()

process_msg()

}

TX:

while(1) {

wait_for_event()

generate_message()

mcapi_msg_send()

}

I found that I get an MCAPI_ERR_WAIT_PENDING error from mcapi_msg_send so I figure I cannot call this while the other thread is waiting. Next thing I tried is:

RX:

while(1) {

request_id = mcapi_msg_recv_i()

mcapi_wait(request_id)

if(!request_was_cancelled) {

process_msg()

}

}

TX:

while(1) {

wait_for_event()

if(request_id) {

mcapi_cancel(request_id)

}

generate_msg()

mcapi_msg_send()

}

The idea is to cancel the running receive-request for the time the send-request is running.

I ran into the following issues:

1. It seems that

mcapi_cancel(MCAPI_IN mcapi_request_t* request, MCAPI_OUT mcapi_status_t* mcapi_status)

does not always set the mcapi_status. I have to initialize mcapi_status to MCAPI_SUCCESS otherwise I get random (not necessarily valid) error codes. I think this is a bug.

2. mcapi_msg_recv_i() gives MCAPI_ERR_REQUEST_CANCELLED error when called after a the TX thread called mcapi_cancel(). From stepping through the mcapi source code I think this is because the state of the micro-request is not correctly reset. If I reset it through the debugger (after _adi_mcapi_allocRequest()) my application seems to work as expected. I think there is a bug here too.

 

So the issues I run into make me wonder if this is the right (i.e. tried and tested) way to do this or if there is a better way to do it. What do you think?

Outcomes