dram  2.1.0.0
dram.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 DRAM_H
29 #define DRAM_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 DRAM_CMD_READ 0x03
71 #define DRAM_CMD_FAST_READ 0x0B
72 #define DRAM_CMD_WRITE 0x02
73 #define DRAM_CMD_RESET_ENABLE 0x66
74 #define DRAM_CMD_RESET 0x99
75 #define DRAM_CMD_WRAP_BOUNDARY_TOGGLE 0xC0
76 #define DRAM_CMD_READ_ID 0x9F
77  // dram_reg
79 
94 #define DRAM_MIN_ADDRESS 0x000000
95 #define DRAM_MAX_ADDRESS 0x7FFFFFul
96 
101 #define DRAM_MANUFACTURER_ID 0x0D
102 
111 #define DRAM_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
112 #define DRAM_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
113  // dram_set
115 
130 #define DRAM_MAP_MIKROBUS( cfg, mikrobus ) \
131  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
132  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
133  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
134  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
135  cfg.io3 = MIKROBUS( mikrobus, MIKROBUS_RST ); \
136  cfg.io2 = MIKROBUS( mikrobus, MIKROBUS_PWM );
137  // dram_map // dram
140 
145 typedef struct
146 {
147  // Output pins
148  digital_out_t io3;
149  digital_out_t io2;
151  // Modules
152  spi_master_t spi;
154  pin_name_t chip_select;
156 } dram_t;
157 
162 typedef 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 io3;
172  pin_name_t io2;
174  // static variable
175  uint32_t spi_speed;
176  spi_master_mode_t spi_mode;
177  spi_master_chip_select_polarity_t cs_polarity;
179 } dram_cfg_t;
180 
185 typedef enum
186 {
187  DRAM_OK = 0,
188  DRAM_ERROR = -1
189 
191 
208 
222 err_t dram_init ( dram_t *ctx, dram_cfg_t *cfg );
223 
238 err_t dram_memory_write ( dram_t *ctx, uint32_t address, uint8_t *data_in, uint32_t len );
239 
254 err_t dram_memory_read ( dram_t *ctx, uint32_t address, uint8_t *data_out, uint32_t len );
255 
270 err_t dram_memory_read_fast ( dram_t *ctx, uint32_t address, uint8_t *data_out, uint32_t len );
271 
283 err_t dram_reset ( dram_t *ctx );
284 
297 
309 err_t dram_read_id ( dram_t *ctx, uint8_t *device_id );
310 
323 
333 void dram_set_io3_pin ( dram_t *ctx, uint8_t state );
334 
344 void dram_set_io2_pin ( dram_t *ctx, uint8_t state );
345 
346 #ifdef __cplusplus
347 }
348 #endif
349 #endif // DRAM_H
350  // dram
352 
353 // ------------------------------------------------------------------------ END
dram_set_io2_pin
void dram_set_io2_pin(dram_t *ctx, uint8_t state)
DRAM set io2 pin function.
DRAM_ERROR
@ DRAM_ERROR
Definition: dram.h:188
dram_cfg_t::io3
pin_name_t io3
Definition: dram.h:171
dram_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: dram.h:176
dram_memory_read
err_t dram_memory_read(dram_t *ctx, uint32_t address, uint8_t *data_out, uint32_t len)
DRAM memory read function.
dram_memory_read_fast
err_t dram_memory_read_fast(dram_t *ctx, uint32_t address, uint8_t *data_out, uint32_t len)
DRAM memory read fast function.
dram_return_value_t
dram_return_value_t
DRAM Click return value data.
Definition: dram.h:186
spi_specifics.h
This file contains SPI specific macros, functions, etc.
dram_toggle_wrap_boundary
err_t dram_toggle_wrap_boundary(dram_t *ctx)
DRAM toggle wrap boundary function.
dram_t::io3
digital_out_t io3
Definition: dram.h:148
DRAM_OK
@ DRAM_OK
Definition: dram.h:187
dram_cfg_t::mosi
pin_name_t mosi
Definition: dram.h:166
dram_set_io3_pin
void dram_set_io3_pin(dram_t *ctx, uint8_t state)
DRAM set io3 pin function.
dram_check_communication
err_t dram_check_communication(dram_t *ctx)
DRAM check communication function.
dram_init
err_t dram_init(dram_t *ctx, dram_cfg_t *cfg)
DRAM initialization function.
dram_t::chip_select
pin_name_t chip_select
Definition: dram.h:154
dram_cfg_t::cs
pin_name_t cs
Definition: dram.h:168
dram_t::spi
spi_master_t spi
Definition: dram.h:152
dram_t::io2
digital_out_t io2
Definition: dram.h:149
dram_cfg_t
DRAM Click configuration object.
Definition: dram.h:163
dram_t
DRAM Click context object.
Definition: dram.h:146
dram_cfg_t::miso
pin_name_t miso
Definition: dram.h:165
dram_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: dram.h:177
dram_cfg_setup
void dram_cfg_setup(dram_cfg_t *cfg)
DRAM configuration object setup function.
dram_cfg_t::spi_speed
uint32_t spi_speed
Definition: dram.h:175
dram_memory_write
err_t dram_memory_write(dram_t *ctx, uint32_t address, uint8_t *data_in, uint32_t len)
DRAM memory write function.
dram_cfg_t::io2
pin_name_t io2
Definition: dram.h:172
dram_cfg_t::sck
pin_name_t sck
Definition: dram.h:167
dram_reset
err_t dram_reset(dram_t *ctx)
DRAM reset function.
dram_read_id
err_t dram_read_id(dram_t *ctx, uint8_t *device_id)
DRAM read id function.