6.5.2. Basic

6.5.2.1. Functions

void PLTFRM_init(void)

This is called when the system boots up. The function initializes the platform. This includes CC2520 SPI interface, UART interface and sensors that have been integrated to the platform.

PLTFRM_sts_t PLTFRM_getMacExtAddr(UINT8_t *extAddr_p)

Every WiSense node must have a unique MAC address that is 8 bytes or 64 bits long. This address is configured in the EEPROM of the node. The platform supports two types of EEPROM devices to store this address: Atmel AT24MAC602 and Atmel AT24C01C. The hardware will have one of the two, not both. Code would be compiled to handle the applicable EEPROM based on compilation flags PLTFRM_AT24MAC602_ENA and PLTFRM_AT24C01C_ENA. If neither of these is defined, a hard-coded value of 47:47:47:47:47:47 is returned as the MAC address.

Parameters:
  • extAddr_p – Points to a location where the MAC address is returned. Address is returned in Big Endian order.
Returns:

PLTFRM_STS_SUCCESS is returned on success. A non-zero value indicates a failure. Two possible errors are PLTFRM_STS_INV_DEV_ID and PLTFRM_STS_OPN_FAILED.

UINT16_t PLTFRM_calcCkSum16(UINT8_t *buff_p, UINT8_t len)

Calculates the checksum based on byte-length data.

Parameters:
  • buff_p – Points to data on which checksum has to be calculated.
  • len – Length in bytes of data to consider from buff_p.
Returns:

The calculated checksum.

6.5.2.2. Macros

// On chip sensing of Vcc
#define PLTFRM_ON_CHIP_VCC_SENSOR_OUTPUT_LEN   2
#define PLTFRM_ON_CHIP_VCC_SENSOR_ACTIVE_TIME_MICROSECS   125

// On chip temperature sensor
#define PLTFRM_ON_CHIP_TEMP_SENSOR_OUTPUT_LEN  2
#define PLTFRM_ON_CHIP_TEMP_SENSOR_ACTIVE_TIME_MICROSECS   125



// --------------------- Devices --------------------------

#define PLTFRM_DUMMY_DEV_ID        0x0

// Serial EEPROM
#define PLTFRM_AT24C01C_1_DEV_ID    0x1           // I2C
#define PLTFRM_AT24C01C_1_I2C_ADDR  0x0

// Serial EEPROM with EUI-64 and 128 bit serial number
#define PLTFRM_AT24MAC602_1_DEV_ID    0x2
#define PLTFRM_AT24MAC602_1_I2C_ADDR  0x0

// Temperature sensors
#define PLTFRM_LM75B_1_DEV_ID       0x9            // I2C
#define PLTFRM_LM75B_1_I2C_ADDR     0x0
#define PLTFRM_LMP75B_DEV_CNT       0x1            // Number of such devices in the system

#define PLTFRM_TMP102_1_DEV_ID      0xa            // I2C
#define PLTFRM_TMP102_1_I2C_ADDR    0x0            // A0 pin connected to ground
#define PLTFRM_TMP102_DEV_CNT       0x1

// Light sensor
#define PLTFRM_SFH_7773_1_DEV_ID    0x11           // I2C
#define PLTFRM_SFH_7773_1_I2C_ADDR  0x0
#define PLTFRM_SFH_7773_DEV_CNT     0x1            // Number of such devices in the system

// Light sensor
#define PLTFRM_TSL45315_1_DEV_ID    0x12           // I2C
#define PLTFRM_TSL45315_1_I2C_ADDR  0x0
#define PLTFRM_TSL45315_DEV_CNT     0x1            // Number of such devices in the system


// Gyro + Accelerometer + Temp
#define PLTFRM_MPU6050_1_DEV_ID     0x13           // I2C
#define PLTFRM_MPU6050_1_I2C_ADDR   0x0            // LSB is 0 (AD0 is 0)
#define PLTFRM_MPU6050_DEV_CNT      0x1            // Number of such devices in the system

// RADIO
#define PLTFRM_CC2520_1_DEV_ID      0x19           // SPI


// Pressure sensor
#define PLTFRM_MPL115A1_1_DEV_ID    0x20           // SPI


#define PLTFRM_EKMC160111X_1_DEV_ID   0x30         // GPIO
#define PLTFRM_EKMC160111X_DEV_CNT    0x1          // Number of such devices in the system

// LEDs
#define PLTFRM_LED_1_DEV_ID           0x40         // GPIO
#define PLTFRM_LED_2_DEV_ID           0x41         // GPIO

// Switches (On/Off)
#define PLTFRM_REED_SWITCH_1_DEV_ID   0x50         // GPIO
#define PLTFRM_REED_SWITCH_DEV_CNT    0x1

// Analog Pressure Sensor
#define PLTFRM_MP3V5050GP_1_DEV_ID    0x60         // Analog input
#define PLTFRM_MP3V5050GP_DEV_CNT     0x1


#define PLTFRM_BATT_1_DEV_ID          0x68         // Analog input
#define PLTFRM_BATT_DEV_CNT           0x1

// AD7797 (Bridge sensor)
#define PLTFRM_AD7797_1_DEV_ID        0x70
#define PLTFRM_AD7797_DEV_CNT         0x1          // SPI bus

#define PLTFRM_ON_CHIP_VCC_SENSOR_DEV_ID    0x78      // ADC_10 channel
#define PLTFRM_ON_CHIP_VCC_SENSOR_DEV_CNT   0x1

// ---------------------------------------------------------


