summaryrefslogtreecommitdiff
path: root/hal/phy/maximus/inc/maximus_phy_ctx.h
blob: 89ed03bf06cbccaaa382492423fb3b534d95e418 (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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
#ifndef hal_phy_maximus_inc_maximus_phy_context_h
#define hal_phy_maximus_inc_maximus_phy_context_h
/* Cesar project {{{
 *
 * Copyright (C) 2007 Spidcom
 *
 * <<<Licence>>>
 *
 * }}} */
/**
 * \file    hal/phy/maximus/inc/maximus_phy_context.h
 * \brief   HAL Phy context for Maximus.
 * \ingroup hal_phy_maximus
 */
#include <stdint.h> // for uint32_t type
#include "hal/phy/access.h"
#include "hal/phy/bridgedma.h"
#include "hal/phy/forward.h"
#include "hal/phy/pbdma.h"
#include "hal/phy/phy.h"
#include "mac/common/tonemap.h" // for 'TONEMAP_INDEX_NB'
#include "host/station.h"
#include "host/netclock.h"
#include "hal/phy/maximus/inc/maximus_trace.h"
#include "lib/rnd.h" // for 'lib_rnd_t'
#ifdef ECOS
#include <cyg/hal/drv_api.h>
#endif /* ECOS */

/** Phy access medium state enum for Maximus */
enum maximus_phy_medium_state_t
{
    MAXIMUS_PHY_MEDIUM_IDLE       = 0x00,
    MAXIMUS_PHY_MEDIUM_PRS0       = 0x01,
    MAXIMUS_PHY_MEDIUM_PRS1       = 0x02,
    MAXIMUS_PHY_MEDIUM_CW         = 0x03,
    MAXIMUS_PHY_MEDIUM_WAIT_CONF  = 0x04,
    MAXIMUS_PHY_MEDIUM_BUSY_RX    = 0x05,
    MAXIMUS_PHY_MEDIUM_BUSY_TX    = 0x06
};
typedef enum maximus_phy_medium_state_t maximus_phy_medium_state_t;

/** Phy RX_FC callback parameter structure for Maximus */
struct maximus_phy_rx_fc_param_t
{
    u32 rx_date;
    u32 *fc_av;
};
typedef struct maximus_phy_rx_fc_param_t maximus_phy_rx_fc_param_t;

/** Phy TX parameters structure for Maximus */
struct maximus_phy_tx_param_t
{
    /** Homeplug 1.0 frame control. */
    u32 fc_10;
    /** Frame control mode. */
    phy_fc_mode_t fc_mode;
    /** True if no data symbols will be sent. */
    bool short_ppdu;
    /** Modulation type. */
    phy_mod_t mod;
    /** TCC rate. */
    phy_fecrate_t fecrate;
    /** PB size. */
    phy_pb_size_t pb_size;
    /** Guard interval for third symbol and following symbols. */
    phy_gil_t gil;
    /** Tonemap index where tonemap is stored. */
    uint tonemap_index;
    /** Number of symbols. */
    uint symbol_nb;
    /** Frame control. */
    u32 fc_av[4];
    /** Id of netclock message sent by 'phy_tx_frame'. */
    netclock_id_t tx_frame_netclock_id;
    /** Callback contexts to insert into callback queue. */
    netclock_callback_t *tx_frame_netclock_cb;
    /** Unique ID incremented for each transmission (TONEMAP if used, PREAMBLE, FC, and MPDU). */
    uint16_t tx_id;
};
typedef struct maximus_phy_tx_param_t maximus_phy_tx_param_t;

/** Phy RX parameters structure for Maximus */
struct maximus_phy_rx_param_t
{
    /** Frame control mode. */
    phy_fc_mode_t fc_mode;
    /** True if no data symbols will be sent. */
    bool short_ppdu;
    /** Modulation type. */
    phy_mod_t mod;
    /** TCC rate. */
    phy_fecrate_t fecrate;
    /** PB size. */
    phy_pb_size_t pb_size;
    /** Guard interval for third symbol and following symbols. */
    phy_gil_t gil;
    /** Tonemap index where tonemap is stored. */
    uint tonemap_index;
    /** Number of symbols. */
    uint symbol_nb; // not used for Maximus version 1
    /** Homeplug 1.0 frame control. */
    u32 fc_10;
    /** Frame control. */
    u32 fc_av[4];
    /** Id of netclock message sent by 'phy_rx_activate'. */
    netclock_id_t rx_activate_netclock_id;
    /** Callback contexts to insert into callback queue. */
    netclock_callback_t *rx_activate_netclock_cb;
    /** Id of netclock message sent by 'maximus_phy_recv_preamble'. */
    netclock_id_t recv_preamble_netclock_id;
    /** Callback contexts to insert into callback queue. */
    netclock_callback_t *recv_preamble_netclock_cb;
    /** Transmission ID of the received frame (PREAMBLE, FC, MPDU, and NOISE if enabled). */
    uint16_t src_tx_id;
    /** Station ID of the received frame (PREAMBLE, FC, MPDU, and NOISE if enabled). */
    uint16_t src_station_id;
    /** Date of last start of preamble. */
    u32 preamble_start_date;
};
typedef struct maximus_phy_rx_param_t maximus_phy_rx_param_t;

/** Phy access structure for Maximus */
struct maximus_phy_access_t
{
    /** Channel access priority. Priority to assert in next PRP. Can be changed at anytime (by 'phy_access_backoff_update'). */
    u8 cap_mpdu;
    /** Current CAP asserted in previous PRP. Can be changed under conditions (by 'phy_access_backoff_update'). */
    u8 cap_sent;
    /** Medium CAP decoded in previous PRP. */
    u8 cap_medium;
    /** Number of slots measured since end of PRP and before PRE detection. */
    uint slot_count;
    /** Possible values are: IDLE, PRS0, PRS1, CW, BUSY. */
    maximus_phy_medium_state_t medium_state;
    /** Received PRS0. */
    bool prs0;
    /** PRP result. */
    bool prp_result;
    /** Id of netclock message sent by 'phy_access_backoff_start',
     * 'maximus_phy_access_backoff_cb' and 'maximus_phy_access_prs0_cb'. */
    netclock_id_t backoff_start_netclock_id;
     /** Callback context to insert into callback queue. */
    netclock_callback_t *backoff_start_netclock_cb;
    /** Id of netclock message sent by 'maximus_phy_access_backoff_cb' and 'maximus_phy_access_slot_count_cb'. */
    netclock_id_t backoff_slot_count_netclock_id;
    /** Callback context to insert into callback queue. */
    netclock_callback_t *backoff_slot_count_netclock_cb;
    /** Id of netclock message sent by 'phy_access_timer_program'. */
    netclock_id_t timer_program_netclock_id;
    /** Callback context to insert into callback queue. */
    netclock_callback_t *timer_program_netclock_cb;
};
typedef struct maximus_phy_access_t maximus_phy_access_t;

/** Phy control structure for Maximus */
struct maximus_phy_ctrl_t
{
    /** User data passed to 'extra_timer_cb'. */
    void *extra_timer_user_data;
    /** User data passed to any other callback. */
    void *user_data;
    /** RX FC event callback. */
    phy_rx_fc_cb_t rx_fc_cb;
    /** ACCESS event callback. */
    phy_access_cb_t access_cb;
    /** ACCESS CONFIRM event callback. */
    phy_access_conf_cb_t access_conf_cb;
    /** PB DMA callback. */
    phy_pbdma_cb_t pbdma_cb;
    /** TX FALSE ALARM callback. */
    phy_tx_false_alarm_cb_t tx_false_alarm_cb;
    /** Zero cross callback. */
    phy_zero_cross_cb_t zero_cross_cb;
    /** DSR callback. */
    phy_deferred_cb_t deferred_cb;
    /** Extra timer callback. */
    phy_extra_timer_cb_t extra_timer_cb;
    /** Pointer to current PHY callback. */
    void *current_cb;
    /** Parameters for rx_fc callback. */
    maximus_phy_rx_fc_param_t rx_fc_param;
    /** Abort TX if PRP was lost. */
    bool stop_tx_on_prp_lost;
    /** Indicates if a TX has been blocked on a PRE TX false alarm. */
    bool tx_blocked_on_false_alarm;
    /** Used to enable or disable PRE detection. */
    bool pre_detection;
    /** Used to indicate if the RX has been prepared. */
    bool rx_prepared;
    /** Date of last zero-cross. */
    u32 zero_cross_date;
    /** Phy RX parameters. */
    maximus_phy_rx_param_t rx_param;
    /** Phy TX parameters for next TX request. */
    maximus_phy_tx_param_t next_tx_param;
    /** Phy TX parameters for current TX request. */
    maximus_phy_tx_param_t current_tx_param;
    /** Id of netclock message sent by 'phy_extra_timer_program'. */
    netclock_id_t extra_timer_program_netclock_id;
    /** Callback context to insert into callback queue. */
    netclock_callback_t *extra_timer_program_netclock_cb;
    /** Random library context.*/
    lib_rnd_t *rnd;
#ifdef ECOS
    /** phy interrupt descriptor for eCos: relates to rx_fc, access and access_conf and extra_timer events */
    cyg_interrupt phy_interrupt;
    /** phy interrupt handle */
    cyg_handle_t phy_interrupt_handle;
    /** pbdma interrupt descriptor for eCos: relates to pbdma event */    
    cyg_interrupt pbdma_interrupt;
    /** pbdma interrupt handle */
    cyg_handle_t pbdma_interrupt_handle;
#endif /* ECOS */
};
typedef struct maximus_phy_ctrl_t maximus_phy_ctrl_t;

/** PB DMA structure for Maximus */
struct maximus_pbdma_t
{
    /** Current status of pbdma: simulates the pbdma status register. */
    phy_pbdma_status_t status_word;
    /** Internal PB counter. */
    u8 index_current_pb;
    /** Do not encrypt or decrypt using AES. */
    bool bypass_aes;
    /** Three first AES initialisation vector words. */
    u32 iv[3];
    /** AES network encryption key. */
    u32 nek[4];
    /** Total number of PB. */
    uint nb_total;
    /** Number of ready descriptors. */
    uint nb_ready;
    /** Number of the PB after which an interrupt is triggered. */
    uint nb_pb_it;
    /** Used to indicate that a chandata transfer has been requested (true) or not (false). */
    bool chandata_transfer;
    /** First PB descriptor. */
    phy_pb_t *first_pb;
    /** Current PB descriptor for Rx. */
    phy_pb_rx_t *current_pb;
    /** First transfer descriptor. */
    phy_chandata_t *first_chandata;
    /** CRC bitmap registers. */
    u32 crc_bitmap[8];
};
typedef struct maximus_pbdma_t maximus_pbdma_t;

/** Tone Map DMA structure for Maximus */
struct maximus_tmdma_t
{
    /** Number of carriers. */
    uint carrier_nb;
    /** Tonemask blocks first descriptor. */
    u8 *tonemask; // tonemask[(PHY_CARRIER_NB+7)/8] (1 bit per carrier)
    /** Tonemap blocks first descriptor. */
    blk_t *tonemap[TONEMAP_INDEX_NB]; // tonemap[(PHY_CARRIER_NB+1)/2] (4 bits per carrier)
};
typedef struct maximus_tmdma_t maximus_tmdma_t;

/** Phy context structure for Maximus */
struct phy_t
{
    maximus_phy_access_t  access;
    maximus_phy_ctrl_t    control;
    maximus_pbdma_t       pbdma;
    maximus_tmdma_t       tmdma;
    /** For phy messages. */
    unsigned char buffer[SCI_MSG_MAX_SIZE];
    /** Set to true to enable assertions on WARNING messages. */
    bool warning_assert;
#if CONFIG_TRACE
    /** PHY trace. */
    trace_buffer_t trace;
#endif /* !CONFIG_TRACE */
};
/* Forward declaration in hal/phy/forward.h. */

#endif /* hal_phy_maximus_inc_maximus_phy_context_h */