cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
gusevv
Adventurer
Adventurer
2,734 Views
Registered: ‎11-13-2008

Code stops working after modification (Mailbox read function hangs or starts misbehaving)

Jump to solution

(edited title after clarification)

 

Hi,

 

I am using xapp996 (dual-proc reference design suite) (http://www.xilinx.com/support/documentation/application_notes/xapp996.pdf), but running on a modified hardware. I tried to limit the effect of hardware difference as much as possible. EDK 9.2 tools.

 

The original example code for ipi.c application sends an integer from CPU0 to CPU1 which in turn interrupts and sends it back. I try to do the same with strings. I simplified the test to only CPU1 receiving interrupt for now to explain the strange behavior. Below are examples of interrupt handlers that work and that do not. I am trying to understand why the latter fail.

 

In all the code below I write a 32-bit value w/ XMD from the other processor:

i.e. mwr 0x81010000 0x48484848

 

1) Original code, works:

int mp_handle_irq ()
{
    u32 val;
    int status;

  XMbox_ReadBlocking (&mbox, &val, 4);
  intr_count++;
  printf ("CPU1: Got an intr: %d. Sending interrupt count as an ack: %d.\r\n",
          val, intr_count);
}

PRINTS:
CPU1: Got an intr: 1162167621. Sending interrupt count as an ack: 1.

 

2) The code below is executed indefinitely. Mailbox is NOT read. I assume the interrupt is still asserted which is the reason for infinite calls. XMbox_Read() returns XST_SUCCESS, however the mailbox is not read. I checked with XMD manually. I added XMBox_ReadBlocking() which didn't help to read from mailbox either.

 

#define MAX_PAYLOAD  1024

int mp_handle_irq ()
{
    u32 val;
    int status;
    char printbuffer[MAX_PAYLOAD];
    char rx_buffer[MAX_PAYLOAD] = "OOPSIK-DOOPSIK";
    u32 num_rx_bytes;

    status = XMbox_Read (&mbox, rx_buffer, 16, &num_rx_bytes); <-- Prints XST_SUCCESS, but mbox is not read
    printf("CPU1: Read %d bytes\r\n", num_rx_bytes);
    printf("CPU1: XST_SUCCESS=%d, XST_NO_DATA=%d, status=%d \r\n",
           XST_SUCCESS,
           XST_NO_DATA,
           status
          );
    XMbox_ReadBlocking (&mbox, &val, 4);    
    memcpy(printbuffer, rx_buffer, num_rx_bytes);
    printf("CPU1: Read me: %s\r\n",
           printbuffer
          );

PRINTS Indefinitely:

CPU1: Read 16 bytes
CPU1: XST_SUCCESS=0, XST_NO_DATA=13, status=0   <-- driver says it read successfully (lies)
CPU1: Read meee: �      ��      ��      ��      �
CPU1: Read 16 bytes
CPU1: XST_SUCCESS=0, XST_NO_DATA=13, status=0
CPU1: Read meee: �      ��      ��      ��      �
CPU1.......

 

3) When memcpy() is removed, the text is printed once, but the CPU hangs and cannot receive more interrupts. Mailbox is still NOT read.

int mp_handle_irq ()
{
    u32 val;
    int status;
    char printbuffer[MAX_PAYLOAD];
    char rx_buffer[MAX_PAYLOAD] = "OOPSIK-DOOPSIK";
    u32 num_rx_bytes;

    status = XMbox_Read (&mbox, rx_buffer, 16, &num_rx_bytes);
    printf("CPU1: Read %d bytes\r\n", num_rx_bytes);
    printf("CPU1: XST_SUCCESS=%d, XST_NO_DATA=%d, status=%d \r\n",
           XST_SUCCESS,
           XST_NO_DATA,
           status
          );
    printf("CPU1: Received: %s\r\n", rx_buffer);
    printf ("CPU1: Got an intr: %d. Sending interrupt count as an ack: %d.\r\n",
          val, intr_count);

}

PRINTS and HANGS:

CPU1: Read 16 bytes                    <-- There were only 4 bytes in mbox, but driver claims maximum requested (Lies)
CPU1: XST_SUCCESS=0, XST_NO_DATA=13, status=0
CPU1: Received: �       |�      |�      |�      |
CPU1: Got an intr: 0. Sending interrupt count as an ack: 0. 

 

Does anything come to your mind to what might be going wrong? Maybe suggested tests to pinpoint the issue?

 

HW details:

UART is on the same bus with the CPU under test. 2nd CPU is on another PLB bus. Both PLBs are connected with Mailbox. MDM is on 2nd PLB. 2nd CPU can print to the same UART via bridge, but I am not printing in this case, just using MDM to write to mailbox.

 

Thanks,

Victor

 

 

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
gusevv
Adventurer
Adventurer
3,354 Views
Registered: ‎11-13-2008

I've spent too much time with Linux lately that takes care of virtual memory management and forgot to set the proper heap size in the linker for the brand new standalone app. The dynamically created arrays inside the shown function most likely overwrote data or text of the program since by default the heap is zero. The custom linker did the trick.

 

Hope someone finds it useful!

 

Thanks,

Victor

View solution in original post

Tags (1)
0 Kudos
1 Reply
gusevv
Adventurer
Adventurer
3,355 Views
Registered: ‎11-13-2008

I've spent too much time with Linux lately that takes care of virtual memory management and forgot to set the proper heap size in the linker for the brand new standalone app. The dynamically created arrays inside the shown function most likely overwrote data or text of the program since by default the heap is zero. The custom linker did the trick.

 

Hope someone finds it useful!

 

Thanks,

Victor

View solution in original post

Tags (1)
0 Kudos