From 96013f29ca870065ad02502fcd26e8fb6c6cafc0 Mon Sep 17 00:00:00 2001 From: Michal Horn Date: Fri, 17 Jul 2015 10:07:23 +0200 Subject: [PATCH] Merge port and gpio definitions into one file in the DRV layer The idea is to have the pin and port names in a separated target specific header files, the pin and port definitions in a target specific source files and the target independent functions and data types in a common header and source files. The application than should include only one header file digital_io_def.h, where are defined the names of the pins, and digital_io.h where is defined the driver interface. --- Makefile.var | 5 +- rpp/include/drv/_rm48_hdk/digital_io_def.h | 76 ++++ rpp/include/drv/_tms570_hdk/digital_io_def.h | 77 ++++ .../drv/_tms570_hydctr/digital_io_def.h | 77 ++++ rpp/include/drv/_tms570_rpp/digital_io_def.h | 85 ++++ rpp/include/drv/dac.h | 2 +- rpp/include/drv/digital_io.h | 289 +++++++++++++ rpp/include/drv/drv.h | 2 +- rpp/include/drv/mout.h | 2 +- rpp/include/hal/_rm48_hdk/.gitattributes | 2 - rpp/include/hal/_rm48_hdk/gpio_def.h | 186 --------- rpp/include/hal/_rm48_hdk/port_def.h | 66 --- rpp/include/hal/_tms570_hdk/.gitattributes | 2 - rpp/include/hal/_tms570_hdk/gpio_def.h | 186 --------- rpp/include/hal/_tms570_hdk/port_def.h | 67 --- rpp/include/hal/_tms570_hydctr/.gitattributes | 2 - rpp/include/hal/_tms570_hydctr/gpio_def.h | 185 --------- rpp/include/hal/_tms570_hydctr/port_def.h | 67 --- rpp/include/hal/_tms570_rpp/gpio_def.h | 194 --------- rpp/include/hal/_tms570_rpp/port_def.h | 77 ---- rpp/include/hal/hal.h | 207 ---------- rpp/include/rpp/gio.h | 2 +- rpp/src/drv/_rm48_hdk/digital_io_def.c | 230 +++++++++++ rpp/src/drv/_tms570_hdk/digital_io_def.c | 230 +++++++++++ rpp/src/drv/_tms570_hydctr/digital_io_def.c | 229 +++++++++++ rpp/src/drv/_tms570_rpp/digital_io_def.c | 386 ++++++++++++++++++ rpp/src/drv/dac.c | 12 +- rpp/src/drv/digital_io.c | 225 ++++++++++ rpp/src/drv/din.c | 25 +- rpp/src/drv/fr_tms570.c | 8 +- rpp/src/drv/hbridge.c | 8 +- rpp/src/drv/hout.c | 15 +- rpp/src/drv/lout.c | 4 +- rpp/src/drv/mout.c | 18 +- rpp/src/hal/_rm48_hdk/.gitattributes | 2 - rpp/src/hal/_rm48_hdk/gpio_def.c | 97 ----- rpp/src/hal/_rm48_hdk/port_def.c | 127 ------ rpp/src/hal/_tms570_hdk/.gitattributes | 2 - rpp/src/hal/_tms570_hdk/gpio_def.c | 97 ----- rpp/src/hal/_tms570_hdk/port_def.c | 127 ------ rpp/src/hal/_tms570_hydctr/.gitattributes | 2 - rpp/src/hal/_tms570_hydctr/gpio_def.c | 96 ----- rpp/src/hal/_tms570_hydctr/port_def.c | 130 ------ rpp/src/hal/_tms570_rpp/gpio_def.c | 152 ------- rpp/src/hal/_tms570_rpp/port_def.c | 192 --------- rpp/src/hal/hal.c | 225 ---------- rpp/src/hal/spi_resp_transl.c | 16 +- rpp/src/rpp/eth.c | 11 +- rpp/src/rpp/gio.c | 14 +- 49 files changed, 1968 insertions(+), 2570 deletions(-) create mode 100644 rpp/include/drv/_rm48_hdk/digital_io_def.h create mode 100644 rpp/include/drv/_tms570_hdk/digital_io_def.h create mode 100644 rpp/include/drv/_tms570_hydctr/digital_io_def.h create mode 100644 rpp/include/drv/_tms570_rpp/digital_io_def.h create mode 100644 rpp/include/drv/digital_io.h delete mode 100644 rpp/include/hal/_rm48_hdk/.gitattributes delete mode 100644 rpp/include/hal/_rm48_hdk/gpio_def.h delete mode 100644 rpp/include/hal/_rm48_hdk/port_def.h delete mode 100644 rpp/include/hal/_tms570_hdk/.gitattributes delete mode 100644 rpp/include/hal/_tms570_hdk/gpio_def.h delete mode 100644 rpp/include/hal/_tms570_hdk/port_def.h delete mode 100644 rpp/include/hal/_tms570_hydctr/.gitattributes delete mode 100644 rpp/include/hal/_tms570_hydctr/gpio_def.h delete mode 100644 rpp/include/hal/_tms570_hydctr/port_def.h delete mode 100644 rpp/include/hal/_tms570_rpp/gpio_def.h delete mode 100644 rpp/include/hal/_tms570_rpp/port_def.h delete mode 100644 rpp/include/hal/hal.h create mode 100644 rpp/src/drv/_rm48_hdk/digital_io_def.c create mode 100644 rpp/src/drv/_tms570_hdk/digital_io_def.c create mode 100644 rpp/src/drv/_tms570_hydctr/digital_io_def.c create mode 100644 rpp/src/drv/_tms570_rpp/digital_io_def.c create mode 100644 rpp/src/drv/digital_io.c delete mode 100644 rpp/src/hal/_rm48_hdk/.gitattributes delete mode 100644 rpp/src/hal/_rm48_hdk/gpio_def.c delete mode 100644 rpp/src/hal/_rm48_hdk/port_def.c delete mode 100644 rpp/src/hal/_tms570_hdk/.gitattributes delete mode 100644 rpp/src/hal/_tms570_hdk/gpio_def.c delete mode 100644 rpp/src/hal/_tms570_hdk/port_def.c delete mode 100644 rpp/src/hal/_tms570_hydctr/.gitattributes delete mode 100644 rpp/src/hal/_tms570_hydctr/gpio_def.c delete mode 100644 rpp/src/hal/_tms570_hydctr/port_def.c delete mode 100644 rpp/src/hal/_tms570_rpp/gpio_def.c delete mode 100644 rpp/src/hal/_tms570_rpp/port_def.c delete mode 100644 rpp/src/hal/hal.c diff --git a/Makefile.var b/Makefile.var index 899602d..f5bc3b7 100644 --- a/Makefile.var +++ b/Makefile.var @@ -39,9 +39,8 @@ rpp_lib_SOURCES += \ rpp/src/rpp/sci.c \ rpp/src/drv/_$(TARGET)/adc.c \ rpp/src/drv/sci.c \ - rpp/src/hal/hal.c \ - rpp/src/hal/_$(TARGET)/gpio_def.c \ - rpp/src/hal/_$(TARGET)/port_def.c \ + rpp/src/drv/_$(TARGET)/digital_io_def.c \ + rpp/src/drv/digital_io.c \ rpp/src/sys/asm/dabort.asm \ rpp/src/sys/asm/sys_core.asm \ rpp/src/sys/asm/sys_intvecs.asm \ diff --git a/rpp/include/drv/_rm48_hdk/digital_io_def.h b/rpp/include/drv/_rm48_hdk/digital_io_def.h new file mode 100644 index 0000000..15ed893 --- /dev/null +++ b/rpp/include/drv/_rm48_hdk/digital_io_def.h @@ -0,0 +1,76 @@ +/** + * + * @file digital_io_def.h + * + * @copyright Copyright (C) 2012-2013 Czech Technical University in Prague + * + * @author Michal Horn + */ + +#ifndef DIGITAL_IO_DEF_H_ +#define DIGITAL_IO_DEF_H_ + +#define DIO_MAX_PIN_CNT 46 +#define DIO_MAX_PORT_CNT 5 + +/* Pin names */ +#define DIO_PIN_NAME_GIOA0 "GIOA0" +#define DIO_PIN_NAME_GIOA1 "GIOA1" +#define DIO_PIN_NAME_GIOA2 "GIOA2" +#define DIO_PIN_NAME_GIOA3 "GIOA3" +#define DIO_PIN_NAME_GIOA4 "GIOA4" +#define DIO_PIN_NAME_GIOA5 "GIOA5" +#define DIO_PIN_NAME_GIOA6 "GIOA6" +#define DIO_PIN_NAME_GIOA7 "GIOA7" + +#define DIO_PIN_NAME_GIOB0 "GIOB0" +#define DIO_PIN_NAME_GIOB1 "GIOB1" +#define DIO_PIN_NAME_GIOB2 "GIOB2" +#define DIO_PIN_NAME_GIOB3 "GIOB3" +#define DIO_PIN_NAME_GIOB4 "GIOB4" +#define DIO_PIN_NAME_GIOB5 "GIOB5" +#define DIO_PIN_NAME_GIOB6 "GIOB6" +#define DIO_PIN_NAME_GIOB7 "GIOB7" + +#define DIO_PIN_NAME_NHET1_0 "NHET10" +#define DIO_PIN_NAME_NHET1_1 "NHET11" +#define DIO_PIN_NAME_NHET1_2 "NHET12" +#define DIO_PIN_NAME_NHET1_3 "NHET13" +#define DIO_PIN_NAME_NHET1_4 "NHET14" +#define DIO_PIN_NAME_NHET1_5 "NHET15" +#define DIO_PIN_NAME_NHET1_6 "NHET16" +#define DIO_PIN_NAME_NHET1_7 "NHET17" +#define DIO_PIN_NAME_NHET1_8 "NHET18" +#define DIO_PIN_NAME_NHET1_9 "NHET19" +#define DIO_PIN_NAME_NHET1_10 "NHET110" +#define DIO_PIN_NAME_NHET1_11 "NHET111" +#define DIO_PIN_NAME_NHET1_12 "NHET112" +#define DIO_PIN_NAME_NHET1_13 "NHET113" +#define DIO_PIN_NAME_NHET1_14 "NHET114" +#define DIO_PIN_NAME_NHET1_15 "NHET115" +#define DIO_PIN_NAME_NHET1_16 "NHET116" +#define DIO_PIN_NAME_NHET1_17 "NHET117" +#define DIO_PIN_NAME_NHET1_18 "NHET118" +#define DIO_PIN_NAME_NHET1_19 "NHET119" +#define DIO_PIN_NAME_NHET1_20 "NHET120" +#define DIO_PIN_NAME_NHET1_21 "NHET121" +#define DIO_PIN_NAME_NHET1_22 "NHET122" +#define DIO_PIN_NAME_NHET1_23 "NHET123" +#define DIO_PIN_NAME_NHET1_24 "NHET124" +#define DIO_PIN_NAME_NHET1_25 "NHET125" +#define DIO_PIN_NAME_NHET1_26 "NHET126" +#define DIO_PIN_NAME_NHET1_27 "NHET127" +#define DIO_PIN_NAME_NHET1_28 "NHET128" +#define DIO_PIN_NAME_NHET1_29 "NHET129" +#define DIO_PIN_NAME_NHET1_30 "NHET130" +#define DIO_PIN_NAME_NHET1_31 "NHET131" +#define DIO_PIN_NAME_UNUSED "unused" + +#define DIO_PORT_CNT 4 +#define DIO_PORT_SHIFT 5 +/* Port names */ +#define DIO_PORT_NAME_GIOA "GIOA" +#define DIO_PORT_NAME_GIOB "GIOB" +#define DIO_PORT_NAME_NHET1 "NHET1" +#define DIO_PORT_NAME_ADC "ADC" +#endif /* DIGITAL_IO_DEF_H_ */ diff --git a/rpp/include/drv/_tms570_hdk/digital_io_def.h b/rpp/include/drv/_tms570_hdk/digital_io_def.h new file mode 100644 index 0000000..c24bf79 --- /dev/null +++ b/rpp/include/drv/_tms570_hdk/digital_io_def.h @@ -0,0 +1,77 @@ +/** + * + * @file digital_io_def.h + * + * @copyright Copyright (C) 2012-2013 Czech Technical University in Prague + * + * @author Michal Horn + */ + +#ifndef DIGITAL_IO_DEF_H_ +#define DIGITAL_IO_DEF_H_ + +#define DIO_MAX_PIN_CNT 46 +#define DIO_MAX_PORT_CNT 5 + +/* Pin names */ +#define DIO_PIN_NAME_GIOA0 "GIOA0" +#define DIO_PIN_NAME_GIOA1 "GIOA1" +#define DIO_PIN_NAME_GIOA2 "GIOA2" +#define DIO_PIN_NAME_GIOA3 "GIOA3" +#define DIO_PIN_NAME_GIOA4 "GIOA4" +#define DIO_PIN_NAME_GIOA5 "GIOA5" +#define DIO_PIN_NAME_GIOA6 "GIOA6" +#define DIO_PIN_NAME_GIOA7 "GIOA7" + +#define DIO_PIN_NAME_GIOB0 "GIOB0" +#define DIO_PIN_NAME_GIOB1 "GIOB1" +#define DIO_PIN_NAME_GIOB2 "GIOB2" +#define DIO_PIN_NAME_GIOB3 "GIOB3" +#define DIO_PIN_NAME_GIOB4 "GIOB4" +#define DIO_PIN_NAME_GIOB5 "GIOB5" +#define DIO_PIN_NAME_GIOB6 "GIOB6" +#define DIO_PIN_NAME_GIOB7 "GIOB7" + +#define DIO_PIN_NAME_NHET1_0 "NHET10" +#define DIO_PIN_NAME_NHET1_1 "NHET11" +#define DIO_PIN_NAME_NHET1_2 "NHET12" +#define DIO_PIN_NAME_NHET1_3 "NHET13" +#define DIO_PIN_NAME_NHET1_4 "NHET14" +#define DIO_PIN_NAME_NHET1_5 "NHET15" +#define DIO_PIN_NAME_NHET1_6 "NHET16" +#define DIO_PIN_NAME_NHET1_7 "NHET17" +#define DIO_PIN_NAME_NHET1_8 "NHET18" +#define DIO_PIN_NAME_NHET1_9 "NHET19" +#define DIO_PIN_NAME_NHET1_10 "NHET110" +#define DIO_PIN_NAME_NHET1_11 "NHET111" +#define DIO_PIN_NAME_NHET1_12 "NHET112" +#define DIO_PIN_NAME_NHET1_13 "NHET113" +#define DIO_PIN_NAME_NHET1_14 "NHET114" +#define DIO_PIN_NAME_NHET1_15 "NHET115" +#define DIO_PIN_NAME_NHET1_16 "NHET116" +#define DIO_PIN_NAME_NHET1_17 "NHET117" +#define DIO_PIN_NAME_NHET1_18 "NHET118" +#define DIO_PIN_NAME_NHET1_19 "NHET119" +#define DIO_PIN_NAME_NHET1_20 "NHET120" +#define DIO_PIN_NAME_NHET1_21 "NHET121" +#define DIO_PIN_NAME_NHET1_22 "NHET122" +#define DIO_PIN_NAME_NHET1_23 "NHET123" +#define DIO_PIN_NAME_NHET1_24 "NHET124" +#define DIO_PIN_NAME_NHET1_25 "NHET125" +#define DIO_PIN_NAME_NHET1_26 "NHET126" +#define DIO_PIN_NAME_NHET1_27 "NHET127" +#define DIO_PIN_NAME_NHET1_28 "NHET128" +#define DIO_PIN_NAME_NHET1_29 "NHET129" +#define DIO_PIN_NAME_NHET1_30 "NHET130" +#define DIO_PIN_NAME_NHET1_31 "NHET131" +#define DIO_PIN_NAME_UNUSED "unused" + +#define DIO_PORT_CNT 4 +#define DIO_PORT_SHIFT 5 +/* Port names */ +#define DIO_PORT_NAME_GIOA "GIOA" +#define DIO_PORT_NAME_GIOB "GIOB" +#define DIO_PORT_NAME_NHET1 "NHET1" +#define DIO_PORT_NAME_ADC "ADC" + +#endif /* DIGITAL_IO_DEF_H_ */ diff --git a/rpp/include/drv/_tms570_hydctr/digital_io_def.h b/rpp/include/drv/_tms570_hydctr/digital_io_def.h new file mode 100644 index 0000000..c24bf79 --- /dev/null +++ b/rpp/include/drv/_tms570_hydctr/digital_io_def.h @@ -0,0 +1,77 @@ +/** + * + * @file digital_io_def.h + * + * @copyright Copyright (C) 2012-2013 Czech Technical University in Prague + * + * @author Michal Horn + */ + +#ifndef DIGITAL_IO_DEF_H_ +#define DIGITAL_IO_DEF_H_ + +#define DIO_MAX_PIN_CNT 46 +#define DIO_MAX_PORT_CNT 5 + +/* Pin names */ +#define DIO_PIN_NAME_GIOA0 "GIOA0" +#define DIO_PIN_NAME_GIOA1 "GIOA1" +#define DIO_PIN_NAME_GIOA2 "GIOA2" +#define DIO_PIN_NAME_GIOA3 "GIOA3" +#define DIO_PIN_NAME_GIOA4 "GIOA4" +#define DIO_PIN_NAME_GIOA5 "GIOA5" +#define DIO_PIN_NAME_GIOA6 "GIOA6" +#define DIO_PIN_NAME_GIOA7 "GIOA7" + +#define DIO_PIN_NAME_GIOB0 "GIOB0" +#define DIO_PIN_NAME_GIOB1 "GIOB1" +#define DIO_PIN_NAME_GIOB2 "GIOB2" +#define DIO_PIN_NAME_GIOB3 "GIOB3" +#define DIO_PIN_NAME_GIOB4 "GIOB4" +#define DIO_PIN_NAME_GIOB5 "GIOB5" +#define DIO_PIN_NAME_GIOB6 "GIOB6" +#define DIO_PIN_NAME_GIOB7 "GIOB7" + +#define DIO_PIN_NAME_NHET1_0 "NHET10" +#define DIO_PIN_NAME_NHET1_1 "NHET11" +#define DIO_PIN_NAME_NHET1_2 "NHET12" +#define DIO_PIN_NAME_NHET1_3 "NHET13" +#define DIO_PIN_NAME_NHET1_4 "NHET14" +#define DIO_PIN_NAME_NHET1_5 "NHET15" +#define DIO_PIN_NAME_NHET1_6 "NHET16" +#define DIO_PIN_NAME_NHET1_7 "NHET17" +#define DIO_PIN_NAME_NHET1_8 "NHET18" +#define DIO_PIN_NAME_NHET1_9 "NHET19" +#define DIO_PIN_NAME_NHET1_10 "NHET110" +#define DIO_PIN_NAME_NHET1_11 "NHET111" +#define DIO_PIN_NAME_NHET1_12 "NHET112" +#define DIO_PIN_NAME_NHET1_13 "NHET113" +#define DIO_PIN_NAME_NHET1_14 "NHET114" +#define DIO_PIN_NAME_NHET1_15 "NHET115" +#define DIO_PIN_NAME_NHET1_16 "NHET116" +#define DIO_PIN_NAME_NHET1_17 "NHET117" +#define DIO_PIN_NAME_NHET1_18 "NHET118" +#define DIO_PIN_NAME_NHET1_19 "NHET119" +#define DIO_PIN_NAME_NHET1_20 "NHET120" +#define DIO_PIN_NAME_NHET1_21 "NHET121" +#define DIO_PIN_NAME_NHET1_22 "NHET122" +#define DIO_PIN_NAME_NHET1_23 "NHET123" +#define DIO_PIN_NAME_NHET1_24 "NHET124" +#define DIO_PIN_NAME_NHET1_25 "NHET125" +#define DIO_PIN_NAME_NHET1_26 "NHET126" +#define DIO_PIN_NAME_NHET1_27 "NHET127" +#define DIO_PIN_NAME_NHET1_28 "NHET128" +#define DIO_PIN_NAME_NHET1_29 "NHET129" +#define DIO_PIN_NAME_NHET1_30 "NHET130" +#define DIO_PIN_NAME_NHET1_31 "NHET131" +#define DIO_PIN_NAME_UNUSED "unused" + +#define DIO_PORT_CNT 4 +#define DIO_PORT_SHIFT 5 +/* Port names */ +#define DIO_PORT_NAME_GIOA "GIOA" +#define DIO_PORT_NAME_GIOB "GIOB" +#define DIO_PORT_NAME_NHET1 "NHET1" +#define DIO_PORT_NAME_ADC "ADC" + +#endif /* DIGITAL_IO_DEF_H_ */ diff --git a/rpp/include/drv/_tms570_rpp/digital_io_def.h b/rpp/include/drv/_tms570_rpp/digital_io_def.h new file mode 100644 index 0000000..f009d77 --- /dev/null +++ b/rpp/include/drv/_tms570_rpp/digital_io_def.h @@ -0,0 +1,85 @@ +/** + * + * @file digital_io_def.h + * + * @copyright Copyright (C) 2012-2013 Czech Technical University in Prague + * + * @author Michal Horn + */ + +#ifndef DIGITAL_IO_DEF_H_ +#define DIGITAL_IO_DEF_H_ + +#define DIO_MAX_PIN_CNT 103 +#define DIO_MAX_PORT_CNT 5 +/* Pin names */ +#define DIO_PIN_NAME_DIN8 "DIN8" +#define DIO_PIN_NAME_DIN9 "DIN9" +#define DIO_PIN_NAME_DIN10 "DIN10" +#define DIO_PIN_NAME_DIN11 "DIN11" +#define DIO_PIN_NAME_DIN12 "DIN12" +#define DIO_PIN_NAME_DIN13 "DIN13" +#define DIO_PIN_NAME_DIN14 "DIN14" +#define DIO_PIN_NAME_DIN15 "DIN15" +#define DIO_PIN_NAME_DININT "DININT" +#define DIO_PIN_NAME_HOUT1IN "HOUT1IN" +#define DIO_PIN_NAME_HOUT2IN "HOUT2IN" +#define DIO_PIN_NAME_HOUT3IN "HOUT3IN" +#define DIO_PIN_NAME_HOUT4IN "HOUT4IN" +#define DIO_PIN_NAME_HOUT5IN "HOUT5IN" +#define DIO_PIN_NAME_HOUT6IN "HOUT6IN" +#define DIO_PIN_NAME_HOUT1DIAG "HOUT1DIAG" +#define DIO_PIN_NAME_HOUT2DIAG "HOUT2DIAG" +#define DIO_PIN_NAME_HOUT3DIAG "HOUT3DIAG" +#define DIO_PIN_NAME_HOUT4DIAG "HOUT4DIAG" +#define DIO_PIN_NAME_HOUT5DIAG "HOUT5DIAG" +#define DIO_PIN_NAME_HOUT6DIAG "HOUT6DIAG" +#define DIO_PIN_NAME_MOUT1IN "MOUT1IN" +#define DIO_PIN_NAME_MOUT2IN "MOUT2IN" +#define DIO_PIN_NAME_MOUT3IN "MOUT3IN" +#define DIO_PIN_NAME_MOUT4IN "MOUT4IN" +#define DIO_PIN_NAME_MOUT5IN "MOUT5IN" +#define DIO_PIN_NAME_MOUT6IN "MOUT6IN" +#define DIO_PIN_NAME_MOUT1EN "MOUT1EN" +#define DIO_PIN_NAME_MOUT2EN "MOUT2EN" +#define DIO_PIN_NAME_MOUT3EN "MOUT3EN" +#define DIO_PIN_NAME_MOUT4EN "MOUT4EN" +#define DIO_PIN_NAME_MOUT5EN "MOUT5EN" +#define DIO_PIN_NAME_MOUT6EN "MOUT6EN" +#define DIO_PIN_NAME_VBAT1EN "VBAT1EN" +#define DIO_PIN_NAME_VBAT2EN "VBAT2EN" +#define DIO_PIN_NAME_VBAT3EN "VBAT3EN" +#define DIO_PIN_NAME_VBATEN "VBATEN" +#define DIO_PIN_NAME_FANCTRL "FANCTRL" +#define DIO_PIN_NAME_ETHRST "ETHRST" +#define DIO_PIN_NAME_SPICSA "SPICSA" +#define DIO_PIN_NAME_SPICSB "SPICSB" +#define DIO_PIN_NAME_CANNSTB "CANNSTB" +#define DIO_PIN_NAME_CANEN "CANEN" +#define DIO_PIN_NAME_LIN2NSLP "LIN2NSLP" +#define DIO_PIN_NAME_LIN1NSLP "LIN1NSLP" +#define DIO_PIN_NAME_HBREN "HBREN" +#define DIO_PIN_NAME_HBRDIR "HBRDIR" +#define DIO_PIN_NAME_HBRPWM "HBRPWM" +#define DIO_PIN_NAME_UNUSED NULL + +#define DIO_PORT_CNT 15 +#define DIO_PORT_SHIFT 5 +/* Port names */ +#define DIO_PORT_NAME_DINMCU "DINMCU" +#define DIO_PORT_NAME_DINSPI "DINSPI" +#define DIO_PORT_NAME_HOUTDIAG "HOUTDIAG" +#define DIO_PORT_NAME_HOUTIN "HOUTIN" +#define DIO_PORT_NAME_HOUTIFBK "HOUTIFBK" +#define DIO_PORT_NAME_ADC "ADC" +#define DIO_PORT_NAME_LOUT "LOUT" +#define DIO_PORT_NAME_DAC1_2 "DAC12" +#define DIO_PORT_NAME_DAC3_4 "DAC34" +#define DIO_PORT_NAME_DACDREF "DACDREF" +#define DIO_PORT_NAME_HBR "HBR" +#define DIO_PORT_NAME_FRAY1 "FRAY1" +#define DIO_PORT_NAME_FRAY2 "FRAY2" +#define DIO_PORT_NAME_MOUTEN "MOUTEN" +#define DIO_PORT_NAME_MOUTIN "MOUTIN" + +#endif /* DIGITAL_IO_DEF_H_ */ diff --git a/rpp/include/drv/dac.h b/rpp/include/drv/dac.h index cd9972e..1bbdfdf 100644 --- a/rpp/include/drv/dac.h +++ b/rpp/include/drv/dac.h @@ -13,7 +13,7 @@ #ifndef __DRV_DAC_H #define __DRV_DAC_H -#include "hal/hal.h" +#include "drv/digital_io.h" /** diff --git a/rpp/include/drv/digital_io.h b/rpp/include/drv/digital_io.h new file mode 100644 index 0000000..f3758b2 --- /dev/null +++ b/rpp/include/drv/digital_io.h @@ -0,0 +1,289 @@ +/** + * Hardware Abstraction Layer library interface file. + * + * @file hal.h + * + * @copyright Copyright (C) 2013, 2015 Czech Technical University in Prague + * + * @author Carlos Jenkins + */ + +#ifndef __HAL_H +#define __HAL_H + +#include "sys/sys.h" + +#if defined(TARGET_POSIX) +#include "drv/_rm48_hdk/digital_io_def.h" +#elif defined(TARGET_RM48_HDK) +#include "drv/_rm48_hdk/digital_io_def.h" +#elif defined(TARGET_TMS570_HDK) +#include "drv/_tms570_hdk/digital_io_def.h" +#elif defined(TARGET_TMS570_HYDCTR) +#include "drv/_tms570_hydctr/digital_io_def.h" +#elif defined(TARGET_TMS570_RPP) +#include "drv/_tms570_rpp/digital_io_def.h" +#else +#error No supported target specified! +#endif + +typedef struct dio_pin_map_element { + const char *pin_name; // Pin name + uint32_t pin_desc; // Pin descriptor assigned to the pin name +} dio_pin_map_element_t; + +enum dio_port_interface_type { + ADC = 1, + SPI, + GPIO +}; + +/** + * @brief Port descriptor + * + * The structure describes the port. Port here means set of IO pins on the board. + * The API is designed to provide an interface for setting and reading from ports connected to the MCU by SPI, GPIO or ADC. + */ +typedef struct dio_port_desc_st { + uint32_t *config; /**< Configuration of the port. An arry of values, which meaning differs for the interface type: + for SPI: address, chip-select + for GPIO: descriptors for pins (defined in gpio_tms570_def.h) + for ADC: ADC base address, ADC group number, Peripheral type (HOUTIFBK or ADC) + */ + uint32_t numValues; /**< Size of the data to be read from or written on the port. Meaning differs for the interface type: + for SPI: size of the command in bytes + for GPIO: number of pins on the port + for ADC: number of channels to be read from ADC. + */ + enum dio_port_interface_type interfaceType; /**< Type of the interface to which the port or its controller is connected. + Can be SPI, ADC or GPIO + */ + uint32_t (*port_getfnc_ptr)(uint32_t *config, uint32_t num_val, uint32_t *values); /**< Pointer to a getter function. If it is NULL, than port is write only. + All SPI ports are write only, because command has to be sent to obtain actual response. + It is allowed to read values from an output port. + */ + uint32_t (*port_setfnc_ptr)(uint32_t *config, uint32_t num_val, const uint32_t *values); /**< Pointer to a setter function. If it is NULL, than port is read only. + All ADC ports are read only. + It is not allowed to write values on an input port. + */ +} dio_port_desc_t; + +/** + * Maps port descriptor to the port name + */ +typedef struct dio_port_def_st { + char *name; + dio_port_desc_t *desc; +} dio_port_def_t; + +#define DIO_PORT_CONF_MASK 0xff000000 + +#define DIO_PORT_CONF_DIR_MASK 0x01000000 +#define DIO_PORT_CONF_DIR_IN (0x00000000 | DIO_PORT_CONF_SET_DIR) +#define DIO_PORT_CONF_DIR_OUT (0x01000000 | DIO_PORT_CONF_SET_DIR) + +#define DIO_PORT_CONF_INIT_MASK 0x02000000 +#define DIO_PORT_CONF_INIT_LOW 0x00000000 +#define DIO_PORT_CONF_INIT_HIGH 0x02000000 + +#define DIO_PORT_CONF_OD_MASK 0x04000000 +#define DIO_PORT_CONF_OD_OFF 0x00000000 +#define DIO_PORT_CONF_OD_ON 0x04000000 + +#define DIO_PORT_CONF_SET_DIR 0x08000000 + +#define DIO_PORT_CONF_MODE_MASK 0x30000000 +#define DIO_PORT_CONF_MODE_PTYPE_MASK 0x10000000 +#define DIO_PORT_CONF_MODE_PEN_MASK 0x20000000 +#define DIO_PORT_CONF_MODE_PU 0x10000000 // Pull-up +#define DIO_PORT_CONF_MODE_PD 0x00000000 // Pull-down +#define DIO_PORT_CONF_MODE_PEN 0x00000000 // Pull resistor enable +#define DIO_PORT_CONF_MODE_PDIS 0x20000000 // Pull resistor disable + +#define DIO_PORT_CONF_FNC_MASK 0xc0000000 +#define DIO_PORT_CONF_FNC_GPIO 0x00000000 +#define DIO_PORT_CONF_FNC_0 0x00000000 +#define DIO_PORT_CONF_FNC_1 0x40000000 +#define DIO_PORT_CONF_FNC_2 0x80000000 +#define DIO_PORT_CONF_FNC_3 0xc0000000 + +/* Port indexes to portmap */ +#define DIO_PORT_ID_DMM 0x0 +#define DIO_PORT_ID_GIOA 0x1 +#define DIO_PORT_ID_GIOB 0x2 +#define DIO_PORT_ID_HET1 0x3 +#define DIO_PORT_ID_HET2 0x4 + +uint8_t dio_gpio_get_pin_cnt(); + +dio_pin_map_element_t* dio_gpio_get_pin_map(); + +/** + * Get port base assigned to port number + * @param[in] port_num Port number <0;4> + * @return Pointer to port registers + */ +gioPORT_t *dio_gpio_get_port_base(uint32_t port_num); + +/** + * Get port number assigned to pin in its descriptor + * @param[in] pin descriptor + * @return Index of port + */ +uint32_t dio_gpio_pin_get_port_num(uint32_t pin_dsc); + +/** + * Get port base from pin descriptor + * Combines two upper defined functions + * @param[in] pin_dcs Pin descriptor + * @return Pointer to port registers + */ +gioPORT_t *dio_gpio_pin_get_port_base(uint32_t pin_dsc); + +/** + * Get pin descriptor assigned to pin name. + * @param[in] pin_name Pointer to string - the name of the pin. + * @param[in] len Length of the name, if terminated by '/0', then len=-1 + * @return Pin descriptor or NULL if not found + */ +uint32_t *dio_gpio_pin_get_dsc(const char *pin_name, int len); + +/** + * Get value from GPIO pin + * @param[in] pin_dsc pin descriptor + * @return value read from specified gpio pin + */ +uint32_t dio_gpio_pin_get_value(uint32_t pin_dsc); + +/** + * Set value to gpio pin + * @param[in] pin_dsc pin descriptor + * @param[in] value value to be assigned to the pin + */ +void dio_gpio_pin_set_value(uint32_t pin_dsc, uint32_t value); + +/** + * Set pin direction to input + * @param[in] pin_dsc pin descriptor + * @return always 0 + */ +int dio_gpio_pin_set_dir_in(uint32_t pin_dsc); + +/** + * Set pin direction to output + * @param[in] pin_dsc pin descriptor + * @return always 0 + */ +int dio_gpio_pin_set_dir_out(uint32_t pin_dsc, uint32_t value); + +/** + * Get pin direction + * @param[in] pin_dsc pin descriptor + * @return 1 - output, 0 - input + */ +int dio_gpio_pin_get_dir(uint32_t pin_dsc); + +/** + * Set pin as pull down or pull up and pull resistor enabled or disabled. + * @param[in] pin_dsc Descriptor of the pin + * @param[in] Mode on which pin will be configured to. + * PORT_CONF_MODE_PU - pull up + * PORT_CONF_MODE_PD - pull down + * must be | with + * PORT_CONF_MODE_PEN - pull resistor enable + * PORT_CONF_MODE_PDIS - pull resistor disable + * @return always 0 + */ +uint32_t dio_gpio_pin_set_mode(uint32_t pin_dsc, uint32_t mode); + +/** + * Configure pin to be open drain or not + * @param[in] pin_dsc Descriptor of the pin + * @param[in] Mode on which pin will be configured to. + * PORT_CONF_OD_OFF - open-drain disabled + * PORT_CONF_OD_ON - open drain enabled + * + * @return always 0 + */ +uint32_t dio_gpio_pin_set_od(uint32_t pin_dsc, uint32_t od); + +/** + * Configure pin + * @param[in] pin_dsc Descriptor of the pin + * @param[in] Mode on which pin will be configured to. + * PORT_CONF_OD_OFF - open-drain disabled + * PORT_CONF_OD_ON - open drain enabled + * + * PORT_CONF_MODE_PU - pull up + * PORT_CONF_MODE_PD - pull down + * + * PORT_CONF_MODE_PEN - pull resistor enable + * PORT_CONF_MODE_PDIS - pull resistor disable + * + * PORT_CONF_DIR_IN - direction input + * PORT_CONF_DIR_OUT - direction output + * + * PORT_CONF_INIT_LOW - init value 0 + * PORT_CONF_INIT_HIGH - init value 1 + * + * PORT_CONF_FNC_GPIO - port function GPIO + * PORT_CONF_FNC_FNCX - port alternate function X + * + * @return always 0 + */ +uint32_t dio_gpio_pin_set_config(uint32_t pin_dsc, uint32_t conf); + +/** + * Do the initial pin configuration according values in pin descriptor + * @param[in] pin_dsc pin descriptor + * @return always 0; + */ +uint32_t dio_gpio_pin_configure(uint32_t pin_dsc); + +/** + * Get values of all pins of given port. + * @param[in] config Pointer to array of pin descriptors + * @param[in] num_val Number of pins assigned to the port + * @param[out] values Stored values of all pins of the port. 1st bit -> pin0, 2nd bit -> pin1... + * @return always 0 + */ +uint32_t dio_gpio_port_get_val(uint32_t *config, uint32_t num_val, uint32_t *values); + +/** + * Set values to all pins of given port. + * @param[in] config Pointer to array of pin descriptors + * @param[in] num_val Number of pins assigned to the port + * @param[in] values Stored values of all pins of the port. 1st bit -> pin0, 2nd bit -> pin1... + * @return always 0 + */ +uint32_t dio_gpio_port_set_val(uint32_t *config, uint32_t num_val, const uint32_t *values); + +/** + * Get port descriptor assigned to port name. + * @param[in] port_name Pointer to string - the name of the port. + * @param[in] len Length of the name, if terminated by '/0', then len=-1 + * @return Port descriptor or NULL if not found + */ +const dio_port_def_t *dio_port_get_map(); + +/** + * Get port descriptor assigned to port name. + * @param[in] port_name Pointer to string - the name of the port. + * @param[in] len Length of the name, if terminated by '/0', then len=-1 + * @return Port descriptor or NULL if not found + */ +dio_port_desc_t *dio_port_get_dsc(const char *port_name, int len); + +uint32_t dio_port_get_val_cnt(const dio_port_desc_t* port_desc); + +/** + * Transfer command through the spi + * @param[in] config Address of the SPI + * @param[in] num_bytes Number of bytes to be trasfered + * @param[in] commands SPI command to be sent + * @return spi response + */ +uint32_t dio_spi_port_transfer_command(uint32_t *config, uint32_t num_bytes, const uint32_t *commands); + + +#endif /* __HAL_H */ diff --git a/rpp/include/drv/drv.h b/rpp/include/drv/drv.h index 4c72c25..f075eff 100644 --- a/rpp/include/drv/drv.h +++ b/rpp/include/drv/drv.h @@ -11,7 +11,7 @@ #ifndef __DRV_H #define __DRV_H -#include "hal/hal.h" +#include "drv/digital_io.h" #include "drv/adc.h" #include "drv/sci.h" diff --git a/rpp/include/drv/mout.h b/rpp/include/drv/mout.h index a74a027..00f8809 100644 --- a/rpp/include/drv/mout.h +++ b/rpp/include/drv/mout.h @@ -12,7 +12,7 @@ #ifndef __DRV_MOUT_H #define __DRV_MOUT_H -#include "hal/hal.h" +#include "drv/digital_io.h" // FIXME Document. int8_t drv_mout_set(uint8_t pin, uint8_t val); diff --git a/rpp/include/hal/_rm48_hdk/.gitattributes b/rpp/include/hal/_rm48_hdk/.gitattributes deleted file mode 100644 index 463133b..0000000 --- a/rpp/include/hal/_rm48_hdk/.gitattributes +++ /dev/null @@ -1,2 +0,0 @@ -/gpio_def.h eaton -/port_def.h eaton diff --git a/rpp/include/hal/_rm48_hdk/gpio_def.h b/rpp/include/hal/_rm48_hdk/gpio_def.h deleted file mode 100644 index 60f1dc8..0000000 --- a/rpp/include/hal/_rm48_hdk/gpio_def.h +++ /dev/null @@ -1,186 +0,0 @@ -/* Copyright (C) 2013-2015 Czech Technical University in Prague - * Authors: - * - Michal Horn - * - * 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. - */ - -#ifndef HAL_GPIO_RM48_DEF_H_ -#define HAL_GPIO_RM48_DEF_H_ - -#include "hal/hal.h" - - -#ifndef PORT_SHIFT -#define PORT_SHIFT 5 -#endif -#ifndef PORT_PIN -#define PORT_PIN(p,n,conf) (((p)< - * - * 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. - */ - -#ifndef PORT_DEF_H_ -#define PORT_DEF_H_ - -#include "types.h" - -enum port_interface_type { - ADC = 1, - SPI, - GPIO -}; -/** - * @brief Port descriptor - * - * The structure describes the port. Port here means set of IO pins on the board. - * The API is designed to provide an interface for setting and reading from ports connected to the MCU by SPI, GPIO or ADC. - */ -typedef struct port_desc_st { - uint32_t *config; /**< Configuration of the port. An array of values, which meaning differs for the interface type: - for SPI: address, chip-select - for GPIO: descriptors for pins (defined in gpio_rm48_def.h) - for ADC: ADC base address, ADC group number, Peripheral type (HOUTIFBK or ADC) - */ - uint32_t numValues; /**< Size of the data to be read from or written on the port. Meaning differs for the interface type: - for SPI: size of the command in bytes - for GPIO: number of pins on the port - for ADC: number of channels to be read from ADC. - */ - enum port_interface_type interfaceType; /**< Type of the interface to which the port or its controller is connected. - Can be SPI, ADC or GPIO - */ - uint32_t (*port_getfnc_ptr)(uint32_t *config, uint32_t num_val, uint32_t *values); /**< Pointer to a getter function. If it is NULL, than port is write only. - All SPI ports are write only, because command has to be sent to obtain actual response. - It is allowed to read values from an output port. - */ - uint32_t (*port_setfnc_ptr)(uint32_t *config, uint32_t num_val, const uint32_t *values); /**< Pointer to a setter function. If it is NULL, than port is read only. - All ADC ports are read only. - It is not allowed to write values on an input port. - */ -} port_desc_t; - -/** - * Maps port descriptor to the port name - */ -typedef struct port_def_st { - char *name; - port_desc_t *desc; -} port_def_t; - -#define PORT_CNT 4 - -#define PORT_NAME_GIOA "GIOA" -#define PORT_NAME_GIOB "GIOB" -#define PORT_NAME_NHET1 "NHET1" -#define PORT_NAME_ADC "ADC" - -#endif /* PORT_DEF_H_ */ diff --git a/rpp/include/hal/_tms570_hdk/.gitattributes b/rpp/include/hal/_tms570_hdk/.gitattributes deleted file mode 100644 index 463133b..0000000 --- a/rpp/include/hal/_tms570_hdk/.gitattributes +++ /dev/null @@ -1,2 +0,0 @@ -/gpio_def.h eaton -/port_def.h eaton diff --git a/rpp/include/hal/_tms570_hdk/gpio_def.h b/rpp/include/hal/_tms570_hdk/gpio_def.h deleted file mode 100644 index be12240..0000000 --- a/rpp/include/hal/_tms570_hdk/gpio_def.h +++ /dev/null @@ -1,186 +0,0 @@ -/* Copyright (C) 2013-2015 Czech Technical University in Prague - * Authors: - * - Michal Horn - * - * 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. - */ - -#ifndef HAL_GPIO_DEF_H_ -#define HAL_GPIO_DEF_H_ - -#include "hal/hal.h" - - -#ifndef PORT_SHIFT -#define PORT_SHIFT 5 -#endif -#ifndef PORT_PIN -#define PORT_PIN(p,n,conf) (((p)< - * - * 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. - */ - -#ifndef PORT_DEF_H_ -#define PORT_DEF_H_ - -#include "types.h" - -enum port_interface_type { - ADC = 1, - SPI, - GPIO -}; - -/** - * @brief Port descriptor - * - * The structure describes the port. Port here means set of IO pins on the board. - * The API is designed to provide an interface for setting and reading from ports connected to the MCU by SPI, GPIO or ADC. - */ -typedef struct port_desc_st { - uint32_t *config; /**< Configuration of the port. An array of values, which meaning differs for the interface type: - for SPI: address, chip-select - for GPIO: descriptors for pins (defined in gpio_rm48_def.h) - for ADC: ADC base address, ADC group number, Peripheral type (HOUTIFBK or ADC) - */ - uint32_t numValues; /**< Size of the data to be read from or written on the port. Meaning differs for the interface type: - for SPI: size of the command in bytes - for GPIO: number of pins on the port - for ADC: number of channels to be read from ADC. - */ - enum port_interface_type interfaceType; /**< Type of the interface to which the port or its controller is connected. - Can be SPI, ADC or GPIO - */ - uint32_t (*port_getfnc_ptr)(uint32_t *config, uint32_t num_val, uint32_t *values); /**< Pointer to a getter function. If it is NULL, than port is write only. - All SPI ports are write only, because command has to be sent to obtain actual response. - It is allowed to read values from an output port. - */ - uint32_t (*port_setfnc_ptr)(uint32_t *config, uint32_t num_val, const uint32_t *values); /**< Pointer to a setter function. If it is NULL, than port is read only. - All ADC ports are read only. - It is not allowed to write values on an input port. - */ -} port_desc_t; - -/** - * Maps port descriptor to the port name - */ -typedef struct port_def_st { - char *name; - port_desc_t *desc; -} port_def_t; - -#define PORT_CNT 4 - -#define PORT_NAME_GIOA "GIOA" -#define PORT_NAME_GIOB "GIOB" -#define PORT_NAME_NHET1 "NHET1" -#define PORT_NAME_ADC "ADC" - -#endif /* PORT_DEF_H_ */ diff --git a/rpp/include/hal/_tms570_hydctr/.gitattributes b/rpp/include/hal/_tms570_hydctr/.gitattributes deleted file mode 100644 index 463133b..0000000 --- a/rpp/include/hal/_tms570_hydctr/.gitattributes +++ /dev/null @@ -1,2 +0,0 @@ -/gpio_def.h eaton -/port_def.h eaton diff --git a/rpp/include/hal/_tms570_hydctr/gpio_def.h b/rpp/include/hal/_tms570_hydctr/gpio_def.h deleted file mode 100644 index 663fc01..0000000 --- a/rpp/include/hal/_tms570_hydctr/gpio_def.h +++ /dev/null @@ -1,185 +0,0 @@ -/* Copyright (C) 2013-2015 Czech Technical University in Prague - * Authors: - * - Michal Horn - * - * 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. - */ - -#ifndef HAL_GPIO_DEF_H_ -#define HAL_GPIO_DEF_H_ - -#include "hal/hal.h" - - -#ifndef PORT_SHIFT -#define PORT_SHIFT 5 -#endif -#ifndef PORT_PIN -#define PORT_PIN(p,n,conf) (((p)< - * - * 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. - */ - -#ifndef PORT_DEF_H_ -#define PORT_DEF_H_ - -#include "types.h" - -enum port_interface_type { - ADC = 1, - SPI, - GPIO -}; - -/** - * @brief Port descriptor - * - * The structure describes the port. Port here means set of IO pins on the board. - * The API is designed to provide an interface for setting and reading from ports connected to the MCU by SPI, GPIO or ADC. - */ -typedef struct port_desc_st { - uint32_t *config; /**< Configuration of the port. An array of values, which meaning differs for the interface type: - for SPI: address, chip-select - for GPIO: descriptors for pins (defined in gpio_rm48_def.h) - for ADC: ADC base address, ADC group number, Peripheral type (HOUTIFBK or ADC) - */ - uint32_t numValues; /**< Size of the data to be read from or written on the port. Meaning differs for the interface type: - for SPI: size of the command in bytes - for GPIO: number of pins on the port - for ADC: number of channels to be read from ADC. - */ - enum port_interface_type interfaceType; /**< Type of the interface to which the port or its controller is connected. - Can be SPI, ADC or GPIO - */ - uint32_t (*port_getfnc_ptr)(uint32_t *config, uint32_t num_val, uint32_t *values); /**< Pointer to a getter function. If it is NULL, than port is write only. - All SPI ports are write only, because command has to be sent to obtain actual response. - It is allowed to read values from an output port. - */ - uint32_t (*port_setfnc_ptr)(uint32_t *config, uint32_t num_val, const uint32_t *values); /**< Pointer to a setter function. If it is NULL, than port is read only. - All ADC ports are read only. - It is not allowed to write values on an input port. - */ -} port_desc_t; - -/** - * Maps port descriptor to the port name - */ -typedef struct port_def_st { - char *name; - port_desc_t *desc; -} port_def_t; - -#define PORT_CNT 4 - -#define PORT_NAME_GIOA "GIOA" -#define PORT_NAME_GIOB "GIOB" -#define PORT_NAME_NHET1 "NHET1" -#define PORT_NAME_ADC "ADC" - -#endif /* PORT_DEF_H_ */ diff --git a/rpp/include/hal/_tms570_rpp/gpio_def.h b/rpp/include/hal/_tms570_rpp/gpio_def.h deleted file mode 100644 index 21c52b0..0000000 --- a/rpp/include/hal/_tms570_rpp/gpio_def.h +++ /dev/null @@ -1,194 +0,0 @@ -/** - * - * @file hal_gpio_tms570_def.h - * - * @copyright Copyright (C) 2012-2013 Czech Technical University in Prague - * - * @author Michal Horn - */ - -#ifndef HAL_GPIO_TMS570_DEF_H_ -#define HAL_GPIO_TMS570_DEF_H_ - -#include "hal/hal.h" - - -#ifndef PORT_SHIFT -#define PORT_SHIFT 5 -#endif -#ifndef PORT_PIN -#define PORT_PIN(p,n,conf) (((p)< - */ - -#ifndef PORT_DEF_H_ -#define PORT_DEF_H_ - -#include "types.h" - -enum port_interface_type { - ADC = 1, - SPI, - GPIO -}; - -/** - * @brief Port descriptor - * - * The structure describes the port. Port here means set of IO pins on the board. - * The API is designed to provide an interface for setting and reading from ports connected to the MCU by SPI, GPIO or ADC. - */ -typedef struct port_desc_st { - uint32_t *config; /**< Configuration of the port. An arry of values, which meaning differs for the interface type: - for SPI: address, chip-select - for GPIO: descriptors for pins (defined in gpio_tms570_def.h) - for ADC: ADC base address, ADC group number, Peripheral type (HOUTIFBK or ADC) - */ - uint32_t numValues; /**< Size of the data to be read from or written on the port. Meaning differs for the interface type: - for SPI: size of the command in bytes - for GPIO: number of pins on the port - for ADC: number of channels to be read from ADC. - */ - enum port_interface_type interfaceType; /**< Type of the interface to which the port or its controller is connected. - Can be SPI, ADC or GPIO - */ - uint32_t (*port_getfnc_ptr)(uint32_t *config, uint32_t num_val, uint32_t *values); /**< Pointer to a getter function. If it is NULL, than port is write only. - All SPI ports are write only, because command has to be sent to obtain actual response. - It is allowed to read values from an output port. - */ - uint32_t (*port_setfnc_ptr)(uint32_t *config, uint32_t num_val, const uint32_t *values); /**< Pointer to a setter function. If it is NULL, than port is read only. - All ADC ports are read only. - It is not allowed to write values on an input port. - */ -} port_desc_t; - -/** - * Maps port descriptor to the port name - */ -typedef struct port_def_st { - char *name; - port_desc_t *desc; -} port_def_t; - -#define PORT_CNT 15 - -#define PORT_NAME_DINMCU "DINMCU" -#define PORT_NAME_DINSPI "DINSPI" -#define PORT_NAME_HOUTDIAG "HOUTDIAG" -#define PORT_NAME_HOUTIN "HOUTIN" -#define PORT_NAME_HOUTIFBK "HOUTIFBK" -#define PORT_NAME_ADC "ADC" -#define PORT_NAME_LOUT "LOUT" -#define PORT_NAME_DAC1_2 "DAC12" -#define PORT_NAME_DAC3_4 "DAC34" -#define PORT_NAME_DACDREF "DACDREF" -#define PORT_NAME_HBR "HBR" -#define PORT_NAME_FRAY1 "FRAY1" -#define PORT_NAME_FRAY2 "FRAY2" -#define PORT_NAME_MOUTEN "MOUTEN" -#define PORT_NAME_MOUTIN "MOUTIN" - -#endif /* PORT_DEF_H_ */ diff --git a/rpp/include/hal/hal.h b/rpp/include/hal/hal.h deleted file mode 100644 index 43d9a43..0000000 --- a/rpp/include/hal/hal.h +++ /dev/null @@ -1,207 +0,0 @@ -/** - * Hardware Abstraction Layer library interface file. - * - * @file hal.h - * - * @copyright Copyright (C) 2013, 2015 Czech Technical University in Prague - * - * @author Carlos Jenkins - */ - -#ifndef __HAL_H -#define __HAL_H - -#include "sys/sys.h" - -#if defined(TARGET_POSIX) -#include "hal/_rm48_hdk/gpio_def.h" -#include "hal/_rm48_hdk/port_def.h" -#elif defined(TARGET_RM48_HDK) -#include "hal/_rm48_hdk/gpio_def.h" -#include "hal/_rm48_hdk/port_def.h" -#elif defined(TARGET_TMS570_HDK) -#include "hal/_tms570_hdk/gpio_def.h" -#include "hal/_tms570_hdk/port_def.h" -#elif defined(TARGET_TMS570_HYDCTR) -#include "hal/_tms570_hydctr/gpio_def.h" -#include "hal/_tms570_hydctr/port_def.h" -#elif defined(TARGET_TMS570_RPP) -#include "hal/_tms570_rpp/gpio_def.h" -#include "hal/_tms570_rpp/port_def.h" -#else -#error No supported target specified! -#endif - -uint8_t hal_gpio_get_pin_cnt(); - -pin_map_element_t* hal_gpio_get_pin_map(); - -/** - * Get port base assigned to port number - * @param[in] port_num Port number <0;4> - * @return Pointer to port registers - */ -gioPORT_t *hal_gpio_get_port_base(uint32_t port_num); - -/** - * Get port number assigned to pin in its descriptor - * @param[in] pin descriptor - * @return Index of port - */ -uint32_t hal_gpio_pin_get_port_num(uint32_t pin_dsc); - -/** - * Get port base from pin descriptor - * Combines two upper defined functions - * @param[in] pin_dcs Pin descriptor - * @return Pointer to port registers - */ -gioPORT_t *hal_gpio_pin_get_port_base(uint32_t pin_dsc); - -/** - * Get pin descriptor assigned to pin name. - * @param[in] pin_name Pointer to string - the name of the pin. - * @param[in] len Length of the name, if terminated by '/0', then len=-1 - * @return Pin descriptor or NULL if not found - */ -uint32_t *hal_gpio_pin_get_dsc(const char *pin_name, int len); - -/** - * Get value from GPIO pin - * @param[in] pin_dsc pin descriptor - * @return value read from specified gpio pin - */ -uint32_t hal_gpio_pin_get_value(uint32_t pin_dsc); - -/** - * Set value to gpio pin - * @param[in] pin_dsc pin descriptor - * @param[in] value value to be assigned to the pin - */ -void hal_gpio_pin_set_value(uint32_t pin_dsc, uint32_t value); - -/** - * Set pin direction to input - * @param[in] pin_dsc pin descriptor - * @return always 0 - */ -int hal_gpio_pin_set_dir_in(uint32_t pin_dsc); - -/** - * Set pin direction to output - * @param[in] pin_dsc pin descriptor - * @return always 0 - */ -int hal_gpio_pin_set_dir_out(uint32_t pin_dsc, uint32_t value); - -/** - * Get pin direction - * @param[in] pin_dsc pin descriptor - * @return 1 - output, 0 - input - */ -int hal_gpio_pin_get_dir(uint32_t pin_dsc); - -/** - * Set pin as pull down or pull up and pull resistor enabled or disabled. - * @param[in] pin_dsc Descriptor of the pin - * @param[in] Mode on which pin will be configured to. - * PORT_CONF_MODE_PU - pull up - * PORT_CONF_MODE_PD - pull down - * must be | with - * PORT_CONF_MODE_PEN - pull resistor enable - * PORT_CONF_MODE_PDIS - pull resistor disable - * @return always 0 - */ -uint32_t hal_gpio_pin_set_mode(uint32_t pin_dsc, uint32_t mode); - -/** - * Configure pin to be open drain or not - * @param[in] pin_dsc Descriptor of the pin - * @param[in] Mode on which pin will be configured to. - * PORT_CONF_OD_OFF - open-drain disabled - * PORT_CONF_OD_ON - open drain enabled - * - * @return always 0 - */ -uint32_t hal_gpio_pin_set_od(uint32_t pin_dsc, uint32_t od); - -/** - * Configure pin - * @param[in] pin_dsc Descriptor of the pin - * @param[in] Mode on which pin will be configured to. - * PORT_CONF_OD_OFF - open-drain disabled - * PORT_CONF_OD_ON - open drain enabled - * - * PORT_CONF_MODE_PU - pull up - * PORT_CONF_MODE_PD - pull down - * - * PORT_CONF_MODE_PEN - pull resistor enable - * PORT_CONF_MODE_PDIS - pull resistor disable - * - * PORT_CONF_DIR_IN - direction input - * PORT_CONF_DIR_OUT - direction output - * - * PORT_CONF_INIT_LOW - init value 0 - * PORT_CONF_INIT_HIGH - init value 1 - * - * PORT_CONF_FNC_GPIO - port function GPIO - * PORT_CONF_FNC_FNCX - port alternate function X - * - * @return always 0 - */ -uint32_t hal_gpio_pin_set_config(uint32_t pin_dsc, uint32_t conf); - -/** - * Do the initial pin configuration according values in pin descriptor - * @param[in] pin_dsc pin descriptor - * @return always 0; - */ -uint32_t hal_gpio_pin_configure(uint32_t pin_dsc); - -/** - * Get values of all pins of given port. - * @param[in] config Pointer to array of pin descriptors - * @param[in] num_val Number of pins assigned to the port - * @param[out] values Stored values of all pins of the port. 1st bit -> pin0, 2nd bit -> pin1... - * @return always 0 - */ -uint32_t hal_gpio_port_get_val(uint32_t *config, uint32_t num_val, uint32_t *values); - -/** - * Set values to all pins of given port. - * @param[in] config Pointer to array of pin descriptors - * @param[in] num_val Number of pins assigned to the port - * @param[in] values Stored values of all pins of the port. 1st bit -> pin0, 2nd bit -> pin1... - * @return always 0 - */ -uint32_t hal_gpio_port_set_val(uint32_t *config, uint32_t num_val, const uint32_t *values); - -/** - * Get port descriptor assigned to port name. - * @param[in] port_name Pointer to string - the name of the port. - * @param[in] len Length of the name, if terminated by '/0', then len=-1 - * @return Port descriptor or NULL if not found - */ -const port_def_t *hal_port_get_map(); - -/** - * Get port descriptor assigned to port name. - * @param[in] port_name Pointer to string - the name of the port. - * @param[in] len Length of the name, if terminated by '/0', then len=-1 - * @return Port descriptor or NULL if not found - */ -port_desc_t *hal_port_get_dsc(const char *port_name, int len); - -uint32_t hal_port_get_val_cnt(const port_desc_t* port_desc); - -/** - * Transfer command through the spi - * @param[in] config Address of the SPI - * @param[in] num_bytes Number of bytes to be trasfered - * @param[in] commands SPI command to be sent - * @return spi response - */ -uint32_t hal_spi_port_transfer_command(uint32_t *config, uint32_t num_bytes, const uint32_t *commands); - - -#endif /* __HAL_H */ diff --git a/rpp/include/rpp/gio.h b/rpp/include/rpp/gio.h index 8581f61..b2fc6a7 100644 --- a/rpp/include/rpp/gio.h +++ b/rpp/include/rpp/gio.h @@ -8,7 +8,7 @@ #ifndef GIO_H_ #define GIO_H_ -#include "hal/hal.h" +#include "drv/digital_io.h" #define RPP_GIO_PORT_GIOA 0x2 #define RPP_GIO_PORT_GIOB 0x4 diff --git a/rpp/src/drv/_rm48_hdk/digital_io_def.c b/rpp/src/drv/_rm48_hdk/digital_io_def.c new file mode 100644 index 0000000..fd0e077 --- /dev/null +++ b/rpp/src/drv/_rm48_hdk/digital_io_def.c @@ -0,0 +1,230 @@ +/* Copyright (C) 2012-2013 Czech Technical University in Prague + * + * Authors: + * - Michal Horn + * + * 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. + * + * Abstract: + * This file contains gpio pins definitions + * + * On TMS570 MCU pins can operates as GIO on ports DMM, GIOA, GIOB, + * HET1 and HET2. Those pins, that are defined in this file, can be + * accessed directly as GPIO by hal_gpio_set_value and + * hal_gpio_get_value. Pin configuration can be modified by functions + * defined in hal_gpio_tms570 source and header files. + * + * NOTE: Although the configuration functions are implemented and + * should be ready to use, they were only slightly tested and are not + * used by the RPP software yet. + */ + +#include "drv/_rm48_hdk/digital_io_def.h" +#include "drv/digital_io.h" +#include "drv/spi.h" +#include "drv/_rm48_hdk/adc.h" + + +#define PORT_PIN(p,n,conf) (((p)< + * + * 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. + * + * Abstract: + * This file contains gpio pins definitions + * + * On TMS570 MCU pins can operates as GIO on ports DMM, GIOA, GIOB, + * HET1 and HET2. Those pins, that are defined in this file, can be + * accessed directly as GPIO by hal_gpio_set_value and + * hal_gpio_get_value. Pin configuration can be modified by functions + * defined in hal_gpio_tms570 source and header files. + * + * NOTE: Although the configuration functions are implemented and + * should be ready to use, they were only slightly tested and are not + * used by the RPP software yet. + */ + +#include "drv/_tms570_hdk/digital_io_def.h" +#include "drv/digital_io.h" +#include "drv/spi.h" +#include "drv/_tms570_hdk/adc.h" + + +#define PORT_PIN(p,n,conf) (((p)< + * + * 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. + * + * Abstract: + * This file contains gpio pins definitions + * + * On TMS570 MCU pins can operates as GIO on ports DMM, GIOA, GIOB, + * HET1 and HET2. Those pins, that are defined in this file, can be + * accessed directly as GPIO by hal_gpio_set_value and + * hal_gpio_get_value. Pin configuration can be modified by functions + * defined in hal_gpio_tms570 source and header files. + * + * NOTE: Although the configuration functions are implemented and + * should be ready to use, they were only slightly tested and are not + * used by the RPP software yet. + */ + +#include "drv/_tms570_hydctr/digital_io_def.h" +#include "drv/digital_io.h" +#include "drv/spi.h" +#include "drv/_tms570_hydctr/adc.h" + + +#define PORT_PIN(p,n,conf) (((p)< + * + * 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. + * + * Abstract: + * This file contains gpio pins definitions + * + * On TMS570 MCU pins can operates as GIO on ports DMM, GIOA, GIOB, + * HET1 and HET2. Those pins, that are defined in this file, can be + * accessed directly as GPIO by hal_gpio_set_value and + * hal_gpio_get_value. Pin configuration can be modified by functions + * defined in hal_gpio_tms570 source and header files. + * + * NOTE: Although the configuration functions are implemented and + * should be ready to use, they were only slightly tested and are not + * used by the RPP software yet. + */ + +#include "drv/_tms570_rpp/digital_io_def.h" +#include "drv/digital_io.h" +#include "drv/spi.h" +#include "drv/_tms570_rpp/adc.h" + + +#define PORT_PIN(p,n,conf) (((p)<> 8; commands[1] = (dac_spi_cmd_sh & 0xFF); diff --git a/rpp/src/drv/digital_io.c b/rpp/src/drv/digital_io.c new file mode 100644 index 0000000..ab07d2a --- /dev/null +++ b/rpp/src/drv/digital_io.c @@ -0,0 +1,225 @@ +/* + * digital_io.c + * + * Created on: 17.7.2015 + * Author: michal + */ + +#include "drv/digital_io.h" +#include "drv/spi.h" + +extern gioPORT_t *dio_port_id_map[DIO_MAX_PORT_CNT]; +extern dio_pin_map_element_t dio_pin_map[DIO_MAX_PIN_CNT]; +extern dio_port_def_t dio_port_definition[DIO_PORT_CNT]; + +#define SPI_PORT_BUF_LEN 4 +/** Buffer for spi command to be sent */ +uint8_t spi_port_buf_tx[SPI_PORT_BUF_LEN]; +/** Buffer for spi response */ +uint8_t spi_port_buf_rx[SPI_PORT_BUF_LEN]; + +uint8_t dio_gpio_get_pin_cnt() { + return DIO_MAX_PIN_CNT; +} + +dio_pin_map_element_t* dio_gpio_get_pin_map() { + return dio_pin_map; +} + +gioPORT_t *dio_gpio_get_port_base(uint32_t port_num) +{ + return dio_port_id_map[port_num]; +} + +uint32_t dio_gpio_pin_get_port_num(uint32_t pin_dsc) +{ + + return (pin_dsc & ~DIO_PORT_CONF_MASK) >> DIO_PORT_SHIFT; +} + +gioPORT_t *dio_gpio_pin_get_port_base(uint32_t pin_dsc) +{ + return dio_gpio_get_port_base(dio_gpio_pin_get_port_num(pin_dsc)); +} + + +uint32_t *dio_gpio_pin_get_dsc(const char *pin_name, int len) +{ + uint32_t i; + const char *pin_name_ptr; + char pin_name_term[32]; + + if (len != -1) { // pin name not terminated by '\0' + strncpy(pin_name_term, pin_name, len); + pin_name_term[len] = '\0'; + pin_name_ptr = pin_name_term; + } + else pin_name_ptr = pin_name; + + for (i = 0; i < DIO_MAX_PIN_CNT; i++) { + if (strcmp(pin_name_ptr, dio_pin_map[i].pin_name) == 0) + return &dio_pin_map[i].pin_desc; + } + return NULL; +} + + +uint32_t dio_gpio_pin_get_value(uint32_t pin_dsc) +{ + return ((dio_gpio_pin_get_port_base(pin_dsc)->DIN) >> (pin_dsc & 0x1f)) & 1; +} + + +void dio_gpio_pin_set_value(uint32_t pin_dsc, uint32_t value) +{ + if (value) + dio_gpio_pin_get_port_base(pin_dsc)->DSET = 1 << (pin_dsc & 0x1f); + else + dio_gpio_pin_get_port_base(pin_dsc)->DCLR = 1 << (pin_dsc & 0x1f); +} + + +int dio_gpio_pin_set_dir_in(uint32_t pin_dsc) +{ + dio_gpio_pin_get_port_base(pin_dsc)->DIR &= ~(1 << (pin_dsc & 0x1f)); + return 0; +} + +int dio_gpio_pin_set_dir_out(uint32_t pin_dsc, uint32_t value) +{ + dio_gpio_pin_set_value(pin_dsc, value); + dio_gpio_pin_get_port_base(pin_dsc)->DIR |= (1 << (pin_dsc & 0x1f)); + return 0; +} + +int dio_gpio_pin_get_dir(uint32_t pin_dsc) +{ + return (dio_gpio_pin_get_port_base(pin_dsc)->DIR >> (pin_dsc & 0x1f)) & 1; +} + + +uint32_t dio_gpio_pin_set_mode(uint32_t pin_dsc, uint32_t mode) +{ + gioPORT_t *gioPort = dio_gpio_pin_get_port_base(pin_dsc); + + if (mode & DIO_PORT_CONF_MODE_PTYPE_MASK) + gioPort->PSL |= (1 << (pin_dsc & 0x1f)); + else + gioPort->PSL &= ~(1 << (pin_dsc & 0x1f)); + if (mode & DIO_PORT_CONF_MODE_PEN_MASK) + gioPort->PULDIS |= (1 << (pin_dsc & 0x1f)); + else + gioPort->PULDIS &= ~(1 << (pin_dsc & 0x1f)); + return 0; +} + + +uint32_t dio_gpio_pin_set_od(uint32_t pin_dsc, uint32_t od) +{ + gioPORT_t *gioPort = dio_gpio_pin_get_port_base(pin_dsc); + + if (od & DIO_PORT_CONF_OD_ON) + gioPort->PDR |= (1 << (pin_dsc & 0x1f)); + else + gioPort->PDR &= ~(1 << (pin_dsc & 0x1f)); + return 0; +} + + +uint32_t dio_gpio_pin_set_config(uint32_t pin_dsc, uint32_t conf) +{ + pin_dsc &= ~DIO_PORT_CONF_MASK; + dio_gpio_pin_set_mode(pin_dsc, conf & DIO_PORT_CONF_MODE_MASK); + dio_gpio_pin_set_od(pin_dsc, conf & DIO_PORT_CONF_OD_MASK); + if (conf & DIO_PORT_CONF_SET_DIR) { + if ((conf & DIO_PORT_CONF_DIR_MASK) == (DIO_PORT_CONF_DIR_IN & DIO_PORT_CONF_DIR_MASK)) + dio_gpio_pin_set_dir_in(pin_dsc); + else + dio_gpio_pin_set_dir_out(pin_dsc, conf & DIO_PORT_CONF_INIT_HIGH); + } + + return 0; +} + +uint32_t dio_gpio_pin_configure(uint32_t pin_dsc) +{ + return dio_gpio_pin_set_config(pin_dsc, pin_dsc); +} + + +uint32_t dio_gpio_port_get_val(uint32_t *config, uint32_t num_val, uint32_t *values) +{ + uint32_t i; + + for (i = 0; i < num_val; i++) { + values[i] = dio_gpio_pin_get_value(config[i]); + } + return 0; +} + +uint32_t dio_gpio_port_set_val(uint32_t *config, uint32_t num_val, const uint32_t *values) +{ + uint32_t i; + + for (i = 0; i < num_val; i++) { + dio_gpio_pin_set_value(config[i], (values[i/8] >> i%8) & 0x1); + } + return 0; +} + +const dio_port_def_t *dio_port_get_map() +{ + return (const dio_port_def_t *)dio_port_definition; +} + +dio_port_desc_t *dio_port_get_dsc(const char *port_name, int len) +{ + uint32_t i; + const char *port_name_ptr; + char port_name_term[32]; + + if (len != -1) { // port name not terminated by '\0' + strncpy(port_name_term, port_name, len); + port_name_term[len] = '\0'; + port_name_ptr = port_name_term; + } + else port_name_ptr = port_name; + + for (i = 0; i < DIO_PORT_CNT; i++) { + if (strcmp(port_name_ptr, dio_port_definition[i].name) == 0) + return dio_port_definition[i].desc; + } + return NULL; +} + +uint32_t dio_port_get_val_cnt(const dio_port_desc_t* port_desc) { + if (port_desc != NULL) { + return port_desc->numValues; + } + else { + return 0; + } +} + +uint32_t dio_spi_port_transfer_command(uint32_t *config, uint32_t num_bytes, const uint32_t *commands) +{ + spi_drv_t *ifc; + int i; + uint32_t ret; + + for (i = 0; i < num_bytes; i++) + spi_port_buf_tx[i] = commands[i]; + + ifc = spi_find_drv(NULL, config[0]); + if (ifc == NULL) + return 0; + + if (!(ifc->flags & SPI_IFC_ON)) + return 0; + + spi_transfer(ifc, config[1], num_bytes, spi_port_buf_tx, spi_port_buf_rx); + ret = 0; + for (i = 0; i < num_bytes; i++) + ret |= spi_port_buf_rx[i] << i*8; + return ret; +} diff --git a/rpp/src/drv/din.c b/rpp/src/drv/din.c index b824d5a..ccdafb2 100644 --- a/rpp/src/drv/din.c +++ b/rpp/src/drv/din.c @@ -38,19 +38,6 @@ static uint32_t din_spi_resp = 0; /** Store commands in shadow registers */ static uint16_t shadow_reg_list[DIN_NUM_SPI_CMD]; - -const static uint32_t dsc_pin_map[8U] = { - PIN_DSC_DIN8, - PIN_DSC_DIN9, - PIN_DSC_DIN10, - PIN_DSC_DIN11, - PIN_DSC_DIN12, - PIN_DSC_DIN13, - PIN_DSC_DIN14, - PIN_DSC_DIN15 -}; - - /****************************************************************************** * Function Prototypes ******************************************************************************/ @@ -111,7 +98,7 @@ int8_t drv_din_ref(uint16_t ref_a, uint16_t ref_b) // Get descriptor uint32_t commands[2]; - port_desc_t *desc = hal_port_get_dsc(PORT_NAME_DACDREF, -1); + dio_port_desc_t *desc = dio_port_get_dsc(DIO_PORT_NAME_DACDREF, -1); // Send command for DAC A cmd = DACA_INIT_VAL | (ref_a & 0x0FFF); @@ -139,7 +126,11 @@ int8_t drv_din_get_varthr(uint8_t pin) if ((pin < 8) || (pin > 15)) return FAILURE; - return hal_gpio_pin_get_value(dsc_pin_map[pin - 8]); + 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]); } uint16_t din_get_val_word() @@ -180,9 +171,9 @@ int din_spi_response() */ int din_spi_transfer_mst(const uint32_t din_spi_cmd) { - port_desc_t *desc; + dio_port_desc_t *desc; - desc = hal_port_get_dsc(PORT_NAME_DINSPI, -1); + desc = dio_port_get_dsc(DIO_PORT_NAME_DINSPI, -1); uint32_t commands[3]; commands[0] = (din_spi_cmd & 0xFF0000) >> 16; // command commands[1] = (din_spi_cmd & 0xFF00) >> 8; // 1.st B of data diff --git a/rpp/src/drv/fr_tms570.c b/rpp/src/drv/fr_tms570.c index eb75c93..b5be0eb 100644 --- a/rpp/src/drv/fr_tms570.c +++ b/rpp/src/drv/fr_tms570.c @@ -17,7 +17,7 @@ #include "drv/drv.h" #include "sys/ti_drv_fray.h" #include "binary.h" -#include "hal/hal.h" +#include "drv/digital_io.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] = { PORT_NAME_FRAY1, PORT_NAME_FRAY2 }; +static const char *fray_port_names[FRAY_NUM_PORTS] = { DIO_PORT_NAME_FRAY1, DIO_PORT_NAME_FRAY2 }; /** Array of integers, where FlexRay cluster and node configuration * parameters are stored to be accessible by indexes defined in Fr_GeneralTypes.h. */ @@ -2198,10 +2198,10 @@ Std_ReturnType Fr_ReadCCConfig( uint8_t Fr_CtrlIdx, uint8_t Fr_ConfigParamIdx, u int Fr_spi_transfer(uint8_t port) { uint32_t commands[2]; - port_desc_t *desc; + dio_port_desc_t *desc; if (port > FRAY_NUM_PORTS) return -1; - desc = hal_port_get_dsc(fray_port_names[port], -1); + desc = dio_port_get_dsc(fray_port_names[port], -1); fray_spi_cmd_sh = fray_spi_cmd; commands[0] = (fray_spi_cmd_sh & 0xFF00) >> 8; commands[1] = (fray_spi_cmd_sh & 0xFF); diff --git a/rpp/src/drv/hbridge.c b/rpp/src/drv/hbridge.c index e4236a1..36d0552 100644 --- a/rpp/src/drv/hbridge.c +++ b/rpp/src/drv/hbridge.c @@ -277,7 +277,7 @@ double drv_hbr_pwm_get_period() */ void drv_hbr_set_dir(int direction) { - hal_gpio_pin_set_value(PIN_DSC_HBRDIR, direction); + dio_gpio_pin_set_value(*dio_gpio_pin_get_dsc(DIO_PIN_NAME_HBRDIR, -1), direction); } /** @@ -287,7 +287,7 @@ void drv_hbr_set_dir(int direction) */ int drv_hbr_get_dir() { - return hal_gpio_pin_get_value(PIN_DSC_HBRDIR); + return dio_gpio_pin_get_value(*dio_gpio_pin_get_dsc(DIO_PIN_NAME_HBRDIR, -1)); } /** @@ -297,7 +297,7 @@ int drv_hbr_get_dir() */ void drv_hbr_set_en(int value) { - hal_gpio_pin_set_value(PIN_DSC_HBREN, value); + dio_gpio_pin_set_value(*dio_gpio_pin_get_dsc(DIO_PIN_NAME_HBREN, -1), value); } /** @@ -307,5 +307,5 @@ void drv_hbr_set_en(int value) */ int drv_hbr_get_en() { - return hal_gpio_pin_get_value(PIN_DSC_HBREN); + return dio_gpio_pin_get_value(*dio_gpio_pin_get_dsc(DIO_PIN_NAME_HBREN, -1)); } diff --git a/rpp/src/drv/hout.c b/rpp/src/drv/hout.c index 80bad2e..ebf0525 100644 --- a/rpp/src/drv/hout.c +++ b/rpp/src/drv/hout.c @@ -22,10 +22,6 @@ #define HOUT_PWM_INITIALIZED 0x1 #define HOUT_PWM_RUNNING 0x100 -/** Map of hout_in pin descriptors to their index **/ -static uint32_t hout_pin_in_descs[] = {PIN_DSC_HOUT1IN, PIN_DSC_HOUT2IN, PIN_DSC_HOUT3IN, PIN_DSC_HOUT4IN, PIN_DSC_HOUT5IN, PIN_DSC_HOUT6IN}; -/** Map of hout_diag pin descriptors to their index **/ -static uint32_t hout_pin_diag_descs[] = {PIN_DSC_HOUT1DIAG, PIN_DSC_HOUT2DIAG, PIN_DSC_HOUT3DIAG, PIN_DSC_HOUT4DIAG, PIN_DSC_HOUT5DIAG, PIN_DSC_HOUT6DIAG}; /** PWM modules from N2HET mapped to HOUT pin ID 0-5 **/ static uint8_t hout_pwm_map[] = {pwm1, pwm2, pwm3, pwm4, pwm5, pwm6}; /** Flag variable @@ -143,8 +139,11 @@ 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); - if (hout_id >= hal_port_get_val_cnt(hal_port_get_dsc(PORT_NAME_HOUTIN, -1))) + + if (hout_id >= dio_port_get_val_cnt(dio_port_get_dsc(DIO_PORT_NAME_HOUTIN, -1))) return -1; // Bad parameter pwm_running = hout_pwm_state & (HOUT_PWM_RUNNING << hout_id); @@ -153,13 +152,13 @@ int hout_fail(uint8_t hout_id) else hout_pwm_stop(hout_id); vTaskDelay(1/portTICK_RATE_MS); - hal_gpio_pin_set_value(hout_pin_in_descs[hout_id], 1); + dio_gpio_pin_set_value(hout_in_port->config[hout_id], 1); for (i = 0; i < 4; i++) { - if (hal_gpio_pin_get_value(hout_pin_diag_descs[hout_id]) != 1) + if (dio_gpio_pin_get_value(hout_diag_port->config[hout_id]) != 1) err_cnt++; // Input value and output value are not equal vTaskDelay(1/portTICK_RATE_MS); } - hal_gpio_pin_set_value(hout_pin_in_descs[hout_id], 0); + dio_gpio_pin_set_value(hout_diag_port->config[hout_id], 0); if (pwm_running) hout_pwm_start(hout_id); return (err_cnt == 0) ? HOUT_OK : HOUT_FAILED; } diff --git a/rpp/src/drv/lout.c b/rpp/src/drv/lout.c index 0ec425c..88b8088 100644 --- a/rpp/src/drv/lout.c +++ b/rpp/src/drv/lout.c @@ -131,9 +131,9 @@ uint8_t lout_get_word() int lout_spi_transfer() { - port_desc_t *desc; + dio_port_desc_t *desc; - desc = hal_port_get_dsc(PORT_NAME_LOUT, -1); + desc = dio_port_get_dsc(DIO_PORT_NAME_LOUT, -1); lout_spi_cmd_sh = lout_spi_cmd; uint32_t commands[4]; diff --git a/rpp/src/drv/mout.c b/rpp/src/drv/mout.c index 3233051..a57816e 100644 --- a/rpp/src/drv/mout.c +++ b/rpp/src/drv/mout.c @@ -20,23 +20,15 @@ #include "drv/mout.h" -const static uint32_t dsc_pin_map[6U][2U] = { - {PIN_DSC_MOUT1IN, PIN_DSC_MOUT1EN}, - {PIN_DSC_MOUT2IN, PIN_DSC_MOUT2EN}, - {PIN_DSC_MOUT3IN, PIN_DSC_MOUT3EN}, - {PIN_DSC_MOUT4IN, PIN_DSC_MOUT4EN}, - {PIN_DSC_MOUT5IN, PIN_DSC_MOUT5EN}, - {PIN_DSC_MOUT6IN, PIN_DSC_MOUT6EN} -}; - - int8_t drv_mout_set(uint8_t pin, uint8_t val) { // Check range if (pin > 5) return -1; - hal_gpio_pin_set_value(dsc_pin_map[pin][0], val); + 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); return SUCCESS; } @@ -47,7 +39,9 @@ int8_t drv_mout_diag(uint8_t pin) if (pin > 5) return -1; - if (hal_gpio_pin_get_value(dsc_pin_map[pin][1]) == 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) return HIGH; return LOW; } diff --git a/rpp/src/hal/_rm48_hdk/.gitattributes b/rpp/src/hal/_rm48_hdk/.gitattributes deleted file mode 100644 index 3dbecf5..0000000 --- a/rpp/src/hal/_rm48_hdk/.gitattributes +++ /dev/null @@ -1,2 +0,0 @@ -/gpio_def.c eaton -/port_def.c eaton diff --git a/rpp/src/hal/_rm48_hdk/gpio_def.c b/rpp/src/hal/_rm48_hdk/gpio_def.c deleted file mode 100644 index e88bd3e..0000000 --- a/rpp/src/hal/_rm48_hdk/gpio_def.c +++ /dev/null @@ -1,97 +0,0 @@ -/* Copyright (C) 2012-2013, 2015 Czech Technical University in Prague - * - * Authors: - * - Michal Horn - * - * 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 : hal_gpio_rm48_def.c - * - * Abstract: - * This file contains gpio pins definitions - * - * On RM48 MCU pins can operates as GIO on ports DMM, GIOA, GIOB, - * HET1 and HET2. Those pins, that are defined in this file, can be - * accessed directly as GPIO by hal_gpio_set_value and - * hal_gpio_get_value. Pin configuration can be modified by functions - * defined in hal_gpio_rm48 source and header files. - * - * NOTE: Although the configuration functions are implemented and - * should be ready to use, they were only slightly tested and are not - * used by the RPP software yet. - */ - -//#include "hal/gpio_rm48_def.h" -#include "hal/hal.h" - -/** - * Array of ports used as GPIO. Thanks to that array, we can - * determine port just by index in pin_desc at 5th bit */ -gioPORT_t *port_id_map[MAX_PORT_CNT] = { - [PORT_ID_DMM] = (gioPORT_t *)dmmPORT, - [PORT_ID_GIOA] = (gioPORT_t *)gioPORTA, - [PORT_ID_GIOB] = (gioPORT_t *)gioPORTB, - [PORT_ID_HET1] = (gioPORT_t *)hetPORT1, - [PORT_ID_HET2] = (gioPORT_t *)hetPORT2 -}; - -/* Some pins are commented out, because they are pinmuxed with SCI. */ -/** - * Map of pin names to pin descriptors. Each pin can be then easily - * found just by its name given as a string to hal_gpio_get_pin_dsc - * function*/ -pin_map_element_t pin_map[MAX_PIN_CNT] = { - /* DMM pins */ - { .pin_name = PIN_NAME_GIOA0, .pin_desc = PIN_DSC_GIOA0 }, - { .pin_name = PIN_NAME_GIOA1, .pin_desc = PIN_DSC_GIOA1 }, - { .pin_name = PIN_NAME_GIOA2, .pin_desc = PIN_DSC_GIOA2 }, - { .pin_name = PIN_NAME_GIOA3, .pin_desc = PIN_DSC_GIOA3 }, - { .pin_name = PIN_NAME_GIOA4, .pin_desc = PIN_DSC_GIOA4 }, - { .pin_name = PIN_NAME_GIOA5, .pin_desc = PIN_DSC_GIOA5 }, - { .pin_name = PIN_NAME_GIOA6, .pin_desc = PIN_DSC_GIOA6 }, - { .pin_name = PIN_NAME_GIOA7, .pin_desc = PIN_DSC_GIOA7 }, - { .pin_name = PIN_NAME_GIOB0, .pin_desc = PIN_DSC_GIOB0 }, - { .pin_name = PIN_NAME_GIOB1, .pin_desc = PIN_DSC_GIOB1 }, - { .pin_name = PIN_NAME_GIOB2, .pin_desc = PIN_DSC_GIOB2 }, - { .pin_name = PIN_NAME_GIOB3, .pin_desc = PIN_DSC_GIOB3 }, - { .pin_name = PIN_NAME_GIOB4, .pin_desc = PIN_DSC_GIOB4 }, - { .pin_name = PIN_NAME_GIOB5, .pin_desc = PIN_DSC_GIOB5 }, - { .pin_name = PIN_NAME_GIOB6, .pin_desc = PIN_DSC_GIOB6 }, - { .pin_name = PIN_NAME_GIOB7, .pin_desc = PIN_DSC_GIOB7 }, - { .pin_name = PIN_NAME_NHET1_0, .pin_desc = PIN_DSC_NHET1_0 }, - { .pin_name = PIN_NAME_NHET1_1, .pin_desc = PIN_DSC_NHET1_1 }, - { .pin_name = PIN_NAME_NHET1_2, .pin_desc = PIN_DSC_NHET1_2 }, - { .pin_name = PIN_NAME_NHET1_3, .pin_desc = PIN_DSC_NHET1_3 }, - { .pin_name = PIN_NAME_NHET1_4, .pin_desc = PIN_DSC_NHET1_4 }, - { .pin_name = PIN_NAME_NHET1_5, .pin_desc = PIN_DSC_NHET1_5 }, - /*{ .pin_name = PIN_NAME_NHET1_6, .pin_desc = PIN_DSC_NHET1_6 },*/ - { .pin_name = PIN_NAME_NHET1_7, .pin_desc = PIN_DSC_NHET1_7 }, - { .pin_name = PIN_NAME_NHET1_8, .pin_desc = PIN_DSC_NHET1_8 }, - { .pin_name = PIN_NAME_NHET1_9, .pin_desc = PIN_DSC_NHET1_9 }, - { .pin_name = PIN_NAME_NHET1_10, .pin_desc = PIN_DSC_NHET1_10 }, - { .pin_name = PIN_NAME_NHET1_11, .pin_desc = PIN_DSC_NHET1_11 }, - { .pin_name = PIN_NAME_NHET1_12, .pin_desc = PIN_DSC_NHET1_12 }, - /*{ .pin_name = PIN_NAME_NHET1_13, .pin_desc = PIN_DSC_NHET1_13 },*/ - { .pin_name = PIN_NAME_NHET1_14, .pin_desc = PIN_DSC_NHET1_14 }, - { .pin_name = PIN_NAME_NHET1_15, .pin_desc = PIN_DSC_NHET1_15 }, - { .pin_name = PIN_NAME_NHET1_16, .pin_desc = PIN_DSC_NHET1_16 }, - { .pin_name = PIN_NAME_NHET1_17, .pin_desc = PIN_DSC_NHET1_17 }, - { .pin_name = PIN_NAME_NHET1_18, .pin_desc = PIN_DSC_NHET1_18 }, - { .pin_name = PIN_NAME_NHET1_19, .pin_desc = PIN_DSC_NHET1_19 }, - { .pin_name = PIN_NAME_NHET1_20, .pin_desc = PIN_DSC_NHET1_20 }, - { .pin_name = PIN_NAME_NHET1_21, .pin_desc = PIN_DSC_NHET1_21 }, - { .pin_name = PIN_NAME_NHET1_22, .pin_desc = PIN_DSC_NHET1_22 }, - { .pin_name = PIN_NAME_NHET1_23, .pin_desc = PIN_DSC_NHET1_23 }, - { .pin_name = PIN_NAME_NHET1_24, .pin_desc = PIN_DSC_NHET1_24 }, - { .pin_name = PIN_NAME_NHET1_25, .pin_desc = PIN_DSC_NHET1_25 }, - { .pin_name = PIN_NAME_NHET1_26, .pin_desc = PIN_DSC_NHET1_26 }, - { .pin_name = PIN_NAME_NHET1_27, .pin_desc = PIN_DSC_NHET1_27 }, - { .pin_name = PIN_NAME_NHET1_28, .pin_desc = PIN_DSC_NHET1_28 }, - { .pin_name = PIN_NAME_NHET1_29, .pin_desc = PIN_DSC_NHET1_29 }, - { .pin_name = PIN_NAME_NHET1_30, .pin_desc = PIN_DSC_NHET1_30 }, - { .pin_name = PIN_NAME_NHET1_31, .pin_desc = PIN_DSC_NHET1_31 }, - /* FIXME: add definitions of all unused pins DMM, HET2, SCI... */ -}; diff --git a/rpp/src/hal/_rm48_hdk/port_def.c b/rpp/src/hal/_rm48_hdk/port_def.c deleted file mode 100644 index 61f4521..0000000 --- a/rpp/src/hal/_rm48_hdk/port_def.c +++ /dev/null @@ -1,127 +0,0 @@ -/* Copyright (C) 2012-2013 Czech Technical University in Prague - * - * Authors: - * - Michal Horn - * - * 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 : port_def.c - * - * Abstract: - * This file contains general ports definitions. Ports are defined according to their names on - * the RPP board. - * Each port is define by port descriptor, which consists of: - * - list of its pin (pin descriptors), - * - number of pins, - * - get value function pointer, - * - set value function pointer. - * Finally each port descriptor is mapped to the port name string. - * - * Get and set value function are defined for each port style (ADC, SPI, GPIO) in separated files. - */ - -#include "hal/hal.h" -#include "drv/spi.h" -#include "drv/_rm48_hdk/adc.h" - -// Lists of pins assigned to the ports -static uint32_t port_cfg_gioa[] = { - PIN_DSC_GIOA0, PIN_DSC_GIOA1, PIN_DSC_GIOA2, PIN_DSC_GIOA3, - PIN_DSC_GIOA4, PIN_DSC_GIOA5, PIN_DSC_GIOA6, PIN_DSC_GIOA7 -}; -static uint32_t port_cfg_giob[] = { - PIN_DSC_GIOB0, PIN_DSC_GIOB1, PIN_DSC_GIOB2, PIN_DSC_GIOB3, - PIN_DSC_GIOB4, PIN_DSC_GIOB5, PIN_DSC_GIOB6, PIN_DSC_GIOB7 -}; -static uint32_t port_cfg_nhet1[] = { - PIN_DSC_NHET1_0, PIN_DSC_NHET1_1, PIN_DSC_NHET1_2, - PIN_DSC_NHET1_3, PIN_DSC_NHET1_4, PIN_DSC_NHET1_5, - PIN_DSC_NHET1_7, PIN_DSC_NHET1_8, PIN_DSC_NHET1_9, - PIN_DSC_NHET1_10, PIN_DSC_NHET1_11, PIN_DSC_NHET1_12, - PIN_DSC_NHET1_14, PIN_DSC_NHET1_15, PIN_DSC_NHET1_16, - PIN_DSC_NHET1_17, PIN_DSC_NHET1_18, PIN_DSC_NHET1_19, - PIN_DSC_NHET1_20, PIN_DSC_NHET1_21, PIN_DSC_NHET1_22, - PIN_DSC_NHET1_23, PIN_DSC_NHET1_24, PIN_DSC_NHET1_25, - PIN_DSC_NHET1_26, PIN_DSC_NHET1_27, PIN_DSC_NHET1_28, - PIN_DSC_NHET1_29, PIN_DSC_NHET1_30, PIN_DSC_NHET1_31 -}; -static uint32_t port_cfg_adc[] = { (uint32_t)adcREG1, adcGROUP1, 1 }; - -// Port descriptors -static port_desc_t port_desc_gioa = { - .config = port_cfg_gioa, - .numValues = 8, - .interfaceType = GPIO, - .port_getfnc_ptr = &hal_gpio_port_get_val, - .port_setfnc_ptr = &hal_gpio_port_set_val, -}; -static port_desc_t port_desc_giob = { - .config = port_cfg_giob, - .numValues = 8, - .interfaceType = GPIO, - .port_getfnc_ptr = &hal_gpio_port_get_val, - .port_setfnc_ptr = &hal_gpio_port_set_val, -}; -static port_desc_t port_desc_nhet1 = { - .config = port_cfg_nhet1, - .numValues = 30, - .interfaceType = GPIO, - .port_getfnc_ptr = &hal_gpio_port_get_val, - .port_setfnc_ptr = &hal_gpio_port_set_val, -}; -static port_desc_t port_desc_adc = { - .config = port_cfg_adc, - .numValues = 16, - .interfaceType = ADC, - .port_getfnc_ptr = &adc_get_port_val, - .port_setfnc_ptr = ((void *)0), -}; - - -// Maps of port names to port descriptors -port_def_t port_definition[PORT_CNT] = { - {.name = PORT_NAME_GIOA, .desc = &port_desc_gioa}, - {.name = PORT_NAME_GIOB, .desc = &port_desc_giob}, - {.name = PORT_NAME_NHET1, .desc = &port_desc_nhet1}, - {.name = PORT_NAME_ADC, .desc = &port_desc_adc} -}; - -/** - * Get port descriptor assigned to port name. - * @param[in] port_name Pointer to string - the name of the port. - * @param[in] len Length of the name, if terminated by '/0', then len=-1 - * @return Port descriptor or NULL if not found - */ -port_desc_t *hal_port_get_dsc(const char *port_name, int len) -{ - uint32_t i; - const char *port_name_ptr; - char port_name_term[32]; - - if (len != -1) { // port name not terminated by '\0' - strncpy(port_name_term, port_name, len); - port_name_term[len] = '\0'; - port_name_ptr = port_name_term; - } - else port_name_ptr = port_name; - - for (i = 0; i < PORT_CNT; i++) { - if (strcmp(port_name_ptr, port_definition[i].name) == 0) - return port_definition[i].desc; - } - return NULL; -} - -/** - * Get port descriptor assigned to port name. - * @param[in] port_name Pointer to string - the name of the port. - * @param[in] len Length of the name, if terminated by '/0', then len=-1 - * @return Port descriptor or NULL if not found - */ -const port_def_t *hal_port_get_map() -{ - return (const port_def_t *)port_definition; -} diff --git a/rpp/src/hal/_tms570_hdk/.gitattributes b/rpp/src/hal/_tms570_hdk/.gitattributes deleted file mode 100644 index 3dbecf5..0000000 --- a/rpp/src/hal/_tms570_hdk/.gitattributes +++ /dev/null @@ -1,2 +0,0 @@ -/gpio_def.c eaton -/port_def.c eaton diff --git a/rpp/src/hal/_tms570_hdk/gpio_def.c b/rpp/src/hal/_tms570_hdk/gpio_def.c deleted file mode 100644 index e88bd3e..0000000 --- a/rpp/src/hal/_tms570_hdk/gpio_def.c +++ /dev/null @@ -1,97 +0,0 @@ -/* Copyright (C) 2012-2013, 2015 Czech Technical University in Prague - * - * Authors: - * - Michal Horn - * - * 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 : hal_gpio_rm48_def.c - * - * Abstract: - * This file contains gpio pins definitions - * - * On RM48 MCU pins can operates as GIO on ports DMM, GIOA, GIOB, - * HET1 and HET2. Those pins, that are defined in this file, can be - * accessed directly as GPIO by hal_gpio_set_value and - * hal_gpio_get_value. Pin configuration can be modified by functions - * defined in hal_gpio_rm48 source and header files. - * - * NOTE: Although the configuration functions are implemented and - * should be ready to use, they were only slightly tested and are not - * used by the RPP software yet. - */ - -//#include "hal/gpio_rm48_def.h" -#include "hal/hal.h" - -/** - * Array of ports used as GPIO. Thanks to that array, we can - * determine port just by index in pin_desc at 5th bit */ -gioPORT_t *port_id_map[MAX_PORT_CNT] = { - [PORT_ID_DMM] = (gioPORT_t *)dmmPORT, - [PORT_ID_GIOA] = (gioPORT_t *)gioPORTA, - [PORT_ID_GIOB] = (gioPORT_t *)gioPORTB, - [PORT_ID_HET1] = (gioPORT_t *)hetPORT1, - [PORT_ID_HET2] = (gioPORT_t *)hetPORT2 -}; - -/* Some pins are commented out, because they are pinmuxed with SCI. */ -/** - * Map of pin names to pin descriptors. Each pin can be then easily - * found just by its name given as a string to hal_gpio_get_pin_dsc - * function*/ -pin_map_element_t pin_map[MAX_PIN_CNT] = { - /* DMM pins */ - { .pin_name = PIN_NAME_GIOA0, .pin_desc = PIN_DSC_GIOA0 }, - { .pin_name = PIN_NAME_GIOA1, .pin_desc = PIN_DSC_GIOA1 }, - { .pin_name = PIN_NAME_GIOA2, .pin_desc = PIN_DSC_GIOA2 }, - { .pin_name = PIN_NAME_GIOA3, .pin_desc = PIN_DSC_GIOA3 }, - { .pin_name = PIN_NAME_GIOA4, .pin_desc = PIN_DSC_GIOA4 }, - { .pin_name = PIN_NAME_GIOA5, .pin_desc = PIN_DSC_GIOA5 }, - { .pin_name = PIN_NAME_GIOA6, .pin_desc = PIN_DSC_GIOA6 }, - { .pin_name = PIN_NAME_GIOA7, .pin_desc = PIN_DSC_GIOA7 }, - { .pin_name = PIN_NAME_GIOB0, .pin_desc = PIN_DSC_GIOB0 }, - { .pin_name = PIN_NAME_GIOB1, .pin_desc = PIN_DSC_GIOB1 }, - { .pin_name = PIN_NAME_GIOB2, .pin_desc = PIN_DSC_GIOB2 }, - { .pin_name = PIN_NAME_GIOB3, .pin_desc = PIN_DSC_GIOB3 }, - { .pin_name = PIN_NAME_GIOB4, .pin_desc = PIN_DSC_GIOB4 }, - { .pin_name = PIN_NAME_GIOB5, .pin_desc = PIN_DSC_GIOB5 }, - { .pin_name = PIN_NAME_GIOB6, .pin_desc = PIN_DSC_GIOB6 }, - { .pin_name = PIN_NAME_GIOB7, .pin_desc = PIN_DSC_GIOB7 }, - { .pin_name = PIN_NAME_NHET1_0, .pin_desc = PIN_DSC_NHET1_0 }, - { .pin_name = PIN_NAME_NHET1_1, .pin_desc = PIN_DSC_NHET1_1 }, - { .pin_name = PIN_NAME_NHET1_2, .pin_desc = PIN_DSC_NHET1_2 }, - { .pin_name = PIN_NAME_NHET1_3, .pin_desc = PIN_DSC_NHET1_3 }, - { .pin_name = PIN_NAME_NHET1_4, .pin_desc = PIN_DSC_NHET1_4 }, - { .pin_name = PIN_NAME_NHET1_5, .pin_desc = PIN_DSC_NHET1_5 }, - /*{ .pin_name = PIN_NAME_NHET1_6, .pin_desc = PIN_DSC_NHET1_6 },*/ - { .pin_name = PIN_NAME_NHET1_7, .pin_desc = PIN_DSC_NHET1_7 }, - { .pin_name = PIN_NAME_NHET1_8, .pin_desc = PIN_DSC_NHET1_8 }, - { .pin_name = PIN_NAME_NHET1_9, .pin_desc = PIN_DSC_NHET1_9 }, - { .pin_name = PIN_NAME_NHET1_10, .pin_desc = PIN_DSC_NHET1_10 }, - { .pin_name = PIN_NAME_NHET1_11, .pin_desc = PIN_DSC_NHET1_11 }, - { .pin_name = PIN_NAME_NHET1_12, .pin_desc = PIN_DSC_NHET1_12 }, - /*{ .pin_name = PIN_NAME_NHET1_13, .pin_desc = PIN_DSC_NHET1_13 },*/ - { .pin_name = PIN_NAME_NHET1_14, .pin_desc = PIN_DSC_NHET1_14 }, - { .pin_name = PIN_NAME_NHET1_15, .pin_desc = PIN_DSC_NHET1_15 }, - { .pin_name = PIN_NAME_NHET1_16, .pin_desc = PIN_DSC_NHET1_16 }, - { .pin_name = PIN_NAME_NHET1_17, .pin_desc = PIN_DSC_NHET1_17 }, - { .pin_name = PIN_NAME_NHET1_18, .pin_desc = PIN_DSC_NHET1_18 }, - { .pin_name = PIN_NAME_NHET1_19, .pin_desc = PIN_DSC_NHET1_19 }, - { .pin_name = PIN_NAME_NHET1_20, .pin_desc = PIN_DSC_NHET1_20 }, - { .pin_name = PIN_NAME_NHET1_21, .pin_desc = PIN_DSC_NHET1_21 }, - { .pin_name = PIN_NAME_NHET1_22, .pin_desc = PIN_DSC_NHET1_22 }, - { .pin_name = PIN_NAME_NHET1_23, .pin_desc = PIN_DSC_NHET1_23 }, - { .pin_name = PIN_NAME_NHET1_24, .pin_desc = PIN_DSC_NHET1_24 }, - { .pin_name = PIN_NAME_NHET1_25, .pin_desc = PIN_DSC_NHET1_25 }, - { .pin_name = PIN_NAME_NHET1_26, .pin_desc = PIN_DSC_NHET1_26 }, - { .pin_name = PIN_NAME_NHET1_27, .pin_desc = PIN_DSC_NHET1_27 }, - { .pin_name = PIN_NAME_NHET1_28, .pin_desc = PIN_DSC_NHET1_28 }, - { .pin_name = PIN_NAME_NHET1_29, .pin_desc = PIN_DSC_NHET1_29 }, - { .pin_name = PIN_NAME_NHET1_30, .pin_desc = PIN_DSC_NHET1_30 }, - { .pin_name = PIN_NAME_NHET1_31, .pin_desc = PIN_DSC_NHET1_31 }, - /* FIXME: add definitions of all unused pins DMM, HET2, SCI... */ -}; diff --git a/rpp/src/hal/_tms570_hdk/port_def.c b/rpp/src/hal/_tms570_hdk/port_def.c deleted file mode 100644 index aaab689..0000000 --- a/rpp/src/hal/_tms570_hdk/port_def.c +++ /dev/null @@ -1,127 +0,0 @@ -/* Copyright (C) 2012-2013 Czech Technical University in Prague - * - * Authors: - * - Michal Horn - * - * 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 : port_def.c - * - * Abstract: - * This file contains general ports definitions. Ports are defined according to their names on - * the RPP board. - * Each port is define by port descriptor, which consists of: - * - list of its pin (pin descriptors), - * - number of pins, - * - get value function pointer, - * - set value function pointer. - * Finally each port descriptor is mapped to the port name string. - * - * Get and set value function are defined for each port style (ADC, SPI, GPIO) in separated files. - */ - -#include "hal/hal.h" -#include "drv/spi.h" -#include "drv/_tms570_hdk/adc.h" - -// Lists of pins assigned to the ports -static uint32_t port_cfg_gioa[] = { - PIN_DSC_GIOA0, PIN_DSC_GIOA1, PIN_DSC_GIOA2, PIN_DSC_GIOA3, - PIN_DSC_GIOA4, PIN_DSC_GIOA5, PIN_DSC_GIOA6, PIN_DSC_GIOA7 -}; -static uint32_t port_cfg_giob[] = { - PIN_DSC_GIOB0, PIN_DSC_GIOB1, PIN_DSC_GIOB2, PIN_DSC_GIOB3, - PIN_DSC_GIOB4, PIN_DSC_GIOB5, PIN_DSC_GIOB6, PIN_DSC_GIOB7 -}; -static uint32_t port_cfg_nhet1[] = { - PIN_DSC_NHET1_0, PIN_DSC_NHET1_1, PIN_DSC_NHET1_2, - PIN_DSC_NHET1_3, PIN_DSC_NHET1_4, PIN_DSC_NHET1_5, - PIN_DSC_NHET1_7, PIN_DSC_NHET1_8, PIN_DSC_NHET1_9, - PIN_DSC_NHET1_10, PIN_DSC_NHET1_11, PIN_DSC_NHET1_12, - PIN_DSC_NHET1_14, PIN_DSC_NHET1_15, PIN_DSC_NHET1_16, - PIN_DSC_NHET1_17, PIN_DSC_NHET1_18, PIN_DSC_NHET1_19, - PIN_DSC_NHET1_20, PIN_DSC_NHET1_21, PIN_DSC_NHET1_22, - PIN_DSC_NHET1_23, PIN_DSC_NHET1_24, PIN_DSC_NHET1_25, - PIN_DSC_NHET1_26, PIN_DSC_NHET1_27, PIN_DSC_NHET1_28, - PIN_DSC_NHET1_29, PIN_DSC_NHET1_30, PIN_DSC_NHET1_31 -}; -static uint32_t port_cfg_adc[] = { (uint32_t)adcREG1, adcGROUP1, 1 }; - -// Port descriptors -static port_desc_t port_desc_gioa = { - .config = port_cfg_gioa, - .numValues = 8, - .interfaceType = GPIO, - .port_getfnc_ptr = &hal_gpio_port_get_val, - .port_setfnc_ptr = &hal_gpio_port_set_val, -}; -static port_desc_t port_desc_giob = { - .config = port_cfg_giob, - .numValues = 8, - .interfaceType = GPIO, - .port_getfnc_ptr = &hal_gpio_port_get_val, - .port_setfnc_ptr = &hal_gpio_port_set_val, -}; -static port_desc_t port_desc_nhet1 = { - .config = port_cfg_nhet1, - .numValues = 30, - .interfaceType = GPIO, - .port_getfnc_ptr = &hal_gpio_port_get_val, - .port_setfnc_ptr = &hal_gpio_port_set_val, -}; -static port_desc_t port_desc_adc = { - .config = port_cfg_adc, - .numValues = 16, - .interfaceType = ADC, - .port_getfnc_ptr = &adc_get_port_val, - .port_setfnc_ptr = ((void *)0), -}; - - -// Maps of port names to port descriptors -port_def_t port_definition[PORT_CNT] = { - {.name = PORT_NAME_GIOA, .desc = &port_desc_gioa}, - {.name = PORT_NAME_GIOB, .desc = &port_desc_giob}, - {.name = PORT_NAME_NHET1, .desc = &port_desc_nhet1}, - {.name = PORT_NAME_ADC, .desc = &port_desc_adc} -}; - -/** - * Get port descriptor assigned to port name. - * @param[in] port_name Pointer to string - the name of the port. - * @param[in] len Length of the name, if terminated by '/0', then len=-1 - * @return Port descriptor or NULL if not found - */ -port_desc_t *hal_port_get_dsc(const char *port_name, int len) -{ - uint32_t i; - const char *port_name_ptr; - char port_name_term[32]; - - if (len != -1) { // port name not terminated by '\0' - strncpy(port_name_term, port_name, len); - port_name_term[len] = '\0'; - port_name_ptr = port_name_term; - } - else port_name_ptr = port_name; - - for (i = 0; i < PORT_CNT; i++) { - if (strcmp(port_name_ptr, port_definition[i].name) == 0) - return port_definition[i].desc; - } - return NULL; -} - -/** - * Get port descriptor assigned to port name. - * @param[in] port_name Pointer to string - the name of the port. - * @param[in] len Length of the name, if terminated by '/0', then len=-1 - * @return Port descriptor or NULL if not found - */ -const port_def_t *hal_port_get_map() -{ - return (const port_def_t *)port_definition; -} diff --git a/rpp/src/hal/_tms570_hydctr/.gitattributes b/rpp/src/hal/_tms570_hydctr/.gitattributes deleted file mode 100644 index 3dbecf5..0000000 --- a/rpp/src/hal/_tms570_hydctr/.gitattributes +++ /dev/null @@ -1,2 +0,0 @@ -/gpio_def.c eaton -/port_def.c eaton diff --git a/rpp/src/hal/_tms570_hydctr/gpio_def.c b/rpp/src/hal/_tms570_hydctr/gpio_def.c deleted file mode 100644 index 98a8b2f..0000000 --- a/rpp/src/hal/_tms570_hydctr/gpio_def.c +++ /dev/null @@ -1,96 +0,0 @@ -/* Copyright (C) 2012-2013, 2015 Czech Technical University in Prague - * - * Authors: - * - Michal Horn - * - * 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 : hal_gpio_rm48_def.c - * - * Abstract: - * This file contains gpio pins definitions - * - * On RM48 MCU pins can operates as GIO on ports DMM, GIOA, GIOB, - * HET1 and HET2. Those pins, that are defined in this file, can be - * accessed directly as GPIO by hal_gpio_set_value and - * hal_gpio_get_value. Pin configuration can be modified by functions - * defined in hal_gpio_rm48 source and header files. - * - * NOTE: Although the configuration functions are implemented and - * should be ready to use, they were only slightly tested and are not - * used by the RPP software yet. - */ - -//#include "hal/gpio_rm48_def.h" -#include "hal/hal.h" - -/** - * Array of ports used as GPIO. Thanks to that array, we can - * determine port just by index in pin_desc at 5th bit */ -gioPORT_t *port_id_map[MAX_PORT_CNT] = { - [PORT_ID_GIOA] = (gioPORT_t *)gioPORTA, - [PORT_ID_GIOB] = (gioPORT_t *)gioPORTB, - [PORT_ID_HET1] = (gioPORT_t *)hetPORT1, - [PORT_ID_HET2] = (gioPORT_t *)hetPORT2 -}; - -/* Some pins are commented out, because they are pinmuxed with SCI. */ -/** - * Map of pin names to pin descriptors. Each pin can be then easily - * found just by its name given as a string to hal_gpio_get_pin_dsc - * function*/ -pin_map_element_t pin_map[MAX_PIN_CNT] = { - /* DMM pins */ - { .pin_name = PIN_NAME_GIOA0, .pin_desc = PIN_DSC_GIOA0 }, - { .pin_name = PIN_NAME_GIOA1, .pin_desc = PIN_DSC_GIOA1 }, - { .pin_name = PIN_NAME_GIOA2, .pin_desc = PIN_DSC_GIOA2 }, - { .pin_name = PIN_NAME_GIOA3, .pin_desc = PIN_DSC_GIOA3 }, - { .pin_name = PIN_NAME_GIOA4, .pin_desc = PIN_DSC_GIOA4 }, - { .pin_name = PIN_NAME_GIOA5, .pin_desc = PIN_DSC_GIOA5 }, - { .pin_name = PIN_NAME_GIOA6, .pin_desc = PIN_DSC_GIOA6 }, - { .pin_name = PIN_NAME_GIOA7, .pin_desc = PIN_DSC_GIOA7 }, - { .pin_name = PIN_NAME_GIOB0, .pin_desc = PIN_DSC_GIOB0 }, - { .pin_name = PIN_NAME_GIOB1, .pin_desc = PIN_DSC_GIOB1 }, - { .pin_name = PIN_NAME_GIOB2, .pin_desc = PIN_DSC_GIOB2 }, - { .pin_name = PIN_NAME_GIOB3, .pin_desc = PIN_DSC_GIOB3 }, - { .pin_name = PIN_NAME_GIOB4, .pin_desc = PIN_DSC_GIOB4 }, - { .pin_name = PIN_NAME_GIOB5, .pin_desc = PIN_DSC_GIOB5 }, - { .pin_name = PIN_NAME_GIOB6, .pin_desc = PIN_DSC_GIOB6 }, - { .pin_name = PIN_NAME_GIOB7, .pin_desc = PIN_DSC_GIOB7 }, - { .pin_name = PIN_NAME_NHET1_0, .pin_desc = PIN_DSC_NHET1_0 }, - { .pin_name = PIN_NAME_NHET1_1, .pin_desc = PIN_DSC_NHET1_1 }, - { .pin_name = PIN_NAME_NHET1_2, .pin_desc = PIN_DSC_NHET1_2 }, - { .pin_name = PIN_NAME_NHET1_3, .pin_desc = PIN_DSC_NHET1_3 }, - { .pin_name = PIN_NAME_NHET1_4, .pin_desc = PIN_DSC_NHET1_4 }, - { .pin_name = PIN_NAME_NHET1_5, .pin_desc = PIN_DSC_NHET1_5 }, - /*{ .pin_name = PIN_NAME_NHET1_6, .pin_desc = PIN_DSC_NHET1_6 },*/ - { .pin_name = PIN_NAME_NHET1_7, .pin_desc = PIN_DSC_NHET1_7 }, - { .pin_name = PIN_NAME_NHET1_8, .pin_desc = PIN_DSC_NHET1_8 }, - { .pin_name = PIN_NAME_NHET1_9, .pin_desc = PIN_DSC_NHET1_9 }, - { .pin_name = PIN_NAME_NHET1_10, .pin_desc = PIN_DSC_NHET1_10 }, - { .pin_name = PIN_NAME_NHET1_11, .pin_desc = PIN_DSC_NHET1_11 }, - { .pin_name = PIN_NAME_NHET1_12, .pin_desc = PIN_DSC_NHET1_12 }, - /*{ .pin_name = PIN_NAME_NHET1_13, .pin_desc = PIN_DSC_NHET1_13 },*/ - { .pin_name = PIN_NAME_NHET1_14, .pin_desc = PIN_DSC_NHET1_14 }, - { .pin_name = PIN_NAME_NHET1_15, .pin_desc = PIN_DSC_NHET1_15 }, - { .pin_name = PIN_NAME_NHET1_16, .pin_desc = PIN_DSC_NHET1_16 }, - { .pin_name = PIN_NAME_NHET1_17, .pin_desc = PIN_DSC_NHET1_17 }, - { .pin_name = PIN_NAME_NHET1_18, .pin_desc = PIN_DSC_NHET1_18 }, - { .pin_name = PIN_NAME_NHET1_19, .pin_desc = PIN_DSC_NHET1_19 }, - { .pin_name = PIN_NAME_NHET1_20, .pin_desc = PIN_DSC_NHET1_20 }, - { .pin_name = PIN_NAME_NHET1_21, .pin_desc = PIN_DSC_NHET1_21 }, - { .pin_name = PIN_NAME_NHET1_22, .pin_desc = PIN_DSC_NHET1_22 }, - { .pin_name = PIN_NAME_NHET1_23, .pin_desc = PIN_DSC_NHET1_23 }, - { .pin_name = PIN_NAME_NHET1_24, .pin_desc = PIN_DSC_NHET1_24 }, - { .pin_name = PIN_NAME_NHET1_25, .pin_desc = PIN_DSC_NHET1_25 }, - { .pin_name = PIN_NAME_NHET1_26, .pin_desc = PIN_DSC_NHET1_26 }, - { .pin_name = PIN_NAME_NHET1_27, .pin_desc = PIN_DSC_NHET1_27 }, - { .pin_name = PIN_NAME_NHET1_28, .pin_desc = PIN_DSC_NHET1_28 }, - { .pin_name = PIN_NAME_NHET1_29, .pin_desc = PIN_DSC_NHET1_29 }, - { .pin_name = PIN_NAME_NHET1_30, .pin_desc = PIN_DSC_NHET1_30 }, - { .pin_name = PIN_NAME_NHET1_31, .pin_desc = PIN_DSC_NHET1_31 }, - /* FIXME: add definitions of all unused pins DMM, HET2, SCI... */ -}; diff --git a/rpp/src/hal/_tms570_hydctr/port_def.c b/rpp/src/hal/_tms570_hydctr/port_def.c deleted file mode 100644 index c9537ef..0000000 --- a/rpp/src/hal/_tms570_hydctr/port_def.c +++ /dev/null @@ -1,130 +0,0 @@ -/* Copyright (C) 2012-2013 Czech Technical University in Prague - * - * Authors: - * - Michal Horn - * - * 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 : port_def.c - * - * Abstract: - * This file contains general ports definitions. Ports are defined according to their names on - * the RPP board. - * Each port is define by port descriptor, which consists of: - * - list of its pin (pin descriptors), - * - number of pins, - * - get value function pointer, - * - set value function pointer. - * Finally each port descriptor is mapped to the port name string. - * - * Get and set value function are defined for each port style (ADC, SPI, GPIO) in separated files. - */ - -#include "hal/hal.h" -#include "drv/spi.h" -#include "drv/_tms570_hydctr/adc.h" - -// FIXME Upper layer dependency/coupling -// Declared in drv/adc.h -extern uint32_t adc_get_port_val(uint32_t *config, uint32_t num_channels, uint32_t *values); - -// Lists of pins assigned to the ports -static uint32_t port_cfg_gioa[] = { - PIN_DSC_GIOA0, PIN_DSC_GIOA1, PIN_DSC_GIOA2, PIN_DSC_GIOA3, - PIN_DSC_GIOA4, PIN_DSC_GIOA5, PIN_DSC_GIOA6, PIN_DSC_GIOA7 -}; -static uint32_t port_cfg_giob[] = { - PIN_DSC_GIOB0, PIN_DSC_GIOB1, PIN_DSC_GIOB2, PIN_DSC_GIOB3, - PIN_DSC_GIOB4, PIN_DSC_GIOB5, PIN_DSC_GIOB6, PIN_DSC_GIOB7 -}; -static uint32_t port_cfg_nhet1[] = { - PIN_DSC_NHET1_0, PIN_DSC_NHET1_1, PIN_DSC_NHET1_2, - PIN_DSC_NHET1_3, PIN_DSC_NHET1_4, PIN_DSC_NHET1_5, - PIN_DSC_NHET1_7, PIN_DSC_NHET1_8, PIN_DSC_NHET1_9, - PIN_DSC_NHET1_10, PIN_DSC_NHET1_11, PIN_DSC_NHET1_12, - PIN_DSC_NHET1_14, PIN_DSC_NHET1_15, PIN_DSC_NHET1_16, - PIN_DSC_NHET1_17, PIN_DSC_NHET1_18, PIN_DSC_NHET1_19, - PIN_DSC_NHET1_20, PIN_DSC_NHET1_21, PIN_DSC_NHET1_22, - PIN_DSC_NHET1_23, PIN_DSC_NHET1_24, PIN_DSC_NHET1_25, - PIN_DSC_NHET1_26, PIN_DSC_NHET1_27, PIN_DSC_NHET1_28, - PIN_DSC_NHET1_29, PIN_DSC_NHET1_30, PIN_DSC_NHET1_31 -}; -static uint32_t port_cfg_adc[] = { (uint32_t)adcREG1, adcGROUP1, 1 }; - -// Port descriptors -static port_desc_t port_desc_gioa = { - .config = port_cfg_gioa, - .numValues = 8, - .interfaceType = GPIO, - .port_getfnc_ptr = &hal_gpio_port_get_val, - .port_setfnc_ptr = &hal_gpio_port_set_val, -}; -static port_desc_t port_desc_giob = { - .config = port_cfg_giob, - .numValues = 8, - .interfaceType = GPIO, - .port_getfnc_ptr = &hal_gpio_port_get_val, - .port_setfnc_ptr = &hal_gpio_port_set_val, -}; -static port_desc_t port_desc_nhet1 = { - .config = port_cfg_nhet1, - .numValues = 30, - .interfaceType = GPIO, - .port_getfnc_ptr = &hal_gpio_port_get_val, - .port_setfnc_ptr = &hal_gpio_port_set_val, -}; -static port_desc_t port_desc_adc = { - .config = port_cfg_adc, - .numValues = 16, - .interfaceType = ADC, - .port_getfnc_ptr = &adc_get_port_val, - .port_setfnc_ptr = ((void *)0), -}; - -// Maps of port names to port descriptors -port_def_t port_definition[PORT_CNT] = { - {.name = PORT_NAME_GIOA, .desc = &port_desc_gioa}, - {.name = PORT_NAME_GIOB, .desc = &port_desc_giob}, - {.name = PORT_NAME_NHET1, .desc = &port_desc_nhet1}, - {.name = PORT_NAME_ADC, .desc = &port_desc_adc} -}; - -/** - * Get port descriptor assigned to port name. - * @param[in] port_name Pointer to string - the name of the port. - * @param[in] len Length of the name, if terminated by '/0', then len=-1 - * @return Port descriptor or NULL if not found - */ -port_desc_t *hal_port_get_dsc(const char *port_name, int len) -{ - uint32_t i; - const char *port_name_ptr; - char port_name_term[32]; - - if (len != -1) { // port name not terminated by '\0' - strncpy(port_name_term, port_name, len); - port_name_term[len] = '\0'; - port_name_ptr = port_name_term; - } - else port_name_ptr = port_name; - - for (i = 0; i < PORT_CNT; i++) { - if (strcmp(port_name_ptr, port_definition[i].name) == 0) - return port_definition[i].desc; - } - return NULL; -} - -/** - * Get port descriptor assigned to port name. - * @param[in] port_name Pointer to string - the name of the port. - * @param[in] len Length of the name, if terminated by '/0', then len=-1 - * @return Port descriptor or NULL if not found - */ -const port_def_t *hal_port_get_map() -{ - return (const port_def_t *)port_definition; -} diff --git a/rpp/src/hal/_tms570_rpp/gpio_def.c b/rpp/src/hal/_tms570_rpp/gpio_def.c deleted file mode 100644 index 042db2f..0000000 --- a/rpp/src/hal/_tms570_rpp/gpio_def.c +++ /dev/null @@ -1,152 +0,0 @@ -/* Copyright (C) 2012-2013 Czech Technical University in Prague - * - * Authors: - * - Michal Horn - * - * 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 : hal_gpio_tms570_def.c - * - * Abstract: - * This file contains gpio pins definitions - * - * On TMS570 MCU pins can operates as GIO on ports DMM, GIOA, GIOB, - * HET1 and HET2. Those pins, that are defined in this file, can be - * accessed directly as GPIO by hal_gpio_set_value and - * hal_gpio_get_value. Pin configuration can be modified by functions - * defined in hal_gpio_tms570 source and header files. - * - * NOTE: Although the configuration functions are implemented and - * should be ready to use, they were only slightly tested and are not - * used by the RPP software yet. - */ - -//#include "hal/gpio_tms570_def.h" -#include "hal/hal.h" - -/** - * Array of ports used as GPIO. Thanks to that array, we can - * determine port just by index in pin_desc at 5th bit */ -gioPORT_t *port_id_map[MAX_PORT_CNT] = { - (gioPORT_t *)dmmPORT, - (gioPORT_t *)gioPORTA, - (gioPORT_t *)gioPORTB, - (gioPORT_t *)hetPORT1, - (gioPORT_t *)hetPORT2 -}; - -/** - * Map of pin names to pin descriptors. Each pin can be then easily - * found just by its name given as a string to hal_gpio_get_pin_dsc - * function*/ -pin_map_element_t pin_map[MAX_PIN_CNT] = { - /* DMM pins */ - { .pin_name = PIN_NAME_FANCTRL, .pin_desc = PIN_DSC_FANCTRL }, - { .pin_name = PIN_NAME_ETHRST, .pin_desc = PIN_DSC_ETHRST }, - { .pin_name = PIN_NAME_VBAT1EN, .pin_desc = PIN_DSC_VBAT1EN }, - { .pin_name = PIN_NAME_VBAT2EN, .pin_desc = PIN_DSC_VBAT2EN }, - { .pin_name = PIN_NAME_VBAT3EN, .pin_desc = PIN_DSC_VBAT3EN }, - { .pin_name = PIN_NAME_VBATEN, .pin_desc = PIN_DSC_VBATEN }, - { .pin_name = PIN_NAME_UNUSED, .pin_desc = PIN_DSC_DMM_UNUSED(6) }, - { .pin_name = PIN_NAME_SPICSA, .pin_desc = PIN_DSC_SPICSA }, - { .pin_name = PIN_NAME_SPICSB, .pin_desc = PIN_DSC_SPICSB }, - { .pin_name = PIN_NAME_UNUSED, .pin_desc = PIN_DSC_DMM_UNUSED(9)}, - { .pin_name = PIN_NAME_UNUSED, .pin_desc = PIN_DSC_DMM_UNUSED(10) }, - { .pin_name = PIN_NAME_MOUT1EN, .pin_desc = PIN_DSC_MOUT1EN }, - { .pin_name = PIN_NAME_MOUT2EN, .pin_desc = PIN_DSC_MOUT2EN }, - { .pin_name = PIN_NAME_CANNSTB, .pin_desc = PIN_DSC_CANNSTB }, - { .pin_name = PIN_NAME_UNUSED, .pin_desc = PIN_DSC_DMM_UNUSED(14) }, - { .pin_name = PIN_NAME_CANEN, .pin_desc = PIN_DSC_CANEN }, - { .pin_name = PIN_NAME_LIN2NSLP,.pin_desc = PIN_DSC_LIN2NSLP }, - { .pin_name = PIN_NAME_LIN1NSLP,.pin_desc = PIN_DSC_LIN1NSLP }, - { .pin_name = PIN_NAME_DININT, .pin_desc = PIN_DSC_DININT }, - /* GIOA pins */ - { .pin_name = PIN_NAME_DIN8, .pin_desc = PIN_DSC_DIN8 }, - { .pin_name = PIN_NAME_DIN9, .pin_desc = PIN_DSC_DIN9 }, - { .pin_name = PIN_NAME_DIN10, .pin_desc = PIN_DSC_DIN10 }, - { .pin_name = PIN_NAME_DIN11, .pin_desc = PIN_DSC_DIN11 }, - { .pin_name = PIN_NAME_DIN12, .pin_desc = PIN_DSC_DIN12 }, - { .pin_name = PIN_NAME_DIN13, .pin_desc = PIN_DSC_DIN13 }, - { .pin_name = PIN_NAME_DIN14, .pin_desc = PIN_DSC_DIN14 }, - { .pin_name = PIN_NAME_DIN15, .pin_desc = PIN_DSC_DIN15 }, - /* GIOB pins */ - { .pin_name = PIN_NAME_MOUT6EN, .pin_desc = PIN_DSC_MOUT6EN }, - { .pin_name = PIN_NAME_MOUT5EN, .pin_desc = PIN_DSC_MOUT5EN }, - { .pin_name = PIN_NAME_MOUT6IN, .pin_desc = PIN_DSC_MOUT6IN }, - { .pin_name = PIN_NAME_MOUT5IN, .pin_desc = PIN_DSC_MOUT5IN }, - { .pin_name = PIN_NAME_MOUT4EN, .pin_desc = PIN_DSC_MOUT4EN }, - { .pin_name = PIN_NAME_MOUT3EN, .pin_desc = PIN_DSC_MOUT3EN }, - { .pin_name = PIN_NAME_MOUT4IN, .pin_desc = PIN_DSC_MOUT4IN }, - { .pin_name = PIN_NAME_MOUT3IN, .pin_desc = PIN_DSC_MOUT3IN }, - /* HET1 pins */ - { .pin_name = PIN_NAME_UNUSED, .pin_desc = PIN_DSC_HET1_UNUSED(0) }, - { .pin_name = PIN_NAME_HBREN, .pin_desc = PIN_DSC_HBREN }, - { .pin_name = PIN_NAME_UNUSED, .pin_desc = PIN_DSC_HET1_UNUSED(2) }, - { .pin_name = PIN_NAME_UNUSED, .pin_desc = PIN_DSC_HET1_UNUSED(3) }, - { .pin_name = PIN_NAME_HBRDIR, .pin_desc = PIN_DSC_HBRDIR }, - { .pin_name = PIN_NAME_UNUSED, .pin_desc = PIN_DSC_HET1_UNUSED(5) }, - { .pin_name = PIN_NAME_UNUSED, .pin_desc = PIN_DSC_HET1_UNUSED(6) }, - { .pin_name = PIN_NAME_HBRPWM, .pin_desc = PIN_DSC_HBRPWM }, - { .pin_name = PIN_NAME_UNUSED, .pin_desc = PIN_DSC_HET1_UNUSED(8) }, - { .pin_name = PIN_NAME_MOUT1IN, .pin_desc = PIN_DSC_MOUT1IN }, - { .pin_name = PIN_NAME_UNUSED, .pin_desc = PIN_DSC_HET1_UNUSED(10) }, - { .pin_name = PIN_NAME_UNUSED, .pin_desc = PIN_DSC_HET1_UNUSED(11) }, - { .pin_name = PIN_NAME_UNUSED, .pin_desc = PIN_DSC_HET1_UNUSED(12) }, - { .pin_name = PIN_NAME_UNUSED, .pin_desc = PIN_DSC_HET1_UNUSED(13) }, - { .pin_name = PIN_NAME_MOUT2IN, .pin_desc = PIN_DSC_MOUT2IN }, - { .pin_name = PIN_NAME_UNUSED, .pin_desc = PIN_DSC_HET1_UNUSED(15) }, - { .pin_name = PIN_NAME_HOUT1IN, .pin_desc = PIN_DSC_HOUT1IN }, - { .pin_name = PIN_NAME_HOUT1DIAG,.pin_desc = PIN_DSC_HOUT1DIAG }, - { .pin_name = PIN_NAME_HOUT2IN, .pin_desc = PIN_DSC_HOUT2IN }, - { .pin_name = PIN_NAME_HOUT2DIAG,.pin_desc = PIN_DSC_HOUT2DIAG }, - { .pin_name = PIN_NAME_HOUT3IN, .pin_desc = PIN_DSC_HOUT3IN }, - { .pin_name = PIN_NAME_HOUT3DIAG,.pin_desc = PIN_DSC_HOUT3DIAG }, - { .pin_name = PIN_NAME_HOUT4IN, .pin_desc = PIN_DSC_HOUT4IN }, - { .pin_name = PIN_NAME_HOUT4DIAG,.pin_desc = PIN_DSC_HOUT4DIAG }, - { .pin_name = PIN_NAME_UNUSED, .pin_desc = PIN_DSC_HET1_UNUSED(22) }, - { .pin_name = PIN_NAME_UNUSED, .pin_desc = PIN_DSC_HET1_UNUSED(23) }, - { .pin_name = PIN_NAME_UNUSED, .pin_desc = PIN_DSC_HET1_UNUSED(24) }, - { .pin_name = PIN_NAME_HOUT5IN, .pin_desc = PIN_DSC_HOUT5IN }, - { .pin_name = PIN_NAME_UNUSED, .pin_desc = PIN_DSC_HET1_UNUSED(26) }, - { .pin_name = PIN_NAME_HOUT5DIAG,.pin_desc = PIN_DSC_HOUT5DIAG }, - { .pin_name = PIN_NAME_UNUSED, .pin_desc = PIN_DSC_HET1_UNUSED(28) }, - { .pin_name = PIN_NAME_HOUT6IN, .pin_desc = PIN_DSC_HOUT6IN }, - { .pin_name = PIN_NAME_UNUSED, .pin_desc = PIN_DSC_HET1_UNUSED(30) }, - { .pin_name = PIN_NAME_HOUT6DIAG,.pin_desc = PIN_DSC_HOUT6DIAG }, - /* HET2 pins */ - { .pin_name = PIN_NAME_UNUSED, .pin_desc = PIN_DSC_HET2_UNUSED(0) }, - { .pin_name = PIN_NAME_UNUSED, .pin_desc = PIN_DSC_HET2_UNUSED(1) }, - { .pin_name = PIN_NAME_UNUSED, .pin_desc = PIN_DSC_HET2_UNUSED(2) }, - { .pin_name = PIN_NAME_UNUSED, .pin_desc = PIN_DSC_HET2_UNUSED(3) }, - { .pin_name = PIN_NAME_UNUSED, .pin_desc = PIN_DSC_HET2_UNUSED(4) }, - { .pin_name = PIN_NAME_UNUSED, .pin_desc = PIN_DSC_HET2_UNUSED(5) }, - { .pin_name = PIN_NAME_UNUSED, .pin_desc = PIN_DSC_HET2_UNUSED(6) }, - { .pin_name = PIN_NAME_UNUSED, .pin_desc = PIN_DSC_HET2_UNUSED(7) }, - { .pin_name = PIN_NAME_UNUSED, .pin_desc = PIN_DSC_HET2_UNUSED(8) }, - { .pin_name = PIN_NAME_UNUSED, .pin_desc = PIN_DSC_HET2_UNUSED(9) }, - { .pin_name = PIN_NAME_UNUSED, .pin_desc = PIN_DSC_HET2_UNUSED(10) }, - { .pin_name = PIN_NAME_UNUSED, .pin_desc = PIN_DSC_HET2_UNUSED(11) }, - { .pin_name = PIN_NAME_UNUSED, .pin_desc = PIN_DSC_HET2_UNUSED(12) }, - { .pin_name = PIN_NAME_UNUSED, .pin_desc = PIN_DSC_HET2_UNUSED(13) }, - { .pin_name = PIN_NAME_UNUSED, .pin_desc = PIN_DSC_HET2_UNUSED(14) }, - { .pin_name = PIN_NAME_UNUSED, .pin_desc = PIN_DSC_HET2_UNUSED(15) }, - { .pin_name = PIN_NAME_UNUSED, .pin_desc = PIN_DSC_HET2_UNUSED(16) }, - { .pin_name = PIN_NAME_UNUSED, .pin_desc = PIN_DSC_HET2_UNUSED(17) }, - { .pin_name = PIN_NAME_UNUSED, .pin_desc = PIN_DSC_HET2_UNUSED(18) }, - { .pin_name = PIN_NAME_UNUSED, .pin_desc = PIN_DSC_HET2_UNUSED(19) }, - { .pin_name = PIN_NAME_UNUSED, .pin_desc = PIN_DSC_HET2_UNUSED(20) }, - { .pin_name = PIN_NAME_UNUSED, .pin_desc = PIN_DSC_HET2_UNUSED(21) }, - { .pin_name = PIN_NAME_UNUSED, .pin_desc = PIN_DSC_HET2_UNUSED(22) }, - { .pin_name = PIN_NAME_UNUSED, .pin_desc = PIN_DSC_HET2_UNUSED(23) }, - { .pin_name = PIN_NAME_UNUSED, .pin_desc = PIN_DSC_HET2_UNUSED(24) }, - { .pin_name = PIN_NAME_UNUSED, .pin_desc = PIN_DSC_HET2_UNUSED(25) }, - { .pin_name = PIN_NAME_UNUSED, .pin_desc = PIN_DSC_HET2_UNUSED(26) }, - { .pin_name = PIN_NAME_UNUSED, .pin_desc = PIN_DSC_HET2_UNUSED(27) }, - { .pin_name = PIN_NAME_UNUSED, .pin_desc = PIN_DSC_HET2_UNUSED(28) }, - { .pin_name = PIN_NAME_UNUSED, .pin_desc = PIN_DSC_HET2_UNUSED(29) }, - { .pin_name = PIN_NAME_UNUSED, .pin_desc = PIN_DSC_HET2_UNUSED(30) }, - { .pin_name = PIN_NAME_UNUSED, .pin_desc = PIN_DSC_HET2_UNUSED(31) } -}; diff --git a/rpp/src/hal/_tms570_rpp/port_def.c b/rpp/src/hal/_tms570_rpp/port_def.c deleted file mode 100644 index bc48325..0000000 --- a/rpp/src/hal/_tms570_rpp/port_def.c +++ /dev/null @@ -1,192 +0,0 @@ -/* Copyright (C) 2012-2013, 2015 Czech Technical University in Prague - * - * Authors: - * - Michal Horn - * - * 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 : port_def.c - * - * Abstract: - * This file contains general ports definitions. Ports are defined according to their names on - * the RPP board. - * Each port is define by port descriptor, which consists of: - * - list of its pin (pin descriptors), - * - number of pins, - * - get value function pointer, - * - set value function pointer. - * Finally each port descriptor is mapped to the port name string. - * - * Get and set value function are defined for each port style (ADC, SPI, GPIO) in separated files. - */ - -#include "hal/hal.h" -#include "drv/spi.h" -#include "drv/_tms570_rpp/adc.h" - -// FIXME Upper layer dependency/coupling -// Declared in drv/adc.h -extern uint32_t adc_get_port_val(uint32_t *config, uint32_t num_channels, uint32_t *values); - - -// Lists of pins assigned to the ports -static uint32_t port_cfg_dinmcu[] = { - PIN_DSC_DIN8, PIN_DSC_DIN9, PIN_DSC_DIN10, PIN_DSC_DIN11, - PIN_DSC_DIN12, PIN_DSC_DIN13, PIN_DSC_DIN14, PIN_DSC_DIN15 -}; -static uint32_t port_cfg_dinspi[] = { 1, 0 }; -static uint32_t port_cfg_houtdiag[] = { - PIN_DSC_HOUT1DIAG, PIN_DSC_HOUT2DIAG, PIN_DSC_HOUT3DIAG, - PIN_DSC_HOUT4DIAG, PIN_DSC_HOUT5DIAG, PIN_DSC_HOUT6DIAG -}; -static uint32_t port_cfg_houtin[] = { - PIN_DSC_HOUT1IN, PIN_DSC_HOUT2IN, PIN_DSC_HOUT3IN, - PIN_DSC_HOUT4IN, PIN_DSC_HOUT5IN, PIN_DSC_HOUT6IN -}; -static uint32_t port_cfg_houtifbk[] = { (uint32_t)adcREG2, adcGROUP1, 0 }; -static uint32_t port_cfg_adc[] = { (uint32_t)adcREG1, adcGROUP1, 1 }; -static uint32_t port_cfg_lout[] = { 1, 1 }; -static uint32_t port_cfg_dac1_2[] = { 3, 0 }; -static uint32_t port_cfg_dac3_4[] = { 3, 1 }; -static uint32_t port_cfg_dacdref[] = { 3, 2 }; -static uint32_t port_cfg_hbr[] = { 4, 0 }; -static uint32_t port_cfg_fray1[] = { 4, 1 }; -static uint32_t port_cfg_fray2[] = { 4, 2 }; -static uint32_t port_cfg_mouten[] = { - PIN_DSC_MOUT1EN, PIN_DSC_MOUT2EN, PIN_DSC_MOUT3EN, - PIN_DSC_MOUT4EN, PIN_DSC_MOUT5EN, PIN_DSC_MOUT6EN -}; -static uint32_t port_cfg_moutin[] = { - PIN_DSC_MOUT1IN, PIN_DSC_MOUT2IN, PIN_DSC_MOUT3IN, - PIN_DSC_MOUT4IN, PIN_DSC_MOUT5IN, PIN_DSC_MOUT6IN -}; - -// Port descriptors -static port_desc_t port_desc_dinmcu = { - .config = port_cfg_dinmcu, - .numValues = 8, - .interfaceType = GPIO, - .port_getfnc_ptr = &hal_gpio_port_get_val, - .port_setfnc_ptr = ((void *)0), -}; -static port_desc_t port_desc_dinspi = { - .config = port_cfg_dinspi, - .numValues = 3, - .interfaceType = SPI, - .port_getfnc_ptr = ((void *)0), - .port_setfnc_ptr = &hal_spi_port_transfer_command, -}; -static port_desc_t port_desc_houtdiag = { - .config = port_cfg_houtdiag, - .numValues = 6, - .interfaceType = GPIO, - .port_getfnc_ptr = &hal_gpio_port_get_val, - .port_setfnc_ptr = ((void *)0), -}; -static port_desc_t port_desc_houtin = { - .config = port_cfg_houtin, - .numValues = 6, - .interfaceType = GPIO, - .port_getfnc_ptr = &hal_gpio_port_get_val, - .port_setfnc_ptr = &hal_gpio_port_set_val, -}; -static port_desc_t port_desc_houtifbk = { - .config = port_cfg_houtifbk, - .numValues = 6, - .interfaceType = ADC, - .port_getfnc_ptr = &adc_get_port_val, - .port_setfnc_ptr = ((void *)0), -}; -static port_desc_t port_desc_adc = { - .config = port_cfg_adc, - .numValues = 12, - .interfaceType = ADC, - .port_getfnc_ptr = &adc_get_port_val, - .port_setfnc_ptr = ((void *)0), -}; -static port_desc_t port_desc_lout = { - .config = port_cfg_lout, - .numValues = 4, - .interfaceType = SPI, - .port_getfnc_ptr = ((void *)0), - .port_setfnc_ptr = &hal_spi_port_transfer_command, -}; -static port_desc_t port_desc_dac1_2 = { - .config = port_cfg_dac1_2, - .numValues = 2, - .interfaceType = SPI, - .port_getfnc_ptr = ((void *)0), - .port_setfnc_ptr = &hal_spi_port_transfer_command, -}; -static port_desc_t port_desc_dac3_4 = { - .config = port_cfg_dac3_4, - .numValues = 2, - .interfaceType = SPI, - .port_getfnc_ptr = ((void *)0), - .port_setfnc_ptr = &hal_spi_port_transfer_command, -}; -static port_desc_t port_desc_dacdref = { - .config = port_cfg_dacdref, - .numValues = 2, - .interfaceType = SPI, - .port_getfnc_ptr = ((void *)0), - .port_setfnc_ptr = &hal_spi_port_transfer_command, -}; -static port_desc_t port_desc_hbr = { - .config = port_cfg_hbr, - .numValues = 2, - .interfaceType = SPI, - .port_getfnc_ptr = ((void *)0), - .port_setfnc_ptr = &hal_spi_port_transfer_command, -}; -static port_desc_t port_desc_fray1 = { - .config = port_cfg_fray1, - .numValues = 2, - .interfaceType = SPI, - .port_getfnc_ptr = ((void *)0), - .port_setfnc_ptr = &hal_spi_port_transfer_command, -}; -static port_desc_t port_desc_fray2 = { - .config = port_cfg_fray2, - .numValues = 2, - .interfaceType = SPI, - .port_getfnc_ptr = ((void *)0), - .port_setfnc_ptr = &hal_spi_port_transfer_command, -}; -static port_desc_t port_desc_mouten = { - .config = port_cfg_mouten, - .numValues = 6, - .interfaceType = GPIO, - .port_getfnc_ptr = &hal_gpio_port_get_val, - .port_setfnc_ptr = ((void *)0), -}; -static port_desc_t port_desc_moutin = { - .config = port_cfg_moutin, - .numValues = 6, - .interfaceType = GPIO, - .port_getfnc_ptr = &hal_gpio_port_get_val, - .port_setfnc_ptr = &hal_gpio_port_set_val, -}; - -// Maps of port names to port descriptors -port_def_t port_definition[PORT_CNT] = { - {.name = PORT_NAME_DINMCU, .desc = &port_desc_dinmcu}, - {.name = PORT_NAME_DINSPI, .desc = &port_desc_dinspi}, - {.name = PORT_NAME_HOUTDIAG, .desc = &port_desc_houtdiag}, - {.name = PORT_NAME_HOUTIN, .desc = &port_desc_houtin}, - {.name = PORT_NAME_HOUTIFBK, .desc = &port_desc_houtifbk}, - {.name = PORT_NAME_ADC, .desc = &port_desc_adc}, - {.name = PORT_NAME_LOUT, .desc = &port_desc_lout}, - {.name = PORT_NAME_DAC1_2, .desc = &port_desc_dac1_2}, - {.name = PORT_NAME_DAC3_4, .desc = &port_desc_dac3_4}, - {.name = PORT_NAME_DACDREF, .desc = &port_desc_dacdref}, - {.name = PORT_NAME_HBR, .desc = &port_desc_hbr}, - {.name = PORT_NAME_FRAY1, .desc = &port_desc_fray1}, - {.name = PORT_NAME_FRAY2, .desc = &port_desc_fray2}, - {.name = PORT_NAME_MOUTEN, .desc = &port_desc_mouten}, - {.name = PORT_NAME_MOUTIN, .desc = &port_desc_moutin} -}; - diff --git a/rpp/src/hal/hal.c b/rpp/src/hal/hal.c deleted file mode 100644 index c7c3483..0000000 --- a/rpp/src/hal/hal.c +++ /dev/null @@ -1,225 +0,0 @@ -/* - * hal.c - * - * Created on: 16.7.2015 - * Author: michal - */ - -#include "hal/hal.h" -#include "drv/spi.h" - -extern gioPORT_t *port_id_map[MAX_PORT_CNT]; -extern pin_map_element_t pin_map[MAX_PIN_CNT]; -extern port_def_t port_definition[PORT_CNT]; - -#define SPI_PORT_BUF_LEN 4 -/** Buffer for spi command to be sent */ -uint8_t spi_port_buf_tx[SPI_PORT_BUF_LEN]; -/** Buffer for spi response */ -uint8_t spi_port_buf_rx[SPI_PORT_BUF_LEN]; - -uint8_t hal_gpio_get_pin_cnt() { - return MAX_PIN_CNT; -} - -pin_map_element_t* hal_gpio_get_pin_map() { - return pin_map; -} - -gioPORT_t *hal_gpio_get_port_base(uint32_t port_num) -{ - return port_id_map[port_num]; -} - -uint32_t hal_gpio_pin_get_port_num(uint32_t pin_dsc) -{ - - return (pin_dsc & ~PORT_CONF_MASK) >> PORT_SHIFT; -} - -gioPORT_t *hal_gpio_pin_get_port_base(uint32_t pin_dsc) -{ - return hal_gpio_get_port_base(hal_gpio_pin_get_port_num(pin_dsc)); -} - - -uint32_t *hal_gpio_pin_get_dsc(const char *pin_name, int len) -{ - uint32_t i; - const char *pin_name_ptr; - char pin_name_term[32]; - - if (len != -1) { // pin name not terminated by '\0' - strncpy(pin_name_term, pin_name, len); - pin_name_term[len] = '\0'; - pin_name_ptr = pin_name_term; - } - else pin_name_ptr = pin_name; - - for (i = 0; i < MAX_PIN_CNT; i++) { - if (strcmp(pin_name_ptr, pin_map[i].pin_name) == 0) - return &pin_map[i].pin_desc; - } - return NULL; -} - - -uint32_t hal_gpio_pin_get_value(uint32_t pin_dsc) -{ - return ((hal_gpio_pin_get_port_base(pin_dsc)->DIN) >> (pin_dsc & 0x1f)) & 1; -} - - -void hal_gpio_pin_set_value(uint32_t pin_dsc, uint32_t value) -{ - if (value) - hal_gpio_pin_get_port_base(pin_dsc)->DSET = 1 << (pin_dsc & 0x1f); - else - hal_gpio_pin_get_port_base(pin_dsc)->DCLR = 1 << (pin_dsc & 0x1f); -} - - -int hal_gpio_pin_set_dir_in(uint32_t pin_dsc) -{ - hal_gpio_pin_get_port_base(pin_dsc)->DIR &= ~(1 << (pin_dsc & 0x1f)); - return 0; -} - -int hal_gpio_pin_set_dir_out(uint32_t pin_dsc, uint32_t value) -{ - hal_gpio_pin_set_value(pin_dsc, value); - hal_gpio_pin_get_port_base(pin_dsc)->DIR |= (1 << (pin_dsc & 0x1f)); - return 0; -} - -int hal_gpio_pin_get_dir(uint32_t pin_dsc) -{ - return (hal_gpio_pin_get_port_base(pin_dsc)->DIR >> (pin_dsc & 0x1f)) & 1; -} - - -uint32_t hal_gpio_pin_set_mode(uint32_t pin_dsc, uint32_t mode) -{ - gioPORT_t *gioPort = hal_gpio_pin_get_port_base(pin_dsc); - - if (mode & PORT_CONF_MODE_PTYPE_MASK) - gioPort->PSL |= (1 << (pin_dsc & 0x1f)); - else - gioPort->PSL &= ~(1 << (pin_dsc & 0x1f)); - if (mode & PORT_CONF_MODE_PEN_MASK) - gioPort->PULDIS |= (1 << (pin_dsc & 0x1f)); - else - gioPort->PULDIS &= ~(1 << (pin_dsc & 0x1f)); - return 0; -} - - -uint32_t hal_gpio_pin_set_od(uint32_t pin_dsc, uint32_t od) -{ - gioPORT_t *gioPort = hal_gpio_pin_get_port_base(pin_dsc); - - if (od & PORT_CONF_OD_ON) - gioPort->PDR |= (1 << (pin_dsc & 0x1f)); - else - gioPort->PDR &= ~(1 << (pin_dsc & 0x1f)); - return 0; -} - - -uint32_t hal_gpio_pin_set_config(uint32_t pin_dsc, uint32_t conf) -{ - pin_dsc &= ~PORT_CONF_MASK; - hal_gpio_pin_set_mode(pin_dsc, conf & PORT_CONF_MODE_MASK); - hal_gpio_pin_set_od(pin_dsc, conf & PORT_CONF_OD_MASK); - if (conf & PORT_CONF_SET_DIR) { - if ((conf & PORT_CONF_DIR_MASK) == (PORT_CONF_DIR_IN & PORT_CONF_DIR_MASK)) - hal_gpio_pin_set_dir_in(pin_dsc); - else - hal_gpio_pin_set_dir_out(pin_dsc, conf & PORT_CONF_INIT_HIGH); - } - - return 0; -} - -uint32_t hal_gpio_pin_configure(uint32_t pin_dsc) -{ - return hal_gpio_pin_set_config(pin_dsc, pin_dsc); -} - - -uint32_t hal_gpio_port_get_val(uint32_t *config, uint32_t num_val, uint32_t *values) -{ - uint32_t i; - - for (i = 0; i < num_val; i++) { - values[i] = hal_gpio_pin_get_value(config[i]); - } - return 0; -} - -uint32_t hal_gpio_port_set_val(uint32_t *config, uint32_t num_val, const uint32_t *values) -{ - uint32_t i; - - for (i = 0; i < num_val; i++) { - hal_gpio_pin_set_value(config[i], (values[i/8] >> i%8) & 0x1); - } - return 0; -} - -const port_def_t *hal_port_get_map() -{ - return (const port_def_t *)port_definition; -} - -port_desc_t *hal_port_get_dsc(const char *port_name, int len) -{ - uint32_t i; - const char *port_name_ptr; - char port_name_term[32]; - - if (len != -1) { // port name not terminated by '\0' - strncpy(port_name_term, port_name, len); - port_name_term[len] = '\0'; - port_name_ptr = port_name_term; - } - else port_name_ptr = port_name; - - for (i = 0; i < PORT_CNT; i++) { - if (strcmp(port_name_ptr, port_definition[i].name) == 0) - return port_definition[i].desc; - } - return NULL; -} - -uint32_t hal_port_get_val_cnt(const port_desc_t* port_desc) { - if (port_desc != NULL) { - return port_desc->numValues; - } - else { - return 0; - } -} - -uint32_t hal_spi_port_transfer_command(uint32_t *config, uint32_t num_bytes, const uint32_t *commands) -{ - spi_drv_t *ifc; - int i; - uint32_t ret; - - for (i = 0; i < num_bytes; i++) - spi_port_buf_tx[i] = commands[i]; - - ifc = spi_find_drv(NULL, config[0]); - if (ifc == NULL) - return 0; - - if (!(ifc->flags & SPI_IFC_ON)) - return 0; - - spi_transfer(ifc, config[1], num_bytes, spi_port_buf_tx, spi_port_buf_rx); - ret = 0; - for (i = 0; i < num_bytes; i++) - ret |= spi_port_buf_rx[i] << i*8; - return ret; -} diff --git a/rpp/src/hal/spi_resp_transl.c b/rpp/src/hal/spi_resp_transl.c index 0edfc3b..967025f 100644 --- a/rpp/src/hal/spi_resp_transl.c +++ b/rpp/src/hal/spi_resp_transl.c @@ -26,7 +26,7 @@ * bit or group of bits in the response. */ -#include "hal/hal.h" +#include "drv/digital_io.h" #include "drv/spi.h" #include "hal/spi_resp_transl.h" @@ -268,13 +268,13 @@ static const spitr_cmd_map_t hbr_cmd_map[HBR_NUM_CMD_D] = { /* Map command maps to SPI peripheral name */ static const spitr_name_map_t spitr_map[NUM_SPI_DEVICES] = { - { .spi_name = PORT_NAME_DINSPI, .cmd_map = din_cmd_map, .num_cmd = DIN_NUM_CMD_D}, - { .spi_name = PORT_NAME_LOUT, .cmd_map = lout_cmd_map, .num_cmd = LOUT_NUM_CMD_D }, - { .spi_name = PORT_NAME_DAC1_2, .cmd_map = dac_cmd_map, .num_cmd = DAC_NUM_CMD_D }, - { .spi_name = PORT_NAME_DAC3_4, .cmd_map = dac_cmd_map, .num_cmd = DAC_NUM_CMD_D }, - { .spi_name = PORT_NAME_HBR, .cmd_map = hbr_cmd_map, .num_cmd = HBR_NUM_CMD_D }, - { .spi_name = PORT_NAME_FRAY1, .cmd_map = fray_cmd_map, .num_cmd = FRAY_NUM_CMD_D }, - { .spi_name = PORT_NAME_FRAY2, .cmd_map = fray_cmd_map, .num_cmd = FRAY_NUM_CMD_D } + { .spi_name = DIO_PORT_NAME_DINSPI, .cmd_map = din_cmd_map, .num_cmd = DIN_NUM_CMD_D}, + { .spi_name = DIO_PORT_NAME_LOUT, .cmd_map = lout_cmd_map, .num_cmd = LOUT_NUM_CMD_D }, + { .spi_name = DIO_PORT_NAME_DAC1_2, .cmd_map = dac_cmd_map, .num_cmd = DAC_NUM_CMD_D }, + { .spi_name = DIO_PORT_NAME_DAC3_4, .cmd_map = dac_cmd_map, .num_cmd = DAC_NUM_CMD_D }, + { .spi_name = DIO_PORT_NAME_HBR, .cmd_map = hbr_cmd_map, .num_cmd = HBR_NUM_CMD_D }, + { .spi_name = DIO_PORT_NAME_FRAY1, .cmd_map = fray_cmd_map, .num_cmd = FRAY_NUM_CMD_D }, + { .spi_name = DIO_PORT_NAME_FRAY2, .cmd_map = fray_cmd_map, .num_cmd = FRAY_NUM_CMD_D } }; diff --git a/rpp/src/rpp/eth.c b/rpp/src/rpp/eth.c index bf8efb8..0d3fd72 100644 --- a/rpp/src/rpp/eth.c +++ b/rpp/src/rpp/eth.c @@ -60,7 +60,7 @@ #include "netif/ppp_oe.h" /* end - lwIP headers */ -#include "hal/hal.h" +#include "drv/digital_io.h" #include "sys/sys.h" /* includes - sys/phy_dp83848h.h */ #include "drv/emac.h" #include "os/os.h" @@ -521,16 +521,17 @@ static err_t rpp_eth_hw_init(struct hdkif *hdkif) */ index = configCPU_CLOCK_HZ/1000000; #endif /* NO_SYS */ - hal_gpio_pin_set_value(*hal_gpio_pin_get_dsc(PIN_NAME_ETHRST, -1), 0); - while(index--) - ; + dio_gpio_pin_set_value(*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 */ - hal_gpio_pin_set_value(*hal_gpio_pin_get_dsc(PIN_NAME_ETHRST, -1), 1); + dio_gpio_pin_set_value(*dio_gpio_pin_get_dsc(DIO_PIN_NAME_ETHRST, -1), 1); /* Initialize EMAC control module and EMAC module */ EMACInit(hdkif->emac_ctrl_base, hdkif->emac_base); diff --git a/rpp/src/rpp/gio.c b/rpp/src/rpp/gio.c index 0c3b1d8..37d8cdb 100644 --- a/rpp/src/rpp/gio.c +++ b/rpp/src/rpp/gio.c @@ -14,9 +14,9 @@ static uint32_t ports_initialized = 0; /* Configuration consistency check */ -#if RPP_GIO_PORT_GIOA != (1 << PORT_ID_GIOA) || \ - RPP_GIO_PORT_GIOB != (1 << PORT_ID_GIOB) || \ - RPP_GIO_PORT_NHET1 != (1 << PORT_ID_HET1) +#if RPP_GIO_PORT_GIOA != (1 << DIO_PORT_ID_GIOA) || \ + RPP_GIO_PORT_GIOB != (1 << DIO_PORT_ID_GIOB) || \ + RPP_GIO_PORT_NHET1 != (1 << DIO_PORT_ID_HET1) #error Port configuration is not consistent. #endif @@ -25,14 +25,14 @@ int8_t rpp_gio_init(uint32_t init_ports) unsigned pin; gioREG->GCR0 = 1; // Bring GIO out of reset - pin_map_element_t* pin_map = hal_gpio_get_pin_map(); + dio_pin_map_element_t* pin_map = dio_gpio_get_pin_map(); - for (pin = 0; pin < hal_gpio_get_pin_cnt(); pin++) { - int port_num = hal_gpio_pin_get_port_num(pin_map[pin].pin_desc); + for (pin = 0; pin < dio_gpio_get_pin_cnt(); pin++) { + int port_num = dio_gpio_pin_get_port_num(pin_map[pin].pin_desc); if ((init_ports & (1 << port_num)) && !(ports_initialized & (1 << port_num))) - hal_gpio_pin_configure(pin_map[pin].pin_desc); + dio_gpio_pin_configure(pin_map[pin].pin_desc); } ports_initialized |= init_ports; -- 2.39.2