|
|
我讲创龙在DSP中使用的例子移植到ARM中,如下是我的底层驱动程序: + M; h' |6 N$ A i
/*
5 U1 U( `! x! f4 D" E0 ~% y. h, _' T$ m * Copyright (C) 2009 Texas Instruments Inc0 I. Z4 t& ]. {6 l J2 C
*7 S' j# ^* I/ h; V
* This program is free software; you can redistribute it and/or modify
5 W; D5 b) {1 H& ?1 x$ i * it under the terms of the GNU General Public License as published by, k) A- E$ ^0 t8 [
* the Free Software Foundation; either version 2 of the License, or6 ?3 \3 _+ J$ c: N' P6 k! ]
* (at your option)any later version.
( p7 f3 H2 [/ l: P- U* p) t( y *
( y: }: u' T) | * This program is distributed in the hope that it will be useful,
5 z+ m* K* u4 t6 Y* U0 s+ l1 D * but WITHOUT ANY WARRANTY; without even the implied warranty of: s' z5 d4 |0 i- S/ N
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the" @# y1 Q6 X; I2 y3 @$ o: j7 M1 o
* GNU General Public License for more details.1 r) h! E! l9 T# l, Q' n
*6 h8 U4 y# z$ G0 }! S4 T
* You should have received a copy of the GNU General Public License
, H- P7 A: Q" m3 Z# P# U3 x * along with this program; if not, write to the Free Software+ X5 m; c3 Y5 `% y/ W$ P
* Foundati5 O# k, O, \* c: \5 k
*/
# B" b, u. N+ p! k2 n1 `! o8 ~#include <linux/module.h>
5 R, {) L# y+ u+ b$ v/ k4 p% ?#include <linux/init.h>
# b7 @% l, Z9 t) _0 G5 l#include <linux/errno.h>* C; x e4 B) I3 [( }8 }0 I0 c+ O1 _
#include <linux/types.h>4 {# p4 S2 P/ O( E. R0 |
#include <linux/interrupt.h>
, X3 [3 N$ x3 B; h. ?#include <linux/io.h>
% x9 H! U6 S" ^4 {5 ~/ Q$ t#include <linux/sysctl.h>
1 x6 A+ h, g: Q: I }0 a' Z, a' \#include <linux/mm.h>& Z7 D" |6 C1 b3 p; H
#include <linux/delay.h>( c' h! n9 q t6 i! O
#include<linux/kernel.h># ] z* W6 o8 ?* ~( D, ]
#include<linux/fs.h>
8 q4 H6 ]2 i& T' G4 {6 z#include<linux/ioctl.h>2 e, w9 M; x6 b+ q
#include<linux/cdev.h>
{1 c' A+ b0 J: k. s#include<linux/kdev_t.h>
r; K. ^! A+ n& ?; Q#include<linux/gpio.h>) P! s: q b. A0 R9 z6 {
#include <mach/hardware.h>
6 g, E1 c3 m: Q( n$ w: {5 r#include <mach/irqs.h>4 _( n9 j# r# S' P
' W5 L5 v) J. Z% `4 X A#include <asm/mach-types.h>
! V/ p+ k- E7 _#include <asm/mach/arch.h>/ ]# H# f* {* D- a- t" U: ]# ?: x
#include <mach/da8xx.h>
, t4 W/ @& @4 c% I: r#define SYSCFG_BASE 0x01c140003 u# a" ~' y( R5 l Z
#define PINMUX1_OFFSET 0x124 4 }$ b8 J3 V: u/ k) _0 E
#define PINMUX18_OFFSET 0x168 % c/ x6 d; e2 k) _# @) m
#define PINMUX19_OFFSET 0x16c
7 X9 t* z8 [4 C( A0 l5 g# y#define SPCR_ADDR 0x01D11008 //MCBSP1_SPCR
3 ^! w4 u" q2 g% D: K2 g#define RCR_ADDR 0x01D1100C //MCBSP1_RCR
& B! B# A- B; Y2 D( X#define XCR_ADDR 0x01D11010 //MCBSP1_XCR
* ?& h$ X5 A9 S#define SRGR_ADDR 0x01D11014 //MCBSP1_SRGR8 P* @; U0 M( e T( a
#define PCR_ADDR 0x01D11024 //MCBSP1_PCR
5 m" M5 b" }; \5 O! E2 P- }
9 k$ m- N5 a! G& P3 k+ D9 p5 X#define DXR_ADDR 0x01D11004 //MCBSP1_DXR4 C2 ~% z, _' h/ A- U6 x
#define DRR_ADDR 0x01D11000 //MCBSP1_DRR
7 [: x9 Q+ c/ _! O//PSC
8 {- j& K6 t4 E0 m! q9 G$ h8 D4 d#define PTCMD_ADDR 0x01E27120
6 L6 E) I- V% K- [8 G9 V#define MDCTL15_ADDR 0x01E27A3C
+ r0 O% x% P9 T#define PDCTL1_ADDR 0x01E27304
$ U, ]3 e2 _, h$ M4 E8 C/ p//GPIO8 direction7 q/ _6 Y! h* k
#define GPIO8_DIRECT 0x01E260B0
% n* [7 b; E( @% Y, U% U: |#define GPIO8_OUT 0x01E260B4) E/ A, G. n, L3 F3 L$ T
#define GPIO8_IN 0x01E260C0
4 Z: q, B" @8 a. j
& L+ w9 j2 F& D# e* w# V//#define MCBSP1_RINT 99 ! W4 l/ _/ P4 D( x' {( Y
//#define MCBSP1_XINT 100 . v; q4 u$ d3 G+ o1 i0 r
static int MCBSP_MAJOR=239;
! e& q+ t% l1 E9 I- `static int MCBSP_MINOR=0;$ f9 h& [7 e/ C6 B
static int count =1;* S f, i! Y4 t& t; u3 x$ l, |; G0 l- |
2 C$ q3 L# ~5 d9 C2 q9 \#define MCBSP_NAME "MCBSP-device"
( W$ {+ V" ~5 r* i* v" u8 k' b" a' Y
9 s( |. H: `$ U' U0 G5 Mstatic struct cdev *mcbsp_cdev;& j* b* ?5 V4 a* d, F, Z7 Q
static struct class *mcbsp_class;7 n& Y% N' c& S6 K1 p. U
static dev_t mcbsp_dev;- e9 z- j% A) k( d1 A
unsigned int DRR_data;, [. _/ q) G" W3 K0 p
unsigned int DXR_data; s8 M: N& | X/ m( d- d9 f6 s; Y
static int mcbsp_open(struct inode *inode,struct file *file)2 P" E7 \/ U' K6 S
{
4 \- N# i( }, E4 O . i u7 X( W* x) p0 j% i- Q
//interrupt enable,initialized
1 U, F/ f3 D1 M9 ] unsigned int temp;
: Q! h8 ^& _! I2 p6 _/ A //SLEEP_EN(GPIO8[10])---0- F- R9 n5 Z/ B) }
temp = __raw_readl(IO_ADDRESS(GPIO8_OUT));2 l5 q/ N! O; e# X i
temp=temp&(~0x00000400);
0 |( u& w, C9 @# I __raw_writel(temp,IO_ADDRESS(GPIO8_OUT));//GPIO8[10]
" s2 {- p5 _5 t- A/ p //RESETn(GPIO8[8])----0----19 G) Y) i& \% ^, _* ~6 ~
temp = __raw_readl(IO_ADDRESS(GPIO8_OUT));* J/ @, H* j/ K
temp=temp&(~0x00000100);' m% T2 t- D3 q# K; k, z7 M; \2 X: ~
__raw_writel(temp,IO_ADDRESS(GPIO8_OUT));//GPIO8[8]---0
' `2 s/ m& M, X: ]$ r udelay(100);- t. v, v. [0 Z* X4 P
temp=temp| 0x00000100;
5 d y0 q) _ k+ r" N __raw_writel(temp,IO_ADDRESS(GPIO8_OUT));//GPIO8[8]---1
/ ?* l. Z& u1 c2 j) o2 n6 ` udelay(100);. }1 u H" m4 C7 p! g1 f" u
printk("open success!\n");- s* d1 k- b- b! q: v1 ?" k
return 0;, [' ~. |! D# M! c
}
, b- J! F5 J1 _
@; G( i4 j0 m, b, K- `static int mcbsp_release(struct inode *inode,struct file *file)2 {7 ^! q" l }' w. A/ i' D8 A
{$ v8 S% _4 W, N# u9 ]% a( }- U% K
printk("release success!\n");
: \; l' r0 {& O" u9 ^/ o return 0;% C, `4 H0 O# E4 T& E) c* n; u
}
' t, {7 C* D2 E: _- w& ]7 s+ d+ C8 m3 W; S, G- }( s
static ssize_t mcbsp_write(struct file *filp,const char *buf,size_t len,loff_t *off)
2 t, ?5 J+ x$ \2 C Y3 Y{" h7 M8 t& j* R$ m3 K8 C
copy_from_user(&DXR_data,buf,len);9 C- L8 g7 _/ r* w/ H# W
iowrite32(DXR_data,IO_ADDRESS(DXR_ADDR));
% E; U. {& O! i( @) v3 p return 0;- d1 i% e; O8 Q' Q
" z! [/ W1 f4 b- C, }}: V* z. p m: {9 _: i
! i3 s+ [( T; P+ {& O8 N
static ssize_t mcbsp_read(struct file *filp,char *buf,size_t len,loff_t *off)! F+ m+ v: R9 w6 w5 S
{
. u1 r; o: g9 {9 n+ n% _ DRR_data = ioread16(IO_ADDRESS(DRR_ADDR));
1 p# W4 x$ C0 Z# Q4 Q! Q copy_to_user(buf,&DRR_data,len);
& b& a+ R0 M3 f4 t return 0;4 n! l* `0 I6 T! d2 d
}- i0 {0 g( @, @- _! M3 Z6 p. U7 c
5 k4 V6 H# e* o. u
: y/ e2 S# I* D8 ?0 P- t; Mstatic struct file_operations mcbsp_fops=
& D- }5 G: W/ B% v# ~{
$ a3 z% I: w) J0 X. `$ i# K$ U9 y! U .owner=THIS_MODULE,( G, m; ^+ k: ~2 w1 p V* c# R
.open=mcbsp_open,: x' t7 G+ U; F, W$ y1 |0 r: o
.release=mcbsp_release,
. C9 r% b1 Q3 u1 Z" l1 _" f .write=mcbsp_write,
) q5 Z3 O$ A+ W% P) V .read=mcbsp_read,
; K* m1 q) q% F) Q- v B};
2 U9 A' o+ r/ \7 Zstatic int __init MCBSP_init(void)+ {8 D5 d, J! q4 E
{; R) \! v4 X# s& c; X7 `% m
int ret;1 Z6 ?0 D* T2 b2 x* y0 c2 {
unsigned int PINMUX1_REG_old;
+ C6 h0 N2 ~9 X2 L Z0 d unsigned int PINMUX18_REG_old;% e% E+ }& y. J) d b8 X1 D; W
unsigned int PINMUX19_REG_old;; o' H" l0 i8 A, J( t- o1 J" g
unsigned int temp; . a6 ^5 [0 w7 X0 y1 g; N
if(MCBSP_MAJOR)3 T2 F6 j9 A5 x; k; ~% F
{; z; e. y" q6 ]' O
mcbsp_dev=MKDEV(MCBSP_MAJOR,MCBSP_MINOR);) a# H6 f- o4 e4 u( D
ret=register_chrdev_region(mcbsp_dev,count,MCBSP_NAME);% T \. }! I9 C5 Z8 A, F
}
. w. g. s2 Y2 u8 z9 {1 _ else# {5 ?$ ~ f" V
{
$ l9 p, [$ f: K. G5 d0 l2 i9 v ret=alloc_chrdev_region(&mcbsp_dev,MCBSP_MINOR,count,MCBSP_NAME);$ o c q3 o- M! x5 C% w
MCBSP_MAJOR=MAJOR(mcbsp_dev);
. }) _& y0 ~7 W* G2 Q* m+ { }
& r$ J1 V2 x* k 8 W6 P7 g/ k1 v9 a7 p$ D
if(ret<0)
% a8 Z% f% C% `( l {
+ _$ w4 s% s7 L printk(KERN_ERR "register chrdev fail!");
" p8 I, M2 f" L/ O4 b: V return -1;% Y4 l) ~! }- d! o4 T9 w5 r O
}1 u3 e+ D8 t+ E# {( g" k( G
8 |0 v6 T) c$ x# ]1 a7 @
mcbsp_cdev=cdev_alloc();
) }$ W$ i. x6 h% ]' \) K7 k# J
& K' e' U/ b3 S# I+ | if(mcbsp_cdev!=NULL)7 G* h" c9 O$ |5 v( R
{& U& w1 t# l8 {: r' h' i4 Y
cdev_init(mcbsp_cdev,&mcbsp_fops);
. _3 j; K; C( A mcbsp_cdev->ops=&mcbsp_fops;. o# G9 o: n8 M p
mcbsp_cdev->owner=THIS_MODULE;
# a: X) B1 n% z9 a/ C! @ . S% R' R- k' X! {
if(cdev_add(mcbsp_cdev,mcbsp_dev,count))
" Q" V# Q* Q; K3 a printk(KERN_ERR "register cdev fail!");8 }. y: w4 l6 z
else; K1 } m( o+ H5 y5 p3 S
printk(KERN_ERR "register success!\n");; S7 Z0 N2 g, y$ B& D
}! E2 a7 M3 L& K) r+ v$ C& H3 N' ]3 A; t
else
0 d6 |8 `8 ?* U# u {
$ d2 o# b5 v- D& s1 L. C* { printk(KERN_ERR "register cdev err!");
& x2 D- t: |) D return -1;
! E8 O0 W3 Q* [5 s. E6 ? }
% [% K8 n( I$ j' @( D% D$ B( C4 g 5 y6 Y) r5 k6 d& A' c `% ~0 b, m
mcbsp_class=class_create(THIS_MODULE,MCBSP_NAME);9 ?! b6 ~* | u& F$ B- F7 T
if(IS_ERR(mcbsp_class))
& g2 @% N" x, i1 K0 h7 F3 | {
; L- J( @5 h) I( S5 [5 C1 d& a3 ~1 v printk(KERN_ERR "register class err!");/ r% G" h7 t: ?+ b/ N
return -1;
- a6 d6 x' p5 M$ @% t- ? }+ F* F0 L+ `! d/ w9 W5 P
device_create(mcbsp_class,NULL,mcbsp_dev,NULL,MCBSP_NAME);; G- l) @1 d) }2 q
) k7 S3 v$ K$ J' ?3 a/ } //PSC4 i% U) X6 V5 ?- k
//add Enable MCBSP
+ v4 Z9 u7 C7 i6 v) ^2 e( d% x //test
( r( e9 v, Y5 Z% V/ x% ^1 Q; Y temp = 0x80000003;* i M8 K5 L5 @+ J, q9 H
writel(temp, IO_ADDRESS(MDCTL15_ADDR));+ K4 t# D5 N7 W% d, r) @) R- `
temp = 0x00000003;
6 `% G/ _6 i7 Z! d0 G% c writel(temp, IO_ADDRESS(PTCMD_ADDR));
) r4 m- I) |) z" V 5 [( J1 H# E O
temp = 0x001FF201;
0 g# g M% l: k8 M writel(temp, IO_ADDRESS(PDCTL1_ADDR));9 _" k0 }1 @6 ?- j
) d( m, C( o. J X
//PINMUX
0 R. Y& B8 W8 s% o/ I9 b //MCBSP_CLK(receive/send),MCBSP_STRB(receive/send),MCBSP_DX,MCBSP_DR,# O7 R4 C/ ]$ u5 p; w
PINMUX1_REG_old=readl(IO_ADDRESS(SYSCFG_BASE)+PINMUX1_OFFSET);
* }. O1 }; Y3 o# [$ D0 y PINMUX1_REG_old=(PINMUX1_REG_old&0xf000000f)|0x02222220;
" A; K p1 u3 F" M writel(PINMUX1_REG_old, IO_ADDRESS(SYSCFG_BASE)+PINMUX1_OFFSET);
( b6 _9 r/ S- I# b3 E1 c# M 1 M% V" \# u, d+ s7 B
//SLEEP_EN,EPR,L138_SHK1,L138_RC! H# J6 ~* Q( f4 n0 `! M1 A
PINMUX18_REG_old=readl(IO_ADDRESS(SYSCFG_BASE)+PINMUX18_OFFSET);
4 p H) \4 n& Z% u, r PINMUX18_REG_old=(PINMUX18_REG_old&0x0000ffff)|0x88880000;
5 h4 Y7 G# u: p& ?* g( c writel(PINMUX18_REG_old, IO_ADDRESS(SYSCFG_BASE)+PINMUX18_OFFSET);
6 h% @8 Z) b2 ]8 ^
; y2 A3 S- ]$ N `0 b //RESETn,L138_SHK2; J% O: V0 g( \9 o# V
PINMUX19_REG_old=readl(IO_ADDRESS(SYSCFG_BASE)+PINMUX19_OFFSET);
* d! F) S" t/ N" ~3 C+ t PINMUX19_REG_old=(PINMUX19_REG_old&0xf0ffff0f)|0x08000080;
D' V. J0 D8 F writel(PINMUX19_REG_old, IO_ADDRESS(SYSCFG_BASE)+PINMUX19_OFFSET);
8 ?* g, a. H. |' F
) y8 _4 s6 m+ j2 Q9 N* {& K0 M
8 E1 t5 O. [) Z O8 {( z1 f) ~ //SPCR Register Y3 |( e" v4 G# O
//FREE-1,SOFT-1,FRST-0,GRST-0,XRST-0,RRST-0,RJUST-00(Zero-fill MSBs)reset
, `& F& @+ @( m6 }9 d- E& Y temp = 0x03000000;//(DLB=0)
! K U+ t, R i // temp = 0x03008000;//(DLB=1)
, L4 m8 A3 I+ ^& V7 Q) T: \0 ~ writel(temp,IO_ADDRESS(SPCR_ADDR)); //reset& E- y& `7 c5 ^
temp = readl(IO_ADDRESS(SPCR_ADDR));( F+ g" e- |8 z- x2 [
printk("temp=%x\n",temp);
7 r r7 E1 t' e
& H- S7 l9 j4 M, u& j6 J( O //PCR Register- h2 |8 A- I! b+ A8 d' @- p
//FSXM-1,FSRM-1,CLKXM-1,CLKRM-1,SCLKME-0,FSXP-0,FSRP-0,CLKXP-0,CLKRP-03 @! c" L8 L- d
// temp = 0x00000F0F;6 n% _" ]4 E6 ~( I9 ~
temp = 0x00000B0F;
( V! e% p( w5 S* e writel(temp,IO_ADDRESS(PCR_ADDR)); //initialized |' g3 f2 X$ I' z; X3 f1 E
temp = readl(IO_ADDRESS(PCR_ADDR));3 [3 H8 E p1 e2 h0 B" I
printk("temp=%x\n",temp); / a! N' P9 P" r4 u8 w8 s1 l9 a
//SRGR Register
8 k" Y3 |( f3 P Y' J; s& [ //GSYNC-0,CLKSP-0,CLKSM-1,FPER-31,FWID-0,CLKGDV==11: N6 m" L6 m9 N7 v% R0 G1 c
//temp = 0x301F000B;# w- B- o: q; D) N( K' k1 @" y
writel(0x0301F000B,IO_ADDRESS(SRGR_ADDR)); //initialized
. G6 ?" a8 a3 _9 Q' j% L3 @ temp = readl(IO_ADDRESS(SRGR_ADDR));& u* @/ _& Q; s4 b2 l# F0 c. M, Z
printk("temp=%x\n",temp);
j" a1 v4 P" z/ P' ?, m //RCR
6 P# t! ~3 `" [" R0 q //RPHASE-0,RFRLEN2-0,RWDLEN2-2,RCOMPAND-0,RFIG-1,2 r* Q1 q- ?& s1 }" {
//RDATDLY-0,RFRLEN1-0,RWDLEN1-2,RWDREVRS-0& X5 x8 @; N4 {0 Y9 _: M5 n
temp = 0x00440040;
* [+ E& f/ z3 Y' ?: v7 m! Y4 x writel(temp,IO_ADDRESS(RCR_ADDR)); //initialized
* Q$ @! n2 R8 ?0 Y! I, E7 O temp = readl(IO_ADDRESS(RCR_ADDR));, ]9 x: U! m3 z1 u4 n
printk("temp=%x\n",temp);
/ w, w8 L% }8 z$ z' S. E3 S //XCR
+ t& `$ m9 i8 I //XPHASE-0,XFRLEN2-0,XWDLEN2-2,XCOMPAND-0,XFIG-16 |$ S V0 [% I; X7 w
//XDATDLY-0,XFRLEN1-0,XWDLEN1-2,XWDREVRS-09 B% Q2 S4 O* [' `
temp = 0x00440040;- f' ?( x% H3 q5 p0 K% |
writel(temp,IO_ADDRESS(XCR_ADDR)); //initialized
) s# ?4 i+ x& d temp = readl(IO_ADDRESS(XCR_ADDR));
& J( N1 R [4 A printk("temp=%x\n",temp);
+ v$ N* D8 C: J, S- K udelay(100);
+ g2 v9 N* n. I- f3 n& `: j8 O: o //SPCR Register
, \# k9 q9 Q- D* J //FREE-1,SOFT-1,FRST-1,GRST-1,XRST-1,RRST-1/ ?# {- e2 \( `9 B: n
temp = 0x03C10001; //DLB = 0 VS DLB = 1
( Q" E$ k! l' M/ ^' v. U writel(temp,IO_ADDRESS(SPCR_ADDR)); //enabled3 u* F# i% q+ z# ^, N Z; [
temp = readl(IO_ADDRESS(SPCR_ADDR));3 E+ t5 ^0 S5 ~( K
printk("temp=%x\n",temp);
1 V' u2 x6 v# q4 K. K- g6 _ udelay(100);
g1 a8 b- t. I# p+ }! J9 O* f/ J* K$ N" u3 v* @$ O! G
//set GPIO direction
9 O6 n; W- }- i: n# Z temp = __raw_readl(IO_ADDRESS(GPIO8_DIRECT));
2 P' G3 `; l( S0 ` s6 p temp = temp | 0x00000100;//EPR----input
1 w+ b3 B* N0 c- V9 }6 u temp = temp&(~0x00000500);//RESETn,SLEEP_EN---output5 x/ Q% e( t( `! N Z* f- l- x
__raw_writel(temp,IO_ADDRESS(GPIO8_DIRECT)); 6 K; H' m( c6 a" }% e7 P, L
x0 R# t5 ~0 D0 M9 z. X; y9 l
return 0;
* f: o; ?1 Q4 j% ]6 P- H}
0 @3 s2 [5 j+ K8 T/ q& u4 Zstatic void __exit MCBSP_exit(void)
; V0 b! E) M$ ]9 i+ m# y{3 \8 _0 ]+ o3 W" k* y' x
printk("mcbsp chrdev exit!\n");* U. x, k# G1 C6 x0 P. a! ]4 ^. w, P
cdev_del(mcbsp_cdev);
5 g& ]. i1 v1 U8 {( k- k/ I unregister_chrdev_region(mcbsp_dev,count);
: `1 U4 a7 A, ?- Q* j5 |8 z device_destroy(mcbsp_class,mcbsp_dev);
+ t" o! I( j) Y) H class_destroy(mcbsp_class);
8 }4 }$ `8 i8 S+ B9 ^' k}! w1 R5 ^9 ]$ E9 W+ h H* G6 D
module_init(MCBSP_init);
! x0 o- n2 J+ E0 a* Gmodule_exit(MCBSP_exit);
0 g; x D2 I G; d. U" S/ I4 N7 b% b5 M, S) D h, t o X5 e
MODULE_LICENSE("GPL");
5 k; L0 T) Y( o) R& `- e) H
0 C! D* V3 J; A; G0 I( Z1 y我讲上面的程序insmod之后我用示波器量 McBSP的发送时钟脚,发送数据脚(我还没有发送数据)以及发送同步脚,3个脚的信号是一样的,不管是用我自己的底板测试还是用创龙OMAPL38 的开发板测试,都是一样的,类似于噪声的信号时钟频率也不对。8 b7 w. }& J: }* A' q
我的应用层的测试程序如下
9 r) _2 O# P7 s6 n' [- O% t#include <stdio.h>- \! g# ], ^1 `5 [0 O
#include <string.h>
' E( {% Z$ m0 h+ i* ^6 ?#include <fcntl.h>3 h2 E; m, n" L7 \) U% H! K
#include <unistd.h># O; ?5 B V& b# \0 u S m2 ]
#include <signal.h>
/ n4 A+ A3 f5 j- H#include <pthread.h> //线程
# X' i6 h$ T; B& _' _0 j#include <stdlib.h># _2 [ D% f- V
#include <pcap.h> //捕获网口数据6 `! G- c$ d0 z$ e
#include <semaphore.h> //信号
# ~# Y4 B( [! Y. E#include <sys/types.h> //消息对列: K, [/ v; T& Z; R3 W" l% w
#include <sys/ipc.h> //消息队列; ?, x0 z0 Y* t. `& t. y
#include <sys/msg.h> //消息队列
5 H% s, K: [3 ^1 _) @5 A) f5 s#include <sys/select.h>
( r7 f; w5 e$ Z1 S5 ]5 e' O#include <sys/syscall.h>
4 X- B% N5 `& z* C8 V3 b#include <sys/stat.h>
1 h6 m4 L \1 ]6 M! M3 H#include <sys/mman.h>! H" I: f- {' X* c
#define msleep(x) usleep(1000*x)! M) T; |7 Z* _3 Y( n
$ r/ \7 y% `5 G2 A8 c; l
int main(); n; P& g/ y: h
{
* O/ `2 c$ e, h, R //MCBSP,ARM与AMBE2000交互设备9 U' ]6 k# L( ^
int fd;8 s1 U4 N& q. V
unsigned short data_write = 0x5555;: W$ D! ?# R; j* l
unsigned short data_read = 0x00;
, Z4 q" F1 m9 g* \, |* g6 Y$ S fd = open("/dev/MCBSP-device", O_RDWR | O_NONBLOCK | O_SYNC);
0 {' {+ i# b" N2 Y // fd = open("/dev/led-device", O_RDWR | O_NONBLOCK | O_SYNC);3 Q$ [* J' T. z. D6 U( a% t Y6 o6 p2 V
) l& h9 H" m' x9 ~5 q1 U6 N
if(fd < 0)9 m7 H: x6 ^! y( B/ d. F) T
{
) W2 K/ K# \, B% }% ]3 P perror("open failed\n");
3 P' ] w9 W6 p% h return -1;
; C0 i* D I1 I; h; i }3 @& y8 |% B( ~' G0 F2 [
6 ]; `0 i: k6 H6 d. U' N+ T6 f. i while(1)
) R3 \; U: i, p- v) ~0 M {
7 w4 W% ~/ A$ f+ l b1 T6 M2 U2 j& K; N/ O; S& j$ j
//AMBE2000每次读写是24个字为一帧
) \3 f+ u) d6 U$ l" A1 D //写数据时将数据在底层存储起来,等到中断的时候再发送' d9 o T0 d8 n; y ]4 w4 }
//AMBE2000输入数据是以0x13EC开头的
" P0 p, D R' `& o write(fd,&data_write,sizeof(unsigned short));
6 F0 Q, ?* W3 n ]$ f4 K0 m" M
; C* F& L" a4 l" d+ m/ T# V //读数据的时候,在底层中断中将接收到的数据存储起来,然后再传送到应用层 * }) W6 w E2 B/ E3 d
read(fd,&data_read,sizeof(unsigned short));
6 y" A; U4 T+ U6 e : v+ w) { Y4 h- I5 ]7 D: t
if(data_read == 0x13Ec)
) ^: f& U' @5 _ {. d9 Q$ i* ^4 Z" \* V: F& l" x
3 f F* \4 j7 u L8 p: F# a
printf("data_read = %x\n",data_read);& l( C; d! d, U7 N5 C
}
7 j/ X4 [+ s4 v9 p
. u# k2 |* ?5 l0 S/ f msleep(10);
6 c Y+ L: D/ F$ P6 R% o , f1 u) K$ D; k+ l9 c
/*
% g; a- d. X8 a ioctl(fd,1);
4 L, W$ U: L7 q! h sleep(1); l& K& ?' ^* Q
ioctl(fd,0);
: K H6 @/ n! h( Y& { sleep(1);
* ?/ T0 }* ?/ k% C! F5 n */ 7 h- @. ?$ F H4 V+ i7 a' _' C: o
} & l0 D- ?, U+ g
return 0;/ m1 t( x. o" J* E7 M) C
/ d* K' p \& m1 M}. u$ \+ U$ |4 @, A& {+ L
# U: K. l+ Z- k5 B
多谢各位指教,谢谢! 急
3 O r# l0 f+ u( k) N0 ?1 d5 ]8 ~. d
9 C0 U4 Y* f8 T) e N' ]0 i4 }: u$ A4 P1 ^
2 T0 L( i8 F" {% e
# @1 L* i, R' Q9 I" s0 ?5 A/ ^8 M1 z4 p" N# K7 A
|
|