Skip to content

Commit 60dbc70

Browse files
committedDec 27, 2017
Improving comments and legibility on Os_Internal_Arch.c for the CortexM4 port.
1 parent b30f7a3 commit 60dbc70

File tree

1 file changed

+45
-17
lines changed

1 file changed

+45
-17
lines changed
 

‎src/cortexM4/Os_Internal_Arch.c

+45-17
Original file line numberDiff line numberDiff line change
@@ -93,22 +93,36 @@ TaskType WaitingTask = INVALID_TASK;
9393

9494
void ReturnHook_Arch(void)
9595
{
96-
/* Tasks shouldn't return here... */
97-
while(1) osekpause();
96+
/*
97+
* Tasks shouldn't return here...
98+
*
99+
* This is a security net for runaway tasks that reach the end of
100+
* their main body code without terminating their execution
101+
* properly using TerminateTask or something of the kind.
102+
*
103+
* */
98104

105+
while(1)
106+
{
107+
osekpause();
108+
}
99109
}
100110

101111

102112

103113
void CheckTerminatingTask_Arch(void)
104114
{
115+
/*
116+
* If there is task being terminated, destroy its context information and
117+
* reset its state so that the next time that the task is activated it
118+
* starts its execution on the first instruction of the task body.
119+
* */
120+
105121
if(TerminatingTask != INVALID_TASK)
106122
{
107-
// int i;
108-
// for(i=0; i<TasksConst[TerminatingTask].StackSize/4; i++)
109-
// ((uint32 *)TasksConst[TerminatingTask].StackPtr)[i] = 0;
110123
InitStack_Arch(TerminatingTask);
111124
}
125+
112126
TerminatingTask = INVALID_TASK;
113127
}
114128

@@ -117,7 +131,6 @@ void CheckTerminatingTask_Arch(void)
117131
/* Task Stack Initialization */
118132
void InitStack_Arch(uint8 TaskID)
119133
{
120-
121134
uint32_t *taskStackRegionPtr;
122135
int32_t taskStackSizeWords;
123136

@@ -243,23 +256,32 @@ void InitStack_Arch(uint8 TaskID)
243256
/* Periodic Interrupt Timer, included in all Cortex-M4 processors */
244257
void SysTick_Handler(void)
245258
{
246-
/* store the calling context in a variable */
259+
/* Store the calling context in a variable. */
247260
ContextType actualContext = GetCallingContext();
248-
/* set isr 2 context */
261+
262+
/* Set ISR2 context. */
249263
SetActualContext(CONTEXT_ISR2);
250264

251265
#if (ALARMS_COUNT != 0)
252-
/* counter increment */
253-
static CounterIncrementType CounterIncrement = 1;
254-
(void)CounterIncrement; /* TODO remove me */
255266

256-
/* increment the disable interrupt conter to avoid enable the interrupts */
267+
/* Counter increment. */
268+
static CounterIncrementType CounterIncrement = 1; /* TODO remove me. */
269+
270+
(void)CounterIncrement; /* This avoids a compiler warning because the variable is not being used. */
271+
272+
/*
273+
* Enter critical section.
274+
* */
257275
IntSecure_Start();
258276

259-
/* call counter interrupt handler */
277+
/*
278+
* The the RTOS counter increment handler.
279+
* */
260280
CounterIncrement = IncrementCounter(0, 1 /* CounterIncrement */); /* TODO FIXME */
261281

262-
/* set the disable interrupt counter back */
282+
/*
283+
* Exit the critical section.
284+
* */
263285
IntSecure_End();
264286

265287
#endif /* #if (ALARMS_COUNT != 0) */
@@ -268,13 +290,19 @@ void SysTick_Handler(void)
268290
SetActualContext(actualContext);
269291

270292
#if (NON_PREEMPTIVE == OSEK_DISABLE)
271-
/* check if the actual task is preemptive */
293+
294+
/*
295+
* Check if the currently active task is preemptive;
296+
* if it is, call schedule().
297+
* */
298+
272299
if ( ( CONTEXT_TASK == actualContext ) &&
273-
( TasksConst[GetRunningTask()].ConstFlags.Preemtive ) )
300+
( TasksConst[GetRunningTask()].ConstFlags.Preemtive ) )
274301
{
275-
/* this shall force a call to the scheduler */
302+
/* This shall force a call to the scheduler. */
276303
PostIsr2_Arch(isr);
277304
}
305+
278306
#endif /* #if (NON_PREEMPTIVE == OSEK_DISABLE) */
279307
}
280308

0 commit comments

Comments
 (0)
Please sign in to comment.