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 )
75 
81 #define FRAM_RETVAL uint8_t
82 
83 #define FRAM_OK 0x00
84 #define FRAM_INIT_ERROR 0xFF
85 
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
97 
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
109  // End group macro
112 // --------------------------------------------------------------- PUBLIC TYPES
121 typedef 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 
139 typedef 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  // End types group
162 // ----------------------------------------------- PUBLIC FUNCTION DECLARATIONS
163 
168 #ifdef __cplusplus
169 extern "C"{
170 #endif
171 
181 
191 
203 void fram_generic_transfer ( fram_t *ctx, uint8_t *wr_buf, uint16_t wr_len, uint8_t *rd_buf, uint16_t rd_len );
204 
212 void fram_init_f ( fram_t *ctx );
213 
221 void fram_write_enable ( fram_t *ctx );
222 
231 
239 uint8_t fram_read_status ( fram_t *ctx ) ;
240 
248 void fram_write_status ( fram_t *ctx, uint8_t value );
249 
260 void fram_read ( fram_t *ctx, uint16_t address, uint8_t *buffer, uint16_t count );
261 
272 void fram_write ( fram_t *ctx, uint16_t address, uint8_t *buffer, uint16_t count );
273 
281 void fram_erase_all ( fram_t *ctx );
282 
283 #ifdef __cplusplus
284 }
285 #endif
286 #endif // _FRAM_H_
287  // End public_function group
290 
291 // ------------------------------------------------------------------------- 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:151
fram_t::wp
digital_out_t wp
Definition: fram.h:127
fram_t::chip_select
pin_name_t chip_select
Definition: fram.h:132
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:150
FRAM_RETVAL
#define FRAM_RETVAL
Definition: fram.h:81
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:122
fram_cfg_t::mosi
pin_name_t mosi
Definition: fram.h:144
fram_cfg_t::cs
pin_name_t cs
Definition: fram.h:146
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:140
fram_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: fram.h:157
fram_cfg_t::spi_speed
uint32_t spi_speed
Definition: fram.h:155
fram_t::spi
spi_master_t spi
Definition: fram.h:131
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:143
fram_t::hld
digital_out_t hld
Definition: fram.h:126
fram_t::cs
digital_out_t cs
Definition: fram.h:125
fram_cfg_t::sck
pin_name_t sck
Definition: fram.h:145
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:156
fram_write
void fram_write(fram_t *ctx, uint16_t address, uint8_t *buffer, uint16_t count)
Fram write function.