Compare commits
3 Commits
4a98d41623
...
5a1deeb9ee
Author | SHA1 | Date | |
---|---|---|---|
5a1deeb9ee | |||
809c86a618 | |||
88a4bb97a5 |
@ -1,12 +1,11 @@
|
||||
#include <error-mem-viewer/crc.h>
|
||||
|
||||
uint32_t do_crc(uint32_t init, uint32_t data)
|
||||
static uint32_t do_crc(uint32_t init, uint32_t data)
|
||||
{
|
||||
uint32_t crc = init;
|
||||
uint32_t cnt;
|
||||
|
||||
for(cnt=0; cnt < 32; cnt++)
|
||||
{
|
||||
for (cnt=0; cnt < 32; cnt++) {
|
||||
crc = ((int32_t)(crc ^ data))<0 ? (crc << 1) ^ 0x04C11DB7 : crc << 1;
|
||||
data <<=1;
|
||||
}
|
||||
@ -18,7 +17,7 @@ uint32_t calculate_stm_crc(uint32_t *data, size_t len)
|
||||
{
|
||||
uint32_t crc = ~0U;
|
||||
|
||||
while(len--) {
|
||||
while (len--) {
|
||||
crc = do_crc(crc, *data++);
|
||||
}
|
||||
|
||||
|
@ -1,64 +0,0 @@
|
||||
/* Reflow Oven Controller
|
||||
*
|
||||
* Copyright (C) 2021 Mario Hüttel <mario.huettel@gmx.net>
|
||||
*
|
||||
* This file is part of the Reflow Oven Controller Project.
|
||||
*
|
||||
* The reflow oven controller is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* The Reflow Oven Control Firmware is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with the reflow oven controller project.
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <reflow-controller/fir-filter.h>
|
||||
|
||||
void fir_filter_init_null(struct fir_filter_fixed *filter)
|
||||
{
|
||||
uint32_t idx;
|
||||
|
||||
if (!filter)
|
||||
return;
|
||||
filter->put_idx = 0U;
|
||||
for (idx = 0; idx < filter->tap_count; idx++)
|
||||
filter->data = 0;
|
||||
}
|
||||
|
||||
|
||||
int32_t fir_filter_process_sample(struct fir_filter_fixed *filter, int32_t sample)
|
||||
{
|
||||
uint32_t tap_idx;
|
||||
uint32_t coeff_idx;
|
||||
int32_t output = 0;
|
||||
|
||||
if (!filter)
|
||||
return 0;
|
||||
|
||||
/* Store the new data point */
|
||||
filter->data[filter->put_idx] = sample;
|
||||
|
||||
coeff_idx = filter->put_idx;
|
||||
|
||||
/* Apply fir taps on data */
|
||||
for (tap_idx = 0; tap_idx < filter->tap_count; tap_idx++) {
|
||||
output += filter->data[tap_idx] * filter->coefficients[coeff_idx];
|
||||
|
||||
if (coeff_idx)
|
||||
coeff_idx--;
|
||||
else
|
||||
coeff_idx = filter->tap_count-1;
|
||||
}
|
||||
|
||||
filter->put_idx++;
|
||||
if (filter->put_idx >= filter->tap_count)
|
||||
filter->put_idx = 0;
|
||||
|
||||
return output;
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
/* Reflow Oven Controller
|
||||
*
|
||||
* Copyright (C) 2021 Mario Hüttel <mario.huettel@gmx.net>
|
||||
*
|
||||
* This file is part of the Reflow Oven Controller Project.
|
||||
*
|
||||
* The reflow oven controller is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* The Reflow Oven Control Firmware is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with the reflow oven controller project.
|
||||
* If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef __FIR_FILTER_H__
|
||||
#define __FIR_FILTER_H__
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
struct fir_filter_fixed {
|
||||
uint32_t tap_count;
|
||||
const int32_t *coefficients;
|
||||
int32_t *data;
|
||||
uint32_t put_idx;
|
||||
};
|
||||
|
||||
void fir_filter_init_null(struct fir_filter_fixed *filter);
|
||||
|
||||
int32_t fir_filter_process_sample(struct fir_filter_fixed *filter, int32_t sample);
|
||||
|
||||
#endif /* __FIR_FILTER_H__ */
|
@ -45,6 +45,7 @@
|
||||
#include <reflow-controller/temp-profile/temp-profile-executer.h>
|
||||
#include <reflow-controller/updater/updater.h>
|
||||
#include <reflow-controller/main-cycle-counter.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#ifndef GIT_VER
|
||||
#define GIT_VER "VERSION NOT SET"
|
||||
@ -792,7 +793,7 @@ shellmatta_retCode_t shell_cmd_execute(const shellmatta_handle_t handle, const c
|
||||
return SHELLMATTA_CONTINUE;
|
||||
}
|
||||
|
||||
shellmatta_retCode_t shell_cmd_cycle_count (const shellmatta_handle_t handle, const char *args, uint32_t len)
|
||||
shellmatta_retCode_t shell_cmd_cycle_count(const shellmatta_handle_t handle, const char *args, uint32_t len)
|
||||
{
|
||||
uint64_t counter;
|
||||
(void)args;
|
||||
@ -829,6 +830,126 @@ shellmatta_retCode_t shell_cmd_cycle_count (const shellmatta_handle_t handle, co
|
||||
return SHELLMATTA_OK;
|
||||
}
|
||||
|
||||
shellmatta_retCode_t shell_cmd_filter_alpha(const shellmatta_handle_t handle, const char *args, uint32_t len)
|
||||
{
|
||||
shellmatta_retCode_t opt_stat;
|
||||
char option;
|
||||
char *argument;
|
||||
uint32_t arg_len;
|
||||
char *alpha_string = NULL;
|
||||
float alpha;
|
||||
(void)len;
|
||||
(void)args;
|
||||
|
||||
const shellmatta_opt_long_t options[] = {
|
||||
{NULL, '\0', SHELLMATTA_OPT_ARG_NONE},
|
||||
};
|
||||
|
||||
while (1) {
|
||||
opt_stat = shellmatta_opt_long(handle, options, &option, &argument, &arg_len);
|
||||
if (opt_stat != SHELLMATTA_OK)
|
||||
break;
|
||||
switch (option) {
|
||||
case '\0':
|
||||
alpha_string = argument;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!alpha_string) {
|
||||
shellmatta_printf(handle, "Specify filter value!\r\n");
|
||||
return SHELLMATTA_OK;
|
||||
}
|
||||
|
||||
alpha = strtof(alpha_string, NULL);
|
||||
if (alpha < 0.0f || alpha == 0.0f || alpha > 0.9f) {
|
||||
shellmatta_printf(handle, "Filter param outside of valid range!\r\n");
|
||||
return SHELLMATTA_OK;
|
||||
}
|
||||
|
||||
adc_pt1000_set_moving_average_filter_param(alpha);
|
||||
shellmatta_printf(handle, "Filter param set to %f\r\n", alpha);
|
||||
|
||||
return SHELLMATTA_OK;
|
||||
}
|
||||
|
||||
#if 0
|
||||
shellmatta_retCode_t shell_cmd_hf_stream(const shellmatta_handle_t handle, const char *args, uint32_t len)
|
||||
{
|
||||
float *data1;
|
||||
volatile int flag;
|
||||
FRESULT fres;
|
||||
char *strbuff;
|
||||
FIL f;
|
||||
const size_t buff_size = 2000UL;
|
||||
uint32_t idx;
|
||||
uint32_t blocks;
|
||||
uint32_t remainder;
|
||||
int cnt;
|
||||
UINT bw;
|
||||
|
||||
data1 = (float *)malloc(buff_size*sizeof(float));
|
||||
strbuff = (char *)malloc(1024);
|
||||
|
||||
if (!data1 || !strbuff) {
|
||||
shellmatta_printf(handle, "Allocating memory failed!\r\n");
|
||||
goto free_data;
|
||||
}
|
||||
|
||||
fres = f_open(&f, "pt1000_hf.dat", FA_CREATE_ALWAYS | FA_WRITE);
|
||||
if (fres != FR_OK) {
|
||||
shellmatta_printf(handle, "Cannot open file.\r\n");
|
||||
goto free_data;
|
||||
}
|
||||
|
||||
shellmatta_printf(handle, "Acquire data...\r\n");
|
||||
flag = 0;
|
||||
adc_pt1000_stream_raw_value_to_memory(data1, buff_size, &flag);
|
||||
while (!flag) {
|
||||
safety_controller_handle();
|
||||
}
|
||||
shellmatta_printf(handle, "Finished. Writing file...\r\n");
|
||||
|
||||
blocks = buff_size / 10UL;
|
||||
remainder = buff_size % 10UL;
|
||||
|
||||
for (idx = 0; idx < blocks; idx++) {
|
||||
cnt = snprintf(strbuff, 1024, "%.2f\n%.2f\n%.2f\n%.2f\n%.2f\n%.2f\n%.2f\n%.2f\n%.2f\n%.2f\n",
|
||||
data1[idx * 10+0],
|
||||
data1[idx * 10+1],
|
||||
data1[idx * 10+2],
|
||||
data1[idx * 10+3],
|
||||
data1[idx * 10+4],
|
||||
data1[idx * 10+5],
|
||||
data1[idx * 10+6],
|
||||
data1[idx * 10+7],
|
||||
data1[idx * 10+8],
|
||||
data1[idx * 10+9]);
|
||||
f_write(&f, strbuff, (UINT)cnt, &bw);
|
||||
safety_controller_handle();
|
||||
}
|
||||
|
||||
|
||||
for (idx = 0; idx < remainder; idx++) {
|
||||
cnt = snprintf(strbuff, 1024, "%.2f\n", data1[blocks * 10 + idx]);
|
||||
f_write(&f, strbuff, (UINT)cnt, &bw);
|
||||
}
|
||||
|
||||
f_close(&f);
|
||||
|
||||
shellmatta_printf(handle, "Completed!\r\n");
|
||||
free_data:
|
||||
if (data1)
|
||||
free(data1);
|
||||
if (strbuff)
|
||||
free(strbuff);
|
||||
|
||||
return SHELLMATTA_OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
//typedef struct shellmatta_cmd
|
||||
//{
|
||||
// char *cmd; /**< command name */
|
||||
@ -838,7 +959,7 @@ shellmatta_retCode_t shell_cmd_cycle_count (const shellmatta_handle_t handle, co
|
||||
// shellmatta_cmdFct_t cmdFct; /**< pointer to the cmd callack function */
|
||||
// struct shellmatta_cmd *next; /**< pointer to next command or NULL */
|
||||
//} shellmatta_cmd_t;
|
||||
static shellmatta_cmd_t cmd[23] = {
|
||||
static shellmatta_cmd_t cmd[24] = {
|
||||
{
|
||||
.cmd = "version",
|
||||
.cmdAlias = "ver",
|
||||
@ -1014,8 +1135,16 @@ static shellmatta_cmd_t cmd[23] = {
|
||||
.helpText = "Print out the cycle counter of the main loop",
|
||||
.usageText = "cyclecount [--clear]",
|
||||
.cmdFct = shell_cmd_cycle_count,
|
||||
.next = NULL,
|
||||
.next = &cmd[22],
|
||||
},
|
||||
{
|
||||
.cmd = "filter-alpha",
|
||||
.cmdAlias = "alpha",
|
||||
.helpText = "Sets the filter constant",
|
||||
.usageText = "filter-alpha <alpha>",
|
||||
.cmdFct = shell_cmd_filter_alpha,
|
||||
.next = NULL,
|
||||
}
|
||||
};
|
||||
|
||||
shellmatta_handle_t shell_init(shellmatta_write_t write_func)
|
||||
|
Loading…
x
Reference in New Issue
Block a user