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 
38 #include "mikrosdk_version.h"
39 
40 #ifdef __GNUC__
41 #if mikroSDK_GET_VERSION < 20800ul
42 #include "rcu_delays.h"
43 #else
44 #include "delays.h"
45 #endif
46 #endif
47 
48 #include "drv_digital_out.h"
49 #include "drv_digital_in.h"
50 #include "drv_spi_master.h"
51 
52 
53 // -------------------------------------------------------------- PUBLIC MACROS
64 #define FRAM_MAP_MIKROBUS( cfg, mikrobus ) \
65  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
66  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
67  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
68  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
69  cfg.hld = MIKROBUS( mikrobus, MIKROBUS_RST ); \
70  cfg.wp = MIKROBUS( mikrobus, MIKROBUS_PWM )
71 
77 #define FRAM_RETVAL uint8_t
78 
79 #define FRAM_OK 0x00
80 #define FRAM_INIT_ERROR 0xFF
81 
87 #define FRAM_WREN 0x06
88 #define FRAM_WRDI 0x04
89 #define FRAM_RDSR 0x05
90 #define FRAM_WRSR 0x01
91 #define FRAM_READ 0x03
92 #define FRAM_WRITE 0x02
93 
99 #define FRAM_WPEN 0x80
100 #define FRAM_BP1 0x08
101 #define FRAM_BP0 0x04
102 #define FRAM_WEL 0x02
103 
104 #define FRAM_MEM_SIZE 0x8000
105  // End group macro
108 // --------------------------------------------------------------- PUBLIC TYPES
117 typedef struct
118 {
119  // Output pins
120 
121  digital_out_t cs;
122  digital_out_t hld;
123  digital_out_t wp;
124 
125  // Modules
126 
127  spi_master_t spi;
128  pin_name_t chip_select;
129 
130 } fram_t;
131 
135 typedef struct
136 {
137  // Communication gpio pins
138 
139  pin_name_t miso;
140  pin_name_t mosi;
141  pin_name_t sck;
142  pin_name_t cs;
143 
144  // Additional gpio pins
145 
146  pin_name_t hld;
147  pin_name_t wp;
148 
149  // static variable
150 
151  uint32_t spi_speed;
152  spi_master_mode_t spi_mode;
153  spi_master_chip_select_polarity_t cs_polarity;
154 
155 } fram_cfg_t;
156  // End types group
158 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
159 
164 #ifdef __cplusplus
165 extern "C"{
166 #endif
167 
177 
187 
199 void fram_generic_transfer ( fram_t *ctx, uint8_t *wr_buf, uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len );
200 
208 void fram_init_f ( fram_t *ctx );
209 
217 void fram_write_enable ( fram_t *ctx );
218 
227 
235 uint8_t fram_read_status ( fram_t *ctx ) ;
236 
244 void fram_write_status ( fram_t *ctx, uint8_t value );
245 
256 void fram_read ( fram_t *ctx, uint16_t address, uint8_t *buffer, uint16_t count );
257 
268 void fram_write ( fram_t *ctx, uint16_t address, uint8_t *buffer, uint16_t count );
269 
277 void fram_erase_all ( fram_t *ctx );
278 
279 #ifdef __cplusplus
280 }
281 #endif
282 #endif // _FRAM_H_
283  // End public_function group
286 
287 // ------------------------------------------------------------------------- END
fram_cfg_setup
void fram_cfg_setup(fram_cfg_t *cfg)
Config Object Initialization function.
fram_cfg_t::wp
pin_name_t wp
Definition: fram.h:147
fram_t::wp
digital_out_t wp
Definition: fram.h:123
fram_t::chip_select
pin_name_t chip_select
Definition: fram.h:128
fram_read_status
uint8_t fram_read_status(fram_t *ctx)
Fram click Read Status function.
fram_cfg_t::hld
pin_name_t hld
Definition: fram.h:146
FRAM_RETVAL
#define FRAM_RETVAL
Definition: fram.h:77
fram_erase_all
void fram_erase_all(fram_t *ctx)
Fram erase all function.
fram_write_status
void fram_write_status(fram_t *ctx, uint8_t value)
Fram click Write Status function.
fram_write_enable
void fram_write_enable(fram_t *ctx)
Fram click Write Enable function.
fram_t
Click ctx object definition.
Definition: fram.h:118
fram_cfg_t::mosi
pin_name_t mosi
Definition: fram.h:140
fram_cfg_t::cs
pin_name_t cs
Definition: fram.h:142
fram_generic_transfer
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.
fram_init_f
void fram_init_f(fram_t *ctx)
Fram click init function.
fram_write_disable
void fram_write_disable(fram_t *ctx)
Fram click Write Disable function.
fram_cfg_t
Click configuration structure definition.
Definition: fram.h:136
fram_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: fram.h:153
fram_cfg_t::spi_speed
uint32_t spi_speed
Definition: fram.h:151
fram_t::spi
spi_master_t spi
Definition: fram.h:127
fram_read
void fram_read(fram_t *ctx, uint16_t address, uint8_t *buffer, uint16_t count)
Fram read function.
fram_cfg_t::miso
pin_name_t miso
Definition: fram.h:139
fram_t::hld
digital_out_t hld
Definition: fram.h:122
fram_t::cs
digital_out_t cs
Definition: fram.h:121
fram_cfg_t::sck
pin_name_t sck
Definition: fram.h:141
fram_init
FRAM_RETVAL fram_init(fram_t *ctx, fram_cfg_t *cfg)
Initialization function.
fram_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: fram.h:152
fram_write
void fram_write(fram_t *ctx, uint16_t address, uint8_t *buffer, uint16_t count)
Fram write function.