int my_printf(char *str, ...) { va_list ap; int pct_i; int size; int i; init_printf(&i, &size, &pct_i); va_start(ap, str); while (str[i]) { if (pct_i != -1) { if (is_flag(str[i]) == 0) { size += do_aff(str, pct_i, i, ap); pct_i = -1; } } else if (str[i] == '%') size += print_between(str, &pct_i, &i); else size += my_putchar(str[i]); ++i; } va_end(ap); return (size); }
/* Main thread */ int main(void) { /* ChibiOS/RT init */ halInit(); chSysInit(); // TESTING // chThdCreateStatic(waBlinkerThread, sizeof(waBlinkerThread), NORMALPRIO, blinkerThread, NULL); hook_early_init(); /* Init USB */ init_usb_driver(&USB_DRIVER); /* init printf */ init_printf(NULL,sendchar_pf); /* Wait until the USB is active */ while(USB_DRIVER.state != USB_ACTIVE) chThdSleepMilliseconds(50); /* Do need to wait here! * Otherwise the next print might start a transfer on console EP * before the USB is completely ready, which sometimes causes * HardFaults. */ chThdSleepMilliseconds(50); print("USB configured.\n"); /* init TMK modules */ keyboard_init(); host_set_driver(&chibios_driver); #ifdef SLEEP_LED_ENABLE sleep_led_init(); #endif print("Keyboard start.\n"); hook_late_init(); /* Main loop */ while(true) { if(USB_DRIVER.state == USB_SUSPENDED) { print("[s]"); while(USB_DRIVER.state == USB_SUSPENDED) { hook_usb_suspend_loop(); } /* Woken up */ // variables have been already cleared send_keyboard_report(); #ifdef MOUSEKEY_ENABLE mousekey_send(); #endif /* MOUSEKEY_ENABLE */ } keyboard_task(); } }
void n230_init(void) { //TODO: We may need to remove the debug UART before we release. //Initialize the debug UART first. wb_uart_init(WB_DBG_UART_BASE, CPU_CLOCK_FREQ/DBG_UART_BAUD); init_printf(NULL, putc); //Now we can init the rest with prints UHD_FW_TRACE_FSTR(INFO, "[ZPU Init Begin -- CPU CLOCK is %d MHz]", (CPU_CLOCK_FREQ/1000000)); //Initialize cron and the per millisecond cron job UHD_FW_TRACE(INFO, "Initializing cron..."); cron_init(get_counter_val, CPU_CLOCK_FREQ); cron_job_init(PER_MILLISEC_CRON_JOBID, 1); cron_job_init(PER_SECOND_CRON_JOBID, 1000); //Initialize rate for I2C cores UHD_FW_TRACE(INFO, "Initializing I2C..."); for (uint32_t i = 0; i < N230_NUM_ETH_PORTS; i++) { wb_i2c_init((i==1)?WB_ETH1_I2C_BASE:WB_ETH0_I2C_BASE, CPU_CLOCK_FREQ); } //Initialize eeprom read_n230_eeprom(); UHD_FW_TRACE(INFO, "Initializing network stack..."); init_network_stack(); }
/* This initializes the putc call. */ void dmesg_init(){ //Wipe out the old buffer. for(int i=0;i<DMESG_SIZE;i++) dmesg_start[i]=0; //Register the putc() function. init_printf(0,md380_putc); }
int main() { LPC_UART_TypeDef *pUart; SystemInit(); __disable_irq(); uart0_irq_init(); // uart0 interrupt driven, for RTX console uart1_init(); // uart1 polling, for debugging #ifdef DEBUG_0 init_printf(NULL, putc); #endif // DEBUG_0 __enable_irq(); uart1_put_string("COM1> Type a character at COM0 terminal\n\r"); pUart = (LPC_UART_TypeDef *) LPC_UART0; //while( 1 ) { if (g_send_char == 0) { /* Enable RBR, THRE is disabled */ pUart->IER = IER_RLS | IER_RBR; } else if (g_send_char == 1) { /* Enable THRE, RBR left as enabled */ pUart->IER = IER_THRE | IER_RLS | IER_RBR; } //} }
int main() { /* CMSIS system initialization */ SystemInit(); #ifdef DEBUG_0 init_printf(NULL, putc); #else #ifdef DEBUG_1 init_printf(NULL, putc); #endif /* DEBUG_1 */ #endif /* DEBUG_0 */ /* start the RTX and built-in processes */ rtx_init(); /* We should never reach here!!! */ return RTX_ERR; }
void init(void) { //init_RCC(); /* RCC_Configuration */ RCC_Configuration(); init_GPIO(); init_SPI(); NVIC_Configuration(); USART_Configuration(); init_printf(0,putc); }
void __zrt_log_init(const char* logpath){ int i; for (i=0; i < MANIFEST->channels_count; i++ ){ if ( !strcmp(logpath, MANIFEST->channels[i].name) ){ s_zrt_log_fd = i; break; } } init_printf(NULL, tfp_printf_putc); s_log_enabled = 1; s_log_prolog_mode_enabled = 1; }
int main(void) { // Configure clock, this figures out HSE for hardware autodetect SetSysClock(0); systemInit(); Serial1 = uartOpen(USART1, &receive_cb, 115200, MODE_RXTX); init_printf( NULL, _putc); while (1); }
void kernel_main(void) { uart_init(); init_printf(0, putc); irq_vector_init(); timer_init(); enable_interrupt_controller(); enable_irq(); while (1){ uart_send(uart_recv()); } }
static void begin(unsigned int baud) { unsigned int ra; if (initted) return; switch (baud) { case 9600: ra = BAUD_9600; break; case 4800: ra = BAUD_4800; break; case 2400: ra = BAUD_2400; break; case 115200: default: ra = BAUD_115200; break; }; aux_write(AUX_ENABLES, 1); aux_write(AUX_MU_IER_REG, 0); aux_write(AUX_MU_CNTL_REG,0); aux_write(AUX_MU_LCR_REG, 3); aux_write(AUX_MU_MCR_REG, 0); aux_write(AUX_MU_IER_REG, 0); aux_write(AUX_MU_IIR_REG, 0xC6); aux_write(AUX_MU_BAUD_REG, ra); ra = gpio_read(GPFSEL1); ra &= ~(7<<12); //gpio14 ra |= 2<<12; //alt5 ra &= ~(7<<15); //gpio15 ra |= 2<<15; //alt5 gpio_write(GPFSEL1, ra); gpio_write(GPPUD, 0); delay(); gpio_write(GPPUDCLK0, (1<<14)|(1<<15)); delay(); gpio_write(GPPUDCLK0, 0); aux_write(AUX_MU_CNTL_REG, 3); init_printf(NULL, uart_put); initted = true; }
/** * Initializes everything on the robot * @author Group B1 * @param oi The open interface of the robot * @date 12/4/2012 */ void init_all(oi_t *oi) { oi = oi_alloc(); oi_init(oi); init_buttons(); init_usart(); lcd_init(); timer3_init(); ADC_init(); init_printf(0,write_one_char); move_servo(0); wait_ms(1000); printf("\n"); printf("\n"); }
uint8_t cypressInit(void){ WIZ_RST_Write(1); SPIM_Start(); UART_Start(); init_printf(NULL,putdata); //if(SW1_Read()) { // if button is not being pressed LED_Write(0); // turn LED off CyGlobalIntEnable; return 1; }
serialPort_t *usbInit(void) { uartPort_t *s; Set_System(); Set_USBClock(); USB_Interrupts_Config(); USB_Init(); init_printf(NULL, usbPrintf); s = &uartPortUSB; s->port.vTable = usbVTable; return (serialPort_t *)s; }
int main() { init_printf(NULL, stdout_putf); printf("Fun with printf and %%!\n"); TPRINTF("d1=%016llx d2=%016lx d3=%02x d4=%02X 42=%03d\n", (long long unsigned)0xd1, (long unsigned)0xd2, 0xd3, 0xd4, 42); TPRINTF("d1=%04x d2=%06x d3=%08x %%100\n", 0xd1, 0xd2, 0xd3); TPRINTF("|%-14s| |%-16s| d2=%2x |%-30s|\n", "str14", "str16", 0xd2, "12345678901234567890123456789012345"); TPRINTF("|%4s|\n", "string4"); TPRINTF("|%-4s|\n", "string4"); TPRINTF("42=%3d d1=%4.4x |%4s| d2=%8.8x\n", 42, 0xd1, "string4", 0xd2); TPRINTF("42=%3d d1=%4.4x |%-4s| d2=%8.8x\n", 42, 0xd1, "string4", 0xd2); TPRINTF("84=%d 21=%ds |%s| |%sOK| d1=%x d2=%#x\n", 84, 21, "hello", "fine", 0xd1, 0xd2); TPRINTF("%lld\n", LLONG_MIN); TPRINTF("%lld\n", LLONG_MAX); TPRINTF("%llu\n", ULLONG_MAX); TPRINTF("%llx\n", LLONG_MIN); TPRINTF("%llx\n", LLONG_MAX); TPRINTF("%llx\n", ULLONG_MAX); TPRINTF("d1=%.1x\n", 0xd1); TPRINTF("d1=%4.1x\n", 0xd1); TPRINTF("d1=%4.x\n", 0xd1); { char blah[256]; TPRINTF("a=%zd\n", sizeof(blah)); TPRINTF("a=%zu\n", sizeof(blah)); TPRINTF("a=%zi\n", sizeof(blah)); TPRINTF("a=0x%zx\n", sizeof(blah)); } { int in_stack; TPRINTF("Adddress of main: %p\n", main); TPRINTF("Adddress of stack variable: %p\n", &in_stack); } return 0; }
int main() { SystemInit(); //uart0_init(); //uart0_put_string("uart0_put_string test: Hello World!\n\r"); #ifdef DEBUG_0 init_printf(NULL, uart_put_char); printf("DEBUG STATE ON - sample decimal print: %d\n\r", 1); #endif /* DEBUG_0 */ /* start the RTX and built-in processes */ k_rtx_init(); //Should never reach here. return RTX_ERR; }
/******************************* **函数名:ChipHalInit() **功能:片内硬件初始化 *******************************/ void ChipHalInit(void) { //初始化时钟源 RCC_Configuration(); //初始化GPIO GPIO_Configuration(); //初始化串口 USART_Configuration(); init_printf(printf_buf,uart1_putc); tfp_printf("tfp_printf Inital over\n"); TIMER_Configuration(); //初始化中断,在ucos启动后执行,其中包含两步,1,分配中断优先级,2,使能中断 //NVIC_Configuration(); // OLED_Configuration(); }
int main(void) { //timer0_init(); timer1_init(); uart_init(115200); init_printf((void*)0,putc); CPU_PRESCALE(0); // set for 16 MHz clock DDRB = 0xFF; PORTB = 0x00; DDRD = 0xFF; //usb_init(); uint16_t last_print = 0; uint16_t last_led = 0; while (1) { _delay_ms(100); uint16_t c = tics() >> 14; } }
void InitSystem(DeviceConfig *devState){ // init HAL HAL_Init(); /* Configure the system clock */ SystemClock_Config(); /* Initialize all configured peripherals */ InitDeviceConfig(devState); MX_USB_DEVICE_Init(); MX_GPIO_Init(); MX_I2C2_Init(devState); MX_ADC1_Init(devState); MX_ADC1_Init(devState); MX_SPI2_Init(devState); MX_TIM4_Init(devState); MX_USART3_UART_Init(devState); init_printf(NULL,usb_putc); }
int main(void) { /* Initialize system */ STM32_Configuration(); /* Wire putchar for printf */ init_printf(0, __io_putchar); printf("Hello World!\r\n"); while (1) { GPIO_WriteBit(GPIOC, GPIO_Pin_8, Bit_SET); GPIO_WriteBit(GPIOC, GPIO_Pin_9, Bit_RESET); Delay(250); GPIO_WriteBit(GPIOC, GPIO_Pin_8, Bit_RESET); GPIO_WriteBit(GPIOC, GPIO_Pin_9, Bit_SET); Delay(250); } }
int dvrmain(void) { int r; unsigned short cpu_id; char commandline[MAX_COMMANDLINE_LENGTH]; init_printf(NULL, _putc); init_commands(); printf("\n"); info(0, NULL); /* check CPU ID */ cpu_id = REG32(RTGALAXY_SB2_CHIP_ID) & 0xffff; if (cpu_id != RTGALAXY_MARS) { printf("Wrong CPU ID detected (%04X) - aborting\n", cpu_id); return -1; } for (;;) { printf("rtdsr> "); r = get_command(commandline, MAX_COMMANDLINE_LENGTH, -1); if (r > 0) { if ((r = parse_command(commandline)) < 0 ) { if (r == PROGRAM_EXIT) { return 0; } printf("error %d executing command\n", r); } } } return 0; }
int main(void) { uint8_t i; drv_pwm_config_t pwm_params; drv_adc_config_t adc_params; bool sensorsOK = false; #ifdef SOFTSERIAL_LOOPBACK serialPort_t* loopbackPort1 = NULL; serialPort_t* loopbackPort2 = NULL; #endif initEEPROM(); checkFirstTime(false); readEEPROM(); systemInit(mcfg.emf_avoidance); #ifdef USE_LAME_PRINTF init_printf(NULL, _putc); #endif activateConfig(); // configure power ADC if (mcfg.power_adc_channel > 0 && (mcfg.power_adc_channel == 1 || mcfg.power_adc_channel == 9)) adc_params.powerAdcChannel = mcfg.power_adc_channel; else { adc_params.powerAdcChannel = 0; mcfg.power_adc_channel = 0; } adcInit(&adc_params); // Check battery type/voltage if (feature(FEATURE_VBAT)) batteryInit(); initBoardAlignment(); // We have these sensors; SENSORS_SET defined in board.h depending on hardware platform sensorsSet(SENSORS_SET); // drop out any sensors that don't seem to work, init all the others. halt if gyro is dead. sensorsOK = sensorsAutodetect(); // production debug output #ifdef PROD_DEBUG productionDebug(); #endif // if gyro was not detected due to whatever reason, we give up now. if (!sensorsOK) failureMode(3); LED1_ON; LED0_OFF; for (i = 0; i < 10; i++) { LED1_TOGGLE; LED0_TOGGLE; delay(25); BEEP_ON; delay(25); BEEP_OFF; } LED0_OFF; LED1_OFF; imuInit(); // Mag is initialized inside imuInit mixerInit(); // this will set core.useServo var depending on mixer type serialInit(mcfg.serial_baudrate); // when using airplane/wing mixer, servo/motor outputs are remapped if (mcfg.mixerConfiguration == MULTITYPE_AIRPLANE || mcfg.mixerConfiguration == MULTITYPE_FLYING_WING) pwm_params.airplane = true; else pwm_params.airplane = false; pwm_params.useUART = feature(FEATURE_GPS) || feature(FEATURE_SERIALRX); // spektrum/sbus support uses UART too pwm_params.useSoftSerial = feature(FEATURE_SOFTSERIAL); pwm_params.usePPM = feature(FEATURE_PPM); pwm_params.enableInput = !feature(FEATURE_SERIALRX); // disable inputs if using spektrum pwm_params.useServos = core.useServo; pwm_params.extraServos = cfg.gimbal_flags & GIMBAL_FORWARDAUX; pwm_params.motorPwmRate = mcfg.motor_pwm_rate; pwm_params.servoPwmRate = mcfg.servo_pwm_rate; pwm_params.idlePulse = PULSE_1MS; // standard PWM for brushless ESC (default, overridden below) if (feature(FEATURE_3D)) pwm_params.idlePulse = mcfg.neutral3d; if (pwm_params.motorPwmRate > 500) pwm_params.idlePulse = 0; // brushed motors pwm_params.servoCenterPulse = mcfg.midrc; pwm_params.failsafeThreshold = cfg.failsafe_detect_threshold; switch (mcfg.power_adc_channel) { case 1: pwm_params.adcChannel = PWM2; break; case 9: pwm_params.adcChannel = PWM8; break; default: pwm_params.adcChannel = 0; break; } pwmInit(&pwm_params); core.numServos = pwm_params.numServos; // configure PWM/CPPM read function and max number of channels. spektrum or sbus below will override both of these, if enabled for (i = 0; i < RC_CHANS; i++) rcData[i] = 1502; rcReadRawFunc = pwmReadRawRC; core.numRCChannels = MAX_INPUTS; if (feature(FEATURE_SERIALRX)) { switch (mcfg.serialrx_type) { case SERIALRX_SPEKTRUM1024: case SERIALRX_SPEKTRUM2048: spektrumInit(&rcReadRawFunc); break; case SERIALRX_SBUS: sbusInit(&rcReadRawFunc); break; case SERIALRX_SUMD: sumdInit(&rcReadRawFunc); break; case SERIALRX_MSP: mspInit(&rcReadRawFunc); break; } } else { // spektrum and GPS are mutually exclusive // Optional GPS - available in both PPM and PWM input mode, in PWM input, reduces number of available channels by 2. // gpsInit will return if FEATURE_GPS is not enabled. gpsInit(mcfg.gps_baudrate); } #ifdef SONAR // sonar stuff only works with PPM if (feature(FEATURE_PPM)) { if (feature(FEATURE_SONAR)) Sonar_init(); } #endif if (feature(FEATURE_SOFTSERIAL)) { //mcfg.softserial_baudrate = 19200; // Uncomment to override config value setupSoftSerialPrimary(mcfg.softserial_baudrate, mcfg.softserial_1_inverted); setupSoftSerialSecondary(mcfg.softserial_2_inverted); #ifdef SOFTSERIAL_LOOPBACK loopbackPort1 = (serialPort_t*)&(softSerialPorts[0]); serialPrint(loopbackPort1, "SOFTSERIAL 1 - LOOPBACK ENABLED\r\n"); loopbackPort2 = (serialPort_t*)&(softSerialPorts[1]); serialPrint(loopbackPort2, "SOFTSERIAL 2 - LOOPBACK ENABLED\r\n"); #endif //core.mainport = (serialPort_t*)&(softSerialPorts[0]); // Uncomment to switch the main port to use softserial. } if (feature(FEATURE_TELEMETRY)) initTelemetry(); previousTime = micros(); if (mcfg.mixerConfiguration == MULTITYPE_GIMBAL) calibratingA = CALIBRATING_ACC_CYCLES; calibratingG = CALIBRATING_GYRO_CYCLES; calibratingB = CALIBRATING_BARO_CYCLES; // 10 seconds init_delay + 200 * 25 ms = 15 seconds before ground pressure settles f.SMALL_ANGLE = 1; // loopy while (1) { loop(); #ifdef SOFTSERIAL_LOOPBACK if (loopbackPort1) { while (serialTotalBytesWaiting(loopbackPort1)) { uint8_t b = serialRead(loopbackPort1); serialWrite(loopbackPort1, b); //serialWrite(core.mainport, 0x01); //serialWrite(core.mainport, b); }; } if (loopbackPort2) { while (serialTotalBytesWaiting(loopbackPort2)) { #ifndef OLIMEXINO // PB0/D27 and PB1/D28 internally connected so this would result in a continuous stream of data serialRead(loopbackPort2); #else uint8_t b = serialRead(loopbackPort2); serialWrite(loopbackPort2, b); //serialWrite(core.mainport, 0x02); //serialWrite(core.mainport, b); #endif // OLIMEXINO }; } #endif } }
int main(void) { uint8_t i; drv_pwm_config_t pwm_params; drv_adc_config_t adc_params; #if 0 // PC12, PA15 // using this to write asm for bootloader :) RCC->APB2ENR |= RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOC | RCC_APB2Periph_AFIO; // GPIOA/C+AFIO only AFIO->MAPR &= 0xF0FFFFFF; AFIO->MAPR = 0x02000000; GPIOA->CRH = 0x34444444; // PIN 15 Output 50MHz GPIOA->BRR = 0x8000; // set low 15 GPIOC->CRH = 0x44434444; // PIN 12 Output 50MHz GPIOC->BRR = 0x1000; // set low 12 #endif #if 0 // using this to write asm for bootloader :) RCC->APB2ENR |= RCC_APB2Periph_GPIOB | RCC_APB2Periph_AFIO; // GPIOB + AFIO AFIO->MAPR &= 0xF0FFFFFF; AFIO->MAPR = 0x02000000; GPIOB->BRR = 0x18; // set low 4 & 3 GPIOB->CRL = 0x44433444; // PIN 4 & 3 Output 50MHz #endif systemInit(); #ifdef USE_LAME_PRINTF init_printf(NULL, _putc); #endif checkFirstTime(false); readEEPROM(); // configure power ADC if (mcfg.power_adc_channel > 0 && (mcfg.power_adc_channel == 1 || mcfg.power_adc_channel == 9)) adc_params.powerAdcChannel = mcfg.power_adc_channel; else { adc_params.powerAdcChannel = 0; mcfg.power_adc_channel = 0; } adcInit(&adc_params); // We have these sensors; SENSORS_SET defined in board.h depending on hardware platform sensorsSet(SENSORS_SET); mixerInit(); // this will set useServo var depending on mixer type // when using airplane/wing mixer, servo/motor outputs are remapped if (mcfg.mixerConfiguration == MULTITYPE_AIRPLANE || mcfg.mixerConfiguration == MULTITYPE_FLYING_WING) pwm_params.airplane = true; else pwm_params.airplane = false; pwm_params.useUART = feature(FEATURE_GPS) || feature(FEATURE_SPEKTRUM); // spektrum support uses UART too pwm_params.usePPM = feature(FEATURE_PPM); pwm_params.enableInput = !feature(FEATURE_SPEKTRUM); // disable inputs if using spektrum pwm_params.useServos = useServo; pwm_params.extraServos = cfg.gimbal_flags & GIMBAL_FORWARDAUX; pwm_params.motorPwmRate = mcfg.motor_pwm_rate; pwm_params.servoPwmRate = mcfg.servo_pwm_rate; pwm_params.failsafeThreshold = cfg.failsafe_detect_threshold; switch (mcfg.power_adc_channel) { case 1: pwm_params.adcChannel = PWM2; break; case 9: pwm_params.adcChannel = PWM8; break; default: pwm_params.adcChannel = 0; break; } pwmInit(&pwm_params); // configure PWM/CPPM read function. spektrum below will override that rcReadRawFunc = pwmReadRawRC; if (feature(FEATURE_SPEKTRUM)) { spektrumInit(); rcReadRawFunc = spektrumReadRawRC; } else { // spektrum and GPS are mutually exclusive // Optional GPS - available in both PPM and PWM input mode, in PWM input, reduces number of available channels by 2. if (feature(FEATURE_GPS)) gpsInit(mcfg.gps_baudrate); } #ifdef SONAR // sonar stuff only works with PPM if (feature(FEATURE_PPM)) { if (feature(FEATURE_SONAR)) Sonar_init(); } #endif LED1_ON; LED0_OFF; for (i = 0; i < 10; i++) { LED1_TOGGLE; LED0_TOGGLE; delay(25); BEEP_ON; delay(25); BEEP_OFF; } LED0_OFF; LED1_OFF; // drop out any sensors that don't seem to work, init all the others. halt if gyro is dead. sensorsAutodetect(); imuInit(); // Mag is initialized inside imuInit // Check battery type/voltage if (feature(FEATURE_VBAT)) batteryInit(); serialInit(mcfg.serial_baudrate); previousTime = micros(); if (mcfg.mixerConfiguration == MULTITYPE_GIMBAL) calibratingA = 400; calibratingG = 1000; calibratingB = 200; // 10 seconds init_delay + 200 * 25 ms = 15 seconds before ground pressure settles f.SMALL_ANGLES_25 = 1; // loopy while (1) { loop(); } }
/** * @brief Main program. * @param None * @retval None */ int main(void) { uint8_t currentLED=0,idx; uint16_t xx,yy; uint16_t testWord; uint8_t shifter=0; /* Initialize LEDs on STM32F4-Discovery --------------------*/ __IO uint32_t i = 0; uint8_t buf[255]; uint8_t len; STM_EVAL_LEDInit(LED4); STM_EVAL_LEDInit(LED3); // You can use these for LEDs if you use the upper 8 bits of the 16b FSMC bus to talk to the ILI9238. // STM_EVAL_LEDInit(LED5); //GPIOD 14 -> FSMC D0. Do not use for LED, we need them to talk to the ILI9238 // STM_EVAL_LEDInit(LED6); //GPIOD 14 -> FSMC D1. // flash the LEDs in a circle to test delayMillis(uint32_t timedelay) STM_EVAL_LEDToggle(currentLED); for (idx=0;idx<8;idx++) { STM_EVAL_LEDToggle(currentLED); currentLED=(currentLED+1)%2; STM_EVAL_LEDToggle(currentLED); delayMillis(250); } // // USBD_Init(&USB_OTG_dev, USB_OTG_FS_CORE_ID, &USR_desc, &USBD_CDC_cb, &USR_cb); // init the printf init_printf(0,tft_putc); // init_tft_printf(NULL,tft_putc); // Get the 32F4 ready to talk to the TFTLCD using FSMC initGPIO(); initFSMC(); uDelay(1000); // probably don't need this reset(); initDisplay(); // ** Do the adafruit Demo ** // fillScreen(BLACK); // setCursor(0, 0); // setTextColor(CYAN); // setTextSize(1); // setRotation(1); // tft_printf("Please connect to virtual COM port..."); delayMillis(2000); testlines(CYAN); delayMillis(2500); testfastlines(RED, BLUE); delayMillis(2500); testdrawrects(GREEN); delayMillis(2500); testfillrects(YELLOW, MAGENTA); delayMillis(2500); fillScreen(BLACK); testfillcircles(10, MAGENTA); testdrawcircles(10, WHITE); delayMillis(2500); testtriangles(); delayMillis(2500); testfilltriangles(); delayMillis(2500); testRoundRect(); delayMillis(2500); testFillRoundRect(); delayMillis(2500); fillScreen(GREEN); delayMillis(2500); // fsmcData = 0x60020000; // sets a16 // fsmcRegister = 0x60000000; // clears a16 // printf("fsmcData:\t0x%08X\r\n",fsmcData); // printf("fsmcRegister:\t0x%08X\r\n",fsmcRegister); // fillScreen(BLACK); // setCursor(0, 20); // setTextColor(color); // setTextSize(1); // write("Hello World!"); // setTextSize(2); // write(1234.56); // setTextSize(3); // // println(0xDEADBEEF, HEX); // printf("0xFF00>>8 0x%04X\r\n",0xff00>>8); // VCP_send_str(&buf[0]); // printf("SysTick_Config(SystemCoreClock/1000)\t %d\r\n",SysTick_Config(SystemCoreClock/1000)); // millisecondCounter=0; // for (idx=0;idx<100;idx++) // { // printf("millisecondCounter:\t%d",millisecondCounter); // } // void delayMillis(uint32_t millis) // { // uint32_t target; // // target=millisecondCounter+millis; // while(millisecondCounter<target); // } // From stm32f4_discovery.h: // typedef enum // { // LED4 = 0, // LED3 = 1, // LED5 = 2, // LED6 = 3 // } Led_TypeDef; while(1) { for (idx=0;idx<8;idx++) { setRotation(idx%4); testtext(RED); delayMillis(1500); } } }
/* Main thread */ int main(void) { /* ChibiOS/RT init */ halInit(); chSysInit(); #ifdef STM32_EEPROM_ENABLE EEPROM_Init(); #endif // TESTING // chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL); keyboard_setup(); /* Init USB */ init_usb_driver(&USB_DRIVER); /* init printf */ init_printf(NULL,sendchar_pf); #ifdef MIDI_ENABLE setup_midi(); #endif #ifdef SERIAL_LINK_ENABLE init_serial_link(); #endif #ifdef VISUALIZER_ENABLE visualizer_init(); #endif host_driver_t* driver = NULL; /* Wait until the USB or serial link is active */ while (true) { #if defined(WAIT_FOR_USB) || defined(SERIAL_LINK_ENABLE) if(USB_DRIVER.state == USB_ACTIVE) { driver = &chibios_driver; break; } #else driver = &chibios_driver; break; #endif #ifdef SERIAL_LINK_ENABLE if(is_serial_link_connected()) { driver = get_serial_link_driver(); break; } serial_link_update(); #endif wait_ms(50); } /* Do need to wait here! * Otherwise the next print might start a transfer on console EP * before the USB is completely ready, which sometimes causes * HardFaults. */ wait_ms(50); print("USB configured.\n"); /* init TMK modules */ keyboard_init(); host_set_driver(driver); #ifdef SLEEP_LED_ENABLE sleep_led_init(); #endif print("Keyboard start.\n"); /* Main loop */ while(true) { #if !defined(NO_USB_STARTUP_CHECK) if(USB_DRIVER.state == USB_SUSPENDED) { print("[s]"); #ifdef VISUALIZER_ENABLE visualizer_suspend(); #endif while(USB_DRIVER.state == USB_SUSPENDED) { /* Do this in the suspended state */ #ifdef SERIAL_LINK_ENABLE serial_link_update(); #endif suspend_power_down(); // on AVR this deep sleeps for 15ms /* Remote wakeup */ if(suspend_wakeup_condition()) { usbWakeupHost(&USB_DRIVER); } } /* Woken up */ // variables has been already cleared by the wakeup hook send_keyboard_report(); #ifdef MOUSEKEY_ENABLE mousekey_send(); #endif /* MOUSEKEY_ENABLE */ #ifdef VISUALIZER_ENABLE visualizer_resume(); #endif } #endif keyboard_task(); #ifdef CONSOLE_ENABLE console_task(); #endif #ifdef VIRTSER_ENABLE virtser_task(); #endif #ifdef RAW_ENABLE raw_hid_task(); #endif } }
int main() { TIL311 = 0x01; __vectors.address_error = &address_err; __vectors.bus_error = &bus_error; __vectors.illegal_instr = &illegal_inst; __vectors.divide_by_0 = &divby0; __vectors.uninitialized_isr = &bad_isr; __vectors.int_spurious = &spurious; __vectors.auto_level2 = &auto_lvl2; __vectors.priv_violation = &priv_vio; serial_start(); millis_start(); init_printf(null, &printf_putc); lcd_init(); lcd_puts("Hello from C,\non the 68008!"); mario(); init_printf(null, &printf_lcd); /* while(true) { lcd_cursor(0,0); printf("Runtime: %d.%02d ",millis/1000, (millis%1000)/10); }*/ while(true) { TIL311 = 0xCC; DELAY_MS(1000); TIL311 = 0xC0; DELAY_MS(1000); TIL311 = 0xDE; DELAY_MS(1000); TIL311 = 0x00; DELAY_MS(1000); if(serial_available()) { int16_t ch; lcd_clear(); uint8_t c = 0; while ((ch = getc()) != -1) { putc(ch); lcd_data(ch); if (c++ == 15) lcd_cursor(0,1); } } else { lcd_clear(); lcd_puts("Time since boot:"); lcd_cursor(0,1); printf("%3d.%02d seconds",millis()/1000, (millis()%1000)/10); } } }
/** * init_debug * * Start debugging subsystems. */ void init_debug(void) { init_printf(NULL, putc_wrapper); Tegra_console_init(); printf("debug_init()\n"); }
/* Main thread */ int main(void) { /* ChibiOS/RT init */ halInit(); chSysInit(); // TESTING // chThdCreateStatic(waBlinkerThread, sizeof(waBlinkerThread), NORMALPRIO, blinkerThread, NULL); /* Init USB */ init_usb_driver(&USB_DRIVER); /* init printf */ init_printf(NULL,sendchar_pf); #ifdef SERIAL_LINK_ENABLE init_serial_link(); #endif #ifdef VISUALIZER_ENABLE visualizer_init(); #endif host_driver_t* driver = NULL; /* Wait until the USB or serial link is active */ while (true) { if(USB_DRIVER.state == USB_ACTIVE) { driver = &chibios_driver; break; } #ifdef SERIAL_LINK_ENABLE if(is_serial_link_connected()) { driver = get_serial_link_driver(); break; } serial_link_update(); #endif chThdSleepMilliseconds(50); } /* Do need to wait here! * Otherwise the next print might start a transfer on console EP * before the USB is completely ready, which sometimes causes * HardFaults. */ chThdSleepMilliseconds(50); print("USB configured.\n"); /* init TMK modules */ keyboard_init(); host_set_driver(driver); #ifdef SLEEP_LED_ENABLE sleep_led_init(); #endif print("Keyboard start.\n"); /* Main loop */ while(true) { if(USB_DRIVER.state == USB_SUSPENDED) { print("[s]"); #ifdef VISUALIZER_ENABLE visualizer_suspend(); #endif while(USB_DRIVER.state == USB_SUSPENDED) { /* Do this in the suspended state */ #ifdef SERIAL_LINK_ENABLE serial_link_update(); #endif suspend_power_down(); // on AVR this deep sleeps for 15ms /* Remote wakeup */ if((USB_DRIVER.status & 2) && suspend_wakeup_condition()) { send_remote_wakeup(&USB_DRIVER); } } /* Woken up */ // variables has been already cleared by the wakeup hook send_keyboard_report(); #ifdef MOUSEKEY_ENABLE mousekey_send(); #endif /* MOUSEKEY_ENABLE */ #ifdef VISUALIZER_ENABLE visualizer_resume(); #endif } keyboard_task(); } }
/***************************************************************************//** * @brief * Main function for the TDxxxx RF modules. * * @details * This function performs all the required initialization for the TDxxxx * RF modules before calling a user supplied function to perform the user * initialization. * This function then enter an infinite loop going into sleep mode waiting * for an interrupt, and calls a user supplied function upon wake-up. * * @note * If you use this main() function, you must provide 2 functions * - TD_USER_Setup(), which will be called once at startup * - TD_SSER_Loop(), which will be called after waking up by an event * If you provide your own main() function, it will take precedence over this * one, which is completely possible. However, using the library main() * function as a template for your implementation is recommended. * * @note * This function never returns. ******************************************************************************/ int main(void) { // Workarounds for chip errata CHIP_Init(); #ifdef EARLY_SERIAL_DEBUG BITBAND_Peripheral(&(CMU ->HFPERCLKDIV), (cmuClock_HFPER >> CMU_EN_BIT_POS) & CMU_EN_BIT_MASK, 1); BITBAND_Peripheral(&(CMU ->HFPERCLKEN0), ((cmuClock_GPIO) >> CMU_EN_BIT_POS) & CMU_EN_BIT_MASK, 1); CMU_ClockSelectSet(cmuClock_LFB, cmuSelect_CORELEDIV2); CMU_ClockDivSet(cmuClock_LEUART0, cmuClkDiv_4); // Enable the LEUART0 clock CMU_ClockEnable(cmuClock_LEUART0, true); init_printf(TD_UART_Init(115200, true, false), TD_UART_Putc, TD_UART_Start, TD_UART_Stop); tfp_printf("--BOOT %s--\r\n", __TIME__); #endif EARLY_DEBUG_PRINTF("TD_BOOT_Init(0x%08X)\r\n", TD_BOOT_Handler); if (TD_BOOT_Handler) { TD_BOOT_Handler(CONFIG_PRODUCT_LED_POLARITY, CONFIG_PRODUCT_TYPE); } // Initialize the clock Management Unit EARLY_DEBUG_PRINTF("TD_CMU_Init\r\n"); TD_CMU_Init(true); // Initialize the RTC clock EARLY_DEBUG_PRINTF("TD_RTC_Init\r\n"); TD_RTC_Init(0); // Initialize GPIOs EARLY_DEBUG_PRINTF("TD_GPIO_Init\r\n"); TD_GPIO_Init(); // Initialize SigFox (can be bypassed by : TD_SIGFOX_REMOVE_CODE) EARLY_DEBUG_PRINTF("TD_SIGFOX_Init\r\n"); if (TD_SIGFOX_Init) { TD_SIGFOX_Init(true); } // Initialize Scheduler EARLY_DEBUG_PRINTF("TD_SCHEDULER_Init\r\n"); TD_SCHEDULER_Init(); // Call user setup function EARLY_DEBUG_PRINTF("TD_USER_Setup\r\n"); TD_USER_Setup(); EARLY_DEBUG_PRINTF("Entering Main Loop ...\r\n"); // Main idle loop while (true) { // Prevent Exception and Interrupt from calling handler __set_PRIMASK(1); // Here: // with "while" : while no background task should be called // all IRQs (or main loop) function that wanted main loop process MUST call TD_WakeMainLoop(); // with "if" : if no background task should be called // all IRQs taken when in sleep mode, do a background loop // all function that wanted accurate main loop process MUST call TD_WakeMainLoop(); if (!BackgroundRoundWanted) { // Go into EM2 sleep mode until an event occurs, exception/interrupt are masked TD_RTC_Sleep(); // Allow exception/interrupts to call their handlers __set_PRIMASK(0); // Interrupt execution will take place at this stage // Now Prevent Exception and Interrupt from calling handler __set_PRIMASK(1); } // Clear flag. We will always do a round at this point, no sync needed BackgroundRoundWanted = false; // Allow exception/interrupts to call their handlers __set_PRIMASK(0); // Scheduler process TD_SCHEDULER_Process(); // Call user loop function TD_USER_Loop(); // RTC Process TD_RTC_Process(); } }
int main(void) { uint8_t i; drv_pwm_config_t pwm_params; drv_adc_config_t adc_params; serialPort_t* loopbackPort = NULL; systemInit(); #ifdef USE_LAME_PRINTF init_printf(NULL, _putc); #endif checkFirstTime(false); readEEPROM(); // configure power ADC if (mcfg.power_adc_channel > 0 && (mcfg.power_adc_channel == 1 || mcfg.power_adc_channel == 9)) adc_params.powerAdcChannel = mcfg.power_adc_channel; else { adc_params.powerAdcChannel = 0; mcfg.power_adc_channel = 0; } adcInit(&adc_params); initBoardAlignment(); // We have these sensors; SENSORS_SET defined in board.h depending on hardware platform sensorsSet(SENSORS_SET); mixerInit(); // this will set core.useServo var depending on mixer type // when using airplane/wing mixer, servo/motor outputs are remapped if (mcfg.mixerConfiguration == MULTITYPE_AIRPLANE || mcfg.mixerConfiguration == MULTITYPE_FLYING_WING) pwm_params.airplane = true; else pwm_params.airplane = false; //pwm_params.useUART = feature(FEATURE_GPS) || feature(FEATURE_SERIALRX); // spektrum/sbus support uses UART too pwm_params.useUART = feature(FEATURE_GPS); pwm_params.useSoftSerial = feature(FEATURE_SOFTSERIAL); pwm_params.usePPM = feature(FEATURE_PPM); pwm_params.enableInput = !feature(FEATURE_SERIALRX); // disable inputs if using spektrum pwm_params.useServos = core.useServo; pwm_params.extraServos = cfg.gimbal_flags & GIMBAL_FORWARDAUX; pwm_params.motorPwmRate = mcfg.motor_pwm_rate; pwm_params.servoPwmRate = mcfg.servo_pwm_rate; pwm_params.idlePulse = PULSE_1MS; // standard PWM for brushless ESC (default, overridden below) if (feature(FEATURE_3D)) pwm_params.idlePulse = mcfg.neutral3d; if (pwm_params.motorPwmRate > 500) pwm_params.idlePulse = 0; // brushed motors pwm_params.servoCenterPulse = mcfg.midrc; pwm_params.failsafeThreshold = cfg.failsafe_detect_threshold; switch (mcfg.power_adc_channel) { case 1: pwm_params.adcChannel = PWM2; break; case 9: pwm_params.adcChannel = PWM8; break; default: pwm_params.adcChannel = 0; break; } pwmInit(&pwm_params); // configure PWM/CPPM read function and max number of channels. spektrum or sbus below will override both of these, if enabled for (i = 0; i < RC_CHANS; i++) rcData[i] = 1502; rcReadRawFunc = pwmReadRawRC; core.numRCChannels = MAX_INPUTS; if (feature(FEATURE_SERIALRX)) { switch (mcfg.serialrx_type) { case SERIALRX_SPEKTRUM1024: case SERIALRX_SPEKTRUM2048: spektrumInit(&rcReadRawFunc); break; case SERIALRX_SBUS: sbusInit(&rcReadRawFunc); break; case SERIALRX_SUMD: sumdInit(&rcReadRawFunc); break; #if defined(SKYROVER) case SERIALRX_HEXAIRBOT: hexairbotInit(&rcReadRawFunc); break; #endif } } else { // spektrum and GPS are mutually exclusive // Optional GPS - available in both PPM and PWM input mode, in PWM input, reduces number of available channels by 2. // gpsInit will return if FEATURE_GPS is not enabled. // Sanity check below - protocols other than NMEA do not support baud rate autodetection if (mcfg.gps_type > 0 && mcfg.gps_baudrate < 0) mcfg.gps_baudrate = 0; gpsInit(mcfg.gps_baudrate); } #ifdef SONAR // sonar stuff only works with PPM if (feature(FEATURE_PPM)) { if (feature(FEATURE_SONAR)) Sonar_init(); } #endif LED1_ON; LED0_OFF; for (i = 0; i < 10; i++) { LED1_TOGGLE; LED0_TOGGLE; delay(25); BEEP_ON; delay(25); BEEP_OFF; } LED0_OFF; LED1_OFF; serialInit(mcfg.serial_baudrate); DEBUG_PRINT("Booting..\r\n"); // drop out any sensors that don't seem to work, init all the others. halt if gyro is dead. sensorsAutodetect(); imuInit(); // Mag is initialized inside imuInit // Check battery type/voltage if (feature(FEATURE_VBAT)) batteryInit(); if (feature(FEATURE_SOFTSERIAL)) { setupSoftSerial1(mcfg.softserial_baudrate, mcfg.softserial_inverted); #ifdef SOFTSERIAL_LOOPBACK loopbackPort = (serialPort_t*)&(softSerialPorts[0]); serialPrint(loopbackPort, "LOOPBACK ENABLED\r\n"); #endif } if (feature(FEATURE_TELEMETRY)) initTelemetry(); previousTime = micros(); if (mcfg.mixerConfiguration == MULTITYPE_GIMBAL) calibratingA = CALIBRATING_ACC_CYCLES; calibratingG = CALIBRATING_GYRO_CYCLES; calibratingB = CALIBRATING_BARO_CYCLES; // 10 seconds init_delay + 200 * 25 ms = 15 seconds before ground pressure settles f.SMALL_ANGLES_25 = 1; DEBUG_PRINT("Start\r\n"); // loopy while (1) { loop(); #ifdef SOFTSERIAL_LOOPBACK if (loopbackPort) { while (serialTotalBytesWaiting(loopbackPort)) { uint8_t b = serialRead(loopbackPort); serialWrite(loopbackPort, b); //serialWrite(core.mainport, b); }; } #endif } }