From 422173a5f74d68bf9cc5952ee96ef00d7f3ea73d Mon Sep 17 00:00:00 2001 From: Jared Boone Date: Mon, 4 Aug 2014 14:20:42 -0700 Subject: [PATCH] SGPIO: Add CPLD RX Q channel inversion, API to control. --- firmware/common/sgpio.c | 12 +++++++++++- firmware/common/sgpio.h | 1 + firmware/cpld/sgpio_if/top.ucf | 1 + firmware/cpld/sgpio_if/top.vhd | 9 ++++++++- 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/firmware/common/sgpio.c b/firmware/common/sgpio.c index 41baa00f..4c87bb44 100644 --- a/firmware/common/sgpio.c +++ b/firmware/common/sgpio.c @@ -43,13 +43,15 @@ void sgpio_configure_pin_functions() { scu_pinmux(SCU_PINMUX_SGPIO9, SCU_GPIO_FAST | SCU_CONF_FUNCTION7); scu_pinmux(SCU_PINMUX_SGPIO10, SCU_GPIO_FAST | SCU_CONF_FUNCTION6); scu_pinmux(SCU_PINMUX_SGPIO11, SCU_GPIO_FAST | SCU_CONF_FUNCTION6); - scu_pinmux(SCU_PINMUX_SGPIO12, SCU_GPIO_FAST | SCU_CONF_FUNCTION6); + scu_pinmux(SCU_PINMUX_SGPIO12, SCU_GPIO_FAST | SCU_CONF_FUNCTION0); /* GPIO0[13] */ scu_pinmux(SCU_PINMUX_SGPIO13, SCU_GPIO_FAST | SCU_CONF_FUNCTION4); /* GPIO5[12] */ scu_pinmux(SCU_PINMUX_SGPIO14, SCU_GPIO_FAST | SCU_CONF_FUNCTION4); /* GPIO5[13] */ scu_pinmux(SCU_PINMUX_SGPIO15, SCU_GPIO_FAST | SCU_CONF_FUNCTION4); /* GPIO5[14] */ sgpio_cpld_stream_rx_set_decimation(1); + sgpio_cpld_stream_rx_set_q_invert(0); + GPIO_DIR(GPIO0) |= GPIOPIN13; GPIO_DIR(GPIO5) |= GPIOPIN14 | GPIOPIN13 | GPIOPIN12; } @@ -300,3 +302,11 @@ bool sgpio_cpld_stream_rx_set_decimation(const uint_fast8_t n) { return (skip_n < 8); } + +void sgpio_cpld_stream_rx_set_q_invert(const uint_fast8_t invert) { + if( invert ) { + GPIO_SET(GPIO0) = GPIOPIN13; + } else { + GPIO_CLR(GPIO0) = GPIOPIN13; + } +} diff --git a/firmware/common/sgpio.h b/firmware/common/sgpio.h index 62bc8f4e..c7c13f8c 100644 --- a/firmware/common/sgpio.h +++ b/firmware/common/sgpio.h @@ -42,5 +42,6 @@ void sgpio_cpld_stream_disable(); bool sgpio_cpld_stream_is_enabled(); bool sgpio_cpld_stream_rx_set_decimation(const uint_fast8_t n); +void sgpio_cpld_stream_rx_set_q_invert(const uint_fast8_t invert); #endif//__SGPIO_H__ diff --git a/firmware/cpld/sgpio_if/top.ucf b/firmware/cpld/sgpio_if/top.ucf index 7fb009ba..db85ab13 100755 --- a/firmware/cpld/sgpio_if/top.ucf +++ b/firmware/cpld/sgpio_if/top.ucf @@ -59,6 +59,7 @@ NET "HOST_DATA<0>" LOC="89" |IOSTANDARD=LVCMOS33 | SLEW=SLOW | TNM=to_host; NET "HOST_DECIM_SEL<2>" LOC="78" |IOSTANDARD=LVCMOS33; NET "HOST_DECIM_SEL<1>" LOC="81" |IOSTANDARD=LVCMOS33; NET "HOST_DECIM_SEL<0>" LOC="90" |IOSTANDARD=LVCMOS33; +NET "HOST_Q_INVERT" LOC="70" |IOSTANDARD=LVCMOS33; TIMEGRP "adc_data" OFFSET = IN 16 ns BEFORE "CODEC_X2_CLK"; diff --git a/firmware/cpld/sgpio_if/top.vhd b/firmware/cpld/sgpio_if/top.vhd index c8fab177..a3e45d38 100755 --- a/firmware/cpld/sgpio_if/top.vhd +++ b/firmware/cpld/sgpio_if/top.vhd @@ -33,6 +33,7 @@ entity top is HOST_DISABLE : in std_logic; HOST_DIRECTION : in std_logic; HOST_DECIM_SEL : in std_logic_vector(2 downto 0); + HOST_Q_INVERT : in std_logic; DA : in std_logic_vector(7 downto 0); DD : out std_logic_vector(9 downto 0); @@ -62,6 +63,9 @@ architecture Behavioral of top is signal decimate_count : std_logic_vector(2 downto 0) := "111"; signal decimate_sel_i : std_logic_vector(2 downto 0); signal decimate_en : std_logic; + + signal q_invert : std_logic; + signal q_invert_mask : std_logic_vector(7 downto 0); begin @@ -113,6 +117,9 @@ begin end if; end process; + q_invert <= HOST_Q_INVERT; + q_invert_mask <= X"80" when q_invert = '1' else X"7f"; + process(host_clk_i) begin if rising_edge(host_clk_i) then @@ -121,7 +128,7 @@ begin data_to_host_o <= adc_data_i xor X"80"; else -- Q: inverted between MAX2837 and MAX5864 - data_to_host_o <= adc_data_i xor X"7f"; + data_to_host_o <= adc_data_i xor q_invert_mask; end if; end if; end process;