UCLA-EEM202A 2nd assignment. time synchronization

Dependencies:   mbed

Committer:
mohammmo
Date:
Thu Mar 06 07:52:19 2014 +0000
Revision:
0:4d75b473d9c9
Child:
1:3f76ed8cd999
failed PIT interrupt

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mohammmo 0:4d75b473d9c9 1 #include "mbed.h"
mohammmo 0:4d75b473d9c9 2
mohammmo 0:4d75b473d9c9 3 // Declare output LEDs
mohammmo 0:4d75b473d9c9 4 DigitalOut ledgreen(PTD5);
mohammmo 0:4d75b473d9c9 5 DigitalOut ledred(PTE29);
mohammmo 0:4d75b473d9c9 6
mohammmo 0:4d75b473d9c9 7 // Serial for debuggin purposes
mohammmo 0:4d75b473d9c9 8
mohammmo 0:4d75b473d9c9 9 void initialize_ticker();
mohammmo 0:4d75b473d9c9 10
mohammmo 0:4d75b473d9c9 11 int main() {
mohammmo 0:4d75b473d9c9 12 ledred = 1;
mohammmo 0:4d75b473d9c9 13 ledgreen = 0;
mohammmo 0:4d75b473d9c9 14 initialize_ticker();
mohammmo 0:4d75b473d9c9 15 while(1){
mohammmo 0:4d75b473d9c9 16
mohammmo 0:4d75b473d9c9 17 }
mohammmo 0:4d75b473d9c9 18 }
mohammmo 0:4d75b473d9c9 19
mohammmo 0:4d75b473d9c9 20 void flip() {
mohammmo 0:4d75b473d9c9 21 //clear interrupt
mohammmo 0:4d75b473d9c9 22 PIT->CHANNEL[1].TFLG |= PIT_TFLG_TIF_MASK;
mohammmo 0:4d75b473d9c9 23 ledgreen = !ledgreen;
mohammmo 0:4d75b473d9c9 24 ledred = !ledred;
mohammmo 0:4d75b473d9c9 25 }
mohammmo 0:4d75b473d9c9 26
mohammmo 0:4d75b473d9c9 27 void initialize_ticker(){
mohammmo 0:4d75b473d9c9 28 //set to zero to enable PIT
mohammmo 0:4d75b473d9c9 29 PIT->MCR = 0x00;
mohammmo 0:4d75b473d9c9 30 //clear interrup before enabling it
mohammmo 0:4d75b473d9c9 31 PIT->CHANNEL[1].TFLG |= PIT_TFLG_TIF_MASK;
mohammmo 0:4d75b473d9c9 32 PIT->CHANNEL[1].LDVAL = 0x00BEBC1F; //1 second
mohammmo 0:4d75b473d9c9 33 //enable interrup
mohammmo 0:4d75b473d9c9 34 PIT->CHANNEL[1].TCTRL |= PIT_TCTRL_TIE_MASK;
mohammmo 0:4d75b473d9c9 35 //enable interrtup
mohammmo 0:4d75b473d9c9 36 __enable_irq();
mohammmo 0:4d75b473d9c9 37 NVIC_SetVector(PIT_IRQn, (uint32_t)flip);
mohammmo 0:4d75b473d9c9 38 NVIC_EnableIRQ(PIT_IRQn);
mohammmo 0:4d75b473d9c9 39 //start timer
mohammmo 0:4d75b473d9c9 40 PIT->CHANNEL[1].TCTRL |= PIT_TCTRL_TEN_MASK;
mohammmo 0:4d75b473d9c9 41 }