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 "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_i2c_master.h"
41 
42 // -------------------------------------------------------------- PUBLIC MACROS
52 #define FRAM3_MAP_MIKROBUS( cfg, mikrobus ) \
53  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
54  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA )
55 
61 #define FRAM3_RETVAL uint8_t
62 
63 #define FRAM3_OK 0x00
64 #define FRAM3_INIT_ERROR 0xFF
65 
71 #define FRAM3_SLAVE_ADDR 0x50
72 
78 #define FRAM3_MAX_ADDR 0x6F
79 #define FRAM3_MAX_BUF_SIZE 16
80 
86 #define FRAM3_CMD_AES_RNG_GEN 0x1D
87 #define FRAM3_CMD_AES_CHALLENGE_RESPONSE_A 0x1B
88 #define FRAM3_CMD_AES_CHALLENGE_RESPONSE_B 0x1E
89 #define FRAM3_CMD_ID_READ 0x63
90 #define FRAM3_CMD_AES_ID_READ_MAC_A 0x8B
91 #define FRAM3_CMD_AES_ID_READ_MAC_B 0x8E
92 #define FRAM3_CMD_COUNTER_READ 0x66
93 #define FRAM3_CMD_COUNTER_INC 0x65
94 #define FRAM3_CMD_AES_COUNTER_READ_MAC_A 0x2B
95 #define FRAM3_CMD_AES_COUNTER_READ_MAC_B 0x2E
96 #define FRAM3_CMD_AES_COUNTER_INC_MAC_A 0x4B
97 #define FRAM3_CMD_AES_COUNTER_INC_MAC_B 0x4E
98 #define FRAM3_CMD_OTW_FRAM_READ 0x2D
99 #define FRAM3_CMD_OTW_FRAM_WRITE 0x27
100 #define FRAM3_CMD_PROTECT_AREA_CONF 0xCA
101 #define FRAM3_CMD_PROTECT_AREA_READ 0x8D
102 #define FRAM3_CMD_PROTECT_AREA_WRITE 0x87
103 #define FRAM3_CMD_MEMORY_RESET 0xA5
104 #define FRAM3_CMD_FRAM_READ 0x4D
105 #define FRAM3_CMD_FRAM_WRITE 0x47
106 #define FRAM3_CMD_ID_WRITE 0xC3
107 #define FRAM3_CMD_FUNC_CONF_WRITE 0xA6
108 #define FRAM3_CMD_SEC_KEY_WRITE 0xA9
109 #define FRAM3_CMD_PASSWORD_CHG 0xC9
110 #define FRAM3_CMD_MIXING_CONST_WRITE 0xCC
111 #define FRAM3_CMD_LIFE_CYCLE_CHG 0x6C
112 #define FRAM3_CMD_STATUS_READ 0x6A
113 
119 #define FRAM3_SUCCESS 0xAA
120 #define FRAM3_ERROR 0xBB
121  // End group macro
124 // --------------------------------------------------------------- PUBLIC TYPES
133 typedef struct
134 {
135  // Modules
136 
137  i2c_master_t i2c;
138 
139  // ctx variable
140 
141  uint8_t slave_address;
142 
143 } fram3_t;
144 
148 typedef struct
149 {
150  // Communication gpio pins
151 
152  pin_name_t scl;
153  pin_name_t sda;
154 
155  // static variable
156 
157  uint32_t i2c_speed;
158  uint8_t i2c_address;
159 
160 } fram3_cfg_t;
161  // End types group
163 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
164 
170 #ifdef __cplusplus
171 extern "C"{
172 #endif
173 
182 void fram3_cfg_setup ( fram3_cfg_t *cfg );
183 
193 
204 void fram3_generic_write ( fram3_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
205 
216 void fram3_generic_read ( fram3_t *ctx, uint8_t reg, uint8_t *data_buf, uint8_t len );
217 
228 uint8_t fram3_read_free_access_memory ( fram3_t *ctx, uint8_t start_addr, uint8_t *data_buf, uint8_t n_buf_size );
229 
240 uint8_t fram3_write_free_access_memory ( fram3_t *ctx, uint8_t start_addr, uint8_t *data_buf, uint8_t n_buf_size );
241 
242 #ifdef __cplusplus
243 }
244 #endif
245 #endif // _FRAM3_H_
246  // End public_function group
249 
250 // ------------------------------------------------------------------------- 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:148
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:61
fram3_cfg_t::i2c_address
uint8_t i2c_address
Definition: fram3.h:158
fram3_t
Click ctx object definition.
Definition: fram3.h:133
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:152
fram3_t::i2c
i2c_master_t i2c
Definition: fram3.h:137
fram3_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: fram3.h:157
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:153
fram3_t::slave_address
uint8_t slave_address
Definition: fram3.h:141