Paparazzi UAS  v5.15_devel-112-g521f3cf
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
settings.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2009-2014 The Paparazzi Team
3  *
4  * This file is part of paparazzi.
5  *
6  * paparazzi is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2, or (at your option)
9  * any later version.
10  *
11  * paparazzi is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with paparazzi; see the file COPYING. If not, write to
18  * the Free Software Foundation, 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  */
21 
28 #include "subsystems/settings.h"
29 #include "generated/settings.h"
30 
31 struct PersistentSettings pers_settings;
32 
39 
41 
42 
43 void settings_init(void)
44 {
45 #if USE_PERSISTENT_SETTINGS
46  if (persistent_read((void *)&pers_settings, sizeof(struct PersistentSettings))) {
47  return; // return -1 ?
48  }
49  /* from generated/settings.h */
50  persistent_settings_load();
51 #endif
52 }
53 
58 {
59 #if USE_PERSISTENT_SETTINGS
60  if (settings_store_flag) {
61  /* from generated/settings.h */
62  persistent_settings_store();
63  if (!persistent_write((void *)&pers_settings, sizeof(struct PersistentSettings))) {
64  /* persistent write was successful */
65  settings_store_flag = true;
66  return 0;
67  }
68  }
69 #endif
70  settings_store_flag = false;
71  return -1;
72 }
73 
78 {
79 #if USE_PERSISTENT_SETTINGS
80  if (settings_clear_flag) {
81  if (!persistent_clear()) {
82  /* clearing all persistent settings was successful */
83  settings_clear_flag = true;
84  return 0;
85  }
86  }
87 #endif
88  settings_clear_flag = false;
89  return -1;
90 }
int32_t persistent_write(void *ptr, uint32_t size)
Definition: settings_arch.c:33
int32_t persistent_read(void *ptr, uint32_t size)
Definition: settings_arch.c:38
int32_t settings_store(void)
store settings marked as persistent to flash
Definition: settings.c:57
void settings_init(void)
Definition: settings.c:43
struct PersistentSettings pers_settings
Definition: settings.c:31
int32_t settings_clear(void)
clear all persistent settings from flash
Definition: settings.c:77
bool settings_store_flag
flag for setting feedback.
Definition: settings.c:38
signed long int32_t
Definition: types.h:19
Persistent settings interface.
int32_t persistent_clear(void)
Definition: settings_arch.c:74
bool settings_clear_flag
Definition: settings.c:40