Psp2Audio::Psp2Audio() :
	bgm_volume(0)
{

	// Creating mutexs
	BGM_Mutex = sceKernelCreateSema("BGM Mutex", 0, 1, 1, NULL);
	SFX_Mutex = sceKernelCreateSema("SFX Mutex", 0, 0, 1, NULL);
	SFX_Mutex_ID = sceKernelCreateSema("SFX Mutex for ID read", 0, 1, 1, NULL);

	// Starting audio thread for BGM
	BGM_Thread = sceKernelCreateThread("BGM Thread", &streamThread, 0x10000100, 0x10000, 0, 0, NULL);
	int res = sceKernelStartThread(BGM_Thread, sizeof(BGM_Thread), &BGM_Thread);
	if (res != 0){
		Output::Error("Failed to init audio thread (0x%x)", res);
		return;
	}

	// Starting audio threads for SFX
	for (int i=0;i < AUDIO_CHANNELS; i++){
		sfx_threads[i] = sceKernelCreateThread("SFX Thread", &sfxThread, 0x10000100, 0x10000, 0, 0, NULL);
		int res = sceKernelStartThread(sfx_threads[i], sizeof(sfx_threads[i]), &sfx_threads[i]);
		if (res != 0){
			Output::Error("Failed to init audio thread (0x%x)", res);
			return;
		}
	}

}
Esempio n. 2
0
void testThreadsEnded() {
	int thread1, thread2, thread3, thread4;
	
	// Thread1 will stop returning the function and sceKernelWaitThreadEnd will be executed after the thread have ended.
	thread1 = sceKernelCreateThread("threadEndedFunction1", (void *)&threadEndedFunction1, 0x12, 0x10000, 0, NULL);

	// Thread1 will stop with sceKernelExitThread and sceKernelWaitThreadEnd will be executed after the thread have ended.
	thread2 = sceKernelCreateThread("threadEndedFunction2", (void *)&threadEndedFunction2, 0x12, 0x10000, 0, NULL);

	// Thread3 will stop after a while so it will allow to execute sceKernelWaitThreadEnd before it ends.
	thread3 = sceKernelCreateThread("threadEndedFunction3", (void *)&threadEndedFunction3, 0x12, 0x10000, 0, NULL);
	
	// Thread4 won't start never, so sceKernelWaitThreadEnd can be executed before thread is started.
	thread4 = sceKernelCreateThread("threadEndedFunction4", NULL, 0x12, 0x10000, 0, NULL);

	sceKernelStartThread(thread1, 0, NULL);
	sceKernelStartThread(thread2, 0, NULL);
	sceKernelStartThread(thread3, 0, NULL);
	
	// This waits 5ms and supposes both threads (1 and 2) have ended. Thread 3 should have not ended. Thread 4 is not going to be started.
	sceKernelDelayThread(2 * 1000);

	printf("Threads.EndedExpected\n");
	
	sceKernelWaitThreadEnd(thread1, NULL);
	printf("Thread1.Ended\n");
	sceKernelWaitThreadEnd(thread2, NULL);
	printf("Thread2.Ended\n");
	sceKernelWaitThreadEnd(thread3, NULL);
	printf("Thread3.Ended\n");
	sceKernelWaitThreadEnd(thread4, NULL);
	printf("Thread4.NotStartedSoEnded\n");
}
Esempio n. 3
0
int main(int argc, char **argv) {
	int result;
	int check_not_update_value = 7;
	SceKernelSemaInfo info;
	
	sema = sceKernelCreateSema("sema1", 0, 0, 2, NULL);
	
	sceKernelReferSemaStatus(sema, &info);
	PRINT_SEMAPHORE(sema, info);
	
	threads[0] = sceKernelCreateThread("Thread-0", (void *)&threadFunction, 0x12, 0x10000, 0, NULL);
	threads[1] = sceKernelCreateThread("Thread-1", (void *)&threadFunction, 0x12, 0x10000, 0, NULL);
	threads[2] = sceKernelCreateThread("Thread-2", (void *)&threadFunction, 0x12, 0x10000, 0, NULL);
	threads[3] = sceKernelCreateThread("Thread-3", (void *)&threadFunction, 0x12, 0x10000, 0, NULL);
	threads[4] = sceKernelCreateThread("Thread-4", (void *)&threadFunction2, 0x12, 0x10000, 0, NULL);
	
	schedf("VALUE-INVARIANT:%d\n", check_not_update_value);
	
	sceKernelStartThread(threads[0], 1, (void*)&test[1]);
	sceKernelStartThread(threads[1], 2, NULL);
	sceKernelStartThread(threads[2], 0, (void*)&test[0]);
	sceKernelStartThread(threads[3], sizeof(int), (void*)&test[4]);
	sceKernelStartThread(threads[4], sizeof(int), &check_not_update_value);

	sceKernelDelayThread(10 * 1000);
	
	schedf("---\n");
	sceKernelReferSemaStatus(sema, &info);
	PRINT_SEMAPHORE(sema, info);
	schedf("---\n");
	sceKernelSignalSema(sema, 1);
	
	sceKernelDelayThread(10 * 1000);

	schedf("---\n");
	sceKernelReferSemaStatus(sema, &info);
	PRINT_SEMAPHORE(sema, info);
	schedf("---\n");

	sceKernelSignalSema(sema, 1);
	
	sceKernelDelayThread(10 * 1000);

	schedf("---\n");
	sceKernelReferSemaStatus(sema, &info);
	PRINT_SEMAPHORE(sema, info);
	schedf("---\n");
	
	result = sceKernelDeleteSema(sema);
	schedf("%08X\n", result);
	result = sceKernelDeleteSema(sema);
	schedf("%08X\n", result);
	
	schedf("VALUE-INVARIANT:%d\n", check_not_update_value);
	flushschedf();
	
	return 0;
}
Esempio n. 4
0
void
psp_audio_init()
{
  psp_audio_chid = sceAudioChReserve(-1, 1024, 0);
  psp_audio_thid = sceKernelCreateThread( "audio_thread",(void*)&psp_audio_thread,0x12,0x10000,0,NULL);
	sceKernelStartThread( psp_audio_thid, 0, 0);

  MP3_Init();

  psp_cdaudio_chid = sceAudioChReserve(-1, 1024, 0);
  psp_cdaudio_thid = sceKernelCreateThread( "cdaudio_thread",(void*)&psp_cdaudio_thread,0x12,0x10000,0,NULL);
	sceKernelStartThread( psp_cdaudio_thid, 0, 0);
}
Esempio n. 5
0
extern int xSetupCallbacks()
{
    int thid = sceKernelCreateThread("xCallbackThread", xCallbackThread, 0x11, 0xFA0, PSP_THREAD_ATTR_USER, 0);
    if(thid >= 0) sceKernelStartThread(thid, 0, 0);
    x_running = 1;
    return thid;
}
Esempio n. 6
0
File: main.c Progetto: AlanDrake/ags
int kernel_loadExec(const char *file, int argc, char** argv)
{
	u32 k1;
	k1 = pspSdkSetK1(0);
	
	// Store file name
	strcpy(exefile, file);
	
	// Concat argument strings
	paramlength = 0;
	
	// argv[0]
	strcpy(parameters, file);
	paramlength = strlen(file) + 1;
	
	// Rest of the arguments
	int i;
	for (i = 0; i < argc; i++)
	{
	  strcpy(&parameters[paramlength], argv[i]);
	  paramlength += (strlen(argv[i]) + 1);
	}
	
    SceUID thid = sceKernelCreateThread("launcher_thread", launcher_thread, 0x20, 0xFA0, 0, 0);
    if (thid > -1)
      thid = sceKernelStartThread(thid, 0, 0);
	
	pspSdkSetK1(k1);
	return 0;
}
Esempio n. 7
0
void testCheckStackLayout(const char *title, int argSize, u32 attr) {
	char argLengthTemp[0x1000];
	memset(argLengthTemp, 0xAB, sizeof(argLengthTemp));

	// First create the thread to wipe the stack area, that way we can see what it'd look like clean.
	SceUID stackCheckThread = sceKernelCreateThread("stackCheck", &stackCheckFunc, 0x10, 0x1000, attr, NULL);
	stackCheckInfo.size = sizeof(stackCheckInfo);
	sceKernelReferThreadStatus(stackCheckThread, &stackCheckInfo);
	sceKernelTerminateDeleteThread(stackCheckThread);
	memset(stackCheckInfo.stack, 0xCC, stackCheckInfo.stackSize);

	stackCheckName = title;
	stackCheckThread = sceKernelCreateThread("stackCheck", &stackCheckFunc, 0x10, 0x1000, attr, NULL);
	sceKernelStartThread(stackCheckThread, argSize, argLengthTemp);
	sceKernelWaitThreadEnd(stackCheckThread, NULL);

	u32 *stack = (u32 *) stackCheckInfo.stack;
	stack[1] = 0xFF1337FF;

	sceKernelTerminateDeleteThread(stackCheckThread);

	if (stack[1] != 0xFF1337FF) {
		schedf("    %s: WARNING: stack cleared to something after delete: %08x.\n", stackCheckName, stack[1]);
	}

	checkpoint("%s", title);
}
Esempio n. 8
0
void initDisp()
{
  // Load images
  img.back = loadImage("graphics/back.png",G2D_SWIZZLE);
  img.tileset = loadImage("graphics/tileset.png",G2D_SWIZZLE);
  img.gsquare = loadImage("./graphics/gsquare.png",G2D_SWIZZLE);
  img.banner = loadImage("./graphics/genesis.png",G2D_SWIZZLE);
  // Init libraries
  intraFontInit();
  font = intraFontLoad("flash0:/font/ltn8.pgf",INTRAFONT_CACHE_MED);
  bigfont = intraFontLoad("flash0:/font/ltn0.pgf",INTRAFONT_CACHE_MED);
  seriffont = intraFontLoad("flash0:/font/ltn1.pgf",INTRAFONT_CACHE_MED);
  intraFontSetEncoding(font,INTRAFONT_STRING_UTF8);
  intraFontSetEncoding(bigfont,INTRAFONT_STRING_UTF8);
  intraFontSetEncoding(seriffont,INTRAFONT_STRING_UTF8);
  // Start display thread
  SceUID thid = sceKernelCreateThread("disp_thread",dispThread,0x10,0x1000,
                                      THREAD_ATTR_USER | THREAD_ATTR_VFPU,0);
  if (thid < 0)
  {
    throwException("Can't create the display thread\n");
  }
  if (sceKernelStartThread(thid,0,0))
  {
    throwException("Can't start the display thread\n");
  }
}
Esempio n. 9
0
/* Entry point */
int module_start(SceSize args, void *argp)
{
	int thid;
	int retv;

	retv = sceUsbStart(PSP_USBBUS_DRIVERNAME, 0, 0);
	if(retv){
		return 0;
	}
	retv = sceUsbStart(HOSTFSDRIVER_NAME, 0, 0);
	if(retv){
		return 0;
	}
	retv = sceUsbActivate(HOSTFSDRIVER_PID);

	usbAsyncRegister(ASYNC_SHELL, &g_endp);
	usbAsyncRegister(ASYNC_STDOUT, &g_stdin);
	usbWaitForConnect();

	retv = stdioTtyInit();
	stdioInstallStdoutHandler(usbStdoutPrint);
	stdioInstallStderrHandler(usbStderrPrint);

	printk("Usbshell Start!\n");

	/* Create a high priority thread */
	thid = sceKernelCreateThread("USBShell", main_thread, 12, 0x2000, 0, NULL);
	if(thid >= 0)
	{
		sceKernelStartThread(thid, args, argp);
	}
	return 0;
}
Esempio n. 10
0
static void setup_callbacks (void)
{
     extern void directfb_dummy(void);
     extern void directfbwm_default(void);
//     extern void IDirectFBImageProvider_DFIFF_ctor(void);
     extern void IDirectFBImageProvider_GIF_ctor(void);
     extern void IDirectFBImageProvider_JPEG_ctor(void);
     extern void IDirectFBImageProvider_PNG_ctor(void);
//     extern void IDirectFBFont_DGIFF_ctor(void);
//     extern void IDirectFBFont_FT2_ctor(void);

     directfb_dummy();
     directfbwm_default();
//     IDirectFBImageProvider_DFIFF_ctor();
     IDirectFBImageProvider_GIF_ctor();
     IDirectFBImageProvider_JPEG_ctor();
     IDirectFBImageProvider_PNG_ctor();
//     IDirectFBFont_DGIFF_ctor();
//     IDirectFBFont_FT2_ctor();


	int id;

	if ((id = sceKernelCreateThread("update_thread", update_thread, 0x11, 0xFA0, 0, 0)) >= 0)
		sceKernelStartThread(id, 0, 0);
}
Esempio n. 11
0
int MP3ME_Load(char *fileName){
    MP3ME_filePos = 0;
    MP3ME_playingSpeed = 0;
    MP3ME_isPlaying = 0;

    getcwd(audioCurrentDir, 256);

    //initFileInfo(&MP3ME_info);
    strcpy(MP3ME_fileName, fileName);
    if (MP3MEgetInfo() != 0){
        strcpy(MP3ME_fileName, "");
        return ERROR_OPENING;
    }

    releaseAudio();
    if (setAudioFrequency(OUTPUT_BUFFER_SIZE/4, MP3ME_info.hz, 2) < 0){
        MP3ME_End();
        return ERROR_INVALID_SAMPLE_RATE;
    }

    MP3ME_thid = -1;
    MP3ME_eof = 0;
    MP3ME_thid = sceKernelCreateThread("decodeThread", decodeThread, THREAD_PRIORITY, DEFAULT_THREAD_STACK_SIZE, PSP_THREAD_ATTR_USER, NULL);
    if(MP3ME_thid < 0)
        return ERROR_CREATE_THREAD;

    sceKernelStartThread(MP3ME_thid, 0, NULL);
    return OPENING_OK;
}
Esempio n. 12
0
static void *psp_audio_init(const char *device,
      unsigned rate, unsigned latency)
{
   psp1_audio_t* psp;
   
   (void)device;
   (void)latency;

  psp = (psp1_audio_t*)calloc(1, sizeof(psp1_audio_t));

   if (!psp)
      return NULL;

   /* Cache aligned, not necessary but helpful. */
   psp->buffer      = (uint32_t*)
      memalign(64, AUDIO_BUFFER_SIZE * sizeof(uint32_t));
   memset(psp->buffer, 0, AUDIO_BUFFER_SIZE * sizeof(uint32_t));

   psp->zeroBuffer  = (uint32_t*)
      memalign(64, AUDIO_OUT_COUNT   * sizeof(uint32_t));
   memset(psp->zeroBuffer, 0, AUDIO_OUT_COUNT * sizeof(uint32_t));

   psp->readPos     = 0;
   psp->writePos    = 0;
   psp->rate        = rate;
   psp->thread      = sceKernelCreateThread
      ("audioMainLoop", audioMainLoop, 0x08, 0x10000, 0, NULL);
   psp->nonblocking = false;

   psp->running     = true;
   sceKernelStartThread(psp->thread, sizeof(psp1_audio_t*), &psp);

   return psp;
}
Esempio n. 13
0
/* Sets up the callback thread and returns its thread id */
int SetupCallbacks(void) {
    int thid = 0;
    thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, PSP_THREAD_ATTR_USER, 0);
    if(thid >= 0)
        sceKernelStartThread(thid, 0, 0);
    return thid;
}
Esempio n. 14
0
/**
 * Startup thread
 *
 * Creates the main program thread based on variables defined by the program.
 *
 * @param args - Size (in bytes) of arguments passed to the program by the kernel.
 * @param argp - Pointer to arguments passed by the kernel.
 */
