]> rtime.felk.cvut.cz Git - pes-rpp/rpp-test-sw.git/commitdiff
Source and Header files modified
authorMichal Horn <michal@michal-laptop.(none)>
Thu, 28 Feb 2013 22:43:49 +0000 (23:43 +0100)
committerMichal Horn <michal@michal-laptop.(none)>
Thu, 28 Feb 2013 22:43:49 +0000 (23:43 +0100)
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

80 files changed:
include/FlexRay.h
include/Fr.h
include/cmd_adc.h
include/cmd_can.h
include/cmd_dac.h
include/cmd_din.h
include/cmd_emac.h
include/cmd_fray.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_proc_freertos_tms570.h
include/cmd_sdram.h
include/cmd_spi.h
include/cmd_vbat.h
include/cmdio_tisci.h
include/drv_adc.h
include/drv_fray.h
include/drv_hbridge.h
include/drv_hout.h
include/hal_gpio_tms570_def.h
include/spi_tms570.h
include/sys_selftest.h
include/system.h
include/ti_drv_dmm.h
include/ti_drv_het.h
include/ti_drv_i2c.h
include/ti_drv_lin.h
include/ti_drv_mibspi.h
include/ti_drv_sci.h
include/utils.h
source/cmd_adc.c
source/cmd_can.c
source/cmd_dac.c
source/cmd_din.c
source/cmd_emac.c
source/cmd_fray.c
source/cmd_hbr.c
source/cmd_hout.c
source/cmd_lin.c
source/cmd_lout.c
source/cmd_pin.c
source/cmd_port.c
source/cmd_sdram.c
source/cmd_spi.c
source/cmd_vbat.c
source/commands.c
source/drv_adc.c
source/drv_dac.c
source/drv_din.c
source/drv_fray.c
source/drv_hbridge.c
source/drv_hout.c
source/drv_lout.c
source/drv_spi.c
source/notification.c
source/phy.c
source/port_def.c
source/port_spi.c
source/spi_tms570.c
source/sys_main.c
source/sys_startup.c
source/ti_drv_adc.c
source/ti_drv_can.c
source/ti_drv_dma.c
source/ti_drv_dmm.c
source/ti_drv_emac.c
source/ti_drv_emif.c
source/ti_drv_esm.c
source/ti_drv_gio.c
source/ti_drv_het.c
source/ti_drv_i2c.c
source/ti_drv_lin.c
source/ti_drv_mdio.c
source/ti_drv_mibspi.c
source/ti_drv_sci.c
source/utils.c

index 49a96c2efc2eba451447972910d81250a459ece3..2d6affdd04cd55c606ab873c2eba53fa9d25b548 100644 (file)
@@ -2,7 +2,7 @@
  * FlexRay.h
  *
  *  Created on: 29.11.2012
- *      Author: michal
+ *      Author: Michal Horn
  */
 
 #ifndef FLEXRAY_H_
index fad4c985dd9fe17f4e1df31bbd798b225825270d..82455f4c5e7e99c9c2b585bd33369b1207a1013e 100644 (file)
@@ -8,6 +8,8 @@
  *\r
  *******************************************************************/\r
 \r
+#ifndef _FE_H_\r
+#define _FE_H_\r
 \r
 #define FRAY1 (&e_FRAY0_ST)\r
 #define FRAY2 (&e_FRAY1_ST)\r
@@ -1374,3 +1376,4 @@ int Fr_StartCommunication(FRAY_ST *Fray_PST);
 void Fr_TransmitTxLPdu(FRAY_ST *Fray_PST, bc *Fr_LSduPtr);\r
 void Fr_ReceiveRxLPdu(FRAY_ST *Fray_PST, bc *Fr_LSduPtr);\r
 \r
