- Main Page
- Modules
- Data Structures
- Files

- File List
- Globals

# /space/home/slher/rel/Beken/v6_4_5/macsw/modules/ke/src/ke_event.c

Go to the documentation of this file.

    00001
    00020 /*
    00021  * INCLUDE FILES
    00022  ****************************************************************************************
    00023  */
    00024 #include <stddef.h>
    00025 #include "co_int.h"
    00026 #include "co_bool.h"
    00027
    00028 #include "rwnx_config.h"
    00029 #include "dbg_assert.h"
    00030
    00031 #include "ke_event.h"
    00032 #include "ke_env.h"
    00033 #include "ke_mem.h"
    00034 #include "mm_timer.h"
    00035
    00036
    00037 /*
    00038  * TABLE OF EVENT HANDLERS
    00039  ****************************************************************************************
    00040  */
    00042 typedef void (*evt_ptr_t)(int);
    00043
    00045 struct ke_evt_tag
    00046 {
    00048     evt_ptr_t func;
    00050     int       param;
    00051 };
    00052
    00053 // Include files used to retrieve the event handler function pointers
    00054 #include "ke_task.h"
    00055 #include "ke_timer.h"
    00056 #include "ipc_emb.h"
    00057 #include "macif.h"
    00058 #include "hal_dma.h"
    00059
    00060 #include "txl_cntrl.h"
    00061 #include "rxl_cntrl.h"
    00062 #if NX_UMAC_PRESENT
    00063 #include "rxu_cntrl.h"
    00064 #endif
    00065 #if NX_TX_FRAME
    00066 #include "txl_frame.h"
    00067 #endif
    00068 #include "txl_cfm.h"
    00069 #include "mm.h"
    00070 #include "rwnx.h"
    00071
    00073 static const struct ke_evt_tag ke_evt_hdlr[32] =
    00074 {
    00075     [KE_EVT_RESET         ]     = {&rwnxl_reset_evt, 0},
    00076     #if NX_GP_DMA
    00077     [KE_EVT_GP_DMA_DL     ]     = {&hal_dma_evt, DMA_DL},
    00078     [KE_EVT_GP_DMA_UL     ]     = {&hal_dma_evt, DMA_UL},
    00079     #endif
    00080     #if NX_MM_TIMER
    00081     [KE_EVT_MM_TIMER      ]     = {&mm_timer_schedule, 0},
    00082     #endif
    00083     [KE_EVT_KE_TIMER      ]     = {&ke_timer_schedule, 0},
    00084     [KE_EVT_KE_MESSAGE    ]     = {&ke_task_schedule, 0},
    00085     [KE_EVT_HW_IDLE       ]     = {&mm_hw_idle_evt, 0},
    00086     #if NX_BEACONING || ((NX_POWERSAVE || NX_CONNECTION_MONITOR || NX_UMAC_PRESENT) && !NX_MULTI_ROLE)
    00087     [KE_EVT_PRIMARY_TBTT  ]     = {&mm_tbtt_evt, 0},
    00088     #endif
    00089     #if NX_BEACONING
    00090     [KE_EVT_SECONDARY_TBTT]     = {&mm_tbtt_evt, 0},
    00091     #endif
    00092     #if NX_UMAC_PRESENT
    00093     [KE_EVT_RXUREADY      ]     = {&rxu_cntrl_evt, 0},
    00094     #endif
    00095     [KE_EVT_RXREADY       ]     = {&rxl_cntrl_evt, 0},
    00096     [KE_EVT_RXUPLOADED    ]     = {&rxl_dma_evt, 0},
    00097     #if NX_TX_FRAME
    00098     [KE_EVT_TXFRAME_CFM   ]     = {&txl_frame_evt, 0},
    00099     #endif
    00100     #if NX_BEACONING
    00101     [KE_EVT_MACIF_TXDESC_BCN]     = {&macif_tx_evt, AC_BCN},
    00102     #endif
    00103     [KE_EVT_MACIF_TXDESC_AC3]     = {&macif_tx_evt, AC_VO},
    00104     [KE_EVT_MACIF_TXDESC_AC2]     = {&macif_tx_evt, AC_VI},
    00105     [KE_EVT_MACIF_TXDESC_AC1]     = {&macif_tx_evt, AC_BE},
    00106     [KE_EVT_MACIF_TXDESC_AC0]     = {&macif_tx_evt, AC_BK},
    00107     [KE_EVT_MACIF_MSG       ]     = {&macif_msg_evt, 0},
    00108     #if NX_BEACONING
    00109     [KE_EVT_TXCFM_BCN     ]     = {&txl_cfm_evt, AC_BCN},
    00110     #endif
    00111     [KE_EVT_TXCFM_AC3     ]     = {&txl_cfm_evt, AC_VO},
    00112     [KE_EVT_TXCFM_AC2     ]     = {&txl_cfm_evt, AC_VI},
    00113     [KE_EVT_TXCFM_AC1     ]     = {&txl_cfm_evt, AC_BE},
    00114     [KE_EVT_TXCFM_AC0     ]     = {&txl_cfm_evt, AC_BK},
    00115 };
    00116
    00117
    00129 void ke_evt_set(evt_field_t const event)
    00130 {
    00131     GLOBAL_INT_DISABLE();
    00132     ke_env.evt_field |= event;
    00133     GLOBAL_INT_RESTORE();
    00134 }
    00135
    00146 void ke_evt_clear(evt_field_t const event)
    00147 {
    00148     GLOBAL_INT_DISABLE();
    00149     ke_env.evt_field &= ~event;
    00150     GLOBAL_INT_RESTORE();
    00151 }
    00152
    00153
    00163 void ke_evt_schedule(void)
    00164 {
    00165     // Get the volatile value
    00166     uint32_t field = ke_env.evt_field;
    00167
    00168     while (field) // Compiler is assumed to optimize with loop inversion
    00169     {
    00170         // Find highest priority event set
    00171         uint32_t event = co_clz(field);
    00172
    00173         // Sanity check
    00174         ASSERT_ERR((event < KE_EVT_MAX) && ke_evt_hdlr[event].func);
    00175
    00176         // Execute corresponding handler
    00177         (ke_evt_hdlr[event].func)(ke_evt_hdlr[event].param);
    00178
    00179         // Update the volatile value
    00180         field = ke_env.evt_field;
    00181     }
    00182 }
    00183
    00193 void ke_init(void)
    00194 {
    00195     // ke_mem_init MUST be called first to be able to allocate memory right from start
    00196     #if KE_MEM_NX
    00197     ke_env.mblock_first = ke_mem_init();
    00198
    00199     #if KE_PROFILING
    00200     ke_env.max_heap_used = 0;
    00201     #endif //KE_PROFILING
    00202     #endif //KE_MEM_RW
    00203
    00204     // initialize the kernel message queue, mandatory before any message can be transmitted
    00205     ke_env.queue_saved.first = NULL;
    00206     ke_env.queue_saved.last = NULL;
    00207     ke_env.queue_sent.first = NULL;
    00208     ke_env.queue_sent.last = NULL;
    00209     ke_env.queue_timer.first = NULL;
    00210     ke_env.queue_timer.last = NULL;
    00211
    00212     // clears all possible pending events
    00213     ke_evt_clear(0xFFFFFFFF);
    00214 }
    00215
    00223 void ke_flush(void)
    00224 {
    00225     // free all pending message(s)
    00226     while(1)
    00227     {
    00228         struct ke_msg *msg = (struct ke_msg*) ke_queue_pop(&ke_env.queue_sent);
    00229         if(msg == NULL)
    00230             break;
    00231         ke_msg_free(msg);
    00232     }
    00233     // free all saved message(s)
    00234     while(1)
    00235     {
    00236         struct ke_msg *msg = (struct ke_msg*) ke_queue_pop(&ke_env.queue_saved);
    00237         if(msg == NULL)
    00238             break;
    00239         ke_msg_free(msg);
    00240     }
    00241     // free all timers
    00242     while(1)
    00243     {
    00244         struct ke_timer *timer = (struct ke_timer*) ke_queue_pop(&ke_env.queue_timer);
    00245         if(timer == NULL)
    00246             break;
    00247         ke_free(timer);
    00248     }
    00249
    00250     // clears all possible pending events
    00251     ke_evt_clear(0xFFFFFFFF);
    00252 }
    00253