void spi_set(SPI_CMD cmd, uint16_t wparam, uint32_t lparam) { lock_enter(&spi_lock); static SPI_MOSI tx1 __attribute__ ((aligned(16))); tx1.cmd = cmd; tx1.wparam = wparam; tx1.lparam = lparam; spi_scan(&tx1); lock_leave(&spi_lock); }
void xivss_draw(vessel* v) { int i;//,w,h; /*XPLMGetScreenSize(&w,&h); for (i = 0; i < 80; i++) { float RGB[4] = { 0.75f,1.00f,1.00f,1.0f }; if (xivss_debug_buf[i]) XPLMDrawString(RGB,12*2,12*(i+2),xivss_debug_buf[i],0,xplmFont_Basic); }*/ lock_enter(xivss_debug_lock); for (i = 0; i < 80; i++) { if (xivss_debug_buf[i]) { if (highlevel_pushcallback("OnIVSSMessage")) { lua_pushstring(L,xivss_debug_buf[i]); highlevel_call(1,0); } free(xivss_debug_buf[i]); xivss_debug_buf[i] = 0; } } lock_leave(xivss_debug_lock); //Read as fast as possible? #ifdef FFMPEG_SUPPORT glReadPixels((1024/2)-(352/2), (768/2)-(288/2), 352, 288, GL_BGR, GL_UNSIGNED_BYTE, av_picture_data); #endif }
void nbuf_cleanup(ndesc_t *nd) { check_ndesc(nd); nbuf_t **q = &nd->q, **q_head = &nd->q_head; nbuf_t *dp; int i=0; lock_enter(&nd->lock); while ((dp = *q_head) != NULL) { check_nbuf(dp); //assert(dp->buf); if (dp->buf == 0) lprintf("WARNING: dp->buf == NULL\n"); else wrx_free("nbuf:buf", dp->buf); *q_head = dp->prev; if (dp == *q) *q = NULL; nbuf_free(dp); i++; } nd->cnt = 0; nd->ovfl = FALSE; lock_leave(&nd->lock); //printf("nbuf_cleanup: removed %d, malloc %d\n", i, wrx_malloc_stat()); }
nbuf_t *nbuf_dequeue(ndesc_t *nd) { check_ndesc(nd); nbuf_t **q = &nd->q, **q_head = &nd->q_head; nbuf_t *nb; lock_enter(&nd->lock); nb = *q_head; if (nb) check_nbuf(nb); while (nb && nb->dequeued) { nb = nb->prev; if (nb) check_nbuf(nb); } if (nb) { if (nd->dbug) printf("D%d ", nb->id); nb->dequeued = TRUE; nd->cnt--; if (nd->dbug) nbuf_dumpq(nd); } lock_leave(&nd->lock); assert(!nb || (nb && !nb->done)); //assert(!nb || ((nb->mc->remote_port == nd->mc->remote_port) && (strcmp(nb->mc->remote_ip, nd->mc->remote_ip) == 0))); if (nb) check_nbuf(nb); return nb; }
void spi_get(SPI_CMD cmd, SPI_MISO *rx, int bytes, uint16_t wparam, uint32_t lparam) { lock_enter(&spi_lock); static SPI_MOSI tx3 __attribute__ ((aligned(16))); tx3.cmd = cmd; tx3.wparam = wparam; tx3.lparam = lparam; spi_scan(&tx3, rx, bytes); lock_leave(&spi_lock); rx->status=BUSY; while(rx->status==BUSY) { NextTaskL("spi_get"); // wait for response } }
void spi_get_noduplex(SPI_CMD cmd, SPI_MISO *rx, int bytes, uint16_t wparam, uint32_t lparam) { lock_enter(&spi_lock); // block other threads static SPI_MOSI tx4 __attribute__ ((aligned(16))); tx4.cmd = cmd; tx4.wparam = wparam; tx4.lparam = lparam; evSpi(-EV_SPILOOP, "spiGetNoDuplex", "enter"); spi_scan(&tx4, rx, bytes); // Send request evSpi(EV_SPILOOP, "spiGetNoDuplex", "sent req"); tx4.cmd = CmdNoDuplex; spi_scan(&tx4); // Collect response to our own request evSpi(EV_SPILOOP, "spiGetNoDuplex", "exit"); lock_leave(&spi_lock); // release block }
void add_debug_log(const char* message) { int i; lock_enter(xivss_debug_lock); #if (!defined(DEDICATED_SERVER)) && (!defined(ORBITER_MODULE)) if (xivss_debug_buf[79]) free(xivss_debug_buf[79]); for (i = 79; i > 0; i--) { xivss_debug_buf[i] = xivss_debug_buf[i-1]; } xivss_debug_buf[0] = malloc(strlen(message)+1); strcpy(xivss_debug_buf[0],message); #else printf("%s\n",message); #endif lock_leave(xivss_debug_lock); }
int nbuf_queued(ndesc_t *nd) { check_ndesc(nd); nbuf_t *bp; int queued = 0; lock_enter(&nd->lock); bp = nd->q; if (bp) check_nbuf(bp); while (bp) { if (!bp->dequeued) { queued++; } bp = bp->next; if (bp) check_nbuf(bp); } lock_leave(&nd->lock); return queued; }
static nbuf_t *nbuf_malloc() { nbuf_t *nb; #ifdef NBUF_STATIC_ALLOC lock_enter(&nbuf_lock); int i; for (i=0; i<NNBUF; i++) { nb = &nbuf[i]; if (nb->isFree) break; } if (i == NNBUF) panic("out of nbufs"); lock_leave(&nbuf_lock); #else nb = (nbuf_t*) wrx_malloc("nbuf", sizeof(nbuf_t)); #endif memset(nb, 0, sizeof(nbuf_t)); nb->magic = NB_MAGIC; nb->magic_b = NBUF_MAGIC_B; nb->magic_e = NBUF_MAGIC_E; check_nbuf(nb); return nb; }
static bool nbuf_enqueue(ndesc_t *nd, nbuf_t *nb) { check_ndesc(nd); nbuf_t **q = &nd->q, **q_head = &nd->q_head; nbuf_t *dp; bool ovfl = FALSE; lock_enter(&nd->lock); // collect done buffers (same thread where they're allocated) #if 1 // decrement ttl counters if (nd->ttl) { dp = *q_head; while (dp) { check_nbuf(dp); if (dp->done) { assert(dp->ttl); dp->ttl--; } dp = dp->prev; } } while ((dp = *q_head) && (((nd->ttl == 0) && dp->done) || ((nd->ttl != 0) && dp->done && (dp->ttl == 0))) ) { check_nbuf(dp); if (nd->dbug) printf("R%d ", dp->id); if (nd->dbug) nbuf_dumpq(nd); assert(dp->buf); wrx_free("nbuf:buf", dp->buf); *q_head = dp->prev; if (*q == dp) { *q = NULL; assert(*q_head == NULL); } else { (*q_head)->next = NULL; } nbuf_free(dp); if (nd->dbug) nbuf_dumpq(nd); } #endif check_nbuf(nb); if (nd->ovfl && (nd->cnt < ND_LOWAT)) { nd->ovfl = FALSE; } if (nd->ovfl || (nd->cnt > ND_HIWAT)) { //if (!nd->ovfl && (nd->cnt > ND_HIWAT)) printf("HIWAT\n"); nd->ovfl = TRUE; ovfl = TRUE; } else { nd->cnt++; check_nbuf(nb); if (*q) (*q)->prev = nb; nb->next = *q; *q = nb; nb->prev = NULL; if (!*q_head) *q_head = nb; } lock_leave(&nd->lock); return ovfl; }