Repostiory containing DAPLink source code with Reset Pin workaround for HANI_IOT board.

Upstream: https://github.com/ARMmbed/DAPLink

Committer:
Pawel Zarembski
Date:
Tue Apr 07 12:55:42 2020 +0200
Revision:
0:01f31e923fe2
hani: DAPLink with reset workaround

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Pawel Zarembski 0:01f31e923fe2 1 /**
Pawel Zarembski 0:01f31e923fe2 2 * @file cmsis_os2_port.c
Pawel Zarembski 0:01f31e923fe2 3 * @brief
Pawel Zarembski 0:01f31e923fe2 4 *
Pawel Zarembski 0:01f31e923fe2 5 * DAPLink Interface Firmware
Pawel Zarembski 0:01f31e923fe2 6 * Copyright (c) 2019, ARM Limited, All Rights Reserved
Pawel Zarembski 0:01f31e923fe2 7 * SPDX-License-Identifier: Apache-2.0
Pawel Zarembski 0:01f31e923fe2 8 *
Pawel Zarembski 0:01f31e923fe2 9 * Licensed under the Apache License, Version 2.0 (the "License"); you may
Pawel Zarembski 0:01f31e923fe2 10 * not use this file except in compliance with the License.
Pawel Zarembski 0:01f31e923fe2 11 * You may obtain a copy of the License at
Pawel Zarembski 0:01f31e923fe2 12 *
Pawel Zarembski 0:01f31e923fe2 13 * http://www.apache.org/licenses/LICENSE-2.0
Pawel Zarembski 0:01f31e923fe2 14 *
Pawel Zarembski 0:01f31e923fe2 15 * Unless required by applicable law or agreed to in writing, software
Pawel Zarembski 0:01f31e923fe2 16 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
Pawel Zarembski 0:01f31e923fe2 17 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Pawel Zarembski 0:01f31e923fe2 18 * See the License for the specific language governing permissions and
Pawel Zarembski 0:01f31e923fe2 19 * limitations under the License.
Pawel Zarembski 0:01f31e923fe2 20 */
Pawel Zarembski 0:01f31e923fe2 21
Pawel Zarembski 0:01f31e923fe2 22 #include "cmsis_os2.h"
Pawel Zarembski 0:01f31e923fe2 23 #include "RTL.h"
Pawel Zarembski 0:01f31e923fe2 24 #include "cortex_m.h"
Pawel Zarembski 0:01f31e923fe2 25
Pawel Zarembski 0:01f31e923fe2 26 #define MAIN_TASK_PRIORITY (10)
Pawel Zarembski 0:01f31e923fe2 27 #define MAIN_TASK_STACK (800)
Pawel Zarembski 0:01f31e923fe2 28 static uint64_t stk_main_task [MAIN_TASK_STACK / sizeof(uint64_t)];
Pawel Zarembski 0:01f31e923fe2 29
Pawel Zarembski 0:01f31e923fe2 30 #define TIMER_TASK_30_PRIORITY (11)
Pawel Zarembski 0:01f31e923fe2 31 #define TIMER_TASK_STACK (136)
Pawel Zarembski 0:01f31e923fe2 32 static uint64_t stk_timer_task[TIMER_TASK_STACK / sizeof(uint64_t)];
Pawel Zarembski 0:01f31e923fe2 33
Pawel Zarembski 0:01f31e923fe2 34 static uint32_t taskCount = 0;
Pawel Zarembski 0:01f31e923fe2 35 static osTimerFunc_t onlyTimerFunction = NULL;
Pawel Zarembski 0:01f31e923fe2 36 static uint32_t timerTick = 0;
Pawel Zarembski 0:01f31e923fe2 37
Pawel Zarembski 0:01f31e923fe2 38 static OS_MUT onlyMutex;
Pawel Zarembski 0:01f31e923fe2 39
Pawel Zarembski 0:01f31e923fe2 40 osStatus_t osKernelInitialize(void)
Pawel Zarembski 0:01f31e923fe2 41 {
Pawel Zarembski 0:01f31e923fe2 42 taskCount = 0;
Pawel Zarembski 0:01f31e923fe2 43 return osOK;
Pawel Zarembski 0:01f31e923fe2 44 }
Pawel Zarembski 0:01f31e923fe2 45
Pawel Zarembski 0:01f31e923fe2 46 osThreadId_t osThreadNew(osThreadFunc_t func, void *argument, const osThreadAttr_t *attr)
Pawel Zarembski 0:01f31e923fe2 47 {
Pawel Zarembski 0:01f31e923fe2 48 OS_TID tid = 0;
Pawel Zarembski 0:01f31e923fe2 49 //first task will init the rtx
Pawel Zarembski 0:01f31e923fe2 50 if (taskCount == 0) {
Pawel Zarembski 0:01f31e923fe2 51 os_sys_init_user((void (*)(void))func, MAIN_TASK_PRIORITY, stk_main_task, MAIN_TASK_STACK);
Pawel Zarembski 0:01f31e923fe2 52 }
Pawel Zarembski 0:01f31e923fe2 53 else {
Pawel Zarembski 0:01f31e923fe2 54 tid = os_tsk_create((void (*)(void))func, MAIN_TASK_PRIORITY+1);
Pawel Zarembski 0:01f31e923fe2 55 }
Pawel Zarembski 0:01f31e923fe2 56 taskCount++;
Pawel Zarembski 0:01f31e923fe2 57 return (osThreadId_t) tid;
Pawel Zarembski 0:01f31e923fe2 58 }
Pawel Zarembski 0:01f31e923fe2 59
Pawel Zarembski 0:01f31e923fe2 60 uint32_t osThreadFlagsSet(osThreadId_t thread_id, uint32_t flags)
Pawel Zarembski 0:01f31e923fe2 61 {
Pawel Zarembski 0:01f31e923fe2 62 if (cortex_in_isr()){
Pawel Zarembski 0:01f31e923fe2 63 isr_evt_set(flags, (OS_TID)thread_id);
Pawel Zarembski 0:01f31e923fe2 64 }else {
Pawel Zarembski 0:01f31e923fe2 65 os_evt_set(flags, (OS_TID)thread_id);
Pawel Zarembski 0:01f31e923fe2 66 }
Pawel Zarembski 0:01f31e923fe2 67 return flags;
Pawel Zarembski 0:01f31e923fe2 68 }
Pawel Zarembski 0:01f31e923fe2 69
Pawel Zarembski 0:01f31e923fe2 70 osStatus_t osKernelStart(void)
Pawel Zarembski 0:01f31e923fe2 71 {
Pawel Zarembski 0:01f31e923fe2 72 //first thread already started the kernel
Pawel Zarembski 0:01f31e923fe2 73 return osOK;
Pawel Zarembski 0:01f31e923fe2 74 }
Pawel Zarembski 0:01f31e923fe2 75
Pawel Zarembski 0:01f31e923fe2 76 // Timer task
Pawel Zarembski 0:01f31e923fe2 77 static void rt_timer_task(void)
Pawel Zarembski 0:01f31e923fe2 78 {
Pawel Zarembski 0:01f31e923fe2 79 os_itv_set(timerTick);
Pawel Zarembski 0:01f31e923fe2 80 while (1) {
Pawel Zarembski 0:01f31e923fe2 81 os_itv_wait();
Pawel Zarembski 0:01f31e923fe2 82 if (onlyTimerFunction) {
Pawel Zarembski 0:01f31e923fe2 83 onlyTimerFunction(NULL);
Pawel Zarembski 0:01f31e923fe2 84 }
Pawel Zarembski 0:01f31e923fe2 85 }
Pawel Zarembski 0:01f31e923fe2 86 }
Pawel Zarembski 0:01f31e923fe2 87
Pawel Zarembski 0:01f31e923fe2 88 osTimerId_t osTimerNew(osTimerFunc_t func, osTimerType_t type, void *argument, const osTimerAttr_t *attr)
Pawel Zarembski 0:01f31e923fe2 89 {
Pawel Zarembski 0:01f31e923fe2 90 OS_TID tid = 0;
Pawel Zarembski 0:01f31e923fe2 91 onlyTimerFunction = func;
Pawel Zarembski 0:01f31e923fe2 92 return (osTimerId_t)tid;
Pawel Zarembski 0:01f31e923fe2 93 }
Pawel Zarembski 0:01f31e923fe2 94
Pawel Zarembski 0:01f31e923fe2 95 osStatus_t osTimerStart(osTimerId_t timer_id, uint32_t ticks)
Pawel Zarembski 0:01f31e923fe2 96 {
Pawel Zarembski 0:01f31e923fe2 97 timerTick = ticks;
Pawel Zarembski 0:01f31e923fe2 98 OS_TID tid = os_tsk_create_user(rt_timer_task, TIMER_TASK_30_PRIORITY, (void *)stk_timer_task, TIMER_TASK_STACK);
Pawel Zarembski 0:01f31e923fe2 99 return osOK;
Pawel Zarembski 0:01f31e923fe2 100 }
Pawel Zarembski 0:01f31e923fe2 101
Pawel Zarembski 0:01f31e923fe2 102 uint32_t osThreadFlagsWait(uint32_t flags, uint32_t options, uint32_t timeout)
Pawel Zarembski 0:01f31e923fe2 103 {
Pawel Zarembski 0:01f31e923fe2 104 os_evt_wait_or(flags, timeout);
Pawel Zarembski 0:01f31e923fe2 105 return os_evt_get();
Pawel Zarembski 0:01f31e923fe2 106 }
Pawel Zarembski 0:01f31e923fe2 107
Pawel Zarembski 0:01f31e923fe2 108 osMutexId_t osMutexNew(const osMutexAttr_t *attr)
Pawel Zarembski 0:01f31e923fe2 109 {
Pawel Zarembski 0:01f31e923fe2 110 os_mut_init(onlyMutex);
Pawel Zarembski 0:01f31e923fe2 111 return (osMutexId_t)onlyMutex;
Pawel Zarembski 0:01f31e923fe2 112 }
Pawel Zarembski 0:01f31e923fe2 113
Pawel Zarembski 0:01f31e923fe2 114 osStatus_t osMutexAcquire(osMutexId_t mutex_id, uint32_t timeout)
Pawel Zarembski 0:01f31e923fe2 115 {
Pawel Zarembski 0:01f31e923fe2 116 os_mut_wait((OS_ID)mutex_id, timeout);
Pawel Zarembski 0:01f31e923fe2 117 return osOK;
Pawel Zarembski 0:01f31e923fe2 118 }
Pawel Zarembski 0:01f31e923fe2 119
Pawel Zarembski 0:01f31e923fe2 120 osStatus_t osMutexRelease(osMutexId_t mutex_id)
Pawel Zarembski 0:01f31e923fe2 121 {
Pawel Zarembski 0:01f31e923fe2 122 os_mut_release((OS_ID)mutex_id);
Pawel Zarembski 0:01f31e923fe2 123 return osOK;
Pawel Zarembski 0:01f31e923fe2 124 }
Pawel Zarembski 0:01f31e923fe2 125
Pawel Zarembski 0:01f31e923fe2 126 osThreadId_t osThreadGetId(void)
Pawel Zarembski 0:01f31e923fe2 127 {
Pawel Zarembski 0:01f31e923fe2 128 return (osThreadId_t)os_tsk_self();
Pawel Zarembski 0:01f31e923fe2 129 }
Pawel Zarembski 0:01f31e923fe2 130
Pawel Zarembski 0:01f31e923fe2 131 osStatus_t osDelay(uint32_t ticks)
Pawel Zarembski 0:01f31e923fe2 132 {
Pawel Zarembski 0:01f31e923fe2 133 os_dly_wait(ticks);
Pawel Zarembski 0:01f31e923fe2 134 return osOK;
Pawel Zarembski 0:01f31e923fe2 135 }
Pawel Zarembski 0:01f31e923fe2 136
Pawel Zarembski 0:01f31e923fe2 137 uint32_t osKernelGetSysTimerCount(void)
Pawel Zarembski 0:01f31e923fe2 138 {
Pawel Zarembski 0:01f31e923fe2 139 return os_time_get();
Pawel Zarembski 0:01f31e923fe2 140 }
Pawel Zarembski 0:01f31e923fe2 141