简体中文 | 日本語
7 Replies Latest reply: Jul 8, 2012 4:23 AM by chenza RSS

读写SD卡出错

chenza Contributor
Currently Being Moderated

大家好!

我通过MMC_SPI读取SD卡中的文件,使用多线程读取多个文件时,时不时会停止,并且网卡看门狗(NETDEV WATCHDOG)会溢出,读操作停止,过3~5秒后,启动读操作又正常。情况如下:

------------[ cut here ]------------

WARNING: at net/sched/sch_generic.c:256 _dev_watchdog+0x206/0x20c()

NETDEV WATCHDOG: eth0 (dm9000): transmit queue 0 timed out

Modules linked in:

Hardware Trace:

   0 Target : <0x0034cac8> { _dump_stack + 0x0 }

     Source : <0x002107f8> { _warn_slowpath_common + 0x40 } CALL pcrel

   1 Target : <0x002107f8> { _warn_slowpath_common + 0x40 }

     Source : <0x0022d038> { _print_modules + 0x4c } RTS

   2 Target : <0x0022d032> { _print_modules + 0x46 }

     Source : <0x0034cbd0> { _printk + 0x14 } RTS

   3 Target : <0x0034cbcc> { _printk + 0x10 }

     Source : <0x00211466> { _vprintk + 0x16a } RTS

   4 Target : <0x00211444> { _vprintk + 0x148 }

     Source : <0x0021152e> { _vprintk + 0x232 } JUMP.S

   5 Target : <0x0021152e> { _vprintk + 0x232 }

     Source : <0x00211082> { _release_console_sem + 0x1be } RTS

   6 Target : <0x0021107a> { _release_console_sem + 0x1b6 }

     Source : <0x0021106c> { _release_console_sem + 0x1a8 } IF CC JUMP pcrel

   7 Target : <0x0021105c> { _release_console_sem + 0x198 }

     Source : <0x0021104e> { _release_console_sem + 0x18a } IF CC JUMP pcrel (BP)

   8 Target : <0x00211046> { _release_console_sem + 0x182 }

     Source : <0x002242e2> { _up + 0x3e } RTS

   9 Target : <0x002242dc> { _up + 0x38 }

     Source : <0x002242ce> { _up + 0x2a } IF CC JUMP pcrel (BP)

  10 Target : <0x002242a4> { _up + 0x0 }

     Source : <0x00211042> { _release_console_sem + 0x17e } CALL pcrel

  11 Target : <0x0021102e> { _release_console_sem + 0x16a }

     Source : <0x00210f26> { _release_console_sem + 0x62 } IF CC JUMP pcrel

  12 Target : <0x00210f06> { _release_console_sem + 0x42 }

     Source : <0x00210f58> { _release_console_sem + 0x94 } IF CC JUMP pcrel (BP)

  13 Target : <0x00210f4e> { _release_console_sem + 0x8a }

     Source : <0x00210ace> { __call_console_drivers + 0x62 } RTS

  14 Target : <0x00210ac8> { __call_console_drivers + 0x5c }

     Source : <0x00210aa2> { __call_console_drivers + 0x36 } IF CC JUMP pcrel

  15 Target : <0x00210a92> { __call_console_drivers + 0x26 }

     Source : <0x00210a82> { __call_console_drivers + 0x16 } IF !CC JUMP pcrel (BP)

Stack info:

SP: [0x003ddd68] <0x003ddd68> /* kernel dynamic memory */

Memory from 0x003ddd60 to 003de000

003ddd60: 003ddd68  003ca1d0 [002107f8] 002107fc  003dddac  003a1024  0000000d  003a1024

003ddd80: 00000100  0031336a  0021084e  003ceaf4  00000000  000004e2  0000003f  00000000

003ddda0: 000004e2  003cc590  003dddac <003a103c> 003dddc4  0031336a  003cd794  0023f150

003dddc0: 00000001  01563c00  003dddd0  00000000  30396d64  00003030  00000000  00000000

003ddde0: 003dde00  0020eb24  003dde00 <0020eaf6> 0000002f  003cf23c  003ccd04  0000ffff

003dde00: 003ceaf4  0023f162  003c4d88  003c4d88 <002186ca> 003c4d88  003dde48  00313164

003dde20: 00000100  003c5594  0000003f  00000000  30a33b1e  0000002f  003bb258  003c5b94

003dde40: 003c5994  003c5794  003d1e0c  003d1e0c  003c4c60 <002150aa> 00000001  003c4c6c

003dde60: 003dc000  00000101  00000004  00000100  0000000a <00209a96> 00232044  003cfa74

003dde80: 003dc008  003dc008  00000006  003bb258  0020368c  003d3324  003dc008  003dc008

003ddea0: 00000006  00000000  00000000  00000000  0000000d  00000000  00000361  002091e6

