2 -- * LXPWR slave part *
3 -- common sioreg & common counter for several ADC&PWM blocks
5 -- part of LXPWR motion control board (c) PiKRON Ltd
6 -- idea by Pavel Pisa PiKRON Ltd <pisa@cmp.felk.cvut.cz>
7 -- code by Marek Peca <mp@duch.cz>
14 use ieee.std_logic_1164.all;
15 use ieee.numeric_std.all;
17 use work.qcounter.all;
19 entity rpi_mc_simple_dc is
21 gpio2: in std_logic; -- SDA
22 gpio3: in std_logic; -- SCL
23 gpio4: out std_logic; -- CLK
24 gpio14: in std_logic; -- Tx
25 gpio15: in std_logic; -- Rx
26 gpio17: out std_logic; -- RTS
27 gpio18: out std_logic; -- PWM0/PCMCLK
28 gpio27: out std_logic; -- SD1DAT3
29 gpio22: out std_logic; -- SD1CLK
30 gpio23: out std_logic; -- SD1CMD
31 gpio24: out std_logic; -- SD1DAT0
32 gpio10: in std_logic; -- SPI0MOSI
33 gpio9: out std_logic; -- SPI0MISO
34 gpio25: out std_logic; -- SD1DAT1
35 gpio11: in std_logic; -- SPI0SCLK
36 gpio8: in std_logic; -- SPI0CE0
37 gpio7: in std_logic; -- SPI0CE1
38 gpio5: in std_logic; -- GPCLK1
39 gpio6: in std_logic; -- GPCLK2
40 gpio12: in std_logic; -- PWM0
41 gpio13: in std_logic; -- PWM1
42 gpio19: in std_logic; -- PWM1/SPI1MISO/PCMFS
43 gpio16: in std_logic; -- SPI1CE2
44 gpio26: in std_logic; -- SD1DAT2
45 gpio20: in std_logic; -- SPI1MOSI/PCMDIN/GPCLK0
46 gpio21: in std_logic; -- SPI1SCLK/PCMDOUT/GPCLK1
49 -- Each PWM signal has cooresponding shutdown
50 pwm: out std_logic_vector (1 to 3);
51 shdn: out std_logic_vector (1 to 3);
52 -- Fault/power stage status
53 stat: in std_logic_vector (1 to 3);
55 hal_in: in std_logic_vector (1 to 3);
61 power_stat: in std_logic;
63 adc_miso: in std_logic;
64 adc_mosi: in std_logic;
65 adc_sclk: in std_logic;
66 adc_scs: in std_logic;
68 ext_miso: in std_logic; --master in slave out
69 ext_mosi: in std_logic; --master out slave in
70 ext_sclk: in std_logic;
71 ext_scs0: in std_logic;
72 ext_scs1: in std_logic;
73 ext_scs2: in std_logic;
75 rs485_rxd: in std_logic;
76 rs485_txd: out std_logic;
77 rs485_dir: out std_logic;
82 dip_sw: in std_logic_vector (1 to 3); --na desce je prohozene cislovanni
83 -- Unused terminal to keep design tools silent
84 dummy_unused : out std_logic
89 architecture behavioral of rpi_mc_simple_dc is
90 attribute syn_noprune :boolean;
91 attribute syn_preserve :boolean;
92 attribute syn_keep :boolean;
93 attribute syn_hier :boolean;
95 -- component pll50to200
97 -- powerdown, clka: in std_logic;
98 -- lock, gla: out std_logic
103 port (A: in std_logic; Y: out std_logic);
106 signal pwm_in, pwm_dir_in: std_logic;
107 signal spi_clk: std_logic;
108 signal dat_reg : STD_LOGIC_VECTOR (7 downto 0):=(others=>'0'); --registr pro SPI
110 -- attribute syn_noprune of gpio2 : signal is true;
111 -- attribute syn_preserve of gpio2 : signal is true;
112 -- attribute syn_keep of gpio2 : signal is true;
113 -- attribute syn_hier of gpio2 : signal is true;
116 -- PLL as a reset generator
125 -- clka => pll_clkin,
126 -- gla => pll_clkout,
127 -- lock => pll_lock);
128 -- -- reset <= not pll_lock;
129 -- reset <= '0'; -- TODO: apply reset for good failsafe
133 dummy_unused <= gpio2 and gpio3 and
135 gpio12 and gpio13 and gpio14 and
136 gpio15 and gpio16 and gpio19 and
137 gpio20 and gpio21 and gpio26 and
138 stat(1) and stat(2) and stat(3) and
139 hal_in(1) and hal_in(2) and hal_in(3) and
140 irc_i and power_stat and
141 adc_miso and adc_mosi and adc_sclk and adc_scs and
143 can_rx and can_tx and
144 dip_sw(1) and dip_sw(2) and dip_sw(3) and
146 -- gpio17 and gpio18 and gpio27 and gpio22 and
147 gpio8 and gpio11 and gpio7 and gpio10 and
148 ext_scs1 and ext_scs2 and ext_miso and ext_mosi and ext_sclk and ext_scs0;
154 --gpio24 <= dip_sw(1); --na desce je prohozene cislovani
166 process (spi_clk) --nufunguje preo piny 11,17,27 funguje pro 4,18,22,ext_sclk,10
168 --if (gpio11'event and gpio11 = '1') then -- rising edge of SCK
169 if (rising_edge(spi_clk)) then
170 if (gpio7 = '0') then -- SPI CS must be selected
171 -- shift serial data into dat_reg on each rising edge
173 dat_reg(7 downto 0) <= dat_reg(6 downto 0) & gpio10;
176 gpio17 <= dat_reg(6);
177 gpio18 <= dat_reg(5);
178 gpio27 <= dat_reg(4);
179 gpio22 <= dat_reg(3);
180 gpio23 <= dat_reg(2);
181 gpio24 <= dat_reg(1);
182 gpio25 <= dat_reg(0);
185 elsif (falling_edge(spi_clk)) then
186 if (gpio7 = '0') then
187 gpio9 <= dat_reg(7); --zapisujeme nejdriv MSB