mram2 2.0.0.0
mram2.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 MRAM2_H
36#define MRAM2_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_spi_master.h"
55
56// -------------------------------------------------------------- PUBLIC MACROS
67#define MRAM2_MAP_MIKROBUS( cfg, mikrobus ) \
68 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
69 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
70 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
71 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
72 cfg.rst = MIKROBUS( mikrobus, MIKROBUS_RST ); \
73 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT );
80#define MRAM2_OK 0
81#define MRAM2_ERROR -1
88#define MRAM2_CMD_RDSR 0x05
89#define MRAM2_CMD_WREN 0x06
90#define MRAM2_CMD_WRDI 0x04
91#define MRAM2_CMD_WRSR 0x01
92#define MRAM2_CMD_READ 0x03
93#define MRAM2_CMD_FREAD 0x0B
94#define MRAM2_CMD_WRITE 0x02
95#define MRAM2_CMD_SLEEP 0xB9
96#define MRAM2_CMD_WAKE 0xAB
97#define MRAM2_CMD_TDET 0x17
98#define MRAM2_CMD_TDETX 0x07
99#define MRAM2_CMD_RDID 0x4B
106#define MRAM2_STAT_REG_SRWD 0x80
107#define MRAM2_STAT_REG_QPI 0x40
108#define MRAM2_STAT_REG_BP1 0x08
109#define MRAM2_STAT_REG_BP0 0x04
110#define MRAM2_STAT_REG_WEL 0x02
117#define MRAM2_XIP_SET_CONT 0xEF
118#define MRAM2_XIP_RST_STOP 0xFF
125#define MRAM2_WP_ENABLE 0x01
126#define MRAM2_WP_DISABLE 0x00
127#define MRAM2_HLD_ENABLE 0x01
128#define MRAM2_HLD_DISABLE 0x00
129#define MRAM2_PIN_LOW 0x00
130#define MRAM2_PIN_HIGH 0x01
133 // End group macro
134// --------------------------------------------------------------- PUBLIC TYPES
143typedef struct
144{
145 digital_out_t cs;
146 // Output pins
147
148 digital_out_t rst;
149 digital_out_t int_pin;
150
151 // Modules
152
153 spi_master_t spi;
154 pin_name_t chip_select;
155
156} mram2_t;
157
161typedef struct
162{
163 // Communication gpio pins
164
165 pin_name_t miso;
166 pin_name_t mosi;
167 pin_name_t sck;
168 pin_name_t cs;
169
170 // Additional gpio pins
171
172 pin_name_t rst;
173 pin_name_t int_pin;
174
175 // static variable
176
177 uint32_t spi_speed;
178 spi_master_mode_t spi_mode;
179 spi_master_chip_select_polarity_t cs_polarity;
180
182
183 // End types group
184// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
185
190#ifdef __cplusplus
191extern "C"{
192#endif
193
203
211err_t mram2_init ( mram2_t *ctx, mram2_cfg_t *cfg );
212
222uint8_t mram2_rdsr ( mram2_t *ctx );
223
231void mram2_wren ( mram2_t *ctx );
232
240void mram2_wrdi ( mram2_t *ctx );
241
254void mram2_wrsr ( mram2_t *ctx, uint8_t stat_reg );
255
267void mram2_read ( mram2_t *ctx, uint32_t mem_adr, uint8_t *rd_data, uint8_t n_bytes );
268
281void mram2_fread ( mram2_t *ctx, uint32_t mem_adr, uint8_t mode, uint8_t *rd_data, uint8_t n_bytes );
282
295void mram2_write ( mram2_t *ctx, uint32_t mem_adr, uint8_t *wr_data, uint8_t n_bytes );
296
304void mram2_sleep ( mram2_t *ctx );
305
313void mram2_wake ( mram2_t *ctx );
314
329uint32_t mram2_tdet ( mram2_t *ctx );
330
340void mram2_tdetx ( mram2_t *ctx );
341
350void mram2_rdid ( mram2_t *ctx, uint8_t *rd_id );
351
360void mram2_write_protect ( mram2_t *ctx, uint8_t state );
361
370void mram2_hold ( mram2_t *ctx, uint8_t state );
371
372#ifdef __cplusplus
373}
374#endif
375#endif // _MRAM2_H_
376
377 // End public_function group
379
380// ------------------------------------------------------------------------- END
void mram2_write(mram2_t *ctx, uint32_t mem_adr, uint8_t *wr_data, uint8_t n_bytes)
Write Data Bytes function.
uint32_t mram2_tdet(mram2_t *ctx)
Tamper Detect (TDET) function.
void mram2_wake(mram2_t *ctx)
Exit Sleep Mode function.
void mram2_wren(mram2_t *ctx)
Write Enable function.
void mram2_write_protect(mram2_t *ctx, uint8_t state)
Write Protect function.
void mram2_wrsr(mram2_t *ctx, uint8_t stat_reg)
Write Status Register function.
void mram2_hold(mram2_t *ctx, uint8_t state)
Hold function.
void mram2_cfg_setup(mram2_cfg_t *cfg)
Config Object Initialization function.
void mram2_tdetx(mram2_t *ctx)
Tamper Detect Exit function.
uint8_t mram2_rdsr(mram2_t *ctx)
Read Status Register function.
err_t mram2_init(mram2_t *ctx, mram2_cfg_t *cfg)
Initialization function.
void mram2_read(mram2_t *ctx, uint32_t mem_adr, uint8_t *rd_data, uint8_t n_bytes)
Read Data Bytes function.
void mram2_wrdi(mram2_t *ctx)
Write Disable function.
void mram2_rdid(mram2_t *ctx, uint8_t *rd_id)
Read ID function.
void mram2_fread(mram2_t *ctx, uint32_t mem_adr, uint8_t mode, uint8_t *rd_data, uint8_t n_bytes)
Fast Read Data Bytes function.
void mram2_sleep(mram2_t *ctx)
Enter Sleep Mode function.
Click configuration structure definition.
Definition mram2.h:162
spi_master_chip_select_polarity_t cs_polarity
Definition mram2.h:179
pin_name_t sck
Definition mram2.h:167
spi_master_mode_t spi_mode
Definition mram2.h:178
pin_name_t mosi
Definition mram2.h:166
uint32_t spi_speed
Definition mram2.h:177
pin_name_t int_pin
Definition mram2.h:173
pin_name_t miso
Definition mram2.h:165
pin_name_t rst
Definition mram2.h:172
pin_name_t cs
Definition mram2.h:168
Click ctx object definition.
Definition mram2.h:144
digital_out_t cs
Definition mram2.h:145
spi_master_t spi
Definition mram2.h:153
digital_out_t int_pin
Definition mram2.h:149
digital_out_t rst
Definition mram2.h:148
pin_name_t chip_select
Definition mram2.h:154