Contiki 2.6
|
00001 #include "contiki-conf.h" 00002 #include "dev/models.h" 00003 #include "dev/leds.h" 00004 00005 #include "cc2430_sfr.h" 00006 00007 /* 00008 * Sensinode v1.0 HW products have 2 red LEDs, LED1 is mapped to the Contiki 00009 * LEDS_GREEN and LED2 is mapped to LEDS_RED. 00010 */ 00011 00012 /*---------------------------------------------------------------------------*/ 00013 void 00014 leds_arch_init(void) 00015 { 00016 #ifdef MODEL_N740 00017 /* 00018 * We don't need explicit led initialisation for N740s. They are controlled 00019 * by the ser/par chip which is initalised already 00020 */ 00021 return; 00022 #else 00023 P0DIR |= 0x30; 00024 #endif 00025 } 00026 /*---------------------------------------------------------------------------*/ 00027 unsigned char 00028 leds_arch_get(void) 00029 { 00030 unsigned char l = 0; 00031 00032 #ifdef MODEL_N740 00033 /* Read the current ser-par chip status */ 00034 uint8_t ser_par; 00035 ser_par = n740_ser_par_get(); 00036 /* Check bits 7 & 8, ignore the rest */ 00037 if(ser_par & N740_SER_PAR_LED_GREEN) { 00038 l |= LEDS_GREEN; 00039 } 00040 if(ser_par & N740_SER_PAR_LED_RED) { 00041 l |= LEDS_RED; 00042 } 00043 #else 00044 if(LED1_PIN) { 00045 l |= LEDS_GREEN; 00046 } 00047 if(LED2_PIN) { 00048 l |= LEDS_RED; 00049 } 00050 #endif 00051 return l; 00052 } 00053 /*---------------------------------------------------------------------------*/ 00054 void 00055 leds_arch_set(unsigned char leds) 00056 { 00057 #ifdef MODEL_N740 00058 /* Read the current ser-par chip status - we want to change bits 7 & 8 but 00059 * the remaining bit values should be retained */ 00060 uint8_t ser_par; 00061 ser_par = n740_ser_par_get(); 00062 if(leds & LEDS_GREEN) { 00063 ser_par |= N740_SER_PAR_LED_GREEN; /* Set bit 7 */ 00064 } else { 00065 ser_par &= ~N740_SER_PAR_LED_GREEN; /* Unset bit 7 */ 00066 } 00067 00068 if(leds & LEDS_RED) { 00069 ser_par |= N740_SER_PAR_LED_RED; /* Set bit 8 */ 00070 } else { 00071 ser_par &= ~N740_SER_PAR_LED_RED; /* Unset bit 8 */ 00072 } 00073 00074 /* Write the new status back to the chip */ 00075 n740_ser_par_set(ser_par); 00076 #else 00077 if(leds & LEDS_GREEN) { 00078 LED1_PIN = 1; 00079 } else { 00080 LED1_PIN = 0; 00081 } 00082 00083 if(leds & LEDS_RED) { 00084 LED2_PIN = 1; 00085 } else { 00086 LED2_PIN = 0; 00087 } 00088 #endif 00089 } 00090 /*---------------------------------------------------------------------------*/