Implemented the Contiki leds driver

NB! This is by no means a future-proof implementation. However, it
should be a good starting point. Configuration of the LEDS_ARCH_*
defines in the leds-arch.c file is what determines what LEDs are
available of a given device/target. This information should be
sufficient from the Board file/device name, and can from there
hardcod what board+device combination a given LED should support.
This commit is contained in:
Edvard Pettersen 2018-02-15 15:39:18 +01:00
parent 723e59264c
commit 6007b1be07
3 changed files with 200 additions and 23 deletions

View File

@ -8,22 +8,65 @@ ifndef SIMPLELINK_SDK
$(error SIMPLELINK_SDK not defined! You must specify where the SimpleLink SDK resides!)
endif
AVAILABLE_BOARDS := $(shell ls $(SIMPLELINK_SDK)/source/ti/boards/)
AVAILABLE_BOARDS += CUSTOM # Allows an own board file in the application project
# Hacky way to emulate line breaks in warnings/errors
# https://stackoverflow.com/questions/17055773/how-to-synthesize-line-breaks-in-gnu-make-warnings-or-errors
define n
endef
# List of all Simplelink SDKs the Contiki Simplelink platform supports
# with the format "simplelink_<device>_sdk". Don't add the version.
# Simply adding a new entry with the name of a new SDK should be enough when
# the necessary implementaitons have been made.
SUPPORTED_SDKS = \
simplelink_cc13x0_sdk \
simplelink_cc13x2_sdk \
simplelink_cc26x0_sdk \
simplelink_cc26x2_sdk \
simplelink_cc2640r2_sdk \
# The Simplelink SDK name extracted from the file path.
# e.g. C:/ti/simplelink_cc13x0_sdk_1_60_00_21 => simplelink_cc13x0_sdk_1_60_00_21
SDK_NAME := $(notdir $(SIMPLELINK_SDK))
# The stripped name from the Simplelink SDK, i.e. without version number.
# e.g. simplelink_cc13x0_sdk_1_60_00_21 => simplelink_cc13x0_sdk
# Note that the first grep verifies the SDK name is on a valid format,
# and the second grep extracts the stripped name
SDK_NAME_STRIPPED := $(shell echo "$(SDK_NAME)" \
| grep -Po "simplelink_.*?_sdk_[0-9_]+" \
| grep -Po "simplelink_.*?_sdk")
# Verify a valid Simplelink SDK has been supplied.
# Format is "simplelink_<device>_sdk_<version>"
ifeq (,$(SDK_NAME_STRIPPED))
$(error Supplied Simplelink SDK '$(SDK_NAME)' is not valid.$nFormat is "simplelink_<device>_sdk_<version>")
endif
# Verify a supported Simplelink SDK has been supplied, else print all supported SDKs
ifeq (,$(findstring $(SDK_NAME_STRIPPED), $(SUPPORTED_SDKS)))
$(error Simplelink SDK '$(SDK_NAME)' is not supported.$nSupported SDKs:$n $(foreach sdk, $(SUPPORTED_SDKS), $(sdk)_<version>$n))
endif
# Find all available boards from the '<sdk>/source/ti/boards directory'
AVAILABLE_BOARDS := $(shell ls -d $(SIMPLELINK_SDK)/source/ti/boards/*)
# Also allow a custom board file in the application project
AVAILABLE_BOARDS += CUSTOM
ifndef SIMPLELINK_BOARD
$(error SIMPLELINK_BOARD not defined! You must specify a board! Available boards: $(AVAILABLE_BOARDS))
$(error SIMPLELINK_BOARD not defined. You must specify a board!$nAvailable boards:$n $(foreach board, $(AVAILABLE_BOARDS), $(board)$n))
endif
ifneq ($(findstring $(SIMPLELINK_BOARD),$(AVAILABLE_BOARDS)),$(SIMPLELINK_BOARD))
$(error '$(SIMPLELINK_BOARD)' is not a valid board. Available boards: $(AVAILABLE_BOARDS))
$(error Board '$(SIMPLELINK_BOARD)' is not valid for the given Simplelink SDK '$(SDK_NAME)'.$nAvailable boards:$n $(foreach board, $(AVAILABLE_BOARDS), $(board)$n))
endif
### Board and BSP selection
CONTIKI_TARGET_DIRS += .
CONTIKI_TARGET_DIRS += . common
CONTIKI_TARGET_SOURCEFILES += platform.c
CONTIKI_TARGET_SOURCEFILES += leds-arch.c
CONTIKI_SOURCEFILES += $(CONTIKI_TARGET_SOURCEFILES)
@ -35,7 +78,7 @@ SMALL ?= 0
CONTIKI_CPU = $(CONTIKI)/arch/cpu/simplelink
include $(CONTIKI_CPU)/Makefile.simplelink
#MODULES += os/net os/net/mac os/net/mac/framer
MODULES += os/net os/net/mac os/net/mac/framer

View File

@ -0,0 +1,134 @@
/*
* 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 simplelink-platform
* @{
*
* \file
* Driver for LaunchPad LEDs
*/
/*---------------------------------------------------------------------------*/
/* Contiki API */
#include <contiki.h>
#include <dev/leds.h>
/*---------------------------------------------------------------------------*/
/* Simplelink SDK API */
#include <Board.h>
#include <ti/drivers/GPIO.h>
/*---------------------------------------------------------------------------*/
/* Standard library */
#include <stdbool.h>
#include <stdint.h>
/*---------------------------------------------------------------------------*/
/* Available LED configuration */
/* Green LED */
#ifdef Board_GPIO_GLED
# define LEDS_ARCH_GREEN Board_GPIO_GLED
#endif
/* 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;
/*---------------------------------------------------------------------------*/
void
leds_arch_init(void)
{
static bool bHasInit = false;
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();
}
/*---------------------------------------------------------------------------*/
unsigned char
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))
// Green LED
#ifdef LEDS_ARCH_GREEN
write_led(LED_ON(LEDS_GREEN), LEDS_ARCH_GREEN);
#endif
// 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
}
/*---------------------------------------------------------------------------*/
/** @} */

