SWILIB API (NSG)    
Loading...
Searching...
No Matches
System

Detailed Description

The system functions to control miscellaneous stuff on the phone.

Usage: #include <swilib.h> or #include <swilib/system.h>

Data Structures

struct  MUTEX
 Mutex object. More...
 

Macros

#define OS_TICK_PERIOD_US   4615
 Duration of one OS tick in microseconds.
 

Typedefs

typedef struct MUTEX MUTEX
 

Functions

int isnewSGold (void)
 Get the platform type.
 
void SUBPROC (void *callback,...)
 Run a callback in the background.
 
uint32_t GetSessionAge (void)
 Get phone uptime in the ticks (1 tick=4.615 ms).
 
static uint32_t TicksToMs (uint32_t ticks)
 Converts OS ticks to milliseconds.
 
static uint32_t TicksToSec (uint32_t ticks)
 Converts OS ticks to seconds.
 
static uint32_t TicksToUs (uint32_t ticks)
 Converts OS ticks to microseconds.
 
static uint32_t MsToTicks (uint32_t ms)
 Converts milliseconds to OS ticks.
 
static uint32_t SecToTicks (uint32_t sec)
 Converts seconds to OS ticks.
 
static uint32_t UsToTicks (uint32_t us)
 Converts microseconds to OS ticks.
 

Locking functions

void LockSched (void)
 Lock OS scheduler.
 
void UnlockSched (void)
 Unlock OS scheduler.
 
void MutexCreate (MUTEX *mtx)
 Init mutex object.
 
void MutexLock (MUTEX *mtx)
 Lock mutex.
 
void MutexLockEx (MUTEX *mtx, int flag)
 Lock mutex.
 
void MutexUnlock (MUTEX *mtx)
 Unlock mutex.
 
void MutexDestroy (MUTEX *mtx)
 Destroy mutex (free resources).
 

Elfloader functions

uint32_t GetLoaderVersion ()
 Get ELFLoader version.
 
void * AddrLibrary ()
 Address of the ElfPack function library.
 
void * LIB_TOP (void)
 Get a pointer to the loaded blib.
 
void * SHARED_TOP ()
 Get a pointer to the list of loaded shared libs.
 
char ** getBaseEnviron ()
 Get a pointer to a list of environment variables.
 
int elfclose (void *ex)
 Close ELF.
 
void kill_elf ()
 Kill current ELF (in background).
 
void kill_data (void *p, void(*func_p)(void *))
 Free data without returning to the current function.
 

Shared libs (internal API)

int _dlopen (const char *name)
 Load the dynamic shared object (.so).
 
void * _dlsym (int handle, const char *name)
 Get a pointer to the symbol from the previously loaded dynamic object.
 
int _dlclose (int handle)
 Close previously loaded dynamic object.
 
const char * _dlerror ()
 Get a string representation of the last error in _dlopen.
 
int dlclean_cache ()
 Call the garbage collector for the loaded dynamic objects.
 

CPU functions

void StartCpuUsageCount (void)
 Enable CPU usage monitor.
 
unsigned long long getCpuUsedTime_if_ena (void)
 Get CPU usage monitor value.
 
uint8_t GetCPUClock ()
 Get CPU freq.
 
uint8_t GetCPULoad ()
 Get CPU load.
 
void SetCpuClockLow (int unk)
 Set the CPU frequency to the minimum value.
 
void SetCpuClockHi (int flag)
 Set the CPU frequency to the maximum value.
 
void SetCpuClockTempHi (int unk)
 Set the CPU frequency to the maximum value.
 

Misc system functions

int * RamRandSeed ()
 Get PRNG seed value.
 
const char * RamLastStoreString ()
 Current pickoff error string.
 
const char * GSM_L1_Disable ()
 Disable GSM L1 layer (NetOff).
 

Stub functions

void loopback0 (void)
 Syscall, which is used by the phone OS, swi 0.
 
void loopback1 (void)
 Syscall, which is used by the phone OS, swi 1.
 
void loopback2 (void)
 Syscall, which is used by the phone OS, swi 2.
 
void loopback3 (void)
 Syscall, which is used by the phone OS, swi 3.
 
void loopback4 (void)
 Syscall, which is used by the phone OS, swi 4.
 
void loopback171 (void)
 Syscall, which is used by the phone OS, swi 171.
 

Data Structure Documentation

◆ MUTEX

struct MUTEX

Macro Definition Documentation

◆ OS_TICK_PERIOD_US

#define OS_TICK_PERIOD_US   4615

Duration of one OS tick in microseconds.

Defines the period of a single system tick. All conversions between ticks and real time are based on this value.

