Beispiel #1
0
//specify delay in us (max 1000)
// TODO: if larger than tick
void delay_us(unsigned int  nCount)
{
	u32 sys_tk = systick_get_value();
	sys_tk -= (nCount-1) * 72;

	for(;systick_get_value() > sys_tk;);
}
Beispiel #2
0
uint8_t tick_expire_us(uint32_t *last_tick, uint32_t time_us)
{
  uint32_t tickus, end;
  time_us *= 72;
  end = systick_get_value();
  tickus = tick_delta_time_tick(end, *last_tick);
  if (tickus < time_us) return 0;
  *last_tick = systick_get_value();
  return 1;
}
Beispiel #3
0
void tick_wait_us(uint32_t wait_us)
{
  uint32_t start;

  start = systick_get_value();

  while (tick_expire_us(&start, wait_us) == 0);
}
Beispiel #4
0
uint64_t time_get_ticks() {
  uint64_t result;
  // keep calculating result until it is calculated without a rollover having
  // happened
  { CriticalSection cs;
    do {
      result = (rollovers << 24) | (0xffffff - systick_get_value());
    } while(check_rollover());
  }
  return result;
}
Beispiel #5
0
uint64_t time_get_ns() {
  uint64_t result;
  // keep calculating result until it is calculated without a rollover having
  // happened
  cm_disable_interrupts();
  do {
    result = (rollovers << 24) | (0xffffff - systick_get_value());
  } while(check_rollover());
  cm_enable_interrupts();
  return result*125/9;
}
Beispiel #6
0
// 1.5 ns step
uint64_t stick_get_us(void)
{
	CM_ATOMIC_CONTEXT();
	uint32_t rld = systick_get_reload() + 1;

	uint64_t ss = (rld-systick_get_value()) * 1000 / rld;

	if (nvic_get_pending_irq(NVIC_SYSTICK_IRQ) && (ss < 500)) {
		// overflow between atomic and get value?
		ss += 1000;
	}

	return ticks * 1000 + ss;
}
  /* external interrupt for drdy pin */
  exti_select_source(EXTI5, GPIOB);
  exti_set_trigger(EXTI5, EXTI_TRIGGER_RISING);
  exti_enable_request(EXTI5);

  nvic_set_priority(NVIC_EXTI9_5_IRQ, 0x0f);
  nvic_enable_irq(NVIC_EXTI9_5_IRQ);
}

void ms2100_reset_cb( struct spi_transaction * t __attribute__ ((unused)) ) {
  // set RESET pin high for at least 100 nsec
  // busy wait should not harm
  Ms2100Set();

  // FIXME, make nanosleep funcion
  uint32_t dt_ticks = cpu_ticks_of_nsec(110);
  int32_t end_cpu_ticks = systick_get_value() - dt_ticks;
  if (end_cpu_ticks < 0)
    end_cpu_ticks += systick_get_reload();
  while (systick_get_value() > (uint32_t)end_cpu_ticks)
    ;

  Ms2100Reset();
}

void exti9_5_isr(void) {
  ms2100.status = MS2100_GOT_EOC;
  exti_reset_request(EXTI5);
}
Beispiel #8
0
uint32_t tick_get_tick(void )
{
  return systick_get_value();
}