]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - processor-sdk/pdk.git/blob - packages/ti/osal/src/tirtos/TaskP_tirtos.c
osal-rtos: add to PDK
[processor-sdk/pdk.git] / packages / ti / osal / src / tirtos / TaskP_tirtos.c
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     Task_delete((Task_Handle *)handle);
82     return TaskP_OK;
83 }
85 /*
86  *  ======== TaskP_Params_init ========
87  */
88 void TaskP_Params_init(TaskP_Params *params)
89 {
90     Task_Params taskParams;
91     Task_Params_init(&taskParams);
92     params->priority = (int8_t)taskParams.priority;
93     params->stacksize = (uint32_t)taskParams.stackSize;
94     params->arg0 = (void *)(taskParams.arg0);
95     params->arg1 = (void *)(taskParams.arg1);
96     params->name = (uint8_t *)(taskParams.instance->name);
97     params->stack = NULL_PTR;
98     params->pErrBlk = NULL_PTR;
99 }
101 void TaskP_sleep(uint32_t timeout)
103     Task_sleep(timeout);
106 void TaskP_sleepInMsecs(uint32_t timeoutInMsecs)
108     uint32_t ticks;
110     /* Clock_tickPeriod is in units of usecs */
111     ticks = (uint32_t)((uint64_t)timeoutInMsecs * 1000U) / Clock_tickPeriod;
113     TaskP_sleep(ticks);
116 void TaskP_setPrio(TaskP_Handle handle, uint32_t priority)
118     (void)Task_setPri((Task_Handle)handle, (int16_t)priority);
121 TaskP_Handle TaskP_self(void)
123     return ((TaskP_Handle)Task_self());
126 TaskP_Handle TaskP_selfmacro(void)
128     return ((TaskP_Handle)Task_selfMacro());
131 void TaskP_yield(void) {
132     Task_yield();
135 uint32_t TaskP_isTerminated(TaskP_Handle handle)
137     uint32_t isTaskTerminated = 0;
139     if(Task_getMode((Task_Handle)handle)!=Task_Mode_TERMINATED)
140     {
141         isTaskTerminated = 0;
142     }
143     else
144     {
145         isTaskTerminated = 1;
146     }
147     return isTaskTerminated;
150 /* Nothing past this point */