fremoclock  1_3A01
FREMO Clock - Software for UTG
ClockKernel.c File Reference

User function called by timer ISR. More...

Go to the source code of this file.

Functions

static void ClockGeneratePulse (void)
 This function is called by SysHWTimer every 100ms. More...
 
void ClockKernelInit (void)
 Initialization of the pulse generator. More...
 
void SysTimerUserInterrupt (void)
 This function is called by SysHWTimer every 1ms. More...
 
void SysTimerUserInterrupt10 (void)
 This function is called by SysHWTimer every 10ms. More...
 
void SysTimerUserInterrupt100 (void)
 This function is called by SysHWTimer every 100ms. More...
 
void ClockSetStatus (uint8_t ucStatus)
 Set status of pulse generator. More...
 
uint8_t ClockReadStatus (void)
 Read status of pulse generator. More...
 
uint8_t ClockIsRunning (void)
 Value used as parameter to ClockSetStatus() to start clock. More...
 
void ClockSetPeriod (uint16_t uiPeriod)
 Set length of model minute in 100ms. More...
 
uint16_t ClockReadPeriod (void)
 Get length of model minute in 100ms. More...
 
void ClockSetPulse (uint16_t uiPulse)
 Set length of pulse length in 100ms. More...
 
uint16_t ClockReadPulse (void)
 Get length of pulse length in 100ms. More...
 
void ClockSetTime (fclock_t newValue)
 Set actual time. More...
 
fclock_t ClockGetTime (void)
 Get actual time. More...
 
void ClockSetTimeFactor (uint8_t ucFactor)
 Set time factor. More...
 
uint8_t ClockReadTimeFactor (void)
 Get time factor. More...
 
void ClockSetStartTimeMinute (uint8_t ucMinute)
 Set the minute of the start time. More...
 
uint8_t ClockReadStartTimeMinute (void)
 Get the minute of the start time. More...
 
void ClockSetStartTimeHour (uint8_t ucHour)
 Set the hour of the start time. More...
 
uint8_t ClockReadStartTimeHour (void)
 Get the hour of the start time. More...
 
void ClockSetEndTimeMinute (uint8_t ucMinute)
 Set the minute of the end time. More...
 
uint8_t ClockReadEndTimeMinute (void)
 Get the minute of the end time. More...
 
void ClockSetEndTimeHour (uint8_t ucHour)
 Set the hour of the end time. More...
 
uint8_t ClockReadEndTimeHour (void)
 Get the hour of the end time. More...
 

Variables

static volatile uint16_t uiClockTimer = 0
 Gets decremented every 100 milliseconds by interrupt. More...
 
static volatile uint16_t uiClockPeriod = 0
 Value of minute in model time (60 in 1:1) at least 2*uiClockPulse. More...
 
static volatile uint16_t uiClockPulse = 0
 Length of pulse on the clock line. More...
 
static volatile uint8_t ucClockStatus = 0
 Clock status byte. More...
 
static volatile bool ucClockOddPulse = 0
 odd minute?! More...
 
static volatile fclock_t ucClock = CLOCK_MIDNIGHT
 actual model time More...
 
static uint8_t ucClockTimeFactor
 
static uint8_t ucStartTimeMinute
 
static uint8_t ucStartTimeHour
 
static uint8_t ucEndTimeMinute
 
static uint8_t ucEndTimeHour
 

Detailed Description

User function called by timer ISR.

Subroutines for clock kernel with:

  • Init
  • UserISR (userdefined function, called by SysHWTimer every 1mS)
  • handler

Software:

  • AVR-GCC

Targets:

  • AtMega128 on PROTO_128
  • AtMega48/88/168

History:

  • 070102 First implementation (R 0)
  • 070104 Development stopped. Only the trick with the headerfile is supported.
  • 070225 Complete Rework. Now it is working
  • 070311 Added new functions and removed old debugging code
  • 150427 StS: Rename file
  • 150518 StS: function for is running state
