Addressing 8 Channel A to D Data

B

Barry Schwarz

Also, you could maybe convert the pointer to something like: ((u16[8]) *)

I have trouble finding the right syntax to do this recast. My best effort so far gets these error messages:

Attempt 1:

".\ADC.c", line 205: cc0070: error: incomplete type is not allowed
u16 *pData[8][] = &((u16 * *)(pBuff->Data));
^

Your array has 8 rows. How many columns per row do you want? Specify
that value in the second dimension. Array initialization should be
enclosed in braces.

The right hand expression has type u16***. Each element of the array
has type u16*. There is no implicit conversion between them. Did you
mean to use * instead of &?
 
N

Noob

Forget the floating point arithmetic.
That should probably be sizeof(u16*).
You can avoid this mistake by using the idiom

u16 ** D2 = malloc(200e3 * sizeof *D2);

malloc(200*1000 * sizeof *D2)
 
A

Artist

Barry Schwarz writes:


On Saturday, August 18, 2012 1:13:13 AM UTC-7, Willem wrote:

Also, you could maybe convert the pointer to something like: ((u16[8]) *)


I have trouble finding the right syntax to do this recast. My best effort so far gets these error messages:

Attempt 1:

".\ADC.c", line 205: cc0070: error: incomplete type is not allowed
u16 *pData[8][] = &((u16 * *)(pBuff->Data));
^
Your array has 8 rows. How many columns per row do you want? Specify
that value in the second dimension. Array initialization should be
enclosed in braces.

The right hand expression has type u16***. Each element of the array
has type u16*. There is no implicit conversion between them. Did you
mean to use * instead of &?



I think these last two are related. I think he's trying to initialise a

pointer to an array. Willem's post continued with "I.E. a pointer to an

array of 8 values."



Without knowing the declared type of the pBuff and the data layout the

OP settled on it's hard to correct.

It is the pointer I want to initialize and not the array data. DMA has already placed array data into the buffer pointed to by pBuff->Data.

pBuff->Data has type (void *).

The number of columns is fixed at 8 A to D channels. The number of rows is arbitrary and depends on how much data the system is configured to receive before the ISR is called that contains this code.

The A to D data has unsigned 16 bit representation. Please see the first post of this thread to see the sequence DMA puts the data into the buffer pointed to by pBuff->Data, and that I am trying recast into a two dimensional array.
 
C

Casey Carter

I have trouble finding the right syntax to do this recast. My best effort so far gets these error messages:

Attempt 1:

".\ADC.c", line 205: cc0070: error: incomplete type is not allowed
u16 *pData[8][] = &((u16 * *)(pBuff->Data));
^

".\ADC.c", line 205: cc0158: error: expression must be an lvalue or a
function designator
u16 *pData[8][] = &((u16 * *)(pBuff->Data));
^
Attempt 2:

".\imi_ADC.c", line 205: cc0070: error: incomplete type is not allowed
u16 *pData[8][] = &(((u16[8]) *)(pBuff->Data));
^

".\imi_ADC.c", line 205: cc0119: error: cast to type "u16 [8]" is not allowed
u16 *pData[8][] = &(((u16[8]) *)(pBuff->Data));
^

u16 (*pData)[8] = pBuff->Data;
 
B

Ben Bacarisse

Artist said:
Barry Schwarz writes:


".\ADC.c", line 205: cc0070: error: incomplete type is not allowed
u16 *pData[8][] = &((u16 * *)(pBuff->Data));
^
It is the pointer I want to initialize and not the array data. DMA has
already placed array data into the buffer pointed to by pBuff->Data.

pBuff->Data has type (void *).

The number of columns is fixed at 8 A to D channels. The number of
rows is arbitrary and depends on how much data the system is
configured to receive before the ISR is called that contains this
code.

The A to D data has unsigned 16 bit representation. Please see the
first post of this thread to see the sequence DMA puts the data into
the buffer pointed to by pBuff->Data, and that I am trying recast into
a two dimensional array.

You want:

u16 (*pData)[8] = pBuff->Data;

I would not use a cast. It adds no safety and they are fiddly with
array and function types. For the record it's (u16 (*)[8]) here -- take
a declaration, remove the name and add brackets.
 
T

Tim Rentsch

Willem said:
Ben Bacarisse wrote:
)<snip>
)> I need to know which of the above equations, 1, 2, or 3, will access
)> the data quickest.
)
) Since I think you'll have to try them all, you might want to consider
) two other options:
)
) 4) Use a 2D array to get the compiler to do the address arithmetic.
) It's unlikely, but the compiler might be able to do it better than
) you can, but if it's no worse you get cleaner code and that can only
) be a Good Thing.

It's already a 2D array, isn't it?
You just need to cast it to the correct type.

Technically, no, it isn't; it's possible for (ie, the Standard
allows) arrays to have alignment requirements that are more
restrictive than their element types. Thus we could have,
for example, an array 'int x[4096];' that has the same
alignment as int, but an array 'int y[512][8];' that has
an alignment of 8 int's. So converting an (int *) pointer
to a (int (*)[8]) pointer could transgress into undefined
behavior. Granted, incredibly unlikely, but possible
under the rules of the Standard.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,078
Messages
2,570,570
Members
47,204
Latest member
MalorieSte

Latest Threads

Top