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
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
78#define SRAM3_OPCODE_WREN 0x06
79#define SRAM3_OPCODE_WRDI 0x04
80#define SRAM3_OPCODE_RDSR 0x05
81#define SRAM3_OPCODE_WRSR 0x01
82#define SRAM3_OPCODE_READ 0x03
83#define SRAM3_OPCODE_SECURE_READ 0x13
84#define SRAM3_OPCODE_WRITE 0x02
85#define SRAM3_OPCODE_SECURE_WRITE 0x12
86#define SRAM3_OPCODE_STORE 0x08
87#define SRAM3_OPCODE_RECALL 0x09
88#define SRAM3_OPCODE_WRSNR 0xC2
89#define SRAM3_OPCODE_RDSNR 0xC3
90#define SRAM3_OPCODE_HIBERNATE 0xB9
91
96#define SRAM3_PROT_NONE 0x00
97#define SRAM3_PROT_QUART 0x04
98#define SRAM3_PROT_HALF 0x08
99#define SRAM3_PROT_ALL 0x0C
100
105#define SRAM3_STATS_RDY_BIT 0x01
106#define SRAM3_STATS_WEN_BIT 0x02
107#define SRAM3_STATS_SWM_BIT 0x10
108#define SRAM3_STATS_PDIS_BIT 0x40
109
114#define SRAM3_SERIAL_LEN 0x10
115#define SRAM3_SECURE_BUF_SIZE 0x80
116 // sram3_set
117
132#define SRAM3_MAP_MIKROBUS( cfg, mikrobus ) \
133 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
134 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
135 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
136 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
137 cfg.hold = MIKROBUS( mikrobus, MIKROBUS_PWM )
138
139 // sram3_map
140 // sram3
141
146typedef struct
147{
148 // Output pins
149 digital_out_t hold;
151 // Modules
152 spi_master_t spi;
154 pin_name_t chip_select;
156} sram3_t;
157
162typedef struct
163{
164 // Communication gpio pins
165 pin_name_t miso;
166 pin_name_t mosi;
167 pin_name_t sck;
168 pin_name_t cs;
170 // Additional gpio pins
171 pin_name_t hold;
173 // static variable
174 uint32_t spi_speed;
175 spi_master_mode_t spi_mode;
176 spi_master_chip_select_polarity_t cs_polarity;
179
184typedef enum
185{
187 SRAM3_ERROR = -1
188
190
207
222err_t sram3_init ( sram3_t *ctx, sram3_cfg_t *cfg );
223
239err_t sram3_generic_write ( sram3_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
240
256err_t sram3_generic_read ( sram3_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
257
268
279
290
301void sram3_write_status( sram3_t *ctx, uint8_t status );
302
313void sram3_protect_memory( sram3_t *ctx, uint8_t protect_range );
314
325
336
347
357void sram3_store( sram3_t *ctx );
358
369
380
390void sram3_hold( sram3_t *ctx );
391
402
413void sram3_read_serial( sram3_t *ctx, uint8_t *buf );
414
425void sram3_write_serial( sram3_t *ctx, uint8_t *buf );
426
427
440void sram3_read( sram3_t *ctx, uint32_t mem_adr, uint8_t *read_buf, uint8_t buf_size );
441
456err_t sram3_secure_read( sram3_t *ctx, uint32_t mem_adr, uint8_t *read_buf, uint8_t buf_size );
457
470void sram3_write( sram3_t *ctx, uint32_t mem_adr, uint8_t *write_buf, uint8_t buf_size );
471
485err_t sram3_secure_write( sram3_t *ctx, uint32_t mem_adr, uint8_t *write_buf, uint8_t buf_size );
486
487#ifdef __cplusplus
488}
489#endif
490#endif // SRAM3_H
491
492 // sram3
493
494// ------------------------------------------------------------------------ END
err_t sram3_generic_write(sram3_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
SRAM 3 data writing function.
void sram3_read_serial(sram3_t *ctx, uint8_t *buf)
SRAM 3 reading number function.
void sram3_hibernate_start(sram3_t *ctx)
SRAM 3 changing function.
void sram3_hibernate_stop(sram3_t *ctx)
SRAM 3 changing function.
void sram3_enable_pdis(sram3_t *ctx)
SRAM 3 set up enable function.
err_t sram3_generic_read(sram3_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
SRAM 3 data reading function.
void sram3_enable_write(sram3_t *ctx)
SRAM 3 enabling writing to memory function.
err_t sram3_secure_write(sram3_t *ctx, uint32_t mem_adr, uint8_t *write_buf, uint8_t buf_size)
SRAM 3 secure writing data function.
void sram3_store(sram3_t *ctx)
SRAM 3 relocation data function.
void sram3_hold(sram3_t *ctx)
SRAM 3 changing pin state function.
void sram3_disable_pdis(sram3_t *ctx)
SRAM 3 set up disable function.
void sram3_read(sram3_t *ctx, uint32_t mem_adr, uint8_t *read_buf, uint8_t buf_size)
SRAM 3 reading data function.
void sram3_protect_memory(sram3_t *ctx, uint8_t protect_range)
SRAM 3 secures memory function.
uint8_t sram3_read_status(sram3_t *ctx)
SRAM 3 reading function.
void sram3_write_serial(sram3_t *ctx, uint8_t *buf)
SRAM 3 writing number function.
void sram3_release_hold(sram3_t *ctx)
SRAM 3 changing pin state function.
err_t sram3_init(sram3_t *ctx, sram3_cfg_t *cfg)
SRAM 3 initialization function.
void sram3_cfg_setup(sram3_cfg_t *cfg)
SRAM 3 configuration object setup function.
void sram3_write(sram3_t *ctx, uint32_t mem_adr, uint8_t *write_buf, uint8_t buf_size)
SRAM 3 writing data function.
err_t sram3_secure_read(sram3_t *ctx, uint32_t mem_adr, uint8_t *read_buf, uint8_t buf_size)
SRAM 3 secure reading data function.
void sram3_recall(sram3_t *ctx)
SRAM 3 relocation data function.
void sram3_disable_write(sram3_t *ctx)
SRAM 3 disabling writing to memory function.
void sram3_write_status(sram3_t *ctx, uint8_t status)
SRAM 3 writing function.
uint8_t buf[10]
Definition main.c:30
sram3_return_value_t
SRAM 3 Click return value data.
Definition sram3.h:185
@ SRAM3_OK
Definition sram3.h:186
@ SRAM3_ERROR
Definition sram3.h:187
SRAM 3 Click configuration object.
Definition sram3.h:163
spi_master_chip_select_polarity_t cs_polarity
Definition sram3.h:176
pin_name_t sck
Definition sram3.h:167
spi_master_mode_t spi_mode
Definition sram3.h:175
pin_name_t mosi
Definition sram3.h:166
uint32_t spi_speed
Definition sram3.h:174
pin_name_t miso
Definition sram3.h:165
pin_name_t hold
Definition sram3.h:171
pin_name_t cs
Definition sram3.h:168
SRAM 3 Click context object.
Definition sram3.h:147
spi_master_t spi
Definition sram3.h:152
digital_out_t hold
Definition sram3.h:149
pin_name_t chip_select
Definition sram3.h:154