コード例 #1
0
ファイル: timers.c プロジェクト: Astralix/ethernut32
/*
 * Main application routine.
 */
int main(void)
{
    uint32_t baud = 115200;

    /*
     * Register the UART device, open it, assign stdout to it and set
     * the baudrate.
     */
    NutRegisterDevice(&DEV_CONSOLE, 0, 0);
    freopen(DEV_CONSOLE.dev_name, "w", stdout);
    _ioctl(_fileno(stdout), UART_SETSPEED, &baud);
    puts("\n\nNut/OS timer sample");

    /*
     * Display some general info.
     */
    printf("CPU running at %lu Hz\n", NutGetCpuClock());
    printf("%lu system ticks per second\n", NutTimerMillisToTicks(1000));

    /*
     * Run the demos.
     */
    OneShotDemo(10);
    PeriodicDemo(2);
    DelayDemo();
    SleepDemo(); /* Never returns. */

    return 0;
}
コード例 #2
0
ファイル: timer.c プロジェクト: niziak/ethernut-4.9
/*!
 * \brief Start a system timer.
 *
 * The function returns immediately, while the timer runs
 * asynchronously in the background.
 *
 * The timer counts for a specified number of milliseconds,
 * then calls the callback routine with a given argument.
 *
 * Even after the timer elapsed, the callback function is not executed
 * before the currently running thread is ready to give up the CPU. Thus,
 * system timers may not fulfill the required accuracy. For precise or
 * high resolution timing, native timer interrupt routines are a better
 * choice.
 *
 * \param ms       Specifies the timer interval in milliseconds. The
 *                 resolution is limited to the granularity of the system
 *                 timer.
 * \param callback Identifies the function to be called on each
 *                 timer interval.
 * \param arg      The argument passed to the callback function.
 * \param flags    If set to TM_ONESHOT, the timer will be stopped
 *                 after the first interval. Set to 0 for periodic
 *                 timers.
 *
 * \return Timer handle if successfull, 0 otherwise. The handle
 *         may be used to stop the timer by calling TimerStop.
 */
HANDLE NutTimerStart(uint32_t ms, void (*callback) (HANDLE, void *), void *arg, uint8_t flags)
{
        return NutTimerStartTicks(NutTimerMillisToTicks(ms), callback, arg, flags);
}