1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
/**
* @file flash.h
*
* @brief Flash conversion and alignment routines
*
* This file is part of the bladeRF project:
* http://www.github.com/nuand/bladeRF
*
* Copyright (C) 2013 Daniel Gröber <dxld AT darkboxed DOT org>
* Copyright (C) 2013 Nuand LLC
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef DRIVER_SPI_FLASH_H_
#define DRIVER_SPI_FLASH_H_
#include <assert.h>
#include <stdint.h>
#include <libbladeRF.h>
/**
* Erase regions of SPI flash
*
* @param dev Device handle
* @param[in] erase_block Erase block to start erasing at
* @param[in] count Number of blocks to erase.
*
* @return 0 on success, or BLADERF_ERR_INVAL on an invalid `erase_block` or
* `count` value, or a value from \ref RETCODES list on other failures
*/
int spi_flash_erase(struct bladerf *dev, uint32_t erase_block, uint32_t count);
/**
* Read data from flash
*
* @param dev Device handle
* @param[out] buf Buffer to read data into. Must be `count` *
* flash-page-size bytes or larger.
* @param[in] page Page to begin reading from
* @param[in] count Number of pages to read
*
* @return 0 on success, or BLADERF_ERR_INVAL on an invalid `page` or `count`
* value, or a value from \ref RETCODES list on other failures.
*/
int spi_flash_read(struct bladerf *dev,
uint8_t *buf,
uint32_t page,
uint32_t count);
/**
* Verify data in flash
*
* @param dev Device handle
* @param[out] readback_buf Buffer to read data into. Must be `count` *
* flash-page-size bytes or larger.
* @param[in] expected_buf Expected contents of buffer
* @param[in] page Page to begin reading from
* @param[in] count Number of pages to read
*
* @return 0 on success, or BLADERF_ERR_INVAL on an invalid `page` or `count`
* value, or a value from \ref RETCODES list on other failures.
*/
int spi_flash_verify(struct bladerf *dev,
uint8_t *readback_buf,
const uint8_t *expected_buf,
uint32_t page,
uint32_t count);
/**
* Write data to flash
*
* @param dev Device handle
* @param[in] buf Data to write to flash
* @param[in] page Page to begin writing at
* @param[in] count Number of pages to write
*
* @return 0 on success, or BLADERF_ERR_INVAL on an invalid `page` or `count`
* value, or a value from \ref RETCODES list on other failures.
*/
int spi_flash_write(struct bladerf *dev,
const uint8_t *buf,
uint32_t page,
uint32_t count);
#endif
|