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
32 extern "C"{
33 #endif
34 
35 #include "mikrosdk_version.h"
36 
37 #ifdef __GNUC__
38 #if mikroSDK_GET_VERSION < 20800ul
39 #include "rcu_delays.h"
40 #else
41 #include "delays.h"
42 #endif
43 #endif
44 
45 #include "drv_digital_out.h"
46 #include "drv_digital_in.h"
47 #include "drv_spi_master.h"
48 #include "spi_specifics.h"
49 
70 #define SRAM4_REG_RDSR 0x05/*< Read status register*/
71 #define SRAM4_REG_FAST_RDSR 0x09/*< Fast Read status register*/
72 #define SRAM4_REG_WRSR 0x01/*< Write status register*/
73 #define SRAM4_REG_WREN 0x06/*< Set write enable latch*/
74 #define SRAM4_REG_WRDI 0x04/*< Reset write enable latch*/
75 #define SRAM4_REG_READ 0x03/*< Read data from memory array*/
76 #define SRAM4_REG_FAST_READ 0x0B/*< Fast read data*/
77 #define SRAM4_REG_WRITE 0x02/*< Write data to memory array*/
78 #define SRAM4_REG_STORE 0x3C/*< Software STORE*/
79 #define SRAM4_REG_RECALL 0x60/*< Software RECALL*/
80 #define SRAM4_REG_ASENB 0x59/*< AutoStore Enable*/
81 #define SRAM4_REG_ASDISB 0x19/*< AutoStore Disable*/
82 #define SRAM4_REG_SLEEP 0xB9/*< Sleep mode enable*/
83 #define SRAM4_REG_WRSN 0xC2/*< Write serial number*/
84 #define SRAM4_REG_RDSN 0xC3/*< Read serial number*/
85 #define SRAM4_REG_FAST_RDSN 0xC9/*< Fast serial number read*/
86 #define SRAM4_REG_RDID 0x9F/*< Read ID's*/
87 #define SRAM4_REG_FAST_RDID 0x9E/*< Fast read ID's*/
88  // sram4_reg
90 
105 #define SRAM4_DEVICE_ID 0x06818818
106 
115 #define SRAM4_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
116 #define SRAM4_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
117  // sram4_set
119 
134 #define SRAM4_MAP_MIKROBUS( cfg, mikrobus ) \
135  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
136  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
137  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
138  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
139  cfg.hold = MIKROBUS( mikrobus, MIKROBUS_PWM );
140  // sram4_map // sram4
143 
148 typedef struct
149 {
150  // Output pins
151  digital_out_t hold;
153  // Modules
154  spi_master_t spi;
156  pin_name_t chip_select;
157  uint32_t device_id;
159 } sram4_t;
160 
165 typedef struct
166 {
167  // Communication gpio pins
168  pin_name_t miso;
169  pin_name_t mosi;
170  pin_name_t sck;
171  pin_name_t cs;
173  // Additional gpio pins
174  pin_name_t hold;
176  // static variable
177  uint32_t spi_speed;
178  spi_master_mode_t spi_mode;
179  spi_master_chip_select_polarity_t cs_polarity;
181 } sram4_cfg_t;
182 
187 typedef enum
188 {
189  SRAM4_OK = 0,
190  SRAM4_ERROR = -1
191 
193 
210 
225 err_t sram4_init ( sram4_t *ctx, sram4_cfg_t *cfg );
226 
240 err_t sram4_default_cfg ( sram4_t *ctx );
241 
253 err_t sram4_generic_command ( sram4_t *ctx, uint8_t cmd );
254 
269 err_t sram4_generic_write ( sram4_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
270 
285 err_t sram4_generic_read ( sram4_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
286 
302 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 );
303 
317 err_t sram4_memory_write ( sram4_t *ctx, uint16_t memory_adr, uint8_t *write_data, uint8_t write_len );
318 
332 err_t sram4_memory_read ( sram4_t *ctx, uint16_t memory_adr, uint8_t *read_data, uint8_t read_len );
333 
342 void sram4_set_hold ( sram4_t *ctx, uint8_t state );
343 
344 #ifdef __cplusplus
345 }
346 #endif
347 #endif // SRAM4_H
348  // sram4
350 
351 // ------------------------------------------------------------------------ END
sram4_cfg_t::miso
pin_name_t miso
Definition: sram4.h:168
sram4_cfg_t
SRAM 4 Click configuration object.
Definition: sram4.h:166
sram4_t::spi
spi_master_t spi
Definition: sram4.h:154
sram4_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: sram4.h:179
sram4_t::device_id
uint32_t device_id
Definition: sram4.h:157
spi_specifics.h
This file contains SPI specific macros, functions, etc.
sram4_cfg_t::cs
pin_name_t cs
Definition: sram4.h:171
sram4_cfg_setup
void sram4_cfg_setup(sram4_cfg_t *cfg)
SRAM 4 configuration object setup function.
sram4_memory_write
err_t sram4_memory_write(sram4_t *ctx, uint16_t memory_adr, uint8_t *write_data, uint8_t write_len)
Write data to memory.
sram4_cfg_t::sck
pin_name_t sck
Definition: sram4.h:170
sram4_set_hold
void sram4_set_hold(sram4_t *ctx, uint8_t state)
Set HOLD pin state.
sram4_t
SRAM 4 Click context object.
Definition: sram4.h:149
sram4_memory_read
err_t sram4_memory_read(sram4_t *ctx, uint16_t memory_adr, uint8_t *read_data, uint8_t read_len)
Read data from memory.
sram4_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: sram4.h:178
sram4_init
err_t sram4_init(sram4_t *ctx, sram4_cfg_t *cfg)
SRAM 4 initialization function.
sram4_generic_write_then_read
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.
sram4_generic_command
err_t sram4_generic_command(sram4_t *ctx, uint8_t cmd)
SRAM 4 command writing function.
SRAM4_ERROR
@ SRAM4_ERROR
Definition: sram4.h:190
sram4_default_cfg
err_t sram4_default_cfg(sram4_t *ctx)
SRAM 4 default configuration function.
SRAM4_OK
@ SRAM4_OK
Definition: sram4.h:189
sram4_t::chip_select
pin_name_t chip_select
Definition: sram4.h:156
sram4_t::hold
digital_out_t hold
Definition: sram4.h:151
sram4_cfg_t::hold
pin_name_t hold
Definition: sram4.h:174
sram4_generic_read
err_t sram4_generic_read(sram4_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
SRAM 4 data reading function.
sram4_cfg_t::spi_speed
uint32_t spi_speed
Definition: sram4.h:177
sram4_return_value_t
sram4_return_value_t
SRAM 4 Click return value data.
Definition: sram4.h:188
sram4_generic_write
err_t sram4_generic_write(sram4_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
SRAM 4 data writing function.
sram4_cfg_t::mosi
pin_name_t mosi
Definition: sram4.h:169