nvsram2 2.0.0.0
nvsram2.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 NVSRAM2_H
29#define NVSRAM2_H
30
31#ifdef __cplusplus
32extern "C"{
33#endif
34
39#ifdef PREINIT_SUPPORTED
40#include "preinit.h"
41#endif
42
43#ifdef MikroCCoreVersion
44 #if MikroCCoreVersion >= 1
45 #include "delays.h"
46 #endif
47#endif
48
49#include "drv_digital_out.h"
50#include "drv_digital_in.h"
51#include "drv_spi_master.h"
52
78#define NVSRAM2_STATUS_RDSR 0x05
79#define NVSRAM2_STATUS_FRDSR 0x0A
80#define NVSRAM2_STATUS_WRSR 0x01
81#define NVSRAM2_STATUS_WREN 0x06
82#define NVSRAM2_STATUS_WRDI 0x04
83
88#define NVSRAM2_SRAM_READ 0x03
89#define NVSRAM2_SRAM_FREAD 0x0B
90#define NVSRAM2_SRAM_WRITE 0x02
91
96#define NVSRAM2_SPEC_NV_STORE 0x3C
97#define NVSRAM2_SPEC_NV_RECALL 0x60
98#define NVSRAM2_SPEC_NV_ASENB 0x59
99#define NVSRAM2_SPEC_NV_ASDISB 0x19
100
105#define NVSRAM2_SPEC_SLEEP 0xB9
106#define NVSRAM2_SPEC_WRSN 0xC2
107#define NVSRAM2_SPEC_RDSN 0xC3
108#define NVSRAM2_SPEC_FRDSN 0xC9
109#define NVSRAM2_SPEC_RDID 0x9F
110#define NVSRAM2_SPEC_FRDID 0x99
111
116#define NVSRAM2_STATUS_RDY 0x01
117#define NVSRAM2_STATUS_WEN 0x02
118#define NVSRAM2_STATUS_BP0 0x04
119#define NVSRAM2_STATUS_BP1 0x08
120#define NVSRAM2_STATUS_SNL 0x40
121#define NVSRAM2_STATUS_WPEN 0x80
122
123#define NVSRAM2_HOLD_ENABLE 0x00
124#define NVSRAM2_HOLD_DISABLE 0x01
125
126#define NVSRAM2_DUMMY_BYTE 0x00
127 // nvsram2_set
128
143#define NVSRAM2_MAP_MIKROBUS( cfg, mikrobus ) \
144 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
145 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
146 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
147 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
148 cfg.hld = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
149
150 // nvsram2_map
151 // nvsram2
152
157typedef struct
158{
159 // Output pins
160
161 digital_out_t hld;
163 // Modules
164
165 spi_master_t spi;
167 pin_name_t chip_select;
169} nvsram2_t;
170
175typedef struct
176{
177 // Communication gpio pins
178
179 pin_name_t miso;
180 pin_name_t mosi;
181 pin_name_t sck;
182 pin_name_t cs;
184 // Additional gpio pins
185
186 pin_name_t hld;
188 // static variable
189
190 uint32_t spi_speed;
191 spi_master_mode_t spi_mode;
192 spi_master_chip_select_polarity_t cs_polarity;
195
200typedef enum
201{
203 NVSRAM2_ERROR = -1
204
206
223
239
254
270err_t nvsram2_generic_write ( nvsram2_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
271
287err_t nvsram2_generic_read ( nvsram2_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
288
301void nvsram2_hold ( nvsram2_t *ctx, uint8_t en_hold );
302
315void nvsram2_set_cmd ( nvsram2_t *ctx, uint8_t cmd );
316
329
342
355void nvsram2_write_status ( nvsram2_t *ctx, uint8_t data_byte );
356
371void nvsram2_burst_read ( nvsram2_t *ctx, uint32_t mem_addr, uint8_t *p_rx_data, uint8_t n_bytes );
372
387void nvsram2_burst_write ( nvsram2_t *ctx, uint32_t mem_addr, uint8_t *p_tx_data, uint8_t n_bytes );
388
400uint32_t nvsram2_read_id ( nvsram2_t *ctx );
401
402#ifdef __cplusplus
403}
404#endif
405#endif // NVSRAM2_H
406
407 // nvsram2
408
409// ------------------------------------------------------------------------ END
void nvsram2_burst_write(nvsram2_t *ctx, uint32_t mem_addr, uint8_t *p_tx_data, uint8_t n_bytes)
nvSRAM 2 burst write function.
err_t nvsram2_generic_write(nvsram2_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
nvSRAM 2 data writing function.
err_t nvsram2_generic_read(nvsram2_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
nvSRAM 2 data reading function.
uint8_t nvsram2_read_status(nvsram2_t *ctx)
nvSRAM 2 read status register function.
err_t nvsram2_default_cfg(nvsram2_t *ctx)
nvSRAM 2 default configuration function.
uint32_t nvsram2_read_id(nvsram2_t *ctx)
nvSRAM 2 read ID function.
err_t nvsram2_init(nvsram2_t *ctx, nvsram2_cfg_t *cfg)
nvSRAM 2 initialization function.
void nvsram2_hold(nvsram2_t *ctx, uint8_t en_hold)
nvSRAM 2 data enable hold operation function.
void nvsram2_burst_read(nvsram2_t *ctx, uint32_t mem_addr, uint8_t *p_rx_data, uint8_t n_bytes)
nvSRAM 2 burst read function.
void nvsram2_write_status(nvsram2_t *ctx, uint8_t data_byte)
nvSRAM 2 write status register function.
uint8_t nvsram2_fast_read_status(nvsram2_t *ctx)
nvSRAM 2 fast read status register function.
void nvsram2_set_cmd(nvsram2_t *ctx, uint8_t cmd)
nvSRAM 2 send command function.
void nvsram2_cfg_setup(nvsram2_cfg_t *cfg)
nvSRAM 2 configuration object setup function.
nvsram2_return_value_t
nvSRAM 2 Click return value data.
Definition nvsram2.h:201
@ NVSRAM2_OK
Definition nvsram2.h:202
@ NVSRAM2_ERROR
Definition nvsram2.h:203
nvSRAM 2 Click configuration object.
Definition nvsram2.h:176
pin_name_t hld
Definition nvsram2.h:186
spi_master_chip_select_polarity_t cs_polarity
Definition nvsram2.h:192
pin_name_t sck
Definition nvsram2.h:181
spi_master_mode_t spi_mode
Definition nvsram2.h:191
pin_name_t mosi
Definition nvsram2.h:180
uint32_t spi_speed
Definition nvsram2.h:190
pin_name_t miso
Definition nvsram2.h:179
pin_name_t cs
Definition nvsram2.h:182
nvSRAM 2 Click context object.
Definition nvsram2.h:158
digital_out_t hld
Definition nvsram2.h:161
spi_master_t spi
Definition nvsram2.h:165
pin_name_t chip_select
Definition nvsram2.h:167