1 /* 2 * Copyright (c) 2001-2019, Arm Limited and Contributors. All rights reserved. 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 */ 6 7 #include "cc_pal_types.h" 8 #include "FreeRTOS.h" 9 #include "task.h" 10 11 int32_t g_pmCntr; 12 CC_PalPowerSaveModeInit(void)13void CC_PalPowerSaveModeInit(void) 14 { 15 g_pmCntr = 0; 16 return; 17 } 18 CC_PalPowerSaveModeStatus(void)19int32_t CC_PalPowerSaveModeStatus(void) 20 { 21 return g_pmCntr; 22 } 23 CC_PalPowerSaveModeSelect(CCBool isPowerSaveMode)24CCError_t CC_PalPowerSaveModeSelect(CCBool isPowerSaveMode) 25 { 26 CCError_t rc = CC_OK; 27 28 switch (isPowerSaveMode){ 29 case CC_FALSE: 30 taskENTER_CRITICAL(); 31 g_pmCntr++; 32 taskEXIT_CRITICAL(); 33 break; 34 case CC_TRUE: 35 taskENTER_CRITICAL(); 36 g_pmCntr--; 37 taskEXIT_CRITICAL(); 38 break; 39 default: 40 return CC_FAIL; 41 } 42 43 if(g_pmCntr == 0){ 44 /* once the counter is zero, 45 * an external callback shall be called to notify the PMU that ARM Cerberus might be powered down. */ 46 } 47 48 if(g_pmCntr < 0 ){ 49 /* illegal state - exit with error */ 50 return CC_FAIL; 51 } 52 53 return rc; 54 } 55