1 /***********************************************************************************************//**
2  * \file cyabs_rtos_impl.h
3  *
4  * \brief
5  * Internal definitions for RTOS abstraction layer
6  *
7  ***************************************************************************************************
8  * \copyright
9  * Copyright 2019-2022 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 <stdbool.h>
30 #include <zephyr/kernel.h>
31 
32 #ifdef __cplusplus
33 extern "C"
34 {
35 #endif
36 
37 /*
38  *                 Constants
39  */
40 #define CY_RTOS_MIN_STACK_SIZE      300                 /** Minimum stack size in bytes */
41 #define CY_RTOS_ALIGNMENT           0x00000008UL        /** Minimum alignment for RTOS objects */
42 #define CY_RTOS_ALIGNMENT_MASK      0x00000007UL        /** Mask for checking the alignment of */
43 
44 /*
45  *                 Type Definitions
46  */
47 
48 /* RTOS thread priority */
49 typedef enum {
50 	CY_RTOS_PRIORITY_MIN            = CONFIG_NUM_PREEMPT_PRIORITIES - 1,
51 	CY_RTOS_PRIORITY_LOW            = (CONFIG_NUM_PREEMPT_PRIORITIES * 6 / 7),
52 	CY_RTOS_PRIORITY_BELOWNORMAL    = (CONFIG_NUM_PREEMPT_PRIORITIES * 5 / 7),
53 	CY_RTOS_PRIORITY_NORMAL         = (CONFIG_NUM_PREEMPT_PRIORITIES * 4 / 7),
54 	CY_RTOS_PRIORITY_ABOVENORMAL    = (CONFIG_NUM_PREEMPT_PRIORITIES * 3 / 7),
55 	CY_RTOS_PRIORITY_HIGH           = (CONFIG_NUM_PREEMPT_PRIORITIES * 2 / 7),
56 	CY_RTOS_PRIORITY_REALTIME       = (CONFIG_NUM_PREEMPT_PRIORITIES * 1 / 7),
57 	CY_RTOS_PRIORITY_MAX            = 0
58 } cy_thread_priority_t;
59 
60 /** \cond INTERNAL */
61 typedef struct {
62 	struct k_thread z_thread;
63 	void *memptr;
64 } k_thread_wrapper_t;
65 
66 typedef struct {
67 	struct k_timer z_timer;
68 	uint32_t trigger_type;
69 	uint32_t status;
70 	void *callback_function;
71 	void *arg;
72 } k_timer_wrapper_t;
73 /** \endcond */
74 
75 /* Zephyr definition of a thread handle */
76 typedef k_thread_wrapper_t *cy_thread_t;
77 
78 /* Argument passed to the entry function of a thread */
79 typedef void *cy_thread_arg_t;
80 
81 /* Zephyr definition of a mutex */
82 typedef struct k_mutex cy_mutex_t;
83 
84 /* Zephyr definition of a semaphore */
85 typedef struct k_sem cy_semaphore_t;
86 
87 /* Zephyr definition of an event */
88 typedef struct k_event cy_event_t;
89 
90 /* Zephyr definition of a message queue */
91 typedef struct k_msgq cy_queue_t;
92 
93 /* Zephyr definition of a timer */
94 typedef k_timer_wrapper_t cy_timer_t;
95 
96 /* Argument passed to the timer callback function */
97 typedef void *cy_timer_callback_arg_t;
98 
99 /* Time in milliseconds */
100 typedef uint32_t cy_time_t;
101 
102 /* Zephyr definition of a error status */
103 typedef int cy_rtos_error_t;
104 
105 #ifdef __cplusplus
106 } /* extern "C" */
107 #endif
108