Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++

how to write the drivers

Altera_Forum
Honored Contributor II
1,251 Views

Hi: 

I design a IP core about AD16bit , which is used to transfer the analogy to the digital and whose "hdl file " is belown: 

 

library ieee; 

use ieee.std_logic_1164.all; 

 

entity ad16bit is 

 

port(D :IN STD_LOGIC_VECTOR(15 DOWNTO 0);  

address: in std_logic_vector(1 downto 0);  

CLK ,STATUS,read: IN STD_LOGIC; 

byteenable: in std_logic_vector(3 downto 0); 

chipselect: in std_logic; 

CE,CS,A0,RC,K12X8: OUT STD_LOGIC;  

Q : out STD_LOGIC_VECTOR(31 DOWNTO 0)); 

end ad16bit; 

 

architecture behav of ad16bit is 

type state is (st0, st1, st2, st3,st4); 

signal current_state,next_state :state:=st0; 

signal data_reg_select: std_logic; 

signal control_reg_select: std_logic; 

SIGNAL data_reg : STD_LOGIC_VECTOR(31 DOWNTO 0); 

SIGNAL lock: STD_LOGIC;  

begin 

K12X8 <= &#39;1&#39;;  

process(address)  

begin  

data_reg_select<=&#39;0&#39;; 

control_reg_select<=&#39;0&#39;; 

case address is  

when "00" => data_reg_select<=&#39;1&#39;; 

when "01" => control_reg_select<=&#39;1&#39;; 

when others => null; 

end case; 

end process;  

 

process(current_state,status)  

begin 

case current_state is 

when st0 =>CE<=&#39;0&#39;;CS<=&#39;1&#39;; A0<=&#39;1&#39;;RC<=&#39;1&#39;;LOCK<=&#39;0&#39;;next_state <= st1; 

when st1 =>CE<=&#39;1&#39;;CS<=&#39;0&#39;; A0<=&#39;0&#39;;RC<=&#39;0&#39;;LOCK<=&#39;0&#39;; next_state <= st2; 

when st2 =>CE<=&#39;1&#39;;CS<=&#39;0&#39;; A0<=&#39;0&#39;;RC<=&#39;0&#39;;LOCK<=&#39;0&#39;;  

IF (STATUS=&#39;1&#39;) THEN next_state <= st2;  

ELSE next_state <= st3;  

END IF ; 

when st3 =>CE<=&#39;1&#39;;CS<=&#39;0&#39;; A0<=&#39;0&#39;;RC<=&#39;1&#39;;LOCK<=&#39;0&#39;; next_state <= st4; 

when st4 =>CE<=&#39;1&#39;;CS<=&#39;0&#39;; A0<=&#39;0&#39;;RC<=&#39;1&#39;;LOCK<=&#39;1&#39;; next_state <= st0; 

when others =>CE<=&#39;0&#39;;CS<=&#39;1&#39;; A0<=&#39;1&#39;;RC<=&#39;1&#39;;LOCK<=&#39;0&#39;;next_state <= st0; 

end case; 

end process; 

 

PROCESS (clk,control_reg_select,chipselect)  

BEGIN 

IF ( clk&#39;EVENT AND clk=&#39;1&#39;) THEN 

if (control_reg_select and chipselect)=&#39;1&#39; then 

current_state <= next_state;  

end if; 

END IF; 

END PROCESS ;  

 

process(lock,byteenable)  

BEGIN 

IF LOCK=&#39;1&#39; AND LOCK&#39;EVENT THEN  

if byteenable(0)=&#39;1&#39; then data_reg(7 downto 0)<=d(7 downto 0);end if; 

if byteenable(1)=&#39;1&#39; then data_reg(15 downto 8)<=d(15 downto 8);end if; 

if byteenable(2)=&#39;1&#39; then data_reg(23 downto 16)<="00000000";end if; 

if byteenable(3)=&#39;1&#39; then data_reg(31 downto 24)<="00000000";end if; 

END IF; 

END PROCESS ; 

 

process(read,clk,data_reg_select)  

begin 

if clk&#39;event and clk=&#39;1&#39; then 

if (read and data_reg_select)=&#39;1&#39; then  

Q <= data_reg;  

else 

Q<=(others=>&#39;Z&#39;); 

end if; 

end if ; 

end process; 

 

END behav; 

 

 

the IP core has connected to the avalon ,but I didn&#39;t design the drivers about the IP core ,and the nios--system&#39;s generation is successful. Now I want to use the niosII to control the ad16bit , like a mcu--At89c52 controling a AD0809, how to work and how to design the drivers about the IP core ad16bit?!! 

thanks advance.
0 Kudos
3 Replies
Altera_Forum
Honored Contributor II
584 Views

How to write device drivers is a big topic. The best place to start for eCos (in fact the best place to start for writing any code for eCos) is the eCos reference manual that is supplied with the eCos installer. Information on how device drivers are used and how to write them can be found in the section "I/O Package (Device Drivers)", in particular the section "How to write a Driver" would be a good starting point. 

 

In your case, a simple character mode device driver may be apropriate. If so, then all you need to do is use the CHAR_DEVIO_TABLE and CHAR_DEVTAB_ENTRY macros (and supply the required functions) to create your device. For example: 

 

CHAR_DEVIO_TABLE(my_adc_handlers,                 NULL,                                                 my_adc_read,                 NULL,                                   NULL,                             NULL);                                                          CHAR_DEVTAB_ENTRY(my_adc_device,                        "/dev/adc",                              NULL,                                    &my_adc_handlers,                        my_adc_init,                              my_adc_lookup,                          NULL);     

 

If you search through the eCos source, you&#39;ll find a number of mouse/touchscreen drivers that use the character device model. These may serve as useful examples. 

 

Of course, this is probably overkill. You may find it more apropriate to simply write a function as a part of your application that reads from your device directly.
0 Kudos
Altera_Forum
Honored Contributor II
584 Views

Hi monkeyboy: 

I don&#39;t see straight the examples you offered , can you give me the appropriate format of the examples. 

and now I found a new problem about the ad16bit core, that is: 

if I change the width of "Port Q " from 16 to 32 , then when I build the soft project , the builing is failed because the size of the ad16bit is too large. and I found that when I fix  

"Q : out STD_LOGIC_VECTOR(15 DOWNTO 0));" the size of the ad16bit range from 0x0xxxxx0 to 0xxxxx7 ,but when I fix "Q : out STD_LOGIC_VECTOR(31 DOWNTO 0)); " and the size of the ad16bit range from 0x0xxxxx0 to 0xxxxxF , what&#39;s wrong with the problem and how can I slove it ?!!
0 Kudos
Altera_Forum
Honored Contributor II
584 Views

The document that was being referred to can be found at D:\altera\kits\nios2\components\ecos\ecos-current\doc\html\ref\ecos-ref.html, assuming of course that you have installed to d:\.

0 Kudos
Reply