?? 嵌入式---程序示例1.htm
字號:
i;<BR> unsigned rev_type = 0;<BR><BR>
irq2dev_map[0] = dev;<BR><BR> /* set up the chip select
*/<BR> <BR><BR>
//下面這一段該怎么理解?看不懂阿<BR>
<BR>////++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++<BR>//這里是對CPU進(jìn)行操作,對cs89進(jìn)行初始化,我沒有見到你的硬件原理圖,我只能按CPU<BR>//的結(jié)構(gòu)定義來解釋一下,你要想搞清楚,只有看硬件原理圖,還要參考CPU的硬件手冊<BR>////++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
<BR> <BR>
<BR><BR>//連通PORT F I/O功能管腳1,SEL1(-IRQ5/PF1),<BR> *(volatile
unsigned char *)0xfffff42b |= 0x02; /* output /sleep */<BR>//設(shè)置PORT F
管腳0為輸出,輸出高電平<BR> *(volatile unsigned short *)0xfffff428 |=
0x0101; /* not sleeping */<BR><BR>//連通PORT F
中斷功能管腳1,SEL1(-IRQ5/PF1)<BR> *(volatile unsigned char
*)0xfffff42b &= ~0x02; /* input irq5 */<BR>//PORT F 管腳1,SEL1(-IRQ5/PF1)
為輸入方式,置低電平有效 <BR> *(volatile unsigned
short *)0xfffff428 &= ~0x0202; /* irq5 fcn on */<BR>
<BR>//在寄存器CSGBB中定義片選及cs89的基地址為:0x10000000.++++非常重要+++++++
<BR> *(volatile unsigned short *)0xfffff102 = 0x8000; /*
0x04000000
*/<BR>//在寄存器CSB中,片選使能,cs89地址空間大小(1M),數(shù)據(jù)線寬16位,6個等待周期,FLASH...,<BR>//非保護(hù)存儲空間(128K)......
<BR> *(volatile unsigned short *)0xfffff112 = 0x01e7; /*
128k, 2ws, FLASH, en */<BR> <BR>//對PORT
G操作........ <BR> *(volatile unsigned int
*)0xfffff430 = 0x023c3d0a;<BR>
<BR>////++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++<BR>//這是I/O模式的主要的兩個PORT口,一個是地址口,一個是數(shù)據(jù)口,這里對0x22操作,<BR>//中斷IRQ0<BR>///+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
<BR> *(volatile unsigned
short*)0x1000030a=0x2200;<BR> *(volatile unsigned
short*)0x1000030c=0;<BR> <BR><BR>
//*(volatile unsigned short *)0xfffff302 |= 0x0080;<BR>
<BR> ......................</P>
<P> .....................</P>
<P>void<BR>reset_chip(struct device *dev)<BR>{<BR> int
reset_start_time;<BR> writereg(dev, PP_SelfCTL, readreg(dev,
PP_SelfCTL) | POWER_ON_RESET);<BR><BR> /* wait 30 ms
*/<BR> current->state =
TASK_INTERRUPTIBLE;<BR> current->timeout = jiffies +
3;<BR> schedule();<BR><BR> /* Wait until
the chip is reset */<BR> <BR>
//這里jiffies說是timestamp,時間標(biāo)記,這個變量和current<BR>
//都在哪里定義?<BR>
//jiffies主要起什么作用?<BR>////+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++<BR>//這里是個延時等待,reset以后必須有等待,以便reset徹底完成,在reset過程中所有寄存器是關(guān)閉的<BR>//不但對cs89,對其他芯片也是一樣的<BR>///++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
reset_start_time = jiffies;<BR> while( (readreg(dev,
PP_SelfST) & INIT_DONE) == 0 && jiffies - reset_start_time<
2);<BR>}</P>
<P>static int<BR>net_open(struct device *dev)<BR>{<BR>
struct net_local *lp = (struct net_local *)dev->priv;<BR>
int result = 0;<BR> int i;<BR><BR>
write_irq(dev, lp->chip_type, 0);<BR><BR> irq2dev_map[/*
FIXME */ 0] = dev;<BR> writereg(dev, PP_BusCTL, 0); /* ints
off!
*/<BR><BR>//這里和上面那個一樣,怎么看懂?<BR>////++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++<BR>//這里也是CPU對CS89操作,我也根據(jù)CPU硬件手冊給你大概說一下
<BR>///+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++<BR><BR>//中斷信號,正電平觸發(fā)(POL5)<BR>
*(volatile unsigned short *)0xfffff302 |= 0x0080; /* +ve pol irq
*/<BR><BR>//調(diào)整PORT G的輸入輸出狀態(tài),及設(shè)置管腳相應(yīng)的電平信號
<BR> *(volatile unsigned int *)0xfffff430 =
0x023c3d0a; /* low -> high */<BR>
*(volatile unsigned int *)0xfffff430 = 0x023e3d0a;<BR>
*(volatile unsigned int *)0xfffff430 = 0x023c3d0a; /* high
-> low
*/<BR><BR>////++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++<BR>//這是I/O模式的主要的兩個PORT口,一個是地址口,一個是數(shù)據(jù)口,這里對0x22操作,<BR>//中斷IRQ0<BR>///+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
<BR> *(volatile unsigned short
*)0x1000030a = 0x2200; /* index window, REG index : 0022h
*/<BR> *(volatile unsigned short *)0x1000030c =
0x0000; /* data window, REG data : 0000h,irq0
*/<BR> <BR>.........................</P>
<P>.........................</P>
<P>static void<BR>net_rx(struct device *dev)<BR>{<BR> struct
net_local *lp = (struct net_local *)dev->priv;<BR> int
ioaddr = dev->base_addr;<BR> struct sk_buff
*skb;<BR> int status,
length;<BR><BR>//下面兩行怎么右邊是一樣的?<BR>//是作者寫錯了嗎?<BR>////++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++|<BR>//不是,這是一個包中前后不同的兩個數(shù)據(jù),前一個數(shù)據(jù)是該數(shù)據(jù)包的狀態(tài),后一個是數(shù)據(jù)包的長度<BR>////++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++<BR>
status = inw(ioaddr + RX_FRAME_PORT);<BR> length =
inw(ioaddr + RX_FRAME_PORT);<BR> if ((status & RX_OK) ==
0) {<BR>
lp->stats.rx_errors++;<BR> if
(status & RX_RUNT)
lp->stats.rx_length_errors++;<BR>
if (status & RX_EXTRA_DATA)
lp->stats.rx_length_errors++;<BR>
if (status & RX_CRC_ERROR) if (!(status &
(RX_EXTRA_DATA|RX_RUNT)))<BR>
/* per str 172
*/<BR>
lp->stats.rx_crc_errors++;<BR> if
(status & RX_DRIBBLE)
lp->stats.rx_frame_errors++;<BR>
return;<BR> }</P>
<BLOCKQUOTE>
<BLOCKQUOTE>
<P>......................</P></BLOCKQUOTE></BLOCKQUOTE>
<P>static int<BR>set_mac_address(struct device *dev, void
*addr)<BR>{<BR> int i;<BR> if
(dev->start)<BR> return
-EBUSY;<BR> <BR>
if(get_arena_addr())<BR>
{<BR>
memcpy(dev->dev_addr,0x1100000,6);<BR>
}<BR> else<BR> {<BR>
//這里的00hhcnl和前面<BR>//出現(xiàn)的00hhcn是什么意思?<BR>////+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++<BR>//注意:在這里他更改了網(wǎng)卡的MAC值,隨便給了一個值"0x00,0x00,'h',h','c','n'",<BR>//不過這個48位值必須是世界唯一的,或者用網(wǎng)卡自帶的也可以.我不能確定是否eeprom中有信息,<BR>//你可以用示波器量一下EEDI管腳,若為高電平,則EEPROM用到了,否則,他們根本沒有用EEPROM.<BR>///++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
<BR> unsigned char
mac[]={0,0,'h','h','c','n'};<BR>
memcpy(dev->dev_addr,mac,6);<BR> }<BR>
printk("%s: Setting MAC address to ", dev->name);<BR> for
(i = 0; i < 6; i++)<BR> printk("
%2.2x", dev->dev_addr[i] = ((unsigned char
*)addr)[i]);<BR> printk(".\n");<BR> /* set
the Ethernet address */<BR> for (i=0; i < ETH_ALEN/2;
i++)<BR> writereg(dev, PP_IA+i*2,
dev->dev_addr[i*2] | (dev->dev_addr[i*2+1] <<
8));<BR><BR> return 0;<BR>}</P></BLOCKQUOTE>
<BLOCKQUOTE>
<BLOCKQUOTE>
<P> </P>
<P align=center><A
href="http://drew.nease.net/mypage/sourcecode.htm#returntop"><B>返回頁首</B></A></P>
<P align=center> </P></BLOCKQUOTE></BLOCKQUOTE>
<P><BIG><A name=LCD></A></BIG><FONT color=black size=5><B>LCD
與觸摸屏</B></FONT></P>
<P align=center><A
href="http://drew.nease.net/mypage/sourcecode.htm#returntop"><B>返回頁首</B></A></P>
<P> </P>
<P><A name=MODEM></A><FONT color=black size=5><B>Modem撥號</B></FONT></P>
<BLOCKQUOTE>
<P><STRONG>Modem</STRONG>撥號程序步驟如下 </P>
<BLOCKQUOTE>
<P><BR>1. off hook,發(fā)出摘機(jī)命令(ATH1\r),
<BR> 等待modem返回狀態(tài),如果是"OK",則表示成功.進(jìn)行第二步.
<BR>2. on hook 發(fā)出掛機(jī)命令(ATH\r),
<BR> 等待modem返回狀態(tài),如果是"OK",則表示成功.進(jìn)行第三步.
<BR>3. off hook,dialing,摘機(jī)撥號(ATDT....\r),
<BR> 等待modem返回狀態(tài),如果是"CONNECT",則表示成功.進(jìn)行第四步.
<BR>4. send data,發(fā)送數(shù)據(jù). <BR><BR>最好按上述步驟一步一步調(diào),并要等待正確的返回值后再進(jìn)行下一步.
<BR><BR>具體程序例子如下,撥號: <BR><BR>// 清空接收FIFO
<BR> REG(FCR, nsChan) |=FCR_RXCLR;
<BR>// 等待,直到清空為止
<BR> while((REG(FCR, nsChan) & FCR_RXCLR) != 0x00);
<BR>// 撥號
<BR> while(atdt1[i]!=0) <BR> {
<BR>// 檢查發(fā)送FIFO是否準(zhǔn)備好,為空 <BR>
while((REG(LSR, nsChan) & LSR_THRE) == 0x00);
<BR>// 在發(fā)送FIFO中放入數(shù)據(jù) <BR>REG(THR, nsChan) = atdt1[i];
<BR>i++; <BR> } <BR>
<BR>// 等待是否有數(shù)據(jù)到達(dá),即modem返回數(shù)據(jù).
<BR>while((REG(LSR, nsChan) & LSR_DR) == 0x00);
<BR>// 接收數(shù)據(jù)并判斷返回值 <BR>response[i-19]=REG(RBR,nsChan);
<BR> if(response[0]!=0x43)
<BR> ..................
<BR> else
<BR> ..................
<BR>// 如果返回值是"connect",
<BR> while(*data!=0) <BR> {
<BR>
while((REG(LSR, nsChan) & LSR_THRE) == 0x00);
<BR>REG(THR, nsChan) = *data++; <BR> }
<BR>其他步驟基本一樣. </P></BLOCKQUOTE>
<P><BR> 這是在ARM7上做的modem驅(qū)動,硬件設(shè)計方法是modem集成在主板上,沒有用串口,modem是用片選地址直接對硬件操作的.</P>
<BLOCKQUOTE>
<P> </P></BLOCKQUOTE>
<P align=center><A
href="http://drew.nease.net/mypage/sourcecode.htm#returntop"><B>返回頁首</B></A></P></BLOCKQUOTE>
<P> </P>
<P><A name=RTC></A><BIG><BIG><STRONG>RTC</STRONG></BIG></BIG></P>
<P align=center><A
href="http://drew.nease.net/mypage/sourcecode.htm#returntop"><B>返回頁首</B></A></P></BODY></HTML>
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -