Skip to content

Commit

Permalink
Several fixes with lastest CC13x2_26x2 SDK (#1695)
Browse files Browse the repository at this point in the history
  • Loading branch information
josesimoes authored Sep 4, 2020
1 parent 3f9df7d commit 1fa469b
Show file tree
Hide file tree
Showing 8 changed files with 123 additions and 105 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
const CCFG = scripting.addModule("/ti/devices/CCFG");
const DMA = scripting.addModule("/ti/drivers/DMA");
const RTOS = scripting.addModule("/ti/drivers/RTOS");
const UART = scripting.addModule("/ti/drivers/UART", {}, false);
const UART1 = UART.addInstance();
const UART2 = scripting.addModule("/ti/drivers/UART2", {}, false);
const UART21 = UART2.addInstance();
const easylink = scripting.addModule("/ti/easylink/easylink");

/**
Expand All @@ -21,11 +21,11 @@ const easylink = scripting.addModule("/ti/easylink/easylink");
CCFG.forceVddr = true;
CCFG.ccfgTemplate.$name = "ti_devices_CCFGTemplate0";

UART1.$hardware = system.deviceData.board.components.XDS110UART;
UART1.$name = "UART0";
UART1.txPinInstance.$name = "CONFIG_PIN_0";
UART1.rxPinInstance.$name = "CONFIG_PIN_1";
UART1.uart.$assign = "UART0";
UART21.$hardware = system.deviceData.board.components.XDS110UART;
UART21.$name = "UART0";
UART21.txPinInstance.$name = "CONFIG_PIN_2";
UART21.rxPinInstance.$name = "CONFIG_PIN_3";
UART21.uart.$assign = "UART0";

easylink.EasyLink_Phy_5kbpsSlLr = true;
easylink.defaultPhy = "EasyLink_Phy_5kbpsSlLr";
Expand All @@ -42,5 +42,5 @@ easylink.radioConfigEasylinkPhy200kbps2gfsk.codeExportConfig.$name = "ti_devices
* version of the tool will not impact the pinmux you originally saw. These lines can be completely deleted in order to
* re-solve from scratch.
*/
UART1.uart.txPin.$suggestSolution = "boosterpack.4";
UART1.uart.rxPin.$suggestSolution = "boosterpack.3";
UART21.uart.txPin.$suggestSolution = "boosterpack.4";
UART21.uart.rxPin.$suggestSolution = "boosterpack.3";
3 changes: 1 addition & 2 deletions targets/TI-SimpleLink/TI_CC1352R1_LAUNCHXL/nanoCLR/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ int main(void)
Task_Params taskParams;

// Call board init functions
Board_initGeneral();
Board_init();

// setup Task thread
Task_Params_init(&taskParams);
Expand Down Expand Up @@ -83,7 +83,6 @@ int main(void)
}

GPIO_init();
UART_init();
ConfigUART();

BIOS_start();
Expand Down
4 changes: 2 additions & 2 deletions targets/TI-SimpleLink/TI_CC1352R1_LAUNCHXL/target_common.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@

/////////////////////////////////////
#if defined(DEBUG)
#define MANAGED_HEAP_SIZE (35*1024)
#define MANAGED_HEAP_SIZE (30*1024)
#else
#define MANAGED_HEAP_SIZE (42*1024)
#define MANAGED_HEAP_SIZE (37*1024)
#endif
/////////////////////////////////////

Expand Down
27 changes: 16 additions & 11 deletions targets/TI-SimpleLink/common/GenericPort.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@

#include <nanoCLR_Types.h>
#include <nanoCLR_Runtime.h>
#include <ti/drivers/UART.h>
#include <ti/drivers/UART2.h>
#include <ti/drivers/dpl/SemaphoreP.h>
#include <ti/sysbios/knl/Clock.h>

extern UART_Handle uart;
// UART operations timeout
#define UART_TIMEOUT_MILLISECONDS 500000

extern UART2_Handle uart;
extern SemaphoreP_Handle uartMutex;

