From: Vladimir Burian Date: Mon, 10 Jan 2011 14:21:22 +0000 (+0100) Subject: Added custom openMSP430 peripheral as an interface to the quadcount module. X-Git-Url: http://rtime.felk.cvut.cz/gitweb/fpga/virtex2/uart.git/commitdiff_plain/f788a91fb82826165450d890a448271d1fdf7577 Added custom openMSP430 peripheral as an interface to the quadcount module. Quadcount modul is currently not present, instead constant vector is supplied. Loading of 32-bit value works and a small sample code is added. --- diff --git a/omsp_quadcount.vhd b/omsp_quadcount.vhd new file mode 100644 index 0000000..e334f41 --- /dev/null +++ b/omsp_quadcount.vhd @@ -0,0 +1,73 @@ +library IEEE; +use IEEE.STD_LOGIC_1164.ALL; +use IEEE.STD_LOGIC_ARITH.ALL; +use IEEE.STD_LOGIC_UNSIGNED.ALL; + +entity omsp_quadcount is + port ( + mclk : in std_logic; + per_addr : in std_logic_vector (7 downto 0); + per_din : in std_logic_vector (15 downto 0); -- unused + per_en : in std_logic; + per_wen : in std_logic_vector (1 downto 0); -- unused + puc : in std_logic; -- unused + per_irq_acc : in std_logic; -- unused + per_irq : out std_logic; -- unused + per_dout : out std_logic_vector (15 downto 0); + + qcount : in std_logic_vector (31 downto 0) + ); +end omsp_quadcount; + +-------------------------------------------------------------------------------- + +architecture behavioral of omsp_quadcount is + + -- When reading whole 32-bit qcount input, first QCNTL has to be loaded, because + -- this event causes QCNTH to latch appropriate value of qcount. This procedure + -- ensures that correct value is readed. + constant QCNTL : std_logic_vector (15 downto 0) := X"0150"; -- qcount lower word logic address + constant QCNTH : std_logic_vector (15 downto 0) := X"0152"; -- qcount higher word logic address + + signal qcntl_sel : boolean; + signal qcnth_sel : boolean; + + signal qcnth_latch : std_logic_vector (15 downto 0) := (others => '0'); + + signal qcount_prev : std_logic_vector (31 downto 0) := (others => '0'); + +-------------------------------------------------------------------------------- + +begin + + qcntl_sel <= (per_addr = QCNTL(8 downto 1)) and (per_en = '1'); + qcnth_sel <= (per_addr = QCNTH(8 downto 1)) and (per_en = '1'); + + per_dout <= qcount (15 downto 0) when qcntl_sel else + qcnth_latch when qcnth_sel else + (others => '0'); + + + process (mclk) + begin + if (rising_edge(mclk) and qcntl_sel) then + qcnth_latch <= qcount (31 downto 16); + end if; + end process; + + -- Generation of IRQ signal. (changes in lower 2 bits are suppresed) + process (mclk) + begin + if (rising_edge(mclk)) then + qcount_prev <= qcount; + + if (qcntl_sel) then + per_irq <= '0'; + elsif (qcount_prev (31 downto 2) /= qcount (31 downto 2)) then + per_irq <= '1'; + end if; + end if; + end process; + +end behavioral; + diff --git a/openMSP430_uart.prj b/openMSP430_uart.prj index d17fdd7..8da5970 100644 --- a/openMSP430_uart.prj +++ b/openMSP430_uart.prj @@ -19,6 +19,8 @@ verilog work openMSP430_defines.v verilog work openmsp430/periph/omsp_gpio.v verilog work openmsp430/periph/omsp_timerA.v +vhdl work omsp_quadcount.vhd + vhdl work coregen/ram_8x512.vhd vhdl work coregen/rom_8x2k.vhd diff --git a/openMSP430_uart.vhd b/openMSP430_uart.vhd index b6e3ece..cbcd0ef 100644 --- a/openMSP430_uart.vhd +++ b/openMSP430_uart.vhd @@ -152,6 +152,22 @@ architecture rtl of openMSP430_uart is ); end component; + component omsp_quadcount is + port ( + mclk : in std_logic; + per_addr : in std_logic_vector (7 downto 0); + per_din : in std_logic_vector (15 downto 0); -- unused + per_en : in std_logic; + per_wen : in std_logic_vector (1 downto 0); -- unused + puc : in std_logic; -- unused + per_irq_acc : in std_logic; -- unused + per_irq : out std_logic; -- unused + per_dout : out std_logic_vector (15 downto 0); + + qcount : in std_logic_vector (31 downto 0) + ); + end component; + signal mclk : std_logic; signal puc : std_logic; @@ -180,6 +196,7 @@ architecture rtl of openMSP430_uart is signal gpio_per_dout : std_logic_vector (15 downto 0); signal timerA_per_dout : std_logic_vector (15 downto 0); + signal omsp_quadcount_dout : std_logic_vector (15 downto 0); signal irq_ta0 : std_logic; signal irq_ta1 : std_logic; @@ -334,9 +351,23 @@ begin taclk => '0' ); + omsp_quadcount_0 : omsp_quadcount port map ( + mclk => mclk, + per_addr => per_addr, + per_din => (others => '0'), + per_en => per_en, + per_wen => "00", + puc => '0', + per_irq_acc => '0', + per_irq => open, + per_dout => omsp_quadcount_dout, + + qcount => X"0001E240" -- 123456 + ); + -------------------------------------------------------------------------------- - per_dout <= gpio_per_dout or timerA_per_dout; + per_dout <= gpio_per_dout or timerA_per_dout or omsp_quadcount_dout; irq <= (9 => irq_ta0, 8 => irq_ta1, diff --git a/software/hardware.h b/software/hardware.h index 7e4d846..d713104 100644 --- a/software/hardware.h +++ b/software/hardware.h @@ -9,6 +9,13 @@ #include +//QuadCounter registers +#define QCNTL_ 0x0150 +sfrw(QCNTL,QCNTL_); +#define QCNTH_ 0x0152 +sfrw(QCNTH,QCNTH_); + + //PINS //PORT1 #define TX BIT1 diff --git a/software/main.c b/software/main.c index 7655138..15b2a05 100644 --- a/software/main.c +++ b/software/main.c @@ -1,7 +1,9 @@ /* see README.txt for details. -chris +original by: chris + +modified by: Vladimir Burian */ #include "hardware.h" #include @@ -9,6 +11,18 @@ chris #include "swuart.h" #include "fll.h" +/** +QuadCounter value +*/ +inline uint32_t qcount() { + uint32_t result = 0; + + result |= QCNTL; + result |= ((uint32_t)QCNTH << 16); + + return result; +} + /** Delay function. */ @@ -61,6 +75,8 @@ int main(void) { printf("\r\n====== openMSP430 in action ======\r\n"); //say hello printf("\r\nSimple Line Editor Ready\r\n"); //say hello + printf("\n[QCount = 0x%08lX]\n", qcount()); + while (1) { //main loop, never ends... printf("> "); //show prompt reading = 1;