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

嵌入式开发者社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

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

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

[复制链接]

6

主题

7

帖子

58

积分

注册会员

Rank: 2

积分
58
跳转到指定楼层
楼主
发表于 2014-10-16 10:58:57 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
我讲创龙在DSP中使用的例子移植到ARM中,如下是我的底层驱动程序: " Y7 E/ X- v" P5 k+ L
/*
# E" o% M+ A! ^$ w' _ * Copyright (C) 2009 Texas Instruments Inc
: ~8 h5 X# S% A9 q+ J+ p; o *
- G8 G2 N: M/ }% d& _/ @ * This program is free software; you can redistribute it and/or modify2 l7 Z- Q3 Z5 n
* it under the terms of the GNU General Public License as published by% t- V7 P' P( D5 u3 ?' |; o4 o
* the Free Software Foundation; either version 2 of the License, or4 w+ @2 E: g( O, n
* (at your option)any later version.
3 s: N4 U1 e* ~0 u2 H *
9 |# V  ?6 v7 j; l  k4 x5 b * This program is distributed in the hope that it will be useful,) Y& V; H7 L4 \! W- ^
* but WITHOUT ANY WARRANTY; without even the implied warranty of* {4 _9 d! E/ @9 v; t
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the1 f" \! r6 {3 Z  c" i. @" z
* GNU General Public License for more details.
; `6 q2 U4 Z9 ^5 \' I$ E ** t$ K$ t) @1 A! N* H7 M+ d
* You should have received a copy of the GNU General Public License. P* i4 F, X1 A$ c
* along with this program; if not, write to the Free Software
8 X8 H# E4 K3 J4 [- `$ X * Foundati
" Y' N5 w4 n8 Q4 S*/! U9 }- o( ]* l* q, S" L
#include <linux/module.h>1 P# H. o, Q6 ~+ A- t0 I1 Q
#include <linux/init.h>7 F- n9 n2 S; s5 h0 E+ A
#include <linux/errno.h>
8 h6 |2 s. \3 h$ F& L3 y: c#include <linux/types.h>
+ M$ N2 l) U" S& r: l( z1 o# v#include <linux/interrupt.h>
' I, q9 `6 \6 f5 i3 v" _) j$ f#include <linux/io.h>
6 Y3 P7 L7 U# G. n( [9 [- s0 X#include <linux/sysctl.h>/ ?6 B0 C* g6 D* }
#include <linux/mm.h>! b! i& N2 }! x3 B
#include <linux/delay.h>
/ G! T3 H9 f% }- @5 D" L- c#include<linux/kernel.h>
# d& a# M$ `/ W" ]5 r#include<linux/fs.h>
3 L. c; n  U8 L( A  o, k2 O#include<linux/ioctl.h>
. Q% B0 P$ J2 \; K  U5 s) J+ V#include<linux/cdev.h>
- O, H6 G& V* H, u( n- H#include<linux/kdev_t.h>5 `9 ]7 p7 P4 S" o! g% {3 P, c! Z
#include<linux/gpio.h>
: f% E, y% p$ R5 w, }' l#include <mach/hardware.h>7 x; x5 ^; K4 s! ]
#include <mach/irqs.h>
  ^, J2 M# R0 o1 I( j2 }  E2 ]* c* B8 d1 M# h' x