// developer note:
Expand All @@ -19,15 +23,15 @@ extern "C" uint32_t DebuggerPort_WriteProxy(const char *format, ...)
va_list arg;
uint32_t chars = 0;

if( CLR_EE_DBG_IS_NOT( Enabled ) )
if (CLR_EE_DBG_IS_NOT(Enabled))
{
if(SemaphoreP_pend(uartMutex, UART_WAIT_FOREVER) == SemaphoreP_OK)
if (SemaphoreP_pend(uartMutex, UART2_WAIT_FOREVER) == SemaphoreP_OK)
{
va_start( arg, format );
va_start(arg, format);

chars = CLR_Debug::PrintfV( format, arg );
chars = CLR_Debug::PrintfV(format, arg);

va_end( arg );
va_end(arg);

SemaphoreP_post(uartMutex);
}
Expand All @@ -36,17 +40,18 @@ extern "C" uint32_t DebuggerPort_WriteProxy(const char *format, ...)
return chars;
}

uint32_t GenericPort_Write( int portNum, const char* data, size_t size )
uint32_t GenericPort_Write(int portNum, const char *data, size_t size)
{
(void)portNum;
size_t bytesWritten;

if( CLR_EE_DBG_IS_NOT( Enabled ) )
if (CLR_EE_DBG_IS_NOT(Enabled))
{
// debugger port is NOT in use, OK to output to UART
// send characters directly to the UART port
UART_write(uart, data, size);
UART2_writeTimeout(uart, data, size, &bytesWritten, UART_TIMEOUT_MILLISECONDS / Clock_tickPeriod);

return size;
return bytesWritten;
}

return (uint32_t)size;
Expand Down
62 changes: 41 additions & 21 deletions targets/TI-SimpleLink/common/WireProtocol_HAL_Interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,48 +4,53 @@
//

// #include <FreeRTOS.h>
#include <ti/drivers/UART.h>
#include <ti/drivers/UART2.h>
#include <ti/sysbios/knl/Clock.h>
#include <board.h>
#include <nanoHAL_v2.h>
#include <WireProtocol.h>
#include <WireProtocol_Message.h>
#include <WireProtocol_HAL_interface.h>

UART_Handle uart = NULL;
// UART operations timeout
#define UART_TIMEOUT_MILLISECONDS 500000

UART2_Handle uart = NULL;

WP_Message inboundMessage;

////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////
// The functions below are the ones that need to be ported to new channels/HALs when required
// These are to be considered as a reference implementations when working on new ports
//
//
// This reference implementation provides communication through:
// - serial port (UART/USART)
// - serial port (UART/USART)
//
////////////////////////////////////////////////////////////////////////////////////////////////

int WP_ReceiveBytes(uint8_t* ptr, uint16_t* size)
int WP_ReceiveBytes(uint8_t *ptr, uint16_t *size)
{
// save for latter comparison
uint16_t requestedSize = *size;
size_t read;

//int readData = 0;
// int readData = 0;
// sanity check for request of 0 size
if(*size)
if (*size)
{
//////////////////////////////////////////////////////////
// PORTING CHANGE REQUIRED HERE //
//////////////////////////////////////////////////////////
// change here to read (size) bytes from the input stream
// preferably with read timeout and being able to check
// preferably with read timeout and being able to check
// if the requested number of bytes was actually read
//////////////////////////////////////////////////////////

// non blocking read from serial port with 500ms timeout
size_t read = UART_read(uart, ptr, requestedSize);
UART2_readTimeout(uart, ptr, requestedSize, &read, UART_TIMEOUT_MILLISECONDS / Clock_tickPeriod);

ptr += read;
ptr += read;
*size -= read;

// check if the requested read matches the actual read count
Expand All @@ -55,7 +60,7 @@ int WP_ReceiveBytes(uint8_t* ptr, uint16_t* size)
return true;
}

int WP_TransmitMessage(WP_Message* message)
int WP_TransmitMessage(WP_Message *message)
{
uint32_t writeResult;
bool operationResult = false;
Expand All @@ -64,21 +69,31 @@ int WP_TransmitMessage(WP_Message* message)
// PORTING CHANGE REQUIRED HERE //
///////////////////////////////////////////////////////////
// change here to write (size) bytes to the output stream
// preferably with timeout and being able to check
// preferably with timeout and being able to check
// if the write was successfull or at least buffered
//////////////////////////////////////////////////////////

TRACE( TRACE_HEADERS, "TXMSG: 0x%08X, 0x%08X, 0x%08X\n", message->m_header.m_cmd, message->m_header.m_flags, message->m_header.m_size );
TRACE(
TRACE_HEADERS,
"TXMSG: 0x%08X, 0x%08X, 0x%08X\n",
message->m_header.m_cmd,
message->m_header.m_flags,
message->m_header.m_size);

// write header to uart
writeResult = UART_write(uart, (const void *)&message->m_header, sizeof(message->m_header));

if(writeResult == sizeof(message->m_header))
UART2_writeTimeout(
uart,
(const void *)&message->m_header,
sizeof(message->m_header),
&writeResult,
UART_TIMEOUT_MILLISECONDS / Clock_tickPeriod);

if (writeResult == sizeof(message->m_header))
{
operationResult = true;

// if there is anything on the payload send it to the output stream
if(message->m_header.m_size && message->m_payload)
if (message->m_header.m_size && message->m_payload)
{
///////////////////////////////////////////////////////////
// PORTING CHANGE REQUIRED HERE //
Expand All @@ -89,13 +104,18 @@ int WP_TransmitMessage(WP_Message* message)
// reset flag
operationResult = false;

writeResult = UART_write(uart, (const void *)message->m_payload, message->m_header.m_size);
UART2_writeTimeout(
uart,
(const void *)message->m_payload,
message->m_header.m_size,
&writeResult,
UART_TIMEOUT_MILLISECONDS / Clock_tickPeriod);

if(writeResult == message->m_header.m_size)
if (writeResult == message->m_header.m_size)
{
operationResult = true;

TRACE0( TRACE_ERRORS, "TXMSG: OK\n");
TRACE0(TRACE_ERRORS, "TXMSG: OK\n");
}
}
}
Expand Down
22 changes: 8 additions & 14 deletions targets/TI-SimpleLink/nanoCLR/targetPAL.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
// See LICENSE file in the project root for full license information.
//

#include <ti/drivers/UART.h>
#include <ti/drivers/UART2.h>
#include <board.h>
#include <ti/drivers/dpl/SemaphoreP.h>
#include <ti/sysbios/knl/Clock.h>

#include <ti_drivers_config.h>

extern UART_Handle uart;
extern UART2_Handle uart;

SemaphoreP_Handle uartMutex;

Expand All @@ -21,9 +20,6 @@ SemaphoreP_Handle uartMutex;

void dummyFunction(void) __attribute__((used));

// UART operations timeout
#define UART_TIMEOUT_MILLISECONDS 500000

// Never called.
void dummyFunction(void)
{
Expand All @@ -34,19 +30,17 @@ void dummyFunction(void)
// configure UART
void ConfigUART()
{
UART_Params uartParams;
UART2_Params uartParams;

// Create a UART with data processing off
UART_Params_init(&uartParams);
UART2_Params_init(&uartParams);

uartParams.writeDataMode = UART_DATA_BINARY;
uartParams.readDataMode = UART_DATA_BINARY;
uartParams.readEcho = UART_ECHO_OFF;
uartParams.writeMode = UART2_Mode_BLOCKING;
uartParams.readMode = UART2_Mode_BLOCKING;
uartParams.baudRate = 921600;
uartParams.readTimeout = UART_TIMEOUT_MILLISECONDS / Clock_tickPeriod;
uartParams.writeTimeout = UART_TIMEOUT_MILLISECONDS / Clock_tickPeriod;
uartParams.readReturnMode = UART2_ReadReturnMode_FULL;

uart = UART_open(UART0, &uartParams);
uart = UART2_open(UART0, &uartParams);

if (uart == NULL)
{
Expand Down
Loading

0 comments on commit 1fa469b

Please sign in to comment.