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
35#include "drv_digital_out.h"
36#include "drv_digital_in.h"
37#include "drv_spi_master.h"
38#include "spi_specifics.h"
39
60#define SRAM4_REG_RDSR 0x05/*< Read status register*/
61#define SRAM4_REG_FAST_RDSR 0x09/*< Fast Read status register*/
62#define SRAM4_REG_WRSR 0x01/*< Write status register*/
63#define SRAM4_REG_WREN 0x06/*< Set write enable latch*/
64#define SRAM4_REG_WRDI 0x04/*< Reset write enable latch*/
65#define SRAM4_REG_READ 0x03/*< Read data from memory array*/
66#define SRAM4_REG_FAST_READ 0x0B/*< Fast read data*/
67#define SRAM4_REG_WRITE 0x02/*< Write data to memory array*/
68#define SRAM4_REG_STORE 0x3C/*< Software STORE*/
69#define SRAM4_REG_RECALL 0x60/*< Software RECALL*/
70#define SRAM4_REG_ASENB 0x59/*< AutoStore Enable*/
71#define SRAM4_REG_ASDISB 0x19/*< AutoStore Disable*/
72#define SRAM4_REG_SLEEP 0xB9/*< Sleep mode enable*/
73#define SRAM4_REG_WRSN 0xC2/*< Write serial number*/
74#define SRAM4_REG_RDSN 0xC3/*< Read serial number*/
75#define SRAM4_REG_FAST_RDSN 0xC9/*< Fast serial number read*/
76#define SRAM4_REG_RDID 0x9F/*< Read ID's*/
77#define SRAM4_REG_FAST_RDID 0x9E/*< Fast read ID's*/
78 // sram4_reg
80
95#define SRAM4_DEVICE_ID 0x06818818
96
105#define SRAM4_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
106#define SRAM4_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
107 // sram4_set
109
124#define SRAM4_MAP_MIKROBUS( cfg, mikrobus ) \
125 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
126 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
127 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
128 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
129 cfg.hold = MIKROBUS( mikrobus, MIKROBUS_PWM );
130 // sram4_map // sram4
133
138typedef struct
139{
140 // Output pins
141 digital_out_t hold;
143 // Modules
144 spi_master_t spi;
146 pin_name_t chip_select;
147 uint32_t device_id;
149} sram4_t;
150
155typedef struct
156{
157 // Communication gpio pins
158 pin_name_t miso;
159 pin_name_t mosi;
160 pin_name_t sck;
161 pin_name_t cs;
163 // Additional gpio pins
164 pin_name_t hold;
166 // static variable
167 uint32_t spi_speed;
168 spi_master_mode_t spi_mode;
169 spi_master_chip_select_polarity_t cs_polarity;
172
177typedef enum
178{
180 SRAM4_ERROR = -1
181
183
200
215err_t sram4_init ( sram4_t *ctx, sram4_cfg_t *cfg );
216
231
243err_t sram4_generic_command ( sram4_t *ctx, uint8_t cmd );
244
259err_t sram4_generic_write ( sram4_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
260
275err_t sram4_generic_read ( sram4_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
276
292err_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 );
293
307err_t sram4_memory_write ( sram4_t *ctx, uint16_t memory_adr, uint8_t *write_data, uint8_t write_len );
308
322err_t sram4_memory_read ( sram4_t *ctx, uint16_t memory_adr, uint8_t *read_data, uint8_t read_len );
323
332void sram4_set_hold ( sram4_t *ctx, uint8_t state );
333
334#ifdef __cplusplus
335}
336#endif
337#endif // SRAM4_H
338 // sram4
340
341// ------------------------------------------------------------------------ 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:178
@ SRAM4_ERROR
Definition: sram4.h:180
@ SRAM4_OK
Definition: sram4.h:179
SRAM 4 Click configuration object.
Definition: sram4.h:156
spi_master_chip_select_polarity_t cs_polarity
Definition: sram4.h:169
pin_name_t sck
Definition: sram4.h:160
spi_master_mode_t spi_mode
Definition: sram4.h:168
pin_name_t mosi
Definition: sram4.h:159
uint32_t spi_speed
Definition: sram4.h:167
pin_name_t miso
Definition: sram4.h:158
pin_name_t hold
Definition: sram4.h:164
pin_name_t cs
Definition: sram4.h:161
SRAM 4 Click context object.
Definition: sram4.h:139
spi_master_t spi
Definition: sram4.h:144
digital_out_t hold
Definition: sram4.h:141
uint32_t device_id
Definition: sram4.h:147
pin_name_t chip_select
Definition: sram4.h:146