Ignore:
Timestamp:
Jun 20, 2018, 7:59:22 PM (6 years ago)
Author:
coas-nagasima
Message:

SDカードの挿抜を検知するよう更新

Location:
asp3_tinet_ecnl_rx/trunk/ntshell
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • asp3_tinet_ecnl_rx/trunk/ntshell/fatfs/ffarch.c

    r337 r359  
    5454#include "mbed_api.h"
    5555
    56 //extern ntstdio_t ntstdio;
     56extern ntstdio_t ntstdio;
     57
     58enum ffarch_state_t {
     59        FFS_IDLE,
     60        FFS_RETRY_WAIT,
     61};
     62
     63enum ffarch_state_t ffarch_state;
     64volatile int ffarch_timer;
     65int ffarch_retry_count;
     66uint8_t mmc_rspi_prev_status;
     67
     68static void ffarch_initialize();
     69
     70/*
     71 * FatFSタスク
     72 */
     73void ffarch_task(intptr_t exinf)
     74{
     75        ER ret, ret2;
     76        SYSTIM prev, now;
     77        int timer;
     78
     79        ffarch_initialize();
     80
     81        ret2 = get_tim(&now);
     82        if (ret2 != E_OK){
     83                ntstdio_printf(&ntstdio, "[ffarch] get_tim error: %s",
     84                        itron_strerror(ret2));
     85                return;
     86        }
     87
     88        for(;;){
     89                prev = now;
     90
     91                /* タイマー取得 */
     92                timer = ffarch_get_timer();
     93
     94                /* 待ち */
     95                ret = tslp_tsk(timer);
     96                if ((ret != E_OK) && (ret != E_TMOUT)) {
     97                        ntstdio_printf(&ntstdio, "[ffarch] tslp_tsk error: %s %d",
     98                                itron_strerror(ret), timer);
     99                        break;
     100                }
     101
     102                ret2 = get_tim(&now);
     103                if (ret2 != E_OK) {
     104                        ntstdio_printf(&ntstdio, "[ffarch] get_tim error: %s",
     105                                itron_strerror(ret2));
     106                        break;
     107                }
     108
     109                /* 時間経過 */
     110                int elapse = now - prev;
     111                ffarch_progress(elapse);
     112
     113                /* タイムアウト処理 */
     114                ffarch_timeout();
     115        }
     116}
    57117
    58118FATFS RomDisk;
     
    88148        //sdfs_init(&sdfs, P8_5, P8_6, P8_3, P8_4, "sd");
    89149
    90         result = SD_begin() ? 0 : -1;
    91         if (result == 0) {
    92                 printf("SD card (1:) OK!\n");
     150        ffarch_state = FFS_IDLE;
     151        ffarch_timer = 0;
     152        ffarch_retry_count = 3;
     153        mmc_rspi_prev_status = STA_NODISK;
     154
     155        ffarch_timeout();
     156
     157        act_tsk(FFARCH_TASK);
     158
     159        if (romdisk_init()) {
     160                ntstdio_printf(&ntstdio, "ROM disk (0:) OK!\n");
    93161        }
    94162        else {
    95                 printf("SD card (1:) NG!\n");
    96         }
     163                ntstdio_printf(&ntstdio, "ROM disk (0:) NG!\n");
     164        }
     165
     166        serial_ctl_por(SIO_PORTID, IOCTL_FCSND | IOCTL_FCRCV);
     167}
     168
     169void ffarch_initialize()
     170{
    97171        sta_cyc(MMC_RSPI_CYC);
    98 
    99         if (romdisk_init())
    100                 result = 0;
    101 
    102         if (result == 0) {
    103                 printf("ROM disk (0:) OK!\n");
    104         }
    105         else {
    106                 printf("ROM disk (0:) NG!\n");
    107         }
    108 
    109         /* uploadディレクトリを作成しておく */
    110         f_mkdir("1:/upload");
    111 
    112         serial_ctl_por(SIO_PORTID, IOCTL_FCSND | IOCTL_FCRCV);
    113 
    114         return result;
    115172}
    116173
     
    216273        }
    217274        return RES_PARERR;
     275}
     276
     277void mmc_rspi_status_changed(DSTATUS newst)
     278{
     279        if (ffarch_state == FFS_IDLE) {
     280                mmc_rspi_prev_status = mmc_rspi_status();
     281                ffarch_timer = 0;
     282                wup_tsk(FFARCH_TASK);
     283        }
     284}
     285
     286int ffarch_get_timer()
     287{
     288        return ffarch_timer;
     289}
     290
     291void ffarch_progress(int elapse)
     292{
     293        if (ffarch_timer != TMO_FEVR) {
     294                ffarch_timer -= elapse;
     295                if (ffarch_timer < 0) {
     296                        ffarch_timer = 0;
     297                }
     298        }
     299}
     300
     301void ffarch_timeout()
     302{
     303        if (ffarch_timer != 0)
     304                return;
     305
     306        switch (ffarch_state) {
     307        case FFS_RETRY_WAIT:
     308                if (ffarch_retry_count == 0) {
     309                        ntstdio_printf(&ntstdio, "SD card (1:) initialize tired...\n");
     310
     311                        ffarch_state = FFS_IDLE;
     312                        ffarch_timer = TMO_FEVR;
     313                        ffarch_retry_count = 3;
     314                        break;
     315                }
     316                ffarch_retry_count--;
     317                //goto case FFS_IDLE;
     318        case FFS_IDLE:
     319                /* SDカードが入れられた場合 */
     320                if (((mmc_rspi_prev_status & STA_NODISK) != 0) && ((mmc_rspi_status() & STA_NODISK) == 0)) {
     321                        ntstdio_printf(&ntstdio, "SD card initializing ...\n");
     322
     323                        Sd.FatFs.fs_type = 0;
     324                        if (SD_begin()) {
     325                                ntstdio_printf(&ntstdio, "SD card (1:) OK!\n");
     326
     327                                /* uploadディレクトリを作成しておく */
     328                                f_mkdir("1:/upload");
     329
     330                                ffarch_state = FFS_IDLE;
     331                                ffarch_timer = TMO_FEVR;
     332                                ffarch_retry_count = 3;
     333                        }
     334                        else {
     335                                ntstdio_printf(&ntstdio, "SD card (1:) NG!\n");
     336                                ffarch_state = FFS_RETRY_WAIT;
     337                                ffarch_timer = 1000 * 1000;
     338                        }
     339                }
     340                /* SDカードが抜かれた場合 */
     341                else if (((mmc_rspi_prev_status & STA_NODISK) == 0) && ((mmc_rspi_status() & STA_NODISK) != 0)) {
     342                        ntstdio_printf(&ntstdio, "SD card unmount\n");
     343
     344                        f_mount(&Sd.FatFs, "1:", 0);
     345                        ffarch_state = FFS_IDLE;
     346                        ffarch_timer = TMO_FEVR;
     347                        ffarch_retry_count = 3;
     348                }
     349                mmc_rspi_prev_status = mmc_rspi_status();
     350                break;
     351        }
    218352}
    219353
  • asp3_tinet_ecnl_rx/trunk/ntshell/fatfs/ffarch.cfg

    r337 r359  
    3838#include "ffarch.h"
    3939
     40CRE_TSK(FFARCH_TASK, { TA_NULL, 0, ffarch_task, FFARCH_PRIORITY, FFARCH_STACK_SIZE, NULL });
    4041INCLUDE("mmc_rspi.cfg");
    4142
  • asp3_tinet_ecnl_rx/trunk/ntshell/fatfs/ffarch.h

    r337 r359  
    3838#define _FFARCH_H_
    3939
    40 int ffarch_init();
     40#define FFARCH_PRIORITY                 5
     41#define FFARCH_STACK_SIZE               512
     42
     43void ffarch_init();
     44void ffarch_task(intptr_t exinf);
     45int ffarch_get_timer();
     46void ffarch_progress(int elapse);
     47void ffarch_timeout();
     48
    4149void sdfs_cychdr(intptr_t exinf);
    4250
  • asp3_tinet_ecnl_rx/trunk/ntshell/fatfs/mmc_rspi.c

    r343 r359  
    201201        ena_int(INTNO_MMC_RSPI_SPII);
    202202
    203         sta_cyc(MMC_RSPI_CYC);
     203        /*sta_cyc(MMC_RSPI_CYC);*/
    204204}
    205205
     
    211211void power_off(void)    /* Disable MMC/SDC interface */
    212212{
    213         stp_cyc(MMC_RSPI_CYC);
     213        /*stp_cyc(MMC_RSPI_CYC);*/
    214214
    215215        dis_int(INTNO_MMC_RSPI_SPRI);
     
    745745        else            /* Socket empty */
    746746                s |= (STA_NODISK | STA_NOINIT);
    747         Stat = s;
     747
     748        if (Stat != s) {
     749                mmc_rspi_status_changed(s);
     750                Stat = s;
     751        }
    748752}
    749753
  • asp3_tinet_ecnl_rx/trunk/ntshell/fatfs/mmc_rspi.h

    r337 r359  
    6767#endif
    6868
    69 extern void mmc_rspi_spri_handler(void);
    70 extern void mmc_rspi_spti_handler(void);
    71 extern void mmc_rspi_spii_handler(void);
    72 extern void mmc_rspi_cychdr(intptr_t exinf);
     69void mmc_rspi_spri_handler(void);
     70void mmc_rspi_spti_handler(void);
     71void mmc_rspi_spii_handler(void);
     72void mmc_rspi_cychdr(intptr_t exinf);
     73void mmc_rspi_status_changed(DSTATUS newst);
    7374
    7475#endif /* _MMC_RSPI_H_ */
  • asp3_tinet_ecnl_rx/trunk/ntshell/src/fdtable.c

    r337 r359  
    400400                FD_SET(fd, (fd_set *)&flgptn);
    401401        }
    402         if (rpor.wricnt < rpor.wbufsz) {
     402        if (rpor.wricnt != 0) {
    403403                if (fp->writeevt_w == fp->writeevt_r) fp->writeevt_w++;
    404404
     
    428428                FD_SET(fd, (fd_set *)flgptn);
    429429        }
    430         if (rpor.wricnt < rpor.wbufsz) {
     430        if (rpor.wricnt != 0) {
    431431                if (fp->writeevt_w == fp->writeevt_r) fp->writeevt_w++;
    432432
  • asp3_tinet_ecnl_rx/trunk/ntshell/src/net_misc.c

    r340 r359  
    3333 *  の責任を負わない.
    3434 *
    35  *  @(#) $Id: net_misc.c 1497 2018-04-13 00:04:30Z coas-nagasima $
     35 *  @(#) $Id$
    3636 */
    3737
     
    6060#include "kernel_cfg.h"
    6161#include "tinet_cfg.h"
     62#include "util/ntstdio.h"
     63
     64extern ntstdio_t ntstdio;
    6265
    6366T_DHCP4_CLI_CONTEXT *dhcp4_cli_initialize(ID tskid, ID cepid);
     
    9497
    9598        get_tid(&nc->tskid);
    96         syslog(LOG_NOTICE, "[NET MISC:%d,%d] started.", nc->tskid, (ID)exinf);
     99        ntstdio_printf(&ntstdio, "[NET MISC:%d,%d] started.", nc->tskid, (ID)exinf);
    97100
    98101        /* 初期化 */
     
    102105        ret = get_tim(&time);
    103106        if (ret != E_OK) {
    104                 syslog(LOG_NOTICE, "[NET MISC,%d] get_tim error: %7lu,%s",
     107                ntstdio_printf(&ntstdio, "[NET MISC,%d] get_tim error: %7lu,%s",
    105108                        nc->cepid, time / SYSTIM_HZ, itron_strerror(ret));
    106109                return;
     
    116119                error = tslp_tsk(timer);
    117120                if ((error != E_OK) && (error != E_TMOUT)) {
    118                         syslog(LOG_NOTICE, "[NET MISC,%d] tslp_tsk error: %s %d",
     121                        ntstdio_printf(&ntstdio, "[NET MISC,%d] tslp_tsk error: %s %d",
    119122                                nc->cepid, itron_strerror(error), timer);
    120123                        break;
     
    123126                ret = get_tim(&time);
    124127                if (ret != E_OK) {
    125                         syslog(LOG_NOTICE, "[NET MISC,%d] get_tim error: %s",
     128                        ntstdio_printf(&ntstdio, "[NET MISC,%d] get_tim error: %s",
    126129                                nc->cepid, itron_strerror(ret));
    127130                        break;
  • asp3_tinet_ecnl_rx/trunk/ntshell/src/net_misc.cfg

    r340 r359  
    3333 *  の責任を負わない.
    3434 *
    35  *  @(#) $Id: net_misc.cfg 1497 2018-04-13 00:04:30Z coas-nagasima $
     35 *  @(#) $Id$
    3636 */
    3737
  • asp3_tinet_ecnl_rx/trunk/ntshell/src/net_misc.h

    r340 r359  
    3333 *  の責任を負わない.
    3434 *
    35  *  @(#) $Id: net_misc.h 1497 2018-04-13 00:04:30Z coas-nagasima $
     35 *  @(#) $Id$
    3636 */
    3737
  • asp3_tinet_ecnl_rx/trunk/ntshell/src/ntp_cli.c

    r340 r359  
    3333 *  の責任を負わない.
    3434 *
    35  *  @(#) $Id: ntp_cli.c 1496 2018-04-12 11:59:40Z coas-nagasima $
     35 *  @(#) $Id$
    3636 */
    3737
     
    5050#include <t_syslog.h>
    5151#include "kernel_cfg.h"
     52#include "util/ntstdio.h"
     53
     54extern ntstdio_t ntstdio;
    5255
    5356#endif  /* of #if defined(TARGET_KERNEL_ASP) */
     
    276279        }
    277280
    278         syslog(LOG_NOTICE, "[NTP CLI,%d] recv time: %s .%09u",
     281        ntstdio_printf(&ntstdio, "[NTP CLI,%d] recv time: %s .%09u\n",
    279282                nc->cepid, nc->buf, tp.tv_nsec);
    280283}
     
    308311                line = lookup_ipaddr(&nc->ipaddr6, NTP_SRV_URL, API_PROTO_IPV4);
    309312                if (line == NULL || !in6_is_addr_ipv4mapped(&nc->ipaddr6)) {
    310                         syslog(LOG_NOTICE, "[NTP CLI,%d] sleep %d.%03u[s], unknown host.",
     313                        ntstdio_printf(&ntstdio, "[NTP CLI,%d] sleep %d.%03u[s], unknown host.",
    311314                                nc->cepid, SLP_ITV / SYSTIM_HZ, SLP_ITV % SYSTIM_HZ);
    312315                        nc->timer = SLP_ITV;
     
    316319#else   /* of #if defined(SUPPORT_INET6) && defined(SUPPORT_INET4) */
    317320                if ((line = lookup_ipaddr(&nc->snd_rmt.ipaddr, NTP_SRV_URL, DEFAULT_API_PROTO)) == NULL) {
    318                         syslog(LOG_NOTICE, "[NTP CLI,%d] sleep %d.%03u[s], unknown host.",
     321                        ntstdio_printf(&ntstdio, "[NTP CLI,%d] sleep %d.%03u[s], unknown host.",
    319322                                nc->cepid, SLP_ITV / SYSTIM_HZ, SLP_ITV % SYSTIM_HZ);
    320323                        nc->timer = SLP_ITV;
     
    420423
    421424        if ((error = udp_snd_dat(nc->cepid, &nc->snd_rmt, ntp, len, TMO_NBLK)) != E_WBLK) {
    422                 syslog(LOG_NOTICE, "[NTP CLI,%d] udp_snd_dat error: %s",
     425                ntstdio_printf(&ntstdio, "[NTP CLI,%d] udp_snd_dat error: %s",
    423426                        nc->cepid, itron_strerror(error));
    424427                return error;
     
    438441        ret = get_tim(&time);
    439442        if (ret != E_OK) {
    440                 syslog(LOG_NOTICE, "[NTP CLI,%d] get_tim error: %s",
     443                ntstdio_printf(&ntstdio, "[NTP CLI,%d] get_tim error: %s",
    441444                        nc->cepid, itron_strerror(ret));
    442445                tp->tv_sec = 0;
     
    458461        ret = set_tim(time);
    459462        if (ret != E_OK) {
    460                 syslog(LOG_NOTICE, "[NTP CLI,%d] set_tim error: %s",
     463                ntstdio_printf(&ntstdio, "[NTP CLI,%d] set_tim error: %s",
    461464                        nc->cepid, itron_strerror(ret));
    462465        }
     
    476479        if (len < 0 && len != E_RLWAI) {
    477480                /* E_RLWAI 以外で、0 以下の場合は、エラーを意味している。*/
    478                 syslog(LOG_NOTICE, "[NTP CLI,%d] callback error: %s, fncd: %s", nc->cepid,
     481                ntstdio_printf(&ntstdio, "[NTP CLI,%d] callback error: %s, fncd: %s", nc->cepid,
    479482                        itron_strerror(len), in_strtfn(fncd));
    480483        }
     
    483486                        if ((len = udp_rcv_dat(nc->cepid, &nc->rcv_rmt, &nc->ntp_msg, len, TMO_POL)) < 0)
    484487                        {
    485                                 syslog(LOG_NOTICE, "[NTP CLI,%d] udp_rcv_dat error: %s", nc->cepid,
     488                                ntstdio_printf(&ntstdio, "[NTP CLI,%d] udp_rcv_dat error: %s", nc->cepid,
    486489                                        itron_strerror(len));
    487490                        }
     
    515518
    516519        get_tid(&nc->tskid);
    517         syslog(LOG_NOTICE, "[NTP CLI:%d,%d] started.", nc->tskid, (ID)exinf);
     520        ntstdio_printf(&ntstdio, "[NTP CLI:%d,%d] started.", nc->tskid, (ID)exinf);
    518521
    519522        /* 初期化 */
     
    522525        ret = get_tim(&time);
    523526        if (ret != E_OK) {
    524                 syslog(LOG_NOTICE, "[NTP CLI,%d] get_tim error: %7lu,%s",
     527                ntstdio_printf(&ntstdio, "[NTP CLI,%d] get_tim error: %7lu,%s",
    525528                        nc->cepid, time / SYSTIM_HZ, itron_strerror(ret));
    526529                return;
     
    536539                error = tslp_tsk(timer);
    537540                if ((error != E_OK) && (error != E_TMOUT)) {
    538                         syslog(LOG_NOTICE, "[NTP CLI,%d] tslp_tsk error: %s %d",
     541                        ntstdio_printf(&ntstdio, "[NTP CLI,%d] tslp_tsk error: %s %d",
    539542                                nc->cepid, itron_strerror(error), timer);
    540543                        break;
     
    543546                ret = get_tim(&time);
    544547                if (ret != E_OK) {
    545                         syslog(LOG_NOTICE, "[NTP CLI,%d] get_tim error: %s",
     548                        ntstdio_printf(&ntstdio, "[NTP CLI,%d] get_tim error: %s",
    546549                                nc->cepid, itron_strerror(ret));
    547550                        break;
  • asp3_tinet_ecnl_rx/trunk/ntshell/src/ntp_cli.cfg

    r340 r359  
    3333 *  の責任を負わない.
    3434 *
    35  *  @(#) $Id: ntp_cli.cfg 1496 2018-04-12 11:59:40Z coas-nagasima $
     35 *  @(#) $Id$
    3636 */
    3737
  • asp3_tinet_ecnl_rx/trunk/ntshell/src/ntp_cli.h

    r340 r359  
    3333 *  の責任を負わない.
    3434 *
    35  *  @(#) $Id: ntp_cli.h 1496 2018-04-12 11:59:40Z coas-nagasima $
     35 *  @(#) $Id$
    3636 */
    3737
  • asp3_tinet_ecnl_rx/trunk/ntshell/src/syscall.c

    r349 r359  
    3333 *  の責任を負わない.
    3434 *
    35  *  @(#) $Id: syscall.c 1530 2018-04-27 04:00:17Z coas-nagasima $
     35 *  @(#) $Id$
    3636 */
    3737#include "bits/syscall.h"
  • asp3_tinet_ecnl_rx/trunk/ntshell/src/tinet_ntp_cli.cfg

    r340 r359  
    2929 *  接的または間接的に生じたいかなる損害に関しても,その責任を負わない.
    3030 *
    31  *  @(#) $Id: tinet_ntp_cli.cfg 1291 2017-07-20 02:51:05Z coas-nagasima $
     31 *  @(#) $Id$
    3232 */
    3333
Note: See TracChangeset for help on using the changeset viewer.