fram6  2.0.0.0
fram6.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 FRAM6_H
29 #define FRAM6_H
30 
31 #ifdef __cplusplus
32 extern "C"{
33 #endif
34 
39 #ifdef PREINIT_SUPPORTED
40 #include "preinit.h"
41 #endif
42 
43 #ifdef MikroCCoreVersion
44  #if MikroCCoreVersion >= 1
45  #include "delays.h"
46  #endif
47 #endif
48 
49 #include "drv_digital_out.h"
50 #include "drv_digital_in.h"
51 #include "drv_spi_master.h"
52 #include "spi_specifics.h"
53 
74 #define FRAM6_OPCODE_WREN 0x06
75 #define FRAM6_OPCODE_WRDI 0x04
76 #define FRAM6_OPCODE_RDSR 0x05
77 #define FRAM6_OPCODE_WRSR 0x01
78 #define FRAM6_OPCODE_READ 0x03
79 #define FRAM6_OPCODE_FSTRD 0x0B
80 #define FRAM6_OPCODE_WRITE 0x02
81 #define FRAM6_OPCODE_SLEEP 0xB9
82 #define FRAM6_OPCODE_RDID 0x9F
83  // fram6_reg
85 
100 #define FRAM6_WEL_BIT_MASK 0x02
101 #define FRAM6_BLOCK_PROTECT_BITS_MASK 0x0C
102 #define FRAM6_BLOCK_PROTECT_NONE 0x00
103 #define FRAM6_BLOCK_PROTECT_UPPER_QUARTER 0x04
104 #define FRAM6_BLOCK_PROTECT_UPPER_HALF 0x08
105 #define FRAM6_BLOCK_PROTECT_ALL 0x0C
106 #define FRAM6_WPEN_BIT_MASK 0x80
107 
112 #define FRAM6_MIN_ADDRESS 0x00000
113 #define FRAM6_MAX_ADDRESS 0x3FFFF
114 
123 #define FRAM6_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
124 #define FRAM6_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
125  // fram6_set
127 
142 #define FRAM6_MAP_MIKROBUS( cfg, mikrobus ) \
143  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
144  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
145  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
146  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
147  cfg.wp = MIKROBUS( mikrobus, MIKROBUS_RST ); \
148  cfg.hld = MIKROBUS( mikrobus, MIKROBUS_PWM );
149  // fram6_map // fram6
152 
157 typedef struct
158 {
159  // Output pins
160  digital_out_t wp;
161  digital_out_t hld;
163  // Modules
164  spi_master_t spi;
166  pin_name_t chip_select;
168 } fram6_t;
169 
174 typedef struct
175 {
176  // Communication gpio pins
177  pin_name_t miso;
178  pin_name_t mosi;
179  pin_name_t sck;
180  pin_name_t cs;
182  // Additional gpio pins
183  pin_name_t wp;
184  pin_name_t hld;
186  // static variable
187  uint32_t spi_speed;
188  spi_master_mode_t spi_mode;
189  spi_master_chip_select_polarity_t cs_polarity;
191 } fram6_cfg_t;
192 
197 typedef enum
198 {
199  FRAM6_OK = 0,
200  FRAM6_ERROR = -1
201 
203 
220 
235 err_t fram6_init ( fram6_t *ctx, fram6_cfg_t *cfg );
236 
250 err_t fram6_default_cfg ( fram6_t *ctx );
251 
264 err_t fram6_write_opcode ( fram6_t *ctx, uint8_t opcode );
265 
281 err_t fram6_read_opcode ( fram6_t *ctx, uint8_t opcode, uint8_t *data_out, uint8_t len );
282 
295 
305 void fram6_set_wp_pin ( fram6_t *ctx, uint8_t state );
306 
316 void fram6_set_hld_pin ( fram6_t *ctx, uint8_t state );
317 
330 
343 
359 err_t fram6_set_block_protection ( fram6_t *ctx, uint8_t block_protect );
360 
373 err_t fram6_write_status ( fram6_t *ctx, uint8_t status );
374 
387 err_t fram6_read_status ( fram6_t *ctx, uint8_t *status );
388 
401 
411 
427 err_t fram6_memory_write ( fram6_t *ctx, uint32_t address, uint8_t *data_in, uint16_t len );
428 
444 err_t fram6_memory_read ( fram6_t *ctx, uint32_t address, uint8_t *data_out, uint16_t len );
445 
461 err_t fram6_memory_read_fast ( fram6_t *ctx, uint32_t address, uint8_t *data_out, uint16_t len );
462 
463 #ifdef __cplusplus
464 }
465 #endif
466 #endif // FRAM6_H
467  // fram6
469 
470 // ------------------------------------------------------------------------ END
fram6_cfg_t::cs
pin_name_t cs
Definition: fram6.h:180
FRAM6_OK
@ FRAM6_OK
Definition: fram6.h:199
fram6_t::hld
digital_out_t hld
Definition: fram6.h:161
fram6_check_communication
err_t fram6_check_communication(fram6_t *ctx)
FRAM 6 check communication function.
fram6_write_opcode
err_t fram6_write_opcode(fram6_t *ctx, uint8_t opcode)
FRAM 6 write opcode function.
spi_specifics.h
This file contains SPI specific macros, functions, etc.
fram6_read_status
err_t fram6_read_status(fram6_t *ctx, uint8_t *status)
FRAM 6 read status function.
fram6_cfg_t
FRAM 6 Click configuration object.
Definition: fram6.h:175
fram6_cfg_t::hld
pin_name_t hld
Definition: fram6.h:184
fram6_cfg_t::wp
pin_name_t wp
Definition: fram6.h:183
fram6_cfg_t::mosi
pin_name_t mosi
Definition: fram6.h:178
fram6_set_block_protection
err_t fram6_set_block_protection(fram6_t *ctx, uint8_t block_protect)
FRAM 6 set block protection function.
fram6_disable_write
err_t fram6_disable_write(fram6_t *ctx)
FRAM 6 disable write function.
fram6_memory_read_fast
err_t fram6_memory_read_fast(fram6_t *ctx, uint32_t address, uint8_t *data_out, uint16_t len)
FRAM 6 memory read fast function.
fram6_t
FRAM 6 Click context object.
Definition: fram6.h:158
fram6_cfg_t::sck
pin_name_t sck
Definition: fram6.h:179
fram6_memory_write
err_t fram6_memory_write(fram6_t *ctx, uint32_t address, uint8_t *data_in, uint16_t len)
FRAM 6 memory write function.
fram6_cfg_t::miso
pin_name_t miso
Definition: fram6.h:177
fram6_t::wp
digital_out_t wp
Definition: fram6.h:160
fram6_memory_read
err_t fram6_memory_read(fram6_t *ctx, uint32_t address, uint8_t *data_out, uint16_t len)
FRAM 6 memory read function.
fram6_set_hld_pin
void fram6_set_hld_pin(fram6_t *ctx, uint8_t state)
FRAM 6 set HLD pin function.
fram6_return_value_t
fram6_return_value_t
FRAM 6 Click return value data.
Definition: fram6.h:198
fram6_set_wp_pin
void fram6_set_wp_pin(fram6_t *ctx, uint8_t state)
FRAM 6 set WP pin function.
fram6_t::chip_select
pin_name_t chip_select
Definition: fram6.h:166
fram6_wakeup_from_sleep
void fram6_wakeup_from_sleep(fram6_t *ctx)
FRAM 6 wake up from sleep function.
fram6_t::spi
spi_master_t spi
Definition: fram6.h:164
FRAM6_ERROR
@ FRAM6_ERROR
Definition: fram6.h:200
fram6_read_opcode
err_t fram6_read_opcode(fram6_t *ctx, uint8_t opcode, uint8_t *data_out, uint8_t len)
FRAM 6 read opcode function.
fram6_enter_sleep_mode
err_t fram6_enter_sleep_mode(fram6_t *ctx)
FRAM 6 enter sleep mode function.
fram6_cfg_setup
void fram6_cfg_setup(fram6_cfg_t *cfg)
FRAM 6 configuration object setup function.
fram6_cfg_t::spi_mode
spi_master_mode_t spi_mode
Definition: fram6.h:188
fram6_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: fram6.h:189
fram6_enable_write
err_t fram6_enable_write(fram6_t *ctx)
FRAM 6 enable write function.
fram6_default_cfg
err_t fram6_default_cfg(fram6_t *ctx)
FRAM 6 default configuration function.
fram6_init
err_t fram6_init(fram6_t *ctx, fram6_cfg_t *cfg)
FRAM 6 initialization function.
fram6_write_status
err_t fram6_write_status(fram6_t *ctx, uint8_t status)
FRAM 6 write status function.
fram6_cfg_t::spi_speed
uint32_t spi_speed
Definition: fram6.h:187