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 
35 #include "drv_digital_out.h"
36 #include "drv_digital_in.h"
37 #include "drv_spi_master.h"
38 #include "spi_specifics.h"
39 
60 #define FRAM6_OPCODE_WREN 0x06
61 #define FRAM6_OPCODE_WRDI 0x04
62 #define FRAM6_OPCODE_RDSR 0x05
63 #define FRAM6_OPCODE_WRSR 0x01
64 #define FRAM6_OPCODE_READ 0x03
65 #define FRAM6_OPCODE_FSTRD 0x0B
66 #define FRAM6_OPCODE_WRITE 0x02
67 #define FRAM6_OPCODE_SLEEP 0xB9
68 #define FRAM6_OPCODE_RDID 0x9F
69  // fram6_reg
71 
86 #define FRAM6_WEL_BIT_MASK 0x02
87 #define FRAM6_BLOCK_PROTECT_BITS_MASK 0x0C
88 #define FRAM6_BLOCK_PROTECT_NONE 0x00
89 #define FRAM6_BLOCK_PROTECT_UPPER_QUARTER 0x04
90 #define FRAM6_BLOCK_PROTECT_UPPER_HALF 0x08
91 #define FRAM6_BLOCK_PROTECT_ALL 0x0C
92 #define FRAM6_WPEN_BIT_MASK 0x80
93 
98 #define FRAM6_MIN_ADDRESS 0x00000
99 #define FRAM6_MAX_ADDRESS 0x3FFFF
100 
109 #define FRAM6_SET_DATA_SAMPLE_EDGE SET_SPI_DATA_SAMPLE_EDGE
110 #define FRAM6_SET_DATA_SAMPLE_MIDDLE SET_SPI_DATA_SAMPLE_MIDDLE
111  // fram6_set
113 
128 #define FRAM6_MAP_MIKROBUS( cfg, mikrobus ) \
129  cfg.miso = MIKROBUS( mikrobus, MIKROBUS_MISO ); \
130  cfg.mosi = MIKROBUS( mikrobus, MIKROBUS_MOSI ); \
131  cfg.sck = MIKROBUS( mikrobus, MIKROBUS_SCK ); \
132  cfg.cs = MIKROBUS( mikrobus, MIKROBUS_CS ); \
133  cfg.wp = MIKROBUS( mikrobus, MIKROBUS_RST ); \
134  cfg.hld = MIKROBUS( mikrobus, MIKROBUS_PWM );
135  // fram6_map // fram6
138 
143 typedef struct
144 {
145  // Output pins
146  digital_out_t wp;
147  digital_out_t hld;
149  // Modules
150  spi_master_t spi;
152  pin_name_t chip_select;
154 } fram6_t;
155 
160 typedef struct
161 {
162  // Communication gpio pins
163  pin_name_t miso;
164  pin_name_t mosi;
165  pin_name_t sck;
166  pin_name_t cs;
168  // Additional gpio pins
169  pin_name_t wp;
170  pin_name_t hld;
172  // static variable
173  uint32_t spi_speed;
174  spi_master_mode_t spi_mode;
175  spi_master_chip_select_polarity_t cs_polarity;
177 } fram6_cfg_t;
178 
183 typedef enum
184 {
185  FRAM6_OK = 0,
186  FRAM6_ERROR = -1
187 
189 
206 
221 err_t fram6_init ( fram6_t *ctx, fram6_cfg_t *cfg );
222 
236 err_t fram6_default_cfg ( fram6_t *ctx );
237 
250 err_t fram6_write_opcode ( fram6_t *ctx, uint8_t opcode );
251 
267 err_t fram6_read_opcode ( fram6_t *ctx, uint8_t opcode, uint8_t *data_out, uint16_t len );
268 
281 
291 void fram6_set_wp_pin ( fram6_t *ctx, uint8_t state );
292 
302 void fram6_set_hld_pin ( fram6_t *ctx, uint8_t state );
303 
316 
329 
345 err_t fram6_set_block_protection ( fram6_t *ctx, uint8_t block_protect );
346 
359 err_t fram6_write_status ( fram6_t *ctx, uint8_t status );
360 
373 err_t fram6_read_status ( fram6_t *ctx, uint8_t *status );
374 
387 
397 
413 err_t fram6_memory_write ( fram6_t *ctx, uint32_t address, uint8_t *data_in, uint16_t len );
414 
430 err_t fram6_memory_read ( fram6_t *ctx, uint32_t address, uint8_t *data_out, uint16_t len );
431 
447 err_t fram6_memory_read_fast ( fram6_t *ctx, uint32_t address, uint8_t *data_out, uint16_t len );
448 
449 #ifdef __cplusplus
450 }
451 #endif
452 #endif // FRAM6_H
453  // fram6
455 
456 // ------------------------------------------------------------------------ END
fram6_cfg_t::cs
pin_name_t cs
Definition: fram6.h:166
FRAM6_OK
@ FRAM6_OK
Definition: fram6.h:185
fram6_t::hld
digital_out_t hld
Definition: fram6.h:147
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:161
fram6_cfg_t::hld
pin_name_t hld
Definition: fram6.h:170
fram6_cfg_t::wp
pin_name_t wp
Definition: fram6.h:169
fram6_cfg_t::mosi
pin_name_t mosi
Definition: fram6.h:164
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:144
fram6_cfg_t::sck
pin_name_t sck
Definition: fram6.h:165
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:163
fram6_read_opcode
err_t fram6_read_opcode(fram6_t *ctx, uint8_t opcode, uint8_t *data_out, uint16_t len)
FRAM 6 read opcode function.
fram6_t::wp
digital_out_t wp
Definition: fram6.h:146
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:184
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:152
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:150
FRAM6_ERROR
@ FRAM6_ERROR
Definition: fram6.h:186
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:174
fram6_cfg_t::cs_polarity
spi_master_chip_select_polarity_t cs_polarity
Definition: fram6.h:175
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:173