ESP8266 ILI9341 display support code with printf sources, wire-frame viewer and custom fonts  1.0
ESP8266ILI9341DisplayProject
Functions | Variables
timer.c File Reference

timer functions More...

#include "user_config.h"
#include "printf/mathio.h"
#include "lib/time.h"
#include "lib/timer.h"

Go to the source code of this file.

Functions

MEMSPACE int set_timers (void(*handler)(void), int timer)
 Install a user timer task. More...
 
MEMSPACE int kill_timer (int timer)
 Delete "Kill" one user timer task. More...
 
MEMSPACE void delete_all_timers ()
 Clear ALL user timer tasks. More...
 
MEMSPACE void subtract_timespec (ts_t *a, ts_t *b)
 subtract a-= b timespec * structures. More...
 
MEMSPACE char * ts_to_str (ts_t *val)
 
MEMSPACE void display_ts (ts_t *val)
 timespec structure in seconds.nanoseconds. More...
 
MEMSPACE void clock_elapsed_begin ()
 Store current struct timespec in __clock_elapsed. More...
 
MEMSPACE void clock_elapsed_end (char *msg)
 Subtract and display time difference from clock_elapesed_begin(). More...
 
MEMSPACE void clock_clear ()
 clear time and timezone to 0. More...
 
MEMSPACE void disable_timers ()
 Disable all timer tasks. More...
 
MEMSPACE void enable_timers ()
 Enable timer tasks. More...
 
void execute_timers ()
 Execute all user timers at SYSTEM_HZ rate. Called by system task. More...
 
void clock_task (void)
 1000HZ timer task More...
 
MEMSPACE void init_timers ()
 Setup all timers tasksi and enable interrupts. More...
 
MEMSPACE int clock_getres (clockid_t clk_id, struct timespec *res)
 Read clock time resolution into struct timepec *ts - POSIX function. More...
 
MEMSPACE int clock_settime (clockid_t clk_id, const struct timespec *ts)
 Set system clock using seconds and nonoseconds - POSIX function. More...
 
MEMSPACE int clock_gettime (clockid_t clk_id, struct timespec *ts)
 Generic clock_gettime() function WITHOUT high resolution. More...
 

Variables

volatile ts_t __clock
 System Clock Time. More...
 
tz_t __tzone
 System Time Zone. More...
 
static int timers_enabled = 0
 
static int timers_configured = 0
 
TIMERS timer_irq [MAX_TIMER_CNT]
 array or user timers More...
 
static char _ts_to_str [32]
 timespec structure in seconds.nanoseconds in string. More...
 
static ts_t __clock_elapsed
 Used for elapsed time calculations. More...
 

Detailed Description

timer functions

Copyright © 2015 Mike Gore, GPL License
You are free to use this code under the terms of GPL
please retain a copy of this notice in any code you use it in.

This is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Definition in file timer.c.

Function Documentation

MEMSPACE void clock_clear ( void  )

clear time and timezone to 0.

See also
clock_settime().
settimezone().
Returns
void.

Definition at line 221 of file timer.c.

Referenced by init_timers().

MEMSPACE void clock_elapsed_begin ( void  )

Store current struct timespec in __clock_elapsed.

See also
clock_gettime() POSIX function.
Returns
void

Definition at line 184 of file timer.c.

MEMSPACE void clock_elapsed_end ( char *  msg)

Subtract and display time difference from clock_elapesed_begin().

  • Notes: Accuracy is a function of timer resolution, CPU overhead and background tasks.
Parameters
[in]msgUser message to proceed Time display.
Returns
void
See also
clock_gettime().
clock_elapesed_begin().

Definition at line 200 of file timer.c.

MEMSPACE int clock_getres ( clockid_t  clk_id,
struct timespec res 
)

Read clock time resolution into struct timepec *ts - POSIX function.

  • Note: We ignore clk_id
    Parameters
    [in]clk_idunused hardware clock index.
    [out]restimespec resolution result.
    Returns
    0 on success.
    -1 on error.

Definition at line 329 of file timer.c.

MEMSPACE int clock_gettime ( clockid_t  clk_id,
struct timespec ts 
)

Generic clock_gettime() function WITHOUT high resolution.

