1 /***********************************************************************************************//**
2  * \file cyabs_rtos_impl.h
3  *
4  * \brief
5  * Internal definitions for RTOS abstraction layer.
6  *
7  ***************************************************************************************************
8  * \copyright
9  * Copyright 2019-2021 Cypress Semiconductor Corporation (an Infineon company) or
10  * an affiliate of Cypress Semiconductor Corporation
11  *
12  * SPDX-License-Identifier: Apache-2.0
13  *
14  * Licensed under the Apache License, Version 2.0 (the "License");
15  * you may not use this file except in compliance with the License.
16  * You may obtain a copy of the License at
17  *
18  *     http://www.apache.org/licenses/LICENSE-2.0
19  *
20  * Unless required by applicable law or agreed to in writing, software
21  * distributed under the License is distributed on an "AS IS" BASIS,
22  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23  * See the License for the specific language governing permissions and
24  * limitations under the License.
25  **************************************************************************************************/
26 
27 #pragma once
28 
29 #include <stdint.h>
30 #include <stdbool.h>
31 #include "tx_api.h"
32 
33 #ifdef __cplusplus
34 extern "C"
35 {
36 #endif
37 
38 #if !defined (COMPONENT_CAT5)
39 #include <cmsis_compiler.h>
40 #else
41 #include "cyabs_rtos_impl_cat5.h"
42 #endif
43 
44 
45 /******************************************************
46 *                 Constants
47 ******************************************************/
48 #define CY_RTOS_MIN_STACK_SIZE  TX_MINIMUM_STACK /**< Minimum stack size in bytes */
49 #define CY_RTOS_ALIGNMENT       0x00000008UL     /**< Minimum alignment for RTOS objects */
50 #define CY_RTOS_ALIGNMENT_MASK  0x00000007UL     /**< Checks for 8-byte alignment */
51 
52 
53 /******************************************************
54 *                 Type Definitions
55 ******************************************************/
56 
57 #if !defined (COMPONENT_CAT5)
58 // RTOS thread priority. See /ref cy_thread_priority_t in the
59 // cyabs_rtos_impl_cat5.h for the CAT5 thread priority definitions
60 typedef enum
61 {
62     CY_RTOS_PRIORITY_MIN         = TX_MAX_PRIORITIES - 1,         /**< Minumum allowable Thread
63                                                                      priority */
64     CY_RTOS_PRIORITY_LOW         = (TX_MAX_PRIORITIES * 6 / 7),   /**< A low priority Thread */
65     CY_RTOS_PRIORITY_BELOWNORMAL = (TX_MAX_PRIORITIES * 5 / 7),   /**< A slightly below normal
66                                                                      Thread priority */
67     CY_RTOS_PRIORITY_NORMAL      = (TX_MAX_PRIORITIES * 4 / 7),   /**< The normal Thread priority */
68     CY_RTOS_PRIORITY_ABOVENORMAL = (TX_MAX_PRIORITIES * 3 / 7),   /**< A slightly elevated Thread
69                                                                      priority */
70     CY_RTOS_PRIORITY_HIGH        = (TX_MAX_PRIORITIES * 2 / 7),   /**< A high priority Thread */
71     CY_RTOS_PRIORITY_REALTIME    = (TX_MAX_PRIORITIES * 1 / 7),   /**< Realtime Thread priority */
72     CY_RTOS_PRIORITY_MAX         = 0                              /**< Maximum allowable Thread
73                                                                      priority */
74 } cy_thread_priority_t;
75 #endif // if !defined (COMPONENT_CAT5)
76 
77 typedef struct
78 {
79     uint32_t     maxcount;
80     TX_SEMAPHORE tx_semaphore;
81 } cy_semaphore_t;
82 
83 typedef struct
84 {
85     ULONG* mem;
86     // ThreadX buffer size is a power of 2 times word size,
87     // this is used to prevent memory corruption when get message from queue.
88     size_t   itemsize;
89     TX_QUEUE tx_queue;
90 } cy_queue_t;
91 
92 typedef struct
93 {
94     bool     oneshot;
95     TX_TIMER tx_timer;
96 } cy_timer_t;
97 
98 typedef TX_THREAD*              cy_thread_t;
99 typedef ULONG                   cy_thread_arg_t;
100 typedef TX_MUTEX                cy_mutex_t;
101 typedef TX_EVENT_FLAGS_GROUP    cy_event_t;
102 typedef ULONG                   cy_timer_callback_arg_t;
103 typedef uint32_t                cy_time_t;
104 typedef UINT                    cy_rtos_error_t;
105 
106 #ifdef __cplusplus
107 } // extern "C"
108 #endif
109