upm  1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
m24lr64e.h
Go to the documentation of this file.
1 /*
2  * Author: Jon Trulson <jtrulson@ics.com>
3  * Abhishek Malik <abhishek.malik@intel.com>
4  * Copyright (c) 2016 Intel Corporation.
5  *
6  *
7  * This code was adapted from the Seeed Studio code at:
8  * https://github.com/Seeed-Studio/NFC_Tag_M24LR6E
9  *
10  * Copyright (c) 2014 seeed technology inc.
11  * Website : www.seeed.cc
12  * Author : lawliet zou
13  * Create Time: March 2014
14  *
15  * Permission is hereby granted, free of charge, to any person obtaining
16  * a copy of this software and associated documentation files (the
17  * "Software"), to deal in the Software without restriction, including
18  * without limitation the rights to use, copy, modify, merge, publish,
19  * distribute, sublicense, and/or sell copies of the Software, and to
20  * permit persons to whom the Software is furnished to do so, subject to
21  * the following conditions:
22  *
23  * The above copyright notice and this permission notice shall be
24  * included in all copies or substantial portions of the Software.
25  *
26  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
27  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
29  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
30  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
31  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
32  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33  */
34 
35 #ifndef M24LR64E_H_
36 #define M24LR64E_H_
37 
38 #include "upm.h"
39 #include "mraa/i2c.h"
40 
41 #define M24LR64E_I2C_BUS 0
42 #define M24LR64E_DEFAULT_I2C_ADDR 0x53
43 #define M24LR64E_DEFAULT_I2C_ADDR_E2 (M24LR64E_DEFAULT_I2C_ADDR | 0x04)
44 
45 #define M24LR64E_EEPROM_I2C_LENGTH 8192
46 #define M24LR64E_PASSWORD_LENGTH 4
47 #define M24LR64E_SECTOR_SECURITY_STATUS_BASE_ADDR 0x800
48 #define M24LR64E_LOCK_PROTECT_BIT 0x01
49 #define M24LR64E_WRITE_READ_PROTECT_BIT 0x02
50 #define M24LR64E_PASSWORD_CTRL_BIT 0x04
51 
52 #define M24LR64E_UID_LENGTH 8
53 #define M24LR64E_I2C_WRITE_TIME 5
54 
63 #include <stdint.h>
64 
65 typedef enum {
66  M24LR64E_I2C_PASSWORD_ADDRESS = 2304,
67  M24LR64E_RF_PASSWORD_1_ADDRESS = 2308, // RF pwds not available in
68  M24LR64E_RF_PASSWORD_2_ADDRESS = 2312, // I2C access modes
69  M24LR64E_RF_PASSWORD_3_ADDRESS = 2316,
70  M24LR64E_DSFID_ADDRESS = 2320, // 1 byte
71  M24LR64E_AFI_ADDRESS = 2321, // 1 byte
72  M24LR64E_RESV_ADDRESS = 2322, // 1 bytes
73  M24LR64E_CONFIG_ADDRESS = 2323, // 1 bytes
74  M24LR64E_UID_ADDRESS = 2324, // 8 bytes
75  M24LR64E_MEM_SIZE_ADDRESS = 2332, // 3 bytes
76  M24LR64E_IC_REF_ADDRESS = 2335, // 1 byte
77  M24LR64E_PROG_COMP_ENERGY_HARVEST_ADDRESS = 2339 // 1 byte
78 } M24LR64E_ADDR_T;
79 
80 typedef enum {
81  M24LR64E_USER_MODE = 0x0, // offers simple read/write access right
82  M24LR64E_ROOT_MODE = 0x1 // offers password change access right
83 } m24lr64e_access_mode;
84 
85 typedef enum {
86  // **********************************
87  // * submit passWd * no submit *
88  //b2,b1 * Read * Write * Read * Write *
89  // 00 * 1 1 1 0 *
90  // 01 * 1 1 1 1 *
91  // 10 * 1 1 0 0 *
92  // 11 * 0 1 0 0 *
93  // **********************************
94  m24lr64e_access_1110 = 0,
95  m24lr64e_access_1111 = 1,
96  m24lr64e_access_1100 = 2,
97  m24lr64e_access_0111 = 3,
98 } sector_access_right;
99 
100 typedef enum {
101  //00 => no passwd protect
102  //01 => passWd 1
103  //10 => passWd 2
104  //11 => passwd 3
105  m24lr64e_no_password = 0,
106  m24lr64e_password_1 = 1,
107  m24lr64e_password_2 = 2,
108  m24lr64e_password_3 = 3,
109 } sector_select_password;
110 
111 /*
112  * device context
113  */
114 typedef struct _m24lr64e_context {
115  mraa_i2c_context i2c;
116  int bus;
117  uint8_t address;
118  m24lr64e_access_mode mode;
120 
127 m24lr64e_context m24lr64e_init(int bus, m24lr64e_access_mode mode);
128 
135 
142 upm_result_t m24lr64e_submit_password(m24lr64e_context dev, uint32_t password);
143 
150 upm_result_t m24lr64e_write_password(m24lr64e_context dev, uint32_t password);
151 
162  uint32_t sector_number,
163  bool protect_enable,
164  sector_access_right access_right,
165  sector_select_password password);
166 
173 
183  uint32_t sector_number,
184  bool sock_enable);
185 
193 upm_result_t m24lr64e_get_dsfid(m24lr64e_context dev, uint8_t* dsfid);
194 
202 upm_result_t m24lr64e_get_afi(m24lr64e_context dev, uint8_t* afi);
203 
212 upm_result_t m24lr64e_get_uid(m24lr64e_context dev, uint8_t* uid);
213 
221 upm_result_t m24lr64e_get_memory_size(m24lr64e_context dev, uint32_t* memory_size);
222 
228 upm_result_t m24lr64e_clear_memory(m24lr64e_context dev);
229 
237 upm_result_t m24lr64e_write_byte(m24lr64e_context dev, uint32_t address,
238  uint8_t data);
239 
248 upm_result_t m24lr64e_write_bytes(m24lr64e_context dev, uint32_t address,
249  uint8_t* buffer, int len);
250 
258 upm_result_t m24lr64e_read_byte(m24lr64e_context dev, uint32_t address,
259  uint8_t* data);
260 
269 upm_result_t m24lr64e_read_bytes(m24lr64e_context dev, uint32_t address,
270  uint8_t* buffer, int len);
271 
272 #endif /* M24LR64E_H_ */
upm_result_t m24lr64e_sector_protect_config(m24lr64e_context dev, uint32_t sector_number, bool protect_enable, sector_access_right access_right, sector_select_password password)
Definition: m24lr64e.c:141
upm_result_t m24lr64e_sector_write_lock_bit(m24lr64e_context dev, uint32_t sector_number, bool sock_enable)
Definition: m24lr64e.c:162
void m24lr64e_close(m24lr64e_context dev)
Definition: m24lr64e.c:82
m24lr64e_context m24lr64e_init(int bus, m24lr64e_access_mode mode)
Definition: m24lr64e.c:51
upm_result_t m24lr64e_clear_sector_protect(m24lr64e_context dev)
Definition: m24lr64e.c:157
upm_result_t m24lr64e_clear_memory(m24lr64e_context dev)
Definition: m24lr64e.c:235
upm_result_t m24lr64e_get_dsfid(m24lr64e_context dev, uint8_t *dsfid)
Definition: m24lr64e.c:187
upm_result_t m24lr64e_get_afi(m24lr64e_context dev, uint8_t *afi)
Definition: m24lr64e.c:192
upm_result_t m24lr64e_write_byte(m24lr64e_context dev, uint32_t address, uint8_t data)
Definition: m24lr64e.c:244
upm_result_t m24lr64e_read_byte(m24lr64e_context dev, uint32_t address, uint8_t *data)
Definition: m24lr64e.c:256
Definition: m24lr64e.h:114
upm_result_t m24lr64e_get_uid(m24lr64e_context dev, uint8_t *uid)
Definition: m24lr64e.c:197
upm_result_t m24lr64e_read_bytes(m24lr64e_context dev, uint32_t address, uint8_t *buffer, int len)
Definition: m24lr64e.c:262
upm_result_t m24lr64e_write_bytes(m24lr64e_context dev, uint32_t address, uint8_t *buffer, int len)
Definition: m24lr64e.c:250
upm_result_t m24lr64e_submit_password(m24lr64e_context dev, uint32_t password)
Definition: m24lr64e.c:87
upm_result_t m24lr64e_write_password(m24lr64e_context dev, uint32_t password)
Definition: m24lr64e.c:115
upm_result_t m24lr64e_get_memory_size(m24lr64e_context dev, uint32_t *memory_size)
Definition: m24lr64e.c:210