003ddec0: ffc00014  002005d4  00000000  7ffff000  000000c0  00000137  002005fc  00008050

003ddee0: 00000000  00000000  019b0000  0094d40c  002005fc <00200c58> 00000006  02002060

003ddf00: 008b5589  002b00a8  008b5582  002b00a6  00000000  00000000  0000071a  00000000

003ddf20: 0000348c  00000000  00000000  7ffff000  000000c0  00000137  00000000  00000000

003ddf40: 00000000  00000000  0000005b  00001802  00000001  fffffffc  00000006  00000003

003ddf60: 00000001  0192feb0  003de000  003bb258  002005d4  003dc008  003dc008  003ccd04

003ddf80: 00000000  00208f60  002005d4  00000000  00000000  00000000  00000065  00000008

003ddfa0: 019accc0  0000ffff  0000ffff  00208f60  00000006  00000000  003f44fc  00000000

003ddfc0: 003de000  003de648  003c6408  003bb004  00000000  003f44fc  0038042c  003f1b34

003ddfe0: 003ba3e0  00000035  003de218  003f44fc  003e5472  00000000  00000000  ffb00000

Return addresses in stack:

    address : <0x002107f8> { _warn_slowpath_common + 0x40 }

    address : <0x003a103c> /* kernel dynamic memory */

    address : <0x0020eaf6> { _try_to_wake_up + 0x5e }

    address : <0x002186ca> { _run_timer_softirq + 0xea }

    address : <0x002150aa> { ___do_softirq + 0x76 }

    address : <0x00209a96> { _bfin_demux_gpio_irq + 0x4e }

    address : <0x00200c58> { _cpu_idle + 0x30 }

---[ end trace 8544a311ca8a6058 ]---

好象是从SD卡读数据时卡在那里,连内核都得不到运行,那位大家遇过这种现象,如何解决? 我使用2010R1-RC4版本

     期望着!

