From ab36342d60bb6fa7039a43b12692f9ce27add8ce Mon Sep 17 00:00:00 2001 From: Michal Horn Date: Thu, 28 Feb 2013 23:43:49 +0100 Subject: [PATCH] Source and Header files modified Commands from commands.c moved to their cmd_peripheral.c files Each periperal division has its sublist, which is defined as external and connected together in root list in commands.c --- include/FlexRay.h | 2 +- include/Fr.h | 3 + include/cmd_adc.h | 5 +- include/cmd_can.h | 5 +- include/cmd_dac.h | 5 +- include/cmd_din.h | 5 +- include/cmd_emac.h | 8 +- include/cmd_fray.h | 5 +- include/cmd_hbr.h | 5 +- include/cmd_hout.h | 5 +- include/cmd_lin.h | 4 +- include/cmd_lout.h | 5 +- include/cmd_pin.h | 5 +- include/cmd_port.h | 5 +- include/cmd_proc_freertos_tms570.h | 2 +- include/cmd_sdram.h | 3 + include/cmd_spi.h | 5 +- include/cmd_vbat.h | 5 +- include/cmdio_tisci.h | 2 +- include/drv_adc.h | 2 +- include/drv_fray.h | 1 + include/drv_hbridge.h | 4 +- include/drv_hout.h | 2 +- include/hal_gpio_tms570_def.h | 6 +- include/spi_tms570.h | 4 +- include/sys_selftest.h | 12 +- include/system.h | 2 +- include/ti_drv_dmm.h | 2 +- include/ti_drv_het.h | 2 +- include/ti_drv_i2c.h | 2 +- include/ti_drv_lin.h | 2 +- include/ti_drv_mibspi.h | 2 +- include/ti_drv_sci.h | 2 +- include/utils.h | 1 + source/cmd_adc.c | 56 +- source/cmd_can.c | 277 ++++- source/cmd_dac.c | 142 ++- source/cmd_din.c | 295 ++++- source/cmd_emac.c | 21 +- source/cmd_fray.c | 139 ++- source/cmd_hbr.c | 158 ++- source/cmd_hout.c | 237 +++- source/cmd_lin.c | 104 +- source/cmd_lout.c | 152 ++- source/cmd_pin.c | 144 ++- source/cmd_port.c | 83 +- source/cmd_sdram.c | 73 +- source/cmd_spi.c | 202 +++- source/cmd_vbat.c | 116 +- source/commands.c | 1741 +--------------------------- source/drv_adc.c | 2 +- source/drv_dac.c | 2 +- source/drv_din.c | 2 +- source/drv_fray.c | 2 +- source/drv_hbridge.c | 2 +- source/drv_hout.c | 2 +- source/drv_lout.c | 2 +- source/drv_spi.c | 4 +- source/notification.c | 34 +- source/phy.c | 4 +- source/port_def.c | 2 +- source/port_spi.c | 2 +- source/spi_tms570.c | 6 +- source/sys_main.c | 18 +- source/sys_startup.c | 2 +- source/ti_drv_adc.c | 2 +- source/ti_drv_can.c | 2 +- source/ti_drv_dma.c | 2 +- source/ti_drv_dmm.c | 2 +- source/ti_drv_emac.c | 2 +- source/ti_drv_emif.c | 2 +- source/ti_drv_esm.c | 2 +- source/ti_drv_gio.c | 2 +- source/ti_drv_het.c | 2 +- source/ti_drv_i2c.c | 2 +- source/ti_drv_lin.c | 2 +- source/ti_drv_mdio.c | 2 +- source/ti_drv_mibspi.c | 2 +- source/ti_drv_sci.c | 2 +- source/utils.c | 2 - 80 files changed, 2367 insertions(+), 1819 deletions(-) diff --git a/include/FlexRay.h b/include/FlexRay.h index 49a96c2..2d6affd 100644 --- a/include/FlexRay.h +++ b/include/FlexRay.h @@ -2,7 +2,7 @@ * FlexRay.h * * Created on: 29.11.2012 - * Author: michal + * Author: Michal Horn */ #ifndef FLEXRAY_H_ diff --git a/include/Fr.h b/include/Fr.h index fad4c98..82455f4 100644 --- a/include/Fr.h +++ b/include/Fr.h @@ -8,6 +8,8 @@ * *******************************************************************/ +#ifndef _FE_H_ +#define _FE_H_ #define FRAY1 (&e_FRAY0_ST) #define FRAY2 (&e_FRAY1_ST) @@ -1374,3 +1376,4 @@ int Fr_StartCommunication(FRAY_ST *Fray_PST); void Fr_TransmitTxLPdu(FRAY_ST *Fray_PST, bc *Fr_LSduPtr); void Fr_ReceiveRxLPdu(FRAY_ST *Fray_PST, bc *Fr_LSduPtr); +#endif //_FE_H_ diff --git a/include/cmd_adc.h b/include/cmd_adc.h index 161c5e3..df298f5 100644 --- a/include/cmd_adc.h +++ b/include/cmd_adc.h @@ -2,12 +2,15 @@ * 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_ */ diff --git a/include/cmd_can.h b/include/cmd_can.h index 7c2788f..c670198 100644 --- a/include/cmd_can.h +++ b/include/cmd_can.h @@ -2,12 +2,15 @@ * 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_ */ diff --git a/include/cmd_dac.h b/include/cmd_dac.h index 489b70f..5946f9a 100644 --- a/include/cmd_dac.h +++ b/include/cmd_dac.h @@ -2,12 +2,15 @@ * 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_ */ diff --git a/include/cmd_din.h b/include/cmd_din.h index f68ed0b..4118269 100644 --- a/include/cmd_din.h +++ b/include/cmd_din.h @@ -2,12 +2,15 @@ * 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_ */ diff --git a/include/cmd_emac.h b/include/cmd_emac.h index 975d930..ad0b995 100644 --- a/include/cmd_emac.h +++ b/include/cmd_emac.h @@ -1,6 +1,9 @@ #ifndef _EMAC_TEST_H_ #define _EMAC_TEST_H_ +#include "cmd_proc.h" +#include "sys_common.h" + /* ************************************************* */ /* Emac frame buffer related stuff */ /* ************************************************* */ @@ -31,5 +34,8 @@ typedef struct { } 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_ */ diff --git a/include/cmd_fray.h b/include/cmd_fray.h index c708849..c0ce44f 100644 --- a/include/cmd_fray.h +++ b/include/cmd_fray.h @@ -2,12 +2,15 @@ * 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_ */ diff --git a/include/cmd_hbr.h b/include/cmd_hbr.h index 83369ca..a580abd 100644 --- a/include/cmd_hbr.h +++ b/include/cmd_hbr.h @@ -2,12 +2,15 @@ * 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_ */ diff --git a/include/cmd_hout.h b/include/cmd_hout.h index 4afdd3e..495e3bf 100644 --- a/include/cmd_hout.h +++ b/include/cmd_hout.h @@ -2,12 +2,15 @@ * 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_ */ diff --git a/include/cmd_lin.h b/include/cmd_lin.h index 7bde706..e86f4d4 100644 --- a/include/cmd_lin.h +++ b/include/cmd_lin.h @@ -2,12 +2,14 @@ * 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_ */ diff --git a/include/cmd_lout.h b/include/cmd_lout.h index 8c98143..55e4086 100644 --- a/include/cmd_lout.h +++ b/include/cmd_lout.h @@ -2,12 +2,15 @@ * 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_ */ diff --git a/include/cmd_pin.h b/include/cmd_pin.h index bf2d70c..4a181a8 100644 --- a/include/cmd_pin.h +++ b/include/cmd_pin.h @@ -2,12 +2,15 @@ * 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_ */ diff --git a/include/cmd_port.h b/include/cmd_port.h index 1d89c73..56fc320 100644 --- a/include/cmd_port.h +++ b/include/cmd_port.h @@ -2,12 +2,15 @@ * 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_ */ diff --git a/include/cmd_proc_freertos_tms570.h b/include/cmd_proc_freertos_tms570.h index be11c44..24421e1 100644 --- a/include/cmd_proc_freertos_tms570.h +++ b/include/cmd_proc_freertos_tms570.h @@ -13,7 +13,7 @@ #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" diff --git a/include/cmd_sdram.h b/include/cmd_sdram.h index fab1132..e9b3a72 100644 --- a/include/cmd_sdram.h +++ b/include/cmd_sdram.h @@ -8,6 +8,9 @@ #ifndef CMD_SDRAM_H_ #define CMD_SDRAM_H_ +#include "cmd_proc.h" + +extern cmd_des_t const *cmd_list_sdram[]; #endif /* CMD_SDRAM_H_ */ diff --git a/include/cmd_spi.h b/include/cmd_spi.h index d080aad..13e3f24 100644 --- a/include/cmd_spi.h +++ b/include/cmd_spi.h @@ -2,12 +2,15 @@ * 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_ */ diff --git a/include/cmd_vbat.h b/include/cmd_vbat.h index cbfd195..59bc886 100644 --- a/include/cmd_vbat.h +++ b/include/cmd_vbat.h @@ -2,12 +2,15 @@ * 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_ */ diff --git a/include/cmdio_tisci.h b/include/cmdio_tisci.h index d4ae721..247403e 100644 --- a/include/cmdio_tisci.h +++ b/include/cmdio_tisci.h @@ -15,7 +15,7 @@ #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 diff --git a/include/drv_adc.h b/include/drv_adc.h index 0891e8f..c1b537c 100644 --- a/include/drv_adc.h +++ b/include/drv_adc.h @@ -8,7 +8,7 @@ #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" diff --git a/include/drv_fray.h b/include/drv_fray.h index a07ad1b..fac1f4b 100644 --- a/include/drv_fray.h +++ b/include/drv_fray.h @@ -9,6 +9,7 @@ #define FRAY_SPI_H_ #include "port_def.h" + #define FRAY_SPICMD_INIT_VAL 0xFFFF #define FRAY_NUM_PORTS 2 diff --git a/include/drv_hbridge.h b/include/drv_hbridge.h index 34fed35..daadd8a 100644 --- a/include/drv_hbridge.h +++ b/include/drv_hbridge.h @@ -7,10 +7,10 @@ #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(); diff --git a/include/drv_hout.h b/include/drv_hout.h index ed35797..3ad3440 100644 --- a/include/drv_hout.h +++ b/include/drv_hout.h @@ -8,7 +8,7 @@ #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); diff --git a/include/hal_gpio_tms570_def.h b/include/hal_gpio_tms570_def.h index 2e7ff72..8f4f0d2 100644 --- a/include/hal_gpio_tms570_def.h +++ b/include/hal_gpio_tms570_def.h @@ -8,9 +8,9 @@ #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 diff --git a/include/spi_tms570.h b/include/spi_tms570.h index b9257cf..101b77c 100644 --- a/include/spi_tms570.h +++ b/include/spi_tms570.h @@ -1,8 +1,8 @@ #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) diff --git a/include/sys_selftest.h b/include/sys_selftest.h index a471eee..e3f189c 100644 --- a/include/sys_selftest.h +++ b/include/sys_selftest.h @@ -18,12 +18,12 @@ #include "sys_core.h" #include "system.h" #include "sys_vim.h" -#include "adc.h" -#include "can.h" -#include "mibspi.h" -#include "het.h" -#include "htu.h" -#include "esm.h" +#include "ti_drv_adc.h" +#include "ti_drv_can.h" +#include "ti_drv_mibspi.h" +#include "ti_drv_het.h" +#include "ti_drv_htu.h" +#include "ti_drv_esm.h" /* USER CODE BEGIN (0) */ /* USER CODE END */ diff --git a/include/system.h b/include/system.h index 7e68e08..4f69fac 100644 --- a/include/system.h +++ b/include/system.h @@ -16,7 +16,7 @@ #define __SYS_SYSTEM_H__ #include "sys_common.h" -#include "gio.h" +#include "ti_drv_gio.h" /* USER CODE BEGIN (0) */ diff --git a/include/ti_drv_dmm.h b/include/ti_drv_dmm.h index 6bad17c..b3e87de 100644 --- a/include/ti_drv_dmm.h +++ b/include/ti_drv_dmm.h @@ -12,7 +12,7 @@ #define __DMM_H__ #include "sys_common.h" -#include "gio.h" +#include "ti_drv_gio.h" #define DMM_SYNC 0 #define DMM_CLK 1 diff --git a/include/ti_drv_het.h b/include/ti_drv_het.h index e2bbcbe..a0cc38e 100644 --- a/include/ti_drv_het.h +++ b/include/ti_drv_het.h @@ -12,7 +12,7 @@ #define __HET_H__ #include "sys_common.h" -#include "gio.h" +#include "ti_drv_gio.h" #include /* USER CODE BEGIN (0) */ diff --git a/include/ti_drv_i2c.h b/include/ti_drv_i2c.h index 8918e3e..ccc6423 100644 --- a/include/ti_drv_i2c.h +++ b/include/ti_drv_i2c.h @@ -12,7 +12,7 @@ #include "sys_common.h" -#include "gio.h" +#include "ti_drv_gio.h" /** @enum i2cMode diff --git a/include/ti_drv_lin.h b/include/ti_drv_lin.h index 4eab4e1..98633cf 100644 --- a/include/ti_drv_lin.h +++ b/include/ti_drv_lin.h @@ -12,7 +12,7 @@ #define __LIN_H__ #include "sys_common.h" -#include "gio.h" +#include "ti_drv_gio.h" /** @def LIN_BREAK_INT diff --git a/include/ti_drv_mibspi.h b/include/ti_drv_mibspi.h index 0c0c131..583d66d 100644 --- a/include/ti_drv_mibspi.h +++ b/include/ti_drv_mibspi.h @@ -12,7 +12,7 @@ #define __MIBSPI_H__ #include "sys_common.h" -#include "gio.h" +#include "ti_drv_gio.h" /** @enum triggerEvent diff --git a/include/ti_drv_sci.h b/include/ti_drv_sci.h index d7e08d3..b6171af 100644 --- a/include/ti_drv_sci.h +++ b/include/ti_drv_sci.h @@ -12,7 +12,7 @@ #define __SCI_H__ #include "sys_common.h" -#include "gio.h" +#include "ti_drv_gio.h" /** @enum sciIntFlags diff --git a/include/utils.h b/include/utils.h index b76dabc..942499c 100644 --- a/include/utils.h +++ b/include/utils.h @@ -6,6 +6,7 @@ #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); diff --git a/source/cmd_adc.c b/source/cmd_adc.c index d26ea5a..df5a4c7 100644 --- a/source/cmd_adc.c +++ b/source/cmd_adc.c @@ -2,7 +2,61 @@ * 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 +}; diff --git a/source/cmd_can.c b/source/cmd_can.c index 72d8bba..a5b6cf5 100644 --- a/source/cmd_can.c +++ b/source/cmd_can.c @@ -2,7 +2,282 @@ * 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 +}; diff --git a/source/cmd_dac.c b/source/cmd_dac.c index fbf7a03..f8481ce 100644 --- a/source/cmd_dac.c +++ b/source/cmd_dac.c @@ -2,7 +2,147 @@ * 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 +}; diff --git a/source/cmd_din.c b/source/cmd_din.c index ea1aee1..7996e9a 100644 --- a/source/cmd_din.c +++ b/source/cmd_din.c @@ -2,7 +2,300 @@ * 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 +}; diff --git a/source/cmd_emac.c b/source/cmd_emac.c index 0d17312..08d645f 100644 --- a/source/cmd_emac.c +++ b/source/cmd_emac.c @@ -1,16 +1,18 @@ +#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; @@ -244,3 +246,14 @@ int emac_test(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) 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 +}; diff --git a/source/cmd_fray.c b/source/cmd_fray.c index 2d410ed..8d9e62d 100644 --- a/source/cmd_fray.c +++ b/source/cmd_fray.c @@ -2,7 +2,144 @@ * 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 +}; diff --git a/source/cmd_hbr.c b/source/cmd_hbr.c index 2653272..7f9b92d 100644 --- a/source/cmd_hbr.c +++ b/source/cmd_hbr.c @@ -2,7 +2,163 @@ * 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 +}; diff --git a/source/cmd_hout.c b/source/cmd_hout.c index 5613415..4c30eef 100644 --- a/source/cmd_hout.c +++ b/source/cmd_hout.c @@ -2,7 +2,242 @@ * 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 +}; diff --git a/source/cmd_lin.c b/source/cmd_lin.c index ee799ea..c356a39 100644 --- a/source/cmd_lin.c +++ b/source/cmd_lin.c @@ -2,7 +2,109 @@ * 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 +}; diff --git a/source/cmd_lout.c b/source/cmd_lout.c index 5bf4f45..e524114 100644 --- a/source/cmd_lout.c +++ b/source/cmd_lout.c @@ -2,7 +2,157 @@ * 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 +}; diff --git a/source/cmd_pin.c b/source/cmd_pin.c index 1dda3d9..e9248db 100644 --- a/source/cmd_pin.c +++ b/source/cmd_pin.c @@ -2,7 +2,149 @@ * 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 +}; diff --git a/source/cmd_port.c b/source/cmd_port.c index 0eedf89..e9d5376 100644 --- a/source/cmd_port.c +++ b/source/cmd_port.c @@ -2,7 +2,88 @@ * 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 +}; diff --git a/source/cmd_sdram.c b/source/cmd_sdram.c index f6e6d52..9d73bdd 100644 --- a/source/cmd_sdram.c +++ b/source/cmd_sdram.c @@ -2,7 +2,78 @@ * 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 +}; diff --git a/source/cmd_spi.c b/source/cmd_spi.c index df52b6d..e069f37 100644 --- a/source/cmd_spi.c +++ b/source/cmd_spi.c @@ -2,7 +2,207 @@ * 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 +}; diff --git a/source/cmd_vbat.c b/source/cmd_vbat.c index a5ae90f..3d1cff5 100644 --- a/source/cmd_vbat.c +++ b/source/cmd_vbat.c @@ -2,7 +2,121 @@ * 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 +}; diff --git a/source/commands.c b/source/commands.c index 6a45100..d8c1d6f 100644 --- a/source/commands.c +++ b/source/commands.c @@ -8,106 +8,38 @@ /* 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); @@ -120,1627 +52,46 @@ int cmd_do_sleep(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[]) { 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; diff --git a/source/drv_adc.c b/source/drv_adc.c index 0718120..126436b 100644 --- a/source/drv_adc.c +++ b/source/drv_adc.c @@ -7,7 +7,7 @@ * 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; diff --git a/source/drv_dac.c b/source/drv_dac.c index 01c1002..98af06b 100644 --- a/source/drv_dac.c +++ b/source/drv_dac.c @@ -6,7 +6,7 @@ */ -#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, diff --git a/source/drv_din.c b/source/drv_din.c index b22af68..44ff83c 100644 --- a/source/drv_din.c +++ b/source/drv_din.c @@ -10,7 +10,7 @@ * 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; diff --git a/source/drv_fray.c b/source/drv_fray.c index 7fa5e98..9e7d89c 100644 --- a/source/drv_fray.c +++ b/source/drv_fray.c @@ -8,7 +8,7 @@ * 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; diff --git a/source/drv_hbridge.c b/source/drv_hbridge.c index 2d861ac..34bba88 100644 --- a/source/drv_hbridge.c +++ b/source/drv_hbridge.c @@ -12,7 +12,7 @@ //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; diff --git a/source/drv_hout.c b/source/drv_hout.c index db8e77d..0a4d714 100644 --- a/source/drv_hout.c +++ b/source/drv_hout.c @@ -8,7 +8,7 @@ * * 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}; diff --git a/source/drv_lout.c b/source/drv_lout.c index 7802671..4c47fc4 100644 --- a/source/drv_lout.c +++ b/source/drv_lout.c @@ -7,7 +7,7 @@ * 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; diff --git a/source/drv_spi.c b/source/drv_spi.c index caf35e1..cf19d9f 100644 --- a/source/drv_spi.c +++ b/source/drv_spi.c @@ -1,6 +1,6 @@ -#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) diff --git a/source/notification.c b/source/notification.c index 671b8df..a8f54b8 100644 --- a/source/notification.c +++ b/source/notification.c @@ -11,16 +11,16 @@ /* Include Files */ -#include "esm.h" +#include "ti_drv_esm.h" #include "sys_selftest.h" -#include "adc.h" -#include "can.h" -#include "gio.h" -#include "lin.h" -#include "mibspi.h" -#include "sci.h" -#include "het.h" -#include "i2c.h" +#include "ti_drv_adc.h" +#include "ti_drv_can.h" +#include "ti_drv_gio.h" +#include "ti_drv_lin.h" +#include "ti_drv_mibspi.h" +#include "ti_drv_sci.h" +#include "ti_drv_het.h" +#include "ti_drv_i2c.h" /* USER CODE BEGIN (0) */ #include "FreeRTOS.h" #include "os_semphr.h" @@ -32,9 +32,6 @@ extern xSemaphoreHandle canMsgReceived; extern xSemaphoreHandle canMsgSent; -extern xSemaphoreHandle linMsgReceived; -extern xSemaphoreHandle linIDReceived; - /** @brief Data structure containing converted data from ADC * * Defined in commands.c */ @@ -154,19 +151,6 @@ void i2cNotification(i2cBASE_t *i2c, uint32_t flags) /* USER CODE BEGIN (21) */ /* USER CODE END */ -} -void linNotification(linBASE_t *lin, uint32_t flags) -{ -/* USER CODE BEGIN (23) */ - if (flags & LIN_ID_INT) { - xSemaphoreGiveFromISR(linIDReceived, NULL); - } - if (flags & LIN_RX_INT) { - lin->FLR |= (1 << 9); - xSemaphoreGiveFromISR(linMsgReceived, NULL); - } -/* USER CODE END */ - } /* USER CODE BEGIN (24) */ diff --git a/source/phy.c b/source/phy.c index cfec6dd..8cbc733 100644 --- a/source/phy.c +++ b/source/phy.c @@ -1,7 +1,7 @@ #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" diff --git a/source/port_def.c b/source/port_def.c index 4173d26..b550751 100644 --- a/source/port_def.c +++ b/source/port_def.c @@ -16,7 +16,7 @@ */ #include "port_def.h" -#include "adc_drv.h" +#include "drv_adc.h" #include "port_spi.h" #include "port_gpio.h" diff --git a/source/port_spi.c b/source/port_spi.c index a3fc033..0204f9f 100644 --- a/source/port_spi.c +++ b/source/port_spi.c @@ -8,7 +8,7 @@ */ #include "port_spi.h" -#include "spi_drv.h" +#include "drv_spi.h" #include "cmd_proc.h" #define PORT_BUF 4 diff --git a/source/spi_tms570.c b/source/spi_tms570.c index 8be4f7c..b5708c7 100644 --- a/source/spi_tms570.c +++ b/source/spi_tms570.c @@ -1,9 +1,9 @@ /* 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); diff --git a/source/sys_main.c b/source/sys_main.c index c09dc05..7f9000d 100644 --- a/source/sys_main.c +++ b/source/sys_main.c @@ -21,16 +21,16 @@ #include "cmd_proc_freertos_tms570.h" #include "FreeRTOS.h" #include "os_task.h" -#include "can.h" -#include "adc.h" -#include "gio.h" -#include "het.h" -#include "emif.h" -#include "dmm.h" -#include "lin.h" -#include "emac_test.h" +#include "ti_drv_can.h" +#include "ti_drv_adc.h" +#include "ti_drv_gio.h" +#include "ti_drv_het.h" +#include "ti_drv_emif.h" +#include "ti_drv_dmm.h" +#include "ti_drv_lin.h" +#include "cmd_emac.h" #include "spi_tms570.h" -#include "spi_drv.h" +#include "drv_spi.h" /* USER CODE END */ diff --git a/source/sys_startup.c b/source/sys_startup.c index c620e82..a1f1820 100644 --- a/source/sys_startup.c +++ b/source/sys_startup.c @@ -26,7 +26,7 @@ #include "sys_vim.h" #include "sys_core.h" #include "sys_selftest.h" -#include "esm.h" +#include "ti_drv_esm.h" /* USER CODE BEGIN (1) */ diff --git a/source/ti_drv_adc.c b/source/ti_drv_adc.c index 71c2e6d..010100d 100644 --- a/source/ti_drv_adc.c +++ b/source/ti_drv_adc.c @@ -17,7 +17,7 @@ /* Include Files */ -#include "adc.h" +#include "ti_drv_adc.h" /* USER CODE BEGIN (1) */ /* USER CODE END */ diff --git a/source/ti_drv_can.c b/source/ti_drv_can.c index 2194e9a..3220372 100644 --- a/source/ti_drv_can.c +++ b/source/ti_drv_can.c @@ -19,7 +19,7 @@ /* Include Files */ -#include "can.h" +#include "ti_drv_can.h" /* USER CODE BEGIN (1) */ /* USER CODE END */ diff --git a/source/ti_drv_dma.c b/source/ti_drv_dma.c index 692d049..df1bdb6 100644 --- a/source/ti_drv_dma.c +++ b/source/ti_drv_dma.c @@ -8,7 +8,7 @@ /* (c) Texas Instruments 2009-2010, All rights reserved. */ -#include "dma.h" +#include "ti_drv_dma.h" g_dmaCTRL g_dmaCTRLPKT; diff --git a/source/ti_drv_dmm.c b/source/ti_drv_dmm.c index 0479449..f1acf5a 100644 --- a/source/ti_drv_dmm.c +++ b/source/ti_drv_dmm.c @@ -10,7 +10,7 @@ /* USER CODE BEGIN (0) */ /* USER CODE END */ -#include "dmm.h" +#include "ti_drv_dmm.h" /* USER CODE BEGIN (1) */ /* USER CODE END */ diff --git a/source/ti_drv_emac.c b/source/ti_drv_emac.c index d364483..80e3b4d 100644 --- a/source/ti_drv_emac.c +++ b/source/ti_drv_emac.c @@ -12,7 +12,7 @@ #include "sys_common.h" #include "hw_reg_access.h" -#include "emac.h" +#include "ti_drv_emac.h" #include "hw_emac.h" #include "hw_emac_ctrl.h" diff --git a/source/ti_drv_emif.c b/source/ti_drv_emif.c index 224d597..7f6b5f2 100644 --- a/source/ti_drv_emif.c +++ b/source/ti_drv_emif.c @@ -9,7 +9,7 @@ #include "system.h" -#include "emif.h" +#include "ti_drv_emif.h" /** @fn void emif_SDRAMInit() * @brief Initializes the emif Driver for SDRAM diff --git a/source/ti_drv_esm.c b/source/ti_drv_esm.c index 593e6e5..c34b06f 100644 --- a/source/ti_drv_esm.c +++ b/source/ti_drv_esm.c @@ -16,7 +16,7 @@ /* Include Files */ -#include "esm.h" +#include "ti_drv_esm.h" /* USER CODE BEGIN (1) */ /* USER CODE END */ diff --git a/source/ti_drv_gio.c b/source/ti_drv_gio.c index c602599..2644bd6 100644 --- a/source/ti_drv_gio.c +++ b/source/ti_drv_gio.c @@ -10,7 +10,7 @@ /* USER CODE BEGIN (0) */ /* USER CODE END */ -#include "gio.h" +#include "ti_drv_gio.h" /* USER CODE BEGIN (1) */ /* USER CODE END */ diff --git a/source/ti_drv_het.c b/source/ti_drv_het.c index fbfe8f2..7ae2a20 100644 --- a/source/ti_drv_het.c +++ b/source/ti_drv_het.c @@ -7,7 +7,7 @@ /* (c) Texas Instruments 2009-2012, All rights reserved. */ -#include "het.h" +#include "ti_drv_het.h" /* USER CODE BEGIN (0) */ /* USER CODE END */ diff --git a/source/ti_drv_i2c.c b/source/ti_drv_i2c.c index 2a444b8..90babff 100644 --- a/source/ti_drv_i2c.c +++ b/source/ti_drv_i2c.c @@ -10,7 +10,7 @@ /* USER CODE BEGIN (0) */ /* USER CODE END */ -#include "i2c.h" +#include "ti_drv_i2c.h" /* USER CODE BEGIN (1) */ /* USER CODE END */ diff --git a/source/ti_drv_lin.c b/source/ti_drv_lin.c index 4572841..76a1a59 100644 --- a/source/ti_drv_lin.c +++ b/source/ti_drv_lin.c @@ -10,7 +10,7 @@ /* USER CODE BEGIN (0) */ /* USER CODE END */ -#include "lin.h" +#include "ti_drv_lin.h" /* USER CODE BEGIN (1) */ /* USER CODE END */ diff --git a/source/ti_drv_mdio.c b/source/ti_drv_mdio.c index 49af9c7..e05387f 100644 --- a/source/ti_drv_mdio.c +++ b/source/ti_drv_mdio.c @@ -13,7 +13,7 @@ #include "sys_common.h" #include "hw_reg_access.h" -#include "mdio.h" +#include "ti_drv_mdio.h" #include "hw_mdio.h" /******************************************************************************* diff --git a/source/ti_drv_mibspi.c b/source/ti_drv_mibspi.c index 82fae1f..ab8c686 100644 --- a/source/ti_drv_mibspi.c +++ b/source/ti_drv_mibspi.c @@ -10,7 +10,7 @@ /* USER CODE BEGIN (0) */ /* USER CODE END */ -#include "mibspi.h" +#include "ti_drv_mibspi.h" /* USER CODE BEGIN (1) */ /* USER CODE END */ diff --git a/source/ti_drv_sci.c b/source/ti_drv_sci.c index 026b0bf..848ee13 100644 --- a/source/ti_drv_sci.c +++ b/source/ti_drv_sci.c @@ -10,7 +10,7 @@ /* USER CODE BEGIN (0) */ /* USER CODE END */ -#include "sci.h" +#include "ti_drv_sci.h" /* USER CODE BEGIN (1) */ #include "cmdio_tisci.h" diff --git a/source/utils.c b/source/utils.c index afa8343..d999545 100644 --- a/source/utils.c +++ b/source/utils.c @@ -10,13 +10,11 @@ *******************************************************************/ #include -//#include #include #include #include #include #include -#include /* string parse and input routines */ -- 2.39.2