2016-07-13 01:42:23 +00:00
//
// D P L L T e s t s . s w i f t
// C l o c k S i g n a l
//
// C r e a t e d b y T h o m a s H a r t e o n 1 2 / 0 7 / 2 0 1 6 .
// C o p y r i g h t © 2 0 1 6 T h o m a s H a r t e . A l l r i g h t s r e s e r v e d .
//
import XCTest
class DPLLTests : XCTestCase {
2016-07-14 11:12:02 +00:00
func testRegularNibblesOnPLL ( pll : DigitalPhaseLockedLoopBridge , bitLength : UInt ) {
// c l o c k i n t w o 1 s , a 0 , a n d a 1 , 2 0 0 t i m e s o v e r
for _ in 0 . . < 200 {
pll . runForCycles ( bitLength / 2 )
pll . addPulse ( )
pll . runForCycles ( bitLength )
pll . addPulse ( )
pll . runForCycles ( bitLength * 2 )
pll . addPulse ( )
pll . runForCycles ( bitLength / 2 )
}
XCTAssert ( ( pll . stream & 0xffffff ) = = 0xdddddd , " PLL should have synchronised and clocked repeating 0xd nibbles; got \( String ( pll . stream , radix : 16 , uppercase : false ) ) " )
}
2016-07-13 01:42:23 +00:00
func testPerfectInput ( ) {
let pll = DigitalPhaseLockedLoopBridge ( clocksPerBit : 100 , tolerance : 20 , historyLength : 5 )
2016-07-14 11:12:02 +00:00
testRegularNibblesOnPLL ( pll , bitLength : 100 )
}
2016-07-13 01:42:23 +00:00
2016-07-14 11:12:02 +00:00
func testFastButRegular ( ) {
let pll = DigitalPhaseLockedLoopBridge ( clocksPerBit : 100 , tolerance : 20 , historyLength : 5 )
testRegularNibblesOnPLL ( pll , bitLength : 90 )
2016-07-13 01:42:23 +00:00
}
2016-07-14 11:12:02 +00:00
func testSlowButRegular ( ) {
let pll = DigitalPhaseLockedLoopBridge ( clocksPerBit : 100 , tolerance : 20 , historyLength : 5 )
testRegularNibblesOnPLL ( pll , bitLength : 110 )
}
2016-07-13 01:42:23 +00:00
}