sram 2.0.0.0
sram.h
Go to the documentation of this file.
1/*
2 * MikroSDK - MikroE Software Development Kit
3 * Copyright© 2020 MikroElektronika d.o.o.
4 *
5 * Permission is hereby granted, free of charge, to any person
6 * obtaining a copy of this software and associated documentation
7 * files (the "Software"), to deal in the Software without restriction,
8 * including without limitation the rights to use, copy, modify, merge,
9 * publish, distribute, sublicense, and/or sell copies of the Software,
10 * and to permit persons to whom the Software is furnished to do so,
11 * subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
22 * OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
33// ----------------------------------------------------------------------------
34
35#ifndef SRAM_H
36#define SRAM_H
37
42#ifdef PREINIT_SUPPORTED
43#include "preinit.h"
44#endif
45
46#ifdef MikroCCoreVersion
47 #if MikroCCoreVersion >= 1
48 #include "delays.h"
49 #endif
50#endif
51
52#include "drv_digital_out.h"
53#include "drv_digital_in.h"
54#include "drv_spi_master.h"
55
56// -------------------------------------------------------------- PUBLIC MACROS
67#define SRAM_MAP_MIKROBUS( cfg, mikrobus ) \
68 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
69 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
70 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
71 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
72 cfg.hld = MIKROBUS( mikrobus, MIKROBUS_RST )
79#define SRAM_RETVAL uint8_t
80
81#define SRAM_OK 0x00
82#define SRAM_INIT_ERROR 0xFF
89#define SRAM_CMD_WRMR 0x01
90#define SRAM_CMD_WRITE 0x02
91#define SRAM_CMD_READ 0x03
92#define SRAM_CMD_RDMR 0x05
93#define SRAM_CMD_EQIO 0x38
94#define SRAM_CMD_EDIO 0x3B
95#define SRAM_CMD_RSTIO 0xFF
102#define SRAM_MODE_REG_BM 0x00
103#define SRAM_MODE_REG_PM 0x80
104#define SRAM_MODE_REG_SM 0x40
107 // End group macro
108// --------------------------------------------------------------- PUBLIC TYPES
117typedef struct
118{
119 // Output pins
120
121 digital_out_t hld;
122 digital_out_t cs;
123
124 // Modules
125
126 spi_master_t spi;
127 pin_name_t chip_select;
128
129} sram_t;
130
134typedef struct
135{
136 // Communication gpio pins
137
138 pin_name_t miso;
139 pin_name_t mosi;
140 pin_name_t sck;
141 pin_name_t cs;
142
143 // Additional gpio pins
144
145 pin_name_t hld;
146
147 // static variable
148
149 uint32_t spi_speed;
150 uint8_t spi_mode;
151 spi_master_chip_select_polarity_t cs_polarity;
152
153} sram_cfg_t;
154
155 // End types group
156
157// ------------------------------------------------------------------ CONSTANTS
164 // End constants group
165
166// ------------------------------------------------------------------ VARIABLES
173 // End variable group
174
175// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
176
181#ifdef __cplusplus
182extern "C"{
183#endif
184
194
204
217(
218 sram_t *ctx,
219 uint8_t *wr_buf,
220 uint16_t wr_len,
221 uint8_t *rd_buf,
222 uint16_t rd_len
223);
224
235(
236 sram_t *ctx,
237 uint8_t *wr_buf,
238 uint16_t wr_len
239);
240
250void sram_write_byte( sram_t *ctx, uint32_t reg_address, uint8_t write_data );
251
260uint8_t sram_read_byte( sram_t *ctx, uint32_t reg_address );
261
270void sram_write_mode_reg_ins ( sram_t *ctx, uint8_t ins_data );
271
280
289
298
299#ifdef __cplusplus
300}
301#endif
302#endif // _SRAM_H_
303
304 // End public_function group
306
307// ------------------------------------------------------------------------- END
#define SRAM_RETVAL
Definition sram.h:79
void sram_generic_transfer(sram_t *ctx, uint8_t *wr_buf, uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len)
Generic transfer function.
SRAM_RETVAL sram_init(sram_t *ctx, sram_cfg_t *cfg)
Initialization function.
void sram_soft_reset(sram_t *ctx)
Soft reset funcion.
uint8_t sram_read_mode_reg_ins(sram_t *ctx)
Read mode register instruction funcion.
void sram_write_byte(sram_t *ctx, uint32_t reg_address, uint8_t write_data)
Generic write byte of data funcion.
void sram_cfg_setup(sram_cfg_t *cfg)
Config Object Initialization function.
void sram_generic_write(sram_t *ctx, uint8_t *wr_buf, uint16_t wr_len)
Generic write function.
uint8_t sram_read_byte(sram_t *ctx, uint32_t reg_address)
Generic read byte of data funcion.
void sram_hold_transmission(sram_t *ctx)
Suspend transmission funcion.
void sram_write_mode_reg_ins(sram_t *ctx, uint8_t ins_data)
Write mode register instruction funcion.
Click configuration structure definition.
Definition sram.h:135
uint8_t spi_mode
Definition sram.h:150
pin_name_t hld
Definition sram.h:145
spi_master_chip_select_polarity_t cs_polarity
Definition sram.h:151
pin_name_t sck
Definition sram.h:140
pin_name_t mosi
Definition sram.h:139
uint32_t spi_speed
Definition sram.h:149
pin_name_t miso
Definition sram.h:138
pin_name_t cs
Definition sram.h:141
Click ctx object definition.
Definition sram.h:118
digital_out_t cs
Definition sram.h:122
digital_out_t hld
Definition sram.h:121
spi_master_t spi
Definition sram.h:126
pin_name_t chip_select
Definition sram.h:127