APP 4

Dependencies:   mbed CRC16 mbed-rtos

Committer:
vinbel93
Date:
Sun Feb 21 18:26:24 2016 +0000
Revision:
6:3181f546e812
Parent:
3:3ffa14e75b8a
Child:
8:60499583959f
clean up

Who changed what in which revision?

UserRevisionLine numberNew contents of line
manl2003 2:1250280a511b 1 #include "APP.h"
vinbel93 3:3ffa14e75b8a 2 #include "Manchester.h"
vinbel93 0:ac5e42371639 3
vinbel93 0:ac5e42371639 4 Serial pc(USBTX, USBRX);
vinbel93 6:3181f546e812 5 DigitalIn in(p9);
vinbel93 0:ac5e42371639 6
vinbel93 6:3181f546e812 7 bool clockTick = false;
vinbel93 6:3181f546e812 8 bitset<FRAMESIZE> message(string("1000111011110101011100000000000111011010101001111111011110011010"));
vinbel93 3:3ffa14e75b8a 9 int counter = 0;
vinbel93 0:ac5e42371639 10
vinbel93 1:f212b6676849 11 int benchmark(void (*function) (void))
vinbel93 0:ac5e42371639 12 {
vinbel93 3:3ffa14e75b8a 13 int count = LPC_TIM2->TC;
vinbel93 0:ac5e42371639 14 function();
vinbel93 3:3ffa14e75b8a 15 return LPC_TIM2->TC - count;
vinbel93 0:ac5e42371639 16 }
vinbel93 0:ac5e42371639 17
vinbel93 1:f212b6676849 18 extern "C" void TIMER2_IRQHandler()
vinbel93 0:ac5e42371639 19 {
vinbel93 0:ac5e42371639 20 if ((LPC_TIM2->IR & 0x01) == 0x01) // if MR0 interrupt, proceed
vinbel93 0:ac5e42371639 21 {
vinbel93 3:3ffa14e75b8a 22 LPC_TIM2->IR |= 1 << 0; // Clear MR0 interrupt flag
vinbel93 6:3181f546e812 23 clockTick = !clockTick;
vinbel93 6:3181f546e812 24 LPC_TIM2->EMR = encode(message[counter], clockTick);
vinbel93 6:3181f546e812 25
vinbel93 6:3181f546e812 26 if (clockTick)
vinbel93 0:ac5e42371639 27 {
vinbel93 6:3181f546e812 28 counter++;
vinbel93 0:ac5e42371639 29 }
vinbel93 6:3181f546e812 30
vinbel93 6:3181f546e812 31 if (counter >= FRAMESIZE)
vinbel93 0:ac5e42371639 32 {
vinbel93 6:3181f546e812 33 counter = 0;
vinbel93 0:ac5e42371639 34 }
vinbel93 0:ac5e42371639 35 }
vinbel93 0:ac5e42371639 36 }
vinbel93 6:3181f546e812 37
vinbel93 1:f212b6676849 38 void initTimer()
vinbel93 0:ac5e42371639 39 {
vinbel93 6:3181f546e812 40 LPC_SC->PCLKSEL1 |= (1 << 12); // pclk = cclk timer2
vinbel93 6:3181f546e812 41 LPC_SC->PCONP |= (1 << 22); // timer2 power on
vinbel93 6:3181f546e812 42 LPC_TIM2->MR0 = CLOCKS_TO_SECOND / 10; // 100 ms
vinbel93 6:3181f546e812 43 LPC_TIM2->MCR = 3; // interrupt & reset timer2 on match
vinbel93 6:3181f546e812 44 LPC_TIM2->EMR = (3 << 4); // toggle
vinbel93 6:3181f546e812 45 NVIC_EnableIRQ(TIMER2_IRQn); // enable timer2 interrupt
vinbel93 6:3181f546e812 46 LPC_TIM2->TCR = 1; // enable timer2
vinbel93 0:ac5e42371639 47 }
vinbel93 0:ac5e42371639 48
vinbel93 1:f212b6676849 49 int main()
vinbel93 0:ac5e42371639 50 {
vinbel93 0:ac5e42371639 51 LPC_PINCON->PINSEL0 |= (3 << 12); // P0.6 = MAT2.0
vinbel93 0:ac5e42371639 52
vinbel93 1:f212b6676849 53 initTimer();
vinbel93 3:3ffa14e75b8a 54
vinbel93 3:3ffa14e75b8a 55 while (true)
vinbel93 0:ac5e42371639 56 {
vinbel93 6:3181f546e812 57 pc.printf("%i", decode(in.read(), clockTick));
vinbel93 6:3181f546e812 58 wait(0.2);
vinbel93 0:ac5e42371639 59 }
vinbel93 0:ac5e42371639 60 }