Skip to content

Commit

Permalink
Added support for TM4C123 series.
Browse files Browse the repository at this point in the history
Fixed crashing issue. Had to add another parameter to task scheduler init (sysctl periph value).

Did simple testing to prove task scheduler works. More advanced testing, like measuring jitter, was not done.
  • Loading branch information
jackerzhaques committed May 19, 2019
1 parent 609ff32 commit ab82708
Show file tree
Hide file tree
Showing 8 changed files with 467 additions and 56 deletions.
86 changes: 46 additions & 40 deletions .cproject

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions .launches/TIVA-Task-Scheduler.launch
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
<?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_DEBUGGER_PROPERTIES.P:\CCS\TIVA-Task-Scheduler\targetConfigs\Tiva TM4C123GH6PM.ccxml.Stellaris In-Circuit Debug Interface/CORTEX_M4_0" value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot; ?&gt;&#10;&lt;PropertyValues&gt;&#10;&#10; &lt;property id=&quot;ConnectOnStartup&quot;&gt;&#10; &lt;curValue&gt;1&lt;/curValue&gt;&#10; &lt;/property&gt;&#10;&#10; &lt;property id=&quot;EnableInstalledBreakpoint&quot;&gt;&#10; &lt;curValue&gt;1&lt;/curValue&gt;&#10; &lt;/property&gt;&#10;&#10; &lt;property id=&quot;IgnoreSoftLaunchFailures&quot;&gt;&#10; &lt;curValue&gt;0&lt;/curValue&gt;&#10; &lt;/property&gt;&#10;&#10;&lt;/PropertyValues&gt;&#10;"/>
<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 TM4C123GH6PM.ccxml.Stellaris In-Circuit Debug Interface/CORTEX_M4_0" value="${build_artifact:TIVA-Task-Scheduler}"/>
<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 TM4C123GH6PM.ccxml.Stellaris In-Circuit Debug Interface/CORTEX_M4_0" value="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}"/>
<stringAttribute key="com.ti.ccstudio.debug.debugModel.MRU_PROGRAM.P:\CCS\TIVA-Task-Scheduler\targetConfigs\Tiva TM4C123GH6PM.ccxml.Stellaris In-Circuit Debug Interface/CORTEX_M4_0" value="P:/CCS\TIVA-Task-Scheduler\Debug\TIVA-Task-Scheduler.out"/>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
<listEntry value="/TIVA-Task-Scheduler"/>
</listAttribute>
Expand Down
11 changes: 7 additions & 4 deletions TaskScheduler/TaskScheduler.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include <driverlib/timer.h>
#include <inc/hw_ints.h>
#include <driverlib/interrupt.h>
#include <inc/hw_memmap.h>
#include <driverlib/rom.h>

#ifndef NULL
#define NULL 0
Expand Down Expand Up @@ -48,19 +50,21 @@ void TaskSchedulerTimer_ISR(void){
TimerIntClear(scheduler.timerBase, TIMER_TIMA_TIMEOUT);
}

