/* blocking call for a character */ int conio_getch() { int key = -1; uint8 b; switch (conio_ttymode) { case CONIO_TTY_PVR: #ifdef GFX while ((key = kbd_get_key()) == -1) { thd_pass(); } #endif break; case CONIO_TTY_SERIAL: { while ((key = scif_read()) == -1) { thd_pass(); } if (key == 3) arch_exit(); break; } case CONIO_TTY_STDIO: { int i; i = fs_read(conio_serial_fd, &b, 1); if (i <= 0) return -1; key = b; if (key == '\n') return conio_getch(); break; } } return key; }
/* Start playback (implies song load) */ int sndmp3_start(const char *fn, int loop) { /* Can't start again if already playing */ if (sndmp3_status == STATUS_PLAYING) return -1; /* Initialize MP3 engine */ if (fn) { if (libmpg123_init(fn) < 0) return -1; /* Set looping status */ sndmp3_loop = loop; } /* Wait for player thread to be ready */ while (sndmp3_status != STATUS_READY) thd_pass(); /* Tell it to start */ if (fn) sndmp3_status = STATUS_STARTING; else sndmp3_status = STATUS_REINIT; sem_signal(sndmp3_halt_sem); return 0; }
int aica_audio_write(char *buffer, int len) { /*If this stuff works, get rid of that bit left from the old output system. */ if (len== -1) { return 0; } retry: mutex_lock(audio_mut); if (sndptr + len > BUFFER_MAX_FILL) { mutex_unlock(audio_mut); if(!aud_set) { start_audio(); } thd_pass(); goto retry; } memcpy (tmpbuf + sndptr, buffer, len); sndptr += len; mutex_unlock(audio_mut); if(!aud_set && sndptr >= sbsize) { start_audio(); } return 0; //return len; }
/* Shutdown the player */ void sndmp3_shutdown() { sndmp3_status = STATUS_QUIT; sem_signal(sndmp3_halt_sem); while (sndmp3_status != STATUS_ZOMBIE) thd_pass(); spu_disable(); }
static void wait_a_while(unsigned int timeout) { timeout = jiffies + 500; while (jiffies < timeout) { thd_pass(); } }
/* Wait for the song to be queued */ void sndoggvorbis_queue_wait() { assert(sndoggvorbis_queue_wait); /* Make sure we've loaded ok */ while (sndoggvorbis_status != STATUS_QUEUED) thd_pass(); }
/* Stop playback (implies song unload) */ void sndmp3_stop() { if (sndmp3_status == STATUS_READY) return; sndmp3_status = STATUS_STOPPING; while (sndmp3_status != STATUS_READY) thd_pass(); libmpg123_shutdown(); mp3_last_fn[0] = 0; }
/* This function waits until it is possible to write a full sound buffer */ static void DCAUD_WaitAudio(_THIS) { if (this->hidden->playing) { /* wait */ while(aica_get_pos(0)/this->spec.samples == this->hidden->nextbuf) { thd_pass(); } } }
/* sndoggvorbis_shutdown() * * function that stops playing and shuts down the player thread. */ void sndoggvorbis_thd_quit() { sndoggvorbis_status = STATUS_QUIT; /* In case player is READY -> tell it to continue */ sem_signal(sndoggvorbis_halt_sem); while (sndoggvorbis_status != STATUS_ZOMBIE) thd_pass(); // snd_stream_stop(); }
static int loader_waitnotstatus(loader_status_e status, unsigned int timeout) { if (timeout) { timeout += jiffies; } while (status == loader_status && (!timeout || jiffies < timeout)) { thd_pass(); } if (status == loader_status) { printf("entrylist_loader : waiting on not status %d timeout..\n", status); } return status != loader_status; }
/* This loops as long as the audio driver is open. Do we want to poll more frequently? */ static void *play_loop(void* yarr) { while (aud_set == 1) { if (sndptr >= sbsize) { while(waiting_for_data == 1) { snd_stream_poll(shnd); thd_pass(); if (aud_set == 0) { return NULL; } } waiting_for_data = 1; } else { thd_pass(); } } /* while (aud_set == 1) */ return NULL; }
static int eth_txts(uint8 *pkt, int len) { int res; int oldirq; for( ; ; ) { if (!irq_inside_int()) tx_lock(); #if 0 STOPIRQ; while (bba_dma_busy) { STARTIRQ; thd_pass(); STOPIRQ; } #endif #ifdef NICE res = net_tx(pkt, len, irq_inside_int()); #else res = net_tx(pkt, len, 1); #endif #if 0 STARTIRQ; #endif if (!irq_inside_int()) tx_unlock(); if (!res || irq_inside_int()) break; thd_pass(); } return res; }
int ppp_modem_init(const char *number, int blind, int *conn_rate) { uint64_t timeout; /* Initialize the modem. */ if(!modem_init()) return -1; /* Set the modem up to connect to a remote machine. */ modem_set_mode(MODEM_MODE_REMOTE, MODEM_SPEED_V8_AUTO); /* If we aren't doing blind dialing, wait up to 5 seconds for a dialtone. */ if(!blind) { if(modem_wait_dialtone(5000)) { modem_shutdown(); return -2; } } /* Dial the specified phone number. */ if(!modem_dial(number)) { modem_shutdown(); return -3; } /* Give ourselves a 60 second timeout to establish a connection. */ timeout = timer_ms_gettime64() + 60 * 1000; while(timer_ms_gettime64() < timeout && modem_is_connecting()) { thd_pass(); } /* Did we connect successfully? */ if(!modem_is_connected()) { modem_shutdown(); return -4; } /* Does the user want the connection rate back? If so give it to them. */ if(conn_rate) { *conn_rate = modem_get_connection_rate(); } dbglog(DBG_KDEBUG, "ppp_modem: connected at %lu bps\n", modem_get_connection_rate()); /* We connected to the peer successfully, set our device with libppp. */ ppp_set_device(&modem_dev); return 0; }
/* sndoggvorbis_stop() * * function to stop the current playback and set the thread back to * STATUS_READY mode. */ void sndoggvorbis_stop() { if (sndoggvorbis_status != STATUS_PLAYING && sndoggvorbis_status != STATUS_STARTING && sndoggvorbis_status != STATUS_QUEUEING && sndoggvorbis_status != STATUS_QUEUED) { return; } /* Wait for the thread to finish starting */ while (sndoggvorbis_status == STATUS_STARTING) thd_pass(); sndoggvorbis_status = STATUS_STOPPING; /* Wait until thread is at STATUS_READY before giving control * back to the MAIN */ while(sndoggvorbis_status != STATUS_READY) { thd_pass(); } }
static void DCAUD_PlayDevice(_THIS) { SDL_AudioSpec *spec = &this->spec; unsigned int offset; if (this->hidden->playing) { /* wait */ while (aica_get_pos(0) / spec->samples == this->hidden->nextbuf) { thd_pass(); } } offset = this->hidden->nextbuf * spec->size; this->hidden->nextbuf ^= 1; /* Write the audio data, checking for EAGAIN on broken audio drivers */ if (spec->channels == 1) { spu_memload(this->hidden->leftpos + offset, this->hidden->mixbuf, this->hidden->mixlen); } else { offset /= 2; if ((this->spec.format & 255) == 8) { spu_memload_stereo8(this->hidden->leftpos + offset, this->hidden->rightpos + offset, this->hidden->mixbuf, this->hidden->mixlen); } else { spu_memload_stereo16(this->hidden->leftpos + offset, this->hidden->rightpos + offset, this->hidden->mixbuf, this->hidden->mixlen); } } if (!this->hidden->playing) { int mode; this->hidden->playing = 1; mode = (spec->format == AUDIO_S8) ? SM_8BIT : SM_16BIT; if (spec->channels == 1) { aica_play(0, mode, this->hidden->leftpos, 0, spec->samples * 2, spec->freq, 255, 128, 1); } else { aica_play(0, mode, this->hidden->leftpos, 0, spec->samples * 2, spec->freq, 255, 0, 1); aica_play(1, mode, this->hidden->rightpos, 0, spec->samples * 2, spec->freq, 255, 255, 1); } } }
static int eth_txts(uint8 *pkt, int len) { int res; for( ; ; ) { if (!irq_inside_int()) tx_lock(); res = net_tx(pkt, len, irq_inside_int()); if (!irq_inside_int()) tx_unlock(); if (!res || irq_inside_int()) break; thd_pass(); } return res; }
/* Wait until the flash is ready, with timeout */ static int bflash_wait_ready(bflash_dev_t *dev, uint32 addr, int timeout) { int wait = 0; if (timeout < 0) { timeout = -timeout; wait = 1; } while (timeout-- && bflash_busy(addr)) { if (wait) thd_sleep(100); else thd_pass(); } if (timeout <= 0) { ds_printf("DS_ERROR: Writing to flash timed out\n"); return -1; } return 0; }
/* initialize the console I/O stuffs */ int conio_init(int ttymode, int inputmode) { conio_ttymode = ttymode; conio_inputmode = inputmode; switch (conio_ttymode) { case CONIO_TTY_PVR: #ifdef GFX conio_draw_init(); #endif break; case CONIO_TTY_STDIO: break; case CONIO_TTY_SERIAL: conio_serial_fd = 1; break; default: assert_msg( false, "Unknown CONIO TTY mode" ); conio_ttymode = CONIO_TTY_PVR; break; } assert_msg( conio_inputmode == CONIO_INPUT_LINE, "Non-Line input modes not supported yet" ); conio_input_init(); if (conio_ttymode == CONIO_TTY_PVR) { conio_clear(); conio_gotoxy(0, 0); } ft_mutex = sem_create(1); /* create the conio thread */ conio_exit = 0; if (thd_create(conio_thread, 0) < 0) return -1; /* Wait for it to actually start */ while (!conio_entered) thd_pass(); return 0; }
static void input_cb_shutdown() { cb_sem_data_t *t, *n; int i; /* Make sure any clients waiting on getline go through */ cb_dead = 1; cb_default(""); /* This is pretty damned hacky but it should do the job */ for (i=0; i<5; i++) thd_pass(); sem_destroy(cb_mutex); sem_destroy(cb_sem); for (t=(cb_sem_data_t *)cb_queue; t; t = n) { n = t->next; free(t); } cb_queue = NULL; }
static char *read_line() { int q = 0, ch; while(1) { while ( (ch = dbgio_read()) == -1) /* sem_wait(chr_ready); */ thd_pass(); if (ch == '\r') { buffer[q] = 0; dbgio_write_str("\n"); return buffer; } if (ch == '\x08') { q--; dbgio_write_str("\x08 \x08"); continue; } buffer[q++] = ch; dbgio_write(ch); } }
/* Call this function as a thread to handle playback. Playback will stop and this thread will return when you call sndmp3_shutdown(). */ static void sndmp3_thread() { int sj; /* Main command loop */ while(sndmp3_status != STATUS_QUIT) { switch(sndmp3_status) { case STATUS_INIT: sndmp3_status = STATUS_READY; break; case STATUS_READY: printf("sndserver: waiting on semaphore\r\n"); sem_wait(sndmp3_halt_sem); printf("sndserver: released from semaphore\r\n"); break; case STATUS_STARTING: /* Initialize streaming driver */ if (stream_init(mpglib_callback) < 0) { sndmp3_status = STATUS_READY; } else { /* stream_start(decinfo.samprate, decinfo.channels - 1); */ stream_start(44100, 1); sndmp3_status = STATUS_PLAYING; } break; case STATUS_REINIT: /* Re-initialize streaming driver */ stream_init(NULL); sndmp3_status = STATUS_READY; break; case STATUS_PLAYING: { sj = jiffies; if (stream_poll() < 0) { if (sndmp3_loop) { printf("sndserver: restarting '%s'\r\n", mp3_last_fn); if (mpglib_init(mp3_last_fn) < 0) { sndmp3_status = STATUS_STOPPING; mp3_last_fn[0] = 0; } } else { printf("sndserver: not restarting\r\n"); stream_stop(); sndmp3_status = STATUS_READY; mp3_last_fn[0] = 0; } // stream_start(); } if (sj == jiffies) thd_pass(); break; } case STATUS_STOPPING: stream_stop(); sndmp3_status = STATUS_READY; break; } } /* Done: clean up */ mpglib_shutdown(); stream_shutdown(); sndmp3_status = STATUS_ZOMBIE; }
/* sndoggvorbis_wait_start() * * let's the caller wait until the vorbis thread is signalling that it is ready * to decode data */ void sndoggvorbis_wait_start() { while(sndoggvorbis_status != STATUS_READY) thd_pass(); }