eeram2 2.0.0.0
eeram2.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 EERAM2_H
36#define EERAM2_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 EERAM2_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.hld = MIKROBUS( mikrobus, MIKROBUS_PWM )
79#define EERAM2_RETVAL uint8_t
80
81#define EERAM2_OK 0x00
82#define EERAM2_INIT_ERROR 0xFF
89#define EERAM2_CMD_WREN 0x06
90#define EERAM2_CMD_WRDI 0x04
97#define EERAM2_CMD_WRITE 0x02
98#define EERAM2_CMD_READ 0x03
99#define EERAM2_CMD_SECURE_WRITE 0x12
100#define EERAM2_CMD_SECURE_READ 0x13
107#define EERAM2_CMD_WRSR 0x01
108#define EERAM2_CMD_RDSR 0x05
115#define EERAM2_CMD_STORE 0x08
116#define EERAM2_CMD_RECALL 0x09
123#define EERAM2_CMD_WRNUR 0xC2
124#define EERAM2_CMD_RDNUR 0xC3
131#define EERAM2_CMD_HIBERNATE 0xB9
138#define EERAM2_HOLD_DISABLE 0x00
139#define EERAM2_HOLD_ENABLE 0x01
146#define EERAM2_WRITE_DISABLE 0x00
147#define EERAM2_WRITE_ENABLE 0x01
149\
154#define EERAM2_STATUS_ASE_ENABLE 0x00
155#define EERAM2_STATUS_ASE_DISABLE 0x40
156#define EERAM2_STATUS_BP_LVL_0 0x00
157#define EERAM2_STATUS_BP_LVL_1 0x04
158#define EERAM2_STATUS_BP_LVL_2 0x08
159#define EERAM2_STATUS_BP_LVL_3 0x0C
166#define EERAM2_ERROR 0x00
167#define EERAM2_SUCCESS 0x01
174#define EERAM2_SRAM_ADDR_FIRST 0x00000000
175#define EERAM2_SRAM_ADDR_LAST 0x00FFFFFF
178 // End group macro
179// --------------------------------------------------------------- PUBLIC TYPES
188typedef struct
189{
190 // Output pins
191 digital_out_t cs;
192 digital_out_t hld;
193
194 // Modules
195
196 spi_master_t spi;
197 pin_name_t chip_select;
198
199} eeram2_t;
200
204typedef struct
205{
206 // Communication gpio pins
207
208 pin_name_t miso;
209 pin_name_t mosi;
210 pin_name_t sck;
211 pin_name_t cs;
212
213 // Additional gpio pins
214
215 pin_name_t hld;
216
217 // static variable
218
219 uint32_t spi_speed;
220 spi_master_mode_t spi_mode;
221 spi_master_chip_select_polarity_t cs_polarity;
222
224
225 // End types group
226
227// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
228
233#ifdef __cplusplus
234extern "C"{
235#endif
236
246
256
268void eeram2_generic_transfer ( eeram2_t *ctx, uint8_t *wr_buf, uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len );
269
281void eeram2_set_on_hold_status ( eeram2_t *ctx, uint8_t en_hold );
282
292void eeram2_set_command ( eeram2_t *ctx, uint8_t command );
293
305void eeram2_set_write_status ( eeram2_t *ctx, uint8_t en_write );
306
324void eeram2_set_status ( eeram2_t *ctx, uint8_t tx_data );
325
355
372uint8_t eeram2_write_byte ( eeram2_t *ctx, uint32_t reg, uint8_t tx_data );
373
387uint8_t eeram2_read_byte ( eeram2_t *ctx, uint32_t reg );
388
407uint8_t eeram2_write_continuous ( eeram2_t *ctx, uint32_t reg, uint8_t *p_tx_data, uint8_t n_bytes );
408
427uint8_t eeram2_read_continuous ( eeram2_t *ctx, uint32_t reg, uint8_t *p_rx_data, uint8_t n_bytes );
428
442uint8_t eeram2_read_nonvolatile ( eeram2_t *ctx, uint8_t *p_rx_data );
443
457uint8_t eeram2_write_nonvolatile ( eeram2_t *ctx, uint8_t *p_tx_data );
458
473uint8_t eeram2_secure_write ( eeram2_t *ctx, uint16_t reg, uint8_t *p_tx_data );
474
488uint8_t eeram2_secure_read ( eeram2_t *ctx, uint16_t reg, uint8_t *p_rx_data );
489
490#ifdef __cplusplus
491}
492#endif
493#endif // _EERAM2_H_
494
495 // End public_function group
497
498// ------------------------------------------------------------------------- END
#define EERAM2_RETVAL
Definition eeram2.h:79
void eeram2_cfg_setup(eeram2_cfg_t *cfg)
Config Object Initialization function.
void eeram2_set_on_hold_status(eeram2_t *ctx, uint8_t en_hold)
Set On-hold status function.
uint8_t eeram2_secure_write(eeram2_t *ctx, uint16_t reg, uint8_t *p_tx_data)
Secure SRAM write function.
EERAM2_RETVAL eeram2_init(eeram2_t *ctx, eeram2_cfg_t *cfg)
Initialization function.
uint8_t eeram2_read_continuous(eeram2_t *ctx, uint32_t reg, uint8_t *p_rx_data, uint8_t n_bytes)
Continuous read the data into SRAM function.
uint8_t eeram2_read_nonvolatile(eeram2_t *ctx, uint8_t *p_rx_data)
Nonvolatile user space write function.
uint8_t eeram2_read_byte(eeram2_t *ctx, uint32_t reg)
Read the data byte from SRAM function.
void eeram2_set_command(eeram2_t *ctx, uint8_t command)
Set command function.
uint8_t eeram2_secure_read(eeram2_t *ctx, uint16_t reg, uint8_t *p_rx_data)
Secure SRAM read function.
void eeram2_generic_transfer(eeram2_t *ctx, uint8_t *wr_buf, uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len)
Generic transfer function.
uint8_t eeram2_write_nonvolatile(eeram2_t *ctx, uint8_t *p_tx_data)
Nonvolatile user space read function.
void eeram2_set_status(eeram2_t *ctx, uint8_t tx_data)
Set status register function.
uint8_t eeram2_write_continuous(eeram2_t *ctx, uint32_t reg, uint8_t *p_tx_data, uint8_t n_bytes)
Continuous write the data into SRAM function.
uint8_t eeram2_get_status(eeram2_t *ctx)
Read status register function.
void eeram2_set_write_status(eeram2_t *ctx, uint8_t en_write)
Set write status function.
uint8_t eeram2_write_byte(eeram2_t *ctx, uint32_t reg, uint8_t tx_data)
Write the data byte into SRAM function.
Click configuration structure definition.
Definition eeram2.h:205
pin_name_t hld
Definition eeram2.h:215
spi_master_chip_select_polarity_t cs_polarity
Definition eeram2.h:221
pin_name_t sck
Definition eeram2.h:210
spi_master_mode_t spi_mode
Definition eeram2.h:220
pin_name_t mosi
Definition eeram2.h:209
uint32_t spi_speed
Definition eeram2.h:219
pin_name_t miso
Definition eeram2.h:208
pin_name_t cs
Definition eeram2.h:211
Click ctx object definition.
Definition eeram2.h:189
digital_out_t cs
Definition eeram2.h:191
digital_out_t hld
Definition eeram2.h:192
spi_master_t spi
Definition eeram2.h:196
pin_name_t chip_select
Definition eeram2.h:197