1 /* 2 * Copyright (c) 2020 - 2024 Renesas Electronics Corporation and/or its affiliates 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 */ 6 7 #ifndef BSP_DELAY_H 8 #define BSP_DELAY_H 9 10 /*********************************************************************************************************************** 11 * Includes <System Includes> , "Project Includes" 12 **********************************************************************************************************************/ 13 14 /** Common macro for FSP header files. There is also a corresponding FSP_FOOTER macro at the end of this file. */ 15 FSP_HEADER 16 17 #include "bsp_compiler_support.h" 18 19 /*******************************************************************************************************************//** 20 * @addtogroup BSP_MCU 21 * @{ 22 **********************************************************************************************************************/ 23 24 /*********************************************************************************************************************** 25 * Macro definitions 26 **********************************************************************************************************************/ 27 28 /* The number of cycles required per software delay loop. */ 29 #ifndef BSP_DELAY_LOOP_CYCLES 30 #if defined(RENESAS_CORTEX_M85) 31 32 /* On M85 cores, code alignment can affect execution speed. bsp_prv_software_delay_loop is aligned to 8 bytes for 33 * GCC and AC6, but IAR does not support aligning code. The below ensures the correct loop cycle count is used in 34 * this case. */ 35 #if defined(__ICCARM__) 36 #define BSP_DELAY_LOOP_CYCLES (((uint32_t) bsp_prv_software_delay_loop & 0x6) ? 2 : 1) 37 #else 38 #define BSP_DELAY_LOOP_CYCLES (1) 39 #endif 40 #else 41 #define BSP_DELAY_LOOP_CYCLES (4) 42 #endif 43 #endif 44 45 /* Calculates the number of delay loops to pass to bsp_prv_software_delay_loop to achieve at least the requested cycle 46 * count delay. This is 1 loop longer than optimal if cycles is a multiple of BSP_DELAY_LOOP_CYCLES, but it ensures 47 * the requested number of loops is at least 1 since bsp_prv_software_delay_loop cannot be called with a loop count 48 * of 0. */ 49 #define BSP_DELAY_LOOPS_CALCULATE(cycles) (((cycles) / BSP_DELAY_LOOP_CYCLES) + 1U) 50 51 /** Available delay units for R_BSP_SoftwareDelay(). These are ultimately used to calculate a total # of microseconds */ 52 typedef enum 53 { 54 BSP_DELAY_UNITS_SECONDS = 1000000, ///< Requested delay amount is in seconds 55 BSP_DELAY_UNITS_MILLISECONDS = 1000, ///< Requested delay amount is in milliseconds 56 BSP_DELAY_UNITS_MICROSECONDS = 1 ///< Requested delay amount is in microseconds 57 } bsp_delay_units_t; 58 59 /** @} (end addtogroup BSP_MCU) */ 60 61 /*********************************************************************************************************************** 62 * Exported global variables 63 **********************************************************************************************************************/ 64 65 /*********************************************************************************************************************** 66 * Exported global functions (to be accessed by other files) 67 **********************************************************************************************************************/ 68 BSP_ATTRIBUTE_STACKLESS void bsp_prv_software_delay_loop(uint32_t loop_cnt); 69 70 /** Common macro for FSP header files. There is also a corresponding FSP_HEADER macro at the top of this file. */ 71 FSP_FOOTER 72 73 #endif 74