|
|
我讲创龙在DSP中使用的例子移植到ARM中,如下是我的底层驱动程序:
8 @7 A x* W+ {6 j! a/* e3 c8 A$ D5 y7 I
* Copyright (C) 2009 Texas Instruments Inc
- L' J S6 x$ ]+ x1 o, f *
* \: f. w1 E7 D * This program is free software; you can redistribute it and/or modify
# I9 X, F! T9 i; E* c2 P0 d$ O * it under the terms of the GNU General Public License as published by
1 \9 L) [- m" P' l8 q% M * the Free Software Foundation; either version 2 of the License, or- f- R/ T% n& F1 L7 p; _* K( D
* (at your option)any later version.% G1 F* K" D! s0 q* y' I* z: k
*
, f! ]& _! m0 G* d' w: M * This program is distributed in the hope that it will be useful,0 ~6 w% ? d1 q+ j0 g1 s( M
* but WITHOUT ANY WARRANTY; without even the implied warranty of( I9 s' `/ Y0 N$ Z- P
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the- I ^* p- ~8 G3 H
* GNU General Public License for more details.( I) u e. {' _4 W
*
: j& k5 B) n3 Z* X+ E! z% p7 _ * You should have received a copy of the GNU General Public License& A* v, B* ^; j1 p. A* ^& v
* along with this program; if not, write to the Free Software$ B/ m* W% z1 b
* Foundati& C+ e/ l/ a4 b5 ?* R0 c T
*/
* s- ?3 t1 ? G$ n9 Z#include <linux/module.h>& n$ R# ]; i I% `5 V# o, | U. `
#include <linux/init.h>$ R& p, e9 ~: L/ \
#include <linux/errno.h>1 w3 s5 l7 X0 m3 g2 U
#include <linux/types.h>
9 }' c& u5 H, g( s. F#include <linux/interrupt.h>
: {1 o; @) G; }4 D' `( s) X% [#include <linux/io.h>2 x3 ]. A4 ^6 J
#include <linux/sysctl.h>
# V0 ~+ S" Y+ q" \! q, q#include <linux/mm.h>* |$ T$ L3 \$ K' J4 E) r) k7 D9 |
#include <linux/delay.h>
. z8 e0 K0 W. l( Q9 y#include<linux/kernel.h>
. Q6 u1 V! _3 v1 X& k0 U7 X7 R#include<linux/fs.h>! O) t3 i0 [ y+ S! A1 t K" k
#include<linux/ioctl.h>
- W4 B+ |% g! a#include<linux/cdev.h>, [- q" I1 q6 b/ ?: S4 I
#include<linux/kdev_t.h>
/ Z: e) S- {* V. r1 W) _$ D3 {#include<linux/gpio.h>) V8 W- I& e2 P3 d" R
#include <mach/hardware.h>
+ {% k# _. S5 o* d/ A, i#include <mach/irqs.h># H% ]7 b$ S; Q, H: C9 P
, P, m. _3 j( E, d#include <asm/mach-types.h>
$ {: m$ [5 C$ k5 I9 n#include <asm/mach/arch.h>
% ]3 T' [. j/ {4 m! j- ^#include <mach/da8xx.h>
4 {- K! R) q- k3 L, M3 ]5 w#define SYSCFG_BASE 0x01c14000. y' ?, @3 |+ [
#define PINMUX1_OFFSET 0x124 % y! R4 o& L' N# N9 c5 O
#define PINMUX18_OFFSET 0x168 b+ R! b- _' A- s; P
#define PINMUX19_OFFSET 0x16c$ j, c" \& t9 u0 e, E
#define SPCR_ADDR 0x01D11008 //MCBSP1_SPCR# x" H; x) o6 \7 c7 _
#define RCR_ADDR 0x01D1100C //MCBSP1_RCR
; ~, }% s8 x/ o) @( i' R/ a#define XCR_ADDR 0x01D11010 //MCBSP1_XCR' B8 n- Q3 i( e* Q
#define SRGR_ADDR 0x01D11014 //MCBSP1_SRGR
$ @7 x4 F: l K3 [" Z$ @; O#define PCR_ADDR 0x01D11024 //MCBSP1_PCR' |$ w: h" a. u* A
% ?+ k+ S3 E; k, f9 T/ z! L
#define DXR_ADDR 0x01D11004 //MCBSP1_DXR7 M! s- u4 O2 M
#define DRR_ADDR 0x01D11000 //MCBSP1_DRR
+ |( \1 {/ W- I; ^) w: K//PSC7 }9 ?0 U8 @& N. T
#define PTCMD_ADDR 0x01E27120 ) V4 [' g! t1 X0 }& Y4 J2 c
#define MDCTL15_ADDR 0x01E27A3C
5 h+ t0 b2 }4 e0 m& P- j2 m#define PDCTL1_ADDR 0x01E27304' Q9 b, t: P1 Q
//GPIO8 direction9 @( ~1 r: V. O3 F7 z) N+ j
#define GPIO8_DIRECT 0x01E260B0
! x" D4 ^- M N" t) j5 A5 U#define GPIO8_OUT 0x01E260B4
T3 P K! f# k0 c7 j& I b& {#define GPIO8_IN 0x01E260C0
1 g3 C. C1 S" x" ^! r* ]$ u; [1 d, P/ T# l6 ]" y$ a
//#define MCBSP1_RINT 99 ! Y% D" n* J$ c: z# j8 D; |1 @3 d, T
//#define MCBSP1_XINT 100 6 ]* o R" N6 \1 P" d
static int MCBSP_MAJOR=239;
5 }+ C' H/ y( e$ Tstatic int MCBSP_MINOR=0;3 Z5 s5 c1 b! }8 u3 b# X/ t
static int count =1;* J/ {3 ]! A8 |
5 }% y# h' P2 I9 \
#define MCBSP_NAME "MCBSP-device"
1 K; v- N9 ~8 R5 j& k) H, P; Y2 v9 P
' m$ I6 w* a, q& S; n% T4 D: ustatic struct cdev *mcbsp_cdev;) k G6 H/ |9 A" f4 [& D
static struct class *mcbsp_class;2 C* M; [, ]( o( @. R
static dev_t mcbsp_dev;) x2 x& ]. p5 z, q; x
unsigned int DRR_data;7 P n- [9 I" \+ w q& V! e: s
unsigned int DXR_data;6 ~+ O3 i) u% C- j) J2 S
static int mcbsp_open(struct inode *inode,struct file *file)- X2 ^' \' g; K( q/ }# F$ c
{
7 W6 M% y5 G4 ^- u9 |3 U# k
A) n: n5 x( ^2 Y6 u. G5 X //interrupt enable,initialized/ O% f( {; s3 u, W' v# z
unsigned int temp;5 q& m# K7 T2 I1 x" R; s- K6 T# s
//SLEEP_EN(GPIO8[10])---02 ^7 r8 y+ w/ h( ^3 L. C5 U8 R
temp = __raw_readl(IO_ADDRESS(GPIO8_OUT));/ b9 i# z ~, T( h, R' m
temp=temp&(~0x00000400);
8 A# G! m8 [/ S' N3 R __raw_writel(temp,IO_ADDRESS(GPIO8_OUT));//GPIO8[10]
1 d6 w5 y2 ^8 y( R! K3 V //RESETn(GPIO8[8])----0----1
8 c, [/ f& E+ H( @4 B( w' Y temp = __raw_readl(IO_ADDRESS(GPIO8_OUT));3 f% y9 Q/ g! q
temp=temp&(~0x00000100);
3 _( U) t' P4 \ __raw_writel(temp,IO_ADDRESS(GPIO8_OUT));//GPIO8[8]---0. Q, b8 Z$ S+ n
udelay(100);8 f1 b/ J9 |& ^) |' D) f) ~, B
temp=temp| 0x00000100;
) c" T9 Y" w) {8 t, [& A" ^8 F8 z __raw_writel(temp,IO_ADDRESS(GPIO8_OUT));//GPIO8[8]---1
7 k2 h$ Y' e6 z7 [, v; G9 o udelay(100);1 A; L* L0 g! V ?
printk("open success!\n");
& L) v/ t9 b K9 d; [+ h return 0;
1 x" m$ i- o$ f" ^4 `2 r: W}
6 M6 Y4 ^. w+ ]* r# b5 d* s. e2 j$ Y0 E6 v
static int mcbsp_release(struct inode *inode,struct file *file)2 ^( N5 K* I% |0 s+ c
{
. f0 X" i7 Z% o+ D printk("release success!\n");- r6 t. P# A- |
return 0;
3 C8 p) x2 M* T! y+ M1 a}6 L( J8 ~% y# E
$ u9 s' N9 Z, \& ?; lstatic ssize_t mcbsp_write(struct file *filp,const char *buf,size_t len,loff_t *off)# J7 M# I; k1 M- _5 V% H# i1 W! j- w
{, X c, W# U9 V0 w4 Z
copy_from_user(&DXR_data,buf,len);
/ R8 B8 a* I, M' [. k iowrite32(DXR_data,IO_ADDRESS(DXR_ADDR)); 9 g$ u( w& v- ~4 @6 v
return 0;) X9 {6 A) x4 A. _& p5 _! J
3 i# y( C' ^4 @: |! N4 N4 u+ |6 y
}$ [& a. P: {+ j! N
3 i& A$ [- R$ u& J/ pstatic ssize_t mcbsp_read(struct file *filp,char *buf,size_t len,loff_t *off)0 ]$ t- [/ n9 l2 D5 k$ Z6 @( W
{
9 T. W1 }0 z' m+ C. a$ d! X DRR_data = ioread16(IO_ADDRESS(DRR_ADDR));2 l, K( B$ a& h* z
copy_to_user(buf,&DRR_data,len); ( ~5 n, y/ P2 L1 ?
return 0;9 X# u T; G/ ]& f
}, k6 K6 Y1 }: f8 b* ]3 E# _* H
( Z! l+ K1 p' ^& r7 a" \& F; D9 D9 E( C
static struct file_operations mcbsp_fops=
# k( o$ P3 N& c( t: W- L( e2 r- S+ S{
' f% O0 U( |+ L# B. P6 G* @6 r5 _ .owner=THIS_MODULE,
6 n6 B# Q& m8 Z+ f, }; T2 T+ m .open=mcbsp_open,
* f! u; w; g+ x" y& t/ | .release=mcbsp_release,0 f1 a, L" w0 J
.write=mcbsp_write,5 D( v) Q$ W( i+ g
.read=mcbsp_read,. z; M/ m9 e' H3 r
};
% |8 R( ~( X( B) Y9 d! b; v/ Jstatic int __init MCBSP_init(void)" w- U/ |. W6 |+ X
{
; x8 Z3 L- I7 ^! j1 Q- t" L6 a int ret;
6 ]7 v/ h X( l unsigned int PINMUX1_REG_old;
5 f# Z% M Z3 k unsigned int PINMUX18_REG_old;+ a2 E' O/ A7 e
unsigned int PINMUX19_REG_old;+ J. r# t, A3 K! N7 C
unsigned int temp;
9 J7 H" I5 c* { w( l( z9 A$ H+ j8 ? if(MCBSP_MAJOR)
7 f! L1 S* p! h! z {6 o' W$ g6 n* G1 c
mcbsp_dev=MKDEV(MCBSP_MAJOR,MCBSP_MINOR);% O- P+ u/ q/ n/ B
ret=register_chrdev_region(mcbsp_dev,count,MCBSP_NAME);
) p, v) Q! t$ D }
% t o5 s8 P9 z5 R5 h( ?2 u& Q else, v/ R( ]9 n u9 m
{ O2 ~0 w& {+ s2 q, B$ z
ret=alloc_chrdev_region(&mcbsp_dev,MCBSP_MINOR,count,MCBSP_NAME);
) K) u% D% ~1 e4 J, ] MCBSP_MAJOR=MAJOR(mcbsp_dev);
, i% P5 n- h: @ j" Y9 ` }
+ n- E- }8 y* W1 d7 r! ^7 h" Q
# L7 d8 N. @! j `+ W6 o if(ret<0)
) c2 B" r1 c8 T7 P8 {$ N: j! c8 z3 W {
! ~ q1 w0 y9 o; J/ a3 W8 K8 V printk(KERN_ERR "register chrdev fail!");5 U. ^/ O+ D2 G) p- @& c
return -1;+ }& b) y; p2 f0 O6 z: R4 R% y
}4 k6 N8 Q( L# \. C" F8 c6 U
+ \6 m7 D) l. g7 _ C0 d( J
mcbsp_cdev=cdev_alloc();& C R( @( H+ r3 a6 ?3 `8 K
2 Z/ o& I! A- m
if(mcbsp_cdev!=NULL)4 E# w, E# n" ]( d! f
{! T6 R1 L& p5 f7 W* ]
cdev_init(mcbsp_cdev,&mcbsp_fops);
7 t! {' {- ^) p9 v2 C3 E( V mcbsp_cdev->ops=&mcbsp_fops;5 s y/ U6 q: T5 g8 x2 w' t
mcbsp_cdev->owner=THIS_MODULE;
]; Z: T1 s) e; L9 n5 K
; i5 L4 t/ t5 ~' a( _ if(cdev_add(mcbsp_cdev,mcbsp_dev,count))
( p- T N: j8 R6 h5 P% ~ printk(KERN_ERR "register cdev fail!");4 V" G! K. \2 ]) b$ `1 ^ F
else
' ]. F, J5 W% O0 \" y printk(KERN_ERR "register success!\n");+ b0 b/ I* B, u
} m. y& M1 j4 ?' S1 R
else9 `1 b3 u7 x7 G8 [8 Z
{
4 r( T) N4 Y/ {* I+ w$ } printk(KERN_ERR "register cdev err!");9 c+ l' u8 H) G" ]( b2 j% E( g
return -1;
. f+ U0 J; L1 j; ^ }$ T$ E4 Y5 j! ^$ N9 r! {
9 v: q% C9 _* K mcbsp_class=class_create(THIS_MODULE,MCBSP_NAME);
* d0 Q; ?& b/ H, g+ v; R8 O if(IS_ERR(mcbsp_class))
% G/ u4 _# c" U. I+ C {
3 `% [' L. o2 }- O3 L7 _ printk(KERN_ERR "register class err!");) g# k8 a- X' ^: k/ t
return -1;: U9 w0 T" z& {# s. C% X& \7 o% y
}; s, g- V# v) }
device_create(mcbsp_class,NULL,mcbsp_dev,NULL,MCBSP_NAME);
/ ]* b9 p, D$ C7 M4 q5 y1 z9 u7 x
//PSC% U: o8 `) ]" ^, A2 B1 k
//add Enable MCBSP
! M% {! y* n+ t# O" y: h$ P //test
1 `# ?2 l$ C) R temp = 0x80000003;5 C2 _+ F7 g# e# m" d' u
writel(temp, IO_ADDRESS(MDCTL15_ADDR));
. i- d6 ]. ^6 P! v+ A3 z temp = 0x00000003;8 [) M& |" H$ o }9 D. Q9 x1 v
writel(temp, IO_ADDRESS(PTCMD_ADDR));
5 p$ T8 l ]! S* [/ M+ l. n9 q # T) j' Q6 Z: `& o( _$ E* o1 m
temp = 0x001FF201;8 h4 S6 g/ m; ?! \. w- E
writel(temp, IO_ADDRESS(PDCTL1_ADDR));
1 g" _+ H2 ?; w: n 7 k, i; Z7 [6 V( S5 a" z" g
//PINMUX " Y# i( C) Y" A3 P% X5 y4 E
//MCBSP_CLK(receive/send),MCBSP_STRB(receive/send),MCBSP_DX,MCBSP_DR,3 E) r; D0 [9 f7 Y) p7 I( ^
PINMUX1_REG_old=readl(IO_ADDRESS(SYSCFG_BASE)+PINMUX1_OFFSET);
/ `9 B, L: B& W0 A, t PINMUX1_REG_old=(PINMUX1_REG_old&0xf000000f)|0x02222220; & M+ B2 @" |. B( }; S* h: j
writel(PINMUX1_REG_old, IO_ADDRESS(SYSCFG_BASE)+PINMUX1_OFFSET);+ l8 |5 [# Z5 w0 O) `
4 ?8 P0 n3 h" h5 M
//SLEEP_EN,EPR,L138_SHK1,L138_RC; g3 p0 e+ D3 S0 \: A C
PINMUX18_REG_old=readl(IO_ADDRESS(SYSCFG_BASE)+PINMUX18_OFFSET); 4 o, f+ o; M' t2 a, Z% I4 W
PINMUX18_REG_old=(PINMUX18_REG_old&0x0000ffff)|0x88880000; - B2 a0 @* M4 h' `
writel(PINMUX18_REG_old, IO_ADDRESS(SYSCFG_BASE)+PINMUX18_OFFSET);
$ f+ F* D2 R( G1 o& Q ( {5 {# Q) g& @ C# H; h M
//RESETn,L138_SHK2
; R" R! W! V" ~1 {: V PINMUX19_REG_old=readl(IO_ADDRESS(SYSCFG_BASE)+PINMUX19_OFFSET); 0 Q" |" X5 [. {* ^9 _3 ^
PINMUX19_REG_old=(PINMUX19_REG_old&0xf0ffff0f)|0x08000080; & `7 ^; ^, J# }& Z) U7 t7 ?
writel(PINMUX19_REG_old, IO_ADDRESS(SYSCFG_BASE)+PINMUX19_OFFSET);: C7 G B7 `) A* m1 S! G7 w7 [
9 _0 @9 [) n* [6 i ) e1 @2 m0 }! L
//SPCR Register
( X- V! d" ~0 l' y //FREE-1,SOFT-1,FRST-0,GRST-0,XRST-0,RRST-0,RJUST-00(Zero-fill MSBs)reset
" G( R; ^) h0 ]- h* r temp = 0x03000000;//(DLB=0)
$ y3 u' K6 l+ w8 Z! [* V* b // temp = 0x03008000;//(DLB=1)* I0 B9 q$ J! _" a( _
writel(temp,IO_ADDRESS(SPCR_ADDR)); //reset
. F+ Q& F8 L* {; `" t$ e+ N# ] temp = readl(IO_ADDRESS(SPCR_ADDR));
; n+ m9 x" v! ?+ Y2 H printk("temp=%x\n",temp);5 X {7 P( }* ^/ c1 u
( q; s! i6 S9 _+ E //PCR Register$ c. G# ]- ^) X0 l
//FSXM-1,FSRM-1,CLKXM-1,CLKRM-1,SCLKME-0,FSXP-0,FSRP-0,CLKXP-0,CLKRP-0! q; @0 e' l# _, E% x
// temp = 0x00000F0F;
5 b$ Z: U" @+ W% p temp = 0x00000B0F;
5 S4 {. H; K6 Q& k. \ writel(temp,IO_ADDRESS(PCR_ADDR)); //initialized
% f `) }/ H J, A- y# b temp = readl(IO_ADDRESS(PCR_ADDR));8 e* H# I7 _6 L! f
printk("temp=%x\n",temp); 9 E# v9 c! r- Z0 Z! G
//SRGR Register
( p( S, q2 i$ N' \& Q* K; F, ~5 K //GSYNC-0,CLKSP-0,CLKSM-1,FPER-31,FWID-0,CLKGDV==11
- a/ H3 r8 Z+ V2 B" m& R //temp = 0x301F000B; @! ?1 [3 M5 ~ z1 _
writel(0x0301F000B,IO_ADDRESS(SRGR_ADDR)); //initialized
5 K: ]4 M5 m- p4 t: x, g temp = readl(IO_ADDRESS(SRGR_ADDR));- U$ n6 [3 s0 p' G
printk("temp=%x\n",temp);
) e' Q) b; i! x2 L% m7 h1 ^; Z //RCR
7 j; \5 W6 K) w, ^3 a( r9 z //RPHASE-0,RFRLEN2-0,RWDLEN2-2,RCOMPAND-0,RFIG-1,7 j: W9 T R# v
//RDATDLY-0,RFRLEN1-0,RWDLEN1-2,RWDREVRS-04 m3 Q0 r6 |- _8 @$ P
temp = 0x00440040;; e% D) n9 z' A% ]% F) [7 i" f2 Q7 `
writel(temp,IO_ADDRESS(RCR_ADDR)); //initialized ( z# N6 f' J. `4 o7 z- P- x0 b( v
temp = readl(IO_ADDRESS(RCR_ADDR));1 ~ u# R9 f1 [# n5 y/ w/ {$ R! g1 m3 _
printk("temp=%x\n",temp);1 P" k" e, [( F- Q
//XCR* O" j9 u% f3 Z0 F
//XPHASE-0,XFRLEN2-0,XWDLEN2-2,XCOMPAND-0,XFIG-1
1 _4 e8 O( ]+ m5 }2 o9 m //XDATDLY-0,XFRLEN1-0,XWDLEN1-2,XWDREVRS-0
7 {( y+ _' `" s( Q6 h7 J temp = 0x00440040;
' l5 O% D; w9 B. y H9 h0 X" p writel(temp,IO_ADDRESS(XCR_ADDR)); //initialized : E2 q9 a1 W& Q% L& ?9 V/ Y# E
temp = readl(IO_ADDRESS(XCR_ADDR)); P7 I. u! K! d/ z7 t5 f* g2 x2 E
printk("temp=%x\n",temp);+ _5 o& A( G( w' P5 n* _3 R; {& d
udelay(100);/ `/ M3 g8 T. g" x/ d1 W
//SPCR Register
, p$ Z V4 D' m1 u7 h; B. C //FREE-1,SOFT-1,FRST-1,GRST-1,XRST-1,RRST-1+ C1 \0 v% U& {2 c' {) i/ V
temp = 0x03C10001; //DLB = 0 VS DLB = 1
7 B$ `. ^. K' ^4 I writel(temp,IO_ADDRESS(SPCR_ADDR)); //enabled
! R1 Y5 s& s1 W+ X( o( I! G temp = readl(IO_ADDRESS(SPCR_ADDR));
: Q: G9 z6 y' B0 z% S0 ~ printk("temp=%x\n",temp);3 c3 \; h" U' q9 Q/ ^
udelay(100);) S9 a: ~5 C0 x; G0 w0 ^0 |! }
' Z4 B& N6 h1 Q2 u5 t7 N5 r/ `
//set GPIO direction5 ?" e- x3 Q) m/ [; n
temp = __raw_readl(IO_ADDRESS(GPIO8_DIRECT));# v/ B/ _7 ^6 Q- T: t1 k6 p
temp = temp | 0x00000100;//EPR----input
* K* \ v0 N; r: Y+ O5 d* d/ j5 \) Z temp = temp&(~0x00000500);//RESETn,SLEEP_EN---output
/ u4 z ?+ I" I1 q8 y% W __raw_writel(temp,IO_ADDRESS(GPIO8_DIRECT));
, ]0 v" i& T- A3 R8 j! h W1 Z. D" @% r
return 0;
1 B+ ]" n5 h+ Q}6 D& l$ ]- X$ }8 T. e' A* ?$ h3 Q$ ]
static void __exit MCBSP_exit(void)! U4 r# Y9 ^7 p% \3 m$ N4 V
{
- n& F% c: x- W" }% f printk("mcbsp chrdev exit!\n");
, F6 R' X8 v$ i" x: S cdev_del(mcbsp_cdev);9 K. Z4 [/ V) c! G5 Q7 ~
unregister_chrdev_region(mcbsp_dev,count);6 U0 d2 C! x# R. C0 J9 b
device_destroy(mcbsp_class,mcbsp_dev);
& \4 ?) {& K9 ^ class_destroy(mcbsp_class);
# v8 x# P6 f5 ~; A}
/ d L% D9 q S2 D6 rmodule_init(MCBSP_init);% D# K* d! b4 Q+ V4 X% d
module_exit(MCBSP_exit);
O: G! [: Z) s" D0 E3 L. z) I) s/ Y4 m7 ^, w. P4 L( s6 m" F& {# z C% A
MODULE_LICENSE("GPL");
# q6 l4 c, C4 o9 ~' U7 e
* j3 w7 ^7 v- s# W7 N( v我讲上面的程序insmod之后我用示波器量 McBSP的发送时钟脚,发送数据脚(我还没有发送数据)以及发送同步脚,3个脚的信号是一样的,不管是用我自己的底板测试还是用创龙OMAPL38 的开发板测试,都是一样的,类似于噪声的信号时钟频率也不对。; _/ {$ ?, ?7 L; K" V. E) d
我的应用层的测试程序如下% q/ W6 s! U2 i- o. D8 ^8 Y
#include <stdio.h>
5 c1 C2 l5 w! R' B+ j6 ?#include <string.h>
3 E- \$ D1 O) @" A#include <fcntl.h>/ V" V5 E/ s4 p4 j, `
#include <unistd.h>& p) D) b1 W- }7 x% ^! S$ f7 l$ x
#include <signal.h>' D2 c0 k. c1 n% I9 G' p
#include <pthread.h> //线程+ {# [* B) i+ `" g9 ^8 h3 I
#include <stdlib.h>% b6 x2 @0 a: l! |# C* W$ f
#include <pcap.h> //捕获网口数据
: A+ O: j2 L6 d7 w" f O. U! M" l#include <semaphore.h> //信号9 u$ c- c- I! z7 j( k
#include <sys/types.h> //消息对列 C, V) `1 s4 Z( G
#include <sys/ipc.h> //消息队列
4 F% ^( N$ M1 Y( u#include <sys/msg.h> //消息队列
2 a. {2 b7 ?. j) S7 s6 N#include <sys/select.h>! r0 C; r, Y0 B+ N3 Y
#include <sys/syscall.h>! ^1 ?2 E: f/ u$ S
#include <sys/stat.h>& J% K% Q; n4 s& v
#include <sys/mman.h>9 H5 } K* ^ d. H0 B
#define msleep(x) usleep(1000*x)
6 @* m7 s8 w- q4 r3 L( A: B0 k) S' I0 d" |. }, r
int main()0 |5 G8 g1 U1 p7 l9 v" w3 E- ~6 @
{
$ |- K7 M D- M //MCBSP,ARM与AMBE2000交互设备" o7 G* p' R% L4 p
int fd;
! ]- o2 m: K$ i unsigned short data_write = 0x5555;& U7 g- y9 t( w7 b: y
unsigned short data_read = 0x00;2 ?/ \( V0 q* T$ @# W: A, }
fd = open("/dev/MCBSP-device", O_RDWR | O_NONBLOCK | O_SYNC);/ U! W7 M+ U( i) {+ L5 `( ]1 C
// fd = open("/dev/led-device", O_RDWR | O_NONBLOCK | O_SYNC);
0 g: V+ q. w: k; M! r9 m2 V
$ K2 u5 C# z6 T2 X" | if(fd < 0)
- x/ ]' r/ X; d$ @ {" c/ K! o+ X) e& U; U
perror("open failed\n");
3 _3 d% Y; ~1 w- G return -1;/ |% j2 V; m. K0 p& ]
}: r! W/ v8 k9 o+ {( b
" i3 Q# u( K2 T$ |+ O/ b; L8 R while(1), C% `; C U! _: X; d
{$ S/ H" A7 b' |2 Y7 [4 T1 ^
% |: |8 Z9 {. u* v //AMBE2000每次读写是24个字为一帧
$ Y. V# P- h% M' f# o& Z2 c //写数据时将数据在底层存储起来,等到中断的时候再发送7 J$ V0 n( m; I# T
//AMBE2000输入数据是以0x13EC开头的
/ |8 {9 |0 {1 c/ i8 u0 r write(fd,&data_write,sizeof(unsigned short));8 ]& t0 B! r! h7 D; P
) V5 `2 X, A1 D" L% @: D7 ^) k //读数据的时候,在底层中断中将接收到的数据存储起来,然后再传送到应用层
: m, b/ p" X. \+ k) D& D read(fd,&data_read,sizeof(unsigned short));
# ^, k, N9 F; i3 I
; D' P) a. b V if(data_read == 0x13Ec)
# @6 |3 x$ o* d( V% e, u1 I {
" p& s" @/ j8 c# j6 s% [$ W0 f ) ^/ q. F' o% |! P3 J. V) u( a' q$ n
printf("data_read = %x\n",data_read);
. i0 R7 F" S. [7 u) o G" c$ C }
5 ^% L6 @/ ]: K9 t' @4 W
8 y+ ^# f, p% M) o6 V7 J9 n msleep(10);
" z5 r0 Y! t r4 L# N8 }1 R
& m1 L( B t: B# y: q2 V& Y) M/ f7 x" R /*
_8 W. P. ?+ W8 C3 S* ^ m ioctl(fd,1); - W- R' j$ `) R% Q1 }
sleep(1);1 W. B/ G: V$ b* z1 i
ioctl(fd,0);% {' U; Z+ W9 u4 }- g
sleep(1);
2 h9 h& e0 j2 ]# [- _ */ - x2 k8 S0 H+ q: } v, p' [5 c
}
% d6 c$ m, D9 t! D+ \* F% Z G return 0;+ |4 A8 F1 ?) ]% t0 m
/ ^8 C$ Z1 C1 B& W}' d& f( Y, B+ n' I! h2 A
! m- `! W( }( T7 p1 M% k0 a9 i
多谢各位指教,谢谢! 急
4 d' `; p* X. J5 z. @, ?: w. q, C
2 r( P+ C- N: Q# X
' @" ~5 g) S$ Z$ L6 H5 v9 I5 J
) K# u* B V2 D* }$ C/ Z+ C) l' f6 T6 E) l
4 {- U2 G' t6 E; t
|
|