|
|
|
@@ -66,6 +66,7 @@ static uint8_t PlsrHostFiniteEnabled; |
|
|
|
static uint8_t PlsrHostFiniteActive[4]; |
|
|
|
static uint8_t PlsrHostFiniteComplete[4]; |
|
|
|
static uint8_t PlsrHostFiniteFrequencyPending[4]; |
|
|
|
static uint8_t PlsrHostCountedStreamActive[4]; |
|
|
|
static uint32_t PlsrHostFiniteTarget[4]; |
|
|
|
static uint32_t PlsrHostFiniteEmitted[4]; |
|
|
|
static PLSR_PLATFORM_FINITE_STEP *PlsrHostFiniteSteps[4]; |
|
|
|
@@ -403,6 +404,7 @@ uint8_t PlsrPlatformStartFinitePrepared( |
|
|
|
PlsrHostFiniteActive[pulseOutput] = 1U; |
|
|
|
PlsrHostFiniteComplete[pulseOutput] = 0U; |
|
|
|
PlsrHostFiniteFrequencyPending[pulseOutput] = 0U; |
|
|
|
PlsrHostCountedStreamActive[pulseOutput] = 0U; |
|
|
|
PlsrHostFiniteTarget[pulseOutput] = pulseCount; |
|
|
|
PlsrHostFiniteEmitted[pulseOutput] = 0UL; |
|
|
|
PlsrHostFiniteStepCount[pulseOutput] = 0U; |
|
|
|
@@ -418,6 +420,21 @@ uint8_t PlsrPlatformStartFinitePrepared( |
|
|
|
return 1U; |
|
|
|
} |
|
|
|
|
|
|
|
uint8_t PlsrPlatformStartCountedStreamPrepared( |
|
|
|
uint8_t pulseOutput, |
|
|
|
const PLSR_PLATFORM_TIMER_SETTING *setting, |
|
|
|
uint32_t pulseCount, |
|
|
|
uint32_t *actualFrequencyHz) |
|
|
|
{ |
|
|
|
if (PlsrPlatformStartFinitePrepared(pulseOutput, setting, pulseCount, |
|
|
|
actualFrequencyHz) == 0U) |
|
|
|
{ |
|
|
|
return 0U; |
|
|
|
} |
|
|
|
PlsrHostCountedStreamActive[pulseOutput] = 1U; |
|
|
|
return 1U; |
|
|
|
} |
|
|
|
|
|
|
|
uint8_t PlsrPlatformStartFiniteSequencePrepared( |
|
|
|
uint8_t pulseOutput, |
|
|
|
PLSR_PLATFORM_FINITE_STEP *steps, |
|
|
|
@@ -1488,6 +1505,13 @@ static uint32_t PlsrFiniteRetargetDrainPulses[4]; |
|
|
|
static uint32_t PlsrFiniteTargetPulses[4]; |
|
|
|
static uint32_t PlsrFiniteRemainingPulses[4]; |
|
|
|
static uint8_t PlsrFiniteCounterPreload[4]; |
|
|
|
static volatile uint8_t PlsrFiniteStreamActive[4]; |
|
|
|
static volatile uint8_t PlsrFiniteStreamNextValid[4]; |
|
|
|
static volatile uint8_t PlsrFiniteStreamNextStartsSegment[4]; |
|
|
|
static volatile uint8_t PlsrFiniteStreamSourceDone[4]; |
|
|
|
static volatile uint8_t PlsrFiniteStreamSourceFault[4]; |
|
|
|
static uint32_t PlsrFiniteStreamNextPulses[4]; |
|
|
|
static PLSR_PLATFORM_TIMER_SETTING PlsrFiniteStreamNextSetting[4]; |
|
|
|
static PLSR_PLATFORM_FINITE_STEP *PlsrFiniteSteps[4]; |
|
|
|
static volatile uint16_t PlsrFiniteStepCount[4]; |
|
|
|
static volatile uint16_t PlsrFiniteStepIndex[4]; |
|
|
|
@@ -3179,6 +3203,10 @@ uint8_t PlsrPlatformStartFinitePrepared( |
|
|
|
PlsrFiniteRemainingPulses[pulseOutput] = pulseCount; |
|
|
|
PlsrFiniteCompletionPending[pulseOutput] = 0U; |
|
|
|
PlsrFiniteFrequencyPending[pulseOutput] = 0U; |
|
|
|
PlsrFiniteStreamActive[pulseOutput] = 0U; |
|
|
|
PlsrFiniteStreamNextValid[pulseOutput] = 0U; |
|
|
|
PlsrFiniteStreamSourceDone[pulseOutput] = 0U; |
|
|
|
PlsrFiniteStreamSourceFault[pulseOutput] = 0U; |
|
|
|
PlsrFiniteActive[pulseOutput] = 1U; |
|
|
|
PlsrFiniteStepCount[pulseOutput] = 0U; |
|
|
|
PlsrFiniteStepIndex[pulseOutput] = 0U; |
|
|
|
@@ -3198,6 +3226,32 @@ uint8_t PlsrPlatformStartFinitePrepared( |
|
|
|
return 1U; |
|
|
|
} |
|
|
|
|
|
|
|
uint8_t PlsrPlatformStartCountedStreamPrepared( |
|
|
|
uint8_t pulseOutput, |
|
|
|
const PLSR_PLATFORM_TIMER_SETTING *setting, |
|
|
|
uint32_t pulseCount, |
|
|
|
uint32_t *actualFrequencyHz) |
|
|
|
{ |
|
|
|
TIM_TypeDef *counter; |
|
|
|
uint32_t firstBlock; |
|
|
|
|
|
|
|
if (PlsrPlatformStartFinitePrepared(pulseOutput, setting, pulseCount, |
|
|
|
actualFrequencyHz) == 0U) |
|
|
|
{ |
|
|
|
return 0U; |
|
|
|
} |
|
|
|
PlsrFiniteStreamActive[pulseOutput] = 1U; |
|
|
|
PlsrFiniteStreamNextValid[pulseOutput] = 0U; |
|
|
|
PlsrFiniteStreamNextStartsSegment[pulseOutput] = 0U; |
|
|
|
PlsrFiniteStreamSourceDone[pulseOutput] = 0U; |
|
|
|
PlsrFiniteStreamSourceFault[pulseOutput] = 0U; |
|
|
|
firstBlock = (pulseCount > PLSR_COUNTER_BLOCK_PULSES) |
|
|
|
? PLSR_COUNTER_BLOCK_PULSES : pulseCount; |
|
|
|
counter = PlsrCounters[PlsrCounterIndexByOutput[pulseOutput]]; |
|
|
|
PlsrFiniteArmNextStepPrepare(pulseOutput, counter, firstBlock); |
|
|
|
return 1U; |
|
|
|
} |
|
|
|
|
|
|
|
uint8_t PlsrPlatformStartFiniteSequencePrepared( |
|
|
|
uint8_t pulseOutput, |
|
|
|
PLSR_PLATFORM_FINITE_STEP *steps, |
|
|
|
@@ -3434,7 +3488,8 @@ uint8_t PlsrPlatformTakeFiniteCompletion(uint8_t pulseOutput, |
|
|
|
{ |
|
|
|
*completedPulses = PlsrFiniteTargetPulses[pulseOutput]; |
|
|
|
} |
|
|
|
if (PlsrFiniteStepCount[pulseOutput] == 0U) |
|
|
|
if ((PlsrFiniteStepCount[pulseOutput] == 0U) |
|
|
|
&& (PlsrFiniteStreamActive[pulseOutput] == 0U)) |
|
|
|
{ |
|
|
|
PlsrObservedPulseBase[pulseOutput] += *completedPulses; |
|
|
|
} |
|
|
|
@@ -3447,6 +3502,11 @@ uint8_t PlsrPlatformTakeFiniteCompletion(uint8_t pulseOutput, |
|
|
|
PlsrFiniteCounterPreload[pulseOutput] = 0U; |
|
|
|
PlsrFiniteStepCount[pulseOutput] = 0U; |
|
|
|
PlsrFiniteStepIndex[pulseOutput] = 0U; |
|
|
|
PlsrFiniteStreamActive[pulseOutput] = 0U; |
|
|
|
PlsrFiniteStreamNextValid[pulseOutput] = 0U; |
|
|
|
PlsrFiniteStreamNextStartsSegment[pulseOutput] = 0U; |
|
|
|
PlsrFiniteStreamSourceDone[pulseOutput] = 0U; |
|
|
|
PlsrFiniteStreamSourceFault[pulseOutput] = 0U; |
|
|
|
PlsrTimerActiveFrequencyHz[pulseOutput] = 0UL; |
|
|
|
PlsrTimerQueuedFrequencyHz[pulseOutput] = 0UL; |
|
|
|
PlsrTimerRunning[pulseOutput] = 0U; |
|
|
|
@@ -3944,6 +4004,11 @@ void PlsrPlatformStopPulse(uint8_t pulseOutput) |
|
|
|
PlsrFiniteRetargetDrainPulses[pulseOutput] = 0UL; |
|
|
|
PlsrFiniteTargetPulses[pulseOutput] = 0UL; |
|
|
|
PlsrFiniteRemainingPulses[pulseOutput] = 0UL; |
|
|
|
PlsrFiniteStreamActive[pulseOutput] = 0U; |
|
|
|
PlsrFiniteStreamNextValid[pulseOutput] = 0U; |
|
|
|
PlsrFiniteStreamNextStartsSegment[pulseOutput] = 0U; |
|
|
|
PlsrFiniteStreamSourceDone[pulseOutput] = 0U; |
|
|
|
PlsrFiniteStreamSourceFault[pulseOutput] = 0U; |
|
|
|
if (PlsrTimerOutputMode[pulseOutput] == PLSR_OUTPUT_AB) |
|
|
|
{ |
|
|
|
uint8_t pairOutput = (uint8_t)(pulseOutput + 1U); |
|
|
|
@@ -4747,8 +4812,12 @@ static void PlsrFiniteArmNextStepPrepare(uint8_t pulseOutput, |
|
|
|
|
|
|
|
counter->DIER &= ~TIM_DIER_CC1IE; |
|
|
|
counter->SR = ~TIM_SR_CC1IF; |
|
|
|
if ((nextIndex >= PlsrFiniteStepCount[pulseOutput]) |
|
|
|
|| (PlsrFiniteRemainingPulses[pulseOutput] > blockPulses)) |
|
|
|
if (PlsrFiniteRemainingPulses[pulseOutput] > blockPulses) |
|
|
|
{ |
|
|
|
return; |
|
|
|
} |
|
|
|
if ((PlsrFiniteStreamActive[pulseOutput] == 0U) |
|
|
|
&& (nextIndex >= PlsrFiniteStepCount[pulseOutput])) |
|
|
|
{ |
|
|
|
return; |
|
|
|
} |
|
|
|
@@ -4772,6 +4841,51 @@ static void PlsrFinitePrepareNextStepIrq(uint8_t pulseOutput, |
|
|
|
const PLSR_PLATFORM_TIMER_SETTING *next; |
|
|
|
|
|
|
|
counter->DIER &= ~TIM_DIER_CC1IE; |
|
|
|
if (PlsrFiniteStreamActive[pulseOutput] != 0U) |
|
|
|
{ |
|
|
|
PLSR_PLATFORM_TIMER_SETTING streamSetting; |
|
|
|
uint32_t streamPulses = 0UL; |
|
|
|
uint8_t startsNextSegment = 0U; |
|
|
|
uint8_t takeResult; |
|
|
|
|
|
|
|
if ((PlsrFiniteStreamNextValid[pulseOutput] != 0U) |
|
|
|
|| (PlsrFiniteStreamSourceDone[pulseOutput] != 0U) |
|
|
|
|| (PlsrFiniteStreamSourceFault[pulseOutput] != 0U)) |
|
|
|
{ |
|
|
|
return; |
|
|
|
} |
|
|
|
takeResult = PlsrExecTakeCountedRunIrq( |
|
|
|
pulseOutput, &streamSetting, &streamPulses, |
|
|
|
&startsNextSegment); |
|
|
|
if (takeResult == PLSR_EXEC_RUN_DONE) |
|
|
|
{ |
|
|
|
PlsrFiniteStreamSourceDone[pulseOutput] = 1U; |
|
|
|
return; |
|
|
|
} |
|
|
|
if ((takeResult != PLSR_EXEC_RUN_READY) |
|
|
|
|| (streamPulses == 0UL) |
|
|
|
|| (PlsrPreparedSettingIsValid( |
|
|
|
pulseOutput, PLSR_OUTPUT_PULSE_DIR, |
|
|
|
&streamSetting) == 0U)) |
|
|
|
{ |
|
|
|
PlsrFiniteStreamSourceFault[pulseOutput] = 1U; |
|
|
|
PlsrExecCountedStreamFaultIrq(pulseOutput); |
|
|
|
return; |
|
|
|
} |
|
|
|
timer = PlsrTimerMap[pulseOutput].timer; |
|
|
|
timer->PSC = streamSetting.prescaler; |
|
|
|
timer->ARR = streamSetting.period; |
|
|
|
timer->CCR1 = streamSetting.compare; |
|
|
|
PlsrTimerQueuedSetting[pulseOutput] = streamSetting; |
|
|
|
PlsrTimerQueuedFrequencyHz[pulseOutput] = |
|
|
|
streamSetting.actualFrequencyHz; |
|
|
|
PlsrFiniteStreamNextSetting[pulseOutput] = streamSetting; |
|
|
|
PlsrFiniteStreamNextPulses[pulseOutput] = streamPulses; |
|
|
|
PlsrFiniteStreamNextStartsSegment[pulseOutput] = |
|
|
|
startsNextSegment; |
|
|
|
PlsrFiniteStreamNextValid[pulseOutput] = 1U; |
|
|
|
return; |
|
|
|
} |
|
|
|
if (nextIndex >= PlsrFiniteStepCount[pulseOutput]) |
|
|
|
{ |
|
|
|
return; |
|
|
|
@@ -4813,7 +4927,47 @@ static void PlsrFiniteCounterIrq(uint8_t pulseOutput, |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
if (PlsrFiniteStepCount[pulseOutput] != 0U) |
|
|
|
if (PlsrFiniteStreamActive[pulseOutput] != 0U) |
|
|
|
{ |
|
|
|
PlsrObservedPulseBase[pulseOutput] += |
|
|
|
PlsrFiniteTargetPulses[pulseOutput]; |
|
|
|
PlsrObservedPulsePublished[pulseOutput] = |
|
|
|
PlsrObservedPulseBase[pulseOutput]; |
|
|
|
if (PlsrFiniteStreamNextValid[pulseOutput] != 0U) |
|
|
|
{ |
|
|
|
uint32_t nextPulses = |
|
|
|
PlsrFiniteStreamNextPulses[pulseOutput]; |
|
|
|
uint32_t firstBlock = |
|
|
|
(nextPulses > PLSR_COUNTER_BLOCK_PULSES) |
|
|
|
? PLSR_COUNTER_BLOCK_PULSES : nextPulses; |
|
|
|
|
|
|
|
if (PlsrFiniteStreamNextStartsSegment[pulseOutput] != 0U) |
|
|
|
{ |
|
|
|
/* 段边界回调只传"到当前 run 完成为止的累计计数"(IRQ 内 |
|
|
|
已累加完成的 base),执行器只置事件,不做簿记。 */ |
|
|
|
PlsrExecCountedSegmentBoundaryIrq( |
|
|
|
pulseOutput, PlsrObservedPulseBase[pulseOutput]); |
|
|
|
} |
|
|
|
PlsrFiniteTargetPulses[pulseOutput] = nextPulses; |
|
|
|
PlsrFiniteRemainingPulses[pulseOutput] = nextPulses; |
|
|
|
PlsrCounterOverflowPulses[ |
|
|
|
PlsrCounterIndexByOutput[pulseOutput]] = 0UL; |
|
|
|
counter->ARR = (firstBlock == 1UL) |
|
|
|
? 1UL : (firstBlock - 1UL); |
|
|
|
PlsrFiniteCounterPreload[pulseOutput] = |
|
|
|
(firstBlock == 1UL) ? 1U : 0U; |
|
|
|
counter->CNT = PlsrFiniteCounterPreload[pulseOutput]; |
|
|
|
PlsrTimerActiveSetting[pulseOutput] = |
|
|
|
PlsrFiniteStreamNextSetting[pulseOutput]; |
|
|
|
PlsrTimerActiveFrequencyHz[pulseOutput] = |
|
|
|
PlsrFiniteStreamNextSetting[pulseOutput].actualFrequencyHz; |
|
|
|
PlsrFiniteStreamNextValid[pulseOutput] = 0U; |
|
|
|
PlsrFiniteStreamNextStartsSegment[pulseOutput] = 0U; |
|
|
|
PlsrFiniteArmNextStepPrepare(pulseOutput, counter, firstBlock); |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
else if (PlsrFiniteStepCount[pulseOutput] != 0U) |
|
|
|
{ |
|
|
|
uint16_t completedIndex = PlsrFiniteStepIndex[pulseOutput]; |
|
|
|
uint16_t nextIndex = (uint16_t)(completedIndex + 1U); |
|
|
|
|