#ifndef PLSR_H #define PLSR_H #include #ifdef __cplusplus extern "C" { #endif #define PLSR_CONFIG_FIRST_ADDRESS (0x1000U) #define PLSR_CONFIG_LAST_ADDRESS (0x1197U) #define PLSR_STATUS_FIRST_ADDRESS (0x2000U) #define PLSR_STATUS_LAST_ADDRESS (0x2006U) #define PLSR_CONTROL_ADDRESS (0x3000U) #define PLSR_OUTPUT_MODE_ADDRESS (0x1200U) #define PLSR_DIAGNOSTIC_FIRST_ADDRESS (0x2100U) #define PLSR_DIAGNOSTIC_LAST_ADDRESS (0x2119U) #define PLSR_DIAGNOSTIC_CONTROL_ADDRESS (0x3100U) typedef enum { PLSR_MB_NOT_HANDLED = 0, PLSR_MB_OK, PLSR_MB_ILLEGAL_ADDRESS, PLSR_MB_ILLEGAL_VALUE, PLSR_MB_DEVICE_BUSY, PLSR_MB_SERVER_FAILURE } PLSR_MB_RESULT; typedef enum { PLSR_STATUS_UNINITIALIZED = 0, PLSR_STATUS_IDLE = 1, PLSR_STATUS_ACCELERATING = 2, PLSR_STATUS_RUNNING = 3, PLSR_STATUS_DECELERATING = 4, PLSR_STATUS_WAITING = 5, PLSR_STATUS_PAUSED = 6, PLSR_STATUS_COMPLETED = 7, PLSR_STATUS_STOPPED = 8, PLSR_STATUS_ERROR = 9 } PLSR_STATUS; typedef enum { PLSR_ERROR_NONE = 0, PLSR_ERROR_INVALID_TRANSITION = 1, PLSR_ERROR_RESOURCE_CONFLICT = 2, PLSR_ERROR_INVALID_RESOURCE = 3, PLSR_ERROR_TIMER = 4, PLSR_ERROR_COUNT = 5, PLSR_ERROR_POSITIVE_LIMIT = 6, PLSR_ERROR_NEGATIVE_LIMIT = 7, PLSR_ERROR_EMERGENCY_STOP = 8, PLSR_ERROR_INTERNAL = 9 } PLSR_ERROR; uint8_t PlsrInit(void); void PlsrPoll1ms(void); void PlsrServicePersistence(void); PLSR_MB_RESULT PlsrModbusReadHolding(uint16_t startAddress, uint16_t quantity, uint16_t *values); PLSR_MB_RESULT PlsrModbusWriteHolding(uint16_t startAddress, uint16_t quantity, const uint16_t *values); /* Called by the selected output timer update interrupt once per pulse. */ void PlsrPulseTimerIrq(uint8_t pulseOutput); void PlsrFinalArmJobIrq(uint8_t pulseOutput); #ifdef PLSR_HOST_TEST uint64_t PlsrTestDivideU64ByU32(uint64_t dividend, uint32_t divisor, uint32_t *remainder); void PlsrTestSetInput(uint8_t inputSelection, uint8_t level); void PlsrTestEmitPulses(uint32_t pulseCount); void PlsrTestEmitPulseOnCriticalEntry(void); void PlsrTestEmitPulseAfterCriticalEntries(uint8_t entriesToSkip); void PlsrTestEmitPulseOnCriticalExit(void); void PlsrTestLatchPulseOnCriticalEntry(void); void PlsrTestLatchAbFinalQuarterOnNextStopArm(void); void PlsrTestCompleteAbCycleOnNextQueueCommit(void); void PlsrTestServicePendingPulse(void); void PlsrTestServiceFinalArmJob(void); void PlsrTestDeferFinalArmJob(uint8_t defer); void PlsrTestFailNextStart(void); void PlsrTestStaleNextFrequencyAtUpdate(void); void PlsrTestFailNextFrequencyAtUpdate(void); void PlsrTestFailNextStopRequest(void); void PlsrTestEmitAbQuarters(uint32_t quarterCount); uint8_t PlsrTestPulseIsActive(void); uint32_t PlsrTestOutputFrequency(void); uint32_t PlsrTestQueuedFrequency(void); uint8_t PlsrTestDirectionLevel(void); uint8_t PlsrTestDirectionPinLevel(uint8_t directionOutput); uint32_t PlsrTestDirectionWriteCount(uint8_t directionOutput); uint32_t PlsrTestDirectionTransitionCount(uint8_t directionOutput); uint8_t PlsrTestAbPhase(void); uint32_t PlsrTestAbTransitionCount(void); uint32_t PlsrTestAbFastGateCount(void); uint32_t PlsrTestAbCleanupCount(void); void PlsrTestInjectCountOffset(int32_t offset); void PlsrTestInjectActiveFrequencyOffset(int32_t offsetHz); void PlsrTestInjectCurveMismatch(void); void PlsrTestForceProfileQueueEmpty(void); uint16_t PlsrTestProfileQueueCount(void); uint32_t PlsrTestProfileQueueGeneration(void); uint32_t PlsrTestProfileQueueReadIndex(void); uint32_t PlsrTestProfileQueueWriteIndex(void); uint32_t PlsrTestProfileQueueHeadFrequency(void); uint16_t PlsrTestProfileProducerNextPeriod(void); uint16_t PlsrTestActiveProfileNextPeriod(void); uint32_t PlsrTestLastGateEvent(void); uint32_t PlsrTestLastDiagnosticFinishEvent(void); void PlsrTestSetPosition(int32_t position, uint8_t positionValid); void PlsrTestClearPersistentStorage(void); void PlsrTestResetSaveCount(void); uint32_t PlsrTestSaveCount(void); #endif #if defined(PLSR_DEBUG_TIMING) && (PLSR_DEBUG_TIMING != 0) extern volatile uint32_t PlsrProfileProducerItemCount; extern volatile uint32_t PlsrProfileProducerTotalCycles; extern volatile uint32_t PlsrProfileProducerMaxItemCycles; #endif #ifdef __cplusplus } #endif #endif /* PLSR_H */