/* * 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); /* * Starts the LED blinker thread. */ chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL); chnWrite(&SD1, (const uint8_t *)"Hello World!\r\n", 14); while(TRUE) { chThdSleepMilliseconds(1000); } }
void raw_hid_send( uint8_t *data, uint8_t length ) { // TODO: implement variable size packet if ( length != RAW_EPSIZE ) { return; } chnWrite(&drivers.raw_driver.driver, data, length); }
THD_FUNCTION(Thread3, arg) { (void)arg; /* * Activates the serial driver 1 using the driver default configuration. */ sdStart(&SD1, NULL); while (true) { chnWrite(&SD1, (const uint8_t *)"Hello World!\r\n", 14); chThdSleepMilliseconds(2000); } }
THD_FUNCTION(Thread2, arg) { (void)arg; /* * Activate the serial driver 0 using the driver default configuration. */ sdStart(&SD0, NULL); while (chnGetTimeout(&SD0, TIME_INFINITE)) { chnWrite(&SD0, (const uint8_t *)"Hello World!\r\n", 14); test_execute((void*)&SD0); chThdSleepMilliseconds(2000); } }
THD_FUNCTION(Thread3, arg) { (void)arg; /* * Activates the serial driver 1 using the driver default configuration. * PA9 and PA10 are routed to USART1. */ sdStart(&SD1, NULL); palSetPadMode(GPIOA, 9, PAL_MODE_ALTERNATE(1)); /* USART1 TX. */ palSetPadMode(GPIOA, 10, PAL_MODE_ALTERNATE(1)); /* USART1 RX. */ while (true) { chnWrite(&SD1, (const uint8_t *)"Hello World!\r\n", 14); chThdSleepMilliseconds(2000); } }
/* * 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(); palSetPadMode(IOPORT3, BOARD_LED1, PAL_MODE_OUTPUT_PUSHPULL); palClearPad(IOPORT3, BOARD_LED1); /* * Initializes a serial-over-USB CDC driver. */ sduObjectInit(&SDU1); sduStart(&SDU1, &serusbcfg); /* * Activates the USB driver and then the USB bus pull-up on D+. * Note, a delay is inserted in order to not have to disconnect the cable * after a reset. */ usbDisconnectBus(serusbcfg.usbp); chThdSleepMilliseconds(1000); usbStart(serusbcfg.usbp, &usbcfg); usbConnectBus(serusbcfg.usbp); /* * Starts the LED blinker thread. */ chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL); while (true) { if (SDU1.config->usbp->state == USB_ACTIVE) { chnWrite(&SDU1, (const uint8_t *)"Hello from Arduino Leonardo!\r\n", 30); } chThdSleepMilliseconds(2113); } }
static THD_FUNCTION(buttonThread, arg) { (void)arg; wkup_old_state = 0; while(1) { wkup_cur_state = palReadPad(GPIOA, GPIOA_BUTTON); if(wkup_cur_state != wkup_old_state) { chSysLock(); if(usbGetDriverStateI(&USBD1) == USB_ACTIVE) { chSysUnlock(); chnWrite((BaseChannel *)&HIDD, (uint8_t *)"Hello, world!\n", 14); } else chSysUnlock(); wkup_old_state = wkup_cur_state; } chThdSleepMilliseconds(50); } }
THD_FUNCTION(Thread3, arg) { (void)arg; /* * Activates the serial driver 1 using the driver default configuration. * PA9 and PA10 are routed to USART1. */ sdStart(&SD1, NULL); palSetPadMode(GPIOA, 9, PAL_MODE_ALTERNATE(7)); /* USART1 TX. */ palSetPadMode(GPIOA, 10, PAL_MODE_ALTERNATE(7)); /* USART1 RX. */ /* Welcome message.*/ chnWrite(&SD1, (const uint8_t *)"Hello World!\r\n", 14); /* Waiting for button push and activation of the test suite.*/ while (true) { if (palReadPad(GPIOA, GPIOA_BUTTON)) test_execute((BaseSequentialStream *)&SD1); chThdSleepMilliseconds(500); } }
/* Can be measured using dd if=/dev/xxxx of=/dev/null bs=512 count=10000.*/ static void cmd_write(BaseSequentialStream *chp, int argc, char *argv[]) { static uint8_t buf[] = "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"; (void)argv; if (argc > 0) { chprintf(chp, "Usage: write\r\n"); return; } while (chnGetTimeout((BaseChannel *)chp, TIME_IMMEDIATE) == Q_TIMEOUT) { #if 1 /* Writing in channel mode.*/ chnWrite(&SDU1, buf, sizeof buf - 1); #else /* Writing in buffer mode.*/ (void) obqGetEmptyBufferTimeout(&SDU1.obqueue, TIME_INFINITE); memcpy(SDU1.obqueue.ptr, buf, SERIAL_USB_BUFFERS_SIZE); obqPostFullBuffer(&SDU1.obqueue, SERIAL_USB_BUFFERS_SIZE); #endif } chprintf(chp, "\r\n\nstopped\r\n"); }
void virtser_send(const uint8_t byte) { chnWrite(&drivers.serial_driver.driver, &byte, 1); }
void send_midi_packet(MIDI_EventPacket_t* event) { chnWrite(&drivers.midi_driver.driver, (uint8_t*)event, sizeof(MIDI_EventPacket_t)); }
int8_t sendchar(uint8_t c) { // The previous implmentation had timeouts, but I think it's better to just slow down // and make sure that everything is transferred, rather than dropping stuff return chnWrite(&drivers.console_driver.driver, &c, 1); }
THD_FUNCTION(Thread1, arg) { (void)arg; /* * Activate the serial driver 0 using the driver default configuration. */ sdStart(&SD0, NULL); while (chnGetTimeout(&SD0, TIME_INFINITE)) { chnWrite(&SD0, (const uint8_t *)start_msg, strlen(start_msg)); chThdSleepMilliseconds(2000); /* Test 1 - use DMA engine to execute a word-wise memory-to-memory copy. */ chnWrite(&SD0, (const uint8_t *)test_1_msg, strlen(test_1_msg)); strcpy(instring, "After DMA test \r\n"); strcpy(outstring, "Before DMA test \r\n"); if (strcmp("Before DMA test \r\n", outstring)) { chnWrite(&SD0, (const uint8_t *)fail_string, strlen(fail_string)); } request = &test_1_req; chSysLock(); dmaRequestS(request, TIME_INFINITE); chSysUnlock(); if (strcmp("After DMA test \r\n", outstring)) { chnWrite(&SD0, (const uint8_t *)fail_string, strlen(fail_string)); } else { chnWrite(&SD0, (const uint8_t *)succeed_string, strlen(succeed_string)); } /* Test 2 - use DMA engine to execute a byte-wise memory-to-memory copy. */ chnWrite(&SD0, (const uint8_t *)test_2_msg, strlen(test_2_msg)); strcpy(instring, "After DMA test \r\n"); strcpy(outstring, "Before DMA test \r\n"); if (strcmp("Before DMA test \r\n", outstring)) { chnWrite(&SD0, (const uint8_t *)fail_string, strlen(fail_string)); } request = &test_2_req; chSysLock(); dmaRequestS(request, TIME_INFINITE); chSysUnlock(); if (strcmp("After DMA test \r\n", outstring)) { chnWrite(&SD0, (const uint8_t *)fail_string, strlen(fail_string)); } else { chnWrite(&SD0, (const uint8_t *)succeed_string, strlen(succeed_string)); } /* Test 3 - use DMA engine to execute a word-wise memory-to-memory set. */ chnWrite(&SD0, (const uint8_t *)test_3_msg, strlen(test_3_msg)); strcpy(instring, "After DMA test \r\n"); strcpy(outstring, "Before DMA test \r\n"); if (strcmp("Before DMA test \r\n", outstring)) { chnWrite(&SD0, (const uint8_t *)fail_string, strlen(fail_string)); } request = &test_3_req; chSysLock(); dmaRequestS(request, TIME_INFINITE); chSysUnlock(); if (strcmp("AAAAAAAAAAAAAAAA\r\n", outstring)) { chnWrite(&SD0, (const uint8_t *)fail_string, strlen(fail_string)); } else { chnWrite(&SD0, (const uint8_t *)succeed_string, strlen(succeed_string)); } /* Test 4 - use DMA engine to execute a word-wise memory-to-memory copy, * then call a callback. */ chnWrite(&SD0, (const uint8_t *)test_4_msg, strlen(test_4_msg)); strcpy(instring, "After DMA test \r\n"); strcpy(outstring, "Before DMA test \r\n"); cb_arg = 1; if (strcmp("Before DMA test \r\n", outstring) || (cb_arg != 1)) { chnWrite(&SD0, (const uint8_t *)fail_string, strlen(fail_string)); } request = &test_4_req; chSysLock(); dmaRequestS(request, TIME_INFINITE); chSysUnlock(); if (strcmp("After DMA test \r\n", outstring) || cb_arg) { chnWrite(&SD0, (const uint8_t *)fail_string, strlen(fail_string)); } else { chnWrite(&SD0, (const uint8_t *)succeed_string, strlen(succeed_string)); } /* Test 5 - use exclusive DMA channel 0 to execute a word-wise * memory-to-memory copy. */ chnWrite(&SD0, (const uint8_t *)test_5_msg, strlen(test_5_msg)); strcpy(instring, "After DMA test \r\n"); strcpy(outstring, "Before DMA test \r\n"); if (strcmp("Before DMA test \r\n", outstring)) { chnWrite(&SD0, (const uint8_t *)fail_string, strlen(fail_string)); } request = &test_5_req; chSysLock(); dmaAcquireI(&ch, 0); chSysUnlock(); dmaTransfer(&ch, request); if (strcmp("After DMA test \r\n", outstring)) { chnWrite(&SD0, (const uint8_t *)fail_string, strlen(fail_string)); } else { chnWrite(&SD0, (const uint8_t *)succeed_string, strlen(succeed_string)); } /* Test 6 - Attempt to claim DMA channel 0, fail, release it, attempt to * claim it again */ chnWrite(&SD0, (const uint8_t *)test_6_msg, strlen(test_6_msg)); chSysLock(); result = dmaAcquireI(&ch, 0); chSysUnlock(); if (!result) { chnWrite(&SD0, (const uint8_t *)fail_string, strlen(fail_string)); } dmaRelease(&ch); chSysLock(); result = dmaAcquireI(&ch, 0); chSysUnlock(); if (result) { chnWrite(&SD0, (const uint8_t *)fail_string, strlen(fail_string)); } else { chnWrite(&SD0, (const uint8_t *)succeed_string, strlen(succeed_string)); } dmaRelease(&ch); /* Test 7 - use exclusive DMA channel 1 to execute a word-wise * memory-to-memory copy. */ chnWrite(&SD0, (const uint8_t *)test_7_msg, strlen(test_7_msg)); strcpy(instring, "After DMA test \r\n"); strcpy(outstring, "Before DMA test \r\n"); if (strcmp("Before DMA test \r\n", outstring)) { chnWrite(&SD0, (const uint8_t *)fail_string, strlen(fail_string)); } request = &test_5_req; chSysLock(); dmaAcquireI(&ch, 1); chSysUnlock(); dmaTransfer(&ch, request); if (strcmp("After DMA test \r\n", outstring)) { chnWrite(&SD0, (const uint8_t *)fail_string, strlen(fail_string)); } else { chnWrite(&SD0, (const uint8_t *)succeed_string, strlen(succeed_string)); } dmaRelease(&ch); /* Test 8 - Claim all 3 DMA channels, attempt dmaRequest, fail */ chnWrite(&SD0, (const uint8_t *)test_8_msg, strlen(test_8_msg)); chSysLock(); result = dmaAcquireI(&ch, 0); chSysUnlock(); if (result) { chnWrite(&SD0, (const uint8_t *)fail_string, strlen(fail_string)); } chSysLock(); result = dmaAcquireI(&ch1, 1); chSysUnlock(); if (result) { chnWrite(&SD0, (const uint8_t *)fail_string, strlen(fail_string)); } chSysLock(); result = dmaAcquireI(&ch2, 2); chSysUnlock(); if (result) { chnWrite(&SD0, (const uint8_t *)fail_string, strlen(fail_string)); } chSysLock(); result_i = dmaRequestS(request, TIME_IMMEDIATE); chSysUnlock(); if (result_i > 0) { chnWrite(&SD0, (const uint8_t *)fail_string, strlen(fail_string)); } else { chnWrite(&SD0, (const uint8_t *)succeed_string, strlen(succeed_string)); } dmaRelease(&ch); dmaRelease(&ch1); dmaRelease(&ch2); } }
void print(const char * msg) { if (!test) { chnWrite(&SD1, (const uint8_t *)msg, strlen(msg)); } }
THD_FUNCTION(LogThread, arg) { (void) arg; uint32_t FlashAddress; chRegSetThreadName("Flash Logger"); int16_t i; OpCode = NO_OPCODE; FlashSate = FLASH_IDLE; FlashAddress = 0; chBSemObjectInit(&FlashSemaphore, TRUE); /* Semaphore initialization before use */ while (TRUE) { chBSemWait(&FlashSemaphore); switch (OpCode) { case NO_OPCODE: break; case RECORDING_OPCODE: TURN_LED_ON(); M25P16SetWriteEnable(); M25P16BulkErase(); FlashSate = FLASH_WAIT_FOR_PAGE; FlashAddress = 0; TURN_LED_OFF(); break; case WRITEPAGE_OPCODE: M25P16WritePage(FlashAddress, DataBuffer); FlashAddress += PAGE_SIZE; if (FlashAddress < LAST_FLASH_ADDRESS) FlashSate = FLASH_WAIT_FOR_PAGE; else { FlashSate = FLASH_FINISHED; TURN_LED_OFF(); chThdSleepMilliseconds(1000); TURN_LED_ON(); while (TRUE) chThdSleep(TIME_INFINITE); } break; case READING_OPCODE: TURN_LED_ON(); FlashAddress = 0; FlashSate = FLASH_FINISHED; DataBuffer = (uint8_t *) LogData; while (FlashAddress < LAST_FLASH_ADDRESS) { M25P16ReadPage(FlashAddress, DataBuffer); for (i=0;i<PAGE_SIZE/16;i++) { if (SDU1.config->usbp->state == USB_ACTIVE) { chnWrite(&SDU1, &(DataBuffer[16*i]),16); } // chThdSleepMicroseconds(50); } FlashAddress += PAGE_SIZE; } TURN_LED_OFF(); while (TRUE) chThdSleep(TIME_INFINITE); break; } } }