- Main Page
- Modules
- Data Structures
- Files

- File List
- Globals

# /space/home/slher/rel/Beken/v6_4_5/macsw/ip/lmac/src/rd/rd.c

Go to the documentation of this file.

    00001
    00018 /*
    00019  * INCLUDE FILES
    00020  ****************************************************************************************
    00021  */
    00022 #include "co_int.h"
    00023 // For bool
    00024 #include "co_bool.h"
    00025 // For NULL
    00026 #include <string.h>
    00027 // For INLINE
    00028 #include "compiler.h"
    00029 // for Radar pulse interface
    00030 #include "phy.h"
    00031 // RX control inclusions
    00032 #include "rd.h"
    00033 // GP DMA descriptor allocation
    00034 #include "hal_dma.h"
    00035 // IPC host buffer allocation
    00036 #include "ipc_emb.h"
    00037 // For debug functions
    00038 #include "dbg.h"
    00039 // For HW/CPU buffer pointer manipulations
    00040 #include "co_utils.h"
    00041
    00042 #if NX_RADAR_DETECT
    00043
    00044 /*
    00045  * MACROS
    00046  ****************************************************************************************
    00047  */
    00048
    00049 /*
    00050  * GLOBAL VARIABLES
    00051  ****************************************************************************************
    00052  */
    00053 struct rd_env_tag rd_env;
    00054
    00055
    00056 /*
    00057  * FUNCTION DEFINITIONS
    00058  ****************************************************************************************
    00059  */
    00060
    00066 static void rd_dma_handler(void *env, int dma_type)
    00067 {
    00068     // Retrieve radar event from env
    00069     struct radar_event_desc *desc = (struct radar_event_desc *)env;
    00070
    00071     // Push it back to the free list - Must be done in critical section as the list is
    00072     // also manipulated under interrupt
    00073     GLOBAL_INT_DISABLE();
    00074     co_list_push_back(&rd_env.event_free_list, &desc->list_hdr);
    00075     GLOBAL_INT_RESTORE();
    00076
    00077     // call the LMAC-UMAC interface function to handle the frame
    00078     ipc_emb_radar_event_ind();
    00079 }
    00080
    00081 void rd_init(void)
    00082 {
    00083     int i;
    00084
    00086     co_list_init(&rd_env.event_free_list);
    00087
    00088     for (i = 0; i < RADAR_EVENT_MAX; i++)
    00089     {
    00090         struct radar_event_desc *desc = &radar_event_desc_array[i];
    00091
    00092         // Initialize descriptors
    00093         desc->dma_desc.src = CPU2HW(&desc->pulse_array);
    00094         desc->dma_desc.length = sizeof_b(desc->pulse_array);
    00095
    00096         desc->gp_dma_desc.dma_desc = &desc->dma_desc;
    00097         desc->gp_dma_desc.cb = rd_dma_handler;
    00098         desc->gp_dma_desc.env = desc;
    00099
    00100         co_list_push_back(&rd_env.event_free_list, &desc->list_hdr);
    00101     }
    00102 }
    00103
    00104 void rd_event_ind(int rd_idx)
    00105 {
    00106     struct radar_event_desc *desc;
    00107     uint32_t hostbuf;
    00108     int i;
    00109
    00110     // Loop until no more radar pulses are available in the PHY
    00111     while (phy_has_radar_pulse(rd_idx))
    00112     {
    00113         // Get a free event descriptor
    00114         desc = (struct radar_event_desc *)co_list_pop_front(&rd_env.event_free_list);
    00115         if (desc == NULL)
    00116             break;
    00117
    00118         // Get a host buffer for this event
    00119         hostbuf = ipc_emb_hostradarbuf_get();
    00120         if (hostbuf == 0)
    00121         {
    00122             // Push back the descriptor to the free list
    00123             co_list_push_back(&rd_env.event_free_list, &desc->list_hdr);
    00124             break;
    00125         }
    00126
    00127         // Initialize the descriptor
    00128         desc->pulse_array.cnt = 0;
    00129         desc->pulse_array.idx = rd_idx;
    00130         desc->dma_desc.dest = hostbuf;
    00131
    00132         // Call the PHY driver to get the pulses
    00133         for (i = 0; i < RADAR_PULSE_MAX; i++)
    00134         {
    00135             if (!phy_get_radar_pulse(rd_idx, &desc->pulse_array.pulse[i]))
    00136                 break;
    00137             desc->pulse_array.cnt++;
    00138         }
    00139
    00140         // Sanity check - we shall not send an empty event to the host
    00141         ASSERT_ERR(desc->pulse_array.cnt != 0);
    00142
    00143         // Program the DMA transfer to the host
    00144         hal_dma_push(&desc->gp_dma_desc, DMA_UL);
    00145     }
    00146 }
    00147
    00148 #endif
    00149