ps2sdk  1.1
A collection of Open Source libraries used for developing applications on Sony's PlayStation 2® (PS2).
poweroff.c File Reference
#include "libpwroff.h"
#include <errno.h>
#include <stdio.h>
#include <tamtypes.h>
#include <kernel.h>
#include <string.h>
#include <sifrpc.h>
#include <pwroff_rpc.h>
+ Include dependency graph for poweroff.c:

Go to the source code of this file.

Functions

static void * PowerOff_ee_rpc_handler (int fnum, void *buffer, int len)
 
static void PowerOffThread (void *dat)
 
int poweroffInit (void)
 
void poweroffSetCallback (poweroff_callback cb, void *arg)
 
void poweroffShutdown (void)
 
void poweroffChangeThreadPriority (int priority)
 

Variables

void * _gp
 
static poweroff_callback poweroff_cb = NULL
 
static void * poweroff_data = NULL
 
static u8 poffThreadStack [512 *16]
 
int _iop_reboot_count
 
static SifRpcClientData_t cd0
 
static struct t_SifRpcDataQueue cb_queue
 
static struct t_SifRpcServerData cb_srv
 
static int powerOffThreadId = -1
 

Function Documentation

◆ PowerOff_ee_rpc_handler()

static void* PowerOff_ee_rpc_handler ( int  fnum,
void *  buffer,
int  len 
)
static

Definition at line 34 of file poweroff.c.

35 {
36  switch(fnum){
37  case POFF_RPC_BUTTON:
38  printf("EE: power button pressed\n");
39 
40  if (poweroff_cb)
42  break;
43  }
44 
45  return buffer;
46 }
#define POFF_RPC_BUTTON
Definition: pwroff_rpc.h:23
u8 buffer[128]
Definition: rpc_client.c:19
static poweroff_callback poweroff_cb
Definition: poweroff.c:23
static void * poweroff_data
Definition: poweroff.c:24

References buffer, POFF_RPC_BUTTON, poweroff_cb, and poweroff_data.

Referenced by PowerOffThread().

◆ poweroffChangeThreadPriority()

void poweroffChangeThreadPriority ( int  priority)

Definition at line 110 of file poweroff.c.

111 {
113 }
s32 ChangeThreadPriority(s32 thread_id, s32 priority)
static int powerOffThreadId
Definition: poweroff.c:32

References ChangeThreadPriority(), and powerOffThreadId.

◆ poweroffInit()

int poweroffInit ( void  )

Initializes the poweroff library. A service thread with a default priority of 0x70 will be created.

Definition at line 57 of file poweroff.c.

58 {
59  ee_thread_t thread;
60  int res;
61  static int _init_count = -1;
62 
63  if(_init_count == _iop_reboot_count)
64  return 0;
65  _init_count = _iop_reboot_count;
66 
67  while(((res = SifBindRpc(&cd0, PWROFF_IRX, 0)) < 0) || (cd0.server == NULL))
68  nopdelay();
69 
70  // Terminate and delete any previously created threads
71  if (powerOffThreadId >= 0) {
76  powerOffThreadId = -1;
77  }
78 
80  thread.stack_size = sizeof(poffThreadStack);
81  thread.gp_reg = &_gp;
82  thread.func = PowerOffThread;
83  thread.stack = (void *)poffThreadStack;
84  thread.option = 0;
85  thread.attr = 0;
86  powerOffThreadId = CreateThread(&thread);
88 
89  int autoShutdown[4] = {0};
90  SifCallRpc(&cd0, PWROFF_ENABLE_AUTO_SHUTOFF, 0, NULL, 0, autoShutdown, sizeof(autoShutdown), NULL, NULL);
91 
92  return res;
93 }
static void nopdelay(void)
Definition: kernel.h:141
s32 CreateThread(ee_thread_t *thread)
s32 StartThread(s32 thread_id, void *args)
s32 TerminateThread(s32 thread_id)
s32 DeleteThread(s32 thread_id)
#define POWEROFF_THREAD_PRIORITY
Definition: libpwroff.h:19
#define PWROFF_IRX
Definition: pwroff_rpc.h:19
#define PWROFF_ENABLE_AUTO_SHUTOFF
Definition: pwroff_rpc.h:21
SifRpcServerData_t * SifRemoveRpc(SifRpcServerData_t *sd, SifRpcDataQueue_t *queue)
SifRpcDataQueue_t * SifRemoveRpcQueue(SifRpcDataQueue_t *qd)
int SifBindRpc(SifRpcClientData_t *client, int rpc_number, int mode)
int SifCallRpc(SifRpcClientData_t *client, int rpc_number, int mode, void *send, int ssize, void *receive, int rsize, SifRpcEndFunc_t end_function, void *end_param)
static SifRpcClientData_t cd0
Definition: poweroff.c:29
int _iop_reboot_count
static u8 poffThreadStack[512 *16]
Definition: poweroff.c:26
static struct t_SifRpcServerData cb_srv
Definition: poweroff.c:31
void * _gp
static struct t_SifRpcDataQueue cb_queue
Definition: poweroff.c:30
static void PowerOffThread(void *dat)
Definition: poweroff.c:48
struct t_SifRpcServerData * server
Definition: sifrpc.h:142
void * gp_reg
Definition: kernel.h:230
u32 option
Definition: kernel.h:234
int stack_size
Definition: kernel.h:229
void * func
Definition: kernel.h:227
void * stack
Definition: kernel.h:228
u32 attr
Definition: kernel.h:233
int initial_priority
Definition: kernel.h:231
#define NULL
Definition: tamtypes.h:91

