2016-07-13 01:42:23 +00:00
|
|
|
//
|
|
|
|
// DigitalPhaseLockedLoopBridge.m
|
|
|
|
// Clock Signal
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 12/07/2016.
|
|
|
|
// Copyright © 2016 Thomas Harte. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#import "DigitalPhaseLockedLoopBridge.h"
|
|
|
|
|
|
|
|
#include "DigitalPhaseLockedLoop.hpp"
|
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
@interface DigitalPhaseLockedLoopBridge(BitPushing)
|
|
|
|
- (void)pushBit:(int)value;
|
|
|
|
@end
|
|
|
|
|
|
|
|
class DigitalPhaseLockedLoopDelegate: public Storage::DigitalPhaseLockedLoop::Delegate {
|
|
|
|
public:
|
|
|
|
__weak DigitalPhaseLockedLoopBridge *bridge;
|
|
|
|
|
2017-07-17 00:55:57 +00:00
|
|
|
void digital_phase_locked_loop_output_bit(int value) {
|
2016-07-13 01:42:23 +00:00
|
|
|
[bridge pushBit:value ? 1 : 0];
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-07-17 00:55:57 +00:00
|
|
|
@implementation DigitalPhaseLockedLoopBridge {
|
2016-07-13 01:42:23 +00:00
|
|
|
std::unique_ptr<Storage::DigitalPhaseLockedLoop> _digitalPhaseLockedLoop;
|
|
|
|
DigitalPhaseLockedLoopDelegate _delegate;
|
|
|
|
}
|
|
|
|
|
2017-07-17 00:55:57 +00:00
|
|
|
- (instancetype)initWithClocksPerBit:(NSUInteger)clocksPerBit historyLength:(NSUInteger)historyLength {
|
2016-07-13 01:42:23 +00:00
|
|
|
self = [super init];
|
2017-07-17 00:55:57 +00:00
|
|
|
if(self) {
|
|
|
|
_digitalPhaseLockedLoop.reset(new Storage::DigitalPhaseLockedLoop((unsigned int)clocksPerBit, (unsigned int)historyLength));
|
2016-07-13 01:42:23 +00:00
|
|
|
_delegate.bridge = self;
|
|
|
|
_digitalPhaseLockedLoop->set_delegate(&_delegate);
|
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2017-07-17 00:55:57 +00:00
|
|
|
- (void)runForCycles:(NSUInteger)cycles {
|
2017-07-25 01:04:47 +00:00
|
|
|
_digitalPhaseLockedLoop->run_for(Cycles((int)cycles));
|
2016-07-13 01:42:23 +00:00
|
|
|
}
|
|
|
|
|
2017-07-17 00:55:57 +00:00
|
|
|
- (void)addPulse {
|
2016-07-13 01:42:23 +00:00
|
|
|
_digitalPhaseLockedLoop->add_pulse();
|
|
|
|
}
|
|
|
|
|
2017-07-17 00:55:57 +00:00
|
|
|
- (void)pushBit:(int)value {
|
2016-07-13 01:42:23 +00:00
|
|
|
_stream = (_stream << 1) | value;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|