jaspreeth / ardupilot-mega

Automatically exported from code.google.com/p/ardupilot-mega
0 stars 0 forks source link

Remove "static" in front of ArduPilotMega functions & globals #405

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Background:

Arduino IDE generates firmware by concatenation of all sketch pde files into a 
single c++ file, generation of a list of function prototypes to resolve any 
"use before define" erros, then compilation of the entire block of code in one 
temporary file with #line number directives to attempt to get compile errors 
reported correctly.

The source code for ArduPilotMega is quite usable outside the IDE with a 
"normal" build environment where each PDE file is a CPP file, and each CPP file 
generates a .o file, and then the final image is a link with the APM library 
and with a few Arduino library modules.

The result of building it this way is the same hex file as the Arduino IDE 
generates. The benefit is the compile-link-test cycle is dramatically reduced 
in time: a code change can be uploaded into the board within 3 seconds, versus 
30 seconds for the Arduino IDE. It is also then immediately portable to any 
other development environment without drama and with the same speed benefit.

Unfortunately all the ArduPilotMega files (the APM library is already ok) have 
"static" needlessly in front of both global variables defined in 
ArduPilotMega.cpp and each function defined in each PDE file.

Removal of "static" in front of each function does not change the Arduino IDE 
compile, however it makes life much easier for compilation outside the IDE 
using the identical file collection (just rename PDE to CPP and include a 
proto.h file that declares all functions called across PDEs and all global 
variables accessed outside ArduPilotMega.cpp)

Request:

my enhancement request is to modify the ArduPilotMega source files to remove 
"static" in front of globals and functions, and to create a proto.h file that 
is included at the start of each PDE file which declares all functions and 
globals in use.

If this enhancement request is accepted I am happy to provide a working proto.h 
file.

Maintenance of this would be minimal: when adding a new global, or adding a new 
function that is used between PDEs, just update the proto.h file.

Example, changing one line of ArduPilot.cpp, then 'make upload'

The rebuilt hex takes sub 2 seconds to find out if the compile is clean
The upload part takes 19 seconds:
The total time to install and start testing a change is 21 seconds.

# time make upload
avr-gcc -Os -w -ffunction-sections -fdata-sections -mmcu=atmega2560 
-DF_CPU=16000000L -DARDUINO=22 -I"/usr/lib/avr/include/avr" 
-I/Applications/Arduino.app/Contents/Resources/Java/libraries/Wire/ 
-I/Applications/Arduino.app/Contents/Resources/Java/libraries/SPI/ 
-I/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/ardui
no/ -I"./include" -I"src" -I"lib/APM_BMP085" -I"lib/APM_PerfMon" 
-I"lib/APM_PerfMon/APM_PerfMon_test" -I"lib/APM_RC" -I"lib/AP_ADC" 
-I"lib/AP_Common" -I"lib/AP_Common/include" -I"lib/AP_Compass" -I"lib/AP_DCM" 
-I"lib/AP_EEPROMB" -I"lib/AP_GPS" -I"lib/AP_IMU" -I"lib/AP_Math" 
-I"lib/AP_Navigation" -I"lib/AP_OpticalFlow" -I"lib/AP_PID"   -I"lib/AP_RC"     
-I"lib/AP_RC_Channel"     -I"lib/AP_RangeFinder"   
-I"lib/AP_RangeFinder/examples/AP_RangeFinder_test" -I"lib/DataFlash"     
-I"lib/FastSerial"     -I"lib/GCS_MAVLink" -I"lib/GCS_MAVLink/doc" 
-I"lib/GCS_MAVLink/include" -I"lib/GCS_MAVLink/include/ardupilotmega" 
-I"lib/GCS_MAVLink/include/common" -I"lib/GCS_MAVLink/include/pixhawk" 
-I"lib/GCS_MAVLink/include/slugs" -I"lib/GCS_MAVLink/include/ualberta" 
-I"lib/GCS_MAVLink/message_definitions" -I"lib/GCS_SIMPLE" -I"lib/GPS_IMU"     
-I"lib/GPS_MTK"     -I"lib/GPS_NMEA"     -I"lib/GPS_UBLOX"     -I"lib/PID"     
-I"lib/RC_Channel"       -I"lib/SPI"         -I"lib/Waypoints" -I"lib/Wire"     
   -I"lib/arduino" -I"lib/default" -I"lib/ModeFilter" -c src/ArduPilotMega.cpp 
