McBSP时钟、同步、数据线不正常 - OMAP-L138 - 嵌入式开发者社区 - 51ele.net
设为首页收藏本站
点击跳转“创龙科技服务通”

嵌入式开发者社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

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

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

[复制链接]

6

主题

7

帖子

58

积分

注册会员

Rank: 2

积分
58
跳转到指定楼层
楼主
发表于 2014-10-16 10:58:57 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
我讲创龙在DSP中使用的例子移植到ARM中,如下是我的底层驱动程序: & L! t5 u" {; K
/*
' G2 u& m# Y( Y * Copyright (C) 2009 Texas Instruments Inc" I9 x9 O& [4 ~8 h, L9 y( O% B
*
0 k5 Z5 s! x2 y1 U, p$ E) k% } * This program is free software; you can redistribute it and/or modify
: c+ S# [( q9 O* @! u% R * it under the terms of the GNU General Public License as published by: t- y/ {8 w  l/ J. \2 M
* the Free Software Foundation; either version 2 of the License, or
# ?  u# _; j9 y+ p; S * (at your option)any later version.
& z  w4 D! L) ~) Q0 W9 N *
  F) t0 h# I( u * This program is distributed in the hope that it will be useful,
& M1 O8 B( N/ N+ n * but WITHOUT ANY WARRANTY; without even the implied warranty of
8 F4 [# _, i, s. Z) A& x * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the( d: d: B! o. t; a
* GNU General Public License for more details.
' U' Q2 N. T7 p# P+ l& i3 Q) c *, D, B$ C7 p) L0 G- W
* You should have received a copy of the GNU General Public License
; `) j1 ?4 G  C" k5 Q * along with this program; if not, write to the Free Software/ x" r- \1 Y/ C- {0 E$ x
* Foundati
& \- x5 y9 q/ ~/ T; }- A- _0 O*/; O7 j+ ?/ Z  b+ ~0 M0 K
#include <linux/module.h>
. B# F7 x3 K" H6 `6 T/ C" j, T#include <linux/init.h>' W! s5 L6 }" u" x- U5 H) l3 u
#include <linux/errno.h>
6 c7 U3 Q" G' ^8 I#include <linux/types.h>
& ~! {5 n8 A) u#include <linux/interrupt.h>
" s4 ?" H2 E3 Y6 F5 V' H9 g: H6 h; U" u#include <linux/io.h>; q- l5 V/ g0 u; @
#include <linux/sysctl.h>2 }3 H# c- G# i2 |
#include <linux/mm.h>1 y. E0 D# H0 M. m  ~' V
#include <linux/delay.h>
* i; S8 d; ?$ c) z8 k9 v9 W5 X#include<linux/kernel.h>/ T9 Y6 U! l) g# W( F6 u
#include<linux/fs.h>
: @. v/ R, `8 }4 }' s9 s  @7 P1 S#include<linux/ioctl.h>: f8 W4 @3 n$ B, @) e
#include<linux/cdev.h>) }3 M& ]' Q. E/ Q# {8 D
#include<linux/kdev_t.h>: g% N: d/ [/ k( [
#include<linux/gpio.h>
. Z) w% N: h' Q2 Z2 l. {7 K#include <mach/hardware.h>0 q+ H+ T& l7 Q
#include <mach/irqs.h>
) ^" R# {3 d% |* y
+ f( k$ y& Y6 ]8 j& Z) g8 b( r5 i3 x#include <asm/mach-types.h>% w* m8 J; V+ o
#include <asm/mach/arch.h>+ n- d% d/ P5 Z' \& R+ B
#include <mach/da8xx.h>. o  s" I4 r& G) M* u7 j9 M
#define  SYSCFG_BASE   0x01c14000
, g+ b+ s3 |6 {- ~) \#define  PINMUX1_OFFSET   0x124
. F2 D  u1 I- C" B0 t0 `#define  PINMUX18_OFFSET  0x168
0 y* X, F: t9 Z% f4 H0 W#define  PINMUX19_OFFSET  0x16c4 `! T) m8 L. q# ?- q
#define  SPCR_ADDR    0x01D11008  //MCBSP1_SPCR
/ V1 f" l! E8 g8 X  d, W#define  RCR_ADDR     0x01D1100C  //MCBSP1_RCR
8 z* h1 P2 r' r+ q% q4 z8 v#define  XCR_ADDR     0x01D11010  //MCBSP1_XCR
- j. u" D# P9 V9 Q6 N#define  SRGR_ADDR    0x01D11014  //MCBSP1_SRGR. ?" P4 m7 ^6 w1 [
#define  PCR_ADDR     0x01D11024  //MCBSP1_PCR& d$ \! f& L. n7 m% W0 y2 h
                           
+ p+ @" i# L3 j#define DXR_ADDR      0x01D11004  //MCBSP1_DXR) u& M9 b  D( L6 }+ Q
#define DRR_ADDR      0x01D11000  //MCBSP1_DRR6 A& P1 d; p+ A$ m) e
//PSC
8 w" R" b4 x) s" ]#define  PTCMD_ADDR   0x01E27120  
5 n- [, w/ |" k/ P#define  MDCTL15_ADDR 0x01E27A3C0 s/ y. E4 a0 O3 Y# Y& g# h  [
#define  PDCTL1_ADDR  0x01E27304  f: K/ C) m# H3 M3 ~
//GPIO8 direction
8 v" V* I- O* ]4 P, c3 G9 `#define GPIO8_DIRECT  0x01E260B0
3 |' s- r% q7 n7 R#define GPIO8_OUT     0x01E260B4
, K" e. g7 U5 N% N#define GPIO8_IN     0x01E260C0
! X5 G& Y6 p3 G$ e  ~2 V/ y5 v+ `5 @$ g6 e
//#define MCBSP1_RINT    99              + {, X0 a6 I0 N$ l
//#define MCBSP1_XINT    100  
- f8 O' P& T: e+ f  X) [- k7 Fstatic int MCBSP_MAJOR=239;: P8 w3 r: B- Z; `) ~8 K, w
static int MCBSP_MINOR=0;
# j. ?  S+ I* l7 t( S4 [2 ^static int count =1;  k3 T3 g# P! N1 Q3 s1 i

