* Authors:
* - Michal Horn
*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * 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
+ * This file contains commands for DIN control. Use can setup DIN pin and read value and diagnosctic value
*
*/
#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] 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[]) {
+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 i;
- p=param[1];
+ 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) {
+ }
+ 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
+ else
return -CMDERR_BADPAR;
for (i = pin_min; i <= pin_max; i++) {
* @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 cmd_do_din_get(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
+{
int pin;
- char *p=param[1];
+ char *p = param[1];
char spareParams;
int ret;
- if (sscanf(p, "%d %1s", &pin, &spareParams) != 1) {
+ if (sscanf(p, "%d %1s", &pin, &spareParams) != 1)
return -CMDERR_BADPAR;
- }
if (rpp_din_update() == FAILURE) {
rpp_sci_printf("DIN SPI transfer failed.\n");
* @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 cmd_do_din_diag(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
+{
int pin;
- char *p=param[1];
+ char *p = param[1];
char spareParams;
int ret;
- if (sscanf(p, "%d %1s", &pin, &spareParams) != 1) {
+ if (sscanf(p, "%d %1s", &pin, &spareParams) != 1)
return -CMDERR_BADPAR;
- }
if (rpp_din_update() == FAILURE) {
rpp_sci_printf("DIN SPI transfer failed.\n");
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
- );
+ 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();
+ // 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) {
+ uint8_t pin;
+ while (cmd_io->getc(cmd_io) < 0) {
- // Update inputs
- rpp_din_update();
+ // 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");
+ // 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);
- }
+ vTaskDelayUntil(&last_wake_time, freq_ticks);
+ }
- rpp_sci_printf("\n");
- return 0;
+ rpp_sci_printf("\n");
+ return 0;
}
-#endif /* DOCGEN */
+#endif /* DOCGEN */
/** Command descriptor for din state command */
-cmd_des_t const cmd_des_din_setup={
+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"
+ "### Command syntax ###\n"
"\n"
- " dinsetup<PINS> [A [B [C]]]\n"
+ " dinsetup<PINS> [A [B [C]]]\n"
"where\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"
+ "- 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"
+ "`<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"
"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"
+ "### Example ###\n"
"\n"
- " --> dinsetup1 1 0 0\n"
- " dinsetup1=100\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"
+ " --> 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"
+ " --> 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",
};
/** Command descriptor for din state command */
-cmd_des_t const cmd_des_din_get={
+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"
+ "### Command syntax ###\n"
"\n"
- " dinget<PIN>\n"
+ " dinget<PIN>\n"
"\n"
"where PIN is a number in range 0-15\n"
"\n"
- "=== Description ===\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"
+ "### Example ###\n"
"\n"
- " --> dinget1\n"
- " dinget1 =0\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={
+cmd_des_t const cmd_des_din_diag = {
0, 0,
"dindiag*","Read diagnostic value from DIN pin",
- "=== Command syntax ===\n"
+ "### Command syntax ###\n"
"\n"
- " dindiag<PIN>\n"
+ " dindiag<PIN>\n"
"\n"
- "where <PIN> is in range 1-16\n"
+ "where `<PIN>` is in range 1-16\n"
"\n"
- "=== Description ===\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"
+ "### Example ###\n"
"\n"
- " --> dindiag1\n"
- " dindiag1 =0\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={
+cmd_des_t const cmd_des_din_watch = {
0, 0,
"dinwatch","Watch status of all DIN pins",
- "=== Command syntax ===\n"
+ "### Command syntax ###\n"
"\n"
- " dinwatch\n"
+ " dinwatch\n"
"\n"
- "=== Description ===\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"
"\n"
"Press any key to end this command.\n"
"\n"
- "=== Example ===\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",
+ " --> 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_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
+ &cmd_des_din_watch,
+ NULL
};