McBSP时钟、同步、数据线不正常 - OMAP-L138 - 嵌入式开发者社区 - 51ele.net
设为首页收藏本站

嵌入式开发者社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 5406|回复: 0
打印 上一主题 下一主题

McBSP时钟、同步、数据线不正常

[复制链接]

6

主题

7

帖子

58

积分

注册会员

Rank: 2

积分
58
跳转到指定楼层
楼主
发表于 2014-10-16 10:58:57 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
我讲创龙在DSP中使用的例子移植到ARM中,如下是我的底层驱动程序: $ l, l' S1 |' W5 S$ {2 f$ O# M
/*, t% K3 n0 T0 a* T! x
* Copyright (C) 2009 Texas Instruments Inc" c" |. a- m7 X& l( x! q
*
% ?3 C5 G) M/ P4 A* g9 h; B * This program is free software; you can redistribute it and/or modify& N! {6 V9 C) T
* it under the terms of the GNU General Public License as published by/ f9 `# ^2 Z0 P+ @- C4 A4 T
* the Free Software Foundation; either version 2 of the License, or
. b  u% p4 ]) E5 ]6 c * (at your option)any later version.7 D' z+ B' I" G6 C4 h9 T# j
*
7 }8 C" k- p4 b' R  p * This program is distributed in the hope that it will be useful,
  n  @( V$ i) ]5 J* m7 ^& K * but WITHOUT ANY WARRANTY; without even the implied warranty of
8 |  E& @7 l+ @7 H+ M * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6 B- Y$ _/ ]- S; |$ [2 w, \, _ * GNU General Public License for more details.7 r- ]3 W; _* k( I4 d
*; c9 K1 Y' G7 S  [  Y, O
* You should have received a copy of the GNU General Public License$ k. f8 ^1 b% v3 k7 J; b- t
* along with this program; if not, write to the Free Software
: J  T7 q/ G: R- U; Z * Foundati
6 r% ~; a+ L! O  M5 F8 O' g* m*/
# {' p! K4 Q! H! a* L$ m#include <linux/module.h>
& O( x0 M2 Z# M#include <linux/init.h>1 P) I  A8 k# t1 }& w: M
#include <linux/errno.h>) u/ X3 w8 a, g1 X
#include <linux/types.h>
  ]9 S! d! Z# ]/ H#include <linux/interrupt.h>
, Z( q* D  L( I9 ~#include <linux/io.h>$ r2 ^2 x% P) D- F
#include <linux/sysctl.h>
8 p% A7 e8 _6 b9 z2 \% N#include <linux/mm.h>
1 G9 ^) J( F, O& P#include <linux/delay.h>4 c7 T- k5 @6 d. x, C
#include<linux/kernel.h>
1 O, t2 S4 t: y! B" m" c#include<linux/fs.h>" J+ u/ c) L& W- P* D, p; ^/ G8 L
#include<linux/ioctl.h>+ j. f  a8 k" {5 R8 h" V7 n
#include<linux/cdev.h>6 Z1 b( R$ S' X' w, s2 ]; `
#include<linux/kdev_t.h>2 z" B7 P: u' N6 [/ q- @; x
#include<linux/gpio.h>
' H8 x! o; j! m#include <mach/hardware.h>7 ^5 S, M$ B. w3 C$ K" O0 x
#include <mach/irqs.h>& H9 U' f# h1 a% r! _2 v

# e; y* ?5 t3 {  P! I. o#include <asm/mach-types.h>
+ M. H  X# K* J9 T. R1 u) \#include <asm/mach/arch.h>
0 ?" Y* Y) N) |4 s#include <mach/da8xx.h>
7 ]; a% r- e- j' f5 z- y- X#define  SYSCFG_BASE   0x01c14000
2 S# \) [+ F5 w7 h8 ^#define  PINMUX1_OFFSET   0x124 7 r5 Q( Q9 o% H
#define  PINMUX18_OFFSET  0x168
. Z4 h8 _, Q5 r& H: P( @! K7 V1 t0 o#define  PINMUX19_OFFSET  0x16c8 b' B7 k1 t7 s- M# e8 d
#define  SPCR_ADDR    0x01D11008  //MCBSP1_SPCR. q- Z/ }0 v; _1 _( q& {1 K
#define  RCR_ADDR     0x01D1100C  //MCBSP1_RCR
% \0 h" H- d5 ?# `#define  XCR_ADDR     0x01D11010  //MCBSP1_XCR
6 k# d* k9 _6 T+ o#define  SRGR_ADDR    0x01D11014  //MCBSP1_SRGR
' C! ?( q9 x+ h* t! a  H#define  PCR_ADDR     0x01D11024  //MCBSP1_PCR
/ B# ^8 A+ D, |' z; }+ ^                           
% C1 V* W( x: h/ K6 X#define DXR_ADDR      0x01D11004  //MCBSP1_DXR
' j8 @' O: |8 Z#define DRR_ADDR      0x01D11000  //MCBSP1_DRR- {; r) l: E( K+ Y
//PSC; X" P( e; U: C0 C
#define  PTCMD_ADDR   0x01E27120  
% q+ d5 \) m0 Z, E#define  MDCTL15_ADDR 0x01E27A3C$ h- I' y' H: y* W* \
#define  PDCTL1_ADDR  0x01E27304
2 @* A+ N6 O$ ]+ `6 r/ `//GPIO8 direction' U' d4 z! N8 I* {5 T3 Q/ W
#define GPIO8_DIRECT  0x01E260B0
9 G% _' r1 G* r( w6 m3 ?, A7 F#define GPIO8_OUT     0x01E260B4
1 h% h9 J1 Z# c% A3 ?#define GPIO8_IN     0x01E260C0
1 H9 p  L* u" s, l+ d
6 O* U* [* `+ B2 ?' Z; y//#define MCBSP1_RINT    99              
( i) _. N4 l3 m: V+ }//#define MCBSP1_XINT    100  
+ B2 {$ ]# j5 ~  X2 Mstatic int MCBSP_MAJOR=239;* o; a2 o% ^( ^0 q
static int MCBSP_MINOR=0;' W" b, m' W) ?
static int count =1;! R. N4 {( F& k  @3 E/ T7 O; H" ]$ |

, c* l; ]1 P4 i#define MCBSP_NAME  "MCBSP-device"
! ^* U! ~# n, X% W* I: X% J: ^/ n, ^  w" m8 ^2 w1 z
static struct cdev *mcbsp_cdev;9 M0 y3 e* `- Y  b5 v; T4 c( K
static struct class *mcbsp_class;" k( d+ n. a/ D6 n6 ?
static dev_t mcbsp_dev;
, ?7 s1 q2 Y7 j% runsigned int DRR_data;* A, y7 h/ Y- n# \7 R" ^
unsigned int DXR_data;
/ S( U/ s% o; c/ g2 I4 _) Ystatic int mcbsp_open(struct inode *inode,struct file *file)% k! m" H+ k6 w7 @6 [) b3 O  j9 o
{6 j, y! w+ B7 J% R, z' S' ^1 N
   ' h4 j4 J) W5 c7 v% f
   //interrupt enable,initialized
. P9 |4 o% U0 {: s+ N* `  x4 B1 ~   unsigned int temp;2 w4 y1 ~, T0 c- e) n5 G
   //SLEEP_EN(GPIO8[10])---0
. A/ h/ z. n% c% }9 q! u. y0 c! S9 Q   temp = __raw_readl(IO_ADDRESS(GPIO8_OUT));( U8 f* q" m7 Q, ?0 T
   temp=temp&(~0x00000400);
( u2 M7 h& _' a/ ^* |! g7 N   __raw_writel(temp,IO_ADDRESS(GPIO8_OUT));//GPIO8[10]
/ b- r' ]' l9 u  //RESETn(GPIO8[8])----0----1
0 u6 v- S! y8 n: E   temp = __raw_readl(IO_ADDRESS(GPIO8_OUT));
! W: V3 t( o5 b7 b3 x$ W& v: A   temp=temp&(~0x00000100);
2 [9 m0 G* L  D; I. q. y4 @   __raw_writel(temp,IO_ADDRESS(GPIO8_OUT));//GPIO8[8]---0  Z! f5 X2 W: r/ w5 |
   udelay(100);4 d; u: T( @" s3 V- }
   temp=temp| 0x00000100;
7 y& R7 u1 t3 W* {   __raw_writel(temp,IO_ADDRESS(GPIO8_OUT));//GPIO8[8]---1+ }4 h( M9 f: d, F
   udelay(100);
& ~! i( g$ f" G( k8 z   printk("open success!\n");6 T" [. x; W8 k$ H# m. u
   return 0;- \: j* `( a* ^7 ]; t* _& g1 O
}
" o8 W) [% z" U( V: P: m# B8 r9 ^
static int mcbsp_release(struct inode *inode,struct file *file)
0 @  U. r& j3 q9 \# @{" ?  r8 n! O8 J% m) b
   printk("release success!\n");
/ ]8 V8 S6 V5 \   return 0;$ K/ C' y8 i  x' o, [
}
; m4 K2 I0 q5 k4 f
+ C$ f; c  U5 Qstatic ssize_t mcbsp_write(struct file *filp,const char *buf,size_t len,loff_t *off)
1 C' K3 Z1 n( Y, _& Z, H{& b2 J& w3 q, E4 u
    copy_from_user(&DXR_data,buf,len);5 n9 V* V2 [% c+ J6 d
    iowrite32(DXR_data,IO_ADDRESS(DXR_ADDR));      
( z& O5 [( t% [5 J$ U1 G    return 0;  i; |4 T# y* Z
# \- z0 E: @  t$ b) @2 o) E1 `) w
}
. {, G/ p! P+ x) K; k. g0 m  Y- F* t
static ssize_t mcbsp_read(struct file *filp,char *buf,size_t len,loff_t *off)
4 ^  }, g/ \* z2 z. A- y" x{
" L$ _& p  I$ c" i2 }- V   DRR_data = ioread16(IO_ADDRESS(DRR_ADDR));0 q4 T% ?! B  r( [  G/ o2 y
   copy_to_user(buf,&DRR_data,len);
. d- i& w: A. I( K$ n   return 0;" K, e, b* K' Y7 y
}
; n& y3 l( q/ l" c# G9 ^2 U+ j& u! v1 M

' y8 g- N  l' A" E# Wstatic struct  file_operations mcbsp_fops=, O% g" ^' y, w3 j+ j: u7 [4 V+ @
{5 n' Q, I1 j. R$ M
   .owner=THIS_MODULE,
4 M# \* Q4 E! a   .open=mcbsp_open,7 s- m+ Q4 G, ~( a( D4 o
   .release=mcbsp_release,
/ a2 @% M; b: k% p9 L- k2 P   .write=mcbsp_write,# ~& O/ M8 R  ~# o* K8 M. n
   .read=mcbsp_read,
& T3 O6 G* ]( N( `8 G5 O};# {( v6 Z* h0 T% `. z7 P
static int __init MCBSP_init(void)
6 v" b1 o) _4 r  i{
! `+ I/ P. Q9 s; h   int ret;# ~7 m8 L, X3 m& g, Z9 v
   unsigned  int   PINMUX1_REG_old;% {) i# j$ |! |! {* h
   unsigned  int   PINMUX18_REG_old;+ X+ }# }3 z6 g( }
   unsigned  int   PINMUX19_REG_old;
* B" D2 X8 ?& }5 R& }: A# I! [% }   unsigned  int   temp;  
6 m0 Q+ ^- W7 D) i, s; ?   if(MCBSP_MAJOR)
4 e) V0 g$ S* y& U5 V- x   {- Y/ h3 W: N# v
      mcbsp_dev=MKDEV(MCBSP_MAJOR,MCBSP_MINOR);
' r6 e% ~* p- f6 {3 @; Z+ L      ret=register_chrdev_region(mcbsp_dev,count,MCBSP_NAME);# I! P! D8 d3 ]$ v9 w) z/ v0 p
   }$ s( m, ?+ n5 f% a( }' T+ v
   else
1 g' e; c$ F0 q2 Q3 ~' i   {
, g! `2 d0 k" y9 O9 e      ret=alloc_chrdev_region(&mcbsp_dev,MCBSP_MINOR,count,MCBSP_NAME);0 |" _, S" J6 \, E* ]3 A+ ~% v0 N
      MCBSP_MAJOR=MAJOR(mcbsp_dev);
* o, ]7 p! p7 V) v  |; [   }
, u8 N5 l/ P4 T4 P' K   
* t% S) b) u( s' r$ ~- z, V8 w+ ]   if(ret<0)
) ?8 k  P8 o6 T   {4 `" |' _! G5 b  G# J# p
      printk(KERN_ERR "register chrdev fail!");. x! W5 O2 R  ~8 {( m2 M
      return -1;4 r8 o8 e0 |: P% d
   }) d1 s% t, C8 n/ R, Q
   7 i- z+ N! M+ M% G" j& d
   mcbsp_cdev=cdev_alloc();* U2 h9 N- D! y# ~0 Y
   # A! q- l& N  }  L2 \. }; y% i
   if(mcbsp_cdev!=NULL)  d: P7 u+ n! x9 ~
   {
, f2 n) v: ]+ }0 P' p& R      cdev_init(mcbsp_cdev,&mcbsp_fops);
+ [2 [1 H% i. c0 K/ ]3 e; e  U' ~      mcbsp_cdev->ops=&mcbsp_fops;+ [: [7 a7 k8 r/ ^0 e. a3 B
      mcbsp_cdev->owner=THIS_MODULE;
# \! R9 A' r9 [" |      6 r2 c5 f/ D0 X6 ?& @
      if(cdev_add(mcbsp_cdev,mcbsp_dev,count))
+ Z- K4 d8 y# Q$ _( v          printk(KERN_ERR "register cdev fail!");
; m; t1 S0 v  }. K      else! X' F) _# Z& ~$ X" r
          printk(KERN_ERR "register success!\n");4 y' |8 _/ b1 F- U" e: G/ g6 I
   }/ \' l6 [, Y% k  x5 A& Y
   else
3 ~5 A+ ?) T: M: y+ }   {+ c( h" }' o8 ~1 _3 v  d( B' t9 n
      printk(KERN_ERR "register cdev err!");
# x; @0 P5 U5 A- Y9 S      return -1;
( }5 a' o% A3 W+ u; S' w$ ~( p   }
. {1 M& t2 P, S   
8 G1 ^2 c6 \' g0 P/ J, o/ S  mcbsp_class=class_create(THIS_MODULE,MCBSP_NAME);" s) w8 O) v8 ~& c# o+ l' d
   if(IS_ERR(mcbsp_class))
. m  f$ y: a& _- r: ^2 ?2 s   {6 @$ u) N$ A( D& [  ?4 m
      printk(KERN_ERR "register class err!");4 r/ K& D  Y" M1 f, A
   return -1;
) ~) L+ v6 |+ V8 q   }
( Q/ K: W- X: W+ y- L   device_create(mcbsp_class,NULL,mcbsp_dev,NULL,MCBSP_NAME);
# w; l( R. q4 ?( R6 O- V4 k2 W* Y0 Y( I0 v8 A; T6 j: i
   //PSC0 Z3 D0 N8 P$ U3 v  P3 S
   //add Enable MCBSP+ j' b- Y0 |. o* z
   //test  E, E6 V: Y, `' \) u4 J
   temp = 0x80000003;% E3 S. D( Y9 }3 R% q! V' Y6 ]
   writel(temp, IO_ADDRESS(MDCTL15_ADDR));
$ {! g; z: N2 w: N7 b( J5 T% g   temp = 0x00000003;+ C* `/ a' ~! ~0 h, h% l- n" j
   writel(temp, IO_ADDRESS(PTCMD_ADDR));+ U  w$ t- Y7 F$ n6 B9 }7 ]  C

! p! ~+ p7 F5 i) Q5 l   temp = 0x001FF201;
/ G2 V% V' ]7 O- x' C0 \$ ~0 y   writel(temp, IO_ADDRESS(PDCTL1_ADDR));
& b" Z& [! P3 b, w; H   / W' w& V! W$ b; Z/ Y- R6 I
   //PINMUX  
+ f3 \, I- p8 g- |/ Z   //MCBSP_CLK(receive/send),MCBSP_STRB(receive/send),MCBSP_DX,MCBSP_DR,
7 o+ D1 s* l" \1 X   PINMUX1_REG_old=readl(IO_ADDRESS(SYSCFG_BASE)+PINMUX1_OFFSET);  . D5 q5 n3 m* U) M) {/ Z# d- E
   PINMUX1_REG_old=(PINMUX1_REG_old&0xf000000f)|0x02222220;   : a# y* a! i, e! M
   writel(PINMUX1_REG_old, IO_ADDRESS(SYSCFG_BASE)+PINMUX1_OFFSET);
" ^' O* t  ]: b3 \  ^" D   4 L) `0 r$ B, r5 _/ u/ ?0 N
   //SLEEP_EN,EPR,L138_SHK1,L138_RC
1 j7 k+ M7 _/ t7 J; X2 H/ B   PINMUX18_REG_old=readl(IO_ADDRESS(SYSCFG_BASE)+PINMUX18_OFFSET);  
8 \+ n: y/ G# }$ u% P- M& V# t   PINMUX18_REG_old=(PINMUX18_REG_old&0x0000ffff)|0x88880000;   
2 \( w  [& r1 F( P" |5 E   writel(PINMUX18_REG_old, IO_ADDRESS(SYSCFG_BASE)+PINMUX18_OFFSET);9 z% L' F3 I; \7 ?  G7 k
+ O, g1 U" `; L  J6 m8 F
   //RESETn,L138_SHK25 Y' _, X* O$ g, c5 K8 d0 {
   PINMUX19_REG_old=readl(IO_ADDRESS(SYSCFG_BASE)+PINMUX19_OFFSET);  
1 K+ X7 F  y; Y/ t; _   PINMUX19_REG_old=(PINMUX19_REG_old&0xf0ffff0f)|0x08000080;   
: Q6 L" z! }# v9 P   writel(PINMUX19_REG_old, IO_ADDRESS(SYSCFG_BASE)+PINMUX19_OFFSET);
8 R) H9 ?% s6 E' M 8 e4 q* y6 G* t
$ T1 Y1 o% a9 N2 \9 w
  //SPCR Register3 \2 m/ ^9 ~& m; K
  //FREE-1,SOFT-1,FRST-0,GRST-0,XRST-0,RRST-0,RJUST-00(Zero-fill MSBs)reset) U" r9 l  f" T+ m+ a( A
  temp = 0x03000000;//(DLB=0)/ N' q6 B- M' ?  v! e% t; F% N
// temp = 0x03008000;//(DLB=1)4 p0 q+ J$ G4 A: N+ p' |
  writel(temp,IO_ADDRESS(SPCR_ADDR));  //reset2 U. v6 \8 c" E6 o. d
  temp = readl(IO_ADDRESS(SPCR_ADDR));
# {! L: `7 O- y  printk("temp=%x\n",temp);
7 w& @2 i0 O9 b/ W" x% {0 v 5 g0 T/ I" Z' l2 Y) U
   //PCR Register9 d; y, l8 t8 `9 B; ?
   //FSXM-1,FSRM-1,CLKXM-1,CLKRM-1,SCLKME-0,FSXP-0,FSRP-0,CLKXP-0,CLKRP-0) Y9 t9 C, l$ H( b  ]* x/ T
  // temp = 0x00000F0F;
. S) M7 y5 M1 l% W  temp = 0x00000B0F;) Q, V' u, T" I" L
  writel(temp,IO_ADDRESS(PCR_ADDR));  //initialized - L  E: M+ a  s9 ~7 c6 v
  temp = readl(IO_ADDRESS(PCR_ADDR));. {$ h* G* w% q/ W' \5 ^
  printk("temp=%x\n",temp);  
! Z) ~3 M7 Q9 B9 E6 U. R, b0 o   //SRGR Register
2 d* g5 c9 n# L: I% b   //GSYNC-0,CLKSP-0,CLKSM-1,FPER-31,FWID-0,CLKGDV==11! T! k$ Q4 T1 P: B) L6 L3 I
//temp = 0x301F000B;
4 r9 T- @) b5 O( Q# v   writel(0x0301F000B,IO_ADDRESS(SRGR_ADDR));  //initialized
5 ~7 m# r* {9 T, P! t. [  temp = readl(IO_ADDRESS(SRGR_ADDR));" n2 @4 ?; ]5 q& H; I- f  n* J# j( t
  printk("temp=%x\n",temp);/ ]: K: v- [9 P- J
   //RCR2 M7 z6 I4 L1 \/ N6 w6 S
   //RPHASE-0,RFRLEN2-0,RWDLEN2-2,RCOMPAND-0,RFIG-1,& @5 F( @' Y; ]) {
   //RDATDLY-0,RFRLEN1-0,RWDLEN1-2,RWDREVRS-0' i4 @" l9 B3 ?) A. W  b  Y( x! K
   temp = 0x00440040;: [' {/ ~$ A# M
   writel(temp,IO_ADDRESS(RCR_ADDR));  //initialized   1 H! N8 z, g4 d2 @. v6 J! ~
   temp = readl(IO_ADDRESS(RCR_ADDR));# ?3 D( Y  ^3 w, D/ \% j1 B
   printk("temp=%x\n",temp);4 Q% k& l: g% V
   //XCR
: F; M+ m! X# `+ V4 w7 A   //XPHASE-0,XFRLEN2-0,XWDLEN2-2,XCOMPAND-0,XFIG-1% u5 _1 S4 Q3 p: }
   //XDATDLY-0,XFRLEN1-0,XWDLEN1-2,XWDREVRS-03 }* {) ]0 C" e& |( i7 g
   temp = 0x00440040;; b+ w  i$ A: f% l
   writel(temp,IO_ADDRESS(XCR_ADDR));  //initialized   
8 W+ j! G2 i) E  c4 W2 W* O   temp = readl(IO_ADDRESS(XCR_ADDR));
5 Q, E7 \- ]4 Q/ b! i   printk("temp=%x\n",temp);
5 _$ Z3 y5 e& F  udelay(100);% h) X1 I7 s$ x+ T6 U4 Q
  //SPCR Register
1 g. _/ f7 h% y' ~" \+ s  //FREE-1,SOFT-1,FRST-1,GRST-1,XRST-1,RRST-1* I1 W9 O4 x2 R
  temp = 0x03C10001;   //DLB = 0 VS DLB = 1
1 i( ~: C4 c4 }  writel(temp,IO_ADDRESS(SPCR_ADDR));  //enabled, D' ]4 s) b7 G3 O
  temp = readl(IO_ADDRESS(SPCR_ADDR));
' z5 H2 z( K7 F, Z  printk("temp=%x\n",temp);
( y, ?- @, z6 W) s. e  udelay(100);5 J7 l" Z; @+ x( Y; t+ f$ n
" P$ F0 q" c- m0 p' |- N
  //set GPIO direction! T& w, \3 U" E2 f5 p# _( b# N5 E. Q
   temp = __raw_readl(IO_ADDRESS(GPIO8_DIRECT));$ o  ^+ Y: I0 d; m
   temp = temp | 0x00000100;//EPR----input9 |* M, q2 K. S" c! `$ r$ M: a9 o
   temp = temp&(~0x00000500);//RESETn,SLEEP_EN---output  @5 A! O1 q8 s2 Q% }$ z
   __raw_writel(temp,IO_ADDRESS(GPIO8_DIRECT));
! z; o& A3 x* V, }( X6 s , T! c4 b& n. F( ~  J3 ^7 d
   return 0;9 @8 @7 }4 u' q" d; f, f; \
}
/ W* g. R9 b0 @static void __exit MCBSP_exit(void)& O( @1 Y' o0 [, x
{4 b1 ]  F+ K. q' F8 X" Q% T' @. T
   printk("mcbsp chrdev exit!\n");7 M; R% q4 J6 o& k0 Z9 P- b" i
   cdev_del(mcbsp_cdev);
, X' g# W+ Z- P; e  X   unregister_chrdev_region(mcbsp_dev,count);
$ z8 a0 \4 G# t& T. y* @   device_destroy(mcbsp_class,mcbsp_dev);% A  g' k0 U$ Y8 r+ j: W
   class_destroy(mcbsp_class);
* X! ]' i+ [; U% H}5 |5 ~, Y4 W4 I! S- m. ~' _6 d
module_init(MCBSP_init);+ U% C. D. s9 ]
module_exit(MCBSP_exit);
  U5 F: i# f+ |/ J& g; S; ?  J4 s) t- ^7 g6 M3 R
MODULE_LICENSE("GPL");! f/ j  F0 c1 I2 S4 W: b4 G
% z: B2 X# d; Q. p
我讲上面的程序insmod之后我用示波器量 McBSP的发送时钟脚,发送数据脚(我还没有发送数据)以及发送同步脚,3个脚的信号是一样的,不管是用我自己的底板测试还是用创龙OMAPL38 的开发板测试,都是一样的,类似于噪声的信号时钟频率也不对。0 O3 n- f$ z6 d& v6 P7 ?
我的应用层的测试程序如下
4 i; T8 O: g5 @# O7 C: u#include <stdio.h>$ \+ z" H1 B) _& S# G
#include <string.h>
1 I6 P/ E. K; b, R, ^' F#include <fcntl.h>! q# r/ s9 |5 C( P, m
#include <unistd.h>- O5 ]9 i+ q/ r( ~
#include <signal.h>/ [, u" T5 H4 D, F/ ]
#include <pthread.h>       //线程
$ A+ F  z$ k* I  E1 f#include <stdlib.h>/ b/ G( A. m2 Y& c8 k" L
#include <pcap.h>          //捕获网口数据
( @8 @+ Q1 |) X9 H3 A9 l9 B( q6 c- H#include <semaphore.h>     //信号2 H' Z" r" X2 s$ H
#include <sys/types.h>     //消息对列
0 ]2 ?" D) |! k5 U#include <sys/ipc.h>       //消息队列( W1 [8 I5 j3 t: B0 {# F
#include <sys/msg.h>       //消息队列
3 g3 N: z: J( I#include <sys/select.h>( f0 G; [6 \5 i& t9 w$ q' g
#include <sys/syscall.h>, K4 t- w$ q. e! u% c7 w6 L7 \
#include <sys/stat.h>( E" i; H6 l! c5 b* i" a
#include <sys/mman.h>" v' h% [% s' N% l. O! ]6 V2 o
#define msleep(x) usleep(1000*x), j, `; Y; C7 `- `! a0 A6 W

1 c2 r& x: h; D9 P# l0 d8 w& c$ s& Jint main()% u  N" L  a  S7 C) g
{
% Z9 y0 k' V7 V  }+ d    //MCBSP,ARM与AMBE2000交互设备) V- J  \% k3 \
int fd;' t% ?4 x- Z  b- M
unsigned short data_write = 0x5555;2 M7 p$ u5 L/ j+ e9 c* a
unsigned short data_read = 0x00;
7 V$ K* ^0 b5 ^4 H2 n! j  fd = open("/dev/MCBSP-device", O_RDWR | O_NONBLOCK | O_SYNC);
' n4 x& y& w$ [; b9 X( s- a //  fd = open("/dev/led-device", O_RDWR | O_NONBLOCK | O_SYNC);
6 G1 G( a! F5 e7 F% I; d0 U    1 S4 k- J% w9 u# M- U: r  l1 q& B
  if(fd < 0)
5 \, ]! ~+ y) G) S8 X" o  {& }. V9 e- F) ?  f9 b$ ]% l
     perror("open failed\n");
8 J' u' R# a' y     return -1;
2 B1 [/ d  y& k  }& b! ?& Q9 L( d9 V# M9 _0 e6 D
  1 X5 c9 ]* K# p' f1 `' K8 o
  while(1)2 e1 P+ }; K- E5 y
  {# d' m& v( k" D, l
   ( i  H! x$ m7 M7 N; Z  F- m5 d
   //AMBE2000每次读写是24个字为一帧
1 Q1 v$ F& E5 ~2 B  A% g   //写数据时将数据在底层存储起来,等到中断的时候再发送0 U2 G% X- e2 {) n2 [
   //AMBE2000输入数据是以0x13EC开头的
' D7 q, J2 X" n' i; b% u7 `   write(fd,&data_write,sizeof(unsigned short));
% f" C& D2 ?/ V  ~( p   
$ U  a1 H' }" s0 y7 j. _  M   //读数据的时候,在底层中断中将接收到的数据存储起来,然后再传送到应用层  
+ c3 d, L7 s' ?   read(fd,&data_read,sizeof(unsigned short));$ A( i& k4 D2 B! ~! y/ r% C
   - G4 w( X, s$ |7 m0 i
   if(data_read == 0x13Ec)
0 \* C5 H0 `2 e+ Q   {5 ?- b" H' \, U6 Q. S4 `! W
   1 a3 W$ i1 c, M$ B* y
    printf("data_read = %x\n",data_read);$ W" K4 |0 F" }) _9 E9 k, f8 u  I+ @) D
   }
# L7 w# g6 g9 ?% n9 }2 E   
, T% u$ q8 Q( F( O' b( T   msleep(10);& F9 V9 V0 @) r1 U, d9 y
  
  J* t/ v$ B" [! }- @2 J0 {0 m  /*- X2 j8 j2 r+ ^( F' ^8 d! ]
   ioctl(fd,1);   6 V4 y; F/ h" q" {  r' X! _
sleep(1);  h8 J5 w, z# ]. X! \' y
ioctl(fd,0);
# g; X8 n4 Q# D3 r- ]0 F sleep(1);) h1 O/ u' p& l: O
*/ 1 U% h( [  y( N( [7 l, T
  }   5 O! Y5 ^4 a5 D
return 0;
# o: d( P9 E* F . ^' G% ?1 k' I
}
4 Q' s# Z* A- R, S" M9 l* L" P$ t$ g! a  c: H* E7 |
多谢各位指教,谢谢! 急
/ Y" y; k. n3 n# j3 Q# x1 D8 h- ~8 n  V% @; o6 L
3 q8 s7 D" u/ i( @! F

1 b3 @6 u: n0 ^  v  F" h' {- s0 P+ s% k  N  H" e

2 ?5 z% c5 n# J; P% V# u
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|手机版|小黑屋|嵌入式开发者社区 ( 粤ICP备15055271号

GMT+8, 2025-12-2 18:38 , Processed in 0.043538 second(s), 25 queries .

Powered by Discuz! X3.2

© 2001-2015 Comsenz Inc.

快速回复 返回顶部 返回列表