2012-10-22 17:46:59 +00:00
|
|
|
/*
|
2013-03-30 10:32:37 +00:00
|
|
|
ChibiOS/RT - Copyright (C) 2006-2013 Giovanni Di Sirio
|
2012-10-22 17:46:59 +00:00
|
|
|
|
2013-03-30 10:32:37 +00:00
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
2012-10-22 17:46:59 +00:00
|
|
|
|
2013-03-30 10:32:37 +00:00
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
2012-10-22 17:46:59 +00:00
|
|
|
|
2013-03-30 10:32:37 +00:00
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
2012-10-22 17:46:59 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "ch.h"
|
|
|
|
#include "hal.h"
|
2012-12-04 15:02:49 +00:00
|
|
|
#include "test.h"
|
2012-10-22 17:46:59 +00:00
|
|
|
|
|
|
|
/*
|
2013-09-13 13:45:42 +00:00
|
|
|
* Blinker thread #1.
|
2012-10-22 17:46:59 +00:00
|
|
|
*/
|
2013-09-13 11:24:38 +00:00
|
|
|
static THD_WORKING_AREA(waThread1, 128);
|
|
|
|
static THD_FUNCTION(Thread1, arg) {
|
2012-10-22 17:46:59 +00:00
|
|
|
|
|
|
|
(void)arg;
|
2013-09-13 13:45:42 +00:00
|
|
|
|
2012-10-22 17:46:59 +00:00
|
|
|
chRegSetThreadName("blinker");
|
2013-09-05 10:34:09 +00:00
|
|
|
while (true) {
|
2012-12-04 13:03:14 +00:00
|
|
|
palSetPad(GPIOE, GPIOE_LED3_RED);
|
2012-12-05 11:19:22 +00:00
|
|
|
chThdSleepMilliseconds(125);
|
2012-12-04 13:03:14 +00:00
|
|
|
palClearPad(GPIOE, GPIOE_LED3_RED);
|
2012-12-05 11:19:22 +00:00
|
|
|
chThdSleepMilliseconds(125);
|
2012-12-04 13:03:14 +00:00
|
|
|
palSetPad(GPIOE, GPIOE_LED7_GREEN);
|
2012-12-05 11:19:22 +00:00
|
|
|
chThdSleepMilliseconds(125);
|
2012-12-04 13:03:14 +00:00
|
|
|
palClearPad(GPIOE, GPIOE_LED7_GREEN);
|
2012-12-05 11:19:22 +00:00
|
|
|
chThdSleepMilliseconds(125);
|
2012-12-04 13:03:14 +00:00
|
|
|
palSetPad(GPIOE, GPIOE_LED10_RED);
|
2012-12-05 11:19:22 +00:00
|
|
|
chThdSleepMilliseconds(125);
|
2012-12-04 13:03:14 +00:00
|
|
|
palClearPad(GPIOE, GPIOE_LED10_RED);
|
2012-12-05 11:19:22 +00:00
|
|
|
chThdSleepMilliseconds(125);
|
2012-12-04 13:03:14 +00:00
|
|
|
palSetPad(GPIOE, GPIOE_LED6_GREEN);
|
2012-12-05 11:19:22 +00:00
|
|
|
chThdSleepMilliseconds(125);
|
2012-12-04 13:03:14 +00:00
|
|
|
palClearPad(GPIOE, GPIOE_LED6_GREEN);
|
2012-12-05 11:19:22 +00:00
|
|
|
chThdSleepMilliseconds(125);
|
2012-10-22 17:46:59 +00:00
|
|
|
}
|
|
|
|
}
|
2013-07-23 13:51:02 +00:00
|
|
|
|
2013-09-13 11:24:38 +00:00
|
|
|
/*
|
2013-09-13 13:45:42 +00:00
|
|
|
* Blinker thread #2.
|
2013-09-13 11:24:38 +00:00
|
|
|
*/
|
|
|
|
static THD_WORKING_AREA(waThread2, 128);
|
|
|
|
static THD_FUNCTION(Thread2, arg) {
|
2013-07-23 13:51:02 +00:00
|
|
|
|
|
|
|
(void)arg;
|
2013-09-13 13:45:42 +00:00
|
|
|
|
2013-09-13 11:24:38 +00:00
|
|
|
chRegSetThreadName("blinker");
|
2013-09-05 10:34:09 +00:00
|
|
|
while (true) {
|
2013-09-13 11:24:38 +00:00
|
|
|
chThdSleepMilliseconds(125);
|
|
|
|
palSetPad(GPIOE, GPIOE_LED5_ORANGE);
|
|
|
|
chThdSleepMilliseconds(125);
|
|
|
|
palClearPad(GPIOE, GPIOE_LED5_ORANGE);
|
|
|
|
chThdSleepMilliseconds(125);
|
|
|
|
palSetPad(GPIOE, GPIOE_LED9_BLUE);
|
|
|
|
chThdSleepMilliseconds(125);
|
|
|
|
palClearPad(GPIOE, GPIOE_LED9_BLUE);
|
|
|
|
chThdSleepMilliseconds(125);
|
|
|
|
palSetPad(GPIOE, GPIOE_LED8_ORANGE);
|
|
|
|
chThdSleepMilliseconds(125);
|
|
|
|
palClearPad(GPIOE, GPIOE_LED8_ORANGE);
|
|
|
|
chThdSleepMilliseconds(125);
|
2013-07-23 13:51:02 +00:00
|
|
|
palSetPad(GPIOE, GPIOE_LED4_BLUE);
|
2013-09-13 11:24:38 +00:00
|
|
|
chThdSleepMilliseconds(125);
|
2013-07-23 13:51:02 +00:00
|
|
|
palClearPad(GPIOE, GPIOE_LED4_BLUE);
|
|
|
|
}
|
|
|
|
}
|
2012-10-22 17:46:59 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Application entry point.
|
|
|
|
*/
|
|
|
|
int main(void) {
|
|
|
|
|
|
|
|
/*
|
|
|
|
* System initializations.
|
|
|
|
* - HAL initialization, this also initializes the configured device drivers
|
|
|
|
* and performs the board-specific initializations.
|
|
|
|
* - Kernel initialization, the main() function becomes a thread and the
|
|
|
|
* RTOS is active.
|
|
|
|
*/
|
|
|
|
halInit();
|
|
|
|
chSysInit();
|
|
|
|
|
2012-12-04 15:02:49 +00:00
|
|
|
/*
|
|
|
|
* Activates the serial driver 1 using the driver default configuration.
|
|
|
|
* PA9(TX) and PA10(RX) are routed to USART1.
|
|
|
|
*/
|
2013-08-08 12:22:21 +00:00
|
|
|
sdStart(&SD1, NULL);
|
|
|
|
palSetPadMode(GPIOA, 9, PAL_MODE_ALTERNATE(7));
|
|
|
|
palSetPadMode(GPIOA, 10, PAL_MODE_ALTERNATE(7));
|
2012-10-28 07:47:01 +00:00
|
|
|
|
2012-10-22 17:46:59 +00:00
|
|
|
/*
|
2013-09-30 09:08:18 +00:00
|
|
|
* Creates the example threads.
|
2012-10-22 17:46:59 +00:00
|
|
|
*/
|
2013-07-23 13:51:02 +00:00
|
|
|
chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO+1, Thread1, NULL);
|
2013-09-13 11:24:38 +00:00
|
|
|
chThdCreateStatic(waThread2, sizeof(waThread2), NORMALPRIO+1, Thread2, NULL);
|
2012-10-22 17:46:59 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Normal main() thread activity, in this demo it does nothing except
|
|
|
|
* sleeping in a loop and check the button state, when the button is
|
2012-10-28 07:47:01 +00:00
|
|
|
* pressed the test procedure is launched.
|
2012-10-22 17:46:59 +00:00
|
|
|
*/
|
|
|
|
while (TRUE) {
|
2013-08-08 12:22:21 +00:00
|
|
|
if (palReadPad(GPIOA, GPIOA_BUTTON))
|
|
|
|
TestThread(&SD1);
|
2012-10-22 17:46:59 +00:00
|
|
|
chThdSleepMilliseconds(500);
|
|
|
|
}
|
|
|
|
}
|