|
|
我讲创龙在DSP中使用的例子移植到ARM中,如下是我的底层驱动程序: |: _# z1 N/ f
/*
_% j9 c/ v5 m# S1 W8 ] * Copyright (C) 2009 Texas Instruments Inc$ C+ J1 x2 W( S2 P& a3 {0 f
*
, h& @" ]. C7 _+ L9 p( @ * This program is free software; you can redistribute it and/or modify- |2 I+ M6 ~- `$ m, I- J+ o+ K& B
* it under the terms of the GNU General Public License as published by O/ a* B- O3 r1 m% ?" N N
* the Free Software Foundation; either version 2 of the License, or
/ \3 H% p/ e3 s * (at your option)any later version.' c# ^6 }$ Y7 D) D: c1 a
*4 e0 G- o3 T3 ~! {: U, o: q7 J
* This program is distributed in the hope that it will be useful,/ |7 O% Q8 v7 n) a# k) B
* but WITHOUT ANY WARRANTY; without even the implied warranty of! g ~& c& l- E- {- j; c% [
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the6 I% @1 R/ \& B \6 O
* GNU General Public License for more details.
- s% r5 Q2 K" Q! b *$ l* N1 w1 f& e H4 E- N2 S, _6 J
* You should have received a copy of the GNU General Public License
. y. a) A+ [, p8 o6 A7 c * along with this program; if not, write to the Free Software: y! g8 z G; x* L2 e
* Foundati9 c) V. {/ d& t9 C6 C
*/; j7 Z1 F) w3 [% P7 U" ?; c
#include <linux/module.h>
+ {3 _- q2 f6 H B$ I$ F#include <linux/init.h>
8 Y1 R/ i, f" p; q% A* G7 t/ Y#include <linux/errno.h>7 @ l$ R2 U/ R
#include <linux/types.h>
" ] |+ F8 c: k" S; [6 U4 @#include <linux/interrupt.h>
7 m/ |7 m) w7 v5 i$ z& O1 r$ n! N#include <linux/io.h>
4 b$ V) D) e8 ~, P#include <linux/sysctl.h>- r7 L- M$ f( T$ l, Y
#include <linux/mm.h>
# f& N. L/ w& D! @, U( n#include <linux/delay.h>& z" f7 S% Z+ `0 v0 n: c: x
#include<linux/kernel.h> u8 o% Q0 _& K/ I" ^( J
#include<linux/fs.h>4 [2 t. ~$ ]: O7 M
#include<linux/ioctl.h>! G4 @3 C" N; k z
#include<linux/cdev.h>: s" X( F" Q. D- p9 z. Z6 P" |
#include<linux/kdev_t.h>/ t6 G# t1 e' u. N% J5 r
#include<linux/gpio.h>
7 z" Z9 E7 C) z9 k. {#include <mach/hardware.h>
: o& G2 U2 o4 T#include <mach/irqs.h>$ o2 `. q2 h& N0 P, r. h/ g) A
w. \; ~2 F9 V. ]. t, R#include <asm/mach-types.h>
$ s- B" L; b4 Z1 Q2 a& c. j#include <asm/mach/arch.h>: u5 n- n* P2 X! i1 L" U
#include <mach/da8xx.h>* N" ]. S: Y1 K0 _5 @
#define SYSCFG_BASE 0x01c140006 T3 n, B4 T% w( m* G
#define PINMUX1_OFFSET 0x124
h( Q s w0 w# Z: \5 z+ V#define PINMUX18_OFFSET 0x168 `, l) |% @0 h: I, I1 z
#define PINMUX19_OFFSET 0x16c E+ B3 N1 o) F
#define SPCR_ADDR 0x01D11008 //MCBSP1_SPCR
/ x: e6 t# ]4 i8 M#define RCR_ADDR 0x01D1100C //MCBSP1_RCR
; j5 x5 M: W) l" ]7 h! u#define XCR_ADDR 0x01D11010 //MCBSP1_XCR
* D) q2 v& B- C ]- Z#define SRGR_ADDR 0x01D11014 //MCBSP1_SRGR
. i3 U# V* p5 R; w#define PCR_ADDR 0x01D11024 //MCBSP1_PCR
r: x! v6 \% W) k* j, Y6 `7 d 7 Y! w. _4 `" N& Z
#define DXR_ADDR 0x01D11004 //MCBSP1_DXR
, ?$ p- h$ u& B! z. d" W0 ]* c#define DRR_ADDR 0x01D11000 //MCBSP1_DRR
t* r6 H/ w3 \2 e d0 ]//PSC" Z0 g+ R4 Q/ G' ?. u
#define PTCMD_ADDR 0x01E27120
8 F4 T$ e: _$ |; J#define MDCTL15_ADDR 0x01E27A3C
5 l) J6 Q8 |/ Q _#define PDCTL1_ADDR 0x01E27304
, H. t2 M- u6 S//GPIO8 direction
& p" u% J+ u: b6 n$ B#define GPIO8_DIRECT 0x01E260B0
2 K# s. ~: d) i _1 b#define GPIO8_OUT 0x01E260B4
W# N( u0 d+ W7 J3 T( W+ k, d8 W#define GPIO8_IN 0x01E260C0+ v9 x4 o) o, }& J8 e
8 D- h' I& g9 u& x//#define MCBSP1_RINT 99 * J7 _& U5 [7 F+ h, V+ Q1 b
//#define MCBSP1_XINT 100 / \) b& Q+ x6 R2 Z6 e& L
static int MCBSP_MAJOR=239;
0 h' c t& {! Cstatic int MCBSP_MINOR=0;7 B- j: w$ l% ]& r/ r
static int count =1;7 O# R3 f* ~, N% g7 O# }
0 A% U! M: K/ a# O& ]' J4 @
#define MCBSP_NAME "MCBSP-device"
. {* H9 T- J% r* j" g1 A1 p! n6 M! X. u% M7 E' ^0 Z" O. j4 Y
static struct cdev *mcbsp_cdev;# E- D: j- ?; i) h1 k3 k
static struct class *mcbsp_class;" T; B# S5 Z g! i2 n3 b" b
static dev_t mcbsp_dev;
" e6 f* ]# M! V8 v [ C- Dunsigned int DRR_data;; }2 U. d' N5 S& u* b+ d! T" B
unsigned int DXR_data;
6 r: ^. i/ c, \$ q. T1 ~static int mcbsp_open(struct inode *inode,struct file *file)( M9 Z4 H* _$ k3 q# t- V
{
& d- \( o2 r5 }! \* ~; g# l
}1 w, E* l4 y- ~ //interrupt enable,initialized
: f* C$ |% ]. a, G unsigned int temp;
1 |7 }0 E0 K* \5 o //SLEEP_EN(GPIO8[10])---0+ P2 h* Z" d0 C. ~3 [" H
temp = __raw_readl(IO_ADDRESS(GPIO8_OUT));
: R4 C1 B. f, c7 ~ temp=temp&(~0x00000400);
6 E& m- M- P# J, O __raw_writel(temp,IO_ADDRESS(GPIO8_OUT));//GPIO8[10]1 o$ }. d0 h/ l' z( b
//RESETn(GPIO8[8])----0----1
/ t$ z5 }/ d( c* V6 E4 A$ c6 _- C temp = __raw_readl(IO_ADDRESS(GPIO8_OUT));
& h6 v- X& X4 l* D. j$ T6 Y- e' F temp=temp&(~0x00000100);; H# M$ |% _! c* t# J7 [: s" C4 p
__raw_writel(temp,IO_ADDRESS(GPIO8_OUT));//GPIO8[8]---0$ e, X; t5 S/ n( t
udelay(100);
; Y1 \: m% [* \& P8 | temp=temp| 0x00000100;
& g e f; M; o7 }, [6 \4 T4 [ __raw_writel(temp,IO_ADDRESS(GPIO8_OUT));//GPIO8[8]---1. f$ j, _) M7 O( q, c$ ~6 _3 u
udelay(100);
( S: b4 M8 N3 v5 T( \, T9 q printk("open success!\n");, d1 ^! y$ P O) s* s
return 0;) M0 x- u; Q* X; `8 q3 ]) W. w; t
}
& b; |5 r$ c t: z' H. N+ X) u: D/ ^$ Z" j+ F; @) ?1 }+ v
static int mcbsp_release(struct inode *inode,struct file *file)
9 R# x. {( B( s* P% K9 ~3 I+ Z{
3 ?" ]" w2 ?! E7 O& {; g* S7 E6 y printk("release success!\n");
. ^7 X- ~# t; l- ^/ Y return 0;
( r6 s4 L/ r0 K/ d* F}
) O0 e$ t+ u+ F4 x- v
/ ^% L, {3 i2 l3 E* Qstatic ssize_t mcbsp_write(struct file *filp,const char *buf,size_t len,loff_t *off)& S1 ~8 y `9 x/ {5 p1 `% W
{% x% I" s u/ w2 y
copy_from_user(&DXR_data,buf,len);
6 s! W+ ^9 X8 x T( O iowrite32(DXR_data,IO_ADDRESS(DXR_ADDR)); ) U. t ?( C5 R8 B
return 0;, Z; X; A- H, x( Y+ M% j
. a" N" k; B0 n7 F: l4 k2 V}
. m6 o+ H$ t) Z' b& _+ p0 V* L: D' m' q/ s
static ssize_t mcbsp_read(struct file *filp,char *buf,size_t len,loff_t *off)1 v7 E# E+ r9 a% ?4 U/ \/ [* [
{ ; t7 g4 M8 ?# l2 B R/ d, f
DRR_data = ioread16(IO_ADDRESS(DRR_ADDR));
7 T2 M0 ^; S6 m9 e copy_to_user(buf,&DRR_data,len);
5 }. n, L, s0 S9 ?: G1 U6 E* v return 0;
3 V4 e; |0 E8 H1 P( J2 S+ F}
' O; c+ D& A/ ?; @; r; s# z0 u% H# T. W5 F
+ k+ k0 K. M9 N$ _
static struct file_operations mcbsp_fops=5 g Y2 w$ l3 z! @+ y Q& \2 V
{ `7 ?4 h; ]4 ~/ I* v
.owner=THIS_MODULE,
- U3 p' Y0 P- N9 C$ v0 }# n .open=mcbsp_open,! C+ P' X9 n' ?0 _0 z% ?1 s. H/ i$ S
.release=mcbsp_release,
3 |- @* E% u! `5 V; I9 T- a* }. K .write=mcbsp_write,! Z J! E: l7 Q1 N( r
.read=mcbsp_read,
( r( |& ~2 _3 i' K* q2 M};$ g3 s, l2 T2 v( K3 L9 w1 Z0 P
static int __init MCBSP_init(void)
( ~* V0 S! o& j* P{: ]% n/ \6 n% n3 k' s% ~- [
int ret;
) L8 E1 P- E" O7 D, |6 { unsigned int PINMUX1_REG_old;* m9 p# @) ?4 Z0 W0 {$ U. A
unsigned int PINMUX18_REG_old;/ I: c0 u/ |' a4 Z; l
unsigned int PINMUX19_REG_old;* H6 [, L( r- C7 ]) E
unsigned int temp;
# h: B& R8 s5 W; ^* b if(MCBSP_MAJOR)3 |: z$ Z _4 d8 R( Q* F6 q Z
{
, |' [% I5 O/ N/ v mcbsp_dev=MKDEV(MCBSP_MAJOR,MCBSP_MINOR);
* v' T8 Y. A( m1 x6 k$ r) y ret=register_chrdev_region(mcbsp_dev,count,MCBSP_NAME);
, b" O% ^: r. S, { }! t5 D, i0 \( C% G0 W$ R, _0 S" f
else
' ]$ c% O% M" e {: \, X/ s- M0 t" |
ret=alloc_chrdev_region(&mcbsp_dev,MCBSP_MINOR,count,MCBSP_NAME);0 U5 `* g" z. p" Q) C d- f
MCBSP_MAJOR=MAJOR(mcbsp_dev);8 _& q9 Q$ R) H! w5 m5 _
}
8 s" z& v$ ~) X- `. R
1 Q, n# O3 g+ t( @( w! t if(ret<0)+ }3 H' i5 ^2 \( A: L) t8 ?/ |: I
{4 k( A0 z9 Q3 t. G1 s& P
printk(KERN_ERR "register chrdev fail!");9 o2 m4 F, {% C" J( m
return -1;( E- O$ Q a/ k% R W& t- Z8 E( S
}
1 l4 K# ]7 N- ]2 K
9 w9 P/ U- b3 B" K4 L+ P b mcbsp_cdev=cdev_alloc();
2 U* I" V/ {- K9 a9 q; h6 A6 d/ i9 s / ^9 k- E E1 B* h2 r/ t
if(mcbsp_cdev!=NULL)
# {9 t2 d: Z U) U {5 h u$ ` @5 U2 A- |& [9 i0 V
cdev_init(mcbsp_cdev,&mcbsp_fops);5 A$ H f1 V0 q+ x& c6 a* S% u' m7 G
mcbsp_cdev->ops=&mcbsp_fops;- N m7 b0 U# k( L
mcbsp_cdev->owner=THIS_MODULE;
. T) p* v+ @. F- f# L _- Q9 ~7 A+ Y- k
if(cdev_add(mcbsp_cdev,mcbsp_dev,count)), F O4 h5 L- c3 \
printk(KERN_ERR "register cdev fail!");0 h& A8 o% I6 @& T: u S/ K
else# ~5 M- C, {" B1 p' q+ x2 F
printk(KERN_ERR "register success!\n");
/ L B8 U2 {# Y3 l. I8 l0 n }. t# l2 B1 u" B9 P# m8 U
else
: y1 P9 ~& e9 G/ o7 ^, a) { {( |7 t1 Y5 h5 |) N
printk(KERN_ERR "register cdev err!");
* o6 l% y5 M, A, c! E" F. t7 d return -1;$ y# u: o5 t0 N% M
}0 y1 v0 _4 f6 P6 U
7 ?2 r/ r, q7 c* V# B2 r mcbsp_class=class_create(THIS_MODULE,MCBSP_NAME);
* ~: m0 W ]; C7 q/ p( j9 ` ~7 q if(IS_ERR(mcbsp_class))
; a. y7 j/ f- k: } {3 C9 \; _5 D/ j: H& Z
printk(KERN_ERR "register class err!");8 Q$ p" W& u4 c: ^9 p
return -1;; y# T3 ~% E8 [
}
( B U6 j/ V: C2 t4 G5 D device_create(mcbsp_class,NULL,mcbsp_dev,NULL,MCBSP_NAME);
" z; X* }% F" N- r" a
+ F+ N1 n# w) i# { //PSC$ b6 z, \$ D* H: @& ^* v, J
//add Enable MCBSP
& p/ f5 [$ c7 ?$ r5 D //test
$ T i( `2 C4 U1 B7 _- M) }+ z+ I temp = 0x80000003;4 G$ {3 I' {! {! S7 H
writel(temp, IO_ADDRESS(MDCTL15_ADDR));: n3 Y/ c7 N/ M# _' V
temp = 0x00000003;6 |0 E& z! [. B" |! b" i. g+ X
writel(temp, IO_ADDRESS(PTCMD_ADDR));
/ {% \4 W3 v& Y 2 d9 {8 i& r8 Y3 T0 D
temp = 0x001FF201;
% j# n, E: P: T" m; Z/ _( a writel(temp, IO_ADDRESS(PDCTL1_ADDR));
4 l) B# m# f; ]( c- o
, e' {" @0 a& ~& v$ O( g$ e //PINMUX
% D( j5 h! |* X6 o2 U! H- l+ T //MCBSP_CLK(receive/send),MCBSP_STRB(receive/send),MCBSP_DX,MCBSP_DR,
% w0 K# s, [; o, [& I N0 z9 D PINMUX1_REG_old=readl(IO_ADDRESS(SYSCFG_BASE)+PINMUX1_OFFSET);
' H& W6 c- I8 |' b2 _4 Z PINMUX1_REG_old=(PINMUX1_REG_old&0xf000000f)|0x02222220; / x1 I% j9 T- o" b( j* r
writel(PINMUX1_REG_old, IO_ADDRESS(SYSCFG_BASE)+PINMUX1_OFFSET);& d: x9 u9 e- ~
7 t* W6 Z( O; x
//SLEEP_EN,EPR,L138_SHK1,L138_RC
) _: d6 b8 r* X& W. i |4 \ PINMUX18_REG_old=readl(IO_ADDRESS(SYSCFG_BASE)+PINMUX18_OFFSET); , Z- N1 | ]& v! U4 N
PINMUX18_REG_old=(PINMUX18_REG_old&0x0000ffff)|0x88880000;
4 [7 _4 l% A% Z/ ^, ] writel(PINMUX18_REG_old, IO_ADDRESS(SYSCFG_BASE)+PINMUX18_OFFSET);
2 ^. f, U0 \; j; y$ v" n
# B! m& @, Q& C4 C9 d. @5 [ //RESETn,L138_SHK2
1 u8 y" c9 f; G/ z PINMUX19_REG_old=readl(IO_ADDRESS(SYSCFG_BASE)+PINMUX19_OFFSET);
% a5 S( @$ H/ b* d4 n# S PINMUX19_REG_old=(PINMUX19_REG_old&0xf0ffff0f)|0x08000080; # L6 C& Y G' q m& L9 U9 r( y
writel(PINMUX19_REG_old, IO_ADDRESS(SYSCFG_BASE)+PINMUX19_OFFSET);* R7 R1 Z; Z& Z/ O& G* V$ l% J, K
0 L8 ]+ A/ Z$ y6 z) f0 {, ? ) ?5 m# o7 i- j, }8 {$ \
//SPCR Register4 ^" D3 p+ _% r' F
//FREE-1,SOFT-1,FRST-0,GRST-0,XRST-0,RRST-0,RJUST-00(Zero-fill MSBs)reset! U( E1 k7 F) J) G3 M
temp = 0x03000000;//(DLB=0)
2 i: n2 W& ?0 ~$ U( s5 B. S // temp = 0x03008000;//(DLB=1)
, {' w- Y- }4 x+ `% t' N writel(temp,IO_ADDRESS(SPCR_ADDR)); //reset
, r+ `" j# q0 u) g! v- a temp = readl(IO_ADDRESS(SPCR_ADDR));; i" P7 E6 R) E. C- g
printk("temp=%x\n",temp);
6 J' _7 D- f8 ?3 k9 h# z; L
* ]% i) j" }: z- }3 p* d& P //PCR Register% [' V- |% D, _5 I2 E0 M" j7 B
//FSXM-1,FSRM-1,CLKXM-1,CLKRM-1,SCLKME-0,FSXP-0,FSRP-0,CLKXP-0,CLKRP-0
U! Q1 g& w, x1 \' z% |+ ]0 S+ q // temp = 0x00000F0F;
( ^2 n6 F# ^5 x3 o* {. r temp = 0x00000B0F;( H) [6 N' \; @, {' k
writel(temp,IO_ADDRESS(PCR_ADDR)); //initialized
% N. P8 Q, l6 z( [2 j8 a temp = readl(IO_ADDRESS(PCR_ADDR));
& h% W( `+ P: S' x) D3 e, }* L printk("temp=%x\n",temp); 7 u/ Y2 `" u) k
//SRGR Register
?' E9 I+ i k4 ~& a1 J6 u //GSYNC-0,CLKSP-0,CLKSM-1,FPER-31,FWID-0,CLKGDV==11
# e; L) Z7 U' ], I //temp = 0x301F000B;
7 S+ @- \; m. T& K+ y writel(0x0301F000B,IO_ADDRESS(SRGR_ADDR)); //initialized 3 C3 t3 y) ?: S
temp = readl(IO_ADDRESS(SRGR_ADDR));6 L3 W7 V6 S* A7 ~( Z1 R& u
printk("temp=%x\n",temp);
& n" ~; k. u' A& {' ` //RCR4 |+ U W3 O+ L
//RPHASE-0,RFRLEN2-0,RWDLEN2-2,RCOMPAND-0,RFIG-1,
n. p7 e% G, V1 h0 L: e7 f //RDATDLY-0,RFRLEN1-0,RWDLEN1-2,RWDREVRS-0
3 r! d* b8 W$ Z) }/ t' v temp = 0x00440040;7 @( [" t2 ^" M* t
writel(temp,IO_ADDRESS(RCR_ADDR)); //initialized 6 ]" [( \' h2 J, [$ h" @' S
temp = readl(IO_ADDRESS(RCR_ADDR));; q/ f& v3 G- J0 F. E" Y
printk("temp=%x\n",temp); H* U5 B4 }* n- V. z8 e) `
//XCR2 p% T Q- b( j/ g
//XPHASE-0,XFRLEN2-0,XWDLEN2-2,XCOMPAND-0,XFIG-1
7 P% A3 p1 ?6 W1 ^6 }$ Q: Z* K //XDATDLY-0,XFRLEN1-0,XWDLEN1-2,XWDREVRS-0
5 u: m7 d/ _9 Y temp = 0x00440040;/ X1 c$ ^5 d# d" b) W( ]
writel(temp,IO_ADDRESS(XCR_ADDR)); //initialized
+ `7 v7 H- o5 f temp = readl(IO_ADDRESS(XCR_ADDR));. N+ \* f6 i& z+ Q1 j& c) z3 D
printk("temp=%x\n",temp);
) O5 J. r% V' `& R/ G; c) [* [ udelay(100);
$ i# K) T' h4 b# D2 c' N //SPCR Register
, p1 L6 Y+ k3 y: ~ Q- e6 z7 _1 | //FREE-1,SOFT-1,FRST-1,GRST-1,XRST-1,RRST-10 d$ @8 \9 L/ I ^
temp = 0x03C10001; //DLB = 0 VS DLB = 1
1 G& a2 A# P& @( X writel(temp,IO_ADDRESS(SPCR_ADDR)); //enabled
4 O& V8 C5 b# b5 u2 U1 `5 h ]) u temp = readl(IO_ADDRESS(SPCR_ADDR));6 Y8 q* h) r+ K; {
printk("temp=%x\n",temp);
. R; }( h9 z. P2 a udelay(100);( _7 u6 w. b$ B+ \% b# Z0 Q
5 \/ @ c! P9 M3 Y0 S# t% c
//set GPIO direction3 `2 y$ l9 U& U9 P' _; `; y8 U0 G
temp = __raw_readl(IO_ADDRESS(GPIO8_DIRECT));# v/ ?5 g# F h8 J
temp = temp | 0x00000100;//EPR----input* |$ H8 x' _0 f+ B( ]' E
temp = temp&(~0x00000500);//RESETn,SLEEP_EN---output
6 ~% A' l/ L# |) Z( _: @ __raw_writel(temp,IO_ADDRESS(GPIO8_DIRECT));
4 }- v# ]- L7 v. S( D 4 Q* r4 @+ Y' X& |9 F- B8 t% _7 }
return 0;
1 R7 h5 Y8 m1 Z}
0 _# g0 ~& }! y) R+ pstatic void __exit MCBSP_exit(void)3 G2 N" ?, ]' x7 g
{
: h# C& A: G& K6 u4 g# R/ D4 k! n1 ?2 p printk("mcbsp chrdev exit!\n");
+ y+ @3 ]; j" d, n0 V cdev_del(mcbsp_cdev);+ l, n9 _( \) i" Q5 m8 N
unregister_chrdev_region(mcbsp_dev,count);* }- W. Y/ I' N: T* C0 G- [! M
device_destroy(mcbsp_class,mcbsp_dev);' @( o5 q5 m9 V
class_destroy(mcbsp_class);0 b8 p' A( Q, w; _. r0 u
}
7 u) B8 J2 j% V2 o' M$ xmodule_init(MCBSP_init);
) R. a8 \! x$ zmodule_exit(MCBSP_exit);8 Q0 o9 `% b; A! u! U8 ?8 g$ Z
) x& \: t" O4 b P9 C
MODULE_LICENSE("GPL");, @5 g# V2 P& T
2 q, j( R" o0 V G9 y
我讲上面的程序insmod之后我用示波器量 McBSP的发送时钟脚,发送数据脚(我还没有发送数据)以及发送同步脚,3个脚的信号是一样的,不管是用我自己的底板测试还是用创龙OMAPL38 的开发板测试,都是一样的,类似于噪声的信号时钟频率也不对。/ p) H. ~$ b' u5 r( i( M B
我的应用层的测试程序如下
7 D7 Z/ j5 L0 I/ R7 n0 A#include <stdio.h>* v( D9 e( o9 M0 B+ h4 Y
#include <string.h> s w1 l ^" b/ ], ]+ S) _0 I
#include <fcntl.h>
1 d7 A0 b0 l2 o0 C% M#include <unistd.h>- A3 E0 s: e' K/ }; w
#include <signal.h>
% m: u* R: w ^: t' c9 T#include <pthread.h> //线程' B6 \- L1 I3 |% {* ^
#include <stdlib.h>! ~0 `4 `+ \# i# m( h/ C
#include <pcap.h> //捕获网口数据
/ n& H1 s6 m, F9 m/ \3 S#include <semaphore.h> //信号
" ^4 H `2 O! c#include <sys/types.h> //消息对列
% U+ b' N: d3 ^3 h" z#include <sys/ipc.h> //消息队列
- g8 x |: J' @, _; r# h3 N8 s; `, H#include <sys/msg.h> //消息队列
) I6 H. \* M8 W2 `6 o4 V#include <sys/select.h>* k4 B3 y! A9 y8 N% I) a! k3 z
#include <sys/syscall.h>
8 v- v4 |) Q4 {2 f- N( {" r#include <sys/stat.h>
( l9 K# Z1 y. G- Y+ D#include <sys/mman.h>0 H8 w% [; U) Q7 E4 H5 G
#define msleep(x) usleep(1000*x)
, [7 h2 I+ `/ Z4 D+ _
1 p, E( N2 j+ K7 e0 u, V" R/ n2 Fint main()
; R: O# P* |1 C4 x# D{ q; L! S0 m/ _
//MCBSP,ARM与AMBE2000交互设备/ R8 d; n& r) B" O# q
int fd;
+ K4 Q- |1 l. v2 J% C5 R! ~ unsigned short data_write = 0x5555;
0 l7 L) x. B5 [) g o unsigned short data_read = 0x00;8 _/ g/ {( {, Z. I' a# ^& [
fd = open("/dev/MCBSP-device", O_RDWR | O_NONBLOCK | O_SYNC);( w# ]! w$ R" a. e" U
// fd = open("/dev/led-device", O_RDWR | O_NONBLOCK | O_SYNC);
/ Q" s C, c1 K) y! x9 F& ? 4 F0 J V0 o4 q* q
if(fd < 0)' ~: ^) I& c B* f
{
$ s3 O$ V( c i* F# x/ { perror("open failed\n");
+ w; Q" I/ J) J return -1;
6 H+ k1 Y* N( D+ L- ` }1 l" F5 M! O# a% M" V2 a
2 z( e* ^2 S. u; ^% k8 v while(1)6 O5 d, U8 a2 G, L+ j; d
{3 n/ {8 g. ]' m1 A, u& _# i4 c
6 e# m# h! V' o- J2 m& N) f //AMBE2000每次读写是24个字为一帧# L1 l, [7 c. y6 u
//写数据时将数据在底层存储起来,等到中断的时候再发送
]( T" W) A1 S, C5 p [/ p //AMBE2000输入数据是以0x13EC开头的6 p% y' L# Y/ M, f4 \
write(fd,&data_write,sizeof(unsigned short));
; N6 q( L' y, e" `0 @, q7 m
+ ]+ H7 V1 K. `$ Z //读数据的时候,在底层中断中将接收到的数据存储起来,然后再传送到应用层
* @9 K- Q8 G1 {: ] G read(fd,&data_read,sizeof(unsigned short));" `: R, s( m$ t* b7 e! Q& B
: k: @* r, ]1 u& {5 c& L$ ?
if(data_read == 0x13Ec)
5 a& w% t/ J4 |- a {
~. W! i" p% e$ g
' |. C. k% \/ {/ _7 {5 T) Y printf("data_read = %x\n",data_read);8 @1 ?# i! [" L0 ?
}
: x- @- q7 K! R* Q5 e5 k7 m8 n1 u - _) c) S4 H" j5 _/ Z
msleep(10);! ^7 o. j y+ `, a/ ^6 y
5 k3 `6 p' i' A% b4 c& _ /*
6 u( g7 ?. Q( R$ z4 h% V ioctl(fd,1); # v, L6 T9 |0 s$ w) t7 j
sleep(1);. I) b0 c* F9 K5 q; y: O
ioctl(fd,0);6 l8 j+ q. A' ?' M$ s& s
sleep(1);
F9 W# ]# H k8 W7 I# O */
- [8 A$ a% `& y f }
& c6 B) U9 Y- k$ p# c7 S# ] return 0;
" d% E9 d4 l# S! F) Q2 o! w
5 Q" s9 d5 A: N4 }1 M}
! S: U% y1 F' q) ]: o- U7 [ C$ O V9 V
多谢各位指教,谢谢! 急& V) M7 v. |6 E& o
) q0 c6 C5 p2 ]" W: I- @7 B* r, B7 c0 L5 N6 }8 u8 v7 y3 Q
% F/ N1 j+ \4 i- k' r" K
! o ~5 e3 ~9 w3 O0 i6 \ Z% Y+ W1 q2 @
|
|