]> rtime.felk.cvut.cz Git - fpga/virtex2/uart.git/commitdiff
Added custom openMSP430 peripheral as an interface to the quadcount module.
authorVladimir Burian <buriavl2@fel.cvut.cz>
Mon, 10 Jan 2011 14:21:22 +0000 (15:21 +0100)
committerVladimir Burian <buriavl2@fel.cvut.cz>
Mon, 10 Jan 2011 20:11:10 +0000 (21:11 +0100)
Quadcount modul is currently not present, instead constant vector is supplied. Loading of 32-bit value works and a small sample code is added.

omsp_quadcount.vhd [new file with mode: 0644]
openMSP430_uart.prj
openMSP430_uart.vhd
software/hardware.h
software/main.c

diff --git a/omsp_quadcount.vhd b/omsp_quadcount.vhd
new file mode 100644 (file)
index 0000000..e334f41
--- /dev/null
@@ -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;
+
index d17fdd7bf7289e464a038b1a65ae7b7c1676b440..8da597078b672028f3fa9a65b07b5f9895c7758f 100644 (file)
@@ -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
 
index b6e3eceae7e709a5640399e47d2976b297d2245e..cbcd0ef237ccd422b141c780fd23f8a9cd9dea9b 100644 (file)
@@ -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,
index 7e4d846071282996632610c748dfa6336cddac05..d7131041c5c0f2b5bf0463ec800aa05d7852c6fe 100644 (file)
@@ -9,6 +9,13 @@
 #include <iomacros.h>
 
 
+//QuadCounter registers
+#define QCNTL_             0x0150
+sfrw(QCNTL,QCNTL_);
+#define QCNTH_             0x0152
+sfrw(QCNTH,QCNTH_);
+
+
 //PINS
 //PORT1
 #define TX              BIT1
index 7655138af9d10e053c2576355ad9b57cb3f51976..15b2a056c19c4b4ec8f849089e3e41d24537f64c 100644 (file)
@@ -1,7 +1,9 @@
 /*
 see README.txt for details.
 
-chris <cliechti@gmx.net>
+original by: chris <cliechti@gmx.net>
+
+modified by: Vladimir Burian <buriavl2@fel.cvut.cz>
 */
 #include "hardware.h"
 #include <stdlib.h>
@@ -9,6 +11,18 @@ chris <cliechti@gmx.net>
 #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;