countup.c

来自「最新版IAR FOR ARM(EWARM)5.11中的代码例子」· C语言 代码 · 共 60 行

C
60
字号
/**************************************************************************/
/*                                                                        */
/*     Copyright (C) 2006 Oki Electric Industry Co., LTD.                 */
/*                                                                        */
/*     System Name  :  uPLAT7D series                                     */
/*     Module Name  :  count up variable routine                          */
/*     File   Name  :  countup.c                                          */
/*     Revision     :  01.00                                              */
/*     Create       :  2006/2/6                                           */
/*                                                                        */
/**************************************************************************/
#include "common.h"
#include "hal_api.h"
#include "drv_api.h"
#include "drv_timer.h"

/************************************************************************/
/*                                                                      */
/*  Function Name   : countup                                           */
/*  Input           : Pointer of countup                                */
/*  Output          : OK(1)                                             */
/*                    ERROR(-1)                                         */
/*                                                                      */
/*  Note : Sample program of count up interval 30ms.                    */
/*                                                                      */
/************************************************************************/
int16_t countup( uint32_t *counter )
{
    int16_t rtnVal = OK;
    int16_t handle_timer;

    if (counter == NULL) {
        return ERROR;
    }
    *counter = 0;   /* Init counter */

    /* Initailize system timer. */
    handle_timer = smpDrv_open(DRVNO_TIMER, 1);
    /* System timer start. */
    if (handle_timer == HANDLE_ID_1) {
        rtnVal = smpDrv_ioctl(DRVNO_TIMER, UPLAT7D_HAL_TIMER_SET_START, 1, handle_timer);
    }
    /* Count up value */
    if (rtnVal == OK) {
        while((*counter<30)&&(rtnVal == OK)){
            rtnVal = smpDrv_poll(DRVNO_TIMER, 0, 1, handle_timer);     /* system timer 1ms polling */
            (*counter)++;
        }
    }
    /* System timer stop. */
    if (rtnVal == OK) {
        rtnVal = smpDrv_ioctl(DRVNO_TIMER, UPLAT7D_HAL_TIMER_SET_START, 0, handle_timer);
    }
    /* Close timer. */
    rtnVal = smpDrv_close(DRVNO_TIMER, handle_timer);
    
    return rtnVal;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?