Contiki-Inga 3.x
leds-arch.c
1 #include "contiki-conf.h"
2 #include "dev/models.h"
3 #include "dev/leds.h"
4 
5 #include "cc2430_sfr.h"
6 
7 /*
8  * Sensinode v1.0 HW products have 2 red LEDs, LED1 is mapped to the Contiki
9  * LEDS_GREEN and LED2 is mapped to LEDS_RED.
10  */
11 
12 /*---------------------------------------------------------------------------*/
13 void
15 {
16 #ifdef MODEL_N740
17  /*
18  * We don't need explicit led initialisation for N740s. They are controlled
19  * by the ser/par chip which is initalised already
20  */
21  return;
22 #else
23  P0DIR |= 0x30;
24 #endif
25 }
26 /*---------------------------------------------------------------------------*/
27 unsigned char
28 leds_arch_get(void)
29 {
30  unsigned char l = 0;
31 
32 #ifdef MODEL_N740
33  /* Read the current ser-par chip status */
34  uint8_t ser_par;
35  ser_par = n740_ser_par_get();
36  /* Check bits 7 & 8, ignore the rest */
37  if(ser_par & N740_SER_PAR_LED_GREEN) {
38  l |= LEDS_GREEN;
39  }
40  if(ser_par & N740_SER_PAR_LED_RED) {
41  l |= LEDS_RED;
42  }
43 #else
44  if(LED1_PIN) {
45  l |= LEDS_GREEN;
46  }
47  if(LED2_PIN) {
48  l |= LEDS_RED;
49  }
50 #endif
51  return l;
52 }
53 /*---------------------------------------------------------------------------*/
54 void
55 leds_arch_set(unsigned char leds)
56 {
57 #ifdef MODEL_N740
58  /* Read the current ser-par chip status - we want to change bits 7 & 8 but
59  * the remaining bit values should be retained */
60  uint8_t ser_par;
61  ser_par = n740_ser_par_get();
62  if(leds & LEDS_GREEN) {
63  ser_par |= N740_SER_PAR_LED_GREEN; /* Set bit 7 */
64  } else {
65  ser_par &= ~N740_SER_PAR_LED_GREEN; /* Unset bit 7 */
66  }
67 
68  if(leds & LEDS_RED) {
69  ser_par |= N740_SER_PAR_LED_RED; /* Set bit 8 */
70  } else {
71  ser_par &= ~N740_SER_PAR_LED_RED; /* Unset bit 8 */
72  }
73 
74  /* Write the new status back to the chip */
75  n740_ser_par_set(ser_par);
76 #else
77  if(leds & LEDS_GREEN) {
78  LED1_PIN = 1;
79  } else {
80  LED1_PIN = 0;
81  }
82 
83  if(leds & LEDS_RED) {
84  LED2_PIN = 1;
85  } else {
86  LED2_PIN = 0;
87  }
88 #endif
89 }
90 /*---------------------------------------------------------------------------*/