summaryrefslogtreecommitdiff
path: root/cesar
diff options
context:
space:
mode:
authorNicolas Schodet2010-11-09 16:53:46 +0100
committerNicolas Schodet2011-01-19 14:41:37 +0100
commitdc487f0dde394dd9e4861902056f139975650bde (patch)
tree8d450431014f96fa2713b8427315dd7b75754884 /cesar
parent027d0fb45cc26c4ee758c2f956795d165b8073ab (diff)
cesar/mac/ca/src: move state/timing check out of compute update, refs #1812
Diffstat (limited to 'cesar')
-rw-r--r--cesar/mac/ca/src/access.c116
1 files changed, 58 insertions, 58 deletions
diff --git a/cesar/mac/ca/src/access.c b/cesar/mac/ca/src/access.c
index ab303313e6..2010be9597 100644
--- a/cesar/mac/ca/src/access.c
+++ b/cesar/mac/ca/src/access.c
@@ -203,69 +203,63 @@ static void ARCH_ILRAM
ca_access_compute_update (ca_t *ctx, u32 update_date)
{
dbg_claim (ctx);
- /* Only update if activated and enough time before the timer expiration. */
- if (ctx->state == CA_STATE_ACTIVATED
- && less_mod2p32 (update_date + CA_ACCESS_UPDATE_ANTICIP_TCK,
- ctx->access.timer_date))
+ bool aifs = true;
+ u32 access_date = ctx->access.param.access_date;
+ u32 allocation_end_date = ctx->current_allocation_param.end_date;
+ /* Test whether an access is possible. */
+ if (!ctx->access.unusable)
{
- bool aifs = true;
- u32 access_date = ctx->access.param.access_date;
- u32 allocation_end_date = ctx->current_allocation_param.end_date;
- /* Test whether an access is possible. */
- if (!ctx->access.unusable)
+ /* Is there MFS to send? */
+ uint glid = ctx->current_allocation_param.glid;
+ mfs_tx_t *mfs = ca_access_choose_mfs_tx (ctx, glid);
+ if (mfs)
{
- /* Is there MFS to send? */
- uint glid = ctx->current_allocation_param.glid;
- mfs_tx_t *mfs = ca_access_choose_mfs_tx (ctx, glid);
- if (mfs)
+ /* Should access be postponed? */
+ if (less_mod2p32 (access_date - ctx->anticipation_tck,
+ update_date + CA_ACCESS_UPDATE_ANTICIP_TCK))
{
- /* Should access be postponed? */
- if (less_mod2p32 (access_date - ctx->anticipation_tck,
- update_date + CA_ACCESS_UPDATE_ANTICIP_TCK))
- {
- u32 offset_tck =
- update_date + CA_ACCESS_UPDATE_ANTICIP_TCK
- - access_date + ctx->anticipation_tck;
- if (!ctx->access.param.cfp)
- offset_tck = (offset_tck + MAC_SLOT_TCK - 1)
- / MAC_SLOT_TCK * MAC_SLOT_TCK;
- access_date += offset_tck;
- ctx->access.param.access_date = access_date;
- }
- /* Is access still possible? */
- if (less_mod2p32 (access_date + CA_ACCESS_MIN_TCK,
- allocation_end_date))
- {
- aifs = false;
- }
- /* Update CAP. */
- if (ctx->access.param.prp)
- phy_access_backoff_update (ctx->phy, mfs->cap);
+ u32 offset_tck =
+ update_date + CA_ACCESS_UPDATE_ANTICIP_TCK
+ - access_date + ctx->anticipation_tck;
+ if (!ctx->access.param.cfp)
+ offset_tck = (offset_tck + MAC_SLOT_TCK - 1)
+ / MAC_SLOT_TCK * MAC_SLOT_TCK;
+ access_date += offset_tck;
+ ctx->access.param.access_date = access_date;
}
- }
- /* Apply decision. */
- u32 timer_date;
- ctx->access.param.aifs = aifs;
- if (!aifs)
- {
- ctx->access.param.duration_tck =
- allocation_end_date - access_date;
- timer_date = access_date - ctx->anticipation_tck;
- CA_TRACE (ACCESS_UPDATE_ACCESS, update_date, access_date,
- ctx->access.param.duration_tck);
- }
- else
- {
- timer_date = allocation_end_date;
- CA_TRACE (ACCESS_UPDATE_AIFS, update_date, allocation_end_date);
- }
- /* Update access timer. */
- if (timer_date != ctx->access.timer_date)
- {
- ctx->access.timer_date = timer_date;
- phy_access_timer_update (ctx->phy, timer_date);
+ /* Is access still possible? */
+ if (less_mod2p32 (access_date + CA_ACCESS_MIN_TCK,
+ allocation_end_date))
+ {
+ aifs = false;
+ }
+ /* Update CAP. */
+ if (ctx->access.param.prp)
+ phy_access_backoff_update (ctx->phy, mfs->cap);
}
}
+ /* Apply decision. */
+ u32 timer_date;
+ ctx->access.param.aifs = aifs;
+ if (!aifs)
+ {
+ ctx->access.param.duration_tck =
+ allocation_end_date - access_date;
+ timer_date = access_date - ctx->anticipation_tck;
+ CA_TRACE (ACCESS_UPDATE_ACCESS, update_date, access_date,
+ ctx->access.param.duration_tck);
+ }
+ else
+ {
+ timer_date = allocation_end_date;
+ CA_TRACE (ACCESS_UPDATE_AIFS, update_date, allocation_end_date);
+ }
+ /* Update access timer. */
+ if (timer_date != ctx->access.timer_date)
+ {
+ ctx->access.timer_date = timer_date;
+ phy_access_timer_update (ctx->phy, timer_date);
+ }
}
void
@@ -373,7 +367,13 @@ ca_access_update (ca_t *ctx)
dbg_assert (ctx);
u32 date = phy_date ();
uint flags = arch_isr_lock ();
- ca_access_compute_update (ctx, date);
+ /* Only update if activated and enough time before the timer expiration. */
+ if (ctx->state == CA_STATE_ACTIVATED
+ && less_mod2p32 (date + CA_ACCESS_UPDATE_ANTICIP_TCK,
+ ctx->access.timer_date))
+ {
+ ca_access_compute_update (ctx, date);
+ }
arch_isr_unlock (flags);
}