sram4 2.0.0.0
sram4.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 SRAM4_H
29#define SRAM4_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 SRAM4_REG_RDSR 0x05/*< Read status register*/
75#define SRAM4_REG_FAST_RDSR 0x09/*< Fast Read status register*/
76#define SRAM4_REG_WRSR 0x01/*< Write status register*/
77#define SRAM4_REG_WREN 0x06/*< Set write enable latch*/
78#define SRAM4_REG_WRDI 0x04/*< Reset write enable latch*/
79#define SRAM4_REG_READ 0x03/*< Read data from memory array*/
80#define SRAM4_REG_FAST_READ 0x0B/*< Fast read data*/
81#define SRAM4_REG_WRITE 0x02/*< Write data to memory array*/
82#define SRAM4_REG_STORE 0x3C/*< Software STORE*/
83#define SRAM4_REG_RECALL 0x60/*< Software RECALL*/
84#define SRAM4_REG_ASENB 0x59/*< AutoStore Enable*/
85#define SRAM4_REG_ASDISB 0x19/*< AutoStore Disable*/
86#define SRAM4_REG_SLEEP 0xB9/*< Sleep mode enable*/
87#define SRAM4_REG_WRSN 0xC2/*< Write serial number*/
88#define SRAM4_REG_RDSN 0xC3/*< Read serial number*/
89#define SRAM4_REG_FAST_RDSN 0xC9/*< Fast serial number read*/
90#define SRAM4_REG_RDID 0x9F/*< Read ID's*/
91#define SRAM4_REG_FAST_RDID 0x9E/*< Fast read ID's*/
92
93 // sram4_reg
94
109#define SRAM4_DEVICE_ID 0x06818818
110
119#define SRAM4_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
120#define SRAM4_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
121
122 // sram4_set
123
138#define SRAM4_MAP_MIKROBUS( cfg, mikrobus ) \
139 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
140 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
141 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
142 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
143 cfg.hold = MIKROBUS( mikrobus, MIKROBUS_PWM );
144
145 // sram4_map
146 // sram4
147
152typedef struct
153{
154 // Output pins
155 digital_out_t hold;
157 // Modules
158 spi_master_t spi;
160 pin_name_t chip_select;
161 uint32_t device_id;
163} sram4_t;
164
169typedef struct
170{
171 // Communication gpio pins
172 pin_name_t miso;
173 pin_name_t mosi;
174 pin_name_t sck;
175 pin_name_t cs;
177 // Additional gpio pins
178 pin_name_t hold;
180 // static variable
181 uint32_t spi_speed;
182 spi_master_mode_t spi_mode;
183 spi_master_chip_select_polarity_t cs_polarity;
186
191typedef enum
192{
194 SRAM4_ERROR = -1
195
197
214
229err_t sram4_init ( sram4_t *ctx, sram4_cfg_t *cfg );
230
245
257err_t sram4_generic_command ( sram4_t *ctx, uint8_t cmd );
258
273err_t sram4_generic_write ( sram4_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
274
289err_t sram4_generic_read ( sram4_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
290
306err_t sram4_generic_write_then_read ( sram4_t *ctx, uint8_t *data_in, uint8_t in_len, uint8_t *data_out, uint8_t out_len );
307
321err_t sram4_memory_write ( sram4_t *ctx, uint16_t memory_adr, uint8_t *write_data, uint8_t write_len );
322
336err_t sram4_memory_read ( sram4_t *ctx, uint16_t memory_adr, uint8_t *read_data, uint8_t read_len );
337
346void sram4_set_hold ( sram4_t *ctx, uint8_t state );
347
348#ifdef __cplusplus
349}
350#endif
351#endif // SRAM4_H
352
353 // sram4
354
355// ------------------------------------------------------------------------ END
err_t sram4_generic_read(sram4_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
SRAM 4 data reading function.
err_t sram4_default_cfg(sram4_t *ctx)
SRAM 4 default configuration function.
err_t sram4_generic_write_then_read(sram4_t *ctx, uint8_t *data_in, uint8_t in_len, uint8_t *data_out, uint8_t out_len)
SRAM 4 data writing and reading function.
err_t sram4_init(sram4_t *ctx, sram4_cfg_t *cfg)
SRAM 4 initialization function.
void sram4_cfg_setup(sram4_cfg_t *cfg)
SRAM 4 configuration object setup function.
err_t sram4_generic_command(sram4_t *ctx, uint8_t cmd)
SRAM 4 command writing function.
void sram4_set_hold(sram4_t *ctx, uint8_t state)
Set HOLD pin state.
err_t sram4_memory_read(sram4_t *ctx, uint16_t memory_adr, uint8_t *read_data, uint8_t read_len)
Read data from memory.
err_t sram4_generic_write(sram4_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
SRAM 4 data writing function.
err_t sram4_memory_write(sram4_t *ctx, uint16_t memory_adr, uint8_t *write_data, uint8_t write_len)
Write data to memory.
This file contains SPI specific macros, functions, etc.
sram4_return_value_t
SRAM 4 Click return value data.
Definition sram4.h:192
@ SRAM4_ERROR
Definition sram4.h:194
@ SRAM4_OK
Definition sram4.h:193
SRAM 4 Click configuration object.
Definition sram4.h:170
spi_master_chip_select_polarity_t cs_polarity
Definition sram4.h:183
pin_name_t sck
Definition sram4.h:174
spi_master_mode_t spi_mode
Definition sram4.h:182
pin_name_t mosi
Definition sram4.h:173
uint32_t spi_speed
Definition sram4.h:181
pin_name_t miso
Definition sram4.h:172
pin_name_t hold
Definition sram4.h:178
pin_name_t cs
Definition sram4.h:175
SRAM 4 Click context object.
Definition sram4.h:153
spi_master_t spi
Definition sram4.h:158
digital_out_t hold
Definition sram4.h:155
uint32_t device_id
Definition sram4.h:161
pin_name_t chip_select
Definition sram4.h:160