/*
- * Copyright (C) 2012-2013 Czech Technical University in Prague
+ * Copyright (C) 2012-2013, 2016 Czech Technical University in Prague
*
* Created on: 28.2.2013
*
* 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.
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following
+ * conditions:
*
- * 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.
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
*
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
*
* 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"
"\n"
- " dinsetup<PINS> [A [B [C]]]\n"
+ " dinsetup<PINS> [PU [ACT [WAKE]]]\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"
+ "- PINS is either a number in range 0-15 or a range written as\n"
+ " `<min>-<max>`\n"
+ "- PU is an optional value - either 0 (pull down/switch to battery) or 1\n"
+ " (pull up/switch to ground). The default is 1.\n"
+ "- ACT is an optional value - either 0 (tri-state) or 1 (active). The\n"
+ " default is 0.\n"
+ "- WAKE is an optional value - either 0 (wake up and IRQ disabled) or 1\n"
+ " (wake up and IRQ 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"
+ "`<PINS>`. Pins 0-7 can be set as pull up (switch to ground) or pull\n"
+ "down (switch to battery), pins 8-15 are hardcoded as switch to ground.\n"
+ "All pins can be set to either tri-state or active state and 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"
+ "The command always prints the final settings of each set pin as PU ACT\n"
+ "WAKE (without spaces). The actual configuration cannot be read out of\n"
+ "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"
+ "Sets the DIN1 as switch to ground, tri-state and disables IRQ\n"
+ "generation.\n"
"\n"
" --> dinsetup2\n"
" dinsetup2=101\n"
"\n"
- "Sets the DIN2 as to the default values i.e. switch to battery,\n"
+ "Sets the DIN2 as to the default values i.e. switch to ground,\n"
"tri-state, wake-up/IRQ enabled.\n"
"\n"
" --> dinsetup0-7 1 1 1\n"
" dinsetup6=111\n"
" dinsetup7=111\n"
"\n"
- "Sets the DIN0 through DIN7 as switch to ground, tri-state, wake-up/IRQ\n"
+ "Sets the DIN0 through DIN7 as switch to battery, active, 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={
+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 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 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"
};
/** 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
};