c - Equivalent to Arduino millis() -
i working on integration of "shunt" type sensor on electronic board. choice on linear (ltc2947), unfortunately has arduino driver. have translate in c under linux compatible microprocessor (apq8009 arm cortex-a7). have small question 1 of functions:
int16_t ltc2947_wake_up() //wake ltc2947 shutdown mode , measure wakeup time { byte data[1]; unsigned long wakeupstart = millis(), wakeuptime; ltc2947_wr_byte(ltc2947_reg_opctl, 0); { delay(1); ltc2947_rd_byte(ltc2947_reg_opctl, data); wakeuptime = millis() - wakeupstart; if (data[0] == 0) //! check if in idle mode { return wakeuptime; } if (wakeuptime > 200) { //! failed wake due timeout, return -1 return -1; } } while (true); }
after finding usleep() equivalent delay(), can not find millis() in c. can me translate function please?
arduino millis()
based on timer trips overflow interrupt @ close 1 khz, or 1 millisecond. achieve same thing, suggest setup timer on arm platform , update volatile unsigned long
variable counter. equivalent of millis().
here millis() doing behind scenes:
signal(timer0_ovf_vect) { // copy these local variables can stored in registers // (volatile variables must read memory on every access) unsigned long m = timer0_millis; unsigned char f = timer0_fract; m += millis_inc; f += fract_inc; if (f >= fract_max) { f -= fract_max; m += 1; } timer0_fract = f; timer0_millis = m; timer0_overflow_count++; } unsigned long millis() { unsigned long m; uint8_t oldsreg = sreg; // disable interrupts while read timer0_millis or might // inconsistent value (e.g. in middle of write timer0_millis) cli(); m = timer0_millis; sreg = oldsreg; return m; }
coming embedded world, arguably first thing should when starting project on new platform establish clocks , timer interrupt going @ prescribed rate. "hello world" of embedded systems. ;) if choose @ 1 khz, you're of way there.
Comments
Post a Comment