|
|
我讲创龙在DSP中使用的例子移植到ARM中,如下是我的底层驱动程序: 3 ?) r9 n* U+ Q+ {& S! T, g4 z `
/*
% V) [/ v' Z! u8 k/ b * Copyright (C) 2009 Texas Instruments Inc4 c/ s. U2 H4 I* ]1 a1 F) q
*
* S8 A X! {$ Z, m2 S/ ~ * This program is free software; you can redistribute it and/or modify8 e5 {- O D( d' Z7 s4 M
* it under the terms of the GNU General Public License as published by4 n# E+ t( m$ r" G$ ^3 \6 J
* the Free Software Foundation; either version 2 of the License, or3 |. y9 b# Z& @6 F
* (at your option)any later version.
2 e6 `2 M; \+ ]1 J, c7 I) ~ *7 U( E7 X; [) A# ~4 i
* This program is distributed in the hope that it will be useful,
. k$ C+ h0 a& p" \0 [ ] * but WITHOUT ANY WARRANTY; without even the implied warranty of! H, b/ H0 f' X: M% E$ j- O0 `
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% j$ `) Q9 V$ p" j' Q * GNU General Public License for more details.
3 Q! l! n6 ~! x *; m$ \9 l; v7 p4 B: ~, L8 y
* You should have received a copy of the GNU General Public License7 j0 L. T Q, |7 i
* along with this program; if not, write to the Free Software" Q& A" [1 `$ L7 g; m8 m j3 d+ m
* Foundati" c: h' i3 I4 y( _# q# m- H
*/
2 V: H! }' s5 w5 z" K#include <linux/module.h>
9 e7 z4 F8 |5 Y! }* e' `# U. \1 F2 `#include <linux/init.h>
9 t5 g- m, \9 B#include <linux/errno.h>3 y4 E; N& p8 v2 y2 U
#include <linux/types.h>
! A6 S9 O! _! d o7 _% n3 t#include <linux/interrupt.h>' E) X, q+ f/ ^* I4 g
#include <linux/io.h>
) n( Q) L6 }4 S8 B% V4 v#include <linux/sysctl.h>
4 N6 @/ r$ z5 w5 E#include <linux/mm.h>
% [: z6 ~5 |0 ^* t; w+ y1 g#include <linux/delay.h>% Z2 ~! o& f9 }' b+ G
#include<linux/kernel.h>, s+ o( z# R+ K$ z: B$ P$ ?" D7 ~
#include<linux/fs.h>
# `* `3 z& F1 K( o#include<linux/ioctl.h>* ?+ q! s3 ?/ u# |
#include<linux/cdev.h>
+ \; i$ T$ o9 z2 f ^% J#include<linux/kdev_t.h>
! a5 s! O$ w+ y7 B$ W# _& {#include<linux/gpio.h>
) Z* |: z; a8 r7 L7 z0 z#include <mach/hardware.h>8 T8 {6 J4 p" O1 F: ]
#include <mach/irqs.h> ]: V5 [/ n7 s2 a; b$ B+ @
5 @) S2 f# R. M; a#include <asm/mach-types.h>
5 z8 O# {+ Q8 j0 }#include <asm/mach/arch.h>
* s; T( B% \+ M#include <mach/da8xx.h>- y1 c, p3 b0 o' i, J- ^
#define SYSCFG_BASE 0x01c14000
* f$ f- T7 H2 f9 e9 z6 C#define PINMUX1_OFFSET 0x124
$ E" i7 }! E. l& H- d. a0 z#define PINMUX18_OFFSET 0x168
% x; [- t& j' o g) {) \#define PINMUX19_OFFSET 0x16c
7 y, i$ Y, {" k! D; g. p! y7 O#define SPCR_ADDR 0x01D11008 //MCBSP1_SPCR; F$ s1 W& U; c2 V1 y. P! _
#define RCR_ADDR 0x01D1100C //MCBSP1_RCR2 A/ t8 Y/ y: K8 d
#define XCR_ADDR 0x01D11010 //MCBSP1_XCR
% E. w1 m# V/ v3 g3 K#define SRGR_ADDR 0x01D11014 //MCBSP1_SRGR5 e+ |6 z& Z8 \7 n: w
#define PCR_ADDR 0x01D11024 //MCBSP1_PCR$ q7 ^$ l+ C. f, P0 f& ~- }
. m' N5 [1 k2 s8 z: `
#define DXR_ADDR 0x01D11004 //MCBSP1_DXR
$ @/ t4 |; U' d0 C, ~% r#define DRR_ADDR 0x01D11000 //MCBSP1_DRR/ U' \$ E9 O6 l( ^' T0 l, z
//PSC
4 | n7 P" F: C- w& ]4 y8 M, i" w#define PTCMD_ADDR 0x01E27120 * a/ c2 s* x. @% N3 _3 ~' O
#define MDCTL15_ADDR 0x01E27A3C% I- R' K- @: S3 a
#define PDCTL1_ADDR 0x01E27304
% G' ]1 X, E/ n- J$ w; G" N% Q9 N//GPIO8 direction
7 q! d2 ]+ n A8 Y5 i7 g0 O- j; _#define GPIO8_DIRECT 0x01E260B0- C- y" T. @( @1 P' h
#define GPIO8_OUT 0x01E260B4
, x2 H9 c/ X/ f4 @ D4 `#define GPIO8_IN 0x01E260C0
- q- m- A5 x$ s- T% r ?* j
K* q7 V8 F& f3 R8 S) b! q1 {% E//#define MCBSP1_RINT 99
4 u9 r( ^ X$ [9 [//#define MCBSP1_XINT 100 ' h: q- I4 A+ n ]2 X* }
static int MCBSP_MAJOR=239;4 x3 @, q% x' J- [ G
static int MCBSP_MINOR=0;: J/ O: M/ w. r& p! k& G* a0 ~8 j
static int count =1;
5 I2 y+ N, f1 V& k2 K! b$ j' X: _
5 H) D( S4 J# T, d1 ~9 z# I! c$ R1 w/ Z) u#define MCBSP_NAME "MCBSP-device"/ s; ~" i% {' B8 [ x( C, Z
7 y& Z* c: q( M7 e
static struct cdev *mcbsp_cdev;
' k, ` ?3 j" ? t& gstatic struct class *mcbsp_class;9 @7 X! m+ [; B* ^! m
static dev_t mcbsp_dev;
5 O- J A! S8 t9 Uunsigned int DRR_data;% Q: z( O& T( y2 \9 v2 a
unsigned int DXR_data; ~/ q& y: O. ~- `$ s: f/ m" D$ |
static int mcbsp_open(struct inode *inode,struct file *file)+ _$ q1 g9 E2 E* ]' s8 Q
{! e: Y" k# g$ F* |+ v
2 Q1 h0 x4 M1 c- a //interrupt enable,initialized" n' i5 X6 o6 _! E& x! B9 N/ {
unsigned int temp;
& U3 e) @0 V) U, F2 \4 u //SLEEP_EN(GPIO8[10])---0" `* o" _5 ~/ ?; T6 S5 r; Z/ u6 b
temp = __raw_readl(IO_ADDRESS(GPIO8_OUT));0 o4 F4 J- X, G* B
temp=temp&(~0x00000400);- Z+ r8 B9 Q- r' k3 M, _" P, K; A
__raw_writel(temp,IO_ADDRESS(GPIO8_OUT));//GPIO8[10]
3 }# g) o* b" [5 F h* `$ O" _3 c+ Y7 b4 M //RESETn(GPIO8[8])----0----1% l! P- V4 ~6 r+ S6 u* w5 W+ \
temp = __raw_readl(IO_ADDRESS(GPIO8_OUT));
/ a3 ~1 {/ O, o1 f' g0 d N temp=temp&(~0x00000100);
- x+ z& p0 M) f7 l. ^ __raw_writel(temp,IO_ADDRESS(GPIO8_OUT));//GPIO8[8]---02 [2 ^+ W' [7 v6 ]6 W
udelay(100);' {; ^) k% ~* b& T( k
temp=temp| 0x00000100;- Y# H$ {' Z' B* \0 o1 I1 g
__raw_writel(temp,IO_ADDRESS(GPIO8_OUT));//GPIO8[8]---1
+ b% J* Q2 T5 `) { udelay(100);
! x! p% n* u! B; P' a8 t8 p8 M$ p printk("open success!\n");9 C( G& X) s6 |: A. f
return 0;$ R" t `1 k5 h: Z
}
; k9 `0 n% @1 ^6 c6 B
# s1 [/ P+ ?6 @$ \static int mcbsp_release(struct inode *inode,struct file *file)2 K& Y# v G% ^; O2 C. `
{" ?% i# V# |. D- D
printk("release success!\n");
. Q; i" P8 @8 L U( S% X( E) `; m return 0;
$ @: h6 Z8 F9 B) _/ B. j O1 }}
0 m5 e* S' v6 D* u4 e. x5 G
# e. e9 V8 J# O. U9 {0 ystatic ssize_t mcbsp_write(struct file *filp,const char *buf,size_t len,loff_t *off)! W+ O. c8 l5 J# s
{
% W' S- e( @# r- i+ R copy_from_user(&DXR_data,buf,len);" N1 Z) R( }' ^3 ~$ w; ~/ h9 F5 v
iowrite32(DXR_data,IO_ADDRESS(DXR_ADDR)); , U2 h1 P5 c4 [8 [* p6 J2 w
return 0;
. N8 v$ l) _3 Q' U
9 _ `6 \2 k4 e}
1 n4 `: _# U3 m' W* }# f7 m1 o. @
: a9 y7 F( `6 k6 n' hstatic ssize_t mcbsp_read(struct file *filp,char *buf,size_t len,loff_t *off)0 @ [- a5 ?1 S% ]$ D1 M
{ ' x% l* v5 C% O' _2 g' N/ Z$ ]# S
DRR_data = ioread16(IO_ADDRESS(DRR_ADDR));
) _2 y/ C$ D' j) r) T copy_to_user(buf,&DRR_data,len);
$ A- @% v9 Z. Y% J return 0;
@7 c1 g, z* u+ ]' Y$ D3 h}" j4 B9 x. s8 h2 q9 Q
6 F0 s5 r" z% S; ]$ x2 `4 t' m6 q* |
static struct file_operations mcbsp_fops=1 D4 P" R/ c0 Z7 s$ o' o
{- i5 e- X& G, C+ }& P
.owner=THIS_MODULE,( x8 ]: i/ T$ ~( b' p" v0 B
.open=mcbsp_open,
; a. ]& {% Q3 w4 S .release=mcbsp_release,7 p ]. e) c3 l3 ~' ^
.write=mcbsp_write,
8 P, X" N& {7 W; H( g .read=mcbsp_read,
( U9 k2 b- A+ x1 @9 @# e7 y; L};, U5 G# I( [% {) n+ A! H
static int __init MCBSP_init(void)
3 W9 P3 h' ^1 W& E{" C0 u$ s. j$ ?
int ret;# d" A& B9 [( O4 h: W; `9 d; P
unsigned int PINMUX1_REG_old;" K+ r- j" G9 V) N B6 s& R0 V" R
unsigned int PINMUX18_REG_old;
( s" c1 C; ^- O; n; d9 Z unsigned int PINMUX19_REG_old;1 \6 m, b N+ d! s& r7 ^
unsigned int temp; * D1 \- Z7 B/ @9 ]5 R% C
if(MCBSP_MAJOR)' y: g7 F9 P% v6 |4 P
{6 c( S' S ^) U1 F8 \, S5 G0 s3 V
mcbsp_dev=MKDEV(MCBSP_MAJOR,MCBSP_MINOR);
! n; F; i" T* T# F- n/ n- F9 T ret=register_chrdev_region(mcbsp_dev,count,MCBSP_NAME);
' E5 C& A! J# V, I4 b; i F }
" l. E# a8 z4 J$ D" s6 P3 e else3 y4 G* I# R {8 I9 Q- s( A
{! b* A# Q f8 d5 a+ x% L1 o0 E
ret=alloc_chrdev_region(&mcbsp_dev,MCBSP_MINOR,count,MCBSP_NAME);
. F+ f% Y) |9 d8 Y MCBSP_MAJOR=MAJOR(mcbsp_dev);
2 X! a! N0 s- L! Y( d) v }+ l. e M! M: A |! c: m3 z3 g
6 n" a- F7 f3 h; ]) M# d
if(ret<0)
3 o0 J* x2 i6 a' r! L0 r% x {
# i. o/ e# B% H" t" M) T printk(KERN_ERR "register chrdev fail!");# W. \1 b9 d( h# u& v- V
return -1;( k5 e; T2 _! V" m# F$ e
}- R; o' h( a( [' f# `8 u; V" |
# l; J0 B$ u B: G* {# t" W
mcbsp_cdev=cdev_alloc();- `8 k* g. S6 z, k! w/ _
! Y2 f: P8 n7 H$ X9 o( l" c if(mcbsp_cdev!=NULL)" c$ g4 J4 H" L' f# m; W
{; [& ^1 r% W; [
cdev_init(mcbsp_cdev,&mcbsp_fops); v( Q9 e9 m- h, P' u/ s
mcbsp_cdev->ops=&mcbsp_fops;
7 D6 c7 h3 O- ?- Z+ o, I' e mcbsp_cdev->owner=THIS_MODULE;9 E$ w) q+ `/ L1 a
. C# ]- y- N% f$ c, G. y, {
if(cdev_add(mcbsp_cdev,mcbsp_dev,count))& ~8 m0 a. h, P; L8 u) q3 k- ?" w
printk(KERN_ERR "register cdev fail!");
- c" O# h# _# k8 s; \! O5 z5 R2 [ else7 u# G( m+ ?3 ^. y1 n5 F
printk(KERN_ERR "register success!\n");7 ]. ~- b/ A$ C' e* \
}6 D5 f6 s! y3 z* K
else
0 C% |3 l/ ~4 k$ t8 v& e% x {
. j$ j2 z: Y2 J0 z: K. c printk(KERN_ERR "register cdev err!");& `! M& r2 t+ c1 t! S6 T/ r
return -1;
' B2 [4 K/ o4 q7 [2 Z/ _: c* j }# j% m0 O8 r$ ^$ W2 | ^
$ ?" E2 e3 o* I mcbsp_class=class_create(THIS_MODULE,MCBSP_NAME);
6 h5 S0 L9 _* G2 O if(IS_ERR(mcbsp_class))
- \& V- d$ k3 H. s {% h' {1 W0 V2 O
printk(KERN_ERR "register class err!");, K6 i) w* V. T. {1 o" V
return -1; h: q8 |$ d. p+ m4 E
}0 Z$ l3 k( i4 ~6 u5 l: F3 Q7 R
device_create(mcbsp_class,NULL,mcbsp_dev,NULL,MCBSP_NAME);2 G7 P1 B& j; X! I
+ f: E! ~- n. P" ^1 z9 _ //PSC
2 y: N4 E5 h% G3 i //add Enable MCBSP4 L% e8 a. N( e# f
//test. G. o$ Z. _* G& ~+ u e8 q
temp = 0x80000003;/ d4 A) z% d. a% _$ ^9 o o$ [( C
writel(temp, IO_ADDRESS(MDCTL15_ADDR));
* m2 x1 x9 r* ]) W temp = 0x00000003;
1 y m7 v5 o- r8 @& E6 g* j% w) p writel(temp, IO_ADDRESS(PTCMD_ADDR));* _8 o$ w ?0 s% e
" s. D: h) s. [# g: Q7 {8 a" B3 B j! b
temp = 0x001FF201;
* y& n. g# w2 j- T5 i; D writel(temp, IO_ADDRESS(PDCTL1_ADDR));
3 R" N& j+ H& ] M& @4 Z 7 z' C2 A4 W* k2 }+ {- }# U
//PINMUX
! Z3 ?$ \$ T, I //MCBSP_CLK(receive/send),MCBSP_STRB(receive/send),MCBSP_DX,MCBSP_DR,9 m' f2 Z% L, o) r% b, U/ I1 q$ F3 P
PINMUX1_REG_old=readl(IO_ADDRESS(SYSCFG_BASE)+PINMUX1_OFFSET); & M9 I; l" ]8 r7 Y; Y
PINMUX1_REG_old=(PINMUX1_REG_old&0xf000000f)|0x02222220; ! T- i, Z; C: O8 E: j: Y
writel(PINMUX1_REG_old, IO_ADDRESS(SYSCFG_BASE)+PINMUX1_OFFSET);7 o$ k/ `9 |( W
* T. p) O9 D! g" n0 d& L: o8 J
//SLEEP_EN,EPR,L138_SHK1,L138_RC
s+ Q& s) j+ l. {0 Q5 t6 g; S PINMUX18_REG_old=readl(IO_ADDRESS(SYSCFG_BASE)+PINMUX18_OFFSET); 1 L* s. ~& ~) F' n
PINMUX18_REG_old=(PINMUX18_REG_old&0x0000ffff)|0x88880000;
1 K( \2 t' | B8 p1 Q; `, N writel(PINMUX18_REG_old, IO_ADDRESS(SYSCFG_BASE)+PINMUX18_OFFSET);
2 T( ], l- N3 A; U" y* K! ] ) E% _. ~, B% u7 y8 ^) [
//RESETn,L138_SHK2$ {% g; ]& Z& y6 u9 A; |8 N3 ~
PINMUX19_REG_old=readl(IO_ADDRESS(SYSCFG_BASE)+PINMUX19_OFFSET); 0 c4 X* S1 a% c0 s9 B
PINMUX19_REG_old=(PINMUX19_REG_old&0xf0ffff0f)|0x08000080; 3 G" j* {9 p' Y2 Q
writel(PINMUX19_REG_old, IO_ADDRESS(SYSCFG_BASE)+PINMUX19_OFFSET);9 A" Q! `, v, U! \
7 B, k# o$ L" N6 Z, ^
" D3 i. Y9 g) ^3 x //SPCR Register
' ^1 j" r* n. [3 j f) |) Y //FREE-1,SOFT-1,FRST-0,GRST-0,XRST-0,RRST-0,RJUST-00(Zero-fill MSBs)reset
m- l0 G% e7 O/ v( y5 e temp = 0x03000000;//(DLB=0)7 K# a: ?$ Z7 C- Z5 T6 X# }
// temp = 0x03008000;//(DLB=1)
- {) F% v) g. f% }9 B writel(temp,IO_ADDRESS(SPCR_ADDR)); //reset
4 ]: Q! s8 H/ ^" F temp = readl(IO_ADDRESS(SPCR_ADDR));
7 e1 M4 A9 ` ?2 k$ s: w printk("temp=%x\n",temp);/ M# E# v$ F/ M$ n. W- T
" c7 \: u) l- ^. T8 X" g
//PCR Register
. O d6 `5 P: S //FSXM-1,FSRM-1,CLKXM-1,CLKRM-1,SCLKME-0,FSXP-0,FSRP-0,CLKXP-0,CLKRP-0. c* P) j, q% B- z4 N4 ]& C
// temp = 0x00000F0F;3 k# {: M9 N$ _" }& d* `6 f4 f
temp = 0x00000B0F;
4 G( j# ] y6 Q# L5 Z* `# K& e writel(temp,IO_ADDRESS(PCR_ADDR)); //initialized ) Q& n+ X+ Y, {: |7 p9 B8 d# U
temp = readl(IO_ADDRESS(PCR_ADDR));
@0 t- ^, I3 q4 s' j# ^) P printk("temp=%x\n",temp);
8 w, t$ b" A8 ^# s$ P, j5 y3 | //SRGR Register! N% ]; K- k! Z+ L6 t
//GSYNC-0,CLKSP-0,CLKSM-1,FPER-31,FWID-0,CLKGDV==11
2 \( ]8 {' k, q v% a //temp = 0x301F000B;1 Z3 c. u0 y1 }
writel(0x0301F000B,IO_ADDRESS(SRGR_ADDR)); //initialized
3 }/ V1 U8 _; M) @# ~ temp = readl(IO_ADDRESS(SRGR_ADDR));
& B/ z: f/ z. E X! k0 E printk("temp=%x\n",temp);
$ }9 t2 F$ w/ P9 Q* P8 v //RCR
. R1 X* o7 k+ D4 m3 K* |; i1 g //RPHASE-0,RFRLEN2-0,RWDLEN2-2,RCOMPAND-0,RFIG-1,
. b( }- S8 z9 `! G //RDATDLY-0,RFRLEN1-0,RWDLEN1-2,RWDREVRS-0
$ n1 v* o j, T9 R! t temp = 0x00440040;
5 X% l. J* u0 d+ V, U: f7 ] writel(temp,IO_ADDRESS(RCR_ADDR)); //initialized 0 O/ p" B6 f8 N) G' v7 g) Y
temp = readl(IO_ADDRESS(RCR_ADDR));
- w* a- w6 u' T$ A( n x printk("temp=%x\n",temp);
* K2 b/ E: U0 K0 p+ l7 l! m B //XCR3 W% u1 G1 `7 p$ ~, L9 o# D
//XPHASE-0,XFRLEN2-0,XWDLEN2-2,XCOMPAND-0,XFIG-1
. D$ I3 y2 @" } `6 b //XDATDLY-0,XFRLEN1-0,XWDLEN1-2,XWDREVRS-0
* ]1 w/ J- u+ n# e temp = 0x00440040;+ S' [: l7 T! t' ~- n/ X
writel(temp,IO_ADDRESS(XCR_ADDR)); //initialized
$ O7 b2 u+ R$ G0 z- f8 y temp = readl(IO_ADDRESS(XCR_ADDR));0 r' B+ q7 I3 c# _% ^( c
printk("temp=%x\n",temp);
1 m! j' l r7 | udelay(100);
( p `% D. S# O% b* Y& Q$ o& n! `) Y //SPCR Register
: p, q |6 ^* \$ } //FREE-1,SOFT-1,FRST-1,GRST-1,XRST-1,RRST-1- P e1 ?+ I( i( |$ d
temp = 0x03C10001; //DLB = 0 VS DLB = 1
1 `& ^/ b7 v) h5 j7 a writel(temp,IO_ADDRESS(SPCR_ADDR)); //enabled
1 Z, e1 t- s( w temp = readl(IO_ADDRESS(SPCR_ADDR));2 `9 {* @. }# g) D/ O7 N5 n
printk("temp=%x\n",temp);0 V" I& x, d, ~/ T
udelay(100);5 G* q- @0 Z1 M: J3 a
! W- [# n, @9 |( u* n A //set GPIO direction; ?) x, W3 i7 i# p- x
temp = __raw_readl(IO_ADDRESS(GPIO8_DIRECT));# x" p/ Y* B$ E9 x
temp = temp | 0x00000100;//EPR----input
* n1 b) @, W) o, q temp = temp&(~0x00000500);//RESETn,SLEEP_EN---output1 l' F3 T$ S2 Q3 g1 G/ Y4 ]
__raw_writel(temp,IO_ADDRESS(GPIO8_DIRECT));
. O- c& I7 l: ]9 p$ ^; |
' _' E, Z* k) M& M/ q: v return 0;
* b, E4 O7 i5 I2 E' R7 |5 z}
9 [9 b5 u# Z4 ostatic void __exit MCBSP_exit(void)' M x7 _+ |4 b3 J3 y+ }. X: y/ e
{: l* W* S% L8 a. L, p: B
printk("mcbsp chrdev exit!\n");7 Q$ n6 |9 K8 [3 h
cdev_del(mcbsp_cdev);
/ g4 `0 }) D" b unregister_chrdev_region(mcbsp_dev,count);: [5 b' T1 x8 r" Y: n
device_destroy(mcbsp_class,mcbsp_dev);
) Q" H+ E6 J8 i" f class_destroy(mcbsp_class);
) o# {4 j; q% c& c2 a}
0 {! \) E% W; G/ K0 Wmodule_init(MCBSP_init);
+ B5 W! T+ ]- q/ M0 w+ R* amodule_exit(MCBSP_exit);
/ o# v% V1 y. |6 Z ~# g3 {, ?9 _, z" ] n. u3 S
MODULE_LICENSE("GPL");
$ d6 \7 @% c2 ~/ i0 r
: v" g2 ^5 d0 p7 l; U6 ^7 }$ W Q我讲上面的程序insmod之后我用示波器量 McBSP的发送时钟脚,发送数据脚(我还没有发送数据)以及发送同步脚,3个脚的信号是一样的,不管是用我自己的底板测试还是用创龙OMAPL38 的开发板测试,都是一样的,类似于噪声的信号时钟频率也不对。
X: J0 U" ^* Y1 j我的应用层的测试程序如下
, X# j4 ~& _. P' W2 h9 `#include <stdio.h>( Q6 ^4 t5 k7 M3 [! ?6 B1 _
#include <string.h>
+ d$ e, |! Q! w, G0 |- z; s#include <fcntl.h>9 b0 y; Q, [' J+ p$ s$ m
#include <unistd.h>3 T7 ]+ ~% n/ N3 d2 A' M- E# y' O5 j
#include <signal.h>
* O# a# `: a0 K7 V#include <pthread.h> //线程
& b, _# ^2 S' } I+ K- }0 V# r#include <stdlib.h>
8 v. F- C2 E6 b#include <pcap.h> //捕获网口数据
& Q( r7 i& f* ~3 |0 {. R3 x* N#include <semaphore.h> //信号4 p P( R4 y1 X# A1 L
#include <sys/types.h> //消息对列. n' C, g+ v& w/ L2 A* L
#include <sys/ipc.h> //消息队列
3 L3 g1 ^# X( O" C1 q/ o- [9 z3 P#include <sys/msg.h> //消息队列
) ^4 a# g7 U7 \/ f& w#include <sys/select.h>
$ ]* v) {7 J3 u* b! }. b#include <sys/syscall.h>: h0 C" d$ |6 [ T$ V9 ?) T
#include <sys/stat.h>) V" f5 W( z" q# {: R, F
#include <sys/mman.h>
6 C$ S4 W1 P- c' l1 b. f4 o#define msleep(x) usleep(1000*x)
9 T s+ S; _8 s: Q3 o' G; Q2 ^& m( X; Q: O& V/ Q" N
int main(), K! }, R, }1 C- |8 M a
{ 5 X0 c( ]* e1 J
//MCBSP,ARM与AMBE2000交互设备
$ R4 j$ i- o9 x% t5 F int fd;
# P$ R+ r0 }8 r+ J unsigned short data_write = 0x5555;
2 G& H8 e7 w5 l/ l8 z3 ^" d unsigned short data_read = 0x00;# N [: K6 L: \" X; {
fd = open("/dev/MCBSP-device", O_RDWR | O_NONBLOCK | O_SYNC);: }5 f0 S% l4 c& l; f- O
// fd = open("/dev/led-device", O_RDWR | O_NONBLOCK | O_SYNC);
1 g. u; e+ E% j0 p
! ^0 z. e; t+ n. Z if(fd < 0)
+ W7 X! @5 E+ Q {; q% C& z) {/ O$ l" @5 H. H
perror("open failed\n");* b# r# U! R# N+ U; x1 L! T
return -1;
8 o. |7 ~2 E' J& [4 r' k4 B }3 i3 ]$ U, f5 H2 t
8 l0 \' n1 F/ U% x0 a$ e while(1)
3 w, r' q, K. }; a8 j# O {
* A4 d$ L+ f9 W. I; ~2 Q1 b
/ m& Z' V+ [1 i# A2 d, [ //AMBE2000每次读写是24个字为一帧9 @3 G1 g$ _$ T9 L& O
//写数据时将数据在底层存储起来,等到中断的时候再发送
. K$ o& R9 z) d! T O //AMBE2000输入数据是以0x13EC开头的7 Q! X6 |& x, j) {/ ~0 H
write(fd,&data_write,sizeof(unsigned short));
5 J. G+ d. ~8 Z* M: U3 R " B* M i D9 Y$ Q. y
//读数据的时候,在底层中断中将接收到的数据存储起来,然后再传送到应用层
) h4 U" H2 @! S5 D$ A read(fd,&data_read,sizeof(unsigned short));8 K4 k% \7 L, p! L
* G" f- R- l# h" S& `. d+ D if(data_read == 0x13Ec)3 ~' P* Y5 y# q5 k5 J5 R
{; ]/ n0 y* ?! c9 W
, |0 [& `9 h. K) F P; |
printf("data_read = %x\n",data_read);6 V- L# T/ D/ B
}
& @- E' H8 v, u& |, w% J+ ]1 ` ( l, E1 a! R3 |
msleep(10);! T- ]0 B; a+ m. h
9 ?( `6 h; L3 R% T0 B0 w) [5 J
/*& `& _; ?2 A5 \3 c' \& [
ioctl(fd,1); ! _3 l! C7 l d! f0 r
sleep(1);
- @, }3 |! n# M$ r; U ioctl(fd,0);
5 p7 O9 p$ [5 a8 U sleep(1);& F- r$ h7 G. H1 L$ w' k- P
*/ , ]' Q% ?1 c1 d% ]
}
! J, g$ o* P; L, G+ z) t return 0;
% X: J+ P' `. r" F - o3 Y0 B+ \: w( `' p. {9 |+ }
}* u+ G: e) t+ {) N Y
% c0 k0 s) K0 O) j- z
多谢各位指教,谢谢! 急
8 z8 T; _' f6 {: ~8 v, k9 O2 v8 {% Y2 |( y* g E& i# y
; X; W- Y3 |! n$ U; Z2 Y" `: p! B- w+ n& [" n! l) Q; Q
1 U0 F7 ~6 r+ P. y/ q
( {/ q# ^" o" k3 ^2 N. ` |
|