#include "drv/dac.h"
+#include "drv/port.h"
#define DAC_PIN_NUM 4
/**
* 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,
};
/**
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));
}
-/* 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];
/******************************************************************************
* 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
{
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)
{
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()
// 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;
}
* 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;
}
-/* 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 "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.
/** 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.
*/
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;
}
#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;
*/
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);
}
/**
*/
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;
}
/**
*/
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);
}
/**
*/
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;
}
-/* 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 "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
}
+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.
*
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);
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;
}
-/* 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 "drv/lout.h"
#include "drv/drv.h"
+#include "drv/port.h"
/** Prepared spi command */
uint32_t lout_spi_cmd = LOUT_SPICMD_INIT_VAL;
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));
}
/**
-/* 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)
{
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;
}
#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"
*/
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);