clock_t clock() {
    _mutex->lock();
    clock_t t = us_ticker_read();
    t /= 1000000 / CLOCKS_PER_SEC; // convert to processor time
    _mutex->unlock();
    return t;
}
Beispiel #2
0
void attach_rtc(time_t (*read_rtc)(void), void (*write_rtc)(time_t), void (*init_rtc)(void), int (*isenabled_rtc)(void)) {
    _mutex->lock();
    _rtc_read = read_rtc;
    _rtc_write = write_rtc;
    _rtc_init = init_rtc;
    _rtc_isenabled = isenabled_rtc;
    _mutex->unlock();
}
Beispiel #3
0
void set_time(time_t t) {
    _mutex->lock();
    if (_rtc_init != NULL) {
        _rtc_init();
    }
    if (_rtc_write != NULL) {
        _rtc_write(t);
    }
    _mutex->unlock();
}
// Called once at boot
void platform_timer_enable(void)
{
#if !MBED_CONF_NANOSTACK_HAL_CRITICAL_SECTION_USABLE_FROM_INTERRUPT
    equeue = mbed_highprio_event_queue();
    MBED_ASSERT(equeue != NULL);
#endif
    timer->start();
    // Prime the SingletonPtr - can't construct from IRQ/critical section
    timeout.get();
}
Beispiel #5
0
void mbedtls_platform_teardown( mbedtls_platform_context *unused_ctx )
{
    mbedtls_mutex->lock();
    --plat_ctx.reference_count;
    if( plat_ctx.reference_count < 1 )
    {
        /* call platform specific code to terminate crypto driver */
        crypto_platform_terminate( &plat_ctx.platform_impl_ctx );
        plat_ctx.reference_count = 0;
    }
    mbedtls_mutex->unlock();
}
Beispiel #6
0
int mbedtls_platform_setup( mbedtls_platform_context *unused_ctx )
{
    int ret = 0;
    mbedtls_mutex->lock();
    ++plat_ctx.reference_count;

    if( plat_ctx.reference_count == 1 )
    {
        /* call platform specific code to setup crypto driver */
        ret = crypto_platform_setup( &plat_ctx.platform_impl_ctx );
    }
    mbedtls_mutex->unlock();
    return ( ret );
}
Beispiel #7
0
static int platform_fhss_timer_start(uint32_t slots, void (*callback)(const fhss_api_t *api, uint16_t), const fhss_api_t *callback_param)
{
    int ret_val = -1;
    platform_enter_critical();
    if (timer_initialized == false) {
#if !MBED_CONF_NANOSTACK_HAL_CRITICAL_SECTION_USABLE_FROM_INTERRUPT
        equeue = mbed_highprio_event_queue();
        MBED_ASSERT(equeue != NULL);
#endif
        timer->start();
        timer_initialized = true;
    }
    fhss_timeout_s *fhss_tim = find_timeout(callback);
    if (!fhss_tim) {
        fhss_tim = allocate_timeout();
    }
    if (!fhss_tim) {
        platform_exit_critical();
        tr_error("Failed to allocate timeout");
        return ret_val;
    }
    fhss_tim->fhss_timer_callback = callback;
    fhss_tim->start_time = read_current_time();
    fhss_tim->stop_time = fhss_tim->start_time + slots;
    fhss_tim->active = true;
    fhss_tim->timeout->attach_us(timer_callback, slots);
    fhss_active_handle = callback_param;
    ret_val = 0;
    platform_exit_critical();
    return ret_val;
}
// This is called from inside platform_enter_critical - IRQs can't happen
uint16_t platform_timer_get_remaining_slots(void)
{
    uint32_t elapsed = timer->read_us();
    if (elapsed < due) {
        return (uint16_t) ((due - elapsed) / 50);
    } else {
        return 0;
    }
}
Beispiel #9
0
time_t time(time_t *timer)
#endif