void InitializeTaskScheduler(uint32_t timerBase, uint32_t sysClkFreq, uint32_t timerIntBase){
void InitializeTaskScheduler(uint32_t timerBase, uint32_t sysCtlTimerPeriph, uint32_t sysClkFreq, uint32_t timerIntBase){
//Initialize the task scheduler
scheduler.timerBase = timerBase;
scheduler.pTaskListRoot = NULL;

//Initialize the timer
SysCtlPeripheralEnable(timerBase);
SysCtlPeripheralEnable(sysCtlTimerPeriph);

//Wait for the clock to stabilize
SysCtlDelay(10);
SysCtlDelay(100);
IntMasterEnable();

//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
Expand All @@ -70,7 +74,6 @@ void InitializeTaskScheduler(uint32_t timerBase, uint32_t sysClkFreq, uint32_t t

//Enable the timer and interrupts
TimerEnable(timerBase, TIMER_A);
IntMasterEnable();
}

void AddTask(Task *pTask){
Expand Down
4 changes: 2 additions & 2 deletions TaskScheduler/TaskScheduler.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

//For the most accurate timer, choose a frequency that is an integer
#define TASK_SCHEDULER_TIMER_PERIOD 100 //us
#define TASK_SCHEDULER_TICKS_IN_ONE_SECOND 1/TASK_SCHEDULER_TIMER_PERIOD
#define TASK_SCHEDULER_TICKS_IN_ONE_SECOND 1/TASK_SCHEDULER_TIMER_PERIOD * 1000000

struct Task_tag;
typedef struct Task_tag Task;
Expand All @@ -28,7 +28,7 @@ typedef struct TaskScheduler_tag{
Task *pTaskListRoot;
} TaskScheduler;

void InitializeTaskScheduler(uint32_t timerBase, uint32_t sysClkFreq, uint32_t timerIntBase);
void InitializeTaskScheduler(uint32_t timerBase, uint32_t sysCtlTimerPeriph, uint32_t sysClkFreq, uint32_t timerIntBase);

void AddTask(Task *pTask);
void RemoveTask(Task *pTask);
Expand Down
60 changes: 50 additions & 10 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,16 @@
#include "driverlib/ssi.h"
#include "driverlib/uart.h"
#include "utils/uartstdio.h"
#include "driverlib/fpu.h"
#include <driverlib/timer.h>
#include <driverlib/interrupt.h>

//System clock running at 120MHz
#define SYS_CLK 120000000
//System clock running at 120MHz if 129 or 80MHz if 123
#ifdef PART_TM4C129
#define SYS_CLK 120000000
#elif PART_TM4C123
#define SYS_CLK 80000000
#endif

void EnableClock(void);
void EnablePeripherals();
Expand All @@ -34,32 +41,65 @@ void sprintfloat(char *Buffer, float val, int arg1){
sprintf(Buffer, "%i.%i", LeftSide, RightSide);
}

void print(){
UARTprintf("Task 1");
}

void print2(){
UARTprintf("Task 2");
}

void print3(){
UARTprintf("Task 3");
}

Task tasks[3];

int main(void)
{
FPULazyStackingEnable();
EnableClock();
EnablePeripherals();

InitializeTaskScheduler(TIMER0_BASE, SYSCTL_PERIPH_TIMER0, SYS_CLK, INT_TIMER0A);

tasks[0].period = 3;
tasks[0].enabled = 1;
tasks[0].pCallback = print;

tasks[1].period = 1.5;
tasks[1].enabled = 1;
tasks[1].pCallback = print2;

tasks[2].period = 1;
tasks[2].enabled = 1;
tasks[2].pCallback = print3;

AddTask(&tasks[0]);
AddTask(&tasks[1]);
AddTask(&tasks[2]);

while(1){
}
}

void EnableClock(void){

#ifdef PART_TM4C129
SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |
SYSCTL_OSC_MAIN |
SYSCTL_USE_PLL |
SYSCTL_CFG_VCO_480), SYS_CLK);
#elif PART_TM4C123
SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ | SYSCTL_OSC_MAIN);
uint32_t g_ui32SysClock = SysCtlClockGet ();
#endif
}

/*
Enables all peripherals needed for this motor driver test
*/
void EnablePeripherals(void){
InitConsole();

InitializeTaskScheduler(TIMER0_BASE, SYS_CLK, INT_TIMER0A);

while(1){
UARTprintf("Hello world!");
SysCtlDelay(SYS_CLK / 3);
}
}

//Initializes UART0 to be used as a console.
Expand Down
13 changes: 13 additions & 0 deletions targetConfigs/Tiva TM4C123GH6PM.ccxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<configurations XML_version="1.2" id="configurations_0">
<configuration XML_version="1.2" id="configuration_0">
<instance XML_version="1.2" desc="Stellaris In-Circuit Debug Interface" href="connections/Stellaris_ICDI_Connection.xml" id="Stellaris In-Circuit Debug Interface" xml="Stellaris_ICDI_Connection.xml" xmlpath="connections"/>
<connection XML_version="1.2" id="Stellaris In-Circuit Debug Interface">
<instance XML_version="1.2" href="drivers/stellaris_cs_dap.xml" id="drivers" xml="stellaris_cs_dap.xml" xmlpath="drivers"/>
<instance XML_version="1.2" href="drivers/stellaris_cortex_m4.xml" id="drivers" xml="stellaris_cortex_m4.xml" xmlpath="drivers"/>
<platform XML_version="1.2" id="platform_0">
<instance XML_version="1.2" desc="Tiva TM4C123GH6PM" href="devices/tm4c123gh6pm.xml" id="Tiva TM4C123GH6PM" xml="tm4c123gh6pm.xml" xmlpath="devices"/>
</platform>
</connection>
</configuration>
</configurations>
45 changes: 45 additions & 0 deletions tm4c123gh6pm.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/******************************************************************************
*
* Default Linker Command file for the Texas Instruments TM4C123GH6PM
*
* This is derived from revision 15071 of the TivaWare Library.
*
*****************************************************************************/

--retain=g_pfnVectors

MEMORY
{
FLASH (RX) : origin = 0x00000000, length = 0x00040000
SRAM (RWX) : origin = 0x20000000, length = 0x00008000
}

/* The following command line options are set as part of the CCS project. */
/* If you are building using the command line, or for some reason want to */
/* define them here, you can uncomment and modify these lines as needed. */
/* If you are using CCS for building, it is probably better to make any such */
/* modifications in your CCS project and leave this file alone. */
/* */
/* --heap_size=0 */
/* --stack_size=256 */
/* --library=rtsv7M4_T_le_eabi.lib */

/* Section allocation in memory */

SECTIONS
{
.intvecs: > 0x00000000
.text : > FLASH
.const : > FLASH
.cinit : > FLASH
.pinit : > FLASH
.init_array : > FLASH

.vtable : > 0x20000000
.data : > SRAM
.bss : > SRAM
.sysmem : > SRAM
.stack : > SRAM
}

__STACK_TOP = __stack + 512;
Loading

0 comments on commit ab82708

Please sign in to comment.