int main(void) { static unsigned int tmp = 0; SET_OUTPUT(LED_R); SET_OUTPUT(LED_G); SET_OUTPUT(LED_B); RESET_LED(LED_R); RESET_LED(LED_G); RESET_LED(LED_B); #ifdef DCDCCTRL SET_OUTPUT(DCDCCTRL); RESET(DCDCCTRL); #endif battery_state = 0; slave_init(); //uart_init(); timer_init(); mcan_init(); spi_init(); spi_adc_init(); relai_init(); adc_init(); sei(); if( (GPIOR0 & (1<<WDRF)) == (1<<WDRF) ) { status("WDTRST "); } else if( (GPIOR0 & (1<<BORF)) == (1<<BORF) ) { status("BORRST "); } else if( (GPIOR0 & (1<<EXTRF)) == (1<<EXTRF) ) { status("START EX"); } else if( (GPIOR0 & (1<<PORF)) == (1<<PORF) ) { status("START PO"); } else if( (GPIOR0 & (1<<JTRF)) == (1<<JTRF) ) { status("START JT"); } else { status("START "); } WDTCR = (1<<WDCE) | (1<<WDE); WDTCR = (1<<WDE) | (1<<WDP2) | (1<<WDP1) | (1<<WDP0); SET_LED(LED_G); while (1) { __asm__ __volatile__ ("wdr"); if( battery_state & STATE_INTERMEDIATE ) { intermediate_loop(); } else if( battery_state & STATE_TRACTIVE ) { tractive_loop(); } else if( battery_state & STATE_CHARGING ) { charge_loop(); } else if( battery_state & STATE_BALANCING ) { balancing_loop(); } else { // standby mode if( (tmp = mcan_check()) && !(battery_state & STATE_ERROR) ) { switch(tmp) { case CAN_TRACTIVE_ENABLE: // CAN_TRACTIVE_ENABLE == 0x2F0 { if( relai_volt < VCC_RELAI_MIN || vcc_volt < VCC_MIN ) { status("NO VCC"); break; } // enable hv intermediate_init(); dspace_heartbeat = 0; battery_state |= STATE_TRACTIVE; } break; case CAN_CHARGE_ENABLE: // CAN_CHARGE_ENABLE == 0x2FA { if( relai_volt < VCC_RELAI_MIN || vcc_volt < VCC_MIN ) { status("NO VCC"); break; } // start charging intermediate_init(); battery_state |= STATE_CHARGING; } break; case CAN_BALANCING_ENABLE: { balancing_start(); battery_state |= STATE_BALANCING; } break; } } } slave_loop(); mcan_send_loop(); adc_loop(); } return 0; }
void main(void){ //Initialize the clock to run the microprocessor ARC_setup_lv();//sets up initializes the clocks and should be called at the beginning of main //initCLK();//this is now set up in ARC_setup //Initialize the uart to talk with terra term P4DIR |= BIT1|BIT2|BIT3|BIT5|BIT6|BIT7;//LIGHT UP LED'S AS OUTPUTS P4OUT &= ~(BIT1|BIT2|BIT3|BIT5|BIT6|BIT7); //P4OUT |= BIT5; VREGinit();//INITALIZE THE VOLTAGE REGULATOR //initUART();//initalize when using TxChar(ch) //setup I2C for use of UCB1 initI2C(); //set up timer init_timerA(); // some of the set up is now started in ARC_setup mmcInit_msp_off(); setup_launch_detect(); //setup_orbit_start(); UnusedPinSetup();//drive all unused pins to outputs GyroOff(); SENSORSoff(); MAGoff(); ACCoff(); RESET_LED(); //Initialize the main task initARCbus_pd(BUS_ADDR_LEDL); // initARCbus(BUS_ADDR_LEDL); //run MSP test /* MSPtest(); //RUN Oscillator Test OscillatorTest(); //Turn temperature sensor/gyro/SD card on SENSORSon(); //Turn temperature sensor/gyro/SD card off SENSORSoff(); //Turn accelerometers on ACCon(); //turn accelerometers off ACCoff(); //Turn magnetometers on MAGon(); //Turn magnetometers off MAGoff(); */ //Test the ADC functionality //ADC_test(); //logging data for launch //launch_data_log(); //test finished //printf("YOU ARE FINISHED!!!\n\r"); memset(stack1,0xcd,sizeof(stack1));//function memset, sets all values(array stack1, everything equals this value, //size of array so everything is changed) stack1[0]=stack1[sizeof(stack1)/sizeof(stack1[0])-1]=0xfeed;//put marker values at the words before/after the stack. memset(stack2,0xcd,sizeof(stack2)); // write known values into the stack stack2[0]=stack2[sizeof(stack2)/sizeof(stack2[0])-1]=0xfeed; // put marker values at the words before/after the stack memset(stack3,0xcd,sizeof(stack3)); // write known values into the stack stack3[0]=stack3[sizeof(stack3)/sizeof(stack3[0])-1]=0xfeed; // put marker values at the words before/after the stack memset(stack5,0xcd,sizeof(stack5)); // write known values into the stack stack5[0]=stack5[sizeof(stack5)/sizeof(stack5[0])-1]=0xfeed; // put marker values at the words before/after the stack memset(stack6,0xcd,sizeof(stack6)); // write known values into the stack stack6[0]=stack6[sizeof(stack6)/sizeof(stack6[0])-1]=0xfeed; // put marker values at the words before/after the stack ctl_events_init(&handle_SDcard, 0); //start timer A (taken from Jesse's code so that I can have an interrupt for my timer) //start_timerA(); ctl_task_run(&Perif_SetUp,BUS_PRI_LOW,Periferial_SetUp,"ARC Bus Test Program","Periferial_SetUp",sizeof(stack2)/sizeof(stack2[0])-2,stack2+1,0);//side note, the termainal can be used in two ways by either passing the uart functin or the async function ctl_task_run(&I2C,BUS_PRI_NORMAL,(void(*)(void*))takeI2Cdata,NULL,"takeI2Cdata",sizeof(stack3)/sizeof(stack3[0])-2,stack3+1,0); ctl_task_run(&LaunchData,BUS_PRI_HIGH,launch_data_log,NULL,"launch_data_log",sizeof(stack1)/sizeof(stack1[0])-2,stack1+1,0);//&LaunchData takes the address ctl_task_run(&LEDL_events,BUS_PRI_NORMAL+10,sub_events,NULL,"sub_events",sizeof(stack6)/sizeof(stack6[0])-2,stack6+1,0);//this is to run orbit code //ctl_task_run(&LaunchDetect,4,VerifyLaunchDetect,NULL,"VerifyLaunchDetect",sizeof(stack5)/sizeof(stack5[0])-2,stack5+1,0); //of the variable which is the task structure is ,2 is the priority,launch_data_log is the function I want to run,"launch_data_log" is //the name when I look at the threads window to identify the task,the size of the memory stack minus the guard bits, //first location where data is stored second element in array (first element is guard bit), the zero is a placeholder //since the MSP doesn't support this function. //put this here for now ctl_task_run(&ACDS_sen_task,BUS_PRI_LOW+10,ACDS_sensor_interface,NULL,"ACDS_sensor_interface",sizeof(stack5)/sizeof(stack5[0])-2,stack5+1,0); //Use I2C sensor function to receive data //Stay in an infinite loop //for(;;){// taken care of in main loop //P5SEL |= BIT6;//OUTPUT aclk //P5DIR |= BIT6;//output aclk mainLoop_lp(); mainLoop(); }