Rev 8 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 8 | Rev 9 | ||
|---|---|---|---|
| Line 25... | Line 25... | ||
| 25 | for full details of how and when the exception can be applied. |
25 | for full details of how and when the exception can be applied. |
| 26 | */ |
26 | */ |
| 27 | 27 | ||
| 28 | #include <stdio.h> |
28 | #include <stdio.h> |
| 29 | #include <string.h> |
29 | #include <string.h> |
| - | 30 | #include <stdlib.h> |
|
| - | 31 | #include <math.h> |
|
| - | 32 | ||
| 30 | 33 | ||
| 31 | #include "ch.h" |
34 | #include "ch.h" |
| 32 | #include "hal.h" |
35 | #include "hal.h" |
| 33 | // #include "test.h" |
36 | // #include "test.h" |
| 34 | #include "shell.h" |
37 | #include "shell.h" |
| Line 38... | Line 41... | ||
| 38 | #include "shellCmds.h" |
41 | #include "shellCmds.h" |
| 39 | 42 | ||
| 40 | #include "ap_math.h" |
43 | #include "ap_math.h" |
| 41 | #include "spiInterface.h" |
44 | #include "spiInterface.h" |
| 42 | #include "SSD1306.h" |
45 | #include "SSD1306.h" |
| 43 | #include "font.h" |
46 | #include "Font.h" |
| 44 | 47 | ||
| 45 | static MUTEX_DECL(mutexDisplay); |
48 | static MUTEX_DECL(mutexDisplay); |
| 46 | 49 | ||
| 47 | /*===========================================================================*/ |
50 | /*===========================================================================*/ |
| 48 | /* Command line related. */ |
51 | /* Command line related. */ |
| Line 51... | Line 54... | ||
| 51 | #define SHELL_WA_SIZE THD_WORKING_AREA_SIZE(1024) |
54 | #define SHELL_WA_SIZE THD_WORKING_AREA_SIZE(1024) |
| 52 | #define TEST_WA_SIZE THD_WORKING_AREA_SIZE(256) |
55 | #define TEST_WA_SIZE THD_WORKING_AREA_SIZE(256) |
| 53 | 56 | ||
| 54 | #define RPM_ID 0x10d |
57 | #define RPM_ID 0x10d |
| 55 | 58 | ||
| - | 59 | // 1 megabit CAN |
|
| - | 60 | #define CAN_CONFIG1000 |
|
| 56 | 61 | ||
| 57 | /* |
62 | /* |
| 58 | * Internal loopback mode, 500KBaud, automatic wakeup, automatic recover |
63 | * Internal loopback mode, 500KBaud, automatic wakeup, automatic recover |
| 59 | * from abort mode. |
64 | * from abort mode. |
| 60 | */ |
65 | */ |
| 61 | 66 | ||
| 62 | // CAN_BTR_SJW(n), where n = SJW - 1 |
67 | // CAN_BTR_SJW(n), where n = SJW - 1 |
| 63 | // CAN_BTR_BRP(n), where n = prescaler - 1 |
68 | // CAN_BTR_BRP(n), where n = prescaler - 1 |
| 64 | // CAN_BTR_TS1(n), where n = Seg 1 - 1 |
69 | // CAN_BTR_TS1(n), where n = Seg 1 - 1 |
| 65 | // CAN_BTR_TS2(n), where n = Seg 2 - 1 |
70 | // CAN_BTR_TS2(n), where n = Seg 2 - 1 |
| 66 | - | ||
| - | 71 | #if defined CAN_CONFIG500 |
|
| 67 | static const CANConfig cancfg500 = { |
72 | static const CANConfig cancfg500 = { |
| 68 | CAN_MCR_ABOM | CAN_MCR_AWUM | CAN_MCR_TXFP, |
73 | CAN_MCR_ABOM | CAN_MCR_AWUM | CAN_MCR_TXFP, |
| 69 | CAN_BTR_LBKM | CAN_BTR_SJW(0) | CAN_BTR_TS2(2) | |
74 | CAN_BTR_LBKM | CAN_BTR_SJW(0) | CAN_BTR_TS2(2) | |
| 70 | CAN_BTR_TS1(3) | CAN_BTR_BRP(8)}; |
75 | CAN_BTR_TS1(3) | CAN_BTR_BRP(8)}; |
| 71 | - | ||
| - | 76 | #elif defined CAN_CONFIG1000 |
|
| 72 | static const CANConfig cancfg1000 = { |
77 | static const CANConfig cancfg1000 = { |
| 73 | CAN_MCR_ABOM | CAN_MCR_AWUM | CAN_MCR_TXFP, |
78 | CAN_MCR_ABOM | CAN_MCR_AWUM | CAN_MCR_TXFP, |
| 74 | CAN_BTR_LBKM | CAN_BTR_SJW(0) | CAN_BTR_TS2(2) | |
79 | CAN_BTR_LBKM | CAN_BTR_SJW(0) | CAN_BTR_TS2(2) | |
| 75 | CAN_BTR_TS1(4) | CAN_BTR_BRP(3)}; |
80 | CAN_BTR_TS1(4) | CAN_BTR_BRP(3)}; |
| 76 | 81 | #endif |
|
| 77 | static const ShellConfig shell_cfg1 = { |
82 | static const ShellConfig shell_cfg1 = { |
| 78 | (BaseSequentialStream *)&SD1, |
83 | (BaseSequentialStream *)&SD1, |
| 79 | shellCommands}; |
84 | shellCommands}; |
| 80 | //////// |
85 | //////// |
| 81 | // end of shell stuff |
86 | // end of shell stuff |
| Line 162... | Line 167... | ||
| 162 | // all this calculates minimum distance from |
167 | // all this calculates minimum distance from |
| 163 | // target or origin |
168 | // target or origin |
| 164 | int d1 = abs(count - origin); |
169 | int d1 = abs(count - origin); |
| 165 | int d2 = abs(count - target); |
170 | int d2 = abs(count - target); |
| 166 | // finally, minimum distance |
171 | // finally, minimum distance |
| 167 | int dist = min(d1,d2); |
172 | int dist = d1<d2 ? d1 : d2; |
| 168 | 173 | ||
| 169 | del = fast; |
174 | del = fast; |
| 170 | if (dist < range) // inside lower bound of distance |
175 | if (dist < range) // inside lower bound of distance |
| 171 | { |
176 | { |
| 172 | del = slow - dist; |
177 | del = slow - dist; |
| Line 312... | Line 317... | ||
| 312 | while (1) |
317 | while (1) |
| 313 | { |
318 | { |
| 314 | 319 | ||
| 315 | chThdSleepMilliseconds(100); |
320 | chThdSleepMilliseconds(100); |
| 316 | unsigned const SCALE = frac * 32 + 16; |
321 | unsigned const SCALE = frac * 32 + 16; |
| - | 322 | ++frac ; |
|
| 317 | frac = (++frac) % 10; |
323 | frac %= 10; |
| 318 | 324 | ||
| 319 | // read the dial |
325 | // read the dial |
| 320 | 326 | ||
| 321 | origin = count; |
327 | origin = count; |
| 322 | 328 | ||