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

嵌入式开发者社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

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

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

[复制链接]

6

主题

7

帖子

58

积分

注册会员

Rank: 2

积分
58
跳转到指定楼层
楼主
发表于 2014-10-16 10:58:57 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
我讲创龙在DSP中使用的例子移植到ARM中,如下是我的底层驱动程序:
+ {1 v9 L) o- v/*
; ]$ b) V9 G6 I% L8 l * Copyright (C) 2009 Texas Instruments Inc
6 m! G- L% e7 U4 [9 a1 V+ P/ B* y *
1 X8 }( j$ @4 ~( \% r. W& g * This program is free software; you can redistribute it and/or modify
9 ^0 b/ [$ f2 }- _$ H' W( g; ~ * it under the terms of the GNU General Public License as published by; L% C7 g- L+ q' a- G+ o
* the Free Software Foundation; either version 2 of the License, or2 o4 W0 F2 U" @# [$ n
* (at your option)any later version./ b! [( u! R) e: N
*- n6 d6 [0 q; M% G
* This program is distributed in the hope that it will be useful,
( P6 ~; K; `* V) e7 A1 a0 J * but WITHOUT ANY WARRANTY; without even the implied warranty of
3 q# t6 C0 T* m0 H* n3 a. m) R/ j * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the. i! H$ G- b) _) ?0 I2 Q1 i
* GNU General Public License for more details.
9 L6 Z, O, {; o3 [) o, L) e$ W *5 E: V* ~7 F+ B# d( Q- ~) ?9 J& V
* You should have received a copy of the GNU General Public License. c* Z. H5 |. U) T$ l, i0 a
* along with this program; if not, write to the Free Software
1 ?) V+ Q$ |$ g * Foundati
+ c% J, B7 B' M4 c1 v: a  z6 G*/* [/ j9 }) v: w& ^( V8 I
#include <linux/module.h>$ S( g& z. o4 N$ Y# U$ n. W, g4 K
#include <linux/init.h>2 O  {3 {$ H0 D# p
#include <linux/errno.h>
3 u2 Q2 ]; J2 ^9 i1 z$ j1 T#include <linux/types.h>" k4 A+ w" V6 k" a6 J
#include <linux/interrupt.h>
- [9 E4 @/ M' a% h  [3 {#include <linux/io.h>
3 m0 s9 d- T* s& D#include <linux/sysctl.h>9 I& |: b' u1 I( R. y5 Q5 `: N
#include <linux/mm.h>  ?( `/ _& V5 c' e: O. J
#include <linux/delay.h>
- O0 o- T; B* \' u7 u" {( T#include<linux/kernel.h>* r( M! c0 X2 L( f
#include<linux/fs.h>
4 `9 c; z" v, M#include<linux/ioctl.h>
4 B2 v! z" K4 ~- w4 [* p  j#include<linux/cdev.h>
+ m9 g1 ?/ d3 P  s/ Q#include<linux/kdev_t.h>
: P3 E3 m- @! W#include<linux/gpio.h>
( ?$ Y- J, s2 W2 c! R  X#include <mach/hardware.h>
: l) t) \2 y2 ~9 \2 l  H' H#include <mach/irqs.h>
. u2 G/ A) A& f" N3 r8 F
  A8 Q9 d2 {0 V7 T#include <asm/mach-types.h>1 E/ F  A, f! L2 J" C+ C
#include <asm/mach/arch.h>5 S" k1 ]2 w7 w7 o) T
#include <mach/da8xx.h>& ]. I3 t" o) D6 s9 Q0 W! w5 k7 F
#define  SYSCFG_BASE   0x01c14000
3 y7 U6 {# k4 v2 \* f#define  PINMUX1_OFFSET   0x124 , B: M5 j8 [- f: |
#define  PINMUX18_OFFSET  0x168
7 C, K7 n, q0 E5 `# H+ C; l#define  PINMUX19_OFFSET  0x16c
' h/ l2 f+ L1 @7 T3 P#define  SPCR_ADDR    0x01D11008  //MCBSP1_SPCR7 L( G0 |6 d8 E* ^; V0 c$ Z
#define  RCR_ADDR     0x01D1100C  //MCBSP1_RCR
+ r5 U: ?9 `  Q7 @. w#define  XCR_ADDR     0x01D11010  //MCBSP1_XCR
; m0 ~9 f% A( j9 q1 ~: m#define  SRGR_ADDR    0x01D11014  //MCBSP1_SRGR
$ ?$ ^9 \, U" t# d4 c* Z#define  PCR_ADDR     0x01D11024  //MCBSP1_PCR
$ X4 H+ H# W0 f  n& P. v                            1 M' Z6 j8 `, I% l0 K4 c
#define DXR_ADDR      0x01D11004  //MCBSP1_DXR/ i  `: Q6 L7 k, _* ~  S
#define DRR_ADDR      0x01D11000  //MCBSP1_DRR
4 U% f, D+ k' ]/ S% l: H//PSC
( L( Y6 w# N- s/ b#define  PTCMD_ADDR   0x01E27120  $ Y) t$ U; H9 s. c
#define  MDCTL15_ADDR 0x01E27A3C
8 O1 u6 L7 u) ^1 L5 Y, m! w2 Y#define  PDCTL1_ADDR  0x01E27304
0 Y# n5 c5 J) o3 o0 H//GPIO8 direction5 U* B0 S' n! }4 [
#define GPIO8_DIRECT  0x01E260B0
, p; {2 ~. I  z, ]5 a0 r8 e#define GPIO8_OUT     0x01E260B4; i3 T% q7 |+ @6 P6 x$ y. [5 J1 k& Z
#define GPIO8_IN     0x01E260C0: d' t- O3 b4 G) e7 s( h6 P6 Q" E
* J- q5 k% L: O4 T; b- P
//#define MCBSP1_RINT    99              
3 ], c$ H5 J3 q8 a7 n$ Z% M9 U//#define MCBSP1_XINT    100  
+ @. \/ L& k0 O- _) g" I5 astatic int MCBSP_MAJOR=239;+ D  d$ P$ \7 n2 U, B
static int MCBSP_MINOR=0;' U0 F! x3 b/ \- ?; d8 y
static int count =1;
% o) R. G8 e. ~5 \  P' U! r- _8 w
#define MCBSP_NAME  "MCBSP-device"! u' D% N2 `$ A

