|
|
我讲创龙在DSP中使用的例子移植到ARM中,如下是我的底层驱动程序: l2 y# G' h! t* f
/*
6 K" q/ |$ S$ S+ f& }/ U( b * Copyright (C) 2009 Texas Instruments Inc6 g3 q: N/ Z& _" Q7 e6 M: z
*
0 A; s- R* Q2 _4 l X: x * This program is free software; you can redistribute it and/or modify
" H) r v, m/ t * it under the terms of the GNU General Public License as published by
9 D5 S: y3 b+ Q6 r+ Y: ]% S * the Free Software Foundation; either version 2 of the License, or
! E$ @; [& a9 a m * (at your option)any later version.
6 C1 U6 L' h. { n' U$ J) q, c *
1 O( \0 W) b* |0 e7 w3 c * This program is distributed in the hope that it will be useful,! m4 [# W& Q& E6 ?- o
* but WITHOUT ANY WARRANTY; without even the implied warranty of; a$ O: V9 @- J6 e+ N
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the# y) D. @- h" x1 V) f# z
* GNU General Public License for more details.& U* G7 l( I6 Z W
*; d+ i4 T/ x6 O/ n
* You should have received a copy of the GNU General Public License7 e; Q2 z2 i2 u- h7 e$ `
* along with this program; if not, write to the Free Software, M" ~2 ~, N& N" c. Z
* Foundati
; x* Z& ~7 P' q/ v*/
& P( J" T2 U a#include <linux/module.h>
2 x; O6 `2 B+ y# J3 c) n- f$ j, q#include <linux/init.h>. s" l" s6 `- e- U) h3 t8 C6 L
#include <linux/errno.h>
# d8 I* j& W6 v' Z" S#include <linux/types.h>+ P. V1 \$ T* V% X ?7 r
#include <linux/interrupt.h>
0 G4 h3 k; i# T#include <linux/io.h>
% j4 y' o& V+ z* N) r; z3 B, Y+ W e#include <linux/sysctl.h>( P5 G+ l! X) r7 }7 M/ \. w
#include <linux/mm.h>4 F" Z5 u0 P; G6 i, e! }
#include <linux/delay.h>: f' g% b0 [& h' R! a( M
#include<linux/kernel.h>
& p3 G8 p. q7 Q* F. s& n#include<linux/fs.h>: I6 K: e- q: j8 H7 ]# r; d
#include<linux/ioctl.h>% j* j* R" j, V6 k# ~4 E
#include<linux/cdev.h>
: D5 r u* a7 g2 j; ~: h! @, l#include<linux/kdev_t.h>
- b$ B+ t e+ [+ g7 X3 x4 I) Z#include<linux/gpio.h>
* ?5 C) U5 ]4 ^! q) t0 n1 i2 V#include <mach/hardware.h>- n; U. r. J' X" F5 `
#include <mach/irqs.h>
: m$ ^5 ^$ e* j3 C4 z; _5 l
6 e2 b9 Y4 Q4 s& A! x* u$ C#include <asm/mach-types.h>% M) N+ d! G3 o/ O' F# H
#include <asm/mach/arch.h>
' m; Y! @* }# z# f#include <mach/da8xx.h>
5 K1 J8 V1 f% H& }3 T3 b p! z#define SYSCFG_BASE 0x01c14000
- ~( b* ?. _ s# u' e4 `#define PINMUX1_OFFSET 0x124 % d. ]5 O; r" X: y6 v f
#define PINMUX18_OFFSET 0x168
, n& d. P* u7 L7 N, a#define PINMUX19_OFFSET 0x16c
; I, x1 o$ L3 J% d" r' b8 n. A#define SPCR_ADDR 0x01D11008 //MCBSP1_SPCR) B. C V) t3 v# U! _2 a% t
#define RCR_ADDR 0x01D1100C //MCBSP1_RCR
/ m9 \# d7 l6 H/ z2 `! t#define XCR_ADDR 0x01D11010 //MCBSP1_XCR
% W7 ^" n8 @6 i* I#define SRGR_ADDR 0x01D11014 //MCBSP1_SRGR! }1 y5 f( ^ r( i
#define PCR_ADDR 0x01D11024 //MCBSP1_PCR
4 i- M3 u0 {9 F& e0 P / {( u5 c6 ~7 d; ?# Z- V
#define DXR_ADDR 0x01D11004 //MCBSP1_DXR# c N1 `9 g' A1 Y1 @. Z: W3 w
#define DRR_ADDR 0x01D11000 //MCBSP1_DRR9 w1 L% q2 G, z
//PSC
; P; n7 [! Z2 ^, }# }9 w! U; V7 Q#define PTCMD_ADDR 0x01E27120
. }+ E1 `/ r4 E#define MDCTL15_ADDR 0x01E27A3C
' T$ u8 {8 b: `% X7 P& d2 R) ?: F; K$ P" Q2 }#define PDCTL1_ADDR 0x01E27304
, k" q1 n+ g4 i4 d! K9 ~6 `//GPIO8 direction: _7 D+ _3 l1 m! Q
#define GPIO8_DIRECT 0x01E260B00 v: `6 h0 J1 B, x2 D6 X
#define GPIO8_OUT 0x01E260B4
5 F1 G9 l0 j! ~" w0 S5 @#define GPIO8_IN 0x01E260C0
% I& o$ _2 z' ?; J& y4 d( z$ w, ]3 G5 Z) }6 P6 l# V* c
//#define MCBSP1_RINT 99 $ g) [# H! J5 T
//#define MCBSP1_XINT 100 ) I; i2 C, `7 `3 G( i- K6 I, H
static int MCBSP_MAJOR=239;
, F4 ?! j d6 V4 p& Wstatic int MCBSP_MINOR=0;
1 a( w6 L/ g5 [0 m* E( M9 h3 f Dstatic int count =1;% [! T' \6 x: k4 L
1 L: J3 T2 ^3 }- |9 [0 m- t, Y
#define MCBSP_NAME "MCBSP-device"
2 r) T* |1 j9 g, K$ r+ z
7 q( l8 ?1 ~% b5 X- estatic struct cdev *mcbsp_cdev;
8 Y; V# o( A- E/ X9 M' zstatic struct class *mcbsp_class;
6 R$ F2 [; P% D% N/ b# ?+ U9 Q: vstatic dev_t mcbsp_dev;, c2 E8 D, V0 J( M i/ v& h6 f
unsigned int DRR_data;7 v1 A& p# L2 k7 t( H# w
unsigned int DXR_data;# x' B2 z- h' a7 {- F
static int mcbsp_open(struct inode *inode,struct file *file)/ r U5 c$ e9 }; V
{) D8 \% j# J' z
6 ~ c: _- C& j9 e9 y" p. b //interrupt enable,initialized: b o" K4 X% ]% c7 F
unsigned int temp;
* p. G( k" g: }8 q" n' c //SLEEP_EN(GPIO8[10])---0; U, H1 V5 A6 ?+ [' N- E
temp = __raw_readl(IO_ADDRESS(GPIO8_OUT));
4 ]! G/ i- E6 [* w( ^$ A' o temp=temp&(~0x00000400);
+ H5 d0 [7 f5 Y! Z% L, q' [ __raw_writel(temp,IO_ADDRESS(GPIO8_OUT));//GPIO8[10]) u* z6 g0 f3 o9 j2 N6 ]
//RESETn(GPIO8[8])----0----17 ]$ b; ~: L9 |# ~- a6 }* J
temp = __raw_readl(IO_ADDRESS(GPIO8_OUT));
1 z9 o1 M2 J! }7 B' J temp=temp&(~0x00000100);
S' c/ H8 i6 ^- R4 P __raw_writel(temp,IO_ADDRESS(GPIO8_OUT));//GPIO8[8]---0
. [/ j: R k* ^ udelay(100);! q# S" j/ g) j% q1 h4 C8 G5 H0 l
temp=temp| 0x00000100;. k- D4 a# o( s0 N1 \
__raw_writel(temp,IO_ADDRESS(GPIO8_OUT));//GPIO8[8]---1# n6 h9 ]# t2 N) B5 A/ E8 w
udelay(100);, l5 z6 {8 X2 T" D
printk("open success!\n");
\' I+ Q, O+ Y return 0;2 {7 S' g3 X/ D/ g& V
}! }1 \: _$ L5 X$ U
/ D0 J) v: {- @1 F" Z
static int mcbsp_release(struct inode *inode,struct file *file)$ `: N5 [5 ~5 L3 e9 K
{
1 y* W: ]$ T$ U2 h: a+ V printk("release success!\n");4 v2 c, x; V2 O/ X- ]9 p5 ]
return 0;# |5 q1 z1 z- q$ K
}, \) E/ d8 `9 X) }0 Y
7 T+ a0 Z% E3 w( r5 sstatic ssize_t mcbsp_write(struct file *filp,const char *buf,size_t len,loff_t *off)
% k9 f+ |5 P: s$ ~{; Q" w/ P( ~6 {" l
copy_from_user(&DXR_data,buf,len);
1 K$ X- ^1 y( w iowrite32(DXR_data,IO_ADDRESS(DXR_ADDR)); 0 l% V, |! K, `+ \
return 0;# R) Z) _6 f9 ^4 ^5 A
0 a$ j7 h: x" p4 k}& x/ o$ w4 ^* ]! K5 q
3 D" V/ U' A& Z& H8 _static ssize_t mcbsp_read(struct file *filp,char *buf,size_t len,loff_t *off)
# d6 F9 o" T7 K1 p5 D t8 C& ?{ 6 p* R' W4 V z2 l; Z' t ~3 _
DRR_data = ioread16(IO_ADDRESS(DRR_ADDR));6 g, j% k) x% M1 ~# k4 i
copy_to_user(buf,&DRR_data,len);
, ?2 W: ?) J9 }3 S1 C4 R1 Q return 0;
& o# G5 q" I" Q. \/ |. e}
( C+ J8 R' V& q3 b7 G' D# |2 d
# N- R$ |; W+ t7 d1 I( {7 ~8 P6 z0 y& C; l+ j8 D
static struct file_operations mcbsp_fops=1 C) ^( a% `# W m
{
/ D$ _8 j2 R$ X, P .owner=THIS_MODULE,
3 j8 T9 i3 G9 m. X .open=mcbsp_open,0 T$ X" k! O+ m8 K3 C6 V
.release=mcbsp_release,
" Q" Y$ p6 Q: {( V" @ .write=mcbsp_write,7 O6 ~6 K5 Z G4 G
.read=mcbsp_read," @7 n! T0 F, r% a
};
/ @8 H3 J! f+ m2 o- J( T" H h7 Nstatic int __init MCBSP_init(void)
- E9 x- y; _# p, r{
7 g, y( t5 P5 | int ret;: @9 f5 c. Q9 `3 h0 M
unsigned int PINMUX1_REG_old;% w5 X3 {" O+ a/ w( d% N
unsigned int PINMUX18_REG_old;
* r, I- k/ D* Z unsigned int PINMUX19_REG_old;
( f( \8 N/ o" y; D, S- u unsigned int temp;
, N ]3 A. s& v4 V, h% N, e if(MCBSP_MAJOR), l% J! u5 H$ C1 B
{9 u" x+ D' p/ h3 Z5 B3 U, t
mcbsp_dev=MKDEV(MCBSP_MAJOR,MCBSP_MINOR);+ K; e' I+ ?; ]" d, U! Y3 x
ret=register_chrdev_region(mcbsp_dev,count,MCBSP_NAME);
/ q ~( L& l5 v+ w4 H }
/ G! q1 j$ q- O$ ]. F; S7 K else
% z: O7 g) @+ I; i4 @9 y' R7 b! o2 ? {& S4 _1 S+ r6 {6 [+ ?( f7 i# C. Y; o
ret=alloc_chrdev_region(&mcbsp_dev,MCBSP_MINOR,count,MCBSP_NAME);- B* n( d! y0 Z) @ \+ ~. @' _
MCBSP_MAJOR=MAJOR(mcbsp_dev);$ }2 f' h6 u0 d/ |
}% o; _2 ?6 X( P0 t% z* I D1 O4 o
2 b0 t" |7 A5 S% A- g+ v A/ `1 N, l if(ret<0)8 c5 c$ s/ h7 V3 s3 U/ I
{% g6 A- m$ R: D- r0 a: D
printk(KERN_ERR "register chrdev fail!");
+ Y. a: m( ?4 D# `' k! b0 Q4 | return -1;
H6 q. G% G& x. a2 M }
3 j) ^* R; F I9 ?
" z6 P+ U6 J9 T- N5 O mcbsp_cdev=cdev_alloc();: G' h( n, I3 [2 o
+ W. ^, E+ P' u9 t( k if(mcbsp_cdev!=NULL)% w4 h+ i& p% j" L8 f. |
{
, M/ Z) b# z4 O9 k/ M cdev_init(mcbsp_cdev,&mcbsp_fops);
$ m* t9 h% F4 W7 O8 {" H mcbsp_cdev->ops=&mcbsp_fops;2 F+ N( ?/ ?& X, r
mcbsp_cdev->owner=THIS_MODULE;
" v% x9 w; }& i) ~/ K6 d : m# L' W. J9 Q9 }3 h
if(cdev_add(mcbsp_cdev,mcbsp_dev,count))5 x, b. u# o0 o" Y9 z, o, r* d( _
printk(KERN_ERR "register cdev fail!");6 D: Y P) z% C) K' ?
else
7 T1 ]* ?: |% ? printk(KERN_ERR "register success!\n");
1 g8 M6 e* h `$ _0 J }
/ S- U; _7 k; ~2 o1 [ else* u8 C) S5 n" i$ B) S6 ~$ D
{
+ ]. o* v8 v# J( h: [0 _6 A! c printk(KERN_ERR "register cdev err!");
5 \) L6 z" X+ h0 G& h; M return -1;( l/ f4 _# k- H+ o9 k( K
}
& G ]; O5 K: b" A2 k, x' n: W ; b9 `# v( `* ]5 ^$ O: r
mcbsp_class=class_create(THIS_MODULE,MCBSP_NAME);
- W$ P9 A' J. g7 q* } if(IS_ERR(mcbsp_class))
) i& I) L7 W* E0 i {
) {7 V! t4 {- _5 v: n/ }, O4 @ printk(KERN_ERR "register class err!");0 {6 N' K/ O( O
return -1;+ E: i! ^ O2 |0 B7 v3 L! m0 [
}
! C h# y- A: Z0 l5 Q device_create(mcbsp_class,NULL,mcbsp_dev,NULL,MCBSP_NAME);$ y: c9 R0 S" G9 F7 r: f
. }8 @9 B# A5 c. |5 w
//PSC+ X9 |' L4 i' b! h7 @: I
//add Enable MCBSP+ C, \. o2 O' b9 N3 W
//test
4 G3 |4 D7 N5 x temp = 0x80000003;
' v- N! A( @) U& t/ s7 q1 s writel(temp, IO_ADDRESS(MDCTL15_ADDR));- ]( h, W- A" N, ?+ p6 f2 u! Z) C
temp = 0x00000003;# y0 R( w5 \0 x' A0 T
writel(temp, IO_ADDRESS(PTCMD_ADDR));
- e3 ?9 b7 \3 Q" M J8 i0 v. G" c ( }. n$ W$ m' }( v2 |) |
temp = 0x001FF201;
$ M/ f* l6 O9 |! Z) A: ~ writel(temp, IO_ADDRESS(PDCTL1_ADDR));
, g% C# ~4 C8 i/ ^6 X. u9 Z. ~
& S/ I" \% a0 B //PINMUX
4 v) g9 |# q! w" k) w7 m //MCBSP_CLK(receive/send),MCBSP_STRB(receive/send),MCBSP_DX,MCBSP_DR,
/ W0 w, [1 S% y8 F PINMUX1_REG_old=readl(IO_ADDRESS(SYSCFG_BASE)+PINMUX1_OFFSET);
! L1 y& u3 p) J PINMUX1_REG_old=(PINMUX1_REG_old&0xf000000f)|0x02222220;
8 C [/ {2 L- N' H, A writel(PINMUX1_REG_old, IO_ADDRESS(SYSCFG_BASE)+PINMUX1_OFFSET);
5 }& b8 M5 i& i3 j% X( X/ @ / Q0 r* d2 o8 H/ V7 r
//SLEEP_EN,EPR,L138_SHK1,L138_RC# E) R+ b& W6 e w) B2 @
PINMUX18_REG_old=readl(IO_ADDRESS(SYSCFG_BASE)+PINMUX18_OFFSET); ( c+ K3 Y8 Y$ ^
PINMUX18_REG_old=(PINMUX18_REG_old&0x0000ffff)|0x88880000;
7 p$ Y+ b4 c, i4 `; y# K5 g, g% k writel(PINMUX18_REG_old, IO_ADDRESS(SYSCFG_BASE)+PINMUX18_OFFSET);
% c( F) F5 y. J n ! q2 e' u* Q, T
//RESETn,L138_SHK2
8 _% |/ w2 R; r; h: X/ N PINMUX19_REG_old=readl(IO_ADDRESS(SYSCFG_BASE)+PINMUX19_OFFSET);
7 T# B* Z# @* M/ M% y7 _. s PINMUX19_REG_old=(PINMUX19_REG_old&0xf0ffff0f)|0x08000080; ' I: p0 I( @) f1 X$ I. U
writel(PINMUX19_REG_old, IO_ADDRESS(SYSCFG_BASE)+PINMUX19_OFFSET); t. _1 B. ]" Q& B1 p
# E$ I' }+ d) _6 r3 { Z2 y0 W) B 1 v8 a4 p* d* d
//SPCR Register9 F! I; @6 d! V( o# k Y
//FREE-1,SOFT-1,FRST-0,GRST-0,XRST-0,RRST-0,RJUST-00(Zero-fill MSBs)reset$ |3 U8 Q& @( R5 D
temp = 0x03000000;//(DLB=0)! F# d$ c0 I# l/ A
// temp = 0x03008000;//(DLB=1)8 j( O8 I M' [ K, `' d4 `
writel(temp,IO_ADDRESS(SPCR_ADDR)); //reset% s4 c" s# g# U$ u
temp = readl(IO_ADDRESS(SPCR_ADDR));# \6 d4 V5 s& H7 A4 _+ F8 R9 b+ w
printk("temp=%x\n",temp);
. [9 J- V u8 D: o9 E- Y5 X ( X/ i0 R: l, @9 P4 ?
//PCR Register
3 f7 H) U6 j$ Z4 I6 s. @7 X* m //FSXM-1,FSRM-1,CLKXM-1,CLKRM-1,SCLKME-0,FSXP-0,FSRP-0,CLKXP-0,CLKRP-0
) e2 r4 l9 @$ o# d& O // temp = 0x00000F0F;6 J& Q |( I0 I, M9 N
temp = 0x00000B0F;
: w+ M# r5 e- p. t- O writel(temp,IO_ADDRESS(PCR_ADDR)); //initialized
9 L t Y# s# l4 @/ q' T' r temp = readl(IO_ADDRESS(PCR_ADDR));' Q, O g$ @' o
printk("temp=%x\n",temp); , f( B/ d& {' V4 t- M/ T
//SRGR Register
# D+ a2 D- y$ k$ c //GSYNC-0,CLKSP-0,CLKSM-1,FPER-31,FWID-0,CLKGDV==11" ^7 E6 C1 k" `7 t5 b% R
//temp = 0x301F000B;
1 B. u3 N2 v1 L writel(0x0301F000B,IO_ADDRESS(SRGR_ADDR)); //initialized 3 v) L3 d3 X' J6 S- P0 n; }
temp = readl(IO_ADDRESS(SRGR_ADDR));
4 E" J! D7 t; `6 J" q$ U printk("temp=%x\n",temp);- S! x# k, y& C/ ?
//RCR
; c! a- k1 L' d/ H //RPHASE-0,RFRLEN2-0,RWDLEN2-2,RCOMPAND-0,RFIG-1,
F9 e+ Z2 N, c- R //RDATDLY-0,RFRLEN1-0,RWDLEN1-2,RWDREVRS-0+ Y9 q; P, U3 ]
temp = 0x00440040;+ Q. ] S6 Q+ g5 ]
writel(temp,IO_ADDRESS(RCR_ADDR)); //initialized , F0 b+ f* W' X8 b( h* w1 V9 \
temp = readl(IO_ADDRESS(RCR_ADDR));* U' q- B+ T0 o, y
printk("temp=%x\n",temp);& o1 H& N* P* p9 a
//XCR& C+ ?; G; N) u% d
//XPHASE-0,XFRLEN2-0,XWDLEN2-2,XCOMPAND-0,XFIG-13 z' `7 D* _- K0 c, ~1 e, {% t
//XDATDLY-0,XFRLEN1-0,XWDLEN1-2,XWDREVRS-0
! X, P4 }' E) n) K temp = 0x00440040;, f$ @! e7 }0 g
writel(temp,IO_ADDRESS(XCR_ADDR)); //initialized
4 @: @; ?* o4 }& l temp = readl(IO_ADDRESS(XCR_ADDR));, U5 B, i: D2 U3 F, {8 z) H; m- h, y# e/ ?
printk("temp=%x\n",temp);
. A& d- |9 M! h S8 D4 F+ G, n9 d6 _ udelay(100);
7 n' _7 f6 c" N7 _& K5 w' X, R1 R- N //SPCR Register
8 e0 ~, w: ^5 _% g; T //FREE-1,SOFT-1,FRST-1,GRST-1,XRST-1,RRST-1
( E9 r; o) F+ g temp = 0x03C10001; //DLB = 0 VS DLB = 1
' X" [0 a9 W! u9 Q& O writel(temp,IO_ADDRESS(SPCR_ADDR)); //enabled" [: x' z4 ~- s" g$ I
temp = readl(IO_ADDRESS(SPCR_ADDR));
& k' v, ] D" Q( x2 _( |3 R printk("temp=%x\n",temp);" B7 j' Y* q( y: o' e! d
udelay(100);
; t1 d# [- s( a; j1 H
$ F* W n+ @) h; ? //set GPIO direction; s7 ~4 a, k" H9 f! w6 o K
temp = __raw_readl(IO_ADDRESS(GPIO8_DIRECT));- F* i5 y- M7 T! k F. E9 P$ w
temp = temp | 0x00000100;//EPR----input
1 E; V* V R \+ ~4 U' e, A) [+ q temp = temp&(~0x00000500);//RESETn,SLEEP_EN---output2 _: A0 y+ ^' N
__raw_writel(temp,IO_ADDRESS(GPIO8_DIRECT)); 3 }5 e6 z9 a5 E: n/ n0 {2 d
& `7 }! i' _: r* d a+ ~+ I0 a
return 0;" S9 a: g7 \: R% r
}: E9 d; y) s3 o# `- i& W3 k, R
static void __exit MCBSP_exit(void)4 ~+ v$ Z0 F; |$ k0 g, h
{ P7 R& B# B0 ^) y: m% G: o! Y _
printk("mcbsp chrdev exit!\n");
- r/ S* U) n$ a( \! h$ S( ? cdev_del(mcbsp_cdev);
4 `0 e; X/ V3 ^0 ^6 n unregister_chrdev_region(mcbsp_dev,count);
/ T& e) x6 B9 a L4 Q9 u device_destroy(mcbsp_class,mcbsp_dev);) ~; c4 D# o3 @9 J6 A7 T6 p
class_destroy(mcbsp_class);
F4 g: t' g0 B7 J) ]# o}/ ~# j0 S$ I1 G# _
module_init(MCBSP_init); r( ]4 ~4 X5 V# g# o3 ~1 [
module_exit(MCBSP_exit);
* h! J, D+ o8 w" S v
9 k( U/ A& c9 y: x+ QMODULE_LICENSE("GPL");: B4 g6 \' N6 @
3 l- h+ X2 Q2 M/ ?% q! o C我讲上面的程序insmod之后我用示波器量 McBSP的发送时钟脚,发送数据脚(我还没有发送数据)以及发送同步脚,3个脚的信号是一样的,不管是用我自己的底板测试还是用创龙OMAPL38 的开发板测试,都是一样的,类似于噪声的信号时钟频率也不对。
* p6 l- n! F" {0 o9 [% _- J2 V我的应用层的测试程序如下
9 z% L* @) b1 M6 |$ H#include <stdio.h>
- P& Y8 _; E2 s0 m& m3 U8 a: a) w) M1 i#include <string.h>5 q3 P5 a4 `' Y! A% D/ J/ ?
#include <fcntl.h>$ e m6 k y* g' Z9 n9 Z' |
#include <unistd.h>5 e6 u- B0 ]+ y: \
#include <signal.h>1 E; b. w; L1 S; v' Q, f
#include <pthread.h> //线程1 l9 C. {. w# ?" n* Y# N' M- C% T
#include <stdlib.h>& q. G4 r: k0 [" q
#include <pcap.h> //捕获网口数据
& H, D8 \ P9 D, P1 n#include <semaphore.h> //信号
' q: p# |. ~" g, n3 t i#include <sys/types.h> //消息对列
9 P" t* z; q A$ z/ |7 i! s1 X5 L' S! |#include <sys/ipc.h> //消息队列( U1 I) m$ B3 A( V/ X f" n, u1 Y* n
#include <sys/msg.h> //消息队列% l2 `- S* T( N& p
#include <sys/select.h>
0 i b/ a5 B# \: G; u: L# k#include <sys/syscall.h>5 p1 B9 U- |, |" i
#include <sys/stat.h>
8 d% M; y7 v' @& K! c#include <sys/mman.h>
# e( s2 C1 B: R5 `. z* S0 m#define msleep(x) usleep(1000*x)
1 @, G0 H1 G7 ~4 C
) E8 o; h3 {. Kint main(). E; d+ e) h9 k$ y
{
; d2 N& b- m; V( \+ T //MCBSP,ARM与AMBE2000交互设备
1 ^9 j9 z J. t3 z! j, J# t4 Z' _1 F int fd;
- Y4 @) s8 D( t3 K' n: ^3 A unsigned short data_write = 0x5555;; o0 S' u& E2 a5 d {
unsigned short data_read = 0x00;9 i7 Q4 V9 @, V% f) r$ R" `6 \
fd = open("/dev/MCBSP-device", O_RDWR | O_NONBLOCK | O_SYNC);
- u" l/ x1 W4 O8 N) j. w // fd = open("/dev/led-device", O_RDWR | O_NONBLOCK | O_SYNC);/ f; a, g8 E- \) `3 w0 L
. T3 B$ q6 S- K if(fd < 0)" e- r5 C( T/ ^) m8 a
{
# E2 _$ B5 q0 ]6 R perror("open failed\n");
. b5 q! {) b: ?6 Z1 K3 [ return -1;
6 S; ]. c2 V V* E: d( ^3 {# G3 S }
( c8 Q( t& i0 q) {' y 8 Y: N& k1 N0 |3 s
while(1)
. d9 _0 B$ X+ c+ v3 h. V1 C* U {
n$ x9 h4 \3 F: C n
( t' C% R9 D& b8 S //AMBE2000每次读写是24个字为一帧- o; J5 o$ W2 h3 ]
//写数据时将数据在底层存储起来,等到中断的时候再发送4 [% W0 s: o8 k5 u8 H `& B
//AMBE2000输入数据是以0x13EC开头的
" N- [3 F3 C- r/ y write(fd,&data_write,sizeof(unsigned short));
& M! x4 W# }% D& f
1 C4 ~# F0 ?* ~% I& y9 z" F4 [ //读数据的时候,在底层中断中将接收到的数据存储起来,然后再传送到应用层
! U5 @3 Z/ U2 U% g* r read(fd,&data_read,sizeof(unsigned short));
# E5 m9 B$ o! |7 j , K1 Z& \: D& W8 B
if(data_read == 0x13Ec)" m" [' n3 t0 X2 U4 F
{6 ]3 ]% L9 o/ P5 R+ l3 q6 b9 k7 Z1 E
, a0 t% \4 O# g/ L+ `
printf("data_read = %x\n",data_read);$ P9 S' ~6 I7 W- K3 S
}; ~8 ?; i k) d. o4 L) p
5 A' r& ^5 x* @) W0 R3 b( q
msleep(10);
Q' a4 P' ~+ N ^0 c4 h, ]# J; y # s# C; i$ G8 u' r1 ?
/*
: s4 q8 g4 P& y: E: U5 Y& l ioctl(fd,1); # U }/ `) w9 |' J
sleep(1);7 @1 c4 U7 S1 h$ f4 E* w
ioctl(fd,0);
9 @- O; K! e0 B: s; O/ D sleep(1);$ n1 ~9 ?& `: c; A- Y3 b
*/ - R3 ^# o, B# t4 x
}
}& [, ~ B5 q% W: m- | return 0;
& d& L6 f7 K8 \. I l* J5 n9 T0 v 7 M$ l! p. L( G' m# f! N0 ]
}
) r) d5 w9 ?* I' a2 f7 z0 o: ~
' o% ], r# S" I9 n3 W& Z多谢各位指教,谢谢! 急
2 @& _. [) ~; b8 i% g4 Y
6 L* v3 b+ Z! V9 w& m. n- Q* ^7 e- a/ O8 _" a$ ]
" }* i- N* u( y: H
" h. C( t# k. o2 j
M# [* ~/ Z/ t2 w0 M! ~& m' B9 ?& y |
|