From 7b812e73c9bea2c115d3bee0382ce7155accc22a Mon Sep 17 00:00:00 2001 From: Edvard Pettersen Date: Thu, 7 Jun 2018 10:29:47 +0200 Subject: [PATCH] Fixed naming and alignment of RF settings, Watchdog driver, Board files --- arch/cpu/arm/Makefile.arm | 6 + arch/cpu/arm/cortex-m/cm3/Makefile.cm3 | 15 +- arch/cpu/arm/cortex-m/cm4/Makefile.cm4 | 7 +- .../cc13x0-cc26x0/cc13x0-cc26x0.lds | 6 +- .../cc13x2-cc26x2/cc13x2-cc26x2.lds | 5 +- arch/cpu/cc13xx-cc26xx/dev/ieee-addr.c | 16 +- arch/cpu/cc13xx-cc26xx/dev/rf-ieee-mode.c | 258 ++++++++++-------- arch/cpu/cc13xx-cc26xx/dev/rf-prop-mode.c | 93 ++++--- .../dev/startup_cc13xx_cc26xx_gcc.c | 4 + arch/cpu/cc13xx-cc26xx/dev/uart0-arch.c | 8 +- arch/cpu/cc13xx-cc26xx/dev/watchdog-arch.c | 75 ++--- .../rf-settings/cc13x0/ieee-settings.c | 36 +-- .../rf-settings/cc13x0/ieee-settings.h | 5 +- .../rf-settings/cc13x0/prop-settings.c | 4 +- .../rf-settings/cc13x2/ieee-settings.c | 8 +- .../rf-settings/cc13x2/ieee-settings.h | 3 +- .../rf-settings/cc13x2/prop-settings.c | 8 +- .../rf-settings/cc13x2/prop-settings.h | 2 +- .../rf-settings/cc26x0/ieee-settings.c | 4 +- .../rf-settings/cc26x0/ieee-settings.h | 1 + .../rf-settings/cc26x2/ieee-settings.c | 12 +- .../rf-settings/cc26x2/ieee-settings.h | 11 +- .../cc13xx-cc26xx/launchpad/cc1310/Board.h | 14 + .../cc13xx-cc26xx/launchpad/cc1312r1/Board.h | 14 + .../launchpad/cc1312r1/Makefile.cc1312r1 | 2 + .../cc13xx-cc26xx/launchpad/cc1350-4/Board.h | 14 + .../cc13xx-cc26xx/launchpad/cc1350/Board.h | 14 + .../launchpad/cc1350/CC1350_LAUNCHXL.c | 5 +- .../cc13xx-cc26xx/launchpad/cc1352p1/Board.h | 14 + .../launchpad/cc1352p1/Makefile.cc1352p1 | 3 + .../cc13xx-cc26xx/launchpad/cc1352p_2/Board.h | 14 + .../launchpad/cc1352p_2/Makefile.cc1352p_2 | 3 + .../cc13xx-cc26xx/launchpad/cc1352p_4/Board.h | 14 + .../launchpad/cc1352p_4/Makefile.cc1352p_4 | 3 + .../cc13xx-cc26xx/launchpad/cc1352r1/Board.h | 14 + .../launchpad/cc1352r1/Makefile.cc1352r1 | 3 + .../cc13xx-cc26xx/launchpad/cc2650/Board.h | 14 + .../cc13xx-cc26xx/launchpad/cc26x2r1/Board.h | 14 + .../cc13xx-cc26xx/launchpad/ext-flash.c | 50 +++- .../cc13xx-cc26xx/launchpad/leds-arch.c | 80 ++---- .../simplelink/cc13xx-cc26xx/platform.c | 39 +-- .../cc13xx-cc26xx/sensortag/sensortag.c | 8 - 42 files changed, 547 insertions(+), 376 deletions(-) diff --git a/arch/cpu/arm/Makefile.arm b/arch/cpu/arm/Makefile.arm index dd00aae6d..2c1a4bf7b 100644 --- a/arch/cpu/arm/Makefile.arm +++ b/arch/cpu/arm/Makefile.arm @@ -15,6 +15,12 @@ CFLAGS += -mthumb -mabi=aapcs -mlittle-endian CFLAGS += -Werror -Wall CFLAGS += -std=c99 CFLAGS += -ffunction-sections -fdata-sections -fno-strict-aliasing +# A weird behaviour of GCC garbage collection has been observed, where unitialized +# global variables put in the COMMON section weren't analyzed by the garbage collector +# at all. No idea why. The fix is to dissallow the common section, which subsequently +# places all unitialized global variables in the .bss section and enables the +# garbage collector to analyze the variables. +CFLAGS += -fno-common CFLAGS += -fshort-enums -fomit-frame-pointer -fno-builtin LDFLAGS += -mthumb -mlittle-endian diff --git a/arch/cpu/arm/cortex-m/cm3/Makefile.cm3 b/arch/cpu/arm/cortex-m/cm3/Makefile.cm3 index 934e233e6..29adac8e8 100644 --- a/arch/cpu/arm/cortex-m/cm3/Makefile.cm3 +++ b/arch/cpu/arm/cortex-m/cm3/Makefile.cm3 @@ -4,23 +4,28 @@ CFLAGS += -mcpu=cortex-m3 LDFLAGS += -mcpu=cortex-m3 -nostartfiles LDFLAGS += -T $(LDSCRIPT) -LDFLAGS += -Wl,--gc-sections,--sort-section=alignment -LDFLAGS += -Wl,-Map=$(CONTIKI_NG_PROJECT_MAP),--cref,--no-warn-mismatch +LDFLAGS += -Wl,--gc-sections +LDFLAGS += -Wl,--sort-section=alignment +LDFLAGS += -Wl,-Map=$(@:.elf=-$(TARGET).map) +LDFLAGS += -Wl,--cref +LDFLAGS += -Wl,--no-warn-mismatch + +TARGET_LIBFLAGS := -Wl,--start-group $(TARGET_LIBFILES) -lc -lgcc -lm -lnosys -Wl,--end-group OBJCOPY_FLAGS += --gap-fill 0xff ### Build syscalls for newlib MODULES += os/lib/newlib -CPU_STARTFILES = ${addprefix $(OBJECTDIR)/,${call oname, $(CPU_START_SOURCEFILES)}} +CPU_STARTFILES := ${addprefix $(OBJECTDIR)/,${call oname, $(CPU_START_SOURCEFILES)}} ### Compilation rules CUSTOM_RULE_LINK = 1 .SECONDEXPANSION: -%.elf: $(CPU_STARTFILES) $$(CONTIKI_OBJECTFILES) $(PROJECT_OBJECTFILES) $(PROJECT_LIBRARIES) $(LDSCRIPT) +%.elf: $(CPU_STARTFILES) $$(CONTIKI_OBJECTFILES) $(PROJECT_OBJECTFILES) $(PROJECT_LIBRARIES) $(TRACE_LD) - $(Q)$(LD) $(LDFLAGS) ${filter-out $(LDSCRIPT) %.a,$^} ${filter %.a,$^} $(TARGET_LIBFILES) -lm -o $@ + $(Q)$(LD) $(LDFLAGS) ${filter %.o %.a,$^} $(TARGET_LIBFLAGS) -o $@ include $(CONTIKI)/arch/cpu/arm/cortex-m/Makefile.cortex-m diff --git a/arch/cpu/arm/cortex-m/cm4/Makefile.cm4 b/arch/cpu/arm/cortex-m/cm4/Makefile.cm4 index 886b33ad4..180c5cd5a 100644 --- a/arch/cpu/arm/cortex-m/cm4/Makefile.cm4 +++ b/arch/cpu/arm/cortex-m/cm4/Makefile.cm4 @@ -4,8 +4,11 @@ CFLAGS += -mcpu=cortex-m4 LDFLAGS += -mcpu=cortex-m4 -nostartfiles LDFLAGS += -T $(LDSCRIPT) -LDFLAGS += -Wl,--gc-sections,--sort-section=alignment -LDFLAGS += -Wl,-Map=$(@:.elf=-$(TARGET).map),--cref,--no-warn-mismatch +LDFLAGS += -Wl,--gc-sections +LDFLAGS += -Wl,--sort-section=alignment +LDFLAGS += -Wl,-Map=$(@:.elf=-$(TARGET).map) +LDFLAGS += -Wl,--cref +LDFLAGS += -Wl,--no-warn-mismatch TARGET_LIBFLAGS := -Wl,--start-group $(TARGET_LIBFILES) -lc -lgcc -lm -lnosys -Wl,--end-group diff --git a/arch/cpu/cc13xx-cc26xx/cc13x0-cc26x0/cc13x0-cc26x0.lds b/arch/cpu/cc13xx-cc26xx/cc13x0-cc26x0/cc13x0-cc26x0.lds index 594779b1b..0e8e66510 100644 --- a/arch/cpu/cc13xx-cc26xx/cc13x0-cc26x0/cc13x0-cc26x0.lds +++ b/arch/cpu/cc13xx-cc26xx/cc13x0-cc26x0/cc13x0-cc26x0.lds @@ -34,7 +34,7 @@ * Default Linker script for the Texas Instruments CC1310 */ -STACKSIZE = 1024; +MIN_STACKSIZE = 0x600; HEAPSIZE = 256; MEMORY @@ -46,6 +46,7 @@ MEMORY */ FLASH_CCFG (RX) : ORIGIN = 0x0001ffa8, LENGTH = 0x00000058 SRAM (RWX) : ORIGIN = 0x20000000, LENGTH = 0x00005000 + GPRAM (RWX) : ORIGIN = 0x11000000, LENGTH = 0x00002000 } REGION_ALIAS("REGION_TEXT", FLASH); @@ -192,6 +193,8 @@ SECTIONS { __HeapLimit = __heap_end__; } > REGION_HEAP AT> REGION_HEAP + PROVIDE(STACKSIZE = ORIGIN(SRAM) + LENGTH(SRAM) - ALIGN(0x8)); + .stack (NOLOAD) : ALIGN(0x8) { _stack = .; __stack = .; @@ -199,5 +202,6 @@ SECTIONS { . += STACKSIZE; _stack_end = .; __stack_end = .; + ASSERT(STACKSIZE >= MIN_STACKSIZE, "Error: No room left for the stack"); } > REGION_STACK AT> REGION_STACK } diff --git a/arch/cpu/cc13xx-cc26xx/cc13x2-cc26x2/cc13x2-cc26x2.lds b/arch/cpu/cc13xx-cc26xx/cc13x2-cc26x2/cc13x2-cc26x2.lds index 91c5e1bd0..9da90ebcd 100644 --- a/arch/cpu/cc13xx-cc26xx/cc13x2-cc26x2/cc13x2-cc26x2.lds +++ b/arch/cpu/cc13xx-cc26xx/cc13x2-cc26x2/cc13x2-cc26x2.lds @@ -34,7 +34,7 @@ * Default Linker script for the Texas Instruments CC1352 */ -STACKSIZE = 1024; +MIN_STACKSIZE = 0x600; HEAPSIZE = 256; /* Size of heap buffer used by HeapMem */ MEMORY @@ -193,6 +193,8 @@ SECTIONS { __HeapLimit = __heap_end__; } > REGION_HEAP AT> REGION_HEAP + PROVIDE(STACKSIZE = ORIGIN(SRAM) + LENGTH(SRAM) - ALIGN(0x8)); + .stack (NOLOAD) : ALIGN(0x8) { _stack = .; __stack = .; @@ -200,5 +202,6 @@ SECTIONS { . += STACKSIZE; _stack_end = .; __stack_end = .; + ASSERT(STACKSIZE >= MIN_STACKSIZE, "Error: No room left for the stack"); } > REGION_STACK AT> REGION_STACK } diff --git a/arch/cpu/cc13xx-cc26xx/dev/ieee-addr.c b/arch/cpu/cc13xx-cc26xx/dev/ieee-addr.c index 144240cc4..b28d7ab9c 100644 --- a/arch/cpu/cc13xx-cc26xx/dev/ieee-addr.c +++ b/arch/cpu/cc13xx-cc26xx/dev/ieee-addr.c @@ -40,10 +40,18 @@ #include "contiki.h" #include "net/linkaddr.h" #include "ieee-addr.h" - +/*---------------------------------------------------------------------------*/ +#include +#include DeviceFamily_constructPath(inc/hw_memmap.h) +#include DeviceFamily_constructPath(inc/hw_fcfg1.h) +#include DeviceFamily_constructPath(inc/hw_ccfg.h) +/*---------------------------------------------------------------------------*/ #include #include /*---------------------------------------------------------------------------*/ +#define IEEE_MAC_PRIMARY_ADDRESS (FCFG1_BASE + FCFG1_O_MAC_15_4_0) +#define IEEE_MAC_SECONDARY_ADDRESS (CCFG_BASE + CCFG_O_IEEE_MAC_0) +/*---------------------------------------------------------------------------*/ void ieee_addr_cpy_to(uint8_t *dst, uint8_t len) { @@ -55,7 +63,7 @@ ieee_addr_cpy_to(uint8_t *dst, uint8_t len) int i; /* Reading from primary location... */ - uint8_t *location = (uint8_t *)IEEE_ADDR_LOCATION_PRIMARY; + const uint8_t *location = (uint8_t *)IEEE_MAC_PRIMARY_ADDRESS; /* * ...unless we can find a byte != 0xFF in secondary @@ -65,9 +73,9 @@ ieee_addr_cpy_to(uint8_t *dst, uint8_t len) * actual number of bytes the caller wants to copy over. */ for(i = 0; i < 8; i++) { - if(((uint8_t *)IEEE_ADDR_LOCATION_SECONDARY)[i] != 0xFF) { + if(((uint8_t *)IEEE_MAC_SECONDARY_ADDRESS)[i] != 0xFF) { /* A byte in the secondary location is not 0xFF. Use the secondary */ - location = (uint8_t *)IEEE_ADDR_LOCATION_SECONDARY; + location = (uint8_t *)IEEE_MAC_SECONDARY_ADDRESS; break; } } diff --git a/arch/cpu/cc13xx-cc26xx/dev/rf-ieee-mode.c b/arch/cpu/cc13xx-cc26xx/dev/rf-ieee-mode.c index 8d8c16e47..08e95a983 100644 --- a/arch/cpu/cc13xx-cc26xx/dev/rf-ieee-mode.c +++ b/arch/cpu/cc13xx-cc26xx/dev/rf-ieee-mode.c @@ -51,11 +51,16 @@ #include "sys/cc.h" /*---------------------------------------------------------------------------*/ /* RF driver and RF Core API */ -#include -#include -#include -#include -#include +#include +#include DeviceFamily_constructPath(driverlib/rf_common_cmd.h) +#include DeviceFamily_constructPath(driverlib/rf_data_entry.h) +#include DeviceFamily_constructPath(driverlib/rf_mailbox.h) +// rf_ieee_cmd and rf_ieee_mailbox included by RF settings because of the +// discrepancy between CC13x0 and CC13x2 IEEE support. CC13x0 doesn't provide +// RFCore definitions of IEEE commandos, and are therefore included locally +// from the Contiki build system. CC13x2 includes these normally from driverlib. +// This is taken care of RF settings. + #include /*---------------------------------------------------------------------------*/ /* SimpleLink Platform RF dev */ @@ -120,8 +125,8 @@ #endif /* Configuration for TX power table */ -#ifdef TX_POWER_CONF_TABLE -# define TX_POWER_TABLE TX_POWER_CONF_TABLE +#ifdef IEEE_MODE_CONF_TX_POWER_TABLE +# define TX_POWER_TABLE IEEE_MODE_CONF_TX_POWER_TABLE #else # define TX_POWER_TABLE ieeeTxPowerTable #endif @@ -143,7 +148,7 @@ #define IEEE_MODE_CHAN_MIN 11 #define IEEE_MODE_CHAN_MAX 26 -#define IEEE_MODE_CHAN_IN_RANGE(ch) (((ch) >= IEEE_MODE_CHAN_MIN) && ((ch) <= IEEE_MODE_CHAN_MAX)) +#define IEEE_MODE_CHAN_IN_RANGE(ch) ((IEEE_MODE_CHAN_MIN <= (ch)) && ((ch) <= IEEE_MODE_CHAN_MAX)) /* Sanity check of default IEEE channel */ #if !IEEE_MODE_CHAN_IN_RANGE(IEEE_MODE_CHANNEL) @@ -172,10 +177,10 @@ static RF_Object g_rfObj; static RF_Handle g_rfHandle; /* RF Core command pointers */ -static volatile rfc_CMD_RADIO_SETUP_t *g_vpCmdRadioSetup = &RF_cmdRadioSetup; -static volatile rfc_CMD_FS_t *g_vpCmdFs = &RF_cmdIeeeFs; -static volatile rfc_CMD_IEEE_TX_t *g_vpCmdTx = &RF_cmdIeeeTx; -static volatile rfc_CMD_IEEE_RX_t *g_vpCmdRx = &RF_cmdIeeeRx; +#define cmd_radio_setup ((volatile rfc_CMD_RADIO_SETUP_t*)&RF_cmdRadioSetup) +#define cmd_fs ((volatile rfc_CMD_FS_t*) &RF_cmdIeeeFs) +#define cmd_tx ((volatile rfc_CMD_IEEE_TX_t*) &RF_cmdIeeeTx) +#define cmd_rx ((volatile rfc_CMD_IEEE_RX_t*) &RF_cmdIeeeRx) /* RF command handles */ static RF_CmdHandle g_cmdTxHandle; @@ -231,12 +236,6 @@ static volatile uint32_t g_ratOverflowCount; /*---------------------------------------------------------------------------*/ /* Global state */ -/* Current RX channel */ -static volatile uint8_t g_currChannel; - -/* Current TX power */ -static volatile RF_TxPower *g_pCurrTxPower; - /* Are we currently in poll mode? */ static volatile bool g_bPollMode = false; @@ -251,7 +250,7 @@ static volatile uint32_t g_lastTimestamp; typedef enum { POWER_STATE_ON = (1 << 0), POWER_STATE_OFF = (1 << 1), - POWER_STATE_RESTART = (1 << 2), + POWER_STATE_RESTART = POWER_STATE_ON | POWER_STATE_OFF, } PowerState; /*---------------------------------------------------------------------------*/ /* Forward declarations of static functions */ @@ -310,9 +309,11 @@ rf_error_cb(RF_Handle h, RF_CmdHandle ch, RF_EventMask e) { // See SWRZ062B: Synth failed to calibrate, CMD_FS must be repeated if ((ch == RF_ERROR_CMDFS_SYNTH_PROG) && - (g_vpCmdFs->status == ERROR_SYNTH_PROG)) { + (cmd_fs->status == ERROR_SYNTH_PROG)) { // Call CMD_FS async, a synth error will trigger rf_error_cb once more - RF_postCmd(g_rfHandle, (RF_Op*)g_vpCmdFs, RF_PriorityNormal, NULL, 0); + const uint8_t stop_gracefully = 1; + RF_flushCmd(g_rfHandle, RF_CMDHANDLE_FLUSH_ALL, stop_gracefully); + RF_postCmd(g_rfHandle, (RF_Op*)cmd_fs, RF_PriorityNormal, NULL, 0); } } /*---------------------------------------------------------------------------*/ @@ -338,22 +339,22 @@ init_data_queue(void) static void init_rf_params(void) { - g_vpCmdRx->pRxQ = &g_rxDataQueue; - g_vpCmdRx->pOutput = &g_rxStats; + cmd_rx->pRxQ = &g_rxDataQueue; + cmd_rx->pOutput = &g_rxStats; #if IEEE_MODE_PROMISCOUS - g_vpCmdRx->frameFiltOpt.frameFiltEn = 0; + cmd_rx->frameFiltOpt.frameFiltEn = 0; #else - g_vpCmdRx->frameFiltOpt.frameFiltEn = 1; + cmd_rx->frameFiltOpt.frameFiltEn = 1; #endif #if IEEE_MODE_AUTOACK - g_vpCmdRx->frameFiltOpt.autoAckEn = 1; + cmd_rx->frameFiltOpt.autoAckEn = 1; #else - g_vpCmdRx->frameFiltOpt.autoAckEn = 0; + cmd_rx->frameFiltOpt.autoAckEn = 0; #endif - g_vpCmdRx->ccaRssiThr = IEEE_MODE_RSSI_THRESHOLD; + cmd_rx->ccaRssiThr = IEEE_MODE_RSSI_THRESHOLD; // Initialize address filter command g_cmdModFilt.commandNo = CMD_IEEE_MOD_FILT; @@ -364,28 +365,28 @@ init_rf_params(void) static void init_rx_buffers(void) { -#define getEntry(n) (&(g_rxBufs[(n)].dataEntry)) +#define GET_ENTRY(n) (&(g_rxBufs[(n)].dataEntry)) rfc_dataEntry_t *entry = NULL; - const uint16_t length = sizeof(g_rxBufs[0].buf) - 8; + const size_t length = sizeof(g_rxBufs[0].buf) - 8; size_t i; for (i = 0; i < (size_t)(RX_BUF_ENTRIES - 1); ++i) { - entry = getEntry(i); - entry->pNextEntry = (uint8_t*)getEntry(i + 1); + entry = GET_ENTRY(i); + entry->pNextEntry = (uint8_t*)GET_ENTRY(i + 1); entry->config.lenSz = DATA_ENTRY_LENSZ_BYTE; - entry->length = length; + entry->length = (uint16_t)length; } - entry = getEntry(RX_BUF_ENTRIES - 1); - entry->pNextEntry = (uint8_t*)getEntry(0); + entry = GET_ENTRY(RX_BUF_ENTRIES - 1); + entry->pNextEntry = (uint8_t*)GET_ENTRY(0); entry->config.lenSz = DATA_ENTRY_LENSZ_BYTE; - entry->length = length; + entry->length = (uint16_t)length; #undef getEntry } /*---------------------------------------------------------------------------*/ -static void +static bool set_channel(uint8_t channel) { if (!IEEE_MODE_CHAN_IN_RANGE(channel)) { @@ -393,41 +394,62 @@ set_channel(uint8_t channel) channel, IEEE_MODE_CHANNEL); channel = IEEE_MODE_CHANNEL; } - if (channel == g_currChannel) { + if (channel == cmd_rx->channel) { // We are already calibrated to this channel - return; + return true; } - g_currChannel = channel; + + cmd_rx->channel = 0; + // freq = freq_base + freq_spacing * (channel - channel_min) - const uint32_t newFreq = (uint32_t)IEEE_MODE_FREQ_BASE + - (uint32_t)IEEE_MODE_FREQ_SPACING * ((uint32_t)channel - (uint32_t)IEEE_MODE_CHAN_MIN); - const uint16_t freq = (uint16_t)(newFreq / 1000); - const uint16_t frac = (uint16_t)((newFreq - (freq * 1000)) * 65536 / 1000); + const uint32_t newFreq = (uint32_t)(IEEE_MODE_FREQ_BASE + IEEE_MODE_FREQ_SPACING * ((uint32_t)channel - IEEE_MODE_CHAN_MIN)); + const uint32_t freq = newFreq / 1000; + const uint32_t frac = (newFreq - (freq * 1000)) * 65536 / 1000; PRINTF("set_channel: %d = 0x%04X.0x%04X (%lu)\n", - channel, freq, frac, newFreq); + channel, (uint16_t)freq, (uint16_t)frac, newFreq); - g_vpCmdFs->frequency = freq; - g_vpCmdFs->fractFreq = frac; + cmd_fs->frequency = (uint16_t)freq; + cmd_fs->fractFreq = (uint16_t)frac; + + const bool rx_active = (cmd_rx->status == ACTIVE); + + if (rx_active) { + const uint8_t stop_gracefully = 1; + RF_flushCmd(g_rfHandle, RF_CMDHANDLE_FLUSH_ALL, stop_gracefully); + } // Start FS command asynchronously. We don't care when it is finished - RF_postCmd(g_rfHandle, (RF_Op*)g_vpCmdFs, RF_PriorityNormal, NULL, 0); - if (g_vpCmdRx->status == ACTIVE) { - set_rx(POWER_STATE_RESTART); + RF_EventMask events = 0; + uint8_t tries = 0; + bool cmd_ok = false; + do { + events = RF_runCmd(g_rfHandle, (RF_Op*)cmd_fs, RF_PriorityNormal, NULL, 0); + cmd_ok = ((events & RF_EventLastCmdDone) != 0) + && (cmd_fs->status == DONE_OK); + } while (!cmd_ok && (tries++ < 3)); + + if (!cmd_ok) { + return false; } + + cmd_rx->channel = channel; + + if (rx_active) { + set_rx(POWER_STATE_ON); + } + + return true; } /*---------------------------------------------------------------------------*/ static int set_tx_power(const radio_value_t dbm) { - const RF_TxPowerTable_Value txPowerTableValue = RF_TxPowerTable_findValue(TX_POWER_TABLE, (int8_t)dbm); - if (txPowerTableValue.rawValue == RF_TxPowerTable_INVALID_VALUE) { - return CMD_RESULT_ERROR; - } + const RF_TxPowerTable_Value tx_power_table_value = RF_TxPowerTable_findValue(TX_POWER_TABLE, (int8_t)dbm); + const RF_Stat stat = RF_setTxPower(g_rfHandle, tx_power_table_value); - const RF_Stat stat = RF_setTxPower(g_rfHandle, txPowerTableValue); if (stat != RF_StatSuccess) { - PRINTF("RF_setTxPower: stat=0x%02X\n", stat); + PRINTF("set_tx_power: stat=0x%02X\n", stat); return CMD_RESULT_ERROR; } return CMD_RESULT_OK; @@ -436,9 +458,14 @@ set_tx_power(const radio_value_t dbm) static radio_value_t get_tx_power(void) { - return (g_pCurrTxPower) - ? g_pCurrTxPower->power - : (radio_value_t)TX_POWER_UNKNOWN; + const RF_TxPowerTable_Value tx_power_table_value = RF_getTxPower(g_rfHandle); + const int8_t dbm = RF_TxPowerTable_findPowerLevel(TX_POWER_TABLE, tx_power_table_value); + + if (dbm == RF_TxPowerTable_INVALID_DBM) { + PRINTF("get_tx_power: invalid dbm received=%d\n", dbm); + } + + return (radio_value_t)dbm; } /*---------------------------------------------------------------------------*/ static void @@ -505,14 +532,12 @@ init(void) { RF_Params params; RF_Params_init(¶ms); - // Disable automatic power-down just to not interfere with stack timing - params.nInactivityTimeout = 0; params.pErrCb = rf_error_cb; init_rf_params(); init_data_queue(); - g_rfHandle = RF_open(&g_rfObj, &RF_ieeeMode, (RF_RadioSetup*)g_vpCmdRadioSetup, ¶ms); + g_rfHandle = RF_open(&g_rfObj, &RF_ieeeMode, (RF_RadioSetup*)cmd_radio_setup, ¶ms); assert(g_rfHandle != NULL); set_channel(IEEE_MODE_CHANNEL); @@ -552,26 +577,23 @@ rf_is_on(void) static int set_rx(const PowerState state) { - if (state & (POWER_STATE_OFF | POWER_STATE_RESTART)) { + if (state & POWER_STATE_OFF) { // Stop RX gracefully, don't care about the result - const uint8_t stopGracefully = 1; - RF_cancelCmd(g_rfHandle, g_cmdRxHandle, stopGracefully); + const uint8_t stop_gracefully = 1; + RF_cancelCmd(g_rfHandle, g_cmdRxHandle, stop_gracefully); } - if (state & (POWER_STATE_ON | POWER_STATE_RESTART)) { - if (g_vpCmdRx->status == ACTIVE) { + if (state & POWER_STATE_ON) { + if (cmd_rx->status == ACTIVE) { PRINTF("set_rx(on): already in RX\n"); return CMD_RESULT_OK; } - RF_ScheduleCmdParams schedParams = { - .endTime = 0, - .priority = RF_PriorityNormal, - //.bIeeeBgCmd = true, - }; + RF_ScheduleCmdParams schedParams; + RF_ScheduleCmdParams_init(&schedParams); - g_vpCmdRx->status = IDLE; - g_cmdRxHandle = RF_scheduleCmd(g_rfHandle, (RF_Op*)g_vpCmdRx, &schedParams, rx_cb, + cmd_rx->status = IDLE; + g_cmdRxHandle = RF_scheduleCmd(g_rfHandle, (RF_Op*)cmd_rx, &schedParams, rx_cb, RF_EventRxOk | RF_EventRxBufFull | RF_EventRxEntryDone); if ((g_cmdRxHandle == RF_ALLOC_ERROR) || (g_cmdRxHandle == RF_SCHEDULE_CMD_ERROR)) { PRINTF("transmit: unable to allocate RX command\n"); @@ -586,25 +608,22 @@ static int transmit_aux(unsigned short transmit_len) { // Configure TX command - g_vpCmdTx->payloadLen = (uint8_t)transmit_len; - g_vpCmdTx->pPayload = &g_txBuf[TX_BUF_HDR_LEN]; - g_vpCmdTx->startTime = 0; - g_vpCmdTx->startTrigger.triggerType = TRIG_NOW; + cmd_tx->payloadLen = (uint8_t)transmit_len; + cmd_tx->pPayload = &g_txBuf[TX_BUF_HDR_LEN]; + cmd_tx->startTime = 0; + cmd_tx->startTrigger.triggerType = TRIG_NOW; - RF_ScheduleCmdParams schedParams = { - .endTime = 0, - .priority = RF_PriorityNormal, - //.bIeeeBgCmd = false, - }; + RF_ScheduleCmdParams schedParams; + RF_ScheduleCmdParams_init(&schedParams); // As IEEE_TX is a FG command, the TX operation will be executed // either way if RX is running or not - g_vpCmdTx->status = IDLE; - g_cmdTxHandle = RF_scheduleCmd(g_rfHandle, (RF_Op*)g_vpCmdTx, &schedParams, NULL, 0); + cmd_tx->status = IDLE; + g_cmdTxHandle = RF_scheduleCmd(g_rfHandle, (RF_Op*)cmd_tx, &schedParams, NULL, 0); if ((g_cmdTxHandle == RF_ALLOC_ERROR) || (g_cmdTxHandle == RF_SCHEDULE_CMD_ERROR)) { // Failure sending the CMD_IEEE_TX command PRINTF("transmit: failed to allocate TX command cmdHandle=%d, status=%04x\n", - g_cmdTxHandle, g_vpCmdTx->status); + g_cmdTxHandle, cmd_tx->status); return RADIO_TX_ERR; } @@ -614,7 +633,7 @@ transmit_aux(unsigned short transmit_len) RF_EventMask events = RF_pendCmd(g_rfHandle, g_cmdTxHandle, 0); if ((events & (RF_EventFGCmdDone | RF_EventLastFGCmdDone)) == 0) { PRINTF("transmit: TX command error events=0x%08llx, status=0x%04x\n", - events, g_vpCmdTx->status); + events, cmd_tx->status); return RADIO_TX_ERR; } @@ -624,7 +643,7 @@ transmit_aux(unsigned short transmit_len) static int transmit(unsigned short transmit_len) { - const bool was_rx = (g_vpCmdRx->status == ACTIVE); + const bool was_rx = (cmd_rx->status == ACTIVE); if (g_bSendOnCca && channel_clear() != 1) { PRINTF("transmit: channel wasn't clear\n"); @@ -734,7 +753,7 @@ channel_clear_aux(void) static int channel_clear(void) { - const bool was_rx = (g_vpCmdRx->status == ACTIVE); + const bool was_rx = (cmd_rx->status == ACTIVE); if (!was_rx && set_rx(POWER_STATE_ON) != CMD_RESULT_OK) { PRINTF("channel_clear: unable to start RX\n"); return CHANNEL_CLEAR_ERROR; @@ -752,7 +771,7 @@ static int receiving_packet(void) { // If we are not in RX, we are not receiving - if (g_vpCmdRx->status != ACTIVE) { + if (cmd_rx->status != ACTIVE) { PRINTF("receiving_packet: not in RX\n"); return 0; } @@ -854,23 +873,23 @@ get_value(radio_param_t param, radio_value_t *value) return RADIO_RESULT_OK; case RADIO_PARAM_CHANNEL: - *value = (radio_value_t)g_currChannel; + *value = (radio_value_t)cmd_rx->channel; return RADIO_RESULT_OK; case RADIO_PARAM_PAN_ID: - *value = (radio_value_t)g_vpCmdRx->localPanID; + *value = (radio_value_t)cmd_rx->localPanID; return RADIO_RESULT_OK; case RADIO_PARAM_16BIT_ADDR: - *value = (radio_value_t)g_vpCmdRx->localShortAddr; + *value = (radio_value_t)cmd_rx->localShortAddr; return RADIO_RESULT_OK; case RADIO_PARAM_RX_MODE: *value = 0; - if (g_vpCmdRx->frameFiltOpt.frameFiltEn) { + if (cmd_rx->frameFiltOpt.frameFiltEn) { *value |= (radio_value_t)RADIO_RX_MODE_ADDRESS_FILTER; } - if (g_vpCmdRx->frameFiltOpt.autoAckEn) { + if (cmd_rx->frameFiltOpt.autoAckEn) { *value |= (radio_value_t)RADIO_RX_MODE_AUTOACK; } if (g_bPollMode) { @@ -889,7 +908,7 @@ get_value(radio_param_t param, radio_value_t *value) : RADIO_RESULT_OK; case RADIO_PARAM_CCA_THRESHOLD: - *value = g_vpCmdRx->ccaRssiThr; + *value = cmd_rx->ccaRssiThr; return RADIO_RESULT_OK; case RADIO_PARAM_RSSI: @@ -930,24 +949,21 @@ get_value(radio_param_t param, radio_value_t *value) static radio_result_t set_value(radio_param_t param, radio_value_t value) { - switch(param) { + switch (param) { case RADIO_PARAM_POWER_MODE: - switch (value) { - case RADIO_POWER_MODE_ON: + if (value == RADIO_POWER_MODE_ON) { if (on() != CMD_RESULT_OK) { PRINTF("set_value: on() failed (1)\n"); return RADIO_RESULT_ERROR; } return RADIO_RESULT_OK; - - case RADIO_POWER_MODE_OFF: + } else if (value == RADIO_POWER_MODE_OFF) { off(); return RADIO_RESULT_OK; - - default: - return RADIO_RESULT_INVALID_VALUE; } + return RADIO_RESULT_INVALID_VALUE; + case RADIO_PARAM_CHANNEL: if (!IEEE_MODE_CHAN_IN_RANGE(value)) { return RADIO_RESULT_INVALID_VALUE; @@ -956,7 +972,7 @@ set_value(radio_param_t param, radio_value_t value) return RADIO_RESULT_OK; case RADIO_PARAM_PAN_ID: - g_vpCmdRx->localPanID = (uint16_t)value; + cmd_rx->localPanID = (uint16_t)value; if (rf_is_on() && set_rx(POWER_STATE_RESTART) != CMD_RESULT_OK) { PRINTF("failed to restart RX"); return RADIO_RESULT_ERROR; @@ -964,7 +980,7 @@ set_value(radio_param_t param, radio_value_t value) return RADIO_RESULT_OK; case RADIO_PARAM_16BIT_ADDR: - g_vpCmdRx->localShortAddr = (uint16_t)value; + cmd_rx->localShortAddr = (uint16_t)value; if (rf_is_on() && set_rx(POWER_STATE_RESTART) != CMD_RESULT_OK) { PRINTF("failed to restart RX"); return RADIO_RESULT_ERROR; @@ -977,15 +993,15 @@ set_value(radio_param_t param, radio_value_t value) return RADIO_RESULT_INVALID_VALUE; } - g_vpCmdRx->frameFiltOpt.frameFiltEn = (value & RADIO_RX_MODE_ADDRESS_FILTER) != 0; - g_vpCmdRx->frameFiltOpt.frameFiltStop = 1; - g_vpCmdRx->frameFiltOpt.autoAckEn = (value & RADIO_RX_MODE_AUTOACK) != 0; - g_vpCmdRx->frameFiltOpt.slottedAckEn = 0; - g_vpCmdRx->frameFiltOpt.autoPendEn = 0; - g_vpCmdRx->frameFiltOpt.defaultPend = 0; - g_vpCmdRx->frameFiltOpt.bPendDataReqOnly = 0; - g_vpCmdRx->frameFiltOpt.bPanCoord = 0; - g_vpCmdRx->frameFiltOpt.bStrictLenFilter = 0; + cmd_rx->frameFiltOpt.frameFiltEn = (value & RADIO_RX_MODE_ADDRESS_FILTER) != 0; + cmd_rx->frameFiltOpt.frameFiltStop = 1; + cmd_rx->frameFiltOpt.autoAckEn = (value & RADIO_RX_MODE_AUTOACK) != 0; + cmd_rx->frameFiltOpt.slottedAckEn = 0; + cmd_rx->frameFiltOpt.autoPendEn = 0; + cmd_rx->frameFiltOpt.defaultPend = 0; + cmd_rx->frameFiltOpt.bPendDataReqOnly = 0; + cmd_rx->frameFiltOpt.bPanCoord = 0; + cmd_rx->frameFiltOpt.bStrictLenFilter = 0; const bool bOldPollMode = g_bPollMode; g_bPollMode = (value & RADIO_RX_MODE_POLL_MODE) != 0; @@ -1022,7 +1038,7 @@ set_value(radio_param_t param, radio_value_t value) : RADIO_RESULT_OK; case RADIO_PARAM_CCA_THRESHOLD: - g_vpCmdRx->ccaRssiThr = (int8_t)value; + cmd_rx->ccaRssiThr = (int8_t)value; if (rf_is_on() && set_rx(POWER_STATE_RESTART) != CMD_RESULT_OK) { PRINTF("failed to restart RX"); return RADIO_RESULT_ERROR; @@ -1043,12 +1059,12 @@ get_object(radio_param_t param, void *dest, size_t size) switch (param) { case RADIO_PARAM_64BIT_ADDR: { - const size_t srcSize = sizeof(g_vpCmdRx->localExtAddr); + const size_t srcSize = sizeof(cmd_rx->localExtAddr); if(size != srcSize) { return RADIO_RESULT_INVALID_VALUE; } - const uint8_t *pSrc = (const uint8_t *)&g_vpCmdRx->localExtAddr; + const uint8_t *pSrc = (uint8_t *)&(cmd_rx->localExtAddr); uint8_t *pDest = dest; for(size_t i = 0; i < srcSize; ++i) { pDest[i] = pSrc[srcSize - 1 - i]; @@ -1079,18 +1095,18 @@ set_object(radio_param_t param, const void *src, size_t size) switch (param) { case RADIO_PARAM_64BIT_ADDR: { - const size_t destSize = sizeof(g_vpCmdRx->localExtAddr); + const size_t destSize = sizeof(cmd_rx->localExtAddr); if (size != destSize) { return RADIO_RESULT_INVALID_VALUE; } const uint8_t *pSrc = (const uint8_t *)src; - uint8_t *pDest = (uint8_t *)&g_vpCmdRx->localExtAddr; + uint8_t *pDest = (uint8_t *)&cmd_rx->localExtAddr; for (size_t i = 0; i < destSize; ++i) { pDest[i] = pSrc[destSize - 1 - i]; } - const bool is_rx = (g_vpCmdRx->status == ACTIVE); + const bool is_rx = (cmd_rx->status == ACTIVE); if (is_rx && set_rx(POWER_STATE_RESTART) != CMD_RESULT_OK) { return RADIO_RESULT_ERROR; } diff --git a/arch/cpu/cc13xx-cc26xx/dev/rf-prop-mode.c b/arch/cpu/cc13xx-cc26xx/dev/rf-prop-mode.c index 26c2a3637..be893e8bc 100644 --- a/arch/cpu/cc13xx-cc26xx/dev/rf-prop-mode.c +++ b/arch/cpu/cc13xx-cc26xx/dev/rf-prop-mode.c @@ -165,8 +165,8 @@ static rfc_propRxOutput_t rx_stats; #define ENTER_RX_WAIT_TIMEOUT (RTIMER_SECOND >> 10) /*---------------------------------------------------------------------------*/ /* Configuration for TX power table */ -#ifdef TX_POWER_CONF_TABLE -# define TX_POWER_TABLE TX_POWER_CONF_TABLE +#ifdef PROP_MODE_CONF_TX_POWER_TABLE +# define TX_POWER_TABLE PROP_MODE_CONF_TX_POWER_TABLE #else # define TX_POWER_TABLE propTxPowerTable #endif @@ -209,18 +209,18 @@ volatile static uint8_t *rx_read_entry; static uint8_t tx_buf[TX_BUF_HDR_LEN + TX_BUF_PAYLOAD_LEN] CC_ALIGN(4); /*---------------------------------------------------------------------------*/ -volatile static rfc_CMD_PROP_RADIO_DIV_SETUP_t *gvp_cmd_radio_div_setup = &RF_cmdPropRadioDivSetup; -volatile static rfc_CMD_FS_t *gvp_cmd_fs = &RF_cmdPropFs; -volatile static rfc_CMD_PROP_TX_ADV_t *gvp_cmd_tx_adv = &RF_cmdPropTxAdv; -volatile static rfc_CMD_PROP_RX_ADV_t *gvp_cmd_rx_adv = &RF_cmdPropRxAdv; +#define cmd_radio_setup ((volatile rfc_CMD_PROP_RADIO_DIV_SETUP_t *)&RF_cmdPropRadioDivSetup) +#define cmd_fs ((volatile rfc_CMD_FS_t *)&RF_cmdPropFs) +#define cmd_tx ((volatile rfc_CMD_PROP_TX_ADV_t *)&RF_cmdPropTxAdv) +#define cmd_rx ((volatile rfc_CMD_PROP_RX_ADV_t *)&RF_cmdPropRxAdv) /*---------------------------------------------------------------------------*/ /* RF driver */ static RF_Object rfObject; static RF_Handle rfHandle; /*---------------------------------------------------------------------------*/ -static inline bool rf_is_transmitting(void) { return gvp_cmd_tx_adv->status == ACTIVE; } -static inline bool rf_is_receiving(void) { return gvp_cmd_rx_adv->status == ACTIVE; } -static inline bool rf_is_on(void) { return rf_is_transmitting() || rf_is_receiving(); } +static CC_INLINE bool rf_is_transmitting(void) { return cmd_tx->status == ACTIVE; } +static CC_INLINE bool rf_is_receiving(void) { return cmd_rx->status == ACTIVE; } +static CC_INLINE bool rf_is_on(void) { return rf_is_transmitting() || rf_is_receiving(); } /*---------------------------------------------------------------------------*/ static void rf_rx_callback(RF_Handle client, RF_CmdHandle command, RF_EventMask events) @@ -233,15 +233,15 @@ rf_rx_callback(RF_Handle client, RF_CmdHandle command, RF_EventMask events) static CmdResult rf_start_rx() { - gvp_cmd_rx_adv->status = IDLE; + cmd_rx->status = IDLE; /* * Set the max Packet length. This is for the payload only, therefore * 2047 - length offset */ - gvp_cmd_rx_adv->maxPktLen = DOT_4G_MAX_FRAME_LEN - gvp_cmd_rx_adv->lenOffset; + cmd_rx->maxPktLen = DOT_4G_MAX_FRAME_LEN - cmd_rx->lenOffset; - RF_CmdHandle rxCmdHandle = RF_postCmd(rfHandle, (RF_Op*)gvp_cmd_rx_adv, RF_PriorityNormal, + RF_CmdHandle rxCmdHandle = RF_postCmd(rfHandle, (RF_Op*)cmd_rx, RF_PriorityNormal, &rf_rx_callback, RF_EventRxEntryDone); if (rxCmdHandle == RF_ALLOC_ERROR) { return CMD_RESULT_ERROR; @@ -254,7 +254,7 @@ rf_start_rx() if (!rf_is_receiving()) { PRINTF("RF_cmdPropRxAdv: handle=0x%08lx, status=0x%04x\n", - (unsigned long)rxCmdHandle, gvp_cmd_rx_adv->status); + (unsigned long)rxCmdHandle, cmd_rx->status); rf_switch_off(); return CMD_RESULT_ERROR; } @@ -275,10 +275,10 @@ rf_stop_rx(void) /* Todo: maybe do a RF_pendCmd() to synchronize with command execution. */ - if(gvp_cmd_rx_adv->status != PROP_DONE_STOPPED && - gvp_cmd_rx_adv->status != PROP_DONE_ABORT) { + if(cmd_rx->status != PROP_DONE_STOPPED && + cmd_rx->status != PROP_DONE_ABORT) { PRINTF("RF_cmdPropRxAdv cancel: status=0x%04x\n", - gvp_cmd_rx_adv->status); + cmd_rx->status); return CMD_RESULT_ERROR; } @@ -290,8 +290,8 @@ rf_stop_rx(void) static CmdResult rf_run_setup() { - RF_runCmd(rfHandle, (RF_Op*)gvp_cmd_radio_div_setup, RF_PriorityNormal, NULL, 0); - if (gvp_cmd_radio_div_setup->status != PROP_DONE_OK) { + RF_runCmd(rfHandle, (RF_Op*)cmd_radio_setup, RF_PriorityNormal, NULL, 0); + if (cmd_radio_setup->status != PROP_DONE_OK) { return CMD_RESULT_ERROR; } @@ -329,7 +329,7 @@ get_channel(void) { uint32_t freq_khz; - freq_khz = gvp_cmd_fs->frequency * 1000; + freq_khz = cmd_fs->frequency * 1000; /* * For some channels, fractFreq * 1000 / 65536 will return 324.99xx. @@ -337,7 +337,7 @@ get_channel(void) * function returning channel - 1 instead of channel. Thus, we do a quick * positive integer round up. */ - freq_khz += (((gvp_cmd_fs->fractFreq * 1000) + 65535) / 65536); + freq_khz += (((cmd_fs->fractFreq * 1000) + 65535) / 65536); return (freq_khz - DOT_15_4G_CHAN0_FREQUENCY) / DOT_15_4G_CHANNEL_SPACING; } @@ -353,9 +353,9 @@ set_channel(uint8_t channel) PRINTF("set_channel: %u = 0x%04x.0x%04x (%lu)\n", channel, freq, frac, new_freq); - gvp_cmd_radio_div_setup->centerFreq = freq; - gvp_cmd_fs->frequency = freq; - gvp_cmd_fs->fractFreq = frac; + cmd_radio_setup->centerFreq = freq; + cmd_fs->frequency = freq; + cmd_fs->fractFreq = frac; // Todo: Need to re-run setup command when deviation from previous frequency // is too large @@ -363,7 +363,7 @@ set_channel(uint8_t channel) // We don't care whether the FS command is successful because subsequent // TX and RX commands will tell us indirectly. - RF_postCmd(rfHandle, (RF_Op*)gvp_cmd_fs, RF_PriorityNormal, NULL, 0); + RF_postCmd(rfHandle, (RF_Op*)cmd_fs, RF_PriorityNormal, NULL, 0); } /*---------------------------------------------------------------------------*/ /* Returns the current TX power in dBm */ @@ -454,11 +454,11 @@ transmit(unsigned short transmit_len) * pktLen: Total number of bytes in the TX buffer, including the header if * one exists, but not including the CRC (which is not present in the buffer) */ - gvp_cmd_tx_adv->pktLen = transmit_len + DOT_4G_PHR_LEN; - gvp_cmd_tx_adv->pPkt = tx_buf; + cmd_tx->pktLen = transmit_len + DOT_4G_PHR_LEN; + cmd_tx->pPkt = tx_buf; // TODO: Register callback - RF_runCmd(rfHandle, (RF_Op*)gvp_cmd_tx_adv, RF_PriorityNormal, NULL, 0); + RF_runCmd(rfHandle, (RF_Op*)cmd_tx, RF_PriorityNormal, NULL, 0); // if (txHandle == RF_ALLOC_ERROR) // { // /* Failure sending the CMD_PROP_TX command */ @@ -474,20 +474,20 @@ transmit(unsigned short transmit_len) // /* Idle away while the command is running */ // RF_pendCmd(rfHandle, txHandle, RF_EventLastCmdDone); - if(gvp_cmd_tx_adv->status == PROP_DONE_OK) { + if(cmd_tx->status == PROP_DONE_OK) { /* Sent OK */ ret = RADIO_TX_OK; } else { /* Operation completed, but frame was not sent */ PRINTF("transmit: Not Sent OK status=0x%04x\n", - gvp_cmd_tx_adv->status); + cmd_tx->status); ret = RADIO_TX_ERR; } ENERGEST_OFF(ENERGEST_TYPE_TRANSMIT); /* Workaround. Set status to IDLE */ - gvp_cmd_tx_adv->status = IDLE; + cmd_tx->status = IDLE; if (was_off) { RF_yield(rfHandle); @@ -636,7 +636,7 @@ rf_switch_off(void) RF_yield(rfHandle); /* We pulled the plug, so we need to restore the status manually */ - gvp_cmd_rx_adv->status = IDLE; + cmd_rx->status = IDLE; return CMD_RESULT_OK; } @@ -644,44 +644,50 @@ rf_switch_off(void) static radio_result_t get_value(radio_param_t param, radio_value_t *value) { - if(!value) { + if (!value) { return RADIO_RESULT_INVALID_VALUE; } - switch(param) { + switch (param) { case RADIO_PARAM_POWER_MODE: /* On / off */ *value = rf_is_on() ? RADIO_POWER_MODE_ON : RADIO_POWER_MODE_OFF; return RADIO_RESULT_OK; + case RADIO_PARAM_CHANNEL: *value = (radio_value_t)get_channel(); return RADIO_RESULT_OK; + case RADIO_PARAM_TXPOWER: *value = get_tx_power(); return RADIO_RESULT_OK; + case RADIO_PARAM_CCA_THRESHOLD: *value = rssi_threshold; return RADIO_RESULT_OK; + case RADIO_PARAM_RSSI: *value = get_rssi(); + return (*value == RF_CMD_CCA_REQ_RSSI_UNKNOWN) + ? RADIO_RESULT_ERROR + : RADIO_RESULT_OK; - if(*value == RF_CMD_CCA_REQ_RSSI_UNKNOWN) { - return RADIO_RESULT_ERROR; - } else { - return RADIO_RESULT_OK; - } case RADIO_CONST_CHANNEL_MIN: *value = 0; return RADIO_RESULT_OK; + case RADIO_CONST_CHANNEL_MAX: *value = DOT_15_4G_CHANNEL_MAX; return RADIO_RESULT_OK; + case RADIO_CONST_TXPOWER_MIN: *value = (radio_value_t)TX_POWER_MIN; return RADIO_RESULT_OK; + case RADIO_CONST_TXPOWER_MAX: *value = (radio_value_t)TX_POWER_MAX; return RADIO_RESULT_OK; + default: return RADIO_RESULT_NOT_SUPPORTED; } @@ -701,6 +707,7 @@ set_value(radio_param_t param, radio_value_t value) return RADIO_RESULT_OK; } return RADIO_RESULT_INVALID_VALUE; + case RADIO_PARAM_CHANNEL: if(value < 0 || value > DOT_15_4G_CHANNEL_MAX) { @@ -715,15 +722,17 @@ set_value(radio_param_t param, radio_value_t value) set_channel((uint8_t)value); break; + case RADIO_PARAM_TXPOWER: return set_tx_power(value); case RADIO_PARAM_RX_MODE: return RADIO_RESULT_OK; + case RADIO_PARAM_CCA_THRESHOLD: rssi_threshold = (int8_t)value; return RADIO_RESULT_OK; - break; + default: return RADIO_RESULT_NOT_SUPPORTED; } @@ -768,7 +777,7 @@ rf_init(void) // Disable automatic power-down just to not interfere with stack timing params.nInactivityTimeout = 0; - rfHandle = RF_open(&rfObject, &RF_propMode, (RF_RadioSetup*)gvp_cmd_radio_div_setup, ¶ms); + rfHandle = RF_open(&rfObject, &RF_propMode, (RF_RadioSetup*)cmd_radio_setup, ¶ms); assert(rfHandle != NULL); /* Initialise RX buffers */ @@ -781,8 +790,8 @@ rf_init(void) /* Initialize current read pointer to first element (used in ISR) */ rx_read_entry = rx_buf[0]; - gvp_cmd_rx_adv->pQueue = &rx_data_queue; - gvp_cmd_rx_adv->pOutput = (uint8_t *)&rx_stats; + cmd_rx->pQueue = &rx_data_queue; + cmd_rx->pOutput = (uint8_t *)&rx_stats; set_channel(RF_CORE_CHANNEL); diff --git a/arch/cpu/cc13xx-cc26xx/dev/startup_cc13xx_cc26xx_gcc.c b/arch/cpu/cc13xx-cc26xx/dev/startup_cc13xx_cc26xx_gcc.c index 6a0042618..ac35116ef 100644 --- a/arch/cpu/cc13xx-cc26xx/dev/startup_cc13xx_cc26xx_gcc.c +++ b/arch/cpu/cc13xx-cc26xx/dev/startup_cc13xx_cc26xx_gcc.c @@ -246,6 +246,8 @@ nmiISR(void) } } +volatile int x__; + //***************************************************************************** // // This is the code that gets called when the processor receives a fault @@ -256,6 +258,7 @@ nmiISR(void) static void faultISR(void) { + x__ = 0; /* Enter an infinite loop. */ while(1) { @@ -273,6 +276,7 @@ faultISR(void) static void busFaultHandler(void) { + x__ = 0; /* Enter an infinite loop. */ while(1) { diff --git a/arch/cpu/cc13xx-cc26xx/dev/uart0-arch.c b/arch/cpu/cc13xx-cc26xx/dev/uart0-arch.c index 3c662d0d2..00390a3e5 100644 --- a/arch/cpu/cc13xx-cc26xx/dev/uart0-arch.c +++ b/arch/cpu/cc13xx-cc26xx/dev/uart0-arch.c @@ -37,6 +37,7 @@ */ /*---------------------------------------------------------------------------*/ #include + #include /*---------------------------------------------------------------------------*/ #include @@ -64,7 +65,7 @@ uart0_cb(UART_Handle handle, void *buf, size_t count) const uart0_input_cb currCb = g_input_cb; // Call the callback. Note this might reset g_input_cb currCb(g_char_buf); - // If the callback pointer didn't change after the call, do another read. + // If g_input_cb didn't change after the call, do another read. // Else, the uart0_set_callback was called with a different callback pointer // and triggered an another read. if (currCb == g_input_cb) { @@ -78,8 +79,6 @@ uart0_init(void) if (g_bIsInit) { return; } g_bIsInit = true; - UART_init(); - UART_Params params; UART_Params_init(¶ms); #ifdef SIMPLELINK_UART_CONF_BAUD_RATE @@ -118,8 +117,7 @@ uart0_set_callback(uart0_input_cb input_cb) g_input_cb = input_cb; if (input_cb) { return UART_read(gh_uart, &g_char_buf, 1); - } - else { + } else { UART_readCancel(gh_uart); return UART_STATUS_SUCCESS; } diff --git a/arch/cpu/cc13xx-cc26xx/dev/watchdog-arch.c b/arch/cpu/cc13xx-cc26xx/dev/watchdog-arch.c index ac137e577..f5eb3537d 100644 --- a/arch/cpu/cc13xx-cc26xx/dev/watchdog-arch.c +++ b/arch/cpu/cc13xx-cc26xx/dev/watchdog-arch.c @@ -42,12 +42,14 @@ * \file * Implementation of the CC13xx/CC26xx watchdog driver. */ -#include -#include - +/*---------------------------------------------------------------------------*/ #include "contiki.h" #include "dev/watchdog.h" +/*---------------------------------------------------------------------------*/ +#include +#include +/*---------------------------------------------------------------------------*/ #include #include /*---------------------------------------------------------------------------*/ @@ -56,49 +58,8 @@ #else #define CONTIKI_WATCHDOG_TIMER_TOP 0xFFFFF #endif - -#ifdef CONTIKI_WATCHDOG_CONF_LOCK_CONFIG -#define CONTIKI_WATCHDOG_LOCK_CONFIG CONTIKI_WATCHDOG_CONF_LOCK_CONFIG -#else -#define CONTIKI_WATCHDOG_LOCK_CONFIG 1 -#endif - -#define LOCK_INTERRUPTS_DISABLED 0x01 -#define LOCK_REGISTERS_UNLOCKED 0x02 /*---------------------------------------------------------------------------*/ -static uint32_t -unlock_config(void) -{ - uint32_t ret = 0; - bool int_status; - - if(CONTIKI_WATCHDOG_LOCK_CONFIG) { - int_status = IntMasterDisable(); - - if(WatchdogLockState()) { - ret |= LOCK_REGISTERS_UNLOCKED; - WatchdogUnlock(); - } - - ret |= (int_status) ? (0) : (LOCK_INTERRUPTS_DISABLED); - } - - return ret; -} -/*---------------------------------------------------------------------------*/ -static void -lock_config(uint32_t status) -{ - if(CONTIKI_WATCHDOG_LOCK_CONFIG) { - - if(status & LOCK_REGISTERS_UNLOCKED) { - WatchdogLock(); - } - if(status & LOCK_INTERRUPTS_DISABLED) { - IntMasterEnable(); - } - } -} +static Watchdog_Handle wd_handle; /*---------------------------------------------------------------------------*/ /** * \brief Initialises the CC26xx WDT @@ -109,8 +70,14 @@ lock_config(uint32_t status) void watchdog_init(void) { - WatchdogReloadSet(CONTIKI_WATCHDOG_TIMER_TOP); - lock_config(LOCK_REGISTERS_UNLOCKED); + Watchdog_init(); + + Watchdog_Params params; + Watchdog_Params_init(¶ms); + params.resetMode = Watchdog_RESET_ON; + params.debugStallMode = Watchdog_DEBUG_STALL_ON; + + wd_handle = Watchdog_open(Board_WATCHDOG0, ¶ms); } /*---------------------------------------------------------------------------*/ /** @@ -119,12 +86,7 @@ watchdog_init(void) void watchdog_start(void) { - uint32_t lock_status = unlock_config(); - watchdog_periodic(); - WatchdogResetEnable(); - - lock_config(lock_status); } /*---------------------------------------------------------------------------*/ /** @@ -133,8 +95,7 @@ watchdog_start(void) void watchdog_periodic(void) { - WatchdogReloadSet(CONTIKI_WATCHDOG_TIMER_TOP); - WatchdogIntClear(); + Watchdog_setReload(wd_handle, CONTIKI_WATCHDOG_TIMER_TOP); } /*---------------------------------------------------------------------------*/ /** @@ -143,11 +104,7 @@ watchdog_periodic(void) void watchdog_stop(void) { - uint32_t lock_status = unlock_config(); - - WatchdogResetDisable(); - - lock_config(lock_status); + Watchdog_clear(wd_handle); } /*---------------------------------------------------------------------------*/ /** diff --git a/arch/cpu/cc13xx-cc26xx/rf-settings/cc13x0/ieee-settings.c b/arch/cpu/cc13xx-cc26xx/rf-settings/cc13x0/ieee-settings.c index 0cd20bb45..b6f05f337 100644 --- a/arch/cpu/cc13xx-cc26xx/rf-settings/cc13x0/ieee-settings.c +++ b/arch/cpu/cc13xx-cc26xx/rf-settings/cc13x0/ieee-settings.c @@ -7,13 +7,14 @@ // Preamble (32 bit): 01010101... // TX Power: 5 dBm +#include "sys/cc.h" + #include #include DeviceFamily_constructPath(driverlib/rf_mailbox.h) #include DeviceFamily_constructPath(driverlib/rf_common_cmd.h) // This must be included "locally" frm the cpu directory, // as it isn't defined in CC13x0 driverlib #include "driverlib/rf_ieee_cmd.h" -#include "rf_patches/rf_patch_cpe_ieee.h" #include @@ -24,7 +25,7 @@ RF_Mode RF_ieeeMode = { .rfMode = RF_MODE_IEEE_15_4, - .cpePatchFxn = &rf_patch_cpe_ieee, + .cpePatchFxn = 0, .mcePatchFxn = 0, .rfePatchFxn = 0, }; @@ -54,8 +55,8 @@ RF_TxPowerTable_Entry ieeeTxPowerTable[14] = }; -// Overrides for CMD_RADIO_SETUP -uint32_t pIeeeOverrides[] = +// Overrides for CMD_RADIO_SETUP (CC2650) +uint32_t pIeeeOverrides[] CC_ALIGN(4) = { // override_synth_ieee_15_4.xml HW_REG_OVERRIDE(0x4038,0x0035), // Synth: Set recommended RTRIM to 5 @@ -83,19 +84,20 @@ uint32_t pIeeeOverrides[] = // Old override list -uint32_t ieee_overrides[] = { - (uint32_t)0x00354038, // Synth: Set RTRIM (POTAILRESTRIM) to 5 - (uint32_t)0x000784A3, // Synth: Set FREF = 3.43 MHz (24 MHz / 7) - (uint32_t)0xA47E0583, // Synth: Set loop bandwidth after lock to 80 kHz (K2) - (uint32_t)0xEAE00603, // Synth: Set loop bandwidth after lock to 80 kHz (K3, LSB) - (uint32_t)0x00010623, // Synth: Set loop bandwidth after lock to 80 kHz (K3, MSB) -// (uint32_t)0x1801F800, // Synth: Set ANADIV DIV_BIAS_MODE to PG1 (value) - (uint32_t)0x4001402D, // Synth: Correct CKVD latency setting (address) - (uint32_t)0x00608402, // Synth: Correct CKVD latency setting (value) -// (uint32_t)0x4001405D, // Synth: Set ANADIV DIV_BIAS_MODE to PG1 (address) - (uint32_t)0x002B50DC, // Adjust AGC DC filter - (uint32_t)0x05000243, // Increase synth programming timeout - (uint32_t)0x002082C3, // Increase synth programming timeout +uint32_t pIeeeOverridesOld[] CC_ALIGN(4) = +{ + (uint32_t)0x00354038, /* Synth: Set RTRIM (POTAILRESTRIM) to 5 */ + (uint32_t)0x4001402D, /* Synth: Correct CKVD latency setting (address) */ + (uint32_t)0x00608402, /* Synth: Correct CKVD latency setting (value) */ +// (uint32_t)0x4001405D, /* Synth: Set ANADIV DIV_BIAS_MODE to PG1 (address) */ +// (uint32_t)0x1801F800, /* Synth: Set ANADIV DIV_BIAS_MODE to PG1 (value) */ + (uint32_t)0x000784A3, /* Synth: Set FREF = 3.43 MHz (24 MHz / 7) */ + (uint32_t)0xA47E0583, /* Synth: Set loop bandwidth after lock to 80 kHz (K2) */ + (uint32_t)0xEAE00603, /* Synth: Set loop bandwidth after lock to 80 kHz (K3, LSB) */ + (uint32_t)0x00010623, /* Synth: Set loop bandwidth after lock to 80 kHz (K3, MSB) */ + (uint32_t)0x002B50DC, /* Adjust AGC DC filter */ + (uint32_t)0x05000243, /* Increase synth programming timeout */ + (uint32_t)0x002082C3, /* Increase synth programming timeout */ (uint32_t)0xFFFFFFFF, }; diff --git a/arch/cpu/cc13xx-cc26xx/rf-settings/cc13x0/ieee-settings.h b/arch/cpu/cc13xx-cc26xx/rf-settings/cc13x0/ieee-settings.h index 5d00932ff..01b773215 100644 --- a/arch/cpu/cc13xx-cc26xx/rf-settings/cc13x0/ieee-settings.h +++ b/arch/cpu/cc13xx-cc26xx/rf-settings/cc13x0/ieee-settings.h @@ -10,9 +10,10 @@ #include #include DeviceFamily_constructPath(driverlib/rf_mailbox.h) #include DeviceFamily_constructPath(driverlib/rf_common_cmd.h) -// This must be included "locally" frm the cpu directory, -// as it isn't defined in CC13x0 driverlib +// These two headers must be included "locally" frm the cpu directory, +// as they aren't defined in CC13x0 driverlib #include "driverlib/rf_ieee_cmd.h" +#include "driverlib/rf_ieee_mailbox.h" #include diff --git a/arch/cpu/cc13xx-cc26xx/rf-settings/cc13x0/prop-settings.c b/arch/cpu/cc13xx-cc26xx/rf-settings/cc13x0/prop-settings.c index 1f86d67ec..702295391 100644 --- a/arch/cpu/cc13xx-cc26xx/rf-settings/cc13x0/prop-settings.c +++ b/arch/cpu/cc13xx-cc26xx/rf-settings/cc13x0/prop-settings.c @@ -27,6 +27,8 @@ // TX Power: 14 dBm (requires define CCFG_FORCE_VDDR_HH = 1 in ccfg.c, see CC13xx/CC26xx Technical Reference Manual) // Whitening: Dynamically IEEE 802.15.4g compatible whitener and 16/32-bit CRC +#include "sys/cc.h" + #include #include DeviceFamily_constructPath(driverlib/rf_mailbox.h) #include DeviceFamily_constructPath(driverlib/rf_common_cmd.h) @@ -77,7 +79,7 @@ RF_TxPowerTable_Entry propTxPowerTable[16] = // Overrides for CMD_PROP_RADIO_DIV_SETUP -uint32_t pPropOverrides[] = +uint32_t pPropOverrides[] CC_ALIGN(4) = { // override_use_patch_prop_genfsk.xml MCE_RFE_OVERRIDE(0,4,0,1,0,0), // PHY: Use MCE ROM bank 4, RFE RAM patch diff --git a/arch/cpu/cc13xx-cc26xx/rf-settings/cc13x2/ieee-settings.c b/arch/cpu/cc13xx-cc26xx/rf-settings/cc13x2/ieee-settings.c index bedbbc792..efb1882da 100644 --- a/arch/cpu/cc13xx-cc26xx/rf-settings/cc13x2/ieee-settings.c +++ b/arch/cpu/cc13xx-cc26xx/rf-settings/cc13x2/ieee-settings.c @@ -20,6 +20,8 @@ // TX Power: 20 dBm (requires define CCFG_FORCE_VDDR_HH = 0 in ccfg.c, see CC13xx/CC26xx Technical Reference Manual) // Enable high output power PA: true +#include "sys/cc.h" + #include #include DeviceFamily_constructPath(driverlib/rf_mailbox.h) #include DeviceFamily_constructPath(driverlib/rf_common_cmd.h) @@ -95,7 +97,7 @@ RF_TxPowerTable_Entry ieeeHighPaTxPowerTable[16] = // Overrides for CMD_RADIO_SETUP -uint32_t pIeeeDefaultPaOverrides[] = +uint32_t pIeeeDefaultPaOverrides[] CC_ALIGN(4) = { // override_ieee_802_15_4.xml MCE_RFE_OVERRIDE(1,0,0,0,1,0), // PHY: Use MCE RAM patch, RFE ROM bank 1 @@ -117,7 +119,7 @@ uint32_t pIeeeDefaultPaOverrides[] = // Overrides for CMD_RADIO_SETUP -uint32_t pIeeeHighPaOverrides[] = +uint32_t pIeeeHighPaOverrides[] CC_ALIGN(4) = { // override_ieee_802_15_4.xml MCE_RFE_OVERRIDE(1,0,0,0,1,0), // PHY: Use MCE RAM patch, RFE ROM bank 1 @@ -167,7 +169,7 @@ rfc_CMD_RADIO_SETUP_t RF_cmdRadioSetup = // CMD_FS // Frequency Synthesizer Programming Command -rfc_CMD_FS_t RF_cmdFs = +rfc_CMD_FS_t RF_cmdIeeeFs = { .commandNo = 0x0803, .status = 0x0000, diff --git a/arch/cpu/cc13xx-cc26xx/rf-settings/cc13x2/ieee-settings.h b/arch/cpu/cc13xx-cc26xx/rf-settings/cc13x2/ieee-settings.h index ed9a7c7e0..8a37b35fe 100644 --- a/arch/cpu/cc13xx-cc26xx/rf-settings/cc13x2/ieee-settings.h +++ b/arch/cpu/cc13xx-cc26xx/rf-settings/cc13x2/ieee-settings.h @@ -11,6 +11,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(driverlib/rf_ieee_mailbox.h) #include @@ -26,7 +27,7 @@ extern RF_TxPowerTable_Entry ieeeHighPaTxPowerTable[16]; // RF Core API commands extern rfc_CMD_RADIO_SETUP_t RF_cmdRadioSetup; -extern rfc_CMD_FS_t RF_cmdFs; +extern rfc_CMD_FS_t RF_cmdIeeeFs; extern rfc_CMD_IEEE_TX_t RF_cmdIeeeTx; extern rfc_CMD_IEEE_RX_t RF_cmdIeeeRx; diff --git a/arch/cpu/cc13xx-cc26xx/rf-settings/cc13x2/prop-settings.c b/arch/cpu/cc13xx-cc26xx/rf-settings/cc13x2/prop-settings.c index e17b71954..f6928f04c 100644 --- a/arch/cpu/cc13xx-cc26xx/rf-settings/cc13x2/prop-settings.c +++ b/arch/cpu/cc13xx-cc26xx/rf-settings/cc13x2/prop-settings.c @@ -24,6 +24,8 @@ // Enable high output power PA: true // Whitening: Dynamically IEEE 802.15.4g compatible whitener and 16/32-bit CRC +#include "sys/cc.h" + #include #include DeviceFamily_constructPath(driverlib/rf_mailbox.h) #include DeviceFamily_constructPath(driverlib/rf_common_cmd.h) @@ -97,7 +99,7 @@ RF_TxPowerTable_Entry propHighPaTxPowerTable[8] = // Overrides for CMD_PROP_RADIO_DIV_SETUP -uint32_t pPropDefaultPaOverrides[] = +uint32_t pPropDefaultPaOverrides[] CC_ALIGN(4) = { // override_use_patch_prop_genfsk.xml MCE_RFE_OVERRIDE(1,0,0,1,0,0), // PHY: Use MCE RAM patch, RFE RAM patch @@ -135,7 +137,7 @@ uint32_t pPropDefaultPaOverrides[] = // Overrides for CMD_PROP_RADIO_DIV_SETUP -uint32_t pPropHighPaOverrides[] = +uint32_t pPropHighPaOverrides[] CC_ALIGN(4) = { // override_use_patch_prop_genfsk.xml MCE_RFE_OVERRIDE(1,0,0,1,0,0), // PHY: Use MCE RAM patch, RFE RAM patch @@ -213,7 +215,7 @@ rfc_CMD_PROP_RADIO_DIV_SETUP_t RF_cmdPropRadioDivSetup = // CMD_FS // Frequency Synthesizer Programming Command -rfc_CMD_FS_t RF_cmdFs = +rfc_CMD_FS_t RF_cmdPropFs = { .commandNo = 0x0803, .status = 0x0000, diff --git a/arch/cpu/cc13xx-cc26xx/rf-settings/cc13x2/prop-settings.h b/arch/cpu/cc13xx-cc26xx/rf-settings/cc13x2/prop-settings.h index 87cbfa562..a3f758abd 100644 --- a/arch/cpu/cc13xx-cc26xx/rf-settings/cc13x2/prop-settings.h +++ b/arch/cpu/cc13xx-cc26xx/rf-settings/cc13x2/prop-settings.h @@ -26,7 +26,7 @@ extern RF_TxPowerTable_Entry propHighPaTxPowerTable[8]; // RF Core API commands extern rfc_CMD_PROP_RADIO_DIV_SETUP_t RF_cmdPropRadioDivSetup; -extern rfc_CMD_FS_t RF_cmdFs; +extern rfc_CMD_FS_t RF_cmdPropFs; extern rfc_CMD_PROP_TX_ADV_t RF_cmdPropTxAdv; extern rfc_CMD_PROP_RX_ADV_t RF_cmdPropRxAdv; diff --git a/arch/cpu/cc13xx-cc26xx/rf-settings/cc26x0/ieee-settings.c b/arch/cpu/cc13xx-cc26xx/rf-settings/cc26x0/ieee-settings.c index 9ed0c5629..15527b039 100644 --- a/arch/cpu/cc13xx-cc26xx/rf-settings/cc26x0/ieee-settings.c +++ b/arch/cpu/cc13xx-cc26xx/rf-settings/cc26x0/ieee-settings.c @@ -7,6 +7,8 @@ // Preamble (32 bit): 01010101... // TX Power: 5 dBm +#include "sys/cc.h" + #include #include DeviceFamily_constructPath(driverlib/rf_mailbox.h) #include DeviceFamily_constructPath(driverlib/rf_common_cmd.h) @@ -53,7 +55,7 @@ RF_TxPowerTable_Entry ieeeTxPowerTable[14] = // Overrides for CMD_RADIO_SETUP -uint32_t pIeeeOverrides[] = +uint32_t pIeeeOverrides[] CC_ALIGN(4) = { // override_synth_ieee_15_4.xml HW_REG_OVERRIDE(0x4038,0x0035), // Synth: Set recommended RTRIM to 5 diff --git a/arch/cpu/cc13xx-cc26xx/rf-settings/cc26x0/ieee-settings.h b/arch/cpu/cc13xx-cc26xx/rf-settings/cc26x0/ieee-settings.h index 1a762a23a..5c6cb3d5a 100644 --- a/arch/cpu/cc13xx-cc26xx/rf-settings/cc26x0/ieee-settings.h +++ b/arch/cpu/cc13xx-cc26xx/rf-settings/cc26x0/ieee-settings.h @@ -11,6 +11,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(driverlib/rf_ieee_mailbox.h) #include diff --git a/arch/cpu/cc13xx-cc26xx/rf-settings/cc26x2/ieee-settings.c b/arch/cpu/cc13xx-cc26xx/rf-settings/cc26x2/ieee-settings.c index fba191773..20fbc6627 100644 --- a/arch/cpu/cc13xx-cc26xx/rf-settings/cc26x2/ieee-settings.c +++ b/arch/cpu/cc13xx-cc26xx/rf-settings/cc26x2/ieee-settings.c @@ -7,6 +7,8 @@ // Preamble (32 bit): 01010101... // TX Power: 5 dBm +#include "sys/cc.h" + #include #include DeviceFamily_constructPath(driverlib/rf_mailbox.h) #include DeviceFamily_constructPath(driverlib/rf_common_cmd.h) @@ -20,7 +22,7 @@ // TI-RTOS RF Mode Object -RF_Mode RF_propMode = +RF_Mode RF_ieeeMode = { .rfMode = RF_MODE_AUTO, .cpePatchFxn = &rf_patch_cpe_ieee_802_15_4, @@ -34,7 +36,7 @@ RF_Mode RF_propMode = // RF_TxPowerTable_DEFAULT_PA_ENTRY(bias, gain, boost coefficient) // See the Technical Reference Manual for further details about the "txPower" Command field. // The PA settings require the CCFG_FORCE_VDDR_HH = 0 unless stated otherwise. -RF_TxPowerTable_Entry txPowerTable[16] = +RF_TxPowerTable_Entry ieeeTxPowerTable[16] = { { -21, RF_TxPowerTable_DEFAULT_PA_ENTRY(7, 3, 0, 3) }, { -18, RF_TxPowerTable_DEFAULT_PA_ENTRY(9, 3, 0, 3) }, @@ -56,7 +58,7 @@ RF_TxPowerTable_Entry txPowerTable[16] = // Overrides for CMD_RADIO_SETUP -uint32_t pOverrides[] = +uint32_t pIeeeOverrides[] CC_ALIGN(4) = { // override_ieee_802_15_4.xml MCE_RFE_OVERRIDE(1,0,0,0,1,0), // PHY: Use MCE RAM patch, RFE ROM bank 1 @@ -98,12 +100,12 @@ rfc_CMD_RADIO_SETUP_t RF_cmdRadioSetup = .config.analogCfgMode = 0x0, .config.bNoFsPowerUp = 0x0, .txPower = 0x941E, - .pRegOverride = pOverrides, + .pRegOverride = pIeeeOverrides, }; // CMD_FS // Frequency Synthesizer Programming Command -rfc_CMD_FS_t RF_cmdFs = +rfc_CMD_FS_t RF_cmdIeeeFs = { .commandNo = 0x0803, .status = 0x0000, diff --git a/arch/cpu/cc13xx-cc26xx/rf-settings/cc26x2/ieee-settings.h b/arch/cpu/cc13xx-cc26xx/rf-settings/cc26x2/ieee-settings.h index a0cbb3abd..251bcb14c 100644 --- a/arch/cpu/cc13xx-cc26xx/rf-settings/cc26x2/ieee-settings.h +++ b/arch/cpu/cc13xx-cc26xx/rf-settings/cc26x2/ieee-settings.h @@ -10,28 +10,29 @@ #include #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(driverlib/rf_ieee_cmd.h +#include DeviceFamily_constructPath(driverlib/rf_ieee_mailbox.h)) #include // TI-RTOS RF Mode Object -extern RF_Mode RF_propMode; +extern RF_Mode RF_ieeeMode; // TX Power Table -extern RF_TxPowerTable_Entry txPowerTable[16]; +extern RF_TxPowerTable_Entry ieeeTxPowerTable[16]; // RF Core API commands extern rfc_CMD_RADIO_SETUP_t RF_cmdRadioSetup; -extern rfc_CMD_FS_t RF_cmdFs; +extern rfc_CMD_FS_t RF_cmdIeeeFs; extern rfc_CMD_IEEE_TX_t RF_cmdIeeeTx; extern rfc_CMD_IEEE_RX_t RF_cmdIeeeRx; // RF Core API Overrides -extern uint32_t pOverrides[]; +extern uint32_t pIeeeOverrides[]; #endif // _IEEE_SETTINGS_H_ diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1310/Board.h b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1310/Board.h index c73198659..66afbb6c6 100644 --- a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1310/Board.h +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1310/Board.h @@ -45,6 +45,20 @@ extern "C" { #define Board_shutDownExtFlash() CC1310_LAUNCHXL_shutDownExtFlash() #define Board_wakeUpExtFlash() CC1310_LAUNCHXL_wakeUpExtFlash() +/*---------------------------------------------------------------------------*/ +/** + * \name LED configurations + * + * Those values are not meant to be modified by the user + * @{ + */ +#define LEDS_RED (1 << 0) +#define LEDS_GREEN (1 << 1) +#define LEDS_YELLOW LEDS_GREEN +#define LEDS_ORANGE LEDS_RED + +#define LEDS_CONF_ALL (LEDS_RED | LEDS_GREEN) +/*---------------------------------------------------------------------------*/ /* These #defines allow us to reuse TI-RTOS across other device families */ #define Board_ADC0 CC1310_LAUNCHXL_ADC0 diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1312r1/Board.h b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1312r1/Board.h index d5db0c364..77179e057 100644 --- a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1312r1/Board.h +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1312r1/Board.h @@ -45,6 +45,20 @@ extern "C" { #define Board_shutDownExtFlash() CC1312R1_LAUNCHXL_shutDownExtFlash() #define Board_wakeUpExtFlash() CC1312R1_LAUNCHXL_wakeUpExtFlash() +/*---------------------------------------------------------------------------*/ +/** + * \name LED configurations + * + * Those values are not meant to be modified by the user + * @{ + */ +#define LEDS_RED (1 << 0) +#define LEDS_GREEN (1 << 1) +#define LEDS_YELLOW LEDS_GREEN +#define LEDS_ORANGE LEDS_RED + +#define LEDS_CONF_ALL (LEDS_RED | LEDS_GREEN) +/*---------------------------------------------------------------------------*/ /* These #defines allow us to reuse TI-RTOS across other device families */ #define Board_ADC0 CC1312R1_LAUNCHXL_ADC0 diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1312r1/Makefile.cc1312r1 b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1312r1/Makefile.cc1312r1 index 6feb804df..495dc498d 100644 --- a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1312r1/Makefile.cc1312r1 +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1312r1/Makefile.cc1312r1 @@ -7,6 +7,8 @@ DEVICE_LINE = CC13XX BOARD_SOURCEFILES += CC1312R1_LAUNCHXL.c CC1312R1_LAUNCHXL_fxns.c +DEFINES += PROP_MODE_CONF_TX_POWER_TABLE=propDefaultPaTxPowerTable + SUPPORTS_PROP_MODE = 1 SUPPORTS_IEEE_MODE = 0 diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1350-4/Board.h b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1350-4/Board.h index 394f3a3cd..3859a6d26 100644 --- a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1350-4/Board.h +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1350-4/Board.h @@ -45,6 +45,20 @@ extern "C" { #define Board_shutDownExtFlash() CC1350_LAUNCHXL_433_shutDownExtFlash() #define Board_wakeUpExtFlash() CC1350_LAUNCHXL_433_wakeUpExtFlash() +/*---------------------------------------------------------------------------*/ +/** + * \name LED configurations + * + * Those values are not meant to be modified by the user + * @{ + */ +#define LEDS_RED (1 << 0) +#define LEDS_GREEN (1 << 1) +#define LEDS_YELLOW LEDS_GREEN +#define LEDS_ORANGE LEDS_RED + +#define LEDS_CONF_ALL (LEDS_RED | LEDS_GREEN) +/*---------------------------------------------------------------------------*/ /* These #defines allow us to reuse TI-RTOS across other device families */ #define Board_ADC0 CC1350_LAUNCHXL_433_ADC0 diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1350/Board.h b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1350/Board.h index a67b34ddb..0e8542d00 100644 --- a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1350/Board.h +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1350/Board.h @@ -45,6 +45,20 @@ extern "C" { #define Board_shutDownExtFlash() CC1350_LAUNCHXL_shutDownExtFlash() #define Board_wakeUpExtFlash() CC1350_LAUNCHXL_wakeUpExtFlash() +/*---------------------------------------------------------------------------*/ +/** + * \name LED configurations + * + * Those values are not meant to be modified by the user + * @{ + */ +#define LEDS_RED (1 << 0) +#define LEDS_GREEN (1 << 1) +#define LEDS_YELLOW LEDS_GREEN +#define LEDS_ORANGE LEDS_RED + +#define LEDS_CONF_ALL (LEDS_RED | LEDS_GREEN) +/*---------------------------------------------------------------------------*/ /* These #defines allow us to reuse TI-RTOS across other device families */ #define Board_ADC0 CC1350_LAUNCHXL_ADC0 #define Board_ADC1 CC1350_LAUNCHXL_ADC1 diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1350/CC1350_LAUNCHXL.c b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1350/CC1350_LAUNCHXL.c index 92ce04a9d..2a4f4dee7 100644 --- a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1350/CC1350_LAUNCHXL.c +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1350/CC1350_LAUNCHXL.c @@ -53,7 +53,7 @@ #include #include -ADCBufCC26XX_Object adcBufCC26XXobjects[CC1350_LAUNCHXL_ADCBUFCOUNT]; +static ADCBufCC26XX_Object adcBufCC26XXobjects[CC1350_LAUNCHXL_ADCBUFCOUNT]; /* * This table converts a virtual adc channel into a dio and internal analogue @@ -90,6 +90,7 @@ const ADCBuf_Config ADCBuf_config[CC1350_LAUNCHXL_ADCBUFCOUNT] = { { &ADCBufCC26XX_fxnTable, &adcBufCC26XXobjects[CC1350_LAUNCHXL_ADCBUF0], + //NULL, &adcBufCC26XXHWAttrs[CC1350_LAUNCHXL_ADCBUF0] }, }; @@ -102,7 +103,7 @@ const uint_least8_t ADCBuf_count = CC1350_LAUNCHXL_ADCBUFCOUNT; #include #include -ADCCC26XX_Object adcCC26xxObjects[CC1350_LAUNCHXL_ADCCOUNT]; +static ADCCC26XX_Object adcCC26xxObjects[CC1350_LAUNCHXL_ADCCOUNT]; const ADCCC26XX_HWAttrs adcCC26xxHWAttrs[CC1350_LAUNCHXL_ADCCOUNT] = { { diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p1/Board.h b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p1/Board.h index c078fe636..a74df419a 100644 --- a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p1/Board.h +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p1/Board.h @@ -45,6 +45,20 @@ extern "C" { #define Board_shutDownExtFlash() CC1352P1_LAUNCHXL_shutDownExtFlash() #define Board_wakeUpExtFlash() CC1352P1_LAUNCHXL_wakeUpExtFlash() +/*---------------------------------------------------------------------------*/ +/** + * \name LED configurations + * + * Those values are not meant to be modified by the user + * @{ + */ +#define LEDS_RED (1 << 0) +#define LEDS_GREEN (1 << 1) +#define LEDS_YELLOW LEDS_GREEN +#define LEDS_ORANGE LEDS_RED + +#define LEDS_CONF_ALL (LEDS_RED | LEDS_GREEN) +/*---------------------------------------------------------------------------*/ /* These #defines allow us to reuse TI-RTOS across other device families */ #define Board_ADC0 CC1352P1_LAUNCHXL_ADC0 diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p1/Makefile.cc1352p1 b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p1/Makefile.cc1352p1 index d24e181a4..accb29899 100644 --- a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p1/Makefile.cc1352p1 +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p1/Makefile.cc1352p1 @@ -7,6 +7,9 @@ DEVICE_LINE = CC13XX BOARD_SOURCEFILES += CC1352P1_LAUNCHXL.c CC1312P1_LAUNCHXL_fxns.c +DEFINES += PROP_MODE_CONF_TX_POWER_TABLE=propDefaultPaTxPowerTable +DEFINES += IEEE_MODE_CONF_TX_POWER_TABLE=ieeeDefaultPaTxPowerTable + SUPPORTS_PROP_MODE = 1 SUPPORTS_IEEE_MODE = 1 diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p_2/Board.h b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p_2/Board.h index 7fe300916..e251723cd 100644 --- a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p_2/Board.h +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p_2/Board.h @@ -45,6 +45,20 @@ extern "C" { #define Board_shutDownExtFlash() CC1352P_2_LAUNCHXL_shutDownExtFlash() #define Board_wakeUpExtFlash() CC1352P_2_LAUNCHXL_wakeUpExtFlash() +/*---------------------------------------------------------------------------*/ +/** + * \name LED configurations + * + * Those values are not meant to be modified by the user + * @{ + */ +#define LEDS_RED (1 << 0) +#define LEDS_GREEN (1 << 1) +#define LEDS_YELLOW LEDS_GREEN +#define LEDS_ORANGE LEDS_RED + +#define LEDS_CONF_ALL (LEDS_RED | LEDS_GREEN) +/*---------------------------------------------------------------------------*/ /* These #defines allow us to reuse TI-RTOS across other device families */ #define Board_ADC0 CC1352P_2_LAUNCHXL_ADC0 diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p_2/Makefile.cc1352p_2 b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p_2/Makefile.cc1352p_2 index 3e7db941d..4c9558719 100644 --- a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p_2/Makefile.cc1352p_2 +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p_2/Makefile.cc1352p_2 @@ -7,6 +7,9 @@ DEVICE_LINE = CC13XX BOARD_SOURCEFILES += CC1352P_2_LAUNCHXL.c CC1352P_2_LAUNCHXL_fxns.c +DEFINES += PROP_MODE_CONF_TX_POWER_TABLE=propDefaultPaTxPowerTable +DEFINES += IEEE_MODE_CONF_TX_POWER_TABLE=ieeeDefaultPaTxPowerTable + SUPPORTS_PROP_MODE = 1 SUPPORTS_IEEE_MODE = 1 diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p_4/Board.h b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p_4/Board.h index 752f8d88f..f36390cea 100644 --- a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p_4/Board.h +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p_4/Board.h @@ -45,6 +45,20 @@ extern "C" { #define Board_shutDownExtFlash() CC1352P_4_LAUNCHXL_shutDownExtFlash() #define Board_wakeUpExtFlash() CC1352P_4_LAUNCHXL_wakeUpExtFlash() +/*---------------------------------------------------------------------------*/ +/** + * \name LED configurations + * + * Those values are not meant to be modified by the user + * @{ + */ +#define LEDS_RED (1 << 0) +#define LEDS_GREEN (1 << 1) +#define LEDS_YELLOW LEDS_GREEN +#define LEDS_ORANGE LEDS_RED + +#define LEDS_CONF_ALL (LEDS_RED | LEDS_GREEN) +/*---------------------------------------------------------------------------*/ /* These #defines allow us to reuse TI-RTOS across other device families */ #define Board_ADC0 CC1352P_4_LAUNCHXL_ADC0 diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p_4/Makefile.cc1352p_4 b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p_4/Makefile.cc1352p_4 index df7cb99a6..a9365a51a 100644 --- a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p_4/Makefile.cc1352p_4 +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352p_4/Makefile.cc1352p_4 @@ -7,6 +7,9 @@ DEVICE_LINE = CC13XX BOARD_SOURCEFILES += CC1352P_4_LAUNCHXL.c CC1352P_4_LAUNCHXL_fxns.c +DEFINES += PROP_MODE_CONF_TX_POWER_TABLE=propDefaultPaTxPowerTable +DEFINES += IEEE_MODE_CONF_TX_POWER_TABLE=ieeeDefaultPaTxPowerTable + SUPPORTS_PROP_MODE = 1 SUPPORTS_IEEE_MODE = 1 diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352r1/Board.h b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352r1/Board.h index 9cc52d689..2c46e0b7c 100644 --- a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352r1/Board.h +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352r1/Board.h @@ -45,6 +45,20 @@ extern "C" { #define Board_shutDownExtFlash() CC1352R1_LAUNCHXL_shutDownExtFlash() #define Board_wakeUpExtFlash() CC1352R1_LAUNCHXL_wakeUpExtFlash() +/*---------------------------------------------------------------------------*/ +/** + * \name LED configurations + * + * Those values are not meant to be modified by the user + * @{ + */ +#define LEDS_RED (1 << 0) +#define LEDS_GREEN (1 << 1) +#define LEDS_YELLOW LEDS_GREEN +#define LEDS_ORANGE LEDS_RED + +#define LEDS_CONF_ALL (LEDS_RED | LEDS_GREEN) +/*---------------------------------------------------------------------------*/ /* These #defines allow us to reuse TI-RTOS across other device families */ #define Board_ADC0 CC1352R1_LAUNCHXL_ADC0 diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352r1/Makefile.cc1352r1 b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352r1/Makefile.cc1352r1 index 272482360..8214b275e 100644 --- a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352r1/Makefile.cc1352r1 +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc1352r1/Makefile.cc1352r1 @@ -7,6 +7,9 @@ DEVICE_LINE = CC13XX BOARD_SOURCEFILES += CC1352R1_LAUNCHXL.c CC1352R1_LAUNCHXL_fxns.c +DEFINES += PROP_MODE_CONF_TX_POWER_TABLE=propDefaultPaTxPowerTable +DEFINES += IEEE_MODE_CONF_TX_POWER_TABLE=ieeeDefaultPaTxPowerTable + SUPPORTS_PROP_MODE = 1 SUPPORTS_IEEE_MODE = 1 diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc2650/Board.h b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc2650/Board.h index 72f5cb42d..07668d60f 100644 --- a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc2650/Board.h +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc2650/Board.h @@ -45,6 +45,20 @@ extern "C" { #define Board_shutDownExtFlash() CC2650_LAUNCHXL_shutDownExtFlash() #define Board_wakeUpExtFlash() CC2650_LAUNCHXL_wakeUpExtFlash() +/*---------------------------------------------------------------------------*/ +/** + * \name LED configurations + * + * Those values are not meant to be modified by the user + * @{ + */ +#define LEDS_RED (1 << 0) +#define LEDS_GREEN (1 << 1) +#define LEDS_YELLOW LEDS_GREEN +#define LEDS_ORANGE LEDS_RED + +#define LEDS_CONF_ALL (LEDS_RED | LEDS_GREEN) +/*---------------------------------------------------------------------------*/ /* These #defines allow us to reuse TI-RTOS across other device families */ #define Board_ADC0 CC2650_LAUNCHXL_ADC0 #define Board_ADC1 CC2650_LAUNCHXL_ADC1 diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc26x2r1/Board.h b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc26x2r1/Board.h index 8940527b9..c984f711b 100644 --- a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc26x2r1/Board.h +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/cc26x2r1/Board.h @@ -47,6 +47,20 @@ extern "C" { #define Board_wakeUpExtFlash() CC26X2R1_LAUNCHXL_wakeUpExtFlash() +/*---------------------------------------------------------------------------*/ +/** + * \name LED configurations + * + * Those values are not meant to be modified by the user + * @{ + */ +#define LEDS_RED (1 << 0) +#define LEDS_GREEN (1 << 1) +#define LEDS_YELLOW LEDS_GREEN +#define LEDS_ORANGE LEDS_RED + +#define LEDS_CONF_ALL (LEDS_RED | LEDS_GREEN) +/*---------------------------------------------------------------------------*/ /* These #defines allow us to reuse TI-RTOS across other device families */ #define Board_ADC0 CC26X2R1_LAUNCHXL_ADC0 diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/ext-flash.c b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/ext-flash.c index b985da95a..a78a5e764 100644 --- a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/ext-flash.c +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/ext-flash.c @@ -37,7 +37,7 @@ */ /*---------------------------------------------------------------------------*/ #include -#include +#include #include /*---------------------------------------------------------------------------*/ #include "contiki.h" @@ -48,7 +48,17 @@ #include #include /*---------------------------------------------------------------------------*/ -static SPI_Handle spiHandle = NULL; +static PIN_Config pin_table[] = { + Board_SPI_FLASH_CS | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | PIN_DRVSTR_MIN, + PIN_TERMINATE +}; + +static PIN_State pin_state; +static PIN_Handle pin_handle; + +static SPI_Handle spi_handle; + +static bool ext_flash_opened; /*---------------------------------------------------------------------------*/ #define SPI_BIT_RATE 4000000 @@ -115,7 +125,7 @@ spi_write(const uint8_t *buf, size_t len) spiTransaction.txBuf = (void *)buf; spiTransaction.rxBuf = NULL; - return SPI_transfer(spiHandle, &spiTransaction); + return SPI_transfer(spi_handle, &spiTransaction); } /*---------------------------------------------------------------------------*/ static bool @@ -126,19 +136,19 @@ spi_read(uint8_t *buf, size_t len) spiTransaction.txBuf = NULL; spiTransaction.rxBuf = buf; - return SPI_transfer(spiHandle, &spiTransaction); + return SPI_transfer(spi_handle, &spiTransaction); } /*---------------------------------------------------------------------------*/ static void select(void) { - ti_lib_gpio_clear_dio(Board_SPI_FLASH_CS); + PIN_setOutputValue(pin_handle, Board_SPI_FLASH_CS, 1); } /*---------------------------------------------------------------------------*/ static void deselect(void) { - ti_lib_gpio_set_dio(Board_SPI_FLASH_CS); + PIN_setOutputValue(pin_handle, Board_SPI_FLASH_CS, 0); } /*---------------------------------------------------------------------------*/ static bool @@ -258,7 +268,13 @@ verify_part(void) bool ext_flash_open() { - if (spiHandle != NULL) { + if (ext_flash_opened) { + return true; + } + + pin_handle = PIN_open(&pin_state, pin_table); + + if (pin_handle == NULL) { return false; } @@ -268,13 +284,15 @@ ext_flash_open() spiParams.mode = SPI_MASTER; spiParams.transferMode = SPI_MODE_BLOCKING; - spiHandle = SPI_open(Board_SPI0, &spiParams); + spi_handle = SPI_open(Board_SPI0, &spiParams); - if (spiHandle == NULL) { + if (spi_handle == NULL) { + PIN_close(pin_handle); return false; } - ti_lib_ioc_pin_type_gpio_output(Board_SPI_FLASH_CS); + ext_flash_opened = true; + deselect(); const bool is_powered = power_standby(); @@ -289,18 +307,21 @@ ext_flash_open() void ext_flash_close() { - if (spiHandle == NULL) { + if (!ext_flash_opened) { return; } + ext_flash_opened = false; power_down(); - SPI_close(spiHandle); + + SPI_close(spi_handle); + PIN_close(pin_handle); } /*---------------------------------------------------------------------------*/ bool ext_flash_read(size_t offset, size_t length, uint8_t *buf) { - if (spiHandle == NULL || buf == NULL) { + if (spi_handle == NULL || buf == NULL) { return false; } @@ -333,7 +354,7 @@ ext_flash_read(size_t offset, size_t length, uint8_t *buf) bool ext_flash_write(size_t offset, size_t length, const uint8_t *buf) { - if (spiHandle == NULL || buf == NULL) { + if (spi_handle == NULL || buf == NULL) { return false; } @@ -441,7 +462,6 @@ ext_flash_test(void) void ext_flash_init() { - GPIO_init(); SPI_init(); } /*---------------------------------------------------------------------------*/ diff --git a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/leds-arch.c b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/leds-arch.c index 7595d47d3..463349854 100644 --- a/arch/platform/simplelink/cc13xx-cc26xx/launchpad/leds-arch.c +++ b/arch/platform/simplelink/cc13xx-cc26xx/launchpad/leds-arch.c @@ -42,35 +42,23 @@ /*---------------------------------------------------------------------------*/ /* Simplelink SDK API */ #include -#include + +#include /*---------------------------------------------------------------------------*/ /* Standard library */ #include #include /*---------------------------------------------------------------------------*/ -/* Available LED configuration */ +static const PIN_Config pin_table[] = { + Board_PIN_LED0 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, + Board_PIN_LED1 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, + PIN_TERMINATE +}; -/* Green LED */ -#ifdef Board_GPIO_GLED -# define LEDS_ARCH_GREEN Board_GPIO_GLED -#endif +static PIN_State pin_state; +static PIN_Handle pin_handle; -/* Yellow LED */ -#ifdef Board_GPIO_YLED -# define LEDS_ARCH_YELLOW Board_GPIO_YLED -#endif - -/* Red LED */ -#ifdef Board_GPIO_RLED -# define LEDS_ARCH_RED Board_GPIO_RLED -#endif - -/* Blue LED */ -#ifdef Board_GPIO_BLED -# define LEDS_ARCH_BLUE Board_GPIO_BLED -#endif -/*---------------------------------------------------------------------------*/ -static unsigned char c; +static volatile unsigned char c; /*---------------------------------------------------------------------------*/ void leds_arch_init(void) @@ -79,12 +67,14 @@ leds_arch_init(void) if(bHasInit) { return; } - bHasInit = true; - // GPIO_init will most likely be called in platform.c, - // but call it here to be sure GPIO is initialized. - // Calling GPIO_init multiple times is safe. - GPIO_init(); + // PIN_init() called from Board_initGeneral() + pin_handle = PIN_open(&pin_state, pin_table); + if (!pin_handle) { + return; + } + + bHasInit = true; } /*---------------------------------------------------------------------------*/ unsigned char @@ -93,42 +83,20 @@ leds_arch_get(void) return c; } /*---------------------------------------------------------------------------*/ -static inline void -write_led(const bool on, const uint_fast32_t gpioLed) -{ - const GPIO_PinConfig pinCfg = (on) - ? Board_GPIO_LED_ON : Board_GPIO_LED_OFF; - GPIO_write(gpioLed, pinCfg); -} -/*---------------------------------------------------------------------------*/ void leds_arch_set(unsigned char leds) { c = leds; -#define LED_ON(led_define) ((leds & (led_define)) == (led_define)) + PIN_setPortOutputValue(pin_handle, 0); - // Green LED -#ifdef LEDS_ARCH_GREEN - write_led(LED_ON(LEDS_GREEN), LEDS_ARCH_GREEN); -#endif + if (leds & LEDS_RED) { + PIN_setOutputValue(pin_handle, Board_PIN_LED0, 1); + } - // Yellow LED -#ifdef LEDS_ARCH_YELLOW - write_led(LED_ON(LEDS_YELLOW), LEDS_ARCH_YELLOW); -#endif - - // Red LED -#ifdef LEDS_ARCH_RED - write_led(LED_ON(LEDS_RED), LEDS_ARCH_RED); -#endif - - // Blue LED -#ifdef LEDS_ARCH_BLUE - write_led(LED_ON(LEDS_BLUE), LEDS_ARCH_BLUE); -#endif - -#undef LED_ON + if (leds & LEDS_GREEN) { + PIN_setOutputValue(pin_handle, Board_PIN_LED1, 1); + } } /*---------------------------------------------------------------------------*/ /** @} */ diff --git a/arch/platform/simplelink/cc13xx-cc26xx/platform.c b/arch/platform/simplelink/cc13xx-cc26xx/platform.c index ab29bce0d..e196efc9a 100644 --- a/arch/platform/simplelink/cc13xx-cc26xx/platform.c +++ b/arch/platform/simplelink/cc13xx-cc26xx/platform.c @@ -49,16 +49,20 @@ /* Simplelink SDK includes */ #include #include + #include #include DeviceFamily_constructPath(driverlib/driverlib_release.h) #include DeviceFamily_constructPath(driverlib/chipinfo.h) #include DeviceFamily_constructPath(driverlib/vims.h) -#include DeviceFamily_constructPath(driverlib/interrupt.h) +#include DeviceFamily_constructPath(inc/hw_cpu_scs.h) + +#include #include #include #include #include #include +#include /*---------------------------------------------------------------------------*/ /* Contiki API */ #include "contiki.h" @@ -114,17 +118,15 @@ fade(unsigned char l) static void set_rf_params(void) { - uint16_t short_addr; uint8_t ext_addr[8]; ieee_addr_cpy_to(ext_addr, sizeof(ext_addr)); - short_addr = ext_addr[7]; - short_addr |= ext_addr[6] << 8; + uint16_t short_addr = (ext_addr[7] << 0) + | (ext_addr[6] << 8); NETSTACK_RADIO.set_value(RADIO_PARAM_PAN_ID, IEEE802154_PANID); NETSTACK_RADIO.set_value(RADIO_PARAM_16BIT_ADDR, short_addr); - NETSTACK_RADIO.set_value(RADIO_PARAM_CHANNEL, RF_CORE_CHANNEL); NETSTACK_RADIO.set_object(RADIO_PARAM_64BIT_ADDR, ext_addr, sizeof(ext_addr)); /* also set the global node id */ @@ -134,29 +136,34 @@ set_rf_params(void) void platform_init_stage_one(void) { + DRIVERLIB_ASSERT_CURR_RELEASE(); + + // TODO: TEMPORARY WHILE DEVELOP. REMOVE + HWREG(CPU_SCS_BASE + CPU_SCS_O_ACTLR) = CPU_SCS_ACTLR_DISDEFWBUF; + // Enable flash cache VIMSModeSet(VIMS_BASE, VIMS_MODE_ENABLED); // Configure round robin arbitration and prefetching VIMSConfigure(VIMS_BASE, true, true); - // NoRTOS_start only enables HWI - NoRTOS_start(); - // Board_initGeneral() will call Power_init() // Board_initGeneral() will call PIN_init(BoardGpioInitTable) Board_initGeneral(); - Board_shutDownExtFlash(); // Contiki drivers init leds_init(); fade(LEDS_RED); - GPIO_init(); + // TI Drivers init I2C_init(); SPI_init(); + UART_init(); fade(LEDS_GREEN); + + // NoRTOS should be called last + NoRTOS_start(); } /*---------------------------------------------------------------------------*/ void @@ -172,7 +179,7 @@ platform_init_stage_two(void) uart0_set_callback(serial_line_input_byte); #endif - // random_init(0x1234); + random_init(0x1234); /* Populate linkaddr_node_addr */ ieee_addr_cpy_to(linkaddr_node_addr.u8, LINKADDR_SIZE); @@ -183,7 +190,7 @@ platform_init_stage_two(void) void platform_init_stage_three(void) { - radio_value_t chan, pan; + radio_value_t chan = 0, pan = 0; set_rf_params(); @@ -192,15 +199,15 @@ platform_init_stage_three(void) LOG_DBG("With DriverLib v%u.%u\n", DRIVERLIB_RELEASE_GROUP, DRIVERLIB_RELEASE_BUILD); - LOG_DBG("IEEE 802.15.4: %s, Sub-GHz: %s, BLE: %s, Prop: %s\n", + LOG_DBG("IEEE 802.15.4: %s, Sub-GHz: %s, BLE: %s\n", ChipInfo_SupportsIEEE_802_15_4() ? "Yes" : "No", - ChipInfo_ChipFamilyIs_CC13x0() ? "Yes" : "No", - ChipInfo_SupportsBLE() ? "Yes" : "No", - ChipInfo_SupportsPROPRIETARY() ? "Yes" : "No"); + ChipInfo_SupportsPROPRIETARY() ? "Yes" : "No", + ChipInfo_SupportsBLE() ? "Yes" : "No"); LOG_INFO("RF: Channel %d, PANID 0x%04X\n", chan, pan); LOG_INFO("Node ID: %d\n", g_nodeId); process_start(&sensors_process, NULL); + fade(LEDS_GREEN); } /*---------------------------------------------------------------------------*/ diff --git a/arch/platform/simplelink/cc13xx-cc26xx/sensortag/sensortag.c b/arch/platform/simplelink/cc13xx-cc26xx/sensortag/sensortag.c index 7f1e3b816..c3043f20e 100644 --- a/arch/platform/simplelink/cc13xx-cc26xx/sensortag/sensortag.c +++ b/arch/platform/simplelink/cc13xx-cc26xx/sensortag/sensortag.c @@ -51,14 +51,6 @@ void board_init(void) { - // Board_initGeneral() will call Power_init() - // Board_initGeneral() will call PIN_init(BoardGpioInitTable) - Board_initGeneral(); - Board_shutDownExtFlash(); - - GPIO_init(); - I2C_init(); - SPI_init(); } /*---------------------------------------------------------------------------*/ /** @} */