+#endif //_FE_H_\r
index 161c5e397820b43a1ac1a426b73e3e0e4f356406..df298f57a1f225a58ede76d869fffccf2227629e 100644 (file)
@@ -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_ */
index 7c2788ff85ae4409085c9df815b0001a08ad92b0..c6701980f0ad9ee4e8008c51edd2113bfa5cc7d9 100644 (file)
@@ -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_ */
index 489b70fdbeadeb247bf139b37bf7d681769fd8c5..5946f9ad9f07b9040edf71d2d17875b1be281717 100644 (file)
@@ -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_ */
index f68ed0bc9eb2df1d59f50c16d67d893b9c18fd10..4118269e2c0e44ce2e77ac951c9e860bd6b1cc42 100644 (file)
@@ -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_ */
index 975d9302eb4a83a543923acab976a72c29d66c08..ad0b99503a53a28990d1b9cb5f980a931dc60281 100644 (file)
@@ -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_ */
index c70884975951fdbf486089b8e842c6befd2e1b65..c0ce44f072c1fc2bbf356c5182b527e6bf3c1068 100644 (file)
@@ -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_ */
index 83369ca6381e1b47f0f94bed622fe1392ecef14d..a580abd2958ba6d9428c1680542d49d440f0af84 100644 (file)
@@ -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_ */
index 4afdd3e6faa67c19d99e58a338f3ff92a0d6834a..495e3bfe9c5c81908e8b252a6a9fb645f36fa483 100644 (file)
@@ -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_ */
index 7bde7061ec766ffa01e9200144b51dbf4f34e771..e86f4d4a37a53abc9d92a41874a2002259191b6d 100644 (file)
@@ -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_ */
index 8c9814334a16d4fec7b48be4b44b0f434ed693b0..55e40861ea84d954932033da7f1959e64f882abd 100644 (file)
@@ -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_ */
index bf2d70cdbbabdeaf13eecaae07799d8aad9b5ad5..4a181a89d70af74b6fafda331668fd631de895b3 100644 (file)
@@ -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_ */
index 1d89c73a85db2d7682a8d702f046c229a70d0ea5..56fc32042c79bfc1a3763f84b7d10719aa3b4448 100644 (file)
@@ -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_ */
index be11c44c23e7a61eb47d64e748131e420536abb0..24421e1207e967a78eb58ddd674f4117753830e1 100644 (file)
@@ -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"
 
index fab11320448fa594dd516004b5aecc4155bce24c..e9b3a72357b95d355a7c27f1cad398d78179fc4e 100644 (file)
@@ -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_ */
index d080aad8863e58ea29a02f4e5b325fac2bb1e8ee..13e3f24a4a6efba9e320c86b3c3777bae8ff7678 100644 (file)
@@ -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_ */
index cbfd1957d43bbc3ba20dd21faea89f3deb94b591..59bc886a184d9bc7823ea2c044b67b10cc679a1d 100644 (file)
@@ -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_ */
index d4ae721576faf4f713cc87cc1083bf466cde793e..247403e7893fccc70e9c5bde78b807b29a44420e 100644 (file)
@@ -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
index 0891e8f1f499946d9fe3cb5852c0e80a5bcb071c..c1b537cc6d342043f8ff50f3ac82c0a3a13d8ae1 100644 (file)
@@ -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"
index a07ad1bf42bb0b59a2210ed27b36d0a82850f27f..fac1f4bab757c3f814dae6ab3a5dee8ac02c4a03 100644 (file)
@@ -9,6 +9,7 @@
 #define FRAY_SPI_H_
 
 #include "port_def.h"
+
 #define FRAY_SPICMD_INIT_VAL   0xFFFF
 #define FRAY_NUM_PORTS                 2
 
index 34fed358bfc43d8d9a18478b0bd7132b1c168688..daadd8a26bcec493088b75e0aa04fccdb45fcd51 100644 (file)
@@ -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();
index ed35797da9c39efe7ae6c43720419034301b6c05..3ad34409774f93d32e3a98d1f9908295bcfa49a4 100644 (file)
@@ -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);
index 2e7ff728f0ec676160291871843eeb80e5496377..8f4f0d2b051d211e16bc70644427d97de75085b8 100644 (file)
@@ -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
index b9257cfeb55f4949d6c0acd20c677d9cb7a46c62..101b77c0092cc39e7153ab02dd0c6234eb310ff6 100644 (file)
@@ -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)
index a471eee69c07e09330fd7925d023e6bd576c0c5f..e3f189cad1e44666337b30a7a1b028ea8029f2bf 100644 (file)
 #include "sys_core.h"\r
 #include "system.h"\r
 #include "sys_vim.h"\r
-#include "adc.h"\r
-#include "can.h"\r
-#include "mibspi.h"\r
-#include "het.h"\r
-#include "htu.h"\r
-#include "esm.h"\r
+#include "ti_drv_adc.h"\r
+#include "ti_drv_can.h"\r
+#include "ti_drv_mibspi.h"\r
+#include "ti_drv_het.h"\r
+#include "ti_drv_htu.h"\r
+#include "ti_drv_esm.h"\r
 \r
 /* USER CODE BEGIN (0) */\r
 /* USER CODE END */\r
index 7e68e0822065cea648be6d8e16e2523c1eaeb395..4f69fac2ae5320ae96578b779d2f472fa6404395 100644 (file)
@@ -16,7 +16,7 @@
 #define __SYS_SYSTEM_H__\r
 \r
 #include "sys_common.h"\r
-#include "gio.h"\r
+#include "ti_drv_gio.h"\r
 \r
 \r
 /* USER CODE BEGIN (0) */\r
index 6bad17c6a709cf684f7a760262ae73d348b5a27d..b3e87de66134e35e8ca28a802e5289dbceed0955 100644 (file)
@@ -12,7 +12,7 @@
 #define __DMM_H__\r
 \r
 #include "sys_common.h"\r
-#include "gio.h"\r
+#include "ti_drv_gio.h"\r
 \r
 #define DMM_SYNC               0\r
 #define DMM_CLK                        1\r
index e2bbcbe0fcfaa8ee2e9d67603f5e08eb00568f2a..a0cc38ec46392da1dd107877a79659d2de10dbaf 100644 (file)
@@ -12,7 +12,7 @@
 #define __HET_H__\r
 \r
 #include "sys_common.h"\r
-#include "gio.h"\r
+#include "ti_drv_gio.h"\r
 #include <string.h>\r
 \r
 /* USER CODE BEGIN (0) */\r
index 8918e3edf176ffd274780f3d77d0b99f085607a2..ccc642306176bff7cc2ea538fe461167c6e66e91 100644 (file)
@@ -12,7 +12,7 @@
 \r
 \r
 #include "sys_common.h"\r
-#include "gio.h"\r
+#include "ti_drv_gio.h"\r
 \r
 \r
 /** @enum i2cMode\r
index 4eab4e1b4bfe4319c707416554c54c26893190b9..98633cf987f5e3b81059dcfb0a6e393b2e7d2cdc 100644 (file)
@@ -12,7 +12,7 @@
 #define __LIN_H__\r
 \r
 #include "sys_common.h"\r
-#include "gio.h"\r
+#include "ti_drv_gio.h"\r
 \r
 \r
 /** @def LIN_BREAK_INT\r
index 0c0c13164adb299e43fe246a64f602010d1d80af..583d66d7aa5a367e9797c9054845e5d502ac0294 100644 (file)
@@ -12,7 +12,7 @@
 #define __MIBSPI_H__\r
 \r
 #include "sys_common.h"\r
-#include "gio.h"\r
+#include "ti_drv_gio.h"\r
 \r
 \r
 /** @enum triggerEvent\r
index d7e08d3becd09b47f3efafae1dab8194712a0c85..b6171af92b9383506aa1cec007fadc91406e49e7 100644 (file)
@@ -12,7 +12,7 @@
 #define __SCI_H__\r
 \r
 #include "sys_common.h"\r
-#include "gio.h"\r
+#include "ti_drv_gio.h"\r
 \r
 \r
 /** @enum sciIntFlags\r
index b76dabcecc49fa9b43f9405a26812c365b435f05..942499c00f2506e417f9d726b8edaabcefcf8826 100644 (file)
@@ -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);
index d26ea5a8f9bfa3dac5f1011b3a82d3747589d1c4..df5a4c7873d4fedaf92bd3b5440ef532080ead3e 100644 (file)
@@ -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
+};
index 72d8bbaf9239c8d145ce609aa9fa01a97f0f661f..a5b6cf508e92fcaa2a0386650a6d8855fc0dfdd9 100644 (file)
@@ -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
+};
index fbf7a030306b750eca25ebb6400d902c2974f55b..f8481cec76490c74a5f30940dae1e5bc6f9f3590 100644 (file)
@@ -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
+};
index ea1aee1d883c622fea09a408948a47e441993521..7996e9a71e3f1450dcb549e63338acf3113b9f53 100644 (file)
@@ -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
+};
index 0d17312b43f1ca6cb01b9b8b99761acc18a4f912..08d645f2ddd820e42d3f241edba4b29395d9e844 100644 (file)
@@ -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
+};
index 2d410edc859625cc1922ae4d83a8160c00914744..8d9e62df2047c393eb6fd25edb870f4f0c09568c 100644 (file)
@@ -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
+};
index 2653272c820e99401c3195a1002f2da2297c209a..7f9b92dbf827e448e374d339c743a84155cad37c 100644 (file)
@@ -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
+};
index 5613415a8f253e3e3de4c837e3e7bfd3b796b810..4c30eef378bdefd436e164c1d4b8e395fe55408f 100644 (file)
@@ -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
+};
index ee799ea3aab81cda97b70e643db47a4187207baf..c356a3933e31e4abfe0d13064002dd095ecd8e5b 100644 (file)
@@ -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
+};
index 5bf4f45d790e02a7cef7527de08c690b560d54e8..e524114167edc62b74e4fdbecdc020a466a6330f 100644 (file)
@@ -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
+};
index 1dda3d93dde633840b23c1706ea5509f8125579a..e9248dbf75d95f926224e159ab2231390965dced 100644 (file)
@@ -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
+};
index 0eedf89b84f22fe2c574db86a2ea73e376f5f6e3..e9d537693364b41d74824989a41868353c84f6d5 100644 (file)
@@ -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
+};
index f6e6d52914132ff520b3c81bc4e304e18f7764e7..9d73bdd179a3674bc3e4de920c83c35da6041b47 100644 (file)
@@ -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
+};
index df52b6d5858f52a41ecd17a7e21b40f39ae0e3c3..e069f37ea544384c88f2e97b215d4065e674984a 100644 (file)
@@ -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
+};
 
 
index a5ae90ff3a88db544dcb3ff21810e18995644e6f..3d1cff548b477906e5b750afbb61e395a0cff57a 100644 (file)
@@ -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
+};
 
index 6a451008ba0880d466438135e5d8a365ab5ba88b..d8c1d6f4ee07fbce82f2fc1abb7d380e97d50cd5 100644 (file)
 
 /* 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;
index 071812050d3d84b17804aefab2846158a7db9765..126436bf15bd12732e4d27785083f4395d0b4339 100644 (file)
@@ -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;
index 01c1002160cd0e3a5daf67723056afdb8be8b94f..98af06b8919e424966a1b3353a4858c269abfe1e 100644 (file)
@@ -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,
index b22af6823b47871765bc34c6c9e141b40c75a4e9..44ff83c31959870b7ba650f6d5d93192e07b53f0 100644 (file)
@@ -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;
index 7fa5e98ee897a6213df315aeea082595626947fa..9e7d89c03e231f4baf25b1beacab5302bf585867 100644 (file)
@@ -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;
index 2d861ac2ca281a9a0a7d17afb113fd7cd8bb1de9..34bba88942ae2328f5c7fe239c29cd5556965047 100644 (file)
@@ -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;
index db8e77df3cc712e6641f808a9a28804a42d2f823..0a4d714da52a432339d5805297ead474d35af5ab 100644 (file)
@@ -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};
index 78026711b3526607a06d14c09d0183cb405f2ebe..4c47fc4465fb687f560656ae768509001644fb20 100644 (file)
@@ -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;
index caf35e1d9648aff158dddd48a094b16d4ef673a0..cf19d9f990c6dc9ed580c0b31f0c1e55b15a4afc 100644 (file)
@@ -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)
index 671b8df276c0090c4b6484ba8ff18bd06b9f2add..a8f54b83fa0aa84f6bf80b78e277ca7df389f316 100644 (file)
 \r
 /* Include Files */\r
 \r
-#include "esm.h"\r
+#include "ti_drv_esm.h"\r
 #include "sys_selftest.h"\r
-#include "adc.h"\r
-#include "can.h"\r
-#include "gio.h"\r
-#include "lin.h"\r
-#include "mibspi.h"\r
-#include "sci.h"\r
-#include "het.h"\r
-#include "i2c.h"\r
+#include "ti_drv_adc.h"\r
+#include "ti_drv_can.h"\r
+#include "ti_drv_gio.h"\r
+#include "ti_drv_lin.h"\r
+#include "ti_drv_mibspi.h"\r
+#include "ti_drv_sci.h"\r
+#include "ti_drv_het.h"\r
+#include "ti_drv_i2c.h"\r
 /* USER CODE BEGIN (0) */\r
 #include "FreeRTOS.h"\r
 #include "os_semphr.h"\r
@@ -32,9 +32,6 @@
 extern xSemaphoreHandle canMsgReceived;\r
 extern xSemaphoreHandle canMsgSent;\r
 \r
-extern xSemaphoreHandle linMsgReceived;\r
-extern xSemaphoreHandle linIDReceived;\r
-\r
 /** @brief Data structure containing converted data from ADC\r
  *\r
  *     Defined in commands.c */\r
@@ -154,19 +151,6 @@ void i2cNotification(i2cBASE_t *i2c, uint32_t flags)
 /* USER CODE BEGIN (21) */\r
 /* USER CODE END */\r
 \r
-}\r
-void linNotification(linBASE_t *lin, uint32_t flags)      \r
-{\r
-/* USER CODE BEGIN (23) */\r
-               if (flags & LIN_ID_INT) {\r
-                       xSemaphoreGiveFromISR(linIDReceived, NULL);\r
-               }\r
-               if (flags & LIN_RX_INT) {\r
-                       lin->FLR |= (1 << 9);\r
-                       xSemaphoreGiveFromISR(linMsgReceived, NULL);\r
-               }\r
-/* USER CODE END */\r
-\r
 }\r
 \r
 /* USER CODE BEGIN (24) */\r
index cfec6dd5508fe9b3fb8b4da94de9d5314d5ecbb5..8cbc7338970dba110040f729460e14ead02f00b9 100644 (file)
@@ -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"
 
index 4173d2697c9539de69a1678f2c05374db578efc0..b550751ddaed67a02e7ec70db528b7781ed9d234 100644 (file)
@@ -16,7 +16,7 @@
  */
 
 #include "port_def.h"
-#include "adc_drv.h"
+#include "drv_adc.h"
 #include "port_spi.h"
 #include "port_gpio.h"
 
index a3fc0332ca95f5a1168c5fdd64090cbd2f0fe356..0204f9f2c9017e83bebf5b0dd7895e286616141c 100644 (file)
@@ -8,7 +8,7 @@
  */
 
 #include "port_spi.h"
-#include "spi_drv.h"
+#include "drv_spi.h"
 #include "cmd_proc.h"
 
 #define PORT_BUF 4
index 8be4f7c6b4d7760cf3a75a1db2ac5f5eacba75e0..b5708c75f60d5eafb530aa9e4aee28f042975bc2 100644 (file)
@@ -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);
 
index c09dc059eeac23835a17efde9774112c6a85b675..7f9000d520046fca7d6994eea71e3f55a1f0f44f 100644 (file)
 #include "cmd_proc_freertos_tms570.h"\r
 #include "FreeRTOS.h"\r
 #include "os_task.h"\r
-#include "can.h"\r
-#include "adc.h"\r
-#include "gio.h"\r
-#include "het.h"\r
-#include "emif.h"\r
-#include "dmm.h"\r
-#include "lin.h"\r
-#include "emac_test.h"\r
+#include "ti_drv_can.h"\r
+#include "ti_drv_adc.h"\r
+#include "ti_drv_gio.h"\r
+#include "ti_drv_het.h"\r
+#include "ti_drv_emif.h"\r
+#include "ti_drv_dmm.h"\r
+#include "ti_drv_lin.h"\r
+#include "cmd_emac.h"\r
 #include "spi_tms570.h"\r
-#include "spi_drv.h"\r
+#include "drv_spi.h"\r
 /* USER CODE END */\r
 \r
 \r
index c620e820c180f3b732485cba0f6c9fc93b1fb79f..a1f1820404a394c40677b9e22edea1f83f15f727 100644 (file)
@@ -26,7 +26,7 @@
 #include "sys_vim.h"\r
 #include "sys_core.h"\r
 #include "sys_selftest.h"\r
-#include "esm.h"\r
+#include "ti_drv_esm.h"\r
 \r
 \r
 /* USER CODE BEGIN (1) */\r
index 71c2e6d59a289f9b663c1cf7fdba9306bcfe6124..010100d389f9e2239b73370e555ca888fe30f121 100644 (file)
@@ -17,7 +17,7 @@
 \r
 /* Include Files */\r
 \r
-#include "adc.h"\r
+#include "ti_drv_adc.h"\r
 \r
 /* USER CODE BEGIN (1) */\r
 /* USER CODE END */\r
index 2194e9a1e22a8825ce1d1e4c972dfc5080de6043..322037280c6625fb6c22d81062ec23d81067fad1 100644 (file)
@@ -19,7 +19,7 @@
 \r
 /* Include Files */\r
 \r
-#include "can.h"\r
+#include "ti_drv_can.h"\r
 \r
 /* USER CODE BEGIN (1) */\r
 /* USER CODE END */\r
index 692d049e8f61ad5c76599ede29d0c47bc61b01a3..df1bdb63fdeec6778db96365a0a923592ef11b5e 100644 (file)
@@ -8,7 +8,7 @@
 /* (c) Texas Instruments 2009-2010, All rights reserved. */\r
 \r
 \r
-#include "dma.h"\r
+#include "ti_drv_dma.h"\r
 \r
 g_dmaCTRL g_dmaCTRLPKT;\r
 \r
index 047944990ecd53a3181ee0ad9839c8fcee637ee8..f1acf5a5454d7d5d5220094b8a10aed067970e55 100644 (file)
@@ -10,7 +10,7 @@
 /* USER CODE BEGIN (0) */\r
 /* USER CODE END */\r
 \r
-#include "dmm.h"\r
+#include "ti_drv_dmm.h"\r
 \r
 /* USER CODE BEGIN (1) */\r
 /* USER CODE END */\r
index d364483588399d518e17dc9959a663c954a45af0..80e3b4dafc2c7e5014ef5fbbf1ea158784f961f3 100644 (file)
@@ -12,7 +12,7 @@
 \r
 #include "sys_common.h"\r
 #include "hw_reg_access.h"\r
-#include "emac.h"\r
+#include "ti_drv_emac.h"\r
 #include "hw_emac.h"\r
 #include "hw_emac_ctrl.h"\r
 \r
index 224d597ebd6c5b1a7dd7148c1a1d4bb22d3c30f0..7f6b5f2fb047fb8b6e2bab29471a082cac238f44 100644 (file)
@@ -9,7 +9,7 @@
 \r
 \r
 #include "system.h"\r
-#include "emif.h"\r
+#include "ti_drv_emif.h"\r
 \r
 /** @fn void emif_SDRAMInit()\r
 *   @brief Initializes the emif Driver for SDRAM\r
index 593e6e553d6739d1fd3ea0e73e921185dfcd3d3a..c34b06fee6d1eac8e5e252e01a8bdf3f05829cd5 100644 (file)
@@ -16,7 +16,7 @@
 \r
 /* Include Files */\r
 \r
-#include "esm.h"\r
+#include "ti_drv_esm.h"\r
 \r
 /* USER CODE BEGIN (1) */\r
 /* USER CODE END */\r
index c6025991afc9f155254a23ff9a1f7b26b1e86eb3..2644bd6388bddf0b62170e1953dc8d65f530aa6c 100644 (file)
@@ -10,7 +10,7 @@
 /* USER CODE BEGIN (0) */\r
 /* USER CODE END */\r
 \r
-#include "gio.h"\r
+#include "ti_drv_gio.h"\r
 \r
 /* USER CODE BEGIN (1) */\r
 /* USER CODE END */\r
index fbfe8f27168ab50c9b86bb559f5244595a2dfff7..7ae2a204c385f9cde322fbe923756e0ab425a04c 100644 (file)
@@ -7,7 +7,7 @@
 \r
 /* (c) Texas Instruments 2009-2012, All rights reserved. */\r
 \r
-#include "het.h"\r
+#include "ti_drv_het.h"\r
 \r
 /* USER CODE BEGIN (0) */\r
 /* USER CODE END */\r
index 2a444b89c55815a3404be4a018026027e8f020ba..90babffa1d15ad03e288d15ee32b52edf957dab3 100644 (file)
@@ -10,7 +10,7 @@
 /* USER CODE BEGIN (0) */\r
 /* USER CODE END */\r
 \r
-#include "i2c.h"\r
+#include "ti_drv_i2c.h"\r
 \r
 /* USER CODE BEGIN (1) */\r
 /* USER CODE END */\r
index 4572841496f4928f8bb47b04f94c6d068a0162c4..76a1a5980fe9be7a80f4cbbb6060c9bd70cb4666 100644 (file)
@@ -10,7 +10,7 @@
 /* USER CODE BEGIN (0) */\r
 /* USER CODE END */\r
 \r
-#include "lin.h"\r
+#include "ti_drv_lin.h"\r
 \r
 /* USER CODE BEGIN (1) */\r
 /* USER CODE END */\r
index 49af9c78f9d8148d3ba0e2a5439666bea0e0f1f1..e05387f27f863b375336c60d575b4ae6033e6578 100644 (file)
@@ -13,7 +13,7 @@
 \r
 #include "sys_common.h"\r
 #include "hw_reg_access.h"\r
-#include "mdio.h"\r
+#include "ti_drv_mdio.h"\r
 #include "hw_mdio.h"\r
 \r
 /*******************************************************************************\r
index 82fae1f88be39690ecc6e508b7aca94f7a443791..ab8c6861e7f883de5544aa520b3219fd4c597d50 100644 (file)
@@ -10,7 +10,7 @@
 /* USER CODE BEGIN (0) */\r
 /* USER CODE END */\r
 \r
-#include "mibspi.h"\r
+#include "ti_drv_mibspi.h"\r
 \r
 /* USER CODE BEGIN (1) */\r
 /* USER CODE END */\r
index 026b0bf538093ae660a8de5c2742e6f54fe030b1..848ee1360a3066f2f122d678ccca3d29d52ada01 100644 (file)
@@ -10,7 +10,7 @@
 /* USER CODE BEGIN (0) */\r
 /* USER CODE END */\r
 \r
-#include "sci.h"\r
+#include "ti_drv_sci.h"\r
 \r
 /* USER CODE BEGIN (1) */\r
 #include "cmdio_tisci.h"\r
index afa834334de57757cea348f7f38d8153b3b49410..d9995454840d8f001d99e3d6e72280af295d688e 100644 (file)
  *******************************************************************/
 
 #include <stdint.h>
-//#include <system_def.h>
 #include <string.h>
 #include <stdio.h>
 #include <ctype.h>
 #include <stdlib.h>
 #include <cmd_proc.h>
-#include <sys_common.h>
 
 /* string parse and input routines */