ΣSigmaStudio Ask AI Русский Log in

A question about DSP communicate with ARM

Processors & DSP Graydon Nov 13, 2014 00:00 1 replies Original on forum ↗
Subscribe
Graydon Question
Nov 13, 2014 00:00

In sharc DSP, all basic data type size: sizeof(... ) =1, However, when communicate with ARM(MCU) using SPI etc. Assuming set spi data width:8, the received data like this: char rcv_buf[16]={0xa5,0x1,0x2,0x3,0x05,...,0xf};

But ARM process send the data as a struct as follow:

struct{

short magic;

short type;

char num;

...

char data[8];

}

How DSP convert the rcv_buf to this struct.? This a example, In fact, there are many struct communicated with ARM.

jobo23 Reply
Jan 14, 2015 00:00

You are correct in your interpretation of how the SHARC works. It is not a byte-addressable architecture, and all data elements are treated as 32-bit entities. From the SPI perspective on the SHARC side, the data would be populated in memory in sequential 32-bit locations, but only the lower 8 bits would contain the data because your SPI data width is set to 8. So, if the ARM treats char as 1-byte and short as 2-byte, and data is transmitted LSB first, then the above structure would come across to the SHARC and be stored in memory as:

rcv_buf[0] = magic.lower

rcv_buf[1] = magic.upper

rcv_buf[2] = type.lower

rcv_buf[3] = type.upper

rcv_buf[4] = num

...

rcv_buf[n-7] = data[0]

rcv_buf[n-6] = data[1]

rcv_buf[n-5] = data[2]

rcv_buf[n-4] = data[3]

rcv_buf[n-3] = data[4]

rcv_buf[n-2] = data[5]

rcv_buf[n-1] = data[6]

rcv_buf[n] = data[7]

Each of the above buffer elements would be a right-justified, 0-filled, 32-bit entity. You would then need to have software appropriately pack the received short data into a single element before processing it. Another alternative would be to use 16-bit SPI width, which would natively accommodate the short data (again, assuming it is 16-bit), but that would require that you insert a zero byte after each char in the structure.