mirror of
https://github.com/pvvx/RTL00MP3.git
synced 2025-07-31 12:41:06 +00:00
first commit
This commit is contained in:
parent
2ee525362e
commit
d108756e9b
792 changed files with 336059 additions and 0 deletions
118
RTL00_SDKV35a/component/common/mbed/common/us_ticker_api.c
Normal file
118
RTL00_SDKV35a/component/common/mbed/common/us_ticker_api.c
Normal file
|
|
@ -0,0 +1,118 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* 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 <stddef.h>
|
||||
#include "us_ticker_api.h"
|
||||
#include "cmsis.h"
|
||||
|
||||
static ticker_event_handler event_handler;
|
||||
static ticker_event_t *head = NULL;
|
||||
|
||||
void us_ticker_set_handler(ticker_event_handler handler) {
|
||||
us_ticker_init();
|
||||
|
||||
event_handler = handler;
|
||||
}
|
||||
|
||||
void us_ticker_irq_handler(void) {
|
||||
us_ticker_clear_interrupt();
|
||||
|
||||
/* Go through all the pending TimerEvents */
|
||||
while (1) {
|
||||
if (head == NULL) {
|
||||
// There are no more TimerEvents left, so disable matches.
|
||||
us_ticker_disable_interrupt();
|
||||
return;
|
||||
}
|
||||
|
||||
if ((int)(head->timestamp - us_ticker_read()) <= 0) {
|
||||
// This event was in the past:
|
||||
// point to the following one and execute its handler
|
||||
ticker_event_t *p = head;
|
||||
head = head->next;
|
||||
if (event_handler != NULL) {
|
||||
event_handler(p->id); // NOTE: the handler can set new events
|
||||
}
|
||||
/* Note: We continue back to examining the head because calling the
|
||||
* event handler may have altered the chain of pending events. */
|
||||
} else {
|
||||
// This event and the following ones in the list are in the future:
|
||||
// set it as next interrupt and return
|
||||
us_ticker_set_interrupt(head->timestamp);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void us_ticker_insert_event(ticker_event_t *obj, timestamp_t timestamp, uint32_t id) {
|
||||
/* disable interrupts for the duration of the function */
|
||||
__disable_irq();
|
||||
|
||||
// initialise our data
|
||||
obj->timestamp = timestamp;
|
||||
obj->id = id;
|
||||
|
||||
/* Go through the list until we either reach the end, or find
|
||||
an element this should come before (which is possibly the
|
||||
head). */
|
||||
ticker_event_t *prev = NULL, *p = head;
|
||||
while (p != NULL) {
|
||||
/* check if we come before p */
|
||||
if ((int)(timestamp - p->timestamp) <= 0) {
|
||||
break;
|
||||
}
|
||||
/* go to the next element */
|
||||
prev = p;
|
||||
p = p->next;
|
||||
}
|
||||
/* if prev is NULL we're at the head */
|
||||
if (prev == NULL) {
|
||||
head = obj;
|
||||
us_ticker_set_interrupt(timestamp);
|
||||
} else {
|
||||
prev->next = obj;
|
||||
}
|
||||
/* if we're at the end p will be NULL, which is correct */
|
||||
obj->next = p;
|
||||
|
||||
__enable_irq();
|
||||
}
|
||||
|
||||
void us_ticker_remove_event(ticker_event_t *obj) {
|
||||
__disable_irq();
|
||||
|
||||
// remove this object from the list
|
||||
if (head == obj) {
|
||||
// first in the list, so just drop me
|
||||
head = obj->next;
|
||||
if (head == NULL) {
|
||||
us_ticker_disable_interrupt();
|
||||
} else {
|
||||
us_ticker_set_interrupt(head->timestamp);
|
||||
}
|
||||
} else {
|
||||
// find the object before me, then drop me
|
||||
ticker_event_t* p = head;
|
||||
while (p != NULL) {
|
||||
if (p->next == obj) {
|
||||
p->next = obj->next;
|
||||
break;
|
||||
}
|
||||
p = p->next;
|
||||
}
|
||||
}
|
||||
|
||||
__enable_irq();
|
||||
}
|
||||
112
RTL00_SDKV35a/component/common/mbed/common/wait_api.c
Normal file
112
RTL00_SDKV35a/component/common/mbed/common/wait_api.c
Normal file
|
|
@ -0,0 +1,112 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* 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 "wait_api.h"
|
||||
#include "us_ticker_api.h"
|
||||
|
||||
#include "platform_autoconf.h"
|
||||
|
||||
#define WAIT_US_USE_CYCCNT
|
||||
|
||||
#ifdef WAIT_US_USE_CYCCNT
|
||||
//#include "core_cm3.h"
|
||||
#ifdef __cplusplus
|
||||
#define __I volatile /*!< Defines 'read only' permissions */
|
||||
#else
|
||||
#define __I volatile const /*!< Defines 'read only' permissions */
|
||||
#endif
|
||||
#define __O volatile /*!< Defines 'write only' permissions */
|
||||
#define __IO volatile /*!< Defines 'read / write' permissions */
|
||||
|
||||
typedef struct
|
||||
{
|
||||
__IO uint32_t DHCSR; /*!< Offset: 0x000 (R/W) Debug Halting Control and Status Register */
|
||||
__O uint32_t DCRSR; /*!< Offset: 0x004 ( /W) Debug Core Register Selector Register */
|
||||
__IO uint32_t DCRDR; /*!< Offset: 0x008 (R/W) Debug Core Register Data Register */
|
||||
__IO uint32_t DEMCR; /*!< Offset: 0x00C (R/W) Debug Exception and Monitor Control Register */
|
||||
} CoreDebug_Type;
|
||||
|
||||
#define CoreDebug_BASE (0xE000EDF0UL) /*!< Core Debug Base Address */
|
||||
#define CoreDebug ((CoreDebug_Type *) CoreDebug_BASE) /*!< Core Debug configuration struct */
|
||||
|
||||
/** \brief Structure type to access the Data Watchpoint and Trace Register (DWT).
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
__IO uint32_t CTRL; /*!< Offset: 0x000 (R/W) Control Register */
|
||||
__IO uint32_t CYCCNT; /*!< Offset: 0x004 (R/W) Cycle Count Register */
|
||||
__IO uint32_t CPICNT; /*!< Offset: 0x008 (R/W) CPI Count Register */
|
||||
__IO uint32_t EXCCNT; /*!< Offset: 0x00C (R/W) Exception Overhead Count Register */
|
||||
__IO uint32_t SLEEPCNT; /*!< Offset: 0x010 (R/W) Sleep Count Register */
|
||||
__IO uint32_t LSUCNT; /*!< Offset: 0x014 (R/W) LSU Count Register */
|
||||
__IO uint32_t FOLDCNT; /*!< Offset: 0x018 (R/W) Folded-instruction Count Register */
|
||||
__I uint32_t PCSR; /*!< Offset: 0x01C (R/ ) Program Counter Sample Register */
|
||||
__IO uint32_t COMP0; /*!< Offset: 0x020 (R/W) Comparator Register 0 */
|
||||
__IO uint32_t MASK0; /*!< Offset: 0x024 (R/W) Mask Register 0 */
|
||||
__IO uint32_t FUNCTION0; /*!< Offset: 0x028 (R/W) Function Register 0 */
|
||||
uint32_t RESERVED0[1];
|
||||
__IO uint32_t COMP1; /*!< Offset: 0x030 (R/W) Comparator Register 1 */
|
||||
__IO uint32_t MASK1; /*!< Offset: 0x034 (R/W) Mask Register 1 */
|
||||
__IO uint32_t FUNCTION1; /*!< Offset: 0x038 (R/W) Function Register 1 */
|
||||
uint32_t RESERVED1[1];
|
||||
__IO uint32_t COMP2; /*!< Offset: 0x040 (R/W) Comparator Register 2 */
|
||||
__IO uint32_t MASK2; /*!< Offset: 0x044 (R/W) Mask Register 2 */
|
||||
__IO uint32_t FUNCTION2; /*!< Offset: 0x048 (R/W) Function Register 2 */
|
||||
uint32_t RESERVED2[1];
|
||||
__IO uint32_t COMP3; /*!< Offset: 0x050 (R/W) Comparator Register 3 */
|
||||
__IO uint32_t MASK3; /*!< Offset: 0x054 (R/W) Mask Register 3 */
|
||||
__IO uint32_t FUNCTION3; /*!< Offset: 0x058 (R/W) Function Register 3 */
|
||||
} DWT_Type;
|
||||
|
||||
#define DWT_BASE (0xE0001000UL) /*!< DWT Base Address */
|
||||
#define DWT ((DWT_Type *) DWT_BASE ) /*!< DWT configuration struct */
|
||||
|
||||
#define DWT_CTRL_CYCCNTENA_Pos 0 /*!< DWT CTRL: CYCCNTENA Position */
|
||||
#define DWT_CTRL_CYCCNTENA_Msk (0x1UL << DWT_CTRL_CYCCNTENA_Pos) /*!< DWT CTRL: CYCCNTENA Mask */
|
||||
#define CoreDebug_DEMCR_TRCENA_Pos 24 /*!< CoreDebug DEMCR: TRCENA Position */
|
||||
#define CoreDebug_DEMCR_TRCENA_Msk (1UL << CoreDebug_DEMCR_TRCENA_Pos) /*!< CoreDebug DEMCR: TRCENA Mask */
|
||||
#endif
|
||||
|
||||
void wait(float s) {
|
||||
// wait_us((int)(s * 1000000.0f));
|
||||
vTaskDelay((int)(s * 1000.0f));
|
||||
}
|
||||
|
||||
void wait_ms(int ms) {
|
||||
if(ms > 0) vTaskDelay(ms);
|
||||
// wait_us(ms * 1000);
|
||||
}
|
||||
|
||||
|
||||
void wait_us(int us) { // До 2.147483648 секунды!
|
||||
uint32_t start;
|
||||
#ifdef WAIT_US_USE_CYCCNT
|
||||
if(us < 1) return;
|
||||
if (us < 255) { // G-timer resolution is ~31 us (1/32K), use DWT->CYCCNT...
|
||||
if(!(DWT->CTRL & DWT_CTRL_CYCCNTENA_Msk)) { // уже включен?
|
||||
CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk; // открыть доступ
|
||||
DWT->CYCCNT = 0; // обнулить и запустить
|
||||
DWT->CTRL |= DWT_CTRL_CYCCNTENA_Msk; // запустить счет
|
||||
}
|
||||
start = DWT->CYCCNT + us * ( PLATFORM_CLOCK / 1000000 );
|
||||
while ( ( ( int32_t )DWT->CYCCNT - start) < 0 );
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
start = us_ticker_read(); // G-timer resolution is ~31 us (1/32K), and is a countdown timer
|
||||
while ((us_ticker_read() - start) < (uint32_t)us);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue