|
|
@@ -49,6 +49,13 @@ |
|
|
#define PLSR_POSITION_CHECKPOINT_MS (10U) |
|
|
#define PLSR_POSITION_CHECKPOINT_MS (10U) |
|
|
#define PLSR_PROFILE_QUEUE_CAPACITY (1024U) |
|
|
#define PLSR_PROFILE_QUEUE_CAPACITY (1024U) |
|
|
#define PLSR_PROFILE_QUEUE_MASK (PLSR_PROFILE_QUEUE_CAPACITY - 1U) |
|
|
#define PLSR_PROFILE_QUEUE_MASK (PLSR_PROFILE_QUEUE_CAPACITY - 1U) |
|
|
|
|
|
/* A profile item can represent only one pulse. At the 100 kHz limit these |
|
|
|
|
|
thresholds provide 4 ms of startup data, refill toward 8 ms, and cap each |
|
|
|
|
|
1 ms producer pass at 2 ms worth of newly planned items. */ |
|
|
|
|
|
#define PLSR_PROFILE_STARTUP_TARGET (400U) |
|
|
|
|
|
#define PLSR_PROFILE_STARTUP_BUDGET (400U) |
|
|
|
|
|
#define PLSR_PROFILE_REFILL_TARGET (800U) |
|
|
|
|
|
#define PLSR_PROFILE_REFILL_BUDGET (200U) |
|
|
#define PLSR_HANDOFF_WARMUP_ITEMS (8U) |
|
|
#define PLSR_HANDOFF_WARMUP_ITEMS (8U) |
|
|
#define PLSR_REPLAN_WARMUP_ITEMS (8U) |
|
|
#define PLSR_REPLAN_WARMUP_ITEMS (8U) |
|
|
#define PLSR_RAMP_POLL_RESERVE_AREA_DIVISOR (20ULL) |
|
|
#define PLSR_RAMP_POLL_RESERVE_AREA_DIVISOR (20ULL) |
|
|
@@ -320,7 +327,8 @@ static uint8_t PlsrProfileQueueBegin( |
|
|
uint32_t producerEpoch, |
|
|
uint32_t producerEpoch, |
|
|
uint8_t producerSegment, |
|
|
uint8_t producerSegment, |
|
|
uint8_t preparedHandoffBank); |
|
|
uint8_t preparedHandoffBank); |
|
|
static uint8_t PlsrProfileQueueFill(uint16_t targetCount); |
|
|
|
|
|
|
|
|
static uint8_t PlsrProfileQueueFill(uint16_t targetCount, |
|
|
|
|
|
uint16_t *itemBudget); |
|
|
static uint8_t PlsrStageCountedHandoff(void); |
|
|
static uint8_t PlsrStageCountedHandoff(void); |
|
|
static PLSR_PLATFORM_QUEUE_RESULT PlsrProfileQueueCommitNext( |
|
|
static PLSR_PLATFORM_QUEUE_RESULT PlsrProfileQueueCommitNext( |
|
|
uint8_t pulseOutput); |
|
|
uint8_t pulseOutput); |
|
|
@@ -1764,6 +1772,7 @@ static uint8_t PlsrReplanPulseDir(uint32_t targetHz, |
|
|
uint32_t epoch; |
|
|
uint32_t epoch; |
|
|
uint8_t segmentNumber; |
|
|
uint8_t segmentNumber; |
|
|
uint8_t handoffBank; |
|
|
uint8_t handoffBank; |
|
|
|
|
|
uint16_t fillBudget = PLSR_REPLAN_WARMUP_ITEMS; |
|
|
|
|
|
|
|
|
PlsrRamp.active = 0U; |
|
|
PlsrRamp.active = 0U; |
|
|
PlsrShortProfile.active = 0U; |
|
|
PlsrShortProfile.active = 0U; |
|
|
@@ -1794,7 +1803,8 @@ static uint8_t PlsrReplanPulseDir(uint32_t targetHz, |
|
|
handoffBank = PlsrPreparedHandoffBank; |
|
|
handoffBank = PlsrPreparedHandoffBank; |
|
|
(void)PlsrProfileQueueBegin(&PlsrShortProfile, epoch, |
|
|
(void)PlsrProfileQueueBegin(&PlsrShortProfile, epoch, |
|
|
segmentNumber, handoffBank); |
|
|
segmentNumber, handoffBank); |
|
|
if (PlsrProfileQueueFill(PLSR_REPLAN_WARMUP_ITEMS) == 0U) |
|
|
|
|
|
|
|
|
if (PlsrProfileQueueFill(PLSR_REPLAN_WARMUP_ITEMS, |
|
|
|
|
|
&fillBudget) == 0U) |
|
|
{ |
|
|
{ |
|
|
PlsrProfileQueueReset(); |
|
|
PlsrProfileQueueReset(); |
|
|
PlsrShortProfile.active = 0U; |
|
|
PlsrShortProfile.active = 0U; |
|
|
@@ -1905,7 +1915,8 @@ static void PlsrProfileRecordProducerCycles(uint32_t startCycles) |
|
|
} |
|
|
} |
|
|
#endif |
|
|
#endif |
|
|
|
|
|
|
|
|
static uint8_t PlsrProfileQueueFill(uint16_t targetCount) |
|
|
|
|
|
|
|
|
static uint8_t PlsrProfileQueueFill(uint16_t targetCount, |
|
|
|
|
|
uint16_t *itemBudget) |
|
|
{ |
|
|
{ |
|
|
PLSR_SHORT_PROFILE candidate; |
|
|
PLSR_SHORT_PROFILE candidate; |
|
|
PLSR_PROFILE_ENTRY entry; |
|
|
PLSR_PROFILE_ENTRY entry; |
|
|
@@ -1918,6 +1929,10 @@ static uint8_t PlsrProfileQueueFill(uint16_t targetCount) |
|
|
uint32_t startCycles; |
|
|
uint32_t startCycles; |
|
|
#endif |
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
if (itemBudget == NULL) |
|
|
|
|
|
{ |
|
|
|
|
|
return 0U; |
|
|
|
|
|
} |
|
|
if ((targetCount == 0U) |
|
|
if ((targetCount == 0U) |
|
|
|| (targetCount > PLSR_PROFILE_QUEUE_CAPACITY)) |
|
|
|| (targetCount > PLSR_PROFILE_QUEUE_CAPACITY)) |
|
|
{ |
|
|
{ |
|
|
@@ -1928,11 +1943,13 @@ static uint8_t PlsrProfileQueueFill(uint16_t targetCount) |
|
|
criticalState = PlsrPlatformEnterCritical(); |
|
|
criticalState = PlsrPlatformEnterCritical(); |
|
|
if ((PlsrProfileQueue.active == 0U) |
|
|
if ((PlsrProfileQueue.active == 0U) |
|
|
|| (PlsrProfileQueue.generatorComplete != 0U) |
|
|
|| (PlsrProfileQueue.generatorComplete != 0U) |
|
|
|| (PlsrProfileQueueCount() >= targetCount)) |
|
|
|
|
|
|
|
|
|| (PlsrProfileQueueCount() >= targetCount) |
|
|
|
|
|
|| (*itemBudget == 0U)) |
|
|
{ |
|
|
{ |
|
|
PlsrPlatformExitCritical(criticalState); |
|
|
PlsrPlatformExitCritical(criticalState); |
|
|
return 1U; |
|
|
return 1U; |
|
|
} |
|
|
} |
|
|
|
|
|
(*itemBudget)--; |
|
|
generation = PlsrProfileQueue.generation; |
|
|
generation = PlsrProfileQueue.generation; |
|
|
producerEpoch = PlsrProfileQueue.producerEpoch; |
|
|
producerEpoch = PlsrProfileQueue.producerEpoch; |
|
|
PlsrCopyShortProfile(&candidate, |
|
|
PlsrCopyShortProfile(&candidate, |
|
|
@@ -2196,6 +2213,7 @@ static uint8_t PlsrBeginSegmentOutput(uint32_t startFrequencyHz) |
|
|
uint32_t profileEpoch; |
|
|
uint32_t profileEpoch; |
|
|
uint8_t profileSegment; |
|
|
uint8_t profileSegment; |
|
|
uint8_t profileHandoffBank; |
|
|
uint8_t profileHandoffBank; |
|
|
|
|
|
uint16_t fillBudget = PLSR_PROFILE_STARTUP_BUDGET; |
|
|
PLSR_PROFILE_ENTRY firstRun; |
|
|
PLSR_PROFILE_ENTRY firstRun; |
|
|
|
|
|
|
|
|
PlsrSegmentClockStarted = 1U; |
|
|
PlsrSegmentClockStarted = 1U; |
|
|
@@ -2220,7 +2238,8 @@ static uint8_t PlsrBeginSegmentOutput(uint32_t startFrequencyHz) |
|
|
profileEpoch, |
|
|
profileEpoch, |
|
|
profileSegment, |
|
|
profileSegment, |
|
|
profileHandoffBank); |
|
|
profileHandoffBank); |
|
|
if (PlsrProfileQueueFill(PLSR_PROFILE_QUEUE_CAPACITY) == 0U) |
|
|
|
|
|
|
|
|
if (PlsrProfileQueueFill(PLSR_PROFILE_STARTUP_TARGET, |
|
|
|
|
|
&fillBudget) == 0U) |
|
|
{ |
|
|
{ |
|
|
PlsrProfileQueueReset(); |
|
|
PlsrProfileQueueReset(); |
|
|
PlsrShortProfile.active = 0U; |
|
|
PlsrShortProfile.active = 0U; |
|
|
@@ -2228,7 +2247,8 @@ static uint8_t PlsrBeginSegmentOutput(uint32_t startFrequencyHz) |
|
|
} |
|
|
} |
|
|
PlsrCountedHandoffStaged = 0U; |
|
|
PlsrCountedHandoffStaged = 0U; |
|
|
if ((PlsrStageCountedHandoff() == 0U) |
|
|
if ((PlsrStageCountedHandoff() == 0U) |
|
|
|| (PlsrProfileQueueFill(PLSR_PROFILE_QUEUE_CAPACITY) == 0U)) |
|
|
|
|
|
|
|
|
|| (PlsrProfileQueueFill(PLSR_PROFILE_STARTUP_TARGET, |
|
|
|
|
|
&fillBudget) == 0U)) |
|
|
{ |
|
|
{ |
|
|
PlsrProfileQueueReset(); |
|
|
PlsrProfileQueueReset(); |
|
|
PlsrShortProfile.active = 0U; |
|
|
PlsrShortProfile.active = 0U; |
|
|
@@ -3156,6 +3176,7 @@ static uint8_t PlsrPrepareFutureHandoffQueue(void) |
|
|
const PLSR_HANDOFF_PLAN *prepared; |
|
|
const PLSR_HANDOFF_PLAN *prepared; |
|
|
uint8_t currentSegment = PlsrCurrentSegment; |
|
|
uint8_t currentSegment = PlsrCurrentSegment; |
|
|
uint8_t preparedBank = PlsrPreparedHandoffBank; |
|
|
uint8_t preparedBank = PlsrPreparedHandoffBank; |
|
|
|
|
|
uint16_t fillBudget = PLSR_PROFILE_STARTUP_BUDGET; |
|
|
|
|
|
|
|
|
PlsrProfileQueueReset(); |
|
|
PlsrProfileQueueReset(); |
|
|
if ((currentSegment == 0U) |
|
|
if ((currentSegment == 0U) |
|
|
@@ -3173,7 +3194,8 @@ static uint8_t PlsrPrepareFutureHandoffQueue(void) |
|
|
PlsrSegmentEpoch + 1UL, |
|
|
PlsrSegmentEpoch + 1UL, |
|
|
prepared->nextSegment, |
|
|
prepared->nextSegment, |
|
|
preparedBank); |
|
|
preparedBank); |
|
|
if (PlsrProfileQueueFill(PLSR_PROFILE_QUEUE_CAPACITY) == 0U) |
|
|
|
|
|
|
|
|
if (PlsrProfileQueueFill(PLSR_PROFILE_STARTUP_TARGET, |
|
|
|
|
|
&fillBudget) == 0U) |
|
|
{ |
|
|
{ |
|
|
PlsrProfileQueueReset(); |
|
|
PlsrProfileQueueReset(); |
|
|
return 0U; |
|
|
return 0U; |
|
|
@@ -4015,6 +4037,7 @@ void PlsrPoll1ms(void) |
|
|
uint32_t criticalState; |
|
|
uint32_t criticalState; |
|
|
uint32_t newTargetHz; |
|
|
uint32_t newTargetHz; |
|
|
uint32_t pollEpoch; |
|
|
uint32_t pollEpoch; |
|
|
|
|
|
uint16_t fillBudget = PLSR_PROFILE_REFILL_BUDGET; |
|
|
|
|
|
|
|
|
if (PlsrInitialized == 0U) |
|
|
if (PlsrInitialized == 0U) |
|
|
{ |
|
|
{ |
|
|
@@ -4046,7 +4069,8 @@ void PlsrPoll1ms(void) |
|
|
|| (PlsrExecutor.mode == PLSR_EXEC_STREAM)) |
|
|
|| (PlsrExecutor.mode == PLSR_EXEC_STREAM)) |
|
|
&& (PlsrProfileQueue.active != 0U) |
|
|
&& (PlsrProfileQueue.active != 0U) |
|
|
&& (PlsrProfileQueue.generatorComplete == 0U) |
|
|
&& (PlsrProfileQueue.generatorComplete == 0U) |
|
|
&& (PlsrProfileQueueFill(PLSR_PROFILE_QUEUE_CAPACITY) == 0U)) |
|
|
|
|
|
|
|
|
&& (PlsrProfileQueueFill(PLSR_PROFILE_REFILL_TARGET, |
|
|
|
|
|
&fillBudget) == 0U)) |
|
|
{ |
|
|
{ |
|
|
PlsrEnterError(PLSR_ERROR_TIMER); |
|
|
PlsrEnterError(PLSR_ERROR_TIMER); |
|
|
return; |
|
|
return; |
|
|
@@ -4054,7 +4078,8 @@ void PlsrPoll1ms(void) |
|
|
if (((PlsrExecutor.mode == PLSR_EXEC_STEP_TABLE) |
|
|
if (((PlsrExecutor.mode == PLSR_EXEC_STEP_TABLE) |
|
|
|| (PlsrExecutor.mode == PLSR_EXEC_STREAM)) |
|
|
|| (PlsrExecutor.mode == PLSR_EXEC_STREAM)) |
|
|
&& ((PlsrStageCountedHandoff() == 0U) |
|
|
&& ((PlsrStageCountedHandoff() == 0U) |
|
|
|| (PlsrProfileQueueFill(PLSR_PROFILE_QUEUE_CAPACITY) == 0U))) |
|
|
|
|
|
|
|
|
|| (PlsrProfileQueueFill(PLSR_PROFILE_REFILL_TARGET, |
|
|
|
|
|
&fillBudget) == 0U))) |
|
|
{ |
|
|
{ |
|
|
PlsrEnterError(PLSR_ERROR_TIMER); |
|
|
PlsrEnterError(PLSR_ERROR_TIMER); |
|
|
return; |
|
|
return; |
|
|
|