Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework UART for TI SimpleLink #1323

Merged
merged 1 commit into from
May 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion targets/TI-SimpleLink/common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ list(APPEND TARGET_TI_SimpleLink_COMMON_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/pla

list(APPEND TARGET_TI_SimpleLink_COMMON_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/FreeRTOS-openocd.c")

# list(APPEND TARGET_TI_SimpleLink_COMMON_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/GenericPort.cpp")
list(APPEND TARGET_TI_SimpleLink_COMMON_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/GenericPort.cpp")
list(APPEND TARGET_TI_SimpleLink_COMMON_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/syscalls.c")
list(APPEND TARGET_TI_SimpleLink_COMMON_SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/nanoSupport_CRC32.c")

Expand Down
31 changes: 17 additions & 14 deletions targets/TI-SimpleLink/common/GenericPort.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,30 @@
// See LICENSE file in the project root for full license information.
//

#include "nanoCLR_Types.h"
#include "nanoCLR_Runtime.h"
#include <nanoCLR_Types.h>
#include <nanoCLR_Runtime.h>
#include <ti/drivers/UART.h>

extern UART_Handle uart;

uint32_t GenericPort_Write( int portNum, const char* data, size_t size )
{
(void)portNum;
if (g_CLR_RT_ExecutionEngine.m_iDebugger_Conditions == CLR_RT_ExecutionEngine::c_fDebugger_StateProgramRunning)
{
char* p = (char*)data;
int counter = 0;

// send characters directly to the trace port
while(*p != '\0' || counter < (int)size)
{
// ets_printf( "%c", *p++);
counter++;
}
return counter;
// developer note:
// Outputing to board UART can be done only if there is no debugger attached, because it uses the same UART.

if( (g_CLR_RT_ExecutionEngine.m_iDebugger_Conditions & CLR_RT_ExecutionEngine::c_fDebugger_Enabled) == CLR_RT_ExecutionEngine::c_fDebugger_Enabled)
{
// debugger port is in use, don't output to UART
}
else
{
return (uint32_t)size;
// send characters directly to the UART port
UART_write(uart, data, size);

return size;
}

return (uint32_t)size;
}
41 changes: 2 additions & 39 deletions targets/TI-SimpleLink/common/WireProtocol_HAL_Interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
#include <WireProtocol_Message.h>
#include <WireProtocol_HAL_interface.h>

WP_Message inboundMessage;
UART_Handle uart = NULL;

bool WP_Initialise(COM_HANDLE port);
WP_Message inboundMessage;

////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////
Expand All @@ -25,40 +25,8 @@ bool WP_Initialise(COM_HANDLE port);
//
////////////////////////////////////////////////////////////////////////////////////////////////

UART_Handle uart = NULL;
UART_Params uartParams;

bool WP_Initialise(COM_HANDLE port)
{
(void)port;

// Create a UART with data processing off
UART_Params_init(&uartParams);
uartParams.readTimeout = 500;
uartParams.writeDataMode = UART_DATA_BINARY;
uartParams.readDataMode = UART_DATA_BINARY;
uartParams.readReturnMode = UART_RETURN_FULL;
uartParams.readEcho = UART_ECHO_OFF;
uartParams.baudRate = 115200;

uart = UART_open(Board_UART0, &uartParams);

if (uart == NULL)
{
// UART_open() failed
while (1);
}

return true;
}

int WP_ReceiveBytes(uint8_t* ptr, uint16_t* size)
{
if(uart == NULL)
{
WP_Initialise(NULL);
}

// save for latter comparison
uint16_t requestedSize = *size;

Expand Down Expand Up @@ -92,11 +60,6 @@ int WP_TransmitMessage(WP_Message* message)
uint32_t writeResult;
bool operationResult = false;

if(uart == NULL)
{
WP_Initialise(NULL);
}

///////////////////////////////////////////////////////////
// PORTING CHANGE REQUIRED HERE //
///////////////////////////////////////////////////////////
Expand Down
28 changes: 28 additions & 0 deletions targets/TI-SimpleLink/nanoCLR/targetPAL.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
// See LICENSE file in the project root for full license information.
//

#include <ti/drivers/UART.h>
#include <board.h>

extern UART_Handle uart;

// Need to have calls to these two functions in C code.
// Because they are called only on asm code, GCC linker with LTO option thinks they are not used and just removes them.
// Having them called from a dummy function that is never called it a workaround for this.
Expand All @@ -15,3 +20,26 @@ void dummyFunction(void) {
vTaskSwitchContext();
localProgramStart();
}

// configure UART
void ConfigUART()
{
UART_Params uartParams;

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

uartParams.writeDataMode = UART_DATA_BINARY;
uartParams.readDataMode = UART_DATA_BINARY;
uartParams.readReturnMode = UART_RETURN_FULL;
uartParams.readEcho = UART_ECHO_OFF;
uartParams.baudRate = 115200;

uart = UART_open(Board_UART0, &uartParams);

if (uart == NULL)
{
// UART_open() failed
while (1);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ extern void * CLRStartupThread(void *arg0);
extern void * ReceiverThread(void *arg0);
extern void sntp_init(void);

// other externals
extern void ConfigUART();

//////////////////////////////
#define SL_STOP_TIMEOUT (200)

Expand Down Expand Up @@ -625,6 +628,9 @@ void * mainThread(void *arg)
ADC_init();
PWM_init();

// initialize UART (need UART to be functional ASAP in order to output to terminal, if required)
ConfigUART();

// Initialize SlNetSock layer
SlNetIf_init(0);
SlNetIf_add(SLNETIF_ID_1, "nF",
Expand Down Expand Up @@ -790,7 +796,7 @@ void * mainThread(void *arg)
pthread_attr_init(&threadAttributes);
priorityParams.sched_priority = NF_TASK_PRIORITY;
retc = pthread_attr_setschedparam(&threadAttributes, &priorityParams);
retc |= pthread_attr_setstacksize(&threadAttributes, 4092);
retc |= pthread_attr_setstacksize(&threadAttributes, 5116);
if (retc != 0)
{
// failed to set attributes
Expand Down