KM3NeT CLB  2.0
KM3NeT CLB v2 Embedded Software
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
runtime.c
1 /*
2  * KM3NeT CLB v2 Firmware
3  * ----------------------
4  *
5  * Copyright 2012-2014 KM3NeT Collaboration
6  *
7  * All Rights Reserved.
8  *
9  *
10  * File : runtime.c
11  * Created : 26 nov. 2014
12  * Author : Vincent van Beveren
13  */
14 
15 #include "runtime.h"
16 #include "kernel/sys.h"
17 #include "cfg_soc.h"
18 #include "kernel/blockstore.h"
19 
20 #include "util/log.h"
21 
22 LOG_DEF("Runtime");
23 
24 #define _CONFIG_VERSION 1
25 
26 typedef struct {
27  uint8_t version;
28  uint8_t rtImage;
30 
31 static RuntimeConfig _rcConfig;
32 
33 static bool _init = false;
34 
35 static void loadRuntimeData() {
36  if (_init) return;
37 
38 
39  bool valid;
40 
41 
42  if (!bsCheck(BLS_RUNTIME, sizeof(_rcConfig), &valid))
43  {
44  sysLogClearError("Load boot data");
45  _rcConfig.version = _CONFIG_VERSION;
46  _rcConfig.rtImage = RT_DEFAULT_IMAGE;
47  } else if (!valid)
48  {
49  logInfo("No runtime data stored. Using defaults");
50  _rcConfig.version = _CONFIG_VERSION;
51  _rcConfig.rtImage = RT_DEFAULT_IMAGE;
52  } else {
53  bsLoad(BLS_RUNTIME, &_rcConfig, sizeof(_rcConfig));
54  }
55 
56  _init = true;
57 }
58 
59 int rtImage()
60 {
61  loadRuntimeData();
62  return _rcConfig.rtImage;
63 }
64 
65 
66 bool rtSetImage(int imgNo)
67 {
68  if (imgNo <= 0 || imgNo >= FLASH_MAX_IMAGES) return errSet(ERROR_CTX(E_INVARGUMENT));
69  loadRuntimeData();
70  _rcConfig.rtImage = imgNo;
71  if (!bsSave(BLS_RUNTIME, &_rcConfig, sizeof(_rcConfig))) return false;
72  return true;
73 }
Defines the configuration of the LM32 SOC for the CLBv2.
Allows for storage of persistent information in flash.
int rtImage()
Returns the image loaded for runtime.
Definition: runtime.c:59
Provides access to the runtime image booting.
System start up and management.
#define BLS_RUNTIME
Runtime information location.
Definition: cfg_soc.h:168
void sysLogClearError(const char *doingWhat)
Logs an error in the context of what the application is doing.
Definition: sys.c:366
#define E_INVARGUMENT
Generic error: invalid argument.
Definition: errorcode.h:112
bool bsCheck(unsigned int block, size_t len, bool *hasValidData)
Checks the contents of a block.
Definition: blockstore.c:63
bool bsLoad(unsigned int block, void *data, size_t len)
Loads a block of data from the flash.
Definition: blockstore.c:79
bool bsSave(unsigned int block, void *data, size_t len)
Saves a block of data on the internal flash.
Definition: blockstore.c:46
#define LOG_DEF(NAME,...)
Define a logger for a module.
Definition: log.h:129
bool errSet(uint32_t code, const char *error, const char *name)
Sets an error.
bool rtSetImage(int imgNo)
Sets the runtime boot image number.
Definition: runtime.c:66
Implements a generic logger facility.
#define logInfo(MSG,...)
Write a log message with formatting on info level.
Definition: log.h:202