diff options
| author | Josh Blum <josh@joshknows.com> | 2010-12-31 14:25:49 -0800 | 
|---|---|---|
| committer | Josh Blum <josh@joshknows.com> | 2010-12-31 14:25:49 -0800 | 
| commit | 886a1be2f24e74de9244e3103e7a8b89071b8eb4 (patch) | |
| tree | 8475cb380868f0d3ba5abd7402d0e7fa49c44193 | |
| parent | 027962b15f711c615235d2968a983107e4c6bd83 (diff) | |
| download | uhd-886a1be2f24e74de9244e3103e7a8b89071b8eb4.tar.gz uhd-886a1be2f24e74de9244e3103e7a8b89071b8eb4.tar.bz2 uhd-886a1be2f24e74de9244e3103e7a8b89071b8eb4.zip  | |
usrp-n2xx: use init non zero constant (see fixme), also simplified spi flash read size functions
| -rw-r--r-- | firmware/zpu/usrp2p/spi_flash_read.c | 40 | 
1 files changed, 14 insertions, 26 deletions
diff --git a/firmware/zpu/usrp2p/spi_flash_read.c b/firmware/zpu/usrp2p/spi_flash_read.c index 36c326e96..75721b0f7 100644 --- a/firmware/zpu/usrp2p/spi_flash_read.c +++ b/firmware/zpu/usrp2p/spi_flash_read.c @@ -21,7 +21,8 @@  #include <stdlib.h>		// abort  #include <nonstdio.h> -static size_t _spi_flash_log2_memory_size; +//FIXME cannot be zero or it gets optimized out and the get size functions break... +#define UNINITIALIZED 0xdeadbeef  uint32_t   spi_flash_rdid(void) @@ -32,42 +33,29 @@ spi_flash_rdid(void)  size_t   spi_flash_log2_sector_size(void)  { -  static size_t _spi_flash_log2_sector_size; - -  if (_spi_flash_log2_sector_size != 0) -    return _spi_flash_log2_sector_size; - -   -  uint32_t id = spi_flash_rdid(); -  int type = (id >> 8) & 0xff; -  int size = id & 0xff; -  if (type != 0x20 || size < 22 || size > 24) -    abort(); -    static unsigned char log2_sector_size[3] = { -    16,	/* M25P32  */ +    16, /* M25P32  */      16, /* M25P64  */      18, /* M25P128 */    }; - -  _spi_flash_log2_sector_size = log2_sector_size[size - 22]; -  _spi_flash_log2_memory_size = size; //while we're at it -  return _spi_flash_log2_sector_size; +  return log2_sector_size[spi_flash_log2_memory_size() - 22];  }  size_t  spi_flash_log2_memory_size(void)  { -  if (_spi_flash_log2_memory_size != 0) -    return _spi_flash_log2_memory_size; +  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(); -  uint32_t id = spi_flash_rdid(); -  int type = (id >> 8) & 0xff; -  int size = id & 0xff; -  if (type != 0x20 || size < 22 || size > 24) -    abort(); +    _spi_flash_log2_memory_size = size; +  } -  _spi_flash_log2_memory_size = size;    return _spi_flash_log2_memory_size;  }  | 
