Programmable Devices
CPLDs, FPGAs, SoC FPGAs, Configuration, and Transceivers
21325 Discussions

Mailboxes error in multicore system

Altera_Forum
Honored Contributor II
1,525 Views

Hi, 

I have a 2-CPU system based on the NEEK, with two mailboxes (one for each CPU). One CPU send a 4-bytes message to the other, which displays it. The problem is that after that, the send and get functions returns the "EWOULDBLOCK" error code(-11) instead of 0, meaning that there is no messages or that the mailbox is full... 

Thank you to post your ideas!! 

Here are the code for the two CPUs: 

 

--- Quote Start ---  

 

int main() 

alt_mailbox_dev* send_dev; 

alt_mailbox_dev* recv_dev; 

alt_u32 temp=0xabcd; //The message to send 

/* Open the two mailboxes between this processor and another */ 

recv_dev = altera_avalon_mailbox_open(MAILBOX_E1_NAME); 

send_dev = altera_avalon_mailbox_open(MAILBOX_O_NAME); 

 

while(1) 

altera_avalon_mailbox_post(send_dev,temp); 

alt_busy_sleep(1000000); 

 

return 0; 

 

--- Quote End ---  

 

--- Quote Start ---  

 

int main() 

int *err= malloc(sizeof(int)); 

alt_u32 temp=0x0; 

alt_mailbox_dev* recv_dev; 

alt_mailbox_dev* send_dev; 

/* Open the two mailboxes between this processor and another */ 

recv_dev = altera_avalon_mailbox_open(MAILBOX_O_NAME); 

send_dev = altera_avalon_mailbox_open(MAILBOX_E1_NAME); 

while(1) 

printf("dans le while...\n"); 

temp= altera_avalon_mailbox_get(recv_dev,err); 

printf("check msg:%d\n",*err); 

if(*err==0x0) 

printf(" %x\n",(int)temp); 

printf("fall asleep..."); 

alt_busy_sleep(1000000); 

printf("and wake up..."); 

 

 

return 0; 

 

--- Quote End ---  

And what I get in result is: 

 

--- Quote Start ---  

 

dans le while... 

check msg:0 

abcd 

fall asleep...and wake up...dans le while... 

check msg:-11 

fall asleep...and wake up...dans le while... 

check msg:-11 

fall asleep...and wake up...dans le while... 

check msg:-11 

--- Quote End ---  

 

 

I am not sure, but I think that the problem comes from the sending CPU which terminates all by itself (surely just after posting the message into the mailbox), although there is a while(1) in the code!  

I see this just after the launching of the multiprocessor collection configuration: 

 

--- Quote Start ---  

<terminated>CPUE Nios II HW configuration [Nios II Hardware]  

<terminated, exit value: 0>Nios II Download output (12/10/09 10:00)  

--- Quote End ---  

Is there any clue to avoid this CPU to terminate in the middle of the launching?
0 Kudos
4 Replies
Altera_Forum
Honored Contributor II
427 Views

There is no problem. The get function returns EWOULDBLOCK because there is no further message to read. It is the expected result, as you post only one message, and then wait for a long period of time. 

If you want the receiving CPU to wait until a new message is available, you should use the altera_avalon_mailbox_pend() function.
0 Kudos
Altera_Forum
Honored Contributor II
427 Views

Hi, 

Thanks for the quick reply. 

But I don't agree with your explanation, because each CPU are waiting 1 second (1000000 µs) before sending new message/checking new messages. So each second there must be a new message in the mailbox, and the other CPU should be able to read it, instead of getting: 

 

--- Quote Start ---  

fall asleep...and wake up...dans le while... 

check msg:-11 

--- Quote End ---  

 

Thank you for your help!
0 Kudos
Altera_Forum
Honored Contributor II
427 Views

Ok, I overlooked that. This will nevertheless give you an unpredictable behaviour, because there is no way of knowing wich CPU will wake up first. I guess the second one will wake up later because of the extra delays in the printf, but it can't be guaranteed. 

Can you make a LED flash in the code fr the first CPU? That way you'll know if it's stuck or not. 

Do the CPU share some RAM? In that case are you sure there is no collisions between their memory areas for text / rwdata / heap / stack?
0 Kudos
Altera_Forum
Honored Contributor II
427 Views

I think a solve the problem: In SOPC I changed the reset and exception vectors of the two CPU and I deleted some unnecessary irq and connections, and now it works, with exactly the same program code...  

Thanks Daixiwen ;) 

(http://www.alteraforum.com/forum/member.php?u=4443)
0 Kudos
Reply