Contiki-NG
eeprom.h
Go to the documentation of this file.
1 /* Copyright (c) 2004 Swedish Institute of Computer Science.
2  * All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without modification,
5  * are permitted provided that the following conditions are met:
6  *
7  * 1. Redistributions of source code must retain the above copyright notice,
8  * this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright notice,
10  * this list of conditions and the following disclaimer in the documentation
11  * and/or other materials provided with the distribution.
12  * 3. The name of the author may not be used to endorse or promote products
13  * derived from this software without specific prior written permission.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
16  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
17  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
18  * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
20  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
23  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
24  * OF SUCH DAMAGE.
25  *
26  *
27  * Author: Adam Dunkels <adam@sics.se>
28  *
29  */
30 
31 /**
32  * \file
33  * EEPROM functions.
34  * \author Adam Dunkels <adam@sics.se>
35  */
36 
37 /**
38  * \addtogroup dev
39  * @{
40  */
41 
42 /**
43  * \defgroup eeprom EEPROM API
44  *
45  * The EEPROM API defines a common interface for EEPROM access.
46  *
47  * A platform with EEPROM support must implement this API.
48  *
49  * @{
50  */
51 
52 #ifndef EEPROM_H_
53 #define EEPROM_H_
54 
55 #include <limits.h>
56 #include <stdbool.h>
57 #include <stddef.h>
58 
59 typedef unsigned short eeprom_addr_t;
60 
61 #ifdef EEPROM_CONF_SIZE
62 #define EEPROM_SIZE (EEPROM_CONF_SIZE)
63 #else
64 #define EEPROM_SIZE 0 /* Default to no EEPROM */
65 #endif
66 
67 #if EEPROM_SIZE > USHRT_MAX
68 #error Too large EEPROM size -- please reconfigure EEPROM_CONF_SIZE.
69 #endif
70 
71 #ifdef EEPROM_CONF_END_ADDR
72 #define EEPROM_END_ADDR (EEPROM_CONF_END_ADDR)
73 #else
74 #define EEPROM_END_ADDR (EEPROM_SIZE - 1)
75 #endif
76 
77 /**
78  * Write a buffer into EEPROM.
79  *
80  * This function writes a buffer of the specified size into EEPROM.
81  *
82  * \param addr The address in EEPROM to which the buffer should be written.
83  *
84  * \param buf A pointer to the buffer from which data is to be read.
85  *
86  * \param size The number of bytes to write into EEPROM.
87  *
88  * \return a boolean indicating whether the operation succeeded.
89  */
90 bool eeprom_write(eeprom_addr_t addr, const unsigned char *buf, size_t size);
91 
92 /**
93  * Read data from the EEPROM.
94  *
95  * This function reads a number of bytes from the specified address in
96  * EEPROM and into a buffer in memory.
97  *
98  * \param addr The address in EEPROM from which the data should be read.
99  *
100  * \param buf A pointer to the buffer to which the data should be stored.
101  *
102  * \param size The number of bytes to read.
103  *
104  * \return a boolean indicating whether the operation succeeded.
105  *
106  */
107 bool eeprom_read(eeprom_addr_t addr, unsigned char *buf, size_t size);
108 
109 /**
110  * Initialize the EEPROM module
111  *
112  * This function initializes the EEPROM module and is called from the
113  * bootup code.
114  *
115  * \return a boolean indicating whether the operation succeeded.
116  */
117 
118 bool eeprom_init(void);
119 
120 #endif /* EEPROM_H_ */
121 
122 /** @} */
123 /** @} */
bool eeprom_init(void)
Initialize the EEPROM module.
Definition: eeprom.c:79
static uip_ds6_addr_t * addr
Pointer to a nbr cache entry.
Definition: uip-nd6.c:107
bool eeprom_write(eeprom_addr_t addr, const unsigned char *buf, size_t size)
Write a buffer into EEPROM.
Definition: eeprom.c:142
bool eeprom_read(eeprom_addr_t addr, unsigned char *buf, size_t size)
Read data from the EEPROM.
Definition: eeprom.c:168