123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- #include "ch.h"
- #include "hal.h"
- static virtual_timer_t vt1, vt2;
- static void restart(void *p) {
- (void)p;
- chSysLockFromISR();
- uartStartSendI(&UARTD2, 14, "Hello World!\r\n");
- chSysUnlockFromISR();
- }
- static void ledoff(void *p) {
- (void)p;
- palSetPad(IOPORT3, GPIOC_LED);
- }
- static void txend1(UARTDriver *uartp) {
- (void)uartp;
- palClearPad(IOPORT3, GPIOC_LED);
- }
- static void txend2(UARTDriver *uartp) {
- (void)uartp;
- palSetPad(IOPORT3, GPIOC_LED);
- chSysLockFromISR();
- chVTResetI(&vt1);
- chVTDoSetI(&vt1, TIME_MS2I(5000), restart, NULL);
- chSysUnlockFromISR();
- }
- static void rxerr(UARTDriver *uartp, uartflags_t e) {
- (void)uartp;
- (void)e;
- }
- static void rxchar(UARTDriver *uartp, uint16_t c) {
- (void)uartp;
- (void)c;
-
- palClearPad(IOPORT3, GPIOC_LED);
- chSysLockFromISR();
- chVTResetI(&vt2);
- chVTDoSetI(&vt2, TIME_MS2I(200), ledoff, NULL);
- chSysUnlockFromISR();
- }
- static void rxend(UARTDriver *uartp) {
- (void)uartp;
- }
- static UARTConfig uart_cfg_1 = {
- txend1,
- txend2,
- rxend,
- rxchar,
- rxerr,
- 38400,
- 0,
- USART_CR2_LINEN,
- 0
- };
- int main(void) {
-
- halInit();
- chSysInit();
-
- uartStart(&UARTD2, &uart_cfg_1);
-
- uartStartSend(&UARTD2, 13, "Starting...\r\n");
-
- while (true) {
- chThdSleepMilliseconds(500);
- }
- return 0;
- }
|