//int count2 = 0; void dummyTask2(void) { // int i; // unsigned long data; // #if PROFILING == 1 // int myPin = 0x02; // #endif while(1) { // OLED_Out(BOTTOM, "task 2 request"); OS_bWait(&binarySemaphore); OLED_Out(BOTTOM, "task 2 acquired"); // for(i = 0; i < 100000; i++) { // #if PROFILING == 1 // GPIO_PORTB_DATA_R ^= myPin; // #endif // } OS_Sleep(1000); OS_bSignal(&binarySemaphore); OLED_Out(BOTTOM, "task 2 released"); OS_Sleep(1000); // for(i = 0; i < 100000; i++) { // #if PROFILING == 1 // GPIO_PORTB_DATA_R ^= myPin; // #endif // } // data = OS_MailBox_Recv(); // OLED_Out(BOTTOM, "task 2 receive"); // OS_AddThread(&dummyTask1, 0, 1); // OLED_Out(BOTTOM, "task 2 dead"); // OS_Kill(); // OS_Sleep(2000); } }
//int count1 = 0; void dummyTask1(void) { // int i; // #if PROFILING == 1 // int myPin = 0x01; // #endif OS_InitSemaphore(&binarySemaphore, OS_BINARY_SEMAPHORE); while(1) { OS_bWait(&binarySemaphore); OLED_Out(TOP, "task 1 acquired"); // for(i = 0; i < 100000; i++) { // #if PROFILING == 1 // GPIO_PORTB_DATA_R ^= myPin; // #endif // } OS_Sleep(1000); OS_bSignal(&binarySemaphore); OLED_Out(TOP, "task 1 released"); OS_Sleep(1000); // for(i = 0; i < 100000; i++) { // #if PROFILING == 1 // GPIO_PORTB_DATA_R ^= myPin; // #endif // } // OLED_Out(TOP, "task 1 dead"); // OS_AddThread(&dummyTask2, 0 ,1); // OS_Kill(); } }
// } void Thread7(void){ // foreground thread printf("\n\rEE345M/EE380L, Lab 3 Preparation 2\n\r"); OS_Sleep(10000); // 10 seconds //Jitter(); // print jitter information printf("\n\r\n\r"); OS_Kill(); }
void Thread4d(void){ int i; for(i=0;i<640;i++){ Count4++; OS_Sleep(1); } OS_Kill(); }
void Thread7(void){ // foreground thread OSuart_OutString(UART0_BASE,"\n\rEE345M/EE380L, Lab 3 Preparation 2\n\r"); OS_Sleep(5000); // 10 seconds Jitter(); // print jitter information OSuart_OutString(UART0_BASE,"\n\r\n\r"); OS_Kill(); }
void Thread7(void){ // foreground thread UART0_SendString("\n\rEE345M/EE380L, Lab 3 Preparation 2\n\r"); OS_Sleep(5000); // 10 seconds Jitter(); // print jitter information UART0_SendString("\n\r\n\r"); OS_Kill(); }
void Thread7(void){ // foreground thread //print("\n\rEE345M/EE380L, Lab 3 Preparation 2\n\r"); oLED_Message(1,0,"\n\rEE345M/EE380L, Lab 3 Preparation 2\n\r",-0); OS_Sleep(5000); // 10 seconds Jitter(); // print jitter information printf("\n\r\n\r"); OS_Kill(); }
void Thread4c(void){ int i; for(i=0;i<64;i++){ Count4++; OS_Sleep(10); } OS_Kill(); Count4 = 0; }
void OutputThread(void){ // foreground thread printf("\n\rEE345M/EE380L, Lab 3 Preparation 4\n\r"); while(SignalCount1+SignalCount2+SignalCount3<100*MAXCOUNT){ OS_Sleep(1000); // 1 second printf("."); } printf(" done\n\r"); printf("Signalled=%u, Waited=%u\n\r",SignalCount1+SignalCount2+SignalCount3,WaitCount1+WaitCount2+WaitCount3); OS_Kill(); }
void read_test(void) { int i; unsigned int then, now; eFile_Init(); eFile_Format(); OS_AddThread(&write_test, 128, 0); OS_Sleep(2000); then = OS_MsTime(); // read 10 blocks for(i = 0; i < 10; i++) { eDisk_ReadBlock(buffer, i); } now = OS_MsTime(); OS_AddThread(&SH_Shell, 128, 0); OS_Sleep(1000); OS_Suspend(); printf("Read test took %d ms", now - then); eFile_Format(); OS_Kill(); }
void thread(void) { unsigned int id; id = OS_Id(); PF3 ^= 0x08; Display_Message(0,line++, "Thread: ", id); OS_Sleep(2000); Display_Message(0,line++, "Thread dying ", id); PF3 ^= 0x08; OS_Kill(); }
//------------------Task 2-------------------------------- // background thread executes with SW1 button // one foreground task created with button push // foreground treads run for 2 sec and die // ***********ButtonWork************* void ButtonWork(void){ unsigned long myId = OS_Id(); PE1 ^= 0x02; ST7735_Message(1,0,"NumCreated =",NumCreated); PE1 ^= 0x02; OS_Sleep(50); // set this to sleep for 50msec ST7735_Message(1,1,"PIDWork =",PIDWork); ST7735_Message(1,2,"DataLost =",DataLost); ST7735_Message(1,3,"Jitter 0.1us=",MaxJitter); PE1 ^= 0x02; OS_Kill(); // done, OS does not return from a Kill }
void OutputThread(void){ // foreground thread char buffer[60]; UART0_SendString("\n\rEE345M/EE380L, Lab 3 Preparation 4\n\r"); while(SignalCount1+SignalCount2+SignalCount3<100*MAXCOUNT){ OS_Sleep(1000); // 1 second UART0_SendString("."); } UART0_SendString(" done\n\r"); snprintf(buffer, 60, "Signalled=%u, Waited=%u\n\r",SignalCount1+SignalCount2+SignalCount3,WaitCount1+WaitCount2+WaitCount3); UART0_SendString(buffer); OS_Kill(); }
//------------------Task 2-------------------------------- // background thread executes with select button // one foreground task created with button push // foreground treads run for 2 sec and die // ***********ButtonWork************* void ButtonWork(void){ unsigned long i; unsigned long myId = OS_Id(); oLED_Message(1,0,"NumCreated =",NumCreated); if(NumSamples < RUNLENGTH){ // finite time run for(i=0;i<20;i++){ // runs for 2 seconds OS_Sleep(50); // set this to sleep for 0.1 sec } } oLED_Message(1,1,"PIDWork =",PIDWork); oLED_Message(1,2,"DataLost =",DataLost); oLED_Message(1,3,"0.1u Jitter=",MaxJitter-MinJitter); OS_Kill(); // done }
int main(void) { unsigned int id; unsigned long time; id = OS_Id(); PF2 ^= 0x04; Display_Message(0,line++, "Hello world: ", id); OS_AddThread(thread, 128, 1); time = OS_Time(); OS_Sleep(1000); time = (((OS_TimeDifference(time, OS_Time()))/1000ul)*125ul)/10000ul; Display_Message(0,line++, "Sleep time: ", time); PF2 ^= 0x04; OS_Kill(); }
void DisplayThread(void) { char str[20]; while(NumSamples < RUNLENGTH) { sprintf(str, "Time left is %d", (RUNLENGTH-NumSamples)/1000); _OLED_Message(TOP, 1, str, 15); sprintf(str, "v(mV) = %d", voltage); _OLED_Message(TOP, 2, str, 15); // OS_Suspend(); OS_Sleep(500); } OS_Kill(); OS_Delay(OS_ARBITRARY_DELAY); }
void dummyTask3(void) { count3++; OS_Sleep(4000); // sleep for 4 seconds OLED_Out(BOTTOM, "task 3 Yaaaaaaaaaawn"); NumCreated += OS_AddThread(&dummyTask3, 64, 2); OS_Kill(); // #if PROFILING == 1 // int myPin = 0x04; // #endif // while(1) { // count3++; // #if PROFILING == 1 // GPIO_PORTB_DATA_R ^= myPin; // #endif // } }
void OutputThread(void){ // foreground thread char sigStr[7], waitStr[7]; OSuart_OutString(UART0_BASE,"\n\rEE345M/EE380L, Lab 3 Preparation 4\n\r"); while(SignalCount1+SignalCount2+SignalCount3<100*MAXCOUNT){ OS_Sleep(1000); // 1 second OSuart_OutString(UART0_BASE,"."); } OSuart_OutString(UART0_BASE," done\n\r"); Int2Str(SignalCount1+SignalCount2+SignalCount3, sigStr); Int2Str(WaitCount1+WaitCount2+WaitCount3, waitStr); OSuart_OutString(UART0_BASE,"Signalled = "); OSuart_OutString(UART0_BASE,sigStr); OSuart_OutString(UART0_BASE,"Waited = "); OSuart_OutString(UART0_BASE,waitStr); OS_Kill(); }
static char *getsAfterHistory(char *buffer, int length) { u8 ucByte; while(1) { if (UART_ReceiveByte(UART_DEBUG, &ucByte)) { UART_WriteToHost( UART_DEBUG, &ucByte, 1 ); if((ucByte == '\n') || (ucByte == '\r')) { // // "carriage return" received, finished getting the string, put '\0' and return // buffer[length] = '\0'; ucByte = '\n'; UART_WriteToHost( UART_DEBUG, &ucByte, 1 ); return buffer; } if(ucByte == '\b' && length > 0) { // // Backspace character // length--; ucByte = ' '; UART_WriteToHost( UART_DEBUG, &ucByte, 1 ); ucByte = '\b'; UART_WriteToHost( UART_DEBUG, &ucByte, 1 ); } else { buffer[length] = ucByte; length ++; } } OS_Sleep(1); } return NULL; // We never ging to be here }
void OS_Init() { ip_info info; for (;;) { OS_Sleep(5); if (!sdk_wifi_get_ip_info(STATION_IF, &info)) { continue; } if (info.ip.addr == 0x00) { continue; } break; } }
//------------------Task 2-------------------------------- // background thread executes with select button // one foreground task created with button push // foreground treads run for 2 sec and die // ***********ButtonWork************* void ButtonWork(void){ unsigned long i; unsigned long myId = OS_Id(); char str[20]; sprintf(str, "NumCreated = %d", NumCreated); OLED_Out(BOTTOM, str); if(NumSamples < RUNLENGTH){ // finite time run for(i=0;i<20;i++){ // runs for 2 seconds OS_Sleep(50); // set this to sleep for 0.1 sec } } sprintf(str, "PIDWork = %d", PIDWork); OLED_Out(BOTTOM, str); sprintf(str, "DataLost = %d", DataLost); OLED_Out(BOTTOM, str); sprintf(str, "Jitter(us) = %d",MaxJitter-MinJitter); OLED_Out(BOTTOM, str); OLED_Out(BOTTOM, ""); OS_Kill(); // done OS_Delay(OS_ARBITRARY_DELAY); }
//******** Consumer *************** // foreground thread, accepts data from producer // calculates FFT, sends DC component to Display // inputs: none // outputs: none void Consumer(void){ unsigned long data,DCcomponent; // 10-bit raw ADC sample, 0 to 1023 unsigned long t; // time in ms unsigned long myId = OS_Id(); ADC_Collect(0, 1000, &Producer); // start ADC sampling, channel 0, 1000 Hz NumCreated += OS_AddThread(&Display,128,0); while(NumSamples < RUNLENGTH) { for(t = 0; t < 64; t++){ // collect 64 ADC samples OS_Fifo_Get(&data); // get from producer x[t] = data; // real part is 0 to 1023, imaginary part is 0 } cr4_fft_64_stm32(y,x,64); // complex FFT of last 64 ADC values DCcomponent = y[0]&0xFFFF; // Real part at frequency 0, imaginary part should be zero OS_Wait(&MailBoxEmpty); OS_MailBox_Send(DCcomponent); GPIO_B1 ^= 0x02; OS_Signal(&MailBoxFull); OS_Sleep(15); } OS_Kill(); // done }
/** * @brief Perform a change in operating modes on the target node * @author R.Lillback * @date 3-Sep-2015 * * @details This function: * 1.) Validates the command & data * 2.) Sends an NMT message out on the CAN bus to change modes * 3.) Waits for a NODE_STATUS message from the target node. * 4.) Validates that the status has updated to what we expect. * * This function will send the request up to 5 times, and then fail. * It does this: * 1.) Send the message * 2.) Listen for up to 12 seconds for a correct response. * 3.) Resend the message * 4.) Listen for up to 12 seconds.... * 5.) Rinse & repeat for a total of 5 messages sent. * * @param subcommand (as in integer), which is the mode you want to change to. * * @returns 0=success, anything else = failure * */ DWORD DoModeChange(DWORD subCommand) { BYTE tries = 1; // Count the number of tries DWORD finished = FALSE; // Did we get back what we expected? DWORD dwCOB_ID; // a cob_id to filter for s_MESSAGE msg = {0}; // Give us a message BYTE cntr; // just a loop variable e_MODES mode = (e_MODES)subCommand; ECI_RESULT result; if ( ((BYTE)subCommand >= 0) && ((BYTE)subCommand <= (BYTE)MODE_TESTHW) ) { if ( (iNode > 0) && (iNode < 1024) ) { // Check node OS_Printf("Asking Node %u to changed to mode %u - %s\n", iNode, mode, MODE_DESCRIPTION[(e_MODES)subCommand].strDescr); dwCOB_ID = (COB_NODE_STATUS << 7); // Looking for a node status message dwCOB_ID += iNode; // from this node while ( (tries <= MAX_TRIES) && (finished == FALSE) ) { mode = (e_MODES)subCommand; result = ChangeMode( iNode, mode ); // Request the change /* Wait for the node status to change coming back */ OS_Printf("Waiting."); OS_Fflush(stdout); result = ~ECI_OK; // Start looping cntr = 0; // clear the loop variable while ( (ECI_OK != result) && (cntr<48)) { // 48 loops at 1/4 second a loop = 12 seconds to wait OS_Sleep(QUARTER_SECOND); result = LookForMessage(&msg); // Look for a message on the FIFO queue if (ECI_OK == result) { // yes, message on the queue, now is it the one we were looking for? if ( (dwCOB_ID == msg.cob_id) && (mode == msg.data[0]) ) { // YAY, it is our message result = ECI_OK; // yeah, let's leave this while loop finished = TRUE; // and the outer while loop eMode = (e_MODES)mode; // Make sure we set the global mode status, too. } else { // it's not our message result = ~ECI_OK; // yeah, don't leave this loop } } // there was a message on the queue OS_Printf("."); OS_Fflush(stdout); cntr++; } // while not ECI_OK tries++; OS_Printf("\n"); OS_Fflush(stdout); } // while we are not finished & we haven't reached our maximum try limit } // if Targeted node was ok else { OS_Printf("Targeted Node - %u - out of range 1..1023\n", (WORD)subCommand); OS_Printf("Mode **NOT** changed. Please change node number from %u\n",iNode); } // Check node } // if subCommand is ok else { OS_Printf("Mode change is out of range. Needs to be from 0..%u\n",(BYTE)MODE_TESTHW); OS_Printf("Mode **NOT** changed."); } if (TRUE == finished) { // only if we found the result we wanted do we return OK result = ECI_OK; } else { result = ~ECI_OK; } return result; } // DoModeChange