Skip to content

Commit

Permalink
move filter functions to ram
Browse files Browse the repository at this point in the history
  • Loading branch information
bkleiner committed Aug 12, 2023
1 parent 561d519 commit d0e0667
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/flight/filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ void filter_lp_pt1_init(filter_lp_pt1 *filter, filter_state_t *state, uint8_t co
filter_init_state(state, count);
}

void filter_lp_pt1_coeff(filter_lp_pt1 *filter, float hz) {
RAM_FUNC void filter_lp_pt1_coeff(filter_lp_pt1 *filter, float hz) {
if (filter->hz == hz && filter->sample_period_us == state.looptime_autodetect) {
return;
}
Expand All @@ -61,7 +61,7 @@ void filter_lp_pt1_coeff(filter_lp_pt1 *filter, float hz) {
filter->alpha = sample_period / (rc + sample_period);
}

float filter_lp_pt1_step(filter_lp_pt1 *filter, filter_state_t *state, float in) {
RAM_FUNC float filter_lp_pt1_step(filter_lp_pt1 *filter, filter_state_t *state, float in) {
state->delay_element[0] = state->delay_element[0] + filter->alpha * (in - state->delay_element[0]);
return state->delay_element[0];
}
Expand All @@ -71,7 +71,7 @@ void filter_lp_pt2_init(filter_lp_pt2 *filter, filter_state_t *state, uint8_t co
filter_init_state(state, count);
}

void filter_lp_pt2_coeff(filter_lp_pt2 *filter, float hz) {
RAM_FUNC void filter_lp_pt2_coeff(filter_lp_pt2 *filter, float hz) {
if (filter->hz == hz && filter->sample_period_us == state.looptime_autodetect) {
return;
}
Expand All @@ -84,7 +84,7 @@ void filter_lp_pt2_coeff(filter_lp_pt2 *filter, float hz) {
filter->alpha = sample_period / (rc + sample_period);
}

float filter_lp_pt2_step(filter_lp_pt2 *filter, filter_state_t *state, float in) {
RAM_FUNC float filter_lp_pt2_step(filter_lp_pt2 *filter, filter_state_t *state, float in) {
state->delay_element[1] = state->delay_element[1] + filter->alpha * (in - state->delay_element[1]);
state->delay_element[0] = state->delay_element[0] + filter->alpha * (state->delay_element[1] - state->delay_element[0]);
return state->delay_element[0];
Expand All @@ -95,7 +95,7 @@ void filter_lp_pt3_init(filter_lp_pt3 *filter, filter_state_t *state, uint8_t co
filter_init_state(state, count);
}

void filter_lp_pt3_coeff(filter_lp_pt3 *filter, float hz) {
RAM_FUNC void filter_lp_pt3_coeff(filter_lp_pt3 *filter, float hz) {
if (filter->hz == hz && filter->sample_period_us == state.looptime_autodetect) {
return;
}
Expand All @@ -108,7 +108,7 @@ void filter_lp_pt3_coeff(filter_lp_pt3 *filter, float hz) {
filter->alpha = sample_period / (rc + sample_period);
}

float filter_lp_pt3_step(filter_lp_pt3 *filter, filter_state_t *state, float in) {
RAM_FUNC float filter_lp_pt3_step(filter_lp_pt3 *filter, filter_state_t *state, float in) {
state->delay_element[1] = state->delay_element[1] + filter->alpha * (in - state->delay_element[1]);
state->delay_element[2] = state->delay_element[2] + filter->alpha * (state->delay_element[1] - state->delay_element[2]);
state->delay_element[0] = state->delay_element[0] + filter->alpha * (state->delay_element[2] - state->delay_element[0]);
Expand Down Expand Up @@ -173,7 +173,7 @@ void filter_init(filter_type_t type, filter_t *filter, filter_state_t *state, ui
}
}

void filter_coeff(filter_type_t type, filter_t *filter, float hz) {
RAM_FUNC void filter_coeff(filter_type_t type, filter_t *filter, float hz) {
switch (type) {
case FILTER_LP_PT1:
filter_lp_pt1_coeff(&filter->lp_pt1, hz);
Expand All @@ -190,7 +190,7 @@ void filter_coeff(filter_type_t type, filter_t *filter, float hz) {
}
}

float filter_step(filter_type_t type, filter_t *filter, filter_state_t *state, float in) {
RAM_FUNC float filter_step(filter_type_t type, filter_t *filter, filter_state_t *state, float in) {
switch (type) {
case FILTER_LP_PT1:
return filter_lp_pt1_step(&filter->lp_pt1, state, in);
Expand Down

0 comments on commit d0e0667

Please sign in to comment.