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();
}
Beispiel #4
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 #5
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 #6
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 #7
0
void FATFileSystem::unlock()
{
    _ffs_mutex->unlock();
}
Beispiel #8
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();
}
Beispiel #9
0
void mbed_mem_trace_unlock()
{
    trace_lock_count--;
    mem_trace_mutex->unlock();
}