Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
12 years ago

Writing Char to On-Chip FIFO

I am trying to take a char array and send it trough a FIFO. but the On-Chip FIFO only accepts alt_u32 as data and i cannot send my data correctly. here is code that i am using to try and send the char array.

        for(i=0;i<recvMsgSize+4;i=i+4){
            memmove(buffer, echoBuffer+i, 4);
            data= atol(buffer);
            altera_avalon_fifo_write_fifo(FIFO_BUFFER_IN_BASE, FIFO_BUFFER_IN_CSR_BASE, data);
             
        }

so i am taking the long echoBuffer and splitting it into 4bytes char chucks to send it trough the 32 bit FIFO port. then i try to change it to a alt_u32 and send it trough but all it sends is 0's

2 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Are you sure the atol() conversion is performed correctly? I mean, is the value assigned to data different from zero ?

    I'd also put buffer[4]=0 in order to correctly terminate the string chunk.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Don't you just want:

    data = *(int *)(echoBuffer + i);

    which will be ok provided echoBuffer is 4 byte aligned.