// ------------- Buses (I2C, SPI, 1-WIRE etc) --------------
// I2C (software)
#define PLFRM_I2C_SW_BUS_1_ID      0x80

// I2C (hardware)
#define PLFRM_I2C_HW_BUS_1_ID      0x88

// SPI (hardware)
#define PLFRM_SPI_HW_BUS_1_ID      0x90

// 1 WIRE (software)
#define PLTFRM_1WIRE_SW_BUS_1_ID   0x98

// UART
#define PLTFRM_UART_HW_1_DEV_ID    0xa0
// ---------------------------------------------------------


// ---------------------------------------------------------
// Layout of EEPROM (device id 0x1)
// ---------------------------------------------------------

#define PLTFRM_AT24C01C_1_OFF_MAC_EXT_ADDR         0x0
#define PLTFRM_AT24C01C_1_OFF_MAC_EXT_ADDR_CKSUM   8

#define PLTFRM_MAC_EXT_ADDR_CKSUM_LEN   0x2

#define PLTFRM_AT24C01C_1_OFF_PHY_CHAN_NR          (PLTFRM_AT24C01C_1_OFF_MAC_EXT_ADDR_CKSUM  \
                                                    + PLTFRM_MAC_EXT_ADDR_CKSUM_LEN)


#define PLTFRM_intDisable( ) \
do \
{  \
   __bic_SR_register(GIE); \
} while (0)

#define PLTFRM_intEnable( ) \
do \
{  \
   __bis_SR_register(GIE); \
} while (0)


#define PLTFRM_saveIntStateAndDisable(intState) \
do \
{  \
   UINT16_t statusReg = _get_SR_register(); \
   intState = statusReg & GIE ? \
              PLTFRM_GLOBAL_INT_ENABLED : PLTFRM_GLOBAL_INT_DISABLED; \
   __bic_SR_register(GIE); \
} while (0)

#define PLTFRM_restoreIntState(savedIntState) \
do \
{  \
   if (savedIntState == PLTFRM_GLOBAL_INT_ENABLED) \
       __bis_SR_register(GIE); \
   else \
           __bic_SR_register(GIE); \
} while (0)

#define PLTFRM_enterLPM( )  \
do \
{  \
   _BIS_SR(LPM3_bits + GIE); \
} while (0)

#define PLTFRM_exitLPM( )  \
do \
{  \
   _BIC_SR_IRQ(LPM3_bits); \
} while (0)


#define PLTFRM_TOGGLE_LED_1()  \
do                             \
{                              \
   P3OUT ^= BIT0;              \
} while (0)

#define PLTFRM_TOGGLE_LED_2()  \
do                             \
{                              \
   P4OUT ^= BIT5;               \
} while (0)

#define PLTFRM_ON_LED_1()   P3OUT |= BIT0
#define PLTFRM_ON_LED_2()   P4OUT |= BIT5

#define PLTFRM_OFF_LED_1()   P3OUT &= ~(BIT0)
#define PLTFRM_OFF_LED_2()   P4OUT &= ~(BIT5)

// IAR compiler - returns a random number in the range 0 to RAND_MAX (32767)
#define pltfrm_randU16( )   rand()

/*
 * WDTCTL is a 16-bit, password-protected, read/write register. Any read
 * or write access must use word instructions and write accesses must
 * include the write password 05Ah in the upper byte. Any write to WDTCTL
 * with any value other than 05Ah in the upper byte is a security key
 * violation and triggers a PUC system reset regardless of timer mode.
 */
#define PLTFRM_mcuReset()  \
do {                       \
   WDTCTL = ~WDTPW;        \
} while (1)

/*
 * Setting WDTCNTCL = 1 clears the count value to 0000h. WDTCNTCL is
 * automatically reset.
 */
#define PLTFRM_kickWatchDog( )   \
do {                             \
   WDTCTL = (WDTPW + WDTCNTCL + WDTSSEL);  \
} while (0)

6.5.2.3. Type Definitions

typedef enum
{
   PLTFRM_STS_SUCCESS = 0,
   PLTFRM_STS_OPN_IN_PROGRESS = 1,
   PLTFRM_STS_INV_DEV_ID = 2,
   PLTFRM_STS_TIMER_ALREADY_ACTIVE = 3,
   PLTFRM_STS_INV_PARAM = 4,
   PLTFRM_STS_I2C_BUS_WR_ERROR = 5,
   PLTFRM_STS_I2C_BUS_RD_ERROR = 6,
   PLTFRM_STS_DEV_REG_UPDATE_ERR = 7,
   PLTFRM_STS_DEV_STATE_UNKNOWN = 8,
   PLTFRM_STS_DEV_NOT_READY = 9,
   PLTFRM_STS_DEV_MISSING = 10,
   PLTFRM_STS_DEV_PART_NR_MISMATCH = 11,
   PLTFRM_STS_UNKNOWN_DEV_OPN_MODE = 12,
   PLTFRM_STS_INV_HW_CONN = 13,
   PLTFRM_STS_FEATURE_NOT_ENA = 14,
   PLTFRM_STS_RESOURCE_CONFLICT = 15,
   PLTFRM_STS_INV_HW_RESOURCE = 16,
   PLTFRM_STS_NO_PENDING_EVT = 17,
   PLTFRM_STS_INV_DEV_OPN_MODE = 18,
   PLTFRM_STS_OPN_FAILED = 19,
   PLTFRM_STS_DEV_DATA_NOT_READY = 20,
   PLTFRM_STS_DEV_INV_OPN_MODE = 21
} PLTFRM_sts_t;