1 /*             ----> DO NOT REMOVE THE FOLLOWING NOTICE <----
2  *
3  *                 Copyright (c) 2014-2015 Datalight, Inc.
4  *                     All Rights Reserved Worldwide.
5  *
6  *  This program is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation; use version 2 of the License.
9  *
10  *  This program is distributed in the hope that it will be useful,
11  *  but "AS-IS," WITHOUT ANY WARRANTY; without even the implied warranty
12  *  of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License along
16  *  with this program; if not, write to the Free Software Foundation, Inc.,
17  *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 /*  Businesses and individuals that for commercial or other reasons cannot
21  *  comply with the terms of the GPLv2 license may obtain a commercial license
22  *  before incorporating Reliance Edge into proprietary software for
23  *  distribution in any form.  Visit http://www.datalight.com/reliance-edge for
24  *  more information.
25  */
26 
27 /** @file
28  *  @brief Implements task functions.
29  */
30 #include <FreeRTOS.h>
31 #include <task.h>
32 
33 #include <redfs.h>
34 
35 #if ( REDCONF_TASK_COUNT > 1U ) && ( REDCONF_API_POSIX == 1 )
36 
37     #include <redosdeviations.h>
38 
39     #if INCLUDE_xTaskGetCurrentTaskHandle != 1
40         #error "INCLUDE_xTaskGetCurrentTaskHandle must be 1 when REDCONF_TASK_COUNT > 1 and REDCONF_API_POSIX == 1"
41     #endif
42 
43 
44 /** @brief Get the current task ID.
45  *
46  *  This task ID must be unique for all tasks using the file system.
47  *
48  *  @return The task ID.  Must not be 0.
49  */
RedOsTaskId(void)50     uint32_t RedOsTaskId( void )
51     {
52         /*  Simply casting the xTaskGetCurrentTaskHandle() return value results in
53          *  warnings from some compilers, so use variables.
54          */
55         TaskHandle_t xTask = xTaskGetCurrentTaskHandle();
56         uintptr_t taskptr = CAST_TASK_PTR_TO_UINTPTR( xTask );
57         uint32_t ulTaskPtr = ( uint32_t ) taskptr;
58 
59         /*  Assert no information was lost casting from uintptr_t to uint32_t.
60          */
61         REDASSERT( ulTaskPtr == taskptr );
62 
63         /*  NULL is a valid task handle in FreeRTOS, so add one to all task IDs.
64          */
65         REDASSERT( ( ulTaskPtr + 1U ) != 0U );
66         return ulTaskPtr + 1U;
67     }
68 
69 #endif /* if ( REDCONF_TASK_COUNT > 1U ) && ( REDCONF_API_POSIX == 1 ) */
70