Created
May 17, 2011 00:02
-
-
Save adamgreig/975629 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* A basic ChibiOS app. | |
* Copyright Adam Greig 2011. | |
* Released under the GNU GPL v3. Insert GPL boilerplate here. | |
*/ | |
#include "ch.h" | |
#include "hal.h" | |
#include "test.h" | |
/* | |
* LED control server. | |
*/ | |
static WORKING_AREA(waLEDS, 128); | |
static msg_t LEDS(void * arg) { | |
Mailbox* mbox = (Mailbox *)arg; | |
msg_t msg, result; | |
while(TRUE) { | |
result = chMBFetch(mbox, &msg, TIME_INFINITE); | |
if(result == RDY_OK) { | |
if(msg == 1) | |
palSetPad(IOPORT1, GPIOA_LED); | |
else if(msg == 0) | |
palClearPad(IOPORT1, GPIOA_LED); | |
} | |
} | |
return 0; | |
} | |
/* | |
* LED request client. | |
*/ | |
static WORKING_AREA(waLEDC, 128); | |
static msg_t LEDC(void * arg) { | |
Mailbox* mbox = (Mailbox *)arg; | |
while(TRUE) { | |
chMBPost(mbox, 0, TIME_INFINITE); | |
chThdSleepMilliseconds(500); | |
chMBPost(mbox, 1, TIME_INFINITE); | |
chThdSleepMilliseconds(500); | |
} | |
return 0; | |
} | |
/* | |
* 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(); | |
/* | |
* Activates the serial driver 1 using the driver default configuration. | |
*/ | |
sdStart(&SD1, NULL); | |
/* | |
* Create a mailbox for IPC. | |
*/ | |
Mailbox mbox; | |
msg_t mbox_buffer[3]; | |
chMBInit(&mbox, mbox_buffer, 3); | |
/* | |
* Create the LED server and client threads | |
*/ | |
chThdCreateStatic(waLEDS, sizeof(waLEDS), NORMALPRIO, LEDS, (void *)&mbox); | |
chThdCreateStatic(waLEDC, sizeof(waLEDC), NORMALPRIO, LEDC, (void *)&mbox); | |
/* | |
* Normal main() thread activity, in this demo it does nothing | |
*/ | |
while (TRUE) { | |
chThdSleepMilliseconds(500); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment