int main2(void) { #if PROFILING == 1 volatile unsigned long delay; #endif /* Initialize 8MHz clock */ SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_XTAL_8MHZ | SYSCTL_OSC_MAIN); OLED_Init(15); ADC_Init(1000); ADC_Open(0); ADC_Open(1); SH_Init(); OS_Init(); OS_MailBox_Init(); SH_Init(); //********initialize communication channels OS_MailBox_Init(); OS_Fifo_Init(32); NumCreated = 0; NumSamples = 0; MaxJitter = 0; // OS_Time in 20ns units MinJitter = 10000000; #if PROFILING // intialize port b pins as specified by PINS mask // for digital output for use in profiling threads SYSCTL_RCGC2_R |= SYSCTL_RCGC2_GPIOB; delay = SYSCTL_RCGC2_R; GPIO_PORTB_DIR_R |= PINS; GPIO_PORTB_DEN_R |= PINS; GPIO_PORTB_DATA_R &= ~PINS; #endif // testing/debugging stuff OS_Add_Periodic_Thread(&DAS,2,1); // OS_AddButtonTask(&dummyButtonTask, 1); OS_AddButtonTask(&ButtonPush, 1); OS_AddDownTask(&ButtonPush, 1); // NumCreated += OS_AddThread(&jerkTask, 0, 6); // NumCreated += OS_AddThread(&dummyTask3, 0, 7); // NumCreated += OS_AddThread(&dummyTask1, 0, 2); NumCreated += OS_AddThread(&PID, 128, 5); // NumCreated += OS_AddThread(&dummyTask2, 0, 2); NumCreated += OS_AddThread(&Consumer, 128, 0); NumCreated += OS_AddThread(&SH_Shell, 128, 6); OS_Launch(TIMESLICE); /* Loop indefinitely */ while(1); }
//*******************final user main DEMONTRATE THIS TO TA********** int main(void){ // lab 3 real main OS_Init(); // initialize, disable interrupts DataLost = 0; // lost data between producer and consumer NumSamples = 0; //********initialize communication channels OS_MailBox_Init(); OS_Fifo_Init(32); // ***note*** 4 is not big enough***** //*******attach background tasks*********** OS_AddButtonTask(&ButtonPush,2); OS_AddDownTask(&DownPush,3); OS_AddPeriodicThread(&DAS,1,PERIOD,0); // 2 kHz real time sampling NumCreated = 0 ; // create initial foreground threads NumCreated += OS_AddThread(&Interpreter,128,2); NumCreated += OS_AddThread(&Consumer,128,1); NumCreated += OS_AddThread(&PID,128,3); OS_Launch(TIMESLICE); // doesn't return, interrupts enabled in here return 0; // this never executes }
//*******************final user main DEMONTRATE THIS TO TA********** int main(void){ // Set the clocking to run from PLL at 50 MHz SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_8MHZ); OS_Init(); // initialize, disable interrupts DataLost = 0; // lost data between producer and consumer NumSamples = 0; MaxJitter = 0; // OS_Time in 20ns units MinJitter = 10000000; //********initialize communication channels OS_MailBox_Init(); OS_Fifo_Init(32); // ***note*** 4 is not big enough***** //*******attach background tasks*********** OS_AddButtonTask(&ButtonPush,2); OS_AddPeriodicThread(&DAS,PERIOD,0); // 2 kHz real time sampling NumCreated = 0 ; // create initial foreground threads NumCreated += OS_AddThread(&Interpreter,128,2); NumCreated += OS_AddThread(&Consumer,128,1); NumCreated += OS_AddThread(&PID,128,3); OS_Launch(TIMESLICE); // doesn't return, interrupts enabled in here return 0; // this never executes }
//*******************final user main DEMONTRATE THIS TO TA********** int main(void){ OS_Init(); // initialize, disable interrupts PortE_Init(); DataLost = 0; // lost data between producer and consumer NumSamples = 0; MaxJitter = 0; // in 1us units //********initialize communication channels OS_MailBox_Init(); OS_Fifo_Init(128); // ***note*** 4 is not big enough***** ST7735_InitR(INITR_REDTAB); // initialize LCD UART_Init(); // initialize UART //*******attach background tasks*********** OS_AddSW1Task(&SW1Push,2); // OS_AddSW2Task(&SW2Push,2); // add this line in Lab 3 ADC_Init(4); // sequencer 3, channel 4, PD3, sampling in DAS() OS_AddPeriodicThread(&DAS,PERIOD,1); // 2 kHz real time sampling of PD3 NumCreated = 0 ; // create initial foreground threads NumCreated += OS_AddThread(&Interpreter,128,2); NumCreated += OS_AddThread(&Consumer,128,1); NumCreated += OS_AddThread(&PID,128,3); // Lab 3, make this lowest priority OS_Launch(TIME_2MS); // doesn't return, interrupts enabled in here return 0; // this never executes }
// ******** OS_Init ************ // initialize operating system, disable interrupts until OS_Launch // initialize OS controlled I/O: serial, ADC, systick, select switch and timer2 // input: none // output: none void OS_Init(void){ DisableInterrupts(); RUNPT=0; // Enable processor interrupts. // //IntMasterEnable(); TIMELORD=0; //initialize the system counter for use with thingies (no shit) SDEBOUNCEPREV = 0; btndown_time = 0; SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_8MHZ); //Init System Clock //Systick Init (Thread Scheduler) //taken care of in OS_Launch // Timers galore! SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); TimerConfigure(TIMER0_BASE, (TIMER_CFG_16_BIT_PAIR | TIMER_CFG_A_PERIODIC | TIMER_CFG_B_PERIODIC)); TimerControlTrigger(TIMER0_BASE, TIMER_A, true); // TIMELORD Updater TimerControlTrigger(TIMER0_BASE, TIMER_B, true); // ADC_Collect Timer TimerLoadSet(TIMER0_BASE, TIMER_A, SysCtlClockGet()/1000); TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT); TimerIntEnable(TIMER0_BASE, TIMER_TIMB_TIMEOUT); IntEnable(INT_TIMER0A); SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1); TimerConfigure(TIMER1_BASE, TIMER_CFG_16_BIT_PAIR | TIMER_CFG_A_PERIODIC | TIMER_CFG_B_PERIODIC); TimerControlTrigger(TIMER1_BASE, TIMER_A, true); // Periodic Timer 1 TimerControlTrigger(TIMER1_BASE, TIMER_B, true); // Periodic Timer 2 TimerIntEnable(TIMER1_BASE, TIMER_TIMA_TIMEOUT); TimerIntEnable(TIMER1_BASE, TIMER_TIMB_TIMEOUT); SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER2); TimerConfigure(TIMER2_BASE, TIMER_CFG_16_BIT_PAIR | TIMER_CFG_A_PERIODIC | TIMER_CFG_B_PERIODIC); TimerControlTrigger(TIMER2_BASE, TIMER_A, true); // Periodic Timer 3 TimerControlTrigger(TIMER2_BASE, TIMER_B, true); // Periodic Timer 4 TimerIntEnable(TIMER2_BASE, TIMER_TIMA_TIMEOUT); TimerIntEnable(TIMER2_BASE, TIMER_TIMB_TIMEOUT); // Init ADC Stuff SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0); SysCtlADCSpeedSet(SYSCTL_ADCSPEED_1MSPS); // Init Debugging LED SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_0); GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_0, GPIO_PIN_0); //Semaphores, OS Stuff OS_InitSemaphore(&oled_free,1); OS_InitSemaphore(&OSMailBoxSema4,0); OS_MailBox_Init(); //UART & OLED UARTInit(); RIT128x96x4Init(1000000); //Init OLED //RIT128x96x4StringDraw("Hello World", 0, 12, 15); //ADC ADC_Init(); // Init ADC to run @ 1KHz //Eval Buttons SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); GPIOPinTypeGPIOInput(GPIO_PORTE_BASE, GPIO_PIN_1); GPIOPadConfigSet(GPIO_PORTE_BASE, GPIO_PIN_1, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); GPIOIntTypeSet(GPIO_PORTE_BASE, GPIO_PIN_1, GPIO_FALLING_EDGE); GPIOPinIntClear(GPIO_PORTE_BASE, GPIO_PIN_1); GPIOPinIntEnable(GPIO_PORTE_BASE, GPIO_PIN_1); IntEnable(INT_GPIOE); //SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); GPIOPinTypeGPIOInput(GPIO_PORTF_BASE, GPIO_PIN_1); GPIOPadConfigSet(GPIO_PORTF_BASE, GPIO_PIN_1, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); GPIOIntTypeSet(GPIO_PORTF_BASE, GPIO_PIN_1, GPIO_FALLING_EDGE); GPIOPinIntClear(GPIO_PORTF_BASE, GPIO_PIN_1); GPIOPinIntEnable(GPIO_PORTF_BASE, GPIO_PIN_1); IntEnable(INT_GPIOF); /* This works for now, but Stellarisware Function owuld be nice */ /*SYSCTL_RCGC2_R |= 0x00000020; // (a) activate port F // delay = SYSCTL_RCGC2_R; //delay, cause i said so GPIO_PORTF_DIR_R &= ~0x02; // (c) make PF1 in GPIO_PORTF_DEN_R |= 0x02; // enable digital I/O on PF1 GPIO_PORTF_IS_R &= ~0x02; // (d) PF1 is edge-sensitive GPIO_PORTF_IBE_R &= ~0x02; // PF1 is not both edges GPIO_PORTF_IEV_R &= ~0x02; // PF1 falling edge event GPIO_PORTF_ICR_R = 0x02; // (e) clear flag4 GPIO_PORTF_IM_R |= 0x02; // (f) arm interrupt on PF1 NVIC_PRI7_R = (NVIC_PRI7_R&0xFF00FFFF)|(0<<21); // (g) priority (shifted into place) (will get set in OS_AddButtonTask) NVIC_EN0_R |= 0x40000000; // (h) enable interrupt 2 in NVIC //dont enable interrupts GPIO_PORTF_PUR_R |= 0x02; //add pull up resistor, just for shits and giggles */ }
// ******** OS_Init ************ // initialize operating system, disable interrupts until OS_Launch // initialize OS controlled I/O: serial, ADC, systick, select switch and timer2 // input: none // output: none void OS_Init(void){ DisableInterrupts(); RUNPT=0; JitterInit(); deleteme=0; // Enable processor interrupts. // //IntMasterEnable(); TIMELORD=0; //initialize the system counter for use with thingies (no shit) NUMBLOCKEDTHREADS=0; TOTALNUMTHREADS=0; SDEBOUNCEPREV = 0; btndown_time = 0; SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_8MHZ); //Init System Clock //Systick Init (Thread Scheduler) //taken care of in OS_Launch // Timers galore! SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); TimerConfigure(TIMER0_BASE, (TIMER_CFG_16_BIT_PAIR | TIMER_CFG_A_PERIODIC | TIMER_CFG_B_PERIODIC)); //TimerControlTrigger(TIMER0_BASE, TIMER_A, false); // TIMELORD Updater //TimerControlTrigger(TIMER0_BASE, TIMER_B, true); // ADC_Collect Timer TimerLoadSet(TIMER0_BASE, TIMER_A, SysCtlClockGet()/1000); TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT); TimerIntEnable(TIMER0_BASE, TIMER_TIMB_TIMEOUT); TimerEnable(TIMER0_BASE, TIMER_BOTH); IntEnable(INT_TIMER0A); SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1); TimerConfigure(TIMER1_BASE, TIMER_CFG_16_BIT_PAIR | TIMER_CFG_A_PERIODIC | TIMER_CFG_B_PERIODIC); TimerControlTrigger(TIMER1_BASE, TIMER_A, true); // Periodic Timer 1 TimerControlTrigger(TIMER1_BASE, TIMER_B, true); // Periodic Timer 2 TimerIntEnable(TIMER1_BASE, TIMER_TIMA_TIMEOUT); TimerIntEnable(TIMER1_BASE, TIMER_TIMB_TIMEOUT); SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER2); TimerConfigure(TIMER2_BASE, TIMER_CFG_16_BIT_PAIR | TIMER_CFG_A_PERIODIC | TIMER_CFG_B_PERIODIC); TimerControlTrigger(TIMER2_BASE, TIMER_A, true); // Periodic Timer 3 TimerControlTrigger(TIMER2_BASE, TIMER_B, true); // Periodic Timer 4 TimerIntEnable(TIMER2_BASE, TIMER_TIMA_TIMEOUT); TimerIntEnable(TIMER2_BASE, TIMER_TIMB_TIMEOUT); // Init ADC Stuff SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0); SysCtlADCSpeedSet(SYSCTL_ADCSPEED_1MSPS); // Init Debugging LED SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_0); GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_0, GPIO_PIN_0); //Semaphores, OS Stuff OS_InitSemaphore(&oled_free,1); OS_InitSemaphore(&OSMailBoxSema4,0); OS_MailBox_Init(); //UART & OLED UARTInit(); RIT128x96x4Init(1000000); //Init OLED //RIT128x96x4StringDraw("Hello World", 0, 12, 15); //ADC ADC_Init(); // Init ADC to run @ 1KHz //Select Switch (button press) Init (select switch is PF1) (pulled from page 67 of the book and modified for PF1...i think) //SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); /*GPIOPinTypeGPIOInput(GPIO_PORTF_BASE, GPIO_PIN_1); IntEnable(INT_GPIOF); //IntPrioritySet(INT_GPIOF, 0x00); GPIOIntTypeSet(GPIO_PORTF_BASE, GPIO_PIN_1, GPIO_BOTH_EDGES); GPIOPinIntEnable(GPIO_PORTF_BASE, GPIO_PIN_1);*/ //NVIC_EN0_R |= 0x40000000; // (h) enable interrupt 2 in NVIC (Not sure what Stellarisware function replaces this) /* This works for now, but Stellarisware Function owuld be nice */ SYSCTL_RCGC2_R |= 0x00000020; // (a) activate port F // delay = SYSCTL_RCGC2_R; //delay, cause i said so GPIO_PORTF_DIR_R &= ~0x02; // (c) make PF1 in GPIO_PORTF_DEN_R |= 0x02; // enable digital I/O on PF1 GPIO_PORTF_IS_R &= ~0x02; // (d) PF1 is edge-sensitive GPIO_PORTF_IBE_R &= ~0x02; // PF1 is not both edges GPIO_PORTF_IEV_R &= ~0x02; // PF1 falling edge event GPIO_PORTF_ICR_R = 0x02; // (e) clear flag4 GPIO_PORTF_IM_R |= 0x02; // (f) arm interrupt on PF1 NVIC_PRI7_R = (NVIC_PRI7_R&0xFF00FFFF)|(0<<21); // (g) priority (shifted into place) (will get set in OS_AddButtonTask) NVIC_EN0_R |= 0x40000000; // (h) enable interrupt 2 in NVIC //dont enable interrupts GPIO_PORTF_PUR_R |= 0x02; //add pull up resistor, just for shits and giggles /* SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF); // Enable GPIOF GPIOPinTypeGPIOInput(GPIO_PORTF_BASE, GPIO_PIN_1); // make Pin 1 an Input GPIOPinRead(GPIO_PORTF_BASE, GPIO_PIN_1); // */ //TODO: i have no f*****g clue what to do here... return; }