libws libws
WSwan hardware library for the Wonderful toolchain
Loading...
Searching...
No Matches
timer.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2025 Adrian "asie" Siekierka
3 *
4 * This software is provided 'as-is', without any express or implied
5 * warranty. In no event will the authors be held liable for any damages
6 * arising from the use of this software.
7 *
8 * Permission is granted to anyone to use this software for any purpose,
9 * including commercial applications, and to alter it and redistribute it
10 * freely, subject to the following restrictions:
11 *
12 * 1. The origin of this software must not be misrepresented; you must not
13 * claim that you wrote the original software. If you use this software
14 * in a product, an acknowledgment in the product documentation would be
15 * appreciated but is not required.
16 *
17 * 2. Altered source versions must be plainly marked as such, and must not be
18 * misrepresented as being the original software.
19 *
20 * 3. This notice may not be removed or altered from any source distribution.
21 */
22
23#ifndef LIBWS_TIMER_H_
24#define LIBWS_TIMER_H_
25
29
30#ifndef __ASSEMBLER__
31#include <stdint.h>
32#endif
33#include <wonderful.h>
34#include "ports.h"
35#include "util.h"
36#include "system.h"
37#include "display.h"
38
43
51#define WS_TIMER_HBLANK_HZ_TO_TICKS(hz) ((uint16_t) WS_HZ_TO_CLOCK_DIVIDER((hz), 12000))
52
60#define WS_TIMER_VBLANK_HZ_TO_TICKS(hz) ((uint16_t) WS_HZ_TO_CLOCK_DIVIDER((hz), 12000 / (WS_DISPLAY_VTOTAL))))
61
62#ifndef __ASSEMBLER__
63
64static inline void ws_timer_hblank_disable(void) {
66}
67
68static inline void ws_timer_vblank_disable(void) {
70}
71
77static inline void ws_timer_hblank_start_once(uint16_t ticks) {
78 outportw(WS_TIMER_HBL_RELOAD_PORT, ticks);
80}
81
87static inline void ws_timer_vblank_start_once(uint16_t ticks) {
88 outportw(WS_TIMER_VBL_RELOAD_PORT, ticks);
90}
91
97static inline void ws_timer_hblank_start_repeat(uint16_t ticks) {
98 outportw(WS_TIMER_HBL_RELOAD_PORT, ticks);
100}
101
107static inline void ws_timer_vblank_start_repeat(uint16_t ticks) {
108 outportw(WS_TIMER_VBL_RELOAD_PORT, ticks);
110}
111
112#endif
113
115
116#endif /* LIBWS_TIMER_H_ */
#define WS_TIMER_CTRL_PORT
Definition ports.h:1062
#define WS_TIMER_VBL_RELOAD_PORT
Definition ports.h:1104
#define WS_TIMER_CTRL_HBL_REPEAT
Definition ports.h:1090
#define WS_TIMER_CTRL_HBL_MASK
Definition ports.h:1092
#define WS_TIMER_CTRL_VBL_REPEAT
Definition ports.h:1074
#define WS_TIMER_HBL_RELOAD_PORT
Definition ports.h:1099
#define WS_TIMER_CTRL_VBL_ONESHOT
Definition ports.h:1070
#define WS_TIMER_CTRL_VBL_MASK
Definition ports.h:1076
#define WS_TIMER_CTRL_HBL_ONESHOT
Definition ports.h:1086
static void ws_timer_vblank_start_once(uint16_t ticks)
Request a one-shot vertical blank timer.
Definition timer.h:87
static void ws_timer_hblank_start_repeat(uint16_t ticks)
Request a repeating horizontal blank timer.
Definition timer.h:97
static void ws_timer_hblank_disable(void)
Definition timer.h:64
static void ws_timer_hblank_start_once(uint16_t ticks)
Request a one-shot horizontal blank timer.
Definition timer.h:77
static void ws_timer_vblank_disable(void)
Definition timer.h:68
static void ws_timer_vblank_start_repeat(uint16_t ticks)
Request a repeating vertical blank timer.
Definition timer.h:107