1 tick = 4.615 ms = 4615 µs

Definition at line 28 of file system.h.

Typedef Documentation

◆ MUTEX

typedef struct MUTEX MUTEX

Definition at line 17 of file system.h.

Function Documentation

◆ isnewSGold()

int isnewSGold ( void )

Get the platform type.

Returns
0 - SGold
1 - NewSGold
2 - NewSGold E71/EL71

◆ SUBPROC()

void SUBPROC ( void * callback,
... )

Run a callback in the background.

You can pass up to two additional (32 bit) parameters that are passed to the callback. Callbacks will be called in the RAP queue instead of the MMI.

Parameters
callbackpointer to the callback
Builtin on platforms:
ELKA, NSG, X75, SG
void test_func(int p1, int p2) {
// some code
}
SUBPROC(test_func, 1, 2);
void SUBPROC(void *callback,...)
Run a callback in the background.

◆ GetSessionAge()

uint32_t GetSessionAge ( void )

Get phone uptime in the ticks (1 tick=4.615 ms).

Returns
ticks

◆ TicksToMs()

static uint32_t TicksToMs ( uint32_t ticks)
inlinestatic

Converts OS ticks to milliseconds.

Parameters
ticksNumber of ticks (1 tick = 4.615 ms).
Returns
Time in milliseconds.

Definition at line 80 of file system.h.

◆ TicksToSec()

static uint32_t TicksToSec ( uint32_t ticks)
inlinestatic

Converts OS ticks to seconds.

Parameters
ticksNumber of ticks (1 tick = 4.615 ms).
Returns
Time in seconds.

Definition at line 89 of file system.h.

◆ TicksToUs()

static uint32_t TicksToUs ( uint32_t ticks)
inlinestatic

Converts OS ticks to microseconds.

Parameters
ticksNumber of ticks (1 tick = 4615 µs).
Returns
Time in microseconds.

Definition at line 98 of file system.h.

◆ MsToTicks()

static uint32_t MsToTicks ( uint32_t ms)
inlinestatic

Converts milliseconds to OS ticks.

Parameters
msTime in milliseconds.
Returns
Number of ticks (1 tick = 4.615 ms).

Definition at line 107 of file system.h.

◆ SecToTicks()

static uint32_t SecToTicks ( uint32_t sec)
inlinestatic

Converts seconds to OS ticks.

Parameters
secTime in seconds.
Returns
Number of ticks (1 tick = 4.615 ms).

Definition at line 116 of file system.h.

◆ UsToTicks()

static uint32_t UsToTicks ( uint32_t us)
inlinestatic

Converts microseconds to OS ticks.

Parameters
usTime in microseconds.
Returns
Number of ticks (1 tick = 4615 µs).

Definition at line 125 of file system.h.

◆ LockSched()

void LockSched ( void )

Lock OS scheduler.

◆ UnlockSched()

void UnlockSched ( void )

Unlock OS scheduler.

◆ MutexCreate()

void MutexCreate ( MUTEX * mtx)

Init mutex object.

Parameters
mtxpointer to the mutex object

◆ MutexLock()

void MutexLock ( MUTEX * mtx)

Lock mutex.

Parameters
mtxpointer to the mutex object

◆ MutexLockEx()

void MutexLockEx ( MUTEX * mtx,
int flag )

Lock mutex.

Parameters
mtxpointer to the mutex object
flagunknown

◆ MutexUnlock()

void MutexUnlock ( MUTEX * mtx)

Unlock mutex.

Parameters
mtxpointer to the mutex object

◆ MutexDestroy()

void MutexDestroy ( MUTEX * mtx)

Destroy mutex (free resources).

Parameters
mtxpointer to the mutex object

◆ GetLoaderVersion()

uint32_t GetLoaderVersion ( )

Get ELFLoader version.

Returns
0x030201 -> 3.2.1
Builtin on platforms:
ELKA, NSG, X75, SG

◆ AddrLibrary()

void * AddrLibrary ( )

Address of the ElfPack function library.

Returns
address in memory
Note
Defined by the ElfPack placement, not by firmware.
Pointer to the memory:
FLASH

◆ LIB_TOP()

void * LIB_TOP ( void )

Get a pointer to the loaded blib.

Returns
pointer
Builtin on platforms:
ELKA, NSG, X75, SG

◆ SHARED_TOP()

void * SHARED_TOP ( )

Get a pointer to the list of loaded shared libs.

Returns
pointer to the first element of the linked-list
Builtin on platforms:
ELKA, NSG, X75, SG
Note
Only for Elfloader 3.0+

◆ getBaseEnviron()

