Rev 3 | Rev 8 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
3 | mjames | 1 | /* |
2 | * misc.c |
||
3 | * |
||
4 | * Created on: 21 Sep 2016 |
||
5 | * Author: Mike |
||
6 | */ |
||
7 | |||
8 | |||
9 | void _init(void) |
||
10 | { |
||
11 | |||
12 | } |
||
6 | mjames | 13 | |
14 | |||
15 | |||
16 | #if OLD_ENGINEBAY |
||
17 | //----------------------------------------------------------- |
||
18 | // This is the 10Hz timer |
||
19 | |||
20 | void interrupt TimerISR1(void) { |
||
21 | TimerFlag = 1; |
||
22 | if (NoSerialInCTR < 5) { |
||
23 | NoSerialInCTR++; |
||
24 | if (NoSerialInCTR == 5) { |
||
25 | NoSerialIn = 1; |
||
26 | } |
||
27 | } |
||
28 | } |
||
29 | //----------------------------------------------------------- |
||
30 | |||
31 | |||
32 | volatile unsigned long RPM_Time[RPM_LIMIT]; |
||
33 | volatile unsigned long RPM_Count; // incremented every reading |
||
34 | |||
35 | void TimerISR0(void) { |
||
36 | // check the listing |
||
37 | asm volatile ("STMDB SP!, {r0-r4} "); |
||
38 | // sort out the captures |
||
39 | int stat = REG(TIMER0_IR); |
||
40 | if (stat & (1 << 4)) //CR0 |
||
41 | { |
||
42 | RPM_Time[RPM_Count++] = REG(TIMER0_CR0); |
||
43 | if (RPM_Count == RPM_LIMIT) { |
||
44 | RPM_Count = 0; |
||
45 | } |
||
46 | } |
||
47 | if (stat & (1 << 5)) //CR1 |
||
48 | { |
||
49 | // TDC_Time = REG(TIMER0_CR1); |
||
50 | // TDC_Count++; |
||
51 | } |
||
52 | |||
53 | REG(TIMER0_IR) = stat; // clear the interrupts just handled. |
||
54 | REG(VICVectAddr) = 0; // reset the VIC |
||
55 | asm volatile ("LDMIA SP!, {r0-r4} "); |
||
56 | asm volatile ("SUBS PC,lr,#4"); |
||
57 | } |
||
58 | |||
59 | //----------------------------------------------------------- |
||
60 | // UART management |
||
61 | // serial counter |
||
62 | #define THRE (1<<6) |
||
63 | #define RDR (1<<0) |
||
64 | #define BUFFSIZ 256 |
||
65 | |||
66 | volatile char txbuff[BUFFSIZ]; |
||
67 | volatile int txptr = 0; |
||
68 | volatile int txcnt = 0; |
||
69 | |||
70 | volatile char rxbuff[BUFFSIZ]; |
||
71 | volatile int rxptr = 0; |
||
72 | volatile int rxcnt = 0; |
||
73 | |||
74 | void Uart0ISR(void) __attribute__((naked)); |
||
75 | void Uart0ISR(void) __attribute__((noinline)); |
||
76 | void Uart0ISR(void) { |
||
77 | asm volatile ("STMDB SP!, {r0-r3} "); |
||
78 | int stat; |
||
79 | while (!((stat = REG(UART0_IIR)) & 1)) { // LSbit is inactive |
||
80 | switch (stat & 0x0E) { |
||
81 | case 4: |
||
82 | case 12: { |
||
83 | char c = REG(UART0_RBR); |
||
84 | |||
85 | NoSerialIn = NoSerialInCTR = 0; |
||
86 | |||
87 | if (rxcnt < (BUFFSIZ - 1)) { |
||
88 | rxbuff[(rxptr + rxcnt) % BUFFSIZ] = c; |
||
89 | rxcnt++; |
||
90 | } |
||
91 | } |
||
92 | break; |
||
93 | case 2: { |
||
94 | if (txcnt > 0) { |
||
95 | REG(UART0_THR) = txbuff[txptr]; |
||
96 | txcnt--; |
||
97 | txptr++; |
||
98 | txptr %= BUFFSIZ; |
||
99 | } else { |
||
100 | REG(UART0_IER) &= ~(1 << 1); // disable TX |
||
101 | } |
||
102 | } |
||
103 | break; |
||
104 | } |
||
105 | } |
||
106 | REG(VICVectAddr) = 0; // reset the VIC |
||
107 | asm volatile ("LDMIA SP!, {r0-r3} "); |
||
108 | asm volatile ("SUBS PC,lr,#4"); |
||
109 | } |
||
110 | |||
111 | int my_putchar(int c) { |
||
112 | int rc = 0; |
||
113 | { |
||
114 | STI; |
||
115 | if (!(REG(UART0_IER) & (1 << 1))) { |
||
116 | REG(UART0_IER) |= (1 << 1); |
||
117 | REG(UART0_THR) = c; |
||
118 | rc=1; |
||
119 | } else { |
||
120 | |||
121 | if (txcnt < (BUFFSIZ - 1)) { |
||
122 | txbuff[(txptr + txcnt) % BUFFSIZ] = c; |
||
123 | txcnt++; |
||
124 | rc = 1; |
||
125 | } |
||
126 | } |
||
127 | CLI; |
||
128 | } |
||
129 | return rc; |
||
130 | } |
||
131 | |||
132 | int my_getchar(void) { |
||
133 | |||
134 | int c = -1; |
||
135 | STI; |
||
136 | if (rxcnt) { |
||
137 | c = rxbuff[rxptr]; |
||
138 | rxcnt--; |
||
139 | rxptr++; |
||
140 | rxptr %= BUFFSIZ; |
||
141 | } |
||
142 | CLI; |
||
143 | return c; |
||
144 | } |
||
145 | |||
146 | |||
147 | |||
148 | #endif |