Re: [beagleboard] Embedded C - Function Declaration

30 views
Skip to first unread message

William Hermans

unread,
Nov 10, 2016, 3:46:49 AM11/10/16
to beagl...@googlegroups.com
#1 Your code as is won't compile. Period.
william@beaglebone:~$ pru-gcc -o main main.c
main.c:10:13: error: redefinition of 'turnOn'
 static void turnOn(){
             ^~~~~~
main.c:5:13: note: previous definition of 'turnOn' was here
 static void turnOn(){
             ^~~~~~

#2 If you use the -Wall compiler option, you'll be given more information as to why.
william@beaglebone:~$ pru-gcc -Wall -o main main.c
main.c:10:13: error: redefinition of 'turnOn'
 static void turnOn(){
             ^~~~~~
main.c:5:13: note: previous definition of 'turnOn' was here
 static void turnOn(){
             ^~~~~~
main.c:5:13: warning: 'turnOn' defined but not used [-Wunused-function]

#3 If you only have one function of the same name.
william@beaglebone:~$ pru-gcc -Wall -o main main.c
william@beaglebone:~$ ls |grep main
main
main.c


#4 I suspect you're not showing all your code. So for anyone to give a proper answer you need to provide _all_your_code_




On Thu, Nov 10, 2016 at 12:14 AM, Neil Jubinville <ne...@orbitalsoftware.ca> wrote:
Hi All, so now that I am underway with the loader working I decided I would abstract out the single command that turns on the LED to a function.  I have been hanging out in high level languages for far too long and it shows!

I am observing that my function is not being called??  

Calling the write function from the main loop results in the LED turning on however the function does not fire.

I would have expected that a forward declaration would work fine and no additional header references would be required.    Is there anything special needed to declare a simple function in a PRU-GCC compiled c file?


static void turnOn(){
   write_r30
(0x1111);
}


static void turnOn(){
   write_r30
(0x0000);
}


int main(void){
 
   turnOn
();   // this does not work.

   
// write_r30(0x1111);   This works.....

return 0;


}




--
For more options, visit http://beagleboard.org/discuss
---
You received this message because you are subscribed to the Google Groups "BeagleBoard" group.
To unsubscribe from this group and stop receiving emails from it, send an email to beagleboard+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/beagleboard/2b564886-2f54-4ffe-a147-130e863d91a2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

William Hermans

unread,
Nov 10, 2016, 3:50:19 AM11/10/16
to beagl...@googlegroups.com
Additionally, it's not clear which version of gcc the pru_gcc compiler is based on. So, it's not readily obvious as to which C std we're using. Anyway, in C technically you can not override a function as can be done in many high level languages such as C++, C#, etc. There are ways to work around this feature, but it depends on which std as to which options you have,

Chris Green

unread,
Nov 10, 2016, 4:34:19 AM11/10/16
to beagl...@googlegroups.com
Neil Jubinville <ne...@orbitalsoftware.ca> wrote:
> [-- multipart/alternative, encoding 7bit, 132 lines --]
>
> [-- text/plain, encoding 7bit, charset: UTF-8, 46 lines --]
>
> Hi All, so now that I am underway with the loader working I decided I would
> abstract out the single command that turns on the LED to a function. I
> have been hanging out in high level languages for far too long and it shows!
>
> I am observing that my function is not being called??
>
> Calling the write function from the main loop results in the LED turning on
> however the function does not fire.
>
> I would have expected that a forward declaration would work fine and no
> additional header references would be required. Is there anything
> special needed to declare a simple function in a PRU-GCC compiled c file?
>
>
> static void turnOn(){
> write_r30(0x1111);
> }
>
>
> static void turnOn(){
> write_r30(0x0000);
> }
>
>
> int main(void){
>
> turnOn(); // this does not work.
>
> // write_r30(0x1111); This works.....
>
> return 0;
>
>
> }
>

When you say "this does not work" what error (compiler error
presumably) do you see? ... and is the code *exactly* as above?


--
Chris Green
·

Przemek Klosowski

unread,
Nov 10, 2016, 10:21:53 AM11/10/16
to beagl...@googlegroups.com
On Thu, Nov 10, 2016 at 2:14 AM, Neil Jubinville
<ne...@orbitalsoftware.ca> wrote:

> Calling the write function from the main loop results in the LED turning on
> however the function does not fire.
>
> static void turnOn(){
> write_r30(0x1111);
> }
>
>
> static void turnOn(){
> write_r30(0x0000);
> }
>
>
> int main(void){
>
> turnOn(); // this does not work.
>

I think it's a simple typo---you have two turnOn() functions---it
looks to me that the second one should be called turnOff(). As it is,
I think you redefine the first turnOn with the second one, which
actually turns off the pin, so you see nothing. Does it make sense?
Reply all
Reply to author
Forward
0 new messages