References _gp, _iop_reboot_count, ee_thread_t::attr, cb_queue, cb_srv, cd0, CreateThread(), DeleteThread(), ee_thread_t::func, ee_thread_t::gp_reg, ee_thread_t::initial_priority, nopdelay(), NULL, ee_thread_t::option, poffThreadStack, POWEROFF_THREAD_PRIORITY, PowerOffThread(), powerOffThreadId, PWROFF_ENABLE_AUTO_SHUTOFF, PWROFF_IRX, SifRpcClientData_t::server, SifBindRpc(), SifCallRpc(), SifRemoveRpc(), SifRemoveRpcQueue(), ee_thread_t::stack, ee_thread_t::stack_size, StartThread(), and TerminateThread().

Referenced by main(), poweroffSetCallback(), and poweroffShutdown().

◆ poweroffSetCallback()

void poweroffSetCallback ( poweroff_callback  cb,
void *  arg 
)

Definition at line 95 of file poweroff.c.

96 {
97  poweroffInit();
98 
99  poweroff_cb = cb;
100  poweroff_data = arg;
101 }
int poweroffInit(void)
Definition: poweroff.c:57

References poweroff_cb, poweroff_data, and poweroffInit().

Referenced by main().

◆ poweroffShutdown()

void poweroffShutdown ( void  )

Definition at line 103 of file poweroff.c.

104 {
105  poweroffInit();
106 
107  SifCallRpc(&cd0, PWROFF_SHUTDOWN, 0, NULL, 0, NULL, 0, NULL, NULL);
108 }
#define PWROFF_SHUTDOWN
Definition: pwroff_rpc.h:20

References cd0, NULL, poweroffInit(), PWROFF_SHUTDOWN, and SifCallRpc().

Referenced by poweroffCallback().

◆ PowerOffThread()

static void PowerOffThread ( void *  dat)
static

Definition at line 48 of file poweroff.c.

49 {
50  static unsigned char cb_rpc_buffer[64] __attribute__((aligned(64)));
51 
55 }
SifRpcServerData_t * SifRegisterRpc(SifRpcServerData_t *srv, int sid, SifRpcFunc_t func, void *buff, SifRpcFunc_t cfunc, void *cbuff, SifRpcDataQueue_t *qd)
SifRpcDataQueue_t * SifSetRpcQueue(SifRpcDataQueue_t *q, int thread_id)
void SifRpcLoop(SifRpcDataQueue_t *q)
static void * PowerOff_ee_rpc_handler(int fnum, void *buffer, int len)
Definition: poweroff.c:34

References cb_queue, cb_srv, NULL, PowerOff_ee_rpc_handler(), powerOffThreadId, PWROFF_IRX, SifRegisterRpc(), SifRpcLoop(), and SifSetRpcQueue().

Referenced by poweroffInit().

Variable Documentation

◆ _gp

void* _gp
extern

Referenced by poweroffInit().

◆ _iop_reboot_count

int _iop_reboot_count
extern

Referenced by poweroffInit().

◆ cb_queue

struct t_SifRpcDataQueue cb_queue
static

Definition at line 29 of file poweroff.c.

Referenced by poweroffInit(), and PowerOffThread().

◆ cb_srv

struct t_SifRpcServerData cb_srv
static

Definition at line 29 of file poweroff.c.

Referenced by poweroffInit(), and PowerOffThread().

◆ cd0

SifRpcClientData_t cd0
static

Definition at line 29 of file poweroff.c.

Referenced by poweroffInit(), and poweroffShutdown().

◆ poffThreadStack

u8 poffThreadStack[512 *16]
static

Definition at line 26 of file poweroff.c.

Referenced by poweroffInit().

◆ poweroff_cb

poweroff_callback poweroff_cb = NULL
static

Definition at line 23 of file poweroff.c.

Referenced by PowerOff_ee_rpc_handler(), and poweroffSetCallback().

◆ poweroff_data

void* poweroff_data = NULL
static

Definition at line 24 of file poweroff.c.

Referenced by PowerOff_ee_rpc_handler(), and poweroffSetCallback().

◆ powerOffThreadId

int powerOffThreadId = -1
static

Definition at line 32 of file poweroff.c.

Referenced by poweroffChangeThreadPriority(), poweroffInit(), and PowerOffThread().