void uartInit(void) { // initialize all uarts uart0Init(); uart1Init(); uart2Init(); uart3Init(); }
//perform all initialization void initialize() { //configure BTN1 as an input cbi(DDRD, 4); //enable pullup for BTN1 sbi(PORTD, 4); //configure LED as an output sbi(DDRG, 2); //configure 74LS374 (D Flip-Flop) clock pin as an output sbi(DDRD, 5); //configure LCD/Servo bus on port C as an output DDRC = 0xFF; #if USE_LCD == 1 //initialize LCD lcdInit(); #endif #if USE_I2C == 1 //configure I2C clock rate i2cInit(); #endif #if USE_MOTOR0 == 1 || USE_MOTOR1 == 1 //initialize enabled motors motorInit(); #endif #if NUM_SERVOS > 0 //initialize servos servoInit(); #endif #if USE_ADC == 1 //initialize ADC adcInit(); #endif #if USE_UART0 == 1 //initialize UART0 uart0Init(); #endif #if USE_UART1 == 1 //initialize UART1 uart1Init(); #endif #if USE_RTC == 1 //initialize RTC rtcInit(); #endif }
static void uart1testInit(DeckInfo *info) { if(isInit) return; uart1Init(115200); xTaskCreate(uart1testTask, "UART1TEST", configMINIMAL_STACK_SIZE, NULL, 1, NULL); isInit = true; }
void open_log_init(void) { uart1Init(); uartSetBaudRate(1,9600); OPEN_LOG_PWR_PORT &= ~(1<<OPEN_LOG_PWR_PIN); DDR(OPEN_LOG_PWR_PORT) |= (1<<OPEN_LOG_PWR_PIN); // setup our reset port and pin, hold reset high OPEN_LOG_RESET_PORT |= (1<<OPEN_LOG_RESET_PIN); DDR(OPEN_LOG_RESET_PORT) |= (1<<OPEN_LOG_RESET_PIN); }
void main() { systemInit(); //Among other things, allocates byte arrays for sending commands. dynamixel_init(); // Oooh. what's this? setDigitalOutput(param_arduino_DTR_pin, LOW); ioTxSignals(0); //usbInit(); uart1Init(); uart1SetBaudRate(param_baud_rate); // Initial setting of serial mode updateSerialMode(); // Set up P1_5 to be the radio's TX debug signal. // P1DIR |= (1<<5); // IOCFG0 = 0b011011; // P1_5 = PA_PD (TX mode) // P1DIR |= 0x20; //Enable pin P1_5 while(1) { uint32 ms; uint16 now; uint16 speed; updateSerialMode(); boardService(); updateLeds(); errorService(); // Code for oscillating a servo back and forth ms = getMs(); // Get current time in ms now = ms % (uint32)10000; // 10 sec for a full swing if(now >= (uint16)5000){ // Goes from 0ms...5000ms now = (uint16)10000 - now; // then 5000ms...0ms } speed = interpolate(now, 0, 5000, 100, 900); // speed is really the position. ax12SetGOAL_POSITION(32, speed); delayMs(30); } }
/* INTERRUPT VECTORS: * 0: OS Timer Tick * 1: Not Used * 2: UART0 Interrupt * 3: UART1 Interrupt * 4: I2C0 Interrupt * 5-16: Not Used */ int main(void) { OSHANDLES SysHandles; // Should contain all OS Handles cpuSetupHardware(); // Setup PLL, enable MAM etc. watchdogDelayUs(1000 * 1000); // Some startup delay uart0Init(38400, 128); // 128 is size of UART0 Rx/Tx FIFO uart1Init(38400, 128); // 128 is size of UART1 Rx/Tx FIFO // Use polling version of uart0 to do printf/rprintf before starting FreeRTOS rprintf_devopen(uart0PutCharPolling); cpuPrintMemoryInfo(); // Open interrupt-driven version of UART0 Rx/Tx rprintf_devopen(uart0PutChar); watchdogDelayUs(1000 * 1000); /** Create timer needed for SD Card I/O */ Timer diskTimer(FatFsDiskTimer, 10, TimerPeriodic); diskTimer.start(); /** Create any Queues and Mutexes **/ SysHandles.lock.SPI = xSemaphoreCreateMutex(); // TODO 2. Create the "song name" Queue here SysHandles.queue.songname = xQueueCreate(1,16); //length, item size // Use the WATERMARK command to determine optimal Stack size of each task (set to high, then slowly decrease) // Priorities should be set according to response required if (pdPASS != xTaskCreate( uartUI, (signed char*)"Uart UI", STACK_BYTES(1024*6), &SysHandles, PRIORITY_HIGH, &SysHandles.task.userInterface ) || pdPASS!= xTaskCreate( mp3Task, (signed char*)"MP3", STACK_BYTES(1024*6), &SysHandles, PRIORITY_HIGH, &SysHandles.task.mp3 ) || pdPASS!= xTaskCreate( sd_card_detect, (signed char*)"sd_card_detect", STACK_BYTES(1024), &SysHandles, PRIORITY_LOW, &SysHandles.task.sd_card_detect ) || pdPASS!= xTaskCreate( mp3_controls, (signed char*)"mp3_controls", STACK_BYTES(1024*6), &SysHandles, PRIORITY_LOW, &SysHandles.task.mp3_controls )) { rprintf( "ERROR: OUT OF MEMORY: Check OS Stack Size or task stack size.\n"); } // Start FreeRTOS to begin servicing tasks created above, vTaskStartScheduler() will not "return" rprintf("\n-- Starting FreeRTOS --\n"); vTaskStartScheduler(); // In case OS is exited: rprintf_devopen(uart0PutCharPolling); rprintf("ERROR: Unexpected OS Exit!\n"); return 0; }
void main() { systemInit(); usbInit(); usbComLineCodingChangeHandler = &lineCodingChanged; uart1Init(); lineCodingChanged(); while(1) { boardService(); updateLeds(); usbComService(); usbToUartService(); } }
void main(void) { systemInit(); radioQueueInit(); //Empfaenger initialisieren radioQueueAllowCrcErrors = 1; //Fehlerhafte Pakete zulassen uart1Init(); //Serielle Schnittstelle initialisieren lineCodingChanged(); //Einstellen der Schnittstellen Eigenschaft while(1) { updateLeds(); //Status der LEDs veraendern boardService(); usbComService(); radioToUart1Service(); //Empfangen der Daten } }
void main() { systemInit(); setDigitalOutput(param_arduino_DTR_pin, LOW); ioTxSignals(0); usbInit(); uart1Init(); uart1SetBaudRate(param_baud_rate); if (param_serial_mode != SERIAL_MODE_USB_UART) { radioComRxEnforceOrdering = 1; radioComInit(); } // Set up P1_5 to be the radio's TX debug signal. P1DIR |= (1<<5); IOCFG0 = 0b011011; // P1_5 = PA_PD (TX mode) while(1) { updateSerialMode(); boardService(); updateLeds(); errorService(); /* toggle_led();*/ if (param_serial_mode != SERIAL_MODE_USB_UART) { radioComTxService(); } usbComService(); switch(currentSerialMode) { case SERIAL_MODE_USB_RADIO: usbToRadioService(); break; case SERIAL_MODE_UART_RADIO: uartToRadioService(); break; case SERIAL_MODE_USB_UART: usbToUartService(); break; } } }
static void bigquadInit(DeckInfo *info) { if(isInit) return; DEBUG_PRINT("Switching to brushless.\n"); motorsInit(motorMapBigQuadDeck); extRxInit(); #ifdef BQ_DECK_ENABLE_PM pmEnableExtBatteryVoltMeasuring(BIGQUAD_BAT_VOLT_PIN, BIGQUAD_BAT_VOLT_MULT); pmEnableExtBatteryCurrMeasuring(BIGQUAD_BAT_CURR_PIN, BIGQUAD_BAT_AMP_PER_VOLT); #endif #ifdef BQ_DECK_ENABLE_OSD uart1Init(115200); mspInit(&s_MspObject, osdResponseCallback); xTaskCreate(osdTask, "BQ_OSDTASK", configMINIMAL_STACK_SIZE, NULL, /*priority*/1, NULL); #endif isInit = true; }
void uartInit(u08 nUart) { assert(nUart < 4); switch (nUart) { case 0: uart0Init(); break; case 1: uart1Init(); break; case 2: uart2Init(); break; case 3: uart3Init(); break; default: break; } }
int main(void) { // initialize processor processorInit(); // initialize timers timerInit(); // initialize uarts uart0Init(UART_BAUD(115200), UART_8N1, UART_FIFO_8); uart1Init(UART_BAUD(115200), UART_8N1, UART_FIFO_8); // initialize rprintf to use UART1 for output rprintfInit(uart1SendByte); // Wait for a moment to allow hardware to stabilize. // This may be important if a serial port level-converter // like the MAX232 is used. Charge-pump based converters // need some time after power-up to charge before // communication is reliable. timerPause(50); // waits 50 milliseconds // run the test uartTest(); return 0; }
void systemTask(void *arg) { bool pass = true; ledInit(); ledSet(CHG_LED, 1); #ifdef DEBUG_QUEUE_MONITOR queueMonitorInit(); #endif uartInit(); #ifdef ENABLE_UART1 uart1Init(); #endif #ifdef ENABLE_UART2 uart2Init(); #endif //Init the high-levels modules systemInit(); #ifndef USE_RADIOLINK_CRTP #ifdef UART_OUTPUT_TRACE_DATA //debugInitTrace(); #endif #ifdef ENABLE_UART // uartInit(); #endif #endif //ndef USE_RADIOLINK_CRTP commInit(); commanderAdvancedInit(); stabilizerInit(); #ifdef PLATFORM_CF2 deckInit(); #endif soundInit(); memInit(); #ifdef PROXIMITY_ENABLED proximityInit(); #endif //Test the modules pass &= systemTest(); pass &= configblockTest(); pass &= commTest(); pass &= commanderAdvancedTest(); pass &= stabilizerTest(); #ifdef PLATFORM_CF2 pass &= deckTest(); #endif pass &= soundTest(); pass &= memTest(); pass &= watchdogNormalStartTest(); //Start the firmware if(pass) { selftestPassed = 1; systemStart(); soundSetEffect(SND_STARTUP); ledseqRun(SYS_LED, seq_alive); ledseqRun(LINK_LED, seq_testPassed); } else { selftestPassed = 0; if (systemTest()) { while(1) { ledseqRun(SYS_LED, seq_testPassed); //Red passed == not passed! vTaskDelay(M2T(2000)); // System can be forced to start by setting the param to 1 from the cfclient if (selftestPassed) { DEBUG_PRINT("Start forced.\n"); systemStart(); break; } } } else { ledInit(); ledSet(SYS_LED, true); } } DEBUG_PRINT("Free heap: %d bytes\n", xPortGetFreeHeapSize()); workerLoop(); //Should never reach this point! while(1) vTaskDelay(portMAX_DELAY); }
void main() { // uint32 ms; // uint32 now; // uint8 cmdrAlive = 0; // Here we define what pins we will be using for PWM. // uint8 CODE pwmPins[] = {ptrGunMotor->pwmpin}; uint8 CODE pwmPins[] = {11}; MOTOR gunMotor = MAKE_MOTOR_3_PIN(pwmPins[0], 12, 13); //(PWM, B, A) MOTOR *ptrGunMotor = &gunMotor; // setDigitalOutput(param_arduino_DTR_pin, LOW); // ioTxSignals(0); // Initialize UARTs uart0Init(); uart0SetBaudRate(param_baud_rate_UART); uart1Init(); uart1SetBaudRate(param_baud_rate_XBEE); pwmStart((uint8 XDATA *)pwmPins, sizeof(pwmPins), 10000); guns_firing_duration = 125; // time in ms gunbutton = zFALSE; solenoid_on_duration = 80; // time in ms solenoidbutton = zFALSE; laserbutton = zFALSE; systemInit(); // Initialize other stuff index_cmdr = -1; /// MAIN LOOP /// while(1) { // updateSerialMode(); boardService(); updateLeds(); errorService(); // cmdr counts down from CMDR_ALIVE_CNT by -1 whenever no packets are received? cmdrAlive = (uint8) CLAMP(cmdrAlive + CmdrReadMsgs(), 0, CMDR_ALIVE_CNT); // ms = getMs(); // Get current time in ms // now = getMs(); // now = ms % (uint32)10000; // 10 sec for a full swing // if(now >= (uint16)5000){ // Goes from 0ms...5000ms // now = (uint16)10000 - now; // then 5000ms...0ms // } // speed = interpolate(now, 0, 5000, 100, 900); if (laserbutton == zTRUE && cmdrAlive > 0){ // uart0TxSendByte('L'); setDigitalOutput(param_laser_pin, HIGH); } else {setDigitalOutput(param_laser_pin, LOW);} //FIRE THE GUNS!!!!! //Resets timer while gunbutton is held down. if (gunbutton == zTRUE){ // uart0TxSendByte('Z'); guns_firing = zTRUE; setMotorSpeed(ptrGunMotor, -60); //NOTE: (7.2 / 12.6) * 127 = 72.5714286 guns_firing_start_time = getMs(); } //Check whether to stop firing guns if (guns_firing && clockHasElapsed(guns_firing_start_time, guns_firing_duration)){ // uart0TxSendByte('X'); guns_firing = zFALSE; setMotorSpeed(ptrGunMotor, 0); //NOTE: (7.2 / 12.6) * 127 = 72.5714286 guns_firing_start_time = getMs(); } //Activate solenoid for hopup feed unjammer if (solenoidbutton == zTRUE){ // uart0TxSendByte('Z'); solenoid_on = zTRUE; setDigitalOutput(10, HIGH); solenoid_on_start_time = getMs(); } //Check whether to disable solenoid if (solenoid_on && clockHasElapsed(solenoid_on_start_time, solenoid_on_duration)){ // uart0TxSendByte('X'); solenoid_on = zFALSE; setDigitalOutput(10, LOW); solenoid_on_start_time = getMs(); } delayMs(5); } }
void systemTask(void *arg) { bool pass = true; ledInit(); ledSet(CHG_LED, 1); #ifdef DEBUG_QUEUE_MONITOR queueMonitorInit(); #endif #ifdef ENABLE_UART1 uart1Init(); #endif #ifdef ENABLE_UART2 uart2Init(); #endif //Init the high-levels modules systemInit(); commInit(); commanderInit(); StateEstimatorType estimator = anyEstimator; deckInit(); estimator = deckGetRequiredEstimator(); stabilizerInit(estimator); if (deckGetRequiredLowInterferenceRadioMode()) { platformSetLowInterferenceRadioMode(); } soundInit(); memInit(); #ifdef PROXIMITY_ENABLED proximityInit(); #endif //Test the modules pass &= systemTest(); pass &= configblockTest(); pass &= commTest(); pass &= commanderTest(); pass &= stabilizerTest(); pass &= deckTest(); pass &= soundTest(); pass &= memTest(); pass &= watchdogNormalStartTest(); //Start the firmware if(pass) { selftestPassed = 1; systemStart(); soundSetEffect(SND_STARTUP); ledseqRun(SYS_LED, seq_alive); ledseqRun(LINK_LED, seq_testPassed); } else { selftestPassed = 0; if (systemTest()) { while(1) { ledseqRun(SYS_LED, seq_testPassed); //Red passed == not passed! vTaskDelay(M2T(2000)); // System can be forced to start by setting the param to 1 from the cfclient if (selftestPassed) { DEBUG_PRINT("Start forced.\n"); systemStart(); break; } } } else { ledInit(); ledSet(SYS_LED, true); } } DEBUG_PRINT("Free heap: %d bytes\n", xPortGetFreeHeapSize()); workerLoop(); //Should never reach this point! while(1) vTaskDelay(portMAX_DELAY); }
void systemInit(void) { RCC_ClocksTypeDef rccClocks; /////////////////////////////////// // Init cycle counter cycleCounterInit(); // SysTick SysTick_Config(SystemCoreClock / 1000); // Turn on peripherial clocks RCC_AHBPeriphClockCmd(RCC_AHBPeriph_ADC12, ENABLE); RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE); // USART1, USART2 RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA2, ENABLE); // ADC2 RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE); RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE); RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOC, ENABLE); RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2, ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE); // PPM RX RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE); // PWM ESC Out 1 & 2 RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE); // PWM ESC Out 5 & 6 RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE); // PWM Servo Out 1, 2, 3, & 4 RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM6, ENABLE); // 500 Hz dt Counter RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM7, ENABLE); // 100 Hz dt Counter RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM15, ENABLE); // PWM ESC Out 3 & 4 RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM16, ENABLE); // RangeFinder PWM RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM17, ENABLE); // Spektrum Frame Sync RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE); // Telemetry RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE); // GPS RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE); // Spektrum RX /////////////////////////////////////////////////////////////////////////// spiInit(SPI2); /////////////////////////////////// checkSensorEEPROM(false); checkSystemEEPROM(false); readSensorEEPROM(); readSystemEEPROM(); /////////////////////////////////// if (systemConfig.receiverType == SPEKTRUM) checkSpektrumBind(); /////////////////////////////////// checkResetType(); NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); // 2 bits for pre-emption priority, 2 bits for subpriority /////////////////////////////////// gpsPortClearBuffer = &uart2ClearBuffer; gpsPortNumCharsAvailable = &uart2NumCharsAvailable; gpsPortPrintBinary = &uart2PrintBinary; gpsPortRead = &uart2Read; telemPortAvailable = &uart1Available; telemPortPrint = &uart1Print; telemPortPrintF = &uart1PrintF; telemPortRead = &uart1Read; /////////////////////////////////// initMixer(); usbInit(); gpioInit(); uart1Init(); uart2Init(); LED0_OFF; delay(10000); // 10 seconds of 20 second delay for sensor stabilization checkUsbActive(); /////////////////////////////////// #ifdef __VERSION__ cliPortPrintF("\ngcc version " __VERSION__ "\n"); #endif cliPortPrintF("\nFF32mini Firmware V%s, Build Date " __DATE__ " "__TIME__" \n", __FF32MINI_VERSION); if ((RCC->CR & RCC_CR_HSERDY) != RESET) { cliPortPrint("\nRunning on external HSE clock....\n"); } else { cliPortPrint("\nERROR: Running on internal HSI clock....\n"); } RCC_GetClocksFreq(&rccClocks); cliPortPrintF("\nHCLK-> %2d MHz\n", rccClocks.HCLK_Frequency / 1000000); cliPortPrintF( "PCLK1-> %2d MHz\n", rccClocks.PCLK1_Frequency / 1000000); cliPortPrintF( "PCLK2-> %2d MHz\n", rccClocks.PCLK2_Frequency / 1000000); cliPortPrintF( "SYSCLK-> %2d MHz\n\n", rccClocks.SYSCLK_Frequency / 1000000); if (systemConfig.receiverType == PPM) cliPortPrint("Using PPM Receiver....\n\n"); else cliPortPrint("Using Spektrum Satellite Receiver....\n\n"); initUBLOX(); delay(10000); // Remaining 10 seconds of 20 second delay for sensor stabilization - probably not long enough.. /////////////////////////////////// adcInit(); aglInit(); pwmServoInit(); if (systemConfig.receiverType == SPEKTRUM) spektrumInit(); else ppmRxInit(); timingFunctionsInit(); batteryInit(); initFirstOrderFilter(); initMavlink(); initPID(); LED0_ON; initMPU6000(); initMag(); initPressure(); }
int main(void) { int ch; int8_t res; systemInit(); gpioInit(); uart1Init(UART_BAUD(BAUD), UART_8N1, UART_FIFO_8); // setup the UART uart1Puts("\r\nMMC/SD Card Filesystem Test (P:LPC2138 L:EFSL)\r\n"); uart1Puts("efsl LPC2000-port and this Demo-Application\r\n"); uart1Puts("done by Martin Thomas, Kaiserslautern, Germany\r\n"); /* init efsl debug-output */ lpc2000_debug_devopen(uart1Putch); ledToggle(); rprintf("CARD init..."); if ( ( res = efs_init( &efs, 0 ) ) != 0 ) { rprintf("failed with %i\n",res); } else { rprintf("ok\n"); rprintf("Directory of 'root':\n"); ls_openDir( &list, &(efs.myFs) , "/"); while ( ls_getNext( &list ) == 0 ) { list.currentEntry.FileName[LIST_MAXLENFILENAME-1] = '\0'; rprintf( "%s ( %li bytes )\n" , list.currentEntry.FileName, list.currentEntry.FileSize ) ; } if ( file_fopen( &filer, &efs.myFs , LogFileName , 'r' ) == 0 ) { rprintf("File %s open. Content:\n", LogFileName); while ( ( e = file_read( &filer, 512, buf ) ) != 0 ) { buf[e]='\0'; uart1Puts((char*)buf); } rprintf("\n"); file_fclose( &filer ); } if ( file_fopen( &filew, &efs.myFs , LogFileName , 'a' ) == 0 ) { rprintf("File %s open for append. Appending...", LogFileName); strcpy((char*)buf, "Martin hat's angehaengt\r\n"); if ( file_write( &filew, strlen((char*)buf), buf ) == strlen((char*)buf) ) { rprintf("ok\n"); } else { rprintf("fail\n"); } file_fclose( &filew ); } if ( file_fopen( &filer, &efs.myFs , LogFileName , 'r' ) == 0 ) { rprintf("File %s open. Content:\n", LogFileName); while ( ( e = file_read( &filer, 512, buf ) ) != 0 ) { buf[e]='\0'; uart1Puts((char*)buf); } rprintf("\n"); file_fclose( &filer ); } fs_umount( &efs.myFs ) ; } while(1) { if ((ch = uart1Getch()) >= 0) { uart1Puts("You pressed : "); uart1Putch(ch); uart1Puts("\r\n"); if ( ch == 'M' ) { rprintf("Creating FS\n"); mkfs_makevfat(&efs.myPart); } ledToggle(); } } return 0; /* never reached */ }
int main(void) { static unsigned char buffer[BUFFER_SIZE]; unsigned short i; unsigned char timeout = 3; RTCTime local_time; SystemInit(); // IODIR0 |= (P0_15|P0_16|P0_17); // some outputs for debugging and measures //P0_16 ReadSector() in mmc_spi.c //P0_17 enc28j60 write packet //P0_15 general purpose, BE AWARE ! // uart1Init(B38400, UART_8N1, UART_FIFO_8); // setup the UART uart1Init(B115200, UART_8N1, UART_FIFO_8); // setup the UART rprintf_devopen( uart1_sendchar ); /* init rprintf */ VICIntEnClear = 0xFFFFFFFF; VICIntSelect = 0x00000000; RTCInit(); /* current date 05.08.2007 20:45:00*/ local_time.RTC_Sec = 0; local_time.RTC_Min = 45; local_time.RTC_Hour = 20; local_time.RTC_Mday = 5; local_time.RTC_Wday = 3; // My monday has 0 local_time.RTC_Yday = 1; local_time.RTC_Mon = 8; local_time.RTC_Year = 2007; RTCSetTime( local_time ); /* Set local time */ // RTCStart(); init_timer(); enableIRQ(); printf("Holgi's ARM7 LPC213x MultiFAT Speed Test\n\r"); MMC_IO_Init(); enc28j60_io_init(); // You don't need this ! It's for my board only. while (GetDriveInformation() != F_OK && timeout--) { printf ("MMC/SD-Card not found !\n\r"); HaltCPU(); } ShowDOSConfig(); // show selected DOS details from dosdefs.h /* // test time measurement StartTimer(); timer_value = SetDelay10ms(1000); // delay 10 seconds while(CheckDelay10ms(timer_value)==0); StopTimer(); // stop measure and show results // result is 2MB in 10s -> 200kB/s // end test time measurement */ printf("\nTest directory functions\n"); Chdir("dir1"); Remove("dir4"); Chdir("/"); // Back to root Remove("dir1"); Mkdir("dir1"); Chdir("dir1"); Mkdir("dir2"); Mkdir("dir3"); Rename("dir3","dir4"); Remove("dir2"); // You should have now: // dir1/dir4 Chdir("/"); // Back to root printf("\nDeleting files\n"); Remove("01.bin"); //Remove last data Remove("02.bin"); Remove("04.bin"); Remove("08.bin"); Remove("16.bin"); Remove("32.bin"); Remove("64.bin"); Remove("77.bin"); Remove("128.bin"); Remove("MAX.bin"); //Fill the test buffer for(i=0; i<BUFFER_SIZE; i++) buffer[i]=(unsigned char)(i); printf("\nStart writing files\n"); WriteTestFile("01.bin",buffer,1); WriteTestFile("02.bin",buffer,2); WriteTestFile("04.bin",buffer,4); WriteTestFile("08.bin",buffer,8); WriteTestFile("16.bin",buffer,16); WriteTestFile("32.bin",buffer,32); WriteTestFile("64.bin",buffer,64); WriteTestFile("77.bin",buffer,77); WriteTestFile("128.bin",buffer,128); WriteTestFile("MAX.bin",buffer,BUFFER_SIZE); printf("\nStart reading files\n"); ReadTestFile("01.bin",buffer,1); ReadTestFile("02.bin",buffer,2); ReadTestFile("04.bin",buffer,4); ReadTestFile("08.bin",buffer,8); ReadTestFile("16.bin",buffer,16); ReadTestFile("32.bin",buffer,32); ReadTestFile("64.bin",buffer,64); ReadTestFile("77.bin",buffer,77); ReadTestFile("128.bin",buffer,128); ReadTestFile("MAX.bin",buffer,BUFFER_SIZE); printf("\nVerifying files\n"); VerifyTestFile("32.bin",buffer,32); VerifyTestFile("64.bin",buffer,64); VerifyTestFile("77.bin",buffer,77); VerifyTestFile("128.bin",buffer,128); VerifyTestFile("MAX.bin",buffer,BUFFER_SIZE); printf("Test done.\n"); // test if RTC is running local_time=RTCGetTime(); printf("%02u:%02u:%02u %02u.%02u.%04u\n\r",local_time.RTC_Hour,local_time.RTC_Min,local_time.RTC_Sec ,local_time.RTC_Mday,local_time.RTC_Mon,local_time.RTC_Year ); while(1) { /* if(CheckDelay10ms(timer_value)) { timer_value = SetDelay10ms(1000); // delay 10 seconds // test if RTC is running local_time=RTCGetTime(); printf("%02u:%02u:%02u %02u.%02u.%04u\n\r",local_time.RTC_Hour,local_time.RTC_Min,local_time.RTC_Sec ,local_time.RTC_Mday,local_time.RTC_Mon,local_time.RTC_Year ); } */ } return(0); }
void systemInit(void) { RCC_ClocksTypeDef rccClocks; /////////////////////////////////// // Init cycle counter cycleCounterInit(); // SysTick SysTick_Config(SystemCoreClock / 1000); // Turn on peripherial clcoks RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC2, ENABLE); RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA1, ENABLE); RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA2, ENABLE); RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE); RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE); RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE); RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE); RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOE, ENABLE); RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1, ENABLE); RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C2, ENABLE); RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2, ENABLE); RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI3, ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE); RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE); RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE); RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE); RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM5, ENABLE); RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM6, ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM8, ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM10, ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM11, ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE); RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE); RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE); /////////////////////////////////// checkFirstTime(false); readEEPROM(); if (eepromConfig.receiverType == SPEKTRUM) checkSpektrumBind(); checkResetType(); NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); // 2 bits for pre-emption priority, 2 bits for subpriority /////////////////////////////////// gpsPortClearBuffer = &uart2ClearBuffer; gpsPortNumCharsAvailable = &uart2NumCharsAvailable; gpsPortPrintBinary = &uart2PrintBinary; gpsPortRead = &uart2Read; telemPortAvailable = &uart1Available; telemPortPrint = &uart1Print; telemPortPrintF = &uart1PrintF; telemPortRead = &uart1Read; /////////////////////////////////// initMixer(); usbInit(); ledInit(); uart1Init(); uart2Init(); BLUE_LED_ON; /////////////////////////////////// delay(10000); // 10 seconds of 20 second delay for sensor stabilization checkUsbActive(); #ifdef __VERSION__ cliPortPrintF("\ngcc version " __VERSION__ "\n"); #endif cliPortPrintF("\nAQ32Plus Firmware V%s, Build Date " __DATE__ " "__TIME__" \n", __AQ32PLUS_VERSION); if ((RCC->CR & RCC_CR_HSERDY) != RESET) { cliPortPrint("\nRunning on external HSE clock....\n"); } else { cliPortPrint("\nERROR: Running on internal HSI clock....\n"); } RCC_GetClocksFreq(&rccClocks); cliPortPrintF("\nHCLK-> %3d MHz\n", rccClocks.HCLK_Frequency / 1000000); cliPortPrintF( "PCLK1-> %3d MHz\n", rccClocks.PCLK1_Frequency / 1000000); cliPortPrintF( "PCLK2-> %3d MHz\n", rccClocks.PCLK2_Frequency / 1000000); cliPortPrintF( "SYSCLK-> %3d MHz\n\n", rccClocks.SYSCLK_Frequency / 1000000); initUBLOX(); delay(10000); // Remaining 10 seconds of 20 second delay for sensor stabilization - probably not long enough.. /////////////////////////////////// adcInit(); i2cInit(I2C1); i2cInit(I2C2); pwmServoInit(); rxInit(); spiInit(SPI2); spiInit(SPI3); timingFunctionsInit(); batteryInit(); initFirstOrderFilter(); initMavlink(); initMax7456(); initPID(); GREEN_LED_ON; initMPU6000(); initMag(); initPressure(); }
int main (void) { int ch = 0; int i = 0; // are we ready to relay scribbler output // by default we wait until we get a scribbler request from // the user before relaying scribbler messages via bluetooth int relay_scrib_messages = 0; // is the current command a scribbler command int scribbler_cmd = 0; // are we processing a get_info packet int get_info = 0; // setup the directionality of the pins setup_pins(); // setup the PLL - 60 MHz setup_pll(); // setup the instruction prefetch setup_mam(); // give some time to let everything settle msleep(100); // The scribbler UART(0) is 38400 8N1 uart0Init(B38400, UART_8N1, UART_FIFO_8); // setup UART 0 // The CM-5 UART (0) is 57600 8N1 // uart0Init(B57600, UART_8N1, UART_FIFO_8); // setup UART 0 // The Robonova UART (0) is 9600 or 115200 8N1 // uart0Init(B115200, UART_8N1, UART_FIFO_8); // setup UART 0 // The bluetooth UART(1) #if (VERSION_OF_BOARD == 3) uart1Init(B57600, UART_8N1, UART_FIFO_8); // setup UART 1 #else uart1Init(B460800, UART_8N1, UART_FIFO_8); // setup UART 1 #endif // synchronize with autobaud for (i = 1; i < 512; i++) { uart1Putch(i); } // Set up VIC and enable interrupts vic_init(); //set timer0 prescalaer to around 1 usec TIMER0_PR = 0x39; // Start timer0 for benchmarking TIMER0_TCR = 1; // Set up the transmit queue uart1_queue_init(); // setup interrupts for receiving IR messages ir_rx_init(); // set back configurable LED off set_led(0); // set front LED off led_off(); // turn IR power to 135 set_ir(135); // set external bluetooth to max; internal amplifier is throttled via pskeys set_bluetooth(255); // slow camera down write_camera(OV_CLKRC, 1); // turn off auto white balance //write_camera(OV_COMA, 0x14 & ~(1<<2)); // turn off auto gain and auto exposure //write_camera(OV_COMB, 0xA3 & ~(0x3)); //flush out any old characters for (i = 0; i < 200; i++) { getch(); } /* read in scribbler orientation * * - scribbler forward is stored as 0xDF in serial memory to avoid * coincidental settings */ read_mem(0, 0, &scribbler_orientation, 1); if (scribbler_orientation == 0xDF) { scribbler_orientation = 0; } else { scribbler_orientation = 1; } while (1) { //led_on(); ch = getch(); //led_off(); // body of the firmware - process the byte code sent over bluetooth if (ch != -1) { cur_rqst[rqst_idx] = ch; // process the cmd if its intended for the fluke if (rqst_idx == 0) { scribbler_cmd = 0; if (ch == SET_WINDOW) serve_set_window(); else if (ch == SET_RLE) serve_set_rle(); else if (ch == GET_RLE) serve_rle(); else if (ch == GET_BLOB) serve_blob(); else if (ch == GET_BLOB_WINDOW) serve_blob_window(); else if (ch == GET_IMAGE) serve_image(); else if (ch == GET_WINDOW) serve_image_window(); else if (ch == GET_WINDOW_LIGHT) serve_image_window_sum(); else if (ch == GET_BATTERY) serve_battery(); else if (ch == SET_DONGLE_LED_ON) led_on(); else if (ch == SET_DONGLE_LED_OFF) led_off(); else if (ch == SET_DIMMER_LED) serve_back_led(); else if (ch == SET_DONGLE_IR) serve_ir_power(); else if (ch == SET_RESET_SCRIBBLER) serve_reset_scribbler(); else if (ch == SET_RESET_SCRIBBLER2) serve_reset_scribbler2(); else if (ch == GET_SERIAL_MEM) serve_get_serial_mem(); else if (ch == SET_SERIAL_MEM) serve_set_serial_mem(); else if (ch == SET_SERIAL_ERASE) serve_erase_serial_mem(); else if (ch == GET_DONGLE_R_IR) serve_ir(0x1); else if (ch == GET_DONGLE_L_IR) serve_ir(0x2); else if (ch == GET_DONGLE_C_IR) serve_ir(0x4); else if (ch == SET_SCRIB_PROGRAM) serve_set_scrib_program(); else if (ch == SET_SCRIB_BATCH) serve_set_scrib_program_batch(); else if (ch == GET_SCRIB_PROGRAM) serve_get_scrib_program(); else if (ch == SET_START_PROGRAM) serve_start_scrib_program(); else if (ch == SET_START_PROGRAM2) serve_start_scrib2_program(); else if (ch == SET_UART0) serve_set_uart0(); else if (ch == SET_PASS_BYTE) serve_send_byte(); else if (ch == SET_PASSTHROUGH) serve_set_passthrough(); else if (ch == SET_PASS_N_BYTES) serve_set_pass_n_bytes(); else if (ch == SET_PASSTHROUGH_ON) relay_scrib_messages = 1; else if (ch == SET_PASSTHROUGH_OFF) relay_scrib_messages = 0; else if (ch == GET_PASS_N_BYTES) serve_get_pass_n_bytes(); else if (ch == GET_PASS_BYTES_UNTIL) serve_get_pass_bytes_until(); else if (ch == SET_FORWARDNESS) serve_set_forwardness(); else if (ch == SET_WHITE_BALANCE) serve_set_wb(); else if (ch == SET_NO_WHITE_BALANCE) serve_unset_wb(); else if (ch == GET_CAM_PARAM) serve_read_camera(); else if (ch == SET_CAM_PARAM) serve_write_camera(); else if (ch == SAVE_EEPROM) serve_save_eeprom(); else if (ch == RESTORE_EEPROM) serve_restore_eeprom(); else if (ch == UPDATE_FIRMWARE) serve_update_firmware(); else if (ch == WATCHDOG_RESET) serve_fluke_reset(); else if (ch == GET_JPEG_GRAY_HEADER) serve_jpeg_gray_header(); else if (ch == GET_JPEG_COLOR_HEADER)serve_jpeg_color_header(); else if (ch == GET_JPEG_GRAY_SCAN) serve_jpeg_gray_scan(); else if (ch == GET_JPEG_COLOR_SCAN) serve_jpeg_color_scan(); else if (ch == GET_VERSION) serve_version(); else if (ch == GET_IR_MESSAGE) serve_get_ir_message(); else if (ch == SEND_IR_MESSAGE) serve_send_ir_message(); else if (ch == SET_IR_EMITTERS) serve_set_ir_emitters(); else if (ch == GET_ROBOT_ID) serve_identify_robot(); else scribbler_cmd = 1; } if (scribbler_cmd) { // Flush if this is the first time we have talked to the scribbler if (relay_scrib_messages == 0) { for (i = 0; i < 100; i++) { uart0Getch(); } } relay_scrib_messages = 1; // we just got a GET_INFO request; pass it on to the scribbler if ((rqst_idx == 0) && (ch == GET_INFO)) { get_info = 1; } // scribbler should now have the whole GET_INFO request else if ((rqst_idx == 8) && get_info == 1) { get_info = 2; } // flip motors forward to backwards if ((cur_rqst[0] == SET_MOTORS) && scribbler_orientation && rqst_idx < 3) { // now send the packet with left/right swapped if ((rqst_idx == 2)) { uart0Putch(cur_rqst[0]); //msleep(10); uart0Putch(200-cur_rqst[2]); //msleep(10); uart0Putch(200-cur_rqst[1]); } } // pass on character to the scribbler else { uart0Putch(ch); } // take care of scribbler packet indexing rqst_idx ++; if (rqst_idx > 8) { rqst_idx = 0; } } } /* end if it received a request */ /* * if we are talking to the scribbler see if it has anything * for us to relay over the bluetooth link */ if (relay_scrib_messages) { ch = uart0Getch(); if (ch != -1) { // Process GET_INFO request we got the last character if (get_info > 500 && ch == 0x0A) { get_info = 0; } // Process GET_INFO we just sent our GET_INFO string if (get_info >= 500 && get_info < 50000) { putch(','); get_info = 50000; } putch(ch); } } /* * send our GET_INFO information * * the GET_INFO handling is pretty hideous to preserve backward * compatibility with other bluetooth serial and serial links. */ if (get_info > 1) { get_info ++; if (get_info == 400) { putstr(VERSION); get_info = 500; } if (get_info == 100000) { putch(0x0A); get_info = 0; } } update_low_battery_light(); } }
void uartInit(void) { // initialize both uarts uart0Init(); uart1Init(); }
int main(void) { #if defined(GATEWAY) || defined(DEBUG) || defined(GPS) // Initialise the UART0 block for printf output uart0Init(115200); #endif // Configure the multi-rate timer for 1ms ticks mrtInit(__SYSTEM_CLOCK/1000); /* Enable AHB clock to the Switch Matrix , UART0 , GPIO , IOCON, MRT , ACMP */ LPC_SYSCON->SYSAHBCLKCTRL |= (1 << 7) | (1 << 14) /*| (1 << 6)*//* | (1 << 18)*/ | (1 << 10) | (1 << 19); // Configure the switch matrix (setup pins for UART0 and SPI) configurePins(); LPC_GPIO_PORT->DIR0 |= (1 << GSM_PWR); RFM69_init(); #if defined(GATEWAY) || defined(DEBUG) || defined(GPS) mrtDelay(100); printf("Node Booted\r\n"); mrtDelay(100); #endif uart1Init(115200); GSM_On(); //GSM_AT(); #if defined(GATEWAY) || defined(DEBUG) || defined(GPS) printf("Node initialized, version %s\r\n",GIT_VER); #endif //Seed random number generator, we can use our 'unique' ID random_output = NODE_ID[0] + NODE_ID[1] + NODE_ID[2]; mrtDelay(5000); GSM_AT(); mrtDelay(5000); GSM_upload(); while(1) { GSM_AT(); incrementPacketCount(); //Clear buffer data_temp[0] = '\0'; uint8_t n; //Create the packet int int_temp; int_temp = RFM69_readTemp(); // Read transmitter temperature rx_rssi = RFM69_lastRssi(); // read the rssi threshold before re-sampling noise floor which will change it rssi_threshold = RFM69_lastRssiThreshold(); floor_rssi = RFM69_sampleRssi(); if(data_count == 97) { n = sprintf(data_temp, "%d%cL%s[%s]", NUM_REPEATS, data_count, LOCATION_STRING, NODE_ID); } else { #ifdef DEBUG n = sprintf(data_temp, "%d%cT%dR%d,%dC%dX%d,%dV%d[%s]", NUM_REPEATS, data_count, int_temp, rx_rssi, floor_rssi, rx_packets, rx_restarts, rssi_threshold, adc_result, NODE_ID); #else n = sprintf(data_temp, "%d%cT%dR%dX%d[%s]", NUM_REPEATS, data_count, int_temp, rx_rssi, rx_packets, NODE_ID); #endif } transmitData(n); GSM_upload(); awaitData(TX_GAP); } }