int main(void) { buttonSemaphore = xSemaphoreCreateBinary(); port2Pin6Init(); eint3_enable_port2(6, eint_falling_edge, port6ButtonPressInterrupt); xTaskCreate(port6ButtonPressTask, "Button Press", STACK_BYTES(2048), 0, PRIORITY_HIGH, 0); xTaskCreate(beggingForSemaphore, "I NEED SEMAPHOREZ", STACK_BYTES(2048), 0, PRIORITY_HIGH, 0); vTaskStartScheduler(); return -1; }
int main(void) { q = xQueueCreate(1, sizeof(orientation_t)); //PRIORITY CAN BE SWITCHED HERE TO FOLLOW ASSIGNMENT xTaskCreate(orientConsumer, "Consumer", STACK_BYTES(2048), 0, PRIORITY_LOW, 0); xTaskCreate(orientProducer, "Producer", STACK_BYTES(2048), 0, PRIORITY_HIGH, 0); vTaskStartScheduler(); return -1; }
/* INTERRUPT VECTORS: * 0: OS Timer Tick * 1: Not Used * 2: UART0 Interrupt * 3: UART1 Interrupt * 4: I2C0 Interrupt * 5-16: Not Used */ int main(void) { OSHANDLES SysHandles; // Should contain all OS Handles cpuSetupHardware(); // Setup PLL, enable MAM etc. watchdogDelayUs(1000 * 1000); // Some startup delay uart0Init(38400, 128); // 128 is size of UART0 Rx/Tx FIFO uart1Init(38400, 128); // 128 is size of UART1 Rx/Tx FIFO // Use polling version of uart0 to do printf/rprintf before starting FreeRTOS rprintf_devopen(uart0PutCharPolling); cpuPrintMemoryInfo(); // Open interrupt-driven version of UART0 Rx/Tx rprintf_devopen(uart0PutChar); watchdogDelayUs(1000 * 1000); /** Create timer needed for SD Card I/O */ Timer diskTimer(FatFsDiskTimer, 10, TimerPeriodic); diskTimer.start(); /** Create any Queues and Mutexes **/ SysHandles.lock.SPI = xSemaphoreCreateMutex(); // TODO 2. Create the "song name" Queue here SysHandles.queue.songname = xQueueCreate(1,16); //length, item size // Use the WATERMARK command to determine optimal Stack size of each task (set to high, then slowly decrease) // Priorities should be set according to response required if (pdPASS != xTaskCreate( uartUI, (signed char*)"Uart UI", STACK_BYTES(1024*6), &SysHandles, PRIORITY_HIGH, &SysHandles.task.userInterface ) || pdPASS!= xTaskCreate( mp3Task, (signed char*)"MP3", STACK_BYTES(1024*6), &SysHandles, PRIORITY_HIGH, &SysHandles.task.mp3 ) || pdPASS!= xTaskCreate( sd_card_detect, (signed char*)"sd_card_detect", STACK_BYTES(1024), &SysHandles, PRIORITY_LOW, &SysHandles.task.sd_card_detect ) || pdPASS!= xTaskCreate( mp3_controls, (signed char*)"mp3_controls", STACK_BYTES(1024*6), &SysHandles, PRIORITY_LOW, &SysHandles.task.mp3_controls )) { rprintf( "ERROR: OUT OF MEMORY: Check OS Stack Size or task stack size.\n"); } // Start FreeRTOS to begin servicing tasks created above, vTaskStartScheduler() will not "return" rprintf("\n-- Starting FreeRTOS --\n"); vTaskStartScheduler(); // In case OS is exited: rprintf_devopen(uart0PutCharPolling); rprintf("ERROR: Unexpected OS Exit!\n"); return 0; }
bool scheduler_init_all(bool register_internal_tlm) { bool failure = false; /* If not tasks ... */ if (0 == gTaskList || 0 == gTaskList->size()) { puts("ERROR: NO tasks added by scheduler_add_task()"); failure = true; return failure; } /* Initialize all tasks */ puts("* Initializing tasks ..."); for (uint32_t i=0; i < gTaskList->size(); i++) { scheduler_task *task = gTaskList->at(i); if (!task->init()) { print_strings(task->getTaskName(), " --> FAILED init()"); failure = true; } } /* Register telemetry for all tasks */ #if ENABLE_TELEMETRY puts("* Registering tasks' telemetry ..."); for (uint32_t i=0; i < gTaskList->size(); i++) { scheduler_task *task = gTaskList->at(i); if (!task->regTlm()) { failure = true; } /* Register statistical variables of this task */ if (register_internal_tlm) { tlm_component *comp = tlm_component_add(task->mName); if (!tlm_variable_register(comp, "cpu_percent", &(task->mCpuPercent), sizeof(task->mCpuPercent), 1, tlm_uint)) { failure = true; } if (!tlm_variable_register(comp, "free_stack", &(task->mFreeStack), sizeof(task->mFreeStack), 1, tlm_uint)) { failure = true; } if (!tlm_variable_register(comp, "run_count", &(task->mRunCount), sizeof(task->mRunCount), 1, tlm_uint)) { failure = true; } } if (failure) { print_strings(task->mName, " --> FAILED telemetry registration"); } } puts("* Restoring disk telemetry"); // Restore telemetry registered by "disk" component FILE *fd = fopen(DISK_TLM_NAME, "r"); if (fd) { tlm_stream_decode_file(fd); fclose(fd); } #endif puts("* Creating tasks ..."); mRunTask = xSemaphoreCreateCounting(gTaskList->size(), 0); if (NULL == mRunTask) { failure = true; } for (uint32_t i=0; i < gTaskList->size(); i++) { scheduler_task *task = gTaskList->at(i); if (!xTaskCreate(scheduler_c_task_private, (signed char*)task->mName, /* Name */ STACK_BYTES(task->mStackSize), /* Stack */ task, /* Task param */ task->mPriority, /* Task priority */ &(task->mHandle))) /* Task Handle */ { print_strings(task->mName, " --> FAILED xTaskCreate()"); failure = true; } } /* Find the task with highest stack, and this task will then be used * to call taskEntry() for everyone once FreeRTOS starts. * We have one task do taskEntry() for all because otherwise tasks will perform * taskEntry() independent of each other, and one task might complete it and * start running without other tasks completing their taskEntry(). */ uint32_t highestStack = 0; for (uint32_t i=0; i < gTaskList->size(); i++) { scheduler_task *task = gTaskList->at(i); if (task->mStackSize > highestStack) { highestStack = task->mStackSize; mTaskEntryTaskHandle = task->mHandle; } } return failure; }