libctru  v1.6.0
Data Structures | Macros | Enumerations | Functions
os.h File Reference

OS related stuff. More...

#include "svc.h"

Go to the source code of this file.

Data Structures

struct  TickCounter
 Tick counter. More...
 
struct  OS_VersionBin
 OS_VersionBin. Format of the system version: "<major>.<minor>.<build>-<nupver><region>". More...
 

Macros

#define SYSCLOCK_SOC   (16756991)
 
#define SYSCLOCK_ARM9   (SYSCLOCK_SOC * 8)
 
#define SYSCLOCK_ARM11   (SYSCLOCK_ARM9 * 2)
 
#define SYSCLOCK_ARM11_NEW   (SYSCLOCK_ARM11 * 3)
 
#define CPU_TICKS_PER_MSEC   (SYSCLOCK_ARM11 / 1000.0)
 
#define CPU_TICKS_PER_USEC   (SYSCLOCK_ARM11 / 1000000.0)
 
#define SYSTEM_VERSION(major, minor, revision)   (((major)<<24)|((minor)<<16)|((revision)<<8))
 Packs a system version from its components.
 
#define GET_VERSION_MAJOR(version)   ((version) >>24)
 Retrieves the major version from a packed system version.
 
#define GET_VERSION_MINOR(version)   (((version)>>16)&0xFF)
 Retrieves the minor version from a packed system version.
 
#define GET_VERSION_REVISION(version)   (((version)>> 8)&0xFF)
 Retrieves the revision version from a packed system version.
 

Enumerations

enum  MemRegion {
  MEMREGION_ALL = 0,
  MEMREGION_APPLICATION = 1,
  MEMREGION_SYSTEM = 2,
  MEMREGION_BASE = 3
}
 Memory regions. More...
 

Functions

u32 osConvertVirtToPhys (const void *vaddr)
 Converts an address from virtual (process) memory to physical memory. More...
 
void * osConvertOldLINEARMemToNew (const void *vaddr)
 Converts 0x14* vmem to 0x30*. More...
 
const char * osStrError (u32 error)
 Retrieves basic information about a service error. More...
 
static u32 osGetFirmVersion (void)
 Gets the system's FIRM version. More...
 
static u32 osGetKernelVersion (void)
 Gets the system's kernel version. More...
 
static u32 osGetMemRegionSize (MemRegion region)
 Gets the size of the specified memory region. More...
 
s64 osGetMemRegionUsed (MemRegion region)
 Gets the number of used bytes within the specified memory region. More...
 
static s64 osGetMemRegionFree (MemRegion region)
 Gets the number of free bytes within the specified memory region. More...
 
u64 osGetTime (void)
 Gets the current time. More...
 
static void osTickCounterStart (TickCounter *cnt)
 Starts a tick counter. More...
 
static void osTickCounterUpdate (TickCounter *cnt)
 Updates the elapsed time in a tick counter. More...
 
double osTickCounterRead (const TickCounter *cnt)
 Reads the elapsed time in a tick counter. More...
 
static u8 osGetWifiStrength (void)
 Gets the current Wifi signal strength. More...
 
static float osGet3DSliderState (void)
 Gets the state of the 3D slider. More...
 
void osSetSpeedupEnable (bool enable)
 Configures the New 3DS speedup. More...
 
Result osGetSystemVersionData (OS_VersionBin *nver_versionbin, OS_VersionBin *cver_versionbin)
 Gets the NAND system-version stored in NVer/CVer. More...
 
Result osGetSystemVersionDataString (OS_VersionBin *nver_versionbin, OS_VersionBin *cver_versionbin, char *sysverstr, u32 sysverstr_maxsize)
 This is a wrapper for osGetSystemVersionData. More...
 

Detailed Description

OS related stuff.

Enumeration Type Documentation

◆ MemRegion

enum MemRegion

Memory regions.

Enumerator
MEMREGION_ALL 

All regions.

MEMREGION_APPLICATION 

APPLICATION memory.

MEMREGION_SYSTEM 

SYSTEM memory.

MEMREGION_BASE 

BASE memory.

Function Documentation

◆ osConvertOldLINEARMemToNew()

void* osConvertOldLINEARMemToNew ( const void *  vaddr)

Converts 0x14* vmem to 0x30*.

Parameters
vaddrInput virtual address.
Returns
The corresponding address in the 0x30* range, the input address if it's already within the new vmem, or 0 if it's outside of both ranges.

◆ osConvertVirtToPhys()

u32 osConvertVirtToPhys ( const void *  vaddr)

