xref: /btstack/port/renesas-tb-s1ja-cc256x/template/btstack_example/synergy/ssp/src/bsp/mcu/s1ja/bsp_cache.c (revision 3b5c872a8c45689e8cc17891f01530f5aa5e911c)
1 /***********************************************************************************************************************
2  * Copyright [2015-2017] Renesas Electronics Corporation and/or its licensors. All Rights Reserved.
3  *
4  * This file is part of Renesas SynergyTM Software Package (SSP)
5  *
6  * The contents of this file (the "contents") are proprietary and confidential to Renesas Electronics Corporation
7  * and/or its licensors ("Renesas") and subject to statutory and contractual protections.
8  *
9  * This file is subject to a Renesas SSP license agreement. Unless otherwise agreed in an SSP license agreement with
10  * Renesas: 1) you may not use, copy, modify, distribute, display, or perform the contents; 2) you may not use any name
11  * or mark of Renesas for advertising or publicity purposes or in connection with your use of the contents; 3) RENESAS
12  * MAKES NO WARRANTY OR REPRESENTATIONS ABOUT THE SUITABILITY OF THE CONTENTS FOR ANY PURPOSE; THE CONTENTS ARE PROVIDED
13  * "AS IS" WITHOUT ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
14  * PARTICULAR PURPOSE, AND NON-INFRINGEMENT; AND 4) RENESAS SHALL NOT BE LIABLE FOR ANY DIRECT, INDIRECT, SPECIAL, OR
15  * CONSEQUENTIAL DAMAGES, INCLUDING DAMAGES RESULTING FROM LOSS OF USE, DATA, OR PROJECTS, WHETHER IN AN ACTION OF
16  * CONTRACT OR TORT, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THE CONTENTS. Third-party contents
17  * included in this file may be subject to different terms.
18  **********************************************************************************************************************/
19 /***********************************************************************************************************************
20 * File Name    : bsp_cache.c
21 * Description  : This module provides APIs for turning cache on and off.
22 ***********************************************************************************************************************/
23 
24 /***********************************************************************************************************************
25 Includes   <System Includes> , "Project Includes"
26 ***********************************************************************************************************************/
27 #include "bsp_api.h"
28 
29 #if defined(BSP_MCU_GROUP_S1JA)
30 
31 /***********************************************************************************************************************
32 Macro definitions
33 ***********************************************************************************************************************/
34 #define BSP_CACHE_TIMEOUT (UINT32_MAX)   /* This timeout is not precise and is only to prevent the code from being
35                                           * stuck in a "while" loop.
36                                           */
37 /***********************************************************************************************************************
38 Typedef definitions
39 ***********************************************************************************************************************/
40 
41 /***********************************************************************************************************************
42 Exported global variables (to be accessed by other files)
43 ***********************************************************************************************************************/
44 
45 /***********************************************************************************************************************
46 Private global variables and functions
47 ***********************************************************************************************************************/
48 
49 /*******************************************************************************************************************//**
50  * @brief Attempt to turn cache off.
51  *
52  * @param[in] p_state Pointer to the on/off state of cache when the function was called.
53  *
54  * @retval SSP_SUCCESS          Cache was turned off.
55  * @retval SSP_ERR_ASSERTION    NULL pointer.
56  **********************************************************************************************************************/
57 
R_BSP_CacheOff(bsp_cache_state_t * p_state)58 ssp_err_t   R_BSP_CacheOff(bsp_cache_state_t * p_state)
59 {
60 #if BSP_CFG_PARAM_CHECKING_ENABLE
61     /* Check pointer for NULL value. */
62     SSP_ASSERT(NULL != p_state);         /** return error if NULL p_state */
63 #endif
64 
65     *p_state = (bsp_cache_state_t)R_ROMC->ROMCE_b.ROMCEN;
66     R_ROMC->ROMCE_b.ROMCEN = 0U;         /** Disable ROM cache. */
67     return SSP_SUCCESS;
68 }
69 
70 /*******************************************************************************************************************//**
71  * @brief Attempt to set the cache on or off.
72  *
73  * @param[in] state on/off state to set cache to.
74  *
75  * @retval SSP_SUCCESS          Cache was set or restored.
76  * @retval SSP_ERR_TIMEOUT      Cache was not restored.
77  **********************************************************************************************************************/
78 
R_BSP_CacheSet(bsp_cache_state_t state)79 ssp_err_t   R_BSP_CacheSet(bsp_cache_state_t state)
80 {
81     ssp_err_t ret_val;
82     ret_val = SSP_SUCCESS;
83     uint32_t i = BSP_CACHE_TIMEOUT;
84 
85     R_ROMC->ROMCIV_b.ROMCIV = 1U;      /** Invalidate cache. */
86     while ((R_ROMC->ROMCIV_b.ROMCIV != 0U) && (i != 0x00U))
87     {
88         /* Wait for bit to clear. Timeout on hardware failure.*/
89         i--;
90     }
91     if (0U == i)
92     {
93         ret_val = SSP_ERR_TIMEOUT;                          /** Return error on timeout. */
94     }
95     else
96     {
97         R_ROMC->ROMCE_b.ROMCEN = (uint16_t)state & 0x01U;   /** Enable ROM cache. */
98     }
99     return ret_val;
100 }
101 
102 
103 #endif
104 
105 
106 
107