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 <FreeRTOS.h>
30 #include <semphr.h>
31 #include <task.h>
32 #include <event_groups.h>
33 #include <timers.h>
34 #include "stdbool.h"
35 #if !defined (COMPONENT_CAT5)
36 #include <cmsis_compiler.h>
37 #endif
38 #if defined(CY_USING_HAL)
39 #include "cyhal.h"
40 #endif
41 
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45 
46 /******************************************************
47 *                 Constants
48 ******************************************************/
49 #define CY_RTOS_MIN_STACK_SIZE      300            /**< Minimum stack size in bytes */
50 #define CY_RTOS_ALIGNMENT           0x00000008UL   /**< Minimum alignment for RTOS objects */
51 #define CY_RTOS_ALIGNMENT_MASK      0x00000007UL   /**< Mask for checking the alignment of
52                                                         created RTOS objects */
53 #if !defined(CY_RTOS_MAX_SUSPEND_NESTING)
54 #define CY_RTOS_MAX_SUSPEND_NESTING 3              /**< Maximum nesting allowed for calls
55                                                         to scheduler suspend from ISR */
56 #endif
57 /******************************************************
58 *                   Enumerations
59 ******************************************************/
60 
61 typedef enum cy_thread_priority
62 {
63     CY_RTOS_PRIORITY_MIN         = 0,
64     CY_RTOS_PRIORITY_LOW         = (configMAX_PRIORITIES * 1 / 7),
65     CY_RTOS_PRIORITY_BELOWNORMAL = (configMAX_PRIORITIES * 2 / 7),
66     CY_RTOS_PRIORITY_NORMAL      = (configMAX_PRIORITIES * 3 / 7),
67     CY_RTOS_PRIORITY_ABOVENORMAL = (configMAX_PRIORITIES * 4 / 7),
68     CY_RTOS_PRIORITY_HIGH        = (configMAX_PRIORITIES * 5 / 7),
69     CY_RTOS_PRIORITY_REALTIME    = (configMAX_PRIORITIES * 6 / 7),
70     CY_RTOS_PRIORITY_MAX         = configMAX_PRIORITIES - 1
71 } cy_thread_priority_t;
72 
73 /******************************************************
74 *                 Type Definitions
75 ******************************************************/
76 
77 typedef struct
78 {
79     SemaphoreHandle_t mutex_handle;
80     bool              is_recursive;
81 } cy_mutex_t;
82 
83 typedef QueueHandle_t      cy_queue_t;
84 typedef SemaphoreHandle_t  cy_semaphore_t;
85 typedef TaskHandle_t       cy_thread_t;
86 typedef EventGroupHandle_t cy_event_t;
87 typedef TimerHandle_t      cy_timer_t;
88 typedef uint32_t           cy_timer_callback_arg_t;
89 typedef void*              cy_thread_arg_t;
90 typedef uint32_t           cy_time_t;
91 typedef BaseType_t         cy_rtos_error_t;
92 
93 #if defined(CY_USING_HAL)
94 /** Stores a reference to an lptimer instance for use with vApplicationSleep().
95  *
96  * @param[in] timer  Pointer to the lptimer handle
97  */
98 void cyabs_rtos_set_lptimer(cyhal_lptimer_t* timer);
99 
100 /** Gets a reference to the lptimer instance object used by vApplicationSleep(). This instance is
101  * what was explicitly set by @ref cyabs_rtos_set_lptimer or, if none was set, what was
102  * automatically allocated by the first call to vApplicationSleep().
103  *
104  * @return Pointer to the lptimer handle
105  */
106 cyhal_lptimer_t* cyabs_rtos_get_lptimer(void);
107 
108 /** If the interrupt is in pending state and disabled need to remove it from NVIC.
109  * NOTE: this function if for internal use
110  */
111 extern void _cyabs_rtos_clear_disabled_irq_in_pending(void);
112 
113 #endif //defined(CY_USING_HAL)
114 
115 
116 cy_time_t convert_ms_to_ticks(cy_time_t timeout_ms);
117 
118 #ifdef __cplusplus
119 } // extern "C"
120 #endif
121