Read clock time into struct timepec *ts - POSIX function.

  • Note: We ignore clk_id, and include low level counter offsets when available.
Parameters
[in]clk_idunused hardware clock index.
[out]tstimespec result.
Returns
0 on success.
-1 on error.

Definition at line 377 of file timer.c.

Referenced by clock_elapsed_begin(), clock_elapsed_end(), display_clock(), gettimeofday(), and time().

MEMSPACE int clock_settime ( clockid_t  clk_id,
const struct timespec ts 
)

Set system clock using seconds and nonoseconds - POSIX function.

Parameters
[in]clk_idHardware timer index used when there are more then one.
  • Note: We ignore clk_id for now.
[in]tsstruct timespec input.
Returns
0.

Definition at line 345 of file timer.c.

Referenced by clock_clear(), clock_set(), initialize_clock(), setdate_r(), and settimeofday().

void clock_task ( void  )

1000HZ timer task

Returns
void

Definition at line 276 of file timer.c.

Referenced by init_timers().

MEMSPACE void delete_all_timers ( void  )

Clear ALL user timer tasks.

Returns
void

Definition at line 117 of file timer.c.

Referenced by init_timers().

MEMSPACE void disable_timers ( void  )

Disable all timer tasks.

Returns
void

Definition at line 235 of file timer.c.

MEMSPACE void display_ts ( ts_t val)

timespec structure in seconds.nanoseconds.

Parameters
[in]valtimespec struct we want to display.
Returns
void.

Definition at line 167 of file timer.c.

MEMSPACE void enable_timers ( void  )

Enable timer tasks.

Returns
void

Definition at line 248 of file timer.c.

Referenced by init_timers().

void execute_timers ( void  )

Execute all user timers at SYSTEM_HZ rate. Called by system task.

Returns
void

Definition at line 261 of file timer.c.

MEMSPACE void init_timers ( void  )

Setup all timers tasksi and enable interrupts.

See also
clock_task()
: timer_hal.c for hardware dependent interface
Returns
void

See time.c

Definition at line 293 of file timer.c.

Referenced by setup().

MEMSPACE int kill_timer ( int  timer)

Delete "Kill" one user timer task.

  • "kill" is a common Linux term for ending a process.
Parameters
[in]timeruser timer task index.
Returns
timer on success.
-1 on error.

Definition at line 100 of file timer.c.

MEMSPACE int set_timers ( void(*)(void)  handler,
int  timer 
)

Install a user timer task.

  • timer argument is unsused, reserved for timer source.
Parameters
[in]handler)function pointer to user task.
[in]timerreserved for systems with additional low level hardware timers.
Returns
timer on success.
-1 on error.

Definition at line 60 of file timer.c.

Referenced by init_timers(), mmc_install_timer(), and ms_init().

MEMSPACE void subtract_timespec ( ts_t a,
ts_t b 
)

subtract a-= b timespec * structures.

Parameters
[in]atimespec struct.
[in]btimespec struct.
Returns
void.

Definition at line 135 of file timer.c.

Referenced by clock_elapsed_end().

MEMSPACE char* ts_to_str ( ts_t val)

Definition at line 155 of file timer.c.

Referenced by clock_elapsed_end(), and display_ts().

Variable Documentation

volatile ts_t __clock

System Clock Time.

Definition at line 38 of file timer.c.

ts_t __clock_elapsed
static

Used for elapsed time calculations.

See also
clock_elapsed_begin().
clock_elapsed_end().

Definition at line 176 of file timer.c.

tz_t __tzone

System Time Zone.

Definition at line 41 of file timer.c.

char _ts_to_str[32]
static

timespec structure in seconds.nanoseconds in string.

Parameters
[in]timespec struct we wish to display.
[in]output string.
Returns
void.

Definition at line 153 of file timer.c.

TIMERS timer_irq[MAX_TIMER_CNT]

array or user timers

Definition at line 47 of file timer.c.

int timers_configured = 0
static

Definition at line 44 of file timer.c.

Referenced by disable_timers(), enable_timers(), and init_timers().

int timers_enabled = 0
static

Definition at line 43 of file timer.c.

Referenced by disable_timers(), enable_timers(), and init_timers().