zpu: add watchdog timer for while( ... ); operations

This commit is contained in:
Sergey Kostanbaev
2015-03-12 20:57:38 +03:00
parent 6129113723
commit 20178f16fd
4 changed files with 40 additions and 10 deletions

View File

@@ -18,6 +18,7 @@
#include "i2c.h" #include "i2c.h"
#include "mdelay.h" #include "mdelay.h"
#include "usrp2/fw_common.h" #include "usrp2/fw_common.h"
#include "nonstdio.h"
static const int EEPROM_PAGESIZE = 16; static const int EEPROM_PAGESIZE = 16;
@@ -26,7 +27,11 @@ bool find_safe_booted_flag(void) {
return 0; return 0;
#else #else
unsigned char flag_byte; unsigned char flag_byte;
eeprom_read(USRP2_I2C_ADDR_MBOARD, USRP2_EE_MBOARD_BOOTLOADER_FLAGS, &flag_byte, 1); if (!eeprom_read(USRP2_I2C_ADDR_MBOARD, USRP2_EE_MBOARD_BOOTLOADER_FLAGS, &flag_byte, 1)) {
puts("Failed to read safe boot flag");
return false;
}
return (flag_byte == 0x5E); return (flag_byte == 0x5E);
#endif #endif
} }

View File

@@ -36,6 +36,8 @@ static uint16_t prescaler_values[MAX_WB_DIV+1] = {
PRESCALER(4), // 4: 25 MHz PRESCALER(4), // 4: 25 MHz
}; };
#define WATCHDOG 50000
void void
i2c_init(void) i2c_init(void)
{ {
@@ -58,8 +60,13 @@ i2c_init(void)
static inline void static inline void
wait_for_xfer(void) wait_for_xfer(void)
{ {
while (i2c_regs->cmd_status & I2C_ST_TIP) // wait for xfer to complete unsigned i = WATCHDOG;
; while ((i != 0) && (i2c_regs->cmd_status & I2C_ST_TIP)) // wait for xfer to complete
--i;
if (i == 0) {
puts("wait_for_xfer WATCHDOG failed!");
}
} }
static inline bool static inline bool
@@ -79,8 +86,13 @@ i2c_read (unsigned char i2c_addr, unsigned char *buf, unsigned int len)
if (len == 0) // reading zero bytes always works if (len == 0) // reading zero bytes always works
return true; return true;
while (i2c_regs->cmd_status & I2C_ST_BUSY) unsigned i = WATCHDOG;
; while ((i != 0) && (i2c_regs->cmd_status & I2C_ST_BUSY))
--i;
if (i == 0) {
puts("i2c_read WATCHDOG failed!");
return false;
}
i2c_regs->data = (i2c_addr << 1) | 1; // 7 bit address and read bit (1) i2c_regs->data = (i2c_addr << 1) | 1; // 7 bit address and read bit (1)
// generate START and write addr // generate START and write addr
@@ -104,8 +116,13 @@ i2c_read (unsigned char i2c_addr, unsigned char *buf, unsigned int len)
bool bool
i2c_write(unsigned char i2c_addr, const unsigned char *buf, unsigned int len) i2c_write(unsigned char i2c_addr, const unsigned char *buf, unsigned int len)
{ {
while (i2c_regs->cmd_status & I2C_ST_BUSY) unsigned i = WATCHDOG;
; while ((i != 0) && (i2c_regs->cmd_status & I2C_ST_BUSY))
--i;
if (i == 0) {
puts("i2c_write WATCHDOG failed!");
return false;
}
i2c_regs->data = (i2c_addr << 1) | 0; // 7 bit address and write bit (0) i2c_regs->data = (i2c_addr << 1) | 0; // 7 bit address and write bit (0)

View File

@@ -64,7 +64,9 @@ void do_the_bootload_thing(void) {
#else #else
spif_init(); //initialize SPI flash clock spif_init(); //initialize SPI flash clock
bool production_image = find_safe_booted_flag(); puts("SPI Flash has been initialized");
bool production_image = find_safe_booted_flag();
printf("Production image = %d\n", production_image); printf("Production image = %d\n", production_image);
set_safe_booted_flag(0); //haven't booted yet set_safe_booted_flag(0); //haven't booted yet

View File

@@ -24,6 +24,9 @@
#include "spi_flash.h" #include "spi_flash.h"
#include "memory_map.h" #include "memory_map.h"
#define WATCHDOG 50000
#include <nonstdio.h>
void void
spif_init(void) spif_init(void)
{ {
@@ -39,8 +42,11 @@ spif_init(void)
inline void inline void
spif_wait(void) spif_wait(void)
{ {
while (spif_regs->ctrl & SPI_CTRL_GO_BSY) unsigned i = WATCHDOG;
; while ((i != 0) && (spif_regs->ctrl & SPI_CTRL_GO_BSY))
--i;
if (i == 0)
puts("spif_wait WATCHDOG failed!");
} }
uint32_t uint32_t