00001
00020
00021
00022
00023
00024 #include "version.h"
00025 #include "dbg.h"
00026 #include "ke_event.h"
00027 #include "mm.h"
00028 #include "hal_machw.h"
00029 #include "rxl_cntrl.h"
00030 #include "txl_cntrl.h"
00031 #include "ps.h"
00032 #include "rwnx.h"
00033 #include "macif.h"
00034 #if (NX_TX_FRAME)
00035 #include "vif_mgmt.h"
00036 #endif //(NX_TX_FRAME)
00037 #if NX_UMAC_PRESENT
00038 #include "me.h"
00039 #endif
00040 #ifdef CFG_RTOS
00041 #include "rtos.h"
00042 #endif
00043 #if NX_FULLY_HOSTED
00044 #include "fhost.h"
00045 #endif
00046
00047
00048
00049
00050
00051 #if NX_POWERSAVE
00053 struct rwnx_env_tag
00054 {
00056 uint8_t prev_hw_state;
00058 bool hw_in_doze;
00059 };
00060
00062 static struct rwnx_env_tag rwnx_env;
00063 #endif
00064
00065
00066
00067
00068
00069
00070 void rwnxl_init(void)
00071 {
00072
00073 trace_init(false, true);
00074
00075 #if NX_POWERSAVE
00076 rwnx_env.hw_in_doze = false;
00077 #endif
00078
00079
00080 dbg_init();
00081
00082 #if NX_UMAC_PRESENT
00083
00084 me_init();
00085 #endif
00086
00087
00088 mm_init();
00089
00090
00091 ke_init();
00092
00093 #if NX_SYS_STAT
00094
00095 dbg_sys_stat_reset();
00096 #endif
00097
00098
00099 macif_init();
00100 }
00101
00102 void rwnxl_start(void)
00103 {
00104
00105 dbg(D_CRT "%s - build: %s\n", nx_version_str, nx_build_date);
00106 #if NX_FULLY_HOSTED
00107 dbg(D_CRT "%s", nx_build_fhost);
00108 #endif
00109
00110
00111 #if NX_PROFILING_ON
00112 if (DBG_PROF_MAX != 0)
00113 {
00114 dbg(D_CRT "SW profiling configuration:\n");
00115 for (int i = 0; i < DBG_PROF_MAX; i++)
00116 {
00117 dbg(D_CRT " - %s: %d\n", dbg_prof_conf[i], i);
00118 }
00119 }
00120 #endif
00121
00122 #ifndef CFG_RTOS
00123 GLOBAL_INT_START();
00124
00125 for (;;)
00126 {
00127
00128 ke_evt_schedule();
00129
00130 #if NX_POWERSAVE
00131
00132 GLOBAL_INT_DISABLE();
00133
00134 if (rwnxl_cpu_can_sleep())
00135 {
00136
00137 rwnxl_sleep();
00138
00139
00140 WFI();
00141
00142
00143 rwnxl_wakeup();
00144 }
00145
00146
00147 GLOBAL_INT_RESTORE();
00148 #endif
00149 }
00150
00151 #else
00152 if (rtos_init())
00153 {
00154 ASSERT_ERR(0);
00155 }
00156
00157 #if NX_FULLY_HOSTED
00158 if (fhost_init(false) || fhost_application_init())
00159 {
00160 ASSERT_ERR(0);
00161 }
00162
00163 #else
00164 if (rtos_wifi_task_create())
00165 {
00166 ASSERT_ERR(0);
00167 }
00168 #endif // NX_FULLY_HOSTED
00169
00170
00171 rtos_start_scheduler();
00172 for( ;; );
00173
00174 #endif // CFG_RTOS
00175 }
00176
00177
00178 void rwnxl_reset_evt(int dummy)
00179 {
00180
00181 GLOBAL_INT_DISABLE();
00182
00183
00184 ke_evt_clear(KE_EVT_RESET_BIT);
00185
00186 #if NX_DEBUG_DUMP
00187
00188 hal_machw_get_diag_state();
00189 #endif
00190
00191
00192 hal_machw_reset();
00193
00194 #if NX_DEBUG_DUMP
00195
00196 dbg_error_ind(dbg_env.error, DBG_ERROR_RECOVERABLE);
00197 #endif
00198
00199
00200 rxl_reset();
00201
00202
00203 txl_reset();
00204
00205
00206 mm_reset();
00207
00208 #if (NX_TX_FRAME)
00209
00210 vif_mgmt_reset();
00211 #endif //(NX_TX_FRAME)
00212
00213
00214 GLOBAL_INT_RESTORE();
00215 }
00216
00217 bool rwnxl_cpu_can_sleep(void)
00218 {
00219 return (ke_evt_get() == 0);
00220 }
00221
00222 void rwnxl_sleep(void)
00223 {
00224 #if NX_POWERSAVE
00225
00226 if (!ps_sleep_check())
00227 return;
00228
00229
00230 if (!txl_sleep_check())
00231 return;
00232
00233
00234 if (!hal_machw_sleep_check())
00235 return;
00236
00237
00238 rwnx_env.prev_hw_state = nxmac_current_state_getf();
00239
00240
00241 if (nxmac_current_state_getf() != HW_IDLE)
00242 {
00243 nxmac_enable_master_gen_int_en_setf(0);
00244 nxmac_next_state_setf(HW_IDLE);
00245 while (nxmac_status_idle_interrupt_getf() != 1);
00246 nxmac_gen_int_ack_clear(NXMAC_IDLE_INTERRUPT_BIT);
00247 nxmac_enable_master_gen_int_en_setf(1);
00248 }
00249
00250 TRACE_LMAC(DOZE, "MACHW enters DOZE mode");
00251
00252
00253 DBG_DOZE_START();
00254 rwnx_env.hw_in_doze = true;
00255 nxmac_next_state_setf(HW_DOZE);
00256 #endif // NX_POWERSAVE
00257 }
00258
00259 void rwnxl_wakeup(void)
00260 {
00261 #if NX_POWERSAVE
00262 if (rwnx_env.hw_in_doze)
00263 {
00264 nxmac_enable_master_gen_int_en_setf(0);
00265
00266 nxmac_wake_up_from_doze_setf(1);
00267 rwnx_env.hw_in_doze = false;
00268
00269
00270 while (nxmac_status_idle_interrupt_getf() != 1);
00271 nxmac_gen_int_ack_clear(NXMAC_IDLE_INTERRUPT_BIT);
00272 nxmac_enable_master_gen_int_en_setf(1);
00273
00274
00275 DBG_DOZE_END();
00276
00277
00278 if (rwnx_env.prev_hw_state != HW_IDLE)
00279 {
00280 nxmac_next_state_setf(rwnx_env.prev_hw_state);
00281 while (nxmac_current_state_getf() != rwnx_env.prev_hw_state);
00282 }
00283
00284
00285 nxmac_wake_up_from_doze_setf(0);
00286
00287 TRACE_LMAC(DOZE, "MACHW exits DOZE mode");
00288 }
00289 #endif // NX_POWERSAVE
00290 }
00291
00292