Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Addressing 8 Channel A to D Data

Reply
Thread Tools

Addressing 8 Channel A to D Data

 
 
Barry Schwarz
Guest
Posts: n/a
 
      09-06-2012
On Wed, 5 Sep 2012 19:50:50 -0700 (PDT), Artist <(E-Mail Removed)>
wrote:

>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 &?

--
Remove del for email
 
Reply With Quote
 
 
 
 
Noob
Guest
Posts: n/a
 
      09-06-2012
Ike Naar wrote:

> Artist wrote:
>
>> I could also dynamically allocate a linear array of pointers to each row:
>>
>> u16 ** D2 = (u16 **)malloc( 200e3 * sizeof( u16 ** ) );


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)

 
Reply With Quote
 
 
 
 
Artist
Guest
Posts: n/a
 
      09-06-2012
On Thursday, September 6, 2012 5:27:27 AM UTC-7, Ben Bacarisse wrote:
> Barry Schwarz writes:
>
>
>
> > On Wed, 5 Sep 2012 19:50:50 -0700 (PDT), Artist

>
> > wrote:

>
> >

>
> >>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.
>
>
>
> --
>
> Ben.


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.
 
Reply With Quote
 
Casey Carter
Guest
Posts: n/a
 
      09-06-2012
On 2012-09-05 21:50, Artist wrote:
> 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;

 
Reply With Quote
 
Ben Bacarisse
Guest
Posts: n/a
 
      09-06-2012
Artist <(E-Mail Removed)> writes:

> On Thursday, September 6, 2012 5:27:27 AM UTC-7, Ben Bacarisse wrote:
>> Barry Schwarz writes:
>>
>>
>>
>> > On Wed, 5 Sep 2012 19:50:50 -0700 (PDT), Artist
>> >>Attempt 1:
>> >>".\ADC.c", line 205: cc0070: error: incomplete type is not allowed
>> >> u16 *pData[8][] = &((u16 * *)(pBuff->Data));
>> >> ^

<snip>
> 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.

--
Ben.
 
Reply With Quote
 
Tim Rentsch
Guest
Posts: n/a
 
      09-07-2012
Willem <(E-Mail Removed)> writes:

> Ben Bacarisse wrote:
> ) Artist <(E-Mail Removed)> writes:
> )<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.
 
Reply With Quote
 
Artist
Guest
Posts: n/a
 
      09-07-2012
On Thursday, September 6, 2012 1:13:59 PM UTC-7, Casey Carter wrote:
> On 2012-09-05 21:50, Artist wrote:
>
> u16 (*pData)[8] = pBuff->Data;


The compiler accepted this syntax. Thank you.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Dual channel or triple channel? Zeke Computer Support 0 06-07-2010 03:40 PM
Re: Dual channel or triple channel? Tony Computer Support 0 06-06-2010 08:32 AM
Re: Dual channel or triple channel? VanguardLH Computer Support 1 06-06-2010 01:36 AM
Six channel or two channel sound on DVD? cydeweys@gmail.com DVD Video 1 10-10-2005 04:51 AM
Have two ATA100 Seagate drives in a vp6, one IDE channel comes up as mode 5 in winxp but the other channel is stuck in mode 4 Tim Computer Support 3 02-23-2004 03:35 AM



Advertisments