Ejemplo n.º 1
0
void spm_ipc_mailbox_init(void)
{
    // Initialization by data from shared memory
    // -----------------------------------------

    // This table is holding addresses of the platform's shared memory.
    addr_table_t *shared_addr_table_ptr = (addr_table_t *)PSA_SHARED_RAM_START;
    MBED_ASSERT(shared_addr_table_ptr->magic == ADDR_TABLE_MAGIC);

    ipc_base_queue_t *tx_queue_mem_ptr = (ipc_base_queue_t *)(shared_addr_table_ptr->tx_queue_ptr);
    MBED_ASSERT(tx_queue_mem_ptr->magic == IPC_QUEUE_BASE_MAGIC);

    ipc_base_queue_t *rx_queue_mem_ptr = (ipc_base_queue_t *)(shared_addr_table_ptr->rx_queue_ptr);
    MBED_ASSERT(rx_queue_mem_ptr->magic == IPC_QUEUE_BASE_MAGIC);

    osMutexId_t queue_mutex = osMutexNew(&queue_mutex_attr);
    MBED_ASSERT(queue_mutex != NULL);    // TODO: Panic instead

    osSemaphoreId_t full_queue_sem = osSemaphoreNew(IPC_QUEUE_SEM_MAX_COUNT, IPC_QUEUE_SEM_INITIAL_COUNT, &full_sem_attr);
    MBED_ASSERT(full_queue_sem != NULL);    // TODO: Panic instead

    osSemaphoreId_t queue_read_sem = osSemaphoreNew(IPC_QUEUE_SEM_MAX_COUNT, IPC_QUEUE_SEM_INITIAL_COUNT, &read_sem_attr);
    MBED_ASSERT(queue_read_sem != NULL);    // TODO: Panic instead

    ipc_producer_queue_init(prod_queue, tx_queue_mem_ptr, queue_mutex, full_queue_sem);
    ipc_consumer_queue_init(cons_queue, rx_queue_mem_ptr, queue_read_sem);
}
Ejemplo n.º 2
0
osMutexId osMutexCreate (const osMutexDef_t *mutex_def) {

  if (mutex_def == NULL) {
    return NULL;
  }
  return osMutexNew(mutex_def);
}
Ejemplo n.º 3
0
void ns_event_loop_thread_create(void)
{
    event_mutex_id = osMutexNew(&event_mutex_attr);
    MBED_ASSERT(event_mutex_id != NULL);

    event_thread_id = osThreadNew(event_loop_thread, NULL, &event_thread_attr);
    MBED_ASSERT(event_thread_id != NULL);
}
Ejemplo n.º 4
0
void mbed_toolchain_init()
{
    malloc_mutex_attr.name = "malloc_mutex";
    malloc_mutex_attr.attr_bits = osMutexRecursive | osMutexPrioInherit | osMutexRobust;
    malloc_mutex_attr.cb_size = sizeof(malloc_mutex_obj);
    malloc_mutex_attr.cb_mem = &malloc_mutex_obj;
    malloc_mutex_id = osMutexNew(&malloc_mutex_attr);

    env_mutex_attr.name = "env_mutex";
    env_mutex_attr.attr_bits = osMutexRecursive | osMutexPrioInherit | osMutexRobust;
    env_mutex_attr.cb_size = sizeof(env_mutex_obj);
    env_mutex_attr.cb_mem = &env_mutex_obj;
    env_mutex_id = osMutexNew(&env_mutex_attr);

    /* Run the C++ global object constructors */
    __libc_init_array();
}
Ejemplo n.º 5
0
int _mutex_initialize(mutex *m) {
  *m = osMutexNew(NULL);
  if (*m == NULL) {
    osRtxErrorNotify(osRtxErrorClibMutex, m);
    return 0;
  }
  return 1;
}
Ejemplo n.º 6
0
/* Initialize mutex */
__USED int _mutex_initialize(mutex *m)
{
    osMutexAttr_t attr;
    memset(&attr, 0, sizeof(attr));
    attr.name = "ARM toolchain mutex";
    attr.attr_bits = osMutexRecursive | osMutexPrioInherit | osMutexRobust;

    mutex *slot = NULL;
    core_util_critical_section_enter();
    for (int i = 0; i < OS_MUTEX_STATIC_NUM; i++) {
        if (_static_mutexes[i] == NULL) {
            _static_mutexes[i] = (mutex) - 1; // dummy value to reserve slot
            slot = &_static_mutexes[i];
            //Use the static attrs
            attr.cb_size = sizeof(mbed_rtos_storage_mutex_t);
            attr.cb_mem = &_static_mutexes_mem[i];
            break;
        }
    }
    core_util_critical_section_exit();

    if (slot != NULL) {
        *m = osMutexNew(&attr);
        *slot = *m;
        if (*m != NULL) {
            return 1;
        }
    }

    /* Mutex pool exhausted, try using HEAP */
    attr.cb_size = sizeof(mbed_rtos_storage_mutex_t);
    attr.cb_mem = (void *)malloc(attr.cb_size);
    if (attr.cb_mem == NULL) {
        osRtxErrorNotify(osRtxErrorClibSpace, m);
        return 0;
    }

    *m = osMutexNew(&attr);
    if (*m == NULL) {
        osRtxErrorNotify(osRtxErrorClibMutex, m);
        return 0;
    }

    return 1;
}
Ejemplo n.º 7
0
// This is used to initialize the lock used by event loop even
// if it is not ran in a separate thread.
void ns_event_loop_init(void)
{
    event_mutex_id = osMutexNew(&event_mutex_attr);
    MBED_ASSERT(event_mutex_id != NULL);

    // If a separate event loop thread is not used, the signaling
    // happens via event flags instead of thread flags. This allows one to
    // perform the initialization from any thread and removes need to know the id
    // of event loop dispatch thread.
#if MBED_CONF_NANOSTACK_HAL_EVENT_LOOP_DISPATCH_FROM_APPLICATION
    event_flag_id  = osEventFlagsNew(&event_flags_attr);
    MBED_ASSERT(event_flag_id != NULL);
#endif
}
Ejemplo n.º 8
0
void __iar_file_Mtxinit(__iar_Rmtx *mutex) /* Initialize a file lock */
{
    osMutexAttr_t attr;
    uint32_t index;
    for (index = 0; index < _FOPEN_MAX; index++) {
        if (0 == std_mutex_id_file[index]) {
            attr.name = "file_mutex";
            attr.cb_mem = &std_mutex_file[index];
            attr.cb_size = sizeof(std_mutex_file[index]);
            attr.attr_bits = osMutexRecursive | osMutexPrioInherit | osMutexRobust;
            std_mutex_id_file[index] = osMutexNew(&attr);
            *mutex = (__iar_Rmtx *)&std_mutex_id_file[index];
            return;
        }
    }
    /* The variable _FOPEN_MAX needs to be increased */
    error("Not enough mutexes\n");
}
Ejemplo n.º 9
0
void __iar_system_Mtxinit(__iar_Rmtx *mutex) /* Initialize a system lock */
{
    osMutexAttr_t attr;
    uint32_t index;
    for (index = 0; index < _MAX_LOCK; index++) {
        if (0 == std_mutex_id_sys[index]) {
            attr.name = "system_mutex";
            attr.cb_mem = &std_mutex_sys[index];
            attr.cb_size = sizeof(std_mutex_sys[index]);
            attr.attr_bits = osMutexRecursive | osMutexPrioInherit | osMutexRobust;
            std_mutex_id_sys[index] = osMutexNew(&attr);
            *mutex = (__iar_Rmtx *)&std_mutex_id_sys[index];
            return;
        }
    }

    /* This should never happen */
    error("Not enough mutexes\n");
}
Ejemplo n.º 10
0
void test_partition_init(spm_partition_t *partition)
{
    if (NULL == partition) {
        SPM_PANIC("partition is NULL!\n");
    }

    partition->mutex = osMutexNew(&test_partition_mutex_attr);
    if (NULL == partition->mutex) {
        SPM_PANIC("Failed to create mutex for secure partition test_partition!\n");
    }

    for (uint32_t i = 0; i < TEST_PARTITION_ROT_SRV_COUNT; ++i) {
        test_partition_rot_services[i].partition = partition;
    }
    partition->rot_services = test_partition_rot_services;

    partition->thread_id = osThreadNew(test_partition_main, NULL, &test_partition_thread_attr);
    if (NULL == partition->thread_id) {
        SPM_PANIC("Failed to create start main thread of partition test_partition!\n");
    }
}
Ejemplo n.º 11
0
void platform_init(spm_partition_t *partition)
{
    if (NULL == partition) {
        SPM_PANIC("partition is NULL!\n");
    }

    partition->mutex = osMutexNew(&platform_mutex_attr);
    if (NULL == partition->mutex) {
        SPM_PANIC("Failed to create mutex for secure partition platform!\n");
    }

    for (uint32_t i = 0; i < PLATFORM_ROT_SRV_COUNT; ++i) {
        platform_rot_services[i].partition = partition;
    }
    partition->rot_services = platform_rot_services;

    partition->thread_id = osThreadNew(platform_partition_entry, NULL, &platform_thread_attr);
    if (NULL == partition->thread_id) {
        SPM_PANIC("Failed to create start main thread of partition platform!\n");
    }
}
Ejemplo n.º 12
0
void server_tests_part2_init(spm_partition_t *partition)
{
    if (NULL == partition) {
        SPM_PANIC("partition is NULL!\n");
    }

    partition->mutex = osMutexNew(&server_tests_part2_mutex_attr);
    if (NULL == partition->mutex) {
        SPM_PANIC("Failed to create mutex for secure partition server_tests_part2!\n");
    }

    for (uint32_t i = 0; i < SERVER_TESTS_PART2_ROT_SRV_COUNT; ++i) {
        server_tests_part2_rot_services[i].partition = partition;
    }
    partition->rot_services = server_tests_part2_rot_services;

    partition->thread_id = osThreadNew(server_part2_main, NULL, &server_tests_part2_thread_attr);
    if (NULL == partition->thread_id) {
        SPM_PANIC("Failed to create start main thread of partition server_tests_part2!\n");
    }
}
Ejemplo n.º 13
0
void crypto_acl_test_init(spm_partition_t *partition)
{
    if (NULL == partition) {
        SPM_PANIC("partition is NULL!\n");
    }

    partition->mutex = osMutexNew(&crypto_acl_test_mutex_attr);
    if (NULL == partition->mutex) {
        SPM_PANIC("Failed to create mutex for secure partition crypto_acl_test!\n");
    }

    for (uint32_t i = 0; i < CRYPTO_ACL_TEST_ROT_SRV_COUNT; ++i) {
        crypto_acl_test_rot_services[i].partition = partition;
    }
    partition->rot_services = crypto_acl_test_rot_services;

    partition->thread_id = osThreadNew(test_partition_main, NULL, &crypto_acl_test_thread_attr);
    if (NULL == partition->thread_id) {
        SPM_PANIC("Failed to create start main thread of partition crypto_acl_test!\n");
    }
}