mram 2.0.0.0
mram.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 MRAM_H
36#define MRAM_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
57// -------------------------------------------------------------- PUBLIC MACROS
68#define MRAM_MAP_MIKROBUS( cfg, mikrobus ) \
69 cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
70 cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
71 cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
72 cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
73 cfg.wp = MIKROBUS( mikrobus, MIKROBUS_RST ); \
74 cfg.hld = MIKROBUS( mikrobus, MIKROBUS_INT )
81#define MRAM_OK 0
82#define MRAM_ERROR -1
89#define MRAM_WRITE_ENABLE_BIT 0x02
90#define MRAM_MEMORY_BLOCK_BIT0 0x04
91#define MRAM_MEMORY_BLOCK_BIT1 0x08
92#define MRAM_STATUS_WRITE_DISABLE_BIT 0x80
93#define MRAM_FIRST_ADDRESS_LOCATION 0x0000
94#define MRAM_ADDRESS_LOCATION_0 0x000F
95#define MRAM_ADDRESS_LOCATION_1 0x00FF
96#define MRAM_ADDRESS_LOCATION_2 0x0FFF
97#define MRAM_LAST_ADDRESS_LOCATION 0x7FFF
98#define MRAM_LOGIC_HIGH 0x01
99#define MRAM_LOGIC_LOW 0x00
100#define MRAM_NONE_PROTECTED_MEMORY 0x82
101#define MRAM_UPPER_QUARTER_PROTECTED_MEMORY 0x86
102#define MRAM_UPPER_HALF_PROTECTED_MEMORY 0x8A
103#define MRAM_ALL_PROTECTED_MEMORY 0x8E
106 // End group macro
107// --------------------------------------------------------------- PUBLIC TYPES
116typedef struct
117{
118 // Output pins
119
120 digital_out_t wp;
121 digital_out_t hld;
122 digital_out_t cs;
123
124 // Modules
125 spi_master_t spi;
126 pin_name_t chip_select;
127
128} mram_t;
129
133typedef struct
134{
135 // Communication gpio pins
136
137 pin_name_t miso;
138 pin_name_t mosi;
139 pin_name_t sck;
140 pin_name_t cs;
141
142 // Additional gpio pins
143
144 pin_name_t wp;
145 pin_name_t hld;
146
147 // static variable
148
149 uint32_t spi_speed;
150 spi_master_mode_t spi_mode;
151 spi_master_chip_select_polarity_t cs_polarity;
152
153} mram_cfg_t;
154
155 // End types group
156
157// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
158
163#ifdef __cplusplus
164extern "C"{
165#endif
166
176
184err_t mram_init ( mram_t *ctx, mram_cfg_t *cfg );
185
194
207(
208 mram_t *ctx,
209 uint8_t *wr_buf,
210 uint16_t wr_len,
211 uint8_t *rd_buf,
212 uint16_t rd_len
213);
214
225
236uint8_t mram_check_status_bit (mram_t *ctx, uint8_t status_bit );
237
247uint8_t mram_enable_write (mram_t *ctx );
248
258uint8_t mram_disable_write ( mram_t *ctx );
259
269void mram_write_status_reg ( mram_t *ctx, uint8_t transfer_data);
270
282void mram_read_data_bytes ( mram_t *ctx, const uint16_t address, uint8_t *buffer, const uint16_t n_bytes );
283
295void mram_write_data_bytes ( mram_t *ctx, const uint16_t address, uint8_t *buffer, const uint16_t n_bytes );
296
306
316
326void mram_enable_write_protect ( mram_t *ctx, uint8_t state);
327
337void mram_enable_hold_mode ( mram_t *ctx, uint8_t state);
338
339#ifdef __cplusplus
340}
341#endif
342#endif // _MRAM_H_
343
344 // End public_function group
346
347// ------------------------------------------------------------------------- END
void mram_write_status_reg(mram_t *ctx, uint8_t transfer_data)
Write status reg.
uint8_t mram_check_status_bit(mram_t *ctx, uint8_t status_bit)
Check status bit.
void mram_wake_up_mode(mram_t *ctx)
Wake up.
void mram_enable_write_protect(mram_t *ctx, uint8_t state)
Enable write protection.
void mram_enter_sleep_mode(mram_t *ctx)
Sleep mode.
void mram_default_cfg(mram_t *ctx)
Click Default Configuration function.
void mram_enable_hold_mode(mram_t *ctx, uint8_t state)
Enable hold mode.
void mram_cfg_setup(mram_cfg_t *cfg)
Config Object Initialization function.
uint8_t mram_disable_write(mram_t *ctx)
Disable write.
err_t mram_init(mram_t *ctx, mram_cfg_t *cfg)
Initialization function.
uint8_t mram_enable_write(mram_t *ctx)
Enable write.
void mram_write_data_bytes(mram_t *ctx, const uint16_t address, uint8_t *buffer, const uint16_t n_bytes)
Write n byte data.
uint8_t mram_read_status_reg(mram_t *ctx)
Read status reg.
void mram_generic_transfer(mram_t *ctx, uint8_t *wr_buf, uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len)
Generic transfer function.
void mram_read_data_bytes(mram_t *ctx, const uint16_t address, uint8_t *buffer, const uint16_t n_bytes)
Read n byte data.
Click configuration structure definition.
Definition mram.h:134
pin_name_t hld
Definition mram.h:145
spi_master_chip_select_polarity_t cs_polarity
Definition mram.h:151
pin_name_t sck
Definition mram.h:139
spi_master_mode_t spi_mode
Definition mram.h:150
pin_name_t mosi
Definition mram.h:138
uint32_t spi_speed
Definition mram.h:149
pin_name_t wp
Definition mram.h:144
pin_name_t miso
Definition mram.h:137
pin_name_t cs
Definition mram.h:140
Click ctx object definition.
Definition mram.h:117
digital_out_t cs
Definition mram.h:122
digital_out_t hld
Definition mram.h:121
spi_master_t spi
Definition mram.h:125
pin_name_t chip_select
Definition mram.h:126
digital_out_t wp
Definition mram.h:120