1 /*
2 * Copyright (c) 2018, Texas Instruments Incorporated
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * * Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * * Neither the name of Texas Instruments Incorporated nor the names of
17 * its contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32 /*
33 * ======== TaskP_tirtos.c ========
34 */
35 #include <ti/sysbios/knl/Task.h>
36 #include <ti/sysbios/knl/Clock.h>
37 #include "TaskP.h"
38 #include <xdc/runtime/Memory.h>
39 #include <xdc/runtime/Error.h>
40 #include <ti/osal/src/tirtos/tirtos_config.h>
41 /*
42 * ======== TaskP_create ========
43 */
44 TaskP_Handle TaskP_create(void *taskfxn, const TaskP_Params *params)
45 {
46 Task_Handle taskHandle;
47 Task_Params taskParams;
48 Error_Block *pErrBlk = (Error_Block *) NULL_PTR;
50 Task_Params_init(&taskParams);
52 if(params != NULL_PTR)
53 {
54 taskParams.stackSize = params->stacksize;
55 taskParams.priority = params->priority;
56 taskParams.arg0 = (UArg)(params->arg0);
57 taskParams.arg1 = (UArg)(params->arg1);
58 taskParams.instance->name = (char *)(params->name);
59 if(params->stack!=NULL_PTR)
60 {
61 taskParams.stack = params->stack;
62 }
63 pErrBlk = (Error_Block *) params->pErrBlk;
64 }
66 if (pErrBlk != NULL_PTR)
67 {
68 Error_init(pErrBlk);
69 }
71 taskHandle = Task_create((Task_FuncPtr)taskfxn, &taskParams, pErrBlk);
73 return ((TaskP_Handle)taskHandle);
74 }
76 /*
77 * ======== TaskP_delete ========
78 */
79 TaskP_Status TaskP_delete(TaskP_Handle *handle)
80 {
81 /* In case of apps with the BIOS cfg 'Task.deleteTerminatedTasks' enabled,
82 * cleanup happens in BIOS idle task.
83 * Deleting terminated task will results in BIOS error.
84 * Hence to make BIOS config independent,
85 * Delete the Task only when flag is disbaled.*/
86 if (Task_deleteTerminatedTasks == FALSE)
87 {
88 Task_delete((Task_Handle *)handle);
89 }
90 return TaskP_OK;
91 }
93 /*
94 * ======== TaskP_Params_init ========
95 */
96 void TaskP_Params_init(TaskP_Params *params)
97 {
98 Task_Params taskParams;
99 Task_Params_init(&taskParams);
100 params->priority = (int8_t)taskParams.priority;
101 params->stacksize = (uint32_t)taskParams.stackSize;
102 params->arg0 = (void *)(taskParams.arg0);
103 params->arg1 = (void *)(taskParams.arg1);
104 params->name = (uint8_t *)(taskParams.instance->name);
105 params->stack = NULL_PTR;
106 params->pErrBlk = NULL_PTR;
107 }
109 void TaskP_sleep(uint32_t timeout)
110 {
111 Task_sleep(timeout);
112 }
114 void TaskP_sleepInMsecs(uint32_t timeoutInMsecs)
115 {
116 uint32_t ticks;
118 /* Clock_tickPeriod is in units of usecs */
119 ticks = (uint32_t)((uint64_t)timeoutInMsecs * 1000U) / Clock_tickPeriod;
121 TaskP_sleep(ticks);
122 }
124 void TaskP_setPrio(TaskP_Handle handle, uint32_t priority)
125 {
126 (void)Task_setPri((Task_Handle)handle, (int16_t)priority);
127 }
129 TaskP_Handle TaskP_self(void)
130 {
131 return ((TaskP_Handle)Task_self());
132 }
134 TaskP_Handle TaskP_selfmacro(void)
135 {
136 return ((TaskP_Handle)Task_selfMacro());
137 }
139 void TaskP_yield(void) {
140 Task_yield();
141 }
143 uint32_t TaskP_isTerminated(TaskP_Handle handle)
144 {
145 uint32_t isTaskTerminated = 0;
147 if(Task_getMode((Task_Handle)handle)!=Task_Mode_TERMINATED)
148 {
149 isTaskTerminated = 0;
150 }
151 else
152 {
153 isTaskTerminated = 1;
154 }
155 return isTaskTerminated;
156 }
158 /* Nothing past this point */