View previous topic :: View next topic |
Author |
Message |
freesat
Joined: 08 Feb 2011 Posts: 32
|
i need help with pointer array function parameter |
Posted: Sat Jul 05, 2014 6:52 pm |
|
|
Hi guys, i need to send an array of bytes to a function that will write it on spi, like this pseudo code:
Code: |
int8 function write( int8 *data ) {
for( idx=0;idx++;idx=sizeof(data) ) {
spi_write( data[idx] );
}
return 0;
}
void main () {
initialize....
// the array size is not fixed, i need send from 2 to 40 bytes at time, but is array values are hard coded.
status = write( {0x26,0x01,0x30,0x55} );
}
|
How can i do that in ccs ? someone can write a sample code?
I will appreciate some help!
thanks... |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sat Jul 05, 2014 9:15 pm |
|
|
The simple way is just to define your function with two parameters.
The first one is a pointer to the array. The second one is the array size
in bytes, or the number of bytes that you want to be processed in the
array. In other words, you pass the size along with your array pointer.
Here's how you would call it:
Code: | result = function_write(my_array, sizeof(my_array)); |
Here's some more. I just did a search and Ttelmah has sample code for
you in this thread:
http://www.ccsinfo.com/forum/viewtopic.php?t=48285 |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19509
|
|
Posted: Sun Jul 06, 2014 12:58 am |
|
|
Also, this thread:
<http://www.ccsinfo.com/forum/viewtopic.php?t=52242&highlight=array+sizeof>
Covers why the called function can't know the 'size' of what is passed, without this being also sent. |
|
|
|