Merge branch 'develop' into coap-example-periodic-resource-interval-fix
This commit is contained in:
commit
afa6f0b60b
|
@ -133,6 +133,32 @@
|
|||
#define RF_MODE RF_CONF_MODE
|
||||
#endif /* RF_CONF_MODE */
|
||||
|
||||
/* Sub-1 GHz path front-end mode configuration */
|
||||
#ifdef RF_SUB_1_GHZ_CONF_FRONT_END_MODE
|
||||
#define RF_SUB_1_GHZ_FRONT_END_MODE RF_SUB_1_GHZ_CONF_FRONT_END_MODE
|
||||
#else
|
||||
#define RF_SUB_1_GHZ_FRONT_END_MODE RF_FRONT_END_MODE_DIFFERENTIAL
|
||||
#endif
|
||||
|
||||
#ifdef RF_SUB_1_GHZ_CONF_BIAS_MODE
|
||||
#define RF_SUB_1_GHZ_BIAS_MODE RF_SUB_1_GHZ_CONF_BIAS_MODE
|
||||
#else
|
||||
#define RF_SUB_1_GHZ_BIAS_MODE RF_BIAS_MODE_INTERNAL
|
||||
#endif
|
||||
|
||||
/* 2.4 GHz path front-end mode configuration */
|
||||
#ifdef RF_2_4_GHZ_CONF_FRONT_END_MODE
|
||||
#define RF_2_4_GHZ_FRONT_END_MODE RF_2_4_GHZ_CONF_FRONT_END_MODE
|
||||
#else
|
||||
#define RF_2_4_GHZ_FRONT_END_MODE RF_FRONT_END_MODE_DIFFERENTIAL
|
||||
#endif
|
||||
|
||||
#ifdef RF_2_4_GHZ_CONF_BIAS_MODE
|
||||
#define RF_2_4_GHZ_BIAS_MODE RF_2_4_GHZ_CONF_BIAS_MODE
|
||||
#else
|
||||
#define RF_2_4_GHZ_BIAS_MODE RF_BIAS_MODE_INTERNAL
|
||||
#endif
|
||||
|
||||
/* Number of RX buffers. */
|
||||
#ifndef RF_CONF_RX_BUF_CNT
|
||||
#define RF_CONF_RX_BUF_CNT 4
|
||||
|
|
|
@ -96,7 +96,7 @@ to_hal_cfg(PIN_Config pin_cfg, gpio_hal_pin_cfg_t *cfg)
|
|||
/* Input config */
|
||||
if(pin_cfg & PIN_BM_INPUT_MODE) {
|
||||
/* Hysteresis config */
|
||||
if((pin_cfg & PIN_BM_HYSTERESIS) == PIN_HYSTERESIS) {
|
||||
if((pin_cfg & PIN_BM_HYSTERESIS) == PIN_BM_HYSTERESIS) {
|
||||
*cfg |= GPIO_HAL_PIN_CFG_HYSTERESIS;
|
||||
}
|
||||
|
||||
|
|
|
@ -56,12 +56,18 @@
|
|||
/* TI-RTOS RF Mode Object */
|
||||
RF_Mode rf_ble_mode =
|
||||
{
|
||||
.rfMode = RF_MODE_BLE,
|
||||
.rfMode = RF_MODE_MULTIPLE,
|
||||
.cpePatchFxn = &rf_patch_cpe_ble,
|
||||
.mcePatchFxn = 0,
|
||||
.rfePatchFxn = &rf_patch_rfe_ble,
|
||||
};
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/*
|
||||
* CMD_RADIO_SETUP must be configured with default TX power value
|
||||
* in the .txPower field.
|
||||
*/
|
||||
#define DEFAULT_TX_POWER 0x5F3C /* 5 dBm */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* Overrides for CMD_RADIO_SETUP */
|
||||
uint32_t rf_ble_overrides[] CC_ALIGN(4) =
|
||||
{
|
||||
|
@ -109,46 +115,14 @@ rfc_CMD_RADIO_SETUP_t rf_ble_cmd_radio_setup =
|
|||
.condition.nSkip = 0x0,
|
||||
.mode = 0x00,
|
||||
.loDivider = 0x00,
|
||||
.config.frontEndMode = 0x0,
|
||||
.config.biasMode = 0x0,
|
||||
.config.frontEndMode = 0x0, /* set by driver */
|
||||
.config.biasMode = 0x0, /* set by driver */
|
||||
.config.analogCfgMode = 0x0,
|
||||
.config.bNoFsPowerUp = 0x0,
|
||||
.txPower = 0x3D3F,
|
||||
.txPower = DEFAULT_TX_POWER,
|
||||
.pRegOverride = rf_ble_overrides,
|
||||
};
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* Structure for CMD_BLE_ADV_NC.pParams */
|
||||
rfc_bleAdvPar_t rf_ble_adv_par =
|
||||
{
|
||||
.pRxQ = 0,
|
||||
.rxConfig.bAutoFlushIgnored = 0x0,
|
||||
.rxConfig.bAutoFlushCrcErr = 0x0,
|
||||
.rxConfig.bAutoFlushEmpty = 0x0,
|
||||
.rxConfig.bIncludeLenByte = 0x0,
|
||||
.rxConfig.bIncludeCrc = 0x0,
|
||||
.rxConfig.bAppendRssi = 0x0,
|
||||
.rxConfig.bAppendStatus = 0x0,
|
||||
.rxConfig.bAppendTimestamp = 0x0,
|
||||
.advConfig.advFilterPolicy = 0x0,
|
||||
.advConfig.deviceAddrType = 0x0,
|
||||
.advConfig.peerAddrType = 0x0,
|
||||
.advConfig.bStrictLenFilter = 0x0,
|
||||
.advConfig.rpaMode = 0x0,
|
||||
.advLen = 0x18,
|
||||
.scanRspLen = 0x00,
|
||||
.pAdvData = 0,
|
||||
.pScanRspData = 0,
|
||||
.pDeviceAddress = 0,
|
||||
.pWhiteList = 0,
|
||||
.__dummy0 = 0x0000,
|
||||
.__dummy1 = 0x00,
|
||||
.endTrigger.triggerType = TRIG_NEVER,
|
||||
.endTrigger.bEnaCmd = 0x0,
|
||||
.endTrigger.triggerNo = 0x0,
|
||||
.endTrigger.pastTrig = 0x0,
|
||||
.endTime = 0x00000000,
|
||||
};
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* CMD_BLE_ADV_NC: BLE Non-Connectable Advertiser Command */
|
||||
rfc_CMD_BLE_ADV_NC_t rf_ble_cmd_ble_adv_nc =
|
||||
{
|
||||
|
@ -159,13 +133,13 @@ rfc_CMD_BLE_ADV_NC_t rf_ble_cmd_ble_adv_nc =
|
|||
.startTrigger.triggerType = TRIG_NOW,
|
||||
.startTrigger.bEnaCmd = 0x0,
|
||||
.startTrigger.triggerNo = 0x0,
|
||||
.startTrigger.pastTrig = 0x0,
|
||||
.condition.rule = COND_NEVER,
|
||||
.startTrigger.pastTrig = 0x1,
|
||||
.condition.rule = 0x0, /* set by driver */
|
||||
.condition.nSkip = 0x0,
|
||||
.channel = 0x8C,
|
||||
.whitening.init = 0x51,
|
||||
.channel = 0x00, /* set by driver */
|
||||
.whitening.init = 0x00, /* set by driver */
|
||||
.whitening.bOverride = 0x1,
|
||||
.pParams = &rf_ble_adv_par,
|
||||
.pOutput = 0,
|
||||
.pParams = 0x00000000, /* set by driver */
|
||||
.pOutput = 0x00000000, /* set by driver */
|
||||
};
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
|
|
@ -43,7 +43,6 @@ extern RF_Mode rf_ble_mode;
|
|||
/*---------------------------------------------------------------------------*/
|
||||
/* RF Core API commands */
|
||||
extern rfc_CMD_RADIO_SETUP_t rf_ble_cmd_radio_setup;
|
||||
extern rfc_bleAdvPar_t rf_ble_adv_par;
|
||||
extern rfc_CMD_BLE_ADV_NC_t rf_ble_cmd_ble_adv_nc;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* RF Core API Overrides */
|
||||
|
|
|
@ -57,7 +57,7 @@
|
|||
/* TI-RTOS RF Mode Object */
|
||||
RF_Mode rf_ieee_mode =
|
||||
{
|
||||
.rfMode = RF_MODE_IEEE_15_4,
|
||||
.rfMode = RF_MODE_MULTIPLE,
|
||||
.cpePatchFxn = 0,
|
||||
.mcePatchFxn = 0,
|
||||
.rfePatchFxn = 0,
|
||||
|
@ -110,8 +110,8 @@ rfc_CMD_RADIO_SETUP_t rf_cmd_ieee_radio_setup =
|
|||
.condition.rule = COND_NEVER,
|
||||
.condition.nSkip = 0x0,
|
||||
.mode = 0x01,
|
||||
.config.frontEndMode = 0x0,
|
||||
.config.biasMode = 0x0,
|
||||
.config.frontEndMode = 0x0, /* set by driver */
|
||||
.config.biasMode = 0x0, /* set by driver */
|
||||
.config.analogCfgMode = 0x0,
|
||||
.config.bNoFsPowerUp = 0x0,
|
||||
.txPower = DEFAULT_TX_POWER, /* 5 dBm default */
|
||||
|
|
|
@ -68,7 +68,7 @@
|
|||
/* TI-RTOS RF Mode Object */
|
||||
RF_Mode rf_prop_mode =
|
||||
{
|
||||
.rfMode = RF_MODE_PROPRIETARY_SUB_1,
|
||||
.rfMode = RF_MODE_MULTIPLE,
|
||||
.cpePatchFxn = &rf_patch_cpe_genfsk,
|
||||
.mcePatchFxn = 0,
|
||||
.rfePatchFxn = &rf_patch_rfe_genfsk,
|
||||
|
|
|
@ -47,7 +47,7 @@
|
|||
#include DeviceFamily_constructPath(driverlib/rf_mailbox.h)
|
||||
#include DeviceFamily_constructPath(driverlib/rf_common_cmd.h)
|
||||
#include DeviceFamily_constructPath(driverlib/rf_ble_cmd.h)
|
||||
#include DeviceFamily_constructPath(rf_patches/rf_patch_cpe_bt5.h)
|
||||
#include DeviceFamily_constructPath(rf_patches/rf_patch_cpe_multi_protocol.h)
|
||||
#include DeviceFamily_constructPath(rf_patches/rf_patch_rfe_bt5.h)
|
||||
#include DeviceFamily_constructPath(rf_patches/rf_patch_mce_bt5.h)
|
||||
|
||||
|
@ -59,11 +59,17 @@
|
|||
RF_Mode rf_ble_mode =
|
||||
{
|
||||
.rfMode = RF_MODE_AUTO,
|
||||
.cpePatchFxn = &rf_patch_cpe_bt5,
|
||||
.cpePatchFxn = &rf_patch_cpe_multi_protocol,
|
||||
.mcePatchFxn = &rf_patch_mce_bt5,
|
||||
.rfePatchFxn = &rf_patch_rfe_bt5,
|
||||
};
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/*
|
||||
* CMD_RADIO_SETUP must be configured with default TX power value
|
||||
* in the .txPower field.
|
||||
*/
|
||||
#define DEFAULT_TX_POWER 0x941E /* 5 dBm */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* Overrides for CMD_BLE5_RADIO_SETUP */
|
||||
uint32_t rf_ble_overrides_common[] CC_ALIGN(4) =
|
||||
{
|
||||
|
@ -137,71 +143,39 @@ rfc_CMD_BLE5_RADIO_SETUP_t rf_ble_cmd_radio_setup =
|
|||
.defaultPhy.mainMode = 0x0,
|
||||
.defaultPhy.coding = 0x0,
|
||||
.loDivider = 0x00,
|
||||
.config.frontEndMode = 0x0,
|
||||
.config.biasMode = 0x0,
|
||||
.config.frontEndMode = 0x0, /* set by driver */
|
||||
.config.biasMode = 0x0, /* set by driver */
|
||||
.config.analogCfgMode = 0x0,
|
||||
.config.bNoFsPowerUp = 0x0,
|
||||
.txPower = 0x941E,
|
||||
.txPower = DEFAULT_TX_POWER,
|
||||
.pRegOverrideCommon = rf_ble_overrides_common,
|
||||
.pRegOverride1Mbps = rf_ble_overrides_1mbps,
|
||||
.pRegOverride2Mbps = rf_ble_overrides_2mbps,
|
||||
.pRegOverrideCoded = rf_ble_overrides_coded,
|
||||
};
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* Structure for CMD_BLE5_ADV_NC.pParams */
|
||||
rfc_bleAdvPar_t rf_ble_adv_par =
|
||||
{
|
||||
.pRxQ = 0,
|
||||
.rxConfig.bAutoFlushIgnored = 0x0,
|
||||
.rxConfig.bAutoFlushCrcErr = 0x0,
|
||||
.rxConfig.bAutoFlushEmpty = 0x0,
|
||||
.rxConfig.bIncludeLenByte = 0x0,
|
||||
.rxConfig.bIncludeCrc = 0x0,
|
||||
.rxConfig.bAppendRssi = 0x0,
|
||||
.rxConfig.bAppendStatus = 0x0,
|
||||
.rxConfig.bAppendTimestamp = 0x0,
|
||||
.advConfig.advFilterPolicy = 0x0,
|
||||
.advConfig.deviceAddrType = 0x0,
|
||||
.advConfig.peerAddrType = 0x0,
|
||||
.advConfig.bStrictLenFilter = 0x0,
|
||||
.advConfig.rpaMode = 0x0,
|
||||
.advLen = 0x18,
|
||||
.scanRspLen = 0x00,
|
||||
.pAdvData = 0,
|
||||
.pScanRspData = 0,
|
||||
.pDeviceAddress = 0,
|
||||
.pWhiteList = 0,
|
||||
.__dummy0 = 0x0000,
|
||||
.__dummy1 = 0x00,
|
||||
.endTrigger.triggerType = TRIG_NEVER,
|
||||
.endTrigger.bEnaCmd = 0x0,
|
||||
.endTrigger.triggerNo = 0x0,
|
||||
.endTrigger.pastTrig = 0x0,
|
||||
.endTime = 0x00000000,
|
||||
};
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* CMD_BLE5_ADV_NC: Bluetooth 5 Non-Connectable Advertiser Command */
|
||||
rfc_CMD_BLE5_ADV_NC_t rf_ble_cmd_ble_adv_nc =
|
||||
{
|
||||
.commandNo = 0x182D,
|
||||
.status = 0x0000,
|
||||
.pNextOp = 0, // INSERT APPLICABLE POINTER: (uint8_t*)&xxx
|
||||
.commandNo = CMD_BLE5_ADV_NC,
|
||||
.status = IDLE,
|
||||
.pNextOp = 0,
|
||||
.startTime = 0x00000000,
|
||||
.startTrigger.triggerType = 0x0,
|
||||
.startTrigger.triggerType = TRIG_NOW,
|
||||
.startTrigger.bEnaCmd = 0x0,
|
||||
.startTrigger.triggerNo = 0x0,
|
||||
.startTrigger.pastTrig = 0x0,
|
||||
.condition.rule = 0x1,
|
||||
.startTrigger.pastTrig = 0x1,
|
||||
.condition.rule = 0x0, /* set by driver */
|
||||
.condition.nSkip = 0x0,
|
||||
.channel = 0x8C,
|
||||
.whitening.init = 0x51,
|
||||
.channel = 0x00, /* set by driver */
|
||||
.whitening.init = 0x00, /* set by driver */
|
||||
.whitening.bOverride = 0x1,
|
||||
.phyMode.mainMode = 0x0,
|
||||
.phyMode.coding = 0x0,
|
||||
.rangeDelay = 0x00,
|
||||
.txPower = 0x0000,
|
||||
.pParams = &rf_ble_adv_par,
|
||||
.pOutput = 0, // INSERT APPLICABLE POINTER: (uint8_t*)&xxx
|
||||
.pParams = 0x00000000, /* set by driver */
|
||||
.pOutput = 0x00000000, /* set by driver */
|
||||
.tx20Power = 0x00000000,
|
||||
};
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
|
|
@ -43,7 +43,6 @@ extern RF_Mode rf_ble_mode;
|
|||
/*---------------------------------------------------------------------------*/
|
||||
/* RF Core API commands */
|
||||
extern rfc_CMD_BLE5_RADIO_SETUP_t rf_ble_cmd_radio_setup;
|
||||
extern rfc_bleAdvPar_t rf_ble_adv_par;
|
||||
extern rfc_CMD_BLE5_ADV_NC_t rf_ble_cmd_ble_adv_nc;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* RF Core API Overrides */
|
||||
|
|
|
@ -51,7 +51,7 @@
|
|||
#include DeviceFamily_constructPath(driverlib/rf_mailbox.h)
|
||||
#include DeviceFamily_constructPath(driverlib/rf_common_cmd.h)
|
||||
#include DeviceFamily_constructPath(driverlib/rf_ieee_cmd.h)
|
||||
#include DeviceFamily_constructPath(rf_patches/rf_patch_cpe_ieee_802_15_4.h)
|
||||
#include DeviceFamily_constructPath(rf_patches/rf_patch_cpe_multi_protocol.h)
|
||||
#include DeviceFamily_constructPath(rf_patches/rf_patch_mce_ieee_802_15_4.h)
|
||||
|
||||
#include <ti/drivers/rf/RF.h>
|
||||
|
@ -62,7 +62,7 @@
|
|||
RF_Mode rf_ieee_mode =
|
||||
{
|
||||
.rfMode = RF_MODE_AUTO,
|
||||
.cpePatchFxn = &rf_patch_cpe_ieee_802_15_4,
|
||||
.cpePatchFxn = &rf_patch_cpe_multi_protocol,
|
||||
.mcePatchFxn = &rf_patch_mce_ieee_802_15_4,
|
||||
.rfePatchFxn = 0,
|
||||
};
|
||||
|
@ -180,8 +180,8 @@ rfc_CMD_RADIO_SETUP_t rf_cmd_ieee_radio_setup =
|
|||
.condition.nSkip = 0x0,
|
||||
.mode = 0x01,
|
||||
.loDivider = 0x00,
|
||||
.config.frontEndMode = 0x0,
|
||||
.config.biasMode = 0x0,
|
||||
.config.frontEndMode = 0x0, /* set by driver */
|
||||
.config.biasMode = 0x0, /* set by driver */
|
||||
.config.analogCfgMode = 0x0,
|
||||
.config.bNoFsPowerUp = 0x0,
|
||||
.txPower = DEFAULT_TX_POWER, /* 5 dBm default */
|
||||
|
|
|
@ -63,7 +63,7 @@
|
|||
#include DeviceFamily_constructPath(driverlib/rf_mailbox.h)
|
||||
#include DeviceFamily_constructPath(driverlib/rf_common_cmd.h)
|
||||
#include DeviceFamily_constructPath(driverlib/rf_prop_cmd.h)
|
||||
#include DeviceFamily_constructPath(rf_patches/rf_patch_cpe_prop.h)
|
||||
#include DeviceFamily_constructPath(rf_patches/rf_patch_cpe_multi_protocol.h)
|
||||
#include DeviceFamily_constructPath(rf_patches/rf_patch_rfe_genfsk.h)
|
||||
#include DeviceFamily_constructPath(rf_patches/rf_patch_mce_genfsk.h)
|
||||
|
||||
|
@ -75,7 +75,7 @@
|
|||
RF_Mode rf_prop_mode =
|
||||
{
|
||||
.rfMode = RF_MODE_AUTO,
|
||||
.cpePatchFxn = &rf_patch_cpe_prop,
|
||||
.cpePatchFxn = &rf_patch_cpe_multi_protocol,
|
||||
.mcePatchFxn = &rf_patch_mce_genfsk,
|
||||
.rfePatchFxn = &rf_patch_rfe_genfsk,
|
||||
};
|
||||
|
|
|
@ -55,12 +55,18 @@
|
|||
/* TI-RTOS RF Mode Object */
|
||||
RF_Mode rf_ble_mode =
|
||||
{
|
||||
.rfMode = RF_MODE_BLE,
|
||||
.rfMode = RF_MODE_MULTIPLE,
|
||||
.cpePatchFxn = &rf_patch_cpe_ble,
|
||||
.mcePatchFxn = 0,
|
||||
.rfePatchFxn = &rf_patch_rfe_ble,
|
||||
};
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/*
|
||||
* CMD_RADIO_SETUP must be configured with default TX power value
|
||||
* in the .txPower field.
|
||||
*/
|
||||
#define DEFAULT_TX_POWER 0x9330 /* 5 dBm */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* Overrides for CMD_RADIO_SETUP */
|
||||
uint32_t rf_ble_overrides[] CC_ALIGN(4) =
|
||||
{
|
||||
|
@ -105,46 +111,14 @@ rfc_CMD_RADIO_SETUP_t rf_ble_cmd_radio_setup =
|
|||
.condition.nSkip = 0x0,
|
||||
.mode = 0x00,
|
||||
.__dummy0 = 0x00,
|
||||
.config.frontEndMode = 0x0,
|
||||
.config.biasMode = 0x0,
|
||||
.config.frontEndMode = 0x0, /* set by driver */
|
||||
.config.biasMode = 0x0, /* set by driver */
|
||||
.config.analogCfgMode = 0x0,
|
||||
.config.bNoFsPowerUp = 0x0,
|
||||
.txPower = 0x9330,
|
||||
.txPower = DEFAULT_TX_POWER,
|
||||
.pRegOverride = rf_ble_overrides,
|
||||
};
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* Structure for CMD_BLE_ADV_NC.pParams */
|
||||
rfc_bleAdvPar_t rf_ble_adv_par =
|
||||
{
|
||||
.pRxQ = 0,
|
||||
.rxConfig.bAutoFlushIgnored = 0x0,
|
||||
.rxConfig.bAutoFlushCrcErr = 0x0,
|
||||
.rxConfig.bAutoFlushEmpty = 0x0,
|
||||
.rxConfig.bIncludeLenByte = 0x0,
|
||||
.rxConfig.bIncludeCrc = 0x0,
|
||||
.rxConfig.bAppendRssi = 0x0,
|
||||
.rxConfig.bAppendStatus = 0x0,
|
||||
.rxConfig.bAppendTimestamp = 0x0,
|
||||
.advConfig.advFilterPolicy = 0x0,
|
||||
.advConfig.deviceAddrType = 0x0,
|
||||
.advConfig.peerAddrType = 0x0,
|
||||
.advConfig.bStrictLenFilter = 0x0,
|
||||
.advConfig.rpaMode = 0x0,
|
||||
.advLen = 0x18,
|
||||
.scanRspLen = 0x00,
|
||||
.pAdvData = 0,
|
||||
.pScanRspData = 0,
|
||||
.pDeviceAddress = 0,
|
||||
.pWhiteList = 0,
|
||||
.__dummy0 = 0x0000,
|
||||
.__dummy1 = 0x00,
|
||||
.endTrigger.triggerType = TRIG_NEVER,
|
||||
.endTrigger.bEnaCmd = 0x0,
|
||||
.endTrigger.triggerNo = 0x0,
|
||||
.endTrigger.pastTrig = 0x0,
|
||||
.endTime = 0x00000000,
|
||||
};
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* CMD_BLE_ADV_NC: BLE Non-Connectable Advertiser Command */
|
||||
rfc_CMD_BLE_ADV_NC_t rf_ble_cmd_ble_adv_nc =
|
||||
{
|
||||
|
@ -155,13 +129,13 @@ rfc_CMD_BLE_ADV_NC_t rf_ble_cmd_ble_adv_nc =
|
|||
.startTrigger.triggerType = TRIG_NOW,
|
||||
.startTrigger.bEnaCmd = 0x0,
|
||||
.startTrigger.triggerNo = 0x0,
|
||||
.startTrigger.pastTrig = 0x0,
|
||||
.condition.rule = COND_NEVER,
|
||||
.startTrigger.pastTrig = 0x1,
|
||||
.condition.rule = 0x0, /* set by driver */
|
||||
.condition.nSkip = 0x0,
|
||||
.channel = 0x8C,
|
||||
.whitening.init = 0x51,
|
||||
.channel = 0x00, /* set by driver */
|
||||
.whitening.init = 0x00, /* set by driver */
|
||||
.whitening.bOverride = 0x1,
|
||||
.pParams = &rf_ble_adv_par,
|
||||
.pOutput = 0,
|
||||
.pParams = 0x00000000, /* set by driver */
|
||||
.pOutput = 0x00000000, /* set by driver */
|
||||
};
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
|
|
@ -43,7 +43,6 @@ extern RF_Mode rf_ble_mode;
|
|||
/*---------------------------------------------------------------------------*/
|
||||
/* RF Core API commands */
|
||||
extern rfc_CMD_RADIO_SETUP_t rf_ble_cmd_radio_setup;
|
||||
extern rfc_bleAdvPar_t rf_ble_adv_par;
|
||||
extern rfc_CMD_BLE_ADV_NC_t rf_ble_cmd_ble_adv_nc;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* RF Core API Overrides */
|
||||
|
|
|
@ -53,7 +53,7 @@
|
|||
/* TI-RTOS RF Mode Object */
|
||||
RF_Mode rf_ieee_mode =
|
||||
{
|
||||
.rfMode = RF_MODE_IEEE_15_4,
|
||||
.rfMode = RF_MODE_MULTIPLE,
|
||||
.cpePatchFxn = &rf_patch_cpe_ieee,
|
||||
.mcePatchFxn = 0,
|
||||
.rfePatchFxn = 0,
|
||||
|
@ -107,8 +107,8 @@ rfc_CMD_RADIO_SETUP_t rf_cmd_ieee_radio_setup =
|
|||
.condition.nSkip = 0x0,
|
||||
.mode = 0x01,
|
||||
.__dummy0 = 0x00,
|
||||
.config.frontEndMode = 0x0,
|
||||
.config.biasMode = 0x0,
|
||||
.config.frontEndMode = 0x0, /* set by driver */
|
||||
.config.biasMode = 0x0, /* set by driver */
|
||||
.config.analogCfgMode = 0x0,
|
||||
.config.bNoFsPowerUp = 0x0,
|
||||
.txPower = DEFAULT_TX_POWER, /* 5 dBm default */
|
||||
|
|
|
@ -46,7 +46,7 @@
|
|||
#include DeviceFamily_constructPath(driverlib/rf_mailbox.h)
|
||||
#include DeviceFamily_constructPath(driverlib/rf_common_cmd.h)
|
||||
#include DeviceFamily_constructPath(driverlib/rf_ble_cmd.h)
|
||||
#include DeviceFamily_constructPath(rf_patches/rf_patch_cpe_bt5.h)
|
||||
#include DeviceFamily_constructPath(rf_patches/rf_patch_cpe_multi_protocol.h)
|
||||
#include DeviceFamily_constructPath(rf_patches/rf_patch_rfe_bt5.h)
|
||||
#include DeviceFamily_constructPath(rf_patches/rf_patch_mce_bt5.h)
|
||||
|
||||
|
@ -58,11 +58,17 @@
|
|||
RF_Mode rf_ble_mode =
|
||||
{
|
||||
.rfMode = RF_MODE_AUTO,
|
||||
.cpePatchFxn = &rf_patch_cpe_bt5,
|
||||
.cpePatchFxn = &rf_patch_cpe_multi_protocol,
|
||||
.mcePatchFxn = &rf_patch_mce_bt5,
|
||||
.rfePatchFxn = &rf_patch_rfe_bt5,
|
||||
};
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/*
|
||||
* CMD_RADIO_SETUP must be configured with default TX power value
|
||||
* in the .txPower field.
|
||||
*/
|
||||
#define DEFAULT_TX_POWER 0x941E /* 5 dBm */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* Overrides for CMD_BLE5_RADIO_SETUP */
|
||||
uint32_t rf_ble_overrides_common[] CC_ALIGN(4) =
|
||||
{
|
||||
|
@ -137,71 +143,39 @@ rfc_CMD_BLE5_RADIO_SETUP_t rf_ble_cmd_radio_setup =
|
|||
.defaultPhy.mainMode = 0x0,
|
||||
.defaultPhy.coding = 0x0,
|
||||
.loDivider = 0x00,
|
||||
.config.frontEndMode = 0x0,
|
||||
.config.biasMode = 0x0,
|
||||
.config.frontEndMode = 0x0, /* set by driver */
|
||||
.config.biasMode = 0x0, /* set by driver */
|
||||
.config.analogCfgMode = 0x0,
|
||||
.config.bNoFsPowerUp = 0x0,
|
||||
.txPower = 0x941E,
|
||||
.txPower = DEFAULT_TX_POWER,
|
||||
.pRegOverrideCommon = rf_ble_overrides_common,
|
||||
.pRegOverride1Mbps = rf_ble_overrides_1mbps,
|
||||
.pRegOverride2Mbps = rf_ble_overrides_2mbps,
|
||||
.pRegOverrideCoded = rf_ble_overrides_coded,
|
||||
};
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* Structure for CMD_BLE5_ADV_NC.pParams */
|
||||
rfc_bleAdvPar_t rf_ble_adv_par =
|
||||
{
|
||||
.pRxQ = 0,
|
||||
.rxConfig.bAutoFlushIgnored = 0x0,
|
||||
.rxConfig.bAutoFlushCrcErr = 0x0,
|
||||
.rxConfig.bAutoFlushEmpty = 0x0,
|
||||
.rxConfig.bIncludeLenByte = 0x0,
|
||||
.rxConfig.bIncludeCrc = 0x0,
|
||||
.rxConfig.bAppendRssi = 0x0,
|
||||
.rxConfig.bAppendStatus = 0x0,
|
||||
.rxConfig.bAppendTimestamp = 0x0,
|
||||
.advConfig.advFilterPolicy = 0x0,
|
||||
.advConfig.deviceAddrType = 0x0,
|
||||
.advConfig.peerAddrType = 0x0,
|
||||
.advConfig.bStrictLenFilter = 0x0,
|
||||
.advConfig.rpaMode = 0x0,
|
||||
.advLen = 0x18,
|
||||
.scanRspLen = 0x00,
|
||||
.pAdvData = 0,
|
||||
.pScanRspData = 0,
|
||||
.pDeviceAddress = 0,
|
||||
.pWhiteList = 0,
|
||||
.__dummy0 = 0x0000,
|
||||
.__dummy1 = 0x00,
|
||||
.endTrigger.triggerType = TRIG_NEVER,
|
||||
.endTrigger.bEnaCmd = 0x0,
|
||||
.endTrigger.triggerNo = 0x0,
|
||||
.endTrigger.pastTrig = 0x0,
|
||||
.endTime = 0x00000000,
|
||||
};
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* CMD_BLE5_ADV_NC: Bluetooth 5 Non-Connectable Advertiser Command */
|
||||
rfc_CMD_BLE5_ADV_NC_t rf_ble_cmd_ble_adv_nc =
|
||||
{
|
||||
.commandNo = 0x182D,
|
||||
.status = 0x0000,
|
||||
.pNextOp = 0, // INSERT APPLICABLE POINTER: (uint8_t*)&xxx
|
||||
.commandNo = CMD_BLE5_ADV_NC,
|
||||
.status = IDLE,
|
||||
.pNextOp = 0,
|
||||
.startTime = 0x00000000,
|
||||
.startTrigger.triggerType = 0x0,
|
||||
.startTrigger.triggerType = TRIG_NOW,
|
||||
.startTrigger.bEnaCmd = 0x0,
|
||||
.startTrigger.triggerNo = 0x0,
|
||||
.startTrigger.pastTrig = 0x0,
|
||||
.condition.rule = 0x1,
|
||||
.startTrigger.pastTrig = 0x1,
|
||||
.condition.rule = 0x0, /* set by driver */
|
||||
.condition.nSkip = 0x0,
|
||||
.channel = 0x8C,
|
||||
.whitening.init = 0x51,
|
||||
.channel = 0x00, /* set by driver */
|
||||
.whitening.init = 0x00, /* set by driver */
|
||||
.whitening.bOverride = 0x1,
|
||||
.phyMode.mainMode = 0x0,
|
||||
.phyMode.coding = 0x0,
|
||||
.rangeDelay = 0x00,
|
||||
.txPower = 0x0000,
|
||||
.pParams = &rf_ble_adv_par,
|
||||
.pOutput = 0, // INSERT APPLICABLE POINTER: (uint8_t*)&xxx
|
||||
.pParams = 0x00000000, /* set by driver */
|
||||
.pOutput = 0x00000000, /* set by driver */
|
||||
.tx20Power = 0x00000000,
|
||||
};
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
|
|
@ -43,7 +43,6 @@ extern RF_Mode rf_ble_mode;
|
|||
/*---------------------------------------------------------------------------*/
|
||||
/* RF Core API commands */
|
||||
extern rfc_CMD_BLE5_RADIO_SETUP_t rf_ble_cmd_radio_setup;
|
||||
extern rfc_bleAdvPar_t rf_ble_adv_par;
|
||||
extern rfc_CMD_BLE5_ADV_NC_t rf_ble_cmd_ble_adv_nc;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* RF Core API Overrides */
|
||||
|
|
|
@ -44,7 +44,7 @@
|
|||
#include DeviceFamily_constructPath(driverlib/rf_mailbox.h)
|
||||
#include DeviceFamily_constructPath(driverlib/rf_common_cmd.h)
|
||||
#include DeviceFamily_constructPath(driverlib/rf_ieee_cmd.h)
|
||||
#include DeviceFamily_constructPath(rf_patches/rf_patch_cpe_ieee_802_15_4.h)
|
||||
#include DeviceFamily_constructPath(rf_patches/rf_patch_cpe_multi_protocol.h)
|
||||
#include DeviceFamily_constructPath(rf_patches/rf_patch_mce_ieee_802_15_4.h)
|
||||
|
||||
#include <ti/drivers/rf/RF.h>
|
||||
|
@ -55,7 +55,7 @@
|
|||
RF_Mode rf_ieee_mode =
|
||||
{
|
||||
.rfMode = RF_MODE_AUTO,
|
||||
.cpePatchFxn = &rf_patch_cpe_ieee_802_15_4,
|
||||
.cpePatchFxn = &rf_patch_cpe_multi_protocol,
|
||||
.mcePatchFxn = &rf_patch_mce_ieee_802_15_4,
|
||||
.rfePatchFxn = 0,
|
||||
};
|
||||
|
@ -104,8 +104,8 @@ rfc_CMD_RADIO_SETUP_t rf_cmd_ieee_radio_setup =
|
|||
.condition.nSkip = 0x0,
|
||||
.mode = 0x01,
|
||||
.loDivider = 0x00,
|
||||
.config.frontEndMode = 0x0,
|
||||
.config.biasMode = 0x0,
|
||||
.config.frontEndMode = 0x0, /* set by driver */
|
||||
.config.biasMode = 0x0, /* set by driver */
|
||||
.config.analogCfgMode = 0x0,
|
||||
.config.bNoFsPowerUp = 0x0,
|
||||
.txPower = DEFAULT_TX_POWER,
|
||||
|
|
|
@ -81,7 +81,7 @@ ble_addr_ptr(void)
|
|||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
int
|
||||
ble_addr_cpy(uint8_t *dst)
|
||||
ble_addr_be_cpy(uint8_t *dst)
|
||||
{
|
||||
if(!dst) {
|
||||
return -1;
|
||||
|
@ -102,6 +102,23 @@ ble_addr_cpy(uint8_t *dst)
|
|||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
int
|
||||
ble_addr_le_cpy(uint8_t *dst)
|
||||
{
|
||||
if(!dst) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
volatile const uint8_t *const ble_addr = ble_addr_ptr();
|
||||
|
||||
size_t i;
|
||||
for(i = 0; i < BLE_ADDR_SIZE; i++) {
|
||||
dst[i] = ble_addr[i];
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
int
|
||||
ble_addr_to_eui64(uint8_t *dst, uint8_t *src)
|
||||
{
|
||||
if(!dst || !src) {
|
||||
|
@ -126,7 +143,7 @@ ble_addr_to_eui64_cpy(uint8_t *dst)
|
|||
int res;
|
||||
uint8_t ble_addr[BLE_ADDR_SIZE];
|
||||
|
||||
res = ble_addr_cpy(ble_addr);
|
||||
res = ble_addr_le_cpy(ble_addr);
|
||||
if(res) {
|
||||
return -1;
|
||||
}
|
||||
|
|
|
@ -59,6 +59,7 @@ uint8_t *ble_addr_ptr(void);
|
|||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \brief Copy the node's factory BLE address to a destination memory area
|
||||
* in big-endian (be) order.
|
||||
* \param dst A pointer to the destination area where the BLE address is to be
|
||||
* written
|
||||
* \return 0 : Returned successfully
|
||||
|
@ -68,7 +69,21 @@ uint8_t *ble_addr_ptr(void);
|
|||
* the process. The factory address on devices is normally little-endian,
|
||||
* therefore you should expect dst to store the address in a big-endian order.
|
||||
*/
|
||||
int ble_addr_cpy(uint8_t *dst);
|
||||
int ble_addr_be_cpy(uint8_t *dst);
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \brief Copy the node's factory BLE address to a destination memory area
|
||||
* in little-endian (le) order.
|
||||
* \param dst A pointer to the destination area where the BLE address is to be
|
||||
* written
|
||||
* \return 0 : Returned successfully
|
||||
* -1 : Returned with error
|
||||
*
|
||||
* This function will copy 6 bytes, but will **not** invert the byte order.
|
||||
* This is usefull for the RF core which assumes the BLE MAC address in
|
||||
* little-endian order.
|
||||
*/
|
||||
int ble_addr_le_cpy(uint8_t *dst);
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \brief Copy the node's BLE address to a destination memory area and converts
|
||||
|
|
|
@ -52,6 +52,7 @@
|
|||
|
||||
#include <ti/drivers/rf/RF.h>
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include "rf/rf.h"
|
||||
#include "rf/sched.h"
|
||||
#include "rf/ble-addr.h"
|
||||
#include "rf/ble-beacond.h"
|
||||
|
@ -70,32 +71,58 @@
|
|||
/*---------------------------------------------------------------------------*/
|
||||
#if RF_CONF_BLE_BEACON_ENABLE
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* BLE Advertisement channels. Not to be changed by the user. */
|
||||
typedef enum {
|
||||
BLE_ADV_CHANNEL_37 = (1 << 0),
|
||||
BLE_ADV_CHANNEL_38 = (1 << 1),
|
||||
BLE_ADV_CHANNEL_39 = (1 << 2),
|
||||
|
||||
BLE_ADV_CHANNEL_ALL = (BLE_ADV_CHANNEL_37 |
|
||||
BLE_ADV_CHANNEL_38 |
|
||||
BLE_ADV_CHANNEL_39),
|
||||
} ble_adv_channel_t;
|
||||
|
||||
#define BLE_ADV_CHANNEL_MIN 37
|
||||
#define BLE_ADV_CHANNEL_MAX 39
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* Maximum BLE advertisement size. Not to be changed by the user. */
|
||||
#define BLE_ADV_MAX_SIZE 31
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* BLE Intervals: Send a burst of advertisements every BLE_ADV_INTERVAL secs */
|
||||
#define BLE_ADV_INTERVAL (CLOCK_SECOND * 5)
|
||||
#define BLE_ADV_DUTY_CYCLE (CLOCK_SECOND / 10)
|
||||
#define BLE_ADV_MESSAGES 10
|
||||
/*
|
||||
* BLE Intervals: Send a burst of advertisements every BLE_ADV_INTERVAL
|
||||
* specified in milliseconds.
|
||||
*/
|
||||
#define BLE_ADV_INTERVAL ((100 * CLOCK_SECOND) / 1000)
|
||||
|
||||
/* GAP Advertisement data types */
|
||||
#define BLE_ADV_TYPE_FLAGS 0x01
|
||||
#define BLE_ADV_TYPE_16BIT_MORE 0x02
|
||||
#define BLE_ADV_TYPE_16BIT_COMPLETE 0x03
|
||||
#define BLE_ADV_TYPE_32BIT_MORE 0x04
|
||||
#define BLE_ADV_TYPE_32BIT_COMPLETE 0x05
|
||||
#define BLE_ADV_TYPE_128BIT_MORE 0x06
|
||||
#define BLE_ADV_TYPE_128BIT_COMPLETE 0x07
|
||||
#define BLE_ADV_TYPE_LOCAL_NAME_SHORT 0x08
|
||||
#define BLE_ADV_TYPE_LOCAL_NAME_COMPLETE 0x09
|
||||
#define BLE_ADV_TYPE_POWER_LEVEL 0x0A
|
||||
#define BLE_ADV_TYPE_OOB_CLASS_OF_DEVICE 0x0D
|
||||
#define BLE_ADV_TYPE_OOB_SIMPLE_PAIRING_HASHC 0x0E
|
||||
#define BLE_ADV_TYPE_OOB_SIMPLE_PAIRING_RANDR 0x0F
|
||||
#define BLE_ADV_TYPE_SM_TK 0x10
|
||||
#define BLE_ADV_TYPE_SM_OOB_FLAG 0x11
|
||||
#define BLE_ADV_TYPE_SLAVE_CONN_INTERVAL_RANGE 0x12
|
||||
#define BLE_ADV_TYPE_SIGNED_DATA 0x13
|
||||
#define BLE_ADV_TYPE_SERVICE_LIST_16BIT 0x14
|
||||
#define BLE_ADV_TYPE_SERVICE_LIST_128BIT 0x15
|
||||
#define BLE_ADV_TYPE_SERVICE_DATA 0x16
|
||||
#define BLE_ADV_TYPE_PUBLIC_TARGET_ADDR 0x17
|
||||
#define BLE_ADV_TYPE_RANDOM_TARGET_ADDR 0x18
|
||||
#define BLE_ADV_TYPE_APPEARANCE 0x19
|
||||
#define BLE_ADV_TYPE_ADV_INTERVAL 0x1A
|
||||
#define BLE_ADV_TYPE_LE_BD_ADDR 0x1B
|
||||
#define BLE_ADV_TYPE_LE_ROLE 0x1C
|
||||
#define BLE_ADV_TYPE_SIMPLE_PAIRING_HASHC_256 0x1D
|
||||
#define BLE_ADV_TYPE_SIMPLE_PAIRING_RANDR_256 0x1E
|
||||
#define BLE_ADV_TYPE_SERVICE_DATA_32BIT 0x20
|
||||
#define BLE_ADV_TYPE_SERVICE_DATA_128BIT 0x21
|
||||
#define BLE_ADV_TYPE_3D_INFO_DATA 0x3D
|
||||
#define BLE_ADV_TYPE_MANUFACTURER_SPECIFIC 0xFF
|
||||
|
||||
/* GAP Advertisement data type flags */
|
||||
|
||||
/* Discovery Mode: LE Limited Discoverable Mode */
|
||||
#define BLE_ADV_TYPE_FLAGS_LIMITED 0x01
|
||||
/* Discovery Mode: LE General Discoverable Mode */
|
||||
#define BLE_ADV_TYPE_FLAGS_GENERAL 0x02
|
||||
/* Discovery Mode: BR/EDR Not Supported */
|
||||
#define BLE_ADV_TYPE_FLAGS_BREDR_NOT_SUPPORTED 0x04
|
||||
|
||||
/* BLE Advertisement-related macros */
|
||||
#define BLE_ADV_TYPE_DEVINFO 0x01
|
||||
#define BLE_ADV_TYPE_NAME 0x09
|
||||
#define BLE_ADV_TYPE_MANUFACTURER 0xFF
|
||||
#define BLE_ADV_NAME_BUF_LEN BLE_ADV_MAX_SIZE
|
||||
#define BLE_ADV_PAYLOAD_BUF_LEN 64
|
||||
#define BLE_UUID_SIZE 16
|
||||
|
@ -117,6 +144,11 @@ typedef struct {
|
|||
|
||||
/* RF driver */
|
||||
RF_Handle rf_handle;
|
||||
|
||||
/* BLE command specific structures. Common accross BLE and BLE5. */
|
||||
uint8_t ble_mac_addr[6];
|
||||
rfc_bleAdvPar_t ble_adv_par;
|
||||
rfc_bleAdvOutput_t ble_adv_output;
|
||||
} ble_beacond_t;
|
||||
|
||||
static ble_beacond_t ble_beacond;
|
||||
|
@ -126,13 +158,13 @@ PROCESS(ble_beacond_process, "RF BLE Beacon Daemon Process");
|
|||
rf_ble_beacond_result_t
|
||||
rf_ble_beacond_init(void)
|
||||
{
|
||||
ble_adv_par.pDeviceAddress = (uint16_t *)ble_addr_ptr();
|
||||
ble_cmd_radio_setup.config.frontEndMode = RF_2_4_GHZ_FRONT_END_MODE;
|
||||
ble_cmd_radio_setup.config.biasMode = RF_2_4_GHZ_BIAS_MODE;
|
||||
|
||||
RF_Params rf_params;
|
||||
RF_Params_init(&rf_params);
|
||||
|
||||
/* Should immediately turn off radio if possible */
|
||||
rf_params.nInactivityTimeout = 0;
|
||||
rf_params.nInactivityTimeout = RF_CONF_INACTIVITY_TIMEOUT;
|
||||
|
||||
ble_beacond.rf_handle = ble_open(&rf_params);
|
||||
|
||||
|
@ -140,6 +172,18 @@ rf_ble_beacond_init(void)
|
|||
return RF_BLE_BEACOND_ERROR;
|
||||
}
|
||||
|
||||
/*
|
||||
* It is important that the contents of the BLE MAC address is copied into
|
||||
* RAM, as the System CPU, and subsequently flash, goes idle when pending
|
||||
* on an RF command. This causes pend to hang forever.
|
||||
*/
|
||||
ble_addr_le_cpy(ble_beacond.ble_mac_addr);
|
||||
ble_beacond.ble_adv_par.pDeviceAddress = (uint16_t *)ble_beacond.ble_mac_addr;
|
||||
ble_beacond.ble_adv_par.endTrigger.triggerType = TRIG_NEVER;
|
||||
|
||||
rf_ble_cmd_ble_adv_nc.pParams = &ble_beacond.ble_adv_par;
|
||||
rf_ble_cmd_ble_adv_nc.pOutput = &ble_beacond.ble_adv_output;
|
||||
|
||||
return RF_BLE_BEACOND_OK;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
@ -154,12 +198,14 @@ rf_ble_beacond_config(clock_time_t interval, const char *name)
|
|||
ble_beacond.ble_adv_interval = interval;
|
||||
|
||||
res = RF_BLE_BEACOND_OK;
|
||||
} else {
|
||||
ble_beacond.ble_adv_interval = BLE_ADV_INTERVAL;
|
||||
}
|
||||
|
||||
if(name != NULL) {
|
||||
const size_t name_len = strlen(name);
|
||||
|
||||
if((name_len == 0) || (name_len >= BLE_ADV_NAME_BUF_LEN)) {
|
||||
if((0 < name_len) && (name_len < BLE_ADV_NAME_BUF_LEN)) {
|
||||
ble_beacond.adv_name_len = name_len;
|
||||
memcpy(ble_beacond.adv_name, name, name_len);
|
||||
|
||||
|
@ -235,37 +281,9 @@ rf_ble_get_tx_power(void)
|
|||
return dbm;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static rf_ble_beacond_result_t
|
||||
ble_beacon_burst(uint8_t channels_bm, uint8_t *data, uint8_t len)
|
||||
{
|
||||
rf_result_t res;
|
||||
|
||||
uint8_t channel;
|
||||
for(channel = BLE_ADV_CHANNEL_MIN; channel <= BLE_ADV_CHANNEL_MAX; ++channel) {
|
||||
const uint8_t channel_bv = (1 << (channel - BLE_ADV_CHANNEL_MIN));
|
||||
if((channel_bv & channels_bm) == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ble_adv_par.advLen = len;
|
||||
ble_adv_par.pAdvData = data;
|
||||
|
||||
ble_cmd_beacon.channel = channel;
|
||||
|
||||
res = ble_sched_beacon(NULL, 0);
|
||||
|
||||
if(res != RF_RESULT_OK) {
|
||||
return RF_BLE_BEACOND_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
return RF_BLE_BEACOND_OK;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS_THREAD(ble_beacond_process, ev, data)
|
||||
{
|
||||
static size_t i;
|
||||
static size_t len;
|
||||
size_t len;
|
||||
|
||||
PROCESS_BEGIN();
|
||||
|
||||
|
@ -278,30 +296,33 @@ PROCESS_THREAD(ble_beacond_process, ev, data)
|
|||
PROCESS_EXIT();
|
||||
}
|
||||
|
||||
/* Device info */
|
||||
/* Set the adv payload each pass: The device name may have changed */
|
||||
len = 0;
|
||||
|
||||
/* Device info */
|
||||
ble_beacond.tx_buf[len++] = (uint8_t)0x02; /* 2 bytes */
|
||||
ble_beacond.tx_buf[len++] = (uint8_t)BLE_ADV_TYPE_DEVINFO;
|
||||
ble_beacond.tx_buf[len++] = (uint8_t)0x1A; /* LE general discoverable + BR/EDR */
|
||||
ble_beacond.tx_buf[len++] = (uint8_t)ble_beacond.adv_name_len;
|
||||
ble_beacond.tx_buf[len++] = (uint8_t)BLE_ADV_TYPE_NAME;
|
||||
#define append_byte(x) ble_beacond.tx_buf[len++] = (uint8_t)((x))
|
||||
|
||||
/* 2 bytes */
|
||||
append_byte(2);
|
||||
append_byte(BLE_ADV_TYPE_FLAGS);
|
||||
/* LE general discoverable + BR/EDR not supported */
|
||||
append_byte(BLE_ADV_TYPE_FLAGS_GENERAL |
|
||||
BLE_ADV_TYPE_FLAGS_BREDR_NOT_SUPPORTED);
|
||||
|
||||
/* 1 + len(name) bytes (excluding zero termination) */
|
||||
append_byte(1 + ble_beacond.adv_name_len);
|
||||
append_byte(BLE_ADV_TYPE_LOCAL_NAME_COMPLETE);
|
||||
|
||||
memcpy(ble_beacond.tx_buf + len, ble_beacond.adv_name, ble_beacond.adv_name_len);
|
||||
len += ble_beacond.adv_name_len;
|
||||
|
||||
/*
|
||||
* Send BLE_ADV_MESSAGES beacon bursts. Each burst on all three
|
||||
* channels, with a BLE_ADV_DUTY_CYCLE interval between bursts
|
||||
*/
|
||||
ble_beacon_burst(BLE_ADV_CHANNEL_ALL, ble_beacond.tx_buf, len);
|
||||
for(i = 1; i < BLE_ADV_MESSAGES; ++i) {
|
||||
etimer_set(&ble_beacond.ble_adv_et, BLE_ADV_DUTY_CYCLE);
|
||||
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&ble_beacond.ble_adv_et));
|
||||
#undef append_byte
|
||||
|
||||
ble_beacon_burst(BLE_ADV_CHANNEL_ALL, ble_beacond.tx_buf, len);
|
||||
}
|
||||
/* Send advertisements on all three channels */
|
||||
ble_beacond.ble_adv_par.advLen = len;
|
||||
ble_beacond.ble_adv_par.pAdvData = ble_beacond.tx_buf;
|
||||
|
||||
ble_sched_beacons(BLE_ADV_CHANNEL_ALL);
|
||||
}
|
||||
PROCESS_END();
|
||||
}
|
||||
|
|
|
@ -217,6 +217,9 @@ rat_overflow_cb(void *arg)
|
|||
static void
|
||||
init_rf_params(void)
|
||||
{
|
||||
cmd_radio_setup.config.frontEndMode = RF_2_4_GHZ_FRONT_END_MODE;
|
||||
cmd_radio_setup.config.biasMode = RF_2_4_GHZ_BIAS_MODE;
|
||||
|
||||
data_queue_t *rx_q = data_queue_init(sizeof(lensz_t));
|
||||
|
||||
cmd_rx.pRxQ = rx_q;
|
||||
|
@ -550,32 +553,42 @@ read(void *buf, unsigned short buf_len)
|
|||
static rf_result_t
|
||||
cca_request(cmd_cca_req_t *cmd_cca_req)
|
||||
{
|
||||
RF_Stat stat = RF_StatRadioInactiveError;
|
||||
rf_result_t res;
|
||||
bool stop_rx = false;
|
||||
|
||||
const bool rx_is_idle = !rx_is_active();
|
||||
/* RX is required to be running in order to do a CCA request */
|
||||
if(!rx_is_active()) {
|
||||
/* If RX is not pending, i.e. soon to be running, schedule the RX command */
|
||||
if(cmd_rx.status != PENDING) {
|
||||
res = netstack_sched_rx(false);
|
||||
if(res != RF_RESULT_OK) {
|
||||
LOG_ERR("CCA request failed to schedule RX\n");
|
||||
return res;
|
||||
}
|
||||
|
||||
if(rx_is_idle) {
|
||||
res = netstack_sched_rx(false);
|
||||
if(res != RF_RESULT_OK) {
|
||||
/* We only stop RX if we had to schedule it */
|
||||
stop_rx = true;
|
||||
}
|
||||
|
||||
/* Make sure RX is running before we continue, unless we timeout and fail */
|
||||
RTIMER_BUSYWAIT_UNTIL(!rx_is_active(), TIMEOUT_ENTER_RX_WAIT);
|
||||
|
||||
if(!rx_is_active()) {
|
||||
LOG_ERR("CCA request failed to turn on RX, RX status=0x%04X\n", cmd_rx.status);
|
||||
return RF_RESULT_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
const rtimer_clock_t t0 = RTIMER_NOW();
|
||||
while((cmd_rx.status != ACTIVE) &&
|
||||
RTIMER_CLOCK_LT(RTIMER_NOW(), t0 + TIMEOUT_ENTER_RX_WAIT)) ;
|
||||
/* Perform the CCA request */
|
||||
stat = RF_runImmediateCmd(ieee_radio.rf_handle, (uint32_t *)&cmd_cca_req);
|
||||
|
||||
RF_Stat stat = RF_StatRadioInactiveError;
|
||||
if(rx_is_active()) {
|
||||
stat = RF_runImmediateCmd(ieee_radio.rf_handle, (uint32_t *)&cmd_cca_req);
|
||||
}
|
||||
|
||||
if(rx_is_idle) {
|
||||
if(stop_rx) {
|
||||
netstack_stop_rx();
|
||||
}
|
||||
|
||||
if(stat != RF_StatCmdDoneSuccess) {
|
||||
LOG_ERR("CCA request failed, stat=0x%02X\n", stat);
|
||||
LOG_ERR("CCA request command failed, stat=0x%02X\n", stat);
|
||||
return RF_RESULT_ERROR;
|
||||
}
|
||||
|
||||
|
|
|
@ -61,6 +61,7 @@
|
|||
#include <ti/drivers/rf/RF.h>
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* Platform RF dev */
|
||||
#include "rf/rf.h"
|
||||
#include "rf/dot-15-4g.h"
|
||||
#include "rf/sched.h"
|
||||
#include "rf/data-queue.h"
|
||||
|
@ -193,6 +194,8 @@ static int off(void);
|
|||
static void
|
||||
init_rf_params(void)
|
||||
{
|
||||
cmd_radio_setup.config.frontEndMode = RF_SUB_1_GHZ_FRONT_END_MODE;
|
||||
cmd_radio_setup.config.biasMode = RF_SUB_1_GHZ_BIAS_MODE;
|
||||
cmd_radio_setup.centerFreq = PROP_MODE_CENTER_FREQ;
|
||||
cmd_radio_setup.loDivider = PROP_MODE_LO_DIVIDER;
|
||||
|
||||
|
@ -207,26 +210,36 @@ static int8_t
|
|||
get_rssi(void)
|
||||
{
|
||||
rf_result_t res;
|
||||
bool stop_rx = false;
|
||||
int8_t rssi = RF_GET_RSSI_ERROR_VAL;
|
||||
|
||||
const bool rx_is_idle = !rx_is_active();
|
||||
/* RX is required to be running in order to do a RSSI measurement */
|
||||
if(!rx_is_active()) {
|
||||
/* If RX is not pending, i.e. soon to be running, schedule the RX command */
|
||||
if(cmd_rx.status != PENDING) {
|
||||
res = netstack_sched_rx(false);
|
||||
if(res != RF_RESULT_OK) {
|
||||
LOG_ERR("RSSI measurement failed to schedule RX\n");
|
||||
return res;
|
||||
}
|
||||
|
||||
if(rx_is_idle) {
|
||||
res = netstack_sched_rx(false);
|
||||
if(res != RF_RESULT_OK) {
|
||||
return RF_GET_RSSI_ERROR_VAL;
|
||||
/* We only stop RX if we had to schedule it */
|
||||
stop_rx = true;
|
||||
}
|
||||
|
||||
/* Make sure RX is running before we continue, unless we timeout and fail */
|
||||
RTIMER_BUSYWAIT_UNTIL(!rx_is_active(), TIMEOUT_ENTER_RX_WAIT);
|
||||
|
||||
if(!rx_is_active()) {
|
||||
LOG_ERR("RSSI measurement failed to turn on RX, RX status=0x%04X\n", cmd_rx.status);
|
||||
return RF_RESULT_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
const rtimer_clock_t t0 = RTIMER_NOW();
|
||||
while((cmd_rx.status != ACTIVE) &&
|
||||
RTIMER_CLOCK_LT(RTIMER_NOW(), t0 + TIMEOUT_ENTER_RX_WAIT)) ;
|
||||
/* Perform the RSSI measurement */
|
||||
rssi = RF_getRssi(prop_radio.rf_handle);
|
||||
|
||||
int8_t rssi = RF_GET_RSSI_ERROR_VAL;
|
||||
if(rx_is_active()) {
|
||||
rssi = RF_getRssi(prop_radio.rf_handle);
|
||||
}
|
||||
|
||||
if(rx_is_idle) {
|
||||
if(stop_rx) {
|
||||
netstack_stop_rx();
|
||||
}
|
||||
|
||||
|
|
|
@ -60,6 +60,37 @@
|
|||
RF_MODE_2_4_GHZ)
|
||||
/** @} */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \name The different front-end modes the CC13xx/CC26xx devices support. The
|
||||
* front-end mode can be configured independently of the bias mode. The
|
||||
* two types of modes are as follows:
|
||||
* - Differential: Both RF_P and RF_N are used as a differential RF
|
||||
* interface.
|
||||
* - Single ended: Either the RF_P pin or the RF_N pin is used as the
|
||||
* RF path.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
/* Available front-end mode configurations */
|
||||
#define RF_FRONT_END_MODE_DIFFERENTIAL 0
|
||||
#define RF_FRONT_END_MODE_SINGLE_ENDED_RFP 1
|
||||
#define RF_FRONT_END_MODE_SINGLE_ENDED_RFN 2
|
||||
/** @} */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \name The different bias modes the CC13xx/CC26xx devices support. The
|
||||
* bias mode can be configured independently of the front-end mode. The
|
||||
* two different modes are as follows:
|
||||
* - Internal bias: the LNA is biased by an internal bias.
|
||||
* - External bias: the LNA is biased by an external bias.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
/* Available bias mode configurations */
|
||||
#define RF_BIAS_MODE_INTERNAL 0
|
||||
#define RF_BIAS_MODE_EXTERNAL 1
|
||||
/** @} */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#endif /* RF_CORE_H_ */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
|
|
|
@ -51,6 +51,7 @@
|
|||
#include <ti/devices/DeviceFamily.h>
|
||||
#include DeviceFamily_constructPath(driverlib/rf_common_cmd.h)
|
||||
#include DeviceFamily_constructPath(driverlib/rf_mailbox.h)
|
||||
#include DeviceFamily_constructPath(driverlib/rf_ble_mailbox.h)
|
||||
|
||||
#include <ti/drivers/rf/RF.h>
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
@ -68,8 +69,6 @@
|
|||
#define LOG_MODULE "Radio"
|
||||
#define LOG_LEVEL LOG_LEVEL_NONE
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* Configuration parameters */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#define CMD_FS_RETRIES 3
|
||||
|
||||
#define RF_EVENTS_CMD_DONE (RF_EventCmdDone | RF_EventLastCmdDone | \
|
||||
|
@ -82,6 +81,13 @@
|
|||
|
||||
#define EVENTS_CMD_DONE(events) (((events) & RF_EVENTS_CMD_DONE) != 0)
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* BLE advertisement channel range (inclusive) */
|
||||
#define BLE_ADV_CHANNEL_MIN 37
|
||||
#define BLE_ADV_CHANNEL_MAX 39
|
||||
|
||||
/* Number of BLE advertisement channels */
|
||||
#define NUM_BLE_ADV_CHANNELS (BLE_ADV_CHANNEL_MAX - BLE_ADV_CHANNEL_MIN + 1)
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* Synth re-calibration every 3 minutes */
|
||||
#define SYNTH_RECAL_INTERVAL (CLOCK_SECOND * 60 * 3)
|
||||
/* Set re-calibration interval with a jitter of 10 seconds */
|
||||
|
@ -89,6 +95,12 @@
|
|||
|
||||
static struct etimer synth_recal_timer;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#if (DeviceFamily_PARENT == DeviceFamily_PARENT_CC13X0_CC26X0)
|
||||
typedef rfc_CMD_BLE_ADV_NC_t ble_cmd_adv_nc_t;
|
||||
#elif (DeviceFamily_PARENT == DeviceFamily_PARENT_CC13X2_CC26X2)
|
||||
typedef rfc_CMD_BLE5_ADV_NC_t ble_cmd_adv_nc_t;
|
||||
#endif
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static RF_Object rf_netstack;
|
||||
|
||||
#if RF_CONF_BLE_BEACON_ENABLE
|
||||
|
@ -479,45 +491,171 @@ ble_open(RF_Params *params)
|
|||
#endif
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#if RF_CONF_BLE_BEACON_ENABLE
|
||||
static RF_Op *
|
||||
init_ble_adv_array(ble_cmd_adv_nc_t *ble_adv_array, uint8_t bm_channel)
|
||||
{
|
||||
RF_Op *first_ble_adv = NULL;
|
||||
ble_cmd_adv_nc_t *cmd_adv_37 = &ble_adv_array[0];
|
||||
ble_cmd_adv_nc_t *cmd_adv_38 = &ble_adv_array[1];
|
||||
ble_cmd_adv_nc_t *cmd_adv_39 = &ble_adv_array[2];
|
||||
|
||||
/* Setup channel 37 advertisement if enabled */
|
||||
if(bm_channel & BLE_ADV_CHANNEL_37) {
|
||||
/* Default configurations from ble_cmd_adv_nc */
|
||||
memcpy(cmd_adv_37, &ble_cmd_adv_nc, sizeof(ble_cmd_adv_nc));
|
||||
|
||||
cmd_adv_37->channel = 37;
|
||||
/* Magic number: initialization for whitener, specific for channel 37 */
|
||||
cmd_adv_37->whitening.init = 0x65;
|
||||
|
||||
/*
|
||||
* The next advertisement is chained depending on whether they are
|
||||
* enbled or not. If both 38 and 39 are disabled, then there is no
|
||||
* chaining.
|
||||
*/
|
||||
if(bm_channel & BLE_ADV_CHANNEL_38) {
|
||||
cmd_adv_37->pNextOp = (RF_Op *)cmd_adv_38;
|
||||
cmd_adv_37->condition.rule = COND_ALWAYS;
|
||||
} else if(bm_channel & BLE_ADV_CHANNEL_39) {
|
||||
cmd_adv_37->pNextOp = (RF_Op *)cmd_adv_39;
|
||||
cmd_adv_37->condition.rule = COND_ALWAYS;
|
||||
} else {
|
||||
cmd_adv_37->pNextOp = NULL;
|
||||
cmd_adv_37->condition.rule = COND_NEVER;
|
||||
}
|
||||
|
||||
/* Channel 37 will always be first if enabled */
|
||||
first_ble_adv = (RF_Op *)cmd_adv_37;
|
||||
}
|
||||
|
||||
/* Setup channel 38 advertisement if enabled */
|
||||
if(bm_channel & BLE_ADV_CHANNEL_38) {
|
||||
memcpy(cmd_adv_38, &ble_cmd_adv_nc, sizeof(ble_cmd_adv_nc));
|
||||
|
||||
cmd_adv_38->channel = 38;
|
||||
/* Magic number: initialization for whitener, specific for channel 38 */
|
||||
cmd_adv_38->whitening.init = 0x66;
|
||||
|
||||
/*
|
||||
* The next advertisement is chained depending on whether they are
|
||||
* enbled or not. If 39 is disabled, then there is no chaining.
|
||||
*/
|
||||
if(bm_channel & BLE_ADV_CHANNEL_39) {
|
||||
cmd_adv_38->pNextOp = (RF_Op *)cmd_adv_39;
|
||||
cmd_adv_38->condition.rule = COND_ALWAYS;
|
||||
} else {
|
||||
cmd_adv_38->pNextOp = NULL;
|
||||
cmd_adv_38->condition.rule = COND_NEVER;
|
||||
}
|
||||
|
||||
/*
|
||||
* Channel 38 is only first if the first_ble_adv pointer is not
|
||||
* set by channel 37.
|
||||
*/
|
||||
if(first_ble_adv == NULL) {
|
||||
first_ble_adv = (RF_Op *)cmd_adv_38;
|
||||
}
|
||||
}
|
||||
|
||||
/* Setup channel 39 advertisement if enabled */
|
||||
if(bm_channel & BLE_ADV_CHANNEL_39) {
|
||||
memcpy(cmd_adv_39, &ble_cmd_adv_nc, sizeof(ble_cmd_adv_nc));
|
||||
|
||||
cmd_adv_39->channel = 39;
|
||||
/* Magic number: initialization for whitener, specific for channel 39 */
|
||||
cmd_adv_39->whitening.init = 0x67;
|
||||
|
||||
/* Channel 39 is always the last advertisement in the chain */
|
||||
cmd_adv_39->pNextOp = NULL;
|
||||
cmd_adv_39->condition.rule = COND_NEVER;
|
||||
|
||||
/*
|
||||
* Channel 39 is only first if the first_ble_adv pointer is not
|
||||
* set by channel 37 or channel 38.
|
||||
*/
|
||||
if(first_ble_adv == NULL) {
|
||||
first_ble_adv = (RF_Op *)cmd_adv_39;
|
||||
}
|
||||
}
|
||||
|
||||
return first_ble_adv;
|
||||
}
|
||||
#endif /* RF_CONF_BLE_BEACON_ENABLE */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
rf_result_t
|
||||
ble_sched_beacon(RF_Callback cb, RF_EventMask bm_event)
|
||||
ble_sched_beacons(uint8_t bm_channel)
|
||||
{
|
||||
#if RF_CONF_BLE_BEACON_ENABLE
|
||||
RF_ScheduleCmdParams sched_params;
|
||||
RF_ScheduleCmdParams_init(&sched_params);
|
||||
/*
|
||||
* Allocate the advertisement commands on the stack rather than statically
|
||||
* to RAM in order to save space. We don't need them after the
|
||||
* advertisements have been transmitted.
|
||||
*/
|
||||
ble_cmd_adv_nc_t ble_cmd_adv_nc_array[NUM_BLE_ADV_CHANNELS];
|
||||
|
||||
RF_Op *initial_adv = NULL;
|
||||
RF_ScheduleCmdParams sched_params;
|
||||
RF_CmdHandle beacon_handle;
|
||||
RF_EventMask beacon_events;
|
||||
rf_result_t rf_result;
|
||||
|
||||
/* If no channels are mapped, then early return OK */
|
||||
if((bm_channel & BLE_ADV_CHANNEL_ALL) == 0) {
|
||||
return RF_RESULT_OK;
|
||||
}
|
||||
|
||||
initial_adv = init_ble_adv_array(ble_cmd_adv_nc_array, bm_channel);
|
||||
|
||||
if(initial_adv == NULL) {
|
||||
LOG_ERR("Initializing BLE Advertisement chain failed\n");
|
||||
return RF_RESULT_ERROR;
|
||||
}
|
||||
|
||||
RF_ScheduleCmdParams_init(&sched_params);
|
||||
sched_params.priority = RF_PriorityNormal;
|
||||
sched_params.endTime = 0;
|
||||
sched_params.allowDelay = RF_AllowDelayAny;
|
||||
|
||||
CMD_STATUS(ble_cmd_beacon) = PENDING;
|
||||
|
||||
RF_CmdHandle beacon_handle = RF_scheduleCmd(
|
||||
&rf_ble,
|
||||
(RF_Op *)&ble_cmd_beacon,
|
||||
&sched_params,
|
||||
cb,
|
||||
bm_event);
|
||||
/*
|
||||
* The most efficient way to schedule the command is as follows:
|
||||
* 1. Schedule the BLE advertisement chain
|
||||
* 2. Reschedule the RX command IF it was running.
|
||||
* 3. Pend on the BLE avertisement chain
|
||||
*/
|
||||
beacon_handle = RF_scheduleCmd(
|
||||
&rf_ble,
|
||||
initial_adv,
|
||||
&sched_params,
|
||||
NULL,
|
||||
0);
|
||||
|
||||
if(!CMD_HANDLE_OK(beacon_handle)) {
|
||||
LOG_ERR("Unable to schedule BLE Beacon command, handle=%d status=0x%04x\n",
|
||||
beacon_handle, CMD_STATUS(ble_cmd_beacon));
|
||||
beacon_handle, CMD_STATUS(ble_cmd_adv_nc));
|
||||
|
||||
return RF_RESULT_ERROR;
|
||||
}
|
||||
|
||||
const uint_fast8_t rx_key = cmd_rx_disable();
|
||||
/* Note that this only reschedules RX if it is running */
|
||||
rf_result = cmd_rx_restore(cmd_rx_disable());
|
||||
|
||||
/* Wait until Beacon operation finishes */
|
||||
RF_EventMask beacon_events = RF_pendCmd(&rf_ble, beacon_handle, 0);
|
||||
if(!EVENTS_CMD_DONE(beacon_events)) {
|
||||
LOG_ERR("Pending on scheduled BLE Beacon command generated error, events=0x%08llx status=0x%04x\n",
|
||||
beacon_events, CMD_STATUS(ble_cmd_beacon));
|
||||
beacon_events = RF_pendCmd(&rf_ble, beacon_handle, 0);
|
||||
|
||||
if(rf_result != RF_RESULT_OK) {
|
||||
LOG_ERR("Rescheduling CMD_RX failed when BLE advertising\n");
|
||||
|
||||
return RF_RESULT_ERROR;
|
||||
}
|
||||
|
||||
if(!EVENTS_CMD_DONE(beacon_events)) {
|
||||
LOG_ERR("Pending on scheduled BLE Beacon command generated error, events=0x%08llx status=0x%04x\n",
|
||||
beacon_events, CMD_STATUS(ble_cmd_adv_nc));
|
||||
|
||||
cmd_rx_restore(rx_key);
|
||||
return RF_RESULT_ERROR;
|
||||
}
|
||||
|
||||
cmd_rx_restore(rx_key);
|
||||
return RF_RESULT_OK;
|
||||
|
||||
#else
|
||||
|
|
|
@ -58,6 +58,16 @@ typedef enum {
|
|||
RF_RESULT_ERROR,
|
||||
} rf_result_t;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
typedef enum {
|
||||
BLE_ADV_CHANNEL_37 = (1 << 0),
|
||||
BLE_ADV_CHANNEL_38 = (1 << 1),
|
||||
BLE_ADV_CHANNEL_39 = (1 << 2),
|
||||
|
||||
BLE_ADV_CHANNEL_ALL = (BLE_ADV_CHANNEL_37 |
|
||||
BLE_ADV_CHANNEL_38 |
|
||||
BLE_ADV_CHANNEL_39),
|
||||
} ble_adv_channel_t;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \name Common RF scheduler functionality.
|
||||
*
|
||||
|
@ -91,7 +101,7 @@ rf_result_t netstack_stop_rx(void);
|
|||
* @{
|
||||
*/
|
||||
RF_Handle ble_open(RF_Params *params);
|
||||
rf_result_t ble_sched_beacon(RF_Callback cb, RF_EventMask bm_event);
|
||||
rf_result_t ble_sched_beacons(uint8_t bm_adv_channel);
|
||||
/** @} */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#endif /* RF_SCHED_H_ */
|
||||
|
|
|
@ -89,7 +89,7 @@
|
|||
#define ble_mode rf_ble_mode
|
||||
#define ble_cmd_radio_setup rf_ble_cmd_radio_setup
|
||||
#define ble_adv_par rf_ble_adv_par
|
||||
#define ble_cmd_beacon rf_ble_cmd_ble_adv_nc
|
||||
#define ble_cmd_adv_nc rf_ble_cmd_ble_adv_nc
|
||||
|
||||
/* CC13x2/CC26x2 devices */
|
||||
#elif (DeviceFamily_PARENT == DeviceFamily_PARENT_CC13X2_CC26X2)
|
||||
|
@ -97,7 +97,7 @@
|
|||
#define ble_mode rf_ble_mode
|
||||
#define ble_cmd_radio_setup rf_ble_cmd_radio_setup
|
||||
#define ble_adv_par rf_ble_adv_par
|
||||
#define ble_cmd_beacon rf_ble_cmd_ble_adv_nc
|
||||
#define ble_cmd_adv_nc rf_ble_cmd_ble_adv_nc
|
||||
|
||||
#endif /* DeviceFamily_PARENT */
|
||||
|
||||
|
|
|
@ -31,6 +31,10 @@
|
|||
* \addtogroup cc13xx-cc26xx-platform
|
||||
* @{
|
||||
*
|
||||
* The order of which these header files are included is important in order
|
||||
* for the configurations to be correctly set. This has to do with some
|
||||
* slight unfortunate configuration dependencies of the board file.
|
||||
*
|
||||
* \file
|
||||
* Configuration for the SimpleLink CC13xx/CC26xx platform.
|
||||
* \author
|
||||
|
@ -40,18 +44,16 @@
|
|||
#ifndef CONTIKI_CONF_H_
|
||||
#define CONTIKI_CONF_H_
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include "board-conf.h"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* Include Project Specific conf */
|
||||
/* Include project-specific configurations */
|
||||
#ifdef PROJECT_CONF_PATH
|
||||
#include PROJECT_CONF_PATH
|
||||
#endif
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* Include CPU-related configuration */
|
||||
#include "cc13xx-cc26xx-conf.h"
|
||||
/* Include board-specific configurations */
|
||||
#include "board-conf.h"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* Must be included after cc13xx-cc26xx-conf.h */
|
||||
#include <Board.h>
|
||||
/* Include CPU-related configurations */
|
||||
#include "cc13xx-cc26xx-conf.h"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#endif /* CONTIKI_CONF_H_ */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
|
|
@ -50,7 +50,7 @@
|
|||
#ifndef BOARD_CONF_H_
|
||||
#define BOARD_CONF_H_
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include "contiki-conf.h"
|
||||
#include "rf-conf.h"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \name LED configurations for the dev/leds.h API.
|
||||
|
|
|
@ -36,6 +36,9 @@
|
|||
#define Board_CC1310_LAUNCHXL
|
||||
#define BOARD_STRING "TI CC1310 LaunchPad"
|
||||
|
||||
#define RF_CONF_FRONT_END_MODE RF_FRONT_END_MODE_DIFFERENTIAL
|
||||
#define RF_CONF_BIAS_MODE RF_BIAS_MODE_EXTERNAL
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
|
|
@ -0,0 +1,66 @@
|
|||
/*
|
||||
* Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/**
|
||||
* \addtogroup launchpad-peripherals
|
||||
* @{
|
||||
*
|
||||
* \file
|
||||
* Header file with board-specific RF configurations.
|
||||
* \author
|
||||
* Texas Instruments <e2e.ti.com>
|
||||
* \note
|
||||
* This file should not be included directly
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#ifndef RF_CONF_H_
|
||||
#define RF_CONF_H_
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include "rf/rf.h"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \name Board-specific front-end mode configurations for the Sub-1 GHz path
|
||||
* on the radio.
|
||||
*
|
||||
* These are the following front-end mode configurations for the
|
||||
* CC1310-LAUNCHXL board:
|
||||
* - Sub-1 GHz: differential and external bias
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
#define RF_SUB_1_GHZ_CONF_FRONT_END_MODE RF_FRONT_END_MODE_DIFFERENTIAL
|
||||
#define RF_SUB_1_GHZ_CONF_BIAS_MODE RF_BIAS_MODE_EXTERNAL
|
||||
/** @} */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#endif /* RF_CONF_H_ */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @}
|
||||
* @}
|
||||
*/
|
|
@ -33,15 +33,15 @@
|
|||
#ifndef __BOARD_H
|
||||
#define __BOARD_H
|
||||
|
||||
#define Board_CC1312R1_LAUNCHXL
|
||||
#define BOARD_STRING "TI CC1312R1 LaunchPad"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "CC1312R1_LAUNCHXL.h"
|
||||
|
||||
#define Board_CC1312R1_LAUNCHXL
|
||||
#define BOARD_STRING "TI CC1312R1 LaunchPad"
|
||||
|
||||
#define Board_initGeneral() CC1312R1_LAUNCHXL_initGeneral()
|
||||
#define Board_shutDownExtFlash() CC1312R1_LAUNCHXL_shutDownExtFlash()
|
||||
#define Board_wakeUpExtFlash() CC1312R1_LAUNCHXL_wakeUpExtFlash()
|
||||
|
|
|
@ -0,0 +1,65 @@
|
|||
/*
|
||||
* Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/**
|
||||
* \addtogroup launchpad-peripherals
|
||||
* @{
|
||||
*
|
||||
* \file
|
||||
* Header file with board-specific RF configurations.
|
||||
* \author
|
||||
* Texas Instruments <e2e.ti.com>
|
||||
* \note
|
||||
* This file should not be included directly
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#ifndef RF_CONF_H_
|
||||
#define RF_CONF_H_
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include "rf/rf.h"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \name Board-specific front-end mode configurations for the Sub-1 GHz path
|
||||
* on the radio.
|
||||
*
|
||||
* These are the following front-end mode configurations for the
|
||||
* CC1312R1-LAUNCHXL board:
|
||||
* - Sub-1 GHz: differential and external bias
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
#define RF_SUB_1_GHZ_CONF_FRONT_END_MODE RF_FRONT_END_MODE_DIFFERENTIAL
|
||||
#define RF_SUB_1_GHZ_CONF_BIAS_MODE RF_BIAS_MODE_EXTERNAL
|
||||
/** @} */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#endif /* RF_CONF_H_ */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
|
@ -33,15 +33,15 @@
|
|||
#ifndef __BOARD_H
|
||||
#define __BOARD_H
|
||||
|
||||
#define Board_CC1350_LAUNCHXL_433
|
||||
#define BOARD_STRING "TI CC1350-433 LaunchPad"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "CC1350_LAUNCHXL_433.h"
|
||||
|
||||
#define Board_CC1350_LAUNCHXL_433
|
||||
#define BOARD_STRING "TI CC1350-433 LaunchPad"
|
||||
|
||||
#define Board_initGeneral() CC1350_LAUNCHXL_433_initGeneral()
|
||||
#define Board_shutDownExtFlash() CC1350_LAUNCHXL_433_shutDownExtFlash()
|
||||
#define Board_wakeUpExtFlash() CC1350_LAUNCHXL_433_wakeUpExtFlash()
|
||||
|
|
|
@ -165,23 +165,60 @@ void Board_initHook()
|
|||
#if defined(Board_RF_SUB1GHZ)
|
||||
|
||||
/*
|
||||
* ======== CC1350_LAUNCHXL_433_rfDriverCallback ========
|
||||
* This is an implementation for the CC1350 launchpad which uses a
|
||||
* Mask to be used to determine the effective value of the setup command's
|
||||
* loDivider field.
|
||||
*/
|
||||
#define LODIVIDER_MASK 0x7F
|
||||
|
||||
/*
|
||||
* ======== rfDriverCallback ========
|
||||
* This is an implementation for the CC1350 LaunchPad which uses a
|
||||
* single signal for antenna switching.
|
||||
*/
|
||||
void rfDriverCallback(RF_Handle client, RF_GlobalEvent events, void *arg)
|
||||
{
|
||||
/* Decode input arguments. */
|
||||
(void)client;
|
||||
RF_RadioSetup* setupCommand = (RF_RadioSetup*)arg;
|
||||
|
||||
/* Local variable. */
|
||||
bool sub1GHz = false;
|
||||
uint8_t loDivider = 0;
|
||||
|
||||
if (events & RF_GlobalEventRadioSetup) {
|
||||
/* Power up the antenna switch */
|
||||
PINCC26XX_setOutputValue(Board_RF_POWER, 1);
|
||||
|
||||
if (setupCommand->common.commandNo == CMD_PROP_RADIO_DIV_SETUP) {
|
||||
/* Sub-1 GHz, requires antenna switch high */
|
||||
/* Decision about the frequency band shall be made based on the
|
||||
loDivider field. */
|
||||
switch (setupCommand->common.commandNo) {
|
||||
case (CMD_RADIO_SETUP):
|
||||
case (CMD_BLE5_RADIO_SETUP):
|
||||
loDivider = LODIVIDER_MASK & setupCommand->common.loDivider;
|
||||
|
||||
/* Sub-1 GHz, requires antenna switch high. */
|
||||
if ((loDivider != 0) && (loDivider != 2)) {
|
||||
sub1GHz = true;
|
||||
}
|
||||
break;
|
||||
case (CMD_PROP_RADIO_DIV_SETUP):
|
||||
loDivider = LODIVIDER_MASK & setupCommand->prop_div.loDivider;
|
||||
|
||||
/* Sub-1 GHz, requires antenna switch high. */
|
||||
if ((loDivider != 0) && (loDivider != 2)) {
|
||||
sub1GHz = true;
|
||||
}
|
||||
break;
|
||||
default:break;
|
||||
}
|
||||
|
||||
/* Select the correct antenna. */
|
||||
if (sub1GHz) {
|
||||
PINCC26XX_setOutputValue(Board_RF_SUB1GHZ, 1);
|
||||
}
|
||||
else {
|
||||
PINCC26XX_setOutputValue(Board_RF_SUB1GHZ, 0);
|
||||
}
|
||||
}
|
||||
else if (events & RF_GlobalEventRadioPowerDown) {
|
||||
/* Disable antenna switch to save current */
|
||||
|
|
|
@ -0,0 +1,69 @@
|
|||
/*
|
||||
* Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/**
|
||||
* \addtogroup launchpad-peripherals
|
||||
* @{
|
||||
*
|
||||
* \file
|
||||
* Header file with board-specific RF configurations.
|
||||
* \author
|
||||
* Texas Instruments <e2e.ti.com>
|
||||
* \note
|
||||
* This file should not be included directly
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#ifndef RF_CONF_H_
|
||||
#define RF_CONF_H_
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include "rf/rf.h"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \name Board-specific front-end mode configurations for both the Sub-1 GHz
|
||||
* path and the 2.4 GHz path on the radio.
|
||||
*
|
||||
* These are the following front-end mode configurations for the
|
||||
* CC1350-4-LAUNCHXL board:
|
||||
* - Sub-1 GHz: differential and external bias
|
||||
* - 2.4 GHz: differential and external bias
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
#define RF_SUB_1_GHZ_CONF_FRONT_END_MODE RF_FRONT_END_MODE_DIFFERENTIAL
|
||||
#define RF_SUB_1_GHZ_CONF_BIAS_MODE RF_BIAS_MODE_EXTERNAL
|
||||
|
||||
#define RF_2_4_GHZ_CONF_FRONT_END_MODE RF_FRONT_END_MODE_DIFFERENTIAL
|
||||
#define RF_2_4_GHZ_CONF_BIAS_MODE RF_BIAS_MODE_EXTERNAL
|
||||
/** @} */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#endif /* RF_CONF_H_ */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
|
@ -33,15 +33,15 @@
|
|||
#ifndef __BOARD_H
|
||||
#define __BOARD_H
|
||||
|
||||
#define Board_CC1350_LAUNCHXL
|
||||
#define BOARD_STRING "TI CC1350 LaunchPad"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "CC1350_LAUNCHXL.h"
|
||||
|
||||
#define Board_CC1350_LAUNCHXL
|
||||
#define BOARD_STRING "TI CC1350 LaunchPad"
|
||||
|
||||
#define Board_initGeneral() CC1350_LAUNCHXL_initGeneral()
|
||||
#define Board_shutDownExtFlash() CC1350_LAUNCHXL_shutDownExtFlash()
|
||||
#define Board_wakeUpExtFlash() CC1350_LAUNCHXL_wakeUpExtFlash()
|
||||
|
|
|
@ -166,6 +166,12 @@ void Board_initHook()
|
|||
*/
|
||||
#if defined(Board_RF_SUB1GHZ)
|
||||
|
||||
/*
|
||||
* Mask to be used to determine the effective value of the setup command's
|
||||
* loDivider field.
|
||||
*/
|
||||
#define LODIVIDER_MASK 0x7F
|
||||
|
||||
/*
|
||||
* ======== rfDriverCallback ========
|
||||
* This is an implementation for the CC1350 launchpad which uses a
|
||||
|
@ -173,17 +179,48 @@ void Board_initHook()
|
|||
*/
|
||||
void rfDriverCallback(RF_Handle client, RF_GlobalEvent events, void *arg)
|
||||
{
|
||||
/* Decode input arguments. */
|
||||
(void)client;
|
||||
RF_RadioSetup* setupCommand = (RF_RadioSetup*)arg;
|
||||
|
||||
/* Local variable. */
|
||||
bool sub1GHz = false;
|
||||
uint8_t loDivider = 0;
|
||||
|
||||
if (events & RF_GlobalEventRadioSetup) {
|
||||
/* Power up the antenna switch */
|
||||
PINCC26XX_setOutputValue(Board_RF_POWER, 1);
|
||||
|
||||
if (setupCommand->common.commandNo == CMD_PROP_RADIO_DIV_SETUP) {
|
||||
/* Sub-1 GHz, requires antenna switch high */
|
||||
/* Decision about the frequency band shall be made based on the
|
||||
loDivider field. */
|
||||
switch (setupCommand->common.commandNo) {
|
||||
case (CMD_RADIO_SETUP):
|
||||
case (CMD_BLE5_RADIO_SETUP):
|
||||
loDivider = LODIVIDER_MASK & setupCommand->common.loDivider;
|
||||
|
||||
/* Sub-1 GHz, requires antenna switch high. */
|
||||
if ((loDivider != 0) && (loDivider != 2)) {
|
||||
sub1GHz = true;
|
||||
}
|
||||
break;
|
||||
case (CMD_PROP_RADIO_DIV_SETUP):
|
||||
loDivider = LODIVIDER_MASK & setupCommand->prop_div.loDivider;
|
||||
|
||||
/* Sub-1 GHz, requires antenna switch high. */
|
||||
if ((loDivider != 0) && (loDivider != 2)) {
|
||||
sub1GHz = true;
|
||||
}
|
||||
break;
|
||||
default:break;
|
||||
}
|
||||
|
||||
/* Select the correct antenna. */
|
||||
if (sub1GHz) {
|
||||
PINCC26XX_setOutputValue(Board_RF_SUB1GHZ, 1);
|
||||
}
|
||||
else {
|
||||
PINCC26XX_setOutputValue(Board_RF_SUB1GHZ, 0);
|
||||
}
|
||||
}
|
||||
else if (events & RF_GlobalEventRadioPowerDown) {
|
||||
/* Disable antenna switch to save current */
|
||||
|
|
|
@ -0,0 +1,69 @@
|
|||
/*
|
||||
* Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/**
|
||||
* \addtogroup launchpad-peripherals
|
||||
* @{
|
||||
*
|
||||
* \file
|
||||
* Header file with board-specific RF configurations.
|
||||
* \author
|
||||
* Texas Instruments <e2e.ti.com>
|
||||
* \note
|
||||
* This file should not be included directly
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#ifndef RF_CONF_H_
|
||||
#define RF_CONF_H_
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include "rf/rf.h"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \name Board-specific front-end mode configurations for both the Sub-1 GHz
|
||||
* path and the 2.4 GHz path on the radio.
|
||||
*
|
||||
* These are the following front-end mode configurations for the
|
||||
* CC1350-LAUNCHXL board:
|
||||
* - Sub-1 GHz: differential and external bias
|
||||
* - 2.4 GHz: differential and external bias
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
#define RF_SUB_1_GHZ_CONF_FRONT_END_MODE RF_FRONT_END_MODE_DIFFERENTIAL
|
||||
#define RF_SUB_1_GHZ_CONF_BIAS_MODE RF_BIAS_MODE_EXTERNAL
|
||||
|
||||
#define RF_2_4_GHZ_CONF_FRONT_END_MODE RF_FRONT_END_MODE_DIFFERENTIAL
|
||||
#define RF_2_4_GHZ_CONF_BIAS_MODE RF_BIAS_MODE_EXTERNAL
|
||||
/** @} */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#endif /* RF_CONF_H_ */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
|
@ -33,15 +33,15 @@
|
|||
#ifndef __BOARD_H
|
||||
#define __BOARD_H
|
||||
|
||||
#define Board_CC1352P_2_LAUNCHXL
|
||||
#define BOARD_STRING "TI CC1352P-2 LaunchPad"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "CC1352P_2_LAUNCHXL.h"
|
||||
|
||||
#define Board_CC1352P_2_LAUNCHXL
|
||||
#define BOARD_STRING "TI CC1352P-2 LaunchPad"
|
||||
|
||||
#define Board_initGeneral() CC1352P_2_LAUNCHXL_initGeneral()
|
||||
#define Board_shutDownExtFlash() CC1352P_2_LAUNCHXL_shutDownExtFlash()
|
||||
#define Board_wakeUpExtFlash() CC1352P_2_LAUNCHXL_wakeUpExtFlash()
|
||||
|
|
|
@ -152,6 +152,12 @@ void CC1352P_2_LAUNCHXL_shutDownExtFlash(void)
|
|||
*/
|
||||
#if defined(Board_RF_SUB1GHZ)
|
||||
|
||||
/*
|
||||
* Mask to be used to determine the effective value of the setup command's
|
||||
* loDivider field.
|
||||
*/
|
||||
#define LODIVIDER_MASK 0x7F
|
||||
|
||||
/*
|
||||
* ======== Antenna switching ========
|
||||
*/
|
||||
|
@ -170,7 +176,7 @@ void initAntennaSwitch()
|
|||
}
|
||||
|
||||
/*
|
||||
* ======== rfDriverCallback ========
|
||||
* ======== CC1352P1_LAUNCHXL_rfDriverCallback ========
|
||||
* Sets up the antenna switch depending on the current PHY configuration.
|
||||
* Truth table:
|
||||
*
|
||||
|
@ -183,6 +189,10 @@ void initAntennaSwitch()
|
|||
*/
|
||||
void rfDriverCallback(RF_Handle client, RF_GlobalEvent events, void *arg)
|
||||
{
|
||||
/* Local variable. */
|
||||
bool sub1GHz = false;
|
||||
uint8_t loDivider = 0;
|
||||
|
||||
/* Switch off all paths first. Needs to be done anyway in every sub-case below. */
|
||||
PINCC26XX_setOutputValue(Board_RF_24GHZ, 0);
|
||||
PINCC26XX_setOutputValue(Board_RF_HIGH_PA, 0);
|
||||
|
@ -195,15 +205,36 @@ void rfDriverCallback(RF_Handle client, RF_GlobalEvent events, void *arg)
|
|||
/* Decode the generic argument as a setup command. */
|
||||
RF_RadioSetup* setupCommand = (RF_RadioSetup*)arg;
|
||||
|
||||
if (setupCommand->common.commandNo == CMD_PROP_RADIO_DIV_SETUP) {
|
||||
switch (setupCommand->common.commandNo) {
|
||||
case (CMD_RADIO_SETUP):
|
||||
case (CMD_BLE5_RADIO_SETUP):
|
||||
loDivider = LODIVIDER_MASK & setupCommand->common.loDivider;
|
||||
|
||||
/* Sub-1GHz front-end. */
|
||||
if (loDivider != 0) {
|
||||
sub1GHz = true;
|
||||
}
|
||||
break;
|
||||
case (CMD_PROP_RADIO_DIV_SETUP):
|
||||
loDivider = LODIVIDER_MASK & setupCommand->prop_div.loDivider;
|
||||
|
||||
/* Sub-1GHz front-end. */
|
||||
if (loDivider != 0) {
|
||||
sub1GHz = true;
|
||||
}
|
||||
break;
|
||||
default:break;
|
||||
}
|
||||
|
||||
if (sub1GHz) {
|
||||
/* Sub-1 GHz */
|
||||
if (paType == RF_TxPowerTable_HighPA) {
|
||||
/* PA enable --> HIGH PA
|
||||
* LNA enable --> Sub-1 GHz
|
||||
*/
|
||||
PINCC26XX_setMux(antennaPins, Board_RF_24GHZ, PINCC26XX_MUX_GPIO);
|
||||
// Note: RFC_GPO3 is a work-around because the RFC_GPO1 (PA enable signal) is sometimes not
|
||||
// de-asserted on CC1352 Rev A.
|
||||
/* Note: RFC_GPO3 is a work-around because the RFC_GPO1 (PA enable signal) is sometimes not
|
||||
de-asserted on CC1352 Rev A. */
|
||||
PINCC26XX_setMux(antennaPins, Board_RF_HIGH_PA, PINCC26XX_MUX_RFC_GPO3);
|
||||
PINCC26XX_setMux(antennaPins, Board_RF_SUB1GHZ, PINCC26XX_MUX_RFC_GPO0);
|
||||
} else {
|
||||
|
@ -221,8 +252,8 @@ void rfDriverCallback(RF_Handle client, RF_GlobalEvent events, void *arg)
|
|||
* LNA enable --> 2.4 GHz
|
||||
*/
|
||||
PINCC26XX_setMux(antennaPins, Board_RF_24GHZ, PINCC26XX_MUX_RFC_GPO0);
|
||||
// Note: RFC_GPO3 is a work-around because the RFC_GPO1 (PA enable signal) is sometimes not
|
||||
// de-asserted on CC1352 Rev A.
|
||||
/* Note: RFC_GPO3 is a work-around because the RFC_GPO1 (PA enable signal) is sometimes not
|
||||
de-asserted on CC1352 Rev A. */
|
||||
PINCC26XX_setMux(antennaPins, Board_RF_HIGH_PA, PINCC26XX_MUX_RFC_GPO3);
|
||||
PINCC26XX_setMux(antennaPins, Board_RF_SUB1GHZ, PINCC26XX_MUX_GPIO);
|
||||
} else {
|
||||
|
|
|
@ -0,0 +1,69 @@
|
|||
/*
|
||||
* Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/**
|
||||
* \addtogroup launchpad-peripherals
|
||||
* @{
|
||||
*
|
||||
* \file
|
||||
* Header file with board-specific RF configurations.
|
||||
* \author
|
||||
* Texas Instruments <e2e.ti.com>
|
||||
* \note
|
||||
* This file should not be included directly
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#ifndef RF_CONF_H_
|
||||
#define RF_CONF_H_
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include "rf/rf.h"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \name Board-specific front-end mode configurations for both the Sub-1 GHz
|
||||
* path and the 2.4 GHz path on the radio.
|
||||
*
|
||||
* These are the following front-end mode configurations for the
|
||||
* CC1352P-2-LAUNCHXL board:
|
||||
* - Sub-1 GHz: differential and external bias
|
||||
* - 2.4 GHz: differential and external bias
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
#define RF_SUB_1_GHZ_CONF_FRONT_END_MODE RF_FRONT_END_MODE_DIFFERENTIAL
|
||||
#define RF_SUB_1_GHZ_CONF_BIAS_MODE RF_BIAS_MODE_EXTERNAL
|
||||
|
||||
#define RF_2_4_GHZ_CONF_FRONT_END_MODE RF_FRONT_END_MODE_DIFFERENTIAL
|
||||
#define RF_2_4_GHZ_CONF_BIAS_MODE RF_BIAS_MODE_EXTERNAL
|
||||
/** @} */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#endif /* RF_CONF_H_ */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
|
@ -33,15 +33,15 @@
|
|||
#ifndef __BOARD_H
|
||||
#define __BOARD_H
|
||||
|
||||
#define Board_CC1352P_4_LAUNCHXL
|
||||
#define BOARD_STRING "TI CC1352P-4 LaunchPad"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "CC1352P_4_LAUNCHXL.h"
|
||||
|
||||
#define Board_CC1352P_4_LAUNCHXL
|
||||
#define BOARD_STRING "TI CC1352P-4 LaunchPad"
|
||||
|
||||
#define Board_initGeneral() CC1352P_4_LAUNCHXL_initGeneral()
|
||||
#define Board_shutDownExtFlash() CC1352P_4_LAUNCHXL_shutDownExtFlash()
|
||||
#define Board_wakeUpExtFlash() CC1352P_4_LAUNCHXL_wakeUpExtFlash()
|
||||
|
|
|
@ -152,6 +152,12 @@ void CC1352P_4_LAUNCHXL_shutDownExtFlash(void)
|
|||
*/
|
||||
#if defined(Board_RF_SUB1GHZ)
|
||||
|
||||
/*
|
||||
* Mask to be used to determine the effective value of the setup command's
|
||||
* loDivider field.
|
||||
*/
|
||||
#define LODIVIDER_MASK 0x7F
|
||||
|
||||
/*
|
||||
* ======== Antenna switching ========
|
||||
*/
|
||||
|
@ -170,7 +176,7 @@ void initAntennaSwitch()
|
|||
}
|
||||
|
||||
/*
|
||||
* ======== rfDriverCallback ========
|
||||
* ======== CC1352P1_LAUNCHXL_rfDriverCallback ========
|
||||
* Sets up the antenna switch depending on the current PHY configuration.
|
||||
* Truth table:
|
||||
*
|
||||
|
@ -183,6 +189,10 @@ void initAntennaSwitch()
|
|||
*/
|
||||
void rfDriverCallback(RF_Handle client, RF_GlobalEvent events, void *arg)
|
||||
{
|
||||
/* Local variable. */
|
||||
bool sub1GHz = false;
|
||||
uint8_t loDivider = 0;
|
||||
|
||||
/* Switch off all paths first. Needs to be done anyway in every sub-case below. */
|
||||
PINCC26XX_setOutputValue(Board_RF_24GHZ, 0);
|
||||
PINCC26XX_setOutputValue(Board_RF_HIGH_PA, 0);
|
||||
|
@ -195,15 +205,36 @@ void rfDriverCallback(RF_Handle client, RF_GlobalEvent events, void *arg)
|
|||
/* Decode the generic argument as a setup command. */
|
||||
RF_RadioSetup* setupCommand = (RF_RadioSetup*)arg;
|
||||
|
||||
if (setupCommand->common.commandNo == CMD_PROP_RADIO_DIV_SETUP) {
|
||||
switch (setupCommand->common.commandNo) {
|
||||
case (CMD_RADIO_SETUP):
|
||||
case (CMD_BLE5_RADIO_SETUP):
|
||||
loDivider = LODIVIDER_MASK & setupCommand->common.loDivider;
|
||||
|
||||
/* Sub-1GHz front-end. */
|
||||
if (loDivider != 0) {
|
||||
sub1GHz = true;
|
||||
}
|
||||
break;
|
||||
case (CMD_PROP_RADIO_DIV_SETUP):
|
||||
loDivider = LODIVIDER_MASK & setupCommand->prop_div.loDivider;
|
||||
|
||||
/* Sub-1GHz front-end. */
|
||||
if (loDivider != 0) {
|
||||
sub1GHz = true;
|
||||
}
|
||||
break;
|
||||
default:break;
|
||||
}
|
||||
|
||||
if (sub1GHz) {
|
||||
/* Sub-1 GHz */
|
||||
if (paType == RF_TxPowerTable_HighPA) {
|
||||
/* PA enable --> HIGH PA
|
||||
* LNA enable --> Sub-1 GHz
|
||||
*/
|
||||
PINCC26XX_setMux(antennaPins, Board_RF_24GHZ, PINCC26XX_MUX_GPIO);
|
||||
// Note: RFC_GPO3 is a work-around because the RFC_GPO1 (PA enable signal) is sometimes not
|
||||
// de-asserted on CC1352 Rev A.
|
||||
/* Note: RFC_GPO3 is a work-around because the RFC_GPO1 (PA enable signal) is sometimes not
|
||||
de-asserted on CC1352 Rev A. */
|
||||
PINCC26XX_setMux(antennaPins, Board_RF_HIGH_PA, PINCC26XX_MUX_RFC_GPO3);
|
||||
PINCC26XX_setMux(antennaPins, Board_RF_SUB1GHZ, PINCC26XX_MUX_RFC_GPO0);
|
||||
} else {
|
||||
|
@ -221,8 +252,8 @@ void rfDriverCallback(RF_Handle client, RF_GlobalEvent events, void *arg)
|
|||
* LNA enable --> 2.4 GHz
|
||||
*/
|
||||
PINCC26XX_setMux(antennaPins, Board_RF_24GHZ, PINCC26XX_MUX_RFC_GPO0);
|
||||
// Note: RFC_GPO3 is a work-around because the RFC_GPO1 (PA enable signal) is sometimes not
|
||||
// de-asserted on CC1352 Rev A.
|
||||
/* Note: RFC_GPO3 is a work-around because the RFC_GPO1 (PA enable signal) is sometimes not
|
||||
de-asserted on CC1352 Rev A. */
|
||||
PINCC26XX_setMux(antennaPins, Board_RF_HIGH_PA, PINCC26XX_MUX_RFC_GPO3);
|
||||
PINCC26XX_setMux(antennaPins, Board_RF_SUB1GHZ, PINCC26XX_MUX_GPIO);
|
||||
} else {
|
||||
|
|
|
@ -0,0 +1,69 @@
|
|||
/*
|
||||
* Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/**
|
||||
* \addtogroup launchpad-peripherals
|
||||
* @{
|
||||
*
|
||||
* \file
|
||||
* Header file with board-specific RF configurations.
|
||||
* \author
|
||||
* Texas Instruments <e2e.ti.com>
|
||||
* \note
|
||||
* This file should not be included directly
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#ifndef RF_CONF_H_
|
||||
#define RF_CONF_H_
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include "rf/rf.h"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \name Board-specific front-end mode configurations for both the Sub-1 GHz
|
||||
* path and the 2.4 GHz path on the radio.
|
||||
*
|
||||
* These are the following front-end mode configurations for the
|
||||
* CC1352P-4-LAUNCHXL board:
|
||||
* - Sub-1 GHz: differential and external bias
|
||||
* - 2.4 GHz: differential and external bias
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
#define RF_SUB_1_GHZ_CONF_FRONT_END_MODE RF_FRONT_END_MODE_DIFFERENTIAL
|
||||
#define RF_SUB_1_GHZ_CONF_BIAS_MODE RF_BIAS_MODE_EXTERNAL
|
||||
|
||||
#define RF_2_4_GHZ_CONF_FRONT_END_MODE RF_FRONT_END_MODE_DIFFERENTIAL
|
||||
#define RF_2_4_GHZ_CONF_BIAS_MODE RF_BIAS_MODE_EXTERNAL
|
||||
/** @} */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#endif /* RF_CONF_H_ */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
|
@ -33,15 +33,15 @@
|
|||
#ifndef __BOARD_H
|
||||
#define __BOARD_H
|
||||
|
||||
#define Board_CC1352P1_LAUNCHXL
|
||||
#define BOARD_STRING "TI CC1352P1 LaunchPad"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "CC1352P1_LAUNCHXL.h"
|
||||
|
||||
#define Board_CC1352P1_LAUNCHXL
|
||||
#define BOARD_STRING "TI CC1352P1 LaunchPad"
|
||||
|
||||
#define Board_initGeneral() CC1352P1_LAUNCHXL_initGeneral()
|
||||
#define Board_shutDownExtFlash() CC1352P1_LAUNCHXL_shutDownExtFlash()
|
||||
#define Board_wakeUpExtFlash() CC1352P1_LAUNCHXL_wakeUpExtFlash()
|
||||
|
|
|
@ -152,6 +152,12 @@ void CC1352P1_LAUNCHXL_shutDownExtFlash(void)
|
|||
*/
|
||||
#if defined(Board_RF_SUB1GHZ)
|
||||
|
||||
/*
|
||||
* Mask to be used to determine the effective value of the setup command's
|
||||
* loDivider field.
|
||||
*/
|
||||
#define LODIVIDER_MASK 0x7F
|
||||
|
||||
/*
|
||||
* ======== Antenna switching ========
|
||||
*/
|
||||
|
@ -170,7 +176,7 @@ void initAntennaSwitch()
|
|||
}
|
||||
|
||||
/*
|
||||
* ======== rfDriverCallback ========
|
||||
* ======== CC1352P1_LAUNCHXL_rfDriverCallback ========
|
||||
* Sets up the antenna switch depending on the current PHY configuration.
|
||||
* Truth table:
|
||||
*
|
||||
|
@ -183,6 +189,10 @@ void initAntennaSwitch()
|
|||
*/
|
||||
void rfDriverCallback(RF_Handle client, RF_GlobalEvent events, void *arg)
|
||||
{
|
||||
/* Local variable. */
|
||||
bool sub1GHz = false;
|
||||
uint8_t loDivider = 0;
|
||||
|
||||
/* Switch off all paths first. Needs to be done anyway in every sub-case below. */
|
||||
PINCC26XX_setOutputValue(Board_RF_24GHZ, 0);
|
||||
PINCC26XX_setOutputValue(Board_RF_HIGH_PA, 0);
|
||||
|
@ -195,15 +205,36 @@ void rfDriverCallback(RF_Handle client, RF_GlobalEvent events, void *arg)
|
|||
/* Decode the generic argument as a setup command. */
|
||||
RF_RadioSetup* setupCommand = (RF_RadioSetup*)arg;
|
||||
|
||||
if (setupCommand->common.commandNo == CMD_PROP_RADIO_DIV_SETUP) {
|
||||
switch (setupCommand->common.commandNo) {
|
||||
case (CMD_RADIO_SETUP):
|
||||
case (CMD_BLE5_RADIO_SETUP):
|
||||
loDivider = LODIVIDER_MASK & setupCommand->common.loDivider;
|
||||
|
||||
/* Sub-1GHz front-end. */
|
||||
if (loDivider != 0) {
|
||||
sub1GHz = true;
|
||||
}
|
||||
break;
|
||||
case (CMD_PROP_RADIO_DIV_SETUP):
|
||||
loDivider = LODIVIDER_MASK & setupCommand->prop_div.loDivider;
|
||||
|
||||
/* Sub-1GHz front-end. */
|
||||
if (loDivider != 0) {
|
||||
sub1GHz = true;
|
||||
}
|
||||
break;
|
||||
default:break;
|
||||
}
|
||||
|
||||
if (sub1GHz) {
|
||||
/* Sub-1 GHz */
|
||||
if (paType == RF_TxPowerTable_HighPA) {
|
||||
/* PA enable --> HIGH PA
|
||||
* LNA enable --> Sub-1 GHz
|
||||
*/
|
||||
PINCC26XX_setMux(antennaPins, Board_RF_24GHZ, PINCC26XX_MUX_GPIO);
|
||||
// Note: RFC_GPO3 is a work-around because the RFC_GPO1 (PA enable signal) is sometimes not
|
||||
// de-asserted on CC1352 Rev A.
|
||||
/* Note: RFC_GPO3 is a work-around because the RFC_GPO1 (PA enable signal) is sometimes not
|
||||
de-asserted on CC1352 Rev A. */
|
||||
PINCC26XX_setMux(antennaPins, Board_RF_HIGH_PA, PINCC26XX_MUX_RFC_GPO3);
|
||||
PINCC26XX_setMux(antennaPins, Board_RF_SUB1GHZ, PINCC26XX_MUX_RFC_GPO0);
|
||||
} else {
|
||||
|
@ -221,8 +252,8 @@ void rfDriverCallback(RF_Handle client, RF_GlobalEvent events, void *arg)
|
|||
* LNA enable --> 2.4 GHz
|
||||
*/
|
||||
PINCC26XX_setMux(antennaPins, Board_RF_24GHZ, PINCC26XX_MUX_RFC_GPO0);
|
||||
// Note: RFC_GPO3 is a work-around because the RFC_GPO1 (PA enable signal) is sometimes not
|
||||
// de-asserted on CC1352 Rev A.
|
||||
/* Note: RFC_GPO3 is a work-around because the RFC_GPO1 (PA enable signal) is sometimes not
|
||||
de-asserted on CC1352 Rev A. */
|
||||
PINCC26XX_setMux(antennaPins, Board_RF_HIGH_PA, PINCC26XX_MUX_RFC_GPO3);
|
||||
PINCC26XX_setMux(antennaPins, Board_RF_SUB1GHZ, PINCC26XX_MUX_GPIO);
|
||||
} else {
|
||||
|
|
|
@ -0,0 +1,69 @@
|
|||
/*
|
||||
* Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/**
|
||||
* \addtogroup launchpad-peripherals
|
||||
* @{
|
||||
*
|
||||
* \file
|
||||
* Header file with board-specific RF configurations.
|
||||
* \author
|
||||
* Texas Instruments <e2e.ti.com>
|
||||
* \note
|
||||
* This file should not be included directly
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#ifndef RF_CONF_H_
|
||||
#define RF_CONF_H_
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include "rf/rf.h"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \name Board-specific front-end mode configurations for both the Sub-1 GHz
|
||||
* path and the 2.4 GHz path on the radio.
|
||||
*
|
||||
* These are the following front-end mode configurations for the
|
||||
* CC1352P1-LAUNCHXL board:
|
||||
* - Sub-1 GHz: differential and external bias
|
||||
* - 2.4 GHz: differential and external bias
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
#define RF_SUB_1_GHZ_CONF_FRONT_END_MODE RF_FRONT_END_MODE_DIFFERENTIAL
|
||||
#define RF_SUB_1_GHZ_CONF_BIAS_MODE RF_BIAS_MODE_EXTERNAL
|
||||
|
||||
#define RF_2_4_GHZ_CONF_FRONT_END_MODE RF_FRONT_END_MODE_DIFFERENTIAL
|
||||
#define RF_2_4_GHZ_CONF_BIAS_MODE RF_BIAS_MODE_EXTERNAL
|
||||
/** @} */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#endif /* RF_CONF_H_ */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
|
@ -33,15 +33,15 @@
|
|||
#ifndef __BOARD_H
|
||||
#define __BOARD_H
|
||||
|
||||
#define Board_CC1352R1_LAUNCHXL
|
||||
#define BOARD_STRING "TI CC1352R1 LaunchPad"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "CC1352R1_LAUNCHXL.h"
|
||||
|
||||
#define Board_CC1352R1_LAUNCHXL
|
||||
#define BOARD_STRING "TI CC1352R1 LaunchPad"
|
||||
|
||||
#define Board_initGeneral() CC1352R1_LAUNCHXL_initGeneral()
|
||||
#define Board_shutDownExtFlash() CC1352R1_LAUNCHXL_shutDownExtFlash()
|
||||
#define Board_wakeUpExtFlash() CC1352R1_LAUNCHXL_wakeUpExtFlash()
|
||||
|
|
|
@ -36,8 +36,6 @@
|
|||
* CC1352R1_LAUNCHXL board.
|
||||
*/
|
||||
|
||||
#include "contiki.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
|
|
@ -164,23 +164,61 @@ void Board_initHook()
|
|||
*/
|
||||
#if defined(Board_RF_SUB1GHZ)
|
||||
|
||||
/*
|
||||
* Mask to be used to determine the effective value of the setup command's
|
||||
* loDivider field.
|
||||
*/
|
||||
#define LODIVIDER_MASK 0x7F
|
||||
|
||||
/*
|
||||
* ======== rfDriverCallback ========
|
||||
* This is an implementation for the CC1352R1 launchpad which uses a
|
||||
* This is an implementation for the CC1352R launchpad which uses a
|
||||
* single signal for antenna switching.
|
||||
*/
|
||||
void rfDriverCallback(RF_Handle client, RF_GlobalEvent events, void *arg)
|
||||
{
|
||||
/* Decode input arguments. */
|
||||
(void)client;
|
||||
RF_RadioSetup* setupCommand = (RF_RadioSetup*)arg;
|
||||
|
||||
if ((events & RF_GlobalEventRadioSetup) &&
|
||||
(setupCommand->common.commandNo == CMD_PROP_RADIO_DIV_SETUP)) {
|
||||
/* Sub-1 GHz, requires antenna switch high */
|
||||
PINCC26XX_setOutputValue(Board_RF_SUB1GHZ, 1);
|
||||
/* Local variable. */
|
||||
bool sub1GHz = false;
|
||||
uint8_t loDivider = 0;
|
||||
|
||||
if (events & RF_GlobalEventRadioSetup) {
|
||||
/* Decision about the frequency band shall be made based on the
|
||||
loDivider field. */
|
||||
switch (setupCommand->common.commandNo) {
|
||||
case (CMD_RADIO_SETUP):
|
||||
case (CMD_BLE5_RADIO_SETUP):
|
||||
loDivider = LODIVIDER_MASK & setupCommand->common.loDivider;
|
||||
|
||||
/* Sub-1GHz front-end. */
|
||||
if (loDivider != 0) {
|
||||
sub1GHz = true;
|
||||
}
|
||||
break;
|
||||
case (CMD_PROP_RADIO_DIV_SETUP):
|
||||
loDivider = LODIVIDER_MASK & setupCommand->prop_div.loDivider;
|
||||
|
||||
/* Sub-1GHz front-end. */
|
||||
if (loDivider != 0) {
|
||||
sub1GHz = true;
|
||||
}
|
||||
break;
|
||||
default:break;
|
||||
}
|
||||
|
||||
/* Select the correct antenna. */
|
||||
if (sub1GHz) {
|
||||
PINCC26XX_setOutputValue(Board_RF_SUB1GHZ, 1);
|
||||
}
|
||||
else {
|
||||
PINCC26XX_setOutputValue(Board_RF_SUB1GHZ, 0);
|
||||
}
|
||||
}
|
||||
else if (events & RF_GlobalEventRadioPowerDown) {
|
||||
/* Disable antenna switch to save current */
|
||||
/* Set the antenna to 2.4 GHz as default. */
|
||||
PINCC26XX_setOutputValue(Board_RF_SUB1GHZ, 0);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,69 @@
|
|||
/*
|
||||
* Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/**
|
||||
* \addtogroup launchpad-peripherals
|
||||
* @{
|
||||
*
|
||||
* \file
|
||||
* Header file with board-specific RF configurations.
|
||||
* \author
|
||||
* Texas Instruments <e2e.ti.com>
|
||||
* \note
|
||||
* This file should not be included directly
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#ifndef RF_CONF_H_
|
||||
#define RF_CONF_H_
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include "rf/rf.h"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \name Board-specific front-end mode configurations for both the Sub-1 GHz
|
||||
* path and the 2.4 GHz path on the radio.
|
||||
*
|
||||
* These are the following front-end mode configurations for the
|
||||
* CC1352R1-LAUNCHXL board:
|
||||
* - Sub-1 GHz: differential and external bias
|
||||
* - 2.4 GHz: differential and external bias
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
#define RF_SUB_1_GHZ_CONF_FRONT_END_MODE RF_FRONT_END_MODE_DIFFERENTIAL
|
||||
#define RF_SUB_1_GHZ_CONF_BIAS_MODE RF_BIAS_MODE_EXTERNAL
|
||||
|
||||
#define RF_2_4_GHZ_CONF_FRONT_END_MODE RF_FRONT_END_MODE_DIFFERENTIAL
|
||||
#define RF_2_4_GHZ_CONF_BIAS_MODE RF_BIAS_MODE_EXTERNAL
|
||||
/** @} */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#endif /* RF_CONF_H_ */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
|
@ -33,18 +33,18 @@
|
|||
#ifndef __BOARD_H
|
||||
#define __BOARD_H
|
||||
|
||||
#define Board_CC2650_LAUNCHXL
|
||||
#define BOARD_STRING "TI CC2650 LaunchPad"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "CC2650_LAUNCHXL.h"
|
||||
|
||||
#define Board_initGeneral() CC2650_LAUNCHXL_initGeneral()
|
||||
#define Board_CC2650_LAUNCHXL
|
||||
#define BOARD_STRING "TI CC2650 LaunchPad"
|
||||
|
||||
#define Board_initGeneral() CC2650_LAUNCHXL_initGeneral()
|
||||
#define Board_shutDownExtFlash() CC2650_LAUNCHXL_shutDownExtFlash()
|
||||
#define Board_wakeUpExtFlash() CC2650_LAUNCHXL_wakeUpExtFlash()
|
||||
#define Board_wakeUpExtFlash() CC2650_LAUNCHXL_wakeUpExtFlash()
|
||||
|
||||
/* These #defines allow us to reuse TI-RTOS across other device families */
|
||||
|
||||
|
|
|
@ -0,0 +1,65 @@
|
|||
/*
|
||||
* Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/**
|
||||
* \addtogroup launchpad-peripherals
|
||||
* @{
|
||||
*
|
||||
* \file
|
||||
* Header file with board-specific RF configurations.
|
||||
* \author
|
||||
* Texas Instruments <e2e.ti.com>
|
||||
* \note
|
||||
* This file should not be included directly
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#ifndef RF_CONF_H_
|
||||
#define RF_CONF_H_
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include "rf/rf.h"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \name Board-specific front-end mode configurations for the 2.4 GHz path
|
||||
* on the radio.
|
||||
*
|
||||
* These are the following front-end mode configurations for the
|
||||
* CC2650-LAUNCHXL board:
|
||||
* - 2.4 GHz: differential and internal bias
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
#define RF_2_4_GHZ_CONF_FRONT_END_MODE RF_FRONT_END_MODE_DIFFERENTIAL
|
||||
#define RF_2_4_GHZ_CONF_BIAS_MODE RF_BIAS_MODE_INTERNAL
|
||||
/** @} */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#endif /* RF_CONF_H_ */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
|
@ -33,20 +33,18 @@
|
|||
#ifndef __BOARD_H
|
||||
#define __BOARD_H
|
||||
|
||||
#define Board_CC26X2R1_LAUNCHXL
|
||||
#define BOARD_STRING "TI CC26x2R1 LaunchPad"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "CC26X2R1_LAUNCHXL.h"
|
||||
|
||||
#define Board_initGeneral() CC26X2R1_LAUNCHXL_initGeneral()
|
||||
#define Board_CC26X2R1_LAUNCHXL
|
||||
#define BOARD_STRING "TI CC26x2R1 LaunchPad"
|
||||
|
||||
#define Board_initGeneral() CC26X2R1_LAUNCHXL_initGeneral()
|
||||
#define Board_shutDownExtFlash() CC26X2R1_LAUNCHXL_shutDownExtFlash()
|
||||
|
||||
#define Board_wakeUpExtFlash() CC26X2R1_LAUNCHXL_wakeUpExtFlash()
|
||||
#define Board_wakeUpExtFlash() CC26X2R1_LAUNCHXL_wakeUpExtFlash()
|
||||
|
||||
/* These #defines allow us to reuse TI-RTOS across other device families */
|
||||
|
||||
|
|
|
@ -35,7 +35,6 @@
|
|||
* This file is responsible for setting up the board specific items for the
|
||||
* CC26X2R1_LAUNCHXL board.
|
||||
*/
|
||||
#include "contiki.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
|
|
|
@ -0,0 +1,65 @@
|
|||
/*
|
||||
* Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/**
|
||||
* \addtogroup launchpad-peripherals
|
||||
* @{
|
||||
*
|
||||
* \file
|
||||
* Header file with board-specific RF configurations.
|
||||
* \author
|
||||
* Texas Instruments <e2e.ti.com>
|
||||
* \note
|
||||
* This file should not be included directly
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#ifndef RF_CONF_H_
|
||||
#define RF_CONF_H_
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include "rf/rf.h"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \name Board-specific front-end mode configurations for the 2.4 GHz path
|
||||
* on the radio.
|
||||
*
|
||||
* These are the following front-end mode configurations for the
|
||||
* CC26X2R1-LAUNCHXL board:
|
||||
* - 2.4 GHz: differential and internal bias
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
#define RF_2_4_GHZ_CONF_FRONT_END_MODE RF_FRONT_END_MODE_DIFFERENTIAL
|
||||
#define RF_2_4_GHZ_CONF_BIAS_MODE RF_BIAS_MODE_INTERNAL
|
||||
/** @} */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#endif /* RF_CONF_H_ */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
|
@ -50,8 +50,7 @@
|
|||
#ifndef BOARD_CONF_H_
|
||||
#define BOARD_CONF_H_
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include "contiki-conf.h"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include "rf-conf.h"
|
||||
#include "leds-arch.h"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
|
|
|
@ -33,15 +33,15 @@
|
|||
#ifndef __BOARD_H
|
||||
#define __BOARD_H
|
||||
|
||||
#define Board_CC1350STK
|
||||
#define BOARD_STRING "TI CC1350 SensorTag"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "CC1350STK.h"
|
||||
|
||||
#define Board_CC1350STK
|
||||
#define BOARD_STRING "TI CC1350 SensorTag"
|
||||
|
||||
#define Board_initGeneral() CC1350STK_initGeneral()
|
||||
#define Board_shutDownExtFlash() CC1350STK_shutDownExtFlash()
|
||||
#define Board_wakeUpExtFlash() CC1350STK_wakeUpExtFlash()
|
||||
|
|
|
@ -0,0 +1,69 @@
|
|||
/*
|
||||
* Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/**
|
||||
* \addtogroup launchpad-peripherals
|
||||
* @{
|
||||
*
|
||||
* \file
|
||||
* Header file with board-specific RF configurations.
|
||||
* \author
|
||||
* Texas Instruments <e2e.ti.com>
|
||||
* \note
|
||||
* This file should not be included directly
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#ifndef RF_CONF_H_
|
||||
#define RF_CONF_H_
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include "rf/rf.h"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \name Board-specific front-end mode configurations for both the Sub-1 GHz
|
||||
* path and the 2.4 GHz path on the radio.
|
||||
*
|
||||
* These are the following front-end mode configurations for the
|
||||
* CC1350STK board:
|
||||
* - Sub-1 GHz: single-ended RFN and external bias
|
||||
* - 2.4 GHz: single-ended RFP and external bias
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
#define RF_SUB_1_GHZ_CONF_FRONT_END_MODE RF_FRONT_END_MODE_SINGLE_ENDED_RFN
|
||||
#define RF_SUB_1_GHZ_CONF_BIAS_MODE RF_BIAS_MODE_EXTERNAL
|
||||
|
||||
#define RF_2_4_GHZ_CONF_FRONT_END_MODE RF_FRONT_END_MODE_SINGLE_ENDED_RFP
|
||||
#define RF_2_4_GHZ_CONF_BIAS_MODE RF_BIAS_MODE_EXTERNAL
|
||||
/** @} */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#endif /* RF_CONF_H_ */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
|
@ -33,15 +33,15 @@
|
|||
#ifndef __BOARD_H
|
||||
#define __BOARD_H
|
||||
|
||||
#define Board_CC2650STK
|
||||
#define BOARD_STRING "TI CC2650 SensorTag"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "CC2650STK.h"
|
||||
|
||||
#define Board_CC2650STK
|
||||
#define BOARD_STRING "TI CC2650 SensorTag"
|
||||
|
||||
#define Board_initGeneral() CC2650STK_initGeneral()
|
||||
#define Board_shutDownExtFlash() CC2650STK_shutDownExtFlash()
|
||||
#define Board_wakeUpExtFlash() CC2650STK_wakeUpExtFlash()
|
||||
|
|
|
@ -0,0 +1,65 @@
|
|||
/*
|
||||
* Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/**
|
||||
* \addtogroup launchpad-peripherals
|
||||
* @{
|
||||
*
|
||||
* \file
|
||||
* Header file with board-specific RF configurations.
|
||||
* \author
|
||||
* Texas Instruments <e2e.ti.com>
|
||||
* \note
|
||||
* This file should not be included directly
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#ifndef RF_CONF_H_
|
||||
#define RF_CONF_H_
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include "rf/rf.h"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \name Board-specific front-end mode configurations for the 2.4 GHz path
|
||||
* on the radio.
|
||||
*
|
||||
* These are the following front-end mode configurations for the
|
||||
* CC2650STK board:
|
||||
* - 2.4 GHz: differential and internal bias
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
#define RF_2_4_GHZ_CONF_FRONT_END_MODE RF_FRONT_END_MODE_DIFFERENTIAL
|
||||
#define RF_2_4_GHZ_CONF_BIAS_MODE RF_BIAS_MODE_INTERNAL
|
||||
/** @} */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#endif /* RF_CONF_H_ */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
|
@ -303,9 +303,13 @@ value(int type)
|
|||
|
||||
result_value = SWAP16(result_value);
|
||||
|
||||
uint32_t e = (result_value & 0x0FFF) >> 0;
|
||||
uint32_t m = (result_value & 0xF000) >> 12;
|
||||
uint32_t converted = m * 100 * (1 << e);
|
||||
/* formula for computing lux: lux = 0.01 * 2^e * m
|
||||
* scale up by 100 to avoid floating point, then require
|
||||
* users to scale down by same.
|
||||
*/
|
||||
uint32_t m = (result_value & 0x0FFF) >> 0;
|
||||
uint32_t e = (result_value & 0xF000) >> 12;
|
||||
uint32_t converted = m * (1 << e);
|
||||
|
||||
PRINTF("OPT: %04X r=%d (centilux)\n", result_value,
|
||||
(int)(converted));
|
||||
|
|
|
@ -42,6 +42,8 @@
|
|||
#ifndef BOARD_CONF_H_
|
||||
#define BOARD_CONF_H_
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include "rf-conf.h"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \name LED configurations for the dev/leds.h API.
|
||||
*
|
||||
|
|
|
@ -33,15 +33,15 @@
|
|||
#ifndef __BOARD_H
|
||||
#define __BOARD_H
|
||||
|
||||
#define Board_CC1350DK_7XD
|
||||
#define BOARD_STRING "TI SmartRF06EB + CC13x0 EM"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "CC1350DK_7XD.h"
|
||||
|
||||
#define Board_CC1350DK_7XD
|
||||
#define BOARD_STRING "TI SmartRF06EB + CC13x0 EM"
|
||||
|
||||
#define Board_initGeneral() CC1350DK_7XD_initGeneral()
|
||||
#define Board_shutDownExtFlash() CC1350DK_7XD_shutDownExtFlash()
|
||||
#define Board_wakeUpExtFlash() CC1350DK_7XD_wakeUpExtFlash()
|
||||
|
|
|
@ -0,0 +1,69 @@
|
|||
/*
|
||||
* Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/**
|
||||
* \addtogroup launchpad-peripherals
|
||||
* @{
|
||||
*
|
||||
* \file
|
||||
* Header file with board-specific RF configurations.
|
||||
* \author
|
||||
* Texas Instruments <e2e.ti.com>
|
||||
* \note
|
||||
* This file should not be included directly
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#ifndef RF_CONF_H_
|
||||
#define RF_CONF_H_
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include "rf/rf.h"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \name Board-specific front-end mode configurations for both the Sub-1 GHz
|
||||
* path and the 2.4 GHz path on the radio.
|
||||
*
|
||||
* These are the following front-end mode configurations for the
|
||||
* CC1350DK-7XD board:
|
||||
* - Sub-1 GHz: differential and external bias
|
||||
* - 2.4 GHz: differential and external bias
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
#define RF_SUB_1_GHZ_CONF_FRONT_END_MODE RF_FRONT_END_MODE_DIFFERENTIAL
|
||||
#define RF_SUB_1_GHZ_CONF_BIAS_MODE RF_BIAS_MODE_EXTERNAL
|
||||
|
||||
#define RF_2_4_GHZ_CONF_FRONT_END_MODE RF_FRONT_END_MODE_DIFFERENTIAL
|
||||
#define RF_2_4_GHZ_CONF_BIAS_MODE RF_BIAS_MODE_EXTERNAL
|
||||
/** @} */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#endif /* RF_CONF_H_ */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
|
@ -33,15 +33,15 @@
|
|||
#ifndef __BOARD_H
|
||||
#define __BOARD_H
|
||||
|
||||
#define Board_CC2650DK_7ID
|
||||
#define BOARD_STRING "TI SmartRF06EB + CC26x0 EM"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "CC2650DK_7ID.h"
|
||||
|
||||
#define Board_CC2650DK_7ID
|
||||
#define BOARD_STRING "TI SmartRF06EB + CC26x0 EM"
|
||||
|
||||
#define Board_initGeneral() CC2650DK_7ID_initGeneral()
|
||||
#define Board_shutDownExtFlash() CC2650DK_7ID_shutDownExtFlash()
|
||||
#define Board_wakeUpExtFlash() CC2650DK_7ID_wakeUpExtFlash()
|
||||
|
|
|
@ -0,0 +1,65 @@
|
|||
/*
|
||||
* Copyright (c) 2018, Texas Instruments Incorporated - http://www.ti.com/
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the copyright holder nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
/**
|
||||
* \addtogroup launchpad-peripherals
|
||||
* @{
|
||||
*
|
||||
* \file
|
||||
* Header file with board-specific RF configurations.
|
||||
* \author
|
||||
* Texas Instruments <e2e.ti.com>
|
||||
* \note
|
||||
* This file should not be included directly
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#ifndef RF_CONF_H_
|
||||
#define RF_CONF_H_
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include "rf/rf.h"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \name Board-specific front-end mode configurations for the 2.4 GHz path
|
||||
* on the radio.
|
||||
*
|
||||
* These are the following front-end mode configurations for the
|
||||
* CC2650DK-7ID board:
|
||||
* - 2.4 GHz: differential and internal bias
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
#define RF_2_4_GHZ_CONF_FRONT_END_MODE RF_FRONT_END_MODE_DIFFERENTIAL
|
||||
#define RF_2_4_GHZ_CONF_BIAS_MODE RF_BIAS_MODE_INTERNAL
|
||||
/** @} */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#endif /* RF_CONF_H_ */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @}
|
||||
*/
|
|
@ -0,0 +1,145 @@
|
|||
|
||||
#
|
||||
# Currently enabling SMALL breaks the build on this platform.
|
||||
# No large effect is expected anyway: unused sections are discarded even if SMALL is not set.
|
||||
#
|
||||
SMALL=0
|
||||
|
||||
ARCH = leds.c xmem.c i2cmaster.c \
|
||||
spi-legacy.c cc2420.c cc2420-arch.c cc2420-arch-sfd.c\
|
||||
node-id-z1.c sensors.c button-sensor.c cfs-coffee.c \
|
||||
uart0.c uart0-putchar.c uip-ipchksum.c \
|
||||
slip.c slip_uart0.c z1-sensors.c adxl345.c temperature-sensor.c \
|
||||
z1-phidgets.c light-sensor.c battery-sensor.c sky-sensors.c tmp102.c \
|
||||
platform.c
|
||||
|
||||
CONTIKI_TARGET_DIRS = . dev apps
|
||||
ifndef CONTIKI_TARGET_MAIN
|
||||
CONTIKI_TARGET_MAIN = contiki-main.c
|
||||
endif
|
||||
|
||||
CONTIKI_TARGET_SOURCEFILES += $(ARCH)
|
||||
|
||||
MCU=msp430f2617
|
||||
CPU_HAS_MSP430X=1
|
||||
|
||||
LDFLAGS += -Wl,--defsym -Wl,__P1SEL2=0x0041 -Wl,--defsym -Wl,__P5SEL2=0x0045
|
||||
|
||||
ifdef nodemac
|
||||
CFLAGS += -DMACID=$(nodemac)
|
||||
endif
|
||||
|
||||
CFLAGS += -g
|
||||
|
||||
include $(ARCH_PATH)/cpu/msp430/Makefile.msp430
|
||||
|
||||
|
||||
NUMPAR=20
|
||||
IHEXFILE=tmpimage.ihex
|
||||
|
||||
ifeq ($(HOST_OS),Darwin)
|
||||
ifndef MOTELIST
|
||||
USBDEVPREFIX=
|
||||
SERIALDUMP = $(CONTIKI)/tools/sky/serialdump-linux
|
||||
MOTELIST = $(CONTIKI)/tools/zolertia/motelist-zolertia-macos
|
||||
BSL = $(CONTIKI)/tools/zolertia/z1-bsl-nopic --z1
|
||||
BSL_FILETYPE = -I
|
||||
MOTES = $(shell $(MOTELIST) -b z1 -c 2>&- | \
|
||||
cut -f 2 -d ,)
|
||||
REFNUM = $(shell $(MOTELIST) -c 2>&- | \
|
||||
cut -f 1 -d , | tail -c5 | sed 's/^0*//')
|
||||
ifneq (,$(REFNUM))
|
||||
# No device fo-und
|
||||
ifeq (,$(findstring und, $(REFNUM)))
|
||||
CFLAGS += -DSERIALNUM=$(REFNUM:0%=%)
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
else
|
||||
# If we are not running under Mac, we assume Linux
|
||||
ifndef MOTELIST
|
||||
USBDEVPREFIX=
|
||||
SERIALDUMP = $(CONTIKI)/tools/sky/serialdump-linux
|
||||
MOTELIST = $(CONTIKI)/tools/zolertia/motelist-zolertia
|
||||
BSL = $(CONTIKI)/tools/zolertia/z1-bsl-nopic --z1
|
||||
BSL_FILETYPE = -I
|
||||
MOTES = $(shell $(MOTELIST) -b z1 -c 2>&- | \
|
||||
cut -f 2 -d , | \
|
||||
perl -ne 'print $$1 . " " if(m-(/dev/\w+)-);')
|
||||
CMOTES=$(MOTES)
|
||||
REFNUM = $(shell $(MOTELIST) -c 2>&- | \
|
||||
cut -f 1 -d , | tail -c5 | sed 's/^0*//')
|
||||
ifneq (,$(REFNUM))
|
||||
# No device fo-und
|
||||
ifeq (,$(findstring und, $(REFNUM)))
|
||||
CFLAGS += -DSERIALNUM=$(REFNUM)
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
|
||||
motelist:
|
||||
$(MOTELIST)
|
||||
z1-motelist:
|
||||
$(MOTELIST) -b z1
|
||||
z1-motes:
|
||||
@echo $(MOTES)
|
||||
|
||||
ifdef MOTE
|
||||
%.upload: %.ihex
|
||||
cp $< $(IHEXFILE)
|
||||
$(MAKE) z1-u.$(subst /,-,$(word $(MOTE), $(MOTES)))
|
||||
else # MOTE
|
||||
%.upload: %.ihex
|
||||
cp $< $(IHEXFILE)
|
||||
@echo $(MOTES)
|
||||
$(MAKE) z1-reset z1-upload
|
||||
endif # MOTE
|
||||
|
||||
z1-upload: z1-reset
|
||||
$(MAKE) -j $(NUMPAR) z1-upload-sequence
|
||||
|
||||
z1-upload-sequence: $(foreach PORT, $(MOTES), z1-u.$(subst /,-,$(PORT)))
|
||||
@echo Done
|
||||
|
||||
z1-reset:
|
||||
$(MAKE) -k -j $(NUMPAR) z1-reset-sequence
|
||||
|
||||
z1-reset-sequence: $(foreach PORT, $(MOTES), z1-r.$(subst /,-,$(PORT)))
|
||||
@echo Done
|
||||
|
||||
z1-u.%:
|
||||
@echo +++++ Erasing $(subst -,/,$*); \
|
||||
$(BSL) -c $(subst -,/,$*) -e && sleep 2 ; \
|
||||
echo +++++ Programming $(subst -,/,$*) ; \
|
||||
$(BSL) -c $(subst -,/,$*) $(BSL_FILETYPE) -p $(IHEXFILE) && sleep 2 ; \
|
||||
echo +++++ Resetting $(subst -,/,$*) ; \
|
||||
$(BSL) -c $(subst -,/,$*) -r
|
||||
|
||||
z1-r.%:
|
||||
$(BSL) -c $(subst -,/,$*) -r
|
||||
|
||||
sizeplot:
|
||||
msp430-size $(OBJECTDIR)/*.o | $(CONTIKI)/tools/sky/check-size > size-data
|
||||
gnuplot $(CONTIKI)/tools/sky/plot-size
|
||||
gv size.pdf
|
||||
|
||||
winslip:
|
||||
ifdef INTERFACE
|
||||
$(CONTIKI)/tools/wpcapslip/wpcapslip -s $(USBDEVPREFIX)$(firstword $(CMOTES)) $(INTERFACE) 172.16.0.0 255.255.0.0
|
||||
else
|
||||
@echo "Usage: \"$(MAKE) $@ INTERFACE=<the IP address of a local network interface>\""
|
||||
@echo "Use the \"ipconfig\" command to find out the IP addresses of the local interfaces"
|
||||
endif
|
||||
|
||||
linslip: $(CONTIKI)/tools/tunslip
|
||||
$(CONTIKI)/tools/tunslip -s $(USBDEVPREFIX)$(firstword $(CMOTES)) 172.16.0.0 255.255.0.0
|
||||
|
||||
$(CONTIKI)/tools/tunslip:
|
||||
(cd $(CONTIKI)/tools; $(MAKE) tunslip)
|
||||
|
||||
ifdef MOTE
|
||||
PORT = $(USBDEVPREFIX)$(word $(MOTE), $(CMOTES))
|
||||
else
|
||||
PORT = $(USBDEVPREFIX)$(firstword $(CMOTES))
|
||||
endif
|
|
@ -0,0 +1,11 @@
|
|||
# Common Makefile between Z1 and Z1SP
|
||||
|
||||
CONTIKI_TARGET_SOURCEFILES += contiki-z1-platform.c
|
||||
|
||||
include $(ARCH_PATH)/platform/z1/Makefile.common
|
||||
|
||||
ifeq ($(ZOLERTIA_Z1SP),1)
|
||||
include $(ARCH_PATH)/platform/z1/Makefile.z1sp
|
||||
endif
|
||||
|
||||
MODULES += arch/dev/cc2420 os/storage/cfs
|
|
@ -0,0 +1,6 @@
|
|||
# Makefile for Z1 Starter Platform
|
||||
|
||||
# This is the actual flag we need to include specific Z1SP components
|
||||
CFLAGS += -DZ1_IS_Z1SP
|
||||
|
||||
CONTIKI_TARGET_SOURCEFILES += potentiometer-sensor.c
|
|
@ -0,0 +1,9 @@
|
|||
Using the Z1 starter platform (Z1SP)
|
||||
============================================
|
||||
|
||||
To enable the Z1SP components, you should include in your application Makefile
|
||||
the ZOLERTIA_Z1SP flag set to 1, see "examples/z1/Makefile".
|
||||
|
||||
For Z1SP specific information please go to:
|
||||
|
||||
http://zolertia.sourceforge.net/wiki/index.php/Mainpage:z1sp
|
|
@ -0,0 +1,83 @@
|
|||
/*
|
||||
* Copyright (c) 2006, Swedish Institute of Computer Science.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file
|
||||
* A program for burning a node ID into the flash ROM of a Tmote Sky node.
|
||||
* \author
|
||||
* Adam Dunkels <adam@sics.se>
|
||||
*/
|
||||
|
||||
#include "dev/leds.h"
|
||||
#include "dev/watchdog.h"
|
||||
#include "sys/node-id.h"
|
||||
#include "contiki.h"
|
||||
#include "sys/etimer.h"
|
||||
|
||||
#include "node-id-z1.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
static struct etimer etimer;
|
||||
|
||||
PROCESS(burn_process, "Burn node id");
|
||||
AUTOSTART_PROCESSES(&burn_process);
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS_THREAD(burn_process, ev, data)
|
||||
{
|
||||
PROCESS_BEGIN();
|
||||
|
||||
etimer_set(&etimer, 5*CLOCK_SECOND);
|
||||
PROCESS_WAIT_UNTIL(etimer_expired(&etimer));
|
||||
|
||||
watchdog_stop();
|
||||
leds_on(LEDS_RED);
|
||||
#if NODEID
|
||||
#warning "***** BURNING NODE ID"
|
||||
printf("Burning node id %d\n", NODEID);
|
||||
node_id_burn(NODEID);
|
||||
leds_on(LEDS_BLUE);
|
||||
node_id_restore();
|
||||
printf("Restored node id %d\n", node_id);
|
||||
#else
|
||||
#error "burn-nodeid must be compiled with nodeid=<the ID of the node>"
|
||||
node_id_restore();
|
||||
printf("Restored node id %d\n", node_id);
|
||||
#endif
|
||||
leds_off(LEDS_RED + LEDS_BLUE);
|
||||
watchdog_start();
|
||||
while(1) {
|
||||
PROCESS_WAIT_EVENT();
|
||||
}
|
||||
PROCESS_END();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
|
@ -0,0 +1,86 @@
|
|||
/*
|
||||
* Copyright (c) 2008, Swedish Institute of Computer Science
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file
|
||||
* Coffee architecture-dependent header for the Zolertia Z1 platform.
|
||||
* \author
|
||||
* Nicolas Tsiftes <nvt@sics.se>
|
||||
* Enric M. Calvo <ecalvo@zolertia.com>
|
||||
*/
|
||||
|
||||
#ifndef CFS_COFFEE_ARCH_H
|
||||
#define CFS_COFFEE_ARCH_H
|
||||
|
||||
#include "contiki-conf.h"
|
||||
#include "dev/xmem.h"
|
||||
|
||||
/*** M25P16 Memory Organization
|
||||
The memory is organized as:
|
||||
16Mbit = 2 097 152 bytes (8 bits each)
|
||||
32 sectors (512 Kbits, 65536 bytes each)
|
||||
8192 pages (256 bytes each).
|
||||
Each page can be individually programmed (bits are programmed from 1 to 0). The device is
|
||||
sector or bulk erasable (bits are erased from 0 to 1) but not page erasable
|
||||
*/
|
||||
|
||||
/* Total size of the External Flash Memory in the Z1 */
|
||||
#define COFFEE_XMEM_TOTAL_SIZE_KB 2048UL
|
||||
|
||||
/* Coffee configuration parameters. */
|
||||
#define COFFEE_SECTOR_SIZE 65536UL
|
||||
#define COFFEE_PAGE_SIZE 256UL
|
||||
#define COFFEE_START COFFEE_SECTOR_SIZE
|
||||
#define COFFEE_SIZE (COFFEE_XMEM_TOTAL_SIZE_KB * 1024UL - COFFEE_START)
|
||||
#define COFFEE_NAME_LENGTH 16
|
||||
#define COFFEE_MAX_OPEN_FILES 6
|
||||
#define COFFEE_FD_SET_SIZE 8
|
||||
#define COFFEE_LOG_TABLE_LIMIT 256
|
||||
#define COFFEE_DYN_SIZE 4*1024
|
||||
#define COFFEE_LOG_SIZE 1024
|
||||
|
||||
#define COFFEE_MICRO_LOGS 1
|
||||
|
||||
/* Flash operations. */
|
||||
#define COFFEE_WRITE(buf, size, offset) \
|
||||
xmem_pwrite((char *)(buf), (size), COFFEE_START + (offset))
|
||||
|
||||
#define COFFEE_READ(buf, size, offset) \
|
||||
xmem_pread((char *)(buf), (size), COFFEE_START + (offset))
|
||||
|
||||
#define COFFEE_ERASE(sector) \
|
||||
xmem_erase(COFFEE_SECTOR_SIZE, COFFEE_START + (sector) * COFFEE_SECTOR_SIZE)
|
||||
|
||||
/* Coffee types. */
|
||||
typedef int16_t coffee_page_t;
|
||||
|
||||
#endif /* !CFS_COFFEE_ARCH_H */
|
|
@ -0,0 +1,72 @@
|
|||
#ifndef CONTIKI_CONF_H
|
||||
#define CONTIKI_CONF_H
|
||||
|
||||
/* include the project config */
|
||||
#ifdef PROJECT_CONF_PATH
|
||||
#include PROJECT_CONF_PATH
|
||||
#endif /* PROJECT_CONF_PATH */
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include "z1-def.h"
|
||||
#include "msp430-def.h"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
/* Configure radio driver */
|
||||
#ifndef NETSTACK_CONF_RADIO
|
||||
#define NETSTACK_CONF_RADIO cc2420_driver
|
||||
#endif /* NETSTACK_CONF_RADIO */
|
||||
|
||||
/* Symbol for the TSCH 15ms timeslot timing template */
|
||||
#define TSCH_CONF_ARCH_HDR_PATH "dev/cc2420/cc2420-tsch-15ms.h"
|
||||
|
||||
/* The TSCH default slot length of 10ms is a bit too short for this platform,
|
||||
* use 15ms instead. */
|
||||
#ifndef TSCH_CONF_DEFAULT_TIMESLOT_TIMING
|
||||
#define TSCH_CONF_DEFAULT_TIMESLOT_TIMING tsch_timeslot_timing_us_15000
|
||||
#endif /* TSCH_CONF_DEFAULT_TIMESLOT_TIMING */
|
||||
|
||||
/* Save RAM through a smaller uIP buffer */
|
||||
#ifndef UIP_CONF_BUFFER_SIZE
|
||||
#define UIP_CONF_BUFFER_SIZE 140
|
||||
#endif
|
||||
|
||||
#define PROCESS_CONF_NUMEVENTS 8
|
||||
#define PROCESS_CONF_STATS 1
|
||||
/*#define PROCESS_CONF_FASTPOLL 4*/
|
||||
|
||||
/* So far, printfs without interrupt. */
|
||||
#define UART0_CONF_TX_WITH_INTERRUPT 0
|
||||
/* This does not work in Cooja. */
|
||||
#define UART0_CONF_RX_WITH_DMA 0
|
||||
|
||||
/* Handle 10 neighbors */
|
||||
#ifndef NBR_TABLE_CONF_MAX_NEIGHBORS
|
||||
#define NBR_TABLE_CONF_MAX_NEIGHBORS 10
|
||||
#endif
|
||||
|
||||
/* Handle 10 routes */
|
||||
#ifndef NETSTACK_MAX_ROUTE_ENTRIES
|
||||
#define NETSTACK_MAX_ROUTE_ENTRIES 10
|
||||
#endif
|
||||
|
||||
/* Handle 10 links */
|
||||
#ifndef TSCH_SCHEDULE_CONF_MAX_LINKS
|
||||
#define TSCH_SCHEDULE_CONF_MAX_LINKS 10
|
||||
#endif
|
||||
|
||||
#ifndef TSCH_CONF_MAX_INCOMING_PACKETS
|
||||
#define TSCH_CONF_MAX_INCOMING_PACKETS 2
|
||||
#endif
|
||||
|
||||
#ifndef TSCH_QUEUE_CONF_NUM_PER_NEIGHBOR
|
||||
#define TSCH_QUEUE_CONF_NUM_PER_NEIGHBOR 4
|
||||
#endif
|
||||
|
||||
/* Platform-specific (H/W) AES implementation */
|
||||
#ifndef AES_128_CONF
|
||||
#define AES_128_CONF cc2420_aes_128_driver
|
||||
#endif /* AES_128_CONF */
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include "msp430-conf.h"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#endif /* CONTIKI_CONF_H */
|
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* Copyright (c) 2011, Zolertia(TM) is a trademark of Advancare,SL
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
*
|
||||
* Author: Enric M. Calvo <ecalvo@zolertia.com> based on previous work by
|
||||
* Niclas Finne <nfi@sics.se>, Joakim Eriksson <joakime@sics.se>
|
||||
*
|
||||
*/
|
||||
|
||||
#include "dev/button-sensor.h"
|
||||
|
||||
void
|
||||
init_platform(void)
|
||||
{
|
||||
process_start(&sensors_process, NULL);
|
||||
}
|
|
@ -0,0 +1,411 @@
|
|||
/*
|
||||
* Copyright (c) 2010, Swedish Institute of Computer Science.
|
||||
* Copyright (c) 2016, Zolertia <http://www.zolertia.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \file
|
||||
* Device drivers for adxl345 accelerometer in Zolertia Z1.
|
||||
* \author
|
||||
* Marcus Lundén, SICS <mlunden@sics.se>
|
||||
* Enric M. Calvo, Zolertia <ecalvo@zolertia.com>
|
||||
* Antonio Lignan, Zolertia <alinan@zolertia.com>
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#include <stdio.h>
|
||||
#include "contiki.h"
|
||||
#include "adxl345.h"
|
||||
#include "cc2420.h"
|
||||
#include "i2cmaster.h"
|
||||
#include "isr_compat.h"
|
||||
#include "lib/sensors.h"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#define DEBUG 0
|
||||
#if DEBUG
|
||||
#define PRINTF(...) printf(__VA_ARGS__)
|
||||
#else
|
||||
#define PRINTF(...)
|
||||
#endif
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static uint8_t enabled;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* Callback pointers when interrupt occurs */
|
||||
void (*accm_int1_cb)(uint8_t reg);
|
||||
void (*accm_int2_cb)(uint8_t reg);
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* Bitmasks for the interrupts */
|
||||
static uint16_t int1_mask = 0, int2_mask = 0;
|
||||
|
||||
/* Default values for adxl345 at startup.
|
||||
* This will be sent to the adxl345 in a
|
||||
* stream at init to set it up in a default state
|
||||
*/
|
||||
|
||||
static uint8_t adxl345_default_settings[] = {
|
||||
/* Note, as the two first two bulks are to be written in a stream, they contain
|
||||
* the register address as first byte in that section.
|
||||
* 0--14 are in one stream, start at ADXL345_THRESH_TAP
|
||||
*/
|
||||
/* XXX NB Register address, not register value!! */
|
||||
ADXL345_THRESH_TAP,
|
||||
ADXL345_THRESH_TAP_DEFAULT,
|
||||
ADXL345_OFSX_DEFAULT,
|
||||
ADXL345_OFSY_DEFAULT,
|
||||
ADXL345_OFSZ_DEFAULT,
|
||||
ADXL345_DUR_DEFAULT,
|
||||
ADXL345_LATENT_DEFAULT,
|
||||
ADXL345_WINDOW_DEFAULT,
|
||||
ADXL345_THRESH_ACT_DEFAULT,
|
||||
ADXL345_THRESH_INACT_DEFAULT,
|
||||
ADXL345_TIME_INACT_DEFAULT,
|
||||
ADXL345_ACT_INACT_CTL_DEFAULT,
|
||||
ADXL345_THRESH_FF_DEFAULT,
|
||||
ADXL345_TIME_FF_DEFAULT,
|
||||
ADXL345_TAP_AXES_DEFAULT,
|
||||
|
||||
/* 15--19 start at ADXL345_BW_RATE */
|
||||
/* XXX NB Register address, not register value!! */
|
||||
ADXL345_BW_RATE,
|
||||
ADXL345_BW_RATE_DEFAULT,
|
||||
ADXL345_POWER_CTL_DEFAULT,
|
||||
ADXL345_INT_ENABLE_DEFAULT,
|
||||
ADXL345_INT_MAP_DEFAULT,
|
||||
|
||||
/* These two: 20, 21 write separately */
|
||||
ADXL345_DATA_FORMAT_DEFAULT,
|
||||
ADXL345_FIFO_CTL_DEFAULT
|
||||
};
|
||||
/*---------------------------------------------------------------------------*/
|
||||
PROCESS(accmeter_process, "Accelerometer process");
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
accm_write_reg(uint8_t reg, uint8_t val)
|
||||
{
|
||||
uint8_t tx_buf[] = {reg, val};
|
||||
|
||||
i2c_transmitinit(ADXL345_ADDR);
|
||||
while (i2c_busy());
|
||||
PRINTF("ADXL345: I2C Ready to TX\n");
|
||||
|
||||
i2c_transmit_n(2, tx_buf);
|
||||
while (i2c_busy());
|
||||
PRINTF("ADXL345: WRITE_REG 0x%02X @ reg 0x%02X\n", val, reg);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* First byte in stream must be the register address to begin writing to.
|
||||
* The data is then written from second byte and increasing.
|
||||
*/
|
||||
static void
|
||||
accm_write_stream(uint8_t len, uint8_t *data)
|
||||
{
|
||||
i2c_transmitinit(ADXL345_ADDR);
|
||||
while (i2c_busy());
|
||||
PRINTF("ADXL345: I2C Ready to TX(stream)\n");
|
||||
|
||||
i2c_transmit_n(len, data); // start tx and send conf reg
|
||||
while (i2c_busy());
|
||||
PRINTF("ADXL345: WRITE_STR %u B to 0x%02X\n", len, data[0]);
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static uint8_t
|
||||
accm_read_reg(uint8_t reg)
|
||||
{
|
||||
uint8_t retVal = 0;
|
||||
uint8_t rtx = reg;
|
||||
PRINTF("ADXL345: READ_REG 0x%02X\n", reg);
|
||||
|
||||
/* transmit the register to read */
|
||||
i2c_transmitinit(ADXL345_ADDR);
|
||||
while (i2c_busy());
|
||||
i2c_transmit_n(1, &rtx);
|
||||
while (i2c_busy());
|
||||
|
||||
/* receive the data */
|
||||
i2c_receiveinit(ADXL345_ADDR);
|
||||
while (i2c_busy());
|
||||
i2c_receive_n(1, &retVal);
|
||||
while (i2c_busy());
|
||||
|
||||
return retVal;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
accm_read_stream(uint8_t reg, uint8_t len, uint8_t *whereto)
|
||||
{
|
||||
uint8_t rtx = reg;
|
||||
PRINTF("ADXL345: READ_STR %u B from 0x%02X\n", len, reg);
|
||||
|
||||
/* transmit the register to start reading from */
|
||||
i2c_transmitinit(ADXL345_ADDR);
|
||||
while (i2c_busy());
|
||||
i2c_transmit_n(1, &rtx);
|
||||
while (i2c_busy());
|
||||
|
||||
/* receive the data */
|
||||
i2c_receiveinit(ADXL345_ADDR);
|
||||
while (i2c_busy());
|
||||
i2c_receive_n(len, whereto);
|
||||
while (i2c_busy());
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* Read an axis of the accelerometer (x, y or z). Return value is a signed
|
||||
* 10 bit int.
|
||||
* The resolution of the acceleration measurement can be increased up to 13 bit,
|
||||
* but will change the data format of this read out. Refer to the data sheet if
|
||||
* so is wanted/needed.
|
||||
*/
|
||||
int16_t
|
||||
accm_read_axis(enum ADXL345_AXIS axis)
|
||||
{
|
||||
int16_t rd = 0;
|
||||
uint8_t tmp[2];
|
||||
if(axis > Z_AXIS){
|
||||
return 0;
|
||||
}
|
||||
accm_read_stream(ADXL345_DATAX0 + axis, 2, &tmp[0]);
|
||||
rd = (int16_t)(tmp[0] | (tmp[1]<<8));
|
||||
return rd;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
int
|
||||
accm_set_grange(uint8_t grange)
|
||||
{
|
||||
uint8_t tempreg = 0;
|
||||
|
||||
if(grange > ADXL345_RANGE_16G) {
|
||||
PRINTF("ADXL345: grange invalid: %u\n", grange);
|
||||
return ADXL345_ERROR;
|
||||
}
|
||||
|
||||
if(!enabled) {
|
||||
return ADXL345_ERROR;
|
||||
}
|
||||
|
||||
/* Keep the previous contents of the register, zero out the last two bits */
|
||||
tempreg = (accm_read_reg(ADXL345_DATA_FORMAT) & 0xFC);
|
||||
tempreg |= grange;
|
||||
accm_write_reg(ADXL345_DATA_FORMAT, tempreg);
|
||||
return ADXL345_SUCCESS;
|
||||
}
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
accm_init(void)
|
||||
{
|
||||
PRINTF("ADXL345: init\n");
|
||||
accm_int1_cb = NULL;
|
||||
accm_int2_cb = NULL;
|
||||
|
||||
/* Set up ports and pins for interrups. */
|
||||
ADXL345_DIR &=~ (ADXL345_INT1_PIN | ADXL345_INT2_PIN);
|
||||
ADXL345_SEL &=~ (ADXL345_INT1_PIN | ADXL345_INT2_PIN);
|
||||
ADXL345_SEL2 &=~ (ADXL345_INT1_PIN | ADXL345_INT2_PIN);
|
||||
|
||||
/* Set up ports and pins for I2C communication */
|
||||
i2c_enable();
|
||||
|
||||
/* set default register values. */
|
||||
accm_write_stream(15, &adxl345_default_settings[0]);
|
||||
accm_write_stream(5, &adxl345_default_settings[15]);
|
||||
accm_write_reg(ADXL345_DATA_FORMAT, adxl345_default_settings[20]);
|
||||
accm_write_reg(ADXL345_FIFO_CTL, adxl345_default_settings[21]);
|
||||
|
||||
process_start(&accmeter_process, NULL);
|
||||
|
||||
/* Enable msp430 interrupts on the two interrupt pins. */
|
||||
dint();
|
||||
/* low to high transition interrupts */
|
||||
ADXL345_IES &=~ (ADXL345_INT1_PIN | ADXL345_INT2_PIN);
|
||||
/* enable interrupts */
|
||||
ADXL345_IE |= (ADXL345_INT1_PIN | ADXL345_INT2_PIN);
|
||||
eint();
|
||||
|
||||
enabled = 1;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
accm_stop(void)
|
||||
{
|
||||
dint();
|
||||
ADXL345_IE &= ~(ADXL345_INT1_PIN | ADXL345_INT2_PIN);
|
||||
accm_write_reg(ADXL345_INT_ENABLE, ~(int1_mask | int2_mask));
|
||||
accm_write_reg(ADXL345_INT_MAP, ~int2_mask);
|
||||
eint();
|
||||
enabled = 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
int
|
||||
accm_set_irq(uint8_t int1, uint8_t int2)
|
||||
{
|
||||
if(!enabled) {
|
||||
return ADXL345_ERROR;
|
||||
}
|
||||
|
||||
/* Set the corresponding interrupt mapping to INT1 or INT2 */
|
||||
PRINTF("ADXL345: IRQs set to INT1: 0x%02X IRQ2: 0x%02X\n", int1, int2);
|
||||
|
||||
int1_mask = int1;
|
||||
int2_mask = int2;
|
||||
|
||||
accm_write_reg(ADXL345_INT_ENABLE, (int1 | int2));
|
||||
/* int1 bits are zeroes in the map register so this is for both ints */
|
||||
accm_write_reg(ADXL345_INT_MAP, int2);
|
||||
return ADXL345_SUCCESS;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* Invoked after an interrupt happened. Reads the interrupt source reg at the
|
||||
* accelerometer, which resets the interrupts, and invokes the corresponding
|
||||
* callback. It passes the source register value so the callback can determine
|
||||
* what interrupt happened, if several interrupts are mapped to the same pin.
|
||||
*/
|
||||
static void
|
||||
poll_handler(void)
|
||||
{
|
||||
uint8_t ireg = 0;
|
||||
ireg = accm_read_reg(ADXL345_INT_SOURCE);
|
||||
|
||||
/* Invoke callbacks for the corresponding interrupts */
|
||||
if(ireg & int1_mask){
|
||||
if(accm_int1_cb != NULL){
|
||||
PRINTF("ADXL345: INT1 cb invoked\n");
|
||||
accm_int1_cb(ireg);
|
||||
}
|
||||
} else if(ireg & int2_mask){
|
||||
if(accm_int2_cb != NULL){
|
||||
PRINTF("ADXL345: INT2 cb invoked\n");
|
||||
accm_int2_cb(ireg);
|
||||
}
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* This process is sleeping until an interrupt from the accelerometer occurs,
|
||||
* which polls this process from the interrupt service routine. */
|
||||
PROCESS_THREAD(accmeter_process, ev, data)
|
||||
{
|
||||
PROCESS_POLLHANDLER(poll_handler());
|
||||
PROCESS_EXITHANDLER();
|
||||
PROCESS_BEGIN();
|
||||
while(1){
|
||||
PROCESS_WAIT_EVENT_UNTIL(0);
|
||||
}
|
||||
PROCESS_END();
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* This interrupt vector is shared with the interrupts from CC2420, so that
|
||||
* was moved here
|
||||
*/
|
||||
static struct timer suppressTimer1, suppressTimer2;
|
||||
|
||||
ISR(PORT1, port1_isr)
|
||||
{
|
||||
/* ADXL345_IFG.x goes high when interrupt occurs, use to check what
|
||||
* interrupted
|
||||
*/
|
||||
if((ADXL345_IFG & ADXL345_INT1_PIN) && !(ADXL345_IFG & BV(CC2420_FIFOP_PIN))){
|
||||
/* Check if this should be suppressed or not */
|
||||
if(timer_expired(&suppressTimer1)) {
|
||||
timer_set(&suppressTimer1, SUPPRESS_TIME_INT1);
|
||||
ADXL345_IFG &= ~ADXL345_INT1_PIN; // clear interrupt flag
|
||||
process_poll(&accmeter_process);
|
||||
LPM4_EXIT;
|
||||
}
|
||||
} else if((ADXL345_IFG & ADXL345_INT2_PIN) &&
|
||||
!(ADXL345_IFG & BV(CC2420_FIFOP_PIN))){
|
||||
/* Check if this should be suppressed or not */
|
||||
if(timer_expired(&suppressTimer2)) {
|
||||
timer_set(&suppressTimer2, SUPPRESS_TIME_INT2);
|
||||
/* clear interrupt flag */
|
||||
ADXL345_IFG &= ~ADXL345_INT2_PIN;
|
||||
process_poll(&accmeter_process);
|
||||
LPM4_EXIT;
|
||||
}
|
||||
} else {
|
||||
/* CC2420 interrupt */
|
||||
if(cc2420_interrupt()) {
|
||||
LPM4_EXIT;
|
||||
}
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
configure(int type, int value)
|
||||
{
|
||||
if(type != SENSORS_ACTIVE) {
|
||||
return ADXL345_ERROR;
|
||||
}
|
||||
|
||||
if(value) {
|
||||
accm_init();
|
||||
} else {
|
||||
accm_stop();
|
||||
}
|
||||
enabled = value;
|
||||
return ADXL345_SUCCESS;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
status(int type)
|
||||
{
|
||||
switch(type) {
|
||||
case SENSORS_ACTIVE:
|
||||
case SENSORS_READY:
|
||||
return enabled;
|
||||
}
|
||||
return ADXL345_SUCCESS;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
value(int type)
|
||||
{
|
||||
if(!enabled) {
|
||||
return ADXL345_ERROR;
|
||||
}
|
||||
|
||||
if((type != X_AXIS) && (type != Y_AXIS) && (type != Z_AXIS)) {
|
||||
return ADXL345_ERROR;
|
||||
}
|
||||
|
||||
switch(type) {
|
||||
case X_AXIS:
|
||||
return accm_read_axis(X_AXIS);
|
||||
case Y_AXIS:
|
||||
return accm_read_axis(Y_AXIS);
|
||||
case Z_AXIS:
|
||||
return accm_read_axis(Z_AXIS);
|
||||
default:
|
||||
return ADXL345_ERROR;
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
SENSORS_SENSOR(adxl345, ADXL345_SENSOR, value, configure, status);
|
||||
/*---------------------------------------------------------------------------*/
|
|
@ -0,0 +1,246 @@
|
|||
/*
|
||||
* Copyright (c) 2010, Swedish Institute of Computer Science.
|
||||
* Copyright (c) 2016, Zolertia <http://www.zolertia.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/**
|
||||
* \file
|
||||
* Device drivers header file for adxl345 accelerometer in Zolertia Z1.
|
||||
* \author
|
||||
* Marcus Lundén, SICS <mlunden@sics.se>
|
||||
* Enric Calvo, Zolertia <ecalvo@zolertia.com>
|
||||
* Antonio Lignan, Zolertia <alinan@zolertia.com>
|
||||
*/
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#ifndef ADXL345_H_
|
||||
#define ADXL345_H_
|
||||
#include <stdio.h>
|
||||
#include "dev/i2cmaster.h"
|
||||
#include "lib/sensors.h"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* Used in accm_read_axis(), eg accm_read_axis(X_AXIS) */
|
||||
enum ADXL345_AXIS {
|
||||
X_AXIS = 0,
|
||||
Y_AXIS = 2,
|
||||
Z_AXIS = 4,
|
||||
};
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* Init the accelerometer: ports, pins, registers, interrupts (none enabled),
|
||||
* I2C, default threshold values etc.
|
||||
*/
|
||||
void accm_init(void);
|
||||
|
||||
/* Read an axis of the accelerometer (x, y or z). Return value is a signed 10
|
||||
* bit int.
|
||||
* The resolution of the acceleration measurement can be increased up to 13 bit,
|
||||
* but will change the data format of this read out. Refer to the data sheet if
|
||||
* so is wanted/needed.
|
||||
*/
|
||||
int16_t accm_read_axis(enum ADXL345_AXIS axis);
|
||||
|
||||
/* Sets the g-range, ie the range the accelerometer measures (ie 2g means -2 to
|
||||
* +2 g on every axis). Possible values:
|
||||
* - ADXL345_RANGE_2G
|
||||
* - ADXL345_RANGE_4G
|
||||
* - ADXL345_RANGE_8G
|
||||
* - ADXL345_RANGE_16G
|
||||
*/
|
||||
int accm_set_grange(uint8_t grange);
|
||||
|
||||
/* Map interrupt (FF, tap, dbltap etc) to interrupt pin (IRQ_INT1, IRQ_INT2).
|
||||
* This must come after accm_init() as the registers will otherwise be
|
||||
* overwritten.
|
||||
*/
|
||||
int accm_set_irq(uint8_t int1, uint8_t int2);
|
||||
|
||||
/* Macros for setting the pointers to callback functions from the interrupts.
|
||||
* The function will be called with an uint8_t as parameter, containing the
|
||||
* interrupt flag register from the ADXL345. That way, several interrupts can be
|
||||
* mapped to the same pin and be read
|
||||
*/
|
||||
#define ACCM_REGISTER_INT1_CB(ptr) accm_int1_cb = ptr;
|
||||
#define ACCM_REGISTER_INT2_CB(ptr) accm_int2_cb = ptr;
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* Application definitions, change if required by application. */
|
||||
|
||||
/* Time after an interrupt that subsequent interrupts are suppressed. Should
|
||||
* later be turned into one specific time per type of interrupt (tap, freefall.
|
||||
* etc)
|
||||
*/
|
||||
#define SUPPRESS_TIME_INT1 CLOCK_SECOND/4
|
||||
#define SUPPRESS_TIME_INT2 CLOCK_SECOND/4
|
||||
|
||||
/* Suggested defaults according to the data sheet etc */
|
||||
#define ADXL345_THRESH_TAP_DEFAULT 0x48 /* 4.5g (0x30 == 3.0g) */
|
||||
#define ADXL345_OFSX_DEFAULT 0x00 /* for calibration only */
|
||||
#define ADXL345_OFSY_DEFAULT 0x00
|
||||
#define ADXL345_OFSZ_DEFAULT 0x00
|
||||
#define ADXL345_DUR_DEFAULT 0x20 /* 20 ms (datasheet: 10ms++) */
|
||||
#define ADXL345_LATENT_DEFAULT 0x50 /* 100 ms (datasheet: 20ms++) */
|
||||
#define ADXL345_WINDOW_DEFAULT 0xFF /* 320 ms (datasheet: 80ms++) */
|
||||
#define ADXL345_THRESH_ACT_DEFAULT 0x15 /* 1.3g (62.5 mg/LSB) */
|
||||
#define ADXL345_THRESH_INACT_DEFAULT 0x08 /* 0.5g (62.5 mg/LSB) */
|
||||
#define ADXL345_TIME_INACT_DEFAULT 0x02 /* 2 s (1 s/LSB) */
|
||||
#define ADXL345_ACT_INACT_CTL_DEFAULT 0xFF /* all axis, ac-coupled */
|
||||
#define ADXL345_THRESH_FF_DEFAULT 0x09 /* 563 mg */
|
||||
#define ADXL345_TIME_FF_DEFAULT 0x20 /* 60 ms */
|
||||
#define ADXL345_TAP_AXES_DEFAULT 0x07 /* all axis, no suppression */
|
||||
|
||||
#define ADXL345_BW_RATE_DEFAULT (0x00 | ADXL345_SRATE_100) /* 100 Hz */
|
||||
/* link bit set, no autosleep, start normal measuring */
|
||||
#define ADXL345_POWER_CTL_DEFAULT 0x28
|
||||
#define ADXL345_INT_ENABLE_DEFAULT 0x00 /* no interrupts enabled */
|
||||
#define ADXL345_INT_MAP_DEFAULT 0x00 /* all mapped to int_1 */
|
||||
|
||||
/* XXX NB: In the data format register, data format of axis readings is chosen
|
||||
* between left or right justify. This affects the position of the MSB/LSB and is
|
||||
* different depending on g-range and resolution. If changed, make sure this is
|
||||
* reflected in the _read_axis() function. Also, the resolution can be increased
|
||||
* from 10 bit to at most 13 bit, but this also changes position of MSB etc on data
|
||||
* format so check this in read_axis() too.
|
||||
*/
|
||||
/* right-justify, 2g, 10-bit mode, int is active high */
|
||||
#define ADXL345_DATA_FORMAT_DEFAULT (0x00 | ADXL345_RANGE_2G)
|
||||
#define ADXL345_FIFO_CTL_DEFAULT 0x00 /* FIFO bypass mode */
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* Reference definitions, should not be changed */
|
||||
/* adxl345 slave address */
|
||||
#define ADXL345_ADDR 0x53
|
||||
|
||||
/* ADXL345 registers */
|
||||
#define ADXL345_DEVID 0x00
|
||||
/* registers 0x01 to 0x1C are reserved, do not access */
|
||||
#define ADXL345_THRESH_TAP 0x1D
|
||||
#define ADXL345_OFSX 0x1E
|
||||
#define ADXL345_OFSY 0x1F
|
||||
#define ADXL345_OFSZ 0x20
|
||||
#define ADXL345_DUR 0x21
|
||||
#define ADXL345_LATENT 0x22
|
||||
#define ADXL345_WINDOW 0x23
|
||||
#define ADXL345_THRESH_ACT 0x24
|
||||
#define ADXL345_THRESH_INACT 0x25
|
||||
#define ADXL345_TIME_INACT 0x26
|
||||
#define ADXL345_ACT_INACT_CTL 0x27
|
||||
#define ADXL345_THRESH_FF 0x28
|
||||
#define ADXL345_TIME_FF 0x29
|
||||
#define ADXL345_TAP_AXES 0x2A
|
||||
#define ADXL345_ACT_TAP_STATUS 0x2B
|
||||
#define ADXL345_BW_RATE 0x2C
|
||||
#define ADXL345_POWER_CTL 0x2D
|
||||
#define ADXL345_INT_ENABLE 0x2E
|
||||
#define ADXL345_INT_MAP 0x2F
|
||||
#define ADXL345_INT_SOURCE 0x30
|
||||
#define ADXL345_DATA_FORMAT 0x31
|
||||
#define ADXL345_DATAX0 0x32 /* read only, LSByte X, two's complement */
|
||||
#define ADXL345_DATAX1 0x33 /* read only, MSByte X */
|
||||
#define ADXL345_DATAY0 0x34 /* read only, LSByte Y */
|
||||
#define ADXL345_DATAY1 0x35 /* read only, MSByte X */
|
||||
#define ADXL345_DATAZ0 0x36 /* read only, LSByte Z */
|
||||
#define ADXL345_DATAZ1 0x37 /* read only, MSByte X */
|
||||
#define ADXL345_FIFO_CTL 0x38
|
||||
#define ADXL345_FIFO_STATUS 0x39 /* read only */
|
||||
|
||||
/* ADXL345 interrupts */
|
||||
#define ADXL345_INT_DISABLE 0X00 /* used for disabling interrupts */
|
||||
#define ADXL345_INT_OVERRUN 0X01
|
||||
#define ADXL345_INT_WATERMARK 0X02
|
||||
#define ADXL345_INT_FREEFALL 0X04
|
||||
#define ADXL345_INT_INACTIVITY 0X08
|
||||
#define ADXL345_INT_ACTIVITY 0X10
|
||||
#define ADXL345_INT_DOUBLETAP 0X20
|
||||
#define ADXL345_INT_TAP 0X40
|
||||
#define ADXL345_INT_DATAREADY 0X80
|
||||
|
||||
/* Accelerometer hardware ports, pins and registers on the msp430 µC */
|
||||
#define ADXL345_DIR P1DIR
|
||||
#define ADXL345_PIN P1PIN
|
||||
#define ADXL345_REN P1REN
|
||||
#define ADXL345_SEL P1SEL
|
||||
#define ADXL345_SEL2 P1SEL2
|
||||
#define ADXL345_INT1_PIN (1<<6) /* P1.6 */
|
||||
#define ADXL345_INT2_PIN (1<<7) /* P1.7 */
|
||||
#define ADXL345_IES P1IES
|
||||
#define ADXL345_IE P1IE
|
||||
#define ADXL345_IFG P1IFG
|
||||
#define ADXL345_VECTOR PORT1_VECTOR
|
||||
|
||||
/* g-range for DATA_FORMAT register */
|
||||
#define ADXL345_RANGE_2G 0x00
|
||||
#define ADXL345_RANGE_4G 0x01
|
||||
#define ADXL345_RANGE_8G 0x02
|
||||
#define ADXL345_RANGE_16G 0x03
|
||||
|
||||
|
||||
/* The adxl345 has programmable sample rates, but unexpected results may occur
|
||||
* if the wrong rate and I2C bus speed is used (see datasheet p 17). Sample
|
||||
* rates in Hz. This setting does not change the internal sampling rate, just
|
||||
* how often it is piped to the output registers (ie the interrupt features use
|
||||
* the full sample rate internally).
|
||||
* Example use:
|
||||
* adxl345_set_reg(ADXL345_BW_RATE, ((_ADXL345_STATUS & LOW_POWER)
|
||||
* | ADXL345_SRATE_50));
|
||||
*/
|
||||
|
||||
/* XXX NB don't use at all as I2C data rate<= 400kHz */
|
||||
#define ADXL345_SRATE_3200 0x0F
|
||||
/* XXX NB don't use at all as I2C data rate<= 400kHz */
|
||||
#define ADXL345_SRATE_1600 0x0E
|
||||
#define ADXL345_SRATE_800 0x0D /* when I2C data rate == 400 kHz */
|
||||
#define ADXL345_SRATE_400 0x0C /* when I2C data rate == 400 kHz */
|
||||
#define ADXL345_SRATE_200 0x0B /* when I2C data rate >= 100 kHz */
|
||||
#define ADXL345_SRATE_100 0x0A /* when I2C data rate >= 100 kHz */
|
||||
#define ADXL345_SRATE_50 0x09 /* when I2C data rate >= 100 kHz */
|
||||
#define ADXL345_SRATE_25 0x08 /* when I2C data rate >= 100 kHz */
|
||||
#define ADXL345_SRATE_12_5 0x07 /* 12.5 Hz, when I2C data rate >= 100 kHz */
|
||||
#define ADXL345_SRATE_6_25 0x06 /* when I2C data rate >= 100 kHz */
|
||||
#define ADXL345_SRATE_3_13 0x05 /* when I2C data rate >= 100 kHz */
|
||||
#define ADXL345_SRATE_1_56 0x04 /* when I2C data rate >= 100 kHz */
|
||||
#define ADXL345_SRATE_0_78 0x03 /* when I2C data rate >= 100 kHz */
|
||||
#define ADXL345_SRATE_0_39 0x02 /* when I2C data rate >= 100 kHz */
|
||||
#define ADXL345_SRATE_0_20 0x01 /* when I2C data rate >= 100 kHz */
|
||||
#define ADXL345_SRATE_0_10 0x00 /* 0.10 Hz, when I2C data rate >= 100 kHz */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* Callback pointers for the interrupts */
|
||||
extern void (*accm_int1_cb)(uint8_t reg);
|
||||
extern void (*accm_int2_cb)(uint8_t reg);
|
||||
/* -------------------------------------------------------------------------- */
|
||||
#define ACCM_INT1 0x01
|
||||
#define ACCM_INT2 0x02
|
||||
#define ADXL345_SUCCESS 0x00
|
||||
#define ADXL345_ERROR (-1)
|
||||
/* -------------------------------------------------------------------------- */
|
||||
#define ADXL345_SENSOR "ADXL345 sensor"
|
||||
/* -------------------------------------------------------------------------- */
|
||||
extern const struct sensors_sensor adxl345;
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
#endif /* ifndef ADXL345_H_ */
|
|
@ -0,0 +1,67 @@
|
|||
/*
|
||||
* Copyright (c) 2006, Swedish Institute of Computer Science.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
*
|
||||
* -----------------------------------------------------------------
|
||||
*
|
||||
* Author : Adam Dunkels, Joakim Eriksson, Niclas Finne
|
||||
* Created : 2005-11-01
|
||||
* Updated : $Date: 2010/08/25 19:30:52 $
|
||||
* $Revision: 1.11 $
|
||||
*/
|
||||
#include "contiki.h"
|
||||
#include "dev/battery-sensor.h"
|
||||
#include "dev/sky-sensors.h"
|
||||
|
||||
/* Configure ADC12_2 to sample channel 11 (voltage) and use */
|
||||
/* the Vref+ as reference (SREF_1) since it is a stable reference */
|
||||
#define INPUT_CHANNEL (1 << INCH_11)
|
||||
#define INPUT_REFERENCE SREF_1
|
||||
#define BATTERY_MEM ADC12MEM11
|
||||
|
||||
const struct sensors_sensor battery_sensor;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
value(int type)
|
||||
{
|
||||
return BATTERY_MEM;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
configure(int type, int c)
|
||||
{
|
||||
return sky_sensors_configure(INPUT_CHANNEL, INPUT_REFERENCE, type, c);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
status(int type)
|
||||
{
|
||||
return sky_sensors_status(INPUT_CHANNEL, type);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
SENSORS_SENSOR(battery_sensor, BATTERY_SENSOR, value, configure, status);
|
|
@ -0,0 +1,101 @@
|
|||
/*
|
||||
* Copyright (c) 2005, Swedish Institute of Computer Science
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "contiki.h"
|
||||
#include "lib/sensors.h"
|
||||
#include "dev/hwconf.h"
|
||||
#include "dev/button-sensor.h"
|
||||
#include "isr_compat.h"
|
||||
|
||||
const struct sensors_sensor button_sensor;
|
||||
|
||||
static struct timer debouncetimer;
|
||||
static int status(int type);
|
||||
|
||||
HWCONF_PIN(BUTTON, 2, 5);
|
||||
HWCONF_IRQ(BUTTON, 2, 5);
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
ISR(PORT2, irq_p2)
|
||||
{
|
||||
if(BUTTON_CHECK_IRQ()) {
|
||||
if(timer_expired(&debouncetimer)) {
|
||||
timer_set(&debouncetimer, CLOCK_SECOND / 4);
|
||||
sensors_changed(&button_sensor);
|
||||
LPM4_EXIT;
|
||||
}
|
||||
}
|
||||
P2IFG = 0x00;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
value(int type)
|
||||
{
|
||||
return BUTTON_READ() || !timer_expired(&debouncetimer);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
configure(int type, int c)
|
||||
{
|
||||
switch (type) {
|
||||
case SENSORS_ACTIVE:
|
||||
if (c) {
|
||||
if(!status(SENSORS_ACTIVE)) {
|
||||
timer_set(&debouncetimer, 0);
|
||||
BUTTON_IRQ_EDGE_SELECTD();
|
||||
|
||||
BUTTON_SELECT();
|
||||
BUTTON_MAKE_INPUT();
|
||||
|
||||
BUTTON_ENABLE_IRQ();
|
||||
}
|
||||
} else {
|
||||
BUTTON_DISABLE_IRQ();
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
status(int type)
|
||||
{
|
||||
switch (type) {
|
||||
case SENSORS_ACTIVE:
|
||||
case SENSORS_READY:
|
||||
return BUTTON_IRQ_ENABLED();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
SENSORS_SENSOR(button_sensor, BUTTON_SENSOR,
|
||||
value, configure, status);
|
|
@ -0,0 +1,76 @@
|
|||
/*
|
||||
* Copyright (c) 2006, Swedish Institute of Computer Science
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "contiki.h"
|
||||
#include "contiki-net.h"
|
||||
#include "dev/spi-legacy.h"
|
||||
#include "cc2420.h"
|
||||
#include "isr_compat.h"
|
||||
|
||||
#ifdef CC2420_CONF_SFD_TIMESTAMPS
|
||||
#define CONF_SFD_TIMESTAMPS CC2420_CONF_SFD_TIMESTAMPS
|
||||
#endif /* CC2420_CONF_SFD_TIMESTAMPS */
|
||||
|
||||
#ifndef CONF_SFD_TIMESTAMPS
|
||||
#define CONF_SFD_TIMESTAMPS 0
|
||||
#endif /* CONF_SFD_TIMESTAMPS */
|
||||
|
||||
#ifdef CONF_SFD_TIMESTAMPS
|
||||
#include "cc2420-arch-sfd.h"
|
||||
#endif /* CONF_SFD_TIMESTAMPS */
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#if 0
|
||||
/* this is now handled in the ADXL345 accelerometer code as it uses irq on port1 too. */
|
||||
ISR(CC2420_IRQ, cc24240_port1_interrupt)
|
||||
{
|
||||
if(cc2420_interrupt()) {
|
||||
LPM4_EXIT;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
cc2420_arch_init(void)
|
||||
{
|
||||
spi_init();
|
||||
|
||||
/* all input by default, set these as output */
|
||||
CC2420_CSN_PORT(DIR) |= BV(CC2420_CSN_PIN);
|
||||
CC2420_VREG_PORT(DIR) |= BV(CC2420_VREG_PIN);
|
||||
CC2420_RESET_PORT(DIR) |= BV(CC2420_RESET_PIN);
|
||||
|
||||
#if CONF_SFD_TIMESTAMPS
|
||||
cc2420_arch_sfd_init();
|
||||
#endif /* CONF_SFD_TIMESTAMPS */
|
||||
|
||||
CC2420_SPI_DISABLE(); /* Unselect radio. */
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
|
@ -0,0 +1,228 @@
|
|||
/*
|
||||
* Copyright (c) 2010, Swedish Institute of Computer Science.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file
|
||||
* I2C communication device drivers for Zolertia Z1 sensor node.
|
||||
* \author
|
||||
* Enric M. Calvo, Zolertia <ecalvo@zolertia.com>
|
||||
* Marcus Lundén, SICS <mlunden@sics.se>
|
||||
*/
|
||||
|
||||
#include "i2cmaster.h"
|
||||
#include "isr_compat.h"
|
||||
|
||||
signed char tx_byte_ctr, rx_byte_ctr;
|
||||
unsigned char rx_buf[2];
|
||||
unsigned char *tx_buf_ptr;
|
||||
unsigned char *rx_buf_ptr;
|
||||
unsigned char receive_data;
|
||||
unsigned char transmit_data1;
|
||||
unsigned char transmit_data2;
|
||||
unsigned char prescale_lsb = I2C_PRESC_Z1_LSB;
|
||||
unsigned char prescale_msb = I2C_PRESC_Z1_MSB;
|
||||
volatile unsigned int i; /* volatile to prevent optimization */
|
||||
|
||||
/* ------------------------------------------------------------------------------
|
||||
* Change the data rate prior initializing transmission or reception
|
||||
* ----------------------------------------------------------------------------- */
|
||||
void
|
||||
i2c_setrate(uint8_t p_lsb, uint8_t p_msb)
|
||||
{
|
||||
prescale_lsb = p_lsb;
|
||||
prescale_lsb = p_msb;
|
||||
}
|
||||
/* ------------------------------------------------------------------------------
|
||||
* This function initializes the USCI module for master-receive operation.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
void
|
||||
i2c_receiveinit(uint8_t slave_address)
|
||||
{
|
||||
UCB1CTL1 = UCSWRST; /* Enable SW reset */
|
||||
UCB1CTL0 = UCMST + UCMODE_3 + UCSYNC; /* I2C Master, synchronous mode */
|
||||
UCB1CTL1 = UCSSEL_2 | UCSWRST; /* Use SMCLK, keep SW reset */
|
||||
UCB1BR0 = prescale_lsb; /* prescaler (default 400 kHz) */
|
||||
UCB1BR1 = prescale_msb;
|
||||
UCB1I2CSA = slave_address; /* set slave address */
|
||||
UCB1CTL1 &= ~UCTR; /* I2C Receiver */
|
||||
UCB1CTL1 &= ~UCSWRST; /* Clear SW reset, resume operation */
|
||||
UCB1I2CIE = UCNACKIE;
|
||||
#if I2C_RX_WITH_INTERRUPT
|
||||
UC1IE = UCB1RXIE; /* Enable RX interrupt if desired */
|
||||
#endif
|
||||
}
|
||||
/* ------------------------------------------------------------------------------
|
||||
* Initializes USCI for master-transmit operation.
|
||||
* ------------------------------------------------------------------------------ */
|
||||
void
|
||||
i2c_transmitinit(uint8_t slave_address)
|
||||
{
|
||||
UCB1CTL1 |= UCSWRST; /* Enable SW reset */
|
||||
UCB1CTL0 |= (UCMST | UCMODE_3 | UCSYNC); /* I2C Master, synchronous mode */
|
||||
UCB1CTL1 = UCSSEL_2 + UCSWRST; /* Use SMCLK, keep SW reset */
|
||||
UCB1BR0 = prescale_lsb; /* prescaler (default 400 kHz) */
|
||||
UCB1BR1 = prescale_msb;
|
||||
UCB1I2CSA = slave_address; /* Set slave address */
|
||||
UCB1CTL1 &= ~UCSWRST; /* Clear SW reset, resume operation */
|
||||
UCB1I2CIE = UCNACKIE;
|
||||
UC1IE = UCB1TXIE; /* Enable TX ready interrupt */
|
||||
}
|
||||
/* ------------------------------------------------------------------------------
|
||||
* This function is used to start an I2C communication in master-receiver mode WITHOUT INTERRUPTS
|
||||
* for more than 1 byte
|
||||
* ------------------------------------------------------------------------------ */
|
||||
static volatile uint8_t rx_byte_tot = 0;
|
||||
uint8_t
|
||||
i2c_receive_n(uint8_t byte_ctr, uint8_t *rx_buf)
|
||||
{
|
||||
|
||||
rx_byte_tot = byte_ctr;
|
||||
rx_byte_ctr = byte_ctr;
|
||||
rx_buf_ptr = rx_buf;
|
||||
|
||||
while((UCB1CTL1 & UCTXSTT) || (UCB1STAT & UCNACKIFG)) /* Slave acks address or not? */
|
||||
PRINTFDEBUG("____ UCTXSTT not clear OR NACK received\n");
|
||||
|
||||
#if I2C_RX_WITH_INTERRUPT
|
||||
PRINTFDEBUG(" RX Interrupts: YES \n");
|
||||
|
||||
/* SPECIAL-CASE: Stop condition must be sent while receiving the 1st byte for 1-byte only read operations */
|
||||
if(rx_byte_tot == 1) { /* See page 537 of slau144e.pdf */
|
||||
dint();
|
||||
UCB1CTL1 |= UCTXSTT; /* I2C start condition */
|
||||
while(UCB1CTL1 & UCTXSTT) /* Waiting for Start bit to clear */
|
||||
PRINTFDEBUG("____ STT clear wait\n");
|
||||
UCB1CTL1 |= UCTXSTP; /* I2C stop condition */
|
||||
eint();
|
||||
} else { /* all other cases */
|
||||
UCB1CTL1 |= UCTXSTT; /* I2C start condition */
|
||||
}
|
||||
return 0;
|
||||
|
||||
#else
|
||||
uint8_t n_received = 0;
|
||||
|
||||
PRINTFDEBUG(" RX Interrupts: NO \n");
|
||||
|
||||
UCB1CTL1 |= UCTXSTT; /* I2C start condition */
|
||||
|
||||
while(rx_byte_ctr > 0) {
|
||||
if(UC1IFG & UCB1RXIFG) { /* Waiting for Data */
|
||||
rx_buf[rx_byte_tot - rx_byte_ctr] = UCB1RXBUF;
|
||||
rx_byte_ctr--;
|
||||
UC1IFG &= ~UCB1RXIFG; /* Clear USCI_B1 RX int flag */
|
||||
n_received++;
|
||||
}
|
||||
}
|
||||
UCB1CTL1 |= UCTXSTP; /* I2C stop condition */
|
||||
return n_received;
|
||||
#endif
|
||||
}
|
||||
/* ------------------------------------------------------------------------------
|
||||
* This function is used to check if there is communication in progress.
|
||||
* ------------------------------------------------------------------------------ */
|
||||
uint8_t
|
||||
i2c_busy(void)
|
||||
{
|
||||
return UCB1STAT & UCBBUSY;
|
||||
}
|
||||
/*----------------------------------------------------------------------------
|
||||
* Setup ports and pins for I2C use.
|
||||
* ------------------------------------------------------------------------------ */
|
||||
|
||||
void
|
||||
i2c_enable(void)
|
||||
{
|
||||
I2C_PxSEL |= (I2C_SDA | I2C_SCL); /* Secondary function (USCI) selected */
|
||||
I2C_PxSEL2 |= (I2C_SDA | I2C_SCL); /* Secondary function (USCI) selected */
|
||||
I2C_PxDIR |= I2C_SCL; /* SCL is output (not needed?) */
|
||||
I2C_PxDIR &= ~I2C_SDA; /* SDA is input (not needed?) */
|
||||
I2C_PxREN |= (I2C_SDA | I2C_SCL); /* Activate internal pull-up/-down resistors */
|
||||
I2C_PxOUT |= (I2C_SDA | I2C_SCL); /* Select pull-up resistors */
|
||||
}
|
||||
void
|
||||
i2c_disable(void)
|
||||
{
|
||||
I2C_PxSEL &= ~(I2C_SDA | I2C_SCL); /* GPIO function selected */
|
||||
I2C_PxSEL2 &= ~(I2C_SDA | I2C_SCL); /* GPIO function selected */
|
||||
I2C_PxREN &= ~(I2C_SDA | I2C_SCL); /* Deactivate internal pull-up/-down resistors */
|
||||
I2C_PxOUT &= ~(I2C_SDA | I2C_SCL); /* Select pull-up resistors */
|
||||
}
|
||||
/* ------------------------------------------------------------------------------
|
||||
* This function is used to start an I2C communication in master-transmit mode.
|
||||
* ------------------------------------------------------------------------------ */
|
||||
static volatile uint8_t tx_byte_tot = 0;
|
||||
void
|
||||
i2c_transmit_n(uint8_t byte_ctr, uint8_t *tx_buf)
|
||||
{
|
||||
tx_byte_tot = byte_ctr;
|
||||
tx_byte_ctr = byte_ctr;
|
||||
tx_buf_ptr = tx_buf;
|
||||
UCB1CTL1 |= UCTR + UCTXSTT; /* I2C TX, start condition */
|
||||
}
|
||||
/*----------------------------------------------------------------------------*/
|
||||
ISR(USCIAB1TX, i2c_tx_interrupt)
|
||||
{
|
||||
/* TX Part */
|
||||
if(UC1IFG & UCB1TXIFG) { /* TX int. condition */
|
||||
if(tx_byte_ctr == 0) {
|
||||
UCB1CTL1 |= UCTXSTP; /* I2C stop condition */
|
||||
UC1IFG &= ~UCB1TXIFG; /* Clear USCI_B1 TX int flag */
|
||||
} else {
|
||||
UCB1TXBUF = tx_buf_ptr[tx_byte_tot - tx_byte_ctr];
|
||||
tx_byte_ctr--;
|
||||
}
|
||||
}
|
||||
/* RX Part */
|
||||
#if I2C_RX_WITH_INTERRUPT
|
||||
else if(UC1IFG & UCB1RXIFG) { /* RX int. condition */
|
||||
rx_buf_ptr[rx_byte_tot - rx_byte_ctr] = UCB1RXBUF;
|
||||
rx_byte_ctr--;
|
||||
if(rx_byte_ctr == 1) { /* stop condition should be set before receiving last byte */
|
||||
/* Only for 1-byte transmissions, STOP is handled in receive_n_int */
|
||||
if(rx_byte_tot != 1) {
|
||||
UCB1CTL1 |= UCTXSTP; /* I2C stop condition */
|
||||
}
|
||||
UC1IFG &= ~UCB1RXIFG; /* Clear USCI_B1 RX int flag. XXX Just in case, check if necessary */
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
ISR(USCIAB1RX, i2c_rx_interrupt)
|
||||
{
|
||||
if(UCB1STAT & UCNACKIFG) {
|
||||
PRINTFDEBUG("!!! NACK received in RX\n");
|
||||
UCB1CTL1 |= UCTXSTP;
|
||||
UCB1STAT &= ~UCNACKIFG;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,65 @@
|
|||
/*
|
||||
* Copyright (c) 2010, Swedish Institute of Computer Science.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file
|
||||
* I2C communication device driver header file for Zolertia Z1 sensor node.
|
||||
* \author
|
||||
* Enric Calvo, Zolertia <ecalvo@zolertia.com>
|
||||
* Marcus Lundén, SICS <mlunden@sics.se>
|
||||
*/
|
||||
|
||||
#ifndef I2CMASTER_H_
|
||||
#define I2CMASTER_H_
|
||||
|
||||
#include "contiki.h"
|
||||
|
||||
void i2c_enable(void);
|
||||
void i2c_disable(void);
|
||||
|
||||
void i2c_receiveinit(uint8_t slave_address);
|
||||
uint8_t i2c_receive_n(uint8_t byte_ctr, uint8_t *rx_buf);
|
||||
|
||||
void i2c_transmitinit(uint8_t slave_address);
|
||||
void i2c_transmit_n(uint8_t byte_ctr, uint8_t *tx_buf);
|
||||
|
||||
uint8_t i2c_busy(void);
|
||||
void i2c_setrate(uint8_t p_lsb, uint8_t p_msb);
|
||||
|
||||
#if 0
|
||||
#include <stdio.h>
|
||||
#define PRINTFDEBUG(...) printf(__VA_ARGS__)
|
||||
#else
|
||||
#define PRINTFDEBUG(...)
|
||||
#endif
|
||||
|
||||
#endif /* #ifdef I2CMASTER_H_ */
|
|
@ -0,0 +1,89 @@
|
|||
/*
|
||||
* Copyright (c) 2005-2010, Swedish Institute of Computer Science
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "contiki.h"
|
||||
#include "lib/sensors.h"
|
||||
#include "dev/sky-sensors.h"
|
||||
#include "dev/light-sensor.h"
|
||||
#include "dev/potentiometer-sensor.h"
|
||||
|
||||
/* Photodiode 1 (P64) on INCH_4 */
|
||||
/* Photodiode 2 (P65) on INCH_5 */
|
||||
/* Enric#define INPUT_CHANNEL ((1 << INCH_4) | (1 << INCH_5)) */
|
||||
#ifndef INPUT_CHANNEL
|
||||
#define INPUT_CHANNEL (1 << INCH_4)
|
||||
#endif
|
||||
|
||||
#ifndef INPUT_REFERENCE
|
||||
#define INPUT_REFERENCE SREF_0
|
||||
#endif
|
||||
|
||||
#ifdef POTENTIOMETER_MEM
|
||||
#define PHOTOSYNTHETIC_MEM POTENTIOMETER_MEM
|
||||
#define TOTAL_SOLAR_MEM POTENTIOMETER_MEM
|
||||
#else
|
||||
#define PHOTOSYNTHETIC_MEM ADC12MEM4
|
||||
#define TOTAL_SOLAR_MEM ADC12MEM4
|
||||
#endif
|
||||
|
||||
|
||||
const struct sensors_sensor light_sensor;
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
value(int type)
|
||||
{
|
||||
switch(type) {
|
||||
/* Photosynthetically Active Radiation. */
|
||||
case LIGHT_SENSOR_PHOTOSYNTHETIC:
|
||||
return PHOTOSYNTHETIC_MEM;
|
||||
|
||||
/* Total Solar Radiation. */
|
||||
case LIGHT_SENSOR_TOTAL_SOLAR:
|
||||
return TOTAL_SOLAR_MEM;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
status(int type)
|
||||
{
|
||||
return sky_sensors_status(INPUT_CHANNEL, type);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
configure(int type, int c)
|
||||
{
|
||||
return sky_sensors_configure(INPUT_CHANNEL, INPUT_REFERENCE, type, c);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
SENSORS_SENSOR(light_sensor, "Light", value, configure, status);
|
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
* Copyright (c) 2010, Swedish Institute of Computer Science.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
*
|
||||
*
|
||||
* -----------------------------------------------------------------
|
||||
*
|
||||
* Author : Adam Dunkels, Joakim Eriksson, Niclas Finne
|
||||
* Created : 2010-01-08
|
||||
* Updated : $Date: 2010/01/14 20:23:02 $
|
||||
* $Revision: 1.2 $
|
||||
*/
|
||||
|
||||
#ifndef LIGHT_SENSOR_H_
|
||||
#define LIGHT_SENSOR_H_
|
||||
|
||||
#include "lib/sensors.h"
|
||||
|
||||
extern const struct sensors_sensor light_sensor;
|
||||
|
||||
#define LIGHT_SENSOR_PHOTOSYNTHETIC 0
|
||||
#define LIGHT_SENSOR_TOTAL_SOLAR 1
|
||||
|
||||
|
||||
#endif /* LIGHT-SENSOR_H_ */
|
|
@ -0,0 +1,219 @@
|
|||
/*
|
||||
* Copyright (c) 2010, Swedish Institute of Computer Science.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file
|
||||
* Device drivers for light ziglet sensor in Zolertia Z1.
|
||||
* It is recommended to use with a 100KHz data rate
|
||||
* \author
|
||||
* Antonio Lignan, Zolertia <alinan@zolertia.com>
|
||||
* Marcus Lundén, SICS <mlunden@sics.se>
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "contiki.h"
|
||||
#include "i2cmaster.h"
|
||||
#include "light-ziglet.h"
|
||||
|
||||
#if 0
|
||||
#define PRINTFDEBUG(...) printf(__VA_ARGS__)
|
||||
#else
|
||||
#define PRINTFDEBUG(...)
|
||||
#endif
|
||||
|
||||
/* Bitmasks and bit flag variable for keeping track of tmp102 status. */
|
||||
enum TSL2563_STATUSTYPES {
|
||||
/* must be a bit and not more, not using 0x00. */
|
||||
INITED = 0x01,
|
||||
RUNNING = 0x02,
|
||||
STOPPED = 0x04,
|
||||
};
|
||||
|
||||
static enum TSL2563_STATUSTYPES _TSL2563_STATUS = 0x00;
|
||||
|
||||
uint16_t
|
||||
calculateLux(uint16_t *buffer)
|
||||
{
|
||||
uint32_t ch0, ch1 = 0;
|
||||
uint32_t aux = (1 << 14);
|
||||
uint32_t ratio, lratio, tmp = 0;
|
||||
|
||||
ch0 = (buffer[0] * aux) >> 10;
|
||||
ch1 = (buffer[1] * aux) >> 10;
|
||||
|
||||
PRINTFDEBUG("B0 %u, B1 %u\n", buffer[0], buffer[1]);
|
||||
PRINTFDEBUG("ch0 %lu, ch1 %lu\n", ch0, ch1);
|
||||
|
||||
ratio = (ch1 << 10);
|
||||
ratio = ratio / ch0;
|
||||
lratio = (ratio + 1) >> 1;
|
||||
|
||||
PRINTFDEBUG("ratio %lu, lratio %lu\n", ratio, lratio);
|
||||
|
||||
if((lratio >= 0) && (lratio <= K1T)) {
|
||||
tmp = (ch0 * B1T) - (ch1 * M1T);
|
||||
} else if(lratio <= K2T) {
|
||||
tmp = (ch0 * B2T) - (ch1 * M2T);
|
||||
} else if(lratio <= K3T) {
|
||||
tmp = (ch0 * B3T) - (ch1 * M3T);
|
||||
} else if(lratio <= K4T) {
|
||||
tmp = (ch0 * B4T) - (ch1 * M4T);
|
||||
} else if(lratio <= K5T) {
|
||||
tmp = (ch0 * B5T) - (ch1 * M5T);
|
||||
} else if(lratio <= K6T) {
|
||||
tmp = (ch0 * B6T) - (ch1 * M6T);
|
||||
} else if(lratio <= K7T) {
|
||||
tmp = (ch0 * B7T) - (ch1 * M7T);
|
||||
} else if(lratio > K8T) {
|
||||
tmp = (ch0 * B8T) - (ch1 * M8T);
|
||||
}
|
||||
|
||||
if(tmp < 0) {
|
||||
tmp = 0;
|
||||
}
|
||||
|
||||
tmp += (1 << 13);
|
||||
|
||||
PRINTFDEBUG("tmp %lu\n", tmp);
|
||||
|
||||
return tmp >> 14;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* Init the light ziglet sensor: ports, pins, registers, interrupts (none enabled), I2C,
|
||||
default threshold values etc. */
|
||||
|
||||
void
|
||||
light_ziglet_init(void)
|
||||
{
|
||||
if(!(_TSL2563_STATUS & INITED)) {
|
||||
PRINTFDEBUG("light ziglet init\n");
|
||||
_TSL2563_STATUS |= INITED;
|
||||
|
||||
/* Set up ports and pins for I2C communication */
|
||||
i2c_enable();
|
||||
return;
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* Write to a 16-bit register.
|
||||
args:
|
||||
reg register to write to
|
||||
val value to write
|
||||
*/
|
||||
|
||||
void
|
||||
tsl2563_write_reg(uint8_t reg, uint16_t val)
|
||||
{
|
||||
uint8_t tx_buf[] = { reg, 0x00, 0x00 };
|
||||
|
||||
tx_buf[1] = (uint8_t)(val >> 8);
|
||||
tx_buf[2] = (uint8_t)(val & 0x00FF);
|
||||
|
||||
i2c_transmitinit(TSL2563_ADDR);
|
||||
while(i2c_busy());
|
||||
PRINTFDEBUG("I2C Ready to TX\n");
|
||||
|
||||
i2c_transmit_n(3, tx_buf);
|
||||
while(i2c_busy());
|
||||
PRINTFDEBUG("WRITE_REG 0x%04X @ reg 0x%02X\n", val, reg);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* Read register.
|
||||
args:
|
||||
reg what register to read
|
||||
returns the value of the read register type uint16_t
|
||||
*/
|
||||
|
||||
uint16_t
|
||||
tsl2563_read_reg(uint8_t reg)
|
||||
{
|
||||
uint16_t readBuf[] = { 0x00, 0x00 };
|
||||
uint8_t buf[] = { 0x00, 0x00, 0x00, 0x00 };
|
||||
uint16_t retVal = 0;
|
||||
uint8_t rtx = reg;
|
||||
|
||||
/* Transmit the register to read */
|
||||
i2c_transmitinit(TSL2563_ADDR);
|
||||
while(i2c_busy());
|
||||
i2c_transmit_n(1, &rtx);
|
||||
while(i2c_busy());
|
||||
|
||||
/* Receive the data */
|
||||
i2c_receiveinit(TSL2563_ADDR);
|
||||
while(i2c_busy());
|
||||
i2c_receive_n(4, buf);
|
||||
while(i2c_busy());
|
||||
|
||||
PRINTFDEBUG("\nb0 %u, b1 %u, b2 %u, b3 %u\n", buf[0], buf[1], buf[2], buf[3]);
|
||||
|
||||
readBuf[0] = (buf[1] << 8 | (buf[0]));
|
||||
readBuf[1] = (buf[3] << 8 | (buf[2]));
|
||||
|
||||
retVal = calculateLux(readBuf);
|
||||
return retVal;
|
||||
}
|
||||
uint16_t
|
||||
light_ziglet_on(void)
|
||||
{
|
||||
uint16_t data;
|
||||
uint8_t regon = TSL2563_PWRN;
|
||||
/* Turn on the sensor */
|
||||
i2c_transmitinit(TSL2563_ADDR);
|
||||
while(i2c_busy());
|
||||
i2c_transmit_n(1, ®on);
|
||||
while(i2c_busy());
|
||||
data = (uint16_t)tsl2563_read_reg(TSL2563_READ);
|
||||
return data;
|
||||
}
|
||||
void
|
||||
light_ziglet_off(void)
|
||||
{
|
||||
uint8_t regoff = 0x00;
|
||||
/* Turn off the sensor */
|
||||
i2c_transmitinit(TSL2563_ADDR);
|
||||
while(i2c_busy());
|
||||
i2c_transmit_n(1, ®off);
|
||||
while(i2c_busy());
|
||||
return;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* Read light ziglet sensor
|
||||
*/
|
||||
|
||||
uint16_t
|
||||
light_ziglet_read(void)
|
||||
{
|
||||
uint16_t lux = 0;
|
||||
lux = light_ziglet_on();
|
||||
light_ziglet_off();
|
||||
return lux;
|
||||
}
|
|
@ -0,0 +1,123 @@
|
|||
/*
|
||||
* Copyright (c) 2010, Swedish Institute of Computer Science.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file
|
||||
* Device drivers header file for light ziglet sensor in Zolertia Z1 WSN Platform.
|
||||
* \author
|
||||
* Antonio Lignan, Zolertia <alinan@zolertia.com>
|
||||
* Marcus Lundén, SICS <mlunden@sics.se>
|
||||
*/
|
||||
|
||||
#ifndef LIGHT_ZIGLET_H_
|
||||
#define LIGHT_ZIGLET_H_
|
||||
#include <stdio.h>
|
||||
#include "i2cmaster.h"
|
||||
|
||||
/* Init the light ziglet sensor: ports, pins, I2C, interrupts */
|
||||
void light_ziglet_init(void);
|
||||
|
||||
/* Write to a register.
|
||||
args:
|
||||
reg register to write to
|
||||
val value to write
|
||||
*/
|
||||
void tsl2563_write_reg(uint8_t reg, uint16_t val);
|
||||
|
||||
/* Read one register.
|
||||
args:
|
||||
reg what register to read
|
||||
returns the value of the read register
|
||||
*/
|
||||
uint16_t tsl2563_read_reg(uint8_t reg);
|
||||
|
||||
/* Takes a single light reading
|
||||
args: none
|
||||
returns a lux value
|
||||
*/
|
||||
uint16_t light_ziglet_read();
|
||||
|
||||
/* Calculates the lux values from the calibration table
|
||||
args: raw values from sensor
|
||||
returns a lux value
|
||||
*/
|
||||
uint16_t calculateLux(uint16_t *readRaw);
|
||||
|
||||
/* Turns the light ziglet ON and polls the sensor for a light reading */
|
||||
uint16_t light_ziglet_on(void);
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* Reference definitions */
|
||||
|
||||
/* TSL2563 slave address */
|
||||
#define TSL2563_ADDR 0x39
|
||||
|
||||
/* Registers */
|
||||
#define TSL2563_READ 0xAC
|
||||
#define TSL2563_PWRN 0x03
|
||||
|
||||
/* Calibration settings */
|
||||
#define K1T 0X0040
|
||||
#define B1T 0x01f2
|
||||
#define M1T 0x01b2
|
||||
|
||||
#define K2T 0x0080
|
||||
#define B2T 0x0214
|
||||
#define M2T 0x02d1
|
||||
|
||||
#define K3T 0x00c0
|
||||
#define B3T 0x023f
|
||||
#define M3T 0x037b
|
||||
|
||||
#define K4T 0x0100
|
||||
#define B4T 0x0270
|
||||
#define M4T 0x03fe
|
||||
|
||||
#define K5T 0x0138
|
||||
#define B5T 0x016f
|
||||
#define M5T 0x01fc
|
||||
|
||||
#define K6T 0x019a
|
||||
#define B6T 0x00d2
|
||||
#define M6T 0x00fb
|
||||
|
||||
#define K7T 0x029a
|
||||
#define B7T 0x0018
|
||||
#define M7T 0x0012
|
||||
|
||||
#define K8T 0x029a
|
||||
#define B8T 0x0000
|
||||
#define M8T 0x0000
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
#endif /* ifndef LIGHT_ZIGLET_H_ */
|
||||
|
|
@ -0,0 +1,67 @@
|
|||
/*
|
||||
* Copyright (c) 2011 Zolertia(TM) is a trademark by Advancare,SL
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
*
|
||||
* -----------------------------------------------------------------
|
||||
*
|
||||
* Author : Enric M. Calvo (based on work by A. Dunkels, J. Eriksson, N. Finne)
|
||||
* Created : 2011-02-22
|
||||
* $Revision: 1.0 $
|
||||
*/
|
||||
|
||||
#include "dev/potentiometer-sensor.h"
|
||||
#include "dev/sky-sensors.h"
|
||||
#include "contiki.h"
|
||||
|
||||
/* Configure ADC12_2 to sample channel 11 (voltage) and use */
|
||||
/* the Vref+ as reference (SREF_1) since it is a stable reference */
|
||||
#define INPUT_CHANNEL (1 << INCH_4)
|
||||
#define INPUT_REFERENCE SREF_0
|
||||
#define POTENTIOMETER_MEM ADC12MEM4
|
||||
|
||||
const struct sensors_sensor potentiometer_sensor;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
value(int type)
|
||||
{
|
||||
return POTENTIOMETER_MEM;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
configure(int type, int c)
|
||||
{
|
||||
return sky_sensors_configure(INPUT_CHANNEL, INPUT_REFERENCE, type, c);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
status(int type)
|
||||
{
|
||||
return sky_sensors_status(INPUT_CHANNEL, type);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
SENSORS_SENSOR(potentiometer_sensor, POTENTIOMETER_SENSOR, value, configure, status);
|
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
* Copyright (c) 2011 Zolertia(TM) is a trademark by Advancare,SL
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
*
|
||||
* -----------------------------------------------------------------
|
||||
*
|
||||
* Author : Enric M. Calvo (based on work by A. Dunkels, J. Eriksson, N. Finne)
|
||||
* Created : 2011-02-22
|
||||
* $Revision: 1.0 $
|
||||
*/
|
||||
|
||||
#ifndef POTENTIOMETER_SENSOR_H_
|
||||
#define POTENTIOMETER_SENSOR_H_
|
||||
|
||||
#include "lib/sensors.h"
|
||||
|
||||
extern const struct sensors_sensor potentiometer_sensor;
|
||||
|
||||
#define POTENTIOMETER_SENSOR "Potentiometer"
|
||||
|
||||
#endif /* POTENTIOMETER_SENSOR_H_ */
|
|
@ -0,0 +1,122 @@
|
|||
/*
|
||||
* Copyright (c) 2015, Zolertia <http://www.zolertia.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
*/
|
||||
/**
|
||||
* \file
|
||||
* Reed sensor driver file
|
||||
* \author
|
||||
* Antonio Lignan <alinan@zolertia.com>
|
||||
*/
|
||||
|
||||
#include "contiki.h"
|
||||
#include "lib/sensors.h"
|
||||
#include "dev/reed-sensor.h"
|
||||
#include "sys/process.h"
|
||||
#include "sys/ctimer.h"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
#ifndef REED_CHECK_PERIOD
|
||||
#define REED_CHECK_PERIOD CLOCK_SECOND
|
||||
#endif
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int current_status = -1;
|
||||
static struct ctimer change_timer;
|
||||
process_event_t reed_sensor_event_changed;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
status(int type)
|
||||
{
|
||||
switch(type) {
|
||||
case SENSORS_ACTIVE:
|
||||
case SENSORS_READY:
|
||||
return ~(REED_PORT_DIR & REED_READ_PIN);
|
||||
}
|
||||
return REED_SENSOR_ERROR;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
value(int type)
|
||||
{
|
||||
if((!status(SENSORS_ACTIVE)) || (type != REED_SENSOR_VAL)) {
|
||||
return REED_SENSOR_ERROR;
|
||||
}
|
||||
return (REED_PORT_READ & REED_READ_PIN) ? REED_CLOSED : REED_OPEN;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static void
|
||||
check_callback(void *data)
|
||||
{
|
||||
static int new_status;
|
||||
if(current_status == -1) {
|
||||
ctimer_stop(&change_timer);
|
||||
return;
|
||||
}
|
||||
|
||||
new_status = value(REED_SENSOR_VAL);
|
||||
if(new_status != current_status) {
|
||||
current_status = new_status;
|
||||
process_post(PROCESS_BROADCAST, reed_sensor_event_changed, ¤t_status);
|
||||
}
|
||||
ctimer_reset(&change_timer);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
configure(int type, int c)
|
||||
{
|
||||
switch(type) {
|
||||
case SENSORS_ACTIVE:
|
||||
if(c) {
|
||||
if(!status(SENSORS_ACTIVE)) {
|
||||
REED_PORT_SEL |= REED_READ_PIN;
|
||||
REED_PORT_DIR &= ~REED_READ_PIN;
|
||||
REED_PORT_REN |= REED_READ_PIN;
|
||||
REED_PORT_PRES |= REED_READ_PIN;
|
||||
}
|
||||
} else {
|
||||
REED_PORT_DIR |= REED_READ_PIN;
|
||||
REED_PORT_REN &= ~REED_READ_PIN;
|
||||
}
|
||||
return REED_SENSOR_SUCCESS;
|
||||
case REED_SENSOR_MODE:
|
||||
if(c == REED_SENSOR_EVENT_MODE) {
|
||||
current_status = value(REED_SENSOR_VAL);
|
||||
ctimer_set(&change_timer, REED_CHECK_PERIOD, check_callback, NULL);
|
||||
} else if(c == REED_SENSOR_EVENT_POLL) {
|
||||
current_status = -1;
|
||||
ctimer_stop(&change_timer);
|
||||
} else {
|
||||
return REED_SENSOR_ERROR;
|
||||
}
|
||||
return REED_SENSOR_SUCCESS;
|
||||
}
|
||||
return REED_SENSOR_ERROR;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
SENSORS_SENSOR(reed_sensor, REED_SENSOR, value, configure, status);
|
|
@ -0,0 +1,76 @@
|
|||
/*
|
||||
* Copyright (c) 2015, Zolertia <http://www.zolertia.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
*/
|
||||
/**
|
||||
* Header file for the reed sensor
|
||||
*
|
||||
* The Reed sensor allows to be used either by polling the sensor status or by
|
||||
* setting up a timer on the background ticking every REED_CHECK_PERIOD, posting
|
||||
* a reed_sensor_event_changed event, informing the application about a change
|
||||
* in the sensor status (basically open or closed). To enable each mode
|
||||
* (default is polling) call the configure() function with REED_SENSOR_MODE
|
||||
* using REED_SENSOR_EVENT_MODE or REED_SENSOR_POLL_MODE, after having
|
||||
* initialized the device using SENSORS_ACTIVATE(reed_sensor).
|
||||
*
|
||||
* \file
|
||||
* Reed sensor header file
|
||||
* \author
|
||||
* Antonio Lignan <alinan@zolertia.com>
|
||||
*/
|
||||
#include "lib/sensors.h"
|
||||
|
||||
#ifndef REED_SENSOR_H_
|
||||
#define REED_SENSOR_H_
|
||||
/* -------------------------------------------------------------------------- */
|
||||
#define REED_SENSOR_ERROR -1
|
||||
#define REED_SENSOR_SUCCESS 0x00
|
||||
#define REED_SENSOR_VAL 0x01
|
||||
/* -------------------------------------------------------------------------- */
|
||||
#define REED_OPEN 0x00
|
||||
#define REED_CLOSED 0x01
|
||||
/* -------------------------------------------------------------------------- */
|
||||
#define REED_SENSOR_MODE 0x01
|
||||
#define REED_SENSOR_EVENT_MODE 0x0A
|
||||
#define REED_SENSOR_EVENT_POLL 0x0B
|
||||
/* -------------------------------------------------------------------------- */
|
||||
#define REED_PORT_DIR P4DIR
|
||||
#define REED_PORT_SEL P4SEL
|
||||
#define REED_PORT_REN P4REN
|
||||
#define REED_PORT_READ P4IN
|
||||
#define REED_PORT_PRES P4OUT
|
||||
#define REED_READ_PIN (1 << 2)
|
||||
/* -------------------------------------------------------------------------- */
|
||||
#define REED_SENSOR "Reed Sensor"
|
||||
/* -------------------------------------------------------------------------- */
|
||||
extern const struct sensors_sensor reed_sensor;
|
||||
extern process_event_t reed_sensor_event_changed;
|
||||
/* -------------------------------------------------------------------------- */
|
||||
#endif /* ifndef REED_SENSOR_H_ */
|
|
@ -0,0 +1,105 @@
|
|||
/*
|
||||
* Copyright (c) 2010, Swedish Institute of Computer Science.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
*
|
||||
* -----------------------------------------------------------------
|
||||
*
|
||||
* \file
|
||||
* Device simple driver for generic relay in phidget port of Zolertia Z1
|
||||
* \author
|
||||
* Antonio Lignan, Zolertia <alinan@zolertia.com>
|
||||
*
|
||||
*/
|
||||
|
||||
#include "contiki.h"
|
||||
#include "relay-phidget.h"
|
||||
|
||||
static uint8_t controlPin;
|
||||
|
||||
enum PHIDGET_RELAY_STATUSTYPES {
|
||||
/* must be a bit and not more, not using 0x00. */
|
||||
INITED = 0x01,
|
||||
RUNNING = 0x02,
|
||||
STOPPED = 0x04,
|
||||
};
|
||||
|
||||
static enum PHIDGET_RELAY_STATUSTYPES _RELAY_STATUS = 0x00;
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
void
|
||||
relay_enable(uint8_t pin)
|
||||
{
|
||||
|
||||
if(!(_RELAY_STATUS & INITED)) {
|
||||
|
||||
_RELAY_STATUS |= INITED;
|
||||
|
||||
/* Selects the pin to be configure as the control pin of the relay module */
|
||||
controlPin = (1 << pin);
|
||||
|
||||
/* Configures the control pin */
|
||||
P6SEL &= ~controlPin;
|
||||
P6DIR |= controlPin;
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
void
|
||||
relay_on()
|
||||
{
|
||||
if((_RELAY_STATUS & INITED)) {
|
||||
P6OUT |= controlPin;
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void
|
||||
relay_off()
|
||||
{
|
||||
if((_RELAY_STATUS & INITED)) {
|
||||
P6OUT &= ~controlPin;
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
||||
int8_t
|
||||
relay_toggle()
|
||||
{
|
||||
if((_RELAY_STATUS & INITED)) {
|
||||
P6OUT ^= controlPin;
|
||||
if((P6OUT & controlPin)) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
|
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
* Copyright (c) 2010, Swedish Institute of Computer Science.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
* -----------------------------------------------------------------
|
||||
*
|
||||
* \file
|
||||
* Device simple driver for generic relay in phidget port of Zolertia Z1
|
||||
* \author
|
||||
* Antonio Lignan, Zolertia <alinan@zolertia.com>
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef RELAY_PHIDGET_H_
|
||||
#define RELAY_PHIDGETS_H_
|
||||
|
||||
void relay_enable(uint8_t pin);
|
||||
|
||||
void relay_on();
|
||||
void relay_off();
|
||||
int8_t relay_toggle();
|
||||
|
||||
#endif /* RELAY_PHIDGET_H_ */
|
|
@ -0,0 +1,63 @@
|
|||
/*
|
||||
* Copyright (c) 2011, Zolertia(TM) is a trademark of Advancare,SL
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file
|
||||
* Architecture-specific definitions for the SHT11 sensor on Zolertia Z1
|
||||
* when connected to the Ziglet port.
|
||||
* \author
|
||||
* Enric M. Calvo <ecalvo@zolertia.com>, adapted from work by
|
||||
* Nicolas Tsiftes <nvt@sics.se>
|
||||
*/
|
||||
|
||||
#ifndef SHT11_ARCH_H
|
||||
#define SHT11_ARCH_H
|
||||
|
||||
/* Architecture-specific definitions for the SHT11 sensor on Zolertia Z1
|
||||
* when connected to the Ziglet port.
|
||||
* CAUTION: I2C needs to be disabled to use the bitbang protocol of SHT11
|
||||
*/
|
||||
|
||||
#define SHT11_ARCH_SDA 1 /* P5.1 */
|
||||
#define SHT11_ARCH_SCL 2 /* P5.2 */
|
||||
/* SHT11_ARCH_PWR is not needed, but until and *-arch abstraction exists, this
|
||||
* should fix it
|
||||
*/
|
||||
#define SHT11_ARCH_PWR 3 /* P5.3 -- unused pin */
|
||||
|
||||
#define SHT11_PxDIR P5DIR
|
||||
#define SHT11_PxIN P5IN
|
||||
#define SHT11_PxOUT P5OUT
|
||||
#define SHT11_PxSEL P5SEL
|
||||
#define SHT11_PxREN P5REN
|
||||
|
||||
#endif
|
|
@ -0,0 +1,134 @@
|
|||
/*
|
||||
* Copyright (c) 2015, Zolertia <http://www.zolertia.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
*/
|
||||
/**
|
||||
* \file
|
||||
* SHT25 temperature and humidity sensor driver
|
||||
* \author
|
||||
* Antonio Lignan <alinan@zolertia.com>
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include "contiki.h"
|
||||
#include "i2cmaster.h"
|
||||
#include "dev/sht25.h"
|
||||
#include "lib/sensors.h"
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static uint8_t enabled;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
configure(int type, int value)
|
||||
{
|
||||
if(type != SENSORS_ACTIVE) {
|
||||
return SHT25_ERROR;
|
||||
}
|
||||
if(value) {
|
||||
i2c_enable();
|
||||
} else {
|
||||
i2c_disable();
|
||||
}
|
||||
enabled = value;
|
||||
return 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
status(int type)
|
||||
{
|
||||
switch(type) {
|
||||
case SENSORS_ACTIVE:
|
||||
case SENSORS_READY:
|
||||
return enabled;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static uint16_t
|
||||
sht25_read_reg(uint8_t reg)
|
||||
{
|
||||
uint8_t buf[] = { 0x00, 0x00 };
|
||||
uint16_t retval;
|
||||
uint8_t rtx = reg;
|
||||
|
||||
/* transmit the register to read */
|
||||
i2c_transmitinit(SHT25_ADDR);
|
||||
while(i2c_busy());
|
||||
i2c_transmit_n(1, &rtx);
|
||||
while(i2c_busy());
|
||||
/* receive the data */
|
||||
i2c_receiveinit(SHT25_ADDR);
|
||||
while(i2c_busy());
|
||||
i2c_receive_n(2, &buf[0]);
|
||||
while(i2c_busy());
|
||||
|
||||
retval = (uint16_t)(buf[0] << 8 | (buf[1]));
|
||||
return retval;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int16_t
|
||||
sht25_convert(uint8_t variable, uint16_t value)
|
||||
{
|
||||
int16_t rd;
|
||||
uint32_t buff;
|
||||
buff = (uint32_t)value;
|
||||
if(variable == SHT25_VAL_TEMP) {
|
||||
buff *= 17572;
|
||||
buff = buff >> 16;
|
||||
rd = (int16_t)buff - 4685;
|
||||
} else {
|
||||
buff *= 12500;
|
||||
buff = buff >> 16;
|
||||
rd = (int16_t)buff - 600;
|
||||
rd = (rd > 10000) ? 10000 : rd;
|
||||
}
|
||||
return rd;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int16_t
|
||||
sht25_read(uint8_t variable)
|
||||
{
|
||||
int16_t rd;
|
||||
uint16_t raw;
|
||||
|
||||
if((variable != SHT25_VAL_TEMP) && (variable != SHT25_VAL_HUM)) {
|
||||
return SHT25_ERROR;
|
||||
}
|
||||
raw = sht25_read_reg(variable);
|
||||
rd = sht25_convert(variable, raw);
|
||||
return rd;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
value(int type)
|
||||
{
|
||||
return sht25_read(type);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
SENSORS_SENSOR(sht25, SHT25_SENSOR, value, configure, status);
|
||||
/*---------------------------------------------------------------------------*/
|
|
@ -0,0 +1,71 @@
|
|||
/*
|
||||
* Copyright (c) 2015, Zolertia <http://www.zolertia.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
*/
|
||||
/**
|
||||
* \file
|
||||
* SHT25 temperature and humidity sensor driver
|
||||
* \author
|
||||
* Antonio Lignan <alinan@zolertia.com>
|
||||
*/
|
||||
#include "lib/sensors.h"
|
||||
|
||||
#ifndef SHT25_H_
|
||||
#define SHT25_H_
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
#define SHT25_ADDR 0x40
|
||||
#define SHT25_TEMP_HOLD 0xE3
|
||||
#define SHT25_HUM_HOLD 0xE5
|
||||
#define SHT25_TEMP_NO_HOLD 0xF3
|
||||
#define SHT25_HUM_NO_HOLD 0xF5
|
||||
#define SHT2X_UREG_WRITE 0xE6
|
||||
#define SHT2X_UREG_READ 0xE7
|
||||
#define SHT2X_SOFT_RESET 0XFE
|
||||
#define SHT2X_NULL 0x00
|
||||
/* -------------------------------------------------------------------------- */
|
||||
#define SHT2X_RES_14T_12RH 0x00
|
||||
#define SHT2X_RES_12T_08RH 0x01
|
||||
#define SHT2X_RES_13T_10RH 0x80
|
||||
#define SHT2X_RES_11T_11RH 0x81
|
||||
#define SHT2X_HEATER_ON 0x04
|
||||
#define SHT2X_HEATER_OFF 0x00
|
||||
#define SHT2X_OTP_RELOAD_EN 0x00
|
||||
#define SHT2X_OTP_RELOAD_DIS 0x02
|
||||
/* -------------------------------------------------------------------------- */
|
||||
#define SHT25_VAL_TEMP SHT25_TEMP_HOLD
|
||||
#define SHT25_VAL_HUM SHT25_HUM_HOLD
|
||||
#define SHT25_ERROR -1
|
||||
/* -------------------------------------------------------------------------- */
|
||||
#define SHT25_SENSOR "SHT25 Sensor"
|
||||
/* -------------------------------------------------------------------------- */
|
||||
extern const struct sensors_sensor sht25;
|
||||
/* -------------------------------------------------------------------------- */
|
||||
#endif /* ifndef SHT25_H_ */
|
|
@ -0,0 +1,152 @@
|
|||
/*
|
||||
* Copyright (c) 2010, Swedish Institute of Computer Science.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
*
|
||||
* -----------------------------------------------------------------
|
||||
*
|
||||
* Author : Joakim Eriksson
|
||||
* Created : 2010-02-02
|
||||
* Updated : $Date: 2010/08/25 19:30:53 $
|
||||
* $Revision: 1.3 $
|
||||
*/
|
||||
#include "contiki.h"
|
||||
#include "lib/sensors.h"
|
||||
|
||||
#define ADC12MCTL_NO(adcno) ((unsigned char *) ADC12MCTL0_)[adcno]
|
||||
|
||||
static uint16_t adc_on;
|
||||
static uint16_t ready;
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static CC_INLINE void
|
||||
start(void)
|
||||
{
|
||||
uint16_t c, last;
|
||||
|
||||
/* Set up the ADC. */
|
||||
P6DIR = 0xff;
|
||||
P6OUT = 0x00;
|
||||
|
||||
/* Setup ADC12, ref., sampling time */
|
||||
/* XXX Note according to the specification a minimum of 17 ms should
|
||||
be allowed after turn on of the internal reference generator. */
|
||||
ADC12CTL0 = REF2_5V + SHT0_6 + SHT1_6 + MSC + REFON;
|
||||
/* Use sampling timer, repeat-sequence-of-channels */
|
||||
ADC12CTL1 = SHP + CONSEQ_3;
|
||||
|
||||
last = 15;
|
||||
for(c = 0; c < 16; c++) {
|
||||
/* Clear all end-of-sequences */
|
||||
ADC12MCTL_NO(c) &= ~EOS;
|
||||
if(adc_on & (1 << c)) {
|
||||
if(last == 15) {
|
||||
/* Set new start of sequence to lowest active memory holder */
|
||||
ADC12CTL1 |= (c * CSTARTADD_1);
|
||||
}
|
||||
last = c;
|
||||
}
|
||||
}
|
||||
|
||||
/* Set highest end-of-sequence. */
|
||||
ADC12MCTL_NO(last) |= EOS;
|
||||
|
||||
ADC12CTL0 |= ADC12ON;
|
||||
ADC12CTL0 |= ENC; /* enable conversion */
|
||||
ADC12CTL0 |= ADC12SC; /* sample & convert */
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static CC_INLINE void
|
||||
stop(void)
|
||||
{
|
||||
/* stop converting immediately, turn off reference voltage, etc. */
|
||||
|
||||
ADC12CTL0 &= ~ENC;
|
||||
/* need to remove CONSEQ_3 if not EOS is configured */
|
||||
ADC12CTL1 &= ~CONSEQ_3;
|
||||
|
||||
/* wait for conversion to stop */
|
||||
while(ADC12CTL1 & ADC12BUSY);
|
||||
|
||||
/* clear any pending interrupts */
|
||||
ADC12IFG = 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
int
|
||||
sky_sensors_status(uint16_t input, int type)
|
||||
{
|
||||
if(type == SENSORS_ACTIVE) {
|
||||
return (adc_on & input) == input;
|
||||
}
|
||||
if(type == SENSORS_READY) {
|
||||
ready |= ADC12IFG & adc_on & input;
|
||||
return (ready & adc_on & input) == input;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
int
|
||||
sky_sensors_configure(uint16_t input, uint8_t ref, int type, int value)
|
||||
{
|
||||
uint16_t c;
|
||||
|
||||
if(type == SENSORS_ACTIVE) {
|
||||
stop();
|
||||
|
||||
if(value) {
|
||||
adc_on |= input;
|
||||
P6SEL |= input & 0xff;
|
||||
|
||||
/* Set ADC config */
|
||||
for(c = 0; c < 16; c++) {
|
||||
if(input & (1 << c)) {
|
||||
ADC12MCTL_NO(c) = (c * INCH_1) | ref;
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
adc_on &= ~input;
|
||||
ready &= ~input;
|
||||
P6SEL &= ~(input & 0xff);
|
||||
}
|
||||
|
||||
if(adc_on == 0) {
|
||||
P6DIR = 0x00;
|
||||
P6SEL = 0x00;
|
||||
|
||||
/* Turn off ADC and internal reference generator */
|
||||
ADC12CTL0 = 0;
|
||||
ADC12CTL1 = 0;
|
||||
} else {
|
||||
start();
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
* Copyright (c) 2010, Swedish Institute of Computer Science.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
* -----------------------------------------------------------------
|
||||
*
|
||||
* Author : Joakim Eriksson
|
||||
* Created : 2010-02-02
|
||||
* Updated : $Date: 2010/08/25 19:30:53 $
|
||||
* $Revision: 1.2 $
|
||||
*/
|
||||
|
||||
#ifndef SKY_SENSORS_H_
|
||||
#define SKY_SENSORS_H_
|
||||
|
||||
int sky_sensors_status(uint16_t input, int type);
|
||||
int sky_sensors_configure(uint16_t input, uint8_t reference,
|
||||
int type, int value);
|
||||
|
||||
#endif /* SKY_SENSORS_H_ */
|
|
@ -0,0 +1,70 @@
|
|||
/*
|
||||
* Copyright (c) 2010, Swedish Institute of Computer Science.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file
|
||||
* Sensor driver for reading the built-in temperature sensor in the CPU.
|
||||
* \author
|
||||
* Adam Dunkels <adam@sics.se>
|
||||
* Joakim Eriksson <joakime@sics.se>
|
||||
* Niclas Finne <nfi@sics.se>
|
||||
*/
|
||||
|
||||
#include "dev/temperature-sensor.h"
|
||||
#include "dev/sky-sensors.h"
|
||||
#include "contiki.h"
|
||||
|
||||
#define INPUT_CHANNEL (1 << INCH_10)
|
||||
#define INPUT_REFERENCE SREF_1
|
||||
#define TEMPERATURE_MEM ADC12MEM10
|
||||
|
||||
const struct sensors_sensor temperature_sensor;
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
value(int type)
|
||||
{
|
||||
return TEMPERATURE_MEM;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
configure(int type, int c)
|
||||
{
|
||||
return sky_sensors_configure(INPUT_CHANNEL, INPUT_REFERENCE, type, c);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static int
|
||||
status(int type)
|
||||
{
|
||||
return sky_sensors_status(INPUT_CHANNEL, type);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
SENSORS_SENSOR(temperature_sensor, TEMPERATURE_SENSOR,
|
||||
value, configure, status);
|
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
* Copyright (c) 2010, Swedish Institute of Computer Science.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file
|
||||
* Temperature sensor header file.
|
||||
* \author
|
||||
* Adam Dunkels <adam@sics.se>
|
||||
* Joakim Eriksson <joakime@sics.se>
|
||||
* Niclas Finne <nfi@sics.se>
|
||||
*/
|
||||
|
||||
#ifndef TEMPERATURE_SENSOR_H_
|
||||
#define TEMPERATURE_SENSOR_H_
|
||||
|
||||
#include "lib/sensors.h"
|
||||
|
||||
extern const struct sensors_sensor temperature_sensor;
|
||||
|
||||
#define TEMPERATURE_SENSOR "Temperature"
|
||||
|
||||
#endif /* TEMPERATURE_SENSOR_H_ */
|
|
@ -0,0 +1,185 @@
|
|||
/*
|
||||
* Copyright (c) 2013, Jelmer Tiete.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote
|
||||
* products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file
|
||||
* Device drivers for tlc59116 i2c led driver on Zolertia Z1.
|
||||
* See http://www.ti.com/product/tlc59116 for datasheet.
|
||||
* \author
|
||||
* Jelmer Tiete, VUB <jelmer@tiete.be>
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include "contiki.h"
|
||||
#include "tlc59116.h"
|
||||
#include "i2cmaster.h"
|
||||
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* Write to a register.
|
||||
* args:
|
||||
* reg register to write to
|
||||
* val value to write
|
||||
*/
|
||||
|
||||
void
|
||||
tlc59116_write_reg(uint8_t reg, uint8_t val)
|
||||
{
|
||||
uint8_t tx_buf[] = { reg, val };
|
||||
|
||||
i2c_transmitinit(TLC59116_ADDR);
|
||||
while(i2c_busy());
|
||||
PRINTFDEBUG("I2C Ready to TX\n");
|
||||
|
||||
i2c_transmit_n(2, tx_buf);
|
||||
while(i2c_busy());
|
||||
PRINTFDEBUG("WRITE_REG 0x%02X @ reg 0x%02X\n", val, reg);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* Write several registers from a stream.
|
||||
* args:
|
||||
* len number of bytes to write
|
||||
* data pointer to where the data is written from
|
||||
*
|
||||
* First byte in stream must be the register address to begin writing to.
|
||||
* The data is then written from second byte and increasing.
|
||||
*/
|
||||
|
||||
void
|
||||
tlc59116_write_stream(uint8_t len, uint8_t *data)
|
||||
{
|
||||
i2c_transmitinit(TLC59116_ADDR);
|
||||
while(i2c_busy());
|
||||
PRINTFDEBUG("I2C Ready to TX(stream)\n");
|
||||
|
||||
i2c_transmit_n(len, data); /* start tx and send conf reg */
|
||||
while(i2c_busy());
|
||||
PRINTFDEBUG("WRITE_STR %u B to 0x%02X\n", len, data[0]);
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* Read one register.
|
||||
* args:
|
||||
* reg what register to read
|
||||
* returns the value of the read register
|
||||
*/
|
||||
|
||||
uint8_t
|
||||
tlc59116_read_reg(uint8_t reg)
|
||||
{
|
||||
uint8_t retVal = 0;
|
||||
uint8_t rtx = reg;
|
||||
|
||||
PRINTFDEBUG("READ_REG 0x%02X\n", reg);
|
||||
|
||||
/* transmit the register to read */
|
||||
i2c_transmitinit(TLC59116_ADDR);
|
||||
while(i2c_busy());
|
||||
i2c_transmit_n(1, &rtx);
|
||||
while(i2c_busy());
|
||||
|
||||
/* receive the data */
|
||||
i2c_receiveinit(TLC59116_ADDR);
|
||||
while(i2c_busy());
|
||||
i2c_receive_n(1, &retVal);
|
||||
while(i2c_busy());
|
||||
|
||||
return retVal;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* Read several registers in a stream.
|
||||
* args:
|
||||
* reg what register to start reading from
|
||||
* len number of bytes to read
|
||||
* whereto pointer to where the data is saved
|
||||
*/
|
||||
|
||||
void
|
||||
tlc59116_read_stream(uint8_t reg, uint8_t len, uint8_t *whereto)
|
||||
{
|
||||
uint8_t rtx = reg;
|
||||
|
||||
PRINTFDEBUG("READ_STR %u B from 0x%02X\n", len, reg);
|
||||
|
||||
/* transmit the register to start reading from */
|
||||
i2c_transmitinit(TLC59116_ADDR);
|
||||
while(i2c_busy());
|
||||
i2c_transmit_n(1, &rtx);
|
||||
while(i2c_busy());
|
||||
|
||||
/* receive the data */
|
||||
i2c_receiveinit(TLC59116_ADDR);
|
||||
while(i2c_busy());
|
||||
i2c_receive_n(len, whereto);
|
||||
while(i2c_busy());
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* Set pwm value for individual led. Make sure PWM mode is enabled.
|
||||
* args:
|
||||
* led led output -> 0 till 15
|
||||
* pwm led pwm value
|
||||
*/
|
||||
|
||||
void
|
||||
tlc59116_led(uint8_t led, uint8_t pwm)
|
||||
{
|
||||
if((led < 0) || (led > 15)) {
|
||||
PRINTFDEBUG("TLC59116: wrong led value.");
|
||||
} else {
|
||||
tlc59116_write_reg(led + TLC59116_PWM0, pwm);
|
||||
}
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
/* Init the led driver: ports, pins, registers, interrupts (none enabled), I2C,
|
||||
* default threshold values etc.
|
||||
*/
|
||||
|
||||
void
|
||||
tlc59116_init(void)
|
||||
{
|
||||
/* Set up ports and pins for I2C communication */
|
||||
i2c_enable();
|
||||
|
||||
/* set default register values. */
|
||||
tlc59116_write_reg(TLC59116_MODE1, TLC59116_MODE1_DEFAULT);
|
||||
tlc59116_write_reg(TLC59116_MODE2, TLC59116_MODE2_DEFAULT);
|
||||
|
||||
/*Set all PWM values to 0x00 (off) */
|
||||
/*This would maybe be better with a SWRST */
|
||||
uint8_t tx_buf[] =
|
||||
{ TLC59116_PWM0_AUTOINCR, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
|
||||
tlc59116_write_stream(17, tx_buf);
|
||||
|
||||
/* set all leds to PWM control */
|
||||
tlc59116_write_reg(TLC59116_LEDOUT0, TLC59116_LEDOUT_PWM);
|
||||
tlc59116_write_reg(TLC59116_LEDOUT1, TLC59116_LEDOUT_PWM);
|
||||
tlc59116_write_reg(TLC59116_LEDOUT2, TLC59116_LEDOUT_PWM);
|
||||
tlc59116_write_reg(TLC59116_LEDOUT3, TLC59116_LEDOUT_PWM);
|
||||
}
|
|
@ -0,0 +1,142 @@
|
|||
/*
|
||||
* Copyright (c) 2013, Jelmer Tiete.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote
|
||||
* products derived from this software without specific prior
|
||||
* written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
|
||||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
|
||||
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the Contiki operating system.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file
|
||||
* Device drivers header file for TLC59116 i2c led driver on Zolertia Z1.
|
||||
* See http://www.ti.com/product/tlc59116 for datasheet.
|
||||
* \author
|
||||
* Jelmer Tiete, VUB <jelmer@tiete.be>
|
||||
*/
|
||||
|
||||
#ifndef TLC59116_H_
|
||||
#define TLC59116_H_
|
||||
#include <stdio.h>
|
||||
#include "dev/i2cmaster.h"
|
||||
|
||||
#if 0
|
||||
#include <stdio.h>
|
||||
#define PRINTFDEBUG(...) printf(__VA_ARGS__)
|
||||
#else
|
||||
#define PRINTFDEBUG(...)
|
||||
#endif
|
||||
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* Init the led driver: ports, pins, registers, I2C*/
|
||||
void tlc59116_init(void);
|
||||
|
||||
/* Write to a register.
|
||||
* args:
|
||||
* reg register to write to
|
||||
* val value to write
|
||||
*/
|
||||
void tlc59116_write_reg(uint8_t reg, uint8_t val);
|
||||
|
||||
/* Write several registers from a stream.
|
||||
* args:
|
||||
* len number of bytes to read
|
||||
* data pointer to where the data is read from
|
||||
* First byte in stream must be the register address to begin writing to.
|
||||
* The data is then written from the second byte and increasing. The address byte
|
||||
* is not included in length len.
|
||||
*/
|
||||
void tlc59116_write_stream(uint8_t len, uint8_t * data);
|
||||
|
||||
/* Read one register.
|
||||
* args:
|
||||
* reg what register to read
|
||||
* returns the value of the read register
|
||||
*/
|
||||
uint8_t tlc59116_read_reg(uint8_t reg);
|
||||
|
||||
/* Read several registers in a stream.
|
||||
* args:
|
||||
* reg what register to start reading from
|
||||
* len number of bytes to read
|
||||
* whereto pointer to where the data is saved
|
||||
*/
|
||||
void tlc59116_read_stream(uint8_t reg, uint8_t len, uint8_t * whereto);
|
||||
|
||||
/* Set pwm value for individual led
|
||||
* args:
|
||||
* led led output -> 0 till 15
|
||||
* pwm led pwm value
|
||||
*/
|
||||
void tlc59116_led(uint8_t led, uint8_t pwm);
|
||||
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* Application definitions, change if required by application. */
|
||||
|
||||
/* Suggested defaults according to the data sheet etc */
|
||||
#define TLC59116_MODE1_DEFAULT 0x00 /* Default (no sub or all call) + OSC on */
|
||||
#define TLC59116_MODE2_DEFAULT 0x00 /* Default (output change on stop) */
|
||||
|
||||
#define TLC59116_LEDOUT_PWM 0xAA /* LDRx = 01 -> PWM; 4 leds per reg: 01010101b -> 0xAA */
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* Reference definitions, should not be changed */
|
||||
/* TLC59116 slave address */
|
||||
#define TLC59116_ADDR 0x60 /* 7bit adress, 8bit write adress: 0xC0 */
|
||||
/* address with all address pins pulled to ground */
|
||||
/* TLC59116 registers */
|
||||
#define TLC59116_MODE1 0x00
|
||||
#define TLC59116_MODE2 0x01
|
||||
#define TLC59116_PWM0_AUTOINCR 0xA2 /* auto increment address for first pwm register */
|
||||
#define TLC59116_PWM0 0x02
|
||||
#define TLC59116_PWM1 0x03
|
||||
#define TLC59116_PWM2 0x04
|
||||
#define TLC59116_PWM3 0x05
|
||||
#define TLC59116_PWM4 0x06
|
||||
#define TLC59116_PWM5 0x07
|
||||
#define TLC59116_PWM6 0x08
|
||||
#define TLC59116_PWM7 0x09
|
||||
#define TLC59116_PWM8 0x0A
|
||||
#define TLC59116_PWM9 0x0B
|
||||
#define TLC59116_PWM10 0x0C
|
||||
#define TLC59116_PWM11 0x0D
|
||||
#define TLC59116_PWM12 0x0E
|
||||
#define TLC59116_PWM13 0x0F
|
||||
#define TLC59116_PWM14 0x10
|
||||
#define TLC59116_PWM15 0x11
|
||||
#define TLC59116_GRPPWM 0x12
|
||||
#define TLC59116_GRPFREQ 0x13
|
||||
#define TLC59116_LEDOUT0 0x14
|
||||
#define TLC59116_LEDOUT1 0x15
|
||||
#define TLC59116_LEDOUT2 0x16
|
||||
#define TLC59116_LEDOUT3 0x17
|
||||
|
||||
/* More registers follow, but not used in this implementation */
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
#endif /* ifndef TLC59116_H_ */
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue