#include "cmd.h"
#include "cmd_adc.h"
#include "cmd_can.h"
-#include "cmd_din.h"
#include "cmd_pin.h"
#include "cmd_port.h"
#include "hal/hal.h"
-/**
- * @brief Sleep the board
- *
- * @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_sleep(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
-{
- hal_gpio_pin_set_value(PIN_DSC_CANNSTB, 1);
- hal_gpio_pin_set_value(PIN_DSC_CANEN, 1);
- hal_gpio_pin_set_value(PIN_DSC_LIN2NSLP, 1);
- hal_gpio_pin_set_value(PIN_DSC_LIN1NSLP, 1);
- vTaskDelay(10/portTICK_RATE_MS);
- hal_gpio_pin_set_value(PIN_DSC_LIN2NSLP, 0);
- hal_gpio_pin_set_value(PIN_DSC_LIN1NSLP, 0);
- hal_gpio_pin_set_value(PIN_DSC_CANNSTB, 0);
- return 0;
-}
-
#include <version.h>
int cmd_do_version(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
/** Root list in which commands are stored */
cmd_des_t const **cmd_list;
-/** Command descriptor for sleep command */
-cmd_des_t const cmd_des_sleep = {
- 0, 0,
- "sleep","Sleep the board",
- "### Syntax ###\n"
- "\n"
- " sleep\n"
- "\n"
- "### Description ###\n"
- "\n"
- "This command configures the LIN and CAN peripherals to enter sleep mode\n"
- "and turn the whole device into sleep mode. External signal on CAN or\n"
- "LIN will wake the device up.\n",
- CMD_HANDLER(cmd_do_sleep), (void *)&cmd_list
-};
-
/** Command descriptor for show help command */
cmd_des_t const cmd_des_help = {
0, 0,
/** @brief Main list of commands */
cmd_des_t const *cmd_list_main[] = {
&cmd_des_help,
- &cmd_des_sleep,
&cmd_des_version,
CMD_DES_INCLUDE_SUBLIST(cmd_list_adc),
CMD_DES_INCLUDE_SUBLIST(cmd_list_can),
- CMD_DES_INCLUDE_SUBLIST(cmd_list_din),
CMD_DES_INCLUDE_SUBLIST(cmd_list_pin),
CMD_DES_INCLUDE_SUBLIST(cmd_list_port),
NULL
+++ /dev/null
-/*
- * Copyright (C) 2012-2013 Czech Technical University in Prague
- *
- * Created on: 28.2.2013
- *
- * Authors:
- * - Michal Horn
- *
- * This document contains proprietary information belonging to Czech
- * Technical University in Prague. Passing on and copying of this
- * document, and communication of its contents is not permitted
- * without prior written authorization.
- *
- * File : cmd_din.c
- *
- * Abstract:
- * This file contains commands for DIN control. Use can setup DIN pin and read value and diagnosctic value
- *
- */
-
-#include "cmd_din.h"
-#include "stdio.h"
-
-#ifndef DOCGEN
-
-#include "cmdproc_utils.h"
-#include "drv/din.h"
-#include "rpp/rpp.h"
-#include "hal/hal.h"
-
-/**
- * @brief Setup DIN pin parameters (pull up/down, tristate/active, IRQ and wakeup disable/enable
- *
- * @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_setup(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
-{
- char *p;
- int ret;
- int pin_min, pin_max;
- int pull_up = 1;
- int active = 0;
- int can_wake = 1;
- char spareParams;
- int i;
-
-
- p = param[1];
- if (sscanf(p, "%d-%d %d %d %d %1s", &pin_min, &pin_max, &pull_up, &active, &can_wake, &spareParams) >= 2) {
- /* Pin range */
- }
- else if (sscanf(p, "%d %d %d %d %1s", &pin_min, &pull_up, &active, &can_wake, &spareParams) >= 1)
- /* Single pin */
- pin_max = pin_min;
- else
- return -CMDERR_BADPAR;
-
- for (i = pin_min; i <= pin_max; i++) {
- ret = rpp_din_setup(i, pull_up, active, can_wake);
- if (ret == -1) {
- rpp_sci_printf("Pin %d out of range.\n", i);
- return -CMDERR_BADPAR;
- }
- else if (ret == -2) {
- rpp_sci_printf("Pin %d is not programmable to switch to battery.\n", i);
- return -CMDERR_BADPAR;
- }
- rpp_sci_printf("dinsetup%d=%d%d%d\n", i, !!pull_up, !!active, !!can_wake);
- }
- if (rpp_din_update() == FAILURE) {
- rpp_sci_printf("DIN SPI transfer failed.\n");
- return -CMDERR_EIO;
- }
- return 0;
-}
-
-/**
- * @brief Get value from DIN pin
- *
- * @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_get(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
-{
- int pin;
- char *p = param[1];
- char spareParams;
- int ret;
-
- if (sscanf(p, "%d %1s", &pin, &spareParams) != 1)
- return -CMDERR_BADPAR;
-
- if (rpp_din_update() == FAILURE) {
- rpp_sci_printf("DIN SPI transfer failed.\n");
- return -CMDERR_EIO;
- }
-
- ret = rpp_din_get(pin);
- if (ret == -1) {
- rpp_sci_printf("Pin out of range.\n");
- return -CMDERR_BADPAR;
- }
- rpp_sci_printf("dinget%d =%x\n", pin, ret);
- return 0;
-}
-
-/**
- * @brief Read DIN diagnostic value
- *
- * @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_diag(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
-{
- int pin;
- char *p = param[1];
- char spareParams;
- int ret;
-
- if (sscanf(p, "%d %1s", &pin, &spareParams) != 1)
- return -CMDERR_BADPAR;
-
- if (rpp_din_update() == FAILURE) {
- rpp_sci_printf("DIN SPI transfer failed.\n");
- return -CMDERR_EIO;
- }
-
- ret = rpp_din_diag(pin);
- if (ret == -1) {
- rpp_sci_printf("Pin out of range.\n");
- return -CMDERR_BADPAR;
- }
- rpp_sci_printf("dindiag%d =%x\n", pin, ret);
- return 0;
-}
-
-int cmd_do_din_watch(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
-{
- rpp_sci_printf((const char *)
- "Digital Inputs Test [0-15]:\r\n"
- );
- rpp_sci_printf((const char *)
- "===========================================================\r\n"
- );
- rpp_sci_printf((const char *)
- " 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 A B C D E F G H\r\n"
- // 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
- );
-
- // Calculate wait time in OS ticks
- static const portTickType freq_ticks = 100 /* ms */ / portTICK_RATE_MS;
- portTickType last_wake_time = xTaskGetTickCount();
-
- uint8_t pin;
- while (cmd_io->getc(cmd_io) < 0) {
-
- // Update inputs
- rpp_din_update();
-
- // Print inputs
- // Terminal needs to be at least 47 chars long
- for (pin = 0; pin < 16; pin++) {
- rpp_sci_printf((const char *)" %d ", rpp_din_get(pin));
- }
- for (pin = 8; pin < 16; pin++) {
- rpp_sci_printf((const char *)" %d ", rpp_din_get_tr(pin));
- }
- rpp_sci_printf("\r");
-
- vTaskDelayUntil(&last_wake_time, freq_ticks);
- }
-
- rpp_sci_printf("\n");
- return 0;
-}
-
-#endif /* DOCGEN */
-
-/** Command descriptor for din state command */
-cmd_des_t const cmd_des_din_setup = {
- 0, 0,
- "dinsetup*", "Setup DIN pin parameters (Pull up/down, tristate/active, IRQ and wakeup disable/enable)",
- "### Command syntax ###\n"
- "\n"
- " dinsetup<PINS> [A [B [C]]]\n"
- "where\n"
- "\n"
- "- PINS is either a number in range 1-16 or a range written as `<min>-<max>`\n"
- "- A is an optional value - either 0 (pull down/switch to battery) or 1 (pull up/switch to ground). The default is 1.\n"
- "- B is an optional value - either 0 (tri-state) or 1 (active). The default is 0.\n"
- "- C is an optional value - either 0 (wake up and IRQ disabled) or 1 (wake up and IRQ disabled enabled). The default is 1.\n"
- "\n"
- "### Description ###\n"
- "\n"
- "The command setups properties of one or more DIN pins as specified by\n"
- "`<PIN>`. Pins 0-7 can be set as pull up (switch to ground) or pull down\n"
- "(switch to battery), pins 8-15 are hardcoded as switch to ground. All\n"
- "pins can be set to either tri-state or active state and also can have\n"
- "wake-up function with IRQ activated or not.\n"
- "\n"
- "The command always prints the final settings of each set pin as ABC.\n"
- "The actual configuration cannot be read out of the pin driver.\n"
- "\n"
- "### Example ###\n"
- "\n"
- " --> dinsetup1 1 0 0\n"
- " dinsetup1=100\n"
- "\n"
- "Sets the DIN1 as switch to ground, active and disables IRQ generation.\n"
- "\n"
- " --> dinsetup2\n"
- " dinsetup2=101\n"
- "\n"
- "Sets the DIN2 as to the default values i.e. switch to battery,\n"
- "tri-state, wake-up/IRQ enabled.\n"
- "\n"
- " --> dinsetup0-7 1 1 1\n"
- " dinsetup0=111\n"
- " dinsetup1=111\n"
- " dinsetup2=111\n"
- " dinsetup3=111\n"
- " dinsetup4=111\n"
- " dinsetup5=111\n"
- " dinsetup6=111\n"
- " dinsetup7=111\n"
- "\n"
- "Sets the DIN0 through DIN7 as switch to ground, tri-state, wake-up/IRQ\n"
- "enabled.\n",
- CMD_HANDLER(cmd_do_din_setup), (void *)&cmd_list_din
-};
-
-/** Command descriptor for din state command */
-cmd_des_t const cmd_des_din_get = {
- 0, 0,
- "dinget*","Read the open/close status of a DIN pin (with the default treshold)", /* TODO add a command for reading with a treshold */
- "### Command syntax ###\n"
- "\n"
- " dinget<PIN>\n"
- "\n"
- "where PIN is a number in range 0-15\n"
- "\n"
- "### Description ###\n"
- "\n"
- "The command reads and prints the status of the DIN pin. Value 0 means\n"
- "switch is open, value 1 means switch is closed. The mapping between\n"
- "the DIN voltage and the open/close status depends on the setup of the\n"
- "pin (see dinsetup command).\n"
- "\n"
- "### Example ###\n"
- "\n"
- " --> dinget1\n"
- " dinget1 =0\n"
- "\n"
- "DIN1 is in open state.\n",
- CMD_HANDLER(cmd_do_din_get), (void *)&cmd_list_din
-};
-
-/** Command descriptor for din state command */
-cmd_des_t const cmd_des_din_diag = {
- 0, 0,
- "dindiag*","Read diagnostic value from DIN pin",
- "### Command syntax ###\n"
- "\n"
- " dindiag<PIN>\n"
- "\n"
- "where `<PIN>` is in range 1-16\n"
- "\n"
- "### Description ###\n"
- "\n"
- "The command reads and prints the value of diagnostic bit corresponding\n"
- "to a DIN pin. TODO check what the value actually mean.\n"
- "\n"
- "### Example ###\n"
- "\n"
- " --> dindiag1\n"
- " dindiag1 =0\n"
- "\n"
- "Prints value of the diagnostic bit of DIN1.\n",
- CMD_HANDLER(cmd_do_din_diag), (void *)&cmd_list_din
-};
-
-/** Command descriptor for din state command */
-cmd_des_t const cmd_des_din_watch = {
- 0, 0,
- "dinwatch","Watch status of all DIN pins",
- "### Command syntax ###\n"
- "\n"
- " dinwatch\n"
- "\n"
- "### Description ###\n"
- "\n"
- "The command reads and prints the status of DIN pins every 100\n"
- "milliseconds. Columns 0-15 correspond to open/close status of DIN pins\n"
- "with the default threshold of 4 V, columns A-H represent the logical\n"
- "values of pins DIN8-15 when read with programmable threshold.\n"
- "Pin status (open=0, close=1) depends on the pin setup that can be\n"
- "changed with dinsetup command, programmable threshold can be set with\n"
- "TODO command.\n"
- "\n"
- "Press any key to end this command.\n"
- "\n"
- "### Example ###\n"
- "\n"
- " --> dinwatch\n"
- " Digital Inputs Test [0-15]:\n"
- " ===========================================================\n"
- " 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 A B C D E F G H\n"
- " 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1\n",
- CMD_HANDLER(cmd_do_din_watch), (void *)&cmd_list_din
-};
-
-/** List of commands for din, defined as external */
-cmd_des_t const *cmd_list_din[] = {
- &cmd_des_din_setup,
- &cmd_des_din_get,
-/* &cmd_des_din_diag, */ // Implementation in lower layers not finished
- &cmd_des_din_watch,
- NULL
-};