#include <asm/mach-types.h>
$ C3 U  h8 [$ M2 @1 n$ N0 U+ ~#include <asm/mach/arch.h>! v: s! I) F7 T. e* x# h, d
#include <mach/da8xx.h>
' F+ P- p7 ]/ v2 ]#define  SYSCFG_BASE   0x01c140002 q9 }; L# E% Y2 e  y1 y( X
#define  PINMUX1_OFFSET   0x124
" H( O" v- i3 m' t' N#define  PINMUX18_OFFSET  0x168 6 F0 C; c4 O. y! H2 z7 x
#define  PINMUX19_OFFSET  0x16c
1 s# \9 C& ^# a( N  p+ T. {9 ]#define  SPCR_ADDR    0x01D11008  //MCBSP1_SPCR3 r8 X% t2 ^# e
#define  RCR_ADDR     0x01D1100C  //MCBSP1_RCR: ?- q' F/ F" \9 W6 x
#define  XCR_ADDR     0x01D11010  //MCBSP1_XCR
2 S& h5 C) _: P4 Q1 o/ X' U6 D0 O#define  SRGR_ADDR    0x01D11014  //MCBSP1_SRGR2 N  B. b# S- n! ^- ^% R2 |
#define  PCR_ADDR     0x01D11024  //MCBSP1_PCR
+ B9 r( w$ C1 o; n                           
( F4 ]6 _5 e- M! n5 n5 H# m#define DXR_ADDR      0x01D11004  //MCBSP1_DXR
" w  i# R( u+ k! T#define DRR_ADDR      0x01D11000  //MCBSP1_DRR
0 l" C; E' [% T0 D# J% W+ h//PSC- Y: @, e% L* U$ {- f
#define  PTCMD_ADDR   0x01E27120  
. J* [2 n& l6 S6 m8 v7 ]#define  MDCTL15_ADDR 0x01E27A3C
8 M8 R9 x: A& p3 G4 V% S4 P/ X#define  PDCTL1_ADDR  0x01E27304
/ B; n6 e, |+ Q; }//GPIO8 direction
0 u. o2 f1 Z. P0 o5 ?+ |  u6 E8 D#define GPIO8_DIRECT  0x01E260B0
4 Q) C" t. t4 l/ X  `& \3 G# K! |: i#define GPIO8_OUT     0x01E260B4
9 D& a+ F+ X: M+ \" j1 Z8 k#define GPIO8_IN     0x01E260C0( p- B! x) X8 N& U1 W

# X0 @& `# t% X6 s% J+ [//#define MCBSP1_RINT    99              
% s4 k) T( ]1 f" q5 y  F' u' x# v//#define MCBSP1_XINT    100  
) n7 N5 W1 M2 ]: J6 _' r2 H6 V/ Zstatic int MCBSP_MAJOR=239;
/ o1 F5 y; d  a9 a- T$ ~static int MCBSP_MINOR=0;
1 ?% v3 F6 r4 A' Z7 Z0 u$ y; Istatic int count =1;, w1 R' E+ K8 m$ L" n* U

, T/ h3 \7 _& p#define MCBSP_NAME  "MCBSP-device"
$ F. X! @7 d, B9 q8 ]$ B# V1 {7 C
8 a, w% ~9 s# R: V; G6 z$ ~static struct cdev *mcbsp_cdev;. D3 `9 V, \% d1 }- u3 A( z
static struct class *mcbsp_class;" U, Q0 {3 g9 B) Y
static dev_t mcbsp_dev;( f# R6 r6 ?- Y: b7 l
unsigned int DRR_data;
6 |+ e& o' J4 j  S) Ounsigned int DXR_data;
# I9 `8 z- U) J* b! x' estatic int mcbsp_open(struct inode *inode,struct file *file)
: y. }' M0 ~! s- j9 _0 N) F{/ b2 q! _" ~! o& n) k
   
& m4 L/ r* B5 x) v( @$ ?; L   //interrupt enable,initialized  _9 E( U. O" w1 y" V
   unsigned int temp;
/ G# D+ N3 [  w   //SLEEP_EN(GPIO8[10])---0; Y* h: m5 \# S
   temp = __raw_readl(IO_ADDRESS(GPIO8_OUT));
4 e+ Y. x* ^/ \8 n   temp=temp&(~0x00000400);
3 s# ]7 h7 {: D, {/ V   __raw_writel(temp,IO_ADDRESS(GPIO8_OUT));//GPIO8[10]
2 }3 ?2 l' o  W5 |6 a6 U) b  //RESETn(GPIO8[8])----0----15 z: x+ G/ a+ L
   temp = __raw_readl(IO_ADDRESS(GPIO8_OUT));