View File

@ -52,6 +52,8 @@
#include <ti/drivers/Power.h>
#include <driverlib/driverlib_release.h>
#include <driverlib/chipinfo.h>
#include <driverlib/vims.h>
#include <driverlib/interrupt.h>
#include <NoRTOS.h>
/*---------------------------------------------------------------------------*/
/* Contiki API */
@ -62,12 +64,12 @@
#include "sys/node-id.h"
#include "sys/platform.h"
#include "dev/serial-line.h"
#include "dev/leds.h"
#include "net/mac/framer/frame802154.h"
/*---------------------------------------------------------------------------*/
/* Arch driver implementations */
#include "uart0-arch.h"
/*---------------------------------------------------------------------------*/
#include "leds.h"
//#include "gpio-interrupt.h"
#include "ieee-addr.h"
#include "dev/rf-common.h"
@ -94,11 +96,11 @@ fade(unsigned char l)
for(int k = 0; k < 800; ++k) {
int j = k > 400 ? 800 - k : k;
GPIO_write(l, Board_GPIO_LED_ON);
leds_on(l);
for(i = 0; i < j; ++i) {
__asm("nop");
}
GPIO_write(l, Board_GPIO_LED_OFF);
leds_off(l);
for(i = 0; i < 400 - j; ++i) {
__asm("nop");
}
@ -128,16 +130,19 @@ set_rf_params(void)
void
platform_init_stage_one()
{
// Enable flash cache
VIMSModeSet(VIMS_BASE, VIMS_MODE_ENABLED);
// Configure round robin arbitration and prefetching
VIMSConfigure(VIMS_BASE, true, true);
Board_initGeneral();
GPIO_init();
// Only enables interrupts
// NoRTOS_start only enables HWI
NoRTOS_start();
// /* Enable flash cache and prefetch. */
// ti_lib_vims_mode_set(VIMS_BASE, VIMS_MODE_ENABLED);
// ti_lib_vims_configure(VIMS_BASE, true, true);
//
leds_init();
// ti_lib_int_master_disable();
//
// /* Set the LF XOSC as the LF system clock source */
@ -145,12 +150,7 @@ platform_init_stage_one()
//
// lpm_init();
//
// board_init();
//
// gpio_interrupt_init();
//
// leds_init();
fade(Board_GPIO_LED0);
fade(LEDS_RED);
//
// /*
// * Disable I/O pad sleep mode and open I/O latches in the AON IOC interface
@ -163,7 +163,7 @@ platform_init_stage_one()
// ti_lib_int_master_enable();
//
// soc_rtc_init();
fade(Board_GPIO_LED1);
fade(LEDS_GREEN);
}
/*---------------------------------------------------------------------------*/
void
@ -177,7 +177,7 @@ platform_init_stage_two()
/* Populate linkaddr_node_addr */
ieee_addr_cpy_to(linkaddr_node_addr.u8, LINKADDR_SIZE);
fade(Board_GPIO_LED0);
fade(LEDS_RED);
}
/*---------------------------------------------------------------------------*/
void
@ -202,7 +202,7 @@ platform_init_stage_three()
LOG_INFO(" Node ID: %d\n", g_nodeId);
//
// process_start(&sensors_process, NULL);
fade(Board_GPIO_LED1);
fade(LEDS_GREEN);
}
/*---------------------------------------------------------------------------*/
void