Przeglądaj źródła

中断瘦身

codex/plsr-2026-minimal
ywh 1 miesiąc temu
rodzic
commit
aaa65d62f1
5 zmienionych plików z 837 dodań i 64 usunięć
  1. +3
    -2
      HostComputer/bin_to_time_freq.py
  2. +650
    -57
      PLSR/Src/plsr.c
  3. +8
    -1
      PLSR/Src/plsr_internal.h
  4. +18
    -0
      PLSR/Src/plsr_platform.h
  5. +158
    -4
      PLSR/Src/plsr_platform_f407.c

+ 3
- 2
HostComputer/bin_to_time_freq.py Wyświetl plik

@@ -28,7 +28,7 @@
Ctrl+滚轮 缩放 Y 轴(以鼠标 Y 位置为中心)
左键拖拽 双向平移(上下左右跟随鼠标)
双击 复位到全图
鼠标悬停 高亮最近的点并显示其时间与频率
鼠标悬停 高亮最近的点并显示其脉冲序号、时间与频率

依赖: pip install numpy matplotlib
"""
@@ -205,7 +205,8 @@ def plot_show(path, fs, thresh, ymax, save_path=None):
if dist[k] <= 20.0:
idx = int(np.flatnonzero(mask)[k])
hl_marker.set_data([tx_ms[idx]], [freq[idx]])
hl_text.set_text("t = %.3f ms\nf = %.0f Hz" % (tx_ms[idx], freq[idx]))
hl_text.set_text("脉冲 #%d\nt = %.3f ms\nf = %.0f Hz"
% (idx + 1, tx_ms[idx], freq[idx]))
hl_text.set_position((tx_ms[idx] + (x1 - x0) * 0.01,
freq[idx] + (ax.get_ylim()[1] - ax.get_ylim()[0]) * 0.02))
hl_marker.set_visible(True)


+ 650
- 57
PLSR/Src/plsr.c
Plik diff jest za duży
Wyświetl plik


+ 8
- 1
PLSR/Src/plsr_internal.h Wyświetl plik

@@ -15,10 +15,17 @@
typedef enum
{
PLSR_EXEC_IDLE = 0,
PLSR_EXEC_STEP_TABLE,
PLSR_EXEC_STREAM,
PLSR_EXEC_AB_LEGACY
PLSR_EXEC_AB_LEGACY,
PLSR_EXEC_REPLANNING,
PLSR_EXEC_STOPPING
} PLSR_EXEC_MODE;

#define PLSR_EXEC_RUN_FAILED (0U)
#define PLSR_EXEC_RUN_READY (1U)
#define PLSR_EXEC_RUN_DONE (2U)

typedef struct
{
uint32_t frequencyHz;


+ 18
- 0
PLSR/Src/plsr_platform.h Wyświetl plik

@@ -73,6 +73,11 @@ uint8_t PlsrPlatformStartFinitePrepared(
const PLSR_PLATFORM_TIMER_SETTING *setting,
uint32_t pulseCount,
uint32_t *actualFrequencyHz);
uint8_t PlsrPlatformStartCountedStreamPrepared(
uint8_t pulseOutput,
const PLSR_PLATFORM_TIMER_SETTING *setting,
uint32_t pulseCount,
uint32_t *actualFrequencyHz);
uint8_t PlsrPlatformStartFiniteSequencePrepared(
uint8_t pulseOutput,
PLSR_PLATFORM_FINITE_STEP *steps,
@@ -95,6 +100,19 @@ uint8_t PlsrPlatformTakeFiniteBoundary(uint8_t pulseOutput,
uint32_t *completedPulses,
uint8_t *sequenceContinues,
uint32_t *activeFrequencyHz);

/* Counted-stream callbacks are owned by the executor in plsr.c. The
platform invokes them only at a hardware counter run boundary. These
callbacks must only latch events/snapshots; all bookkeeping runs in the
1 ms task. */
uint8_t PlsrExecTakeCountedRunIrq(
uint8_t pulseOutput,
PLSR_PLATFORM_TIMER_SETTING *setting,
uint32_t *pulseCount,
uint8_t *startsNextSegment);
void PlsrExecCountedSegmentBoundaryIrq(uint8_t pulseOutput,
uint32_t completedPulses);
void PlsrExecCountedStreamFaultIrq(uint8_t pulseOutput);
PLSR_PLATFORM_QUEUE_RESULT PlsrPlatformLoadPreparedFromIrq(
uint8_t pulseOutput,
const PLSR_PLATFORM_TIMER_SETTING *setting,


+ 158
- 4
PLSR/Src/plsr_platform_f407.c Wyświetl plik

@@ -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);


Ładowanie…
Anuluj
Zapisz