5.2.1 - Updated I2C files

Dependents:   mbed-TFT-example-NCS36510 mbed-Accelerometer-example-NCS36510 mbed-Accelerometer-example-NCS36510

Committer:
jacobjohnson
Date:
Mon Feb 27 17:45:05 2017 +0000
Revision:
1:f30bdcd2b33b
Parent:
0:098463de4c5d
changed the inputscale from 1 to 7 in analogin_api.c.  This will need to be changed later, and accessed from the main level, but for now this allows the  adc to read a value from 0 to 3.7V, instead of just up to 1V.;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
group-onsemi 0:098463de4c5d 1 /*
group-onsemi 0:098463de4c5d 2 * Copyright (c) 2016, ARM Limited, All Rights Reserved
group-onsemi 0:098463de4c5d 3 * SPDX-License-Identifier: Apache-2.0
group-onsemi 0:098463de4c5d 4 *
group-onsemi 0:098463de4c5d 5 * Licensed under the Apache License, Version 2.0 (the "License"); you may
group-onsemi 0:098463de4c5d 6 * not use this file except in compliance with the License.
group-onsemi 0:098463de4c5d 7 * You may obtain a copy of the License at
group-onsemi 0:098463de4c5d 8 *
group-onsemi 0:098463de4c5d 9 * http://www.apache.org/licenses/LICENSE-2.0
group-onsemi 0:098463de4c5d 10 *
group-onsemi 0:098463de4c5d 11 * Unless required by applicable law or agreed to in writing, software
group-onsemi 0:098463de4c5d 12 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
group-onsemi 0:098463de4c5d 13 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
group-onsemi 0:098463de4c5d 14 * See the License for the specific language governing permissions and
group-onsemi 0:098463de4c5d 15 * limitations under the License.
group-onsemi 0:098463de4c5d 16 */
group-onsemi 0:098463de4c5d 17 #include "uvisor-lib/uvisor-lib.h"
group-onsemi 0:098463de4c5d 18 #include "api/inc/pool_queue_exports.h"
group-onsemi 0:098463de4c5d 19 #include "api/inc/rpc_exports.h"
group-onsemi 0:098463de4c5d 20 #include "api/inc/uvisor_semaphore.h"
group-onsemi 0:098463de4c5d 21 #include "mbed_interface.h"
group-onsemi 0:098463de4c5d 22 #include "cmsis_os.h"
group-onsemi 0:098463de4c5d 23 #include <stdint.h>
group-onsemi 0:098463de4c5d 24 #include <string.h>
group-onsemi 0:098463de4c5d 25
group-onsemi 0:098463de4c5d 26 /* Register the OS with uVisor */
group-onsemi 0:098463de4c5d 27 extern void SVC_Handler(void);
group-onsemi 0:098463de4c5d 28 extern void PendSV_Handler(void);
group-onsemi 0:098463de4c5d 29 extern void SysTick_Handler(void);
group-onsemi 0:098463de4c5d 30 extern uint32_t rt_suspend(void);
group-onsemi 0:098463de4c5d 31
group-onsemi 0:098463de4c5d 32 UVISOR_SET_PRIV_SYS_HOOKS(SVC_Handler, PendSV_Handler, SysTick_Handler, rt_suspend, __uvisor_semaphore_post);
group-onsemi 0:098463de4c5d 33
group-onsemi 0:098463de4c5d 34 extern RtxBoxIndex * const __uvisor_ps;
group-onsemi 0:098463de4c5d 35
group-onsemi 0:098463de4c5d 36 void __uvisor_initialize_rpc_queues(void)
group-onsemi 0:098463de4c5d 37 {
group-onsemi 0:098463de4c5d 38 UvisorBoxIndex * const index = &__uvisor_ps->index;
group-onsemi 0:098463de4c5d 39
group-onsemi 0:098463de4c5d 40 uvisor_pool_slot_t i;
group-onsemi 0:098463de4c5d 41
group-onsemi 0:098463de4c5d 42 uvisor_rpc_outgoing_message_queue_t * rpc_outgoing_msg_queue = index->rpc_outgoing_message_queue;
group-onsemi 0:098463de4c5d 43 uvisor_rpc_incoming_message_queue_t * rpc_incoming_msg_queue = index->rpc_incoming_message_queue;
group-onsemi 0:098463de4c5d 44 uvisor_rpc_fn_group_queue_t * rpc_fn_group_queue = index->rpc_fn_group_queue;
group-onsemi 0:098463de4c5d 45
group-onsemi 0:098463de4c5d 46 /* Initialize the outgoing RPC message queue. */
group-onsemi 0:098463de4c5d 47 if (uvisor_pool_queue_init(&rpc_outgoing_msg_queue->queue,
group-onsemi 0:098463de4c5d 48 &rpc_outgoing_msg_queue->pool,
group-onsemi 0:098463de4c5d 49 rpc_outgoing_msg_queue->messages,
group-onsemi 0:098463de4c5d 50 sizeof(*rpc_outgoing_msg_queue->messages),
group-onsemi 0:098463de4c5d 51 UVISOR_RPC_OUTGOING_MESSAGE_SLOTS,
group-onsemi 0:098463de4c5d 52 UVISOR_POOL_QUEUE_BLOCKING)) {
group-onsemi 0:098463de4c5d 53 uvisor_error(USER_NOT_ALLOWED);
group-onsemi 0:098463de4c5d 54 }
group-onsemi 0:098463de4c5d 55
group-onsemi 0:098463de4c5d 56 /* Initialize all the result semaphores. */
group-onsemi 0:098463de4c5d 57 for (i = 0; i < UVISOR_RPC_OUTGOING_MESSAGE_SLOTS; i++) {
group-onsemi 0:098463de4c5d 58 UvisorSemaphore * semaphore = &rpc_outgoing_msg_queue->messages[i].semaphore;
group-onsemi 0:098463de4c5d 59 if (__uvisor_semaphore_init(semaphore, 1)) {
group-onsemi 0:098463de4c5d 60 uvisor_error(USER_NOT_ALLOWED);
group-onsemi 0:098463de4c5d 61 }
group-onsemi 0:098463de4c5d 62
group-onsemi 0:098463de4c5d 63 /* Semaphores are created with their value initialized to count. We
group-onsemi 0:098463de4c5d 64 * want the semaphore to start at zero. Decrement the semaphore, so it
group-onsemi 0:098463de4c5d 65 * starts with a value of zero. This will allow the first pend to
group-onsemi 0:098463de4c5d 66 * block. */
group-onsemi 0:098463de4c5d 67 if (__uvisor_semaphore_pend(semaphore, 0)) {
group-onsemi 0:098463de4c5d 68 uvisor_error(USER_NOT_ALLOWED);
group-onsemi 0:098463de4c5d 69 }
group-onsemi 0:098463de4c5d 70 }
group-onsemi 0:098463de4c5d 71
group-onsemi 0:098463de4c5d 72 /* Initialize the incoming RPC message queues. */
group-onsemi 0:098463de4c5d 73 if (uvisor_pool_queue_init(&rpc_incoming_msg_queue->todo_queue,
group-onsemi 0:098463de4c5d 74 &rpc_incoming_msg_queue->pool,
group-onsemi 0:098463de4c5d 75 rpc_incoming_msg_queue->messages,
group-onsemi 0:098463de4c5d 76 sizeof(*rpc_incoming_msg_queue->messages),
group-onsemi 0:098463de4c5d 77 UVISOR_RPC_INCOMING_MESSAGE_SLOTS,
group-onsemi 0:098463de4c5d 78 UVISOR_POOL_QUEUE_NON_BLOCKING)) {
group-onsemi 0:098463de4c5d 79 uvisor_error(USER_NOT_ALLOWED);
group-onsemi 0:098463de4c5d 80 }
group-onsemi 0:098463de4c5d 81 /* This is a double init of the pool. We need a function that just inits
group-onsemi 0:098463de4c5d 82 * the queue, not the pool, and init everybody separately. */
group-onsemi 0:098463de4c5d 83 if (uvisor_pool_queue_init(&rpc_incoming_msg_queue->done_queue,
group-onsemi 0:098463de4c5d 84 &rpc_incoming_msg_queue->pool,
group-onsemi 0:098463de4c5d 85 rpc_incoming_msg_queue->messages,
group-onsemi 0:098463de4c5d 86 sizeof(*rpc_incoming_msg_queue->messages),
group-onsemi 0:098463de4c5d 87 UVISOR_RPC_INCOMING_MESSAGE_SLOTS,
group-onsemi 0:098463de4c5d 88 UVISOR_POOL_QUEUE_NON_BLOCKING)) {
group-onsemi 0:098463de4c5d 89 uvisor_error(USER_NOT_ALLOWED);
group-onsemi 0:098463de4c5d 90 }
group-onsemi 0:098463de4c5d 91
group-onsemi 0:098463de4c5d 92 /* Initialize the function group pool. */
group-onsemi 0:098463de4c5d 93 if (uvisor_pool_queue_init(&rpc_fn_group_queue->queue,
group-onsemi 0:098463de4c5d 94 &rpc_fn_group_queue->pool,
group-onsemi 0:098463de4c5d 95 rpc_fn_group_queue->fn_groups,
group-onsemi 0:098463de4c5d 96 sizeof(*rpc_fn_group_queue->fn_groups),
group-onsemi 0:098463de4c5d 97 UVISOR_RPC_FN_GROUP_SLOTS,
group-onsemi 0:098463de4c5d 98 UVISOR_POOL_QUEUE_BLOCKING)) {
group-onsemi 0:098463de4c5d 99 uvisor_error(USER_NOT_ALLOWED);
group-onsemi 0:098463de4c5d 100 }
group-onsemi 0:098463de4c5d 101
group-onsemi 0:098463de4c5d 102 /* Initialize all the function group semaphores. */
group-onsemi 0:098463de4c5d 103 for (i = 0; i < UVISOR_RPC_FN_GROUP_SLOTS; i++) {
group-onsemi 0:098463de4c5d 104 UvisorSemaphore * semaphore = &rpc_fn_group_queue->fn_groups[i].semaphore;
group-onsemi 0:098463de4c5d 105 if (__uvisor_semaphore_init(semaphore, 1)) {
group-onsemi 0:098463de4c5d 106 uvisor_error(USER_NOT_ALLOWED);
group-onsemi 0:098463de4c5d 107 }
group-onsemi 0:098463de4c5d 108
group-onsemi 0:098463de4c5d 109 /* Semaphores are created with their value initialized to count. We
group-onsemi 0:098463de4c5d 110 * want the semaphore to start at zero. Decrement the semaphore, so it
group-onsemi 0:098463de4c5d 111 * starts with a value of zero. This will allow the first pend to
group-onsemi 0:098463de4c5d 112 * block. */
group-onsemi 0:098463de4c5d 113 if (__uvisor_semaphore_pend(semaphore, 0)) {
group-onsemi 0:098463de4c5d 114 uvisor_error(USER_NOT_ALLOWED);
group-onsemi 0:098463de4c5d 115 }
group-onsemi 0:098463de4c5d 116 }
group-onsemi 0:098463de4c5d 117 }
group-onsemi 0:098463de4c5d 118
group-onsemi 0:098463de4c5d 119 /* This function is called by uVisor in unprivileged mode. On this OS, we
group-onsemi 0:098463de4c5d 120 * create box main threads for the box. */
group-onsemi 0:098463de4c5d 121 void __uvisor_lib_box_init(void * lib_config)
group-onsemi 0:098463de4c5d 122 {
group-onsemi 0:098463de4c5d 123 osThreadId thread_id;
group-onsemi 0:098463de4c5d 124 osThreadDef_t * flash_thread_def = lib_config;
group-onsemi 0:098463de4c5d 125 osThreadDef_t thread_def;
group-onsemi 0:098463de4c5d 126
group-onsemi 0:098463de4c5d 127 __uvisor_initialize_rpc_queues();
group-onsemi 0:098463de4c5d 128
group-onsemi 0:098463de4c5d 129 /* Copy thread definition from flash to RAM. The thread definition is most
group-onsemi 0:098463de4c5d 130 * likely in flash, so we need to copy it to box-local RAM before we can
group-onsemi 0:098463de4c5d 131 * modify it. */
group-onsemi 0:098463de4c5d 132 memcpy(&thread_def, flash_thread_def, sizeof(thread_def));
group-onsemi 0:098463de4c5d 133
group-onsemi 0:098463de4c5d 134 /* Note that the box main thread stack is separate from the box stack. This
group-onsemi 0:098463de4c5d 135 * is because the thread must be created to use a different stack than the
group-onsemi 0:098463de4c5d 136 * stack osCreateThread() is called from, as context information is saved
group-onsemi 0:098463de4c5d 137 * to the thread stack by the call to osCreateThread(). */
group-onsemi 0:098463de4c5d 138 /* Allocate memory for the main thread from the process heap (which is
group-onsemi 0:098463de4c5d 139 * private to the process). This memory is never freed, even if the box's
group-onsemi 0:098463de4c5d 140 * main thread exits. */
group-onsemi 0:098463de4c5d 141 thread_def.stack_pointer = malloc_p(thread_def.stacksize);
group-onsemi 0:098463de4c5d 142
group-onsemi 0:098463de4c5d 143 if (thread_def.stack_pointer == NULL) {
group-onsemi 0:098463de4c5d 144 /* No process heap memory available */
group-onsemi 0:098463de4c5d 145 mbed_die();
group-onsemi 0:098463de4c5d 146 }
group-onsemi 0:098463de4c5d 147
group-onsemi 0:098463de4c5d 148 thread_id = osThreadCreate(&thread_def, NULL);
group-onsemi 0:098463de4c5d 149
group-onsemi 0:098463de4c5d 150 if (thread_id == NULL) {
group-onsemi 0:098463de4c5d 151 /* Failed to create thread */
group-onsemi 0:098463de4c5d 152 mbed_die();
group-onsemi 0:098463de4c5d 153 }
group-onsemi 0:098463de4c5d 154 }