Version
$Id: ClockKernel.c 159 2016-09-03 06:51:47Z pischky $
Author
Bernd Wisotzki [BA] wsb56.nosp@m.@use.nosp@m.rs.so.nosp@m.urce.nosp@m.forge.nosp@m..net
Date
25-Feb-2007

Definition in file ClockKernel.c.

Function Documentation

static void ClockGeneratePulse ( void  )
static

This function is called by SysHWTimer every 100ms.

Be careful, not to overload this isr. Runs with global interrupts disabled. It generates the clock pulse on the output pin and increment actual model time as appropriate.

Definition at line 458 of file ClockKernel.c.

fclock_t ClockGetTime ( void  )

Get actual time.

Atomic access to variable clock.

Returns
the actual time
See also
ClockSetTime()

Definition at line 317 of file ClockKernel.c.

uint8_t ClockIsRunning ( void  )

Value used as parameter to ClockSetStatus() to start clock.

Returns
_BV(CLOCK_STATUS_RUN) | _BV(CLOCK_STATUS_TIME)

Definition at line 228 of file ClockKernel.c.

void ClockKernelInit ( void  )

Initialization of the pulse generator.

Definition at line 107 of file ClockKernel.c.

uint8_t ClockReadEndTimeHour ( void  )

Get the hour of the end time.

Returns
the current value of variable endTimeHour
See also
ClockSetEndTimeMinute()
ClockReadEndTimeMinute()
ClockSetEndTimeHour()

Definition at line 446 of file ClockKernel.c.

uint8_t ClockReadEndTimeMinute ( void  )

Get the minute of the end time.

Returns
the current value of variable endTimeMinute
See also
ClockSetEndTimeMinute()
ClockSetEndTimeHour()
ClockReadEndTimeHour()

Definition at line 422 of file ClockKernel.c.

uint16_t ClockReadPeriod ( void  )

Get length of model minute in 100ms.

The read is done with interrupts disabled.

Returns
the current value of clockPeriod
See also
ClockSetPeriod()

Definition at line 255 of file ClockKernel.c.

uint16_t ClockReadPulse ( void  )

Get length of pulse length in 100ms.

The read is done with interrupts disabled.

Returns
the current value of clockPulse
See also
ClockSetPulse()

Definition at line 286 of file ClockKernel.c.

uint8_t ClockReadStartTimeHour ( void  )

Get the hour of the start time.

Returns
the current value of variable startTimeHour
See also
ClockSetStartTimeMinute()
ClockReadStartTimeMinute()
ClockSetStartTimeHour()

Definition at line 398 of file ClockKernel.c.

uint8_t ClockReadStartTimeMinute ( void  )

Get the minute of the start time.

Returns
the current value of variable startTimeMinute
See also
ClockSetStartTimeMinute()
ClockSetStartTimeHour()
ClockReadStartTimeHour()

Definition at line 374 of file ClockKernel.c.

uint8_t ClockReadStatus ( void  )

Read status of pulse generator.

The read is done with interrupts disabled.

Returns
the value of clockStatus
See also
CLOCK_STATUS_RUN
CLOCK_STATUS_TIME
ClockSetStatus()

Definition at line 214 of file ClockKernel.c.

uint8_t ClockReadTimeFactor ( void  )

Get time factor.

Returns
the current time factor
See also
ClockSetTimeFactor()

Definition at line 350 of file ClockKernel.c.

void ClockSetEndTimeHour ( uint8_t  ucHour)

Set the hour of the end time.

Parameters
ucHournew value of variable endTimeMinute
See also
ClockSetEndTimeMinute()
ClockReadEndTimeMinute()
ClockReadEndTimeHour()

Definition at line 434 of file ClockKernel.c.

void ClockSetEndTimeMinute ( uint8_t  ucMinute)

Set the minute of the end time.

Parameters
ucMinutenew value of variable endTimeMinute
See also
ClockReadEndTimeMinute()
ClockSetEndTimeHour()
ClockReadEndTimeHour()

Definition at line 410 of file ClockKernel.c.

void ClockSetPeriod ( uint16_t  uiPeriod)

Set length of model minute in 100ms.

