APP 4
Dependencies: mbed CRC16 mbed-rtos
Diff: APP.cpp
- Revision:
- 23:d41a23d8f2d7
- Parent:
- 20:f0932bfe09ed
- Child:
- 24:e307f6aad106
- Child:
- 25:a3e06778c54b
- Child:
- 26:f2b37f9dfca9
--- a/APP.cpp Tue Feb 23 00:22:49 2016 +0000 +++ b/APP.cpp Tue Feb 23 14:50:48 2016 +0000 @@ -18,11 +18,16 @@ unsigned int period = 0; unsigned int currentClocks = 0; bool periodCalculated = false; -bool firstBit = true; -bool value = false; MEF mef; STATES mefSTATE; int payloadSize = 0; +bool swag = false; +bool asdf = false; +int messageLength = 4; +bool buffer[16]; +int bufferCounter = 0; +bool firstBit = true; +STATES tempState = NOSTATE; int benchmark(void (*function) (void)) { @@ -35,7 +40,6 @@ { if ((LPC_TIM1->IR & 0x01) == 0x01) // if MR0 interrupt, proceed { - LPC_TIM1->IR |= 1 << 0; // Clear MR0 interrupt flag clockTick = !clockTick; out = encode(message[counter], clockTick); @@ -44,10 +48,12 @@ counter++; } - if (counter >= FRAMESIZE) + if (counter >= 56+messageLength*8) { - LPC_TIM1->MR0 = 1000000000; + counter = 0; } + + LPC_TIM1->IR |= 1 << 0; // Clear MR0 interrupt flag } } @@ -65,6 +71,8 @@ if (firstBit) { + swag = true; + asdf = !inputValue; mef.ReceiveBit(!inputValue); firstBit = false; } @@ -74,6 +82,8 @@ if (clocks >= period*1.5 || (currentClocks + clocks) >= period*1.5) { currentClocks = 0; + swag = true; + asdf = !inputValue; mef.ReceiveBit(!inputValue); } else @@ -92,7 +102,7 @@ //Timer 1 (match) LPC_SC->PCLKSEL0 |= (1 << 4); // pclk = cclk timer1 LPC_SC->PCONP |= (1 << 2); // timer1 power on - LPC_TIM1->MR0 = CLOCKS_TO_SECOND / 1000; // 100 ms + LPC_TIM1->MR0 = CLOCKS_TO_SECOND / 100; // 100 ms LPC_TIM1->MCR = 3; // interrupt and reset control // Interrupt & reset timer on match LPC_TIM1->EMR = (3 << 4); @@ -115,11 +125,11 @@ int main() { - message = buildFrame(convertToBits("BLUBLUBLUBLUBLU", 17), 17); + message = buildFrame(convertToBits("BLUB", messageLength), messageLength); LPC_PINCON->PINSEL0 |= (3 << 8); // P0.4 = CAP2.0 initTimers(); - STATES tempState = BLU; + while (true) { if (dataReady) @@ -135,21 +145,12 @@ } dataReady = false; } - if (tempState != mefSTATE) - { - pc.printf("\r\nNew state: %i \r\n", mefSTATE); - tempState = mefSTATE; - } - if(frameDropped) - { - pc.printf("Frame dropped\r\n"); - frameDropped = false; - } - if(debugMessageReady) - { - pc.printf("%i\r\n", debugMessage); - debugMessageReady = false; - } + + + + #if DEBUG + debugPrint(); + #endif } } @@ -168,6 +169,8 @@ void _decodeError() { frameDropped = true; + periodCalculated = false; + period = 0; } void _updateState(STATES state) @@ -180,3 +183,28 @@ debugMessage = blu; debugMessageReady = true; } + +void debugPrint() +{ + if (tempState != mefSTATE) + { + pc.printf("\r\nNew state: %i \r\n", mefSTATE); + tempState = mefSTATE; + } + if(frameDropped) + { + pc.printf("Frame dropped\r\n"); + frameDropped = false; + } + if(debugMessageReady) + { + pc.printf("%i\r\n", debugMessage); + debugMessageReady = false; + } + + if (swag) + { + pc.printf("%i ", asdf); + swag = false; + } +}