int _start(SceSize args, void *argp)
{
	if (&sce_newlib_nocreate_thread_in_start != NULL) {
		/* The program does not want main() to be run in a seperate thread. */
		_main(args, argp);
		return 1;
	}

	int priority = DEFAULT_THREAD_PRIORITY;
	unsigned int attribute = DEFAULT_THREAD_ATTRIBUTE;
	unsigned int stackSize = DEFAULT_THREAD_STACK_KB_SIZE * 1024;
	const char *threadName = DEFAULT_MAIN_THREAD_NAME;

	if (&sce_newlib_priority != NULL) {
		priority = sce_newlib_priority;
	}
	if (&sce_newlib_attribute != NULL) {
		attribute = sce_newlib_attribute;
	}
	if (&sce_newlib_stack_kb_size != NULL) {
		stackSize = sce_newlib_stack_kb_size * 1024;
	}
	if (&sce_newlib_main_thread_name != NULL) {
		threadName = sce_newlib_main_thread_name;
	}

	SceUID thid;
	thid = sceKernelCreateThread(threadName, (void *) _main, priority, stackSize, attribute, 0);
	sceKernelStartThread(thid, args, argp);

	return 0;
}
Esempio n. 15
0
void testTryAllocThread(const char *title, u32 attr, u32 requestBytes, u32 initialBytes) {
	schedf("%s: ", title);

	SceUID vpl = sceKernelCreateVpl("vpl", PSP_MEMORY_PARTITION_USER, attr, 0x100, NULL);

	// This way we have some allocated + free.
	void *data;
	sceKernelAllocateVpl(vpl, initialBytes, &data, NULL);

	SceUID allocThread = sceKernelCreateThread("allocThread", &allocFunc, 0x12, 0x1000, 0, NULL);
	sceKernelStartThread(allocThread, sizeof(SceUID), &vpl);
	sceKernelDelayThread(400);

	int result = sceKernelTryAllocateVpl(vpl, requestBytes, &data);
	schedf("L2 ");
	sceKernelDelayThread(600);

	sceKernelDeleteVpl(vpl);
	sceKernelWaitThreadEnd(allocThread, NULL);
	sceKernelTerminateDeleteThread(allocThread);

	if (result == 0) {
		schedf("OK (thread=%08X)\n", schedulingResult);
	} else {
		schedf("Failed (thread=%08X, main=%08X)\n", schedulingResult, result);
	}
}
Esempio n. 16
0
void psp_init(void)
{
	SceUID thid;
	char buff[128], *r;

	/* fw 1.5 sometimes returns 8002032c, although getcwd works */
	r = getcwd(buff, sizeof(buff));
	if (r) sceIoChdir(buff);

	main_thread_id = sceKernelGetThreadId();

	lprintf("running on %08x kernel\n", sceKernelDevkitVersion()),
	lprintf("entered psp_init, threadId %08x, priority %i\n", main_thread_id,
		sceKernelGetThreadCurrentPriority());

	thid = sceKernelCreateThread("update_thread", callback_thread, 0x11, 0xFA0, 0, NULL);
	if (thid >= 0)
	{
		sceKernelStartThread(thid, 0, 0);
	}

	/* video */
	sceDisplaySetMode(0, 480, 272);
	sceDisplaySetFrameBuf(VRAM_FB1, 512, PSP_DISPLAY_PIXEL_FORMAT_565, PSP_DISPLAY_SETBUF_NEXTFRAME);
	current_screen = 1;
	psp_screen = VRAM_FB0;

	/* gu */
	sceGuInit();

	sceGuStart(GU_DIRECT, guCmdList);
	sceGuDrawBuffer(GU_PSM_5650, (void *)VRAMOFFS_FB0, 512);
	sceGuDispBuffer(480, 272, (void *)VRAMOFFS_FB1, 512); // don't care
	sceGuClear(GU_COLOR_BUFFER_BIT | GU_DEPTH_BUFFER_BIT);
	sceGuDepthBuffer((void *)VRAMOFFS_DEPTH, 512);
	sceGuOffset(2048 - (480 / 2), 2048 - (272 / 2));
	sceGuViewport(2048, 2048, 480, 272);
	sceGuDepthRange(0xc350, 0x2710);
	sceGuScissor(0, 0, 480, 272);
	sceGuEnable(GU_SCISSOR_TEST);

	sceGuDepthMask(0xffff);
	sceGuDisable(GU_DEPTH_TEST);

	sceGuFrontFace(GU_CW);
	sceGuEnable(GU_TEXTURE_2D);
	sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGB);
	sceGuAmbientColor(0xffffffff);
	sceGuColor(0xffffffff);
	sceGuFinish();
	sceGuSync(0, 0);

	sceDisplayWaitVblankStart();
	sceGuDisplay(GU_TRUE);


	/* input */
	sceCtrlSetSamplingCycle(0);
	sceCtrlSetSamplingMode(PSP_CTRL_MODE_ANALOG);
}
Esempio n. 17
0
static bool psp_audio_start(void *data)
{
    psp_audio_t* psp = (psp_audio_t*)data;

#if defined(VITA)
    SceKernelThreadInfo info;

    info.size = sizeof(SceKernelThreadInfo);

    if (sceKernelGetThreadInfo(
                psp->thread, &info) < 0) /* Error */
        return false;

    if (info.status != PSP2_THREAD_STOPPED)
        return false;

#else
    SceKernelThreadRunStatus runStatus;

    runStatus.size    = sizeof(SceKernelThreadRunStatus);

    if (sceKernelReferThreadRunStatus(
                psp->thread, &runStatus) < 0) /* Error */
        return false;
    if (runStatus.status != PSP_THREAD_STOPPED)
        return false;

#endif

    psp->running = true;

    sceKernelStartThread(psp->thread, sizeof(psp_audio_t*), &psp);

    return true;
}
Esempio n. 18
0
int main(int argc, char *argv[]) {
	testMemcpy("sceDmacMemcpy", &sceDmacMemcpy);
	testMemcpy("sceDmacTryMemcpy", &sceDmacTryMemcpy);

	checkpointNext("Size of copy:");
	// Approximate speed: 225 MB/s.
	checkpoint("  sceDmacMemcpy 1MB: %08x", sceDmacMemcpy((void*)0x04000000, (void*)0x04100000, 0x00100000));
	checkpoint("  sceDmacTryMemcpy 1MB: %08x", sceDmacTryMemcpy((void*)0x04000000, (void*)0x04100000, 0x00100000));
	checkpoint("  sceDmacMemcpy 1KB: %08x", sceDmacMemcpy((void*)0x04000000, (void*)0x04100000, 0x00000400));
	checkpoint("  sceDmacMemcpy 512B: %08x", sceDmacMemcpy((void*)0x04000000, (void*)0x04100000, 0x00000200));
	// This is suspiciously consistent, but maybe it's just chance.
	checkpoint("  sceDmacMemcpy 272B: %08x", sceDmacMemcpy((void*)0x04000000, (void*)0x04100000, 0x00000110));
	checkpoint("  sceDmacMemcpy 271B: %08x", sceDmacMemcpy((void*)0x04000000, (void*)0x04100000, 0x0000010F));
	checkpoint("  sceDmacMemcpy 257B: %08x", sceDmacMemcpy((void*)0x04000000, (void*)0x04100000, 0x00000101));
	checkpoint("  sceDmacMemcpy 256B: %08x", sceDmacMemcpy((void*)0x04000000, (void*)0x04100000, 0x00000100));
	
	checkpointNext("Concurrent copies:");
	SceUID copyThread = sceKernelCreateThread("dmac", &dmacCopyFunc, 0x10, 0x1000, 0, NULL);
	sceKernelStartThread(copyThread, 0, NULL);
	checkpoint("  sceDmacTryMemcpy 1MB: %08x", sceDmacTryMemcpy((void*)0x04000000, (void*)0x04100000, 0x00100000));
	checkpoint("  sceDmacMemcpy 1MB: %08x", sceDmacMemcpy((void*)0x04000000, (void*)0x04100000, 0x00100000));

	checkpointNext("memalign:");
	void *ptr;
	ptr = memalign(128 , 2048); checkpoint("%d", ((int)ptr) % 128);
	ptr = memalign(1024, 2048); checkpoint("%d", ((int)ptr) % 1024);
	//ptr = memalign(100 , 2048); checkpoint("%d", ((int)ptr) % 100);

	//checkpoint("%i bytes available", oslGetRamStatus().maxAvailable);

	return 0;
}
Esempio n. 19
0
int JNetwork::connect(const string& serverIP) {
#ifdef NETWORK_SUPPORT
    int err;
    char buffer[4096];
    if(netthread) return 0;


    sceUtilityLoadNetModule(1);
    sceUtilityLoadNetModule(3);

    if((err = pspSdkInetInit())) {
        sprintf(buffer, "JGE Error, could not initialise the network %08X", err);
        printf(buffer);
        printf("\n");
        error = buffer;
        return err;
    }

    if(JNetwork::connect_to_apctl(1)) {
        JNetwork::serverIP = serverIP;
        /* Create a user thread to do the real work */
        netthread = sceKernelCreateThread("net_thread", net_thread, 0x18, 0x10000, PSP_THREAD_ATTR_USER, NULL);

        if(netthread < 0)
        {
            printf("Error, could not create thread\n");
            sceKernelSleepThread();
        }

        sceKernelStartThread(netthread, 0, NULL);
        return netthread;
    }
#endif
    return 0;
}
Esempio n. 20
0
int main(int argc, char **argv) {
	LOCK_TEST("Lock 0 => 0", PSP_MUTEX_ATTR_FIFO, 0, 0);
	LOCK_TEST("Lock 0 => 1", PSP_MUTEX_ATTR_FIFO, 0, 1);
	LOCK_TEST("Lock 0 => 2", PSP_MUTEX_ATTR_FIFO, 0, 2);
	LOCK_TEST("Lock 0 => -1", PSP_MUTEX_ATTR_FIFO, 0, -1);
	LOCK_TEST("Lock 1 => 1", PSP_MUTEX_ATTR_FIFO, 1, 1);
	LOCK_TEST("Lock 0 => 2 (recursive)", PSP_MUTEX_ATTR_ALLOW_RECURSIVE, 0, 2);
	LOCK_TEST("Lock 0 => -1 (recursive)", PSP_MUTEX_ATTR_ALLOW_RECURSIVE, 0, -1);
	LOCK_TEST("Lock 1 => 1 (recursive)", PSP_MUTEX_ATTR_ALLOW_RECURSIVE, 1, 1);
	LOCK_TEST("Lock 1 => INT_MAX - 1 (recursive)", PSP_MUTEX_ATTR_ALLOW_RECURSIVE, 1, INT_MAX - 1);
	LOCK_TEST("Lock 1 => INT_MAX (recursive)", PSP_MUTEX_ATTR_ALLOW_RECURSIVE, 1, INT_MAX);
	LOCK_TEST("Lock INT_MAX => INT_MAX (recursive)", PSP_MUTEX_ATTR_ALLOW_RECURSIVE, INT_MAX, INT_MAX);

	SceUID lockThread = CREATE_SIMPLE_THREAD(lockFunc);
	LOCK_TEST_THREAD("Locked 1 => 1", PSP_MUTEX_ATTR_FIFO, 1, 1);
	LOCK_TEST_THREAD("Locked 0 => 1", PSP_MUTEX_ATTR_FIFO, 0, 1);
	LOCK_TEST_THREAD("Locked 1 => 1 (recursive)", PSP_MUTEX_ATTR_ALLOW_RECURSIVE, 1, 1);
	LOCK_TEST_THREAD("Locked 0 => 1 (recursive)", PSP_MUTEX_ATTR_ALLOW_RECURSIVE, 0, 1);

	// Probably we can't manage to delete it at the same time.
	SceUID deleteThread = CREATE_SIMPLE_THREAD(deleteMeFunc);
	SceUID mutex = sceKernelCreateMutex("lock", 0, 1, NULL);
	sceKernelStartThread(deleteThread, sizeof(int), &mutex);
	sceKernelDeleteMutex(mutex);

	LOCK_TEST_SIMPLE("NULL => 0", 0, 0);
	LOCK_TEST_SIMPLE("NULL => 1", 0, 1);
	LOCK_TEST_SIMPLE("Invalid => 1", 0xDEADBEEF, 1);
	LOCK_TEST_SIMPLE("Deleted => 1", mutex, 1);
	
	BASIC_SCHED_TEST("NULL",
		result = sceKernelTryLockMutex(0, 1);
	);
Esempio n. 21
0
void execPriorityTests(int attr, int deleteInstead) {
	SceUID threads[5];
	int test[5] = {1, 2, 3, 4, 5};
	int result;

	sceKernelCreateLwMutex(&workarea, "mutex1", attr, 1, NULL);

	int i;
	for (i = 0; i < 5; i++) {
		threads[i] = CREATE_PRIORITY_THREAD(threadFunction, 0x16 - i);
		sceKernelStartThread(threads[i], sizeof(int), (void*)&test[i]);
	}

	// This one intentionally is an invalid unlock.
	sceKernelDelayThread(1000);
	printf("Unlocking...\n");
	result = sceKernelUnlockLwMutex(&workarea, 2);
	sceKernelDelayThread(5000);
	printf("Unlocked 2? %08X\n", result);

	if (!deleteInstead)
	{
		sceKernelDelayThread(1000);
		printf("Unlocking...\n");
		result = sceKernelUnlockLwMutex(&workarea, 1);
		sceKernelDelayThread(5000);
		printf("Unlocked 1? %08X\n", result);
	}

	sceKernelDelayThread(1000);
	printf("Delete: %08X\n", sceKernelDeleteLwMutex(&workarea));
	printf("\n\n");
}
Esempio n. 22
0
static xjse_result_t	xjse_xpnet_startthread(XPNETCTX* pxpnctx)
{
	XJSE_TRACE("(*) XXXX starting xpnet thread: (%p)", pxpnctx);
	// create xpnet controll thread
#ifdef	XTPF_Linux
	xjse_int_t	n1 = pthread_create(&(pxpnctx->threadid), 0,
		xpnet_cb_thread, pxpnctx);
	if(n1 != 0) {
		XJSE_TRACE("(E) pthread_create() failed!");
		goto	failed;
	}
#endif	//XTPF_Linux
#ifdef	XTPF_PSP
	pxpnctx->threadid = sceKernelCreateThread("xpnet_thread", xpnet_cb_thread,
		32, 10 * 1024, PSP_THREAD_ATTR_USER, 0);
	if(pxpnctx->threadid < 0) {
		XJSE_TRACE("(E) sceKernelCreateThread() failed!");
		goto	failed;
	}
	sceKernelStartThread(pxpnctx->threadid, sizeof(XPNETCTX**), &pxpnctx);
#endif	//XTPF_PSP

	return	XJSE_SUCCESS;

failed:
	return	XJSE_E_UNKNOWN;
}
Esempio n. 23
0
static void setup_callbacks (void)
{
    int id;

    if ((id = sceKernelCreateThread("update_thread", update_thread, 0x11, 0xFA0, 0, 0)) >= 0)
        sceKernelStartThread(id, 0, 0);
}
Esempio n. 24
0
	/* Sets up the callback thread and returns its thread id */
	int SetupCallbacks()
	{
		int thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, 0, 0);
		if (thid >= 0)
			sceKernelStartThread(thid, 0, 0);
		return thid;
	}
