##// END OF EJS Templates
Update and debug UART
martin -
r99:fb73d940a921 martin
parent child
Show More
@@ -0,0 +1,41
1 /*------------------------------------------------------------------------------
2 -- This file is a part of the LPP VHDL IP LIBRARY
3 -- Copyright (C) 2009 - 2010, Laboratory of Plasmas Physic - CNRS
4 --
5 -- This program is free software; you can redistribute it and/or modify
6 -- it under the terms of the GNU General Public License as published by
7 -- the Free Software Foundation; either version 3 of the License, or
8 -- (at your option) any later version.
9 --
10 -- This program is distributed in the hope that it will be useful,
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 -- GNU General Public License for more details.
14 --
15 -- You should have received a copy of the GNU General Public License
16 -- along with this program; if not, write to the Free Software
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 -------------------------------------------------------------------------------
19 -- Author : Martin Morlot
20 -- Mail : martin.morlot@lpp.polytechnique.fr
21 -----------------------------------------------------------------------------*/
22 #ifndef ADC_DRIVER_H
23 #define ADC_DRIVER_H
24
25 #include "apb_fifo_Driver.h"
26 #include "apb_uart_Driver.h"
27 #include "apb_gpio_Driver.h"
28
29 #define samplecnt 4096
30 #define Mask 0x0000FFFF
31
32 /*===================================================
33 F U N C T I O N S
34 ====================================================*/
35
36 void flushFIFO(FIFO_Device*,GPIO_Device*);
37 void getPacket(FIFO_Device*,unsigned short*,unsigned short*,unsigned short*,unsigned short*,unsigned short*,int);
38 void mkfakePacket(FIFO_Device*,unsigned short*,unsigned short*,unsigned short*,unsigned short*,unsigned short*,int);
39 void sendPacket(UART_Device*,unsigned short*,unsigned short*,unsigned short*,unsigned short*,unsigned short*,int);
40
41 #endif
@@ -0,0 +1,93
1 /*------------------------------------------------------------------------------
2 -- This file is a part of the LPP VHDL IP LIBRARY
3 -- Copyright (C) 2009 - 2010, Laboratory of Plasmas Physic - CNRS
4 --
5 -- This program is free software; you can redistribute it and/or modify
6 -- it under the terms of the GNU General Public License as published by
7 -- the Free Software Foundation; either version 3 of the License, or
8 -- (at your option) any later version.
9 --
10 -- This program is distributed in the hope that it will be useful,
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 -- GNU General Public License for more details.
14 --
15 -- You should have received a copy of the GNU General Public License
16 -- along with this program; if not, write to the Free Software
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 -------------------------------------------------------------------------------
19 -- Author : Martin Morlot
20 -- Mail : martin.morlot@lpp.polytechnique.fr
21 -----------------------------------------------------------------------------*/
22 #include "ADC_Driver.h"
23 #include <stdio.h>
24
25 unsigned char packetNumber = 0;
26
27 void flushFIFO(FIFO_Device*fifo,GPIO_Device* adcResetPin)
28 {
29 adcResetPin->Dout = 0x0;
30 int trash;
31 while((fifo->FIFOreg[(2*0)+FIFO_Ctrl] & FIFO_Empty) != FIFO_Empty){ // TANT QUE empty a 0 ALORS
32 trash = fifo->FIFOreg[(2*0)+FIFO_RWdata];
33 trash = fifo->FIFOreg[(2*1)+FIFO_RWdata];
34 trash = fifo->FIFOreg[(2*2)+FIFO_RWdata];
35 trash = fifo->FIFOreg[(2*3)+FIFO_RWdata];
36 trash = fifo->FIFOreg[(2*4)+FIFO_RWdata];
37 }
38
39 adcResetPin->Dout = 0x1;
40 }
41
42 void getPacket(FIFO_Device*fifo,unsigned short*CH1,unsigned short*CH2,unsigned short*CH3,unsigned short*CH4,unsigned short*CH5,int packetSize)
43 {
44 int i=0;
45 for(i=0;i<packetSize;i++)
46 {
47 while((fifo->FIFOreg[(2*0)+FIFO_Ctrl] & FIFO_Empty) == FIFO_Empty);
48 CH1[i] = (fifo->FIFOreg[(2*0)+FIFO_RWdata] & Mask);
49 CH2[i] = (fifo->FIFOreg[(2*1)+FIFO_RWdata] & Mask);
50 CH3[i] = (fifo->FIFOreg[(2*2)+FIFO_RWdata] & Mask);
51 CH4[i] = (fifo->FIFOreg[(2*3)+FIFO_RWdata] & Mask);
52 CH5[i] = (fifo->FIFOreg[(2*4)+FIFO_RWdata] & Mask);
53 }
54 }
55
56 void mkfakePacket(FIFO_Device*fifo,unsigned short*CH1,unsigned short*CH2,unsigned short*CH3,unsigned short*CH4,unsigned short*CH5,int packetSize)
57 {
58 int i=0;
59 for(i=0;i<packetSize;i++)
60 {
61 CH1[i] = (unsigned short)(i);
62 CH2[i] = (unsigned short)(i+10);
63 CH3[i] = (unsigned short)(i+20);
64 CH4[i] = (unsigned short)(i+30);
65 CH5[i] = (unsigned short)(i+40);
66 }
67 }
68
69
70 void sendPacket(UART_Device* uart0,unsigned short*CH1,unsigned short*CH2,unsigned short*CH3,unsigned short*CH4,unsigned short*CH5,int packetSize)
71 {
72 int i=0;
73
74 for(i=0;i<packetSize;i++)
75 {
76 uartputc(uart0,0xa5);
77 uartputc(uart0,0x0f);
78 uartputc(uart0,packetNumber++);
79 uartputc(uart0,(char)(CH1[i]>>8));
80 uartputc(uart0,(char)CH1[i]);
81 uartputc(uart0,(char)(CH2[i]>>8));
82 uartputc(uart0,(char)CH2[i]);
83 uartputc(uart0,(char)(CH3[i]>>8));
84 uartputc(uart0,(char)CH3[i]);
85 uartputc(uart0,(char)(CH4[i]>>8));
86 uartputc(uart0,(char)CH4[i]);
87 uartputc(uart0,(char)(CH5[i]>>8));
88 uartputc(uart0,(char)CH5[i]);
89 uartputc(uart0,0xf0);
90 uartputc(uart0,0x5a);
91 }
92
93 }
@@ -0,0 +1,41
1 /*------------------------------------------------------------------------------
2 -- This file is a part of the LPP VHDL IP LIBRARY
3 -- Copyright (C) 2009 - 2010, Laboratory of Plasmas Physic - CNRS
4 --
5 -- This program is free software; you can redistribute it and/or modify
6 -- it under the terms of the GNU General Public License as published by
7 -- the Free Software Foundation; either version 3 of the License, or
8 -- (at your option) any later version.
9 --
10 -- This program is distributed in the hope that it will be useful,
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 -- GNU General Public License for more details.
14 --
15 -- You should have received a copy of the GNU General Public License
16 -- along with this program; if not, write to the Free Software
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 -------------------------------------------------------------------------------
19 -- Author : Martin Morlot
20 -- Mail : martin.morlot@lpp.polytechnique.fr
21 -----------------------------------------------------------------------------*/
22 #ifndef ADC_DRIVER_H
23 #define ADC_DRIVER_H
24
25 #include "apb_fifo_Driver.h"
26 #include "apb_uart_Driver.h"
27 #include "apb_gpio_Driver.h"
28
29 #define samplecnt 4096
30 #define Mask 0x0000FFFF
31
32 /*===================================================
33 F U N C T I O N S
34 ====================================================*/
35
36 void flushFIFO(FIFO_Device*,GPIO_Device*);
37 void getPacket(FIFO_Device*,unsigned short*,unsigned short*,unsigned short*,unsigned short*,unsigned short*,int);
38 void mkfakePacket(FIFO_Device*,unsigned short*,unsigned short*,unsigned short*,unsigned short*,unsigned short*,int);
39 void sendPacket(UART_Device*,unsigned short*,unsigned short*,unsigned short*,unsigned short*,unsigned short*,int);
40
41 #endif
@@ -0,0 +1,25
1 #------------------------------------------------------------------------------
2 #-- This file is a part of the LPP VHDL IP LIBRARY
3 #-- Copyright (C) 2009 - 2010, Laboratory of Plasmas Physic - CNRS
4 #--
5 #-- This program is free software; you can redistribute it and/or modify
6 #-- it under the terms of the GNU General Public License as published by
7 #-- the Free Software Foundation; either version 3 of the License, or
8 #-- (at your option) any later version.
9 #--
10 #-- This program is distributed in the hope that it will be useful,
11 #-- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 #-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 #-- GNU General Public License for more details.
14 #--
15 #-- You should have received a copy of the GNU General Public License
16 #-- along with this program; if not, write to the Free Software
17 #-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 #------------------------------------------------------------------------------
19 FILE = adc_Driver
20 LIB = liblpp_adc_Driver.a
21
22 include ../../rules.mk
23
24 all: $(FILE).a
25 @echo $(FILE)".a created"
@@ -7,13 +7,8 int main()
7 {
7 {
8 printf("Debut Main\n\n");
8 printf("Debut Main\n\n");
9 UART_Device* dev = openUART(0);
9 UART_Device* dev = openUART(0);
10 printf("addr: %x\n",(unsigned int)dev);
10 while(1){
11 printf("cfg: %x\n",dev->ConfigReg);
11 uartputc(dev,uartgetc(dev));
12 char* a = "hello world\n";
12 }
13 uartputs(dev,a);
14 printf("Try #1 done\n");
15 uartputs(dev,"salut monde\n");
16 printf("Try #2 done\n");
17 return 0;
13 return 0;
18 }
14 }
19
@@ -30,6 +30,7 all:
30 make all -C FFT
30 make all -C FFT
31 make all -C DELAY
31 make all -C DELAY
32 make all -C GPIO
32 make all -C GPIO
33 make all -C ADC
33 make all -C MATRIX
34 make all -C MATRIX
34
35
35
36
@@ -42,5 +43,6 cleanall:
42 make clean -C FFT
43 make clean -C FFT
43 make clean -C DELAY
44 make clean -C DELAY
44 make clean -C GPIO
45 make clean -C GPIO
46 make clean -C ADC
45 make clean -C MATRIX
47 make clean -C MATRIX
46
48
@@ -38,7 +38,6 void uartputc(UART_Device* dev,char c)
38 //while (!(dev->ConfigReg & (1<<5)));
38 //while (!(dev->ConfigReg & (1<<5)));
39 while (!((dev->ConfigReg & DataSended) == DataSended));
39 while (!((dev->ConfigReg & DataSended) == DataSended));
40 dev->DataWReg = c;
40 dev->DataWReg = c;
41 printf(" ");
42 }
41 }
43
42
44 void uartputs(UART_Device* dev,char* s)
43 void uartputs(UART_Device* dev,char* s)
@@ -93,15 +93,9 Rec.UART_Cfg(2) <= NwData;
93 begin
93 begin
94 if(rst='0')then
94 if(rst='0')then
95 Rec.UART_Wdata <= (others => '0');
95 Rec.UART_Wdata <= (others => '0');
96
96 Send <= '0';
97
97
98 elsif(clk'event and clk='1')then
98 elsif(clk'event and clk='1')then
99 temp_ND <= NwData;
100 if(NwData='1' and temp_ND='1')then
101 ACK <= '1';
102 else
103 ACK <= '0';
104 end if;
105
99
106 --APB Write OP
100 --APB Write OP
107 if (apbi.psel(pindex) and apbi.penable and apbi.pwrite) = '1' then
101 if (apbi.psel(pindex) and apbi.penable and apbi.pwrite) = '1' then
@@ -109,13 +103,13 Rec.UART_Cfg(2) <= NwData;
109 when "000000" =>
103 when "000000" =>
110 Rec.UART_Cfg(0) <= apbi.pwdata(0);
104 Rec.UART_Cfg(0) <= apbi.pwdata(0);
111 when "000001" =>
105 when "000001" =>
112 Rec.UART_Wdata(7 downto 0) <= apbi.pwdata(7 downto 0);
106 Rec.UART_Wdata(7 downto 0) <= apbi.pwdata(7 downto 0);
113 Send <= '1';
107 Send <= '1';
114 when others =>
108 when others =>
115 null;
109 null;
116 end case;
110 end case;
117 else
111 elsif(Sended = '0')then
118 Send <= '0';
112 Send <= '0';
119 end if;
113 end if;
120
114
121 --APB READ OP
115 --APB READ OP
@@ -133,9 +127,12 Rec.UART_Cfg(2) <= NwData;
133 when "000010" =>
127 when "000010" =>
134 Rdata(31 downto 8) <= X"EEEEEE";
128 Rdata(31 downto 8) <= X"EEEEEE";
135 Rdata(7 downto 0) <= Rec.UART_Rdata;
129 Rdata(7 downto 0) <= Rec.UART_Rdata;
130 ACK <= '1';
136 when others =>
131 when others =>
137 Rdata <= (others => '0');
132 Rdata <= (others => '0');
138 end case;
133 end case;
134 else
135 ACK <= '0';
139 end if;
136 end if;
140
137
141 end if;
138 end if;
@@ -28,14 +28,12 use IEEE.std_logic_1164.all;
28 --! \Author Alexis Jeandet alexis.jeandet@lpp.polytechnique.fr
28 --! \Author Alexis Jeandet alexis.jeandet@lpp.polytechnique.fr
29 --! \todo move to general purpose library, explain more in detail the code and add some schematic in doc.
29 --! \todo move to general purpose library, explain more in detail the code and add some schematic in doc.
30
30
31 entity Shift_REG is
31 entity Shift_Reg is
32 generic(
32 generic(
33 Data_sz : integer := 10 --! Width of the shift register
33 Data_sz : integer := 10 --! Width of the shift register
34 );
34 );
35 port(
35 port(
36 clk : in std_logic; --! System clock
37 Sclk : in std_logic; --! Serial clock
36 Sclk : in std_logic; --! Serial clock
38 reset : in std_logic; --! System reset
39 SIN : in std_logic; --! Serial data in
37 SIN : in std_logic; --! Serial data in
40 SOUT : out std_logic; --! Serial data out
38 SOUT : out std_logic; --! Serial data out
41 Serialize : in std_logic; --! Launch serialization
39 Serialize : in std_logic; --! Launch serialization
@@ -46,72 +44,49 port(
46 end entity;
44 end entity;
47
45
48
46
49 architecture ar_Shift_REG of Shift_REG is
47 architecture ar_Shift_Reg of Shift_Reg is
50
48
51 signal REG : std_logic_vector(Data_sz-1 downto 0);
49 signal REG : std_logic_vector(Data_sz-1 downto 0);
52 signal Serialized_int : std_logic;
50 signal CptBits : std_logic_vector(Data_sz-1 downto 0) := (others => '0');
53 signal Serialize_reg : std_logic;
54 signal Serial_reg : std_logic;
55 signal CptBits : std_logic_vector(Data_sz-1 downto 0);
56 constant CptBits_trig : std_logic_vector(Data_sz-1 downto 0) := (others => '1');
51 constant CptBits_trig : std_logic_vector(Data_sz-1 downto 0) := (others => '1');
57 signal CptBits_flag : std_logic;
52 signal CptBits_flag : std_logic :='0';
58 signal CptBits_flag_reg : std_logic;
53 signal Serialized_int : std_logic :='1';
59
54
60 begin
55 begin
61
56
62 Serialized <= Serialized_int;
57 CptBits_flag <= '1' when CptBits=CptBits_trig else '0';
63 CptBits_flag <= '1' when CptBits = CptBits_trig else '0';
58 Serialized <= Serialized_int;
64
59 process(Serialize,Sclk,D)
65 process(reset,clk)
66 begin
60 begin
67 if reset = '0' then
61 if(Serialize = '1') then
68 Serialized_int <= '1';
62 REG <= D;
69 CptBits_flag_reg <= '0';
63 CptBits <= (others => '0');
70 Serial_reg <= '0';
64 Serialized_int <= '0';
71 Q <= (others => '0');
65 Q <= REG;
72 elsif clk'event and clk = '1' then
66 SOUT <= '1';
73 CptBits_flag_reg <= CptBits_flag;
67 elsif Sclk'event and Sclk = '1' then
74 Serial_reg <= Serialize;
68 if(Serialized_int='0') then
75
69 REG <= SIN & REG(Data_sz-1 downto 1);
76 if CptBits_flag = '1' and CptBits_flag_reg = '0' then
70 CptBits <= '1' & CptBits(Data_sz-1 downto 1);
77 Serialized_int <= '1';
71 SOUT <= REG(0);
78 Q <= REG;
72 if(CptBits_flag = '1') then
79 elsif(Serial_reg='0' and Serialize='1')then
73 Serialized_int <= '1';
80 Serialized_int <= '0';
74 Q <= REG;
75 end if;
76 else
77 SOUT <= '1';
78 Serialized_int <= '1';
79 -- Q <= REG;
81 end if;
80 end if;
82 end if;
81 end if;
83 end process;
82 end process;
84
83
84 end architecture;
85
85
86 process(reset,Sclk)
86
87 begin
87
88 if reset = '0' then
88
89 CptBits <= (others => '0');
90 REG <= (others => '0');
91 SOUT <= '1';
92 Serialize_reg <= '0';
93 elsif Sclk'event and Sclk = '1' then
94 Serialize_reg <= Serialized_int;
95 if (Serialized_int = '0' and Serialize_reg ='1') then
96 REG <= SIN & D(Data_sz-1 downto 1);
97 SOUT <= D(0);
98 elsif Serialized_int = '0' then
99 REG <= SIN & REG(Data_sz-1 downto 1);
100 SOUT <= REG(0);
101 else
102 SOUT <= '1';
103 end if;
104 if Serialized_int = '0' then
105 if CptBits_flag = '1' then
106 CptBits <= (others => '0');
107 else
108 CptBits <= '1' & CptBits(Data_sz-1 downto 1);
109 end if;
110 else
111 CptBits <= (others => '0');
112 end if;
113
114 end if;
115 end process;
116
89
117 end ar_Shift_REG;
90
91
92
@@ -51,56 +51,52 end entity;
51 architecture ar_UART of UART is
51 architecture ar_UART of UART is
52 signal Bclk : std_logic;
52 signal Bclk : std_logic;
53
53
54 signal RDATA_int : std_logic_vector(Data_sz+1 downto 0);
54 signal RDATA_int : std_logic_vector(Data_sz+1 downto 0);
55 signal WDATA_int : std_logic_vector(Data_sz+1 downto 0);
55 signal WDATA_int : std_logic_vector(Data_sz+1 downto 0);
56
56
57 signal TXD_Dummy : std_logic;
57 signal Take : std_logic;
58 signal NwDat_int : std_logic;
58 signal Taken : std_logic;
59 signal NwDat_int_reg : std_logic;
59 signal Taken_reg : std_logic;
60 signal receive : std_logic;
60
61 constant zeroVect : std_logic_vector(Data_sz+1 downto 0) := (others => '0');
61 constant Dummy : std_logic_vector(Data_sz+1 downto 0) := (others => '1');
62
62
63 begin
63 begin
64
64
65
65 NwDat <= '0' when (ack = '1') else '1' when (Taken_reg='0' and Taken='1');
66 WDATA_int <= '1' & WDATA & '0';
66
67
67 WDATA_int <= '1' & WDATA & '0';
68 BaudGenerator : BaudGen
68
69 BaudGenerator : entity work.BaudGen
70 port map(clk,reset,Capture,Bclk,RXD,BTrigger);
69 port map(clk,reset,Capture,Bclk,RXD,BTrigger);
71
70
72
71 RX_REG : Shift_Reg
73 RX_REG : entity work.Shift_REG
74 generic map(Data_sz+2)
72 generic map(Data_sz+2)
75 port map(clk,Bclk,reset,RXD,TXD_Dummy,receive,NwDat_int,zeroVect,RDATA_int);
73 port map(Bclk,RXD,open,Take,Taken,Dummy,RDATA_int);
76
74
77 TX_REG : entity work.Shift_REG
75 TX_REG : Shift_Reg
78 generic map(Data_sz+2)
76 generic map(Data_sz+2)
79 port map(clk,Bclk,reset,'1',TXD,Send,Sended,WDATA_int);
77 port map(Bclk,Dummy(0),TXD,Send,Sended,WDATA_int,open);
80
81
82
78
83 process(clk,reset)
79 process(clk,reset)
84 begin
80 begin
85 if reset = '0' then
81 if(reset ='0')then
86 NwDat <= '0';
82 Take <= '0';
87 elsif clk'event and clk = '1' then
83
88 NwDat_int_reg <= NwDat_int;
84 elsif(clk'event and clk ='1')then
89 if RXD = '1' and NwDat_int = '1' then
85 Taken_reg <= Taken;
90 receive <= '0';
86
91 elsif RXD = '0' then
87 if(RXD ='0' and Taken ='1')then
92 receive <= '1';
88 Take <= '1';
89 elsif(Taken ='0')then
90 Take <= '0';
93 end if;
91 end if;
94 if NwDat_int_reg = '0' and NwDat_int = '1' then
92
95 NwDat <= '1';
93 if (Taken_reg ='0' and Taken ='1') then
96 RDATA <= RDATA_int(8 downto 1);
94 RDATA <= RDATA_int(8 downto 1);
97 elsif ack = '1' then
98 NwDat <= '0';
99 end if;
95 end if;
96
100 end if;
97 end if;
101 end process;
98 end process;
102
99
103 end ar_UART;
100 end architecture;
104
101
105
102
106
@@ -41,25 +41,24 port(
41 Send : in std_logic; --! Flag, Demande d'envoi sur le bus
41 Send : in std_logic; --! Flag, Demande d'envoi sur le bus
42 Sended : out std_logic; --! Flag, Envoi termine
42 Sended : out std_logic; --! Flag, Envoi termine
43 BTrigger : out std_logic_vector(11 downto 0); --! Registre contenant la valeur du diviseur de frequence pour la transmission
43 BTrigger : out std_logic_vector(11 downto 0); --! Registre contenant la valeur du diviseur de frequence pour la transmission
44 RDATA : out std_logic_vector(Data_sz-1 downto 0); --! Mot de donnee en provenance de l'utilisateur
44 RDATA : out std_logic_vector(Data_sz-1 downto 0); --! Current read word
45 WDATA : in std_logic_vector(Data_sz-1 downto 0) --! Mot de donnee a transmettre a l'utilisateur
45 WDATA : in std_logic_vector(Data_sz-1 downto 0) --! Mot de donnee a transmettre a l'utilisateur
46 );
46 );
47 end component;
47 end component;
48
48
49
49
50 component Shift_REG is
50 component Shift_Reg is
51 generic(Data_sz : integer := 10);
51 generic(
52 Data_sz : integer := 10 --! Width of the shift register
53 );
52 port(
54 port(
53 clk : in std_logic;
55 Sclk : in std_logic; --! Serial clock
54 Sclk : in std_logic;
56 SIN : in std_logic; --! Serial data in
55 reset : in std_logic;
57 SOUT : out std_logic; --! Serial data out
56 SIN : in std_logic;
58 Serialize : in std_logic; --! Launch serialization
57 SOUT : out std_logic;
59 Serialized : out std_logic; --! Serialization complete
58 Serialize : in std_logic;
60 D : in std_logic_vector(Data_sz-1 downto 0); --! Parallel data to be shifted out
59 Serialized : out std_logic;
61 Q : out std_logic_vector(Data_sz-1 downto 0) --! Unserialized data
60 D : in std_logic_vector(Data_sz-1 downto 0);
61 Q : out std_logic_vector(Data_sz-1 downto 0)
62
63 );
62 );
64 end component;
63 end component;
65
64
General Comments 0
You need to be logged in to leave comments. Login now