& p5 l2 t9 J$ {#define MCBSP_NAME  "MCBSP-device"2 k5 ~* f3 C$ @2 U2 h2 I
7 [- @: \6 y/ H+ @% D6 z. n( \
static struct cdev *mcbsp_cdev;
, H/ x! \3 f( Z1 Y# R* s1 Astatic struct class *mcbsp_class;) R4 ^) w/ S  ~
static dev_t mcbsp_dev;& V' k2 T/ _- a1 S* x; s3 I
unsigned int DRR_data;' I& M( o5 b5 g+ ?4 K5 M( M  P5 ?
unsigned int DXR_data;
4 \0 K' |2 y' H. `% c9 Z3 H; ystatic int mcbsp_open(struct inode *inode,struct file *file), Y, `  D+ i: H$ u
{3 d+ F" i: z2 {! d* }3 V
   
; V* B& n; _7 L' V2 t, D   //interrupt enable,initialized
. s9 _- _+ {0 ^4 E$ P, w0 z   unsigned int temp;
1 ]5 P3 A0 P8 p: G* i& J   //SLEEP_EN(GPIO8[10])---0
0 h( ~6 E8 X5 O& Z/ C1 Z   temp = __raw_readl(IO_ADDRESS(GPIO8_OUT));
3 S( d7 y4 m: J) T0 z/ e, k9 O2 T   temp=temp&(~0x00000400);
: B' x- B( d, z$ U8 v. R7 t   __raw_writel(temp,IO_ADDRESS(GPIO8_OUT));//GPIO8[10]
( B, h) q4 i& P4 r. t  //RESETn(GPIO8[8])----0----1" e6 O$ O' |% Z1 o4 s; M
   temp = __raw_readl(IO_ADDRESS(GPIO8_OUT));
& i2 ]! I+ U  \   temp=temp&(~0x00000100);
8 o  I+ o3 }' \2 c% n. e( a: s   __raw_writel(temp,IO_ADDRESS(GPIO8_OUT));//GPIO8[8]---0
# r: {( h2 K3 O   udelay(100);
4 [, k, y( P% |" I, c, x  d   temp=temp| 0x00000100;
2 V. M0 S) i: ?* v. p* h/ L   __raw_writel(temp,IO_ADDRESS(GPIO8_OUT));//GPIO8[8]---1
4 J' O; S5 l0 B+ f; [) W   udelay(100);- {$ B3 o: l9 r* p0 O
   printk("open success!\n");
- x( |, @. _7 H3 c   return 0;
2 ]- D2 M) l1 H# ^7 g. _0 ^}
; `) _  M) m1 j. u! _" x" d
& x5 C; N7 b* A1 N5 Z  Hstatic int mcbsp_release(struct inode *inode,struct file *file)
. L+ Y0 T4 t9 h9 a! r{
3 L; J% O; U% x8 [/ ^' D   printk("release success!\n");; A$ j# Y5 Z9 g( A3 H: F
   return 0;
! f$ o% G( Y. b! J8 U1 i}
1 [+ ~+ D* U# I; d9 V3 a: b6 Z" F" d8 Y) w* T/ e
static ssize_t mcbsp_write(struct file *filp,const char *buf,size_t len,loff_t *off)
1 w: L3 K( _! x* z7 z0 F& s. v  ^{
. C; `4 c- ~) ?( R0 v0 \8 i! h    copy_from_user(&DXR_data,buf,len);+ t3 ]& |, V9 q
    iowrite32(DXR_data,IO_ADDRESS(DXR_ADDR));      
: }$ W$ _- i, B( M    return 0;0 P. d' g$ M( }' w8 r
0 b+ s& x) q4 q& n
}  |6 ]% j( Z% V9 l

$ {, Y, n  g. h$ ^static ssize_t mcbsp_read(struct file *filp,char *buf,size_t len,loff_t *off)5 ~" R2 j$ u* ]' ?5 \% I4 t1 \) p
{
/ @- ?6 e6 [& i$ w! [+ G   DRR_data = ioread16(IO_ADDRESS(DRR_ADDR));$ P, Q0 n, G+ q% b' F7 G) A9 S
   copy_to_user(buf,&DRR_data,len);
7 `" h$ h5 k9 U/ _# v% F   return 0;+ p( d2 H. \) h" E9 V
}. z- s6 T5 \5 d! [7 ~6 Z& T* e
% r+ G" n! q9 c/ I, Y- F
$ z8 J8 \1 x, b/ e. N) j
static struct  file_operations mcbsp_fops=; \/ z4 K3 {& x2 g8 ~8 d5 Z  y
{' c9 P) O9 N) \9 g. B, `2 p! Q4 r
   .owner=THIS_MODULE,( v1 ]+ d6 |7 {! L$ S: G3 ?: u* K
   .open=mcbsp_open,
& w" h# p: ~" d! o  J5 l  S   .release=mcbsp_release,/ [$ W8 u- P' Q" ?
   .write=mcbsp_write,+ j8 l; [( D2 ^7 C
   .read=mcbsp_read,8 P7 ~. ]" ^: A4 I1 a  Q
};# r8 B7 @: z7 n, h( Y8 h9 |1 S
static int __init MCBSP_init(void)
9 G6 t: c* @% E{
8 J8 P3 c- D0 H. \6 x; H& _0 G   int ret;
7 r" H4 v& p6 e7 u% y) X' V# y   unsigned  int   PINMUX1_REG_old;
/ y& Y* w! U5 k% R   unsigned  int   PINMUX18_REG_old;
" t$ z% F8 t) a/ |! n   unsigned  int   PINMUX19_REG_old;: J3 k% t" u. x: I
   unsigned  int   temp;  + v  `) l$ W, \- M
   if(MCBSP_MAJOR)
; I: _& P. ~  w* Y  G8 Z# a9 s& [   {
4 h: U, I$ ?1 t      mcbsp_dev=MKDEV(MCBSP_MAJOR,MCBSP_MINOR);3 ]4 v# b; C5 ^
      ret=register_chrdev_region(mcbsp_dev,count,MCBSP_NAME);
2 r6 V+ o' R) t$ a9 m' p. u1 @   }
8 X) W$ @% O9 U8 ?( d- B2 `   else3 b3 |$ g/ r- q" C: J! n* Y
   {
' ]5 t& ?( c+ B0 j      ret=alloc_chrdev_region(&mcbsp_dev,MCBSP_MINOR,count,MCBSP_NAME);! a$ b. Z! n5 \  r7 o
      MCBSP_MAJOR=MAJOR(mcbsp_dev);
3 O; Z+ c) {4 |$ }" z4 X: d+ E/ E   }6 }" a3 i/ J5 E% S4 n2 m, s
   " `9 N& O# V  v9 J3 V; j
   if(ret<0)6 t& |3 V# J' N) ?& o
   {- T# U7 |/ A" T2 b/ _# |
      printk(KERN_ERR "register chrdev fail!");9 z4 S# y- Q6 |
      return -1;* U0 S! }2 l* I; u2 o
   }2 |5 b* Q1 d  P+ J$ H
   
6 p9 R$ g! [1 `4 m3 X- W+ i& Z   mcbsp_cdev=cdev_alloc();
: B# g7 `) |& W   
/ q' o2 ]' o9 P. B8 ^. @  `   if(mcbsp_cdev!=NULL)
0 J" k9 S6 G( P1 v" y, K   {2 _3 C6 V) Q; v: v5 b1 [
      cdev_init(mcbsp_cdev,&mcbsp_fops);
8 w3 f3 q. o: Q- I7 J6 Y- \      mcbsp_cdev->ops=&mcbsp_fops;, |0 g! L  K  h6 W; {3 ~( E( J3 q5 J
      mcbsp_cdev->owner=THIS_MODULE;. _; l- J3 M2 P' Z7 m
      
1 y" y! ?2 S- s  |: ^$ q      if(cdev_add(mcbsp_cdev,mcbsp_dev,count))
1 M$ U  K/ z0 n2 ?          printk(KERN_ERR "register cdev fail!");7 P7 ~  j7 o* \
      else/ L/ Y) Z" y" M1 X# b( U5 T3 G
          printk(KERN_ERR "register success!\n");+ E* I; w4 Q; A7 ?, H
   }
( x$ \0 @- i8 Y4 x   else! }( I; O( Q, i0 X& D$ t
   {, o3 `- O4 L& q& T+ E) h
      printk(KERN_ERR "register cdev err!");
% o% `4 Y8 ?0 r6 _" I; i      return -1;) V8 u! m' y" q
   }+ U* W7 x" m3 Z
   
/ I" ~6 t( F3 ?" l/ n7 R8 O  mcbsp_class=class_create(THIS_MODULE,MCBSP_NAME);
' j  s3 Y6 E' j1 J) _   if(IS_ERR(mcbsp_class))" b) }  Z7 w. Q& J7 W+ d$ e& Z
   {
9 c0 v9 c4 \( D2 U      printk(KERN_ERR "register class err!");+ v4 H+ J8 K" ~6 K7 F
   return -1;
2 d" S! L- g: e( u9 `9 y7 v2 r1 G   }4 N) h6 P$ U8 Z0 a/ e
   device_create(mcbsp_class,NULL,mcbsp_dev,NULL,MCBSP_NAME);1 g3 H+ f' `' g9 d8 I  L* q% C

6 D! x- C; g( C- ?   //PSC# e3 L1 i  y1 G' E3 n
   //add Enable MCBSP* F1 e8 k' c/ t6 _$ [
   //test
' w# h' E# r9 \1 H- G; y1 K   temp = 0x80000003;# V6 |: H/ ~. l& i# P- }: n
   writel(temp, IO_ADDRESS(MDCTL15_ADDR));
, ~3 U% K! J( ^! }, X& d   temp = 0x00000003;. L9 K' p! H0 g/ w; J
   writel(temp, IO_ADDRESS(PTCMD_ADDR));
- \* c* k4 l# K& i' q  ^ , N; t$ {& U9 |7 [
   temp = 0x001FF201;
, a& A0 G+ i4 P% y/ a! r. N8 `   writel(temp, IO_ADDRESS(PDCTL1_ADDR));& E, n- J# j* P9 t; i2 p! m
   1 Z8 b* Y/ z0 T: W2 T/ c
   //PINMUX  7 P$ T; V3 A( j- W2 A9 h
   //MCBSP_CLK(receive/send),MCBSP_STRB(receive/send),MCBSP_DX,MCBSP_DR,! e, M* s6 j3 D, f$ t* Z
   PINMUX1_REG_old=readl(IO_ADDRESS(SYSCFG_BASE)+PINMUX1_OFFSET);  ( K5 A1 @- n4 c+ t
   PINMUX1_REG_old=(PINMUX1_REG_old&0xf000000f)|0x02222220;   
" p! C, s2 k9 U% P1 o" x, n   writel(PINMUX1_REG_old, IO_ADDRESS(SYSCFG_BASE)+PINMUX1_OFFSET);3 e! J! ~* J" U; l
   
( D% Y6 c1 o5 D   //SLEEP_EN,EPR,L138_SHK1,L138_RC
. f7 \0 C) m5 d8 n7 h% d9 {  R) F   PINMUX18_REG_old=readl(IO_ADDRESS(SYSCFG_BASE)+PINMUX18_OFFSET);  
; ?9 B+ U$ I6 m/ d   PINMUX18_REG_old=(PINMUX18_REG_old&0x0000ffff)|0x88880000;   + s- @- P/ L* q& H2 R* O; m
   writel(PINMUX18_REG_old, IO_ADDRESS(SYSCFG_BASE)+PINMUX18_OFFSET);
5 [( J3 E' y3 Y6 _5 `7 y" W7 H
# e' \4 U" ^) O1 M3 }  }) m% e   //RESETn,L138_SHK2
3 v+ h% i& ?/ L9 j6 z0 n( s   PINMUX19_REG_old=readl(IO_ADDRESS(SYSCFG_BASE)+PINMUX19_OFFSET);  
! G) M# `7 L/ c9 I; b   PINMUX19_REG_old=(PINMUX19_REG_old&0xf0ffff0f)|0x08000080;   2 r# U, E0 T3 z0 N
   writel(PINMUX19_REG_old, IO_ADDRESS(SYSCFG_BASE)+PINMUX19_OFFSET);" E6 E9 P% n# d4 \5 A6 J5 E: D4 ~

& T* E* }! n' @& E0 z
& S+ P3 @2 b4 `  //SPCR Register. ~. r/ E! ~$ p6 y3 w8 {
  //FREE-1,SOFT-1,FRST-0,GRST-0,XRST-0,RRST-0,RJUST-00(Zero-fill MSBs)reset- ]1 ~/ r" `3 F( T" T
  temp = 0x03000000;//(DLB=0)
, O+ ?9 j! E7 U9 H5 x // temp = 0x03008000;//(DLB=1)2 r7 t) y/ S4 c2 C
  writel(temp,IO_ADDRESS(SPCR_ADDR));  //reset
- J6 I3 }: |( ~& m  temp = readl(IO_ADDRESS(SPCR_ADDR));
4 t* G+ s5 M9 h  M, C  printk("temp=%x\n",temp);
2 b( ?% x3 S8 N4 r
2 [; x8 n: z, X# X. ^2 @" _   //PCR Register
8 t0 K! i/ B0 o, \" s9 h   //FSXM-1,FSRM-1,CLKXM-1,CLKRM-1,SCLKME-0,FSXP-0,FSRP-0,CLKXP-0,CLKRP-0) R# D- U; l! U! J5 \; T" _
  // temp = 0x00000F0F;
5 ?, r% F, N$ X3 d' D9 W1 B  temp = 0x00000B0F;& i* A& B" m$ P, b! S
  writel(temp,IO_ADDRESS(PCR_ADDR));  //initialized
4 X3 J1 i" c9 Z# }, f( w& F3 u  temp = readl(IO_ADDRESS(PCR_ADDR));
, o- [$ N+ Q5 v7 a1 @6 `  t  printk("temp=%x\n",temp);  & s' _% j9 A$ f/ H& o" ~0 G0 _
   //SRGR Register
3 h8 _; `" w9 U( G   //GSYNC-0,CLKSP-0,CLKSM-1,FPER-31,FWID-0,CLKGDV==11
7 J- j. G) e9 ^) V //temp = 0x301F000B;* G! g) z  ?& ^7 n7 B1 C
   writel(0x0301F000B,IO_ADDRESS(SRGR_ADDR));  //initialized ' }5 o; [0 d( i: c2 {7 L  m
  temp = readl(IO_ADDRESS(SRGR_ADDR));9 A# o6 K/ z5 F& M" \( Y. m2 \7 x
  printk("temp=%x\n",temp);8 v" n9 k5 o0 {7 T; _
   //RCR- }' M# ~7 F. ]+ q2 `
   //RPHASE-0,RFRLEN2-0,RWDLEN2-2,RCOMPAND-0,RFIG-1,
2 _. H  @/ ?% _4 e5 Y   //RDATDLY-0,RFRLEN1-0,RWDLEN1-2,RWDREVRS-09 j$ `8 d# l& L" v/ c! C
   temp = 0x00440040;
4 n5 l. I3 [; f7 B. ~0 S4 P   writel(temp,IO_ADDRESS(RCR_ADDR));  //initialized   
1 z. Q3 T) w3 S3 w  a# a   temp = readl(IO_ADDRESS(RCR_ADDR));
- d+ e4 q8 `6 Q   printk("temp=%x\n",temp);+ z( h; }; `) ~! i( T# K
   //XCR
5 a# ~. F, s. l; F; s- Q   //XPHASE-0,XFRLEN2-0,XWDLEN2-2,XCOMPAND-0,XFIG-1' x) j6 ?5 W( a. H0 K
   //XDATDLY-0,XFRLEN1-0,XWDLEN1-2,XWDREVRS-0
2 {: m& d$ ?' I9 @) S% G   temp = 0x00440040;
% |: \2 m' d/ u# I   writel(temp,IO_ADDRESS(XCR_ADDR));  //initialized   3 I% H- R1 o: A1 b
   temp = readl(IO_ADDRESS(XCR_ADDR));4 c6 ~" R, e' n4 W
   printk("temp=%x\n",temp);5 F% X* S9 c( U- Z' r4 i
  udelay(100);- L  f) w/ L$ F3 c
  //SPCR Register
! M8 F! D) k; x' o. u2 V4 d: N  //FREE-1,SOFT-1,FRST-1,GRST-1,XRST-1,RRST-11 w- X" O3 l. f7 m+ ]6 z
  temp = 0x03C10001;   //DLB = 0 VS DLB = 1
& \9 O: ~' W4 Y) n/ M) }* N. i  writel(temp,IO_ADDRESS(SPCR_ADDR));  //enabled
$ ?$ M/ g3 A7 c  temp = readl(IO_ADDRESS(SPCR_ADDR));6 V: ?: n  ~0 f4 K
  printk("temp=%x\n",temp);% A' S/ U# i; g3 l6 R
  udelay(100);5 |8 q) i2 S) G9 N$ n- h

; {/ Z  C; C9 N1 L0 ~, k% x  //set GPIO direction9 x! v, }: K6 n3 M. }8 i5 \
   temp = __raw_readl(IO_ADDRESS(GPIO8_DIRECT));
) m0 t2 E6 w# P9 Q% o   temp = temp | 0x00000100;//EPR----input
- m2 b) F, R  z   temp = temp&(~0x00000500);//RESETn,SLEEP_EN---output
( a4 z5 b! G- ?8 I   __raw_writel(temp,IO_ADDRESS(GPIO8_DIRECT));
# y5 u- }/ l! u' a5 `& [  N
8 f' K- c- l3 q" ]( `   return 0;
6 x$ |* I6 N3 a8 c}  O# b' h4 M; {8 t7 F  O4 g) Z
static void __exit MCBSP_exit(void)4 F+ R/ h/ G- A! Z
{
$ L8 D, ~' m& T5 @3 z' d   printk("mcbsp chrdev exit!\n");
0 Q! k! c$ n) u* @   cdev_del(mcbsp_cdev);. @4 ~3 H+ y# L- c
   unregister_chrdev_region(mcbsp_dev,count);
2 X. u2 o7 w& v% O( x   device_destroy(mcbsp_class,mcbsp_dev);. ]6 a9 P. v3 k0 T4 f" W
   class_destroy(mcbsp_class);
1 c! I) n/ [! ?}
0 {0 M5 H- [' O5 j2 pmodule_init(MCBSP_init);' _, ^1 g( i1 s& [5 P# v' y  `
module_exit(MCBSP_exit);1 q5 b5 t) |6 N" ^" Q: |, g

6 W* v- z7 h* B4 G$ n7 H. XMODULE_LICENSE("GPL");
5 O' |! ]: p4 w+ D# j$ Y! D% ]2 x+ f7 h# N, W4 ]2 T
我讲上面的程序insmod之后我用示波器量 McBSP的发送时钟脚,发送数据脚(我还没有发送数据)以及发送同步脚,3个脚的信号是一样的,不管是用我自己的底板测试还是用创龙OMAPL38 的开发板测试,都是一样的,类似于噪声的信号时钟频率也不对。
1 }& @5 e1 G. C! D: P# I5 T我的应用层的测试程序如下
9 L4 G+ x: A2 q. J#include <stdio.h>
4 ]" \( z& Q2 }) p#include <string.h>7 u# r7 p1 I+ c9 s7 w3 J
#include <fcntl.h>
+ z) ~/ Z& A( Y' `5 n5 P) t! n#include <unistd.h>
$ `* B. k. R) }9 |6 k#include <signal.h>' y* t- [2 z# S+ ?5 O6 o
#include <pthread.h>       //线程9 s5 Q5 O: M  {
#include <stdlib.h>! n8 g2 m" B9 O& H
#include <pcap.h>          //捕获网口数据  |& W! J6 ^2 n, l
#include <semaphore.h>     //信号
' E2 m- q" c' s$ [+ o#include <sys/types.h>     //消息对列
' S) S% M" ^4 o- v9 E#include <sys/ipc.h>       //消息队列
' _$ c4 Z& }/ S. e$ B& e#include <sys/msg.h>       //消息队列- m; C/ v$ |( f6 [; q% N0 L
#include <sys/select.h>
$ `' u+ ~' t5 J8 o) C- V" m0 W5 O#include <sys/syscall.h>& h( o" @) T/ c+ K
#include <sys/stat.h>
& d8 Q8 j" v- L9 H1 y# R#include <sys/mman.h>; N; r* C" m0 [0 [
#define msleep(x) usleep(1000*x)6 _9 t7 Z7 e: N* O/ W
; @9 B9 Y# _5 Z. E2 q+ d, C# G
int main()
8 D+ m. A8 z# n; [4 I; }{ 2 \( W) H. \' G/ {
    //MCBSP,ARM与AMBE2000交互设备
6 _# C2 w* {$ _  {; l( w* ~ int fd;& D% A1 u$ t1 `
unsigned short data_write = 0x5555;) S1 @  e- j% G$ Y# w- s  Q8 d6 Q0 t
unsigned short data_read = 0x00;: X9 F8 G/ M2 C5 d' L6 p5 {: n5 J7 P
  fd = open("/dev/MCBSP-device", O_RDWR | O_NONBLOCK | O_SYNC);' ]( m8 h3 T6 ?& m
//  fd = open("/dev/led-device", O_RDWR | O_NONBLOCK | O_SYNC);* m; |$ p: i( G- E& h$ s# l  d" P4 o6 I' f
    1 |' p7 R& C) H) W& F: K
  if(fd < 0)
( q7 I5 a6 X# u! ^: J7 z0 R' {% _  {
( J. R/ c3 s- t' w) X+ d$ p     perror("open failed\n");1 c$ @7 R% W8 y' H
     return -1;
: t) K3 _( W6 _  u8 ]; f4 F  }- ~9 Z5 [3 u' H# \- S4 |$ y/ g
  
! b7 C! S. r. V; r  while(1)
" B; U5 j0 @9 d  @) r  {
# c+ J; [6 C* @: u7 g5 Q3 O   . h( j4 }; S9 O) e8 g
   //AMBE2000每次读写是24个字为一帧
, m% g1 \6 [/ c* c6 s% H   //写数据时将数据在底层存储起来,等到中断的时候再发送# H' R" X9 y" o5 L7 F0 |
   //AMBE2000输入数据是以0x13EC开头的
" p) L  c* q  t) E   write(fd,&data_write,sizeof(unsigned short));# M# k. Y0 y. g5 w& U# _
   ; {7 A6 c3 o5 F% n
   //读数据的时候,在底层中断中将接收到的数据存储起来,然后再传送到应用层  
8 D; d4 a8 T7 |. ~8 G; ]9 E+ P   read(fd,&data_read,sizeof(unsigned short));0 t8 ~4 }$ @+ b. |+ _
   1 U9 j$ k& V' H' w* ~
   if(data_read == 0x13Ec)
, ]% o7 l/ O# J   {
, l  z. L& g7 G& P# y8 h3 \2 ~  I   
: [9 m' s2 _5 K# S5 @% Y    printf("data_read = %x\n",data_read);+ A: L  c% ]6 n! b, |
   }. m' H4 {, M2 s. g) |
   
3 Q0 M' i! `% }* x7 d* h   msleep(10);# i7 [7 m* T7 J6 n9 p2 s2 l
  
8 B. V3 s; ^! p7 V  /*5 {1 T, ]9 k7 l8 b: d/ _
   ioctl(fd,1);   + S$ G# q9 d8 z2 I2 h2 a& G! }( B
sleep(1);
& B6 b( W* ^* J; Z ioctl(fd,0);
. c0 o, @0 A! `8 }9 N- i' C2 p sleep(1);
# i$ H  m0 h, C */ 9 a( ]$ [4 P( s* a" ?/ O" p: \  v# m
  }   
; T9 F7 z! V+ ?9 G5 F return 0;
0 m+ }! c7 X0 B) s/ p , n8 g9 a  M# \. W- O, X( x
}
, d0 L: l' z: q+ w% s  P( l' P, F
. S, ?( ^- A# [( R多谢各位指教,谢谢! 急
, ?* k( \- r1 M/ K& D: A7 ]
+ Y# V; E9 |* G3 d0 ~/ W& E
5 J. E4 D2 B8 w1 \% ?  J  T9 h2 ?8 Z- ]2 ?* t1 l+ y7 x

' D% n, T; o) ?( |2 D& o( W2 v1 I# h. d8 V' h7 N( }3 U& A
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖
回复

使用道具 举报

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

本版积分规则

点击跳转“创龙科技服务通”

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

GMT+8, 2026-1-18 18:14 , Processed in 0.047713 second(s), 26 queries .

Powered by Discuz! X3.2

© 2001-2015 Comsenz Inc.

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