libww libww
WWitch compatibility library for the Wonderful toolchain
Loading...
Searching...
No Matches
timer.h
Go to the documentation of this file.
1#include <sys/types.h>
2
3#ifndef __LIBWW_SYS_TIMER_H__
4#define __LIBWW_SYS_TIMER_H__
5
6/* Begin auto-generated section */
7
8/* RTC fields */
9#define RTC_YEAR 0
10#define RTC_MONTH 1
11#define RTC_DATE 2
12#define RTC_DAY_OF_WEEK 3
13#define RTC_HOUR 4
14#define RTC_MIN 5
15#define RTC_SEC 6
16
17/* Timers */
18#define TIMER_HBLANK 0
19#define TIMER_VBLANK 1
20
21/* Timer reload modes */
22#define TIMER_ONESHOT 0
23#define TIMER_AUTOPRESET 1
24
25#define rtc_set_year(value) rtc_set_datetime(RTC_YEAR, value)
26#define rtc_set_month(value) rtc_set_datetime(RTC_MONTH, value)
27#define rtc_set_date(value) rtc_set_datetime(RTC_DATE, value)
28#define rtc_set_day_of_week(value) rtc_set_datetime(RTC_DAY_OF_WEEK, value)
29#define rtc_set_hour(value) rtc_set_datetime(RTC_HOUR, value)
30#define rtc_set_min(value) rtc_set_datetime(RTC_MIN, value)
31#define rtc_set_sec(value) rtc_set_datetime(RTC_SEC, value)
32
33#define rtc_get_year() rtc_get_datetime(RTC_YEAR)
34#define rtc_get_month() rtc_get_datetime(RTC_MONTH)
35#define rtc_get_date() rtc_get_datetime(RTC_DATE)
36#define rtc_get_day_of_week() rtc_get_datetime(RTC_DAY_OF_WEEK)
37#define rtc_get_hour() rtc_get_datetime(RTC_HOUR)
38#define rtc_get_min() rtc_get_datetime(RTC_MIN)
39#define rtc_get_sec() rtc_get_datetime(RTC_SEC)
40
41static inline void rtc_reset(void) {
42 uint16_t result;
43 __asm volatile (
44 "int $0x16"
45 : "=a" (result)
46 : "Rah" ((uint8_t) 0x00)
47 : "cc", "memory"
48 );
49}
50
51static inline void rtc_set_datetime(uint16_t field, uint16_t value) {
52 uint16_t result;
53 __asm volatile (
54 "int $0x16"
55 : "=a" (result)
56 : "b" (field), "c" (value), "Rah" ((uint8_t) 0x01)
57 : "cc", "memory"
58 );
59}
60
61static inline uint16_t rtc_get_datetime(uint16_t field) {
62 uint16_t result;
63 __asm volatile (
64 "int $0x16"
65 : "=a" (result)
66 : "b" (field), "Rah" ((uint8_t) 0x02)
67 : "cc", "memory"
68 );
69 return result;
70}
71
72void rtc_set_datetime_struct(const datetime_t __far* value);
73
75
76static inline void rtc_enable_alarm(uint8_t hour, uint8_t minute) {
77 uint16_t result;
78 __asm volatile (
79 "int $0x16"
80 : "=a" (result)
81 : "b" (((minute << 8) | hour)), "Rah" ((uint8_t) 0x05)
82 : "cc", "memory"
83 );
84}
85
86static inline void rtc_disable_alarm(void) {
87 uint16_t result;
88 __asm volatile (
89 "int $0x16"
90 : "=a" (result)
91 : "Rah" ((uint8_t) 0x06)
92 : "cc", "memory"
93 );
94}
95
96static inline void timer_enable(uint8_t type, uint16_t reload, uint16_t count) {
97 uint16_t result;
98 __asm volatile (
99 "int $0x16"
100 : "=a" (result)
101 : "a" ((uint16_t) (((0x07) << 8) | (type & 0xFF))), "b" (reload), "c" (count)
102 : "cc", "memory"
103 );
104}
105
106static inline void timer_disable(uint8_t type) {
107 uint16_t result;
108 __asm volatile (
109 "int $0x16"
110 : "=a" (result)
111 : "a" ((uint16_t) (((0x08) << 8) | (type & 0xFF)))
112 : "cc", "memory"
113 );
114}
115
116static inline void timer_get_count(uint8_t type) {
117 uint16_t result;
118 __asm volatile (
119 "int $0x16"
120 : "=a" (result)
121 : "a" ((uint16_t) (((0x09) << 8) | (type & 0xFF)))
122 : "cc", "memory"
123 );
124}
125
126/* End auto-generated section */
127
128
129#endif /* __LIBWW_SYS_TIMER_H__ */
void rtc_get_datetime_struct(datetime_t __far *value)
static void rtc_disable_alarm(void)
Definition timer.h:86
static void rtc_set_datetime(uint16_t field, uint16_t value)
Definition timer.h:51
static void rtc_reset(void)
Definition timer.h:41
static void timer_enable(uint8_t type, uint16_t reload, uint16_t count)
Definition timer.h:96
static uint16_t rtc_get_datetime(uint16_t field)
Definition timer.h:61
static void rtc_enable_alarm(uint8_t hour, uint8_t minute)
Definition timer.h:76
static void timer_get_count(uint8_t type)
Definition timer.h:116
static void timer_disable(uint8_t type)
Definition timer.h:106
void rtc_set_datetime_struct(const datetime_t __far *value)