/*---------------------------------------------------------------------------*/
static void
init(void)
{
  radio_is_on = 0;
  PT_INIT(&pt);
#if NURTIMER
  rtimer_setup(&rt, RTIMER_HARD,
               (void (*)(struct rtimer *, void *, int status))powercycle,
               NULL);
  rtimer_schedule(&rt, CYCLE_TIME, 1);
#else
  rtimer_set(&rt, RTIMER_NOW() + CYCLE_TIME, 1,
             (void (*)(struct rtimer *, void *))powercycle, NULL);
#endif

  contikimac_is_on = 1;

#if WITH_PHASE_OPTIMIZATION
  phase_init(&phase_list);
#endif /* WITH_PHASE_OPTIMIZATION */

#if CONTIKIMAC_CONF_ANNOUNCEMENTS
  announcement_register_listen_callback(listen_callback);
  ctimer_set(&announcement_cycle_ctimer, ANNOUNCEMENT_TIME,
             cycle_announcement, NULL);
#endif /* CONTIKIMAC_CONF_ANNOUNCEMENTS */
}
/*---------------------------------------------------------------------------*/
static int
turn_on(void)
{
  if(contikimac_is_on == 0) {
    contikimac_is_on = 1;
#if NURTIMER
    rtimer_schedule(&rt, CYCLE_TIME, 1);
#else
    rtimer_set(&rt, RTIMER_NOW() + CYCLE_TIME, 1,
               (void (*)(struct rtimer *, void *))powercycle, NULL);
#endif
  }
  return 1;
}
Beispiel #3
0
/*---------------------------------------------------------------------------*/
static inline void
schedule_timeout(void)
{
  /* number of slots after which the timeout will expire: */
  /* random number between SLOT_TIMEOUT_MIN and SLOT_TIMEOUT_MAX */
  uint8_t slot_timeout = SLOT_TIMEOUT_MIN +
    (random_rand() % (SLOT_TIMEOUT_MAX - SLOT_TIMEOUT_MIN + 1));
  if(WITH_RELAY_CNT()) {
    /* if the relay counter is sent, increment it by the chosen number of
     * slots */
    g.relay_cnt_timeout = g.header.relay_cnt + slot_timeout;
  }
  rtimer_schedule(GLOSSY_CONF_RTIMER_ID, 
                  g.t_timeout + slot_timeout * g.T_slot_estimated, 
                  0,
                  timeout_expired);
}
Beispiel #4
0
/*---------------------------------------------------------------------------*/
static inline char
timeout_expired(rtimer_t *rt)
{
  if(!rf1a_is_busy()) {
    /* we are not receiving anything: retransmit the packet */
    rf1a_start_tx();
    g.header.relay_cnt = g.relay_cnt_timeout;
    rf1a_write_to_tx_fifo((uint8_t *)&g.header,
                          GLOSSY_HEADER_LEN(g.header.pkt_type),
                          (uint8_t *)g.payload, g.payload_len);
    g.t_timeout = rt->time;
  } else {
    /* we are receiving a packet: postpone the timeout by one slot */
    g.relay_cnt_timeout++;
    rtimer_schedule(GLOSSY_CONF_RTIMER_ID, rt->time + g.T_slot_estimated, 0,
                    timeout_expired);
  }
  return 0;
}