Wixel SDK
green_led.c
1 #include <usb.h>
2 #include <board.h>
3 #include <time.h>
4 
5 // USBFRML is the USB frame number, which is a convenient millisecond
6 // time base that we can use when we are the configured USB state
7 // and not in suspend mode.
8 
9 BIT usbBlinkActive = 0;
10 uint8 usbLastActivity;
11 uint8 usbBlinkStart;
12 
14 {
15  if (usbActivityFlag)
16  {
17  // Some USB activity happened recently.
18  usbActivityFlag = 0;
19 
20  // Record the time that the USB activity occurred.
21  usbLastActivity = USBFRML;
22 
23  // If we are not already blinking to indicate USB activity,
24  // start blinking.
25  if (!usbBlinkActive)
26  {
27  usbBlinkActive = 1;
28  usbBlinkStart = USBFRML;
29  }
30  }
31 
32  if (usbSuspended() || usbDeviceState == USB_STATE_DETACHED)
33  {
34  LED_GREEN(0); // We aren't connected to USB, or we are in suspend
35  // mode, so turn off the LED.
36  }
37  else if (usbDeviceState == USB_STATE_CONFIGURED)
38  {
39  if (usbBlinkActive)
40  {
41  LED_GREEN((USBFRML - usbBlinkStart) & 64);
42 
43  if ((uint8)(USBFRML - usbLastActivity) > 96)
44  {
45  usbBlinkActive = 0;
46  }
47  }
48  else
49  {
50  LED_GREEN(1); // On solid because we are properly connected.
51  }
52  }
53  else
54  {
55  // We do not use USBFRML for timing here because it might not be reliable
56  // before we reach the configured state.
57  LED_GREEN(getMs() >> 9 & 1); // Blink with a period of 1024 ms.
58  }
59 }
BIT usbSuspended(void)
Definition: usb.c:537
volatile BIT usbActivityFlag
Definition: usb.c:27
#define LED_GREEN(v)
Definition: board.h:27
enum USB_DEVICE_STATES XDATA usbDeviceState
Definition: usb.c:18
void usbShowStatusWithGreenLed(void)
Definition: green_led.c:13
__bit BIT
Definition: cc2511_types.h:32
unsigned char uint8
Definition: cc2511_types.h:9
uint32 getMs()
Definition: time.c:19