KM3NeT CLB  2.0
KM3NeT CLB v2 Embedded Software
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
blockstore.h
Go to the documentation of this file.
1 /*
2  * KM3NeT CLB v2 Firmware
3  * ----------------------
4  *
5  * Copyright 2012-2014 KM3NeT Collaboration
6  *
7  * All Rights Reserved.
8  *
9  *
10  * File : blockstore.h
11  * Created : 26 nov. 2014
12  * Author : Vincent van Beveren
13  */
14 
15 #ifndef KERNEL_BLOCKSTORE_H_
16 #define KERNEL_BLOCKSTORE_H_
17 
18 /**
19  * @file
20  *
21  * @ingroup kernel
22  *
23  * Allows for storage of persistent information in flash.
24  */
25 
26 
27 #include <stdbool.h>
28 #include <stddef.h>
29 
30 #include "kernel/err.h"
31 #include "errorcode.h"
32 
33 //! Block storage is not valid. Must erase.
34 #define E_BS_INVALID (E_BLOCK + 0x01)
35 #define E_BS_INVALID_DESCR "Can not load blockdata, invalid"
36 
37 //! Buffer does not match the size of the allocated area.
38 #define E_BS_LEN_MISMATCH (E_BLOCK + 0x02)
39 #define E_BS_LEN_MISMATCH_DESCR "Length of block not equal to provided buffer"
40 
41 
42 
43 /**
44  * Saves a block of data on the internal flash.
45  * If there is already data in the flash, and its not the same, the block will be erased, and
46  * new data written.
47  *
48  * @param block The block number
49  * @param data The data to write
50  * @param len The length of the data
51  *
52  * @retval true Saving successful.
53  * @retval false Saving failed, please check error module for error.
54  */
55 bool bsSave(unsigned int block, void * data, size_t len);
56 
57 /**
58  * Loads a block of data from the flash.
59  *
60  * @param block The block number.
61  * @param data The data
62  * @param len The length
63  *
64  * @retval true Loading successful.
65  * @retval false Loading failed, please check error module for error.
66  */
67 bool bsLoad(unsigned int block, void * data, size_t len);
68 
69 /**
70  * Checks the contents of a block.
71  *
72  * @param block The block to check
73  * @param len Length to check (optional, 0 - don't check).
74  * @param hasValidData Pointer to result to fill.
75  *
76  * @retval true Check successful.
77  * @retval false Check failed, please check error module for error.
78  */
79 bool bsCheck(unsigned int block, size_t len, bool * hasValidData);
80 
81 /**
82  * Erases all data.
83  *
84  * @param block Block number
85  *
86  * @retval true Erase successful.
87  * @retval false Erase failed, please check error module for error.
88  */
89 bool bsErase(unsigned int block);
90 
91 
92 
93 #endif /* KERNEL_BLOCKSTORE_H_ */
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
Manages the global system error.
bool bsSave(unsigned int block, void *data, size_t len)
Saves a block of data on the internal flash.
Definition: blockstore.c:46
bool bsErase(unsigned int block)
Erases all data.
Definition: blockstore.c:91
This module is responsible for distributing error codes.