int main(void) { SetupClock(); SwitchClocks(); SetupPorts(); //lcdSetup(4,20); // 4 rows & 20 cols radioSetup(); // polling mode bootSetup(); LED_1 = 1; LED_2 = 1; LED_3 = 1; delay_ms(500); LED_1 = 0; LED_2 = 0; LED_3 = 0; delay_ms(200); LED_1 = 1; LED_2 = 1; LED_3 = 1; delay_ms(500); // check if radio is working and at the right state. while (radioGetTrxState() != 0x16); LED_1 = 0; LED_2 = 0; LED_3 = 0; //print("Ready"); //bootTestRadio(); bootRun(); bootReset(); while(1); return 1; }
DataServeriOS::DataServeriOS(EthernetServer *server, char *pass, boolean serial, char *Arduino, void (*substitudeLoop)(void),int pwmports[],byte nports,int cfports[],byte ncfports,void(*customfunction)(int),char*(*customdigitalreturn)(int),int crports[],byte ncrports,char*(*customanalogreturn)(int)) { _serial = serial; _nPWMports = nports; if (nports > 0) { _pwm = true; _PWMPorts = pwmports; } else _pwm = false; _nCRports = ncrports; if (ncrports > 0) { _cr = true; _CRPorts = crports; _returnAnalogForPort = customanalogreturn; } else _cr = false; _nCFports = ncfports; if (ncfports > 0) { _cf = true; _CFPorts = cfports; _function = customfunction; _returnDigitalForPort = customdigitalreturn; } else _cf = false; _server = server; _pass = pass; _Arduino = Arduino; _substitudeLoop = substitudeLoop; SetupPorts(); }
void init(void) { int i; volatile WordVal src_addr = {SRC_ADDR}; volatile WordVal src_pan_id = {SRC_PAN_ID}; SetupClock(); SwitchClocks(); SetupPorts(); for (i = 0; i < 6; i++) { LED_RED = ~LED_RED; delay_ms(50); LED_YLW1 = ~LED_YLW1; delay_ms(50); LED_YLW2 = ~LED_YLW2; delay_ms(50); LED_BLU = ~LED_BLU; delay_ms(50); } SetupUART1(); SetupInterrupts(); EnableIntU1TX; EnableIntU1RX; radioInit(src_addr, src_pan_id, 150, 150); atSetPromMode(1); //This turns off Automatic Acknowledgements and puts the radio in prom mode radioSetChannel(MY_CHAN); //Set to my channel //atSetAntDiversity(1); }
int main(void) { WordVal src_addr_init = {SRC_ADDR}; WordVal src_pan_id_init = {SRC_PAN_ID}; WordVal dst_addr_init = {DST_ADDR}; SetupClock(); SwitchClocks(); SetupPorts(); batSetup(); swatchSetup(); radioInit(src_addr_init, src_pan_id_init, RXPQ_MAX_SIZE, TXPQ_MAX_SIZE); radioSetChannel(MY_CHAN); //Set to my channel macSetDestAddr(dst_addr_init); dfmemSetup(); unsigned char memsize; memsize = dfmemGetChipSize(); xlSetup(); gyroSetup(); mcSetup(); cmdSetup(); //senSetup(); adcSetup(); pidSetup(); steeringSetup(); //radioReadTrxId(id); LED_RED = 1; LED_BLUE = 0; LED_YELLOW = 0; //while(1); if(phyGetState() == 0x16) { LED_GREEN = 1; } //print("Ready"); //readDFMemBySample(5); while(1) { cmdHandleRadioRxBuffer(); //Simple idle ; reduces idle current to 70 mA // TODO (abuchan, apullin, fgb) : Idle() causes unexpected behavior //if(radioIsRxQueueEmpty()){ // Idle(); //} } }
int main ( void ) { fun_queue = queueInit(FUN_Q_LEN); rx_pay_queue = pqInit(12); //replace 12 with a #define const later test_function tf; /* Initialization */ SetupClock(); SwitchClocks(); SetupPorts(); SetupInterrupts(); SetupI2C(); SetupADC(); SetupTimer1(); SetupPWM(); SetupTimer2(); gyroSetup(); xlSetup(); dfmemSetup(); WordVal pan_id = {RADIO_PAN_ID}; WordVal src_addr = {RADIO_SRC_ADDR}; WordVal dest_addr = {RADIO_DEST_ADDR}; radioInit(src_addr, pan_id, RADIO_RXPQ_MAX_SIZE, RADIO_TXPQ_MAX_SIZE); radioSetDestAddr(dest_addr); radioSetChannel(RADIO_MY_CHAN); char j; for(j=0; j<3; j++){ LED_2 = ON; delay_ms(500); LED_2 = OFF; delay_ms(500); } LED_2 = ON; EnableIntT2; while(1){ while(!queueIsEmpty(fun_queue)) { rx_payload = pqPop(rx_pay_queue); tf = (test_function)queuePop(fun_queue); (*tf)(payGetType(rx_payload), payGetStatus(rx_payload), payGetDataLength(rx_payload), payGetData(rx_payload)); payDelete(rx_payload); } } return 0; }
//-------------------------------------------------------------------------------- // // Main program loop. // void main() { __disable_interrupt(); _pulseDataAddress = (char *) EEPROM_PULSE_DATA; _numberOfPulses = *_pulseDataAddress++; SetupPorts(); SetupUART(); SetupTimer2(); SetupTimer1(); __enable_interrupt(); while (1) { __wait_for_interrupt(); } }
int main (void) { unsigned int i; /* Initialization */ SetupClock(); SetupPorts(); batSetup(); cmdSetup(); mcSetup(); SetupADC(); SwitchClocks(); sclockSetup(); radioInit(TXPQ_MAX_SIZE, RXPQ_MAX_SIZE); radioSetChannel(MY_CHAN); radioSetSrcPanID(PAN_ID); radioSetSrcAddr(SRC_ADDR); dfmemSetup(); camSetup(); cambuffSetup(); gyroSetup(); cmdResetSettings(); for (i = 0; i < 6; i++) { LED_GREEN = ~LED_GREEN; delay_ms(50); LED_RED = ~LED_RED; delay_ms(50); LED_ORANGE = ~LED_ORANGE; delay_ms(50); } LED_GREEN = 0; LED_RED = 0; LED_ORANGE = 0; /* Program */ while (1) { cmdHandleRadioRxBuffer(); radioProcess(); } }
int main ( void ) { /** pin buttons locals */ volatile bool regPinButton1; volatile bool regPinButton2; /** speed local */ short iRefSpeed; // Configure Oscillator to operate the device at 40Mhz // Fosc= Fin*M/(N1*N2), Fcy=Fosc/2 // Fosc= 8*40/(2*2)= 80Mhz for 8M input clock PLLFBD = 38; // M=40 CLKDIVbits.PLLPOST = 0; // N1=2 CLKDIVbits.PLLPRE = 0; // N2=2 // while(OSCCONbits.LOCK != 1) {}; // Wait for PLL to loc /** setup dsPIC ports */ SetupPorts(); /** init user parameters */ InitUserParms(); /** init user specified parms and stop on error */ if( SetupPeripherals() ) { /* Error */ return 0; } uGF.Word = 0; // clear flags while(1) { // init Mode eStateControl = CNTRL_STOP; iLockLoopCnt = 0; /** clear the variables other than STOP command */ uGF.bit.TLock = 0; uGF.bit.Btn1Pressed = 0; uGF.bit.Btn2Pressed = 0; uGF.bit.DoSnap = 0; uGF.bit.SnapDone = 0; /** ============= Open Loop ======================*/ OpenLoopParm.qVelMech = dqOL_VelMech; CtrlParm.qVelRef = OpenLoopParm.qVelMech; iRefSpeed = CtrlParm.qVelRef; InitOpenLoop(); /** Inital offsets for currents */ InitMeasCompCurr( 450, 730 ); // init board SetupBoard(); // Enable ADC interrupt and begin main loop timing IFS0bits.AD1IF = 0; IEC0bits.AD1IE = 1; /** Initialize private variables used by CalcVelIrp. */ InitCalcVel(); /** Initialize private variables used by CurrModel */ InitCurModel(); // zero out i sums PIParmD.qdSum = 0; PIParmQ.qdSum = 0; PIParmQref.qdSum = 0; // zero out i out PIParmD.qOut = 0; PIParmQ.qOut = 0; PIParmQref.qOut = 0; /** if state is stop */ if(eStateControl == CNTRL_STOP) { //wait here until button 1 is pressed or stop time elapsed while(uGF.bit.TStop){}; while(!pinButton1) { /** make sure that the STOP do not occur due to this loop */ iStopLoopCnt = 0; // Start offset accumulation //and accumulate current offset while waiting MeasCompCurr(); } while(pinButton1); //when button 1 is released eStateControl = CNTRL_OPEN_LOOP; //then start motor in open loop } // Run the motor uGF.bit.ChangeMode = 1; // Enable the driver IC on the motor control PCB pinPWMOutputEnable_ = 0; //Run Motor loop while(1) { /** algorithm was stopped before*/ if(uGF.bit.TStop) { /* break the while */ break; } /* for logic of this application 2 buttons are used S3 and S6. If both buttons are pressed the state of the application is commuted between OPEN_LOOP, CLOSED_LOOP and CLOSED_LOOP_DOUBLE_SPEED. The touch of only one button will increase the speed in one of the states enumerated above */ /* read the buttons state */ /* while no buttons are pushed */ do{ regPinButton1 = pinButton1; /* pin button 1 */ /* retain if pressed */ if(regPinButton1 == 1) { uGF.bit.Btn1Pressed=1; } regPinButton2 = pinButton2; /* pin button 2 */ /* retain if pressed */ if(regPinButton2 == 1) { uGF.bit.Btn2Pressed=1; } /** make sure that the STOP do not occur due to this loop */ iStopLoopCnt = 0; }while((!regPinButton1)&&(!regPinButton2)); /* while buttons are released */ do{ regPinButton1 = pinButton1; /* pin button 1 */ /* retain if pressed */ if(regPinButton1 == 1) { uGF.bit.Btn1Pressed=1; } regPinButton2 = pinButton2; /* pin button 2 */ /* retain if pressed */ if(regPinButton2 == 1) { uGF.bit.Btn2Pressed=1; } }while(pinButton1||pinButton2); /** the counter for STOP is cleared - if buttons released */ iStopLoopCnt = 0; /* check if one of the buttons is pressed */ /* check if both buttons are pressed */ if ((uGF.bit.Btn1Pressed)&&(uGF.bit.Btn2Pressed)) { /* if yes */ /* clear both flags indicating the buttons were pressed */ uGF.bit.Btn1Pressed = 0; uGF.bit.Btn2Pressed = 0; /* and command not locked */ /* check if command not locked */ if(!uGF.bit.TLock) { /* lock command for Tlock_multiple */ uGF.bit.TLock = 1; /* command locked */ iLockLoopCnt = 0; /* reset counter */ /* state machine for control algorithm */ switch(eStateControl) { /* the previous state was STOP */ case CNTRL_OPEN_LOOP: { /* swich the state machine */ eStateControl = CNTRL_CLOSED_LOOP; /* first switch the global flag */ uGF.bit.ChangeMode = 1; break; } case CNTRL_CLOSED_LOOP: { /* double the speed of the motor */ /* and swich the state machine */ eStateControl = CNTRL_CLOSED_LOOP_DBL_SPEED; /* double the speed */ iRefSpeed += iRefSpeed; #ifdef SNAPSHOT uGF.bit.DoSnap = 1; SnapCount = 0; #endif break; } case CNTRL_CLOSED_LOOP_DBL_SPEED: { /* divide by 2 the speed of the motor */ /* and swich the state machine */ eStateControl = CNTRL_CLOSED_LOOP; /* divide the speed by 2 */ iRefSpeed -= iRefSpeed/2; #ifdef SNAPSHOT uGF.bit.DoSnap = 1; SnapCount = 0; #endif break; } default: { /* undefined state, stop */ eStateControl = CNTRL_STOP; /* disable the PWM module */ pinPWMOutputEnable_ = 1; break; } } } } /* check which button was pressed */ /* perhaps button 1 was the one */ else if(uGF.bit.Btn1Pressed) { /* if yes */ /* clear the button flag for future usage */ uGF.bit.Btn1Pressed = 0; /* and command not locked */ /* check if command not locked */ if(!uGF.bit.TLock) { /* lock command for Tlock_multiple */ uGF.bit.TLock = 1; /* command locked */ iLockLoopCnt = 0; /* reset counter */ /* increase speed with SPEED_STEP */ iRefSpeed += SPEED_STEP; } } /* it was button 2, but checking */ else if(uGF.bit.Btn2Pressed) { /* if yes */ /* clear the button flag for future usage */ uGF.bit.Btn2Pressed = 0; /* and command not locked */ /* check if command not locked */ if(!uGF.bit.TLock) { /* lock command for Tlock_multiple */ uGF.bit.TLock = 1; /* command locked */ iLockLoopCnt = 0; /* reset counter */ /* decrease speed with SPEED_STEP */ iRefSpeed -= SPEED_STEP; } } /** limit the reference to 60Hz */ if( iRefSpeed > MAX_SPEED_UP ) { iRefSpeed = MAX_SPEED_UP; } /** limit the reference to 60Hz */ if((signed short)iRefSpeed < (signed short)MAX_SPEED_DOWN ) { iRefSpeed = MAX_SPEED_DOWN; } /** update the global speed reference */ CtrlParm.qVelRef = iRefSpeed; if( uGF.bit.SnapDone ) { uGF.bit.SnapDone=0; } } // End of Run Motor loop } // End of Main loop // should never get here while(1){} }
int main(void) { wakeTime = 0; dcCounter = 0; WordVal src_addr_init = {RADIO_SRC_ADDR}; WordVal src_pan_id_init = {RADIO_SRC_PAN_ID}; WordVal dst_addr_init = {RADIO_DST_ADDR}; SetupClock(); SwitchClocks(); SetupPorts(); tiHSetup(); //swatchSetup(); radioInit(src_addr_init, src_pan_id_init, RADIO_RXPQ_MAX_SIZE, RADIO_TXPQ_MAX_SIZE); radioSetChannel(RADIO_CHANNEL); //Set to my channel macSetDestAddr(dst_addr_init); cmdSetup(); if(phyGetState() == 0x16) { LED_RED = 1; } while(1){ cmdHandleRadioRxBuffer(); } LED_GREEN = 0; LED_RED = 1; LED_YELLOW = 1; _LATG9 = 1; _LATC15 = 1; //testRadio(); /* LED_GREEN = 1; mpuSetup(); LED_GREEN = 0; LED_RED = 1; LED_YELLOW = 1; //batSetup(); //int old_ipl; //mSET_AND_SAVE_CPU_IP(old_ipl, 1) //LED_YELLOW = 1; //dfmemSetup(); //xlSetup(); //gyroSetup(); //tiHSetup(); //mcSetup(); //cmdSetup(); //adcSetup(); //telemSetup(); //Timer 5 //mcSetDutyCycle(1,70.0); //mcSetDutyCycle(2,70.0); //mcSetDutyCycle(3,70.0); //mcSetDutyCycle(4,70.0); #ifdef HALL_SENSORS //hallSetup(); // Timer 1, Timer 2 //hallSteeringSetup(); //doesn't exist yet #else //No hall sensors, standard BEMF control //legCtrlSetup(); // Timer 1 //steeringSetup(); //Timer 5 #endif //tailCtrlSetup(); //ovcamSetup(); /* //radioReadTrxId(id); LED_RED = 1; //Red is use an "alive" indicator LED_GREEN = 0; LED_YELLOW = 0; //tiHSetFloat(1,50.0); //tiHSetFloat(2,75.0); //tiHSetup(); //LED_GREEN = 1; //tiHSetFloat(1,.800); //LED_YELLOW = 1; //Radio startup verification //if(phyGetState() == 0x16) { LED_GREEN = 1; } //Sleeping and low power options //_VREGS = 1; //gyroSleep(); //tiHSetFloat(1,98.0); //tiHSetFloat(2,30.0); //tiHSetFloat(3,99.0); //tiHSetFloat(4,99.0); LED_GREEN = 0; LED_RED = 0; LED_YELLOW = 1; int i = 0; while (1) { delay_ms(2000); int i = i+1; LED_GREEN = i%2; // cmdHandleRadioRxBuffer(); #ifndef __DEBUG //Idle will not work with debug //Simple idle: if (radioIsRxQueueEmpty()) { Idle(); //_T1IE = 0; } #endif //delay_ms(1000); //cmdEcho(0, 1 , (unsigned char*)(&i) ); //i++; //if(radioIsRxQueueEmpty() && (t1_ticks >= wakeTime + 5000) ){ //Idle(); //LED_RED = 0; //gyroSleep(); //Sleep(); //} } /* if(g_radio_duty_cycle){ if(dcCounter == 0){ //LED_GREEN = 1; atSetRXAACKON(); }else{ //LED_GREEN = 0; atSetTRXOFF(); } } else{ //LED_GREEN = 1; } dcCounter = (dcCounter + 1) % 8; if(radioIsRxQueueEmpty() && !inMotion){ //gyroSleep(); LED_RED = 0; _SWDTEN = 1; //restart wdt Sleep(); //Idle(); } //should be asleep here, waiting for WTD wakeup ClrWdt(); //clear wdt _SWDTEN = 0; //software disable wdt LED_RED = 1; //spin up clock if(_COSC != 0b010){ while(OSCCONbits.LOCK!=1); } //gyroWake(); } } void testRadio(void) { //designed to be used with testRadio.py. //test radio.py should produce many echoes that cycle through the ASCII characters //comment out all code in main and use test Radio to test the radio only. //This code does not initialize non-radio-nessisary components. wakeTime = 0; dcCounter = 0; WordVal src_addr_init = {RADIO_SRC_ADDR}; WordVal src_pan_id_init = {RADIO_SRC_PAN_ID}; WordVal dst_addr_init = {RADIO_DST_ADDR}; SetupClock(); SwitchClocks(); SetupPorts(); int old_ipl; mSET_AND_SAVE_CPU_IP(old_ipl, 1) swatchSetup(); radioInit(src_addr_init, src_pan_id_init, RADIO_RXPQ_MAX_SIZE, RADIO_TXPQ_MAX_SIZE); radioSetChannel(RADIO_CHANNEL); //Set to my channel macSetDestAddr(dst_addr_init); cmdSetup(); LED_GREEN = ON; int i = 0; while (1) { i++; cmdHandleRadioRxBuffer(); } LED_RED = OFF; }*/ }
int main() { // Processor Initialization SetupClock(); SwitchClocks(); SetupPorts(); sclockSetup(); LED_1 = 1; LED_2 = 1; LED_3 = 1; // Message Passing fun_queue = carrayCreate(FUN_Q_LEN); cmdSetup(); // Radio setup radioInit(RADIO_RXPQ_MAX_SIZE, RADIO_TXPQ_MAX_SIZE); radioSetChannel(RADIO_CHANNEL); radioSetSrcAddr(RADIO_SRC_ADDR); radioSetSrcPanID(RADIO_PAN_ID); uart_tx_packet = NULL; uart_tx_flag = 0; //uartInit(&cmdPushFunc); tactileInit(); // Need delay for encoders to be ready delay_ms(100); amsEncoderSetup(); mpuSetup(); tiHSetup(); dfmemSetup(); telemSetup(); adcSetup(); pidSetup(); LED_1 = 0; LED_3 = 1; while(1){ // Send outgoing radio packets radioProcess(); /* // Send outgoing uart packets if(uart_tx_flag) { uartSendPacket(uart_tx_packet); uart_tx_flag = 0; }*/ checkTactileBuffer(); // move received packets to function queue while (!radioRxQueueEmpty()) { // Check for unprocessed packet rx_packet = radioDequeueRxPacket(); if(rx_packet != NULL) { cmdPushFunc(rx_packet); } } // process commands from function queue while(!carrayIsEmpty(fun_queue)) { rx_packet = carrayPopHead(fun_queue); unsigned int rx_src_addr = rx_packet->src_addr.val; if(rx_packet != NULL) { rx_payload = macGetPayload(rx_packet); if(rx_payload != NULL) { rx_function = (test_function)(rx_payload->test); if(rx_function != NULL) { LED_2 = ~LED_2; (rx_function)(payGetType(rx_payload), payGetStatus(rx_payload), payGetDataLength(rx_payload), payGetData(rx_payload), rx_src_addr); } } ppoolReturnFullPacket(rx_packet); } } } return 0; }
int main(void) { //wakeTime = 0; //dcCounter = 0; // Processor Initialization SetupClock(); SwitchClocks(); SetupPorts(); sclockSetup(); LED_1 = 0; LED_2 = 0; LED_3 = 0; cmdSetup(); radioInit(RADIO_TXPQ_MAX_SIZE, RADIO_RXPQ_MAX_SIZE); radioSetChannel(RADIO_CHANNEL); radioSetSrcPanID(RADIO_PAN_ID); radioSetSrcAddr(RADIO_SRC_ADDR); dfmemSetup(); uint64_t id = dfmemGetUnqiueID(); telemSetup(); //Timer 5, HW priority 4 mpuSetup(); imuSetup(); //Timer 4, HW priority 3 tiHSetup(); adcSetup(); //AMS Encoders //encSetup(); //"Open Loop" vibration & jitter generator, AP 2014 //olVibeSetup(); legCtrlSetup(); //Timer 1, HW priority 5 steeringSetup(); //Timer 5, HW priority 4 //Tail control is a special case //tailCtrlSetup(); //Camera is untested with current code base, AP 12/6/2012 //ovcamSetup(); LED_RED = 1; //Red is use an "alive" indicator LED_GREEN = 0; LED_YELLOW = 0; //Radio startup verification //if (phyGetState() == 0x16) { // LED_GREEN = 1; //} //Sleeping and low power options //_VREGS = 1; //gyroSleep(); /////FUNCTION TEST, NOT FOR PRODUCTION //olVibeStart(); //////////////////// while (1) { cmdHandleRadioRxBuffer(); radioProcess(); } }