Subversion Repositories chibiosIgnition

Rev

Go to most recent revision | Details | 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
 
38
#include "hardware.h"
3 mjames 39
#include "spiInterface.h"
40
#include "SSD1306.h"
2 mjames 41
 
42
 
43
/*===========================================================================*/
44
/* Command line related.                                                     */
45
/*===========================================================================*/
46
 
47
#define SHELL_WA_SIZE   THD_WA_SIZE(2048)
48
#define TEST_WA_SIZE    THD_WA_SIZE(256)
49
 
50
static void cmd_mem(BaseChannel *chp, int argc, char *argv[]) {
51
        size_t n, size;
52
 
53
        (void) argv;
54
        if (argc > 0) {
55
                chprintf(chp, "Usage: mem\r\n");
56
                return;
57
        }
58
        n = chHeapStatus(NULL, &size);
59
        chprintf(chp, "core free memory : %u bytes\r\n", chCoreStatus());
60
        chprintf(chp, "heap fragments   : %u\r\n", n);
61
        chprintf(chp, "heap free total  : %u bytes\r\n", size);
62
}
63
 
64
static void cmd_threads(BaseChannel *chp, int argc, char *argv[]) {
65
        static const char *states[] = { THD_STATE_NAMES };
66
        Thread *tp;
67
 
68
        (void) argv;
69
        if (argc > 0) {
70
                chprintf(chp, "Usage: threads\r\n");
71
                return;
72
        }
73
        chprintf(chp, "    addr    stack prio refs     state time\r\n");
74
        tp = chRegFirstThread();
75
        do {
76
                chprintf(chp, "%.8lx %.8lx %4lu %4lu %9s %lu\r\n", (uint32_t) tp,
77
                                (uint32_t) tp->p_ctx.r13, (uint32_t) tp->p_prio,
78
                                (uint32_t)(tp->p_refs - 1), states[tp->p_state],
79
                                (uint32_t) tp->p_time);
80
                tp = chRegNextThread(tp);
81
        } while (tp != NULL);
82
}
83
 
84
static void cmd_test(BaseChannel *chp, int argc, char *argv[]) {
85
        Thread *tp;
86
 
87
        (void) argv;
88
        if (argc > 0) {
89
                chprintf(chp, "Usage: test\r\n");
90
                return;
91
        }
92
        tp = chThdCreateFromHeap(NULL, TEST_WA_SIZE, chThdGetPriority(), TestThread,
93
                        chp);
94
        if (tp == NULL) {
95
                chprintf(chp, "out of memory\r\n");
96
                return;
97
        }
98
        chThdWait(tp);
99
}
100
 
101
static const ShellCommand commands[] = { { "mem", cmd_mem }, { "threads",
102
                cmd_threads }, { "test", cmd_test }, { NULL, NULL } };
103
 
104
static const ShellConfig shell_cfg1 = { (BaseChannel *) &SD2, commands };
105
 
106
/*
107
 * Red LEDs blinker thread, times are in milliseconds.
108
 */
109
static WORKING_AREA(waThread1, 128);
110
static msg_t Thread1(void *arg) {
111
 
112
        (void) arg;
113
        chRegSetThreadName("blinker");
114
        while (TRUE) {
115
                palTogglePad(GPIOC, GPIOC_LED);
116
                chThdSleepMilliseconds(500);
117
        }
118
        return 0;
119
}
120
 
121
/*
122
 * Application entry point.
123
 */
124
int main(void) {
125
        Thread *shelltp = NULL;
126
//  struct EventListener el0, el1;
127
 
128
        /*
129
         * System initializations.
130
         * - HAL initialization, this also initializes the configured device drivers
131
         *   and performs the board-specific initializations.
132
         * - Kernel initialization, the main() function becomes a thread and the
133
         *   RTOS is active.
134
         */
135
        halInit();
136
        chSysInit();
137
 
138
        /*
139
         * Activates the serial driver 2 using the driver default configuration.
140
         */
141
        sdStart(&SD2, NULL);
142
 
143
        /*
144
         * Shell manager initialization.
145
         */
146
        shellInit();
147
 
3 mjames 148
 
149
        /* start the SPI hardware for display */
150
        ssd1306spiInit();
151
 
152
        ssd1306_begin( SSD1306_SWITCHCAPVCC, 0) ;
153
 
154
                int x = 0;
155
while(1)
156
{
157
        /* initialise the display */
158
   if(x==0)
159
        clearDisplay();
160
 
161
    dim(x);
162
 
163
 
164
         font_puts("Hello !\r\nDisplay\r\n");
165
 
166
          drawLine(x, 0, x, 63 , 1);
167
          x++;
168
          if (x==128)
169
                  x=0;
170
 
171
 
172
         display();
173
 
174
         invertDisplay(x & 32);
175
 
176
         chThdSleep(MS2ST(100));
177
}
178
 
179
         /*
2 mjames 180
         * Creates the blinker thread.
181
         */
182
        chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);
183
 
184
        /*
185
         * Normal main() thread activity, in this demo it does nothing except
186
         * sleeping in a loop and listen for events.
187
         */
188
        while (TRUE) {
189
                if (!shelltp)
190
                        shelltp = shellCreate(&shell_cfg1, SHELL_WA_SIZE, NORMALPRIO);
191
                else if (chThdTerminated(shelltp)) {
192
                        chThdRelease(shelltp); /* Recovers memory of the previous shell.   */
193
                        shelltp = NULL; /* Triggers spawning of a new shell.        */
194
                }
195
                chThdSleep(MS2ST(100));
196
                //   chEvtDispatch(evhndl, chEvtWaitOne(ALL_EVENTS));
197
        }
198
        return 0;
199
}