eeram3 2.0.0.0
eeram3.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 EERAM3_H
29#define EERAM3_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#include "spi_specifics.h"
53
74#define EERAM3_OPCODE_WREN 0x06
75#define EERAM3_OPCODE_WRDI 0x04
76#define EERAM3_OPCODE_WRITE 0x02
77#define EERAM3_OPCODE_READ 0x03
78#define EERAM3_OPCODE_RDLSWA 0x0A
79#define EERAM3_OPCODE_SECURE_WRITE 0x12
80#define EERAM3_OPCODE_SECURE_READ 0x13
81#define EERAM3_OPCODE_WRSR 0x01
82#define EERAM3_OPCODE_RDSR 0x05
83#define EERAM3_OPCODE_STORE 0x08
84#define EERAM3_OPCODE_RECALL 0x09
85#define EERAM3_OPCODE_WRNUR 0xC2
86#define EERAM3_OPCODE_RDNUR 0xC3
87#define EERAM3_OPCODE_HIBERNATE 0xB9
88
89 // eeram3_reg
90
105#define EERAM3_RDY_BIT_MASK 0x01
106#define EERAM3_WEL_BIT_MASK 0x02
107#define EERAM3_BLOCK_PROTECT_BITS_MASK 0x0C
108#define EERAM3_BLOCK_PROTECT_NONE 0x00
109#define EERAM3_BLOCK_PROTECT_UPPER_QUARTER 0x04
110#define EERAM3_BLOCK_PROTECT_UPPER_HALF 0x08
111#define EERAM3_BLOCK_PROTECT_ALL 0x0C
112#define EERAM3_SWM_BIT_MASK 0x10
113#define EERAM3_PRO_BIT_MASK 0x20
114#define EERAM3_ASE_BIT_MASK 0x40
115
120#define EERAM3_MIN_ADDRESS 0x0000
121#define EERAM3_MAX_ADDRESS 0x7FFF
122#define EERAM3_MAX_PAGE_ADDRESS 0x3F
123
132#define EERAM3_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
133#define EERAM3_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
134
135 // eeram3_set
136
151#define EERAM3_MAP_MIKROBUS( cfg, mikrobus ) \
152 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
153 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
154 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
155 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
156 cfg.hld = MIKROBUS( mikrobus, MIKROBUS_INT )
157
158 // eeram3_map
159 // eeram3
160
165typedef struct
166{
167 // Output pins
168 digital_out_t hld;
170 // Modules
171 spi_master_t spi;
173 pin_name_t chip_select;
175} eeram3_t;
176
181typedef struct
182{
183 // Communication gpio pins
184 pin_name_t miso;
185 pin_name_t mosi;
186 pin_name_t sck;
187 pin_name_t cs;
189 // Additional gpio pins
190 pin_name_t hld;
192 // static variable
193 uint32_t spi_speed;
194 spi_master_mode_t spi_mode;
195 spi_master_chip_select_polarity_t cs_polarity;
198
203typedef enum
204{
206 EERAM3_ERROR = -1
207
209
226
241err_t eeram3_init ( eeram3_t *ctx, eeram3_cfg_t *cfg );
242
254
267err_t eeram3_write_opcode ( eeram3_t *ctx, uint8_t opcode );
268
284err_t eeram3_read_opcode ( eeram3_t *ctx, uint8_t opcode, uint8_t *data_out, uint8_t len );
285
295void eeram3_set_hld_pin ( eeram3_t *ctx, uint8_t state );
296
309
322
338err_t eeram3_set_block_protection ( eeram3_t *ctx, uint8_t block_protect );
339
352err_t eeram3_write_status ( eeram3_t *ctx, uint8_t status );
353
366err_t eeram3_read_status ( eeram3_t *ctx, uint8_t *status );
367
380
390
406err_t eeram3_memory_write ( eeram3_t *ctx, uint16_t address, uint8_t *data_in, uint16_t len );
407
423err_t eeram3_memory_read ( eeram3_t *ctx, uint16_t address, uint8_t *data_out, uint16_t len );
424
440err_t eeram3_memory_secure_write ( eeram3_t *ctx, uint16_t address, uint8_t *data_in, uint8_t len );
441
457err_t eeram3_memory_secure_read ( eeram3_t *ctx, uint16_t address, uint8_t *data_out, uint8_t len );
458
471err_t eeram3_read_last_written_address ( eeram3_t *ctx, uint16_t *address );
472
486err_t eeram3_nv_user_space_write ( eeram3_t *ctx, uint16_t data_in );
487
501err_t eeram3_nv_user_space_read ( eeram3_t *ctx, uint16_t *data_out );
502
515
528
541
554
555#ifdef __cplusplus
556}
557#endif
558#endif // EERAM3_H
559
560 // eeram3
561
562// ------------------------------------------------------------------------ END
eeram3_return_value_t
EERAM 3 Click return value data.
Definition eeram3.h:204
@ EERAM3_ERROR
Definition eeram3.h:206
@ EERAM3_OK
Definition eeram3.h:205
err_t eeram3_write_status(eeram3_t *ctx, uint8_t status)
EERAM 3 write status function.
void eeram3_wakeup_from_hibernate(eeram3_t *ctx)
EERAM 3 wake up from hibernate function.
void eeram3_set_hld_pin(eeram3_t *ctx, uint8_t state)
EERAM 3 set HLD pin function.
err_t eeram3_store_data(eeram3_t *ctx)
EERAM 3 store data function.
err_t eeram3_memory_secure_read(eeram3_t *ctx, uint16_t address, uint8_t *data_out, uint8_t len)
EERAM 3 memory secure read function.
void eeram3_default_cfg(eeram3_t *ctx)
EERAM 3 default configuration function.
err_t eeram3_memory_read(eeram3_t *ctx, uint16_t address, uint8_t *data_out, uint16_t len)
EERAM 3 memory read function.
err_t eeram3_nv_user_space_write(eeram3_t *ctx, uint16_t data_in)
EERAM 3 nv user space write function.
err_t eeram3_recall_data(eeram3_t *ctx)
EERAM 3 recall data function.
err_t eeram3_memory_write(eeram3_t *ctx, uint16_t address, uint8_t *data_in, uint16_t len)
EERAM 3 memory write function.
err_t eeram3_enable_write(eeram3_t *ctx)
EERAM 3 enable write function.
err_t eeram3_disable_write(eeram3_t *ctx)
EERAM 3 disable write function.
err_t eeram3_nv_user_space_read(eeram3_t *ctx, uint16_t *data_out)
EERAM 3 nv user space read function.
err_t eeram3_set_block_protection(eeram3_t *ctx, uint8_t block_protect)
EERAM 3 set block protection function.
err_t eeram3_init(eeram3_t *ctx, eeram3_cfg_t *cfg)
EERAM 3 initialization function.
void eeram3_cfg_setup(eeram3_cfg_t *cfg)
EERAM 3 configuration object setup function.
err_t eeram3_write_opcode(eeram3_t *ctx, uint8_t opcode)
EERAM 3 write opcode function.
err_t eeram3_autostore_disable(eeram3_t *ctx)
EERAM 3 autostore disable function.
err_t eeram3_read_status(eeram3_t *ctx, uint8_t *status)
EERAM 3 read status function.
err_t eeram3_autostore_enable(eeram3_t *ctx)
EERAM 3 autostore enable function.
err_t eeram3_read_opcode(eeram3_t *ctx, uint8_t opcode, uint8_t *data_out, uint8_t len)
EERAM 3 read opcode function.
err_t eeram3_enter_hibernate_mode(eeram3_t *ctx)
EERAM 3 enter hibernate mode function.
err_t eeram3_read_last_written_address(eeram3_t *ctx, uint16_t *address)
EERAM 3 read last written address function.
err_t eeram3_memory_secure_write(eeram3_t *ctx, uint16_t address, uint8_t *data_in, uint8_t len)
EERAM 3 memory write function.
This file contains SPI specific macros, functions, etc.
EERAM 3 Click configuration object.
Definition eeram3.h:182
pin_name_t hld
Definition eeram3.h:190
spi_master_chip_select_polarity_t cs_polarity
Definition eeram3.h:195
pin_name_t sck
Definition eeram3.h:186
spi_master_mode_t spi_mode
Definition eeram3.h:194
pin_name_t mosi
Definition eeram3.h:185
uint32_t spi_speed
Definition eeram3.h:193
pin_name_t miso
Definition eeram3.h:184
pin_name_t cs
Definition eeram3.h:187
EERAM 3 Click context object.
Definition eeram3.h:166
digital_out_t hld
Definition eeram3.h:168
spi_master_t spi
Definition eeram3.h:171
pin_name_t chip_select
Definition eeram3.h:173