Exemplo n.º 1
0
void display_right(void) {
  unsigned long data;
    
    // send all the pixels
    for ( p=0; p < NUMLEDS_R ; p++ ) {
      data = pixels_right[p];
      // 24 bits of data per pixel
      for ( i=0x800000; i>0 ; i>>=1 ) {
        if (data & i) {
            P1OUT |= DATA_R;
        } else {
            P1OUT &= ~DATA_R;
        }
        P1OUT |= CLOCK_R;    // latch on clock rise
        P1OUT &= ~CLOCK_R;
      }
    }
    writezeros(3 * ((NUMLEDS_R + 63) / 64)); // latch
    delayMillis(3);
}
Exemplo n.º 2
0
//initialization
void init(void) {
  int i;

  __disable_interrupt(); //because f**k that shit

  WDTCTL = WDTPW | WDTHOLD;	// Stop watchdog timer

  P1DIR |= DATA + CLOCK; // set data and clock pins to output
  P1OUT &= ~DATA; // Data low
  P1OUT &= ~CLOCK;
  for(i=0; i<NUMLEDS; i++) {
    pixels_left[i] = pixels_right[i] = 0x808080;
  }
  writezeros(3 * ((NUMLEDS + 63) / 64)); // latch to wake it up

    //encoder
    P2DIR = 0; //all input
    //P2REN = M_PHASEA | M_PHASEB | S_PHASEA | S_PHASEB | ON_SWITCH; //pull-up resistors
    P2REN = 0xFF; //all pull high
}
Exemplo n.º 3
0
void *
DiskWriter(void *arg)
{
	writebuf_t	*wbuf = 0;
	static int	gotone;

	while (1) {
		pthread_testcancel();

		pthread_mutex_lock(&writequeue_mutex);
		if (queue_empty(&writequeue)) {
			if (gotone)
				writeridles++;
			do {
#ifdef CONDVARS_WORK
				pthread_cond_wait(&writequeue_cond,
						  &writequeue_mutex);
#else
				pthread_mutex_unlock(&writequeue_mutex);
				fsleep(1000);
				pthread_mutex_lock(&writequeue_mutex);
#endif
				pthread_testcancel();
			} while (queue_empty(&writequeue));
		}
		queue_remove_first(&writequeue, wbuf, writebuf_t *, chain);
		writeinprogress = 1; /* XXX */
		gotone = 1;
		pthread_mutex_unlock(&writequeue_mutex);

		if (wbuf->data == NULL) {
			writezeros(wbuf->offset, wbuf->size);
		} else {
			rdycount++;
			assert(wbuf->size <= OUTSIZE);
			writedata(wbuf->offset, (size_t)wbuf->size, wbuf->data);
		}
		free_writebuf(wbuf);
		writeinprogress = 0; /* XXX, ok as unlocked access */
	}
}
Exemplo n.º 4
0
static void
dowrite_request(writebuf_t *wbuf)
{
	off_t offset, size;
	void *buf;
	
	offset = wbuf->offset;
	size = wbuf->size;
	buf = wbuf->data;
	assert(offset >= 0);
	assert(size > 0);

	/*
	 * Adjust for partition start and ensure data fits
	 * within partition boundaries.
	 */
	offset += sectobytes(outputminsec);
	assert((offset & (SECSIZE-1)) == 0);
	if (outputmaxsec > 0 && offset + size > sectobytes(outputmaxsec)) {
		if (!imagetoobigwarned) {
			fprintf(stderr, "WARNING: image too large "
				"for target slice, truncating\n");
			imagetoobigwarned = 1;
		}
		if (offset >= sectobytes(outputmaxsec)) {
			free_writebuf(wbuf);
			return;
		}
		size = sectobytes(outputmaxsec) - offset;
		wbuf->size = size;
	}
	wbuf->offset = offset;

	totaledata += size;

	if (nothreads) {
		/*
		 * Null buf means its a request to zero.
		 * If we are not filling, just return.
		 */
		if (buf == NULL) {
			if (dofill)
				writezeros(offset, size);
		} else {
			assert(size <= OUTSIZE);

			/*
			 * Handle any relocations
			 */
			applyrelocs(offset, (size_t)size, buf);
			writedata(offset, (size_t)size, buf);
		}
		free_writebuf(wbuf);
		return;
	}

#ifndef NOTHREADS
	if (buf == NULL) {
		if (!dofill) {
			free_writebuf(wbuf);
			return;
		}
	} else {
		assert(size <= OUTSIZE);

		/*
		 * Handle any relocations
		 */
		applyrelocs(offset, (size_t)size, buf);
	}

	/*
	 * Queue it up for the writer thread
	 */
	pthread_mutex_lock(&writequeue_mutex);
	queue_enter(&writequeue, wbuf, writebuf_t *, chain);
#ifdef CONDVARS_WORK
	pthread_cond_signal(&writequeue_cond);
#endif
	pthread_mutex_unlock(&writequeue_mutex);
#endif
}