The write is done with interrupts disabled.

Parameters
uiPeriodthe new value of clockPeriod
See also
ClockReadPeriod()

Definition at line 239 of file ClockKernel.c.

void ClockSetPulse ( uint16_t  uiPulse)

Set length of pulse length in 100ms.

The write is done with interrupts disabled.

Parameters
uiPulsethe new value for clockPulse
See also
ClockReadPulse()

Definition at line 270 of file ClockKernel.c.

void ClockSetStartTimeHour ( uint8_t  ucHour)

Set the hour of the start time.

Parameters
ucHournew value of variable startTimeHour
See also
ClockSetStartTimeMinute()
ClockReadStartTimeMinute()
ClockReadStartTimeHour()

Definition at line 386 of file ClockKernel.c.

void ClockSetStartTimeMinute ( uint8_t  ucMinute)

Set the minute of the start time.

Parameters
ucMinutenew value of variable startTimeMinute
See also
ClockReadStartTimeMinute()
ClockSetStartTimeHour()
ClockReadStartTimeHour()

Definition at line 362 of file ClockKernel.c.

void ClockSetStatus ( uint8_t  ucStatus)

Set status of pulse generator.

Bits used are:

  • 0: start/stop
  • 1: with/without increment of actual time
  • 2-7: unused, reserved for future use

The write is done with interrupts disabled.

Parameters
ucStatusthe new status
See also
CLOCK_STATUS_RUN
CLOCK_STATUS_TIME
ClockReadStatus()

Definition at line 187 of file ClockKernel.c.

void ClockSetTime ( fclock_t  newValue)

Set actual time.

Atomic access to variable clock.

Parameters
newValuethe new value for clock.
See also
ClockGetTime()

Definition at line 301 of file ClockKernel.c.

void ClockSetTimeFactor ( uint8_t  ucFactor)

Set time factor.

Parameters
ucFactorthe new time factor.
See also
ClockReadTimeFactor()

Definition at line 331 of file ClockKernel.c.

Here is the call graph for this function:

void SysTimerUserInterrupt ( void  )

This function is called by SysHWTimer every 1ms.

Be careful, not to overload this isr. Runs with global interrupts disabled.

Definition at line 135 of file ClockKernel.c.

void SysTimerUserInterrupt10 ( void  )

This function is called by SysHWTimer every 10ms.

Be careful, not to overload this isr. Runs with global interrupts disabled.

Definition at line 145 of file ClockKernel.c.

void SysTimerUserInterrupt100 ( void  )

This function is called by SysHWTimer every 100ms.

Be careful, not to overload this isr. Runs with global interrupts disabled.

Definition at line 155 of file ClockKernel.c.

Here is the call graph for this function:

Variable Documentation

volatile fclock_t ucClock = CLOCK_MIDNIGHT
static

actual model time

Definition at line 88 of file ClockKernel.c.

volatile bool ucClockOddPulse = 0
static

odd minute?!

Definition at line 85 of file ClockKernel.c.

volatile uint8_t ucClockStatus = 0
static

Clock status byte.

Definition at line 82 of file ClockKernel.c.

uint8_t ucClockTimeFactor
static

Definition at line 91 of file ClockKernel.c.

uint8_t ucEndTimeHour
static

Definition at line 95 of file ClockKernel.c.

uint8_t ucEndTimeMinute
static

Definition at line 94 of file ClockKernel.c.

uint8_t ucStartTimeHour
static

Definition at line 93 of file ClockKernel.c.

uint8_t ucStartTimeMinute
static

Definition at line 92 of file ClockKernel.c.

volatile uint16_t uiClockPeriod = 0
static

Value of minute in model time (60 in 1:1) at least 2*uiClockPulse.

Definition at line 76 of file ClockKernel.c.

volatile uint16_t uiClockPulse = 0
static

Length of pulse on the clock line.

Definition at line 79 of file ClockKernel.c.

volatile uint16_t uiClockTimer = 0
static

Gets decremented every 100 milliseconds by interrupt.

Definition at line 73 of file ClockKernel.c.