sram3  2.0.0.0
sram3.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 SRAM3_H
29 #define SRAM3_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
35 #include "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_spi_master.h"
38 
64 #define SRAM3_OPCODE_WREN 0x06
65 #define SRAM3_OPCODE_WRDI 0x04
66 #define SRAM3_OPCODE_RDSR 0x05
67 #define SRAM3_OPCODE_WRSR 0x01
68 #define SRAM3_OPCODE_READ 0x03
69 #define SRAM3_OPCODE_SECURE_READ 0x13
70 #define SRAM3_OPCODE_WRITE 0x02
71 #define SRAM3_OPCODE_SECURE_WRITE 0x12
72 #define SRAM3_OPCODE_STORE 0x08
73 #define SRAM3_OPCODE_RECALL 0x09
74 #define SRAM3_OPCODE_WRSNR 0xC2
75 #define SRAM3_OPCODE_RDSNR 0xC3
76 #define SRAM3_OPCODE_HIBERNATE 0xB9
77 
82 #define SRAM3_PROT_NONE 0x00
83 #define SRAM3_PROT_QUART 0x04
84 #define SRAM3_PROT_HALF 0x08
85 #define SRAM3_PROT_ALL 0x0C
86 
91 #define SRAM3_STATS_RDY_BIT 0x01
92 #define SRAM3_STATS_WEN_BIT 0x02
93 #define SRAM3_STATS_SWM_BIT 0x10
94 #define SRAM3_STATS_PDIS_BIT 0x40
95 
100 #define SRAM3_SERIAL_LEN 0x10
101 #define SRAM3_SECURE_BUF_SIZE 0x80
102  // sram3_set
103 
118 #define SRAM3_MAP_MIKROBUS( cfg, mikrobus ) \
119  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
120  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
121  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
122  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
123  cfg.hold = MIKROBUS( mikrobus, MIKROBUS_PWM )
124  // sram3_map // sram3
127 
132 typedef struct
133 {
134  // Output pins
135  digital_out_t hold;
137  // Modules
138  spi_master_t spi;
140  pin_name_t chip_select;
142 } sram3_t;
143 
148 typedef struct
149 {
150  // Communication gpio pins
151  pin_name_t miso;
152  pin_name_t mosi;
153  pin_name_t sck;
154  pin_name_t cs;
156  // Additional gpio pins
157  pin_name_t hold;
159  // static variable
160  uint32_t spi_speed;
161  spi_master_mode_t spi_mode;
162  spi_master_chip_select_polarity_t cs_polarity;
164 } sram3_cfg_t;
165 
170 typedef enum
171 {
172  SRAM3_OK = 0,
173  SRAM3_ERROR = -1
174 
176 
193 
208 err_t sram3_init ( sram3_t *ctx, sram3_cfg_t *cfg );
209 
225 err_t sram3_generic_write ( sram3_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
226 
242 err_t sram3_generic_read ( sram3_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
243 
254 
265 
275 uint8_t sram3_read_status( sram3_t *ctx );
276 
287 void sram3_write_status( sram3_t *ctx, uint8_t status );
288 
299 void sram3_protect_memory( sram3_t *ctx, uint8_t protect_range );
300 
311 
322 
332 void sram3_recall( sram3_t *ctx );
333 
343 void sram3_store( sram3_t *ctx );
344 
355 
366 
376 void sram3_hold( sram3_t *ctx );
377 
388 
399 void sram3_read_serial( sram3_t *ctx, uint8_t *buf );
400 
411 void sram3_write_serial( sram3_t *ctx, uint8_t *buf );
412 
413 
426 void sram3_read( sram3_t *ctx, uint32_t mem_adr, uint8_t *read_buf, uint8_t buf_size );
427 
439 err_t sram3_secure_read( sram3_t *ctx, uint32_t mem_adr, uint8_t *read_buf );
440 
453 void sram3_write( sram3_t *ctx, uint32_t mem_adr, uint8_t *write_buf, uint8_t buf_size );
454 
467 err_t sram3_secure_write( sram3_t *ctx, uint32_t mem_adr, uint8_t *write_buf );
468 
469 #ifdef __cplusplus
470 }
471 #endif
472 #endif // SRAM3_H
473  // sram3
475 
476 // ------------------------------------------------------------------------ END
sram3_cfg_t::cs
pin_name_t cs
Definition: sram3.h:154
sram3_write_serial
void sram3_write_serial(sram3_t *ctx, uint8_t *buf)
SRAM 3 writing number function.
sram3_read_serial
void sram3_read_serial(sram3_t *ctx, uint8_t *buf)
SRAM 3 reading number function.
sram3_cfg_t::hold
pin_name_t hold
Definition: sram3.h:157
sram3_secure_write
err_t sram3_secure_write(sram3_t *ctx, uint32_t mem_adr, uint8_t *write_buf)
SRAM 3 secure writing data function.
sram3_secure_read
err_t sram3_secure_read(sram3_t *ctx, uint32_t mem_adr, uint8_t *read_buf)
SRAM 3 secure reading data function.
sram3_cfg_t
SRAM 3 Click configuration object.
Definition: sram3.h:149
sram3_disable_pdis
void sram3_disable_pdis(sram3_t *ctx)
SRAM 3 set up disable function.
sram3_t::spi
spi_master_t spi
Definition: sram3.h:138
sram3_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: sram3.h:161
sram3_cfg_t::miso
pin_name_t miso
Definition: sram3.h:151
sram3_hibernate_stop
void sram3_hibernate_stop(sram3_t *ctx)
SRAM 3 changing function.
sram3_enable_pdis
void sram3_enable_pdis(sram3_t *ctx)
SRAM 3 set up enable function.
sram3_hold
void sram3_hold(sram3_t *ctx)
SRAM 3 changing pin state function.
sram3_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: sram3.h:162
sram3_release_hold
void sram3_release_hold(sram3_t *ctx)
SRAM 3 changing pin state function.
sram3_write_status
void sram3_write_status(sram3_t *ctx, uint8_t status)
SRAM 3 writing function.
sram3_read
void sram3_read(sram3_t *ctx, uint32_t mem_adr, uint8_t *read_buf, uint8_t buf_size)
SRAM 3 reading data function.
sram3_t
SRAM 3 Click context object.
Definition: sram3.h:133
sram3_hibernate_start
void sram3_hibernate_start(sram3_t *ctx)
SRAM 3 changing function.
sram3_recall
void sram3_recall(sram3_t *ctx)
SRAM 3 relocation data function.
sram3_init
err_t sram3_init(sram3_t *ctx, sram3_cfg_t *cfg)
SRAM 3 initialization function.
sram3_cfg_t::sck
pin_name_t sck
Definition: sram3.h:153
SRAM3_OK
@ SRAM3_OK
Definition: sram3.h:172
sram3_generic_read
err_t sram3_generic_read(sram3_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
SRAM 3 data reading function.
sram3_read_status
uint8_t sram3_read_status(sram3_t *ctx)
SRAM 3 reading function.
sram3_store
void sram3_store(sram3_t *ctx)
SRAM 3 relocation data function.
sram3_cfg_t::spi_speed
uint32_t spi_speed
Definition: sram3.h:160
sram3_write
void sram3_write(sram3_t *ctx, uint32_t mem_adr, uint8_t *write_buf, uint8_t buf_size)
SRAM 3 writing data function.
sram3_generic_write
err_t sram3_generic_write(sram3_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
SRAM 3 data writing function.
SRAM3_ERROR
@ SRAM3_ERROR
Definition: sram3.h:173
sram3_t::chip_select
pin_name_t chip_select
Definition: sram3.h:140
sram3_cfg_t::mosi
pin_name_t mosi
Definition: sram3.h:152
buf
uint8_t buf[10]
Definition: main.c:30
sram3_protect_memory
void sram3_protect_memory(sram3_t *ctx, uint8_t protect_range)
SRAM 3 secures memory function.
sram3_disable_write
void sram3_disable_write(sram3_t *ctx)
SRAM 3 disabling writing to memory function.
sram3_cfg_setup
void sram3_cfg_setup(sram3_cfg_t *cfg)
SRAM 3 configuration object setup function.
sram3_return_value_t
sram3_return_value_t
SRAM 3 Click return value data.
Definition: sram3.h:171
sram3_t::hold
digital_out_t hold
Definition: sram3.h:135
sram3_enable_write
void sram3_enable_write(sram3_t *ctx)
SRAM 3 enabling writing to memory function.