systime.c File Reference

Implementation: system time services. More...

#include <config.h>
#include <sys/time.h>
#include <sys/h8.h>
#include <sys/irq.h>
#include <sys/dmotor.h>
#include <sys/dsound.h>
#include <sys/battery.h>
#include <sys/critsec.h>
#include <sys/timeout.h>
Include dependency graph for systime.c:

Go to the source code of this file.

Functions

void clock_handler (void)
 clock handler triggered on the WDT overflow (every msec) on the NMI More...
 
void subsystem_handler (void)
 subsystem handler for every 2nd msec More...
 
void task_switch_handler (void)
 task switch handler called every msec More...
 
void systime_init (void)
 initialize system timer More...
 
void systime_shutdown (void)
 shutdown system timer More...
 
void systime_set_switcher (void *switcher)
 set task switcher vector More...
 
void systime_set_timeslice (unsigned char slice)
 set multitasking timeslice in ms More...
 
time_t get_system_up_time (void)
 retrieve the current system time More...
 
 __asm__ ("\n\ .text\n\ .align 1\n\ .global _get_system_up_time\n\ _get_system_up_time:\n\ push r2\n\ try_again:\n\ mov.w @_sys_time+2, r1\n\ mov.w @_sys_time, r0\n\ mov.w @_sys_time+2, r2\n\ cmp r2, r1\n\ bne try_again\n\ pop r2\n\ rts\n\ ")
 

Variables

volatile time_t sys_time
 current system time in ms More...
 
volatile unsigned char tm_timeslice
 task time slice More...
 
volatile unsigned char tm_current_slice
 current time remaining More...
 
void * tm_switcher_vector
 pointer to task switcher More...
 

Detailed Description

Implementation: system time services.

Author
Markus L. Noga marku.nosp@m.s@no.nosp@m.ga.de

Definition in file systime.c.

Function Documentation

◆ __asm__()

__asm__ ( "\n\.text\n\.align 1\n\.global _get_system_up_time\n\_get_system_up_time:\n\ push r2\n\ try_again:\n\ mov.w @_sys_time+  2,
r1\n\ mov.w @  _sys_time,
r0\n\ mov.w @_sys_time+  2,
r2\n\ cmp  r2,
r1\n\ bne try_again\n\ pop r2\n\ rts\n\"   
)

◆ clock_handler()

void clock_handler ( void  )

clock handler triggered on the WDT overflow (every msec) on the NMI

this is the system clock

Referenced by systime_init().

◆ get_system_up_time()

time_t get_system_up_time ( void  )

retrieve the current system time

Returns
number of msecs the system has been running Since sys_time is 32bits, it takes more than one instruction to retrieve; the NMI can fire mid retrieval; causing the upper and lower 16bits to be unmatched (lower 16bits could overflow and reset to 0, while upper 16bits were already read)

◆ subsystem_handler()

void subsystem_handler ( void  )

subsystem handler for every 2nd msec

this is the pulse of the system (subsystems). sound, motor and lcd driver calls are initiated here. task_switch_handler is called from here as well.

Referenced by systime_init().

◆ systime_init()

◆ systime_set_switcher()

void systime_set_switcher ( void *  switcher)

set task switcher vector

Parameters
switcherthe switcher

Definition at line 326 of file systime.c.

References tm_switcher_vector.

◆ systime_set_timeslice()

void systime_set_timeslice ( unsigned char  slice)

set multitasking timeslice in ms

Parameters
slicethe timeslice. must be at least 5ms.

Definition at line 333 of file systime.c.

References tm_current_slice, and tm_timeslice.

◆ systime_shutdown()

void systime_shutdown ( void  )

shutdown system timer

will also stop task switching and motors.

Definition at line 317 of file systime.c.

References T_IER, TIER_ENABLE_OCA, TIER_ENABLE_OCB, and WDT_CSR.

Referenced by systime_init().

◆ task_switch_handler()

void task_switch_handler ( void  )

task switch handler called every msec

handles swapping between tasks

Referenced by systime_init().

Variable Documentation

◆ sys_time

volatile time_t sys_time

current system time in ms

Warning
This is a 32 bit value which will overflow after 49.7 days of continuous operation.

Definition at line 63 of file systime.c.

Referenced by systime_init().

◆ tm_current_slice

volatile unsigned char tm_current_slice

current time remaining

Definition at line 73 of file systime.c.

Referenced by systime_init(), and systime_set_timeslice().

◆ tm_switcher_vector

void* tm_switcher_vector

pointer to task switcher

Definition at line 75 of file systime.c.

Referenced by systime_init(), and systime_set_switcher().

◆ tm_timeslice

volatile unsigned char tm_timeslice

task time slice

Definition at line 72 of file systime.c.

Referenced by systime_init(), and systime_set_timeslice().


brickOS is released under the Mozilla Public License.
Original code copyright 1998-2005 by the authors.

Generated for brickOS Kernel Developer by doxygen 1.9.4