reram2 2.0.0.0
reram2.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 RERAM2_H
29#define RERAM2_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_spi_master.h"
51#include "spi_specifics.h"
52
73#define RERAM2_CMD_WREN 0x06
74#define RERAM2_CMD_WRDI 0x04
75#define RERAM2_CMD_RDSR 0x05
76#define RERAM2_CMD_WRSR 0x01
77#define RERAM2_CMD_READ 0x03
78#define RERAM2_CMD_WRITE 0x02
79#define RERAM2_CMD_RDID 0x9F
80#define RERAM2_CMD_RDUID 0x83
81#define RERAM2_CMD_SLEEP 0xB9
82#define RERAM2_CMD_PWDN 0xE2
83
84 // reram2_cmd
85
100#define RERAM2_DEVICE_ID 0x047FAA03
101#define RERAM2_MANUFACTURER_ID 0x04
102#define RERAM2_CONTINUATION_CODE 0x7F
103#define RERAM2_PRODUCT_ID 0xAA03
104
109#define RERAM2_HOLD_ENABLE 0x00
110#define RERAM2_HOLD_DISABLE 0x01
111
116#define RERAM2_WP_ENABLE 0x00
117#define RERAM2_WP_DISABLE 0x01
118
127#define RERAM2_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
128#define RERAM2_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
129
130 // reram2_set
131
146#define RERAM2_MAP_MIKROBUS( cfg, mikrobus ) \
147 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
148 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
149 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
150 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
151 cfg.ho = MIKROBUS( mikrobus, MIKROBUS_RST ); \
152 cfg.wp = MIKROBUS( mikrobus, MIKROBUS_PWM )
153
154 // reram2_map
155 // reram2
156
161typedef struct
162{
163 // Output pins
164 digital_out_t ho;
165 digital_out_t wp;
167 // Modules
168 spi_master_t spi;
170 pin_name_t chip_select;
172} reram2_t;
173
178typedef struct
179{
180 // Communication gpio pins
181 pin_name_t miso;
182 pin_name_t mosi;
183 pin_name_t sck;
184 pin_name_t cs;
186 // Additional gpio pins
187 pin_name_t ho;
188 pin_name_t wp;
190 // static variable
191 uint32_t spi_speed;
192 spi_master_mode_t spi_mode;
193 spi_master_chip_select_polarity_t cs_polarity;
196
201typedef struct
202{
207
209
214typedef struct
215{
218 uint16_t product_id;
219 uint8_t lot_id[ 5 ];
220 uint8_t wafer_id;
221 uint16_t chip_id;
222
224
229typedef enum
230{
232 RERAM2_ERROR = -1
233
235
252
267err_t reram2_init ( reram2_t *ctx, reram2_cfg_t *cfg );
268
283
299err_t reram2_generic_write ( reram2_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
300
316err_t reram2_generic_read ( reram2_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
317
332err_t reram2_set_hold ( reram2_t *ctx, uint8_t en_hold );
333
348err_t reram2_set_write_protect ( reram2_t *ctx, uint8_t en_wp );
349
362
375err_t reram2_send_command ( reram2_t *ctx, uint8_t cmd );
376
392
408
423
441err_t reram2_write_memory ( reram2_t *ctx, uint32_t mem_addr, uint8_t *data_in, uint16_t len );
442
460err_t reram2_read_memory ( reram2_t *ctx, uint32_t mem_addr, uint8_t *data_out, uint16_t len );
461
462#ifdef __cplusplus
463}
464#endif
465#endif // RERAM2_H
466
467 // reram2
468
469// ------------------------------------------------------------------------ END
err_t reram2_generic_read(reram2_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
ReRAM 2 data reading function.
err_t reram2_generic_write(reram2_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
ReRAM 2 data writing function.
err_t reram2_wake_up(reram2_t *ctx)
ReRAM 2 wake up function.
err_t reram2_set_hold(reram2_t *ctx, uint8_t en_hold)
ReRAM 2 set hold function.
err_t reram2_set_write_protect(reram2_t *ctx, uint8_t en_wp)
ReRAM 2 write protection function.
err_t reram2_read_device_id(reram2_t *ctx, reram2_dev_id_t *dev_id)
ReRAM 2 read device ID function.
err_t reram2_init(reram2_t *ctx, reram2_cfg_t *cfg)
ReRAM 2 initialization function.
err_t reram2_write_memory(reram2_t *ctx, uint32_t mem_addr, uint8_t *data_in, uint16_t len)
ReRAM 2 write memory function.
err_t reram2_send_command(reram2_t *ctx, uint8_t cmd)
ReRAM 2 set command function.
err_t reram2_check_device_id(reram2_t *ctx)
ReRAM 2 check device ID function.
err_t reram2_read_memory(reram2_t *ctx, uint32_t mem_addr, uint8_t *data_out, uint16_t len)
ReRAM 2 read memory function.
err_t reram2_get_status(reram2_t *ctx, reram2_status_t *status)
ReRAM 2 get status function.
void reram2_cfg_setup(reram2_cfg_t *cfg)
ReRAM 2 configuration object setup function.
err_t reram2_default_cfg(reram2_t *ctx)
ReRAM 2 default configuration function.
reram2_return_value_t
ReRAM 2 Click return value data.
Definition reram2.h:230
@ RERAM2_OK
Definition reram2.h:231
@ RERAM2_ERROR
Definition reram2.h:232
This file contains SPI specific macros, functions, etc.
ReRAM 2 Click configuration object.
Definition reram2.h:179
pin_name_t ho
Definition reram2.h:187
spi_master_chip_select_polarity_t cs_polarity
Definition reram2.h:193
pin_name_t sck
Definition reram2.h:183
spi_master_mode_t spi_mode
Definition reram2.h:192
pin_name_t mosi
Definition reram2.h:182
uint32_t spi_speed
Definition reram2.h:191
pin_name_t wp
Definition reram2.h:188
pin_name_t miso
Definition reram2.h:181
pin_name_t cs
Definition reram2.h:184
ReRAM 2 Click status object.
Definition reram2.h:215
uint16_t product_id
Definition reram2.h:218
uint8_t continuation_code
Definition reram2.h:217
uint8_t wafer_id
Definition reram2.h:220
uint8_t manufacturer_id
Definition reram2.h:216
uint16_t chip_id
Definition reram2.h:221
ReRAM 2 Click status object.
Definition reram2.h:202
uint8_t block_protect
Definition reram2.h:204
uint8_t write_protect
Definition reram2.h:203
uint8_t write_in_progress
Definition reram2.h:206
uint8_t write_enable_latch
Definition reram2.h:205
ReRAM 2 Click context object.
Definition reram2.h:162
spi_master_t spi
Definition reram2.h:168
digital_out_t ho
Definition reram2.h:164
pin_name_t chip_select
Definition reram2.h:170
digital_out_t wp
Definition reram2.h:165