src.dualinventive.com/dinet/libdi_fw/include/di_fw/pt.h

308 lines
11 KiB
C

/**
* @file include/pt.h
* @brief production test firmware common constructs
* @date sept 18, 2018
* @author R.R.R. van Leeuwen (Asmyldof)
* @copyright 2018 Dual Inventive Technology Centre B.V.
*
* Header file to the Production Test system's common procedures and enumerations
*
* @addtogroup MAIN
* @{
*/
#ifndef _INCLUDE_LIBDIFW_PT_H_
#define _INCLUDE_LIBDIFW_PT_H_
#include <di/errno.h>
#include <di_fw/os.h>
#include <di/constants/rpc.h>
/** Time in milliseconds to sleep between IIC transactions for the local IO-Expander test. */
#define DI_PT_IIC_RETRANSACT_SLEEPTIME 50
/** Shell prefix for Test Pass */
#define PASS_PREFIX_STRING "PASS: "
/** Shell prefix for Test Fail */
#define FAIL_PREFIX_STRING "FAIL: "
/** Shell prefix for run time Error */
#define ERROR_PREFIX_STRING "ERROR: "
/** Shell prefix for background information */
#define INFO_PREFIX_STRING "INFO: "
/* An enumeration of available IOpins, for internal code clarity only */
enum di_fw_pt_iopinlist {
DI_FW_PT_IOPIN_CLOUD_BLUE = 0, /* 0 */
DI_FW_PT_IOPIN_CLOUD_GREEN, /* 1 */
DI_FW_PT_IOPIN_CLOUD_RED, /* 2 */
DI_FW_PT_IOPIN_UI_INPUT, /* 3 */
DI_FW_PT_IOPIN_CHG_14V6, /* 4 */
DI_FW_PT_IOPIN_CHG_ON, /* 5 */
DI_FW_PT_IOPIN_US1_ON, /* 6 */
DI_FW_PT_IOPIN_US2_ON, /* 7 */
DI_FW_PT_IOPIN_CAN_RX, /* 8 */
DI_FW_PT_IOPIN_CAN_TX, /* 9 */
DI_FW_PT_IOPIN_DEAD_MANS_SWITCH, /* 10 */
DI_FW_PT_IOPIN_US1_DATA, /* 11 */
DI_FW_PT_IOPIN_US2_DATA, /* 12 */
DI_FW_PT_IOPIN_ONOFF_SWITCH, /* 13 */
DI_FW_PT_IOPIN_RESET_DNCM1, /* 14 */
DI_FW_PT_IOPIN_RESET_DNCM2, /* 15 */
DI_FW_PT_IOPIN_VERSION0, /* 16 */
DI_FW_PT_IOPIN_VERSION1, /* 17 */
DI_FW_PT_IOPIN_VERSION2, /* 18 */
DI_FW_PT_IOPIN_VERSION3, /* 19 */
DI_FW_PT_IOPIN_ENABLE_BAT, /* 20 */
DI_FW_PT_IOPIN_SUB_VERSION0, /* 21 */
DI_FW_PT_IOPIN_SUB_VERSION1, /* 22 */
DI_FW_PT_IOPIN_SUB_VERSION2, /* 23 */
DI_FW_PT_IOPIN_CHARGE_STAT1, /* 24 */
DI_FW_PT_IOPIN_CHARGE_STAT2, /* 25 */
DI_FW_PT_IOPIN_CHARGE_HIGH_POWER, /* 26 */
DI_FW_PT_IOPIN_DNCM_OFF, /* 27 */
DI_FW_PT_IOPIN_WARN_LED_1, /* 28 */
DI_FW_PT_IOPIN_WARN_LED_2, /* 29 */
DI_FW_PT_IOPIN_WARN_LED_3, /* 30 */
DI_FW_PT_IOPIN_WARN_LED_4, /* 31 */
DI_FW_PT_IOPIN_BOOST_ENABLE, /* 32 */
DI_FW_PT_IOPIN_AMP_ENABLE, /* 33 */
DI_FW_PT_IOPIN_ATTENTION_IN, /* 34 */
DI_FW_PT_IOPIN_ATTENTION_OUT, /* 35 */
DI_FW_PT_IOPIN_EMERGENCY_BTN, /* 36 */
DI_FW_PT_IOPIN_LEADER_SELECT, /* 37 */
DI_FW_PT_IOPIN_CAN_ENABLE, /* 38 */
DI_FW_PT_IOPIN_CAN_LISTEN, /* 39 */
DI_FW_PT_IOPIN_NOT_LEADER_SELECT, /* 40 */
DI_FW_PT_IOPIN_ENABLE_UI_POWER, /* 41 */
DI_FW_PT_IOPIN_CAN_RX_2, /* 42 */
DI_FW_PT_IOPIN_CAN_TX_2, /* 43 */
DI_FW_PT_IOPIN_ONOFF_SWITCH_2, /* 44 */
DI_FW_PT_IOPIN_POWERUP, /* 45 */
DI_FW_PT_IOPIN_EOL /* END OF LIST : NOT A COMMAND */
};
/* set of case-insensitive code words to identify the pins on the shell */
#define DI_FW_PT_IOPIN_NAMES { \
"BLUE", /* DI_FW_PT_IOPIN_CLOUD_BLUE */\
"GREEN", /* DI_FW_PT_IOPIN_CLOUD_GREEN */\
"RED", /* DI_FW_PT_IOPIN_CLOUD_RED */\
"UIIN", /* DI_FW_PT_IOPIN_UI_INPUT */\
"CHGHIV", /* DI_FW_PT_IOPIN_CHG_14V6 */\
"CHGON", /* DI_FW_PT_IOPIN_CHG_ON */\
"US1ON", /* DI_FW_PT_IOPIN_US1_ON */\
"US2ON", /* DI_FW_PT_IOPIN_US2_ON */\
"CANRX", /* DI_FW_PT_IOPIN_CAN_RX */\
"CANTX", /* DI_FW_PT_IOPIN_CAN_TX */\
"DMSWITCH", /* DI_FW_PT_IOPIN_DEAD_MANS_SWITCH */\
"US1DAT", /* DI_FW_PT_IOPIN_US1_DATA */\
"US2DAT", /* DI_FW_PT_IOPIN_US2_DATA */\
"ONOFFSW", /* DI_FW_PT_IOPIN_ONOFF_SWITCH */\
"RESETDNCM1", /* DI_FW_PT_IOPIN_RESET_DNCM1 */\
"RESETDNCM2", /* DI_FW_PT_IOPIN_RESET_DNCM2 */\
"VERSION0", /* DI_FW_PT_IOPIN_VERSION0 */\
"VERSION1", /* DI_FW_PT_IOPIN_VERSION1 */\
"VERSION2", /* DI_FW_PT_IOPIN_VERSION2 */\
"VERSION3", /* DI_FW_PT_IOPIN_VERSION3 */\
"ENBAT", /* DI_FW_PT_IOPIN_ENABLE_BAT */\
"SUBVERSION0", /* DI_FW_PT_IOPIN_SUB_VERSION0 */\
"SUBVERSION1", /* DI_FW_PT_IOPIN_SUB_VERSION1 */\
"SUBVERSION2", /* DI_FW_PT_IOPIN_SUB_VERSION2 */\
"CHGSTAT1", /* DI_FW_PT_IOPIN_CHARGE_STAT1 */\
"CHGSTAT2", /* DI_FW_PT_IOPIN_CHARGE_STAT2 */\
"CHGHIPOW", /* DI_FW_PT_IOPIN_CHARGE_HIGH_POWER */\
"DNCMOFF", /* DI_FW_PT_IOPIN_DNCM_OFF */\
"WARNLED1", /* DI_FW_PT_IOPIN_WARN_LED_1 */\
"WARNLED2", /* DI_FW_PT_IOPIN_WARN_LED_2 */\
"WARNLED3", /* DI_FW_PT_IOPIN_WARN_LED_3 */\
"WARNLED4", /* DI_FW_PT_IOPIN_WARN_LED_4 */\
"BOOSTEN", /* DI_FW_PT_IOPIN_BOOST_ENABLE */\
"AMPEN", /* DI_FW_PT_IOPIN_AMP_ENABLE */\
"ATTENTION_IN", /* DI_FW_PT_IOPIN_ATTENTION_IN */\
"ATTENTION_OUT", /* DI_FW_PT_IOPIN_ATTENTION_OUT */\
"EMERGENCY", /* DI_FW_PT_IOPIN_EMERGENCY_BTN */\
"LEADER_SEL", /* DI_FW_PT_IOPIN_LEADER_SELECT */\
"CAN_ENABLE", /* DI_FW_PT_IOPIN_CAN_ENABLE */\
"CAN_LISTEN", /* DI_FW_PT_IOPIN_CAN_LISTEN */\
"NOT_LEADER_SEL", /* DI_FW_PT_IOPIN_NOT_LEADER_SELECT */\
"ENABLE_UIPOW", /* DI_FW_PT_IOPIN_ENABLE_UI_POWER */\
"CANRX_2", /* DI_FW_PT_IOPIN_CAN_RX_2, 42 */\
"CANTX_2", /* DI_FW_PT_IOPIN_CAN_TX_2, 43 */\
"ONOFFSW2", /* DI_FW_PT_IOPIN_ONOFF_SWITCH_2, 44 */\
"POWERUP" /* DI_FW_PT_IOPIN_POWERUP, 45 */\
}
/* indicates whether a pin has shell-write permission. Only a 1 here allows shell writing to the pin. */
#define DI_FW_PT_IOPIN_IS_OUTPUT { \
1, /* DI_FW_PT_IOPIN_CLOUD_BLUE */\
1, /* DI_FW_PT_IOPIN_CLOUD_GREEN */\
1, /* DI_FW_PT_IOPIN_CLOUD_RED */\
0, /* DI_FW_PT_IOPIN_UI_INPUT */\
1, /* DI_FW_PT_IOPIN_CHG_14V6 */\
1, /* DI_FW_PT_IOPIN_CHG_ON */\
1, /* DI_FW_PT_IOPIN_US1_ON */\
1, /* DI_FW_PT_IOPIN_US2_ON */\
0, /* DI_FW_PT_IOPIN_CAN_RX */\
1, /* DI_FW_PT_IOPIN_CAN_TX */\
0, /* DI_FW_PT_IOPIN_DEAD_MANS_SWITCH */\
0, /* DI_FW_PT_IOPIN_US1_DATA */\
0, /* DI_FW_PT_IOPIN_US2_DATA */\
0, /* DI_FW_PT_IOPIN_ONOFF_SWITCH */\
1, /* DI_FW_PT_IOPIN_RESET_DNCM1 */\
1, /* DI_FW_PT_IOPIN_RESET_DNCM2 */\
0, /* DI_FW_PT_IOPIN_VERSION0 */\
0, /* DI_FW_PT_IOPIN_VERSION1 */\
0, /* DI_FW_PT_IOPIN_VERSION2 */\
0, /* DI_FW_PT_IOPIN_VERSION3 */\
0, /* DI_FW_PT_IOPIN_ENABLE_BAT */\
0, /* DI_FW_PT_IOPIN_SUB_VERSION0 */\
0, /* DI_FW_PT_IOPIN_SUB_VERSION1 */\
0, /* DI_FW_PT_IOPIN_SUB_VERSION2 */\
0, /* DI_FW_PT_IOPIN_CHARGE_STAT1 */\
0, /* DI_FW_PT_IOPIN_CHARGE_STAT2 */\
1, /* DI_FW_PT_IOPIN_CHARGE_HIGH_POWER */\
1, /* DI_FW_PT_IOPIN_DNCM_OFF */\
1, /* DI_FW_PT_IOPIN_WARN_LED_1 */\
1, /* DI_FW_PT_IOPIN_WARN_LED_2 */\
1, /* DI_FW_PT_IOPIN_WARN_LED_3 */\
1, /* DI_FW_PT_IOPIN_WARN_LED_4 */\
1, /* DI_FW_PT_IOPIN_BOOST_ENABLE */\
1, /* DI_FW_PT_IOPIN_AMP_ENABLE */\
0, /* DI_FW_PT_IOPIN_ATTENTION_IN */\
1, /* DI_FW_PT_IOPIN_ATTENTION_OUT */\
0, /* DI_FW_PT_IOPIN_EMERGENCY_BTN */\
0, /* DI_FW_PT_IOPIN_LEADER_SELECT */\
1, /* DI_FW_PT_IOPIN_CAN_ENABLE */\
1, /* DI_FW_PT_IOPIN_CAN_LISTEN */\
0, /* DI_FW_PT_IOPIN_NOT_LEADER_SELECT */\
1, /* DI_FW_PT_IOPIN_ENABLE_UI_POWER */\
0, /* DI_FW_PT_IOPIN_CAN_RX_2, 42 */\
1, /* DI_FW_PT_IOPIN_CAN_TX_2, 43 */\
0, /* DI_FW_PT_IOPIN_ONOFF_SWITCH_2, 44 */\
1 /* DI_FW_PT_IOPIN_POWERUP, 45 */\
}
/* List of IO Pins to override.
* Best to only use this for pins that get configured into a special mode in normal mode, but need to be IO in PT.
* It could theoretically be the entire list of IOs, since they are used only once and locally in PT, but
* using no overrides allows an instant check of correct pin functioning and polarity with default configurations,
* where possible. Thus here, initially, only the PWMed and CAN pins are listed.
*/
#define DI_FW_PT_IOPIN_OVERRIDE_LIST {\
DI_FW_PT_IOPIN_CLOUD_BLUE, /* 0 */\
DI_FW_PT_IOPIN_CLOUD_GREEN, /* 1 */\
DI_FW_PT_IOPIN_CLOUD_RED, /* 2 */\
DI_FW_PT_IOPIN_CAN_RX, /* 8 */\
DI_FW_PT_IOPIN_CAN_TX, /* 9 */\
DI_FW_PT_IOPIN_WARN_LED_1, /* 28 */\
DI_FW_PT_IOPIN_WARN_LED_2, /* 29 */\
DI_FW_PT_IOPIN_WARN_LED_3, /* 30 */\
DI_FW_PT_IOPIN_WARN_LED_4, /* 31 */\
DI_FW_PT_IOPIN_CAN_RX_2, /* 42 */\
DI_FW_PT_IOPIN_CAN_TX_2 /* 43 */\
}
/* The pin mode the IO pins in the list above should be set to, in order */
#define DI_FW_PT_IOPIN_OVERRIDE_MODE {\
PAL_MODE_OUTPUT_PUSHPULL, /* DI_FW_PT_IOPIN_CLOUD_BLUE, 0 */\
PAL_MODE_OUTPUT_PUSHPULL, /* DI_FW_PT_IOPIN_CLOUD_GREEN, 1 */\
PAL_MODE_OUTPUT_PUSHPULL, /* DI_FW_PT_IOPIN_CLOUD_RED, 2 */\
PAL_MODE_INPUT, /* DI_FW_PT_IOPIN_CAN_RX, 8 */\
PAL_MODE_OUTPUT_PUSHPULL, /* DI_FW_PT_IOPIN_CAN_TX, 9 */\
PAL_MODE_OUTPUT_PUSHPULL, /* DI_FW_PT_IOPIN_WARN_LED_1, 28 */\
PAL_MODE_OUTPUT_PUSHPULL, /* DI_FW_PT_IOPIN_WARN_LED_2, 29 */\
PAL_MODE_OUTPUT_PUSHPULL, /* DI_FW_PT_IOPIN_WARN_LED_3, 30 */\
PAL_MODE_OUTPUT_PUSHPULL, /* DI_FW_PT_IOPIN_WARN_LED_4 31 */\
PAL_MODE_INPUT, /* DI_FW_PT_IOPIN_CAN_RX_2, 42 */\
PAL_MODE_OUTPUT_PUSHPULL /* DI_FW_PT_IOPIN_CAN_TX_2, 43 */\
}
/**
* Wrapper function to print a status message with some special formatting to the shell.
* Please use defined prefixes, found in this header.
*/
void di_fw_pt_print_message(BaseSequentialStream *chp, const char *prefix, const char *format, ...);
/**
* Wrapper function to print a standard float response (voltages)
*/
void di_fw_pt_msg_float(BaseSequentialStream *chp, const float value);
/**
* Subroutine to test the IOExpander with some R/W bit patterns.
*/
void di_fw_pt_test_ioexpander(BaseSequentialStream *chp);
/**
* Simple function for toggling a pin
*/
void di_fw_pt_toggle_pin(BaseSequentialStream *chp, enum di_fw_pt_iopinlist pin);
/**
* Simple function for reading a pin
*/
bool di_fw_pt_read_pin(BaseSequentialStream *chp, enum di_fw_pt_iopinlist pin);
/**
* Simple function for writing to a pin
*/
void di_fw_pt_force_pin(BaseSequentialStream *chp, enum di_fw_pt_iopinlist pin, bool value);
/**
* Wrapper function for testing if a pin is legal
*/
bool di_fw_pt_pinlist_test(BaseSequentialStream *chp, enum di_fw_pt_iopinlist pin, bool verbose);
/**
* Subroutine for decoding the pin name into a number from the shell
* @param null terminated standard char string containing a pinname.
* @return An indexed value identifying the pin numerically, returns DI_FW_PT_IOPIN_EOL for failure
*/
enum di_fw_pt_iopinlist di_fw_pt_decode_iopin(char *pinname);
/**
* Function that retrieves the firmware version, build date and hardware version IO pin information.
*/
void di_fw_pt_print_versions(BaseSequentialStream *chp);
/**
* Standard function to toggle the light status on all pins controlling UI-Panel LEDs
*/
void di_fw_pt_toggle_lights(BaseSequentialStream *chp);
/**
* Standard function to turn off the light on all pins controlling UI-Panel LEDs
*/
void di_fw_pt_clear_lights(BaseSequentialStream *chp);
/**
* Standard function to turn on the light on all pins controlling UI-Panel LEDs
*/
void di_fw_pt_set_lights(BaseSequentialStream *chp);
/**
* Subroutine to grab the battery ADC value, based on input parameters, and convert to voltage.
*/
void di_fw_pt_get_battery_voltage(BaseSequentialStream *chp, int argc, char *argv[]);
/**
* Subroutine to grab the charger ADC value, based on input parameters, and convert to voltage.
*/
void di_fw_pt_get_charger_voltage(BaseSequentialStream *chp, int argc, char *argv[]);
/**
* Subroutine for reconfiguring the IOpins required here back to normal IO.
*/
void di_fw_pt_iopin_take_over(void);
/**
* Implementation of the "HELlo" shell command
* @param stream to read from
* @param nr of arguments that was passed on the command-line (apart from the command itself)
* @param arguments (strings) that were passed on the command-line
*/
void di_fw_pt_shell_cmd_hello(BaseSequentialStream *chp, int argc, char *argv[]);
#endif /* _INCLUDE_LIBDIFW_PT_H_ */