feat(newlib): Add newlib platform function

This commit is contained in:
Dong Heng
2018-05-11 17:27:54 +08:00
parent 58a66a3d39
commit 30de450816
11 changed files with 330 additions and 13 deletions

View File

@ -77,6 +77,17 @@ extern "C" {
#include <xtensa/xtruntime.h>
#include "xtensa_rtos.h"
#if defined(configUSE_NEWLIB_REENTRANT) && configUSE_NEWLIB_REENTRANT == 1
#if defined(CONFIG_NEWLIB_LIBRARY_LEVEL_NORMAL) || defined(CONFIG_NEWLIB_LIBRARY_LEVEL_NANO)
#include "esp_newlib.h"
#define _impure_ptr _global_impure_ptr
#undef _REENT_INIT_PTR
#define _REENT_INIT_PTR(p) esp_reent_init(p)
#endif
#endif
/*-----------------------------------------------------------
* Port specific definitions.
*

View File

@ -0,0 +1,44 @@
// Copyright 2018-2019 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
static struct _reent impure_data;
struct _reent *_global_impure_ptr = &impure_data;
struct _reent *__getreent()
{
extern char _xt_isr_status;
/*
* Locking mutex(only mutex, not ISR mutex) at the following three
* state may cause OS death. So we use a extra _reent data instead
* of task private reent data.
*
* But although at the state none of "taskSCHEDULER_RUNNING", exception
* can cause CPU swicth context, then Locking mutex may cause OS death.
* So we command that use ets_printf(ROM function) instead of "printf"
* at exception and system kernal critical state.
*/
if (_xt_isr_status
|| !xTaskGetCurrentTaskHandle()
|| xTaskGetSchedulerState() != taskSCHEDULER_RUNNING)
return &impure_data;
/*
* When scheduler starts, _global_impure_ptr = pxCurrentTCB->xNewLib_reent.
*/
return _global_impure_ptr;
}