예제 #1
0
static ssize_t leds_dev_read (struct file *file, char *buf, size_t len,
			      loff_t *pos)
{
	char temp_buf[LED_NUM_DIGITS];
	len = read_leds (*pos, temp_buf, len);
	if (copy_to_user (buf, temp_buf, len))
		return -EFAULT;
	*pos += len;
	return len;
}
예제 #2
0
static void led_tick ()
{
	static unsigned counter = 0;
	
	if (++counter == (HZ / TICK_UPD_FREQ)) {
		/* Which frame we're currently displaying for each digit.  */
		static unsigned frame_nums[LED_NUM_DIGITS] = { 0 };
		/* Display image.  */
		static unsigned char image[LED_NUM_DIGITS] = { 0 };
		unsigned char prev_image[LED_NUM_DIGITS];
		int write_to_leds = 1; /* true if we should actually display */
		int digit;

		/* We check to see if the physical LEDs contains what we last
		   wrote to them; if not, we suppress display (this is so that
		   users can write to the LEDs, and not have their output
		   overwritten).  As a special case, we start writing again if
		   all the LEDs are blank, or our display image is all zeros
		   (indicating that this is the initial update, when the actual
		   LEDs might contain random data).  */
		read_leds (0, prev_image, LED_NUM_DIGITS);
		for (digit = 0; digit < LED_NUM_DIGITS; digit++)
			if (image[digit] != prev_image[digit]
			    && image[digit] && prev_image[digit])
			{
				write_to_leds = 0;
				break;
			}

		/* Update display image.  */
		for (digit = 0;
		     digit < LED_NUM_DIGITS && tick_frames[digit][0] >= 0;
		     digit++)
		{
			int frame = tick_frames[digit][frame_nums[digit]];
			if (frame < 0) {
				image[digit] = tick_frames[digit][0];
				frame_nums[digit] = 1;
			} else {
				image[digit] = frame;
				frame_nums[digit]++;
				break;
			}
		}

		if (write_to_leds)
			/* Write the display image to the physical LEDs.  */
			write_leds (0, image, LED_NUM_DIGITS);

		counter = 0;
	}
}
예제 #3
0
void main ()
{
  const sColor * cp = colors;
  const sColor * const ecp = colors + sizeof(colors) / sizeof(*colors);

  vBSP430platformInitialize_ni();
  (void)iBSP430consoleInitialize();
  while (1) {
    if (0 > cp->idx) {
      cprintf("%s is not available\n", cp->name);
    } else {
      vBSP430ledSet(cp->idx, 1);
      cprintf("%s lit; mask 0x%x\n", cp->name, read_leds());
      BSP430_CORE_DELAY_CYCLES(5 * BSP430_CLOCK_NOMINAL_MCLK_HZ);
      vBSP430ledSet(cp->idx, 0);
    }
    if (++cp == ecp) {
      cp = colors;
    }
  }
}