Added async read on UART

This commit is contained in:
Edvard Pettersen 2018-02-08 10:35:08 +01:00
parent c99c3b4b5f
commit b30ef7d56d
4 changed files with 53 additions and 27 deletions

View File

@ -394,10 +394,6 @@ ifndef LD
LD = $(CC)
endif
### Make sure Makefiles with the $(TARGET) suffix doesn't match
Makefile.$(TARGET):
@
ifndef CUSTOM_RULE_LINK
%.$(TARGET): %.o $(PROJECT_OBJECTFILES) $(PROJECT_LIBRARIES) $(CONTIKI_NG_TARGET_LIB)
$(TRACE_LD)
@ -493,8 +489,6 @@ endif
# in fact the primary target.
.PRECIOUS: %.$(TARGET)
# Cancel the predefined implict rule for compiling and linking
# a single C source into a binary to force GNU make to consider
# the match-anything rule below instead.

View File

@ -41,7 +41,26 @@
#include <stdint.h>
static UART_Handle hUart;
#include "simplelink-uart.h"
static UART_Handle gh_uart;
static volatile InputCb g_input_cb;
static unsigned char g_charbuf;
/*---------------------------------------------------------------------------*/
static void
uart_cb(UART_Handle handle, void *buf, size_t count)
{
if (!g_input_cb) { return; }
const InputCb currCb = g_input_cb;
currCb(g_charbuf);
if (currCb == g_input_cb)
{
UART_read(gh_uart, &g_charbuf, 1);
}
}
/*---------------------------------------------------------------------------*/
void
simplelink_uart_init(void)
@ -50,10 +69,13 @@ simplelink_uart_init(void)
UART_Params params;
UART_Params_init(&params);
params.readMode = UART_MODE_CALLBACK;
params.writeMode = UART_MODE_BLOCKING ;
params.readCallback = uart_cb;
// TODO configure
hUart = UART_open(Board_UART0, &params);
if (!hUart)
gh_uart = UART_open(Board_UART0, &params);
if (!gh_uart)
{
for (;;) { /* hang */ }
}
@ -62,21 +84,27 @@ simplelink_uart_init(void)
int_fast32_t
simplelink_uart_write(const void *buffer, size_t size)
{
if (!hUart)
if (!gh_uart)
{
return UART_STATUS_ERROR;
}
return UART_write(hUart, buffer, size);
return UART_write(gh_uart, buffer, size);
}
/*---------------------------------------------------------------------------*/
int_fast32_t
simplelink_uart_read(void *buffer, size_t size)
void
simplelink_uart_set_callback(InputCb input_cb)
{
if (!hUart)
if (g_input_cb == input_cb) { return; }
g_input_cb = input_cb;
if (input_cb)
{
return UART_STATUS_ERROR;
UART_read(gh_uart, &g_charbuf, 1);
}
else
{
UART_readCancel(gh_uart);
}
return UART_read(hUart, buffer, size);
}
/*---------------------------------------------------------------------------*/
/** @} */

View File

@ -44,6 +44,8 @@
#include <stdint.h>
typedef void (*InputCb)(unsigned char);
/*---------------------------------------------------------------------------*/
/** \name UART functions
* @{
@ -70,7 +72,7 @@ int_fast32_t simplelink_uart_write(const void *buffer, size_t size);
* \return Number of bytes that has been written to the buffer. If an
* error occurs, a negative value is returned.
*/
int_fast32_t simplelink_uart_read(void *buffer, size_t size);
void simplelink_uart_set_callback(InputCb input_cb);
/** @} */
/*---------------------------------------------------------------------------*/

View File

@ -48,6 +48,8 @@
#include <Board.h>
#include <ti/drivers/GPIO.h>
#include <ti/drivers/Power.h>
#include <driverlib/driverlib_release.h>
#include <driverlib/chipinfo.h>
#include <NoRTOS.h>
#include "contiki.h"
@ -192,16 +194,16 @@ platform_init_stage_three()
// NETSTACK_RADIO.get_value(RADIO_PARAM_CHANNEL, &chan);
// NETSTACK_RADIO.get_value(RADIO_PARAM_PAN_ID, &pan);
//
// LOG_DBG("With DriverLib v%u.%u\n", DRIVERLIB_RELEASE_GROUP,
// DRIVERLIB_RELEASE_BUILD);
// LOG_INFO(BOARD_STRING "\n");
// LOG_DBG("IEEE 802.15.4: %s, Sub-GHz: %s, BLE: %s, Prop: %s\n",
// ti_lib_chipinfo_supports_ieee_802_15_4() == true ? "Yes" : "No",
// ti_lib_chipinfo_chip_family_is_cc13xx() == true ? "Yes" : "No",
// ti_lib_chipinfo_supports_ble() == true ? "Yes" : "No",
// ti_lib_chipinfo_supports_proprietary() == true ? "Yes" : "No");
// LOG_INFO(" RF: Channel %d, PANID 0x%04X\n", chan, pan);
// LOG_INFO(" Node ID: %d\n", node_id);
LOG_DBG("With DriverLib v%u.%u\n", DRIVERLIB_RELEASE_GROUP,
DRIVERLIB_RELEASE_BUILD);
//LOG_INFO(BOARD_STRING "\n");
LOG_DBG("IEEE 802.15.4: %s, Sub-GHz: %s, BLE: %s, Prop: %s\n",
ChipInfo_SupportsIEEE_802_15_4() ? "Yes" : "No",
ChipInfo_ChipFamilyIs_CC13x0() ? "Yes" : "No",
ChipInfo_SupportsBLE() ? "Yes" : "No",
ChipInfo_SupportsPROPRIETARY() ? "Yes" : "No");
//LOG_INFO(" RF: Channel %d, PANID 0x%04X\n", chan, pan);
//LOG_INFO(" Node ID: %d\n", node_id);
//
// process_start(&sensors_process, NULL);
fade(Board_GPIO_LED1);