HPGCC3 Documentation 3.0 R003
|
Header file for system functions. More...
#include <kos.h>
Go to the source code of this file.
Data Structures | |
struct | _atexit_entry |
struct | lldiv_t |
struct | timed_event |
Defines | |
#define | _LONGLONG_DEF |
#define | EXTERN extern |
#define | sys_bcd2bin(BCD) sys_bcd2bin_nibbles(BCD,2) |
Convert a BCD format BYTE (least significant 2 digits) to an integer value. | |
#define | _mmu_table_addr 0x01100000 |
Value of r1 register at the begining of execution. | |
#define | _code_base_addr 0x01220000 |
#define | _ram_base_addr 0x01101000 |
#define | _ram_size ((__mg->_mmu_table_entries-4)<<10) |
#define | MEM_REGS 0x07000000 |
#define | SD_REGS 0x07e00000 |
#define | IO_REGS 0x07a00000 |
#define | LCD_REGS 0x07300000 |
#define | CLK_REGS 0x07200000 |
#define | RTC_REGS 0x07B00000 |
#define | TMR_REGS 0x07600000 |
#define | INT_REGS 0x07100000 |
#define | CLK_1MHZ 0x16000000 |
#define | CLK_6MHZ 0x11000000 |
#define | CLK_12MHZ 0x10000000 |
#define | CLK_48MHZ 0x78023 |
#define | CLK_75MHZ 0x43012 |
#define | CLK_120MHZ 0x5c080 |
#define | CLK_152MHZ 0x44011 |
#define | CLK_192MHZ 0x58011 |
#define | NUM_EVENTS 5 |
#define | tmr_ms2ticks(a) tmr_addms((tmr_t)0,(a)) |
Macro to convert milliseconds to ticks. | |
#define | tmr_us2ticks(a) tmr_addus((tmr_t)0,(a)) |
Macro to convert milliseconds to ticks. | |
#define | MODE_MONO 0 |
#define | MODE_4GRAY 1 |
#define | MODE_16GRAY 2 |
#define | __EX_CONT 1 |
Options for throw_exception. | |
#define | __EX_EXIT 2 |
Options for throw_exception. | |
#define | __EX_WARM 4 |
Options for throw_exception. | |
#define | __EX_RESET 8 |
Options for throw_exception. | |
Typedefs | |
typedef unsigned long long | ULONGLONG |
typedef long long | LONGLONG |
typedef void(* | __interrupt__ )(void) |
Type definition for interrupt handler functions. | |
typedef void(* | ATEXITFUNC )() |
typedef struct _atexit_entry | ATEXIT_ENTRY |
typedef int | HEVENT |
Handle to refer to a timed event. | |
typedef ULONGLONG | tmr_t |
Type to use with all timer routines: ticks and frequencies are 64-bit. | |
Functions | |
int | atexit (ATEXITFUNC f) |
unsigned int | sys_bcd2bin_nibbles (unsigned int BCD, int nibbles) |
Convert the least significant n (=nibbles, max. 8) digits of a BCD formatted number to it's integer value. | |
lldiv_t | lldiv (LONGLONG, LONGLONG) |
unsigned | divlu2 (unsigned num_h, unsigned num_l, unsigned den, unsigned *rem) |
Unsigned 64/32 bit division. | |
ULONGLONG | udiv64 (ULONGLONG nom, unsigned den, unsigned *rem) |
Unsigned 64/32 bit division with 64 bit quotient. | |
LONGLONG | sdiv64 (LONGLONG nom, int den, int *rem) |
Signed 64/32 bit division with 64 bit quotient. | |
void | cpu_intoff () |
void | cpu_inton () |
void | cpu_intsave (unsigned int *buffer) |
Save interrupt controller state to a buffer (11 words) | |
void | cpu_intrestore (unsigned int *buffer) |
Restore interrupt controller state from a buffer (11 words) | |
void | cpu_clksave (unsigned int *buf) |
Save CPU clock state to a buffer (8-words) | |
void | cpu_clkrestore (unsigned int *buf) |
Restore CPU clock from a buffer (8-words) | |
int | cpu_setspeed (int hz) |
Set CPU speed in Hz, change to closest supported speed and return new frequency. | |
int | cpu_getspeed () |
Get CPU speed in Hz. | |
int | __cpu_setspeed (int PLLCON) |
Low-level cpu speed control. | |
int | __cpu_getFCLK () |
Get CPU clock speed in Hz. Same as cpu_getspeed. | |
int | __cpu_getHCLK () |
Get peripherals clock (HCLK) speed in Hz. | |
int | __cpu_getPCLK () |
Get peripherals clock (PCLK) speed in Hz. | |
void | cpu_flush_cache (int *ptr, int size) |
Flush write-back caches on the specified block of memory. | |
void | tmr_save (unsigned int *tmrbuffer) |
Save all timers state to a buffer (13-word) | |
void | tmr_restore (unsigned int *tmrbuffer) |
Restore saved timers state from buffer. | |
void | tmr_setup () |
Setup system timers and event scheduler - automatically called at startup. | |
tmr_t | tmr_getsysfreq () |
Get the frequency of the system timer in ticks per second, normally 100 KHz or 125KHz. | |
tmr_t | tmr_ticks () |
Get system timer count in ticks since program started. | |
void | tmr_delayms (int milliseconds) |
Do not return until the specified time has passed. | |
void | tmr_delayus (int microseconds) |
Do not return until the specified time has passed (in microseconds). Accuracy is +/- 10 microseconds. | |
int | tmr_ticks2ms (tmr_t before, tmr_t after) |
Calculate elapsed time in milliseconds between before and after (both given in ticks) | |
int | tmr_ticks2us (tmr_t before, tmr_t after) |
Calculate elapsed time in microseconds between before and after (both given in ticks) | |
tmr_t | tmr_addms (tmr_t time, int ms) |
Add/subtract an interval in milliseconds to the given time in ticks. | |
tmr_t | tmr_addus (tmr_t time, int us) |
Add/subtract an interval in microseconds to the given time in ticks. | |
void | tmr_waituntil (tmr_t time) |
Wait until the system timer reaches the given time in ticks. | |
HEVENT | tmr_eventcreate (__interrupt__ handler, unsigned int ms, BOOL autorepeat) |
Create a timed event. Create a new timed event, specifying a callback function that will be called after the given time has passed. The autorepeat feature allows the event to be automatically rescheduled for another interval of time. Autorepeated events need to be manually removed by tmr_eventkill. One-shot events will remove themselves after completion (no need to explicitly call tmr_eventkill). | |
void | tmr_eventkill (HEVENT event) |
Kill a timed event. Stops an autoreloading event. | |
int | sys_RTC_seconds () |
Get date in seconds from RTC. | |
void | lcd_sync () |
Wait for LCD synchro. | |
void | __lcd_fix () |
Fix LCD clock rate at any CPU speed. | |
void | lcd_save (unsigned int *buffer) |
Save LCD controller state (buffer size must be 17 words min.) | |
void | lcd_restore (unsigned int *buffer) |
Restore LCD controller state from buffer (saved by lcd_save) | |
int | lcd_setmode (int mode, int *physicalbuffer) |
int | lcd_getheight () |
void | lcd_off () |
Turn screen off. | |
void | lcd_on () |
Turn screen on. | |
void | lcd_setcontrast (int level) |
Set the contrast level. | |
EXTERN int | sys_map_v2p (unsigned int vaddr) |
Convert a virtual address to its physical bus address. | |
EXTERN int | sys_map_p2v (unsigned int paddr) |
Convert a physical bus address to its virtual address. | |
int | sys_mem_classify (int addr) |
Classify a memory address 0=System; 1=Port1; 2=Main. | |
void * | sys_phys_malloc (size_t) |
EXTERN void | sys_playTone (unsigned int tone, unsigned int duration) |
EXTERN void | sys_waitTicks (unsigned int time) |
EXTERN void | setDisplayPlane (unsigned char *plane) |
EXTERN void | sys_playTone2 (unsigned int time, unsigned int duration) |
int | sys_isRTCTick () |
Returns '1' if an RTC Interrupt Tick has occured since it was last called. | |
unsigned char | sys_setRTCTickPeriod (unsigned char n) |
Ajdusts the rate of the RTC Tick. Remember to restore the default when done! | |
void | sys_waitRTCTicks (int count) |
Waits for 'count' RTC Ticks to elapse. | |
int | sys_delta_seconds (int t_start, int t_end) |
Compute the time span (in seconds) between t_start and t_end. Account for possible wrap around at midnight. | |
void | sys_error (const char *msg, int code) |
Output msg to screen, set errno=code and exit if code < 0. | |
void * | sys_chkptr (void *p) |
Check pointer after malloc'ing and exit via sys_error() if NULL. | |
void | throw_exception (char *message, unsigned int options) |
Throw a user exception Cause a user exception to be thrown. It displays the requested message and offer the user several options to treat the exception. | |
void | throw_dbgexception (char *message, unsigned int options) |
void | __irq_addhook (int service_number, __interrupt__ serv_routine) |
Install an IRQ handler Set a routine to service interrupt requests from a specific device. It does not change the state of the interrupt controller, so the user needs to manually unmask the interrupt and configure the rest of the hardware to generate the proper IRQ request. | |
void | __irq_releasehook (int service_number) |
Uninstall an IRQ handler Removes a service routine that handles interrupt requests from a specific device. It does not change the state of the interrupt controller, so the user needs to manually mask the interrupt and configure the rest of the hardware to stop generating IRQ requests. If an IRQ is generated after this routine is called, it will be serviced by a do-nothing routine. |
Header file for system functions.
Definition in file sys.h.
#define _mmu_table_addr 0x01100000 |
Value of r1 register at the begining of execution.
See post of Robert Hildinger: "The R1 register contains the base address for all the ARM globals, which can be used to access all of the Saturn registers. Altering this register will not affect the calling code. The LR register contains the return address to get back into Saturn emulation."
API INFORMATION
---------------
So far there is no real API information available, although experimentally I've been able to determine the following offsets from the global base register for accessing the emulated Saturn CPU registers:
Base (R1) offset Description
---------------------------------------
0x90C Saturn register A (low order 8 nibbles)
0x910 Saturn register A (high order 8 nibbles)
0x914 Saturn register B (low order 8 nibbles)
0x918 Saturn register B (high order 8 nibbles)
0x91C Saturn register C (low order 8 nibbles)
0x920 Saturn register C (high order 8 nibbles)
0x924 Saturn register D (low order 8 nibbles)
0x928 Saturn register D (high order 8 nibbles)
0x92C Saturn register R0 (low order 8 nibbles)
0x930 Saturn register R0 (high order 8 nibbles)
0x934 Saturn register R1 (low order 8 nibbles)
0x938 Saturn register R1 (high order 8 nibbles)
0x93C Saturn register R2 (low order 8 nibbles)
0x940 Saturn register R2 (high order 8 nibbles)
0x944 Saturn register R3 (low order 8 nibbles)
0x948 Saturn register R3 (high order 8 nibbles)
0x94C Saturn register R4 (low order 8 nibbles)
0x950 Saturn register R4 (high order 8 nibbles)
0x954 Saturn register d0
0x958 Saturn register d1
0x95C Saturn register P
0x968 Saturn register ST
0x96C Saturn register HST
0x970 Saturn CARRY flag
0x974 Saturn DECIMAL_MODE flag
#define sys_bcd2bin | ( | BCD | ) | sys_bcd2bin_nibbles(BCD,2) |
#define tmr_ms2ticks | ( | a | ) | tmr_addms((tmr_t)0,(a)) |
#define tmr_us2ticks | ( | a | ) | tmr_addus((tmr_t)0,(a)) |
typedef void(* __interrupt__)(void) |
typedef struct _atexit_entry ATEXIT_ENTRY |
typedef void(* ATEXITFUNC)() |
int __cpu_getFCLK | ( | ) |
Get CPU clock speed in Hz. Same as cpu_getspeed.
int __cpu_getHCLK | ( | ) |
Get peripherals clock (HCLK) speed in Hz.
int __cpu_getPCLK | ( | ) |
Get peripherals clock (PCLK) speed in Hz.
int __cpu_setspeed | ( | int | PLLCON | ) |
Low-level cpu speed control.
void __irq_addhook | ( | int | service_number, |
__interrupt__ | serv_routine | ||
) |
Install an IRQ handler Set a routine to service interrupt requests from a specific device. It does not change the state of the interrupt controller, so the user needs to manually unmask the interrupt and configure the rest of the hardware to generate the proper IRQ request.
service_number | Identifies the device that is causing the interrupt. It's a number from 0 to 31 according to the list below (see Samsung S3C2410X manual). |
serv_routine | Address of a service routine. The service routine has no special requirements, other than returning as fast as possible to allow other IRQ's to be processed. |
void __irq_releasehook | ( | int | service_number | ) |
Uninstall an IRQ handler Removes a service routine that handles interrupt requests from a specific device. It does not change the state of the interrupt controller, so the user needs to manually mask the interrupt and configure the rest of the hardware to stop generating IRQ requests. If an IRQ is generated after this routine is called, it will be serviced by a do-nothing routine.
service_number | Identifies the device that is causing the interrupt. It's a number from 0 to 31 according to the list below (see Samsung S3C2410X manual). |
void __lcd_fix | ( | ) |
Fix LCD clock rate at any CPU speed.
int atexit | ( | ATEXITFUNC | f | ) |
void cpu_clkrestore | ( | unsigned int * | buf | ) |
Restore CPU clock from a buffer (8-words)
void cpu_clksave | ( | unsigned int * | buf | ) |
Save CPU clock state to a buffer (8-words)
void cpu_flush_cache | ( | int * | ptr, |
int | size | ||
) |
Flush write-back caches on the specified block of memory.
int cpu_getspeed | ( | ) |
Get CPU speed in Hz.
void cpu_intoff | ( | ) |
void cpu_inton | ( | ) |
void cpu_intrestore | ( | unsigned int * | buffer | ) |
Restore interrupt controller state from a buffer (11 words)
void cpu_intsave | ( | unsigned int * | buffer | ) |
Save interrupt controller state to a buffer (11 words)
int cpu_setspeed | ( | int | hz | ) |
Set CPU speed in Hz, change to closest supported speed and return new frequency.
unsigned divlu2 | ( | unsigned | num_h, |
unsigned | num_l, | ||
unsigned | den, | ||
unsigned * | rem | ||
) |
Unsigned 64/32 bit division.
int lcd_getheight | ( | ) |
void lcd_off | ( | ) |
Turn screen off.
void lcd_on | ( | ) |
Turn screen on.
void lcd_restore | ( | unsigned int * | buffer | ) |
Restore LCD controller state from buffer (saved by lcd_save)
void lcd_save | ( | unsigned int * | buffer | ) |
Save LCD controller state (buffer size must be 17 words min.)
void lcd_setcontrast | ( | int | level | ) |
Set the contrast level.
level | Number from 0 to 15, being 15=darkest, 0=lightest |
int lcd_setmode | ( | int | mode, |
int * | physicalbuffer | ||
) |
void lcd_sync | ( | ) |
Wait for LCD synchro.
Signed 64/32 bit division with 64 bit quotient.
EXTERN void setDisplayPlane | ( | unsigned char * | plane | ) |
unsigned int sys_bcd2bin_nibbles | ( | unsigned int | BCD, |
int | nibbles | ||
) |
Convert the least significant n (=nibbles, max. 8) digits of a BCD formatted number to it's integer value.
void sys_chkptr | ( | void * | p | ) |
Check pointer after malloc'ing and exit via sys_error() if NULL.
p | the pointer to be checked |
int sys_delta_seconds | ( | int | t_start, |
int | t_end | ||
) |
Compute the time span (in seconds) between t_start and t_end. Account for possible wrap around at midnight.
t_start | Start time |
t_end | End time |
void sys_error | ( | const char * | msg, |
int | code | ||
) |
Output msg to screen, set errno=code and exit if code < 0.
msg | The message text or NULL for none |
code | The error code, forwarded to exit() |
int sys_isRTCTick | ( | ) |
Returns '1' if an RTC Interrupt Tick has occured since it was last called.
EXTERN int sys_map_p2v | ( | unsigned int | paddr | ) |
Convert a physical bus address to its virtual address.
EXTERN int sys_map_v2p | ( | unsigned int | vaddr | ) |
Convert a virtual address to its physical bus address.
int sys_mem_classify | ( | int | addr | ) |
Classify a memory address 0=System; 1=Port1; 2=Main.
void* sys_phys_malloc | ( | size_t | ) |
EXTERN void sys_playTone | ( | unsigned int | tone, |
unsigned int | duration | ||
) |
EXTERN void sys_playTone2 | ( | unsigned int | time, |
unsigned int | duration | ||
) |
int sys_RTC_seconds | ( | ) |
Get date in seconds from RTC.
The total number of seconds 3600*H+60*M+S.
unsigned char sys_setRTCTickPeriod | ( | unsigned char | n | ) |
Ajdusts the rate of the RTC Tick. Remember to restore the default when done!
void sys_waitRTCTicks | ( | int | count | ) |
Waits for 'count' RTC Ticks to elapse.
EXTERN void sys_waitTicks | ( | unsigned int | time | ) |
void throw_dbgexception | ( | char * | message, |
unsigned int | options | ||
) |
void throw_exception | ( | char * | message, |
unsigned int | options | ||
) |
Throw a user exception Cause a user exception to be thrown. It displays the requested message and offer the user several options to treat the exception.
message | The string that will be displayed. |
options | One or more of the following constants:
|
Add/subtract an interval in milliseconds to the given time in ticks.
Add/subtract an interval in microseconds to the given time in ticks.
void tmr_delayms | ( | int | milliseconds | ) |
Do not return until the specified time has passed.
void tmr_delayus | ( | int | microseconds | ) |
Do not return until the specified time has passed (in microseconds). Accuracy is +/- 10 microseconds.
HEVENT tmr_eventcreate | ( | __interrupt__ | handler, |
unsigned int | ms, | ||
BOOL | autorepeat | ||
) |
Create a timed event. Create a new timed event, specifying a callback function that will be called after the given time has passed. The autorepeat feature allows the event to be automatically rescheduled for another interval of time. Autorepeated events need to be manually removed by tmr_eventkill. One-shot events will remove themselves after completion (no need to explicitly call tmr_eventkill).
handler | The function that will be called back on every interval |
ms | Time interval in milliseconds after which the handler will be called |
autorepeat | If TRUE, the event will be repeated every 'ms' milliseconds, if FALSE the event will be executed only once after 'ms' milliseconds have passed since the event was created. |
void tmr_eventkill | ( | HEVENT | event | ) |
Kill a timed event. Stops an autoreloading event.
event | The event handler obtained from tmr_eventcreate |
tmr_t tmr_getsysfreq | ( | ) |
Get the frequency of the system timer in ticks per second, normally 100 KHz or 125KHz.
void tmr_restore | ( | unsigned int * | tmrbuffer | ) |
Restore saved timers state from buffer.
void tmr_save | ( | unsigned int * | tmrbuffer | ) |
Save all timers state to a buffer (13-word)
void tmr_setup | ( | ) |
Setup system timers and event scheduler - automatically called at startup.
tmr_t tmr_ticks | ( | ) |
Get system timer count in ticks since program started.
Calculate elapsed time in milliseconds between before and after (both given in ticks)
Calculate elapsed time in microseconds between before and after (both given in ticks)
void tmr_waituntil | ( | tmr_t | time | ) |
Wait until the system timer reaches the given time in ticks.