delete old cse7759 counter code

master
vuko 2018-03-20 10:45:12 +01:00
parent 6489e78cdc
commit 26ac421d40
2 changed files with 0 additions and 85 deletions

View File

@ -1,43 +0,0 @@
#include <freq_counter.h>
void freq_counter_init ( struct freq_counter *f, uint32_t cycle_len ) {
f->input_initialized = false;
f->input_state = false;
f->counter = 0;
f->samples = 0;
f->cycle_len = cycle_len;
f->new_measurement = false;
f->measurement = 0;
}
void IRAM_ATTR freq_counter_update ( struct freq_counter *f, bool input ) {
if ( f->input_initialized == false ) {
// ignore first input value
f->input_state = input;
f->input_initialized = true;
}
if ( f->input_state != input) {
f->counter += 1;
f->input_state = input;
}
f->samples += 1;
if ( f->samples >= f->cycle_len ) {
/* cycle complete */
f->measurement = f->counter;
f->new_measurement = true;
f->samples = 0;
f->counter = 0;
}
}
bool freq_counter_get_measurement( struct freq_counter *f, uint32_t *measurement) {
if ( f->new_measurement == true ) {
*measurement = f->measurement;
f->new_measurement = false;
return true;
} else {
return false;
}
}

View File

@ -1,42 +0,0 @@
#include <stdbool.h>
#include <stdint.h>
#ifndef FREQ_COUNTER_H
#define FREQ_COUNTER_H
#ifndef IRAM_ATTR
#define IRAM_ATTR __attribute__((section(".iram.text")))
#endif
struct freq_counter {
bool input_initialized; /* false before first update call */
bool input_state; /* last update input state */
uint32_t counter; /* input state changes counter */
uint32_t samples; /* input samples counter */
uint32_t cycle_len; /* number of samples in one cycle */
bool new_measurement; /* set to true after updating measurement */
uint32_t measurement; /* number of state changes in last complete cycle */
};
/**
* @brief initialize frequency counter structure
*
* @param cycle_len number of samples in one measurement cycle
*/
void freq_counter_init ( struct freq_counter *f, uint32_t cycle_len );
void IRAM_ATTR freq_counter_update ( struct freq_counter *f, bool input );
/**
* @brief get new measurement from freq_counter
*
* this function should be called at least twice per cycle in order to avoid
* concurrent rw acces to measurement variable
* @param measurement is set to new measurement value if returned true
* @return true if new measurement is available
*/
bool freq_counter_get_measurement( struct freq_counter *f, uint32_t *measurement);
#endif /* end of include guard: FREQ_COUNTER_H */