Paparazzi UAS  v5.15_devel-230-gc96ce27
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
sst25vfxxxx.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2014 Freek van Tienen <freek.v.tienen@gmail.com>
3  *
4  * This file is part of paparazzi.
5  *
6  * paparazzi is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2, or (at your option)
9  * any later version.
10  *
11  * paparazzi is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with paparazzi; see the file COPYING. If not, write to
18  * the Free Software Foundation, 59 Temple Place - Suite 330,
19  * Boston, MA 02111-1307, USA.
20  */
21 
27 #ifndef SST25VFXXXX_H
28 #define SST25VFXXXX_H
29 
30 #include "mcu_periph/spi.h"
31 
32 /* Register defines */
33 #define SST25VFXXXX_READ 0x03
34 #define SST25VFXXXX_HGIH_SPEAD_READ 0x0B
35 #define SST25VFXXXX_ERASE_4K 0x20
36 #define SST25VFXXXX_ERASE_32K 0x52
37 #define SST25VFXXXX_ERASE_64K 0xD8
38 #define SST25VFXXXX_ERASE_CHIP 0x60
39 #define SST25VFXXXX_BYTE_PROG 0x02
40 #define SST25VFXXXX_AAI_PROG 0xAD
41 #define SST25VFXXXX_RDSR 0x05
42 #define SST25VFXXXX_EWSR 0x50
43 #define SST25VFXXXX_WRSR 0x01
44 #define SST25VFXXXX_WREN 0x06
45 #define SST25VFXXXX_WRDI 0x04
46 #define SST25VFXXXX_RDID 0x90
47 #define SST25VFXXXX_JEDEC_ID 0x9F
48 #define SST25VFXXXX_EBSY 0x70
49 #define SST25VFXXXX_DBSY 0x80
50 
51 /* The different statuses the SST25VFxxxx chip can be in */
60 };
61 
62 /* The structure for the SST25VFxxxx chip that handles all the buffers and requests */
63 struct SST25VFxxxx {
64  volatile enum SST25VFxxxxStatus status;
66  struct spi_periph *spi_p;
75 };
76 
77 void sst25vfxxxx_init(struct SST25VFxxxx *sst, struct spi_periph *spi_p, const uint8_t slave_idx, SPICallback spi_cb);
78 void sst25vfxxxx_after_cb(struct SST25VFxxxx *sst);
79 void sst25vfxxxx_read_id(struct SST25VFxxxx *sst);
80 void sst25vfxxxx_block_write_en(struct SST25VFxxxx *sst);
81 void sst25vfxxxx_chip_erase(struct SST25VFxxxx *sst);
82 void sst25vfxxxx_write(struct SST25VFxxxx *sst, uint8_t *transfer_buffer, uint8_t transfer_length);
83 void sst25vfxxxx_read(struct SST25VFxxxx *sst, uint8_t *transfer_buffer, uint8_t transfer_length);
84 
85 #endif /* SST25VFXXXX_H */
void sst25vfxxxx_read_id(struct SST25VFxxxx *sst)
Read the chip identifier.
Definition: sst25vfxxxx.c:220
uint8_t output_buf[16]
The output buffer for the SPI transaction.
Definition: sst25vfxxxx.h:69
void sst25vfxxxx_block_write_en(struct SST25VFxxxx *sst)
Enable block writing.
Definition: sst25vfxxxx.c:240
SPI transaction structure.
Definition: spi.h:148
The chip is busy with getting the chip ID.
Definition: sst25vfxxxx.h:55
void(* SPICallback)(struct spi_transaction *trans)
SPI Callback function.
Definition: spi.h:136
void sst25vfxxxx_chip_erase(struct SST25VFxxxx *sst)
Full chip erase.
Definition: sst25vfxxxx.c:258
struct spi_periph * spi_p
The SPI peripheral for the connection.
Definition: sst25vfxxxx.h:66
struct spi_transaction spi_t
The SPI transaction used for the writing and reading of registers.
Definition: sst25vfxxxx.h:67
Architecture independent SPI (Serial Peripheral Interface) API.
SPI peripheral structure.
Definition: spi.h:174
uint8_t transfer_idx
The transfer idx is used for counting input/output bytes.
Definition: sst25vfxxxx.h:73
The chip is busy reading bytes.
Definition: sst25vfxxxx.h:59
uint8_t * transfer_buf
The transfer buffer.
Definition: sst25vfxxxx.h:72
The chip is busy enabeling writing to blocks.
Definition: sst25vfxxxx.h:56
uint8_t status_idx
The counter of substatuses.
Definition: sst25vfxxxx.h:65
enum SST25VFxxxxStatus status
The status of the SST25VFxxxx flash chip.
Definition: sst25vfxxxx.h:64
The chip is busy writing bytes.
Definition: sst25vfxxxx.h:58
unsigned long uint32_t
Definition: types.h:18
The chip isn't initialized.
Definition: sst25vfxxxx.h:53
void sst25vfxxxx_after_cb(struct SST25VFxxxx *sst)
Callback of the SPI after going one level higher for gathering the sst pointer.
Definition: sst25vfxxxx.c:64
SST25VFxxxxStatus
Definition: sst25vfxxxx.h:52
The chip is idle and can be used.
Definition: sst25vfxxxx.h:54
void sst25vfxxxx_init(struct SST25VFxxxx *sst, struct spi_periph *spi_p, const uint8_t slave_idx, SPICallback spi_cb)
Initializing the sst25vfxxxx chip.
Definition: sst25vfxxxx.c:34
The chip is busy erasing itself.
Definition: sst25vfxxxx.h:57
void sst25vfxxxx_write(struct SST25VFxxxx *sst, uint8_t *transfer_buffer, uint8_t transfer_length)
Write bytes.
Definition: sst25vfxxxx.c:276
unsigned char uint8_t
Definition: types.h:14
uint32_t flash_addr
The flash address to write at.
Definition: sst25vfxxxx.h:70
uint8_t input_buf[16]
The input buffer for the SPI transaction.
Definition: sst25vfxxxx.h:68
uint8_t slave_idx
slave id: SPI_SLAVE0 to SPI_SLAVE4
Definition: spi.h:153
uint8_t transfer_length
The transfer buffer length.
Definition: sst25vfxxxx.h:74
void sst25vfxxxx_read(struct SST25VFxxxx *sst, uint8_t *transfer_buffer, uint8_t transfer_length)
Read bytes Need 5 more extra bytes because of SPI overhead.
Definition: sst25vfxxxx.c:300