mirror of
https://github.com/fairwaves/UHD-Fairwaves.git
synced 2025-10-23 07:42:00 +00:00
zpu: add watchdog timer for while( ... ); operations
This commit is contained in:
@@ -18,6 +18,7 @@
|
||||
#include "i2c.h"
|
||||
#include "mdelay.h"
|
||||
#include "usrp2/fw_common.h"
|
||||
#include "nonstdio.h"
|
||||
|
||||
static const int EEPROM_PAGESIZE = 16;
|
||||
|
||||
@@ -26,7 +27,11 @@ bool find_safe_booted_flag(void) {
|
||||
return 0;
|
||||
#else
|
||||
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);
|
||||
#endif
|
||||
}
|
||||
|
@@ -36,6 +36,8 @@ static uint16_t prescaler_values[MAX_WB_DIV+1] = {
|
||||
PRESCALER(4), // 4: 25 MHz
|
||||
};
|
||||
|
||||
#define WATCHDOG 50000
|
||||
|
||||
void
|
||||
i2c_init(void)
|
||||
{
|
||||
@@ -58,8 +60,13 @@ i2c_init(void)
|
||||
static inline 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
|
||||
@@ -79,8 +86,13 @@ i2c_read (unsigned char i2c_addr, unsigned char *buf, unsigned int len)
|
||||
if (len == 0) // reading zero bytes always works
|
||||
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)
|
||||
// generate START and write addr
|
||||
@@ -104,8 +116,13 @@ i2c_read (unsigned char i2c_addr, unsigned char *buf, unsigned int len)
|
||||
bool
|
||||
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)
|
||||
|
||||
|
@@ -64,7 +64,9 @@ void do_the_bootload_thing(void) {
|
||||
#else
|
||||
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);
|
||||
set_safe_booted_flag(0); //haven't booted yet
|
||||
|
||||
|
@@ -24,6 +24,9 @@
|
||||
#include "spi_flash.h"
|
||||
#include "memory_map.h"
|
||||
|
||||
#define WATCHDOG 50000
|
||||
#include <nonstdio.h>
|
||||
|
||||
void
|
||||
spif_init(void)
|
||||
{
|
||||
@@ -39,8 +42,11 @@ spif_init(void)
|
||||
inline 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
|
||||
|
Reference in New Issue
Block a user