|
Functions | |
| __VOID | __systemThread (__VOID) |
| System thread. | |
| __STATIC __VOID | __systemInitThread (__VOID) |
| Creates the system threads. | |
| __VOID | __systemInit (__APP_ENTRY *entry) |
| System initialization. | |
| __VOID | __systemProcessTick (__VOID) |
| Manages the system tick timer. | |
| __VOID | __systemStop (__VOID) |
| Disables interrupts. | |
| __VOID | __systemStart (__VOID) |
| Enables interrupts. | |
| __VOID | __systemEnableScheduler (__VOID) |
| Enables scheduler. | |
| __VOID | __systemDisableScheduler (__VOID) |
| Disables scheduler. | |
| __VOID | __systemScheduleThreadChange (__VOID) |
| Schedules a context switch. | |
| __VOID | __systemEnterISR (__VOID) |
| Enter ISR. | |
| __VOID | __systemLeaveISR (__VOID) |
| Leave ISR. | |
| u32 | __systemGetTickCount (__VOID) |
| Gets the system tick count from the last reset. | |
| u32 | __systemGetSecondsCount (__VOID) |
| Gets the seconds passed from the last reset. | |
| u32 | __systemGetIrqCount (__VOID) |
| Gets the nested interrupt count. | |
| __BOOL | __systemSchedulerDisabled (__VOID) |
| Call this function to check if the scheduler is disabled. | |
System thread.
Internal thread, created after system initialization (__systemCreateThread() function). Calls the application's entry point and should perform maintenance tasks.
Add maintenance tasks.
Add __heapDefrag() as user option.
Definition at line 102 of file system.c.
{
u32 ticks = __systemTickCount;
/* Start thread for software timers */
#if __CONFIG_ENABLE_SWTIMERS
__timerInit(__CONFIG_STACK_TIMTHREAD);
#endif
/* Initialize the Debug Terminal, if enabled */
#if __CONFIG_DBGTERM_ENABLED
__dbgInit();
#endif // __CONFIG_DBGTERM_ENABLED
if (__systemAppEntry)
{
(__systemAppEntry)();
}
for(;;)
{
#if __CONFIG_ENABLE_WATCHDOG
if (!__systemReset)
{
// __cpuResetWatchdog();
}
#endif /* __CONFIG_ENABLE_WATCHDOG */
#if __CONFIG_ENABLE_HEARTBEAT
__cpuHeartBeat();
#endif /* __CONFIG_ENABLE_HEARTBEAT */
/* Seconds counter */
if (__systemTickCount < ticks)
{
/* overflowed */
ticks = 0xFFFFFFFF - ticks;
}
if (__systemTickCount - ticks > CPU_MS_TO_TICKS(1000))
{
__systemSecondsCount += (__systemTickCount - ticks) / CPU_MS_TO_TICKS(1000);
ticks = __systemTickCount;
}
__threadSleep(__CONFIG_SYSTHREAD_SLEEP_TIME);
}
}

Creates the system threads.
Internal use. Called from __systemInit() function.
Definition at line 158 of file system.c.
{
/* Create system thread */
__systemThreadPtr = __threadCreate( "system", /* name */
__systemThread, /* function */
__CONFIG_PRIO_SYSTHREAD, /* priority */
__CONFIG_STACK_SYSTHREAD, /* stack */
1, /* time to live */
__NULL); /* parameter */
/* Call platform custom initialization before activating
* the scheduler
*/
__cpuCustomCreateSystemThread();
}

| __VOID __systemInit | ( | __APP_ENTRY * | entry | ) |
System initialization.
Call this function to start the OS. Provide an __APP_ENTRY() function pointer that will be called from the System thread upon initialization. This function is intended to never return, the application will take control of the system from the __APP_ENTRY() function.
| entry | Pointer to the application entry function. |
Definition at line 186 of file system.c.
{
/* Avoid interrupts we are not handling yet */
__systemStop();
__systemAppEntry = entry;
/* Init CPU hardware */
__cpuInitHardware();
/* MMU */
__cpuStartMMU();
/* Init Interrupts */
__cpuInitInterrupts();
/* Init Heap */
__heapInit(&__CPU_HEAP_BASE, (u32) &__CPU_HEAP_SIZE);
/* Init RTC */
#if __CONFIG_COMPILE_RTC
__rtcInit();
#endif /* __CONFIG_COMPILE_RTC */
/* Initialize Watchdog */
#if __CONFIG_ENABLE_WATCHDOG
// __cpuStartWatchdog();
#endif /* __CONFIG_ENABLE_WATCHDOG */
/* Create System Threads */
__systemInitThread();
/* Init Scheduler timer after creating the first thread */
__cpuInitSchedulerTimer();
__systemScheduleThreadChange();
/* Enable interrupts */
__systemStart();
/* If everything is OK, we should be running the OS by now.
* This function will never return. __systemThread() will now enter execution under
* the context of the OS.
*/
for (;;)
{
}
}

Manages the system tick timer.
Called from platform implementation of the system tick timer.
Definition at line 242 of file system.c.
{
/* Software system ticks */
__systemTickCount++;
__threadProcessTick();
}

| __VOID __systemStop | ( | __VOID | ) |
Disables interrupts.
Definition at line 254 of file system.c.
{
if (!__systemIrqCount)
{
__cpuDisableInterrupts();
}
__systemIrqCount++;
}
Enables interrupts.
Definition at line 268 of file system.c.
{
if (__systemIrqCount && --__systemIrqCount) {
return;
}
/* enable interrupts */
__cpuEnableInterrupts();
}
Enables scheduler.
Enables context switching. This function will check if a previous request from a context change was made, while the scheduler was disabled. If so, and the first thread in the ready list has a higher priority than the current one, a context switch will take place.
Definition at line 289 of file system.c.
{
__systemStop();
if (__systemContextSwCount)
{
__systemContextSwCount--;
/* Check for pending thread change request */
if (!__systemContextSwCount && __systemContextSwRequest)
{
__systemContextSwRequest = 0;
/* Check if there is a ready thread with higher priority
* than the current one.
*/
if (__threadGetCurrent()) {
if (__threadGetCurrent()->th_priority > __threadGetReady()->th_priority)
{
__threadAddToReadyList(__threadGetCurrent());
__threadSetCurrent(__NULL);
__systemScheduleThreadChange();
}
}
}
}
__systemStart();
}

Disables scheduler.
Disables context switching.
Definition at line 324 of file system.c.
{
__systemStop();
__systemContextSwCount++;
if (__cpuThreadChangeScheduled())
__cpuClearPendingThreadChange();
__systemStart();
}

Schedules a context switch.
Definition at line 338 of file system.c.
{
if (!__systemContextSwCount)
{
__cpuScheduleThreadChange();
} else
{
__systemContextSwRequest = 1;
}
}

| u32 __systemGetTickCount | ( | __VOID | ) |
Gets the system tick count from the last reset.
Definition at line 376 of file system.c.
{
return __systemTickCount;
}
| u32 __systemGetSecondsCount | ( | __VOID | ) |
Gets the seconds passed from the last reset.
Definition at line 386 of file system.c.
{
return __systemSecondsCount;
}
| u32 __systemGetIrqCount | ( | __VOID | ) |
Gets the nested interrupt count.
Definition at line 396 of file system.c.
{
return __systemIrqCount;
}
Call this function to check if the scheduler is disabled.
Definition at line 406 of file system.c.
{
if (__systemContextSwCount) return __TRUE;
return __FALSE;
}