Contiki 2.5
board-mb851.c
1 #include PLATFORM_HEADER
2 #include BOARD_HEADER
3 #include "hal/micro/micro-common.h"
5 
6 #include "dev/button-sensor.h"
7 #include "dev/temperature-sensor.h"
8 #include "dev/acc-sensor.h"
9 #include "dev/leds.h"
10 
11 void halBoardInit(void)
12 {
13 
14  return;
15 }
16 
17 static uint8_t sensors_status;
18 
19 #define BUTTON_STATUS_ACTIVE (1 << 0)
20 #define TEMP_STATUS_ACTIVE (1 << 1)
21 #define ACC_STATUS_ACTIVE (1 << 2)
22 
23 
25 {
26  /* Set everything to input value except LEDs */
27  GPIO_PACFGL = (GPIOCFG_IN <<PA0_CFG_BIT)|
28  (GPIOCFG_IN <<PA1_CFG_BIT)|
29  (GPIOCFG_IN <<PA2_CFG_BIT)|
30  (GPIOCFG_IN <<PA3_CFG_BIT);
31  GPIO_PACFGH = (GPIOCFG_IN <<PA4_CFG_BIT)| /* PTI EN */
32  (GPIOCFG_IN <<PA5_CFG_BIT)| /* PTI_DATA */
33  (GPIOCFG_IN <<PA6_CFG_BIT)|
34  (GPIOCFG_IN <<PA7_CFG_BIT);
35  GPIO_PBCFGL = (GPIOCFG_IN <<PB0_CFG_BIT)|
36  (GPIOCFG_IN <<PB1_CFG_BIT)| /* Uart TX */
37  (GPIOCFG_IN <<PB2_CFG_BIT)| /* Uart RX */
38  (GPIOCFG_IN <<PB3_CFG_BIT);
39  GPIO_PBCFGH = (GPIOCFG_IN <<PB4_CFG_BIT)|
40  (GPIOCFG_IN <<PB5_CFG_BIT)|
41  (GPIOCFG_IN <<PB6_CFG_BIT)|
42  (GPIOCFG_IN <<PB7_CFG_BIT);
43  GPIO_PCCFGL = (GPIOCFG_IN <<PC0_CFG_BIT)|
44  (GPIOCFG_IN <<PC1_CFG_BIT)|
45  (GPIOCFG_IN <<PC2_CFG_BIT)|
46  (GPIOCFG_IN <<PC3_CFG_BIT);
47  GPIO_PCCFGH = (GPIOCFG_IN <<PC4_CFG_BIT)|
48  (GPIOCFG_IN <<PC5_CFG_BIT)|
49  (GPIOCFG_IN <<PC6_CFG_BIT)| /* OSC32K */
50  (GPIOCFG_IN <<PC7_CFG_BIT); /* OSC32K */
51 
52  leds_init();
53 
54 }
55 
56 /* Remember state of sensors (if active or not), in order to
57  * resume their original state after calling powerUpSensors().
58  * Useful when entering in sleep mode, since all system
59  * peripherals have to be reinitialized. */
60 
62 
63  sensors_status = 0;
64 
65  if(button_sensor.status(SENSORS_READY)){
66  sensors_status |= BUTTON_STATUS_ACTIVE;
67  }
68  if(temperature_sensor.status(SENSORS_READY)){
69  sensors_status |= TEMP_STATUS_ACTIVE;
70  }
71  if(acc_sensor.status(SENSORS_READY)){
72  sensors_status |= ACC_STATUS_ACTIVE;
73  // Power down accelerometer to save power
74  SENSORS_DEACTIVATE(acc_sensor);
75  }
76 }
77 
78 /**/
80 
81  button_sensor.configure(SENSORS_HW_INIT, 0);
82  temperature_sensor.configure(SENSORS_HW_INIT, 0);
83  acc_sensor.configure(SENSORS_HW_INIT, 0);
84 
85  if(sensors_status & BUTTON_STATUS_ACTIVE){
86  SENSORS_ACTIVATE(button_sensor);
87  }
88  if(sensors_status & TEMP_STATUS_ACTIVE){
89  SENSORS_ACTIVATE(temperature_sensor);
90  }
91  if(sensors_status & ACC_STATUS_ACTIVE){
92  SENSORS_ACTIVATE(acc_sensor);
93  }
94 }
95 
96 void halBoardPowerUp(void)
97 {
98  /* Set everything to input value */
99  GPIO_PACFGL = (GPIOCFG_IN <<PA0_CFG_BIT)|
100  (GPIOCFG_IN <<PA1_CFG_BIT)|
101  (GPIOCFG_IN <<PA2_CFG_BIT)|
102  (GPIOCFG_IN <<PA3_CFG_BIT);
103  GPIO_PACFGH = (GPIOCFG_IN <<PA4_CFG_BIT)| /* PTI EN */
104  (GPIOCFG_IN <<PA5_CFG_BIT)| /* PTI_DATA */
105  (GPIOCFG_IN <<PA6_CFG_BIT)|
106  (GPIOCFG_IN <<PA7_CFG_BIT);
107  GPIO_PBCFGL = (GPIOCFG_IN <<PB0_CFG_BIT)|
108  (GPIOCFG_OUT_ALT <<PB1_CFG_BIT)| /* Uart TX */
109  (GPIOCFG_IN <<PB2_CFG_BIT)| /* Uart RX */
110  (GPIOCFG_IN <<PB3_CFG_BIT);
111  GPIO_PBCFGH = (GPIOCFG_IN <<PB4_CFG_BIT)|
112  (GPIOCFG_IN <<PB5_CFG_BIT)|
113  (GPIOCFG_IN <<PB6_CFG_BIT)|
114  (GPIOCFG_IN <<PB7_CFG_BIT);
115  GPIO_PCCFGL = (GPIOCFG_IN <<PC0_CFG_BIT)|
116  (GPIOCFG_IN <<PC1_CFG_BIT)|
117  (GPIOCFG_IN <<PC2_CFG_BIT)|
118  (GPIOCFG_IN <<PC3_CFG_BIT);
119  GPIO_PCCFGH = (GPIOCFG_IN <<PC4_CFG_BIT)|
120  (GPIOCFG_IN <<PC5_CFG_BIT)|
121  (GPIOCFG_IN <<PC6_CFG_BIT)| /* OSC32K */
122  (GPIOCFG_IN <<PC7_CFG_BIT); /* OSC32K */
123 
124 }