software/bios: factor out busy_wait() function

Signed-off-by: Gabriel Somlo <gsomlo@gmail.com>
This commit is contained in:
Gabriel Somlo 2020-03-27 06:58:06 -04:00
parent 540218b2d8
commit c6b6dee2e7
4 changed files with 14 additions and 22 deletions

View file

@ -143,16 +143,6 @@ void sdclk_set_clk(unsigned int freq) {
/* command utils */
static void busy_wait(unsigned int ms)
{
timer0_en_write(0);
timer0_reload_write(0);
timer0_load_write(CONFIG_CLOCK_FREQUENCY/1000*ms);
timer0_en_write(1);
timer0_update_value_write(1);
while(timer0_value_read()) timer0_update_value_write(1);
}
static void sdtimer_init(void)
{
sdtimer_en_write(0);

View file

@ -9,6 +9,8 @@ void flush_cpu_icache(void);
void flush_cpu_dcache(void);
void flush_l2_cache(void);
void busy_wait(unsigned int ms);
#ifdef __or1k__
#include <spr-defs.h>
static inline unsigned long mfspr(unsigned long add)

View file

@ -128,3 +128,13 @@ void flush_l2_cache(void)
}
}
#endif
void busy_wait(unsigned int ms)
{
timer0_en_write(0);
timer0_reload_write(0);
timer0_load_write(CONFIG_CLOCK_FREQUENCY/1000*ms);
timer0_en_write(1);
timer0_update_value_write(1);
while(timer0_value_read()) timer0_update_value_write(1);
}

View file

@ -448,24 +448,14 @@ void microudp_service(void)
}
}
static void busy_wait(unsigned int ds)
{
timer0_en_write(0);
timer0_reload_write(0);
timer0_load_write(CONFIG_CLOCK_FREQUENCY/10*ds);
timer0_en_write(1);
timer0_update_value_write(1);
while(timer0_value_read()) timer0_update_value_write(1);
}
void eth_init(void)
{
printf("Ethernet init...\n");
#ifdef CSR_ETHPHY_CRG_RESET_ADDR
ethphy_crg_reset_write(1);
busy_wait(2);
busy_wait(200);
ethphy_crg_reset_write(0);
busy_wait(2);
busy_wait(200);
#endif
}