f3 rt too long fix, hal debug level

This commit is contained in:
crinq
2018-03-19 01:30:10 +01:00
parent d889388b8a
commit 3bd1cf8907
6 changed files with 107 additions and 38 deletions
+2 -1
View File
@@ -26,7 +26,7 @@
#define ABS_MAX_CURRENT 30.0
enum hv_fault_t{
HV_NO_FAULT,
HV_NO_FAULT = 0,
HV_OVERTEMP,
HV_OVERVOLT,
HV_OVERCURRENT_RMS,
@@ -34,6 +34,7 @@ enum hv_fault_t{
HV_HV_FAULT,
HV_CURRENT_OFFSET_FAULT,
HV_COMM_FAULT,
HV_HAL_FAULT,
};
//io board
+62 -20
View File
@@ -268,20 +268,28 @@ COMMAND("hal", hal_term_print_info, "print HAL stats");
uint32_t load_comp(hal_comp_t *comp) {
if(!comp) {
printf("<font color=\"FireBrick\">load_comp: not found</font>\n");
if(hal.debug_level < 2){
printf("<font color=\"FireBrick\">load_comp: not found</font>\n");
}
return (0);
}
if(hal.comp_inst_count >= HAL_MAX_COMPS - 1) {
printf("<font color=\"FireBrick\">load_comp: not enough space to load comp: %s</font>\n", comp->name);
if(hal.debug_level < 2){
printf("<font color=\"FireBrick\">load_comp: not enough space to load comp: %s</font>\n", comp->name);
}
return (0);
}
if(hal.pin_inst_count + comp->pin_count >= HAL_MAX_PINS - 1) {
printf("<font color=\"FireBrick\">load_comp: not enough space to load comp pins: %s</font>\n", comp->name);
if(hal.debug_level < 2){
printf("<font color=\"FireBrick\">load_comp: not enough space to load comp pins: %s</font>\n", comp->name);
}
return (0);
}
uint32_t ctx_size = ((uint32_t)ceil((comp->ctx_size / 4.0))) * 4;
if(hal.ctx_count + ctx_size >= HAL_MAX_CTX - 1) {
printf("<font color=\"FireBrick\">load_comp: not enough space to load comp ctx: %s</font>\n", comp->name);
if(hal.debug_level < 2){
printf("<font color=\"FireBrick\">load_comp: not enough space to load comp ctx: %s</font>\n", comp->name);
}
return (0);
}
@@ -503,7 +511,6 @@ void hal_init_hw() {
void load(char *ptr) {
printf("load :%s:\n", ptr);
load_comp(comp_by_name(ptr));
}
@@ -795,12 +802,16 @@ uint32_t hal_parse_(char *cmd) {
case 1: // search comps
for(int i = 0; i < hal.comp_inst_count; i++) {
if(!strncmp(hal.comp_insts[i].comp->name, sinkc, strlen(sinkc))) {
printf("%s%lu\n", hal.comp_insts[i].comp->name, hal.comp_insts[i].instance);
if(hal.debug_level < 1){
printf("%s%lu\n", hal.comp_insts[i].comp->name, hal.comp_insts[i].instance);
}
found = 1;
}
}
if(!found) {
printf("<font color=\"FireBrick\">not found: %s</font>\n", cmd);
if(hal.debug_level < 2){
printf("<font color=\"FireBrick\">not found: %s</font>\n", cmd);
}
}
break;
case 2: // search comps + instance
@@ -815,7 +826,9 @@ uint32_t hal_parse_(char *cmd) {
}
}
if(!found) {
printf("<font color=\"FireBrick\">not found: %s</font>\n", cmd);
if(hal.debug_level < 2){
printf("<font color=\"FireBrick\">not found: %s</font>\n", cmd);
}
}
break;
case 3:
@@ -825,12 +838,17 @@ uint32_t hal_parse_(char *cmd) {
source = pin_inst_by_name(sourcec, sourcei, sourcep);
if(sink && source) {
sink->source = source;
printf("OK %s%lu.%s <= %s%lu.%s = %f\n", sinkc, sinki, sinkp, sourcec, sourcei, sourcep, source->source->value);
if(hal.debug_level < 1){
printf("OK %s%lu.%s <= %s%lu.%s = %f\n", sinkc, sinki, sinkp, sourcec, sourcei, sourcep, source->source->value);
}
} else if(sink) {
printf("<font color=\"FireBrick\">not found: %s%lu.%s</font>\n", sourcec, sourcei, sourcep);
if(hal.debug_level < 2){
printf("<font color=\"FireBrick\">not found: %s%lu.%s</font>\n", sourcec, sourcei, sourcep);
}
} else {
printf("<font color=\"FireBrick\">not found: %s%lu.%s</font>\n", sinkc, sinki, sinkp);
if(hal.debug_level < 2){
printf("<font color=\"FireBrick\">not found: %s%lu.%s</font>\n", sinkc, sinki, sinkp);
}
}
} else { // search comps + instance + pin
for(int i = 0; i < hal.comp_inst_count; i++) {
@@ -846,7 +864,9 @@ uint32_t hal_parse_(char *cmd) {
}
}
if(!found) {
printf("<font color=\"FireBrick\">not found: %s</font>\n", cmd);
if(hal.debug_level < 2){
printf("<font color=\"FireBrick\">not found: %s</font>\n", cmd);
}
}
}
break;
@@ -855,13 +875,19 @@ uint32_t hal_parse_(char *cmd) {
if(sink) {
sink->value = value;
sink->source = sink;
printf("OK %s%lu.%s = %f\n", sinkc, sinki, sinkp, value);
if(hal.debug_level < 1){
printf("OK %s%lu.%s = %f\n", sinkc, sinki, sinkp, value);
}
} else {
printf("<font color=\"FireBrick\">not found: %s%lu.%s</font>\n", sinkc, sinki, sinkp);
if(hal.debug_level < 2){
printf("<font color=\"FireBrick\">not found: %s%lu.%s</font>\n", sinkc, sinki, sinkp);
}
}
break;
default:
printf("<font color=\"FireBrick\">not found: %s</font>\n", cmd);
if(hal.debug_level < 2){
printf("<font color=\"FireBrick\">not found: %s</font>\n", cmd);
}
}
return (0);
}
@@ -875,15 +901,15 @@ void hal_error(uint32_t error_handler) {
hal.hal_state = MISC_ERROR;
}
void fault() {
void fault(char *ptr) {
printf("trigger fault handler\n");
volatile uint32_t *ptr = (uint32_t *)0x08010000;
ptr[0] = 1;
volatile uint32_t *p = (uint32_t *)0x08010000;
p[0] = 1;
}
COMMAND("fault", fault, "trigger fault");
void about() {
void about(char *ptr) {
printf("######## software info ########\n");
printf(
"%s v%i.%i.%i %s\n",
@@ -919,3 +945,19 @@ void about() {
}
COMMAND("about", about, "show system infos");
void hal_set_debug_level(uint32_t debug_level){
hal.debug_level = debug_level;
}
void debug_level(char *ptr){
int debug_level = 0;
if(ptr){
sscanf(ptr, "%i", &debug_level);
}
hal_set_debug_level(CLAMP(debug_level, 0, 2));
}
COMMAND("debug_level", debug_level, "set hal debug level, 0 = print all, 1 = print errors, 2 = no output");
+7
View File
@@ -160,6 +160,12 @@ typedef struct {
volatile float frt_period;
hal_error_t error_info;
volatile enum {
PRINT_ALL,
PRINT_ERRORS,
NO_PRINT,
} debug_level;
} hal_t;
extern hal_t hal;
@@ -183,5 +189,6 @@ void hal_run_frt();
void hal_run_nrt();
uint32_t hal_parse(char *cmd);
void hal_error(uint32_t error_handler);
void hal_set_debug_level(uint32_t debug_level);
#include "hal_tbl.h"
+25 -8
View File
@@ -47,6 +47,8 @@ struct io_ctx_t {
float overvoltage_error;
float overcurrent_error;
float fault_pin_error;
uint32_t hv_temp;
uint32_t mot_temp;
};
#define ARES 4096.0 // analog resolution, 12 bit
@@ -127,6 +129,9 @@ static void nrt_init(volatile void *ctx_ptr, volatile hal_pin_inst_t *pin_ptr) {
ctx->overvoltage_error = 0;
ctx->overcurrent_error = 0;
ctx->fault_pin_error = 0;
ctx->hv_temp = 0;
ctx->mot_temp = 0;
#ifdef HV_EN_PIN
GPIO_InitStruct.Pin = HV_EN_PIN;
@@ -186,13 +191,9 @@ static void rt_func(float period, volatile void *ctx_ptr, volatile hal_pin_inst_
PIN(u) = VOLT(adc_34_buf[5] & 0xFFFF) * 0.05 + PIN(u) * 0.95;
PIN(udc) = VOLT(adc_34_buf[5] >> 16) * 0.05 + PIN(udc) * 0.95;
PIN(iabs) = MAX3(ABS(PIN(iu)), PIN(iv), PIN(iw));
PIN(hv_temp) = r2temp(HV_R(ADC(adc_34_buf[0] >> 16))) * 0.01 + PIN(hv_temp) * 0.99; // 5.5u
PIN(mot_temp) = MOT_R(MOT_REF(ADC(adc_34_buf[3] >> 16))); // 1.4u
HAL_GPIO_WritePin(LED_PORT, LED_PIN, BLINK(PIN(led)) > 0 ? GPIO_PIN_SET : GPIO_PIN_RESET); // 0.1u
// mot temp fault
// f4 hv fault = max(f4 fault, f3 fault)
ctx->hv_temp = adc_34_buf[0];
ctx->mot_temp = adc_34_buf[3];
if(err_filter(&(ctx->overtemp_error), 5.0, 0.001, PIN(hv_temp) > ABS_MAX_TEMP)) {
ctx->fault = HV_OVERTEMP;
}
@@ -238,9 +239,25 @@ static void rt_func(float period, volatile void *ctx_ptr, volatile hal_pin_inst_
}
}
void nrt_func(volatile void *ctx_ptr, volatile hal_pin_inst_t *pin_ptr) {
struct io_ctx_t *ctx = (struct io_ctx_t *)ctx_ptr;
struct io_pin_ctx_t *pins = (struct io_pin_ctx_t *)pin_ptr;
uint32_t led = PIN(led);
if(hal.hal_state != HAL_OK2){
led = HV_HAL_FAULT;
}
HAL_GPIO_WritePin(LED_PORT, LED_PIN, BLINK(led) > 0 ? GPIO_PIN_SET : GPIO_PIN_RESET);
PIN(hv_temp) = r2temp(HV_R(ADC(ctx->hv_temp >> 16))) * 0.01 + PIN(hv_temp) * 0.99;
PIN(mot_temp) = MOT_R(MOT_REF(ADC(ctx->mot_temp >> 16)));
}
hal_comp_t io_comp_struct = {
.name = "io",
.nrt = 0,
.nrt = nrt_func,
.rt = rt_func,
.frt = 0,
.nrt_init = nrt_init,
+1 -1
View File
@@ -157,7 +157,7 @@ static void rt_start(volatile void *ctx_ptr, volatile hal_pin_inst_t *pin_ptr) {
PIN(timeout) = 0.0;
PIN(idle) = 0.0;
PIN(dma_pos_cmd) = 4;
PIN(inc) = 10;
PIN(inc) = 5;
PIN(window) = 1;
}
+10 -8
View File
@@ -237,15 +237,16 @@ int main(void) {
hal_init(1.0 / 15000.0, 0.0);
// hal load comps
load_comp(comp_by_name("term"));
hal_parse("debug_level 1");
hal_parse("load term");
// load_comp(comp_by_name("sim"));
load_comp(comp_by_name("io"));
load_comp(comp_by_name("ls"));
load_comp(comp_by_name("dq"));
load_comp(comp_by_name("idq"));
load_comp(comp_by_name("svm"));
load_comp(comp_by_name("hv"));
load_comp(comp_by_name("curpid"));
hal_parse("load io");
hal_parse("load ls");
hal_parse("load dq");
hal_parse("load idq");
hal_parse("load svm");
hal_parse("load hv");
hal_parse("load curpid");
hal_parse("term0.rt_prio = 0.1");
hal_parse("ls0.rt_prio = 0.6");
@@ -323,6 +324,7 @@ int main(void) {
hal_parse("curpid0.en = ls0.en");
hal_parse("curpid0.cmd_mode = ls0.cmd_mode");
hal_parse("hv0.arr = ls0.arr");
hal_parse("debug_level 0");
// hal parse config
// hal_init_nrt();