char ** getBaseEnviron ( )

Get a pointer to a list of environment variables.

Returns
pointer to the C-like array of strings
Builtin on platforms:
ELKA, NSG, X75, SG
Note
Only for Elfloader 3.0+

◆ elfclose()

int elfclose ( void * ex)

Close ELF.

Parameters
expointer to the opened ELF
Returns
0 or error
Builtin on platforms:
ELKA, NSG, X75, SG
Note
Only for Elfloader 3.0+

◆ kill_elf()

void kill_elf ( )

Kill current ELF (in background).

Note
Only for Elfloader 3.0+

◆ kill_data()

void kill_data ( void * p,
void(* func_p )(void *) )
extern

Free data without returning to the current function.

Note
Only for Elfloader 3.0+

◆ _dlopen()

int _dlopen ( const char * name)

Load the dynamic shared object (.so).

Parameters
namepath to the .so file or only name (libNAME.so)
Returns
0 or error
Builtin on platforms:
ELKA, NSG, X75, SG
Note
Only for Elfloader 3.0+

◆ _dlsym()

void * _dlsym ( int handle,
const char * name )

Get a pointer to the symbol from the previously loaded dynamic object.

Parameters
handledescriptor obtained from _dlopen
namename of the symbol
Returns
pointer to the symbol
Builtin on platforms:
ELKA, NSG, X75, SG
Note
Only for Elfloader 3.0+

◆ _dlclose()

int _dlclose ( int handle)

Close previously loaded dynamic object.

Parameters
handledescriptor obtained from _dlopen
Returns
0 or error
Builtin on platforms:
ELKA, NSG, X75, SG
Note
Only for Elfloader 3.0+

◆ _dlerror()

const char * _dlerror ( )

Get a string representation of the last error in _dlopen.

Returns
C-string
Builtin on platforms:
ELKA, NSG, X75, SG
Note
Only for Elfloader 3.0+

◆ dlclean_cache()

int dlclean_cache ( )

Call the garbage collector for the loaded dynamic objects.

Returns
0 or error
Builtin on platforms:
ELKA, NSG, X75, SG
Note
Only for Elfloader 3.0+

◆ StartCpuUsageCount()

void StartCpuUsageCount ( void )

Enable CPU usage monitor.

◆ getCpuUsedTime_if_ena()

unsigned long long getCpuUsedTime_if_ena ( void )

Get CPU usage monitor value.

The result depends on the model.

Returns
ELKA, S68: time since StartCpuUsageCount in microseconds, or 0 if the monitor is disabled
C81, S75, SL75: time of the last StartCpuUsageCount in microseconds, or 0 if the monitor is disabled
SG, X75: CPU load in percent (0-100, in the low 32 bits); does not check that the monitor is enabled
Note
On NSG and ELKA, nonzero means that the monitor is enabled.
Warning
On SG and X75, each call resets the CPU usage counters.

◆ GetCPUClock()

uint8_t GetCPUClock ( )

Get CPU freq.

Returns
freq in MHz

◆ GetCPULoad()

uint8_t GetCPULoad ( )

Get CPU load.

Returns
0-100

◆ SetCpuClockLow()

void SetCpuClockLow ( int unk)

Set the CPU frequency to the minimum value.

Parameters
unkunknown, set to 2

◆ SetCpuClockHi()

void SetCpuClockHi ( int flag)

Set the CPU frequency to the maximum value.

Parameters
flagunknown, set to 2

◆ SetCpuClockTempHi()

void SetCpuClockTempHi ( int unk)

Set the CPU frequency to the maximum value.

Parameters
unkunknown, set to 2

◆ RamRandSeed()

int * RamRandSeed ( )

Get PRNG seed value.

Returns
pointer to the seed.

◆ RamLastStoreString()

const char * RamLastStoreString ( )

Current pickoff error string.

Returns
C-string

◆ GSM_L1_Disable()

const char * GSM_L1_Disable ( )

Disable GSM L1 layer (NetOff).

Returns
C-string

◆ loopback0()

void loopback0 ( void )

Syscall, which is used by the phone OS, swi 0.

◆ loopback1()

void loopback1 ( void )

Syscall, which is used by the phone OS, swi 1.

◆ loopback2()

void loopback2 ( void )

Syscall, which is used by the phone OS, swi 2.

◆ loopback3()

void loopback3 ( void )

Syscall, which is used by the phone OS, swi 3.

◆ loopback4()

void loopback4 ( void )

Syscall, which is used by the phone OS, swi 4.

◆ loopback171()

void loopback171 ( void )

Syscall, which is used by the phone OS, swi 171.