nvsram  2.0.0.0
nvsram.h
Go to the documentation of this file.
1 /****************************************************************************
2 ** Copyright (C) 2020 MikroElektronika d.o.o.
3 ** Contact: https://www.mikroe.com/contact
4 **
5 ** Permission is hereby granted, free of charge, to any person obtaining a copy
6 ** of this software and associated documentation files (the "Software"), to deal
7 ** in the Software without restriction, including without limitation the rights
8 ** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 ** copies of the Software, and to permit persons to whom the Software is
10 ** furnished to do so, subject to the following conditions:
11 ** The above copyright notice and this permission notice shall be
12 ** included in all copies or substantial portions of the Software.
13 **
14 ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16 ** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18 ** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19 ** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20 ** USE OR OTHER DEALINGS IN THE SOFTWARE.
21 ****************************************************************************/
22 
28 #ifndef NVSRAM_H
29 #define NVSRAM_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
35 #include "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_i2c_master.h"
38 
59 #define NVSRAM_MEM_CTL_REG 0x00
60 #define NVSRAM_SERIAL_NUM_REG_1 0x01
61 #define NVSRAM_SERIAL_NUM_REG_2 0x02
62 #define NVSRAM_SERIAL_NUM_REG_3 0x03
63 #define NVSRAM_SERIAL_NUM_REG_4 0x04
64 #define NVSRAM_SERIAL_NUM_REG_5 0x05
65 #define NVSRAM_SERIAL_NUM_REG_6 0x06
66 #define NVSRAM_SERIAL_NUM_REG_7 0x07
67 #define NVSRAM_SERIAL_NUM_REG_8 0x08
68 #define NVSRAM_DEV_ID_REG_1 0x09
69 #define NVSRAM_DEV_ID_REG_2 0x0A
70 #define NVSRAM_DEV_ID_REG_3 0x0B
71 #define NVSRAM_DEV_ID_REG_4 0x0C
72 #define NVSRAM_CMD_REG 0xAA
73  // nvsram_reg
75 
90 #define NVSRAM_I2C_MEM_SEL 0x50
91 
96 #define NVSRAM_CMD_STORE 0x3C
97 #define NVSRAM_CMD_RECALL 0x60
98 #define NVSRAM_CMD_ASENB 0x59
99 #define NVSRAM_CMD_ASDISB 0x19
100 #define NVSRAM_CMD_SLEEP 0xB9
101 
106 #define NVSRAM_BP_NONE 0x00
107 #define NVSRAM_BP_QUARTER 0x04
108 #define NVSRAM_BP_HALF 0x08
109 #define NVSRAM_BP_ALL 0x0C
110 #define NVSRAM_NO_SNL 0x00
111 #define NVSRAM_SNL 0x40
112 
117 #define NVSRAM_WRITE_MEMORY_DISABLE 0x00
118 #define NVSRAM_WRITE_MEMORY_ENABLE 0x01
119 
124 #define NVSRAM_I2C_SLAVE_ADDR_0 0x18
125 #define NVSRAM_I2C_SLAVE_ADDR_1 0x1A
126 #define NVSRAM_I2C_SLAVE_ADDR_2 0x1C
127 #define NVSRAM_I2C_SLAVE_ADDR_3 0x1E
128  // nvsram_set
130 
145 #define NVSRAM_MAP_MIKROBUS( cfg, mikrobus ) \
146  cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
147  cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
148  cfg.wp = MIKROBUS( mikrobus, MIKROBUS_PWM )
149  // nvsram_map // nvsram
152 
157 typedef struct
158 {
159  // Output pins
160  digital_out_t wp;
162  // Modules
163  i2c_master_t i2c;
165  // I2C slave address
166  uint8_t slave_address;
168 } nvsram_t;
169 
174 typedef struct
175 {
176  pin_name_t scl;
177  pin_name_t sda;
179  pin_name_t wp;
181  uint32_t i2c_speed;
182  uint8_t i2c_address;
184 } nvsram_cfg_t;
185 
190 typedef enum
191 {
193  NVSRAM_ERROR = -1
194 
196 
213 
228 err_t nvsram_init ( nvsram_t *ctx, nvsram_cfg_t *cfg );
229 
245 err_t nvsram_generic_write ( nvsram_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len );
246 
262 err_t nvsram_generic_read ( nvsram_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len );
263 
277 void nvsram_reg_write ( nvsram_t *ctx, uint8_t reg, uint8_t tx_data );
278 
291 uint8_t nvsram_reg_read ( nvsram_t *ctx, uint8_t reg );
292 
308 void nvsram_burst_reg_write ( nvsram_t *ctx, uint8_t reg, uint8_t *p_tx_data, uint8_t n_bytes );
309 
325 void nvsram_burst_reg_read ( nvsram_t *ctx, uint8_t reg, uint8_t *p_rx_data, uint8_t n_bytes );
326 
339 void nvsram_send_cmd ( nvsram_t *ctx, uint8_t cmd );
340 
352 uint32_t nvsram_read_dev_id ( nvsram_t *ctx );
353 
369 void nvsram_memory_write ( nvsram_t *ctx, uint32_t mem_adr, uint8_t *p_tx_data, uint16_t n_bytes );
370 
386 void nvsram_memory_read ( nvsram_t *ctx, uint32_t mem_adr, uint8_t *p_rx_data, uint16_t n_bytes );
387 
400 void nvsram_enable_memory_write ( nvsram_t *ctx, uint8_t en_wr_mem );
401 
402 #ifdef __cplusplus
403 }
404 #endif
405 #endif // NVSRAM_H
406  // nvsram
408 
409 // ------------------------------------------------------------------------ END
nvsram_generic_read
err_t nvsram_generic_read(nvsram_t *ctx, uint8_t reg, uint8_t *rx_buf, uint8_t rx_len)
nvSRAM I2C reading function.
nvsram_cfg_t::i2c_address
uint8_t i2c_address
Definition: nvsram.h:182
nvsram_cfg_t::i2c_speed
uint32_t i2c_speed
Definition: nvsram.h:181
nvsram_init
err_t nvsram_init(nvsram_t *ctx, nvsram_cfg_t *cfg)
nvSRAM initialization function.
nvsram_burst_reg_read
void nvsram_burst_reg_read(nvsram_t *ctx, uint8_t reg, uint8_t *p_rx_data, uint8_t n_bytes)
Burst register read function.
nvsram_enable_memory_write
void nvsram_enable_memory_write(nvsram_t *ctx, uint8_t en_wr_mem)
Enable memory write function.
nvsram_burst_reg_write
void nvsram_burst_reg_write(nvsram_t *ctx, uint8_t reg, uint8_t *p_tx_data, uint8_t n_bytes)
Burst register write function.
nvsram_t
nvSRAM Click context object.
Definition: nvsram.h:158
NVSRAM_OK
@ NVSRAM_OK
Definition: nvsram.h:192
nvsram_reg_read
uint8_t nvsram_reg_read(nvsram_t *ctx, uint8_t reg)
Generic read the byte of data function.
nvsram_generic_write
err_t nvsram_generic_write(nvsram_t *ctx, uint8_t reg, uint8_t *tx_buf, uint8_t tx_len)
nvSRAM I2C writing function.
nvsram_memory_write
void nvsram_memory_write(nvsram_t *ctx, uint32_t mem_adr, uint8_t *p_tx_data, uint16_t n_bytes)
Write memory function.
NVSRAM_ERROR
@ NVSRAM_ERROR
Definition: nvsram.h:193
nvsram_memory_read
void nvsram_memory_read(nvsram_t *ctx, uint32_t mem_adr, uint8_t *p_rx_data, uint16_t n_bytes)
Read memory function.
nvsram_cfg_t
nvSRAM Click configuration object.
Definition: nvsram.h:175
nvsram_t::wp
digital_out_t wp
Definition: nvsram.h:160
nvsram_t::slave_address
uint8_t slave_address
Definition: nvsram.h:166
nvsram_cfg_t::scl
pin_name_t scl
Definition: nvsram.h:176
nvsram_return_value_t
nvsram_return_value_t
nvSRAM Click return value data.
Definition: nvsram.h:191
nvsram_reg_write
void nvsram_reg_write(nvsram_t *ctx, uint8_t reg, uint8_t tx_data)
Generic write the byte of data function.
nvsram_cfg_t::sda
pin_name_t sda
Definition: nvsram.h:177
nvsram_send_cmd
void nvsram_send_cmd(nvsram_t *ctx, uint8_t cmd)
Send command function.
nvsram_cfg_setup
void nvsram_cfg_setup(nvsram_cfg_t *cfg)
nvSRAM configuration object setup function.
nvsram_t::i2c
i2c_master_t i2c
Definition: nvsram.h:163
nvsram_read_dev_id
uint32_t nvsram_read_dev_id(nvsram_t *ctx)
Read device ID function.
nvsram_cfg_t::wp
pin_name_t wp
Definition: nvsram.h:179