]> rtime.felk.cvut.cz Git - rpp-test-sw.git/blobdiff - rpp-test-sw/commands/cmd_motor_example.c
Change license to MIT
[rpp-test-sw.git] / rpp-test-sw / commands / cmd_motor_example.c
index 8a68c9cbbfe1c0952cab9bc299976efd03504a76..3d84c210e7208d336b62641afcba85c8692d6c4c 100644 (file)
@@ -1,23 +1,31 @@
 /*
- * Copyright (C) 2012-2013 Czech Technical University in Prague
+ * Copyright (C) 2012-2013, 2015 Czech Technical University in Prague
  *
  * Created on: 16.5.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_pin.c
  *
@@ -33,9 +41,8 @@
 #ifndef DOCGEN
 
 #include "rpp/rpp.h"
-#include "hal/hal.h"
-#include "drv/drv.h"
 #include "cmdproc.h"
+#include "drv/port.h"
 
 #define ADC_MAX_VALUE 0x0983
 #define RX_ERROR_MAX 100
@@ -328,8 +335,6 @@ int receive_control_data(int *enable, int *direction, int *duty)
  */
 int cmd_do_control(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
 {
-       port_desc_t *adc_desc;
-       uint32_t adc_values[PORT_ADC_CHANNEL_NUM*2];
        int ret;
        int duty = 0;
        int button = 0;
@@ -339,8 +344,6 @@ int cmd_do_control(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
        int dir_cnt = 0;            // Debounce counter for direction button
        uint32_t error;
 
-       adc_desc = hal_port_get_dsc(PORT_NAME_ADC, -1);
-
        if (rpp_din_setup(0, FALSE, TRUE, FALSE) == FAILURE) {  // For the red button, which is switch to battery
                rpp_sci_printf("Din 0 setup failed.\n");
                return -CMDERR_BADCFG;
@@ -377,8 +380,11 @@ int cmd_do_control(cmd_io_t *cmd_io, const struct cmd_des *des, char *param[])
        rpp_sci_printf("Connected.\r\n");
 
        while (1) {
+               const struct port_desc *port = &port_desc[PORT_ID_ADC];
+               uint16_t adc_values[port->numchn];
                vTaskDelay(10/portTICK_RATE_MS);
-               ret = adc_desc->port_getfnc_ptr(adc_desc->config, PORT_ADC_CHANNEL_NUM, adc_values);
+
+               ret = port->get(port, adc_values, sizeof(adc_values));
                if (ret < 0) {
                        rpp_sci_printf("ADC read failed!\n");
                        break;
@@ -521,7 +527,7 @@ cmd_des_t const cmd_des_control = {
        "\n"
        "The purpose of this pair of commands is to demonstrate functionality\n"
        "of the FlexRay, ADC, DIN and HBR peripherals.\n",
-       CMD_HANDLER(cmd_do_control), (void*)&cmd_list_motor_example
+       CMD_HANDLER(cmd_do_control), (void *)&cmd_list_motor_example
 };
 
 /** Command descriptor for motor */
@@ -540,7 +546,7 @@ cmd_des_t const cmd_des_motor = {
        "\n"
        "The purpose of this pair of commands is to demonstrate functionality\n"
        "of the FlexRay, ADC, DIN and HBR peripherals.\n",
-       CMD_HANDLER(cmd_do_motor), (void*)&cmd_list_motor_example
+       CMD_HANDLER(cmd_do_motor), (void *)&cmd_list_motor_example
 };
 
 /** List of commands for example, defined as external */