Contiki 3.x
board.c
1 /**
2  * Board-initialisation for the Muntjac
3  */
4 
5 #include <stdio.h>
6 #include <stdint.h>
7 #include "contiki-conf.h"
8 #include "board.h"
9 #include "spi-arch.h"
10 #include "dev/xmem.h"
11 #include "dev/i2c.h"
12 #include "reset-sensor.h"
13 #include "dev/gpio.h"
14 #include "dev/ioc.h"
15 
16 void board_init() {
17  /* Disable & turn off CC1120. */
18  GPIO_SOFTWARE_CONTROL(GPIO_PORT_TO_BASE(CC1200_RESET_PORT), GPIO_PIN_MASK(CC1200_RESET_PIN));
19  GPIO_SET_OUTPUT(GPIO_PORT_TO_BASE(CC1200_RESET_PORT), GPIO_PIN_MASK(CC1200_RESET_PIN));
20  ioc_set_over(CC1200_RESET_PORT, CC1200_RESET_PIN, IOC_OVERRIDE_OE);
21 
22  GPIO_SOFTWARE_CONTROL(GPIO_PORT_TO_BASE(PWR_RADIO_EN_PORT), GPIO_PIN_MASK(PWR_RADIO_EN_PIN));
23  GPIO_SET_OUTPUT(GPIO_PORT_TO_BASE(PWR_RADIO_EN_PORT), GPIO_PIN_MASK(PWR_RADIO_EN_PIN));
24  ioc_set_over(PWR_RADIO_EN_PORT, PWR_RADIO_EN_PIN, IOC_OVERRIDE_OE);
25 
26  GPIO_CLR_PIN(GPIO_PORT_TO_BASE(CC1200_RESET_PORT), GPIO_PIN_MASK(CC1200_RESET_PIN));
27  GPIO_CLR_PIN(GPIO_PORT_TO_BASE(PWR_RADIO_EN_PORT), GPIO_PIN_MASK(PWR_RADIO_EN_PIN));
28 
29  // Update and print reset sensor.
30  printf("Reset count: %d\n", reset_sensor.configure(0,0));
31 
32  // TODO - setup all output pins as GPIO
33 
34  // Initialize and deselect SD CSN
35  spix_cs_init(USD_CSN_PORT, USD_CSN_PIN);
36  SPIX_CS_SET(USD_CSN_PORT, USD_CSN_PIN);
37 
38  /* Ensure that the SD card is powered OFF. */
39  GPIO_SOFTWARE_CONTROL(GPIO_PORT_TO_BASE(PWR_SD_EN_PORT), GPIO_PIN_MASK(PWR_SD_EN_PIN));
40  GPIO_SET_OUTPUT(GPIO_PORT_TO_BASE(PWR_SD_EN_PORT), GPIO_PIN_MASK(PWR_SD_EN_PIN));
41  ioc_set_over(PWR_SD_EN_PORT, PWR_SD_EN_PIN, IOC_OVERRIDE_OE);
42  GPIO_CLR_PIN(GPIO_PORT_TO_BASE(PWR_SD_EN_PORT), GPIO_PIN_MASK(PWR_SD_EN_PIN));
43 
44  /* Turn ON the CC1120. */
45  GPIO_SET_PIN(GPIO_PORT_TO_BASE(PWR_RADIO_EN_PORT), GPIO_PIN_MASK(PWR_RADIO_EN_PIN));
46 
47  /* Initialise the onboard flash. */
48  xmem_init();
49 
50  // TODO - these are MS1/MS2 specific, do we want to stick in their own init file?
51  // maybe with RTC stuff and #define it in?. Could use presence (or lack of) RTC to
52  // determine whether we are connected to an MS1/MS2.
53  /* Ensure that Sensors are powered OFF. */
54  GPIO_SOFTWARE_CONTROL(GPIO_PORT_TO_BASE(PWR_SENSE_EN_PORT), GPIO_PIN_MASK(PWR_SENSE_EN_PIN));
55  GPIO_SET_OUTPUT(GPIO_PORT_TO_BASE(PWR_SENSE_EN_PORT), GPIO_PIN_MASK(PWR_SENSE_EN_PIN));
56  ioc_set_over(PWR_SENSE_EN_PORT, PWR_SENSE_EN_PIN, IOC_OVERRIDE_OE);
57  GPIO_CLR_PIN(GPIO_PORT_TO_BASE(PWR_SENSE_EN_PORT), GPIO_PIN_MASK(PWR_SENSE_EN_PIN));
58 
59  /* Ensure that RS485 TXEN is DISABLED. */
60  GPIO_SOFTWARE_CONTROL(GPIO_PORT_TO_BASE(RS485_TXEN_PORT), GPIO_PIN_MASK(RS485_TXEN_PIN));
61  GPIO_SET_OUTPUT(GPIO_PORT_TO_BASE(RS485_TXEN_PORT), GPIO_PIN_MASK(RS485_TXEN_PIN));
62  ioc_set_over(RS485_TXEN_PORT, RS485_TXEN_PIN, IOC_OVERRIDE_OE);
63  GPIO_CLR_PIN(GPIO_PORT_TO_BASE(RS485_TXEN_PORT), GPIO_PIN_MASK(RS485_TXEN_PIN));
64 
65  /* Setup I2C */
66  i2c_init(I2C_SDA_PORT, I2C_SDA_PIN, I2C_SCL_PORT, I2C_SCL_PIN, I2C_SCL_NORMAL_BUS_SPEED);
67 }
#define GPIO_PIN_MASK(PIN)
Converts a pin number to a pin mask.
Definition: gpio.h:321
Header file with definitions related to the I/O connections on the Muntjac platform, cc2538-based.
Header file for the cc2538 SPI driver, including macros for the implementation of the low-level SPI p...
#define IOC_OVERRIDE_OE
Output Enable.
Definition: ioc.h:222
#define GPIO_CLR_PIN(PORT_BASE, PIN_MASK)
Set pins with PIN_MASK of port with PORT_BASE low.
Definition: gpio.h:114
void i2c_init(uint8_t port_sda, uint8_t pin_sda, uint8_t port_scl, uint8_t pin_scl, uint32_t bus_speed)
Initialize the I2C peripheral and pins.
Definition: i2c.c:49
#define GPIO_SET_PIN(PORT_BASE, PIN_MASK)
Set pins with PIN_MASK of port with PORT_BASE high.
Definition: gpio.h:107
void spix_cs_init(uint8_t port, uint8_t pin)
Configure a GPIO to be the chip select pin.
Definition: spi.c:319
void board_init()
Board specific iniatialisation.
Definition: board.c:54
#define GPIO_SET_OUTPUT(PORT_BASE, PIN_MASK)
Set pins with PIN_MASK of port with PORT_BASE to output.
Definition: gpio.h:100
Header file with declarations for the I/O Control module.
#define GPIO_SOFTWARE_CONTROL(PORT_BASE, PIN_MASK)
Configure the pin to be software controlled with PIN_MASK of port with PORT_BASE. ...
Definition: gpio.h:259
#define GPIO_PORT_TO_BASE(PORT)
Converts a port number to the port base address.
Definition: gpio.h:329
void ioc_set_over(uint8_t port, uint8_t pin, uint8_t over)
Set Port:Pin override function.
Definition: ioc.c:54