Converts an address from virtual (process) memory to physical memory.

Parameters
vaddrInput virtual address.
Returns
The corresponding physical address. It is sometimes required by services or when using the GPU command buffer.
Examples
mvd/source/main.c.

◆ osGet3DSliderState()

static float osGet3DSliderState ( void  )
inlinestatic

◆ osGetFirmVersion()

static u32 osGetFirmVersion ( void  )
inlinestatic

Gets the system's FIRM version.

Returns
The system's FIRM version.

This can be used to compare system versions easily with SYSTEM_VERSION.

◆ osGetKernelVersion()

static u32 osGetKernelVersion ( void  )
inlinestatic

Gets the system's kernel version.

Returns
The system's kernel version.

This can be used to compare system versions easily with SYSTEM_VERSION.

if(osGetKernelVersion() > SYSTEM_VERSION(2,46,0)) printf("You are running 9.0 or higher\n");

◆ osGetMemRegionFree()

static s64 osGetMemRegionFree ( MemRegion  region)
inlinestatic

Gets the number of free bytes within the specified memory region.

Parameters
regionMemory region to check.
Returns
The number of free bytes of memory.

◆ osGetMemRegionSize()

static u32 osGetMemRegionSize ( MemRegion  region)
inlinestatic

Gets the size of the specified memory region.

Parameters
regionMemory region to check.
Returns
The size of the memory region, in bytes.

◆ osGetMemRegionUsed()

s64 osGetMemRegionUsed ( MemRegion  region)

Gets the number of used bytes within the specified memory region.

Parameters
regionMemory region to check.
Returns
The number of used bytes of memory.

◆ osGetSystemVersionData()

Result osGetSystemVersionData ( OS_VersionBin nver_versionbin,
OS_VersionBin cver_versionbin 
)

Gets the NAND system-version stored in NVer/CVer.

Parameters
nver_versionbinOutput OS_VersionBin structure for the data read from NVer.
cver_versionbinOutput OS_VersionBin structure for the data read from CVer.
Returns
The result-code. This value can be positive if opening "romfs:/version.bin" fails with stdio, since errno would be returned in that case. In some cases the error can be special negative values as well.

◆ osGetSystemVersionDataString()

Result osGetSystemVersionDataString ( OS_VersionBin nver_versionbin,
OS_VersionBin cver_versionbin,
char *  sysverstr,
u32  sysverstr_maxsize 
)

This is a wrapper for osGetSystemVersionData.

Parameters
nver_versionbinOptional output OS_VersionBin structure for the data read from NVer, can be NULL.
cver_versionbinOptional output OS_VersionBin structure for the data read from CVer, can be NULL.
sysverstrOutput string where the printed system-version will be written, in the same format displayed by the System Settings title.
sysverstr_maxsizeMax size of the above string buffer, including NULL-terminator.
Returns
See osGetSystemVersionData.

◆ osGetTime()

u64 osGetTime ( void  )

Gets the current time.

Returns
The number of milliseconds since 1st Jan 1900 00:00.

◆ osGetWifiStrength()

static u8 osGetWifiStrength ( void  )
inlinestatic

Gets the current Wifi signal strength.

Returns
The current Wifi signal strength.

Valid values are 0-3:

  • 0 means the singal strength is terrible or the 3DS is disconnected from all networks.
  • 1 means the signal strength is bad.
  • 2 means the signal strength is decent.
  • 3 means the signal strength is good.

Values outside the range of 0-3 should never be returned.

These values correspond with the number of wifi bars displayed by Home Menu.

◆ osSetSpeedupEnable()

void osSetSpeedupEnable ( bool  enable)

Configures the New 3DS speedup.

Parameters
enableSpecifies whether to enable or disable the speedup.

◆ osStrError()

const char* osStrError ( u32  error)

Retrieves basic information about a service error.

Parameters
errorError to retrieve information about.
Returns
A string containing a summary of an error.

This can be used to get some details about an error returned by a service call.

◆ osTickCounterRead()

double osTickCounterRead ( const TickCounter cnt)

Reads the elapsed time in a tick counter.

Parameters
cntThe tick counter.
Returns
The number of milliseconds elapsed.

◆ osTickCounterStart()

static void osTickCounterStart ( TickCounter cnt)
inlinestatic

Starts a tick counter.

Parameters
cntThe tick counter.

◆ osTickCounterUpdate()

static void osTickCounterUpdate ( TickCounter cnt)
inlinestatic

Updates the elapsed time in a tick counter.

Parameters
cntThe tick counter.