|
|
我讲创龙在DSP中使用的例子移植到ARM中,如下是我的底层驱动程序:
1 h! D! w# m5 t/*( @! Y* P1 B0 x9 h$ m) D, E2 ~
* Copyright (C) 2009 Texas Instruments Inc& g- S1 s& F0 p+ b" _" o* P' h
*
9 H, i9 H* d: b8 z P * This program is free software; you can redistribute it and/or modify9 p# k }' t+ C+ f# H& W
* it under the terms of the GNU General Public License as published by. n2 D! q0 C% i3 ~ ]' ^
* the Free Software Foundation; either version 2 of the License, or) L& v+ Y* F# z$ N8 W
* (at your option)any later version.
8 z+ e4 S: w/ S& A2 w& A *
W- c( G" H% Q( z1 s * This program is distributed in the hope that it will be useful,1 x: F, \# }; f s$ b0 i! J
* but WITHOUT ANY WARRANTY; without even the implied warranty of
! Y. H- t* {( H3 e * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% R6 u0 @4 v5 O) A: S: T * GNU General Public License for more details.7 j: ^0 S D) L/ q, a! g: }
*
0 h% o8 I8 q( d * You should have received a copy of the GNU General Public License1 h# z" W- L! a- g+ G
* along with this program; if not, write to the Free Software
+ B1 [5 M3 c: b/ w; _, X+ P3 H# X * Foundati. N4 y/ _6 m, R* |2 p& C' D& V' O
*/
. C! H a6 T0 h) e g6 ]- Y#include <linux/module.h>7 j6 s4 f# s) v0 b% e
#include <linux/init.h>
4 q, }2 n, |. {, l# C4 S) r$ s#include <linux/errno.h>% j4 q$ L6 E# W w) w+ R6 d
#include <linux/types.h>/ J# K7 r8 {; V" \+ T
#include <linux/interrupt.h>
: r, t8 G, B0 r; t2 Y#include <linux/io.h>7 r: ^, [0 \/ H, `; D, X
#include <linux/sysctl.h>/ a! @( Y) `8 n0 h p
#include <linux/mm.h>. c% J' H. t5 _8 e* E
#include <linux/delay.h>( F( f/ N4 k$ }/ W6 w9 l
#include<linux/kernel.h>
7 D* H( ~6 K# e* L( I#include<linux/fs.h>
" ` Q: ^/ {; @#include<linux/ioctl.h>
5 ]3 N0 O5 e7 K( b: Y$ Z3 _1 x# k; [#include<linux/cdev.h>
# x$ c6 p; _6 b5 e#include<linux/kdev_t.h>
& }( w+ ]' P! m" a- I' N9 f#include<linux/gpio.h>
2 t+ K! |: }: m9 s4 l#include <mach/hardware.h>
9 {3 r2 J9 ~0 f$ C, q#include <mach/irqs.h>: r* p' i# [' e8 F0 [% x0 K
3 G* h7 p2 I0 N1 d
#include <asm/mach-types.h>
/ V/ q3 f) I) y5 G5 A9 F1 Z1 V#include <asm/mach/arch.h>6 N' @; R {" b, L
#include <mach/da8xx.h>
; Q4 b+ R( ?# {5 D0 ]7 A5 u#define SYSCFG_BASE 0x01c14000
a7 p# I+ D( d1 n- e8 F#define PINMUX1_OFFSET 0x124 ) H- \) p7 }& t: }* @9 P
#define PINMUX18_OFFSET 0x168
4 o6 Z8 y4 B8 M W' j$ p7 {#define PINMUX19_OFFSET 0x16c
* e$ a1 ~6 z9 j6 q/ U#define SPCR_ADDR 0x01D11008 //MCBSP1_SPCR% E; O$ }1 \. z/ A4 L4 P7 ^
#define RCR_ADDR 0x01D1100C //MCBSP1_RCR3 u" S" e8 G f
#define XCR_ADDR 0x01D11010 //MCBSP1_XCR
0 N! s8 f& z# D#define SRGR_ADDR 0x01D11014 //MCBSP1_SRGR
0 P4 r* v! K* s0 ]6 R1 P- S7 d L#define PCR_ADDR 0x01D11024 //MCBSP1_PCR
3 ~+ X1 F7 M$ l1 P1 @ % u7 w' q _1 W: {
#define DXR_ADDR 0x01D11004 //MCBSP1_DXR6 v* ~9 Y5 ~; m
#define DRR_ADDR 0x01D11000 //MCBSP1_DRR! p |( p2 G+ c( z) j3 v3 S: K% S
//PSC* e( `% o* D2 d/ o0 F: A; Y, [
#define PTCMD_ADDR 0x01E27120
. h6 E, }7 W9 Z2 T; I* a#define MDCTL15_ADDR 0x01E27A3C1 i7 l0 V7 t8 U$ W9 R
#define PDCTL1_ADDR 0x01E27304$ x9 e) A- P' m
//GPIO8 direction
- u( f0 K7 _# M% m4 W3 ^3 n J#define GPIO8_DIRECT 0x01E260B0
& g2 v/ b6 l; I( _! {" w! n5 y#define GPIO8_OUT 0x01E260B4
8 h8 U' G9 M x' w5 ^8 H#define GPIO8_IN 0x01E260C0" W4 G" u4 ]- Z# F% U
, M( R; m: O1 i
//#define MCBSP1_RINT 99
% ~: R$ Z+ ^' T- {//#define MCBSP1_XINT 100 , M( t9 K9 O/ m& U6 N, [
static int MCBSP_MAJOR=239;
7 V5 P$ V4 E# W! Xstatic int MCBSP_MINOR=0;
" y, \/ H H! v/ X0 {4 nstatic int count =1;
; f+ {! v+ W; q/ l* e# E7 n. B1 q6 J" T
#define MCBSP_NAME "MCBSP-device"# w6 X. Y3 G; k/ a
8 ^. z3 y6 E0 @9 Y4 |' e6 t4 C* `
static struct cdev *mcbsp_cdev;
+ Q# q1 i3 `( K( estatic struct class *mcbsp_class;
+ ~- E/ p1 \4 W3 f5 X7 k' [static dev_t mcbsp_dev;# ^% a1 a/ N* S; t U
unsigned int DRR_data;5 ^& y% g/ U. m# t; A# o
unsigned int DXR_data;7 P/ D: S( l$ G* ~0 l8 n
static int mcbsp_open(struct inode *inode,struct file *file) R4 g3 a, m( s3 S, A( w
{6 z! e5 F7 c3 P! Q7 o7 g- a
: m+ }, L4 B6 {- l* L, T' `7 ~
//interrupt enable,initialized0 M( O) j; i6 r m: ?
unsigned int temp;2 P" W! M- C2 w F+ i$ l
//SLEEP_EN(GPIO8[10])---0
( H( b9 J* J q1 L' A- D temp = __raw_readl(IO_ADDRESS(GPIO8_OUT));# v& l( q3 H& H
temp=temp&(~0x00000400);& y/ {9 `8 M P9 g b/ H4 v
__raw_writel(temp,IO_ADDRESS(GPIO8_OUT));//GPIO8[10]
. a2 F6 y" g/ h& y' p0 L" ~& r //RESETn(GPIO8[8])----0----11 h% M2 [3 G# t. m6 |
temp = __raw_readl(IO_ADDRESS(GPIO8_OUT));
1 j) b2 Q$ e- z0 h$ C5 |$ H; N temp=temp&(~0x00000100);
+ c' v9 s8 x) B' T9 e' i __raw_writel(temp,IO_ADDRESS(GPIO8_OUT));//GPIO8[8]---01 e# |$ B* H4 J, c! e+ |/ S1 I0 F
udelay(100);; y1 t3 H* Z& @1 l/ I, u& ]
temp=temp| 0x00000100;
# X8 W, y6 O8 F8 Y __raw_writel(temp,IO_ADDRESS(GPIO8_OUT));//GPIO8[8]---1
; [" W( @, Z$ n8 M" }3 ?4 y6 | udelay(100);
: N4 i( o, u/ t9 M( _! C' M2 S printk("open success!\n");
: l6 p* V7 h& y% e9 W# ] return 0;
( i5 H# T, v2 B0 V \1 o) B} i. l$ N. Z7 F
, U- M/ Y$ I# D& p+ i! c# d
static int mcbsp_release(struct inode *inode,struct file *file)
# I7 ~! B6 d- ]+ l% J- g{9 R1 T3 p J) e( G7 i* A) P
printk("release success!\n");5 q$ Z% {5 |+ Z3 e% i
return 0;) A/ s1 I& }1 m3 h* U/ z3 z' N
}8 {$ x" G2 N( m1 F: [/ q
- ]/ \- r* g/ m* e ]static ssize_t mcbsp_write(struct file *filp,const char *buf,size_t len,loff_t *off)
8 E r/ [ g, D6 L{# S7 {3 Z, G2 Q& ~, D( y s
copy_from_user(&DXR_data,buf,len);8 q' q* S: F: [, y
iowrite32(DXR_data,IO_ADDRESS(DXR_ADDR));
6 [7 k3 k1 ~ O( s. L" s, y3 p) R; z return 0;
5 V/ W" g; v. q7 n
" k7 J- T6 A! \}
( h/ w8 r8 T( J. ~# B* U3 ]- `* j, A# h3 u9 Z
static ssize_t mcbsp_read(struct file *filp,char *buf,size_t len,loff_t *off)
P: |6 Y$ c$ g+ y- V{
- t0 c# o9 e: c0 s, _ DRR_data = ioread16(IO_ADDRESS(DRR_ADDR));
% Y- U4 M) t7 @; L/ L' Q copy_to_user(buf,&DRR_data,len); % {5 b2 C" U- {% j$ @: n: f
return 0;9 u1 B- h" f1 \0 ?; Z
}
7 H) C3 K% @4 e8 s$ H* p: ~
) [: n& I' C9 U- T" @! n- k
8 F- Z3 J8 d- t9 R4 Gstatic struct file_operations mcbsp_fops=
w7 I* h) J5 H- K{. D3 T/ Y& x' V" m, N
.owner=THIS_MODULE,
0 \8 z9 u# R: P9 u$ e6 H .open=mcbsp_open,- a/ m# i8 Q* I. X
.release=mcbsp_release,
" w1 h& c. U* |+ t& @8 F6 ~ .write=mcbsp_write,- {+ [! u# {! c, ^7 H+ v2 V7 @, N
.read=mcbsp_read,6 q" _9 Y4 |" K; |9 A, G( @
};
9 V# L4 P# U' L: O7 c( i( `7 nstatic int __init MCBSP_init(void)1 i2 c2 V* E7 E+ L
{
6 I9 Z& N5 t I& b/ y3 |0 C9 M int ret; e7 O- e3 E/ k/ O
unsigned int PINMUX1_REG_old;7 I- N7 A' D% ^" s
unsigned int PINMUX18_REG_old;
( m" b4 k, H7 r! P. e unsigned int PINMUX19_REG_old;7 P& ]1 ^9 x9 F5 A2 l
unsigned int temp;
0 }& E, p% P* g0 ~, a! C if(MCBSP_MAJOR)
; P9 Q: O8 Q; u) M% b {+ w7 a' c0 ^- O! o- t! `1 ~
mcbsp_dev=MKDEV(MCBSP_MAJOR,MCBSP_MINOR);+ k& ~$ _1 ~ [" h
ret=register_chrdev_region(mcbsp_dev,count,MCBSP_NAME);
6 @7 N; h' T! ^: E5 S8 P }. y; k8 y8 }; b- }' J
else: B( e& _% ]" m
{
. Y' W& o, {) T$ `2 _- A0 N ret=alloc_chrdev_region(&mcbsp_dev,MCBSP_MINOR,count,MCBSP_NAME);8 ]: }; ]' f& O7 M4 |
MCBSP_MAJOR=MAJOR(mcbsp_dev);) x1 I% P {* k8 a
}
. |9 W7 }; ?& N' i
. c0 z$ |/ _1 _# _: w- g if(ret<0)
q6 G( ]. i" Q' p { y& v4 F/ q* X i
printk(KERN_ERR "register chrdev fail!");
* @4 I$ C1 U6 t return -1;9 ?* Q: ?% O9 g- ?# ^7 w
}0 Q0 p n4 B% v9 F
; B8 ]6 Y* N; e' ]/ } mcbsp_cdev=cdev_alloc();1 p; r" L: H4 d2 u8 r
4 C1 h7 \. Z9 w3 a5 i/ ] if(mcbsp_cdev!=NULL)# M5 A& Y2 @+ x* u: y. ]2 D
{/ {5 c% A# l& l% E. {
cdev_init(mcbsp_cdev,&mcbsp_fops);
7 Z3 t4 t S+ m" @5 L mcbsp_cdev->ops=&mcbsp_fops;+ P% c% S9 p" h. e% B
mcbsp_cdev->owner=THIS_MODULE;
- D) C, m7 c. i! K2 _ ! L$ C4 }$ ^$ x- o+ E l: o1 v
if(cdev_add(mcbsp_cdev,mcbsp_dev,count))
m& ~4 I! d- ~" s* D: m printk(KERN_ERR "register cdev fail!");2 D& g0 a1 x5 f. h$ n4 B3 C6 ?
else
3 D6 ?, w7 w( b* C( H1 H printk(KERN_ERR "register success!\n");
! M) }, H3 A; \0 W }' |1 m* q: Z, q) R* O
else
7 O7 k' E: b) j# w6 I {+ o) F4 ?% } l$ V8 Y" m
printk(KERN_ERR "register cdev err!");) h5 q; s5 Z4 ^7 x( k
return -1;: S$ _8 v1 z8 c* T
}; K4 _. V" o; J% A
( a1 T2 ]( L# k/ [0 x4 S4 t mcbsp_class=class_create(THIS_MODULE,MCBSP_NAME);; B% i) g8 w( V/ A0 k; n1 h5 P
if(IS_ERR(mcbsp_class))" A1 K; Q4 E* e# Z
{
. e T9 w) q* Z- w, {1 m' Y printk(KERN_ERR "register class err!");
8 z T+ j/ p+ e% x! V return -1;
9 b) r7 p: s* T- w% t }
}) K- [4 i6 ~- ?$ g* h device_create(mcbsp_class,NULL,mcbsp_dev,NULL,MCBSP_NAME);/ d C: U4 c5 w0 B0 t0 n
9 J z* R% {) j2 }' z( L //PSC
5 H' P- d' ? m# h/ d1 n //add Enable MCBSP% g' H9 h9 X! c/ V2 b: x5 I5 U
//test
# q* T G; a, U! {/ z temp = 0x80000003;6 ]) n3 Y) b* e. Z- L! W
writel(temp, IO_ADDRESS(MDCTL15_ADDR));
}9 a% I" Y; M5 h+ A6 O temp = 0x00000003;0 d9 g) Q0 P4 y6 j
writel(temp, IO_ADDRESS(PTCMD_ADDR));
7 t+ V t8 y$ _" ]
5 [$ I2 {& p. j$ F; } temp = 0x001FF201;
: K- w; p* C. }+ @ writel(temp, IO_ADDRESS(PDCTL1_ADDR));
" j! r' W4 A- E7 {) v7 {. ~. q- s & \& ~) A1 R2 l D. l6 U
//PINMUX 1 `' @9 `) p7 O+ p6 K" R- {8 p( I2 ?' T
//MCBSP_CLK(receive/send),MCBSP_STRB(receive/send),MCBSP_DX,MCBSP_DR,
8 R: {& e# v. t- F$ F) B PINMUX1_REG_old=readl(IO_ADDRESS(SYSCFG_BASE)+PINMUX1_OFFSET); / {) c% H% h) R' ~" M( w
PINMUX1_REG_old=(PINMUX1_REG_old&0xf000000f)|0x02222220;
1 I* n N, M% x- p writel(PINMUX1_REG_old, IO_ADDRESS(SYSCFG_BASE)+PINMUX1_OFFSET);0 |/ N; r. ~% u
& }- h! P2 E0 |4 n/ {5 g# L+ w6 L' D
//SLEEP_EN,EPR,L138_SHK1,L138_RC& g% Y! {' T6 M4 E' H E2 K
PINMUX18_REG_old=readl(IO_ADDRESS(SYSCFG_BASE)+PINMUX18_OFFSET);
8 s- V6 y! n3 t/ k: b, g% { PINMUX18_REG_old=(PINMUX18_REG_old&0x0000ffff)|0x88880000;
8 ~- H E7 V, n2 Y writel(PINMUX18_REG_old, IO_ADDRESS(SYSCFG_BASE)+PINMUX18_OFFSET);
! l8 n: ?; W& h$ K; `8 s ! M, s: \/ x, a& Q5 k
//RESETn,L138_SHK2
) @6 {+ P z5 ~4 u PINMUX19_REG_old=readl(IO_ADDRESS(SYSCFG_BASE)+PINMUX19_OFFSET);
: `+ j$ r9 i% _+ F, V PINMUX19_REG_old=(PINMUX19_REG_old&0xf0ffff0f)|0x08000080; 3 c3 Z! d8 ]( Y, n( k
writel(PINMUX19_REG_old, IO_ADDRESS(SYSCFG_BASE)+PINMUX19_OFFSET);& u, [2 O2 m9 P$ j& D
% M( }. u3 u$ L' [. }# R * H4 {; D" T/ y, ~; v4 G4 j
//SPCR Register
^- e& Z2 C; r6 A& B! G% d //FREE-1,SOFT-1,FRST-0,GRST-0,XRST-0,RRST-0,RJUST-00(Zero-fill MSBs)reset
( N: Q& {1 p6 f temp = 0x03000000;//(DLB=0)
6 L7 L% d6 r% j" N4 t% i/ g // temp = 0x03008000;//(DLB=1)
# Z( g( L' q( |# S3 _ writel(temp,IO_ADDRESS(SPCR_ADDR)); //reset1 t- T# C4 O7 g, s
temp = readl(IO_ADDRESS(SPCR_ADDR));% f! N' p' G9 R2 i) M9 S
printk("temp=%x\n",temp);
5 b% \ g+ D: Q) b& v- R J
1 L7 w2 ]. B% N% g3 W //PCR Register8 n* C: ^% ^' u" q2 a
//FSXM-1,FSRM-1,CLKXM-1,CLKRM-1,SCLKME-0,FSXP-0,FSRP-0,CLKXP-0,CLKRP-0
5 o' J: S* d% Y' y // temp = 0x00000F0F;6 y7 t* I/ J( M" ]& e8 g
temp = 0x00000B0F;; u( ?5 ?6 b6 e' O
writel(temp,IO_ADDRESS(PCR_ADDR)); //initialized 2 a, b( } c9 C' O: W# R! @( b
temp = readl(IO_ADDRESS(PCR_ADDR));
2 \$ ~5 _ W9 F t' y$ @7 x printk("temp=%x\n",temp);
6 @% o: B" M9 j% ^8 L# i+ a //SRGR Register
B0 [7 i* v! g/ n0 J7 B) L/ B //GSYNC-0,CLKSP-0,CLKSM-1,FPER-31,FWID-0,CLKGDV==11, r" R+ k: C8 r" A5 n1 [2 ^
//temp = 0x301F000B;: n/ P( H9 O1 O2 P
writel(0x0301F000B,IO_ADDRESS(SRGR_ADDR)); //initialized 7 }* R3 _" x$ O& }2 c8 e& p
temp = readl(IO_ADDRESS(SRGR_ADDR));+ {0 P4 C+ U; K( r$ ?
printk("temp=%x\n",temp);) X& {" ]9 s# p8 @, K. D) U# }
//RCR/ K/ y: n; i0 p- J- O
//RPHASE-0,RFRLEN2-0,RWDLEN2-2,RCOMPAND-0,RFIG-1,
2 M, `8 ?( t' Y5 v6 A //RDATDLY-0,RFRLEN1-0,RWDLEN1-2,RWDREVRS-08 W0 u( ?- {/ d/ M4 a% Y
temp = 0x00440040;
0 P& C/ c* w2 }1 l7 Z writel(temp,IO_ADDRESS(RCR_ADDR)); //initialized 3 e2 S5 V6 u! T& N$ Y' H
temp = readl(IO_ADDRESS(RCR_ADDR));/ d7 o% L/ B3 j: R
printk("temp=%x\n",temp);; a+ s9 R4 {8 w" L* ^" L/ O
//XCR2 Z$ u: l3 ^+ n6 Z3 A& `( r
//XPHASE-0,XFRLEN2-0,XWDLEN2-2,XCOMPAND-0,XFIG-17 a* p+ i4 s+ q' Q& B$ a! z
//XDATDLY-0,XFRLEN1-0,XWDLEN1-2,XWDREVRS-0& ?5 T, s' e/ }
temp = 0x00440040;4 f, y" y/ H' w: E
writel(temp,IO_ADDRESS(XCR_ADDR)); //initialized , L9 _7 H9 R! V. d
temp = readl(IO_ADDRESS(XCR_ADDR));6 n; x) o$ v: a4 \% n) J9 G
printk("temp=%x\n",temp);2 D1 a9 g) W, }
udelay(100);5 U0 U) Z" n5 r$ T6 p8 x: x
//SPCR Register
0 d' O& E8 [7 p0 ^0 J //FREE-1,SOFT-1,FRST-1,GRST-1,XRST-1,RRST-1
7 Z2 T& Y7 L, ^1 W/ f# ? temp = 0x03C10001; //DLB = 0 VS DLB = 1
. s; \! A' j5 D& V! r" T' f writel(temp,IO_ADDRESS(SPCR_ADDR)); //enabled
% j& N1 V- Q2 T& K- c3 i' M- L+ i temp = readl(IO_ADDRESS(SPCR_ADDR));
$ u- U/ G8 w+ H1 E0 K+ T printk("temp=%x\n",temp);
. Z' w5 d7 H$ X5 x) B! R0 ` udelay(100);- w. m1 p0 [6 U3 }6 X# o& ]
* b( s' S+ V5 J //set GPIO direction
: N% S5 z% u8 G" b temp = __raw_readl(IO_ADDRESS(GPIO8_DIRECT));; e: Y4 O/ ~7 ?$ N# m4 X
temp = temp | 0x00000100;//EPR----input6 J" e( y, m$ C9 w) e4 _5 Z
temp = temp&(~0x00000500);//RESETn,SLEEP_EN---output% }. k1 W8 z# t! s4 G! P$ Q
__raw_writel(temp,IO_ADDRESS(GPIO8_DIRECT)); 3 w \% \/ L4 O
; l' Y7 ~; j& U1 ^ return 0;2 }+ f: a3 S( C2 W& D
}
9 _* l2 O' y: D3 k# i! E Cstatic void __exit MCBSP_exit(void)
# c$ ~' Q ]0 q _{5 n$ _, Z: l' O2 i
printk("mcbsp chrdev exit!\n");
2 q: g; F; w+ m* M% _9 { cdev_del(mcbsp_cdev);
. C9 h" D% w! A' q( B# q% g8 R* B unregister_chrdev_region(mcbsp_dev,count);
5 K1 k* A2 |: [8 Q' N; P device_destroy(mcbsp_class,mcbsp_dev);
* ?. \/ I. S% a& `' Q class_destroy(mcbsp_class);
$ W" D: }/ G5 l1 C& {) M}$ Y; Q, g- g4 \6 D7 b( n
module_init(MCBSP_init);
& O3 E) ~/ R; F! @module_exit(MCBSP_exit);
7 b2 f. P& @- u/ b0 j
& v- d3 h* O2 K [$ a& N/ cMODULE_LICENSE("GPL");
- c) I3 Y' A0 f, V- Z4 E. n2 R
/ c9 ?# R* G2 @* y我讲上面的程序insmod之后我用示波器量 McBSP的发送时钟脚,发送数据脚(我还没有发送数据)以及发送同步脚,3个脚的信号是一样的,不管是用我自己的底板测试还是用创龙OMAPL38 的开发板测试,都是一样的,类似于噪声的信号时钟频率也不对。; k" Q( t9 H: S# E
我的应用层的测试程序如下+ B m9 j2 b, ~- I" q7 J
#include <stdio.h>/ q" ^' |- t/ {% x9 i% t1 Q
#include <string.h>
+ a6 G$ Q9 N- [# x; H E#include <fcntl.h>
: I' i9 |9 m* `6 v#include <unistd.h>/ r D W4 v8 d- _
#include <signal.h>
, d0 B# H9 i% }: x#include <pthread.h> //线程+ O' m; ?2 G a
#include <stdlib.h>
# S/ f: ]' R9 v! [& p: ~) H#include <pcap.h> //捕获网口数据
/ [5 |4 d. j' z9 ~#include <semaphore.h> //信号
/ `, k' z I& T; Z( {% P+ y#include <sys/types.h> //消息对列9 t8 P4 Z4 d! f( I% i: e# C; r
#include <sys/ipc.h> //消息队列3 h }- O/ J/ ^& b- _
#include <sys/msg.h> //消息队列
+ x% { q# {* f5 L#include <sys/select.h>
: T9 m0 H$ @2 n9 t; K#include <sys/syscall.h>
3 X% i. ~1 u w8 e#include <sys/stat.h>" |% O% O# w5 u2 p3 B8 ]
#include <sys/mman.h>
F Y8 g, e9 N* `8 H; i8 b#define msleep(x) usleep(1000*x)7 x: Q# T* \' a2 Z' O4 l
/ }! ^ x& T8 t0 x1 F
int main()& S6 |; D* m% i% b7 X' C" ]
{
. D4 b5 d- o5 B //MCBSP,ARM与AMBE2000交互设备
^: |' q7 T J, n9 I int fd;/ }4 `' ]( _# _5 P$ k
unsigned short data_write = 0x5555;
/ x5 m5 C, S" Q g& t9 r( Y7 P6 z unsigned short data_read = 0x00;6 A* j2 B/ ~' x" J, u a8 Y
fd = open("/dev/MCBSP-device", O_RDWR | O_NONBLOCK | O_SYNC);
( ^+ w2 G5 b+ R; R8 I! R: c // fd = open("/dev/led-device", O_RDWR | O_NONBLOCK | O_SYNC);: c) F1 _) v0 ~9 j1 t
8 F `0 J9 w7 l+ u" s' n( z+ @ if(fd < 0)1 f& Q* I0 A O" s0 }6 L
{
( n) k2 C8 ^' J) V perror("open failed\n");2 z, h, u0 y$ \( c' f" k, {
return -1;9 S0 q+ B6 }( O3 ~; Y4 c3 {* R
}# n. c g- H0 Z% `' M/ i
+ l7 U0 O. ` t3 q( Z
while(1)) A0 P5 r& N/ u1 `) A6 X& m; F
{+ Y' i M5 V/ E6 o0 k+ n- t& n
5 B& X( R* S- E/ f( @! ? //AMBE2000每次读写是24个字为一帧
# Q/ K0 v/ l3 R* c6 P. R8 v. Z //写数据时将数据在底层存储起来,等到中断的时候再发送
* I T( J! _; |" R //AMBE2000输入数据是以0x13EC开头的
' Q9 _% l+ c. G. A3 t- x4 E% v write(fd,&data_write,sizeof(unsigned short));8 j& T2 x9 C' x0 C
5 z2 z+ a y+ s //读数据的时候,在底层中断中将接收到的数据存储起来,然后再传送到应用层 7 i8 n0 m& B7 N9 h* [4 U
read(fd,&data_read,sizeof(unsigned short));8 q0 ?' A* U4 Y! c6 I$ E7 R
0 s) ~. W) X; }: J4 d; ?" B if(data_read == 0x13Ec)0 L# x4 s# i; a
{. F- P7 @1 B2 P6 H2 c! k6 }0 ~, F/ P
8 a- k* O1 c% `4 t. V% ~* | printf("data_read = %x\n",data_read);
5 i; V2 m; @, i, T. ]3 s9 h }+ {9 H3 s- S0 o- C; p
) ^% x. L& R' c+ h. z! t msleep(10);9 y5 n1 q/ `; b9 z* U7 B: A5 M1 ?
7 a+ k4 U* T1 V1 y$ I4 v8 u
/*
. }% ?- O s( K: s- F ioctl(fd,1);
' n; a' o1 G& K/ F! I- ^8 g8 ?6 V sleep(1);
; f* A: ^/ r: |" L9 `" v g1 y! F ioctl(fd,0);. e7 v4 L. N, Q/ Q! V! g
sleep(1);: l; c" g( V5 o4 i v
*/ - x2 e' p/ i% j j
} , V; [2 o# E2 m. M4 T; O& s
return 0;
! S6 |6 }! w9 c
+ k6 a% ]% P" R. \: x, h3 X! J}
[$ @7 Y; s( W* A5 h1 N% {: m1 d& z) p4 E) B
多谢各位指教,谢谢! 急
7 x, n* v( o$ T1 o1 }8 T2 o; Z, _+ m, i; i2 u: ]
. y/ f# U( h" [+ ^1 T5 N8 K' ?
8 \5 [9 C P8 z( [
0 b1 N; L* N, {3 V+ `& Y0 n6 F1 |: g, V7 F8 H" n7 x# C- S, G# _% T5 k( |
|
|