1 /***********************************************************************************************//**
2  * \file cyabs_freertos_common.c
3  *
4  * \brief
5  * Provides implementations for common functions in FreeRTOS abstraction.
6  *
7  ***************************************************************************************************
8  * \copyright
9  * Copyright 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 #include "cyabs_rtos.h"
27 #if defined(CY_USING_HAL)
28 #include "cyhal.h"
29 #endif
30 
31 
32 #if defined(CY_USING_HAL)
33 //--------------------------------------------------------------------------------------------------
34 // _cyhal_system_irq_clear_disabled_in_pending
35 //--------------------------------------------------------------------------------------------------
_cyhal_system_irq_clear_disabled_in_pending(void)36 __WEAK void _cyhal_system_irq_clear_disabled_in_pending(void)
37 {
38     /*
39      * The weak implementation for function that
40      * clears disabled interrupts in pending state
41      */
42 }
43 
44 
45 #endif /* defined(CY_USING_HAL) */
46 
47 
48 #if defined(FREERTOS_COMMON_SECTION_BEGIN)
49 FREERTOS_COMMON_SECTION_BEGIN
50 #endif
51 //--------------------------------------------------------------------------------------------------
52 // convert_ms_to_ticks
53 //--------------------------------------------------------------------------------------------------
convert_ms_to_ticks(cy_time_t timeout_ms)54 cy_time_t convert_ms_to_ticks(cy_time_t timeout_ms)
55 {
56     // Don't convert away from CY_RTOS_NEVER_TIMEOUT due to it being max value
57     // Also, skip conversion if timeout_ms is 0
58     if (timeout_ms == CY_RTOS_NEVER_TIMEOUT)
59     {
60         return CY_RTOS_NEVER_TIMEOUT;
61     }
62     else if (timeout_ms == 0)
63     {
64         return 0;
65     }
66     else
67     {
68         // Convert using our conversion to avoid overflow
69         uint64_t ticks =
70             ((uint64_t)(((uint64_t)(timeout_ms) * (uint64_t)configTICK_RATE_HZ) /
71                         (uint64_t)1000));
72 
73         if (ticks >= UINT32_MAX)
74         {
75             // if ticks if more than 32 bits, change ticks to max possible value
76             // that isn't CY_RTOS_NEVER_TIMEOUT.
77             ticks = UINT32_MAX - 1;
78         }
79         return (cy_time_t)ticks;
80     }
81 }
82 
83 
84 #if defined(FREERTOS_COMMON_SECTION_END)
85 FREERTOS_COMMON_SECTION_END
86 #endif
87