diff --git a/conf/airframes/examples/setup_lisam2.xml b/conf/airframes/examples/setup_lisam2.xml index 45da9e7c27..73ce8b63d0 100644 --- a/conf/airframes/examples/setup_lisam2.xml +++ b/conf/airframes/examples/setup_lisam2.xml @@ -1,3 +1,5 @@ + + diff --git a/conf/airframes/test_settings.xml b/conf/airframes/test_settings.xml new file mode 100644 index 0000000000..b1891eed3a --- /dev/null +++ b/conf/airframes/test_settings.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/conf/conf_tests.xml b/conf/conf_tests.xml index bfcd52169d..049e0a40b1 100644 --- a/conf/conf_tests.xml +++ b/conf/conf_tests.xml @@ -329,6 +329,16 @@ settings=" settings/setup_actuators.xml" gui_color="blue" /> + - + diff --git a/sw/airborne/arch/lpc21/subsystems/settings_arch.c b/sw/airborne/arch/lpc21/subsystems/settings_arch.c index ea6b285355..b0a252fa3b 100644 --- a/sw/airborne/arch/lpc21/subsystems/settings_arch.c +++ b/sw/airborne/arch/lpc21/subsystems/settings_arch.c @@ -1,6 +1,4 @@ /* - * Paparazzi persistent settings low level flash routines lpc21 - * * Copyright (C) 2011 Martin Mueller * * This file is part of Paparazzi. @@ -22,21 +20,24 @@ * */ -/* - LPC2148 flash data is located in the last available page - - 0x00000000: Paparazzi bootloader (16k) - 0x00004000: Paparazzi code (480k) - 0x0007C000: persistent settings (4k) - 0x0007D000: Philips/NXP bootloader (12k) - - data flash_addr - data_size flash_end - FSIZ - checksum flash_end - FCHK - - LPC21: minimum write size 256 bytes, endurance 100k cycles, - max sector erase time 400ms, max prog time 1ms per 256 bytes -*/ +/** + * @file arch/lpc21/subsystems/settings_arch.c + * Persistent settings low level flash routines lpc21. + * + * LPC2148 flash data is located in the last available page + * + * 0x00000000: Paparazzi bootloader (16k) + * 0x00004000: Paparazzi code (480k) + * 0x0007C000: persistent settings (4k) + * 0x0007D000: Philips/NXP bootloader (12k) + * + * data flash_addr + * data_size flash_end - FSIZ + * checksum flash_end - FCHK + * + * LPC21: minimum write size 256 bytes, endurance 100k cycles, + * max sector erase time 400ms, max prog time 1ms per 256 bytes + */ #include "subsystems/settings.h" diff --git a/sw/airborne/arch/lpc21/subsystems/settings_arch.h b/sw/airborne/arch/lpc21/subsystems/settings_arch.h deleted file mode 100644 index ffd6d185fa..0000000000 --- a/sw/airborne/arch/lpc21/subsystems/settings_arch.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Paparazzi persistent settings low level flash routines lpc21 - * - * Copyright (C) 2011 Martin Mueller - * - * This file is part of Paparazzi. - * - * Paparazzi is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * Paparazzi is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Paparazzi; see the file COPYING. If not, write to - * the Free Software Foundation, 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - * - */ - - -#ifndef LPC21_SUBSYSTEMS_SETTINGS_H -#define LPC21_SUBSYSTEMS_SETTINGS_H - - - -#endif /* LPC21_SUBSYSTEMS_SETTINGS_H */ diff --git a/sw/airborne/arch/omap/subsystems/settings_arch.c b/sw/airborne/arch/omap/subsystems/settings_arch.c index 9cd1d5d489..8056be7184 100644 --- a/sw/airborne/arch/omap/subsystems/settings_arch.c +++ b/sw/airborne/arch/omap/subsystems/settings_arch.c @@ -1,5 +1,4 @@ /* - * * Copyright (C) 2009-2013 The Paparazzi Team * * This file is part of paparazzi. @@ -27,3 +26,16 @@ * Unimplemented. */ +#include "subsystems/settings.h" + +int32_t persistent_write(uint32_t ptr, uint32_t size) { + ptr=ptr; + size=size; + return -1; +} + +int32_t persistent_read(uint32_t ptr, uint32_t size) { + ptr=ptr; + size=size; + return -1; +} diff --git a/sw/airborne/arch/omap/subsystems/settings_arch.h b/sw/airborne/arch/omap/subsystems/settings_arch.h deleted file mode 100644 index c0c8a88a90..0000000000 --- a/sw/airborne/arch/omap/subsystems/settings_arch.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * - * Copyright (C) 2009-2013 The Paparazzi Team - * - * This file is part of paparazzi. - * - * paparazzi is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * paparazzi is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with paparazzi; see the file COPYING. If not, write to - * the Free Software Foundation, 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -/** - * @file arch/omap/subsystems/settings_arch.h - * OMAP arch Persistent settings. - * - * Unimplemented. - */ - -#ifndef OMAP_SUBSYSTEMS_SETTINGS_H -#define OMAP_SUBSYSTEMS_SETTINGS_H - - - -#endif /* OMAP_SUBSYSTEMS_SETTINGS_H */ diff --git a/sw/airborne/arch/sim/subsystems/settings_arch.c b/sw/airborne/arch/sim/subsystems/settings_arch.c index 1ed8a6a601..94bfbb9e62 100644 --- a/sw/airborne/arch/sim/subsystems/settings_arch.c +++ b/sw/airborne/arch/sim/subsystems/settings_arch.c @@ -1,14 +1,41 @@ -#include "subsystems/settings.h" +/* + * Copyright (C) 2009-2013 The Paparazzi Team + * + * This file is part of paparazzi. + * + * paparazzi is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * paparazzi is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with paparazzi; see the file COPYING. If not, write to + * the Free Software Foundation, 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ +/** + * @file arch/sim/subsystems/settings_arch.c + * Sim arch Persistent settings. + * + * Unimplemented. + */ + +#include "subsystems/settings.h" int32_t persistent_write(uint32_t ptr, uint32_t size) { ptr=ptr; size=size; - return 0; + return -1; } int32_t persistent_read(uint32_t ptr, uint32_t size) { ptr=ptr; size=size; - return 0; + return -1; } diff --git a/sw/airborne/arch/stm32/subsystems/settings_arch.c b/sw/airborne/arch/stm32/subsystems/settings_arch.c index f38fbe84c7..eb4022132c 100644 --- a/sw/airborne/arch/stm32/subsystems/settings_arch.c +++ b/sw/airborne/arch/stm32/subsystems/settings_arch.c @@ -1,6 +1,4 @@ /* - * Paparazzi persistent settings low level flash routines stm32 - * * Copyright (C) 2011 Martin Mueller * * This file is part of Paparazzi. @@ -22,16 +20,17 @@ * */ -/* - flash data is located in the last page/sector of flash - - data flash_addr - data_size flash_end - FSIZ - checksum flash_end - FCHK - - STM32: minimum write size 2 bytes, endurance 10k cycles, - max sector erase time 40ms, max prog time 70us per 2 bytes -*/ +/** + * @file arch/lpc21/subsystems/settings_arch.c + * Persistent settings low level flash routines stm32. + * + * data flash_addr + * data_size flash_end - FSIZ + * checksum flash_end - FCHK + * + * STM32: minimum write size 2 bytes, endurance 10k cycles, + * max sector erase time 40ms, max prog time 70us per 2 bytes + */ #include "subsystems/settings.h" @@ -243,7 +242,7 @@ static int32_t pflash_program_bytes(struct FlashInfo* flash __attribute__((unuse uint32_t src __attribute__((unused)), uint32_t size __attribute__((unused)), uint32_t chksum __attribute__((unused))) { - return 0; + return -1; } #endif diff --git a/sw/airborne/arch/stm32/subsystems/settings_arch.h b/sw/airborne/arch/stm32/subsystems/settings_arch.h deleted file mode 100644 index 41123a9247..0000000000 --- a/sw/airborne/arch/stm32/subsystems/settings_arch.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Paparazzi persistent settings low level flash routines stm32 - * - * Copyright (C) 2011 Martin Mueller - * - * This file is part of Paparazzi. - * - * Paparazzi is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * Paparazzi is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Paparazzi; see the file COPYING. If not, write to - * the Free Software Foundation, 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - * - */ - - -#ifndef STM32_SUBSYSTEMS_SETTINGS_H -#define STM32_SUBSYSTEMS_SETTINGS_H - - - -#endif /* STM32_SUBSYSTEMS_SETTINGS_H */ diff --git a/sw/airborne/subsystems/settings.c b/sw/airborne/subsystems/settings.c index e32c194722..5e8de775a6 100644 --- a/sw/airborne/subsystems/settings.c +++ b/sw/airborne/subsystems/settings.c @@ -1,22 +1,67 @@ +/* + * Copyright (C) 2009-2014 The Paparazzi Team + * + * This file is part of paparazzi. + * + * paparazzi is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * paparazzi is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with paparazzi; see the file COPYING. If not, write to + * the Free Software Foundation, 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +/** + * @file subsystems/settings.c + * Persistent settings interface. + * + */ + #include "subsystems/settings.h" struct PersistentSettings pers_settings; -bool_t settings_store_now; + +/** flag for setting feedback. + * if TRUE, was stored sucessfully. + * Also settings still need a variable, + * pure function call not possible yet. + */ +bool_t settings_store_flag; void settings_init(void) { #if USE_PERSISTENT_SETTINGS if (persistent_read((uint32_t)&pers_settings, sizeof(struct PersistentSettings))) return; // return -1 ? + /* from generated/settings.h */ persistent_settings_load(); #endif } - -void settings_store(void) { +/** store settings marked as persistent to flash + * @return 0 on success + */ +int32_t settings_store(void) { #if USE_PERSISTENT_SETTINGS - persistent_settings_store(); - persistent_write((uint32_t)&pers_settings, sizeof(struct PersistentSettings)); + if (settings_store_flag) { + /* from generated/settings.h */ + persistent_settings_store(); + if (!persistent_write((uint32_t)&pers_settings, sizeof(struct PersistentSettings))) { + /* persistent write was successful */ + settings_store_flag = TRUE; + return 0; + } + } #endif + settings_store_flag = FALSE; + return -1; } diff --git a/sw/airborne/subsystems/settings.h b/sw/airborne/subsystems/settings.h index 8c39b680eb..784e3a410b 100644 --- a/sw/airborne/subsystems/settings.h +++ b/sw/airborne/subsystems/settings.h @@ -1,14 +1,41 @@ +/* + * Copyright (C) 2009-2014 The Paparazzi Team + * + * This file is part of paparazzi. + * + * paparazzi is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * paparazzi is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with paparazzi; see the file COPYING. If not, write to + * the Free Software Foundation, 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +/** + * @file subsystems/settings.h + * Persistent settings interface. + * + */ + #ifndef SUBSYSTEMS_SETTINGS_H #define SUBSYSTEMS_SETTINGS_H #include "std.h" extern void settings_init(void); -extern void settings_store(void); +extern int32_t settings_store(void); -extern bool_t settings_store_now; +extern bool_t settings_store_flag; -#define settings_StoreSettings(_v) { settings_store_now = _v; settings_store(); } +#define settings_StoreSettings(_v) { settings_store_flag = _v; settings_store(); } #include "generated/settings.h" diff --git a/sw/airborne/test/subsystems/test_settings.c b/sw/airborne/test/subsystems/test_settings.c index 467114741d..b7ae642fc7 100644 --- a/sw/airborne/test/subsystems/test_settings.c +++ b/sw/airborne/test/subsystems/test_settings.c @@ -32,8 +32,6 @@ #include "mcu_periph/uart.h" #include "messages.h" -#include "my_debug_servo.h" - static inline void main_init( void ); static inline void main_periodic( void ); static inline void main_event( void ); @@ -68,8 +66,8 @@ static inline void main_init( void ) { static inline void main_periodic( void ) { RunOnceEvery(100, { - DOWNLINK_SEND_ALIVE(DefaultChannel, DefaultDevice, 16, MD5SUM); - PeriodicSendDlValue(DefaultChannel); + DOWNLINK_SEND_ALIVE(DefaultChannel, DefaultDevice, 16, MD5SUM); + PeriodicSendDlValue(DefaultChannel, DefaultDevice); }); } @@ -86,11 +84,11 @@ void dl_parse_msg(void) { switch (msg_id) { case DL_PING: { - DOWNLINK_SEND_PONG(DefaultChannel); + DOWNLINK_SEND_PONG(DefaultChannel, DefaultDevice); } break; case DL_SETTING: - if(DL_SETTING_ac_id(dl_buffer) == AC_ID) { + if (DL_SETTING_ac_id(dl_buffer) == AC_ID) { uint8_t i = DL_SETTING_index(dl_buffer); float val = DL_SETTING_value(dl_buffer); DlSetting(i, val);