fram 2.0.0.0
fram.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 FRAM_H
36#define FRAM_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 FRAM_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.hld = MIKROBUS( mikrobus, MIKROBUS_RST ); \
74 cfg.wp = MIKROBUS( mikrobus, MIKROBUS_PWM )
81#define FRAM_RETVAL uint8_t
82
83#define FRAM_OK 0x00
84#define FRAM_INIT_ERROR 0xFF
91#define FRAM_WREN 0x06
92#define FRAM_WRDI 0x04
93#define FRAM_RDSR 0x05
94#define FRAM_WRSR 0x01
95#define FRAM_READ 0x03
96#define FRAM_WRITE 0x02
103#define FRAM_WPEN 0x80
104#define FRAM_BP1 0x08
105#define FRAM_BP0 0x04
106#define FRAM_WEL 0x02
107
108#define FRAM_MEM_SIZE 0x8000
111 // End group macro
112// --------------------------------------------------------------- PUBLIC TYPES
121typedef struct
122{
123 // Output pins
124
125 digital_out_t cs;
126 digital_out_t hld;
127 digital_out_t wp;
128
129 // Modules
130
131 spi_master_t spi;
132 pin_name_t chip_select;
133
134} fram_t;
135
139typedef struct
140{
141 // Communication gpio pins
142
143 pin_name_t miso;
144 pin_name_t mosi;
145 pin_name_t sck;
146 pin_name_t cs;
147
148 // Additional gpio pins
149
150 pin_name_t hld;
151 pin_name_t wp;
152
153 // static variable
154
155 uint32_t spi_speed;
156 spi_master_mode_t spi_mode;
157 spi_master_chip_select_polarity_t cs_polarity;
158
159} fram_cfg_t;
160
161 // End types group
162// ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
163
168#ifdef __cplusplus
169extern "C"{
170#endif
171
181
191
203void fram_generic_transfer ( fram_t *ctx, uint8_t *wr_buf, uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len );
204
212void fram_init_f ( fram_t *ctx );
213
222
231
239uint8_t fram_read_status ( fram_t *ctx ) ;
240
248void fram_write_status ( fram_t *ctx, uint8_t value );
249
260void fram_read ( fram_t *ctx, uint16_t address, uint8_t *buffer, uint16_t count );
261
272void fram_write ( fram_t *ctx, uint16_t address, uint8_t *buffer, uint16_t count );
273
281void fram_erase_all ( fram_t *ctx );
282
283#ifdef __cplusplus
284}
285#endif
286#endif // _FRAM_H_
287
288 // End public_function group
290
291// ------------------------------------------------------------------------- END
#define FRAM_RETVAL
Definition fram.h:81
void fram_read(fram_t *ctx, uint16_t address, uint8_t *buffer, uint16_t count)
Fram read function.
void fram_write(fram_t *ctx, uint16_t address, uint8_t *buffer, uint16_t count)
Fram write function.
void fram_generic_transfer(fram_t *ctx, uint8_t *wr_buf, uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len)
Generic transfer function.
uint8_t fram_read_status(fram_t *ctx)
Fram click Read Status function.
void fram_write_status(fram_t *ctx, uint8_t value)
Fram click Write Status function.
void fram_erase_all(fram_t *ctx)
Fram erase all function.
FRAM_RETVAL fram_init(fram_t *ctx, fram_cfg_t *cfg)
Initialization function.
void fram_cfg_setup(fram_cfg_t *cfg)
Config Object Initialization function.
void fram_init_f(fram_t *ctx)
Fram click init function.
void fram_write_enable(fram_t *ctx)
Fram click Write Enable function.
void fram_write_disable(fram_t *ctx)
Fram click Write Disable function.
Click configuration structure definition.
Definition fram.h:140
pin_name_t hld
Definition fram.h:150
spi_master_chip_select_polarity_t cs_polarity
Definition fram.h:157
pin_name_t sck
Definition fram.h:145
spi_master_mode_t spi_mode
Definition fram.h:156
pin_name_t mosi
Definition fram.h:144
uint32_t spi_speed
Definition fram.h:155
pin_name_t wp
Definition fram.h:151
pin_name_t miso
Definition fram.h:143
pin_name_t cs
Definition fram.h:146
Click ctx object definition.
Definition fram.h:122
digital_out_t cs
Definition fram.h:125
digital_out_t hld
Definition fram.h:126
spi_master_t spi
Definition fram.h:131
pin_name_t chip_select
Definition fram.h:132
digital_out_t wp
Definition fram.h:127