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 9 int32_t g_apbcCntr; 10 CC_PalApbcCntrInit(void)11void CC_PalApbcCntrInit(void) 12 { 13 g_apbcCntr = 0; 14 return; 15 } 16 CC_PalApbcCntrValue(void)17int32_t CC_PalApbcCntrValue(void) 18 { 19 return g_apbcCntr; 20 } 21 CC_PalApbcModeSelect(CCBool isApbcInc)22CCError_t CC_PalApbcModeSelect(CCBool isApbcInc) 23 { 24 CCError_t rc = CC_OK; 25 switch (isApbcInc){ 26 case CC_FALSE: 27 __atomic_fetch_sub(&g_apbcCntr, 1, __ATOMIC_SEQ_CST); 28 break; 29 case CC_TRUE: 30 __atomic_fetch_add(&g_apbcCntr, 1, __ATOMIC_SEQ_CST); 31 break; 32 default: 33 return -1; 34 } 35 36 if(g_apbcCntr < 0 ){ 37 /* illegal state - exit with error */ 38 return 1; 39 } 40 41 return rc; 42 } 43