void main(void) { int i=0; EnableInterrupts; /* enable interrupts */ /* include your code here */ InitClock(); IIC1_Init(); configIIC(); /* IIC_Start(); IIC_write_byte(0x3D); IIC_write_byte(0x03); IIC_Stop(); */ //iic1=IIC_read_byte(); for(;;) { IIC_Start(); IIC_write_byte(0x3C); IIC_write_byte(0x03); IIC_Stop(FALSE); IIC_write_byte(0x3D); while(i<6){ iic1=IIC_read_byte(); i++; } i=0; IIC_Stop(FALSE); //__RESET_WATCHDOG(); /* feeds the dog */ } /* loop forever */ /* please make sure that you never leave main */ }
void init(){ GLCD_Ctrl (FALSE); // Init GPIO GpioInit(); #ifndef SDRAM_DEBUG // MAM init MAMCR_bit.MODECTRL = 0; MAMTIM_bit.CYCLES = 3; // FCLK > 40 MHz MAMCR_bit.MODECTRL = 2; // MAM functions fully enabled // Init clock InitClock(); // SDRAM Init SDRAM_Init(); #endif // SDRAM_DEBUG // Init VIC VIC_Init(); // GLCD init GLCD_Init (NULL, NULL); // Disable Hardware cursor GLCD_Cursor_Dis(0); // Touched indication LED USB_H_LINK_LED_SEL = 0; // GPIO USB_H_LINK_LED_FSET = USB_H_LINK_LED_MASK; USB_H_LINK_LED_FDIR |= USB_H_LINK_LED_MASK; __enable_interrupt(); // Enable GLCD GLCD_Ctrl (TRUE); }
/******************************************************************************* 関数名: void InitGame(void) 引数: なし 戻り値: なし 説明: ゲームの初期化処理 *******************************************************************************/ void InitGame(void) { //ゲームモードの初期化 SetGameStep(STEP_PLAY); //stageの初期化 SetStageMode(STAGE0); // ライトの初期化 InitLight(); //dome InitMeshDome( D3DXVECTOR3( 0, 0, 0), D3DXVECTOR3( 0, 0, 0), 1500.0f, 32, 32); //UI InitTime(); InitClock(D3DXVECTOR3(SCREEN_WIDTH/2 + 100, 70, 0)); InitGunSight(); InitNumLife(); InitEnemyNum(); //Model InitStageManager(true, INI_NUM_LIFE); //InitModel(); //グローバル変数の初期化 g_nCounterFrame = 0; g_nCounterShoot = 0; g_nCounterEShoot = 0; g_fTimeSpeed = 0.01f; g_bNeedRseet = false; g_bGameClear = false; }
void TestDS1302(void) { u8 i,tt[7],dd1[30],dd2[30]; DS1302_Configuration(); InitClock(); tt[0] = 0x13; tt[1] = 0x05; tt[2] = 0x23; tt[3] = 0x09; tt[4] = 0x25; tt[5] = 0x00; WriteDS1302Clock(tt); for(i=0;i<30;i++) { dd1[i] = i; dd2[i] = 0; } WriteDSRam(dd1,0,30); ReadDSRam(dd2,0,30); while(1) { ReadDS1302Clock(tt); } }
Player::Player(colour_t colour) { this->colour = colour; this->_moves = 0; InitClock(Player::ClockDefaultMoves, Player::ClockDefaultSeconds, Player::ClockDefaultIncr); }
int main(void) { // packets[0] = UPC-A Barcode // packets[1] = Item Name // packets[2] = Number of Servings // packets[3] = Scan Date (MM/DD/YYYY); char** packets; char return_key; char package[] = "<keypad><x>*/"; TRISGbits.TRISG7 = 1; //in breakout pin RF2 (row 1) TRISGbits.TRISG2 = 1; //in breakout pin RA2 (row 2) TRISCbits.TRISC0 = 1; //in breakout pin RB8 (row 3) TRISCbits.TRISC1 = 1;//in breakout pin RB9 (row 4) TRISEbits.TRISE12 = 0; //in breakout pin RB12 (col 1) TRISCbits.TRISC2 = 0; //in breakout pin RB10 (col 2) TRISEbits.TRISE14 = 0; //in breakout pin RB14 (col 3) ANSELGbits.ANSG7 = 0; //Row 1-4 //configuring all pins as digital ANSELGbits.ANSG2 = 0; ANSELCbits.ANSC0 = 0; ANSELCbits.ANSC1 = 0; ANSELEbits.ANSE12 = 0; //Col 1-3 ANSELCbits.ANSC2 = 0; ANSELEbits.ANSE14 = 0; InitClock(); InitUART2(); /* Infinite Loop */ while ( TRUE ) { if (rx_complete) { break; } return_key = 'X'; //initialize return key to default return variable from readKeyboard() while(return_key == 'X'){ //while nothing is pressed, keep on making calls return_key = readKeyboard(); } if(return_key != 'X'){ //if return_key is not default key, send to RPi package[9] = return_key; U1MODEbits.UARTEN = 1; // Re-enable UART if not already done printf("%s", package); } while(readKeyboard() != 'X'){ //no operation till next key is pressed. } } packets = get_barcode(); read_sd_card(packets); }
//======================================================================================== //---------------------------------------------+++--> SystemTray Clock ShellHook Procedure: LRESULT CALLBACK Hook_CallWndProc(int nCode, WPARAM wParam, LPARAM lParam) //-----+++--> {/// @todo : rewrite hooking code (use wrapper exe to hook it) CWPSTRUCT* pcwps = (CWPSTRUCT*)lParam; if(nCode >= 0 && pcwps && pcwps->hwnd) { // if this message is sent to the clock char classname[80]; if(!gs_hwndClock && GetClassNameA(pcwps->hwnd, classname, 80) && !strcmp(classname, "TrayClockWClass")) { InitClock(pcwps->hwnd); // initialize cf. wndproc.c PostMessage(gs_hwndTClockMain,MAINM_CLOCKINIT,0,(LPARAM)pcwps->hwnd); } } return CallNextHookEx(NULL, nCode, wParam, lParam); }
int main(void) { InitClock(); // This is the PLL settings InitUART2(); // Initialize UART2 for 9600,8,N,1 TX/RX InitPorts(); // LEDs outputs, Switches Inputs while(1) { // The ever versatile Infinite Loop! SoftwareDebounce(); } }
/*--------------------------------------------------------- hook procedure this function is called in explorer.exe process ----------------------------------------------------------*/ LRESULT CALLBACK CallWndProc(int nCode, WPARAM wParam, LPARAM lParam) { LPCWPSTRUCT pcwps = (LPCWPSTRUCT)lParam; if(nCode == HC_ACTION && pcwps && pcwps->hwnd) { if(!g_bInitClock /*&& pcwps->hwnd == g_hwndClock*/) { InitClock(g_hwndClock); // main2.c } } return CallNextHookEx(g_hhook, nCode, wParam, lParam); }
static inline void Init() { InitClock(clk8MHzInternal); klJtagDisable(); Delay.Init(); Uart.Init(115200); Uart.Printf("\rMagicOrb\r"); // Setup CC CC.Init(); CC.SetChannel(CC_CHNL); Led.Init(); }
void main(void) { // DbgPin::SetDirWrite(); //DbgPin2::SetDirWrite(); LedPwmPin::SetDirWrite(); InitClock(); Timer0::Start(Timer0::Normal, Timer0::Div8); Timer0::InterruptEnable(); CCR0 = PwmPeriod - PwmDutyCycle; Timer0::CCInteruptEnable<0>(); P1IE |= (1 << Button1::Number); P1IES |= (1 << Button1::Number); P1IFG = 0; _BIS_SR(LPM0_bits + GIE); // Enter LPM0 w/ interrupt }
void rt_hw_rtc_init(void) { InitClock(); rtc.type = RT_Device_Class_RTC; rtc.init = RT_NULL; rtc.open = rt_rtc_open; rtc.close = RT_NULL; rtc.read = rt_rtc_read; rtc.write = RT_NULL; rtc.control = rt_rtc_control; rtc.user_data = RT_NULL; rt_device_register(&rtc, "rtc", RT_DEVICE_FLAG_RDWR); init_per_get_time(); }
void TFC_Init() { InitClock(); /* Initialize clock system for 48 MHz */ InitSysTick(); /* Configure the timer and the interrupt to be used to generate the tick of the scheduler */ TFC_InitGPIO(); TFC_InitServos(); TFC_InitMotorPWM(); TFC_InitADCs(); TFC_InitLineScanCamera(); TFC_InitTerminal(); TFC_InitUARTs(); TFC_HBRIDGE_DISABLE; TFC_SetMotorPWM(0,0); TFC_RGB_Init(); TFC_Accel_Init(); }
int main(void) { char start_char; uint16_t n_chars; /* Clock setup */ InitClock(); /* Program Timer 1 to raise interrupts */ T1_program(); /* Init leds */ EE_leds_init(); EE_demoboard_leds_init(); console_init(); USART_printf("Hello From Erika RTOS, press t to run the benchmark \r\n"); //calcRawSpeed(); do{ readChar(&start_char); }while(start_char != 't'); //USART_printf("T ok \r\n"); stop = 0; uint8_t i; calcRawSpeed(); initState(kwips_rawspeed, initAlarms, initFreq, initKWPP); //for(i=0; i<9999; i++){} ActivateTask(SuperTask); //for(i=0; i<9999; i++){} StartOS(OSDEFAULTAPPMODE); /* Forever loop: background activities (if any) should go here */ for (;;); return 0; }
int main(void) { pInt8U pBuffer; Int32U Size,TranSize; int i=0,j; int k=0; int cnt=0; int tempcnt=0; int concurCnt = 0; Flo64 curP, curQ; int meanCalc=1,displayIntro=1; AlgoPowers_t PowerLines[3]; AlgoPowers_t prevPLines; AlgoPowers_t curPLines; int LearnNewMean = 1; int learning =1; int recognized=0; int plugOut = 0; Flo64 cInterval = 5000; int debug = 0; // int deviceCnt[3] = {0}; //AlgoLine_t TestLine; // pAlgoLine_t pTestLine=&TestLine; AlgoDevice_t tmpDev; // AlgoDevice_t devProfiles[3]={0}; AlgoDevice_t devProfiles[3]; int devNum=0; bool addDevice = 1; Int32S devLamps[3]; #if CDC_DEVICE_SUPPORT_LINE_CODING > 0 CDC_LineCoding_t CDC_LineCoding; UartLineCoding_t UartLineCoding; #endif // CDC_DEVICE_SUPPORT_LINE_CODING > 0 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // GUI init START ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // initialize touch parametres Int32U cursor_x = (C_GLCD_H_SIZE - CURSOR_H_SIZE)/2, cursor_y = (C_GLCD_V_SIZE - CURSOR_V_SIZE)/2; ToushRes_t XY_Touch; Boolean Touch = FALSE; GLCD_Ctrl (FALSE); // Init GPIO GpioInit(); #ifndef SDRAM_DEBUG // MAM init MAMCR_bit.MODECTRL = 0; MAMTIM_bit.CYCLES = 3; // FCLK > 40 MHz MAMCR_bit.MODECTRL = 2; // MAM functions fully enabled // Init clock InitClock(); // SDRAM Init SDRAM_Init(); #endif // SDRAM_DEBUG // Init VIC ---interrupt VIC_Init(); // GLCD init GLCD_Init (NULL, NULL); GLCD_Cursor_Dis(0); GLCD_Copy_Cursor ((Int32U *)Cursor, 0, sizeof(Cursor)/sizeof(Int32U)); GLCD_Cursor_Cfg(CRSR_FRAME_SYNC | CRSR_PIX_32); GLCD_Move_Cursor(cursor_x, cursor_y); GLCD_Cursor_En(0); // Init touch screen TouchScrInit(); // Touched indication LED USB_H_LINK_LED_SEL = 0; // GPIO USB_H_LINK_LED_FSET = USB_H_LINK_LED_MASK; USB_H_LINK_LED_FDIR |= USB_H_LINK_LED_MASK; // Init UART 0 UartInit(UART_0,0,NORM); __enable_interrupt(); GLCD_Ctrl (TRUE); ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // GUI init END ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /* devProfiles[0].dP= 101366.22; //blow dryer devProfiles[0].dQ =51765.90; devProfiles[1].dP= 35957.14; //light bulb devProfiles[1].dQ = 9045.64; */ // GLCD_print("Device char %f %f\r\n",devProfiles[devNum].dP, devProfiles[devNum].dQ ); ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Update the baud rate UartLineCoding.dwDTERate = 115200; // Update the stop bits number UartLineCoding.bStopBitsFormat = UART_ONE_STOP_BIT; // Update the parity type UartLineCoding.bParityType = UART_NO_PARITY; // Update the word width UartLineCoding.bDataBits = (UartWordWidth_t)(3); //Description: Init UART Baud rate, Word width, Stop bits, Parity type UartSetLineCoding(UART_0,UartLineCoding); ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //calculate the no load powerlines //calcMeanRange(&prevPLines); // GLCD_print("P %f %f\n\r",prevPLines.P.CiHigh, prevPLines.P.CiLow); ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// for(i=0; i<3; i++){ devProfiles[i].dP=0; devProfiles[i].dQ=0; devLamps[i]=0; } // initialize gui //gui_monitoringScreen(devProfiles,devLamps); gui_mainScreen(); GLCD_SetFont(&Terminal_6_8_6,0x0000FF,0x000cd4ff); GLCD_SetWindow(0,0,319,239); GLCD_TextSetPos(0,0); //calculate the no load powerlines calcMeanRange(&prevPLines); while(1) { /////////////////////////////////////////////////////////////////////////////// GLCD_SetFont(&Terminal_6_8_6,0x0000FF,0x000cd4ff); GLCD_SetWindow(0,0,319,239); GLCD_TextSetPos(0,0); ///////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////// //algo START ///////////////////////////////////////////////////////////////////////////////// if(dataReady){ dataReady=0; GLCD_print("%s\r\n",dataArray); // GLCD_print("reach reach!!!\r\n"); //convert the incoming data to floats dataConversion(dataArray, dataP, dataQ, dataT, cnt); //keep track of devices GLCD_print("Device zero:%d one:%d two:%d\r",devLamps[0], devLamps[1],devLamps[2]); concurCnt=0; //detect a step change. if(detectStepChange(&prevPLines, dataP[cnt], dataQ[cnt] )){ tempcnt=(int) fmod(cnt+4,45); while(cnt != tempcnt){ if(dataReady){ dataConversion(dataArray, dataP, dataQ, dataT, cnt); if(detectStepChange(&prevPLines, dataP[cnt], dataQ[cnt] )){ concurCnt++; } cnt++; dataReady=0; if(cnt>=45){ cnt=0; } } } if(concurCnt>=3){ //calculate new powerlines calcMeanRange(&curPLines); tmpDev.dP = curPLines.P.mean - prevPLines.P.mean; tmpDev.dQ = curPLines.Q.mean - prevPLines.Q.mean; GLCD_print("test dev dP is %f\r\n",tmpDev.dP); GLCD_print("test dev dQ is %f\r\n",tmpDev.dQ); //in learning phase if(screen==1){ // GLCD_print("we can now add DEVICES!!!\r\n"); if(devNum==3){ GLCD_print("Can't learn anymore devices\r\n"); learning=0; } else{ if(tmpDev.dP>0 && tmpDev.dQ>0){ GLCD_print("add device or not?\r\n"); if(addDevice){ devProfiles[devNum].dP = tmpDev.dP; devProfiles[devNum].dQ = tmpDev.dQ; GLCD_print("new profile %d p:%f q:%f\r\n",devNum, tmpDev.dP,tmpDev.dQ); devNum++; } } else{ GLCD_print("device is unplugged\r\n"); //DO THE CHECK // determineDevice(devProfiles,tmpDev,&devNum,devLamps); //gui_monitoringScreen(devProfiles,devLamps); } } } //in user phase else if (screen==0){ if(devNum==0){ GLCD_print("No devices on file. Please enter learning mode"); } else{ //check aganst known devices for(k=0;k<3;k++){ GLCD_print("devProfile %d p:%f q:%f\r\n",k, devProfiles[k].dP, devProfiles[k].dQ); //if plugging out, the deltas will be negative if(tmpDev.dP<0 && tmpDev.dQ<0){ plugOut=1; tmpDev.dP = fabs(tmpDev.dP); tmpDev.dQ = fabs(tmpDev.dQ); } if(withinRange(tmpDev,devProfiles[k],cInterval)){ if(plugOut){ GLCD_print("device %d unplugged!\r\n",k); plugOut=0; devLamps[k]=0; } else{ GLCD_print("device %d plugged in!\r\n",k); devLamps[k]=1; } gui_monitoringScreen(devProfiles,devLamps); break; } } } // end of if(devNum>0) } // end user phase prevPLines = curPLines; GLCD_print("prevPlines %f, %f\r",prevPLines.P,prevPLines.Q); } // end of (concurCnt>=3) } // end of detectStepChange() cnt++; //dataReady=0; if(cnt >= 45){ cnt=0; } } // end of dataReady ///////////////////////////////////////////////////////////////////////////////// // End of Algo ///////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////// // GUI start ///////////////////////////////////////////////////////////////////////////////// if(TouchGet(&XY_Touch)) { cursor_x = XY_Touch.X; cursor_y = XY_Touch.Y; GLCD_Move_Cursor(cursor_x, cursor_y); if (FALSE == Touch) { Touch = TRUE; USB_H_LINK_LED_FCLR = USB_H_LINK_LED_MASK; } } // check the need to swtich screen else if(Touch) { switch(screen) { case 0: // 0 = Monitoring screen // Touch logic if(modeButtonState) { if (cursor_x <= 80 && cursor_y >= 190) { gui_toggleMode(devProfiles,devLamps); break; } } if(settingsButtonState) { if (cursor_x >= 239 && cursor_y >= 190) { gui_settingsScreen(); break; } } // Back button if (cursor_x <= 59 && cursor_y <= 59) { gui_mainScreen(); break; } break; case 1: // 1 = Learning screen // Touch logic if(modeButtonState) { if (cursor_x <= 80 && cursor_y >= 190) // mode { gui_toggleMode(devProfiles,devLamps); break; } } if(addDeviceButtonState) { // add device button placement (80,70,240,120) if (cursor_x >= 80 && cursor_y >= 70 && cursor_x <= 240 && cursor_y <= 120) { addDevice = 1; //gui_addDeviceScreen(); break; } } // Back button if (cursor_x <= 59 && cursor_y <= 59) { gui_mainScreen(); break; } break; case 2: // 2 = Devices screen // Back button if (cursor_x <= 59 && cursor_y <= 59) { gui_mainScreen(); break; } break; case 3: // 3: Webserver screen // Back button if (cursor_x <= 59 && cursor_y <= 59) { gui_mainScreen(); break; } break; case 4: // 4: Inormation Screen // Back button if (cursor_x <= 59 && cursor_y <= 59) { gui_mainScreen(); break; } break; case 5: // 5: Settings Screen // Back button if (cursor_x <= 59 && cursor_y <= 59) { gui_mainScreen(); break; } break; case 9: // 9: Main Screen // Monitor Button if (cursor_x >= 59 && cursor_y >= 64 && cursor_x <= 119 && cursor_y <= 124) { gui_monitoringScreen(devProfiles,devLamps); break; } // Learn Button else if (cursor_x >= 129 && cursor_y >= 64 && cursor_x <= 189 && cursor_y <= 124) { gui_learningScreen(); break; } // Devices Button else if (cursor_x >= 199 && cursor_y >= 64 && cursor_x <= 259 && cursor_y <= 124) { gui_devicesScreen(); break; } // Server Button else if (cursor_x >= 59 && cursor_y >= 134 && cursor_x <= 119 && cursor_y <= 194) { gui_serverScreen(); break; } // Info Button else if (cursor_x >= 129 && cursor_y >= 134 && cursor_x <= 189 && cursor_y <= 194) { gui_infoScreen(); break; } // Settings Button else if (cursor_x >= 199 && cursor_y >= 134 && cursor_x <= 259 && cursor_y <= 194) { gui_settingsScreen(); break; } break; } USB_H_LINK_LED_FSET = USB_H_LINK_LED_MASK; Touch = FALSE; } ///////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////// } }
void main(void) { int t=15; /* include your code here */ f1.functionId=ULTRASONIC_FRONT; f1.status=READY; f1.root=UNIQUE_FUNCTION; f1.timerCount=50; DisableInterrupts; InitReg(); InitClock(); InitComunication(); InitPorts(); InitInputCompare(); InitKbi(); beginComunication(); initExecutingVector(); InitBuffer(&bufferIn); InitBuffer(&bufferOut); InitPwm(); InitADC(); EnableInterrupts; InitRtc(); /* despues de habilitar interrupciones y antes de empezar a mover el robot debe calibrar sensores de meta no arrancar el motor sin antes ejecutar initGoalSensor()! */ initGoalSensor(); setPwmValue(t); if(t>35){ kbiSampleFreq=1000; }else{ kbiSampleFreq=1000+((35-t)*200); } for(;;) { if(goalStatus == 0){ PTDD_PTDD1; setGoalMode(STOP_ON_GOAL); SENTIDO_M1_1=1; SENTIDO_M1_2=0; SENTIDO_M2_1=1; SENTIDO_M2_2=0; SENSOR_DE_META_ON; PTDD_PTDD0=1; /* functionHandler(); dispatcher(&executingVector,&bufferOut); frameGenerator();*/ /* f1.functionId=ULTRASONIC_FRONT; f1.status=READY; getUltrasonic(&f1); while(f1.status!=AVAILABLE); t=3000; while(t!=0){ t--; } */ /* f1.functionId=ULTRASONIC_FRONT; f1.status=READY; f1.root=UNIQUE_FUNCTION; f1.timerCount=50; getUltrasonic(&f1); while(f1.status!=AVAILABLE); t=3000; while(t!=0){ t--; } */ /* f1.functionId=ULTRASONIC_RIGHT; f1.status=READY; getUltrasonic(&f1); while(f1.status!=AVAILABLE); t=30000; while(t!=0){ t--; } */ } /* loop forever */ } /* please make sure that you never leave main */ }
/************************************************************************* * Function Name: main * Parameters: none * * Return: none * * Description: main * *************************************************************************/ int main(void) { typedef Int32U ram_unit; // int cursor_x = (C_GLCD_H_SIZE - CURSOR_H_SIZE)/2, cursor_y = (C_GLCD_V_SIZE - CURSOR_V_SIZE)/2; // unsigned long int deltaT; static float freq_aveg; int LCD_updatecount; LCD_updatecount = 0; //From uip start unsigned int i; uip_ipaddr_t ipaddr; struct timer periodic_timer, arp_timer; //From uip end /*** COMPARE FIX POINT 523235 ***/ /*** COMPARE FIX POINT 523235 ***/ GLCD_Ctrl (FALSE); // Init GPIO GpioInit(); #ifndef SDRAM_DEBUG // MAM init MAMCR_bit.MODECTRL = 0; MAMTIM_bit.CYCLES = 3; // FCLK > 40 MHz MAMCR_bit.MODECTRL = 2; // MAM functions fully enabled // Init clock InitClock(); // SDRAM Init SDRAM_Init(); #endif // SDRAM_DEBUG // Init VIC VIC_Init(); // GLCD init // GLCD_Init (IarLogoPic.pPicStream, NULL); // Can be removed, remember to remove the h and c file as well // GLCD_Init (LogoPic.pPicStream, NULL); // Can be removed, remember to remove the h and c file as well GLCD_Init (what_is_a_blissPic.pPicStream, NULL); GLCD_Cursor_Dis(0); //From uip // GLCD_Cursor_Dis(0); // GLCD_Copy_Cursor ((Int32U *)Cursor, 0, sizeof(Cursor)/sizeof(Int32U)); /*** COMPARE FIX POINT 534252 ***/ /*** COMPARE FIX POINT 534252 ***/ GLCD_Cursor_Cfg(CRSR_FRAME_SYNC | CRSR_PIX_32); //From uip // GLCD_Cursor_Cfg(CRSR_FRAME_SYNC | CRSR_PIX_64); // GLCD_Move_Cursor(cursor_x, cursor_y); // GLCD_Cursor_En(0); //From uip start // Sys timer init 1/100 sec tick clock_init(2); timer_set(&periodic_timer, CLOCK_SECOND / 2); timer_set(&arp_timer, CLOCK_SECOND * 10); //From uip end // Init USB Link LED USB_D_LINK_LED_SEL = 0; // GPIO USB_D_LINK_LED_FSET = USB_D_LINK_LED_MASK; USB_D_LINK_LED_FDIR |= USB_D_LINK_LED_MASK; USB_H_LINK_LED_SEL = 0; // GPIO USB_H_LINK_LED_FSET = USB_H_LINK_LED_MASK; USB_H_LINK_LED_FDIR |= USB_H_LINK_LED_MASK; /*-----------------------------------------------------------------*/ // Init AD0[3] for current meassurement PINSEL1_bit.P0_26 = 1; // Assign P26 to AD0[3], page 180 PINMODE1_bit.P0_26 = 2; // //Neither pull-up or pull-down // PCONP_bit.PCAD = 1; // Note: Clear the PDN bit in the AD0CR before clearing this bit and set this before PDN // Other initial parameters are already set // AD0CR_bit.SEL = 8; // select Ch3 [1111] current_amp = 0; /*-----------------------------------------------------------------*/ // Init the DAC converter //Clock: In the PCLK_SEL0 register (Table 4�), select PCLK_DAC //PCLKSEL0_bit.PCLK_DAC = 3UL;// **HAS Desided for values yet!** // '11' at bit 23 and 22 (which is CCLK/8) //or use 0x3 for 3UL instead //Pins: Select the DAC pin and pin mode in registers PINSEL1 and PINMODE1 (see Section 9�. //PINSEL1 |= (2UL<<20); // PINSEL1_bit.P0_26 = 1; //?? //PINSEL1_bit.P0_26 = 2UL; //"PINMODE registers control the on-chip pull-up/pull-down resistor feature for all GPIO ports." - page 178 //PINMODE1 |= ________; // See table 128 for values. Write to bit 21:20 //PINMODE1_bit.P0_26 = 2UL; //P0.26MODE = 2UL; //Neither pull-up or pull-down /* ------------------------------------------------------------------*/ // Init ADC converter // Power the ADC converter PINSEL1_bit.P0_25 = 1; // Assign Pin 25 to ADO[2] PINMODE1_bit.P0_25 = 1; // Neither pull-up or pull-dow PCONP_bit.PCAD = 1; // Note: Clear the PDN bit in the AD0CR before clearing this bit and set this before PDN AD0CR_bit.PDN = 1; // A/D converter is operational AD0CR_bit.START = 0; // Conversion not started AD0CR_bit.BURST = 0; // disable burst // AD0CR_bit.SEL = 4; // select Ch2 [11] // Select number of clocks for each conversion AD0CR_bit.CLKS = 0; // [000] 11 clocks / 10 bits AD0CR_bit.CLKDIV = SYS_GetFpclk(ADC_PCLK_OFFSET)/ 10000; // 4500000; // Should be equal to 10K samplingrate ADINTEN_bit.ADGINTEN = 1; // Global A/D channels enabled by ADINTEN 7:0 // Since only on channel is used at the moment the global flag is enabled VIC_SetVectoredIRQ(AD0IntrHandler,1,VIC_AD0); // Set the interrupt call VICINTENABLE |= 1UL << VIC_AD0; // Setting parameters for the low-pass filter DACR_previous = 0; // Initialize DACR_temp which is y(i-1) deltaT = 1.0/TIMER0_TICK_PER_SEC; // Set the sample rate // Calculate the R*C for cut-off frequency of the low pass filter alpha = deltaT/(1./(2.*3.1416*100.) + deltaT); // Cut-off = 100 Hz done = 0; // Channel stage /* ------------------------------------------------------------------*/ // Setting the port to P0[11] and P0[19] PINSEL1_bit.P0_19 = 0; // GPIO to P0[19] PINSEL0_bit.P0_11 = 0; // GPIO to P0[11] PINMODE1_bit.P0_19 = 2; // Pin has neither pull up or down PINMODE0_bit.P0_11 = 2; // Pin has neither pull up or down FIO0DIR_bit.P0_19 = 1; FIO0CLR = (1UL<<19); FIO0DIR_bit.P0_11 = 1; FIO0CLR = (1UL<<11); FIO0PIN_bit.P0_19 = 1; FIO0PIN_bit.P0_11 = 1; /* ------------------------------------------------------------------*/ // Enable TIM0 clocks PCONP_bit.PCTIM0 = 1; // enable clock // Init Time0 T0TCR_bit.CE = 0; // counting disable T0TCR_bit.CR = 1; // set reset T0TCR_bit.CR = 0; // release reset T0CTCR_bit.CTM = 0; // Timer Mode: every rising PCLK edge T0MCR_bit.MR0I = 1; // Enable Interrupt on MR0 T0MCR_bit.MR0R = 1; // Enable reset on MR0 T0MCR_bit.MR0S = 0; // Disable stop on MR0 // set timer 0 period T0PR = 0; T0MR0 = SYS_GetFpclk(TIMER0_PCLK_OFFSET)/(TIMER0_TICK_PER_SEC); // init timer 0 interrupt T0IR_bit.MR0INT = 1; // clear pending interrupt VIC_SetVectoredIRQ(Timer0IntrHandler,0,VIC_TIMER0); VICINTENABLE |= 1UL << VIC_TIMER0; T0TCR_bit.CE = 1; // counting Enable __enable_interrupt(); GLCD_Ctrl (TRUE); #if 0 SDRAM_Test(); #endif /* // SMB380_Init(); SMB380_GetID(&Smb380Id, &Smb380Ver); SMB380_Data_t XYZT; */ /*** COMPARE FIX POINT 856364 ***/ /*** COMPARE FIX POINT 856364 ***/ /*** COMPARE FIX POINT 856364 ***/ /*** COMPARE FIX POINT 856364 ***/ //From uip start GLCD_SetFont(&Terminal_18_24_12,0x000000,0x000cd4ff); GLCD_SetWindow(85,10,255,33); GLCD_TextSetPos(0,0); GLCD_print("\f Room Station"); //From uip start /*** COMPARE FIX POINT 458923 ***/ /*** COMPARE FIX POINT 458923 ***/ // GLCD_SetWindow(5,200,319,239); // GLCD_SetFont(&Terminal_6_8_6,0x0000FF,0x000cd4ff); // Initialize the ethernet device driver do { GLCD_TextSetPos(0,0); } while(!tapdev_init()); GLCD_TextSetPos(0,0); // uIP web server // Initialize the uIP TCP/IP stack. uip_init(); uip_ipaddr(ipaddr, 192,168,0,100); uip_sethostaddr(ipaddr); uip_ipaddr(ipaddr, 192,168,0,1); uip_setdraddr(ipaddr); uip_ipaddr(ipaddr, 255,255,255,0); uip_setnetmask(ipaddr); // Initialize the HTTP server. httpd_init(); /*** COMPARE FIX POINT 4572742 ***/ /*** COMPARE FIX POINT 4572742 ***/ /*** COMPARE FIX POINT 4572742 ***/ /*** COMPARE FIX POINT 4572742 ***/ /*** WHILE LOOP START ***/ while(1) { /*** COMPARE FIX POINT 938194 ***/ /*** COMPARE FIX POINT 938194 ***/ /*** COMPARE FIX POINT 938194 ***/ /*** COMPARE FIX POINT 938194 ***/ /*** COMPARE FIX POINT 938194 ***/ uip_len = tapdev_read(uip_buf); if(uip_len > 0) { if(BUF->type == htons(UIP_ETHTYPE_IP)) { uip_arp_ipin(); uip_input(); /* If the above function invocation resulted in data that should be sent out on the network, the global variable uip_len is set to a value > 0. */ if(uip_len > 0) { uip_arp_out(); tapdev_send(uip_buf,uip_len); } } else if(BUF->type == htons(UIP_ETHTYPE_ARP)) { uip_arp_arpin(); /* If the above function invocation resulted in data that should be sent out on the network, the global variable uip_len is set to a value > 0. */ if(uip_len > 0) { tapdev_send(uip_buf,uip_len); } } } else if(timer_expired(&periodic_timer)) { timer_reset(&periodic_timer); for(i = 0; i < UIP_CONNS; i++) { uip_periodic(i); /* If the above function invocation resulted in data that should be sent out on the network, the global variable uip_len is set to a value > 0. */ if(uip_len > 0) { uip_arp_out(); tapdev_send(uip_buf,uip_len); } } #if UIP_UDP for(i = 0; i < UIP_UDP_CONNS; i++) { uip_udp_periodic(i); /* If the above function invocation resulted in data that should be sent out on the network, the global variable uip_len is set to a value > 0. */ if(uip_len > 0) { uip_arp_out(); tapdev_send(); } } #endif /* UIP_UDP */ /* Call the ARP timer function every 10 seconds. */ if(timer_expired(&arp_timer)) { timer_reset(&arp_timer); uip_arp_timer(); } } #define AVERAGECOUNT 100000 if(LCD_updatecount <= AVERAGECOUNT) { ++LCD_updatecount; freq_aveg += freq; } else { freq_aveg = freq_aveg/AVERAGECOUNT; updateFreqHistory(freq_aveg); //Must be kept together with freq calculation! GLCD_SetWindow(20,55,150,80); GLCD_SetFont(&Terminal_18_24_12,0x000000,0x009fee00); GLCD_TextSetPos(0,5); GLCD_print("\f Hz %3.3f", freq_aveg); freq_aveg = 0; GLCD_SetWindow(20,90,150,115); GLCD_SetFont(&Terminal_18_24_12,0x000000,0x009fee00); GLCD_TextSetPos(0,5); GLCD_print("\f V %3.3f", sqrtf(vol_rms_result)); updateVoltageHistory(sqrtf(vol_rms_result)); GLCD_SetWindow(20,125,150,150); GLCD_SetFont(&Terminal_18_24_12,0x000000,0x009fee00); GLCD_TextSetPos(0,5); GLCD_print("\f uA %3.3f", sqrtf(current_amp)); GLCD_SetWindow(20,160,150,185); GLCD_SetFont(&Terminal_18_24_12,0x000000,0x009fee00); GLCD_TextSetPos(0,5); GLCD_print("\f uP %3.3f", sqrtf(vol_rms_result)*sqrtf(current_amp)); LCD_updatecount = 0; } }//while(1) loop }//main function
bool InitProgram(void){ // GC_INIT(); bool ret; #if !defined(FOR_MACOSX) RADIUM_ensure_bin_packages_gc_is_used(); #endif printf("Initializing...\n"); printf("...Error handler\n"); Error_init(); printf("...Memory handler\n"); init_memory(); root=tralloc(sizeof(struct Root)); if(root==NULL){ fprintf(stderr,"Not enough memory\n"); return false; } root->keyoct=36; root->quantitize_options = Quantitize_get_default_options(); root->grid_numerator=1; root->grid_denominator=1; root->min_standardvel=MAX_VELOCITY*40/100; root->standardvel=MAX_VELOCITY*80/100; ATOMIC_SET(root->editonoff, true); ATOMIC_SET(root->play_cursor_onoff, false); ATOMIC_SET(root->editor_follows_play_cursor_onoff, true); root->song=talloc(sizeof(struct Song)); pc=tralloc(sizeof(PlayerClass)); if(root->song==NULL || pc==NULL){ fprintf(stderr,"Not enough memory\n"); return false; } pc->pfreq = 48000; // Default value. Should be overridden in MIXER_start(). /* if( ( ! InitPEQmempool(1000) ) || ( ! Input_Init(4000) ) ){ // 1000 and 4000 are hardcoded values. Not good. return false; } */ printf("...Midi\n"); MIDI_input_init(); SCHEDULER_init(); PATCH_init(); printf("...Sound\n"); if(MIXER_start()==false){ fprintf(stderr,"Could not open Sound\n"); return false; } printf("...Player 1/2\n"); if( ( ! InitPEQmempool() ) ){ // 1000 and 4000 are hardcoded values. Not good. return false; } printf("...Clock handler\n"); if( ! InitClock() ) return false; printf("...Player 2/2\n"); PEQ_GetType_Init(); printf("...Instrument\n"); if( OpenInstruments()==false ){ return false; } printf("...Kebang\n"); ret=NewSong(); #if !USE_OPENGL printf("...Blitting\n"); if(ret==true){ Blt_blt(root->song->tracker_windows); } #endif printf("Initialization finished.\n"); return ret; }
int main(void) { InitClock(); SerialInit(); RingBufferInit(&location_buffer, 4, locations); PORTC.DIRSET = 0xF3; PORTE.DIRSET = 0xFF; PORTD.DIRSET = 0x33; PORTB.DIRCLR = 0xFF; /* PortB all inputs */ /* Timers */ //x_axis.step_timer = &TCC1; x_axis.pwm_timer = &TCC0; /* Limit Switches */ x_axis.limit_switch_port = &PORTB; x_axis.limit_switch_mask = (1<<0); /* PORTB.0 */ /* DIR ports (for inverting the stepper motor driver polarity) */ x_axis.sign_select_port = &PORTC; x_axis.sign_switch_mask1 = 0x20; /* PORTC.5 */ x_axis.sign_switch_mask2 = 0x10; /* PORTC.4 */ /* PWM outputs: outputs will be 90 degrees out of phase */ x_axis.phase_pwm_cmp1 = &(TCC0.CCB); x_axis.phase_pwm_cmp2 = &(TCC0.CCA); x_axis.compare_mask = TC0_CCBEN_bm | TC0_CCAEN_bm; /* Power Controls change the period: a longer period means longer off time and lower duty cycle */ //x_axis.axis_idle_power = 60; x_axis.axis_run_power = 31; /* The minimum period of the PWM update timer/counter */ /* Stepper motor tick period = 32 * min_period / 16000000 */ //x_axis.min_period = 15; AxisInit (&x_axis); //y_axis.step_timer = &TCD1; y_axis.pwm_timer = &TCD0; y_axis.limit_switch_port = &PORTB; y_axis.limit_switch_mask = (1<<1); /* PORTB.1 */ y_axis.sign_select_port = &PORTD; y_axis.sign_switch_mask1 = 0x20; y_axis.sign_switch_mask2 = 0x10; y_axis.phase_pwm_cmp1 = &(TCD0.CCB); y_axis.phase_pwm_cmp2 = &(TCD0.CCA); y_axis.compare_mask = TC0_CCBEN_bm | TC0_CCAEN_bm; //y_axis.axis_idle_power = 60; y_axis.axis_run_power = 31; //y_axis.min_period = 15; AxisInit (&y_axis); //z_axis.step_timer = &TCE1; z_axis.pwm_timer = &TCE0; z_axis.limit_switch_port = &PORTB; z_axis.limit_switch_mask = (1<<2); /* PORTB.2 */ z_axis.sign_select_port = &PORTE; z_axis.sign_switch_mask1 = 0x20; /* PORTE.5 */ z_axis.sign_switch_mask2 = 0x10; /* PORTE.4 */ z_axis.phase_pwm_cmp1 = &(TCE0.CCD); z_axis.phase_pwm_cmp2 = &(TCE0.CCC); z_axis.compare_mask = TC0_CCDEN_bm | TC0_CCCEN_bm; //z_axis.axis_idle_power = 60; z_axis.axis_run_power = 31; /* 33 unique waveform values: 0 (ground) to 33 (3.3v) */ //z_axis.min_period = 15; AxisInit (&z_axis); PMIC.CTRL |= PMIC_LOLVLEN_bm | PMIC_MEDLVLEN_bm | PMIC_HILVLEN_bm; // Fire up the timer for incrementing/decrementing steps TC0_t * step_timer = &TCC1; step_timer->CTRLB = TC_WGMODE_SS_gc; /* Overflow every 1 ms: 16Mhz / (64 * 250) = 1ms */ step_timer->PER = 250; step_timer->CTRLA = TC_CLKSEL_DIV64_gc; step_timer->CTRLFSET = TC_CMD_RESTART_gc; /* Enable the step overflow interrupt */ step_timer->INTCTRLA |= TC_OVFINTLVL_LO_gc; // To Disable: axis->step_timer->INTCTRLA &= ~TC1_OVFINTLVL_gm; char task = 0; sei(); while(1) { //PORTE.OUTTGL = 0x02; //_delay_ms (10); //SerialData * s = SerialDataTransmitStruct(); //if (s != 0) //{ // s->transmit_data[0] = 'a'; // s->transmit_data[1] = 'b'; // s->transmit_data[2] = 'c'; // SerialTransmit(s, 0x00, 3); //} SerialData * s = SerialDataAvailable(); if (s != 0) { switch (s->receive_data[0]) { case 0x88: // Reset everything (all axis back to limit switches) { task = TASK_LIMIT_SWITCH_Y; x_axis.state = 1; y_axis.state = 1; z_axis.state = 1; s->transmit_data[0] = 0x88; SerialTransmit (s, 0x00, 1); // Transmit to master device break; } case 0x77: // Ping (and location/status information) { s->transmit_data[0] = 0x77; // TODO: find a better way to do this step_timer->INTCTRLA &= ~TC1_OVFINTLVL_gm; // Disable the step timer int32_t x = AxisGetCurrentPosition(&x_axis); int32_t y = AxisGetCurrentPosition(&y_axis); int32_t z = AxisGetCurrentPosition(&z_axis); step_timer->INTCTRLA |= TC_OVFINTLVL_LO_gc; // Enable the step timer s->transmit_data[1] = x & 0xFF; x = x >> 8; s->transmit_data[2] = x & 0xFF; x = x >> 8; s->transmit_data[3] = x & 0xFF; x = x >> 8; s->transmit_data[4] = x & 0xFF; s->transmit_data[5] = y & 0xFF; y = y >> 8; s->transmit_data[6] = y & 0xFF; y = y >> 8; s->transmit_data[7] = y & 0xFF; y = y >> 8; s->transmit_data[8] = y & 0xFF; s->transmit_data[9] = z & 0xFF; z = z >> 8; s->transmit_data[10] = z & 0xFF; z = z >> 8; s->transmit_data[11] = z & 0xFF; z = z >> 8; s->transmit_data[12] = z & 0xFF; uint8_t status_bits = 0; if (IsMoving (&x_axis)) { status_bits |= 0x01; } if (IsMoving (&y_axis)) { status_bits |= 0x02; } if (IsMoving (&z_axis)) { status_bits |= 0x04; } s->transmit_data[13] = status_bits; //step_timer->INTCTRLA &= ~TC1_OVFINTLVL_gm; // Disable the step timer buffer_lock = 1; s->transmit_data[14] = RingBufferCount(&location_buffer); buffer_lock = 0; //step_timer->INTCTRLA |= TC_OVFINTLVL_LO_gc; // Enable the step timer //s->transmit_data[14] = location_buffer_size; SerialTransmit (s, 0x00, 15); // Transmit to master device break; } case 0x32: // Set Position + Speed { Location_t l; /* Bytes 1:2 are time in milliseconds */ l.time = decode_uint16_t(&(s->receive_data[1])); /* Bytes 3:14 are position */ l.x = decode_uint32_t(&(s->receive_data[3])); l.y = decode_uint32_t(&(s->receive_data[7])); l.z = decode_uint32_t(&(s->receive_data[11])); // Add the new location to the buffer //step_timer->INTCTRLA &= ~TC1_OVFINTLVL_gm; // Disable the step timer buffer_lock = 1; if (!RingBufferIsFull(&location_buffer)) { RingBufferAdd(&location_buffer, l); } //if (location_buffer_size < 1) //{ // nextLocation = l; // location_buffer_size++; //} s->transmit_data[1] = RingBufferCount(&location_buffer); buffer_lock = 0; //step_timer->INTCTRLA |= TC_OVFINTLVL_LO_gc; // Enable the step timer s->transmit_data[0] = 0x32; //s->transmit_data[1] = location_buffer_size; SerialTransmit(s, 0x00, 2); break; } } } else if (task == TASK_LIMIT_SWITCH_Y) { uint8_t v = LimitSwitchHelper(&x_axis); v &= LimitSwitchHelper(&y_axis); v &= LimitSwitchHelper(&z_axis); if (v) { task = 0; } } }
void init(int argc, char **argv) { FILE *fp; int daemon = FALSE; int i, ntoken, status, problems; BOOL debug; THREAD tid; char pwd[MAXPATHLEN+1], RunFile[MAXPATHLEN+1]; char *token[MAXTOKEN]; char *myname, *sta, *log, *user, *prefix, *dbspec = NULL; struct stat statbuf; struct isp_dascnf dascnf; LOGIO *lp = NULL; static char *fid = "init"; memset(DasCnf, 0, sizeof(struct isp_dascnf)); MUTEX_INIT(&DasCnf->mutex); /* Get my name without path prefix (if any) */ if ((myname = strdup(argv[0])) == NULL) { perror(argv[0]); exit(1); } ntoken = util_sparse(myname, token, "./", MAXTOKEN); myname = token[ntoken-1]; /* Parse command line for required input and selected overrides */ sta = (char *) NULL; user = ISPD_DEF_USER; log = NULL; debug = ISPD_DEF_DEBUG; for (i = 1; i < argc; i++) { if (strncasecmp(argv[i], "sta=", strlen("sta=")) == 0) { sta = argv[i] + strlen("sta="); } else if (strncasecmp(argv[i], "log=", strlen("log=")) == 0) { log = argv[i] + strlen("log="); } else if (strncasecmp(argv[i], "db=", strlen("db=")) == 0) { dbspec = argv[i] + strlen("db="); } else if (strncasecmp(argv[i], "user="******"user="******"user="******"-debug") == 0) { debug = TRUE; } else if (strcasecmp(argv[i], "-bd") == 0) { daemon = TRUE; } else if (sta == (char *) NULL) { sta = argv[i]; } else { help(myname); } } if (sta == NULL) { fprintf(stderr, "%s: system name must be specified\n", myname); help(myname); } if (log == NULL) log = daemon ? DEFAULT_BACKGROUND_LOG : DEFAULT_FOREGROUND_LOG; if (!isidlSetGlobalParameters(dbspec, argv[0], &Params->glob)) { fprintf(stderr, "%s: isidlSetGlobalParameters: %s\n", argv[0], strerror(errno)); exit(1); } sprintf(pwd, "%s/%s/%s", Params->glob.root, sta, ISP_SUBDIR); if (chdir(pwd) != 0) { fprintf(stderr, "%s: chdir: ", myname); perror(pwd); exit (1); } Home = strdup(Params->glob.root); Syscode = strdup(sta); prefix = strdup(sta); if (Home == (char *) NULL || Syscode == (char *) NULL || prefix == NULL) { perror(myname); exit(1); } Syscode = util_lcase(Syscode); /* Make sure we can find the various set up files now */ problems = 0; if ((fp = fopen(ISP_RUN_FILE, "r")) == (FILE *) NULL) { fprintf(stderr, "%s: fopen: %s/", myname, pwd); perror(ISP_RUN_FILE); ++problems; } else { fclose(fp); } if (problems) exit(1); /* Load run parameters */ sprintf(RunFile, "%s/%s", pwd, ISP_RUN_FILE); if (!ispLoadRunParam(RunFile, sta, Params, Server)) { fprintf(stderr, "%s: problems with parameter file\n", myname); exit(1); } /* By insuring that we can stat the output device now, we will later * be able to treat open failures as no-media-installed conditions. */ SetOutputMediaType(); if (OutputMediaType() == ISP_OUTPUT_TAPE && stat(Params->odev, &statbuf) != 0) { fprintf(stderr, "%s: can't stat: ", myname); perror(Params->odev); exit(1); } /* Check for digitizer specific support files */ if (Params->digitizer == ISP_DAS) { if (isp_getcnf(&dascnf) != 0) { fprintf(stderr, "%s: fopen: %s/", myname, pwd); perror(ISP_CNF_FILE); fprintf(stderr, "can't load DAS configuration... set default\n"); dascnf.flag = ISP_DASCNF_DEF; if (isp_setcnf(&dascnf) != 0 || isp_getcnf(&dascnf) != 0) { perror("can't load default DAS configuration either!\n"); ++problems; } } } if (problems) exit(1); /* Set user and group identity */ utilSetIdentity(user); /* Go into the background */ if (daemon && !utilBackGround()) { perror("utilBackGround"); exit(1); } /* Start logging facility */ util_ucase(prefix); if ((lp = InitLogging(myname, log, prefix, debug)) == NULL) { perror("InitLogging"); exit(1); } ispSetLogParameter(Params, lp); LogMsg(LOG_DEBUG, "uid=%d, euid=%d, gid=%d, egid=%d", getuid(), geteuid(), getgid(), getegid()); if (Params->rt593.present) { LogMsg(LOG_INFO, "Configured for RT593 with %d tic delay", Params->rt593.correct); } /* Initialize the message queues and massio buffers */ InitMsgqs(); /* Initialize the status structure */ status_init(); /* Start signal handling thread */ signals_init(); /* Initialize the output device */ InitMediaOps(); /* Start the ISI thread */ InitIsi(lp); sleep(1); /* Start the digitizer specific I/O thread */ if (Params->digitizer == ISP_DAS) { InitDasIO(); } else { InitSanIO(); } sleep(1); /* Start the DAS packet processor thread */ InitProcess(); sleep(1); /* Start the massio buffering thread */ InitMassio(); sleep(1); /* Start the DAS status request thread */ InitSoh(); sleep(1); /* Start the digitizer configuration verification process */ if (Params->digitizer == ISP_DAS) { VerifyDasConfig(0); } else { VerifySanConfig(0); } /* Start up auxiliary threads, if any */ if (Params->clock.enabled) { set_alarm(ISP_ALARM_AUXCLK); InitClock(); } if (Params->baro.enabled) { set_alarm(ISP_ALARM_AUX); InitBaro(); } if (Params->dpm.enabled) { set_alarm(ISP_ALARM_AUX); InitDPM(); } /* Start up ISP injection service */ if (Params->inject) isp_inject(); /* Command and control server */ server_init(); /* iboot watchdog */ StartIbootWatchdog(); return; }
int main(void) { /* initialize the core clock and the systick timer */ InitClock(); InitSysTick(); /* initialize the RGB led */ LED_Init(); /* Initialize UART0 */ InitUart0(); /* double rainbow all across the sky */ DoubleFlash(); /* initialize the I2C bus */ I2C_Init(); #if DATA_FUSE_MODE /* signaling for fusion */ FusionSignal_Init(); #endif // DATA_FUSE_MODE /* initialize UART fifos */ RingBuffer_Init(&uartInputFifo, &uartInputData, UART_RX_BUFFER_SIZE); RingBuffer_Init(&uartOutputFifo, &uartOutputData, UART_TX_BUFFER_SIZE); /* initialize UART0 interrupts */ Uart0_InitializeIrq(&uartInputFifo, &uartOutputFifo); Uart0_EnableReceiveIrq(); /* initialize I2C arbiter */ InitI2CArbiter(); /* initialize the IMUs */ InitHMC5883L(); InitMPU6050(); // InitMPU6050(); #if ENABLE_MMA8451Q InitMMA8451Q(); #endif /* Wait for the config messages to get flushed */ //TrafficLight(); DoubleFlash(); RingBuffer_BlockWhileNotEmpty(&uartOutputFifo); #if ENABLE_MMA8451Q /* initialize the MMA8451Q data structure for accelerometer data fetching */ mma8451q_acc_t acc; MMA8451Q_InitializeData(&acc); #endif /* initialize the MPU6050 data structure */ mpu6050_sensor_t accgyrotemp, previous_accgyrotemp; MPU6050_InitializeData(&accgyrotemp); MPU6050_InitializeData(&previous_accgyrotemp); /* initialize the HMC5883L data structure */ hmc5883l_data_t compass, previous_compass; HMC5883L_InitializeData(&compass); HMC5883L_InitializeData(&previous_compass); /* initialize HMC5883L reading */ uint32_t lastHMCRead = 0; const uint32_t readHMCEvery = 1000 / 75; /* at 75Hz, data come every (1000/75Hz) ms. */ /************************************************************************/ /* Fetch scaler values */ /************************************************************************/ #if DATA_FUSE_MODE const fix16_t mpu6050_accelerometer_scaler = mpu6050_accelerometer_get_scaler(); const fix16_t mpu6050_gyroscope_scaler = mpu6050_gyroscope_get_scaler(); const fix16_t hmc5883l_magnetometer_scaler = hmc5883l_magnetometer_get_scaler(); #endif // DATA_FUSE_MODE /************************************************************************/ /* Prepare data fusion */ /************************************************************************/ #if DATA_FUSE_MODE uint32_t last_transmit_time = 0; uint32_t last_fusion_time = systemTime(); fusion_initialize(); #endif // DATA_FUSE_MODE /************************************************************************/ /* Main loop */ /************************************************************************/ for(;;) { /* helper variables to track data freshness */ uint_fast8_t have_gyro_data = 0; uint_fast8_t have_acc_data = 0; uint_fast8_t have_mag_data = 0; /************************************************************************/ /* Determine if sensor data fetching is required */ /************************************************************************/ /* helper variables for event processing */ int eventsProcessed = 0; int readMPU, readHMC; #if ENABLE_MMA8451Q int readMMA; #endif /* atomic detection of fresh data */ __disable_irq(); #if ENABLE_MMA8451Q readMMA = poll_mma8451q; #endif readMPU = poll_mpu6050; poll_mma8451q = 0; poll_mpu6050 = 0; __enable_irq(); /* detection of HMC read */ /* * TODO: read synchronized with MPU */ readHMC = 0; uint32_t time = systemTime(); if ((time - lastHMCRead) >= readHMCEvery) { readHMC = 1; lastHMCRead = time; } /************************************************************************/ /* Fetching MPU6050 sensor data if required */ /************************************************************************/ /* read accelerometer/gyro */ if (readMPU) { LED_BlueOff(); I2CArbiter_Select(MPU6050_I2CADDR); MPU6050_ReadData(&accgyrotemp); /* mark event as detected */ eventsProcessed = 1; /* check for data freshness */ have_acc_data = (accgyrotemp.accel.x != previous_accgyrotemp.accel.x) || (accgyrotemp.accel.y != previous_accgyrotemp.accel.y) || (accgyrotemp.accel.z != previous_accgyrotemp.accel.z); have_gyro_data = (accgyrotemp.gyro.x != previous_accgyrotemp.gyro.x) || (accgyrotemp.gyro.y != previous_accgyrotemp.gyro.y) || (accgyrotemp.gyro.z != previous_accgyrotemp.gyro.z); /* loop current data --> previous data */ previous_accgyrotemp = accgyrotemp; } /************************************************************************/ /* Fetching HMC5883L sensor data if required */ /************************************************************************/ /* read compass data */ if (readHMC) { I2CArbiter_Select(HMC5883L_I2CADDR); HMC5883L_ReadData(&compass); /* mark event as detected */ eventsProcessed = 1; /* check for data freshness */ have_mag_data = (compass.x != previous_compass.x) || (compass.y != previous_compass.y) || (compass.z != previous_compass.z); /* loop current data --> previous data */ previous_compass = compass; } /************************************************************************/ /* Fetching MMA8451Q sensor data if required */ /************************************************************************/ #if ENABLE_MMA8451Q /* read accelerometer */ if (readMMA) { LED_RedOff(); I2CArbiter_Select(MMA8451Q_I2CADDR); MMA8451Q_ReadAcceleration14bitNoFifo(&acc); /* mark event as detected */ eventsProcessed = 1; } #endif /************************************************************************/ /* Raw sensor data output over serial */ /************************************************************************/ #if DATA_FETCH_MODE /* data availability + sanity check * This sent me on a long bug hunt: Sometimes the interrupt would be raised * even if not all data registers were written. This always resulted in a * z data register not being fully written which, in turn, resulted in * extremely jumpy measurements. */ if (readMPU && accgyrotemp.status != 0) { /* write data */ uint8_t type = 0x02; P2PPE_TransmissionPrefixed(&type, 1, (uint8_t*)accgyrotemp.data, sizeof(accgyrotemp.data), IO_SendByte); } /* data availability + sanity check */ if (readHMC && (compass.status & HMC5883L_SR_RDY_MASK) != 0) /* TODO: check if not in lock state */ { uint8_t type = 0x03; P2PPE_TransmissionPrefixed(&type, 1, (uint8_t*)compass.xyz, sizeof(compass.xyz), IO_SendByte); } #if ENABLE_MMA8451Q /* data availability + sanity check */ if (readMMA && acc.status != 0) { uint8_t type = 0x01; P2PPE_TransmissionPrefixed(&type, 1, (uint8_t*)acc.xyz, sizeof(acc.xyz), IO_SendByte); } #endif #endif // DATA_FETCH_MODE /************************************************************************/ /* Sensor data fusion */ /************************************************************************/ #if DATA_FUSE_MODE // if there were sensor data ... if (eventsProcessed) { v3d gyro, acc, mag; // convert, calibrate and store gyroscope data if (have_gyro_data) { sensor_prepare_mpu6050_gyroscope_data(&gyro, accgyrotemp.gyro.x, accgyrotemp.gyro.y, accgyrotemp.gyro.z, mpu6050_gyroscope_scaler); fusion_set_gyroscope_v3d(&gyro); } // convert, calibrate and store accelerometer data if (have_acc_data) { sensor_prepare_mpu6050_accelerometer_data(&acc, accgyrotemp.accel.x, accgyrotemp.accel.y, accgyrotemp.accel.z, mpu6050_accelerometer_scaler); fusion_set_accelerometer_v3d(&acc); } // convert, calibrate and store magnetometer data if (have_mag_data) { sensor_prepare_hmc5883l_data(&mag, compass.x, compass.y, compass.z, hmc5883l_magnetometer_scaler); fusion_set_magnetometer_v3d(&mag); } // get the time differential const uint32_t current_time = systemTime(); const fix16_t deltaT_ms = fix16_from_int(current_time - last_fusion_time); const fix16_t deltaT = fix16_mul(deltaT_ms, F16(0.001)); last_fusion_time = current_time; FusionSignal_Predict(); // predict the current measurements fusion_predict(deltaT); FusionSignal_Update(); // correct the measurements fusion_update(deltaT); FusionSignal_Clear(); #if 0 fix16_t yaw, pitch, roll; fusion_fetch_angles(&roll, &pitch, &yaw); #if 0 float yawf = fix16_to_float(yaw), pitchf = fix16_to_float(pitch), rollf = fix16_to_float(roll); IO_SendInt16((int16_t)yawf); IO_SendInt16((int16_t)pitchf); IO_SendInt16((int16_t)rollf); IO_SendByteUncommited('\r'); IO_SendByte('\n'); #else if (current_time - last_transmit_time >= 100) { /* write data */ uint8_t type = 42; fix16_t buffer[3] = { roll, pitch, yaw }; P2PPE_TransmissionPrefixed(&type, 1, (uint8_t*)buffer, sizeof(buffer), IO_SendByte); last_transmit_time = current_time; } #endif #else if (current_time - last_transmit_time >= 100) { /* write data */ switch (output_mode) { case RPY: { fix16_t roll, pitch, yaw; fusion_fetch_angles(&roll, &pitch, &yaw); /* write data */ uint8_t type = 42; fix16_t buffer[3] = { roll, pitch, yaw }; P2PPE_TransmissionPrefixed(&type, 1, (uint8_t*)buffer, sizeof(buffer), IO_SendByte); break; } case QUATERNION: { qf16 orientation; fusion_fetch_quaternion(&orientation); uint8_t type = 43; fix16_t buffer[4] = { orientation.a, orientation.b, orientation.c, orientation.d }; P2PPE_TransmissionPrefixed(&type, 1, (uint8_t*)buffer, sizeof(buffer), IO_SendByte); break; } case QUATERNION_RPY: { fix16_t roll, pitch, yaw; fusion_fetch_angles(&roll, &pitch, &yaw); qf16 orientation; fusion_fetch_quaternion(&orientation); uint8_t type = 44; fix16_t buffer[7] = { orientation.a, orientation.b, orientation.c, orientation.d, roll, pitch, yaw }; P2PPE_TransmissionPrefixed(&type, 1, (uint8_t*)buffer, sizeof(buffer), IO_SendByte); break; } case SENSORS_RAW: { uint8_t type = 0; fix16_t buffer[6] = { acc.x, acc.y, acc.z, mag.x, mag.y, mag.z }; P2PPE_TransmissionPrefixed(&type, 1, (uint8_t*)buffer, sizeof(buffer), IO_SendByte); break; } } last_transmit_time = current_time; } #endif } #endif // DATA_FUSE_MODE /************************************************************************/ /* Read user data input */ /************************************************************************/ /* as long as there is data in the buffer */ while(!RingBuffer_Empty(&uartInputFifo)) { /* light one led */ LED_RedOn(); /* fetch byte */ uint8_t data = IO_ReadByte(); output_mode = (output_mode_t)data; LED_RedOff(); #if 0 /* echo to output */ IO_SendByte(data); /* mark event as detected */ eventsProcessed = 1; #endif } /************************************************************************/ /* Save energy if you like to */ /************************************************************************/ /* in case of no events, allow a sleep */ if (!eventsProcessed) { /* * Care must be taken with this instruction here, as it can lead * to a condition where after being woken up (e.g. by the SysTick) * and looping through, immediately before entering WFI again * an interrupt would yield a true condition for the branches below. * In this case this loop would be blocked until the next IRQ, * which, in case of a 1ms SysTick timer, could be too late. * * To counter this behaviour, SysTick has been speed up by factor * four (0.25ms). */ #if 0 __WFI(); #endif } } return 0; }
/************************************************************************* * Function Name: main * Parameters: none * * Return: none * * Description: main * *************************************************************************/ int main(void) { MamInit(); // Init clock InitClock(); // Init GPIO GpioInit(); // Init VIC init_VIC(); // Enable TIM0 clocks PCONP_bit.PCTIM0 = 1; // enable clock PCLKSEL0_bit.PCLK_TIMER0 = 1; //timer clock = pclk // Init Time0 T0TCR_bit.CE = 0; // counting disable T0TCR_bit.CR = 1; // set reset T0TCR_bit.CR = 0; // release reset T0CTCR_bit.CTM = 0; // Timer Mode: every rising PCLK edge T0MCR_bit.MR0I = 1; // Enable Interrupt on MR0 T0MCR_bit.MR0R = 1; // Enable reset on MR0 T0MCR_bit.MR0S = 0; // Disable stop on MR0 // set timer 0 period T0PR = 18-1; T0MR0 = (TIMER0_IN_FREQ)/(18 * TIMER0_TICK_PER_SEC); // init timer 0 interrupt T0IR_bit.MR0INT = 1; // clear pending interrupt VIC_SetVectoredIRQ(Timer0IntrHandler,0,VIC_TIMER0); VICINTENABLE |= 1UL << VIC_TIMER0; T0TCR_bit.CE = 1; // counting Enable __enable_interrupt(); LcdInitPio(); BoardInit(); SysSpiInitPio(); DacInitPio(); AdcInitPio(); InitAdc(); LcdInitModule(); LcdClear(); // LcdLine(10,32,130, 32); // LcdLine(60,10,60, 60); // LcdLine(70,10,70, 60); // LcdRect(10,20,40, 50); // LcdRect(10,1,80, 7); /* SetFont(BIG_FONT); LcdLine(10, 28, 120, 28); LcdLine(10, 45, 120, 45); // LcdRect(10, 30, 50, 43); LcdText(50, 20, 200, 36, "-123456789.0"); */ /* LcdBmp(10, 20, BMP_HN_WIDTH, BMP_HN_HEIGHT, bmp_hn); LcdBmp(10, 35, BMP_O2_WIDTH, BMP_O2_HEIGHT, bmp_o2); DrawCheckBox(8, 8, 0, 1); DrawCheckBox(20, 8, 1, 1);*/ // DrawMainScreen(); DrawParamScreen(); LcdClear(); //DrawMenuScreen(); DrawDOutTestScreen(); LcdDraw(); OutputSet(LCD_LED); InitMessages(); InitKeyb(); InitCursor(); InitAdc(); // SetCursorPos(100, 32); SendMessage(MSG_EDITOR_SCREEN_ACTIVATE); int debug = 0, debug2 = 0; char s[4]; /* LcdClear(); for(char i = 0; i < 16; i++) LcdLine(i * 8, 0, i * 8, 63); LcdDraw(); */ // debug = ReadTemp() / 32; debug = 3855.0 + 20.0 * ((402.0 - 3855.0) / 20.0); unsigned int dac_codes[4] = {0, 0, 0, 0}; dac_codes[0] = debug; // unsigned int dac_codes[4] = {0, 0, 0, 4095}; WriteToDac(dac_codes); // char adc_codes[4] = {0x58, 0, 0, 0}; // char adc_codes2[4] = {0, 0, 0, 0,}; char state = 0; while(1) { /* WriteIntToFram(0, 100); ReadIntFromFram(0, &debug); */ /* WriteToDac(dac_codes); */ /* switch(state) { case 0: //if(GetTimer(KEYB_TIMER) > 100) if(GetMessage(MSG_R_ENCODER_PRESSED)) { OutputSet(LED11); OutputClr(LED12); OutputClr(LED13); OutputSet(LED15); ResetTimer(KEYB_TIMER); SendMessage(MSG_CUR_DEACTIVATE); state = 1; }; break; case 1: // if(GetTimer(KEYB_TIMER) > 100) if(GetMessage(MSG_R_ENCODER_PRESSED)) { OutputClr(LED11); OutputSet(LED12); OutputClr(LED13); OutputClr(LED15); ResetTimer(KEYB_TIMER); SendMessage(MSG_CUR_ACTIVATE); state = 0; }; break; case 2: // if(GetTimer(KEYB_TIMER) > 100) if(GetMessage(MSG_KEY_PRESSED)) { OutputClr(LED11); OutputClr(LED12); OutputSet(LED13); OutputClr(LED15); ResetTimer(KEYB_TIMER); state = 3; }; break; case 3: // if(GetTimer(KEYB_TIMER) > 100) if(GetMessage(MSG_KEY_PRESSED)) { OutputClr(LED11); OutputClr(LED12); OutputClr(LED13); OutputSet(LED15); ResetTimer(KEYB_TIMER); state = 0; }; break; }; if (GetMessage(MSG_L_ENCODER_CW)) { debug++; sprintf(s, "%d", debug); // LcdClear(); LcdText(0, 0, 63, 9, s); LcdDraw(); }; if (GetMessage(MSG_L_ENCODER_CCW)) { debug--; sprintf(s, "%d", debug); // LcdClear(); LcdText(0, 0, 63, 9, s); LcdDraw(); }; if (GetMessage(MSG_R_ENCODER_CW)) { debug2++; sprintf(s, "%d", debug2); // LcdClear(); LcdText(100, 0, 127, 9, s); LcdDraw(); }; if (GetMessage(MSG_R_ENCODER_CCW)) { debug2--; sprintf(s, "%d", debug2); // LcdClear(); LcdText(100, 0, 127, 9, s); LcdDraw(); }; */ // ProcessEditorScreen(); // ProcessEditor(); ProcessAdc(); ProcessCursor(); ProcessKeyb(); ProcessMessages(); } }