Milos RTOS v0.3.4a
Real Time Operating System
Functions
Collaboration diagram for Functions:

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.

Function Documentation

System thread.

Internal thread, created after system initialization (__systemCreateThread() function). Calls the application's entry point and should perform maintenance tasks.

Returns:
Nothing.
Todo:

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);
    }
}

Here is the call graph for this function:

Creates the system threads.

Internal use. Called from __systemInit() function.

Returns:
Nothing.

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();
}

Here is the call graph for this function:

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.

Parameters:
entryPointer to the application entry function.
Returns:
Nothing.

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 (;;)
    {
    }
}

Here is the call graph for this function:

Manages the system tick timer.

Called from platform implementation of the system tick timer.

Returns:
Nothing.

Definition at line 242 of file system.c.

{
    /* Software system ticks */
    __systemTickCount++;
    __threadProcessTick();
}

Here is the call graph for this function:

Disables interrupts.

Returns:
Nothing.

Definition at line 254 of file system.c.

Enables interrupts.

Returns:
Nothing.

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.

Returns:
Nothing.

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();
}

Here is the call graph for this function:

Disables scheduler.

Disables context switching.

Returns:
Nothing.

Definition at line 324 of file system.c.

Here is the call graph for this function:

Schedules a context switch.

Returns:
Nothing.

Definition at line 338 of file system.c.

Here is the call graph for this function:

Enter ISR.

Returns:
Nothing.

Definition at line 354 of file system.c.

Leave ISR.

Returns:
Nothing.

Definition at line 365 of file system.c.

Gets the system tick count from the last reset.

Returns:
The count of system ticks.

Definition at line 376 of file system.c.

{
    return __systemTickCount;
}

Gets the seconds passed from the last reset.

Returns:
The seconds passed from the last reset.

Definition at line 386 of file system.c.

Gets the nested interrupt count.

Returns:
The nested interrupt count.

Definition at line 396 of file system.c.

{
    return __systemIrqCount;
}

Call this function to check if the scheduler is disabled.

Returns:
__TRUE is the scheduler is disabled, otherwise __FALSE.

Definition at line 406 of file system.c.

{
    if (__systemContextSwCount) return __TRUE;
    return __FALSE;
}
 All Data Structures Files Functions Variables Typedefs Defines