8 |, r5 [- N/ V   temp=temp&(~0x00000100);
/ J! z3 t( ?. K! [% T' S6 C7 r   __raw_writel(temp,IO_ADDRESS(GPIO8_OUT));//GPIO8[8]---0
% l3 h0 x1 E) f' E   udelay(100);
0 h4 L2 _# ?& m( p$ |   temp=temp| 0x00000100;1 ^2 D! o" w, [
   __raw_writel(temp,IO_ADDRESS(GPIO8_OUT));//GPIO8[8]---1" W& D$ e: {! e3 }! p
   udelay(100);
1 D7 D. U1 V3 w: r- Z6 g% |   printk("open success!\n");
& \2 C1 V  N5 d   return 0;8 Y5 N7 O, o$ T
}: J( m1 N6 v: R! `8 a

7 U( x9 y* J  d2 U" G* W5 cstatic int mcbsp_release(struct inode *inode,struct file *file)
3 Y9 h6 h9 A& Z{
; C1 |+ H5 b2 b' o9 x' l7 v   printk("release success!\n");
- @; c$ _$ F2 p/ b* X; G/ G   return 0;
) S9 P4 c, A! ]9 \}7 E7 C8 |; j- }2 K4 G
; ~1 E7 N4 @$ l6 ]
static ssize_t mcbsp_write(struct file *filp,const char *buf,size_t len,loff_t *off); L9 J7 j& c' o
{8 c; d, K# z" v# G' W" _0 N0 _) d
    copy_from_user(&DXR_data,buf,len);
/ C  j  d; E1 j0 |    iowrite32(DXR_data,IO_ADDRESS(DXR_ADDR));      
8 I) n8 G7 Z; u' }% b5 l    return 0;8 A6 L6 X+ c; J3 [& b
" P% P( I$ n0 ?6 J0 i1 X4 q
}% L* D# o# I/ w9 v, I6 B# }

5 K; O  b& n2 |7 `$ R) g8 ]2 pstatic ssize_t mcbsp_read(struct file *filp,char *buf,size_t len,loff_t *off)
& F0 H# T4 v# ~& K{ ' J' k* {. ~' `) o% l
   DRR_data = ioread16(IO_ADDRESS(DRR_ADDR));& e, D/ w5 {! x% P( q' r% @6 {/ A" G
   copy_to_user(buf,&DRR_data,len); $ j- N7 s: c) I
   return 0;5 R" r3 f8 y6 M5 |' j" C; s
}
! ^/ ?7 H# v: V' S2 R, k2 G3 b: {! Q$ j. P% Q