{
    _mutex->lock();
    if (_rtc_isenabled != NULL) {
        if (!(_rtc_isenabled())) {
            set_time(0);
        }
    }
    
    time_t t = (time_t)-1;
    if (_rtc_read != NULL) {
        t = _rtc_read();
    }

    if (timer != NULL) {
        *timer = t;
    }
    _mutex->unlock();
    return t;
}
Beispiel #10
0
void mbed_mem_trace_unlock()
{
    trace_lock_count--;
    mem_trace_mutex->unlock();
}
Beispiel #11
0
static void _rtc_lpticker_init(void)
{
    _rtc_lp_timer->start();
    _rtc_enabled = true;
}
Beispiel #12
0
static time_t _rtc_lpticker_read(void)
{
    return (uint64_t)_rtc_lp_timer->read() + _rtc_lp_base;
}
Beispiel #13
0
static uint32_t read_current_time(void)
{
    return timer->read_us();
}
// This is called from inside platform_enter_critical - IRQs can't happen
void platform_timer_start(uint16_t slots)
{
    timer->reset();
    due = slots * UINT32_C(50);
    timeout->attach_us(timer_callback, due);
}
Beispiel #15
0
void FATFileSystem::unlock()
{
    _ffs_mutex->unlock();
}
Beispiel #16
0
void FATFileSystem::lock()
{
    _ffs_mutex->lock();
}
Beispiel #17
0
void mbed_mem_trace_lock()
{
    mem_trace_mutex->lock();
    trace_lock_count++;
}
Beispiel #18
0
// Mutex is protecting rand() per srand for buffer writing and verification.
// Mutex is also protecting printouts for clear logs.
// Mutex is NOT protecting Block Device actions: erase/program/read - which is the purpose of the multithreaded test!
void basic_erase_program_read_test(BlockDevice *block_device, bd_size_t block_size, uint8_t *write_block,
                                   uint8_t *read_block, unsigned addrwidth, int thread_num)
{
    int err = 0;
    _mutex->lock();

    // Make sure block address per each test is unique
    static unsigned block_seed = 1;
    srand(block_seed++);

    // Find a random block
    int threaded_rand_number = (rand() * TEST_NUM_OF_THREADS) + thread_num;
    bd_addr_t block = (threaded_rand_number * block_size) % block_device->size();

    // Flashiap boards with inconsistent sector size will not align with random start addresses
    if (bd_arr[test_iteration] == flashiap) {
        block = 0;
    }

    // Use next random number as temporary seed to keep
    // the address progressing in the pseudorandom sequence
    unsigned seed = rand();

    // Fill with random sequence
    srand(seed);
    for (bd_size_t i_ind = 0; i_ind < block_size; i_ind++) {
        write_block[i_ind] = 0xff & rand();
    }
    // Write, sync, and read the block
    utest_printf("test  %0*llx:%llu...\n", addrwidth, block, block_size);

    // Thread test for flashiap write to the same sector, so all write/read/erase actions should be locked
    if (bd_arr[test_iteration] != flashiap) {
        _mutex->unlock();
    }

    err = block_device->erase(block, block_size);
    TEST_ASSERT_EQUAL(0, err);

    err = block_device->program(write_block, block, block_size);
    TEST_ASSERT_EQUAL(0, err);

    err = block_device->read(read_block, block, block_size);
    TEST_ASSERT_EQUAL(0, err);

    if (bd_arr[test_iteration] != flashiap) {
        _mutex->lock();
    }

    // Check that the data was unmodified
    srand(seed);
    int val_rand;
    for (bd_size_t i_ind = 0; i_ind < block_size; i_ind++) {
        val_rand = rand();
        if ((0xff & val_rand) != read_block[i_ind]) {
            utest_printf("\n Assert Failed Buf Read - block:size: %llx:%llu \n", block, block_size);
            utest_printf("\n pos: %llu, exp: %02x, act: %02x, wrt: %02x \n", i_ind, (0xff & val_rand),
                         read_block[i_ind],
                         write_block[i_ind]);
        }
        TEST_ASSERT_EQUAL(0xff & val_rand, read_block[i_ind]);
    }
    _mutex->unlock();
}
// Actually cancels a timer, not the opposite of enable
void platform_timer_disable(void)
{
    timeout->detach();
}