* FlexRay.h
*
* Created on: 29.11.2012
- * Author: michal
+ * Author: Michal Horn
*/
#ifndef FLEXRAY_H_
*\r
*******************************************************************/\r
\r
+#ifndef _FE_H_\r
+#define _FE_H_\r
\r
#define FRAY1 (&e_FRAY0_ST)\r
#define FRAY2 (&e_FRAY1_ST)\r
void Fr_TransmitTxLPdu(FRAY_ST *Fray_PST, bc *Fr_LSduPtr);\r
void Fr_ReceiveRxLPdu(FRAY_ST *Fray_PST, bc *Fr_LSduPtr);\r
\r
+#endif //_FE_H_\r
* cmd_adc.h
*
* Created on: 28.2.2013
- * Author: michal
+ * Author: Michal Horn
*/
#ifndef CMD_ADC_H_
#define CMD_ADC_H_
+#include "cmd_proc.h"
+
+extern cmd_des_t const *cmd_list_adc[];
#endif /* CMD_ADC_H_ */
* cmd_can.h
*
* Created on: 28.2.2013
- * Author: michal
+ * Author: Michal Horn
*/
#ifndef CMD_CAN_H_
#define CMD_CAN_H_
+#include "cmd_proc.h"
+
+extern cmd_des_t const *cmd_list_can[];
#endif /* CMD_CAN_H_ */
* cmd_dac.h
*
* Created on: 28.2.2013
- * Author: michal
+ * Author: Michal Horn
*/
#ifndef CMD_DAC_H_
#define CMD_DAC_H_
+#include "cmd_proc.h"
+
+extern cmd_des_t const *cmd_list_dac[];
#endif /* CMD_DAC_H_ */
* cmd_din.h
*
* Created on: 28.2.2013
- * Author: michal
+ * Author: Michal Horn
*/
#ifndef CMD_DIN_H_
#define CMD_DIN_H_
+#include "cmd_proc.h"
+
+extern cmd_des_t const *cmd_list_din[];
#endif /* CMD_DIN_H_ */
#ifndef _EMAC_TEST_H_
#define _EMAC_TEST_H_
+#include "cmd_proc.h"
+#include "sys_common.h"
+
/* ************************************************* */
/* Emac frame buffer related stuff */
/* ************************************************* */
} eth_frame_t;
/* ************************************************* */
-int emac_test(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]);
+
+extern cmd_des_t const *cmd_list_emac[];
+
+
#endif /* _EMAC_TEST_H_ */
* cmd_fray.h
*
* Created on: 28.2.2013
- * Author: michal
+ * Author: Michal Horn
*/
#ifndef CMD_FRAY_H_
#define CMD_FRAY_H_
+#include "cmd_proc.h"
+
+extern cmd_des_t const *cmd_list_fray[];
#endif /* CMD_FRAY_H_ */
* cmd_hbr.h
*
* Created on: 28.2.2013
- * Author: michal
+ * Author: Michal Horn
*/
#ifndef CMD_HBR_H_
#define CMD_HBR_H_
+#include "cmd_proc.h"
+
+extern cmd_des_t const *cmd_list_hbr[];
#endif /* CMD_HBR_H_ */
* cmd_hout.h
*
* Created on: 28.2.2013
- * Author: michal
+ * Author: Michal Horn
*/
#ifndef CMD_HOUT_H_
#define CMD_HOUT_H_
+#include "cmd_proc.h"
+
+extern cmd_des_t const *cmd_list_hout[];
#endif /* CMD_HOUT_H_ */
* cmd_lin.h
*
* Created on: 28.2.2013
- * Author: michal
+ * Author: Michal Horn
*/
#ifndef CMD_LIN_H_
#define CMD_LIN_H_
+#include "cmd_proc.h"
+extern cmd_des_t const *cmd_list_lin[];
#endif /* CMD_LIN_H_ */
* cmd_lout.h
*
* Created on: 28.2.2013
- * Author: michal
+ * Author: Michal Horn
*/
#ifndef CMD_LOUT_H_
#define CMD_LOUT_H_
+#include "cmd_proc.h"
+
+extern cmd_des_t const *cmd_list_lout[];
#endif /* CMD_LOUT_H_ */
* cmd_pin.h
*
* Created on: 28.2.2013
- * Author: michal
+ * Author: Michal Horn
*/
#ifndef CMD_PIN_H_
#define CMD_PIN_H_
+#include "cmd_proc.h"
+
+extern cmd_des_t const *cmd_list_pin[];
#endif /* CMD_PIN_H_ */
* cmd_port.h
*
* Created on: 28.2.2013
- * Author: michal
+ * Author: Michal Horn
*/
#ifndef CMD_PORT_H_
#define CMD_PORT_H_
+#include "cmd_proc.h"
+
+extern cmd_des_t const *cmd_list_port[];
#endif /* CMD_PORT_H_ */
#include "string.h"
#include "cmd_proc.h"
#include "cmdio_tisci.h"
-#include "sci.h"
+#include "ti_drv_sci.h"
#include "os_task.h"
#include "os_portmacro.h"
#ifndef CMD_SDRAM_H_
#define CMD_SDRAM_H_
+#include "cmd_proc.h"
+
+extern cmd_des_t const *cmd_list_sdram[];
#endif /* CMD_SDRAM_H_ */
* cmd_spi.h
*
* Created on: 28.2.2013
- * Author: michal
+ * Author: Michal Horn
*/
#ifndef CMD_SPI_H_
#define CMD_SPI_H_
+#include "cmd_proc.h"
+
+extern cmd_des_t const *cmd_list_spi[];
#endif /* CMD_SPI_H_ */
* cmd_vbat.h
*
* Created on: 28.2.2013
- * Author: michal
+ * Author: Michal Horn
*/
#ifndef CMD_VBAT_H_
#define CMD_VBAT_H_
+#include "cmd_proc.h"
+
+extern cmd_des_t const *cmd_list_vbat[];
#endif /* CMD_VBAT_H_ */
#include "os_queue.h"
#include "os_semphr.h"
#include "os_task.h"
-#include "sci.h"
+#include "ti_drv_sci.h"
/** Maximal length of buffers */
#define MAX_BUFFER_LEN 128
#ifndef ADC_CMD_H_
#define ADC_CMD_H_
-#include "adc.h"
+#include "ti_drv_adc.h"
#include "cmd_proc.h"
#include "sys_common.h"
#include "cmdio_tisci.h"
#define FRAY_SPI_H_
#include "port_def.h"
+
#define FRAY_SPICMD_INIT_VAL 0xFFFF
#define FRAY_NUM_PORTS 2
#ifndef HBRIDGE_H_
#define HBRIDGE_H_
-#include "spi_drv.h"
+#include "drv_spi.h"
#include "FreeRTOS.h"
#include "os_task.h"
-#include "het.h"
+#include "ti_drv_het.h"
int hbr_spi_wdg_callback (struct spi_drv * ifc, int code, struct spi_msg_head * msg); /* Called when whole transfer is finished */
int hbr_spi_wdg_transfer();
#ifndef HOUT_H_
#define HOUT_H_
-#include "het.h"
+#include "ti_drv_het.h"
#include "port_def.h"
void hout_pwm_set_signal(uint8_t hout_id, double period, uint32_t duty);
#ifndef HAL_GPIO_TMS570_DEF_H_
#define HAL_GPIO_TMS570_DEF_H_
-#include "dmm.h"
-#include "gio.h"
-#include "het.h"
+#include "ti_drv_dmm.h"
+#include "ti_drv_gio.h"
+#include "ti_drv_het.h"
#ifndef PORT_SHIFT
#ifndef _MYSPI_H_
#define _MYSPI_H_
-#include "sys_common.h"
-#include "spi_drv.h"
+//#include "sys_common.h"
+#include "drv_spi.h"
#define spi_compat_REG2 ((spiBASE_compat_t *)0xFFF7F600U)
#define spi_compat_REG4 ((spiBASE_compat_t *)0xFFF7FA00U)
#include "sys_core.h"\r
#include "system.h"\r
#include "sys_vim.h"\r
-#include "adc.h"\r
-#include "can.h"\r
-#include "mibspi.h"\r
-#include "het.h"\r
-#include "htu.h"\r
-#include "esm.h"\r
+#include "ti_drv_adc.h"\r
+#include "ti_drv_can.h"\r
+#include "ti_drv_mibspi.h"\r
+#include "ti_drv_het.h"\r
+#include "ti_drv_htu.h"\r
+#include "ti_drv_esm.h"\r
\r
/* USER CODE BEGIN (0) */\r
/* USER CODE END */\r
#define __SYS_SYSTEM_H__\r
\r
#include "sys_common.h"\r
-#include "gio.h"\r
+#include "ti_drv_gio.h"\r
\r
\r
/* USER CODE BEGIN (0) */\r
#define __DMM_H__\r
\r
#include "sys_common.h"\r
-#include "gio.h"\r
+#include "ti_drv_gio.h"\r
\r
#define DMM_SYNC 0\r
#define DMM_CLK 1\r
#define __HET_H__\r
\r
#include "sys_common.h"\r
-#include "gio.h"\r
+#include "ti_drv_gio.h"\r
#include <string.h>\r
\r
/* USER CODE BEGIN (0) */\r
\r
\r
#include "sys_common.h"\r
-#include "gio.h"\r
+#include "ti_drv_gio.h"\r
\r
\r
/** @enum i2cMode\r
#define __LIN_H__\r
\r
#include "sys_common.h"\r
-#include "gio.h"\r
+#include "ti_drv_gio.h"\r
\r
\r
/** @def LIN_BREAK_INT\r
#define __MIBSPI_H__\r
\r
#include "sys_common.h"\r
-#include "gio.h"\r
+#include "ti_drv_gio.h"\r
\r
\r
/** @enum triggerEvent\r
#define __SCI_H__\r
\r
#include "sys_common.h"\r
-#include "gio.h"\r
+#include "ti_drv_gio.h"\r
\r
\r
/** @enum sciIntFlags\r
#define __val2mfld(mask,val) (((mask)&~((mask)<<1))*(val)&(mask))
#define __mfld2val(mask,val) (((val)&(mask))/((mask)&~((mask)<<1)))
+#define MAX_PARAM_VALUES_NUM 64
/* skip space/blank characters, return 0 if no space found */
int si_skspace(char **ps);
* cmd_adc.c
*
* Created on: 28.2.2013
- * Author: michal
+ * Author: Michal Horn
+ *
+ * Commands for ADC1 port reading
+ */
+
+#include "cmd_adc.h"
+#include "cmdio_tisci.h"
+#include "port_def.h"
+
+
+/** Reads values from ADC1 pins
+ * @param[in] cmd_io Pointer to IO stack
+ * @param[in] des Pointer to command descriptor
+ * @param[in] param Parameters of command
+ * @return 0 when OK or error code
*/
+int cmd_do_read_adc1_values(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
+{
+ char numBuf[4]; // Buffer used for i2str conversion
+ uint32_t i; // Cycle control variable
+ port_desc_t* desc;
+ uint32_t values[PORT_ADC_CHANNEL_NUM*2];
+ int ret;
+
+ desc = port_get_dsc(PORT_NAME_ADC, -1);
+
+ ret = desc->port_getfnc_ptr(desc->config, PORT_ADC_CHANNEL_NUM, values);
+ if (ret < 0)
+ return ret;
+
+ print((uint8_t *)"\r\nADC1: values: ");
+ /* conversion results : */
+ for (i = 0; i < PORT_ADC_CHANNEL_NUM; i++) {
+ print((uint8_t *)"\r\nChannel: ");
+ i2str(numBuf, values[i+PORT_ADC_CHANNEL_NUM], 1, 10);
+ print((uint8_t *)numBuf);
+ print((uint8_t *)"\tvalue: ");
+ i2str(numBuf, values[i], 1, 10);
+ print((uint8_t *)numBuf);
+ print((uint8_t *)" 0x");
+ i2str(numBuf, values[i], 1, 16);
+ print((uint8_t *)numBuf);
+ }
+ return 0;
+}
+/** Descriptor of command for lin loopback test */
+cmd_des_t const cmd_des_read_adc1={
+ 0, 0,
+ "readadc","Reads values from ADC1",
+ cmd_do_read_adc1_values, (void *)&cmd_list_adc
+};
+/** List of commands for adc, defined as external */
+cmd_des_t const *cmd_list_adc[]={
+ &cmd_des_read_adc1,
+ NULL
+};
* cmd_can.c
*
* Created on: 28.2.2013
- * Author: michal
+ * Author: Michal Horn
+ *
+ * Commands for CAN control
+ */
+
+#include "cmd_can.h"
+#include "ti_drv_can.h"
+#include "FreeRTOS.h"
+#include "os_semphr.h"
+#include "ti_drv_dmm.h"
+#include "stdio.h"
+#include "cmdio_tisci.h"
+#include "string.h"
+
+/** Semaphore used for blocking task until message is received */
+xSemaphoreHandle canMsgReceived;
+/** Semaphore used for blocking task until message is sent */
+xSemaphoreHandle canMsgSent;
+/** Pointer to Destination CAN registers */
+canBASE_t* canDst;
+/** Pointer to Source CAN registers */
+canBASE_t* canSrc;
+/** Can message box for received messages */
+uint32_t canMsgBox;
+/** Error counter for errors in sending */
+uint32_t canSendError;
+/** Error counter for errors in receiving */
+uint32_t canRecError;
+
+/**
+ * @brief Function for printing CAN error status
+ *
+ * Function prints CAN status as a human readable string and status code.
+ *
+ * @note The function canInit has to be called before this function can be used.
+ *
+ * @param[in] node Pointer to CAN registers
+ * @param[in] str String to be printed befor status and code
+ * @param[in] errorStatus Code of the CAN status
+ * @param[in] isFinal 0 when error testing during sending and receiving
+ * 1 when final printout was requested
+ */
+uint32_t canCheckForError(canBASE_t *node, const char* str, uint32_t *errorStatus, uint8_t isFinal)
+{
+ //uint32_t errorStatus = node->ES;
+ uint32_t errorLevel = *errorStatus & 0xE0U;
+ uint32_t errStat = *errorStatus;
+ char buf[9];
+ char* levText = "Unknown level. ES: 0x";
+
+
+ if (*errorStatus != 0) {
+ if (errorLevel & canLEVEL_BUS_OFF) {
+ levText = "CAN bus is off. ES: 0x";
+ }
+ else if (errorLevel & canLEVEL_PASSIVE) {
+ levText = "CAN bus in passive mode. ES: 0x";
+ }
+ else if (errorLevel & canLEVEL_WARNING) {
+ levText = "CAN bus in passive mode. ES: 0x";
+ }
+ else if (errorLevel == canLEVEL_ACTIVE) {
+ if (isFinal) {
+ levText = "CAN is active. ES: 0x";
+ *errorStatus = 0;
+ }
+ else levText = NULL;
+ }
+ }
+ else {
+ if (isFinal) {
+ levText = "CAN no error. ES: 0x";
+ }
+ else levText = NULL;
+ }
+
+ if (levText == NULL) return errorLevel;
+
+ print((uint8_t*)str);
+ print((uint8_t*)levText);
+ i2str(buf, errStat, 1, 16);
+ print((uint8_t*)buf);
+ print((uint8_t*)"\r\n");
+
+ return errorLevel;
+}
+
+/**
+ * @brief Command for external CAN loopback testing.
+ *
+ * Command syntax: testcan src dest, where src and dest are numbers of CAN in range 1 - 3 and can not be equal.
+ *
+ * Command resets CAN bus and than sends 100 times message from source and destination.
+ * During the sending process number of tx errors, rx errors, tx timeouts and rx timeouts is being tracked.
+ *
+ * @param[in] cmd_io Pointer to IO stack
+ * @param[in] des Pointer to command descriptor
+ * @param[in] param Parameters of command
+ * @return 0 when OK or error code
*/
+int cmd_do_test_can_loopback(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
+{
+ uint32_t can[2];
+ canBASE_t *canBases[3] = {canREG1, canREG2, canREG3};
+ uint32_t canMailBoxes[3] = {canMESSAGE_BOX1, canMESSAGE_BOX2, canMESSAGE_BOX3};
+ char* token = NULL;
+ uint32_t txTimeOutCnt = 0;
+ uint32_t rxTimeOutCnt = 0;
+ uint32_t messagesTransmitted = 0;
+ uint32_t messagesReceived = 0;
+ uint32_t i;
+ uint8_t tx_data[8] = {'T', 'E', 'S', 'T', ' ', 'C', 'A', 'N'};
+ uint8_t rx_data[8] = {0, 0, 0, 0, 0, 0, 0, 0 };
+
+
+ dmmREG->PC4 = (1<<(13)); // set CAN_NSTB
+ vTaskDelay(50/portTICK_RATE_MS);
+ dmmREG->PC5 = (1<<(15)); // clr CAN_EN
+ vTaskDelay(50/portTICK_RATE_MS);
+ dmmREG->PC5 = (1<<(13)); // clr CAN_NSTB
+ vTaskDelay(50/portTICK_RATE_MS);
+ dmmREG->PC4 = (1<<(13)); // set CAN_NSTB
+ vTaskDelay(50/portTICK_RATE_MS);
+ dmmREG->PC4 = (1<<(15)); // set CAN_EN
+ vTaskDelay(50/portTICK_RATE_MS);
+
+ // Get can ID 1
+ if ((token = strtok(param[1], " ")) == NULL) {
+
+ print((uint8_t *)"ERROR: Parameter 1 expected.");
+ return 1;
+ }
+ if (EOF == sscanf(token, "%d", &can[0])){
+ print((uint8_t *)"ERROR: unsigned number expected as param 1!");
+ return 1;
+ }
+ // Get can ID 2
+ if ((token = strtok(NULL, " ")) == NULL) {
+ print((uint8_t *)"ERROR: Parameter 2 expected.");
+ return 1;
+ }
+ if (EOF == sscanf(token, "%d", &can[1])){
+ print((uint8_t *)"ERROR: unsigned number expected as param 2!");
+ return 1;
+ }
+ if ((token = strtok(NULL, " ")) != NULL) {
+ print((uint8_t *)"ERROR: More than 2 parameters detected!");
+ return 1;
+ }
+ if (can[0] == can[1]) {
+ print((uint8_t *)"ERROR: Destination equals source!);");
+ return 1;
+ }
+ if (can[0] < 1 | can[1] > 3) {
+ print((uint8_t *)"Parameter out of range <1;3>!");
+ return 1;
+ }
+ canSrc = canBases[can[0]-1];
+ canDst = canBases[can[1]-1];
+ canMsgBox = canMailBoxes[can[0]-1];
+ canMsgReceived = xSemaphoreCreateCounting(1, 0);
+ canMsgSent = xSemaphoreCreateCounting(1, 0);
+
+ print((uint8_t *)"\r\nTesting CAN loopback\r\n");
+ canREG1->CTL |= 1|(1<<9);
+ canREG2->CTL |= 1|(1<<9);
+ canREG3->CTL |= 1|(1<<9);
+ canRecError = 0;
+ canDst->CTL |= 1<<15; // Reset
+ while (canDst->CTL & (1<<15)) ; // Wait for reset
+ canSendError = 0;
+ canSrc->CTL |= 1<<15;
+ while (canSrc->CTL & (1<<15)) ;
+ canInit();
+ canDst->CTL |= 1<<9;
+ canSrc->CTL |= 1<<9;
+ vTaskDelay(50/portTICK_RATE_MS);
+
+ i = canSrc->ES; // Reset error flag
+ i = canDst->ES; // Reset error flag
+ canEnableErrorNotification(canDst);
+ canEnableErrorNotification(canSrc);
+
+ for (i = 0; i < 100; i++) { // Send 100 times the message
+ if (canCheckForError(canSrc, "TX", &canSendError, 0) != canLEVEL_ACTIVE) {
+ break;
+ }
+ canTransmit(canSrc, canMsgBox, tx_data);
+ if (xSemaphoreTake(canMsgSent, 100/portTICK_RATE_MS) == pdFALSE) {
+ txTimeOutCnt++;
+ }
+ else {
+ if (canCheckForError(canSrc, "TX", &canSendError, 0) & canLEVEL_BUS_OFF) {
+ break;
+ }
+ else {
+ messagesTransmitted++;
+ if (xSemaphoreTake(canMsgReceived, 100/portTICK_RATE_MS) == pdFALSE) {
+ rxTimeOutCnt++;
+ }
+ else {
+ if (canGetData(canDst, canMsgBox, rx_data))
+ messagesReceived++;
+
+ if (canCheckForError(canDst, "RX", &canRecError, 0) & canLEVEL_BUS_OFF) {
+ break;
+ }
+ }
+ }
+ }
+ }
+ print((uint8_t *)"CAN final error state:\r\n");
+ canCheckForError(canSrc, "TX", &canSendError, 1);
+ canCheckForError(canDst, "RX", &canRecError, 1);
+ print((uint8_t *)"Messages transmitted: ");
+ char errBuf[10];
+ i2str(errBuf, messagesTransmitted, 1, 10);
+ print((uint8_t *)errBuf);
+ print((uint8_t *)"/100\r\n");
+
+ print((uint8_t *)"Messages received: ");
+ i2str(errBuf, messagesReceived, 1, 10);
+ print((uint8_t *)errBuf);
+ print((uint8_t *)"/100\r\n");
+
+ print((uint8_t *)"TX timeouts: ");
+ i2str(errBuf, txTimeOutCnt, 1, 10);
+ print((uint8_t *)errBuf);
+ print((uint8_t *)"\r\n");
+
+ print((uint8_t *)"RX timeouts: ");
+ i2str(errBuf, rxTimeOutCnt, 1, 10);
+ print((uint8_t *)errBuf);
+ print((uint8_t *)"\r\n");
+
+ print((uint8_t *)"Src TX error counter: ");
+ uint32_t errCnt = canSrc->EERC & 0xFFU;
+ i2str(errBuf, errCnt, 1, 10);
+ print((uint8_t *)errBuf);
+ print((uint8_t *)"\r\n");
+
+ print((uint8_t *)"Src RX error counter: ");
+ errCnt = (canSrc->EERC & 0xFF00U) >> 8;
+ i2str(errBuf, errCnt, 1, 10);
+ print((uint8_t *)errBuf);
+ print((uint8_t *)"\r\n");
+
+ print((uint8_t *)"Dst TX error counter: ");
+ errCnt = canDst->EERC & 0xFFU;
+ i2str(errBuf, errCnt, 1, 10);
+ print((uint8_t *)errBuf);
+ print((uint8_t *)"\r\n");
+
+ print((uint8_t *)"Dst RX error counter: ");
+ errCnt = (canDst->EERC & 0xFF00U) >> 8;
+ i2str(errBuf, errCnt, 1, 10);
+ print((uint8_t *)errBuf);
+ print((uint8_t *)"\r\n");
+
+ canDisableErrorNotification(canDst);
+ canDisableErrorNotification(canSrc);
+ vSemaphoreDelete(canMsgReceived);
+ vSemaphoreDelete(canMsgSent);
+ return 0;
+}
+
+
+/** @brief command descriptor for test CAN loopback command */
+cmd_des_t const cmd_des_test_can_loopback={
+ 0, 0,
+ "testcan","testcan src<1;3> dest<1;3> Test CAN loopback between src and dest.",
+ cmd_do_test_can_loopback, (void *)&cmd_list_can
+};
+cmd_des_t const *cmd_list_can[]={
+ &cmd_des_test_can_loopback,
+ NULL
+};
* cmd_dac.c
*
* Created on: 28.2.2013
- * Author: michal
+ * Author: Michal Horn
+ * Commands for control DAC port. Setting voltage, getting voltage, Turn pins on and off.
*/
+#include "cmd_dac.h"
+#include "cmdio_tisci.h"
+#include "drv_dac.h"
+#include "utils.h"
+/**
+ * @brief Command for setting DAC pin on/off or getting state of DAC pin.
+ *
+ * Command syntax: dacpinon##:state - ## specifies number of the DAC pin in range 1-4
+ * - state 1 resp. 0 sets pin number ## to on resp. off
+ * dacpinon##? - Get state of pin number ##
+ *
+ * @param[in] cmd_io Pointer to IO stack
+ * @param[in] des Pointer to command descriptor
+ * @param[in] param Parameters of command
+ * @return 0 when OK or error code
+ */
+int cmd_do_dac_pin_on(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
+ char *p;
+ int opchar;
+ int pin;
+ int val;
+ uint32_t status;
+
+ if((opchar=cmd_opchar_check(cmd_io,des,param))<0) return opchar;
+ p=param[1];
+ if(si_long(&p,(long*)&pin,0)<0) return -CMDERR_BADPAR;
+ pin--; // Highlevel command has pin number mapped according the board scheme, this switches to internal representation
+ if (pin > DAC_PIN_NUM || pin < 0) return -CMDERR_BADPAR;
+ if(opchar=='?') {
+ status = dac_pin_is_on(pin);
+ return cmd_opchar_replong(cmd_io, param, status, 0, 16);
+ }
+ else {
+ p=param[3];
+ if(si_long(&p,(long*)&val,0)<0) return -CMDERR_BADPAR;
+ if (val == 0) dac_set_pin_off(pin);
+ else if (val == 1) dac_set_pin_on(pin);
+ else return -CMDERR_BADPAR;
+ dac_spi_transfer(pin);
+ status = dac_pin_is_on(pin);
+ return cmd_opchar_replong(cmd_io, param, status, 0, 16);
+ }
+}
+
+/**
+ * @brief Command for getting state and voltage of DAC port in human readable form.
+ *
+ * Command syntax: dacstat
+ *
+ * Prints table of pins and their state and voltage seted by according command.
+ *
+ * @param[in] cmd_io Pointer to IO stack
+ * @param[in] des Pointer to command descriptor
+ * @param[in] param Parameters of command
+ * @return always 0
+ */
+int cmd_do_dac_stat(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
+ char buf[6];
+ int i;
+ char* dac_on_off[2] = {":\tOFF\t", ":\tON\t"};
+
+ for (i = 0; i < DAC_PIN_NUM; i++) {
+ print((uint8_t*)"DAC");
+ i2str(buf, i+1, 0, 10);
+ print((uint8_t*)buf);
+ print((uint8_t*)dac_on_off[dac_pin_is_on(i)]);
+ i2str(buf, dac_get_pin_voltage(i), 0, 10);
+ print((uint8_t*)buf);
+ print((uint8_t*)"\r\n");
+ }
+ return 0;
+}
+
+/**
+ * @brief Command for setting and getting voltage on selected DAC pin.
+ *
+ * Command syntax: dacpinval##:V - ## specifies number of the DAC pin in range 1-4
+ * - V specifies voltage in mV
+ * dacpinval##? - Gets voltage on selected pin ## in mV.
+ *
+ *
+ * @param[in] cmd_io Pointer to IO stack
+ * @param[in] des Pointer to command descriptor
+ * @param[in] param Parameters of command
+ * @return 0 when OK or error code
+ */
+int cmd_do_dac_pin_value(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
+ char *p;
+ int opchar;
+ int pin;
+ int voltage;
+
+ if((opchar=cmd_opchar_check(cmd_io,des,param))<0) return opchar;
+ p=param[1];
+ if(si_long(&p,(long*)&pin,0)<0) return -CMDERR_BADPAR;
+ pin--; // Highlevel command has pin number mapped according the board scheme, this switches to internal representation
+ if (pin > DAC_PIN_NUM || pin < 0) return -CMDERR_BADPAR;
+ if(opchar=='?') {
+ voltage = dac_get_pin_voltage(pin);
+ return cmd_opchar_replong(cmd_io, param, voltage, 0, 10);
+ }
+ else {
+ p=param[3];
+ if(si_long(&p,(long*)&voltage,10)<0) return -CMDERR_BADPAR;
+ dac_set_pin_voltage(pin, voltage);
+ dac_spi_transfer(pin);
+ voltage = dac_get_pin_voltage(pin);
+ return cmd_opchar_replong(cmd_io, param, voltage, 0, 10);
+ }
+}
+
+/** Descriptor of command for dac state set/get */
+cmd_des_t const cmd_des_dac_on={
+ 0, CDESM_OPCHR|CDESM_RW,
+ "dacpinon#","\tdacpinonX:Y - if Y=1, turns DACX ON, if Y=0, turns DACX OFF\r\n\t\tdacpinonX? - reads status of DACX (1=ON, 0=OFF)\r\n\t\tX = <1;4>",
+ cmd_do_dac_pin_on, (void *)&cmd_list_dac
+};
+
+/** Descriptor of command for dac port status setter */
+cmd_des_t const cmd_des_dac_stat={
+ 0, 0,
+ "dacstat","\tdacstat - Reads status of each DAC",
+ cmd_do_dac_stat, (void *)&cmd_list_dac
+};
+
+/** Descriptor of command for dac pin voltage set/get */
+cmd_des_t const cmd_des_dac_val={
+ 0, CDESM_OPCHR|CDESM_RW,
+ "dacpinval#","\tdacpinvalX:Y - DACX <- Y mV\r\n\t\tdacpinvalX? - Get DACX voltage in mV\r\n\t\tX = <1;4>",
+ cmd_do_dac_pin_value, (void *)&cmd_list_dac
+};
+
+/** List of commands for dac, defined as external */
+cmd_des_t const *cmd_list_dac[]={
+ &cmd_des_dac_on,
+ &cmd_des_dac_stat,
+ &cmd_des_dac_val,
+ NULL
+};
* cmd_din.c
*
* Created on: 28.2.2013
- * Author: michal
+ * Author: Michal Horn
+ *
+ * Commands for DIN port control.
+ * - Setting pins to tri-state or not
+ * - Enabling interrupt and wake-up function on pins
+ * - Reseting DIN
+ * - Switching status on DIN
+ * - Setting programable pins as switch-to-ground and switch-to-battery
+ * - Getting port state as a number
+ * - Getting port state in human readable form
+ */
+
+#include "cmd_din.h"
+#include "cmdio_tisci.h"
+#include "utils.h"
+#include "port_def.h"
+#include "spi_resp_transl.h"
+#include "drv_din.h"
+
+/** @brief Set pins on DIN port to be active or tri-state.
+ *
+ * Function expects two hexa numbers after ':' in brackets, ie command:(BB,AA).
+ * First number sets state of pins SG0 - SG13, second number sets state of pins SP0 - SP7.
+ * Bits are assigned from the left to the right pins SP0, SP1...SP7 and SG0, SG1..SG13.
+ * 1 set the pin to be tri-state, 0 set the pin to be active.
+ *
+ * Function creates, sends two SPI commands. One is for SP and the second one is for SG pins.
+ * Command receive response from the second command.
+ *
+ * @param[in] cmd_io Pointer to IO stack
+ * @param[in] des Pointer to command descriptor
+ * @param[in] param Parameters of command
+ * @return 0 when OK or error code
+ */
+int cmd_do_din_st_wr(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
+ char *p;
+ int opchar;
+ int i;
+ uint32_t spi_resp;
+ uint32_t values[MAX_PARAM_VALUES_NUM];
+
+ if((opchar=cmd_opchar_check(cmd_io,des,param))<0) return opchar;
+
+ if(opchar==':'){
+ p=param[3];
+ si_skspace(&p);
+ i = read_arg(&p, values, MAX_PARAM_VALUES_NUM, 16);
+ if (i != 2)
+ return -CMDERR_BADPAR;
+
+ din_set_stat(values[1], values[0]);
+ spi_resp=din_spi_transfer();
+ return cmd_opchar_replong(cmd_io, param, spi_resp, 0, 16);
+ }
+ else return -CMDERR_OPCHAR;
+}
+
+/** @brief Enables or disables wake-up and interrupt function for pins on DIN port.
+ *
+ * Function expects two hexa numbers after ':' in brackets, ie command:(BB,AA).
+ * First number sets pins SG0 - SG13, second number sets pins SP0 - SP7.
+ * Bits are assigned from the left to the right to pins SP0, SP1...SP7 and SG0, SG1..SG13.
+ * 1 - enable interrupt and wake-up function on the pin, 0 - disable those function on the pin.
+ *
+ * Function creates, sends two SPI commands. One is for SP and the second one is for SG pins.
+ * Command receive response from the second command.
+ *
+ * @param[in] cmd_io Pointer to IO stack
+ * @param[in] des Pointer to command descriptor
+ * @param[in] param Parameters of command
+ * @return 0 when OK or error code
*/
+int cmd_do_din_int_wr(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
+ char *p;
+ int opchar;
+ int i;
+ uint32_t spi_resp;
+ uint32_t values[MAX_PARAM_VALUES_NUM];
+
+ if((opchar=cmd_opchar_check(cmd_io,des,param))<0) return opchar;
+
+ if(opchar==':'){
+ p=param[3];
+ si_skspace(&p);
+ i = read_arg(&p, values, MAX_PARAM_VALUES_NUM, 16);
+ if (i != 2)
+ return -CMDERR_BADPAR;
+
+ din_set_int(values[1], values[0]);
+ spi_resp=din_spi_transfer();
+ return cmd_opchar_replong(cmd_io, param, spi_resp, 0, 16);
+ }
+ else return -CMDERR_OPCHAR;
+}
+
+/** @brief Send reset command to DIN
+ *
+ * Function creates, sends SPI command that resets chip MC33972 and receive response.
+ *
+ * @param[in] cmd_io Pointer to IO stack
+ * @param[in] des Pointer to command descriptor
+ * @param[in] param Parameters of command
+ * @return 0 when OK or error code
+ */
+int cmd_do_din_reset(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
+ char b[32];
+ din_reset();
+ uint32_t spi_resp = din_spi_transfer();
+ print((uint8_t *)"dinreset: ");
+ i2str(b, spi_resp, 0, 16);
+ print((uint8_t *)b);
+ return 0;
+}
+
+/** @brief Send switch status command to DIN
+ *
+ * Function creates, sends SPI command that poll new switches state and receive response.
+ *
+ * @param[in] cmd_io Pointer to IO stack
+ * @param[in] des Pointer to command descriptor
+ * @param[in] param Parameters of command
+ * @return 0 when OK or error code
+ */
+int cmd_do_din_switch_st(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
+ char b[32];
+ din_switch_st();
+ uint32_t spi_resp = din_spi_transfer();
+ print((uint8_t *)"dinswst: ");
+ i2str(b, spi_resp, 0, 16);
+ print((uint8_t *)b);
+ return 0;
+}
+
+/** @brief Set programable pins as switch-to-battery or switch-to-ground
+ *
+ * Function expects one hexa number after ':' in brackets, ie command:(AA).
+ * The number sets pins SP0 - SP7.
+ * Bits are assigned from the left to the right to pins SP0, SP1...SP7.
+ * 1 - set pin as switch-to-battery, 0 - set pin as switch-to-ground.
+ *
+ * Function creates, sends SPI command and receive response.
+ *
+ * @param[in] cmd_io Pointer to IO stack
+ * @param[in] des Pointer to command descriptor
+ * @param[in] param Parameters of command
+ * @return 0 when OK or error code
+ */
+int cmd_do_din_pr_wr(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
+ char *p;
+ int opchar;
+ int i;
+ uint32_t spi_resp;
+ uint32_t values[MAX_PARAM_VALUES_NUM];
+
+ if((opchar=cmd_opchar_check(cmd_io,des,param))<0) return opchar;
+
+ if(opchar==':'){
+ p=param[3];
+ si_skspace(&p);
+ i = read_arg(&p, values, MAX_PARAM_VALUES_NUM, 16);
+ if (i != 1)
+ return -CMDERR_BADPAR;
+
+ din_set_pr(values[0]);
+ spi_resp=din_spi_transfer();
+ return cmd_opchar_replong(cmd_io, param, spi_resp, 0, 16);
+ }
+ else return -CMDERR_OPCHAR;
+}
+
+/** @brief Get state of DIN port as 16-b word
+ *
+ * Function creates, sends SPI command that poll new switches state,
+ * receives response and filters just the pins, that are connected to the MC33972.
+ *
+ * @param[in] cmd_io Pointer to IO stack
+ * @param[in] des Pointer to command descriptor
+ * @param[in] param Parameters of command
+ * @return 0 when OK or error code
+ */
+int cmd_do_din_val_word(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
+ int opchar;
+ uint32_t spi_resp;
+
+ if((opchar=cmd_opchar_check(cmd_io,des,param))<0) return opchar;
+
+ if(opchar=='?') {
+ din_switch_st();
+ din_spi_transfer();
+ spi_resp=din_get_val_word();
+ return cmd_opchar_replong(cmd_io, param, spi_resp, 0, 16);
+ }
+ else return -CMDERR_OPCHAR;
+}
+
+/** @brief Get state of DIN port in human readable form
+ *
+ * Function creates, sends SPI command that poll new switches state,
+ * receives response and translates it to human readable form.
+ *
+ * @param[in] cmd_io Pointer to IO stack
+ * @param[in] des Pointer to command descriptor
+ * @param[in] param Parameters of command
+ * @return 0 when OK or error code
+ */
+int cmd_do_din_status(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
+ uint32_t numCmdDesc;
+ int i;
+ char buf[16];
+ uint32_t numFieldDesc;
+
+ din_switch_st();
+ uint32_t din_spi_resp = din_spi_transfer();
+
+ spitr_reg_translate_table_t translatedData;
+
+ const spitr_cmd_map_t* cmdDesc = get_spi_cmd_map(PORT_NAME_DINSPI, -1, &numCmdDesc);
+ if(cmdDesc == NULL) return -CMDERR_BADREG;
+
+ const spitr_field_desc_t* fieldDescs = get_spi_field_desc(cmdDesc, numCmdDesc, din_spi_get_cmd(), &numFieldDesc);
+ if (fieldDescs == NULL)
+ return -CMDERR_BADPAR;
+ uint32_t lsbResponse = 0 | ((din_spi_resp & 0xFF) << 16 ) | ((din_spi_resp & 0xFF0000) >> 16) | (din_spi_resp & 0xFF00);
+ spitr_fill_tr_table(fieldDescs, numFieldDesc, lsbResponse, &translatedData);
+
+ for (i = 0; i < translatedData.num_rows; i++) {
+ print((uint8_t *)translatedData.row[i].field_name);
+ print((uint8_t *)": 0x");
+ i2str(buf, translatedData.row[i].value, 0, 16);
+ print((uint8_t *)buf);
+ print((uint8_t *)"\r\n");
+ }
+ return cmd_opchar_replong(cmd_io, param, din_spi_resp, 0, 16);
+}
+
+
+
+/** Command descriptor for din state command */
+cmd_des_t const cmd_des_din_st_word={
+ 0, CDESM_OPCHR|CDESM_WR,
+ "dinportst","\tdinportst:(wrsg,wrsp) - writes word wr (8b) into din sg and sp. 1 - tri-state, 0 - active.",
+ cmd_do_din_st_wr, (void *)&cmd_list_din
+};
+
+/** Command descriptor for din switch-to-ground/battery command */
+cmd_des_t const cmd_des_din_pr_word={
+ 0, CDESM_OPCHR|CDESM_WR,
+ "dinportpr","\tdinportpr:(wr) - writes word wr (8b) into din. 1 - switch-to-bat, 0 - switch-to-gnd.",
+ cmd_do_din_pr_wr, (void *)&cmd_list_din
+};
+
+/** Command descriptor for din enable interrupts command */
+cmd_des_t const cmd_des_din_int_word={
+ 0, CDESM_OPCHR|CDESM_WR,
+ "dinportint","\tdinportint:(wrsg, wrsp) - writes word wr (16b) into din sg and sp. 1 - enable interrupt, 0 - disable interrupt.",
+ cmd_do_din_int_wr, (void *)&cmd_list_din
+};
+
+/** Command descriptor for din reset command */
+cmd_des_t const cmd_des_din_rst={
+ 0, 0,
+ "dinreset","\tdinreset - send reset command to DIN",
+ cmd_do_din_reset, (void *)&cmd_list_din
+};
+
+/** Command descriptor for din switch state command */
+cmd_des_t const cmd_des_din_sw_st={
+ 0, 0,
+ "dinswst","\tdinswst - Send switch status to DIN",
+ cmd_do_din_switch_st, (void *)&cmd_list_din
+};
+
+/** Command descriptor for din get value command */
+cmd_des_t const cmd_des_din_val_word={
+ 0, CDESM_OPCHR|CDESM_RD,
+ "dinportval","\tdinportval? - reads values from DIN port as 16b word",
+ cmd_do_din_val_word, (void *)&cmd_list_din
+};
+/** Command descriptor for din get state command */
+cmd_des_t const cmd_des_din_stat={
+ 0, 0,
+ "dinstat","\tdinstat - get DIN status in human readable form",
+ cmd_do_din_status, (void *)&cmd_list_din
+};
+/** List of commands for din, defined as external */
+cmd_des_t const *cmd_list_din[]={
+ &cmd_des_din_st_word,
+ &cmd_des_din_pr_word,
+ &cmd_des_din_int_word,
+ &cmd_des_din_rst,
+ &cmd_des_din_sw_st,
+ &cmd_des_din_val_word,
+ &cmd_des_din_stat,
+ NULL
+};
+#include "cmd_emac.h"
+
#include "sys_common.h"
#include "system.h"
#include "string.h"
#include "cmdio_tisci.h"
-#include "emac.h"
-#include "mdio.h"
+#include "ti_drv_emac.h"
+#include "ti_drv_mdio.h"
#include "hw_mdio.h"
#include "hw_emac.h"
-#include "emac_test.h"
+#include "cmd_emac.h"
#include "phy.h"
-#include "dmm.h"
+#include "ti_drv_dmm.h"
unsigned int emacCtrlBase = EMAC_CTRL_BASE;
unsigned int emacBase = EMAC_BASE;
return 0;
}
+
+cmd_des_t const cmd_des_test_ethernet={
+ 0, 0,
+ "ethernet", "Try to send few ethernet frames",
+ emac_test, (void *)&cmd_list_emac
+};
+
+cmd_des_t const *cmd_list_emac[]={
+ &cmd_des_test_ethernet,
+ NULL
+};
* cmd_fray.c
*
* Created on: 28.2.2013
- * Author: michal
+ * Author: Michal Horn
+ *
+ * Commands for control FlexRay
+ * - Getting status of FlexRay from chips on SPI
+ * - Sending test chunk on FRAY
+ * - Receiving test chunk on FRAY
+ */
+
+#include "cmd_fray.h"
+#include "cmdio_tisci.h"
+#include "drv_fray.h"
+#include "Fr.h"
+#include "spi_resp_transl.h"
+#include "FlexRay.h"
+
+FRAY_ST e_FRAY0_ST;
+
+
+/**
+ * @brief Get FlexRay status in human readable form
+ *
+ * Command sends some data on SPI (data do not matters, chips are read only) and retreives a response.
+ * The response is translated and displayed as readable text.
+ *
+ * @param[in] cmd_io Pointer to IO stack
+ * @param[in] des Pointer to command descriptor
+ * @param[in] param Parameters of command
+ * @return 0 when OK or error code
*/
+int cmd_do_fray_status(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
+ char *p;
+ int pin;
+ uint32_t numCmdDesc;
+ int i;
+ char buf[16];
+ uint32_t numFieldDesc;
+
+ p=param[1];
+ if(si_long(&p,(long*)&pin,0)<0) return -CMDERR_BADPAR;
+ pin--; // Highlevel command has pin number mapped according the board scheme, this switches to internal representation
+ if (pin > FRAY_NUM_PORTS || pin < 0) return -CMDERR_BADPAR;
+
+ if (fray_spi_transfer(pin) != 0) return -CMDERR_BADDIO;
+
+ spitr_reg_translate_table_t translatedData;
+ const spitr_cmd_map_t* cmdDesc = get_spi_cmd_map(PORT_NAME_FRAY1, -1, &numCmdDesc);
+ if(cmdDesc == NULL) return -CMDERR_BADREG;
+
+ const spitr_field_desc_t* fieldDescs = get_spi_field_desc(cmdDesc, numCmdDesc, fray_spi_get_cmd(pin), &numFieldDesc);
+ if (fieldDescs == NULL)
+ return -CMDERR_BADPAR;
+ uint32_t fr_spi_response = fray_spi_response(pin);
+ uint32_t lsbResponse = 0 | ((fr_spi_response & 0xFF) << 8) | ((fr_spi_response & 0xFF00) >> 8);
+ spitr_fill_tr_table(fieldDescs, numFieldDesc, lsbResponse, &translatedData);
+ for (i = 0; i < translatedData.num_rows; i++) {
+ print((uint8_t *)translatedData.row[i].field_name);
+ print((uint8_t *)": 0x");
+ i2str(buf, translatedData.row[i].value, 0, 16);
+ print((uint8_t *)buf);
+ print((uint8_t *)"\r\n");
+ }
+ return 0;
+}
+
+/**
+ * @brief Start sending and receiving data on as node A
+ *
+ * Command initializes FRAY1 node A and start sending and receiving data forever.
+ * There is command for node B, which should be launched on another device.
+ *
+ * @param[in] cmd_io Pointer to IO stack
+ * @param[in] des Pointer to command descriptor
+ * @param[in] param Parameters of command
+ * @return 0 when OK or error code
+ */
+int cmd_do_test_frayA(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
+{
+ print((uint8_t *)"Test fray 1, node A\r\n");
+ configure_initialize_node_a(FRAY1);
+ print((uint8_t *)"Initialized.\r\n");
+ Fr_StartCommunication(FRAY1);
+ print((uint8_t *)"Communication started.\r\n");
+ while(1)
+ {
+ transmit_check_node_a(FRAY1);
+ }
+}
+
+/**
+ * @brief Start sending and receiving data on as node B
+ *
+ * Command initializes FRAY1 node B and start sending and receiving data forever.
+ * There is command for node A, which should be launched on another device.
+ *
+ * @param[in] cmd_io Pointer to IO stack
+ * @param[in] des Pointer to command descriptor
+ * @param[in] param Parameters of command
+ * @return 0 when OK or error code
+ */
+int cmd_do_test_frayB(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
+{
+ print((uint8_t *)"Test fray 1, node B\r\n");
+ configure_initialize_node_b(FRAY1);
+ print((uint8_t *)"Initialized.\r\n");
+ Fr_StartCommunication(FRAY1);
+ print((uint8_t *)"Communication started.\r\n");
+
+ while(1)
+ {
+ transmit_check_node_b(FRAY1);
+ }
+}
+
+/** Command descriptor for FlexRay status command */
+cmd_des_t const cmd_des_fray_stat={
+ 0, 0,
+ "fraystat#","\tget FRAYX status in human readable form",
+ cmd_do_fray_status, (void *)&cmd_list_fray
+};
+
+/** Command descriptor for FlexRay 1 test node A */
+cmd_des_t const cmd_des_test_fray_a={
+ 0, 0,
+ "testfrayA","Run FlexRay test as A node",
+ cmd_do_test_frayA, (void *)&cmd_list_fray
+};
+/** Command descriptor for FlexRay 1 test node B */
+cmd_des_t const cmd_des_test_fray_b={
+ 0, 0,
+ "testfrayB","Run FlexRay test as B node",
+ cmd_do_test_frayB, (void *)&cmd_list_fray
+};
+/** List of commands for din, defined as external */
+cmd_des_t const *cmd_list_fray[]={
+ &cmd_des_fray_stat,
+ &cmd_des_test_fray_a,
+ &cmd_des_test_fray_b,
+ NULL
+};
* cmd_hbr.c
*
* Created on: 28.2.2013
- * Author: michal
+ * Author: Michal Horn
+ *
+ * Commands for controling H-bridge
+ * - Start periodic watchdog reset
+ * - Set PWM
+ * - Start PWM
+ * - Stop PWM
+ */
+
+#include "cmd_hbr.h"
+#include "cmdio_tisci.h"
+#include "utils.h"
+#include "drv_hbridge.h"
+
+
+/**
+ * @brief Start periodic HBR watchdog reset.
+ *
+ * Command syntax: hbrwdg
+ *
+ * Command, if launched for the first time, creates new thread, which
+ * is sending watchdog reset command to H-bridge each 10ms.
+ *
+ * @param[in] cmd_io Pointer to IO stack
+ * @param[in] des Pointer to command descriptor
+ * @param[in] param Parameters of command
+ * @return always 0
+ */
+int cmd_do_hbr_wdg(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
+ int ret = hbr_spi_wdg_transfer();
+ char buf[16];
+ i2str(buf, ret, 0, 16);
+ print((uint8_t *)"SPI! RX(");
+ print((uint8_t *)buf);
+ print((uint8_t *)")");
+ return 0;
+}
+
+/**
+ * @brief Set or get actual pwm parameters
+ *
+ * Command syntax: hbrpwm:(p,d) - set p as a period in us and D as duty cycle in % of the period.
+ * hbrpwm? - Get actual PWM parameters, period in us and duty cycle in % of the period.
+ *
+ * @param[in] cmd_io Pointer to IO stack
+ * @param[in] des Pointer to command descriptor
+ * @param[in] param Parameters of command
+ * @return 0 when OK or error code
+ */
+int cmd_do_hbr_pwm(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
+{
+ char *p;
+ int opchar;
+ int i;
+ uint32_t values[MAX_PARAM_VALUES_NUM];
+ char buf[16];
+
+ if((opchar=cmd_opchar_check(cmd_io,des,param))<0) return opchar;
+
+ if(opchar==':'){
+ p=param[3];
+ si_skspace(&p);
+ i = read_arg(&p, values, MAX_PARAM_VALUES_NUM, 10);
+ if (i < 0)
+ return i;
+ if (i != 2)
+ return -CMDERR_BADPAR;
+ if (values[0] < 1 || values[1] > 100) return -CMDERR_BADPAR;
+ hbr_pwm_set_signal((double)values[0], values[1]);
+ return 0;
+ }
+ else{
+ double period = hbr_pwm_get_period();
+ uint32_t duty = hbr_pwm_get_duty();
+
+ print((uint8_t *)"hbr_pwm_period: ");
+ i2str(buf, period, 0, 10);
+ print((uint8_t *)buf);
+ print((uint8_t *)"\r\nhbr_pwm_duty: ");
+ i2str(buf, duty, 0, 10);
+ print((uint8_t *)buf);
+ print((uint8_t *)"%");
+ return 0;
+ }
+}
+
+/**
+ * @brief Start PWM, if it was previously set by hbrpwm command
+ *
+ * Command syntax: hbrpwmstart
+ *
+ * @param[in] cmd_io Pointer to IO stack
+ * @param[in] des Pointer to command descriptor
+ * @param[in] param Parameters of command
+ * @return 0 when OK or error code
*/
+int cmd_do_hbr_pwm_start(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
+{
+ int ret = hbr_pwm_start();
+ if (ret == -1) {
+ print((uint8_t*)"PWM was not initialized.\r\n");
+ return -CMDERR_BADCFG;
+ }
+ else {
+ return 0;
+ }
+}
+
+/**
+ * @brief Stop PWM
+ *
+ * Command syntax: hbrpwmstop
+ *
+ * @param[in] cmd_io Pointer to IO stack
+ * @param[in] des Pointer to command descriptor
+ * @param[in] param Parameters of command
+ * @return 0 when OK or error code
+ */
+int cmd_do_hbr_pwm_stop(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
+{
+ hbr_pwm_stop();
+ return 0;
+}
+
+/** Command descriptor for HBR reset watchdog command */
+cmd_des_t const cmd_des_hbr_wdg={
+ 0, 0,
+ "hbrwdg","Send repeated HBR WDG reset command",
+ cmd_do_hbr_wdg, (void *)&cmd_list_hbr
+};
+
+/** Command descriptor for HBR set PWM command */
+cmd_des_t const cmd_des_hbr_pwm={
+ 0, CDESM_OPCHR|CDESM_RW,
+ "hbrpwm*","\t- hbrpwm:(period,duty) set pwm period in us and duty in % of period\r\n\t\thbrpwm? read period in us and duty in % of period from hbrpwm.",
+ cmd_do_hbr_pwm, (void *)&cmd_list_hbr
+};
+
+/** Command descriptor for PWM start command */
+cmd_des_t const cmd_des_hbr_pwm_start={
+ 0, 0,
+ "hbrpwmstart","\t- hbrpwmstart - Start generating of pwm signal on HBR",
+ cmd_do_hbr_pwm_start, (void *)&cmd_list_hbr
+};
+/** Command descriptor for PWM stop command */
+cmd_des_t const cmd_des_hbr_pwm_stop={
+ 0, 0,
+ "hbrpwmstop","\t- hbrpwmstop - Stop generating of pwm signal on HBR",
+ cmd_do_hbr_pwm_stop, (void *)&cmd_list_hbr
+};
+/** List of commands for hbr, defined as external */
+cmd_des_t const *cmd_list_hbr[]={
+ &cmd_des_hbr_wdg,
+ &cmd_des_hbr_pwm,
+ &cmd_des_hbr_pwm_start,
+ &cmd_des_hbr_pwm_stop,
+ NULL
+};
* cmd_hout.c
*
* Created on: 28.2.2013
- * Author: michal
+ * Author: Michal Horn
*/
+#include "cmd_hout.h"
+#include "cmdio_tisci.h"
+#include "port_def.h"
+#include "utils.h"
+#include "hal_gpio_tms570.h"
+#include "drv_hout.h"
+
+/**
+ * @brief Reads values from HOUT_IFBK pins (subset of ADC)
+ *
+ * Command syntax: readhifbk
+ *
+ * @param[in] cmd_io Pointer to IO stack
+ * @param[in] des Pointer to command descriptor
+ * @param[in] param Parameters of command
+ * @return 0 when OK or error code
+ */
+int cmd_do_read_hout_ifbk_values(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
+{
+ char numBuf[32]; // Buffer used for i2str conversion
+ uint32_t i; // Cycle control variable
+ port_desc_t* desc;
+ uint32_t values[PORT_HOUTIFBK_CHANNEL_NUM*2];
+ int ret;
+
+ desc = port_get_dsc(PORT_NAME_HOUTIFBK, -1);
+
+ ret = desc->port_getfnc_ptr(desc->config, PORT_HOUTIFBK_CHANNEL_NUM, values);
+ if (ret < 0)
+ return ret;
+
+ print((uint8_t *)"\r\nHOUT_IFBK: values: ");
+ /* conversion results : */
+ for (i = 0; i < PORT_HOUTIFBK_CHANNEL_NUM; i++) {
+ print((uint8_t *)"\r\nChannel: ");
+ i2str(numBuf, values[i+PORT_HOUTIFBK_CHANNEL_NUM], 1, 10);
+ print((uint8_t *)numBuf);
+ print((uint8_t *)"\tvalue: ");
+ i2str(numBuf, values[i], 1, 10);
+ print((uint8_t *)numBuf);
+ print((uint8_t *)" 0x");
+ i2str(numBuf, values[i], 1, 16);
+ print((uint8_t *)numBuf);
+ }
+ return 0;
+}
+
+//TODO: Repair this function - HOUT_DIAG id periodicaly shorted to ground and each 2ms
+/**
+ * @brief Runs test of HOUT. Test, weather HOUT is in fault state, which means that HOUT_DIAG is shorted to ground
+ *
+ * Command syntax: houtfail
+ *
+ * @param[in] cmd_io Pointer to IO stack
+ * @param[in] des Pointer to command descriptor
+ * @param[in] param Parameters of command
+ * @return 0 when OK or error code
+ */
+int cmd_do_test_hout_fault(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
+{
+ print((uint8_t *)"Testing fault state of HOUT port:");
+ uint8_t i;
+ uint32_t values[] = {1, 1, 1, 1, 1, 1};
+
+ port_desc_t* inDesc = port_get_dsc(PORT_NAME_HOUTIN, -1);
+ port_desc_t* diagDesc = port_get_dsc(PORT_NAME_HOUTDIAG, -1);
+
+ inDesc->port_setfnc_ptr(inDesc->config, inDesc->numValues, values);
+ vTaskDelay(100/portTICK_RATE_MS);
+ for (i = 0; i < inDesc->numValues; i++) {
+ if (hal_gpio_get_value(diagDesc->config[i]) == values[i]) {
+ print((uint8_t *)"\r\nOK");
+ }
+ else {
+ print((uint8_t *)"\r\nFAIL");
+ }
+ values[i] = 0;
+ }
+ inDesc->port_setfnc_ptr(inDesc->config, inDesc->numValues, values);
+ return 0;
+}
+
+/**
+ * @brief Set or get actual pwm parameters
+ *
+ * Command syntax: houtpwm:(p,d) - set p as a period in us and D as duty cycle in % of the period.
+ * houtpwm? - Get actual PWM parameters, period in us and duty cycle in % of the period.
+ *
+ * @param[in] cmd_io Pointer to IO stack
+ * @param[in] des Pointer to command descriptor
+ * @param[in] param Parameters of command
+ * @return 0 when OK or error code
+ */
+int cmd_do_hout_pwm(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
+{
+ char *p;
+ int opchar;
+ int i;
+ uint32_t values[MAX_PARAM_VALUES_NUM];
+ char buf[16];
+ int pin;
+
+ if((opchar=cmd_opchar_check(cmd_io,des,param))<0) return opchar;
+
+ p=param[1];
+ if(si_long(&p,(long*)&pin,0)<0) return -CMDERR_BADPAR;
+ pin--;
+ if (pin < 0 || pin > 5) return -CMDERR_BADPAR;
+
+ if(opchar==':'){
+ p=param[3];
+ si_skspace(&p);
+ i = read_arg(&p, values, MAX_PARAM_VALUES_NUM, 10);
+ if (i < 0)
+ return i;
+ if (i != 2)
+ return -CMDERR_BADPAR;
+ if (values[0] < 1 || values[1] > 100) return -CMDERR_BADPAR;
+ hout_pwm_set_signal(pin, (double)values[0], values[1]);
+ return 0;
+ }
+ else{
+ double period = hout_pwm_get_period(pin);
+ uint32_t duty = hout_pwm_get_duty(pin);
+
+ print((uint8_t *)"hout");
+ i2str(buf, pin, 0, 10);
+ print((uint8_t *)"_pwm_period: ");
+ i2str(buf, period, 0, 10);
+ print((uint8_t *)buf);
+ print((uint8_t *)"\r\nhout");
+ i2str(buf, pin, 0, 10);
+ print((uint8_t *)"_pwm_duty: ");
+ i2str(buf, duty, 0, 10);
+ print((uint8_t *)buf);
+ print((uint8_t *)"%");
+ return 0;
+ }
+}
+
+/**
+ * @brief Start PWM, if it was previously set by houtpwm command
+ *
+ * Command syntax: houtpwmstart
+ *
+ * @param[in] cmd_io Pointer to IO stack
+ * @param[in] des Pointer to command descriptor
+ * @param[in] param Parameters of command
+ * @return 0 when OK or error code
+ */
+int cmd_do_hout_pwm_start(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
+{
+ char* p;
+ int pin;
+
+ p=param[1];
+ if(si_long(&p,(long*)&pin,0)<0) return -CMDERR_BADPAR;
+ pin--;
+ if (pin < 0 || pin > 5) return -CMDERR_BADPAR;
+ int ret = hout_pwm_start(pin);
+ if (ret == -1) {
+ print((uint8_t*)"PWM was not initialized.\r\n");
+ return -CMDERR_BADCFG;
+ }
+ else {
+ return 0;
+ }
+}
+
+/**
+ * @brief Stop PWM
+ *
+ * Command syntax: houtpwmstop
+ *
+ * @param[in] cmd_io Pointer to IO stack
+ * @param[in] des Pointer to command descriptor
+ * @param[in] param Parameters of command
+ * @return 0 when OK or error code
+ */
+int cmd_do_hout_pwm_stop(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
+{
+ char* p;
+ int pin;
+
+ p=param[1];
+ if(si_long(&p,(long*)&pin,0)<0) return -CMDERR_BADPAR;
+ pin--;
+ if (pin < 0 || pin > 5) return -CMDERR_BADPAR;
+ hout_pwm_stop(pin);
+ return 0;
+}
+/** Command descriptor for test hout fault state command */
+cmd_des_t const cmd_des_test_hout_fail = {
+ 0, 0,
+ "houtfail","Test if some HOUT port is in fault state",
+ cmd_do_test_hout_fault, (void *)&cmd_list_hout
+};
+
+/** Command descriptor for hout read IFBK command */
+cmd_des_t const cmd_des_read_hifbk={
+ 0, 0,
+ "readhifbk","Reads values from HOUT IFBK",
+ cmd_do_read_hout_ifbk_values, (void *)&cmd_list_hout
+};
+
+/** Command descriptor for HBR set PWM command */
+cmd_des_t const cmd_des_hout_pwm={
+ 0, CDESM_OPCHR|CDESM_RW,
+ "houtpwm*","\t- houtpwmX:(period,duty) set pwm period in us and duty in % of period\r\n\t\thoutpwmX? read period in us and duty in % of period from HOUTX.",
+ cmd_do_hout_pwm, (void *)&cmd_list_hout
+};
+
+/** Command descriptor for PWM start command */
+cmd_des_t const cmd_des_hout_pwm_start={
+ 0, 0,
+ "houtpwmstart#","\t- houtpwmstartX - Start generating of pwm signal on HOUTX",
+ cmd_do_hout_pwm_start, (void *)&cmd_list_hout
+};
+
+/** Command descriptor for PWM stop command */
+cmd_des_t const cmd_des_hout_pwm_stop={
+ 0, 0,
+ "houtpwmstop#","\t- houtpwmstopX - Stop generating of pwm signal on HOUTX",
+ cmd_do_hout_pwm_stop, (void *)&cmd_list_hout
+};
+
+/** List of commands for hout, defined as external */
+cmd_des_t const *cmd_list_hout[]={
+ &cmd_des_test_hout_fail,
+ &cmd_des_read_hifbk,
+ &cmd_des_hout_pwm,
+ &cmd_des_hout_pwm_start,
+ &cmd_des_hout_pwm_stop,
+ NULL
+};
* cmd_lin.c
*
* Created on: 28.2.2013
- * Author: michal
+ * Author: Michal Horn
+ *
+ * Commands for LIN control.
+ */
+
+#include "cmd_lin.h"
+#include "ti_drv_lin.h"
+#include "hal_gpio_tms570_def.h"
+#include "os_portmacro.h"
+#include "FreeRTOS.h"
+#include "os_semphr.h"
+#include "hal_gpio_tms570.h"
+#include "cmdio_tisci.h"
+
+/** Semaphore used to stop command, until message is received */
+xSemaphoreHandle linMsgReceived;
+/** Semaphore used to stop command, until ID is received */
+xSemaphoreHandle linIDReceived;
+
+/**
+ * @brief Function called by LIN ISR
+ * Gives semaphores according the type of interrupt
+ *
+ * @param[in] lin Pointer to LIN registers
+ * @param[in] flags Type of interrupt
+ */
+void linNotification(linBASE_t *lin, uint32_t flags)
+{
+ if (flags & LIN_ID_INT) {
+ xSemaphoreGiveFromISR(linIDReceived, NULL);
+ }
+ if (flags & LIN_RX_INT) {
+ lin->FLR |= (1 << 9);
+ xSemaphoreGiveFromISR(linMsgReceived, NULL);
+ }
+}
+
+/** @brief Command for testing LIN loopback
+ *
+ * Command sends short data chunk and counts errors when receiving through loopback.
+ *
+ * @param[in] cmd_io Pointer to IO functions
+ * @param[in] cmd_des Pointer to command descriptor
+ * @param[in] param Pointer to an array of parameters
+ *
+ * @return
*/
+int cmd_do_lin_loop_back(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
+ uint8_t txData[8] = {'L', 'I', 'N', ' ', 'T', 'E', 'S', 'T'};
+ uint8_t rxData[8];
+ uint8_t txID = 0xAC;
+ uint8_t rxID = 0;
+
+ linEnableLoopback(linREG, Digital);
+ hal_gpio_set_value(PIN_DSC_LIN1NSLP, 1);
+ linIDReceived = xSemaphoreCreateCounting(1, 0);
+ linMsgReceived = xSemaphoreCreateCounting(1, 0);
+
+ linSetLength(linREG, 8);
+ linSendHeader(linREG, txID);
+ while(!linIsTxReady(linREG)) ;
+ xSemaphoreTake(linIDReceived, portMAX_DELAY);
+ rxID = linGetIdentifier(linREG);
+ if (rxID == txID) {
+ linSend(linREG, txData);
+ while(!linIsTxReady(linREG)) ;
+ xSemaphoreTake(linMsgReceived, portMAX_DELAY);
+ linGetData(linREG, rxData);
+ uint8_t errCnt = 0;
+ uint8_t i;
+ for (i = 0; i < 8; i++) {
+ if (txData[i] != rxData[i]) errCnt++;
+ }
+
+ if (!errCnt) {
+ print((uint8_t *)"OK");
+ }
+ else {
+ print((uint8_t *)"Transmittion errors: ");
+ char errBuf[2];
+ i2str(errBuf, errCnt, 1, 10);
+ print((uint8_t *)errBuf);
+ print((uint8_t *)"\r\n");
+ }
+ }
+ else {
+ print((uint8_t *)"FAILED: Sent and Received ID does not match.\r\n");
+ }
+ vSemaphoreDelete(linIDReceived);
+ vSemaphoreDelete(linMsgReceived);
+ hal_gpio_set_value(PIN_DSC_LIN1NSLP, 0);
+ return 0;
+}
+/** Descriptor of command for lin loopback test */
+cmd_des_t const cmd_des_lin_loop_back={
+ 0, 0,
+ "testlin","Test digital loopback on LIN",
+ cmd_do_lin_loop_back, (void *)&cmd_list_lin
+};
+/** List of commands for lin, defined as external */
+cmd_des_t const *cmd_list_lin[]={
+ &cmd_des_lin_loop_back,
+ NULL
+};
* cmd_lout.c
*
* Created on: 28.2.2013
- * Author: michal
+ * Author: Michal Horn
+ *
+ * Commands for LOUT controlling.
+ * - Setting and getting value to LOUT port
+ * - Setting and getting value to LOUT pin
+ * - Getting LOUT status from SPI
+ */
+
+#include "cmd_lout.h"
+#include "cmdio_tisci.h"
+#include "utils.h"
+#include "port_def.h"
+#include "spi_resp_transl.h"
+#include "drv_lout.h"
+
+/**
+ * @brief Set and get value on LOUT port
+ *
+ * Command syntax: loutwr:(val) - Set value val to port. 1st bit of val -> LOUT1, 2nd bit of val -> LOUT2 etc.
+ * loutwr? - Get value on LOUT port.
+ *
+ * @param[in] cmd_io Pointer to IO stack
+ * @param[in] des Pointer to command descriptor
+ * @param[in] param Parameters of command
+ * @return 0 when OK or error code
+ */
+int cmd_do_lout_wr(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
+ char *p;
+ int opchar;
+ int i;
+ uint32_t ret;
+ uint32_t values[MAX_PARAM_VALUES_NUM];
+
+ if((opchar=cmd_opchar_check(cmd_io,des,param))<0) return opchar;
+
+ if(opchar==':'){
+ p=param[3];
+ si_skspace(&p);
+ i = read_arg(&p, values, MAX_PARAM_VALUES_NUM, 16);
+ if (i != 1)
+ return -CMDERR_BADPAR;
+
+ lout_set_word(values[0]);
+ ret=lout_spi_transfer();
+ return cmd_opchar_replong(cmd_io, param, ret, 0, 16);
+ }
+ else{
+ ret = lout_get_word();
+ return cmd_opchar_replong(cmd_io, param, ret, 0, 16);
+ }
+}
+
+/**
+ * @brief Set and get value on specified LOUT pin
+ *
+ * Command syntax: loutval#:v - Set value v to pin #. V must be 0 or 1, # in range 1-8
+ * loutval#? - Get value on pin #, in range 1-8.
+ *
+ * @param[in] cmd_io Pointer to IO stack
+ * @param[in] des Pointer to command descriptor
+ * @param[in] param Parameters of command
+ * @return 0 when OK or error code
*/
+int cmd_do_lout_val(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
+ char *p;
+ int opchar;
+ int pin;
+ int value;
+ uint32_t ret;
+
+ if((opchar=cmd_opchar_check(cmd_io,des,param))<0) return opchar;
+ p=param[1];
+ if(si_long(&p,(long*)&pin,0)<0) return -CMDERR_BADPAR;
+
+ if(opchar==':'){
+ p=param[3];
+ if(si_long(&p,(long*)&value,0)<0) return -CMDERR_BADPAR;
+ lout_set_pin(pin, value);
+ ret=lout_spi_transfer();
+ return cmd_opchar_replong(cmd_io, param, ret, 0, 16);
+ }
+ else{
+ ret = lout_get_pin(pin);
+ return cmd_opchar_replong(cmd_io, param, ret, 0, 16);
+ }
+}
+
+/**
+ * @brief Get status of LOUT in human readable form
+ *
+ * Command syntax: loutstat
+ *
+ * @param[in] cmd_io Pointer to IO stack
+ * @param[in] des Pointer to command descriptor
+ * @param[in] param Parameters of command
+ * @return 0 when OK or error code
+ */
+int cmd_do_lout_status(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
+ uint32_t ret;
+ uint32_t numCmdDesc;
+ int i;
+ char buf[16];
+ uint32_t numFieldDesc;
+
+
+ ret = lout_spi_transfer();
+ spitr_reg_translate_table_t translatedData;
+
+ const spitr_cmd_map_t* cmdDesc = get_spi_cmd_map(PORT_NAME_LOUT, -1, &numCmdDesc);
+ if(cmdDesc == NULL) return -CMDERR_BADREG;
+
+ const spitr_field_desc_t* fieldDescs = get_spi_field_desc(cmdDesc, numCmdDesc, lout_spi_get_cmd(), &numFieldDesc);
+ if (fieldDescs == NULL)
+ return -CMDERR_BADPAR;
+ ret = spitr_fill_tr_table(fieldDescs, numFieldDesc, lout_spi_get_response(), &translatedData);
+
+ for (i = 0; i < translatedData.num_rows; i++) {
+ print((uint8_t *)translatedData.row[i].field_name);
+ print((uint8_t *)": 0x");
+ i2str(buf, translatedData.row[i].value, 0, 16);
+ print((uint8_t *)buf);
+ print((uint8_t *)"\r\n");
+ }
+ return cmd_opchar_replong(cmd_io, param, ret, 0, 10);
+}
+
+/** Command descriptor for lout get/set port value */
+cmd_des_t const cmd_des_lout_wr={
+ 0, CDESM_OPCHR|CDESM_RW,
+ "loutwr","\tloutwr:(wr) - writes word wr in LOUT\r\n\t\tloutwr? - reads word from LOUT",
+ cmd_do_lout_wr, (void *)&cmd_list_lout
+};
+
+/** Command descriptor for lout get/set pin value */
+cmd_des_t const cmd_des_lout_val={
+ 0, CDESM_OPCHR|CDESM_RW,
+ "loutval#","\tloutvalX:Y - writes bit Y on LOUTX\r\n\t\tloutvalX? - reads bit from LOUTX",
+ cmd_do_lout_val, (void *)&cmd_list_lout
+};
+/** Command descriptor for lout get status */
+cmd_des_t const cmd_des_lout_status={
+ 0, 0,
+ "loutstat","get LOUT status in human readable format",
+ cmd_do_lout_status, (void *)&cmd_list_lout
+ };
+/** List of commands for hout, defined as external */
+cmd_des_t const *cmd_list_lout[]={
+ &cmd_des_lout_wr,
+ &cmd_des_lout_val,
+ &cmd_des_lout_status,
+ NULL
+};
* cmd_pin.c
*
* Created on: 28.2.2013
- * Author: michal
+ * Author: Michal Horn
+ *
+ * Commands for pin controlling
+ * - Printing list of available pins
+ * - Setting and getting value to pins
+ * - Setting and getting pins direction
+ */
+
+#include "cmd_pin.h"
+#include "cmdio_tisci.h"
+#include "hal_gpio_tms570_def.h"
+#include "hal_gpio_tms570.h"
+#include "utils.h"
+/**
+ * @brief Print list of pins
+ *
+ * Command syntax: pinlist
+ *
+ * @param[in] cmd_io Pointer to IO stack
+ * @param[in] des Pointer to command descriptor
+ * @param[in] param Parameters of command
+ * @return 0 when OK or error code
+ */
+int cmd_do_pin_list(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
+ uint32_t i;
+ print((uint8_t*)"List of all defined pins. Those names can be used by pinval command.\r\n");
+ for (i = 0; i < MAX_PIN_CNT; i++) {
+ if (pin_map[i].pin_name == PIN_NAME_UNUSED) continue;
+ print((uint8_t*)pin_map[i].pin_name);
+ print((uint8_t*)"\r\n");
+ }
+ return 1;
+}
+
+/**
+ * @brief Set or get pin value
+ *
+ * Command syntax: pinvalNAME:v - set value v (1 or 0) to pin NAME (can be obtained by pinlist command)
+ * pinvalNAME? - get value on pin NAME (can be obtained by pinlist command)
+ *
+ * @param[in] cmd_io Pointer to IO stack
+ * @param[in] des Pointer to command descriptor
+ * @param[in] param Parameters of command
+ * @return 0 when OK or error code
+ */
+int cmd_do_pin_val(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
+ char *p;
+ long val;
+ int opchar;
+ uint32_t* desc;
+
+ if((opchar=cmd_opchar_check(cmd_io,des,param))<0) return opchar;
+
+ if((desc = hal_gpio_get_pin_dsc(param[1], param[2]-param[1]))==NULL) return -CMDERR_BADREG;
+
+ if(opchar==':'){
+ p=param[3];
+ if(si_long(&p,&val,0)<0) return -CMDERR_BADPAR;
+ si_skspace(&p);
+ if(*p) return -CMDERR_GARBAG;
+ if (val != 0 && val != 1)
+ return -CMDERR_BADPAR;
+ hal_gpio_set_value(*desc, (uint32_t) val);
+ return val;
+ }
+ else{
+ uint32_t pin_value = hal_gpio_get_value(*desc);
+ return cmd_opchar_replong(cmd_io, param, pin_value, 0, 0);
+ }
+}
+
+/**
+ * @brief Set or get pin direction
+ *
+ * Command syntax: pindirNAME:v - set direction 1-out, 0-in to pin NAME (can be obtained by pinlist command)
+ * pindirNAME? - get direction of pin NAME (can be obtained by pinlist command)
+ *
+ * @param[in] cmd_io Pointer to IO stack
+ * @param[in] des Pointer to command descriptor
+ * @param[in] param Parameters of command
+ * @return 0 when OK or error code
*/
+int cmd_do_pin_dir(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
+ char *p;
+ long val;
+ int opchar;
+ uint32_t* desc;
+
+ if((opchar=cmd_opchar_check(cmd_io,des,param))<0) return opchar;
+
+ if((desc = hal_gpio_get_pin_dsc(param[1], param[2]-param[1]))==NULL) return -CMDERR_BADREG;
+
+ if(opchar==':'){
+ p=param[3];
+ if(si_long(&p,&val,0)<0) return -CMDERR_BADPAR;
+ si_skspace(&p);
+ if(*p) return -CMDERR_GARBAG;
+ if (val == 1) {
+ *desc |= PORT_CONF_SET_DIR;
+ *desc |= PORT_CONF_DIR_OUT;
+ }
+ else if (val == 0) {
+ *desc &= (~PORT_CONF_DIR_OUT);
+ *desc |= PORT_CONF_SET_DIR;
+ }
+ else {
+ return -CMDERR_BADPAR;
+ }
+
+ hal_pin_conf(*desc);
+ return val;
+ }
+ else{
+ uint32_t pin_dir = hal_gpio_get_direction(*desc);
+ return cmd_opchar_replong(cmd_io, param, pin_dir, 0, 0);
+ }
+}
+
+/** Command descriptor for pin list */
+cmd_des_t const cmd_des_pin_list = {
+ 0, 0,
+ "pinlist","Prints list of all defined pins",
+ cmd_do_pin_list, (void *)&cmd_list_pin
+};
+
+/** Command descriptor for pin get/set value */
+cmd_des_t const cmd_des_pin_val={
+ 0, CDESM_OPCHR|CDESM_RW,
+ "pinval*","Sets or get pin value",
+ cmd_do_pin_val, (void *)&cmd_list_pin
+};
+/** Command descriptor for pin get/set direction */
+cmd_des_t const cmd_des_pin_dir={
+ 0, CDESM_OPCHR|CDESM_RW,
+ "pindir*","Sets pin direction 1-out, 0-in",
+ cmd_do_pin_dir, (void *)&cmd_list_pin
+};
+/** List of commands for pin, defined as external */
+cmd_des_t const *cmd_list_pin[]={
+ &cmd_des_pin_list,
+ &cmd_des_pin_val,
+ &cmd_des_pin_dir,
+ NULL
+};
* cmd_port.c
*
* Created on: 28.2.2013
- * Author: michal
+ * Author: Michal Horn
+ *
+ * Commands for port controlling
+ * - Printing list of available ports (not yet available)
+ * - Setting/getting port value
*/
+#include "cmd_port.h"
+#include "cmdio_tisci.h"
+#include "port_def.h"
+#include "utils.h"
+
+/*
+int cmd_do_port_list(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
+ uint32_t i;
+ char buf[4];
+ print((uint8_t*)"List of all defined ports with its type. Those names can be used by portval command.\r\n");
+ for (i = 0; i < PORT_CNT; i++) {
+ if (port_ [i].pin_name == PIN_NAME_UNUSED) continue;
+ print((uint8_t*)pin_map[i].pin_name);
+ print((uint8_t*)"\r\n");
+ }
+}
+*/
+
+
+/**
+ * @brief Read values from specified port
+ *
+ * Command syntax: portvalNAME:(val) - Set value val to port specified by NAME (can be obtsined by portlist command). 1st bit -> PORT_PIN_1, 2nd bit -> PORT_PIN_2)
+ * portvalNAME? - Get value on port specified by NAME (can be obtsined by portlist command). 1st bit -> PORT_PIN_1, 2nd bit -> PORT_PIN_2)
+ *
+ * @param[in] cmd_io Pointer to IO stack
+ * @param[in] des Pointer to command descriptor
+ * @param[in] param Parameters of command
+ * @return 0 when OK or error code
+ */
+int cmd_do_port_val(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
+ char *p;
+ int opchar;
+ int i;
+ port_desc_t* desc;
+ uint32_t ret;
+ uint32_t values[MAX_PARAM_VALUES_NUM];
+ char buf[16];
+
+ if((opchar=cmd_opchar_check(cmd_io,des,param))<0) return opchar;
+
+ if((desc = port_get_dsc(param[1], param[2]-param[1]))==NULL) return -CMDERR_BADREG;
+
+ if(opchar==':'){
+ p=param[3];
+ si_skspace(&p);
+ i = read_arg(&p, values, MAX_PARAM_VALUES_NUM, 16);
+ if (i < 0)
+ return i;
+ if (i != desc->numValues)
+ return -CMDERR_BADPAR;
+
+ ret = desc->port_setfnc_ptr(desc->config, desc->numValues, values);
+ return cmd_opchar_replong(cmd_io, param, ret, 0, 16);
+ }
+ else{
+ ret = desc->port_getfnc_ptr(desc->config, desc->numValues, values);
+ for (i = 0; i < desc->numValues; i++) {
+ i2str(buf, values[i], 0, 16);
+ print((uint8_t *)buf);
+ print((uint8_t *)"\r\n");
+ }
+ return cmd_opchar_replong(cmd_io, param, ret, 0, 16);
+ }
+}
+
+/** Command descriptor for read values from port command */
+cmd_des_t const cmd_des_port_val={
+ 0, CDESM_OPCHR|CDESM_RW,
+ "portval*","Read values from port",
+ cmd_do_port_val, (void *)&cmd_list_port
+};
+/** List of commands for port, defined as external */
+cmd_des_t const *cmd_list_port[]={
+ &cmd_des_port_val,
+ NULL
+};
* cmd_sdram.c
*
* Created on: 28.2.2013
- * Author: michal
+ * Author: Michal Horn
*/
+#include "cmd_sdram.h"
+#include "cmdio_tisci.h"
+
+/**
+ * @brief Tests the capacity and fitness of connected SDRAM
+ *
+ * Command syntax: testsdram
+ *
+ * @param[in] cmd_io Pointer to IO stack
+ * @param[in] des Pointer to command descriptor
+ * @param[in] param Parameters of command
+ * @return 0 when OK or error code
+ */
+int cmd_do_test_ram(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
+ volatile uint32_t* addrPtr = (uint32_t*)0x80000000U;
+ volatile uint32_t* endAddr = (uint32_t*)0x83FFFFFFU;
+ uint32_t pattern = 0x55555555U;
+ uint32_t cnt = 0;
+ uint32_t errCnt = 0;
+ uint32_t readVal = 0;
+
+ while (addrPtr <= endAddr) {
+ *addrPtr = pattern;
+ pattern += 0x55555555U;
+ addrPtr++;
+ }
+
+ addrPtr = (uint32_t *)0x80000000U;
+ pattern = 0x55555555U;
+ while (addrPtr <= endAddr) {
+ readVal = *addrPtr;
+ if (pattern == readVal) cnt++;
+ else if(errCnt++ <= 10) {
+ print((uint8_t *)"Error at 0x");
+ char numBuf[10];
+ i2str(numBuf, (long)addrPtr, 1, 16);
+ print((uint8_t *)numBuf);
+ print((uint8_t *)"\r\n");
+ }
+ else break;
+ pattern += 0x55555555U;
+ addrPtr++;
+ }
+
+ cnt = cnt * sizeof(uint32_t) / 1024 / 1024;
+ if (cnt == 0) {
+ print((uint8_t*)"SDRAM not connected.\r\n");
+ }
+ else {
+ char numBuf[10];
+ i2str(numBuf, cnt, 1, 10);
+ print((uint8_t*)"SDRAM installed: ");
+ print((uint8_t*)numBuf);
+ print((uint8_t*)" MB\r\n");
+ }
+
+ return 0;
+}
+
+/** Command descriptor for test SDRAM */
+cmd_des_t const cmd_des_test_sdram={
+ 0, 0,
+ "testsdram","Test if SDRAM module is connected and if it is, measure capacity",
+ cmd_do_test_ram, (void *)&cmd_list_sdram
+};
+
+/** List of commands for sdram, defined as external */
+cmd_des_t const *cmd_list_sdram[]={
+ &cmd_des_test_sdram,
+ NULL
+};
* cmd_spi.c
*
* Created on: 28.2.2013
- * Author: michal
+ * Author: Michal Horn
+ *
+ * Command for processing data from SPI and
+ * lowlevel command for sending data on SPI
+ */
+
+#include "cmd_spi.h"
+#include "cmdio_tisci.h"
+#include "drv_spi.h"
+#include "utils.h"
+#include "spi_resp_transl.h"
+#include "_isfuncdcl.h"
+
+/**
+ * @brief Translate SPI response according the command and peripheral type
+ *
+ * Command syntax: spitrNAME?(cmd, resp)
+ *
+ * Command take response resp given by last command cmd and translate it according peripheral
+ * type specified by NAME.
+ *
+ * @param[in] cmd_io Pointer to IO stack
+ * @param[in] des Pointer to command descriptor
+ * @param[in] param Parameters of command
+ * @return 0 when OK or error code
+ */
+int cmd_do_spi_translate(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
+ char *p;
+ int opchar;
+ int i;
+ uint32_t ret;
+ uint32_t values[MAX_PARAM_VALUES_NUM];
+ char buf[16];
+ uint32_t numFieldDesc;
+ uint32_t numCmdDesc;
+ uint32_t command;
+ uint32_t response;
+ spitr_reg_translate_table_t translatedData;
+
+ if((opchar=cmd_opchar_check(cmd_io,des,param))<0) return opchar;
+
+ const spitr_cmd_map_t* cmdDesc = cmdDesc = get_spi_cmd_map(param[1], param[2]-param[1], &numCmdDesc);
+ if(cmdDesc == NULL) return -CMDERR_BADREG;
+
+
+ if(opchar=='?'){
+ p=param[3];
+ si_skspace(&p);
+ i = read_arg(&p, values, MAX_PARAM_VALUES_NUM, 16);
+ if (i < 0)
+ return i;
+ command = values[0];
+ response = values[1];
+
+ const spitr_field_desc_t* fieldDescs = get_spi_field_desc(cmdDesc, numCmdDesc, command, &numFieldDesc);
+ if (fieldDescs == NULL)
+ return -CMDERR_BADPAR;
+
+ ret = spitr_fill_tr_table(fieldDescs, numFieldDesc, response, &translatedData);
+
+ for (i = 0; i < translatedData.num_rows; i++) {
+ print((uint8_t *)translatedData.row[i].field_name);
+ print((uint8_t *)": 0x");
+ i2str(buf, translatedData.row[i].value, 0, 16);
+ print((uint8_t *)buf);
+ print((uint8_t *)"\r\n");
+ }
+ return cmd_opchar_replong(cmd_io, param, ret, 0, 10);
+ }
+ else{
+ return -CMDERR_BADPAR;
+ }
+}
+
+
+/* SPI Master testing command */
+#define TEST_BUF 64
+uint8_t spi_test_buf_tx[TEST_BUF];
+uint8_t spi_test_buf_rx[TEST_BUF];
+
+static int test_rd_arr(char **ps, uint8_t *buf, int n)
+{
+ long val;
+ int c;
+ int i;
+
+ if (si_fndsep(ps, "({") < 0)
+ return -CMDERR_BADSEP;
+ i = 0;
+ si_skspace(ps);
+ if ((**ps != ')') && (**ps != '}'))
+ do {
+ if (i >= n)
+ return -CMDERR_BADPAR;
+ if (si_long(ps, &val, 16) < 0)
+ return -CMDERR_BADPAR;
+ buf[i] = val;
+ i++;
+ if ((c = si_fndsep(ps, ",)}")) < 0)
+ return -CMDERR_BADSEP;
+ } while (c == ',');
+
+ return i;
+}
+
+int spimst_print_rx(struct spi_drv *ifc, int status, int addr, uint8_t *buf)
+{
+ char tmp_buff[64];
+ int i;
+
+ print("SPI! ");
+ i2str(tmp_buff, addr, 1, 16);
+ print((uint8_t*)tmp_buff);
+ if (status < 0)
+ print("FAIL ");
+
+ print(" RX(");
+ for (i = 0; i < status; i++) {
+ i2str(tmp_buff, buf[i], 1, 16);
+ print((uint8_t*)tmp_buff);
+ print(",");
+ }
+ print(")");
+ print("\n");
+
+ return 0;
+}
+
+
+/**
+ * @brief Send SPI command on SPI and receive response
+ *
+ * Command syntax: spimst##:ADDR(cmd) - Sends command cmd on SPI ## with address ADDR
+ *
+ * @param[in] cmd_io Pointer to IO stack
+ * @param[in] des Pointer to command descriptor
+ * @param[in] param Parameters of command
+ * @return 0 when OK or error code
*/
+int cmd_do_spimst(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
+{
+ spi_drv_t *ifc;
+ int i;
+ char *p;
+ long val;
+ int ret;
+ unsigned int addr;
+ unsigned int rq_len;
+
+ if (!param[1] || !isdigit(*param[1]))
+ return -CMDERR_BADSUF;
+
+ if (*param[2] != ':')
+ return -CMDERR_OPCHAR;
+
+ ifc = spi_find_drv(NULL, *param[1] - '0');
+ if (ifc == NULL)
+ return -CMDERR_NODEV;
+
+ if (!(ifc->flags & SPI_IFC_ON)) {
+ //if (spi_tms570_init(ifc) < 0)
+ return -CMDERR_BADCFG;
+ }
+
+ p = param[3];
+
+ si_skspace(&p);
+ if (isdigit(*p)) {
+ if (si_long(&p, &val, 16) < 0)
+ return -CMDERR_BADPAR;
+ addr = val;
+ }
+ si_skspace(&p);
+ i = test_rd_arr(&p, spi_test_buf_tx, TEST_BUF);
+ if (i < 0)
+ return i;
+ rq_len = i;
+
+ ret = spi_transfer(ifc, addr, rq_len, spi_test_buf_tx, spi_test_buf_rx);
+ spimst_print_rx(ifc, ret, addr, spi_test_buf_rx);
+ return 0;
+}
+
+/** Command descriptor for SPI response translation */
+cmd_des_t const cmd_des_spi_translate={
+ 0, CDESM_OPCHR|CDESM_RW,
+ "spitr*","Translate response from SPI peripheral. spitrPERNAME?(CMD, RESP)",
+ cmd_do_spi_translate, (void *)&cmd_list_spi
+};
+
+/** Command descriptor for SPI trasfer */
+cmd_des_t const cmd_des_spimst = { 0, CDESM_OPCHR,
+ "spimst#", "SPI master communication request",
+ cmd_do_spimst, (void *)&cmd_list_spi
+};
+
+/** List of commands for SPI, defined as external */
+cmd_des_t const *cmd_list_spi[]={
+ &cmd_des_spi_translate,
+ &cmd_des_spimst,
+ NULL
+};
* cmd_vbat.c
*
* Created on: 28.2.2013
- * Author: michal
+ * Author: Michal Horn
+ *
+ * Commands for VBAT control
+ * - Power VBAT1 on and off using PWM to charge capacitors
+ */
+
+#include "cmd_vbat.h"
+#include "hal_gpio_tms570_def.h"
+#include "FreeRTOSConfig.h"
+#include "os_portmacro.h"
+#include "hal_gpio_tms570.h"
+#include "FreeRTOS.h"
+#include "os_task.h"
+
+#define VBATPWM_PERIOD 400
+
+/** Delay between set and clear vbat */
+static int vbatPwmRampProfile[] = {
+ 19,
+ 20,
+ 21,
+ 23,
+ 27,
+ 30,
+ 0
+};
+
+/**
+ * @brief Runs PWM defined by ramp profile on VBAT1
+ *
+ * @return value on VBAT port
+ */
+int vbat1_pwm() {
+ int *ppwm = vbatPwmRampProfile;
+ int pwm;
+ volatile uint8_t val = 1;
+ int i, j;
+ int pulse_cnt = 100;
+ uint32_t desc;
+
+ desc = PIN_DSC_VBAT1EN;
+ hal_gpio_set_value(desc, 0);
+ hal_gpio_direction_output(desc, 0);
+ vTaskDelay(10/portTICK_RATE_MS+2);
+ _disable_IRQ();
+ while((pwm = *(ppwm++))) {
+ for (i = 0; i < pulse_cnt; i++) {
+ hal_gpio_set_value(desc, 1);
+ for (j = 0; j < pwm; j++)
+ ;
+ hal_gpio_set_value(desc, 0);
+ for (j = 0; j < VBATPWM_PERIOD - pwm; j++)
+ ;
+ }
+ }
+ hal_gpio_set_value(desc, 1);
+ _enable_IRQ();
+ return hal_gpio_get_value(desc);
+}
+
+/**
+ * @brief Power on VBAT and VBAT1 using PWM
+ *
+ * Command syntax: poweron
+ *
+ * @param[in] cmd_io Pointer to IO stack
+ * @param[in] des Pointer to command descriptor
+ * @param[in] param Parameters of command
+ * @return value on VBAT port
*/
+int cmd_do_power_on(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
+ int ret = 0;
+ hal_gpio_set_value(PIN_DSC_VBATEN, 1);
+ ret = hal_gpio_get_value(PIN_DSC_VBATEN);
+ ret |= vbat1_pwm() << 1;
+ return cmd_opchar_replong(cmd_io, param, ret, 0, 0);
+}
+
+/**
+ * @brief Power off VBAT and VBAT1 using PWM
+ *
+ * Command syntax: poweroff
+ *
+ * @param[in] cmd_io Pointer to IO stack
+ * @param[in] des Pointer to command descriptor
+ * @param[in] param Parameters of command
+ * @return value on VBAT port
+ */
+int cmd_do_power_off(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
+ int ret = 0;
+ hal_gpio_set_value(PIN_DSC_VBAT1EN, 0);
+ ret = hal_gpio_get_value(PIN_DSC_VBAT1EN);
+ hal_gpio_set_value(PIN_DSC_VBATEN, 0);
+ ret |= hal_gpio_get_value(PIN_DSC_VBATEN) << 1;
+ return cmd_opchar_replong(cmd_io, param, ret, 0, 0);
+}
+
+/** Command descriptor for poweron */
+cmd_des_t const cmd_des_power_on = {
+ 0, 0,
+ "poweron","Set VBATEN and VBAT1EN using PWM",
+ cmd_do_power_on, (void *)&cmd_list_vbat
+};
+
+/** Command descriptor for poweroff */
+cmd_des_t const cmd_des_power_off = {
+ 0, 0,
+ "poweroff","Clear VBATEN and VBAT1EN",
+ cmd_do_power_off, (void *)&cmd_list_vbat
+};
+/** List of commands for vbat, defined as external */
+cmd_des_t const *cmd_list_vbat[]={
+ &cmd_des_power_on,
+ &cmd_des_power_off,
+ NULL
+};
/* Include files */
#include "cmd_proc.h"
-#include "sys_common.h"
-#include "cmdio_tisci.h"
-#include "string.h"
-#include "stdio.h"
-#include "can.h"
-#include "adc.h"
-#include "dmm.h"
-#include "lin.h"
-#include "emac_test.h"
-#include "spi_drv.h"
-#include "spi_tms570.h"
-#include "hbridge.h"
+#include "FreeRTOS.h"
+#include "os_task.h"
#include "hal_gpio_tms570.h"
-#include "adc_drv.h"
-#include "port_def.h"
-#include "FlexRay.h"
-#include "spi_resp_transl.h"
-#include "lout_spi.h"
-#include "din_spi.h"
-#include "dac_spi.h"
-#include "fray_spi.h"
-#include "hout.h"
-
-#include "ctype.h"
-#include "utils.h"
-
-#define MAX_PARAM_VALUES_NUM 64
-
-
-/** @brief List in which commands are stored */
+#include "cmd_adc.h"
+#include "cmd_dac.h"
+#include "cmd_emac.h"
+#include "cmd_fray.h"
+#include "cmd_can.h"
+#include "cmd_din.h"
+#include "cmd_hbr.h"
+#include "cmd_hout.h"
+#include "cmd_lin.h"
+#include "cmd_lout.h"
+#include "cmd_pin.h"
+#include "cmd_port.h"
+#include "cmd_sdram.h"
+#include "cmd_spi.h"
+#include "cmd_vbat.h"
+
+/** Root list in which commands are stored */
cmd_des_t const **cmd_list;
-xSemaphoreHandle linMsgReceived;
-xSemaphoreHandle linIDReceived;
-
-/** @brief Semaphore blocking task when it waits for interrupt signaling message receive */
-xSemaphoreHandle canMsgReceived;
-xSemaphoreHandle canMsgSent;
-canBASE_t* canDst;
-canBASE_t* canSrc;
-uint32_t canMsgBox;
-uint32_t canSendError;
-uint32_t canRecError;
-
-FRAY_ST e_FRAY0_ST;
-
-
-
-/* ------------------------------
- * User defined command functions
- * ------------------------------
+/**
+ * @brief Sleep the board
+ *
+ * Command syntax: sleep
+ *
+ * @param[in] cmd_io Pointer to IO stack
+ * @param[in] des Pointer to command descriptor
+ * @param[in] param Parameters of command
+ * @return 0 when OK or error code
*/
-
-int cmd_do_lin_loop_back(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
- uint8_t txData[8] = {'L', 'I', 'N', ' ', 'T', 'E', 'S', 'T'};
- uint8_t rxData[8];
- uint8_t txID = 0xAC;
- uint8_t rxID = 0;
-
- linEnableLoopback(linREG, Digital);
- hal_gpio_set_value(PIN_DSC_LIN1NSLP, 1);
- linIDReceived = xSemaphoreCreateCounting(1, 0);
- linMsgReceived = xSemaphoreCreateCounting(1, 0);
-
- linSetLength(linREG, 8);
- linSendHeader(linREG, txID);
- while(!linIsTxReady(linREG)) ;
- xSemaphoreTake(linIDReceived, portMAX_DELAY);
- rxID = linGetIdentifier(linREG);
- if (rxID == txID) {
- linSend(linREG, txData);
- while(!linIsTxReady(linREG)) ;
- xSemaphoreTake(linMsgReceived, portMAX_DELAY);
- linGetData(linREG, rxData);
- uint8_t errCnt = 0;
- uint8_t i;
- for (i = 0; i < 8; i++) {
- if (txData[i] != rxData[i]) errCnt++;
- }
-
- if (!errCnt) {
- print((uint8_t *)"OK");
- }
- else {
- print((uint8_t *)"Transmittion errors: ");
- char errBuf[2];
- i2str(errBuf, errCnt, 1, 10);
- print((uint8_t *)errBuf);
- print((uint8_t *)"\r\n");
- }
- }
- else {
- print((uint8_t *)"FAILED: Sent and Received ID does not match.\r\n");
- }
- vSemaphoreDelete(linIDReceived);
- vSemaphoreDelete(linMsgReceived);
- hal_gpio_set_value(PIN_DSC_LIN1NSLP, 0);
- return 0;
-}
-
int cmd_do_sleep(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
hal_gpio_set_value(PIN_DSC_CANNSTB, 1);
hal_gpio_set_value(PIN_DSC_CANEN, 1);
return 0;
}
-
-/** Tests the capacity of connected SDRAM
- * @param[in] cmd_io Pointer to IO stack
- * @param[in] des Pointer to command descriptor
- * @param[in] param Parameters of command
- * @return 0 when OK or error code
- */
-int cmd_do_test_ram(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
- volatile uint32_t* addrPtr = (uint32_t*)0x80000000U;
- volatile uint32_t* endAddr = (uint32_t*)0x83FFFFFFU;
- uint32_t pattern = 0x55555555U;
- uint32_t cnt = 0;
- uint32_t errCnt = 0;
- uint32_t readVal = 0;
-
- while (addrPtr <= endAddr) {
- *addrPtr = pattern;
- pattern += 0x55555555U;
- addrPtr++;
- }
-
- addrPtr = (uint32_t *)0x80000000U;
- pattern = 0x55555555U;
- while (addrPtr <= endAddr) {
- readVal = *addrPtr;
- if (pattern == readVal) cnt++;
- else if(errCnt++ <= 10) {
- print((uint8_t *)"Error at 0x");
- char numBuf[10];
- i2str(numBuf, (long)addrPtr, 1, 16);
- print((uint8_t *)numBuf);
- print((uint8_t *)"\r\n");
- }
- else break;
- pattern += 0x55555555U;
- addrPtr++;
- }
-
- cnt = cnt * sizeof(uint32_t) / 1024 / 1024;
- if (cnt == 0) {
- print((uint8_t*)"SDRAM not connected.\r\n");
- }
- else {
- char numBuf[10];
- i2str(numBuf, cnt, 1, 10);
- print((uint8_t*)"SDRAM installed: ");
- print((uint8_t*)numBuf);
- print((uint8_t*)" MB\r\n");
- }
-
- return 0;
-}
-
-
-/** Reads values from HOUT_IFBK pins (subset of ADC)
- * @param[in] cmd_io Pointer to IO stack
- * @param[in] des Pointer to command descriptor
- * @param[in] param Parameters of command
- * @return 0 when OK or error code
- */
-int cmd_do_read_hout_ifbk_values(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
-{
- char numBuf[32]; // Buffer used for i2str conversion
- uint32_t i; // Cycle control variable
- port_desc_t* desc;
- uint32_t values[PORT_HOUTIFBK_CHANNEL_NUM*2];
- int ret;
-
- desc = port_get_dsc(PORT_NAME_HOUTIFBK, -1);
-
- ret = desc->port_getfnc_ptr(desc->config, PORT_HOUTIFBK_CHANNEL_NUM, values);
- if (ret < 0)
- return ret;
-
- print((uint8_t *)"\r\nHOUT_IFBK: values: ");
- /* conversion results : */
- for (i = 0; i < PORT_HOUTIFBK_CHANNEL_NUM; i++) {
- print((uint8_t *)"\r\nChannel: ");
- i2str(numBuf, values[i+PORT_HOUTIFBK_CHANNEL_NUM], 1, 10);
- print((uint8_t *)numBuf);
- print((uint8_t *)"\tvalue: ");
- i2str(numBuf, values[i], 1, 10);
- print((uint8_t *)numBuf);
- print((uint8_t *)" 0x");
- i2str(numBuf, values[i], 1, 16);
- print((uint8_t *)numBuf);
- }
- return 0;
-}
-
-/** Reads values from ADC1 pins
- * @param[in] cmd_io Pointer to IO stack
- * @param[in] des Pointer to command descriptor
- * @param[in] param Parameters of command
- * @return 0 when OK or error code
- */
-int cmd_do_read_adc1_values(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
-{
- char numBuf[4]; // Buffer used for i2str conversion
- uint32_t i; // Cycle control variable
- port_desc_t* desc;
- uint32_t values[PORT_ADC_CHANNEL_NUM*2];
- int ret;
-
- desc = port_get_dsc(PORT_NAME_ADC, -1);
-
- ret = desc->port_getfnc_ptr(desc->config, PORT_ADC_CHANNEL_NUM, values);
- if (ret < 0)
- return ret;
-
- print((uint8_t *)"\r\nADC1: values: ");
- /* conversion results : */
- for (i = 0; i < PORT_ADC_CHANNEL_NUM; i++) {
- print((uint8_t *)"\r\nChannel: ");
- i2str(numBuf, values[i+PORT_ADC_CHANNEL_NUM], 1, 10);
- print((uint8_t *)numBuf);
- print((uint8_t *)"\tvalue: ");
- i2str(numBuf, values[i], 1, 10);
- print((uint8_t *)numBuf);
- print((uint8_t *)" 0x");
- i2str(numBuf, values[i], 1, 16);
- print((uint8_t *)numBuf);
- }
- return 0;
-}
-
-#define VBATPWM_PERIOD 400
-
-static int vbatPwmRampProfile[] = {
- 19,
- 20,
- 21,
- 23,
- 27,
- 30,
- 0
-};
-
-
-int vbat1_pwm() {
- int *ppwm = vbatPwmRampProfile;
- int pwm;
- volatile uint8_t val = 1;
- int i, j;
- int pulse_cnt = 100;
- uint32_t desc;
-
- desc = PIN_DSC_VBAT1EN;
- hal_gpio_set_value(desc, 0);
- hal_gpio_direction_output(desc, 0);
- vTaskDelay(10/portTICK_RATE_MS+2);
- _disable_IRQ();
- while((pwm = *(ppwm++))) {
- for (i = 0; i < pulse_cnt; i++) {
- hal_gpio_set_value(desc, 1);
- for (j = 0; j < pwm; j++)
- ;
- hal_gpio_set_value(desc, 0);
- for (j = 0; j < VBATPWM_PERIOD - pwm; j++)
- ;
- }
- }
- hal_gpio_set_value(desc, 1);
- _enable_IRQ();
- return hal_gpio_get_value(desc);
-}
-
-int cmd_do_vbat1_set_bit(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
- return cmd_opchar_replong(cmd_io, param, vbat1_pwm(), 0, 0);
-}
-
-int cmd_do_vbat1_clr_bit(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
- uint32_t desc;
- desc = PIN_DSC_VBAT1EN;
- hal_gpio_set_value(desc, 0);
- return cmd_opchar_replong(cmd_io, param, 0, 0, 0);
-}
-
-int cmd_do_power_on(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
- int ret = 0;
- hal_gpio_set_value(PIN_DSC_VBATEN, 1);
- ret = hal_gpio_get_value(PIN_DSC_VBATEN);
- ret |= vbat1_pwm() << 1;
- return cmd_opchar_replong(cmd_io, param, ret, 0, 0);
-}
-
-int cmd_do_power_off(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
- int ret = 0;
- hal_gpio_set_value(PIN_DSC_VBAT1EN, 0);
- ret = hal_gpio_get_value(PIN_DSC_VBAT1EN);
- hal_gpio_set_value(PIN_DSC_VBATEN, 0);
- ret |= hal_gpio_get_value(PIN_DSC_VBATEN) << 1;
- return cmd_opchar_replong(cmd_io, param, ret, 0, 0);
-}
-
-int cmd_do_lout_wr(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
- char *p;
- int opchar;
- int i;
- uint32_t ret;
- uint32_t values[MAX_PARAM_VALUES_NUM];
-
- if((opchar=cmd_opchar_check(cmd_io,des,param))<0) return opchar;
-
- if(opchar==':'){
- p=param[3];
- si_skspace(&p);
- i = read_arg(&p, values, MAX_PARAM_VALUES_NUM, 16);
- if (i != 1)
- return -CMDERR_BADPAR;
-
- lout_set_word(values[0]);
- ret=lout_spi_transfer();
- return cmd_opchar_replong(cmd_io, param, ret, 0, 16);
- }
- else{
- ret = lout_get_word();
- return cmd_opchar_replong(cmd_io, param, ret, 0, 16);
- }
-}
-
-int cmd_do_lout_val(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
- char *p;
- int opchar;
- int pin;
- int value;
- uint32_t ret;
-
- if((opchar=cmd_opchar_check(cmd_io,des,param))<0) return opchar;
- p=param[1];
- if(si_long(&p,(long*)&pin,0)<0) return -CMDERR_BADPAR;
-
- if(opchar==':'){
- p=param[3];
- if(si_long(&p,(long*)&value,0)<0) return -CMDERR_BADPAR;
- lout_set_pin(pin, value);
- ret=lout_spi_transfer();
- return cmd_opchar_replong(cmd_io, param, ret, 0, 16);
- }
- else{
- ret = lout_get_pin(pin);
- return cmd_opchar_replong(cmd_io, param, ret, 0, 16);
- }
-}
-
-int cmd_do_lout_status(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
- uint32_t ret;
- uint32_t numCmdDesc;
- int i;
- char buf[16];
- uint32_t numFieldDesc;
-
-
- ret = lout_spi_transfer();
- spitr_reg_translate_table_t translatedData;
-
- const spitr_cmd_map_t* cmdDesc = get_spi_cmd_map(PORT_NAME_LOUT, -1, &numCmdDesc);
- if(cmdDesc == NULL) return -CMDERR_BADREG;
-
- const spitr_field_desc_t* fieldDescs = get_spi_field_desc(cmdDesc, numCmdDesc, lout_spi_get_cmd(), &numFieldDesc);
- if (fieldDescs == NULL)
- return -CMDERR_BADPAR;
- ret = spitr_fill_tr_table(fieldDescs, numFieldDesc, lout_spi_get_response(), &translatedData);
-
- for (i = 0; i < translatedData.num_rows; i++) {
- print((uint8_t *)translatedData.row[i].field_name);
- print((uint8_t *)": 0x");
- i2str(buf, translatedData.row[i].value, 0, 16);
- print((uint8_t *)buf);
- print((uint8_t *)"\r\n");
- }
- return cmd_opchar_replong(cmd_io, param, ret, 0, 10);
-}
-
-/** @brief Set pins on DIN port to be active or tri-state.
- *
- * Function expects two hexa numbers after ':' in brackets, ie command:(BB,AA).
- * First number sets state of pins SG0 - SG13, second number sets state of pins SP0 - SP7.
- * Bits are assigned from the left to the right pins SP0, SP1...SP7 and SG0, SG1..SG13.
- * 1 set the pin to be tri-state, 0 set the pin to be active.
- *
- * Function creates, sends two SPI commands. One is for SP and the second one is for SG pins.
- * Command receive response from the second command.
- *
- * @param[in] cmd_io Pointer to IO stack
- * @param[in] des Pointer to command descriptor
- * @param[in] param Parameters of command
- * @return 0 when OK or error code
- */
-int cmd_do_din_st_wr(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
- char *p;
- int opchar;
- int i;
- uint32_t spi_resp;
- uint32_t values[MAX_PARAM_VALUES_NUM];
-
- if((opchar=cmd_opchar_check(cmd_io,des,param))<0) return opchar;
-
- if(opchar==':'){
- p=param[3];
- si_skspace(&p);
- i = read_arg(&p, values, MAX_PARAM_VALUES_NUM, 16);
- if (i != 2)
- return -CMDERR_BADPAR;
-
- din_set_stat(values[1], values[0]);
- spi_resp=din_spi_transfer();
- return cmd_opchar_replong(cmd_io, param, spi_resp, 0, 16);
- }
- else return -CMDERR_OPCHAR;
-}
-
-/** @brief Enables or disables wake-up and interrupt function for pins on DIN port.
- *
- * Function expects two hexa numbers after ':' in brackets, ie command:(BB,AA).
- * First number sets pins SG0 - SG13, second number sets pins SP0 - SP7.
- * Bits are assigned from the left to the right to pins SP0, SP1...SP7 and SG0, SG1..SG13.
- * 1 - enable interrupt and wake-up function on the pin, 0 - disable those function on the pin.
- *
- * Function creates, sends two SPI commands. One is for SP and the second one is for SG pins.
- * Command receive response from the second command.
- *
- * @param[in] cmd_io Pointer to IO stack
- * @param[in] des Pointer to command descriptor
- * @param[in] param Parameters of command
- * @return 0 when OK or error code
- */
-int cmd_do_din_int_wr(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
- char *p;
- int opchar;
- int i;
- uint32_t spi_resp;
- uint32_t values[MAX_PARAM_VALUES_NUM];
-
- if((opchar=cmd_opchar_check(cmd_io,des,param))<0) return opchar;
-
- if(opchar==':'){
- p=param[3];
- si_skspace(&p);
- i = read_arg(&p, values, MAX_PARAM_VALUES_NUM, 16);
- if (i != 2)
- return -CMDERR_BADPAR;
-
- din_set_int(values[1], values[0]);
- spi_resp=din_spi_transfer();
- return cmd_opchar_replong(cmd_io, param, spi_resp, 0, 16);
- }
- else return -CMDERR_OPCHAR;
-}
-
-/** @brief Send reset command to DIN
- *
- * Function creates, sends SPI command that resets chip MC33972 and receive response.
- *
- * @param[in] cmd_io Pointer to IO stack
- * @param[in] des Pointer to command descriptor
- * @param[in] param Parameters of command
- * @return 0 when OK or error code
- */
-int cmd_do_din_reset(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
- char b[32];
- din_reset();
- uint32_t spi_resp = din_spi_transfer();
- print((uint8_t *)"dinreset: ");
- i2str(b, spi_resp, 0, 16);
- print((uint8_t *)b);
- return 0;
-}
-
-/** @brief Send switch status command to DIN
- *
- * Function creates, sends SPI command that poll new switches state and receive response.
- *
- * @param[in] cmd_io Pointer to IO stack
- * @param[in] des Pointer to command descriptor
- * @param[in] param Parameters of command
- * @return 0 when OK or error code
- */
-int cmd_do_din_switch_st(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
- char b[32];
- din_switch_st();
- uint32_t spi_resp = din_spi_transfer();
- print((uint8_t *)"dinswst: ");
- i2str(b, spi_resp, 0, 16);
- print((uint8_t *)b);
- return 0;
-}
-
-/** @brief Set programable pins as switch-to-battery or switch-to-ground
- *
- * Function expects one hexa number after ':' in brackets, ie command:(AA).
- * The number sets pins SP0 - SP7.
- * Bits are assigned from the left to the right to pins SP0, SP1...SP7.
- * 1 - set pin as switch-to-battery, 0 - set pin as switch-to-ground.
- *
- * Function creates, sends SPI command and receive response.
- *
- * @param[in] cmd_io Pointer to IO stack
- * @param[in] des Pointer to command descriptor
- * @param[in] param Parameters of command
- * @return 0 when OK or error code
- */
-int cmd_do_din_pr_wr(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
- char *p;
- int opchar;
- int i;
- uint32_t spi_resp;
- uint32_t values[MAX_PARAM_VALUES_NUM];
-
- if((opchar=cmd_opchar_check(cmd_io,des,param))<0) return opchar;
-
- if(opchar==':'){
- p=param[3];
- si_skspace(&p);
- i = read_arg(&p, values, MAX_PARAM_VALUES_NUM, 16);
- if (i != 1)
- return -CMDERR_BADPAR;
-
- din_set_pr(values[0]);
- spi_resp=din_spi_transfer();
- return cmd_opchar_replong(cmd_io, param, spi_resp, 0, 16);
- }
- else return -CMDERR_OPCHAR;
-}
-
-/** @brief Get state of DIN port as 16-b word
- *
- * Function creates, sends SPI command that poll new switches state,
- * receives response and filters just the pins, that are connected to the MC33972.
- *
- * @param[in] cmd_io Pointer to IO stack
- * @param[in] des Pointer to command descriptor
- * @param[in] param Parameters of command
- * @return 0 when OK or error code
- */
-int cmd_do_din_val_word(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
- int opchar;
- uint32_t spi_resp;
-
- if((opchar=cmd_opchar_check(cmd_io,des,param))<0) return opchar;
-
- if(opchar=='?') {
- din_switch_st();
- din_spi_transfer();
- spi_resp=din_get_val_word();
- return cmd_opchar_replong(cmd_io, param, spi_resp, 0, 16);
- }
- else return -CMDERR_OPCHAR;
-}
-
-/** @brief Get state of DIN port in human readable form
- *
- * Function creates, sends SPI command that poll new switches state,
- * receives response and translates it to human readable form.
- *
- * @param[in] cmd_io Pointer to IO stack
- * @param[in] des Pointer to command descriptor
- * @param[in] param Parameters of command
- * @return 0 when OK or error code
- */
-int cmd_do_din_status(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
- uint32_t numCmdDesc;
- int i;
- char buf[16];
- uint32_t numFieldDesc;
-
- din_switch_st();
- uint32_t din_spi_resp = din_spi_transfer();
-
- spitr_reg_translate_table_t translatedData;
-
- const spitr_cmd_map_t* cmdDesc = get_spi_cmd_map(PORT_NAME_DINSPI, -1, &numCmdDesc);
- if(cmdDesc == NULL) return -CMDERR_BADREG;
-
- const spitr_field_desc_t* fieldDescs = get_spi_field_desc(cmdDesc, numCmdDesc, din_spi_get_cmd(), &numFieldDesc);
- if (fieldDescs == NULL)
- return -CMDERR_BADPAR;
- uint32_t lsbResponse = 0 | ((din_spi_resp & 0xFF) << 16 ) | ((din_spi_resp & 0xFF0000) >> 16) | (din_spi_resp & 0xFF00);
- spitr_fill_tr_table(fieldDescs, numFieldDesc, lsbResponse, &translatedData);
-
- for (i = 0; i < translatedData.num_rows; i++) {
- print((uint8_t *)translatedData.row[i].field_name);
- print((uint8_t *)": 0x");
- i2str(buf, translatedData.row[i].value, 0, 16);
- print((uint8_t *)buf);
- print((uint8_t *)"\r\n");
- }
- return cmd_opchar_replong(cmd_io, param, din_spi_resp, 0, 16);
-}
-
-int cmd_do_dac_pin_on(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
- char *p;
- int opchar;
- int pin;
- int val;
- uint32_t status;
-
- if((opchar=cmd_opchar_check(cmd_io,des,param))<0) return opchar;
- p=param[1];
- if(si_long(&p,(long*)&pin,0)<0) return -CMDERR_BADPAR;
- pin--; // Highlevel command has pin number mapped according the board scheme, this switches to internal representation
- if (pin > DAC_PIN_NUM || pin < 0) return -CMDERR_BADPAR;
- if(opchar=='?') {
- status = dac_pin_is_on(pin);
- return cmd_opchar_replong(cmd_io, param, status, 0, 16);
- }
- else {
- p=param[3];
- if(si_long(&p,(long*)&val,0)<0) return -CMDERR_BADPAR;
- if (val == 0) dac_set_pin_off(pin);
- else if (val == 1) dac_set_pin_on(pin);
- else return -CMDERR_BADPAR;
- dac_spi_transfer(pin);
- status = dac_pin_is_on(pin);
- return cmd_opchar_replong(cmd_io, param, status, 0, 16);
- }
-}
-
-int cmd_do_dac_stat(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
- char buf[6];
- int i;
- char* dac_on_off[2] = {":\tOFF\t", ":\tON\t"};
-
- for (i = 0; i < DAC_PIN_NUM; i++) {
- print((uint8_t*)"DAC");
- i2str(buf, i+1, 0, 10);
- print((uint8_t*)buf);
- print((uint8_t*)dac_on_off[dac_pin_is_on(i)]);
- i2str(buf, dac_get_pin_voltage(i), 0, 10);
- print((uint8_t*)buf);
- print((uint8_t*)"\r\n");
- }
- return 0;
-}
-
-int cmd_do_dac_pin_value(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
- char *p;
- int opchar;
- int pin;
- int voltage;
-
- if((opchar=cmd_opchar_check(cmd_io,des,param))<0) return opchar;
- p=param[1];
- if(si_long(&p,(long*)&pin,0)<0) return -CMDERR_BADPAR;
- pin--; // Highlevel command has pin number mapped according the board scheme, this switches to internal representation
- if (pin > DAC_PIN_NUM || pin < 0) return -CMDERR_BADPAR;
- if(opchar=='?') {
- voltage = dac_get_pin_voltage(pin);
- return cmd_opchar_replong(cmd_io, param, voltage, 0, 10);
- }
- else {
- p=param[3];
- if(si_long(&p,(long*)&voltage,10)<0) return -CMDERR_BADPAR;
- dac_set_pin_voltage(pin, voltage);
- dac_spi_transfer(pin);
- voltage = dac_get_pin_voltage(pin);
- return cmd_opchar_replong(cmd_io, param, voltage, 0, 10);
- }
-}
-
-int cmd_do_fray_status(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
- char *p;
- int pin;
- uint32_t numCmdDesc;
- int i;
- char buf[16];
- uint32_t numFieldDesc;
-
- p=param[1];
- if(si_long(&p,(long*)&pin,0)<0) return -CMDERR_BADPAR;
- pin--; // Highlevel command has pin number mapped according the board scheme, this switches to internal representation
- if (pin > FRAY_NUM_PORTS || pin < 0) return -CMDERR_BADPAR;
-
- if (fray_spi_transfer(pin) != 0) return -CMDERR_BADDIO;
-
- spitr_reg_translate_table_t translatedData;
- const spitr_cmd_map_t* cmdDesc = get_spi_cmd_map(PORT_NAME_FRAY1, -1, &numCmdDesc);
- if(cmdDesc == NULL) return -CMDERR_BADREG;
-
- const spitr_field_desc_t* fieldDescs = get_spi_field_desc(cmdDesc, numCmdDesc, fray_spi_get_cmd(pin), &numFieldDesc);
- if (fieldDescs == NULL)
- return -CMDERR_BADPAR;
- uint32_t fr_spi_response = fray_spi_response(pin);
- uint32_t lsbResponse = 0 | ((fr_spi_response & 0xFF) << 8) | ((fr_spi_response & 0xFF00) >> 8);
- spitr_fill_tr_table(fieldDescs, numFieldDesc, lsbResponse, &translatedData);
- for (i = 0; i < translatedData.num_rows; i++) {
- print((uint8_t *)translatedData.row[i].field_name);
- print((uint8_t *)": 0x");
- i2str(buf, translatedData.row[i].value, 0, 16);
- print((uint8_t *)buf);
- print((uint8_t *)"\r\n");
- }
- return 0;
-}
-
-int cmd_do_pin_list(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
- uint32_t i;
- print((uint8_t*)"List of all defined pins. Those names can be used by pinval command.\r\n");
- for (i = 0; i < MAX_PIN_CNT; i++) {
- if (pin_map[i].pin_name == PIN_NAME_UNUSED) continue;
- print((uint8_t*)pin_map[i].pin_name);
- print((uint8_t*)"\r\n");
- }
- return 1;
-}
-
-/*
-int cmd_do_port_list(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
- uint32_t i;
- char buf[4];
- print((uint8_t*)"List of all defined ports with its type. Those names can be used by portval command.\r\n");
- for (i = 0; i < PORT_CNT; i++) {
- if (port_ [i].pin_name == PIN_NAME_UNUSED) continue;
- print((uint8_t*)pin_map[i].pin_name);
- print((uint8_t*)"\r\n");
- }
-}
-*/
-
-int cmd_do_pin_val(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
- char *p;
- long val;
- int opchar;
- uint32_t* desc;
-
- if((opchar=cmd_opchar_check(cmd_io,des,param))<0) return opchar;
-
- if((desc = hal_gpio_get_pin_dsc(param[1], param[2]-param[1]))==NULL) return -CMDERR_BADREG;
-
- if(opchar==':'){
- p=param[3];
- if(si_long(&p,&val,0)<0) return -CMDERR_BADPAR;
- si_skspace(&p);
- if(*p) return -CMDERR_GARBAG;
- if (val != 0 && val != 1)
- return -CMDERR_BADPAR;
- hal_gpio_set_value(*desc, (uint32_t) val);
- return val;
- }
- else{
- uint32_t pin_value = hal_gpio_get_value(*desc);
- return cmd_opchar_replong(cmd_io, param, pin_value, 0, 0);
- }
-}
-
-int cmd_do_pin_dir(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
- char *p;
- long val;
- int opchar;
- uint32_t* desc;
-
- if((opchar=cmd_opchar_check(cmd_io,des,param))<0) return opchar;
-
- if((desc = hal_gpio_get_pin_dsc(param[1], param[2]-param[1]))==NULL) return -CMDERR_BADREG;
-
- if(opchar==':'){
- p=param[3];
- if(si_long(&p,&val,0)<0) return -CMDERR_BADPAR;
- si_skspace(&p);
- if(*p) return -CMDERR_GARBAG;
- if (val == 1) {
- *desc |= PORT_CONF_SET_DIR;
- *desc |= PORT_CONF_DIR_OUT;
- }
- else if (val == 0) {
- *desc &= (~PORT_CONF_DIR_OUT);
- *desc |= PORT_CONF_SET_DIR;
- }
- else {
- return -CMDERR_BADPAR;
- }
-
- hal_pin_conf(*desc);
- return val;
- }
- else{
- uint32_t pin_dir = hal_gpio_get_direction(*desc);
- return cmd_opchar_replong(cmd_io, param, pin_dir, 0, 0);
- }
-}
-
-
-/** Read values general command function. According the suffix switch to appropriate reading procedure.
- * @param[in] cmd_io Pointer to IO stack
- * @param[in] des Pointer to command descriptor
- * @param[in] param Parameters of command
- * @return 0 when OK or error code
- */
-int cmd_do_port_val(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
- char *p;
- int opchar;
- int i;
- port_desc_t* desc;
- uint32_t ret;
- uint32_t values[MAX_PARAM_VALUES_NUM];
- char buf[16];
-
- if((opchar=cmd_opchar_check(cmd_io,des,param))<0) return opchar;
-
- if((desc = port_get_dsc(param[1], param[2]-param[1]))==NULL) return -CMDERR_BADREG;
-
- if(opchar==':'){
- p=param[3];
- si_skspace(&p);
- i = read_arg(&p, values, MAX_PARAM_VALUES_NUM, 16);
- if (i < 0)
- return i;
- if (i != desc->numValues)
- return -CMDERR_BADPAR;
-
- ret = desc->port_setfnc_ptr(desc->config, desc->numValues, values);
- return cmd_opchar_replong(cmd_io, param, ret, 0, 16);
- }
- else{
- ret = desc->port_getfnc_ptr(desc->config, desc->numValues, values);
- for (i = 0; i < desc->numValues; i++) {
- i2str(buf, values[i], 0, 16);
- print((uint8_t *)buf);
- print((uint8_t *)"\r\n");
- }
- return cmd_opchar_replong(cmd_io, param, ret, 0, 16);
- }
-}
-
-int cmd_do_spi_translate(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
- char *p;
- int opchar;
- int i;
- uint32_t ret;
- uint32_t values[MAX_PARAM_VALUES_NUM];
- char buf[16];
- uint32_t numFieldDesc;
- uint32_t numCmdDesc;
- uint32_t command;
- uint32_t response;
- spitr_reg_translate_table_t translatedData;
-
- if((opchar=cmd_opchar_check(cmd_io,des,param))<0) return opchar;
-
- const spitr_cmd_map_t* cmdDesc = cmdDesc = get_spi_cmd_map(param[1], param[2]-param[1], &numCmdDesc);
- if(cmdDesc == NULL) return -CMDERR_BADREG;
-
-
- if(opchar=='?'){
- p=param[3];
- si_skspace(&p);
- i = read_arg(&p, values, MAX_PARAM_VALUES_NUM, 16);
- if (i < 0)
- return i;
- command = values[0];
- response = values[1];
-
- const spitr_field_desc_t* fieldDescs = get_spi_field_desc(cmdDesc, numCmdDesc, command, &numFieldDesc);
- if (fieldDescs == NULL)
- return -CMDERR_BADPAR;
-
- ret = spitr_fill_tr_table(fieldDescs, numFieldDesc, response, &translatedData);
-
- for (i = 0; i < translatedData.num_rows; i++) {
- print((uint8_t *)translatedData.row[i].field_name);
- print((uint8_t *)": 0x");
- i2str(buf, translatedData.row[i].value, 0, 16);
- print((uint8_t *)buf);
- print((uint8_t *)"\r\n");
- }
- return cmd_opchar_replong(cmd_io, param, ret, 0, 10);
- }
- else{
- return -CMDERR_BADPAR;
- }
-}
-
-
-uint32_t canCheckForError(canBASE_t *node, const char* str, uint32_t *errorStatus, uint8_t isFinal)
-{
- //uint32_t errorStatus = node->ES;
- uint32_t errorLevel = *errorStatus & 0xE0U;
- uint32_t errStat = *errorStatus;
- char buf[9];
- char* levText = "Unknown level. ES: 0x";
-
-
- if (*errorStatus != 0) {
- if (errorLevel & canLEVEL_BUS_OFF) {
- levText = "CAN bus is off. ES: 0x";
- }
- else if (errorLevel & canLEVEL_PASSIVE) {
- levText = "CAN bus in passive mode. ES: 0x";
- }
- else if (errorLevel & canLEVEL_WARNING) {
- levText = "CAN bus in passive mode. ES: 0x";
- }
- else if (errorLevel == canLEVEL_ACTIVE) {
- if (isFinal) {
- levText = "CAN is active. ES: 0x";
- *errorStatus = 0;
- }
- else levText = NULL;
- }
- }
- else {
- if (isFinal) {
- levText = "CAN no error. ES: 0x";
- }
- else levText = NULL;
- }
-
- if (levText == NULL) return errorLevel;
-
- print((uint8_t*)str);
- print((uint8_t*)levText);
- i2str(buf, errStat, 1, 16);
- print((uint8_t*)buf);
- print((uint8_t*)"\r\n");
-
- /** @note The function canInit has to be called before this function can be used. */
- return errorLevel;
-}
-
-/** Runs test of CAN loopback. Send message from CAN1 and receive it on CAN2.
- * @param[in] cmd_io Pointer to IO stack
- * @param[in] des Pointer to command descriptor
- * @param[in] param Parameters of command
- * @return 0 when OK or error code
- */
-int cmd_do_test_can_loopback(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
-{
- uint32_t can[2];
- canBASE_t *canBases[3] = {canREG1, canREG2, canREG3};
- uint32_t canMailBoxes[3] = {canMESSAGE_BOX1, canMESSAGE_BOX2, canMESSAGE_BOX3};
- char* token = NULL;
- uint32_t txTimeOutCnt = 0;
- uint32_t rxTimeOutCnt = 0;
- uint32_t messagesTransmitted = 0;
- uint32_t messagesReceived = 0;
- uint32_t i;
- uint8_t tx_data[8] = {'T', 'E', 'S', 'T', ' ', 'C', 'A', 'N'};
- uint8_t rx_data[8] = {0, 0, 0, 0, 0, 0, 0, 0 };
-
-
- dmmREG->PC4 = (1<<(13)); // set CAN_NSTB
- vTaskDelay(50/portTICK_RATE_MS);
- dmmREG->PC5 = (1<<(15)); // clr CAN_EN
- vTaskDelay(50/portTICK_RATE_MS);
- dmmREG->PC5 = (1<<(13)); // clr CAN_NSTB
- vTaskDelay(50/portTICK_RATE_MS);
- dmmREG->PC4 = (1<<(13)); // set CAN_NSTB
- vTaskDelay(50/portTICK_RATE_MS);
- dmmREG->PC4 = (1<<(15)); // set CAN_EN
- vTaskDelay(50/portTICK_RATE_MS);
-
- // Get can ID 1
- if ((token = strtok(param[1], " ")) == NULL) {
-
- print((uint8_t *)"ERROR: Parameter 1 expected.");
- return 1;
- }
- if (EOF == sscanf(token, "%d", &can[0])){
- print((uint8_t *)"ERROR: unsigned number expected as param 1!");
- return 1;
- }
- // Get can ID 2
- if ((token = strtok(NULL, " ")) == NULL) {
- print((uint8_t *)"ERROR: Parameter 2 expected.");
- return 1;
- }
- if (EOF == sscanf(token, "%d", &can[1])){
- print((uint8_t *)"ERROR: unsigned number expected as param 2!");
- return 1;
- }
- if ((token = strtok(NULL, " ")) != NULL) {
- print((uint8_t *)"ERROR: More than 2 parameters detected!");
- return 1;
- }
- if (can[0] == can[1]) {
- print((uint8_t *)"ERROR: Destination equals source!);");
- return 1;
- }
- if (can[0] < 1 | can[1] > 3) {
- print((uint8_t *)"Parameter out of range <1;3>!");
- return 1;
- }
- canSrc = canBases[can[0]-1];
- canDst = canBases[can[1]-1];
- canMsgBox = canMailBoxes[can[0]-1];
- canMsgReceived = xSemaphoreCreateCounting(1, 0);
- canMsgSent = xSemaphoreCreateCounting(1, 0);
-
- print((uint8_t *)"\r\nTesting CAN loopback\r\n");
- canREG1->CTL |= 1|(1<<9);
- canREG2->CTL |= 1|(1<<9);
- canREG3->CTL |= 1|(1<<9);
- canRecError = 0;
- canDst->CTL |= 1<<15; // Reset
- while (canDst->CTL & (1<<15)) ; // Wait for reset
- canSendError = 0;
- canSrc->CTL |= 1<<15;
- while (canSrc->CTL & (1<<15)) ;
- canInit();
- canDst->CTL |= 1<<9;
- canSrc->CTL |= 1<<9;
- vTaskDelay(50/portTICK_RATE_MS);
-
- i = canSrc->ES; // Reset error flag
- i = canDst->ES; // Reset error flag
- canEnableErrorNotification(canDst);
- canEnableErrorNotification(canSrc);
-
- for (i = 0; i < 100; i++) { // Send 100 times the message
- if (canCheckForError(canSrc, "TX", &canSendError, 0) != canLEVEL_ACTIVE) {
- break;
- }
- canTransmit(canSrc, canMsgBox, tx_data);
- if (xSemaphoreTake(canMsgSent, 100/portTICK_RATE_MS) == pdFALSE) {
- txTimeOutCnt++;
- }
- else {
- if (canCheckForError(canSrc, "TX", &canSendError, 0) & canLEVEL_BUS_OFF) {
- break;
- }
- else {
- messagesTransmitted++;
- if (xSemaphoreTake(canMsgReceived, 100/portTICK_RATE_MS) == pdFALSE) {
- rxTimeOutCnt++;
- }
- else {
- if (canGetData(canDst, canMsgBox, rx_data))
- messagesReceived++;
-
- if (canCheckForError(canDst, "RX", &canRecError, 0) & canLEVEL_BUS_OFF) {
- break;
- }
- }
- }
- }
- }
- print((uint8_t *)"CAN final error state:\r\n");
- canCheckForError(canSrc, "TX", &canSendError, 1);
- canCheckForError(canDst, "RX", &canRecError, 1);
- print((uint8_t *)"Messages transmitted: ");
- char errBuf[10];
- i2str(errBuf, messagesTransmitted, 1, 10);
- print((uint8_t *)errBuf);
- print((uint8_t *)"/100\r\n");
-
- print((uint8_t *)"Messages received: ");
- i2str(errBuf, messagesReceived, 1, 10);
- print((uint8_t *)errBuf);
- print((uint8_t *)"/100\r\n");
-
- print((uint8_t *)"TX timeouts: ");
- i2str(errBuf, txTimeOutCnt, 1, 10);
- print((uint8_t *)errBuf);
- print((uint8_t *)"\r\n");
-
- print((uint8_t *)"RX timeouts: ");
- i2str(errBuf, rxTimeOutCnt, 1, 10);
- print((uint8_t *)errBuf);
- print((uint8_t *)"\r\n");
-
- print((uint8_t *)"Src TX error counter: ");
- uint32_t errCnt = canSrc->EERC & 0xFFU;
- i2str(errBuf, errCnt, 1, 10);
- print((uint8_t *)errBuf);
- print((uint8_t *)"\r\n");
-
- print((uint8_t *)"Src RX error counter: ");
- errCnt = (canSrc->EERC & 0xFF00U) >> 8;
- i2str(errBuf, errCnt, 1, 10);
- print((uint8_t *)errBuf);
- print((uint8_t *)"\r\n");
-
- print((uint8_t *)"Dst TX error counter: ");
- errCnt = canDst->EERC & 0xFFU;
- i2str(errBuf, errCnt, 1, 10);
- print((uint8_t *)errBuf);
- print((uint8_t *)"\r\n");
-
- print((uint8_t *)"Dst RX error counter: ");
- errCnt = (canDst->EERC & 0xFF00U) >> 8;
- i2str(errBuf, errCnt, 1, 10);
- print((uint8_t *)errBuf);
- print((uint8_t *)"\r\n");
-
- canDisableErrorNotification(canDst);
- canDisableErrorNotification(canSrc);
- vSemaphoreDelete(canMsgReceived);
- vSemaphoreDelete(canMsgSent);
- return 0;
-}
-
-
-
-/** Runs test of HOUT. Test, weather HOUT is in fault state, which means that HOUT_DIAG is shorted to ground
- * @param[in] cmd_io Pointer to IO stack
- * @param[in] des Pointer to command descriptor
- * @param[in] param Parameters of command
- * @return 0 when OK or error code
- */
-int cmd_do_test_hout_fault(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
-{
- print((uint8_t *)"Testing fault state of HOUT port:");
- uint8_t i;
- uint32_t values[] = {1, 1, 1, 1, 1, 1};
-
- port_desc_t* inDesc = port_get_dsc(PORT_NAME_HOUTIN, -1);
- port_desc_t* diagDesc = port_get_dsc(PORT_NAME_HOUTDIAG, -1);
-
- inDesc->port_setfnc_ptr(inDesc->config, inDesc->numValues, values);
- vTaskDelay(100/portTICK_RATE_MS);
- for (i = 0; i < inDesc->numValues; i++) {
- if (hal_gpio_get_value(diagDesc->config[i]) == values[i]) {
- print((uint8_t *)"\r\nOK");
- }
- else {
- print((uint8_t *)"\r\nFAIL");
- }
- values[i] = 0;
- }
- inDesc->port_setfnc_ptr(inDesc->config, inDesc->numValues, values);
- return 0;
-}
-
-int cmd_do_test_frayA(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
-{
- print((uint8_t *)"Test fray 1, node A\r\n");
- configure_initialize_node_a(FRAY1);
- print((uint8_t *)"Initialized.\r\n");
- Fr_StartCommunication(FRAY1);
- print((uint8_t *)"Communication started.\r\n");
- while(1)
- {
- transmit_check_node_a(FRAY1);
- }
-}
-
-int cmd_do_test_frayB(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
-{
- print((uint8_t *)"Test fray 1, node B\r\n");
- configure_initialize_node_b(FRAY1);
- print((uint8_t *)"Initialized.\r\n");
- Fr_StartCommunication(FRAY1);
- print((uint8_t *)"Communication started.\r\n");
-
- while(1)
- {
- transmit_check_node_b(FRAY1);
- }
-}
-
-/* SPI Master testing command */
-#define TEST_BUF 64
-uint8_t spi_test_buf_tx[TEST_BUF];
-uint8_t spi_test_buf_rx[TEST_BUF];
-
-static int test_rd_arr(char **ps, uint8_t *buf, int n)
-{
- long val;
- int c;
- int i;
-
- if (si_fndsep(ps, "({") < 0)
- return -CMDERR_BADSEP;
- i = 0;
- si_skspace(ps);
- if ((**ps != ')') && (**ps != '}'))
- do {
- if (i >= n)
- return -CMDERR_BADPAR;
- if (si_long(ps, &val, 16) < 0)
- return -CMDERR_BADPAR;
- buf[i] = val;
- i++;
- if ((c = si_fndsep(ps, ",)}")) < 0)
- return -CMDERR_BADSEP;
- } while (c == ',');
-
- return i;
-}
-
-int spimst_print_rx(struct spi_drv *ifc, int status, int addr, uint8_t *buf)
-{
- char tmp_buff[64];
- int i;
-
- print("SPI! ");
- i2str(tmp_buff, addr, 1, 16);
- print((uint8_t*)tmp_buff);
- if (status < 0)
- print("FAIL ");
-
- print(" RX(");
- for (i = 0; i < status; i++) {
- i2str(tmp_buff, buf[i], 1, 16);
- print((uint8_t*)tmp_buff);
- print(",");
- }
- print(")");
- print("\n");
-
- return 0;
-}
-
-int cmd_do_hbr_wdg(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) {
- int ret = hbr_spi_wdg_transfer();
- char buf[16];
- i2str(buf, ret, 0, 16);
- print((uint8_t *)"SPI! RX(");
- print((uint8_t *)buf);
- print((uint8_t *)")");
- return 0;
-}
-
-
-int cmd_do_spimst(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
-{
- spi_drv_t *ifc;
- int i;
- char *p;
- long val;
- int ret;
- unsigned int addr;
- unsigned int rq_len;
-
- if (!param[1] || !isdigit(*param[1]))
- return -CMDERR_BADSUF;
-
- if (*param[2] != ':')
- return -CMDERR_OPCHAR;
-
- ifc = spi_find_drv(NULL, *param[1] - '0');
- if (ifc == NULL)
- return -CMDERR_NODEV;
-
- if (!(ifc->flags & SPI_IFC_ON)) {
- //if (spi_tms570_init(ifc) < 0)
- return -CMDERR_BADCFG;
- }
-
- p = param[3];
-
- si_skspace(&p);
- if (isdigit(*p)) {
- if (si_long(&p, &val, 16) < 0)
- return -CMDERR_BADPAR;
- addr = val;
- }
- si_skspace(&p);
- i = test_rd_arr(&p, spi_test_buf_tx, TEST_BUF);
- if (i < 0)
- return i;
- rq_len = i;
-
- ret = spi_transfer(ifc, addr, rq_len, spi_test_buf_tx, spi_test_buf_rx);
- spimst_print_rx(ifc, ret, addr, spi_test_buf_rx);
- return 0;
-}
-
-int cmd_do_hbr_pwm(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
-{
- char *p;
- int opchar;
- int i;
- uint32_t values[MAX_PARAM_VALUES_NUM];
- char buf[16];
-
- if((opchar=cmd_opchar_check(cmd_io,des,param))<0) return opchar;
-
- if(opchar==':'){
- p=param[3];
- si_skspace(&p);
- i = read_arg(&p, values, MAX_PARAM_VALUES_NUM, 10);
- if (i < 0)
- return i;
- if (i != 2)
- return -CMDERR_BADPAR;
- if (values[0] < 1 || values[1] > 100) return -CMDERR_BADPAR;
- hbr_pwm_set_signal((double)values[0], values[1]);
- return 0;
- }
- else{
- double period = hbr_pwm_get_period();
- uint32_t duty = hbr_pwm_get_duty();
-
- print((uint8_t *)"hbr_pwm_period: ");
- i2str(buf, period, 0, 10);
- print((uint8_t *)buf);
- print((uint8_t *)"\r\nhbr_pwm_duty: ");
- i2str(buf, duty, 0, 10);
- print((uint8_t *)buf);
- print((uint8_t *)"%");
- return 0;
- }
-}
-
-int cmd_do_hbr_pwm_start(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
-{
- int ret = hbr_pwm_start();
- if (ret == -1) {
- print((uint8_t*)"PWM was not initialized.\r\n");
- return -CMDERR_BADCFG;
- }
- else {
- return 0;
- }
-}
-
-int cmd_do_hbr_pwm_stop(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
-{
- hbr_pwm_stop();
- return 0;
-}
-
-int cmd_do_hout_pwm(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
-{
- char *p;
- int opchar;
- int i;
- uint32_t values[MAX_PARAM_VALUES_NUM];
- char buf[16];
- int pin;
-
- if((opchar=cmd_opchar_check(cmd_io,des,param))<0) return opchar;
-
- p=param[1];
- if(si_long(&p,(long*)&pin,0)<0) return -CMDERR_BADPAR;
- pin--;
- if (pin < 0 || pin > 5) return -CMDERR_BADPAR;
-
- if(opchar==':'){
- p=param[3];
- si_skspace(&p);
- i = read_arg(&p, values, MAX_PARAM_VALUES_NUM, 10);
- if (i < 0)
- return i;
- if (i != 2)
- return -CMDERR_BADPAR;
- if (values[0] < 1 || values[1] > 100) return -CMDERR_BADPAR;
- hout_pwm_set_signal(pin, (double)values[0], values[1]);
- return 0;
- }
- else{
- double period = hout_pwm_get_period(pin);
- uint32_t duty = hout_pwm_get_duty(pin);
-
- print((uint8_t *)"hout");
- i2str(buf, pin, 0, 10);
- print((uint8_t *)"_pwm_period: ");
- i2str(buf, period, 0, 10);
- print((uint8_t *)buf);
- print((uint8_t *)"\r\nhout");
- i2str(buf, pin, 0, 10);
- print((uint8_t *)"_pwm_duty: ");
- i2str(buf, duty, 0, 10);
- print((uint8_t *)buf);
- print((uint8_t *)"%");
- return 0;
- }
-}
-
-int cmd_do_hout_pwm_start(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
-{
- char* p;
- int pin;
-
- p=param[1];
- if(si_long(&p,(long*)&pin,0)<0) return -CMDERR_BADPAR;
- pin--;
- if (pin < 0 || pin > 5) return -CMDERR_BADPAR;
- int ret = hout_pwm_start(pin);
- if (ret == -1) {
- print((uint8_t*)"PWM was not initialized.\r\n");
- return -CMDERR_BADCFG;
- }
- else {
- return 0;
- }
-}
-
-int cmd_do_hout_pwm_stop(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
-{
- char* p;
- int pin;
-
- p=param[1];
- if(si_long(&p,(long*)&pin,0)<0) return -CMDERR_BADPAR;
- pin--;
- if (pin < 0 || pin > 5) return -CMDERR_BADPAR;
- hout_pwm_stop(pin);
- return 0;
-}
-
-/* ------------------------------
- * User defined command variables
- * ------------------------------
- */
-
-/* -------------------
- * Command definitions
- * -------------------
- */
-
+/** Command descriptor for sleep command */
cmd_des_t const cmd_des_sleep={
0, 0,
"sleep","Sleep the board",
cmd_do_sleep, (void *)&cmd_list
};
-cmd_des_t const cmd_des_vbat1_set_bit={
- 0, 0,
- "vbat1set","Set VBAT1_EN using PWM",
- cmd_do_vbat1_set_bit, (void *)&cmd_list
-};
-
-cmd_des_t const cmd_des_vbat1_clr_bit={
- 0, 0,
- "vbat1clr","Clear VBAT1_EN",
- cmd_do_vbat1_clr_bit, (void *)&cmd_list
-};
-
-cmd_des_t const cmd_des_power_on = {
- 0, 0,
- "poweron","Set VBATEN and VBAT1EN using PWM",
- cmd_do_power_on, (void *)&cmd_list
-};
-
-cmd_des_t const cmd_des_power_off = {
- 0, 0,
- "poweroff","Clear VBATEN and VBAT1EN",
- cmd_do_power_off, (void *)&cmd_list
-};
-
-cmd_des_t const cmd_des_lout_wr={
- 0, CDESM_OPCHR|CDESM_RW,
- "loutwr","\tloutwr:(wr) - writes word wr in LOUT\r\n\t\tloutwr? - reads word from LOUT",
- cmd_do_lout_wr, (void *)&cmd_list
-};
-
-/** @brief command descriptor for din state command */
-cmd_des_t const cmd_des_din_st_word={
- 0, CDESM_OPCHR|CDESM_WR,
- "dinportst","\tdinportst:(wrsg,wrsp) - writes word wr (8b) into din sg and sp. 1 - tri-state, 0 - active.",
- cmd_do_din_st_wr, (void *)&cmd_list
-};
-
-/** @brief command descriptor for din switch-to-ground/battery command */
-cmd_des_t const cmd_des_din_pr_word={
- 0, CDESM_OPCHR|CDESM_WR,
- "dinportpr","\tdinportpr:(wr) - writes word wr (8b) into din. 1 - switch-to-bat, 0 - switch-to-gnd.",
- cmd_do_din_pr_wr, (void *)&cmd_list
-};
-
-/** @brief command descriptor for din enable interrupts command */
-cmd_des_t const cmd_des_din_int_word={
- 0, CDESM_OPCHR|CDESM_WR,
- "dinportint","\tdinportint:(wrsg, wrsp) - writes word wr (16b) into din sg and sp. 1 - enable interrupt, 0 - disable interrupt.",
- cmd_do_din_int_wr, (void *)&cmd_list
-};
-
-/** @brief command descriptor for din reset command */
-cmd_des_t const cmd_des_din_rst={
- 0, 0,
- "dinreset","\tdinreset - send reset command to DIN",
- cmd_do_din_reset, (void *)&cmd_list
-};
-
-/** @brief command descriptor for din switch state command */
-cmd_des_t const cmd_des_din_sw_st={
- 0, 0,
- "dinswst","\tdinswst - Send switch status to DIN",
- cmd_do_din_switch_st, (void *)&cmd_list
-};
-
-/** @brief command descriptor for din get value command */
-cmd_des_t const cmd_des_din_val_word={
- 0, CDESM_OPCHR|CDESM_RD,
- "dinportval","\tdinportval? - reads values from DIN port as 16b word",
- cmd_do_din_val_word, (void *)&cmd_list
-};
-
-/** @brief command descriptor for din get state command */
-cmd_des_t const cmd_des_din_stat={
- 0, 0,
- "dinstat","\tdinstat - get DIN status in human readable form",
- cmd_do_din_status, (void *)&cmd_list
-};
-
-cmd_des_t const cmd_des_lout_val={
- 0, CDESM_OPCHR|CDESM_RW,
- "loutval#","\tloutvalX:Y - writes bit Y on LOUTX\r\n\t\tloutvalX? - reads bit from LOUTX",
- cmd_do_lout_val, (void *)&cmd_list
-};
-
-cmd_des_t const cmd_des_lout_status={
- 0, 0,
- "loutstat","get LOUT status in human readable format",
- cmd_do_lout_status, (void *)&cmd_list
- };
-
-cmd_des_t const cmd_des_dac_on={
- 0, CDESM_OPCHR|CDESM_RW,
- "dacpinon#","\tdacpinonX:Y - if Y=1, turns DACX ON, if Y=0, turns DACX OFF\r\n\t\tdacpinonX? - reads status of DACX (1=ON, 0=OFF)\r\n\t\tX = <1;4>",
- cmd_do_dac_pin_on, (void *)&cmd_list
-};
-
-cmd_des_t const cmd_des_dac_stat={
- 0, 0,
- "dacstat","\tdacstat - Reads status of each DAC",
- cmd_do_dac_stat, (void *)&cmd_list
-};
-
-cmd_des_t const cmd_des_dac_val={
- 0, CDESM_OPCHR|CDESM_RW,
- "dacpinval#","\tdacpinvalX:Y - DACX <- Y mV\r\n\t\tdacpinvalX? - Get DACX voltage in mV\r\n\t\tX = <1;4>",
- cmd_do_dac_pin_value, (void *)&cmd_list
-};
-
-cmd_des_t const cmd_des_fray_stat={
- 0, 0,
- "fraystat#","\tget FRAYX status in human readable form",
- cmd_do_fray_status, (void *)&cmd_list
-};
-
-cmd_des_t const cmd_des_pin_list = {
- 0, 0,
- "pinlist","Prints list of all defined pins",
- cmd_do_pin_list, (void *)&cmd_list
-};
-
-/** @brief command descriptor for test SDRAM */
-cmd_des_t const cmd_des_test_sdram={
- 0, 0,
- "testsdram","Test if SDRAM module is connected and if it is, measure capacity",
- cmd_do_test_ram, (void *)&cmd_list
-};
-
-
-/** @brief command descriptor for test CAN loopback command */
-cmd_des_t const cmd_des_test_can_loopback={
- 0, 0,
- "testcan","testcan src<1;3> dest<1;3> Test CAN loopback between src and dest.",
- cmd_do_test_can_loopback, (void *)&cmd_list
-};
-
-cmd_des_t const cmd_des_lin_loop_back={
- 0, 0,
- "testlin","Test digital loopback on LIN",
- cmd_do_lin_loop_back, (void *)&cmd_list
-};
-
-/** @brief command descriptor for test hout fault state command */
-cmd_des_t const cmd_des_test_ethernet = {
- 0, 0,
- "houtfail","Test if some HOUT port is in fault state",
- cmd_do_test_hout_fault, (void *)&cmd_list
-};
-cmd_des_t const cmd_des_test_hout_fail={
- 0, 0,
- "ethernet", "Try to send few ethernet frames",
- emac_test, (void *)&cmd_list
-};
-/** @brief command descriptor for show help command */
+/** Command descriptor for show help command */
cmd_des_t const cmd_des_help={
0, 0,
"help","prints help for commands",
cmd_do_help, (void *)&cmd_list
};
-cmd_des_t const cmd_des_hbr_wdg={
- 0, 0,
- "hbrwdg","Send repeated HBR WDG reset command",
- cmd_do_hbr_wdg, (void *)&cmd_list
-};
-
-
-cmd_des_t const cmd_des_read_adc1={
- 0, 0,
- "readadc","Reads values from ADC1",
- cmd_do_read_adc1_values, (void *)&cmd_list
-};
-
-cmd_des_t const cmd_des_read_hifbk={
- 0, 0,
- "readhifbk","Reads values from HOUT IFBK",
- cmd_do_read_hout_ifbk_values, (void *)&cmd_list
-};
-
-cmd_des_t const cmd_des_test_fray_a={
- 0, 0,
- "testfrayA","Run FlexRay test as A node",
- cmd_do_test_frayA, (void *)&cmd_list
-};
-
-cmd_des_t const cmd_des_test_fray_b={
- 0, 0,
- "testfrayB","Run FlexRay test as B node",
- cmd_do_test_frayB, (void *)&cmd_list
-};
-
-cmd_des_t const cmd_des_pin_val={
- 0, CDESM_OPCHR|CDESM_RW,
- "pinval*","Sets or get pin value",
- cmd_do_pin_val, (void *)&cmd_list
-};
-
-cmd_des_t const cmd_des_spi_translate={
- 0, CDESM_OPCHR|CDESM_RW,
- "spitr*","Translate response from SPI peripheral. spitrPERNAME?(CMD, RESP)",
- cmd_do_spi_translate, (void *)&cmd_list
-};
-
-cmd_des_t const cmd_des_spimst = { 0, CDESM_OPCHR,
- "spimst#", "SPI master communication request",
- cmd_do_spimst, (void *)&cmd_list
-};
-
-cmd_des_t const cmd_des_pin_dir={
- 0, CDESM_OPCHR|CDESM_RW,
- "pindir*","Sets pin direction 1-out, 0-in",
- cmd_do_pin_dir, (void *)&cmd_list
-};
-
-/** @brief command descriptor for read values from port command */
-cmd_des_t const cmd_des_port_val={
- 0, CDESM_OPCHR|CDESM_RW,
- "portval*","Read values from port",
- cmd_do_port_val, (void *)&cmd_list
-};
-
-cmd_des_t const cmd_des_hbr_pwm={
- 0, CDESM_OPCHR|CDESM_RW,
- "hbrpwm*","\t- hbrpwm:(period,duty) set pwm period in us and duty in % of period\r\n\t\thbrpwm? read period in us and duty in % of period from hbrpwm.",
- cmd_do_hbr_pwm, (void *)&cmd_list
-};
-
-cmd_des_t const cmd_des_hbr_pwm_start={
- 0, 0,
- "hbrpwmstart","\t- hbrpwmstart - Start generating of pwm signal on HBR",
- cmd_do_hbr_pwm_start, (void *)&cmd_list
-};
-
-cmd_des_t const cmd_des_hbr_pwm_stop={
- 0, 0,
- "hbrpwmstop","\t- hbrpwmstop - Stop generating of pwm signal on HBR",
- cmd_do_hbr_pwm_stop, (void *)&cmd_list
-};
-
-cmd_des_t const cmd_des_hout_pwm={
- 0, CDESM_OPCHR|CDESM_RW,
- "houtpwm*","\t- houtpwmX:(period,duty) set pwm period in us and duty in % of period\r\n\t\thoutpwmX? read period in us and duty in % of period from HOUTX.",
- cmd_do_hout_pwm, (void *)&cmd_list
-};
-
-cmd_des_t const cmd_des_hout_pwm_start={
- 0, 0,
- "houtpwmstart#","\t- houtpwmstartX - Start generating of pwm signal on HOUTX",
- cmd_do_hout_pwm_start, (void *)&cmd_list
-};
-
-cmd_des_t const cmd_des_hout_pwm_stop={
- 0, 0,
- "houtpwmstop#","\t- houtpwmstopX - Stop generating of pwm signal on HOUTX",
- cmd_do_hout_pwm_stop, (void *)&cmd_list
-};
-
/* ------------------------
* Command lists definitons
* ------------------------
*/
-cmd_des_t const *cmd_list_lowlevel[]={
- &cmd_des_pin_val,
- &cmd_des_pin_dir,
- &cmd_des_pin_list,
- &cmd_des_port_val,
- &cmd_des_spimst,
- &cmd_des_spi_translate,
- &cmd_des_hbr_pwm,
- &cmd_des_hbr_pwm_start,
- &cmd_des_hbr_pwm_stop,
- &cmd_des_hout_pwm,
- &cmd_des_hout_pwm_start,
- &cmd_des_hout_pwm_stop,
- NULL
-};
-
/** @brief Main list of commands */
cmd_des_t const *cmd_list_main[]={
&cmd_des_help,
- &cmd_des_read_adc1,
- &cmd_des_read_hifbk,
- &cmd_des_lin_loop_back,
- &cmd_des_test_can_loopback,
- &cmd_des_test_sdram,
- &cmd_des_test_hout_fail,
- &cmd_des_test_ethernet,
- &cmd_des_test_fray_a,
- &cmd_des_test_fray_b,
- &cmd_des_hbr_wdg,
&cmd_des_sleep,
- &cmd_des_power_on,
- &cmd_des_power_off,
- &cmd_des_lout_wr,
- &cmd_des_lout_val,
- &cmd_des_lout_status,
- &cmd_des_din_rst,
- &cmd_des_din_sw_st,
- &cmd_des_din_stat,
- &cmd_des_din_pr_word,
- &cmd_des_din_st_word,
- &cmd_des_din_int_word,
- &cmd_des_din_val_word,
- &cmd_des_dac_on,
- &cmd_des_dac_stat,
- &cmd_des_dac_val,
- &cmd_des_fray_stat,
- &cmd_des_vbat1_set_bit,
- &cmd_des_vbat1_clr_bit,
- CMD_DES_INCLUDE_SUBLIST(cmd_list_lowlevel),
+ CMD_DES_INCLUDE_SUBLIST(cmd_list_adc),
+ CMD_DES_INCLUDE_SUBLIST(cmd_list_can),
+ CMD_DES_INCLUDE_SUBLIST(cmd_list_dac),
+ CMD_DES_INCLUDE_SUBLIST(cmd_list_din),
+ CMD_DES_INCLUDE_SUBLIST(cmd_list_emac),
+ CMD_DES_INCLUDE_SUBLIST(cmd_list_fray),
+ CMD_DES_INCLUDE_SUBLIST(cmd_list_hbr),
+ CMD_DES_INCLUDE_SUBLIST(cmd_list_hout),
+ CMD_DES_INCLUDE_SUBLIST(cmd_list_lin),
+ CMD_DES_INCLUDE_SUBLIST(cmd_list_lout),
+ CMD_DES_INCLUDE_SUBLIST(cmd_list_pin),
+ CMD_DES_INCLUDE_SUBLIST(cmd_list_port),
+ CMD_DES_INCLUDE_SUBLIST(cmd_list_sdram),
+ CMD_DES_INCLUDE_SUBLIST(cmd_list_spi),
+ CMD_DES_INCLUDE_SUBLIST(cmd_list_vbat),
NULL
};
-/** @brief pointer to the main list */
+/** Pointer to the root list */
cmd_des_t const **cmd_list = cmd_list_main;
* This file contains low level and high level functions for reading from ADC.
* One function for reading from ADC port on the board is also defined.
*/
-#include "adc_drv.h"
+#include "drv_adc.h"
/** @brief Semaphore blocking task when it waits for interrupt signaling end of the conversion */
xSemaphoreHandle adcDataConverted;
*/
-#include "dac_spi.h"
+#include "drv_dac.h"
/** Pin status for each DAC pin, the structure of each field is defined as spi command structure. */
uint16_t dac_pin_stat[DAC_PIN_NUM] = { DAC1_INIT_VAL,
* interrupts on each pins can be disabled and enabled
*/
-#include "din_spi.h"
+#include "drv_din.h"
/** Prepared command */
uint32_t din_spi_cmd = DIN_SPICMD_INIT_VAL;
* Flexray chips on SPI are read only.
*/
-#include "fray_spi.h"
+#include "drv_fray.h"
/** Prepared spi command */
uint32_t fray_spi_cmd = FRAY_SPICMD_INIT_VAL;
//TODO: HBR_DIR and HBR_EN toggling
-#include "hbridge.h"
+#include "drv_hbridge.h"
/** Flag variable if watchdog command has been sent one before **/
static char hbr_spi_initialized;
*
* Functions for setting, starting and stopping PWM on selected HOUT pin.
*/
-#include "hout.h"
+#include "drv_hout.h"
/** PWM modules from N2HET mapped to HOUT pin ID 0-5 **/
static uint8_t hout_pwm_map[PORT_NV_HOUTIN] = {pwm1, pwm2, pwm3, pwm4, pwm5, pwm6};
* This file contains functions to control LOUT port over SPI
*/
-#include "lout_spi.h"
+#include "drv_lout.h"
/** Prepared spi command */
uint32_t lout_spi_cmd = LOUT_SPICMD_INIT_VAL;
-#include "sys_common.h"
+//#include "sys_common.h"
#include "ul_list.h"
-#include "spi_drv.h"
+#include "drv_spi.h"
#include "cpu_def.h"
int spi_msg_rq_ins(spi_drv_t *ifc, spi_msg_head_t *msg)
\r
/* Include Files */\r
\r
-#include "esm.h"\r
+#include "ti_drv_esm.h"\r
#include "sys_selftest.h"\r
-#include "adc.h"\r
-#include "can.h"\r
-#include "gio.h"\r
-#include "lin.h"\r
-#include "mibspi.h"\r
-#include "sci.h"\r
-#include "het.h"\r
-#include "i2c.h"\r
+#include "ti_drv_adc.h"\r
+#include "ti_drv_can.h"\r
+#include "ti_drv_gio.h"\r
+#include "ti_drv_lin.h"\r
+#include "ti_drv_mibspi.h"\r
+#include "ti_drv_sci.h"\r
+#include "ti_drv_het.h"\r
+#include "ti_drv_i2c.h"\r
/* USER CODE BEGIN (0) */\r
#include "FreeRTOS.h"\r
#include "os_semphr.h"\r
extern xSemaphoreHandle canMsgReceived;\r
extern xSemaphoreHandle canMsgSent;\r
\r
-extern xSemaphoreHandle linMsgReceived;\r
-extern xSemaphoreHandle linIDReceived;\r
-\r
/** @brief Data structure containing converted data from ADC\r
*\r
* Defined in commands.c */\r
/* USER CODE BEGIN (21) */\r
/* USER CODE END */\r
\r
-}\r
-void linNotification(linBASE_t *lin, uint32_t flags) \r
-{\r
-/* USER CODE BEGIN (23) */\r
- if (flags & LIN_ID_INT) {\r
- xSemaphoreGiveFromISR(linIDReceived, NULL);\r
- }\r
- if (flags & LIN_RX_INT) {\r
- lin->FLR |= (1 << 9);\r
- xSemaphoreGiveFromISR(linMsgReceived, NULL);\r
- }\r
-/* USER CODE END */\r
-\r
}\r
\r
/* USER CODE BEGIN (24) */\r
#include "sys_common.h"
-#include "emac.h"
-#include "mdio.h"
+#include "ti_drv_emac.h"
+#include "ti_drv_mdio.h"
#include "hw_mdio.h"
#include "hw_emac.h"
*/
#include "port_def.h"
-#include "adc_drv.h"
+#include "drv_adc.h"
#include "port_spi.h"
#include "port_gpio.h"
*/
#include "port_spi.h"
-#include "spi_drv.h"
+#include "drv_spi.h"
#include "cmd_proc.h"
#define PORT_BUF 4
/* Code based on Halcogen generated source code */
#include "spi_tms570.h"
-#include "spi_drv.h"
-#include "sys_common.h"
-#include "dmm.h"
+#include "drv_spi.h"
+//#include "sys_common.h"
+#include "ti_drv_dmm.h"
static int spi_tms570_ctrl_fnc(spi_drv_t *ifc, int ctrl, void *p);
#include "cmd_proc_freertos_tms570.h"\r
#include "FreeRTOS.h"\r
#include "os_task.h"\r
-#include "can.h"\r
-#include "adc.h"\r
-#include "gio.h"\r
-#include "het.h"\r
-#include "emif.h"\r
-#include "dmm.h"\r
-#include "lin.h"\r
-#include "emac_test.h"\r
+#include "ti_drv_can.h"\r
+#include "ti_drv_adc.h"\r
+#include "ti_drv_gio.h"\r
+#include "ti_drv_het.h"\r
+#include "ti_drv_emif.h"\r
+#include "ti_drv_dmm.h"\r
+#include "ti_drv_lin.h"\r
+#include "cmd_emac.h"\r
#include "spi_tms570.h"\r
-#include "spi_drv.h"\r
+#include "drv_spi.h"\r
/* USER CODE END */\r
\r
\r
#include "sys_vim.h"\r
#include "sys_core.h"\r
#include "sys_selftest.h"\r
-#include "esm.h"\r
+#include "ti_drv_esm.h"\r
\r
\r
/* USER CODE BEGIN (1) */\r
\r
/* Include Files */\r
\r
-#include "adc.h"\r
+#include "ti_drv_adc.h"\r
\r
/* USER CODE BEGIN (1) */\r
/* USER CODE END */\r
\r
/* Include Files */\r
\r
-#include "can.h"\r
+#include "ti_drv_can.h"\r
\r
/* USER CODE BEGIN (1) */\r
/* USER CODE END */\r
/* (c) Texas Instruments 2009-2010, All rights reserved. */\r
\r
\r
-#include "dma.h"\r
+#include "ti_drv_dma.h"\r
\r
g_dmaCTRL g_dmaCTRLPKT;\r
\r
/* USER CODE BEGIN (0) */\r
/* USER CODE END */\r
\r
-#include "dmm.h"\r
+#include "ti_drv_dmm.h"\r
\r
/* USER CODE BEGIN (1) */\r
/* USER CODE END */\r
\r
#include "sys_common.h"\r
#include "hw_reg_access.h"\r
-#include "emac.h"\r
+#include "ti_drv_emac.h"\r
#include "hw_emac.h"\r
#include "hw_emac_ctrl.h"\r
\r
\r
\r
#include "system.h"\r
-#include "emif.h"\r
+#include "ti_drv_emif.h"\r
\r
/** @fn void emif_SDRAMInit()\r
* @brief Initializes the emif Driver for SDRAM\r
\r
/* Include Files */\r
\r
-#include "esm.h"\r
+#include "ti_drv_esm.h"\r
\r
/* USER CODE BEGIN (1) */\r
/* USER CODE END */\r
/* USER CODE BEGIN (0) */\r
/* USER CODE END */\r
\r
-#include "gio.h"\r
+#include "ti_drv_gio.h"\r
\r
/* USER CODE BEGIN (1) */\r
/* USER CODE END */\r
\r
/* (c) Texas Instruments 2009-2012, All rights reserved. */\r
\r
-#include "het.h"\r
+#include "ti_drv_het.h"\r
\r
/* USER CODE BEGIN (0) */\r
/* USER CODE END */\r
/* USER CODE BEGIN (0) */\r
/* USER CODE END */\r
\r
-#include "i2c.h"\r
+#include "ti_drv_i2c.h"\r
\r
/* USER CODE BEGIN (1) */\r
/* USER CODE END */\r
/* USER CODE BEGIN (0) */\r
/* USER CODE END */\r
\r
-#include "lin.h"\r
+#include "ti_drv_lin.h"\r
\r
/* USER CODE BEGIN (1) */\r
/* USER CODE END */\r
\r
#include "sys_common.h"\r
#include "hw_reg_access.h"\r
-#include "mdio.h"\r
+#include "ti_drv_mdio.h"\r
#include "hw_mdio.h"\r
\r
/*******************************************************************************\r
/* USER CODE BEGIN (0) */\r
/* USER CODE END */\r
\r
-#include "mibspi.h"\r
+#include "ti_drv_mibspi.h"\r
\r
/* USER CODE BEGIN (1) */\r
/* USER CODE END */\r
/* USER CODE BEGIN (0) */\r
/* USER CODE END */\r
\r
-#include "sci.h"\r
+#include "ti_drv_sci.h"\r
\r
/* USER CODE BEGIN (1) */\r
#include "cmdio_tisci.h"\r
*******************************************************************/
#include <stdint.h>
-//#include <system_def.h>
#include <string.h>
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include <cmd_proc.h>
-#include <sys_common.h>
/* string parse and input routines */