Initial commit of firmware
This commit is contained in:
286
Libs/platform/service/iostream/inc/sl_iostream.h
Normal file
286
Libs/platform/service/iostream/inc/sl_iostream.h
Normal file
@@ -0,0 +1,286 @@
|
||||
/***************************************************************************//**
|
||||
* @file
|
||||
* @brief IO Stream.
|
||||
*******************************************************************************
|
||||
* # License
|
||||
* <b>Copyright 2019 Silicon Laboratories Inc. www.silabs.com</b>
|
||||
*******************************************************************************
|
||||
*
|
||||
* SPDX-License-Identifier: Zlib
|
||||
*
|
||||
* The licensor of this software is Silicon Laboratories Inc.
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef SL_IOSTREAM_H
|
||||
#define SL_IOSTREAM_H
|
||||
|
||||
#if defined(SL_COMPONENT_CATALOG_PRESENT)
|
||||
#include "sl_component_catalog.h"
|
||||
#endif
|
||||
#include "sl_enum.h"
|
||||
#include "sl_status.h"
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/***************************************************************************//**
|
||||
* @addtogroup iostream I/O Stream
|
||||
* @brief I/O Stream can be used to read/write different formats of data to various streams.
|
||||
* The source files for I/O Stream platform software module are present under platform/services/iostream.
|
||||
* @details
|
||||
* ## Overview
|
||||
*
|
||||
* I/O Stream is a platform module software that provides Input/Output functionalities
|
||||
* by creating streams. Streams are abstractions allowing a uniform way to read/write
|
||||
* data regardless of the physical communication interface.
|
||||
*
|
||||
* I/O Stream offers many interfaces, see submodules for a list of all types available
|
||||
* and their specificities.You can load multiple streams in the project and you can
|
||||
* select the interface that must be used at runtime.Some interface type can also
|
||||
* be instantiated, meaning that you can have multiple instances of an interface
|
||||
* type which will be normally bound to a hardware peripheral.
|
||||
*
|
||||
* ## Initialization
|
||||
*
|
||||
* The I/O Stream core doesn't require any initialization. Instead each stream type has
|
||||
* their own initialization and their own configuration. See I/O Stream specific type
|
||||
* to know more about how to initialize a stream.
|
||||
*
|
||||
* Note that most stream will set itself as the default stream during their initialization.
|
||||
* Thus the initial default stream will be the last stream initialized.
|
||||
*
|
||||
* ## Default system-wide stream
|
||||
*
|
||||
* Multiple streams can be initialized in your application and you can configure a default
|
||||
* stream that must be used when no stream is specified. Also note that the default stream
|
||||
* will be used when calling printf and you can change the default stream at runtime.
|
||||
* The following defines should be used for the default stream:
|
||||
*
|
||||
* SL_IOSTREAM_STDIN
|
||||
* SL_IOSTREAM_STDOUT
|
||||
* SL_IOSTREAM_STDERR
|
||||
*
|
||||
* ## RTOS - Task's default stream
|
||||
*
|
||||
* In the case of an RTOS environment, each task can set its own stream. By default, the task
|
||||
* stream will be set to the system_wide default stream. From your task, you can change the
|
||||
* default stream assigned to your task without affecting the other tasks' stream.
|
||||
*
|
||||
* ## Printf
|
||||
*
|
||||
* I/O Stream provides third-party printf integrations. It can work with toolchain implementation
|
||||
* or with the tiny printf implementation for embedded system. The printf API doesn't have an
|
||||
* argument for specifying the stream to be used, so I/O Stream provides a printf API that takes
|
||||
* a stream as an argument and calls the configured third-party implementation of printf.
|
||||
*
|
||||
* @{
|
||||
******************************************************************************/
|
||||
|
||||
/// @cond DO_NOT_INCLUDE_WITH_DOXYGEN
|
||||
#define SL_IOSTREAM_STDIN 0 ///< Default input stream
|
||||
#define SL_IOSTREAM_STDOUT 0 ///< Default output stream
|
||||
#define SL_IOSTREAM_STDERR 0 ///< Default error stream
|
||||
/// @endcond
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Data Types
|
||||
|
||||
/// @brief Struct representing iostream operations.
|
||||
typedef struct {
|
||||
void *context; ///< context
|
||||
sl_status_t (*write)(void *context, const void *buffer, size_t buffer_length); ///< write
|
||||
sl_status_t (*read)(void *context, void *buffer, size_t buffer_length, size_t *bytes_read); ///< read
|
||||
} sl_iostream_t;
|
||||
|
||||
/// @brief Enumeration representing the possible types of iostream instances.
|
||||
SL_ENUM(sl_iostream_type_t){
|
||||
SL_IOSTREAM_TYPE_SWO = 0, ///< SWO Instance
|
||||
SL_IOSTREAM_TYPE_RTT = 1, ///< RTT Instance
|
||||
SL_IOSTREAM_TYPE_UART = 2, ///< USART Instance
|
||||
SL_IOSTREAM_TYPE_VUART = 3, ///< Vuart
|
||||
SL_IOSTREAM_TYPE_DEBUG_OUTPUT = 4, ///< Backchannel output Instance Type
|
||||
SL_IOSTREAM_TYPE_LOOPBACK = 5, ///< Loopback Instance
|
||||
SL_IOSTREAM_TYPE_UNDEFINED = 6, ///< Undefined Instance Type
|
||||
};
|
||||
|
||||
/// @brief Struct representing an I/O Stream instance.
|
||||
typedef struct {
|
||||
sl_iostream_t *handle; ///< iostream instance handle.
|
||||
char *name; ///< iostream instance name.
|
||||
sl_iostream_type_t type; ///< iostream instance type.
|
||||
uint8_t periph_id; ///< iostream peripheral id.
|
||||
sl_status_t (*init)(void); ///< iostream instance init function.
|
||||
} sl_iostream_instance_info_t;
|
||||
|
||||
/// @cond DO_NOT_INCLUDE_WITH_DOXYGEN
|
||||
// Special stream to be used when you want to avoid printing anything
|
||||
extern sl_iostream_t sl_iostream_null;
|
||||
/// @endcond
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Prototypes
|
||||
|
||||
/***************************************************************************//**
|
||||
* Set the stream as default I/O Stream.
|
||||
*
|
||||
* @param[in] stream I/O Stream to set as default.
|
||||
*
|
||||
* @return Status result
|
||||
******************************************************************************/
|
||||
sl_status_t sl_iostream_set_default(sl_iostream_t *stream);
|
||||
|
||||
/***************************************************************************//**
|
||||
* Get the default I/O Stream configured.
|
||||
*
|
||||
* @return Status result
|
||||
******************************************************************************/
|
||||
sl_iostream_t *sl_iostream_get_default(void);
|
||||
|
||||
/***************************************************************************//**
|
||||
* Configure the systemwide default stream.
|
||||
*
|
||||
* @param[in] stream I/O Stream to be used.
|
||||
*
|
||||
* @return Status result
|
||||
******************************************************************************/
|
||||
#if defined(SL_CATALOG_KERNEL_PRESENT) && !defined(SL_IOSTREAM_FORCE_BAREMETAL)
|
||||
sl_status_t sl_iostream_set_system_default(sl_iostream_t *stream);
|
||||
#else
|
||||
#define sl_iostream_set_system_default sl_iostream_set_default
|
||||
#endif
|
||||
|
||||
/***************************************************************************//**
|
||||
* Output data on a stream.
|
||||
*
|
||||
* @param[in] stream I/O Stream to be used.
|
||||
* SL_IOSTREAM_STDOUT; Default output stream will be used.
|
||||
* Pointer to specific stream; Specific stream will be used.
|
||||
*
|
||||
* @param[in] buffer Buffer that contains the data to output.
|
||||
*
|
||||
* @param[in] buffer_length Data length contained in the buffer.
|
||||
*
|
||||
* @return Status result
|
||||
******************************************************************************/
|
||||
sl_status_t sl_iostream_write(sl_iostream_t *stream,
|
||||
const void *buffer,
|
||||
size_t buffer_length);
|
||||
|
||||
/***************************************************************************//**
|
||||
* Get data from a stream.
|
||||
*
|
||||
* @param[in] stream I/O Stream to be used.
|
||||
* SL_IOSTREAM_STDOUT; Default output stream will be used.
|
||||
* Pointer to specific stream; Specific stream will be used.
|
||||
*
|
||||
* @param[out] buffer Buffer that contains the data to output.
|
||||
*
|
||||
* @param[in] buffer_length Data length contained in the buffer.
|
||||
*
|
||||
* @param[out] bytes_read Data length copied to the buffer.
|
||||
*
|
||||
* @return Status result
|
||||
******************************************************************************/
|
||||
sl_status_t sl_iostream_read(sl_iostream_t *stream,
|
||||
void *buffer,
|
||||
size_t buffer_length,
|
||||
size_t *bytes_read);
|
||||
|
||||
/***************************************************************************//**
|
||||
* Print a character on stream.
|
||||
*
|
||||
* @param[in] stream I/O Stream to be used:
|
||||
* SL_IOSTREAM_STDOUT; Default output stream will be used.
|
||||
* SL_IOSTREAM_STDERR; Default error output stream will be used.
|
||||
* Pointer to specific stream; Specific stream will be used.
|
||||
*
|
||||
* @param[in] c Character to print
|
||||
*
|
||||
* @return Status result
|
||||
******************************************************************************/
|
||||
sl_status_t sl_iostream_putchar(sl_iostream_t *stream,
|
||||
char c);
|
||||
|
||||
/***************************************************************************//**
|
||||
* Print a character on stream.
|
||||
*
|
||||
* @param[in] stream I/O Stream to be used.
|
||||
* SL_IOSTREAM_STDIN; Default input stream will be used.
|
||||
* Pointer to specific stream; Specific stream will be used.
|
||||
*
|
||||
* @param[out] c Pointer to variable that will receive the character.
|
||||
*
|
||||
* @return Status result
|
||||
******************************************************************************/
|
||||
sl_status_t sl_iostream_getchar(sl_iostream_t *stream,
|
||||
char *c);
|
||||
|
||||
/***************************************************************************//**
|
||||
* Print a formated string on stream.
|
||||
*
|
||||
* @param[in] stream I/O Stream to be used:
|
||||
* SL_IOSTREAM_STDOUT; Default output stream will be used.
|
||||
* SL_IOSTREAM_STDERR; Default error output stream will be used.
|
||||
* Pointer to specific stream; Specific stream will be used.
|
||||
*
|
||||
* @param[in] format String that contains the text to be written.
|
||||
*
|
||||
* @param[in] argp A value identifying a variable arguments list.
|
||||
*
|
||||
* @return Status result
|
||||
******************************************************************************/
|
||||
sl_status_t sl_iostream_vprintf(sl_iostream_t *stream,
|
||||
const char *format,
|
||||
va_list argp);
|
||||
|
||||
#if defined(__GNUC__)
|
||||
__attribute__((format(printf, 2, 3)))
|
||||
#endif
|
||||
|
||||
/***************************************************************************//**
|
||||
* Print a formated string on stream.
|
||||
*
|
||||
* @param[in] stream I/O Stream to be used:
|
||||
* SL_IOSTREAM_STDOUT; Default output stream will be used.
|
||||
* SL_IOSTREAM_STDERR; Default error output stream will be used.
|
||||
* Pointer to specific stream; Specific stream will be used.
|
||||
*
|
||||
* @param[in] format String that contains the text to be written.
|
||||
*
|
||||
* @param[in] ... Additional arguments.
|
||||
*
|
||||
* @return Status result
|
||||
******************************************************************************/
|
||||
sl_status_t sl_iostream_printf(sl_iostream_t *stream,
|
||||
const char *format,
|
||||
...);
|
||||
|
||||
/** @} (end addtogroup iostream) */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // SL_IOSTREAM_H
|
||||
112
Libs/platform/service/iostream/inc/sl_iostream_rtt.h
Normal file
112
Libs/platform/service/iostream/inc/sl_iostream_rtt.h
Normal file
@@ -0,0 +1,112 @@
|
||||
/***************************************************************************//**
|
||||
* @file
|
||||
* @brief IO Stream RTT Component.
|
||||
*******************************************************************************
|
||||
* # License
|
||||
* <b>Copyright 2019 Silicon Laboratories Inc. www.silabs.com</b>
|
||||
*******************************************************************************
|
||||
*
|
||||
* SPDX-License-Identifier: Zlib
|
||||
*
|
||||
* The licensor of this software is Silicon Laboratories Inc.
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef SL_IOSTREAM_RTT_H
|
||||
#define SL_IOSTREAM_RTT_H
|
||||
|
||||
#include "sl_iostream.h"
|
||||
#include "sl_status.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/***************************************************************************//**
|
||||
* @addtogroup iostream
|
||||
* @{
|
||||
******************************************************************************/
|
||||
|
||||
/***************************************************************************//**
|
||||
* @addtogroup iostream_rtt I/O Stream RTT
|
||||
* @brief I/O Stream RTT
|
||||
* @details
|
||||
* ## Overview
|
||||
*
|
||||
* Real Time Transfer (RTT) is a bi-directional communication interface developed
|
||||
* by Segger and used with J-Link module. You need to have the Segger RTT library
|
||||
* in your project to use this stream. It is offered as a third-party module in
|
||||
* the Silicon Labs SDK.
|
||||
*
|
||||
* RTT module uses a control block structure located in RAM memory with a specific
|
||||
* ID so that it can be discovered when a connection is established via J-Link.
|
||||
* The control block references a ring buffer for each configured channel. You can
|
||||
* configure the number and size of the ring buffers at compile-time in
|
||||
* SEGGER_RTT_Conf.h configuration file. Please refer to Segger's documentation
|
||||
* for further information on RTT.
|
||||
*
|
||||
* Note that you should only use this stream in a development environment. You
|
||||
* should avoid using it in production.
|
||||
*
|
||||
* ## Initialization
|
||||
*
|
||||
* The stream sets itself as the default stream at the end of the initialization
|
||||
* function.You must reconfigure the default interface if you have multiple streams
|
||||
* in your project else the last stream initialized will be set as the system default
|
||||
* stream.
|
||||
*
|
||||
* ## Power manager integration
|
||||
*
|
||||
* Because RTT communication uses the J-link debug interface when going into EM2 or EM3,
|
||||
* the system will actually go into a special Energy Mode to maintain the debug
|
||||
* capabilities and the power consumption will still remain high. Therefore it is unwise
|
||||
* to keep a debug interface with RTT channel open if you want to test your power
|
||||
* consumption.
|
||||
*
|
||||
* ## Communication channel connection
|
||||
*
|
||||
* For connecting to the RTT channel you can use the tools provided by Segger or you
|
||||
* can open a telnet session and connect to the port 19021 using your host IP
|
||||
* address when the debugger is connected using USB and using J-Link debugger IP address
|
||||
* when your debugger is connected over ethernet.
|
||||
*
|
||||
* @{
|
||||
******************************************************************************/
|
||||
|
||||
extern sl_iostream_t *sl_iostream_rtt_handle; ///< sl_iostream_rtt_handle
|
||||
extern sl_iostream_instance_info_t sl_iostream_instance_rtt_info; ///< sl_iostream_instance_rtt_info
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Prototypes
|
||||
|
||||
/***************************************************************************//**
|
||||
* RTT Stream init.
|
||||
*
|
||||
* @return Status result
|
||||
******************************************************************************/
|
||||
sl_status_t sl_iostream_rtt_init(void);
|
||||
|
||||
/** @} (end addtogroup iostream_rtt) */
|
||||
/** @} (end addtogroup iostream) */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // SL_IOSTREAM_RTT_H
|
||||
303
Libs/platform/service/iostream/src/sl_iostream.c
Normal file
303
Libs/platform/service/iostream/src/sl_iostream.c
Normal file
@@ -0,0 +1,303 @@
|
||||
/***************************************************************************//**
|
||||
* @file
|
||||
* @brief IO Stream.
|
||||
*******************************************************************************
|
||||
* # License
|
||||
* <b>Copyright 2019 Silicon Laboratories Inc. www.silabs.com</b>
|
||||
*******************************************************************************
|
||||
*
|
||||
* SPDX-License-Identifier: Zlib
|
||||
*
|
||||
* The licensor of this software is Silicon Laboratories Inc.
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
#include "sl_iostream.h"
|
||||
#include "sl_status.h"
|
||||
#include "sl_assert.h"
|
||||
#include "sl_core.h"
|
||||
|
||||
#if defined(SL_CATALOG_KERNEL_PRESENT) && !defined(SL_IOSTREAM_FORCE_BAREMETAL)
|
||||
#include "cmsis_os2.h"
|
||||
#include "sli_cmsis_os2_ext_task_register.h"
|
||||
#endif
|
||||
|
||||
#if defined(SL_CATALOG_PRINTF_PRESENT)
|
||||
#include "printf.h"
|
||||
#else
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
|
||||
/*******************************************************************************
|
||||
******************************* DEFINES ***********************************
|
||||
******************************************************************************/
|
||||
|
||||
#if defined(SL_CATALOG_KERNEL_PRESENT) && !defined(SL_IOSTREAM_FORCE_BAREMETAL)
|
||||
#define TASK_REGISTER_ID_INVALID 0xFF
|
||||
#endif
|
||||
|
||||
/*******************************************************************************
|
||||
*************************** LOCAL VARIABLES ********************************
|
||||
******************************************************************************/
|
||||
|
||||
#if defined(SL_CATALOG_KERNEL_PRESENT) && !defined(SL_IOSTREAM_FORCE_BAREMETAL)
|
||||
static sli_task_register_id_t sli_task_register_id = TASK_REGISTER_ID_INVALID;
|
||||
static sl_iostream_t *sli_iostream_system_default = NULL;
|
||||
#endif
|
||||
static sl_iostream_t *sli_iostream_default = NULL;
|
||||
|
||||
sl_iostream_t sl_iostream_null = {
|
||||
.write = NULL,
|
||||
.read = NULL,
|
||||
.context = NULL
|
||||
};
|
||||
|
||||
/*******************************************************************************
|
||||
********************* LOCAL FUNCTION PROTOTYPES ***************************
|
||||
******************************************************************************/
|
||||
|
||||
#if defined(SL_CATALOG_PRINTF_PRESENT)
|
||||
static void stream_putchar(char character,
|
||||
void *arg);
|
||||
#endif
|
||||
|
||||
/*******************************************************************************
|
||||
************************** GLOBAL FUNCTIONS *******************************
|
||||
******************************************************************************/
|
||||
|
||||
/***************************************************************************//**
|
||||
* Registers default IO stream to be used
|
||||
******************************************************************************/
|
||||
sl_status_t sl_iostream_set_default(sl_iostream_t *stream)
|
||||
{
|
||||
#if defined(SL_CATALOG_KERNEL_PRESENT) && !defined(SL_IOSTREAM_FORCE_BAREMETAL)
|
||||
sli_task_register_id_t reg_id;
|
||||
sl_status_t status;
|
||||
#endif
|
||||
CORE_DECLARE_IRQ_STATE;
|
||||
|
||||
CORE_ENTER_CRITICAL();
|
||||
#if defined(SL_CATALOG_KERNEL_PRESENT) && !defined(SL_IOSTREAM_FORCE_BAREMETAL)
|
||||
if (osThreadGetId() != NULL) {
|
||||
reg_id = sli_task_register_id;
|
||||
if (reg_id == TASK_REGISTER_ID_INVALID) {
|
||||
status = sli_osTaskRegisterNew(®_id);
|
||||
EFM_ASSERT(status == SL_STATUS_OK);
|
||||
sli_task_register_id = reg_id;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
sli_iostream_default = stream;
|
||||
CORE_EXIT_CRITICAL();
|
||||
|
||||
#if defined(SL_CATALOG_KERNEL_PRESENT) && !defined(SL_IOSTREAM_FORCE_BAREMETAL)
|
||||
if (osThreadGetId() != NULL) {
|
||||
status = sli_osTaskRegisterSetValue(NULL, reg_id, (uint32_t)stream);
|
||||
EFM_ASSERT(status == SL_STATUS_OK);
|
||||
}
|
||||
#endif
|
||||
|
||||
return SL_STATUS_OK;
|
||||
}
|
||||
|
||||
/***************************************************************************//**
|
||||
* Get default IO stream configured
|
||||
******************************************************************************/
|
||||
sl_iostream_t *sl_iostream_get_default(void)
|
||||
{
|
||||
#if defined(SL_CATALOG_KERNEL_PRESENT) && !defined(SL_IOSTREAM_FORCE_BAREMETAL)
|
||||
sl_status_t status;
|
||||
sli_task_register_id_t reg_id;
|
||||
#endif
|
||||
sl_iostream_t *stream = NULL;
|
||||
CORE_DECLARE_IRQ_STATE;
|
||||
|
||||
CORE_ENTER_CRITICAL();
|
||||
#if defined(SL_CATALOG_KERNEL_PRESENT) && !defined(SL_IOSTREAM_FORCE_BAREMETAL)
|
||||
reg_id = sli_task_register_id;
|
||||
#endif
|
||||
stream = sli_iostream_default;
|
||||
CORE_EXIT_CRITICAL();
|
||||
|
||||
#if defined(SL_CATALOG_KERNEL_PRESENT) && !defined(SL_IOSTREAM_FORCE_BAREMETAL)
|
||||
if (osThreadGetId() != NULL) {
|
||||
if (reg_id != TASK_REGISTER_ID_INVALID) {
|
||||
uint32_t reg;
|
||||
|
||||
status = sli_osTaskRegisterGetValue(NULL, sli_task_register_id, ®);
|
||||
EFM_ASSERT(status == SL_STATUS_OK);
|
||||
|
||||
stream = (sl_iostream_t *)reg;
|
||||
}
|
||||
}
|
||||
if (stream == NULL) {
|
||||
CORE_ENTER_CRITICAL();
|
||||
stream = sli_iostream_system_default;
|
||||
CORE_EXIT_CRITICAL();
|
||||
}
|
||||
#endif
|
||||
|
||||
return stream;
|
||||
}
|
||||
|
||||
/***************************************************************************//**
|
||||
* Set systemwide default IO stream
|
||||
******************************************************************************/
|
||||
#if defined(SL_CATALOG_KERNEL_PRESENT) && !defined(SL_IOSTREAM_FORCE_BAREMETAL)
|
||||
sl_status_t sl_iostream_set_system_default(sl_iostream_t *stream)
|
||||
{
|
||||
sl_status_t status = SL_STATUS_OK;
|
||||
CORE_DECLARE_IRQ_STATE;
|
||||
|
||||
CORE_ENTER_CRITICAL();
|
||||
sli_iostream_system_default = stream;
|
||||
CORE_EXIT_CRITICAL();
|
||||
return status;
|
||||
}
|
||||
#endif
|
||||
|
||||
/***************************************************************************//**
|
||||
* Stream write implementation
|
||||
******************************************************************************/
|
||||
sl_status_t sl_iostream_write(sl_iostream_t *stream,
|
||||
const void *buffer,
|
||||
size_t buffer_length)
|
||||
{
|
||||
if (stream == SL_IOSTREAM_STDOUT) {
|
||||
stream = sl_iostream_get_default();
|
||||
}
|
||||
|
||||
if ((stream != NULL) && (stream->write != NULL)) {
|
||||
return stream->write(stream->context, buffer, buffer_length);
|
||||
} else {
|
||||
return SL_STATUS_INVALID_CONFIGURATION;
|
||||
}
|
||||
}
|
||||
|
||||
/***************************************************************************//**
|
||||
* Stream read implementation
|
||||
******************************************************************************/
|
||||
sl_status_t sl_iostream_read(sl_iostream_t *stream,
|
||||
void *buffer,
|
||||
size_t buffer_length,
|
||||
size_t *bytes_read)
|
||||
{
|
||||
size_t size;
|
||||
size_t *read_size = &size;
|
||||
|
||||
if (stream == SL_IOSTREAM_STDIN) {
|
||||
stream = sl_iostream_get_default();
|
||||
}
|
||||
|
||||
if (bytes_read != NULL) {
|
||||
read_size = bytes_read;
|
||||
}
|
||||
|
||||
if ((stream != NULL) && (stream->read != NULL)) {
|
||||
return stream->read(stream->context, buffer, buffer_length, read_size);
|
||||
} else {
|
||||
return SL_STATUS_INVALID_CONFIGURATION;
|
||||
}
|
||||
}
|
||||
|
||||
/***************************************************************************//**
|
||||
* Stream putchar implementation
|
||||
******************************************************************************/
|
||||
sl_status_t sl_iostream_putchar(sl_iostream_t *stream,
|
||||
char c)
|
||||
{
|
||||
return sl_iostream_write(stream, &c, 1);
|
||||
}
|
||||
|
||||
/***************************************************************************//**
|
||||
* Stream getchar implementation
|
||||
******************************************************************************/
|
||||
sl_status_t sl_iostream_getchar(sl_iostream_t *stream,
|
||||
char *c)
|
||||
{
|
||||
return sl_iostream_read(stream, c, 1, NULL);
|
||||
}
|
||||
|
||||
/***************************************************************************//**
|
||||
* Stream vprintf implementation
|
||||
******************************************************************************/
|
||||
sl_status_t sl_iostream_vprintf(sl_iostream_t *stream,
|
||||
const char *format,
|
||||
va_list argp)
|
||||
{
|
||||
#if !defined(SL_CATALOG_PRINTF_PRESENT)
|
||||
sl_iostream_t *default_stream;
|
||||
#endif
|
||||
sl_iostream_t *output_stream = stream;
|
||||
sl_status_t status = SL_STATUS_OK;
|
||||
int ret;
|
||||
|
||||
#if defined(SL_CATALOG_PRINTF_PRESENT)
|
||||
if (output_stream == SL_IOSTREAM_STDOUT) {
|
||||
output_stream = sl_iostream_get_default();
|
||||
}
|
||||
ret = vfctprintf(stream_putchar, output_stream, format, argp);
|
||||
#else
|
||||
if (output_stream == SL_IOSTREAM_STDOUT) {
|
||||
default_stream = sl_iostream_get_default();
|
||||
output_stream = default_stream;
|
||||
} else {
|
||||
default_stream = sl_iostream_get_default();
|
||||
if (default_stream != output_stream) {
|
||||
sl_iostream_set_default(output_stream);
|
||||
}
|
||||
}
|
||||
|
||||
ret = vprintf(format, argp);
|
||||
if (default_stream != output_stream) {
|
||||
sl_iostream_set_default(default_stream);
|
||||
}
|
||||
#endif
|
||||
if (ret <= 0) {
|
||||
status = SL_STATUS_OBJECT_WRITE;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/***************************************************************************//**
|
||||
* Stream printf implementation
|
||||
******************************************************************************/
|
||||
sl_status_t sl_iostream_printf(sl_iostream_t *stream,
|
||||
const char *format,
|
||||
...)
|
||||
{
|
||||
sl_status_t status;
|
||||
va_list argp;
|
||||
va_start(argp, format);
|
||||
status = sl_iostream_vprintf(stream, format, argp);
|
||||
va_end(argp);
|
||||
return status;
|
||||
}
|
||||
|
||||
/***************************************************************************//**
|
||||
* putchar implementation for sl_iostream_printf; called by fnctprintf()
|
||||
******************************************************************************/
|
||||
#if defined(SL_CATALOG_PRINTF_PRESENT)
|
||||
static void stream_putchar(char character,
|
||||
void *arg)
|
||||
{
|
||||
sl_iostream_putchar((sl_iostream_t *)arg, character);
|
||||
}
|
||||
#endif
|
||||
144
Libs/platform/service/iostream/src/sl_iostream_rtt.c
Normal file
144
Libs/platform/service/iostream/src/sl_iostream_rtt.c
Normal file
@@ -0,0 +1,144 @@
|
||||
/***************************************************************************//**
|
||||
* @file
|
||||
* @brief IO Stream RTT Component.
|
||||
*******************************************************************************
|
||||
* # License
|
||||
* <b>Copyright 2019 Silicon Laboratories Inc. www.silabs.com</b>
|
||||
*******************************************************************************
|
||||
*
|
||||
* SPDX-License-Identifier: Zlib
|
||||
*
|
||||
* The licensor of this software is Silicon Laboratories Inc.
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
#include "sl_iostream_rtt.h"
|
||||
//#include "SEGGER_RTT.h"
|
||||
#include "sl_status.h"
|
||||
|
||||
#if !defined(IOSTREAM_RTT_UP_MODE)
|
||||
#define IOSTREAM_RTT_UP_MODE SEGGER_RTT_MODE_NO_BLOCK_TRIM
|
||||
#endif
|
||||
|
||||
#if !defined(IOSTREAM_RTT_DOWN_MODE)
|
||||
#define IOSTREAM_RTT_DOWN_MODE SEGGER_RTT_MODE_NO_BLOCK_TRIM
|
||||
#endif
|
||||
|
||||
/*******************************************************************************
|
||||
********************* LOCAL FUNCTION PROTOTYPES ***************************
|
||||
******************************************************************************/
|
||||
|
||||
static sl_status_t rtt_write(void *context,
|
||||
const void *buffer,
|
||||
size_t buffer_length);
|
||||
|
||||
static sl_status_t rtt_read(void *context,
|
||||
void *buffer,
|
||||
size_t buffer_length,
|
||||
size_t *bytes_read);
|
||||
|
||||
/*******************************************************************************
|
||||
****************************** VARIABLES **********************************
|
||||
******************************************************************************/
|
||||
|
||||
static sl_iostream_t sl_iostream_rtt = {
|
||||
.read = rtt_read,
|
||||
.write = rtt_write,
|
||||
.context = NULL
|
||||
};
|
||||
|
||||
sl_iostream_t *sl_iostream_rtt_handle = &sl_iostream_rtt;
|
||||
|
||||
sl_iostream_instance_info_t sl_iostream_instance_rtt_info = {
|
||||
.handle = &sl_iostream_rtt,
|
||||
.name = "rtt",
|
||||
.type = SL_IOSTREAM_TYPE_RTT,
|
||||
.periph_id = 0,
|
||||
.init = sl_iostream_rtt_init,
|
||||
};
|
||||
|
||||
/*******************************************************************************
|
||||
************************** GLOBAL FUNCTIONS *******************************
|
||||
******************************************************************************/
|
||||
|
||||
/***************************************************************************//**
|
||||
* RTT Stream init.
|
||||
******************************************************************************/
|
||||
sl_status_t sl_iostream_rtt_init(void)
|
||||
{
|
||||
//SEGGER_RTT_ConfigUpBuffer(0, NULL, NULL, 0, IOSTREAM_RTT_UP_MODE);
|
||||
//SEGGER_RTT_ConfigDownBuffer(0, NULL, NULL, 0, IOSTREAM_RTT_DOWN_MODE);
|
||||
sl_iostream_set_system_default(&sl_iostream_rtt);
|
||||
|
||||
return SL_STATUS_OK;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
************************** LOCAL FUNCTIONS ********************************
|
||||
******************************************************************************/
|
||||
|
||||
/***************************************************************************//**
|
||||
* Internal RTT stream write implementation
|
||||
******************************************************************************/
|
||||
static sl_status_t rtt_write(void *context,
|
||||
const void *buffer,
|
||||
size_t buffer_length)
|
||||
{
|
||||
uint32_t ret = 0;
|
||||
sl_status_t status;
|
||||
(void)context;
|
||||
(void)ret;
|
||||
|
||||
//ret = SEGGER_RTT_Write(0, buffer, buffer_length);
|
||||
|
||||
#if ((IOSTREAM_RTT_UP_MODE == SEGGER_RTT_MODE_NO_BLOCK_TRIM) \
|
||||
|| (IOSTREAM_RTT_UP_MODE == SEGGER_RTT_MODE_NO_BLOCK_SKIP))
|
||||
status = SL_STATUS_OK; // Ignore error
|
||||
#else
|
||||
if (ret > 0) {
|
||||
status = SL_STATUS_OK;
|
||||
} else {
|
||||
status = SL_STATUS_IO;
|
||||
}
|
||||
#endif
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/***************************************************************************//**
|
||||
* Internal RTT stream read implementation
|
||||
******************************************************************************/
|
||||
static sl_status_t rtt_read(void *context,
|
||||
void *buffer,
|
||||
size_t buffer_length,
|
||||
size_t *bytes_read)
|
||||
{
|
||||
sl_status_t status;
|
||||
(void)context;
|
||||
|
||||
// *bytes_read = SEGGER_RTT_Read(0, buffer, buffer_length);
|
||||
|
||||
if (*bytes_read > 0) {
|
||||
status = SL_STATUS_OK;
|
||||
} else {
|
||||
status = SL_STATUS_EMPTY;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
Reference in New Issue
Block a user