Example #1
0
void
rtimer_arch_schedule(rtimer_clock_t t)
{
	#if DEBUG
	printf("DEBUG: rtimer_arch_schedule time %llu\r\n", /*((uint32_t*)&t)+1,*/(uint64_t)t);
	#endif

	next_rtimer_time = t;
	
	rtimer_clock_t now = rtimer_arch_now();
	
	rtimer_clock_t clock_to_wait = t - now;
		
	if(clock_to_wait <= 0x100000000){ // We must set now the Timer Compare Register.
	
		// Set the auxiliary timer (TC0,1) at the write time interrupt
		// [clock_to_wait] TODO Check the standard drift and perhaps remove it from the waiting time
		tc_write_rc(TC0,1,(uint32_t)(t-rtimer_arch_now())); 
		// Set and enable interrupt on RC compare
		tc_enable_interrupt(TC0,1,TC_IER_CPCS);
		// Start the auxiliary timer
		tc_start(TC0,1);
		
		#if DEBUG
		now = rtimer_arch_now();
		printf("DEBUG: Timer started on time %llu.\n",now);
		#endif
	}
// else compare register will be set at overflow interrupt closer to the rtimer event.

}
Example #2
0
static void
recv_mesh(struct mesh_conn *c, const rimeaddr_t *from, uint8_t hops)
{
  struct rime_ping_msg ping;
  char buf[64];
  rtimer_clock_t pingrecvtime;
  
  memcpy(&ping, packetbuf_dataptr(), sizeof(struct rime_ping_msg));

  if(waiting_for_pong == 0) {
#if TIMESYNCH_CONF_ENABLED
    ping.pongtime = timesynch_time();
#else
    ping.pongtime = ping.pingtime;
#endif
    memcpy(packetbuf_dataptr(), &ping, sizeof(struct rime_ping_msg));
    mesh_send(&mesh, from);
  } else {
#if TIMESYNCH_CONF_ENABLED
    pingrecvtime = timesynch_time();
#else
    pingrecvtime = rtimer_arch_now();
#endif
    snprintf(buf, sizeof(buf), "%lu ms (%lu + %lu), %d hops.",
	    ((pingrecvtime  - ping.pingtime) * 1000L) / RTIMER_ARCH_SECOND,
	    ((ping.pongtime - ping.pingtime) * 1000L) / RTIMER_ARCH_SECOND,
	    ((pingrecvtime  - ping.pongtime) * 1000L) / RTIMER_ARCH_SECOND,
	    hops);

    shell_output_str(&rime_ping_command,
		     "Pong recived; rtt ", buf);
    waiting_for_pong = 0;
    process_post(&shell_rime_ping_process, PROCESS_EVENT_CONTINUE, NULL);
  }
}
Example #3
0
void rtc_isr(void) {
	PRINTF("rtc_wu_irq\n\r");
	PRINTF("now is %u\n", rtimer_arch_now());
	disable_rtc_wu();
	disable_rtc_wu_irq();
	rtimer_run_next();
	clear_rtc_wu_evt();
}
Example #4
0
int
cgroups_radio_interrupt(void)
{
  interrupt_time = rtimer_arch_now();
  
  //CLEAR_FIFOP_INT();
  process_poll(&cgroups_radio_process);
  PRINTF("CGROUPS RADIO: packet seen set\n");
  packet_seen = 1;
  return 1;
}
Example #5
0
/*---------------------------------------------------------------------------*/
void
rtimer_arch_schedule(rtimer_clock_t t)
{
  // Program Alarm
  RTC_IntClear(RTC_IF_COMP0);

  // Enable Alarm 0 preventing overflow !!!
  RTC_CompareSet(0, (t & 0xFFFFFF));
  PRINTF("Now %u, comp0 = %u\r\n", rtimer_arch_now(), t);

  RTC_IntEnable(RTC_IF_COMP0);
}
Example #6
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(shell_rime_ping_process, ev, data)
{
  static int i;
  static struct etimer timeout, periodic;
  static rimeaddr_t receiver;
  struct rime_ping_msg *ping;
  const char *nextptr;
  char buf[32];

  PROCESS_BEGIN();

  receiver.u8[0] = shell_strtolong(data, &nextptr);
  if(nextptr == data || *nextptr != '.') {
    shell_output_str(&rime_ping_command,
		     "ping <receiver>: recevier must be specified", "");
    PROCESS_EXIT();
  }
  ++nextptr;
  receiver.u8[1] = shell_strtolong(nextptr, &nextptr);

  snprintf(buf, sizeof(buf), "%d.%d", receiver.u8[0], receiver.u8[1]);
  shell_output_str(&rime_ping_command, "Sending 4 pings to ", buf);

  for(i = 0; i < 4; ++i) {
    packetbuf_clear();
    ping = packetbuf_dataptr();
    packetbuf_set_datalen(sizeof(struct rime_ping_msg));
#if TIMESYNCH_CONF_ENABLED
    ping->pingtime = timesynch_time();
#else
    ping->pingtime = rtimer_arch_now();
#endif
    mesh_send(&mesh, &receiver);

    etimer_set(&timeout, CLOCK_SECOND * 8);
    etimer_set(&periodic, CLOCK_SECOND * 1);
    waiting_for_pong = 1;
    PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&timeout) ||
			     waiting_for_pong == 0);
    if(waiting_for_pong == 0) {
      PROCESS_WAIT_UNTIL(etimer_expired(&periodic));
    } else {
      shell_output_str(&rime_ping_command,
		       "Timed out", "");
    }
    waiting_for_pong = 0;
  }
  PROCESS_END();
}
Example #7
0
void
rtimer_arch_schedule(rtimer_clock_t t)
{
	volatile uint32_t now;
	now = rtimer_arch_now();
	PRINTF("rtimer_arch_schedule time %u; now is %u\n", t,now);
	if(now>t) {
		*CRM_RTC_TIMEOUT = 1;
	} else {
		*CRM_RTC_TIMEOUT = t - now;
	}

	clear_rtc_wu_evt();
	enable_rtc_wu();
	enable_rtc_wu_irq();
	PRINTF("rtimer_arch_schedule CRM_RTC_TIMEOUT is %u\n", *CRM_RTC_TIMEOUT);
}
/*---------------------------------------------------------------------------*/
void
LPTMR_IRQHandler(void)
  {
    ENERGEST_ON(ENERGEST_TYPE_IRQ);

    watchdog_start();
    
    PRINTF("rtimer_arch_init compare event at 0x%4x.\n", rtimer_arch_now());

    LPTMR0_CMR = LPTMR_CMR_COMPARE(LPTMR_CMR_COMPARE_MASK);
    LPTMR0_CSR = (uint32_t) ((LPTMR0_CSR
        & (uint32_t) ~(uint32_t) (LPTMR_CSR_TIE_MASK))
    | (uint32_t) (LPTMR_CSR_TCF_MASK)); // Clear interrupt flag and disable interrupt

    rtimer_run_next();

    watchdog_stop();

    ENERGEST_OFF(ENERGEST_TYPE_IRQ);
  }
