|
我讲创龙在DSP中使用的例子移植到ARM中,如下是我的底层驱动程序: * [) R# @/ C8 D0 z
/*
8 o7 n3 Q: u i! q * Copyright (C) 2009 Texas Instruments Inc
8 h+ p7 x3 {5 w R' f# J *& P/ b* G6 X+ h3 E
* This program is free software; you can redistribute it and/or modify
! ^7 L1 A% I- j5 T9 z# G * it under the terms of the GNU General Public License as published by
1 M3 B# o. d% _ * the Free Software Foundation; either version 2 of the License, or
7 k" G3 c" N( i * (at your option)any later version.
( i- e* ~) ^6 k$ j% x$ o1 N *
8 q" T* b Z$ i6 ]( E# j7 L * This program is distributed in the hope that it will be useful,, ^& ]; ~7 h# W
* but WITHOUT ANY WARRANTY; without even the implied warranty of
' R( O* p; k$ O$ \ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 [; T+ @, h# W * GNU General Public License for more details.
) T$ H; G1 {, A! q: T, R *1 [ v* |( C* c4 t
* You should have received a copy of the GNU General Public License
l% o. v! {% L. h * along with this program; if not, write to the Free Software
, f- r. P9 F, [ * Foundati
: [7 x) G( ]# w6 @*/% L5 G, u6 {. V( p: s/ L
#include <linux/module.h>
0 F% {# X7 i0 u. }. }/ t#include <linux/init.h>5 C0 G+ |2 `0 ^- t \$ P7 T
#include <linux/errno.h>
& @) c8 _. q8 D4 x5 p#include <linux/types.h> |" M0 F; h$ @& e
#include <linux/interrupt.h>
" c! T/ w6 {7 ?& b+ K#include <linux/io.h>. |3 h+ U% }$ U/ V" N/ |/ G
#include <linux/sysctl.h>
7 N5 j7 M& e5 y#include <linux/mm.h>
) b' p2 w1 A, h2 t#include <linux/delay.h>( z! t& e8 ]7 x A' }. U
#include<linux/kernel.h>
" u3 L) B- L' h/ G5 M# |#include<linux/fs.h>0 o$ X9 y( E! f0 ^
#include<linux/ioctl.h>
6 X$ F) V" D+ n#include<linux/cdev.h>4 X0 V: U% R4 r. i) O3 }
#include<linux/kdev_t.h>
: u' F2 W# q* R8 e2 k; U#include<linux/gpio.h>: Q: p& x: N' x' h
#include <mach/hardware.h>
$ T b/ D- q8 b: |3 _3 K: ?& m" j#include <mach/irqs.h>8 `$ z# w9 F- o4 g
* Q: \. x7 Y# L: z6 x" l6 h#include <asm/mach-types.h>
0 H; l$ B% `0 A: \0 ^; f! o#include <asm/mach/arch.h>7 d) w( Z* U& p
#include <mach/da8xx.h>9 A# N* t2 a5 }3 E& ]* Z _4 k
#define SYSCFG_BASE 0x01c14000
' Y* z* Z8 [, W#define PINMUX1_OFFSET 0x124
" P2 t# D) ]4 i0 O" ~#define PINMUX18_OFFSET 0x168 v2 Q' Q# P+ x3 |6 R1 O: C
#define PINMUX19_OFFSET 0x16c
; b1 p7 d. F q9 w+ v) K9 r#define SPCR_ADDR 0x01D11008 //MCBSP1_SPCR
& x8 q% q+ F7 n8 n3 J$ Q+ q#define RCR_ADDR 0x01D1100C //MCBSP1_RCR5 B1 W" f2 v: w( x" j$ h1 ]2 p
#define XCR_ADDR 0x01D11010 //MCBSP1_XCR
/ v. _3 j* v U# a; x#define SRGR_ADDR 0x01D11014 //MCBSP1_SRGR
) L! t/ c4 I, [5 n& S. y#define PCR_ADDR 0x01D11024 //MCBSP1_PCR
! _! e4 F- {$ ]7 ]6 B( |+ @( z ( h% h+ t0 p, z/ D+ _& y
#define DXR_ADDR 0x01D11004 //MCBSP1_DXR# H. m! ?7 |7 Z
#define DRR_ADDR 0x01D11000 //MCBSP1_DRR5 |$ i/ r8 _ q2 K
//PSC
! c# y+ c; ~ u& j$ y' B#define PTCMD_ADDR 0x01E27120 2 L" K" N- x4 q, x! y% p; L
#define MDCTL15_ADDR 0x01E27A3C
: ^: c9 G9 C, A' C#define PDCTL1_ADDR 0x01E27304/ @# W h# A) R4 x
//GPIO8 direction
% ?2 t: d5 t( l' I; Y* L#define GPIO8_DIRECT 0x01E260B0
3 M5 J- J) C3 V) _2 D0 k4 S# i#define GPIO8_OUT 0x01E260B4, G, E) r% E# }" d0 h
#define GPIO8_IN 0x01E260C03 n' ^5 A' \- |1 o) j- G
' b1 r* o# L) r& O3 |
//#define MCBSP1_RINT 99
- U9 S8 y7 q. r4 |" j& U- C2 X//#define MCBSP1_XINT 100 . v; S* ~, ~; I& ~* z$ {# H5 J
static int MCBSP_MAJOR=239;
- v, v3 w6 V+ V8 Gstatic int MCBSP_MINOR=0;, j' D7 v# K- J
static int count =1;
4 n5 X6 o* Z5 I8 J* ^
& D3 n* I( H3 U" c9 ?& Y3 a/ s# }( P5 y3 @#define MCBSP_NAME "MCBSP-device" D Y. ?5 f, A# O+ `8 ^+ ]. H+ W* a
! L) l! V6 v# C$ G& g2 P
static struct cdev *mcbsp_cdev;
* o& J. I& A* v4 q) F1 a4 i! Ystatic struct class *mcbsp_class;
! S5 |. U J8 x' Jstatic dev_t mcbsp_dev;
, i5 P) U+ t8 [: Runsigned int DRR_data;
; q" x6 j/ D& d/ nunsigned int DXR_data;- P x: G$ E3 ^! X8 Z' F
static int mcbsp_open(struct inode *inode,struct file *file)% f4 q( w/ J% G/ _& w: v
{
" h6 w4 D, h9 F9 J1 v8 J2 I & Y1 D6 ^/ Y' Z' _
//interrupt enable,initialized
) A1 _2 U0 {0 v7 L5 h E2 b" s unsigned int temp;
- J6 m2 c H: m) K, y5 }, j: w //SLEEP_EN(GPIO8[10])---0
+ g. |! ]3 A( d temp = __raw_readl(IO_ADDRESS(GPIO8_OUT));
- m! J. v6 S0 F0 g1 }8 j4 J temp=temp&(~0x00000400);
7 y _1 _( X7 f5 H) B __raw_writel(temp,IO_ADDRESS(GPIO8_OUT));//GPIO8[10]
4 A+ t0 s* B. d //RESETn(GPIO8[8])----0----1$ X9 @& }( y) r3 o/ k/ @, y
temp = __raw_readl(IO_ADDRESS(GPIO8_OUT));
5 k5 q/ L6 W& ~- G! x temp=temp&(~0x00000100);' N: }: {. }0 Y2 U+ v/ _ R
__raw_writel(temp,IO_ADDRESS(GPIO8_OUT));//GPIO8[8]---0
9 u9 m4 {( b2 T/ I$ a1 `5 P& S udelay(100);
' b9 T) j1 S- D8 t4 M temp=temp| 0x00000100;2 ]- K7 @, i! ], `/ B: R+ z4 U" {
__raw_writel(temp,IO_ADDRESS(GPIO8_OUT));//GPIO8[8]---1
/ L/ a# N- R) U. _2 J4 l udelay(100); o& a. J$ K. D. \
printk("open success!\n");
7 h% k6 h) p4 c& e return 0;
0 S) v% M+ l- j' g' ^# a& M' N}2 G0 }/ Y! e4 z: m4 ~) C
. M* }( S1 x7 X3 g" K5 B) Zstatic int mcbsp_release(struct inode *inode,struct file *file)
, D( T E( y# s3 |' L. Z2 E{: q/ p |, c+ h! H
printk("release success!\n");1 E1 Q* L) b$ F$ W: ~ j
return 0;! R" M e) m2 o: m! t. P
}
* u1 J2 @5 f; V. W) ~+ n+ d4 @6 E
static ssize_t mcbsp_write(struct file *filp,const char *buf,size_t len,loff_t *off): C3 c# w; p# ~2 `( B% L4 d$ ]
{) E. j5 o9 u0 W
copy_from_user(&DXR_data,buf,len);
+ o: [- F4 i% J+ X5 x$ }* R( Q4 c iowrite32(DXR_data,IO_ADDRESS(DXR_ADDR)); ' w( S3 W1 d" o6 a/ ~$ Y
return 0;9 Z3 @9 |6 b+ E6 _! o5 u
7 `0 `9 y& u* ?; \}
1 {/ V4 {( V5 C1 P* J2 e2 r: h1 e0 _( B
static ssize_t mcbsp_read(struct file *filp,char *buf,size_t len,loff_t *off)
5 {& G) K7 }1 B& f0 j{ 4 E2 d6 J- y: [, ]5 [- b9 E1 p
DRR_data = ioread16(IO_ADDRESS(DRR_ADDR));
9 K' i; A! a! N/ k copy_to_user(buf,&DRR_data,len); 5 G) A9 r) a6 L( h: s
return 0;
. [% p+ v4 m% g" K}
1 F. d; W; n3 n B
x7 z! |& F C1 W* Y* \1 U( q
8 X" P+ e o( |! J1 E4 p5 \static struct file_operations mcbsp_fops=' x% Q5 K# N8 N( l6 l
{
) D% ^& Q9 n7 ]4 }: b. u .owner=THIS_MODULE,
- k7 R @2 n4 \" b: h8 Z1 I .open=mcbsp_open,/ @# a/ i3 [4 G; d) V
.release=mcbsp_release,
: R# C& Y$ t3 ` N# _2 x# @3 X .write=mcbsp_write,
* }6 \! R% B, Y: Y1 G .read=mcbsp_read,/ g. s8 V+ d; {* V' ~
};
& Y, D- X: L; M' i) {% {$ @( X1 o1 [static int __init MCBSP_init(void)2 u$ U, P Z) G
{
% e/ ]$ `$ W3 S int ret;
% {7 Q) t$ G' e- z2 b' b unsigned int PINMUX1_REG_old;7 c% u. S5 ]# |7 `
unsigned int PINMUX18_REG_old;
5 Y7 D1 F) f8 M+ t8 d unsigned int PINMUX19_REG_old;
% F" f1 ] s/ l% ~) Y unsigned int temp;
0 T x2 M( j* O! o4 J' q! g if(MCBSP_MAJOR)
8 F: ^+ u$ c o) K" { {
& g& U$ h x- ^0 U6 W/ g1 U& } mcbsp_dev=MKDEV(MCBSP_MAJOR,MCBSP_MINOR);
5 l- R- X5 b! |& \/ w$ F# w- D ret=register_chrdev_region(mcbsp_dev,count,MCBSP_NAME);
9 U, G. \$ h% } }4 N' c, X% n0 ~/ U) r9 `
else
) _2 P% M0 r3 d {
' u) ^! ^4 d/ _4 t7 p# g3 }" T ret=alloc_chrdev_region(&mcbsp_dev,MCBSP_MINOR,count,MCBSP_NAME);+ d k( A6 K, L" d9 ]# \
MCBSP_MAJOR=MAJOR(mcbsp_dev);5 V. ?! W* P: Y6 K$ T9 r
}% _* r/ I0 Z" _% O: \3 Y
' ]# Y1 @; ^2 q$ ^ if(ret<0); V9 G' `) s- E- f' I- y: Q
{
8 J" y5 Z; G% H1 C. k printk(KERN_ERR "register chrdev fail!");, ^' l- `$ R5 K3 W3 B3 D# v
return -1;
+ \: x/ m, q K- G! N }
# m2 ^ i' R. B* N
/ e' V0 }2 K0 D' B1 m mcbsp_cdev=cdev_alloc();
, ^& g3 |+ e A3 L7 y8 {% D: D
* U3 i$ C" h' I3 {( H8 V if(mcbsp_cdev!=NULL)8 T0 i1 q2 W q
{
. p4 O7 Z r: O A2 N; b5 H cdev_init(mcbsp_cdev,&mcbsp_fops);* z; x7 v) L$ n# k- x5 m# @
mcbsp_cdev->ops=&mcbsp_fops;1 f! j: H% z& @1 q( F' {
mcbsp_cdev->owner=THIS_MODULE;. N8 w, z) T7 @0 D( d
0 G0 A8 X/ @( k
if(cdev_add(mcbsp_cdev,mcbsp_dev,count))
. m( ~6 G9 \# @' o printk(KERN_ERR "register cdev fail!");+ }: t; C2 l# l! X8 G7 S
else+ l3 `* g' L( f/ B* M
printk(KERN_ERR "register success!\n");7 c" @) h; Z# l- a2 i6 e
}$ D/ }3 h* J6 r1 b ?! Y n
else% a) N+ B% D6 P5 {; v
{: D: e* u2 D$ s- Z. y) W3 J
printk(KERN_ERR "register cdev err!");
0 I0 G- \! X0 F! K3 w, ~" Q return -1;
4 [4 D% m m) C* L1 W1 R7 t }
2 Z& o8 r+ g( J/ a: ]' I 7 J9 D2 i* b" N4 n; L |( o! p
mcbsp_class=class_create(THIS_MODULE,MCBSP_NAME);
8 y8 C" V" |( y. s if(IS_ERR(mcbsp_class)); ]4 l' ?* h: @8 n2 S) F' r
{
5 Y, Q1 V7 f& B3 T: B printk(KERN_ERR "register class err!");
" j3 S1 ?$ E3 \5 ]$ B return -1;% q: l4 H+ a1 ?5 ] `+ m, U
}
. V5 S" }0 y5 _( S device_create(mcbsp_class,NULL,mcbsp_dev,NULL,MCBSP_NAME);
4 U# Q9 W9 U% ~6 ?4 w$ ~
@6 h& }5 E4 U% S; f. P$ U //PSC
4 r8 a! D: q3 i( F //add Enable MCBSP$ a% {8 I( `& q" q8 P) Y+ I0 u
//test
* _( i$ P: U, J% j8 y: p/ ` temp = 0x80000003;
2 q7 s' Y: P& f$ s" m) B2 S writel(temp, IO_ADDRESS(MDCTL15_ADDR));
& O. D. _# ]8 G temp = 0x00000003;
1 l, \! e% v, v0 W writel(temp, IO_ADDRESS(PTCMD_ADDR));
# b2 I5 H1 x6 h. J5 C/ \, Q- Q3 I
# d% J3 k" z! K: q) O temp = 0x001FF201;5 \" `/ q5 B; V. z
writel(temp, IO_ADDRESS(PDCTL1_ADDR));
+ v- @1 i I2 ? c0 v/ ` ' \ i; O l5 r# B! Q
//PINMUX 8 h" u3 N1 Y0 ?! @$ u w1 o, ]3 C
//MCBSP_CLK(receive/send),MCBSP_STRB(receive/send),MCBSP_DX,MCBSP_DR,; G5 {8 ^3 h, b" R
PINMUX1_REG_old=readl(IO_ADDRESS(SYSCFG_BASE)+PINMUX1_OFFSET); , r' C* E9 l; n" W
PINMUX1_REG_old=(PINMUX1_REG_old&0xf000000f)|0x02222220; ) ?& b7 Z; N5 f# |0 I7 _; y
writel(PINMUX1_REG_old, IO_ADDRESS(SYSCFG_BASE)+PINMUX1_OFFSET);0 o `+ r. n1 h$ g6 \8 G
% S# D$ N7 g7 V. O2 @2 r, i+ g, |
//SLEEP_EN,EPR,L138_SHK1,L138_RC
6 k9 I X" ?5 Y: [ PINMUX18_REG_old=readl(IO_ADDRESS(SYSCFG_BASE)+PINMUX18_OFFSET);
, }4 E8 w X5 J3 J/ l0 }4 Z% S PINMUX18_REG_old=(PINMUX18_REG_old&0x0000ffff)|0x88880000; e; G$ Q" ^' ~& Z
writel(PINMUX18_REG_old, IO_ADDRESS(SYSCFG_BASE)+PINMUX18_OFFSET);
# w6 G& V3 G; E! f; J# N7 C
) b5 Q0 Y& h# v% c/ _+ A! V //RESETn,L138_SHK2
8 L, \. S+ H/ [% ? PINMUX19_REG_old=readl(IO_ADDRESS(SYSCFG_BASE)+PINMUX19_OFFSET); 5 ^) K( _' Q0 V9 S" \
PINMUX19_REG_old=(PINMUX19_REG_old&0xf0ffff0f)|0x08000080; 3 ]# C8 g8 Q3 ?7 w
writel(PINMUX19_REG_old, IO_ADDRESS(SYSCFG_BASE)+PINMUX19_OFFSET);% o5 ]. e% d" [0 u9 i
* w6 r' L7 m. }
, c* r# Q( T5 M S8 G R/ d* [ //SPCR Register
$ _( V( N6 L+ L; D. R //FREE-1,SOFT-1,FRST-0,GRST-0,XRST-0,RRST-0,RJUST-00(Zero-fill MSBs)reset9 K: D+ I6 y9 q" i+ M! J# ]
temp = 0x03000000;//(DLB=0)( L0 ~- d6 B" R% [% ^7 R
// temp = 0x03008000;//(DLB=1)$ h" y/ c5 \! O. ^; j$ j
writel(temp,IO_ADDRESS(SPCR_ADDR)); //reset
" n0 \1 A ]* r; E8 A, s, ` temp = readl(IO_ADDRESS(SPCR_ADDR));6 c1 @3 c+ Y8 ]8 _- D
printk("temp=%x\n",temp);& m3 h' P' S4 \$ v6 C
4 d+ a% |" f& F) ^0 T; G U3 G
//PCR Register
5 m, z% Z$ f3 O0 B- Z //FSXM-1,FSRM-1,CLKXM-1,CLKRM-1,SCLKME-0,FSXP-0,FSRP-0,CLKXP-0,CLKRP-08 L8 F/ i; l( K' w
// temp = 0x00000F0F;5 U% V! E- {" d5 g
temp = 0x00000B0F;
7 m, _, m4 ]; W$ b% ^3 w writel(temp,IO_ADDRESS(PCR_ADDR)); //initialized 5 J9 G# P7 `. c# |
temp = readl(IO_ADDRESS(PCR_ADDR));3 t6 s, d" B+ o; N; p: `
printk("temp=%x\n",temp);
$ J+ A( m2 V, d, i" m; ` //SRGR Register
5 J) {% i- K# j7 [! d //GSYNC-0,CLKSP-0,CLKSM-1,FPER-31,FWID-0,CLKGDV==11+ }( ^7 p1 l7 w7 x M
//temp = 0x301F000B;7 J, B/ s: X+ ]/ j# e/ D
writel(0x0301F000B,IO_ADDRESS(SRGR_ADDR)); //initialized * ^$ s/ {0 Y' G( I8 U
temp = readl(IO_ADDRESS(SRGR_ADDR));
$ d' v5 ~. l. j' w2 V1 H# Y printk("temp=%x\n",temp);0 [ { Q% }8 A; b3 d/ L
//RCR
8 d. {6 H9 q- g3 X6 l7 P //RPHASE-0,RFRLEN2-0,RWDLEN2-2,RCOMPAND-0,RFIG-1,8 c, _; L9 ~0 n. M% }# R; R
//RDATDLY-0,RFRLEN1-0,RWDLEN1-2,RWDREVRS-0: c4 s6 ^# @! J: ]1 `& E
temp = 0x00440040;; o5 c: @; e. [1 Z1 p0 D7 r" u1 _. A
writel(temp,IO_ADDRESS(RCR_ADDR)); //initialized
/ v! N* l" @- T- J temp = readl(IO_ADDRESS(RCR_ADDR));3 o# r4 z8 E8 p7 p& H* M
printk("temp=%x\n",temp);! K- l0 M9 M( y' }! s1 O: N
//XCR1 [, e @% H4 [1 ?
//XPHASE-0,XFRLEN2-0,XWDLEN2-2,XCOMPAND-0,XFIG-1
4 J6 a2 n1 c+ o2 V' [ //XDATDLY-0,XFRLEN1-0,XWDLEN1-2,XWDREVRS-0 z) q! Y) W4 Z& J4 z! y$ X+ b4 P- W3 g
temp = 0x00440040;1 c: d( m. M5 O, t
writel(temp,IO_ADDRESS(XCR_ADDR)); //initialized
: I) k8 R* J& l+ b0 v6 ]" d temp = readl(IO_ADDRESS(XCR_ADDR));
& C6 E6 O8 U1 @+ V U printk("temp=%x\n",temp);
) B: \+ c7 _3 a! T udelay(100);
7 y4 Y3 a8 ^- o# I1 _4 j% ~+ r //SPCR Register
4 l! c# D( Z1 T5 w //FREE-1,SOFT-1,FRST-1,GRST-1,XRST-1,RRST-1
# d* M* u- F' \! Y/ q* a9 r temp = 0x03C10001; //DLB = 0 VS DLB = 1* D/ Y/ n9 u% N4 O. _) ?
writel(temp,IO_ADDRESS(SPCR_ADDR)); //enabled
# ^" k2 X- v9 V9 m \7 K4 e) z; K temp = readl(IO_ADDRESS(SPCR_ADDR)); L! m. g" y1 \, {, a. |8 U
printk("temp=%x\n",temp);& [5 d2 g# O7 s, p$ F( v
udelay(100);
( J. \, J( T6 f$ y5 t
) g( M, `& W# b$ ?7 u3 b6 h1 A& t //set GPIO direction: K1 g. P2 z( z
temp = __raw_readl(IO_ADDRESS(GPIO8_DIRECT));
4 j$ z/ k2 R# d: I" O$ t- U temp = temp | 0x00000100;//EPR----input
- ^ ~7 @, v/ X! q9 T3 Q temp = temp&(~0x00000500);//RESETn,SLEEP_EN---output3 W/ R5 ]( I* W0 t0 B
__raw_writel(temp,IO_ADDRESS(GPIO8_DIRECT)); 9 K0 t6 [$ i [ y# R) v; D
5 }' A7 E% E5 C8 O% j: A return 0;8 n& l, J0 K( }* a4 j- V8 ?1 W5 m, N
}
& A" E0 p2 g5 E% o6 Z k0 }/ R3 Y% vstatic void __exit MCBSP_exit(void)
% {$ M$ c4 _1 ~' e: z{
' N0 c* @0 C! t1 h0 Z% V- Q' e printk("mcbsp chrdev exit!\n");
+ d: v$ P+ a8 W m4 S cdev_del(mcbsp_cdev);% ^. w4 D$ Q: l, J4 ~; a2 t0 V
unregister_chrdev_region(mcbsp_dev,count);
6 Z1 b& W( G! n$ H device_destroy(mcbsp_class,mcbsp_dev);' N" w' i/ l" B A q
class_destroy(mcbsp_class);0 |+ r+ p4 e# Q+ ~ ?. Z6 s. o
}' ?0 H. D2 Q0 p# Z1 K. `& Y( ^
module_init(MCBSP_init);( g5 r h, ~, w2 |) G, {9 d
module_exit(MCBSP_exit);
9 P! `; Q, K- Q, ?) m
2 z. J" |) D* L) t, tMODULE_LICENSE("GPL");
2 W2 V: M# `+ S$ a" e$ w
& v6 N- T; W; e% w+ v) @5 s我讲上面的程序insmod之后我用示波器量 McBSP的发送时钟脚,发送数据脚(我还没有发送数据)以及发送同步脚,3个脚的信号是一样的,不管是用我自己的底板测试还是用创龙OMAPL38 的开发板测试,都是一样的,类似于噪声的信号时钟频率也不对。* z. v8 V: L4 J+ \, a7 `$ _, G! o
我的应用层的测试程序如下4 c. m& X/ [8 ?& { v9 S9 A! I
#include <stdio.h>1 v6 V! A3 o" O" n* r/ H2 z. s
#include <string.h>
U9 O" p8 ?9 K#include <fcntl.h>( M& q* _- E E% o2 [. L# j
#include <unistd.h>* Y0 T+ _& W! P: f7 P: F/ B3 r
#include <signal.h>
" d4 ~" b. g" X2 `, p, ~#include <pthread.h> //线程/ i+ s' s+ S! x5 I
#include <stdlib.h>7 o8 n3 _7 v: S9 b9 S( G: f8 K8 S
#include <pcap.h> //捕获网口数据
" |% ?2 t' j# o) ?5 U" a#include <semaphore.h> //信号
% C, v! }) V Z: ]#include <sys/types.h> //消息对列' Y2 C5 S5 c$ @' M5 K5 e, w
#include <sys/ipc.h> //消息队列
8 K6 d% [4 q) ]0 ^#include <sys/msg.h> //消息队列
3 t" L4 l0 t0 `#include <sys/select.h>, b3 s6 ]+ f4 z+ k* t$ T+ ?
#include <sys/syscall.h>! O% v4 w9 |2 X5 x& g0 l& j F# ^
#include <sys/stat.h>
4 Q, w% B* L0 n M- B8 Z8 H#include <sys/mman.h>
) f L% g! E: d R5 c( \9 c#define msleep(x) usleep(1000*x)+ B1 u. x# q) N. y$ N9 ~, T; ]% \
6 J) ?5 K7 p' D# J
int main()
% U1 V1 t( S4 j+ }% c- M. ?& T9 H- b r{
& C) L q+ Y. Z. E //MCBSP,ARM与AMBE2000交互设备
7 e W7 ?. x) N) u* z# J( a# p+ L# p) N int fd;5 N0 l% a. _! ~5 K2 C% z* r* N
unsigned short data_write = 0x5555;
0 {, R" q* d1 f' o4 d7 W& q unsigned short data_read = 0x00;
7 a& z; ?6 i5 e- q* M" Y# f" { fd = open("/dev/MCBSP-device", O_RDWR | O_NONBLOCK | O_SYNC);
1 x g3 p! [: k( k- ~, D3 e // fd = open("/dev/led-device", O_RDWR | O_NONBLOCK | O_SYNC);
+ M' T6 d0 d2 u
7 t# ~$ M2 z) I- L; \( _ if(fd < 0)
# w; R1 ?: {$ e4 L+ j4 e2 \ {( C# y0 W7 W8 a! c
perror("open failed\n");
6 }3 L3 x- t# t) r# z. h return -1;
/ e5 e {; N+ y# C! r3 d [4 Y }# o4 Z `( T% G
& _7 F, ^! o' H2 F* ] while(1)* q1 [, [9 f( l3 k* A
{
5 V% s0 H4 a* Q. E7 K% w( m4 C/ N0 F8 k2 b
8 s# _& H" u0 k& `6 y! e //AMBE2000每次读写是24个字为一帧' w4 N5 c' r1 G% q1 f2 c! D& B
//写数据时将数据在底层存储起来,等到中断的时候再发送0 U! {8 G# O/ `. i5 `8 v! l7 X! U
//AMBE2000输入数据是以0x13EC开头的( a9 X! ^* x- t$ M
write(fd,&data_write,sizeof(unsigned short));
" N+ o( k1 J7 k: K 8 |" k3 P3 F6 Z* F( ]3 T% j
//读数据的时候,在底层中断中将接收到的数据存储起来,然后再传送到应用层
. [# d% \. j$ o+ _% g* j/ q read(fd,&data_read,sizeof(unsigned short));
+ a6 b5 O* ]' g% u
- O" [/ P8 a$ E6 P6 U if(data_read == 0x13Ec)
+ P" f w. p) G& [3 Q" D2 z$ m S {$ ^8 M% y ~$ ~/ u9 x
0 ?+ i3 q4 ~+ C/ C8 H4 n: z printf("data_read = %x\n",data_read);
9 @3 y6 |2 g6 {# S9 U3 [ } e9 C$ J! {9 Y1 [! ?& G- Y- H
* C* e- G2 J, S) a msleep(10);
\- L7 q. R* F6 _! M# c ! }) c7 ~- X4 _: h) W$ ]
/*! e+ b1 d, k( w# d& Y# F
ioctl(fd,1); 3 s7 a* \1 r$ a1 v
sleep(1);
6 E! l( c: S9 G8 R ioctl(fd,0);
$ p# O0 V9 V( X' E' c" i% M, {/ x: I sleep(1);( @8 G" R3 u$ z" Z
*/
5 y9 L0 i# D6 L+ Z } " ~' m$ ?. L- H2 K3 g( h
return 0; D' _- @' w& q6 B
K: N# [% t' b0 y9 F
}; P3 ?8 k6 Z& t7 Q! T% j- A
! k( ~( u% |6 [' w多谢各位指教,谢谢! 急1 ~& V3 T% z6 z5 {
# \ |4 k& P3 o+ O# W \- o' r: ?$ }* y7 g8 l+ N
8 f7 j1 U( C) D/ k0 x# V+ }$ R
! B8 b' |. n( W$ |1 o' e$ R* G/ c4 x! H# U4 [+ K# i
|
|