Initial cut of the open ath9k htc firmware.
[open-ath9k-htc-firmware.git] / target_firmware / magpie_fw_dev / target / rompatch / cmnos_clock_patch.c
1 #include "athos_api.h"
2 #include "sys_cfg.h"
3
4 a_uint32_t ref_clk = 0;
5 extern a_uint32_t cticks;
6
7 // clock change 
8 //
9 void cmnos_clock_init_patch(a_uint32_t refclk)
10 {
11     ref_clk = refclk;
12 }
13
14 // retrieve current clock setting
15 a_uint32_t cmnos_refclk_speed_get_patch(void)
16 {
17     return ref_clk;
18 }
19
20
21 // software emulate delay function
22 void cmnos_delay_us_patch(int us)
23 {
24     a_uint32_t start_time = NOW();
25     unsigned int num_ticks = us*ref_clk; // system_freq == number of ticks per 1us
26     
27     while ( (NOW() - start_time) < num_ticks) {
28         /* busy spin */
29         ;
30     }
31 }
32
33
34 // software emulate microsecond ticks
35 void cmnos_tick_patch(void)
36 {
37     static a_uint32_t last_tick = 0;
38     a_uint32_t current_tick = NOW();
39     a_uint32_t delta_tick;
40
41     delta_tick = (A_UINT32 ) (current_tick - last_tick)/(ref_clk<<10);
42
43     if( delta_tick > 0 )
44         last_tick = current_tick;
45
46     cticks += delta_tick;
47 }
48
49 // get current sysmem up time in milliseconds based
50 a_uint32_t cmnos_milliseconds_patch(void)
51 {
52     cmnos_tick_patch();
53     
54     return (cticks);
55 }