aboutsummaryrefslogtreecommitdiffstats
path: root/firmware/zpu/usrp2p/spi_flash_read.c
diff options
context:
space:
mode:
authorJosh Blum <josh@joshknows.com>2011-01-09 20:45:35 -0800
committerJosh Blum <josh@joshknows.com>2011-01-09 20:45:35 -0800
commitac97f5ba9c07b29840eddc9f3ecfcac5d9926efd (patch)
tree83303fc8c161e31fd5c99dcd1b6c2c83b3b5278c /firmware/zpu/usrp2p/spi_flash_read.c
parent4ca01c6dbeb253162e64a13f69ce981fc0b8b9bd (diff)
downloaduhd-ac97f5ba9c07b29840eddc9f3ecfcac5d9926efd.tar.gz
uhd-ac97f5ba9c07b29840eddc9f3ecfcac5d9926efd.tar.bz2
uhd-ac97f5ba9c07b29840eddc9f3ecfcac5d9926efd.zip
usrp-n210: firmware changes related to init and bootloader
added u2p init file that is called by u2init added spi flash init and added to u2pinit implemented mdelay usage in bootloader
Diffstat (limited to 'firmware/zpu/usrp2p/spi_flash_read.c')
-rw-r--r--firmware/zpu/usrp2p/spi_flash_read.c46
1 files changed, 24 insertions, 22 deletions
diff --git a/firmware/zpu/usrp2p/spi_flash_read.c b/firmware/zpu/usrp2p/spi_flash_read.c
index 75721b0f7..c65b8c1a1 100644
--- a/firmware/zpu/usrp2p/spi_flash_read.c
+++ b/firmware/zpu/usrp2p/spi_flash_read.c
@@ -21,42 +21,44 @@
#include <stdlib.h> // abort
#include <nonstdio.h>
-//FIXME cannot be zero or it gets optimized out and the get size functions break...
-#define UNINITIALIZED 0xdeadbeef
-
uint32_t
spi_flash_rdid(void)
{
return spif_transact(SPI_TXRX, SPI_SS_FLASH, RDID_CMD << 24, 32, FLAGS) & 0xffffff;
}
-size_t
-spi_flash_log2_sector_size(void)
-{
- static unsigned char log2_sector_size[3] = {
- 16, /* M25P32 */
- 16, /* M25P64 */
- 18, /* M25P128 */
- };
- return log2_sector_size[spi_flash_log2_memory_size() - 22];
-}
+static size_t _spi_flash_log2_memory_size, _spi_flash_log2_sector_size;
-size_t
-spi_flash_log2_memory_size(void)
+void spi_flash_init(void)
{
- static size_t _spi_flash_log2_memory_size = UNINITIALIZED;
-
- if (_spi_flash_log2_memory_size == UNINITIALIZED){
uint32_t id = spi_flash_rdid();
uint8_t type = (id >> 8) & 0xff;
uint8_t size = (id >> 0) & 0xff;
if (type != 0x20 || size < 22 || size > 24)
- abort();
-
+ abort();
_spi_flash_log2_memory_size = size;
- }
- return _spi_flash_log2_memory_size;
+ static unsigned char log2_sector_size[3] = {
+ 16, /* M25P32 */
+ 16, /* M25P64 */
+ 18, /* M25P128 */
+ };
+ _spi_flash_log2_sector_size = log2_sector_size[_spi_flash_log2_memory_size - 22];
+}
+
+size_t spi_flash_log2_sector_size(void)
+{
+ return _spi_flash_log2_sector_size;
+}
+
+size_t spi_flash_sector_size(void)
+{
+ return ((size_t) 1) << _spi_flash_log2_sector_size;
+}
+
+size_t spi_flash_memory_size(void)
+{
+ return ((size_t) 1) << _spi_flash_log2_memory_size;
}
void