1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-17 02:52:12 +01:00

OP-423: move the module initialize funtion into a specific section for OP and CC.

- create linker section for those <module>Initialize()
- later this list will incorporate parameters as well. (this probably will be more a OP feature to swap/remove/delete module on the fly.
- this is not done at compile time anymore by Makefile.
- this will allow us to have control on the module start at run-time (not implemented but build the ground for it).
- this simplify the startup (Part of code re-org).
- this change does not affect sim_posix and win32 (since they don't need that)
- ensure it's compiling for PiOS.posix
- port to PiOS.win32 but not tested (not compiled)
- tested on CC
- compile on OP.
- this free ~200 bytes.
- current avalable bytes (is we keep the same remaining bytes on the stack than before) is easily passed the 1.2Ko mark on CC with new gcc (4.5.2)
- this does not include init-reorg for each module (I still think more can be freed)
This commit is contained in:
Mathieu Rondonneau 2011-06-16 22:13:19 -07:00
parent e8cdf22427
commit 65cf467ca4
23 changed files with 113 additions and 86 deletions

View File

@ -113,12 +113,9 @@ OPUAVSYNTHDIR = $(OUTDIR)/../uavobject-synthetics/flight
# List C source files here. (C dependencies are automatically generated.)
# use file-extension c for "c-only"-files
MODNAMES = $(notdir ${MODULES})
ifndef TESTAPP
## MODULES
SRC += ${foreach MOD, ${MODULES}, ${wildcard ${OPMODULEDIR}/${MOD}/*.c}}
SRC += ${OUTDIR}/InitMods.c
## OPENPILOT CORE:
SRC += ${OPMODULEDIR}/System/systemmod.c
SRC += $(OPSYSTEM)/coptercontrol.c
@ -486,7 +483,7 @@ LSTFILES = $(addprefix $(OUTDIR)/, $(addsuffix .lst, $(ALLSRCBASE)))
DEPFILES = $(addprefix $(OUTDIR)/dep/, $(addsuffix .o.d, $(ALLSRCBASE)))
# Default target.
all: gencode build
all: build
ifeq ($(LOADFORMAT),ihex)
build: elf hex lss sym
@ -502,18 +499,6 @@ endif
endif
endif
# Generate intermediate code for objects
gencode: ${OUTDIR}/InitMods.c
# Generate code for module initialization
${OUTDIR}/InitMods.c: Makefile
@echo $(MSG_MODINIT) $(call toprel, $@)
@echo ${quote}// Autogenerated file${quote} > ${OUTDIR}/InitMods.c
@echo ${quote}${foreach MOD, ${MODNAMES}, extern unsigned int ${MOD}Initialize(void);}${quote} >> ${OUTDIR}/InitMods.c
@echo ${quote}void InitModules() {${quote} >> ${OUTDIR}/InitMods.c
@echo ${quote}${foreach MOD, ${MODNAMES}, ${MOD}Initialize();}${quote} >> ${OUTDIR}/InitMods.c
@echo ${quote}}${quote} >> ${OUTDIR}/InitMods.c
# Generate code for PyMite
#$(OUTDIR)/pmlib_img.c $(OUTDIR)/pmlib_nat.c $(OUTDIR)/pmlibusr_img.c $(OUTDIR)/pmlibusr_nat.c $(OUTDIR)/pmfeatures.h: $(wildcard $(PYMITELIB)/*.py) $(wildcard $(PYMITEPLAT)/*.py) $(wildcard $(FLIGHTPLANLIB)/*.py) $(wildcard $(FLIGHTPLANS)/*.py)
# @echo $(MSG_PYMITEINIT) $(call toprel, $@)
@ -620,4 +605,4 @@ else
endif
# Listing of phony targets.
.PHONY : all build clean clean_list gencode install
.PHONY : all build clean clean_list install

View File

@ -48,6 +48,9 @@ extern void InitModules(void);
/* Prototype of PIOS_Board_Init() function */
extern void PIOS_Board_Init(void);
/* Init module section */
extern initcall_t __module_initcall_start[], __module_initcall_end[];
/**
* OpenPilot Main function:
*
@ -65,8 +68,30 @@ int main()
/* Brings up System using CMSIS functions, enables the LEDs. */
PIOS_SYS_Init();
/* Initialize the system thread */
SystemModInitialize();
/* Architecture dependant Hardware and
* core subsystem initialisation
* (see pios_board.c for your arch)
* */
PIOS_Board_Init();
#ifdef ERASE_FLASH
PIOS_Flash_W25X_EraseChip();
while(TRUE){};
#endif
/* Initialize modules */
/* TODO: add id so we can parse this list later and replace module on the fly */
/* property flag will be add to give information like:
* - importance of the module (can be dropped or required for flight
* - parameter to enable feature at run-time (based on user setup on GCS)
* All this will be handled by bootloader. this section will add a function pointer
* and a pointer to a 32 bit in RAM with all the flags.
* Limited on CC this could be mapped on RAM for OP so we can grow the list at run-time.
*/
initcall_t *fn;
int32_t ret;
for (fn = __module_initcall_start; fn < __module_initcall_end; fn++)
ret = (*fn)();
#if defined(ARCH_POSIX) || defined(ARCH_WIN32)
/* Start the FreeRTOS scheduler which never returns.*/
@ -80,29 +105,6 @@ int main()
return 0;
}
/**
* Initialize the hardware, libraries and modules (called by the System thread in systemmod.c)
*/
void OpenPilotInit()
{
/* Architecture dependant Hardware and
* core subsystem initialisation
* (see pios_board.c for your arch)
* */
PIOS_Board_Init();
#ifdef ERASE_FLASH
PIOS_Flash_W25X_EraseChip();
while(TRUE){};
#endif
/* Initialize modules */
InitModules();
}
/**
* @}
* @}

View File

@ -69,6 +69,7 @@ static void ahrscommsTask(void *parameters);
* Initialise the module, called on startup
* \returns 0 on success or -1 if initialisation failed
*/
module_initcall(AHRSCommsInitialize, 0);
int32_t AHRSCommsInitialize(void)
{
// Start main task

View File

@ -90,6 +90,7 @@ typedef struct {
* @brief Module initialization
* @return 0
*/
module_initcall(ActuatorInitialize, 0);
int32_t ActuatorInitialize()
{
// Create object queue

View File

@ -37,6 +37,7 @@
*/
#include "openpilot.h"
#include "altitude.h"
#include "baroaltitude.h" // object that will be updated by the module
#if defined(PIOS_INCLUDE_HCSR04)
#include "sonaraltitude.h" // object that will be updated by the module
@ -66,6 +67,7 @@ static void altitudeTask(void *parameters);
* Initialise the module, called on startup
* \returns 0 on success or -1 if initialisation failed
*/
module_initcall(AltitudeInitialize, 0);
int32_t AltitudeInitialize()
{
// Start main task

View File

@ -94,6 +94,7 @@ static bool zero_during_arming = false;
* Initialise the module, called on startup
* \returns 0 on success or -1 if initialisation failed
*/
module_initcall(AttitudeInitialize, 0);
int32_t AttitudeInitialize(void)
{
// Initialize quaternion

View File

@ -75,6 +75,7 @@ static void onTimer(UAVObjEvent* ev);
* Initialise the module, called on startup
* \returns 0 on success or -1 if initialisation failed
*/
module_initcall(BatteryInitialize, 0);
int32_t BatteryInitialize(void)
{
static UAVObjEvent ev;

View File

@ -88,7 +88,7 @@ static void resetTask(UAVObjEvent *);
* \note
*
*/
module_initcall(FirmwareIAPInitialize, 0);
int32_t FirmwareIAPInitialize()
{
const struct pios_board_info * bdinfo = &pios_board_info_blob;

View File

@ -31,6 +31,7 @@
#include "openpilot.h"
#include "pm.h"
#include "flightplan.h"
#include "flightplanstatus.h"
#include "flightplancontrol.h"
#include "flightplansettings.h"
@ -56,6 +57,7 @@ extern unsigned char usrlib_img[];
/**
* Module initialization
*/
module_initcall(FlightPlanInitialize, 0);
int32_t FlightPlanInitialize()
{
taskHandle = NULL;

View File

@ -108,7 +108,7 @@ static uint32_t numParsingErrors;
* \return -1 if initialisation failed
* \return 0 on success
*/
module_initcall(GPSInitialize, 0);
int32_t GPSInitialize(void)
{
signed portBASE_TYPE xReturn;

View File

@ -82,6 +82,7 @@ static void updateVtolDesiredAttitude();
* Initialise the module, called on startup
* \returns 0 on success or -1 if initialisation failed
*/
module_initcall(GuidanceInitialize, 0);
int32_t GuidanceInitialize()
{
// Create object queue

View File

@ -27,5 +27,5 @@
#define EXAMPLEMODPERIODIC_H
int32_t ExampleModPeriodicInitialize();
int32_t GuidanceInitialize(void);
#endif // EXAMPLEMODPERIODIC_H

View File

@ -143,6 +143,7 @@ static bool validInputRange(int16_t min, int16_t max, uint16_t value);
/**
* Module initialization
*/
module_initcall(ManualControlInitialize, 0);
int32_t ManualControlInitialize()
{
/* Check the assumptions about uavobject enum's are correct */

View File

@ -89,6 +89,7 @@ static void SettingsUpdatedCb(UAVObjEvent * ev);
/**
* Module initialization
*/
module_initcall(StabilizationInitialize, 0);
int32_t StabilizationInitialize()
{
// Initialize variables

View File

@ -87,6 +87,7 @@ static void systemTask(void *parameters);
* Initialise the module, called on startup.
* \returns 0 on success or -1 if initialisation failed
*/
module_initcall(SystemModInitialize, 0);
int32_t SystemModInitialize(void)
{
// Initialize vars
@ -103,9 +104,6 @@ static void systemTask(void *parameters)
{
portTickType lastSysTime;
// System initialization
OpenPilotInit();
// Register task
TaskMonitorAdd(TASKINFO_RUNNING_SYSTEM, systemTaskHandle);

View File

@ -31,6 +31,7 @@
*/
#include "openpilot.h"
#include "telemetry.h"
#include "flighttelemetrystats.h"
#include "gcstelemetrystats.h"
#include "telemetrysettings.h"
@ -85,6 +86,7 @@ static void updateSettings();
* \return -1 if initialisation failed
* \return 0 on success
*/
module_initcall(TelemetryInitialize, 0);
int32_t TelemetryInitialize(void)
{
UAVObjEvent ev;
@ -131,6 +133,7 @@ int32_t TelemetryInitialize(void)
return 0;
}
/**
* Register a new object, adds object to local list and connects the queue depending on the object's
* telemetry settings.

View File

@ -115,8 +115,6 @@ UAVOBJSYNTHDIR = $(OUTDIR)/../uavobject-synthetics/flight
# List C source files here. (C dependencies are automatically generated.)
# use file-extension c for "c-only"-files
MODNAMES = $(notdir ${MODULES} ${PYMODULES})
ifndef TESTAPP
## PyMite files and modules
@ -131,7 +129,6 @@ SRC += $(PYSRC)
## MODULES
SRC += ${foreach MOD, ${MODULES}, ${wildcard ${OPMODULEDIR}/${MOD}/*.c}}
SRC += ${OUTDIR}/InitMods.c
## OPENPILOT CORE:
SRC += ${OPMODULEDIR}/System/systemmod.c
SRC += $(OPSYSTEM)/openpilot.c
@ -478,19 +475,10 @@ endif
endif
# Generate intermediate code
gencode: ${OUTDIR}/InitMods.c ${OUTDIR}/pmlib_img.c ${OUTDIR}/pmlib_nat.c ${OUTDIR}/pmlibusr_img.c ${OUTDIR}/pmlibusr_nat.c ${OUTDIR}/pmfeatures.h
gencode: ${OUTDIR}/pmlib_img.c ${OUTDIR}/pmlib_nat.c ${OUTDIR}/pmlibusr_img.c ${OUTDIR}/pmlibusr_nat.c ${OUTDIR}/pmfeatures.h
$(PYSRC): gencode
# Generate code for module initialization
${OUTDIR}/InitMods.c: Makefile
@echo $(MSG_MODINIT) $(call toprel, $@)
@echo ${quote}// Autogenerated file${quote} > ${OUTDIR}/InitMods.c
@echo ${quote}${foreach MOD, ${MODNAMES}, extern unsigned int ${MOD}Initialize(void);}${quote} >> ${OUTDIR}/InitMods.c
@echo ${quote}void InitModules() {${quote} >> ${OUTDIR}/InitMods.c
@echo ${quote}${foreach MOD, ${MODNAMES}, ${MOD}Initialize();}${quote} >> ${OUTDIR}/InitMods.c
@echo ${quote}}${quote} >> ${OUTDIR}/InitMods.c
# Generate code for PyMite
${OUTDIR}/pmlib_img.c ${OUTDIR}/pmlib_nat.c ${OUTDIR}/pmlibusr_img.c ${OUTDIR}/pmlibusr_nat.c ${OUTDIR}/pmfeatures.h: $(wildcard ${PYMITELIB}/*.py) $(wildcard ${PYMITEPLAT}/*.py) $(wildcard ${FLIGHTPLANLIB}/*.py) $(wildcard ${FLIGHTPLANS}/*.py)
@echo $(MSG_PYMITEINIT) $(call toprel, $@)

View File

@ -68,6 +68,11 @@ extern void InitModules(void);
/* Prototype of PIOS_Board_Init() function */
extern void PIOS_Board_Init(void);
#if !defined(ARCH_POSIX) && !defined(ARCH_WIN32)
/* Init module section */
extern initcall_t __module_initcall_start[], __module_initcall_end[];
#endif
/**
* OpenPilot Main function:
*
@ -85,16 +90,45 @@ int main()
/* Brings up System using CMSIS functions, enables the LEDs. */
PIOS_SYS_Init();
/* Initialize the system thread */
SystemModInitialize();
/* Architecture dependant Hardware and
* core subsystem initialisation
* (see pios_board.c for your arch)
* */
PIOS_Board_Init();
#if !defined(ARCH_POSIX) && !defined(ARCH_WIN32)
/* Initialize modules */
/* TODO: add id so we can parse this list later and replace module on the fly */
/* property flag will be add to give information like:
* - importance of the module (can be dropped or required for flight
* - parameter to enable feature at run-time (based on user setup on GCS)
* All this will be handled by bootloader. this section will add a function pointer
* and a pointer to a 32 bit in RAM with all the flags.
* Limited on CC this could be mapped on RAM for OP so we can grow the list at run-time.
*/
initcall_t *fn;
int32_t ret;
for (fn = __module_initcall_start; fn < __module_initcall_end; fn++)
ret = (*fn)();
/* Create test tasks */
/* keep this just because it was there */
//xTaskCreate(TaskTesting, (signed portCHAR *)"Testing", configMINIMAL_STACK_SIZE , NULL, 4, NULL);
//xTaskCreate(TaskHIDTest, (signed portCHAR *)"HIDTest", configMINIMAL_STACK_SIZE , NULL, 3, NULL);
//xTaskCreate(TaskServos, (signed portCHAR *)"Servos", configMINIMAL_STACK_SIZE , NULL, 3, NULL);
//xTaskCreate(TaskSDCard, (signed portCHAR *)"SDCard", configMINIMAL_STACK_SIZE, NULL, (tskIDLE_PRIORITY + 2), NULL);
#else
/* only do this for posix and win32 since the caller will take care
* of starting the scheduler and increase the heap and swith back to
* MSP stack. (all arch specific is hidden from here and take care by reset handler)
* LED blinking in case of scheduler returning back should be handled in NMI or other
* appropriate handlers like mem manager.
*/
#if defined(ARCH_POSIX) || defined(ARCH_WIN32)
/* Initialize modules */
InitModules();
/* Start the FreeRTOS scheduler which never returns.*/
vTaskStartScheduler();
@ -111,28 +145,6 @@ int main()
return 0;
}
/**
* Initialize the hardware, libraries and modules (called by the System thread in systemmod.c)
*/
void OpenPilotInit()
{
/* Architecture dependant Hardware and
* core subsystem initialisation
* (see pios_board.c for your arch)
* */
PIOS_Board_Init();
/* Initialize modules */
InitModules();
/* Create test tasks */
//xTaskCreate(TaskTesting, (signed portCHAR *)"Testing", configMINIMAL_STACK_SIZE , NULL, 4, NULL);
//xTaskCreate(TaskHIDTest, (signed portCHAR *)"HIDTest", configMINIMAL_STACK_SIZE , NULL, 3, NULL);
//xTaskCreate(TaskServos, (signed portCHAR *)"Servos", configMINIMAL_STACK_SIZE , NULL, 3, NULL);
//xTaskCreate(TaskSDCard, (signed portCHAR *)"SDCard", configMINIMAL_STACK_SIZE, NULL, (tskIDLE_PRIORITY + 2), NULL);
}
#if INCLUDE_TEST_TASKS
static void TaskTesting(void *pvParameters)

View File

@ -39,6 +39,7 @@
*/
#define uavobj_initcall(fn)
#define module_initcall(fn, param)
#endif /* PIOS_INITCALL_H */

View File

@ -39,6 +39,7 @@
*/
#define uavobj_initcall(fn)
#define module_initcall(fn, param)
#endif /* PIOS_INITCALL_H */

View File

@ -36,6 +36,16 @@ SECTIONS
__uavobj_initcall_end = .;
} >FLASH
/* module sections */
.initcallmodule.init :
{
. = ALIGN(4);
__module_initcall_start = .;
KEEP(*(.initcallmodule.init))
. = ALIGN(4);
__module_initcall_end = .;
} >FLASH
.ARM.extab :
{
*(.ARM.extab* .gnu.linkonce.armextab.*)

View File

@ -195,6 +195,16 @@ SECTIONS
__uavobj_initcall_end = .;
} >FLASH
/* module sections */
.initcallmodule.init :
{
. = ALIGN(4);
__module_initcall_start = .;
KEEP(*(.initcallmodule.init))
. = ALIGN(4);
__module_initcall_end = .;
} >FLASH
/* the program code is stored in the .text section, which goes to Flash */
.text :
{

View File

@ -55,7 +55,13 @@ typedef int32_t (*initcall_t)(void);
static initcall_t __initcall_##fn##id __attribute__((__used__)) \
__attribute__((__section__(".initcall" level ".init"))) = fn
/* TODO: add param later */
#define __define_module_initcall(level,fn,param) \
static initcall_t __initcall_##fn __attribute__((__used__)) \
__attribute__((__section__(".initcall" level ".init"))) = fn
#define uavobj_initcall(fn) __define_initcall("uavobj",fn,1)
#define module_initcall(fn, param) __define_module_initcall("module",fn,param)
#endif /* PIOS_INITCALL_H */