Initial cut of the open ath9k htc firmware.
[open-ath9k-htc-firmware.git] / target_firmware / magpie_fw_dev / target / cmnos / k2_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 // 
16 a_uint32_t cmnos_refclk_speed_get_patch(void)
17 {
18     return ref_clk;
19 }
20
21
22 // software emulate delay function
23 //
24 void cmnos_delay_us_patch(int us)
25 {
26     a_uint32_t start_time = NOW();
27     unsigned int num_ticks = us*ref_clk; // system_freq == number of ticks per 1us
28     
29     while ( (NOW() - start_time) < num_ticks) {
30         /* busy spin */
31         ;
32     }
33 }
34
35
36 // software emulate microsecond ticks
37 //
38 void cmnos_tick_patch(void)
39 {
40     static a_uint32_t last_tick = 0;
41     a_uint32_t current_tick = NOW();
42     a_uint32_t delta_tick;
43
44     delta_tick = (A_UINT32 ) (current_tick - last_tick)/(ref_clk<<10);
45
46     if( delta_tick > 0 )
47         last_tick = current_tick;
48
49     cticks += delta_tick;
50 }
51
52 // get current sysmem up time in milliseconds based
53 // 
54 a_uint32_t cmnos_milliseconds_patch(void)
55 {
56     cmnos_tick_patch();
57     
58     return (cticks);
59 }
60