Example #9
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(shell_time_process, ev, data)
{
  struct {
    uint16_t len;
    uint16_t clock;
    uint16_t rtimer;
    uint16_t timesynch;
    uint16_t timesynch_authority;
    uint16_t time[2];
  } msg;
  unsigned long newtime;
  
  PROCESS_BEGIN();

  if(data != NULL) {
    const char *nextptr;
    newtime = shell_strtolong(data, &nextptr);
    if(data != nextptr) {
      shell_set_time(newtime);
    }
  }
  
  msg.clock = (uint16_t)clock_time();
  msg.rtimer = (uint16_t)rtimer_arch_now();
#if TIMESYNCH_CONF_ENABLED
  msg.timesynch = timesynch_time();
  msg.timesynch_authority = timesynch_authority_level();
#else
  msg.timesynch = 0;
  msg.timesynch_authority = -1;
#endif
  msg.time[0] = (uint16_t)(shell_time() >> 16);
  msg.time[1] = (uint16_t)(shell_time());
  msg.len = 6;

  shell_output(&time_command, &msg, sizeof(msg), "", 0);

  PROCESS_END();
}
Example #10
0
/*---------------------------------------------------------------------------*/
rtimer_clock_t
timesynch_time(void)
{
  return rtimer_arch_now() + offset;
}