123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335 |
- #include "platform.h"
- #define BSP_PRV_PRCR_KEY (0xA500)
-
- static volatile uint16_t g_protect_counters[BSP_REG_PROTECT_TOTAL_ITEMS];
- static const uint16_t g_prcr_masks[BSP_REG_PROTECT_TOTAL_ITEMS-1] =
- {
- 0x0001,
- 0x0002,
- 0x0008,
- };
- void R_BSP_InterruptsDisable (void)
- {
-
- R_CLRPSW_I();
- }
- void R_BSP_InterruptsEnable (void)
- {
-
- R_SETPSW_I();
- }
- uint32_t R_BSP_CpuInterruptLevelRead (void)
- {
-
- uint32_t psw_value;
- psw_value = (uint32_t)R_GET_PSW();
- psw_value = psw_value & 0x0f000000;
- psw_value = psw_value >> 24;
- return psw_value;
- }
- bool R_BSP_CpuInterruptLevelWrite (uint32_t level)
- {
- uint32_t psw_value;
- #if (BSP_CFG_PARAM_CHECKING_ENABLE == 1)
-
- if (level > BSP_MCU_IPL_MAX)
- {
- return false;
- }
- #endif
-
- psw_value = level << 24;
- psw_value = psw_value | ((uint32_t)R_GET_PSW() & 0xf0ffffff);
- R_SET_PSW(psw_value);
- return true;
- }
- void R_BSP_RegisterProtectEnable (bsp_reg_protect_t regs_to_protect)
- {
- volatile uint32_t ipl_value;
- bool ret;
-
- ipl_value = R_BSP_CpuInterruptLevelRead();
-
- if (ipl_value < BSP_CFG_FIT_IPL_MAX)
- {
- ret = R_BSP_CpuInterruptLevelWrite(BSP_CFG_FIT_IPL_MAX);
- if (false == ret)
- {
-
- }
- }
-
- if (0 != g_protect_counters[regs_to_protect])
- {
-
- g_protect_counters[regs_to_protect]--;
- }
-
- if (0 == g_protect_counters[regs_to_protect])
- {
- if (BSP_REG_PROTECT_MPC != regs_to_protect)
- {
-
-
- SYSTEM.PRCR.WORD = (uint16_t)((SYSTEM.PRCR.WORD | BSP_PRV_PRCR_KEY) & (~g_prcr_masks[regs_to_protect]));
- }
- else
- {
-
-
- MPC.PWPR.BIT.B0WI = 0;
-
- MPC.PWPR.BIT.PFSWE = 0;
-
- MPC.PWPR.BIT.B0WI = 1;
- }
- }
-
- if (ipl_value < BSP_CFG_FIT_IPL_MAX)
- {
- ret = R_BSP_CpuInterruptLevelWrite(ipl_value);
- if (false == ret)
- {
-
- }
- }
- }
- void R_BSP_RegisterProtectDisable (bsp_reg_protect_t regs_to_unprotect)
- {
- volatile uint32_t ipl_value;
- bool ret;
-
- ipl_value = R_BSP_CpuInterruptLevelRead();
-
- if (ipl_value < BSP_CFG_FIT_IPL_MAX)
- {
- ret = R_BSP_CpuInterruptLevelWrite(BSP_CFG_FIT_IPL_MAX);
- if (false == ret)
- {
-
- }
- }
-
- if (0 == g_protect_counters[regs_to_unprotect])
- {
- if (BSP_REG_PROTECT_MPC != regs_to_unprotect)
- {
-
-
- SYSTEM.PRCR.WORD = (uint16_t)((SYSTEM.PRCR.WORD | BSP_PRV_PRCR_KEY) | g_prcr_masks[regs_to_unprotect]);
- }
- else
- {
-
-
- MPC.PWPR.BIT.B0WI = 0;
-
- MPC.PWPR.BIT.PFSWE = 1;
- }
- }
-
- g_protect_counters[regs_to_unprotect]++;
-
- if (ipl_value < BSP_CFG_FIT_IPL_MAX)
- {
- ret = R_BSP_CpuInterruptLevelWrite(ipl_value);
- if (false == ret)
- {
-
- }
- }
- }
- void bsp_register_protect_open (void)
- {
- uint32_t i;
-
- for (i = 0; i < BSP_REG_PROTECT_TOTAL_ITEMS; i++)
- {
- g_protect_counters[i] = 0;
- }
- }
- void bsp_ram_initialize (void)
- {
- uint32_t i;
-
- for (i = 0; i < BSP_NUM_LOCKS; i++)
- {
- g_bsp_Locks[i].lock = 0;
- }
- }
|