2 K+ m, l2 x6 w" _* O; {0 m; estatic struct  file_operations mcbsp_fops=3 R! s4 F( n: U( j1 i9 x6 x  ^
{. G, d* |3 o: v( `  x
   .owner=THIS_MODULE,
. i+ |1 e7 Q1 b3 t" K% U   .open=mcbsp_open,
3 t2 O  L  E5 [   .release=mcbsp_release,
1 }" N  t  J8 O7 ~! ^   .write=mcbsp_write,7 l: w6 ~7 c: \2 @; d1 P
   .read=mcbsp_read,
; n3 z- r# b- J& ]) P7 Z# A};
5 G" s, h5 U8 R$ O0 U6 ]1 V" O, ustatic int __init MCBSP_init(void)6 m# o' w* t* `: \+ C
{
% V9 \# L7 ~2 U; H1 U   int ret;
" Y: U# a2 o! d$ _. D0 ~   unsigned  int   PINMUX1_REG_old;
8 ^7 H8 ^5 T/ Z) t+ _- Z! W   unsigned  int   PINMUX18_REG_old;+ {$ ?3 t! Z+ ?8 K
   unsigned  int   PINMUX19_REG_old;, a) S! O: {# |* _# s
   unsigned  int   temp;  8 {2 U( K. I8 V
   if(MCBSP_MAJOR)
) ~6 j5 z+ `0 x% i   {
5 L: Y3 f$ `) e, N" f2 y      mcbsp_dev=MKDEV(MCBSP_MAJOR,MCBSP_MINOR);4 @) ?1 o) V( f2 l+ h* H3 J
      ret=register_chrdev_region(mcbsp_dev,count,MCBSP_NAME);
  D) W, Y& f, W) d" h6 c   }
+ g! h5 H) K3 g' p7 Z! z! M   else
% Z6 [( N3 v9 _. Q, i8 P- c; E   {* N" @& ]9 o% L8 g5 W' \* T
      ret=alloc_chrdev_region(&mcbsp_dev,MCBSP_MINOR,count,MCBSP_NAME);
( u. b& F  ~2 ]      MCBSP_MAJOR=MAJOR(mcbsp_dev);- e' H4 K) y  {2 @* }1 }3 R
   }2 J; {! o6 s/ K% f% d9 w0 V; N
   
1 e( t# ]2 ]- g2 Q0 R9 M; J/ p   if(ret<0)
& f: s6 \  i# N4 v" `( |/ M' p   {
1 O/ ^% r2 o8 u4 b: u4 c      printk(KERN_ERR "register chrdev fail!");
6 H' {/ [+ g' T7 A" d& o, k) ^      return -1;
, p" O$ x. E# ?, `* ^# Y2 Z   }
- d- _% C* O, p" }# H; o" d! G   
$ h/ E. y1 c# Z' R. w   mcbsp_cdev=cdev_alloc();
) e. P2 i* g! E) w5 \9 d   
; T$ l* G0 Q. s   if(mcbsp_cdev!=NULL)
* |  j  \: Y' W: P* }   {8 \; f) y8 T) N6 _5 ?) b
      cdev_init(mcbsp_cdev,&mcbsp_fops);8 B- C4 i7 w% k/ V( ^& l$ m) p$ x
      mcbsp_cdev->ops=&mcbsp_fops;9 H2 i2 P6 c% p  D5 _
      mcbsp_cdev->owner=THIS_MODULE;- X) Q$ ]3 c/ U
      - Q- J2 }( Z4 G8 S& |1 v
      if(cdev_add(mcbsp_cdev,mcbsp_dev,count))! @" H* R3 A/ D+ Q
          printk(KERN_ERR "register cdev fail!");
' U& h- L* V1 Z" c8 V      else
6 I: ~/ L- s$ d8 `- o          printk(KERN_ERR "register success!\n");9 Y! J% z  A: k5 v# V+ E
   }
4 x+ U! N7 |( j6 ~. `8 A   else: g7 o, R- N/ ?# T, h1 X! ]
   {6 X5 @) i; w1 a+ [* d! b) r
      printk(KERN_ERR "register cdev err!");; A& v( E& V9 p: `) M
      return -1;
& T+ j) j& u2 E" r  V1 v   }
# @1 k( {" }: x8 z8 @/ t- n1 G/ v   , M! x) c. c- U; a% S& H$ U( m( {& b
  mcbsp_class=class_create(THIS_MODULE,MCBSP_NAME);
  P+ `2 X# L0 W0 F; v) h& y   if(IS_ERR(mcbsp_class))2 M- V7 |, m+ z! e( C7 {' J
   {
0 W7 v, e2 D6 h1 I  M2 ?: W* i5 k2 X      printk(KERN_ERR "register class err!");
9 G& d3 E3 h8 w& f% J1 u; F   return -1;
0 ~0 ^1 ?' T& }   }' f% G& q$ V7 Y/ t: D0 G) T# }& m( F
   device_create(mcbsp_class,NULL,mcbsp_dev,NULL,MCBSP_NAME);4 z& f6 g; i2 X% C3 V

+ I6 V9 N, D9 ?   //PSC
- D+ k9 F2 n: p6 b# D   //add Enable MCBSP1 E! I9 v9 b. d( B: U5 A$ E7 d* i
   //test
- |+ J3 |, G# N  H   temp = 0x80000003;
4 J. |7 _& B# |# B1 N9 t  {   writel(temp, IO_ADDRESS(MDCTL15_ADDR));
8 J9 ?5 V, _$ a1 [% x3 r* m/ i   temp = 0x00000003;: L& {# v8 M: j5 X* N7 z% f
   writel(temp, IO_ADDRESS(PTCMD_ADDR));
& e4 v$ t- J( w4 c$ G% ]2 u. B( @ 9 w+ C" L. j5 y6 Z  B
   temp = 0x001FF201;
% M  |1 q9 u+ C" F; I   writel(temp, IO_ADDRESS(PDCTL1_ADDR));; P9 C) E5 K( h8 U8 @
   + M  W# K9 H2 r& m
   //PINMUX  # R: M3 z7 R" ~" J6 {: B" c
   //MCBSP_CLK(receive/send),MCBSP_STRB(receive/send),MCBSP_DX,MCBSP_DR,& q3 Q2 E! x& k1 ~7 i! `
   PINMUX1_REG_old=readl(IO_ADDRESS(SYSCFG_BASE)+PINMUX1_OFFSET);  
  H+ |" L1 s. D/ {   PINMUX1_REG_old=(PINMUX1_REG_old&0xf000000f)|0x02222220;   
0 C7 A% a& Y9 l3 U/ v' R5 C! ~   writel(PINMUX1_REG_old, IO_ADDRESS(SYSCFG_BASE)+PINMUX1_OFFSET);/ Z" @$ b! d  U' {) C5 x7 f) Z
   
9 U" U# b% @4 o+ D' I   //SLEEP_EN,EPR,L138_SHK1,L138_RC
: L3 q9 Y6 ?5 E5 _* L, k$ Y   PINMUX18_REG_old=readl(IO_ADDRESS(SYSCFG_BASE)+PINMUX18_OFFSET);  ! p5 s0 u0 v0 K$ J
   PINMUX18_REG_old=(PINMUX18_REG_old&0x0000ffff)|0x88880000;   & |4 K: D# W4 W6 W
   writel(PINMUX18_REG_old, IO_ADDRESS(SYSCFG_BASE)+PINMUX18_OFFSET);0 x1 f) E" e) E: M/ ~2 J
$ f# T0 h  `3 l; h7 F
   //RESETn,L138_SHK25 I! A" U, e9 U
   PINMUX19_REG_old=readl(IO_ADDRESS(SYSCFG_BASE)+PINMUX19_OFFSET);  
7 X7 \& H7 U% f   PINMUX19_REG_old=(PINMUX19_REG_old&0xf0ffff0f)|0x08000080;   7 {. r) d% h$ R* i) A6 B
   writel(PINMUX19_REG_old, IO_ADDRESS(SYSCFG_BASE)+PINMUX19_OFFSET);" l% D  b+ w  Y

  I. o7 q8 @: R) x4 F) x5 p
