int exchange_data(int func_nr , uint8_t *write_buffer, int write_count , uint8_t *read_buffer, int read_count , uint32_t timeout) { int ret; if (sa == NULL) { return 0; } sa->error_code = 0xfffffff1; if (write_count > 0) { memcpy(sa->buffer, write_buffer, min(write_count, DMA_BUFFER_SIZE)); } ret = sysMutexLock(sa->mmio_mutex, 0); if (ret != 0) { LOG(lm_main, LOG_ERROR, ("sysMutexLock() failed. (%d)\n", ret)); return ret; } sysSpuRawWriteProblemStorage(sa->id, SPU_In_MBox, func_nr); sysSpuRawWriteProblemStorage(sa->id, SPU_In_MBox, read_count); ret = sysCondWait(sa->mmio_cond, timeout); if (ret != 0) { LOG(lm_main, LOG_ERROR, ("exchange_data: [sysCondWait timeout]\n")); sysMutexUnlock(sa->mmio_mutex); return ret; } ret = sysMutexUnlock(sa->mmio_mutex); if (ret != 0) { return ret; } if (sa->error_code == 0xfffffff1) { return -1; } if (read_buffer != NULL && read_count > 0) { memcpy(read_buffer, sa->buffer, min(read_count, DMA_BUFFER_SIZE)); } return sa->error_code; }
/* video worker thread */ void videoWorker ( void *arg ) { static s32 frames ; static time_t starttime ; dbgprintf ( "video thread starting" ) ; /* cast the void *arg to rsxData */ videoData* vdata = ( videoData* )arg ; /* signal main thread is ready */ sysCondSignal ( vdata->cond ) ; /* lock mutex */ sysMutexLock ( vdata->mutex, NO_TIMEOUT ) ; dbgprintf ( "video thread waiting" ) ; /* wait for main to be ready */ sysCondWait ( vdata->cond, NO_TIMEOUT ) ; /* release lock */ sysMutexUnlock ( vdata->mutex ) ; starttime = time( NULL ) ; dbgprintf ( "video thread entering loop" ) ; /* render frames until exit */ while ( *vdata->exitapp ) { /* render frame */ videoDrawFrame ( vdata ) ; frames++ ; } dbgprintf ( "video thread left loop" ) ; /* lock mutex */ sysMutexLock ( vdata->mutex, NO_TIMEOUT ) ; /* signal main before exit */ sysCondSignal ( vdata->cond ) ; /* release lock */ sysMutexUnlock ( vdata->mutex ) ; argprintf ( "frame rate: %g frames/sec", ( ( double ) frames ) / difftime ( time ( NULL ) , starttime ) ) ; dbgprintf ( "video thread exiting" ) ; /* exit thread */ sysThreadExit ( 0 ) ; }
/* pad worker thread */ void padWorker ( void *arg ) { dbgprintf ( "pad thread starting" ) ; /* cast the void *arg to rsxData */ padBtnData* pdata = ( padBtnData* )arg ; /* signal main thread is ready */ sysCondSignal ( pdata->cond ) ; /* lock mutex */ sysMutexLock ( pdata->mutex, NO_TIMEOUT ) ; dbgprintf ( "pad thread waiting" ) ; /* wait for main to be ready */ sysCondWait ( pdata->cond, NO_TIMEOUT ) ; /* release lock */ sysMutexUnlock ( pdata->mutex ) ; dbgprintf ( "pad thread entering loop" ) ; /* render frames until exit */ while ( *pdata->exitapp ) { /* check pads */ padCheckState ( pdata ) ; } dbgprintf ( "pad thread left loop" ) ; /* lock mutex */ sysMutexLock ( pdata->mutex, NO_TIMEOUT ) ; /* signal main before exit */ sysCondSignal ( pdata->cond ) ; /* release lock */ sysMutexUnlock ( pdata->mutex ) ; dbgprintf ( "pad thread exiting" ) ; /* exit thread */ sysThreadExit ( 0 ) ; }