---陈忠安

  • 1. Re: 读写SD卡出错
    Aaronwu Analog Employee
    Currently Being Moderated

    Could you post your test application here?

  • 2. Re: 读写SD卡出错
    chenza Contributor
    Currently Being Moderated

    Hi, Aaronwu!

    Thanks for your reply.

    here is the application:

    1. one thread:

      open the file:

       m_pVNet->Lock();

      pf = fopen(FileName, "rb");

       m_pVNet->WaittoUnLock();

    read the file in one thread:

    while(1) {

      if (!m_Holt) {

       for (unsigned int i=0; i<4; i++) {

        if (m_ReadRecode[i].Addr.nIp !=0 ) {

         if (m_ReadRecode[i].Ack == 1) {

          m_pVNet->Lock();

          m_ReadRecode[i].Packet.len = fread(m_ReadRecode[i].Packet.value, 1, MAX_PACKET_SIZE, m_ReadRecode[i].pf);

          m_pVNet->WaittoUnLock();

          m_ReadRecode[i].Packet.index++;

          m_ReadRecode[i].Ack = 0;

          m_ReadRecode[i].lostnums = 0;

         }

         else if (++m_ReadRecode[i].lostnums >= 400) {

          m_ReadRecode[i].Addr.nIp  = 0;

          m_pVNet->Lock();

          fclose(m_ReadRecode[i].pf);

          m_pVNet->WaittoUnLock();

          continue;

         }

         if (m_ReadRecode[i].lostnums%20 == 0) { // 每160ms上传一次

          addr_remote.sin_addr.s_addr = m_ReadRecode[i].Addr.nIp;

          addr_remote.sin_port = m_ReadRecode[i].Addr.nPort;

          sendto(m_pVNet->m_pDoc->m_Sock, &m_ReadRecode[i].Packet, m_ReadRecode[i].Packet.len+12, 0,

            (struct sockaddr*)&addr_remote, sizeof(addr_remote));

          if (m_ReadRecode[i].Packet.len == 0) {

           m_ReadRecode[i].Addr.nIp  = 0;

           m_pVNet->Lock();

           fclose(m_ReadRecode[i].pf);

           m_pVNet->WaittoUnLock();

          }

         }

        }

       }

      }

      usleep(4000);

    }

     

    2.another thread read by FFMPEG

       m_pVNet->Lock();
      if (av_open_input_file(&pFormatCtx, m_FileName, NULL, 0, NULL) != 0) {
        m_pVNet->WaittoUnLock();
        goto EXIT1;
       }

       if (av_find_stream_info(pFormatCtx) < 0) {
        m_pVNet->WaittoUnLock();
        goto EXIT2;
       }
       m_pVNet->WaittoUnLock();

         .

         .

         .

       while (m_Run) {
        unsigned char mask = (1<<6);

        m_pVNet->Lock();
       ret = av_read_frame(pFormatCtx, &packet);
        m_pVNet->WaittoUnLock();
         .

         .

         .   

          if (sendcount >= 15) { // 2.4s内无应答
           m_Run = 0;
           break;
          }
         }
        }
        av_free_packet(&packet);
       }
       av_free(pPacketMsg);
    EXIT2:
       m_pVNet->Lock();
       av_close_input_file(pFormatCtx);
       m_pVNet->WaittoUnLock();
    EXIT1:
       if (m_OtherFile == 0)
        m_AddrInfo.nIp = 0;
       else
        usleep(100000);

     

    to this porblem, I take a lock in 12 ms times after a read operation .

  • 3. Re: 读写SD卡出错
    chenza Contributor
    Currently Being Moderated

    I use "bonnie++", the result is here:

    Version  1.94       ------Sequential Output------ --Sequential Input- --Random-

    Concurrency   1     -Per Chr- --Block-- -Rewrite- -Per Chr- --Block-- --Seeks--

    Machine        Size K/sec %CP K/sec %CP K/sec %CP K/sec %CP K/sec %CP  /sec %CP

    blackfin       300M    43  91   809   5   410   2   111  83   870   2  60.6   2

    Latency               509ms    1522ms    1350ms     153ms   81767us    1158ms

    Version  1.94       ------Sequential Create------ --------Random Create--------

    blackfin            -Create-- --Read--- -Delete-- -Create-- --Read--- -Delete--

                  files  /sec %CP  /sec %CP  /sec %CP  /sec %CP  /sec %CP  /sec %CP

                     16     7  96    14  96    54  95    11  95    14  96    12  93

    Latency               391ms     164ms     104ms     208ms     156ms     618ms

    1.93c,1.94,blackfin,1,507585383,300M,,43,91,809,5,410,2,111,83,870,2,60.6,2,16,,,,,7,96,14,96,54,95,11,95,14,96,12,93,509ms,1522ms,1350ms,153ms,81767us,1158ms,391ms,164ms,104ms,208ms,156ms,618ms

  • 4. Re: 读写SD卡出错
    Aaronwu Analog Employee
    Currently Being Moderated

    please post your complete code that could easily be complied/run on ADI board, we don't have time re-org your code.

  • 5. Re: 读写SD卡出错
    chenza Contributor
    Currently Being Moderated

    Hi, Aaronwu!

    Thanks for your reply.

    OK, I will test in other program, but My board is not suitable for ADI board, SD_SPI is simulation by SPORT.

    捕获.PNG

    捕获.PNG

    I will post test code and the result.

         thanks!

         --chenza

  • 6. Re: 读写SD卡出错
    chenza Contributor
    Currently Being Moderated

    Hi, Aaronwu!

    I use test code, every thing is ok, there are must be something mistake in my application program.

         thanks you, very much.

    --chenza

     

    /*
    * test.c
    */
    #include <stdlib.h>
    #include <stdio.h>
    #include <unistd.h>
    #include <pthread.h>
    #include <string.h>


    #define FILE_NAME "/mnt/fat/86-02-01_0753_A.mp4"
    #define SIZE1 1400
    #define SIZE2 1500

    void  *read2_thread(void)
    {
    FILE *fd;
    fd = fopen(FILE_NAME, "rb");
    if (fd == NULL) {
      printf("thread2 Open file err\n");
      return (void *)NULL;
    }

    while (1) {
      int len;
      char value[SIZE2];

      len = fread(value, 1, SIZE2, fd);
      if (len < SIZE2) {
       printf("thread2 read end, len is 0x%x\n", len);
       rewind(fd);
      }
    //  else
    //   printf("thread2 read one packet success\n");

      usleep(16000);
    }
    fclose(fd);

    return (void *)NULL;
    }

    int main(void)
    {
    pthread_t read2;
    pthread_create(&read2, NULL, (void *)read2_thread, NULL);

    FILE *fd;
    fd = fopen(FILE_NAME, "rb");
    if (fd == NULL) {
      printf("Open file err\n");
      return -1;
    }

    while (1) {
      int len;
      char value[SIZE1];

      len = fread(value, 1, SIZE1, fd);
      if (len < SIZE1) {
       printf("thread1 read end, len is 0x%x\n", len);
       rewind(fd);
      }
    //  else
    //   printf("thread1 read one packet success\n");

      usleep(12000);
    }
    fclose(fd);

    return 0;
    }

  • 7. Re: 读写SD卡出错
    chenza Contributor
    Currently Being Moderated

    解决问题:是电源的问题,我使用了二级LM2596,在示波器上看不出什么问题(可能示波器不够高级),稳压的电源对SD卡影响很大,读与写都可能造成问题,最后将LM2596分开,仅一级稳压即解决了问题。

More Like This

  • Retrieving data ...

Legend

  • Correct Answers - 4 points
  • Helpful Answers - 2 points