/*!
* @brief Set the value of counter.
*
* The function is to set the value of Count register, Writing to the COUNT_L, COUNT_H, or unified register
* is only allowed when the corresponding counter is halted (HALT bits are set to 1 in the CTRL register).
*
* @param base SCTimer peripheral base address
* @param whichCounter SCTimer counter to use. In 16-bit mode, we can select Counter_L and Counter_H,
* In 32-bit mode, we can select Counter_U.
* @param value the counter value update to the COUNT register.
*/
static inline void SCTIMER_SetCOUNTValue(SCT_Type *base, sctimer_counter_t whichCounter, uint32_t value)
{
SCTIMER_StopTimer(base, (uint32_t)whichCounter);
switch (whichCounter)
{
case kSCTIMER_Counter_L:
assert(value <= 0xFFFFU);
assert(0U == (base->CONFIG & SCT_CONFIG_UNIFY_MASK));
/* Use Counter_L bits when user wants to setup the Low counter */
base->COUNT_ACCESS16BIT.COUNTL = (uint16_t)value;
break;
case kSCTIMER_Counter_H:
assert(value <= 0xFFFFU);
assert(0U == (base->CONFIG & SCT_CONFIG_UNIFY_MASK));
/* Use Counter_H bits when user wants to setup the High counter */
// base->COUNT = (uint32_t)base->COUNT_ACCESS16BIT.COUNTL | SCT_COUNT_CTR_H(value);
base->COUNT_ACCESS16BIT.COUNTH = (uint16_t)value; //the fix
break;
case kSCTIMER_Counter_U:
assert(1U == (base->CONFIG & SCT_CONFIG_UNIFY_MASK));
/* Use both Counter_L/Counter_H bits when counter is operating in 32-bit mode (unify counter). */
base->COUNT = value;
break;
default:
/* Fix the MISRA C-2012 issue rule 16.4. */
break;
}
SCTIMER_StartTimer(base, (uint32_t)whichCounter);
}