fram3  2.0.0.0
fram3.h
Go to the documentation of this file.
1 /*
2  * MikroSDK - MikroE Software Development Kit
3  * Copyright© 2020 MikroElektronika d.o.o.
4  *
5  * Permission is hereby granted, free of charge, to any person
6  * obtaining a copy of this software and associated documentation
7  * files (the "Software"), to deal in the Software without restriction,
8  * including without limitation the rights to use, copy, modify, merge,
9  * publish, distribute, sublicense, and/or sell copies of the Software,
10  * and to permit persons to whom the Software is furnished to do so,
11  * subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
22  * OR OTHER DEALINGS IN THE SOFTWARE.
23  */
24 
33 // ----------------------------------------------------------------------------
34 
35 #ifndef FRAM3_H
36 #define FRAM3_H
37 
38 #include "mikrosdk_version.h"
39 
40 #ifdef __GNUC__
41 #if mikroSDK_GET_VERSION < 20800ul
42 #include "rcu_delays.h"
43 #else
44 #include "delays.h"
45 #endif
46 #endif
47 
48 #include "drv_digital_out.h"
49 #include "drv_digital_in.h"
50 #include "drv_i2c_master.h"
51 
52 // -------------------------------------------------------------- PUBLIC MACROS
62 #define FRAM3_MAP_MIKROBUS( cfg, mikrobus ) \
63  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
64  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA )
65 
71 #define FRAM3_RETVAL uint8_t
72 
73 #define FRAM3_OK 0x00
74 #define FRAM3_INIT_ERROR 0xFF
75 
81 #define FRAM3_SLAVE_ADDR 0x50
82 
88 #define FRAM3_MAX_ADDR 0x6F
89 #define FRAM3_MAX_BUF_SIZE 16
90 
96 #define FRAM3_CMD_AES_RNG_GEN 0x1D
97 #define FRAM3_CMD_AES_CHALLENGE_RESPONSE_A 0x1B
98 #define FRAM3_CMD_AES_CHALLENGE_RESPONSE_B 0x1E
99 #define FRAM3_CMD_ID_READ 0x63
100 #define FRAM3_CMD_AES_ID_READ_MAC_A 0x8B
101 #define FRAM3_CMD_AES_ID_READ_MAC_B 0x8E
102 #define FRAM3_CMD_COUNTER_READ 0x66
103 #define FRAM3_CMD_COUNTER_INC 0x65
104 #define FRAM3_CMD_AES_COUNTER_READ_MAC_A 0x2B
105 #define FRAM3_CMD_AES_COUNTER_READ_MAC_B 0x2E
106 #define FRAM3_CMD_AES_COUNTER_INC_MAC_A 0x4B
107 #define FRAM3_CMD_AES_COUNTER_INC_MAC_B 0x4E
108 #define FRAM3_CMD_OTW_FRAM_READ 0x2D
109 #define FRAM3_CMD_OTW_FRAM_WRITE 0x27
110 #define FRAM3_CMD_PROTECT_AREA_CONF 0xCA
111 #define FRAM3_CMD_PROTECT_AREA_READ 0x8D
112 #define FRAM3_CMD_PROTECT_AREA_WRITE 0x87
113 #define FRAM3_CMD_MEMORY_RESET 0xA5
114 #define FRAM3_CMD_FRAM_READ 0x4D
115 #define FRAM3_CMD_FRAM_WRITE 0x47
116 #define FRAM3_CMD_ID_WRITE 0xC3
117 #define FRAM3_CMD_FUNC_CONF_WRITE 0xA6
118 #define FRAM3_CMD_SEC_KEY_WRITE 0xA9
119 #define FRAM3_CMD_PASSWORD_CHG 0xC9
120 #define FRAM3_CMD_MIXING_CONST_WRITE 0xCC
121 #define FRAM3_CMD_LIFE_CYCLE_CHG 0x6C
122 #define FRAM3_CMD_STATUS_READ 0x6A
123 
129 #define FRAM3_SUCCESS 0xAA
130 #define FRAM3_ERROR 0xBB
131  // End group macro
134 // --------------------------------------------------------------- PUBLIC TYPES
143 typedef struct
144 {
145  // Modules
146 
147  i2c_master_t i2c;
148 
149  // ctx variable
150 
151  uint8_t slave_address;
152 
153 } fram3_t;
154 
158 typedef struct
159 {
160  // Communication gpio pins
161 
162  pin_name_t scl;
163  pin_name_t sda;
164 
165  // static variable
166 
167  uint32_t i2c_speed;
168  uint8_t i2c_address;
169 
170 } fram3_cfg_t;
171  // End types group
173 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
174 
180 #ifdef __cplusplus
181 extern "C"{
182 #endif
183 
193 
203 
214 void fram3_generic_write ( fram3_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
215 
226 void fram3_generic_read ( fram3_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
227 
238 uint8_t fram3_read_free_access_memory ( fram3_t *ctx, uint8_t start_addr, uint8_t *data_buf, uint8_t n_buf_size );
239 
250 uint8_t fram3_write_free_access_memory ( fram3_t *ctx, uint8_t start_addr, uint8_t *data_buf, uint8_t n_buf_size );
251 
252 #ifdef __cplusplus
253 }
254 #endif
255 #endif // _FRAM3_H_
256  // End public_function group
259 
260 // ------------------------------------------------------------------------- END
fram3_generic_read
void fram3_generic_read(fram3_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic read function.
fram3_cfg_t
Click configuration structure definition.
Definition: fram3.h:159
fram3_init
FRAM3_RETVAL fram3_init(fram3_t *ctx, fram3_cfg_t *cfg)
Initialization function.
fram3_read_free_access_memory
uint8_t fram3_read_free_access_memory(fram3_t *ctx, uint8_t start_addr, uint8_t *data_buf, uint8_t n_buf_size)
Memory read function.
fram3_write_free_access_memory
uint8_t fram3_write_free_access_memory(fram3_t *ctx, uint8_t start_addr, uint8_t *data_buf, uint8_t n_buf_size)
Memory write function.
FRAM3_RETVAL
#define FRAM3_RETVAL
Definition: fram3.h:71
fram3_cfg_t::i2c_address
uint8_t i2c_address
Definition: fram3.h:168
fram3_t
Click ctx object definition.
Definition: fram3.h:144
fram3_generic_write
void fram3_generic_write(fram3_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
fram3_cfg_t::scl
pin_name_t scl
Definition: fram3.h:162
fram3_t::i2c
i2c_master_t i2c
Definition: fram3.h:147
fram3_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: fram3.h:167
fram3_cfg_setup
void fram3_cfg_setup(fram3_cfg_t *cfg)
Config Object Initialization function.
fram3_cfg_t::sda
pin_name_t sda
Definition: fram3.h:163
fram3_t::slave_address
uint8_t slave_address
Definition: fram3.h:151