7 `8 x* f" x6 |: {% c& Y2 ~static struct cdev *mcbsp_cdev;1 h: C. h1 h" ]. l6 G% h4 a7 |
static struct class *mcbsp_class;3 M: N4 |1 D4 s9 _# H2 s* Y
static dev_t mcbsp_dev;
- I# C! m0 {( Q! m, [unsigned int DRR_data;
3 W4 `6 v( V% u9 _( gunsigned int DXR_data;
* ^$ j+ E1 k0 L; |, N( dstatic int mcbsp_open(struct inode *inode,struct file *file)& U2 v1 h2 y( L7 [
{& W0 j: b2 ?" x  W- D/ c* V5 i9 g
   7 D' Y- b: j/ H0 ^
   //interrupt enable,initialized* @9 O% P$ N8 q( I* x+ h- ?
   unsigned int temp;- M3 I4 J/ y% e- S
   //SLEEP_EN(GPIO8[10])---0
. V) B- ~/ s/ ~; r$ S3 k6 f- S7 ]5 O   temp = __raw_readl(IO_ADDRESS(GPIO8_OUT));) v6 d" d, a4 d) c, }9 T5 B
   temp=temp&(~0x00000400);: x3 Z; `7 \8 G  Z6 E6 i+ W
   __raw_writel(temp,IO_ADDRESS(GPIO8_OUT));//GPIO8[10]
$ P7 H7 `; D' g: v) w( C5 w1 M  //RESETn(GPIO8[8])----0----10 A# z, T, m) b6 k- k  j$ `
   temp = __raw_readl(IO_ADDRESS(GPIO8_OUT));
# p+ b3 J/ b# x' M/ w5 V/ t- y( m   temp=temp&(~0x00000100);
2 [% q6 {; m( c2 L3 x   __raw_writel(temp,IO_ADDRESS(GPIO8_OUT));//GPIO8[8]---0
2 q9 Q/ `) T: G- D) x" G   udelay(100);& z: m4 j0 n/ X! Z9 {2 r; t7 \
   temp=temp| 0x00000100;4 d/ E3 O. n. F
   __raw_writel(temp,IO_ADDRESS(GPIO8_OUT));//GPIO8[8]---1' Q7 H" b9 D1 {+ p/ n
   udelay(100);
. U4 y; [$ i1 v' u, u7 \   printk("open success!\n");4 ^% C6 f( U/ i6 _  Z
   return 0;$ C- j& r. ^' M3 i5 }2 `% t6 u6 v
}
1 P7 K# ?1 T5 K: q" f: n0 v  n/ [6 l* h/ M$ V2 K* Z
static int mcbsp_release(struct inode *inode,struct file *file)
) z/ r) D( J9 m; T) z" j{
1 e$ X  J9 D: }' j   printk("release success!\n");
! j* U* C: V/ j" g   return 0;; g- z7 o% a: p2 h/ V1 M$ \
}# c/ s# I% A' v
3 D* ^" P% D$ R) K
static ssize_t mcbsp_write(struct file *filp,const char *buf,size_t len,loff_t *off)) ~2 h$ L$ n$ O, Y" U
{5 G/ ?2 |& ?+ J! Y2 e. B& B
    copy_from_user(&DXR_data,buf,len);
6 u4 y0 i" W% ^* I1 C$ V    iowrite32(DXR_data,IO_ADDRESS(DXR_ADDR));      
) l+ ?, u, k7 u4 F1 X6 z/ [2 Q    return 0;
: W6 L7 N& x) u- R9 l 1 @% ]9 e- I; m5 [& q
}
5 B1 `- ^5 l- B5 u: I$ G# C, O9 U
, W, r* [8 f: u/ J% d- w; H. fstatic ssize_t mcbsp_read(struct file *filp,char *buf,size_t len,loff_t *off)/ l. _2 a8 a: K$ Y1 o2 p7 H
{ - A6 x7 i: w) q
   DRR_data = ioread16(IO_ADDRESS(DRR_ADDR));/ N) V1 c5 J- U) k# i
   copy_to_user(buf,&DRR_data,len); 7 o* P' i4 ]+ ]# b. \  X! ~
   return 0;, X' I8 B5 h+ |5 |% M5 p
}# a* D$ V5 x% u2 m2 |+ K

) F1 U: W" S5 s# X. E- a8 {7 x! K. d- k
static struct  file_operations mcbsp_fops=
9 n3 j! y/ f8 c# a9 o# j{
3 A' M3 e" b1 C9 k  i7 \   .owner=THIS_MODULE,# N) p, c; R0 C) c( \9 F' b! E- b
   .open=mcbsp_open,
  S) J1 s7 Z7 f   .release=mcbsp_release,
' B, E& J" R7 C8 g   .write=mcbsp_write,
: |- r% ?( b, S1 T1 k   .read=mcbsp_read,
3 i  S! f' ~) f};
! O7 L$ r7 i4 q! Q( Y1 K- ustatic int __init MCBSP_init(void)
4 q4 h5 F9 \" S$ q. I' t# Y0 V{
  H" ]" V1 O1 Q1 A7 ]/ N* _   int ret;
) _) F1 I' V$ k6 a% D2 C: r: }   unsigned  int   PINMUX1_REG_old;
+ E, B% k. J' T2 k* ~3 D) e   unsigned  int   PINMUX18_REG_old;
2 u( O' |& e8 @( {( f' W. Y   unsigned  int   PINMUX19_REG_old;% F1 b* L, N- K& J4 |. t, q* [: J
   unsigned  int   temp;  - ^: K% s2 R' y! y5 [
   if(MCBSP_MAJOR)
6 }) y2 a: W! j# C& X: n' \2 Z0 ]7 u   {& W- ^+ x5 ]: h) b1 O' o, a- D
      mcbsp_dev=MKDEV(MCBSP_MAJOR,MCBSP_MINOR);) y1 s" a+ d3 n3 {
      ret=register_chrdev_region(mcbsp_dev,count,MCBSP_NAME);0 }2 ]8 F2 O7 J$ F% m1 k$ O
   }
3 V2 l! `* e& U8 q7 s5 U( r3 z   else
- s/ a0 f0 z; ?. D   {6 f6 _% \& R! Z1 Y7 V
      ret=alloc_chrdev_region(&mcbsp_dev,MCBSP_MINOR,count,MCBSP_NAME);3 [- @5 s/ d3 q( M4 D; h( Z7 K  g
      MCBSP_MAJOR=MAJOR(mcbsp_dev);
! g8 x, \  y) B$ R) v   }, X: p6 ]- f# r8 T5 H- t; r
     {5 ~( }& r$ n7 {' S: d. m
   if(ret<0)
/ t3 s; }1 X. ^7 E5 P5 z! I   {
9 v/ c+ w" P$ d) T0 t, V) Q" D      printk(KERN_ERR "register chrdev fail!");0 L: @  N7 {* T, ~7 w
      return -1;
! r# t: U7 u( ^/ v* ^( k! l* ^   }
2 X8 p0 A8 e* C/ ]0 G& {( M     u/ M  K, M) D' c! D/ \
   mcbsp_cdev=cdev_alloc();
+ c. o! ]- I( Q1 I   
9 e- ?2 X+ m7 n1 q. Y6 K   if(mcbsp_cdev!=NULL)) J- l9 ?$ b% |6 V* b+ H
   {
0 _: w8 M1 S0 t$ ]& x5 Y: P. P      cdev_init(mcbsp_cdev,&mcbsp_fops);
6 P9 f; i: z) s& K2 E* l      mcbsp_cdev->ops=&mcbsp_fops;
# E% c) m' o6 _2 W+ z0 P" R      mcbsp_cdev->owner=THIS_MODULE;8 f7 Y0 N" D- `" ?  s
      
( j; C: w" i4 V. S! o8 s      if(cdev_add(mcbsp_cdev,mcbsp_dev,count))
- x' S) s# F7 O' t/ i; N2 k          printk(KERN_ERR "register cdev fail!");- u1 o% W. d! T0 `
      else# G( R) @; g9 q) w5 t4 P# G3 i
          printk(KERN_ERR "register success!\n");  R( b5 ]. P8 I: {6 b: r: Y
   }
; U, U# [3 Z- {9 z  g4 v$ u. `2 T$ R   else. x6 l' R& V& x' l
   {
# j0 B; x+ C! d( @$ b+ i. t      printk(KERN_ERR "register cdev err!");( B: T  [; @) x/ K. H1 e
      return -1;
; p8 e6 `) A# T) u) n   }/ U$ i. t1 r( |+ H" Y5 _8 q
   
' e' J* U) F7 S6 P+ ~* v  mcbsp_class=class_create(THIS_MODULE,MCBSP_NAME);4 X# b$ o% A: j
   if(IS_ERR(mcbsp_class))
& d, V0 `- ]6 c8 R+ s' Q2 ?( y   {
% e* ?4 M! G, s% p& U      printk(KERN_ERR "register class err!");2 o0 O4 [0 r: f- H3 l/ Z
   return -1;6 O8 d/ H  S1 ]8 G2 g+ e
   }: O4 m: R3 p( O, w3 G% A, T% W# D$ Z
   device_create(mcbsp_class,NULL,mcbsp_dev,NULL,MCBSP_NAME);
6 z" q6 m7 s( `- l) `' T! ]9 u! P4 v6 B0 y0 G( R1 s) ?4 ?
   //PSC
4 s1 O: q3 _- M/ Y6 @5 u   //add Enable MCBSP
" F4 H* k4 i: j- [   //test
. I# V+ I$ N  X   temp = 0x80000003;
5 f- c0 d$ J9 {8 y& i3 I  D   writel(temp, IO_ADDRESS(MDCTL15_ADDR));
5 d7 @9 q# l; H8 Q   temp = 0x00000003;- Q, G3 }3 K0 }1 y+ @7 S
   writel(temp, IO_ADDRESS(PTCMD_ADDR));6 f* o. k; g3 C+ y1 p, V
# r, M- @! e/ l% {( [
   temp = 0x001FF201;
7 W& H' _- U3 R: Q$ y, S+ m* w6 z   writel(temp, IO_ADDRESS(PDCTL1_ADDR));( x; A! K$ y* w3 p0 m
   ) m  H" o$ f5 V* X7 P$ ~
   //PINMUX  + g: c; T" Y: Y2 _
   //MCBSP_CLK(receive/send),MCBSP_STRB(receive/send),MCBSP_DX,MCBSP_DR,( U( D% I) P5 v: y  f
   PINMUX1_REG_old=readl(IO_ADDRESS(SYSCFG_BASE)+PINMUX1_OFFSET);    F  u7 @8 {+ B( w3 j7 |  g  ]
   PINMUX1_REG_old=(PINMUX1_REG_old&0xf000000f)|0x02222220;   ' V" |! m8 Q7 J$ @6 W
   writel(PINMUX1_REG_old, IO_ADDRESS(SYSCFG_BASE)+PINMUX1_OFFSET);' ?$ `4 }5 v9 L! I
   3 T% y3 {* @5 f
   //SLEEP_EN,EPR,L138_SHK1,L138_RC- Y) f/ h! m$ I# F8 N/ z
   PINMUX18_REG_old=readl(IO_ADDRESS(SYSCFG_BASE)+PINMUX18_OFFSET);  
0 h1 S8 [9 ~6 u2 E0 ?6 ?. o   PINMUX18_REG_old=(PINMUX18_REG_old&0x0000ffff)|0x88880000;   % x9 ~0 `- m. T
   writel(PINMUX18_REG_old, IO_ADDRESS(SYSCFG_BASE)+PINMUX18_OFFSET);
) t! {9 c: h* `2 I/ `9 l# |
  L) h7 N0 O( P! Z$ z5 q0 [   //RESETn,L138_SHK2
9 ~6 O& l/ ?3 d* f& |  D( {* t6 ~   PINMUX19_REG_old=readl(IO_ADDRESS(SYSCFG_BASE)+PINMUX19_OFFSET);  $ D4 m" E; I" c' W3 n- d, c* F- J1 p* k
   PINMUX19_REG_old=(PINMUX19_REG_old&0xf0ffff0f)|0x08000080;   
9 w% K& J8 b8 K7 |3 W+ L8 O( x   writel(PINMUX19_REG_old, IO_ADDRESS(SYSCFG_BASE)+PINMUX19_OFFSET);
! x$ S% s- F% J( R; h& [/ ~ 5 o! e1 i) X- o( Z# S+ L0 F

6 `% \: K# F6 F% V" N3 c  //SPCR Register5 c; I; f( L7 i, R' Q5 \
  //FREE-1,SOFT-1,FRST-0,GRST-0,XRST-0,RRST-0,RJUST-00(Zero-fill MSBs)reset# n& Y' T% U0 w$ k
  temp = 0x03000000;//(DLB=0)
& f5 }: h2 B% S8 g // temp = 0x03008000;//(DLB=1)
. Z0 J5 q& Y+ Z" p' }  writel(temp,IO_ADDRESS(SPCR_ADDR));  //reset
" S, B! P. C; H" t  temp = readl(IO_ADDRESS(SPCR_ADDR));$ Z' S% O  H! e4 o: h1 }. @
  printk("temp=%x\n",temp);
% E7 i: G$ L6 w- J& M. A  m + M8 q7 m8 x7 r/ v- e1 j
   //PCR Register- b  }! ~3 o( N0 }8 I4 ]
   //FSXM-1,FSRM-1,CLKXM-1,CLKRM-1,SCLKME-0,FSXP-0,FSRP-0,CLKXP-0,CLKRP-0
* i2 \1 c& k8 l& t0 |! g( V6 ?  // temp = 0x00000F0F;9 Z% }# E; `5 o2 P* J* O
  temp = 0x00000B0F;2 d! s0 Z9 x1 I+ ]1 K* R4 v7 X
  writel(temp,IO_ADDRESS(PCR_ADDR));  //initialized
, p( Q( D* x' |. \  temp = readl(IO_ADDRESS(PCR_ADDR));& o. V: C( e) Z% b1 p% X: k* @- ]
  printk("temp=%x\n",temp);  
9 M" Z  g  T. s0 _! O' A( [! S   //SRGR Register+ K6 ?/ Q( z7 a* O0 K; V9 Z
   //GSYNC-0,CLKSP-0,CLKSM-1,FPER-31,FWID-0,CLKGDV==117 D3 y6 ~/ x9 R
//temp = 0x301F000B;
. J1 P' Z# |# T" w% b& ?+ I: ~) @   writel(0x0301F000B,IO_ADDRESS(SRGR_ADDR));  //initialized , C4 z' F0 Z$ {# ^$ y+ K0 V
  temp = readl(IO_ADDRESS(SRGR_ADDR));
3 R+ y! ?, N/ [/ Q  printk("temp=%x\n",temp);& Q2 }* J) v: f
   //RCR
1 j9 k# F( V& w% I! V8 \* ~; v" F5 o   //RPHASE-0,RFRLEN2-0,RWDLEN2-2,RCOMPAND-0,RFIG-1,3 y) o* Y1 s. E6 s
   //RDATDLY-0,RFRLEN1-0,RWDLEN1-2,RWDREVRS-0
  W5 y9 c6 `6 S* ^* t4 [- B   temp = 0x00440040;
  S) _6 ]" R  P2 K% P! |   writel(temp,IO_ADDRESS(RCR_ADDR));  //initialized   : A6 L, w( V! x4 T) |- G
   temp = readl(IO_ADDRESS(RCR_ADDR));6 g0 }# b) S- l8 f* K$ M* v9 R  _$ e
   printk("temp=%x\n",temp);
. c  Z  Y9 A+ b% f   //XCR
3 u7 o) b& u0 a2 S7 t! w   //XPHASE-0,XFRLEN2-0,XWDLEN2-2,XCOMPAND-0,XFIG-1
% L1 q$ [- l$ R- P  {; f   //XDATDLY-0,XFRLEN1-0,XWDLEN1-2,XWDREVRS-0
; a- g$ }9 d, b9 l* V, x   temp = 0x00440040;" H# h2 `6 F# M# Z- q; R) A
   writel(temp,IO_ADDRESS(XCR_ADDR));  //initialized   
3 g% G/ \" J  d9 Q   temp = readl(IO_ADDRESS(XCR_ADDR));+ Z  `- \# X" x
   printk("temp=%x\n",temp);( y- K; m3 U* A9 f) q6 e6 W2 v  N3 \
  udelay(100);
& ?- c% K* }7 X- S  //SPCR Register$ k/ m& U4 v/ M" [. u. d  ~" O' x
  //FREE-1,SOFT-1,FRST-1,GRST-1,XRST-1,RRST-1
6 M" W* c1 ]1 }  temp = 0x03C10001;   //DLB = 0 VS DLB = 1
5 i# h" D# i  V" g7 c# A7 ~  writel(temp,IO_ADDRESS(SPCR_ADDR));  //enabled
' `% M# Y- B! o) g7 _) u  temp = readl(IO_ADDRESS(SPCR_ADDR));6 h3 U; }/ B! ^5 g8 E5 U
  printk("temp=%x\n",temp);
+ Q4 {5 ?# R$ L6 r  udelay(100);
2 q( h- R8 t9 [% U/ {$ |  U$ @  q) X9 {3 c
  //set GPIO direction
& J: C# f2 G& G% }9 @9 B' L  m   temp = __raw_readl(IO_ADDRESS(GPIO8_DIRECT));& ~+ v& F& C2 p* y/ S: B1 r
   temp = temp | 0x00000100;//EPR----input3 S  T) D4 h6 y' Y/ N! M+ [6 ?* D
   temp = temp&(~0x00000500);//RESETn,SLEEP_EN---output
' |3 `4 f- x6 [# o' S6 \+ d) t   __raw_writel(temp,IO_ADDRESS(GPIO8_DIRECT));   f( p( @" V$ j& |  I" d

8 U/ n) p9 b1 Y/ p! ?$ }   return 0;
* X) S' J+ L# ?7 j  }- {}1 X7 [( E& W( p9 K
static void __exit MCBSP_exit(void)
# F! ?2 E2 }2 t3 R( r% D{, H7 [5 P+ h1 b. I6 t; ?
   printk("mcbsp chrdev exit!\n");9 J  ~0 n8 h, G& T& V, J
   cdev_del(mcbsp_cdev);$ I: H( {, l& [# `" z
   unregister_chrdev_region(mcbsp_dev,count);8 Q, `9 a+ I: F4 V+ ^. T/ ?
   device_destroy(mcbsp_class,mcbsp_dev);! m; @! Q5 d7 v( p$ m' i
   class_destroy(mcbsp_class);5 g! H  g5 j8 ]" U
}* B/ k3 ?; \! C, {7 v9 V
module_init(MCBSP_init);7 c( c: O. F5 I# p4 ?% x3 d8 w2 k
module_exit(MCBSP_exit);
0 D5 D! c! W! }5 {. \* L
! @$ F& A& w& c# W* h% KMODULE_LICENSE("GPL");
$ h1 T7 M2 B6 j8 u0 H: Y
3 d; U; d; M$ t7 o- Y) b3 K8 y我讲上面的程序insmod之后我用示波器量 McBSP的发送时钟脚,发送数据脚(我还没有发送数据)以及发送同步脚,3个脚的信号是一样的,不管是用我自己的底板测试还是用创龙OMAPL38 的开发板测试,都是一样的,类似于噪声的信号时钟频率也不对。
6 r. B" j5 k# L6 n" l. v我的应用层的测试程序如下9 `: M0 x7 E; Y% D' c9 G& L
#include <stdio.h>
: q( s! n% {4 b# m#include <string.h>5 d2 s) _) J" o8 p. n' J
#include <fcntl.h>
) T1 w5 B+ W5 ~) `: r+ L+ m#include <unistd.h>2 ~+ P' o# w9 E$ W. j$ F
#include <signal.h>1 m! [& f  x' t
#include <pthread.h>       //线程
0 G# w0 V8 N% L#include <stdlib.h>
' K. `! F1 ]" ~$ n0 }  w( T#include <pcap.h>          //捕获网口数据* h6 ~7 I% J+ k# c* p  x
#include <semaphore.h>     //信号
9 W* K! w% F$ Y' L5 n- l$ x, M#include <sys/types.h>     //消息对列" ]) h( ^9 P% k! z2 b
#include <sys/ipc.h>       //消息队列5 H! G; \# Y& D0 ~
#include <sys/msg.h>       //消息队列8 L2 Y" U- ~( f, x( ?$ M
#include <sys/select.h>- l- E( I" x  [1 _6 i4 s' a4 P
#include <sys/syscall.h>, A; N" B9 n8 U% ?) B
#include <sys/stat.h>
5 |( D6 k3 e4 s* u) h6 B#include <sys/mman.h>- ]* l) _! \4 t4 A3 `8 k2 @
#define msleep(x) usleep(1000*x)* D' a9 ~" [+ e& o; E) w  H

$ i1 r2 r4 j% q" v" nint main()2 u7 U4 M# {( z3 s9 e3 y4 `2 o
{ 4 n8 F0 z, X) M+ l0 {9 Y
    //MCBSP,ARM与AMBE2000交互设备; x3 H, U9 v+ ~( b
int fd;! b6 l3 N8 @+ \) d4 M% o8 n6 `
unsigned short data_write = 0x5555;
. J* `" G) {, f unsigned short data_read = 0x00;. j$ ]8 V, ~" w
  fd = open("/dev/MCBSP-device", O_RDWR | O_NONBLOCK | O_SYNC);/ ?( G. ^. U! A
//  fd = open("/dev/led-device", O_RDWR | O_NONBLOCK | O_SYNC);
1 X) s$ x  u& y  ^   
& w/ k' K9 g8 h  z0 d4 S; r! w  if(fd < 0)
9 i0 z2 k7 t# l1 B0 J  {, S1 L3 z' l$ E3 C+ A
     perror("open failed\n");6 F8 I- q# S5 ?
     return -1;
, v% K, S. l9 S3 E4 E7 z/ h  }+ [% h! V0 B$ t/ {" x
  7 h6 Y- G1 ~4 l( v- J
  while(1)% S  w$ k; r" Y
  {; U  l0 _' a$ i( J0 G, o( E
   
+ o+ }9 F# p* p$ z% R1 h   //AMBE2000每次读写是24个字为一帧
, z0 p! X( B0 f  W, z# }% x   //写数据时将数据在底层存储起来,等到中断的时候再发送
7 ?0 ?  ?3 E! W1 O   //AMBE2000输入数据是以0x13EC开头的
6 |, U) u2 A1 c' I2 |) S" C' i) {3 A   write(fd,&data_write,sizeof(unsigned short));: [* R: E' C3 h; u  V* T% m4 ~
   
/ {: v- d, z( N$ R- o5 \# ?   //读数据的时候,在底层中断中将接收到的数据存储起来,然后再传送到应用层  ( H. s6 c$ z/ S. C/ K( Z9 B  \7 E
   read(fd,&data_read,sizeof(unsigned short));1 H, O, V( A) r# n7 K# i9 Y2 z
   
8 Q6 C# o4 m2 Z5 k0 v0 y9 p   if(data_read == 0x13Ec)
  w' E, B( C& Q6 R9 _   {
$ u/ k& X( b6 M# S2 I; |5 Z/ |   0 B( @( C& a& ~4 K( r# t+ w1 N
    printf("data_read = %x\n",data_read);! F9 O" I6 e4 p
   }3 B) Z; y# F. G- S  ]/ B  |6 e$ G
   
, u) W: G/ \" F, ~: N. R   msleep(10);$ v: L4 X/ m- P* U
  + W6 G" |1 e  ?- t
  /*0 w* u* ^: |7 w/ ~
   ioctl(fd,1);   2 X; r2 q1 H5 v9 ]" c8 [2 j
sleep(1);4 W, e7 ^/ \6 ]( z/ W4 Q4 [/ [8 C
ioctl(fd,0);1 A* l$ C8 z4 C* Q
sleep(1);
! ~: T  J; {  @. J; X1 I- a: | */ " B7 C# u8 K) Y
  }   7 G$ G# E$ V: e! j
return 0;
  M9 @4 J8 r7 ?$ O2 V 1 u7 ?# |; N. |
}0 z4 J5 b9 s; ~9 N
+ u3 j4 M2 G4 ?. C0 n* J+ P- h
多谢各位指教,谢谢! 急
: L' W4 A" K) `, ^; ~6 }
5 ~! u7 Q$ ?7 W, O4 Q3 b
4 x7 ?! O$ l  D+ E( M6 r7 C
8 W7 C  Q+ v2 Y7 I; [5 O  T) R/ j  N( H5 X, k! c8 f; i
: Y4 j& `# c1 D" P
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖
回复

使用道具 举报

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

本版积分规则

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

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

GMT+8, 2026-2-11 07:34 , Processed in 0.052060 second(s), 26 queries .

Powered by Discuz! X3.2

© 2001-2015 Comsenz Inc.

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