add flash.c and all stubs for common functions

This commit is contained in:
Edward Emelianov
2023-02-13 21:55:18 +03:00
parent 2ecd2d188e
commit 617daf62c7
13 changed files with 816 additions and 7 deletions

View File

@@ -20,9 +20,11 @@
#include <string.h>
#include "can.h"
#include "flash.h"
#include "hardware.h"
#include "hdr.h"
#include "proto.h"
#include "commonproto.h"
#include "version.inc"
// software ignore buffer size
@@ -371,20 +373,134 @@ int fn_canresume(_U_ uint32_t hash, _U_ char *args){
return RET_GOOD;
}
int fn_reset(_U_ uint32_t hash, _U_ char *args){
// dump base commands codes (for CAN protocol)
int fn_dumpcmd(_U_ uint32_t hash, _U_ char *args){ // "dumpcmd" (1223955823)
USB_sendstr("CANbus commands list:\n");
for(uint16_t i = 1; i < CCMD_AMOUNT; ++i){
if(!cancmds[i]) continue;
printu(i);
USB_sendstr(" - ");
USB_sendstr(cancmds[i]);
newline();
}
return RET_GOOD;
}
int fn_reset(_U_ uint32_t hash, _U_ char *args){ // "reset" (1907803304)
USB_sendstr("Soft reset\n");
USB_sendall(); // wait until everything will gone
NVIC_SystemReset();
return RET_GOOD;
}
int fn_time(_U_ uint32_t hash, _U_ char *args){
int fn_time(_U_ uint32_t hash, _U_ char *args){ // "time" (19148340)
USB_sendstr("Time (ms): ");
printu(Tms);
USB_putbyte('\n');
return RET_GOOD;
}
static const char* errtxt[ERR_AMOUNT] = {
[ERR_OK] = "all OK",
[ERR_BADPAR] = "wrong parameter's value",
[ERR_BADVAL] = "wrong setter of parameter",
[ERR_WRONGLEN] = "bad message length",
[ERR_BADCMD] = "unknown command",
[ERR_CANTRUN] = "temporary can't run given command",
};
int fn_dumperr(_U_ uint32_t hash, _U_ char *args){ // "dumperr" (1223989764)
USND("Error codes:");
for(int i = 0; i < ERR_AMOUNT; ++i){
printu(i); USB_sendstr(" - ");
USB_sendstr(errtxt[i]); newline();
}
return RET_GOOD;
}
static int canusb_function(uint32_t hash, char *args){
errcodes e = ERR_BADCMD;
uint32_t N;
int32_t val = 0;
uint8_t par = CANMESG_NOPAR;
if(*args){
const char *n = getnum(args, &N);
if(n != args){ // get parameter
if(N >= CANMESG_NOPAR){
USND("Wrong parameter value");
return RET_GOOD;
}
par = (uint8_t) N;
n = strchr(n, '=');
if(n){
const char *nxt = getnum(n, &N);
if(nxt != n){ // give flag issetter
val = (int32_t) N;
par |= SETTERFLAG;
}
}
}
}
switch(hash){
case CMD_PING:
e = cu_ping(par, &val);
break;
default:
break;
}
//if(e < ERR_OK || e >= ERR_AMOUNT) USND("Bad return code");
//else
if(ERR_OK != e){
USB_sendstr(errtxt[e]); newline();
}else{
USB_sendstr("OK par");
if(par != CANMESG_NOPAR) printu(PARBASE(par));
USB_putbyte('='); printi(val);
newline();
}
return RET_GOOD;
}
#define AL __attribute__ ((alias ("canusb_function")))
// COMMON with CAN
int fn_ping(_U_ uint32_t hash, _U_ char *args) AL; //* "ping" (10561715)
// not realized yet
int fn_abspos(_U_ uint32_t hash, _U_ char *args) AL; //* "abspos" (3056382221)
int fn_accel(_U_ uint32_t hash, _U_ char *args) AL; //* "accel" (1490521981)
int fn_adc(_U_ uint32_t hash, _U_ char *args) AL; //* "adc" (2963026093)
int fn_button(_U_ uint32_t hash, _U_ char *args) AL; //* "button" (1093508897)
int fn_canid(_U_ uint32_t hash, _U_ char *args) AL; // "canid" (2040257924)
int fn_diagn(_U_ uint32_t hash, _U_ char *args) AL; // "diagn" (2334137736)
int fn_emstop(_U_ uint32_t hash, _U_ char *args) AL; //* "emstop" (2965919005)
int fn_eraseflash(_U_ uint32_t hash, _U_ char *args) AL; // "eraseflash" (3177247267)
int fn_esw(_U_ uint32_t hash, _U_ char *args) AL; //* "esw" (2963094612)
int fn_eswreact(_U_ uint32_t hash, _U_ char *args) AL; //* "eswreact" (1614224995)
int fn_goto(_U_ uint32_t hash, _U_ char *args) AL; // "goto" (4286309438)
int fn_gotoz(_U_ uint32_t hash, _U_ char *args) AL; //* "gotoz" (3178103736)
int fn_gpio(_U_ uint32_t hash, _U_ char *args) AL; //* "gpio" (4286324660)
int fn_gpioconf(_U_ uint32_t hash, _U_ char *args) AL; // "gpioconf" (1309721562)
int fn_maxspeed(_U_ uint32_t hash, _U_ char *args) AL; //* "maxspeed" (1498078812)
int fn_maxsteps(_U_ uint32_t hash, _U_ char *args) AL; //* "maxsteps" (1506667002)
int fn_mcut(_U_ uint32_t hash, _U_ char *args) AL; //* "mcut" (4022718)
int fn_mcuvdd(_U_ uint32_t hash, _U_ char *args) AL; //* "mcuvdd" (2517587080)
int fn_microsteps(_U_ uint32_t hash, _U_ char *args) AL; //* "microsteps" (3974395854)
int fn_minspeed(_U_ uint32_t hash, _U_ char *args) AL; //* "minspeed" (3234848090)
int fn_motflags(_U_ uint32_t hash, _U_ char *args) AL; //* "motflags" (2153634658)
int fn_motmul(_U_ uint32_t hash, _U_ char *args) AL; // "motmul" (1543400099)
int fn_motreinit(_U_ uint32_t hash, _U_ char *args) AL; //* "motreinit" (199682784)
int fn_relpos(_U_ uint32_t hash, _U_ char *args) AL; //* "relpos" (1278646042)
int fn_relslow(_U_ uint32_t hash, _U_ char *args) AL; //* "relslow" (1742971917)
int fn_saveconf(_U_ uint32_t hash, _U_ char *args) AL; //* "saveconf" (141102426)
int fn_screen(_U_ uint32_t hash, _U_ char *args) AL; // "screen" (2100809349)
int fn_speedlimit(_U_ uint32_t hash, _U_ char *args) AL; //* "speedlimit" (1654184245)
int fn_state(_U_ uint32_t hash, _U_ char *args) AL; //* "state" (2216628902)
int fn_stop(_U_ uint32_t hash, _U_ char *args) AL; //* "stop" (17184971)
int fn_tmcbus(_U_ uint32_t hash, _U_ char *args) AL; // "tmcbus" (1906135955)
int fn_udata(_U_ uint32_t hash, _U_ char *args) AL; // "udata" (2736127636)
int fn_usartstatus(_U_ uint32_t hash, _U_ char *args) AL; // "usartstatus" (4007098968)
/**
* @brief cmd_parser - command parsing
* @param txt - buffer with commands & data