#ifndef ce_inc_rx_h #define ce_inc_rx_h /* Cesar project {{{ * * Copyright (C) 2007 Spidcom * * <<>> * * }}} */ /** * * \file ../../inc/rx.h * * \brief « brief description » * * \ingroup * * * * « long description » * */ #include "ce/inc/cei_param.h" #include "ce/inc/mpdu_measure_store.h" #include "cyg/kernel/kapi.h" #include "lib/trace.h" #include "mac/sar/sar.h" #ifdef MAXIMUS_TEST #define TXCE #endif /** Priority of CEI message */ #define CEI_PRIORITY 2 // The MARGE can be optimized versus the stations number, and the knowledge of // worst case where rxce can turned. #ifndef EXPIRATION_TEST #define RXCE_TONEMAPS_REFRESH_MARGIN_S 2 #define RXCE_TONEMAPS_REFRESH_PERIOD_S (TONEMAPS_LIFE_DURATION_S - RXCE_TONEMAPS_REFRESH_MARGIN_S) #else #define RXCE_TONEMAPS_REFRESH_MARGIN_S 1 #define RXCE_TONEMAPS_REFRESH_PERIOD_S (2 - RXCE_TONEMAPS_REFRESH_MARGIN_S) #endif /** Structure describing the last received sound frame situation */ struct sound_param_t { uint stei; uint reason_code; }; typedef struct sound_param_t sound_param_t; /** Global structure for rxce context. */ struct rxce_t { /** Semaphore incremented when rxce has something to do : * -PBproc would have a Sound complete flag. * -A CEI must be built (a cei_param has been added in the * cei_param_fifo.) * -Computation can be done. (A frame measurement has been added, but * not the first). * */ cyg_sem_t job; mac_store_t *mac_store_ctx; /** Pointer to global tonemask */ u8 *mask; /** Received sound frame information.*/ bool pbproc_need_scf; sound_param_t sound_param; mpdu_measure_store_t *mpdu_measure_store_ctx; /** Tracing system */ #if CONFIG_TRACE /** cl Trace */ trace_buffer_t trace; #endif /* !CONFIG_TRACE */ #ifdef RXCE_MONITORING /** Pipe to send measurement and tonemap when processed*/ int pipe_out_fd; char pipe_out_name[1024]; #endif }; typedef struct rxce_t rxce_t; #ifdef EXPIRATION_TEST typedef void ( *test_cb_t) (int); void rxce_init_test_cb (test_cb_t test); test_cb_t expiration_test; #endif BEGIN_DECLS /** * Initialize the global structure of rxce context. * \param mac_store_ctx Access to the sta. * \param mac_config_ctx Access to the tonemask. * \return the rxce context. * */ rxce_t * rxce_init (sar_t *sar_ctx, mac_store_t *mac_store_ctx, mac_config_t *mac_config_ctx); /** * Callback called by pbproc when it need to have a SCF i.e when it receives a * sound frame. If CE is late, pbproc returns a SCF to false. * \param tei tei of station that has sent the sound frame. * \param src SoundReasonCode :why station has sent the sound frame. * * The rxce initialize the pbproc status variables and add a job to do. */ void pbproc_need_scf_cb (uint tei, uint src); /** * Callback called by SAR when it need to has new pb measurement. This * function add the pb measurement in the list of frame measurement. * \param user . * \param rx_params Frame reception condition. * \param pb_nb The pb measurement number that the SAR wants to dispose. * \param first First descriptor and so data block where to store pb * measurement. * \param last Last descriptor and so data block where to store pb * measurement. */ bool // does channel estimation need pb_measurement? rxce_mpdu_measurement_add (void *user, pbproc_rx_params_t *rx_params, uint pb_nb, blk_t **first, blk_t **last, pb_t *noise, uint n, uint *blk_offset); /** * Add a 'cei message job' for each tonemaps that must be updated and evaluate * the next milestone to redo it. * \param ctx rxce context * \return the next refresh date. * * For rx_tonemaps, the expiration_rtc_date must be interpreted as a * refresh_rtc_date that is the expiration_rtc_date less a marging to allow the * CP to create cei message, to the lower layers to send it, and the * destination station to receive it. * Dates are expressed in rtc, real-time clock is ecos context, i.e. the tick * ecos. (certainly 10ms). * Algorithm runs stupidly all tonemaps. An optimized algorithm with a * management of a tree could be envisaged. */ cyg_tick_count_t rxce_tonemaps_refresh_management(rxce_t *ctx); /** * Determine the value of SCF that PBproc must answer to the station * sound transmitter versus the announced SRC stored in rxce context. * \return SCF to be sent by PBproc. * * Function called in rxce process when there is a new 'pbproc need scf job' * to do. */ bool compute_scf (rxce_t *ctx); /** * Compute the first frame measurement present in the list of frame * measurement. * * Function called in rxce process when there is a 'frame measurement job' to * do. */ void rxce_next_measurement_compute (rxce_t *ctx); /** * Main thread of rxce. * \param data allows the pass the rxce context. * * rxce_process wait on the 'job' semaphore. The several callback can * provide new 'jobs'. Three sort of 'job' exists : * -PBproc need to know the scf to return. * -A station need or must receive a CEI to update its set of tonemaps. * -Noise (any frame measurement) are waiting to be computed. * Those 'jobs' are described by priority order. * * More, the semaphore can be timeout in order to ensure tonemaps refresh. * Timeout is reestimatimate at each loop of the process thanks to * rxce_tonemaps_refresh_management. */ void rxce_process (cyg_addrword_t data); /** * Add a job for rxce that will create and add a cei message to transmit * \param ctx rxce context. * \param tms set of tonemaps to encode in cei message. * \param new_tmi new tmi created if necessary, else NULL_TONEMAP_INDEX. * \param old_tmi tmi that new_tmi will replace. * \param dtei destination tei of cei message. * */ void rxce_job_cei_add (rxce_t *ctx, uint dtei, tonemaps_t *tms, uint new_tmi, uint old_tmi); END_DECLS #endif /* ce_inc_rx_h */