-o src/ArduPilotMega.o
avr-gcc -Os -Wl,--relax,--gc-sections -mmcu=atmega2560 src/ArduPilotMega.o 
src/Attitude.o src/climb_rate.o src/commands.o src/commands_logic.o 
src/commands_process.o src/control_modes.o src/events.o src/GCS_Mavlink.o 
src/HIL_Xplane.o src/Log.o src/navigation.o src/planner.o src/radio.o 
src/sensors.o src/setup.o src/system.o src/test.o src/tracker1.o 
/Applications/Arduino.app/Contents/Resources/Java/libraries/Wire/Wire.o 
/Applications/Arduino.app/Contents/Resources/Java/libraries/Wire/utility/twi.o 
/Applications/Arduino.app/Contents/Resources/Java/libraries/SPI/SPI.o 
/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/arduino
/main.o  APM_BMP085.a APM_PerfMon.a APM_RC.a AP_ADC.a AP_Common.a AP_Compass.a 
AP_DCM.a AP_EEPROMB.a AP_GPS.a AP_IMU.a AP_Navigation.a AP_OpticalFlow.a 
AP_PID.a AP_RC.a AP_RC_Channel.a AP_RangeFinder.a DataFlash.a FastSerial.a 
GCS_MAVLink.a GCS_SIMPLE.a GPS_IMU.a GPS_MTK.a GPS_NMEA.a GPS_UBLOX.a PID.a 
RC_Channel.a Waypoints.a arduino.a default.a ModeFilter.a -lm -o 
ArduPilotMega.elf
avr-objcopy -O ihex -j .eeprom --set-section-flags=.eeprom=alloc,load 
--no-change-warnings --change-section-lma .eeprom=0 ArduPilotMega.elf 
ArduPilotMega.eep
avr-objcopy -O ihex -R .eeprom ArduPilotMega.elf ArduPilotMega.hex
avr-size -A --mcu=atmega2560 ArduPilotMega.hex | scripts/size.rb 256000 
"ArduPilotMega.hex"
Sketch size: 100162 bytes (of a 256000 bytes maximum).
avrdude -Cavrdude.conf -V -patmega2560 -cstk500v2 -P/dev/tty.usbserial-A400CZEV 
-b115200 -D -Uflash:w:ArduPilotMega.hex:i

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.06s

avrdude: Device signature = 0x1e9801
avrdude: reading input file "ArduPilotMega.hex"
avrdude: writing flash (100162 bytes):

Writing | ################################################## | 100% 18.96s

avrdude: 100162 bytes of flash written

avrdude: safemode: Fuses OK

avrdude done.  Thank you.

real    0m21.182s
user    0m0.572s
sys 0m0.137s

Original issue reported on code.google.com by justinbe...@gmail.com on 5 Sep 2011 at 3:57

GoogleCodeExporter commented 8 years ago
Thanks for the thoughtful and detailed discussion here.

We actually addressed the non-IDE build problem slightly differently with a 
Makefile that emulates the Arduino IDE's behaviour.  This avoids introducing 
accidental incompatibilities into the build process when working in one world 
or the other  - we have considered a completely separate compilation model, but 
that would involve renaming all of the .pde files and creating significantly 
more than a single header if we were to do it properly.

To use the Makefile, you'll need to create a config.mk file at the top level of 
the checked-out sketchbook; a simple version might read:

BOARD=mega2560
PORT=/dev/tty.usbserial-A700eFgB

This supports a Mega2560 on a Mac OS X USB serial port - your port names will 
vary.  BOARD=mega supports the 1280-based APM boards.

Once you have this in place, 'make' and 'make upload' will behave as you 
expect, with comparable performance.

Original comment by DrZip...@gmail.com on 12 Sep 2011 at 5:21