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
42#ifdef PREINIT_SUPPORTED
43#include "preinit.h"
44#endif
45
46#ifdef MikroCCoreVersion
47 #if MikroCCoreVersion >= 1
48 #include "delays.h"
49 #endif
50#endif
51
52#include "drv_digital_out.h"
53#include "drv_digital_in.h"
54#include "drv_i2c_master.h"
55
56// -------------------------------------------------------------- PUBLIC MACROS
66#define FRAM3_MAP_MIKROBUS( cfg, mikrobus ) \
67 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
68 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA )
75#define FRAM3_RETVAL uint8_t
76
77#define FRAM3_OK 0x00
78#define FRAM3_INIT_ERROR 0xFF
85#define FRAM3_SLAVE_ADDR 0x50
92#define FRAM3_MAX_ADDR 0x6F
93#define FRAM3_MAX_BUF_SIZE 16
100#define FRAM3_CMD_AES_RNG_GEN 0x1D
101#define FRAM3_CMD_AES_CHALLENGE_RESPONSE_A 0x1B
102#define FRAM3_CMD_AES_CHALLENGE_RESPONSE_B 0x1E
103#define FRAM3_CMD_ID_READ 0x63
104#define FRAM3_CMD_AES_ID_READ_MAC_A 0x8B
105#define FRAM3_CMD_AES_ID_READ_MAC_B 0x8E
106#define FRAM3_CMD_COUNTER_READ 0x66
107#define FRAM3_CMD_COUNTER_INC 0x65
108#define FRAM3_CMD_AES_COUNTER_READ_MAC_A 0x2B
109#define FRAM3_CMD_AES_COUNTER_READ_MAC_B 0x2E
110#define FRAM3_CMD_AES_COUNTER_INC_MAC_A 0x4B
111#define FRAM3_CMD_AES_COUNTER_INC_MAC_B 0x4E
112#define FRAM3_CMD_OTW_FRAM_READ 0x2D
113#define FRAM3_CMD_OTW_FRAM_WRITE 0x27
114#define FRAM3_CMD_PROTECT_AREA_CONF 0xCA
115#define FRAM3_CMD_PROTECT_AREA_READ 0x8D
116#define FRAM3_CMD_PROTECT_AREA_WRITE 0x87
117#define FRAM3_CMD_MEMORY_RESET 0xA5
118#define FRAM3_CMD_FRAM_READ 0x4D
119#define FRAM3_CMD_FRAM_WRITE 0x47
120#define FRAM3_CMD_ID_WRITE 0xC3
121#define FRAM3_CMD_FUNC_CONF_WRITE 0xA6
122#define FRAM3_CMD_SEC_KEY_WRITE 0xA9
123#define FRAM3_CMD_PASSWORD_CHG 0xC9
124#define FRAM3_CMD_MIXING_CONST_WRITE 0xCC
125#define FRAM3_CMD_LIFE_CYCLE_CHG 0x6C
126#define FRAM3_CMD_STATUS_READ 0x6A
133#define FRAM3_SUCCESS 0xAA
134#define FRAM3_ERROR 0xBB
137 // End group macro
138// --------------------------------------------------------------- PUBLIC TYPES
147typedef struct
148{
149 // Modules
150
151 i2c_master_t i2c;
152
153 // ctx variable
154
156
157} fram3_t;
158
162typedef struct
163{
164 // Communication gpio pins
165
166 pin_name_t scl;
167 pin_name_t sda;
168
169 // static variable
170
171 uint32_t i2c_speed;
172 uint8_t i2c_address;
173
175
176 // End types group
177// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
178
184#ifdef __cplusplus
185extern "C"{
186#endif
187
197
207
218void fram3_generic_write ( fram3_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
219
230void fram3_generic_read ( fram3_t *ctx, uint8_t *tx_buf, uint8_t *data_buf, uint8_t len );
231
242uint8_t fram3_read_free_access_memory ( fram3_t *ctx, uint8_t start_addr, uint8_t *data_buf, uint8_t n_buf_size );
243
254uint8_t fram3_write_free_access_memory ( fram3_t *ctx, uint8_t start_addr, uint8_t *data_buf, uint8_t n_buf_size );
255
256#ifdef __cplusplus
257}
258#endif
259#endif // _FRAM3_H_
260
261 // End public_function group
263
264// ------------------------------------------------------------------------- END
#define FRAM3_RETVAL
Definition fram3.h:75
void fram3_generic_read(fram3_t *ctx, uint8_t *tx_buf, uint8_t *data_buf, uint8_t len)
Generic read function.
void fram3_cfg_setup(fram3_cfg_t *cfg)
Config Object Initialization function.
void fram3_generic_write(fram3_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len)
Generic write function.
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.
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 fram3_init(fram3_t *ctx, fram3_cfg_t *cfg)
Initialization function.
Click configuration structure definition.
Definition fram3.h:163
uint32_t i2c_speed
Definition fram3.h:171
pin_name_t scl
Definition fram3.h:166
pin_name_t sda
Definition fram3.h:167
uint8_t i2c_address
Definition fram3.h:172
Click ctx object definition.
Definition fram3.h:148
i2c_master_t i2c
Definition fram3.h:151
uint8_t slave_address
Definition fram3.h:155