APP 4
Dependencies: mbed CRC16 mbed-rtos
APP.cpp@8:60499583959f, 2016-02-21 (annotated)
- Committer:
- manl2003
- Date:
- Sun Feb 21 18:58:52 2016 +0000
- Revision:
- 8:60499583959f
- Parent:
- 7:733d500dbe5c
- Parent:
- 6:3181f546e812
- Child:
- 9:b937f9c6d682
- Child:
- 10:51ee22e230c7
asddd
Who changed what in which revision?
User | Revision | Line number | New 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 | 0:ac5e42371639 | 37 | |
manl2003 | 7:733d500dbe5c | 38 | void initTimers() |
vinbel93 | 0:ac5e42371639 | 39 | { |
manl2003 | 7:733d500dbe5c | 40 | //Timer 2 (match) |
vinbel93 | 0:ac5e42371639 | 41 | LPC_SC->PCLKSEL1 |= (1 << 12); // pclk = cclk timer2 |
vinbel93 | 0:ac5e42371639 | 42 | LPC_SC->PCONP |= (1 << 22); // timer2 power on |
manl2003 | 8:60499583959f | 43 | LPC_TIM2->MR0 = CLOCKS_TO_SECOND / 10; // 100 ms |
vinbel93 | 3:3ffa14e75b8a | 44 | LPC_TIM2->MCR = 3; // interrupt and reset control |
vinbel93 | 3:3ffa14e75b8a | 45 | // Interrupt & reset timer2 on match |
manl2003 | 8:60499583959f | 46 | LPC_TIM2->EMR = (2 << 4); // toggle |
vinbel93 | 0:ac5e42371639 | 47 | NVIC_EnableIRQ(TIMER2_IRQn); // enable timer2 interrupt |
vinbel93 | 0:ac5e42371639 | 48 | LPC_TIM2->TCR = 1; // enable Timer2 |
manl2003 | 7:733d500dbe5c | 49 | |
manl2003 | 7:733d500dbe5c | 50 | //Timer 1 (cap) |
manl2003 | 7:733d500dbe5c | 51 | LPC_SC->PCLKSEL1 |= (1 << 4); // pclk = cclk timer2 |
manl2003 | 7:733d500dbe5c | 52 | LPC_SC->PCONP |= (1 << 2); // timer1 power on |
manl2003 | 8:60499583959f | 53 | LPC_TIM1->MR0 = CLOCKS_TO_SECOND / 10; // 100 ms |
manl2003 | 7:733d500dbe5c | 54 | LPC_TIM1->MCR = 3; // interrupt and reset control |
manl2003 | 7:733d500dbe5c | 55 | // Interrupt & reset timer1 on match |
manl2003 | 7:733d500dbe5c | 56 | NVIC_EnableIRQ(TIMER1_IRQn); // enable timer1 interrupt |
manl2003 | 7:733d500dbe5c | 57 | LPC_TIM1->TCR = 1; // enable Timer1 |
manl2003 | 8:60499583959f | 58 | |
vinbel93 | 0:ac5e42371639 | 59 | } |
vinbel93 | 0:ac5e42371639 | 60 | |
vinbel93 | 1:f212b6676849 | 61 | int main() |
vinbel93 | 0:ac5e42371639 | 62 | { |
vinbel93 | 0:ac5e42371639 | 63 | LPC_PINCON->PINSEL0 |= (3 << 12); // P0.6 = MAT2.0 |
manl2003 | 8:60499583959f | 64 | initTimers(); |
vinbel93 | 3:3ffa14e75b8a | 65 | |
vinbel93 | 3:3ffa14e75b8a | 66 | while (true) |
vinbel93 | 0:ac5e42371639 | 67 | { |
vinbel93 | 6:3181f546e812 | 68 | pc.printf("%i", decode(in.read(), clockTick)); |
vinbel93 | 6:3181f546e812 | 69 | wait(0.2); |
vinbel93 | 0:ac5e42371639 | 70 | } |
vinbel93 | 0:ac5e42371639 | 71 | } |