summaryrefslogtreecommitdiff
path: root/cesar/mac/sar/inc/sar_context.h
blob: ec3965b6de665ea8ea5268baabd86e2122c54196 (plain)
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
#ifndef SAR_CONTEXT_H_
#define SAR_CONTEXT_H_

/* Cesar project {{{
 *
 * Copyright (C) 2007 Spidcom
 *
 * <<<Licence>>>
 *
 * }}} */
/**
 * \file    mac/sar/inc/sar_context.h
 * \brief   SAR context declarations.
 * \ingroup mac_sar
 */

#include "mac/pbproc/pbproc.h"
#include "lib/slist.h"
#include "lib/rnd.h"
#include "lib/seq_check.h"
#include "hal/phy/bridgedma.h"

#ifdef STATION_H_
#include "hal/phy/forward.h"
#include "hal/phy/maximus/inc/maximus_interrupts.h"
#include "hal/phy/maximus/inc/maximus_phy_ctx.h"
#endif

#include "mac/sar/sar.h"
#include "mac/sar/sar_mf.h"
#include "mac/sar/sar_pb_stats.h"
#include "mac/sar/inc/sar_expiration.h"
#include "mac/sar/inc/sar_pb.h"
#include "mac/sar/inc/sar_job_mfs.h"
#include "mac/sar/inc/trace.h"
#include "config/stats.h"
#include "config/sar.h"
#include "common/defs/priority.h"

/** Invalid SSN. */
#define SAR_SSN_INVALID 0x10000

struct sar_mpdu_t
{
    /** Received frame. */
    pbproc_rx_t rx;
    /** Arrival time of the frame in NTB ticks. */
    u32 arrival_ntb;
};
typedef struct sar_mpdu_t sar_mpdu_t;

struct sar_msdu_t
{
    /** Ats confounder field*/
    u32 ats_confounder;
    /** type and length of the data to segment */
    u16 length;
    /** The buffer address to use */
    u8 *buffer_address;
    /** the associated MFS */
    mfs_tx_t *mfs;
    /** User data. */
    void *user_data;
    /** Arrival time in NTB. */
    u32 arrival_ntb;
};
typedef struct sar_msdu_t sar_msdu_t;

struct sar_buffer_t
{
    /** Next pointer. */
    struct sar_buffer_t *next;
};
typedef struct sar_buffer_t sar_buffer_t;

struct sar_buffer_list_t
{
    /** List head. */
    sar_buffer_t *head;
    /** List tail. */
    sar_buffer_t *tail;
};
typedef struct sar_buffer_list_t sar_buffer_list_t;

struct sar_bridgedma_pending_list_t
{
    /* list head. */
    sar_job_mfs_t *head;
    /* list tail. */
    sar_job_mfs_t *tail;
};
typedef struct sar_bridgedma_pending_list_t sar_bridgedma_pending_list_t;

struct sar_reassembly_ctx_t
{
    /** SAR reassembly done callback function. */
    sar_reassembly_done_cb_t sar_rea_done;
    /** SAR job pending list. */
    sar_bridgedma_pending_list_t jobs_pending_list;
    /** SAR buffer list containing reassembly buffers. */
    sar_buffer_list_t buffer_list;
};
typedef struct sar_reassembly_ctx_t sar_reassembly_ctx_t;

#if CONFIG_STATS
/**
 * Statistics gathered by the SAR module.
 */
struct sar_stats_t
{
    /** Total number of PB received by ourself (from anyone). */
    u32 rx_pb_count;
    /** Total number of PB with a CRC error received by ourself (from
     * anyone). */
    u32 rx_pb_crc_error_count;
    /** BER sum of all PBs correct received from any station in the AVLN. */
    u64 ber_sum;
    /** Number of times the PBPool had not been filled. */
    u32 pb_pool_not_filled;
};
typedef struct sar_stats_t sar_stats_t;
#endif

struct sar_pb_stats_t
{
    blk_table_t *table;
    sar_pb_stats_entry_t *current_entry;
    uint write_index;
    uint amount_to_read;
    uint amount_read;

    uint control_reg;
    uint current_pb;
    u8 current_stei_filter;
    u8 enable;
};
typedef struct sar_pb_stats_t sar_pb_stats_t;

/** SAR context */
struct sar_t
{
    /** Mac store. */
    mac_store_t *mac_store;
    /** Channel access. */
    ca_t *ca;
    /** inform the upper layer when a job had been bridged
     * Initialized in sar_segmentation_init_mme_cb */
    sar_segmentation_done_cb_t sar_seg_data_done_cb;

    /** inform the upper layer when a job had been bridged
     * Initialized in sar_segmentation_init_data_cb*/
    sar_segmentation_done_cb_t sar_seg_msg_done_cb;

    /** Call back pointer for measurement data
     * Data initialized in the sar_init_measurement_cb */
    sar_measurement_cb_t sar_measurement;

    /** SAR context for the DATA reassembly
     * sar_init_reassembly_data_cb */
    sar_reassembly_ctx_t data_ctx;

    /** SAR context for the MME reassembly
     * sar_init_reassembly_mme_cb */
    sar_reassembly_ctx_t mme_ctx;

    /** beacon function call back */
    void *beacon_user_data;
    sar_beacon_cb_t beacon_function_cb;

    /** Activated. */
    bool activate;

    /** Random generator context. */
    lib_rnd_t rnd_gen;

    /** Missing PBs number to allocate for the PB Pool. */
    uint pbs_missing_for_pbproc;
    /** DMA pointer to TX static SAR job descriptor . */
    sar_job_mfs_t *job_tx;

    /** ****************** Layers context ***************/

    /** Bridge DMA context
     * Data initialized in the sar_init */
    phy_bridgedma_t *bridgedma_ctx;

    /** Pb proc call back to provide pbs */
    pbproc_t *pbproc_ctx;

    /** Channel estimation ctx */
    void *ul_ce_ctx;

    /** data context */
    void *ul_data_ctx;

    /** message context */
    void *ul_msg_ctx;

    /** Thread context. */
    u8 thread_stack [MAC_SAR_THREAD_STACK_SIZE];
    cyg_handle_t thread_handle;
    cyg_thread thread;

    /** Tracing system */
#if CONFIG_TRACE
    /** SAR Trace */
    trace_buffer_t trace;
#endif /* !CONFIG_TRACE */
#if CONFIG_STATS
    sar_stats_t stats;
#endif
#if CONFIG_SEQ_CHECK
    lib_seq_check_t seq;
#endif
#if CONFIG_SAR_PB_STATS
    sar_pb_stats_t pb_stats;
#endif
};

#endif /*SAR_CONTEXT_H_*/