]> rtime.felk.cvut.cz Git - pes-rpp/rpp-lib.git/commitdiff
Update remaining files to the changed interface
authorMichal Sojka <sojkam1@fel.cvut.cz>
Sat, 1 Aug 2015 14:55:27 +0000 (16:55 +0200)
committerMichal Sojka <sojkam1@fel.cvut.cz>
Fri, 7 Aug 2015 17:57:02 +0000 (19:57 +0200)
rpp/src/drv/dac.c
rpp/src/drv/din.c
rpp/src/drv/fr_tms570.c
rpp/src/drv/hbridge.c
rpp/src/drv/hout.c
rpp/src/drv/lout.c
rpp/src/drv/mout.c
rpp/src/rpp/eth.c

index c2a4d2c38b2996a69da53ca4139c1e4812240c05..dd7ccf6cd0212fdcc385ea3cf5ec04c4abed8ca1 100644 (file)
@@ -19,6 +19,7 @@
 
 
 #include "drv/dac.h"
+#include "drv/port.h"
 
 #define DAC_PIN_NUM     4
 
@@ -43,11 +44,11 @@ static uint16_t dac_pin_status[DAC_PIN_NUM] = {
 /**
  * Port names for each DAC port, to be easily accessible by indexing
  */
-const char *dac_port_names[DAC_PIN_NUM] = {
-       DIO_PORT_NAME_DAC1_2,
-       DIO_PORT_NAME_DAC1_2,
-       DIO_PORT_NAME_DAC3_4,
-       DIO_PORT_NAME_DAC3_4
+static const enum port_id dac_ports[DAC_PIN_NUM] = {
+       PORT_ID_DAC1_2,
+       PORT_ID_DAC1_2,
+       PORT_ID_DAC3_4,
+       PORT_ID_DAC3_4,
 };
 
 /**
@@ -78,16 +79,15 @@ int drv_dac_spi_transfer(uint8_t pin, boolean_t enabled, uint16_t value)
        dac_pin_status[pin] = dac_pin_status[pin] & 0xF000;
        dac_pin_status[pin] |= (value & 0xFFF);
 
-       uint32_t commands[2];
+       char commands[2];
 
        // Warning!!! Can be "optimized" by compiler
        dac_spi_cmd = dac_pin_status[pin];
        dac_spi_cmd_sh = dac_spi_cmd;
        //--
-       dio_port_desc_t *desc;
-       desc = dio_port_get_dsc(dac_port_names[pin], -1);
+       const struct port_desc *port = &port_desc[dac_ports[pin]];
        commands[0] = (dac_spi_cmd_sh & 0xFF00) >> 8;
        commands[1] = (dac_spi_cmd_sh & 0xFF);
 
-       return desc->port_setfnc_ptr(desc->config, desc->numValues, commands);
+       return port->set(port, commands, sizeof(commands));
 }
index ccdafb23548e3248503fe90a8fc5ef4d06f9d760..8d39830a644cb9beae20eae643aa631c3ceb5f5f 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 2012-2013 Czech Technical University in Prague
+/* Copyright (C) 2012-2013, 2015 Czech Technical University in Prague
  *
  * Authors:
  *     - Michal Horn <hornmich@fel.cvut.cz>
 *   Include Files
 ******************************************************************************/
 #include "drv/drv.h"
-
+#include "drv/port.h"
+#include "drv/gio_tab.h"
 
 
 /******************************************************************************
 *   Static Variable Definitions
 ******************************************************************************/
-/** Stored response from SPI */
-static uint32_t din_spi_resp = 0;
+/**
+ * Stored response from SPI.
+ *
+ * The response data does not depend on the command sent.
+ */
+static uint8_t din_spi_resp[3];
 
 /** Store commands in shadow registers */
 static uint16_t shadow_reg_list[DIN_NUM_SPI_CMD];
@@ -41,14 +46,7 @@ static uint16_t shadow_reg_list[DIN_NUM_SPI_CMD];
 /******************************************************************************
 *   Function Prototypes
 ******************************************************************************/
-/**
- * Switch copy command, prepared by other functions, to shadow variable,
- * convert command to MSB,
- * transfer command to DIN
- * store spi response
- * return spi response
- */
-int din_spi_transfer_mst(const uint32_t din_spi_cmd);
+static int din_spi_transfer_mst(const uint32_t din_spi_cmd);
 
 /******************************************************************************
 *   Close variable declaration sections
@@ -95,29 +93,38 @@ int8_t drv_din_ref(uint16_t ref_a, uint16_t ref_b)
 {
 
        uint16_t cmd;
-
-       // Get descriptor
-       uint32_t commands[2];
-       dio_port_desc_t *desc = dio_port_get_dsc(DIO_PORT_NAME_DACDREF, -1);
+       char commands[2];
+       const struct port_desc *port = &port_desc[PORT_ID_DACDREF];
 
        // Send command for DAC A
        cmd = DACA_INIT_VAL | (ref_a & 0x0FFF);
 
        commands[0] = (cmd & 0xFF00) >> 8;
        commands[1] = (cmd & 0xFF);
-       desc->port_setfnc_ptr(desc->config, desc->numValues, commands);
+       port->set(port, commands, sizeof(commands));
 
        // Send command for DAC B
        cmd = DACB_INIT_VAL | (ref_b & 0x0FFF);
 
        commands[0] = (cmd & 0xFF00) >> 8;
        commands[1] = (cmd & 0xFF);
-       desc->port_setfnc_ptr(desc->config, desc->numValues, commands);
+       port->set(port, commands, sizeof(commands));
 
        // Fixme: check SPI return value.
        return SUCCESS;
 }
 
+STATIC_ASSERT(PIN_DIN8  - 0 == PIN_DIN8 &&
+                         PIN_DIN9  - 1 == PIN_DIN8 &&
+                         PIN_DIN10 - 2 == PIN_DIN8 &&
+                         PIN_DIN11 - 3 == PIN_DIN8 &&
+                         PIN_DIN12 - 4 == PIN_DIN8 &&
+                         PIN_DIN13 - 5 == PIN_DIN8 &&
+                         PIN_DIN14 - 6 == PIN_DIN8 &&
+                         PIN_DIN15 - 7 == PIN_DIN8
+                         ,
+                         DIN_pins_are_contiguous); /* The following function relies on this */
+
 
 int8_t drv_din_get_varthr(uint8_t pin)
 {
@@ -126,11 +133,8 @@ int8_t drv_din_get_varthr(uint8_t pin)
        if ((pin < 8) || (pin > 15))
                return FAILURE;
 
-       dio_port_desc_t* port = dio_port_get_dsc(DIO_PORT_NAME_DINMCU, -1);
-       if (pin-8 >= port->numValues)
-               return FAILURE;
-
-       return dio_gpio_pin_get_value(port->config[pin - 8]);
+       /* TODO: Move this function to rpp layer and use rpp_gio_get() */
+       return gio_tab_get(PIN_DIN8 + (pin - 8)) ? 1 : 0;
 }
 
 uint16_t din_get_val_word()
@@ -146,9 +150,9 @@ uint16_t din_get_val_word()
        //  y: Maybe SG13-SG8, but untested.
        //  z: Maybe therm flag and int flag.
        // For SP: First get SP7-SP2 right, then add SP1 and SP0
-       uint16_t sp = ((din_spi_resp << 2) & 0x00FF) | ((din_spi_resp >> 14) & 0x3);
-       uint16_t sg = ((din_spi_resp >> 8) & 0xFF00);
-       uint16_t word = sg | sp;
+       uint16_t sp = (din_spi_resp[0] << 2) | (din_spi_resp[1] >> 6);
+       uint16_t sg = din_spi_resp[2];
+       uint16_t word = (sg << 8) | sp;
 
        return word;
 }
@@ -169,17 +173,21 @@ int din_spi_response()
  * store spi response
  * return spi response
  */
-int din_spi_transfer_mst(const uint32_t din_spi_cmd)
+static int din_spi_transfer_mst(const uint32_t din_spi_cmd)
 {
-       dio_port_desc_t *desc;
+       const struct port_desc* port = &port_desc[PORT_ID_DINSPI];
 
-       desc = dio_port_get_dsc(DIO_PORT_NAME_DINSPI, -1);
-       uint32_t commands[3];
+       char commands[3];
        commands[0] = (din_spi_cmd & 0xFF0000) >> 16;   // command
        commands[1] = (din_spi_cmd & 0xFF00) >> 8;      // 1.st B of data
        commands[2] = (din_spi_cmd & 0xFF);             // 2.nd B of data
 
-       din_spi_resp = desc->port_setfnc_ptr(desc->config, desc->numValues,     \
-                                                                                commands);
-       return din_spi_resp;
+       int8_t ret = port->set(port, commands, sizeof(commands));
+       if (ret == FAILURE)
+               return FAILURE;
+
+       STATIC_ASSERT(sizeof(commands) == sizeof(din_spi_resp), din_spi_buffer_size_missmatch);
+       memcpy(din_spi_resp, commands, sizeof(din_spi_resp));
+
+       return SUCCESS;
 }
index b5be0ebbc578f23e2a62d6cac5c1ff96ad5cef92..a0a645a6300defb3286aefac15fce814a50adfc8 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 2012-2013 Czech Technical University in Prague
+/* Copyright (C) 2012-2013, 2015 Czech Technical University in Prague
  *
  * Authors:
  *     - Michal Horn <hornmich@fel.cvut.cz>
@@ -17,7 +17,7 @@
 #include "drv/drv.h"
 #include "sys/ti_drv_fray.h"
 #include "binary.h"
-#include "drv/digital_io.h"
+#include "drv/port.h"
 
 /**
  * The structure maps a RX/TX buffer to a slot in the communication cycle.
@@ -48,7 +48,7 @@ static uint32_t fray_spi_cmd_sh;
 /** Array of responses for each fray driver */
 static uint32_t fray_spi_resp[FRAY_NUM_PORTS];
 /** Array of port names to be easily accessible by indexing */
-static const char *fray_port_names[FRAY_NUM_PORTS] = { DIO_PORT_NAME_FRAY1, DIO_PORT_NAME_FRAY2 };
+static const int fray_port_names[FRAY_NUM_PORTS] = { PORT_ID_FRAY1, PORT_ID_FRAY2 };
 /** Array of integers, where FlexRay cluster and node configuration
  * parameters are stored to be accessible by indexes defined in Fr_GeneralTypes.h.
  */
@@ -2198,15 +2198,15 @@ Std_ReturnType Fr_ReadCCConfig( uint8_t Fr_CtrlIdx, uint8_t Fr_ConfigParamIdx, u
 int Fr_spi_transfer(uint8_t port)
 {
        uint32_t commands[2];
-       dio_port_desc_t *desc;
+       const struct port_desc *pd;
 
        if (port > FRAY_NUM_PORTS) return -1;
-       desc = dio_port_get_dsc(fray_port_names[port], -1);
+       pd = &port_desc[fray_port_names[port]];
        fray_spi_cmd_sh = fray_spi_cmd;
        commands[0] = (fray_spi_cmd_sh & 0xFF00) >> 8;
        commands[1] = (fray_spi_cmd_sh & 0xFF);
 
-       fray_spi_resp[port] = desc->port_setfnc_ptr(desc->config, desc->numValues, commands);
+       fray_spi_resp[port] = pd->set(pd, commands, sizeof(commands));
        return 0;
 }
 
index 36d0552869c944392f5ca0eb9b5cfdd93ecb858a..0c8066e6cae11cb8151ceccb526dce4a5c1bfc52 100644 (file)
@@ -23,6 +23,7 @@
 #include "drv/drv.h"
 #include <os/semphr.h>
 #include "drv/spi.h"
+#include "drv/gio_tab.h"
 
 //Flag variable if pwm was initialized and is ready to start.
 static boolean_t pwm_initialized = FALSE;
@@ -277,7 +278,7 @@ double drv_hbr_pwm_get_period()
  */
 void drv_hbr_set_dir(int direction)
 {
-       dio_gpio_pin_set_value(*dio_gpio_pin_get_dsc(DIO_PIN_NAME_HBRDIR, -1), direction);
+       gio_tab_set(PIN_HBRDIR, !!direction);
 }
 
 /**
@@ -287,7 +288,7 @@ void drv_hbr_set_dir(int direction)
  */
 int drv_hbr_get_dir()
 {
-       return dio_gpio_pin_get_value(*dio_gpio_pin_get_dsc(DIO_PIN_NAME_HBRDIR, -1));
+       return gio_tab_get(PIN_HBRDIR) ? 1 : 0;
 }
 
 /**
@@ -297,7 +298,7 @@ int drv_hbr_get_dir()
  */
 void drv_hbr_set_en(int value)
 {
-       dio_gpio_pin_set_value(*dio_gpio_pin_get_dsc(DIO_PIN_NAME_HBREN, -1), value);
+       gio_tab_set(PIN_HBREN, !!value);
 }
 
 /**
@@ -307,5 +308,5 @@ void drv_hbr_set_en(int value)
  */
 int drv_hbr_get_en()
 {
-       return dio_gpio_pin_get_value(*dio_gpio_pin_get_dsc(DIO_PIN_NAME_HBREN, -1));
+       return gio_tab_get(PIN_HBREN) ? 1 : 0;
 }
index ebf052531e850ddecae5174444a0bc03989da327..6ea1dfa2ca2d8f22c1cf001485ffc66452696167 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 2012-2013 Czech Technical University in Prague
+/* Copyright (C) 2012-2013, 2015 Czech Technical University in Prague
  *
  * Authors:
  *     - Michal Horn <hornmich@fel.cvut.cz>
@@ -18,6 +18,8 @@
 
 //#include "drv_hout.h"
 #include "drv/drv.h"
+#include "drv/port.h"
+#include "drv/gio_tab.h"
 
 #define HOUT_PWM_INITIALIZED    0x1
 #define HOUT_PWM_RUNNING        0x100
@@ -116,6 +118,24 @@ double hout_pwm_get_period(uint8_t hout_id)
 
 }
 
+STATIC_ASSERT(PIN_HOUT1IN - 0 == PIN_HOUT1IN &&
+                         PIN_HOUT2IN - 2 == PIN_HOUT1IN &&
+                         PIN_HOUT3IN - 4 == PIN_HOUT1IN &&
+                         PIN_HOUT4IN - 6 == PIN_HOUT1IN &&
+                         PIN_HOUT5IN - 8 == PIN_HOUT1IN &&
+                         PIN_HOUT6IN - 10 == PIN_HOUT1IN
+                         ,
+                         HOUTIN_pins_are_ordered_correctly);
+
+STATIC_ASSERT(PIN_HOUT1DIAG - 0 == PIN_HOUT1DIAG &&
+                         PIN_HOUT2DIAG - 2 == PIN_HOUT1DIAG &&
+                         PIN_HOUT3DIAG - 4 == PIN_HOUT1DIAG &&
+                         PIN_HOUT4DIAG - 6 == PIN_HOUT1DIAG &&
+                         PIN_HOUT5DIAG - 8 == PIN_HOUT1DIAG &&
+                         PIN_HOUT6DIAG - 10 == PIN_HOUT1DIAG
+                         ,
+                         HOUTDIAG_pins_are_ordered_correctly);
+
 /**
  * @brief   Runs test of selected HOUT pin.
  *
@@ -139,11 +159,10 @@ int hout_fail(uint8_t hout_id)
        uint32_t i;
        uint16_t pwm_running;
        int err_cnt = 0;
-       dio_port_desc_t* hout_in_port = dio_port_get_dsc(DIO_PORT_NAME_HOUTIN, -1);
-       dio_port_desc_t* hout_diag_port = dio_port_get_dsc(DIO_PORT_NAME_HOUTDIAG, -1);
+       const struct port_desc* hout_in_port = &port_desc[PORT_ID_HOUTIN];
 
 
-       if (hout_id >= dio_port_get_val_cnt(dio_port_get_dsc(DIO_PORT_NAME_HOUTIN, -1)))
+       if (hout_id >= hout_in_port->numchn)
                return -1;   // Bad parameter
        pwm_running = hout_pwm_state & (HOUT_PWM_RUNNING << hout_id);
 
@@ -152,13 +171,13 @@ int hout_fail(uint8_t hout_id)
        else
                hout_pwm_stop(hout_id);
        vTaskDelay(1/portTICK_RATE_MS);
-       dio_gpio_pin_set_value(hout_in_port->config[hout_id], 1);
+       gio_tab_set(PIN_HOUT1IN + (2 * hout_id), 1);
        for (i = 0; i < 4; i++) {
-               if (dio_gpio_pin_get_value(hout_diag_port->config[hout_id]) != 1)
+               if (!gio_tab_get(PIN_HOUT1DIAG + (2 * hout_id)))
                        err_cnt++;  // Input value and output value are not equal
                vTaskDelay(1/portTICK_RATE_MS);
        }
-       dio_gpio_pin_set_value(hout_diag_port->config[hout_id], 0);
+       gio_tab_set(PIN_HOUT1DIAG + (2 * hout_id), 0);
        if (pwm_running) hout_pwm_start(hout_id);
        return (err_cnt == 0) ? HOUT_OK : HOUT_FAILED;
 }
index 88b8088cbcf620c69a2b272de7510d039a88fd0c..e3e8ec47cb52d9d6a2230b493e567ae74ba46a62 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 2012-2013 Czech Technical University in Prague
+/* Copyright (C) 2012-2013, 2015 Czech Technical University in Prague
  *
  * Authors:
  *     - Michal Horn <hornmich@fel.cvut.cz>
@@ -16,6 +16,7 @@
 
 //#include "drv/lout.h"
 #include "drv/drv.h"
+#include "drv/port.h"
 
 /** Prepared spi command */
 uint32_t lout_spi_cmd = LOUT_SPICMD_INIT_VAL;
@@ -131,19 +132,18 @@ uint8_t lout_get_word()
 int lout_spi_transfer()
 {
 
-       dio_port_desc_t *desc;
+       const struct port_desc *port;
 
-       desc = dio_port_get_dsc(DIO_PORT_NAME_LOUT, -1);
+       port = &port_desc[PORT_ID_LOUT];
 
        lout_spi_cmd_sh = lout_spi_cmd;
-       uint32_t commands[4];
+       char commands[4];
        commands[0] = (lout_spi_cmd_sh & 0xFF000000) >> 24;
        commands[1] = (lout_spi_cmd_sh & 0xFF0000) >> 16;
        commands[2] = (lout_spi_cmd_sh & 0xFF00) >> 8;
        commands[3] = (lout_spi_cmd_sh & 0xFF);
 
-       lout_spi_resp = desc->port_setfnc_ptr(desc->config, desc->numValues, commands);
-       return lout_spi_resp;
+       return lout_spi_resp = port->set(port, commands, sizeof(commands));
 }
 
 /**
index a57816ec4ee36f8c4bc3e6cf7a9d2d94a60aef0b..a6359f773369b25ce488c44a1062c090ca25603f 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 2012-2013 Czech Technical University in Prague
+/* Copyright (C) 2012-2013, 2015 Czech Technical University in Prague
  *
  * Authors:
  *     - Carlos Jenkins <carlos@jenkins.co.cr>
 
 
 #include "drv/mout.h"
+#include "drv/port.h"
+#include "drv/gio_names.h"
+
+static enum pin_name in_pin[] = { PIN_MOUT1IN, PIN_MOUT2IN, PIN_MOUT3IN, PIN_MOUT4IN, PIN_MOUT5IN, PIN_MOUT6IN };
+static enum pin_name en_pin[] = { PIN_MOUT1EN, PIN_MOUT2EN, PIN_MOUT3EN, PIN_MOUT4EN, PIN_MOUT5EN, PIN_MOUT6EN };
 
 int8_t drv_mout_set(uint8_t pin, uint8_t val)
 {
@@ -26,22 +31,17 @@ int8_t drv_mout_set(uint8_t pin, uint8_t val)
        if (pin > 5)
                return -1;
 
-       dio_port_desc_t* mout_in_port = dio_port_get_dsc(DIO_PORT_NAME_MOUTIN, -1);
-
-       dio_gpio_pin_set_value(mout_in_port->config[pin], val);
+       gio_set(in_pin[pin], val);
        return SUCCESS;
 }
 
-
 int8_t drv_mout_diag(uint8_t pin)
 {
        // Check range
        if (pin > 5)
                return -1;
 
-       dio_port_desc_t* mout_en_port = dio_port_get_dsc(DIO_PORT_NAME_MOUTEN, -1);
-
-       if (dio_gpio_pin_get_value(mout_en_port->config[pin]) == 1)
+       if (gio_get(en_pin[pin]) == 1)
                return HIGH;
        return LOW;
 }
index 0d3fd7230e6fc59c8a15e68514a0fec677eb6506..cb3e2989dafc4990a884bdb39c8184ae6f802a7d 100644 (file)
@@ -60,7 +60,7 @@
 #include "netif/ppp_oe.h"
 /* end - lwIP headers */
 
-#include "drv/digital_io.h"
+#include "drv/gio.h"
 #include "sys/sys.h" /* includes - sys/phy_dp83848h.h */
 #include "drv/emac.h"
 #include "os/os.h"
@@ -521,17 +521,14 @@ static err_t rpp_eth_hw_init(struct hdkif *hdkif)
         */
        index = configCPU_CLOCK_HZ/1000000;
 #endif /* NO_SYS */
-       dio_gpio_pin_set_value(*dio_gpio_pin_get_dsc(PIN_NAME_ETHRST, -1), 0);
+       dio_pin_set(*dio_gpio_pin_get_dsc(PIN_NAME_ETHRST, -1), 0);
        while (index--) ;
 #endif /* !INIT_ONLY_AFTER_RESET */
-          /* we have pull-down resistor, so after reset, we only need to put ETHRST pin to log. high */
-       dio_gpio_pin_set_value(*dio_gpio_pin_get_dsc(DIO_PIN_NAME_ETHRST, -1), 1);
-
        /*
         * We have pull-down resistor, so after reset, we only need
         * to put ETHRST pin to log. high
         */
-       dio_gpio_pin_set_value(*dio_gpio_pin_get_dsc(DIO_PIN_NAME_ETHRST, -1), 1);
+       gio_set(PIN_ETHRST, 1);
 
        /* Initialize EMAC control module and EMAC module */
        EMACInit(hdkif->emac_ctrl_base, hdkif->emac_base);