1 f3 @& n0 N, h% |9 E8 `* |) R  //SPCR Register
6 Q2 E4 ^: p( C' I/ h/ y  //FREE-1,SOFT-1,FRST-0,GRST-0,XRST-0,RRST-0,RJUST-00(Zero-fill MSBs)reset
# E3 K! z" a& H& L$ }  temp = 0x03000000;//(DLB=0)
/ D2 f6 X% i8 `* v+ E1 h // temp = 0x03008000;//(DLB=1)
0 }% y0 B  B: D$ c* O, z  writel(temp,IO_ADDRESS(SPCR_ADDR));  //reset
4 ~7 [- L- e0 t' y6 b7 K6 B( S  temp = readl(IO_ADDRESS(SPCR_ADDR));/ U: P: }) K) P9 H$ k1 s: ~
  printk("temp=%x\n",temp);
8 V2 T/ K7 z  h$ R
/ N' z& Q5 H! @( Z5 m1 m+ Z, K   //PCR Register
; B+ z& I0 Y% t7 u   //FSXM-1,FSRM-1,CLKXM-1,CLKRM-1,SCLKME-0,FSXP-0,FSRP-0,CLKXP-0,CLKRP-04 J1 g: i! ?( i+ U! `
  // temp = 0x00000F0F;
  |2 J+ Y8 [$ v, ^* O  temp = 0x00000B0F;/ S1 d" k0 t& F, K& N6 c
  writel(temp,IO_ADDRESS(PCR_ADDR));  //initialized 3 l: O% j/ }7 J  [0 h+ n+ d
  temp = readl(IO_ADDRESS(PCR_ADDR));
& G* m  y3 K/ Q$ X  printk("temp=%x\n",temp);  
1 S, I$ q( D( a- B   //SRGR Register
& Q" F1 n4 D9 l1 K  V   //GSYNC-0,CLKSP-0,CLKSM-1,FPER-31,FWID-0,CLKGDV==11: k. c1 M) J* j! W. M
//temp = 0x301F000B;1 u' E; m9 Q% @4 ~2 B; ^$ C9 j# ?
   writel(0x0301F000B,IO_ADDRESS(SRGR_ADDR));  //initialized
3 M5 s; m9 S" [8 }7 p) @  temp = readl(IO_ADDRESS(SRGR_ADDR));8 f; a1 s% B3 r# c% _& b- L0 p7 e
  printk("temp=%x\n",temp);' y( V/ }4 P8 F( |
   //RCR6 C) W/ ]6 D, H4 u% o9 b. @
   //RPHASE-0,RFRLEN2-0,RWDLEN2-2,RCOMPAND-0,RFIG-1,+ H) L7 Q& B% N  ~" w' P, A
   //RDATDLY-0,RFRLEN1-0,RWDLEN1-2,RWDREVRS-0
5 F5 j, j( Y  N* z( }& P   temp = 0x00440040;
$ G9 L- Z* g, K9 G   writel(temp,IO_ADDRESS(RCR_ADDR));  //initialized   + l7 ~( q! H7 t; K& @
   temp = readl(IO_ADDRESS(RCR_ADDR));! _; p" V& A' z* }7 G
   printk("temp=%x\n",temp);
7 [$ u2 q6 g* l' \2 }   //XCR2 G7 A7 H8 i: u' z& e
   //XPHASE-0,XFRLEN2-0,XWDLEN2-2,XCOMPAND-0,XFIG-1
0 }" b# `1 \" x% D; `; k   //XDATDLY-0,XFRLEN1-0,XWDLEN1-2,XWDREVRS-03 Q. _6 C# L3 L
   temp = 0x00440040;4 U% A! R* W" Q& O/ J2 w
   writel(temp,IO_ADDRESS(XCR_ADDR));  //initialized   8 z% j5 {: C, Z  @& `3 j0 r! a
   temp = readl(IO_ADDRESS(XCR_ADDR));: L- p% t+ h6 f& K+ X
   printk("temp=%x\n",temp);) `$ m& c4 Q% a$ X( K& z
  udelay(100);
* Q% g/ `* y8 Q5 ~9 |- ]  //SPCR Register
7 \6 S; n6 O4 z  //FREE-1,SOFT-1,FRST-1,GRST-1,XRST-1,RRST-16 S: F7 Y& d8 C. \; o* Q- s; Z
  temp = 0x03C10001;   //DLB = 0 VS DLB = 1
. V. C. }/ U) O/ F) A2 i9 y( G  writel(temp,IO_ADDRESS(SPCR_ADDR));  //enabled
6 K- B1 ~% b1 z% r0 [$ z  M- O# l3 R  temp = readl(IO_ADDRESS(SPCR_ADDR));: K4 {( ]5 t  B- \; ^4 k
  printk("temp=%x\n",temp);
; A! e$ h% |% e9 j  udelay(100);
7 s& Q  n. M) j# y6 i, J
2 q" p! D* w& M; l  //set GPIO direction
( M6 T8 \- z3 z1 B5 z8 w7 U   temp = __raw_readl(IO_ADDRESS(GPIO8_DIRECT));! O7 G5 F3 w. L9 q3 K
   temp = temp | 0x00000100;//EPR----input: X) G% |7 V% f  J/ `0 ]) I; Z
   temp = temp&(~0x00000500);//RESETn,SLEEP_EN---output
, K& m9 l5 A  ~$ w% h# r   __raw_writel(temp,IO_ADDRESS(GPIO8_DIRECT)); " c& h5 d  p3 Y: y
. a1 J, [+ p# t) P
   return 0;
; U! P$ I+ w0 W5 |! w! E}
$ \0 m2 Y  i( w) T, K; k9 \8 }( Wstatic void __exit MCBSP_exit(void)
) P. x; R( W4 H* _: S# r: U6 M{7 A$ I4 ]7 ~3 Y6 K$ K; {  Q
   printk("mcbsp chrdev exit!\n");& V' y) h+ o7 X, b$ K- E. _) `
   cdev_del(mcbsp_cdev);8 [+ P4 J9 T5 {. N* h9 ~
   unregister_chrdev_region(mcbsp_dev,count);9 L6 W* Y& j- j& o) K' ]4 f5 p
   device_destroy(mcbsp_class,mcbsp_dev);3 b2 B2 s2 g8 a
   class_destroy(mcbsp_class);6 r0 C9 A6 \! G$ }9 ^7 Y
}, w+ X# n& p4 v  p$ T5 \
module_init(MCBSP_init);
# N; {( ~: T! Z  N3 l9 Hmodule_exit(MCBSP_exit);5 T  F7 _  E# ]9 x" m

" A# ^" n4 f3 ^; zMODULE_LICENSE("GPL");
% u" [5 A) Z# G2 O0 R8 P) X4 w1 l0 j  u3 R2 q8 o* k
我讲上面的程序insmod之后我用示波器量 McBSP的发送时钟脚,发送数据脚(我还没有发送数据)以及发送同步脚,3个脚的信号是一样的,不管是用我自己的底板测试还是用创龙OMAPL38 的开发板测试,都是一样的,类似于噪声的信号时钟频率也不对。
6 b+ ]: Q2 @, ?我的应用层的测试程序如下
4 q3 W) X3 P; G2 f6 P& G. F  ?/ M#include <stdio.h>
0 F$ g1 \! s1 b+ d3 p6 t- P6 Y8 p#include <string.h>
% m8 b# x' J- @2 g! D) n- S2 R#include <fcntl.h>* I- H5 {+ ]& J
#include <unistd.h>
4 V- U/ u; d8 w, h/ Z  w#include <signal.h>4 P$ \6 v: j. S) ~% j, b5 R
#include <pthread.h>       //线程
) t' p1 V6 }+ h1 `7 a#include <stdlib.h>) T- H- ^9 o3 B1 ~, {
#include <pcap.h>          //捕获网口数据2 n& _$ R2 u' C( @3 l
#include <semaphore.h>     //信号1 _+ N; z6 S0 u
#include <sys/types.h>     //消息对列( D7 ]* R2 W0 G# ^" H$ }
#include <sys/ipc.h>       //消息队列
# d& {. ]# P6 [#include <sys/msg.h>       //消息队列8 J, `2 X: A0 @: V. @) l+ t
#include <sys/select.h>" m3 w1 Q9 \( G/ h
#include <sys/syscall.h>4 O8 u2 \- k* |5 N- i- T
#include <sys/stat.h>
* M3 E( e6 M  K) V5 r#include <sys/mman.h>
6 T8 B2 P  B0 _4 \, D8 q' E#define msleep(x) usleep(1000*x)
5 R% P: C& f$ f) G/ H" x) R. q3 Z- G3 W, r0 I/ f6 p0 c
int main()
5 ]- l9 e* n0 k/ k4 w* k{ & d: U, ^% N6 `8 A$ G' S
    //MCBSP,ARM与AMBE2000交互设备
7 J9 ]/ e8 `7 j6 _5 v7 p/ M int fd;
: A8 f7 I7 z' ^4 r  R9 h7 I unsigned short data_write = 0x5555;* y3 U  ]3 d) o! {* |$ Y8 ?
unsigned short data_read = 0x00;
0 I! v0 [& [6 O1 g  fd = open("/dev/MCBSP-device", O_RDWR | O_NONBLOCK | O_SYNC);
3 H+ K1 R7 ~" k. e //  fd = open("/dev/led-device", O_RDWR | O_NONBLOCK | O_SYNC);. R% v. }) x3 F' k3 f& T
   
  ~* ~0 R3 T* j  if(fd < 0)" N6 i& b3 V0 V# n+ I! X; H
  {
6 j7 L8 N; M5 L; e     perror("open failed\n");3 g5 Q2 V2 K8 r* K* C
     return -1;
6 s" M6 v* m6 y4 M' c% f2 q( E. c  }
( Y, K% Y3 o! a/ h  5 x0 T7 {/ o  K( H7 Z: I9 B0 N
  while(1), r/ s" I+ g( F6 r
  {1 \( r5 g, v/ t2 F3 o
   
6 @* U5 l6 j! J- C$ @0 p   //AMBE2000每次读写是24个字为一帧- `8 d" v, C; B! P  H
   //写数据时将数据在底层存储起来,等到中断的时候再发送
, }7 U8 E1 c6 Q6 e( M% v" a   //AMBE2000输入数据是以0x13EC开头的
* P* X( f+ P3 f7 W# P   write(fd,&data_write,sizeof(unsigned short));0 M( \+ \! t6 ?+ J( p& B1 [
   
. n) F: A7 `  O* s; d. F' O   //读数据的时候,在底层中断中将接收到的数据存储起来,然后再传送到应用层  6 w8 E' h: g' L3 {' z
   read(fd,&data_read,sizeof(unsigned short));" ~) R  _1 H+ p8 N% P. J( f: Z
     N$ W+ [6 r% U3 c; M. i
   if(data_read == 0x13Ec)
5 f% h6 u1 w: p6 A   {
, E8 M. y7 n! ^: C' K# A% n   
$ A& d2 g* Z7 `2 o  a    printf("data_read = %x\n",data_read);! p! @) H+ R' K/ \; R
   }0 R; b. `+ ]: m
   - s7 T5 \7 V1 O, |, H
   msleep(10);
  c; p* g1 P; O: F/ Y  
- S  s! c  u8 f- X, Y) s2 }  /*. g  L2 [& h. j  z
   ioctl(fd,1);   
! {7 ^; W" b" z- K0 l$ W  w sleep(1);
) _) [, {/ E! i+ u ioctl(fd,0);
: d) m2 N+ P7 [' ]" E/ L sleep(1);2 b. A8 _( D1 c$ N6 ^& g) q( h- d
*/
1 q5 U) \7 s0 |* L) B8 u) m  }   / a! [3 {- U: P$ T' |, m. _5 y
return 0;
; U6 t' {4 M' X% j! D $ e6 N2 Q  u% G- S: u
}
" y! z" y" b7 F8 l3 \9 T6 h( x( k
多谢各位指教,谢谢! 急
& ]/ a  J  X3 T, V" P, n& B# f2 w
$ [0 X; |4 i7 R: L3 N
3 C3 i" R" ?. P; w0 f9 ^" P$ W5 F1 }2 C

1 [$ g8 K+ B$ U/ e: G, q/ t
! {0 g& h: u* t' Q+ v
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖
回复

使用道具 举报

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

本版积分规则

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

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

GMT+8, 2026-2-26 22:45 , Processed in 0.055730 second(s), 26 queries .

Powered by Discuz! X3.2

© 2001-2015 Comsenz Inc.

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