-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented task scheduler. Did not implement priority queue.
Could not test. TIVA on hand was defective.
- Loading branch information
1 parent
424c32e
commit 85531ee
Showing
6 changed files
with
174 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="no"?> | ||
<launchConfiguration type="com.ti.ccstudio.debug.launchType.device.debugging"> | ||
<stringAttribute key="com.ti.ccstudio.debug.debugModel.ATTR_LOAD_PROGRAM.P:\CCS\TIVA-Task-Scheduler\targetConfigs\Tiva TM4C1294NCPDT.ccxml.Stellaris In-Circuit Debug Interface/CORTEX_M4_0" value="ALL"/> | ||
<stringAttribute key="com.ti.ccstudio.debug.debugModel.ATTR_PROGRAM.P:\CCS\TIVA-Task-Scheduler\targetConfigs\Tiva TM4C1294NCPDT.ccxml.Stellaris In-Circuit Debug Interface/CORTEX_M4_0" value="${build_artifact:TIVA-Task-Scheduler}"/> | ||
<stringAttribute key="com.ti.ccstudio.debug.debugModel.ATTR_PROJECT.P:\CCS\TIVA-Task-Scheduler\targetConfigs\Tiva TM4C1294NCPDT.ccxml.Stellaris In-Circuit Debug Interface/CORTEX_M4_0" value="TIVA-Task-Scheduler"/> | ||
<stringAttribute key="com.ti.ccstudio.debug.debugModel.ATTR_TARGET_CONFIG" value="${target_config_active_default:TIVA-Task-Scheduler}"/> | ||
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS"> | ||
<listEntry value="/TIVA-Task-Scheduler"/> | ||
</listAttribute> | ||
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES"> | ||
<listEntry value="4"/> | ||
</listAttribute> | ||
<stringAttribute key="org.eclipse.debug.core.source_locator_id" value="com.ti.ccstudio.debug.sourceLocator"/> | ||
<stringAttribute key="org.eclipse.debug.core.source_locator_memento" value="<?xml version="1.0" encoding="UTF-8" standalone="no"?> <sourceLookupDirector> <sourceContainers duplicates="false"> <container memento="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#13;&#10;&lt;default/&gt;&#13;&#10;" typeId="org.eclipse.debug.core.containerType.default"/> <container memento="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#13;&#10;&lt;cpuSpecificContainer cpuName=&quot;Stellaris In-Circuit Debug Interface/CORTEX_M4_0&quot;&gt;&#13;&#10;&lt;childContainerEntry childMemento=&quot;&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;UTF-8&amp;quot; standalone=&amp;quot;no&amp;quot;?&amp;gt;&amp;#13;&amp;#10;&amp;lt;project name=&amp;quot;TIVA-Task-Scheduler&amp;quot; referencedProjects=&amp;quot;true&amp;quot;/&amp;gt;&amp;#13;&amp;#10;&quot; childType=&quot;org.eclipse.debug.core.containerType.project&quot;/&gt;&#13;&#10;&lt;childContainerEntry childMemento=&quot;&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;UTF-8&amp;quot; standalone=&amp;quot;no&amp;quot;?&amp;gt;&amp;#13;&amp;#10;&amp;lt;default/&amp;gt;&amp;#13;&amp;#10;&quot; childType=&quot;org.eclipse.debug.core.containerType.default&quot;/&gt;&#13;&#10;&lt;childContainerEntry childMemento=&quot;&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;UTF-8&amp;quot; standalone=&amp;quot;no&amp;quot;?&amp;gt;&amp;#13;&amp;#10;&amp;lt;productsSource/&amp;gt;&amp;#13;&amp;#10;&quot; childType=&quot;com.ti.ccstudio.debug.containerType.products.source&quot;/&gt;&#13;&#10;&lt;childContainerEntry childMemento=&quot;&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;UTF-8&amp;quot; standalone=&amp;quot;no&amp;quot;?&amp;gt;&amp;#13;&amp;#10;&amp;lt;deviceLibrarySource/&amp;gt;&amp;#13;&amp;#10;&quot; childType=&quot;com.ti.ccstudio.debug.containerType.device.library.source&quot;/&gt;&#13;&#10;&lt;childContainerEntry childMemento=&quot;&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;UTF-8&amp;quot; standalone=&amp;quot;no&amp;quot;?&amp;gt;&amp;#13;&amp;#10;&amp;lt;librarySource/&amp;gt;&amp;#13;&amp;#10;&quot; childType=&quot;com.ti.ccstudio.debug.containerType.library.source&quot;/&gt;&#13;&#10;&lt;childContainerEntry childMemento=&quot;&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;UTF-8&amp;quot; standalone=&amp;quot;no&amp;quot;?&amp;gt;&amp;#13;&amp;#10;&amp;lt;project name=&amp;quot;PUMA260&amp;quot; referencedProjects=&amp;quot;true&amp;quot;/&amp;gt;&amp;#13;&amp;#10;&quot; childType=&quot;org.eclipse.debug.core.containerType.project&quot;/&gt;&#13;&#10;&lt;/cpuSpecificContainer&gt;&#13;&#10;" typeId="com.ti.ccstudio.debug.containerType.cpu.specific"/> </sourceContainers> </sourceLookupDirector> "/> | ||
</launchConfiguration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,113 @@ | ||
//Project includes | ||
#include "TaskScheduler.h" | ||
|
||
//Tivaware includes | ||
#include <driverlib/sysctl.h> | ||
#include <driverlib/timer.h> | ||
#include <inc/hw_ints.h> | ||
#include <driverlib/interrupt.h> | ||
|
||
#ifndef NULL | ||
#define NULL 0 | ||
#endif | ||
|
||
static volatile TaskScheduler scheduler; | ||
|
||
void InitializeTaskScheduler(uint32_t timerBase){ | ||
/* | ||
* Timer ISR for the task scheduler | ||
* | ||
* Updates each timer's task | ||
* If the task is ready to be fired, then it is added to a queue and processed | ||
* | ||
* This timer must be given a low priority ISR because it is possible to have | ||
* a heavy load to process | ||
*/ | ||
void TaskSchedulerTimer_ISR(void){ | ||
//Loop through every task | ||
Task *pTask = scheduler.pTaskListRoot; | ||
while(pTask){ | ||
if(pTask->enabled){ | ||
pTask->ticks++; | ||
|
||
if(pTask->ticks >= pTask->maxTicks){ | ||
pTask->ticks = 0; | ||
|
||
//Add task to priority queue | ||
//TODO: Implement priority queue | ||
pTask->pCallback(); | ||
} | ||
} | ||
else{ | ||
//Do nothing | ||
} | ||
|
||
//Move to next task | ||
pTask = pTask->pNextTask; | ||
} | ||
|
||
TimerIntClear(scheduler.timerBase, TIMER_TIMA_TIMEOUT); | ||
} | ||
|
||
void InitializeTaskScheduler(uint32_t timerBase, uint16_t sysClkFreq, uint32_t timerIntBase){ | ||
//Initialize the task scheduler | ||
scheduler.timerBase = timerBase; | ||
scheduler.pTaskListRoot = NULL; | ||
|
||
//Initialize the timer | ||
SysCtlPeripheralEnable(timerBase); | ||
|
||
//Wait for the clock to stabilize | ||
SysCtlDelay(10); | ||
|
||
//Configure the timer to be a periodic 100us timer | ||
TimerConfigure(timerBase, TIMER_CFG_PERIODIC); | ||
TimerLoadSet(timerBase, TIMER_A, sysClkFreq * TASK_SCHEDULER_TIMER_PERIOD / 1000000); | ||
|
||
//Configure the ISR | ||
TimerIntRegister(timerBase, TIMER_BOTH, TaskSchedulerTimer_ISR); | ||
IntEnable(timerIntBase); | ||
TimerIntEnable(timerBase, TIMER_TIMA_TIMEOUT); | ||
|
||
//Enable the timer and interrupts | ||
TimerEnable(timerBase, TIMER_A); | ||
IntMasterEnable(); | ||
} | ||
|
||
void AddTask(Task *pTask){ | ||
//Reset the task and calculate the max ticks | ||
pTask->ticks = 0; | ||
pTask->maxTicks = pTask->period * TASK_SCHEDULER_TICKS_IN_ONE_SECOND; | ||
|
||
//Add the task to the list | ||
pTask->pNextTask = scheduler.pTaskListRoot; | ||
scheduler.pTaskListRoot = pTask; | ||
} | ||
|
||
//Only remove the task if you must | ||
//It is recommended to just disable the task | ||
void RemoveTask(Task *pTask){ | ||
Task *pTaskRoot = scheduler.pTaskListRoot; | ||
|
||
//Loop until we are pointing to the task before the one to be removed | ||
//Or no task was found | ||
bool taskFound = false; | ||
while(pTaskRoot->pNextTask){ | ||
if(pTaskRoot->pNextTask == pTask){ | ||
taskFound = true; | ||
break; | ||
} | ||
else{ | ||
//Keep searching | ||
pTaskRoot = pTaskRoot->pNextTask; | ||
} | ||
} | ||
|
||
if(taskFound){ | ||
//Remove the task from the list | ||
pTaskRoot->pNextTask = pTask->pNextTask; | ||
} | ||
} | ||
void DisableTask(Task *pTask){ | ||
|
||
void DisableTask(Task *pTask){ | ||
pTask->enabled = false; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters