mirror of
https://github.com/TomHarte/CLK.git
synced 2024-12-23 20:29:42 +00:00
Fixed the DigitalPhaseLockedLoopBridge
bridge, once again fixing tests.
This commit is contained in:
parent
b3861ff755
commit
7b5f93510b
@ -10,7 +10,7 @@
|
||||
|
||||
@interface DigitalPhaseLockedLoopBridge : NSObject
|
||||
|
||||
- (instancetype)initWithClocksPerBit:(NSUInteger)clocksPerBit tolerance:(NSUInteger)tolerance historyLength:(NSUInteger)historyLength;
|
||||
- (instancetype)initWithClocksPerBit:(NSUInteger)clocksPerBit historyLength:(NSUInteger)historyLength;
|
||||
|
||||
- (void)runForCycles:(NSUInteger)cycles;
|
||||
- (void)addPulse;
|
||||
|
@ -19,42 +19,35 @@ class DigitalPhaseLockedLoopDelegate: public Storage::DigitalPhaseLockedLoop::De
|
||||
public:
|
||||
__weak DigitalPhaseLockedLoopBridge *bridge;
|
||||
|
||||
void digital_phase_locked_loop_output_bit(int value)
|
||||
{
|
||||
void digital_phase_locked_loop_output_bit(int value) {
|
||||
[bridge pushBit:value ? 1 : 0];
|
||||
}
|
||||
};
|
||||
|
||||
@implementation DigitalPhaseLockedLoopBridge
|
||||
{
|
||||
@implementation DigitalPhaseLockedLoopBridge {
|
||||
std::unique_ptr<Storage::DigitalPhaseLockedLoop> _digitalPhaseLockedLoop;
|
||||
DigitalPhaseLockedLoopDelegate _delegate;
|
||||
}
|
||||
|
||||
- (instancetype)initWithClocksPerBit:(NSUInteger)clocksPerBit tolerance:(NSUInteger)tolerance historyLength:(NSUInteger)historyLength
|
||||
{
|
||||
- (instancetype)initWithClocksPerBit:(NSUInteger)clocksPerBit historyLength:(NSUInteger)historyLength {
|
||||
self = [super init];
|
||||
if(self)
|
||||
{
|
||||
_digitalPhaseLockedLoop.reset(new Storage::DigitalPhaseLockedLoop((unsigned int)clocksPerBit, (unsigned int)tolerance, (unsigned int)historyLength));
|
||||
if(self) {
|
||||
_digitalPhaseLockedLoop.reset(new Storage::DigitalPhaseLockedLoop((unsigned int)clocksPerBit, (unsigned int)historyLength));
|
||||
_delegate.bridge = self;
|
||||
_digitalPhaseLockedLoop->set_delegate(&_delegate);
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)runForCycles:(NSUInteger)cycles
|
||||
{
|
||||
- (void)runForCycles:(NSUInteger)cycles {
|
||||
_digitalPhaseLockedLoop->run_for_cycles((unsigned int)cycles);
|
||||
}
|
||||
|
||||
- (void)addPulse
|
||||
{
|
||||
- (void)addPulse {
|
||||
_digitalPhaseLockedLoop->add_pulse();
|
||||
}
|
||||
|
||||
- (void)pushBit:(int)value
|
||||
{
|
||||
- (void)pushBit:(int)value {
|
||||
_stream = (_stream << 1) | value;
|
||||
}
|
||||
|
||||
|
@ -26,22 +26,22 @@ class DPLLTests: XCTestCase {
|
||||
}
|
||||
|
||||
func testPerfectInput() {
|
||||
let pll = DigitalPhaseLockedLoopBridge(clocksPerBit: 100, tolerance: 20, historyLength: 3)
|
||||
let pll = DigitalPhaseLockedLoopBridge(clocksPerBit: 100, historyLength: 3)
|
||||
testRegularNibblesOnPLL(pll!, bitLength: 100)
|
||||
}
|
||||
|
||||
func testFastButRegular() {
|
||||
let pll = DigitalPhaseLockedLoopBridge(clocksPerBit: 100, tolerance: 20, historyLength: 3)
|
||||
let pll = DigitalPhaseLockedLoopBridge(clocksPerBit: 100, historyLength: 3)
|
||||
testRegularNibblesOnPLL(pll!, bitLength: 90)
|
||||
}
|
||||
|
||||
func testSlowButRegular() {
|
||||
let pll = DigitalPhaseLockedLoopBridge(clocksPerBit: 100, tolerance: 20, historyLength: 3)
|
||||
let pll = DigitalPhaseLockedLoopBridge(clocksPerBit: 100, historyLength: 3)
|
||||
testRegularNibblesOnPLL(pll!, bitLength: 110)
|
||||
}
|
||||
|
||||
func testTwentyPercentSinePattern() {
|
||||
let pll = DigitalPhaseLockedLoopBridge(clocksPerBit: 100, tolerance: 20, historyLength: 3)
|
||||
let pll = DigitalPhaseLockedLoopBridge(clocksPerBit: 100, historyLength: 3)
|
||||
var angle = 0.0
|
||||
|
||||
// clock in two 1s, a 0, and a 1, 200 times over
|
||||
|
Loading…
Reference in New Issue
Block a user