Initial commit: TXW82x FPV v2.7.0.7-42229 SDK + project sources
This commit is contained in:
36
.gitignore
vendored
Normal file
36
.gitignore
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
# ===== IDE / Editor caches =====
|
||||
.vscode/
|
||||
.idea/
|
||||
*.swp
|
||||
*.swo
|
||||
|
||||
# ===== Tool caches =====
|
||||
.ruff_cache/
|
||||
project/.cache/
|
||||
project/.cdk/
|
||||
*.idx
|
||||
|
||||
# ===== Build output directories =====
|
||||
project/Obj/
|
||||
project/Lst/
|
||||
project/bakup/
|
||||
|
||||
# ===== Build intermediate / output files =====
|
||||
*.o
|
||||
*.d
|
||||
*.obj
|
||||
*.elf
|
||||
*.hex
|
||||
*.map
|
||||
*.asm
|
||||
*.lst
|
||||
|
||||
# ===== Firmware build outputs (keep core firmware: txw82xcore.bin) =====
|
||||
project/APP.bin
|
||||
project/txw82xApp*.bin
|
||||
project/txw82xapp.bin
|
||||
|
||||
# ===== OS junk =====
|
||||
.DS_Store
|
||||
Thumbs.db
|
||||
desktop.ini
|
||||
14
csky/configs/csi_config.h
Normal file
14
csky/configs/csi_config.h
Normal file
@@ -0,0 +1,14 @@
|
||||
#ifndef _CSI_CONFIG_H_
|
||||
#define _CSI_CONFIG_H_
|
||||
|
||||
#include "sys_config.h"
|
||||
|
||||
#define CONFIG_HAVE_VIC 1
|
||||
#define CONFIG_SUPPORT_TSPEND 1
|
||||
#define CONFIG_SEPARATE_IRQ_SP 1
|
||||
#define CONFIG_ARCH_INTERRUPTSTACK OS_IRQ_STACK_SIZE
|
||||
#define CONFIG_SYSTICK_HZ OS_SYSTICK_HZ
|
||||
#define CONFIG_IDLE_TASK_STACK_SIZE OS_IDLE_TASK_STACK
|
||||
#define CONFIG_TIMER_TASK_STACK_SIZE OS_TIMER_TASK_STACK_SIZE
|
||||
#define RHINO_CONFIG_TIMER_MSG_NUM OS_TIMER_MSG_NUM
|
||||
#endif
|
||||
1604
csky/csi_core/include/core_802.h
Normal file
1604
csky/csi_core/include/core_802.h
Normal file
File diff suppressed because it is too large
Load Diff
1720
csky/csi_core/include/core_803.h
Normal file
1720
csky/csi_core/include/core_803.h
Normal file
File diff suppressed because it is too large
Load Diff
1659
csky/csi_core/include/core_804.h
Normal file
1659
csky/csi_core/include/core_804.h
Normal file
File diff suppressed because it is too large
Load Diff
1288
csky/csi_core/include/core_rv32.h
Normal file
1288
csky/csi_core/include/core_rv32.h
Normal file
File diff suppressed because it is too large
Load Diff
65
csky/csi_core/include/csi_core.h
Normal file
65
csky/csi_core/include/csi_core.h
Normal file
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Copyright (C) 2017 C-SKY Microsystems Co., Ltd. All rights reserved.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/******************************************************************************
|
||||
* @file csi_core.h
|
||||
* @brief CSI Core Layer Header File
|
||||
* @version V1.0
|
||||
* @date 02. June 2017
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef _CORE_H_
|
||||
#define _CORE_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#if defined(__CK801__) || defined(__E801__)
|
||||
#include <core_801.h>
|
||||
#elif defined(__CK802__) || defined(__E802__) || defined(__E802T__) || defined(__S802__) || defined(__S802T__)
|
||||
#include <core_802.h>
|
||||
#elif defined(__CK804__) || defined(__E804D__) || defined(__E804DT__) || defined(__E804F__) || defined(__E804FT__) || defined (__E804DF__) || defined(__E804DFT__)
|
||||
#include <core_804.h>
|
||||
#elif defined(__CK803__) || defined(__E803__) || defined(__E803T__) || defined(__S803__) || defined(__S803T__)
|
||||
#include <core_803.h>
|
||||
#elif defined(__CK805__) || defined(__I805__) || defined(__I805F__)
|
||||
#include <core_805.h>
|
||||
#elif defined(__CK610__)
|
||||
#include <core_ck610.h>
|
||||
#elif defined(__CK810__) || defined(__C810__) || defined(__C810T__) || defined(__C810V__) || defined(__C810VT__)
|
||||
#include <core_810.h>
|
||||
#elif defined(__CK807__) || defined(__C807__) || defined(__C807F__) || defined(__C807FV__) || defined(__R807__)
|
||||
#include <core_807.h>
|
||||
#elif defined(__riscv) && defined(CONFIG_CSKY_CORETIM)
|
||||
#include <core_rv32_old.h>
|
||||
#elif defined(__riscv)
|
||||
#include <core_rv32.h>
|
||||
#endif
|
||||
|
||||
#ifdef __riscv
|
||||
#include <csi_rv32_gcc.h>
|
||||
#else
|
||||
#include <csi_gcc.h>
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _CORE_H_ */
|
||||
2936
csky/csi_core/include/csi_gcc.h
Normal file
2936
csky/csi_core/include/csi_gcc.h
Normal file
File diff suppressed because it is too large
Load Diff
2904
csky/csi_core/include/csi_rv32_gcc.h
Normal file
2904
csky/csi_core/include/csi_rv32_gcc.h
Normal file
File diff suppressed because it is too large
Load Diff
BIN
csky/csi_dsp/doc/csi-dsp-cn.pdf
Normal file
BIN
csky/csi_dsp/doc/csi-dsp-cn.pdf
Normal file
Binary file not shown.
BIN
csky/csi_dsp/doc/csi-dsp-en.pdf
Normal file
BIN
csky/csi_dsp/doc/csi-dsp-en.pdf
Normal file
Binary file not shown.
BIN
csky/csi_dsp/doc/csi-nn-dsp2.pdf
Normal file
BIN
csky/csi_dsp/doc/csi-nn-dsp2.pdf
Normal file
Binary file not shown.
BIN
csky/csi_dsp/doc/csi-nn-vdsp2.pdf
Normal file
BIN
csky/csi_dsp/doc/csi-nn-vdsp2.pdf
Normal file
Binary file not shown.
316
csky/csi_dsp/include/csi_common_tables.h
Normal file
316
csky/csi_dsp/include/csi_common_tables.h
Normal file
@@ -0,0 +1,316 @@
|
||||
/*
|
||||
* Copyright (C) 2016-2019 C-SKY Limited. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/******************************************************************************
|
||||
* @file csi_common_tables.h
|
||||
* @brief This file has extern declaration for common tables like
|
||||
* Bitreverse, reciprocal etc which are used across different functions.
|
||||
* @version V1.0
|
||||
* @date 20. Dec 2016
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef _CSI_COMMON_TABLES_H
|
||||
#define _CSI_COMMON_TABLES_H
|
||||
|
||||
#include "csi_math.h"
|
||||
|
||||
extern const uint16_t csiBitRevTable[1024];
|
||||
extern const q15_t csiRecipTableQ15[64];
|
||||
extern const q31_t csiRecipTableQ31[64];
|
||||
extern const uint32_t twiddleCoef_16[32];
|
||||
extern const uint32_t twiddleCoef_32[64];
|
||||
extern const uint32_t twiddleCoef_64[128];
|
||||
extern const uint32_t twiddleCoef_128[256];
|
||||
extern const uint32_t twiddleCoef_256[512];
|
||||
extern const uint32_t twiddleCoef_512[1024];
|
||||
extern const uint32_t twiddleCoef_1024[2048];
|
||||
extern const uint32_t twiddleCoef_2048[4096];
|
||||
extern const uint32_t twiddleCoef_4096[8192];
|
||||
extern const q31_t twiddleCoef_16_q31[24];
|
||||
extern const q31_t twiddleCoef_32_q31[48];
|
||||
extern const q31_t twiddleCoef_64_q31[96];
|
||||
extern const q31_t twiddleCoef_128_q31[192];
|
||||
extern const q31_t twiddleCoef_256_q31[384];
|
||||
extern const q31_t twiddleCoef_512_q31[768];
|
||||
extern const q31_t twiddleCoef_1024_q31[1536];
|
||||
extern const q31_t twiddleCoef_2048_q31[3072];
|
||||
extern const q31_t twiddleCoef_4096_q31[6144];
|
||||
extern const q15_t twiddleCoef_16_q15[24];
|
||||
extern const q15_t twiddleCoef_32_q15[48];
|
||||
extern const q15_t twiddleCoef_64_q15[96];
|
||||
extern const q15_t twiddleCoef_128_q15[192];
|
||||
extern const q15_t twiddleCoef_256_q15[384];
|
||||
extern const q15_t twiddleCoef_512_q15[768];
|
||||
extern const q15_t twiddleCoef_1024_q15[1536];
|
||||
extern const q15_t twiddleCoef_2048_q15[3072];
|
||||
extern const q15_t twiddleCoef_4096_q15[6144];
|
||||
extern const float32_t twiddleCoef_rfft_32[32];
|
||||
extern const float32_t twiddleCoef_rfft_64[64];
|
||||
extern const float32_t twiddleCoef_rfft_128[128];
|
||||
extern const float32_t twiddleCoef_rfft_256[256];
|
||||
extern const float32_t twiddleCoef_rfft_512[512];
|
||||
extern const float32_t twiddleCoef_rfft_1024[1024];
|
||||
extern const float32_t twiddleCoef_rfft_2048[2048];
|
||||
extern const float32_t twiddleCoef_rfft_4096[4096];
|
||||
extern const float32_t twiddleCoef_rfft_8192[8192];
|
||||
|
||||
extern const q15_t twiddleCoef_fast_16_q15[24];
|
||||
extern const q15_t twiddleCoef_fast_32_q15[56];
|
||||
extern const q15_t twiddleCoef_fast_64_q15[120];
|
||||
extern const q15_t twiddleCoef_fast_128_q15[248];
|
||||
extern const q15_t twiddleCoef_fast_256_q15[504];
|
||||
extern const q15_t twiddleCoef_fast_512_q15[1016];
|
||||
extern const q15_t twiddleCoef_fast_1024_q15[2040];
|
||||
extern const q15_t twiddleCoef_fast_2048_q15[4088];
|
||||
extern const q15_t twiddleCoef_fast_4096_q15[8184];
|
||||
|
||||
extern const q31_t twiddleCoef_fast_16_q31[24];
|
||||
extern const q31_t twiddleCoef_fast_32_q31[56];
|
||||
extern const q31_t twiddleCoef_fast_64_q31[120];
|
||||
extern const q31_t twiddleCoef_fast_128_q31[248];
|
||||
extern const q31_t twiddleCoef_fast_256_q31[504];
|
||||
extern const q31_t twiddleCoef_fast_512_q31[1016];
|
||||
extern const q31_t twiddleCoef_fast_1024_q31[2040];
|
||||
extern const q31_t twiddleCoef_fast_2048_q31[4088];
|
||||
extern const q31_t twiddleCoef_fast_4096_q31[8184];
|
||||
|
||||
extern const uint32_t twiddleCoef_fast_16[24];
|
||||
extern const uint32_t twiddleCoef_fast_32[56];
|
||||
extern const uint32_t twiddleCoef_fast_64[120];
|
||||
extern const uint32_t twiddleCoef_fast_128[248];
|
||||
extern const uint32_t twiddleCoef_fast_256[504];
|
||||
extern const uint32_t twiddleCoef_fast_512[1016];
|
||||
extern const uint32_t twiddleCoef_fast_1024[2040];
|
||||
extern const uint32_t twiddleCoef_fast_2048[4088];
|
||||
extern const uint32_t twiddleCoef_fast_4096[8184];
|
||||
|
||||
extern const q15_t realCoefAQ15_8192[8192];
|
||||
extern const q31_t realCoefAQ31_8192[8192];
|
||||
extern const q15_t realCoefBQ15_8192[8192];
|
||||
extern const q31_t realCoefBQ31_8192[8192];
|
||||
|
||||
/*Tables for RFFT.*/
|
||||
extern const q15_t ALIGN4 realCoefAQ15_32[32];
|
||||
extern const q15_t ALIGN4 realCoefAQ15_64[64];
|
||||
extern const q15_t ALIGN4 realCoefAQ15_128[128];
|
||||
extern const q15_t ALIGN4 realCoefAQ15_256[256];
|
||||
extern const q15_t ALIGN4 realCoefAQ15_512[512];
|
||||
extern const q15_t ALIGN4 realCoefAQ15_1024[1024];
|
||||
extern const q15_t ALIGN4 realCoefAQ15_2048[2048];
|
||||
extern const q15_t ALIGN4 realCoefAQ15_4096[4096];
|
||||
|
||||
extern const q15_t ALIGN4 realCoefBQ15_32[32];
|
||||
extern const q15_t ALIGN4 realCoefBQ15_64[64];
|
||||
extern const q15_t ALIGN4 realCoefBQ15_128[128];
|
||||
extern const q15_t ALIGN4 realCoefBQ15_256[256];
|
||||
extern const q15_t ALIGN4 realCoefBQ15_512[512];
|
||||
extern const q15_t ALIGN4 realCoefBQ15_1024[1024];
|
||||
extern const q15_t ALIGN4 realCoefBQ15_2048[2048];
|
||||
extern const q15_t ALIGN4 realCoefBQ15_4096[4096];
|
||||
|
||||
extern const q31_t realCoefAQ31_32[32];
|
||||
extern const q31_t realCoefAQ31_64[64];
|
||||
extern const q31_t realCoefAQ31_128[128];
|
||||
extern const q31_t realCoefAQ31_256[256];
|
||||
extern const q31_t realCoefAQ31_512[512];
|
||||
extern const q31_t realCoefAQ31_1024[1024];
|
||||
extern const q31_t realCoefAQ31_2048[2048];
|
||||
extern const q31_t realCoefAQ31_4096[4096];
|
||||
|
||||
extern const q31_t realCoefBQ31_32[32];
|
||||
extern const q31_t realCoefBQ31_64[64];
|
||||
extern const q31_t realCoefBQ31_128[128];
|
||||
extern const q31_t realCoefBQ31_256[256];
|
||||
extern const q31_t realCoefBQ31_512[512];
|
||||
extern const q31_t realCoefBQ31_1024[1024];
|
||||
extern const q31_t realCoefBQ31_2048[2048];
|
||||
extern const q31_t realCoefBQ31_4096[4096];
|
||||
|
||||
|
||||
extern const float32_t realCoefA[8192];
|
||||
extern const float32_t realCoefB[8192];
|
||||
|
||||
extern const csi_cfft_instance_q15 csi_cfft_fast_sR_q15_len16;
|
||||
extern const csi_cfft_instance_q15 csi_cfft_fast_sR_q15_len32;
|
||||
extern const csi_cfft_instance_q15 csi_cfft_fast_sR_q15_len64;
|
||||
extern const csi_cfft_instance_q15 csi_cfft_fast_sR_q15_len128;
|
||||
extern const csi_cfft_instance_q15 csi_cfft_fast_sR_q15_len256;
|
||||
extern const csi_cfft_instance_q15 csi_cfft_fast_sR_q15_len512;
|
||||
extern const csi_cfft_instance_q15 csi_cfft_fast_sR_q15_len1024;
|
||||
extern const csi_cfft_instance_q15 csi_cfft_fast_sR_q15_len2048;
|
||||
extern const csi_cfft_instance_q15 csi_cfft_fast_sR_q15_len4096;
|
||||
|
||||
extern const csi_cfft_instance_q31 csi_cfft_fast_sR_q31_len16;
|
||||
extern const csi_cfft_instance_q31 csi_cfft_fast_sR_q31_len32;
|
||||
extern const csi_cfft_instance_q31 csi_cfft_fast_sR_q31_len64;
|
||||
extern const csi_cfft_instance_q31 csi_cfft_fast_sR_q31_len128;
|
||||
extern const csi_cfft_instance_q31 csi_cfft_fast_sR_q31_len256;
|
||||
extern const csi_cfft_instance_q31 csi_cfft_fast_sR_q31_len512;
|
||||
extern const csi_cfft_instance_q31 csi_cfft_fast_sR_q31_len1024;
|
||||
extern const csi_cfft_instance_q31 csi_cfft_fast_sR_q31_len2048;
|
||||
extern const csi_cfft_instance_q31 csi_cfft_fast_sR_q31_len4096;
|
||||
|
||||
extern csi_rfft_fast_instance_q15 csi_rfft_fast_sR_q15_len32;
|
||||
extern csi_rfft_fast_instance_q15 csi_rfft_fast_sR_q15_len64;
|
||||
extern csi_rfft_fast_instance_q15 csi_rfft_fast_sR_q15_len128;
|
||||
extern csi_rfft_fast_instance_q15 csi_rfft_fast_sR_q15_len256;
|
||||
extern csi_rfft_fast_instance_q15 csi_rfft_fast_sR_q15_len512;
|
||||
extern csi_rfft_fast_instance_q15 csi_rfft_fast_sR_q15_len1024;
|
||||
extern csi_rfft_fast_instance_q15 csi_rfft_fast_sR_q15_len2048;
|
||||
extern csi_rfft_fast_instance_q15 csi_rfft_fast_sR_q15_len4096;
|
||||
extern csi_rfft_fast_instance_q15 csi_rfft_fast_sR_q15_len8192;
|
||||
|
||||
extern csi_rfft_fast_instance_q15 csi_inv_rfft_fast_sR_q15_len32;
|
||||
extern csi_rfft_fast_instance_q15 csi_inv_rfft_fast_sR_q15_len64;
|
||||
extern csi_rfft_fast_instance_q15 csi_inv_rfft_fast_sR_q15_len128;
|
||||
extern csi_rfft_fast_instance_q15 csi_inv_rfft_fast_sR_q15_len256;
|
||||
extern csi_rfft_fast_instance_q15 csi_inv_rfft_fast_sR_q15_len512;
|
||||
extern csi_rfft_fast_instance_q15 csi_inv_rfft_fast_sR_q15_len1024;
|
||||
extern csi_rfft_fast_instance_q15 csi_inv_rfft_fast_sR_q15_len2048;
|
||||
extern csi_rfft_fast_instance_q15 csi_inv_rfft_fast_sR_q15_len4096;
|
||||
extern csi_rfft_fast_instance_q15 csi_inv_rfft_fast_sR_q15_len8192;
|
||||
|
||||
extern csi_rfft_fast_instance_q31 csi_rfft_fast_sR_q31_len32;
|
||||
extern csi_rfft_fast_instance_q31 csi_rfft_fast_sR_q31_len64;
|
||||
extern csi_rfft_fast_instance_q31 csi_rfft_fast_sR_q31_len128;
|
||||
extern csi_rfft_fast_instance_q31 csi_rfft_fast_sR_q31_len256;
|
||||
extern csi_rfft_fast_instance_q31 csi_rfft_fast_sR_q31_len512;
|
||||
extern csi_rfft_fast_instance_q31 csi_rfft_fast_sR_q31_len1024;
|
||||
extern csi_rfft_fast_instance_q31 csi_rfft_fast_sR_q31_len2048;
|
||||
extern csi_rfft_fast_instance_q31 csi_rfft_fast_sR_q31_len4096;
|
||||
extern csi_rfft_fast_instance_q31 csi_rfft_fast_sR_q31_len8192;
|
||||
|
||||
extern csi_rfft_fast_instance_q31 csi_inv_rfft_fast_sR_q31_len32;
|
||||
extern csi_rfft_fast_instance_q31 csi_inv_rfft_fast_sR_q31_len64;
|
||||
extern csi_rfft_fast_instance_q31 csi_inv_rfft_fast_sR_q31_len128;
|
||||
extern csi_rfft_fast_instance_q31 csi_inv_rfft_fast_sR_q31_len256;
|
||||
extern csi_rfft_fast_instance_q31 csi_inv_rfft_fast_sR_q31_len512;
|
||||
extern csi_rfft_fast_instance_q31 csi_inv_rfft_fast_sR_q31_len1024;
|
||||
extern csi_rfft_fast_instance_q31 csi_inv_rfft_fast_sR_q31_len2048;
|
||||
extern csi_rfft_fast_instance_q31 csi_inv_rfft_fast_sR_q31_len4096;
|
||||
extern csi_rfft_fast_instance_q31 csi_inv_rfft_fast_sR_q31_len8192;
|
||||
|
||||
extern csi_dct4_fast_instance_q15 csi_dct4_fast_sR_q15_len128;
|
||||
extern csi_dct4_fast_instance_q15 csi_dct4_fast_sR_q15_len512;
|
||||
extern csi_dct4_fast_instance_q15 csi_dct4_fast_sR_q15_len2048;
|
||||
extern csi_dct4_fast_instance_q15 csi_dct4_fast_sR_q15_len8192;
|
||||
|
||||
extern csi_dct4_fast_instance_q31 csi_dct4_fast_sR_q31_len128;
|
||||
extern csi_dct4_fast_instance_q31 csi_dct4_fast_sR_q31_len512;
|
||||
extern csi_dct4_fast_instance_q31 csi_dct4_fast_sR_q31_len2048;
|
||||
extern csi_dct4_fast_instance_q31 csi_dct4_fast_sR_q31_len8192;
|
||||
|
||||
/*Tables for DCT4*/
|
||||
#ifndef CSI_OPT_WEIGHT
|
||||
extern const q15_t ALIGN4 WeightsQ15_128[256];
|
||||
extern const q15_t ALIGN4 WeightsQ15_512[1024];
|
||||
extern const q15_t ALIGN4 WeightsQ15_2048[4096];
|
||||
extern const q15_t ALIGN4 WeightsQ15_8192[16384];
|
||||
#else
|
||||
extern const q15_t ALIGN4 WeightsQ15_128[128+2];
|
||||
extern const q15_t ALIGN4 WeightsQ15_512[512+2];
|
||||
extern const q15_t ALIGN4 WeightsQ15_2048[2048+2];
|
||||
extern const q15_t ALIGN4 WeightsQ15_8192[8192+2];
|
||||
#endif
|
||||
extern const q15_t ALIGN4 cos_factorsQ15_128[128];
|
||||
extern const q15_t ALIGN4 cos_factorsQ15_512[512];
|
||||
extern const q15_t ALIGN4 cos_factorsQ15_2048[2048];
|
||||
extern const q15_t ALIGN4 cos_factorsQ15_8192[8192];
|
||||
|
||||
#ifndef CSI_OPT_WEIGHT
|
||||
extern const q31_t WeightsQ31_128[256];
|
||||
extern const q31_t WeightsQ31_512[1024];
|
||||
extern const q31_t WeightsQ31_2048[4096];
|
||||
extern const q31_t WeightsQ31_8192[16384];
|
||||
#else
|
||||
extern const q31_t WeightsQ31_128[128+2];
|
||||
extern const q31_t WeightsQ31_512[512+2];
|
||||
extern const q31_t WeightsQ31_2048[2048+2];
|
||||
extern const q31_t WeightsQ31_8192[8192+2];
|
||||
#endif
|
||||
|
||||
extern const q31_t cos_factorsQ31_128[128];
|
||||
extern const q31_t cos_factorsQ31_512[512];
|
||||
extern const q31_t cos_factorsQ31_2048[2048];
|
||||
extern const q31_t cos_factorsQ31_8192[8192];
|
||||
|
||||
#ifndef CSI_OPT_WEIGHT
|
||||
extern const float32_t Weights_128[256];
|
||||
extern const float32_t Weights_512[1024];
|
||||
extern const float32_t Weights_2048[4096];
|
||||
extern const float32_t Weights_8192[16384];
|
||||
|
||||
#else
|
||||
extern const float32_t Weights_128[128+2];
|
||||
extern const float32_t Weights_512[512+2];
|
||||
extern const float32_t Weights_2048[2048+2];
|
||||
extern const float32_t Weights_8192[8192+2];
|
||||
#endif
|
||||
extern const float32_t cos_factors_128[128];
|
||||
extern const float32_t cos_factors_512[512];
|
||||
extern const float32_t cos_factors_2048[2048];
|
||||
extern const float32_t cos_factors_8192[8192];
|
||||
|
||||
/* floating-point bit reversal tables */
|
||||
#define CSIBITREVINDEXTABLE_16_TABLE_LENGTH ((uint16_t)20 )
|
||||
#define CSIBITREVINDEXTABLE_32_TABLE_LENGTH ((uint16_t)48 )
|
||||
#define CSIBITREVINDEXTABLE_64_TABLE_LENGTH ((uint16_t)56 )
|
||||
#define CSIBITREVINDEXTABLE_128_TABLE_LENGTH ((uint16_t)208 )
|
||||
#define CSIBITREVINDEXTABLE_256_TABLE_LENGTH ((uint16_t)440 )
|
||||
#define CSIBITREVINDEXTABLE_512_TABLE_LENGTH ((uint16_t)448 )
|
||||
#define CSIBITREVINDEXTABLE_1024_TABLE_LENGTH ((uint16_t)1800)
|
||||
#define CSIBITREVINDEXTABLE_2048_TABLE_LENGTH ((uint16_t)3808)
|
||||
#define CSIBITREVINDEXTABLE_4096_TABLE_LENGTH ((uint16_t)4032)
|
||||
|
||||
extern const uint16_t csiBitRevIndexTable16[CSIBITREVINDEXTABLE_16_TABLE_LENGTH];
|
||||
extern const uint16_t csiBitRevIndexTable32[CSIBITREVINDEXTABLE_32_TABLE_LENGTH];
|
||||
extern const uint16_t csiBitRevIndexTable64[CSIBITREVINDEXTABLE_64_TABLE_LENGTH];
|
||||
extern const uint16_t csiBitRevIndexTable128[CSIBITREVINDEXTABLE_128_TABLE_LENGTH];
|
||||
extern const uint16_t csiBitRevIndexTable256[CSIBITREVINDEXTABLE_256_TABLE_LENGTH];
|
||||
extern const uint16_t csiBitRevIndexTable512[CSIBITREVINDEXTABLE_512_TABLE_LENGTH];
|
||||
extern const uint16_t csiBitRevIndexTable1024[CSIBITREVINDEXTABLE_1024_TABLE_LENGTH];
|
||||
extern const uint16_t csiBitRevIndexTable2048[CSIBITREVINDEXTABLE_2048_TABLE_LENGTH];
|
||||
extern const uint16_t csiBitRevIndexTable4096[CSIBITREVINDEXTABLE_4096_TABLE_LENGTH];
|
||||
|
||||
/* fixed-point bit reversal tables */
|
||||
#define CSIBITREVINDEXTABLE_FIXED_16_TABLE_LENGTH ((uint16_t)12 )
|
||||
#define CSIBITREVINDEXTABLE_FIXED_32_TABLE_LENGTH ((uint16_t)24 )
|
||||
#define CSIBITREVINDEXTABLE_FIXED_64_TABLE_LENGTH ((uint16_t)56 )
|
||||
#define CSIBITREVINDEXTABLE_FIXED_128_TABLE_LENGTH ((uint16_t)112 )
|
||||
#define CSIBITREVINDEXTABLE_FIXED_256_TABLE_LENGTH ((uint16_t)240 )
|
||||
#define CSIBITREVINDEXTABLE_FIXED_512_TABLE_LENGTH ((uint16_t)480 )
|
||||
#define CSIBITREVINDEXTABLE_FIXED_1024_TABLE_LENGTH ((uint16_t)992 )
|
||||
#define CSIBITREVINDEXTABLE_FIXED_2048_TABLE_LENGTH ((uint16_t)1984)
|
||||
#define CSIBITREVINDEXTABLE_FIXED_4096_TABLE_LENGTH ((uint16_t)4032)
|
||||
|
||||
extern const uint16_t csiBitRevIndexTable_fixed_16[CSIBITREVINDEXTABLE_FIXED_16_TABLE_LENGTH];
|
||||
extern const uint16_t csiBitRevIndexTable_fixed_32[CSIBITREVINDEXTABLE_FIXED_32_TABLE_LENGTH];
|
||||
extern const uint16_t csiBitRevIndexTable_fixed_64[CSIBITREVINDEXTABLE_FIXED_64_TABLE_LENGTH];
|
||||
extern const uint16_t csiBitRevIndexTable_fixed_128[CSIBITREVINDEXTABLE_FIXED_128_TABLE_LENGTH];
|
||||
extern const uint16_t csiBitRevIndexTable_fixed_256[CSIBITREVINDEXTABLE_FIXED_256_TABLE_LENGTH];
|
||||
extern const uint16_t csiBitRevIndexTable_fixed_512[CSIBITREVINDEXTABLE_FIXED_512_TABLE_LENGTH];
|
||||
extern const uint16_t csiBitRevIndexTable_fixed_1024[CSIBITREVINDEXTABLE_FIXED_1024_TABLE_LENGTH];
|
||||
extern const uint16_t csiBitRevIndexTable_fixed_2048[CSIBITREVINDEXTABLE_FIXED_2048_TABLE_LENGTH];
|
||||
extern const uint16_t csiBitRevIndexTable_fixed_4096[CSIBITREVINDEXTABLE_FIXED_4096_TABLE_LENGTH];
|
||||
|
||||
/* Tables for Fast Math Sine and Cosine */
|
||||
extern const float32_t sinTable_f32[FAST_MATH_TABLE_SIZE + 1];
|
||||
extern const q31_t sinTable_q31[FAST_MATH_TABLE_SIZE + 1];
|
||||
extern const q15_t sinTable_q15[FAST_MATH_TABLE_SIZE + 1];
|
||||
|
||||
#endif /* CSI_COMMON_TABLES_H */
|
||||
157
csky/csi_dsp/include/csi_const_structs.h
Normal file
157
csky/csi_dsp/include/csi_const_structs.h
Normal file
@@ -0,0 +1,157 @@
|
||||
/*
|
||||
* Copyright (C) 2016-2020 T-head Limited. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/******************************************************************************
|
||||
* @file csi_const_structs.h
|
||||
* @brief Constant structs that are initialized for user convenience.
|
||||
* @version V1.0
|
||||
* @date Feb. 2020
|
||||
******************************************************************************/
|
||||
|
||||
|
||||
#ifndef _RISCV_CONST_STRUCTS_H
|
||||
#define _RISCV_CONST_STRUCTS_H
|
||||
|
||||
#include "csi_math.h"
|
||||
#include "csi_common_tables.h"
|
||||
|
||||
extern const csi_cfft_instance_f32 csi_cfft_radix4_fast_sR_f32_len16;
|
||||
extern const csi_cfft_instance_f32 csi_cfft_radix4_fast_sR_f32_len32;
|
||||
extern const csi_cfft_instance_f32 csi_cfft_radix4_fast_sR_f32_len64;
|
||||
extern const csi_cfft_instance_f32 csi_cfft_radix4_fast_sR_f32_len128;
|
||||
extern const csi_cfft_instance_f32 csi_cfft_radix4_fast_sR_f32_len256;
|
||||
extern const csi_cfft_instance_f32 csi_cfft_radix4_fast_sR_f32_len512;
|
||||
extern const csi_cfft_instance_f32 csi_cfft_radix4_fast_sR_f32_len1024;
|
||||
extern const csi_cfft_instance_f32 csi_cfft_radix4_fast_sR_f32_len2048;
|
||||
extern const csi_cfft_instance_f32 csi_cfft_radix4_fast_sR_f32_len4096;
|
||||
|
||||
extern const csi_cfft_instance_f32 csi_cfft_radix2_sR_f32_len16;
|
||||
extern const csi_cfft_instance_f32 csi_cfft_radix2_sR_f32_len32;
|
||||
extern const csi_cfft_instance_f32 csi_cfft_radix2_sR_f32_len64;
|
||||
extern const csi_cfft_instance_f32 csi_cfft_radix2_sR_f32_len128;
|
||||
extern const csi_cfft_instance_f32 csi_cfft_radix2_sR_f32_len256;
|
||||
extern const csi_cfft_instance_f32 csi_cfft_radix2_sR_f32_len512;
|
||||
extern const csi_cfft_instance_f32 csi_cfft_radix2_sR_f32_len1024;
|
||||
extern const csi_cfft_instance_f32 csi_cfft_radix2_sR_f32_len2048;
|
||||
extern const csi_cfft_instance_f32 csi_cfft_radix2_sR_f32_len4096;
|
||||
|
||||
extern const csi_cfft_instance_f32 csi_cfft_radix4_sR_f32_len16;
|
||||
extern const csi_cfft_instance_f32 csi_cfft_radix4_sR_f32_len32;
|
||||
extern const csi_cfft_instance_f32 csi_cfft_radix4_sR_f32_len64;
|
||||
extern const csi_cfft_instance_f32 csi_cfft_radix4_sR_f32_len128;
|
||||
extern const csi_cfft_instance_f32 csi_cfft_radix4_sR_f32_len256;
|
||||
extern const csi_cfft_instance_f32 csi_cfft_radix4_sR_f32_len512;
|
||||
extern const csi_cfft_instance_f32 csi_cfft_radix4_sR_f32_len1024;
|
||||
extern const csi_cfft_instance_f32 csi_cfft_radix4_sR_f32_len2048;
|
||||
extern const csi_cfft_instance_f32 csi_cfft_radix4_sR_f32_len4096;
|
||||
|
||||
extern const csi_cfft_instance_f32 csi_cfft_sR_f32_len16 ;
|
||||
extern const csi_cfft_instance_f32 csi_cfft_sR_f32_len32 ;
|
||||
extern const csi_cfft_instance_f32 csi_cfft_sR_f32_len64 ;
|
||||
extern const csi_cfft_instance_f32 csi_cfft_sR_f32_len128 ;
|
||||
extern const csi_cfft_instance_f32 csi_cfft_sR_f32_len256 ;
|
||||
extern const csi_cfft_instance_f32 csi_cfft_sR_f32_len512 ;
|
||||
extern const csi_cfft_instance_f32 csi_cfft_sR_f32_len1024 ;
|
||||
extern const csi_cfft_instance_f32 csi_cfft_sR_f32_len2048 ;
|
||||
extern const csi_cfft_instance_f32 csi_cfft_sR_f32_len4096 ;
|
||||
extern const csi_cfft_instance_q31 csi_cfft_sR_q31_len16 ;
|
||||
extern const csi_cfft_instance_q31 csi_cfft_sR_q31_len32 ;
|
||||
extern const csi_cfft_instance_q31 csi_cfft_sR_q31_len64 ;
|
||||
extern const csi_cfft_instance_q31 csi_cfft_sR_q31_len128 ;
|
||||
extern const csi_cfft_instance_q31 csi_cfft_sR_q31_len256 ;
|
||||
extern const csi_cfft_instance_q31 csi_cfft_sR_q31_len512 ;
|
||||
extern const csi_cfft_instance_q31 csi_cfft_sR_q31_len1024 ;
|
||||
extern const csi_cfft_instance_q31 csi_cfft_sR_q31_len2048 ;
|
||||
extern const csi_cfft_instance_q31 csi_cfft_sR_q31_len4096 ;
|
||||
extern const csi_cfft_instance_q15 csi_cfft_sR_q15_len16 ;
|
||||
extern const csi_cfft_instance_q15 csi_cfft_sR_q15_len32 ;
|
||||
extern const csi_cfft_instance_q15 csi_cfft_sR_q15_len64 ;
|
||||
extern const csi_cfft_instance_q15 csi_cfft_sR_q15_len128 ;
|
||||
extern const csi_cfft_instance_q15 csi_cfft_sR_q15_len256 ;
|
||||
extern const csi_cfft_instance_q15 csi_cfft_sR_q15_len512 ;
|
||||
extern const csi_cfft_instance_q15 csi_cfft_sR_q15_len1024 ;
|
||||
extern const csi_cfft_instance_q15 csi_cfft_sR_q15_len2048 ;
|
||||
extern const csi_cfft_instance_q15 csi_cfft_sR_q15_len4096 ;
|
||||
extern const csi_rfft_fast_instance_f32 csi_rfft_sR_f32_len32 ;
|
||||
extern const csi_rfft_fast_instance_f32 csi_rfft_sR_f32_len64 ;
|
||||
extern const csi_rfft_fast_instance_f32 csi_rfft_sR_f32_len128 ;
|
||||
extern const csi_rfft_fast_instance_f32 csi_rfft_sR_f32_len256 ;
|
||||
extern const csi_rfft_fast_instance_f32 csi_rfft_sR_f32_len512 ;
|
||||
extern const csi_rfft_fast_instance_f32 csi_rfft_sR_f32_len1024 ;
|
||||
extern const csi_rfft_fast_instance_f32 csi_rfft_sR_f32_len2048 ;
|
||||
extern const csi_rfft_fast_instance_f32 csi_rfft_sR_f32_len4096 ;
|
||||
extern const csi_rfft_fast_instance_f32 csi_rfft_sR_f32_len8192 ;
|
||||
extern const csi_rfft_instance_q31 csi_rfft_sR_q31_len32 ;
|
||||
extern const csi_rfft_instance_q31 csi_rfft_sR_q31_len64 ;
|
||||
extern const csi_rfft_instance_q31 csi_rfft_sR_q31_len128 ;
|
||||
extern const csi_rfft_instance_q31 csi_rfft_sR_q31_len256 ;
|
||||
extern const csi_rfft_instance_q31 csi_rfft_sR_q31_len512 ;
|
||||
extern const csi_rfft_instance_q31 csi_rfft_sR_q31_len1024 ;
|
||||
extern const csi_rfft_instance_q31 csi_rfft_sR_q31_len2048 ;
|
||||
extern const csi_rfft_instance_q31 csi_rfft_sR_q31_len4096 ;
|
||||
extern const csi_rfft_instance_q31 csi_rfft_sR_q31_len8192 ;
|
||||
extern const csi_rfft_instance_q15 csi_rfft_sR_q15_len32 ;
|
||||
extern const csi_rfft_instance_q15 csi_rfft_sR_q15_len64 ;
|
||||
extern const csi_rfft_instance_q15 csi_rfft_sR_q15_len128 ;
|
||||
extern const csi_rfft_instance_q15 csi_rfft_sR_q15_len256 ;
|
||||
extern const csi_rfft_instance_q15 csi_rfft_sR_q15_len512 ;
|
||||
extern const csi_rfft_instance_q15 csi_rfft_sR_q15_len1024 ;
|
||||
extern const csi_rfft_instance_q15 csi_rfft_sR_q15_len2048 ;
|
||||
extern const csi_rfft_instance_q15 csi_rfft_sR_q15_len4096 ;
|
||||
extern const csi_rfft_instance_q15 csi_rfft_sR_q15_len8192 ;
|
||||
extern const csi_rfft_instance_f32 csi_inv_rfft_sR_f32_len32;
|
||||
extern const csi_rfft_instance_f32 csi_inv_rfft_sR_f32_len64;
|
||||
extern const csi_rfft_instance_f32 csi_inv_rfft_sR_f32_len128;
|
||||
extern const csi_rfft_instance_f32 csi_inv_rfft_sR_f32_len256;
|
||||
extern const csi_rfft_instance_f32 csi_inv_rfft_sR_f32_len512;
|
||||
extern const csi_rfft_instance_f32 csi_inv_rfft_sR_f32_len1024;
|
||||
extern const csi_rfft_instance_f32 csi_inv_rfft_sR_f32_len2048;
|
||||
extern const csi_rfft_instance_f32 csi_inv_rfft_sR_f32_len4096;
|
||||
extern const csi_rfft_instance_f32 csi_inv_rfft_sR_f32_len8192;
|
||||
extern const csi_rfft_instance_q31 csi_inv_rfft_sR_q31_len32;
|
||||
extern const csi_rfft_instance_q31 csi_inv_rfft_sR_q31_len64;
|
||||
extern const csi_rfft_instance_q31 csi_inv_rfft_sR_q31_len128;
|
||||
extern const csi_rfft_instance_q31 csi_inv_rfft_sR_q31_len256;
|
||||
extern const csi_rfft_instance_q31 csi_inv_rfft_sR_q31_len512;
|
||||
extern const csi_rfft_instance_q31 csi_inv_rfft_sR_q31_len1024;
|
||||
extern const csi_rfft_instance_q31 csi_inv_rfft_sR_q31_len2048;
|
||||
extern const csi_rfft_instance_q31 csi_inv_rfft_sR_q31_len4096;
|
||||
extern const csi_rfft_instance_q31 csi_inv_rfft_sR_q31_len8192;
|
||||
extern const csi_rfft_instance_q15 csi_inv_rfft_sR_q15_len32;
|
||||
extern const csi_rfft_instance_q15 csi_inv_rfft_sR_q15_len64;
|
||||
extern const csi_rfft_instance_q15 csi_inv_rfft_sR_q15_len128;
|
||||
extern const csi_rfft_instance_q15 csi_inv_rfft_sR_q15_len256;
|
||||
extern const csi_rfft_instance_q15 csi_inv_rfft_sR_q15_len512;
|
||||
extern const csi_rfft_instance_q15 csi_inv_rfft_sR_q15_len1024;
|
||||
extern const csi_rfft_instance_q15 csi_inv_rfft_sR_q15_len2048;
|
||||
extern const csi_rfft_instance_q15 csi_inv_rfft_sR_q15_len4096;
|
||||
extern const csi_rfft_instance_q15 csi_inv_rfft_sR_q15_len8192;
|
||||
extern const csi_dct4_instance_q31 csi_dct4_sR_q31_len128;
|
||||
extern const csi_dct4_instance_q31 csi_dct4_sR_q31_len512;
|
||||
extern const csi_dct4_instance_q31 csi_dct4_sR_q31_len2048;
|
||||
extern const csi_dct4_instance_q31 csi_dct4_sR_q31_len8192;
|
||||
extern const csi_dct4_instance_q15 csi_dct4_sR_q15_len128;
|
||||
extern const csi_dct4_instance_q15 csi_dct4_sR_q15_len512;
|
||||
extern const csi_dct4_instance_q15 csi_dct4_sR_q15_len2048;
|
||||
extern const csi_dct4_instance_q15 csi_dct4_sR_q15_len8192;
|
||||
extern const csi_dct4_instance_f32 csi_dct4_sR_f32_len128;
|
||||
extern const csi_dct4_instance_f32 csi_dct4_sR_f32_len512;
|
||||
extern const csi_dct4_instance_f32 csi_dct4_sR_f32_len2048;
|
||||
extern const csi_dct4_instance_f32 csi_dct4_sR_f32_len8192;
|
||||
|
||||
#endif
|
||||
1879
csky/csi_dsp/include/csi_instance.h
Normal file
1879
csky/csi_dsp/include/csi_instance.h
Normal file
File diff suppressed because it is too large
Load Diff
5739
csky/csi_dsp/include/csi_math.h
Normal file
5739
csky/csi_dsp/include/csi_math.h
Normal file
File diff suppressed because it is too large
Load Diff
54
csky/csi_dsp/include/csi_nn_tables.h
Normal file
54
csky/csi_dsp/include/csi_nn_tables.h
Normal file
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright (C) 2016-2019 C-SKY Limited. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
* Title: csky_nn_tables.h
|
||||
* Description: Extern declaration for NN tables
|
||||
* -------------------------------------------------------------------- */
|
||||
|
||||
#ifndef _CSI_NN_TABLES_H
|
||||
#define _CSI_NN_TABLES_H
|
||||
|
||||
#include "csi_instance.h"
|
||||
|
||||
/**
|
||||
* @brief tables for various activation functions
|
||||
*
|
||||
*/
|
||||
|
||||
extern const q15_t sigmoidTable_q15[256];
|
||||
extern const q7_t sigmoidTable_q7[256];
|
||||
|
||||
extern const q7_t tanhTable_q7[256];
|
||||
extern const q15_t tanhTable_q15[256];
|
||||
|
||||
/**
|
||||
* @brief 2-way tables for various activation functions
|
||||
*
|
||||
* 2-way table, H table for value larger than 1/4
|
||||
* L table for value smaller than 1/4, H table for remaining
|
||||
* We have this only for the q15_t version. It does not make
|
||||
* sense to have it for q7_t type
|
||||
*/
|
||||
extern const q15_t sigmoidHTable_q15[192];
|
||||
extern const q15_t sigmoidLTable_q15[128];
|
||||
|
||||
extern const q15_t sigmoidLTable_q15[128];
|
||||
extern const q15_t sigmoidHTable_q15[192];
|
||||
|
||||
#endif /* CSI_NN_TABLES_H */
|
||||
552
csky/csi_dsp/include/csi_nnfunctions.h
Normal file
552
csky/csi_dsp/include/csi_nnfunctions.h
Normal file
@@ -0,0 +1,552 @@
|
||||
/*
|
||||
* Copyright (C) 2016-2019 C-SKY Limited. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
* Title: csi_nnfunctions.h
|
||||
* Description: Public header file for CSI NN Library
|
||||
*
|
||||
* -------------------------------------------------------------------- */
|
||||
|
||||
#ifndef _CSI_NNFUNCTIONS_H
|
||||
#define _CSI_NNFUNCTIONS_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#ifdef CSI_MATH_DSP
|
||||
#include "csi_instance.h"
|
||||
#include "csi_nnsupportfunctions.h"
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Struct for specifying activation function types
|
||||
*
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
CSKY_SIGMOID = 0, /**< Sigmoid activation function */
|
||||
CSKY_TANH = 1, /**< Tanh activation function */
|
||||
} csi_nn_activation_type;
|
||||
|
||||
/**
|
||||
* @brief Basic Q7 convolution function
|
||||
* @param[in] Im_in pointer to input tensor
|
||||
* @param[in] dim_im_in input tensor dimention
|
||||
* @param[in] ch_im_in number of input tensor channels
|
||||
* @param[in] wt pointer to kernel weights
|
||||
* @param[in] ch_im_out number of filters, i.e., output tensor channels
|
||||
* @param[in] dim_kernel filter kernel size
|
||||
* @param[in] padding padding sizes
|
||||
* @param[in] stride convolution stride
|
||||
* @param[in] bias pointer to bias
|
||||
* @param[in] bias_shift amount of left-shift for bias
|
||||
* @param[in] out_shift amount of right-shift for output
|
||||
* @param[in,out] Im_out pointer to output tensor
|
||||
* @param[in] dim_im_out output tensor dimension
|
||||
* @param[in,out] bufferA pointer to buffer space for input
|
||||
* @return none.
|
||||
*
|
||||
*/
|
||||
|
||||
void csi_convolve_HWC_q7_basic(const q7_t * Im_in,
|
||||
const uint16_t dim_im_in,
|
||||
const uint16_t ch_im_in,
|
||||
const q7_t * wt,
|
||||
const uint16_t ch_im_out,
|
||||
const uint16_t dim_kernel,
|
||||
const uint16_t padding,
|
||||
const uint16_t stride,
|
||||
const q7_t * bias,
|
||||
const uint16_t bias_shift,
|
||||
const uint16_t out_shift,
|
||||
q7_t * Im_out,
|
||||
const uint16_t dim_im_out,
|
||||
q15_t * bufferA);
|
||||
|
||||
/**
|
||||
* @brief Basic Q15 convolution function
|
||||
* @param[in] Im_in pointer to input tensor
|
||||
* @param[in] dim_im_in input tensor dimention
|
||||
* @param[in] ch_im_in number of input tensor channels
|
||||
* @param[in] wt pointer to kernel weights
|
||||
* @param[in] ch_im_out number of filters, i.e., output tensor channels
|
||||
* @param[in] dim_kernel filter kernel size
|
||||
* @param[in] padding padding sizes
|
||||
* @param[in] stride convolution stride
|
||||
* @param[in] bias pointer to bias
|
||||
* @param[in] bias_shift amount of left-shift for bias
|
||||
* @param[in] out_shift amount of right-shift for output
|
||||
* @param[in,out] Im_out pointer to output tensor
|
||||
* @param[in] dim_im_out output tensor dimension
|
||||
* @param[in,out] bufferA pointer to buffer space for input
|
||||
* @return none.
|
||||
*
|
||||
*/
|
||||
|
||||
void csi_convolve_HWC_q15_basic(const q15_t * Im_in,
|
||||
const uint16_t dim_im_in,
|
||||
const uint16_t ch_im_in,
|
||||
const q15_t * wt,
|
||||
const uint16_t ch_im_out,
|
||||
const uint16_t dim_kernel,
|
||||
const uint16_t padding,
|
||||
const uint16_t stride,
|
||||
const q15_t * bias,
|
||||
const uint16_t bias_shift,
|
||||
const uint16_t out_shift,
|
||||
q15_t * Im_out,
|
||||
const uint16_t dim_im_out,
|
||||
q15_t * bufferA);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Fast Q7 convolution function (non-sqaure shape)
|
||||
* @param[in] Im_in pointer to input tensor
|
||||
* @param[in] dim_im_in_x input tensor dimention x
|
||||
* @param[in] dim_im_in_y input tensor dimention y
|
||||
* @param[in] ch_im_in number of input tensor channels
|
||||
* @param[in] wt pointer to kernel weights
|
||||
* @param[in] ch_im_out number of filters, i.e., output tensor channels
|
||||
* @param[in] dim_kernel_x filter kernel size x
|
||||
* @param[in] dim_kernel_y filter kernel size y
|
||||
* @param[in] padding_x padding size x
|
||||
* @param[in] padding_y padding size y
|
||||
* @param[in] stride_x convolution stride x
|
||||
* @param[in] stride_y convolution stride y
|
||||
* @param[in] bias pointer to bias
|
||||
* @param[in] bias_shift amount of left-shift for bias
|
||||
* @param[in] out_shift amount of right-shift for output
|
||||
* @param[in,out] Im_out pointer to output tensor
|
||||
* @param[in] dim_im_out_x output tensor dimension x
|
||||
* @param[in] dim_im_out_y output tensor dimension y
|
||||
* @param[in,out] bufferA pointer to buffer space for input
|
||||
* @return none.
|
||||
*
|
||||
* This function is the version with full list of optimization tricks, but with
|
||||
* some contraints:
|
||||
* ch_im_in is multiple of 4
|
||||
* ch_im_out is multiple of 2
|
||||
*/
|
||||
|
||||
void csi_convolve_HWC_q7_fast_nonsquare(const q7_t * Im_in,
|
||||
const uint16_t dim_im_in_x,
|
||||
const uint16_t dim_im_in_y,
|
||||
const uint16_t ch_im_in,
|
||||
const q7_t * wt,
|
||||
const uint16_t ch_im_out,
|
||||
const uint16_t dim_kernel_x,
|
||||
const uint16_t dim_kernel_y,
|
||||
const uint16_t padding_x,
|
||||
const uint16_t padding_y,
|
||||
const uint16_t stride_x,
|
||||
const uint16_t stride_y,
|
||||
const q7_t * bias,
|
||||
const uint16_t bias_shift,
|
||||
const uint16_t out_shift,
|
||||
q7_t * Im_out,
|
||||
const uint16_t dim_im_out_x,
|
||||
const uint16_t dim_im_out_y,
|
||||
q15_t * bufferA);
|
||||
|
||||
/**
|
||||
* @brief Fast Q7 version of 1x1 convolution (non-sqaure shape)
|
||||
* @param[in] Im_in pointer to input tensor
|
||||
* @param[in] dim_im_in_x input tensor dimention x
|
||||
* @param[in] dim_im_in_y input tensor dimention y
|
||||
* @param[in] ch_im_in number of input tensor channels
|
||||
* @param[in] wt pointer to kernel weights
|
||||
* @param[in] ch_im_out number of filters, i.e., output tensor channels
|
||||
* @param[in] dim_kernel_x filter kernel size x
|
||||
* @param[in] dim_kernel_y filter kernel size y
|
||||
* @param[in] padding_x padding size x
|
||||
* @param[in] padding_y padding size y
|
||||
* @param[in] stride_x convolution stride x
|
||||
* @param[in] stride_y convolution stride y
|
||||
* @param[in] bias pointer to bias
|
||||
* @param[in] bias_shift amount of left-shift for bias
|
||||
* @param[in] out_shift amount of right-shift for output
|
||||
* @param[in,out] Im_out pointer to output tensor
|
||||
* @param[in] dim_im_out_x output tensor dimension x
|
||||
* @param[in] dim_im_out_y output tensor dimension y
|
||||
* @param[in,out] bufferA pointer to buffer space for input
|
||||
* @return none.
|
||||
*
|
||||
* This function implement convolution with 1x1 kernel size (i.e., dim_kernel_x=1
|
||||
* and dim_kernel_y=1). It can be used for
|
||||
* second half of MobileNets after depthwise separable convolution.
|
||||
*
|
||||
* This function is the version with full list of optimization tricks, but with
|
||||
* some contraints:
|
||||
* ch_im_in is multiple of 4
|
||||
* ch_im_out is multiple of 2
|
||||
*/
|
||||
void csi_convolve_1x1_HWC_q7_fast(const q7_t * Im_in,
|
||||
const uint16_t dim_im_in_x,
|
||||
const uint16_t dim_im_in_y,
|
||||
const uint16_t ch_im_in,
|
||||
const q7_t * wt,
|
||||
const uint16_t ch_im_out,
|
||||
const q7_t * bias,
|
||||
const uint16_t bias_shift,
|
||||
const uint16_t out_shift,
|
||||
q7_t * Im_out,
|
||||
const uint16_t dim_im_out_x,
|
||||
const uint16_t dim_im_out_y,
|
||||
q15_t * bufferA);
|
||||
|
||||
/**
|
||||
* @brief Q7 version of convolution for RGB image
|
||||
* @param[in] Im_in pointer to input tensor
|
||||
* @param[in] dim_im_in input tensor dimention
|
||||
* @param[in] ch_im_in number of input tensor channels
|
||||
* @param[in] wt pointer to kernel weights
|
||||
* @param[in] ch_im_out number of filters, i.e., output tensor channels
|
||||
* @param[in] dim_kernel filter kernel size
|
||||
* @param[in] padding padding sizes
|
||||
* @param[in] stride convolution stride
|
||||
* @param[in] bias pointer to bias
|
||||
* @param[in] bias_shift amount of left-shift for bias
|
||||
* @param[in] out_shift amount of right-shift for output
|
||||
* @param[in,out] Im_out pointer to output tensor
|
||||
* @param[in] dim_im_out output tensor dimension
|
||||
* @param[in,out] bufferA pointer to buffer space for input
|
||||
* @return none.
|
||||
*
|
||||
* This kernel is written exclusively for convolution with ch_im_in
|
||||
* equals 3. This applies on the first layer of CNNs which has input
|
||||
* image with RGB format.
|
||||
*/
|
||||
|
||||
void csi_convolve_HWC_q7_RGB(const q7_t * Im_in,
|
||||
const uint16_t dim_im_in,
|
||||
const q7_t * wt,
|
||||
const uint16_t ch_im_out,
|
||||
const uint16_t dim_kernel,
|
||||
const uint16_t padding,
|
||||
const uint16_t stride,
|
||||
const q7_t * bias,
|
||||
const uint16_t bias_shift,
|
||||
const uint16_t out_shift,
|
||||
q7_t * Im_out,
|
||||
const uint16_t dim_im_out,
|
||||
q15_t * bufferA);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Q7 depthwise separable convolution function
|
||||
* @param[in] Im_in pointer to input tensor
|
||||
* @param[in] dim_im_in input tensor dimention
|
||||
* @param[in] ch_im_in number of input tensor channels
|
||||
* @param[in] wt pointer to kernel weights
|
||||
* @param[in] ch_im_out number of filters, i.e., output tensor channels
|
||||
* @param[in] dim_kernel filter kernel size
|
||||
* @param[in] padding padding sizes
|
||||
* @param[in] stride convolution stride
|
||||
* @param[in] bias pointer to bias
|
||||
* @param[in] bias_shift amount of left-shift for bias
|
||||
* @param[in] out_shift amount of right-shift for output
|
||||
* @param[in,out] Im_out pointer to output tensor
|
||||
* @param[in] dim_im_out output tensor dimension
|
||||
* @param[in,out] bufferA pointer to buffer space for input
|
||||
* @return none.
|
||||
*
|
||||
* This function is the version with full list of optimization tricks, but with
|
||||
* some contraints:
|
||||
* ch_im_in is multiple of 2
|
||||
* ch_im_out is multiple of 2
|
||||
*/
|
||||
|
||||
void csi_depthwise_separable_conv_HWC_q7(const q7_t * Im_in,
|
||||
const uint16_t dim_im_in,
|
||||
const uint16_t ch_im_in,
|
||||
const q7_t * wt,
|
||||
const uint16_t ch_im_out,
|
||||
const uint16_t dim_kernel,
|
||||
const uint16_t padding,
|
||||
const uint16_t stride,
|
||||
const q7_t * bias,
|
||||
const uint16_t bias_shift,
|
||||
const uint16_t out_shift,
|
||||
q7_t * Im_out,
|
||||
const uint16_t dim_im_out,
|
||||
q15_t * bufferA);
|
||||
|
||||
/**
|
||||
* @brief Q7 depthwise separable convolution function (non-square shape)
|
||||
* @param[in] Im_in pointer to input tensor
|
||||
* @param[in] dim_im_in_x input tensor dimention x
|
||||
* @param[in] dim_im_in_y input tensor dimention y
|
||||
* @param[in] ch_im_in number of input tensor channels
|
||||
* @param[in] wt pointer to kernel weights
|
||||
* @param[in] ch_im_out number of filters, i.e., output tensor channels
|
||||
* @param[in] dim_kernel_x filter kernel size x
|
||||
* @param[in] dim_kernel_y filter kernel size y
|
||||
* @param[in] padding_x padding sizes x
|
||||
* @param[in] padding_y padding sizes y
|
||||
* @param[in] stride_x convolution stride x
|
||||
* @param[in] stride_y convolution stride y
|
||||
* @param[in] bias pointer to bias
|
||||
* @param[in] bias_shift amount of left-shift for bias
|
||||
* @param[in] out_shift amount of right-shift for output
|
||||
* @param[in,out] Im_out pointer to output tensor
|
||||
* @param[in] dim_im_out_x output tensor dimension x
|
||||
* @param[in] dim_im_out_y output tensor dimension y
|
||||
* @param[in,out] bufferA pointer to buffer space for input
|
||||
* @return none.
|
||||
*
|
||||
* This function is the version with full list of optimization tricks, but with
|
||||
* some contraints:
|
||||
* ch_im_in is multiple of 2
|
||||
* ch_im_out is multiple of 2
|
||||
*/
|
||||
void csi_depthwise_separable_conv_HWC_q7_nonsquare(const q7_t * Im_in,
|
||||
const uint16_t dim_im_in_x,
|
||||
const uint16_t dim_im_in_y,
|
||||
const uint16_t ch_im_in,
|
||||
const q7_t * wt,
|
||||
const uint16_t ch_im_out,
|
||||
const uint16_t dim_kernel_x,
|
||||
const uint16_t dim_kernel_y,
|
||||
const uint16_t padding_x,
|
||||
const uint16_t padding_y,
|
||||
const uint16_t stride_x,
|
||||
const uint16_t stride_y,
|
||||
const q7_t * bias,
|
||||
const uint16_t bias_shift,
|
||||
const uint16_t out_shift,
|
||||
q7_t * Im_out,
|
||||
const uint16_t dim_im_out_x,
|
||||
const uint16_t dim_im_out_y,
|
||||
q15_t * bufferA);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Q7 basic fully-connected layer function
|
||||
* @param[in] pV pointer to input vector
|
||||
* @param[in] pM pointer to matrix weights
|
||||
* @param[in] dim_vec length of the vector
|
||||
* @param[in] num_of_rows number of rows in weight matrix
|
||||
* @param[in] bias_shift amount of left-shift for bias
|
||||
* @param[in] out_shift amount of right-shift for output
|
||||
* @param[in] bias pointer to bias
|
||||
* @param[in,out] pOut pointer to output vector
|
||||
* @return none.
|
||||
*/
|
||||
|
||||
void csi_fully_connected_q7(const q7_t * pV,
|
||||
const q7_t * pM,
|
||||
const uint16_t dim_vec,
|
||||
const uint16_t num_of_rows,
|
||||
const uint16_t bias_shift,
|
||||
const uint16_t out_shift,
|
||||
const q7_t * bias,
|
||||
q7_t * pOut);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Q15 basic fully-connected layer function
|
||||
* @param[in] pV pointer to input vector
|
||||
* @param[in] pM pointer to matrix weights
|
||||
* @param[in] dim_vec length of the vector
|
||||
* @param[in] num_of_rows number of rows in weight matrix
|
||||
* @param[in] bias_shift amount of left-shift for bias
|
||||
* @param[in] out_shift amount of right-shift for output
|
||||
* @param[in] bias pointer to bias
|
||||
* @param[in,out] pOut pointer to output vector
|
||||
* @return none.
|
||||
*
|
||||
*/
|
||||
|
||||
void csi_fully_connected_q15(const q15_t * pV,
|
||||
const q15_t * pM,
|
||||
const uint16_t dim_vec,
|
||||
const uint16_t num_of_rows,
|
||||
const uint16_t bias_shift,
|
||||
const uint16_t out_shift,
|
||||
const q15_t * bias,
|
||||
q15_t * pOut);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Mixed Q15-Q7 fully-connected layer function
|
||||
* @param[in] pV pointer to input vector
|
||||
* @param[in] pM pointer to matrix weights
|
||||
* @param[in] dim_vec length of the vector
|
||||
* @param[in] num_of_rows number of rows in weight matrix
|
||||
* @param[in] bias_shift amount of left-shift for bias
|
||||
* @param[in] out_shift amount of right-shift for output
|
||||
* @param[in] bias pointer to bias
|
||||
* @param[in,out] pOut pointer to output vector
|
||||
* @return none.
|
||||
*
|
||||
*/
|
||||
|
||||
void csi_fully_connected_mat_q7_vec_q15(const q15_t * pV,
|
||||
const q7_t * pM,
|
||||
const uint16_t dim_vec,
|
||||
const uint16_t num_of_rows,
|
||||
const uint16_t bias_shift,
|
||||
const uint16_t out_shift,
|
||||
const q7_t * bias,
|
||||
q15_t * pOut);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Q7 RELU function
|
||||
* @param[in,out] data pointer to input
|
||||
* @param[in] size number of elements
|
||||
* @return none.
|
||||
*/
|
||||
|
||||
void csi_relu_q7(q7_t * data, uint16_t size);
|
||||
|
||||
/**
|
||||
* @brief Q15 RELU function
|
||||
* @param[in,out] data pointer to input
|
||||
* @param[in] size number of elements
|
||||
* @return none.
|
||||
*/
|
||||
|
||||
void csi_relu_q15(q15_t * data, uint16_t size);
|
||||
|
||||
/**
|
||||
* @brief Q7 neural network activation function using direct table look-up
|
||||
* @param[in,out] data pointer to input
|
||||
* @param[in] size number of elements
|
||||
* @param[in] int_width bit-width of the integer part, assume to be smaller than 3
|
||||
* @param[in] type type of activation functions
|
||||
* @return none.
|
||||
*/
|
||||
|
||||
void csi_nn_activations_direct_q7(q7_t * data, uint16_t size,
|
||||
uint16_t int_width,
|
||||
csi_nn_activation_type type);
|
||||
|
||||
/**
|
||||
* @brief Q15 neural network activation function using direct table look-up
|
||||
* @param[in,out] data pointer to input
|
||||
* @param[in] size number of elements
|
||||
* @param[in] int_width bit-width of the integer part, assume to be smaller than 3
|
||||
* @param[in] type type of activation functions
|
||||
* @return none.
|
||||
*/
|
||||
|
||||
void csi_nn_activations_direct_q15(q15_t * data, uint16_t size,
|
||||
uint16_t int_width,
|
||||
csi_nn_activation_type type);
|
||||
|
||||
/**
|
||||
* @brief Q7 max pooling function
|
||||
* @param[in] Im_in pointer to input tensor
|
||||
* @param[in] dim_im_in input tensor dimention
|
||||
* @param[in] ch_im_in number of input tensor channels
|
||||
* @param[in] dim_kernel filter kernel size
|
||||
* @param[in] padding padding sizes
|
||||
* @param[in] stride convolution stride
|
||||
* @param[in] dim_im_out output tensor dimension
|
||||
* @param[in,out] bufferA pointer to buffer space for input
|
||||
* @param[in,out] Im_out pointer to output tensor
|
||||
* @return none.
|
||||
*
|
||||
*/
|
||||
|
||||
void csi_maxpool_q7_HWC(q7_t * Im_in,
|
||||
const uint16_t dim_im_in,
|
||||
const uint16_t ch_im_in,
|
||||
const uint16_t dim_kernel,
|
||||
const uint16_t padding,
|
||||
const uint16_t stride,
|
||||
const uint16_t dim_im_out,
|
||||
q7_t * bufferA,
|
||||
q7_t * Im_out);
|
||||
|
||||
/**
|
||||
* @brief Q7 average pooling function
|
||||
* @param[in] Im_in pointer to input tensor
|
||||
* @param[in] dim_im_in input tensor dimention
|
||||
* @param[in] ch_im_in number of input tensor channels
|
||||
* @param[in] dim_kernel filter kernel size
|
||||
* @param[in] padding padding sizes
|
||||
* @param[in] stride convolution stride
|
||||
* @param[in] dim_im_out output tensor dimension
|
||||
* @param[in,out] bufferA pointer to buffer space for input
|
||||
* @param[in,out] Im_out pointer to output tensor
|
||||
* @return none.
|
||||
*
|
||||
*/
|
||||
|
||||
void csi_avepool_q7_HWC(q7_t * Im_in,
|
||||
const uint16_t dim_im_in,
|
||||
const uint16_t ch_im_in,
|
||||
const uint16_t dim_kernel,
|
||||
const uint16_t padding,
|
||||
const uint16_t stride,
|
||||
const uint16_t dim_im_out,
|
||||
q7_t * bufferA,
|
||||
q7_t * Im_out);
|
||||
|
||||
|
||||
void csi_avepool_q7_HWC_nonsquare(
|
||||
q7_t *Im_in, // input image
|
||||
const uint16_t dim_im_in_x, // input image dimension
|
||||
const uint16_t dim_im_in_y, // input image dimension
|
||||
const uint16_t ch_im_in, // number of input image channels
|
||||
const uint16_t dim_kernel_x, // window kernel size
|
||||
const uint16_t dim_kernel_y, // window kernel size
|
||||
const uint16_t padding_x, // padding sizes
|
||||
const uint16_t padding_y, // padding sizes
|
||||
const uint16_t stride_x, // stride
|
||||
const uint16_t stride_y, // stride
|
||||
const uint16_t dim_im_out_x, // output image dimension
|
||||
const uint16_t dim_im_out_y, // output image dimension
|
||||
q7_t *bufferA, // a buffer for local storage
|
||||
q7_t *Im_out, // output feature
|
||||
const uint16_t out_lshift); // output left shift (scaling)
|
||||
|
||||
|
||||
/**
|
||||
* @brief Q7 softmax function
|
||||
* @param[in] vec_in pointer to input vector
|
||||
* @param[in] dim_vec input vector dimention
|
||||
* @param[out] p_out pointer to output vector
|
||||
* @return none.
|
||||
*
|
||||
*/
|
||||
|
||||
void csi_softmax_q7(const q7_t *vec_in, const uint16_t dim_vec, q7_t *p_out);
|
||||
|
||||
/**
|
||||
* @brief Q15 softmax function
|
||||
* @param[in] vec_in pointer to input vector
|
||||
* @param[in] dim_vec input vector dimention
|
||||
* @param[out] p_out pointer to output vector
|
||||
* @return none.
|
||||
*
|
||||
*/
|
||||
|
||||
void csi_softmax_q15(const q15_t *vec_in, const uint16_t dim_vec,
|
||||
q15_t *p_out);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
162
csky/csi_dsp/include/csi_nnsupportfunctions.h
Normal file
162
csky/csi_dsp/include/csi_nnsupportfunctions.h
Normal file
@@ -0,0 +1,162 @@
|
||||
/*
|
||||
* Copyright (C) 2016-2019 C-SKY Limited. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
* Title: csi_nnsupportfunctions.h
|
||||
* Description: Public header file of support functions for CSI NN Library
|
||||
*
|
||||
* -------------------------------------------------------------------- */
|
||||
|
||||
#ifndef _CSKY_DSP2_NNSUPPORTFUNCTIONS_H_
|
||||
#define _CSKY_DSP2_NNSUPPORTFUNCTIONS_H_
|
||||
|
||||
#include "csi_instance.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Union for SIMD access of Q31/Q15/Q7 types
|
||||
*/
|
||||
union csi_nnword
|
||||
{
|
||||
q31_t word; /**< Q31 type */
|
||||
q15_t half_words[2]; /**< Q15 type */
|
||||
q7_t bytes[4]; /**< Q7 type */
|
||||
};
|
||||
|
||||
/**
|
||||
* @defgroup nndata_convert Neural Network Data Conversion Functions
|
||||
*
|
||||
* Perform data type conversion in-between neural network operations
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Converts the elements of the Q7 vector to Q15 vector without left-shift
|
||||
* @param[in] *pSrc points to the Q7 input vector
|
||||
* @param[out] *pDst points to the Q15 output vector
|
||||
* @param[in] blockSize length of the input vector
|
||||
* @return none.
|
||||
*
|
||||
*/
|
||||
|
||||
void csi_q7_to_q15_no_shift(const q7_t * pSrc, q15_t * pDst,
|
||||
uint32_t blockSize);
|
||||
|
||||
/**
|
||||
* @brief Converts the elements of the Q7 vector to reordered Q15 vector without left-shift
|
||||
* @param[in] *pSrc points to the Q7 input vector
|
||||
* @param[out] *pDst points to the Q15 output vector
|
||||
* @param[in] blockSize length of the input vector
|
||||
* @return none.
|
||||
*
|
||||
*/
|
||||
|
||||
void csi_q7_to_q15_reordered_no_shift(const q7_t * pSrc, q15_t * pDst,
|
||||
uint32_t blockSize);
|
||||
|
||||
#if defined (CSI_MATH_DSP)
|
||||
|
||||
/**
|
||||
* @brief read and expand one Q7 word into two Q15 words
|
||||
*/
|
||||
|
||||
__ALWAYS_STATIC_INLINE void *read_and_pad(void *source, q31_t *out1,
|
||||
q31_t *out2)
|
||||
{
|
||||
q31_t inA = *__SIMD32(source)++;
|
||||
q31_t inAbuf1 = __SXTB16(__ROR(inA, 8));
|
||||
q31_t inAbuf2 = __SXTB16(inA);
|
||||
|
||||
#ifndef CSKY_MATH_BIG_ENDIAN
|
||||
*out2 = __PKHTB(inAbuf1, inAbuf2, 16);
|
||||
*out1 = __PKHBT(inAbuf2, inAbuf1, 16);
|
||||
#else
|
||||
*out1 = __PKHTB(inAbuf1, inAbuf2, 16);
|
||||
*out2 = __PKHBT(inAbuf2, inAbuf1, 16);
|
||||
#endif
|
||||
|
||||
return source;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief read and expand one Q7 word into two Q15 words with reordering
|
||||
*/
|
||||
|
||||
__ALWAYS_STATIC_INLINE void *read_and_pad_reordered(void *source, q31_t * out1,
|
||||
q31_t * out2)
|
||||
{
|
||||
q31_t inA = *__SIMD32(source)++;
|
||||
#ifndef CSKY_MATH_BIG_ENDIAN
|
||||
*out2 = __SXTB16(__ROR(inA, 8));
|
||||
*out1 = __SXTB16(inA);
|
||||
#else
|
||||
*out1 = __SXTB16(__ROR(inA, 8));
|
||||
*out2 = __SXTB16(inA);
|
||||
#endif
|
||||
|
||||
return source;
|
||||
}
|
||||
#endif
|
||||
|
||||
q7_t *csi_nn_mat_mult_kernel_q7_q15_reordered(const q7_t * pA,
|
||||
const q15_t * pInBuffer,
|
||||
const uint16_t ch_im_out,
|
||||
const uint16_t numCol_A,
|
||||
const uint16_t bias_shift,
|
||||
const uint16_t out_shift,
|
||||
const q7_t * bias,
|
||||
q7_t * pOut);
|
||||
|
||||
q7_t *csi_nn_mat_mult_kernel_q7_q15(const q7_t * pA,
|
||||
const q15_t * pInBuffer,
|
||||
const uint16_t ch_im_out,
|
||||
const uint16_t numCol_A,
|
||||
const uint16_t bias_shift,
|
||||
const uint16_t out_shift,
|
||||
const q7_t * bias,
|
||||
q7_t * pOut);
|
||||
|
||||
/**
|
||||
* @brief A few utility functions used by pooling functions
|
||||
*
|
||||
*/
|
||||
|
||||
void buffer_scale_back_q15_to_q7(q15_t * buffer, q7_t * target,
|
||||
uint16_t length, uint16_t scale);
|
||||
|
||||
void accumulate_q7_to_q15(q15_t * base, q7_t * target,
|
||||
const uint16_t length);
|
||||
|
||||
/**
|
||||
* @brief defition to adding rouding offset
|
||||
*/
|
||||
#ifndef CSKY_NN_TRUNCATE
|
||||
#define NN_ROUND(out_shift) ( 0x1 << (out_shift - 1) )
|
||||
#else
|
||||
#define NN_ROUND(out_shift) 0
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
229
csky/csi_dsp/include/csky_common_tables.h
Normal file
229
csky/csi_dsp/include/csky_common_tables.h
Normal file
@@ -0,0 +1,229 @@
|
||||
/*
|
||||
* Copyright (C) 2016-2019 C-SKY Limited. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/******************************************************************************
|
||||
* @file csky_common_tables.h
|
||||
* @brief This file has extern declaration for common tables like
|
||||
* Bitreverse, reciprocal etc which are used across different functions.
|
||||
* @version V1.0
|
||||
* @date 20. Dec 2016
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef _CSKY_COMMON_TABLES_H
|
||||
#define _CSKY_COMMON_TABLES_H
|
||||
|
||||
#include "csky_math.h"
|
||||
|
||||
extern const uint16_t cskyBitRevTable[1024];
|
||||
extern const q15_t cskyRecipTableQ15[64];
|
||||
extern const q31_t cskyRecipTableQ31[64];
|
||||
extern const uint32_t twiddleCoef_16[32];
|
||||
extern const uint32_t twiddleCoef_32[64];
|
||||
extern const uint32_t twiddleCoef_64[128];
|
||||
extern const uint32_t twiddleCoef_128[256];
|
||||
extern const uint32_t twiddleCoef_256[512];
|
||||
extern const uint32_t twiddleCoef_512[1024];
|
||||
extern const uint32_t twiddleCoef_1024[2048];
|
||||
extern const uint32_t twiddleCoef_2048[4096];
|
||||
extern const uint32_t twiddleCoef_4096[8192];
|
||||
extern const q31_t twiddleCoef_16_q31[24];
|
||||
extern const q31_t twiddleCoef_32_q31[48];
|
||||
extern const q31_t twiddleCoef_64_q31[96];
|
||||
extern const q31_t twiddleCoef_128_q31[192];
|
||||
extern const q31_t twiddleCoef_256_q31[384];
|
||||
extern const q31_t twiddleCoef_512_q31[768];
|
||||
extern const q31_t twiddleCoef_1024_q31[1536];
|
||||
extern const q31_t twiddleCoef_2048_q31[3072];
|
||||
extern const q31_t twiddleCoef_4096_q31[6144];
|
||||
extern const q15_t twiddleCoef_16_q15[24];
|
||||
extern const q15_t twiddleCoef_32_q15[48];
|
||||
extern const q15_t twiddleCoef_64_q15[96];
|
||||
extern const q15_t twiddleCoef_128_q15[192];
|
||||
extern const q15_t twiddleCoef_256_q15[384];
|
||||
extern const q15_t twiddleCoef_512_q15[768];
|
||||
extern const q15_t twiddleCoef_1024_q15[1536];
|
||||
extern const q15_t twiddleCoef_2048_q15[3072];
|
||||
extern const q15_t twiddleCoef_4096_q15[6144];
|
||||
extern const float32_t twiddleCoef_rfft_32[32];
|
||||
extern const float32_t twiddleCoef_rfft_64[64];
|
||||
extern const float32_t twiddleCoef_rfft_128[128];
|
||||
extern const float32_t twiddleCoef_rfft_256[256];
|
||||
extern const float32_t twiddleCoef_rfft_512[512];
|
||||
extern const float32_t twiddleCoef_rfft_1024[1024];
|
||||
extern const float32_t twiddleCoef_rfft_2048[2048];
|
||||
extern const float32_t twiddleCoef_rfft_4096[4096];
|
||||
extern const float32_t twiddleCoef_rfft_8192[8192];
|
||||
|
||||
extern const q15_t twiddleCoef_fast_16_q15[24];
|
||||
extern const q15_t twiddleCoef_fast_32_q15[56];
|
||||
extern const q15_t twiddleCoef_fast_64_q15[120];
|
||||
extern const q15_t twiddleCoef_fast_128_q15[248];
|
||||
extern const q15_t twiddleCoef_fast_256_q15[504];
|
||||
extern const q15_t twiddleCoef_fast_512_q15[1016];
|
||||
extern const q15_t twiddleCoef_fast_1024_q15[2040];
|
||||
extern const q15_t twiddleCoef_fast_2048_q15[4088];
|
||||
extern const q15_t twiddleCoef_fast_4096_q15[8184];
|
||||
|
||||
extern const q31_t twiddleCoef_fast_16_q31[24];
|
||||
extern const q31_t twiddleCoef_fast_32_q31[56];
|
||||
extern const q31_t twiddleCoef_fast_64_q31[120];
|
||||
extern const q31_t twiddleCoef_fast_128_q31[248];
|
||||
extern const q31_t twiddleCoef_fast_256_q31[504];
|
||||
extern const q31_t twiddleCoef_fast_512_q31[1016];
|
||||
extern const q31_t twiddleCoef_fast_1024_q31[2040];
|
||||
extern const q31_t twiddleCoef_fast_2048_q31[4088];
|
||||
extern const q31_t twiddleCoef_fast_4096_q31[8184];
|
||||
|
||||
extern const uint32_t twiddleCoef_fast_16[24];
|
||||
extern const uint32_t twiddleCoef_fast_32[56];
|
||||
extern const uint32_t twiddleCoef_fast_64[120];
|
||||
extern const uint32_t twiddleCoef_fast_128[248];
|
||||
extern const uint32_t twiddleCoef_fast_256[504];
|
||||
extern const uint32_t twiddleCoef_fast_512[1016];
|
||||
extern const uint32_t twiddleCoef_fast_1024[2040];
|
||||
extern const uint32_t twiddleCoef_fast_2048[4088];
|
||||
extern const uint32_t twiddleCoef_fast_4096[8184];
|
||||
|
||||
extern const q15_t realCoefAQ15_8192[8192];
|
||||
extern const q31_t realCoefAQ31_8192[8192];
|
||||
extern const q15_t realCoefBQ15_8192[8192];
|
||||
extern const q31_t realCoefBQ31_8192[8192];
|
||||
|
||||
/*Tables for RFFT.*/
|
||||
extern const q15_t ALIGN4 realCoefAQ15_32[32];
|
||||
extern const q15_t ALIGN4 realCoefAQ15_64[64];
|
||||
extern const q15_t ALIGN4 realCoefAQ15_128[128];
|
||||
extern const q15_t ALIGN4 realCoefAQ15_256[256];
|
||||
extern const q15_t ALIGN4 realCoefAQ15_512[512];
|
||||
extern const q15_t ALIGN4 realCoefAQ15_1024[1024];
|
||||
extern const q15_t ALIGN4 realCoefAQ15_2048[2048];
|
||||
extern const q15_t ALIGN4 realCoefAQ15_4096[4096];
|
||||
|
||||
extern const q15_t ALIGN4 realCoefBQ15_32[32];
|
||||
extern const q15_t ALIGN4 realCoefBQ15_64[64];
|
||||
extern const q15_t ALIGN4 realCoefBQ15_128[128];
|
||||
extern const q15_t ALIGN4 realCoefBQ15_256[256];
|
||||
extern const q15_t ALIGN4 realCoefBQ15_512[512];
|
||||
extern const q15_t ALIGN4 realCoefBQ15_1024[1024];
|
||||
extern const q15_t ALIGN4 realCoefBQ15_2048[2048];
|
||||
extern const q15_t ALIGN4 realCoefBQ15_4096[4096];
|
||||
|
||||
extern const q31_t realCoefAQ31_32[32];
|
||||
extern const q31_t realCoefAQ31_64[64];
|
||||
extern const q31_t realCoefAQ31_128[128];
|
||||
extern const q31_t realCoefAQ31_256[256];
|
||||
extern const q31_t realCoefAQ31_512[512];
|
||||
extern const q31_t realCoefAQ31_1024[1024];
|
||||
extern const q31_t realCoefAQ31_2048[2048];
|
||||
extern const q31_t realCoefAQ31_4096[4096];
|
||||
|
||||
extern const q31_t realCoefBQ31_32[32];
|
||||
extern const q31_t realCoefBQ31_64[64];
|
||||
extern const q31_t realCoefBQ31_128[128];
|
||||
extern const q31_t realCoefBQ31_256[256];
|
||||
extern const q31_t realCoefBQ31_512[512];
|
||||
extern const q31_t realCoefBQ31_1024[1024];
|
||||
extern const q31_t realCoefBQ31_2048[2048];
|
||||
extern const q31_t realCoefBQ31_4096[4096];
|
||||
|
||||
|
||||
extern const float32_t realCoefA[8192];
|
||||
extern const float32_t realCoefB[8192];
|
||||
|
||||
|
||||
/*Tables for DCT4*/
|
||||
extern const q15_t ALIGN4 WeightsQ15_128[128+2];
|
||||
extern const q15_t ALIGN4 WeightsQ15_512[512+2];
|
||||
extern const q15_t ALIGN4 WeightsQ15_2048[2048+2];
|
||||
extern const q15_t ALIGN4 WeightsQ15_8192[8192+2];
|
||||
|
||||
extern const q15_t ALIGN4 cos_factorsQ15_128[128];
|
||||
extern const q15_t ALIGN4 cos_factorsQ15_512[512];
|
||||
extern const q15_t ALIGN4 cos_factorsQ15_2048[2048];
|
||||
extern const q15_t ALIGN4 cos_factorsQ15_8192[8192];
|
||||
|
||||
|
||||
extern const q31_t WeightsQ31_128[128+2];
|
||||
extern const q31_t WeightsQ31_512[512+2];
|
||||
extern const q31_t WeightsQ31_2048[2048+2];
|
||||
extern const q31_t WeightsQ31_8192[8192+2];
|
||||
|
||||
extern const q31_t cos_factorsQ31_128[128];
|
||||
extern const q31_t cos_factorsQ31_512[512];
|
||||
extern const q31_t cos_factorsQ31_2048[2048];
|
||||
extern const q31_t cos_factorsQ31_8192[8192];
|
||||
|
||||
|
||||
extern const float32_t Weights_128[128+2];
|
||||
extern const float32_t Weights_512[512+2];
|
||||
extern const float32_t Weights_2048[2048+2];
|
||||
extern const float32_t Weights_8192[8192+2];
|
||||
|
||||
extern const float32_t cos_factors_128[128];
|
||||
extern const float32_t cos_factors_512[512];
|
||||
extern const float32_t cos_factors_2048[2048];
|
||||
extern const float32_t cos_factors_8192[8192];
|
||||
|
||||
/* floating-point bit reversal tables */
|
||||
#define CSKYBITREVINDEXTABLE__16_TABLE_LENGTH ((uint16_t)20 )
|
||||
#define CSKYBITREVINDEXTABLE__32_TABLE_LENGTH ((uint16_t)48 )
|
||||
#define CSKYBITREVINDEXTABLE__64_TABLE_LENGTH ((uint16_t)56 )
|
||||
#define CSKYBITREVINDEXTABLE_128_TABLE_LENGTH ((uint16_t)208 )
|
||||
#define CSKYBITREVINDEXTABLE_256_TABLE_LENGTH ((uint16_t)440 )
|
||||
#define CSKYBITREVINDEXTABLE_512_TABLE_LENGTH ((uint16_t)448 )
|
||||
#define CSKYBITREVINDEXTABLE1024_TABLE_LENGTH ((uint16_t)1800)
|
||||
#define CSKYBITREVINDEXTABLE2048_TABLE_LENGTH ((uint16_t)3808)
|
||||
#define CSKYBITREVINDEXTABLE4096_TABLE_LENGTH ((uint16_t)4032)
|
||||
|
||||
extern const uint16_t cskyBitRevIndexTable16[CSKYBITREVINDEXTABLE__16_TABLE_LENGTH];
|
||||
extern const uint16_t cskyBitRevIndexTable32[CSKYBITREVINDEXTABLE__32_TABLE_LENGTH];
|
||||
extern const uint16_t cskyBitRevIndexTable64[CSKYBITREVINDEXTABLE__64_TABLE_LENGTH];
|
||||
extern const uint16_t cskyBitRevIndexTable128[CSKYBITREVINDEXTABLE_128_TABLE_LENGTH];
|
||||
extern const uint16_t cskyBitRevIndexTable256[CSKYBITREVINDEXTABLE_256_TABLE_LENGTH];
|
||||
extern const uint16_t cskyBitRevIndexTable512[CSKYBITREVINDEXTABLE_512_TABLE_LENGTH];
|
||||
extern const uint16_t cskyBitRevIndexTable1024[CSKYBITREVINDEXTABLE1024_TABLE_LENGTH];
|
||||
extern const uint16_t cskyBitRevIndexTable2048[CSKYBITREVINDEXTABLE2048_TABLE_LENGTH];
|
||||
extern const uint16_t cskyBitRevIndexTable4096[CSKYBITREVINDEXTABLE4096_TABLE_LENGTH];
|
||||
|
||||
/* fixed-point bit reversal tables */
|
||||
#define CSKYBITREVINDEXTABLE_FIXED___16_TABLE_LENGTH ((uint16_t)12 )
|
||||
#define CSKYBITREVINDEXTABLE_FIXED___32_TABLE_LENGTH ((uint16_t)24 )
|
||||
#define CSKYBITREVINDEXTABLE_FIXED___64_TABLE_LENGTH ((uint16_t)56 )
|
||||
#define CSKYBITREVINDEXTABLE_FIXED__128_TABLE_LENGTH ((uint16_t)112 )
|
||||
#define CSKYBITREVINDEXTABLE_FIXED__256_TABLE_LENGTH ((uint16_t)240 )
|
||||
#define CSKYBITREVINDEXTABLE_FIXED__512_TABLE_LENGTH ((uint16_t)480 )
|
||||
#define CSKYBITREVINDEXTABLE_FIXED_1024_TABLE_LENGTH ((uint16_t)992 )
|
||||
#define CSKYBITREVINDEXTABLE_FIXED_2048_TABLE_LENGTH ((uint16_t)1984)
|
||||
#define CSKYBITREVINDEXTABLE_FIXED_4096_TABLE_LENGTH ((uint16_t)4032)
|
||||
|
||||
extern const uint16_t cskyBitRevIndexTable_fixed_16[CSKYBITREVINDEXTABLE_FIXED___16_TABLE_LENGTH];
|
||||
extern const uint16_t cskyBitRevIndexTable_fixed_32[CSKYBITREVINDEXTABLE_FIXED___32_TABLE_LENGTH];
|
||||
extern const uint16_t cskyBitRevIndexTable_fixed_64[CSKYBITREVINDEXTABLE_FIXED___64_TABLE_LENGTH];
|
||||
extern const uint16_t cskyBitRevIndexTable_fixed_128[CSKYBITREVINDEXTABLE_FIXED__128_TABLE_LENGTH];
|
||||
extern const uint16_t cskyBitRevIndexTable_fixed_256[CSKYBITREVINDEXTABLE_FIXED__256_TABLE_LENGTH];
|
||||
extern const uint16_t cskyBitRevIndexTable_fixed_512[CSKYBITREVINDEXTABLE_FIXED__512_TABLE_LENGTH];
|
||||
extern const uint16_t cskyBitRevIndexTable_fixed_1024[CSKYBITREVINDEXTABLE_FIXED_1024_TABLE_LENGTH];
|
||||
extern const uint16_t cskyBitRevIndexTable_fixed_2048[CSKYBITREVINDEXTABLE_FIXED_2048_TABLE_LENGTH];
|
||||
extern const uint16_t cskyBitRevIndexTable_fixed_4096[CSKYBITREVINDEXTABLE_FIXED_4096_TABLE_LENGTH];
|
||||
|
||||
/* Tables for Fast Math Sine and Cosine */
|
||||
extern const float32_t sinTable_f32[FAST_MATH_TABLE_SIZE + 1];
|
||||
extern const q31_t sinTable_q31[FAST_MATH_TABLE_SIZE + 1];
|
||||
extern const q15_t sinTable_q15[FAST_MATH_TABLE_SIZE + 1];
|
||||
|
||||
#endif /* CSKY_COMMON_TABLES_H */
|
||||
131
csky/csi_dsp/include/csky_const_structs.h
Normal file
131
csky/csi_dsp/include/csky_const_structs.h
Normal file
@@ -0,0 +1,131 @@
|
||||
/*
|
||||
* Copyright (C) 2016-2019 C-SKY Limited. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/******************************************************************************
|
||||
* @file csky_const_structs.h
|
||||
* @brief This file has constant structs that are initialized for
|
||||
* user convenience. For example, some can be given as
|
||||
* arguments to the csky_cfft_f32() function.
|
||||
* @version V1.0
|
||||
* @date 20. Dec 2016
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef _CSKY_CONST_STRUCTS_H
|
||||
#define _CSKY_CONST_STRUCTS_H
|
||||
|
||||
#include "csky_math.h"
|
||||
#include "csky_common_tables.h"
|
||||
|
||||
extern const csky_cfft_instance_f32 csky_cfft_sR_f32_len16;
|
||||
extern const csky_cfft_instance_f32 csky_cfft_sR_f32_len32;
|
||||
extern const csky_cfft_instance_f32 csky_cfft_sR_f32_len64;
|
||||
extern const csky_cfft_instance_f32 csky_cfft_sR_f32_len128;
|
||||
extern const csky_cfft_instance_f32 csky_cfft_sR_f32_len256;
|
||||
extern const csky_cfft_instance_f32 csky_cfft_sR_f32_len512;
|
||||
extern const csky_cfft_instance_f32 csky_cfft_sR_f32_len1024;
|
||||
extern const csky_cfft_instance_f32 csky_cfft_sR_f32_len2048;
|
||||
extern const csky_cfft_instance_f32 csky_cfft_sR_f32_len4096;
|
||||
|
||||
extern const csky_cfft_instance_q31 csky_cfft_sR_q31_len16;
|
||||
extern const csky_cfft_instance_q31 csky_cfft_sR_q31_len32;
|
||||
extern const csky_cfft_instance_q31 csky_cfft_sR_q31_len64;
|
||||
extern const csky_cfft_instance_q31 csky_cfft_sR_q31_len128;
|
||||
extern const csky_cfft_instance_q31 csky_cfft_sR_q31_len256;
|
||||
extern const csky_cfft_instance_q31 csky_cfft_sR_q31_len512;
|
||||
extern const csky_cfft_instance_q31 csky_cfft_sR_q31_len1024;
|
||||
extern const csky_cfft_instance_q31 csky_cfft_sR_q31_len2048;
|
||||
extern const csky_cfft_instance_q31 csky_cfft_sR_q31_len4096;
|
||||
|
||||
extern const csky_cfft_instance_q15 csky_cfft_sR_q15_len16;
|
||||
extern const csky_cfft_instance_q15 csky_cfft_sR_q15_len32;
|
||||
extern const csky_cfft_instance_q15 csky_cfft_sR_q15_len64;
|
||||
extern const csky_cfft_instance_q15 csky_cfft_sR_q15_len128;
|
||||
extern const csky_cfft_instance_q15 csky_cfft_sR_q15_len256;
|
||||
extern const csky_cfft_instance_q15 csky_cfft_sR_q15_len512;
|
||||
extern const csky_cfft_instance_q15 csky_cfft_sR_q15_len1024;
|
||||
extern const csky_cfft_instance_q15 csky_cfft_sR_q15_len2048;
|
||||
extern const csky_cfft_instance_q15 csky_cfft_sR_q15_len4096;
|
||||
|
||||
extern csky_rfft_instance_q15 csky_rfft_sR_q15_len32;
|
||||
extern csky_rfft_instance_q15 csky_rfft_sR_q15_len64;
|
||||
extern csky_rfft_instance_q15 csky_rfft_sR_q15_len128;
|
||||
extern csky_rfft_instance_q15 csky_rfft_sR_q15_len256;
|
||||
extern csky_rfft_instance_q15 csky_rfft_sR_q15_len512;
|
||||
extern csky_rfft_instance_q15 csky_rfft_sR_q15_len1024;
|
||||
extern csky_rfft_instance_q15 csky_rfft_sR_q15_len2048;
|
||||
extern csky_rfft_instance_q15 csky_rfft_sR_q15_len4096;
|
||||
extern csky_rfft_instance_q15 csky_rfft_sR_q15_len8192;
|
||||
|
||||
|
||||
extern csky_rfft_instance_q15 csky_inv_rfft_sR_q15_len32;
|
||||
extern csky_rfft_instance_q15 csky_inv_rfft_sR_q15_len64;
|
||||
extern csky_rfft_instance_q15 csky_inv_rfft_sR_q15_len128;
|
||||
extern csky_rfft_instance_q15 csky_inv_rfft_sR_q15_len256;
|
||||
extern csky_rfft_instance_q15 csky_inv_rfft_sR_q15_len512;
|
||||
extern csky_rfft_instance_q15 csky_inv_rfft_sR_q15_len1024;
|
||||
extern csky_rfft_instance_q15 csky_inv_rfft_sR_q15_len2048;
|
||||
extern csky_rfft_instance_q15 csky_inv_rfft_sR_q15_len4096;
|
||||
extern csky_rfft_instance_q15 csky_inv_rfft_sR_q15_len8192;
|
||||
|
||||
|
||||
extern csky_rfft_instance_q31 csky_rfft_sR_q31_len32;
|
||||
extern csky_rfft_instance_q31 csky_rfft_sR_q31_len64;
|
||||
extern csky_rfft_instance_q31 csky_rfft_sR_q31_len128;
|
||||
extern csky_rfft_instance_q31 csky_rfft_sR_q31_len256;
|
||||
extern csky_rfft_instance_q31 csky_rfft_sR_q31_len512;
|
||||
extern csky_rfft_instance_q31 csky_rfft_sR_q31_len1024;
|
||||
extern csky_rfft_instance_q31 csky_rfft_sR_q31_len2048;
|
||||
extern csky_rfft_instance_q31 csky_rfft_sR_q31_len4096;
|
||||
extern csky_rfft_instance_q31 csky_rfft_sR_q31_len8192;
|
||||
|
||||
extern csky_rfft_instance_q31 csky_inv_rfft_sR_q31_len32;
|
||||
extern csky_rfft_instance_q31 csky_inv_rfft_sR_q31_len64;
|
||||
extern csky_rfft_instance_q31 csky_inv_rfft_sR_q31_len128;
|
||||
extern csky_rfft_instance_q31 csky_inv_rfft_sR_q31_len256;
|
||||
extern csky_rfft_instance_q31 csky_inv_rfft_sR_q31_len512;
|
||||
extern csky_rfft_instance_q31 csky_inv_rfft_sR_q31_len1024;
|
||||
extern csky_rfft_instance_q31 csky_inv_rfft_sR_q31_len2048;
|
||||
extern csky_rfft_instance_q31 csky_inv_rfft_sR_q31_len4096;
|
||||
extern csky_rfft_instance_q31 csky_inv_rfft_sR_q31_len8192;
|
||||
|
||||
|
||||
extern csky_rfft_fast_instance_f32 csky_rfft_sR_f32_len32;
|
||||
extern csky_rfft_fast_instance_f32 csky_rfft_sR_f32_len64;
|
||||
extern csky_rfft_fast_instance_f32 csky_rfft_sR_f32_len128;
|
||||
extern csky_rfft_fast_instance_f32 csky_rfft_sR_f32_len256;
|
||||
extern csky_rfft_fast_instance_f32 csky_rfft_sR_f32_len512;
|
||||
extern csky_rfft_fast_instance_f32 csky_rfft_sR_f32_len1024;
|
||||
extern csky_rfft_fast_instance_f32 csky_rfft_sR_f32_len2048;
|
||||
extern csky_rfft_fast_instance_f32 csky_rfft_sR_f32_len4096;
|
||||
extern csky_rfft_fast_instance_f32 csky_rfft_sR_f32_len8192;
|
||||
|
||||
extern csky_dct4_instance_q15 csky_dct4_sR_q15_len128;
|
||||
extern csky_dct4_instance_q15 csky_dct4_sR_q15_len512;
|
||||
extern csky_dct4_instance_q15 csky_dct4_sR_q15_len2048;
|
||||
extern csky_dct4_instance_q15 csky_dct4_sR_q15_len8192;
|
||||
|
||||
extern csky_dct4_instance_q31 csky_dct4_sR_q31_len128;
|
||||
extern csky_dct4_instance_q31 csky_dct4_sR_q31_len512;
|
||||
extern csky_dct4_instance_q31 csky_dct4_sR_q31_len2048;
|
||||
extern csky_dct4_instance_q31 csky_dct4_sR_q31_len8192;
|
||||
|
||||
extern csky_dct4_instance_f32 csky_dct4_sR_f32_len128;
|
||||
extern csky_dct4_instance_f32 csky_dct4_sR_f32_len512;
|
||||
extern csky_dct4_instance_f32 csky_dct4_sR_f32_len2048;
|
||||
extern csky_dct4_instance_f32 csky_dct4_sR_f32_len8192;
|
||||
#endif
|
||||
745
csky/csi_dsp/include/csky_dsp2_nnfunctions.h
Normal file
745
csky/csi_dsp/include/csky_dsp2_nnfunctions.h
Normal file
@@ -0,0 +1,745 @@
|
||||
/*
|
||||
* Copyright (C) 2016-2019 C-SKY Limited. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
* Title: csky_dsp2_nnfunctions.h
|
||||
* Description: Public header file for CSI NN Library
|
||||
*
|
||||
* -------------------------------------------------------------------- */
|
||||
|
||||
#ifndef _CSKY_DSP2_NNFUNCTIONS_H
|
||||
#define _CSKY_DSP2_NNFUNCTIONS_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#include"csky_math.h"
|
||||
/**
|
||||
* @brief Struct for specifying activation function types
|
||||
*
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
CSKY_SIGMOID = 0, /**< Sigmoid activation function */
|
||||
CSKY_TANH = 1, /**< Tanh activation function */
|
||||
} csky_dsp2_nn_activation_type;
|
||||
|
||||
/**
|
||||
* @brief Basic Q7 convolution function
|
||||
* @param[in] Im_in pointer to input tensor
|
||||
* @param[in] dim_im_in input tensor dimention
|
||||
* @param[in] ch_im_in number of input tensor channels
|
||||
* @param[in] wt pointer to kernel weights
|
||||
* @param[in] ch_im_out number of filters, i.e., output tensor channels
|
||||
* @param[in] dim_kernel filter kernel size
|
||||
* @param[in] padding padding sizes
|
||||
* @param[in] stride convolution stride
|
||||
* @param[in] bias pointer to bias
|
||||
* @param[in] bias_shift amount of left-shift for bias
|
||||
* @param[in] out_shift amount of right-shift for output
|
||||
* @param[in,out] Im_out pointer to output tensor
|
||||
* @param[in] dim_im_out output tensor dimension
|
||||
* @param[in,out] bufferA pointer to buffer space for input
|
||||
* @return none.
|
||||
*
|
||||
*/
|
||||
|
||||
void csky_dsp2_convolve_HWC_q7_basic(const q7_t * Im_in,
|
||||
const uint16_t dim_im_in,
|
||||
const uint16_t ch_im_in,
|
||||
const q7_t * wt,
|
||||
const uint16_t ch_im_out,
|
||||
const uint16_t dim_kernel,
|
||||
const uint16_t padding,
|
||||
const uint16_t stride,
|
||||
const q7_t * bias,
|
||||
const uint16_t bias_shift,
|
||||
const uint16_t out_shift,
|
||||
q7_t * Im_out,
|
||||
const uint16_t dim_im_out,
|
||||
q15_t * bufferA);
|
||||
|
||||
/**
|
||||
* @brief Basic Q15 convolution function
|
||||
* @param[in] Im_in pointer to input tensor
|
||||
* @param[in] dim_im_in input tensor dimention
|
||||
* @param[in] ch_im_in number of input tensor channels
|
||||
* @param[in] wt pointer to kernel weights
|
||||
* @param[in] ch_im_out number of filters, i.e., output tensor channels
|
||||
* @param[in] dim_kernel filter kernel size
|
||||
* @param[in] padding padding sizes
|
||||
* @param[in] stride convolution stride
|
||||
* @param[in] bias pointer to bias
|
||||
* @param[in] bias_shift amount of left-shift for bias
|
||||
* @param[in] out_shift amount of right-shift for output
|
||||
* @param[in,out] Im_out pointer to output tensor
|
||||
* @param[in] dim_im_out output tensor dimension
|
||||
* @param[in,out] bufferA pointer to buffer space for input
|
||||
* @return none.
|
||||
*
|
||||
*/
|
||||
|
||||
void csky_dsp2_convolve_HWC_q15_basic(const q15_t * Im_in,
|
||||
const uint16_t dim_im_in,
|
||||
const uint16_t ch_im_in,
|
||||
const q15_t * wt,
|
||||
const uint16_t ch_im_out,
|
||||
const uint16_t dim_kernel,
|
||||
const uint16_t padding,
|
||||
const uint16_t stride,
|
||||
const q15_t * bias,
|
||||
const uint16_t bias_shift,
|
||||
const uint16_t out_shift,
|
||||
q15_t * Im_out,
|
||||
const uint16_t dim_im_out,
|
||||
q15_t * bufferA);
|
||||
|
||||
/**
|
||||
* @brief Fast Q7 convolution function
|
||||
* @param[in] Im_in pointer to input tensor
|
||||
* @param[in] dim_im_in input tensor dimention
|
||||
* @param[in] ch_im_in number of input tensor channels
|
||||
* @param[in] wt pointer to kernel weights
|
||||
* @param[in] ch_im_out number of filters, i.e., output tensor channels
|
||||
* @param[in] dim_kernel filter kernel size
|
||||
* @param[in] padding padding sizes
|
||||
* @param[in] stride convolution stride
|
||||
* @param[in] bias pointer to bias
|
||||
* @param[in] bias_shift amount of left-shift for bias
|
||||
* @param[in] out_shift amount of right-shift for output
|
||||
* @param[in,out] Im_out pointer to output tensor
|
||||
* @param[in] dim_im_out output tensor dimension
|
||||
* @param[in,out] bufferA pointer to buffer space for input
|
||||
* @return none.
|
||||
*
|
||||
* This function is the version with full list of optimization tricks, but with
|
||||
* some contraints:
|
||||
* ch_im_in is multiple of 4
|
||||
* ch_im_out is multiple of 2
|
||||
*/
|
||||
|
||||
void csky_dsp2_convolve_HWC_q7_fast(const q7_t * Im_in,
|
||||
const uint16_t dim_im_in,
|
||||
const uint16_t ch_im_in,
|
||||
const q7_t * wt,
|
||||
const uint16_t ch_im_out,
|
||||
const uint16_t dim_kernel,
|
||||
const uint16_t padding,
|
||||
const uint16_t stride,
|
||||
const q7_t * bias,
|
||||
const uint16_t bias_shift,
|
||||
const uint16_t out_shift,
|
||||
q7_t * Im_out,
|
||||
const uint16_t dim_im_out,
|
||||
q15_t * bufferA);
|
||||
|
||||
/**
|
||||
* @brief Fast Q7 convolution function (non-sqaure shape)
|
||||
* @param[in] Im_in pointer to input tensor
|
||||
* @param[in] dim_im_in_x input tensor dimention x
|
||||
* @param[in] dim_im_in_y input tensor dimention y
|
||||
* @param[in] ch_im_in number of input tensor channels
|
||||
* @param[in] wt pointer to kernel weights
|
||||
* @param[in] ch_im_out number of filters, i.e., output tensor channels
|
||||
* @param[in] dim_kernel_x filter kernel size x
|
||||
* @param[in] dim_kernel_y filter kernel size y
|
||||
* @param[in] padding_x padding size x
|
||||
* @param[in] padding_y padding size y
|
||||
* @param[in] stride_x convolution stride x
|
||||
* @param[in] stride_y convolution stride y
|
||||
* @param[in] bias pointer to bias
|
||||
* @param[in] bias_shift amount of left-shift for bias
|
||||
* @param[in] out_shift amount of right-shift for output
|
||||
* @param[in,out] Im_out pointer to output tensor
|
||||
* @param[in] dim_im_out_x output tensor dimension x
|
||||
* @param[in] dim_im_out_y output tensor dimension y
|
||||
* @param[in,out] bufferA pointer to buffer space for input
|
||||
* @return none.
|
||||
*
|
||||
* This function is the version with full list of optimization tricks, but with
|
||||
* some contraints:
|
||||
* ch_im_in is multiple of 4
|
||||
* ch_im_out is multiple of 2
|
||||
*/
|
||||
|
||||
void csky_dsp2_convolve_HWC_q7_fast_nonsquare(const q7_t * Im_in,
|
||||
const uint16_t dim_im_in_x,
|
||||
const uint16_t dim_im_in_y,
|
||||
const uint16_t ch_im_in,
|
||||
const q7_t * wt,
|
||||
const uint16_t ch_im_out,
|
||||
const uint16_t dim_kernel_x,
|
||||
const uint16_t dim_kernel_y,
|
||||
const uint16_t padding_x,
|
||||
const uint16_t padding_y,
|
||||
const uint16_t stride_x,
|
||||
const uint16_t stride_y,
|
||||
const q7_t * bias,
|
||||
const uint16_t bias_shift,
|
||||
const uint16_t out_shift,
|
||||
q7_t * Im_out,
|
||||
const uint16_t dim_im_out_x,
|
||||
const uint16_t dim_im_out_y,
|
||||
q15_t * bufferA);
|
||||
|
||||
/**
|
||||
* @brief Fast Q7 version of 1x1 convolution (non-sqaure shape)
|
||||
* @param[in] Im_in pointer to input tensor
|
||||
* @param[in] dim_im_in_x input tensor dimention x
|
||||
* @param[in] dim_im_in_y input tensor dimention y
|
||||
* @param[in] ch_im_in number of input tensor channels
|
||||
* @param[in] wt pointer to kernel weights
|
||||
* @param[in] ch_im_out number of filters, i.e., output tensor channels
|
||||
* @param[in] dim_kernel_x filter kernel size x
|
||||
* @param[in] dim_kernel_y filter kernel size y
|
||||
* @param[in] padding_x padding size x
|
||||
* @param[in] padding_y padding size y
|
||||
* @param[in] stride_x convolution stride x
|
||||
* @param[in] stride_y convolution stride y
|
||||
* @param[in] bias pointer to bias
|
||||
* @param[in] bias_shift amount of left-shift for bias
|
||||
* @param[in] out_shift amount of right-shift for output
|
||||
* @param[in,out] Im_out pointer to output tensor
|
||||
* @param[in] dim_im_out_x output tensor dimension x
|
||||
* @param[in] dim_im_out_y output tensor dimension y
|
||||
* @param[in,out] bufferA pointer to buffer space for input
|
||||
* @return none.
|
||||
*
|
||||
* This function implement convolution with 1x1 kernel size (i.e., dim_kernel_x=1
|
||||
* and dim_kernel_y=1). It can be used for
|
||||
* second half of MobileNets after depthwise separable convolution.
|
||||
*
|
||||
* This function is the version with full list of optimization tricks, but with
|
||||
* some contraints:
|
||||
* ch_im_in is multiple of 4
|
||||
* ch_im_out is multiple of 2
|
||||
*/
|
||||
void csky_dsp2_convolve_1x1_HWC_q7_fast(const q7_t * Im_in,
|
||||
const uint16_t dim_im_in_x,
|
||||
const uint16_t dim_im_in_y,
|
||||
const uint16_t ch_im_in,
|
||||
const q7_t * wt,
|
||||
const uint16_t ch_im_out,
|
||||
const q7_t * bias,
|
||||
const uint16_t bias_shift,
|
||||
const uint16_t out_shift,
|
||||
q7_t * Im_out,
|
||||
const uint16_t dim_im_out_x,
|
||||
const uint16_t dim_im_out_y,
|
||||
q15_t * bufferA);
|
||||
|
||||
/**
|
||||
* @brief Q7 version of convolution for RGB image
|
||||
* @param[in] Im_in pointer to input tensor
|
||||
* @param[in] dim_im_in input tensor dimention
|
||||
* @param[in] ch_im_in number of input tensor channels
|
||||
* @param[in] wt pointer to kernel weights
|
||||
* @param[in] ch_im_out number of filters, i.e., output tensor channels
|
||||
* @param[in] dim_kernel filter kernel size
|
||||
* @param[in] padding padding sizes
|
||||
* @param[in] stride convolution stride
|
||||
* @param[in] bias pointer to bias
|
||||
* @param[in] bias_shift amount of left-shift for bias
|
||||
* @param[in] out_shift amount of right-shift for output
|
||||
* @param[in,out] Im_out pointer to output tensor
|
||||
* @param[in] dim_im_out output tensor dimension
|
||||
* @param[in,out] bufferA pointer to buffer space for input
|
||||
* @return none.
|
||||
*
|
||||
* This kernel is written exclusively for convolution with ch_im_in
|
||||
* equals 3. This applies on the first layer of CNNs which has input
|
||||
* image with RGB format.
|
||||
*/
|
||||
|
||||
void csky_dsp2_convolve_HWC_q7_RGB(const q7_t * Im_in,
|
||||
const uint16_t dim_im_in,
|
||||
const q7_t * wt,
|
||||
const uint16_t ch_im_out,
|
||||
const uint16_t dim_kernel,
|
||||
const uint16_t padding,
|
||||
const uint16_t stride,
|
||||
const q7_t * bias,
|
||||
const uint16_t bias_shift,
|
||||
const uint16_t out_shift,
|
||||
q7_t * Im_out,
|
||||
const uint16_t dim_im_out,
|
||||
q15_t * bufferA);
|
||||
|
||||
/**
|
||||
* @brief Fast Q15 convolution function
|
||||
* @param[in] Im_in pointer to input tensor
|
||||
* @param[in] dim_im_in input tensor dimention
|
||||
* @param[in] ch_im_in number of input tensor channels
|
||||
* @param[in] wt pointer to kernel weights
|
||||
* @param[in] ch_im_out number of filters, i.e., output tensor channels
|
||||
* @param[in] dim_kernel filter kernel size
|
||||
* @param[in] padding padding sizes
|
||||
* @param[in] stride convolution stride
|
||||
* @param[in] bias pointer to bias
|
||||
* @param[in] bias_shift amount of left-shift for bias
|
||||
* @param[in] out_shift amount of right-shift for output
|
||||
* @param[in,out] Im_out pointer to output tensor
|
||||
* @param[in] dim_im_out output tensor dimension
|
||||
* @param[in,out] bufferA pointer to buffer space for input
|
||||
* @return none.
|
||||
*
|
||||
* This function is the version with full list of optimization tricks, but with
|
||||
* some contraints:
|
||||
* ch_im_in is multiple of 2
|
||||
* ch_im_out is multiple of 2
|
||||
*/
|
||||
|
||||
void csky_dsp2_convolve_HWC_q15_fast(const q15_t * Im_in,
|
||||
const uint16_t dim_im_in,
|
||||
const uint16_t ch_im_in,
|
||||
const q15_t * wt,
|
||||
const uint16_t ch_im_out,
|
||||
const uint16_t dim_kernel,
|
||||
const uint16_t padding,
|
||||
const uint16_t stride,
|
||||
const q15_t * bias,
|
||||
const uint16_t bias_shift,
|
||||
const uint16_t out_shift,
|
||||
q15_t * Im_out,
|
||||
const uint16_t dim_im_out,
|
||||
q15_t * bufferA);
|
||||
|
||||
/**
|
||||
* @brief Q7 depthwise separable convolution function
|
||||
* @param[in] Im_in pointer to input tensor
|
||||
* @param[in] dim_im_in input tensor dimention
|
||||
* @param[in] ch_im_in number of input tensor channels
|
||||
* @param[in] wt pointer to kernel weights
|
||||
* @param[in] ch_im_out number of filters, i.e., output tensor channels
|
||||
* @param[in] dim_kernel filter kernel size
|
||||
* @param[in] padding padding sizes
|
||||
* @param[in] stride convolution stride
|
||||
* @param[in] bias pointer to bias
|
||||
* @param[in] bias_shift amount of left-shift for bias
|
||||
* @param[in] out_shift amount of right-shift for output
|
||||
* @param[in,out] Im_out pointer to output tensor
|
||||
* @param[in] dim_im_out output tensor dimension
|
||||
* @param[in,out] bufferA pointer to buffer space for input
|
||||
* @return none.
|
||||
*
|
||||
* This function is the version with full list of optimization tricks, but with
|
||||
* some contraints:
|
||||
* ch_im_in is multiple of 2
|
||||
* ch_im_out is multiple of 2
|
||||
*/
|
||||
|
||||
void csky_dsp2_depthwise_separable_conv_HWC_q7(const q7_t * Im_in,
|
||||
const uint16_t dim_im_in,
|
||||
const uint16_t ch_im_in,
|
||||
const q7_t * wt,
|
||||
const uint16_t ch_im_out,
|
||||
const uint16_t dim_kernel,
|
||||
const uint16_t padding,
|
||||
const uint16_t stride,
|
||||
const q7_t * bias,
|
||||
const uint16_t bias_shift,
|
||||
const uint16_t out_shift,
|
||||
q7_t * Im_out,
|
||||
const uint16_t dim_im_out,
|
||||
q15_t * bufferA);
|
||||
|
||||
/**
|
||||
* @brief Q7 depthwise separable convolution function (non-square shape)
|
||||
* @param[in] Im_in pointer to input tensor
|
||||
* @param[in] dim_im_in_x input tensor dimention x
|
||||
* @param[in] dim_im_in_y input tensor dimention y
|
||||
* @param[in] ch_im_in number of input tensor channels
|
||||
* @param[in] wt pointer to kernel weights
|
||||
* @param[in] ch_im_out number of filters, i.e., output tensor channels
|
||||
* @param[in] dim_kernel_x filter kernel size x
|
||||
* @param[in] dim_kernel_y filter kernel size y
|
||||
* @param[in] padding_x padding sizes x
|
||||
* @param[in] padding_y padding sizes y
|
||||
* @param[in] stride_x convolution stride x
|
||||
* @param[in] stride_y convolution stride y
|
||||
* @param[in] bias pointer to bias
|
||||
* @param[in] bias_shift amount of left-shift for bias
|
||||
* @param[in] out_shift amount of right-shift for output
|
||||
* @param[in,out] Im_out pointer to output tensor
|
||||
* @param[in] dim_im_out_x output tensor dimension x
|
||||
* @param[in] dim_im_out_y output tensor dimension y
|
||||
* @param[in,out] bufferA pointer to buffer space for input
|
||||
* @return none.
|
||||
*
|
||||
* This function is the version with full list of optimization tricks, but with
|
||||
* some contraints:
|
||||
* ch_im_in is multiple of 2
|
||||
* ch_im_out is multiple of 2
|
||||
*/
|
||||
void csky_dsp2_depthwise_separable_conv_HWC_q7_nonsquare(const q7_t * Im_in,
|
||||
const uint16_t dim_im_in_x,
|
||||
const uint16_t dim_im_in_y,
|
||||
const uint16_t ch_im_in,
|
||||
const q7_t * wt,
|
||||
const uint16_t ch_im_out,
|
||||
const uint16_t dim_kernel_x,
|
||||
const uint16_t dim_kernel_y,
|
||||
const uint16_t padding_x,
|
||||
const uint16_t padding_y,
|
||||
const uint16_t stride_x,
|
||||
const uint16_t stride_y,
|
||||
const q7_t * bias,
|
||||
const uint16_t bias_shift,
|
||||
const uint16_t out_shift,
|
||||
q7_t * Im_out,
|
||||
const uint16_t dim_im_out_x,
|
||||
const uint16_t dim_im_out_y,
|
||||
q15_t * bufferA);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Q7 basic fully-connected layer function
|
||||
* @param[in] pV pointer to input vector
|
||||
* @param[in] pM pointer to matrix weights
|
||||
* @param[in] dim_vec length of the vector
|
||||
* @param[in] num_of_rows number of rows in weight matrix
|
||||
* @param[in] bias_shift amount of left-shift for bias
|
||||
* @param[in] out_shift amount of right-shift for output
|
||||
* @param[in] bias pointer to bias
|
||||
* @param[in,out] pOut pointer to output vector
|
||||
* @return none.
|
||||
*/
|
||||
|
||||
void csky_dsp2_fully_connected_q7(const q7_t * pV,
|
||||
const q7_t * pM,
|
||||
const uint16_t dim_vec,
|
||||
const uint16_t num_of_rows,
|
||||
const uint16_t bias_shift,
|
||||
const uint16_t out_shift,
|
||||
const q7_t * bias,
|
||||
q7_t * pOut);
|
||||
|
||||
/**
|
||||
* @brief Q7 opt fully-connected layer function
|
||||
* @param[in] pV pointer to input vector
|
||||
* @param[in] pM pointer to matrix weights
|
||||
* @param[in] dim_vec length of the vector
|
||||
* @param[in] num_of_rows number of rows in weight matrix
|
||||
* @param[in] bias_shift amount of left-shift for bias
|
||||
* @param[in] out_shift amount of right-shift for output
|
||||
* @param[in] bias pointer to bias
|
||||
* @param[in,out] pOut pointer to output vector
|
||||
* @param[in,out] vec_buffer pointer to buffer space for input
|
||||
* @return none.
|
||||
*
|
||||
*/
|
||||
|
||||
void csky_dsp2_fully_connected_q7_opt(const q7_t * pV,
|
||||
const q7_t * pM,
|
||||
const uint16_t dim_vec,
|
||||
const uint16_t num_of_rows,
|
||||
const uint16_t bias_shift,
|
||||
const uint16_t out_shift,
|
||||
const q7_t * bias,
|
||||
q7_t * pOut,
|
||||
q15_t * vec_buffer);
|
||||
|
||||
/**
|
||||
* @brief Q15 basic fully-connected layer function
|
||||
* @param[in] pV pointer to input vector
|
||||
* @param[in] pM pointer to matrix weights
|
||||
* @param[in] dim_vec length of the vector
|
||||
* @param[in] num_of_rows number of rows in weight matrix
|
||||
* @param[in] bias_shift amount of left-shift for bias
|
||||
* @param[in] out_shift amount of right-shift for output
|
||||
* @param[in] bias pointer to bias
|
||||
* @param[in,out] pOut pointer to output vector
|
||||
* @return none.
|
||||
*
|
||||
*/
|
||||
|
||||
void csky_dsp2_fully_connected_q15(const q15_t * pV,
|
||||
const q15_t * pM,
|
||||
const uint16_t dim_vec,
|
||||
const uint16_t num_of_rows,
|
||||
const uint16_t bias_shift,
|
||||
const uint16_t out_shift,
|
||||
const q15_t * bias,
|
||||
q15_t * pOut);
|
||||
|
||||
/**
|
||||
* @brief Q15 opt fully-connected layer function
|
||||
* @param[in] pV pointer to input vector
|
||||
* @param[in] pM pointer to matrix weights
|
||||
* @param[in] dim_vec length of the vector
|
||||
* @param[in] num_of_rows number of rows in weight matrix
|
||||
* @param[in] bias_shift amount of left-shift for bias
|
||||
* @param[in] out_shift amount of right-shift for output
|
||||
* @param[in] bias pointer to bias
|
||||
* @param[in,out] pOut pointer to output vector
|
||||
* @return none.
|
||||
*
|
||||
*/
|
||||
|
||||
void csky_dsp2_fully_connected_q15_opt(const q15_t * pV,
|
||||
const q15_t * pM,
|
||||
const uint16_t dim_vec,
|
||||
const uint16_t num_of_rows,
|
||||
const uint16_t bias_shift,
|
||||
const uint16_t out_shift,
|
||||
const q15_t * bias,
|
||||
q15_t * pOut);
|
||||
|
||||
/**
|
||||
* @brief Mixed Q15-Q7 fully-connected layer function
|
||||
* @param[in] pV pointer to input vector
|
||||
* @param[in] pM pointer to matrix weights
|
||||
* @param[in] dim_vec length of the vector
|
||||
* @param[in] num_of_rows number of rows in weight matrix
|
||||
* @param[in] bias_shift amount of left-shift for bias
|
||||
* @param[in] out_shift amount of right-shift for output
|
||||
* @param[in] bias pointer to bias
|
||||
* @param[in,out] pOut pointer to output vector
|
||||
* @return none.
|
||||
*
|
||||
*/
|
||||
|
||||
void csky_dsp2_fully_connected_mat_q7_vec_q15(const q15_t * pV,
|
||||
const q7_t * pM,
|
||||
const uint16_t dim_vec,
|
||||
const uint16_t num_of_rows,
|
||||
const uint16_t bias_shift,
|
||||
const uint16_t out_shift,
|
||||
const q7_t * bias,
|
||||
q15_t * pOut);
|
||||
|
||||
/**
|
||||
* @brief Mixed Q15-Q7 opt fully-connected layer function
|
||||
* @param[in] pV pointer to input vector
|
||||
* @param[in] pM pointer to matrix weights
|
||||
* @param[in] dim_vec length of the vector
|
||||
* @param[in] num_of_rows number of rows in weight matrix
|
||||
* @param[in] bias_shift amount of left-shift for bias
|
||||
* @param[in] out_shift amount of right-shift for output
|
||||
* @param[in] bias pointer to bias
|
||||
* @param[in,out] pOut pointer to output vector
|
||||
* @return none.
|
||||
*
|
||||
*/
|
||||
|
||||
void csky_dsp2_fully_connected_mat_q7_vec_q15_opt(const q15_t * pV,
|
||||
const q7_t * pM,
|
||||
const uint16_t dim_vec,
|
||||
const uint16_t num_of_rows,
|
||||
const uint16_t bias_shift,
|
||||
const uint16_t out_shift,
|
||||
const q7_t * bias,
|
||||
q15_t * pOut);
|
||||
|
||||
/**
|
||||
* @brief Matrix-Multiplication Kernels for Convolution
|
||||
*
|
||||
* These functions are used within convolution layer functions for
|
||||
* matrix multiplication.
|
||||
*
|
||||
* The implementation is similar to CSI-DSP csky_dsp2_mat_mult functions
|
||||
* with one Q7 and one Q15 operands. The Q15 operand is the im2col
|
||||
* output which is always with 2 columns.
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Matrix-multiplication function for convolution
|
||||
* @param[in] pA pointer to operand A
|
||||
* @param[in] pInBuffer pointer to operand B, always conssists of 2 vectors
|
||||
* @param[in] ch_im_out numRow of A
|
||||
* @param[in] numCol_A numCol of A
|
||||
* @param[in] bias_shift amount of left-shift for bias
|
||||
* @param[in] out_shift amount of right-shift for output
|
||||
* @param[in] bias the bias
|
||||
* @param[in,out] pOut pointer to output
|
||||
* @return The function returns the incremented output pointer
|
||||
*/
|
||||
|
||||
q7_t *csky_dsp2_nn_mat_mult_kernel_q7_q15(const q7_t * pA,
|
||||
const q15_t * pInBuffer,
|
||||
const uint16_t ch_im_out,
|
||||
const uint16_t numCol_A,
|
||||
const uint16_t bias_shift,
|
||||
const uint16_t out_shift,
|
||||
const q7_t * bias,
|
||||
q7_t * pOut);
|
||||
|
||||
/**
|
||||
* @brief Matrix-multiplication function for convolution with reordered columns
|
||||
* @param[in] pA pointer to operand A
|
||||
* @param[in] pInBuffer pointer to operand B, always conssists of 2 vectors
|
||||
* @param[in] ch_im_out numRow of A
|
||||
* @param[in] numCol_A numCol of A
|
||||
* @param[in] bias_shift amount of left-shift for bias
|
||||
* @param[in] out_shift amount of right-shift for output
|
||||
* @param[in] bias the bias
|
||||
* @param[in,out] pOut pointer to output
|
||||
* @return The function returns the incremented output pointer
|
||||
*/
|
||||
|
||||
q7_t *csky_dsp2_nn_mat_mult_kernel_q7_q15_reordered(const q7_t * pA,
|
||||
const q15_t * pInBuffer,
|
||||
const uint16_t ch_im_out,
|
||||
const uint16_t numCol_A,
|
||||
const uint16_t bias_shift,
|
||||
const uint16_t out_shift,
|
||||
const q7_t * bias,
|
||||
q7_t * pOut);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Other functions
|
||||
* These layers are typically not timing critical
|
||||
* Basic implementation is supported here
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
* @brief Q7 RELU function
|
||||
* @param[in,out] data pointer to input
|
||||
* @param[in] size number of elements
|
||||
* @return none.
|
||||
*/
|
||||
|
||||
void csky_dsp2_relu_q7(q7_t * data, uint16_t size);
|
||||
|
||||
/**
|
||||
* @brief Q15 RELU function
|
||||
* @param[in,out] data pointer to input
|
||||
* @param[in] size number of elements
|
||||
* @return none.
|
||||
*/
|
||||
|
||||
void csky_dsp2_relu_q15(q15_t * data, uint16_t size);
|
||||
|
||||
/**
|
||||
* @brief Q7 neural network activation function using direct table look-up
|
||||
* @param[in,out] data pointer to input
|
||||
* @param[in] size number of elements
|
||||
* @param[in] int_width bit-width of the integer part, assume to be smaller than 3
|
||||
* @param[in] type type of activation functions
|
||||
* @return none.
|
||||
*/
|
||||
|
||||
void csky_dsp2_nn_activations_direct_q7(q7_t * data, uint16_t size,
|
||||
uint16_t int_width,
|
||||
csky_dsp2_nn_activation_type type);
|
||||
|
||||
/**
|
||||
* @brief Q15 neural network activation function using direct table look-up
|
||||
* @param[in,out] data pointer to input
|
||||
* @param[in] size number of elements
|
||||
* @param[in] int_width bit-width of the integer part, assume to be smaller than 3
|
||||
* @param[in] type type of activation functions
|
||||
* @return none.
|
||||
*/
|
||||
|
||||
void csky_dsp2_nn_activations_direct_q15(q15_t * data, uint16_t size,
|
||||
uint16_t int_width,
|
||||
csky_dsp2_nn_activation_type type);
|
||||
|
||||
/**
|
||||
* @brief Q7 max pooling function
|
||||
* @param[in] Im_in pointer to input tensor
|
||||
* @param[in] dim_im_in input tensor dimention
|
||||
* @param[in] ch_im_in number of input tensor channels
|
||||
* @param[in] dim_kernel filter kernel size
|
||||
* @param[in] padding padding sizes
|
||||
* @param[in] stride convolution stride
|
||||
* @param[in] dim_im_out output tensor dimension
|
||||
* @param[in,out] bufferA pointer to buffer space for input
|
||||
* @param[in,out] Im_out pointer to output tensor
|
||||
* @return none.
|
||||
*
|
||||
*/
|
||||
|
||||
void csky_dsp2_maxpool_q7_HWC(q7_t * Im_in,
|
||||
const uint16_t dim_im_in,
|
||||
const uint16_t ch_im_in,
|
||||
const uint16_t dim_kernel,
|
||||
const uint16_t padding,
|
||||
const uint16_t stride,
|
||||
const uint16_t dim_im_out,
|
||||
q7_t * bufferA,
|
||||
q7_t * Im_out);
|
||||
|
||||
/**
|
||||
* @brief Q7 average pooling function
|
||||
* @param[in] Im_in pointer to input tensor
|
||||
* @param[in] dim_im_in input tensor dimention
|
||||
* @param[in] ch_im_in number of input tensor channels
|
||||
* @param[in] dim_kernel filter kernel size
|
||||
* @param[in] padding padding sizes
|
||||
* @param[in] stride convolution stride
|
||||
* @param[in] dim_im_out output tensor dimension
|
||||
* @param[in,out] bufferA pointer to buffer space for input
|
||||
* @param[in,out] Im_out pointer to output tensor
|
||||
* @return none.
|
||||
*
|
||||
*/
|
||||
|
||||
void csky_dsp2_avepool_q7_HWC(q7_t * Im_in,
|
||||
const uint16_t dim_im_in,
|
||||
const uint16_t ch_im_in,
|
||||
const uint16_t dim_kernel,
|
||||
const uint16_t padding,
|
||||
const uint16_t stride,
|
||||
const uint16_t dim_im_out,
|
||||
q7_t * bufferA,
|
||||
q7_t * Im_out);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Q7 softmax function
|
||||
* @param[in] vec_in pointer to input vector
|
||||
* @param[in] dim_vec input vector dimention
|
||||
* @param[out] p_out pointer to output vector
|
||||
* @return none.
|
||||
*
|
||||
*/
|
||||
|
||||
void csky_dsp2_softmax_q7(const q7_t *vec_in, const uint16_t dim_vec, q7_t *p_out);
|
||||
|
||||
/**
|
||||
* @brief Q15 softmax function
|
||||
* @param[in] vec_in pointer to input vector
|
||||
* @param[in] dim_vec input vector dimention
|
||||
* @param[out] p_out pointer to output vector
|
||||
* @return none.
|
||||
*
|
||||
*/
|
||||
|
||||
void csky_dsp2_softmax_q15(const q15_t *vec_in, const uint16_t dim_vec,
|
||||
q15_t *p_out);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
132
csky/csi_dsp/include/csky_dsp2_nnsupportfunctions.h
Normal file
132
csky/csi_dsp/include/csky_dsp2_nnsupportfunctions.h
Normal file
@@ -0,0 +1,132 @@
|
||||
/*
|
||||
* Copyright (C) 2016-2019 C-SKY Limited. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
* Title: csky_dsp2_nnsupportfunctions.h
|
||||
* Description: Public header file of support functions for CSI NN Library
|
||||
*
|
||||
* -------------------------------------------------------------------- */
|
||||
|
||||
#ifndef _CSKY_DSP2_NNSUPPORTFUNCTIONS_H_
|
||||
#define _CSKY_DSP2_NNSUPPORTFUNCTIONS_H_
|
||||
|
||||
#include "csky_math.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Union for SIMD access of Q31/Q15/Q7 types
|
||||
*/
|
||||
union csky_dsp2_nnword
|
||||
{
|
||||
q31_t word; /**< Q31 type */
|
||||
q15_t half_words[2]; /**< Q15 type */
|
||||
q7_t bytes[4]; /**< Q7 type */
|
||||
};
|
||||
|
||||
/**
|
||||
* @defgroup nndata_convert Neural Network Data Conversion Functions
|
||||
*
|
||||
* Perform data type conversion in-between neural network operations
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Converts the elements of the Q7 vector to Q15 vector without left-shift
|
||||
* @param[in] *pSrc points to the Q7 input vector
|
||||
* @param[out] *pDst points to the Q15 output vector
|
||||
* @param[in] blockSize length of the input vector
|
||||
* @return none.
|
||||
*
|
||||
*/
|
||||
|
||||
void csky_dsp2_q7_to_q15_no_shift(const q7_t * pSrc, q15_t * pDst,
|
||||
uint32_t blockSize);
|
||||
|
||||
/**
|
||||
* @brief Converts the elements of the Q7 vector to reordered Q15 vector without left-shift
|
||||
* @param[in] *pSrc points to the Q7 input vector
|
||||
* @param[out] *pDst points to the Q15 output vector
|
||||
* @param[in] blockSize length of the input vector
|
||||
* @return none.
|
||||
*
|
||||
*/
|
||||
|
||||
void csky_dsp2_q7_to_q15_reordered_no_shift(const q7_t * pSrc, q15_t * pDst,
|
||||
uint32_t blockSize);
|
||||
|
||||
#if defined (CSKY_MATH_DSP)
|
||||
|
||||
/**
|
||||
* @brief read and expand one Q7 word into two Q15 words
|
||||
*/
|
||||
|
||||
__ALWAYS_INLINE void *read_and_pad(void *source, q31_t *out1, q31_t *out2)
|
||||
{
|
||||
q31_t inA = *__SIMD32(source)++;
|
||||
q31_t inAbuf1 = __SXTB16(__ROR(inA, 8));
|
||||
q31_t inAbuf2 = __SXTB16(inA);
|
||||
|
||||
#ifndef CSKY_MATH_BIG_ENDIAN
|
||||
*out2 = __PKHTB(inAbuf1, inAbuf2, 16);
|
||||
*out1 = __PKHBT(inAbuf2, inAbuf1, 16);
|
||||
#else
|
||||
*out1 = __PKHTB(inAbuf1, inAbuf2, 16);
|
||||
*out2 = __PKHBT(inAbuf2, inAbuf1, 16);
|
||||
#endif
|
||||
|
||||
return source;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief read and expand one Q7 word into two Q15 words with reordering
|
||||
*/
|
||||
|
||||
__ALWAYS_INLINE void *read_and_pad_reordered(void *source, q31_t * out1,
|
||||
q31_t * out2)
|
||||
{
|
||||
q31_t inA = *__SIMD32(source)++;
|
||||
#ifndef CSKY_MATH_BIG_ENDIAN
|
||||
*out2 = __SXTB16(__ROR(inA, 8));
|
||||
*out1 = __SXTB16(inA);
|
||||
#else
|
||||
*out1 = __SXTB16(__ROR(inA, 8));
|
||||
*out2 = __SXTB16(inA);
|
||||
#endif
|
||||
|
||||
return source;
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief defition to adding rouding offset
|
||||
*/
|
||||
#ifndef CSKY_NN_TRUNCATE
|
||||
#define NN_ROUND(out_shift) ( 0x1 << (out_shift - 1) )
|
||||
#else
|
||||
#define NN_ROUND(out_shift) 0
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
4637
csky/csi_dsp/include/csky_math.h
Normal file
4637
csky/csi_dsp/include/csky_math.h
Normal file
File diff suppressed because it is too large
Load Diff
54
csky/csi_dsp/include/csky_nn_tables.h
Normal file
54
csky/csi_dsp/include/csky_nn_tables.h
Normal file
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright (C) 2016-2019 C-SKY Limited. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
* Title: csky_nn_tables.h
|
||||
* Description: Extern declaration for NN tables
|
||||
* -------------------------------------------------------------------- */
|
||||
|
||||
#ifndef _CSKY_NN_TABLES_H
|
||||
#define _CSKY_NN_TABLES_H
|
||||
|
||||
#include "csky_vdsp2_math.h"
|
||||
|
||||
/**
|
||||
* @brief tables for various activation functions
|
||||
*
|
||||
*/
|
||||
|
||||
extern const q15_t sigmoidTable_q15[256];
|
||||
extern const q7_t sigmoidTable_q7[256];
|
||||
|
||||
extern const q7_t tanhTable_q7[256];
|
||||
extern const q15_t tanhTable_q15[256];
|
||||
|
||||
/**
|
||||
* @brief 2-way tables for various activation functions
|
||||
*
|
||||
* 2-way table, H table for value larger than 1/4
|
||||
* L table for value smaller than 1/4, H table for remaining
|
||||
* We have this only for the q15_t version. It does not make
|
||||
* sense to have it for q7_t type
|
||||
*/
|
||||
extern const q15_t sigmoidHTable_q15[192];
|
||||
extern const q15_t sigmoidLTable_q15[128];
|
||||
|
||||
extern const q15_t sigmoidLTable_q15[128];
|
||||
extern const q15_t sigmoidHTable_q15[192];
|
||||
|
||||
#endif /* CSKY_NN_TABLES_H */
|
||||
232
csky/csi_dsp/include/csky_vdsp2_const_structs.h
Normal file
232
csky/csi_dsp/include/csky_vdsp2_const_structs.h
Normal file
@@ -0,0 +1,232 @@
|
||||
/*
|
||||
* Copyright (C) 2016-2019 C-SKY Limited. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/******************************************************************************
|
||||
* @file csky_vdsp2_const_structs.h
|
||||
* @brief This file has constant structs that are initialized for
|
||||
* user convenience. For example, some can be given as
|
||||
* arguments to the csky_vdsp2_cfft_f32() function.
|
||||
* @version V1.0
|
||||
* @date 20. Dec 2016
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef _CSKY_CONST_STRUCTS_H
|
||||
#define _CSKY_CONST_STRUCTS_H
|
||||
|
||||
#include "csky_vdsp2_math.h"
|
||||
#include "csky_common_tables.h"
|
||||
|
||||
extern const csky_vdsp2_cfft_instance_f32 csky_vdsp2_cfft_sR_f32_len16;
|
||||
extern const csky_vdsp2_cfft_instance_f32 csky_vdsp2_cfft_sR_f32_len32;
|
||||
extern const csky_vdsp2_cfft_instance_f32 csky_vdsp2_cfft_sR_f32_len64;
|
||||
extern const csky_vdsp2_cfft_instance_f32 csky_vdsp2_cfft_sR_f32_len128;
|
||||
extern const csky_vdsp2_cfft_instance_f32 csky_vdsp2_cfft_sR_f32_len256;
|
||||
extern const csky_vdsp2_cfft_instance_f32 csky_vdsp2_cfft_sR_f32_len512;
|
||||
extern const csky_vdsp2_cfft_instance_f32 csky_vdsp2_cfft_sR_f32_len1024;
|
||||
extern const csky_vdsp2_cfft_instance_f32 csky_vdsp2_cfft_sR_f32_len2048;
|
||||
extern const csky_vdsp2_cfft_instance_f32 csky_vdsp2_cfft_sR_f32_len4096;
|
||||
|
||||
extern const csky_vdsp2_cfft_instance_f32 csky_vdsp2_cfft_radix4_sR_f32_len16;
|
||||
extern const csky_vdsp2_cfft_instance_f32 csky_vdsp2_cfft_radix4_sR_f32_len32;
|
||||
extern const csky_vdsp2_cfft_instance_f32 csky_vdsp2_cfft_radix4_sR_f32_len64;
|
||||
extern const csky_vdsp2_cfft_instance_f32 csky_vdsp2_cfft_radix4_sR_f32_len128;
|
||||
extern const csky_vdsp2_cfft_instance_f32 csky_vdsp2_cfft_radix4_sR_f32_len256;
|
||||
extern const csky_vdsp2_cfft_instance_f32 csky_vdsp2_cfft_radix4_sR_f32_len512;
|
||||
extern const csky_vdsp2_cfft_instance_f32 csky_vdsp2_cfft_radix4_sR_f32_len1024;
|
||||
extern const csky_vdsp2_cfft_instance_f32 csky_vdsp2_cfft_radix4_sR_f32_len2048;
|
||||
extern const csky_vdsp2_cfft_instance_f32 csky_vdsp2_cfft_radix4_sR_f32_len4096;
|
||||
|
||||
extern const csky_vdsp2_cfft_instance_f32 csky_vdsp2_cfft_radix4_fast_sR_f32_len16;
|
||||
extern const csky_vdsp2_cfft_instance_f32 csky_vdsp2_cfft_radix4_fast_sR_f32_len32;
|
||||
extern const csky_vdsp2_cfft_instance_f32 csky_vdsp2_cfft_radix4_fast_sR_f32_len64;
|
||||
extern const csky_vdsp2_cfft_instance_f32 csky_vdsp2_cfft_radix4_fast_sR_f32_len128;
|
||||
extern const csky_vdsp2_cfft_instance_f32 csky_vdsp2_cfft_radix4_fast_sR_f32_len256;
|
||||
extern const csky_vdsp2_cfft_instance_f32 csky_vdsp2_cfft_radix4_fast_sR_f32_len512;
|
||||
extern const csky_vdsp2_cfft_instance_f32 csky_vdsp2_cfft_radix4_fast_sR_f32_len1024;
|
||||
extern const csky_vdsp2_cfft_instance_f32 csky_vdsp2_cfft_radix4_fast_sR_f32_len2048;
|
||||
extern const csky_vdsp2_cfft_instance_f32 csky_vdsp2_cfft_radix4_fast_sR_f32_len4096;
|
||||
|
||||
extern const csky_vdsp2_cfft_instance_f32 csky_vdsp2_cfft_radix2_sR_f32_len16;
|
||||
extern const csky_vdsp2_cfft_instance_f32 csky_vdsp2_cfft_radix2_sR_f32_len32;
|
||||
extern const csky_vdsp2_cfft_instance_f32 csky_vdsp2_cfft_radix2_sR_f32_len64;
|
||||
extern const csky_vdsp2_cfft_instance_f32 csky_vdsp2_cfft_radix2_sR_f32_len128;
|
||||
extern const csky_vdsp2_cfft_instance_f32 csky_vdsp2_cfft_radix2_sR_f32_len256;
|
||||
extern const csky_vdsp2_cfft_instance_f32 csky_vdsp2_cfft_radix2_sR_f32_len512;
|
||||
extern const csky_vdsp2_cfft_instance_f32 csky_vdsp2_cfft_radix2_sR_f32_len1024;
|
||||
extern const csky_vdsp2_cfft_instance_f32 csky_vdsp2_cfft_radix2_sR_f32_len2048;
|
||||
extern const csky_vdsp2_cfft_instance_f32 csky_vdsp2_cfft_radix2_sR_f32_len4096;
|
||||
|
||||
extern const csky_vdsp2_cfft_instance_q31 csky_vdsp2_cfft_sR_q31_len16;
|
||||
extern const csky_vdsp2_cfft_instance_q31 csky_vdsp2_cfft_sR_q31_len32;
|
||||
extern const csky_vdsp2_cfft_instance_q31 csky_vdsp2_cfft_sR_q31_len64;
|
||||
extern const csky_vdsp2_cfft_instance_q31 csky_vdsp2_cfft_sR_q31_len128;
|
||||
extern const csky_vdsp2_cfft_instance_q31 csky_vdsp2_cfft_sR_q31_len256;
|
||||
extern const csky_vdsp2_cfft_instance_q31 csky_vdsp2_cfft_sR_q31_len512;
|
||||
extern const csky_vdsp2_cfft_instance_q31 csky_vdsp2_cfft_sR_q31_len1024;
|
||||
extern const csky_vdsp2_cfft_instance_q31 csky_vdsp2_cfft_sR_q31_len2048;
|
||||
extern const csky_vdsp2_cfft_instance_q31 csky_vdsp2_cfft_sR_q31_len4096;
|
||||
|
||||
extern const csky_vdsp2_cfft_instance_q15 csky_vdsp2_cfft_sR_q15_len16;
|
||||
extern const csky_vdsp2_cfft_instance_q15 csky_vdsp2_cfft_sR_q15_len32;
|
||||
extern const csky_vdsp2_cfft_instance_q15 csky_vdsp2_cfft_sR_q15_len64;
|
||||
extern const csky_vdsp2_cfft_instance_q15 csky_vdsp2_cfft_sR_q15_len128;
|
||||
extern const csky_vdsp2_cfft_instance_q15 csky_vdsp2_cfft_sR_q15_len256;
|
||||
extern const csky_vdsp2_cfft_instance_q15 csky_vdsp2_cfft_sR_q15_len512;
|
||||
extern const csky_vdsp2_cfft_instance_q15 csky_vdsp2_cfft_sR_q15_len1024;
|
||||
extern const csky_vdsp2_cfft_instance_q15 csky_vdsp2_cfft_sR_q15_len2048;
|
||||
extern const csky_vdsp2_cfft_instance_q15 csky_vdsp2_cfft_sR_q15_len4096;
|
||||
|
||||
extern const csky_vdsp2_cfft_instance_q15 csky_vdsp2_cfft_fast_sR_q15_len16;
|
||||
extern const csky_vdsp2_cfft_instance_q15 csky_vdsp2_cfft_fast_sR_q15_len32;
|
||||
extern const csky_vdsp2_cfft_instance_q15 csky_vdsp2_cfft_fast_sR_q15_len64;
|
||||
extern const csky_vdsp2_cfft_instance_q15 csky_vdsp2_cfft_fast_sR_q15_len128;
|
||||
extern const csky_vdsp2_cfft_instance_q15 csky_vdsp2_cfft_fast_sR_q15_len256;
|
||||
extern const csky_vdsp2_cfft_instance_q15 csky_vdsp2_cfft_fast_sR_q15_len512;
|
||||
extern const csky_vdsp2_cfft_instance_q15 csky_vdsp2_cfft_fast_sR_q15_len1024;
|
||||
extern const csky_vdsp2_cfft_instance_q15 csky_vdsp2_cfft_fast_sR_q15_len2048;
|
||||
extern const csky_vdsp2_cfft_instance_q15 csky_vdsp2_cfft_fast_sR_q15_len4096;
|
||||
|
||||
extern const csky_vdsp2_cfft_instance_q31 csky_vdsp2_cfft_fast_sR_q31_len16;
|
||||
extern const csky_vdsp2_cfft_instance_q31 csky_vdsp2_cfft_fast_sR_q31_len32;
|
||||
extern const csky_vdsp2_cfft_instance_q31 csky_vdsp2_cfft_fast_sR_q31_len64;
|
||||
extern const csky_vdsp2_cfft_instance_q31 csky_vdsp2_cfft_fast_sR_q31_len128;
|
||||
extern const csky_vdsp2_cfft_instance_q31 csky_vdsp2_cfft_fast_sR_q31_len256;
|
||||
extern const csky_vdsp2_cfft_instance_q31 csky_vdsp2_cfft_fast_sR_q31_len512;
|
||||
extern const csky_vdsp2_cfft_instance_q31 csky_vdsp2_cfft_fast_sR_q31_len1024;
|
||||
extern const csky_vdsp2_cfft_instance_q31 csky_vdsp2_cfft_fast_sR_q31_len2048;
|
||||
extern const csky_vdsp2_cfft_instance_q31 csky_vdsp2_cfft_fast_sR_q31_len4096;
|
||||
|
||||
extern csky_vdsp2_rfft_instance_q15 csky_vdsp2_rfft_sR_q15_len32;
|
||||
extern csky_vdsp2_rfft_instance_q15 csky_vdsp2_rfft_sR_q15_len64;
|
||||
extern csky_vdsp2_rfft_instance_q15 csky_vdsp2_rfft_sR_q15_len128;
|
||||
extern csky_vdsp2_rfft_instance_q15 csky_vdsp2_rfft_sR_q15_len256;
|
||||
extern csky_vdsp2_rfft_instance_q15 csky_vdsp2_rfft_sR_q15_len512;
|
||||
extern csky_vdsp2_rfft_instance_q15 csky_vdsp2_rfft_sR_q15_len1024;
|
||||
extern csky_vdsp2_rfft_instance_q15 csky_vdsp2_rfft_sR_q15_len2048;
|
||||
extern csky_vdsp2_rfft_instance_q15 csky_vdsp2_rfft_sR_q15_len4096;
|
||||
extern csky_vdsp2_rfft_instance_q15 csky_vdsp2_rfft_sR_q15_len8192;
|
||||
|
||||
|
||||
extern csky_vdsp2_rfft_instance_q15 csky_vdsp2_inv_rfft_sR_q15_len32;
|
||||
extern csky_vdsp2_rfft_instance_q15 csky_vdsp2_inv_rfft_sR_q15_len64;
|
||||
extern csky_vdsp2_rfft_instance_q15 csky_vdsp2_inv_rfft_sR_q15_len128;
|
||||
extern csky_vdsp2_rfft_instance_q15 csky_vdsp2_inv_rfft_sR_q15_len256;
|
||||
extern csky_vdsp2_rfft_instance_q15 csky_vdsp2_inv_rfft_sR_q15_len512;
|
||||
extern csky_vdsp2_rfft_instance_q15 csky_vdsp2_inv_rfft_sR_q15_len1024;
|
||||
extern csky_vdsp2_rfft_instance_q15 csky_vdsp2_inv_rfft_sR_q15_len2048;
|
||||
extern csky_vdsp2_rfft_instance_q15 csky_vdsp2_inv_rfft_sR_q15_len4096;
|
||||
extern csky_vdsp2_rfft_instance_q15 csky_vdsp2_inv_rfft_sR_q15_len8192;
|
||||
|
||||
extern csky_vdsp2_rfft_fast_instance_q15 csky_vdsp2_rfft_fast_sR_q15_len32;
|
||||
extern csky_vdsp2_rfft_fast_instance_q15 csky_vdsp2_rfft_fast_sR_q15_len64;
|
||||
extern csky_vdsp2_rfft_fast_instance_q15 csky_vdsp2_rfft_fast_sR_q15_len128;
|
||||
extern csky_vdsp2_rfft_fast_instance_q15 csky_vdsp2_rfft_fast_sR_q15_len256;
|
||||
extern csky_vdsp2_rfft_fast_instance_q15 csky_vdsp2_rfft_fast_sR_q15_len512;
|
||||
extern csky_vdsp2_rfft_fast_instance_q15 csky_vdsp2_rfft_fast_sR_q15_len1024;
|
||||
extern csky_vdsp2_rfft_fast_instance_q15 csky_vdsp2_rfft_fast_sR_q15_len2048;
|
||||
extern csky_vdsp2_rfft_fast_instance_q15 csky_vdsp2_rfft_fast_sR_q15_len4096;
|
||||
extern csky_vdsp2_rfft_fast_instance_q15 csky_vdsp2_rfft_fast_sR_q15_len8192;
|
||||
|
||||
|
||||
extern csky_vdsp2_rfft_fast_instance_q15 csky_vdsp2_inv_rfft_fast_sR_q15_len32;
|
||||
extern csky_vdsp2_rfft_fast_instance_q15 csky_vdsp2_inv_rfft_fast_sR_q15_len64;
|
||||
extern csky_vdsp2_rfft_fast_instance_q15 csky_vdsp2_inv_rfft_fast_sR_q15_len128;
|
||||
extern csky_vdsp2_rfft_fast_instance_q15 csky_vdsp2_inv_rfft_fast_sR_q15_len256;
|
||||
extern csky_vdsp2_rfft_fast_instance_q15 csky_vdsp2_inv_rfft_fast_sR_q15_len512;
|
||||
extern csky_vdsp2_rfft_fast_instance_q15 csky_vdsp2_inv_rfft_fast_sR_q15_len1024;
|
||||
extern csky_vdsp2_rfft_fast_instance_q15 csky_vdsp2_inv_rfft_fast_sR_q15_len2048;
|
||||
extern csky_vdsp2_rfft_fast_instance_q15 csky_vdsp2_inv_rfft_fast_sR_q15_len4096;
|
||||
extern csky_vdsp2_rfft_fast_instance_q15 csky_vdsp2_inv_rfft_fast_sR_q15_len8192;
|
||||
|
||||
|
||||
extern csky_vdsp2_rfft_instance_q31 csky_vdsp2_rfft_sR_q31_len32;
|
||||
extern csky_vdsp2_rfft_instance_q31 csky_vdsp2_rfft_sR_q31_len64;
|
||||
extern csky_vdsp2_rfft_instance_q31 csky_vdsp2_rfft_sR_q31_len128;
|
||||
extern csky_vdsp2_rfft_instance_q31 csky_vdsp2_rfft_sR_q31_len256;
|
||||
extern csky_vdsp2_rfft_instance_q31 csky_vdsp2_rfft_sR_q31_len512;
|
||||
extern csky_vdsp2_rfft_instance_q31 csky_vdsp2_rfft_sR_q31_len1024;
|
||||
extern csky_vdsp2_rfft_instance_q31 csky_vdsp2_rfft_sR_q31_len2048;
|
||||
extern csky_vdsp2_rfft_instance_q31 csky_vdsp2_rfft_sR_q31_len4096;
|
||||
extern csky_vdsp2_rfft_instance_q31 csky_vdsp2_rfft_sR_q31_len8192;
|
||||
|
||||
extern csky_vdsp2_rfft_instance_q31 csky_vdsp2_inv_rfft_sR_q31_len32;
|
||||
extern csky_vdsp2_rfft_instance_q31 csky_vdsp2_inv_rfft_sR_q31_len64;
|
||||
extern csky_vdsp2_rfft_instance_q31 csky_vdsp2_inv_rfft_sR_q31_len128;
|
||||
extern csky_vdsp2_rfft_instance_q31 csky_vdsp2_inv_rfft_sR_q31_len256;
|
||||
extern csky_vdsp2_rfft_instance_q31 csky_vdsp2_inv_rfft_sR_q31_len512;
|
||||
extern csky_vdsp2_rfft_instance_q31 csky_vdsp2_inv_rfft_sR_q31_len1024;
|
||||
extern csky_vdsp2_rfft_instance_q31 csky_vdsp2_inv_rfft_sR_q31_len2048;
|
||||
extern csky_vdsp2_rfft_instance_q31 csky_vdsp2_inv_rfft_sR_q31_len4096;
|
||||
extern csky_vdsp2_rfft_instance_q31 csky_vdsp2_inv_rfft_sR_q31_len8192;
|
||||
|
||||
extern csky_vdsp2_rfft_fast_instance_q31 csky_vdsp2_rfft_fast_sR_q31_len32;
|
||||
extern csky_vdsp2_rfft_fast_instance_q31 csky_vdsp2_rfft_fast_sR_q31_len64;
|
||||
extern csky_vdsp2_rfft_fast_instance_q31 csky_vdsp2_rfft_fast_sR_q31_len128;
|
||||
extern csky_vdsp2_rfft_fast_instance_q31 csky_vdsp2_rfft_fast_sR_q31_len256;
|
||||
extern csky_vdsp2_rfft_fast_instance_q31 csky_vdsp2_rfft_fast_sR_q31_len512;
|
||||
extern csky_vdsp2_rfft_fast_instance_q31 csky_vdsp2_rfft_fast_sR_q31_len1024;
|
||||
extern csky_vdsp2_rfft_fast_instance_q31 csky_vdsp2_rfft_fast_sR_q31_len2048;
|
||||
extern csky_vdsp2_rfft_fast_instance_q31 csky_vdsp2_rfft_fast_sR_q31_len4096;
|
||||
extern csky_vdsp2_rfft_fast_instance_q31 csky_vdsp2_rfft_fast_sR_q31_len8192;
|
||||
|
||||
extern csky_vdsp2_rfft_fast_instance_q31 csky_vdsp2_inv_rfft_fast_sR_q31_len32;
|
||||
extern csky_vdsp2_rfft_fast_instance_q31 csky_vdsp2_inv_rfft_fast_sR_q31_len64;
|
||||
extern csky_vdsp2_rfft_fast_instance_q31 csky_vdsp2_inv_rfft_fast_sR_q31_len128;
|
||||
extern csky_vdsp2_rfft_fast_instance_q31 csky_vdsp2_inv_rfft_fast_sR_q31_len256;
|
||||
extern csky_vdsp2_rfft_fast_instance_q31 csky_vdsp2_inv_rfft_fast_sR_q31_len512;
|
||||
extern csky_vdsp2_rfft_fast_instance_q31 csky_vdsp2_inv_rfft_fast_sR_q31_len1024;
|
||||
extern csky_vdsp2_rfft_fast_instance_q31 csky_vdsp2_inv_rfft_fast_sR_q31_len2048;
|
||||
extern csky_vdsp2_rfft_fast_instance_q31 csky_vdsp2_inv_rfft_fast_sR_q31_len4096;
|
||||
extern csky_vdsp2_rfft_fast_instance_q31 csky_vdsp2_inv_rfft_fast_sR_q31_len8192;
|
||||
|
||||
|
||||
extern csky_vdsp2_rfft_fast_instance_f32 csky_vdsp2_rfft_sR_f32_len32;
|
||||
extern csky_vdsp2_rfft_fast_instance_f32 csky_vdsp2_rfft_sR_f32_len64;
|
||||
extern csky_vdsp2_rfft_fast_instance_f32 csky_vdsp2_rfft_sR_f32_len128;
|
||||
extern csky_vdsp2_rfft_fast_instance_f32 csky_vdsp2_rfft_sR_f32_len256;
|
||||
extern csky_vdsp2_rfft_fast_instance_f32 csky_vdsp2_rfft_sR_f32_len512;
|
||||
extern csky_vdsp2_rfft_fast_instance_f32 csky_vdsp2_rfft_sR_f32_len1024;
|
||||
extern csky_vdsp2_rfft_fast_instance_f32 csky_vdsp2_rfft_sR_f32_len2048;
|
||||
extern csky_vdsp2_rfft_fast_instance_f32 csky_vdsp2_rfft_sR_f32_len4096;
|
||||
extern csky_vdsp2_rfft_fast_instance_f32 csky_vdsp2_rfft_sR_f32_len8192;
|
||||
|
||||
extern csky_vdsp2_dct4_instance_q15 csky_vdsp2_dct4_sR_q15_len128;
|
||||
extern csky_vdsp2_dct4_instance_q15 csky_vdsp2_dct4_sR_q15_len512;
|
||||
extern csky_vdsp2_dct4_instance_q15 csky_vdsp2_dct4_sR_q15_len2048;
|
||||
extern csky_vdsp2_dct4_instance_q15 csky_vdsp2_dct4_sR_q15_len8192;
|
||||
|
||||
extern csky_vdsp2_dct4_instance_q31 csky_vdsp2_dct4_sR_q31_len128;
|
||||
extern csky_vdsp2_dct4_instance_q31 csky_vdsp2_dct4_sR_q31_len512;
|
||||
extern csky_vdsp2_dct4_instance_q31 csky_vdsp2_dct4_sR_q31_len2048;
|
||||
extern csky_vdsp2_dct4_instance_q31 csky_vdsp2_dct4_sR_q31_len8192;
|
||||
|
||||
extern csky_vdsp2_dct4_fast_instance_q15 csky_vdsp2_dct4_fast_sR_q15_len128;
|
||||
extern csky_vdsp2_dct4_fast_instance_q15 csky_vdsp2_dct4_fast_sR_q15_len512;
|
||||
extern csky_vdsp2_dct4_fast_instance_q15 csky_vdsp2_dct4_fast_sR_q15_len2048;
|
||||
extern csky_vdsp2_dct4_fast_instance_q15 csky_vdsp2_dct4_fast_sR_q15_len8192;
|
||||
|
||||
extern csky_vdsp2_dct4_fast_instance_q31 csky_vdsp2_dct4_fast_sR_q31_len128;
|
||||
extern csky_vdsp2_dct4_fast_instance_q31 csky_vdsp2_dct4_fast_sR_q31_len512;
|
||||
extern csky_vdsp2_dct4_fast_instance_q31 csky_vdsp2_dct4_fast_sR_q31_len2048;
|
||||
extern csky_vdsp2_dct4_fast_instance_q31 csky_vdsp2_dct4_fast_sR_q31_len8192;
|
||||
|
||||
extern csky_vdsp2_dct4_instance_f32 csky_vdsp2_dct4_sR_f32_len128;
|
||||
extern csky_vdsp2_dct4_instance_f32 csky_vdsp2_dct4_sR_f32_len512;
|
||||
extern csky_vdsp2_dct4_instance_f32 csky_vdsp2_dct4_sR_f32_len2048;
|
||||
extern csky_vdsp2_dct4_instance_f32 csky_vdsp2_dct4_sR_f32_len8192;
|
||||
#endif
|
||||
2378
csky/csi_dsp/include/csky_vdsp2_math.h
Normal file
2378
csky/csi_dsp/include/csky_vdsp2_math.h
Normal file
File diff suppressed because it is too large
Load Diff
552
csky/csi_dsp/include/csky_vdsp2_nnfunctions.h
Normal file
552
csky/csi_dsp/include/csky_vdsp2_nnfunctions.h
Normal file
@@ -0,0 +1,552 @@
|
||||
/*
|
||||
* Copyright (C) 2016-2019 C-SKY Limited. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
* Title: csky_vdsp2_nnfunctions.h
|
||||
* Description: Public header file for CSI NN Library
|
||||
*
|
||||
* -------------------------------------------------------------------- */
|
||||
|
||||
#ifndef _CSKY_VDSP2_NNFUNCTIONS_H
|
||||
#define _CSKY_VDSP2_NNFUNCTIONS_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#ifdef CSKY_VDSP2_MATH_DSP
|
||||
#include "csky_vdsp2_math.h"
|
||||
#include "csky_vdsp2_nnsupportfunctions.h"
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Struct for specifying activation function types
|
||||
*
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
CSKY_SIGMOID = 0, /**< Sigmoid activation function */
|
||||
CSKY_TANH = 1, /**< Tanh activation function */
|
||||
} csky_vdsp2_nn_activation_type;
|
||||
|
||||
/**
|
||||
* @brief Basic Q7 convolution function
|
||||
* @param[in] Im_in pointer to input tensor
|
||||
* @param[in] dim_im_in input tensor dimention
|
||||
* @param[in] ch_im_in number of input tensor channels
|
||||
* @param[in] wt pointer to kernel weights
|
||||
* @param[in] ch_im_out number of filters, i.e., output tensor channels
|
||||
* @param[in] dim_kernel filter kernel size
|
||||
* @param[in] padding padding sizes
|
||||
* @param[in] stride convolution stride
|
||||
* @param[in] bias pointer to bias
|
||||
* @param[in] bias_shift amount of left-shift for bias
|
||||
* @param[in] out_shift amount of right-shift for output
|
||||
* @param[in,out] Im_out pointer to output tensor
|
||||
* @param[in] dim_im_out output tensor dimension
|
||||
* @param[in,out] bufferA pointer to buffer space for input
|
||||
* @return none.
|
||||
*
|
||||
*/
|
||||
|
||||
void csky_vdsp2_convolve_HWC_q7_basic(const q7_t * Im_in,
|
||||
const uint16_t dim_im_in,
|
||||
const uint16_t ch_im_in,
|
||||
const q7_t * wt,
|
||||
const uint16_t ch_im_out,
|
||||
const uint16_t dim_kernel,
|
||||
const uint16_t padding,
|
||||
const uint16_t stride,
|
||||
const q7_t * bias,
|
||||
const uint16_t bias_shift,
|
||||
const uint16_t out_shift,
|
||||
q7_t * Im_out,
|
||||
const uint16_t dim_im_out,
|
||||
q15_t * bufferA);
|
||||
|
||||
/**
|
||||
* @brief Basic Q15 convolution function
|
||||
* @param[in] Im_in pointer to input tensor
|
||||
* @param[in] dim_im_in input tensor dimention
|
||||
* @param[in] ch_im_in number of input tensor channels
|
||||
* @param[in] wt pointer to kernel weights
|
||||
* @param[in] ch_im_out number of filters, i.e., output tensor channels
|
||||
* @param[in] dim_kernel filter kernel size
|
||||
* @param[in] padding padding sizes
|
||||
* @param[in] stride convolution stride
|
||||
* @param[in] bias pointer to bias
|
||||
* @param[in] bias_shift amount of left-shift for bias
|
||||
* @param[in] out_shift amount of right-shift for output
|
||||
* @param[in,out] Im_out pointer to output tensor
|
||||
* @param[in] dim_im_out output tensor dimension
|
||||
* @param[in,out] bufferA pointer to buffer space for input
|
||||
* @return none.
|
||||
*
|
||||
*/
|
||||
|
||||
void csky_vdsp2_convolve_HWC_q15_basic(const q15_t * Im_in,
|
||||
const uint16_t dim_im_in,
|
||||
const uint16_t ch_im_in,
|
||||
const q15_t * wt,
|
||||
const uint16_t ch_im_out,
|
||||
const uint16_t dim_kernel,
|
||||
const uint16_t padding,
|
||||
const uint16_t stride,
|
||||
const q15_t * bias,
|
||||
const uint16_t bias_shift,
|
||||
const uint16_t out_shift,
|
||||
q15_t * Im_out,
|
||||
const uint16_t dim_im_out,
|
||||
q15_t * bufferA);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Fast Q7 convolution function (non-sqaure shape)
|
||||
* @param[in] Im_in pointer to input tensor
|
||||
* @param[in] dim_im_in_x input tensor dimention x
|
||||
* @param[in] dim_im_in_y input tensor dimention y
|
||||
* @param[in] ch_im_in number of input tensor channels
|
||||
* @param[in] wt pointer to kernel weights
|
||||
* @param[in] ch_im_out number of filters, i.e., output tensor channels
|
||||
* @param[in] dim_kernel_x filter kernel size x
|
||||
* @param[in] dim_kernel_y filter kernel size y
|
||||
* @param[in] padding_x padding size x
|
||||
* @param[in] padding_y padding size y
|
||||
* @param[in] stride_x convolution stride x
|
||||
* @param[in] stride_y convolution stride y
|
||||
* @param[in] bias pointer to bias
|
||||
* @param[in] bias_shift amount of left-shift for bias
|
||||
* @param[in] out_shift amount of right-shift for output
|
||||
* @param[in,out] Im_out pointer to output tensor
|
||||
* @param[in] dim_im_out_x output tensor dimension x
|
||||
* @param[in] dim_im_out_y output tensor dimension y
|
||||
* @param[in,out] bufferA pointer to buffer space for input
|
||||
* @return none.
|
||||
*
|
||||
* This function is the version with full list of optimization tricks, but with
|
||||
* some contraints:
|
||||
* ch_im_in is multiple of 4
|
||||
* ch_im_out is multiple of 2
|
||||
*/
|
||||
|
||||
void csky_vdsp2_convolve_HWC_q7_fast_nonsquare(const q7_t * Im_in,
|
||||
const uint16_t dim_im_in_x,
|
||||
const uint16_t dim_im_in_y,
|
||||
const uint16_t ch_im_in,
|
||||
const q7_t * wt,
|
||||
const uint16_t ch_im_out,
|
||||
const uint16_t dim_kernel_x,
|
||||
const uint16_t dim_kernel_y,
|
||||
const uint16_t padding_x,
|
||||
const uint16_t padding_y,
|
||||
const uint16_t stride_x,
|
||||
const uint16_t stride_y,
|
||||
const q7_t * bias,
|
||||
const uint16_t bias_shift,
|
||||
const uint16_t out_shift,
|
||||
q7_t * Im_out,
|
||||
const uint16_t dim_im_out_x,
|
||||
const uint16_t dim_im_out_y,
|
||||
q15_t * bufferA);
|
||||
|
||||
/**
|
||||
* @brief Fast Q7 version of 1x1 convolution (non-sqaure shape)
|
||||
* @param[in] Im_in pointer to input tensor
|
||||
* @param[in] dim_im_in_x input tensor dimention x
|
||||
* @param[in] dim_im_in_y input tensor dimention y
|
||||
* @param[in] ch_im_in number of input tensor channels
|
||||
* @param[in] wt pointer to kernel weights
|
||||
* @param[in] ch_im_out number of filters, i.e., output tensor channels
|
||||
* @param[in] dim_kernel_x filter kernel size x
|
||||
* @param[in] dim_kernel_y filter kernel size y
|
||||
* @param[in] padding_x padding size x
|
||||
* @param[in] padding_y padding size y
|
||||
* @param[in] stride_x convolution stride x
|
||||
* @param[in] stride_y convolution stride y
|
||||
* @param[in] bias pointer to bias
|
||||
* @param[in] bias_shift amount of left-shift for bias
|
||||
* @param[in] out_shift amount of right-shift for output
|
||||
* @param[in,out] Im_out pointer to output tensor
|
||||
* @param[in] dim_im_out_x output tensor dimension x
|
||||
* @param[in] dim_im_out_y output tensor dimension y
|
||||
* @param[in,out] bufferA pointer to buffer space for input
|
||||
* @return none.
|
||||
*
|
||||
* This function implement convolution with 1x1 kernel size (i.e., dim_kernel_x=1
|
||||
* and dim_kernel_y=1). It can be used for
|
||||
* second half of MobileNets after depthwise separable convolution.
|
||||
*
|
||||
* This function is the version with full list of optimization tricks, but with
|
||||
* some contraints:
|
||||
* ch_im_in is multiple of 4
|
||||
* ch_im_out is multiple of 2
|
||||
*/
|
||||
void csky_vdsp2_convolve_1x1_HWC_q7_fast(const q7_t * Im_in,
|
||||
const uint16_t dim_im_in_x,
|
||||
const uint16_t dim_im_in_y,
|
||||
const uint16_t ch_im_in,
|
||||
const q7_t * wt,
|
||||
const uint16_t ch_im_out,
|
||||
const q7_t * bias,
|
||||
const uint16_t bias_shift,
|
||||
const uint16_t out_shift,
|
||||
q7_t * Im_out,
|
||||
const uint16_t dim_im_out_x,
|
||||
const uint16_t dim_im_out_y,
|
||||
q15_t * bufferA);
|
||||
|
||||
/**
|
||||
* @brief Q7 version of convolution for RGB image
|
||||
* @param[in] Im_in pointer to input tensor
|
||||
* @param[in] dim_im_in input tensor dimention
|
||||
* @param[in] ch_im_in number of input tensor channels
|
||||
* @param[in] wt pointer to kernel weights
|
||||
* @param[in] ch_im_out number of filters, i.e., output tensor channels
|
||||
* @param[in] dim_kernel filter kernel size
|
||||
* @param[in] padding padding sizes
|
||||
* @param[in] stride convolution stride
|
||||
* @param[in] bias pointer to bias
|
||||
* @param[in] bias_shift amount of left-shift for bias
|
||||
* @param[in] out_shift amount of right-shift for output
|
||||
* @param[in,out] Im_out pointer to output tensor
|
||||
* @param[in] dim_im_out output tensor dimension
|
||||
* @param[in,out] bufferA pointer to buffer space for input
|
||||
* @return none.
|
||||
*
|
||||
* This kernel is written exclusively for convolution with ch_im_in
|
||||
* equals 3. This applies on the first layer of CNNs which has input
|
||||
* image with RGB format.
|
||||
*/
|
||||
|
||||
void csky_vdsp2_convolve_HWC_q7_RGB(const q7_t * Im_in,
|
||||
const uint16_t dim_im_in,
|
||||
const q7_t * wt,
|
||||
const uint16_t ch_im_out,
|
||||
const uint16_t dim_kernel,
|
||||
const uint16_t padding,
|
||||
const uint16_t stride,
|
||||
const q7_t * bias,
|
||||
const uint16_t bias_shift,
|
||||
const uint16_t out_shift,
|
||||
q7_t * Im_out,
|
||||
const uint16_t dim_im_out,
|
||||
q15_t * bufferA);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Q7 depthwise separable convolution function
|
||||
* @param[in] Im_in pointer to input tensor
|
||||
* @param[in] dim_im_in input tensor dimention
|
||||
* @param[in] ch_im_in number of input tensor channels
|
||||
* @param[in] wt pointer to kernel weights
|
||||
* @param[in] ch_im_out number of filters, i.e., output tensor channels
|
||||
* @param[in] dim_kernel filter kernel size
|
||||
* @param[in] padding padding sizes
|
||||
* @param[in] stride convolution stride
|
||||
* @param[in] bias pointer to bias
|
||||
* @param[in] bias_shift amount of left-shift for bias
|
||||
* @param[in] out_shift amount of right-shift for output
|
||||
* @param[in,out] Im_out pointer to output tensor
|
||||
* @param[in] dim_im_out output tensor dimension
|
||||
* @param[in,out] bufferA pointer to buffer space for input
|
||||
* @return none.
|
||||
*
|
||||
* This function is the version with full list of optimization tricks, but with
|
||||
* some contraints:
|
||||
* ch_im_in is multiple of 2
|
||||
* ch_im_out is multiple of 2
|
||||
*/
|
||||
|
||||
void csky_vdsp2_depthwise_separable_conv_HWC_q7(const q7_t * Im_in,
|
||||
const uint16_t dim_im_in,
|
||||
const uint16_t ch_im_in,
|
||||
const q7_t * wt,
|
||||
const uint16_t ch_im_out,
|
||||
const uint16_t dim_kernel,
|
||||
const uint16_t padding,
|
||||
const uint16_t stride,
|
||||
const q7_t * bias,
|
||||
const uint16_t bias_shift,
|
||||
const uint16_t out_shift,
|
||||
q7_t * Im_out,
|
||||
const uint16_t dim_im_out,
|
||||
q15_t * bufferA);
|
||||
|
||||
/**
|
||||
* @brief Q7 depthwise separable convolution function (non-square shape)
|
||||
* @param[in] Im_in pointer to input tensor
|
||||
* @param[in] dim_im_in_x input tensor dimention x
|
||||
* @param[in] dim_im_in_y input tensor dimention y
|
||||
* @param[in] ch_im_in number of input tensor channels
|
||||
* @param[in] wt pointer to kernel weights
|
||||
* @param[in] ch_im_out number of filters, i.e., output tensor channels
|
||||
* @param[in] dim_kernel_x filter kernel size x
|
||||
* @param[in] dim_kernel_y filter kernel size y
|
||||
* @param[in] padding_x padding sizes x
|
||||
* @param[in] padding_y padding sizes y
|
||||
* @param[in] stride_x convolution stride x
|
||||
* @param[in] stride_y convolution stride y
|
||||
* @param[in] bias pointer to bias
|
||||
* @param[in] bias_shift amount of left-shift for bias
|
||||
* @param[in] out_shift amount of right-shift for output
|
||||
* @param[in,out] Im_out pointer to output tensor
|
||||
* @param[in] dim_im_out_x output tensor dimension x
|
||||
* @param[in] dim_im_out_y output tensor dimension y
|
||||
* @param[in,out] bufferA pointer to buffer space for input
|
||||
* @return none.
|
||||
*
|
||||
* This function is the version with full list of optimization tricks, but with
|
||||
* some contraints:
|
||||
* ch_im_in is multiple of 2
|
||||
* ch_im_out is multiple of 2
|
||||
*/
|
||||
void csky_vdsp2_depthwise_separable_conv_HWC_q7_nonsquare(const q7_t * Im_in,
|
||||
const uint16_t dim_im_in_x,
|
||||
const uint16_t dim_im_in_y,
|
||||
const uint16_t ch_im_in,
|
||||
const q7_t * wt,
|
||||
const uint16_t ch_im_out,
|
||||
const uint16_t dim_kernel_x,
|
||||
const uint16_t dim_kernel_y,
|
||||
const uint16_t padding_x,
|
||||
const uint16_t padding_y,
|
||||
const uint16_t stride_x,
|
||||
const uint16_t stride_y,
|
||||
const q7_t * bias,
|
||||
const uint16_t bias_shift,
|
||||
const uint16_t out_shift,
|
||||
q7_t * Im_out,
|
||||
const uint16_t dim_im_out_x,
|
||||
const uint16_t dim_im_out_y,
|
||||
q15_t * bufferA);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Q7 basic fully-connected layer function
|
||||
* @param[in] pV pointer to input vector
|
||||
* @param[in] pM pointer to matrix weights
|
||||
* @param[in] dim_vec length of the vector
|
||||
* @param[in] num_of_rows number of rows in weight matrix
|
||||
* @param[in] bias_shift amount of left-shift for bias
|
||||
* @param[in] out_shift amount of right-shift for output
|
||||
* @param[in] bias pointer to bias
|
||||
* @param[in,out] pOut pointer to output vector
|
||||
* @return none.
|
||||
*/
|
||||
|
||||
void csky_vdsp2_fully_connected_q7(const q7_t * pV,
|
||||
const q7_t * pM,
|
||||
const uint16_t dim_vec,
|
||||
const uint16_t num_of_rows,
|
||||
const uint16_t bias_shift,
|
||||
const uint16_t out_shift,
|
||||
const q7_t * bias,
|
||||
q7_t * pOut);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Q15 basic fully-connected layer function
|
||||
* @param[in] pV pointer to input vector
|
||||
* @param[in] pM pointer to matrix weights
|
||||
* @param[in] dim_vec length of the vector
|
||||
* @param[in] num_of_rows number of rows in weight matrix
|
||||
* @param[in] bias_shift amount of left-shift for bias
|
||||
* @param[in] out_shift amount of right-shift for output
|
||||
* @param[in] bias pointer to bias
|
||||
* @param[in,out] pOut pointer to output vector
|
||||
* @return none.
|
||||
*
|
||||
*/
|
||||
|
||||
void csky_vdsp2_fully_connected_q15(const q15_t * pV,
|
||||
const q15_t * pM,
|
||||
const uint16_t dim_vec,
|
||||
const uint16_t num_of_rows,
|
||||
const uint16_t bias_shift,
|
||||
const uint16_t out_shift,
|
||||
const q15_t * bias,
|
||||
q15_t * pOut);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Mixed Q15-Q7 fully-connected layer function
|
||||
* @param[in] pV pointer to input vector
|
||||
* @param[in] pM pointer to matrix weights
|
||||
* @param[in] dim_vec length of the vector
|
||||
* @param[in] num_of_rows number of rows in weight matrix
|
||||
* @param[in] bias_shift amount of left-shift for bias
|
||||
* @param[in] out_shift amount of right-shift for output
|
||||
* @param[in] bias pointer to bias
|
||||
* @param[in,out] pOut pointer to output vector
|
||||
* @return none.
|
||||
*
|
||||
*/
|
||||
|
||||
void csky_vdsp2_fully_connected_mat_q7_vec_q15(const q15_t * pV,
|
||||
const q7_t * pM,
|
||||
const uint16_t dim_vec,
|
||||
const uint16_t num_of_rows,
|
||||
const uint16_t bias_shift,
|
||||
const uint16_t out_shift,
|
||||
const q7_t * bias,
|
||||
q15_t * pOut);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Q7 RELU function
|
||||
* @param[in,out] data pointer to input
|
||||
* @param[in] size number of elements
|
||||
* @return none.
|
||||
*/
|
||||
|
||||
void csky_vdsp2_relu_q7(q7_t * data, uint16_t size);
|
||||
|
||||
/**
|
||||
* @brief Q15 RELU function
|
||||
* @param[in,out] data pointer to input
|
||||
* @param[in] size number of elements
|
||||
* @return none.
|
||||
*/
|
||||
|
||||
void csky_vdsp2_relu_q15(q15_t * data, uint16_t size);
|
||||
|
||||
/**
|
||||
* @brief Q7 neural network activation function using direct table look-up
|
||||
* @param[in,out] data pointer to input
|
||||
* @param[in] size number of elements
|
||||
* @param[in] int_width bit-width of the integer part, assume to be smaller than 3
|
||||
* @param[in] type type of activation functions
|
||||
* @return none.
|
||||
*/
|
||||
|
||||
void csky_vdsp2_nn_activations_direct_q7(q7_t * data, uint16_t size,
|
||||
uint16_t int_width,
|
||||
csky_vdsp2_nn_activation_type type);
|
||||
|
||||
/**
|
||||
* @brief Q15 neural network activation function using direct table look-up
|
||||
* @param[in,out] data pointer to input
|
||||
* @param[in] size number of elements
|
||||
* @param[in] int_width bit-width of the integer part, assume to be smaller than 3
|
||||
* @param[in] type type of activation functions
|
||||
* @return none.
|
||||
*/
|
||||
|
||||
void csky_vdsp2_nn_activations_direct_q15(q15_t * data, uint16_t size,
|
||||
uint16_t int_width,
|
||||
csky_vdsp2_nn_activation_type type);
|
||||
|
||||
/**
|
||||
* @brief Q7 max pooling function
|
||||
* @param[in] Im_in pointer to input tensor
|
||||
* @param[in] dim_im_in input tensor dimention
|
||||
* @param[in] ch_im_in number of input tensor channels
|
||||
* @param[in] dim_kernel filter kernel size
|
||||
* @param[in] padding padding sizes
|
||||
* @param[in] stride convolution stride
|
||||
* @param[in] dim_im_out output tensor dimension
|
||||
* @param[in,out] bufferA pointer to buffer space for input
|
||||
* @param[in,out] Im_out pointer to output tensor
|
||||
* @return none.
|
||||
*
|
||||
*/
|
||||
|
||||
void csky_vdsp2_maxpool_q7_HWC(q7_t * Im_in,
|
||||
const uint16_t dim_im_in,
|
||||
const uint16_t ch_im_in,
|
||||
const uint16_t dim_kernel,
|
||||
const uint16_t padding,
|
||||
const uint16_t stride,
|
||||
const uint16_t dim_im_out,
|
||||
q7_t * bufferA,
|
||||
q7_t * Im_out);
|
||||
|
||||
/**
|
||||
* @brief Q7 average pooling function
|
||||
* @param[in] Im_in pointer to input tensor
|
||||
* @param[in] dim_im_in input tensor dimention
|
||||
* @param[in] ch_im_in number of input tensor channels
|
||||
* @param[in] dim_kernel filter kernel size
|
||||
* @param[in] padding padding sizes
|
||||
* @param[in] stride convolution stride
|
||||
* @param[in] dim_im_out output tensor dimension
|
||||
* @param[in,out] bufferA pointer to buffer space for input
|
||||
* @param[in,out] Im_out pointer to output tensor
|
||||
* @return none.
|
||||
*
|
||||
*/
|
||||
|
||||
void csky_vdsp2_avepool_q7_HWC(q7_t * Im_in,
|
||||
const uint16_t dim_im_in,
|
||||
const uint16_t ch_im_in,
|
||||
const uint16_t dim_kernel,
|
||||
const uint16_t padding,
|
||||
const uint16_t stride,
|
||||
const uint16_t dim_im_out,
|
||||
q7_t * bufferA,
|
||||
q7_t * Im_out);
|
||||
|
||||
|
||||
void csky_vdsp2_avepool_q7_HWC_nonsquare(
|
||||
q7_t *Im_in, // input image
|
||||
const uint16_t dim_im_in_x, // input image dimension
|
||||
const uint16_t dim_im_in_y, // input image dimension
|
||||
const uint16_t ch_im_in, // number of input image channels
|
||||
const uint16_t dim_kernel_x, // window kernel size
|
||||
const uint16_t dim_kernel_y, // window kernel size
|
||||
const uint16_t padding_x, // padding sizes
|
||||
const uint16_t padding_y, // padding sizes
|
||||
const uint16_t stride_x, // stride
|
||||
const uint16_t stride_y, // stride
|
||||
const uint16_t dim_im_out_x, // output image dimension
|
||||
const uint16_t dim_im_out_y, // output image dimension
|
||||
q7_t *bufferA, // a buffer for local storage
|
||||
q7_t *Im_out, // output feature
|
||||
const uint16_t out_lshift); // output left shift (scaling)
|
||||
|
||||
|
||||
/**
|
||||
* @brief Q7 softmax function
|
||||
* @param[in] vec_in pointer to input vector
|
||||
* @param[in] dim_vec input vector dimention
|
||||
* @param[out] p_out pointer to output vector
|
||||
* @return none.
|
||||
*
|
||||
*/
|
||||
|
||||
void csky_vdsp2_softmax_q7(const q7_t *vec_in, const uint16_t dim_vec, q7_t *p_out);
|
||||
|
||||
/**
|
||||
* @brief Q15 softmax function
|
||||
* @param[in] vec_in pointer to input vector
|
||||
* @param[in] dim_vec input vector dimention
|
||||
* @param[out] p_out pointer to output vector
|
||||
* @return none.
|
||||
*
|
||||
*/
|
||||
|
||||
void csky_vdsp2_softmax_q15(const q15_t *vec_in, const uint16_t dim_vec,
|
||||
q15_t *p_out);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
162
csky/csi_dsp/include/csky_vdsp2_nnsupportfunctions.h
Normal file
162
csky/csi_dsp/include/csky_vdsp2_nnsupportfunctions.h
Normal file
@@ -0,0 +1,162 @@
|
||||
/*
|
||||
* Copyright (C) 2016-2019 C-SKY Limited. All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
* Title: csky_vdsp2_nnsupportfunctions.h
|
||||
* Description: Public header file of support functions for CSI NN Library
|
||||
*
|
||||
* -------------------------------------------------------------------- */
|
||||
|
||||
#ifndef _CSKY_DSP2_NNSUPPORTFUNCTIONS_H_
|
||||
#define _CSKY_DSP2_NNSUPPORTFUNCTIONS_H_
|
||||
|
||||
#include "csky_math.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Union for SIMD access of Q31/Q15/Q7 types
|
||||
*/
|
||||
union csky_vdsp2_nnword
|
||||
{
|
||||
q31_t word; /**< Q31 type */
|
||||
q15_t half_words[2]; /**< Q15 type */
|
||||
q7_t bytes[4]; /**< Q7 type */
|
||||
};
|
||||
|
||||
/**
|
||||
* @defgroup nndata_convert Neural Network Data Conversion Functions
|
||||
*
|
||||
* Perform data type conversion in-between neural network operations
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Converts the elements of the Q7 vector to Q15 vector without left-shift
|
||||
* @param[in] *pSrc points to the Q7 input vector
|
||||
* @param[out] *pDst points to the Q15 output vector
|
||||
* @param[in] blockSize length of the input vector
|
||||
* @return none.
|
||||
*
|
||||
*/
|
||||
|
||||
void csky_vdsp2_q7_to_q15_no_shift(const q7_t * pSrc, q15_t * pDst,
|
||||
uint32_t blockSize);
|
||||
|
||||
/**
|
||||
* @brief Converts the elements of the Q7 vector to reordered Q15 vector without left-shift
|
||||
* @param[in] *pSrc points to the Q7 input vector
|
||||
* @param[out] *pDst points to the Q15 output vector
|
||||
* @param[in] blockSize length of the input vector
|
||||
* @return none.
|
||||
*
|
||||
*/
|
||||
|
||||
void csky_vdsp2_q7_to_q15_reordered_no_shift(const q7_t * pSrc, q15_t * pDst,
|
||||
uint32_t blockSize);
|
||||
|
||||
#if defined (CSKY_VDSP2_MATH_DSP)
|
||||
|
||||
/**
|
||||
* @brief read and expand one Q7 word into two Q15 words
|
||||
*/
|
||||
|
||||
__ALWAYS_STATIC_INLINE void *read_and_pad(void *source, q31_t *out1,
|
||||
q31_t *out2)
|
||||
{
|
||||
q31_t inA = *__SIMD32(source)++;
|
||||
q31_t inAbuf1 = __SXTB16(__ROR(inA, 8));
|
||||
q31_t inAbuf2 = __SXTB16(inA);
|
||||
|
||||
#ifndef CSKY_MATH_BIG_ENDIAN
|
||||
*out2 = __PKHTB(inAbuf1, inAbuf2, 16);
|
||||
*out1 = __PKHBT(inAbuf2, inAbuf1, 16);
|
||||
#else
|
||||
*out1 = __PKHTB(inAbuf1, inAbuf2, 16);
|
||||
*out2 = __PKHBT(inAbuf2, inAbuf1, 16);
|
||||
#endif
|
||||
|
||||
return source;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief read and expand one Q7 word into two Q15 words with reordering
|
||||
*/
|
||||
|
||||
__ALWAYS_STATIC_INLINE void *read_and_pad_reordered(void *source, q31_t * out1,
|
||||
q31_t * out2)
|
||||
{
|
||||
q31_t inA = *__SIMD32(source)++;
|
||||
#ifndef CSKY_MATH_BIG_ENDIAN
|
||||
*out2 = __SXTB16(__ROR(inA, 8));
|
||||
*out1 = __SXTB16(inA);
|
||||
#else
|
||||
*out1 = __SXTB16(__ROR(inA, 8));
|
||||
*out2 = __SXTB16(inA);
|
||||
#endif
|
||||
|
||||
return source;
|
||||
}
|
||||
#endif
|
||||
|
||||
q7_t *csky_vdsp2_nn_mat_mult_kernel_q7_q15_reordered(const q7_t * pA,
|
||||
const q15_t * pInBuffer,
|
||||
const uint16_t ch_im_out,
|
||||
const uint16_t numCol_A,
|
||||
const uint16_t bias_shift,
|
||||
const uint16_t out_shift,
|
||||
const q7_t * bias,
|
||||
q7_t * pOut);
|
||||
|
||||
q7_t *csky_vdsp2_nn_mat_mult_kernel_q7_q15(const q7_t * pA,
|
||||
const q15_t * pInBuffer,
|
||||
const uint16_t ch_im_out,
|
||||
const uint16_t numCol_A,
|
||||
const uint16_t bias_shift,
|
||||
const uint16_t out_shift,
|
||||
const q7_t * bias,
|
||||
q7_t * pOut);
|
||||
|
||||
/**
|
||||
* @brief A few utility functions used by pooling functions
|
||||
*
|
||||
*/
|
||||
|
||||
void buffer_scale_back_q15_to_q7(q15_t * buffer, q7_t * target,
|
||||
uint16_t length, uint16_t scale);
|
||||
|
||||
void accumulate_q7_to_q15(q15_t * base, q7_t * target,
|
||||
const uint16_t length);
|
||||
|
||||
/**
|
||||
* @brief defition to adding rouding offset
|
||||
*/
|
||||
#ifndef CSKY_NN_TRUNCATE
|
||||
#define NN_ROUND(out_shift) ( 0x1 << (out_shift - 1) )
|
||||
#else
|
||||
#define NN_ROUND(out_shift) 0
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
BIN
csky/csi_dsp/lib/libcsi_E804d_dsp2_nn.a
Normal file
BIN
csky/csi_dsp/lib/libcsi_E804d_dsp2_nn.a
Normal file
Binary file not shown.
BIN
csky/csi_dsp/lib/libcsi_E804d_math.a
Normal file
BIN
csky/csi_dsp/lib/libcsi_E804d_math.a
Normal file
Binary file not shown.
BIN
csky/csi_dsp/lib/libcsi_E804df_math.a
Normal file
BIN
csky/csi_dsp/lib/libcsi_E804df_math.a
Normal file
Binary file not shown.
BIN
csky/csi_dsp/lib/libcsi_xt900p32_dsp.a
Normal file
BIN
csky/csi_dsp/lib/libcsi_xt900p32_dsp.a
Normal file
Binary file not shown.
BIN
csky/csi_dsp/lib/libcsi_xt900p32f_dsp.a
Normal file
BIN
csky/csi_dsp/lib/libcsi_xt900p32f_dsp.a
Normal file
Binary file not shown.
BIN
csky/csi_dsp/lib/libcsi_xt900p32fd_dsp.a
Normal file
BIN
csky/csi_dsp/lib/libcsi_xt900p32fd_dsp.a
Normal file
Binary file not shown.
BIN
csky/csi_dsp/lib/libcsky_E804df_math.a
Normal file
BIN
csky/csi_dsp/lib/libcsky_E804df_math.a
Normal file
Binary file not shown.
641
csky/csi_kernel/include/csi_kernel.h
Normal file
641
csky/csi_kernel/include/csi_kernel.h
Normal file
@@ -0,0 +1,641 @@
|
||||
/*
|
||||
* Copyright (C) 2017 C-SKY Microsystems Co., Ltd. All rights reserved.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/******************************************************************************
|
||||
* @file csi_kernel.h
|
||||
* @brief header file for kernel definition
|
||||
* @version V1.0
|
||||
* @date 02. June 2017
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef _CSI_KERNEL_
|
||||
#define _CSI_KERNEL_
|
||||
|
||||
|
||||
#include <stdint.h>
|
||||
#include <errno.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
typedef struct osTimespec {
|
||||
long tv_sec;
|
||||
long tv_msec;
|
||||
} osTimespec_t;
|
||||
|
||||
/* =================================================================================== */
|
||||
/* Enumerations, structures, defines */
|
||||
/* =================================================================================== */
|
||||
|
||||
/// Status code values returned by CSI-kernel functions. 0 - success, negative represents error code ,see errno.h
|
||||
typedef int32_t k_status_t;
|
||||
|
||||
/// Kernel scheduler state.
|
||||
typedef enum {
|
||||
KSCHED_ST_INACTIVE = 0, ///< Inactive: The kernel is not ready yet. csi_kernel_init needs to be executed successfully.
|
||||
KSCHED_ST_READY = 1, ///< Ready: The kernel is not yet running. csi_kernel_start transfers the kernel to the running state.
|
||||
KSCHED_ST_RUNNING = 2, ///< Running: The kernel is initialized and running.
|
||||
KSCHED_ST_LOCKED = 3, ///< Locked: The kernel was locked with csi_kernel_sched_lock. The functions csi_kernel_sched_unlock or csi_kernel_sched_restore_lock unlocks it.
|
||||
KSCHED_ST_SUSPEND = 4, ///< Suspended: The kernel was suspended using csi_kernel_sched_suspend. The function csi_kernel_sched_resume returns to normal operation
|
||||
KSCHED_ST_ERROR = 5 ///< Error: An error occurred.
|
||||
} k_sched_stat_t;
|
||||
|
||||
/// task state.
|
||||
typedef enum {
|
||||
KTASK_ST_INACTIVE = 0, ///< Inactive.
|
||||
KTASK_ST_READY = 1, ///< Ready.
|
||||
KTASK_ST_RUNNING = 2, ///< Running.
|
||||
KTASK_ST_BLOCKED = 3, ///< Blocked.
|
||||
KTASK_ST_TERMINATED = 4, ///< Terminated.
|
||||
KTASK_ST_ERROR = 5 ///< Error: An error occurred.
|
||||
} k_task_stat_t;
|
||||
|
||||
/// timer state.
|
||||
typedef enum {
|
||||
KTIMER_ST_INACTIVE = 0, ///< not running
|
||||
KTIMER_ST_ACTIVE = 1, ///< running
|
||||
} k_timer_stat_t;
|
||||
|
||||
/// Timer type.
|
||||
typedef enum {
|
||||
KTIMER_TYPE_ONCE = 0, ///< One-shot timer.
|
||||
KTIMER_TYPE_PERIODIC = 1 ///< Repeating timer.
|
||||
} k_timer_type_t;
|
||||
|
||||
/// event option.
|
||||
typedef enum {
|
||||
KEVENT_OPT_SET_ANY = 0, ///< Check any bit in flags to be 1.
|
||||
KEVENT_OPT_SET_ALL = 1, ///< Check all bits in flags to be 1.
|
||||
KEVENT_OPT_CLR_ANY = 2, ///< Check any bit in flags to be 0.
|
||||
KEVENT_OPT_CLR_ALL = 3 ///< Check all bits in flags to be 0.
|
||||
} k_event_opt_t;
|
||||
|
||||
/// Priority definition.
|
||||
typedef enum {
|
||||
KPRIO_IDLE = 0, ///< priority: idle (lowest)
|
||||
KPRIO_LOW0 , ///< priority: low
|
||||
KPRIO_LOW1 , ///< priority: low + 1
|
||||
KPRIO_LOW2 , ///< priority: low + 2
|
||||
KPRIO_LOW3 , ///< priority: low + 3
|
||||
KPRIO_LOW4 , ///< priority: low + 4
|
||||
KPRIO_LOW5 , ///< priority: low + 5
|
||||
KPRIO_LOW6 , ///< priority: low + 6
|
||||
KPRIO_LOW7 , ///< priority: low + 7
|
||||
KPRIO_NORMAL_BELOW0 , ///< priority: below normal
|
||||
KPRIO_NORMAL_BELOW1 , ///< priority: below normal + 1
|
||||
KPRIO_NORMAL_BELOW2 , ///< priority: below normal + 2
|
||||
KPRIO_NORMAL_BELOW3 , ///< priority: below normal + 3
|
||||
KPRIO_NORMAL_BELOW4 , ///< priority: below normal + 4
|
||||
KPRIO_NORMAL_BELOW5 , ///< priority: below normal + 5
|
||||
KPRIO_NORMAL_BELOW6 , ///< priority: below normal + 6
|
||||
KPRIO_NORMAL_BELOW7 , ///< priority: below normal + 7
|
||||
KPRIO_NORMAL , ///< priority: normal (default)
|
||||
KPRIO_NORMAL1 , ///< priority: normal + 1
|
||||
KPRIO_NORMAL2 , ///< priority: normal + 2
|
||||
KPRIO_NORMAL3 , ///< priority: normal + 3
|
||||
KPRIO_NORMAL4 , ///< priority: normal + 4
|
||||
KPRIO_NORMAL5 , ///< priority: normal + 5
|
||||
KPRIO_NORMAL6 , ///< priority: normal + 6
|
||||
KPRIO_NORMAL7 , ///< priority: normal + 7
|
||||
KPRIO_NORMAL_ABOVE0 , ///< priority: above normal + 1
|
||||
KPRIO_NORMAL_ABOVE1 , ///< priority: above normal + 2
|
||||
KPRIO_NORMAL_ABOVE2 , ///< priority: above normal + 3
|
||||
KPRIO_NORMAL_ABOVE3 , ///< priority: above normal + 4
|
||||
KPRIO_NORMAL_ABOVE4 , ///< priority: above normal + 5
|
||||
KPRIO_NORMAL_ABOVE5 , ///< priority: above normal + 6
|
||||
KPRIO_NORMAL_ABOVE6 , ///< priority: above normal + 7
|
||||
KPRIO_NORMAL_ABOVE7 , ///< priority: above normal + 8
|
||||
KPRIO_HIGH0 , ///< priority: high
|
||||
KPRIO_HIGH1 , ///< priority: high + 1
|
||||
KPRIO_HIGH2 , ///< priority: high + 2
|
||||
KPRIO_HIGH3 , ///< priority: high + 3
|
||||
KPRIO_HIGH4 , ///< priority: high + 4
|
||||
KPRIO_HIGH5 , ///< priority: high + 5
|
||||
KPRIO_HIGH6 , ///< priority: high + 6
|
||||
KPRIO_HIGH7 , ///< priority: high + 7
|
||||
KPRIO_REALTIME0 , ///< priority: realtime + 1
|
||||
KPRIO_REALTIME1 , ///< priority: realtime + 2
|
||||
KPRIO_REALTIME2 , ///< priority: realtime + 3
|
||||
KPRIO_REALTIME3 , ///< priority: realtime + 4
|
||||
KPRIO_REALTIME4 , ///< priority: realtime + 5
|
||||
KPRIO_REALTIME5 , ///< priority: realtime + 6
|
||||
KPRIO_REALTIME6 , ///< priority: realtime + 7
|
||||
KPRIO_REALTIME7 , ///< priority: realtime + 8
|
||||
KPRIO_ISR , ///< priority: Reserved for ISR deferred thread
|
||||
KPRIO_ERROR ///< Illegal priority
|
||||
} k_priority_t;
|
||||
|
||||
/// Entry point of a task.
|
||||
typedef void (*k_task_entry_t)(void *arg);
|
||||
|
||||
/// Entry point of a timer call back function.
|
||||
typedef void (*k_timer_cb_t)(void *arg);
|
||||
|
||||
/// \details Task handle identifies the task.
|
||||
typedef void *k_task_handle_t;
|
||||
|
||||
/// \details Timer handle identifies the timer.
|
||||
typedef void *k_timer_handle_t;
|
||||
|
||||
/// \details Event Flags handle identifies the event flags.
|
||||
typedef void *k_event_handle_t;
|
||||
|
||||
/// \details Mutex handle identifies the mutex.
|
||||
typedef void *k_mutex_handle_t;
|
||||
|
||||
/// \details Semaphore handle identifies the semaphore.
|
||||
typedef void *k_sem_handle_t;
|
||||
|
||||
/// \details Memory Pool handle identifies the memory pool.
|
||||
typedef void *k_mpool_handle_t;
|
||||
|
||||
/// \details Message Queue handle identifies the message queue.
|
||||
typedef void *k_msgq_handle_t;
|
||||
|
||||
|
||||
|
||||
/* =================================================================================== */
|
||||
/* Kernel Management Functions */
|
||||
/* =================================================================================== */
|
||||
|
||||
/// Initialize the Kernel. Before it is successfully executed, no RTOS function should be called
|
||||
/// \return execution status code. \ref k_status_t
|
||||
k_status_t csi_kernel_init(void);
|
||||
|
||||
/// Start the kernel .It will not return to its calling function in case of success
|
||||
/// \return execution status code. \ref k_status_t
|
||||
k_status_t csi_kernel_start(void);
|
||||
|
||||
/// Get the current kernel state.
|
||||
/// \return current kernel state \ref k_sched_stat_t .
|
||||
k_sched_stat_t csi_kernel_get_stat(void);
|
||||
|
||||
|
||||
/* =================================================================================== */
|
||||
/* scheduler Management Functions */
|
||||
/* =================================================================================== */
|
||||
|
||||
/// Lock the scheduler.
|
||||
/// \return previous lock state (1 - locked, 0 - not locked, error code if negative).
|
||||
int32_t csi_kernel_sched_lock(void);
|
||||
|
||||
/// Unlock the scheduler.
|
||||
/// \return previous lock state (1 - locked, 0 - not locked, error code if negative).
|
||||
int32_t csi_kernel_sched_unlock(void);
|
||||
|
||||
/// Restore the scheduler lock state.
|
||||
/// \param[in] lock lock state obtained by \ref csi_kernel_sched_lock or \ref csi_kernel_sched_unlock.
|
||||
/// \return new lock state (1 - locked, 0 - not locked, error code if negative).
|
||||
int32_t csi_kernel_sched_restore_lock(int32_t lock);
|
||||
|
||||
/// Suspend the scheduler.
|
||||
/// \return time in ticks, for how long the system can sleep or power-down.
|
||||
uint32_t csi_kernel_sched_suspend(void);
|
||||
|
||||
/// Resume the scheduler.
|
||||
/// \param[in] sleep_ticks time in ticks for how long the system was in sleep or power-down mode.
|
||||
void csi_kernel_sched_resume(uint32_t sleep_ticks);
|
||||
|
||||
|
||||
/* =================================================================================== */
|
||||
/* Task Management Functions */
|
||||
/* =================================================================================== */
|
||||
|
||||
/// Create a task and add it to Active Tasks.
|
||||
/// \param[in] task task function.
|
||||
/// \param[in] name the name of task.
|
||||
/// \param[in] arg pointer that is passed to the task function as start argument.
|
||||
/// \param[in] prio task priority.
|
||||
/// \param[in] time_quanta the amount of time (in clock ticks) for the time quanta when round robin is enabled,if Zero, then use FIFO sched
|
||||
/// \param[in] stack stack base.
|
||||
/// \param[in] stack_size stack size.
|
||||
/// \param[in] task_handle reference to a task handle.
|
||||
/// \return execution status code. \ref k_status_t
|
||||
k_status_t csi_kernel_task_new(k_task_entry_t task, const char *name, void *arg,
|
||||
k_priority_t prio, uint32_t time_quanta,
|
||||
void *stack, uint32_t stack_size, k_task_handle_t *task_handle);
|
||||
|
||||
/// Delete a task.
|
||||
/// \param[in] task_handle task handle to operate.
|
||||
/// \return execution status code. \ref k_status_t
|
||||
k_status_t csi_kernel_task_del(k_task_handle_t task_handle);
|
||||
|
||||
/// Return the task handle of the current running task.
|
||||
/// \return task handle for reference by other functions or NULL in case of error.
|
||||
k_task_handle_t csi_kernel_task_get_cur(void);
|
||||
|
||||
/// Get current task state of a task.
|
||||
/// \param[in] task_handle task handle to operate.
|
||||
/// \return current task state of the specified task.
|
||||
k_task_stat_t csi_kernel_task_get_stat(k_task_handle_t task_handle);
|
||||
|
||||
/// Change priority of a task.
|
||||
/// \param[in] task_handle task handle to operate.
|
||||
/// \param[in] priority new priority value for the task function.
|
||||
/// \return execution status code. \ref k_status_t
|
||||
k_status_t csi_kernel_task_set_prio(k_task_handle_t task_handle, k_priority_t priority);
|
||||
|
||||
k_status_t csi_kernel_task_set_lprun(k_task_handle_t task_handle, uint8_t run);
|
||||
|
||||
void csi_kernel_lpower_mode(uint8_t enable);
|
||||
|
||||
/// Get current priority of a task.
|
||||
/// \param[in] task_handle task handle to operate.
|
||||
/// \return current priority value of the specified task.negative indicates error code.
|
||||
k_priority_t csi_kernel_task_get_prio(k_task_handle_t task_handle);
|
||||
|
||||
/// Get name of a task.
|
||||
/// \param[in] task_handle task handle to operate.
|
||||
/// \return name of the task.
|
||||
const char *csi_kernel_task_get_name(k_task_handle_t task_handle);
|
||||
|
||||
/// Suspend execution of a task.
|
||||
/// \param[in] task_handle task handle to operate.
|
||||
/// \return execution status code. \ref k_status_t
|
||||
k_status_t csi_kernel_task_suspend(k_task_handle_t task_handle);
|
||||
|
||||
/// Resume execution of a task.
|
||||
/// \param[in] task_handle task handle to operate.
|
||||
/// \return execution status code. \ref k_status_t
|
||||
k_status_t csi_kernel_task_resume(k_task_handle_t task_handle);
|
||||
|
||||
/// Terminate execution of a task.
|
||||
/// \param[in] task_handle task handle to operate.
|
||||
/// \return execution status code. \ref k_status_t
|
||||
k_status_t csi_kernel_task_terminate(k_task_handle_t task_handle);
|
||||
|
||||
void csi_kernel_task_dump(k_task_handle_t task_handle, void* stack);
|
||||
|
||||
/// Exit from the calling task.
|
||||
/// \return none
|
||||
void csi_kernel_task_exit(void);
|
||||
|
||||
/// Pass control to next task that is in state \b READY.
|
||||
/// \return execution status code. \ref k_status_t
|
||||
k_status_t csi_kernel_task_yield(void);
|
||||
|
||||
/// Get number of active tasks.
|
||||
/// \return number of active tasks.
|
||||
uint32_t csi_kernel_task_get_count(void);
|
||||
|
||||
/// Get stack size of a task.
|
||||
/// \param[in] task_handle task handle to operate.
|
||||
/// \return stack size in bytes.
|
||||
uint32_t csi_kernel_task_get_stack_size(k_task_handle_t task_handle);
|
||||
|
||||
/// Get available stack space of a thread based on stack watermark recording during execution.
|
||||
/// \param[in] task_handle task handle to operate.
|
||||
/// \return remaining stack space in bytes.
|
||||
uint32_t csi_kernel_task_get_stack_space(k_task_handle_t task_handle);
|
||||
|
||||
/// Enumerate active tasks.
|
||||
/// \param[out] task_array pointer to array for retrieving task handles.
|
||||
/// \param[in] array_items maximum number of items in array for retrieving task handles.
|
||||
/// \return number of enumerated tasks.
|
||||
uint32_t csi_kernel_task_list(k_task_handle_t *task_array, uint32_t array_items);
|
||||
|
||||
/// System enter interrupt status.
|
||||
/// \return execution status code. \ref k_status_t
|
||||
k_status_t csi_kernel_intrpt_enter(void);
|
||||
|
||||
/// System exit interrupt status.
|
||||
/// \return execution status code. \ref k_status_t
|
||||
k_status_t csi_kernel_intrpt_exit(void);
|
||||
|
||||
/* =================================================================================== */
|
||||
/* Generic time Functions */
|
||||
/* =================================================================================== */
|
||||
|
||||
/// Waits for a time period specified in kernel ticks.
|
||||
/// \param[in] ticks time ticks value
|
||||
/// \return execution status code. \ref k_status_t
|
||||
k_status_t csi_kernel_delay(uint32_t ticks);
|
||||
|
||||
/// Waits until an absolute time (specified in kernel ticks) is reached.
|
||||
/// \param[in] ticks absolute time in ticks
|
||||
/// \return execution status code. \ref k_status_t
|
||||
k_status_t csi_kernel_delay_until(uint64_t ticks);
|
||||
|
||||
/// Convert kernel ticks to ms.
|
||||
/// \param[in] ticks ticks which will be converted to ms
|
||||
/// \return the ms of the ticks.
|
||||
uint64_t csi_kernel_tick2ms(uint32_t ticks);
|
||||
|
||||
/// Convert ms to kernel ticks.
|
||||
/// \param[in] ms ms which will be converted to ticks
|
||||
/// \return the ticks of the ms.
|
||||
uint64_t csi_kernel_ms2tick(uint32_t ms);
|
||||
|
||||
/// Waits for a time period specified in ms.
|
||||
/// \param[in] ms time to be delayed in ms
|
||||
/// \return execution status code. \ref k_status_t
|
||||
k_status_t csi_kernel_delay_ms(uint32_t ms);
|
||||
|
||||
/// Get kernel ticks.
|
||||
/// \return kernel ticks number
|
||||
uint64_t csi_kernel_get_ticks(void);
|
||||
|
||||
/// Get the RTOS kernel tick frequency.
|
||||
/// \return frequency of the kernel tick.
|
||||
uint32_t csi_kernel_get_tick_freq(void);
|
||||
|
||||
/// Get the RTOS kernel system timer frequency.
|
||||
/// \return frequency of the system timer.
|
||||
uint32_t csi_kernel_get_systimer_freq(void);
|
||||
|
||||
/* =================================================================================== */
|
||||
/* Timer Management Functions */
|
||||
/* =================================================================================== */
|
||||
|
||||
/// Create and Initialize a timer.
|
||||
/// \param[in] func start address of a timer call back function.
|
||||
/// \param[in] type time type, \ref k_timer_type_t.
|
||||
/// \param[in] arg argument to the timer call back function.
|
||||
/// \return timer handle for reference by other functions or NULL in case of error.
|
||||
k_timer_handle_t csi_kernel_timer_new(k_timer_cb_t func, k_timer_type_t type, void *arg);
|
||||
|
||||
/// Delete a timer.
|
||||
/// \param[in] timer_handle timer handle to operate.
|
||||
/// \return execution status code. \ref k_status_t
|
||||
k_status_t csi_kernel_timer_del(k_timer_handle_t timer_handle);
|
||||
|
||||
/// Start or restart a timer.
|
||||
/// \param[in] timer_handle timer handle to operate.
|
||||
/// \param[in] ticks time out value in ticks
|
||||
/// \return execution status code. \ref k_status_t
|
||||
k_status_t csi_kernel_timer_start(k_timer_handle_t timer_handle, uint32_t ticks);
|
||||
|
||||
/// Stop a timer.
|
||||
/// \param[in] timer_handle timer handle to operate.
|
||||
/// \return execution status code. \ref k_status_t
|
||||
k_status_t csi_kernel_timer_stop(k_timer_handle_t timer_handle);
|
||||
|
||||
/// Check if a timer is running.
|
||||
/// \param[in] timer_handle timer handle to operate.
|
||||
/// \return \ref k_timer_stat_t.
|
||||
k_timer_stat_t csi_kernel_timer_get_stat(k_timer_handle_t timer_handle);
|
||||
|
||||
|
||||
/* =================================================================================== */
|
||||
/* Event Management Functions */
|
||||
/* =================================================================================== */
|
||||
|
||||
/// Create and Initialize an Event Flags object.
|
||||
/// \return event flags handle for reference by other functions or NULL in case of error.
|
||||
k_event_handle_t csi_kernel_event_new(void);
|
||||
|
||||
/// Delete an Event Flags object.
|
||||
/// \param[in] ev_handle event flags handle to operate.
|
||||
/// \return execution status code. \ref k_status_t
|
||||
k_status_t csi_kernel_event_del(k_event_handle_t ev_handle);
|
||||
|
||||
/// Set the specified Event Flags.
|
||||
/// \param[in] ev_handle event flags handle to operate.
|
||||
/// \param[in] flags specifies the flags that shall be set.
|
||||
/// \param[out] ret_flags The value of the event after setting.
|
||||
/// \return execution status code. \ref k_status_t
|
||||
k_status_t csi_kernel_event_set(k_event_handle_t ev_handle, uint32_t flags, uint32_t *ret_flags);
|
||||
|
||||
/// Clear the specified Event Flags.
|
||||
/// \param[in] ev_handle event flags handle to operate.
|
||||
/// \param[in] flags specifies the flags that shall be clear.
|
||||
/// \param[out] ret_flags event flags before clearing.
|
||||
/// \return execution status code. \ref k_status_t
|
||||
k_status_t csi_kernel_event_clear(k_event_handle_t ev_handle, uint32_t flags, uint32_t *ret_flags);
|
||||
|
||||
/// Get the current Event Flags. This function allows the user to know “Who did it!”
|
||||
/// \param[in] ev_handle event flags handle to operate.
|
||||
/// \param[out] ret_flags The value of the current event.
|
||||
/// \return execution status code. \ref k_status_t
|
||||
k_status_t csi_kernel_event_get(k_event_handle_t ev_handle, uint32_t *ret_flags);
|
||||
|
||||
/// Wait for one or more Event Flags to become signaled.
|
||||
/// \param[in] ev_handle event flags handle to operate.
|
||||
/// \param[in] flags specifies the flags to wait for.
|
||||
/// \param[in] options specifies flags options, \ref k_event_opt_t.
|
||||
/// \param[in] clr_on_exit 1 - event flags will be cleared before exit, otherwise event flags are not altered
|
||||
/// \param[out] actl_flags The value of the event at the time either the bits being waited for became set, or the block time expired.
|
||||
/// \param[in] timeout time out value in ticks if > 0, 0 in case of no time-out, negative in case of wait forever
|
||||
/// \return execution status code. \ref k_status_t
|
||||
k_status_t csi_kernel_event_wait(k_event_handle_t ev_handle, uint32_t flags,
|
||||
k_event_opt_t options, uint8_t clr_on_exit,
|
||||
uint32_t *actl_flags, int32_t timeout);
|
||||
|
||||
|
||||
/* =================================================================================== */
|
||||
/* Mutex Management Functions */
|
||||
/* =================================================================================== */
|
||||
|
||||
/// Create and Initialize a Mutex object.
|
||||
/// \return mutex handle for reference by other functions or NULL in case of error.
|
||||
k_mutex_handle_t csi_kernel_mutex_new(void);
|
||||
|
||||
/// Delete a Mutex object.
|
||||
/// \param[in] mutex_handle mutex handle to operate.
|
||||
/// \return execution status code. \ref k_status_t
|
||||
k_status_t csi_kernel_mutex_del(k_mutex_handle_t mutex_handle);
|
||||
|
||||
/// Acquire a Mutex or timeout if it is locked.
|
||||
/// \param[in] mutex_handle mutex handle to operate.
|
||||
/// \param[in] timeout time out value in ticks if > 0, 0 in case of no time-out, negative in case of wait forever
|
||||
/// \return execution status code. \ref k_status_t
|
||||
k_status_t csi_kernel_mutex_lock(k_mutex_handle_t mutex_handle, int32_t timeout, uint32_t lr);
|
||||
|
||||
/// Release a Mutex that was acquired by \ref csi_kernel_mutex_new.
|
||||
/// \param[in] mutex_handle mutex handle to operate.
|
||||
/// \return execution status code. \ref k_status_t
|
||||
k_status_t csi_kernel_mutex_unlock(k_mutex_handle_t mutex_handle);
|
||||
|
||||
/// Get Thread which owns a Mutex object.
|
||||
/// \param[in] mutex_handle mutex handle to operate.
|
||||
/// \return task handle or NULL when mutex was not acquired.
|
||||
k_task_handle_t csi_kernel_mutex_get_owner(k_mutex_handle_t mutex_handle);
|
||||
|
||||
/* =================================================================================== */
|
||||
/* Semaphore Management Functions */
|
||||
/* =================================================================================== */
|
||||
|
||||
/// Create and Initialize a Semaphore object.
|
||||
/// \param[in] max_count maximum number of available tokens.
|
||||
/// \param[in] initial_count initial number of available tokens.
|
||||
/// \return semaphore handle for reference by other functions or NULL in case of error.
|
||||
k_sem_handle_t csi_kernel_sem_new(int32_t max_count, int32_t initial_count);
|
||||
|
||||
/// Delete a Semaphore object.
|
||||
/// \param[in] sem_handle semaphore handle to operate.
|
||||
/// \return execution status code. \ref k_status_t
|
||||
k_status_t csi_kernel_sem_del(k_sem_handle_t sem_handle);
|
||||
|
||||
/// Acquire a Semaphore token or timeout if no tokens are available.
|
||||
/// \param[in] sem_handle semaphore handle to operate.
|
||||
/// \param[in] timeout time out value in ticks if > 0, 0 in case of no time-out, negative in case of wait forever
|
||||
/// \return execution status code. \ref k_status_t
|
||||
k_status_t csi_kernel_sem_wait(k_sem_handle_t sem_handle, int32_t timeout);
|
||||
|
||||
/// Release a Semaphore token that was acquired by \ref csi_kernel_sem_wait.
|
||||
/// \param[in] sem_handle semaphore handle to operate.
|
||||
/// \return execution status code. \ref k_status_t
|
||||
k_status_t csi_kernel_sem_post(k_sem_handle_t sem_handle);
|
||||
|
||||
/// Get current Semaphore token count.
|
||||
/// \param[in] sem_handle semaphore handle to operate.
|
||||
/// \return number of tokens available. negative indicates error code.
|
||||
int32_t csi_kernel_sem_get_count(k_sem_handle_t sem_handle);
|
||||
|
||||
|
||||
/* =================================================================================== */
|
||||
/* Memory Pool Management Functions */
|
||||
/* =================================================================================== */
|
||||
|
||||
/// Create and Initialize a Memory Pool object.
|
||||
/// \param[in] p_addr memory block base address.
|
||||
/// \param[in] block_count maximum number of memory blocks in memory pool.
|
||||
/// \param[in] block_size memory block size in bytes.
|
||||
/// \return memory pool handle for reference by other functions or NULL in case of error.
|
||||
k_mpool_handle_t csi_kernel_mpool_new(void *p_addr, int32_t block_count, int32_t block_size);
|
||||
|
||||
/// Delete a Memory Pool object.
|
||||
/// \param[in] mp_handle memory pool handle to operate.
|
||||
/// \return execution status code. \ref k_status_t
|
||||
k_status_t csi_kernel_mpool_del(k_mpool_handle_t mp_handle);
|
||||
|
||||
/// Allocate a memory block from a Memory Pool.
|
||||
/// \param[in] mp_handle memory pool handle to operate.
|
||||
/// \param[in] timeout time out value in ticks if > 0, 0 in case of no time-out, negative in case of wait forever
|
||||
/// \return address of the allocated memory block or NULL in case of no memory is available.
|
||||
void *csi_kernel_mpool_alloc(k_mpool_handle_t mp_handle, int32_t timeout);
|
||||
|
||||
/// Return an allocated memory block back to a Memory Pool.
|
||||
/// \param[in] mp_handle memory pool handle to operate.
|
||||
/// \param[in] block address of the allocated memory block to be returned to the memory pool.
|
||||
/// \return execution status code. \ref k_status_t
|
||||
k_status_t csi_kernel_mpool_free(k_mpool_handle_t mp_handle, void *block);
|
||||
|
||||
/// Get number of memory blocks used in a Memory Pool.
|
||||
/// \param[in] mp_handle memory pool handle to operate.
|
||||
/// \return number of memory blocks used. negative indicates error code.
|
||||
int32_t csi_kernel_mpool_get_count(k_mpool_handle_t mp_handle);
|
||||
|
||||
/// Get maximum number of memory blocks in a Memory Pool.
|
||||
/// \param[in] mp_handle memory pool handle to operate.
|
||||
/// \return maximum number of memory blocks.
|
||||
uint32_t csi_kernel_mpool_get_capacity(k_mpool_handle_t mp_handle);
|
||||
|
||||
/// Get memory block size in a Memory Pool.
|
||||
/// \param[in] mp_handle memory pool handle to operate.
|
||||
/// \return memory block size in bytes.
|
||||
uint32_t csi_kernel_mpool_get_block_size(k_mpool_handle_t mp_handle);
|
||||
|
||||
/* =================================================================================== */
|
||||
/* Message Queue Management Functions */
|
||||
/* =================================================================================== */
|
||||
|
||||
/// Create and Initialize a Message Queue object.
|
||||
/// \param[in] msg_count maximum number of messages in queue.
|
||||
/// \param[in] msg_size maximum message size in bytes.
|
||||
/// \return message queue handle for reference by other functions or NULL in case of error.
|
||||
k_msgq_handle_t csi_kernel_msgq_new(int32_t msg_count, int32_t msg_size);
|
||||
|
||||
/// Delete a Message Queue object.
|
||||
/// \param[in] mq_handle message queue handle to operate.
|
||||
/// \return execution status code. \ref k_status_t
|
||||
k_status_t csi_kernel_msgq_del(k_msgq_handle_t mq_handle);
|
||||
|
||||
/// Put a Message into a Queue or timeout if Queue is full.
|
||||
/// \param[in] mq_handle message queue handle to operate.
|
||||
/// \param[in] msg_ptr pointer to buffer with message to put into a queue.
|
||||
/// \param[in] front_or_back specify this msg to be put to front or back. 1 - front, 0 -back
|
||||
/// \param[in] timeout time out value in ticks if > 0, 0 in case of no time-out, negative in case of wait forever
|
||||
/// \return execution status code. \ref k_status_t
|
||||
k_status_t csi_kernel_msgq_put(k_msgq_handle_t mq_handle, const void *msg_ptr, uint8_t front_or_back, int32_t timeout);
|
||||
|
||||
/// Get a Message from a Queue or timeout if Queue is empty.
|
||||
/// \param[in] mq_handle message queue handle to operate.
|
||||
/// \param[out] msg_ptr pointer to buffer for message to get from a queue.
|
||||
/// \param[in] timeout time out value in ticks if > 0, 0 in case of no time-out, negative in case of wait forever
|
||||
/// \return execution status code. \ref k_status_t
|
||||
k_status_t csi_kernel_msgq_get(k_msgq_handle_t mq_handle, void *msg_ptr, int32_t timeout);
|
||||
|
||||
/// Get number of queued messages in a message queue.
|
||||
/// \param[in] mq_handle message queue handle to operate.
|
||||
/// \return number of queued messages.negative indicates error code.
|
||||
int32_t csi_kernel_msgq_get_count(k_msgq_handle_t mq_handle);
|
||||
|
||||
/// Get maximum number of messages in a message queue.
|
||||
/// \param[in] mq_handle message queue handle to operate.
|
||||
/// \return maximum number of messages.
|
||||
uint32_t csi_kernel_msgq_get_capacity(k_msgq_handle_t mq_handle);
|
||||
|
||||
/// Get maximum message size in a message queue.
|
||||
/// \param[in] mq_handle message queue handle to operate.
|
||||
/// \return maximum message size in bytes.
|
||||
uint32_t csi_kernel_msgq_get_msg_size(k_msgq_handle_t mq_handle);
|
||||
|
||||
/// Reset a Message Queue to initial empty state.
|
||||
/// \param[in] mq_handle message queue handle to operate.
|
||||
/// \return execution status code. \ref k_status_t
|
||||
k_status_t csi_kernel_msgq_flush(k_msgq_handle_t mq_handle);
|
||||
|
||||
|
||||
/* =================================================================================== */
|
||||
/* Heap Management Functions */
|
||||
/* =================================================================================== */
|
||||
|
||||
/// Allocates size bytes and returns a pointer to the allocated memory.
|
||||
/// \param[in] size Allocates size bytes.
|
||||
/// \param[in] caller the function who call this interface or NULL.
|
||||
/// \return a pointer to the allocated memory.
|
||||
void *csi_kernel_malloc(int32_t size, void *caller);
|
||||
|
||||
/// Frees the memory space pointed to by ptr
|
||||
/// \param[in] ptr a pointer to memory block, return by csi_kernel_malloc or csi_kernel_realloc.
|
||||
/// \param[in] caller the function who call this interface or NULL.
|
||||
/// \return void
|
||||
void csi_kernel_free(void *ptr, void *caller);
|
||||
|
||||
/// Changes the size of the memory block pointed to by ptr to size bytes
|
||||
/// \param[in] ptr a pointer to memory block, return by csi_kernel_malloc or csi_kernel_realloc.
|
||||
/// \param[in] size Allocates size bytes.
|
||||
/// \param[in] caller the function who call this interface or NULL.
|
||||
/// \return a pointer to the allocated memory.
|
||||
void *csi_kernel_realloc(void *ptr, int32_t size, void *caller);
|
||||
|
||||
/// Get csi memory used info.
|
||||
/// \param[out] total the total memory can be use.
|
||||
/// \param[out] used the used memory by malloc.
|
||||
/// \param[out] free the free memory can be use.
|
||||
/// \param[out] peak the peak memory used.
|
||||
/// \return execution status code. \ref k_status_t.
|
||||
k_status_t csi_kernel_get_mminfo(int32_t *total, int32_t *used, int32_t *free, int32_t *peak);
|
||||
|
||||
/// Dump csi memory .
|
||||
/// \param void
|
||||
/// \return execution status code. \ref k_status_t.
|
||||
k_status_t csi_kernel_mm_dump(void);
|
||||
|
||||
void csi_kernel_blklist_suspend(void *hdl, k_task_handle_t task_hdl);
|
||||
void csi_kernel_blklist_wakeup(void *hdl);
|
||||
void *csi_kernel_blklist_new();
|
||||
void csi_kernel_blklist_del(void *hdl);
|
||||
uint64_t krhino_curr_nanosec(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // _CSI_KERNEL_
|
||||
1574
csky/csi_kernel/rhino/adapter/csi_rhino.c
Normal file
1574
csky/csi_kernel/rhino/adapter/csi_rhino.c
Normal file
File diff suppressed because it is too large
Load Diff
49
csky/csi_kernel/rhino/arch/csky/ck803/port_c.c
Normal file
49
csky/csi_kernel/rhino/arch/csky/ck803/port_c.c
Normal file
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (C) 2016 YunOS Project. All rights reserved.
|
||||
*
|
||||
* 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 <k_api.h>
|
||||
#include "csi_core.h"
|
||||
void *cpu_task_stack_init(cpu_stack_t *stack_base, size_t stack_size,
|
||||
void *arg, task_entry_t entry)
|
||||
{
|
||||
cpu_stack_t *stk;
|
||||
uint32_t temp = (uint32_t)(stack_base + stack_size);
|
||||
|
||||
temp &= 0xfffffffc;
|
||||
|
||||
stk = (cpu_stack_t *)temp;
|
||||
*(--stk) = (uint32_t)0x28282828L; /* R28 */
|
||||
*(--stk) = (uint32_t)entry; /* entry point */
|
||||
*(--stk) = (uint32_t)0x80000140L; /* PSR */
|
||||
*(--stk) = (uint32_t)krhino_task_deathbed; /* R15 (LR) */
|
||||
*(--stk) = (uint32_t)0x13131313L; /* R13 */
|
||||
*(--stk) = (uint32_t)0x12121212L; /* R12 */
|
||||
*(--stk) = (uint32_t)0x11111111L; /* R11 */
|
||||
*(--stk) = (uint32_t)0x10101010L; /* R10 */
|
||||
*(--stk) = (uint32_t)0x09090909L; /* R9 */
|
||||
*(--stk) = (uint32_t)0x00000000L; /* R8 */
|
||||
*(--stk) = (uint32_t)0x07070707L; /* R7 */
|
||||
*(--stk) = (uint32_t)0x06060606L; /* R6 */
|
||||
*(--stk) = (uint32_t)0x05050505L; /* R5 */
|
||||
*(--stk) = (uint32_t)0x04040404L; /* R4 */
|
||||
*(--stk) = (uint32_t)0x03030303L; /* R3 */
|
||||
*(--stk) = (uint32_t)0x02020202L; /* R2 */
|
||||
*(--stk) = (uint32_t)0x01010101L; /* R1 */
|
||||
*(--stk) = (uint32_t)arg; /* R0 : argument */
|
||||
|
||||
return stk;
|
||||
}
|
||||
|
||||
180
csky/csi_kernel/rhino/arch/csky/ck803/port_s.S
Normal file
180
csky/csi_kernel/rhino/arch/csky/ck803/port_s.S
Normal file
@@ -0,0 +1,180 @@
|
||||
/*
|
||||
* Copyright (C) 2016 YunOS Project. All rights reserved.
|
||||
*
|
||||
* 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 <k_config.h>
|
||||
|
||||
#define VIC_TSPDR 0XE000EC08
|
||||
|
||||
.extern g_active_task
|
||||
.extern g_preferred_ready_task
|
||||
.extern krhino_task_sched_stats_get
|
||||
.extern krhino_stack_ovf_check
|
||||
/******************************************************************************
|
||||
* EXPORT FUNCTIONS
|
||||
******************************************************************************/
|
||||
|
||||
.global cpu_intrpt_save
|
||||
.global cpu_intrpt_restore
|
||||
.global cpu_task_switch
|
||||
.global cpu_intrpt_switch
|
||||
.global cpu_first_task_start
|
||||
.global tspend_handler
|
||||
|
||||
/******************************************************************************
|
||||
* EQUATES
|
||||
******************************************************************************/
|
||||
|
||||
/******************************************************************************
|
||||
* CODE GENERATION DIRECTIVES
|
||||
******************************************************************************/
|
||||
|
||||
.text
|
||||
.align 2
|
||||
|
||||
/******************************************************************************
|
||||
* Functions:
|
||||
* size_t cpu_intrpt_save(void);
|
||||
* void cpu_intrpt_restore(size_t psr);
|
||||
******************************************************************************/
|
||||
|
||||
.type cpu_intrpt_save, %function
|
||||
cpu_intrpt_save:
|
||||
mfcr r0, psr
|
||||
psrclr ie
|
||||
rts
|
||||
|
||||
.type cpu_intrpt_restore, %function
|
||||
cpu_intrpt_restore:
|
||||
mtcr r0, psr
|
||||
btsti r0, 6
|
||||
bf .Lret
|
||||
lrw r1, 0x00ff0000
|
||||
and r1, r0
|
||||
cmpnei r1, 0
|
||||
bt .Lret
|
||||
lrw r1, VIC_TSPDR
|
||||
.Lloop:
|
||||
ldw r2, (r1)
|
||||
btsti r2, 0
|
||||
bt .Lloop
|
||||
.Lret:
|
||||
rts
|
||||
|
||||
/******************************************************************************
|
||||
* Functions:
|
||||
* void cpu_intrpt_switch(void);
|
||||
* void cpu_task_switch(void);
|
||||
******************************************************************************/
|
||||
|
||||
.type cpu_task_switch, %function
|
||||
cpu_task_switch:
|
||||
lrw r0, VIC_TSPDR
|
||||
bgeni r1, 0
|
||||
stw r1, (r0)
|
||||
rts
|
||||
|
||||
.type cpu_intrpt_switch, %function
|
||||
cpu_intrpt_switch:
|
||||
lrw r0, VIC_TSPDR
|
||||
bgeni r1, 0
|
||||
stw r1, (r0)
|
||||
rts
|
||||
|
||||
/******************************************************************************
|
||||
* Functions:
|
||||
* void cpu_first_task_start(void);
|
||||
******************************************************************************/
|
||||
|
||||
.type cpu_first_task_start, %function
|
||||
cpu_first_task_start:
|
||||
psrclr ie
|
||||
jbr __tspend_handler_nosave
|
||||
|
||||
/******************************************************************************
|
||||
* Functions:
|
||||
* void __task_switch(void);
|
||||
******************************************************************************/
|
||||
|
||||
.type tspend_handler, %function
|
||||
tspend_handler:
|
||||
#ifdef __CK803__
|
||||
subi sp, 72
|
||||
#else
|
||||
subi sp, 68
|
||||
#endif
|
||||
stm r0-r13, (sp)
|
||||
stw r15, (sp, 56)
|
||||
mfcr r0, epsr
|
||||
stw r0, (sp, 60)
|
||||
mfcr r0, epc
|
||||
stw r0, (sp, 64)
|
||||
#ifdef __CK803__
|
||||
stw r28, (sp, 68)
|
||||
#endif
|
||||
|
||||
lrw r0, g_sched_lock
|
||||
ldb r1, (r0)
|
||||
cmpnei r1, 0
|
||||
bt .Lnot_switch
|
||||
|
||||
lrw r2, g_active_task
|
||||
ldw r2, (r2)
|
||||
stw sp, (r2)
|
||||
|
||||
#if (RHINO_CONFIG_TASK_STACK_OVF_CHECK > 0)
|
||||
jbsr krhino_stack_ovf_check
|
||||
#endif
|
||||
|
||||
#if (RHINO_CONFIG_TASK_SCHED_STATS > 0)
|
||||
jbsr krhino_task_sched_stats_get
|
||||
#endif
|
||||
|
||||
__tspend_handler_nosave:
|
||||
lrw r4, g_active_task
|
||||
lrw r5, g_preferred_ready_task
|
||||
ldw r6, (r5)
|
||||
stw r6, (r4)
|
||||
|
||||
#ifdef CONFIG_STACK_GUARD
|
||||
jbsr csky_set_stackbound
|
||||
#endif
|
||||
|
||||
ldw sp, (r6)
|
||||
|
||||
#ifdef CONFIG_STACK_GUARD
|
||||
mfcr r3, cr<0, 4>
|
||||
bseti r3, 0
|
||||
bseti r3, 1
|
||||
mtcr r3, cr<0, 4>
|
||||
#endif
|
||||
|
||||
.Lnot_switch:
|
||||
#ifdef __CK803__
|
||||
ldw r28, (sp, 68)
|
||||
#endif
|
||||
ldw r0, (sp, 64)
|
||||
mtcr r0, epc
|
||||
ldw r0, (sp, 60)
|
||||
mtcr r0, epsr
|
||||
ldw r15, (sp, 56)
|
||||
ldm r0-r13, (sp)
|
||||
#ifdef __CK803__
|
||||
addi sp, 72
|
||||
#else
|
||||
addi sp, 68
|
||||
#endif
|
||||
rte
|
||||
|
||||
93
csky/csi_kernel/rhino/arch/csky/cpu_impl.c
Normal file
93
csky/csi_kernel/rhino/arch/csky/cpu_impl.c
Normal file
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
* Copyright (C) 2016 YunOS Project. All rights reserved.
|
||||
*
|
||||
* 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 <k_api.h>
|
||||
#include <k_config.h>
|
||||
|
||||
#if (RHINO_CONFIG_STACK_OVF_CHECK_HW != 0)
|
||||
void cpu_intrpt_stack_protect(void)
|
||||
{
|
||||
}
|
||||
|
||||
void task_stack_crash_warning(void)
|
||||
{
|
||||
printf("****The task stack base has been broken !!!****\n");
|
||||
}
|
||||
|
||||
void cpu_task_stack_protect(cpu_stack_t *base, size_t size)
|
||||
{
|
||||
uint32_t base_addr = (uint32_t)base;
|
||||
|
||||
int num_return = wp_register(base_addr, AWATCH, task_stack_crash_warning);
|
||||
if (num_return == 1) {
|
||||
wp_enable(1);
|
||||
} else if (num_return == 2 || num_return == -1) {
|
||||
wp_unregister(1);
|
||||
int number_tmp = wp_register(base_addr, AWATCH, task_stack_crash_warning);
|
||||
if (number_tmp == 1){
|
||||
wp_enable(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_STACK_GUARD
|
||||
|
||||
void csky_set_stackbound(void)
|
||||
{
|
||||
uint32_t size;
|
||||
cpu_stack_t *base;
|
||||
|
||||
ktask_t *get_task = (ktask_t *)g_active_task;
|
||||
|
||||
base = get_task->task_stack_base;
|
||||
size = get_task->stack_size;
|
||||
|
||||
asm volatile(
|
||||
"mfcr r9, cr<0, 4>\n\r"
|
||||
"bclri r9, 0\n\r"
|
||||
"mtcr r9, cr<0, 4>\n\r"
|
||||
"mtcr %0, cr<2, 4>\n\r"
|
||||
"lsli %1, %1, 2\n\r"
|
||||
"add %0, %0, %1\n\r"
|
||||
"mtcr %0, cr<1, 4>\n\r"
|
||||
::"r"(base), "r"(size):"r9");
|
||||
}
|
||||
|
||||
int stack_guard_save(void)
|
||||
{
|
||||
int value;
|
||||
|
||||
asm volatile(
|
||||
"mfcr %0, cr<0, 4>\n\t"
|
||||
"mov r0, %0\n\t"
|
||||
"bclri r0, 0\n\t"
|
||||
"mtcr r0, cr<0, 4>\n\t"
|
||||
:"=r"(value)
|
||||
::"r0");
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
void stack_guard_restore(int value)
|
||||
{
|
||||
asm volatile(
|
||||
"mtcr %0, cr<0, 4>\n\t"
|
||||
::"r"(value):
|
||||
);
|
||||
}
|
||||
|
||||
#endif
|
||||
92
csky/csi_kernel/rhino/arch/csky/csky_sched.c
Normal file
92
csky/csi_kernel/rhino/arch/csky/csky_sched.c
Normal file
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
* Copyright (C) 2016 YunOS Project. All rights reserved.
|
||||
*
|
||||
* 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 <k_api.h>
|
||||
|
||||
#undef PSR_SP
|
||||
#define PSR_SP (1UL << 29)
|
||||
static ktask_t *tee_caller_task = NULL;
|
||||
|
||||
static inline uint32_t getcurrentpsr(void)
|
||||
{
|
||||
uint32_t flags;
|
||||
|
||||
__asm__ __volatile__(
|
||||
"mfcr %0, psr \n"
|
||||
:"=r"(flags)
|
||||
:
|
||||
:
|
||||
);
|
||||
|
||||
return flags;
|
||||
}
|
||||
|
||||
static inline void clear_psr_sp(void)
|
||||
{
|
||||
__asm__ __volatile__ (
|
||||
"mfcr r0, psr \n"
|
||||
"bclri r0, 29 \n"
|
||||
"mtcr r0, psr \n"
|
||||
:
|
||||
:
|
||||
:"r0"
|
||||
);
|
||||
}
|
||||
|
||||
static inline void set_psr_sp(void)
|
||||
{
|
||||
__asm__ __volatile__ (
|
||||
"mfcr r0, psr \n"
|
||||
"bseti r0, 29 \n"
|
||||
"mtcr r0, psr \n"
|
||||
:
|
||||
:
|
||||
:"r0"
|
||||
);
|
||||
}
|
||||
|
||||
void csky_get_tee_caller_task(void)
|
||||
{
|
||||
uint32_t temp_psr;
|
||||
|
||||
temp_psr = getcurrentpsr();
|
||||
if (temp_psr & PSR_SP) {
|
||||
tee_caller_task = (tee_caller_task == NULL) ? g_active_task[cpu_cur_get()] : tee_caller_task;
|
||||
}
|
||||
}
|
||||
|
||||
void csky_deal_tee_caller_task(void)
|
||||
{
|
||||
uint32_t temp_psr;
|
||||
|
||||
temp_psr = getcurrentpsr();
|
||||
if (temp_psr & PSR_SP) {
|
||||
if (tee_caller_task != NULL) {
|
||||
if (tee_caller_task == g_active_task[cpu_cur_get()]) {
|
||||
tee_caller_task = NULL;
|
||||
} else {
|
||||
clear_psr_sp();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (tee_caller_task != NULL) {
|
||||
if (tee_caller_task == g_active_task[cpu_cur_get()]) {
|
||||
tee_caller_task = NULL;
|
||||
set_psr_sp();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
111
csky/csi_kernel/rhino/arch/csky/dump_backtrace.c
Normal file
111
csky/csi_kernel/rhino/arch/csky/dump_backtrace.c
Normal file
@@ -0,0 +1,111 @@
|
||||
/*
|
||||
* Copyright (C) 2016 YunOS Project. All rights reserved.
|
||||
*
|
||||
* 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 <csi_config.h>
|
||||
|
||||
#ifdef CONFIG_BACKTRACE
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <backtrace.h>
|
||||
|
||||
#define BT_SIZE 40
|
||||
void *g_bt_buffer[BT_SIZE];
|
||||
#define BT_STACK_SIZE 600
|
||||
int g_bt_stack[BT_STACK_SIZE / 4];
|
||||
char *g_dumpbuf = NULL;
|
||||
int g_dump_len = 0;
|
||||
int g_dump_max = 0;
|
||||
|
||||
void dump_backtrace(void)
|
||||
{
|
||||
int i;
|
||||
int nptr;
|
||||
|
||||
g_dump_len = 0;
|
||||
|
||||
nptr = backtrace(g_bt_buffer, BT_SIZE);
|
||||
|
||||
if (nptr <= 0) {
|
||||
printf("error: backtrace_symbols\n");
|
||||
return;
|
||||
}
|
||||
|
||||
for (i = 0; i < nptr; i++) {
|
||||
if (g_dumpbuf == NULL) {
|
||||
printf("[<%p>]\n", g_bt_buffer[i]);
|
||||
} else {
|
||||
g_dump_len += snprintf(&g_dumpbuf[g_dump_len], g_dump_max - g_dump_len, "[<%p>]\n", g_bt_buffer[i]);
|
||||
|
||||
if (g_dump_len >= g_dump_max) {
|
||||
printf("error, user buffer no space \n");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void __attribute__((naked))csky_show_backtrace(void *stack)
|
||||
{
|
||||
asm volatile(
|
||||
"subi sp, 68\n\t"
|
||||
"stm r0-r13, (sp)\n\t"
|
||||
"mtcr sp, cr<14, 1>\n\t"
|
||||
"stw r15, (sp, 56)\n\t"
|
||||
"mov sp, %0\n\t"
|
||||
|
||||
"lrw r0, g_bt_stack\n\t"
|
||||
"mov r1, sp\n\t"
|
||||
"sub r1, %1\n\t"
|
||||
"mov r2, %1\n\t"
|
||||
"mov r4, %1\n\t"
|
||||
"jbsr memcpy\n\t"
|
||||
|
||||
"ldw r8, (sp, 32)\n\t"
|
||||
"ldw r15, (sp, 64)\n\t"
|
||||
"subi sp, 16\n\t"
|
||||
"stw r8, (sp, 0)\n\t"
|
||||
"stw r15, (sp, 4)\n\t"
|
||||
"mov r8, sp\n\t"
|
||||
"jbsr dump_backtrace\n\t"
|
||||
|
||||
"addi sp, 16\n\t"
|
||||
"lrw r1, g_bt_stack\n\t"
|
||||
"mov r0, sp\n\t"
|
||||
"sub r0, r4\n\t"
|
||||
"mov r2, r4\n\t"
|
||||
"jbsr memcpy\n\t"
|
||||
|
||||
"mfcr sp, cr<14, 1>\n\t"
|
||||
"ldw r15, (sp, 56)\n\t"
|
||||
"ldm r0-r13, (sp)\n\t"
|
||||
"addi sp, 68\n\t"
|
||||
"jmp r15\n\t"
|
||||
::"r"(stack), "r"(BT_STACK_SIZE):);
|
||||
|
||||
}
|
||||
|
||||
int csky_task_backtrace(void *stack, void *buf, int len)
|
||||
{
|
||||
g_dumpbuf = buf;
|
||||
g_dump_max = len;
|
||||
|
||||
csky_show_backtrace(stack);
|
||||
|
||||
return g_dump_len;
|
||||
}
|
||||
#endif
|
||||
49
csky/csi_kernel/rhino/arch/csky/e802/port_c.c
Normal file
49
csky/csi_kernel/rhino/arch/csky/e802/port_c.c
Normal file
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Copyright (C) 2016 YunOS Project. All rights reserved.
|
||||
*
|
||||
* 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 <csi_core.h>
|
||||
#include <k_api.h>
|
||||
|
||||
void *cpu_task_stack_init(cpu_stack_t *stack_base, size_t stack_size,
|
||||
void *arg, task_entry_t entry)
|
||||
{
|
||||
cpu_stack_t *stk;
|
||||
uint32_t temp = (uint32_t)(stack_base + stack_size);
|
||||
|
||||
temp &= 0xfffffffc;
|
||||
|
||||
stk = (cpu_stack_t *)temp;
|
||||
|
||||
*(--stk) = (uint32_t)entry; /* entry point */
|
||||
*(--stk) = (uint32_t)0x80000140L; /* PSR */
|
||||
*(--stk) = (uint32_t)krhino_task_deathbed; /* R15 (LR) */
|
||||
*(--stk) = (uint32_t)0x13131313L; /* R13 */
|
||||
*(--stk) = (uint32_t)0x12121212L; /* R12 */
|
||||
*(--stk) = (uint32_t)0x11111111L; /* R11 */
|
||||
*(--stk) = (uint32_t)0x10101010L; /* R10 */
|
||||
*(--stk) = (uint32_t)0x09090909L; /* R9 */
|
||||
*(--stk) = (uint32_t)0x00000000L; /* R8 */
|
||||
*(--stk) = (uint32_t)0x07070707L; /* R7 */
|
||||
*(--stk) = (uint32_t)0x06060606L; /* R6 */
|
||||
*(--stk) = (uint32_t)0x05050505L; /* R5 */
|
||||
*(--stk) = (uint32_t)0x04040404L; /* R4 */
|
||||
*(--stk) = (uint32_t)0x03030303L; /* R3 */
|
||||
*(--stk) = (uint32_t)0x02020202L; /* R2 */
|
||||
*(--stk) = (uint32_t)0x01010101L; /* R1 */
|
||||
*(--stk) = (uint32_t)arg; /* R0 : argument */
|
||||
|
||||
return stk;
|
||||
}
|
||||
|
||||
180
csky/csi_kernel/rhino/arch/csky/e802/port_s.S
Normal file
180
csky/csi_kernel/rhino/arch/csky/e802/port_s.S
Normal file
@@ -0,0 +1,180 @@
|
||||
/*
|
||||
* Copyright (C) 2016 YunOS Project. All rights reserved.
|
||||
*
|
||||
* 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 <k_config.h>
|
||||
|
||||
#define VIC_TSPDR 0XE000EC08
|
||||
|
||||
.extern g_active_task
|
||||
.extern g_preferred_ready_task
|
||||
.extern krhino_task_sched_stats_get
|
||||
.extern krhino_stack_ovf_check
|
||||
/******************************************************************************
|
||||
* EXPORT FUNCTIONS
|
||||
******************************************************************************/
|
||||
|
||||
.global cpu_intrpt_save
|
||||
.global cpu_intrpt_restore
|
||||
.global cpu_task_switch
|
||||
.global cpu_intrpt_switch
|
||||
.global cpu_first_task_start
|
||||
.global tspend_handler
|
||||
|
||||
/******************************************************************************
|
||||
* EQUATES
|
||||
******************************************************************************/
|
||||
|
||||
/******************************************************************************
|
||||
* CODE GENERATION DIRECTIVES
|
||||
******************************************************************************/
|
||||
|
||||
.text
|
||||
.align 2
|
||||
|
||||
/******************************************************************************
|
||||
* Functions:
|
||||
* size_t cpu_intrpt_save(void);
|
||||
* void cpu_intrpt_restore(size_t psr);
|
||||
******************************************************************************/
|
||||
|
||||
.type cpu_intrpt_save, %function
|
||||
cpu_intrpt_save:
|
||||
mfcr r0, psr
|
||||
psrclr ie
|
||||
rts
|
||||
|
||||
.type cpu_intrpt_restore, %function
|
||||
cpu_intrpt_restore:
|
||||
mtcr r0, psr
|
||||
btsti r0, 6
|
||||
bf .Lret
|
||||
lrw r1, 0x00ff0000
|
||||
and r1, r0
|
||||
cmpnei r1, 0
|
||||
bt .Lret
|
||||
lrw r1, VIC_TSPDR
|
||||
.Lloop:
|
||||
ldw r2, (r1)
|
||||
btsti r2, 0
|
||||
bt .Lloop
|
||||
.Lret:
|
||||
rts
|
||||
|
||||
/******************************************************************************
|
||||
* Functions:
|
||||
* void cpu_intrpt_switch(void);
|
||||
* void cpu_task_switch(void);
|
||||
******************************************************************************/
|
||||
|
||||
.type cpu_task_switch, %function
|
||||
cpu_task_switch:
|
||||
lrw r0, VIC_TSPDR
|
||||
bgeni r1, 0
|
||||
stw r1, (r0)
|
||||
rts
|
||||
|
||||
.type cpu_intrpt_switch, %function
|
||||
cpu_intrpt_switch:
|
||||
lrw r0, VIC_TSPDR
|
||||
bgeni r1, 0
|
||||
stw r1, (r0)
|
||||
rts
|
||||
|
||||
/******************************************************************************
|
||||
* Functions:
|
||||
* void cpu_first_task_start(void);
|
||||
******************************************************************************/
|
||||
|
||||
.type cpu_first_task_start, %function
|
||||
cpu_first_task_start:
|
||||
psrclr ie
|
||||
jbr __tspend_handler_nosave
|
||||
|
||||
/******************************************************************************
|
||||
* Functions:
|
||||
* void __task_switch(void);
|
||||
******************************************************************************/
|
||||
|
||||
.type tspend_handler, %function
|
||||
tspend_handler:
|
||||
#ifdef __CK803__
|
||||
subi sp, 72
|
||||
#else
|
||||
subi sp, 68
|
||||
#endif
|
||||
stm r0-r13, (sp)
|
||||
stw r15, (sp, 56)
|
||||
mfcr r0, epsr
|
||||
stw r0, (sp, 60)
|
||||
mfcr r0, epc
|
||||
stw r0, (sp, 64)
|
||||
#ifdef __CK803__
|
||||
stw r28, (sp, 68)
|
||||
#endif
|
||||
|
||||
lrw r0, g_sched_lock
|
||||
ldb r1, (r0)
|
||||
cmpnei r1, 0
|
||||
bt .Lnot_switch
|
||||
|
||||
lrw r2, g_active_task
|
||||
ldw r2, (r2)
|
||||
stw sp, (r2)
|
||||
|
||||
#if (RHINO_CONFIG_TASK_STACK_OVF_CHECK > 0)
|
||||
jbsr krhino_stack_ovf_check
|
||||
#endif
|
||||
|
||||
#if (RHINO_CONFIG_TASK_SCHED_STATS > 0)
|
||||
jbsr krhino_task_sched_stats_get
|
||||
#endif
|
||||
|
||||
__tspend_handler_nosave:
|
||||
lrw r4, g_active_task
|
||||
lrw r5, g_preferred_ready_task
|
||||
ldw r6, (r5)
|
||||
stw r6, (r4)
|
||||
|
||||
#ifdef CONFIG_STACK_GUARD
|
||||
jbsr csky_set_stackbound
|
||||
#endif
|
||||
|
||||
ldw sp, (r6)
|
||||
|
||||
#ifdef CONFIG_STACK_GUARD
|
||||
mfcr r3, cr<0, 4>
|
||||
bseti r3, 0
|
||||
bseti r3, 1
|
||||
mtcr r3, cr<0, 4>
|
||||
#endif
|
||||
|
||||
.Lnot_switch:
|
||||
#ifdef __CK803__
|
||||
ldw r28, (sp, 68)
|
||||
#endif
|
||||
ldw r0, (sp, 64)
|
||||
mtcr r0, epc
|
||||
ldw r0, (sp, 60)
|
||||
mtcr r0, epsr
|
||||
ldw r15, (sp, 56)
|
||||
ldm r0-r13, (sp)
|
||||
#ifdef __CK803__
|
||||
addi sp, 72
|
||||
#else
|
||||
addi sp, 68
|
||||
#endif
|
||||
rte
|
||||
|
||||
66
csky/csi_kernel/rhino/arch/csky/e804d/port_c.c
Normal file
66
csky/csi_kernel/rhino/arch/csky/e804d/port_c.c
Normal file
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright (C) 2016 YunOS Project. All rights reserved.
|
||||
*
|
||||
* 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 <k_api.h>
|
||||
#include <core_804.h>
|
||||
|
||||
void *cpu_task_stack_init(cpu_stack_t *stack_base, size_t stack_size,
|
||||
void *arg, task_entry_t entry)
|
||||
{
|
||||
cpu_stack_t *stk;
|
||||
uint32_t temp = (uint32_t)(stack_base + stack_size);
|
||||
|
||||
temp &= 0xFFFFFFFCUL;
|
||||
|
||||
stk = (cpu_stack_t *)temp;
|
||||
|
||||
*(--stk) = (uint32_t)entry; /* entry point */
|
||||
*(--stk) = (uint32_t)0x80000340L; /* PSR */
|
||||
*(--stk) = (uint32_t)0x31313131L; /* R31 */
|
||||
*(--stk) = (uint32_t)0x30303030L; /* R30 */
|
||||
*(--stk) = (uint32_t)0x29292929L; /* R29 */
|
||||
*(--stk) = (uint32_t)0x28282828L; /* R28 */
|
||||
*(--stk) = (uint32_t)0x27272727L; /* R27 */
|
||||
*(--stk) = (uint32_t)0x26262626L; /* R26 */
|
||||
*(--stk) = (uint32_t)0x25252525L; /* R25 */
|
||||
*(--stk) = (uint32_t)0x24242424L; /* R24 */
|
||||
*(--stk) = (uint32_t)0x23232323L; /* R23 */
|
||||
*(--stk) = (uint32_t)0x22222222L; /* R22 */
|
||||
*(--stk) = (uint32_t)0x21212121L; /* R21 */
|
||||
*(--stk) = (uint32_t)0x20202020L; /* R20 */
|
||||
*(--stk) = (uint32_t)0x19191919L; /* R19 */
|
||||
*(--stk) = (uint32_t)0x18181818L; /* R18 */
|
||||
*(--stk) = (uint32_t)0x17171717L; /* R17 */
|
||||
*(--stk) = (uint32_t)0x16161616L; /* R16 */
|
||||
*(--stk) = (uint32_t)krhino_task_deathbed; /* R15 (LR) */
|
||||
*(--stk) = (uint32_t)0x13131313L; /* R13 */
|
||||
*(--stk) = (uint32_t)0x12121212L; /* R12 */
|
||||
*(--stk) = (uint32_t)0x11111111L; /* R11 */
|
||||
*(--stk) = (uint32_t)0x10101010L; /* R10 */
|
||||
*(--stk) = (uint32_t)0x09090909L; /* R9 */
|
||||
*(--stk) = (uint32_t)0x00000000L; /* R8 */
|
||||
*(--stk) = (uint32_t)0x07070707L; /* R7 */
|
||||
*(--stk) = (uint32_t)0x06060606L; /* R6 */
|
||||
*(--stk) = (uint32_t)0x05050505L; /* R5 */
|
||||
*(--stk) = (uint32_t)0x04040404L; /* R4 */
|
||||
*(--stk) = (uint32_t)0x03030303L; /* R3 */
|
||||
*(--stk) = (uint32_t)0x02020202L; /* R2 */
|
||||
*(--stk) = (uint32_t)0x01010101L; /* R1 */
|
||||
*(--stk) = (uint32_t)arg; /* R0 : argument */
|
||||
|
||||
return stk;
|
||||
}
|
||||
|
||||
153
csky/csi_kernel/rhino/arch/csky/e804d/port_s.S
Normal file
153
csky/csi_kernel/rhino/arch/csky/e804d/port_s.S
Normal file
@@ -0,0 +1,153 @@
|
||||
/*
|
||||
* Copyright (C) 2016 YunOS Project. All rights reserved.
|
||||
*
|
||||
* 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 <k_config.h>
|
||||
|
||||
#define VIC_TSPDR 0XE000EC08
|
||||
|
||||
.extern g_active_task
|
||||
.extern g_preferred_ready_task
|
||||
.extern krhino_task_sched_stats_get
|
||||
.extern krhino_stack_ovf_check
|
||||
/******************************************************************************
|
||||
* EXPORT FUNCTIONS
|
||||
******************************************************************************/
|
||||
|
||||
.global cpu_intrpt_save
|
||||
.global cpu_intrpt_restore
|
||||
.global cpu_task_switch
|
||||
.global cpu_intrpt_switch
|
||||
.global cpu_first_task_start
|
||||
.global tspend_handler
|
||||
|
||||
/******************************************************************************
|
||||
* EQUATES
|
||||
******************************************************************************/
|
||||
|
||||
/******************************************************************************
|
||||
* CODE GENERATION DIRECTIVES
|
||||
******************************************************************************/
|
||||
|
||||
.text
|
||||
.align 2
|
||||
|
||||
/******************************************************************************
|
||||
* Functions:
|
||||
* size_t cpu_intrpt_save(void);
|
||||
* void cpu_intrpt_restore(size_t psr);
|
||||
******************************************************************************/
|
||||
|
||||
.type cpu_intrpt_save, %function
|
||||
cpu_intrpt_save:
|
||||
mfcr r0, psr
|
||||
psrclr ie
|
||||
rts
|
||||
|
||||
.type cpu_intrpt_restore, %function
|
||||
cpu_intrpt_restore:
|
||||
mtcr r0, psr
|
||||
rts
|
||||
|
||||
/******************************************************************************
|
||||
* Functions:
|
||||
* void cpu_intrpt_switch(void);
|
||||
* void cpu_task_switch(void);
|
||||
******************************************************************************/
|
||||
|
||||
.type cpu_task_switch, %function
|
||||
cpu_task_switch:
|
||||
lrw r0, VIC_TSPDR
|
||||
bgeni r1, 0
|
||||
stw r1, (r0)
|
||||
rts
|
||||
|
||||
.type cpu_intrpt_switch, %function
|
||||
cpu_intrpt_switch:
|
||||
lrw r0, VIC_TSPDR
|
||||
bgeni r1, 0
|
||||
stw r1, (r0)
|
||||
rts
|
||||
|
||||
/******************************************************************************
|
||||
* Functions:
|
||||
* void cpu_first_task_start(void);
|
||||
******************************************************************************/
|
||||
|
||||
.type cpu_first_task_start, %function
|
||||
cpu_first_task_start:
|
||||
psrclr ie
|
||||
jbr __tspend_handler_nosave
|
||||
|
||||
/******************************************************************************
|
||||
* Functions:
|
||||
* void __task_switch(void);
|
||||
******************************************************************************/
|
||||
|
||||
.type tspend_handler, %function
|
||||
tspend_handler:
|
||||
subi sp, 132
|
||||
stm r0-r13, (sp)
|
||||
stw r15, (sp, 56)
|
||||
addi r0, sp, 60
|
||||
stm r16-r31, (r0)
|
||||
mfcr r1, epsr
|
||||
stw r1, (r0, 64)
|
||||
mfcr r1, epc
|
||||
stw r1, (r0, 68)
|
||||
|
||||
lrw r2, g_active_task
|
||||
ldw r2, (r2)
|
||||
stw sp, (r2)
|
||||
|
||||
#if (RHINO_CONFIG_TASK_STACK_OVF_CHECK > 0)
|
||||
jbsr krhino_stack_ovf_check
|
||||
#endif
|
||||
|
||||
#if (RHINO_CONFIG_TASK_SCHED_STATS > 0)
|
||||
jbsr krhino_task_sched_stats_get
|
||||
#endif
|
||||
|
||||
__tspend_handler_nosave:
|
||||
lrw r4, g_active_task
|
||||
lrw r5, g_preferred_ready_task
|
||||
ldw r6, (r5)
|
||||
stw r6, (r4)
|
||||
|
||||
#ifdef CONFIG_STACK_GUARD
|
||||
jbsr csky_set_stackbound
|
||||
#endif
|
||||
|
||||
ldw sp, (r6)
|
||||
|
||||
#ifdef CONFIG_STACK_GUARD
|
||||
mfcr r3, cr<0, 4>
|
||||
bseti r3, 0
|
||||
bseti r3, 1
|
||||
mtcr r3, cr<0, 4>
|
||||
#endif
|
||||
|
||||
ldw r0, (sp, 128)
|
||||
mtcr r0, epc
|
||||
ldw r0, (sp, 124)
|
||||
mtcr r0, epsr
|
||||
|
||||
ldm r0-r13, (sp)
|
||||
ldw r15, (sp, 56)
|
||||
addi sp, 60
|
||||
ldm r16-r31, (sp)
|
||||
addi sp, 72
|
||||
|
||||
rte
|
||||
82
csky/csi_kernel/rhino/arch/csky/e804df/port_c.c
Normal file
82
csky/csi_kernel/rhino/arch/csky/e804df/port_c.c
Normal file
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* Copyright (C) 2016 YunOS Project. All rights reserved.
|
||||
*
|
||||
* 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 <k_api.h>
|
||||
#include <core_804.h>
|
||||
|
||||
void *cpu_task_stack_init(cpu_stack_t *stack_base, size_t stack_size,
|
||||
void *arg, task_entry_t entry)
|
||||
{
|
||||
cpu_stack_t *stk;
|
||||
uint32_t temp = (uint32_t)(stack_base + stack_size);
|
||||
|
||||
temp &= 0xFFFFFFFCUL;
|
||||
|
||||
stk = (cpu_stack_t *)temp;
|
||||
|
||||
*(--stk) = (uint32_t)entry; /* Entry Point */
|
||||
*(--stk) = (uint32_t)0x80000340L; /* PSR */
|
||||
*(--stk) = (uint32_t)0x12345678L; /* VR15 */
|
||||
*(--stk) = (uint32_t)0x12345678L; /* VR14 */
|
||||
*(--stk) = (uint32_t)0x12345678L; /* VR13 */
|
||||
*(--stk) = (uint32_t)0x12345678L; /* VR12 */
|
||||
*(--stk) = (uint32_t)0x12345678L; /* VR11 */
|
||||
*(--stk) = (uint32_t)0x12345678L; /* VR10 */
|
||||
*(--stk) = (uint32_t)0x12345678L; /* VR9 */
|
||||
*(--stk) = (uint32_t)0x12345678L; /* VR8 */
|
||||
*(--stk) = (uint32_t)0x12345678L; /* VR7 */
|
||||
*(--stk) = (uint32_t)0x12345678L; /* VR6 */
|
||||
*(--stk) = (uint32_t)0x12345678L; /* VR5 */
|
||||
*(--stk) = (uint32_t)0x12345678L; /* VR4 */
|
||||
*(--stk) = (uint32_t)0x12345678L; /* VR3 */
|
||||
*(--stk) = (uint32_t)0x12345678L; /* VR2 */
|
||||
*(--stk) = (uint32_t)0x12345678L; /* VR1 */
|
||||
*(--stk) = (uint32_t)0x12345678L; /* VR0 */
|
||||
*(--stk) = (uint32_t)0x31313131L; /* R31 */
|
||||
*(--stk) = (uint32_t)0x30303030L; /* R30 */
|
||||
*(--stk) = (uint32_t)0x29292929L; /* R29 */
|
||||
*(--stk) = (uint32_t)0x28282828L; /* R28 */
|
||||
*(--stk) = (uint32_t)0x27272727L; /* R27 */
|
||||
*(--stk) = (uint32_t)0x26262626L; /* R26 */
|
||||
*(--stk) = (uint32_t)0x25252525L; /* R25 */
|
||||
*(--stk) = (uint32_t)0x24242424L; /* R24 */
|
||||
*(--stk) = (uint32_t)0x23232323L; /* R23 */
|
||||
*(--stk) = (uint32_t)0x22222222L; /* R22 */
|
||||
*(--stk) = (uint32_t)0x21212121L; /* R21 */
|
||||
*(--stk) = (uint32_t)0x20202020L; /* R20 */
|
||||
*(--stk) = (uint32_t)0x19191919L; /* R19 */
|
||||
*(--stk) = (uint32_t)0x18181818L; /* R18 */
|
||||
*(--stk) = (uint32_t)0x17171717L; /* R17 */
|
||||
*(--stk) = (uint32_t)0x16161616L; /* R16 */
|
||||
*(--stk) = (uint32_t)krhino_task_deathbed; /* R15 (LR) */
|
||||
*(--stk) = (uint32_t)0x13131313L; /* R13 */
|
||||
*(--stk) = (uint32_t)0x12121212L; /* R12 */
|
||||
*(--stk) = (uint32_t)0x11111111L; /* R11 */
|
||||
*(--stk) = (uint32_t)0x10101010L; /* R10 */
|
||||
*(--stk) = (uint32_t)0x09090909L; /* R9 */
|
||||
*(--stk) = (uint32_t)0x00000000L; /* R8 */
|
||||
*(--stk) = (uint32_t)0x07070707L; /* R7 */
|
||||
*(--stk) = (uint32_t)0x06060606L; /* R6 */
|
||||
*(--stk) = (uint32_t)0x05050505L; /* R5 */
|
||||
*(--stk) = (uint32_t)0x04040404L; /* R4 */
|
||||
*(--stk) = (uint32_t)0x03030303L; /* R3 */
|
||||
*(--stk) = (uint32_t)0x02020202L; /* R2 */
|
||||
*(--stk) = (uint32_t)0x01010101L; /* R1 */
|
||||
*(--stk) = (uint32_t)arg; /* R0 : Argument */
|
||||
|
||||
return stk;
|
||||
}
|
||||
|
||||
157
csky/csi_kernel/rhino/arch/csky/e804df/port_s.S
Normal file
157
csky/csi_kernel/rhino/arch/csky/e804df/port_s.S
Normal file
@@ -0,0 +1,157 @@
|
||||
/*
|
||||
* Copyright (C) 2016 YunOS Project. All rights reserved.
|
||||
*
|
||||
* 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 <k_config.h>
|
||||
|
||||
#define VIC_TSPDR 0XE000EC08
|
||||
|
||||
.extern g_active_task
|
||||
.extern g_preferred_ready_task
|
||||
.extern krhino_task_sched_stats_get
|
||||
.extern krhino_stack_ovf_check
|
||||
/******************************************************************************
|
||||
* EXPORT FUNCTIONS
|
||||
******************************************************************************/
|
||||
|
||||
.global cpu_intrpt_save
|
||||
.global cpu_intrpt_restore
|
||||
.global cpu_task_switch
|
||||
.global cpu_intrpt_switch
|
||||
.global cpu_first_task_start
|
||||
.global tspend_handler
|
||||
|
||||
/******************************************************************************
|
||||
* EQUATES
|
||||
******************************************************************************/
|
||||
|
||||
/******************************************************************************
|
||||
* CODE GENERATION DIRECTIVES
|
||||
******************************************************************************/
|
||||
|
||||
.text
|
||||
.align 2
|
||||
|
||||
/******************************************************************************
|
||||
* Functions:
|
||||
* size_t cpu_intrpt_save(void);
|
||||
* void cpu_intrpt_restore(size_t psr);
|
||||
******************************************************************************/
|
||||
|
||||
.type cpu_intrpt_save, %function
|
||||
cpu_intrpt_save:
|
||||
mfcr r0, psr
|
||||
psrclr ie
|
||||
rts
|
||||
|
||||
.type cpu_intrpt_restore, %function
|
||||
cpu_intrpt_restore:
|
||||
mtcr r0, psr
|
||||
rts
|
||||
|
||||
/******************************************************************************
|
||||
* Functions:
|
||||
* void cpu_intrpt_switch(void);
|
||||
* void cpu_task_switch(void);
|
||||
******************************************************************************/
|
||||
|
||||
.type cpu_task_switch, %function
|
||||
cpu_task_switch:
|
||||
lrw r0, VIC_TSPDR
|
||||
bgeni r1, 0
|
||||
stw r1, (r0)
|
||||
rts
|
||||
|
||||
.type cpu_intrpt_switch, %function
|
||||
cpu_intrpt_switch:
|
||||
lrw r0, VIC_TSPDR
|
||||
bgeni r1, 0
|
||||
stw r1, (r0)
|
||||
rts
|
||||
|
||||
/******************************************************************************
|
||||
* Functions:
|
||||
* void cpu_first_task_start(void);
|
||||
******************************************************************************/
|
||||
|
||||
.type cpu_first_task_start, %function
|
||||
cpu_first_task_start:
|
||||
psrclr ie
|
||||
jbr __tspend_handler_nosave
|
||||
|
||||
/******************************************************************************
|
||||
* Functions:
|
||||
* void __task_switch(void);
|
||||
******************************************************************************/
|
||||
|
||||
.type tspend_handler, %function
|
||||
tspend_handler:
|
||||
subi sp, 196
|
||||
stm r0-r13, (sp)
|
||||
stw r15, (sp, 56)
|
||||
addi r0, sp, 60
|
||||
stm r16-r31, (r0)
|
||||
addi r0, 64
|
||||
fstms vr0-vr15, (r0)
|
||||
mfcr r1, epsr
|
||||
stw r1, (r0, 64)
|
||||
mfcr r1, epc
|
||||
stw r1, (r0, 68)
|
||||
|
||||
lrw r2, g_active_task
|
||||
ldw r2, (r2)
|
||||
stw sp, (r2)
|
||||
|
||||
#if (RHINO_CONFIG_TASK_STACK_OVF_CHECK > 0)
|
||||
jbsr krhino_stack_ovf_check
|
||||
#endif
|
||||
|
||||
#if (RHINO_CONFIG_TASK_SCHED_STATS > 0)
|
||||
jbsr krhino_task_sched_stats_get
|
||||
#endif
|
||||
|
||||
__tspend_handler_nosave:
|
||||
lrw r4, g_active_task
|
||||
lrw r5, g_preferred_ready_task
|
||||
ldw r6, (r5)
|
||||
stw r6, (r4)
|
||||
|
||||
#ifdef CONFIG_STACK_GUARD
|
||||
jbsr csky_set_stackbound
|
||||
#endif
|
||||
|
||||
ldw sp, (r6)
|
||||
|
||||
#ifdef CONFIG_STACK_GUARD
|
||||
mfcr r3, cr<0, 4>
|
||||
bseti r3, 0
|
||||
bseti r3, 1
|
||||
mtcr r3, cr<0, 4>
|
||||
#endif
|
||||
|
||||
ldw r0, (sp, 192)
|
||||
mtcr r0, epc
|
||||
ldw r0, (sp, 188)
|
||||
mtcr r0, epsr
|
||||
|
||||
ldm r0-r13, (sp)
|
||||
ldw r15, (sp, 56)
|
||||
addi sp, 60
|
||||
ldm r16-r31, (sp)
|
||||
addi sp, 64
|
||||
fldms vr0-vr15, (sp)
|
||||
addi sp, 72
|
||||
|
||||
rte
|
||||
166
csky/csi_kernel/rhino/arch/include/k_config.h
Normal file
166
csky/csi_kernel/rhino/arch/include/k_config.h
Normal file
@@ -0,0 +1,166 @@
|
||||
/*
|
||||
* Copyright (C) 2016 YunOS Project. All rights reserved.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef CONFIG_H
|
||||
#define CONFIG_H
|
||||
|
||||
#include <csi_config.h>
|
||||
|
||||
#if defined (__CSKY_DSP__) || defined(__CSKY_DSPV2__) || defined(__CSKY_VDSPV2__) || defined (__CSKY_HARD_FLOAT__) || defined(__C807__)
|
||||
#define CSK_CPU_STACK_EXTRAL 68
|
||||
#elif defined (__I805__)
|
||||
#define CSK_CPU_STACK_EXTRAL 260
|
||||
#else
|
||||
#define CSK_CPU_STACK_EXTRAL 0
|
||||
#endif
|
||||
|
||||
#define RHINO_CONFIG_STD_MALLOC 1
|
||||
#define K_MM_STATISTIC 1
|
||||
|
||||
/* chip level conf */
|
||||
#define RHINO_CONFIG_LITTLE_ENDIAN 1
|
||||
#define RHINO_CONFIG_CPU_STACK_DOWN 1
|
||||
|
||||
/* kernel feature conf */
|
||||
#define RHINO_CONFIG_SEM 1
|
||||
#define RHINO_CONFIG_QUEUE 1
|
||||
#define RHINO_CONFIG_TASK_SEM 1
|
||||
#define RHINO_CONFIG_EVENT_FLAG 1
|
||||
#define RHINO_CONFIG_TIMER 1
|
||||
#define RHINO_CONFIG_BUF_QUEUE 1
|
||||
#define RHINO_CONFIG_MM_BLK 1
|
||||
#define RHINO_CONFIG_MM_TLF_BLK_SIZE 4096
|
||||
|
||||
#ifdef CONFIG_DEBUG_MM
|
||||
#define RHINO_CONFIG_MM_DEBUG 1
|
||||
#define RHINO_CONFIG_GCC_RETADDR 1
|
||||
#else
|
||||
#define RHINO_CONFIG_MM_DEBUG 0
|
||||
#define RHINO_CONFIG_GCC_RETADDR 0
|
||||
#endif
|
||||
|
||||
#define RHINO_CONFIG_KOBJ_SET 1
|
||||
#define RHINO_CONFIG_RINGBUF_VENDOR 0
|
||||
|
||||
/* kernel dynamic tick conf */
|
||||
#ifdef CONFIG_KERNEL_PWR_MGMT
|
||||
#define RHINO_CONFIG_CPU_PWR_MGMT 1
|
||||
#else
|
||||
#define RHINO_CONFIG_CPU_PWR_MGMT 0
|
||||
#endif
|
||||
|
||||
/*
|
||||
#define RHINO_CONFIG_TICKS_PER_SECOND 100
|
||||
#define RHINO_CONFIG_TICK_HEAD_ARRAY 1
|
||||
#define RHINO_CONFIG_SCHED_RR 0
|
||||
#define RHINO_CONFIG_TIMER_RATE 1
|
||||
#define RHINO_CONFIG_TIMER 1
|
||||
*/
|
||||
|
||||
/* kernel task conf */
|
||||
#define RHINO_CONFIG_TASK_SUSPEND 1
|
||||
#define RHINO_CONFIG_TASK_INFO 0
|
||||
#define RHINO_CONFIG_TASK_DEL 1
|
||||
#define RHINO_CONFIG_TASK_WAIT_ABORT 0
|
||||
#define RHINO_CONFIG_TASK_STACK_OVF_CHECK 1
|
||||
|
||||
#define RHINO_CONFIG_SCHED_RR 1
|
||||
|
||||
#define RHINO_CONFIG_TIME_SLICE_DEFAULT 5
|
||||
#define RHINO_CONFIG_PRI_MAX 62
|
||||
#define RHINO_CONFIG_USER_PRI_MAX (RHINO_CONFIG_PRI_MAX - 2)
|
||||
|
||||
#define RHINO_CONFIG_MM_REGION_MUTEX 0
|
||||
|
||||
/* kernel workqueue conf */
|
||||
#ifdef CONFIG_KERNEL_WORKQUEUE
|
||||
#define RHINO_CONFIG_WORKQUEUE 1
|
||||
#else
|
||||
#define RHINO_CONFIG_WORKQUEUE 0
|
||||
#endif
|
||||
|
||||
/* kernel timer&tick conf */
|
||||
#define RHINO_CONFIG_HW_COUNT 0
|
||||
#define RHINO_CONFIG_TICK_TASK 1
|
||||
#if (RHINO_CONFIG_TICK_TASK > 0)
|
||||
#define RHINO_CONFIG_TICK_TASK_STACK_SIZE (50 + CSK_CPU_STACK_EXTRAL)
|
||||
#define RHINO_CONFIG_TICK_TASK_PRI 1
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_SYSTICK_HZ
|
||||
#define RHINO_CONFIG_TICKS_PER_SECOND CONFIG_SYSTICK_HZ
|
||||
#else
|
||||
#define RHINO_CONFIG_TICKS_PER_SECOND 100
|
||||
#endif
|
||||
|
||||
/* must be 2^n size!, such as 1, 2, 4, 8, 16,32, etc....... */
|
||||
#define RHINO_CONFIG_TICK_HEAD_ARRAY 1
|
||||
|
||||
#ifdef CONFIG_TIMER_TASK_STACK_SIZE
|
||||
#define RHINO_CONFIG_TIMER_TASK_STACK_SIZE (CONFIG_TIMER_TASK_STACK_SIZE + CSK_CPU_STACK_EXTRAL)
|
||||
#else
|
||||
#define RHINO_CONFIG_TIMER_TASK_STACK_SIZE (200 + CSK_CPU_STACK_EXTRAL)
|
||||
#endif
|
||||
#define RHINO_CONFIG_TIMER_RATE 1
|
||||
#define RHINO_CONFIG_TIMER_TASK_PRI 5
|
||||
|
||||
/* kernel intrpt conf */
|
||||
#define RHINO_CONFIG_INTRPT_STACK_REMAIN_GET 1
|
||||
#define RHINO_CONFIG_INTRPT_STACK_OVF_CHECK 0
|
||||
#define RHINO_CONFIG_INTRPT_MAX_NESTED_LEVEL 188u
|
||||
#define RHINO_CONFIG_INTRPT_GUARD 0
|
||||
#define RHINO_CONFIG_STACK_OVF_CHECK_HW 0
|
||||
|
||||
#define RHINO_CONFIG_KOBJ_DYN_ALLOC 1
|
||||
#if (RHINO_CONFIG_KOBJ_DYN_ALLOC > 0)
|
||||
#define RHINO_CONFIG_K_DYN_QUEUE_MSG 30
|
||||
#define RHINO_CONFIG_K_DYN_TASK_STACK (64 + CSK_CPU_STACK_EXTRAL)
|
||||
#define RHINO_CONFIG_K_DYN_MEM_TASK_PRI RHINO_CONFIG_USER_PRI_MAX
|
||||
#endif
|
||||
|
||||
/* kernel idle conf */
|
||||
#ifdef CONFIG_IDLE_TASK_STACK_SIZE
|
||||
#define RHINO_CONFIG_IDLE_TASK_STACK_SIZE CONFIG_IDLE_TASK_STACK_SIZE
|
||||
#else
|
||||
#define RHINO_CONFIG_IDLE_TASK_STACK_SIZE (256 + CSK_CPU_STACK_EXTRAL)
|
||||
#endif
|
||||
/* kernel hook conf */
|
||||
#define RHINO_CONFIG_USER_HOOK 1
|
||||
//#define RHINO_CONFIG_ISR_TASK 1
|
||||
|
||||
/* kernel stats conf */
|
||||
#define RHINO_CONFIG_SYSTEM_STATS 1
|
||||
#define RHINO_CONFIG_DISABLE_SCHED_STATS 0
|
||||
#define RHINO_CONFIG_DISABLE_INTRPT_STATS 0
|
||||
#define RHINO_CONFIG_CPU_USAGE_STATS 0
|
||||
#define RHINO_CONFIG_CPU_USAGE_TASK_PRI (RHINO_CONFIG_PRI_MAX - 2)
|
||||
#define RHINO_CONFIG_TASK_SCHED_STATS 0
|
||||
#define RHINO_CONFIG_CPU_USAGE_TASK_STACK (50 + CSK_CPU_STACK_EXTRAL)
|
||||
|
||||
#ifdef RHINO_CONFIG_ISR_TASK
|
||||
#ifndef RHINO_CONFIG_ISR_BUFF_SIZE
|
||||
#define RHINO_CONFIG_ISR_BUFF_SIZE (16)
|
||||
#endif
|
||||
#ifndef RHINO_CONFIG_ISR_TASK_PRI
|
||||
#define RHINO_CONFIG_ISR_TASK_PRI (1)
|
||||
#endif
|
||||
#ifndef RHINO_CONFIG_ISR_TASK_STACK_SIZE
|
||||
#define RHINO_CONFIG_ISR_TASK_STACK_SIZE (1024)
|
||||
#endif
|
||||
|
||||
#endif
|
||||
#endif /* CONFIG_H */
|
||||
|
||||
51
csky/csi_kernel/rhino/arch/include/k_types.h
Normal file
51
csky/csi_kernel/rhino/arch/include/k_types.h
Normal file
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright (C) 2016 YunOS Project. All rights reserved.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef TYPES_H
|
||||
#define TYPES_H
|
||||
|
||||
#define RHINO_NO_WAIT 0u
|
||||
//#define RHINO_WAIT_FOREVER 0xffffffffu /* 32 bit value, if tick type is 64 bit, you need change it to 64 bit */
|
||||
#define RHINO_TASK_STACK_OVF_MAGIC 0xdeadbeafu /* 32 bit or 64 bit stack overflow magic value */
|
||||
#define RHINO_INTRPT_STACK_OVF_MAGIC 0xdeaddeadu /* 32 bit or 64 bit stack overflow magic value */
|
||||
#define RHINO_MM_FRAG_ALLOCATED 0xabcddcabu /* 32 bit value, if 64 bit system, you need change it to 64 bit */
|
||||
#define RHINO_MM_FRAG_FREE 0xfefdecdbu /* 32 bit value, if 64 bit system, you need change it to 64 bit */
|
||||
#define RHINO_INLINE static __inline /* inline keyword, it may change under different compilers */
|
||||
|
||||
#define RHINO_MM_CORRUPT_DYE 0xFEFEFEFE
|
||||
#define RHINO_MM_FREE_DYE 0xABABABAB
|
||||
|
||||
typedef char name_t;
|
||||
typedef uint32_t sem_count_t;
|
||||
typedef uint32_t cpu_stack_t;
|
||||
typedef uint32_t cpu_cpsr_t;
|
||||
|
||||
/* you may change here depend on your hardware timer */
|
||||
typedef uint32_t hr_timer_t; /* 32 bit or 64 bit unsigned value */
|
||||
typedef uint32_t lr_timer_t; /* 32 bit or 64 bit unsigned value */
|
||||
|
||||
//typedef uint64_t tick_t; /* 32 bit or 64 bit unsigned value */
|
||||
//typedef uint64_t idle_count_t; /* 64 bit unsigned value */
|
||||
//typedef uint64_t sys_time_t; /* 64 bit unsigned value */
|
||||
typedef uint32_t mutex_nested_t; /* 8 bit or 16bit or 32bit unsigned value */
|
||||
typedef uint8_t suspend_nested_t; /* 8 bit normally */
|
||||
|
||||
typedef uint64_t ctx_switch_t; /* 32 bit or 64 bit unsigned value */
|
||||
|
||||
//typedef int32_t ssize_t;
|
||||
|
||||
#endif /* TYPES_H */
|
||||
|
||||
43
csky/csi_kernel/rhino/arch/include/port.h
Normal file
43
csky/csi_kernel/rhino/arch/include/port.h
Normal file
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright (C) 2016 YunOS Project. All rights reserved.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef PORT_H
|
||||
#define PORT_H
|
||||
|
||||
#include <k_types.h>
|
||||
#include <k_task.h>
|
||||
|
||||
size_t cpu_intrpt_save(void);
|
||||
void cpu_intrpt_restore(size_t psr);
|
||||
void cpu_intrpt_switch(void);
|
||||
void cpu_task_switch(void);
|
||||
void cpu_first_task_start(void);
|
||||
|
||||
void *cpu_task_stack_init(cpu_stack_t *base, size_t size,
|
||||
void *arg, task_entry_t entry);
|
||||
|
||||
RHINO_INLINE uint8_t cpu_cur_get(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define CPSR_ALLOC() size_t psr
|
||||
|
||||
#define RHINO_CPU_INTRPT_DISABLE() { psr = cpu_intrpt_save(); }
|
||||
#define RHINO_CPU_INTRPT_ENABLE() { cpu_intrpt_restore(psr); }
|
||||
|
||||
#endif /* PORT_H */
|
||||
|
||||
45
csky/csi_kernel/rhino/arch/riscv/cpu_impl.c
Normal file
45
csky/csi_kernel/rhino/arch/riscv/cpu_impl.c
Normal file
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright (C) 2016 YunOS Project. All rights reserved.
|
||||
*
|
||||
* 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 <k_api.h>
|
||||
#include <k_config.h>
|
||||
|
||||
#if (RHINO_CONFIG_STACK_OVF_CHECK_HW != 0)
|
||||
void cpu_intrpt_stack_protect(void)
|
||||
{
|
||||
}
|
||||
|
||||
void task_stack_crash_warning(void)
|
||||
{
|
||||
printf("****The task stack base has been broken !!!****\n");
|
||||
}
|
||||
|
||||
void cpu_task_stack_protect(cpu_stack_t *base, size_t size)
|
||||
{
|
||||
uint32_t base_addr = (uint32_t)base;
|
||||
|
||||
int num_return = wp_register(base_addr, AWATCH, task_stack_crash_warning);
|
||||
if (num_return == 1) {
|
||||
wp_enable(1);
|
||||
} else if (num_return == 2 || num_return == -1) {
|
||||
wp_unregister(1);
|
||||
int number_tmp = wp_register(base_addr, AWATCH, task_stack_crash_warning);
|
||||
if (number_tmp == 1){
|
||||
wp_enable(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
79
csky/csi_kernel/rhino/arch/riscv/csky_sched.c
Normal file
79
csky/csi_kernel/rhino/arch/riscv/csky_sched.c
Normal file
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* Copyright (C) 2016 YunOS Project. All rights reserved.
|
||||
*
|
||||
* 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 <k_api.h>
|
||||
|
||||
#undef PSR_SP
|
||||
#define PSR_SP (1UL << 29)
|
||||
static ktask_t *tee_caller_task = NULL;
|
||||
|
||||
static inline uint32_t getcurrentpsr(void)
|
||||
{
|
||||
uint32_t flags = 0;
|
||||
|
||||
__asm__ __volatile__(
|
||||
"ebreak\n" /* TODO */
|
||||
);
|
||||
|
||||
return flags;
|
||||
}
|
||||
|
||||
static inline void clear_psr_sp(void)
|
||||
{
|
||||
__asm__ __volatile__ (
|
||||
"ebreak\n" /* TODO */
|
||||
);
|
||||
}
|
||||
|
||||
static inline void set_psr_sp(void)
|
||||
{
|
||||
__asm__ __volatile__ (
|
||||
"ebreak\n" /* TODO */
|
||||
);
|
||||
}
|
||||
|
||||
void csky_get_tee_caller_task(void)
|
||||
{
|
||||
uint32_t temp_psr;
|
||||
|
||||
temp_psr = getcurrentpsr();
|
||||
if (temp_psr & PSR_SP) {
|
||||
tee_caller_task = (tee_caller_task == NULL) ? g_active_task[cpu_cur_get()] : tee_caller_task;
|
||||
}
|
||||
}
|
||||
|
||||
void csky_deal_tee_caller_task(void)
|
||||
{
|
||||
uint32_t temp_psr;
|
||||
|
||||
temp_psr = getcurrentpsr();
|
||||
if (temp_psr & PSR_SP) {
|
||||
if (tee_caller_task != NULL) {
|
||||
if (tee_caller_task == g_active_task[cpu_cur_get()]) {
|
||||
tee_caller_task = NULL;
|
||||
} else {
|
||||
clear_psr_sp();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (tee_caller_task != NULL) {
|
||||
if (tee_caller_task == g_active_task[cpu_cur_get()]) {
|
||||
tee_caller_task = NULL;
|
||||
set_psr_sp();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
64
csky/csi_kernel/rhino/arch/riscv/e906/port_c.c
Normal file
64
csky/csi_kernel/rhino/arch/riscv/e906/port_c.c
Normal file
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright (C) 2016 YunOS Project. All rights reserved.
|
||||
*
|
||||
* 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 <k_api.h>
|
||||
|
||||
void *cpu_task_stack_init(cpu_stack_t *stack_base, size_t stack_size,
|
||||
void *arg, task_entry_t entry)
|
||||
{
|
||||
cpu_stack_t *stk;
|
||||
register int *gp asm("x3");
|
||||
uint32_t temp = (uint32_t)(stack_base + stack_size);
|
||||
|
||||
temp &= 0xFFFFFFF8UL;
|
||||
|
||||
stk = (cpu_stack_t *)temp;
|
||||
|
||||
*(--stk) = (uint32_t)entry; /* PC */
|
||||
*(--stk) = (uint32_t)0x31313131L; /* X31 */
|
||||
*(--stk) = (uint32_t)0x30303030L; /* X30 */
|
||||
*(--stk) = (uint32_t)0x29292929L; /* X29 */
|
||||
*(--stk) = (uint32_t)0x28282828L; /* X28 */
|
||||
*(--stk) = (uint32_t)0x27272727L; /* X27 */
|
||||
*(--stk) = (uint32_t)0x26262626L; /* X26 */
|
||||
*(--stk) = (uint32_t)0x25252525L; /* X25 */
|
||||
*(--stk) = (uint32_t)0x24242424L; /* X24 */
|
||||
*(--stk) = (uint32_t)0x23232323L; /* X23 */
|
||||
*(--stk) = (uint32_t)0x22222222L; /* X22 */
|
||||
*(--stk) = (uint32_t)0x21212121L; /* X21 */
|
||||
*(--stk) = (uint32_t)0x20202020L; /* X20 */
|
||||
*(--stk) = (uint32_t)0x19191919L; /* X19 */
|
||||
*(--stk) = (uint32_t)0x18181818L; /* X18 */
|
||||
*(--stk) = (uint32_t)0x17171717L; /* X17 */
|
||||
*(--stk) = (uint32_t)0x16161616L; /* X16 */
|
||||
*(--stk) = (uint32_t)0x15151515L; /* X15 */
|
||||
*(--stk) = (uint32_t)0x14141414L; /* X14 */
|
||||
*(--stk) = (uint32_t)0x13131313L; /* X13 */
|
||||
*(--stk) = (uint32_t)0x12121212L; /* X12 */
|
||||
*(--stk) = (uint32_t)0x11111111L; /* X11 */
|
||||
*(--stk) = (uint32_t)arg; /* X10 */
|
||||
*(--stk) = (uint32_t)0x09090909L; /* X9 */
|
||||
*(--stk) = (uint32_t)0x08080808L; /* X8 */
|
||||
*(--stk) = (uint32_t)0x07070707L; /* X7 */
|
||||
*(--stk) = (uint32_t)0x06060606L; /* X6 */
|
||||
*(--stk) = (uint32_t)0x05050505L; /* X5 */
|
||||
*(--stk) = (uint32_t)0x04040404L; /* X4 */
|
||||
*(--stk) = (uint32_t)gp; /* X3 */
|
||||
*(--stk) = (uint32_t)krhino_task_deathbed; /* X1 */
|
||||
|
||||
return stk;
|
||||
}
|
||||
|
||||
172
csky/csi_kernel/rhino/arch/riscv/e906/port_s.S
Normal file
172
csky/csi_kernel/rhino/arch/riscv/e906/port_s.S
Normal file
@@ -0,0 +1,172 @@
|
||||
/*
|
||||
* Copyright (C) 2016 YunOS Project. All rights reserved.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/* Enable interrupts when returning from the handler */
|
||||
#define MSTATUS_PRV1 0x1880
|
||||
|
||||
/******************************************************************************
|
||||
* Functions:
|
||||
* size_t cpu_intrpt_save(void);
|
||||
* void cpu_intrpt_restore(size_t psr);
|
||||
******************************************************************************/
|
||||
|
||||
.global cpu_intrpt_save
|
||||
.type cpu_intrpt_save, %function
|
||||
cpu_intrpt_save:
|
||||
csrr a0, mstatus
|
||||
csrc mstatus, 8
|
||||
ret
|
||||
|
||||
.global cpu_intrpt_restore
|
||||
.type cpu_intrpt_restore, %function
|
||||
cpu_intrpt_restore:
|
||||
csrw mstatus, a0
|
||||
ret
|
||||
|
||||
/******************************************************************************
|
||||
* Functions:
|
||||
* void cpu_intrpt_switch(void);
|
||||
* void cpu_task_switch(void);
|
||||
******************************************************************************/
|
||||
|
||||
.global cpu_task_switch
|
||||
.type cpu_task_switch, %function
|
||||
cpu_task_switch:
|
||||
li t0, 0xE080100C
|
||||
lb t1, (t0)
|
||||
li t2, 0x01
|
||||
or t1, t1, t2
|
||||
sb t1, (t0)
|
||||
|
||||
ret
|
||||
|
||||
.global cpu_intrpt_switch
|
||||
.type cpu_intrpt_switch, %function
|
||||
cpu_intrpt_switch:
|
||||
li t0, 0xE080100C
|
||||
lb t1, (t0)
|
||||
li t2, 0x01
|
||||
or t1, t1, t2
|
||||
sb t1, (t0)
|
||||
|
||||
ret
|
||||
|
||||
/******************************************************************************
|
||||
* Functions:
|
||||
* void cpu_first_task_start(void);
|
||||
******************************************************************************/
|
||||
.global cpu_first_task_start
|
||||
.type cpu_first_task_start, %function
|
||||
cpu_first_task_start:
|
||||
j __task_switch_nosave
|
||||
|
||||
/******************************************************************************
|
||||
* Functions:
|
||||
* void tspend_handler(void);
|
||||
******************************************************************************/
|
||||
|
||||
.global tspend_handler
|
||||
.type tspend_handler, %function
|
||||
tspend_handler:
|
||||
csrrw sp, mscratch, sp
|
||||
addi sp, sp, -124
|
||||
|
||||
sw x1, 0(sp)
|
||||
sw x3, 4(sp)
|
||||
sw x4, 8(sp)
|
||||
sw x5, 12(sp)
|
||||
sw x6, 16(sp)
|
||||
sw x7, 20(sp)
|
||||
sw x8, 24(sp)
|
||||
sw x9, 28(sp)
|
||||
sw x10, 32(sp)
|
||||
sw x11, 36(sp)
|
||||
sw x12, 40(sp)
|
||||
sw x13, 44(sp)
|
||||
sw x14, 48(sp)
|
||||
sw x15, 52(sp)
|
||||
sw x16, 56(sp)
|
||||
sw x17, 60(sp)
|
||||
sw x18, 64(sp)
|
||||
sw x19, 68(sp)
|
||||
sw x20, 72(sp)
|
||||
sw x21, 76(sp)
|
||||
sw x22, 80(sp)
|
||||
sw x23, 84(sp)
|
||||
sw x24, 88(sp)
|
||||
sw x25, 92(sp)
|
||||
sw x26, 96(sp)
|
||||
sw x27, 100(sp)
|
||||
sw x28, 104(sp)
|
||||
sw x29, 108(sp)
|
||||
sw x30, 112(sp)
|
||||
sw x31, 116(sp)
|
||||
csrr t0, mepc
|
||||
sw t0, 120(sp)
|
||||
|
||||
la a1, g_active_task
|
||||
lw a1, (a1)
|
||||
sw sp, (a1)
|
||||
|
||||
__task_switch_nosave:
|
||||
la a0, g_preferred_ready_task
|
||||
la a1, g_active_task
|
||||
lw a2, (a0)
|
||||
sw a2, (a1)
|
||||
|
||||
lw sp, (a2)
|
||||
|
||||
/* Run in machine mode */
|
||||
li t0, MSTATUS_PRV1
|
||||
csrs mstatus, t0
|
||||
|
||||
lw t0, 120(sp)
|
||||
csrw mepc, t0
|
||||
|
||||
lw x1, 0(sp)
|
||||
lw x3, 4(sp)
|
||||
lw x4, 8(sp)
|
||||
lw x5, 12(sp)
|
||||
lw x6, 16(sp)
|
||||
lw x7, 20(sp)
|
||||
lw x8, 24(sp)
|
||||
lw x9, 28(sp)
|
||||
lw x10, 32(sp)
|
||||
lw x11, 36(sp)
|
||||
lw x12, 40(sp)
|
||||
lw x13, 44(sp)
|
||||
lw x14, 48(sp)
|
||||
lw x15, 52(sp)
|
||||
lw x16, 56(sp)
|
||||
lw x17, 60(sp)
|
||||
lw x18, 64(sp)
|
||||
lw x19, 68(sp)
|
||||
lw x20, 72(sp)
|
||||
lw x21, 76(sp)
|
||||
lw x22, 80(sp)
|
||||
lw x23, 84(sp)
|
||||
lw x24, 88(sp)
|
||||
lw x25, 92(sp)
|
||||
lw x26, 96(sp)
|
||||
lw x27, 100(sp)
|
||||
lw x28, 104(sp)
|
||||
lw x29, 108(sp)
|
||||
lw x30, 112(sp)
|
||||
lw x31, 116(sp)
|
||||
|
||||
addi sp, sp, 124
|
||||
csrrw sp, mscratch, sp
|
||||
mret
|
||||
155
csky/csi_kernel/rhino/board/board_cpu_pwr.c
Normal file
155
csky/csi_kernel/rhino/board/board_cpu_pwr.c
Normal file
@@ -0,0 +1,155 @@
|
||||
#include "k_api.h"
|
||||
#include "cpu_pwr_config.h"
|
||||
|
||||
//#if RHINO_CONFIG_CPU_PWR_MGMT
|
||||
|
||||
#include "cpu_pwr_hal_lib.h"
|
||||
#include "pwr_debug.h"
|
||||
#include "soc.h"
|
||||
|
||||
#if RHINO_CONFIG_CPU_TICKLESS
|
||||
#include "cpu_tickless.h"
|
||||
#endif /*RHINO_CONFIG_CPU_TICKLESS*/
|
||||
|
||||
#ifdef CONFIG_TEE_CA
|
||||
#include "drv_tee.h"
|
||||
#endif
|
||||
|
||||
/* forward declarations */
|
||||
|
||||
extern cpu_pwr_t *p_cpu_pwr_root_node;
|
||||
|
||||
#if RHINO_CONFIG_CPU_TICKLESS
|
||||
extern one_shot_timer_t tim_one_shot; /* wakeup source for C1 */
|
||||
#endif /* RHINO_CONFIG_CPU_TICKLESS */
|
||||
|
||||
static cpu_pwr_t cpu_pwr_node_package_0;
|
||||
static cpu_pwr_t cpu_pwr_node_core_0;
|
||||
static kstat_t board_cpu_c_state_set
|
||||
(
|
||||
uint32_t cpuCState,
|
||||
int master
|
||||
)
|
||||
{
|
||||
switch (cpuCState) {
|
||||
case CPU_CSTATE_C0:
|
||||
|
||||
//printf("enter C0\n");
|
||||
if (master) {
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case CPU_CSTATE_C1:
|
||||
|
||||
/*
|
||||
* put CPU into C1 state
|
||||
* to put CPU into C1 state.
|
||||
*/
|
||||
//printf("enter C1\n");
|
||||
#ifdef CONFIG_CHIP_CH2201
|
||||
*(volatile unsigned int *)(0xe000e1c0) = 0xffffffff; // reload wakeup_IRQ
|
||||
//*(volatile unsigned int *)(0xe000e280) = 0xffffffff; // clear pend IRQ
|
||||
csi_vic_set_wakeup_irq(RTC_IRQn);
|
||||
csi_vic_set_wakeup_irq(UART2_IRQn);
|
||||
csi_vic_set_wakeup_irq(UART1_IRQn);
|
||||
csi_vic_set_wakeup_irq(UART0_IRQn);
|
||||
csi_vic_set_wakeup_irq(CORET_IRQn);
|
||||
csi_vic_set_wakeup_irq(GPIOA_IRQn);
|
||||
csi_vic_set_wakeup_irq(GPIOB_IRQn);
|
||||
csi_vic_set_wakeup_irq(TIMA0_IRQn);
|
||||
|
||||
#ifdef CONFIG_TEE_CA
|
||||
csi_tee_enter_lpm(0, 0, TEE_LPM_MODE_WAIT);
|
||||
#else
|
||||
__WFI();
|
||||
#endif
|
||||
#endif
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
PWR_DBG(DBG_ERR, "invalid C state: C%d\n", cpuCState);
|
||||
break;
|
||||
}
|
||||
|
||||
return RHINO_SUCCESS;
|
||||
}
|
||||
|
||||
kstat_t board_cpu_pwr_topo_create(void)
|
||||
{
|
||||
cpu_pwr_t *pCpuNode = NULL;
|
||||
cpu_pwr_t *pParentL1 = NULL; /* parent of level 1 */
|
||||
cpu_pwr_t *pParentL2 = NULL; /* parent of level 2 */
|
||||
kstat_t retVal = RHINO_SUCCESS;
|
||||
uint32_t cpuIndex = 0; /* 0 for UP */
|
||||
|
||||
if (p_cpu_pwr_root_node == NULL) {
|
||||
return RHINO_PWR_MGMT_ERR;
|
||||
}
|
||||
|
||||
pParentL1 = p_cpu_pwr_root_node;
|
||||
|
||||
pCpuNode = &cpu_pwr_node_package_0;
|
||||
retVal = cpu_pwr_node_init_static(CPU_PWR_TOPO_LEVEL_1, "package", 0, pCpuNode);
|
||||
|
||||
if (retVal != RHINO_SUCCESS) {
|
||||
return RHINO_PWR_MGMT_ERR;
|
||||
}
|
||||
|
||||
/* add this node as a child of p_cpu_pwr_root_node */
|
||||
|
||||
cpu_pwr_child_add(pParentL1, pCpuNode);
|
||||
pParentL2 = pCpuNode;
|
||||
|
||||
pCpuNode = &cpu_pwr_node_core_0;
|
||||
retVal = cpu_pwr_node_init_static(CPU_PWR_TOPO_LEVEL_2, "core", 0, pCpuNode);
|
||||
|
||||
if (retVal != RHINO_SUCCESS) {
|
||||
return RHINO_PWR_MGMT_ERR;
|
||||
}
|
||||
|
||||
cpu_pwr_child_add(pParentL2, pCpuNode);
|
||||
|
||||
/* record this node as leaf node in the topology */
|
||||
|
||||
retVal = cpu_pwr_leaf_node_record(pCpuNode, cpuIndex);
|
||||
|
||||
if (retVal == RHINO_PWR_MGMT_ERR) {
|
||||
return RHINO_PWR_MGMT_ERR;
|
||||
}
|
||||
|
||||
retVal = cpu_pwr_c_method_set_by_level(CPU_PWR_TOPO_LEVEL_2,
|
||||
board_cpu_c_state_set);
|
||||
|
||||
if (retVal == RHINO_PWR_MGMT_ERR) {
|
||||
return RHINO_PWR_MGMT_ERR;
|
||||
}
|
||||
|
||||
retVal = cpu_pwr_c_state_capability_set_by_level(CPU_PWR_TOPO_LEVEL_2,
|
||||
CPU_STATE_BIT(CPU_CSTATE_C0)
|
||||
| CPU_STATE_BIT(CPU_CSTATE_C1)
|
||||
);
|
||||
|
||||
if (retVal == RHINO_PWR_MGMT_ERR) {
|
||||
return RHINO_PWR_MGMT_ERR;
|
||||
}
|
||||
|
||||
|
||||
cpu_pwr_c_state_latency_save(cpuIndex, CPU_CSTATE_C0, 0);
|
||||
cpu_pwr_c_state_latency_save(cpuIndex, CPU_CSTATE_C1, 0);
|
||||
|
||||
tickless_one_shot_timer_save(CPU_CSTATE_C1, &tim_one_shot);
|
||||
|
||||
#if RHINO_CONFIG_CPU_TICKLESS
|
||||
|
||||
tickless_c_states_add(CPU_STATE_BIT(CPU_CSTATE_C0)
|
||||
| CPU_STATE_BIT(CPU_CSTATE_C1)
|
||||
);
|
||||
|
||||
#endif /* RHINO_CONFIG_CPU_TICKLESS */
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
//#endif /* RHINO_CONFIG_CPU_PWR_MGMT */
|
||||
129
csky/csi_kernel/rhino/board/board_cpu_pwr_rtc.c
Normal file
129
csky/csi_kernel/rhino/board/board_cpu_pwr_rtc.c
Normal file
@@ -0,0 +1,129 @@
|
||||
/*
|
||||
* Copyright (C) 2018 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
/*
|
||||
* This file supplied RTC one-shot start/stop services for CPU tickless
|
||||
* module, verifyied on STM32L496-DISCOVERY with C3/C4 mode.
|
||||
* C3: stop mode.
|
||||
* C4: standby mode.
|
||||
*/
|
||||
|
||||
#include "k_api.h"
|
||||
#include "cpu_pwr_config.h"
|
||||
|
||||
//#if (RHINO_CONFIG_CPU_PWR_MGMT > 0)
|
||||
//#if (RHINO_CONFIG_CPU_TICKLESS > 0)
|
||||
|
||||
#include "cpu_tickless.h"
|
||||
#include "drv_rtc.h"
|
||||
#define RTC_ONE_SHOT_DBG
|
||||
|
||||
extern void SystemClock_Config(void);
|
||||
|
||||
#define RTC_WAKEUP_SOURCE_FREQ_2000HZ
|
||||
//#define RTC_WAKEUP_SOURCE_FREQ_1HZ
|
||||
|
||||
/* According reference manual of STM32496G, RTC_WUTR is 16bit */
|
||||
#define RTC_WAKE_UP_RGE_MAX 0xffff
|
||||
//static uint32_t one_shot_enabled = 0;
|
||||
//static uint32_t one_shot_start_value = 0;
|
||||
static uint32_t one_shot_max_period = 0;/* seconds */
|
||||
//static kspinlock_t rtc_spin;
|
||||
//static RTC_HandleTypeDef RtcHandle;
|
||||
#ifdef RTC_ONE_SHOT_DBG
|
||||
//static int rtc_wakeup_irq_count = 0;
|
||||
#endif /* RTC_ONE_SHOT_DBG */
|
||||
|
||||
static kstat_t rtc_init(void);
|
||||
static uint32_t rtc_one_shot_max_seconds(void);
|
||||
static kstat_t rtc_one_shot_start(uint64_t planUs);
|
||||
static kstat_t rtc_one_shot_stop(uint64_t *pPassedUs);
|
||||
|
||||
one_shot_timer_t rtc_one_shot = {
|
||||
rtc_init,
|
||||
rtc_one_shot_max_seconds,
|
||||
rtc_one_shot_start,
|
||||
rtc_one_shot_stop,
|
||||
};
|
||||
|
||||
static uint32_t rtc_one_shot_max_seconds(void)
|
||||
{
|
||||
return one_shot_max_period;
|
||||
}
|
||||
|
||||
static kstat_t rtc_init(void)
|
||||
{
|
||||
|
||||
|
||||
return RHINO_SUCCESS;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
*
|
||||
* rtc_one_shot_start - enable the timer in oneshot mode
|
||||
*
|
||||
* This function enables the timer in oneshot mode, the interrupt will be fired
|
||||
* after servral microseconds which is indicated by planUs.
|
||||
*
|
||||
* RETURNS: RHINO_SUCCESS or RHINO_PWR_MGMT_ERR if timer is not enabled
|
||||
*
|
||||
* ERRNO
|
||||
*/
|
||||
|
||||
static kstat_t rtc_one_shot_start(uint64_t planUs)
|
||||
{
|
||||
|
||||
|
||||
return RHINO_SUCCESS;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
*
|
||||
* one_shot_planed_cnt - cancel the timer which was in oneshot mode
|
||||
*
|
||||
* This function is called to cancel the timer which was in oneshot mode.
|
||||
* the time has passed(microseconds) will be return in pPassedUs.
|
||||
*
|
||||
* RETURNS: RHINO_SUCCESS or RHINO_PWR_MGMT_ERR if timer is not disabled
|
||||
*
|
||||
* ERRNO: N/A
|
||||
*/
|
||||
|
||||
static kstat_t rtc_one_shot_stop
|
||||
(
|
||||
uint64_t *pPassedUs /* OUT */
|
||||
)
|
||||
{
|
||||
|
||||
return RHINO_SUCCESS;
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
*
|
||||
* RTC_WKUP_IRQHandler - ISR handle of RTC wakeup interrupt
|
||||
*
|
||||
* This function will replace weak one which is defined in
|
||||
* startup_stm32l496xx_keil.s
|
||||
*
|
||||
* RETURNS: N/A
|
||||
*
|
||||
* ERRNO: N/A
|
||||
*/
|
||||
|
||||
void RTC_WKUP_IRQHandler(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
#ifdef RTC_ONE_SHOT_DBG
|
||||
void rtc_info_show(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif /* RTC_ONE_SHOT_DBG */
|
||||
|
||||
//#endif /* RHINO_CONFIG_CPU_TICKLESS */
|
||||
//#endif /* RHINO_CONFIG_CPU_PWR_MGMT */
|
||||
46
csky/csi_kernel/rhino/board/board_cpu_pwr_systick.c
Normal file
46
csky/csi_kernel/rhino/board/board_cpu_pwr_systick.c
Normal file
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright (C) 2018 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
/*
|
||||
DESCRIPTION
|
||||
This file provides two fundtions systick_suspend()/systick_resume()
|
||||
which is used by cpu tickless module to suspend/resume system tick
|
||||
interrupt.
|
||||
|
||||
Differrent board may has different way to suspend/resume system tick
|
||||
interrupt, please reference your board/soc user manual to find the
|
||||
detail for how to implement these two functions.
|
||||
*/
|
||||
|
||||
#include "k_api.h"
|
||||
#include "cpu_pwr_config.h"
|
||||
#include "port.h"
|
||||
#include "csi_core.h"
|
||||
#if (RHINO_CONFIG_CPU_PWR_MGMT > 0)
|
||||
extern uint32_t csi_coret_suspend();
|
||||
extern uint32_t csi_coret_resume();
|
||||
|
||||
void systick_suspend(void)
|
||||
{
|
||||
CORET->CTRL = CORET_CTRL_CLKSOURCE_Msk | CORET_CTRL_TICKINT_Msk;
|
||||
}
|
||||
|
||||
void systick_resume(void)
|
||||
{
|
||||
CORET->CTRL = CORET_CTRL_CLKSOURCE_Msk |
|
||||
CORET_CTRL_TICKINT_Msk |
|
||||
CORET_CTRL_ENABLE_Msk; /* Enable CORET IRQ and CORET Timer */
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
void systick_suspend(void)
|
||||
{
|
||||
}
|
||||
|
||||
void systick_resume(void)
|
||||
{
|
||||
}
|
||||
|
||||
#endif /* RHINO_CONFIG_CPU_PWR_MGMT */
|
||||
152
csky/csi_kernel/rhino/board/board_cpu_pwr_timer.c
Normal file
152
csky/csi_kernel/rhino/board/board_cpu_pwr_timer.c
Normal file
@@ -0,0 +1,152 @@
|
||||
/*
|
||||
* Copyright (C) 2018 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
/*
|
||||
* According user manual of STM32L496-DISCOVERY
|
||||
* TIM2 and TIM5 are 32-bit timer, other timer is 16-bit.
|
||||
* This file will use TIM5 to supply one-shot start/stop service
|
||||
* for CPU tickless module.
|
||||
* verifyied on STM32L496-DISCOVERY with C1/C2 mode.
|
||||
* C1: sleep mode.
|
||||
* C2: low power sleep mode.
|
||||
*/
|
||||
|
||||
#include "k_api.h"
|
||||
#include "cpu_pwr_config.h"
|
||||
|
||||
//#if (RHINO_CONFIG_CPU_PWR_MGMT > 0)
|
||||
//#if (RHINO_CONFIG_CPU_TICKLESS > 0)
|
||||
|
||||
#include "cpu_tickless.h"
|
||||
//#include "drv_timer.h"
|
||||
#include "soc.h"
|
||||
|
||||
//#define TIM_DBG
|
||||
|
||||
#ifndef CONFIG_LPM_TICKLESS_SYSTIM
|
||||
#define CONFIG_LPM_TICKLESS_SYSTIM 0
|
||||
#endif
|
||||
|
||||
extern int aos_lpm_register_device(uint8_t level, void *func, void *param);
|
||||
|
||||
timer_handle_t wakeup_timer;
|
||||
|
||||
static uint32_t init_flag = 0;
|
||||
|
||||
static kspinlock_t tim_spin;
|
||||
|
||||
static kstat_t tim_timer_init(void);
|
||||
static uint32_t tim_one_shot_max_seconds(void);
|
||||
static kstat_t tim_one_shot_start(uint64_t planUs);
|
||||
static kstat_t tim_one_shot_stop(uint64_t *pPassedUs);
|
||||
|
||||
one_shot_timer_t tim_one_shot = {
|
||||
tim_timer_init,
|
||||
tim_one_shot_max_seconds,
|
||||
tim_one_shot_start,
|
||||
tim_one_shot_stop,
|
||||
};
|
||||
|
||||
void timer_event_cb(int32_t idx, timer_event_e event)
|
||||
{
|
||||
#ifdef TIM_DBG
|
||||
printf("time out\n");
|
||||
#endif
|
||||
}
|
||||
|
||||
kstat_t tim_timer_init(void)
|
||||
{
|
||||
if (init_flag == 1) {
|
||||
return RHINO_SUCCESS;
|
||||
}
|
||||
|
||||
krhino_spin_init(&tim_spin);
|
||||
wakeup_timer = csi_timer_initialize(CONFIG_LPM_TICKLESS_SYSTIM, timer_event_cb);
|
||||
csi_timer_config(wakeup_timer, TIMER_MODE_FREE_RUNNING);
|
||||
|
||||
#ifdef CONFIG_LPM
|
||||
aos_lpm_register_device(0, csi_timer_power_control, wakeup_timer);
|
||||
#endif
|
||||
|
||||
init_flag = 1;
|
||||
return RHINO_SUCCESS;
|
||||
}
|
||||
|
||||
/* return the max period(in second) that could trigger interrupt */
|
||||
|
||||
uint32_t tim_one_shot_max_seconds(void)
|
||||
{
|
||||
/* the max 32 bit value / count frequency */
|
||||
|
||||
return 0xffffffff / drv_get_sys_freq();
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
*
|
||||
* tim_one_shot_start - enable the timer in oneshot mode
|
||||
*
|
||||
* This function enables the timer in oneshot mode, the interrupt will be fired
|
||||
* after servral microseconds which is indicated by planUs.
|
||||
*
|
||||
* RETURNS: RHINO_SUCCESS or RHINO_PWR_MGMT_ERR if timer is not enabled
|
||||
*
|
||||
* ERRNO
|
||||
*/
|
||||
|
||||
kstat_t tim_one_shot_start
|
||||
(
|
||||
uint64_t planUs /* IN */
|
||||
)
|
||||
{
|
||||
|
||||
krhino_spin_lock_irq_save(&tim_spin);
|
||||
#ifdef TIM_DBG
|
||||
printf("tim_one_shot_start %d\n", planUs);
|
||||
#endif
|
||||
csi_timer_set_timeout(wakeup_timer, planUs);
|
||||
csi_timer_start(wakeup_timer);
|
||||
krhino_spin_unlock_irq_restore(&tim_spin);
|
||||
return RHINO_SUCCESS;
|
||||
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
*
|
||||
* tim_one_shot_stop - cancel the timer which was in oneshot mode
|
||||
*
|
||||
* This function is called to cancel the timer which was in oneshot mode.
|
||||
* the time has passed(microseconds) will be return in pPassedUs.
|
||||
*
|
||||
* RETURNS: RHINO_SUCCESS or RHINO_PWR_MGMT_ERR if timer is not disabled
|
||||
*
|
||||
* ERRNO: N/A
|
||||
*/
|
||||
|
||||
kstat_t tim_one_shot_stop
|
||||
(
|
||||
uint64_t *pPassedUs /* OUT */
|
||||
)
|
||||
{
|
||||
uint32_t load_val = 0;
|
||||
uint32_t current_val = 0;
|
||||
*pPassedUs = 0;
|
||||
krhino_spin_lock_irq_save(&tim_spin);
|
||||
|
||||
csi_timer_get_load_value(wakeup_timer, &load_val);
|
||||
csi_timer_get_current_value(wakeup_timer, ¤t_val);
|
||||
|
||||
*pPassedUs = (load_val - current_val) ? (load_val - current_val) : 0;
|
||||
|
||||
*pPassedUs = *pPassedUs * 1000000 / drv_get_sys_freq();
|
||||
#ifdef TIM_DBG
|
||||
printf("tim_one_shot_stop, pPassedUs %u, load_val %u, current_val %u\n", *pPassedUs, load_val, current_val);
|
||||
#endif
|
||||
csi_timer_stop(wakeup_timer);
|
||||
krhino_spin_unlock_irq_restore(&tim_spin);
|
||||
return RHINO_SUCCESS;
|
||||
}
|
||||
|
||||
//#endif /* RHINO_CONFIG_CPU_TICKLESS */
|
||||
//#endif /* RHINO_CONFIG_CPU_PWR_MGMT */
|
||||
|
||||
333
csky/csi_kernel/rhino/common/k_atomic.c
Normal file
333
csky/csi_kernel/rhino/common/k_atomic.c
Normal file
@@ -0,0 +1,333 @@
|
||||
/*
|
||||
* Copyright (C) 2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
/*
|
||||
modification history
|
||||
--------------------
|
||||
2017_12_27,WangMin(Rocky) created.
|
||||
*/
|
||||
|
||||
/*
|
||||
* DESCRIPTION
|
||||
* This library is used to provide the atomic operators for CPU
|
||||
* which do not support native atomic operations.
|
||||
*
|
||||
* The design principle is disable the interrupt when execute the
|
||||
* atomic operations and enable the interrupt after finish the
|
||||
* operation.
|
||||
*/
|
||||
|
||||
#include "k_api.h"
|
||||
#include "k_atomic.h"
|
||||
|
||||
/**
|
||||
* This routine atomically adds <*target> and <value>, placing the result in
|
||||
* <*target>. The operation is done using unsigned integer arithmetic.
|
||||
*
|
||||
* This routine can be used from both task and interrupt context.
|
||||
*
|
||||
* @param target memory location to add to
|
||||
* @param value the value to add
|
||||
*
|
||||
* @return The previous value from <target>
|
||||
*/
|
||||
|
||||
atomic_val_t rhino_atomic_add(atomic_t *target, atomic_val_t value)
|
||||
{
|
||||
CPSR_ALLOC();
|
||||
atomic_val_t old_value;
|
||||
|
||||
RHINO_CPU_INTRPT_DISABLE();
|
||||
|
||||
old_value = *target;
|
||||
*target += value;
|
||||
|
||||
RHINO_CPU_INTRPT_ENABLE();
|
||||
|
||||
return old_value;
|
||||
}
|
||||
|
||||
/**
|
||||
* This routine atomically subtracts <value> from <*target>, result is placed
|
||||
* in <*target>. The operation is done using unsigned integer arithmetic.
|
||||
*
|
||||
* This routine can be used from both task and interrupt context.
|
||||
*
|
||||
* @param target the memory location to subtract from
|
||||
* @param value the value to subtract
|
||||
*
|
||||
* @return The previous value from <target>
|
||||
*/
|
||||
|
||||
atomic_val_t rhino_atomic_sub(atomic_t *target, atomic_val_t value)
|
||||
{
|
||||
CPSR_ALLOC();
|
||||
atomic_val_t old_value;
|
||||
|
||||
RHINO_CPU_INTRPT_DISABLE();
|
||||
|
||||
old_value = *target;
|
||||
*target -= value;
|
||||
|
||||
RHINO_CPU_INTRPT_ENABLE();
|
||||
|
||||
return old_value;
|
||||
}
|
||||
|
||||
/**
|
||||
* This routine atomically increments the value in <*target>. The operation is
|
||||
* done using unsigned integer arithmetic.
|
||||
*
|
||||
* This routine can be used from both task and interrupt context.
|
||||
*
|
||||
* @return The value from <target> before the increment
|
||||
*/
|
||||
|
||||
atomic_val_t rhino_atomic_inc(atomic_t *target)
|
||||
{
|
||||
CPSR_ALLOC();
|
||||
atomic_val_t old_value;
|
||||
|
||||
RHINO_CPU_INTRPT_DISABLE();
|
||||
|
||||
old_value = *target;
|
||||
(*target)++;
|
||||
|
||||
RHINO_CPU_INTRPT_ENABLE();
|
||||
|
||||
return old_value;
|
||||
}
|
||||
|
||||
/**
|
||||
* This routine atomically decrement the value in <*target>. The operation is
|
||||
* done using unsigned integer arithmetic.
|
||||
*
|
||||
* This routine can be used from both task and interrupt context.
|
||||
*
|
||||
* @return The value from <target> before the increment
|
||||
*/
|
||||
|
||||
atomic_val_t rhino_atomic_dec(atomic_t *target)
|
||||
{
|
||||
CPSR_ALLOC();
|
||||
atomic_val_t old_value;
|
||||
|
||||
RHINO_CPU_INTRPT_DISABLE();
|
||||
|
||||
old_value = *target;
|
||||
(*target)--;
|
||||
|
||||
RHINO_CPU_INTRPT_ENABLE();
|
||||
|
||||
return old_value;
|
||||
}
|
||||
|
||||
/**
|
||||
* This routine atomically sets <*target> to <value> and returns the old value
|
||||
* that was in <*target>. Normally all CPU architectures can atomically write
|
||||
* to a variable of size atomic_t without the help of this routine.
|
||||
* This routine is intended for software that needs to atomically fetch and
|
||||
* replace the value of a memory location.
|
||||
*
|
||||
* This routine can be used from both task and interrupt context.
|
||||
*
|
||||
* @param target the memory location to write to
|
||||
* @param value the value to write
|
||||
*
|
||||
* @return The previous value from <target>
|
||||
*/
|
||||
|
||||
atomic_val_t rhino_atomic_set(atomic_t *target, atomic_val_t value)
|
||||
{
|
||||
CPSR_ALLOC();
|
||||
atomic_val_t old_value;
|
||||
|
||||
RHINO_CPU_INTRPT_DISABLE();
|
||||
|
||||
old_value = *target;
|
||||
*target = value;
|
||||
|
||||
RHINO_CPU_INTRPT_ENABLE();
|
||||
|
||||
return old_value;
|
||||
}
|
||||
|
||||
/**
|
||||
* This routine atomically read a value from <target>.
|
||||
* This routine can be used from both task and interrupt context.
|
||||
*
|
||||
* @return The value read from <target>
|
||||
*/
|
||||
|
||||
atomic_val_t rhino_atomic_get(const atomic_t *target)
|
||||
{
|
||||
return *target;
|
||||
}
|
||||
|
||||
/**
|
||||
* This routine atomically performs a bitwise OR operation of <*target>
|
||||
* and <value>, placing the result in <*target>.
|
||||
*
|
||||
* This routine can be used from both task and interrupt context.
|
||||
*
|
||||
* @param target the memory location to be modified
|
||||
* @param value the value to OR
|
||||
*
|
||||
* @return The previous value from <target>
|
||||
*/
|
||||
|
||||
atomic_val_t rhino_atomic_or(atomic_t *target, atomic_val_t value)
|
||||
{
|
||||
CPSR_ALLOC();
|
||||
atomic_val_t old_value;
|
||||
|
||||
RHINO_CPU_INTRPT_DISABLE();
|
||||
|
||||
old_value = *target;
|
||||
*target |= value;
|
||||
|
||||
RHINO_CPU_INTRPT_ENABLE();
|
||||
|
||||
return old_value;
|
||||
}
|
||||
|
||||
/**
|
||||
* This routine atomically performs a bitwise XOR operation of <*target> and
|
||||
* <value>, placing the result in <*target>.
|
||||
*
|
||||
* This routine can be used from both task and interrupt context.
|
||||
*
|
||||
* @param target the memory location to be modified
|
||||
* @param value the value to XOR
|
||||
*
|
||||
* @return The previous value from <target>
|
||||
*/
|
||||
|
||||
atomic_val_t rhino_atomic_xor(atomic_t *target, atomic_val_t value)
|
||||
{
|
||||
CPSR_ALLOC();
|
||||
atomic_val_t old_value;
|
||||
|
||||
RHINO_CPU_INTRPT_DISABLE();
|
||||
|
||||
old_value = *target;
|
||||
*target ^= value;
|
||||
|
||||
RHINO_CPU_INTRPT_ENABLE();
|
||||
|
||||
return old_value;
|
||||
}
|
||||
|
||||
/**
|
||||
* This routine atomically performs a bitwise AND operation of <*target> and
|
||||
* <value>, placing the result in <*target>.
|
||||
*
|
||||
* This routine can be used from both task and interrupt context.
|
||||
*
|
||||
* @param target the memory location to be modified
|
||||
* @param value the value to AND
|
||||
*
|
||||
* @return The previous value from <target>
|
||||
*/
|
||||
|
||||
atomic_val_t rhino_atomic_and(atomic_t *target, atomic_val_t value)
|
||||
{
|
||||
CPSR_ALLOC();
|
||||
atomic_val_t old_value;
|
||||
|
||||
RHINO_CPU_INTRPT_DISABLE();
|
||||
|
||||
old_value = *target;
|
||||
*target &= value;
|
||||
|
||||
RHINO_CPU_INTRPT_ENABLE();
|
||||
|
||||
return old_value;
|
||||
}
|
||||
|
||||
/**
|
||||
* This routine atomically performs a bitwise NAND operation of <*target> and
|
||||
* <value>, placing the result in <*target>.
|
||||
*
|
||||
* This routine can be used from both task and interrupt context.
|
||||
*
|
||||
* @param target the memory location to be modified
|
||||
* @param value the value to NAND
|
||||
*
|
||||
* @return The previous value from <target>
|
||||
*/
|
||||
|
||||
atomic_val_t rhino_atomic_nand(atomic_t *target, atomic_val_t value)
|
||||
{
|
||||
CPSR_ALLOC();
|
||||
atomic_val_t old_value;
|
||||
|
||||
RHINO_CPU_INTRPT_DISABLE();
|
||||
|
||||
old_value = *target;
|
||||
*target = ~(*target & value);
|
||||
|
||||
RHINO_CPU_INTRPT_ENABLE();
|
||||
|
||||
return old_value;
|
||||
}
|
||||
|
||||
/**
|
||||
* This routine provides the atomic clear operator. The value of 0 is atomically
|
||||
* written at <target> and the previous value at <target> is returned.
|
||||
*
|
||||
* This routine can be used from both task and interrupt context.
|
||||
*
|
||||
* @param target the memory location to write
|
||||
*
|
||||
* @return The previous value from <target>
|
||||
*/
|
||||
|
||||
atomic_val_t rhino_atomic_clear(atomic_t *target)
|
||||
{
|
||||
CPSR_ALLOC();
|
||||
atomic_val_t old_value;
|
||||
|
||||
RHINO_CPU_INTRPT_DISABLE();
|
||||
|
||||
old_value = *target;
|
||||
*target = 0;
|
||||
|
||||
RHINO_CPU_INTRPT_ENABLE();
|
||||
|
||||
return old_value;
|
||||
}
|
||||
|
||||
/**
|
||||
* This routine performs an atomic compare-and-swap, it test that whether
|
||||
* <*target> equal to <oldValue>, and if TRUE, setting the value of <*target>
|
||||
* to <newValue> and return 1.
|
||||
*
|
||||
* If the original value at <target> does not equal <oldValue>, then the target
|
||||
* will not be updated and return 0.
|
||||
*
|
||||
* @param target address to be tested
|
||||
* @param old_value value to compare against
|
||||
* @param new_value value to compare against
|
||||
* @return Returns 1 if <new_value> is written, 0 otherwise.
|
||||
*/
|
||||
|
||||
int rhino_atomic_cas(atomic_t *target, atomic_val_t old_value,
|
||||
atomic_val_t new_value)
|
||||
{
|
||||
CPSR_ALLOC();
|
||||
int ret = 0;
|
||||
|
||||
RHINO_CPU_INTRPT_DISABLE();
|
||||
|
||||
if (*target == old_value)
|
||||
{
|
||||
*target = new_value;
|
||||
ret = 1;
|
||||
}
|
||||
|
||||
RHINO_CPU_INTRPT_ENABLE();
|
||||
|
||||
return ret;
|
||||
}
|
||||
40
csky/csi_kernel/rhino/common/k_atomic.h
Normal file
40
csky/csi_kernel/rhino/common/k_atomic.h
Normal file
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright (C) 2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
/*
|
||||
modification history
|
||||
--------------------
|
||||
2017_12_27,WangMin(Rocky) created.
|
||||
*/
|
||||
|
||||
#ifndef K_ATOMIC_H
|
||||
#define K_ATOMIC_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef unsigned int atomic_t;
|
||||
typedef atomic_t atomic_val_t;
|
||||
|
||||
extern atomic_val_t rhino_atomic_add(atomic_t *target, atomic_val_t value);
|
||||
extern atomic_val_t rhino_atomic_sub(atomic_t *target, atomic_val_t value);
|
||||
extern atomic_val_t rhino_atomic_inc(atomic_t *target);
|
||||
extern atomic_val_t rhino_atomic_dec(atomic_t *target);
|
||||
extern atomic_val_t rhino_atomic_set(atomic_t *target, atomic_val_t value);
|
||||
extern atomic_val_t rhino_atomic_get(const atomic_t *target);
|
||||
extern atomic_val_t rhino_atomic_or(atomic_t *target, atomic_val_t value);
|
||||
extern atomic_val_t rhino_atomic_xor(atomic_t *target, atomic_val_t value);
|
||||
extern atomic_val_t rhino_atomic_and(atomic_t *target, atomic_val_t value);
|
||||
extern atomic_val_t rhino_atomic_nand(atomic_t *target, atomic_val_t value);
|
||||
extern atomic_val_t rhino_atomic_clear(atomic_t *target);
|
||||
extern int rhino_atomic_cas(atomic_t *target, atomic_val_t old_value,
|
||||
atomic_val_t new_value);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* K_ATOMIC_H */
|
||||
|
||||
47
csky/csi_kernel/rhino/common/k_cpuset.h
Normal file
47
csky/csi_kernel/rhino/common/k_cpuset.h
Normal file
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright (C) 2018 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
/*
|
||||
modification history
|
||||
--------------------
|
||||
21jan2018,WangMin writen.
|
||||
*/
|
||||
|
||||
/*
|
||||
DESCRIPTION
|
||||
This file provides base type of cpu set and method for cpu set.
|
||||
*/
|
||||
|
||||
#ifndef __cpuset_h__
|
||||
#define __cpuset_h__
|
||||
|
||||
#include "k_atomic.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* typedefs */
|
||||
|
||||
typedef unsigned int cpuset_t;
|
||||
|
||||
#define CPUSET_ATOMIC_SET(cpuset, n) \
|
||||
(void) rhino_atomic_or ((atomic_t *) &(cpuset), 1 << (n))
|
||||
#define CPUSET_ATOMIC_CLR(cpuset, n) \
|
||||
(void) rhino_atomic_and ((atomic_t *) &(cpuset), ~((1 << (n))))
|
||||
#define CPUSET_ATOMIC_COPY(cpusetDst, cpusetSrc) \
|
||||
(void) rhino_atomic_set ((atomic_t *) &(cpusetDst), (atomic_t) (cpusetSrc))
|
||||
|
||||
#define CPUSET_CLR(cpuset, n) ((cpuset) &= ~(1 << (n)))
|
||||
#define CPUSET_ZERO(cpuset) ((cpuset) = 0)
|
||||
#define CPUSET_IS_ZERO(cpuset) ((cpuset) == 0)
|
||||
#define CPUSET_SET(cpuset, n) ((cpuset) |= (1 << (n)))
|
||||
#define CPUSET_ISSET(cpuset, n) ((cpuset) & (1 << (n)))
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __cpuset_h__ */
|
||||
|
||||
45
csky/csi_kernel/rhino/common/k_ffs.c
Normal file
45
csky/csi_kernel/rhino/common/k_ffs.c
Normal file
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright (C) 2018 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
/*
|
||||
DESCRIPTION
|
||||
This file provides method to find the least/most significant bit in 32 bit
|
||||
fields.
|
||||
*/
|
||||
|
||||
#include "k_api.h"
|
||||
#include "k_ffs.h"
|
||||
#include "k_bitmap.h"
|
||||
|
||||
/* find most significant bit set */
|
||||
|
||||
int ffs32_msb(uint32_t bitmap)
|
||||
{
|
||||
if (bitmap == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 32 - krhino_find_first_bit(&bitmap);
|
||||
}
|
||||
|
||||
|
||||
/* find least significant bit set */
|
||||
|
||||
int ffs32_lsb(uint32_t bitmap)
|
||||
{
|
||||
uint32_t x;
|
||||
int lsbit;
|
||||
|
||||
if (bitmap == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
x = bitmap & -bitmap;
|
||||
lsbit = krhino_find_first_bit((uint32_t *)(&x));
|
||||
|
||||
return 32 - lsbit;
|
||||
}
|
||||
|
||||
25
csky/csi_kernel/rhino/common/k_ffs.h
Normal file
25
csky/csi_kernel/rhino/common/k_ffs.h
Normal file
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright (C) 2018 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#ifndef __k_ffs_h__
|
||||
#define __k_ffs_h__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* function declarations */
|
||||
|
||||
extern int ffs32_lsb (uint32_t i);
|
||||
extern int ffs32_msb (uint32_t i);
|
||||
|
||||
#define FFS_LSB(i) ffs32_lsb(i)
|
||||
#define FFS_MSB(i) ffs32_msb(i)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __k_ffs_h__ */
|
||||
|
||||
177
csky/csi_kernel/rhino/common/k_fifo.c
Normal file
177
csky/csi_kernel/rhino/common/k_fifo.c
Normal file
@@ -0,0 +1,177 @@
|
||||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <k_api.h>
|
||||
|
||||
|
||||
/*
|
||||
* internal helper to calculate the unused elements in a fifo
|
||||
*/
|
||||
static uint32_t fifo_unused(struct k_fifo *fifo)
|
||||
{
|
||||
return (fifo->mask + 1) - (fifo->in - fifo->out);
|
||||
}
|
||||
|
||||
static int8_t is_power_of_2(uint32_t n)
|
||||
{
|
||||
return (n != 0 && ((n & (n - 1)) == 0));
|
||||
}
|
||||
|
||||
int8_t fifo_init(struct k_fifo *fifo, void *buffer, uint32_t size)
|
||||
{
|
||||
/*
|
||||
* round down to the next power of 2, since our 'let the indices
|
||||
* wrap' technique works only in this case.
|
||||
*/
|
||||
if (!is_power_of_2(size)) {
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
fifo->in = 0;
|
||||
fifo->out = 0;
|
||||
fifo->data = buffer;
|
||||
|
||||
if (size < 2) {
|
||||
fifo->mask = 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
fifo->mask = size - 1;
|
||||
fifo->free_bytes = size;
|
||||
fifo->size = size;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void fifo_copy_in(struct k_fifo *fifo, const void *src,
|
||||
uint32_t len, uint32_t off)
|
||||
{
|
||||
uint32_t l;
|
||||
|
||||
uint32_t size = fifo->mask + 1;
|
||||
|
||||
off &= fifo->mask;
|
||||
|
||||
l = fifo_min(len, size - off);
|
||||
|
||||
memcpy((unsigned char *)fifo->data + off, src, l);
|
||||
memcpy(fifo->data, (unsigned char *)src + l, len - l);
|
||||
|
||||
|
||||
}
|
||||
|
||||
uint32_t fifo_in(struct k_fifo *fifo, const void *buf, uint32_t len)
|
||||
{
|
||||
uint32_t l;
|
||||
|
||||
CPSR_ALLOC();
|
||||
|
||||
RHINO_CRITICAL_ENTER();
|
||||
|
||||
l = fifo_unused(fifo);
|
||||
|
||||
if (len > l) {
|
||||
len = l;
|
||||
}
|
||||
|
||||
fifo_copy_in(fifo, buf, len, fifo->in);
|
||||
fifo->in += len;
|
||||
|
||||
fifo->free_bytes -= len;
|
||||
|
||||
RHINO_CRITICAL_EXIT();
|
||||
return len;
|
||||
}
|
||||
|
||||
static void kfifo_copy_out(struct k_fifo *fifo, void *dst,
|
||||
uint32_t len, uint32_t off)
|
||||
{
|
||||
uint32_t l;
|
||||
uint32_t size = fifo->mask + 1;
|
||||
|
||||
off &= fifo->mask;
|
||||
|
||||
l = fifo_min(len, size - off);
|
||||
|
||||
memcpy(dst, (unsigned char *)fifo->data + off, l);
|
||||
memcpy((unsigned char *)dst + l, fifo->data, len - l);
|
||||
|
||||
}
|
||||
|
||||
static uint32_t internal_fifo_out_peek(struct k_fifo *fifo,
|
||||
void *buf, uint32_t len)
|
||||
{
|
||||
uint32_t l;
|
||||
|
||||
l = fifo->in - fifo->out;
|
||||
|
||||
if (len > l) {
|
||||
len = l;
|
||||
}
|
||||
|
||||
kfifo_copy_out(fifo, buf, len, fifo->out);
|
||||
return len;
|
||||
}
|
||||
|
||||
uint32_t fifo_out_peek(struct k_fifo *fifo,
|
||||
void *buf, uint32_t len)
|
||||
{
|
||||
|
||||
uint32_t ret_len;
|
||||
|
||||
CPSR_ALLOC();
|
||||
|
||||
RHINO_CRITICAL_ENTER();
|
||||
|
||||
ret_len = internal_fifo_out_peek(fifo, buf, len);
|
||||
|
||||
RHINO_CRITICAL_EXIT();
|
||||
|
||||
return ret_len;
|
||||
|
||||
}
|
||||
|
||||
uint32_t fifo_out(struct k_fifo *fifo, void *buf, uint32_t len)
|
||||
{
|
||||
CPSR_ALLOC();
|
||||
|
||||
RHINO_CRITICAL_ENTER();
|
||||
|
||||
len = internal_fifo_out_peek(fifo, buf, len);
|
||||
fifo->out += len;
|
||||
|
||||
fifo->free_bytes += len;
|
||||
|
||||
RHINO_CRITICAL_EXIT();
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
uint32_t fifo_out_all(struct k_fifo *fifo, void *buf)
|
||||
{
|
||||
uint32_t len;
|
||||
|
||||
CPSR_ALLOC();
|
||||
|
||||
RHINO_CRITICAL_ENTER();
|
||||
|
||||
len = fifo->size - fifo->free_bytes;
|
||||
|
||||
if (len == 0) {
|
||||
|
||||
RHINO_CRITICAL_EXIT();
|
||||
return 0;
|
||||
}
|
||||
|
||||
len = internal_fifo_out_peek(fifo, buf, len);
|
||||
fifo->out += len;
|
||||
|
||||
fifo->free_bytes += len;
|
||||
|
||||
RHINO_CRITICAL_EXIT();
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
1540
csky/csi_kernel/rhino/common/k_trace.c
Normal file
1540
csky/csi_kernel/rhino/common/k_trace.c
Normal file
File diff suppressed because it is too large
Load Diff
68
csky/csi_kernel/rhino/core/include/k_api.h
Normal file
68
csky/csi_kernel/rhino/core/include/k_api.h
Normal file
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#ifndef K_API_H
|
||||
#define K_API_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <k_config.h>
|
||||
#include <k_default_config.h>
|
||||
#include <k_types.h>
|
||||
#include <k_err.h>
|
||||
#include <k_critical.h>
|
||||
#include <k_sys.h>
|
||||
#include <k_bitmap.h>
|
||||
#include <k_list.h>
|
||||
#include <k_obj.h>
|
||||
#include <k_sched.h>
|
||||
#include <k_task.h>
|
||||
#include <k_ringbuf.h>
|
||||
#include <k_queue.h>
|
||||
#include <k_buf_queue.h>
|
||||
#include <k_sem.h>
|
||||
#include <k_task_sem.h>
|
||||
#include <k_mutex.h>
|
||||
#include <k_timer.h>
|
||||
#include <k_time.h>
|
||||
#include <k_event.h>
|
||||
#include <k_stats.h>
|
||||
#include <k_mm_debug.h>
|
||||
#include <k_mm_blk.h>
|
||||
#include <k_mm_region.h>
|
||||
#include <k_mm.h>
|
||||
#include <k_workqueue.h>
|
||||
#include <k_internal.h>
|
||||
#include <k_trace.h>
|
||||
#include <k_soc.h>
|
||||
#include <k_hook.h>
|
||||
#include <port.h>
|
||||
#include <k_endian.h>
|
||||
#include <k_fifo.h>
|
||||
|
||||
#ifndef __at_section
|
||||
#define __at_section(sec) __attribute__((section(sec)))
|
||||
#endif
|
||||
|
||||
#ifndef __bobj
|
||||
#define __bobj
|
||||
#endif
|
||||
|
||||
#ifndef __init
|
||||
#define __init
|
||||
#endif
|
||||
|
||||
extern void assert_internal(const char *__function, unsigned int __line, const char *__assertion, void *lr);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* K_API_H */
|
||||
|
||||
108
csky/csi_kernel/rhino/core/include/k_bitmap.h
Normal file
108
csky/csi_kernel/rhino/core/include/k_bitmap.h
Normal file
@@ -0,0 +1,108 @@
|
||||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#ifndef K_BITMAP_H
|
||||
#define K_BITMAP_H
|
||||
|
||||
#define BITMAP_UNIT_SIZE 32U
|
||||
#define BITMAP_UNIT_MASK 0X0000001F
|
||||
#define BITMAP_UNIT_BITS 5U
|
||||
|
||||
#define BITMAP_MASK(nr) (1UL << (BITMAP_UNIT_SIZE - 1U - ((nr) & BITMAP_UNIT_MASK)))
|
||||
#define BITMAP_WORD(nr) ((nr) >> BITMAP_UNIT_BITS)
|
||||
|
||||
|
||||
#define LITTLE_TO_BIG_ENDIAN(x) ((uint32_t)(((x) & 0x000000ffUL) << 24u) | \
|
||||
(((x) & 0x0000ff00UL) << 8u) | \
|
||||
(((x) & 0x00ff0000UL) >> 8u) | \
|
||||
(((x) & 0xff000000UL) >> 24u))
|
||||
|
||||
/**
|
||||
** This MACRO will declare a bitmap
|
||||
** @param[in] name the name of the bitmap to declare
|
||||
** @param[in] bits the bits of the bitmap
|
||||
** @return no return
|
||||
**/
|
||||
#define BITMAP_DECLARE(name, bits) uint32_t name[((bits) + (BITMAP_UNIT_SIZE - 1U)) >> BITMAP_UNIT_BITS]
|
||||
|
||||
#if (RHINO_CONFIG_BITMAP_HW != 0)
|
||||
extern int32_t cpu_bitmap_clz(uint32_t val);
|
||||
#endif
|
||||
|
||||
/**
|
||||
** This function will set a bit of the bitmap
|
||||
** @param[in] bitmap pointer to the bitmap
|
||||
** @param[in] nr position of the bitmap to set
|
||||
** @return no return
|
||||
**/
|
||||
RHINO_INLINE void krhino_bitmap_set(uint32_t *bitmap, int32_t nr)
|
||||
{
|
||||
bitmap[BITMAP_WORD(nr)] |= BITMAP_MASK(nr);
|
||||
}
|
||||
|
||||
/**
|
||||
** This function will clear a bit of the bitmap
|
||||
** @param[in] bitmap pointer to the bitmap
|
||||
** @param[in] nr position of the bitmap to clear
|
||||
** @return no return
|
||||
**/
|
||||
RHINO_INLINE void krhino_bitmap_clear(uint32_t *bitmap, int32_t nr)
|
||||
{
|
||||
bitmap[BITMAP_WORD(nr)] &= ~BITMAP_MASK(nr);
|
||||
}
|
||||
|
||||
/**
|
||||
** This function will find the first bit(1) of the bitmap
|
||||
** @param[in] bitmap pointer to the bitmap
|
||||
** @return the first bit position
|
||||
**/
|
||||
RHINO_INLINE int krhino_find_first_bit(uint32_t *bitmap)
|
||||
{
|
||||
int32_t nr = 0;
|
||||
uint32_t tmp = 0;
|
||||
|
||||
while (*bitmap == 0UL) {
|
||||
nr += BITMAP_UNIT_SIZE;
|
||||
bitmap++;
|
||||
}
|
||||
|
||||
tmp = *bitmap;
|
||||
|
||||
#if (RHINO_CONFIG_LITTLE_ENDIAN == 0)
|
||||
tmp = LITTLE_TO_BIG_ENDIAN(tmp);
|
||||
#endif
|
||||
|
||||
#if (RHINO_CONFIG_BITMAP_HW == 0)
|
||||
if (!(tmp & 0XFFFF0000)) {
|
||||
tmp <<= 16;
|
||||
nr += 16;
|
||||
}
|
||||
|
||||
if (!(tmp & 0XFF000000)) {
|
||||
tmp <<= 8;
|
||||
nr += 8;
|
||||
}
|
||||
|
||||
if (!(tmp & 0XF0000000)) {
|
||||
tmp <<= 4;
|
||||
nr += 4;
|
||||
}
|
||||
|
||||
if (!(tmp & 0XC0000000)) {
|
||||
tmp <<= 2;
|
||||
nr += 2;
|
||||
}
|
||||
|
||||
if (!(tmp & 0X80000000)) {
|
||||
nr += 1;
|
||||
}
|
||||
#else
|
||||
nr += cpu_bitmap_clz(tmp);
|
||||
#endif
|
||||
|
||||
return nr;
|
||||
}
|
||||
|
||||
#endif /* K_BITMAP_H */
|
||||
|
||||
122
csky/csi_kernel/rhino/core/include/k_buf_queue.h
Normal file
122
csky/csi_kernel/rhino/core/include/k_buf_queue.h
Normal file
@@ -0,0 +1,122 @@
|
||||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#ifndef K_BUF_QUEUE_H
|
||||
#define K_BUF_QUEUE_H
|
||||
|
||||
typedef struct {
|
||||
blk_obj_t blk_obj;
|
||||
blk_obj_t sblk_obj;
|
||||
void *buf;
|
||||
k_ringbuf_t ringbuf;
|
||||
size_t max_msg_size;
|
||||
size_t cur_num;
|
||||
size_t peak_num;
|
||||
size_t min_free_buf_size;
|
||||
#if (RHINO_CONFIG_SYSTEM_STATS > 0)
|
||||
klist_t buf_queue_item;
|
||||
#endif
|
||||
uint8_t mm_alloc_flag;
|
||||
} kbuf_queue_t;
|
||||
|
||||
typedef struct {
|
||||
size_t buf_size;
|
||||
size_t max_msg_size;
|
||||
size_t cur_num;
|
||||
size_t peak_num;
|
||||
size_t free_buf_size;
|
||||
size_t min_free_buf_size;
|
||||
} kbuf_queue_info_t;
|
||||
|
||||
/**
|
||||
* This function will create a buf-queue
|
||||
* @param[in] queue pointer to the queue(the space is provided by user)
|
||||
* @param[in] name name of the queue
|
||||
* @param[in] buf pointer to the buf
|
||||
* @param[in] size size of the buf
|
||||
* @param[in] max_msg max size of one msg
|
||||
* @return the operation status, RHINO_SUCCESS is OK, others is error
|
||||
*/
|
||||
kstat_t krhino_buf_queue_create(kbuf_queue_t *queue, const name_t *name,
|
||||
void *buf,
|
||||
size_t size, size_t max_msg);
|
||||
|
||||
/**
|
||||
* This function will create a fix buf-queue
|
||||
* @param[in] queue pointer to the queue(the space is provided by user)
|
||||
* @param[in] name name of the queue
|
||||
* @param[in] buf pointer to the buf
|
||||
* @param[in] msg_size size of the msg
|
||||
* @param[in] msg_num number of msg
|
||||
* @return the operation status, RHINO_SUCCESS is OK, others is error
|
||||
*/
|
||||
kstat_t krhino_fix_buf_queue_create(kbuf_queue_t *queue, const name_t *name,
|
||||
void *buf, size_t msg_size, size_t msg_num);
|
||||
|
||||
/**
|
||||
* This function will delete a queue
|
||||
* @param[in] queue pointer to the queue
|
||||
* @return the operation status, RHINO_SUCCESS is OK, others is error
|
||||
*/
|
||||
kstat_t krhino_buf_queue_del(kbuf_queue_t *queue);
|
||||
|
||||
#if (RHINO_CONFIG_KOBJ_DYN_ALLOC > 0)
|
||||
/**
|
||||
* This function will create a dyn-queue
|
||||
* @param[out] queue pointer to the queue(The space is provided by kernel)
|
||||
* @param[in] name pointer to the nam
|
||||
* @param[in] size size of the buf
|
||||
* @param[in] max_msg max size of one msg
|
||||
* @return the operation status, RHINO_SUCCESS is OK, others is error
|
||||
*/
|
||||
kstat_t krhino_buf_queue_dyn_create(kbuf_queue_t **queue, const name_t *name,
|
||||
size_t size, size_t max_msg);
|
||||
|
||||
/**
|
||||
* This function will delete a dyn-queue
|
||||
* @param[in] queue pointer to the queue
|
||||
* @return the operation status, RHINO_SUCCESS is OK, others is error
|
||||
*/
|
||||
kstat_t krhino_buf_queue_dyn_del(kbuf_queue_t *queue);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This function will send a msg at the end of queue
|
||||
* @param[in] queue pointer to the queue
|
||||
* @param[in] msg pointer to msg to be send
|
||||
* @param[in] size size of the msg
|
||||
* @return the operation status, RHINO_SUCCESS is OK, others is error
|
||||
*/
|
||||
kstat_t krhino_buf_queue_send(kbuf_queue_t *queue, void *msg, size_t size, tick_t ticks);
|
||||
|
||||
|
||||
/**
|
||||
* This function will receive msg form aqueue
|
||||
* @param[in] queue pointer to the queue
|
||||
* @param[in] ticks ticks to wait before receiving msg
|
||||
* @param[out] msg pointer to the buf to save msg
|
||||
* @param[out] size size of received msg
|
||||
* @return the operation status, RHINO_SUCCESS is OK, others is error
|
||||
*/
|
||||
kstat_t krhino_buf_queue_recv(kbuf_queue_t *queue, tick_t ticks, void *msg,
|
||||
size_t *size);
|
||||
|
||||
/**
|
||||
* This function will reset queue
|
||||
* @param[in] queue pointer to the queue
|
||||
* @return the operation status, RHINO_SUCCESS is OK, others is error
|
||||
*/
|
||||
kstat_t krhino_buf_queue_flush(kbuf_queue_t *queue);
|
||||
|
||||
/**
|
||||
* This function will get information of a queue
|
||||
* @param[in] queue pointer to the queue
|
||||
* @param[out] free free size of the queue buf
|
||||
* @param[out] total total size of the queue buf
|
||||
* @return the operation status, RHINO_SUCCESS is OK, others is error
|
||||
*/
|
||||
kstat_t krhino_buf_queue_info_get(kbuf_queue_t *queue, kbuf_queue_info_t *info);
|
||||
|
||||
#endif /* K_BUF_QUEUE_H */
|
||||
|
||||
132
csky/csi_kernel/rhino/core/include/k_critical.h
Normal file
132
csky/csi_kernel/rhino/core/include/k_critical.h
Normal file
@@ -0,0 +1,132 @@
|
||||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#ifndef K_CRITICAL_H
|
||||
#define K_CRITICAL_H
|
||||
|
||||
typedef struct {
|
||||
#if (RHINO_CONFIG_CPU_NUM > 1)
|
||||
uint32_t owner; /* cpu index of owner */
|
||||
#endif
|
||||
uint32_t cnt;
|
||||
cpu_cpsr_t cpsr; /* the int key for this lock */
|
||||
} kspinlock_t;
|
||||
|
||||
#if (RHINO_CONFIG_CPU_NUM > 1)
|
||||
/* SMP spin lock */
|
||||
#define krhino_spin_lock(lock) do { \
|
||||
kspinlock_t *s = (kspinlock_t*)(lock); \
|
||||
cpu_spin_lock((lock)); \
|
||||
s->cnt++; \
|
||||
} while (0) \
|
||||
|
||||
#define krhino_spin_unlock(lock) do { \
|
||||
kspinlock_t *s = (kspinlock_t*)(lock); \
|
||||
s->cnt--; \
|
||||
if (s->cnt == 0u) { \
|
||||
cpu_spin_unlock((lock)); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define krhino_spin_lock_irq_save(lock) do { \
|
||||
kspinlock_t *s = (kspinlock_t*)(lock); \
|
||||
s->cpsr = cpu_intrpt_save(); \
|
||||
cpu_spin_lock((lock)); \
|
||||
s->cnt++; \
|
||||
} while (0)
|
||||
|
||||
#define krhino_spin_unlock_irq_restore(lock) do { \
|
||||
kspinlock_t *s = (kspinlock_t*)(lock); \
|
||||
s->cnt--; \
|
||||
if (s->cnt == 0u) { \
|
||||
cpu_spin_unlock((lock)); \
|
||||
cpu_intrpt_restore(s->cpsr); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define krhino_spin_init(lock) do{ \
|
||||
kspinlock_t *s = (kspinlock_t*)(lock); \
|
||||
s->owner = (uint32_t)-1; \
|
||||
s->cnt = 0u; \
|
||||
} while(0)
|
||||
#else
|
||||
/* UP spin lock */
|
||||
#define krhino_spin_lock(lock) krhino_sched_disable();
|
||||
#define krhino_spin_unlock(lock) krhino_sched_enable();
|
||||
|
||||
#define krhino_spin_lock_irq_save(lock) do { \
|
||||
kspinlock_t *s = (kspinlock_t*)(lock); \
|
||||
s->cpsr = cpu_intrpt_save(); \
|
||||
s->cnt++; \
|
||||
} while (0)
|
||||
|
||||
#define krhino_spin_unlock_irq_restore(lock) do { \
|
||||
kspinlock_t *s = (kspinlock_t*)(lock); \
|
||||
s->cnt--; \
|
||||
if (s->cnt == 0u) { \
|
||||
cpu_intrpt_restore(s->cpsr); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define krhino_spin_init(lock)
|
||||
#endif
|
||||
|
||||
#if (RHINO_CONFIG_DISABLE_INTRPT_STATS > 0)
|
||||
#define RHINO_CRITICAL_ENTER() \
|
||||
do { \
|
||||
RHINO_CPU_INTRPT_DISABLE(); \
|
||||
intrpt_disable_measure_start(); \
|
||||
} while (0)
|
||||
|
||||
#define RHINO_CRITICAL_EXIT() \
|
||||
do { \
|
||||
intrpt_disable_measure_stop(); \
|
||||
RHINO_CPU_INTRPT_ENABLE(); \
|
||||
} while (0)
|
||||
|
||||
#if (RHINO_CONFIG_CPU_NUM > 1)
|
||||
#define RHINO_CRITICAL_EXIT_SCHED() \
|
||||
do { \
|
||||
intrpt_disable_measure_stop(); \
|
||||
core_sched(); \
|
||||
RHINO_CPU_INTRPT_ENABLE(); \
|
||||
} while (0)
|
||||
#else
|
||||
#define RHINO_CRITICAL_EXIT_SCHED() \
|
||||
do { \
|
||||
intrpt_disable_measure_stop(); \
|
||||
RHINO_CPU_INTRPT_ENABLE(); \
|
||||
core_sched(); \
|
||||
} while (0)
|
||||
#endif
|
||||
|
||||
#else /* RHINO_CONFIG_DISABLE_INTRPT_STATS */
|
||||
#define RHINO_CRITICAL_ENTER() \
|
||||
do { \
|
||||
RHINO_CPU_INTRPT_DISABLE(); \
|
||||
} while (0)
|
||||
|
||||
#define RHINO_CRITICAL_EXIT() \
|
||||
do { \
|
||||
RHINO_CPU_INTRPT_ENABLE(); \
|
||||
} while (0)
|
||||
|
||||
#if (RHINO_CONFIG_CPU_NUM > 1)
|
||||
#define RHINO_CRITICAL_EXIT_SCHED() \
|
||||
do { \
|
||||
core_sched(); \
|
||||
RHINO_CPU_INTRPT_ENABLE(); \
|
||||
} while (0)
|
||||
#else
|
||||
#define RHINO_CRITICAL_EXIT_SCHED() \
|
||||
do { \
|
||||
RHINO_CPU_INTRPT_ENABLE(); \
|
||||
core_sched(); \
|
||||
} while (0)
|
||||
#endif
|
||||
|
||||
#endif /* RHINO_CONFIG_DISABLE_INTRPT_STATS */
|
||||
|
||||
#endif /* K_CRITICAL_H */
|
||||
|
||||
314
csky/csi_kernel/rhino/core/include/k_default_config.h
Normal file
314
csky/csi_kernel/rhino/core/include/k_default_config.h
Normal file
@@ -0,0 +1,314 @@
|
||||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#ifndef K_DEFAULT_CONFIG_H
|
||||
#define K_DEFAULT_CONFIG_H
|
||||
|
||||
#ifndef RHINO_CONFIG_CPU_PWR_MGMT
|
||||
#define RHINO_CONFIG_CPU_PWR_MGMT 0
|
||||
#endif
|
||||
|
||||
/* leave this option as default unless your compiler does not support 64 bit data such as uint64_t */
|
||||
#ifndef RHINO_CONFIG_64_BIT_TYPE
|
||||
#define RHINO_CONFIG_64_BIT_TYPE 1
|
||||
#endif
|
||||
|
||||
/* chip level conf */
|
||||
#ifndef RHINO_CONFIG_LITTLE_ENDIAN
|
||||
#define RHINO_CONFIG_LITTLE_ENDIAN 1
|
||||
#endif
|
||||
|
||||
#ifndef RHINO_CONFIG_CPU_STACK_DOWN
|
||||
#define RHINO_CONFIG_CPU_STACK_DOWN 1
|
||||
#endif
|
||||
|
||||
#ifndef RHINO_CONFIG_BITMAP_HW
|
||||
#define RHINO_CONFIG_BITMAP_HW 0
|
||||
#endif
|
||||
|
||||
/* kernel feature conf */
|
||||
#ifndef RHINO_CONFIG_SEM
|
||||
#define RHINO_CONFIG_SEM 0
|
||||
#endif
|
||||
|
||||
#ifndef RHINO_CONFIG_QUEUE
|
||||
#define RHINO_CONFIG_QUEUE 0
|
||||
#endif
|
||||
|
||||
#ifndef RHINO_CONFIG_TASK_SEM
|
||||
#define RHINO_CONFIG_TASK_SEM 0
|
||||
#endif
|
||||
|
||||
#ifndef RHINO_CONFIG_WORKQUEUE
|
||||
#define RHINO_CONFIG_WORKQUEUE 0
|
||||
#endif
|
||||
|
||||
#ifndef RHINO_CONFIG_WORKQUEUE_STACK_SIZE
|
||||
#define RHINO_CONFIG_WORKQUEUE_STACK_SIZE 512
|
||||
#endif
|
||||
|
||||
#ifndef RHINO_CONFIG_WORKQUEUE_TASK_PRIO
|
||||
#define RHINO_CONFIG_WORKQUEUE_TASK_PRIO 9
|
||||
#endif
|
||||
|
||||
#ifndef RHINO_CONFIG_EVENT_FLAG
|
||||
#define RHINO_CONFIG_EVENT_FLAG 0
|
||||
#endif
|
||||
|
||||
#ifndef RHINO_CONFIG_TIMER
|
||||
#define RHINO_CONFIG_TIMER 0
|
||||
#endif
|
||||
|
||||
#ifndef RHINO_CONFIG_BUF_QUEUE
|
||||
#define RHINO_CONFIG_BUF_QUEUE 0
|
||||
#endif
|
||||
|
||||
#ifndef RHINO_CONFIG_MM_BLK
|
||||
#define RHINO_CONFIG_MM_BLK 1
|
||||
#endif
|
||||
|
||||
#ifndef RHINO_CONFIG_MM_TLF
|
||||
#define RHINO_CONFIG_MM_TLF 1
|
||||
#endif
|
||||
|
||||
#ifndef RHINO_CONFIG_MM_MAXMSIZEBIT
|
||||
#define RHINO_CONFIG_MM_MAXMSIZEBIT 20
|
||||
#endif
|
||||
|
||||
#ifndef RHINO_CONFIG_MM_TLF_BLK_SIZE
|
||||
#define RHINO_CONFIG_MM_TLF_BLK_SIZE 8192
|
||||
#endif
|
||||
|
||||
#ifndef RHINO_CONFIG_MM_DEBUG
|
||||
#define RHINO_CONFIG_MM_DEBUG 0
|
||||
#endif
|
||||
|
||||
#ifndef RHINO_CONFIG_GCC_RETADDR
|
||||
#define RHINO_CONFIG_GCC_RETADDR 0
|
||||
#endif
|
||||
|
||||
#ifndef RHINO_CONFIG_MM_LEAKCHECK
|
||||
#define RHINO_CONFIG_MM_LEAKCHECK 0
|
||||
#endif
|
||||
|
||||
#ifndef K_MM_STATISTIC
|
||||
#define K_MM_STATISTIC 0
|
||||
#endif
|
||||
|
||||
#ifndef RHINO_CONFIG_TASK_SEM
|
||||
#define RHINO_CONFIG_TASK_SEM 0
|
||||
#endif
|
||||
|
||||
/* kernel task conf */
|
||||
#ifndef RHINO_CONFIG_TASK_PRI_CHG
|
||||
#define RHINO_CONFIG_TASK_PRI_CHG 1
|
||||
#endif
|
||||
|
||||
#ifndef RHINO_CONFIG_TASK_INFO
|
||||
#define RHINO_CONFIG_TASK_INFO 0
|
||||
#endif
|
||||
|
||||
#ifndef RHINO_CONFIG_TASK_INFO_NUM
|
||||
#define RHINO_CONFIG_TASK_INFO_NUM 2
|
||||
#endif
|
||||
|
||||
#ifndef RHINO_CONFIG_TASK_DEL
|
||||
#define RHINO_CONFIG_TASK_DEL 0
|
||||
#endif
|
||||
|
||||
#ifndef RHINO_CONFIG_TASK_STACK_CUR_CHECK
|
||||
#define RHINO_CONFIG_TASK_STACK_CUR_CHECK 0
|
||||
#endif
|
||||
|
||||
#ifndef RHINO_CONFIG_TASK_WAIT_ABORT
|
||||
#define RHINO_CONFIG_TASK_WAIT_ABORT 0
|
||||
#endif
|
||||
|
||||
#ifndef RHINO_CONFIG_SCHED_RR
|
||||
#define RHINO_CONFIG_SCHED_RR 0
|
||||
#endif
|
||||
|
||||
#ifndef RHINO_CONFIG_TIME_SLICE_DEFAULT
|
||||
#define RHINO_CONFIG_TIME_SLICE_DEFAULT 50
|
||||
#endif
|
||||
|
||||
#ifndef RHINO_CONFIG_PRI_MAX
|
||||
#define RHINO_CONFIG_PRI_MAX 62
|
||||
#endif
|
||||
|
||||
#ifndef RHINO_CONFIG_USER_PRI_MAX
|
||||
#define RHINO_CONFIG_USER_PRI_MAX (RHINO_CONFIG_PRI_MAX - 2)
|
||||
#endif
|
||||
|
||||
#ifndef RHINO_CONFIG_RINGBUF_VENDOR
|
||||
#define RHINO_CONFIG_RINGBUF_VENDOR 0
|
||||
#endif
|
||||
|
||||
/* kernel mm_region conf */
|
||||
#ifndef RHINO_CONFIG_MM_REGION_MUTEX
|
||||
#define RHINO_CONFIG_MM_REGION_MUTEX 1
|
||||
#endif
|
||||
|
||||
/* kernel timer&tick conf */
|
||||
#ifndef RHINO_CONFIG_HW_COUNT
|
||||
#define RHINO_CONFIG_HW_COUNT 0
|
||||
#endif
|
||||
|
||||
#ifndef RHINO_CONFIG_TICKS_PER_SECOND
|
||||
#define RHINO_CONFIG_TICKS_PER_SECOND 100
|
||||
#endif
|
||||
|
||||
#ifndef RHINO_CONFIG_TIMER_TASK_STACK_SIZE
|
||||
#define RHINO_CONFIG_TIMER_TASK_STACK_SIZE 200
|
||||
#endif
|
||||
|
||||
#ifndef RHINO_CONFIG_TIMER_RATE
|
||||
#define RHINO_CONFIG_TIMER_RATE 1
|
||||
#endif
|
||||
|
||||
#ifndef RHINO_CONFIG_TIMER_TASK_PRI
|
||||
#define RHINO_CONFIG_TIMER_TASK_PRI 5
|
||||
#endif
|
||||
|
||||
#ifndef RHINO_CONFIG_TIMER_MSG_NUM
|
||||
#define RHINO_CONFIG_TIMER_MSG_NUM 20
|
||||
#endif
|
||||
|
||||
/* kernel intrpt conf */
|
||||
#ifndef RHINO_CONFIG_INTRPT_STACK_REMAIN_GET
|
||||
#define RHINO_CONFIG_INTRPT_STACK_REMAIN_GET 0
|
||||
#endif
|
||||
|
||||
#ifndef RHINO_CONFIG_INTRPT_MAX_NESTED_LEVEL
|
||||
#define RHINO_CONFIG_INTRPT_MAX_NESTED_LEVEL 188u
|
||||
#endif
|
||||
|
||||
#ifndef RHINO_CONFIG_INTRPT_GUARD
|
||||
#define RHINO_CONFIG_INTRPT_GUARD 0
|
||||
#endif
|
||||
|
||||
/* kernel stack ovf check */
|
||||
#ifndef RHINO_CONFIG_INTRPT_STACK_OVF_CHECK
|
||||
#define RHINO_CONFIG_INTRPT_STACK_OVF_CHECK 0
|
||||
#endif
|
||||
|
||||
#ifndef RHINO_CONFIG_TASK_STACK_OVF_CHECK
|
||||
#define RHINO_CONFIG_TASK_STACK_OVF_CHECK 0
|
||||
#endif
|
||||
|
||||
/* kernel dyn alloc conf */
|
||||
#ifndef RHINO_CONFIG_KOBJ_DYN_ALLOC
|
||||
#define RHINO_CONFIG_KOBJ_DYN_ALLOC 0
|
||||
#endif
|
||||
|
||||
#if (RHINO_CONFIG_KOBJ_DYN_ALLOC > 0)
|
||||
|
||||
#ifndef RHINO_CONFIG_K_DYN_QUEUE_MSG
|
||||
#define RHINO_CONFIG_K_DYN_QUEUE_MSG 30
|
||||
#endif
|
||||
|
||||
#ifndef RHINO_CONFIG_K_DYN_TASK_STACK
|
||||
#define RHINO_CONFIG_K_DYN_TASK_STACK 256
|
||||
#endif
|
||||
|
||||
#ifndef RHINO_CONFIG_K_DYN_MEM_TASK_PRI
|
||||
#define RHINO_CONFIG_K_DYN_MEM_TASK_PRI RHINO_CONFIG_USER_PRI_MAX
|
||||
#endif
|
||||
|
||||
#endif /* RHINO_CONFIG_KOBJ_DYN_ALLOC */
|
||||
|
||||
/* kernel idle conf */
|
||||
#ifndef RHINO_CONFIG_IDLE_TASK_STACK_SIZE
|
||||
#define RHINO_CONFIG_IDLE_TASK_STACK_SIZE 100
|
||||
#endif
|
||||
|
||||
/* kernel hook conf */
|
||||
#ifndef RHINO_CONFIG_USER_HOOK
|
||||
#define RHINO_CONFIG_USER_HOOK 1
|
||||
#endif
|
||||
|
||||
/* kernel stats conf */
|
||||
#ifndef RHINO_CONFIG_SYSTEM_STATS
|
||||
#define RHINO_CONFIG_SYSTEM_STATS 0
|
||||
#endif
|
||||
|
||||
#ifndef RHINO_CONFIG_DISABLE_SCHED_STATS
|
||||
#define RHINO_CONFIG_DISABLE_SCHED_STATS 0
|
||||
#endif
|
||||
|
||||
#ifndef RHINO_CONFIG_DISABLE_INTRPT_STATS
|
||||
#define RHINO_CONFIG_DISABLE_INTRPT_STATS 0
|
||||
#endif
|
||||
|
||||
#ifndef RHINO_CONFIG_CPU_USAGE_STATS
|
||||
#define RHINO_CONFIG_CPU_USAGE_STATS 0
|
||||
#endif
|
||||
|
||||
#ifndef RHINO_CONFIG_CPU_USAGE_TASK_PRI
|
||||
#define RHINO_CONFIG_CPU_USAGE_TASK_PRI (RHINO_CONFIG_PRI_MAX - 2)
|
||||
#endif
|
||||
|
||||
#ifndef RHINO_CONFIG_TASK_SCHED_STATS
|
||||
#define RHINO_CONFIG_TASK_SCHED_STATS 0
|
||||
#endif
|
||||
|
||||
#ifndef RHINO_CONFIG_CPU_USAGE_TASK_STACK
|
||||
#define RHINO_CONFIG_CPU_USAGE_TASK_STACK 256
|
||||
#endif
|
||||
|
||||
/* kernel trace conf */
|
||||
#ifndef RHINO_CONFIG_TRACE
|
||||
#define RHINO_CONFIG_TRACE 0
|
||||
#endif
|
||||
|
||||
#ifndef RHINO_CONFIG_CPU_NUM
|
||||
#define RHINO_CONFIG_CPU_NUM 1
|
||||
#endif
|
||||
|
||||
#ifdef RHINO_CONFIG_ISR_TASK
|
||||
#ifndef RHINO_CONFIG_ISR_BUFF_SIZE
|
||||
#define RHINO_CONFIG_ISR_BUFF_SIZE (16)
|
||||
#endif
|
||||
#ifndef RHINO_CONFIG_ISR_TASK_PRI
|
||||
#define RHINO_CONFIG_ISR_TASK_PRI (1)
|
||||
#endif
|
||||
#ifndef RHINO_CONFIG_ISR_TASK_STACK_SIZE
|
||||
#define RHINO_CONFIG_ISR_TASK_STACK_SIZE (1024)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if ((RHINO_CONFIG_TIMER >= 1) && (RHINO_CONFIG_BUF_QUEUE == 0))
|
||||
#error "RHINO_CONFIG_BUF_QUEUE should be 1 when RHINO_CONFIG_TIMER is enabled."
|
||||
#endif
|
||||
|
||||
#if ((RHINO_CONFIG_MM_TLF >= 1) && (RHINO_CONFIG_MM_BLK == 0))
|
||||
#error "RHINO_CONFIG_MM_BLK should be 1 when RHINO_CONFIG_MM_TLF is enabled."
|
||||
#endif
|
||||
|
||||
#if ((RHINO_CONFIG_KOBJ_DYN_ALLOC >= 1) && (RHINO_CONFIG_MM_TLF == 0))
|
||||
#error "RHINO_CONFIG_MM_TLF should be 1 when RHINO_CONFIG_KOBJ_DYN_ALLOC is enabled."
|
||||
#endif
|
||||
|
||||
#if (RHINO_CONFIG_PRI_MAX >= 256)
|
||||
#error "RHINO_CONFIG_PRI_MAX must be <= 255."
|
||||
#endif
|
||||
|
||||
#if ((RHINO_CONFIG_SEM == 0) && (RHINO_CONFIG_TASK_SEM >= 1))
|
||||
#error "you need enable RHINO_CONFIG_SEM as well."
|
||||
#endif
|
||||
|
||||
#if ((RHINO_CONFIG_HW_COUNT == 0) && (RHINO_CONFIG_TASK_SCHED_STATS >= 1))
|
||||
#error "you need enable RHINO_CONFIG_HW_COUNT as well."
|
||||
#endif
|
||||
|
||||
#if ((RHINO_CONFIG_HW_COUNT == 0) && (RHINO_CONFIG_DISABLE_SCHED_STATS >= 1))
|
||||
#error "you need enable RHINO_CONFIG_HW_COUNT as well."
|
||||
#endif
|
||||
|
||||
#if ((RHINO_CONFIG_HW_COUNT == 0) && (RHINO_CONFIG_DISABLE_INTRPT_STATS >= 1))
|
||||
#error "you need enable RHINO_CONFIG_HW_COUNT as well."
|
||||
#endif
|
||||
|
||||
#endif /* K_DEFAULT_CONFIG_H */
|
||||
|
||||
46
csky/csi_kernel/rhino/core/include/k_endian.h
Normal file
46
csky/csi_kernel/rhino/core/include/k_endian.h
Normal file
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#ifndef K_ENDIAN_H
|
||||
#define K_ENDIAN_H
|
||||
|
||||
#if (RHINO_CONFIG_LITTLE_ENDIAN != 1)
|
||||
|
||||
#define krhino_htons(x) x
|
||||
#define krhino_htonl(x) x
|
||||
#define krhino_ntohl(x) x
|
||||
#define krhino_ntohs(x) x
|
||||
|
||||
#else
|
||||
|
||||
#ifndef krhino_htons
|
||||
#define krhino_htons(x) ((uint16_t)(((x) & 0x00ffU) << 8)| \
|
||||
(((x) & 0xff00U) >> 8))
|
||||
#endif
|
||||
|
||||
#ifndef krhino_htonl
|
||||
#define krhino_htonl(x) ((uint32_t)(((x) & 0x000000ffUL) << 24) | \
|
||||
(((x) & 0x0000ff00UL) << 8) | \
|
||||
(((x) & 0x00ff0000UL) >> 8) | \
|
||||
(((x) & 0xff000000UL) >> 24))
|
||||
#endif
|
||||
|
||||
#ifndef krhino_ntohs
|
||||
#define krhino_ntohs(x) ((uint16_t)((x & 0x00ffU) << 8) | \
|
||||
((x & 0xff00U) >> 8))
|
||||
#endif
|
||||
|
||||
#ifndef krhino_ntohl
|
||||
#define krhino_ntohl(x) ((uint32_t)(((x) & 0x000000ffUL) << 24) | \
|
||||
(((x) & 0x0000ff00UL) << 8) | \
|
||||
(((x) & 0x00ff0000UL) >> 8) | \
|
||||
(((x) & 0xff000000UL) >> 24))
|
||||
#endif
|
||||
|
||||
|
||||
#endif /*RHINO_CONFIG_LITTLE_ENDIAN*/
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
95
csky/csi_kernel/rhino/core/include/k_err.h
Normal file
95
csky/csi_kernel/rhino/core/include/k_err.h
Normal file
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#ifndef K_ERR_H
|
||||
#define K_ERR_H
|
||||
|
||||
typedef enum {
|
||||
RHINO_SUCCESS = 0u,
|
||||
RHINO_SYS_FATAL_ERR,
|
||||
RHINO_SYS_SP_ERR,
|
||||
RHINO_RUNNING,
|
||||
RHINO_STOPPED,
|
||||
RHINO_INV_PARAM,
|
||||
RHINO_NULL_PTR,
|
||||
RHINO_INV_ALIGN,
|
||||
RHINO_KOBJ_TYPE_ERR,
|
||||
RHINO_KOBJ_DEL_ERR,
|
||||
RHINO_KOBJ_DOCKER_EXIST,
|
||||
RHINO_KOBJ_BLK,
|
||||
RHINO_KOBJ_SET_FULL,
|
||||
RHINO_NOTIFY_FUNC_EXIST,
|
||||
|
||||
RHINO_MM_POOL_SIZE_ERR = 100u,
|
||||
RHINO_MM_ALLOC_SIZE_ERR,
|
||||
RHINO_MM_FREE_ADDR_ERR,
|
||||
RHINO_MM_CORRUPT_ERR,
|
||||
RHINO_DYN_MEM_PROC_ERR,
|
||||
RHINO_NO_MEM,
|
||||
RHINO_RINGBUF_FULL,
|
||||
RHINO_RINGBUF_EMPTY,
|
||||
|
||||
RHINO_SCHED_DISABLE = 200u,
|
||||
RHINO_SCHED_ALREADY_ENABLED,
|
||||
RHINO_SCHED_LOCK_COUNT_OVF,
|
||||
RHINO_INV_SCHED_WAY,
|
||||
|
||||
RHINO_TASK_INV_STACK_SIZE = 300u,
|
||||
RHINO_TASK_NOT_SUSPENDED,
|
||||
RHINO_TASK_DEL_NOT_ALLOWED,
|
||||
RHINO_TASK_SUSPEND_NOT_ALLOWED,
|
||||
RHINO_SUSPENDED_COUNT_OVF,
|
||||
RHINO_BEYOND_MAX_PRI,
|
||||
RHINO_PRI_CHG_NOT_ALLOWED,
|
||||
RHINO_INV_TASK_STATE,
|
||||
RHINO_IDLE_TASK_EXIST,
|
||||
|
||||
RHINO_NO_PEND_WAIT = 400u,
|
||||
RHINO_BLK_ABORT,
|
||||
RHINO_BLK_TIMEOUT,
|
||||
RHINO_BLK_DEL,
|
||||
RHINO_BLK_INV_STATE,
|
||||
RHINO_BLK_POOL_SIZE_ERR,
|
||||
|
||||
RHINO_TIMER_STATE_INV = 500u,
|
||||
|
||||
RHINO_NO_THIS_EVENT_OPT = 600u,
|
||||
|
||||
RHINO_BUF_QUEUE_INV_SIZE = 700u,
|
||||
RHINO_BUF_QUEUE_SIZE_ZERO,
|
||||
RHINO_BUF_QUEUE_FULL,
|
||||
RHINO_BUF_QUEUE_MSG_SIZE_OVERFLOW,
|
||||
RHINO_QUEUE_FULL,
|
||||
RHINO_QUEUE_NOT_FULL,
|
||||
|
||||
RHINO_SEM_OVF = 800u,
|
||||
RHINO_SEM_TASK_WAITING,
|
||||
|
||||
RHINO_MUTEX_NOT_RELEASED_BY_OWNER = 900u,
|
||||
RHINO_MUTEX_OWNER_NESTED,
|
||||
RHINO_MUTEX_NESTED_OVF,
|
||||
|
||||
RHINO_INTRPT_NESTED_LEVEL_OVERFLOW = 1000u,
|
||||
RHINO_INV_INTRPT_NESTED_LEVEL,
|
||||
RHINO_NOT_CALLED_BY_INTRPT,
|
||||
RHINO_TRY_AGAIN,
|
||||
|
||||
RHINO_WORKQUEUE_EXIST = 1100u,
|
||||
RHINO_WORKQUEUE_NOT_EXIST,
|
||||
RHINO_WORKQUEUE_WORK_EXIST,
|
||||
RHINO_WORKQUEUE_BUSY,
|
||||
RHINO_WORKQUEUE_WORK_RUNNING,
|
||||
|
||||
RHINO_TASK_STACK_OVF = 1200u,
|
||||
RHINO_INTRPT_STACK_OVF,
|
||||
RHINO_INTRPT_ISR_OVF,
|
||||
|
||||
} kstat_t;
|
||||
|
||||
typedef void (*krhino_err_proc_t)(kstat_t err);
|
||||
|
||||
extern krhino_err_proc_t g_err_proc;
|
||||
|
||||
#endif /* K_ERR_H */
|
||||
|
||||
84
csky/csi_kernel/rhino/core/include/k_event.h
Normal file
84
csky/csi_kernel/rhino/core/include/k_event.h
Normal file
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#ifndef K_EVENT_H
|
||||
#define K_EVENT_H
|
||||
|
||||
typedef struct {
|
||||
blk_obj_t blk_obj;
|
||||
uint32_t flags;
|
||||
|
||||
#if (RHINO_CONFIG_SYSTEM_STATS > 0)
|
||||
klist_t event_item;
|
||||
#endif
|
||||
|
||||
uint8_t mm_alloc_flag;
|
||||
} kevent_t;
|
||||
|
||||
#define RHINO_FLAGS_AND_MASK 0x2u
|
||||
#define RHINO_FLAGS_CLEAR_MASK 0x1u
|
||||
|
||||
#define RHINO_AND 0x02u
|
||||
#define RHINO_AND_CLEAR 0x03u
|
||||
#define RHINO_OR 0x00u
|
||||
#define RHINO_OR_CLEAR 0x01u
|
||||
|
||||
/**
|
||||
* This function will create a event
|
||||
* @param[in] event pointer to the event
|
||||
* @param[in] name name of the event
|
||||
* @param[in] flags flags to be init
|
||||
* @return the operation status, RHINO_SUCCESS is OK, others is error
|
||||
*/
|
||||
kstat_t krhino_event_create(kevent_t *event, const name_t *name, uint32_t flags);
|
||||
|
||||
/**
|
||||
* This function will delete a event
|
||||
* @param[in] event pointer to a event
|
||||
* @return the operation status, RHINO_SUCCESS is OK, others is error
|
||||
*/
|
||||
kstat_t krhino_event_del(kevent_t *event);
|
||||
|
||||
#if (RHINO_CONFIG_KOBJ_DYN_ALLOC > 0)
|
||||
/**
|
||||
* This function will create a dyn-event
|
||||
* @param[out] event pointer to the event
|
||||
* @param[in] name name of the semaphore
|
||||
* @param[in] flags flags to be init
|
||||
* @return the operation status, RHINO_SUCCESS is OK, others is error
|
||||
*/
|
||||
kstat_t krhino_event_dyn_create(kevent_t **event, const name_t *name,
|
||||
uint32_t flags);
|
||||
|
||||
/**
|
||||
* This function will delete a dyn created event
|
||||
* @param[in] event pointer to a event
|
||||
* @return the operation status, RHINO_SUCCESS is OK, others is error
|
||||
*/
|
||||
kstat_t krhino_event_dyn_del(kevent_t *event);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This function will get event
|
||||
* @param[in] event pointer to the event
|
||||
* @param[in] flags which is provided by users
|
||||
* @param[in] opt could be RHINO_AND, RHINO_AND_CLEAR, RHINO_OR, RHINO_OR_CLEAR
|
||||
* @param[out] actl_flags the actually flag where flags is satisfied
|
||||
* @param[in] ticks ticks to wait
|
||||
* @return the operation status, RHINO_SUCCESS is OK, others is error
|
||||
*/
|
||||
kstat_t krhino_event_get(kevent_t *event, uint32_t flags, uint8_t opt,
|
||||
uint32_t *actl_flags, tick_t ticks);
|
||||
|
||||
/**
|
||||
* This function will set a event
|
||||
* @param[in] event pointer to a event
|
||||
* @param[in] flags which users want to be set
|
||||
* @param[in] opt could be RHINO_AND, RHINO_OR
|
||||
* @return the operation status, RHINO_SUCCESS is OK, others is error
|
||||
*/
|
||||
kstat_t krhino_event_set(kevent_t *event, uint32_t flags, uint8_t opt);
|
||||
|
||||
#endif /* K_EVENT_H */
|
||||
|
||||
76
csky/csi_kernel/rhino/core/include/k_fifo.h
Normal file
76
csky/csi_kernel/rhino/core/include/k_fifo.h
Normal file
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#ifndef FIFO_H
|
||||
#define FIFO_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct k_fifo {
|
||||
|
||||
uint32_t in;
|
||||
uint32_t out;
|
||||
uint32_t mask;
|
||||
void *data;
|
||||
uint32_t free_bytes;
|
||||
uint32_t size;
|
||||
|
||||
};
|
||||
|
||||
#define fifo_min(x, y) ((x) > (y)?(y):(x))
|
||||
#define fifo_max(x, y) ((x) > (y)?(x):(y))
|
||||
|
||||
/**
|
||||
* This function will init the fifo.
|
||||
* @param[in] fifo pointer to fifo
|
||||
* @param[in] buffer pointer to fifo buffer
|
||||
* @param[in] size size of fifo buffer
|
||||
* @return the operation status, 0 is OK, others is error
|
||||
*/
|
||||
int8_t fifo_init(struct k_fifo *fifo, void *buffer, uint32_t size);
|
||||
|
||||
/**
|
||||
* This function will write buf to fifo.
|
||||
* @param[in] fifo pointer to fifo
|
||||
* @param[in] buf pointer to buffer write
|
||||
* @param[in] size size of buffer
|
||||
* @return the size has been written to the fifo
|
||||
*/
|
||||
uint32_t fifo_in(struct k_fifo *fifo, const void *buf, uint32_t len);
|
||||
|
||||
/**
|
||||
* This function will read fifo data to buf
|
||||
* @param[in] fifo pointer to fifo
|
||||
* @param[in] buf pointer to buffer read
|
||||
* @param[in] len len of buffer
|
||||
* @return the size has read
|
||||
*/
|
||||
uint32_t fifo_out(struct k_fifo *fifo, void *buf, uint32_t len);
|
||||
|
||||
/**
|
||||
* This function will read fifo data to buf,but data remain in fifo
|
||||
* @param[in] fifo pointer to fifo
|
||||
* @param[in] buf pointer to buffer read
|
||||
* @param[in] len len of buffer
|
||||
* @return the size has read
|
||||
*/
|
||||
uint32_t fifo_out_peek(struct k_fifo *fifo,
|
||||
void *buf, uint32_t len);
|
||||
|
||||
/**
|
||||
* This function will read fifo all data
|
||||
* @param[in] fifo pointer to fifo
|
||||
* @param[in] buf pointer to buffer read
|
||||
* @return the size has read
|
||||
*/
|
||||
uint32_t fifo_out_all(struct k_fifo *fifo, void *buf);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
64
csky/csi_kernel/rhino/core/include/k_hook.h
Normal file
64
csky/csi_kernel/rhino/core/include/k_hook.h
Normal file
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#ifndef K_HOOK_H
|
||||
#define K_HOOK_H
|
||||
|
||||
#if (RHINO_CONFIG_USER_HOOK > 0)
|
||||
/**
|
||||
* This function will provide init hook
|
||||
*/
|
||||
void krhino_init_hook(void);
|
||||
|
||||
/**
|
||||
* This function will provide system start hook
|
||||
*/
|
||||
void krhino_start_hook(void);
|
||||
|
||||
/**
|
||||
* This function will provide task create hook
|
||||
* @param[in] task pointer to the task
|
||||
*/
|
||||
void krhino_task_create_hook(ktask_t *task);
|
||||
|
||||
/**
|
||||
* This function will provide task delete hook
|
||||
* @param[in] task pointer to the task
|
||||
*/
|
||||
void krhino_task_del_hook(ktask_t *task, res_free_t *arg);
|
||||
|
||||
/**
|
||||
* This function will provide task abort hook
|
||||
* @param[in] task pointer to the task
|
||||
*/
|
||||
void krhino_task_abort_hook(ktask_t *task);
|
||||
|
||||
/**
|
||||
* This function will provide task switch hook
|
||||
*/
|
||||
void krhino_task_switch_hook(ktask_t *orgin, ktask_t *dest);
|
||||
|
||||
/**
|
||||
* This function will provide system tick hook
|
||||
*/
|
||||
void krhino_tick_hook(void);
|
||||
|
||||
/**
|
||||
* This function will provide idle hook
|
||||
*/
|
||||
void krhino_idle_hook(void);
|
||||
|
||||
/**
|
||||
* This function will provide idle pre hook
|
||||
*/
|
||||
void krhino_idle_pre_hook(void);
|
||||
|
||||
/**
|
||||
* This function will provide krhino_mm_alloc hook
|
||||
*/
|
||||
void krhino_mm_alloc_hook(void *mem, size_t size);
|
||||
#endif
|
||||
|
||||
#endif /* K_HOOK_H */
|
||||
|
||||
193
csky/csi_kernel/rhino/core/include/k_internal.h
Normal file
193
csky/csi_kernel/rhino/core/include/k_internal.h
Normal file
@@ -0,0 +1,193 @@
|
||||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#ifndef K_INTERNAL_H
|
||||
#define K_INTERNAL_H
|
||||
|
||||
extern kstat_t g_sys_stat;
|
||||
extern uint8_t g_idle_task_spawned[RHINO_CONFIG_CPU_NUM];
|
||||
|
||||
extern runqueue_t g_ready_queue;
|
||||
|
||||
/* System lock */
|
||||
extern uint8_t g_sched_lock[RHINO_CONFIG_CPU_NUM];
|
||||
extern uint8_t g_intrpt_nested_level[RHINO_CONFIG_CPU_NUM];
|
||||
|
||||
/* highest pri ready task object */
|
||||
extern ktask_t *g_preferred_ready_task[RHINO_CONFIG_CPU_NUM];
|
||||
|
||||
/* current active task */
|
||||
extern ktask_t *g_active_task[RHINO_CONFIG_CPU_NUM];
|
||||
|
||||
/* idle attribute */
|
||||
extern ktask_t g_idle_task[RHINO_CONFIG_CPU_NUM];
|
||||
extern idle_count_t g_idle_count[RHINO_CONFIG_CPU_NUM];
|
||||
extern cpu_stack_t g_idle_task_stack[RHINO_CONFIG_CPU_NUM][RHINO_CONFIG_IDLE_TASK_STACK_SIZE];
|
||||
|
||||
/* tick attribute */
|
||||
extern tick_t g_tick_count;
|
||||
extern klist_t g_tick_head;
|
||||
|
||||
#if (RHINO_CONFIG_SYSTEM_STATS > 0)
|
||||
extern kobj_list_t g_kobj_list;
|
||||
#endif
|
||||
|
||||
#if (RHINO_CONFIG_TIMER > 0)
|
||||
extern klist_t g_timer_head;
|
||||
extern sys_time_t g_timer_count;
|
||||
extern ktask_t g_timer_task;
|
||||
extern cpu_stack_t g_timer_task_stack[RHINO_CONFIG_TIMER_TASK_STACK_SIZE];
|
||||
extern kbuf_queue_t g_timer_queue;
|
||||
extern k_timer_queue_cb timer_queue_cb[RHINO_CONFIG_TIMER_MSG_NUM];
|
||||
#endif
|
||||
|
||||
#if (RHINO_CONFIG_DISABLE_SCHED_STATS > 0)
|
||||
extern hr_timer_t g_sched_disable_time_start;
|
||||
extern hr_timer_t g_sched_disable_max_time;
|
||||
extern hr_timer_t g_cur_sched_disable_max_time;
|
||||
#endif
|
||||
|
||||
#if (RHINO_CONFIG_DISABLE_INTRPT_STATS > 0)
|
||||
extern uint16_t g_intrpt_disable_times;
|
||||
extern hr_timer_t g_intrpt_disable_time_start;
|
||||
extern hr_timer_t g_intrpt_disable_max_time;
|
||||
extern hr_timer_t g_cur_intrpt_disable_max_time;
|
||||
#endif
|
||||
|
||||
#if (RHINO_CONFIG_HW_COUNT > 0)
|
||||
extern hr_timer_t g_sys_measure_waste;
|
||||
#endif
|
||||
|
||||
#if (RHINO_CONFIG_CPU_USAGE_STATS > 0)
|
||||
extern ktask_t g_cpu_usage_task;
|
||||
extern cpu_stack_t g_cpu_task_stack[RHINO_CONFIG_CPU_USAGE_TASK_STACK];
|
||||
extern idle_count_t g_idle_count_max;
|
||||
extern uint32_t g_cpu_usage;
|
||||
#endif
|
||||
|
||||
#if (RHINO_CONFIG_TASK_SCHED_STATS > 0)
|
||||
extern ctx_switch_t g_sys_ctx_switch_times;
|
||||
#endif
|
||||
|
||||
#if (RHINO_CONFIG_KOBJ_DYN_ALLOC > 0)
|
||||
extern ksem_t g_res_sem;
|
||||
extern klist_t g_res_list;
|
||||
extern ktask_t g_dyn_task;
|
||||
extern cpu_stack_t g_dyn_task_stack[RHINO_CONFIG_K_DYN_TASK_STACK];
|
||||
#endif
|
||||
|
||||
#if (RHINO_CONFIG_WORKQUEUE > 0)
|
||||
extern klist_t g_workqueue_list_head;
|
||||
extern kmutex_t g_workqueue_mutex;
|
||||
extern kworkqueue_t g_workqueue_default;
|
||||
extern cpu_stack_t g_workqueue_stack[RHINO_CONFIG_WORKQUEUE_STACK_SIZE];
|
||||
#endif
|
||||
|
||||
#if (RHINO_CONFIG_MM_TLF > 0)
|
||||
extern k_mm_head *g_kmm_head;
|
||||
#endif
|
||||
|
||||
#ifdef RHINO_CONFIG_ISR_TASK
|
||||
extern ktask_t g_isr_task;
|
||||
extern ksem_t g_isr_sem;
|
||||
extern uint32_t g_isr_buff[4+2*RHINO_CONFIG_ISR_BUFF_SIZE];
|
||||
extern cpu_stack_t g_isr_task_stack[RHINO_CONFIG_ISR_TASK_STACK_SIZE];
|
||||
#endif
|
||||
|
||||
extern kspinlock_t g_sys_lock;
|
||||
extern uint8_t g_in_interrupt;
|
||||
|
||||
#define K_OBJ_STATIC_ALLOC 1u
|
||||
#define K_OBJ_DYN_ALLOC 2u
|
||||
|
||||
#define NULL_PARA_CHK(para) \
|
||||
do { \
|
||||
if (para == NULL) { \
|
||||
return RHINO_NULL_PTR; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define INTRPT_NESTED_LEVEL_CHK()\
|
||||
do { \
|
||||
if (g_intrpt_nested_level[cpu_cur_get()] > 0u) { \
|
||||
RHINO_CRITICAL_EXIT(); \
|
||||
return RHINO_NOT_CALLED_BY_INTRPT; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define RES_FREE_NUM 4
|
||||
|
||||
typedef struct {
|
||||
uint8_t cnt;
|
||||
void *res[RES_FREE_NUM];
|
||||
klist_t res_list;
|
||||
} res_free_t;
|
||||
|
||||
void preferred_cpu_ready_task_get(runqueue_t *rq, uint8_t cpu_num);
|
||||
|
||||
void core_sched(void);
|
||||
void runqueue_init(runqueue_t *rq);
|
||||
|
||||
void ready_list_add(runqueue_t *rq, ktask_t *task);
|
||||
void ready_list_add_head(runqueue_t *rq, ktask_t *task);
|
||||
void ready_list_add_tail(runqueue_t *rq, ktask_t *task);
|
||||
void ready_list_rm(runqueue_t *rq, ktask_t *task);
|
||||
void ready_list_head_to_tail(runqueue_t *rq, ktask_t *task);
|
||||
|
||||
void time_slice_update(void);
|
||||
void timer_task_sched(void);
|
||||
|
||||
void pend_list_reorder(ktask_t *task);
|
||||
void pend_task_wakeup(ktask_t *task);
|
||||
void pend_to_blk_obj(blk_obj_t *blk_obj, ktask_t *task, tick_t timeout, uint32_t psr);
|
||||
void pend_task_rm(ktask_t *task);
|
||||
|
||||
kstat_t pend_state_end_proc(ktask_t *task);
|
||||
|
||||
void idle_task(void *p_arg);
|
||||
void idle_count_set(idle_count_t value);
|
||||
idle_count_t idle_count_get(void);
|
||||
|
||||
void tick_list_init(void);
|
||||
void tick_task_start(void);
|
||||
void tick_list_rm(ktask_t *task);
|
||||
void tick_list_insert(ktask_t *task, tick_t time);
|
||||
void tick_list_update(tick_i_t ticks);
|
||||
|
||||
uint8_t mutex_pri_limit(ktask_t *tcb, uint8_t pri);
|
||||
void mutex_task_pri_reset(ktask_t *tcb);
|
||||
uint8_t mutex_pri_look(ktask_t *tcb, kmutex_t *mutex_rel);
|
||||
|
||||
kstat_t task_pri_change(ktask_t *task, uint8_t new_pri);
|
||||
|
||||
void k_err_proc(kstat_t err);
|
||||
|
||||
void ktimer_init(void);
|
||||
void kisr_init(void);
|
||||
|
||||
|
||||
void intrpt_disable_measure_start(void);
|
||||
void intrpt_disable_measure_stop(void);
|
||||
void dyn_mem_proc_task_start(void);
|
||||
void cpu_usage_stats_start(void);
|
||||
void dym_mem_proc_hdl(void);
|
||||
|
||||
kstat_t ringbuf_init(k_ringbuf_t *p_ringbuf, void *buf, size_t len, size_t type,
|
||||
size_t block_size);
|
||||
kstat_t ringbuf_reset(k_ringbuf_t *p_ringbuf);
|
||||
kstat_t ringbuf_push(k_ringbuf_t *p_ringbuf, void *data, size_t len);
|
||||
kstat_t ringbuf_head_push(k_ringbuf_t *p_ringbuf, void *data, size_t len);
|
||||
kstat_t ringbuf_pop(k_ringbuf_t *p_ringbuf, void *pdata, size_t *plen);
|
||||
uint8_t ringbuf_is_full(k_ringbuf_t *p_ringbuf);
|
||||
uint8_t ringbuf_is_empty(k_ringbuf_t *p_ringbuf);
|
||||
void workqueue_init(void);
|
||||
//void k_mm_init(void);
|
||||
|
||||
#if (RHINO_CONFIG_CPU_PWR_MGMT > 0)
|
||||
void cpu_pwr_down(void);
|
||||
void cpu_pwr_up(void);
|
||||
#endif
|
||||
|
||||
#endif /* K_INTERNAL_H */
|
||||
|
||||
60
csky/csi_kernel/rhino/core/include/k_list.h
Normal file
60
csky/csi_kernel/rhino/core/include/k_list.h
Normal file
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#ifndef K_LIST_H
|
||||
#define K_LIST_H
|
||||
|
||||
typedef struct klist_s {
|
||||
struct klist_s *next;
|
||||
struct klist_s *prev;
|
||||
} klist_t;
|
||||
|
||||
#define krhino_list_entry(node, type, member) ((type *)((uint8_t *)(node) - (size_t)(&((type *)0)->member)))
|
||||
|
||||
RHINO_INLINE void klist_init(klist_t *list_head)
|
||||
{
|
||||
list_head->next = list_head;
|
||||
list_head->prev = list_head;
|
||||
}
|
||||
|
||||
RHINO_INLINE uint8_t is_klist_empty(klist_t *list)
|
||||
{
|
||||
return (list->next == list);
|
||||
}
|
||||
|
||||
RHINO_INLINE void klist_insert(klist_t *head, klist_t *element)
|
||||
{
|
||||
element->prev = head->prev;
|
||||
element->next = head;
|
||||
|
||||
head->prev->next = element;
|
||||
head->prev = element;
|
||||
}
|
||||
|
||||
RHINO_INLINE void klist_add(klist_t *head, klist_t *element)
|
||||
{
|
||||
element->prev = head;
|
||||
element->next = head->next;
|
||||
|
||||
head->next->prev = element;
|
||||
head->next = element;
|
||||
}
|
||||
|
||||
RHINO_INLINE void klist_rm(klist_t *element)
|
||||
{
|
||||
element->prev->next = element->next;
|
||||
element->next->prev = element->prev;
|
||||
}
|
||||
|
||||
RHINO_INLINE void klist_rm_init(klist_t *element)
|
||||
{
|
||||
element->prev->next = element->next;
|
||||
element->next->prev = element->prev;
|
||||
|
||||
element->next = element->prev = element;
|
||||
}
|
||||
|
||||
|
||||
#endif /* K_LIST_H */
|
||||
|
||||
153
csky/csi_kernel/rhino/core/include/k_mm.h
Normal file
153
csky/csi_kernel/rhino/core/include/k_mm.h
Normal file
@@ -0,0 +1,153 @@
|
||||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#ifndef K_MM_H
|
||||
#define K_MM_H
|
||||
|
||||
#ifdef HAVE_VALGRIND_H
|
||||
#include <valgrind.h>
|
||||
#include <memcheck.h>
|
||||
#define VGF(X) X
|
||||
#elif defined(HAVE_VALGRIND_VALGRIND_H)
|
||||
#include <valgrind/valgrind.h>
|
||||
#include <valgrind/memcheck.h>
|
||||
#define VGF(X) X
|
||||
#else
|
||||
#define VGF(X)
|
||||
#endif
|
||||
|
||||
|
||||
/*use two level bit map to find free memory block*/
|
||||
|
||||
#if (RHINO_CONFIG_MM_TLF > 0)
|
||||
#define MAX_MM_BIT RHINO_CONFIG_MM_MAXMSIZEBIT
|
||||
|
||||
#define MAX_MM_SIZE (1<<MAX_MM_BIT)
|
||||
#define FIX_BLK_BIT 5 /*32 bytes*/
|
||||
#define DEF_FIX_BLK_SIZE (1<<FIX_BLK_BIT) /*32 bytes*/
|
||||
#define MIN_FLT_BIT 7 /*<2^7 only need one level mapping */
|
||||
#define MIN_FLT_SIZE (1<<MIN_FLT_BIT)
|
||||
#define MAX_LOG2_SLT 5
|
||||
#define SLT_SIZE (1<<MAX_LOG2_SLT)
|
||||
#define FLT_SIZE (MAX_MM_BIT - MIN_FLT_BIT + 1)
|
||||
#define MM_ALIGIN_SIZE (1<<(MIN_FLT_BIT - MAX_LOG2_SLT))
|
||||
#define MM_ALIGN_MASK (sizeof(void*)-1)
|
||||
|
||||
#define MM_ALIGN_UP(a) (((a) + MM_ALIGN_MASK) & ~MM_ALIGN_MASK)
|
||||
#define MM_ALIGN_DOWN(a) ((a) & ~MM_ALIGN_MASK)
|
||||
|
||||
|
||||
#define RHINO_MM_BLKSIZE_MASK (0xFFFFFFFF - MM_ALIGN_MASK)
|
||||
|
||||
#define DEF_TOTAL_FIXEDBLK_SIZE 8192 /*by default, total 2k momory fo fix size block */
|
||||
#define MIN_FREE_MEMORY_SIZE 1024 /*at least need 1k for user alloced*/
|
||||
|
||||
|
||||
|
||||
/*bit 0 and bit 1 mask*/
|
||||
#define RHINO_MM_CURSTAT_MASK 0x1
|
||||
#define RHINO_MM_PRESTAT_MASK 0x2
|
||||
|
||||
/*bit 0*/
|
||||
#define RHINO_MM_FREE 1
|
||||
#define RHINO_MM_ALLOCED 0
|
||||
|
||||
/*bit 1*/
|
||||
#define RHINO_MM_PREVFREE 2
|
||||
#define RHINO_MM_PREVALLOCED 0
|
||||
|
||||
#define NEXT_MM_BLK(_addr, _r) ((k_mm_list_t *) ((uint8_t *) (_addr) + (_r)))
|
||||
|
||||
#define MMLIST_HEAD_SIZE (sizeof(k_mm_list_t) - sizeof(free_ptr_t))
|
||||
/*
|
||||
-------------------------------------------------------------------
|
||||
| k_mm_list_t |k_mm_region_info_t|k_mm_list_t|free space |k_mm_list_t|
|
||||
-------------------------------------------------------------------
|
||||
*/
|
||||
#define MMREGION_USED_SIZE (MM_ALIGN_UP(sizeof(k_mm_region_info_t)) + 3 * MMLIST_HEAD_SIZE )
|
||||
|
||||
/*struct of memory list ,every memory block include this information*/
|
||||
typedef struct free_ptr_struct {
|
||||
struct k_mm_list_struct *prev;
|
||||
struct k_mm_list_struct *next;
|
||||
} free_ptr_t;
|
||||
|
||||
typedef struct k_mm_list_struct {
|
||||
#if (RHINO_CONFIG_MM_DEBUG > 0)
|
||||
size_t dye;
|
||||
size_t owner;
|
||||
#endif
|
||||
struct k_mm_list_struct *prev;
|
||||
size_t size;
|
||||
/* bit 0 indicates whether the block is used and */
|
||||
/* bit 1 allows to know whether the previous block is free */
|
||||
union {
|
||||
struct free_ptr_struct free_ptr;
|
||||
uint8_t buffer[1];
|
||||
} mbinfo;
|
||||
} k_mm_list_t;
|
||||
|
||||
typedef struct k_mm_region_info_struct {
|
||||
k_mm_list_t *end;
|
||||
struct k_mm_region_info_struct *next;
|
||||
} k_mm_region_info_t;
|
||||
|
||||
|
||||
typedef struct {
|
||||
#if (RHINO_CONFIG_MM_REGION_MUTEX == 1)
|
||||
kmutex_t mm_mutex;
|
||||
#endif
|
||||
k_mm_region_info_t *regioninfo;
|
||||
k_mm_list_t *fixedmblk;
|
||||
|
||||
#if (K_MM_STATISTIC > 0)
|
||||
size_t used_size;
|
||||
size_t maxused_size;
|
||||
size_t free_size;
|
||||
size_t mm_size_stats[MAX_MM_BIT];
|
||||
#endif
|
||||
|
||||
uint32_t fl_bitmap;
|
||||
uint32_t sl_bitmap[FLT_SIZE]; /* the second-level bitmap */
|
||||
k_mm_list_t *mm_tbl[FLT_SIZE][SLT_SIZE];
|
||||
} k_mm_head;
|
||||
|
||||
|
||||
kstat_t krhino_init_mm_head(k_mm_head **ppmmhead, void *addr, size_t len );
|
||||
kstat_t krhino_deinit_mm_head(k_mm_head *mmhead);
|
||||
|
||||
kstat_t krhino_add_mm_region(k_mm_head *mmhead, void *addr, size_t len);
|
||||
|
||||
|
||||
void *k_mm_alloc(k_mm_head *mmhead, size_t size);
|
||||
void k_mm_free(k_mm_head *mmhead, void *ptr);
|
||||
void *k_mm_realloc(k_mm_head *mmhead, void *oldmem, size_t new_size);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This function is wrapper of mm allocation
|
||||
* @param[in] size size of the mem to malloc
|
||||
* @return the operation status, NULL is error, others is memory address
|
||||
*/
|
||||
void *krhino_mm_alloc(size_t size, void *caller);
|
||||
|
||||
/**
|
||||
* This function is wrapper of mm free
|
||||
* @param[in] ptr address point of the mem
|
||||
*/
|
||||
void krhino_mm_free(void *ptr);
|
||||
|
||||
|
||||
/**
|
||||
* This function is wrapper of mm rallocation
|
||||
* @param[in] oldmem oldmem address
|
||||
* @param[in] size size of the mem to malloc
|
||||
* @return the operation status, NULL is error, others is realloced memory address
|
||||
*/
|
||||
void *krhino_mm_realloc(void *oldmem, size_t newsize, void *caller);
|
||||
|
||||
|
||||
|
||||
#endif /* K_MM_BESTFIT_H */
|
||||
|
||||
50
csky/csi_kernel/rhino/core/include/k_mm_blk.h
Normal file
50
csky/csi_kernel/rhino/core/include/k_mm_blk.h
Normal file
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#ifndef K_MM_BLK_H
|
||||
#define K_MM_BLK_H
|
||||
|
||||
typedef struct {
|
||||
kobj_type_t obj_type;
|
||||
const name_t *pool_name;
|
||||
size_t blk_size;
|
||||
size_t blk_avail;
|
||||
size_t blk_whole;
|
||||
uint8_t *avail_list;
|
||||
#if (RHINO_CONFIG_SYSTEM_STATS > 0)
|
||||
klist_t mblkpool_stats_item;
|
||||
#endif
|
||||
} mblk_pool_t;
|
||||
|
||||
/**
|
||||
* This function will init a blk-pool
|
||||
* @param[in] pool pointer to the pool
|
||||
* @param[in] name name of the pool
|
||||
* @param[in] pool_start start addr of the pool
|
||||
* @param[in] blk_size size of the blk
|
||||
* @param[in] pool_size size of the pool
|
||||
* @return the operation status, RHINO_SUCCESS is OK, others is error
|
||||
*/
|
||||
kstat_t krhino_mblk_pool_init(mblk_pool_t *pool, const name_t *name,
|
||||
void *pool_start,
|
||||
size_t blk_size, size_t pool_size);
|
||||
|
||||
/**
|
||||
* This function will alloc a blk-pool
|
||||
* @param[in] pool pointer to a pool
|
||||
* @param[in] blk pointer to a blk
|
||||
* @return the operation status, RHINO_SUCCESS is OK, others is error
|
||||
*/
|
||||
kstat_t krhino_mblk_alloc(mblk_pool_t *pool, void **blk);
|
||||
|
||||
/**
|
||||
* This function will free a blk-pool
|
||||
* @param[in] pool pointer to the pool
|
||||
* @param[in] blk pointer to the blk
|
||||
* @return the operation status, RHINO_SUCCESS is OK, others is error
|
||||
*/
|
||||
kstat_t krhino_mblk_free(mblk_pool_t *pool, void *blk);
|
||||
|
||||
#endif /* K_MM_BLK_H */
|
||||
|
||||
40
csky/csi_kernel/rhino/core/include/k_mm_debug.h
Normal file
40
csky/csi_kernel/rhino/core/include/k_mm_debug.h
Normal file
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#ifndef RHINO_MM_DEBUG_H
|
||||
#define RHINO_MM_DEBUG_H
|
||||
|
||||
#if (RHINO_CONFIG_MM_DEBUG > 0)
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define AOS_MM_SCAN_REGION_MAX 10
|
||||
typedef struct {
|
||||
void *start;
|
||||
void *end;
|
||||
} mm_scan_region_t;
|
||||
|
||||
#if (RHINO_CONFIG_GCC_RETADDR > 0u)
|
||||
#include <k_mm.h>
|
||||
#define AOS_UNSIGNED_INT_MSB (1u << (sizeof(unsigned int) * 8 - 1))
|
||||
void krhino_owner_attach(k_mm_head *mmhead, void *addr, size_t allocator);
|
||||
#endif
|
||||
|
||||
uint32_t krhino_mm_leak_region_init(void *start, void *end);
|
||||
|
||||
uint32_t dumpsys_mm_info_func(char *buf, uint32_t len);
|
||||
|
||||
uint32_t dump_mmleak(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* RHINO_CONFIG_MM_DEBUG */
|
||||
|
||||
#endif /* YSH_H */
|
||||
|
||||
|
||||
14
csky/csi_kernel/rhino/core/include/k_mm_region.h
Normal file
14
csky/csi_kernel/rhino/core/include/k_mm_region.h
Normal file
@@ -0,0 +1,14 @@
|
||||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#ifndef K_MM_REGION_H
|
||||
#define K_MM_REGION_H
|
||||
|
||||
typedef struct {
|
||||
uint8_t *start;
|
||||
size_t len;
|
||||
} k_mm_region_t;
|
||||
|
||||
#endif /* K_MM_REGION_H */
|
||||
|
||||
69
csky/csi_kernel/rhino/core/include/k_mutex.h
Normal file
69
csky/csi_kernel/rhino/core/include/k_mutex.h
Normal file
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#ifndef K_MUTEX_H
|
||||
#define K_MUTEX_H
|
||||
|
||||
typedef struct mutex_s {
|
||||
blk_obj_t blk_obj;
|
||||
ktask_t *mutex_task; /* mutex owner task */
|
||||
struct mutex_s *mutex_list; /* task mutex list */
|
||||
mutex_nested_t owner_nested;
|
||||
|
||||
#if (RHINO_CONFIG_SYSTEM_STATS > 0)
|
||||
klist_t mutex_item;
|
||||
#endif
|
||||
|
||||
uint8_t mm_alloc_flag;
|
||||
} kmutex_t;
|
||||
|
||||
/**
|
||||
* This function will create a mutex
|
||||
* @param[in] mutex pointer to the mutex(the space is provided by user)
|
||||
* @param[in] name name of the mutex
|
||||
* @return the operation status, RHINO_SUCCESS is OK, others is error
|
||||
*/
|
||||
kstat_t krhino_mutex_create(kmutex_t *mutex, const name_t *name);
|
||||
|
||||
/**
|
||||
* This function will delete a mutex
|
||||
* @param[in] mutex pointer to the mutex
|
||||
* @return the operation status, RHINO_SUCCESS is OK, others is error
|
||||
*/
|
||||
kstat_t krhino_mutex_del(kmutex_t *mutex);
|
||||
|
||||
#if (RHINO_CONFIG_KOBJ_DYN_ALLOC > 0)
|
||||
/**
|
||||
* This function will create a dyn mutex
|
||||
* @param[in] mutex pointer to the mutex(the space is provided by user)
|
||||
* @param[in] name name of the mutex
|
||||
* @return the operation status, RHINO_SUCCESS is OK, others is error
|
||||
*/
|
||||
kstat_t krhino_mutex_dyn_create(kmutex_t **mutex, const name_t *name);
|
||||
|
||||
/**
|
||||
* This function will delete a dyn mutex
|
||||
* @param[in] mutex pointer to the mutex
|
||||
* @return the operation status, RHINO_SUCCESS is OK, others is error
|
||||
*/
|
||||
kstat_t krhino_mutex_dyn_del(kmutex_t *mutex);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This function will lock mutex
|
||||
* @param[in] mutex pointer to the mutex
|
||||
* @param[in] ticks ticks to be wait for before lock
|
||||
* @return the operation status, RHINO_SUCCESS is OK, others is error
|
||||
*/
|
||||
kstat_t krhino_mutex_lock(kmutex_t *mutex, tick_t ticks, uint32_t lr);
|
||||
|
||||
/**
|
||||
* This function will unlock a mutex
|
||||
* @param[in] mutex pointer to the mutex
|
||||
* @return the operation status, RHINO_SUCCESS is OK, others is error
|
||||
*/
|
||||
kstat_t krhino_mutex_unlock(kmutex_t *mutex);
|
||||
|
||||
#endif /* K_MUTEX_H */
|
||||
|
||||
67
csky/csi_kernel/rhino/core/include/k_obj.h
Normal file
67
csky/csi_kernel/rhino/core/include/k_obj.h
Normal file
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#ifndef K_OBJ_H
|
||||
#define K_OBJ_H
|
||||
|
||||
typedef enum {
|
||||
BLK_POLICY_PRI = 0u,
|
||||
BLK_POLICY_FIFO
|
||||
} blk_policy_t;
|
||||
|
||||
typedef enum {
|
||||
BLK_FINISH = 0,
|
||||
BLK_ABORT,
|
||||
BLK_TIMEOUT,
|
||||
BLK_DEL,
|
||||
BLK_INVALID
|
||||
} blk_state_t;
|
||||
|
||||
typedef enum {
|
||||
RHINO_OBJ_TYPE_NONE = 0,
|
||||
RHINO_SEM_OBJ_TYPE,
|
||||
RHINO_MUTEX_OBJ_TYPE,
|
||||
RHINO_QUEUE_OBJ_TYPE,
|
||||
RHINO_BUF_QUEUE_OBJ_TYPE,
|
||||
RHINO_TIMER_OBJ_TYPE,
|
||||
RHINO_EVENT_OBJ_TYPE,
|
||||
RHINO_MM_BLK_OBJ_TYPE,
|
||||
RHINO_MM_OBJ_TYPE,
|
||||
RHINO_BLKLIST_OBJ_TYPE,
|
||||
} kobj_type_t;
|
||||
|
||||
typedef struct blk_obj {
|
||||
klist_t blk_list;
|
||||
const name_t *name;
|
||||
uint8_t blk_policy; // blk_policy_t
|
||||
uint8_t obj_type; // blk_state_t
|
||||
} blk_obj_t;
|
||||
|
||||
typedef struct {
|
||||
klist_t task_head;
|
||||
klist_t mutex_head;
|
||||
|
||||
#if (RHINO_CONFIG_MM_BLK > 0)
|
||||
klist_t mblkpool_head;
|
||||
#endif
|
||||
|
||||
#if (RHINO_CONFIG_SEM > 0)
|
||||
klist_t sem_head;
|
||||
#endif
|
||||
|
||||
#if (RHINO_CONFIG_QUEUE > 0)
|
||||
klist_t queue_head;
|
||||
#endif
|
||||
|
||||
#if (RHINO_CONFIG_EVENT_FLAG > 0)
|
||||
klist_t event_head;
|
||||
#endif
|
||||
|
||||
#if (RHINO_CONFIG_BUF_QUEUE > 0)
|
||||
klist_t buf_queue_head;
|
||||
#endif
|
||||
} kobj_list_t;
|
||||
|
||||
#endif /* K_OBJ_H */
|
||||
|
||||
118
csky/csi_kernel/rhino/core/include/k_queue.h
Normal file
118
csky/csi_kernel/rhino/core/include/k_queue.h
Normal file
@@ -0,0 +1,118 @@
|
||||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#ifndef K_QUEUE_H
|
||||
#define K_QUEUE_H
|
||||
|
||||
#define WAKE_ONE_TASK 0u
|
||||
#define WAKE_ALL_TASK 1u
|
||||
|
||||
typedef struct {
|
||||
void **queue_start;
|
||||
size_t size;
|
||||
size_t cur_num;
|
||||
size_t peak_num;
|
||||
} msg_q_t;
|
||||
|
||||
typedef struct {
|
||||
msg_q_t msg_q;
|
||||
klist_t *pend_entry;
|
||||
} msg_info_t;
|
||||
|
||||
typedef struct queue_s {
|
||||
blk_obj_t blk_obj;
|
||||
k_ringbuf_t ringbuf;
|
||||
msg_q_t msg_q;
|
||||
#if (RHINO_CONFIG_SYSTEM_STATS > 0)
|
||||
klist_t queue_item;
|
||||
#endif
|
||||
uint8_t mm_alloc_flag;
|
||||
} kqueue_t;
|
||||
|
||||
/**
|
||||
* This function will create a queue
|
||||
* @param[in] queue pointer to the queue(the space is provided by user)
|
||||
* @param[in] name name of the queue
|
||||
* @param[in] start start address of the queue internal space
|
||||
* @param[in] msg_num num of the msg
|
||||
* @return the operation status, RHINO_SUCCESS is OK, others is error
|
||||
*/
|
||||
kstat_t krhino_queue_create(kqueue_t *queue, const name_t *name, void **start,
|
||||
size_t msg_num);
|
||||
|
||||
/**
|
||||
* This function will delete a queue
|
||||
* @param[in] queue pointer to the queue
|
||||
* @return the operation status, RHINO_SUCCESS is OK, others is error
|
||||
*/
|
||||
kstat_t krhino_queue_del(kqueue_t *queue);
|
||||
|
||||
#if (RHINO_CONFIG_KOBJ_DYN_ALLOC > 0)
|
||||
/**
|
||||
* This function will create a dyn queue
|
||||
* @param[in] queue pointer to the queue
|
||||
* @param[in] name name of the queue
|
||||
* @param[in] msg_num num of the msg
|
||||
* @return the operation status, RHINO_SUCCESS is OK, others is error
|
||||
*/
|
||||
kstat_t krhino_queue_dyn_create(kqueue_t **queue, const name_t *name,
|
||||
size_t msg_num);
|
||||
|
||||
/**
|
||||
* This function will delete a dyn created queue
|
||||
* @param[in] queue pointer to the queue
|
||||
* @return the operation status, RHINO_SUCCESS is OK, others is error
|
||||
*/
|
||||
kstat_t krhino_queue_dyn_del(kqueue_t *queue);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This function will send a msg to the back of a queue
|
||||
* @param[in] queue pointer to the queue
|
||||
* @param[in] msg msg to send
|
||||
* @return the operation status, RHINO_SUCCESS is OK, others is error
|
||||
*/
|
||||
kstat_t krhino_queue_back_send(kqueue_t *queue, void *msg);
|
||||
|
||||
/**
|
||||
* This function will send a msg to a queue and wake all tasks
|
||||
* @param[in] queue pointer to the queue
|
||||
* @param[in] msg msg to send
|
||||
* @return the operation status, RHINO_SUCCESS is OK, others is error
|
||||
*/
|
||||
kstat_t krhino_queue_all_send(kqueue_t *queue, void *msg);
|
||||
|
||||
/**
|
||||
* This function will receive msg from a queue
|
||||
* @param[in] queue pointer to the queue
|
||||
* @param[in] ticks ticks to wait before receive
|
||||
* @param[out] msg buf to save msg
|
||||
* @return the operation status, RHINO_SUCCESS is OK, others is error
|
||||
*/
|
||||
kstat_t krhino_queue_recv(kqueue_t *queue, tick_t ticks, void **msg);
|
||||
|
||||
/**
|
||||
* This function will detect a queue full or not
|
||||
* @param[in] queue pointer to the queue
|
||||
* @return the operation status, RHINO_QUEUE_FULL/RHINO_QUEUE_NOT_FULL
|
||||
*/
|
||||
kstat_t krhino_queue_is_full(kqueue_t *queue);
|
||||
|
||||
/**
|
||||
* This function will reset a queue
|
||||
* @param[in] queue pointer to the queue
|
||||
* @return the operation status, RHINO_SUCCESS is OK, others is error
|
||||
*/
|
||||
kstat_t krhino_queue_flush(kqueue_t *queue);
|
||||
|
||||
/**
|
||||
* This function will get information of a queue
|
||||
* @param[in] queue pointer to the queue
|
||||
* @param[out] info buf to save msg-info
|
||||
* @return the operation status, RHINO_SUCCESS is OK, others is error
|
||||
*/
|
||||
kstat_t krhino_queue_info_get(kqueue_t *queue, msg_info_t *info);
|
||||
|
||||
#endif /* K_QUEUE_H */
|
||||
|
||||
101
csky/csi_kernel/rhino/core/include/k_ringbuf.h
Normal file
101
csky/csi_kernel/rhino/core/include/k_ringbuf.h
Normal file
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#ifndef K_MM_RINGBUF_H
|
||||
#define K_MM_RINGBUF_H
|
||||
|
||||
#define RINGBUF_TYPE_FIX 0
|
||||
#define RINGBUF_TYPE_DYN 1
|
||||
|
||||
#define RINGBUF_LEN_MAX_SIZE 3
|
||||
#define RINGBUF_LEN_MASK_ONEBIT 0x80 //1000 0000
|
||||
#define RINGBUF_LEN_MASK_TWOBIT 0xC0 //1100 0000
|
||||
#define RINGBUF_LEN_MASK_CLEAN_TWOBIT 0x3f //0011 1111
|
||||
|
||||
|
||||
#define RINGBUF_LEN_VLE_2BYTES 0x80 //1000 0000
|
||||
#define RINGBUF_LEN_VLE_3BYTES 0xC0 //1100 0000
|
||||
|
||||
#define RINGBUF_LEN_1BYTE_MAXVALUE 0x7f //0111 1111; 127
|
||||
#define RINGBUF_LEN_2BYTES_MAXVALUE 0x3fff // 16383
|
||||
#define RINGBUF_LEN_3BYTES_MAXVALUE 0x3fffff //4194303
|
||||
|
||||
|
||||
#ifndef true
|
||||
#define true 1
|
||||
#endif
|
||||
|
||||
#ifndef false
|
||||
#define false 0
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
uint8_t *buf;
|
||||
uint8_t *end;
|
||||
uint8_t *head;
|
||||
uint8_t *tail;
|
||||
size_t freesize;
|
||||
size_t type;
|
||||
size_t blk_size;
|
||||
} k_ringbuf_t;
|
||||
|
||||
#define COMPRESS_LEN(x) ((x) <= RINGBUF_LEN_1BYTE_MAXVALUE ? 1: (x) <= RINGBUF_LEN_2BYTES_MAXVALUE ? 2: \
|
||||
(x) <= RINGBUF_LEN_3BYTES_MAXVALUE ? 3 : RHINO_INV_PARAM)
|
||||
|
||||
|
||||
#if (RHINO_CONFIG_RINGBUF_VENDOR > 0)
|
||||
/**
|
||||
* This function will init the mm ring buffer.
|
||||
* @param[in] p_ringbuf pointer to ring buffer
|
||||
* @param[in] buf pointer to memory buffer
|
||||
* @param[in] len length of memory buffer
|
||||
* @param[in] type type of ring buffer, fix length or dynamic length
|
||||
* @param[in] block_size block size of fix length ringbuf, if dynamic ringbuffer, ignore this parameter
|
||||
* @return the operation status, RHINO_SUCCESS is OK, others is error
|
||||
*/
|
||||
kstat_t krhino_ringbuf_init (k_ringbuf_t *p_ringbuf, void *buf, size_t len,
|
||||
size_t type, size_t block_size);
|
||||
|
||||
/**
|
||||
* This function will clean all data in mm ring buffer.
|
||||
* @param[in] p_ringbuf pointer to ring buffer
|
||||
* @return the operation status, RHINO_SUCCESS is OK, others is error
|
||||
*/
|
||||
kstat_t krhino_ringbuf_reset(k_ringbuf_t *p_ringbuf);
|
||||
|
||||
/**
|
||||
* This function will push the data to ring buffer end.
|
||||
* @param[in] p_ringbuf pointer to ring buffer
|
||||
* @param[in] data pointer to data
|
||||
* @param[in] len length of data
|
||||
* @return the operation status, RHINO_SUCCESS is OK, others is error
|
||||
*/
|
||||
kstat_t krhino_ringbuf_push(k_ringbuf_t *p_ringbuf, void *data, size_t len);
|
||||
|
||||
/**
|
||||
* This function will pop the data from ring buffer head.
|
||||
* @param[in] p_ringbuf pointer to ring buffer
|
||||
* @param[out] pdata pointer to data
|
||||
* @param[out] plen length of data
|
||||
* @return the operation status, RHINO_SUCCESS is OK, others is error
|
||||
*/
|
||||
kstat_t krhino_ringbuf_pop(k_ringbuf_t *p_ringbuf, void *pdata, size_t *plen);
|
||||
|
||||
|
||||
/**
|
||||
* This function will check if the ring buffer is full.
|
||||
* @param[in] p_ringbuf pointer to ring buffer
|
||||
* @return the ringbuf status, true is full. else is not.
|
||||
*/
|
||||
uint8_t krhino_ringbuf_is_full(k_ringbuf_t *p_ringbuf);
|
||||
|
||||
/**
|
||||
* This function will check if the ring buffer is empty.
|
||||
* @param[in] p_ringbuf pointer to ring buffer
|
||||
* @return the ringbuf status, true is empty. else is not.
|
||||
*/
|
||||
uint8_t krhino_ringbuf_is_empty(k_ringbuf_t *p_ringbuf);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
32
csky/csi_kernel/rhino/core/include/k_sched.h
Normal file
32
csky/csi_kernel/rhino/core/include/k_sched.h
Normal file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#ifndef K_SCHED_H
|
||||
#define K_SCHED_H
|
||||
|
||||
#define KSCHED_FIFO 0u
|
||||
#define KSCHED_RR 1u
|
||||
#define SCHED_MAX_LOCK_COUNT 200u
|
||||
#define NUM_WORDS ((RHINO_CONFIG_PRI_MAX + 31) / 32)
|
||||
|
||||
typedef struct {
|
||||
klist_t *cur_list_item[RHINO_CONFIG_PRI_MAX];
|
||||
uint32_t task_bit_map[NUM_WORDS];
|
||||
uint8_t highest_pri;
|
||||
} runqueue_t;
|
||||
|
||||
/**
|
||||
* This function will disable schedule
|
||||
* @return the operation status, RHINO_SUCCESS is OK, others is error
|
||||
*/
|
||||
kstat_t krhino_sched_disable(void);
|
||||
|
||||
/**
|
||||
* This function will enable schedule
|
||||
* @return the operation status, RHINO_SUCCESS is OK, others is error
|
||||
*/
|
||||
kstat_t krhino_sched_enable(void);
|
||||
|
||||
#endif /* K_SCHED_H */
|
||||
|
||||
95
csky/csi_kernel/rhino/core/include/k_sem.h
Normal file
95
csky/csi_kernel/rhino/core/include/k_sem.h
Normal file
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#ifndef K_SEM_H
|
||||
#define K_SEM_H
|
||||
|
||||
#define WAKE_ONE_SEM 0u
|
||||
#define WAKE_ALL_SEM 1u
|
||||
|
||||
typedef struct sem_s {
|
||||
blk_obj_t blk_obj;
|
||||
sem_count_t count;
|
||||
sem_count_t peak_count;
|
||||
#if (RHINO_CONFIG_SYSTEM_STATS > 0)
|
||||
klist_t sem_item;
|
||||
#endif
|
||||
uint8_t mm_alloc_flag;
|
||||
} ksem_t;
|
||||
|
||||
/**
|
||||
* This function will create a semaphore
|
||||
* @param[in] sem pointer to the semaphore(the space is provided by user)
|
||||
* @param[in] name name of the semaphore
|
||||
* @param[in] count the init count of the semaphore
|
||||
* @return the operation status, RHINO_SUCCESS is OK, others is error
|
||||
*/
|
||||
kstat_t krhino_sem_create(ksem_t *sem, const name_t *name, sem_count_t count);
|
||||
|
||||
/**
|
||||
* This function will delete a semaphore
|
||||
* @param[in] sem pointer to the semaphore
|
||||
* @return the operation status, RHINO_SUCCESS is OK, others is error
|
||||
*/
|
||||
kstat_t krhino_sem_del(ksem_t *sem);
|
||||
|
||||
#if (RHINO_CONFIG_KOBJ_DYN_ALLOC > 0)
|
||||
/**
|
||||
* This function will create a dyn-semaphore
|
||||
* @param[out] sem pointer to the semaphore(the space is provided by kernel)
|
||||
* @param[in] name name of the semaphore
|
||||
* @param[in] count the init count of the semaphore
|
||||
* @return the operation status, RHINO_SUCCESS is OK, others is error
|
||||
*/
|
||||
kstat_t krhino_sem_dyn_create(ksem_t **sem, const name_t *name,
|
||||
sem_count_t count);
|
||||
|
||||
/**
|
||||
* This function will delete a dyn-semaphore
|
||||
* @param[in] sem pointer to the semaphore
|
||||
* @return the operation status, RHINO_SUCCESS is OK, others is error
|
||||
*/
|
||||
kstat_t krhino_sem_dyn_del(ksem_t *sem);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This function will give a semaphore
|
||||
* @param[in] sem pointer to the semphore
|
||||
* @return the operation status, RHINO_SUCCESS is OK, others is error
|
||||
*/
|
||||
kstat_t krhino_sem_give(ksem_t *sem);
|
||||
|
||||
/**
|
||||
* This function will give a semaphore and wakeup all thee waiting task
|
||||
* @param[in] sem pointer to the semaphore
|
||||
* @return the operation status, RHINO_SUCCESS is OK, others is error
|
||||
*/
|
||||
kstat_t krhino_sem_give_all(ksem_t *sem);
|
||||
|
||||
/**
|
||||
* This function will take a semaphore
|
||||
* @param[in] sem pointer to the semaphore
|
||||
* @param[in] ticks ticks to wait before take
|
||||
* @return the operation status, RHINO_SUCCESS is OK, others is error
|
||||
*/
|
||||
kstat_t krhino_sem_take(ksem_t *sem, tick_t ticks);
|
||||
|
||||
/**
|
||||
* This function will set the count of a semaphore
|
||||
* @param[in] sem pointer to the semaphore
|
||||
* @param[in] sem_count count of the semaphore
|
||||
* @return the operation status, RHINO_SUCCESS is OK, others is error
|
||||
*/
|
||||
kstat_t krhino_sem_count_set(ksem_t *sem, sem_count_t count);
|
||||
|
||||
/**
|
||||
* This function will get count of a semaphore
|
||||
* @param[in] sem pointer to the semaphore
|
||||
* @param[out] count count of the semaphore
|
||||
* @return the operation status, RHINO_SUCCESS is OK, others is error
|
||||
*/
|
||||
kstat_t krhino_sem_count_get(ksem_t *sem, sem_count_t *count);
|
||||
|
||||
#endif /* K_SEM_H */
|
||||
|
||||
40
csky/csi_kernel/rhino/core/include/k_soc.h
Normal file
40
csky/csi_kernel/rhino/core/include/k_soc.h
Normal file
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#ifndef K_SOC_H
|
||||
#define K_SOC_H
|
||||
|
||||
#if (RHINO_CONFIG_HW_COUNT > 0)
|
||||
void soc_hw_timer_init(void);
|
||||
hr_timer_t soc_hr_hw_cnt_get(void);
|
||||
lr_timer_t soc_lr_hw_cnt_get(void);
|
||||
#define HR_COUNT_GET() soc_hr_hw_cnt_get()
|
||||
#else /* RHINO_CONFIG_HW_COUNT */
|
||||
#define HR_COUNT_GET() 0u
|
||||
#endif /* RHINO_CONFIG_HW_COUNT */
|
||||
|
||||
#if (RHINO_CONFIG_TASK_SCHED_STATS > 0)
|
||||
#define LR_COUNT_GET() soc_lr_hw_cnt_get()
|
||||
#else /* RHINO_CONFIG_TASK_SCHED_STATS */
|
||||
#define LR_COUNT_GET() 0u
|
||||
#endif /* RHINO_CONFIG_TASK_SCHED_STATS */
|
||||
|
||||
#if (RHINO_CONFIG_INTRPT_GUARD > 0)
|
||||
void soc_intrpt_guard(void);
|
||||
#endif
|
||||
|
||||
#if (RHINO_CONFIG_INTRPT_STACK_REMAIN_GET > 0)
|
||||
size_t soc_intrpt_stack_remain_get(void);
|
||||
#endif
|
||||
|
||||
#if (RHINO_CONFIG_INTRPT_STACK_OVF_CHECK > 0)
|
||||
void soc_intrpt_stack_ovf_check(void);
|
||||
#endif
|
||||
|
||||
void soc_err_proc(kstat_t err);
|
||||
|
||||
size_t soc_get_cur_sp(void);
|
||||
|
||||
#endif /* K_SOC_H */
|
||||
|
||||
39
csky/csi_kernel/rhino/core/include/k_stats.h
Normal file
39
csky/csi_kernel/rhino/core/include/k_stats.h
Normal file
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#ifndef K_STATS_H
|
||||
#define K_STATS_H
|
||||
|
||||
#if (RHINO_CONFIG_SYSTEM_STATS > 0)
|
||||
void kobj_list_init(void);
|
||||
#endif
|
||||
|
||||
#if (RHINO_CONFIG_TASK_STACK_OVF_CHECK > 0)
|
||||
/**
|
||||
* This function will check task stack overflow
|
||||
*/
|
||||
void krhino_stack_ovf_check(void);
|
||||
#endif
|
||||
|
||||
#if (RHINO_CONFIG_TASK_SCHED_STATS > 0)
|
||||
/**
|
||||
* This function will reset task schedule stats
|
||||
*/
|
||||
void krhino_task_sched_stats_reset(void);
|
||||
/**
|
||||
* This function will get task statistic data
|
||||
*/
|
||||
void krhino_task_sched_stats_get(void);
|
||||
#endif
|
||||
|
||||
#if (RHINO_CONFIG_HW_COUNT > 0)
|
||||
void krhino_overhead_measure(void);
|
||||
#endif
|
||||
|
||||
#if (RHINO_CONFIG_CPU_USAGE_STATS > 0)
|
||||
uint32_t krhino_get_cpu_usage(void);
|
||||
#endif
|
||||
|
||||
#endif /* K_STATS_H */
|
||||
|
||||
84
csky/csi_kernel/rhino/core/include/k_sys.h
Normal file
84
csky/csi_kernel/rhino/core/include/k_sys.h
Normal file
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#ifndef K_SYS_H
|
||||
#define K_SYS_H
|
||||
|
||||
#define RHINO_VERSION 10000
|
||||
#define RHINO_IDLE_PRI (RHINO_CONFIG_PRI_MAX - 1)
|
||||
#define RHINO_FALSE 0u
|
||||
#define RHINO_TRUE 1u
|
||||
|
||||
#define RHINO_NO_WAIT 0u
|
||||
|
||||
#define MAX_TIMER_TICKS ((tick_t)-1 >> 1)
|
||||
|
||||
#if (RHINO_CONFIG_64_BIT_TYPE > 0)
|
||||
#define RHINO_WAIT_FOREVER ((uint64_t)-1)
|
||||
typedef uint64_t sys_time_t;
|
||||
typedef int64_t sys_time_i_t;
|
||||
typedef uint64_t idle_count_t;
|
||||
typedef uint64_t tick_t;
|
||||
typedef int64_t tick_i_t;
|
||||
#else
|
||||
#define RHINO_WAIT_FOREVER ((uint32_t)-1)
|
||||
typedef uint32_t sys_time_t;
|
||||
typedef int32_t sys_time_i_t;
|
||||
typedef uint32_t idle_count_t;
|
||||
typedef uint32_t tick_t;
|
||||
typedef int32_t tick_i_t;
|
||||
#endif
|
||||
|
||||
#if (RHINO_CONFIG_INTRPT_STACK_OVF_CHECK > 0)
|
||||
#if (RHINO_CONFIG_CPU_STACK_DOWN > 0)
|
||||
extern cpu_stack_t *g_intrpt_stack_bottom;
|
||||
#else
|
||||
extern cpu_stack_t *g_intrpt_stack_top;
|
||||
#endif
|
||||
#endif /* RHINO_CONFIG_INTRPT_STACK_OVF_CHECK */
|
||||
|
||||
/**
|
||||
* This function will init AliOS
|
||||
* @return the operation status, RHINO_SUCCESS is OK, others is error
|
||||
*/
|
||||
kstat_t krhino_init(void);
|
||||
|
||||
/**
|
||||
* This function will start AliOS
|
||||
* @return the operation status, RHINO_SUCCESS is OK, others is error
|
||||
*/
|
||||
kstat_t krhino_start(void);
|
||||
|
||||
/**
|
||||
* This function will enter interrupt
|
||||
* @return the operation status, RHINO_SUCCESS is OK, others is error
|
||||
*/
|
||||
kstat_t krhino_intrpt_enter(void);
|
||||
|
||||
/**
|
||||
* This function will exit interrupt
|
||||
*/
|
||||
void krhino_intrpt_exit(void);
|
||||
|
||||
/**
|
||||
* This function will check intrpt-stack overflow
|
||||
*/
|
||||
void krhino_intrpt_stack_ovf_check(void);
|
||||
|
||||
/**
|
||||
* This function will get the whole ram space used by kernel
|
||||
* @return the whole ram space used by kernel
|
||||
*/
|
||||
size_t krhino_global_space_get(void);
|
||||
|
||||
/**
|
||||
* This function will get kernel version
|
||||
* @return the operation status, RHINO_SUCCESS is OK, others is error
|
||||
*/
|
||||
uint32_t krhino_version_get(void);
|
||||
|
||||
void krhino_check_fatal_call(const char *func);
|
||||
|
||||
#endif /* K_SYS_H */
|
||||
|
||||
312
csky/csi_kernel/rhino/core/include/k_task.h
Normal file
312
csky/csi_kernel/rhino/core/include/k_task.h
Normal file
@@ -0,0 +1,312 @@
|
||||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#ifndef K_TASK_H
|
||||
#define K_TASK_H
|
||||
|
||||
typedef enum {
|
||||
K_SEED,
|
||||
K_RDY,
|
||||
K_PEND,
|
||||
K_SUSPENDED,
|
||||
K_PEND_SUSPENDED,
|
||||
K_SLEEP,
|
||||
K_SLEEP_SUSPENDED,
|
||||
K_DELETED,
|
||||
} task_stat_t;
|
||||
|
||||
typedef struct {
|
||||
void *task_stack;
|
||||
|
||||
#if (RHINO_CONFIG_TASK_INFO > 0)
|
||||
/* for user data extension do not move the position! */
|
||||
void *user_info[RHINO_CONFIG_TASK_INFO_NUM];
|
||||
#endif
|
||||
|
||||
cpu_stack_t *task_stack_base;
|
||||
uint32_t stack_size;
|
||||
klist_t task_list;
|
||||
|
||||
#if (RHINO_CONFIG_TASK_SUSPEND > 0)
|
||||
suspend_nested_t suspend_count;
|
||||
#endif
|
||||
|
||||
struct mutex_s *mutex_list;
|
||||
|
||||
#if (RHINO_CONFIG_SYSTEM_STATS > 0)
|
||||
klist_t task_stats_item;
|
||||
#endif
|
||||
|
||||
klist_t tick_list;
|
||||
tick_t tick_match;
|
||||
tick_t tick_remain;
|
||||
klist_t *tick_head;
|
||||
|
||||
void *msg;
|
||||
|
||||
#if (RHINO_CONFIG_BUF_QUEUE > 0)
|
||||
size_t bq_msg_size;
|
||||
#endif
|
||||
|
||||
const name_t *task_name;
|
||||
|
||||
task_stat_t task_state;
|
||||
blk_state_t blk_state;
|
||||
|
||||
/* Task block on mutex, queue, semphore, event */
|
||||
blk_obj_t *blk_obj;
|
||||
|
||||
#if (RHINO_CONFIG_TASK_SEM > 0)
|
||||
struct sem_s *task_sem_obj;
|
||||
#endif
|
||||
|
||||
#if (RHINO_CONFIG_TASK_SCHED_STATS > 0)
|
||||
size_t task_free_stack_size;
|
||||
ctx_switch_t task_ctx_switch_times;
|
||||
sys_time_t task_time_total_run;
|
||||
sys_time_t task_time_total_run_prev;
|
||||
lr_timer_t task_exec_time;
|
||||
lr_timer_t task_time_start;
|
||||
#endif
|
||||
|
||||
#if (RHINO_CONFIG_DISABLE_INTRPT_STATS > 0)
|
||||
hr_timer_t task_intrpt_disable_time_max;
|
||||
#endif
|
||||
|
||||
#if (RHINO_CONFIG_DISABLE_SCHED_STATS > 0)
|
||||
hr_timer_t task_sched_disable_time_max;
|
||||
#endif
|
||||
|
||||
#if (RHINO_CONFIG_SCHED_RR > 0)
|
||||
/* for task time slice*/
|
||||
uint32_t time_slice;
|
||||
uint32_t time_total;
|
||||
#endif
|
||||
|
||||
#if (RHINO_CONFIG_EVENT_FLAG > 0)
|
||||
uint32_t pend_flags;
|
||||
void *pend_info;
|
||||
uint8_t pend_option;
|
||||
#endif
|
||||
|
||||
#if (RHINO_CONFIG_SCHED_RR > 0)
|
||||
uint8_t sched_policy;
|
||||
#endif
|
||||
|
||||
uint8_t cpu_num;
|
||||
|
||||
#if (RHINO_CONFIG_CPU_NUM > 1)
|
||||
uint8_t cpu_binded;
|
||||
uint8_t cur_exc;
|
||||
#endif
|
||||
|
||||
/* current prio */
|
||||
uint8_t prio;
|
||||
/* base prio */
|
||||
uint8_t b_prio;
|
||||
uint8_t mm_alloc_flag:2, lprun:1, rev: 5;
|
||||
|
||||
void *arg;
|
||||
uint32_t runtime;
|
||||
int32_t task_errno;
|
||||
} ktask_t;
|
||||
|
||||
typedef void (*task_entry_t)(void *arg);
|
||||
|
||||
/**
|
||||
* This function will initialize a task
|
||||
* @param[in] task the task to be created
|
||||
* @param[in] name the name of task, which shall be unique
|
||||
* @param[in] arg the parameter of task enter function
|
||||
* @param[in] pri the prio of task
|
||||
* @param[in] ticks the time slice if there are same prio task
|
||||
* @param[in] stack_buf the start address of task stack
|
||||
* @param[in] stack the size of thread stack
|
||||
* @param[in] entry the entry function of task
|
||||
* @param[in] autorun the autorunning flag of task
|
||||
* @return the operation status, RHINO_SUCCESS is OK, others is error
|
||||
*/
|
||||
kstat_t krhino_task_create(ktask_t *task, const name_t *name, void *arg,
|
||||
uint8_t prio, tick_t ticks, cpu_stack_t *stack_buf,
|
||||
size_t stack_size, task_entry_t entry, uint8_t autorun);
|
||||
|
||||
#if (RHINO_CONFIG_CPU_NUM > 1)
|
||||
kstat_t krhino_task_cpu_create(ktask_t *task, const name_t *name, void *arg,
|
||||
uint8_t prio, tick_t ticks, cpu_stack_t *stack_buf,
|
||||
size_t stack_size, task_entry_t entry, uint8_t cpu_num,
|
||||
uint8_t autorun);
|
||||
|
||||
kstat_t krhino_task_cpu_bind(ktask_t *task, uint8_t cpu_num);
|
||||
kstat_t krhino_task_cpu_unbind(ktask_t *task);
|
||||
#endif
|
||||
|
||||
|
||||
#if (RHINO_CONFIG_KOBJ_DYN_ALLOC > 0)
|
||||
/**
|
||||
* This function will initialize a task
|
||||
* @param[in] task the task to be created
|
||||
* @param[in] name the name of task, which shall be unique
|
||||
* @param[in] arg the parameter of task enter function
|
||||
* @param[in] pri the prio of task
|
||||
* @param[in] ticks the time slice if there are same prio task
|
||||
* @param[in] stack the size of thread stack
|
||||
* @param[in] entry the entry function of task
|
||||
* @param[in] autorun the autorunning flag of task
|
||||
* @return the operation status, RHINO_SUCCESS is OK, others is error
|
||||
*/
|
||||
kstat_t krhino_task_dyn_create(ktask_t **task, const name_t *name, void *arg,
|
||||
uint8_t pri,
|
||||
tick_t ticks, void *stack, size_t stack_size,
|
||||
task_entry_t entry, uint8_t autorun);
|
||||
|
||||
#if (RHINO_CONFIG_CPU_NUM > 1)
|
||||
kstat_t krhino_task_cpu_dyn_create(ktask_t **task, const name_t *name, void *arg,
|
||||
uint8_t pri, tick_t ticks, size_t stack,
|
||||
task_entry_t entry, uint8_t cpu_num, uint8_t autorun);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if (RHINO_CONFIG_TASK_DEL > 0)
|
||||
/**
|
||||
* This function will delete a task
|
||||
* @param[in] task the task to be deleted.
|
||||
* @return the operation status, RHINO_SUCCESS is OK, others is error
|
||||
*/
|
||||
kstat_t krhino_task_del(ktask_t *task);
|
||||
#if (RHINO_CONFIG_KOBJ_DYN_ALLOC > 0)
|
||||
/**
|
||||
* This function will delete a dyn-task
|
||||
* @param[in] task the task to be deleted.
|
||||
* @return the operation status, RHINO_SUCCESS is OK, others is error
|
||||
*/
|
||||
kstat_t krhino_task_dyn_del(ktask_t *task);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This function will cause a task to sleep for some ticks
|
||||
* @param[in] ticks the ticks to sleep
|
||||
* @return the operation status, RHINO_SUCCESS is OK, others is error
|
||||
*/
|
||||
|
||||
kstat_t krhino_task_sleep(tick_t dly);
|
||||
|
||||
/**
|
||||
* This function will yield a task
|
||||
* @return the operation status, RHINO_SUCCESS is OK, others is error
|
||||
*/
|
||||
kstat_t krhino_task_yield(void);
|
||||
|
||||
/**
|
||||
* This function will get the current task for this cpu
|
||||
* @return the current task
|
||||
*/
|
||||
ktask_t *krhino_cur_task_get(void);
|
||||
|
||||
#if (RHINO_CONFIG_TASK_SUSPEND > 0)
|
||||
/**
|
||||
* This function will suspend a task
|
||||
* @param[in] task the task to be suspended
|
||||
* @return the operation status, RHINO_SUCCESS is OK, others is error
|
||||
*/
|
||||
kstat_t krhino_task_suspend(ktask_t *task);
|
||||
|
||||
/**
|
||||
* This function will resume a task
|
||||
* @param[in] task the task to be resumed
|
||||
* @return the operation status, RHINO_SUCCESS is OK, others is error
|
||||
*/
|
||||
kstat_t krhino_task_resume(ktask_t *task);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This function will get min free stack size in the total runtime
|
||||
* @param[in] task the task where get free stack size.
|
||||
* @param[in] free the free task stack size to be filled with.
|
||||
* @return the operation status, RHINO_SUCCESS is OK, others is error
|
||||
*/
|
||||
kstat_t krhino_task_stack_min_free(ktask_t *task, size_t *free);
|
||||
|
||||
|
||||
/**
|
||||
* This function will get current free stack size
|
||||
* @param[in] task the task where get free stack size.
|
||||
* @param[in] free the free task stack size to be filled with.
|
||||
* @return the operation status, RHINO_SUCCESS is OK, others is error
|
||||
*/
|
||||
kstat_t krhino_task_stack_cur_free(ktask_t *task, size_t *free);
|
||||
|
||||
/**
|
||||
* This function will change the prio of task
|
||||
* @param[in] task the task to be changed prio
|
||||
* @param[in] pri the prio to be changed.
|
||||
* @param[out] old_pri the old task prio to be filled with
|
||||
* @return the operation status, RHINO_SUCCESS is OK, others is error
|
||||
*/
|
||||
kstat_t krhino_task_pri_change(ktask_t *task, uint8_t pri, uint8_t *old_pri);
|
||||
|
||||
#if (RHINO_CONFIG_TASK_WAIT_ABORT > 0)
|
||||
/**
|
||||
* This function will abort a task and wakup the task
|
||||
* @param[in] task the task to be aborted
|
||||
* @return the operation status, RHINO_SUCCESS is OK, others is error
|
||||
*/
|
||||
kstat_t krhino_task_wait_abort(ktask_t *task);
|
||||
#endif
|
||||
|
||||
#if (RHINO_CONFIG_SCHED_RR > 0)
|
||||
/**
|
||||
* This function will set task timeslice
|
||||
* @param[in] task the task to be set timeslice
|
||||
* @param[in] slice the task time slice
|
||||
* @return the operation status, RHINO_SUCCESS is OK, others is error
|
||||
*/
|
||||
kstat_t krhino_task_time_slice_set(ktask_t *task, size_t slice);
|
||||
|
||||
/**
|
||||
* This function will set task sched policy
|
||||
* @param[in] task the task to be set timeslice
|
||||
* @param[in] policy the policy to be set, pllicy option can be either KSCHED_FIFO or KSCHED_RR
|
||||
* @return the operation status, RHINO_SUCCESS is OK, others is error
|
||||
*/
|
||||
kstat_t krhino_sched_policy_set(ktask_t *task, uint8_t policy);
|
||||
|
||||
/**
|
||||
* This function will get task sched policy
|
||||
* @param[in] task the task to be get timeslice
|
||||
* @param[out] policy the policy to be get
|
||||
* @return the operation status, RHINO_SUCCESS is OK, others is error
|
||||
*/
|
||||
kstat_t krhino_sched_policy_get(ktask_t *task, uint8_t *policy);
|
||||
#endif
|
||||
|
||||
#if (RHINO_CONFIG_TASK_INFO > 0)
|
||||
/**
|
||||
* This function will set task private infomation
|
||||
* @param[in] task the task to be set private infomation
|
||||
* @param[out] info the private information
|
||||
* @return the operation status, RHINO_SUCCESS is OK, others is error
|
||||
*/
|
||||
kstat_t krhino_task_info_set(ktask_t *task, size_t idx, void *info);
|
||||
|
||||
/**
|
||||
* This function will get task private infomation
|
||||
* @param[in] task the task to be get private infomation
|
||||
* @param[out] info to save private infomation
|
||||
* @return the task private information
|
||||
*/
|
||||
kstat_t krhino_task_info_get(ktask_t *task, size_t idx, void **info);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This function will be set in cpu_task_stack_init,set LR reg with
|
||||
* this funtion pointer
|
||||
*/
|
||||
void krhino_task_deathbed(void);
|
||||
|
||||
void krhino_task_set_lprun(ktask_t *task, uint8_t run);
|
||||
void krhino_lpower_mode(uint8_t enable);
|
||||
|
||||
#endif /* K_TASK_H */
|
||||
|
||||
57
csky/csi_kernel/rhino/core/include/k_task_sem.h
Normal file
57
csky/csi_kernel/rhino/core/include/k_task_sem.h
Normal file
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#ifndef K_TASK_SEM_H
|
||||
#define K_TASK_SEM_H
|
||||
|
||||
/**
|
||||
* This function will create a task-semaphore
|
||||
* @param[in] task pointer to the task
|
||||
* @param[in] sem pointer to the semaphore
|
||||
* @param[in] name name of the task-semaphore
|
||||
* @param[in] count count of the semaphore
|
||||
* @return the operation status, RHINO_SUCCESS is OK, others is error
|
||||
*/
|
||||
kstat_t krhino_task_sem_create(ktask_t *task, ksem_t *sem, const name_t *name,
|
||||
size_t count);
|
||||
|
||||
/**
|
||||
* This function will delete a task-semaphore
|
||||
* @param[in] task pointer to the semaphore
|
||||
* @return the operation status, RHINO_SUCCESS is OK, others is error
|
||||
*/
|
||||
kstat_t krhino_task_sem_del(ktask_t *task);
|
||||
|
||||
/**
|
||||
* This function will give up a task-semaphore
|
||||
* @param[in] task pointer to the task
|
||||
* @return the operation status, RHINO_SUCCESS is OK, others is error
|
||||
*/
|
||||
kstat_t krhino_task_sem_give(ktask_t *task);
|
||||
|
||||
/**
|
||||
* This function will take a task-semaphore
|
||||
* @param[in] ticks ticks to wait before take the semaphore
|
||||
* @return the operation status, RHINO_SUCCESS is OK, others is error
|
||||
*/
|
||||
kstat_t krhino_task_sem_take(tick_t ticks);
|
||||
|
||||
/**
|
||||
* This function will set the count of a task-semaphore
|
||||
* @param[in] task pointer to the task
|
||||
* @param[in] count count of the semaphre to set
|
||||
* @return the operation status, RHINO_SUCCESS is OK, others is error
|
||||
*/
|
||||
kstat_t krhino_task_sem_count_set(ktask_t *task, sem_count_t count);
|
||||
|
||||
/**
|
||||
* This function will get task-semaphore count
|
||||
* @param[in] task pointer to the semphore
|
||||
* @param[out] count count of the semaphore
|
||||
* @return the operation status, RHINO_SUCCESS is OK, others is error
|
||||
*/
|
||||
kstat_t krhino_task_sem_count_get(ktask_t *task, sem_count_t *count);
|
||||
|
||||
#endif /* K_TASK_SEM_H */
|
||||
|
||||
41
csky/csi_kernel/rhino/core/include/k_time.h
Normal file
41
csky/csi_kernel/rhino/core/include/k_time.h
Normal file
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#ifndef K_TIME_H
|
||||
#define K_TIME_H
|
||||
|
||||
/**
|
||||
* This function will handle systick routine
|
||||
* @return the operation status, RHINO_SUCCESS is OK, others is error
|
||||
*/
|
||||
void krhino_tick_proc(void);
|
||||
|
||||
/**
|
||||
* This function will get time of the system in ms
|
||||
* @return system time
|
||||
*/
|
||||
sys_time_t krhino_sys_time_get(void);
|
||||
|
||||
/**
|
||||
* This function will get ticks of the system
|
||||
* @return the system ticks
|
||||
*/
|
||||
sys_time_t krhino_sys_tick_get(void);
|
||||
|
||||
/**
|
||||
* This function will convert ms to ticks
|
||||
* @param[in] ms ms which will be converted to ticks
|
||||
* @return the ticks of the ms
|
||||
*/
|
||||
tick_t krhino_ms_to_ticks(sys_time_t ms);
|
||||
|
||||
/**
|
||||
* This function will convert ticks to ms
|
||||
* @param[in] ticks ticks which will be converted to ms
|
||||
* @return the ms of the ticks
|
||||
*/
|
||||
sys_time_t krhino_ticks_to_ms(tick_t ticks);
|
||||
|
||||
#endif /* K_TIME_H */
|
||||
|
||||
137
csky/csi_kernel/rhino/core/include/k_timer.h
Normal file
137
csky/csi_kernel/rhino/core/include/k_timer.h
Normal file
@@ -0,0 +1,137 @@
|
||||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#ifndef K_TIMER_H
|
||||
#define K_TIMER_H
|
||||
|
||||
enum {
|
||||
TIMER_CMD_CB = 0u,
|
||||
TIMER_CMD_START,
|
||||
TIMER_CMD_STOP,
|
||||
TIMER_CMD_CHG,
|
||||
TIMER_ARG_CHG,
|
||||
TIMER_ARG_CHG_AUTO,
|
||||
TIMER_CMD_DEL,
|
||||
TIMER_CMD_DYN_DEL
|
||||
};
|
||||
|
||||
typedef void (*timer_cb_t)(void *timer, void *arg);
|
||||
|
||||
typedef struct {
|
||||
klist_t timer_list;
|
||||
klist_t *to_head;
|
||||
const name_t *name;
|
||||
timer_cb_t cb;
|
||||
void *timer_cb_arg;
|
||||
sys_time_t match;
|
||||
sys_time_t remain;
|
||||
sys_time_t init_count;
|
||||
sys_time_t round_ticks;
|
||||
void *priv;
|
||||
kobj_type_t obj_type;
|
||||
uint8_t timer_state;
|
||||
uint8_t mm_alloc_flag;
|
||||
} ktimer_t;
|
||||
|
||||
typedef struct {
|
||||
ktimer_t *timer;
|
||||
uint8_t cb_num;
|
||||
sys_time_t first;
|
||||
union {
|
||||
sys_time_t round;
|
||||
void *arg;
|
||||
} u;
|
||||
} k_timer_queue_cb;
|
||||
|
||||
typedef enum {
|
||||
TIMER_DEACTIVE = 0u,
|
||||
TIMER_ACTIVE
|
||||
} k_timer_state_t;
|
||||
|
||||
/**
|
||||
* This function will create a timer
|
||||
* @param[in] timer pointer to the timer(the space is provided by user)
|
||||
* @param[in] name name of the timer
|
||||
* @param[in] cb callbak of the timer
|
||||
* @param[in] first ticks of the first timer triger
|
||||
* @param[in] round ticks of the normal timer triger
|
||||
* @param[in] arg the argument of the callback
|
||||
* @param[in] auto_run auto run or not when the timer is created
|
||||
* @return the operation status, RHINO_SUCCESS is OK, others is error
|
||||
*/
|
||||
kstat_t krhino_timer_create(ktimer_t *timer, const name_t *name, timer_cb_t cb,
|
||||
sys_time_t first, sys_time_t round, void *arg, uint8_t auto_run);
|
||||
|
||||
/**
|
||||
* This function will delete a timer
|
||||
* @param[in] timer pointer to a timer
|
||||
* @return the operation status, RHINO_SUCCESS is OK, others is error
|
||||
*/
|
||||
kstat_t krhino_timer_del(ktimer_t *timer);
|
||||
|
||||
#if (RHINO_CONFIG_KOBJ_DYN_ALLOC > 0)
|
||||
/**
|
||||
* This function will create a dyn-timer
|
||||
* @param[in] timer pointer to the timer
|
||||
* @param[in] name name of the timer
|
||||
* @param[in] cb callbak of the timer
|
||||
* @param[in] first ticks of the first timer triger
|
||||
* @param[in] round ticks of the normal timer triger
|
||||
* @param[in] arg the argument of the callback
|
||||
* @param[in] auto_run auto run or not when the timer is created
|
||||
* @return the operation status, RHINO_SUCCESS is OK, others is error
|
||||
*/
|
||||
kstat_t krhino_timer_dyn_create(ktimer_t **timer, const name_t *name,
|
||||
timer_cb_t cb,
|
||||
sys_time_t first, sys_time_t round, void *arg, uint8_t auto_run);
|
||||
/**
|
||||
* This function will delete a dyn-timer
|
||||
* @param[in] timer pointer to a timer
|
||||
* @return the operation status, RHINO_SUCCESS is OK, others is error
|
||||
*/
|
||||
kstat_t krhino_timer_dyn_del(ktimer_t *timer);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* This function will start a timer
|
||||
* @param[in] timer pointer to the timer
|
||||
* @return the operation status, RHINO_SUCCESS is OK, others is error
|
||||
*/
|
||||
kstat_t krhino_timer_start(ktimer_t *timer);
|
||||
|
||||
/**
|
||||
* This function will stop a timer
|
||||
* @param[in] timer pointer to the timer
|
||||
* @return the operation status, RHINO_SUCCESS is OK, others is error
|
||||
*/
|
||||
kstat_t krhino_timer_stop(ktimer_t *timer);
|
||||
|
||||
/**
|
||||
* This function will change attributes of a timer
|
||||
* @param[in] timer pointer to the timer
|
||||
* @param[in] first ticks of the first timer triger
|
||||
* @param[in] round ticks of the normal timer triger
|
||||
* @return the operation status, RHINO_SUCCESS is OK, others is error
|
||||
*/
|
||||
kstat_t krhino_timer_change(ktimer_t *timer, sys_time_t first, sys_time_t round);
|
||||
|
||||
/**
|
||||
* This function will change attributes of a timer without stop and start
|
||||
* @param[in] timer pointer to the timer
|
||||
* @param[in] first ticks of the first timer triger
|
||||
* @param[in] round ticks of the normal timer triger
|
||||
* @return the operation status, RHINO_SUCCESS is OK, others is error
|
||||
*/
|
||||
kstat_t krhino_timer_arg_change_auto(ktimer_t *timer, void *arg);
|
||||
|
||||
/**
|
||||
* This function will change callback arg attributes of a timer
|
||||
* @param[in] timer pointer to the timer
|
||||
* @param[in] arg timer callback arg
|
||||
* @return the operation status, RHINO_SUCCESS is OK, others is error
|
||||
*/
|
||||
kstat_t krhino_timer_arg_change(ktimer_t *timer, void *arg);
|
||||
|
||||
#endif /* K_TIMER_H */
|
||||
|
||||
207
csky/csi_kernel/rhino/core/include/k_trace.h
Normal file
207
csky/csi_kernel/rhino/core/include/k_trace.h
Normal file
@@ -0,0 +1,207 @@
|
||||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#ifndef K_TRACE_H
|
||||
#define K_TRACE_H
|
||||
|
||||
|
||||
#if (RHINO_CONFIG_TRACE > 0)
|
||||
/* task trace function */
|
||||
void _trace_init(void);
|
||||
void _trace_task_switch(ktask_t *from, ktask_t *to);
|
||||
void _trace_intrpt_task_switch(ktask_t *from, ktask_t *to);
|
||||
void _trace_task_create(ktask_t *task);
|
||||
void _trace_task_sleep(ktask_t *task, tick_t ticks);
|
||||
void _trace_task_pri_change(ktask_t *task, ktask_t *task_pri_chg, uint8_t pri);
|
||||
void _trace_task_suspend(ktask_t *task, ktask_t *task_suspended);
|
||||
void _trace_task_resume(ktask_t *task, ktask_t *task_resumed);
|
||||
void _trace_task_del(ktask_t *task, ktask_t *task_del);
|
||||
void _trace_task_abort(ktask_t *task, ktask_t *task_abort);
|
||||
|
||||
/* semaphore trace function */
|
||||
void _trace_sem_create(ktask_t *task, ksem_t *sem);
|
||||
void _trace_sem_overflow(ktask_t *task, ksem_t *sem);
|
||||
void _trace_sem_del(ktask_t *task, ksem_t *sem);
|
||||
void _trace_sem_get_success(ktask_t *task, ksem_t *sem);
|
||||
void _trace_sem_get_blk(ktask_t *task, ksem_t *sem, tick_t wait_option);
|
||||
void _trace_sem_task_wake(ktask_t *task, ktask_t *task_waked_up, ksem_t *sem,
|
||||
uint8_t opt_wake_all);
|
||||
void _trace_sem_cnt_increase(ktask_t *task, ksem_t *sem);
|
||||
|
||||
/* mutex trace function */
|
||||
void _trace_mutex_create(ktask_t *task, kmutex_t *mutex, const name_t *name);
|
||||
void _trace_mutex_release(ktask_t *task, ktask_t *task_release,
|
||||
uint8_t new_pri);
|
||||
void _trace_mutex_get(ktask_t *task, kmutex_t *mutex, tick_t wait_option);
|
||||
void _trace_task_pri_inv(ktask_t *task, ktask_t *mtxtsk);
|
||||
void _trace_mutex_get_blk(ktask_t *task, kmutex_t *mutex, tick_t wait_option);
|
||||
void _trace_mutex_release_success(ktask_t *task, kmutex_t *mutex);
|
||||
void _trace_mutex_task_wake(ktask_t *task, ktask_t *task_waked_up,
|
||||
kmutex_t *mutex);
|
||||
void _trace_mutex_del(ktask_t *task, kmutex_t *mutex);
|
||||
|
||||
/* event trace function */
|
||||
void _trace_event_create(ktask_t *task, kevent_t *event, const name_t *name,
|
||||
uint32_t flags_init);
|
||||
void _trace_event_get(ktask_t *task, kevent_t *event);
|
||||
void _trace_event_get_blk(ktask_t *task, kevent_t *event, tick_t wait_option);
|
||||
void _trace_event_task_wake(ktask_t *task, ktask_t *task_waked_up,
|
||||
kevent_t *event);
|
||||
void _trace_event_del(ktask_t *task, kevent_t *event);
|
||||
|
||||
/* buf_queue trace function */
|
||||
void _trace_buf_queue_create(ktask_t *task, kbuf_queue_t *buf_queue);
|
||||
void _trace_buf_max(ktask_t *task, kbuf_queue_t *buf_queue, void *p_void,
|
||||
size_t msg_size);
|
||||
void _trace_buf_post(ktask_t *task, kbuf_queue_t *buf_queue, void *p_void,
|
||||
size_t msg_size);
|
||||
void _trace_buf_queue_task_wake(ktask_t *task, ktask_t *task_waked_up,
|
||||
kbuf_queue_t *buf_queue);
|
||||
void _trace_buf_queue_get_blk(ktask_t *task, kbuf_queue_t *buf_queue,
|
||||
tick_t wait_option);
|
||||
|
||||
/* timer trace function */
|
||||
void _trace_timer_create(ktask_t *task, ktimer_t *timer);
|
||||
void _trace_timer_del(ktask_t *task, ktimer_t *timer);
|
||||
|
||||
/* mblk trace function */
|
||||
void _trace_mblk_pool_create(ktask_t *task, mblk_pool_t *pool);
|
||||
|
||||
/* mm trace function */
|
||||
//void _trace_mm_pool_create(ktask_t *task, mm_pool_t *pool);
|
||||
|
||||
/* work queue trace */
|
||||
void _trace_work_init(ktask_t *task, kwork_t *work);
|
||||
void _trace_workqueue_create(ktask_t *task, kworkqueue_t *workqueue);
|
||||
void _trace_workqueue_del(ktask_t *task, kworkqueue_t *workqueue);
|
||||
|
||||
/* task trace */
|
||||
#define TRACE_INIT() _trace_init()
|
||||
#define TRACE_TASK_SWITCH(from, to) _trace_task_switch(from, to)
|
||||
#define TRACE_TASK_CREATE(task) _trace_task_create(task)
|
||||
#define TRACE_TASK_SLEEP(task, ticks) _trace_task_sleep(task, ticks)
|
||||
#define TRACE_INTRPT_TASK_SWITCH(from, to) _trace_intrpt_task_switch(from, to)
|
||||
#define TRACE_TASK_PRI_CHANGE(task, task_pri_chg, pri) _trace_task_pri_change(task, task_pri_chg, pri)
|
||||
#define TRACE_TASK_SUSPEND(task, task_suspended) _trace_task_suspend(task, task_suspended)
|
||||
#define TRACE_TASK_RESUME(task, task_resumed) _trace_task_resume(task, task_resumed)
|
||||
#define TRACE_TASK_DEL(task, task_del) _trace_task_del(task, task_del)
|
||||
#define TRACE_TASK_WAIT_ABORT(task, task_abort) _trace_task_abort(task, task_abort)
|
||||
|
||||
/* semaphore trace */
|
||||
#define TRACE_SEM_CREATE(task, sem) _trace_sem_create(task, sem)
|
||||
#define TRACE_SEM_OVERFLOW(task, sem) _trace_sem_overflow(task, sem)
|
||||
#define TRACE_SEM_CNT_INCREASE(task, sem) _trace_sem_cnt_increase(task, sem)
|
||||
#define TRACE_SEM_GET_SUCCESS(task, sem) _trace_sem_get_success(task, sem)
|
||||
#define TRACE_SEM_GET_BLK(task, sem, wait_option) _trace_sem_get_blk(task, sem, wait_option)
|
||||
#define TRACE_SEM_TASK_WAKE(task, task_waked_up, sem, opt_wake_all) _trace_sem_task_wake(task, task_waked_up, sem, opt_wake_all)
|
||||
#define TRACE_SEM_DEL(task, sem) _trace_sem_del(task, sem);
|
||||
|
||||
/* mutex trace */
|
||||
#define TRACE_MUTEX_CREATE(task, mutex, name) _trace_mutex_create(task, mutex, name)
|
||||
#define TRACE_MUTEX_RELEASE(task, task_release, new_pri) _trace_mutex_release(task, task_release, new_pri)
|
||||
#define TRACE_MUTEX_GET(task, mutex, wait_option) _trace_mutex_get(task, mutex, wait_option)
|
||||
#define TRACE_TASK_PRI_INV(task, mtxtsk) _trace_task_pri_inv(task, mtxtsk)
|
||||
#define TRACE_MUTEX_GET_BLK(task, mutex, wait_option) _trace_mutex_get_blk(task, mutex, wait_option)
|
||||
#define TRACE_MUTEX_RELEASE_SUCCESS(task, mutex) _trace_mutex_release_success(task, mutex)
|
||||
#define TRACE_MUTEX_TASK_WAKE(task, task_waked_up, mutex) _trace_mutex_task_wake(task, task_waked_up, mutex)
|
||||
#define TRACE_MUTEX_DEL(task, mutex) _trace_mutex_del(task, mutex)
|
||||
|
||||
/* event trace */
|
||||
#define TRACE_EVENT_CREATE(task, event, name, flags_init) _trace_event_create(task, event, name, flags_init)
|
||||
#define TRACE_EVENT_GET(task, event) _trace_event_get(task, event)
|
||||
#define TRACE_EVENT_GET_BLK(task, event, wait_option) _trace_event_get_blk(task, event, wait_option)
|
||||
#define TRACE_EVENT_TASK_WAKE(task, task_waked_up, event) _trace_event_task_wake(task, task_waked_up, event)
|
||||
#define TRACE_EVENT_DEL(task, event) _trace_event_del(task, event)
|
||||
|
||||
/* buf_queue trace */
|
||||
#define TRACE_BUF_QUEUE_CREATE(task, buf_queue) _trace_buf_queue_create(task, buf_queue)
|
||||
#define TRACE_BUF_QUEUE_MAX(task, buf_queue, msg, msg_size) _trace_buf_max(task, buf_queue, msg, msg_size)
|
||||
#define TRACE_BUF_QUEUE_POST(task, buf_queue, msg, msg_size) _trace_buf_post(task, buf_queue, msg, msg_size)
|
||||
#define TRACE_BUF_QUEUE_TASK_WAKE(task, task_waked_up, queue) _trace_buf_queue_task_wake(task, task_waked_up, queue)
|
||||
#define TRACE_BUF_QUEUE_GET_BLK(task, buf_queue, wait_option) _trace_buf_queue_get_blk(task, buf_queue, wait_option)
|
||||
|
||||
/* timer trace */
|
||||
#define TRACE_TIMER_CREATE(task, timer) _trace_timer_create(task, timer)
|
||||
#define TRACE_TIMER_DEL(task, timer) _trace_timer_del(task, timer)
|
||||
|
||||
/* mblk trace */
|
||||
#define TRACE_MBLK_POOL_CREATE(task, pool) _trace_mblk_pool_create(task, pool)
|
||||
|
||||
/* mm trace */
|
||||
#define TRACE_MM_POOL_CREATE(task, pool) _trace_mm_pool_create(task, pool)
|
||||
|
||||
/* mm region */
|
||||
#define TRACE_MM_REGION_CREATE(task, regions) _trace_mm_region_create(task, regions)
|
||||
|
||||
/* work queue trace */
|
||||
#define TRACE_WORK_INIT(task, work) _trace_work_init(task, work)
|
||||
#define TRACE_WORKQUEUE_CREATE(task, workqueue) _trace_workqueue_create(task, workqueue)
|
||||
#define TRACE_WORKQUEUE_DEL(task, workqueue) _trace_workqueue_del(task, workqueue)
|
||||
|
||||
#else
|
||||
/* task trace */
|
||||
#define TRACE_INIT()
|
||||
#define TRACE_TASK_SWITCH(from, to)
|
||||
#define TRACE_TASK_CREATE(task)
|
||||
#define TRACE_TASK_SLEEP(task, ticks)
|
||||
#define TRACE_INTRPT_TASK_SWITCH(from, to)
|
||||
#define TRACE_TASK_PRI_CHANGE(task, task_pri_chg, pri)
|
||||
#define TRACE_TASK_SUSPEND(task, task_suspended)
|
||||
#define TRACE_TASK_RESUME(task, task_resumed)
|
||||
#define TRACE_TASK_DEL(task, task_del)
|
||||
#define TRACE_TASK_WAIT_ABORT(task, task_abort)
|
||||
|
||||
/* semaphore trace */
|
||||
#define TRACE_SEM_CREATE(task, sem)
|
||||
#define TRACE_SEM_OVERFLOW(task, sem)
|
||||
#define TRACE_SEM_CNT_INCREASE(task, sem)
|
||||
#define TRACE_SEM_GET_SUCCESS(task, sem)
|
||||
#define TRACE_SEM_GET_BLK(task, sem, wait_option)
|
||||
#define TRACE_SEM_TASK_WAKE(task, task_waked_up, sem, opt_wake_all)
|
||||
#define TRACE_SEM_DEL(task, sem)
|
||||
|
||||
/* mutex trace */
|
||||
#define TRACE_MUTEX_CREATE(task, mutex, name)
|
||||
#define TRACE_MUTEX_RELEASE(task, task_release, new_pri)
|
||||
#define TRACE_MUTEX_GET(task, mutex, wait_option)
|
||||
#define TRACE_TASK_PRI_INV(task, mtxtsk)
|
||||
#define TRACE_MUTEX_GET_BLK(task, mutex, wait_option)
|
||||
#define TRACE_MUTEX_RELEASE_SUCCESS(task, mutex)
|
||||
#define TRACE_MUTEX_TASK_WAKE(task, task_waked_up, mutex)
|
||||
#define TRACE_MUTEX_DEL(task, mutex)
|
||||
|
||||
/* event trace */
|
||||
#define TRACE_EVENT_CREATE(task, event, name, flags_init)
|
||||
#define TRACE_EVENT_GET(task, event)
|
||||
#define TRACE_EVENT_GET_BLK(task, event, wait_option)
|
||||
#define TRACE_EVENT_TASK_WAKE(task, task_waked_up, event)
|
||||
#define TRACE_EVENT_DEL(task, event)
|
||||
|
||||
/* buf_queue trace */
|
||||
#define TRACE_BUF_QUEUE_CREATE(task, buf_queue)
|
||||
#define TRACE_BUF_QUEUE_MAX(task, buf_queue, msg, msg_size)
|
||||
#define TRACE_BUF_QUEUE_POST(task, buf_queue, msg, msg_size)
|
||||
#define TRACE_BUF_QUEUE_TASK_WAKE(task, task_waked_up, queue)
|
||||
#define TRACE_BUF_QUEUE_GET_BLK(task, buf_queue, wait_option)
|
||||
|
||||
/* timer trace */
|
||||
#define TRACE_TIMER_CREATE(task, timer)
|
||||
#define TRACE_TIMER_DEL(task, timer)
|
||||
|
||||
/* MBLK trace */
|
||||
#define TRACE_MBLK_POOL_CREATE(task, pool)
|
||||
|
||||
/* MM trace */
|
||||
#define TRACE_MM_POOL_CREATE(task, pool)
|
||||
|
||||
/* MM region trace*/
|
||||
#define TRACE_MM_REGION_CREATE(task, regions)
|
||||
|
||||
/* work queue trace */
|
||||
#define TRACE_WORK_INIT(task, work)
|
||||
#define TRACE_WORKQUEUE_CREATE(task, workqueue)
|
||||
#define TRACE_WORKQUEUE_DEL(task, workqueue)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
86
csky/csi_kernel/rhino/core/include/k_workqueue.h
Normal file
86
csky/csi_kernel/rhino/core/include/k_workqueue.h
Normal file
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#ifndef K_WORKQUEUE_H
|
||||
#define K_WORKQUEUE_H
|
||||
|
||||
#if (RHINO_CONFIG_WORKQUEUE > 0)
|
||||
#define WORKQUEUE_WORK_MAX 32
|
||||
|
||||
typedef void (*work_handle_t)(void *arg);
|
||||
|
||||
typedef struct {
|
||||
klist_t work_node;
|
||||
work_handle_t handle;
|
||||
void *arg;
|
||||
tick_t dly;
|
||||
ktimer_t *timer;
|
||||
void *wq;
|
||||
uint8_t work_exit;
|
||||
} kwork_t;
|
||||
|
||||
typedef struct {
|
||||
klist_t workqueue_node;
|
||||
klist_t work_list;
|
||||
kwork_t *work_current; /* current work */
|
||||
const name_t *name;
|
||||
ktask_t worker;
|
||||
ksem_t sem;
|
||||
} kworkqueue_t;
|
||||
|
||||
/**
|
||||
* This function will creat a workqueue
|
||||
* @param[in] workqueue the workqueue to be created
|
||||
* @param[in] name the name of workqueue/worker, which should be unique
|
||||
* @param[in] pri the priority of the worker
|
||||
* @param[in] stack_buf the stack of the worker(task)
|
||||
* @param[in] stack_size the size of the worker-stack
|
||||
* @return the operation status, RHINO_SUCCESS is OK, others is error
|
||||
*/
|
||||
kstat_t krhino_workqueue_create(kworkqueue_t *workqueue, const name_t *name,
|
||||
uint8_t pri, cpu_stack_t *stack_buf, size_t stack_size);
|
||||
|
||||
/**
|
||||
* This function will delete a workqueue
|
||||
* @param[in] workqueue the workqueue to be deleted
|
||||
* @return the operation status, RHINO_SUCCESS is OK, others is error
|
||||
*/
|
||||
kstat_t krhino_workqueue_del(kworkqueue_t *workqueue);
|
||||
|
||||
/**
|
||||
* This function will initialize a work
|
||||
* @param[in] work the work to be initialized
|
||||
* @param[in] handle the call back function to run
|
||||
* @param[in] arg the paraments of the function
|
||||
* @param[in] dly the ticks to delay before run
|
||||
* @return the operation status, RHINO_SUCCESS is OK, others is error
|
||||
*/
|
||||
kstat_t krhino_work_init(kwork_t *work, work_handle_t handle, void *arg,
|
||||
tick_t dly);
|
||||
|
||||
/**
|
||||
* This function will run a work on a workqueue
|
||||
* @param[in] workqueue the workqueue to run work
|
||||
* @param[in] work the work to run
|
||||
* @return the operation status, RHINO_SUCCESS is OK, others is error
|
||||
*/
|
||||
kstat_t krhino_work_run(kworkqueue_t *workqueue, kwork_t *work);
|
||||
|
||||
/**
|
||||
* This function will run a work on the default workqueue
|
||||
* @param[in] work the work to run
|
||||
* @return the operation status, RHINO_SUCCESS is OK, others is error
|
||||
*/
|
||||
kstat_t krhino_work_sched(kwork_t *work);
|
||||
|
||||
/**
|
||||
* This function will cancel a work
|
||||
* @param[in] work the work to cancel
|
||||
* @return the operation status, RHINO_SUCCESS is OK, others is error
|
||||
*/
|
||||
kstat_t krhino_work_cancel(kwork_t *work);
|
||||
#endif
|
||||
|
||||
#endif /* K_WORKQUEUE_H */
|
||||
|
||||
439
csky/csi_kernel/rhino/core/k_buf_queue.c
Normal file
439
csky/csi_kernel/rhino/core/k_buf_queue.c
Normal file
@@ -0,0 +1,439 @@
|
||||
/*
|
||||
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
|
||||
*/
|
||||
|
||||
#include <k_api.h>
|
||||
|
||||
#if (RHINO_CONFIG_BUF_QUEUE > 0)
|
||||
|
||||
static kstat_t buf_queue_create(kbuf_queue_t *queue, const name_t *name,
|
||||
void *buf, size_t size, size_t max_msg, uint8_t mm_alloc_flag, size_t type)
|
||||
{
|
||||
CPSR_ALLOC();
|
||||
|
||||
NULL_PARA_CHK(queue);
|
||||
NULL_PARA_CHK(buf);
|
||||
NULL_PARA_CHK(name);
|
||||
|
||||
if (max_msg == 0u) {
|
||||
return RHINO_INV_PARAM;
|
||||
}
|
||||
|
||||
if (size == 0u) {
|
||||
return RHINO_BUF_QUEUE_SIZE_ZERO;
|
||||
}
|
||||
|
||||
/* init the queue blocked list */
|
||||
klist_init(&queue->blk_obj.blk_list);
|
||||
klist_init(&queue->sblk_obj.blk_list);
|
||||
|
||||
queue->buf = buf;
|
||||
queue->cur_num = 0u;
|
||||
queue->peak_num = 0u;
|
||||
queue->max_msg_size = max_msg;
|
||||
queue->blk_obj.name = name;
|
||||
queue->blk_obj.blk_policy = BLK_POLICY_PRI;
|
||||
queue->sblk_obj.name = name;
|
||||
queue->sblk_obj.blk_policy = BLK_POLICY_PRI;
|
||||
queue->mm_alloc_flag = mm_alloc_flag;
|
||||
|
||||
RHINO_CRITICAL_ENTER();
|
||||
#if (RHINO_CONFIG_SYSTEM_STATS > 0)
|
||||
klist_insert(&(g_kobj_list.buf_queue_head), &queue->buf_queue_item);
|
||||
#endif
|
||||
RHINO_CRITICAL_EXIT();
|
||||
|
||||
queue->blk_obj.obj_type = RHINO_BUF_QUEUE_OBJ_TYPE;
|
||||
queue->sblk_obj.obj_type = RHINO_BUF_QUEUE_OBJ_TYPE;
|
||||
|
||||
ringbuf_init(&(queue->ringbuf), buf, size, type, max_msg);
|
||||
queue->min_free_buf_size = queue->ringbuf.freesize;
|
||||
TRACE_BUF_QUEUE_CREATE(krhino_cur_task_get(), queue);
|
||||
|
||||
return RHINO_SUCCESS;
|
||||
}
|
||||
|
||||
kstat_t krhino_buf_queue_create(kbuf_queue_t *queue, const name_t *name,
|
||||
void *buf, size_t size, size_t max_msg)
|
||||
{
|
||||
return buf_queue_create(queue, name, buf, size, max_msg, K_OBJ_STATIC_ALLOC, RINGBUF_TYPE_DYN);
|
||||
}
|
||||
|
||||
kstat_t krhino_fix_buf_queue_create(kbuf_queue_t *queue, const name_t *name,
|
||||
void *buf, size_t msg_size, size_t msg_num)
|
||||
{
|
||||
return buf_queue_create(queue, name, buf, msg_size * msg_num, msg_size, K_OBJ_STATIC_ALLOC, RINGBUF_TYPE_FIX);
|
||||
}
|
||||
|
||||
kstat_t krhino_buf_queue_del(kbuf_queue_t *queue)
|
||||
{
|
||||
CPSR_ALLOC();
|
||||
|
||||
klist_t *head;
|
||||
|
||||
NULL_PARA_CHK(queue);
|
||||
|
||||
RHINO_CRITICAL_ENTER();
|
||||
|
||||
INTRPT_NESTED_LEVEL_CHK();
|
||||
|
||||
if (queue->blk_obj.obj_type != RHINO_BUF_QUEUE_OBJ_TYPE) {
|
||||
RHINO_CRITICAL_EXIT();
|
||||
return RHINO_KOBJ_TYPE_ERR;
|
||||
}
|
||||
|
||||
if (queue->mm_alloc_flag != K_OBJ_STATIC_ALLOC) {
|
||||
RHINO_CRITICAL_EXIT();
|
||||
return RHINO_KOBJ_DEL_ERR;
|
||||
}
|
||||
|
||||
head = &queue->blk_obj.blk_list;
|
||||
|
||||
queue->blk_obj.obj_type = RHINO_OBJ_TYPE_NONE;
|
||||
|
||||
/* all task blocked on this queue is waken up */
|
||||
while (!is_klist_empty(head)) {
|
||||
|
||||
pend_task_rm(krhino_list_entry(head->next, ktask_t, task_list));
|
||||
}
|
||||
|
||||
head = &queue->sblk_obj.blk_list;
|
||||
queue->sblk_obj.obj_type = RHINO_OBJ_TYPE_NONE;
|
||||
/* all task blocked on this queue is waken up */
|
||||
while (!is_klist_empty(head)) {
|
||||
pend_task_rm(krhino_list_entry(head->next, ktask_t, task_list));
|
||||
}
|
||||
|
||||
#if (RHINO_CONFIG_SYSTEM_STATS > 0)
|
||||
klist_rm(&queue->buf_queue_item);
|
||||
#endif
|
||||
|
||||
ringbuf_reset(&queue->ringbuf);
|
||||
|
||||
RHINO_CRITICAL_EXIT_SCHED();
|
||||
|
||||
return RHINO_SUCCESS;
|
||||
}
|
||||
|
||||
#if (RHINO_CONFIG_KOBJ_DYN_ALLOC > 0)
|
||||
kstat_t krhino_buf_queue_dyn_create(kbuf_queue_t **queue, const name_t *name,
|
||||
size_t size, size_t max_msg)
|
||||
{
|
||||
kstat_t stat;
|
||||
kbuf_queue_t *queue_obj;
|
||||
|
||||
NULL_PARA_CHK(queue);
|
||||
|
||||
if (size == 0u) {
|
||||
return RHINO_BUF_QUEUE_SIZE_ZERO;
|
||||
}
|
||||
|
||||
queue_obj = krhino_mm_alloc(sizeof(kbuf_queue_t), __builtin_return_address(0));
|
||||
|
||||
if (queue_obj == NULL) {
|
||||
return RHINO_NO_MEM;
|
||||
}
|
||||
|
||||
queue_obj->buf = krhino_mm_alloc(size, __builtin_return_address(0));
|
||||
|
||||
if (queue_obj->buf == NULL) {
|
||||
krhino_mm_free(queue_obj);
|
||||
return RHINO_NO_MEM;
|
||||
}
|
||||
|
||||
stat = buf_queue_create(queue_obj, name, queue_obj->buf, size, max_msg,
|
||||
K_OBJ_DYN_ALLOC, RINGBUF_TYPE_DYN);
|
||||
|
||||
if (stat != RHINO_SUCCESS) {
|
||||
krhino_mm_free(queue_obj->buf);
|
||||
krhino_mm_free(queue_obj);
|
||||
return stat;
|
||||
}
|
||||
|
||||
*queue = queue_obj;
|
||||
|
||||
return RHINO_SUCCESS;
|
||||
}
|
||||
|
||||
kstat_t krhino_buf_queue_dyn_del(kbuf_queue_t *queue)
|
||||
{
|
||||
CPSR_ALLOC();
|
||||
klist_t *head;
|
||||
|
||||
NULL_PARA_CHK(queue);
|
||||
|
||||
RHINO_CRITICAL_ENTER();
|
||||
|
||||
INTRPT_NESTED_LEVEL_CHK();
|
||||
|
||||
if (queue->blk_obj.obj_type != RHINO_BUF_QUEUE_OBJ_TYPE) {
|
||||
RHINO_CRITICAL_EXIT();
|
||||
return RHINO_KOBJ_TYPE_ERR;
|
||||
}
|
||||
|
||||
if (queue->mm_alloc_flag != K_OBJ_DYN_ALLOC) {
|
||||
RHINO_CRITICAL_EXIT();
|
||||
return RHINO_KOBJ_DEL_ERR;
|
||||
}
|
||||
|
||||
head = &queue->blk_obj.blk_list;
|
||||
|
||||
queue->blk_obj.obj_type = RHINO_OBJ_TYPE_NONE;
|
||||
while (!is_klist_empty(head)) {
|
||||
pend_task_rm(krhino_list_entry(head->next, ktask_t, task_list));
|
||||
}
|
||||
|
||||
head = &queue->sblk_obj.blk_list;
|
||||
queue->sblk_obj.obj_type = RHINO_OBJ_TYPE_NONE;
|
||||
while (!is_klist_empty(head)) {
|
||||
pend_task_rm(krhino_list_entry(head->next, ktask_t, task_list));
|
||||
}
|
||||
|
||||
#if (RHINO_CONFIG_SYSTEM_STATS > 0)
|
||||
klist_rm(&queue->buf_queue_item);
|
||||
#endif
|
||||
|
||||
ringbuf_reset(&queue->ringbuf);
|
||||
|
||||
RHINO_CRITICAL_EXIT_SCHED();
|
||||
krhino_mm_free(queue->buf);
|
||||
krhino_mm_free(queue);
|
||||
|
||||
return RHINO_SUCCESS;
|
||||
}
|
||||
#endif
|
||||
|
||||
static kstat_t buf_queue_send(kbuf_queue_t *queue, void *msg, size_t msg_size, tick_t ticks)
|
||||
{
|
||||
CPSR_ALLOC();
|
||||
|
||||
klist_t *head;
|
||||
ktask_t *task;
|
||||
kstat_t err;
|
||||
|
||||
uint8_t cur_cpu_num;
|
||||
|
||||
/* this is only needed when system zero interrupt feature is enabled */
|
||||
#if (RHINO_CONFIG_INTRPT_GUARD > 0)
|
||||
soc_intrpt_guard();
|
||||
#endif
|
||||
|
||||
__retry:
|
||||
RHINO_CRITICAL_ENTER();
|
||||
|
||||
if (queue->blk_obj.obj_type != RHINO_BUF_QUEUE_OBJ_TYPE) {
|
||||
RHINO_CRITICAL_EXIT();
|
||||
return RHINO_KOBJ_TYPE_ERR;
|
||||
}
|
||||
|
||||
cur_cpu_num = cpu_cur_get();
|
||||
(void)cur_cpu_num;
|
||||
|
||||
if (msg_size > queue->max_msg_size) {
|
||||
TRACE_BUF_QUEUE_MAX(g_active_task[cur_cpu_num], queue, msg, msg_size);
|
||||
RHINO_CRITICAL_EXIT();
|
||||
return RHINO_BUF_QUEUE_MSG_SIZE_OVERFLOW;
|
||||
}
|
||||
|
||||
if (msg_size == 0) {
|
||||
RHINO_CRITICAL_EXIT();
|
||||
return RHINO_INV_PARAM;
|
||||
}
|
||||
|
||||
head = &queue->blk_obj.blk_list;
|
||||
|
||||
/* buf queue is not full here, if there is no blocked receive task */
|
||||
if (is_klist_empty(head)) {
|
||||
|
||||
err = ringbuf_push(&(queue->ringbuf), msg, msg_size);
|
||||
|
||||
if (err != RHINO_SUCCESS) {
|
||||
if (err == RHINO_RINGBUF_FULL) {
|
||||
if(ticks){
|
||||
pend_to_blk_obj((blk_obj_t *)&queue->sblk_obj.blk_list, g_active_task[cur_cpu_num], ticks, psr);
|
||||
RHINO_CRITICAL_EXIT_SCHED();
|
||||
|
||||
RHINO_CPU_INTRPT_DISABLE();
|
||||
err = pend_state_end_proc(g_active_task[cur_cpu_num]);
|
||||
RHINO_CPU_INTRPT_ENABLE();
|
||||
if(err == RHINO_SUCCESS){
|
||||
goto __retry;
|
||||
}
|
||||
|
||||
RHINO_CRITICAL_ENTER();
|
||||
}
|
||||
err = RHINO_BUF_QUEUE_FULL;
|
||||
}
|
||||
RHINO_CRITICAL_EXIT();
|
||||
return err;
|
||||
}
|
||||
|
||||
queue->cur_num ++;
|
||||
|
||||
if (queue->peak_num < queue->cur_num) {
|
||||
queue->peak_num = queue->cur_num;
|
||||
}
|
||||
|
||||
if (queue->min_free_buf_size > queue->ringbuf.freesize) {
|
||||
queue->min_free_buf_size = queue->ringbuf.freesize;
|
||||
}
|
||||
|
||||
TRACE_BUF_QUEUE_POST(g_active_task[cur_cpu_num], queue, msg, msg_size);
|
||||
|
||||
RHINO_CRITICAL_EXIT();
|
||||
return RHINO_SUCCESS;
|
||||
}
|
||||
|
||||
task = krhino_list_entry(head->next, ktask_t, task_list);
|
||||
memcpy(task->msg, msg, msg_size);
|
||||
task->bq_msg_size = msg_size;
|
||||
|
||||
pend_task_wakeup(task);
|
||||
|
||||
TRACE_BUF_QUEUE_TASK_WAKE(g_active_task[cur_cpu_num], task, queue);
|
||||
|
||||
RHINO_CRITICAL_EXIT_SCHED();
|
||||
|
||||
return RHINO_SUCCESS;
|
||||
}
|
||||
|
||||
kstat_t krhino_buf_queue_send(kbuf_queue_t *queue, void *msg, size_t size, tick_t ticks)
|
||||
{
|
||||
NULL_PARA_CHK(queue);
|
||||
NULL_PARA_CHK(msg);
|
||||
|
||||
return buf_queue_send(queue, msg, size, ticks);
|
||||
}
|
||||
|
||||
kstat_t krhino_buf_queue_recv(kbuf_queue_t *queue, tick_t ticks, void *msg,
|
||||
size_t *size)
|
||||
{
|
||||
CPSR_ALLOC();
|
||||
klist_t *blk_list_head;
|
||||
|
||||
kstat_t ret;
|
||||
uint8_t cur_cpu_num;
|
||||
|
||||
NULL_PARA_CHK(queue);
|
||||
NULL_PARA_CHK(msg);
|
||||
NULL_PARA_CHK(size);
|
||||
|
||||
krhino_check_fatal_call(__FUNCTION__);
|
||||
RHINO_CRITICAL_ENTER();
|
||||
|
||||
cur_cpu_num = cpu_cur_get();
|
||||
|
||||
if ((g_intrpt_nested_level[cur_cpu_num] > 0u) && (ticks != RHINO_NO_WAIT)) {
|
||||
RHINO_CRITICAL_EXIT();
|
||||
return RHINO_NOT_CALLED_BY_INTRPT;
|
||||
}
|
||||
|
||||
if (queue->blk_obj.obj_type != RHINO_BUF_QUEUE_OBJ_TYPE) {
|
||||
RHINO_CRITICAL_EXIT();
|
||||
return RHINO_KOBJ_TYPE_ERR;
|
||||
}
|
||||
|
||||
blk_list_head = &queue->sblk_obj.blk_list;
|
||||
if (!ringbuf_is_empty(&(queue->ringbuf))) {
|
||||
ringbuf_pop(&(queue->ringbuf), msg, size);
|
||||
queue->cur_num --;
|
||||
while (!is_klist_empty(blk_list_head)) {
|
||||
pend_task_wakeup(krhino_list_entry(blk_list_head->next, ktask_t, task_list));
|
||||
}
|
||||
RHINO_CRITICAL_EXIT_SCHED();
|
||||
return RHINO_SUCCESS;
|
||||
}
|
||||
|
||||
if (ticks == RHINO_NO_WAIT) {
|
||||
*size = 0u;
|
||||
RHINO_CRITICAL_EXIT();
|
||||
return RHINO_NO_PEND_WAIT;
|
||||
}
|
||||
|
||||
if (g_sched_lock[cur_cpu_num] > 0u) {
|
||||
*size = 0u;
|
||||
RHINO_CRITICAL_EXIT();
|
||||
return RHINO_SCHED_DISABLE;
|
||||
}
|
||||
|
||||
g_active_task[cur_cpu_num]->msg = msg;
|
||||
pend_to_blk_obj((blk_obj_t *)queue, g_active_task[cur_cpu_num], ticks, psr);
|
||||
|
||||
TRACE_BUF_QUEUE_GET_BLK(g_active_task[cur_cpu_num], queue, ticks);
|
||||
|
||||
RHINO_CRITICAL_EXIT_SCHED();
|
||||
|
||||
RHINO_CPU_INTRPT_DISABLE();
|
||||
|
||||
cur_cpu_num = cpu_cur_get();
|
||||
|
||||
ret = pend_state_end_proc(g_active_task[cur_cpu_num]);
|
||||
|
||||
switch (ret) {
|
||||
case RHINO_SUCCESS:
|
||||
*size = g_active_task[cur_cpu_num]->bq_msg_size;
|
||||
break;
|
||||
|
||||
default:
|
||||
*size = 0u;
|
||||
break;
|
||||
}
|
||||
|
||||
RHINO_CPU_INTRPT_ENABLE();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
kstat_t krhino_buf_queue_flush(kbuf_queue_t *queue)
|
||||
{
|
||||
CPSR_ALLOC();
|
||||
|
||||
NULL_PARA_CHK(queue);
|
||||
|
||||
RHINO_CRITICAL_ENTER();
|
||||
|
||||
INTRPT_NESTED_LEVEL_CHK();
|
||||
|
||||
if (queue->blk_obj.obj_type != RHINO_BUF_QUEUE_OBJ_TYPE) {
|
||||
RHINO_CRITICAL_EXIT();
|
||||
return RHINO_KOBJ_TYPE_ERR;
|
||||
}
|
||||
|
||||
ringbuf_reset(&(queue->ringbuf));
|
||||
queue->cur_num = 0u;
|
||||
queue->peak_num = 0u;
|
||||
queue->min_free_buf_size = queue->ringbuf.freesize;
|
||||
|
||||
RHINO_CRITICAL_EXIT();
|
||||
|
||||
return RHINO_SUCCESS;
|
||||
}
|
||||
|
||||
kstat_t krhino_buf_queue_info_get(kbuf_queue_t *queue, kbuf_queue_info_t *info)
|
||||
{
|
||||
CPSR_ALLOC();
|
||||
|
||||
NULL_PARA_CHK(queue);
|
||||
NULL_PARA_CHK(info);
|
||||
|
||||
RHINO_CRITICAL_ENTER();
|
||||
|
||||
if (queue->blk_obj.obj_type != RHINO_BUF_QUEUE_OBJ_TYPE) {
|
||||
RHINO_CRITICAL_EXIT();
|
||||
return RHINO_KOBJ_TYPE_ERR;
|
||||
}
|
||||
|
||||
info->free_buf_size = queue->ringbuf.freesize;
|
||||
info->min_free_buf_size = queue->min_free_buf_size;
|
||||
info->buf_size = queue->ringbuf.end - queue->ringbuf.buf;
|
||||
info->max_msg_size = queue->max_msg_size;
|
||||
info->cur_num = queue->cur_num;
|
||||
info->peak_num = queue->peak_num;
|
||||
|
||||
RHINO_CRITICAL_EXIT();
|
||||
|
||||
return RHINO_SUCCESS;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user