v0.1 board believed to be reading Vbat, Pressure, and X/Y/Z correctly now,
[fw/openalt] / rtc / rtcISR.c
1 #include <stdlib.h>
2
3 //
4 // Scheduler includes
5 //
6 #include "FreeRTOS.h"
7 #include "task.h"
8 #include "queue.h"
9
10 #include "../uart/uart.h"
11 #include "../usbser/usbser.h"
12 #include "rtcISR.h"
13 #include "rtc.h"
14
15 //
16 //
17 //
18 static xQueueHandle consoleQueue = NULL;
19
20 //
21 //
22 //
23 void rtcISRInit (void)
24 {
25 #if defined CFG_CONSOLE_USB
26   usbserGetRxQueue (&consoleQueue);
27 #elif defined CFG_CONSOLE_UART0
28   uart0GetRxQueue (&consoleQueue);
29 #elif defined CFG_CONSOLE_UART1
30   uart1GetRxQueue (&consoleQueue);
31 #else
32 #error "Eeek!  No console devices defined!"
33 #endif
34 }
35
36 //
37 //
38 //
39 void rtcISR (void) __attribute__ ((naked));
40 void rtcISR (void)
41 {
42         portENTER_SWITCHING_ISR ();
43
44   portBASE_TYPE taskWoken = pdFALSE;
45
46   RTC_CCR = (RTC_CCR_CLKEN | RTC_CCR_CLKSRC);
47   SCB_PCONP |= SCB_PCONP_PCRTC;
48
49   if (RTC_ILR & RTC_ILR_RTCCIF)
50   {
51     U8 c = 0xff;
52
53     if (consoleQueue && xQueueSendFromISR (consoleQueue, &c, (portBASE_TYPE) pdFALSE)) 
54       taskWoken = pdTRUE;
55
56           RTC_ILR = RTC_ILR_RTCCIF;
57   }
58
59   if (RTC_ILR & RTC_ILR_RTCALF)
60   {
61     U8 c = 0xfe;
62
63     if (consoleQueue && xQueueSendFromISR (consoleQueue, &c, (portBASE_TYPE) pdFALSE)) 
64       taskWoken = pdTRUE;
65
66           RTC_ILR = RTC_ILR_RTCALF;
67   }
68
69   VIC_VectAddr = (unsigned portLONG) 0;
70
71   RTC_CCR = (RTC_CCR_CLKEN | RTC_CCR_CLKSRC);
72   SCB_PCONP &= ~SCB_PCONP_PCRTC;
73
74         portEXIT_SWITCHING_ISR (taskWoken);
75 }