| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
#include "carl9170.h" |
| 26 |
#include "timer.h" |
| 27 |
#include "hostif.h" |
| 28 |
#include "printf.h" |
| 29 |
#include "gpio.h" |
| 30 |
#include "wl.h" |
| 31 |
#include "rf.h" |
| 32 |
#include "usb.h" |
| 33 |
|
| 34 |
#define AR9170_WATCH_DOG_TIMER 0x100 |
| 35 |
|
| 36 |
static void init(void) |
| 37 |
{ |
| 38 |
led_init(); |
| 39 |
|
| 40 |
#ifdef CONFIG_CARL9170FW_DEBUG_UART |
| 41 |
uart_init(); |
| 42 |
#endif |
| 43 |
|
| 44 |
|
| 45 |
timer_init(0, 50000); |
| 46 |
|
| 47 |
|
| 48 |
usb_init(); |
| 49 |
|
| 50 |
|
| 51 |
memset(&dma_mem, 0, sizeof(dma_mem)); |
| 52 |
|
| 53 |
|
| 54 |
dma_init_descriptors(); |
| 55 |
|
| 56 |
|
| 57 |
set(AR9170_MAC_REG_INT_CTRL, 0xffff); |
| 58 |
|
| 59 |
orl(AR9170_MAC_REG_AFTER_PNP, 1); |
| 60 |
|
| 61 |
|
| 62 |
fw.watchdog_enable = 1; |
| 63 |
|
| 64 |
set(AR9170_TIMER_REG_WATCH_DOG, AR9170_WATCH_DOG_TIMER); |
| 65 |
|
| 66 |
#ifdef CONFIG_CARL9170FW_GPIO_INTERRUPT |
| 67 |
fw.cached_gpio_state.gpio = get(AR9170_GPIO_REG_PORT_DATA) & |
| 68 |
CARL9170_GPIO_MASK; |
| 69 |
#endif |
| 70 |
|
| 71 |
|
| 72 |
down_trigger(); |
| 73 |
} |
| 74 |
|
| 75 |
static void handle_fw(void) |
| 76 |
{ |
| 77 |
if (fw.watchdog_enable == 1) |
| 78 |
set(AR9170_TIMER_REG_WATCH_DOG, AR9170_WATCH_DOG_TIMER); |
| 79 |
|
| 80 |
if (fw.reboot) |
| 81 |
reboot(); |
| 82 |
} |
| 83 |
|
| 84 |
static void tally_update(void) |
| 85 |
{ |
| 86 |
unsigned int time; |
| 87 |
|
| 88 |
time = get_clock_counter(); |
| 89 |
#ifdef CONFIG_CARL9170FW_RADIO_FUNCTIONS |
| 90 |
if (fw.phy.state == CARL9170_PHY_ON) { |
| 91 |
unsigned int boff, delta; |
| 92 |
|
| 93 |
delta = (time - fw.tally_clock); |
| 94 |
|
| 95 |
fw.tally.active += delta; |
| 96 |
|
| 97 |
boff = get(AR9170_MAC_REG_BACKOFF_STATUS); |
| 98 |
if (boff & AR9170_MAC_BACKOFF_TX_PE) |
| 99 |
fw.tally.tx_time += delta; |
| 100 |
if (boff & AR9170_MAC_BACKOFF_CCA) |
| 101 |
fw.tally.cca += delta; |
| 102 |
} |
| 103 |
#endif |
| 104 |
fw.tally_clock = time; |
| 105 |
fw.counter++; |
| 106 |
} |
| 107 |
|
| 108 |
static void __noreturn main_loop(void) |
| 109 |
{ |
| 110 |
|
| 111 |
while (1) { |
| 112 |
handle_fw(); |
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
handle_wlan(); |
| 119 |
|
| 120 |
handle_host_interface(); |
| 121 |
|
| 122 |
handle_usb(); |
| 123 |
|
| 124 |
handle_timer(); |
| 125 |
|
| 126 |
tally_update(); |
| 127 |
} |
| 128 |
} |
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
void __in_section(boot) __noreturn __visible start(void) |
| 141 |
{ |
| 142 |
clock_set(AHB_40MHZ_OSC, true); |
| 143 |
|
| 144 |
|
| 145 |
if ((get(AR9170_PWR_REG_WATCH_DOG_MAGIC) & 0xffff0000) == 0x12340000) { |
| 146 |
|
| 147 |
incl(AR9170_PWR_REG_WATCH_DOG_MAGIC); |
| 148 |
usb_trigger_out(); |
| 149 |
} else if ((get(AR9170_PWR_REG_WATCH_DOG_MAGIC) & 0xffff0000) == 0x98760000) { |
| 150 |
|
| 151 |
} |
| 152 |
|
| 153 |
|
| 154 |
andl(AR9170_PWR_REG_WATCH_DOG_MAGIC, 0xFFFF); |
| 155 |
orl(AR9170_PWR_REG_WATCH_DOG_MAGIC, 0x12340000); |
| 156 |
|
| 157 |
init(); |
| 158 |
|
| 159 |
#ifdef CONFIG_CARL9170FW_DEBUG |
| 160 |
|
| 161 |
BUG("TEST BUG"); |
| 162 |
BUG_ON(0x2b || !0x2b); |
| 163 |
INFO("INFO MESSAGE"); |
| 164 |
|
| 165 |
|
| 166 |
DBG("AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz" |
| 167 |
" ~`!1@2#3$4%%5^6&7*8(9)0_-+={[}]|\\:;\"'<,>.?/"); |
| 168 |
#endif |
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
send_cmd_to_host(0, CARL9170_RSP_BOOT, 0x00, NULL); |
| 175 |
main_loop(); |
| 176 |
} |