using allwrite to write 4 Bytes of string

Questions and discussions about the Xillybus IP core and drivers

using allwrite to write 4 Bytes of string

Postby thatnitai »

Hi,

I'm having what are probably very basic knowledge difficulties. I want to load strings 32bits wide (by strings I mean the binary ascii values of 4 chars grouped together so for example "AB!@"). The issue is I'm not sure how to use allwrite for this, beyond changing the length to 4 (from 1 in the example).

What does work for me is if I use on "strtoul" and hex numbers:

Code: Select all
unsigned char *buf[1]={ "A5CB2C1D", "AFCB1CBD"};

data = (unsigned char *) strtoul(buf[0], NULL, 10);

allwrite(fd, &data, 4);


This does give me the expected result, the FPGA at the location written to returns "A5CB2C1D" etc. when I use allread.

However, I don't know how to transfer ascii values, and not use strtoul for this, since I want to transfer a string that is 4 bytes long, rather than a number.

How can I approach this?
Thank you.
thatnitai
 
Posts: 2
Joined:

Re: using allwrite to write 4 Bytes of string

Postby thatnitai »

I don't see a way to edit so let me correct myself, the middle line is
data = (unsigned char *) strtoul(buf[0], NULL, 16);

(Base 16 not 10)
thatnitai
 
Posts: 2
Joined:

Re: using allwrite to write 4 Bytes of string

Postby support »

Hello,

This forum deals with Xillybus specific issues. Your issue seems to be with the C language.

And frankly speaking, I didn't understand what you're trying to achieve, and what the problem is. If you want to send the contents of the buf[] array (defined one element long but initialized with two?), why don't you just give allwrite the buf[0] or buf[1]?

Regards,
Eli
support
 
Posts: 802
Joined:

Re: using allwrite to write 4 Bytes of string

Postby Guest »

Sorry about the messy phrasing.

Well, I found that for some reason the string is sent (or received?) in reverse order. So using allwrite(fd, &data, 4) when data is initialized with ABCD is being stored as DCBA on the FPGA. Perhaps it's related to the fact I've "broken" the user_w_mem_data signal to 4 chunks of 8 bits, so I can store the chars individually for convenience. At any rate, this wasn't an issue when I was using strtoul or atoi. Furthermore, when reading from FPGA and using %s in printf, it does show up correctly as ABCD.

I'd like to understand why and how this is happening, but I understand this is probably not the right place to ask. So sorry if this question was misplaced, but thanks for the help, because I now know the issue and can work around it (I'll just reverse the order of Bytes on the FPGA side).

Thank you.
Guest
 


Return to Xillybus

cron