コード例 #1
0
ファイル: main.cpp プロジェクト: Archcady/mbed-os
void test_attach_time(void)
{
    LowPowerTicker ticker;
    ticker_callback_flag = 0;

    gtimer.reset();
    gtimer.start();
    ticker.attach(callback(stop_gtimer_set_flag), ((float)DELAY_US) / 1000000.0f);
    while(!ticker_callback_flag);
    ticker.detach();
    const int time_diff = gtimer.read_us();

    TEST_ASSERT_UINT64_WITHIN(TOLERANCE_US, DELAY_US, time_diff);
}
コード例 #2
0
ファイル: main.cpp プロジェクト: Archcady/mbed-os
/** Test if detach cancel scheduled callback event

    Given a Ticker with callback attached
    When the callback is detached
    Then the callback is not being called
 */
void test_detach(void)
{
    LowPowerTicker ticker;
    int32_t ret;
    const float ticker_time_s = 0.1f;
    const uint32_t wait_time_ms = 500;
    Semaphore sem(0, 1);

    ticker.attach(callback(sem_release, &sem), ticker_time_s);

    ret = sem.wait();
    TEST_ASSERT_TRUE(ret > 0);

    ret = sem.wait();
    ticker.detach(); /* cancel */
    TEST_ASSERT_TRUE(ret > 0);

    ret = sem.wait(wait_time_ms);
    TEST_ASSERT_EQUAL(0, ret);
}
コード例 #3
0
/**
* Callback serial
**/
void serial(int events) {
    unsigned char i;
    if(events & SERIAL_EVENT_RX_CHARACTER_MATCH) {
        for(i = 0; i < BUFFER_LENGTH; i++) {
            if(rx_buffer[i] == 't') break;																									// 't' is received, check for buffer length
        }
        
        if(blinking) {																														// Toggle blink
            counter.detach();
            blinking = false;
        } else {
            counter.attach(blink, TOGGLE_SPEED);
            blinking = true;
        }
    } else if (events & SERIAL_EVENT_RX_COMPLETE) {
        i = BUFFER_LENGTH - 1;
    }
    
    test_connection.write(rx_buffer, i+1, 0, 0);																							// Echo string without callback																			
    test_connection.read(rx_buffer, BUFFER_LENGTH, serial_event, SERIAL_EVENT_RX_ALL, 't');													// Reset serial reception
}