Rev 3 | Rev 6 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 2 | mjames | 1 | /* |
| 2 | ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010, |
||
| 3 | 2011,2012 Giovanni Di Sirio. |
||
| 4 | |||
| 5 | This file is part of ChibiOS/RT. |
||
| 6 | |||
| 7 | ChibiOS/RT is free software; you can redistribute it and/or modify |
||
| 8 | it under the terms of the GNU General Public License as published by |
||
| 9 | the Free Software Foundation; either version 3 of the License, or |
||
| 10 | (at your option) any later version. |
||
| 11 | |||
| 12 | ChibiOS/RT is distributed in the hope that it will be useful, |
||
| 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
| 15 | GNU General Public License for more details. |
||
| 16 | |||
| 17 | You should have received a copy of the GNU General Public License |
||
| 18 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
||
| 19 | |||
| 20 | --- |
||
| 21 | |||
| 22 | A special exception to the GPL can be applied should you wish to distribute |
||
| 23 | a combined work that includes ChibiOS/RT, without being obliged to provide |
||
| 24 | the source code for any proprietary components. See the file exception.txt |
||
| 25 | for full details of how and when the exception can be applied. |
||
| 26 | */ |
||
| 27 | |||
| 28 | #include <string.h> |
||
| 29 | |||
| 30 | #include "ch.h" |
||
| 31 | #include "hal.h" |
||
| 32 | #include "test.h" |
||
| 33 | #include "shell.h" |
||
| 34 | #include "evtimer.h" |
||
| 35 | #include "chprintf.h" |
||
| 36 | |||
| 37 | |||
| 5 | mjames | 38 | #include "ap_math.h" |
| 2 | mjames | 39 | #include "hardware.h" |
| 3 | mjames | 40 | #include "spiInterface.h" |
| 41 | #include "SSD1306.h" |
||
| 2 | mjames | 42 | |
| 43 | |||
| 44 | /*===========================================================================*/ |
||
| 45 | /* Command line related. */ |
||
| 46 | /*===========================================================================*/ |
||
| 47 | |||
| 48 | #define SHELL_WA_SIZE THD_WA_SIZE(2048) |
||
| 49 | #define TEST_WA_SIZE THD_WA_SIZE(256) |
||
| 50 | |||
| 51 | static void cmd_mem(BaseChannel *chp, int argc, char *argv[]) { |
||
| 52 | size_t n, size; |
||
| 53 | |||
| 54 | (void) argv; |
||
| 55 | if (argc > 0) { |
||
| 56 | chprintf(chp, "Usage: mem\r\n"); |
||
| 57 | return; |
||
| 58 | } |
||
| 59 | n = chHeapStatus(NULL, &size); |
||
| 60 | chprintf(chp, "core free memory : %u bytes\r\n", chCoreStatus()); |
||
| 61 | chprintf(chp, "heap fragments : %u\r\n", n); |
||
| 62 | chprintf(chp, "heap free total : %u bytes\r\n", size); |
||
| 63 | } |
||
| 64 | |||
| 65 | static void cmd_threads(BaseChannel *chp, int argc, char *argv[]) { |
||
| 66 | static const char *states[] = { THD_STATE_NAMES }; |
||
| 67 | Thread *tp; |
||
| 68 | |||
| 69 | (void) argv; |
||
| 70 | if (argc > 0) { |
||
| 71 | chprintf(chp, "Usage: threads\r\n"); |
||
| 72 | return; |
||
| 73 | } |
||
| 74 | chprintf(chp, " addr stack prio refs state time\r\n"); |
||
| 75 | tp = chRegFirstThread(); |
||
| 76 | do { |
||
| 77 | chprintf(chp, "%.8lx %.8lx %4lu %4lu %9s %lu\r\n", (uint32_t) tp, |
||
| 78 | (uint32_t) tp->p_ctx.r13, (uint32_t) tp->p_prio, |
||
| 79 | (uint32_t)(tp->p_refs - 1), states[tp->p_state], |
||
| 80 | (uint32_t) tp->p_time); |
||
| 81 | tp = chRegNextThread(tp); |
||
| 82 | } while (tp != NULL); |
||
| 83 | } |
||
| 84 | |||
| 85 | static void cmd_test(BaseChannel *chp, int argc, char *argv[]) { |
||
| 86 | Thread *tp; |
||
| 87 | |||
| 88 | (void) argv; |
||
| 89 | if (argc > 0) { |
||
| 90 | chprintf(chp, "Usage: test\r\n"); |
||
| 91 | return; |
||
| 92 | } |
||
| 93 | tp = chThdCreateFromHeap(NULL, TEST_WA_SIZE, chThdGetPriority(), TestThread, |
||
| 94 | chp); |
||
| 95 | if (tp == NULL) { |
||
| 96 | chprintf(chp, "out of memory\r\n"); |
||
| 97 | return; |
||
| 98 | } |
||
| 99 | chThdWait(tp); |
||
| 100 | } |
||
| 101 | |||
| 102 | static const ShellCommand commands[] = { { "mem", cmd_mem }, { "threads", |
||
| 103 | cmd_threads }, { "test", cmd_test }, { NULL, NULL } }; |
||
| 104 | |||
| 105 | static const ShellConfig shell_cfg1 = { (BaseChannel *) &SD2, commands }; |
||
| 106 | |||
| 107 | /* |
||
| 108 | * Red LEDs blinker thread, times are in milliseconds. |
||
| 109 | */ |
||
| 110 | static WORKING_AREA(waThread1, 128); |
||
| 111 | static msg_t Thread1(void *arg) { |
||
| 112 | |||
| 113 | (void) arg; |
||
| 114 | chRegSetThreadName("blinker"); |
||
| 115 | while (TRUE) { |
||
| 5 | mjames | 116 | palClearPad(GPIOA, GPIOA_STROBE); |
| 117 | chThdSleep(1); |
||
| 118 | palSetPad(GPIOA, GPIOA_STROBE); |
||
| 119 | chThdSleepMilliseconds(50); |
||
| 2 | mjames | 120 | } |
| 121 | return 0; |
||
| 122 | } |
||
| 123 | |||
| 124 | /* |
||
| 125 | * Application entry point. |
||
| 126 | */ |
||
| 127 | int main(void) { |
||
| 128 | Thread *shelltp = NULL; |
||
| 129 | // struct EventListener el0, el1; |
||
| 130 | |||
| 131 | /* |
||
| 132 | * System initializations. |
||
| 133 | * - HAL initialization, this also initializes the configured device drivers |
||
| 134 | * and performs the board-specific initializations. |
||
| 135 | * - Kernel initialization, the main() function becomes a thread and the |
||
| 136 | * RTOS is active. |
||
| 137 | */ |
||
| 138 | halInit(); |
||
| 139 | chSysInit(); |
||
| 140 | |||
| 141 | /* |
||
| 142 | * Activates the serial driver 2 using the driver default configuration. |
||
| 143 | */ |
||
| 144 | sdStart(&SD2, NULL); |
||
| 145 | |||
| 146 | /* |
||
| 147 | * Shell manager initialization. |
||
| 148 | */ |
||
| 149 | shellInit(); |
||
| 150 | |||
| 5 | mjames | 151 | ap_init(); |
| 3 | mjames | 152 | |
| 5 | mjames | 153 | |
| 154 | /* |
||
| 155 | * Creates the blinker thread. |
||
| 156 | */ |
||
| 157 | chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL); |
||
| 158 | |||
| 3 | mjames | 159 | /* start the SPI hardware for display */ |
| 160 | ssd1306spiInit(); |
||
| 161 | |||
| 162 | ssd1306_begin( SSD1306_SWITCHCAPVCC, 0) ; |
||
| 163 | |||
| 164 | int x = 0; |
||
| 165 | while(1) |
||
| 166 | { |
||
| 167 | /* initialise the display */ |
||
| 168 | clearDisplay(); |
||
| 169 | |||
| 170 | dim(x); |
||
| 5 | mjames | 171 | font_gotoxy(0,0); |
| 172 | font_puts("count"); |
||
| 173 | font_sig_digits(12, 0,1,2, x); |
||
| 3 | mjames | 174 | |
| 5 | mjames | 175 | print_digits(64, 32, 4,2, 10000-x); |
| 3 | mjames | 176 | |
| 177 | |||
| 178 | |||
| 179 | display(); |
||
| 5 | mjames | 180 | // |
| 181 | // invertDisplay(x & 32); |
||
| 3 | mjames | 182 | |
| 5 | mjames | 183 | chThdSleep(MS2ST(10)); |
| 3 | mjames | 184 | |
| 5 | mjames | 185 | if (x++ == 10000) |
| 186 | x=0; |
||
| 3 | mjames | 187 | } |
| 188 | |||
| 2 | mjames | 189 | |
| 190 | /* |
||
| 191 | * Normal main() thread activity, in this demo it does nothing except |
||
| 192 | * sleeping in a loop and listen for events. |
||
| 193 | */ |
||
| 194 | while (TRUE) { |
||
| 195 | if (!shelltp) |
||
| 196 | shelltp = shellCreate(&shell_cfg1, SHELL_WA_SIZE, NORMALPRIO); |
||
| 197 | else if (chThdTerminated(shelltp)) { |
||
| 198 | chThdRelease(shelltp); /* Recovers memory of the previous shell. */ |
||
| 199 | shelltp = NULL; /* Triggers spawning of a new shell. */ |
||
| 200 | } |
||
| 201 | chThdSleep(MS2ST(100)); |
||
| 202 | // chEvtDispatch(evhndl, chEvtWaitOne(ALL_EVENTS)); |
||
| 203 | } |
||
| 204 | return 0; |
||
| 205 | } |