Esempio n. 25
0
int pspAudioInit()
{
	int i,ret;
	int failed=0;
	char str[32];

	audio_terminate=0;
	audio_ready=0;

	for (i=0; i<PSP_NUM_AUDIO_CHANNELS; i++) {
    AudioStatus[i].handle = -1;
    AudioStatus[i].threadhandle = -1;
    AudioStatus[i].volumeright = PSP_VOLUME_MAX;
    AudioStatus[i].volumeleft  = PSP_VOLUME_MAX;
    AudioStatus[i].callback = 0;
    AudioStatus[i].pdata = 0;
	}
	for (i=0; i<PSP_NUM_AUDIO_CHANNELS; i++) {
		if ((AudioStatus[i].handle = sceAudioChReserve(-1,PSP_NUM_AUDIO_SAMPLES,0))<0) 
      failed=1;
	}
	if (failed) {
		for (i=0; i<PSP_NUM_AUDIO_CHANNELS; i++) {
			if (AudioStatus[i].handle != -1) 
        sceAudioChRelease(AudioStatus[i].handle);
			AudioStatus[i].handle = -1;
		}
		return -1;
	}
	audio_ready = 1;
	strcpy(str,"audiot0");
	for (i=0; i<PSP_NUM_AUDIO_CHANNELS; i++) {
		str[6]='0'+i;
		AudioStatus[i].threadhandle = sceKernelCreateThread(str,(void*)&AudioChannelThread,0x12,0x10000,0,NULL);
		if (AudioStatus[i].threadhandle < 0) {
			AudioStatus[i].threadhandle = -1;
			failed=1;
			break;
		}
		ret=sceKernelStartThread(AudioStatus[i].threadhandle,sizeof(i),&i);
		if (ret!=0) {
			failed=1;
			break;
		}
	}
	if (failed) {
		audio_terminate=1;
		for (i=0; i<PSP_NUM_AUDIO_CHANNELS; i++) {
			if (AudioStatus[i].threadhandle != -1) {
				//sceKernelWaitThreadEnd(AudioStatus[i].threadhandle,NULL);
				sceKernelDeleteThread(AudioStatus[i].threadhandle);
			}
			AudioStatus[i].threadhandle = -1;
		}
		audio_ready=0;
		return -1;
	}
	return 0;
}
Esempio n. 26
0
extern "C" int main(int argc, char **argv) {
	SceUID th1 = sceKernelCreateThread("thread1", &thread1, 0x21, 0x1000, 0, NULL);
	SceUID th2 = sceKernelCreateThread("thread2", &thread2, 0x21, 0x1000, 0, NULL);
	sema = sceKernelCreateSema("vpl", 0, 0, 10, NULL);
	sceKernelSignalSema(sema, 1);
	checkpoint("starting");
	sceKernelStartThread(th1, 0, NULL);
	sceKernelStartThread(th2, 0, NULL);
	checkpoint("waiting");
	sceKernelDelayThread(10000);
	checkpoint("deleting");
	sceKernelDeleteSema(sema);
	checkpoint("done, waiting");
	sceKernelDelayThread(10000);

	return 0;
}
Esempio n. 27
0
/* Sets up the callback thread and returns its thread id */
int SetupCallbacks(void) {
	int thid = sceKernelCreateThread("power_thread", CallbackThread, PRIORITY_POWER_THREAD, STACK_POWER_THREAD, THREAD_ATTR_USER, 0);
	if (thid >= 0) {
		sceKernelStartThread(thid, 0, 0);
	}

	return thid;
}
Esempio n. 28
0
int module_start( SceSize args, void *argp )
{
	memset( &ctrl_opts, 0, sizeof( WifiCtrlOpts ) );
	ctrl_opts.thid = sceKernelCreateThread( "wifhost_thread", main_thread, 0x20, 0x2000, PSP_THREAD_ATTR_USBWLAN, NULL );
	if( ctrl_opts.thid >= 0 )
		sceKernelStartThread( ctrl_opts.thid, args, argp );
	return 0;
}
Esempio n. 29
0
static int setup_callback(void)
{
   int thread_id = sceKernelCreateThread("update_thread", callback_thread, 0x11, 0xFA0, 0, 0);

   if (thread_id >= 0)
      sceKernelStartThread(thread_id, 0, 0);

   return thread_id;
}
Esempio n. 30
0
int _start(SceSize args, void *argp)
{
    SceUID thid;
    void (*_main_func)(SceSize args, void *argp) = _main;
    _main_func = (void *) ((u32) _main_func | 0x80000000);
	thid = sceKernelCreateThread("PSPPackerThread", (void *) _main_func, 32, 2048, 0, 0);
	sceKernelStartThread(thid, args, argp);
	return 0;
}