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 
38 #include "drv_digital_out.h"
39 #include "drv_digital_in.h"
40 #include "drv_spi_master.h"
41 
42 // -------------------------------------------------------------- PUBLIC MACROS
53 #define EERAM2_MAP_MIKROBUS( cfg, mikrobus ) \
54  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
55  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
56  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
57  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
58  cfg.hld = MIKROBUS( mikrobus, MIKROBUS_PWM )
59 
65 #define EERAM2_RETVAL uint8_t
66 
67 #define EERAM2_OK 0x00
68 #define EERAM2_INIT_ERROR 0xFF
69 
75 #define EERAM2_CMD_WREN 0x06
76 #define EERAM2_CMD_WRDI 0x04
77 
83 #define EERAM2_CMD_WRITE 0x02
84 #define EERAM2_CMD_READ 0x03
85 #define EERAM2_CMD_SECURE_WRITE 0x12
86 #define EERAM2_CMD_SECURE_READ 0x13
87 
93 #define EERAM2_CMD_WRSR 0x01
94 #define EERAM2_CMD_RDSR 0x05
95 
101 #define EERAM2_CMD_STORE 0x08
102 #define EERAM2_CMD_RECALL 0x09
103 
109 #define EERAM2_CMD_WRNUR 0xC2
110 #define EERAM2_CMD_RDNUR 0xC3
111 
117 #define EERAM2_CMD_HIBERNATE 0xB9
118 
124 #define EERAM2_HOLD_DISABLE 0x00
125 #define EERAM2_HOLD_ENABLE 0x01
126 
132 #define EERAM2_WRITE_DISABLE 0x00
133 #define EERAM2_WRITE_ENABLE 0x01
134 
135 \
140 #define EERAM2_STATUS_ASE_ENABLE 0x00
141 #define EERAM2_STATUS_ASE_DISABLE 0x40
142 #define EERAM2_STATUS_BP_LVL_0 0x00
143 #define EERAM2_STATUS_BP_LVL_1 0x04
144 #define EERAM2_STATUS_BP_LVL_2 0x08
145 #define EERAM2_STATUS_BP_LVL_3 0x0C
146 
152 #define EERAM2_ERROR 0x00
153 #define EERAM2_SUCCESS 0x01
154 
160 #define EERAM2_SRAM_ADDR_FIRST 0x00000000
161 #define EERAM2_SRAM_ADDR_LAST 0x00FFFFFF
162  // End group macro
165 // --------------------------------------------------------------- PUBLIC TYPES
174 typedef struct
175 {
176  // Output pins
177  digital_out_t cs;
178  digital_out_t hld;
179 
180  // Modules
181 
182  spi_master_t spi;
183  pin_name_t chip_select;
184 
185 } eeram2_t;
186 
190 typedef struct
191 {
192  // Communication gpio pins
193 
194  pin_name_t miso;
195  pin_name_t mosi;
196  pin_name_t sck;
197  pin_name_t cs;
198 
199  // Additional gpio pins
200 
201  pin_name_t hld;
202 
203  // static variable
204 
205  uint32_t spi_speed;
206  spi_master_mode_t spi_mode;
207  spi_master_chip_select_polarity_t cs_polarity;
208 
209 } eeram2_cfg_t;
210  // End types group
212 
213 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
214 
219 #ifdef __cplusplus
220 extern "C"{
221 #endif
222 
232 
242 
254 void eeram2_generic_transfer ( eeram2_t *ctx, uint8_t *wr_buf, uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len );
255 
267 void eeram2_set_on_hold_status ( eeram2_t *ctx, uint8_t en_hold );
268 
278 void eeram2_set_command ( eeram2_t *ctx, uint8_t command );
279 
291 void eeram2_set_write_status ( eeram2_t *ctx, uint8_t en_write );
292 
310 void eeram2_set_status ( eeram2_t *ctx, uint8_t tx_data );
311 
340 uint8_t eeram2_get_status ( eeram2_t *ctx );
341 
358 uint8_t eeram2_write_byte ( eeram2_t *ctx, uint32_t reg, uint8_t tx_data );
359 
373 uint8_t eeram2_read_byte ( eeram2_t *ctx, uint32_t reg );
374 
393 uint8_t eeram2_write_continuous ( eeram2_t *ctx, uint32_t reg, uint8_t *p_tx_data, uint8_t n_bytes );
394 
413 uint8_t eeram2_read_continuous ( eeram2_t *ctx, uint32_t reg, uint8_t *p_rx_data, uint8_t n_bytes );
414 
428 uint8_t eeram2_read_nonvolatile ( eeram2_t *ctx, uint8_t *p_rx_data );
429 
443 uint8_t eeram2_write_nonvolatile ( eeram2_t *ctx, uint8_t *p_tx_data );
444 
459 uint8_t eeram2_secure_write ( eeram2_t *ctx, uint16_t reg, uint8_t *p_tx_data );
460 
474 uint8_t eeram2_secure_read ( eeram2_t *ctx, uint16_t reg, uint8_t *p_rx_data );
475 
476 #ifdef __cplusplus
477 }
478 #endif
479 #endif // _EERAM2_H_
480  // End public_function group
483 
484 // ------------------------------------------------------------------------- END
eeram2_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: eeram2.h:206
eeram2_cfg_t::spi_speed
uint32_t spi_speed
Definition: eeram2.h:205
eeram2_set_status
void eeram2_set_status(eeram2_t *ctx, uint8_t tx_data)
Set status register function.
eeram2_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: eeram2.h:207
eeram2_cfg_t::cs
pin_name_t cs
Definition: eeram2.h:197
eeram2_write_byte
uint8_t eeram2_write_byte(eeram2_t *ctx, uint32_t reg, uint8_t tx_data)
Write the data byte into SRAM function.
eeram2_init
EERAM2_RETVAL eeram2_init(eeram2_t *ctx, eeram2_cfg_t *cfg)
Initialization function.
eeram2_cfg_t::miso
pin_name_t miso
Definition: eeram2.h:194
eeram2_cfg_setup
void eeram2_cfg_setup(eeram2_cfg_t *cfg)
Config Object Initialization function.
eeram2_t::hld
digital_out_t hld
Definition: eeram2.h:178
eeram2_set_on_hold_status
void eeram2_set_on_hold_status(eeram2_t *ctx, uint8_t en_hold)
Set On-hold status function.
eeram2_t::spi
spi_master_t spi
Definition: eeram2.h:182
eeram2_t
Click ctx object definition.
Definition: eeram2.h:175
eeram2_generic_transfer
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.
eeram2_cfg_t
Click configuration structure definition.
Definition: eeram2.h:191
eeram2_read_byte
uint8_t eeram2_read_byte(eeram2_t *ctx, uint32_t reg)
Read the data byte from SRAM function.
EERAM2_RETVAL
#define EERAM2_RETVAL
Definition: eeram2.h:65
eeram2_write_nonvolatile
uint8_t eeram2_write_nonvolatile(eeram2_t *ctx, uint8_t *p_tx_data)
Nonvolatile user space read function.
eeram2_read_continuous
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.
eeram2_set_command
void eeram2_set_command(eeram2_t *ctx, uint8_t command)
Set command function.
eeram2_secure_write
uint8_t eeram2_secure_write(eeram2_t *ctx, uint16_t reg, uint8_t *p_tx_data)
Secure SRAM write function.
eeram2_cfg_t::hld
pin_name_t hld
Definition: eeram2.h:201
eeram2_write_continuous
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.
eeram2_t::cs
digital_out_t cs
Definition: eeram2.h:177
eeram2_set_write_status
void eeram2_set_write_status(eeram2_t *ctx, uint8_t en_write)
Set write status function.
eeram2_t::chip_select
pin_name_t chip_select
Definition: eeram2.h:183
eeram2_cfg_t::mosi
pin_name_t mosi
Definition: eeram2.h:195
eeram2_cfg_t::sck
pin_name_t sck
Definition: eeram2.h:196
eeram2_get_status
uint8_t eeram2_get_status(eeram2_t *ctx)
Read status register function.
eeram2_read_nonvolatile
uint8_t eeram2_read_nonvolatile(eeram2_t *ctx, uint8_t *p_rx_data)
Nonvolatile user space write function.
eeram2_secure_read
uint8_t eeram2_secure_read(eeram2_t *ctx, uint16_t reg, uint8_t *p_rx_data)
Secure SRAM read function.