FreeCalypso > hg > freecalypso-tools
view rvinterf/tmsh/bsimcmd.c @ 982:1c5b485f10ba
fc-loadtool flash: do AMD reset after PL-J PPB write operations
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sat, 02 Dec 2023 06:04:37 +0000 |
parents | b3724fe6c581 |
children |
line wrap: on
line source
/* * In this module we are going to implement FreeCalypso BSIM * (battery simulation mode) commands. */ #include <sys/types.h> #include <stdio.h> #include <string.h> #include <strings.h> #include <stdlib.h> #include "limits.h" #include "localtypes.h" #include "etm.h" #include "bsim_etm_cmd.h" #include "exitcodes.h" cmd_bsim_query(argc, argv) char **argv; { u_char cmdpkt[4]; cmdpkt[1] = ETM_BSIM; cmdpkt[2] = BSIM_CMD_QUERY; send_etm_cmd(cmdpkt, 2); return(0); } cmd_bsim_disch(argc, argv) char **argv; { u_char cmdpkt[5]; cmdpkt[1] = ETM_BSIM; cmdpkt[2] = BSIM_CMD_DISCHARGE; cmdpkt[3] = strtoul(argv[1], 0, 0); send_etm_cmd(cmdpkt, 3); return(0); } cmd_bsim_start(argc, argv) char **argv; { u_char cmdpkt[4]; cmdpkt[1] = ETM_BSIM; cmdpkt[2] = BSIM_CMD_CHG_START; send_etm_cmd(cmdpkt, 2); return(0); } cmd_bsim_start_enable(argc, argv) char **argv; { u_char cmdpkt[5]; cmdpkt[1] = ETM_BSIM; cmdpkt[2] = BSIM_CMD_START_ENABLE; cmdpkt[3] = strtoul(argv[1], 0, 0); send_etm_cmd(cmdpkt, 3); return(0); } cmd_bsim_ci2cv(argc, argv) char **argv; { u_char cmdpkt[4]; cmdpkt[1] = ETM_BSIM; cmdpkt[2] = BSIM_CMD_CHG_CI2CV; send_etm_cmd(cmdpkt, 2); return(0); } cmd_bsim_complete(argc, argv) char **argv; { u_char cmdpkt[4]; cmdpkt[1] = ETM_BSIM; cmdpkt[2] = BSIM_CMD_CHG_COMPLETE; send_etm_cmd(cmdpkt, 2); return(0); } cmd_bsim_ichg(argc, argv) char **argv; { u_char cmdpkt[6]; unsigned ichg; ichg = strtoul(argv[1], 0, 0); cmdpkt[1] = ETM_BSIM; cmdpkt[2] = BSIM_CMD_SET_ICHG; cmdpkt[3] = ichg; cmdpkt[4] = ichg >> 8; send_etm_cmd(cmdpkt, 4); return(0); } static struct cmdtab { char *cmd; int minargs; int maxargs; int (*func)(); } bsim_cmds[] = { {"ci2cv", 0, 0, cmd_bsim_ci2cv}, {"complete", 0, 0, cmd_bsim_complete}, {"disch", 1, 1, cmd_bsim_disch}, {"ichg", 1, 1, cmd_bsim_ichg}, {"query", 0, 0, cmd_bsim_query}, {"start", 0, 0, cmd_bsim_start}, {"start-enable", 1, 1, cmd_bsim_start_enable}, {0, 0, 0, 0} }; cmd_bsim(argc, argv) char **argv; { struct cmdtab *tp; int extargs; for (tp = bsim_cmds; tp->cmd; tp++) if (!strcmp(tp->cmd, argv[1])) break; if (!tp->func) { printf("error: no such bsim command\n"); return(ERROR_USAGE); } extargs = argc - 2; if (extargs > tp->maxargs) { printf("error: too many arguments\n"); return(ERROR_USAGE); } if (extargs < tp->minargs) { printf("error: too few arguments\n"); return(ERROR_USAGE); } return tp->func(argc - 1, argv + 1); }