diff --git a/bk7235/hals/communication/wifi_lite/wifiservice/source/wifi_device_util.h b/bk7235/hals/communication/wifi_lite/wifiservice/source/wifi_device_util.h index 66eea9c8c45759866090d794c788a90ce35e882c..70644254ddc76ac8a3a17d0aca4d9c5e8e30a97c 100755 --- a/bk7235/hals/communication/wifi_lite/wifiservice/source/wifi_device_util.h +++ b/bk7235/hals/communication/wifi_lite/wifiservice/source/wifi_device_util.h @@ -1,3 +1,16 @@ +// Copyright (C) 2022 Beken Corporation +// 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 _WIFI_DEVICE_UTIL_H #define _WIFI_DEVICE_UTIL_H diff --git a/bk7235/hals/iot_hardware/wifiiot_lite/hal_iot_flash.c b/bk7235/hals/iot_hardware/wifiiot_lite/hal_iot_flash.c index c31c7dfee24a1e9bd21e0559850d0a38d4f499a7..a2f89d89e64487997889fcdc971fb6e257f57f92 100755 --- a/bk7235/hals/iot_hardware/wifiiot_lite/hal_iot_flash.c +++ b/bk7235/hals/iot_hardware/wifiiot_lite/hal_iot_flash.c @@ -1,3 +1,16 @@ +// Copyright (C) 2022 Beken Corporation +// 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 "iot_errno.h" #include "iot_flash.h" #include "flash.h" @@ -48,4 +61,4 @@ unsigned int IoTFlashDeinit(void) { bk_flash_set_protect_type(protect_flag); return IOT_SUCCESS; -} \ No newline at end of file +} diff --git a/bk7235/hals/iot_hardware/wifiiot_lite/hal_iot_gpio.c b/bk7235/hals/iot_hardware/wifiiot_lite/hal_iot_gpio.c index 886d9b0b838f3bb55eb9f7ae7bf214b3c2672b08..820ed13ff9dfd6a66cf4027a74a1e28e6c7edc10 100755 --- a/bk7235/hals/iot_hardware/wifiiot_lite/hal_iot_gpio.c +++ b/bk7235/hals/iot_hardware/wifiiot_lite/hal_iot_gpio.c @@ -1,3 +1,16 @@ +// Copyright (C) 2022 Beken Corporation +// 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 "iot_errno.h" #include "iot_gpio.h" diff --git a/bk7235/hals/iot_hardware/wifiiot_lite/hal_iot_i2c.c b/bk7235/hals/iot_hardware/wifiiot_lite/hal_iot_i2c.c index b83b3946251038dcc4a5996617b49dd65c0f8d57..0d10c40ad042694a962e0b446cc3d67d05c380e6 100755 --- a/bk7235/hals/iot_hardware/wifiiot_lite/hal_iot_i2c.c +++ b/bk7235/hals/iot_hardware/wifiiot_lite/hal_iot_i2c.c @@ -1,3 +1,16 @@ +// Copyright (C) 2022 Beken Corporation +// 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 "iot_errno.h" #include "iot_i2c.h" diff --git a/bk7235/hals/iot_hardware/wifiiot_lite/hal_iot_pwm.c b/bk7235/hals/iot_hardware/wifiiot_lite/hal_iot_pwm.c index b7f96eb28091fcd4fd9bac5988a6e240381b20b2..26fad191e0c2a219bbbd7481e85c061f9546021c 100755 --- a/bk7235/hals/iot_hardware/wifiiot_lite/hal_iot_pwm.c +++ b/bk7235/hals/iot_hardware/wifiiot_lite/hal_iot_pwm.c @@ -1,3 +1,16 @@ +// Copyright (C) 2022 Beken Corporation +// 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 "iot_errno.h" #include "iot_pwm.h" diff --git a/bk7235/hals/iot_hardware/wifiiot_lite/hal_iot_uart.c b/bk7235/hals/iot_hardware/wifiiot_lite/hal_iot_uart.c index e42fd3bf4ecf5ea8a6900ee3f9731cec4e902c25..fffee75bf8c5ec14f5d0cf52a16b96fe86572625 100755 --- a/bk7235/hals/iot_hardware/wifiiot_lite/hal_iot_uart.c +++ b/bk7235/hals/iot_hardware/wifiiot_lite/hal_iot_uart.c @@ -1,3 +1,16 @@ +// Copyright (C) 2022 Beken Corporation +// 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 "iot_errno.h" #include "iot_uart.h" diff --git a/bk7235/hals/iot_hardware/wifiiot_lite/hal_iot_watchdog.c b/bk7235/hals/iot_hardware/wifiiot_lite/hal_iot_watchdog.c index 180eabbf55331bf98a4666c32b68f54ba10d9f96..968a1b038a4fd6752e7348f2ad9f88562b0402cd 100755 --- a/bk7235/hals/iot_hardware/wifiiot_lite/hal_iot_watchdog.c +++ b/bk7235/hals/iot_hardware/wifiiot_lite/hal_iot_watchdog.c @@ -1,3 +1,16 @@ +// Copyright (C) 2022 Beken Corporation +// 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 "iot_errno.h" #include "iot_watchdog.h" diff --git a/bk7235/hals/iot_hardware/wifiiot_lite/hal_lowpower.c b/bk7235/hals/iot_hardware/wifiiot_lite/hal_lowpower.c index 1e3d27e252e2e4169483adb52df88020838ab30f..4f795a6f9608db42f76100d0c94216aa1ce24db3 100755 --- a/bk7235/hals/iot_hardware/wifiiot_lite/hal_lowpower.c +++ b/bk7235/hals/iot_hardware/wifiiot_lite/hal_lowpower.c @@ -1,3 +1,16 @@ +// Copyright (C) 2022 Beken Corporation +// 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 "iot_errno.h" #include "lowpower.h" diff --git a/bk7235/hals/iot_hardware/wifiiot_lite/hal_reset.c b/bk7235/hals/iot_hardware/wifiiot_lite/hal_reset.c index 03532583b61e09401843c0eaa818f49cc1ce1c52..a10b962a72c37a35e9409198f30817a3a5b43dad 100755 --- a/bk7235/hals/iot_hardware/wifiiot_lite/hal_reset.c +++ b/bk7235/hals/iot_hardware/wifiiot_lite/hal_reset.c @@ -1,3 +1,16 @@ +// Copyright (C) 2022 Beken Corporation +// 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 "iot_errno.h" #include "reset.h" #include diff --git a/bk7235/hals/iot_hardware/wifiiot_lite/iot_test.c b/bk7235/hals/iot_hardware/wifiiot_lite/iot_test.c index 19ef0ec79d0227426ae2e2b5f3063c73d1c42b72..8321ecb37e437838f9f15db56acd8de8729c4aff 100755 --- a/bk7235/hals/iot_hardware/wifiiot_lite/iot_test.c +++ b/bk7235/hals/iot_hardware/wifiiot_lite/iot_test.c @@ -1,3 +1,17 @@ +// Copyright (C) 2022 Beken Corporation +// 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 #include diff --git a/bk7235/hals/iot_hardware/wifiiot_lite/iot_test.h b/bk7235/hals/iot_hardware/wifiiot_lite/iot_test.h index 1ae35099efbec36cee2f0e031bcf1bfc8665543d..ef3327412b0d8bb41a0a74baf465d6ae28f2b397 100755 --- a/bk7235/hals/iot_hardware/wifiiot_lite/iot_test.h +++ b/bk7235/hals/iot_hardware/wifiiot_lite/iot_test.h @@ -1,3 +1,15 @@ +// Copyright (C) 2022 Beken Corporation +// 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. int iot_test_gpio(void); int iot_test_flash(void); diff --git a/bk7235/hals/update/hal_hota_board.c b/bk7235/hals/update/hal_hota_board.c index 7df88327c51a27b7f90de4ea42098602e510efc5..d102a9e94ad0e73f819bd744851c71425ada0e8b 100755 --- a/bk7235/hals/update/hal_hota_board.c +++ b/bk7235/hals/update/hal_hota_board.c @@ -1,3 +1,16 @@ +// Copyright (C) 2022 Beken Corporation +// 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 "hal_hota_board.h" #include diff --git a/bk7235/hals/utils/file/BUILD.gn b/bk7235/hals/utils/file/BUILD.gn index 74d9da7671714ee9d5d0a5658e96cbd2813b8e60..54959a333759433ad5c794df8af726a2790cf1b2 100755 --- a/bk7235/hals/utils/file/BUILD.gn +++ b/bk7235/hals/utils/file/BUILD.gn @@ -1,3 +1,17 @@ +# Copyright (C) 2022 Beken Corporation +# 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. + + import("//build/lite/config/component/lite_component.gni") import("${board_adapter_dir}/hals/sdk_dir.gni") diff --git a/bk7235/liteos_m/bk_sdk_armino/components/at/include/at_ble_common.h b/bk7235/liteos_m/bk_sdk_armino/components/at/include/at_ble_common.h index ba313a5b449026744a62d7a7b3b3df662f8c039f..8eabca99fe8b6f340de81be447356b149f741bc4 100755 --- a/bk7235/liteos_m/bk_sdk_armino/components/at/include/at_ble_common.h +++ b/bk7235/liteos_m/bk_sdk_armino/components/at/include/at_ble_common.h @@ -1,3 +1,17 @@ +/* + * Copyright (C) 2022 Beken Corporation + * 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 AT_BLE_COMMON_H_ #define AT_BLE_COMMON_H_ //#if (CONFIG_BLE_5_X || CONFIG_BTDM_5_2) diff --git a/bk7235/liteos_m/bk_sdk_armino/components/at/include/at_common.h b/bk7235/liteos_m/bk_sdk_armino/components/at/include/at_common.h index d4f2070346392126013e277f8ff3c209835b35f2..0529efe1fd0435ef28df5b6515dc3378181a3bee 100755 --- a/bk7235/liteos_m/bk_sdk_armino/components/at/include/at_common.h +++ b/bk7235/liteos_m/bk_sdk_armino/components/at/include/at_common.h @@ -1,3 +1,17 @@ +/* + * Copyright (C) 2022 Beken Corporation + * 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 AT_COMMON_H_ #define AT_COMMON_H_ diff --git a/bk7235/liteos_m/bk_sdk_armino/components/at/src/at_common.c b/bk7235/liteos_m/bk_sdk_armino/components/at/src/at_common.c index 725e93c2fa33b7d6a8ee80ed00fce0837570543d..c21e57f7871d4f281b025eea60924f092ea39ca4 100755 --- a/bk7235/liteos_m/bk_sdk_armino/components/at/src/at_common.c +++ b/bk7235/liteos_m/bk_sdk_armino/components/at/src/at_common.c @@ -1,3 +1,17 @@ +/* + * Copyright (C) 2022 Beken Corporation + * 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 "at_common.h" #if CONFIG_BT #include "bt_include.h" diff --git a/bk7235/liteos_m/bk_sdk_armino/components/at/src/ble_at_command.c b/bk7235/liteos_m/bk_sdk_armino/components/at/src/ble_at_command.c index a908da7e9c713fdaabe2073a2a34803087447ac6..ee67e890e28d7d1b3da15ee56a87d56826f57e99 100755 --- a/bk7235/liteos_m/bk_sdk_armino/components/at/src/ble_at_command.c +++ b/bk7235/liteos_m/bk_sdk_armino/components/at/src/ble_at_command.c @@ -1,3 +1,17 @@ +/* + * Copyright (C) 2022 Beken Corporation + * 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 #include #include "at_common.h" diff --git a/bk7235/liteos_m/bk_sdk_armino/components/at/src/bt_at_command.c b/bk7235/liteos_m/bk_sdk_armino/components/at/src/bt_at_command.c index 382cf4234e0992aa243016d7d8bf20a7636aa9c3..d7e5f13885ab789e89a1c3a14e22ac37c58e986e 100755 --- a/bk7235/liteos_m/bk_sdk_armino/components/at/src/bt_at_command.c +++ b/bk7235/liteos_m/bk_sdk_armino/components/at/src/bt_at_command.c @@ -1,3 +1,17 @@ +/* + * Copyright (C) 2022 Beken Corporation + * 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 #include #include "at_common.h" diff --git a/bk7235/liteos_m/bk_sdk_armino/components/at/src/video_at_command.c b/bk7235/liteos_m/bk_sdk_armino/components/at/src/video_at_command.c index 32d021d3169f1ee85fa475b6a3206632b2e39591..8d0521c48ae00ff4e848294e03abf1683b83fea1 100755 --- a/bk7235/liteos_m/bk_sdk_armino/components/at/src/video_at_command.c +++ b/bk7235/liteos_m/bk_sdk_armino/components/at/src/video_at_command.c @@ -1,3 +1,17 @@ +/* + * Copyright (C) 2022 Beken Corporation + * 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 "at_common.h" #include #include diff --git a/bk7235/liteos_m/bk_sdk_armino/components/at/src/wifi_at_command.c b/bk7235/liteos_m/bk_sdk_armino/components/at/src/wifi_at_command.c index 8de3f5678bc3721dcd1472785339b6276a0b6a93..746c22e58d90231fd1abb4c14a676120d19afe7f 100755 --- a/bk7235/liteos_m/bk_sdk_armino/components/at/src/wifi_at_command.c +++ b/bk7235/liteos_m/bk_sdk_armino/components/at/src/wifi_at_command.c @@ -1,3 +1,17 @@ +/* + * Copyright (C) 2022 Beken Corporation + * 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 "at_common.h" #include #include diff --git a/bk7235/liteos_m/bk_sdk_armino/components/at_server/CMakeLists.txt b/bk7235/liteos_m/bk_sdk_armino/components/at_server/CMakeLists.txt deleted file mode 100644 index 92e129ecb190a517ed9d4794b0ad15b329c26ff1..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/at_server/CMakeLists.txt +++ /dev/null @@ -1,26 +0,0 @@ -set(incs "") -set(srcs "") - -if (CONFIG_AT) - list(APPEND incs - . - _at_server - _at_server_port - at_server_func - atsvr_cmd - ) - - list(APPEND srcs - "_at_server_port/atsvr_core.c" - "_at_server_port/atsvr_port.c" - "atsvr_cmd/atsvr_cmd.c" - "atsvr_cmd/atsvr_wlan.c" - "atsvr_cmd/atsvr_misc.c" - "_at_server/_at_server.c" - "_at_server/_at_server_port.c" - "at_server_func/_atsvr_func.c" - "at_server.c" - ) -endif() - -armino_component_register(SRCS "${srcs}" INCLUDE_DIRS "${incs}" PRIV_REQUIRES bk_common) diff --git a/bk7235/liteos_m/bk_sdk_armino/components/at_server/Kconfig b/bk7235/liteos_m/bk_sdk_armino/components/at_server/Kconfig deleted file mode 100644 index 6d151e15210dcfccd5d6b70b6d9e0deef512ae05..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/at_server/Kconfig +++ /dev/null @@ -1,3 +0,0 @@ -config AT - bool "Enable AT" - default n diff --git a/bk7235/liteos_m/bk_sdk_armino/components/at_server/_at_server/_at_server.c b/bk7235/liteos_m/bk_sdk_armino/components/at_server/_at_server/_at_server.c deleted file mode 100755 index 3caf58519c28a83cb7767c50d1c1b477ae7d15c7..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/at_server/_at_server/_at_server.c +++ /dev/null @@ -1,438 +0,0 @@ -#include "_at_server.h" -#include "_atsvr_func.h" -#include "string.h" -#include "stdio.h" -#include "stdlib.h" - - -static const char *_atsvr_version_num = ATSVR_VERSION_NUM; - - -char *_get_atsvr_version(void) -{ - return (char*)_atsvr_version_num; -} - - -void _set_atsvr_echo_mode(_atsvr_env_t *env,_atsvr_echo_t echo) -{ - if(env){ - env->echo = echo; - } -} - -_atsvr_echo_t _get_atsvr_echo_mode(_atsvr_env_t *env) -{ - return env->echo; -} - -int _atsvr_register_command(_atsvr_env_t *env,const struct _atsvr_command *command) -{ - int i; - - if (!command->name || !command->function) { - return ATSVR_GENERAL; - } - - if (env->num_commands < ATSVR_MAX_COMMANDS){ - /* Check if the command has already been registered. - * Return 0, if it has been registered. - */ - for (i = 0; i < env->num_commands; i++){ - if (env->commands[i] == command){ - return ATSVR_GENERAL; - } - } - env->commands[env->num_commands++] = command; - ATSVRLOG("register \"%s\" command\r\n",command->name); - return ATSVR_OK; - } - - return ATSVR_ERROR; -} - -int _atsvr_unregister_command(_atsvr_env_t *env,const struct _atsvr_command *command) -{ - int i; - - if (!command->name || !command->function) { - return ATSVR_GENERAL; - } - - if (env->num_commands < ATSVR_MAX_COMMANDS){ - /* Check if the command has already been registered. - * Return 0, if it has been registered. - */ - for (i = 0; i < env->num_commands; i++){ - if (env->commands[i] == command){ - ATSVRLOG("unregister \"%s\" command\r\n",command->name); - env->commands[i] = NULL; - break; - } - } - } - - return ATSVR_OK; -} - -int _atsvr_register_commands(_atsvr_env_t *env,const struct _atsvr_command *commands,int num_commands) -{ - int i,sta; - - for (i = 0; i < num_commands; i++) { - sta = _atsvr_register_command(env, commands++); - if (sta != ATSVR_OK){ - return sta; - } - } - - return ATSVR_OK; -} - -int _atsvr_unregister_commands(_atsvr_env_t *env,const struct _atsvr_command *commands,int num_commands) -{ - int i,sta; - - for (i = 0; i < num_commands; i++) { - sta = _atsvr_unregister_command(env, commands++); - if (sta != ATSVR_OK){ - return sta; - } - } - - return ATSVR_OK; -} - - -void _atsvr_notice_ready(_atsvr_env_t *env) -{ - if(env && env->output_func){ - env->output_func(ATSVR_READY_MSG,sizeof(ATSVR_READY_MSG)-1); - } -} - -void _atsvr_cmd_analysis_notice_error(_atsvr_env_t *env) -{ - if(env && env->output_func){ - env->output_func(ATSVR_CMDMSG_ERROR_RSP,sizeof(ATSVR_CMDMSG_ERROR_RSP)-1); - } -} - -void _atsvr_cmd_rsp_ok(_atsvr_env_t *env) -{ - if(env && env->output_func){ - env->output_func(ATSVR_CMD_RSP_SUCCEED,sizeof(ATSVR_CMD_RSP_SUCCEED)-1); - } -} - -void _atsvr_cmd_rsp_error(_atsvr_env_t *env) -{ - if(env && env->output_func){ - env->output_func(ATSVR_CMD_RSP_ERROR,sizeof(ATSVR_CMD_RSP_ERROR)-1); - } -} - -void _atsvr_output_msg(_atsvr_env_t *env,char *msg,unsigned int msg_len) -{ - if(env && env->output_func){ - env->output_func(msg,msg_len); - } -} - - - -static const struct _atsvr_command *_atsvr_lookup_at_command(_atsvr_env_t *env,char *name, int len) -{ - int i = 0; - int n = 0; - int name_len,cmd_name_len; - - name_len = strlen(name); - while (i < ATSVR_MAX_COMMANDS && n < env->num_commands) { - if (env->commands[i]->name == NULL) { - i++; - continue; - } - #if defined(ATSVR_OPTIM_FD_CMD) && ATSVR_OPTIM_FD_CMD - cmd_name_len = env->commands[i]->name_len; - #else - cmd_name_len = strlen(env->commands[i]->name); - #endif - /* See if partial or full match is expected */ - if (len != 0) { - if ((cmd_name_len >= len) - && (!strncmp(env->commands[i]->name, name, len))) { - return env->commands[i]; - } - }else { - if ((cmd_name_len == name_len) - && (!strcmp(env->commands[i]->name, name))) { - return env->commands[i]; - } - } - - i++; - n++; - } - - return NULL; -} - -int _atsvc_command_handle(_atsvr_env_t *env,unsigned char argc,char **argv) -{ - const struct _atsvr_command *command = NULL; - int i; - char *p; - - i = ((p = strchr(argv[0], '.')) == NULL) ? 0 : (p - argv[0]); - - command = _atsvr_lookup_at_command(env,argv[0], i); - if ((command == NULL) || (NULL == command->function)) { - ATSVRLOG("[ATSVR]no find \"%s\" command\r\n",argv[0]); - return ATSVR_GENERAL; - } - -#if ATSVR_HANDLER_ENV - command->function(env, argc, argv); -#else - if(argc < ATSVR_MAX_ARG) { - argv[argc] = (char *)env; - } - command->function(argc, argv); -#endif - return ATSVR_OK; -} - -typedef struct{ - unsigned inArg : 1; - unsigned done : 1; - unsigned isD : 2; - unsigned limQ : 1; -}_atsvr_handle_input_stat; - -static int _atsvr_handle_input(_atsvr_env_t *env,unsigned char *inbuf,int len) -{ - _atsvr_handle_input_stat stat; -#if ATSVR_HANDLER_ENV - char *argv[ATSVR_MAX_ARG]; -#else - char *argv[ATSVR_MAX_ARG + 1]; -#endif - int argc = 0; - int i = 0; - int offset = 0; - - memset((void *)&argv, 0, sizeof(argv)); - memset(&stat, 0, sizeof(stat)); - - do - { - offset++; - if(offset > len){ - ATSVRLOG("The data is incomplete\r\n"); - return 7; ////error - } - switch (inbuf[i]) - { - case '\0': - if(((argc == 0)||(stat.isD == 1))||(stat.limQ)){ - ATSVRLOG("The data does not conform to the regulations %d\r\n",__LINE__); - return 2; - } - - stat.done = 1; - break; - case '=': - if(argc == 1) { - inbuf[i] = '\0'; - stat.inArg = 0; - stat.isD = 1; - } - else if(argc == 0){ - ATSVRLOG("The data does not conform to the regulations %d\r\n",__LINE__); - return 4; - } - break; -#if ATSVR_ADD_ESCAPE_CFG - case '\\': ////"\" - offset += 1; - if((offset + 1) > len){ - ATSVRLOG("The data does not conform to the regulations %d\r\n",__LINE__); - return 6; ////error - } - memmove(&inbuf[i],&inbuf[i+1],(len-offset) + 1); - break; -#endif - case ',': - if((stat.isD == 1)&&(argc == 1)) ///=, - { - ATSVRLOG("The data does not conform to the regulations %d\r\n",__LINE__); - return 5; - } - if(stat.inArg) { - stat.inArg = 0; - inbuf[i] = '\0'; - stat.limQ = 1; - } - break; - default: - if(!stat.inArg) { - stat.inArg = 1; - argc++; - argv[argc - 1] = (char*)&inbuf[i]; - stat.limQ = 0; - if(stat.isD == 1) { - stat.isD = 2; - } - } - break; - } - } - while (!stat.done && (++i < ATSVR_INPUT_BUFF_MAX_SIZE)); - - if (argc < 1) { - ATSVRLOG("Data parsing exception\r\n"); - return 3; - } - - return _atsvc_command_handle(env,argc,argv); -} - - -int _atsvr_input_msg_analysis_handler(_atsvr_env_t *env,char *msg,unsigned int msg_len) -{ - int ret; - - if(env == NULL){ - return ATSVR_SEVERE_ERR; - } - - if( env->echo != _ATSVR_ECHO_NONE ) { - if(env->output_func){ - env->output_func(msg, msg_len - 1); - env->output_func("\r\n\r\n",4); - } - } - - ret = _atsvr_handle_input(env,(unsigned char*)msg,msg_len); - if(ret != ATSVR_OK) { - goto error; - } - - return ATSVR_OK; -error: - _atsvr_cmd_analysis_notice_error(env); - return ATSVR_ERROR; -} - - -int _atsvr_def_config(_atsvr_env_t *env) -{ - int i; - - if(env == NULL){ - return ATSVR_SEVERE_ERR; - } - - env->num_commands = 0; - for(i = 0;i < ATSVR_MAX_COMMANDS; i++){ - env->commands[i] = NULL; - } - env->output_func = NULL; - env->echo = ATSVR_ECHO_DEFAULT; -#if ATSVR_INTERNAL_CMD - _atsvr_def_cmd_init(env); -#endif - return ATSVR_OK; -} - -void _atsvr_register_output_func(_atsvr_env_t *env,output_func_t output_func) -{ - if( env ){ - env->output_func = output_func; - } -} - -///Register the resource critical protection function -void _atsvr_register_resources_protection_func(_atsvr_env_t *env,resources_protection res_prot) -{ - if( env ) { - env->res_prot = res_prot; - } -} - -int _atsvr_resource_protection_lock(_atsvr_env_t *env) -{ - if(env->res_prot) { - if(env->res_prot(1,0xFFFFFFFFU) != 0) { - return ATSVR_ERROR; - } - } - return ATSVR_OK; -} - -int _atsvr_resource_protection_lock_timeout(_atsvr_env_t *env,unsigned int timeout) -{ - if( env->res_prot ) { - if(env->res_prot(1,timeout) != 0){ - return ATSVR_ERROR; - } - } - return ATSVR_OK; -} - -void _atsvr_resource_protection_unlock(_atsvr_env_t *env) -{ - if(env->res_prot) { - env->res_prot(0, 0); - } -} - -void _atsvr_register_input_msg_func(_atsvr_env_t *env,input_msg_get_t input_msg_func) -{ - if( env ) { - env->input_msg_func = input_msg_func; - } -} - -unsigned int _atsvr_input_msg_get(_atsvr_env_t *env,char *data,unsigned int data_len) -{ - int length = 0; - - if(env && env->input_msg_func) { - env->input_msg_func(data,data_len); - } - return length; -} - - -_atsvr_work_st _get_atsvr_work_state(_atsvr_env_t *env) -{ - _atsvr_work_st wk_st; - int ret; - - ret = _atsvr_resource_protection_lock(env); - if(ret == ATSVR_OK){ - wk_st = env->wk_st; - _atsvr_resource_protection_unlock(env); - }else{ - wk_st = env->wk_st; - } - return wk_st; -} - -void _set_atsvr_work_state(_atsvr_env_t *env,_atsvr_work_st wk_st) -{ - int ret; - - ret = _atsvr_resource_protection_lock(env); - if(ret == ATSVR_OK){ - env->wk_st = wk_st; - _atsvr_resource_protection_unlock(env); - }else{ - env->wk_st = wk_st; - } - return; -} - - diff --git a/bk7235/liteos_m/bk_sdk_armino/components/at_server/_at_server/_at_server.h b/bk7235/liteos_m/bk_sdk_armino/components/at_server/_at_server/_at_server.h deleted file mode 100755 index 21b1b1cf3b7c3e9c84a59b92384a2718b3e248e4..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/at_server/_at_server/_at_server.h +++ /dev/null @@ -1,104 +0,0 @@ -#ifndef __AT_SERVER_H_ -#define __AT_SERVER_H_ - -#include "_at_svr_opts.h" -#include "atsvr_unite.h" - -typedef enum{ - ATSVR_OK = 0, - ATSVR_SEVERE_ERR = -2, - ATSVR_ERROR = -1, - - ATSVR_GENERAL = 1, - ATSVR_NnMemoryErr = 2, - -}_atsvr_st; - -typedef enum{ - _ATSVR_ECHO_NONE = 0, - _ATSVR_ECHO_NORMAL, - _ATSVR_ECHO_ALL, -}_atsvr_echo_t; - -typedef enum{ - _ATSVR_WK_IDLE = 0, - _ATSVR_WK_DOING = 1, - _ATSVR_WK_DONE = 2, -}_atsvr_work_st; - -#if 0 -/* Structure for registering at server commands */ -struct _atsvr_command{ - const char *name; - const char *help; - - void (*function)(int argc, char **argv); -}; - -typedef void (*output_func_t)(char *msg,unsigned int msg_len); -typedef int (*resources_protection)(int is_lock,unsigned int timeout); -typedef unsigned int (*input_msg_get_t)(char *data,unsigned int dat_len); - -#endif - -typedef struct{ - _atsvr_echo_t echo; - _atsvr_work_st wk_st; - resources_protection res_prot; - - const struct _atsvr_command *commands[ATSVR_MAX_COMMANDS]; - unsigned int num_commands; - - output_func_t output_func; - input_msg_get_t input_msg_func; -}_at_svr_ctrl_env_t; - -typedef _at_svr_ctrl_env_t _atsvr_env_t; - -#ifndef _ATSVR_SIZEOF_OUTPUT_STRING -#define _ATSVR_SIZEOF_OUTPUT_STRING(env,string) _atsvr_output_msg(env,string,ATSVR_SIZEOF_STR_LEN_NOEOF(string)); -#endif - -#ifndef _ATSVR_OUTPUT_STRING -#define _ATSVR_OUTPUT_STRING(env,string) _atsvr_output_msg(env,string,strlen(string)); -#endif - - -extern char *_get_atsvr_version(void); - -extern void _set_atsvr_echo_mode(_atsvr_env_t *env,_atsvr_echo_t echo); -extern _atsvr_echo_t _get_atsvr_echo_mode(_atsvr_env_t *env); - -extern int _atsvr_register_command(_atsvr_env_t *env,const struct _atsvr_command *command); -extern int _atsvr_unregister_command(_atsvr_env_t *env,const struct _atsvr_command *command); -extern int _atsvr_register_commands(_atsvr_env_t *env,const struct _atsvr_command *commands,int num_commands); -extern int _atsvr_unregister_commands(_atsvr_env_t *env,const struct _atsvr_command *commands,int num_commands); - -extern int _atsvr_input_msg_analysis_handler(_atsvr_env_t *env,char *msg,unsigned int msg_len); - -extern void _atsvr_notice_ready(_atsvr_env_t *env); -extern void _atsvr_cmd_analysis_notice_error(_atsvr_env_t *env); -extern void _atsvr_cmd_rsp_ok(_atsvr_env_t *env); -extern void _atsvr_cmd_rsp_error(_atsvr_env_t *env); -extern void _atsvr_output_msg(_atsvr_env_t *env,char *msg,unsigned int msg_len); - -extern void _atsvr_register_output_func(_atsvr_env_t *env,output_func_t output_func); -///Register the resource critical protection function -extern void _atsvr_register_resources_protection_func(_atsvr_env_t *env,resources_protection res_prot); -extern int _atsvr_resource_protection_lock(_atsvr_env_t *env); -extern int _atsvr_resource_protection_lock_timeout(_atsvr_env_t *env,unsigned int timeout); -extern void _atsvr_resource_protection_unlock(_atsvr_env_t *env); -extern void _atsvr_register_input_msg_func(_atsvr_env_t *env,input_msg_get_t input_msg_func); -extern unsigned int _atsvr_input_msg_get(_atsvr_env_t *env,char *data,unsigned int data_len); -extern _atsvr_work_st _get_atsvr_work_state(_atsvr_env_t *env); -extern void _set_atsvr_work_state(_atsvr_env_t *env,_atsvr_work_st wk_st); -extern int _atsvr_def_config(_atsvr_env_t *env); - -#if defined(ATSVR_OPTIM_FD_CMD) && ATSVR_OPTIM_FD_CMD -#define _ATSVR_CMD_HADLER(name_st,help_st,func) {.name = name_st,.help = help_st,.function = func,.name_len = (sizeof(name_st) - 1)} -#else -#define _ATSVR_CMD_HADLER(name_st,help_st,func) {.name = name_st,.help = help_st,.function = func} -#endif - - -#endif diff --git a/bk7235/liteos_m/bk_sdk_armino/components/at_server/_at_server/_at_server_port.c b/bk7235/liteos_m/bk_sdk_armino/components/at_server/_at_server/_at_server_port.c deleted file mode 100755 index 80cec439dfe39f6710d8e539e34af7175b3b0f84..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/at_server/_at_server/_at_server_port.c +++ /dev/null @@ -1,22 +0,0 @@ -#include "_at_server_port.h" -#include "_at_server.h" -#include "string.h" -#include "stdio.h" -#include "stdlib.h" - - - - -void __weak__ *at_malloc(unsigned int size) -{ - return NULL; -} - -void __weak__ at_free(void *p) -{ - -} - - - - diff --git a/bk7235/liteos_m/bk_sdk_armino/components/at_server/_at_server/_at_server_port.h b/bk7235/liteos_m/bk_sdk_armino/components/at_server/_at_server/_at_server_port.h deleted file mode 100755 index 87d40226f51ef985f90cd372e214dfca4e5e24b2..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/at_server/_at_server/_at_server_port.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef __AT_SERVER_PORT_H_ -#define __AT_SERVER_PORT_H_ - - -#include "_at_svr_opts.h" - - -extern void *at_malloc(unsigned int size); -extern void at_free(void *p); - -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/components/at_server/_at_server/_at_svr_opts.h b/bk7235/liteos_m/bk_sdk_armino/components/at_server/_at_server/_at_svr_opts.h deleted file mode 100755 index 8a113f9fd39bb6ad2f812b89971e9903ff87d2f4..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/at_server/_at_server/_at_svr_opts.h +++ /dev/null @@ -1,130 +0,0 @@ -#ifndef __AT_SVR_OPTS_H_ -#define __AT_SVR_OPTS_H_ - - -#include "at_svr_opts.h" - - -#ifndef ATSVR_VERSION_NUM -#define ATSVR_VERSION_NUM "ATSVR-00.01" -#endif - -#ifndef ATSVR_MAX_COMMANDS -#define ATSVR_MAX_COMMANDS 64 -#endif - -/////set arguments max number -#ifndef ATSVR_MAX_ARG -#define ATSVR_MAX_ARG 16 -#endif - -#ifndef ATSVR_ADD_ESCAPE_CFG -#define ATSVR_ADD_ESCAPE_CFG 1 -#endif - -#ifndef ATSVRLOG -#define ATSVRLOG(...) -#endif - -#ifndef ATSVR_INPUT_BUFF_MAX_SIZE -#define ATSVR_INPUT_BUFF_MAX_SIZE 4096 -#endif - -#ifndef ATSVR_HANDLER_ENV -#define ATSVR_HANDLER_ENV 0 -#endif - -#ifndef ATSVR_CMD_HELP -#define ATSVR_CMD_HELP 1 -#endif - -#ifndef ATSVR_CMD_HELP_BUF_SIZE -#define ATSVR_CMD_HELP_BUF_SIZE (5 * 1024) -#endif - -#ifndef ATSVR_ECHO_DEFAULT -#define ATSVR_ECHO_DEFAULT _ATSVR_ECHO_NORMAL -#endif - -#ifndef ATSVR_INTERNAL_CMD -#define ATSVR_INTERNAL_CMD 1 -#endif - -#ifndef ATSVR_RET_CHAR -#define ATSVR_RET_CHAR '\r' -#endif - -#ifndef ATSVR_END_CHAR -#define ATSVR_END_CHAR '\n' -#endif - -////optimization find command speed -#ifndef ATSVR_OPTIM_FD_CMD -#define ATSVR_OPTIM_FD_CMD 0 -#endif - -#ifndef ATSVR_READY_MSG -#define ATSVR_READY_MSG "ready\r\n" -#endif - -#ifndef ATSVR_CMD_RSP_SUCCEED -#define ATSVR_CMD_RSP_SUCCEED "\r\nCMDRSP:OK\r\n" -#endif - -#ifndef ATSVR_CMD_RSP_ERROR -#define ATSVR_CMD_RSP_ERROR "\r\nCMDRSP:ERROR\r\n" -#endif - -#ifndef ATSVR_CMDMSG_ERROR_RSP -#define ATSVR_CMDMSG_ERROR_RSP "\r\nCMDRSP:ERROR\r\n" -#endif - -#ifndef ATSVR_CMDRSP_HEAD -#define ATSVR_CMDRSP_HEAD "CMDRSP:" -#endif - -#ifndef ATSVR_EVENT_HEAD -#define ATSVR_EVENT_HEAD "EVT:" -#endif - -#ifndef ATSVR_EVT_WLAN_CONNECTED -#define ATSVR_EVT_WLAN_CONNECTED "EVT:WLAN CONNECTED\r\n" -#endif - -#ifndef ATSVR_EVT_WLAN_DISCONNECTED -#define ATSVR_EVT_WLAN_DISCONNECTED "EVT:WLAN DISCONNECTED\r\n" -#endif - -#ifndef ATSVR_EVT_GOT_IP -#define ATSVR_EVT_GOT_IP "EVT:GOT-IP\r\n" -#endif - -#ifndef ATSVR_EVT_TCP_DISCONNECTED -#define ATSVR_EVT_TCP_DISCONNECTED "EVT:TCP DISCONNECTED,%d\r\n" -#endif - -#ifndef ATSVR_EVT_TCP_DISCONNECTED -#define ATSVR_EVT_TCP_DISCONNECTED "CMDRSP:TCP CONNECTED,%d\r\n" -#endif - -#ifndef ATSVR_INPUT_MSG_OVERFLOW -#define ATSVR_INPUT_MSG_OVERFLOW "Error: input overflow\r\n" -#endif - -#ifndef ATSVR_POWER_UP_READY_DELAY -#define ATSVR_POWER_UP_READY_DELAY 200 -#endif - -#ifndef __weak__ -#define __weak__ __attribute__((weak)) -#endif - -#ifndef ATSVR_SIZEOF_STR_LEN -#define ATSVR_SIZEOF_STR_LEN(string) (sizeof(string)) -#endif - -#ifndef ATSVR_SIZEOF_STR_LEN_NOEOF -#define ATSVR_SIZEOF_STR_LEN_NOEOF(string) (sizeof(string) - 1) -#endif - -#endif diff --git a/bk7235/liteos_m/bk_sdk_armino/components/at_server/_at_server_port/atsvr_core.c b/bk7235/liteos_m/bk_sdk_armino/components/at_server/_at_server_port/atsvr_core.c deleted file mode 100755 index 1c796c9da2712c5128b071e4fbcbea0e2cbf4459..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/at_server/_at_server_port/atsvr_core.c +++ /dev/null @@ -1,173 +0,0 @@ -#include "atsvr_core.h" -#include "atsvr_port.h" -#include "at_server.h" -#include "string.h" -#include "stdio.h" -#include "stdlib.h" -#include "_at_server_port.h" - -#if 0 -typedef struct{ - unsigned uart_overflow : 1; -}atsvr_env_t; - -static atsvr_env_t atsvr_env = { - 0 -}; -#endif - -int atsvr_send_msg_queue(atsvr_msg_t *sd_atsvrmsg,unsigned int timeout) -{ - return atsvr_port_send_msg_queue(sd_atsvrmsg,timeout); -} - -int atsvr_send_msg_queue_block(atsvr_msg_t *sd_atsvrmsg) -{ - return atsvr_port_send_msg_queue(sd_atsvrmsg,0xFFFFFFFF); -} - -int __weak__ atsvr_port_send_msg_queue(atsvr_msg_t *sd_atsvrmsg,unsigned int timeout) -{ - return -1; -} - -int atsvr_msg_get_input(unsigned char *inbuf, unsigned int *bp) -{ - if (inbuf == NULL){ - ATSVRLOG("inbuf_null\r\n"); - return 0; - } - - if(get_at_uart_overflow()) { - atsvr_overflow_handler(); - atsvr_input_msg_overflow(); - ATSVRLOG("[atsvr]overflow\r\n"); - (*bp) = 0; - return -10; - } - - while (atsvr_input_char(&inbuf[(*bp)]) == 1) - { - if ((inbuf[(*bp)] == ATSVR_RET_CHAR) - || (inbuf[(*bp)] == ATSVR_END_CHAR)) /* end of input line */ - { - if((*bp) >= 2) { - inbuf[(*bp)] = '\0'; - (*bp)++; - return 1; - } else if((*bp) == 0) { - continue; - } - ATSVRLOG("[AC]%d bp:%d\r\n",__LINE__,(*bp)); - (*bp) = 0; - return -1; - } - - if((*bp) <= 1) { - if((*bp) == 0) { - if(inbuf[0] != 'A') { - if(get_atsvr_echo_mode() != ATSVR_ECHO_NONE) { - inbuf[1] = '\r'; - inbuf[2] = '\n'; - atsvr_output_msg((char*)&inbuf[0],3); - } - (*bp) = 0; - ATSVRLOG("[AT]head 1(%x) error\r\n",inbuf[0]); - return -1; - } - }else if((*bp) == 1) { - if(inbuf[1] != 'T') { - if(get_atsvr_echo_mode() != ATSVR_ECHO_NONE) { - inbuf[2] = '\r'; - inbuf[3] = '\n'; - atsvr_output_msg((char*)&inbuf[0],4); - } - (*bp) = 0; - ATSVRLOG("[AT]head 2(%x) error\r\n",inbuf[0]); - return -1; - } - } - } - if(inbuf[(*bp)] == '\0') { - ATSVRLOG("[AC]%d bp:%d\r\n",__LINE__,(*bp)); - ///(*bp) = 0; - (*bp)++; - return -1; - } - - (*bp)++; - if ((*bp) >= ATSVR_INPUT_BUFF_MAX_SIZE) { - atsvr_input_msg_overflow(); - ATSVRLOG("[AC]%d bp:%d\r\n",__LINE__,(*bp)); - (*bp) = 0; - return 0; - } - } - - return 0; -} - - -void atsvr_msg_handler(atsvr_msg_t *msg) -{ - int ret; - - ATSVRLOG("[ATSVR]msg type:%d\r\n", msg->type); - switch( msg->type ) { - case ATSVR_MSG_STREAM: - { - ret = atsvr_input_msg_analysis_handler((char *)msg->msg_param,msg->len); - if(ret != 0){ - ///ATSVRLOG("[ATSVR]analysis stream error\r\n"); - } - } - break; - case ATSVR_MSG_INIT: - { - at_server_init(); - } - break; - case ATSVR_MSG_WLAN_EVENT: - { - atsvr_event_handler(msg->addition_infor); - } - break; - default: - break; - } - - if( msg->sub_type == ATSVR_SUBMSG_ATFREE ) { - if( msg->msg_param ) { - at_free(msg->msg_param); - } - } -} - -void atsvr_event_sender(ATSVR_EVT_T event) -{ - atsvr_msg_t sdmsg; - int ret; - - sdmsg.type = ATSVR_MSG_WLAN_EVENT; - sdmsg.sub_type = ATSVR_SUBMSG_NONE; - sdmsg.addition_infor = event; - sdmsg.len = 0; - sdmsg.msg_param = NULL; - ret = atsvr_send_msg_queue(&sdmsg,0); - if( ret != 0 ) { - ATSVRLOG("wlan_event(%x) notice error\r\n",event); - } -} - -void __weak__ atsvr_event_handler(int event) -{ - -} - - - - - - - - diff --git a/bk7235/liteos_m/bk_sdk_armino/components/at_server/_at_server_port/atsvr_core.h b/bk7235/liteos_m/bk_sdk_armino/components/at_server/_at_server_port/atsvr_core.h deleted file mode 100755 index 9fb7ee01a2f941b6fd524344b0af0e4644feb9d5..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/at_server/_at_server_port/atsvr_core.h +++ /dev/null @@ -1,42 +0,0 @@ -#ifndef _ATSVR_CORE_H_ -#define _ATSVR_CORE_H_ - -typedef enum{ - ATSVR_MSG_INIT = 0, - ATSVR_MSG_STREAM, - - ATSVR_MSG_WLAN_EVENT, -}atsvr_msgtype_e; - -typedef enum{ - ATSVR_SUBMSG_NONE = 0x00, - ATSVR_SUBMSG_ATFREE, -}atsvr_subtype_e; - -typedef enum{ - ATSVR_WLAN_DISCONNECT, - ATSVR_WLAN_CONNECTTED, - ATSVR_WLAN_GOT_IP, - -}ATSVR_EVT_T; - -typedef struct{ - atsvr_msgtype_e type; - atsvr_subtype_e sub_type; - unsigned char addition_infor; - unsigned int len; - void *msg_param; -}atsvr_msg_t; - -extern int atsvr_msg_get_input(unsigned char *inbuf, unsigned int *bp); -extern void atsvr_msg_handler(atsvr_msg_t *msg); - -extern int atsvr_send_msg_queue(atsvr_msg_t *sd_atsvrmsg,unsigned int timeout); -extern int atsvr_send_msg_queue_block(atsvr_msg_t *sd_atsvrmsg); -extern int atsvr_port_send_msg_queue(atsvr_msg_t *sd_atsvrmsg,unsigned int timeout); - -extern void atsvr_event_handler(int event); -extern void atsvr_event_sender(ATSVR_EVT_T event); - -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/components/at_server/_at_server_port/atsvr_port.c b/bk7235/liteos_m/bk_sdk_armino/components/at_server/_at_server_port/atsvr_port.c deleted file mode 100755 index ca46a579492c6d75c58f37da5f0d114997b405d0..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/at_server/_at_server_port/atsvr_port.c +++ /dev/null @@ -1,347 +0,0 @@ -#include "atsvr_port.h" -#include "atsvr_core.h" -#include "at_server.h" -#include "atsvr_cmd.h" -#include "atsvr_wlan.h" -#include "string.h" -#include "stdio.h" -#include "stdlib.h" - -#include -#include -#include "uart_pub.h" -#include "BkDriverUart.h" -#include - - -typedef struct{ - unsigned uart_overflow : 1; - - beken_queue_t msg_queue; - beken_semaphore_t at_rx_sema; - beken_semaphore_t at_tx_sema; - - beken_semaphore_t resources_protection; - - unsigned char rxbuf[ATSVR_INPUT_BUFF_MAX_SIZE]; - unsigned int bp; -}atsvr_port_env; - -atsvr_port_env atsvr_port = { - .uart_overflow = 0, - .msg_queue = NULL, - .at_rx_sema = NULL, - .at_tx_sema = NULL, - .resources_protection = NULL, -}; - - - - -void set_at_uart_overflow(int enable) -{ - GLOBAL_INT_DECLARATION(); - - GLOBAL_INT_DISABLE(); - atsvr_port.uart_overflow = (enable > 0)?1:0; - GLOBAL_INT_RESTORE(); -} - -int get_at_uart_overflow(void) -{ - int flag; - GLOBAL_INT_DECLARATION(); - - GLOBAL_INT_DISABLE(); - flag = atsvr_port.uart_overflow; - GLOBAL_INT_RESTORE(); - return flag; -} - -int IN atsvr_input_char(unsigned char *buf) -{ - if (bk_uart_recv(AT_UART_PORT_CFG, buf, 1, BEKEN_NO_WAIT) == 0){ - return 1; - }else{ - return 0; - } -} - -#define REG_READ(addr) (*((volatile UINT32 *)(addr))) -#define REG_WRITE(addr, _data) (*((volatile UINT32 *)(addr)) = (_data)) -static void atsvr_send_byte(UINT8 data) -{ - UINT8 uport = UART1_PORT; -#if AT_UART_SEND_DATA_INTTRRUPT_PROTECT - GLOBAL_INT_DECLARATION(); -#endif - if(UART1_PORT == uport) - while(!UART1_TX_WRITE_READY); - else - while(!UART2_TX_WRITE_READY); -#if AT_UART_SEND_DATA_INTTRRUPT_PROTECT - GLOBAL_INT_DISABLE(); -#endif - UART_WRITE_BYTE(uport, data); -#if AT_UART_SEND_DATA_INTTRRUPT_PROTECT - GLOBAL_INT_RESTORE(); -#endif -} - -void at_msg_intf_clear(unsigned int dnum) -{ - unsigned char dat; - unsigned int count = 0; - int ret; - - do{ - if(count >= dnum){ - break; - } - ret = atsvr_input_char(&dat); - if(ret == 1){ - count++; - } - }while(ret); -} - -void atsvr_overflow_handler(void) -{ - at_msg_intf_clear(RX_RB_LENGTH); - set_at_uart_overflow(0); -} - -static void atsvr_rx_sema_callback(int uport, void *param) -{ - if(atsvr_port.at_rx_sema){ - rtos_set_semaphore(&atsvr_port.at_rx_sema); - } -} - -void atsvr_msg_intf_init(void) -{ - rtos_init_semaphore(&atsvr_port.at_rx_sema, 32); - rtos_init_semaphore(&atsvr_port.at_tx_sema, 1); - rtos_init_semaphore(&atsvr_port.resources_protection, 1); - if(atsvr_port.at_tx_sema){ - rtos_set_semaphore(&atsvr_port.at_tx_sema); - } - if(atsvr_port.resources_protection){ - rtos_set_semaphore(&atsvr_port.resources_protection); - } - bk_uart_set_rx_callback(AT_UART_PORT_CFG, atsvr_rx_sema_callback,NULL); -} - -static int resources_protection_func(int is_lock,unsigned int timeout) -{ - if(atsvr_port.resources_protection){ - if(is_lock){ - if(rtos_get_semaphore(&atsvr_port.resources_protection,timeout) != kNoErr){ - return -1; - } - }else{ - rtos_set_semaphore(&atsvr_port.resources_protection); - } - } - return 0; -} - -int OUT atsvr_command_msg_handle_result_output_u(char *msg,unsigned int len,unsigned int timeout) -{ - int i = 0; - int sta = 0; - - if(atsvr_port.at_tx_sema) { - sta = rtos_get_semaphore(&atsvr_port.at_tx_sema, timeout); - if(kNoErr != sta ){ - sta = -1; - } else{ - for(i = 0; i < len; i++) { - atsvr_send_byte(msg[i]); - } - rtos_set_semaphore(&atsvr_port.at_tx_sema); - } - } - else { - sta = -1; - } - - return sta; -} - -static void atsvr_output_func(char *msg,unsigned int msg_len) -{ - atsvr_command_msg_handle_result_output_u(msg,msg_len,0xFFFFFFFFU); -} - -static unsigned int atsvr_input_msg_get_func(char *data,unsigned int dat_len) -{ - - return 0; -} - - -void *at_malloc(unsigned int size) -{ - return os_malloc(size); -} - -void at_free(void *p) -{ - os_free(p); -} - -int atsvr_port_send_msg_queue(atsvr_msg_t *sd_atsvrmsg,unsigned int timeout) -{ - if(atsvr_port.msg_queue != NULL){ - int ret = rtos_push_to_queue(&atsvr_port.msg_queue,sd_atsvrmsg,timeout); - if(ret != kNoErr){ - ATSVRLOG("[ATSVR]msg_queue push error:%d\r\n",ret); - return -1; - } - return 0; - }else{ - ATSVRLOG("[ATSVR]atsvr_port.msg_queue is invaild\r\n"); - return -1; - } -} - -void atsvr_event_handler(int event) -{ - ATSVRLOG("[ATSVR]treated event(%x)\r\n",event); - if(!wlan_event_handler(event)){ - return; - }else{ - ATSVRLOG("[ATSVR]untreated event(%x)\r\n",event); - } -} - -int get_atsvr_cmd_message_state(unsigned int timeout) -{ - int32 sta = -1; - - if(atsvr_port.at_rx_sema){ - sta = rtos_get_semaphore(&atsvr_port.at_rx_sema, timeout); - }else{ - ATSVRLOG("[%s]at_rx_sema error\r\n",__FUNCTION__); - } - return sta; -} - - -static void atsvr_msg_main( UINT32 data ) -{ - unsigned int timeout = BEKEN_NEVER_TIMEOUT; - int state; - - at_server_init(); - atsvr_msg_intf_init(); - atsvr_cmd_init(); - atsvr_register_resources_protection_func(resources_protection_func); - atsvr_register_output_func(atsvr_output_func); - atsvr_register_input_msg_func(atsvr_input_msg_get_func); - rtos_delay_milliseconds(ATSVR_POWER_UP_READY_DELAY); - at_msg_intf_clear(0xFFFFFFFF); - atsvr_notice_ready(); - - while (1) - { - state = get_atsvr_cmd_message_state(timeout); - if(state == kNoErr) { - con: - state = atsvr_msg_get_input(&atsvr_port.rxbuf[0],&atsvr_port.bp); - if( state == 1 ) { - atsvr_msg_t msg; - msg.type = ATSVR_MSG_STREAM; - msg.sub_type = ATSVR_SUBMSG_NONE; - msg.len = atsvr_port.bp; - msg.msg_param = (void*)atsvr_port.rxbuf; - atsvr_msg_handler(&msg); - atsvr_port.bp = 0; - goto con; - }else if( state <= -1 ) { - ATSVRLOG("[ATSVR]READ LINE ERROR(%d)\r\n",state); - atsvr_cmd_analysis_notice_error(); - atsvr_port.bp = 0; - goto con; - }else if ( state != 0 ){ - atsvr_port.bp = 0; - } - } - else { - ATSVRLOG("[ATSVR]at msg receive timeout error\r\n"); - } - } - - rtos_delete_thread(NULL); -} - -static void atsvr_handler_main( UINT32 data ) -{ - unsigned int timeout = BEKEN_NEVER_TIMEOUT; - atsvr_msg_t atsvrmsg; - int ret; - - while (1) - { - ret = rtos_pop_from_queue(&atsvr_port.msg_queue,&atsvrmsg,timeout); - if(ret == kNoErr){ - atsvr_msg_handler(&atsvrmsg); - } - } - - rtos_delete_thread(NULL); -} - - -int atsvr_app_init(void) -{ - int ret; - beken_thread_t msg_thread = NULL,handler_thread = NULL; - - if(atsvr_port.msg_queue == NULL){ - ret = rtos_init_queue(&atsvr_port.msg_queue,"atsvr-q",sizeof(atsvr_msg_t),ATSVR_QUEUE_MAX_NB); - if(ret){ - ATSVRLOG("Error: Failed to create atsvr-q (ret:%d)\r\n",ret); - goto init_general_err; - } - } - ret = rtos_create_thread(&msg_thread, - BEKEN_DEFAULT_WORKER_PRIORITY, - "atsvr-m", - (beken_thread_function_t)atsvr_msg_main, - (1024 * 3), - 0); - if (ret != kNoErr) { - ATSVRLOG("Error: Failed to create cli thread: %d\r\n",ret); - goto init_general_err; - } - - ret = rtos_create_thread(&handler_thread, - BEKEN_DEFAULT_WORKER_PRIORITY, - "atsvr-h", - (beken_thread_function_t)atsvr_handler_main, - (1024 * 3), - 0); - if (ret != kNoErr) { - ATSVRLOG("Error: Failed to create cli thread: %d\r\n",ret); - goto init_general_err; - } - - return kNoErr; -init_general_err: - if( msg_thread != NULL ) { - rtos_delete_thread(&msg_thread); - } - if( handler_thread != NULL ) { - rtos_delete_thread(&handler_thread); - } - if(atsvr_port.msg_queue != NULL){ - ret = rtos_deinit_queue( &atsvr_port.msg_queue ); - atsvr_port.msg_queue = NULL; - } - return kGeneralErr; -} - - - diff --git a/bk7235/liteos_m/bk_sdk_armino/components/at_server/_at_server_port/atsvr_port.h b/bk7235/liteos_m/bk_sdk_armino/components/at_server/_at_server_port/atsvr_port.h deleted file mode 100755 index d6e3fb57b5653bc259cd749f60452f0bdf8205df..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/at_server/_at_server_port/atsvr_port.h +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef _ATSVR_PORT_H_ -#define _ATSVR_PORT_H_ - -#define ATSVR_QUEUE_MAX_NB 6 - -#define AT_UART_PORT_CFG UART1_PORT -#define AT_CTS_RTS_SOFTWARE_CFG 1 -#define AT_UART_SEND_DATA_INTTRRUPT_PROTECT 0 - - -#define IN -#define OUT -#define CONST const -#define STRING - -extern void set_at_uart_overflow(int enable); -extern int get_at_uart_overflow(void); - -extern void atsvr_overflow_handler(void); - -extern int IN atsvr_input_char(unsigned char *buf); - -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/components/at_server/at_server.c b/bk7235/liteos_m/bk_sdk_armino/components/at_server/at_server.c deleted file mode 100755 index 9d1092619b95a0163ce5f9cec2aaf1029515066c..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/at_server/at_server.c +++ /dev/null @@ -1,139 +0,0 @@ -#include "at_server.h" -#include "_at_server.h" -#include "_atsvr_func.h" - - -_at_svr_ctrl_env_t _at_svr_env = { - 0 -}; - -char *get_atsvr_version(void) -{ - return _get_atsvr_version(); -} - -void set_atsvr_echo_mode(atsvr_echo_t echo) -{ - _set_atsvr_echo_mode(&_at_svr_env,(_atsvr_echo_t)echo); -} - -atsvr_echo_t get_atsvr_echo_mode(void) -{ - return (atsvr_echo_t)_get_atsvr_echo_mode(&_at_svr_env); -} - -int atsvr_register_command(const struct _atsvr_command *command) -{ - return _atsvr_register_command(&_at_svr_env,command); -} - -int atsvr_register_commands(const struct _atsvr_command *commands,int num_commands) -{ - return _atsvr_register_commands(&_at_svr_env,commands,num_commands); -} - -void atsvr_notice_ready(void) -{ - _atsvr_notice_ready(&_at_svr_env); -} - -void atsvr_cmd_rsp_ok(void) -{ - _atsvr_cmd_rsp_ok(&_at_svr_env); -} - -void atsvr_cmd_rsp_error(void) -{ - _atsvr_cmd_rsp_error(&_at_svr_env); -} - -void atsvr_cmd_analysis_notice_error(void) -{ - _atsvr_cmd_analysis_notice_error(&_at_svr_env); -} - -void atsvr_input_msg_overflow(void) -{ - _ATSVR_SIZEOF_OUTPUT_STRING(&_at_svr_env,ATSVR_INPUT_MSG_OVERFLOW); -} - -void atsvr_output_msg(char *msg,unsigned int msg_len) -{ - _atsvr_output_msg(&_at_svr_env,msg,msg_len); -} - -void atsvr_register_output_func(output_func_t output_func) -{ - _atsvr_register_output_func(&_at_svr_env,output_func); -} - -///Register the resource critical protection function -void atsvr_register_resources_protection_func(resources_protection res_prot) -{ - _atsvr_register_resources_protection_func(&_at_svr_env,res_prot); -} - -void atsvr_register_input_msg_func(input_msg_get_t input_msg_func) -{ - _atsvr_register_input_msg_func(&_at_svr_env,input_msg_func); -} - -atsvr_work_st get_atsvr_work_state(void) -{ - return (atsvr_work_st)_get_atsvr_work_state(&_at_svr_env); -} - -void set_atsvr_work_state(atsvr_work_st wk_st) -{ - _set_atsvr_work_state(&_at_svr_env,(_atsvr_work_st)wk_st); -} - -int atsvr_resource_protection_lock(void) -{ - if(_atsvr_resource_protection_lock(&_at_svr_env) == ATSVR_OK){ - return 0; - } - return -1; -} - -int atsvr_resource_protection_lock_timeout(unsigned int timeout) -{ - if(_atsvr_resource_protection_lock_timeout(&_at_svr_env,timeout) == ATSVR_OK){ - return 0; - } - return -1; -} - -void atsvr_resource_protection_unlock(void) -{ - _atsvr_resource_protection_unlock(&_at_svr_env); -} - -int atsvr_input_msg_analysis_handler(char *msg,unsigned int msg_len) -{ - int ret = _atsvr_input_msg_analysis_handler(&_at_svr_env,msg,msg_len); - - if(ret != ATSVR_OK){ - ret = -1; - } - _set_atsvr_work_state(&_at_svr_env,_ATSVR_WK_IDLE); - return ret; -} - -unsigned int atsvr_input_msg_get(char *data,unsigned int data_len) -{ - unsigned int length = _atsvr_input_msg_get(&_at_svr_env,data,data_len); - return length; -} - - -void atsvr_def_cmd_init(void) -{ - _atsvr_def_cmd_init(&_at_svr_env); -} - -void at_server_init(void) -{ - _atsvr_def_config(&_at_svr_env); -} - diff --git a/bk7235/liteos_m/bk_sdk_armino/components/at_server/at_server.h b/bk7235/liteos_m/bk_sdk_armino/components/at_server/at_server.h deleted file mode 100755 index dc29aec77534fc54477131a7e6c9c5bd587950a8..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/at_server/at_server.h +++ /dev/null @@ -1,66 +0,0 @@ -#ifndef _AT_SERVER_H_ -#define _AT_SERVER_H_ - -#include "_at_svr_opts.h" -#include "atsvr_unite.h" - -typedef enum{ - ATSVR_ECHO_NONE = 0, - ATSVR_ECHO_NORMAL, - ATSVR_ECHO_ALL, -}atsvr_echo_t; - -typedef enum{ - ATSVR_WK_IDLE = 0, - ATSVR_WK_DOING = 1, - ATSVR_WK_DONE = 2, -}atsvr_work_st; - -#if defined(ATSVR_OPTIM_FD_CMD) && ATSVR_OPTIM_FD_CMD -#define ATSVR_CMD_HADLER(name_st,help_str,func) {.name = name_st,.help = help_str,.function = func,.name_len = (sizeof(name_st) - 1)} -#else -#define ATSVR_CMD_HADLER(name_st,help_str,func) {.name = name_st,.help = help_str,.function = func} -#endif - - -#ifndef ATSVR_SIZEOF_OUTPUT_STRRING -#define ATSVR_SIZEOF_OUTPUT_STRRING(string) atsvr_output_msg(string,ATSVR_SIZEOF_STR_LEN_NOEOF(string)); -#endif - -#ifndef ATSVR_OUTPUT_STRRING -#define ATSVR_OUTPUT_STRRING(string) atsvr_output_msg(string,strlen(string)); -#endif - -extern char *get_atsvr_version(void); - -extern void set_atsvr_echo_mode(atsvr_echo_t echo); -extern atsvr_echo_t get_atsvr_echo_mode(void); - -extern int atsvr_register_command(const struct _atsvr_command *command); -extern int atsvr_register_commands(const struct _atsvr_command *commands,int num_commands); - -extern void atsvr_notice_ready(void); -extern void atsvr_cmd_rsp_ok(void); -extern void atsvr_cmd_rsp_error(void); -extern void atsvr_cmd_analysis_notice_error(void); -extern void atsvr_input_msg_overflow(void); -extern void atsvr_output_msg(char *msg,unsigned int msg_len); -extern void atsvr_register_output_func(output_func_t output_func); -extern void atsvr_register_input_msg_func(input_msg_get_t input_msg_func); -extern void atsvr_register_resources_protection_func(resources_protection res_prot); -extern atsvr_work_st get_atsvr_work_state(void); -extern void set_atsvr_work_state(atsvr_work_st wk_st); -extern int atsvr_resource_protection_lock(void); -extern int atsvr_resource_protection_lock_timeout(unsigned int timeout); -extern void atsvr_resource_protection_unlock(void); - -extern int atsvr_input_msg_analysis_handler(char *msg,unsigned int msg_len); -extern unsigned int atsvr_input_msg_get(char *data,unsigned int data_len); - -extern void at_server_init(void); - - -extern void *at_malloc(unsigned int size); -extern void at_free(void *p); - -#endif diff --git a/bk7235/liteos_m/bk_sdk_armino/components/at_server/at_server_func/_atsvr_func.c b/bk7235/liteos_m/bk_sdk_armino/components/at_server/at_server_func/_atsvr_func.c deleted file mode 100755 index 5907057622276fd2f6a8223060aed4cbf2f9c6ea..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/at_server/at_server_func/_atsvr_func.c +++ /dev/null @@ -1,176 +0,0 @@ -#include "_atsvr_func.h" -#include "_at_server.h" -#include "_at_server_port.h" -#include "string.h" -#include "stdio.h" -#include "stdlib.h" - - -static void _atsvr_at_command( -#if ATSVR_HANDLER_ENV - void* env, -#endif - int argc, char **argv) -{ - _at_svr_ctrl_env_t *p_env = NULL; - -#if ATSVR_HANDLER_ENV - p_env = env; -#else - if(argc < ATSVR_MAX_ARG) { - p_env = (_at_svr_ctrl_env_t*)argv[argc]; - } -#endif - if(argc != 1){ - _atsvr_cmd_rsp_error(p_env); - return; - } - _atsvr_cmd_rsp_ok(p_env); -} - -static void _atsvr_at_echo_command( -#if ATSVR_HANDLER_ENV - void* env, -#endif - int argc, char **argv) -{ - _at_svr_ctrl_env_t *p_env = NULL; - -#if ATSVR_HANDLER_ENV - p_env = env; -#else - if(argc < ATSVR_MAX_ARG) { - p_env = (_at_svr_ctrl_env_t*)argv[argc]; - } -#endif - if(argc != 2){ - _atsvr_cmd_rsp_error(p_env); - return; - } - int en = atoi(argv[1]); - if(en == 0){ - _set_atsvr_echo_mode(p_env,_ATSVR_ECHO_NONE); - }else if(en == 1){ - _set_atsvr_echo_mode(p_env,_ATSVR_ECHO_NORMAL); - }else if(en == 2){ - _set_atsvr_echo_mode(p_env,_ATSVR_ECHO_ALL); - }else{ - if(strcmp(argv[1],"en") == 0){ - _set_atsvr_echo_mode(p_env,_ATSVR_ECHO_NORMAL); - }else if(strcmp(argv[1],"EN") == 0){ - _set_atsvr_echo_mode(p_env,_ATSVR_ECHO_NORMAL); - }else if(strcmp(argv[1],"dis") == 0){ - _set_atsvr_echo_mode(p_env,_ATSVR_ECHO_NONE); - }else if(strcmp(argv[1],"DIS") == 0){ - _set_atsvr_echo_mode(p_env,_ATSVR_ECHO_NONE); - }else{ - _atsvr_cmd_rsp_error(p_env); - return; - } - } - _atsvr_cmd_rsp_ok(p_env); -} - -#if ATSVR_CMD_HELP -static void _atsvr_help_command( -#if ATSVR_HANDLER_ENV - void* env, -#endif - int argc, char **argv); -#endif - -static void _atsvr_at_verion( -#if ATSVR_HANDLER_ENV - void* env, -#endif - int argc, char **argv) -{ - _at_svr_ctrl_env_t *p_env = NULL; -#if ATSVR_HANDLER_ENV - p_env = env; -#else - if(argc < ATSVR_MAX_ARG) { - p_env = (_at_svr_ctrl_env_t*)argv[argc]; - } -#endif - if(argc != 1){ - _atsvr_cmd_rsp_error(p_env); - return; - } - char output[100]; - int n; - - n = snprintf(output,100,"CMDRSP:ATVERSION:%s\r\n",ATSVR_VERSION_NUM); - n += snprintf(output+n,100 - n,ATSVR_CMD_RSP_SUCCEED); - _atsvr_output_msg(p_env,output,n); - - return; -} - - -const struct _atsvr_command _atsvc_cmds_table[] = { - _ATSVR_CMD_HADLER("AT","AT",_atsvr_at_command), -#if defined(ATSVR_CMD_HELP) && ATSVR_CMD_HELP - _ATSVR_CMD_HADLER("AT+HELP","AT+HELP",_atsvr_help_command), -#endif - _ATSVR_CMD_HADLER("AT+VERSION","AT+VERSION",_atsvr_at_verion), - _ATSVR_CMD_HADLER("AT+ECHO","AT+ECHO=0\\1\\2",_atsvr_at_echo_command), - -}; - -#if ATSVR_CMD_HELP -static void _atsvr_help_command( -#if ATSVR_HANDLER_ENV - void* env, -#endif - int argc, char **argv) -{ - unsigned int i; - int n,len; - char *resultbuf; - _at_svr_ctrl_env_t *p_env = NULL; - -#if ATSVR_HANDLER_ENV - p_env = env; -#else - if(argc < ATSVR_MAX_ARG) { - p_env = (_at_svr_ctrl_env_t*)argv[argc]; - } -#endif - resultbuf = at_malloc(ATSVR_CMD_HELP_BUF_SIZE); - if(resultbuf) { - len = 0; - if(p_env != NULL){ - for (i = 0, n = 0; i < ATSVR_MAX_COMMANDS && n < p_env->num_commands; i++){ - if (p_env->commands[i]->name) { - len += snprintf(resultbuf+len,ATSVR_CMD_HELP_BUF_SIZE - len, - "CMDRSP:cmd:%s,help:%s\r\n", p_env->commands[i]->name, - p_env->commands[i]->help ? p_env->commands[i]->help : ""); - n++; - } - } - len += snprintf(resultbuf+len,ATSVR_CMD_HELP_BUF_SIZE - len,"%s",ATSVR_CMD_RSP_SUCCEED); - }else { - len += snprintf(resultbuf+len,ATSVR_CMD_HELP_BUF_SIZE - len,"%s",ATSVR_CMD_RSP_ERROR); - } - if(p_env && p_env->output_func) { - p_env->output_func(resultbuf,len); - } - at_free(resultbuf); - }else { - _atsvr_cmd_rsp_error(p_env); - } -} -#endif - - -void _atsvr_def_cmd_init(_atsvr_env_t *env) -{ - _atsvr_register_commands(env,_atsvc_cmds_table, sizeof(_atsvc_cmds_table) / sizeof(struct _atsvr_command)); -} - -void _atsvr_def_cmd_deinit(_atsvr_env_t *env) -{ - _atsvr_unregister_commands(env,_atsvc_cmds_table, sizeof(_atsvc_cmds_table) / sizeof(struct _atsvr_command)); -} - diff --git a/bk7235/liteos_m/bk_sdk_armino/components/at_server/at_server_func/_atsvr_func.h b/bk7235/liteos_m/bk_sdk_armino/components/at_server/at_server_func/_atsvr_func.h deleted file mode 100755 index de10a7c3b15d8e729550e34bc023182aea98ae1f..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/at_server/at_server_func/_atsvr_func.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef __ATSVR_FUNC_H_ -#define __ATSVR_FUNC_H_ - -#include "_at_svr_opts.h" -#include "_at_server.h" - - - -extern void _atsvr_def_cmd_init(_atsvr_env_t *env); - -#endif diff --git a/bk7235/liteos_m/bk_sdk_armino/components/at_server/at_svr_opts.h b/bk7235/liteos_m/bk_sdk_armino/components/at_server/at_svr_opts.h deleted file mode 100755 index a267da2709af10786793696ac733e7d8cab32381..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/at_server/at_svr_opts.h +++ /dev/null @@ -1,37 +0,0 @@ -#ifndef _AT_SVR_OPTS_H_ -#define _AT_SVR_OPTS_H_ - - -#define ATSVR_VERSION_NUM "ATSVR-01.01" - -#define ATSVR_MAX_COMMANDS 64 -#define ATSVR_MAX_ARG 16 - -#define ATSVR_ADD_ESCAPE_CFG 1 -#define ATSVR_INPUT_BUFF_MAX_SIZE 2048 - -#define ATSVR_POWER_UP_READY_DELAY 400 - -#define ATSVR_CMDRSP_HEAD "CMDRSP:" -#define ATSVR_READY_MSG "\r\nready\r\n" -#define ATSVR_CMD_RSP_SUCCEED "CMDRSP:OK\r\n" -#define ATSVR_CMD_RSP_ERROR "CMDRSP:ERROR\r\n" -#define ATSVR_CMDMSG_ERROR_RSP "CMDRSP:ERROR\r\n" -#define ATSVR_RET_CHAR '\r' -#define ATSVR_END_CHAR '\n' - -#define ATSVR_EVENT_HEAD "EVT:" -#define ATSVR_EVT_WLAN_DISCONNECTED "EVT:WLAN DISCONNECTED\r\n" -#define ATSVR_EVT_WLAN_CONNECTED "EVT:WLAN CONNECTED\r\n" -#define ATSVR_EVT_GOT_IP "EVT:GOT-IP\r\n" - - -#ifndef __weak__ -#define __weak__ __attribute__((weak)) -#endif - -extern void bk_printf(const char *fmt, ...); -#define ATSVRLOG bk_printf - - -#endif diff --git a/bk7235/liteos_m/bk_sdk_armino/components/at_server/atsvr_cmd/atsvr_cmd.c b/bk7235/liteos_m/bk_sdk_armino/components/at_server/atsvr_cmd/atsvr_cmd.c deleted file mode 100755 index da704b5e0b3a91ed403eb07826f3deb117999184..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/at_server/atsvr_cmd/atsvr_cmd.c +++ /dev/null @@ -1,346 +0,0 @@ -#include "atsvr_cmd.h" -#include "at_server.h" -#include "atsvr_wlan.h" -#include "atsvr_misc.h" -#include "string.h" -#include "stdio.h" -#include "stdlib.h" - - -static void atsvr_reset_system(int argc, char **argv) -{ - if(argc != 1){ - atsvr_cmd_rsp_error(); - return; - } - atsvr_cmd_rsp_ok(); - reboot_the_system(); - return; -} - - -static void atsvr_get_station_mac(int argc, char **argv) -{ - if(argc == 1){ - unsigned char mac[6]; - int n = 0; - char resultbuf[200]; - - wlan_get_station_mac_address((char*)mac); - - n = snprintf(resultbuf,sizeof(resultbuf),ATSVR_CMDRSP_HEAD"+WMAC:%02x:%02x:%02x:%02x:%02x:%02x\r\n",mac[0], - mac[1],mac[2],mac[3],mac[4],mac[5]); - n += snprintf(resultbuf+n,sizeof(resultbuf) - n,"%s",ATSVR_CMD_RSP_SUCCEED); - atsvr_output_msg(resultbuf,n); - return; - }else{ - atsvr_cmd_rsp_error(); - } -} - -void atsvr_set_station_dhcp(int argc, char **argv) -{ - char *mode; - unsigned int param; - - if(argc != 2){ - atsvr_cmd_rsp_error(); - return; - } - - mode = argv[1]; - if(strcmp(mode,"ON DHCP") == 0){ - param = 1; - }else if(strcmp(mode,"OFF DHCP") == 0){ - param = 0; - }else if(strcmp(mode,"1") == 0){ - param = 1; - }else if(strcmp(mode,"0") == 0){ - param = 0; - }else{ - atsvr_cmd_rsp_error(); - return; - } - - wlan_set_station_dhcp(param); - atsvr_cmd_rsp_ok(); - return; -} - -static void atsvr_station_ssid_pwd(int argc, char **argv) -{ - if((argc != 2)&&(argc != 3)){ - atsvr_cmd_rsp_error(); - return; - } - char *my_ssid; - char *connect_key; - - if(argc == 2){ - my_ssid = argv[1]; - connect_key = "OPEN"; - }else if(argc == 3){ - my_ssid = argv[1]; - connect_key = argv[2]; - }else{ - atsvr_cmd_rsp_error(); - return; - } - if(wlan_start_station_connect(my_ssid, connect_key) == 0){ - atsvr_cmd_rsp_ok(); - }else{ - atsvr_cmd_rsp_error(); - } - - return; -} - -static void atsvr_station_stop(int argc, char **argv) -{ - if(argc != 1){ - atsvr_cmd_rsp_error(); - return; - } - - if(wlan_stop_station() == 0){ - atsvr_cmd_rsp_ok(); - }else{ - atsvr_cmd_rsp_error(); - } - - return; -} - -static void atsvr_station_static_ip(int argc, char **argv) -{ - if((argc != 4)&&(argc != 5)){ - atsvr_cmd_rsp_error(); - return; - } - char *ip = argv[1]; - char *mask = argv[2]; - char *gate = argv[3]; - char *dns = NULL; - char *dns2 = NULL; - - if(argc == 5){ - dns = argv[4]; - } - if(judge_the_string_is_ipv4_string(ip) != 0){ - atsvr_cmd_rsp_error(); - ATSVRLOG("[atsvr]ip:%s error\r\n",ip); - return; - } - if(judge_the_string_is_ipv4_string(mask) != 0){ - atsvr_cmd_rsp_error(); - ATSVRLOG("[atsvr]mask:%s error\r\n",mask); - return; - } - if(judge_the_string_is_ipv4_string(gate) != 0){ - atsvr_cmd_rsp_error(); - ATSVRLOG("[atsvr]gate:%s error\r\n",gate); - return; - } - if(dns != NULL){ - if(judge_the_string_is_ipv4_string(dns) != 0){ - atsvr_cmd_rsp_error(); - ATSVRLOG("[atsvr]dns:%s error\r\n",dns); - return; - } - } - if(dns2 != NULL){ - if(judge_the_string_is_ipv4_string(dns2) != 0){ - atsvr_cmd_rsp_error(); - ATSVRLOG("[atsvr]dns2:%s error\r\n",dns2); - return; - } - } - - if(wlan_set_station_static_ip(ip, mask,gate,dns,dns2) == 0){ - atsvr_cmd_rsp_ok(); - }else{ - atsvr_cmd_rsp_error(); - } - - return; -} - -void atsvr_get_station_status(int argc, char **argv) -{ - if(argc != 1){ - atsvr_cmd_rsp_error(); - return; - } - int statue = wlan_get_station_cur_status(); - if(statue == 1){ - ATSVR_SIZEOF_OUTPUT_STRRING(ATSVR_CMDRSP_HEAD"STATION_UP\r\n"); - }else{ - ATSVR_SIZEOF_OUTPUT_STRRING(ATSVR_CMDRSP_HEAD"STATION_DOWN\r\n"); - } - set_atsvr_work_state(ATSVR_WK_DONE); - atsvr_cmd_rsp_ok(); - return; -} - -void atsvr_wlan_scan_cmd(int argc, char **argv) -{ - if((argc != 1) && (argc != 2)){ - atsvr_cmd_rsp_error(); - return; - } - char *ssid = NULL; - - if(argc == 2){ - ssid = argv[1]; - } - if(wlan_scan_start(ssid) != 0){ - atsvr_cmd_rsp_error(); - return; - } - set_atsvr_work_state(ATSVR_WK_DONE); - atsvr_cmd_rsp_ok(); - return; -} - - -static void atsvr_softap_start(int argc, char **argv) -{ - if((argc != 2)&&(argc != 3)){ - atsvr_cmd_rsp_error(); - return; - } - char *my_ssid; - char *connect_key; - - if(argc == 2){ - my_ssid = argv[1]; - connect_key = "OPEN"; - }else if(argc == 3){ - my_ssid = argv[1]; - connect_key = argv[2]; - }else{ - atsvr_cmd_rsp_error(); - return; - } - if(wlan_softap_start(my_ssid, connect_key) == 0){ - atsvr_cmd_rsp_ok(); - }else{ - atsvr_cmd_rsp_error(); - } - - return; -} - -static void atsvr_softap_stop(int argc, char **argv) -{ - if(argc != 1){ - atsvr_cmd_rsp_error(); - return; - } - - if(wlan_stop_softap() == 0){ - set_atsvr_work_state(ATSVR_WK_DONE); - atsvr_cmd_rsp_ok(); - }else{ - set_atsvr_work_state(ATSVR_WK_DONE); - atsvr_cmd_rsp_error(); - } - - return; -} - -static void atsvr_softap_static_ip(int argc, char **argv) -{ - if((argc != 4)&&(argc != 5)){ - atsvr_cmd_rsp_error(); - return; - } - char *ip = argv[1]; - char *mask = argv[2]; - char *gate = argv[3]; - char *dns = NULL; - - if(argc == 5){ - dns = argv[4]; - } - if(judge_the_string_is_ipv4_string(ip) != 0){ - atsvr_cmd_rsp_error(); - ATSVRLOG("[atsvr]ip:%s error\r\n",ip); - return; - } - if(judge_the_string_is_ipv4_string(mask) != 0){ - atsvr_cmd_rsp_error(); - ATSVRLOG("[atsvr]mask:%s error\r\n",mask); - return; - } - if(judge_the_string_is_ipv4_string(gate) != 0){ - atsvr_cmd_rsp_error(); - ATSVRLOG("[atsvr]gate:%s error\r\n",gate); - return; - } - if(dns != NULL){ - if(judge_the_string_is_ipv4_string(dns) != 0){ - atsvr_cmd_rsp_error(); - ATSVRLOG("[atsvr]dns:%s error\r\n",dns); - return; - } - } - if(wlan_set_softap_static_ip(ip, mask,gate,dns) == 0){ - atsvr_cmd_rsp_ok(); - }else{ - atsvr_cmd_rsp_error(); - } - - return; -} - -void atsvr_get_softap_status(int argc, char **argv) -{ - if(argc != 1){ - atsvr_cmd_rsp_error(); - return; - } - int statue = wlan_get_softap_cur_status(); - if(statue == 1){ - ATSVR_SIZEOF_OUTPUT_STRRING(ATSVR_CMDRSP_HEAD"SOFTAP_UP\r\n"); - }else{ - ATSVR_SIZEOF_OUTPUT_STRRING(ATSVR_CMDRSP_HEAD"SOFTAP_DOWN\r\n"); - } - set_atsvr_work_state(ATSVR_WK_DONE); - atsvr_cmd_rsp_ok(); - return; -} - -const struct _atsvr_command atsvc_cmds_table[] = { - ATSVR_CMD_HADLER("AT+RST","AT+RST",atsvr_reset_system), - - ATSVR_CMD_HADLER("AT+WLMAC","AT+WLMAC",atsvr_get_station_mac), - ATSVR_CMD_HADLER("AT+STADHCP","AT+STADHCP=0/1",atsvr_set_station_dhcp), - ATSVR_CMD_HADLER("AT+STAAPINFO","AT+STAAPINFO=SSID,PWD",atsvr_station_ssid_pwd), - ATSVR_CMD_HADLER("AT+STASTOP","AT+STASTOP",atsvr_station_stop), - ATSVR_CMD_HADLER("AT+STASTATIC","AT+STASTATIC=ip,mask,gate[,dns]",atsvr_station_static_ip), - ATSVR_CMD_HADLER("AT+STAST","AT+STAST",atsvr_get_station_status), - ATSVR_CMD_HADLER("AT+WSCAN","AT+WSCAN",atsvr_wlan_scan_cmd), - - ATSVR_CMD_HADLER("AT+SOFTAP","AT+SOFTAP=SSID,PWD",atsvr_softap_start), - ATSVR_CMD_HADLER("AT+SOFTAPSTOP","AT+STASTOP",atsvr_softap_stop), - ATSVR_CMD_HADLER("AT+APSTATIC","AT+APSTATIC=ip,mask,gate[,dns]",atsvr_softap_static_ip), - ATSVR_CMD_HADLER("AT+APSTATE","AT+APSTATE",atsvr_get_softap_status), -}; - - - - -void atsvr_cmd_init(void) -{ - atsvr_register_commands(atsvc_cmds_table, sizeof(atsvc_cmds_table) / sizeof(struct _atsvr_command)); - atsvr_extern_cmd_init(); - - atsvr_wlan_init(); -} - -void __weak__ atsvr_extern_cmd_init(void) -{ - -} - diff --git a/bk7235/liteos_m/bk_sdk_armino/components/at_server/atsvr_cmd/atsvr_cmd.h b/bk7235/liteos_m/bk_sdk_armino/components/at_server/atsvr_cmd/atsvr_cmd.h deleted file mode 100755 index 906cdd117691dc6660f31487ad5d4ee1d53f6b40..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/at_server/atsvr_cmd/atsvr_cmd.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef _ATSVR_CMD_H_ -#define _ATSVR_CMD_H_ - - - -#include "atsvr_cmd_cfg.h" - -extern void atsvr_cmd_init(void); -extern void atsvr_extern_cmd_init(void); - -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/components/at_server/atsvr_cmd/atsvr_cmd_cfg.h b/bk7235/liteos_m/bk_sdk_armino/components/at_server/atsvr_cmd/atsvr_cmd_cfg.h deleted file mode 100755 index 67f3b0185ab62b4df12222ee2aaf075db1977897..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/at_server/atsvr_cmd/atsvr_cmd_cfg.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef _ATSVR_CMD_CFG_H_ -#define _ATSVR_CMD_CFG_H_ - - - - -#define ATSVR_WLAN_STA_DHCP 1 - - - - - - -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/components/at_server/atsvr_cmd/atsvr_misc.c b/bk7235/liteos_m/bk_sdk_armino/components/at_server/atsvr_cmd/atsvr_misc.c deleted file mode 100755 index ccff73fb541e6e52e2f18755d147daf092140170..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/at_server/atsvr_cmd/atsvr_misc.c +++ /dev/null @@ -1,22 +0,0 @@ -#include "atsvr_misc.h" -#include "atsvr_core.h" -#include "at_server.h" -#include "atsvr_cmd.h" -#include "string.h" -#include "stdio.h" -#include "stdlib.h" - -#include "wlan_ui_pub.h" - - -void reboot_the_system(void) -{ - bk_reboot(); -} - - - - - - - diff --git a/bk7235/liteos_m/bk_sdk_armino/components/at_server/atsvr_cmd/atsvr_misc.h b/bk7235/liteos_m/bk_sdk_armino/components/at_server/atsvr_cmd/atsvr_misc.h deleted file mode 100755 index d1528c505ad565eb414026379a175ba0aa007e41..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/at_server/atsvr_cmd/atsvr_misc.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef _ATSVR_MISC_H_ -#define _ATSVR_MISC_H_ - - - - - - -#include "atsvr_cmd_cfg.h" - - - - -extern void reboot_the_system(void); - - -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/components/at_server/atsvr_cmd/atsvr_wlan.c b/bk7235/liteos_m/bk_sdk_armino/components/at_server/atsvr_cmd/atsvr_wlan.c deleted file mode 100755 index 32c51a79526013df21331772b8e2e7abb58ed51b..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/at_server/atsvr_cmd/atsvr_wlan.c +++ /dev/null @@ -1,569 +0,0 @@ -#include "atsvr_wlan.h" -#include "atsvr_core.h" -#include "at_server.h" -#include "atsvr_cmd.h" -#include "at_server.h" -#include "string.h" -#include "stdio.h" -#include "stdlib.h" - -#include -#include "wlan_ui_pub.h" -#include "bk_rw_msg.h" -#include -#include -#include -#include "param_config.h" -#include -#include -#include -#include - -typedef struct{ - unsigned dhcp : 1; - unsigned station_status : 1; -#define STATION_UP 1 -#define STATION_DOWN 0 - unsigned softap_status : 1; -#define SOFTAP_UP 1 -#define SOFTAP_DOWN 0 - - unsigned char static_ip[16]; - unsigned char static_maks[16]; - unsigned char static_gate[16]; - unsigned char static_dns1[16]; - unsigned char static_dns2[16]; - - unsigned char softap_ip[16]; - unsigned char softap_mask[16]; - unsigned char softap_gate[16]; - unsigned char softap_dns[16]; -}atsvr_wlan_t; - -atsvr_wlan_t atsvr_wlan = { - .dhcp = ATSVR_WLAN_STA_DHCP, - .station_status = STATION_DOWN, - .softap_status = SOFTAP_DOWN, - .static_ip = ATSVR_WLAN_STA_DEFAULT_IP, - .static_maks = ATSVR_WLAN_STA_DEFAULT_MASK, - .static_gate = ATSVR_WLAN_STA_DEFAULT_GW, - .static_dns1 = ATSVR_WLAN_STA_DEFAULT_DNS, - .static_dns2 = ATSVR_WLAN_STA_DEFAULT_DNS, - - .softap_ip = ATSVR_WLAN_DEFAULT_IP, - .softap_mask = ATSVR_WLAN_DEFAULT_MASK, - .softap_gate = ATSVR_WLAN_DEFAULT_GW, - .softap_dns = ATSVR_WLAN_DEFAULT_DNS, -}; - - - -void wlan_get_station_mac_address(char *mac) -{ - bk_wifi_sta_get_mac(mac); -} - -void wlan_get_softap_mac_address(char *mac) -{ - bk_wifi_ap_get_mac(mac); -} - -int wlan_start_station_connect(char *my_ssid,char* connect_key) -{ - wifi_sta_config_t sta_config = WIFI_DEFAULT_STA_CONFIG(); - network_InitTypeDef_st wNetConfig; - int dhcp_sta; - unsigned char *bssid = NULL; - - memset(&wNetConfig, 0x0, sizeof(network_InitTypeDef_st)); - dhcp_sta = wlan_get_station_dhcp(); - - memcpy(sta_config.ssid, my_ssid,32); - sta_config.ssid[32] = '\0'; - memcpy(sta_config.password, connect_key,64); - - if(!dhcp_sta){ - netif_ip4_config_t ip4_config = {0}; - - ATSVRLOG("DHCP Static ip:%s,maks:%s,gate:%s,dns1:%s,dns2:%s\r\n", - atsvr_wlan.static_ip,atsvr_wlan.static_maks, atsvr_wlan.static_gate, - atsvr_wlan.static_dns1, atsvr_wlan.static_dns2); - strncpy(ip4_config.ip, (char *)atsvr_wlan.static_ip,16); - strncpy(ip4_config.mask, (char *)atsvr_wlan.static_maks,16); - strncpy(ip4_config.gateway, (char *)atsvr_wlan.static_gate,16); - strncpy(ip4_config.dns, (char *)atsvr_wlan.static_dns1,16); - BK_LOG_ON_ERR(bk_netif_set_ip4_config(NETIF_IF_STA, &ip4_config)); - } - - if ( bssid != NULL){ - memcpy(sta_config.bssid, bssid, 6); - } - - ATSVRLOG("atsvr_ssid:%s atsvr_key:%s\r\n", sta_config.ssid, sta_config.password); - BK_LOG_ON_ERR(bk_wifi_sta_set_config(&sta_config)); - BK_LOG_ON_ERR(bk_wifi_sta_start()); - - return 0; -} - -int wlan_stop_station(void) -{ - BK_LOG_ON_ERR(bk_wifi_sta_stop()); - return 0; -} - -void wlan_set_station_dhcp(int en) -{ - atsvr_wlan.dhcp = ( en ) ? 1 : 0; -} - -int wlan_get_station_dhcp(void) -{ - return ( atsvr_wlan.dhcp != 0 ) ? 1 : 0; -} - -int wlan_set_station_static_ip(char *ip,char *mask,char *gate,char *dns,char *dns2) -{ - strncpy((char *)atsvr_wlan.static_ip,ip,16); - strncpy((char *)atsvr_wlan.static_maks,mask,16); - strncpy((char *)atsvr_wlan.static_gate,gate,16); - if( dns != NULL){ - strncpy((char *)atsvr_wlan.static_dns1,dns,16); - } - if( dns != NULL){ - strncpy((char *)atsvr_wlan.static_dns2,dns2,16); - } - return 0; -} - -int wlan_set_station_dns(char *dns_ip,char *dns2_ip) -{ - if( dns_ip != NULL ) { - strncpy((char *)atsvr_wlan.static_dns1,dns_ip,16); - } - if( dns2_ip != NULL ) { - strncpy((char *)atsvr_wlan.static_dns2,dns2_ip,16); - } - return 0; -} - -int wlan_get_station_cur_status(void) -{ - return (atsvr_wlan.station_status == STATION_UP) ? 1 : 0; -} - -int wlan_softap_start(char *ap_ssid, char *ap_key) -{ - wifi_ap_config_t ap_config = WIFI_DEFAULT_AP_CONFIG(); - netif_ip4_config_t ip4_config = {0}; - int len; - - len = strlen(ap_ssid); - if(ATSVR_MAX_SSID_LEN < len) { - ATSVRLOG("ssid name more than 32 Bytes\r\n"); - return -1; - } - - strncpy(ap_config.ssid, ap_ssid,33); - strncpy(ap_config.password, ap_key,64); - - strncpy(ip4_config.ip, (char *)atsvr_wlan.softap_ip,16); - strncpy(ip4_config.mask, (char *)atsvr_wlan.softap_mask,16); - strncpy(ip4_config.gateway, (char *)atsvr_wlan.softap_gate,16); - strncpy(ip4_config.dns, (char *)atsvr_wlan.softap_dns,16); - - ATSVRLOG("softap-ssid:%s | key:%s\r\n", ap_config.ssid, ap_config.password); - BK_LOG_ON_ERR(bk_netif_set_ip4_config(NETIF_IF_AP, &ip4_config)); - BK_LOG_ON_ERR(bk_wifi_ap_set_config(&ap_config)); - BK_LOG_ON_ERR(bk_wifi_ap_start()); - return 0; -} - -int wlan_stop_softap(void) -{ - BK_LOG_ON_ERR(bk_wifi_ap_stop()); - return 0; -} - -int wlan_set_softap_static_ip(char *ip,char *mask,char *gate,char *dns_ip) -{ - strncpy((char *)atsvr_wlan.softap_ip,ip,16); - strncpy((char *)atsvr_wlan.softap_mask,mask,16); - strncpy((char *)atsvr_wlan.softap_gate,gate,16); - if(dns_ip != NULL){ - strncpy((char *)atsvr_wlan.softap_dns,dns_ip,16); - } - return 0; -} - -int wlan_set_softap_dns(char *dns_ip) -{ - strncpy((char *)atsvr_wlan.softap_dns,dns_ip,16); - return 0; -} - -int wlan_get_softap_cur_status(void) -{ - return (atsvr_wlan.softap_status == SOFTAP_UP) ? 1 : 0; -} - -atsvr_wlan_sec_type wlan2atsvr_sec_type(int sec_type) -{ - switch(sec_type){ - case BK_SECURITY_TYPE_NONE: - return ATSVR_SEC_TYPE_NONE; - case BK_SECURITY_TYPE_WEP: - return ATSVR_SEC_TYPE_WEP; - case BK_SECURITY_TYPE_WPA_TKIP: - return ATSVR_SEC_TYPE_WPA_TKIP; - case BK_SECURITY_TYPE_WPA_AES: - return ATSVR_SEC_TYPE_WPA_AES; - case BK_SECURITY_TYPE_WPA2_TKIP: - return ATSVR_SEC_TYPE_WPA2_TKIP; - case BK_SECURITY_TYPE_WPA2_AES: - return ATSVR_SEC_TYPE_WPA2_AES; - case BK_SECURITY_TYPE_WPA2_MIXED: - return ATSVR_SEC_TYPE_WPA2_MIXED; - case BK_SECURITY_TYPE_WPA3_SAE: - return ATSVR_SEC_TYPE_WPA3_SAE; - case BK_SECURITY_TYPE_WPA3_WPA2_MIXED: - return ATSVR_SEC_TYPE_WPA3_WPA2_MIXED; - case BK_SECURITY_TYPE_OWE: - return ATSVR_SEC_TYPE_OWE; - case BK_SECURITY_TYPE_AUTO: - return ATSVR_SEC_TYPE_AUTO; - } - return ATSVR_SEC_TYPE_AUTO; -} - -int atsvr2wlan_sec_type(atsvr_wlan_sec_type sec_type) -{ - switch(sec_type){ - case ATSVR_SEC_TYPE_NONE: - return BK_SECURITY_TYPE_NONE; - case ATSVR_SEC_TYPE_WEP: - return BK_SECURITY_TYPE_WEP; - case ATSVR_SEC_TYPE_WPA_TKIP: - return BK_SECURITY_TYPE_WPA_TKIP; - case ATSVR_SEC_TYPE_WPA_AES: - return BK_SECURITY_TYPE_WPA_AES; - case ATSVR_SEC_TYPE_WPA2_TKIP: - return BK_SECURITY_TYPE_WPA2_TKIP; - case ATSVR_SEC_TYPE_WPA2_AES: - return BK_SECURITY_TYPE_WPA2_AES; - case ATSVR_SEC_TYPE_WPA2_MIXED: - return BK_SECURITY_TYPE_WPA2_MIXED; - case ATSVR_SEC_TYPE_WPA3_SAE: - return BK_SECURITY_TYPE_WPA3_SAE; - case ATSVR_SEC_TYPE_WPA3_WPA2_MIXED: - return BK_SECURITY_TYPE_WPA3_WPA2_MIXED; - case ATSVR_SEC_TYPE_OWE: - return BK_SECURITY_TYPE_OWE; - case ATSVR_SEC_TYPE_AUTO: - return BK_SECURITY_TYPE_AUTO; - default: - break; - } - return BK_SECURITY_TYPE_AUTO; -} - - -static beken_semaphore_t atsvr_scan_sema = NULL; - -static int wlan_scan_done_handler(void *arg, event_module_t event_module, - int event_id, void *event_data) -{ - if (atsvr_scan_sema) { - rtos_set_semaphore( &atsvr_scan_sema ); - } - return BK_OK; -} - -int atsvr_wlan_scan_ap_sorting(int ap_num,struct sta_scan_res *table,char **out) -{ - char *array = NULL; - char t_rssi[64][2]; - char temp[2]; - unsigned char i,j; - - if(out == NULL){ - return -1; - } - *out = NULL; - array = at_malloc(ap_num); - if(array == NULL){ - return -1; - } - for(i=0;i (char)t_rssi[i][1]){ - temp[0] = t_rssi[i][0]; - temp[1] = t_rssi[i][1]; - t_rssi[i][0] = t_rssi[j][0]; - t_rssi[i][1] = t_rssi[j][1]; - t_rssi[j][0] = temp[0]; - t_rssi[j][1] = temp[1]; - } - } - } - - for(i = 0; i < ap_num; i++){ - array[i] = t_rssi[i][0]; - } - *out = array; - return 0; -} - -static int atsvr_wlan_scan_find_ssid_len(unsigned char *ssid) -{ - int i; - - for(i = 0;i < 32; i++){ - if(ssid[i] == '\0'){ - break; - } - } - return i; -} - -int atsvr_wlan_scan_ap_result(void) -{ - wifi_scan_result_t scan_result = {0}; - char *resultbuf = NULL; - int i; - int n = 0; - - BK_LOG_ON_ERR(bk_wifi_scan_dump_result(&scan_result)); - bk_wifi_scan_free_result(&scan_result); - -#define ATSVR_WLAN_SCAN_BUF_SIZE (5 * 1024) - resultbuf = at_malloc(ATSVR_WLAN_SCAN_BUF_SIZE); - if(resultbuf == NULL) { - ATSVRLOG("resultbuf malloc failed!\r\n"); - return 1; - } - if (bk_wifi_scan_get_result(&scan_result) == BK_OK) { - int ap_num = scan_result.ap_num; - - bk_printf("Got ap count: %d\r\n", scan_result.ap_num); - resultbuf[0] = '\0'; - for (i = 0; i < ap_num; i++) { - if(atsvr_wlan_scan_find_ssid_len((unsigned char*)scan_result.aps[i].ssid) >= 32){ - char temp[33]; - memcpy(temp,scan_result.aps[i].ssid,32); - temp[32] = '\0'; - n += sprintf(resultbuf+n,ATSVR_CMDRSP_HEAD"+WSCAN:%s,",temp); - }else{ - n += sprintf(resultbuf+n,ATSVR_CMDRSP_HEAD"+WSCAN:%s,",scan_result.aps[i].ssid); - } - switch(scan_result.aps[i].security) { - case BK_SECURITY_TYPE_NONE: - n += sprintf(resultbuf+n,"%s","OPEN"); - break; - case BK_SECURITY_TYPE_WEP: - n += sprintf(resultbuf+n,"%s","WEP_SHARED"); - break; - case BK_SECURITY_TYPE_WPA_TKIP: - n += sprintf(resultbuf+n,"%s","WPA_TKIP_PSK"); - break; - case BK_SECURITY_TYPE_WPA_AES: - n += sprintf(resultbuf+n,"%s","WPA_AES_PSK"); - break; - case BK_SECURITY_TYPE_WPA2_TKIP: - n += sprintf(resultbuf+n,"%s","WPA2_TKIP_PSK"); - break; - case BK_SECURITY_TYPE_WPA2_AES: - n += sprintf(resultbuf+n,"%s","WPA2_AES_PSK"); - break; - case BK_SECURITY_TYPE_WPA2_MIXED: - n += sprintf(resultbuf+n,"%s","WPA2_MIXED_PSK"); - break; - case BK_SECURITY_TYPE_WPA3_SAE: - n += sprintf(resultbuf+n,"%s","WPA3_SAE"); - break; - case BK_SECURITY_TYPE_WPA3_WPA2_MIXED: - n += sprintf(resultbuf+n,"%s","WPA3_WPA2_MIXED"); - break; - case BK_SECURITY_TYPE_OWE: - n += sprintf(resultbuf+n,"%s","OWE"); - break; - case BK_SECURITY_TYPE_AUTO: - n += sprintf(resultbuf+n,"%s","AUTO_PSK"); - break; - default: - n += sprintf(resultbuf+n,"%s","UNKNOWN"); - break; - } - n += sprintf(resultbuf+n,",%d",ATSVR_RSSI2APPOWER(scan_result.aps[i].rssi)); ///RSSI - n += sprintf(resultbuf+n,","BK_MAC_FORMAT, BK_MAC_STR(scan_result.aps[i].bssid)); - n += sprintf(resultbuf+n,",%d\r\n", scan_result.aps[i].channel); - if(n > (ATSVR_WLAN_SCAN_BUF_SIZE - 512)){ - atsvr_output_msg(resultbuf,strlen(resultbuf)); - resultbuf[0] = '\0'; - n = 0; - } - } - - bk_wifi_scan_free_result(&scan_result); - atsvr_output_msg(resultbuf,strlen(resultbuf)); - } - - if(resultbuf) { - at_free(resultbuf); - resultbuf = NULL; - } - return 0; -} - -int wlan_scan_start(char *ssid) -{ - int err; - - if( atsvr_scan_sema == NULL ) { - err = rtos_init_semaphore( &atsvr_scan_sema, 1 ); - if(err != kNoErr){ - return -1; - } - } - - bk_event_register_cb(EVENT_MOD_WIFI, EVENT_WIFI_SCAN_DONE, - wlan_scan_done_handler, NULL); - - BK_LOG_ON_ERR(bk_wifi_scan_start(NULL)); - if(atsvr_scan_sema != NULL) { - err = rtos_get_semaphore(&atsvr_scan_sema, ATSVR_SCAN_TIMEOUT_MS); - if(err != kNoErr) { - ATSVRLOG("atsvr scan wait semaphore error!\r\n"); - } else { - ATSVRLOG("atsvr scan wait semaphore error!\r\n"); - } - } else { - ATSVRLOG("atsvr waited semaphore!\r\n"); - return -1; - } - - return 0; -} - - -int wlan_event_handler(int event) -{ - int ret = 0; - switch(event){ - case ATSVR_WLAN_DISCONNECT: - atsvr_wlan.station_status = STATION_DOWN; - ATSVR_SIZEOF_OUTPUT_STRRING(ATSVR_EVT_WLAN_DISCONNECTED); - break; - case ATSVR_WLAN_CONNECTTED: - atsvr_wlan.station_status = STATION_UP; - ATSVR_SIZEOF_OUTPUT_STRRING(ATSVR_EVT_WLAN_CONNECTED); - break; - case ATSVR_WLAN_GOT_IP: - ATSVR_SIZEOF_OUTPUT_STRRING(ATSVR_EVT_GOT_IP); - break; - default: - ret = -1; - break; - } - return ret; -} - - -static void wlan_status_callback(void *ctxt) -{ - wifi_linkstate_reason_t info = *(wifi_linkstate_reason_t info*)ctxt; - - ATSVRLOG("[WLAN]event(%x)\r\n", info.state); - switch(info.state){ - case WIFI_LINKSTATE_STA_GOT_IP: - atsvr_event_sender(ATSVR_WLAN_GOT_IP); - break; - case WIFI_LINKSTATE_STA_CONNECTED: - atsvr_event_sender(ATSVR_WLAN_CONNECTTED); - break; - case WIFI_LINKSTATE_STA_DISCONNECTED: - atsvr_event_sender(ATSVR_WLAN_DISCONNECT); - break; - default: - break; - } -} - -int judge_the_string_is_ipv4_string(char *is_ip_string) -{ - int len = strlen(is_ip_string); - - if((len > 16 ) || (len < 7 )){ - return -1; - } - if(is_ip_string[(len - 1)] == '.'){ - return -1; - } - int num; - int point_num = 0; - char *p,*p_prev = is_ip_string; - char ip_num[4]; - int i,j; - - while(1){ - p = strchr(p_prev, '.'); - if((p == NULL) && (point_num != 3)) { - return -1; - } - point_num++; - i = p - p_prev; - if((i <= 3) && (i > 0)){ - for(j = 0; j < i; j++) { - ip_num[j] = p_prev[j]; - if((ip_num[j] < '0') || (ip_num[j] > '9')){ - return -1; - } - } - ip_num[j] = '\0'; - num = atoi( ip_num ); - if(num < 0 || num > 255){ - return -1; - }else { - p_prev = p + 1; - if(point_num == 3) { - p = strchr(p_prev, '.'); - if(p != NULL){ - return -1; - } - i = strlen(p_prev); - if(i > 3 || i <= 0){ - return -1; - } - for(j = 0; j < i; j++) { - ip_num[j] = p_prev[j]; - if((ip_num[j] < '0') || (ip_num[j] > '9')){ - return -1; - } - } - ip_num[j] = '\0'; - num = atoi( ip_num ); - if(num < 0 || num > 255){ - return -1; - } - return 0; - } - } - }else{ - return -1; - } - } - - return 0; -} - -void atsvr_wlan_init(void) -{ - extern void bk_wlan_status_register_cb(FUNC_1PARAM_PTR cb); - bk_wlan_status_register_cb(wlan_status_callback); -} - diff --git a/bk7235/liteos_m/bk_sdk_armino/components/at_server/atsvr_cmd/atsvr_wlan.h b/bk7235/liteos_m/bk_sdk_armino/components/at_server/atsvr_cmd/atsvr_wlan.h deleted file mode 100755 index 862c911c2beb11c582b3fd48d8c004ae1cb85d98..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/at_server/atsvr_cmd/atsvr_wlan.h +++ /dev/null @@ -1,84 +0,0 @@ -#ifndef _ATSVR_WLAN_H_ -#define _ATSVR_WLAN_H_ - -#define ATSVR_MAX_SSID_LEN 32 - -#define ATSVR_WLAN_DEFAULT_IP "192.168.19.1" -#define ATSVR_WLAN_DEFAULT_GW "192.168.19.1" -#define ATSVR_WLAN_DEFAULT_MASK "255.255.255.0" -#define ATSVR_WLAN_DEFAULT_DNS "192.168.19.1" - -#define ATSVR_WLAN_STA_DEFAULT_IP "192.168.0.19" -#define ATSVR_WLAN_STA_DEFAULT_GW "192.168.0.19" -#define ATSVR_WLAN_STA_DEFAULT_MASK "255.255.255.0" -#define ATSVR_WLAN_STA_DEFAULT_DNS "192.168.0.1" - -#define ATSVR_SCAN_TIMEOUT_MS (4000) - -#ifndef ATSVR_MACSTR -#define ATSVR_MACSTR "%02x:%02x:%02x:%02x:%02x:%02x " -#endif -#ifndef ATSVR_MAC2STR -#define ATSVR_MAC2STR(a) (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5] -#endif - -#define ATSVR_RSSI2APPOWER(rssi) (((rssi + 100) > 100) ? 100 : (rssi + 100)) - -typedef enum atsvr_wlan_sec_type_e -{ - ATSVR_SEC_TYPE_NONE = 0, /**< Open system. */ - ATSVR_SEC_TYPE_WEP, /**< Wired Equivalent Privacy. WEP security. */ - ATSVR_SEC_TYPE_WPA_TKIP, /**< WPA /w TKIP */ - ATSVR_SEC_TYPE_WPA_AES, /**< WPA /w AES */ - ATSVR_SEC_TYPE_WPA2_TKIP, /**< WPA2 /w TKIP */ - ATSVR_SEC_TYPE_WPA2_AES, /**< WPA2 /w AES */ - ATSVR_SEC_TYPE_WPA2_MIXED, /**< WPA2 /w AES or TKIP */ - ATSVR_SEC_TYPE_WPA3_SAE, /**< WPA3 SAE */ - ATSVR_SEC_TYPE_WPA3_WPA2_MIXED, /** WPA3 SAE or WPA2 AES */ - ATSVR_SEC_TYPE_OWE, /**< WPA3 OWE */ - ATSVR_SEC_TYPE_AUTO, /**< It is used when calling @ref bkWlanStartAdv, It's read security type from scan result. */ -}atsvr_wlan_sec_type; - -typedef struct{ - char ssid[33]; /**< The SSID of an access point. */ - char ApPower; /**< Signal strength, min:0, max:100. */ - char channel; /**< The RF frequency, 1-13*/ - atsvr_wlan_sec_type security; /**< Security type, @ref atsvr_wlan_sec_type*/ -}atsvr_ap_item; - -typedef struct _atsvr_scan_result{ - char ApNum; - atsvr_ap_item *ApList; -}atsvr_scan_result; - -extern void wlan_get_station_mac_address(char *mac); -extern void wlan_get_softap_mac_address(char *mac); -extern void wlan_set_station_dhcp(int en); -extern int wlan_get_station_dhcp(void); - -extern int wlan_set_station_static_ip(char *ip,char *mask,char *gate,char *dns,char *dns2); -extern int wlan_set_station_dns(char *dns_ip,char *dns2_ip); - -extern int wlan_get_station_cur_status(void); - -extern int wlan_start_station_connect(char *my_ssid,char* connect_key); -extern int wlan_stop_station(void); - - -extern int wlan_softap_start(char *ap_ssid, char *ap_key); -extern int wlan_stop_softap(void); - -extern int wlan_set_softap_static_ip(char *ip,char *mask,char *gate,char *dns_ip); -extern int wlan_set_softap_dns(char *dns_ip); -extern int wlan_get_softap_cur_status(void); -extern int wlan_scan_start(char *ssid); - -extern int wlan_event_handler(int event); - -extern atsvr_wlan_sec_type wlan2atsvr_sec_type(int sec_type); -extern int atsvr2wlan_sec_type(atsvr_wlan_sec_type sec_type); -extern int judge_the_string_is_ipv4_string(char *is_ip_string); - -extern void atsvr_wlan_init(void); - -#endif diff --git a/bk7235/liteos_m/bk_sdk_armino/components/at_server/atsvr_unite.h b/bk7235/liteos_m/bk_sdk_armino/components/at_server/atsvr_unite.h deleted file mode 100755 index 50ce714ebf4580c095356e818f71d2849e5be898..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/at_server/atsvr_unite.h +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef _ATSVR_UNITE_H_ -#define _ATSVR_UNITE_H_ - -#include "_at_svr_opts.h" - -#if ATSVR_HANDLER_ENV -typedef void (*atsvr_handler)(void*env,int argc, char **argv); -#else -typedef void (*atsvr_handler)(int argc, char **argv); -#endif - -/* Structure for registering at server commands */ -struct _atsvr_command{ - const char *name; - const char *help; - - atsvr_handler function; -#if defined(ATSVR_OPTIM_FD_CMD) && ATSVR_OPTIM_FD_CMD - unsigned char name_len; -#endif -}; - -typedef struct _atsvr_command atsvr_command_t; -typedef struct _atsvr_command atsvr_command; -typedef struct _atsvr_command _atsvr_command_t; - - -typedef void (*output_func_t)(char *msg,unsigned int msg_len); -typedef int (*resources_protection)(int is_lock,unsigned int timeout); -typedef unsigned int (*input_msg_get_t)(char *data,unsigned int dat_len); - -#endif diff --git a/bk7235/liteos_m/bk_sdk_armino/components/base64/base_64.c b/bk7235/liteos_m/bk_sdk_armino/components/base64/base_64.c index 2d5c6a510a5386c0c173ff1e6b8b3c47f8558325..452e4ba32876f147eb7c7715fd7c5d4285d4b585 100644 --- a/bk7235/liteos_m/bk_sdk_armino/components/base64/base_64.c +++ b/bk7235/liteos_m/bk_sdk_armino/components/base64/base_64.c @@ -1,3 +1,17 @@ +/* + * Copyright (C) 2022 Beken Corporation + * 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 "base_64.h" #include #include diff --git a/bk7235/liteos_m/bk_sdk_armino/components/base64/base_64.h b/bk7235/liteos_m/bk_sdk_armino/components/base64/base_64.h index 22f5402f9781d27f2f7b7bd974ccef79d46d3b99..e47542a15f8eeefd1279aeb958c316fd09d7a723 100644 --- a/bk7235/liteos_m/bk_sdk_armino/components/base64/base_64.h +++ b/bk7235/liteos_m/bk_sdk_armino/components/base64/base_64.h @@ -1,3 +1,17 @@ +/* + * Copyright (C) 2022 Beken Corporation + * 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 _BSAE64_ENC_H_ #define _BSAE64_ENC_H_ diff --git a/bk7235/liteos_m/bk_sdk_armino/components/bk_ble/legacy_include/bluetooth_legacy_include.h b/bk7235/liteos_m/bk_sdk_armino/components/bk_ble/legacy_include/bluetooth_legacy_include.h index 5f1b6754c81f4bfc43198f9920fb2b4097de269d..16b0e3dc7c06a74792b53cff85d34ccd00bd8add 100644 --- a/bk7235/liteos_m/bk_sdk_armino/components/bk_ble/legacy_include/bluetooth_legacy_include.h +++ b/bk7235/liteos_m/bk_sdk_armino/components/bk_ble/legacy_include/bluetooth_legacy_include.h @@ -1,3 +1,17 @@ +/* + * Copyright (C) 2022 Beken Corporation + * 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. + */ #pragma once #ifdef __cplusplus diff --git a/bk7235/liteos_m/bk_sdk_armino/components/bk_bt/legacy_include/bt_include.h b/bk7235/liteos_m/bk_sdk_armino/components/bk_bt/legacy_include/bt_include.h index bd85093535b1d275ed1d50b44ed81e21c2e14f36..fc4d8045ce717ecb4112a1aeedce95d1b8aabbcc 100755 --- a/bk7235/liteos_m/bk_sdk_armino/components/bk_bt/legacy_include/bt_include.h +++ b/bk7235/liteos_m/bk_sdk_armino/components/bk_bt/legacy_include/bt_include.h @@ -1,3 +1,17 @@ +/* + * Copyright (C) 2022 Beken Corporation + * 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 INCLUDE_MODULES_BK_BT_INCLUDE_H_ #define INCLUDE_MODULES_BK_BT_INCLUDE_H_ diff --git a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/CMakeLists.txt b/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/CMakeLists.txt deleted file mode 100755 index d40f749624669a9fc22604a3885794001a9252f2..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/CMakeLists.txt +++ /dev/null @@ -1,306 +0,0 @@ -set(incs include include/bk_private) - -list(APPEND incs - ../../properties/modules/aec/ - . - ) - -if (CONFIG_CLI) -set(srcs - cli_adc.c - cli_ble.c - cli_event.c - cli_keyValue.c - cli_gpio.c - cli_main.c - cli_misc.c - cli_mico.c - cli_mem.c - cli_os.c - cli_rpc.c - cli_reg.c - cli_timer.c - cli_temp_detect.c - cli_uart.c - cli_security.c - cli_spi.c - cli_exception.c - cli_icu.c - ) - -if (CONFIG_INT_WDT) - list(APPEND srcs - cli_wdt.c - ) -endif() - -if (CONFIG_STA_PS) - list(APPEND srcs - cli_pwr.c - ) -endif() - -if (CONFIG_OTA_TFTP OR CONFIG_OTA_HTTP) - list(APPEND srcs - cli_ota.c - ) -endif() - -if (CONFIG_WIFI_ENABLE) - list(APPEND srcs - cli_wifi.c - cli_phy.c - ) -endif() - -if (CONFIG_AIRKISS_TEST) - list(APPEND srcs - cli_airkiss.c - ) -endif() - -if (CONFIG_IPERF_TEST) - list(APPEND srcs - cli_iperf.c - ) -endif() - -if (CONFIG_GENERAL_DMA) - list(APPEND srcs - cli_dma.c - ) -endif() - -if (CONFIG_SDCARD_HOST) - list(APPEND srcs - cli_sd.c - ) -endif() - -if (CONFIG_PWM) - list(APPEND srcs - cli_pwm.c - ) -endif() - -if (CONFIG_I2C) - list(APPEND srcs - cli_i2c.c - ) -endif() - -if (CONFIG_SUPPORT_MATTER) - list(APPEND srcs - cli_matter.c - ) -endif() - -if (CONFIG_FLASH) - list(APPEND srcs - cli_flash.c - ) -endif() - -if (CONFIG_FLASH) - list(APPEND srcs - cli_flash_test.c - ) -endif() - -if (CONFIG_TRNG_SUPPORT) - list(APPEND srcs - cli_trng.c - ) -endif() - -if (CONFIG_I2S) - list(APPEND srcs - cli_i2s.c - ) -endif() - -if (CONFIG_FATFS) - list(APPEND srcs "cli_fatfs.c") -endif() - -if (CONFIG_EFUSE) - list(APPEND srcs - cli_efuse.c - ) -endif() - -if (CONFIG_SDIO_HOST) - list(APPEND srcs - cli_sdio_host.c - ) -endif() - -if (CONFIG_LWIP) - list(APPEND srcs - cli_lwip.c - ) -endif() - -if (CONFIG_BK_NETIF) - list(APPEND srcs - cli_netif.c - ) -endif() - -if (CONFIG_SHELL_ASYNCLOG) - list(APPEND srcs - shell_task.c - shell_uart.c - ) - if (CONFIG_MASTER_CORE) - list(APPEND srcs - shell_mailbox_ipc.c - ) - endif() - if (CONFIG_SLAVE_CORE) - list(APPEND srcs - shell_mailbox_cp1.c - ) - endif() -endif() - -if (CONFIG_DUAL_CORE) - list(APPEND srcs - rpc_client_gpio.c - ) -endif() - -if (CONFIG_SOC_BK7271) - list(APPEND srcs "cli_dsp_bk7271.c") -endif() - -if (CONFIG_SOC_BK7256XX) - list(APPEND srcs "cli_usb.c") -endif() - -if (CONFIG_SOC_BK7256XX OR CONFIG_USB_UVC) -if (CONFIG_DUAL_CORE AND CONFIG_PSRAM) - list(APPEND srcs "cli_uvc.c") -endif() -endif() - -if (CONFIG_SECURITYIP) - list(APPEND srcs "cli_securityip.c") -endif() - -if (CONFIG_QSPI) - list(APPEND srcs - "cli_qspi.c" - ) -endif() - -if (CONFIG_AON_RTC_TEST) - list(APPEND srcs - "cli_aon_rtc.c" - ) -endif() - -if (CONFIG_JPEG_ENCODE) - list(APPEND srcs - "cli_jpegenc.c" - ) -endif() - - -if (CONFIG_AT_CMD) - list(APPEND srcs "cli_at.c") -endif() - -if (CONFIG_LCD_TEST) - list(APPEND srcs - "cli_lcd.c") -endif() #CONFIG_LCD_TEST -if (CONFIG_DMA2D_TEST) - list(APPEND srcs - "cli_dma2d.c" - ) -endif() #CONFIG_DMA2D_TEST - - -if (CONFIG_AUDIO_TEST AND CONFIG_AUDIO_RISCV_IP_V1_0) - list(APPEND srcs "cli_aud.c") -endif() #if(CONFIG_AUDIO) - -if (CONFIG_AUDIO_TEST) -if (CONFIG_AUDIO_RISCV_IP_V1_0 AND CONFIG_DUAL_CORE) -if (NOT CONFIG_SLAVE_CORE) - list(APPEND srcs cli_aud_cp0.c) -endif() -endif() -endif() - -if (CONFIG_AUDIO_AEC_TEST) - list(APPEND srcs "cli_aec.c") -endif() - -if (CONFIG_AUDIO_G711_TEST) - list(APPEND srcs "cli_g711.c") -endif() - -if (CONFIG_AUDIO_MP3_TEST) - list(APPEND srcs "cli_mp3.c") -endif() - -if (CONFIG_FFT_TEST) - list(APPEND srcs "cli_fft.c") -endif() - -if (CONFIG_SBC_TEST) - list(APPEND srcs "cli_sbc.c") -endif() - -if (CONFIG_I2S_TEST) - list(APPEND srcs "cli_i2s.c") -endif() - -if (CONFIG_TOUCH) - list(APPEND srcs "cli_touch.c") -endif() - -if (CONFIG_CALENDAR) - list(APPEND srcs "cli_calendar.c") -endif() - -endif() #if(CONFIG_CLI) - -if (CONFIG_JPEG_DECODE) - list(APPEND srcs cli_jpegdec.c) -endif() - -if (CONFIG_JPEG_DECODE) - list(APPEND srcs cli_jpegdec.c) -endif() - -if (CONFIG_CAMERA OR CONFIG_SPIDMA) -if (CONFIG_APP_DEMO_VIDEO_TRANSFER) - list(APPEND srcs "cli_dvp.c") -endif() -endif() - -if (CONFIG_DOORBELL) - list(APPEND srcs cli_doorbell.c) -endif() - -if (CONFIG_PSRAM) - list(APPEND srcs cli_psram.c) -endif() - -if (CONFIG_AUD_INTF_TEST) - list(APPEND srcs cli_aud_intf.c) -endif() - -armino_component_register(SRCS "${srcs}" - INCLUDE_DIRS "${incs}" - REQUIRES utf8 temp_detect driver user_driver bk_system user_driver - #PRIV_REQUIRES airkiss bk_common bk_netif bk_ble bk_ps http adc_key app iperf media_common - PRIV_REQUIRES bk_common bk_netif bk_ble bk_ps bk_init at bk_wifi compal media bk_bt - ) - -if(CONFIG_ARCH_RISCV) -target_compile_options(${COMPONENT_LIB} PRIVATE -mno-relax) -endif() \ No newline at end of file diff --git a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/Kconfig b/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/Kconfig deleted file mode 100644 index 98061d16ccd5694a87e9478892f50835b90a86e1..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/Kconfig +++ /dev/null @@ -1,157 +0,0 @@ -menu "Cli" - config CLI - bool "Enable BK Cli" - default y - - config BKREG - depends on CLI - bool "Enable BK Reg read/write" - default y - - config MAX_COMMANDS - depends on CLI - int "MAX number of commands is configured by default" - range 0 65535 - default 255 - - config IPERF_TEST - depends on CLI - bool "Enable Iperf Test" - default y - - config TCP_SERVER_TEST - depends on CLI - bool "Enable TCP server Test" - default n - - config AIRKISS_TEST - depends on CLI - bool "Enable Airkiss Test" - default n - - config WIFI_RAW_TX_TEST - depends on CLI - bool "Enable WiFi Raw TX" - default n - - #TODO Exculsive?? - config I2C1_TEST - depends on CLI - bool "Enable I2C1 Test" - default n - - config I2C2_TEST - depends on CLI - bool "Enable I2C2 Test" - default n - - config UART_TEST - depends on CLI - bool "Enable Uart Test" - default n - - config SPI_TEST - depends on CLI - bool "Enable SPI Test" - default n - - config PERI_TEST - depends on CLI - bool "Enable Periperal Test" - default n - - config RF_OTA_TEST - depends on CLI - bool "Enable RF OTA Test" - default n - - config SHELL_ASYNCLOG - depends on CLI - bool "Enable Shell and Async log optimize" - default n - - config TOUCH - depends on CLI - bool "Enable TOUCH Test" - default n - config SBC_TEST - depends on CLI - bool "Enable SBC Test" - default n - - config AUDIO - depends on CLI - bool "Enable AUDIO" - default n - - config EFUSE - bool "Enable Efuse" - default y - - config ICU - bool "Enable ICU" - default y - - config SECURITYIP - bool "Enable securityIP" - default n - - config KEYVALUE - bool "Enable KEYVALUE" - default n - - config IDLE_UART_OUT_TEST - bool "Enable idle uart out test" - default n - - config COMPONENTS_WPA2_ENTERPRISE - bool "Enable WPA2 ENTERPRISE" - default n - - config COMPONENTS_WPA_TWT_TEST - bool "Enable WPA TWT TEST" - default n - - config COMPONENTS_WFA_CA - bool "WFA_CA" - default n - - config ENABLE_WIFI_DEFAULT_CONNECT - bool "Enable Wi-Fi Default Connect" - default n -endmenu - -menu "DUAL_CORE" - config DUAL_CORE - bool "Dual cpu core run as master core" - default n - - config MASTER_CORE - depends on DUAL_CORE - bool "Dual cpu core run as master core" - default n - - config SLAVE_CORE - depends on DUAL_CORE - bool "Dual cpu core run as slave core" - default n - - config SLAVE_CORE_OFFSET - depends on MASTER_CORE - int "Slave core offset address default 0x2e0000" - range 0 4194304 - default 3014656 - - config SLAVE_CORE_RESET_VALUE - depends on MASTER_CORE - int "Slave core reset value" - range 0 1 - default 1 - config EFUSE - bool "Enable Efuse" - default y - - config ICU - bool "Enable ICU" - default y -endmenu diff --git a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli.h b/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli.h deleted file mode 100644 index a08af1fe04fb82fc223f28962ac813fd048eb18f..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli.h +++ /dev/null @@ -1,122 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#include -#include -#include -#include "cli_config.h" -#include "param_config.h" -#include "bk_cli.h" -#include -#include -#include -#include -#include -#include -#include "bk_uart.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define CLI_TAG "cli" - -#define CLI_LOGI(...) BK_LOGI(CLI_TAG, ##__VA_ARGS__) -#define CLI_LOGW(...) BK_LOGW(CLI_TAG, ##__VA_ARGS__) -#define CLI_LOGE(...) BK_LOGE(CLI_TAG, ##__VA_ARGS__) -#define CLI_LOGD(...) BK_LOGD(CLI_TAG, ##__VA_ARGS__) - -#define CLI_RET_ON_INVALID_ARGC(_actual_argc, _expect_minimum_argc) do {\ - if ((_actual_argc) < (_expect_minimum_argc)) {\ - CLI_LOGE("invalid argc, expect %d actual %d\n", (_expect_minimum_argc), (_actual_argc));\ - return;\ - }\ - }while(0) - -int cli_wifi_init(void); -int cli_ble_init(void); -int cli_netif_init(void); -int cli_misc_init(void); -int cli_mem_init(void); -int cli_airkiss_init(void); -int cli_phy_init(void); - -#if CONFIG_LWIP -int cli_lwip_init(void); -#endif - -int cli_iperf_init(void); -int cli_pwr_init(void); -int cli_timer_init(void); -int cli_wdt_init(void); -int cli_trng_init(void); -int cli_efuse_init(void); -int cli_gpio_init(void); -int cli_os_init(void); -int cli_ota_init(void); -int cli_flash_init(void); -int cli_flash_test_init(void); -int cli_keyVaule_init(void); -int cli_matter_init(void); - -int cli_uart_init(void); -int cli_adc_init(void); -int cli_spi_init(void); -int cli_qspi_init(void); -int cli_i2c_init(void); -int cli_aon_rtc_init(void); -int cli_sd_init(void); -int cli_fatfs_init(void); -int cli_temp_detect_init(void); -int cli_security_init(void); -int cli_mico_init(void); -int cli_peri_init(void); -int cli_event_init(void); -int cli_pwm_init(void); -int cli_reg_init(void); -int cli_dma_init(void); -int cli_exception_init(void); -int cli_icu_init(void); -int cli_at_init(void); -#if CONFIG_SECURITYIP -int cli_vault_init(void); -#endif -int cli_aud_init(void); -int cli_aud_intf_init(void); -int cli_fft_init(void); -int cli_sbc_init(void); -int cli_touch_init(void); -int cli_jpeg_init(void); -int cli_lcd_init(void); -int cli_dma2d_init(void); -int cli_i2s_init(void); -int cli_uvc_init(void); -int cli_aud_cp0_init(void); -int cli_calendar_init(void); -int cli_jpegdec_init(void); -int cli_aec_init(void); -int cli_g711_init(void); -int cli_mp3_init(void); -int cli_dvp_init(void); -int cli_doorbell_init(void); -int cli_sdio_host_init(void); -int cli_psram_init(void); - -extern int hexstr2bin(const char *hex, u8 *buf, size_t len); - -#ifdef __cplusplus -} -#endif diff --git a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_adc.c b/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_adc.c deleted file mode 100644 index 46c47e4168729eb8af313fc13a2747543a25de46..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_adc.c +++ /dev/null @@ -1,296 +0,0 @@ -#include "cli.h" -#include "bk_saradc.h" -#include -#include "adc_statis.h" -#include -#include - -static void cli_adc_help(void) -{ - CLI_LOGI("adc_driver init/deinit\n"); - CLI_LOGI("adc_test [channel] [init/deinit/start/stop/dump_statis/get_value/single_step_mode_read\n"); - CLI_LOGI("adc_test [channel] [config] [mode] [src_clk] [adc_clk] [sature_mode] [sampl_rate]\n"); - CLI_LOGI("adc_test [channel] [read/rag_cb] [size] [time_out]\n"); - CLI_LOGI("adc_api_test [set_mode/get_mode/set_clk/set_sample_rate/set_channel/set_filter/\ - set_steady_time/set_sample_cnt/set_saturate\n"); -} - -static void cli_adc_register_cb(uint32_t param) -{ - CLI_LOGI("param:%d , adc isr cb \r\n", param); -} - -static void cli_adc_driver_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - if (argc < 2) { - cli_adc_help(); - return; - } - - if (os_strcmp(argv[1], "init") == 0) { - BK_LOG_ON_ERR(bk_adc_driver_init()); - CLI_LOGI("adc driver init\n"); - } else if (os_strcmp(argv[1], "deinit") == 0) { - BK_LOG_ON_ERR(bk_adc_driver_deinit()); - CLI_LOGI("adc driver deinit\n"); - } else { - cli_adc_help(); - return; - } -} - -static void cli_adc_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - uint32_t adc_chan; - - if (argc < 2) { - cli_adc_help(); - return; - } - - adc_chan = os_strtoul(argv[1], NULL, 10); - - if (os_strcmp(argv[2], "config") == 0) { - adc_config_t config = {0}; - os_memset(&config, 0, sizeof(adc_config_t)); - - config.chan = adc_chan; - - config.adc_mode = os_strtoul(argv[3], NULL, 10); - config.src_clk = os_strtoul(argv[4], NULL, 10); - config.clk = os_strtoul(argv[5], NULL, 10); - config.saturate_mode = os_strtoul(argv[6], NULL, 10); - config.steady_ctrl= 7; - config.adc_filter = 0; - if(config.adc_mode == ADC_CONTINUOUS_MODE) { - config.sample_rate = os_strtoul(argv[7], NULL, 10); - } - - BK_LOG_ON_ERR(bk_adc_init(adc_chan)); - BK_LOG_ON_ERR(bk_adc_set_config(&config)); - CLI_LOGI("adc init test:adc_channel:%x, adc_mode:%x,src_clk:%x,adc_clk:%x, saturate_mode:%x, sample_rate:%x", - adc_chan, config.adc_mode, config.src_clk, config.clk, config.saturate_mode, config.sample_rate); - } else if (os_strcmp(argv[2], "deinit") == 0) { - BK_LOG_ON_ERR(bk_adc_deinit(adc_chan)); - CLI_LOGI("adc deinit test"); - } else if (os_strcmp(argv[2], "start") == 0) { - BK_LOG_ON_ERR(bk_adc_set_channel(adc_chan)); - BK_LOG_ON_ERR(bk_adc_start()); - CLI_LOGI("start adc test\n"); - } else if (os_strcmp(argv[2], "stop") == 0) { - BK_LOG_ON_ERR(bk_adc_stop()); - CLI_LOGI("adc_stop test: %d\n", adc_chan); - } else if (os_strcmp(argv[2], "get_value") == 0) { - uint16_t value = 0; - float cali_value = 0; - bk_adc_acquire(); - - if(bk_adc_set_channel(adc_chan)) { - bk_adc_release(); - return; - } - - BK_LOG_ON_ERR(bk_adc_read(&value, ADC_READ_SEMAPHORE_WAIT_TIME)); - cali_value = saradc_calculate(value); - bk_adc_release(); - CLI_LOGI("adc value:%d mv\n", (uint32_t)(cali_value * 1000)); - } else if (os_strcmp(argv[2], "read") == 0) { - uint32_t sum = 0; - uint32_t size = os_strtoul(argv[3], NULL, 10); - uint16_t *recv_data = (uint16_t *)os_malloc(size); - if (recv_data == NULL) { - CLI_LOGE("recv buffer malloc failed\r\n"); - return; - } - - int time_out = os_strtoul(argv[4], NULL, 10); - if (time_out < 0) { - time_out = BEKEN_WAIT_FOREVER; - } - - bk_adc_acquire(); - - if(bk_adc_set_channel(adc_chan)) { - bk_adc_release(); - return; - } - - BK_LOG_ON_ERR(bk_adc_read_raw(recv_data, size, time_out)); -#if 0 - if((length > ADC_TEST_CNT_MAX) || (length == 0)) - return; -#endif - - bk_adc_release(); - - if (!recv_data) { - CLI_LOGE("adc read failed, recv_data is null \r\n"); - } - CLI_LOGI("adc: read length :time_out:%d read_size:%d\n",time_out, size); - - for (int i = 0; i < size; i++) { - sum = sum + recv_data[i]; - CLI_LOGI("recv_buffer[%d]=%02x, sum =%d\n", i, recv_data[i], sum); - } - sum = sum / size; - CLI_LOGI("adc read size:%d, adc_result_from _data_reg:%d\n", size, sum); - os_free(recv_data); - } else if (os_strcmp(argv[2], "dump_statis") == 0) { - adc_statis_dump(); - CLI_LOGI("adc dump statis ok\r\n"); - } else if (os_strcmp(argv[2], "single_step_mode_read") == 0) { - bk_adc_acquire(); - bk_adc_set_channel(adc_chan); - uint32_t ret = bk_adc_set_mode(ADC_SINGLE_STEP_MODE); - if(ret) { - bk_adc_release(); - return ; - } - - uint16_t sum = 0; - sum = bk_adc_read_raw(NULL, 1, 0); - bk_adc_release(); - CLI_LOGI("adc single step mode: adc value is %d\n", sum); - } else if (os_strcmp(argv[2], "reg_cb") == 0) { - uint32_t size = os_strtoul(argv[3], NULL, 10); - BK_LOG_ON_ERR(bk_adc_register_isr(cli_adc_register_cb, size)); - CLI_LOGI("adc isr cb register\r\n"); - } - else if (0 == os_strcmp(argv[2], "saradc_val_read")) - { - uint32_t status; - status=0; - //status = manual_cal_load_adc_cali_flash(); - if (status != 0) - { - os_printf("Can't read cali value, use default!\r\n"); - os_printf("calibrate low value:[%x]\r\n", saradc_val.low); - os_printf("calibrate high value:[%x]\r\n", saradc_val.high); - } - } - else if(0 == os_strcmp(argv[2], "use_sample_set_saradc_val")) - { - uint16_t sample_value= 0; - uint8_t ret; - SARADC_MODE saradc_cal_mode; - - adc_config_t config = {0}; - os_memset(&config, 0, sizeof(adc_config_t)); - - config.chan = adc_chan; - - config.adc_mode = os_strtoul(argv[3], NULL, 10); - config.src_clk = os_strtoul(argv[4], NULL, 10); - config.clk = os_strtoul(argv[5], NULL, 10); - config.saturate_mode = os_strtoul(argv[6], NULL, 10); - config.steady_ctrl= 7; - config.adc_filter = 0; - if(config.adc_mode == ADC_CONTINUOUS_MODE) - { - config.sample_rate = os_strtoul(argv[7], NULL, 10); - } - BK_LOG_ON_ERR(bk_adc_init(adc_chan)); - BK_LOG_ON_ERR(bk_adc_set_config(&config)); - CLI_LOGI("adc init test:adc_channel:%x, adc_mode:%x,src_clk:%x,adc_clk:%x, saturate_mode:%x, sample_rate:%x", - adc_chan, config.adc_mode, config.src_clk, config.clk, config.saturate_mode, config.sample_rate); - - BK_LOG_ON_ERR(bk_adc_set_channel(adc_chan)); - - if (0 == os_strcmp(argv[8], "low")) - { - saradc_cal_mode = SARADC_CALIBRATE_LOW; - } - else if (0 == os_strcmp(argv[3], "high")) - { - saradc_cal_mode = SARADC_CALIBRATE_HIGH; - } - else - { - os_printf("invalid parameter\r\n"); - return; - } - - BK_LOG_ON_ERR(bk_adc_start()); - CLI_LOGI("start adc test\n"); - - bk_adc_acquire(); - BK_LOG_ON_ERR(bk_adc_read(&sample_value, ADC_READ_SEMAPHORE_WAIT_TIME)); - - ret = saradc_set_calibrate_val(&sample_value, saradc_cal_mode); - if(ret == SARADC_FAILURE) - { - os_printf("saradc_set_calibrate_val fail\r\n"); - } - os_printf("saradc_set_calibrate_val success\r\n"); - os_printf("mode:[%s] value:[%d]\r\n", (saradc_cal_mode ? "high" : "low"), sample_value); - //BK_LOG_ON_ERR(bk_adc_stop()); - } - else - { - cli_adc_help(); - return; - } -} - -static void cli_adc_api_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - if (argc < 2) { - cli_adc_help(); - return; - } - - if (os_strcmp(argv[1], "set_clk") == 0) { - uint32_t clk = os_strtoul(argv[2], NULL, 10); - uint32_t src_clk = os_strtoul(argv[3], NULL, 10); - BK_LOG_ON_ERR(bk_adc_set_clk(src_clk, clk)); - CLI_LOGI("adc set clk: clk_src:%d, clk:%d", src_clk, clk); - } else if (os_strcmp(argv[1], "set_mode") == 0) { - uint32_t mode = os_strtoul(argv[2], NULL, 10); - BK_LOG_ON_ERR(bk_adc_set_mode(mode)); - CLI_LOGI("adc set_mode: %x", mode); - } else if (os_strcmp(argv[1], "set_channel") == 0) { - uint32_t adc_chan = os_strtoul(argv[2], NULL, 10); - BK_LOG_ON_ERR(bk_adc_set_channel(adc_chan)); - CLI_LOGI("adc %d test", adc_chan); - }else if (os_strcmp(argv[1], "set_sample_rate") == 0) { - uint32_t sample_rate = os_strtoul(argv[2], NULL, 10); - BK_LOG_ON_ERR(bk_adc_set_sample_rate(sample_rate)); - CLI_LOGI("adc sample rate: %x", sample_rate); - } else if (os_strcmp(argv[1], "set_filter") == 0) { - uint32_t filter = os_strtoul(argv[2], NULL, 10); - BK_LOG_ON_ERR(bk_adc_set_filter(filter)); - CLI_LOGI("adc set_filter : %x", filter); - } else if (os_strcmp(argv[1], "set_steady_time") == 0) { - uint32_t time = os_strtoul(argv[2], NULL, 10); - BK_LOG_ON_ERR(bk_adc_set_steady_time(time)); - CLI_LOGI("adc set_steady time : %x", time); - }else if (os_strcmp(argv[1], "set_sample_cnt") == 0) { - uint32_t sample_cnt = os_strtoul(argv[2], NULL, 10); - BK_LOG_ON_ERR(bk_adc_set_sample_cnt(sample_cnt)); - CLI_LOGI("adc set_sample_cnt: %x", sample_cnt); - } else if (os_strcmp(argv[1], "set_saturate") == 0) { - uint32_t saturate = os_strtoul(argv[2], NULL, 10); - BK_LOG_ON_ERR(bk_adc_set_saturate_mode(saturate)); - CLI_LOGI("adc set_set_saturate: %x", saturate); - } else if (os_strcmp(argv[1], "get_mode") == 0) { - uint32_t mode = 0; - mode = bk_adc_get_mode(); - CLI_LOGI("adc get_mode: %x", mode); - } else { - cli_adc_help(); - return; - } -} - -#define ADC_CMD_CNT (sizeof(s_adc_commands) / sizeof(struct cli_command)) -static const struct cli_command s_adc_commands[] = { - {"adc_driver", "adc_driver [init/deinit]", cli_adc_driver_cmd}, - {"adc_test", "adc_test [channel] [start/stop/dump_statis]", cli_adc_cmd}, - {"adc_api_test", "adc_api_test []", cli_adc_api_cmd}, - -}; - -int cli_adc_init(void) -{ - return cli_register_commands(s_adc_commands, ADC_CMD_CNT); -} diff --git a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_aec.c b/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_aec.c deleted file mode 100755 index 82f321b7bdadd89430792b1819390a0ede2d61c4..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_aec.c +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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 "cli.h" - -extern void cli_aec_test_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv); - -#define AEC_CMD_CNT (sizeof(s_aec_commands) / sizeof(struct cli_command)) -static const struct cli_command s_aec_commands[] = { - {"aec_test", "aec_test", cli_aec_test_cmd}, -}; - -int cli_aec_init(void) -{ - return cli_register_commands(s_aec_commands, AEC_CMD_CNT); -} - diff --git a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_airkiss.c b/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_airkiss.c deleted file mode 100644 index acb103fd35143634d036d36db721dbce9765843a..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_airkiss.c +++ /dev/null @@ -1,77 +0,0 @@ -#include "cli.h" - -#if CONFIG_AIRKISS_TEST -u32 airkiss_process(u8 start); -uint32_t bk_airkiss_process(uint32_t start); -#endif - -#if CONFIG_AIRKISS_TEST -void cli_wifi_airkiss_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - u8 is_fail = 0; - u8 start = 0; - char *in_str, *end_ptr; - - if (argc != 2) { - os_printf("need 2 parameters: airkiss 1(start), 0(stop)\r\n"); - return; - } - - in_str = argv[1]; - start = strtol(in_str, &end_ptr, 0); - if (end_ptr == in_str) - is_fail = 1; - else if ('\0' == *end_ptr) { - } else - is_fail = 1; - - if (!((0 == start) || (1 == start))) - is_fail = 1; - - if (is_fail) - os_printf("check the cli parameter, thx\r\n"); - else - airkiss_process(start); -} - -void cli_airkiss_v2_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - u8 is_fail = 0; - u8 start = 0; - char *in_str, *end_ptr; - - if (argc != 2) { - os_printf("need 2 parameters: airkiss_v2 1(start), 0(stop)\r\n"); - return; - } - - in_str = argv[1]; - start = strtol(in_str, &end_ptr, 0); - if (end_ptr == in_str) - is_fail = 1; - else if ('\0' == *end_ptr) { - } else - is_fail = 1; - - if (!((0 == start) || (1 == start))) - is_fail = 1; - - if (is_fail) - os_printf("check the cli parameter, thx\r\n"); - else - bk_airkiss_process(start); -} -#endif - -#define AIRKISS_CMD_CNT (sizeof(s_airkiss_commands) / sizeof(struct cli_command)) -static const struct cli_command s_airkiss_commands[] = { -#if CONFIG_AIRKISS_TEST - {"airkiss", "airkiss {0|1}", cli_wifi_airkiss_cmd}, - {"airkiss_v2", "ak {0|1}", cli_airkiss_v2_cmd}, -#endif -}; - -int cli_airkiss_init(void) -{ - return cli_register_commands(s_airkiss_commands, AIRKISS_CMD_CNT); -} diff --git a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_aon_rtc.c b/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_aon_rtc.c deleted file mode 100755 index ebfa53ed1b49f44be5e73ba4b6be0ef970d65e8b..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_aon_rtc.c +++ /dev/null @@ -1,312 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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 -#include "cli.h" -#include - -static void alarm_auto_test_callback(aon_rtc_id_t id, uint8_t *name_p, void *param); - - -static void cli_aon_rtc_help(void) -{ - CLI_LOGI("aon_rtc_driver init\r\n"); - CLI_LOGI("aon_rtc_driver deinit\r\n"); -#if 0 //remove it, only one HW can't be used for many APPs. - CLI_LOGI("aon_rtc create \r\n"); - CLI_LOGI("aon_rtc destroy\r\n"); - CLI_LOGI("aon_rtc_int tick\r\n"); - CLI_LOGI("aon_rtc_int upper\r\n"); -#endif - CLI_LOGI("aon_rtc_register {id} {name} {period_tick} {period_cnt}, {callback}\r\n"); - CLI_LOGI("aon_rtc_unregister {id} {name}\r\n"); - CLI_LOGI("aon_rtc_timing_test {id} {rounds} {cycles} {set tick val}\r\n"); -} - -#if 0 //remove it, only one HW can't be used for many APPs. -static void cli_aon_rtc_tick_isr(aon_rtc_id_t id, uint8_t *name_p, void *param) -{ - CLI_LOGI("aon_rtc_tick_isr(%d)\n", id); -} - -static void cli_aon_rtc_upper_isr(aon_rtc_id_t id, uint8_t *name_p, void *param) -{ - CLI_LOGI("aon_rtc_upper_isr(%d)\n", id); -} -#endif - -static void cli_aon_rtc_driver_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - if (argc < 2) { - cli_aon_rtc_help(); - return; - } - - if (os_strcmp(argv[1], "init") == 0) { - BK_LOG_ON_ERR(bk_aon_rtc_driver_init()); - CLI_LOGI("aon_rtc driver init\n"); - } else if (os_strcmp(argv[1], "deinit") == 0) { - BK_LOG_ON_ERR(bk_aon_rtc_driver_deinit()); - CLI_LOGI("aon_rtc driver deinit\n"); - } else { - cli_aon_rtc_help(); - return; - } -} - -#if 0 //remove it, only one HW can't be used for many APPs. -static void cli_aon_rtc_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - uint32_t aon_rtc_id; - uint64_t tick; - uint32_t period; - - aon_rtc_id = os_strtoul(argv[1], NULL, 10); - - if (os_strcmp(argv[2], "create") == 0) { - tick = os_strtoul(argv[3], NULL, 10); - period = os_strtoul(argv[4], NULL, 10); - BK_LOG_ON_ERR(bk_aon_rtc_create(aon_rtc_id, tick, period)); - CLI_LOGI("aon_rtc id:%d bk_aon_rtc_create\n", aon_rtc_id); - } else if (os_strcmp(argv[2], "destroy") == 0) { - BK_LOG_ON_ERR(bk_aon_rtc_destroy(aon_rtc_id)); - CLI_LOGI("aon_rtc id:%d bk_aon_rtc_destroy\n", aon_rtc_id); - } else if (os_strcmp(argv[2], "init") == 0) { - BK_LOG_ON_ERR(bk_aon_rtc_tick_init()); - CLI_LOGI("aon_rtc id:%d bk_aon_rtc_tick_init\n", aon_rtc_id); - } else if (os_strcmp(argv[2], "deinit") == 0) { - BK_LOG_ON_ERR(bk_aon_rtc_destroy(aon_rtc_id)); - CLI_LOGI("aon_rtc id:%d bk_aon_rtc_deinit\n", aon_rtc_id); - } else if (os_strcmp(argv[2], "set") == 0) { - tick = os_strtoul(argv[3], NULL, 10); - tick = 32 * 1000 * tick; - BK_LOG_ON_ERR(bk_aon_rtc_create(0, tick, 1)); - CLI_LOGI("aon_rtc id:%d set rtc period = %d s.\n", aon_rtc_id, tick); - } else if (os_strcmp(argv[2], "get") == 0) { - tick = bk_aon_rtc_get_current_tick(aon_rtc_id); - tick = tick / 32000; - CLI_LOGI("aon_rtc id:%d get rtc tick time = %d s.\n", aon_rtc_id, tick); - } else { - cli_aon_rtc_help(); - return; - } -} - -static void cli_aon_rtc_int_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - uint32_t aon_rtc_id; - - if (argc != 3) { - cli_aon_rtc_help(); - return; - } - - aon_rtc_id = os_strtoul(argv[1], NULL, 10); - if (os_strcmp(argv[2], "tick") == 0) { - BK_LOG_ON_ERR(bk_aon_rtc_register_tick_isr(aon_rtc_id, cli_aon_rtc_tick_isr, NULL)); - CLI_LOGI("aon_rtc id:%d register tick interrupt isr\n", aon_rtc_id); - } else if (os_strcmp(argv[2], "upper") == 0) { - BK_LOG_ON_ERR(bk_aon_rtc_register_upper_isr(aon_rtc_id, cli_aon_rtc_upper_isr, NULL)); - CLI_LOGI("aon_rtc id:%d register upper interrupt isr\n", aon_rtc_id); - } else { - cli_aon_rtc_help(); - return; - } -} -#endif - -static uint8_t alarm_param[12] = {'a', 'l', 'a', 'r', 'm', 'p', 'r', 'm', 0, 0, 0, 0}; -static void alarm_callback(aon_rtc_id_t id, uint8_t *name_p, void *param) -{ - CLI_LOGI("id=%d, name=%s %s\r\n", id, name_p, alarm_param); -} - -static void cli_aon_rtc_get_time(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - uint32_t aon_rtc_id; - uint64_t tick = 0; - - aon_rtc_id = os_strtoul(argv[1], NULL, 10); - tick = bk_aon_rtc_get_current_tick(aon_rtc_id); - - //CLI_LOGI("id=%d, tick_h=%d tick_l=%d\r\n", aon_rtc_id, (uint32_t)(tick>>32), (uint32_t)tick); - CLI_LOGI("id=%d, tick_h=%d tick_l=%d ms\r\n", aon_rtc_id, (uint32_t)((tick/32)>>32), (uint32_t)(tick/32)); -} - -static void cli_aon_rtc_register_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - uint32_t aon_rtc_id; - alarm_info_t alarm_info; - - if (argc != 5) { - cli_aon_rtc_help(); - return; - } - - aon_rtc_id = os_strtoul(argv[1], NULL, 10); - strncpy((char *)alarm_info.name, argv[2], ALARM_NAME_MAX_LEN); - alarm_info.period_tick = os_strtoul(argv[3], NULL, 10); - alarm_info.period_cnt = os_strtoul(argv[4], NULL, 10); - alarm_info.param_p = (void *)alarm_param; - alarm_info.callback = alarm_callback; - bk_alarm_register(aon_rtc_id, &alarm_info); -} - -static void cli_aon_rtc_unregister_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - uint32_t aon_rtc_id; - uint8_t name[ALARM_NAME_MAX_LEN+1]; - - if (argc != 3) { - cli_aon_rtc_help(); - return; - } - - aon_rtc_id = os_strtoul(argv[1], NULL, 10); - strncpy((char *)name, argv[2], ALARM_NAME_MAX_LEN); - - bk_alarm_unregister(aon_rtc_id, name); -} - -static alarm_info_t s_cli_alarm_info[] = -{ - {"alarm_1", (1000 * AON_RTC_MS_TICK_CNT), 0xFFFFFFFF, alarm_auto_test_callback, NULL}, - {"alarm_2", (6000 * AON_RTC_MS_TICK_CNT), 0xFFFFFFFF, alarm_auto_test_callback, NULL}, - {"alarm_3", (12000 * AON_RTC_MS_TICK_CNT), 0xFFFFFFFF, alarm_auto_test_callback, NULL}, - {"alarm_4", (48000 * AON_RTC_MS_TICK_CNT), 0xFFFFFFFF, alarm_auto_test_callback, NULL}, - {"alarm_5", (3000 * AON_RTC_MS_TICK_CNT), 0xFFFFFFFF, alarm_auto_test_callback, NULL}, - {"alarm_6", (4000 * AON_RTC_MS_TICK_CNT), 0xFFFFFFFF, alarm_auto_test_callback, NULL}, -}; - -static void alarm_auto_test_callback(aon_rtc_id_t id, uint8_t *name_p, void *param) -{ - uint32_t i = 0; - uint32_t arr_size = sizeof(s_cli_alarm_info)/sizeof(alarm_info_t); - - CLI_LOGI("id=%d, name=%s\r\n", id, name_p); - for(i = 0; i < arr_size; i++) - { - if(os_strcmp((const char*)s_cli_alarm_info[i].name, (const char*)name_p) == 0) - { - //forbid unregister self in the callback - //CLI_LOGI("Unregister name=%s\r\n", name_p); - //bk_alarm_unregister(id, s_cli_alarm_info[i].name); - - CLI_LOGI("register name=%s\r\n", s_cli_alarm_info[(i+3)%arr_size].name); - bk_alarm_register(id, &s_cli_alarm_info[(i+3)%arr_size]); - - break; - } - } -} - -static void aon_rtc_autotest_start(aon_rtc_id_t id) -{ - uint32_t i = 0; - - for(i = 0; i < sizeof(s_cli_alarm_info)/sizeof(alarm_info_t); i++) - { - bk_alarm_register(id, &s_cli_alarm_info[i]); - } -} - -static void aon_rtc_autotest_stop(aon_rtc_id_t id) -{ - uint32_t i = 0; - for(i = 0; i < sizeof(s_cli_alarm_info)/sizeof(alarm_info_t); i++) - { - bk_alarm_unregister(id, s_cli_alarm_info[i].name); - } -} - -static void cli_aon_rtc_auto_test_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - uint32_t aon_rtc_id; - - if (argc != 3) { - cli_aon_rtc_help(); - return; - } - - aon_rtc_id = os_strtoul(argv[1], NULL, 10); - if (os_strcmp(argv[2], "start") == 0) - { - aon_rtc_autotest_start(aon_rtc_id); - } - else if (os_strcmp(argv[2], "stop") == 0) - { - aon_rtc_autotest_stop(aon_rtc_id); - } - else - cli_aon_rtc_help(); -} - -#if AON_RTC_DEBUG -static void cli_aon_rtc_timing_test_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - uint32_t aon_rtc_id; - uint32_t round, cnts, set_tick_val = 0xfffffff0; - - if (argc != 5) { - cli_aon_rtc_help(); - return; - } - - aon_rtc_id = os_strtoul(argv[1], NULL, 10); - round = os_strtoul(argv[2], NULL, 10); - cnts = os_strtoul(argv[3], NULL, 10); - set_tick_val = os_strtoul(argv[4], NULL, 10); - - bk_aon_rtc_timing_test(aon_rtc_id, round, cnts, set_tick_val); -} -#endif - -static void cli_aon_rtc_dump_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - uint32_t aon_rtc_id; - - if (argc != 2) { - cli_aon_rtc_help(); - return; - } - - aon_rtc_id = os_strtoul(argv[1], NULL, 10); - - bk_aon_rtc_dump(aon_rtc_id); -} - - -#define AON_RTC_CMD_CNT (sizeof(s_aon_rtc_commands) / sizeof(struct cli_command)) -static const struct cli_command s_aon_rtc_commands[] = { - {"aon_rtc_driver", "aon_rtc_driver {init|deinit}", cli_aon_rtc_driver_cmd}, -#if 0 //remove it, only one HW can't be used for many APPs. - {"aon_rtc", "aon_rtc {id} {create|destroy}", cli_aon_rtc_cmd}, - {"aon_rtc_int", "aon_rtc_int {id} {tick|upper}", cli_aon_rtc_int_cmd}, -#endif - {"aon_rtc_get_time", "aon_rtc_get_time {id}", cli_aon_rtc_get_time}, - {"aon_rtc_register", "aon_rtc_register {id} {name} {period_tick} {period_cnt}, {callback}", cli_aon_rtc_register_cmd}, - {"aon_rtc_unregister", "aon_rtc_unregister {id} {name}", cli_aon_rtc_unregister_cmd}, - {"aon_rtc_auto_test", "{id} {start|stop}", cli_aon_rtc_auto_test_cmd}, -#if AON_RTC_DEBUG - {"aon_rtc_timing_test", "{id} {rounds} {cycles} {set tick val}", cli_aon_rtc_timing_test_cmd}, -#endif - {"aon_rtc_dump", "{id}", cli_aon_rtc_dump_cmd}, -}; - -int cli_aon_rtc_init(void) -{ - BK_LOG_ON_ERR(bk_aon_rtc_driver_init()); - return cli_register_commands(s_aon_rtc_commands, AON_RTC_CMD_CNT); -} - diff --git a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_at.c b/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_at.c deleted file mode 100755 index 43c72b66c397970eed32a395a834ba9428b1bf57..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_at.c +++ /dev/null @@ -1,350 +0,0 @@ -#include "cli.h" -#include "bk_cli.h" -#include -#include "cli_config.h" -#include - -#if (CONFIG_AT_CMD) -#if CONFIG_BLE//(CONFIG_BLE_5_X) -#include "ble_api_5_x.h" -#include -#endif -#if CONFIG_BT -#include -#include "bt_include.h" -#endif -#include "at_common.h" -#include "bk_private/bk_wifi_wpa_cmd.h" -#include -#include -#include "bk_wifi_wrapper.h" -#if CONFIG_LWIP -#if CONFIG_HARMONY_LWIP -#include "ping.h" -#else -#include "lwip/ping.h" -#endif -#endif - - -static void at_base_command(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - char *msg = NULL; - - if(argc != 1){ - msg = AT_CMD_RSP_ERROR; - } - else - { - msg = AT_CMD_RSP_SUCCEED; - } - - os_memcpy(pcWriteBuffer, msg, os_strlen(msg)); -} - -static void at_reset_command(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - char *msg = NULL; - - if(argc != 1){ - msg = AT_CMD_RSP_ERROR; - } - else - { - bk_reboot(); - msg = AT_CMD_RSP_SUCCEED; - } - - os_memcpy(pcWriteBuffer, msg, os_strlen(msg)); -} - -//#if (CONFIG_BLE_5_X || CONFIG_BTDM_5_2) -#if CONFIG_BLE -static void bleat_command_handler(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - char *msg = NULL; - const at_command_t *command = NULL; - uint8_t type = bk_ble_get_controller_stack_type(); - - if(type != BK_BLE_CONTROLLER_STACK_TYPE_BLE_5_X && - type != BK_BLE_CONTROLLER_STACK_TYPE_BTDM_5_2) - { - os_printf("%s stack type %d not support\n", __func__, type); - return; - } - - command = lookup_ble_at_command(argv[1]); - if (command == NULL) { - bk_printf("cannot find this cmd, please check again!!!\n"); - msg = AT_CMD_RSP_ERROR; - os_memcpy(pcWriteBuffer, msg, os_strlen(msg)); - return; - } - - command->function(pcWriteBuffer, xWriteBufferLen, argc - 2, argv + 2); -} -#endif /// CONFIG_BLE_5_X || CONFIG_BTDM_5_2 - -#if CONFIG_BT -static void bt_at_command_handler(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - char *msg = NULL; - const at_command_t *command = NULL; - uint8_t type = bk_bt_get_controller_stack_type(); - if(type != BK_BT_CONTROLLER_STACK_TYPE_BTDM_5_2) - { - os_printf("%s stack type %d not support\n", __func__, type); - return; - } - - command = lookup_bt_at_command(argv[1]); - if (command == NULL) { - bk_printf("cannot find this cmd, please check again!!!\n"); - msg = AT_CMD_RSP_ERROR; - os_memcpy(pcWriteBuffer, msg, os_strlen(msg)); - return; - } - - command->function(pcWriteBuffer, xWriteBufferLen, argc - 2, argv + 2); -} -#endif - -#if CONFIG_LWIP -static void wifi_Command_handler(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - char *msg = NULL; - const at_command_t *command = NULL; - - command = lookup_wifi_at_command(argv[1]); - if (command == NULL) { - bk_printf("cannot find this cmd, please check again!!!\n"); - msg = AT_CMD_RSP_ERROR; - os_memcpy(pcWriteBuffer, msg, os_strlen(msg)); - return; - } - - command->function(pcWriteBuffer, xWriteBufferLen, argc - 2, argv + 2); -} - -void at_wifi_Command_sta(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - char buf[128]; - int i, left = sizeof(buf) - 1, len = 0; - int ret; - char *msg = NULL; - - if (argc <= 1) { - os_printf("no cmd, please check again!!!"); - msg = AT_CMD_RSP_ERROR; - os_memcpy(pcWriteBuffer, msg, os_strlen(msg)); - return; - } - buf[0] = 0; - for (i = 1; i < argc; i++) { - len = os_strlen(buf); - snprintf(buf + len, left - len, "%s ", argv[i]); - } - buf[strlen(buf)-1] = 0; - //os_printf("CMD: |%s|\n", buf); - -#if 1 - if (buf != 0) { - ret = cmd_wlan_sta_exec(buf); - } - else { - os_printf("buf null, please check again!!!"); - msg = AT_CMD_RSP_ERROR; - os_memcpy(pcWriteBuffer, msg, os_strlen(msg)); - return; - } - if(ret == 0) - msg = AT_CMD_RSP_SUCCEED; - else - msg = AT_CMD_RSP_ERROR; - os_memcpy(pcWriteBuffer, msg, os_strlen(msg)); -#endif -} - -void at_wifi_Command_ap(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - char buf[128]; - int i, left = sizeof(buf) - 1, len = 0; - int ret; - char *msg = NULL; - - if (argc <= 1) { - os_printf("no cmd, please check again!!!"); - msg = AT_CMD_RSP_ERROR; - os_memcpy(pcWriteBuffer, msg, os_strlen(msg)); - return; - } - buf[0] = 0; - for (i = 1; i < argc; i++) { - len = os_strlen(buf); - snprintf(buf + len, left - len, "%s ", argv[i]); - } - buf[strlen(buf)-1] = 0; - //os_printf("CMD: |%s|\n", buf); - -#if 1 - if (buf != 0) { - ret = cmd_wlan_ap_exec(buf); - } - else { - os_printf("buf null, please check again!!!"); - msg = AT_CMD_RSP_ERROR; - os_memcpy(pcWriteBuffer, msg, os_strlen(msg)); - return; - } - if(ret == 0) - msg = AT_CMD_RSP_SUCCEED; - else - msg = AT_CMD_RSP_ERROR; - os_memcpy(pcWriteBuffer, msg, os_strlen(msg)); -#endif -} -void at_wifi_state(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - char *msg = NULL; - - if(argc != 1) { - msg = AT_CMD_RSP_ERROR; - } - else { - if(demo_state_app_init()) - msg = AT_CMD_RSP_ERROR; - else - msg = AT_CMD_RSP_SUCCEED; - } - os_memcpy(pcWriteBuffer, msg, os_strlen(msg)); -} -void at_wifi_ping(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ -#if 0 - char *msg = NULL; - int ret; - uint32_t cnt = 4; - - if (argc == 1) { - os_printf("Please input: ping \n"); - msg = AT_CMD_RSP_ERROR; - os_memcpy(pcWriteBuffer, msg, os_strlen(msg)); - return; - } - - if (argc > 2) - cnt = os_strtoul(argv[2], NULL, 10); - - os_printf("ping IP address:%s\n", argv[1]); - ret = ping(argv[1], cnt, 0); - if(ret == 0) - msg = AT_CMD_RSP_SUCCEED; - else - msg = AT_CMD_RSP_ERROR; - os_memcpy(pcWriteBuffer, msg, os_strlen(msg)); -#endif -} - -#endif - -void videoat_command_handler(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - char *msg = NULL; - const at_command_t *command = lookup_video_at_command(argv[1]); - if (command == NULL) { - bk_printf("cannot find this cmd, please check again!!!\n"); - msg = AT_CMD_RSP_ERROR; - os_memcpy(pcWriteBuffer, msg, os_strlen(msg)); - return; - } - - command->function(pcWriteBuffer, xWriteBufferLen, argc - 2, argv + 2); -} - -#if (CONFIG_WIFI_ENABLE) -void at_mac_command(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - char *msg = NULL; - int ret1,ret2,ret3,ret4; - uint8_t base_mac[BK_MAC_ADDR_LEN] = {0}; - uint8_t sta_mac[BK_MAC_ADDR_LEN] = {0}; - uint8_t ap_mac[BK_MAC_ADDR_LEN] = {0}; - - if (argc == 1) { - ret1 = bk_get_mac(base_mac, MAC_TYPE_BASE); - ret2 = bk_wifi_sta_get_mac(sta_mac); - ret3 = bk_wifi_ap_get_mac(ap_mac); - if ((ret1 != BK_OK) && (ret2 != BK_OK) && (ret3 != BK_OK)) - msg = AT_CMD_RSP_ERROR; - else - msg = AT_CMD_RSP_SUCCEED; - os_printf("base mac: "BK_MAC_FORMAT"\n", BK_MAC_STR(base_mac)); - os_printf("sta mac: "BK_MAC_FORMAT"\n", BK_MAC_STR(sta_mac)); - os_printf("ap mac: "BK_MAC_FORMAT"\n", BK_MAC_STR(ap_mac)); - - } else if (argc == 2) { - hexstr2bin(argv[1], base_mac, BK_MAC_ADDR_LEN); - ret4 = bk_set_base_mac(base_mac); - os_printf("set base mac: "BK_MAC_FORMAT"\n", BK_MAC_STR(base_mac)); - if (ret4 != BK_OK) - msg = AT_CMD_RSP_ERROR; - else - msg = AT_CMD_RSP_SUCCEED; - - } else { - os_printf("invalid cmd\r\n"); - msg = AT_CMD_RSP_ERROR; - } - os_memcpy(pcWriteBuffer, msg, os_strlen(msg)); -} -#endif /// CONFIG_WIFI_ENABLE -#endif /// CONFIG_AT_CMD - -#define AT_CMD_CNT (sizeof(s_at_commands) / sizeof(struct cli_command)) - -static const struct cli_command s_at_commands[] = { -#if (CONFIG_AT_CMD) - {"AT", "AT", at_base_command}, - {"AT+RST", "AT+RST", at_reset_command}, -#if CONFIG_BLE//(CONFIG_BLE_5_X || CONFIG_BTDM_5_2) - {"AT+BLE", "AT+TYPE_CMD=CMD_name,param1,...,paramn", bleat_command_handler}, -#endif -#if CONFIG_BT - {"AT+BT", "AT+TYPE_CMD=CMD_name,param1,...,paramn", bt_at_command_handler}, -#endif -#if CONFIG_LWIP - {"AT+WIFISTA", "at sta config", at_wifi_Command_sta}, - {"AT+WIFIAP", "at ap config", at_wifi_Command_ap}, - {"AT+WIFISTATE", "state", at_wifi_state}, - {"AT+WIFIPING", "state", at_wifi_ping}, - {"AT+WIFI", "AT+TYPE_CMD=CMD_name,param1,...,paramn", wifi_Command_handler}, -#endif - {"AT+VIDEO", "video cmd(open/read/close)", videoat_command_handler}, -#if (CONFIG_WIFI_ENABLE) - {"AT+MAC", "mac , get/set mac. e.g. mac c89346000001", at_mac_command}, -#endif - - /* - {"AT+HELP","AT+HELP", at_help_command}, - {"AT+VERSION", "AT+VERSION", at_version_command}, - {"AT+ECHO","AT+ECHO=0\\1\\2", at_echo_command}, - - {"AT+WLMAC","AT+WLMAC", at_get_station_mac_command}, - {"AT+STADHCP", "AT+STADHCP", at_set_station_dhcp_command}, - {"AT+STAAPINFO","AT+STAAPINFO", at_set_station_ssid_pwd_command}, - {"AT+STASTOP","AT+STASTOP",at_station_stop}, - {"AT+STASTATIC","AT+STASTATIC=ip,mask,gate[,dns]",at_set_station_static_ip_command}, - {"AT+STAST","AT+STAST",at_get_station_status_command}, - {"AT+WSCAN","AT+WSCAN",at_wlan_scan_command}, - - {"AT+SOFTAP","AT+SOFTAP=SSID,PWD",at_softap_start_command}, - {"AT+SOFTAPSTOP","AT+STASTOP",at_softap_stop_command}, - {"AT+APSTATIC","AT+APSTATIC=ip,mask,gate[,dns]",at_softap_static_ip_command}, - {"AT+APSTATE","AT+APSTATE",at_get_softap_status_command},*/ -#endif -}; - -int cli_at_init(void) -{ - return cli_register_commands(s_at_commands, AT_CMD_CNT); -} diff --git a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_aud.c b/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_aud.c deleted file mode 100755 index 83ca371be5a54a6abdf4fa8d8329c9f5065cb898..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_aud.c +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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 "cli.h" - - -extern void cli_aud_adc_mcp_test_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv); -extern void cli_aud_dtmf_mcp_test_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv); -extern void cli_aud_adc_dma_test_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv); -extern void cli_aud_adc_loop_test_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv); -extern void cli_aud_dtmf_loop_test_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv); -extern void cli_aud_pcm_mcp_test_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv); -extern void cli_aud_pcm_dma_test_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv); -extern void cli_aud_enable_adc_test_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv); -extern void cli_aud_eq_test_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv); -extern void cli_aud_mic_to_pcm_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv); - -#define AUD_CMD_CNT (sizeof(s_aud_commands) / sizeof(struct cli_command)) -static const struct cli_command s_aud_commands[] = { - {"aud_adc_mcp_test", "aud_adc_mcp_test {start|stop}", cli_aud_adc_mcp_test_cmd}, - {"aud_dtmf_mcp_test", "aud_dtmf_mcp_test {start|stop}", cli_aud_dtmf_mcp_test_cmd}, - {"aud_adc_dma_test", "aud_adc_dma_test {start|stop}", cli_aud_adc_dma_test_cmd}, - {"aud_adc_loop_test", "aud_adc_loop_test {start|stop}", cli_aud_adc_loop_test_cmd}, - {"aud_dtmf_loop_test", "aud_dtmf_loop_test {start|stop}", cli_aud_dtmf_loop_test_cmd}, - {"aud_pcm_mcp_test", "aud_pcm_mcp_test {8000|16000|44100|48000}", cli_aud_pcm_mcp_test_cmd}, - {"aud_pcm_dma_test", "aud_pcm_dma_test {8000|16000|44100|48000|stop}", cli_aud_pcm_dma_test_cmd}, -// {"aud_file_to_dac_test", "aud_file_to_dac_test {start|stop} {filename}", cli_aud_file_to_dac_test_cmd}, - {"aud_enable_adc_test", "aud_enable_adc_test {start|stop}", cli_aud_enable_adc_test_cmd}, - {"aud_eq_test", "aud_eq_test {start|stop}", cli_aud_eq_test_cmd}, - {"aud_mic_to_pcm_test", "aud_mic_to_pcm_test {start|stop}", cli_aud_mic_to_pcm_cmd}, -}; - -int cli_aud_init(void) -{ - return cli_register_commands(s_aud_commands, AUD_CMD_CNT); -} - diff --git a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_aud_cp0.c b/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_aud_cp0.c deleted file mode 100755 index bcf8d45cd3118004f51128c11e52dd3f7c8c7afe..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_aud_cp0.c +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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 "cli.h" - -extern void cli_aud_cp0_adc_to_sd_test_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv); -extern void cli_aud_cp0_psram_init_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv); -extern void cli_aud_cp0_mic_to_pcm_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv); -extern void cli_aud_cp0_sdcard_to_dac_test_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv); - -extern void cli_aud_cp0_signal_to_dual_test_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv); -extern void cli_cp0_audio_record_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv); -extern void cli_cp0_audio_play_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv); - -#define AUD_CP0_CMD_CNT (sizeof(s_aud_cp0_commands) / sizeof(struct cli_command)) -static const struct cli_command s_aud_cp0_commands[] = { - {"aud_cp0_adc_to_sd_test", "aud_cp0_adc_to_sd_test {start|stop}", cli_aud_cp0_adc_to_sd_test_cmd}, - {"aud_cp0_psram_init", "aud_cp0_psram_init {start|stop}", cli_aud_cp0_psram_init_cmd}, - {"aud_cp0_mic_to_pcm", "aud_cp0_mic_to_pcm {start|stop}", cli_aud_cp0_mic_to_pcm_cmd}, - {"aud_cp0_sdcard_play_test", "aud_cp0_sdcard_play_test{start}", cli_aud_cp0_sdcard_to_dac_test_cmd}, - {"aud_cp0_signal_to_dual_test", "aud_cp0_signal_to_dual_test", cli_aud_cp0_signal_to_dual_test_cmd}, - {"aud_cp0_audio_record_test", "aud_cp0_audio_record_test {start|stop xx.pcm}", cli_cp0_audio_record_cmd}, - {"aud_cp0_audio_play_test", "aud_cp0_audio_play_test {start|stop xx.pcm}", cli_cp0_audio_play_cmd}, -}; - -int cli_aud_cp0_init(void) -{ - return cli_register_commands(s_aud_cp0_commands, AUD_CP0_CMD_CNT); -} - diff --git a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_aud_cp0.h b/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_aud_cp0.h deleted file mode 100755 index 5765361223194b30b9c13079fcff0df6ed8389c4..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_aud_cp0.h +++ /dev/null @@ -1,37 +0,0 @@ -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define psram_block_num 10 -#define PSRAM_AUD_ADDR_BASE 0x60000000 -#define AUD_DMA_SIZE 0xFFFF -#define MB_CHNL_AUD 2 - - -typedef enum { - IDLE = 0, - BUSING -} sd_status_t; - -typedef struct { - sd_status_t sd_status; - uint32_t block_status; //bit9-0 0:free, 1:full -} psram_block_status_t; - -typedef enum { - AUD_MB_DMA_DONE = 0, //CPU1->CPU0 - AUD_MB_STOP_TEST, //CPU1->CPU0 && CPU0->cpu1 - AUD_MB_WRITE_SD_DONE, //CPU0->CPU1 - AUD_MB_START_TEST, -} aud_mb_cmd_t; - -typedef struct { - uint32_t chnl_id; -} aud_mb_t; - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_aud_intf.c b/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_aud_intf.c deleted file mode 100755 index c27f66a34263fa57d38794ff59397920fc0d22b6..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_aud_intf.c +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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 "cli.h" - - -extern void cli_aud_intf_record_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv); -extern void cli_aud_intf_play_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv); -extern void cli_aud_intf_sd_voc_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv); -extern void cli_aud_intf_set_voc_param_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv); -extern void cli_aud_intf_set_aec_param_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv); -extern void cli_aud_intf_get_aec_param_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv); -extern void cli_aud_intf_set_samp_rate_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv); - -#define AUD_INTF_CMD_CNT (sizeof(s_aud_intf_commands) / sizeof(struct cli_command)) -static const struct cli_command s_aud_intf_commands[] = { - {"aud_intf_record_test", "aud_intf_record_test {init|start|pause|stop|set_chl|deinit xxx.pcm|mic1|dual}", cli_aud_intf_record_cmd}, - {"aud_intf_play_test", "{init|start|pause|stop|set_chl|deinit xxx.pcm|left|dual}", cli_aud_intf_play_cmd}, - {"aud_intf_sd_voc_test", "aud_intf_sd_voc_test {start|stop xx.pcm, xx.pcm}", cli_aud_intf_sd_voc_cmd}, - {"aud_intf_set_voc_param_test", "aud_intf_set_voc_param_test {param value}", cli_aud_intf_set_voc_param_cmd}, - {"aud_intf_set_aec_param_test", "aud_intf_set_aec_param_test {param value}", cli_aud_intf_set_aec_param_cmd}, - {"aud_intf_get_aec_param_test", "aud_intf_get_aec_param_test", cli_aud_intf_get_aec_param_cmd}, - {"aud_intf_set_samp_rate_test", "aud_intf_set_samp_rate_test {param value}", cli_aud_intf_set_samp_rate_cmd}, -}; - -int cli_aud_intf_init(void) -{ - return cli_register_commands(s_aud_intf_commands, AUD_INTF_CMD_CNT); -} - diff --git a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_ble.c b/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_ble.c deleted file mode 100644 index 010db334dcef23ad57d8a1caccadd0ca7874f5e5..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_ble.c +++ /dev/null @@ -1,17 +0,0 @@ -#include "bk_cli.h" -#include - -extern void ble_command(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv);//TODO - -#define BLE_CMD_CNT (sizeof(s_ble_commands) / sizeof(struct cli_command)) - -static const struct cli_command s_ble_commands[] = { -#if (CONFIG_BLE == 1) - {"ble", "ble arg1 arg2", ble_command}, -#endif -}; - -int cli_ble_init(void) -{ - return cli_register_commands(s_ble_commands, BLE_CMD_CNT); -} diff --git a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_calendar.c b/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_calendar.c deleted file mode 100644 index 33f8b7f18f6dfe639a34896a37d19d15b190d97f..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_calendar.c +++ /dev/null @@ -1,72 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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 -#include -#include "cli.h" - -static void cli_calendar_help(void) -{ - CLI_LOGI("calendar_driver init\r\n"); - CLI_LOGI("calendar_driver deinit\r\n"); - CLI_LOGI("calendar get_time_us\r\n"); -} - -static void cli_calendar_driver_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - if (argc < 2) { - cli_calendar_help(); - return; - } - - if (os_strcmp(argv[1], "init") == 0) { - BK_LOG_ON_ERR(bk_calendar_driver_init()); - CLI_LOGI("calendar driver init\n"); - } else if (os_strcmp(argv[1], "deinit") == 0) { - BK_LOG_ON_ERR(bk_calendar_driver_deinit()); - CLI_LOGI("calendar driver deinit\n"); - } else { - cli_calendar_help(); - return; - } -} - -static void cli_calendar_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - if (argc < 2) { - cli_calendar_help(); - return; - } - - if (os_strcmp(argv[1], "get_time_us") == 0) { - uint64_t time_us = bk_calendar_get_time_us(); - CLI_LOGI("calendar get time_us:%d\r\n", time_us); - } else { - cli_calendar_help(); - return; - } -} - -#define CALENDAR_CMD_CNT (sizeof(s_calendar_commands) / sizeof(struct cli_command)) -static const struct cli_command s_calendar_commands[] = { - {"calendar_driver", "calendar_driver {init|deinit}", cli_calendar_driver_cmd}, - {"calendar", "calendar get_time_us", cli_calendar_cmd} -}; - -int cli_calendar_init(void) -{ - BK_LOG_ON_ERR(bk_calendar_driver_init()); - return cli_register_commands(s_calendar_commands, CALENDAR_CMD_CNT); -} - diff --git a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_config.h b/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_config.h deleted file mode 100644 index b83c92d3fa41aa559f2385d70e0c94e321ab362d..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_config.h +++ /dev/null @@ -1,275 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -#if (CONFIG_WIFI_ENABLE) -#define CLI_CFG_WIFI 1 -#else -#define CLI_CFG_WIFI 0 -#endif //#if (CONFIG_WIFI_ENABLE) -#define CLI_CFG_BLE 1 - -#if (CONFIG_BK_NETIF) -#define CLI_CFG_NETIF 1 -#else -#define CLI_CFG_NETIF 0 -#endif //#if (CONFIG_LWIP) - -#define CLI_CFG_MISC 1 -#define CLI_CFG_MEM 1 - -#if (CONFIG_WIFI_ENABLE) -#define CLI_CFG_PHY 1 -#else -#define CLI_CFG_PHY 0 -#endif //#if (CONFIG_WIFI_ENABLE) - -#if (CONFIG_STA_PS) -#define CLI_CFG_PWR 1 -#else -#define CLI_CFG_PWR 0 -#endif -#define CLI_CFG_TIMER 1 -#if CONFIG_INT_WDT -#define CLI_CFG_WDT 1 -#endif -#if CONFIG_TRNG_SUPPORT -#define CLI_CFG_TRNG 1 -#else -#define CLI_CFG_TRNG 0 -#endif -#if CONFIG_EFUSE -#define CLI_CFG_EFUSE 1 -#else -#define CLI_CFG_EFUSE 0 -#endif -#define CLI_CFG_GPIO 1 -#define CLI_CFG_OS 1 -#if ((CONFIG_OTA_TFTP) || (CONFIG_OTA_HTTP)) -#define CLI_CFG_OTA 1 -#else -#define CLI_CFG_OTA 0 -#endif -#if(CONFIG_KEYVALUE) -#define CLI_CFG_KEYVALUE 1 -#else -#define CLI_CFG_KEYVALUE 0 -#endif -#if(CONFIG_SUPPORT_MATTER) -#define CLI_CFG_MATTER 1 -#else -#define CLI_CFG_MATTER 0 -#endif -#define CLI_CFG_UART 1 -#define CLI_CFG_ADC 1 -#define CLI_CFG_SPI 1 -#define CLI_CFG_MICO 1 -#define CLI_CFG_REG 1 -#define CLI_CFG_EXCEPTION 1 - -#if(CONFIG_GENERAL_DMA) -#define CLI_CFG_DMA 1 -#else -#define CLI_CFG_DMA 0 -#endif - -#if(CONFIG_PWM) -#define CLI_CFG_PWM 1 -#else -#define CLI_CFG_PWM 0 -#endif - -#if(CONFIG_FLASH) -#define CLI_CFG_FLASH 1 -#else -#define CLI_CFG_FLASH 0 -#endif - -#if(CONFIG_SDIO_HOST) -#define CLI_CFG_SDIO_HOST 1 -#else -#define CLI_CFG_SDIO_HOST 0 -#endif - -#if(CONFIG_ICU) -#define CLI_CFG_ICU 1 -#else -#define CLI_CFG_ICU 0 -#endif - -#if CONFIG_I2C -#define CLI_CFG_I2C 1 -#else -#define CLI_CFG_I2C 0 -#endif - -#if CONFIG_QSPI -#define CLI_CFG_QSPI 1 -#else -#define CLI_CFG_QSPI 0 -#endif - -#if CONFIG_AON_RTC_TEST -#define CLI_CFG_AON_RTC 1 -#else -#define CLI_CFG_AON_RTC 0 -#endif - -#if CONFIG_JPEG_ENCODE -#define CLI_CFG_JPEGENC 1 -#else -#define CLI_CFG_JPEGENC 0 -#endif - -#if CONFIG_JPEG_DECODE -#define CLI_CFG_JPEGDEC 1 -#else -#define CLI_CFG_JPEGDEC 0 -#endif - -#if CONFIG_CALENDAR -#define CLI_CFG_CALENDAR 1 -#else -#define CLI_CFG_CALENDAR 0 -#endif - -//TODO default to 0 -#define CLI_CFG_EVENT 1 - -#if (CONFIG_SOC_BK7251) -#define CLI_CFG_SECURITY 1 -#else -#define CLI_CFG_SECURITY 1 -#endif - -#if CONFIG_TEMP_DETECT -#define CLI_CFG_TEMP_DETECT 1 -#else -#define CLI_CFG_TEMP_DETECT 0 -#endif - -#if CONFIG_SDCARD_HOST -#define CLI_CFG_SD 1 -#else -#define CLI_CFG_SD 0 -#endif - -#if CONFIG_FATFS -#define CLI_FATFS 1 -#else -#define CLI_FATFS 0 -#endif - -#if CONFIG_AIRKISS_TEST -#define CLI_CFG_AIRKISS 1 -#else -#define CLI_CFG_AIRKISS 0 -#endif - -#if CONFIG_IPERF_TEST -#define CLI_CFG_IPERF 1 -#else -#define CLI_CFG_IPERF 0 -#endif - -#if (CONFIG_I2S) -#define CLI_CFG_I2S 1 -#else -#define CLI_CFG_I2S 0 -#endif - -#if (CONFIG_SOC_BK7256XX) - -#if CONFIG_DMA2D_TEST -#define CLI_CFG_DMA2D 1 -#else -#define CLI_CFG_DMA2D 0 -#endif - -#if (CONFIG_AUDIO && CONFIG_DUAL_CORE && CONFIG_AUDIO_TEST && CONFIG_AUDIO_RISCV_IP_V1_0) -#define CLI_CFG_AUD 1 -#endif - -#if CONFIG_AUD_INTF_TEST -#define CLI_CFG_AUD_INTF 1 -#endif - -#if (CONFIG_SBC) -#define CLI_CFG_SBC 1 -#endif - -#if CONFIG_LCD_TEST -#define CLI_CFG_LCD 1 -#else -#define CLI_CFG_LCD 0 -#endif - -#if (CONFIG_DUAL_CORE && CONFIG_AUDIO_TEST && !CONFIG_SLAVE_CORE) -#define CLI_CFG_AUD_CP0 1 -#endif - -#if (CONFIG_FFT_TEST) -#define CLI_CFG_FFT 1 -#else -#define CLI_CFG_FFT 0 -#endif -#endif - -#if (CONFIG_AUDIO_AEC_TEST) -#define CLI_CFG_AEC 1 -#endif - -#if (CONFIG_AUDIO_G711_TEST) -#define CLI_CFG_G711 1 -#endif - -#if (CONFIG_AUDIO_MP3_TEST) -#define CLI_CFG_MP3 1 -#endif - -#if (CONFIG_SECURITYIP) -#define CLI_CFG_VAULT 1 -#else -#define CLI_CFG_vault 0 -#endif - -#if ((CONFIG_SOC_BK7256XX || CONFIG_USB_UVC) && CONFIG_DUAL_CORE && CONFIG_PSRAM) -#define CLI_CFG_UVC 1 -#else -#define CLI_CFG_UVC 0 -#endif - -#if ((CONFIG_CAMERA || CONFIG_SPIDMA) && CONFIG_APP_DEMO_VIDEO_TRANSFER) -#define CLI_CFG_DVP 1 -#else -#define CLI_CFG_DVP 0 -#endif - -#if (CONFIG_PSRAM && !CONFIG_SLAVE_CORE) -#define CLI_CFG_PSRAM 1 -#else -#define CLI_CFG_PSRAM 0 - -#endif - -#ifdef __cplusplus -} -#endif diff --git a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_dma.c b/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_dma.c deleted file mode 100644 index eace1fb72d329d84ebbc6ae32e2e7ea7d8a87b02..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_dma.c +++ /dev/null @@ -1,561 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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 -#include "cli.h" -#include -#include -#include "bk_general_dma.h" - -#define SEND_BUF_LEN 1024 - -static void cli_dma_help(void) -{ - CLI_LOGI("dma_driver {init|deinit}\n"); - CLI_LOGI("dma {id} {init|deinit|start|stop}\n"); - CLI_LOGI("dma_int {id} {reg|enable|disable}\n"); - CLI_LOGI("dma_chnl alloc \n"); - CLI_LOGI("dma_chnl_free free {id} \n"); - CLI_LOGI("dma_memcopy_test {copy} {count|in_number1|in_number2|out_number1|out_number2}\r\n"); - CLI_LOGI("dma_chnl_test {start|stop} {uart1|uart2|uart3} {wait_ms}\r\n"); -} - -static void cli_dma_driver_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - if (argc < 2) { - cli_dma_help(); - return; - } - - if (os_strcmp(argv[1], "init") == 0) { - BK_LOG_ON_ERR(bk_dma_driver_init()); - CLI_LOGI("dma driver init\n"); - } else if (os_strcmp(argv[1], "deinit") == 0) { - BK_LOG_ON_ERR(bk_dma_driver_deinit()); - CLI_LOGI("dma driver deinit\n"); - } else { - cli_dma_help(); - return; - } -} - -static void cli_dma_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - uint32_t id; - - if (argc < 2) { - cli_dma_help(); - return; - } - - id = os_strtoul(argv[1], NULL, 10); - - if (os_strcmp(argv[2], "init") == 0) { - CLI_RET_ON_INVALID_ARGC(argc, 3); - dma_config_t config = { - .mode = DMA_WORK_MODE_SINGLE, - .chan_prio = 2, - .src = { - .dev = DMA_DEV_DTCM, - .width = DMA_DATA_WIDTH_32BITS, - .addr_inc_en = DMA_ADDR_INC_ENABLE, - .addr_loop_en = DMA_ADDR_LOOP_DISABLE, - .start_addr = 0, - .end_addr = 0, - }, - .dst = { - .dev = DMA_DEV_UART1, - .width = DMA_DATA_WIDTH_8BITS, - .addr_inc_en = DMA_ADDR_INC_DISABLE, - .addr_loop_en = DMA_ADDR_LOOP_DISABLE, - .start_addr = 0x0802100 + 0x3 * 4, - .end_addr = 0, - }, - }; - BK_LOG_ON_ERR(bk_dma_init(id, &config)); - CLI_LOGI("dma init, id=%d\n", id); - }else if (os_strcmp(argv[2], "start") == 0) { - BK_LOG_ON_ERR(bk_dma_start(id)); - CLI_LOGI("dma start, id=%d\n", id); - } else if (os_strcmp(argv[2], "stop") == 0) { - BK_LOG_ON_ERR(bk_dma_stop(id)); - CLI_LOGI("dma stop, id=%d\n", id); - } else if (os_strcmp(argv[2], "deinit") == 0) { - BK_LOG_ON_ERR(bk_dma_deinit(id)); - CLI_LOGI("dma deinit, id=%d\n", id); - } else if (os_strcmp(argv[2], "set_tran_len") == 0) { - BK_LOG_ON_ERR(bk_dma_set_transfer_len(id, SEND_BUF_LEN)); - CLI_LOGI("dma set tran len, id=%d, len=%d\n", id, SEND_BUF_LEN); - } else if (os_strcmp(argv[2], "get_remain_len") == 0) { - uint32_t remain_len = bk_dma_get_remain_len(id); - CLI_LOGI("dma get remain_len, id=%d, len=%x\n", id, remain_len); - }else { - cli_dma_help(); - return; - } -} - -static void cli_dma_half_finish_isr(dma_id_t dma_id) -{ - CLI_LOGI("dma half finish isr(%d)\n", dma_id); -} - -static void cli_dma_finish_isr(dma_id_t dma_id) -{ - CLI_LOGI("dma finish isr(%d)\n", dma_id); -} - -static void cli_dma_int_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - uint32_t id; - - if (argc != 3) { - cli_dma_help(); - return; - } - - id = os_strtoul(argv[1], NULL, 10); - - if (os_strcmp(argv[2], "reg") == 0) { - BK_LOG_ON_ERR(bk_dma_register_isr(id, cli_dma_half_finish_isr, cli_dma_finish_isr)); - CLI_LOGI("dma id:%d register interrupt isr\n", id); - } else if (os_strcmp(argv[2], "enable_hf_fini") == 0) { - BK_LOG_ON_ERR(bk_dma_enable_half_finish_interrupt(id)); - CLI_LOGI("dma id%d enable half finish interrupt\n", id); - } else if (os_strcmp(argv[2], "disable_hf_fini") == 0) { - BK_LOG_ON_ERR(bk_dma_disable_half_finish_interrupt(id)); - CLI_LOGI("dma id%d disable half finish interrupt\n", id); - } else if (os_strcmp(argv[2], "enable_fini") == 0) { - BK_LOG_ON_ERR(bk_dma_enable_finish_interrupt(id)); - CLI_LOGI("dma id%d enable finish interrupt\n", id); - } else if (os_strcmp(argv[2], "disable_fini") == 0) { - BK_LOG_ON_ERR(bk_dma_disable_finish_interrupt(id)); - CLI_LOGI("dma id%d disable finish interrupt\n", id); - } else { - cli_dma_help(); - return; - } -} - -static void cli_dma_chnl_alloc(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - uint8_t id; - - if (argc < 2) { - cli_dma_help(); - return; - } - - if (os_strcmp(argv[1], "alloc") == 0) { - id = bk_dma_alloc(DMA_DEV_MAX); - CLI_LOGI("dma channel id:%x\n", id); - } else { - cli_dma_help(); - return; - } -} - -static void cli_dma_chnl_free(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - uint32_t id; - uint32_t ret; - - if (argc < 2) { - cli_dma_help(); - return; - } - - if (os_strcmp(argv[1], "free") == 0) { - id = os_strtoul(argv[2], NULL, 10); - ret = bk_dma_free(DMA_DEV_MAX, id); - CLI_LOGI("dma channel free id:%d ret:%d\n", id, ret); - } else { - CLI_LOGI("cli_dma_chnl_free NOT free\n"); - cli_dma_help(); - return; - } -} - -static void cli_dma_memcpy_test(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - - if (argc < 7) { - cli_dma_help(); - return; - } - uint32_t *out_buffer = NULL; - uint32_t *in_buffer = NULL; - uint32_t in_write_buffer[2] = {0}; - uint32_t out_write_buffer[2] = {0}; - - int count = 1; - if (os_strcmp(argv[1], "copy") == 0) { - count = os_strtoul(argv[2], NULL, 10); - - in_write_buffer[0] = os_strtoul(argv[3], NULL, 10); - CLI_LOGD("cli_dma_memcpy_TEST IN_buffer[0]: %d\r\n", in_write_buffer[0]); - in_write_buffer[1] = os_strtoul(argv[4], NULL, 10); - CLI_LOGD("cli_dma_memcpy_TEST IN_buffer[1]: %d\r\n", in_write_buffer[1]); - in_buffer = in_write_buffer; - - - out_write_buffer[0] = os_strtoul(argv[5], NULL, 10); - CLI_LOGD("cli_dma_memcpy_TEST OUT_buffer[0]: %d\r\n", out_write_buffer[0]); - out_write_buffer[1] = os_strtoul(argv[6], NULL, 10); - CLI_LOGD("cli_dma_memcpy_TEST OUT_buffer[1]: %d\r\n", out_write_buffer[1]); - out_buffer = out_write_buffer; - - while(count) { - for(int j = 0; j < 2; j++) { - CLI_LOGI("cli_dma_memcpy_test BEFORE IN_buffer[%d]: %d\r\n", j,in_buffer[j]); - CLI_LOGI("cli_dma_memcpy_test BEFORE OUT_buffer[%d]: %d\r\n", j,out_buffer[j]); - } - CLI_LOGI("===============================================\r\n"); - - dma_memcpy(out_buffer, in_buffer, 2 * sizeof(uint32_t)); - - for(int i = 0; i < 2; i++) { - CLI_LOGI("cli_dma_memcpy_test AFTER IN_buffer[%d]: %d\r\n", i,in_buffer[i]); - CLI_LOGI("cli_dma_memcpy_test AFTER OUT_buffer[%d]: %d\r\n", i,out_buffer[i]); - } - CLI_LOGI("#############################################\r\n"); - - count--; - } - - } else { - cli_dma_help(); - return; - } -} - -static beken_semaphore_t dma_chnl_test_semaphore = NULL; -static beken_thread_t dma_chnl_test_handle = NULL; -static uint16_t dma_chnl_get_data_uart_id = UART_ID_MAX; -static uint16_t dma_chnl_wait_ms = 1000; - -static void dma_chnl_primenumber_copy_finish_isr(void) -{ - CLI_LOGD("dma_channel test PRIMENUMBER copy finish!\r\n"); -} - -static uint32_t dma_chnl_primenumber_copy(void) -{ - dma_config_t dma_config; - - int length = 3; - uint32_t *trng_inbuffer = NULL; - uint32_t *trng_outbuffer = NULL; - uint32_t set_inbuffer[3] = {21341, 16931, 11239}; - uint32_t set_outbuffer[3] = {9929, 14633, 22727}; - uint32_t irq_level; - - trng_inbuffer = set_inbuffer; - trng_outbuffer = set_outbuffer; - os_memset(&dma_config, 0, sizeof(dma_config_t)); - - dma_config.mode = DMA_WORK_MODE_SINGLE; - dma_config.chan_prio = 0; - - dma_config.src.dev = DMA_DEV_DTCM; - dma_config.src.width = DMA_DATA_WIDTH_32BITS; - dma_config.src.addr_inc_en = DMA_ADDR_INC_ENABLE; - dma_config.src.start_addr = (uint32_t)trng_inbuffer; - dma_config.src.end_addr = (uint32_t)(trng_inbuffer + length * sizeof(uint32_t)); - - dma_config.dst.dev = DMA_DEV_DTCM; - dma_config.dst.width = DMA_DATA_WIDTH_32BITS; - dma_config.dst.addr_inc_en = DMA_ADDR_INC_ENABLE; - dma_config.dst.start_addr = (uint32_t)trng_outbuffer; - dma_config.dst.end_addr = (uint32_t)(trng_outbuffer + length * sizeof(uint32_t)); - - dma_id_t cpy_chnl = bk_dma_alloc(DMA_DEV_DTCM); - CLI_LOGI("dma_chnl_test_PRIMENUMBER dma_chnl: %d\r\n", cpy_chnl); - - if(cpy_chnl >= DMA_ID_MAX) { - return BK_FAIL; - } - - irq_level = rtos_disable_int(); - - bk_dma_init(cpy_chnl, &dma_config); - bk_dma_register_isr(cpy_chnl, NULL, (void *)dma_chnl_primenumber_copy_finish_isr); - bk_dma_enable_finish_interrupt(cpy_chnl); - bk_dma_set_transfer_len(cpy_chnl, length * sizeof(uint32_t)); - bk_dma_start(cpy_chnl); - bk_dma_get_enable_status(cpy_chnl); - bk_dma_free(DMA_DEV_DTCM, cpy_chnl); - - rtos_enable_int(irq_level); - - for(int i = 0; i < length; i++) { - if(set_inbuffer[i] == set_outbuffer[i]) - CLI_LOGD("copy PRIMENUMBER right\r\n"); - else - CLI_LOGI("copy PRIMENUMBER ERROR!!!\r\n"); - } - - return BK_OK; - -} - -static void dma_chnl_data_from_uart_copy_finish(void) -{ - CLI_LOGD("dma_channel test UART_DATA copy finish isr\r\n"); -} - -static uint32_t dma_chnl_data_from_uart_copy(void *out, const void *in, uint32_t len) -{ - dma_config_t dma_config; - uint32_t irq_level; - - os_memset(&dma_config, 0, sizeof(dma_config_t)); - - dma_config.mode = DMA_WORK_MODE_SINGLE; - dma_config.chan_prio = 0; - - dma_config.src.dev = DMA_DEV_DTCM; - dma_config.src.width = DMA_DATA_WIDTH_32BITS; - dma_config.src.addr_inc_en = DMA_ADDR_INC_ENABLE; - dma_config.src.start_addr = (uint32_t)in; - dma_config.src.end_addr = (uint32_t)(in + len); - - dma_config.dst.dev = DMA_DEV_DTCM; - dma_config.dst.width = DMA_DATA_WIDTH_32BITS; - dma_config.dst.addr_inc_en = DMA_ADDR_INC_ENABLE; - dma_config.dst.start_addr = (uint32_t)out; - dma_config.dst.end_addr = (uint32_t)(out + len); - - dma_id_t cpy_chnl = bk_dma_alloc(DMA_DEV_DTCM); - CLI_LOGI("UART FROM DATA copy dma_chnl: %d\r\n", cpy_chnl); - - if(cpy_chnl >= DMA_ID_MAX) { - return BK_FAIL; - } - - irq_level = rtos_disable_int(); - - bk_dma_init(cpy_chnl, &dma_config); - bk_dma_register_isr(cpy_chnl, NULL, (void *)dma_chnl_data_from_uart_copy_finish); - bk_dma_enable_finish_interrupt(cpy_chnl); - bk_dma_set_transfer_len(cpy_chnl, len); - bk_dma_start(cpy_chnl); - bk_dma_get_enable_status(cpy_chnl); - bk_dma_free(DMA_DEV_DTCM, cpy_chnl); - - rtos_enable_int(irq_level); - - return BK_OK; -} - -static void dma_channel_test_uart_rx_isr(uart_id_t id, void *param) -{ - int ret; - - ret = rtos_set_semaphore(&dma_chnl_test_semaphore); - if(kNoErr !=ret) - CLI_LOGI("dma_channel_uart_rx_isr: uart set sema failed\r\n"); - return; -} - -static void cli_dma_channel_test(uint32_t data) -{ - - char *msg = NULL; - int ret = -1; - int cnt = 0; - uint8_t rx_data; - char uart_get_data[INBUF_SIZE]; - char dma_out_buffer[INBUF_SIZE]; - - if(NULL == dma_chnl_test_semaphore) - { - ret = rtos_init_semaphore(&dma_chnl_test_semaphore, 1); - if (kNoErr != ret) - CLI_LOGI("cli_dma_channel_test: create background sema failed\r\n"); - } - - while (1) { - - dma_chnl_primenumber_copy(); - - ret = rtos_get_semaphore(&dma_chnl_test_semaphore, dma_chnl_wait_ms); - if(kNoErr == ret) { - while(1) /* read all data from rx-FIFO. */ - { - ret = uart_read_byte_ex(dma_chnl_get_data_uart_id, &rx_data); - if (ret == -1) - break; - - uart_get_data[cnt] = (char)rx_data; - cnt++; - - if(cnt >= INBUF_SIZE) - break; - } - - if (cnt <= 0) - break; - - BK_LOG_ON_ERR(dma_chnl_data_from_uart_copy(dma_out_buffer, uart_get_data, cnt)); - BK_LOG_ON_ERR(bk_uart_write_bytes(dma_chnl_get_data_uart_id, dma_out_buffer, cnt)); - CLI_LOGI("copy From UART Get/Send OK!\r\n"); - - for(int i = 0; i < cnt; i++) { - if(dma_out_buffer[i] == uart_get_data[i]) { - CLI_LOGD("copy From UART right!!!\r\n"); - dma_out_buffer[i] = 0; - } else - CLI_LOGI("copy From UART ERROR\r\n"); - } - - BK_LOG_ON_ERR(dma_memcpy(dma_out_buffer, uart_get_data, cnt * sizeof(char))); - CLI_LOGI("copy dma_MEMCPY OK!\r\n"); - - for(int k = 0; k < cnt; k++) { - if(dma_out_buffer[k] == uart_get_data[k]) { - CLI_LOGD("copy dma_MEMCPY right!!!\r\n"); - dma_out_buffer[k] = 0; - } else - CLI_LOGI("copy dma_MEMCPY ERROR\r\n"); - } - - if (cnt > 0) { - for (int j = 0;j < cnt; j++) - uart_get_data[j] = 0; - cnt = 0; - } - } - - msg = uart_get_data; - if (os_strcmp(msg, EXIT_MSG) == 0) - os_printf("cli_dma_channel_test: EXIT_MSG\r\n"); - } - -} - -static void cli_dma_chnl_test_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - if (argc < 3) { - cli_dma_help(); - return; - } - - if (os_strcmp(argv[1], "start") == 0) { - - if (!dma_chnl_test_handle) { - if (os_strcmp(argv[2], "uart1") == 0) { - dma_chnl_get_data_uart_id = UART_ID_0; - CLI_LOGI("cli_uart_test_cmd Maybe UART1 for log output!!!\n"); - } else if (os_strcmp(argv[2], "uart2")== 0) { - dma_chnl_get_data_uart_id = UART_ID_1; - CLI_LOGI("cli_uart_test_cmd Maybe UART2 for log output!!!\n"); - } else if (os_strcmp(argv[2], "uart3")== 0) { - dma_chnl_get_data_uart_id = UART_ID_2; - CLI_LOGI("cli_uart_test_cmd Maybe UART3 for log output!!!\n"); - } else { - cli_dma_help(); - return; - } - } else { - CLI_LOGI("dma_chnl_test TASK WARKING!!!\n"); - return; - } - - uint32_t wait_ms = 0; - wait_ms = os_strtoul(argv[3], NULL, 10); - - if (wait_ms) - dma_chnl_wait_ms = wait_ms; - - - uart_config_t config = {0}; - os_memset(&config, 0, sizeof(uart_config_t)); - - config.baud_rate = UART_BAUD_RATE; - config.data_bits = UART_DATA_8_BITS; - config.parity = UART_PARITY_NONE; - config.stop_bits = UART_STOP_BITS_1; - config.flow_ctrl = UART_FLOWCTRL_DISABLE; - config.src_clk = UART_SCLK_XTAL_26M; - - BK_LOG_ON_ERR(bk_uart_init(dma_chnl_get_data_uart_id, &config)); - - BK_LOG_ON_ERR(bk_uart_disable_sw_fifo(dma_chnl_get_data_uart_id)); - BK_LOG_ON_ERR(bk_uart_register_rx_isr(dma_chnl_get_data_uart_id, - (uart_isr_t)dma_channel_test_uart_rx_isr, NULL)); - BK_LOG_ON_ERR(bk_uart_enable_rx_interrupt(dma_chnl_get_data_uart_id)); - - if(rtos_create_thread(&dma_chnl_test_handle, 8, "dma_chnl_test", - (beken_thread_function_t) cli_dma_channel_test, 2048, 0)) { - CLI_LOGI("cli_dma_channel_test rtos_create_thread FAILED!\n"); - return; - } - - } - - if (os_strcmp(argv[1], "stop") == 0) { - - if (os_strcmp(argv[2], "uart1") == 0) { - if(dma_chnl_get_data_uart_id != UART_ID_0) { - CLI_LOGI("PLEASE enter a correct ID\n"); - return; - } else - dma_chnl_get_data_uart_id = UART_ID_0; - } else if (os_strcmp(argv[2], "uart2")== 0) { - if(dma_chnl_get_data_uart_id != UART_ID_1) { - CLI_LOGI("PLEASE enter a correct ID\n"); - return; - } else - dma_chnl_get_data_uart_id = UART_ID_1; - } else if (os_strcmp(argv[2], "uart3")== 0) { - if(dma_chnl_get_data_uart_id != UART_ID_2) { - CLI_LOGI("PLEASE enter a correct ID\n"); - return; - } else - dma_chnl_get_data_uart_id = UART_ID_2; - } else { - cli_dma_help(); - return; - } - - rtos_delete_thread(&dma_chnl_test_handle); - dma_chnl_test_handle = NULL; - BK_LOG_ON_ERR(bk_uart_disable_rx_interrupt(dma_chnl_get_data_uart_id)); - BK_LOG_ON_ERR(bk_uart_register_rx_isr(dma_chnl_get_data_uart_id, NULL, NULL)); - BK_LOG_ON_ERR(bk_uart_deinit(dma_chnl_get_data_uart_id)); - dma_chnl_get_data_uart_id = UART_ID_MAX; - dma_chnl_wait_ms = 1000; - - CLI_LOGI("idle_uart_out task stop\n"); - } -} - -#define DMA_CMD_CNT (sizeof(s_dma_commands) / sizeof(struct cli_command)) -static const struct cli_command s_dma_commands[] = { - {"dma_driver", "dma_driver {init|deinit}", cli_dma_driver_cmd}, - {"dma", "dma {id} {init|deinit|start|stop|set_tran_len|get_remain_len}", cli_dma_cmd}, - {"dma_int", "dma_int {id} {reg|enable_hf_fini|disable_hf_fini|enable_fini|disable_fini}", cli_dma_int_cmd}, - {"dma_chnl", "dma_chnl alloc", cli_dma_chnl_alloc}, - {"dma_chnl_free", "dma_chnl_free {id}", cli_dma_chnl_free}, - {"dma_memcopy_test", "copy {count|in_number1|in_number2|out_number1|out_number2}", cli_dma_memcpy_test}, - {"dma_chnl_test", "{start|stop} {uart1|uart2|uart3} {wait_ms}", cli_dma_chnl_test_cmd}, -}; - -int cli_dma_init(void) -{ - BK_LOG_ON_ERR(bk_dma_driver_init()); - return cli_register_commands(s_dma_commands, DMA_CMD_CNT); -} - diff --git a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_dma2d.c b/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_dma2d.c deleted file mode 100755 index a2ef8da08acf3a6054cce339eb79fe8bb170a170..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_dma2d.c +++ /dev/null @@ -1,43 +0,0 @@ -#include "cli.h" -extern void dma2d_memcpy_display(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv); -extern void bk_example_alpha_blend(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv); -extern void bk_example_fill_2p_alpha_blend(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv); -extern void bk_example_dma2d_rgb565_to_argb8888pixel(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv); -extern void bk_example_dma2d_argb8888_to_rgb565pixel(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv); -extern void bk_example_dma2d_deinit(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv); - -#define DMA2D_CNT (sizeof(s_dma2d_commands) / sizeof(struct cli_command)) -static const struct cli_command s_dma2d_commands[] = { - {"dma2d_memcpy_display", "dma2d_mem_to_mem \r\n", dma2d_memcpy_display}, - {"dma2d_565_to_8888", "dma2d_pfc = RedBlueSwapConfig", bk_example_dma2d_rgb565_to_argb8888pixel}, - {"dma2d_8888_to_565", "dma2d_pfc = RedBlueSwapConfig", bk_example_dma2d_argb8888_to_rgb565pixel}, - {"alpha_patrtial_blend", "bk_example_alpha_blend", bk_example_alpha_blend}, - {"alpha_fill_blend_p2", "bk_example_alpha_blend", bk_example_fill_2p_alpha_blend}, - {"dma2d_deinit", "bk_example_alpha_blend", bk_example_dma2d_deinit}, -}; - -int cli_dma2d_init(void) -{ - return cli_register_commands(s_dma2d_commands, DMA2D_CNT); -} - - - - - - - - - - - - - - - - - - - - - diff --git a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_doorbell.c b/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_doorbell.c deleted file mode 100755 index c96a4df915949978f845a0042450d88e034603d0..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_doorbell.c +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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 "cli.h" - -#if CONFIG_DOORBELL - - -extern void cli_doorbell_test_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv); - - - -#define DOORBELL_CMD_CNT (sizeof(s_doorbell_commands) / sizeof(struct cli_command)) - -static const struct cli_command s_doorbell_commands[] = { - {"doorbell", "doorbell...", cli_doorbell_test_cmd}, -}; - -int cli_doorbell_init(void) -{ - return cli_register_commands(s_doorbell_commands, DOORBELL_CMD_CNT); -} - -#endif diff --git a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_dsp_bk7271.c b/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_dsp_bk7271.c deleted file mode 100644 index 8c577f31cb9c97c61d2bc4596ef58cf81b64d60f..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_dsp_bk7271.c +++ /dev/null @@ -1,905 +0,0 @@ -#include -#include "stdarg.h" -#include -#include "sys_rtos.h" -#include -#include - -#include "bk_sys_ctrl.h" -#include "bk_cli.h" -#include "bk_mailbox.h" -#include -#include "ff.h" -#include "diskio.h" -#include "audio_pub.h" -#include -#include -#include "cli.h" -#include - -#if CONFIG_USB_HOST -static dma_buffer_node record_buffer_nodes[DAC_PLAY_NODE_MAX]; -struct adc_dac_context g_record_context; -volatile int record_flag = 0; -volatile int thread_flag = 0; -beken_thread_t usb_record_thread_handle; -beken_semaphore_t usb_record_sem = NULL; -beken_semaphore_t usb_play_sem = NULL; -FIL record_file; - -FATFS *pfs = NULL; -uint8_t mount_flag = 0; - -static const unsigned long PCM_8000[] = { - 0x00010000, 0x5A825A81, 0x7FFF7FFF, 0x5A825A83, 0x00000000, 0xA57FA57E, 0x80018002, 0xA57EA57E, -}; - -static const unsigned long PCM_16000[] = { - 0x00000001, 0x30FC30FA, 0x5A815A82, 0x76417641, 0x7FFF7FFF, 0x76417641, 0x5A815A82, 0x30FB30FB, - 0x00000000, 0xCF05CF04, 0xA57EA57E, 0x89BF89BF, 0x80018000, 0x89C089BF, 0xA57EA57F, 0xCF05CF04, -}; - -static const unsigned long PCM_44100[] = { - 0x00000000, 0x122D122E, 0x23FC23FB, 0x350F350F, 0x450F4510, 0x53AA53AA, 0x60926092, 0x6B866B85, - 0x744A744A, 0x7AB57AB5, 0x7EA37EA2, 0x7FFF7FFF, 0x7EC37EC4, 0x7AF77AF6, 0x74AB74AC, 0x6C036C04, - 0x612B612A, 0x5459545A, 0x45D445D3, 0x35E335E3, 0x24DB24DA, 0x13141313, 0x00EA00EA, 0xEEBAEEBB, - 0xDCE5DCE4, 0xCBC5CBC6, 0xBBB6BBB5, 0xAD08AD08, 0xA008A008, 0x94FA94FA, 0x8C188C17, 0x858E858E, - 0x81818181, 0x80038003, 0x811D811D, 0x84C984CA, 0x8AF58AF5, 0x93809381, 0x9E3E9E3E, 0xAAF7AAF7, - 0xB969B96A, 0xC94AC94A, 0xDA46DA46, 0xEC05EC06, 0xFE2DFE2E, 0x105E105E, 0x223B223B, 0x33653365, - 0x43854384, 0x52465246, 0x5F5D5F5D, 0x6A856A85, 0x73847384, 0x7A2C7A2C, 0x7E5B7E5B, 0x7FFA7FFA, - 0x7F007F01, 0x7B747B75, 0x75697569, 0x6CFB6CFB, 0x62586258, 0x55B755B7, 0x47594759, 0x37893789, - 0x26992699, 0x14E114E1, 0x02BC02BC, 0xF08AF08A, 0xDEA6DEA6, 0xCD72CD72, 0xBD42BD43, 0xAE6DAE6D, - 0xA13FA13F, 0x95FD95FD, 0x8CE18CE2, 0x86198619, 0x81CA81CB, 0x800B800C, 0x80E380E3, 0x844E844E, - 0x8A3C8A3C, 0x928B928B, 0x9D149D13, 0xA99CA99C, 0xB7E6B7E6, 0xC7A4C7A5, 0xD889D888, 0xEA39EA39, - 0xFC5AFC5A, 0x0E8F0E8F, 0x20782077, 0x31B831B8, 0x41F641F6, 0x50DF50DF, 0x5E235E23, 0x697F697F, - 0x72B972B8, 0x799F799E, 0x7E0D7E0D, 0x7FEE7FEE, 0x7F387F38, 0x7BED7BED, 0x761F761F, 0x6DEC6DED, - 0x63806380, 0x570F5710, 0x48DB48DA, 0x392C392C, 0x28552855, 0x16AC16AD, 0x048F048F, 0xF25AF259, - 0xE06BE06B, 0xCF1FCF1F, 0xBED2BED3, 0xAFD8AFD7, 0xA27CA27B, 0x97059706, 0x8DB08DB1, 0x86AB86AB, - 0x821C821C, 0x801A801A, 0x80B080AF, 0x83DA83DA, 0x89888988, 0x919C919C, 0x9BED9BEE, 0xA847A846, - 0xB666B666, 0xC603C603, 0xD6CED6CD, 0xE86DE86D, 0xFA89FA87, 0x0CBE0CBF, 0x1EB31EB3, 0x30083007, - 0x40644064, 0x4F734F73, 0x5CE55CE4, 0x68756874, 0x71E771E7, 0x790A790A, 0x7DB87DB9, 0x7FDC7FDD, - 0x7F677F68, 0x7C5F7C5E, 0x76CF76D0, 0x6ED96EDA, 0x64A364A3, 0x58635863, 0x4A594A58, 0x3ACD3ACC, - 0x2A102A0F, 0x18781878, 0x06610661, 0xF429F42A, 0xE230E22F, 0xD0D0D0D0, 0xC066C066, 0xB145B145, - 0xA3BCA3BD, 0x98149813, 0x8E848E85, 0x87438743, 0x82738273, 0x802F8030, 0x80848083, 0x836B836B, - 0x88DA88DB, 0x90B390B3, 0x9ACE9ACD, 0xA6F5A6F5, 0xB4EAB4EA, 0xC464C465, 0xD515D515, 0xE6A3E6A3, - 0xF8B6F8B6, 0x0AED0AEE, 0x1CEC1CED, 0x2E562E57, 0x3ED03ED0, 0x4E024E03, 0x5BA15BA0, 0x67646764, - 0x710E710F, 0x786F786E, 0x7D5E7D5E, 0x7FC37FC3, 0x7F917F91, 0x7CCA7CC9, 0x777A777A, 0x6FBF6FC0, - 0x65C165C2, 0x59B259B3, 0x4BD34BD3, 0x3C693C69, 0x2BC62BC7, 0x1A411A40, 0x08330834, 0xF5FBF5FB, - 0xE3F6E3F7, 0xD283D284, 0xC1FCC1FD, 0xB2B7B2B8, 0xA503A503, 0x99279926, 0x8F608F60, 0x87E187E2, - 0x82D282D2, 0x804D804C, 0x805D805C, 0x83038304, 0x88338833, 0x8FCF8FCF, 0x99B299B1, 0xA5A8A5A8, - 0xB371B372, 0xC2C8C2CA, 0xD35ED35E, 0xE4DAE4DB, 0xF6E4F6E4, 0x091C091C, 0x1B261B25, 0x2CA22CA2, - 0x3D373D37, 0x4C8E4C8E, 0x5A595A59, 0x664E664E, 0x70307030, 0x77CD77CE, 0x7CFD7CFD, 0x7FA37FA3, - 0x7FB37FB4, 0x7D2E7D2E, 0x781F781F, 0x70A170A0, 0x66DA66DA, 0x5AFE5AFD, 0x4D494D49, 0x3E033E04, - 0x2D7D2D7D, 0x1C091C0A, 0x0A050A05, 0xF7CCF7CD, 0xE5BEE5BE, 0xD439D439, 0xC396C396, 0xB42DB42D, - 0xA64DA64E, 0x9A3E9A3E, 0x90409040, 0x88868886, 0x83378337, 0x806E806E, 0x803D803E, 0x82A382A1, - 0x87928791, 0x8EF18EF2, 0x989C989C, 0xA45FA45F, 0xB1FEB1FD, 0xC131C131, 0xD1AAD1AA, 0xE313E313, - 0xF512F512, 0x074A074B, 0x195D195C, 0x2AEC2AEC, 0x3B9C3B9C, 0x4B164B16, 0x590C590B, 0x65336532, - 0x6F4D6F4C, 0x77267726, 0x7C957C95, 0x7F7D7F7D, 0x7FD17FD1, 0x7D8C7D8C, 0x78BD78BC, 0x717B717A, - 0x67ED67ED, 0x5C445C43, 0x4EBB4EBB, 0x3F9B3F9A, 0x2F302F30, 0x1DD01DD0, 0x0BD60BD7, 0xF99FF99E, - 0xE788E789, 0xD5F1D5F1, 0xC533C533, 0xB5A8B5A7, 0xA79DA79D, 0x9B5D9B5D, 0x91289127, 0x89308930, - 0x83A283A2, 0x80988098, 0x80248024, 0x82468247, 0x86F786F6, 0x8E1A8E19, 0x978C978C, 0xA31CA31C, - 0xB08EB08D, 0xBF9CBF9B, 0xCFF7CFF8, 0xE14DE14C, 0xF342F342, 0x05780578, 0x17931792, 0x29332933, - 0x39FE39FD, 0x499B499A, 0x57B957BA, 0x64126413, 0x6E636E64, 0x76787678, 0x7C277C27, 0x7F517F50, - 0x7FE67FE5, 0x7DE47DE3, 0x79557955, 0x72517250, 0x68FA68FB, 0x5D855D84, 0x50295029, 0x412E412E, - 0x30E030E1, 0x1F961F95, 0x0DA70DA6, 0xFB71FB70, 0xE954E953, 0xD7ABD7AB, 0xC6D4C6D3, 0xB726B725, - 0xA8F1A8F1, 0x9C809C80, 0x92139213, 0x89E189E0, 0x84138413, 0x80C880C9, 0x80128011, 0x81F381F3, - 0x86618663, 0x8D478D48, 0x96819680, 0xA1DDA1DD, 0xAF22AF22, 0xBE0ABE0A, 0xCE48CE48, 0xDF88DF89, - 0xF172F171, 0x03A603A5, 0x15C715C8, 0x27782777, 0x385B385B, 0x481B481A, 0x56635664, 0x62ED62EC, - 0x6D746D75, 0x75C475C5, 0x7BB17BB2, 0x7F1C7F1C, 0x7FF57FF4, 0x7E347E35, 0x79E679E6, 0x731F731F, - 0x6A046A03, 0x5EC15EC1, 0x51935194, 0x42BE42BE, 0x328E328F, 0x21592159, 0x0F770F77, 0xFD43FD44, - 0xEB20EB1F, 0xD967D966, 0xC877C877, 0xB8A8B8A7, 0xAA49AA49, 0x9DA89DA9, 0x93059306, 0x8A988A98, - 0x848B848B, 0x80FF80FF, 0x80068006, 0x81A581A4, 0x85D485D3, 0x8C7B8C7C, 0x957B957A, 0xA0A4A0A2, - 0xADBAADBA, 0xBC7BBC7B, 0xCC9CCC9C, 0xDDC6DDC6, 0xEFA2EFA2, 0x01D201D3, 0x13FB13FB, 0x25BA25BA, - 0x36B636B7, 0x46964697, 0x550A5509, 0x61C261C2, 0x6C806C7F, 0x750B750A, 0x7B377B36, 0x7EE37EE2, - 0x7FFD7FFE, 0x7E7F7E80, 0x7A717A71, 0x73E973E8, 0x6B066B06, 0x5FF85FF8, 0x52F952F8, 0x444A444B, - 0x343B343A, 0x231B231A, 0x11461146, 0xFF17FF17, 0xECEDECEC, 0xDB26DB25, 0xCA1DCA1E, 0xBA2CBA2D, - 0xABA6ABA6, 0x9ED59ED5, 0x93FD93FD, 0x8B558B55, 0x85098509, 0x813C813D, 0x80018001, 0x815E815E, - 0x854B854C, 0x8BB58BB5, 0x947B947B, 0x9F6D9F6F, 0xAC56AC57, 0xBAF1BAF0, 0xCAF1CAF1, 0xDC05DC04, - 0xEDD2EDD4, -}; - -static const unsigned long PCM_48000[] = { - 0x0000FFFF, 0x10B510B5, 0x21202121, 0x30FB30FC, 0x40003FFF, 0x4DEC4DEC, 0x5A825A82, 0x658C658C, - 0x6EDA6ED9, 0x76417641, 0x7BA37BA2, 0x7EE77EE7, 0x7FFF7FFF, 0x7EE67EE6, 0x7BA27BA3, 0x76417641, - 0x6ED86EDA, 0x658C658B, 0x5A825A82, 0x4DEB4DEB, 0x3FFF3FFF, 0x30FC30FB, 0x21202120, 0x10B510B5, - 0x00010000, 0xEF4AEF4B, 0xDEDFDEDF, 0xCF05CF05, 0xC000C000, 0xB214B215, 0xA57EA57F, 0x9A759A74, - 0x91269127, 0x89C089BF, 0x845D845D, 0x811A8119, 0x80018001, 0x811A811A, 0x845E845D, 0x89BF89C0, - 0x91279127, 0x9A749A74, 0xA57EA57E, 0xB214B216, 0xC001C001, 0xCF05CF04, 0xDEDFDEDF, 0xEF4BEF4B, -}; - -static uint32_t dsp_atoi(char *src) -{ - uint32_t num = 0; - - if (NULL == src) - return 0; - - while ((*src != 0) && ((*src < '0') || (*src > '9'))) - src++; - - if ((*src == '0') && ((*(src + 1) == 'x') || ((*(src + 1) == 'X')))) { - src += 2; - while (*src != 0) { - if ((*src >= '0') && (*src <= '9')) - num = num * 16 + *src - '0'; - else if ((*src >= 'A') && (*src <= 'F')) - num = num * 16 + *src - 'A' + 10; - else if ((*src >= 'a') && (*src <= 'f')) - num = num * 16 + *src - 'a' + 10; - else - return num; - src++; - } - } else { - while (*src != 0) { - if ((*src >= '0') && (*src <= '9')) - num = num * 10 + *src - '0'; - else - return num; - src++; - } - } - - return num; -} - -void dsp_wake_up_cb(mailbox_data_t *param) -{ - if (param->param0 == MAILBOX_CMD_AUDIO_WIFI_WAKEUP) - CLI_LOGI("recv wake up from dsp!!!!\r\n"); -} - -void mic_test_command(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - uint32_t enable; - mailbox_data_t mailbox; - - if (argc > 1) - enable = dsp_atoi(argv[1]); - else - enable = 0; - bk_mailbox_set_param(&mailbox, MAILBOX_CMD_AUDIO_ADC_TEST, enable, 0, 0); - bk_mailbox_send(&mailbox, MAILBOX_CPU0, MAILBOX_DSP, NULL); -} - -void usb_mount_command(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - FRESULT fr; - char sys_path[10]; - int number = DISK_NUMBER_UDISK; - - if (pfs) - os_free(pfs); - - pfs = os_malloc(sizeof(FATFS)); - if (NULL == pfs) { - CLI_LOGI("f_mount malloc failed!\r\n"); - return; - } - - os_memset(sys_path, 0, sizeof(sys_path)); - sprintf(sys_path, "%d:", number); - fr = f_mount(pfs, sys_path, 1); - if (fr != FR_OK) { - mount_flag = 0; - CLI_LOGI("usb mount failed:%d\r\n", fr); - } else { - mount_flag = 1; - CLI_LOGI("usb mount OK!\r\n"); - } -} - - - -void usb_unmount_command(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - FRESULT fr; - char sys_path[10]; - int number = DISK_NUMBER_UDISK; - - if (mount_flag != 1) { - CLI_LOGI("usb hasn't initialization!\r\n"); - return; - } - - os_memset(sys_path, 0, sizeof(sys_path)); - sprintf(sys_path, "%d:", number); - fr = f_mount(NULL, sys_path, 1); - if (fr != FR_OK) { - CLI_LOGI("unmount %s fail.\r\n", sys_path); - return; - } - - if (pfs) { - os_free(pfs); - pfs = NULL; - } - - mount_flag = 0; - CLI_LOGI("usb unmount OK!\r\n"); -} - -static FRESULT usb_scan_files(char *path) -{ - FRESULT fr; - DIR dir; - FILINFO fno; - char path_temp[255]; - - fr = f_opendir(&dir, path); - if (fr == FR_OK) { - while (1) { - fr = f_readdir(&dir, &fno); - if (fr != FR_OK) - break; - if (fno.fname[0] == 0) - break; - if (fno.fattrib & AM_DIR) { - /* It is a directory */ - os_memset(path_temp, 0, sizeof(path_temp)); - sprintf(path_temp, "%s/%s", path, fno.fname); - fr = usb_scan_files(path_temp); - if (fr != FR_OK) break; - } else { - /* It is a file. */ - CLI_LOGI("%s/%s\r\n", path, fno.fname); - } - } - f_closedir(&dir); - } else - CLI_LOGI("f_opendir failed\r\n"); - - return fr; -} - -void usb_ls_command(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - FRESULT fr; - char sys_path[10]; - int number = DISK_NUMBER_UDISK; - - if (mount_flag != 1) { - CLI_LOGI("usb hasn't initialization!\r\n"); - return; - } - - os_memset(sys_path, 0, sizeof(sys_path)); - sprintf(sys_path, "%d:", number); - fr = usb_scan_files(sys_path); - if (fr != FR_OK) - CLI_LOGI("scan_files failed!\r\n"); -} - -void pcm_test_command(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - int i; - uint32_t rate; - uint32_t *aud_ptr = 0; - uint32_t aud_len = 0; - uint32_t *aud_addr = (uint32_t *)DAC_PLAY_NODE_ADDR; - mailbox_data_t mailbox; - - if (argc < 2) { - CLI_LOGI("pcm_test <8000|16000|44100|48000>\r\n"); - return; - } - - if (os_strcmp(argv[1], "start") == 0) { - if (argc > 2) - rate = dsp_atoi(argv[2]); - else - rate = 8000; - - if (rate == 8000) { - aud_ptr = (uint32_t *)PCM_8000; - aud_len = sizeof(PCM_8000) / sizeof(PCM_8000[0]); - } else if (rate == 16000) { - aud_ptr = (uint32_t *)PCM_16000; - aud_len = sizeof(PCM_16000) / sizeof(PCM_16000[0]); - } else if (rate == 44100) { - aud_ptr = (uint32_t *)PCM_44100; - aud_len = sizeof(PCM_44100) / sizeof(PCM_44100[0]); - } else if (rate == 48000) { - aud_ptr = (uint32_t *)PCM_48000; - aud_len = sizeof(PCM_48000) / sizeof(PCM_48000[0]); - } else - CLI_LOGI("rate error: %d.\r\n", rate); - - sddev_control(DD_DEV_TYPE_SCTRL, CMD_SCTRL_AUDIO_PLL, &rate); - - bk_mailbox_set_param(&mailbox, MAILBOX_CMD_AUDIO_DAC_SAMPLE_RATE_SET, rate, 0, 0); - bk_mailbox_send(&mailbox, MAILBOX_CPU0, MAILBOX_DSP, NULL); - - for (i = 0; i < aud_len; i++) { - aud_addr[2 * i] = ((uint32_t)aud_ptr[i] & 0xFFFF) << 8; - aud_addr[2 * i + 1] = ((uint32_t)aud_ptr[i] & 0xFFFF) << 8; - } - bk_mailbox_set_param(&mailbox, MAILBOX_CMD_AUDIO_DAC_PCM_CHECK, ((uint32_t)aud_addr) - W_DSP_DMEM_64KB_BASE_ADDR, aud_len * 8, 1); - bk_mailbox_send(&mailbox, MAILBOX_CPU0, MAILBOX_DSP, NULL); - } else if (os_strcmp(argv[1], "stop") == 0) { - bk_mailbox_set_param(&mailbox, MAILBOX_CMD_AUDIO_DAC_PCM_CHECK, 0, 0, 0); - bk_mailbox_send(&mailbox, MAILBOX_CPU0, MAILBOX_DSP, NULL); - } -} - - -void record2dac_cb(mailbox_data_t *param) -{ - mailbox_data_t mailbox; - dma_buffer_node *node; - - switch (param->param0) { - case MAILBOX_CMD_AUDIO_ADC_PCM_READ: - if (NULL == (uint8_t *)param->param1) { - CLI_LOGI("%s:%d param1 is invalid\r\n", __FUNCTION__, __LINE__); - break; - } - node = (dma_buffer_node *)co_list_pop_front(&g_record_context.free_list); - if (NULL == node) { - CLI_LOGI("free_list is empty\r\n"); - break; - } - - node->buffer = (uint8_t *)param->param1; - node->size = param->param2; - co_list_push_back(&g_record_context.using_list, (struct co_list_hdr *)node); - bk_mailbox_set_param(&mailbox, MAILBOX_CMD_AUDIO_DAC_PCM_WRITE, param->param1, param->param2, 0); - bk_mailbox_send(&mailbox, MAILBOX_CPU0, MAILBOX_DSP, NULL); - break; - - case MAILBOX_CMD_AUDIO_DAC_PCM_WRITE_DONE: - if (NULL == (uint8_t *)param->param1) { - CLI_LOGI("%s:%d param1 is invalid\r\n", __FUNCTION__, __LINE__); - break; - } - node = (dma_buffer_node *)co_list_pick(&g_record_context.using_list); - if (NULL == node) { - CLI_LOGI("using_list is empty\r\n"); - break; - } - - for (; NULL != node; node = (dma_buffer_node *)node->header.next) { - if (node->buffer == (uint8_t *)param->param1) { - co_list_extract(&g_record_context.using_list, (struct co_list_hdr *)node); - break; - } - } - - if (node == NULL) - CLI_LOGI("can't find 0x%x in dac_list\r\n", param->param1); - else { - co_list_push_back(&g_record_context.free_list, (struct co_list_hdr *)node); - bk_mailbox_set_param(&mailbox, MAILBOX_CMD_AUDIO_ADC_PCM_READ_DONE, param->param1, param->param2, 0); - bk_mailbox_send(&mailbox, MAILBOX_CPU0, MAILBOX_DSP, NULL); - } - break; - - default: - CLI_LOGI("%s:%d cmd=0x%x\r\n", __FUNCTION__, __LINE__, param->param0); - break; - } -} - -void record2dac_command(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - int i; - mailbox_data_t mailbox; - - if (argc < 2) { - CLI_LOGI("record2dac \r\n"); - CLI_LOGI("record2dac \r\n"); - return; - } - - if (os_strcmp(argv[1], "start") == 0) { - if (argc < 3) { - CLI_LOGI("record2dac \r\n"); - return; - } - co_list_init(&g_record_context.using_list); - co_list_init(&g_record_context.free_list); - for (i = 0; i < sizeof(record_buffer_nodes) / sizeof(record_buffer_nodes[0]); i++) { - record_buffer_nodes[i].buffer = (uint8_t *)NULL; - record_buffer_nodes[i].size = 0; - co_list_push_back(&g_record_context.free_list, &record_buffer_nodes[i].header); - } - bk_mailbox_recv_callback_register(MAILBOX_DSP, MAILBOX_CPU0, (mailbox_callback_t)record2dac_cb); - - if (os_strcmp(argv[2], "adcx") == 0) { - bk_mailbox_set_param(&mailbox, MAILBOX_CMD_AUDIO_DAC_ENABLE, 1, 1, 1); - } else { - bk_mailbox_set_param(&mailbox, MAILBOX_CMD_AUDIO_DAC_ENABLE, 1, 2, 1); - } - bk_mailbox_send(&mailbox, MAILBOX_CPU0, MAILBOX_DSP, NULL); - - if (os_strcmp(argv[2], "adcx") == 0) - bk_mailbox_set_param(&mailbox, MAILBOX_CMD_AUDIO_ADC_RECORD, 0, 1, 0); - else if (os_strcmp(argv[2], "adc1") == 0) - bk_mailbox_set_param(&mailbox, MAILBOX_CMD_AUDIO_ADC_RECORD, 1, 0, 0); - else if (os_strcmp(argv[2], "adc2") == 0) - bk_mailbox_set_param(&mailbox, MAILBOX_CMD_AUDIO_ADC_RECORD, 2, 0, 0); - else - bk_mailbox_set_param(&mailbox, MAILBOX_CMD_AUDIO_ADC_RECORD, 0, 0, 0); - bk_mailbox_send(&mailbox, MAILBOX_CPU0, MAILBOX_DSP, NULL); - } else if (os_strcmp(argv[1], "stop") == 0) { - bk_mailbox_set_param(&mailbox, MAILBOX_CMD_AUDIO_ADC_RECORD, 0, 0, 0); - bk_mailbox_send(&mailbox, MAILBOX_CPU0, MAILBOX_DSP, NULL); - - bk_mailbox_set_param(&mailbox, MAILBOX_CMD_AUDIO_DAC_ENABLE, 0, 0, 0); - bk_mailbox_send(&mailbox, MAILBOX_CPU0, MAILBOX_DSP, NULL); - bk_mailbox_recv_callback_unregister(MAILBOX_CPU0, MAILBOX_DSP); - } else - CLI_LOGI("NOT support command %s.\r\n", argv[1]); -} - -static void usb_record_thread_main(void *arg) -{ - int ret; - mailbox_data_t mailbox; - dma_buffer_node *node; - UINT bw; - FRESULT fr; - - while (record_flag) { - ret = rtos_get_semaphore(&usb_record_sem, BEKEN_WAIT_FOREVER); - if (ret) { - CLI_LOGI("get usb record semaphore fail.\r\n"); - break; - } - - /*write adc data to usb*/ - node = (dma_buffer_node *)co_list_pick(&g_record_context.using_list); - if (node) { - for (; node != NULL; node = (dma_buffer_node *)node->header.next) { - co_list_extract(&g_record_context.using_list, (struct co_list_hdr *)node); - fr = f_write(&record_file, node->buffer, node->size, &bw); - if (fr != FR_OK) - CLI_LOGI("write %x to usb fail.\r\n", (uint32_t)node->buffer); - if (node->size != bw) - CLI_LOGI("write %x to usb bytes %d/%d.\r\n", (uint32_t)node->buffer, bw, node->size); - co_list_push_back(&g_record_context.free_list, (struct co_list_hdr *)node); - bk_mailbox_set_param(&mailbox, MAILBOX_CMD_AUDIO_ADC_PCM_READ_DONE, ((uint32_t)node->buffer) - W_DSP_DMEM_64KB_BASE_ADDR, node->size, 0); - bk_mailbox_send(&mailbox, MAILBOX_CPU0, MAILBOX_DSP, NULL); - } - } - } - - /*set flag for thread end*/ - thread_flag = 0; - rtos_delete_thread(&usb_record_thread_handle); -} - -static void usb_record_cb_hdl(mailbox_data_t *param) -{ - int ret; - dma_buffer_node *node; - - switch (param->param0) { - case MAILBOX_CMD_AUDIO_ADC_PCM_READ: - if ((uint8_t *)param->param1 == NULL) { - CLI_LOGI("%s:%d param1 is invalid!\r\n", __FUNCTION__, __LINE__); - break; - } - - node = (dma_buffer_node *)co_list_pop_front(&g_record_context.free_list); - if (node == NULL) { - CLI_LOGI("free_list is empty!\r\n"); - break; - } - - node->buffer = (uint8_t *)(param->param1 + W_DSP_DMEM_64KB_BASE_ADDR); - node->size = param->param2; - co_list_push_back(&g_record_context.using_list, (struct co_list_hdr *)node); - ret = rtos_set_semaphore(&usb_record_sem); - if (ret) - CLI_LOGI("set usb record semaphore fail.\r\n"); - break; - default: - CLI_LOGI("%s:%d cmd=0x%x!\r\n", __FUNCTION__, __LINE__, param->param0); - break; - } -} - -void record2usb_command(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - int ret; - uint32_t index = 0; - mailbox_data_t mailbox; - char file_name[50]; - FRESULT fr; - int number = DISK_NUMBER_UDISK; - - if (argc < 2) { - CLI_LOGI("record2usb [file name]\r\n"); - CLI_LOGI("record2usb \r\n"); - return; - } - - if (mount_flag != 1) { - CLI_LOGI("usb hasn't initialization!\r\n"); - return; - } - - if (os_strcmp(argv[1], "start") == 0) { - if (argc < 3) { - CLI_LOGI("record2usb [file name]\r\n"); - return; - } - - if (record_flag) { - CLI_LOGW("record thread is running cmd is invalid!\r\n"); - return; - } - - /*create&open record file*/ - os_memset(file_name, 0, sizeof(file_name)); - if (argc > 3) - sprintf(file_name, "%d:/%s", number, argv[3]); - else - sprintf(file_name, "%d:/record.pcm", number); - fr = f_open(&record_file, file_name, FA_CREATE_ALWAYS | FA_READ | FA_WRITE); - if (fr != FR_OK) { - CLI_LOGI("open %s fail.\r\n", file_name); - return; - } - - /*init list*/ - co_list_init(&g_record_context.using_list); - co_list_init(&g_record_context.free_list); - for (index = 0; index < sizeof(record_buffer_nodes) / sizeof(record_buffer_nodes[0]); index++) { - record_buffer_nodes[index].buffer = (uint8_t *)NULL; - record_buffer_nodes[index].size = 0; - co_list_push_back(&g_record_context.free_list, &record_buffer_nodes[index].header); - } - - /*create thread to write usb*/ - ret = rtos_init_semaphore(&usb_record_sem, 10); - if (ret) { - CLI_LOGI("create usb record semaphore fail.\r\n"); - return; - } - record_flag = 1; - thread_flag = 1; - ret = rtos_create_thread(&usb_record_thread_handle, - 5, - "usb_record_thread", - (beken_thread_function_t)usb_record_thread_main, - 2048, - (beken_thread_arg_t)0); - if (ret) { - CLI_LOGI("create usb record thread fail.\r\n"); - return; - } - - /*set mailbox callback*/ - bk_mailbox_recv_callback_register(MAILBOX_CPU0, MAILBOX_DSP, (mailbox_callback_t)usb_record_cb_hdl); - - /*send record start to dsp*/ - if (os_strcmp(argv[2], "adcx") == 0) - bk_mailbox_set_param(&mailbox, MAILBOX_CMD_AUDIO_ADC_RECORD, 0, 1, 0); - else if (os_strcmp(argv[2], "adc1") == 0) - bk_mailbox_set_param(&mailbox, MAILBOX_CMD_AUDIO_ADC_RECORD, 1, 0, 0); - else if (os_strcmp(argv[2], "adc2") == 0) - bk_mailbox_set_param(&mailbox, MAILBOX_CMD_AUDIO_ADC_RECORD, 2, 0, 0); - else - bk_mailbox_set_param(&mailbox, MAILBOX_CMD_AUDIO_ADC_RECORD, 0, 0, 0); - bk_mailbox_send(&mailbox, MAILBOX_CPU0, MAILBOX_DSP, NULL); - } else if (os_strcmp(argv[1], "stop") == 0) { - if (!usb_record_sem) { - CLI_LOGW("please start record thread.\r\n"); - return; - } - - /*send record stop to dsp*/ - bk_mailbox_set_param(&mailbox, MAILBOX_CMD_AUDIO_ADC_RECORD, 0, 0, 0); - bk_mailbox_send(&mailbox, MAILBOX_CPU0, MAILBOX_DSP, NULL); - - /*delete usb record thread*/ - record_flag = 0; - ret = rtos_set_semaphore(&usb_record_sem); - if (ret) { - CLI_LOGI("set usb record semaphore fail.\r\n"); - return; - } - while (thread_flag) - rtos_delay_milliseconds(2); - ret = rtos_deinit_semaphore(&usb_record_sem); - if (ret) - CLI_LOGI("delete usb record semaphore fail.\r\n"); - bk_mailbox_recv_callback_unregister(MAILBOX_CPU0, MAILBOX_DSP); - - /*close record file*/ - fr = f_close(&record_file); - if (fr != FR_OK) - CLI_LOGI("close record file fail.\r\n"); - } -} - -static void usb_play_cb_hdl(mailbox_data_t *param) -{ - int ret; - dma_buffer_node *node; - - switch (param->param0) { - case MAILBOX_CMD_AUDIO_DAC_PCM_WRITE_DONE: - node = (dma_buffer_node *)co_list_pick(&g_record_context.using_list); - if (node == NULL) { - CLI_LOGI("%s:%d using list is empty!\r\n", __FUNCTION__, __LINE__); - break; - } - - for (; node != NULL; node = (dma_buffer_node *)node->header.next) { - if (node->buffer == (uint8_t *)(param->param1 + W_DSP_DMEM_64KB_BASE_ADDR)) { - co_list_extract(&g_record_context.using_list, (struct co_list_hdr *)node); - break; - } - } - - if (node == NULL) - CLI_LOGI("can not find 0x%x in dac_list!\r\n", param->param1); - else - co_list_push_back(&g_record_context.free_list, (struct co_list_hdr *)node); - - if (param->param2 == 0) { - ret = rtos_set_semaphore(&usb_play_sem); - if (ret) - CLI_LOGI("set usb play semaphore fail.\r\n"); - } - break; - - default: - CLI_LOGI("%s:%d cmd=0x%x!\r\n", __FUNCTION__, __LINE__, param->param0); - break; - } -} - -void usb_play_command(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - int ret; - uint32_t index = 0; - uint32_t address = DAC_PLAY_NODE_ADDR; - mailbox_data_t mailbox; - dma_buffer_node *node; - char file_name[50]; - FRESULT fr; - int number = DISK_NUMBER_UDISK; - UINT br; - uint32_t retry_cnt = 0; - char *postfix; - uint32_t chann; - - if (mount_flag != 1) { - CLI_LOGI("usb hasn't initialization!\r\n"); - return; - } - - if (argc < 2) { - CLI_LOGI("usb_play [filename]\r\n"); - return; - } - - /*init usb play semaphore*/ - ret = rtos_init_semaphore(&usb_play_sem, 1); - if (ret) { - CLI_LOGI("create usb play semaphore fail.\r\n"); - return; - } - - /*get play mono or stereo*/ - chann = dsp_atoi(argv[1]); - if (chann != 1 && chann != 2) { - CLI_LOGI("usb_play [filename]\r\n"); - return; - } - - /*open record file*/ - os_memset(file_name, 0, sizeof(file_name)); - if (argc > 2) - sprintf(file_name, "%d:/%s", number, argv[2]); - else - sprintf(file_name, "%d:/record.pcm", number); - - fr = f_open(&record_file, file_name, FA_OPEN_EXISTING | FA_READ); - if (fr != FR_OK) { - CLI_LOGI("open %s fail.\r\n", file_name); - return; - } - - /*init list*/ - co_list_init(&g_record_context.using_list); - co_list_init(&g_record_context.free_list); - for (index = 0; index < sizeof(record_buffer_nodes) / sizeof(record_buffer_nodes[0]); index++) { - record_buffer_nodes[index].buffer = (uint8_t *)address; - record_buffer_nodes[index].size = DAC_PLAY_NODE_SIZE; - co_list_push_back(&g_record_context.free_list, &record_buffer_nodes[index].header); - address += DAC_PLAY_NODE_SIZE; - } - - /*set mailbox callback*/ - bk_mailbox_recv_callback_register(MAILBOX_CPU0, MAILBOX_DSP, (mailbox_callback_t)usb_play_cb_hdl); - - /*send play start to dsp*/ - postfix = os_strrchr(file_name, '.'); - if (os_strcmp(postfix, ".opus") == 0) { - bk_mailbox_set_param(&mailbox, MAILBOX_CMD_AUDIO_DAC_ENABLE, 1, chann, 0); - bk_mailbox_send(&mailbox, MAILBOX_CPU0, MAILBOX_DSP, NULL); - } else if (os_strcmp(postfix, ".pcm") == 0) { - bk_mailbox_set_param(&mailbox, MAILBOX_CMD_AUDIO_DAC_ENABLE, 1, chann, 1); - bk_mailbox_send(&mailbox, MAILBOX_CPU0, MAILBOX_DSP, NULL); - } else { - CLI_LOGI("unknown file type: %s.\r\n", file_name); - } - - /*play record file*/ - while (1) { - node = (dma_buffer_node *)co_list_pop_front(&g_record_context.free_list); - if (node == NULL) { - retry_cnt++; - if (retry_cnt > 10000) { - retry_cnt = 0; - CLI_LOGI("get free list fail.\r\n"); - } - rtos_delay_milliseconds(2); - continue; - } - - if (retry_cnt) - retry_cnt = 0; - - fr = f_read(&record_file, node->buffer, DAC_PLAY_NODE_SIZE, &br); - if (fr != FR_OK) { - CLI_LOGI("read record file fail.\r\n"); - break; - } - - node->size = br; - co_list_push_back(&g_record_context.using_list, (struct co_list_hdr *)node); - bk_mailbox_set_param(&mailbox, MAILBOX_CMD_AUDIO_DAC_PCM_WRITE, ((uint32_t)node->buffer) - W_DSP_DMEM_64KB_BASE_ADDR, node->size, 0); - bk_mailbox_send(&mailbox, MAILBOX_CPU0, MAILBOX_DSP, NULL); - - if (br == 0) break; - } - - /*wait for play stop*/ - ret = rtos_get_semaphore(&usb_play_sem, BEKEN_WAIT_FOREVER); - if (ret) - CLI_LOGI("get usb play semaphore fail.\r\n"); - - /*send play stop to dsp*/ - bk_mailbox_set_param(&mailbox, MAILBOX_CMD_AUDIO_DAC_ENABLE, 0, 0, 0); - bk_mailbox_send(&mailbox, MAILBOX_CPU0, MAILBOX_DSP, NULL); - bk_mailbox_recv_callback_unregister(MAILBOX_CPU0, MAILBOX_DSP); - - /*close record file*/ - fr = f_close(&record_file); - if (fr != FR_OK) - CLI_LOGI("close %s fail.\r\n", file_name); -} - -void line_in_command(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - uint32_t enable; - - if (argc > 1) - enable = dsp_atoi(argv[1]); - else - enable = 0; - - if (enable) - sddev_control(DD_DEV_TYPE_SCTRL, CMD_SCTRL_ENALBLE_ADC_LINE_IN, NULL); - else - sddev_control(DD_DEV_TYPE_SCTRL, CMD_SCTRL_DISALBLE_ADC_LINE_IN, NULL); -} - -void adc_analog_gain_command(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - uint32_t param; - mailbox_data_t mailbox; - - if (argc < 2) { - CLI_LOGI("please input gain.\r\n"); - return; - } - param = dsp_atoi(argv[1]); - bk_mailbox_set_param(&mailbox, MAILBOX_CMD_AUDIO_ADC_ANALOG_VOLUME_SET, param & 0x7F, 0, 0); - bk_mailbox_send(&mailbox, MAILBOX_CPU0, MAILBOX_DSP, NULL); -} - -void adc_digital_gain_command(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - uint32_t param; - mailbox_data_t mailbox; - - if (argc < 2) { - CLI_LOGI("please input gain.\r\n"); - return; - } - param = dsp_atoi(argv[1]); - bk_mailbox_set_param(&mailbox, MAILBOX_CMD_AUDIO_ADC_DIGITAL_VOLUME_SET, param & 0x3F, 0, 0); - bk_mailbox_send(&mailbox, MAILBOX_CPU0, MAILBOX_DSP, NULL); -} - -void adc_sample_rate_command(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - uint32_t param; - mailbox_data_t mailbox; - - if (argc < 2) { - CLI_LOGI("please input sample rate.\r\n"); - return; - } - param = dsp_atoi(argv[1]); - sddev_control(DD_DEV_TYPE_SCTRL, CMD_SCTRL_AUDIO_PLL, ¶m); - bk_mailbox_set_param(&mailbox, MAILBOX_CMD_AUDIO_ADC_SAMPLE_RATE_SET, param, 0, 0); - bk_mailbox_send(&mailbox, MAILBOX_CPU0, MAILBOX_DSP, NULL); -} - -void dac_analog_gain_command(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - uint32_t param; - - if (argc < 2) { - CLI_LOGI("please input gain.\r\n"); - return; - } - param = dsp_atoi(argv[1]); - sddev_control(DD_DEV_TYPE_SCTRL, CMD_SCTRL_SET_DAC_VOLUME_ANALOG, ¶m); -} - -void dac_digital_gain_command(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - uint32_t param; - mailbox_data_t mailbox; - - if (argc < 2) { - CLI_LOGI("please input gain.\r\n"); - return; - } - param = dsp_atoi(argv[1]); - bk_mailbox_set_param(&mailbox, MAILBOX_CMD_AUDIO_DAC_DIGITAL_VOLUME_SET, param & 0xFFF, 0, 0); - bk_mailbox_send(&mailbox, MAILBOX_CPU0, MAILBOX_DSP, NULL); -} - -void dac_sample_rate_command(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - uint32_t param; - mailbox_data_t mailbox; - - if (argc < 2) { - CLI_LOGI("please input sample rate.\r\n"); - return; - } - param = dsp_atoi(argv[1]); - sddev_control(DD_DEV_TYPE_SCTRL, CMD_SCTRL_AUDIO_PLL, ¶m); - bk_mailbox_set_param(&mailbox, MAILBOX_CMD_AUDIO_DAC_SAMPLE_RATE_SET, param, 0, 0); - bk_mailbox_send(&mailbox, MAILBOX_CPU0, MAILBOX_DSP, NULL); -} - -const struct cli_command dsp_clis[] = { - {"mic_test", "mic_test <0|1|2|3|4>", mic_test_command}, - {"pcm_test", "pcm_test <8000|16000|44100|48000>", pcm_test_command}, - {"record2dac", "record2dac ", record2dac_command}, - {"usb_mount", "usb mount", usb_mount_command}, - {"usb_unmount", "usb unmount", usb_unmount_command}, - {"usb_ls", "usb list system", usb_ls_command}, - {"record2usb", "record2usb ", record2usb_command}, - {"usb_play", "usb play", usb_play_command}, - {"line_in", "line_in <0|1>", line_in_command}, - {"adc_analog_gain", "adc_analog_gain ", adc_analog_gain_command}, - {"adc_digital_gain", "adc_digital_gain ", adc_digital_gain_command}, - {"adc_sample_rate", "adc_sample_rate ", adc_sample_rate_command}, - {"dac_analog_gain", "dac_analog_gain ", dac_analog_gain_command}, - {"dac_digital_gain", "dac_digital_gain ", dac_digital_gain_command}, - {"dac_sample_rate", "dac_sample_rate ", dac_sample_rate_command} -}; - -void bk7271_dsp_cli_init(void) -{ - int ret; - - bk_mailbox_recv_callback_register(MAILBOX_DSP, MAILBOX_CPU0, (mailbox_callback_t)dsp_wake_up_cb); - ret = cli_register_commands(dsp_clis, sizeof(dsp_clis) / sizeof(struct cli_command)); - if (ret) - CLI_LOGI("register dsp commands fail.\r\n"); -} -#endif diff --git a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_dvp.c b/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_dvp.c deleted file mode 100755 index 2c86aec5b18b54ba6d249af64724c8140a607fd1..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_dvp.c +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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 "cli.h" - -extern void image_save_dvp(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv); - -#define DVP_CMD_CNT (sizeof(s_dvp_commands) / sizeof(struct cli_command)) -static const struct cli_command s_dvp_commands[] = { - {"dvp", "dvp init/save_image file_id/deinit", image_save_dvp}, -}; - -int cli_dvp_init(void) -{ - return cli_register_commands(s_dvp_commands, DVP_CMD_CNT); -} - diff --git a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_efuse.c b/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_efuse.c deleted file mode 100644 index 965e78a043569291bc84996302f84373e3e42b4f..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_efuse.c +++ /dev/null @@ -1,81 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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 -#include "cli.h" -#include - -static void cli_efuse_help(void) -{ - CLI_LOGI("efuse_driver init\r\n"); - CLI_LOGI("efuse_driver deinit\r\n"); - CLI_LOGI("efuse_test write [addr] [data]\r\n"); - CLI_LOGI("efuse_test read [addr]\r\n"); -} - -static void cli_efuse_driver_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - if (argc < 2) { - cli_efuse_help(); - return; - } - - if (os_strcmp(argv[1], "init") == 0) { - BK_LOG_ON_ERR(bk_efuse_driver_init()); - CLI_LOGI("efuse driver init\n"); - } else if (os_strcmp(argv[1], "deinit") == 0) { - BK_LOG_ON_ERR(bk_efuse_driver_deinit()); - CLI_LOGI("efuse driver deinit\n"); - } else { - cli_efuse_help(); - return; - } -} - -static void cli_efuse_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - if (argc < 2) { - cli_efuse_help(); - return; - } - - uint8_t addr, data; - - if (os_strcmp(argv[1], "write") == 0) { - addr = os_strtoul(argv[2], NULL, 16); - data = os_strtoul(argv[3], NULL, 16); - BK_LOG_ON_ERR(bk_efuse_write_byte(addr, data)); - CLI_LOGI("efuse write addr:0x%02x, data:0x%02x\r\n", addr, data); - } else if (os_strcmp(argv[1], "read") == 0) { - addr = os_strtoul(argv[2], NULL, 16); - data = 0; - BK_LOG_ON_ERR(bk_efuse_read_byte(addr, &data)); - CLI_LOGI("efuse read addr:0x%02x, data:0x%02x\r\n", addr, data); - } else { - cli_efuse_help(); - return; - } -} - -#define EFUSE_CMD_CNT (sizeof(s_efuse_commands) / sizeof(struct cli_command)) -static const struct cli_command s_efuse_commands[] = { - {"efuse_driver", "efuse_driver {init|deinit}", cli_efuse_driver_cmd}, - {"efuse_test", "efuse_test {write|read}", cli_efuse_cmd} -}; - -int cli_efuse_init(void) -{ - BK_LOG_ON_ERR(bk_efuse_driver_init()); - return cli_register_commands(s_efuse_commands, EFUSE_CMD_CNT); -} diff --git a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_event.c b/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_event.c deleted file mode 100644 index f48b0857b796d37e09a4aa3c39db1fc91dd38433..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_event.c +++ /dev/null @@ -1,130 +0,0 @@ -#include "cli.h" -#include -#include - -typedef struct { - uint32_t data[32]; -} test_event_data_t; - -static bk_err_t cli_event_cb_0(void *arg, event_module_t event_module, - int event_id, void *event_data) -{ - CLI_LOGI("event cb#0, event=<%d %d %x>\n", event_module, event_id, (uint32_t)event_data); - return BK_OK; -} - -static bk_err_t cli_event_cb_1(void *arg, event_module_t event_module, - int event_id, void *event_data) -{ - CLI_LOGI("event cb#1, event=<%d %d %x>\n", event_module, event_id, (uint32_t)event_data); - return BK_OK; -} - -static bk_err_t cli_event_cb_2(void *arg, event_module_t event_module, - int event_id, void *event_data) -{ - CLI_LOGI("event cb#2, event=<%d %d %x>\n", event_module, event_id, (uint32_t)event_data); - return BK_OK; -} - -static void cli_event_reg_cb(int argc, char **argv) -{ - uint32_t module_id = 0; - uint32_t event_id = 0; - uint32_t cb_arg = 0; - uint32_t cb_fn_id = 0; - - module_id = os_strtoul(argv[2], NULL, 10); - event_id = os_strtoul(argv[3], NULL, 10); - - if (argc >= 4) - cb_arg = os_strtoul(argv[4], NULL, 10); - - if (argc >= 5) - cb_fn_id = os_strtoul(argv[5], NULL, 10); - - if (cb_fn_id == 0) - BK_LOG_ON_ERR(bk_event_register_cb(module_id, event_id, cli_event_cb_0, (void *)cb_arg)); - else if (cb_fn_id == 1) - BK_LOG_ON_ERR(bk_event_register_cb(module_id, event_id, cli_event_cb_1, (void *)cb_arg)); - else if (cb_fn_id == 2) - BK_LOG_ON_ERR(bk_event_register_cb(module_id, event_id, cli_event_cb_2, (void *)cb_arg)); - else - BK_LOG_ON_ERR(bk_event_register_cb(module_id, event_id, cli_event_cb_0, (void *)cb_arg)); -} - -static void cli_event_unreg_cb(int argc, char **argv) -{ - uint32_t module_id = 0; - uint32_t event_id = 0; - uint32_t cb_fn_id = 0; - - module_id = os_strtoul(argv[2], NULL, 10); - event_id = os_strtoul(argv[3], NULL, 10); - - if (argc >= 4) - cb_fn_id = os_strtoul(argv[4], NULL, 10); - - if (cb_fn_id == 0) - BK_LOG_ON_ERR(bk_event_unregister_cb(module_id, event_id, cli_event_cb_0)); - else if (cb_fn_id == 1) - BK_LOG_ON_ERR(bk_event_unregister_cb(module_id, event_id, cli_event_cb_1)); - else if (cb_fn_id == 2) - BK_LOG_ON_ERR(bk_event_unregister_cb(module_id, event_id, cli_event_cb_2)); - else - BK_LOG_ON_ERR(bk_event_unregister_cb(module_id, event_id, cli_event_cb_0)); -} - - -#define CLI_RETURN_ON -static void cli_event_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - test_event_data_t event_data = {0}; - uint32_t module_id = 0; - uint32_t event_id = 0; - char *cmd; - - cmd = argv[1]; - - if (argc >= 3) { - module_id = os_strtoul(argv[2], NULL, 10); - event_id = os_strtoul(argv[3], NULL, 10); - } - - if (os_strcmp(cmd, "reg") == 0) { - CLI_RET_ON_INVALID_ARGC(argc, 3); - cli_event_reg_cb(argc, argv); - } else if (os_strcmp(cmd, "unreg") == 0) { - CLI_RET_ON_INVALID_ARGC(argc, 3); - cli_event_unreg_cb(argc, argv); - } else if (os_strcmp(cmd, "post") == 0) { - CLI_RET_ON_INVALID_ARGC(argc, 3); - BK_LOG_ON_ERR(bk_event_post(module_id, event_id, &event_data, - sizeof(event_data), BEKEN_NEVER_TIMEOUT)); - } else if (os_strcmp(cmd, "dump") == 0) { - CLI_RET_ON_INVALID_ARGC(argc, 1); - BK_LOG_ON_ERR(bk_event_dump()); - } else if (os_strcmp(cmd, "init") == 0) { - CLI_RET_ON_INVALID_ARGC(argc, 1); - BK_LOG_ON_ERR(bk_event_init()); - } else if (os_strcmp(cmd, "deinit") == 0) { - CLI_RET_ON_INVALID_ARGC(argc, 1); - BK_LOG_ON_ERR(bk_event_deinit()); - } else if (os_strcmp(cmd, "test") == 0) { - CLI_RET_ON_INVALID_ARGC(argc, 1); - //cli_event_test(); - } else { - CLI_LOGI("usage: event {reg|unreg|post} {mod_id} {event_id} [data]\n"); - return; - } -} - -#define EVENT_CMD_CNT (sizeof(s_event_commands) / sizeof(struct cli_command)) -static const struct cli_command s_event_commands[] = { - {"event", "event {reg|unreg|post} {mod_id} {event_id}", cli_event_cmd}, -}; - -int cli_event_init(void) -{ - return cli_register_commands(s_event_commands, EVENT_CMD_CNT); -} diff --git a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_exception.c b/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_exception.c deleted file mode 100644 index 2be93a30d29135b8615aaf5c321ac4e3527533d7..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_exception.c +++ /dev/null @@ -1,131 +0,0 @@ -#include "cli.h" -#include -#include - -#define CLI_UNDEFINE 1 -#define CLI_DABORT 2 -#define CLI_ILLEGAL 3 - -typedef void (*cli_fn_t)(uint32_t param); - -static void cli_exception_prompt(void) -{ - os_printf("usage: exception {undefine|dabort|illegal}\n"); -} - -/** - * In order to generate data abort, cli_data_abort shall be defined - * as non-static function, otherwise no data abort because of compiler - * optimization - */ -void cli_data_abort(uint32_t unaligned_addr) -{ - uint32_t *crash = (uint32_t*)unaligned_addr; - os_printf("call %s\n", __FUNCTION__); - os_printf("Generate data abort exception\n"); - *crash = 100; -} - -void cli_f3(uint32_t exception_type) -{ - char *undefine = 0; - cli_fn_t illegal = 0; - - os_printf("call %s\n", __FUNCTION__); - - switch (exception_type) { - case CLI_UNDEFINE: - os_printf("Generate undefined exception\n"); - *undefine = 0; - break; - - case CLI_DABORT: - cli_data_abort(11); - break; - - case CLI_ILLEGAL: - os_printf("Generate illegal jump exception\n"); - rtos_delay_milliseconds(100); - illegal(100); - break; - - default: - os_printf("invalid exception type\n"); - } -} - -void cli_f2(uint32_t exception_type) -{ - os_printf("call %s\n", __FUNCTION__); - cli_f3(exception_type); -} - -void cli_f1(uint32_t exception_type) -{ - os_printf("call %s\n", __FUNCTION__); - cli_f2(exception_type); -} - -#if CONFIG_PWM -static void cli_pwm0_isr(pwm_chan_t chan) -{ - char *s_undefine = 0; - os_printf("PWM isr triggered\n"); - os_printf("Generate undefined exception in isr\n"); - *s_undefine = 0; -} -#endif - -static void cli_irq(void) -{ -#if CONFIG_PWM - - pwm_init_config_t config = { - .period_cycle = 26000000, - .duty_cycle = 13000000, - .duty2_cycle = 0, - .duty3_cycle = 0, - .reserved = {0}, - }; - - BK_LOG_ON_ERR(bk_pwm_driver_init()); - BK_LOG_ON_ERR(bk_pwm_init(0, &config)); - BK_LOG_ON_ERR(bk_pwm_register_isr(0, cli_pwm0_isr)); - BK_LOG_ON_ERR(bk_pwm_start(0)); - BK_LOG_ON_ERR(bk_pwm_enable_interrupt(0)); -#else - os_printf("CONFIG_PWM UNDEFINE\n"); - -#endif -} - -static void cli_exception_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - if (argc != 2) { - cli_exception_prompt(); - return; - } - - if (os_strcmp(argv[1], "undefine") == 0) { - cli_f1(CLI_UNDEFINE); - } else if (os_strcmp(argv[1], "dabort") == 0) { - cli_f1(CLI_DABORT); - } else if (os_strcmp(argv[1], "illegal") == 0) { - cli_f1(CLI_ILLEGAL); - } else if (os_strcmp(argv[1], "irq") == 0) { - cli_irq(); - } else if (os_strcmp(argv[1], "fiq") == 0) { - } else { - cli_exception_prompt(); - } -} - -#define EXCEPTION_CMD_CNT (sizeof(s_exception_commands) / sizeof(struct cli_command)) -static const struct cli_command s_exception_commands[] = { - {"exception", "{undefine|dabort|illegal|irq|fiq}", cli_exception_cmd}, -}; - -int cli_exception_init(void) -{ - return cli_register_commands(s_exception_commands, EXCEPTION_CMD_CNT); -} diff --git a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_fatfs.c b/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_fatfs.c deleted file mode 100755 index ba59f71366f9277fb2662246e2920fef5b96ed9e..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_fatfs.c +++ /dev/null @@ -1,174 +0,0 @@ -#include "cli.h" - -#if CONFIG_FATFS - -#include "test_fatfs.h" - -static void fatfs_operate(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - uint32_t cmd; - char *disk_name[DISK_NUMBER_COUNT] = {"ram", "sdio_sd", "udisk", "flash"}; - DISK_NUMBER drv_num = DISK_NUMBER_SDIO_SD; - char file_name[64]; - char write_content[64]; - uint64_t content_len = 0; - uint32_t test_cnt = 0; - - if (argc >= 3) { - cmd = argv[1][0]; - drv_num = os_strtoul(argv[2], NULL, 10); - if(argc >= 4) - { - snprintf(&file_name[0], sizeof(file_name) - 1, argv[3]); - file_name[sizeof(file_name)-1] = 0; - - if(argc >= 5) - { - snprintf(&write_content[0], sizeof(write_content) - 1, argv[4]); - write_content[sizeof(file_name)-1] = 0; - - if(argc >= 6) - { - content_len = os_strtoul(argv[5], NULL, 10); - content_len = content_len > (sizeof(write_content) - 1) ? (sizeof(write_content) - 1) : content_len; - content_len = content_len > strlen(write_content)? strlen(write_content) : content_len; - - //re-use in autotest - test_cnt = os_strtoul(argv[5], NULL, 10); - } - } - } - - switch (cmd) { - case 'M': - test_mount(drv_num); - os_printf("mount:%s\r\n", disk_name[drv_num%DISK_NUMBER_COUNT]); - break; - case 'R': - if (argc >= 5) - content_len = os_strtoul(argv[4], NULL, 10); - else - content_len = 0x0fffffffffffffff; //read finish - test_fatfs_read(drv_num, file_name, content_len); - os_printf("read %s, len_h = %d, len_l = %d\r\n", file_name, (uint32_t)(content_len>>32), (uint32_t)content_len); - break; - case 'W': - test_fatfs_append_write(drv_num, file_name, write_content, content_len); - os_printf("append and write:%s,%s\r\n", file_name, write_content); - break; - //fatfstest D dev-num file-name start-addr dump-len - case 'D': - { - uint32_t start_addr = 0; - if(argc >= 5) - { - start_addr = os_strtoul(argv[4], NULL, 10); - } - if(argc >= 6) - { - content_len = os_strtoul(argv[5], NULL, 10); - } - test_fatfs_dump(drv_num, file_name, start_addr, content_len); - break; - } - - //fatfstest A dev-num file-name write-len test_cnt start-addr - //fatfstest A 1 autotest.txt 12487 3 - case 'A': - { - uint32_t start_addr = 0; - if(argc >= 5) - { - content_len = os_strtoul(argv[4], NULL, 10); - } - if(argc >= 6) - { - start_addr = os_strtoul(argv[5], NULL, 16); - } - test_fatfs_auto_test(drv_num, file_name, content_len, test_cnt, start_addr); - break; - } - case 'F': - test_fatfs_format(drv_num); - os_printf("format :%d\r\n", drv_num); - break; - case 'S': - scan_file_system(drv_num); - os_printf("scan \r\n"); - break; - default: - break; - } - } else - os_printf("cmd param error\r\n"); -} - -static beken_thread_t idle_fatfs_out_test_handle = NULL; -static bool s_fatfs_idle_test_stop_flag = 1; - -static void cli_fatfs_idle_out_test(void) -{ - char *file_name = "1.txt"; - - test_mount(1); - rtos_delay_milliseconds(10); - test_fatfs_format(1); - - while (1) { - rtos_delay_milliseconds(50); - if(s_fatfs_idle_test_stop_flag) - break; - else - test_fatfs_auto_test(1, file_name, 12487, 1, 0); - } - - rtos_delete_thread(&idle_fatfs_out_test_handle); - -} - -static void fatfs_idle_test(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - if (argc < 2) { - return; - } - - if (os_strcmp(argv[1], "start") == 0) { - if (!idle_fatfs_out_test_handle && s_fatfs_idle_test_stop_flag){ - CLI_LOGI("fatfs_idle_test START!\n"); - s_fatfs_idle_test_stop_flag = 0; - if(rtos_create_thread(&idle_fatfs_out_test_handle, 8, "idle_fatfs_out", - (beken_thread_function_t) cli_fatfs_idle_out_test, 2048, 0)) { - CLI_LOGI("fatfs_idle_test rtos_create_thread FAILED!\n"); - return; - } - } else - CLI_LOGI("fatfs idle test WORKING!\n"); - - } else if (os_strcmp(argv[1], "stop") == 0) { - if (idle_fatfs_out_test_handle && !s_fatfs_idle_test_stop_flag) { - s_fatfs_idle_test_stop_flag = 1; - CLI_LOGI("fatfs_idle_test STOP! Please clean FLAG!\n"); - } else - CLI_LOGI("PLEASE start fatfs idle test!\n"); - - } else if (os_strcmp(argv[1], "clean") == 0) { - if (idle_fatfs_out_test_handle && s_fatfs_idle_test_stop_flag) - idle_fatfs_out_test_handle = NULL; - else - CLI_LOGI("PLEASE start->stop->clean, check thread status!\n"); - } -} - - -#define FATFS_CMD_CNT (sizeof(s_fatfs_commands) / sizeof(struct cli_command)) -static const struct cli_command s_fatfs_commands[] = { - {"fatfstest", "fatfstest ", fatfs_operate}, - {"fatfs_idle_test", "fatfs_idle_test {start|stop|clean}", fatfs_idle_test}, -}; - -int cli_fatfs_init(void) -{ - return cli_register_commands(s_fatfs_commands, FATFS_CMD_CNT); -} - -#endif diff --git a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_fft.c b/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_fft.c deleted file mode 100755 index 36c84e720a0a52c0f6cbeeffa55813064c16bc5e..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_fft.c +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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 "cli.h" - -extern void cli_fft_fft_test_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv); -extern void cli_fft_ifft_test_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv); - -#define FFT_CMD_CNT (sizeof(s_fft_commands) / sizeof(struct cli_command)) -static const struct cli_command s_fft_commands[] = { - {"fft_fft_test", "fft_fft_test {start|stop}", cli_fft_fft_test_cmd}, - {"fft_ifft_test", "fft_ifft_test {start|stop}", cli_fft_ifft_test_cmd}, -}; - -int cli_fft_init(void) -{ - return cli_register_commands(s_fft_commands, FFT_CMD_CNT); -} - diff --git a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_flash.c b/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_flash.c deleted file mode 100644 index 0367b17febf37aa9055708fb6d0a207458cf4dcf..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_flash.c +++ /dev/null @@ -1,107 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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 -#include -#include "cli.h" -#include "flash_driver.h" - -static void cli_flash_help(void) -{ - CLI_LOGI("flash driver init\n"); - CLI_LOGI("flash_driver deinit\n"); - CLI_LOGI("flash {erase|write|read} [start_addr] [len]\n"); - CLI_LOGI("flash_partition show\n"); -} - -static void cli_flash_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - if (argc < 2) { - cli_flash_help(); - return; - } - - uint32_t start_addr = os_strtoul(argv[2], NULL, 16); - uint32_t len = os_strtoul(argv[3], NULL, 10); - - if (os_strcmp(argv[1], "erase") == 0) { - bk_flash_set_protect_type(FLASH_PROTECT_NONE); - for (uint32_t addr = start_addr; addr < (start_addr + len); addr += FLASH_SECTOR_SIZE) { - bk_flash_erase_sector(addr); - } - bk_flash_set_protect_type(FLASH_UNPROTECT_LAST_BLOCK); - } else if (os_strcmp(argv[1], "read") == 0) { - uint8_t buf[FLASH_PAGE_SIZE] = {0}; - for (uint32_t addr = start_addr; addr < (start_addr + len); addr += FLASH_PAGE_SIZE) { - os_memset(buf, 0, FLASH_PAGE_SIZE); - bk_flash_read_bytes(addr, buf, FLASH_PAGE_SIZE); - CLI_LOGI("flash read addr:%x\r\n", addr); - - CLI_LOGI("dump read flash data:\r\n"); - for (uint32_t i = 0; i < 16; i++) { - for (uint32_t j = 0; j < 16; j++) { - os_printf("%02x ", buf[i * 16 + j]); - } - os_printf("\r\n"); - } - } - } else if (os_strcmp(argv[1], "write") == 0) { - uint8_t buf[FLASH_PAGE_SIZE] = {0}; - for (uint32_t i = 0; i < FLASH_PAGE_SIZE; i++) { - buf[i] = i; - } - bk_flash_set_protect_type(FLASH_PROTECT_NONE); - for (uint32_t addr = start_addr; addr < (start_addr + len); addr += FLASH_PAGE_SIZE) { - bk_flash_write_bytes(addr, buf, FLASH_PAGE_SIZE); - } - bk_flash_set_protect_type(FLASH_UNPROTECT_LAST_BLOCK); - } else if (os_strcmp(argv[1], "get_id") == 0) { - uint32_t flash_id = bk_flash_get_id(); - CLI_LOGI("flash_id:%x\r\n", flash_id); - } else { - cli_flash_help(); - } -} - -static void cli_flash_partition_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - bk_logic_partition_t *partition; - - if (os_strcmp(argv[1], "show") == 0) { - for (bk_partition_t par= BK_PARTITION_BOOTLOADER; par <= BK_PARTITION_MAX; par++) { - partition = bk_flash_partition_get_info(par); - if (partition == NULL) - continue; - - CLI_LOGI("%4d | %11s | Dev:%d | 0x%08lx | 0x%08lx |\r\n", par, - partition->partition_description, partition->partition_owner, - partition->partition_start_addr, partition->partition_length); - } - } else { - cli_flash_help(); - } -} - -#define FLASH_CMD_CNT (sizeof(s_flash_commands) / sizeof(struct cli_command)) -static const struct cli_command s_flash_commands[] = { - {"flash", "flash {erase|read|write} [start_addr] [len]", cli_flash_cmd}, - {"flash_partition", "flash_partition {show}", cli_flash_partition_cmd}, -}; - -int cli_flash_init(void) -{ - BK_LOG_ON_ERR(bk_flash_driver_init()); - return cli_register_commands(s_flash_commands, FLASH_CMD_CNT); -} - diff --git a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_flash_test.c b/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_flash_test.c deleted file mode 100644 index 67cc7f8a2ef190ff5e1106b958f58b10cecffb57..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_flash_test.c +++ /dev/null @@ -1,493 +0,0 @@ -#include -#include "cli.h" -#include "driver/flash.h" -#include -#include "sys_driver.h" -#include "flash_bypass.h" -#include "flash.h" -#include - -#define TICK_PER_US 26 -beken_thread_t idle_read_flash_handle = NULL; -beken_thread_t idle_read_psram_handle = NULL; -extern void delay_ms(UINT32 ms_count); - -static bk_err_t test_flash_write(volatile uint32_t start_addr, uint32_t len) -{ - uint32_t i; - u8 buf[256]; - uint32_t addr = start_addr; - uint32_t length = len; - uint32_t tmp = addr + length; - - for (i = 0; i < 256; i++) - buf[i] = i; - - for (; addr < tmp; addr += 256) { - os_printf("write addr(size:256):%d\r\n", addr); - bk_flash_write_bytes(addr, (uint8_t *)buf, 256); - } - - return kNoErr; -} - -static bk_err_t test_flash_erase(volatile uint32_t start_addr, uint32_t len) -{ - uint32_t addr = start_addr; - uint32_t length = len; - uint32_t tmp = addr + length; - - for (; addr < tmp; addr += 0x1000) { - os_printf("erase addr:%d\r\n", addr); - bk_flash_erase_sector(addr); - } - return kNoErr; -} - -static bk_err_t test_flash_read(volatile uint32_t start_addr, uint32_t len) -{ - uint32_t i, j, tmp; - u8 buf[256]; - uint32_t addr = start_addr; - uint32_t length = len; - tmp = addr + length; - - for (; addr < tmp; addr += 256) { - os_memset(buf, 0, 256); - bk_flash_read_bytes(addr, (uint8_t *)buf, 256); - os_printf("read addr:%x\r\n", addr); - for (i = 0; i < 16; i++) { - for (j = 0; j < 16; j++) - os_printf("%02x ", buf[i * 16 + j]); - os_printf("\r\n"); - } - } - - return kNoErr; -} - -static bk_err_t test_flash_read_without_print(volatile uint32_t start_addr, uint32_t len) -{ - uint32_t tmp; - u8 buf[256]; - uint32_t addr = start_addr; - uint32_t length = len; - tmp = addr + length; - - for (; addr < tmp; addr += 256) { - os_memset(buf, 0, 256); - bk_flash_read_bytes(addr, (uint8_t *)buf, 256); - } - - return kNoErr; -} - -static bk_err_t test_flash_read_time(volatile uint32_t start_addr, uint32_t len) -{ - UINT32 time_start, time_end; - uint32_t tmp; - u8 buf[256]; - uint32_t addr = start_addr; - uint32_t length = len; - - tmp = addr + length; - beken_time_get_time((beken_time_t *)&time_start); - os_printf("read time start:%d\r\n", time_start); - - for (; addr < tmp; addr += 256) { - os_memset(buf, 0, 256); - bk_flash_read_bytes(addr, (uint8_t *)buf, 256); - } - beken_time_get_time((beken_time_t *)&time_end); - os_printf("read time end:%d\r\n", time_end); - os_printf("cost time:%d\r\n", time_end - time_start); - - return kNoErr; -} - -#if (CONFIG_SYSTEM_CTRL) -static bk_err_t test_flash_count_time(volatile uint32_t start_addr, uint32_t len, uint32_t test_times) -{ - UINT32 time_start, time_end; - uint32_t tmp; - u8 buf[256]; - uint32_t addr = start_addr; - uint32_t length = len; - extern u64 riscv_get_mtimer(void); - uint64_t start_tick, end_tick, tick_cnt = 0; - - tmp = addr + length; - bk_flash_set_protect_type(FLASH_PROTECT_NONE); - - beken_time_get_time((beken_time_t *)&time_start); - os_printf("----- FLASH COUNT TIME TEST BEGIN: start time:%d ms -----\r\n", time_start); - os_printf("===============================\r\n"); - - start_tick = riscv_get_mtimer(); - for (addr = start_addr; addr < tmp; addr += 256) { - os_memset(buf, 0, 256); - bk_flash_read_bytes(addr, (uint8_t *)buf, 256); - } - end_tick = riscv_get_mtimer(); - tick_cnt = end_tick - start_tick; - os_printf("[read 1 time] >>>>> cost tick time: %d us.\r\n", (uint32_t) (tick_cnt / TICK_PER_US)); - os_printf("===============================\r\n"); - - - start_tick = riscv_get_mtimer(); - for (int i = 0; i < test_times; i++ ) { - for (addr = start_addr; addr < tmp; addr += 256) { - os_memset(buf, 0, 256); - bk_flash_read_bytes(addr, (uint8_t *)buf, 256); - } - } - end_tick = riscv_get_mtimer(); - tick_cnt = end_tick - start_tick; - os_printf("[read %d time] >>>>> average tick time: %d us.\r\n", test_times, (uint32_t) (tick_cnt / TICK_PER_US / test_times)); - os_printf("===============================\r\n"); - - - start_tick = riscv_get_mtimer(); - for (addr = start_addr; addr < tmp; addr += 0x1000) { - os_printf("erase addr:%d\r\n", addr); - bk_flash_erase_sector(addr); - } - end_tick = riscv_get_mtimer(); - tick_cnt = end_tick - start_tick; - os_printf("[erase 1 time] >>>>> cost tick time: %d us.\r\n", (uint32_t) (tick_cnt / TICK_PER_US)); - os_printf("===============================\r\n"); - - - start_tick = riscv_get_mtimer(); - for (int i = 0; i < test_times; i++ ) { - for (addr = start_addr; addr < tmp; addr += 0x1000) { - bk_flash_erase_sector(addr); - } - } - end_tick = riscv_get_mtimer(); - tick_cnt = end_tick - start_tick; - os_printf("[erase %d time] >>>>> average tick time: %d us.\r\n", test_times, (uint32_t) (tick_cnt / TICK_PER_US / test_times)); - os_printf("===============================\r\n"); - - - start_tick = riscv_get_mtimer(); - for (int i = 0; i < 256; i++) - buf[i] = i; - - for (addr = start_addr; addr < tmp; addr += 256) { - bk_flash_write_bytes(addr, (uint8_t *)buf, 256); - } - end_tick = riscv_get_mtimer(); - tick_cnt = end_tick - start_tick; - os_printf("[write 1 time] >>>>> cost tick time: %d us.\r\n", (uint32_t) (tick_cnt / TICK_PER_US)); - os_printf("===============================\r\n"); - - - start_tick = riscv_get_mtimer(); - for (int i = 0; i < test_times; i++ ) { - for (addr = start_addr; addr < tmp; addr += 256) { - bk_flash_write_bytes(addr, (uint8_t *)buf, 256); - } - } - end_tick = riscv_get_mtimer(); - tick_cnt = end_tick - start_tick; - os_printf("[write %d time] >>>>> average tick time: %d us.\r\n", test_times, (uint32_t) (tick_cnt / TICK_PER_US / test_times)); - os_printf("===============================\r\n"); - - - start_tick = riscv_get_mtimer(); - bk_flash_set_protect_type(FLASH_PROTECT_NONE); - end_tick = riscv_get_mtimer(); - tick_cnt = end_tick - start_tick; - os_printf("[enable security 1 time] >>>>> cost tick time: %d us.\r\n", (uint32_t)(tick_cnt / TICK_PER_US)); - os_printf("===============================\r\n"); - - - start_tick = riscv_get_mtimer(); - for (int i = 0; i < test_times; i++ ) { - bk_flash_set_protect_type(FLASH_PROTECT_NONE); - } - end_tick = riscv_get_mtimer(); - tick_cnt = end_tick - start_tick; - os_printf("[enable security %d time] >>>>> average tick time: %d us.\r\n", test_times, (uint32_t)(tick_cnt / TICK_PER_US / test_times)); - os_printf("===============================\r\n"); - - - start_tick = riscv_get_mtimer(); - bk_flash_set_protect_type(FLASH_PROTECT_NONE); - bk_flash_set_protect_type(FLASH_UNPROTECT_LAST_BLOCK); - end_tick = riscv_get_mtimer(); - tick_cnt = end_tick - start_tick; - os_printf("[en/dis security 1 time] >>>>> cost tick time: %d us.\r\n", (uint32_t) ((tick_cnt / TICK_PER_US))); - os_printf("===============================\r\n"); - - - beken_time_get_time((beken_time_t *)&time_end); - os_printf("----- FLASH COUNT TIME TEST END: end time:%d ms -----\r\n", time_end); - os_printf("----- OVERALL TEST TIME:%d ms -----\r\n", time_end - time_start); - - bk_flash_set_protect_type(FLASH_UNPROTECT_LAST_BLOCK); - return kNoErr; -} -#endif - -static void test_idle_read_flash(void *arg) { - while (1) { - test_flash_read_without_print(0x1000, 1000); - test_flash_read_without_print(0x100000, 1000); - test_flash_read_without_print(0x200000, 1000); - test_flash_read_without_print(0x300000, 0x1000); - } - rtos_delete_thread(&idle_read_flash_handle); -} - -#define write_data(addr,val) *((volatile unsigned long *)(addr)) = val -#define read_data(addr,val) val = *((volatile unsigned long *)(addr)) -#define get_addr_data(addr) *((volatile unsigned long *)(addr)) - -#if (CONFIG_SYSTEM_CTRL && CONFIG_PSRAM) -static void test_idle_read_psram(void *arg) { - uint32_t i,val = 0; - uint32_t s0 = 0; - uint32_t s1 = 0; - uint32_t s2 = 0; - uint32_t s3 = 0; - - os_printf("enter test_idle_read_psram\r\n"); - - bk_psram_init(); - - while (1) { - for(i=0;i<1024;i++){ - write_data((0x60000000+i*0x4),0x11+i); - write_data((0x60001000+i*0x4),0x22+i); - write_data((0x60002000+i*0x4),0x33+i); - write_data((0x60003000+i*0x4),0x44+i); - } - for(i=0;i<1024;i++){ - write_data((0x60004000+i*0x4),0x55+i); - write_data((0x60005000+i*0x4),0x66+i); - write_data((0x60006000+i*0x4),0x77+i); - write_data((0x60007000+i*0x4),0x88+i); - } - for(i=0;i<4*1024;i++){ - val = get_addr_data(0x60000000+i*0x4); - s0 += val; - } - for(i=0;i<4*1024;i++){ - val = get_addr_data(0x60004000+i*0x4); - s1 += val; - } - for(i=0;i<4*1024;i++){ - val = get_addr_data(0x60000000+i*0x4); - s2 += val; - } - for(i=0;i<4*1024;i++){ - val = get_addr_data(0x60004000+i*0x4); - s3 += val; - } - - } - rtos_delete_thread(&idle_read_psram_handle); -} -#endif -static void flash_command_test(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - char cmd = 0; - uint32_t len = 0; - uint32_t addr = 0; -#if (CONFIG_SYSTEM_CTRL) - if (os_strcmp(argv[1], "config") == 0) { - uint32_t flash_src_clk = os_strtoul(argv[2], NULL, 10); - uint32_t flash_div_clk = os_strtoul(argv[3], NULL, 10); - uint32_t flash_line_mode = os_strtoul(argv[4], NULL, 10); - - if (FLASH_CLK_XTAL == flash_src_clk) { - sys_drv_flash_cksel(flash_src_clk); - } - - if((FLASH_CLK_XTAL != sys_drv_flash_get_clk_sel()) && (0 == flash_div_clk)) { - os_printf("Config fail. Please set src clk as 26M, or set div larger than 0 firstly.\n"); - return; - } - - sys_drv_flash_set_clk_div(flash_div_clk); - sys_drv_flash_cksel(flash_src_clk); - bk_flash_set_line_mode(flash_line_mode); - os_printf("flash_src_clk = %u. [0 -> 26M; 1->98M; 2-> 120M]\n", flash_src_clk); - os_printf("flash_div_clk = %u. \n", flash_div_clk); - os_printf("flash_line_mode = %u. \n", flash_line_mode); - - return; - } - if (os_strcmp(argv[1], "qe") == 0) { - uint32_t param = 0; - uint32_t quad_enable = os_strtoul(argv[2], NULL, 10); - uint32_t delay_cycle1 = os_strtoul(argv[3], NULL, 10); - uint32_t delay_cycle2 = os_strtoul(argv[4], NULL, 10); - - for(int i = 0; i< 20; i++) { - bk_flash_set_line_mode(2); - flash_bypass_quad_test(quad_enable, delay_cycle1, delay_cycle2); - while (REG_READ(REG_FLASH_OPERATE_SW) & BUSY_SW); - param = bk_flash_read_status_reg(); - if (quad_enable) { - if(param & 0x200){ - break; - } else { - os_printf("retry quad test, i = %d, flash status: 0x%x.\n", i, param); - } - } else { - if(param & 0x200){ - os_printf("retry quad test, i = %d, flash status: 0x%x.\n", i, param); - } else { - break; - } - } - } - - if (quad_enable) { - if(param & 0x200){ - os_printf("flash quad enable success, flash status: 0x%x.\n", param); - } else { - os_printf("flash quad enable fail, flash status: 0x%x.\n", param); - } - } else { - if(param & 0x200){ - os_printf("flash quad disable fail, flash status: 0x%x.\n", param); - } else { - os_printf("flash quad disable success, flash status: 0x%x.\n", param); - } - } - return; - } -#endif - if (os_strcmp(argv[1], "idle_read_start") == 0) { - uint32_t task_prio = os_strtoul(argv[2], NULL, 10); - os_printf("idle_read_flash task start: task_prio = %u.\n", task_prio); - rtos_create_thread(&idle_read_flash_handle, task_prio, - "idle_read_flash", - (beken_thread_function_t) test_idle_read_flash, - CONFIG_APP_MAIN_TASK_STACK_SIZE, - (beken_thread_arg_t)0); - - return; - } else if (os_strcmp(argv[1], "idle_read_stop") == 0) { - if (idle_read_flash_handle) { - rtos_delete_thread(&idle_read_flash_handle); - idle_read_flash_handle = NULL; - os_printf("idle_read_flash task stop\n"); - } - return; - } - -#if (CONFIG_SYSTEM_CTRL && CONFIG_PSRAM) - if (os_strcmp(argv[1], "idle_read_psram_start") == 0) { - uint32_t task_prio = os_strtoul(argv[2], NULL, 10); - os_printf("idle_read_psram task start: task_prio = %u.\n", task_prio); - rtos_create_thread(&idle_read_psram_handle, task_prio, - "idle_read_psram", - (beken_thread_function_t) test_idle_read_psram, - CONFIG_APP_MAIN_TASK_STACK_SIZE, - (beken_thread_arg_t)0); - - return; - } else if (os_strcmp(argv[1], "idle_read_psram_stop") == 0) { - if (idle_read_psram_handle) { - rtos_delete_thread(&idle_read_psram_handle); - idle_read_psram_handle = NULL; - os_printf("idle_read_psram task stop\n"); - } - return; - } -#endif - - if (os_strcmp(argv[1], "U") == 0) { - bk_flash_set_protect_type(FLASH_PROTECT_NONE); - return; - } else if (os_strcmp(argv[1], "P") == 0) { - bk_flash_set_protect_type(FLASH_UNPROTECT_LAST_BLOCK); - return; - } else if (os_strcmp(argv[1], "RSR") == 0) { - uint16_t sts_val = bk_flash_read_status_reg(); - os_printf("read sts_val = 0x%x\n", sts_val); - return; - } else if (os_strcmp(argv[1], "WSR") == 0) { - uint16_t sts_val = os_strtoul(argv[2], NULL, 16); - bk_flash_write_status_reg(sts_val); - return; - } else if (os_strcmp(argv[1], "C") == 0) { -#if (CONFIG_SYSTEM_CTRL) - addr = atoi(argv[2]); - len = atoi(argv[3]); - uint32_t test_times = os_strtoul(argv[4], NULL, 10); - test_flash_count_time(addr, len, test_times); -#endif - return; - } - - if (argc == 4) { - cmd = argv[1][0]; - addr = atoi(argv[2]); - len = atoi(argv[3]); - - switch (cmd) { - case 'E': - bk_flash_set_protect_type(FLASH_PROTECT_NONE); - test_flash_erase(addr, len); - bk_flash_set_protect_type(FLASH_UNPROTECT_LAST_BLOCK); - break; - - case 'R': - test_flash_read(addr, len); - break; - case 'W': - bk_flash_set_protect_type(FLASH_PROTECT_NONE); - test_flash_write(addr, len); - bk_flash_set_protect_type(FLASH_UNPROTECT_LAST_BLOCK); - break; - //to check whether protection mechanism can work - case 'N': - test_flash_erase(addr, len); - break; - case 'M': - test_flash_write(addr, len); - break; - case 'T': - test_flash_read_time(addr, len); - break; - default: - break; - } - } else - os_printf("FLASH \r\n"); -} - - -static void partShow_Command(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - bk_partition_t i; - bk_logic_partition_t *partition; - - for (i = BK_PARTITION_BOOTLOADER; i <= BK_PARTITION_MAX; i++) { - partition = bk_flash_partition_get_info(i); - if (partition == NULL) - continue; - - os_printf("%4d | %11s | Dev:%d | 0x%08lx | 0x%08lx |\r\n", i, - partition->partition_description, partition->partition_owner, - partition->partition_start_addr, partition->partition_length); - }; - -} - -#define FLASH_CMD_CNT (sizeof(s_flash_commands) / sizeof(struct cli_command)) -static const struct cli_command s_flash_commands[] = { - {"fmap_test", "flash_test memory map", partShow_Command}, - {"flash_test", "flash_test ", flash_command_test}, -}; - -int cli_flash_test_init(void) -{ - return cli_register_commands(s_flash_commands, FLASH_CMD_CNT); -} diff --git a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_g711.c b/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_g711.c deleted file mode 100755 index d192fe5d9b81f6750b1b5231a406c3278dfce134..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_g711.c +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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 "cli.h" - -extern void cli_g711_encoder_test_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv); -extern void cli_g711_decoder_test_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv); - -#define G711_CMD_CNT (sizeof(s_g711_commands) / sizeof(struct cli_command)) -static const struct cli_command s_g711_commands[] = { - {"g711_encoder_test", "g711_encoder_test", cli_g711_encoder_test_cmd}, - {"g711_decoder_test", "g711_decoder_test", cli_g711_decoder_test_cmd}, -}; - -int cli_g711_init(void) -{ - return cli_register_commands(s_g711_commands, G711_CMD_CNT); -} - diff --git a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_gpio.c b/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_gpio.c deleted file mode 100644 index 3841f0ee8735780a9accd9a0bbfcb6b339a1543c..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_gpio.c +++ /dev/null @@ -1,365 +0,0 @@ -#include -#include "cli.h" -#include "bk_gpio.h" -#include -#include -#include "gpio_driver.h" - -static void cli_gpio_help(void) -{ - CLI_LOGI("gpio_driver [init/deinit] \r\n"); - - CLI_LOGI("gpio [set_config/input_pulldown/input_pullup////] only in set_sonfig:[io_mode] [pull mode] \r\n"); - CLI_LOGI("gpio [output/input] [gpio_pin] [pullup/pulldown] \r\n"); - CLI_LOGI("gpio [output_high/output_low/input_get] [gpio_pin] \r\n"); - CLI_LOGI("gpio_map [sdio_map/spi_map] [mode]\r\n"); - CLI_LOGI("gpio_int [index] [inttype/start/stop] [low/high_level/rising/falling edge]\r\n"); -#if CONFIG_GPIO_DYNAMIC_WAKEUP_SUPPORT - CLI_LOGI("gpio_wake [index][low/high_level/rising/falling edge][enable/disable wakeup]\r\n"); - CLI_LOGI("gpio_low_power [simulate][param]\r\n"); -#endif -#if CONFIG_GPIO_SIMULATE_UART_WRITE - CLI_LOGI("gpio_uart_write [index][div(baud_rate=1Mbps/(1+div))][string(len < 8)]\r\n"); -#endif -} - -static void cli_gpio_driver_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - if (argc < 2) - { - cli_gpio_help(); - return; - } - - if (os_strcmp(argv[1], "init") == 0) { - BK_LOG_ON_ERR(bk_gpio_driver_init()); - CLI_LOGI("gpio init\n"); - } else if(os_strcmp(argv[1], "deinit") == 0) { - BK_LOG_ON_ERR(bk_gpio_driver_deinit()); - CLI_LOGI("gpio deinit\n"); - } else { - cli_gpio_help(); - return; - } -} - - - -static void cli_gpio_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - if (argc < 2) { - cli_gpio_help(); - return; - } - - if (os_strcmp(argv[1], "set_config") == 0) { - gpio_id_t id; - id = os_strtoul(argv[2], NULL, 10); - - gpio_config_t mode; - - mode.io_mode = os_strtoul(argv[3], NULL, 10); - mode.pull_mode = os_strtoul(argv[4], NULL, 10); - BK_LOG_ON_ERR(bk_gpio_set_config(id, &mode)); - - CLI_LOGI("gpio io(output/disable/input): %x , pull(disable/down/up) : %x\n", mode.io_mode, mode.pull_mode); - - } else if (os_strcmp(argv[1], "output") == 0) { - gpio_id_t id; - - id = os_strtoul(argv[2], NULL, 10); - - BK_LOG_ON_ERR(bk_gpio_disable_input(id)); - BK_LOG_ON_ERR(bk_gpio_enable_output(id)); - - if (os_strcmp(argv[3], "pull_up") == 0) { - BK_LOG_ON_ERR(bk_gpio_enable_pull(id)); - BK_LOG_ON_ERR(bk_gpio_pull_up(id)); - }else if (os_strcmp(argv[3], "pull_down") == 0) { - BK_LOG_ON_ERR(bk_gpio_enable_pull(id)); - BK_LOG_ON_ERR(bk_gpio_pull_down(id)); - } else { - BK_LOG_ON_ERR(bk_gpio_disable_pull(id)); - } - - CLI_LOGI("gpio output test: %x \n", id); - - }else if (os_strcmp(argv[1], "input") == 0) { - gpio_id_t id; - - id = os_strtoul(argv[2], NULL, 10); - - BK_LOG_ON_ERR(bk_gpio_disable_output(id)); - BK_LOG_ON_ERR(bk_gpio_enable_input(id)); - - if (os_strcmp(argv[3], "pull_up") == 0) { - BK_LOG_ON_ERR(bk_gpio_enable_pull(id)); - BK_LOG_ON_ERR(bk_gpio_pull_up(id)); - }else if (os_strcmp(argv[3], "pull_down") == 0) { - BK_LOG_ON_ERR(bk_gpio_enable_pull(id)); - BK_LOG_ON_ERR(bk_gpio_pull_down(id)); - } else { - BK_LOG_ON_ERR(bk_gpio_disable_pull(id)); - } - - CLI_LOGI("gpio input test: %d \n", id); - - }else if (os_strcmp(argv[1], "output_high") == 0) { - gpio_id_t id; - - id = os_strtoul(argv[2], NULL, 10); - - // must set gpio mode before gpio output test - BK_LOG_ON_ERR(bk_gpio_set_output_high(id)); - - CLI_LOGI("gpio output hgih\n"); - }else if (os_strcmp(argv[1], "output_low") == 0) { - gpio_id_t id; - - id = os_strtoul(argv[2], NULL, 10); - - // must set gpio mode before gpio output test - BK_LOG_ON_ERR(bk_gpio_set_output_low(id)); - - CLI_LOGI("gpio output low\n"); - } else if (os_strcmp(argv[1], "input_get") == 0) { - gpio_id_t id; - - id = os_strtoul(argv[2], NULL, 10); - - // must set gpio mode before gpio output test - uint8_t input_value = bk_gpio_get_input(id); - - CLI_LOGI("gpio input value is %x\r\n", input_value); - } else { - cli_gpio_help(); - return; - } -} - - -static void cli_gpio_map_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - if (argc < 2) { - cli_gpio_help(); - return; - } - uint8 mode = 0; - - if (os_strcmp(argv[1], "devs") == 0) { - gpio_id_t id = 0; - - id = os_strtoul(argv[2], NULL, 10); - mode = os_strtoul(argv[3], NULL, 10); - - gpio_dev_unmap(id); - gpio_dev_map(id, mode); - } else if (os_strcmp(argv[1], "jtag_map") == 0) { - gpio_id_t id = 0; - - id = os_strtoul(argv[2], NULL, 10); - gpio_dev_unmap(id); - - if (os_strcmp(argv[3], "tck") == 0) { - CLI_LOGI("gpio set JTAG_TCK\r\n"); - gpio_dev_map(id, GPIO_DEV_JTAG_TCK); - } else if(os_strcmp(argv[3], "tms") == 0) { - CLI_LOGI("gpio set JTAG_TMS\r\n"); - gpio_dev_map(id, GPIO_DEV_JTAG_TMS); - } else if(os_strcmp(argv[3], "tdi") == 0) { - CLI_LOGI("gpio set JTAG_TDI\r\n"); - gpio_dev_map(id, GPIO_DEV_JTAG_TDI); - } else if(os_strcmp(argv[3], "tdo") == 0) { - CLI_LOGI("gpio set JTAG_TDO\r\n"); - gpio_dev_map(id, GPIO_DEV_JTAG_TDO); - } else { - cli_gpio_help(); - return; - } - } -#if ((CONFIG_SOC_BK7271) ||(CONFIG_SOC_BK7251) ) - else if (os_strcmp(argv[1], "sdio_map") == 0) { - - mode = os_strtoul(argv[2], NULL, 10); - BK_LOG_ON_ERR(gpio_sdio_sel(mode)); - } else if (os_strcmp(argv[1], "spi_map") == 0){ - mode = os_strtoul(argv[2], NULL, 10); - BK_LOG_ON_ERR(gpio_spi_sel(mode)); - } -#if (CONFIG_SOC_BK7271) - else if (os_strcmp(argv[1], "uart2_map") == 0) { - - mode = os_strtoul(argv[2], NULL, 10); - BK_LOG_ON_ERR(gpio_uart2_sel(mode)); - } else if (os_strcmp(argv[1], "pwms_map") == 0){ - mode = os_strtoul(argv[2], NULL, 10); - uint32 channel = os_strtoul(argv[3], NULL, 10); - BK_LOG_ON_ERR(gpio_pwms_sel(channel,mode)); - } - -#endif -#endif - else { - cli_gpio_help(); - return; - } -} - -#if CONFIG_GPIO_DYNAMIC_WAKEUP_SUPPORT -static void cli_gpio_set_wake_source_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - if (argc < 4) { - cli_gpio_help(); - return; - } - - gpio_id_t id = 0; - uint32_t mode = 0; - - id = os_strtoul(argv[2], NULL, 10); - mode = os_strtoul(argv[3], NULL, 10); - - if(os_strcmp(argv[1], "register") == 0) - bk_gpio_register_wakeup_source(id, mode); - else if(os_strcmp(argv[1], "unregister") == 0) - bk_gpio_unregister_wakeup_source(id); - else if(os_strcmp(argv[1], "get_id") == 0) - CLI_LOGI("GET wakeup gpio id: %d\r\n", bk_gpio_get_wakeup_gpio_id()); - else - return cli_gpio_help(); -} - -static void cli_gpio_simulate_low_power_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - if (argc < 3) { - cli_gpio_help(); - return; - } - - uint32_t param = 0; - - param = os_strtoul(argv[2], NULL, 10); - - if(os_strcmp(argv[1], "simulate") == 0) - { - uint32_t int_level = 0; - - //if param == 0x534b4950 == "SKIP" == 1,397,442,896 - //means not switch GPIO to low power status just do save and restore - CLI_LOGD("mode:%d,0x%x\n", param, param); - int_level = rtos_disable_int(); - gpio_enter_low_power((void *)param); - rtos_enable_int(int_level); - - //TODO:simulate sytem entry low voltage. - - int_level = rtos_disable_int(); - gpio_exit_low_power((void *)param); - rtos_enable_int(int_level); - return; - } - else - return cli_gpio_help(); -} -#endif - - -#if CONFIG_GPIO_SIMULATE_UART_WRITE -static void cli_gpio_simulate_uart_write_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - uint32_t id = 0, div = 0; - uint32_t len = 8; - - if (argc < 4) { - cli_gpio_help(); - return; - } - - id = os_strtoul(argv[1], NULL, 10); - div = os_strtoul(argv[2], NULL, 10); - if(len > strlen(argv[3])) - len = strlen(argv[3]); - gpio_simulate_uart_write((uint8_t *)argv[3], len, id, div); -} -#endif - - -static void cli_gpio_int_isr(gpio_id_t id) -{ - CLI_LOGI("gpio isr index:%d\n",id); -} - -static void cli_gpio_int_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - uint32_t id; - gpio_config_t cfg; - - cfg.io_mode =GPIO_INPUT_ENABLE; - - if (argc < 2) { - cli_gpio_help(); - return; - } - - id = os_strtoul(argv[1], NULL, 10); - - if (os_strcmp(argv[2], "intype") == 0) { - CLI_RET_ON_INVALID_ARGC(argc, 4); - gpio_int_type_t int_type = 0; - if (os_strcmp(argv[3], "low_level") == 0) { - int_type = GPIO_INT_TYPE_LOW_LEVEL; - cfg.pull_mode = GPIO_PULL_UP_EN; - bk_gpio_set_config(id, &cfg); - } else if (os_strcmp(argv[3], "high_level") == 0) { - int_type = GPIO_INT_TYPE_HIGH_LEVEL; - cfg.pull_mode = GPIO_PULL_DOWN_EN; - bk_gpio_set_config(id, &cfg); - }else if (os_strcmp(argv[3], "rising_edge") == 0) { - int_type = GPIO_INT_TYPE_RISING_EDGE; - cfg.pull_mode = GPIO_PULL_DOWN_EN; - bk_gpio_set_config(id, &cfg); - } else if (os_strcmp(argv[3], "falling_edge") == 0) { - int_type = GPIO_INT_TYPE_FALLING_EDGE; - cfg.pull_mode = GPIO_PULL_UP_EN; - bk_gpio_set_config(id, &cfg); - } else { - cli_gpio_help(); - return; - } - bk_gpio_register_isr(id ,cli_gpio_int_isr); - - BK_LOG_ON_ERR(bk_gpio_set_interrupt_type(id, int_type)); - CLI_LOGI("gpio[%d] set int type:%x\n", id, int_type); - } else if (os_strcmp(argv[2], "start") == 0) { - BK_LOG_ON_ERR(bk_gpio_enable_interrupt(id)); - } else if (os_strcmp(argv[2], "stop") == 0) { - BK_LOG_ON_ERR(bk_gpio_disable_interrupt(id)); - CLI_LOGI("gpio[%d] int stop \r\n", id); - - } else { - cli_gpio_help(); - return; - } -} - -#define GPIO_CMD_CNT (sizeof(s_gpio_commands) / sizeof(struct cli_command)) -static const struct cli_command s_gpio_commands[] = { - {"gpio_int", "gpio_int [index] [inttype/start/stop] [low/high_level/rising/falling edge]", cli_gpio_int_cmd}, - {"gpio", "gpio [set_mode/output_low/output_high/input/spi_mode] [id] [mode]", cli_gpio_cmd}, - {"gpio_driver", "gpio_driver [init/deinit]}", cli_gpio_driver_cmd}, - {"gpio_map", "gpio_map [sdio_map/spi_map]",cli_gpio_map_cmd}, -#if CONFIG_GPIO_DYNAMIC_WAKEUP_SUPPORT - {"gpio_wake", "gpio_wake [index][low/high_level/rising/falling edge][enable/disable wakeup]", cli_gpio_set_wake_source_cmd}, - {"gpio_low_power", "gpio_low_power [simulate][param]", cli_gpio_simulate_low_power_cmd}, -#endif -#if CONFIG_GPIO_SIMULATE_UART_WRITE - {"gpio_uart_write", "[index][div(baud_rate=1Mbps/(1+div))][string]", cli_gpio_simulate_uart_write_cmd} -#endif - -}; - -int cli_gpio_init(void) -{ - BK_LOG_ON_ERR(bk_gpio_driver_init()); - return cli_register_commands(s_gpio_commands, GPIO_CMD_CNT); -} diff --git a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_i2c.c b/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_i2c.c deleted file mode 100644 index 5b323bf3efd59dbdf80095c549f4d835650a779f..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_i2c.c +++ /dev/null @@ -1,139 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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 -#include -#include "cli.h" - -#define EEPROM_DEV_ADDR 0x50 -#define EEPROM_MEM_ADDR 0x10 -#define I2C_SLAVE_ADDR 0x73 -#define I2C_WRITE_WAIT_MAX_MS (500) -#define I2C_READ_WAIT_MAX_MS (500) -#define CAMERA_DEV_ADDR (0x21) - -static void cli_i2c_help(void) -{ - CLI_LOGI("i2c_driver init\r\n"); - CLI_LOGI("i2c_driver deinit\r\n"); - CLI_LOGI("i2c {id} init\r\n"); - CLI_LOGI("i2c {id} deinit\r\n"); - CLI_LOGI("i2c {id} memory_write {data_size}\r\n"); - CLI_LOGI("i2c {id} memory_read {data_size}\r\n"); -} - -static void cli_i2c_driver_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - if (argc < 2) { - cli_i2c_help(); - return; - } - - if (os_strcmp(argv[1], "init") == 0) { - BK_LOG_ON_ERR(bk_i2c_driver_init()); - CLI_LOGI("i2c driver init\n"); - } else if (os_strcmp(argv[1], "deinit") == 0) { - BK_LOG_ON_ERR(bk_i2c_driver_deinit()); - CLI_LOGI("i2c driver deinit\n"); - } else { - cli_i2c_help(); - return; - } -} - -static void cli_i2c_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - if (argc < 2) { - cli_i2c_help(); - return; - } - - uint32_t i2c_id = os_strtoul(argv[1], NULL, 10); - - if (os_strcmp(argv[2], "init") == 0) { - i2c_config_t i2c_cfg = {0}; - i2c_cfg.baud_rate = 400000; - i2c_cfg.addr_mode = I2C_ADDR_MODE_7BIT; - i2c_cfg.slave_addr = I2C_SLAVE_ADDR; - - BK_LOG_ON_ERR(bk_i2c_init(i2c_id, &i2c_cfg)); - CLI_LOGI("i2c(%d) init\n", i2c_id); - } else if (os_strcmp(argv[2], "deinit") == 0) { - BK_LOG_ON_ERR(bk_i2c_deinit(i2c_id)); - CLI_LOGI("i2c(%d) deinit\n", i2c_id); - } else if (os_strcmp(argv[2], "master_write") == 0) { - uint8_t data_buf[10] = {0}; - for (uint32_t i = 0; i < 10; i++) { - data_buf[i] = i & 0xff; - } - BK_LOG_ON_ERR(bk_i2c_master_write(i2c_id, EEPROM_DEV_ADDR, data_buf, 10, I2C_WRITE_WAIT_MAX_MS)); - } else if (os_strcmp(argv[2], "memory_write") == 0) { - uint32_t buf_len = os_strtoul(argv[3], NULL, 10); - uint8_t *data_buf = os_malloc(buf_len); - BK_ASSERT(NULL != data_buf); - for (uint32_t i = 0; i < buf_len; i++) { - data_buf[i] = (i + 1) & 0xff; - } - uint32_t dev_addr = os_strtoul(argv[4], NULL, 16); - i2c_mem_param_t mem_param = {0}; - mem_param.dev_addr = dev_addr; - mem_param.mem_addr = EEPROM_MEM_ADDR; - mem_param.mem_addr_size = I2C_MEM_ADDR_SIZE_8BIT; - mem_param.data = data_buf; - mem_param.data_size = buf_len; - mem_param.timeout_ms = I2C_WRITE_WAIT_MAX_MS; - BK_LOG_ON_ERR(bk_i2c_memory_write(i2c_id, &mem_param)); - if (data_buf) { - os_free(data_buf); - data_buf = NULL; - } - CLI_LOGI("i2c(%d) memory_write buf_len:%d\r\n", i2c_id, buf_len); - } else if (os_strcmp(argv[2], "memory_read") == 0) { - uint32_t buf_len = os_strtoul(argv[3], NULL, 10); - uint8_t *data_buf = os_zalloc(buf_len); - BK_ASSERT(NULL != data_buf); - i2c_mem_param_t mem_param = {0}; - mem_param.dev_addr = EEPROM_DEV_ADDR; - mem_param.mem_addr = EEPROM_MEM_ADDR; - mem_param.mem_addr_size = I2C_MEM_ADDR_SIZE_8BIT; - mem_param.data = data_buf; - mem_param.data_size = buf_len; - mem_param.timeout_ms = I2C_WRITE_WAIT_MAX_MS; - BK_LOG_ON_ERR(bk_i2c_memory_read(i2c_id, &mem_param)); - for (uint32_t i = 0; i < buf_len; i++) { - CLI_LOGI("i2c_read_buf[%d]=%x\r\n", i, data_buf[i]); - } - if (data_buf) { - os_free(data_buf); - data_buf = NULL; - } - CLI_LOGI("i2c(%d) memory_read buf_len:%d\r\n", i2c_id, buf_len); - } else { - cli_i2c_help(); - return; - } -} - -#define I2C_CMD_CNT (sizeof(s_i2c_commands) / sizeof(struct cli_command)) -static const struct cli_command s_i2c_commands[] = { - {"i2c_driver", "i2c_driver {init|deinit}", cli_i2c_driver_cmd}, - {"i2c", "i2c {init|write|read}", cli_i2c_cmd}, -}; - -int cli_i2c_init(void) -{ - BK_LOG_ON_ERR(bk_i2c_driver_init()); - return cli_register_commands(s_i2c_commands, I2C_CMD_CNT); -} - diff --git a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_i2s.c b/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_i2s.c deleted file mode 100755 index a7805c119ec1114a9e386e373bf1a6646b97fe3b..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_i2s.c +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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 "cli.h" - - -extern void cli_i2s_master_test_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv); -extern void cli_i2s_master_sin_test_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv); -extern void cli_i2s_slave_test_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv); - -#if CONFIG_AUDIO -void cli_i2s_master_mic_test_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv); -void cli_i2s_slave_mic_test_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv); -#endif - -#define I2S_CMD_CNT (sizeof(s_i2s_commands) / sizeof(struct cli_command)) -static const struct cli_command s_i2s_commands[] = { - {"i2s_master_test", "i2s_master_test {start|stop}", cli_i2s_master_test_cmd}, - {"i2s_master_sin_test", "i2s_master_sin_test {start|stop}", cli_i2s_master_sin_test_cmd}, - {"i2s_slave_test", "i2s_slave_test {start|stop}", cli_i2s_slave_test_cmd}, -#if CONFIG_AUDIO - {"i2s_master_mic_test", "i2s_master_mic_test {start|stop}", cli_i2s_master_mic_test_cmd}, - {"i2s_slave_mic_test", "i2s_slave_mic_test {start|stop}", cli_i2s_slave_mic_test_cmd}, -#endif -}; - -int cli_i2s_init(void) -{ - return cli_register_commands(s_i2s_commands, I2S_CMD_CNT); -} - diff --git a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_icu.c b/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_icu.c deleted file mode 100644 index bfd9490c8b78180687ac6e7a43bb2ecd43d29a30..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_icu.c +++ /dev/null @@ -1,180 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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 "cli.h" -#include -#include "pwm_hal.h" -#include "gpio_hal.h" -#include "gpio_driver_base.h" -#include "icu_driver.h" -#include "clock_driver.h" -#include "power_driver.h" - - -typedef struct { - pwm_chan_t chan1; - pwm_chan_t chan2; - bool is_valid; -} pwm_group_info_t; -#define PWM_GROUP_NUM (SOC_PWM_CHAN_NUM_PER_UNIT >> 1) - -typedef struct { - pwm_hal_t hal; - //Important notes: currently no lock for bits - //Concurrently operation is NOT allowed!!! - uint32_t chan_init_bits; - pwm_group_info_t groups[PWM_GROUP_NUM]; -} pwm_driver_t; - -extern pwm_driver_t s_pwm; -extern gpio_driver_t s_gpio; - -static void cli_icu_help(void) -{ - CLI_LOGI("icu {init|deinit|get_int_statis}\n"); - CLI_LOGI("icu_control {power_on_pwm| power_down_pwm|enable_pwm_int|disable_pwm_int|\ - set_pwm_26m|set_pwm_dco|enable_pwm_lpo|disable_pwm_lpo|pwm_isr_register\ - |gpio_isr_register chan}\n"); -} - -static void cli_int_service_pwm_isr(void) -{ - pwm_hal_t *hal = &s_pwm.hal; - uint32_t int_status; - int chan; - - int_status = pwm_hal_get_interrupt_status(hal); - pwm_hal_clear_interrupt_status(hal, int_status); - for (chan = 0; chan < SOC_PWM_CHAN_NUM_PER_UNIT; chan++) { - if (pwm_hal_is_interrupt_triggered(hal, chan, int_status)) { - CLI_LOGI("pwm change register isr test :pwm[%d] isr\r\n", chan); - } - } -} - -static void cli_int_service_gpio_isr(void) -{ - gpio_hal_t *hal = &s_gpio.hal; - gpio_interrupt_status_t gpio_status; - int gpio_id; - - gpio_hal_get_interrupt_status(hal, &gpio_status); - - gpio_hal_clear_interrupt_status(hal, &gpio_status); - - for (gpio_id = 0; gpio_id < GPIO_NUM; gpio_id++) { - if (gpio_hal_is_interrupt_triggered(hal, gpio_id, &gpio_status)) { - CLI_LOGI("gpio change register isr test :gpio[%d] isr\r\n", gpio_id); - } - } - -} - -static void cli_icu_int_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - - if (argc < 2) { - cli_icu_help(); - return; - } - - if (os_strcmp(argv[1], "init") == 0) { - BK_LOG_ON_ERR(bk_icu_driver_init()); - CLI_LOGI("icu intterupt init\n"); - } else if(os_strcmp(argv[1], "deinit") == 0) { - BK_LOG_ON_ERR(bk_icu_driver_deinit()); - CLI_LOGI("icu interrupt deinit\n"); - } -#if CONFIG_INT_STATIS - else if(os_strcmp(argv[1], "get_int_statis") == 0) { - int_statis_t *int_st = {0}; - int_st = bk_get_int_statis(); - BK_LOG_ON_ERR(bk_dump_int_statis(int_st)); - CLI_LOGI("icu get interrupt statistic\n"); - } -#endif - else if(os_strcmp(argv[1], "pwm_isr_register") == 0) { - bk_int_isr_register(INT_SRC_PWM, cli_int_service_pwm_isr, NULL); - CLI_LOGI("pwm registert isr change test\n"); - } else if(os_strcmp(argv[1], "gpio_isr_register") == 0) { - bk_int_isr_register(INT_SRC_GPIO, cli_int_service_gpio_isr, NULL); - CLI_LOGI("gpio register isr changing test\n"); - } else if(os_strcmp(argv[1], "set_pwm_int_pri") == 0) { - uint32_t pri = os_strtoul(argv[2], NULL, 10); - bk_int_set_priority(INT_SRC_PWM, pri); - CLI_LOGI("pwm int priority changing test\n"); - }else if(os_strcmp(argv[1], "set_gpio_int_pri") == 0) { - uint32_t pri = os_strtoul(argv[2], NULL, 10); - bk_int_set_priority(INT_SRC_GPIO, pri); - CLI_LOGI("gpio int priority changing test\n"); - }else { - cli_icu_help(); - return; - } - -} - -static void cli_icu_control_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - uint32_t chan; - - if (argc < 2) - { - cli_icu_help(); - return; - } - - chan = os_strtoul(argv[2], NULL, 10); - - if (os_strcmp(argv[1], "power_on_pwm") == 0) - { - power_pwm_pwr_up(chan); - CLI_LOGI("pwr up pwm channel %d\n", chan); - } else if (os_strcmp(argv[1], "power_down_pwm") == 0) { - power_pwm_pwr_down(chan); - CLI_LOGI("pwr down pwm channel %d\n", chan); - } else if (os_strcmp(argv[1], "enable_pwm_int") == 0) { - icu_enable_pwm_interrupt(); - icu_enable_pwm2_interrupt(); - } else if (os_strcmp(argv[1], "disable_pwm_int") == 0) { - icu_disable_pwm_interrupt(); - icu_disable_pwm2_interrupt(); - } else if (os_strcmp(argv[1], "set_pwm_26m") == 0) { - clk_set_pwms_clk_26m(); - } else if (os_strcmp(argv[1], "set_pwm_dco") == 0) { - clk_set_pwms_clk_dco(); - } else if (os_strcmp(argv[1], "enable_pwm_lpo") == 0) { - clk_enable_pwm_clk_lpo(chan); - } else if (os_strcmp(argv[1], "disable_pwm_lpo") == 0) { - clk_disable_pwm_clk_lpo(chan); - }else { - cli_icu_help(); - return; - } - -} - - -#define ICU_CMD_CNT (sizeof(s_icu_commands) / sizeof(struct cli_command)) -static const struct cli_command s_icu_commands[] = { - {"icu", "icu {init}", cli_icu_int_cmd}, - {"icu_control", "icu {power_on_pwm|power_down_pwm}", cli_icu_control_cmd}, -}; - -int cli_icu_init(void) -{ - BK_LOG_ON_ERR(bk_icu_driver_init()); - return cli_register_commands(s_icu_commands, ICU_CMD_CNT); -} - diff --git a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_iperf.c b/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_iperf.c deleted file mode 100644 index 387e1b5c33bcde034f1daf9ae4eb21dddbac6552..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_iperf.c +++ /dev/null @@ -1,15 +0,0 @@ -#include "cli.h" - -#if CONFIG_IPERF_TEST -extern void iperf(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv); - -#define IPERF_CMD_CNT (sizeof(s_iperf_commands) / sizeof(struct cli_command)) -static const struct cli_command s_iperf_commands[] = { - {"iperf", "iperf help", iperf }, -}; - -int cli_iperf_init(void) -{ - return cli_register_commands(s_iperf_commands, IPERF_CMD_CNT); -} -#endif diff --git a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_jpegdec.c b/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_jpegdec.c deleted file mode 100755 index 882c096d791496ec436d77dcb7f1bb83c50b47da..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_jpegdec.c +++ /dev/null @@ -1,10 +0,0 @@ -#include "cli.h" - -#define JPEG_DEC_CNT (sizeof(s_jpegdec_commands) / sizeof(struct cli_command)) -static const struct cli_command s_jpegdec_commands[] = {}; - -int cli_jpegdec_init(void) -{ - return cli_register_commands(s_jpegdec_commands, JPEG_DEC_CNT); -} - diff --git a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_jpegenc.c b/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_jpegenc.c deleted file mode 100755 index b59194376df7e6525f86010fb34288c4cf940fdf..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_jpegenc.c +++ /dev/null @@ -1,77 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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 -#include "cli.h" -//#include "jpeg_hw.h" - -static void cli_jpeg_help(void) -{ - CLI_LOGI("jpeg_driver init\r\n"); - CLI_LOGI("jpeg_driver deinit\r\n"); - CLI_LOGI("jpeg init\r\n"); - CLI_LOGI("jpeg deinit\r\n"); -} - -static void cli_jpeg_driver_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - if (argc < 2) { - cli_jpeg_help(); - return; - } - - if (os_strcmp(argv[1], "init") == 0) { - BK_LOG_ON_ERR(bk_jpeg_enc_driver_init()); - CLI_LOGI("jpeg driver init\n"); - } else if (os_strcmp(argv[1], "deinit") == 0) { - BK_LOG_ON_ERR(bk_jpeg_enc_driver_deinit()); - CLI_LOGI("jpeg driver deinit\n"); - } else { - cli_jpeg_help(); - return; - } -} - -static void cli_jpeg_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - if (argc < 2) { - cli_jpeg_help(); - return; - } - - if (os_strcmp(argv[1], "init") == 0) { - jpeg_config_t jpeg_cfg = {0}; - BK_LOG_ON_ERR(bk_jpeg_enc_driver_init()); - BK_LOG_ON_ERR(bk_jpeg_enc_init(&jpeg_cfg)); - CLI_LOGI("jpeg init\r\n"); - } else if (os_strcmp(argv[1], "deinit") == 0) { - BK_LOG_ON_ERR(bk_jpeg_enc_deinit()); - CLI_LOGI("jpeg deinit\r\n"); - } else { - cli_jpeg_help(); - } -} - -#define JPEG_CMD_CNT (sizeof(s_jpeg_commands) / sizeof(struct cli_command)) -static const struct cli_command s_jpeg_commands[] = { - {"jpeg_driver", "jpeg_driver {init|deinit}", cli_jpeg_driver_cmd}, - {"jpeg", "jpeg {init|deint}", cli_jpeg_cmd}, -}; - -int cli_jpeg_init(void) -{ - //BK_LOG_ON_ERR(bk_jpeg_enc_driver_init()); - return cli_register_commands(s_jpeg_commands, JPEG_CMD_CNT); -} - diff --git a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_keyValue.c b/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_keyValue.c deleted file mode 100644 index e3ef5ba68fb35d095881ac53070515a51d104431..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_keyValue.c +++ /dev/null @@ -1,188 +0,0 @@ -#include -#include "cli.h" -#include "key_value.h" -#include "func_convert.h" -#ifdef CONFIG_LWIP -#include "net.h" -#endif -#ifdef CONFIG_KEYVALUE -#if 0 -#include "ADK.h" -#include "HAPBase.h" -#include "HAPPlatformRandomNumber.h" -#include "HAPCrypto.h" -#endif - - -typedef struct { - uint8_t salt[16]; /**< SRP salt. */ - uint8_t verifier[384]; /**< SRP verifier. */ -} HAPSetupInfo_ext; - -extern void* AdkRunApplication(void* ctx ); -extern void HAPPlatformRandomNumberFill(void* bytes, size_t numBytes); -extern void HAP_srp_verifier( - uint8_t v[384], - const uint8_t salt[16], - const uint8_t* user, - size_t user_len, - const uint8_t* pass, - size_t pass_len); -#endif - -/** - ************************************************************ - * @brief wirte_flash. - * - * @param[in] - * @param[out] - * @return - ************************************************************* - */ -static void key_value_command_test(char * pcWriteBuffer, int xWriteBufferLen, int argc, char * *argv) -{ - char cmd = 0; - UINT32 len = 0, domain = 0, idx; - UINT32 key = 0; - UINT8 * ptr; -#ifdef CONFIG_KEYVALUE - beken_thread_t homekit_app; - bk_err_t ret; - const char name[] = "Pair-Setup"; - HAPSetupInfo_ext info; -#endif - ptr = ((uint8_t *) os_malloc(0x400)); - if (argc >= 4) - { - cmd = argv[1][0]; - domain = str_to_hexnum(argv[2]); - key = str_to_hexnum(argv[3]); - switch (cmd) - { - case 'e': - erase_flash(domain); - break; - - case 'r': - read_flash(domain, ptr, key); - for (idx = 0; idx < key; idx++) os_printf("%02x ", ptr[idx]); - os_printf(" end.\r\n"); - break; - - case 'w': - if (argc > 4) - { - len = str_to_hexarray(argv[4], ptr); - write_flash(domain, ptr, len); - } - break; - - case 'E': - rm_domain(KV_BASE_ADDR, domain); - break; - - case 'R': - if (get_domain_key_value(KV_BASE_ADDR, domain, key, ptr, 0x400, &len)) - { - os_printf("key %02x%02x= \r\n", domain, key); - for (idx = 0; idx < len; idx++) os_printf("%02x ", ptr[idx]); - os_printf(" end.\r\n"); - } - break; - - case 'U': - if (argc > 4) set_domain_key_value(KV_BASE_ADDR, domain, key, (UINT8 *)argv[4], os_strlen(argv[4])); - break; - - case 'W': - if (argc > 4) set_domain_key_value(KV_BASE_ADDR, domain, key, (UINT8 *)argv[4], os_strlen(argv[4]) + 1); - break; - - case 'V': - if (argc > 4) - { - len = str_to_hexarray(argv[4], ptr); - set_domain_key_value(KV_BASE_ADDR, domain, key, ptr, len); - } - break; - - case 'N': - search_domain_key(KV_BASE_ADDR, domain, ptr); - break; -#ifdef CONFIG_LWIP - case 'B': - switch (argv[2][0]) - { - case 'U': - sta_ip_start(); - break; - - case 'D': - sta_ip_down(); - break; - } -#endif - break; - - case 'M': - rm_domain_key(KV_BASE_ADDR, domain, key); - break; - -#ifdef CONFIG_KEYVALUE - case 'K': - - if (argc > 4) - { - if (argc == 5) HAPPlatformRandomNumberFill((void *)info.salt, sizeof(info.salt)); - else - { - len = str_to_hexarray(argv[5], ptr); - os_memcpy((void *)info.salt, (void *)ptr, sizeof(info.salt)); - } - HAP_srp_verifier(info.verifier, info.salt, (UINT8 *)name, os_strlen(name), (UINT8 *)argv[4], os_strlen(argv[4])); - set_domain_key_value(KV_BASE_ADDR, 0x40, 0x10, info.salt, sizeof(info)); - } - break; - - case 'T': - len = atoi(argv[2]); - if (len < 2048) len = 2048; - ret = rtos_create_thread(&homekit_app, - BEKEN_APPLICATION_PRIORITY, - "homekit", - (beken_thread_function_t) AdkRunApplication, - (unsigned short) len, - (beken_thread_arg_t) 0); - if(kNoErr != ret) - os_printf("!!! homekit task err\r\n"); - break; - -#endif - - default: - break; - } - } - else - { - os_printf("key_value \r\n"); - } - os_free(ptr); -} - - -#define KV_CMD_CNT (sizeof(s_kv_commands) / sizeof(struct cli_command)) -static const struct cli_command s_kv_commands[] = -{ - { - "KEY_VALUE", "KEY_VALUE ", key_value_command_test - }, -}; - - -int cli_keyVaule_init(void) -{ - return cli_register_commands(s_kv_commands, KV_CMD_CNT); -} - - diff --git a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_lcd.c b/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_lcd.c deleted file mode 100755 index 2dedd14fd4d8b9cd231584af5bff95a39baf2966..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_lcd.c +++ /dev/null @@ -1,41 +0,0 @@ -#include "cli.h" -extern void lcd_8080_display_test(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv); -extern void lcd_8080_display_yuv(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv); -extern void lcd_8080_display_480p_yuv(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv); -extern void lcd_rgb_display_test(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv); -extern void lcd_rgb_display_jpeg(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv); -extern void lcd_rgb_display_yuv(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv); -extern void lcd_rgb_close(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv); -extern void sdcard_read_to_psram(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv); -extern void lcd_rgb_gc9503v_test(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv); -extern void jpeg_dec_display_demo(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv); -extern void sdcard_write_from_mem(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv); - - -#define LCD_CNT (sizeof(s_lcd_commands) / sizeof(struct cli_command)) -static const struct cli_command s_lcd_commands[] = { - {"lcd_8080", "init|fram_disp", lcd_8080_display_test}, - {"lcd_8080_yuv", "lcd_8080_yuv=4", lcd_8080_display_yuv}, - {"lcd_8080_yuv_partical", "lcd_8080_yuv_partical=4", lcd_8080_display_480p_yuv}, - {"lcd_rgb", "lcd_rgb=rgb565_display,1,display_partical", lcd_rgb_display_test}, - {"lcd_rgb_yuv", "lcd_rgb=480p,1,display_partical", lcd_rgb_display_yuv}, - {"lcd_rgb_jpeg", "lcd_rgb_jpeg =480p ,25", lcd_rgb_display_jpeg}, - {"lcd_close", "lcd_close=yuv|jpeg,", lcd_rgb_close}, - {"lcd_device_init_handler", " init , gc9503v ,display", lcd_rgb_gc9503v_test}, - {"sdcard_write_from_mem", "file_name|pixelx|pixely|addr", sdcard_write_from_mem}, - {"sdcard_read_to_mem", "file_name,addr", sdcard_read_to_psram}, - {"lcd", " file_display,file name", jpeg_dec_display_demo}, -}; - -int cli_lcd_init(void) -{ - return cli_register_commands(s_lcd_commands, LCD_CNT); -} - - - - - - - - diff --git a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_lwip.c b/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_lwip.c deleted file mode 100644 index 6d9cce77e16253639bdc00131dbf5dcf08e156e0..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_lwip.c +++ /dev/null @@ -1,164 +0,0 @@ -#include -#include "lwip/opt.h" - -#include "lwip/memp.h" -#include "lwip/sys.h" -#include "lwip/stats.h" -#include "cli.h" -#include -#include -#include "bk_cli.h" -#include -#include -#if !CONFIG_HARMONY_LWIP - -void cli_lwip_pbuf_info(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ -#if PBUF_LIFETIME_DBG - if ((argc == 2) && (os_strcmp(argv[1], "-r") == 0)) - { - CLI_LOGI("reset lwip pbuf count\n"); - - lwip_stats.pbuf_info.all_cnt = 0; - lwip_stats.pbuf_info.prep_cnt = 0; - lwip_stats.pbuf_info.mac_prep_cnt = 0; - lwip_stats.pbuf_info.send_cnt = 0; - lwip_stats.pbuf_info.cfm_cnt = 0; - lwip_stats.pbuf_info.cfm_free_cnt = 0; - } - else if((os_strcmp(argv[1], "log") == 0)) - { - CLI_LOGI("pbuf debug\n"); - pbuf_set_log(os_strtoul(argv[2], NULL, 10)); - } - SYS_ARCH_DECL_PROTECT(old_level); - SYS_ARCH_PROTECT(old_level); - - os_printf("pbuf all %d prep %d mac %d send %d cfm %d free %d\r\n", - lwip_stats.pbuf_info.all_cnt, - lwip_stats.pbuf_info.prep_cnt, - lwip_stats.pbuf_info.mac_prep_cnt, - lwip_stats.pbuf_info.send_cnt, - lwip_stats.pbuf_info.cfm_cnt, - lwip_stats.pbuf_info.cfm_free_cnt); - - if(lwip_stats.pbuf_info.all_cnt != 0) - { - os_printf("pbuf prep %d mac %d send %d cfm %d free %d\r\n", - (lwip_stats.pbuf_info.prep_cnt*100/lwip_stats.pbuf_info.all_cnt), - (lwip_stats.pbuf_info.mac_prep_cnt*100/lwip_stats.pbuf_info.all_cnt), - (lwip_stats.pbuf_info.send_cnt*100/lwip_stats.pbuf_info.all_cnt), - (lwip_stats.pbuf_info.cfm_cnt*100/lwip_stats.pbuf_info.all_cnt), - (lwip_stats.pbuf_info.cfm_free_cnt*100/lwip_stats.pbuf_info.all_cnt)); - } - - SYS_ARCH_UNPROTECT(old_level); -#endif -} - -void cli_lwip_mem_info(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - int i; - struct memp_desc *tmp; - - if (argc > 2) { - CLI_LOGI("invalid lwip command paramters\n"); - return; - } - - if ((argc == 2) && (os_strcmp(argv[1], "-r") == 0)) - { - CLI_LOGI("reset lwip memory err count and max used\n"); - - for (i = 0; i < MEMP_MAX; i++) { - lwip_stats.memp[i]->max = 0, - lwip_stats.memp[i]->err = 0; - } - - lwip_stats.mem.max = 0; - lwip_stats.mem.err = 0; -#if (MEM_TRX_DYNAMIC_EN) - lwip_stats.mem.tx_max = 0; - lwip_stats.mem.rx_max = 0; - lwip_stats.mem.tx_err = 0; - lwip_stats.mem.rx_err = 0; -#endif - } - - SYS_ARCH_DECL_PROTECT(old_level); - SYS_ARCH_PROTECT(old_level); - - os_printf("%-16s total used addr size err\r\n", "Name"); - os_printf("----------------------------------------------------\r\n"); - for (i = 0; i < MEMP_MAX; i++) { - tmp = (struct memp_desc *)memp_pools[i]; - os_printf("%-16s %-5d %-4d 0x%08x %-4d %d\r\n", - tmp->desc, tmp->num, tmp->stats->used, - (unsigned int)tmp->base, tmp->size, lwip_stats.memp[i]->err); - } - - os_printf("===== MEMP_PUBF_POOL ======\r\n"); - os_printf("avail %d, used %d, max %d, err %d\r\n", - lwip_stats.memp[MEMP_PBUF_POOL]->avail, - lwip_stats.memp[MEMP_PBUF_POOL]->used, - lwip_stats.memp[MEMP_PBUF_POOL]->max, - lwip_stats.memp[MEMP_PBUF_POOL]->err); - - os_printf("========== MEM ============\r\n"); - os_printf("avail %d, used %d, max %d, err %d\r\n", - lwip_stats.mem.avail, - lwip_stats.mem.used, - lwip_stats.mem.max, - lwip_stats.mem.err); - -#if (MEM_TRX_DYNAMIC_EN) - os_printf("tx avail %d, rx avail %d, tx used %d, rx used %d, tx max %d, rx max %d, tx err %d, rx err %d\r\n", - MEM_MAX_TX_SIZE, - MEM_MAX_RX_SIZE, - lwip_stats.mem.tx_used, - lwip_stats.mem.rx_used, - lwip_stats.mem.tx_max, - lwip_stats.mem.rx_max, - lwip_stats.mem.tx_err, - lwip_stats.mem.rx_err); -#endif - - SYS_ARCH_UNPROTECT(old_level); -} -void cli_lwip_stats(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ -#if LWIP_STATS_DISPLAY - if (argc > 2) { - CLI_LOGI("invalid lwip command paramters\n"); - return; - } - - if ((argc == 2) && (os_strcmp(argv[1], "-r") == 0)) - { - CLI_LOGI("reset lwip status\n"); - stats_reset_short(); - } - - stats_display_short(); -#endif -} -#endif -extern void iperf(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv); - -#define IPERF_CMD_CNT (sizeof(s_lwip_commands) / sizeof(struct cli_command)) -static const struct cli_command s_lwip_commands[] = { -#if CONFIG_LWIP -#if !CONFIG_HARMONY_LWIP - {"lwip_mem", "print lwip memory information", cli_lwip_mem_info}, - {"lwip_stats", "print lwip protocal statistics", cli_lwip_stats}, - {"lwip_pbuf", "print lwip pbuf information", cli_lwip_pbuf_info}, -#endif -#endif -}; - -int cli_lwip_init(void) -{ - return cli_register_commands(s_lwip_commands, IPERF_CMD_CNT); -} -// eof - diff --git a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_main.c b/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_main.c deleted file mode 100644 index 079331c732b38fd689aa56c76a93b19c53f2a9b8..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_main.c +++ /dev/null @@ -1,1569 +0,0 @@ -/** - * UNPUBLISHED PROPRIETARY SOURCE CODE - * Copyright (c) 2016 BEKEN Inc. - * - * The contents of this file may not be disclosed to third parties, copied or - * duplicated in any form, in whole or in part, without the prior written - * permission of BEKEN Corporation. - * - */ -#include -#include "sys_rtos.h" -#include -#include - -#include "bk_cli.h" -#include "stdarg.h" -#include -#include -#include -#include "bk_phy.h" -#include "cli.h" -#include "cli_config.h" -#include -#include -#include "bk_rtos_debug.h" -#if CONFIG_SHELL_ASYNCLOG -#include "components/shell_task.h" -#endif -#include "bk_uart_debug.h" -#include "bk_api_cli.h" -#if (CONFIG_SLAVE_CORE && CONFIG_MEDIA) -#include "media_common.h" -#endif - -#ifdef CONFIG_MEDIA -#include "media_cli.h" -#endif - - -#define TAG "cli" - -static struct cli_st *pCli = NULL; - -#if (!CONFIG_SHELL_ASYNCLOG) -beken_semaphore_t log_rx_interrupt_sema = NULL; -#endif - -static uint16_t s_running_command_index = MAX_COMMANDS; -#if CFG_CLI_DEBUG -static uint8_t s_running_status = 0; -#endif - -extern int cli_putstr(const char *msg); -extern int hexstr2bin(const char *hex, u8 *buf, size_t len); - -#if CONFIG_CAMERA -extern int video_demo_register_cmd(void); -#endif - -#if CONFIG_BKREG -#define BKREG_MAGIC_WORD0 (0x01) -#define BKREG_MAGIC_WORD1 (0xE0) -#define BKREG_MAGIC_WORD2 (0xFC) -#define BKREG_MIN_LEN 3 -#endif - -#define SHELL_TASK_PRIORITY 1 - -/* Find the command 'name' in the cli commands table. -* If len is 0 then full match will be performed else upto len bytes. -* Returns: a pointer to the corresponding cli_command struct or NULL. -*/ -const struct cli_command *lookup_command(char *name, int len) -{ - int i = 0; - int n = 0; - - while (i < MAX_COMMANDS && n < pCli->num_commands) { - if (pCli->commands[i]->name == NULL) { - i++; - continue; - } - - /* See if partial or full match is expected */ - if (len != 0) { - if (!os_strncmp(pCli->commands[i]->name, name, len)) { - s_running_command_index = i; - return pCli->commands[i]; - } - } else { - if (!os_strcmp(pCli->commands[i]->name, name)) { - s_running_command_index = i; - return pCli->commands[i]; - } - } - - i++; - n++; - } - - return NULL; -} - -int lookup_cmd_table(const struct cli_command *cmd_table, int table_items, char *name, int len) -{ - int i; - - for (i = 0; i < table_items; i++) - { - if (cmd_table[i].name == NULL) - { - continue; - } - - /* See if partial or full match is expected */ - if (len != 0) - { - if (!os_strncmp(cmd_table[i].name, name, len)) - { - return i; - } - } - else - { - if (!os_strcmp(cmd_table[i].name, name)) - { - return i; - } - } - } - - return -1; -} - -#if (CONFIG_SHELL_ASYNCLOG && !CONFIG_ATE_TEST) - -/* Parse input line and locate arguments (if any), keeping count of the number -* of arguments and their locations. Look up and call the corresponding cli -* function if one is found and pass it the argv array. -* -* Returns: 0 on success: the input line contained at least a function name and -* that function exists and was called. -* 1 on lookup failure: there is no corresponding function for the -* input line. -* 2 on invalid syntax: the arguments list couldn't be parsed -*/ -int handle_shell_input(char *inbuf, int in_buf_size, char * outbuf, int out_buf_size) -{ - struct { - unsigned inArg: 1; - unsigned inQuote: 1; - unsigned done: 1; - unsigned limQ : 1; - unsigned isD : 2; - } stat; - static char *argv[16]; - int argc = 0; - int i = 0; - const struct cli_command *command = NULL; - const char *p; - - os_memset((void *)&argv, 0, sizeof(argv)); - os_memset(&stat, 0, sizeof(stat)); - - if(outbuf != NULL) - os_memset(outbuf, 0, out_buf_size); - - if (inbuf[i] == '\0') - return 0; - - do { - switch (inbuf[i]) { - case '\0': - if (((argc == 0)||(stat.isD == 1))||(stat.limQ)||(stat.inQuote)) - { - if(outbuf != NULL) - strcpy(&outbuf[0], "syntax error\r\n"); - return 2; - } - stat.done = 1; - break; - - case '"': - if (i > 0 && inbuf[i - 1] == '\\' && stat.inArg) { - os_memcpy(&inbuf[i - 1], &inbuf[i], - os_strlen(&inbuf[i]) + 1); - --i; - break; - } - if (!stat.inQuote && stat.inArg) - break; - if (stat.inQuote && !stat.inArg) - { - if(outbuf != NULL) - strcpy(&outbuf[0], "syntax error\r\n"); - return 2; - } - - if (!stat.inQuote && !stat.inArg) { - stat.inArg = 1; - stat.inQuote = 1; - argc++; - argv[argc - 1] = &inbuf[i + 1]; - } else if (stat.inQuote && stat.inArg) { - stat.inArg = 0; - stat.inQuote = 0; - inbuf[i] = '\0'; - } - break; - - case ' ': - if (i > 0 && inbuf[i - 1] == '\\' && stat.inArg) { - os_memcpy(&inbuf[i - 1], &inbuf[i], - os_strlen(&inbuf[i]) + 1); - --i; - break; - } - if (!stat.inQuote && stat.inArg) { - stat.inArg = 0; - inbuf[i] = '\0'; - } - break; - - case '=': - if(argc == 1) { - inbuf[i] = '\0'; - stat.inArg = 0; - stat.isD = 1; - } - else if(argc == 0){ - if(outbuf != NULL) - strcpy(&outbuf[0], "syntax error\r\n"); - return 2; - } - break; - - case ',': - if((stat.isD == 1)&&(argc == 1)) ///=, - { - if(outbuf != NULL) - strcpy(&outbuf[0], "syntax error\r\n"); - return 2; - } - if(!stat.inQuote && stat.inArg) { - stat.inArg = 0; - inbuf[i] = '\0'; - stat.limQ = 1; - } - break; - - default: - if (!stat.inArg) { - stat.inArg = 1; - argc++; - argv[argc - 1] = &inbuf[i]; - stat.limQ = 0; - if(stat.isD == 1) { - stat.isD = 2; - } - } - break; - } - } while (!stat.done && ++i < in_buf_size); - - if (stat.inQuote) - { - if(outbuf != NULL) - strcpy(&outbuf[0], "syntax error\r\n"); - return 2; - } - - if (argc < 1) - { - if(outbuf != NULL) - strcpy(&outbuf[0], "argc = 0\r\n"); - return 0; - } - - /* - * Some comamands can allow extensions like foo.a, foo.b and hence - * compare commands before first dot. - */ - i = ((p = os_strchr(argv[0], '.')) == NULL) ? 0 : - (p - argv[0]); - command = lookup_command(argv[0], i); - if (command == NULL) - { - if(outbuf != NULL) - sprintf(&outbuf[0], "cmd: %s NOT found.\r\n", inbuf); - return 1; - } - -#if CONFIG_STA_PS - /*if cmd,exit dtim ps*/ - if (os_strncmp(command->name, "ps", 2)) { - } -#endif - -#if CFG_CLI_DEBUG - s_running_status |= CLI_COMMAND_IS_RUNNING; - command->function(outbuf, out_buf_size , argc, argv); - s_running_status &= ~CLI_COMMAND_IS_RUNNING; -#else - command->function(outbuf, out_buf_size , argc, argv); -#endif - - return 0; -} - -#elif CONFIG_ATE_TEST -static beken_semaphore_t ate_test_semaphore = NULL; -static void ate_uart_rx_isr(uart_id_t id, void *param) -{ - int ret; - - ret = rtos_set_semaphore(&ate_test_semaphore); - if(kNoErr !=ret) - os_printf("ate_uart_rx_isr: ATE set sema failed\r\n"); -} - -static void ate_uart_tx_isr(uart_id_t id, void *param) -{ - bk_uart_disable_tx_interrupt(CONFIG_UART_PRINT_PORT); -} - -static void cli_ate_main(uint32_t data) -{ - - char *msg = NULL; - int ret = -1; - int cnt = 0; - uint8_t rx_data; - - if(NULL == ate_test_semaphore) - { - ret = rtos_init_semaphore(&ate_test_semaphore, 1); - if (kNoErr != ret) - os_printf("cli_ate_main: ATE create background sema failed\r\n"); - } - - bk_uart_disable_sw_fifo(CONFIG_UART_PRINT_PORT); - bk_uart_register_rx_isr(CONFIG_UART_PRINT_PORT, (uart_isr_t)ate_uart_rx_isr, NULL); - bk_uart_enable_rx_interrupt(CONFIG_UART_PRINT_PORT); - - bk_uart_register_tx_isr(CONFIG_UART_PRINT_PORT, (uart_isr_t)ate_uart_tx_isr, NULL); - bk_uart_enable_tx_interrupt(CONFIG_UART_PRINT_PORT); - - send_device_id(); - ate_test_multiple_cpus_init(); - - while (1) { - - ret = rtos_get_semaphore(&ate_test_semaphore, BEKEN_WAIT_FOREVER); - if(kNoErr == ret) { - while(1) /* read all data from rx-FIFO. */ - { - ret = uart_read_byte_ex(CONFIG_UART_PRINT_PORT, &rx_data); - if (ret == -1) - break; - - pCli->inbuf[cnt] = (char)rx_data; - cnt++; - - if(cnt >= INBUF_SIZE) - break; - } - - bkreg_run_command1(pCli->inbuf, cnt); - - if (cnt > 0) { - for (int i = 0;i < cnt; i++) - pCli->inbuf[i] = 0; - cnt = 0; - } - } - - msg = pCli->inbuf; - if (os_strcmp(msg, EXIT_MSG) == 0) - break; - } - - os_printf("CLI exited\r\n"); - os_free(pCli); - pCli = NULL; - - rtos_delete_thread(NULL); -} - -#else - -/* Parse input line and locate arguments (if any), keeping count of the number -* of arguments and their locations. Look up and call the corresponding cli -* function if one is found and pass it the argv array. -* -* Returns: 0 on success: the input line contained at least a function name and -* that function exists and was called. -* 1 on lookup failure: there is no corresponding function for the -* input line. -* 2 on invalid syntax: the arguments list couldn't be parsed -*/ -static int handle_input(char *inbuf) -{ - struct { - unsigned inArg: 1; - unsigned inQuote: 1; - unsigned done: 1; - unsigned limQ : 1; - unsigned isD : 2; - } stat; - static char *argv[16]; - int argc = 0; - int i = 0; - const struct cli_command *command = NULL; - const char *p; - - os_memset((void *)&argv, 0, sizeof(argv)); - os_memset(&stat, 0, sizeof(stat)); - - if (inbuf[i] == '\0') - return 0; - - do { - switch (inbuf[i]) { - case '\0': - if (((argc == 0)||(stat.isD == 1))||(stat.limQ)||(stat.inQuote)) - return 2; - stat.done = 1; - break; - - case '"': - if (i > 0 && inbuf[i - 1] == '\\' && stat.inArg) { - os_memcpy(&inbuf[i - 1], &inbuf[i], - os_strlen(&inbuf[i]) + 1); - --i; - break; - } - if (!stat.inQuote && stat.inArg) - break; - if (stat.inQuote && !stat.inArg) - return 2; - - if (!stat.inQuote && !stat.inArg) { - stat.inArg = 1; - stat.inQuote = 1; - argc++; - argv[argc - 1] = &inbuf[i + 1]; - } else if (stat.inQuote && stat.inArg) { - stat.inArg = 0; - stat.inQuote = 0; - inbuf[i] = '\0'; - } - break; - - case ' ': - if (i > 0 && inbuf[i - 1] == '\\' && stat.inArg) { - os_memcpy(&inbuf[i - 1], &inbuf[i], - os_strlen(&inbuf[i]) + 1); - --i; - break; - } - if (!stat.inQuote && stat.inArg) { - stat.inArg = 0; - inbuf[i] = '\0'; - } - break; - - case '=': - if(argc == 1) { - inbuf[i] = '\0'; - stat.inArg = 0; - stat.isD = 1; - } - else if(argc == 0){ - os_printf("The data does not conform to the regulations %d\r\n",__LINE__); - return 2; - } - break; - - case ',': - if((stat.isD == 1)&&(argc == 1)) ///=, - { - os_printf("The data does not conform to the regulations %d\r\n",__LINE__); - return 2; - } - if(!stat.inQuote && stat.inArg) { - stat.inArg = 0; - inbuf[i] = '\0'; - stat.limQ = 1; - } - break; - - default: - if (!stat.inArg) { - stat.inArg = 1; - argc++; - argv[argc - 1] = &inbuf[i]; - stat.limQ = 0; - if(stat.isD == 1) { - stat.isD = 2; - } - } - break; - } - } while (!stat.done && ++i < INBUF_SIZE); - - if (stat.inQuote) - return 2; - - if (argc < 1) - return 0; - - if (!pCli->echo_disabled) - os_printf("\r\n"); - - /* - * Some comamands can allow extensions like foo.a, foo.b and hence - * compare commands before first dot. - */ - i = ((p = os_strchr(argv[0], '.')) == NULL) ? 0 : - (p - argv[0]); - command = lookup_command(argv[0], i); - if (command == NULL) - return 1; - - os_memset(pCli->outbuf, 0, OUTBUF_SIZE); - cli_putstr("\r\n"); - -#if CONFIG_STA_PS - /*if cmd,exit dtim ps*/ - if (os_strncmp(command->name, "ps", 2)) { - } -#endif - -#if CFG_CLI_DEBUG - s_running_status |= CLI_COMMAND_IS_RUNNING; - command->function(pCli->outbuf, OUTBUF_SIZE, argc, argv); - s_running_status &= ~CLI_COMMAND_IS_RUNNING; -#else - command->function(pCli->outbuf, OUTBUF_SIZE, argc, argv); -#endif - cli_putstr(pCli->outbuf); - return 0; -} - -/* Perform basic tab-completion on the input buffer by string-matching the -* current input line against the cli functions table. The current input line -* is assumed to be NULL-terminated. */ -static void tab_complete(char *inbuf, unsigned int *bp) -{ - int i, n, m; - const char *fm = NULL; - - os_printf("\r\n"); - - /* show matching commands */ - for (i = 0, n = 0, m = 0; i < MAX_COMMANDS && n < pCli->num_commands; - i++) { - if (pCli->commands[i]->name != NULL) { - if (!os_strncmp(inbuf, pCli->commands[i]->name, *bp)) { - m++; - if (m == 1) - fm = pCli->commands[i]->name; - else if (m == 2) - os_printf("%s %s ", fm, - pCli->commands[i]->name); - else - os_printf("%s ", - pCli->commands[i]->name); - } - n++; - } - } - - /* there's only one match, so complete the line */ - if (m == 1 && fm) { - n = os_strlen(fm) - *bp; - if (*bp + n < INBUF_SIZE) { - os_memcpy(inbuf + *bp, fm + *bp, n); - *bp += n; - inbuf[(*bp)++] = ' '; - inbuf[*bp] = '\0'; - } - } - - /* just redraw input line */ - os_printf("%s%s", PROMPT, inbuf); -} -/* Get an input line. -* -* Returns: 1 if there is input, 0 if the line should be ignored. */ -static int get_input(char *inbuf, unsigned int *bp) -{ - if (inbuf == NULL) { - os_printf("inbuf_null\r\n"); - return 0; - } - - while (cli_getchar(&inbuf[*bp]) == 1) { -#if CONFIG_BKREG - if ((0x01U == (UINT8)inbuf[*bp]) && (*bp == 0)) { - (*bp)++; - continue; - } else if ((0xe0U == (UINT8)inbuf[*bp]) && (*bp == 1)) { - (*bp)++; - continue; - } else if ((0xfcU == (UINT8)inbuf[*bp]) && (*bp == 2)) { - (*bp)++; - continue; - } else { - if ((0x01U == (UINT8)inbuf[0]) - && (0xe0U == (UINT8)inbuf[1]) - && (0xfcU == (UINT8)inbuf[2]) - && (*bp == 3)) { - uint8_t ch = inbuf[*bp]; - uint8_t left = ch, len = 4 + (uint8_t)ch; - inbuf[*bp] = ch; - (*bp)++; - - if (ch >= INBUF_SIZE) { - os_printf("Error: input buffer overflow\r\n"); - os_printf(PROMPT); - *bp = 0; - return 0; - } - - while (left--) { - if (0 == cli_getchar((char *)&ch)) - break; - - inbuf[*bp] = ch; - (*bp)++; - } - - bkreg_run_command(inbuf, len); - os_memset(inbuf, 0, len); - *bp = 0; - continue; - } - } -#endif - if (inbuf[*bp] == RET_CHAR) - continue; - if (inbuf[*bp] == END_CHAR) { /* end of input line */ - inbuf[*bp] = '\0'; - *bp = 0; - return 1; - } - - if ((inbuf[*bp] == 0x08) || /* backspace */ - (inbuf[*bp] == 0x7f)) { /* DEL */ - if (*bp > 0) { - (*bp)--; - if (!pCli->echo_disabled) - os_printf("%c %c", 0x08, 0x08); - } - continue; - } - - if (inbuf[*bp] == '\t') { - inbuf[*bp] = '\0'; - tab_complete(inbuf, bp); - continue; - } - - if (!pCli->echo_disabled) - os_printf("%c", inbuf[*bp]); - - (*bp)++; - if (*bp >= INBUF_SIZE) { - os_printf("Error: input buffer overflow\r\n"); - os_printf(PROMPT); - *bp = 0; - return 0; - } - } - - return 0; -} - -/* Print out a bad command string, including a hex -* representation of non-printable characters. -* Non-printable characters show as "\0xXX". -*/ -static void print_bad_command(char *cmd_string) -{ - if (cmd_string != NULL) { - char *c = cmd_string; - os_printf("command '"); - while (*c != '\0') { - if (is_print(*c)) - os_printf("%c", *c); - else - os_printf("\\0x%x", *c); - ++c; - } - os_printf("' not found\r\n"); - } -} - -/* Main CLI processing thread -* -* Waits to receive a command buffer pointer from an input collector, and -* then processes. Note that it must cleanup the buffer when done with it. -* -* Input collectors handle their own lexical analysis and must pass complete -* command lines to CLI. -*/ -void icu_struct_dump(void); - -static void cli_main(uint32_t data) -{ - - char *msg = NULL; - int ret; - -#if CONFIG_RF_OTA_TEST - demo_sta_app_init("CMW-AP", "12345678"); -#endif /* CONFIG_RF_OTA_TEST*/ - - bk_uart_enable_rx_interrupt(CONFIG_UART_PRINT_PORT); - - while (1) { - - if (get_input(pCli->inbuf, &pCli->bp)) { - msg = pCli->inbuf; - - if (os_strcmp(msg, EXIT_MSG) == 0) - break; - - ret = handle_input(msg); - if (ret == 1) - print_bad_command(msg); - else if (ret == 2) - os_printf("syntax error\r\n"); - - os_printf(PROMPT); - } - } - - os_printf("CLI exited\r\n"); - os_free(pCli); - pCli = NULL; - - rtos_delete_thread(NULL); -} - -#endif // #if (!CONFIG_SHELL_ASYNCLOG) - -void help_command(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv); -void cli_sort_command(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv); - -extern const struct cli_command * cli_debug_cmd_table(int *num); - -void cli_debug_command(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - int i, tbl_num = 0; - const struct cli_command *cmd_tbl; - - if (argc < 2) - { - if(pcWriteBuffer != NULL) - strcpy(&pcWriteBuffer[0], "argc < 2\r\n"); - return; - } - - cmd_tbl = cli_debug_cmd_table(&tbl_num); - - i = lookup_cmd_table(cmd_tbl, tbl_num, argv[1], 0); - - if (i < 0) - { - if(pcWriteBuffer != NULL) - sprintf(&pcWriteBuffer[0], "cmd: %s NOT found.\r\n", argv[1]); - return; - } - - cmd_tbl[i].function(pcWriteBuffer, xWriteBufferLen , argc - 1, &argv[1]); - -} - -static void log_setting_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - int echo_level; - int level; - int sync_lvl; - - if (argc > 1) - { - echo_level = strtoul(argv[1], NULL, 0); - -#if (CONFIG_SHELL_ASYNCLOG) - shell_echo_set(echo_level); -#else - if(echo_level) - echo_level = 0; - else - echo_level = 1; - pCli->echo_disabled = echo_level; -#endif //#if (CONFIG_SHELL_ASYNCLOG) - } - -#if (CONFIG_SHELL_ASYNCLOG) - if (argc > 2) - { - level = strtoul(argv[2], NULL, 0); - shell_set_log_level(level); - } - if (argc > 3) - { - sync_lvl = strtoul(argv[3], NULL, 0); - bk_set_printf_sync(sync_lvl); - } -#endif - -#if (CONFIG_SHELL_ASYNCLOG) - echo_level = shell_echo_get(); - level = shell_get_log_level(); - sync_lvl = bk_get_printf_sync(); - - sprintf(pcWriteBuffer, "log: echo %d, level %d, sync %d.\r\n", echo_level, level, sync_lvl); -#else - - sprintf(pcWriteBuffer,"log: echo %d.\r\n", pCli->echo_disabled ? 0 : 1); -#endif //#if (CONFIG_SHELL_ASYNCLOG) - - return; - - (void)level; - (void)sync_lvl; - -} - -#if (CONFIG_SHELL_ASYNCLOG && CONFIG_MASTER_CORE) -#if 0 -#define CPU1_CMD_BUF_SIZE 128 -static char cpu1_cmd_buf[CPU1_CMD_BUF_SIZE]; -void cli_cpu1_command(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - int i; - int buf_len = 0; - int str_len = 0; - - for(i = 1; i < argc; i++) - { - str_len = strlen(argv[i]); - if ((buf_len + str_len + 3) < CPU1_CMD_BUF_SIZE) - { - os_memcpy(&cpu1_cmd_buf[buf_len], argv[i], str_len); - buf_len += str_len; - cpu1_cmd_buf[buf_len++] = ' '; - } - else - break; - } - - cpu1_cmd_buf[buf_len++] = '\r'; - cpu1_cmd_buf[buf_len++] = '\n'; - - shell_cmd_forward(cpu1_cmd_buf, buf_len); -} -#endif - -/* it is a new implementation of the cli_cpu1_command, combine cpu1 cmd & paramters into argv[0] buffer. */ -void cli_cpu1_command(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - int i, j; - int buf_len = 0; - int str_len = 0; - - for(i = 1; i < argc; i++) - { - str_len = strlen(argv[i]); - for(j = 0; j < str_len; j++) - { - if(argv[i][j] == ' ') - { - break; - } - } - - if(j < str_len) /* contains ' ' in string. */ - { - argv[0][buf_len++] = '"'; - for(j = 0; j < str_len; j++) - { - if(argv[i][j] == '"') - { - argv[0][buf_len++] = '\\'; - } - argv[0][buf_len++] = argv[i][j]; - } - argv[0][buf_len++] = '"'; - } - else - { - memcpy(&argv[0][buf_len], argv[i], str_len); - buf_len += str_len; - argv[0][buf_len++] = ' '; - } - } - - argv[0][buf_len++] = '\r'; - argv[0][buf_len++] = '\n'; - - shell_cmd_forward(argv[0], buf_len); -} - -#endif - -#if (CONFIG_SHELL_ASYNCLOG) -void cli_log_statist(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - int data_cnt, i, buf_len = 0; - u32 log_statist[5]; - data_cnt = shell_get_log_statist(log_statist, ARRAY_SIZE(log_statist)); - - if(data_cnt == 0) - { - strcpy(pcWriteBuffer, "\r\n Nothing \r\n"); - return; - } - - buf_len = sprintf(&pcWriteBuffer[0], "\r\nlog overflow: %d.", log_statist[0]); - buf_len += sprintf(&pcWriteBuffer[buf_len], "\r\nlog out count: %d.", log_statist[1]); - - for(i = 2; i < data_cnt; i++) - { - buf_len += sprintf(&pcWriteBuffer[buf_len], "\r\nBuffer[%d] run out count: %d.", i - 2, log_statist[i]); - } - - return; - -} - -static void cli_log_disable(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - if (argc < 3) - { - int i = 0, buf_len = 0; - char * mod_name; - - buf_len = sprintf(&pcWriteBuffer[0], "Usage: modlog tag_name on/off\r\n"); - - while(1) - { - mod_name = bk_get_disable_mod(&i); - - if(mod_name != NULL) - { - if(buf_len == 0) - { - buf_len = sprintf(&pcWriteBuffer[0], "disabled mod list:\r\n%s\r\n", mod_name); - } - else - { - buf_len += sprintf(&pcWriteBuffer[buf_len], "%s\r\n", mod_name); - } - } - else - break; - } - - return; - } - - if (!os_strcasecmp(argv[2], "on")) - { - bk_disable_mod_printf(argv[1], 0); - } - else if (!os_strcasecmp(argv[2], "off")) - { - bk_disable_mod_printf(argv[1], 1); - } -} -#endif - -#if CONFIG_BKREG -#define BKCMD_RXSENS_R 'r' -#define BKCMD_RXSENS_X 'x' -#define BKCMD_RXSENS_s 's' - -#define BKCMD_TXEVM_T 't' -#define BKCMD_TXEVM_X 'x' -#define BKCMD_TXEVM_E 'e' - -void bkreg_cmd_handle_input(char *inbuf, int len) -{ - if (((char)BKREG_MAGIC_WORD0 == inbuf[0]) - && ((char)BKREG_MAGIC_WORD1 == inbuf[1]) - && ((char)BKREG_MAGIC_WORD2 == inbuf[2])) { - if (cli_getchars(inbuf, len)) { - bkreg_run_command(inbuf, len); - os_memset(inbuf, 0, len); - } - } else if ((((char)BKCMD_RXSENS_R == inbuf[0]) - && ((char)BKCMD_RXSENS_X == inbuf[1]) - && ((char)BKCMD_RXSENS_s == inbuf[2])) - || (((char)BKCMD_TXEVM_T == inbuf[0]) - && ((char)BKCMD_TXEVM_X == inbuf[1]) - && ((char)BKCMD_TXEVM_E == inbuf[2]))) { - if (cli_getchars(inbuf, len)) { -#if (CONFIG_SHELL_ASYNCLOG) - handle_shell_input(inbuf, len, 0, 0); -#else //#if (CONFIG_SHELL_ASYNCLOG) - handle_input(inbuf); -#endif // #if (CONFIG_SHELL_ASYNCLOG) - os_memset(inbuf, 0, len); - } - } - -} -#endif - -static const struct cli_command built_ins[] = { - {"help", NULL, help_command}, - {"log", "log [echo(0,1)] [level(0~5)] [sync(0,1)]", log_setting_cmd}, -// {"sort", NULL, cli_sort_command}, - {"debug", "debug cmd [param] (ex:debug help)", cli_debug_command}, -#if (CONFIG_SHELL_ASYNCLOG && CONFIG_MASTER_CORE) - {"cpu1", "cpu1 cmd (ex:cpu1 help)", cli_cpu1_command}, -#endif -#if (CONFIG_SHELL_ASYNCLOG) - {"loginfo", "log statistics.", cli_log_statist}, - {"modlog", "modlog tag_name on/off", cli_log_disable}, -#endif -}; - -static int _cli_name_cmp(const void *a, const void *b) -{ - struct cli_command *cli0, *cli1; - - cli0 = *(struct cli_command **)a; - cli1 = *(struct cli_command **)b; - - if ((NULL == a) || (NULL == b)) - return 0; - - return os_strcmp(cli0->name, cli1->name); -} - -void cli_sort_command(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - uint32_t build_in_count; - GLOBAL_INT_DECLARATION(); - - build_in_count = sizeof(built_ins) / sizeof(struct cli_command); - - os_printf("cmd_count:%d, built_in_count:%d\r\n", pCli->num_commands, build_in_count); - - GLOBAL_INT_DISABLE(); - qsort(&pCli->commands[build_in_count], pCli->num_commands - build_in_count, sizeof(struct cli_command *), _cli_name_cmp); - GLOBAL_INT_RESTORE(); -} - -/* Built-in "help" command: prints all registered commands and their help -* text string, if any. */ -void help_command(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - int i, n; - uint32_t build_in_count = sizeof(built_ins) / sizeof(struct cli_command); - -#if (DEBUG) - build_in_count++; //For command: micodebug -#endif - - os_printf("====Build-in Commands====\r\n"); - for (i = 0, n = 0; i < MAX_COMMANDS && n < pCli->num_commands; i++) { - if (pCli->commands[i]->name) { - if (pCli->commands[i]->help) - os_printf("%s: %s\r\n", pCli->commands[i]->name, - pCli->commands[i]->help ? - pCli->commands[i]->help : ""); - else - os_printf("%s\r\n", pCli->commands[i]->name); - - n++; - if (n == build_in_count) - os_printf("\r\n====User Commands====\r\n"); - - if((n & 0x0f) == 0) - rtos_delay_milliseconds(50); - } - } -} - -int cli_register_command(const struct cli_command *command) -{ - int i; - if (!command->name || !command->function) - return 1; - - if (pCli->num_commands < MAX_COMMANDS) { - /* Check if the command has already been registered. - * Return 0, if it has been registered. - */ - for (i = 0; i < pCli->num_commands; i++) { - if (pCli->commands[i] == command) - return 0; - } - pCli->commands[pCli->num_commands++] = command; - return 0; - } - - return 1; -} - -int cli_unregister_command(const struct cli_command *command) -{ - int i; - if (!command->name || !command->function) - return 1; - - for (i = 0; i < pCli->num_commands; i++) { - if (pCli->commands[i] == command) { - pCli->num_commands--; - int remaining_cmds = pCli->num_commands - i; - if (remaining_cmds > 0) { - os_memmove(&pCli->commands[i], &pCli->commands[i + 1], - (remaining_cmds * - sizeof(struct cli_command *))); - } - pCli->commands[pCli->num_commands] = NULL; - return 0; - } - } - - return 1; -} - - -int cli_register_commands(const struct cli_command *commands, int num_commands) -{ - int i; - for (i = 0; i < num_commands; i++) - if (cli_register_command(commands++)) - return 1; - return 0; -} - -int cli_unregister_commands(const struct cli_command *commands, - int num_commands) -{ - int i; - for (i = 0; i < num_commands; i++) - if (cli_unregister_command(commands++)) - return 1; - - return 0; -} - -/* ========= CLI input&output APIs ============ */ -int cli_printf(const char *msg, ...) -{ - va_list ap; - char *pos, message[256]; - int sz; - int nMessageLen = 0; - - os_memset(message, 0, 256); - pos = message; - - sz = 0; - va_start(ap, msg); - nMessageLen = vsnprintf(pos, 256 - sz, msg, ap); - va_end(ap); - - if (nMessageLen <= 0) return 0; - - cli_putstr((const char *)message); - return 0; -} - -int cli_putstr(const char *msg) -{ - if (msg[0] != 0) - uart_write_string(CLI_UART, msg); - return 0; -} - -int cli_getchar(char *inbuf) -{ - if (bk_uart_read_bytes(CLI_UART, inbuf, 1, CLI_GETCHAR_TIMEOUT) > 0) - return 1; - else - return 0; -} - -int cli_getchars(char *inbuf, int len) -{ - if (bk_uart_read_bytes(CLI_UART, inbuf, len, CLI_GETCHAR_TIMEOUT) > 0) - return 1; - else - return 0; -} - -int cli_getchars_prefetch(char *inbuf, int len) -{ - return 0; -} - -int cli_get_all_chars_len(void) -{ - return uart_get_length_in_buffer(CLI_UART); -} - -static const struct cli_command user_clis[] = { -}; - -beken_thread_t cli_thread_handle = NULL; -int bk_cli_init(void) -{ - int ret; - - pCli = (struct cli_st *)os_malloc(sizeof(struct cli_st)); - if (pCli == NULL) - return kNoMemoryErr; - - os_memset((void *)pCli, 0, sizeof(struct cli_st)); - - if (cli_register_commands(&built_ins[0], - sizeof(built_ins) / sizeof(struct cli_command))) - goto init_general_err; - - if (cli_register_commands(user_clis, sizeof(user_clis) / sizeof(struct cli_command))) - goto init_general_err; - -#if (CLI_CFG_WIFI == 1) - cli_wifi_init(); -#endif - -#if (CLI_CFG_NETIF == 1) - cli_netif_init(); -#endif - -#if (CLI_CFG_BLE == 1) - cli_ble_init(); -#endif - -#if (CLI_CFG_MISC == 1) - cli_misc_init(); -#endif - -#if (CLI_CFG_MEM == 1) - cli_mem_init(); -#endif - -#if (CLI_CFG_AIRKISS == 1) - cli_airkiss_init(); -#endif - -#if (CLI_CFG_PHY == 1) - cli_phy_init(); -#endif - -#if (CLI_CFG_IPERF == 1) - cli_phy_init(); -#endif - -#if (CLI_CFG_TIMER == 1) - cli_timer_init(); -#endif - -#if (CLI_CFG_WDT == 1) - cli_wdt_init(); -#endif - -#if (CLI_CFG_TRNG == 1) - cli_trng_init(); -#endif - -#if (CLI_CFG_EFUSE == 1) - cli_efuse_init(); -#endif - -#if (CLI_CFG_DMA == 1) - cli_dma_init(); -#endif - -#if (CLI_CFG_GPIO == 1) - cli_gpio_init(); -#endif - -#if (CLI_CFG_OS == 1) - cli_os_init(); -#endif - -#if (CLI_CFG_OTA == 1) - cli_ota_init(); -#endif - -#if (CLI_CFG_FLASH == 1) - cli_flash_init(); -#endif - -#if (CLI_CFG_FLASH == 1) - cli_flash_test_init(); -#endif - -#if (CLI_CFG_SDIO_HOST == 1) - cli_sdio_host_init(); -#endif - -#if (CLI_CFG_KEYVALUE == 1) - cli_keyVaule_init(); -#endif - -#if (CLI_CFG_MATTER == 1) - cli_matter_init(); -#endif - -#if (CLI_CFG_UART == 1) - cli_uart_init(); -#endif - -#if (CLI_CFG_SPI == 1) - cli_spi_init(); -#endif - -#if (CLI_CFG_QSPI == 1) - cli_qspi_init(); -#endif - -#if (CONFIG_AON_RTC_TEST == 1) - cli_aon_rtc_init(); -#endif - -#if (CLI_CFG_I2C == 1) - cli_i2c_init(); -#endif - -#if (CLI_CFG_JPEGENC == 1) - cli_jpeg_init(); -#endif - -#if (CLI_CFG_ADC == 1) - cli_adc_init(); -#endif - -#if (CLI_CFG_SD == 1) - cli_sd_init(); -#endif - -#if (CLI_FATFS == 1) - cli_fatfs_init(); -#endif - -#if (CLI_CFG_TEMP_DETECT == 1) - cli_temp_detect_init(); -#endif - -#if (CLI_CFG_SECURITY == 1) - cli_security_init(); -#endif - -#if (CLI_CFG_MICO == 1) - cli_mico_init(); -#endif - -#if (CLI_CFG_EVENT == 1) - cli_event_init(); -#endif - -#if (CLI_CFG_PWR == 1) - cli_pwr_init(); -#endif - -#if (CLI_CFG_REG == 1) - cli_reg_init(); -#endif - -#if CONFIG_CAMERA - if (video_demo_register_cmd()) - goto init_general_err; -#endif -#if (CONFIG_SOC_BK7271) -#if CONFIG_BT - bk7271_ble_cli_init(); -#endif -#if CONFIG_USB_HOST - bk7271_dsp_cli_init(); -#endif -#endif - -#if (CONFIG_SOC_BK7256XX) -#if CONFIG_USB_HOST - usb_cli_init(); -#endif -#endif - -#if (CLI_CFG_PWM == 1) - cli_pwm_init(); -#endif - -#if (CLI_CFG_IPERF == 1) - cli_iperf_init(); -#endif - -#if CONFIG_LWIP - cli_lwip_init(); -#endif - -#if (CLI_CFG_EXCEPTION == 1) - cli_exception_init(); -#endif - -#if (CLI_CFG_ICU == 1) - cli_icu_init(); -#endif - -#if (CLI_CFG_VAULT == 1) - cli_vault_init(); -#endif - -#if (CLI_CFG_AUD == 1) - cli_aud_init(); -#endif - -#if (CLI_CFG_AUD_INTF == 1) - cli_aud_intf_init(); -#endif - -#if (CLI_CFG_AUD_CP0 == 1) - cli_aud_cp0_init(); -#endif - -#if (CLI_CFG_FFT == 1) - cli_fft_init(); -#endif - -#if (CLI_CFG_SBC == 1) - cli_sbc_init(); -#endif - -#if (CLI_CFG_I2S == 1) - cli_i2s_init(); -#endif - -#if (CONFIG_TOUCH) - cli_touch_init(); -#endif - -#if (CLI_CFG_LCD == 1) - cli_lcd_init(); -#endif - -#if (CLI_CFG_DMA2D == 1) - cli_dma2d_init(); -#endif - -#if (CLI_CFG_CALENDAR == 1) - cli_calendar_init(); -#endif - -#if (CLI_CFG_UVC == 1) - cli_uvc_init(); -#endif - -#if (CONFIG_AT_CMD) - cli_at_init(); -#endif - -#if (CLI_CFG_JPEGDEC == 1) - cli_jpegdec_init(); -#endif - -#if (CLI_CFG_AEC == 1) - cli_aec_init(); -#endif - -#if (CLI_CFG_G711 == 1) - cli_g711_init(); -#endif - -#if (CLI_CFG_MP3 == 1) - cli_mp3_init(); -#endif - -#if (CLI_CFG_DVP == 1) - cli_dvp_init(); -#endif - -#if (CONFIG_DOORBELL == 1) -//#if (CONFIG_DUAL_CORE) - cli_doorbell_init(); -//#endif -#endif - -#if (CONFIG_MEDIA == 1) - media_cli_init(); -#endif - -#if (CLI_CFG_PSRAM) - cli_psram_init(); -#endif - - - /* sort cmds after registered all cmds. */ - cli_sort_command(NULL, 0, 0, NULL); - -#if CONFIG_SHELL_ASYNCLOG -#if CONFIG_ATE_TEST - ret = rtos_create_thread(&cli_thread_handle, - SHELL_TASK_PRIORITY, - "cli", - (beken_thread_function_t)cli_ate_main /*cli_main*/, - 4096, - 0); -#else - ret = rtos_create_thread(&cli_thread_handle, - SHELL_TASK_PRIORITY, - "cli", - (beken_thread_function_t)shell_task /*cli_main*/, - 4096, - 0); -#endif -#else // #if CONFIG_SHELL_ASYNCLOG - ret = rtos_create_thread(&cli_thread_handle, - BEKEN_DEFAULT_WORKER_PRIORITY, - "cli", - (beken_thread_function_t)cli_main, - 4096, - 0); -#endif // #if CONFIG_SHELL_ASYNCLOG - if (ret != kNoErr) { - os_printf("Error: Failed to create cli thread: %d\r\n", - ret); - goto init_general_err; - } - - pCli->initialized = 1; -#if (!CONFIG_SHELL_ASYNCLOG) - pCli->echo_disabled = 0; -#endif - -#if (CONFIG_SLAVE_CORE && CONFIG_MEDIA) - ret = common_mb_init(); - if (ret != kNoErr) { - os_printf("Error: Failed to create common_mb thread: %d\r\n", ret); - } -#endif - - return kNoErr; - -init_general_err: - if (pCli) { - os_free(pCli); - pCli = NULL; - } - - return kGeneralErr; -} - -#if CFG_CLI_DEBUG -void cli_show_running_command(void) -{ - if (s_running_command_index < MAX_COMMANDS) { - const struct cli_command *cmd = pCli->commands[s_running_command_index]; - - CLI_LOGI("last cli command[%d]: %s(%s)\n", s_running_command_index, cmd->name, - (s_running_status & CLI_COMMAND_IS_RUNNING) ? "running" : "stopped"); - rtos_dump_task_list(); - rtos_dump_backtrace(); - } else - CLI_LOGI("no command running\n"); -} -#endif - -// eof - diff --git a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_matter.c b/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_matter.c deleted file mode 100644 index 975d661d5a1d8a18c6f27669ba60eeaec793691c..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_matter.c +++ /dev/null @@ -1,80 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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 -#include "cli.h" -#include "flash_namespace_value.h" - - - -extern void BkQueryImageCmdHandler(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv ); -extern void BkApplyUpdateCmdHandler(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv ); -extern void ChipTest(void); - - -void matter_test(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - beken_thread_t matter_thread_handle = NULL; - - os_printf("start matter\r\n"); - rtos_create_thread(&matter_thread_handle, - BEKEN_DEFAULT_WORKER_PRIORITY, - "matter", - (beken_thread_function_t)ChipTest, - 8192, - 0); - -} - - - -#define NAMEKEY_CMD_CNT (sizeof(s_nameKey_commands) / sizeof(struct cli_command)) -static const struct cli_command s_nameKey_commands[] = -{ - { - "bk_write_data_test", "bk_write_data_test", bk_write_data_test - }, - { - "bk_read_data_test", "bk_read_data_test", bk_read_data_test - }, - { - "bk_erase_namespace_test", "bk_erase_namespace_test", bk_erase_namespace_test - }, - { - "bk_erase_name_test", "bk_erase_name_test", bk_erase_name_test - }, - { - "bk_name_data_exits", "bk_name_data_exits", bk_name_data_exits - }, - { - "bk_erase_all_test", "bk_erase_all_test", bk_erase_all_test - }, - { - "matter", "matter", matter_test - }, - { - "BkQueryImageCmdHandler", "BkQueryImageCmdHandler", BkQueryImageCmdHandler - }, - { - "BkApplyUpdateCmdHandler", "BkApplyUpdateCmdHandler", BkApplyUpdateCmdHandler - }, -}; - - -int cli_matter_init(void) -{ - return cli_register_commands(s_nameKey_commands, NAMEKEY_CMD_CNT); -} - - diff --git a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_mem.c b/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_mem.c deleted file mode 100644 index 8c620c390f9c0c5dea66d3af996755f81267b758..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_mem.c +++ /dev/null @@ -1,130 +0,0 @@ -#include -#include "cli.h" -#include -#include -#include "bk_rtos_debug.h" -#if CONFIG_PSRAM -#include -#endif - -void cli_memory_free_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - cmd_printf("free memory %d\r\n", rtos_get_free_heap_size()); -} - -void cli_memory_dump_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - int i; - uint8_t *pstart; - uint32_t start, length; - - if (argc != 3) { - cmd_printf("Usage: memdump .\r\n"); - return; - } - - start = strtoul(argv[1], NULL, 0); - length = strtoul(argv[2], NULL, 0); - pstart = (uint8_t *)start; - - for (i = 0; i < length; i++) { - cmd_printf("%02x ", pstart[i]); - if (i % 0x10 == 0x0F) - cmd_printf("\r\n"); - - } -} - -void cli_memory_set_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - os_printf("cli_memory_set_cmd\r\n"); -} - -void cli_memory_stack_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ -#if CONFIG_FREERTOS - GLOBAL_INT_DECLARATION(); - GLOBAL_INT_DISABLE(); - rtos_dump_stack_memory_usage(); - GLOBAL_INT_RESTORE(); -#endif -} - -#if CONFIG_MEM_DEBUG && CONFIG_FREERTOS -static void cli_memory_leak_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - uint32_t start_tick = 0; - uint32_t ticks_since_malloc = 0; - uint32_t seconds_since_malloc = 0; - char *task_name = NULL; - - if (argc >= 2) { - seconds_since_malloc = os_strtoul(argv[1], NULL, 10); - ticks_since_malloc = bk_get_ticks_per_second() * seconds_since_malloc; - } - - if (argc >= 3) - start_tick = os_strtoul(argv[2], NULL, 10); - - if (argc >= 4) - task_name = argv[3]; - - os_dump_memory_stats(start_tick, ticks_since_malloc, task_name); -} -#endif - -#if CONFIG_PSRAM_AS_SYS_MEMORY && CONFIG_FREERTOS -void cli_psram_malloc_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - uint8_t *pstart; - uint32_t length; - - if (argc != 2) { - cmd_printf("Usage: psram_malloc .\r\n"); - return; - } - - length = strtoul(argv[1], NULL, 0); - - pstart = (uint8_t *)psram_malloc(length); - - cmd_printf("psram_malloc ret(%p).\r\n", pstart); -} - -void cli_psram_free_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - uint8_t *pstart; - uint32_t start; - - if (argc != 2) { - cmd_printf("Usage: psram_free .\r\n"); - return; - } - - start = strtoul(argv[1], NULL, 0); - pstart = (uint8_t *)start; - cmd_printf("psram_free addr(%p).\r\n", pstart); - os_free(pstart); - -} -#endif - -#define MEM_CMD_CNT (sizeof(s_mem_commands) / sizeof(struct cli_command)) -static const struct cli_command s_mem_commands[] = { - {"memstack", "show stack memory usage", cli_memory_stack_cmd}, - {"memshow", "show free heap", cli_memory_free_cmd}, - {"memdump", " ", cli_memory_dump_cmd}, - {"memset", " [ ... ]", cli_memory_set_cmd}, -#if CONFIG_MEM_DEBUG && CONFIG_FREERTOS - {"memleak", "[show memleak", cli_memory_leak_cmd}, -#endif -#if CONFIG_PSRAM_AS_SYS_MEMORY && CONFIG_FREERTOS - {"psram_malloc", "psram_malloc ", cli_psram_malloc_cmd}, - {"psram_free", "psram_free ", cli_psram_free_cmd}, -#endif -}; - -int cli_mem_init(void) -{ - return cli_register_commands(s_mem_commands, MEM_CMD_CNT); -} diff --git a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_mico.c b/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_mico.c deleted file mode 100644 index b54b079a7140cd9449024cb6bbd0e9ba136c5b8f..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_mico.c +++ /dev/null @@ -1,30 +0,0 @@ -#include "cli.h" - -static int mico_debug_enabled; -static void micodebug_Command(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - if (argc == 1) { - os_printf("Usage: micodebug on/off. _BK_ debug is currently %s\r\n", - mico_debug_enabled ? "Enabled" : "Disabled"); - return; - } - - if (!os_strcasecmp(argv[1], "on")) { - os_printf("Enable _BK_ debug\r\n"); - mico_debug_enabled = 1; - } else if (!os_strcasecmp(argv[1], "off")) { - os_printf("Disable _BK_ debug\r\n"); - mico_debug_enabled = 0; - } -} - - -#define MICO_CMD_CNT (sizeof(s_mico_commands) / sizeof(struct cli_command)) -static const struct cli_command s_mico_commands[] = { - {"micodebug", "micodebug on/off", micodebug_Command}, -}; - -int cli_mico_init(void) -{ - return cli_register_commands(s_mico_commands, MICO_CMD_CNT); -} diff --git a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_misc.c b/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_misc.c deleted file mode 100644 index 7e18c26f688a301ed4f1bcd931403d6ec3097390..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_misc.c +++ /dev/null @@ -1,441 +0,0 @@ -#include "cli.h" -#include -#include -#include "bk_sys_ctrl.h" -#include "bk_drv_model.h" -#include "release.h" -#include -#include -#include -#include "sys_driver.h" -#include -#include -#include "gpio_driver.h" -#include -#include "bk_ps.h" -#include "bk_pm_internal_api.h" -#if CONFIG_ARCH_RISCV -#include "cache.h" -#endif - - -#if (CONFIG_EFUSE) -static void efuse_cmd_test(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv); -static void efuse_mac_cmd_test(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv); -#endif //#if (CONFIG_EFUSE) - -static void cli_misc_help(void) -{ - CLI_LOGI("pwm_driver init {26M|DCO}\n"); -#if (CONFIG_WIFI_ENABLE) - CLI_LOGI("mac , get/set mac. e.g. mac c89346000001\r\n"); -#endif - -#if (!CONFIG_SOC_BK7231) -#if (CONFIG_EFUSE) - CLI_LOGI("efuse [-r addr] [-w addr data]\r\n"); - CLI_LOGI("efusemac [-r] [-w] [mac]\r\n"); -#endif -#endif -#if (CONFIG_MASTER_CORE) - CLI_LOGI("bootcore1 boot slave core,1:start,0:stop,others:start and stop many times\r\n"); -#endif - CLI_LOGI("jtagmode get jtag mode\r\n"); - CLI_LOGI("setjtagmode set jtag mode [cpu0|cpu1] [group1|group2]\r\n"); - CLI_LOGI("[cksel] [ckdiv_core] [ckdiv_bus] [ckdiv_cpu]\r\n"); -#if CONFIG_COMMON_IO - CLI_LOGI("testcommonio test common io\r\n"); -#endif - -} - -extern volatile const uint8_t build_version[]; - -void get_version(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - CLI_LOGI("get_version\r\n"); - //os_printf("firmware version : %s", BEKEN_SDK_REV); - CLI_LOGI("firmware version : %s", build_version); -} - -void get_id(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - CLI_LOGI("get_id\r\n"); - //os_printf("id : %x_%x",sddev_control(DD_DEV_TYPE_SCTRL,CMD_GET_DEVICE_ID, NULL), sddev_control(DD_DEV_TYPE_SCTRL,CMD_GET_CHIP_ID, NULL)); - CLI_LOGI("id : %x_%x",sys_drv_get_device_id(), sys_drv_get_chip_id()); -} - -static void uptime_Command(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - CLI_LOGI("UP time %ldms\r\n", rtos_get_time()); -} - -void reboot(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - bk_reboot(); -} - -#if (!CONFIG_SOC_BK7231) -#if (CONFIG_EFUSE) -static void efuse_cmd_test(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - uint8_t addr, data; - - if (argc == 3) { - if (os_strncmp(argv[1], "-r", 2) == 0) { - hexstr2bin(argv[2], &addr, 1); - bk_efuse_read_byte(addr, &data); - CLI_LOGI("efuse read: addr-0x%02x, data-0x%02x\r\n", - addr, data); - } - } else if (argc == 4) { - if (os_strncmp(argv[1], "-w", 2) == 0) { - hexstr2bin(argv[2], &addr, 1); - hexstr2bin(argv[3], &data, 6); - CLI_LOGI("efuse write: addr-0x%02x, data-0x%02x, ret:%d\r\n", - addr, data, bk_efuse_write_byte(addr, data)); - } - } else - cli_misc_help(); -} - -static void efuse_mac_cmd_test(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ -#if CONFIG_BASE_MAC_FROM_EFUSE - uint8_t mac[6]; - - if (argc == 1) { - if (bk_get_mac(mac, MAC_TYPE_BASE) == BK_OK) - CLI_LOGI("MAC address: %02x-%02x-%02x-%02x-%02x-%02x\r\n", - mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); - } else if (argc == 2) { - if (os_strncmp(argv[1], "-r", 2) == 0) { - if (bk_get_mac(mac, MAC_TYPE_BASE) == BK_OK) - CLI_LOGI("MAC address: %02x-%02x-%02x-%02x-%02x-%02x\r\n", - mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); - } - } else if (argc == 3) { - if (os_strncmp(argv[1], "-w", 2) == 0) { - hexstr2bin(argv[2], mac, 6); - CLI_LOGI("Set MAC address: %02x-%02x-%02x-%02x-%02x-%02x\r\n", - mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); - } - } else - CLI_LOGI("efusemac [-r] [-w] [mac]\r\n"); -#else - CLI_LOGI("base mac is not from efuse\n"); -#endif -} -#endif //#if (CONFIG_EFUSE) -#endif //(!CONFIG_SOC_BK7231) - -#if (CONFIG_WIFI_ENABLE) -static void mac_command(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - uint8_t base_mac[BK_MAC_ADDR_LEN] = {0}; - uint8_t sta_mac[BK_MAC_ADDR_LEN] = {0}; - uint8_t ap_mac[BK_MAC_ADDR_LEN] = {0}; - - if (argc == 1) { - BK_LOG_ON_ERR(bk_get_mac(base_mac, MAC_TYPE_BASE)); - BK_LOG_ON_ERR(bk_wifi_sta_get_mac(sta_mac)); - BK_LOG_ON_ERR(bk_wifi_ap_get_mac(ap_mac)); - CLI_LOGI("base mac: "BK_MAC_FORMAT"\n", BK_MAC_STR(base_mac)); - CLI_LOGI("sta mac: "BK_MAC_FORMAT"\n", BK_MAC_STR(sta_mac)); - CLI_LOGI("ap mac: "BK_MAC_FORMAT"\n", BK_MAC_STR(ap_mac)); - } else if (argc == 2) { - hexstr2bin(argv[1], base_mac, BK_MAC_ADDR_LEN); - bk_set_base_mac(base_mac); - CLI_LOGI("set base mac: "BK_MAC_FORMAT"\n", BK_MAC_STR(base_mac)); - } else - cli_misc_help(); - -} -#endif //#if (CONFIG_WIFI_ENABLE) - -#if (CONFIG_MASTER_CORE) -//extern void reset_slave_core(uint32 offset, uint32_t reset_value); -extern void start_slave_core(void); -extern void stop_slave_core(void); -static void boot_slave_core(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ -#if (CONFIG_SLAVE_CORE_OFFSET && CONFIG_SLAVE_CORE_RESET_VALUE) - //uint32 offset = CONFIG_SLAVE_CORE_OFFSET; - uint32_t reset_value = CONFIG_SLAVE_CORE_RESET_VALUE; - - if (argc == 2) { - reset_value = os_strtoul(argv[1], NULL, 10); - } - - //reset_slave_core(offset, reset_value); - if(reset_value == 1) - start_slave_core(); - else if(reset_value == 0) - stop_slave_core(); - else //test start/stop many times. - { - uint32_t i = 0; - - //start first:odd will be at start status, even will be at stop status - while(1) - { - start_slave_core(); - i++; - if(i == reset_value) - break; - stop_slave_core(); - i++; - if(i == reset_value) - break; - } - CLI_LOGI("boot on/off %d times.\r\n", reset_value); - } - -#endif - CLI_LOGI("boot_slave_core end.\r\n"); -} -#endif - -static void get_jtag_mode(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - uint32 jtag_mode = sys_drv_get_jtag_mode(); - - CLI_LOGI("get_jtag_mode: %d.\r\n", jtag_mode); -} - -static void set_jtag_mode(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - if (argc < 3) { - cli_misc_help(); - return; - } - - uint32_t cksel_core = 3; - uint32_t ckdiv_core = 3; - uint32_t ckdiv_bus = 0; - uint32_t ckdiv_cpu0 = 0; - uint32_t ckdiv_cpu1 = 0; - - if (argc > 3) - cksel_core = os_strtoul(argv[3], NULL, 10); - if (argc > 4) - ckdiv_core = os_strtoul(argv[4], NULL, 10); - if (argc > 5) - ckdiv_bus = os_strtoul(argv[5], NULL, 10); - - if (os_strcmp(argv[1], "cpu0") == 0) { - (void)sys_drv_set_jtag_mode(0); - CLI_LOGI("gpio Jtag CPU0\r\n"); - if (argc > 6) { - ckdiv_cpu0 = os_strtoul(argv[6], NULL, 10); - if((ckdiv_bus != ckdiv_cpu0)) { - CLI_LOGI("Please set [ckdiv_bus == ckdiv_cpu0]\r\n"); - return; - } - } - } else if (os_strcmp(argv[1], "cpu1") == 0) { - (void)sys_drv_set_jtag_mode(1); - CLI_LOGI("gpio Jtag CPU1\r\n"); - if (argc > 6) { - ckdiv_cpu1 = os_strtoul(argv[6], NULL, 10); - if((ckdiv_bus != ckdiv_cpu1)) { - CLI_LOGI("Please set [ckdiv_bus == ckdiv_cpu1]\r\n"); - return; - } - } - } else { - cli_misc_help(); - } - - CLI_LOGI("[cksel:%d] [ckdiv_core:%d] [ckdiv_bus:%d] [ckdiv_cpu0:%d] [ckdiv_cpu1:%d]\r\n", - cksel_core, ckdiv_core, ckdiv_bus, ckdiv_cpu0, ckdiv_cpu1); - pm_core_bus_clock_ctrl(cksel_core, ckdiv_core, ckdiv_bus, ckdiv_cpu0, ckdiv_cpu1); - - /*close watchdog*/ - extern void wdt_debug_disable(void); - wdt_debug_disable(); -#if CONFIG_INT_WDT - bk_wdt_stop(); -#endif -#if CONFIG_TASK_WDT - bk_task_wdt_stop(); -#endif - -#if CONFIG_CHANGE_JTAG_GPIO - - if (os_strcmp(argv[2], "group1") == 0) { - gpio_jtag_sel(0); - CLI_LOGD("gpio Jtag group1\r\n"); - } else if (os_strcmp(argv[2], "group2") == 0) { - gpio_jtag_sel(1); - CLI_LOGD("gpio Jtag group2\r\n"); - } else - cli_misc_help(); -#endif - - CLI_LOGI("set_jtag_mode end.\r\n"); -} - -#if CONFIG_COMMON_IO -extern int common_io_test_main(int argc, const char * argv[]); -void test_common_io(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - CLI_LOGI("common io test begin.===================.\r\n"); - common_io_test_main(0, NULL); - CLI_LOGI("common io test end.====================.\r\n"); -} -#endif - -#if CONFIG_ARCH_RISCV -extern void show_pmp_config(void); -static void pmp_command(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - if (argc == 2) { - if (os_strncmp(argv[1], "test1", 5) == 0) { - int *test_ptr = NULL; - *test_ptr = 0x12345678; - return; - } - if (os_strncmp(argv[1], "test2", 5) == 0) { - int *test_ptr = (int *)0x10000000; //itcm - *test_ptr = 0x12345678; - return; - } - } - - os_printf("pmp test, get/test1/test2 pmp. e.g. pmp test\r\n"); - show_pmp_config(); -} -#endif - -void set_printf_uart_port(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - unsigned char uart_port = 0; - - if (argc != 2) { - os_printf("set log/shell uart port 0/1/2"); - return; - } - - uart_port = os_strtoul(argv[1], NULL, 10); - os_printf("set_printf_uart_port: %d.\r\n", uart_port); - - if (uart_port < UART_ID_MAX) { -#if CONFIG_SHELL_ASYNCLOG - shell_set_uart_port(uart_port); -#else - bk_set_printf_port(uart_port); -#endif - } else { - os_printf("uart_port must be 0/1/2.\r\n"); - } - - os_printf("uart_port end.\r\n"); -} - -#if CONFIG_CACHE_ENABLE -static void prvBUS(void) { - union { - char a[10]; - int i; - } u; - - int *p = (int *) &(u.a[1]); - os_printf("prvBUS() enter(%x).\n", &(u.a[1])); - os_printf("prvBUS() p(%x).\n", p); - *p = 17; - os_printf("prvBUS() left().\n"); -} - - -void show_cache_config(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - show_cache_config_info(); - - prvBUS(); -} -#endif - -#if CONFIG_ADC_KEY -static void adc_key_next_cb() -{ - os_printf("adc_key_next_cb NEXT\r\n"); -} -static void adc_key_prev_cb() -{ - os_printf("adc_key_prev_cb PREV\r\n"); -} -static void adc_key_play_pause_cb() -{ - os_printf("adc_key_play_pause_cb PLAY PAUSE\r\n"); -} -static void adc_key_menu_cb() -{ - os_printf("adc_key_menu_cb MENU\r\n"); -} -static void cli_adc_key_op(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - if (argc < 2) { - os_printf("cli_adc_key_op please init/deinit"); - return; - } - if (os_strcmp(argv[1], "init") == 0) { - adc_key_init(); - adc_key_register_next_cb(adc_key_next_cb); - adc_key_register_prev_cb(adc_key_prev_cb); - adc_key_register_play_pause_cb(adc_key_play_pause_cb); - adc_key_register_menu_cb(adc_key_menu_cb); - CLI_LOGI("adc_key init\n"); - } else if(os_strcmp(argv[1], "deinit") == 0) { - adc_key_deinit(); - CLI_LOGI("adc_key deinit\n"); - } else if(os_strcmp(argv[1], "set_int") == 0) { - int type = os_strtoul(argv[2], NULL, 10); - adc_key_set_gpio_int_type(type); - CLI_LOGI("adc_key SET_GPIO_INT_TYPE\n"); - } else { - return; - } -} -#endif - -#define MISC_CMD_CNT (sizeof(s_misc_commands) / sizeof(struct cli_command)) -static const struct cli_command s_misc_commands[] = { - {"version", NULL, get_version}, - {"id", NULL, get_id}, - {"reboot", "reboot system", reboot}, - {"time", "system time", uptime_Command}, -#if (CONFIG_WIFI_ENABLE) - {"mac", "mac , get/set mac. e.g. mac c89346000001", mac_command}, -#endif - -#if (!CONFIG_SOC_BK7231) -#if (CONFIG_EFUSE) - {"efuse", "efuse [-r addr] [-w addr data]", efuse_cmd_test}, - {"efusemac", "efusemac [-r] [-w] [mac]", efuse_mac_cmd_test}, -#endif //#if (CONFIG_EFUSE) -#endif -#if (CONFIG_MASTER_CORE) - {"bootcore1", "boot slave core,1:start,0:stop,others:start and stop many times", boot_slave_core}, -#endif - {"jtagmode", "get jtag mode", get_jtag_mode}, - {"setjtagmode", "set jtag mode {cpu0|cpu1} {group1|group2}", set_jtag_mode}, -#if CONFIG_COMMON_IO - {"testcommonio", "test common io", test_common_io}, -#endif -#if CONFIG_ARCH_RISCV - {"pmp", "pmp test, get/test pmp. e.g. pmp test", pmp_command}, -#endif - {"setprintport", "set log/shell uart port 0/1/2", set_printf_uart_port}, -#if CONFIG_CACHE_ENABLE - {"cache", "show cache config info", show_cache_config}, -#endif -#if CONFIG_ADC_KEY - {"adc_key", "adc_key {init|deinit}", cli_adc_key_op}, -#endif -}; - -int cli_misc_init(void) -{ - return cli_register_commands(s_misc_commands, MISC_CMD_CNT); -} diff --git a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_mp3.c b/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_mp3.c deleted file mode 100755 index 5290ca0bb938328682523e78ae6cc90c97f55e43..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_mp3.c +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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 "cli.h" - -extern void cli_mp3_decode_test_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv); -extern void cli_mp3_play_test_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv); - - -#define MP3_CMD_CNT (sizeof(s_mp3_commands) / sizeof(struct cli_command)) -static const struct cli_command s_mp3_commands[] = { - {"mp3_decode_test", "mp3_decode_test {start|stop} xx.mp3 xx.pcm", cli_mp3_decode_test_cmd}, - {"mp3_play_test", "mp3_play_test {start|stop} xx.mp3", cli_mp3_play_test_cmd}, -}; - -int cli_mp3_init(void) -{ - return cli_register_commands(s_mp3_commands, MP3_CMD_CNT); -} - diff --git a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_netif.c b/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_netif.c deleted file mode 100644 index e4526fb7731118d8e35701783975a4a2c11150bd..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_netif.c +++ /dev/null @@ -1,226 +0,0 @@ -#include "bk_cli.h" -#include "wlan_defs_pub.h" -#include "bk_private/bk_wifi_wrapper.h" -#if CONFIG_LWIP -#if CONFIG_HARMONY_LWIP -#include "ping.h" -#else -#include "lwip/ping.h" -#endif - -#endif -#include -#include "cli.h" - -extern void make_tcp_server_command(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv); - -#define CLI_DUMP_IP(_prompt, _ifx, _cfg) do {\ - CLI_LOGI("%s netif(%s) ip4=%s mask=%s gate=%s dns=%s\n", (_prompt),\ - (_ifx) == NETIF_IF_STA ? "sta" : "ap",\ - (_cfg)->ip, (_cfg)->mask, (_cfg)->gateway, (_cfg)->dns);\ -} while(0) - -#if (CLI_CFG_NETIF == 1) - -static void ip_cmd_show_ip(int ifx) -{ - netif_ip4_config_t config; - - if (ifx == NETIF_IF_STA || ifx == NETIF_IF_AP) { - BK_LOG_ON_ERR(bk_netif_get_ip4_config(ifx, &config)); - CLI_DUMP_IP(" ", ifx, &config); - } else { - BK_LOG_ON_ERR(bk_netif_get_ip4_config(NETIF_IF_STA, &config)); - CLI_DUMP_IP(" ", NETIF_IF_STA, &config); - BK_LOG_ON_ERR(bk_netif_get_ip4_config(NETIF_IF_AP, &config)); - CLI_DUMP_IP(" ", NETIF_IF_AP, &config); - } -} - -void cli_ip_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - netif_ip4_config_t config = {0}; - int ifx = NETIF_IF_COUNT; - - if (argc > 1) { - if (os_strcmp("sta", argv[1]) == 0) { - ifx = NETIF_IF_STA; - } else if (os_strcmp("ap", argv[1]) == 0) { - ifx = NETIF_IF_AP; - } else { - CLI_LOGE("invalid netif name\n"); - return; - } - } - - if (argc == 1) { - ip_cmd_show_ip(NETIF_IF_COUNT); - } else if (argc == 2) { - ip_cmd_show_ip(ifx); - } else if (argc == 6) { - os_strncpy(config.ip, argv[2], NETIF_IP4_STR_LEN); - os_strncpy(config.mask, argv[3], NETIF_IP4_STR_LEN); - os_strncpy(config.gateway, argv[4], NETIF_IP4_STR_LEN); - os_strncpy(config.dns, argv[5], NETIF_IP4_STR_LEN); - BK_LOG_ON_ERR(bk_netif_set_ip4_config(ifx, &config)); - CLI_DUMP_IP("set static ip, ", ifx, &config); - } else { - CLI_LOGE("usage: ip [sta|ap][{ip}{mask}{gate}{dns}]\n"); - } -} - -#if CONFIG_IPV6 -static void ip6_cmd_show_ip(int ifx) -{ - if (ifx == NETIF_IF_STA || ifx == NETIF_IF_AP) { - bk_netif_get_ip6_addr_info(ifx); - } else { - CLI_LOGI("[sta]\n"); - bk_netif_get_ip6_addr_info(NETIF_IF_STA); - CLI_LOGI("[ap]\n"); - bk_netif_get_ip6_addr_info(NETIF_IF_AP); - } -} - -void cli_ip6_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) - -{ - int ifx = NETIF_IF_COUNT; - - if (argc > 1) { - if (os_strcmp("sta", argv[1]) == 0) { - ifx = NETIF_IF_STA; - } else if (os_strcmp("ap", argv[1]) == 0) { - ifx = NETIF_IF_AP; - } else { - CLI_LOGE("invalid netif name\n"); - return; - } - } - - if (argc == 1) { - ip6_cmd_show_ip(NETIF_IF_COUNT); - } else if (argc == 2) { - ip6_cmd_show_ip(ifx); - } -} -#endif - -void cli_dhcpc_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - BK_LOG_ON_ERR(bk_netif_dhcpc_start(NETIF_IF_STA)); - CLI_LOGI("STA start dhcp client\n"); -} - -void arp_Command(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - os_printf("arp_Command\r\n"); -} - -void cli_ping_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ -#if 0 //CONFIG_LWIP - uint32_t cnt = 4; - if (argc == 1) { - os_printf("Please input: ping \n"); - return; - } - if (argc == 2 && (os_strcmp("--stop", argv[1]) == 0)) { - ping_stop(); - return; - } - if (argc > 2) - cnt = os_strtoul(argv[2], NULL, 10); - - os_printf("ping IP address:%s\n", argv[1]); - ping_start(argv[1], cnt, 0); -#endif -} - -#if CONFIG_ALI_MQTT -extern void test_mqtt_start(const char *host_name, const char *username, - const char *password, const char *topic); -void cli_ali_mqtt_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - os_printf("start test mqtt...\n"); - if (argc == 4) { - test_mqtt_start(argv[1], argv[2], argv[3], NULL); - } else if (argc == 5) { - test_mqtt_start(argv[1], argv[2], argv[3], argv[4]); - } else { - // mqttali 222.71.10.2 aclsemi ****** /aclsemi/bk7256/cmd/1234 - CLI_LOGE("usage: mqttali [host name|ip] [username] [password] [topic]\n"); - } -} -#endif - -#if CONFIG_HTTP -extern void LITE_openlog(const char *ident); -extern void LITE_closelog(void); -void cli_http_debug_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - uint32 http_log = 0; - - if (argc == 2) { - http_log = os_strtoul(argv[1], NULL, 10); - if (1 == http_log ) { - LITE_openlog("http"); - } else { - LITE_closelog(); - } - } else { - CLI_LOGE("usage: httplog [1|0].\n"); - } -} -#endif - -uint32_t g_per_packet_info_output_bitmap = 0; - -void set_per_packet_info_output_bitmap(const char *bitmap) -{ - g_per_packet_info_output_bitmap = os_strtoul(bitmap, NULL, 16); - CLI_LOGI("set per_packet_info_output_bitmap:0x%x\n",g_per_packet_info_output_bitmap); -} - -void cli_per_packet_info_output_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - if (argc == 2) { - set_per_packet_info_output_bitmap(argv[1]); - } else { - CLI_LOGE("usage: per_packet_info [per_packet_info_output_bitmap(base 16)]\n"); - } -} - - -#define NETIF_CMD_CNT (sizeof(s_netif_commands) / sizeof(struct cli_command)) -static const struct cli_command s_netif_commands[] = { - {"ip", "ip [sta|ap][{ip}{mask}{gate}{dns}]", cli_ip_cmd}, - {"dhcpc", "dhcpc", cli_dhcpc_cmd}, - {"ping", "ping ", cli_ping_cmd}, -#ifdef CONFIG_IPV6 - {"ping6", "ping6 xxx", cli_ping_cmd}, - {"ip6", "ip6 [sta|ap][{ip}{state}]", cli_ip6_cmd}, -#endif -#ifdef TCP_CLIENT_DEMO - {"tcp_cont", "tcp_cont [ip] [port]", tcp_make_connect_server_command}, -#endif - -#if CONFIG_TCP_SERVER_TEST - {"tcp_server", "tcp_server [ip] [port]", make_tcp_server_command }, -#endif -#if CONFIG_ALI_MQTT - {"mqttali", "paho mqtt test", cli_ali_mqtt_cmd}, -#endif -#if CONFIG_OTA_HTTP - {"httplog", "httplog [1|0].", cli_http_debug_cmd}, -#endif - {"per_packet_info", "per_packet_info [per_packet_info_output_bitmap(base 16)]", cli_per_packet_info_output_cmd}, - -}; - -int cli_netif_init(void) -{ - return cli_register_commands(s_netif_commands, NETIF_CMD_CNT); -} - -#endif //#if (CLI_CFG_NETIF == 1) diff --git a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_os.c b/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_os.c deleted file mode 100644 index 9f643e28c88a4ef51da71d7cb1b96b2861a900e2..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_os.c +++ /dev/null @@ -1,58 +0,0 @@ -#include "cli.h" -#include -#include "bk_rtos_debug.h" - -static void cli_task_list_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - rtos_dump_task_list(); -} - -static void cli_task_cpuload_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ -#if CONFIG_FREERTOS - rtos_dump_task_runtime_stats(); -#endif -} - -static void cli_task_backtrace_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - rtos_dump_backtrace(); -} - -static void cli_os_info_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - rtos_dump_backtrace(); - rtos_dump_task_list(); - -#if CONFIG_FREERTOS - rtos_dump_task_runtime_stats(); -#endif - -#if CONFIG_FREERTOS && CONFIG_MEM_DEBUG - os_dump_memory_stats(0, 0, NULL); -#endif - -#if CONFIG_FREERTOS_V10 - extern void port_check_isr_stack(void); - port_check_isr_stack(); -#endif -} - -static void cli_assert_dump_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - BK_ASSERT(false); -} - -#define OS_CMD_CNT (sizeof(s_os_commands) / sizeof(struct cli_command)) -static const struct cli_command s_os_commands[] = { - {"tasklist", "list tasks", cli_task_list_cmd}, - {"cpuload", "show task cpu load", cli_task_cpuload_cmd}, - {"backtrace", "show task backtrace", cli_task_backtrace_cmd}, - {"osinfo", "show os runtime information", cli_os_info_cmd}, - {"assert", "asset and dump system information", cli_assert_dump_cmd}, -}; - -int cli_os_init(void) -{ - return cli_register_commands(s_os_commands, OS_CMD_CNT); -} diff --git a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_ota.c b/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_ota.c deleted file mode 100644 index ed66e2381d451506c2dcfb8760858a0c8557eddd..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_ota.c +++ /dev/null @@ -1,131 +0,0 @@ -#include "cli.h" -#include "bk_private/bk_wifi.h" -#include -#if CONFIG_OTA_HTTP -#include "utils_httpc.h" -#endif - -#if CONFIG_OTA_TFTP - -extern void tftp_start(void); -extern void string_to_ip(char *s); -static void tftp_ota_get_Command(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - short len = 0, i; - extern char BootFile[] ; - - if (argc > 3) { - os_printf("ota server_ip ota_file\r\n"); - return; - } - - os_printf("%s\r\n", argv[1]); - - os_strcpy(BootFile, argv[2]); - os_printf("%s\r\n", BootFile); - string_to_ip(argv[1]); - - - tftp_start(); - - return; - -} -#endif - -#ifdef CONFIG_HTTP_AB_PARTITION - part_flag update_part_flag; -#endif -#if CONFIG_OTA_HTTP -int http_ota_download(const char *uri) -{ - int ret; - httpclient_t httpclient; - httpclient_data_t httpclient_data; - char http_content[HTTP_RESP_CONTENT_LEN]; - - CLI_LOGI("http_ota_download :0x%x",http_ota_download); - - //__asm volatile ("j ."); -#ifdef CONFIG_HTTP_AB_PARTITION - bk_logic_partition_t *bk_ptr =NULL; - int exec_part_sta_addr = 0; - int exec_part_len = 0; - int this_func_adr = 0; - - this_func_adr = (int)http_ota_download; - CLI_LOGI("this_func_adr :0x%x",http_ota_download); - - bk_ptr = bk_flash_partition_get_info(BK_PARTITION_APPLICATION); - CLI_LOGI("bk_ptr :0x%x",bk_ptr); - //__asm volatile ("j ."); - exec_part_sta_addr = (bk_ptr->partition_start_addr)*INS_NO_CRC_CHUNK/INS_CRC_CHUNK; - exec_part_len = (bk_ptr->partition_length)*INS_NO_CRC_CHUNK/INS_CRC_CHUNK; - CLI_LOGI("exec_part_sta_addr :0x%x,exec_part_len :0x%x",exec_part_sta_addr,exec_part_len); - if((this_func_adr > exec_part_sta_addr)&&(this_func_adr < (exec_part_len + exec_part_len))) - { - CLI_LOGI("12345"); - update_part_flag = UPDATE_B_PART; - } - else - update_part_flag = UPDATE_A_PART; -#endif - - os_memset(&httpclient, 0, sizeof(httpclient_t)); - os_memset(&httpclient_data, 0, sizeof(httpclient_data)); - os_memset(&http_content, 0, sizeof(HTTP_RESP_CONTENT_LEN)); - httpclient.header = "Accept: text/xml,text/html,\r\n"; - httpclient_data.response_buf = http_content; - httpclient_data.response_content_len = HTTP_RESP_CONTENT_LEN; - ret = httpclient_common(&httpclient, - uri, - 80,/*port*/ - NULL, - HTTPCLIENT_GET, - 180000, - &httpclient_data); - - if (0 != ret) - CLI_LOGI("request epoch time from remote server failed."); - else { - CLI_LOGI("sucess.\r\n"); - bk_reboot(); - } - - return ret; -} - -void http_ota_Command(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - int ret; - if (argc != 2) - goto HTTP_CMD_ERR; - ret = http_ota_download(argv[1]); - - if (0 != ret) - os_printf("http_ota download failed."); - - return; - -HTTP_CMD_ERR: - os_printf("Usage:http_ota [url:]\r\n"); -} -#endif - - -#define OTA_CMD_CNT (sizeof(s_ota_commands) / sizeof(struct cli_command)) -static const struct cli_command s_ota_commands[] = { - -#if CONFIG_OTA_TFTP - {"tftpota", "tftpota [ip] [file]", tftp_ota_get_Command}, -#endif - -#if CONFIG_OTA_HTTP - {"http_ota", "http_ota url", http_ota_Command}, -#endif -}; - -int cli_ota_init(void) -{ - return cli_register_commands(s_ota_commands, OTA_CMD_CNT); -} diff --git a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_phy.c b/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_phy.c deleted file mode 100644 index 8ca47c844a282b9fec610c7435325646760c5033..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_phy.c +++ /dev/null @@ -1,77 +0,0 @@ -#include "cli.h" -#include "bk_phy.h" - -#if CONFIG_POWER_TABLE -extern void pwr_tbl_command(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv); -#endif - -#if (CLI_CFG_PHY == 1) - -static void phy_cca_test(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - if (argc != 2) { - os_printf("cca open\r\n"); - os_printf("cca close\r\n"); - os_printf("cca show\r\n"); - return; - } - - if (os_strncmp(argv[1], "open", 4) == 0) { - phy_open_cca(); - os_printf("cca opened\r\n"); - } else if (os_strncmp(argv[1], "close", 4) == 0) { - phy_close_cca(); - os_printf("cca closed\r\n"); - } else if (os_strncmp(argv[1], "show", 4) == 0) - phy_show_cca(); - else { - os_printf("cca open\r\n"); - os_printf("cca close\r\n"); - os_printf("cca show\r\n"); - } -} - -#if (CONFIG_SOC_BK7256XX) -extern void cmd_saradc_auto_test(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv); -extern void cmd_sigtest(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv); - -#endif -#define PHY_CMD_CNT (sizeof(s_phy_commands) / sizeof(struct cli_command)) -static const struct cli_command s_phy_commands[] = { - {"cca", "cca open\\close\\show", phy_cca_test}, - - {"txevm", "txevm [-m] [-c] [-l] [-r] [-w]", tx_evm_cmd_test}, - {"rxsens", "rxsens [-m] [-d] [-c] [-l]", rx_sens_cmd_test}, - - -#if ((!CONFIG_SOC_BK7231) && (!CONFIG_SOC_BK7271)) - {"rfcali_cfg_mode", "1:manual, 0:auto", cmd_rfcali_cfg_mode}, - {"rfcali_cfg_tssi_g", "0-255", cmd_rfcali_cfg_tssi_g}, - {"rfcali_cfg_tssi_b", "0-255", cmd_rfcali_cfg_tssi_b}, - {"rfcali_show_data", "", cmd_rfcali_show_data}, - {"rfcali_cfg_rate_dist", "b g n40 ble (0-31)", cmd_rfcali_cfg_rate_dist}, -#if (CONFIG_SOC_BK7256XX) - {"cali", "cali auto_test", cmd_cali}, -#if CONFIG_PSRAM - {"psram", "psram enable clk_div", cmd_psram}, -#endif - {"saradc", "start close", cmd_saradc_auto_test}, - {"sigtest", "sigtest enable format_mod mcs_index", cmd_sigtest}, - - -#endif -#endif -#if CONFIG_POWER_TABLE - {"pwrtbl", "pwrtbl cal/set/get ", pwr_tbl_command}, -#endif -#if ((CONFIG_SOC_BK7256XX) || (CONFIG_SOC_BK7236A)) - {"la", "bk7256:la rf_adc/fe_adc/rf_dac/fe_dac;bk7236a:la rx_adc/rx_dac/tx_dac", cmd_la_sample_test}, -#endif -}; - -int cli_phy_init(void) -{ - return cli_register_commands(s_phy_commands, PHY_CMD_CNT); -} - -#endif //#if (CLI_CFG_PHY == 1) diff --git a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_psram.c b/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_psram.c deleted file mode 100755 index 8120e37dc2c634e2e537ddbce0f70296f0683de2..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_psram.c +++ /dev/null @@ -1,322 +0,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 -// -// 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 "cli.h" - -#include -#include -#include -#include "bk_general_dma.h" - - -typedef enum { - PSRAM_START = 0, - PSRAM_STOP, -}cmd_type_t; - -typedef struct { - uint8_t type; - uint32_t data; -}psram_msg_t; - - -extern u64 riscv_get_mtimer(void); - -#define ITERATIONS 1024 - -#define PSRAM_QITEM_COUNT (30) - - -#define write_data(addr,val) *((volatile uint32_t *)(addr)) = val -#define read_data(addr,val) val = *((volatile uint32_t *)(addr)) -#define get_addr_data(addr) *((volatile uint32_t *)(addr)) - -beken_thread_t psram_thread_hdl = NULL; -beken_queue_t psram_msg_que = NULL; - -uint32_t *test_data = NULL; - -uint8_t test_mode = 0; - -static void cli_psram_help(void) -{ - CLI_LOGI("psram_test {start|stop}\n"); -} - -bk_err_t psram_send_msg(uint8_t type, uint32_t data) -{ - bk_err_t ret; - psram_msg_t msg; - - if (psram_msg_que) { - msg.type = type; - msg.data = data; - - ret = rtos_push_to_queue(&psram_msg_que, &msg, BEKEN_NO_WAIT); - if (kNoErr != ret) { - CLI_LOGE("send_msg failed\r\n"); - return kOverrunErr; - } - - return ret; - } - return kNoResourcesErr; -} - -static void psram_test(void) -{ - uint32_t i = 0; - uint32_t error_num = 0; - uint64_t timer0, timer1; - uint32_t total_time = 0; - uint32_t test_len = ITERATIONS * 1024 * 2; - - uint32_t value = 0; - CLI_LOGI("begin write 0x60000000, len:8Mbyte\r\n"); - timer0 = riscv_get_mtimer(); - for (i = 0; i < test_len; i++) - write_data((0x60000000 + i * 0x4), 0x11111111 + i); - - timer1 = riscv_get_mtimer(); - total_time = (uint32_t) (timer1 - timer0)/26000; - CLI_LOGI("finish write, use time: %ld ms, write_rate:%ld Kbyte/ms\r\n", total_time, test_len * 4 / total_time); - - CLI_LOGI("begin read 0x60000000, len:8Mbyte\r\n"); - timer0 = riscv_get_mtimer(); - for (i = 0; i < test_len; i++) - read_data((0x60000000 + i * 0x4), value); - - timer1 = riscv_get_mtimer(); - total_time = (uint32_t) (timer1 - timer0)/26000; - CLI_LOGI("finish read, use time: %ld ms, read_rate:%ld Kbyte/ms\r\n", total_time, test_len * 4 / total_time); - - CLI_LOGI("begin compare 0x60000000, len:8Mbyte\r\n"); - - for (i = 0; i < test_len; i++) - { - value = get_addr_data(0x60000000 + i * 0x4); - if (value != (0x11111111 + i)) - error_num++; - } - - CLI_LOGI("finish cpmpare, error_num: %ld, corr_rate: %ld.\r\n", error_num, ((test_len - error_num) * 100 / test_len)); - - rtos_delay_milliseconds(1000); - psram_send_msg(PSRAM_START, 0); -} - -#include "soc/mapping.h" -static void psram_test_unit(void) -{ - uint32_t i = 0; - uint32_t error_num = 0; - uint64_t timer0, timer1; - uint32_t total_time = 0; - uint32_t start_address = (uint32_t)&psram_map->aud_adc[0]; - uint32_t end_address = (8 * 1024 * 1024 + 0x64000000); - uint32_t test_len = (end_address - start_address) / 4; - - uint32_t value = 0; - CLI_LOGI("begin write %08X-%08X, count: %d\n", start_address, end_address, test_len); - timer0 = riscv_get_mtimer(); - for (i = 0; i < test_len; i++) - write_data((start_address + i * 0x4), 0x11111111 + i); - - timer1 = riscv_get_mtimer(); - total_time = (uint32_t) (timer1 - timer0)/26000; - CLI_LOGI("finish write, use time: %ld ms, write_rate:%ld Kbyte/ms\n", total_time, test_len * 4 / total_time); - - CLI_LOGI("begin write %08X-%08X, count: %d\n", start_address, end_address, test_len); - timer0 = riscv_get_mtimer(); - for (i = 0; i < test_len; i++) - read_data((start_address + i * 0x4), value); - - timer1 = riscv_get_mtimer(); - total_time = (uint32_t) (timer1 - timer0)/26000; - CLI_LOGI("finish read, use time: %ld ms, read_rate:%ld Kbyte/ms\n", total_time, test_len * 4 / total_time); - - CLI_LOGI("begin write %08X-%08X, count: %d\n", start_address, end_address, test_len); - - for (i = 0; i < test_len; i++) - { - value = get_addr_data(start_address + i * 0x4); - if (value != (0x11111111 + i)) - error_num++; - } - - CLI_LOGI("finish cpmpare, error_num: %ld, corr_rate: %ld\n", error_num, ((test_len - error_num) * 100 / test_len)); - - rtos_delay_milliseconds(1000); - psram_send_msg(PSRAM_START, 0); -} - -static void psram_test_main(void) -{ - bk_err_t ret = kNoErr; - - if (test_data == NULL) - { - test_data = (uint32_t *)os_malloc(1024 * 4); - if (test_data == NULL) - goto exit; - } - - psram_send_msg(PSRAM_START, 0); - - while (1) - { - psram_msg_t msg; - ret = rtos_pop_from_queue(&psram_msg_que, &msg, BEKEN_WAIT_FOREVER); - - if (kNoErr == ret) - { - switch(msg.type) - { - case PSRAM_START: - if (test_mode == 1) - { - psram_test_unit(); - } - else - { - psram_test(); - } - break; - case PSRAM_STOP: - goto exit; - break; - - default: - break; - } - - } - } - -exit: - - if (test_data) - { - os_free(test_data); - test_data = NULL; - } - - rtos_deinit_queue(&psram_msg_que); - psram_msg_que = NULL; - - psram_thread_hdl = NULL; - rtos_delete_thread(NULL); -} - -static bk_err_t psram_task_init(void) -{ - bk_err_t ret = kNoErr; - - ret = bk_psram_init(); - if (ret != kNoErr) - { - CLI_LOGE("psram init failed!\r\n"); - return ret; - } - - if ((!psram_thread_hdl) && (!psram_msg_que)) - { - ret = rtos_init_queue(&psram_msg_que, - "psram_queue", - sizeof(psram_msg_t), - PSRAM_QITEM_COUNT); - if (kNoErr != ret) - { - CLI_LOGE("ceate queue failed\r\n"); - return kGeneralErr; - } - - ret = rtos_create_thread(&psram_thread_hdl, - 4, - "video_intf", - (beken_thread_function_t)psram_test_main, - 4 * 1024, - (beken_thread_arg_t)NULL); - if (ret != kNoErr) - { - rtos_deinit_queue(&psram_msg_que); - psram_msg_que = NULL; - psram_thread_hdl = NULL; - CLI_LOGE("Error: Failed to create psram test task: %d\r\n", ret); - return kGeneralErr; - } - - return kNoErr; - } - else - return kInProgressErr; -} - -static void cli_psram_cmd_handle(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - bk_err_t ret = kNoErr; - - if (os_strcmp(argv[1], "1") == 0) - { - test_mode = 1; - } - - if (os_strcmp(argv[1], "start") == 0) - { - ret = psram_task_init(); - if (ret != kNoErr) - { - CLI_LOGE("psram test failed!\r\n"); - } - - CLI_LOGI("psram test start success!\r\n"); - } - else if (os_strcmp(argv[1], "stop") == 0) - { - if (psram_thread_hdl) - { - psram_send_msg(PSRAM_STOP, 0); - } - else - { - CLI_LOGI("psram test have been stopped or not started!\r\n"); - return; - } - - while (psram_thread_hdl) - { - rtos_delay_milliseconds(10); - } - - CLI_LOGI("psram test stop success!\r\n"); - } - else - { - cli_psram_help(); - return; - } -} - - -#define PSRAM_CNT (sizeof(s_psram_commands) / sizeof(struct cli_command)) -static const struct cli_command s_psram_commands[] = { - {"psram_test", "start|stop", cli_psram_cmd_handle}, - -}; - -int cli_psram_init(void) -{ - return cli_register_commands(s_psram_commands, PSRAM_CNT); -} - - diff --git a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_pwm.c b/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_pwm.c deleted file mode 100644 index 645975a44fcd06d6087ab5139185aea17e927ab5..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_pwm.c +++ /dev/null @@ -1,313 +0,0 @@ -#include "cli.h" -#include -#include -#include "pwm_hal.h" - -#if CONFIG_PWM - -static void cli_pwm_help(void) -{ - CLI_LOGI("pwm_driver init {26M|DCO}\n"); - CLI_LOGI("pwm_driver deinit\n"); - CLI_LOGI("pwm {chan} init {period_v} {duty_v} [duty1_v][duty2_v][duty3_v]\n"); - CLI_LOGI("pwm {chan} {start|stop|deinit}\n"); - CLI_LOGI("pwm {chan} duty {period_v} {duty1_v} [duty2_v] [duty3_v]\n"); - CLI_LOGI("pwm {chan} signal {low|high}\n"); - CLI_LOGI("pwm_group init {chan1} {chan2} {period} {chan1_duty} {chan2_duty}\n"); - CLI_LOGI("pwm_group {start|stop|deinit}\n"); - CLI_LOGI("pwm_group config {group} {period} {chan1_duty} {chan2_duty}\n"); - CLI_LOGI("pwm_int {chan} {reg|enable|disable}\n"); - CLI_LOGI("pwm_capture {chan} {init}\nn"); - CLI_LOGI("pwm_capture {chan} {start|stop|deinit}\n"); - CLI_LOGI("pwm_idle_test {idle_start|idle_stop}\n"); -} - -static void cli_pwm_timer_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ -} - -static void cli_pwm_counter_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ -} - -static void cli_pwm_carrier_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ -} - -static void cli_pwm_driver_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - if (argc < 2) { - cli_pwm_help(); - return; - } - - if (os_strcmp(argv[1], "init") == 0) { - BK_LOG_ON_ERR(bk_pwm_driver_init()); - CLI_LOGI("pwm init\n"); - } else if (os_strcmp(argv[1], "deinit") == 0) { - BK_LOG_ON_ERR(bk_pwm_driver_deinit()); - CLI_LOGI("pwm deinit\n"); - } else { - cli_pwm_help(); - return; - } -} - -static void cli_pwm_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - uint32_t chan; - - if (argc < 2) { - cli_pwm_help(); - return; - } - - chan = os_strtoul(argv[1], NULL, 10); - - if (os_strcmp(argv[2], "init") == 0) { - CLI_RET_ON_INVALID_ARGC(argc, 5); - pwm_init_config_t config = {0}; - - config.period_cycle = os_strtoul(argv[3], NULL, 10); - config.duty_cycle = os_strtoul(argv[4], NULL, 10); - if (argc > 5) - config.duty2_cycle = os_strtoul(argv[5], NULL, 10); - if (argc > 6) - config.duty3_cycle = os_strtoul(argv[6], NULL, 10); - - BK_LOG_ON_ERR(bk_pwm_init(chan, &config)); - CLI_LOGI("pwm init, chan=%d period=%x duty=%x\n", chan, config.period_cycle, config.duty_cycle); - } else if (os_strcmp(argv[2], "start") == 0) { - BK_LOG_ON_ERR(bk_pwm_start(chan)); - CLI_LOGI("pwm start, chan=%d\n", chan); - } else if (os_strcmp(argv[2], "stop") == 0) { - BK_LOG_ON_ERR(bk_pwm_stop(chan)); - CLI_LOGI("pwm stop, chan=%d\n", chan); - } else if (os_strcmp(argv[2], "deinit") == 0) { - BK_LOG_ON_ERR(bk_pwm_deinit(chan)); - CLI_LOGI("pwm deinit, chan=%d\n", chan); - } else if (os_strcmp(argv[2], "signal") == 0) { - if (argc != 4) { - cli_pwm_help(); - return; - } - - if (os_strcmp(argv[3], "low") == 0) - BK_LOG_ON_ERR(bk_pwm_set_init_signal_low(chan)); - else - BK_LOG_ON_ERR(bk_pwm_set_init_signal_high(chan)); - CLI_LOGI("pwm set signal, chan=%d\n", chan); - } else if (os_strcmp(argv[2], "duty") == 0) { - pwm_period_duty_config_t config = {0}; - if (argc < 5) { - cli_pwm_help(); - return; - } - - config.period_cycle = os_strtoul(argv[3], NULL, 10); - config.duty_cycle = os_strtoul(argv[4], NULL, 10); - if (argc > 5) - config.duty2_cycle = os_strtoul(argv[5], NULL, 10); - if (argc > 6) - config.duty3_cycle = os_strtoul(argv[6], NULL, 10); - BK_LOG_ON_ERR(bk_pwm_set_period_duty(chan, &config)); - CLI_LOGI("pwm duty, chan=%d period=%x t1=%x t2=%x t3=%x\n", chan, config.period_cycle, - config.duty_cycle, config.duty2_cycle, config.duty3_cycle); - } else { - cli_pwm_help(); - return; - } -} - -static void cli_pwm_group_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - uint32_t group; - - if (argc < 2) { - cli_pwm_help(); - return; - } - - group = os_strtoul(argv[2], NULL, 10); - - if (os_strcmp(argv[1], "init") == 0) { - if (argc != 7) { - cli_pwm_help(); - return; - } - pwm_group_init_config_t config = {0}; - pwm_group_t group = 0; - - config.chan1 = os_strtoul(argv[2], NULL, 10); - config.chan2 = os_strtoul(argv[3], NULL, 10); - config.period_cycle = os_strtoul(argv[4], NULL, 10); - config.chan1_duty_cycle = os_strtoul(argv[5], NULL, 10); - config.chan2_duty_cycle = os_strtoul(argv[6], NULL, 10); - BK_LOG_ON_ERR(bk_pwm_group_init(&config, &group)); - CLI_LOGI("pwm init, group=%d chan1=%d chan2=%d period=%x d1=%x d2=%x\n", - group, config.chan1, config.chan2, config.period_cycle, - config.chan1_duty_cycle, config.chan2_duty_cycle); - } else if (os_strcmp(argv[1], "start") == 0) { - BK_LOG_ON_ERR(bk_pwm_group_start(group)); - CLI_LOGI("pwm start, group=%d\n", group); - } else if (os_strcmp(argv[1], "stop") == 0) { - BK_LOG_ON_ERR(bk_pwm_group_stop(group)); - CLI_LOGI("pwm stop, group=%d\n", group); - } else if (os_strcmp(argv[1], "deinit") == 0) { - BK_LOG_ON_ERR(bk_pwm_group_deinit(group)); - CLI_LOGI("pwm deinit, group=%d\n", group); - } else if (os_strcmp(argv[1], "config") == 0) { - pwm_group_config_t config = {0}; - if (argc != 5) { - cli_pwm_help(); - return; - } - - config.period_cycle = os_strtoul(argv[2], NULL, 10); - config.chan1_duty_cycle = os_strtoul(argv[3], NULL, 10); - config.chan2_duty_cycle = os_strtoul(argv[4], NULL, 10); - BK_LOG_ON_ERR(bk_pwm_group_set_config(group, &config)); - CLI_LOGI("pwm config, group=%x period=%x chan1_duty=%x chan2_duty=%x\n", - group, config.period_cycle, config.chan1_duty_cycle, config.chan2_duty_cycle); - } else { - cli_pwm_help(); - return; - } -} - - -static void cli_pwm_isr(pwm_chan_t chan) -{ - CLI_LOGI("isr(%d)\n", chan); -} - -static void cli_pwm_capture_isr(pwm_chan_t chan) -{ - CLI_LOGI("capture(%d), value=%x\n", chan, bk_pwm_capture_get_value(chan)); -} - -static void cli_pwm_int_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - uint32_t chan; - - if (argc != 3) { - cli_pwm_help(); - return; - } - - chan = os_strtoul(argv[1], NULL, 10); - - if (os_strcmp(argv[2], "reg") == 0) { - BK_LOG_ON_ERR(bk_pwm_register_isr(chan, cli_pwm_isr)); - CLI_LOGI("pwm chan%d register interrupt isr\n", chan); - } else if (os_strcmp(argv[2], "enable") == 0) { - BK_LOG_ON_ERR(bk_pwm_enable_interrupt(chan)); - CLI_LOGI("pwm chan%d enable interrupt\n", chan); - } else if (os_strcmp(argv[2], "disable") == 0) { - BK_LOG_ON_ERR(bk_pwm_disable_interrupt(chan)); - CLI_LOGI("pwm chan%d disable interrupt\n", chan); - } else { - cli_pwm_help(); - return; - } -} - -static void cli_pwm_capture_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - uint32_t chan; - - if (argc < 2) { - cli_pwm_help(); - return; - } - - chan = os_strtoul(argv[1], NULL, 10); - - if (os_strcmp(argv[2], "init") == 0) { - CLI_RET_ON_INVALID_ARGC(argc, 4); - pwm_capture_init_config_t config = {0}; - if (os_strcmp(argv[3], "pos") == 0) - config.edge = PWM_CAPTURE_POS; - else if (os_strcmp(argv[3], "neg") == 0) - config.edge = PWM_CAPTURE_NEG; - else if (os_strcmp(argv[3], "edge") == 0) - config.edge = PWM_CAPTURE_EDGE; - else { - cli_pwm_help(); - return; - } - - config.isr = cli_pwm_capture_isr; - BK_LOG_ON_ERR(bk_pwm_capture_init(chan, &config)); - CLI_LOGI("pwm_capture init, chan=%d\n", chan); - } else if (os_strcmp(argv[2], "start") == 0) { - BK_LOG_ON_ERR(bk_pwm_capture_start(chan)); - CLI_LOGI("pwm_capture start, chan=%d\n", chan); - } else if (os_strcmp(argv[2], "stop") == 0) { - BK_LOG_ON_ERR(bk_pwm_capture_stop(chan)); - CLI_LOGI("pwm_capture stop, chan=%d\n", chan); - } else if (os_strcmp(argv[2], "deinit") == 0) { - BK_LOG_ON_ERR(bk_pwm_capture_deinit(chan)); - CLI_LOGI("pwm_capture deinit, chan=%d\n", chan); - } else { - cli_pwm_help(); - return; - } -} - -static void cli_pwm_idle_test_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - if (argc < 2) { - cli_pwm_help(); - return; - } - - if (os_strcmp(argv[1], "idle_start") == 0) { - BK_LOG_ON_ERR(bk_pwm_driver_init()); - CLI_LOGI("pwm driver init\n"); - - pwm_init_config_t config = {0}; - - config.period_cycle = 10; - config.duty_cycle = 5; - config.duty2_cycle = 0; - config.duty3_cycle = 0; - - for(int chan = 0; chan < SOC_PWM_CHAN_NUM_PER_UNIT; chan++) { - BK_LOG_ON_ERR(bk_pwm_init(chan, &config)); - BK_LOG_ON_ERR(bk_pwm_start(chan)); - CLI_LOGI("pwm init, chan=%d period=%x duty=%x\n", chan, config.period_cycle, config.duty_cycle); - } - } else if (os_strcmp(argv[1], "idle_stop") == 0) { - for(int chan = 0; chan < SOC_PWM_CHAN_NUM_PER_UNIT; chan++) { - BK_LOG_ON_ERR(bk_pwm_stop(chan)); - BK_LOG_ON_ERR(bk_pwm_deinit(chan)); - } - - } else { - cli_pwm_help(); - return; - } -} - -#define PWM_CMD_CNT (sizeof(s_pwm_commands) / sizeof(struct cli_command)) -static const struct cli_command s_pwm_commands[] = { - {"pwm_driver", "{init|deinit} [26M|DCO]}", cli_pwm_driver_cmd}, - {"pwm", "pwm {chan} {config|start|stop|init|deinit|signal} [...]", cli_pwm_cmd}, - {"pwm_int", "pwm_int {chan} {reg|enable|disable}", cli_pwm_int_cmd}, - {"pwm_duty", "pwm_duty {chan} {period} {d1} [d2] [d3]", cli_pwm_int_cmd}, - {"pwm_capture", "pwm_capture {chan} {config|start|stop|init|deinit}", cli_pwm_capture_cmd}, - {"pwm_group", "pwm_group {init|deinit|config|start|stop} [...]", cli_pwm_group_cmd}, - {"pwm_timer", "pwm_timer ", cli_pwm_timer_cmd}, - {"pwm_counter", "pwm_counter", cli_pwm_counter_cmd}, - {"pwm_carrier", "pwm_carrier", cli_pwm_carrier_cmd}, - {"pwm_idle_test", "{idle_start|idle_stop}", cli_pwm_idle_test_cmd}, -}; - -int cli_pwm_init(void) -{ - BK_LOG_ON_ERR(bk_pwm_driver_init()); - return cli_register_commands(s_pwm_commands, PWM_CMD_CNT); -} - -#endif diff --git a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_pwr.c b/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_pwr.c deleted file mode 100644 index 01e94837e8a8f3588b115bc25b45e9dcbc94dddb..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_pwr.c +++ /dev/null @@ -1,883 +0,0 @@ -#include "cli.h" -#include "wlan_ui_pub.h" -#include "bk_manual_ps.h" -#include "bk_mac_ps.h" -#include "bk_mcu_ps.h" -#include "bk_ps.h" -#include "bk_wifi.h" -#include "modules/pm.h" -#include "sys_driver.h" -#include "bk_pm_internal_api.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include - - -#if CONFIG_MCU_PS -static void cli_ps_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ -#if PS_SUPPORT_MANUAL_SLEEP - UINT32 standby_time = 0; - UINT32 dtim_wait_time = 0; -#endif - - if (argc != 3) - goto _invalid_ps_arg; - -#if CONFIG_MCU_PS - if (0 == os_strcmp(argv[1], "mcudtim")) { - UINT32 dtim = os_strtoul(argv[2], NULL, 10); - if (dtim == 1) - bk_wlan_mcu_ps_mode_enable(); - else if (dtim == 0) - bk_wlan_mcu_ps_mode_disable(); - else - goto _invalid_ps_arg; - } -#endif -#if CONFIG_STA_PS - else if (0 == os_strcmp(argv[1], "rfdtim")) { - UINT32 dtim = os_strtoul(argv[2], NULL, 10); - if (dtim == 1) { - if (bk_wlan_ps_enable()) - os_printf("dtim enable failed\r\n"); - } else if (dtim == 0) { - if (bk_wlan_ps_disable()) - os_printf("dtim disable failed\r\n"); - } else - goto _invalid_ps_arg; - } -#if PS_USE_KEEP_TIMER - else if (0 == os_strcmp(argv[1], "rf_timer")) { - UINT32 dtim = os_strtoul(argv[2], NULL, 10); - - if (dtim == 1) { - extern int bk_wlan_ps_timer_start(void); - bk_wlan_ps_timer_start(); - } else if (dtim == 0) { - extern int bk_wlan_ps_timer_pause(void); - bk_wlan_ps_timer_pause(); - } else - goto _invalid_ps_arg; - } -#endif -#endif - else - goto _invalid_ps_arg; - - - return; - -_invalid_ps_arg: - os_printf("Usage:ps {rfdtim|mcudtim|rf_timer} {1/0}\r\n"); -} -#endif -#if CONFIG_SYSTEM_CTRL -#define PM_MANUAL_LOW_VOL_VOTE_ENABLE (0) -#define PM_DEEP_SLEEP_REGISTER_CALLBACK_ENABLE (0x1) - -static UINT32 s_cli_sleep_mode = 0; -static UINT32 s_pm_vote1 = 0; -static UINT32 s_pm_vote2 = 0; -static UINT32 s_pm_vote3 = 0; - -extern void stop_slave_core(void); -#if CONFIG_AON_RTC -static void cli_pm_rtc_callback(aon_rtc_id_t id, uint8_t *name_p, void *param) -{ - if(s_cli_sleep_mode == PM_MODE_DEEP_SLEEP)//when wakeup from deep sleep, all thing initial - { - bk_pm_sleep_mode_set(PM_MODE_DEFAULT); - } - else if(s_cli_sleep_mode == PM_MODE_LOW_VOLTAGE) - { - bk_pm_sleep_mode_set(PM_MODE_DEFAULT); - bk_pm_module_vote_sleep_ctrl(PM_SLEEP_MODULE_NAME_APP,0x0,0x0); - } - else - { - bk_pm_sleep_mode_set(PM_MODE_DEFAULT); - bk_pm_module_vote_sleep_ctrl(s_pm_vote1,0x0,0x0); - bk_pm_module_vote_sleep_ctrl(s_pm_vote2,0x0,0x0); - bk_pm_module_vote_sleep_ctrl(s_pm_vote3,0x0,0x0); - } - os_printf("cli_pm_rtc_callback\r\n"); -} -#endif -#if CONFIG_TOUCH -void cli_pm_touch_callback(void *param) -{ - if(s_cli_sleep_mode == PM_MODE_DEEP_SLEEP)//when wakeup from deep sleep, all thing initial - { - bk_pm_sleep_mode_set(PM_MODE_DEFAULT); - } - else if(s_cli_sleep_mode == PM_MODE_LOW_VOLTAGE) - { - bk_pm_sleep_mode_set(PM_MODE_DEFAULT); - bk_pm_module_vote_sleep_ctrl(PM_SLEEP_MODULE_NAME_APP,0x0,0x0); - } - else - { - bk_pm_sleep_mode_set(PM_MODE_DEFAULT); - bk_pm_module_vote_sleep_ctrl(s_pm_vote1,0x0,0x0); - bk_pm_module_vote_sleep_ctrl(s_pm_vote2,0x0,0x0); - bk_pm_module_vote_sleep_ctrl(s_pm_vote3,0x0,0x0); - } - os_printf("cli_pm_touch_callback\r\n"); -} -#endif -void cli_pm_gpio_callback(gpio_id_t gpio_id) -{ - if(s_cli_sleep_mode == PM_MODE_DEEP_SLEEP)//when wakeup from deep sleep, all thing initial - { - bk_pm_sleep_mode_set(PM_MODE_DEFAULT); - } - else if(s_cli_sleep_mode == PM_MODE_LOW_VOLTAGE) - { - bk_pm_sleep_mode_set(PM_MODE_DEFAULT); - bk_pm_module_vote_sleep_ctrl(PM_SLEEP_MODULE_NAME_APP,0x0,0x0); - } - else - { - bk_pm_sleep_mode_set(PM_MODE_DEFAULT); - bk_pm_module_vote_sleep_ctrl(s_pm_vote1,0x0,0x0); - bk_pm_module_vote_sleep_ctrl(s_pm_vote2,0x0,0x0); - bk_pm_module_vote_sleep_ctrl(s_pm_vote3,0x0,0x0); - } - os_printf("cli_pm_gpio_callback\r\n"); -} - -#define PM_MANUAL_LOW_VOL_VOTE_ENABLE (0) -extern void stop_slave_core(void); - -static void cli_pm_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - UINT32 pm_sleep_mode = 0; - UINT32 pm_vote1 = 0,pm_vote2 = 0,pm_vote3=0; - UINT32 pm_wake_source = 0; - UINT32 pm_param1 = 0,pm_param2 = 0,pm_param3 = 0; - //rtc_wakeup_param_t rtc_wakeup_param = {0}; - system_wakeup_param_t system_wakeup_param = {0}; - #if (!CONFIG_GPIO_WAKEUP_SUPPORT) && (!CONFIG_SLAVE_CORE) - gpio_wakeup_param_t gpio_wakeup_param = {0}; - #endif - #if CONFIG_TOUCH - touch_wakeup_param_t touch_wakeup_param = {0}; - #endif - usbplug_wakeup_param_t usbplug_wakeup_param = {0}; - - if (argc != 9) - { - os_printf("set low power parameter invalid %d\r\n",argc); - return; - } - pm_sleep_mode = os_strtoul(argv[1], NULL, 10); - pm_wake_source = os_strtoul(argv[2], NULL, 10); - pm_vote1 = os_strtoul(argv[3], NULL, 10); - pm_vote2 = os_strtoul(argv[4], NULL, 10); - pm_vote3 = os_strtoul(argv[5], NULL, 10); - pm_param1 = os_strtoul(argv[6], NULL, 10); - pm_param2 = os_strtoul(argv[7], NULL, 10); - pm_param3 = os_strtoul(argv[8], NULL, 10); - - os_printf("cli_pm_cmd %d %d %d %d %d %d %d!!! \r\n", - pm_sleep_mode, - pm_wake_source, - pm_vote1, - pm_vote2, - pm_vote3, - pm_param1, - pm_param2); - if((pm_sleep_mode > PM_MODE_DEFAULT)||(pm_wake_source > PM_WAKEUP_SOURCE_INT_NONE)) - { - os_printf("set low power parameter value invalid\r\n"); - return; - } - - if(pm_sleep_mode == PM_MODE_DEEP_SLEEP) - { - if((pm_vote1 > PM_POWER_MODULE_NAME_NONE) ||(pm_vote2 > PM_POWER_MODULE_NAME_NONE) ||(pm_vote3 > PM_POWER_MODULE_NAME_NONE)) - { - os_printf("set pm vote deepsleep parameter value invalid\r\n"); - return; - } - } - - if(pm_sleep_mode == PM_MODE_LOW_VOLTAGE) - { - if((pm_vote1 > PM_SLEEP_MODULE_NAME_NONE) ||(pm_vote2 > PM_SLEEP_MODULE_NAME_NONE) ||(pm_vote3 > PM_SLEEP_MODULE_NAME_NONE)) - { - os_printf("set pm vote low vol parameter value invalid\r\n"); - return; - } - } - - s_cli_sleep_mode = pm_sleep_mode; - s_pm_vote1 = pm_vote1; - s_pm_vote2 = pm_vote2; - s_pm_vote3 = pm_vote3; - - - - - /*set sleep mode*/ - //bk_pm_sleep_mode_set(pm_sleep_mode); - - /*set wakeup source*/ - if(pm_wake_source == PM_WAKEUP_SOURCE_INT_RTC) - { - //rtc_wakeup_param.period = pm_param1; - //rtc_wakeup_param.isr_callback = cli_pm_rtc_callback; - #if CONFIG_AON_RTC - alarm_info_t low_valtage_alarm = { - "low_vol", - pm_param1*RTC_TICKS_PER_1MS, - 1, - cli_pm_rtc_callback, - NULL - }; - - //force unregister previous if doesn't finish. - bk_alarm_unregister(AON_RTC_ID_1, low_valtage_alarm.name); - bk_alarm_register(AON_RTC_ID_1, &low_valtage_alarm); - #endif - bk_pm_wakeup_source_set(PM_WAKEUP_SOURCE_INT_RTC, NULL); - - } - else if(pm_wake_source == PM_WAKEUP_SOURCE_INT_GPIO) - { - #if CONFIG_GPIO_WAKEUP_SUPPORT - bk_gpio_register_isr(pm_param1, cli_pm_gpio_callback); - bk_gpio_register_wakeup_source(pm_param1,pm_param2); - bk_pm_wakeup_source_set(PM_WAKEUP_SOURCE_INT_GPIO, NULL); - #else - #if !CONFIG_SLAVE_CORE - gpio_wakeup_param.gpio_id = pm_param1; - gpio_wakeup_param.gpio_valid = PARAM_DATA_VALID; - gpio_wakeup_param.gpio_trigger_interrupt_type = pm_param2; - - bk_pm_wakeup_source_set(PM_WAKEUP_SOURCE_INT_GPIO, &gpio_wakeup_param); - #endif - #endif - } - else if(pm_wake_source == PM_WAKEUP_SOURCE_INT_SYSTEM_WAKE) - { - if(pm_param1 == WIFI_WAKEUP) - { - system_wakeup_param.wifi_bt_wakeup = WIFI_WAKEUP; - } - else - { - system_wakeup_param.wifi_bt_wakeup = BT_WAKEUP; - } - - bk_pm_wakeup_source_set(PM_WAKEUP_SOURCE_INT_SYSTEM_WAKE, &system_wakeup_param); - } - else if(pm_wake_source == PM_WAKEUP_SOURCE_INT_TOUCHED) - { - #if CONFIG_TOUCH - touch_wakeup_param.touch_channel = pm_param1; - bk_touch_register_touch_isr((1<< touch_wakeup_param.touch_channel), cli_pm_touch_callback, NULL); - bk_pm_wakeup_source_set(PM_WAKEUP_SOURCE_INT_TOUCHED, &touch_wakeup_param); - #endif - } - else if(pm_wake_source == PM_WAKEUP_SOURCE_INT_USBPLUG) - { - bk_pm_wakeup_source_set(PM_WAKEUP_SOURCE_INT_USBPLUG, &usbplug_wakeup_param); - } - else - { - ; - } - - /*vote*/ - if(pm_sleep_mode == PM_MODE_DEEP_SLEEP) - { - if(pm_vote3 == PM_POWER_MODULE_NAME_CPU1) - { - #if (CONFIG_SLAVE_CORE_OFFSET && CONFIG_SLAVE_CORE_RESET_VALUE) - stop_slave_core(); - #endif - } - - } - else if(pm_sleep_mode == PM_MODE_LOW_VOLTAGE) - { - #if PM_MANUAL_LOW_VOL_VOTE_ENABLE - if(pm_vote1 == PM_SLEEP_MODULE_NAME_APP) - { - bk_pm_module_vote_sleep_ctrl(pm_vote1,0x1,pm_param3); - } - else - { - bk_pm_module_vote_sleep_ctrl(pm_vote1,0x1,0x0); - } - - if(pm_vote2 == PM_SLEEP_MODULE_NAME_APP) - { - bk_pm_module_vote_sleep_ctrl(pm_vote2,0x1,pm_param3); - } - else - { - bk_pm_module_vote_sleep_ctrl(pm_vote2,0x1,0x0); - } - - if(pm_vote3 == PM_SLEEP_MODULE_NAME_APP) - { - bk_pm_module_vote_sleep_ctrl(pm_vote3,0x1,pm_param3); - } - else - { - bk_pm_module_vote_sleep_ctrl(pm_vote3,0x1,0x0); - } - #endif - - if((pm_vote1 == PM_SLEEP_MODULE_NAME_APP)||(pm_vote2 == PM_SLEEP_MODULE_NAME_APP)||(pm_vote3 == PM_SLEEP_MODULE_NAME_APP)) - { - bk_pm_module_vote_sleep_ctrl(PM_SLEEP_MODULE_NAME_APP,0x1,pm_param3); - } - } - else - { - ;//do something - } - - bk_pm_sleep_mode_set(pm_sleep_mode); - -} -static void cli_pm_debug(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - UINT32 pm_debug = 0; - if (argc != 2) - { - os_printf("set low power debug parameter invalid %d\r\n",argc); - return; - } - - pm_debug = os_strtoul(argv[1], NULL, 10); - - pm_debug_ctrl(pm_debug); - -} -static void cli_pm_vol(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - UINT32 pm_vol = 0; - if (argc != 2) - { - os_printf("set pm voltage parameter invalid %d\r\n",argc); - return; - } - - pm_vol = os_strtoul(argv[1], NULL, 10); - if ((pm_vol < 0) || (pm_vol > 7)) - { - os_printf("set pm voltage value invalid %d\r\n",pm_vol); - return; - } - - bk_pm_lp_vol_set(pm_vol); - -} -static void cli_pm_clk(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - UINT32 pm_clk_state = 0; - UINT32 pm_module_id = 0; - if (argc != 3) - { - os_printf("set pm clk parameter invalid %d\r\n",argc); - return; - } - - pm_module_id = os_strtoul(argv[1], NULL, 10); - pm_clk_state = os_strtoul(argv[2], NULL, 10); - if ((pm_clk_state < 0) || (pm_clk_state > 1) || (pm_module_id < 0) || (pm_module_id > 31)) - { - os_printf("set pm clk value invalid %d %d\r\n",pm_clk_state,pm_module_id); - return; - } - bk_pm_clock_ctrl(pm_module_id,pm_clk_state); - -} -static void cli_pm_power(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - UINT32 pm_power_state = 0; - UINT32 pm_module_id = 0; - if (argc != 3) - { - os_printf("set pm power parameter invalid %d\r\n",argc); - return; - } - - pm_module_id = os_strtoul(argv[1], NULL, 10); - pm_power_state = os_strtoul(argv[2], NULL, 10); - if ((pm_power_state < 0) || (pm_power_state > 1) || (pm_module_id < 0) || (pm_module_id > 31)) - { - os_printf("set pm power value invalid %d %d \r\n",pm_power_state,pm_module_id); - return; - } - - bk_pm_module_vote_power_ctrl(pm_module_id,pm_power_state); - -} -static void cli_pm_freq(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - UINT32 pm_freq = 0; - UINT32 pm_module_id = 0; - pm_cpu_freq_e module_freq = 0; - pm_cpu_freq_e current_max_freq = 0; - if (argc != 3) - { - os_printf("set pm freq parameter invalid %d\r\n",argc); - return; - } - - pm_module_id = os_strtoul(argv[1], NULL, 10); - pm_freq = os_strtoul(argv[2], NULL, 10); - if ((pm_freq < 0) || (pm_freq > 3) || (pm_module_id < 0) || (pm_module_id > PM_DEV_ID_MAX)) - { - os_printf("set pm freq value invalid %d %d \r\n",pm_freq,pm_module_id); - return; - } - - bk_pm_module_vote_cpu_freq(pm_module_id,pm_freq); - - module_freq = bk_pm_module_current_cpu_freq_get(pm_module_id); - - current_max_freq = bk_pm_current_max_cpu_freq_get(); - - os_printf("pm cpu freq test id: %d; freq: %d; current max cpu freq: %d;\r\n",pm_module_id,module_freq,current_max_freq); - -} -static void cli_pm_lpo(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - UINT32 pm_lpo = 0; - if (argc != 2) - { - os_printf("set pm lpo parameter invalid %d\r\n",argc); - return; - } - - pm_lpo = os_strtoul(argv[1], NULL, 10); - if ((pm_lpo < 0) || (pm_lpo > 3)) - { - os_printf("set pm lpo value invalid %d\r\n",pm_lpo); - return; - } - - bk_pm_lpo_src_set(pm_lpo); - -} -static void cli_pm_ctrl(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - UINT32 pm_ctrl = 0; - if (argc != 2) - { - os_printf("set pm ctrl parameter invalid %d\r\n",argc); - return; - } - - pm_ctrl = os_strtoul(argv[1], NULL, 10); - if ((pm_ctrl < 0) || (pm_ctrl > 1)) - { - os_printf("set pm ctrl value invalid %d\r\n",pm_ctrl); - return; - } - - bk_pm_mcu_pm_ctrl(pm_ctrl); - -} -static void cli_pm_pwr_state(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - UINT32 pm_pwr_module = 0; - UINT32 pm_pwr_module_state = 0; - if (argc != 2) - { - os_printf("set pm pwr state parameter invalid %d\r\n",argc); - return; - } - - pm_pwr_module = os_strtoul(argv[1], NULL, 10); - if ((pm_pwr_module < 0) || (pm_pwr_module >= PM_POWER_MODULE_NAME_NONE)) - { - os_printf("pm module[%d] not support ,get power state fail\r\n",pm_pwr_module); - return; - } - - pm_pwr_module_state = bk_pm_module_power_state_get(pm_pwr_module); - os_printf("Get module[%d] power state[%d] \r\n",pm_pwr_module,pm_pwr_module_state); - -} -static void cli_pm_auto_vote(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - UINT32 pm_ctrl = 0; - if (argc != 2) - { - os_printf("set pm auto_vote parameter invalid %d\r\n",argc); - return; - } - - pm_ctrl = os_strtoul(argv[1], NULL, 10); - if ((pm_ctrl < 0) || (pm_ctrl > 1)) - { - os_printf("set pm auto vote value invalid %d\r\n",pm_ctrl); - return; - } - - bk_pm_app_auto_vote_state_set(pm_ctrl); - -} -static void cli_pm_vote_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - UINT32 pm_sleep_mode = 0; - UINT32 pm_vote = 0; - UINT32 pm_vote_value = 0; - UINT32 pm_sleep_time = 0; - if (argc != 5) - { - os_printf("set low power vote parameter invalid %d\r\n",argc); - return; - } - pm_sleep_mode = os_strtoul(argv[1], NULL, 10); - pm_vote = os_strtoul(argv[2], NULL, 10); - pm_vote_value = os_strtoul(argv[3], NULL, 10); - pm_sleep_time = os_strtoul(argv[4], NULL, 10); - if((pm_sleep_mode > LOW_POWER_MODE_NONE)|| (pm_vote > POWER_MODULE_NAME_NONE)||(pm_vote_value > 1)) - { - os_printf("set low power vote parameter value invalid\r\n"); - return; - } - /*vote*/ - if(pm_sleep_mode == LOW_POWER_DEEP_SLEEP) - { - if((pm_vote == POWER_MODULE_NAME_BTSP)||(pm_vote == POWER_MODULE_NAME_WIFIP_MAC)) - { - bk_pm_module_vote_power_ctrl(pm_vote,pm_vote_value); - } - } - else if(pm_sleep_mode == LOW_POWER_MODE_LOW_VOLTAGE) - { - bk_pm_module_vote_sleep_ctrl(pm_vote,pm_vote_value,pm_sleep_time); - } - else - { - ;//do something - } - - -} -#define CLI_DVFS_FREQUNCY_DIV_MAX (15) -#define CLI_DVFS_FREQUNCY_DIV_BUS_MAX (1) -static void cli_dvfs_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - UINT32 cksel_core = 0; - UINT32 ckdiv_core = 0; - UINT32 ckdiv_bus = 0; - UINT32 ckdiv_cpu0 = 0; - UINT32 ckdiv_cpu1 = 0; - UINT32 clk_param = 0; - - if (argc != 6) - { - os_printf("set dvfs parameter invalid %d\r\n",argc); - return; - } - - GLOBAL_INT_DECLARATION(); - cksel_core = os_strtoul(argv[1], NULL, 10); - ckdiv_core = os_strtoul(argv[2], NULL, 10); - ckdiv_bus = os_strtoul(argv[3], NULL, 10); - ckdiv_cpu0 = os_strtoul(argv[4], NULL, 10); - ckdiv_cpu1 = os_strtoul(argv[5], NULL, 10); - - os_printf("cli_dvfs_cmd %d %d %d %d %d !!! \r\n", - cksel_core, - ckdiv_core, - ckdiv_bus, - ckdiv_cpu0, - ckdiv_cpu1); - GLOBAL_INT_DISABLE(); - if(cksel_core > 3) - { - os_printf("set dvfs cksel core > 3 invalid %d\r\n",cksel_core); - GLOBAL_INT_RESTORE(); - return; - } - - if((ckdiv_core > CLI_DVFS_FREQUNCY_DIV_MAX) || (ckdiv_bus > CLI_DVFS_FREQUNCY_DIV_BUS_MAX)||(ckdiv_cpu0 > CLI_DVFS_FREQUNCY_DIV_MAX)||(ckdiv_cpu0 > CLI_DVFS_FREQUNCY_DIV_MAX)) - { - os_printf("set dvfs ckdiv_core ckdiv_bus ckdiv_cpu0 ckdiv_cpu0 > 15 invalid\r\n"); - GLOBAL_INT_RESTORE(); - return; - } - - clk_param = 0; - clk_param = sys_drv_all_modules_clk_div_get(CLK_DIV_REG0); - if(((clk_param >> 0x4)&0x3) > cksel_core)//when it from the higher frequecy to lower frqquecy - { - /*1.core clk select*/ - clk_param = 0; - clk_param = sys_drv_all_modules_clk_div_get(CLK_DIV_REG0); - clk_param &= ~(0x3 << 4); - clk_param |= cksel_core << 4; - sys_drv_all_modules_clk_div_set(CLK_DIV_REG0,clk_param); - - /*2.config bus and core clk div*/ - clk_param = 0; - clk_param = sys_drv_all_modules_clk_div_get(CLK_DIV_REG0); - clk_param &= ~((0x1 << 6)|(0xF << 0)); - clk_param |= ckdiv_core << 0; - clk_param |= (ckdiv_bus&0x1) << 6; - sys_drv_all_modules_clk_div_set(CLK_DIV_REG0,clk_param); - - /*3.config cpu clk div*/ - sys_drv_cpu_clk_div_set(0,ckdiv_cpu0); - - sys_drv_cpu_clk_div_set(1,ckdiv_cpu1); - - } - else//when it from the lower frequecy to higher frqquecy - { - /*1.config bus and core clk div*/ - clk_param = 0; - clk_param = sys_drv_all_modules_clk_div_get(CLK_DIV_REG0); - clk_param &= ~(0xF << 0); - clk_param |= ckdiv_core << 0; - sys_drv_all_modules_clk_div_set(CLK_DIV_REG0,clk_param); - - clk_param = 0; - clk_param = sys_drv_all_modules_clk_div_get(CLK_DIV_REG0); - clk_param &= ~(0x1 << 6); - clk_param |= (ckdiv_bus&0x1) << 6; - sys_drv_all_modules_clk_div_set(CLK_DIV_REG0,clk_param); - - /*2.config cpu clk div*/ - sys_drv_cpu_clk_div_set(0,ckdiv_cpu0); - - sys_drv_cpu_clk_div_set(1,ckdiv_cpu1); - - /*3.core clk select*/ - - clk_param = 0; - clk_param = sys_drv_all_modules_clk_div_get(CLK_DIV_REG0); - clk_param &= ~(0x3 << 4); - clk_param |= cksel_core << 4; - sys_drv_all_modules_clk_div_set(CLK_DIV_REG0,clk_param); - } - GLOBAL_INT_RESTORE(); - os_printf("switch cpu frequency ok 0x%x 0x%x 0x%x\r\n",sys_drv_all_modules_clk_div_get(CLK_DIV_REG0),sys_drv_cpu_clk_div_get(0),sys_drv_cpu_clk_div_get(1)); -} -#if CONFIG_AON_RTC -static UINT32 s_pre_tick; -static void cli_pm_timer_isr(timer_id_t chan) -{ - UINT32 current_tick = 0; - current_tick = bk_aon_rtc_get_current_tick(AON_RTC_ID_1); - - os_printf("rosc accuracy count %d %d %d \r\n",current_tick - s_pre_tick,current_tick,s_pre_tick); - s_pre_tick = current_tick; -} -#endif -static void cli_pm_rosc_accuracy(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ -#if CONFIG_AON_RTC - UINT32 timer_count_interval = 0; - - if (argc != 2) - { - os_printf("set osc_accurac parameter invalid %d\r\n",argc); - return; - } - - timer_count_interval = os_strtoul(argv[1], NULL, 10); - bk_timer_start(0, timer_count_interval, cli_pm_timer_isr); -#endif -} - -#endif -#if CONFIG_MCU_PS -static void cli_deep_sleep_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - PS_DEEP_CTRL_PARAM deep_sleep_param; - - deep_sleep_param.wake_up_way = 0; - - deep_sleep_param.gpio_index_map = os_strtoul(argv[1], NULL, 16); - deep_sleep_param.gpio_edge_map = os_strtoul(argv[2], NULL, 16); - deep_sleep_param.gpio_last_index_map = os_strtoul(argv[3], NULL, 16); - deep_sleep_param.gpio_last_edge_map = os_strtoul(argv[4], NULL, 16); - deep_sleep_param.sleep_time = os_strtoul(argv[5], NULL, 16); - deep_sleep_param.wake_up_way = os_strtoul(argv[6], NULL, 16); - deep_sleep_param.gpio_stay_lo_map = os_strtoul(argv[7], NULL, 16); - deep_sleep_param.gpio_stay_hi_map = os_strtoul(argv[8], NULL, 16); - - if (argc == 9) { - os_printf("---deep sleep test param : 0x%0X 0x%0X 0x%0X 0x%0X %d %d\r\n", - deep_sleep_param.gpio_index_map, - deep_sleep_param.gpio_edge_map, - deep_sleep_param.gpio_last_index_map, - deep_sleep_param.gpio_last_edge_map, - deep_sleep_param.sleep_time, - deep_sleep_param.wake_up_way); - -#if (!CONFIG_SOC_BK7271) && (CONFIG_DEEP_PS) - bk_enter_deep_sleep_mode(&deep_sleep_param); -#endif - } else - os_printf("---argc error!!! \r\n"); -} - -void cli_mac_ps_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ -#if (CONFIG_MCU_PS | CONFIG_STA_PS) - UINT32 dtim = 0; -#endif - -#if PS_SUPPORT_MANUAL_SLEEP - UINT32 standby_time = 0; - UINT32 dtim_wait_time = 0; -#endif - - if (argc < 2) - goto _invalid_mac_ps_arg; -#if CONFIG_FAKE_RTC_PS - if (0 == os_strcmp(argv[1], "idleps")) { - GLOBAL_INT_DECLARATION(); - int count = 0; - bk_printf("[ARF]rwnxl_reset_evt\r\n"); - HAL_FATAL_ERROR_RECOVER(0); // rwnxl_reset_evt(0); - - rtos_delay_milliseconds(10); - - while (1) { - GLOBAL_INT_DISABLE(); - evt_field_t field = ke_evt_get(); - GLOBAL_INT_RESTORE(); - - if (!(field & KE_EVT_RESET_BIT)) - break; - - rtos_delay_milliseconds(10); - if (++count > 10000) { - bk_printf("%s: failed\r\n", __func__); - break; - } - } - - //bk_enable_unconditional_sleep(); - count = 100; - while ((1 == bk_unconditional_normal_sleep(0xFFFFFFFF, 1))) { - rtos_delay_milliseconds(2); - count--; - if (count == 0) { - bk_printf("IDLE_SLEEP timeout\r\n"); - break; - } - } - - bk_printf("idle Sleep out\r\n"); - } -#endif - -#if CONFIG_STA_PS - else if (0 == os_strcmp(argv[1], "rfwkup")) { - mac_ps_wakeup_immediately(); - os_printf("done.\r\n"); - } else if (0 == os_strcmp(argv[1], "bcmc")) { - if (argc != 3) - goto _invalid_mac_ps_arg; - - dtim = os_strtoul(argv[2], NULL, 10); - - if (dtim == 0 || dtim == 1) - power_save_sm_set_all_bcmc(dtim); - else - goto _invalid_mac_ps_arg; - } else if (0 == os_strcmp(argv[1], "listen")) { - if (argc != 4) - goto _invalid_mac_ps_arg; - - if (0 == os_strcmp(argv[2], "dtim")) { - dtim = os_strtoul(argv[3], NULL, 10); - power_save_set_dtim_multi(dtim); - - } else - goto _invalid_mac_ps_arg; - - } else if (0 == os_strcmp(argv[1], "dump")) { -#if CONFIG_MCU_PS - mcu_ps_dump(); -#endif - power_save_dump(); - } -#endif - else - goto _invalid_mac_ps_arg; - - return; -_invalid_mac_ps_arg: - os_printf("Usage:mac_ps {func} [param1] [param2]\r\n"); -#if CONFIG_FAKE_RTC_PS - os_printf("mac_ps {idleps}\r\n"); -#endif -#if CONFIG_STA_PS - os_printf("mac_ps {rfwkup}\r\n"); - os_printf("mac_ps {bcmc} {1|0}\r\n"); - os_printf("mac_ps {listen} {dtim} {dtim_val}\r\n"); -#endif - os_printf("mac_ps dump\r\n"); -} - -void cli_pwr_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - int pwr = 0; - - if (argc != 3) { - os_printf("Usage: pwr [hex:5~15]."); - return; - } - - pwr = os_strtoul(argv[2], NULL, 16); - if (0 == os_strcmp(argv[1], "sta")) { - bk_wifi_sta_set_power(pwr); - } else if (0 == os_strcmp(argv[1], "ap")) { - bk_wifi_ap_set_power(pwr); - } -} -#endif -#define PWR_CMD_CNT (sizeof(s_pwr_commands) / sizeof(struct cli_command)) -static const struct cli_command s_pwr_commands[] = { -#if CONFIG_MCU_PS - {"ps", "ps {rfdtim|mcudtim|rf_timer} {1|0}", cli_ps_cmd}, - {"mac_ps", "mac_ps {func} [param1] [param2]", cli_mac_ps_cmd}, - {"deep_sleep", "deep_sleep [param]", cli_deep_sleep_cmd}, -#endif -#if CONFIG_SYSTEM_CTRL - {"pm", "pm [sleep_mode] [wake_source] [vote1] [vote2] [vote3] [param1] [param2] [param3]", cli_pm_cmd}, - {"dvfs", "dvfs [cksel_core] [ckdiv_core] [ckdiv_bus] [ckdiv_cpu0] [ckdiv_cpu1]", cli_dvfs_cmd}, - {"pm_vote", "pm_vote [pm_sleep_mode] [pm_vote] [pm_vote_value] [pm_sleep_time]", cli_pm_vote_cmd}, - {"pm_debug", "pm_debug [debug_en_value]", cli_pm_debug}, - {"pm_lpo", "pm_lpo [lpo_type]", cli_pm_lpo}, - {"pm_vol", "pm_vol [vol_value]", cli_pm_vol}, - {"pm_clk", "pm_clk [module_name][clk_state]", cli_pm_clk}, - {"pm_power", "pm_power [module_name][ power state]", cli_pm_power}, - {"pm_freq", "pm_freq [module_name][ frequency]", cli_pm_freq}, - {"pm_ctrl", "pm_ctrl [ctrl_value]", cli_pm_ctrl}, - {"pm_pwr_state", "pm_pwr_state [pwr_state]", cli_pm_pwr_state}, - {"pm_auto_vote", "pm_auto_vote [auto_vote_value]", cli_pm_auto_vote}, - {"pm_rosc", "pm_rosc [rosc_accuracy_count_interval]", cli_pm_rosc_accuracy}, -#endif -#if CONFIG_TPC_PA_MAP - {"pwr", "pwr {sta|ap} pwr", cli_pwr_cmd }, -#endif -}; - -int cli_pwr_init(void) -{ - return cli_register_commands(s_pwr_commands, PWR_CMD_CNT); -} diff --git a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_qspi.c b/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_qspi.c deleted file mode 100644 index 8cbc426a0c4cda686b2dd1239b73cb03aa528849..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_qspi.c +++ /dev/null @@ -1,199 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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 -#include -#include "cli.h" -#include "qspi_hw.h" - -#define PSRAM_TEST_START_ADDR (QSPI_DCACHE_BASE_ADDR) -#define PSRAM_TEST_LEN (1024 * 10) - -static void cli_qspi_help(void) -{ - CLI_LOGI("qspi_driver init\r\n"); - CLI_LOGI("qspi_driver deinit\r\n"); - CLI_LOGI("qspi init\r\n"); - CLI_LOGI("qspi enter_quad_mode\r\n"); - CLI_LOGI("qspi exit_quad_mode\r\n"); - CLI_LOGI("qspi quad_write\r\n"); - CLI_LOGI("qspi quad_read\r\n"); - CLI_LOGI("qspi compare\r\n"); -} - -static void cli_qspi_driver_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - if (argc < 2) { - cli_qspi_help(); - return; - } - - if (os_strcmp(argv[1], "init") == 0) { - BK_LOG_ON_ERR(bk_qspi_driver_init()); - CLI_LOGI("qspi driver init\n"); - } else if (os_strcmp(argv[1], "deinit") == 0) { - BK_LOG_ON_ERR(bk_qspi_driver_deinit()); - CLI_LOGI("qspi driver deinit\n"); - } else { - cli_qspi_help(); - return; - } -} - -static bk_err_t cli_qspi_psram_8bit_increase_init_memory(uint8_t *buf, uint32_t count) -{ - BK_RETURN_ON_NULL(buf); - uint8_t *ptr = buf; - for (int i = 0; i < count; i++) { - ptr[i] = i & 0xff; - } - return BK_OK; -} - -static bk_err_t cli_qspi_psram_8bit_increase_compare(uint8_t *buf, uint32_t count) -{ - BK_RETURN_ON_NULL(buf); - uint8_t *ptr = buf; - for (int i = 0; i < count; i ++) { - if ((i & 0xff) != ptr[i]) { - CLI_LOGW("qspi dcache failed [%d] addr:0x%x, value:%x/%x\r\n", i, &ptr[i], (i & 0xff), ptr[i]); - return -1; - } - } - return BK_OK; -} - -static bk_err_t cli_qspi_psram_8bit_init_fixed_value(uint8_t *buf, uint32_t count, uint8_t val) -{ - BK_RETURN_ON_NULL(buf); - uint8_t *ptr = buf; - for (int i = 0; i < count; i++) { - ptr[i] = val; - } - return BK_OK; -} - -static bk_err_t cli_qspi_psram_8bit_cmp_fixed_value(uint8_t *buf, uint32_t count, uint8_t val) -{ - BK_RETURN_ON_NULL(buf); - uint8_t *ptr = buf; - for (int i = 0; i < count; i ++) { - if (val != ptr[i]) { - CLI_LOGW("qspi dcache [%d] addr:0x%x, %x/%x\r\n", i, &ptr[i], val, ptr[i]); - return -1; - } - } - return BK_OK; -} - -static void cli_qspi_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - if (argc < 2) { - cli_qspi_help(); - return; - } - - if (os_strcmp(argv[1], "init") == 0) { - //BK_LOG_ON_ERR(bk_qspi_psram_init()); - /* config qspi init psram dynamically */ - qspi_config_t config = {0}; - config.src_clk = os_strtoul(argv[2], NULL, 10); - config.src_clk_div = os_strtoul(argv[3], NULL, 10); - config.clk_div = os_strtoul(argv[4], NULL, 10); - BK_LOG_ON_ERR(bk_qspi_init(&config)); - CLI_LOGI("qspi init\r\n"); - } else if (os_strcmp(argv[1], "flash_test") == 0) { - extern void test_qspi_flash(uint32_t base_addr, uint32_t buf_len); - uint32_t base_addr = os_strtoul(argv[2], NULL, 16); - uint32_t buf_len = 256; - test_qspi_flash(base_addr, buf_len); - CLI_LOGI("qspi flash test end\r\n"); - } else if (os_strcmp(argv[1], "enter_quad_mode") == 0) { - BK_LOG_ON_ERR(bk_qspi_psram_enter_quad_mode()); - CLI_LOGI("qspi enter quad mode\r\n"); - } else if (os_strcmp(argv[1], "exit_quad_mode") == 0) { - BK_LOG_ON_ERR(bk_qspi_psram_exit_quad_mode()); - CLI_LOGI("qspi exit quad mode\r\n"); - } else if (os_strcmp(argv[1], "quad_write") == 0) { - BK_LOG_ON_ERR(bk_qspi_psram_quad_write()); - CLI_LOGI("qspi psram quad write mode\r\n"); - } else if (os_strcmp(argv[1], "quad_read") == 0) { - BK_LOG_ON_ERR(bk_qspi_psram_quad_read()); - CLI_LOGI("qspi psram quad read mode\r\n"); - } else if (os_strcmp(argv[1], "single_write") == 0) { - BK_LOG_ON_ERR(bk_qspi_psram_single_write()); - CLI_LOGI("qspi psram single write mode\r\n"); - } else if (os_strcmp(argv[1], "single_read") == 0) { - BK_LOG_ON_ERR(bk_qspi_psram_single_read()); - CLI_LOGI("qspi psram single read mode\r\n"); - } else if (os_strcmp(argv[1], "compare") == 0) { - cli_qspi_psram_8bit_increase_init_memory((uint8_t *)PSRAM_TEST_START_ADDR, PSRAM_TEST_LEN); - cli_qspi_psram_8bit_increase_compare((uint8_t *)PSRAM_TEST_START_ADDR, PSRAM_TEST_LEN); - - cli_qspi_psram_8bit_init_fixed_value((uint8_t *)PSRAM_TEST_START_ADDR, PSRAM_TEST_LEN, 0xff); - cli_qspi_psram_8bit_cmp_fixed_value((uint8_t *)PSRAM_TEST_START_ADDR, PSRAM_TEST_LEN, 0xff); - - cli_qspi_psram_8bit_init_fixed_value((uint8_t *)PSRAM_TEST_START_ADDR, PSRAM_TEST_LEN, 0x5a); - cli_qspi_psram_8bit_cmp_fixed_value((uint8_t *)PSRAM_TEST_START_ADDR, PSRAM_TEST_LEN, 0x5a); - CLI_LOGI("qspi psram write and read ok\r\n"); - } else if (os_strcmp(argv[1], "write") == 0) { - uint32_t base_addr = os_strtoul(argv[2], NULL, 16); - uint8_t write_data = os_strtoul(argv[3], NULL, 16); - uint32_t write_size = os_strtoul(argv[4], NULL, 10); - uint8_t *wr_buf = (uint8_t *)os_malloc(write_size); - if (!wr_buf) { - CLI_LOGE("qspi write buff malloc failed\r\n"); - return; - } - os_memset(wr_buf, write_data, write_size); - BK_LOG_ON_ERR(bk_qspi_psram_write(base_addr, wr_buf, write_size)); - if (wr_buf) { - os_free(wr_buf); - wr_buf = NULL; - } - CLI_LOGI("qspi psram write\r\n"); - } else if (os_strcmp(argv[1], "read") == 0) { - uint32_t base_addr = os_strtoul(argv[2], NULL, 16); - uint32_t read_size = os_strtoul(argv[3], NULL, 10); - uint8_t *rd_buf = (uint8_t *)os_zalloc(read_size); - if (!rd_buf) { - CLI_LOGE("qspi read buff malloc failed\r\n"); - return; - } - BK_LOG_ON_ERR(bk_qspi_psram_read(base_addr, rd_buf, read_size)); - for (int i = 0; i < read_size; i++) { - CLI_LOGI("read_buf[%d]=%x\r\n", i, rd_buf[i]); - } - if (rd_buf) { - os_free(rd_buf); - rd_buf = NULL; - } - CLI_LOGI("qspi psram read\r\n"); - } else { - cli_qspi_help(); - } -} - -#define QSPI_CMD_CNT (sizeof(s_qspi_commands) / sizeof(struct cli_command)) -static const struct cli_command s_qspi_commands[] = { - {"qspi_driver", "qspi_driver {init|deinit}", cli_qspi_driver_cmd}, - {"qspi", "qspi {init|write|read}", cli_qspi_cmd}, -}; - -int cli_qspi_init(void) -{ - BK_LOG_ON_ERR(bk_qspi_driver_init()); - return cli_register_commands(s_qspi_commands, QSPI_CMD_CNT); -} - diff --git a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_reg.c b/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_reg.c deleted file mode 100644 index 4897b6c53c38dcad56c59a779dc52871eff54eb5..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_reg.c +++ /dev/null @@ -1,268 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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 "cli.h" -#include -#include -#include "icu_hal.h" -#include "pwm_hal.h" -#include "timer_hal.h" -#include "gpio_hal.h" -#include "dma_hal.h" -#include "uart_hal.h" -#include "wdt_hal.h" -#include "trng_hal.h" -#include "efuse_hal.h" -#include "adc_hal.h" -#include "spi_hal.h" -#include "i2c_hal.h" - -#if CONFIG_QSPI -#include "qspi_hal.h" -#endif -#if CONFIG_AON_RTC -#include "aon_rtc_hal.h" -#endif -#if CONFIG_CALENDAR -#include "calendar_hal.h" -#endif -#if CONFIG_FLASH -#include "flash_hal.h" -#endif -#if CONFIG_SDIO_HOST -#include "sdio_host_hal.h" -#endif - -static int hex2num(char c) -{ - if (c >= '0' && c <= '9') - return c - '0'; - if (c >= 'a' && c <= 'f') - return c - 'a' + 10; - if (c >= 'A' && c <= 'F') - return c - 'A' + 10; - return -1; -} - -static int hex2byte(const char *hex) -{ - int a, b; - a = hex2num(*hex++); - if (a < 0) - return -1; - b = hex2num(*hex++); - if (b < 0) - return -1; - return (a << 4) | b; -} - -/** - * hexstr2bin - Convert ASCII hex string into binary data - * @hex: ASCII hex string (e.g., "01ab") - * @buf: Buffer for the binary data - * @len: Length of the text to convert in bytes (of buf); hex will be double - * this size - * Returns: 0 on success, -1 on failure (invalid hex string) - */ -static int cli_hexstr2bin(const char *hex, u8 *buf, size_t len) -{ - size_t i; - int a; - const char *ipos = hex; - u8 *opos = buf; - - for (i = 0; i < len; i++) { - a = hex2byte(ipos); - if (a < 0) - return -1; - *opos++ = a; - ipos += 2; - } - return 0; -} - -#if CONFIG_JPEG_ENCODE -#include "jpeg_hal.h" -#endif - -static void cli_reg_write_read_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - UINT32 reg_addr = 0, reg_value = 0; - UINT8 optr_len = 0, optr_tab[9]; - - os_memset(optr_tab, 0, 9); - os_memset(optr_tab, 0x30, 8); - - if (os_strncmp(argv[1], "-r", 2) == 0) { - if (argc != 3) { - os_printf("regshow -r addr\r\n"); - return; - } - - optr_len = os_strlen(argv[2]); - if (optr_len > 8) { - os_printf("addr 0-FFFFFFFF\r\n"); - return; - } - optr_len = 8 - optr_len; - os_memcpy(&optr_tab[optr_len], argv[2], os_strlen(argv[2])); - - cli_hexstr2bin((char *)optr_tab, (u8 *)®_addr, 4); - reg_addr = ntohl(reg_addr); - os_printf("regshow R: addr:0x%08x, value:0x%08x\r\n", reg_addr, REG_READ(reg_addr)); - } else if (os_strncmp(argv[1], "-w", 2) == 0) { - if (argc != 4) { - os_printf("regshow -w addr value\r\n"); - return; - } - - optr_len = os_strlen(argv[2]); - if (optr_len > 8) { - os_printf("addr 0-FFFFFFFF\r\n"); - return; - } - optr_len = 8 - optr_len; - os_memcpy(&optr_tab[optr_len], argv[2], os_strlen(argv[2])); - - cli_hexstr2bin((char *)optr_tab, (u8 *)®_addr, 4); - reg_addr = ntohl(reg_addr); - - - os_memset(optr_tab, 0x30, 8); - optr_len = os_strlen(argv[3]); - if (optr_len > 8) { - os_printf("value 0-FFFFFFFF\r\n"); - return; - } - optr_len = 8 - optr_len; - os_memcpy(&optr_tab[optr_len], argv[3], os_strlen(argv[3])); - cli_hexstr2bin((char *)optr_tab, (u8 *)®_value, 4); - reg_value = ntohl(reg_value); - - REG_WRITE(reg_addr, reg_value); - -#if (CLI_CFG_WIFI == 1) - extern INT32 rwnx_cal_save_trx_rcbekn_reg_val(void); - // when write trx and rc beken regs, updata registers save. - if ((reg_addr & 0xfff0000) == 0x1050000) - rwnx_cal_save_trx_rcbekn_reg_val(); -#endif - - os_printf("regshow W: addr:0x%08x, value:0x%08x - check:0x%08x\r\n", - reg_addr, reg_value, REG_READ(reg_addr)); - } else - os_printf("regshow -w/r addr [value]\r\n"); -} - -static void cli_reg_dump_help(void) -{ - CLI_LOGI("regdump icu\n"); - CLI_LOGI(" pwm\n"); - CLI_LOGI(" gpio [index]\n"); - CLI_LOGI(" timer\n"); - CLI_LOGI(" dma [channel]\n"); - CLI_LOGI(" uart id\n"); - CLI_LOGI(" wdt\n"); - CLI_LOGI(" trng\n"); - CLI_LOGI(" efuse\n"); - CLI_LOGI(" adc\n"); - CLI_LOGI(" spi\n"); -} - -static void cli_reg_dump_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - uint8_t index = os_strtoul(argv[2], NULL, 10); - - if (argc == 1) { - cli_reg_dump_help(); - return; - } - - if (os_strcmp(argv[1], "icu") == 0) { -#if (CONFIG_ICU) - icu_struct_dump(); -#endif - } else if (os_strcmp(argv[1], "pwm") == 0) { - pwm_struct_dump(); - } else if (os_strcmp(argv[1], "timer") == 0) { - timer_struct_dump(); - } else if (os_strcmp(argv[1], "gpio") == 0) { - gpio_struct_dump(index); - } else if (os_strcmp(argv[1], "dma") == 0) { - dma_struct_dump(index); - } else if (os_strcmp(argv[1], "uart") == 0) { - uart_struct_dump(index); - } else if (os_strcmp(argv[1], "wdt") == 0) { - wdt_struct_dump(); - } else if (os_strcmp(argv[1], "trng") == 0) { -#if (CONFIG_TRNG_SUPPORT) - trng_struct_dump(); -#endif - } else if (os_strcmp(argv[1], "efuse") == 0) { -#if (CONFIG_EFUSE) - efuse_struct_dump(); -#endif - } else if (os_strcmp(argv[1], "adc") == 0) { - adc_struct_dump(); - } else if (os_strcmp(argv[1], "spi") == 0) { - spi_struct_dump(index); - } else if (os_strcmp(argv[1], "i2c") == 0) { - i2c_struct_dump(index); - } -#if CONFIG_QSPI - else if (os_strcmp(argv[1], "qspi") == 0) { - qspi_struct_dump(); - } -#endif -#if CONFIG_AON_RTC - else if (os_strcmp(argv[1], "aon_rtc") == 0) { - aon_rtc_struct_dump(); - } -#endif -#if CONFIG_JPEG_ENCODE - else if (os_strcmp(argv[1], "jpeg") == 0) { - jpeg_struct_dump(); - } -#endif -#if CONFIG_CALENDAR - else if (os_strcmp(argv[1], "calendar") == 0) { - calendar_struct_dump(); - } -#endif -#if CONFIG_FLASH - else if (os_strcmp(argv[1], "flash") == 0) { - flash_struct_dump(); - } -#endif -#if CONFIG_SDIO_HOST - else if (os_strcmp(argv[1], "sdio_host") == 0) { - sdio_host_struct_dump(); - } -#endif - else { - cli_reg_dump_help(); - return; - } -} - -#define REG_CMD_CNT (sizeof(s_reg_commands) / sizeof(struct cli_command)) -static const struct cli_command s_reg_commands[] = { - {"regshow", "regshow -w/r addr [value]", cli_reg_write_read_cmd}, - {"regdump", "regdump {module}", cli_reg_dump_cmd}, -}; - -int cli_reg_init(void) -{ - return cli_register_commands(s_reg_commands, REG_CMD_CNT); -} diff --git a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_rpc.c b/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_rpc.c deleted file mode 100755 index 0678ac6815dc1b17b72b098a51324b21251a3b7f..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_rpc.c +++ /dev/null @@ -1,315 +0,0 @@ -/** - * UNPUBLISHED PROPRIETARY SOURCE CODE - * Copyright (c) 2016 BEKEN Inc. - * - * The contents of this file may not be disclosed to third parties, copied or - * duplicated in any form, in whole or in part, without the prior written - * permission of BEKEN Corporation. - * - */ -#include -#include "sys_rtos.h" -#include -#include - -#include "bk_cli.h" -#include "stdarg.h" -#include -#include -#include -#include "bk_phy.h" -#include "cli.h" -#include "cli_config.h" -#include -#include -#include "bk_rtos_debug.h" -#if CONFIG_SHELL_ASYNCLOG -#include "components/shell_task.h" -#endif -#include "bk_api_cli.h" -#include "boot.h" - -static void debug_help_command(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv); - -#if CONFIG_DUAL_CORE -#include "mb_ipc_cmd.h" -#include - -#include "amp_lock_api.h" - -static void debug_ipc_command(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv); -static void debug_rpc_command(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv); -static void debug_rpc_gpio_command(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv); -static void debug_cpulock_command(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv); - -static u8 ipc_inited = 0; -static u8 rpc_inited = 0; - -#endif - -#if CONFIG_ARCH_RISCV -static void debug_perfmon_command(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv); -static void debug_show_boot_time(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv); -#endif - -const struct cli_command debug_cmds[] = { - {"help", "list debug cmds", debug_help_command}, -#if CONFIG_DUAL_CORE - {"ipc", "ipc", debug_ipc_command}, - {"rpc", "rpc", debug_rpc_command}, - {"gpio_out", "gpio_out gpio_id {0|1}", debug_rpc_gpio_command}, - {"cpu_lock", "cpu_lock [timeout 1~20]", debug_cpulock_command}, -#endif - -#if CONFIG_ARCH_RISCV - {"perfmon", "perfmon(calc MIPS)", debug_perfmon_command}, - {"boottime", "boottime(show boot mtime info)", debug_show_boot_time}, -#endif -}; - -const int cli_debug_table_size = ARRAY_SIZE(debug_cmds); - -void print_cmd_table(const struct cli_command *cmd_table, int table_items) -{ - int i; - - for (i = 0; i < table_items; i++) - { - if (cmd_table[i].name) - { - if (cmd_table[i].help) - os_printf("%s: %s\r\n", cmd_table[i].name, cmd_table[i].help); - else - os_printf("%s\r\n", cmd_table[i].name); - } - } -} - -void print_cmd_help(const struct cli_command *cmd_table, int table_items, void *func) -{ - int i; - - for (i = 0; i < table_items; i++) - { - if(cmd_table[i].function == func) - { - if (cmd_table[i].help) - os_printf("%s\r\n", cmd_table[i].help); - - break; - } - } -} - -static void debug_help_command(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - os_printf("====Debug Commands====\r\n"); - - print_cmd_table(debug_cmds, ARRAY_SIZE(debug_cmds)); -} - -#if CONFIG_DUAL_CORE -static void print_debug_cmd_help(void *func) -{ - print_cmd_help(debug_cmds, ARRAY_SIZE(debug_cmds), func); -} - -static void debug_rpc_command(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - int ret_val; - - if(rpc_inited) - { - os_printf("rpc started\r\n"); - return; - } - - ret_val = rpc_init(); - os_printf("rpc init: %d\r\n", ret_val); - rpc_inited = 1; - -#if CONFIG_MASTER_CORE - - if(ipc_inited) - { - ret_val = ipc_send_test_cmd(0x12); - os_printf("ipc server test: ret=%d\r\n", ret_val); - - ret_val = ipc_send_get_ps_flag(); - os_printf("ipc server ps: ret= 0x%x\r\n", ret_val); - - ret_val = ipc_send_get_heart_rate(); - os_printf("ipc server hr: ret= 0x%x\r\n", ret_val); - - ret_val = ipc_send_set_heart_rate(0x33); - os_printf("ipc server set hr: ret= %d\r\n", ret_val); - } - -#endif - -} - -static void debug_ipc_command(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - int ret_val; - - if(ipc_inited) - { - os_printf("ipc started\r\n"); - return; - } - - ret_val = ipc_init(); - os_printf("ipc init: %d\r\n", ret_val); - ipc_inited = 1; - -#if CONFIG_SLAVE_CORE - - ret_val = ipc_send_power_up(); - os_printf("ipc client power: %d\r\n", ret_val); - - ret_val = ipc_send_heart_beat(0x34); - os_printf("ipc client heartbeat: %d\r\n", ret_val); - - ret_val = ipc_send_test_cmd(0x12); - os_printf("ipc client test: %d\r\n", ret_val); - -#endif -} - -extern bk_err_t bk_gpio_enable_output_rpc(gpio_id_t gpio_id); -extern bk_err_t bk_gpio_set_output_high_rpc(gpio_id_t gpio_id); -extern bk_err_t bk_gpio_set_output_low_rpc(gpio_id_t gpio_id); - -static void debug_rpc_gpio_command(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ -#if CONFIG_SLAVE_CORE - - int ret_val; - - u32 gpio_id = 0; - u32 level = 0; - - if (argc < 3) - { - print_debug_cmd_help(debug_rpc_gpio_command); - return; - } - - gpio_id = strtoul(argv[1], NULL, 0); - level = strtoul(argv[2], NULL, 0); - - ret_val = bk_gpio_enable_output_rpc(gpio_id); - os_printf("rpc gpio:ret=%d\r\n", ret_val); - - if(level) - ret_val = bk_gpio_set_output_high_rpc(gpio_id); - else - ret_val = bk_gpio_set_output_low_rpc(gpio_id); - - os_printf("rpc gpio:ret=%d\r\n", ret_val); - -#endif - -} - -static void debug_cpulock_command(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - u32 timeout_second = 10; // 10s - - if(ipc_inited == 0) - { - os_printf("Failed: no ipc client/server in CPU0/CPU1.\r\n"); - return; - } - - if (argc > 1) - { - timeout_second = strtoul(argv[1], NULL, 0); - - if(timeout_second > 20) - timeout_second = 20; - if(timeout_second == 0) - timeout_second = 10; - } - else - { - print_debug_cmd_help(debug_cpulock_command); - os_printf("default timeout 10s is used.\r\n"); - } - - int ret_val = BK_FAIL; - - ret_val = amp_res_init(AMP_RES_ID_GPIO); - os_printf("amp res init:ret=%d\r\n", ret_val); - - ret_val = amp_res_acquire(AMP_RES_ID_GPIO, timeout_second * 1000); - os_printf("amp res acquire:ret=%d\r\n", ret_val); - - rtos_delay_milliseconds(timeout_second * 1000); - - if(ret_val == 0) - { - ret_val = amp_res_release(AMP_RES_ID_GPIO); - os_printf("amp res release:ret=%d\r\n", ret_val); - } - else - { - os_printf("amp res release: no release\r\n"); - } - -} -#endif - -const struct cli_command * cli_debug_cmd_table(int *num) -{ - *num = ARRAY_SIZE(debug_cmds); - - return &debug_cmds[0]; -} - -#if CONFIG_ARCH_RISCV - -extern u64 riscv_get_instruct_cnt(void); -extern u64 riscv_get_mtimer(void); - -static u64 saved_time = 0; -static u64 saved_inst_cnt = 0; - -static void debug_perfmon_command(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - u64 cur_time = riscv_get_mtimer(); - u64 cur_inst_cnt = riscv_get_instruct_cnt(); - - os_printf("cur time: %x:%08x\r\n", (u32)(cur_time >> 32), (u32)(cur_time & 0xFFFFFFFF)); - os_printf("cur inst_cnt: %x:%08x\r\n", (u32)(cur_inst_cnt >> 32), (u32)(cur_inst_cnt & 0xFFFFFFFF)); - - saved_time = (cur_time - saved_time) / 26; - saved_inst_cnt = cur_inst_cnt - saved_inst_cnt; - -// os_printf("elapse time(us): %x:%08x\r\n", (u32)(saved_time >> 32), (u32)(saved_time & 0xFFFFFFFF)); -// os_printf("diff inst_cnt: %x:%08x\r\n", (u32)(saved_inst_cnt >> 32), (u32)(saved_inst_cnt & 0xFFFFFFFF)); - - os_printf("MIPS: %d KIPS\r\n", (u32)(saved_inst_cnt * 1000 / saved_time)); - - saved_time = cur_time; - saved_inst_cnt = cur_inst_cnt; -} - - -static void debug_show_boot_time(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - u64 cur_time = riscv_get_mtimer(); - u64 cur_inst_cnt = riscv_get_instruct_cnt(); - - BK_LOGI("debug","cur time: %x:%08x\r\n", (u32)(cur_time >> 32), (u32)(cur_time & 0xFFFFFFFF)); - BK_LOGI("debug","cur time: %ldms\r\n", (u32)(cur_time/26000)); - BK_LOGI("debug","cur inst_cnt: %x:%08x\r\n", (u32)(cur_inst_cnt >> 32), (u32)(cur_inst_cnt & 0xFFFFFFFF)); - -#if CONFIG_SAVE_BOOT_TIME_POINT - show_saved_mtime_info(); -#endif - -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_sbc.c b/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_sbc.c deleted file mode 100755 index fd4c2b88cada7f9adcaa24f66e92b3ac69817854..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_sbc.c +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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 "cli.h" - - -extern void cli_sbc_decoder_test_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv); - -extern void cli_msbc_decoder_test_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv); - - -#define SBC_CMD_CNT (sizeof(s_sbc_commands) / sizeof(struct cli_command)) - -static const struct cli_command s_sbc_commands[] = { - {"sbc_decoder_test", "sbc_decoder_test {start|stop}", cli_sbc_decoder_test_cmd}, - {"msbc_decoder_test", "msbc_decoder_test {start|stop}", cli_msbc_decoder_test_cmd}, -}; - -int cli_sbc_init(void) -{ - return cli_register_commands(s_sbc_commands, SBC_CMD_CNT); -} - - diff --git a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_sd.c b/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_sd.c deleted file mode 100644 index fe12040cb207fb92e7ffb314a69b4ee6f5741df5..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_sd.c +++ /dev/null @@ -1,70 +0,0 @@ -#include "cli.h" - -#if CONFIG_SDCARD_HOST -/* -sdtest I 0 -- -sdtest R secnum -sdtest W secnum -*/ -extern uint32_t sdcard_intf_test(void); -extern uint32_t test_sdcard_read(uint32_t blk, uint32_t blk_cnt); -extern uint32_t test_sdcard_write(uint32_t blk, uint32_t blk_cnt, uint32_t wr_val); -extern void sdcard_intf_close(void); - -static void sd_operate(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - uint32_t cmd; - uint32_t blknum = 0, blkcnt = 1, wr_val = 0x12345678; - uint32_t ret; - if (argc > 1) { - cmd = argv[1][0]; - if (argc > 2) - { - blknum = os_strtoul(argv[2], NULL, 10); - if (argc > 3) - { - blkcnt = os_strtoul(argv[3], NULL, 10); - if (argc > 4) - { - wr_val = os_strtoul(argv[4], NULL, 16); - } - } - } - switch (cmd) { - case 'I': - ret = sdcard_intf_test(); - os_printf("init ret=%x\r\n", ret); - break; - case 'R': - ret = test_sdcard_read(blknum, blkcnt); - os_printf("read ret=%x,blknum=%d,blkcnt=%d\r\n", ret, blknum, blkcnt); - break; - case 'W': - ret = test_sdcard_write(blknum, blkcnt, wr_val); - os_printf("write ret=%x,blknum=%d,blkcnt=%d, wr_val=0x%08x\r\n", ret, blknum, blkcnt, wr_val); - break; - case 'C': - sdcard_intf_close(); - os_printf("sdtest close \r\n"); - break; - default: - break; - } - } else - os_printf("cmd param error\r\n"); -} - -#endif - - -#define SD_CMD_CNT (sizeof(s_sd_commands) / sizeof(struct cli_command)) -static const struct cli_command s_sd_commands[] = { -#if CONFIG_SDCARD_HOST - {"sdtest", "sdtest ", sd_operate}, -#endif -}; - -int cli_sd_init(void) -{ - return cli_register_commands(s_sd_commands, SD_CMD_CNT); -} diff --git a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_sdio_host.c b/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_sdio_host.c deleted file mode 100644 index 4e60fe77f916b45f33a8bada21cca7d5b5608e52..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_sdio_host.c +++ /dev/null @@ -1,205 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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 -#include "cli.h" -#include -#include - -#define SD_CMD_GO_IDLE_STATE 0 -#define SD_BLOCK_SIZE 512 -#define SD_CARD_READ_BUFFER_SIZE 512 -#define CMD_TIMEOUT_200K 5000 //about 5us per cycle (25ms) -#define DATA_TIMEOUT_13M 6000000 //450ms - -static void cli_sdio_host_help(void) -{ - CLI_LOGI("sdio_host_driver init\r\n"); - CLI_LOGI("sdio_host driver deinit\r\n"); - CLI_LOGI("sdio send_cmd Index Arg(hex-decimal) RSP_Type Timeout_Value\r\n"); -} - -static void cli_sdio_host_driver_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - if (argc < 2) { - cli_sdio_host_help(); - return; - } - - if (os_strcmp(argv[1], "init") == 0) { - BK_LOG_ON_ERR(bk_sdio_host_driver_init()); - CLI_LOGI("sdio_host driver init\n"); - } else if (os_strcmp(argv[1], "deinit") == 0) { - BK_LOG_ON_ERR(bk_sdio_host_driver_deinit()); - CLI_LOGI("sdio_host driver deinit\n"); - } else { - cli_sdio_host_help(); - return; - } -} - -static void cli_sdio_host_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - if (argc < 2) { - cli_sdio_host_help(); - return; - } - - if (os_strcmp(argv[1], "init") == 0) { - sdio_host_config_t sdio_cfg = {0}; - - sdio_cfg.clock_freq = CONFIG_SDIO_HOST_DEFAULT_CLOCK_FREQ; - sdio_cfg.bus_width = SDIO_HOST_BUS_WIDTH_1LINE; - - BK_LOG_ON_ERR(bk_sdio_host_init(&sdio_cfg)); - CLI_LOGI("sdio host init\r\n"); - } else if (os_strcmp(argv[1], "deinit") == 0) { - BK_LOG_ON_ERR(bk_sdio_host_deinit()); - CLI_LOGI("sdio host deinit\r\n"); - } else if (os_strcmp(argv[1], "send_cmd") == 0) { - bk_err_t error_state = BK_OK; - sdio_host_cmd_cfg_t cmd_cfg = {0}; - - //modify to send cmd by parameter,then we can easy to debug any cmds. - cmd_cfg.cmd_index = os_strtoul(argv[2], NULL, 10); //CMD0,CMD-XXX,SD_CMD_GO_IDLE_STATE - cmd_cfg.argument = os_strtoul(argv[3], NULL, 16); //0x123456xx - cmd_cfg.response = os_strtoul(argv[4], NULL, 10); //SDIO_HOST_CMD_RSP_NONE,SHORT,LONG - cmd_cfg.wait_rsp_timeout = os_strtoul(argv[5], NULL, 10); //CMD_TIMEOUT_200K; - - bk_sdio_host_send_command(&cmd_cfg); - error_state = bk_sdio_host_wait_cmd_response(cmd_cfg.cmd_index); - if (error_state != BK_OK) { - CLI_LOGW("sdio:cmd %d err:-%x\r\n", cmd_cfg.cmd_index, -error_state); - } - } else if (os_strcmp(argv[1], "config_data") == 0) { - sdio_host_data_config_t data_config = {0}; - - data_config.data_timeout = DATA_TIMEOUT_13M; - data_config.data_len = SD_BLOCK_SIZE * 1; - data_config.data_block_size = SD_BLOCK_SIZE; - data_config.data_dir = SDIO_HOST_DATA_DIR_RD; - - BK_LOG_ON_ERR(bk_sdio_host_config_data(&data_config)); - CLI_LOGI("sdio host config data ok\r\n"); - } else { - cli_sdio_host_help(); - return; - } -} - -static void cli_sd_card_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - if (argc < 2) { - cli_sdio_host_help(); - return; - } - - if (os_strcmp(argv[1], "init") == 0) { - BK_LOG_ON_ERR(bk_sd_card_init()); - CLI_LOGI("sd card init ok\r\n"); - } else if (os_strcmp(argv[1], "read") == 0) { - uint32_t block_num = os_strtoul(argv[2], NULL, 10); - uint8_t *buf = os_malloc(SD_CARD_READ_BUFFER_SIZE * block_num); - if (buf == NULL) { - CLI_LOGE("sd card buf malloc failed\r\n"); - return; - } - BK_LOG_ON_ERR(bk_sd_card_read_blocks(buf, 0, block_num)); - while (bk_sd_card_get_card_state() != SD_CARD_TRANSFER); - for (int i = 0; i < SD_CARD_READ_BUFFER_SIZE * block_num; i++) { - CLI_LOGI("buf[%d]=%x\r\n", i, buf[i]); - } - if (buf) { - os_free(buf); - buf = NULL; - } - CLI_LOGI("sd card read ok\r\n"); - } else if (os_strcmp(argv[1], "write") == 0) { - uint32_t block_num = os_strtoul(argv[2], NULL, 10); - uint8_t *buf = os_malloc(SD_CARD_READ_BUFFER_SIZE * block_num); - if (buf == NULL) { - CLI_LOGE("sd card buf malloc failed\r\n"); - return; - } - for (int i = 0; i < SD_CARD_READ_BUFFER_SIZE * block_num; i++) { - buf[i] = i & 0xff; - } - BK_LOG_ON_ERR(bk_sd_card_write_blocks(buf, 0, block_num)); - while (bk_sd_card_get_card_state() != SD_CARD_TRANSFER); - if (buf) { - os_free(buf); - buf = NULL; - } - CLI_LOGI("sd card write ok\r\n"); - } else if (os_strcmp(argv[1], "erase") == 0) { - uint32_t block_num = os_strtoul(argv[2], NULL, 10); - BK_LOG_ON_ERR(bk_sd_card_erase(0, block_num)); - while (bk_sd_card_get_card_state() != SD_CARD_TRANSFER); - CLI_LOGI("sd card erase ok\r\n"); - } else if (os_strcmp(argv[1], "cmp") == 0) { - BK_LOG_ON_ERR(bk_sd_card_erase(0, 2)); - while (bk_sd_card_get_card_state() != SD_CARD_TRANSFER); - - uint8_t *write_buf = os_malloc(SD_CARD_READ_BUFFER_SIZE * 2); - if (write_buf == NULL) { - CLI_LOGE("sd card write_buf malloc failed\r\n"); - return; - } - for (int i = 0; i < SD_CARD_READ_BUFFER_SIZE * 2; i++) { - write_buf[i] = i & 0xff; - } - BK_LOG_ON_ERR(bk_sd_card_write_blocks(write_buf, 0, 2)); - while (bk_sd_card_get_card_state() != SD_CARD_TRANSFER); - - uint8_t *read_buf = os_malloc(SD_CARD_READ_BUFFER_SIZE * 2); - if (read_buf == NULL) { - CLI_LOGE("sd card read_buf malloc failed\r\n"); - return; - } - BK_LOG_ON_ERR(bk_sd_card_read_blocks(read_buf, 0, 2)); - while (bk_sd_card_get_card_state() != SD_CARD_TRANSFER); - - int ret = os_memcmp(write_buf, read_buf, SD_CARD_READ_BUFFER_SIZE * 2); - if (ret == 0) { - CLI_LOGI("sd card test ok\r\n"); - } - - if (write_buf) { - os_free(write_buf); - write_buf = NULL; - } - - if (read_buf) { - os_free(read_buf); - read_buf = NULL; - } - } else { - cli_sdio_host_help(); - return; - } -} - -#define SDIO_HOST_CMD_CNT (sizeof(s_sdio_host_commands) / sizeof(struct cli_command)) -static const struct cli_command s_sdio_host_commands[] = { - {"sdio_host_driver", "sdio_host_driver {init|deinit}", cli_sdio_host_driver_cmd}, - {"sdio", "sdio {init|deinit|send_cmd|config_data}", cli_sdio_host_cmd}, - {"sd_card", "sd_card {init|read|write|erase|cmp|}", cli_sd_card_cmd}, -}; - -int cli_sdio_host_init(void) -{ - BK_LOG_ON_ERR(bk_sdio_host_driver_init()); - return cli_register_commands(s_sdio_host_commands, SDIO_HOST_CMD_CNT); -} - diff --git a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_security.c b/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_security.c deleted file mode 100644 index 5a5b4fa636e5bab1cf174c26e6ab4767f660f3cd..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_security.c +++ /dev/null @@ -1,18 +0,0 @@ -#include "cli.h" - -#if (CONFIG_SOC_BK7251) -#include "bk_security.h" -extern void sec_Command(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv); -#endif - -#define SECURITY_CMD_CNT (sizeof(s_security_commands) / sizeof(struct cli_command)) -static const struct cli_command s_security_commands[] = { -#if (CONFIG_SOC_BK7251) - {"sec", "sec help", sec_Command }, -#endif -}; - -int cli_security_init(void) -{ - return cli_register_commands(s_security_commands, SECURITY_CMD_CNT); -} diff --git a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_securityip.c b/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_securityip.c deleted file mode 100755 index 4be4971fcc7da8061db879d2a7dd02931825b0fc..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_securityip.c +++ /dev/null @@ -1,112 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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 "cli.h" -#include "driver/securityip.h" -static void cli_securityip_help(void) -{ - CLI_LOGI("securityip_driver init/deinit\r\n"); - CLI_LOGI("securityip_trng cfg/get\r\n"); - -} - -static void cli_securityip_driver_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - if (argc < 2) { - cli_securityip_help(); - return; - } - - if (os_strcmp(argv[1], "init") == 0) { - BK_LOG_ON_ERR(bk_securityip_driver_init()); - } else if (os_strcmp(argv[1], "deinit") == 0) { - BK_LOG_ON_ERR(bk_securityip_driver_deinit()); - } else { - cli_securityip_help(); - return; - } -} - -static void cli_securityip_system_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - if (argc < 2) { - cli_securityip_help(); - return; - } - - if (os_strcmp(argv[1], "version") == 0) { - - CLI_LOGI("get securityip system version sucess!\r\n"); - } else if (os_strcmp(argv[1], "state") == 0) { - - CLI_LOGI("get securityip system state sucess!\r\n"); - } else if (os_strcmp(argv[1], "reset") == 0) { - - CLI_LOGI("securityip system reset!\r\n"); - } else { - cli_securityip_help(); - return; - } -} - -static void cli_securityip_trng_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - if (argc < 2) { - cli_securityip_help(); - return; - } - - if (os_strcmp(argv[1], "cfg") == 0) { - BK_LOG_ON_ERR(bk_securityip_trng_def_cfg()); - } else if (os_strcmp(argv[1], "get") == 0) { - uint8_t * RandNum_p; - uint8_t * Num_p; - - uint32_t random_size = os_strtoul(argv[2], NULL, 10)&0xffff; - Num_p = RandNum_p = (uint8_t *)malloc(random_size+4); - memset(RandNum_p, 0xaa, random_size+4); - - BK_LOG_ON_ERR(bk_securityip_get_trng(random_size, RandNum_p)); - CLI_LOGI("get random num is \r\n"); - for(int i=0; i -#include "cli.h" -#include -#include -#include -#include - -static void cli_spi_help(void) -{ - CLI_LOGI("spi_driver {init|deinit}\r\n"); - CLI_LOGI("spi {id} {init} [mode] [bit_width] [bit_width] [cpol] [cpha] [wire_mode] [baud_rate] [bit_order]\r\n"); - CLI_LOGI("spi {id} {deinit} \r\n"); - CLI_LOGI("spi {id} {write} [buf_len]\r\n"); - CLI_LOGI("spi_data_test {id} {master|slave} {baud_rate} {start|stop} {uart2|uart3} {exchange}\r\n"); - CLI_LOGI("spi_data_test {id} {master|slave} {send} {buf_len}\r\n"); -} - -static void cli_spi_rx_isr(spi_id_t id, void *param) -{ - CLI_LOGI("spi_rx_isr(%d)\n", id); -} - -static void cli_spi_tx_isr(spi_id_t id, void *param) -{ - CLI_LOGI("spi_tx_isr(%d)\n", id); -} - -static void cli_spi_driver_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - if (argc < 2) { - cli_spi_help(); - return; - } - - if (os_strcmp(argv[1], "init") == 0) { - BK_LOG_ON_ERR(bk_spi_driver_init()); - CLI_LOGI("spi driver init\n"); - } else if (os_strcmp(argv[1], "deinit") == 0) { - BK_LOG_ON_ERR(bk_spi_driver_deinit()); - CLI_LOGI("spi driver deinit\n"); - } else { - cli_spi_help(); - return; - } -} - -static void cli_spi_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - if (argc < 2) { - cli_spi_help(); - return; - } - uint32_t spi_id = os_strtoul(argv[1], NULL, 10); - - if (os_strcmp(argv[2], "init") == 0) { - spi_config_t config = {0}; - if (os_strcmp(argv[3], "master") == 0) { - config.role = SPI_ROLE_MASTER; - } else { - config.role = SPI_ROLE_SLAVE; - } - if (os_strtoul(argv[4], NULL, 10) == 8) { - config.bit_width = SPI_BIT_WIDTH_8BITS; - } else { - config.bit_width = SPI_BIT_WIDTH_16BITS; - } - config.polarity = os_strtoul(argv[5], NULL, 10); - config.phase = os_strtoul(argv[6], NULL, 10); - if (os_strtoul(argv[7], NULL, 10) == 3) { - config.wire_mode = SPI_3WIRE_MODE; - } else { - config.wire_mode = SPI_4WIRE_MODE; - } - config.baud_rate = os_strtoul(argv[8], NULL, 10); - if (os_strcmp(argv[9], "LSB") == 0) { - config.bit_order = SPI_LSB_FIRST; - } else { - config.bit_order = SPI_MSB_FIRST; - } -#if CONFIG_SPI_DMA - config.dma_mode = os_strtoul(argv[10], NULL, 10); - config.spi_tx_dma_chan = os_strtoul(argv[11], NULL, 10); - config.spi_rx_dma_chan = os_strtoul(argv[12], NULL, 10); -#endif - BK_LOG_ON_ERR(bk_spi_init(spi_id, &config)); - CLI_LOGI("spi init, spi_id=%d\n", spi_id); - } else if (os_strcmp(argv[2], "deinit") == 0) { - BK_LOG_ON_ERR(bk_spi_deinit(spi_id)); - CLI_LOGI("spi deinit, spi_id=%d\n", spi_id); - } else if (os_strcmp(argv[2], "write") == 0) { - uint32_t buf_len = os_strtoul(argv[3], NULL, 10); - uint8_t *send_data = (uint8_t *)os_zalloc(buf_len); - if (send_data == NULL) { - CLI_LOGE("send buffer malloc failed\r\n"); - return; - } - for (int i = 0; i < buf_len; i++) { - send_data[i] = i & 0xff; - } - BK_LOG_ON_ERR(bk_spi_write_bytes(spi_id, send_data, buf_len)); - if (send_data) { - os_free(send_data); - } - send_data = NULL; - CLI_LOGI("spi write bytes, spi_id=%d, data_len=%d\n", spi_id, buf_len); - } else if (os_strcmp(argv[2], "read") == 0) { - uint32_t buf_len = os_strtoul(argv[3], NULL, 10); - uint8_t *recv_data = (uint8_t *)os_malloc(buf_len); - if (recv_data == NULL) { - CLI_LOGE("recv buffer malloc failed\r\n"); - return; - } - os_memset(recv_data, 0xff, buf_len); - BK_LOG_ON_ERR(bk_spi_read_bytes(spi_id, recv_data, buf_len)); - CLI_LOGI("spi read, spi_id=%d, size:%d\n", spi_id, buf_len); - for (int i = 0; i < buf_len; i++) { - CLI_LOGI("recv_buffer[%d]=0x%x\n", i, recv_data[i]); - } - if (recv_data) { - os_free(recv_data); - } - recv_data = NULL; - } else if (os_strcmp(argv[2], "transmit") == 0) { - int send_len = os_strtoul(argv[3], NULL, 10); - int recv_len = os_strtoul(argv[4], NULL, 10); - - uint8_t *send_data = (uint8_t *)os_zalloc(send_len); - if (send_data == NULL) { - CLI_LOGE("send buffer malloc failed\r\n"); - return; - } - for (int i = 0; i < send_len; i++) { - send_data[i] = i & 0xff; - } - uint8_t *recv_data = (uint8_t *)os_malloc(recv_len); - if (recv_data == NULL) { - CLI_LOGE("recv buffer malloc failed\r\n"); - return; - } - os_memset(recv_data, 0xff, recv_len); - int ret = bk_spi_transmit(spi_id, send_data, send_len, recv_data, recv_len); - if (ret < 0) { - CLI_LOGE("spi transmit failed, ret:-0x%x\r\n", -ret); - goto transmit_exit; - } - for (int i = 0; i < recv_len; i++) { - CLI_LOGI("recv_buffer[%d]=0x%x\r\n", i, recv_data[i]); - } -transmit_exit: - if (send_data) { - os_free(send_data); - } - send_data = NULL; - - if (recv_data) { - os_free(recv_data); - } - recv_data = NULL; - } -#if CONFIG_SPI_DMA - else if (os_strcmp(argv[2], "dma_write") == 0) { - uint32_t buf_len = os_strtoul(argv[3], NULL, 10); - uint8_t *send_data = (uint8_t *)os_zalloc(buf_len); - if (send_data == NULL) { - CLI_LOGE("send buffer malloc failed\r\n"); - return; - } - for (int i = 0; i < buf_len; i++) { - send_data[i] = i & 0xff; - } - BK_LOG_ON_ERR(bk_spi_dma_write_bytes(spi_id, send_data, buf_len)); - if (send_data) { - os_free(send_data); - } - send_data = NULL; - CLI_LOGI("spi dma send, spi_id=%d, data_len=%d\n", spi_id, buf_len); - } else if (os_strcmp(argv[2], "dma_read") == 0) { - uint32_t buf_len = os_strtoul(argv[3], NULL, 10); - uint8_t *recv_data = (uint8_t *)os_malloc(buf_len); - if (recv_data == NULL) { - CLI_LOGE("recv buffer malloc failed\r\n"); - return; - } - os_memset(recv_data, 0xff, buf_len); - BK_LOG_ON_ERR(bk_spi_dma_read_bytes(spi_id, recv_data, buf_len)); - CLI_LOGI("spi dma recv, spi_id=%d, data_len=%d\n", spi_id, buf_len); - for (int i = 0; i < buf_len; i++) { - CLI_LOGI("recv_buffer[%d]=0x%x\n", i, recv_data[i]); - } - if (recv_data) { - os_free(recv_data); - } - recv_data = NULL; - } -#endif - else { - cli_spi_help(); - return; - } -} - -static void cli_spi_config_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - uint32_t spi_id; - - if (argc < 4) { - cli_spi_help(); - return; - } - - spi_id = os_strtoul(argv[1], NULL, 10); - - if (os_strcmp(argv[2], "baud_rate") == 0) { - CLI_RET_ON_INVALID_ARGC(argc, 4); - uint32_t baud_rate = os_strtoul(argv[3], NULL, 10); - BK_LOG_ON_ERR(bk_spi_set_baud_rate(spi_id, baud_rate)); - CLI_LOGI("spi(%d) config baud_rate:%d\n", spi_id, baud_rate); - } else if (os_strcmp(argv[2], "mode") == 0) { - CLI_RET_ON_INVALID_ARGC(argc, 4); - uint32_t mode = os_strtoul(argv[3], NULL, 10); - BK_LOG_ON_ERR(bk_spi_set_mode(spi_id, mode)); - CLI_LOGI("spi(%d) config mode:%d\n", spi_id, mode); - } else if (os_strcmp(argv[2], "bit_width") == 0) { - CLI_RET_ON_INVALID_ARGC(argc, 4); - uint32_t bit_width = os_strtoul(argv[3], NULL, 10); - if (bit_width == 16) { - BK_LOG_ON_ERR(bk_spi_set_bit_width(spi_id, SPI_BIT_WIDTH_16BITS)); - } else { - bit_width = 8; - BK_LOG_ON_ERR(bk_spi_set_bit_width(spi_id, SPI_BIT_WIDTH_8BITS)); - } - CLI_LOGI("spi(%d) config bit_width:%d\n", spi_id, bit_width); - } else if (os_strcmp(argv[2], "wire_mode") == 0) { - CLI_RET_ON_INVALID_ARGC(argc, 4); - uint32_t wire_mode = os_strtoul(argv[3], NULL, 10); - if (wire_mode == 3) { - BK_LOG_ON_ERR(bk_spi_set_wire_mode(spi_id, SPI_3WIRE_MODE)); - } else { - BK_LOG_ON_ERR(bk_spi_set_wire_mode(spi_id, SPI_4WIRE_MODE)); - } - CLI_LOGI("spi(%d) config wire_mode:%d\n", spi_id, wire_mode); - } else if (os_strcmp(argv[2], "bit_order") == 0) { - CLI_RET_ON_INVALID_ARGC(argc, 4); - if (os_strcmp(argv[3], "LSB") == 0) { - BK_LOG_ON_ERR(bk_spi_set_bit_order(spi_id, SPI_LSB_FIRST)); - } else { - BK_LOG_ON_ERR(bk_spi_set_bit_order(spi_id, SPI_MSB_FIRST)); - } - CLI_LOGI("spi(%d) config bit_order:%s\n", spi_id, argv[3]); - } else { - cli_spi_help(); - return; - } -} - -static void cli_spi_int_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - uint32_t spi_id; - - if (argc != 4) { - cli_spi_help(); - return; - } - - spi_id = os_strtoul(argv[1], NULL, 10); - if (os_strcmp(argv[2], "reg") == 0) { - if (os_strcmp(argv[3], "tx") == 0) { - BK_LOG_ON_ERR(bk_spi_register_tx_finish_isr(spi_id, cli_spi_tx_isr, NULL)); - CLI_LOGI("spi id:%d register tx finish interrupt isr\n", spi_id); - } else { - BK_LOG_ON_ERR(bk_spi_register_rx_isr(spi_id, cli_spi_rx_isr, NULL)); - CLI_LOGI("spi id:%d register rx interrupt isr\n", spi_id); - } - } else { - cli_spi_help(); - return; - } -} - -typedef struct { - beken_thread_t handle; - beken_semaphore_t uart_rx_semaphore; - beken_semaphore_t spi_tx_finish_semaphore; - spi_role_t role; - uint32_t baud_rate; - spi_id_t spi_id; - uart_id_t uart_id; - uint32_t data_len; - uint8_t *data; - uint8_t *uart_get_data; - uint8_t *spi_get_buffer; - dma_id_t spi_tx_dma_chan; /**< SPI tx dma channel */ - dma_id_t spi_rx_dma_chan; /**< SPI rx dma channel */ - bool exchange_flag; - -} spi_data_test_config_t; - -static spi_data_test_config_t s_spi_test; -#define PER_PACKET_MAX_BYTES_SIZE 256 - -static uint32_t spi_data_test_send(spi_id_t id, uint32_t buf_len) -{ - bool middle_exchange_flag = s_spi_test.exchange_flag; - - while(buf_len > PER_PACKET_MAX_BYTES_SIZE){ - - s_spi_test.data = (uint8_t *)os_zalloc(PER_PACKET_MAX_BYTES_SIZE); - - s_spi_test.exchange_flag = 0; - s_spi_test.data_len = PER_PACKET_MAX_BYTES_SIZE; - - for (int i = 0; i < PER_PACKET_MAX_BYTES_SIZE; i++) { -#if (CONFIG_TRNG_SUPPORT) - s_spi_test.data[i] = bk_rand(); -#else - s_spi_test.data[i] = i & 0xff; -#endif - } - - BK_LOG_ON_ERR(bk_spi_write_bytes(id, s_spi_test.data, PER_PACKET_MAX_BYTES_SIZE)); - buf_len = buf_len - PER_PACKET_MAX_BYTES_SIZE; - } - - s_spi_test.data = (uint8_t *)os_zalloc(buf_len); - s_spi_test.exchange_flag = middle_exchange_flag; - s_spi_test.data_len = buf_len; - - for (int i = 0; i < buf_len; i++) { -#if (CONFIG_TRNG_SUPPORT) - s_spi_test.data[i] = bk_rand(); -#else - s_spi_test.data[i] = i & 0xff; -#endif - } - - BK_LOG_ON_ERR(bk_spi_write_bytes(id, s_spi_test.data, buf_len)); - CLI_LOGI("spi MASTER write bytes, spi_id=%d, data_len=%d\n", id, buf_len); - - return BK_OK; -} - -static void spi_data_test_tx_finish_isr(uart_id_t id, void *param) -{ - int ret; - - ret = rtos_set_semaphore(&s_spi_test.spi_tx_finish_semaphore); - if(kNoErr !=ret) - CLI_LOGI("spi_data_test_Tx_isr: spi set sema failed\r\n"); - - return; -} - -static void spi_data_test_spi_config(spi_id_t id, spi_role_t role, uint32_t baud_rate) -{ - spi_config_t config = {0}; - config.role = role; - config.bit_width = SPI_BIT_WIDTH_8BITS; - config.polarity = 1; - config.phase = 1; - config.wire_mode = SPI_4WIRE_MODE; - config.baud_rate = baud_rate; - config.bit_order = SPI_MSB_FIRST; - -#if CONFIG_SPI_DMA - config.dma_mode = 1; - s_spi_test.spi_tx_dma_chan = bk_dma_alloc(DMA_DEV_DTCM); - config.spi_tx_dma_chan = s_spi_test.spi_tx_dma_chan; - s_spi_test.spi_rx_dma_chan = bk_dma_alloc(DMA_DEV_DTCM); - config.spi_rx_dma_chan = s_spi_test.spi_rx_dma_chan; -#endif - - if(role == SPI_ROLE_MASTER) - BK_LOG_ON_ERR(bk_spi_register_tx_finish_isr(id, (spi_isr_t)spi_data_test_tx_finish_isr, NULL)); - - BK_LOG_ON_ERR(bk_spi_init(id, &config)); - -} - -static void spi_data_test_spi_deconfig(spi_id_t id) -{ - BK_LOG_ON_ERR(bk_spi_unregister_tx_finish_isr(id)); - BK_LOG_ON_ERR(bk_spi_deinit(id)); - bk_dma_free(DMA_DEV_DTCM, s_spi_test.spi_tx_dma_chan); - bk_dma_free(DMA_DEV_DTCM, s_spi_test.spi_rx_dma_chan); -} - -static void spi_data_test_exchange_role(void) -{ - spi_data_test_spi_deconfig(s_spi_test.spi_id); - - if(s_spi_test.role == SPI_ROLE_MASTER) - s_spi_test.role = SPI_ROLE_SLAVE; - else - s_spi_test.role = SPI_ROLE_MASTER; - - spi_data_test_spi_config(s_spi_test.spi_id, s_spi_test.role, s_spi_test.baud_rate); - -} - -static void cli_spi_data_txrx_test(uint32_t data) -{ - int ret = -1; - - int spi_tx_finish_isr_ret = -1; - int uart_isr_ret = -1; - int cnt = 0; - uint8_t rx_data; - - if(NULL == s_spi_test.uart_rx_semaphore) - { - ret = rtos_init_semaphore(&s_spi_test.uart_rx_semaphore, 1); - if (kNoErr != ret) - CLI_LOGI("s_spi_test.uart_rx_semaphore failed\r\n"); - } - - if(NULL == s_spi_test.spi_tx_finish_semaphore) - { - ret = rtos_init_semaphore(&s_spi_test.spi_tx_finish_semaphore, 1); - if (kNoErr != ret) - CLI_LOGI("s_spi_test.spi_tx_finish_semaphore failed\r\n"); - } - - CLI_LOGI("cli_spi_data_txrx_test\r\n"); - - while (1) { - - if (s_spi_test.role == SPI_ROLE_MASTER) { - - spi_tx_finish_isr_ret = rtos_get_semaphore(&s_spi_test.spi_tx_finish_semaphore, BEKEN_WAIT_FOREVER); - if(kNoErr == spi_tx_finish_isr_ret) { - rtos_delay_milliseconds(10); - BK_LOG_ON_ERR(bk_uart_write_bytes(s_spi_test.uart_id, s_spi_test.data, s_spi_test.data_len)); - for(int j = 0; j < s_spi_test.data_len; j++) { - CLI_LOGI("s_spi_test.data[%d]: %d\r\n", j, s_spi_test.data[j]); - } - CLI_LOGI("spi Tx finish! UART send OK!\r\n"); - - if (s_spi_test.data) { - os_free(s_spi_test.data); - } - - if(s_spi_test.exchange_flag) { - spi_data_test_exchange_role(); - CLI_LOGI("spi EXCHANGE ROLE! MASTER ==> SLAVE\r\n"); - } - } - } else { - - uart_isr_ret = rtos_get_semaphore(&s_spi_test.uart_rx_semaphore, 300); - if(kNoErr == uart_isr_ret) { - while(1) /* read all data from rx-FIFO. */ - { - ret = uart_read_byte_ex(s_spi_test.uart_id, &rx_data); - if (ret == -1) - break; - s_spi_test.uart_get_data[cnt] = rx_data; - cnt++; - if(cnt >= PER_PACKET_MAX_BYTES_SIZE) - break; - } - - if (cnt <= 0) - break; - - if (cnt > 0) { - s_spi_test.data_len = cnt; - for(int i = 0; i < cnt; i++) { - if(s_spi_test.spi_get_buffer[i] != s_spi_test.uart_get_data[i]) - CLI_LOGI("ERROR spi_get_buffer[%d]: %d uart_get_data[%d]: %d\r\n", - i, s_spi_test.spi_get_buffer[i], i, s_spi_test.uart_get_data[i]); - else - CLI_LOGI("OK !!!spi get data == uart get data\r\n"); - - s_spi_test.spi_get_buffer[i] = 0; - s_spi_test.uart_get_data[i] = 0; - } - cnt = 0; - } - - if(s_spi_test.exchange_flag) { - spi_data_test_exchange_role(); - CLI_LOGI("spi EXCHANGE ROLE! SLAVE ==> MASTER\r\n"); - } - }else { - CLI_LOGI("BEKEN_WAIT_FOREVER for spi read\r\n"); - BK_LOG_ON_ERR(bk_spi_read_bytes(s_spi_test.spi_id, s_spi_test.spi_get_buffer, s_spi_test.data_len)); - } - } - - } - -} - -static void spi_data_test_uart_rx_isr(uart_id_t id, void *param) -{ - int ret; - - ret = rtos_set_semaphore(&s_spi_test.uart_rx_semaphore); - if(kNoErr !=ret) - CLI_LOGI("spi_data_test_uart_rx_isr: uart set sema failed\r\n"); - return; -} - -static void spi_data_test_uart_config(void) -{ - uart_config_t config = {0}; - os_memset(&config, 0, sizeof(uart_config_t)); - config.baud_rate = UART_BAUD_RATE; - config.data_bits = UART_DATA_8_BITS; - config.parity = UART_PARITY_NONE; - config.stop_bits = UART_STOP_BITS_1; - config.flow_ctrl = UART_FLOWCTRL_DISABLE; - config.src_clk = UART_SCLK_XTAL_26M; - - BK_LOG_ON_ERR(bk_uart_init(s_spi_test.uart_id, &config)); - BK_LOG_ON_ERR(bk_uart_disable_sw_fifo(s_spi_test.uart_id)); - BK_LOG_ON_ERR(bk_uart_register_rx_isr(s_spi_test.uart_id, - (uart_isr_t)spi_data_test_uart_rx_isr, NULL)); - BK_LOG_ON_ERR(bk_uart_enable_rx_interrupt(s_spi_test.uart_id)); - -} - -static void spi_data_test_uart_deconfig(void) -{ - BK_LOG_ON_ERR(bk_uart_disable_rx_interrupt(s_spi_test.uart_id)); - BK_LOG_ON_ERR(bk_uart_register_rx_isr(s_spi_test.uart_id, NULL, NULL)); - BK_LOG_ON_ERR(bk_uart_deinit(s_spi_test.uart_id)); - s_spi_test.uart_id = UART_ID_MAX; - -} - -static void cli_spi_data_txrx_test_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - if (argc < 4) { - cli_spi_help(); - return; - } - - spi_id_t spi_id = os_strtoul(argv[1], NULL, 10); - spi_role_t role; - uint32_t baud_rate; - - if (os_strcmp(argv[2], "master") == 0) { - role = SPI_ROLE_MASTER; - } else if(os_strcmp(argv[2], "slave") == 0){ - role = SPI_ROLE_SLAVE; - } else { - cli_spi_help(); - return; - } - - baud_rate = os_strtoul(argv[3], NULL, 10); - - if (os_strcmp(argv[4], "start") == 0) { - s_spi_test.spi_id = spi_id; - s_spi_test.role = role; - s_spi_test.baud_rate = baud_rate; - s_spi_test.uart_get_data = (uint8_t *)os_zalloc(PER_PACKET_MAX_BYTES_SIZE); - s_spi_test.spi_get_buffer = (uint8_t *)os_zalloc(PER_PACKET_MAX_BYTES_SIZE); - - if (!s_spi_test.handle) { - if (os_strcmp(argv[5], "uart2")== 0) { - s_spi_test.uart_id = UART_ID_1; - CLI_LOGD("cli_spi_test Maybe UART2 for log output!!!\n"); - } else if (os_strcmp(argv[5], "uart3")== 0) { - s_spi_test.uart_id = UART_ID_2; - CLI_LOGD("cli_spi_test Maybe UART3 for log output!!!\n"); - } else { - cli_spi_help(); - return; - } - } else { - CLI_LOGI("spi_data_test TASK WARKING!!!\n"); - return; - } - - if (os_strcmp(argv[6], "exchange") == 0) - s_spi_test.exchange_flag = 1; - else - s_spi_test.exchange_flag = 0; - - spi_data_test_uart_config(); - spi_data_test_spi_config(spi_id, role, baud_rate); - -#if (CONFIG_TRNG_SUPPORT) - BK_LOG_ON_ERR(bk_trng_driver_init()); - BK_LOG_ON_ERR(bk_trng_start()); -#endif - - if(rtos_create_thread(&s_spi_test.handle, 8, "spi_data_test", - (beken_thread_function_t) cli_spi_data_txrx_test, 2048, 0)) { - CLI_LOGI("spi_data_txrx_test rtos_create_thread FAILED!\n"); - return; - } - - } - - if (os_strcmp(argv[4], "stop") == 0) { - if (os_strcmp(argv[5], "uart2")== 0) { - if(s_spi_test.uart_id != UART_ID_1) { - CLI_LOGI("PLEASE enter a correct ID\n"); - return; - } else - s_spi_test.uart_id = UART_ID_1; - } else if (os_strcmp(argv[5], "uart3")== 0) { - if(s_spi_test.uart_id != UART_ID_2) { - CLI_LOGI("PLEASE enter a correct ID\n"); - return; - } else - s_spi_test.uart_id = UART_ID_2; - } else { - cli_spi_help(); - return; - } - - rtos_delete_thread(&s_spi_test.handle); - s_spi_test.handle = NULL; - spi_data_test_uart_deconfig(); - - if(s_spi_test.spi_id != spi_id) { - cli_spi_help(); - return; - } else - spi_data_test_spi_deconfig(spi_id); - - if(NULL != s_spi_test.uart_get_data) - os_free(s_spi_test.uart_get_data); - - if(NULL != s_spi_test.spi_get_buffer) - os_free(s_spi_test.spi_get_buffer); - CLI_LOGI("cli_spi_data_txrx_test task stop\n"); - } - - if (os_strcmp(argv[3], "send") == 0) { - uint32_t buf_len = os_strtoul(argv[4], NULL, 10); - if(s_spi_test.spi_id != spi_id) { - cli_spi_help(); - return; - } else { - if(s_spi_test.role == SPI_ROLE_MASTER) { - spi_data_test_send(spi_id, buf_len); - } else { - CLI_LOGI("PLEASE use master send\n"); - } - } - } -} - - -#define SPI_CMD_CNT (sizeof(s_spi_commands) / sizeof(struct cli_command)) -static const struct cli_command s_spi_commands[] = { - {"spi_driver", "spi_driver {init|deinit}", cli_spi_driver_cmd}, - {"spi", "spi {init|write|read}", cli_spi_cmd}, - {"spi_config", "spi_config {id} {mode|baud_rate} [...]", cli_spi_config_cmd}, - {"spi_int", "spi_int {id} {reg} {tx|rx}", cli_spi_int_cmd}, - {"spi_data_test", "spi_data_test {id} {master|slave} {baud_rate|send}[...]", cli_spi_data_txrx_test_cmd}, -}; - -int cli_spi_init(void) -{ - BK_LOG_ON_ERR(bk_spi_driver_init()); - return cli_register_commands(s_spi_commands, SPI_CMD_CNT); -} - - diff --git a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_temp_detect.c b/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_temp_detect.c deleted file mode 100644 index 153231fa9fd1402ec6a881ee4bda2c694f296765..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_temp_detect.c +++ /dev/null @@ -1,43 +0,0 @@ -#include "cli.h" -#include "temp_detect_pub.h" - -void cli_temp_detect_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - uint32_t temperature = 0; - - if (argc == 1) { - BK_LOG_ON_ERR(temp_detect_get_temperature(&temperature)); - CLI_LOGI("current temperature is %d\n", temperature); - return; - } - -#if CONFIG_TEMP_DETECT - - if (os_strcmp(argv[1], "init") == 0) { - uint32_t init_temperature = 0; - - if (argc == 3) - init_temperature = os_strtoul(argv[2], NULL, 10); - - BK_LOG_ON_ERR(temp_detect_init(init_temperature)); - } else if (os_strcmp(argv[1], "deinit") == 0) { - BK_LOG_ON_ERR(temp_detect_deinit()); - } else if (os_strcmp(argv[1], "start") == 0) { - BK_LOG_ON_ERR(temp_detect_start()); - } else if (os_strcmp(argv[1], "stop") == 0) { - BK_LOG_ON_ERR(temp_detect_stop()); - } else if (os_strcmp(argv[1], "update") == 0) { - //TODO by Frank!! - } -#endif -} - -#define TEMP_DETECT_CMD_CNT (sizeof(s_temp_detect_commands) / sizeof(struct cli_command)) -static const struct cli_command s_temp_detect_commands[] = { - {"tempd", "tempd [init|deinit|stop|start|update]", cli_temp_detect_cmd}, -}; - -int cli_temp_detect_init(void) -{ - return cli_register_commands(s_temp_detect_commands, TEMP_DETECT_CMD_CNT); -} diff --git a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_timer.c b/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_timer.c deleted file mode 100644 index a2374725bbea509aa83ad728628f8dd1cf3a177e..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_timer.c +++ /dev/null @@ -1,69 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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 -#include "cli.h" -#include - -static void cli_timer_isr(timer_id_t chan) -{ - CLI_LOGI("[TIMER][ISR] chan:%d\r\n", chan); -} - -static void cli_timer_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - int ret = 0; - uint8_t channel = 0; - uint32_t time_ms = 0, read_cnt = 0; - - channel = os_strtoul(argv[1], NULL, 10); - - if (os_strcmp(argv[2], "start") == 0) { - time_ms = os_strtoul(argv[3], NULL, 10); - CLI_LOGI("[TIMER][START] channel:%d, time_ms:%d\r\n", channel, time_ms); - ret = bk_timer_start(channel, time_ms, cli_timer_isr); - if (ret != BK_OK) { - CLI_LOGW("[TIMER][START] start failed, error code:%x\n", ret); - } - } else if (os_strcmp(argv[2], "stop") == 0) { - CLI_LOGI("[TIMER][STOP] channel:%d\r\n", channel); - bk_timer_stop(channel); - } else if (os_strcmp(argv[2], "read") == 0) { - read_cnt = bk_timer_get_cnt(channel); - CLI_LOGI("[TIMER][READ] read cnt:%x\r\n", read_cnt); - } else if (os_strcmp(argv[2], "enable") == 0) { - bk_timer_enable(channel); - CLI_LOGI("[TIMER][ENABLE] channel:%x\r\n", channel); - } else if (os_strcmp(argv[2], "disable") == 0) { - bk_timer_disable(channel); - CLI_LOGI("[TIMER][DISABLE] channel:%x\r\n", channel); - } else if (os_strcmp(argv[2], "get_period") == 0) { - read_cnt = bk_timer_get_period(channel); - CLI_LOGI("[TIMER][GET][PERIOD] period value:%x\r\n", read_cnt); - } else { - CLI_LOGW("timer {chan} {start|stop|read} [...]\r\n"); - } -} - -#define TIMER_CMD_CNT (sizeof(s_timer_commands) / sizeof(struct cli_command)) -static const struct cli_command s_timer_commands[] = { - {"timer", "timer {chan} {start|stop|read} [...]", cli_timer_cmd}, -}; - -int cli_timer_init(void) -{ - BK_LOG_ON_ERR(bk_timer_driver_init()); - return cli_register_commands(s_timer_commands, TIMER_CMD_CNT); -} - diff --git a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_touch.c b/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_touch.c deleted file mode 100755 index edd96bc184b7afd5557af3704344e4e2d0fb54f0..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_touch.c +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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 "cli.h" - - -#if CONFIG_TOUCH -extern void cli_touch_single_channel_calib_mode_test_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv); - -extern void cli_touch_single_channel_manul_mode_test_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv); - -extern void cli_touch_multi_channel_scan_mode_test_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv); - -extern void cli_touch_single_channel_multi_calib_test_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv); - -extern void cli_touch_multi_channel_cyclic_calib_test_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv); - -#define TOUCH_CMD_CNT (sizeof(s_touch_commands) / sizeof(struct cli_command)) - -static const struct cli_command s_touch_commands[] = { - {"touch_single_channel_calib_mode_test", "touch_single_channel_calib_mode_test {0|1|...|15} {0|1|2|3}", cli_touch_single_channel_calib_mode_test_cmd}, - {"touch_single_channel_manul_mode_test", "touch_single_channel_manul_mode_test {0|1|...|15} {calibration_value}", cli_touch_single_channel_manul_mode_test_cmd}, - {"touch_multi_channel_scan_mode_test", "touch_multi_channel_scan_mode_test {start|stop} {0|1|2|3}", cli_touch_multi_channel_scan_mode_test_cmd}, - {"touch_single_channel_multi_calib_test", "touch_single_channel_multi_calib_test {0|1|...|15} {0|1|2|3}", cli_touch_single_channel_multi_calib_test_cmd}, - {"touch_multi_channel_cyclic_calib_test", "touch_multi_channel_cyclic_calib_test {start|stop} {0|1|2|3}", cli_touch_multi_channel_cyclic_calib_test_cmd}, -}; - -int cli_touch_init(void) -{ - return cli_register_commands(s_touch_commands, TOUCH_CMD_CNT); -} - -#endif - - diff --git a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_trng.c b/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_trng.c deleted file mode 100644 index c00adffcb2c0ce6a8e2bd0ab4561ef7c138eaebc..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_trng.c +++ /dev/null @@ -1,81 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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 -#include "cli.h" -#include - -static void cli_trng_help(void) -{ - CLI_LOGI("trng_driver init\r\n"); - CLI_LOGI("trng_driver deinit\r\n"); - CLI_LOGI("trng start\r\n"); - CLI_LOGI("trng stop\r\n"); - CLI_LOGI("trng get\r\n"); -} - -static void cli_trng_driver_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - if (argc < 2) { - cli_trng_help(); - return; - } - - if (os_strcmp(argv[1], "init") == 0) { - BK_LOG_ON_ERR(bk_trng_driver_init()); - CLI_LOGI("trng driver init\n"); - } else if (os_strcmp(argv[1], "deinit") == 0) { - BK_LOG_ON_ERR(bk_trng_driver_deinit()); - CLI_LOGI("trng driver deinit\n"); - } else { - cli_trng_help(); - return; - } -} - -static void cli_trng_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - if (argc < 2) { - cli_trng_help(); - return; - } - - if (os_strcmp(argv[1], "start") == 0) { - BK_LOG_ON_ERR(bk_trng_start()); - CLI_LOGI("trng start\r\n"); - } else if (os_strcmp(argv[1], "stop") == 0) { - BK_LOG_ON_ERR(bk_trng_stop()); - CLI_LOGI("trng stop\r\n"); - }else if (os_strcmp(argv[1], "get") == 0) { - int random_data = bk_rand(); - CLI_LOGI("trng get random data:%u\r\n", random_data); - } else { - cli_trng_help(); - return; - } -} - -#define TRNG_CMD_CNT (sizeof(s_trng_commands) / sizeof(struct cli_command)) -static const struct cli_command s_trng_commands[] = { - {"trng_driver", "{init|deinit}", cli_trng_driver_cmd}, - {"trng", "trng {start|stop|get}", cli_trng_cmd} -}; - -int cli_trng_init(void) -{ - BK_LOG_ON_ERR(bk_trng_driver_init()); - return cli_register_commands(s_trng_commands, TRNG_CMD_CNT); -} - - diff --git a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_uart.c b/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_uart.c deleted file mode 100644 index 370a792578da527e950356876a3d0adfc4bcdfbb..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_uart.c +++ /dev/null @@ -1,403 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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 -#include "cli.h" -#include -#include -#include "uart_statis.h" -#include "bk_misc.h" - -#define CLI_UART_RECV_BUF_LEN 1024 - -static void cli_uart_help(void) -{ - CLI_LOGI("uart_driver init\n"); - CLI_LOGI("uart_driver deinit\n"); - CLI_LOGI("uart_int {id} {enable|disable|reg} {tx|rx}\n"); - CLI_LOGI("uart {id} {init|deinit|write|read|write_string|dump_statis} [...]\n"); - CLI_LOGI("uart_test {idle_start|idle_stop} {uart1|uart2|uart3}\n"); -} - -static void cli_uart_driver_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - if (argc < 2) { - cli_uart_help(); - return; - } - - if (os_strcmp(argv[1], "init") == 0) { - BK_LOG_ON_ERR(bk_uart_driver_init()); - CLI_LOGI("uart driver init\n"); - } else if (os_strcmp(argv[1], "deinit") == 0) { - BK_LOG_ON_ERR(bk_uart_driver_deinit()); - CLI_LOGI("uart driver deinit\n"); - } else { - cli_uart_help(); - return; - } -} - -static void cli_uart_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - uint32_t uart_id; - - if (argc < 2) { - cli_uart_help(); - return; - } - - uart_id = os_strtoul(argv[1], NULL, 10); - - if (os_strcmp(argv[2], "init") == 0) { - CLI_RET_ON_INVALID_ARGC(argc, 5); - uart_config_t config = {0}; - os_memset(&config, 0, sizeof(uart_config_t)); - config.baud_rate = os_strtoul(argv[3], NULL, 10); - config.data_bits = os_strtoul(argv[4], NULL, 10); - config.parity = os_strtoul(argv[5], NULL, 10); - config.stop_bits = os_strtoul(argv[6], NULL, 10); - if (argc > 7) { - config.flow_ctrl = os_strtoul(argv[7], NULL, 10); - } - if (argc > 8) { - config.src_clk = os_strtoul(argv[8], NULL, 10); - } - - BK_LOG_ON_ERR(bk_uart_init(uart_id, &config)); - CLI_LOGI("uart init, uart_id=%d\n", uart_id); - } else if (os_strcmp(argv[2], "deinit") == 0) { - BK_LOG_ON_ERR(bk_uart_deinit(uart_id)); - CLI_LOGI("uart deinit, uart_id=%d\n", uart_id); - } else if (os_strcmp(argv[2], "write") == 0) { - uint32_t buf_len = os_strtoul(argv[3], NULL, 10); - uint8_t *send_data = (uint8_t *)os_malloc(buf_len); - if (send_data == NULL) { - CLI_LOGE("send buffer malloc failed\r\n"); - return; - } - os_memset(send_data, 0, buf_len); - for (int i = 0; i < buf_len; i++) { - send_data[i] = i & 0xff; - } - BK_LOG_ON_ERR(bk_uart_write_bytes(uart_id, send_data, buf_len)); - if (send_data) { - os_free(send_data); - } - send_data = NULL; - CLI_LOGI("uart write, uart_id=%d, data_len:%d\n", uart_id, buf_len); - } else if (os_strcmp(argv[2], "read") == 0) { - uint32_t buf_len = os_strtoul(argv[3], NULL, 10); - uint8_t *recv_data = (uint8_t *)os_malloc(buf_len); - if (recv_data == NULL) { - CLI_LOGE("recv buffer malloc failed\r\n"); - return; - } - int time_out = os_strtoul(argv[4], NULL, 10); - if (time_out < 0) { - time_out = BEKEN_WAIT_FOREVER; - } - int data_len = bk_uart_read_bytes(uart_id, recv_data, buf_len, time_out); - if (data_len < 0) { - CLI_LOGE("uart read failed, ret:-0x%x\r\n", -data_len); - goto exit; - } - CLI_LOGI("uart read, uart_id=%d, time_out:%x data_len:%d\n", uart_id, time_out, data_len); - for (int i = 0; i < data_len; i++) { - CLI_LOGI("recv_buffer[%d]=0x%x\n", i, recv_data[i]); - } -exit: - if (recv_data) { - os_free(recv_data); - } - recv_data = NULL; - } else if (os_strcmp(argv[2], "write_string") == 0) { - char send_data[] = "beken uart write string test\r\n"; - BK_LOG_ON_ERR(bk_uart_write_bytes(uart_id, send_data, os_strlen(send_data))); - CLI_LOGI("uart write string, uart_id=%d, data_len:%d\n", uart_id, os_strlen(send_data)); - } -#if CONFIG_UART_STATIS - else if (os_strcmp(argv[2], "dump_statis") == 0) { - uart_statis_dump(uart_id); - CLI_LOGI("uart dump statis ok\r\n"); - } else if (os_strcmp(argv[2], "reset_statis") == 0) { - uart_statis_id_init(uart_id); - CLI_LOGI("uart reset statis ok\r\n"); - } -#endif - else { - cli_uart_help(); - return; - } -} - -static void cli_uart_config_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - uint32_t uart_id; - - if (argc < 4) { - cli_uart_help(); - return; - } - - uart_id = os_strtoul(argv[1], NULL, 10); - - if (os_strcmp(argv[2], "baud_rate") == 0) { - CLI_RET_ON_INVALID_ARGC(argc, 4); - uint32_t baud_rate = os_strtoul(argv[3], NULL, 10); - BK_LOG_ON_ERR(bk_uart_set_baud_rate(uart_id, baud_rate)); - CLI_LOGI("uart(%d) config baud_rate:%d\n", uart_id, baud_rate); - } else if (os_strcmp(argv[2], "data_bits") == 0) { - CLI_RET_ON_INVALID_ARGC(argc, 4); - uint32_t data_bits = os_strtoul(argv[3], NULL, 10); - BK_LOG_ON_ERR(bk_uart_set_data_bits(uart_id, data_bits)); - CLI_LOGI("uart(%d) config data_bits:%d\n", uart_id, data_bits); - } else if (os_strcmp(argv[2], "stop_bits") == 0) { - CLI_RET_ON_INVALID_ARGC(argc, 4); - uint32_t stop_bits = os_strtoul(argv[3], NULL, 10); - BK_LOG_ON_ERR(bk_uart_set_stop_bits(uart_id, stop_bits)); - CLI_LOGI("uart(%d) config stop_bits:%d\n", uart_id, stop_bits); - } else if (os_strcmp(argv[2], "parity") == 0) { - CLI_RET_ON_INVALID_ARGC(argc, 4); - uint32_t parity = os_strtoul(argv[3], NULL, 10); - BK_LOG_ON_ERR(bk_uart_set_parity(uart_id, parity)); - CLI_LOGI("uart(%d) config parity:%d\n", uart_id, parity); - } else if (os_strcmp(argv[2], "flow_ctrl") == 0) { - CLI_RET_ON_INVALID_ARGC(argc, 4); - uint32_t rx_threshold = os_strtoul(argv[3], NULL, 10); - BK_LOG_ON_ERR(bk_uart_set_hw_flow_ctrl(uart_id, rx_threshold)); - CLI_LOGI("uart(%d) config flow_ctrl:%d\n", uart_id, rx_threshold); - } else if (os_strcmp(argv[2], "rx_thresh") == 0) { - CLI_RET_ON_INVALID_ARGC(argc, 4); - uint32_t rx_thresh = os_strtoul(argv[3], NULL, 10); - BK_LOG_ON_ERR(bk_uart_set_rx_full_threshold(uart_id, rx_thresh)); - CLI_LOGI("uart(%d) config rx_thresh:%d\n", uart_id, rx_thresh); - } else if (os_strcmp(argv[2], "tx_thresh") == 0) { - CLI_RET_ON_INVALID_ARGC(argc, 4); - uint32_t tx_thresh = os_strtoul(argv[3], NULL, 10); - BK_LOG_ON_ERR(bk_uart_set_tx_empty_threshold(uart_id, tx_thresh)); - CLI_LOGI("uart(%d) config tx_thresh:%d\n", uart_id, tx_thresh); - } else if (os_strcmp(argv[2], "rx_timeout") == 0) { - CLI_RET_ON_INVALID_ARGC(argc, 4); - uint32_t timeout_thresh = os_strtoul(argv[3], NULL, 10); - BK_LOG_ON_ERR(bk_uart_set_rx_timeout(uart_id, timeout_thresh)); - CLI_LOGI("uart(%d) config rx_timeout:%d\n", uart_id, timeout_thresh); - } else { - cli_uart_help(); - return; - } -} - -static void cli_uart_rx_isr(uart_id_t id, void *param) -{ - CLI_LOGI("uart_rx_isr(%d)\n", id); -} - -static void cli_uart_tx_isr(uart_id_t id, void *param) -{ - CLI_LOGI("uart_tx_isr(%d)\n", id); -} - -static void cli_uart_int_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - uint32_t uart_id; - - if (argc != 4) { - cli_uart_help(); - return; - } - - uart_id = os_strtoul(argv[1], NULL, 10); - - if (os_strcmp(argv[2], "enable") == 0) { - if (os_strcmp(argv[3], "tx") == 0) { - BK_LOG_ON_ERR(bk_uart_enable_tx_interrupt(uart_id)); - CLI_LOGI("uart id:%d enable tx interrupt\n", uart_id); - } else { - BK_LOG_ON_ERR(bk_uart_enable_rx_interrupt(uart_id)); - CLI_LOGI("uart id:%d enable rx interrupt\n", uart_id); - } - } else if (os_strcmp(argv[2], "disable") == 0) { - if (os_strcmp(argv[3], "tx") == 0) { - BK_LOG_ON_ERR(bk_uart_disable_tx_interrupt(uart_id)); - CLI_LOGI("uart id:%d disable tx interrupt\n", uart_id); - } else { - BK_LOG_ON_ERR(bk_uart_disable_rx_interrupt(uart_id)); - CLI_LOGI("uart id:%d disable rx interrupt\n", uart_id); - } - } else if (os_strcmp(argv[2], "reg") == 0) { - if (os_strcmp(argv[3], "tx") == 0) { - BK_LOG_ON_ERR(bk_uart_register_tx_isr(uart_id, cli_uart_tx_isr, NULL)); - CLI_LOGI("uart id:%d register tx interrupt isr\n", uart_id); - } else { - BK_LOG_ON_ERR(bk_uart_register_rx_isr(uart_id, cli_uart_rx_isr, NULL)); - CLI_LOGI("uart id:%d register rx interrupt isr\n", uart_id); - } - } else { - cli_uart_help(); - return; - } -} - -#if CONFIG_IDLE_UART_OUT_TEST -static beken_thread_t idle_uart_out_test_handle = NULL; -static uint16_t idle_uart_out_test_id = 0; -static void cli_idle_uart_out_test_isr(uart_id_t id, void *param) -{ - return; -} - -static void cli_idle_uart_out_test(void *arg) -{ - while (1) { - unsigned long random; - char tx_buffer[16]; - - random = bk_rand(); - itoa(random, tx_buffer, 14); - tx_buffer[16] = '\0'; - uart_write_string(idle_uart_out_test_id, tx_buffer); - - } - rtos_delete_thread(&idle_uart_out_test_handle); -} - -static void cli_uart_test_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - if (argc < 2) { - cli_uart_help(); - return; - } - - if (os_strcmp(argv[1], "idle_start") == 0) { - if (!idle_uart_out_test_handle) { - if (os_strcmp(argv[2], "uart1") == 0) { -#if !CONFIG_PRINT_PORT_UART1 - idle_uart_out_test_id = UART_ID_0; - CLI_LOGI("idle_uart_out task start: uart_id = UART1\n" ); - -#else - CLI_LOGI("cli_uart_test_cmd UART1 for log output!!!\n"); - return; -#endif - } else if (os_strcmp(argv[2], "uart2")== 0) { -#if !CONFIG_PRINT_PORT_UART2 - idle_uart_out_test_id = UART_ID_1; - CLI_LOGI("idle_uart_out task start: uart_id = UART2\n" ); - -#else - CLI_LOGI("cli_uart_test_cmd UART2 for log output!!!\n"); - return; -#endif - } else if (os_strcmp(argv[2], "uart3")== 0) { -#if !CONFIG_PRINT_PORT_UART3 - idle_uart_out_test_id = UART_ID_2; - CLI_LOGI("idle_uart_out task start: uart_id = UART3\n" ); - -#else - CLI_LOGI("cli_uart_test_cmd UART3 for log output!!!\n"); - return; -#endif - - } else { - cli_uart_help(); - return; - } - - uart_config_t config = {0}; - os_memset(&config, 0, sizeof(uart_config_t)); - - config.baud_rate = UART_BAUD_RATE; - config.data_bits = UART_DATA_8_BITS; - config.parity = UART_PARITY_NONE; - config.stop_bits = UART_STOP_BITS_1; - config.flow_ctrl = UART_FLOWCTRL_DISABLE; - config.src_clk = UART_SCLK_XTAL_26M; - - BK_LOG_ON_ERR(bk_uart_init(idle_uart_out_test_id, &config)); - BK_LOG_ON_ERR(bk_uart_deinit(idle_uart_out_test_id)); - - BK_LOG_ON_ERR(bk_uart_register_tx_isr(idle_uart_out_test_id, cli_idle_uart_out_test_isr, NULL)); - BK_LOG_ON_ERR(bk_uart_enable_tx_interrupt(idle_uart_out_test_id)); - BK_LOG_ON_ERR(bk_uart_init(idle_uart_out_test_id, &config)); - BK_LOG_ON_ERR(bk_trng_driver_init()); - BK_LOG_ON_ERR(bk_trng_start()); - if(rtos_create_thread(&idle_uart_out_test_handle, 8, "idle_uart_out", - (beken_thread_function_t) cli_idle_uart_out_test, 2048, 0)) { - CLI_LOGI("cli_uart_test_cmd rtos_create_thread FAILED!\n"); - return; - } - }else { - CLI_LOGI("PLEASE stop the task\n"); - } - return; - } else if (os_strcmp(argv[1], "idle_stop") == 0) { - - if (idle_uart_out_test_handle) { - if (os_strcmp(argv[2], "uart1") == 0) { - if(idle_uart_out_test_id != UART_ID_0) { - CLI_LOGI("PLEASE enter a correct ID\n"); - return; - } else - idle_uart_out_test_id = UART_ID_0; - } else if (os_strcmp(argv[2], "uart2")== 0) { - if(idle_uart_out_test_id != UART_ID_1) { - CLI_LOGI("PLEASE enter a correct ID\n"); - return; - } else - idle_uart_out_test_id = UART_ID_1; - } else if (os_strcmp(argv[2], "uart3")== 0) { - if(idle_uart_out_test_id != UART_ID_2) { - CLI_LOGI("PLEASE enter a correct ID\n"); - return; - } else - idle_uart_out_test_id = UART_ID_2; - } else { - cli_uart_help(); - return; - } - - rtos_delete_thread(&idle_uart_out_test_handle); - idle_uart_out_test_handle = NULL; - BK_LOG_ON_ERR(bk_uart_disable_tx_interrupt(idle_uart_out_test_id)); - BK_LOG_ON_ERR(bk_uart_register_tx_isr(idle_uart_out_test_id, NULL, NULL)); - BK_LOG_ON_ERR(bk_uart_deinit(idle_uart_out_test_id)); - BK_LOG_ON_ERR(bk_trng_stop()); - CLI_LOGI("idle_uart_out task stop\n"); - } else { - CLI_LOGI("PLEASE start task FIRST!!!\n"); - } - return; - } - -} -#endif //CONFIG_IDLE_UART_OUT_TEST - -#define UART_CMD_CNT (sizeof(s_uart_commands) / sizeof(struct cli_command)) -static const struct cli_command s_uart_commands[] = { - {"uart_driver", "{init|deinit}", cli_uart_driver_cmd}, - {"uart", "uart {id} {init|deinit|write|read|write_string|dump_statis} [...]", cli_uart_cmd}, - {"uart_config", "uart_config {id} {baud_rate|data_bits} [...]", cli_uart_config_cmd}, - {"uart_int", "uart_int {id} {enable|disable|reg} {tx|rx}", cli_uart_int_cmd}, -#if CONFIG_IDLE_UART_OUT_TEST - {"uart_test", "{idle_start|idle_stop} {uart1|uart2|uart3}", cli_uart_test_cmd}, -#endif //CONFIG_IDLE_UART_OUT_TEST -}; - -int cli_uart_init(void) -{ - BK_LOG_ON_ERR(bk_uart_driver_init()); - return cli_register_commands(s_uart_commands, UART_CMD_CNT); -} - diff --git a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_usb.c b/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_usb.c deleted file mode 100755 index ad2048785426104ade10f91bba8a375888819259..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_usb.c +++ /dev/null @@ -1,410 +0,0 @@ -#include -#include "stdarg.h" -#include -#include "sys_rtos.h" -#include -#include -#include "bk_sys_ctrl.h" -#include "bk_cli.h" -#include -#include -#include "bk_usb.h" -#include "drv_model_pub.h" -#include "cli.h" - -#if CONFIG_USB_HOST -#if CONFIG_USB_MSD -#include "ff.h" -#include "diskio.h" -#endif - -static void cli_usb_help(void) -{ - CLI_LOGI("cli_usb_help!\r\n"); -} - -#if CONFIG_USB_MSD - -static FATFS *pfs = NULL; -uint8_t mount_flag = 0; - -void usb_mount_command(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - FRESULT fr; - char sys_path[10]; - int number = DISK_NUMBER_UDISK; - - if (pfs) - os_free(pfs); - - pfs = os_malloc(sizeof(FATFS)); - if (NULL == pfs) { - CLI_LOGI("f_mount malloc failed!\r\n"); - return; - } - - os_memset(sys_path, 0, sizeof(sys_path)); - sprintf(sys_path, "%d:", number); - fr = f_mount(pfs, sys_path, 1); - if (fr != FR_OK) { - mount_flag = 0; - CLI_LOGI("usb mount failed:%d\r\n", fr); - } else { - mount_flag = 1; - CLI_LOGI("usb mount OK!\r\n"); - } -} - - - -void usb_unmount_command(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - FRESULT fr; - char sys_path[10]; - int number = DISK_NUMBER_UDISK; - - if (mount_flag != 1) { - CLI_LOGI("usb hasn't initialization!\r\n"); - return; - } - - os_memset(sys_path, 0, sizeof(sys_path)); - sprintf(sys_path, "%d:", number); - fr = f_mount(NULL, sys_path, 1); - if (fr != FR_OK) { - CLI_LOGI("unmount %s fail.\r\n", sys_path); - return; - } - - if (pfs) { - os_free(pfs); - pfs = NULL; - } - - mount_flag = 0; - CLI_LOGI("usb unmount OK!\r\n"); -} - -static FRESULT usb_scan_files(char *path) -{ - FRESULT fr; - DIR dir; - FILINFO fno; - char path_temp[255]; - - fr = f_opendir(&dir, path); - if (fr == FR_OK) { - while (1) { - fr = f_readdir(&dir, &fno); - if (fr != FR_OK) - break; - if (fno.fname[0] == 0) - break; - if (fno.fattrib & AM_DIR) { - /* It is a directory */ - os_memset(path_temp, 0, sizeof(path_temp)); - sprintf(path_temp, "%s/%s", path, fno.fname); - fr = usb_scan_files(path_temp); - if (fr != FR_OK) break; - } else { - /* It is a file. */ - CLI_LOGI("%s/%s\r\n", path, fno.fname); - } - } - f_closedir(&dir); - } else - CLI_LOGI("f_opendir failed\r\n"); - - return fr; -} - -void usb_ls_command(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - FRESULT fr; - char sys_path[10]; - int number = DISK_NUMBER_UDISK; - - if (mount_flag != 1) { - CLI_LOGI("usb hasn't initialization!\r\n"); - return; - } - - os_memset(sys_path, 0, sizeof(sys_path)); - sprintf(sys_path, "%d:", number); - fr = usb_scan_files(sys_path); - if (fr != FR_OK) - CLI_LOGI("scan_files failed!\r\n"); -} -#endif - -void uvc_get_param(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - if (argc < 3) { - cli_usb_help(); - return; - } - uint32_t attribute = 0x00; - - if (os_strcmp(argv[1], "backlight") == 0) { - attribute = 0x01; - } else if (os_strcmp(argv[1], "brightness") == 0) { - attribute = 0x02; - } else if (os_strcmp(argv[1], "contrast") == 0) { - attribute = 0x03; - } else if (os_strcmp(argv[1], "gain") == 0) { - attribute = 0x04; - } else if (os_strcmp(argv[1], "powerlinefre") == 0) { - attribute = 0x05; - } else if (os_strcmp(argv[1], "hue") == 0) { - attribute = 0x06; - } else if (os_strcmp(argv[1], "hueauto") == 0) { - attribute = 0x10; - } else if (os_strcmp(argv[1], "saturation") == 0) { - attribute = 0x07; - } else if (os_strcmp(argv[1], "sharpness") == 0) { - attribute = 0x08; - } else if (os_strcmp(argv[1], "gamma") == 0) { - attribute = 0x09; - } else if (os_strcmp(argv[1], "wbt") == 0) { - attribute = 0x0a; - } else if (os_strcmp(argv[1], "wbtauto") == 0) { - attribute = 0x0b; - } else if (os_strcmp(argv[1], "wbc") == 0) { - attribute = 0x0c; - } else if (os_strcmp(argv[1], "wbcauto") == 0) { - attribute = 0x0d; - } else if (os_strcmp(argv[1], "digmu") == 0) { - attribute = 0x0e; - } else if (os_strcmp(argv[1], "digmulimit") == 0) { - attribute = 0x0f; - } else if (os_strcmp(argv[1], "analogvideo") == 0) { - attribute = 0x10; - } else if (os_strcmp(argv[1], "analoglock") == 0) { - attribute = 0x12; - } else { - cli_usb_help(); - return; - } - - - if (os_strcmp(argv[2], "cur") == 0) { - bk_uvc_get_cur(attribute); - } else if (os_strcmp(argv[2], "min") == 0) { - bk_uvc_get_min(attribute); - } else if (os_strcmp(argv[2], "max") == 0) { - bk_uvc_get_max(attribute); - } else if (os_strcmp(argv[2], "info") == 0) { - bk_uvc_get_info(attribute); - } else if (os_strcmp(argv[2], "len") == 0) { - bk_uvc_get_len(attribute); - } else if (os_strcmp(argv[2], "res") == 0) { - bk_uvc_get_res(attribute); - } else if (os_strcmp(argv[2], "def") == 0) { - bk_uvc_get_def(attribute); - } else { - cli_usb_help(); - return; - } - -} - -void uvc_set_param(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - if (argc < 3) { - cli_usb_help(); - CLI_LOGI("cli_usb_help!\r\n"); - return; - } - uint32_t attribute = 0x00; - uint32_t param = 0; - - if (os_strcmp(argv[1], "backlight") == 0) { - attribute = 0x01; - } else if (os_strcmp(argv[1], "brightness") == 0) { - attribute = 0x02; - } else if (os_strcmp(argv[1], "contrast") == 0) { - attribute = 0x03; - } else if (os_strcmp(argv[1], "gain") == 0) { - attribute = 0x04; - } else if (os_strcmp(argv[1], "powerlinefre") == 0) { - attribute = 0x05; - } else if (os_strcmp(argv[1], "hue") == 0) { - attribute = 0x06; - } else if (os_strcmp(argv[1], "hueauto") == 0) { - attribute = 0x10; - } else if (os_strcmp(argv[1], "saturation") == 0) { - attribute = 0x07; - } else if (os_strcmp(argv[1], "sharpness") == 0) { - attribute = 0x08; - } else if (os_strcmp(argv[1], "gamma") == 0) { - attribute = 0x09; - } else if (os_strcmp(argv[1], "wbt") == 0) { - attribute = 0x0a; - } else if (os_strcmp(argv[1], "wbtauto") == 0) { - attribute = 0x0b; - } else if (os_strcmp(argv[1], "wbc") == 0) { - attribute = 0x0c; - } else if (os_strcmp(argv[1], "wbcauto") == 0) { - attribute = 0x0d; - } else if (os_strcmp(argv[1], "digmu") == 0) { - attribute = 0x0e; - } else if (os_strcmp(argv[1], "digmulimit") == 0) { - attribute = 0x0f; - } else if (os_strcmp(argv[1], "analogvideo") == 0) { - attribute = 0x10; - } else if (os_strcmp(argv[1], "analoglock") == 0) { - attribute = 0x12; - } else { - cli_usb_help(); - return; - } - - param = os_strtoul(argv[2], NULL, 10); - bk_uvc_set_cur(attribute, param); - -} - -void uvc_start_stream(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - if (argc < 2) { - cli_usb_help(); - return; - } - - if (os_strcmp(argv[1], "start") == 0) { - bk_uvc_start(); - } else if(os_strcmp(argv[1], "stop") == 0) { - bk_uvc_stop(); - } - else { - cli_usb_help(); - return; - } - -} - - -#ifdef CONFIG_USB_UVC -void cli_fuvc_test_init(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - if (argc < 2) { - cli_usb_help(); - return; - } - - if (os_strcmp(argv[1], "init") == 0) { - fuvc_test_init(1); - } else { - cli_usb_help(); - return; - } - -} - -void cli_fuvc_printf_test_buff(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - if (argc < 2) { - cli_usb_help(); - return; - } - - if (os_strcmp(argv[1], "print") == 0) { - printf_test_buff(); - } else { - cli_usb_help(); - return; - } - -} -#endif - -#if CONFIG_USB_PLUG_IN_OUT -void cli_usb_plug_init(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - if (argc < 2) { - cli_usb_help(); - return; - } - - if (os_strcmp(argv[1], "init") == 0) { - usb_plug_inout_init(); - } else if (os_strcmp(argv[1], "deinit") == 0) { - usb_plug_inout_deinit(); - } else { - cli_usb_help(); - return; - } - -} - -void cli_usb_plug_inout(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - if (argc < 2) { - cli_usb_help(); - return; - } - - if (os_strcmp(argv[1], "open") == 0) { - usb_plug_inout_open(); - CLI_LOGI("cli_usb_plug_inout inout open!\r\n"); - } else if (os_strcmp(argv[1], "close") == 0) { - usb_plug_inout_close(); - CLI_LOGI("cli_usb_plug_inout inout close!\r\n"); - } else { - cli_usb_help(); - return; - } - -} -#endif - -void cli_usb_open_close(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - if (argc < 2) { - cli_usb_help(); - return; - } - - if (os_strcmp(argv[1], "open_host") == 0) { - CLI_LOGI("cli_usb_open host! %d\r\n", bk_usb_open(0)); - } else if (os_strcmp(argv[1], "open_dev") == 0) { - CLI_LOGI("cli_usb_open device!\r\n"); - bk_usb_open(1); - } else if (os_strcmp(argv[1], "close") == 0) { - bk_usb_close(); - } else { - cli_usb_help(); - return; - } - -} - -const struct cli_command usb_host_clis[] = { - -#if CONFIG_USB_MSD - {"usb_mount", "usb mount", usb_mount_command}, - {"usb_unmount", "usb unmount", usb_unmount_command}, - {"usb_ls", "usb list system", usb_ls_command}, -#endif -#ifdef CONFIG_USB_UVC - {"fuvc_test", "cli_fuvc_test_init", cli_fuvc_test_init}, - {"fuvc_printf_buff", "fuvc_printf_buff", cli_fuvc_printf_test_buff}, - {"uvc_ctrl_get", "uvc ctrl get attribute information", uvc_get_param}, - {"uvc_ctrl_set", "uvc ctrl set attribute param", uvc_set_param}, - {"uvc_stream", "uvc ctrl set attribute param", uvc_start_stream}, -#endif -#if CONFIG_USB_PLUG_IN_OUT - {"usb_plug", "usb plug init|out", cli_usb_plug_init}, - {"usb_plug_inout", "usb open|close", cli_usb_plug_inout}, -#endif - {"usb", "usb open_host|open_dev|close", cli_usb_open_close}, -}; - -void usb_cli_init(void) -{ - int ret; - ret = cli_register_commands(usb_host_clis, sizeof(usb_host_clis) / sizeof(struct cli_command)); - if (ret) - CLI_LOGI("register usb host commands fail.\r\n"); -} -#endif diff --git a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_uvc.c b/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_uvc.c deleted file mode 100755 index 39fcca0951ed96ea6a709845195924e9aad874b5..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_uvc.c +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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 -#include "cli.h" - -#if (!CONFIG_USB_UVC && !CONFIG_SLAVE_CORE) -extern void uvc_process_cpu0(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv); -#endif - -#if (CONFIG_USB_UVC && CONFIG_SLAVE_CORE) -extern void uvc_process_cpu1(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv); -#endif - -#define UVC_CMD_CNT (sizeof(s_uvc_commands) / sizeof(struct cli_command)) -static const struct cli_command s_uvc_commands[] = { - -#if (!CONFIG_USB_UVC && !CONFIG_SLAVE_CORE) - {"uvc", "uvc {}", uvc_process_cpu0}, -#endif - -#if (CONFIG_USB_UVC && CONFIG_SLAVE_CORE) - {"uvc", "cpu1 uvc {}", uvc_process_cpu1}, -#endif -}; - -int cli_uvc_init(void) -{ - return cli_register_commands(s_uvc_commands, UVC_CMD_CNT); -} - diff --git a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_wdt.c b/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_wdt.c deleted file mode 100644 index da35e2b564cb58ceaa2b0baa0d9f93d6b4d1c323..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_wdt.c +++ /dev/null @@ -1,100 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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 -#include "cli.h" -#include -#include - -static void cli_wdt_help(void) -{ - CLI_LOGI("wdt_driver init\n"); - CLI_LOGI("wdt_driver deinit\n"); - CLI_LOGI("wdt start [timeout]\n"); - CLI_LOGI("wdt stop\n"); - CLI_LOGI("wdt feed\n"); -} - -static void cli_wdt_driver_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - if (argc < 2) { - cli_wdt_help(); - return; - } - - if (os_strcmp(argv[1], "init") == 0) { - BK_LOG_ON_ERR(bk_wdt_driver_init()); - CLI_LOGI("wdt driver init\n"); - } else if (os_strcmp(argv[1], "deinit") == 0) { - BK_LOG_ON_ERR(bk_wdt_driver_deinit()); - CLI_LOGI("wdt driver deinit\n"); - } else { - cli_wdt_help(); - return; - } -} - -static void cli_wdt_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - if (argc < 2) { - cli_wdt_help(); - return; - } - - if (os_strcmp(argv[1], "start") == 0) { - uint32_t timeout = os_strtoul(argv[2], NULL, 10); - BK_LOG_ON_ERR(bk_wdt_start(timeout)); - CLI_LOGI("wdt start, timeout=%d\n", timeout); - } else if (os_strcmp(argv[1], "stop") == 0) { - BK_LOG_ON_ERR(bk_wdt_stop()); - CLI_LOGI("wdt stop\n"); - }else if (os_strcmp(argv[1], "feed") == 0) { - BK_LOG_ON_ERR(bk_wdt_feed()); - CLI_LOGI("wdt feed\n"); - }else if (os_strcmp(argv[1], "disable") == 0) { - extern void wdt_debug_disable(void); - wdt_debug_disable(); - bk_wdt_stop(); - bk_task_wdt_stop(); - CLI_LOGI("wdt debug disabled\n"); - }else if (os_strcmp(argv[1], "enable") == 0) { - extern void wdt_debug_enable(void); - extern void wdt_init(void); - wdt_debug_enable(); - wdt_init(); - CLI_LOGI("wdt debug enabled\n"); - }else if (os_strcmp(argv[1], "while") == 0) { - GLOBAL_INT_DECLARATION(); - GLOBAL_INT_DISABLE(); - CLI_LOGI("wdt enter while1\n"); - while(1); - GLOBAL_INT_RESTORE(); - } else { - cli_wdt_help(); - return; - } -} - -#define WDT_CMD_CNT (sizeof(s_wdt_commands) / sizeof(struct cli_command)) -static const struct cli_command s_wdt_commands[] = { - {"wdt_driver", "{init|deinit}", cli_wdt_driver_cmd}, - {"wdt", "wdt {start|stop|feed} [...]", cli_wdt_cmd} -}; - -int cli_wdt_init(void) -{ - BK_LOG_ON_ERR(bk_wdt_driver_init()); - return cli_register_commands(s_wdt_commands, WDT_CMD_CNT); -} - diff --git a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_wifi.c b/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_wifi.c deleted file mode 100644 index 76d6c3940ee84d56c537a9c8a5165ad8068d6584..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/cli_wifi.c +++ /dev/null @@ -1,1135 +0,0 @@ -#include -#include -#include "bk_uart.h" -#include "param_config.h" -#include "bk_private/bk_wifi_wrapper.h" -#if CONFIG_LWIP -#include "net.h" -#endif -#include "bk_private/bk_wifi.h" -#include "bk_wifi_private.h" -#include "bk_cli.h" -#include "cli.h" -#include -#include -#include "bk_wifi_wpa.h" -#include "bk_wifi_wpa_cmd.h" -#include "bk_wifi_frame.h" -#include "bk_wifi_types.h" -#if CONFIG_WIFI6_CODE_STACK -#include "bk_wifi_netif.h" -#include "bk_wifi.h" -#endif -#include "bk_wifi_rw.h" - -#if CONFIG_ENABLE_WIFI_DEFAULT_CONNECT -#include "driver/flash.h" -#include -#include -#include "bk_wifi_private.h" -#include "boot.h" -#endif - -#define TAG "wifi_cli" -#define CMD_WLAN_MAX_BSS_CNT 50 - -#if (CLI_CFG_WIFI == 1) -#if CONFIG_ENABLE_WIFI_DEFAULT_CONNECT -typedef struct bk_fast_connect_t -{ - uint8_t flag; //to check if ssid/pwd saved in easy flash is valid, default 0x70 - //bit[0]:write sta deault info;bit[1]:write ap deault info - uint8_t sta_ssid[33]; - uint8_t sta_pwd[65]; - uint8_t ap_ssid[33]; - uint8_t ap_pwd[65]; - uint8_t ap_channel; -}BK_FAST_CONNECT_T; - -int wifi_cli_find_id(int argc, char **argv, char *param) -{ - int i; - int index; - - index = -1; - if (NULL == param) - goto find_over; - - for (i = 1; i < argc; i ++) { - if (os_strcmp(argv[i], param) == 0) { - index = i; - break; - } - } - -find_over: - return index; -} - -static BK_FAST_CONNECT_T info_t; -static int fast_connect_cb(void *arg, event_module_t event_module, - int event_id, void *event_data) -{ - bk_logic_partition_t *pt = bk_flash_partition_get_info(BK_PARTITION_USR_CONFIG); - BK_FAST_CONNECT_T info_tmp; - - CLI_LOGI("%s, flag:%x\r\n", __func__, info_t.flag); - bk_flash_read_bytes(pt->partition_start_addr + pt->partition_length -4096, - (uint8_t *)&info_tmp, sizeof(BK_FAST_CONNECT_T)); - - if (info_t.flag == 0x71l) { - if ((info_tmp.flag & 0xf8l) == 0x70l) - info_tmp.flag |= 0x1l; - else - info_tmp.flag = 0x71l; - os_strcpy((char *)info_tmp.sta_ssid, (char *)info_t.sta_ssid); - os_strcpy((char *)info_tmp.sta_pwd, (char *)info_t.sta_pwd); - } else if (info_t.flag == 0x72l) { - if ((info_tmp.flag & 0xf8l) == 0x70l) - info_tmp.flag |= 0x2l; - else - info_tmp.flag = 0x72l; - os_strcpy((char *)info_tmp.ap_ssid, (char *)info_t.ap_ssid); - os_strcpy((char *)info_tmp.ap_pwd, (char *)info_t.ap_pwd); - } else - return -1; - - bk_flash_set_protect_type(FLASH_PROTECT_NONE); - bk_flash_erase_sector(pt->partition_start_addr + pt->partition_length -4096); - bk_flash_write_bytes(pt->partition_start_addr + pt->partition_length -4096, - (uint8_t *)&info_tmp, sizeof(BK_FAST_CONNECT_T)); - bk_flash_set_protect_type(FLASH_UNPROTECT_LAST_BLOCK); - - return 0; -} - -#if 0 -static int demo_tcp_send(void *arg, event_module_t event_module, - int event_id, void *event_data) -{ - struct sockaddr_in addr; - int flag = 1, sock, ret = -1, len = 40*1024; - struct timeval tv; - uint8_t *send_buf; - - send_buf = (uint8_t *) os_malloc(len); - for (int i = 0; i < len; i++) - send_buf[i] = i & 0xff; - - sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); - if (sock < 0) { - CLI_LOGI("create socket failed, err=%d!\n", errno); - return -1; - } - addr.sin_family = PF_INET; - addr.sin_port = htons(5001); - addr.sin_addr.s_addr = inet_addr((char *)"192.168.1.102"); - - ret = connect(sock, (const struct sockaddr *)&addr, sizeof(addr)); - if (ret == -1) { - CLI_LOGI("connect failed, err=%d!\n", errno); - closesocket(sock); - return -1; - } - - setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, - (void *)&flag, sizeof(int)); - - tv.tv_sec = 3; - tv.tv_usec = 0; - setsockopt(sock, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv)); - - tv.tv_sec = 3; - tv.tv_usec = 0; - setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)); - - ret = send(sock, send_buf, len, 0); - - closesocket(sock); - - return 0; -} -#endif - -void demo_wifi_fast_connect(void) -{ - bk_logic_partition_t *pt = bk_flash_partition_get_info(BK_PARTITION_USR_CONFIG); - BK_FAST_CONNECT_T info; - - bk_flash_read_bytes(pt->partition_start_addr + pt->partition_length -4096, - (uint8_t *)&info, sizeof(BK_FAST_CONNECT_T)); - CLI_LOGD("%s, flag:%x\r\n", __func__, info.flag); - if (info.flag == 0x71l) { - demo_sta_app_init((char *)info.sta_ssid, (char *)info.sta_pwd); -#if 0 - bk_event_register_cb(EVENT_MOD_NETIF, EVENT_NETIF_GOT_IP4, - demo_tcp_send, &info_t); -#endif - } else if (info.flag == 0x72l) { - demo_softap_app_init((char *)info.ap_ssid, (char *)info.ap_pwd, NULL); - } else if (info.flag == 0x73l) { - demo_sta_app_init((char *)info.sta_ssid, (char *)info.sta_pwd); - demo_softap_app_init((char *)info.ap_ssid, (char *)info.ap_pwd, NULL); - } -} -#endif - -void cli_wifi_scan_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - if (argc < 2) { - demo_scan_app_init(); - return; - } else { - uint8_t *ap_ssid; - - ap_ssid = (uint8_t *)argv[1]; - demo_scan_adv_app_init(ap_ssid); - } -} - -void cli_wifi_ap_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - char *ap_ssid = NULL; - char *ap_key = ""; - char *ap_channel = NULL; - -#if CONFIG_ENABLE_WIFI_DEFAULT_CONNECT - if (wifi_cli_find_id(argc, argv, "-w") > 0 || - wifi_cli_find_id(argc, argv, "-e") > 0) { - if (argc == 3) - ap_ssid = argv[2]; - else if (argc == 4) { - ap_ssid = argv[2]; - if (os_strlen(argv[3]) <= 2) - ap_channel = argv[3]; - else - ap_key = argv[3]; - } else if (argc == 5) { - ap_ssid = argv[2]; - ap_key = argv[3]; - ap_channel = argv[4]; - } - } else { -#endif - if (argc == 2) - ap_ssid = argv[1]; - else if (argc == 3) { - ap_ssid = argv[1]; - if (os_strlen(argv[2]) <= 2) - ap_channel = argv[2]; - else - ap_key = argv[2]; - } else if (argc == 4) { - ap_ssid = argv[1]; - ap_key = argv[2]; - ap_channel = argv[3]; - } -#if CONFIG_ENABLE_WIFI_DEFAULT_CONNECT - } -#endif - - if (ap_ssid) { - demo_softap_app_init(ap_ssid, ap_key, ap_channel); -#if CONFIG_ENABLE_WIFI_DEFAULT_CONNECT - bk_event_unregister_cb(EVENT_MOD_WIFI, EVENT_WIFI_STA_CONNECTED, - fast_connect_cb); - if (wifi_cli_find_id(argc, argv, "-w") > 0) { - bk_logic_partition_t *pt = bk_flash_partition_get_info(BK_PARTITION_USR_CONFIG); - - bk_flash_read_bytes(pt->partition_start_addr + pt->partition_length -4096, - (uint8_t *)&info_t, sizeof(BK_FAST_CONNECT_T)); - if ((info_t.flag & 0xf0l) == 0x70l) - info_t.flag |= 0x2l; - else - info_t.flag = 0x72l; - os_strcpy((char *)info_t.ap_ssid, (char *)ap_ssid); - os_strcpy((char *)info_t.ap_pwd, ap_key); - fast_connect_cb(NULL, 0, 0, NULL); - } else if (wifi_cli_find_id(argc, argv, "-e") > 0) { - bk_logic_partition_t *pt = bk_flash_partition_get_info(BK_PARTITION_USR_CONFIG); - - bk_flash_read_bytes(pt->partition_start_addr + pt->partition_length -4096, - (uint8_t *)&info_t, sizeof(BK_FAST_CONNECT_T)); - if (info_t.flag == 0x72l || info_t.flag == 0x73l) { - info_t.flag &= ~0x2l; - bk_flash_set_protect_type(FLASH_PROTECT_NONE); - bk_flash_erase_sector(pt->partition_start_addr + pt->partition_length -4096); - bk_flash_write_bytes(pt->partition_start_addr + pt->partition_length -4096, - (uint8_t *)&info_t, sizeof(BK_FAST_CONNECT_T)); - bk_flash_set_protect_type(FLASH_UNPROTECT_LAST_BLOCK); - } - } -#endif - } -} - -void cli_wifi_stop_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - if (argc == 2) { - if (os_strcmp(argv[1], "sta") == 0) { -#if CONFIG_ENABLE_WIFI_DEFAULT_CONNECT - bk_event_unregister_cb(EVENT_MOD_WIFI, EVENT_WIFI_STA_CONNECTED, - fast_connect_cb); -#endif - BK_LOG_ON_ERR(bk_wifi_sta_stop()); - } else if (os_strcmp(argv[1], "ap") == 0) - BK_LOG_ON_ERR(bk_wifi_ap_stop()); - else - CLI_LOGI("unknown WiFi interface\n"); - } else - CLI_LOGI("bad parameters\r\n"); -} - -void cli_wifi_iplog_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - char *iplog_mode = NULL; - - if (argc == 2) - iplog_mode = argv[1]; - - if (iplog_mode) - demo_wifi_iplog_init(iplog_mode); -} -void cli_wifi_ipdbg_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - char *ipdbg_module = NULL; - char *ipdbg_para = NULL; - char *ipdbg_para_value = NULL; - - if (argc == 3) - { - ipdbg_module = argv[1]; - ipdbg_para = argv[2]; - if (ipdbg_module && ipdbg_para) - demo_wifi_ipdbg_init(ipdbg_module, ipdbg_para, ipdbg_para_value); - else - CLI_LOGI("cli_wifi_ipdbg_cmd:invalid argc param\r\n"); - } - else if(argc == 4) - { - ipdbg_module = argv[1]; - ipdbg_para = argv[2]; - ipdbg_para_value = argv[3]; - if (ipdbg_module && ipdbg_para && ipdbg_para_value) - demo_wifi_ipdbg_init(ipdbg_module, ipdbg_para, ipdbg_para_value); - else - CLI_LOGI("cli_wifi_ipdbg_cmd:invalid argc param\r\n"); - } - else - { - CLI_LOGI("cli_wifi_ipdbg_cmd:invalid argc num\r\n"); - return; - } -} - -typedef struct { - uint8_t channel; - uint32_t rx_cnt_mgmt; - uint32_t rx_cnt_data; - uint32_t rx_cnt_ctrl; - uint32_t rx_cnt_0_255; - uint32_t rx_cnt_256_511; - uint32_t rx_cnt_512_1023; - uint32_t rx_cnt_1024; - uint32_t rx_cnt_total; -} cli_monitor_result_t; -static cli_monitor_result_t *s_monitor_result = NULL; - -bk_err_t cli_monitor_cb(const uint8_t *data, uint32_t len, const wifi_frame_info_t *info) -{ - if (s_monitor_result) { - s_monitor_result->rx_cnt_total++; - - if (data) { - if ((data[0] & 0xc) == 0x8) - s_monitor_result->rx_cnt_data ++; - else if ((data[0] & 0xc) == 0x0) - s_monitor_result->rx_cnt_mgmt ++; - else - s_monitor_result->rx_cnt_ctrl ++; - } - - if (len < 256) - s_monitor_result->rx_cnt_0_255++; - else if (len < 512) - s_monitor_result->rx_cnt_256_511++; - else if (len < 1024) - s_monitor_result->rx_cnt_512_1023++; - else - s_monitor_result->rx_cnt_1024++; - } - - return BK_OK; -} - -void cli_monitor_show(void) -{ - if (s_monitor_result) { - BK_LOG_RAW("total: %u\n", s_monitor_result->rx_cnt_total); - BK_LOG_RAW("mgmt: %u\n", s_monitor_result->rx_cnt_mgmt); - BK_LOG_RAW("data: %u\n", s_monitor_result->rx_cnt_data); - BK_LOG_RAW("ctrl: %u\n", s_monitor_result->rx_cnt_ctrl); - BK_LOG_RAW("0 - 255: %u\n", s_monitor_result->rx_cnt_0_255); - BK_LOG_RAW("256 - 511: %u\n", s_monitor_result->rx_cnt_256_511); - BK_LOG_RAW("512 - 1023: %u\n", s_monitor_result->rx_cnt_512_1023); - BK_LOG_RAW(">=1024: %u\n", s_monitor_result->rx_cnt_1024); - } -} - -void cli_wifi_set_interval_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - uint8_t interval = 0; - int ret = 0; - - if (argc < 2) { - CLI_LOGI("invalid argc num"); - return; - } - - interval = (uint8_t)os_strtoul(argv[1], NULL, 10); - ret = bk_wifi_send_listen_interval_req(interval); - - if (!ret) - CLI_LOGI("set_interval ok"); - else - CLI_LOGI("set_interval failed"); -} - -void cli_monitor_stop(void) -{ - if (s_monitor_result) { - os_free(s_monitor_result); - s_monitor_result = NULL; - } - - BK_LOG_ON_ERR(bk_wifi_monitor_stop()); -} - -void cli_monitor_start(uint32_t primary_channel) -{ - wifi_channel_t chan = {0}; - - chan.primary = primary_channel; - - if (!s_monitor_result) { - s_monitor_result = os_zalloc(sizeof(cli_monitor_result_t)); - if (!s_monitor_result) - CLI_LOGI("failed to alloc monitor result\n"); - } - - BK_LOG_ON_ERR(bk_wifi_monitor_register_cb(cli_monitor_cb)); - BK_LOG_ON_ERR(bk_wifi_monitor_start()); - BK_LOG_ON_ERR(bk_wifi_monitor_set_channel(&chan)); -} - -void cli_wifi_monitor_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - uint32_t primary_channel; - - if (argc != 2) { - CLI_LOGI("monitor_parameter invalid\r\n"); - return; - } - - primary_channel = os_strtoul(argv[1], NULL, 10); - if (99 == primary_channel) - cli_monitor_stop(); - else if ((primary_channel > 0) && (primary_channel < 15)) - cli_monitor_start(primary_channel); - else - cli_monitor_show(); -} - -#include "conv_utf8_pub.h" -void cli_wifi_sta_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - char *ssid = NULL; - char *password = ""; - - if ((argc < 2) || (argc > 6)) { - CLI_LOGI("invalid argc number\n"); - return; - } - -#if CONFIG_ENABLE_WIFI_DEFAULT_CONNECT - if (wifi_cli_find_id(argc, argv, "-w") > 0 || - wifi_cli_find_id(argc, argv, "-e") > 0) { - if (argc >= 2) - ssid = argv[2]; - - if (argc >= 3) - password = argv[3]; - } else { -#endif - if (argc >= 2) - ssid = argv[1]; - - if (argc >= 3) - password = argv[2]; -#if CONFIG_ENABLE_WIFI_DEFAULT_CONNECT - } -#endif - -#if 0 //TODO support BSSID/Channel configuration - if (argc >= 4) - bssid = argv[3]; - - if (argc >= 5) - channel = argv[4]; -#endif - - char *oob_ssid_tp = ssid; -#if CONFIG_USE_CONV_UTF8 - oob_ssid_tp = (char *)conv_utf8((uint8_t *)ssid); -#endif - - if (oob_ssid_tp) { - demo_sta_app_init((char *)oob_ssid_tp, password); -#if CONFIG_ENABLE_WIFI_DEFAULT_CONNECT - if (wifi_cli_find_id(argc, argv, "-w") > 0) { - bk_logic_partition_t *pt = bk_flash_partition_get_info(BK_PARTITION_USR_CONFIG); - bk_flash_read_bytes(pt->partition_start_addr + pt->partition_length -4096, - (uint8_t *)&info_t, sizeof(BK_FAST_CONNECT_T)); - if ((info_t.flag & 0xf0l) == 0x70l) - info_t.flag |= 0x1l; - else - info_t.flag = 0x71l; - os_strcpy((char *)info_t.sta_ssid, (char *)oob_ssid_tp); - os_strcpy((char *)info_t.sta_pwd, password); - bk_event_register_cb(EVENT_MOD_WIFI, EVENT_WIFI_STA_CONNECTED, - fast_connect_cb, &info_t); - } else if (wifi_cli_find_id(argc, argv, "-e") > 0) { - bk_logic_partition_t *pt = bk_flash_partition_get_info(BK_PARTITION_USR_CONFIG); - - bk_flash_read_bytes(pt->partition_start_addr + pt->partition_length -4096, - (uint8_t *)&info_t, sizeof(BK_FAST_CONNECT_T)); - if (info_t.flag == 0x71l || info_t.flag == 0x73l) { - info_t.flag &= ~0x1l; - bk_flash_set_protect_type(FLASH_PROTECT_NONE); - bk_flash_write_bytes(pt->partition_start_addr + pt->partition_length -4096, - (uint8_t *)&info_t, sizeof(BK_FAST_CONNECT_T)); - bk_flash_set_protect_type(FLASH_UNPROTECT_LAST_BLOCK); - } - } -#endif -#if CONFIG_USE_CONV_UTF8 - os_free(oob_ssid_tp); -#endif - } else { - CLI_LOGI("not buf for utf8\r\n"); - } -} - -#if CONFIG_COMPONENTS_WPA2_ENTERPRISE -/** - * cli command: sta_eap , connect to EAP-TLS AP. - * - * restrictions: EAP-TLS is based on PKI, both AP and STA may have certificate. So - * we must install certificate and private key to system. For example, `beken-iot-1.pem' - * is STA's certificate, `beken-iot-1.key' is private key, `rootca.pem' is the RootCA. - * These certificates and private key may be registered to system via `register_xfile' - * function. - */ -void cli_wifi_sta_eap_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - char *ssid = NULL; - char *ca = "cacert.pem"; - char *client_cert = "beken-iot-1.pem"; - char *private_key = "beken-iot-1.key"; - char *private_key_passwd = "12345678"; - char *identity = "user"; - - if ((argc < 2) || (argc > 5)) { - CLI_LOGI("invalid argc number\n"); - return; - } - - ssid = argv[1]; - - char *oob_ssid_tp = ssid; -#if CONFIG_USE_CONV_UTF8 - oob_ssid_tp = (char *)conv_utf8((uint8_t *)ssid); -#endif - - if (oob_ssid_tp) { - int len; - wifi_sta_config_t *sta_config; - - len = os_strlen((char *)oob_ssid_tp); - if (WLAN_SSID_MAX_LEN < len) { - CLI_LOGI("ssid name more than 32 Bytes\n"); - return; - } - - sta_config = os_zalloc(sizeof(*sta_config)); - if (!sta_config) { - CLI_LOGI("Cannot alloc STA config\n"); - return; - } - - os_strlcpy(sta_config->ssid, oob_ssid_tp, sizeof(sta_config->ssid)); - sta_config->password[0] = '\0'; // No passwd needed fo EAP. - os_strlcpy(sta_config->eap, "TLS", sizeof(sta_config->eap)); - os_strlcpy(sta_config->identity, identity, sizeof(sta_config->identity)); - os_strlcpy(sta_config->ca, ca, sizeof(sta_config->ca)); - os_strlcpy(sta_config->client_cert, client_cert, sizeof(sta_config->client_cert)); - os_strlcpy(sta_config->private_key, private_key, sizeof(sta_config->private_key)); - os_strlcpy(sta_config->private_key_passwd, private_key_passwd, sizeof(sta_config->private_key_passwd)); - os_strlcpy(sta_config->phase1, "tls_disable_time_checks=1", sizeof(sta_config->phase1)); - - CLI_LOGI("ssid:%s key:%s\n", sta_config->ssid, sta_config->password); - CLI_LOGI("eap:%s identity:%s\n", sta_config->eap, sta_config->identity); - CLI_LOGI("ca:%s client_cert:%s\n", sta_config->ca, sta_config->client_cert); - CLI_LOGI("private_key:%s\n", sta_config->private_key); - BK_LOG_ON_ERR(bk_wifi_sta_set_config(sta_config)); - BK_LOG_ON_ERR(bk_wifi_sta_start()); - - os_free(sta_config); - -#if CONFIG_USE_CONV_UTF8 - os_free(oob_ssid_tp); -#endif - } else { - CLI_LOGI("not buf for utf8\r\n"); - } -} -#endif - -void cli_wifi_state_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - demo_state_app_init(); -} - -#if CONFIG_WIFI_SENSOR -static void cli_wifi_sensor_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - int status; - - if (argc != 2) - bk_printf("param error"); - - - if (os_strcmp(argv[1], "start") == 0) - bk_wifi_detect_movement_start(); - - if (os_strcmp(argv[1], "stop") == 0) - bk_wifi_detect_movement_stop(); - - if (os_strcmp(argv[1], "status") == 0) { - status = bk_get_movement_status(); - - if (status == 0) - bk_printf("detect something"); - else - bk_printf("detect nothing"); - } -} -#endif - -#if CONFIG_COMPONENTS_WFA_CA -extern void wfa_ca_start(); -extern void wfa_ca_stop(); - -void cli_wifi_wfa_ca_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - if (argc != 2) { - os_printf("param error"); - return; - } - - if (os_strcmp(argv[1], "start") == 0) - wfa_ca_start(); - else if (os_strcmp(argv[1], "stop") == 0) - wfa_ca_stop(); -} -#endif - -typedef struct { - uint16_t cnt_probe_req; - uint16_t cnt_probe_rsp; - uint16_t cnt_beacon; - uint16_t cnt_action; - uint16_t cnt_auth; - uint16_t cnt_assoc_req; - uint16_t cnt_assoc_rsp; - uint16_t cnt_others; - uint16_t cnt_total; -} wifi_filter_result_t; - -static wifi_filter_result_t *s_filter_result = NULL; - -static int wifi_filter_cb(const uint8_t *data, uint32_t len, const wifi_frame_info_t *frame_info) -{ - if (!data) { - CLI_LOGE("null data\n"); - return BK_OK; - } - - if (!s_filter_result) - return BK_OK; - - uint16_t framectrl = *(uint16_t*)(data); - uint16_t type_subtype = framectrl & MAC_FCTRL_TYPESUBTYPE_MASK; - - if (type_subtype == MAC_FCTRL_BEACON) - s_filter_result->cnt_beacon ++; - else if (type_subtype == MAC_FCTRL_PROBEREQ) - s_filter_result->cnt_probe_req++; - else if (type_subtype == MAC_FCTRL_PROBERSP) - s_filter_result->cnt_probe_rsp++; - else if (type_subtype == MAC_FCTRL_ACTION) - s_filter_result->cnt_action++; - else if (type_subtype == MAC_FCTRL_AUTHENT) - s_filter_result->cnt_auth++; - else if (type_subtype == MAC_FCTRL_ASSOCREQ) - s_filter_result->cnt_assoc_req++; - else if (type_subtype == MAC_FCTRL_ASSOCRSP) - s_filter_result->cnt_assoc_rsp++; - else - s_filter_result->cnt_others++; - - s_filter_result->cnt_total++; - return BK_OK; -} - -static void wifi_filter_result_dump(void) -{ - if (!s_filter_result) - return; - - bk_printf("filter result:\n"); - bk_printf("total: %u\n", s_filter_result->cnt_total); - bk_printf("beacon: %u\n", s_filter_result->cnt_beacon); - bk_printf("probe req: %u\n", s_filter_result->cnt_probe_req); - bk_printf("probe rsp: %u\n", s_filter_result->cnt_probe_rsp); - bk_printf("auth: %u\n", s_filter_result->cnt_auth); - bk_printf("assoc req: %u\n", s_filter_result->cnt_assoc_req); - bk_printf("assoc rsp: %u\n", s_filter_result->cnt_assoc_rsp); - bk_printf("action: %u\n", s_filter_result->cnt_action); - bk_printf("others: %u\n", s_filter_result->cnt_others); -} - -static void wifi_mgmt_filter_help(void) -{ - bk_printf("filter {filter_bitmap}\n"); - bk_printf(" bit0 - default management\n"); - bk_printf(" bit1 - probe req\n"); - bk_printf(" bit2 - probe rsp\n"); - bk_printf(" bit3 - all beacon\n"); - bk_printf(" bit4 - action\n"); - bk_printf(" 0 - stop filter\n"); - bk_printf(" -1 - display result\n"); -} - -static void cli_wifi_filter_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - wifi_filter_config_t filter_config = {0}; - uint32_t filter = 0; - - if (argc != 2) { - wifi_mgmt_filter_help(); - return; - } - - filter = os_strtoul(argv[1], NULL, 0); - - if (filter == 0) { - if (s_filter_result) { - os_free(s_filter_result); - s_filter_result = NULL; - } - BK_LOG_ON_ERR(bk_wifi_filter_set_config(&filter_config)); - BK_LOG_ON_ERR(bk_wifi_filter_register_cb(NULL)); - return; - } else if (filter == -1) { - wifi_filter_result_dump(); - return; - } - - if (!s_filter_result) { - s_filter_result = (wifi_filter_result_t *)os_zalloc(sizeof(wifi_filter_result_t)); - if (!s_filter_result) - return; - } - - if (filter & (1 << 0)) - filter_config.rx_all_default_mgmt = 1; - - if (filter & (1 << 1)) - filter_config.rx_probe_req = 1; - - if (filter & (1 << 2)) - filter_config.rx_probe_rsp = 1; - - if (filter & (1 << 3)) - filter_config.rx_all_beacon = 1; - - if (filter & (1 << 4)) - filter_config.rx_action = 1; - - BK_LOG_ON_ERR(bk_wifi_filter_set_config(&filter_config)); - BK_LOG_ON_ERR(bk_wifi_filter_register_cb(wifi_filter_cb)); -} - -#if CONFIG_WIFI_RAW_TX_TEST - -typedef struct { - uint32_t interval; - uint32_t counter; -} wifi_raw_tx_param_t; - -static void wifi_raw_tx_thread(void *arg) -{ - char frame[] = { - 0xB0, //version, type, subtype - 0x00, //frame control - 0x3A, 0x01, //duration - 0xC8, 0x47, 0x8C, 0x42, 0x00, 0x48, //Address1 - destination - 0x4C, 0xD1, 0xA1, 0xC5, 0x38, 0xE4, //Address2 - source - 0x4C, 0xD1, 0xA1, 0xC5, 0x38, 0xE4, //Address3 - bssid - 0x20, 0xC0, //sequence - - //Auth Response - 0x00, 0x00, //Auth algorithm - open system - 0x02, 0x00, //Auth seq num - 0x00, 0x00, //Status code - }; - wifi_raw_tx_param_t *tx_param; - int ret; - - tx_param = (wifi_raw_tx_param_t *)arg; - CLI_LOGI("wifi raw tx begin, interval=%u counter=%d\n", tx_param->interval, - tx_param->counter); - - for (uint32_t i = 0; i < tx_param->counter; i++) { - ret = bk_wlan_send_80211_raw_frame((unsigned char *)frame, sizeof(frame)); - if (ret != kNoErr) - CLI_LOGI("raw tx error, ret=%d\n", ret); - - rtos_delay_milliseconds(tx_param->interval); - } - - os_free(arg); - CLI_LOGI("wifi raw tx end\n"); - rtos_delete_thread(NULL); -} - -static void cli_wifi_raw_tx_cmd(char *pcWriteBuffer, int xWriteBufferLen, - int argc, char **argv) -{ - bk_err_t ret; - - if (argc != 3) { - CLI_LOGE("param error"); - CLI_LOGI("usage: wifi_raw_tx interval counter"); - return; - } - - wifi_raw_tx_param_t *tx_param; - tx_param = (wifi_raw_tx_param_t *)os_malloc(sizeof(wifi_raw_tx_param_t)); - if (!tx_param) { - CLI_LOGE("out of memory\n"); - return; - } - - tx_param->interval = os_strtoul(argv[1], NULL, 10); - tx_param->counter = os_strtoul(argv[2], NULL, 10); - ret = rtos_create_thread(NULL, 2, "raw_tx", - (beken_thread_function_t)wifi_raw_tx_thread, - 2048, tx_param); - if (kNoErr != ret) { - os_free(tx_param); - CLI_LOGI("Create raw tx thread failed, ret=%d\r\n", ret); - return; - } -} -#endif - -static void cli_wifi_monitor_channel_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - wifi_channel_t chan = {0}; - int channel, i = 0; - - if (argc == 1) { - CLI_LOGI("Usage: channel [1~13]."); - return; - } - - while (argv[1][i]) { - if ((argv[1][i] < '0') || (argv[1][i] > '9')) { - CLI_LOGE("parameter should be a number\r\n"); - return ; - } - i++; - } - - channel = atoi(argv[1]); - - if ((channel < 1) || (channel > 13)) { - CLI_LOGE("Invalid channel number \r\n"); - return ; - } - BK_LOG_RAW("monitor mode, set to channel %d\r\n", channel); - chan.primary = channel; - BK_LOG_ON_ERR(bk_wifi_monitor_set_channel(&chan)); -} - -int cli_netif_event_cb(void *arg, event_module_t event_module, - int event_id, void *event_data) -{ - netif_event_got_ip4_t *got_ip; - - switch (event_id) { - case EVENT_NETIF_GOT_IP4: - got_ip = (netif_event_got_ip4_t *)event_data; - CLI_LOGI("%s got ip\n", got_ip->netif_if == NETIF_IF_STA ? "BK STA" : "unknown netif"); -#if CONFIG_WIFI6_CODE_STACK - unsigned char vif_idx = wifi_netif_mac_to_vifid((uint8_t*)&g_sta_param_ptr->own_mac); - wlan_dhcp_done_ind(vif_idx); -#endif - break; - default: - CLI_LOGI("rx event <%d %d>\n", event_module, event_id); - break; - } - - return BK_OK; -} - -int cli_wifi_event_cb(void *arg, event_module_t event_module, - int event_id, void *event_data) -{ - wifi_event_sta_disconnected_t *sta_disconnected; - wifi_event_sta_connected_t *sta_connected; - wifi_event_ap_disconnected_t *ap_disconnected; - wifi_event_ap_connected_t *ap_connected; - - switch (event_id) { - case EVENT_WIFI_STA_CONNECTED: - sta_connected = (wifi_event_sta_connected_t *)event_data; - CLI_LOGI("BK STA connected %s\n", sta_connected->ssid); - break; - - case EVENT_WIFI_STA_DISCONNECTED: - sta_disconnected = (wifi_event_sta_disconnected_t *)event_data; - CLI_LOGI("BK STA disconnected, reason(%d)%s\n", sta_disconnected->disconnect_reason, - sta_disconnected->local_generated ? ", local_generated" : ""); - break; - - case EVENT_WIFI_AP_CONNECTED: - ap_connected = (wifi_event_ap_connected_t *)event_data; - CLI_LOGI(BK_MAC_FORMAT" connected to BK AP\n", BK_MAC_STR(ap_connected->mac)); - break; - - case EVENT_WIFI_AP_DISCONNECTED: - ap_disconnected = (wifi_event_ap_disconnected_t *)event_data; - CLI_LOGI(BK_MAC_FORMAT" disconnected from BK AP\n", BK_MAC_STR(ap_disconnected->mac)); - break; - - default: - CLI_LOGI("rx event <%d %d>\n", event_module, event_id); - break; - } - - return BK_OK; -} - -void cli_wifi_net_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - char buf[128]; - int i, left = sizeof(buf) - 1, len = 0; - - // net sta xxx - // net ap xxx - if (argc <= 2) { - CLI_LOGI("Usage: net sta/ap \n"); - return; - } - - buf[0] = 0; - for (i = 2; i < argc; i++) { - len = os_strlen(buf); - snprintf(buf + len, left - len, "%s ", argv[i]); - } - buf[strlen(buf) - 1] = 0; - //CLI_LOGI("CMD: |%s|\n", buf); - -#if 1 - if (os_strcmp(argv[1], "sta") == 0) - cmd_wlan_sta_exec(buf); - else if (os_strcmp(argv[1], "ap") == 0) - cmd_wlan_ap_exec(buf); -#if CONFIG_COMPONENTS_P2P - else if (os_strcmp(argv[1], "p2p") == 0) - cmd_wlan_p2p_exec(buf); -#endif - else { - CLI_LOGI("Usage: net sta/ap \n"); - return; - } -#endif -} - -void cli_wifi_get_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) { - // get pm status - // get xx status - if (argc <= 2) { - CLI_LOGI("Usage get xx status\n"); - return; - } - - if(os_strcmp(argv[1], "ps") == 0) { - int state = 0; - if(os_strcmp(argv[2], "status") == 0) { - state = cmd_wlan_get_ps_status(); - CLI_LOGI("ps status: %s \n", (state?"sleep":"active")); - } else { - CLI_LOGI("Usage get ps status\n"); - } - } - else if (os_strcmp(argv[1], "mac_trx") == 0) { - - bool reset_status = false; - - if ((argc == 4) && (os_strcmp(argv[3], "-r") == 0)) - { - reset_status = true; - } - - if(os_strcmp(argv[2], "status") == 0) { - bk_wifi_get_mac_trx_status(reset_status); - } else { - CLI_LOGI("Usage get MAC TRX status\n"); - } - } -} -void cli_wifi_rc_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) { - - uint8_t sta_idx = 0; - uint16_t rate_cfg = 0; - - if (argc <= 2) { - CLI_LOGI("invalid RC command\n"); - return; - } - - if(os_strcmp(argv[1], "set_fixrate") == 0) { - sta_idx = os_strtoul(argv[2], NULL, 10) & 0xFFFF; - rate_cfg = os_strtoul(argv[3], NULL, 10) & 0xFFFF; - bk_wifi_rc_config(sta_idx, rate_cfg); - } - else { - CLI_LOGI("invalid RC paramter\n"); - } -} -void cli_wifi_capa_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) { - uint32_t capa_id = 0; - uint32_t capa_val = 0; - - if (argc <= 2) { - CLI_LOGI("invalid CAPA command\n"); - return; - } - - if(os_strcmp(argv[1], "ht") == 0) { - capa_id = WIFI_CAPA_ID_HT_EN; - } - else if(os_strcmp(argv[1], "vht") == 0) { - capa_id = WIFI_CAPA_ID_VHT_EN; - } - else if(os_strcmp(argv[1], "he") == 0) { - capa_id = WIFI_CAPA_ID_HE_EN; - } - else if(os_strcmp(argv[1], "tx_ampdu") == 0) { - capa_id = WIFI_CAPA_ID_TX_AMPDU_EN; - } - else if(os_strcmp(argv[1], "rx_ampdu") == 0) { - capa_id = WIFI_CAPA_ID_RX_AMPDU_EN; - } - else if(os_strcmp(argv[1], "he_mcs") == 0) { - capa_id = WIFI_CAPA_ID_HE_MCS; - } - else { - CLI_LOGI("invalid CAPA paramter\n"); - return; - } - - capa_val = os_strtoul(argv[2], NULL, 10) & 0xFFFF; - bk_wifi_capa_config(capa_id, capa_val); -} - -#ifdef CONFIG_COMPONENTS_WPA_TWT_TEST -void cli_wifi_twt_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - uint16_t mantissa = 0; - uint8_t min_twt = 0; - - if(os_strcmp(argv[1], "setup") == 0) { - int setup_command = 0; - - if(os_strcmp(argv[2], "suggest") == 0) { - setup_command = 1; - } - else if(os_strcmp(argv[2], "demand") == 0) { - setup_command = 2; - } - else { - CLI_LOGI("Usage: twt setup suggest/demand \n"); - return; - } - mantissa = os_strtoul(argv[3], NULL, 10) & 0xFF; - min_twt = os_strtoul(argv[4], NULL, 10) & 0xFF; - bk_wifi_twt_setup(setup_command, mantissa, min_twt); - } - else if (os_strcmp(argv[1], "teardown") == 0) - bk_wifi_twt_teardown(); - else - CLI_LOGI("Usage: twt setup/teardown \n"); -} -#endif - -#define WIFI_CMD_CNT (sizeof(s_wifi_commands) / sizeof(struct cli_command)) -static const struct cli_command s_wifi_commands[] = { - {"scan", "scan [ssid]", cli_wifi_scan_cmd}, - {"ap", "ap ssid [password] [channel[1:14]]", cli_wifi_ap_cmd}, - {"sta", "sta ssid [password][bssid][channel]", cli_wifi_sta_cmd}, //TODO support connect speicific BSSID -#if CONFIG_COMPONENTS_WPA2_ENTERPRISE - {"sta_eap", "sta_eap ssid password [identity] [client_cert] [private_key]", cli_wifi_sta_eap_cmd}, -#endif - {"stop", "stop {sta|ap}", cli_wifi_stop_cmd}, - {"set_interval", "set listen interval}", cli_wifi_set_interval_cmd}, - {"monitor", "monitor {1~13|15|99}", cli_wifi_monitor_cmd}, - {"state", "state - show STA/AP state", cli_wifi_state_cmd}, - {"channel", "channel {1~13} - set monitor channel", cli_wifi_monitor_channel_cmd}, - {"net", "net {sta/ap} ... - wifi net config", cli_wifi_net_cmd}, - {"get", "get wifi status", cli_wifi_get_cmd}, - {"iplog", "iplog [modle]", cli_wifi_iplog_cmd}, - {"ipdbg", "ipdbg [module][para][value]", cli_wifi_ipdbg_cmd}, - -#ifdef CONFIG_COMPONENTS_WPA_TWT_TEST - {"twt", "twt {setup|teardown}", cli_wifi_twt_cmd}, -#endif - -#if CONFIG_COMPONENTS_WFA_CA - {"wfa_ca", "wfa_ca ", cli_wifi_wfa_ca_cmd}, -#endif - -#if CONFIG_WIFI_SENSOR - {"wifisensor", "wifi sensor", cli_wifi_sensor_cmd}, -#endif - {"filter", "filter - bit0/d, 1/preq, 2/prsp, 3/b, 4/a", cli_wifi_filter_cmd}, -#if CONFIG_WIFI_RAW_TX_TEST - {"wifi_tx", "wifi_tx - Tx WiFi raw frame", cli_wifi_raw_tx_cmd}, -#endif - {"rc", "wifi rate control config", cli_wifi_rc_cmd}, - {"capa", "wifi capability config", cli_wifi_capa_cmd}, -}; - -int cli_wifi_init(void) -{ - BK_LOG_ON_ERR(bk_event_register_cb(EVENT_MOD_WIFI, EVENT_ID_ALL, cli_wifi_event_cb, NULL)); - BK_LOG_ON_ERR(bk_event_register_cb(EVENT_MOD_NETIF, EVENT_ID_ALL, cli_netif_event_cb, NULL)); - return cli_register_commands(s_wifi_commands, WIFI_CMD_CNT); -} - -#endif //#if (CLI_CFG_WIFI == 1) diff --git a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/include/bk_api_cli.h b/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/include/bk_api_cli.h deleted file mode 100644 index 6364000f44b5b9dba742ad75df30acb22a311489..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/include/bk_api_cli.h +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -int bk_cli_init(void); - -#if CONFIG_SHELL_ASYNCLOG -#include - -#include "components/shell_task.h" - -#endif // #if CONFIG_SHELL_ASYNCLOG - - -#ifdef __cplusplus -} -#endif diff --git a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/include/bk_private/bk_cli.h b/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/include/bk_private/bk_cli.h deleted file mode 100755 index b8616867769452f30a31727ab3dc6d516bc341d7..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/include/bk_private/bk_cli.h +++ /dev/null @@ -1,212 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -#define CLI_UART CONFIG_UART_PRINT_PORT - -#define RX_WAIT BEKEN_WAIT_FOREVER -#define SEND_WAIT BEKEN_WAIT_FOREVER - -#define RET_CHAR '\n' -#define END_CHAR '\r' -#define PROMPT "\r\n# " -#define EXIT_MSG "exit" - -#define NUM_BUFFERS 1 - -#ifndef CONFIG_MAX_COMMANDS -#define MAX_COMMANDS 255 -#else -#define MAX_COMMANDS CONFIG_MAX_COMMANDS -#endif - -#ifdef CONFIG_KEYVALUE -#define INBUF_SIZE 1024 -#else -#define INBUF_SIZE 128 -#endif -#define OUTBUF_SIZE 2048 - -#define LOG_SERVICE_BUFLEN 100 - -#ifndef CFG_CLI_DEBUG -#define CFG_CLI_DEBUG 1 -#endif - -#if CFG_CLI_DEBUG -#define CLI_GETCHAR_TIMEOUT (120000) -#define CLI_COMMAND_IS_RUNNING (1) -#else -#define CLI_GETCHAR_TIMEOUT BEKEN_NEVER_TIMEOUT -#endif - -/** Structure for registering CLI commands */ -struct cli_command -{ - /** The name of the CLI command */ - const char *name; - /** The help text associated with the command */ - const char *help; - /** The function that should be invoked for this command. */ - void (*function) (char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv); -}; - -struct cli_st -{ - int initialized; - const struct cli_command *commands[MAX_COMMANDS]; - unsigned int num_commands; -#if ((!CONFIG_SHELL_ASYNCLOG) || CONFIG_ATE_TEST) - int echo_disabled; - - unsigned int bp; /* buffer pointer */ - char inbuf[INBUF_SIZE]; - - char outbuf[OUTBUF_SIZE]; -#endif -} ; - - -#define cmd_printf(...) do{\ - if (xWriteBufferLen > 0) {\ - snprintf(pcWriteBuffer, xWriteBufferLen, __VA_ARGS__);\ - xWriteBufferLen-= os_strlen(pcWriteBuffer);\ - pcWriteBuffer+= os_strlen(pcWriteBuffer);\ - }\ - }while(0) - - -#define CLI_ARGS char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv - -#define is_print(c) ((uint8_t)c >= 0x20 && (uint8_t)c <= 0x7f) - -#if (CONFIG_SOC_BK7271) -void bk7271_dsp_cli_init(void); -#if CONFIG_BT -void bk7271_ble_cli_init(void); -#endif -#endif - -#if (CONFIG_SOC_BK7256XX) -void usb_cli_init(void); -#endif - -/** Register a CLI command - * - * This function registers a command with the command-line interface. - * - * \param[in] command The structure to register one CLI command - * \return 0 on success - * \return 1 on failure - */ -int cli_register_command(const struct cli_command *command); - -/** Unregister a CLI command - * - * This function unregisters a command from the command-line interface. - * - * \param[in] command The structure to unregister one CLI command - * \return 0 on success - * \return 1 on failure - */ -int cli_unregister_command(const struct cli_command *command); - - - -/** Stop the CLI thread and carry out the cleanup - * - * \return kNoErr on success - * \return error code otherwise. - * - */ -int cli_stop(void); - -/** Register a batch of CLI commands - * - * Often, a module will want to register several commands. - * - * \param[in] commands Pointer to an array of commands. - * \param[in] num_commands Number of commands in the array. - * \return 0 on success - * \return 1 on failure - */ -int cli_register_commands(const struct cli_command *commands, int num_commands); - -/** Unregister a batch of CLI commands - * - * \param[in] commands Pointer to an array of commands. - * \param[in] num_commands Number of commands in the array. - * \return 0 on success - * \return 1 on failure - */ -int cli_unregister_commands(const struct cli_command *commands, - int num_commands); - -/* Get a CLI msg - * - * If an external input task wants to use the CLI, it can use - * cli_get_cmd_buffer() to get a command buffer that it can then - * submit to the CLI later using cli_submit_cmd_buffer(). - * - * \param buff Pointer to a char * to place the buffer pointer in. - * \return 0 on success - * \return error code otherwise. - */ -int cli_getchar(char *inbuf); -int cli_getchars(char *inbuf, int len); -int cli_get_all_chars_len(void); -int cli_getchars_prefetch(char *inbuf, int len); - -/* Send CLI output msg - * - * \param buff Pointer to a char * buffer. - * \return 0 on success - * \return error code otherwise. - */ -int cli_printf(const char *buff, ...); - - -// library CLI APIs -void ifconfig_Command(CLI_ARGS); -void arp_Command(CLI_ARGS); -void ping_Command(CLI_ARGS); -void dns_Command(CLI_ARGS); -void socket_show_Command(CLI_ARGS); -void memory_show_Command(CLI_ARGS); -void memory_dump_Command(CLI_ARGS); -void memory_set_Command(CLI_ARGS); -void memp_dump_Command(CLI_ARGS); -void cli_show_running_command(void); - -int cli_init(void); - -#ifdef MOC -void task_Command(CLI_ARGS); -#endif - -#if CONFIG_SHELL_ASYNCLOG -int handle_shell_input(char *inbuf, int in_buf_size, char * outbuf, int out_buf_size); -#endif - -#ifdef __cplusplus -} -#endif diff --git a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/rpc_client_gpio.c b/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/rpc_client_gpio.c deleted file mode 100755 index dedce8c989cc00fd9849c6c123d1cb6860616726..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/rpc_client_gpio.c +++ /dev/null @@ -1,268 +0,0 @@ -// Copyright 2020-2022 Beken -// -// 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 -#include - -#include -#include "mb_ipc_cmd.h" -#include - -#define MOD_TAG "RPC" - -#define GPIO_API_IDX(member) FIELD_IDX(gpio_func_tbl_t, member) - -typedef struct -{ - rpc_call_hdr_t call_hdr; - u32 gpio_id; -} rpc_gpio_call_t; - -typedef struct -{ - rpc_call_hdr_t call_hdr; - u32 ret_val; /* api_ret_data_t */ -} rpc_gpio_ret_t; - -typedef struct -{ - void * gpio_enable_output; - void * gpio_disable_output; - void * gpio_enable_input; - void * gpio_disable_input; - void * gpio_enable_pull; - void * gpio_disable_pull; - void * gpio_pull_up; - void * gpio_pull_down; - void * gpio_set_output_high; - void * gpio_set_output_low; - void * gpio_get_input; - void * gpio_set_config; - void * gpio_enable_interrupt; - void * gpio_disable_interrupt; - void * gpio_set_interrupt_type; -} gpio_func_tbl_t; - - -#if CONFIG_SLAVE_CORE - -/** ============================ gpio client ============================ **/ - -//bk_err_t bk_gpio_enable_output(gpio_id_t gpio_id) // should used this prototype. -bk_err_t bk_gpio_enable_output_rpc(gpio_id_t gpio_id) -{ - rpc_gpio_call_t gpio_rpc; - - gpio_rpc.call_hdr.mod_id = RPC_MOD_GPIO; - gpio_rpc.call_hdr.api_id = GPIO_API_IDX(gpio_enable_output); - gpio_rpc.call_hdr.ctrl = RPC_CTRL_NO_RETURN; - gpio_rpc.call_hdr.data_len = sizeof(gpio_rpc) - FIELD_OFFSET(rpc_call_def_t, call_param[0]); - gpio_rpc.gpio_id = gpio_id; - - return rpc_client_call((rpc_call_def_t *)&gpio_rpc, sizeof(gpio_rpc), NULL, 0); -} - -//bk_err_t bk_gpio_disable_output(gpio_id_t gpio_id) -bk_err_t bk_gpio_disable_output_rpc(gpio_id_t gpio_id) -{ - rpc_gpio_call_t gpio_rpc; - - gpio_rpc.call_hdr.mod_id = RPC_MOD_GPIO; - gpio_rpc.call_hdr.api_id = GPIO_API_IDX(gpio_disable_output); - gpio_rpc.call_hdr.ctrl = RPC_CTRL_NO_RETURN; - gpio_rpc.call_hdr.data_len = sizeof(gpio_rpc) - FIELD_OFFSET(rpc_call_def_t, call_param[0]); - gpio_rpc.gpio_id = gpio_id; - - return rpc_client_call((rpc_call_def_t *)&gpio_rpc, sizeof(gpio_rpc), NULL, 0); -} - -//bk_err_t bk_gpio_set_output_high(gpio_id_t gpio_id) -bk_err_t bk_gpio_set_output_high_rpc(gpio_id_t gpio_id) -{ - rpc_gpio_call_t gpio_rpc; - - gpio_rpc.call_hdr.mod_id = RPC_MOD_GPIO; - gpio_rpc.call_hdr.api_id = GPIO_API_IDX(gpio_set_output_high); - gpio_rpc.call_hdr.ctrl = RPC_CTRL_NO_RETURN; - gpio_rpc.call_hdr.data_len = sizeof(gpio_rpc) - FIELD_OFFSET(rpc_call_def_t, call_param[0]); - gpio_rpc.gpio_id = gpio_id; - - return rpc_client_call((rpc_call_def_t *)&gpio_rpc, sizeof(gpio_rpc), NULL, 0); -} - -//bk_err_t bk_gpio_set_output_low(gpio_id_t gpio_id) -bk_err_t bk_gpio_set_output_low_rpc(gpio_id_t gpio_id) -{ - rpc_gpio_call_t gpio_rpc; - - gpio_rpc.call_hdr.mod_id = RPC_MOD_GPIO; - gpio_rpc.call_hdr.api_id = GPIO_API_IDX(gpio_set_output_low); - gpio_rpc.call_hdr.ctrl = RPC_CTRL_NO_RETURN; - gpio_rpc.call_hdr.data_len = sizeof(gpio_rpc) - FIELD_OFFSET(rpc_call_def_t, call_param[0]); - gpio_rpc.gpio_id = gpio_id; - - return rpc_client_call((rpc_call_def_t *)&gpio_rpc, sizeof(gpio_rpc), NULL, 0); -} - -/** ============================ gpio client end ============================ **/ - -#endif - -#if CONFIG_MASTER_CORE - -/** ============================ gpio server ============================ **/ - -static const gpio_func_tbl_t rpc_gpio_api_tbl = -{ - .gpio_enable_output = bk_gpio_enable_output, - .gpio_disable_output = bk_gpio_disable_output, - .gpio_enable_input = bk_gpio_enable_input, - .gpio_disable_input = bk_gpio_disable_input, - .gpio_enable_pull = bk_gpio_enable_pull, - .gpio_disable_pull = bk_gpio_disable_pull, - .gpio_pull_up = bk_gpio_pull_up, - .gpio_pull_down = bk_gpio_pull_down, - .gpio_set_output_high = bk_gpio_set_output_high, - .gpio_set_output_low = bk_gpio_set_output_low, - .gpio_get_input = bk_gpio_get_input, - .gpio_set_config = bk_gpio_set_config, - .gpio_enable_interrupt = bk_gpio_enable_interrupt, - .gpio_disable_interrupt = bk_gpio_disable_interrupt, - .gpio_set_interrupt_type = bk_gpio_set_interrupt_type, -}; - -typedef int (*gpio_func_t)(); - -int bk_gpio_api_svr(rpc_call_def_t * call_buf) -{ - rpc_gpio_call_t * gpio_param = (rpc_gpio_call_t *)call_buf; - gpio_func_t * func_list = (gpio_func_t *)&rpc_gpio_api_tbl; - - if(call_buf->call_hdr.api_id >= sizeof(gpio_func_tbl_t) / sizeof(void *)) - return 0; - - switch(call_buf->call_hdr.api_id) - { - case GPIO_API_IDX(gpio_enable_output): - case GPIO_API_IDX(gpio_disable_output): - case GPIO_API_IDX(gpio_enable_input): - case GPIO_API_IDX(gpio_disable_input): - case GPIO_API_IDX(gpio_enable_pull): - case GPIO_API_IDX(gpio_disable_pull): - case GPIO_API_IDX(gpio_set_output_high): - case GPIO_API_IDX(gpio_set_output_low): - { - rpc_gpio_ret_t gpio_ret; - - gpio_ret.call_hdr.call_id = call_buf->call_hdr.call_id; - gpio_ret.call_hdr.data_len = sizeof(gpio_ret) - sizeof(gpio_ret.call_hdr); - gpio_ret.ret_val = func_list[call_buf->call_hdr.api_id](gpio_param->gpio_id); - - BK_LOGI(MOD_TAG, "gpio api: %d, id: %d\r\n", call_buf->call_hdr.api_id, gpio_param->gpio_id); - - rpc_server_rsp((rpc_ret_def_t *)&gpio_ret, sizeof(gpio_ret)); - } - break; - - case GPIO_API_IDX(gpio_set_config): - { - //bk_gpio_set_config(gpio_param->gpio_id); - return 0; - } - break; - - default: - return 0; - break; - } - - return 1; -} - -/** ============================ gpio server end ============================ **/ - -#endif - -#include -#include "mb_ipc_cmd.h" -#include - -//#define MOD_TAG "RPC" - -/** ============================ dma client ============================ **/ - -#define DMA_API_IDX(member) FIELD_IDX(dma_func_tbl_t, member) - -typedef struct -{ - void * dma_init; - void * dma_deinit; - void * dma_start; - void * dma_stop; - void * dma_write; - void * dma_read; - void * dma_enable_finish_interrupt; - void * dma_disable_finish_interrupt; - void * dma_enable_half_finish_interrupt; - void * dma_disable_half_finish_interrupt; - void * dma_set_transfer_len; - void * dma_set_src_addr; - void * dma_set_dest_addr; - void * dma_get_remain_len; - void * dma_set_src_pause_addr; - void * dma_set_dst_pause_addr; - void * dma_get_src_read_addr; - void * dma_get_dest_write_addr; - void * dma_memcpy; -} dma_func_tbl_t; - -/** ============================ dma client end ============================ **/ - -/** ============================ dma server ============================ **/ - -static const dma_func_tbl_t rpc_dma_api_tbl = -{ - .dma_init = bk_dma_init, - .dma_deinit = bk_dma_deinit, - .dma_start = bk_dma_start, - .dma_stop = bk_dma_stop, - .dma_write = bk_dma_write, - .dma_read = bk_dma_read, - .dma_enable_finish_interrupt = bk_dma_enable_finish_interrupt, - .dma_disable_finish_interrupt = bk_dma_disable_finish_interrupt, - .dma_enable_half_finish_interrupt = bk_dma_enable_half_finish_interrupt, - .dma_disable_half_finish_interrupt = bk_dma_disable_half_finish_interrupt, - .dma_set_transfer_len = bk_dma_set_transfer_len, - .dma_set_src_addr = bk_dma_set_src_addr, - .dma_set_dest_addr = bk_dma_set_dest_addr, - .dma_get_remain_len = bk_dma_get_remain_len, -/* .dma_set_src_pause_addr = dma_set_src_pause_addr, - .dma_set_dst_pause_addr = dma_set_dst_pause_addr, - .dma_get_src_read_addr = dma_get_src_read_addr, - .dma_get_dest_write_addr = dma_get_dest_write_addr, - .dma_memcpy = dma_memcpy,*/ -}; - -typedef int (*dma_func_t)(); - -int bk_dma_api_svr(rpc_call_def_t * call_buf) -{ - if(call_buf->call_hdr.api_id >= sizeof(rpc_dma_api_tbl) / sizeof(void *)) - return 0; - - return 0; -} - -/** ============================ dma server end ============================ **/ - diff --git a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/shell_drv.h b/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/shell_drv.h deleted file mode 100755 index 4f087be4a5bb6fc188499fba8c9ae8babdb335d8..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/shell_drv.h +++ /dev/null @@ -1,127 +0,0 @@ - -#ifndef _shell_drv_h_ -#define _shell_drv_h_ - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -typedef enum -{ - bFALSE = 0, - bTRUE = !bFALSE, -} bool_t; - -typedef enum -{ - SHELL_IO_CTRL_GET_STATUS = 0, - SHELL_IO_CTRL_RX_RESET, - SHELL_IO_CTRL_TX_RESET, - SHELL_IO_CTRL_FLUSH, - SHELL_IO_CTRL_SET_UART_PORT, - SHELL_IO_CTRL_GET_RX_STATUS, -} shell_ctrl_cmd_t; - -enum -{ - SHELL_DEV_UART = 0, - SHELL_DEV_MAILBOX, -}; - -struct _shell_dev_drv; - -typedef struct -{ - struct _shell_dev_drv *dev_drv; - u8 dev_type; - void * dev_ext; -} shell_dev_t; - -typedef void (* tx_complete_t)(u8 *pbuf, u16 Tag); -typedef void (* rx_indicate_t)(void); - -typedef struct _shell_dev_drv -{ - bool_t (*init)(shell_dev_t * shell_dev); - bool_t (*open)(shell_dev_t * shell_dev, tx_complete_t tx_callback, rx_indicate_t rx_callback); - u16 (*write_async)(shell_dev_t * shell_dev, u8 * pBuf, u16 BufLen, u16 Tag); - u16 (*read)(shell_dev_t * shell_dev, u8 * pBuf, u16 BufLen); - u16 (*write_sync)(shell_dev_t * shell_dev, u8 * pBuf, u16 BufLen); - u16 (*write_echo)(shell_dev_t * shell_dev, u8 * pBuf, u16 BufLen); - bool_t (*io_ctrl)(shell_dev_t * shell_dev, u8 cmd, void * param); - bool_t (*close)(shell_dev_t * shell_dev); -} shell_dev_drv_t; - -extern shell_dev_t shell_uart; -extern shell_dev_t shell_dev_mb; -extern shell_dev_t shell_uart3; - - -#ifdef CONFIG_DUAL_CORE - -#include "mailbox_channel.h" - -struct _shell_ipc_drv; - -typedef struct -{ - struct _shell_ipc_drv *dev_drv; - u8 dev_type; - void * dev_ext; -} shell_dev_ipc_t; - -typedef int (* shell_ipc_rx_t)(u16 cmd, void *data_buf, u16 dataLen); - -typedef struct _shell_ipc_drv -{ - bool_t (*init)(shell_dev_ipc_t * dev_ipc); - bool_t (*open)(shell_dev_ipc_t * dev_ipc, shell_ipc_rx_t rx_callback); - u16 (*read)(shell_dev_ipc_t * dev_ipc, u8 * pBuf, u16 BufLen); - u16 (*write_sync)(shell_dev_ipc_t * dev_ipc, u8 * pBuf, u16 BufLen); - bool_t (*io_ctrl)(shell_dev_ipc_t * dev_ipc, u8 cmd, void * param); - bool_t (*close)(shell_dev_ipc_t * dev_ipc); -} shell_ipc_drv_t; - -typedef union -{ - struct - { - mb_chnl_hdr_t hdr; - u8 * buf; - u16 len; - u16 tag; - }; - mb_chnl_cmd_t cmd_buf; -} log_cmd_t; - -typedef union -{ - struct - { - mb_chnl_hdr_t hdr; - u8 * buf; - u16 len; - }; - mb_chnl_cmd_t cmd_buf; -} user_cmd_t; - -enum -{ - MB_CMD_LOG_OUT = 1, - MB_CMD_LOG_OUT_OK, - MB_CMD_USER_INPUT, - MB_CMD_ASSERT_OUT, -} ; - -extern shell_dev_ipc_t shell_dev_ipc; - -#endif /* CONFIG_DUAL_CORE */ - -#ifdef __cplusplus -} -#endif - -#endif /* _shell_drv_h_ */ - diff --git a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/shell_mailbox_cp1.c b/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/shell_mailbox_cp1.c deleted file mode 100755 index 795d03e29e53d5489498b2bb7e616d15bc0fc23b..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/shell_mailbox_cp1.c +++ /dev/null @@ -1,603 +0,0 @@ - -#include -#include - -#include "cli.h" -#include "shell_drv.h" -#include "mailbox_channel.h" - -#if CONFIG_ARCH_RISCV -#include "cache.h" -#endif - -#define TX_QUEUE_LEN 8 -#define RX_BUFF_SIZE 160 -#define TX_SYNC_BUF_SIZE 142 - -typedef struct -{ - u8 * packet; - u16 len; - u16 tag; -} dev_tx_packet_t; - -typedef struct -{ - u8 chnl_id; - - /* ======== TX channel ======= */ - /* tx queue */ - dev_tx_packet_t tx_list[TX_QUEUE_LEN]; - u16 list_out_idx; - u16 list_in_idx; - - /* currently tx packet info */ - u8 *cur_packet; - u16 packet_len; - u16 packet_tag; - - u8 tx_stopped; - - tx_complete_t tx_complete_callback; - - u8 tx_sync_buff[TX_SYNC_BUF_SIZE + 2]; - - /* ======== RX channel ======= */ - /* rx buffer */ - u8 rx_buff[RX_BUFF_SIZE + 2]; /* 2 bytes additional for '\r\n' */ - u8 rx_buff_wr_idx; - u8 rx_buff_rd_idx; - u16 rx_data_len; - - rx_indicate_t rx_indicate_callback; - -} shell_mb_ext_t; - -static bool_t shell_mb_init(shell_dev_t * shell_dev); -static bool_t shell_mb_open(shell_dev_t * shell_dev, tx_complete_t tx_callback, rx_indicate_t rx_callback); -static u16 shell_mb_write_async(shell_dev_t * shell_dev, u8 * pBuf, u16 BufLen, u16 Tag); -static u16 shell_mb_read(shell_dev_t * shell_dev, u8 * pBuf, u16 BufLen); -static u16 shell_mb_write_sync(shell_dev_t * shell_dev, u8 * pBuf, u16 BufLen); -static u16 shell_mb_write_echo(shell_dev_t * shell_dev, u8 * pBuf, u16 BufLen); -static bool_t shell_mb_ctrl(shell_dev_t * shell_dev, u8 cmd, void *param); -static bool_t shell_mb_close(shell_dev_t * shell_dev); - -static const shell_dev_drv_t shell_mb_drv = - { - .init = shell_mb_init, - .open = shell_mb_open, - .write_async = shell_mb_write_async, - .read = shell_mb_read, - .write_sync = shell_mb_write_sync, - .write_echo = shell_mb_write_echo, - .io_ctrl = shell_mb_ctrl, - .close = shell_mb_close - }; - -static shell_mb_ext_t dev_mb_ext = - { - .chnl_id = MB_CHNL_LOG - }; - -shell_dev_t shell_dev_mb = - { - .dev_drv = (struct _shell_dev_drv *)&shell_mb_drv, - .dev_type = SHELL_DEV_MAILBOX, - .dev_ext = &dev_mb_ext - }; - -/* =============================== internal functions =========================== */ -static void shell_mb_rx_isr(shell_mb_ext_t *mb_ext, mb_chnl_cmd_t *cmd_buf) -{ - u32 result = ACK_STATE_FAIL; - - if(cmd_buf->hdr.cmd == MB_CMD_LOG_OUT_OK) /* rsp of log_out_cmd, so free the log_buffer. */ - { - log_cmd_t * log_cmd = (log_cmd_t *)cmd_buf; - - /* do nothing except notifying app to free buffer. */ - if(mb_ext->tx_complete_callback != NULL) - { - mb_ext->tx_complete_callback(log_cmd->buf, log_cmd->tag); - } - - result = ACK_STATE_COMPLETE; - } - else if(cmd_buf->hdr.cmd == MB_CMD_USER_INPUT) /* cmd line inputs. */ - { - user_cmd_t * user_cmd = (user_cmd_t *)cmd_buf; - -#if CONFIG_CACHE_ENABLE - flush_dcache((void *)user_cmd->buf, user_cmd->len); -#endif - - if((user_cmd->len >= RX_BUFF_SIZE) || (mb_ext->rx_buff_wr_idx != mb_ext->rx_buff_rd_idx)) - { - result = ACK_STATE_FAIL; - } - else - { - memcpy(mb_ext->rx_buff, user_cmd->buf, user_cmd->len); - - result = ACK_STATE_COMPLETE; /* it means the buffer can be freed. cmd is pending and will rsp later by MB_CMD_LOG_OUT. */ - - mb_ext->rx_data_len = user_cmd->len; - mb_ext->rx_buff_wr_idx++; /* prevent mb_rx_isr from receiving new cmd. */ - } - - if(mb_ext->rx_indicate_callback != NULL) - { - mb_ext->rx_indicate_callback(); - } - } - else /* unknown cmd. */ - { - result = ACK_STATE_FAIL; - } - - /* overwrite the cmd_buf->param3 after the ISR handle complete. - * return the ack info to caller using the SAME buffer with cmd buffer. - * !!!! [input as param / outpu as result ] !!!! - */ - mb_chnl_ack_t * ack_buf = (mb_chnl_ack_t *)cmd_buf; - ack_buf->ack_state = result; - - return; -} - -static void shell_mb_tx_isr2(shell_mb_ext_t *mb_ext) -{ - mb_chnl_cmd_t mb_cmd_buf; - - /* next tx. */ - if(mb_ext->list_out_idx != mb_ext->list_in_idx) - { - mb_ext->cur_packet = mb_ext->tx_list[mb_ext->list_out_idx].packet; - mb_ext->packet_len = mb_ext->tx_list[mb_ext->list_out_idx].len; - mb_ext->packet_tag = mb_ext->tx_list[mb_ext->list_out_idx].tag; - - log_cmd_t * cmd_buf = (log_cmd_t *)&mb_cmd_buf; - - cmd_buf->hdr.data = 0; - cmd_buf->hdr.cmd = MB_CMD_LOG_OUT; - cmd_buf->buf = mb_ext->cur_packet; - cmd_buf->len = mb_ext->packet_len; - cmd_buf->tag = mb_ext->packet_tag; - - bk_err_t ret_code; - - ret_code = mb_chnl_write(mb_ext->chnl_id, &mb_cmd_buf); - - if(ret_code == BK_OK) - { - /* to next packet. */ - mb_ext->list_out_idx = (mb_ext->list_out_idx + 1) % TX_QUEUE_LEN; - } - } - else - { - /* all packets tx complete. */ - - mb_ext->cur_packet = NULL; - mb_ext->packet_len = 0; - - mb_ext->tx_stopped = 1; /* bTRUE;*/ /* all data tranferred, tx stopped.*/ - } -} - -static void shell_mb_tx_cmpl_isr2(shell_mb_ext_t *mb_ext, mb_chnl_ack_t *ack_buf) -{ - if(ack_buf->hdr.cmd != MB_CMD_LOG_OUT) - { - /* - * !!! FAULT !!! - */ - - // return; - } - - /* MB_CMD_LOG_OUT tx complete. */ - - if( (ack_buf->hdr.state & CHNL_STATE_COM_FAIL) - || (ack_buf->ack_state != ACK_STATE_PENDING) ) - { - /* MB_CMD_LOG_OUT handle complete. */ - /* so notify app to free buffer. */ - if(mb_ext->tx_complete_callback != NULL) - { - mb_ext->tx_complete_callback(mb_ext->cur_packet, mb_ext->packet_tag); - } - } -} - -static void shell_mb_tx_cmpl_isr(shell_mb_ext_t *mb_ext, mb_chnl_ack_t *ack_buf) -{ - shell_mb_tx_cmpl_isr2(mb_ext, ack_buf); /* not the SAME with following code if cmd is NOT MB_CMD_LOG_OUT. */ - shell_mb_tx_isr2(mb_ext); - return; - - /* shell_mb_tx_cmpl_isr2 */ - - #if 0 - if(ack_buf->hdr.cmd != MB_CMD_LOG_OUT) - { - /* - * !!! FAULT !!! - */ - - // return; - } - - /* MB_CMD_LOG_OUT tx complete. */ - - if(ack_buf->ack_state != ACK_STATE_PENDING) - { - /* MB_CMD_LOG_OUT handle complete. */ - /* so notify app to free buffer. */ - if(mb_ext->tx_complete_callback != NULL) - { - mb_ext->tx_complete_callback(mb_ext->cur_packet, mb_ext->packet_tag); - } - } - #endif - - /* shell_mb_tx_isr2 */ - - #if 0 - /* next tx. */ - if(mb_ext->list_out_idx != mb_ext->list_in_idx) - { - mb_ext->cur_packet = mb_ext->tx_list[mb_ext->list_out_idx].packet; - mb_ext->packet_len = mb_ext->tx_list[mb_ext->list_out_idx].len; - mb_ext->packet_tag = mb_ext->tx_list[mb_ext->list_out_idx].tag; - - log_cmd_t * cmd_buf = (log_cmd_t *)ack_buf; - - cmd_buf->hdr.data = MB_CMD_LOG_OUT; - cmd_buf->buf = mb_ext->cur_packet; - cmd_buf->len = mb_ext->packet_len; - cmd_buf->tag = mb_ext->packet_tag; - - bk_err_t ret_code; - - ret_code = mb_chnl_write(mb_ext->chnl_id, (mb_chnl_cmd_t *)cmd_buf); - - if(ret_code == BK_OK) - { - /* to next packet. */ - mb_ext->list_out_idx = (mb_ext->list_out_idx + 1) % TX_QUEUE_LEN; - } - } - else - { - /* all packets tx complete. */ - - mb_ext->cur_packet = NULL; - mb_ext->packet_len = 0; - - mb_ext->tx_stopped = 1; /* bTRUE;*/ /* all data tranferred, tx stopped.*/ - } - #endif -} - -static bk_err_t write_sync(shell_mb_ext_t *mb_ext, u8 * p_buf, u16 buf_len) -{ - volatile u8 * buff_busy; - u8 * tx_buff; - - tx_buff = &mb_ext->tx_sync_buff[0]; - if((buf_len + 1) > sizeof(mb_ext->tx_sync_buff)) - { - buf_len = sizeof(mb_ext->tx_sync_buff) - 1; - } - /* - tx_buff = &mb_ext->rx_buff[0]; - if((buf_len + 1) > sizeof(mb_ext->rx_buff)) - { - buf_len = sizeof(mb_ext->rx_buff) - 1; - } - */ // can use rx_buff for assert_out, because the interrpt is disabled when assert, no cmd will be arrived. - - buff_busy = (volatile u8 * )&tx_buff[0]; - tx_buff[0] = 1; /* the buffer is busy. */ - memcpy(&tx_buff[1], p_buf, buf_len); - - mb_chnl_cmd_t mb_cmd_buf; - log_cmd_t * cmd_buf = (log_cmd_t *)&mb_cmd_buf; - - cmd_buf->hdr.data = 0; - cmd_buf->hdr.cmd = MB_CMD_ASSERT_OUT; - cmd_buf->buf = tx_buff; - cmd_buf->len = buf_len + 1; - cmd_buf->tag = 0xFFFF; /* tx_buff is not memory of allocated dynamically. */ - - bk_err_t ret_code; - - ret_code = mb_chnl_ctrl(mb_ext->chnl_id, MB_CHNL_WRITE_SYNC, &mb_cmd_buf); - - if(ret_code == BK_OK) - { - while(*buff_busy) - { - // wait buffer to be free. - } - } - - return ret_code; -} - -static void shell_mb_flush(shell_mb_ext_t *mb_ext) -{ - while(mb_ext->tx_stopped == 0) - { - #if 1 - /* next tx. */ - if(mb_ext->list_out_idx != mb_ext->list_in_idx) - { - mb_ext->cur_packet = mb_ext->tx_list[mb_ext->list_out_idx].packet; - mb_ext->packet_len = mb_ext->tx_list[mb_ext->list_out_idx].len; - mb_ext->packet_tag = mb_ext->tx_list[mb_ext->list_out_idx].tag; - - write_sync(mb_ext, mb_ext->cur_packet, mb_ext->packet_len); - - /* to next packet. */ - mb_ext->list_out_idx = (mb_ext->list_out_idx + 1) % TX_QUEUE_LEN; - } - else - { - /* all packets tx complete. */ - - mb_ext->cur_packet = NULL; - mb_ext->packet_len = 0; - - mb_ext->tx_stopped = 1; /* bTRUE;*/ /* all data tranferred, tx stopped.*/ - - continue; - } - #endif - #if 1 - /* MB_CMD_LOG_OUT tx complete. */ - - // must have handled complete, because of using MB_CMD_ASSERT_OUT. - // if(ack_buf->ack_state != ACK_STATE_PENDING) - { - /* MB_CMD_LOG_OUT handle complete. */ - /* so notify app to free buffer. */ - if(mb_ext->tx_complete_callback != NULL) - { - mb_ext->tx_complete_callback(mb_ext->cur_packet, mb_ext->packet_tag); - } - } - #endif - } -} - -static void shell_mb_tx_trigger(shell_mb_ext_t *mb_ext) -{ - if(mb_ext->tx_stopped == 0) - return; - - mb_ext->tx_stopped = 0; // set tx_stopped to 0 firstly, then enable TX. - - shell_mb_tx_isr2(mb_ext); -} - -/* =============================== shell mailbox driver APIs =========================== */ - -static bool_t shell_mb_init(shell_dev_t * shell_dev) -{ - u8 dev_id; - shell_mb_ext_t *mb_ext; - - if(shell_dev == NULL) - return bFALSE; - - mb_ext = (shell_mb_ext_t *)shell_dev->dev_ext; - dev_id = mb_ext->chnl_id; - - memset(mb_ext, 0, sizeof(shell_mb_ext_t)); - mb_ext->tx_stopped = 1; - mb_ext->chnl_id = dev_id; - - return bTRUE; -} - -static bool_t shell_mb_open(shell_dev_t * shell_dev, tx_complete_t tx_callback, rx_indicate_t rx_callback) -{ - shell_mb_ext_t *mb_ext; - - if(shell_dev == NULL) - return bFALSE; - - mb_ext = (shell_mb_ext_t *)shell_dev->dev_ext; - - mb_ext->tx_complete_callback = tx_callback; - mb_ext->rx_indicate_callback = rx_callback; - - bk_err_t ret_code = mb_chnl_open(mb_ext->chnl_id, mb_ext); - - if(ret_code != BK_OK) - return bFALSE; - - // call chnl driver to register isr callback; - mb_chnl_ctrl(mb_ext->chnl_id, MB_CHNL_SET_RX_ISR, (void *)shell_mb_rx_isr); - #if 0 - mb_chnl_ctrl(mb_ext->chnl_id, MB_CHNL_SET_TX_ISR, (void *)shell_mb_tx_isr2); - mb_chnl_ctrl(mb_ext->chnl_id, MB_CHNL_SET_TX_CMPL_ISR, (void *)shell_mb_tx_cmpl_isr2); - #else - mb_chnl_ctrl(mb_ext->chnl_id, MB_CHNL_SET_TX_CMPL_ISR, (void *)shell_mb_tx_cmpl_isr); - #endif - - return bTRUE; -} - -static u16 shell_mb_write_async(shell_dev_t * shell_dev, u8 * pBuf, u16 BufLen, u16 Tag) -{ - u16 free_items; - shell_mb_ext_t *mb_ext; - - if(shell_dev == NULL) - return 0; - - mb_ext = (shell_mb_ext_t *)shell_dev->dev_ext; - - if((pBuf == NULL) /*|| (BufLen == 0)*/) - return 0; - - /* enqueue pBuf even if BufLen is 0, upper layer need tx-complete-callback to free this pBuf. */ - - if(mb_ext->list_out_idx > mb_ext->list_in_idx) - free_items = mb_ext->list_out_idx - mb_ext->list_in_idx; - else - free_items = TX_QUEUE_LEN - mb_ext->list_in_idx + mb_ext->list_out_idx; - - /* list_out_idx == list_in_idx means empty, so reserved one item. */ - if(free_items > 1) - { - mb_ext->tx_list[mb_ext->list_in_idx].packet = pBuf; - mb_ext->tx_list[mb_ext->list_in_idx].len = BufLen; - mb_ext->tx_list[mb_ext->list_in_idx].tag = Tag; - - mb_ext->list_in_idx = (mb_ext->list_in_idx + 1) % TX_QUEUE_LEN; - - shell_mb_tx_trigger(mb_ext); - - return 1; - } - else - { - return 0; - } -} - -static u16 shell_mb_read(shell_dev_t * shell_dev, u8 * pBuf, u16 BufLen) -{ - u16 read_cnt = 0; - - shell_mb_ext_t *mb_ext; - - if(shell_dev == NULL) - return 0; - - mb_ext = (shell_mb_ext_t *)shell_dev->dev_ext; - - if(pBuf == NULL) - return 0; - - if( (mb_ext->rx_buff_rd_idx != mb_ext->rx_buff_wr_idx) && - (BufLen >= mb_ext->rx_data_len) ) - { - read_cnt = mb_ext->rx_data_len; - memcpy(pBuf, mb_ext->rx_buff, read_cnt); - - mb_ext->rx_buff_rd_idx++; /* allow mb_rx_isr to recv new cmd. */ - } - - return read_cnt; - -} - -/* call this after interrupt is DISABLED. */ -static u16 shell_mb_write_sync(shell_dev_t * shell_dev, u8 * pBuf, u16 BufLen) -{ - shell_mb_ext_t *mb_ext; - - if(shell_dev == NULL) - return 0; - - mb_ext = (shell_mb_ext_t *)shell_dev->dev_ext; - - bk_err_t ret_code; - - ret_code = write_sync(mb_ext, pBuf, BufLen); - - if(ret_code != BK_OK) - return 0; - - return 1; -} - -static u16 shell_mb_write_echo(shell_dev_t * shell_dev, u8 * pBuf, u16 BufLen) -{ - return 0; -} - -static bool_t shell_mb_ctrl(shell_dev_t * shell_dev, u8 cmd, void *param) -{ - shell_mb_ext_t *mb_ext; - - if(shell_dev == NULL) - return bFALSE; - - mb_ext = (shell_mb_ext_t *)shell_dev->dev_ext; - - switch(cmd) - { - case SHELL_IO_CTRL_GET_STATUS: - if(param == NULL) - return bFALSE; - - u16 free_items; - - if(mb_ext->list_out_idx > mb_ext->list_in_idx) - free_items = mb_ext->list_out_idx - mb_ext->list_in_idx; - else - free_items = TX_QUEUE_LEN - mb_ext->list_in_idx + mb_ext->list_out_idx; - - if(free_items > 1) - *((u16 *)param) = free_items - 1; - else - *((u16 *)param) = 0; - - break; - - case SHELL_IO_CTRL_RX_RESET: - mb_ext->rx_buff_rd_idx = 0; - mb_ext->rx_buff_wr_idx = 0; - mb_ext->rx_data_len = 0; - break; - - case SHELL_IO_CTRL_TX_RESET: - mb_ext->list_out_idx = 0; - mb_ext->list_in_idx = 0; - - mb_ext->cur_packet = NULL; - mb_ext->packet_len = 0; - - break; - - case SHELL_IO_CTRL_FLUSH: - shell_mb_flush(mb_ext); - break; - - default: - return bFALSE; - break; - } - - return bTRUE; -} - -static bool_t shell_mb_close(shell_dev_t * shell_dev) -{ - shell_mb_ext_t *mb_ext; - - if(shell_dev == NULL) - return bFALSE; - - mb_ext = (shell_mb_ext_t *)shell_dev->dev_ext; - - // call chnl driver to register isr callback; - mb_chnl_ctrl(mb_ext->chnl_id, MB_CHNL_SET_RX_ISR, NULL); - mb_chnl_ctrl(mb_ext->chnl_id, MB_CHNL_SET_TX_ISR, NULL); - mb_chnl_ctrl(mb_ext->chnl_id, MB_CHNL_SET_TX_CMPL_ISR, NULL); - - mb_chnl_close(mb_ext->chnl_id); - - mb_ext->tx_complete_callback = NULL; - mb_ext->rx_indicate_callback = NULL; - - return bTRUE; -} - - diff --git a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/shell_mailbox_ipc.c b/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/shell_mailbox_ipc.c deleted file mode 100755 index 349a45d580a5304ace27938d97711258c4e5b20e..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/shell_mailbox_ipc.c +++ /dev/null @@ -1,219 +0,0 @@ - -#include -#include - -#include "cli.h" -#include "shell_drv.h" -#include "mailbox_channel.h" - -#if CONFIG_ARCH_RISCV -#include "cache.h" -#endif - -typedef struct -{ - u8 chnl_id; - - shell_ipc_rx_t rx_callback; - -} shell_ipc_ext_t; - -static bool_t shell_ipc_init(shell_dev_ipc_t * dev_ipc); -static bool_t shell_ipc_open(shell_dev_ipc_t * dev_ipc, shell_ipc_rx_t rx_callback); -static u16 shell_ipc_read(shell_dev_ipc_t * dev_ipc, u8 * pBuf, u16 BufLen); -static u16 shell_ipc_write_sync(shell_dev_ipc_t * dev_ipc, u8 * pBuf, u16 BufLen); -static bool_t shell_ipc_ctrl(shell_dev_ipc_t * dev_ipc, u8 cmd, void *param); -static bool_t shell_ipc_close(shell_dev_ipc_t * dev_ipc); - -static const shell_ipc_drv_t shell_ipc_drv = - { - .init = shell_ipc_init, - .open = shell_ipc_open, - .read = shell_ipc_read, - .write_sync = shell_ipc_write_sync, - .io_ctrl = shell_ipc_ctrl, - .close = shell_ipc_close - }; - -static shell_ipc_ext_t dev_ipc_ext = - { - .chnl_id = MB_CHNL_LOG - }; - -shell_dev_ipc_t shell_dev_ipc = - { - .dev_drv = (struct _shell_ipc_drv *)&shell_ipc_drv, - .dev_type = SHELL_DEV_MAILBOX, - .dev_ext = &dev_ipc_ext - }; - -/* =============================== internal functions =========================== */ -static void shell_ipc_rx_isr(shell_ipc_ext_t *ipc_ext, mb_chnl_cmd_t *cmd_buf) -{ - u32 result = ACK_STATE_FAIL; - - if(cmd_buf->hdr.cmd == MB_CMD_LOG_OUT) - { - if(ipc_ext->rx_callback != NULL) - { - log_cmd_t * log_cmd = (log_cmd_t *)cmd_buf; - -#if CONFIG_CACHE_ENABLE - flush_dcache((void *)log_cmd->buf, log_cmd->len); -#endif - - result = ipc_ext->rx_callback(log_cmd->hdr.cmd, log_cmd->buf, log_cmd->len); - - if(result == 0) - result = ACK_STATE_FAIL; // log discarded. - else - result = ACK_STATE_COMPLETE; - } - } - else if (cmd_buf->hdr.cmd == MB_CMD_ASSERT_OUT) - { - if(ipc_ext->rx_callback != NULL) - { - log_cmd_t * log_cmd = (log_cmd_t *)cmd_buf; - - result = ipc_ext->rx_callback(log_cmd->hdr.cmd, log_cmd->buf + 1, log_cmd->len - 1); - - if(result == 0) - result = ACK_STATE_FAIL; // log discarded. - else - result = ACK_STATE_COMPLETE; - - /* assert_out must be handled in synchrously, so the buffer is free when return. */ - log_cmd->buf[0] = 0; /* notify the sender that buffer can be freed now. */ - } - } - else /* unknown cmd. */ - { - result = ACK_STATE_FAIL; - } - - /* overwrite the cmd_buf->param3 after the ISR handle complete. - * return the ack info to caller using the SAME buffer with cmd buffer. - * !!!! [input as param / outpu as result ] !!!! - */ - mb_chnl_ack_t * ack_buf = (mb_chnl_ack_t *)cmd_buf; - ack_buf->ack_state = result; - - return; -} - -/* =============================== shell ipc driver APIs =========================== */ - -static bool_t shell_ipc_init(shell_dev_ipc_t * dev_ipc) -{ - u8 dev_id; - shell_ipc_ext_t *ipc_ext; - - if(dev_ipc == NULL) - return bFALSE; - - ipc_ext = (shell_ipc_ext_t *)dev_ipc->dev_ext; - dev_id = ipc_ext->chnl_id; - - memset(ipc_ext, 0, sizeof(shell_ipc_ext_t)); - ipc_ext->chnl_id = dev_id; - - return bTRUE; -} - -static bool_t shell_ipc_open(shell_dev_ipc_t * dev_ipc, shell_ipc_rx_t rx_callback) -{ - shell_ipc_ext_t *ipc_ext; - - if(dev_ipc == NULL) - return bFALSE; - - ipc_ext = (shell_ipc_ext_t *)dev_ipc->dev_ext; - - ipc_ext->rx_callback = rx_callback; - - bk_err_t ret_code = mb_chnl_open(ipc_ext->chnl_id, ipc_ext); - - if(ret_code != BK_OK) - return bFALSE; - - // call chnl driver to register isr callback; - mb_chnl_ctrl(ipc_ext->chnl_id, MB_CHNL_SET_RX_ISR, (void *)shell_ipc_rx_isr); - - return bTRUE; -} - -static u16 shell_ipc_read(shell_dev_ipc_t * dev_ipc, u8 * pBuf, u16 BufLen) -{ - return 0; -} - -/* call this after interrupt is DISABLED. */ -static u16 shell_ipc_write_sync(shell_dev_ipc_t * dev_ipc, u8 * pBuf, u16 BufLen) -{ - shell_ipc_ext_t *ipc_ext; - ipc_ext = (shell_ipc_ext_t *)dev_ipc->dev_ext; - - mb_chnl_cmd_t mb_cmd_buf; - user_cmd_t * user_cmd = (user_cmd_t *)&mb_cmd_buf; - - user_cmd->hdr.data = 0; - user_cmd->hdr.cmd = MB_CMD_USER_INPUT; - user_cmd->buf = pBuf; - user_cmd->len = BufLen; - - bk_err_t ret_code; - - ret_code = mb_chnl_write(ipc_ext->chnl_id, &mb_cmd_buf); - - if(ret_code == BK_OK) - { - return BufLen; - } - - return 0; -} - -static bool_t shell_ipc_ctrl(shell_dev_ipc_t * dev_ipc, u8 cmd, void *param) -{ - if(dev_ipc == NULL) - return bFALSE; - - switch(cmd) - { - /* - case SHELL_IPC_SET_RX_CALLBACK: - ipc_ext->rx_callback = (shell_ipc_rx_t)param; - break; - */ - - default: - return bFALSE; - break; - } - - return bTRUE; -} - -static bool_t shell_ipc_close(shell_dev_ipc_t * dev_ipc) -{ - shell_ipc_ext_t *ipc_ext; - - if(dev_ipc == NULL) - return bFALSE; - - ipc_ext = (shell_ipc_ext_t *)dev_ipc->dev_ext; - - // call chnl driver to register isr callback; - mb_chnl_ctrl(ipc_ext->chnl_id, MB_CHNL_SET_RX_ISR, NULL); - mb_chnl_ctrl(ipc_ext->chnl_id, MB_CHNL_SET_TX_ISR, NULL); - mb_chnl_ctrl(ipc_ext->chnl_id, MB_CHNL_SET_TX_CMPL_ISR, NULL); - - mb_chnl_close(ipc_ext->chnl_id); - - ipc_ext->rx_callback = NULL; - - return bTRUE; -} - - diff --git a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/shell_task.c b/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/shell_task.c deleted file mode 100755 index 30d33cd3874b1a3cbbfe9b2c57655e1fa34d3518..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/shell_task.c +++ /dev/null @@ -1,1553 +0,0 @@ - -#include -#include -#include - -#include "cli.h" -#include -#include -#include "shell_drv.h" - -#define SHELL_TASK_DEF_TICK (1000) // 1000ms -> 1s -#define SHELL_EVENT_TX_REQ 0x01 -#define SHELL_EVENT_RX_IND 0x02 - -#define SHELL_LOG_BUF1_LEN 136 -#define SHELL_LOG_BUF2_LEN 64 -#define SHELL_LOG_BUF3_LEN 40 - -#ifdef CONFIG_SLAVE_CORE -#define SHELL_LOG_BUF1_NUM 6 -#define SHELL_LOG_BUF2_NUM 16 -#define SHELL_LOG_BUF3_NUM 20 - -#define SHELL_LOG_BUF_NUM (SHELL_LOG_BUF1_NUM + SHELL_LOG_BUF2_NUM + SHELL_LOG_BUF3_NUM) -#define SHELL_LOG_PEND_NUM (SHELL_LOG_BUF_NUM + 3) /* 1: for RSP, 1: reserved(queue empty), 1: cmd ovf. */ -#define SHELL_LOG_BUSY_NUM (SHELL_LOG_PEND_NUM) /* depending on lower driver's pending queue size. IPC drv no busy state. */ -#else -#define SHELL_LOG_BUF1_NUM 16 -#define SHELL_LOG_BUF2_NUM 48 -#define SHELL_LOG_BUF3_NUM 64 - -#define SHELL_LOG_BUF_NUM (SHELL_LOG_BUF1_NUM + SHELL_LOG_BUF2_NUM + SHELL_LOG_BUF3_NUM) -#define SHELL_LOG_PEND_NUM (SHELL_LOG_BUF_NUM * 2 + 3) /* 1: for RSP, 1: reserved(queue empty, 1: cmd ovf). */ /* the worst case may be (one log + one hint) in pending queue.*/ -#define SHELL_LOG_BUSY_NUM (20) /* depending on lower driver's pending queue size. drv's queue size < BUSY_NUM <= PEND_NUM. */ -#endif - -#define SHELL_ASSERT_BUF_LEN 140 -#define SHELL_CMD_BUF_LEN 140 -#define SHELL_RSP_BUF_LEN 200 - -#define SHELL_RSP_QUEUE_ID (7) -#define SHELL_FW_QUE_ID (8) -#define SHELL_ROM_QUEUE_ID (9) - -#define MAX_TRACE_ARGS 10 -#define MOD_NAME_LEN 4 - -#define HEX_SYNC_CHAR 0xFE -#define HEX_MOD_CHAR 0xFF -#define HEX_ESC_CHAR 0xFD - -#ifndef MIN -#define MIN(a,b) ((a) < (b) ? (a) : (b)) -#endif - -#define TBL_SIZE(tbl) (sizeof(tbl) / sizeof(tbl[0])) - -enum -{ - CMD_TYPE_TEXT = 0, - CMD_TYPE_HEX, - CMD_TYPE_BKREG, /* patch for BK_REG tool cmd. */ - CMD_TYPE_INVALID, -}; - -/* patch for BK_REG tool. */ -enum -{ - BKREG_WAIT_01 = 0, - BKREG_WAIT_E0, - BKREG_WAIT_FC, -}; - -typedef struct -{ - u8 rsp_buff[SHELL_RSP_BUF_LEN]; - bool_t rsp_ongoing; - - u8 cur_cmd_type; - u8 cmd_buff[SHELL_CMD_BUF_LEN]; - u8 cmd_data_len; - - /* patch for BK_REG tool. */ - /* added one state machine for BK_REG tool cmd. */ - u8 bkreg_state; - u8 bkreg_left_byte; - /* patch end. */ - - u8 assert_buff[SHELL_ASSERT_BUF_LEN]; - u8 assert_data_len; - - u8 log_level; - bool_t echo_enable; -} cmd_line_t; - -#define GET_BLOCK_ID(blocktag) ((blocktag) & 0xFF) -#define GET_QUEUE_ID(blocktag) (((blocktag) & 0x0F00) >> 8) -#define MAKE_BLOCK_TAG(blk_id, q_id) (((blk_id) & 0xFF) | (((q_id) & 0x0F) << 8) ) - -typedef struct -{ - u16 blk_tag; /* bit0~bit7: blk_id, bit8~bit11: queue_id; */ - u16 packet_len; -} tx_packet_t; - -typedef struct -{ - tx_packet_t packet_list[SHELL_LOG_PEND_NUM]; - u16 list_out_idx; - u16 list_in_idx; -} pending_queue_t; - -typedef struct -{ - u16 blk_list[SHELL_LOG_BUSY_NUM]; - u16 list_out_idx; - u16 list_in_idx; -} busy_queue_t; - -typedef struct -{ - u8 * const log_buf; - u16 * const blk_list; - const u16 blk_num; - const u16 blk_len; - u16 list_out_idx; - u16 list_in_idx; - u16 free_blk_num; - u32 empty_cnt; -} free_queue_t; - -#if CONFIG_ARCH_RISCV && !CONFIG_SLAVE_CORE -static __attribute__((section(".dtcm_sec_data "))) u8 shell_log_buff1[SHELL_LOG_BUF1_NUM * SHELL_LOG_BUF1_LEN]; -static __attribute__((section(".dtcm_sec_data "))) u8 shell_log_buff2[SHELL_LOG_BUF2_NUM * SHELL_LOG_BUF2_LEN]; -static __attribute__((section(".dtcm_sec_data "))) u8 shell_log_buff3[SHELL_LOG_BUF3_NUM * SHELL_LOG_BUF3_LEN]; -static __attribute__((section(".dtcm_sec_data "))) u16 buff1_free_list[SHELL_LOG_BUF1_NUM]; -static __attribute__((section(".dtcm_sec_data "))) u16 buff2_free_list[SHELL_LOG_BUF2_NUM]; -static __attribute__((section(".dtcm_sec_data "))) u16 buff3_free_list[SHELL_LOG_BUF3_NUM]; -#else -static u8 shell_log_buff1[SHELL_LOG_BUF1_NUM * SHELL_LOG_BUF1_LEN]; -static u8 shell_log_buff2[SHELL_LOG_BUF2_NUM * SHELL_LOG_BUF2_LEN]; -static u8 shell_log_buff3[SHELL_LOG_BUF3_NUM * SHELL_LOG_BUF3_LEN]; -static u16 buff1_free_list[SHELL_LOG_BUF1_NUM]; -static u16 buff2_free_list[SHELL_LOG_BUF2_NUM]; -static u16 buff3_free_list[SHELL_LOG_BUF3_NUM]; -#endif - -/* queue sort ascending in blk_len. */ -static free_queue_t free_queue[3] = - { - {.log_buf = shell_log_buff3, .blk_list = buff3_free_list, .blk_num = SHELL_LOG_BUF3_NUM, \ - .blk_len = SHELL_LOG_BUF3_LEN, .list_out_idx = 0, .list_in_idx = 0, \ - .free_blk_num = SHELL_LOG_BUF3_NUM, .empty_cnt = 0}, - - {.log_buf = shell_log_buff2, .blk_list = buff2_free_list, .blk_num = SHELL_LOG_BUF2_NUM, \ - .blk_len = SHELL_LOG_BUF2_LEN, .list_out_idx = 0, .list_in_idx = 0, \ - .free_blk_num = SHELL_LOG_BUF2_NUM, .empty_cnt = 0}, - - {.log_buf = shell_log_buff1, .blk_list = buff1_free_list, .blk_num = SHELL_LOG_BUF1_NUM, \ - .blk_len = SHELL_LOG_BUF1_LEN, .list_out_idx = 0, .list_in_idx = 0, \ - .free_blk_num = SHELL_LOG_BUF1_NUM, .empty_cnt = 0}, - }; - -static busy_queue_t log_busy_queue; -static pending_queue_t pending_queue; - -static cmd_line_t cmd_line_buf; - -#ifdef CONFIG_SLAVE_CORE -#if 1 -static shell_dev_t * log_dev = &shell_dev_mb; -static shell_dev_t * cmd_dev = &shell_dev_mb; -#else -static shell_dev_t * log_dev = &shell_uart3; -static shell_dev_t * cmd_dev = &shell_uart3; -#endif -static const char shell_fault_str[] = "\r\n!!CPU1:some LOGs discarded!!\r\n"; -static const u16 shell_fault_str_len = sizeof(shell_fault_str) - 1; -#else - -static shell_dev_t * log_dev = &shell_uart; -static shell_dev_t * cmd_dev = &shell_uart; - -#ifdef CONFIG_MASTER_CORE -static shell_dev_ipc_t * ipc_dev = &shell_dev_ipc; -static int shell_ipc_rx_indication(u16 cmd, u8 *data, u16 data_len); -#endif -static const char shell_fault_str[] = "\r\n!!some LOGs discarded!!\r\n"; -static const u16 shell_fault_str_len = sizeof(shell_fault_str) - 1; -#endif - -static const char shell_cmd_ovf_str[] = "\r\n!!some CMDs lost!!\r\n"; -static const u16 shell_cmd_ovf_str_len = sizeof(shell_cmd_ovf_str) - 1; - -static bool_t shell_init_ok = bFALSE; -static u8 fault_hint_print = 0; -static u32 shell_log_overflow = 0; -static u32 shell_log_count = 0; - -static beken_semaphore_t shell_semaphore; // will release from ISR. - - -static bool_t create_shell_event(void) -{ - rtos_init_semaphore(&shell_semaphore, 1); - - return bTRUE; -} - -static bool_t set_shell_event(u32 event_flag) -{ - (void)event_flag; - - rtos_set_semaphore(&shell_semaphore); - - return bTRUE; -} - -static u32 wait_any_event(u32 timeout) -{ - int result; - - result = rtos_get_semaphore(&shell_semaphore, timeout); - - if(result == kTimeoutErr) - return 0; - - return SHELL_EVENT_RX_IND; -} - -static void tx_req_process(void); - -#if 0 -static u16 get_free_buff_cnt(free_queue_t *free_q) -{ - u16 free_cnt; - - if(free_q->list_out_idx >= free_q->list_in_idx) - { - free_cnt = free_q->blk_num + free_q->list_in_idx - free_q->list_out_idx; - } - else - { - free_cnt = free_q->list_in_idx - free_q->list_out_idx; - } - - return free_cnt; /* should reserve 1 block. *//* (list_out_idx == list_in_idx) means all buf free. */ -} -#endif - -static u8 * alloc_log_blk(u16 log_len, u16 *blk_tag) -{ - u16 free_blk_id; - u8 queue_id; - free_queue_t * free_q; - u8 * blk_buf = NULL; - - //disable_interrupt(); // called from task context, use semaphore instead of locking interrupt. - //get_shell_mutex(); - u32 int_mask = rtos_disable_int(); - - for(queue_id = 0; queue_id < TBL_SIZE(free_queue); queue_id++) - { - free_q = &free_queue[queue_id]; - - /* queue ascending in blk_len. */ - if(free_q->blk_len < log_len) - continue; - - if(/*get_free_buff_cnt(free_q) */ free_q->free_blk_num > 0) - { - free_blk_id = free_q->blk_list[free_q->list_out_idx]; - free_q->list_out_idx = (free_q->list_out_idx + 1) % free_q->blk_num; - free_q->free_blk_num--; - - blk_buf = &free_q->log_buf[free_blk_id * free_q->blk_len]; - *blk_tag = MAKE_BLOCK_TAG(free_blk_id, queue_id); - - break; - } - else - { - free_q->empty_cnt++; - } - } - - if(blk_buf == NULL) - { - shell_log_overflow++; - } - else - { - fault_hint_print = 0; - shell_log_count++; - } - - //enable_interrupt(); // called from task context, use semaphore instead of locking interrupt. - //release_shell_mutex(); - rtos_enable_int(int_mask); - - return blk_buf; -} - -static bool_t free_log_blk(u16 block_tag) -{ - u8 queue_id = GET_QUEUE_ID(block_tag); - u16 blk_id = GET_BLOCK_ID(block_tag); - free_queue_t *free_q; - - if(queue_id >= TBL_SIZE(free_queue)) - return bFALSE; - - free_q = &free_queue[queue_id]; - - if(blk_id >= free_q->blk_num) - return bFALSE; - - //disable_interrupt(); // called from tx-complete only, don't lock interrupt. - - free_q->blk_list[free_q->list_in_idx] = blk_id; - free_q->list_in_idx = (free_q->list_in_idx + 1) % free_q->blk_num; - free_q->free_blk_num++; - - //enable_interrupt(); // called from tx-complete only, don't lock interrupt. - - return bTRUE; -} - -static void push_pending_queue(u16 blk_tag, u16 data_len) -{ - //get_shell_mutex(); - - pending_queue.packet_list[pending_queue.list_in_idx].blk_tag = blk_tag; - pending_queue.packet_list[pending_queue.list_in_idx].packet_len = data_len; - - pending_queue.list_in_idx = (pending_queue.list_in_idx + 1) % SHELL_LOG_PEND_NUM; - - //release_shell_mutex(); - - return; -} - -static void pull_pending_queue(u16 *blk_tag, u16 *data_len) -{ - *blk_tag = pending_queue.packet_list[pending_queue.list_out_idx].blk_tag; - *data_len = pending_queue.packet_list[pending_queue.list_out_idx].packet_len; - - pending_queue.list_out_idx = (pending_queue.list_out_idx + 1) % SHELL_LOG_PEND_NUM; - - return; -} - -int shell_assert_out(bool bContinue, char * format, ...); - -/* call from TX ISR. */ -static void shell_tx_complete(u8 *pbuf, u16 buf_tag) -{ - u16 block_tag; - u8 queue_id = GET_QUEUE_ID(buf_tag); - u16 blk_id = GET_BLOCK_ID(buf_tag); - free_queue_t *free_q; - - /* rsp ok ?? */ - if( queue_id == SHELL_RSP_QUEUE_ID ) /* rsp. */ - { - /* it is called from cmd_dev tx ISR. */ - - if ( (pbuf != cmd_line_buf.rsp_buff) || (blk_id != 0) || - ( !cmd_line_buf.rsp_ongoing ) ) - { - /* something wrong!!! */ - shell_assert_out(bTRUE, "FAULT: in rsp.\r\n"); - } - - cmd_line_buf.rsp_ongoing = bFALSE; /* rsp compelete, rsp_buff can be used for next cmd/response. */ - - //set_shell_event(SHELL_EVENT_TX_REQ); // notify shell task to process the log tx. - tx_req_process(); - - return; - } - - if( queue_id == SHELL_ROM_QUEUE_ID ) /* fault hints buffer, point to flash. */ - { - /* it is called from log_dev/cmd_dev tx ISR. */ - - if ( (blk_id == 0) && (pbuf == (u8 *)shell_fault_str) ) - { - } - else if ( (blk_id == 1) && (pbuf == (u8 *)shell_cmd_ovf_str) ) - { - } - else - { - /* something wrong!!! */ - shell_assert_out(bTRUE, "FATAL:t-%x,p-%x\r\n", buf_tag, pbuf); - } - - //set_shell_event(SHELL_EVENT_TX_REQ); // notify shell task to process the log tx. - tx_req_process(); - - return; - } - - if (queue_id < TBL_SIZE(free_queue)) /* from log busy queue. */ - { - /* it is called from log_dev tx ISR. */ - - free_q = &free_queue[queue_id]; - - block_tag = log_busy_queue.blk_list[log_busy_queue.list_out_idx]; - - if( ( buf_tag != block_tag ) || (blk_id >= free_q->blk_num) || - ( (&free_q->log_buf[blk_id * free_q->blk_len]) != pbuf) ) - { - /* something wrong!!! */ - /* FAULT !!!! */ - shell_assert_out(bTRUE, "FATAL:%x,%x\r\n", buf_tag, block_tag); - - return; - } - - /* de-queue from busy queue. */ - log_busy_queue.list_out_idx = (log_busy_queue.list_out_idx + 1) % SHELL_LOG_BUSY_NUM; - - /* free buffer to queue. */ - free_log_blk(block_tag); - - //set_shell_event(SHELL_EVENT_TX_REQ); // notify shell task to process the log tx. - tx_req_process(); - - return; - } - - /* FAULT !!!! */ - shell_assert_out(bTRUE, "FATAL:%x,\r\n", buf_tag); - - return; -} - -/* call from RX ISR. */ -static void shell_rx_indicate(void) -{ - set_shell_event(SHELL_EVENT_RX_IND); - - return; -} - -static u16 append_link_data_byte(u8 * link_buf, u16 buf_len, u8 * data_ptr, u16 data_len) -{ - u16 cnt = 0, i; - - for(i = 0; i < data_len; i++) - { - if( (*data_ptr == HEX_SYNC_CHAR) || - (*data_ptr == HEX_ESC_CHAR) ) - { - if(cnt < (buf_len - 1)) - { - link_buf[cnt] = HEX_ESC_CHAR; - cnt++; - link_buf[cnt] = (*data_ptr) ^ HEX_MOD_CHAR; - cnt++; - } - } - else - { - if(cnt < buf_len) - { - link_buf[cnt] = (*data_ptr); - cnt++; - } - } - - data_ptr++; - } - - return cnt; -} - -static bool_t echo_out(u8 * echo_str, u16 len) -{ - u16 wr_cnt; - - if(len == 0) - return bTRUE; - - wr_cnt = cmd_dev->dev_drv->write_echo(cmd_dev, echo_str, len); - - return (wr_cnt == len); -} - -/* NOTICE: this can only be called by shell task internally (cmd handler). */ -/* it is not re-enterance function. */ -static bool_t rsp_out(u8 * rsp_msg, u16 msg_len) -{ - u16 rsp_blk_tag = MAKE_BLOCK_TAG(0, SHELL_RSP_QUEUE_ID); - - if(rsp_msg != cmd_line_buf.rsp_buff) - { - if(msg_len > sizeof(cmd_line_buf.rsp_buff)) - { - msg_len = sizeof(cmd_line_buf.rsp_buff);; - } - - memcpy(cmd_line_buf.rsp_buff, rsp_msg, msg_len); - } - - if(log_dev != cmd_dev) - { - // set TRUE, then call driver, in case TX_COMPLETE_ISR will happen before set TRUE. - cmd_line_buf.rsp_ongoing = bTRUE; // one by one for cmd handler. - - /* dedicated device for cmd/response, don't enqueue the msg to pending queue. */ - /* send to cmd dev directly. */ - cmd_dev->dev_drv->write_async(cmd_dev, cmd_line_buf.rsp_buff, msg_len, rsp_blk_tag); - } - else - { - /* shared device for response & log, push the rsp msg to pending queue. */ - - u32 int_mask = rtos_disable_int(); - - cmd_line_buf.rsp_ongoing = bTRUE; // one by one for cmd handler. set to true before trigger the TX. - - push_pending_queue(rsp_blk_tag, msg_len); - - //set_shell_event(SHELL_EVENT_TX_REQ); // notify shell task to process the log tx. - tx_req_process(); - - rtos_enable_int(int_mask); - } - - return bTRUE; -} - -static bool_t cmd_hint_out(void) -{ - u16 hint_blk_tag = MAKE_BLOCK_TAG(1, SHELL_ROM_QUEUE_ID); - - if(log_dev != cmd_dev) - { - /* dedicated device for cmd_hint, don't enqueue the msg to pending queue. */ - /* send to cmd dev directly. */ - cmd_dev->dev_drv->write_async(cmd_dev, (u8 *)shell_cmd_ovf_str, shell_cmd_ovf_str_len, hint_blk_tag); - } - else - { - /* shared device for response & log, push the cmd_hint msg to pending queue. */ - - u32 int_mask = rtos_disable_int(); - - push_pending_queue(hint_blk_tag, shell_fault_str_len); - - //set_shell_event(SHELL_EVENT_TX_REQ); // notify shell task to process the log tx. - tx_req_process(); - - rtos_enable_int(int_mask); - } - - return bTRUE; -} - -static bool_t log_hint_out(void) -{ - if(fault_hint_print) /* sent one hint since last allocation fail.*/ - return bTRUE; - - u16 hint_blk_tag = MAKE_BLOCK_TAG(0, SHELL_ROM_QUEUE_ID); - - u32 int_mask = rtos_disable_int(); - - push_pending_queue(hint_blk_tag, shell_fault_str_len); - - //set_shell_event(SHELL_EVENT_TX_REQ); // notify shell task to process the log tx. - tx_req_process(); - - fault_hint_print = 1; - - rtos_enable_int(int_mask); - - return bTRUE; -} - -/* call this in !* DISABLE *! interrupt context. */ -static void tx_req_process(void) -{ - u8 *packet_buf = NULL; - u16 block_tag; - u16 log_len; - u16 tx_ready; - u16 blk_id; - u8 queue_id; - free_queue_t *free_q; - - /* maybe tx_req is from tx_complete_callback, check if there any log in queue. */ - if(pending_queue.list_out_idx == pending_queue.list_in_idx) /* queue empty! */ - return; - - tx_ready = 0; - - log_dev->dev_drv->io_ctrl(log_dev, SHELL_IO_CTRL_GET_STATUS, &tx_ready); - - if(tx_ready == 0) - return; - - /** ==== POP from pending queue ==== **/ - pull_pending_queue(&block_tag, &log_len); - - queue_id = GET_QUEUE_ID(block_tag); - blk_id = GET_BLOCK_ID(block_tag); - - if (queue_id < TBL_SIZE(free_queue)) - { - free_q = &free_queue[queue_id]; - - if(blk_id < free_q->blk_num) - { - packet_buf = &free_q->log_buf[blk_id * free_q->blk_len]; - } - } - else if(queue_id == SHELL_RSP_QUEUE_ID) - { - packet_buf = cmd_line_buf.rsp_buff; - - if((cmd_line_buf.rsp_ongoing == bFALSE) || (log_dev != cmd_dev) || (blk_id != 0)) - { - shell_assert_out(bTRUE, "xFATAL: in Tx_req\r\n"); - /* FAULT !!!! */ - /* if log_dev is not the same with cmd_dev, - * rsp will not be pushed into pending queue. - */ - } - } - else if(queue_id == SHELL_ROM_QUEUE_ID) - { - if(blk_id == 0) - { - packet_buf = (u8 *)shell_fault_str; - } - else if(blk_id == 1) - { - packet_buf = (u8 *)shell_cmd_ovf_str; - if(log_dev != cmd_dev) - { - shell_assert_out(bTRUE, "xFATAL: in Tx_req id=%x\r\n", blk_id); - /* FAULT !!!! */ - /* if log_dev is not the same with cmd_dev, - * cmd_hint will not be pushed into pending queue. - */ - } - } - else - { - /* FAULT !!!! */ - shell_assert_out(bTRUE, "xFATAL: in Tx_req id=%x\r\n", blk_id); - } - } - else - { - /* FAULT !!!! */ - shell_assert_out(bTRUE, "xFATAL: in Tx_req %x.\r\n", block_tag); - } - - if(packet_buf == NULL) - return; - - /* rom & rsp buff not enter busy-queue. */ - if(queue_id < TBL_SIZE(free_queue)) - { - log_busy_queue.blk_list[log_busy_queue.list_in_idx] = block_tag; - log_busy_queue.list_in_idx = (log_busy_queue.list_in_idx + 1) % SHELL_LOG_BUSY_NUM; - } - - log_dev->dev_drv->write_async(log_dev, packet_buf, log_len, block_tag); /* send to log dev driver. */ - /* if driver return 0, should free log-block or not de-queue pending queue and try again. */ - /* if return 1, push log-block into busy queue is OK. */ - - return; -} - -int shell_trace_out( u32 trace_id, ... ); -int shell_spy_out( u16 spy_id, u8 * data_buf, u16 data_len); - -static void rx_ind_process(void) -{ - u16 read_cnt, buf_len, echo_len; - u16 i = 0; - bool_t cmd_rx_done = bFALSE, need_backspace = bFALSE; - - if(cmd_line_buf.rsp_ongoing) - { - /* previous cmd not complete, inform itself to handle it later. */ - set_shell_event(SHELL_EVENT_RX_IND); - - rtos_delay_milliseconds(100); /* delay 100ms, wait cmd to be completed. */ - - return; - } - - /* cmd_line_buf.rsp_buff is free, can be used for read buff temporarily */ - - if(cmd_dev->dev_type == SHELL_DEV_MAILBOX) - { - buf_len = MIN(SHELL_CMD_BUF_LEN, SHELL_RSP_BUF_LEN); - } - else /* if(cmd_dev->dev_type == SHELL_DEV_UART) */ - { - buf_len = 1; /* for UART device, read one by one. */ - } - - while(bTRUE) - { - u8 * rx_temp_buff = &cmd_line_buf.rsp_buff[0]; - - read_cnt = cmd_dev->dev_drv->read(cmd_dev, rx_temp_buff, buf_len); - - echo_len = 0; - - for(i = 0; i < read_cnt; i++) - { - if(cmd_line_buf.cur_cmd_type == CMD_TYPE_INVALID) - { - #if 0 - if(rx_temp_buff[i] == HEX_SYNC_CHAR) // SYNC_CHAR, hex frame start. - { - cmd_line_buf.cur_cmd_type = CMD_TYPE_HEX; - - cmd_line_buf.cmd_data_len = 0; - cmd_line_buf.cmd_buff[cmd_line_buf.cmd_data_len] = HEX_SYNC_CHAR; - cmd_line_buf.cmd_data_len++; - - continue; - } - #endif - - echo_len++; /* SYNC_CHAR not echo. */ - - if((rx_temp_buff[i] >= 0x20) && (rx_temp_buff[i] < 0x7f)) - { - cmd_line_buf.cur_cmd_type = CMD_TYPE_TEXT; - - cmd_line_buf.cmd_data_len = 0; - cmd_line_buf.cmd_buff[cmd_line_buf.cmd_data_len] = rx_temp_buff[i]; - cmd_line_buf.cmd_data_len++; - - continue; - } - - /* patch for BK_REG tool. */ - if(cmd_line_buf.bkreg_state == BKREG_WAIT_01) - { - if(rx_temp_buff[i] == 0x01) - cmd_line_buf.bkreg_state = BKREG_WAIT_E0; - } - else if(cmd_line_buf.bkreg_state == BKREG_WAIT_E0) - { - if(rx_temp_buff[i] == 0xE0) - cmd_line_buf.bkreg_state = BKREG_WAIT_FC; - else if(rx_temp_buff[i] != 0x01) - cmd_line_buf.bkreg_state = BKREG_WAIT_01; - } - else if(cmd_line_buf.bkreg_state == BKREG_WAIT_FC) - { - if(rx_temp_buff[i] == 0xFC) - { - cmd_line_buf.cur_cmd_type = CMD_TYPE_BKREG; - - cmd_line_buf.cmd_buff[0] = 0x01; - cmd_line_buf.cmd_buff[1] = 0xE0; - cmd_line_buf.cmd_buff[2] = 0xFC; - - cmd_line_buf.cmd_data_len = 3; - - echo_len = 0; // cann't echo anything. - - continue; - } - else if(rx_temp_buff[i] != 0x01) - cmd_line_buf.bkreg_state = BKREG_WAIT_01; - else - cmd_line_buf.bkreg_state = BKREG_WAIT_E0; - } - - } - - #if 0 - if(cmd_line_buf.cur_cmd_type == CMD_TYPE_HEX) - { - if(cmd_line_buf.cmd_data_len < sizeof(cmd_line_buf.cmd_buff)) - { - cmd_line_buf.cmd_buff[cmd_line_buf.cmd_data_len] = rx_temp_buff[i]; - cmd_line_buf.cmd_data_len++; - } - - if(rx_temp_buff[i] == HEX_SYNC_CHAR) // SYNC_CHAR, hex frame end. - { - cmd_line_buf.cmd_buff[cmd_line_buf.cmd_data_len - 1] = HEX_SYNC_CHAR; // in case cmd_data_len overflow. - cmd_rx_done = bTRUE; - break; - } - } - #endif - - if(cmd_line_buf.cur_cmd_type == CMD_TYPE_TEXT) - { - echo_len++; - if(rx_temp_buff[i] == '\b') - { - if(cmd_line_buf.cmd_data_len > 0) - { - cmd_line_buf.cmd_data_len--; - - if(cmd_line_buf.cmd_data_len == 0) - need_backspace = bTRUE; - } - } - else if((rx_temp_buff[i] == '\n') || (rx_temp_buff[i] == '\r')) - { - if(cmd_line_buf.cmd_data_len < sizeof(cmd_line_buf.cmd_buff)) - { - cmd_line_buf.cmd_buff[cmd_line_buf.cmd_data_len] = 0; - } - else - { - cmd_line_buf.cmd_buff[cmd_line_buf.cmd_data_len - 1] = 0; // in case cmd_data_len overflow. - } - - cmd_rx_done = bTRUE; - break; - } - else if((rx_temp_buff[i] >= 0x20)) - { - if(cmd_line_buf.cmd_data_len < sizeof(cmd_line_buf.cmd_buff)) - { - cmd_line_buf.cmd_buff[cmd_line_buf.cmd_data_len] = rx_temp_buff[i]; - cmd_line_buf.cmd_data_len++; - } - } - - } - - /* patch for BK_REG tool. */ - if(cmd_line_buf.cur_cmd_type == CMD_TYPE_BKREG) - { - echo_len = 0; // cann't echo anything. - - /* p[0] = 0x1, p[1]=0xe0, p[2]=0xfc, p[3]=len. */ - if(cmd_line_buf.cmd_data_len == 3) - { - cmd_line_buf.bkreg_left_byte = rx_temp_buff[i] + 1; // +1, because will -1 in next process. - - if((cmd_line_buf.bkreg_left_byte + 3) >= sizeof(cmd_line_buf.cmd_buff)) // 3 bytes of header + 1 byte of len. - { - cmd_line_buf.cmd_data_len = 0; - - cmd_rx_done = bTRUE; - break; - } - } - - if(cmd_line_buf.cmd_data_len < sizeof(cmd_line_buf.cmd_buff)) - { - cmd_line_buf.cmd_buff[cmd_line_buf.cmd_data_len] = rx_temp_buff[i]; - cmd_line_buf.cmd_data_len++; - } - - cmd_line_buf.bkreg_left_byte--; - - if(cmd_line_buf.bkreg_left_byte == 0) - { - cmd_rx_done = bTRUE; - break; - } - } - } - - if( cmd_rx_done ) - { - /* patch for BK_REG tool. */ - if(cmd_line_buf.cur_cmd_type == CMD_TYPE_BKREG) - { - break; // cann't echo anything. - } - - if(cmd_line_buf.echo_enable) - { - echo_out(&rx_temp_buff[0], echo_len); - echo_out((u8 *)"\r\n", 2); - } - - break; - } - else - { - /* patch for BK_REG tool. */ - if( (cmd_line_buf.cur_cmd_type == CMD_TYPE_BKREG) || - ((cmd_line_buf.cur_cmd_type == CMD_TYPE_INVALID) && (cmd_line_buf.bkreg_state != BKREG_WAIT_01)) ) - { - // cann't echo anything. - } - else if(cmd_line_buf.echo_enable) - { - if(echo_len > 0) - { - if( (rx_temp_buff[echo_len - 1] == '\b') || - (rx_temp_buff[echo_len - 1] == 0x7f) ) /* DEL */ - { - echo_len--; - if((cmd_line_buf.cmd_data_len > 0) || need_backspace) - echo_out((u8 *)"\b \b", 3); - } - - u8 cr_lf = 0; - - if(echo_len == 1) - { - if( (rx_temp_buff[echo_len - 1] == '\r') || - (rx_temp_buff[echo_len - 1] == '\n') ) - { - cr_lf = 1; - } - } - else if(echo_len == 2) - { - if( (memcmp(rx_temp_buff, "\r\n", 2) == 0) || - (memcmp(rx_temp_buff, "\n\r", 2) == 0) ) - { - cr_lf = 1; - } - } - - if(cr_lf != 0) - { - echo_out((u8 *)"\r\n#", sizeof("\r\n#") - 1); - echo_len = 0; - } - } - echo_out(rx_temp_buff, echo_len); - } - } - - if(read_cnt < buf_len) /* all data are read out. */ - break; - } - - if(read_cnt < buf_len) /* all data are read out. */ - { - } - else /* cmd pends in buffer, handle it in new loop cycle. */ - { - set_shell_event(SHELL_EVENT_RX_IND); - } - - /* can re-use *buf_len*. */ - if( cmd_rx_done ) - { - #if 0 - if(cmd_line_buf.cur_cmd_type == CMD_TYPE_HEX) - { - #if 1 /* it's test code. */ - buf_len = sprintf((char *)&cmd_line_buf.rsp_buff[0], "\r\nHex count: %d, ", cmd_line_buf.cmd_data_len); - buf_len += sprintf((char *)&cmd_line_buf.rsp_buff[buf_len], "Hdr: %x, Tail: %x.\r\n", \ - cmd_line_buf.cmd_buff[0], cmd_line_buf.cmd_buff[cmd_line_buf.cmd_data_len - 1]); - - for(i = 1; (i < cmd_line_buf.cmd_data_len) && (i < 18); i++) - { - buf_len += sprintf((char *)&cmd_line_buf.rsp_buff[buf_len], "%x ", cmd_line_buf.cmd_buff[i]); - } - - strcpy((char *)&cmd_line_buf.rsp_buff[buf_len], "\r\n#"); - rsp_out(cmd_line_buf.rsp_buff, strlen((char *)cmd_line_buf.rsp_buff)); - - shell_trace_out(0x39, 8, cmd_line_buf.cmd_buff[0], cmd_line_buf.cmd_buff[1], cmd_line_buf.cmd_buff[2], cmd_line_buf.cmd_buff[3], \ - cmd_line_buf.cmd_buff[4], cmd_line_buf.cmd_buff[5], cmd_line_buf.cmd_buff[6], cmd_line_buf.cmd_buff[7]); - shell_spy_out(0x40, cmd_line_buf.cmd_buff, 9); - - #endif - } - #endif - - if(cmd_line_buf.cur_cmd_type == CMD_TYPE_TEXT) - { - u16 rx_ovf = 0; - cmd_dev->dev_drv->io_ctrl(cmd_dev, SHELL_IO_CTRL_GET_RX_STATUS, &rx_ovf); - - if(rx_ovf != 0) - { - cmd_hint_out(); - } - - cmd_line_buf.rsp_buff[0] = 0; - /* handle command. */ - if( cmd_line_buf.cmd_data_len > 0 ) - handle_shell_input( (char *)cmd_line_buf.cmd_buff, cmd_line_buf.cmd_data_len, (char *)cmd_line_buf.rsp_buff, sizeof(cmd_line_buf.rsp_buff) ); - - cmd_line_buf.rsp_buff[SHELL_RSP_BUF_LEN - 4] = 0; - - buf_len = strlen((char *)cmd_line_buf.rsp_buff); - if(buf_len > (SHELL_RSP_BUF_LEN - 4)) - buf_len = (SHELL_RSP_BUF_LEN - 4); - buf_len += sprintf((char *)&cmd_line_buf.rsp_buff[buf_len], "\r\n#"); - - rsp_out(cmd_line_buf.rsp_buff, buf_len); - } - - /* patch for BK_REG tool. */ - if(cmd_line_buf.cur_cmd_type == CMD_TYPE_BKREG) - { - if(cmd_line_buf.cmd_data_len > 3) - { -#if CONFIG_BKREG - extern int bkreg_run_command(const char *cmd, int flag); - - bkreg_run_command((const char *)&cmd_line_buf.cmd_buff[0], (int)cmd_line_buf.cmd_data_len); -#endif // CONFIG_BKREG - } - } - - cmd_line_buf.cur_cmd_type = CMD_TYPE_INVALID; /* reset cmd line to interpret new cmd. */ - cmd_line_buf.cmd_data_len = 0; - cmd_line_buf.bkreg_state = BKREG_WAIT_01; /* reset state machine. */ - } - - return; -} - -static void shell_task_init(void) -{ - u16 i; - - for(i = 0; i < SHELL_LOG_BUF1_NUM; i++) - { - buff1_free_list[i] = i; - } - for(i = 0; i < SHELL_LOG_BUF2_NUM; i++) - { - buff2_free_list[i] = i; - } - for(i = 0; i < SHELL_LOG_BUF3_NUM; i++) - { - buff3_free_list[i] = i; - } - - memset(&log_busy_queue, 0, sizeof(log_busy_queue)); - memset(&pending_queue, 0, sizeof(pending_queue)); - - cmd_line_buf.rsp_ongoing = bFALSE; - cmd_line_buf.cur_cmd_type = CMD_TYPE_INVALID; - cmd_line_buf.cmd_data_len = 0; - cmd_line_buf.bkreg_state = BKREG_WAIT_01; - cmd_line_buf.assert_data_len = 0; - cmd_line_buf.log_level = LOG_LEVEL; - cmd_line_buf.echo_enable = bTRUE; - - create_shell_event(); - - cmd_dev->dev_drv->init(cmd_dev); - cmd_dev->dev_drv->open(cmd_dev, shell_tx_complete, shell_rx_indicate); - - if(log_dev != cmd_dev) - { - log_dev->dev_drv->init(log_dev); - log_dev->dev_drv->open(log_dev, shell_tx_complete, NULL); - } - - #ifdef CONFIG_MASTER_CORE - ipc_dev->dev_drv->init(ipc_dev); - ipc_dev->dev_drv->open(ipc_dev, (shell_ipc_rx_t)shell_ipc_rx_indication); /* register rx-callback to copy log data to buffer. */ - #endif - - shell_init_ok = bTRUE; - -} - -void shell_task( void *para ) -{ - u32 Events; - - shell_task_init(); - - echo_out((u8 *)"\r\n#", sizeof("\r\n#") - 1); - - while(bTRUE) - { - Events = wait_any_event(SHELL_TASK_DEF_TICK); // WAIT_EVENT; - - if(Events & SHELL_EVENT_TX_REQ) - { - echo_out((u8 *)"Unsolicited\r\n#", sizeof("Unsolicited\r\n#") - 1); - } - - if(Events & SHELL_EVENT_RX_IND) - { - rx_ind_process(); - } - } -} - -__bk_weak int shell_log_check(u8 level, char *mod_name) -{ - if(level > cmd_line_buf.log_level) - return 0; //bFALSE; - - return 1;// bTRUE; -} - -int shell_log_out_direct(const char *format, va_list ap) -{ - u32 int_mask; - char *pbuf; - u16 data_len, buf_len; - va_list arg_list; - - pbuf = (char *)&cmd_line_buf.assert_buff[0]; - buf_len = sizeof(cmd_line_buf.assert_buff); - - int_mask = rtos_disable_int(); - - va_copy(arg_list, ap); - data_len = vsnprintf( pbuf, buf_len -1, format, arg_list ); - va_end( arg_list ); - - if ( (data_len != 0) && (pbuf[data_len - 1] == '\n') ) - { - if (data_len == 1 || pbuf[data_len - 2] != '\r') - { - pbuf[data_len] = '\n'; - pbuf[data_len - 1] = '\r'; - data_len++; - } - } - - log_dev->dev_drv->write_sync(log_dev, (u8 *)pbuf, data_len); - - rtos_enable_int(int_mask); - - return 1; -} - -int shell_log_raw_data(const u8 *data, u16 data_len) -{ - u8 *packet_buf; - u16 free_blk_tag; - - if (!shell_init_ok) - { - return 0; // bFALSE; - } - - if (NULL == data || 0 == data_len) - { - return 0; // bFALSE; - } - - packet_buf = alloc_log_blk(data_len, &free_blk_tag); - - if (NULL == packet_buf) - { - log_hint_out(); - return 0; // bFALSE; - } - - memcpy(packet_buf, data, data_len); - - u32 int_mask = rtos_disable_int(); - - // push to pending queue. - push_pending_queue(free_blk_tag, data_len); - - // notify shell task to process the log tx. - tx_req_process(); - - rtos_enable_int(int_mask); - - return 1; // bTRUE; -} - -void shell_log_out_port(int level, char *mod_name, const char *format, va_list ap) -{ - u8 * packet_buf; - u16 free_blk_tag; - u16 log_len = 0, buf_len; - va_list arg_list; - - if( !shell_init_ok ) - { - cmd_line_buf.log_level = LOG_LEVEL; // if not intialized, set log_level temporarily here. !!!patch!!! - shell_log_out_direct(format, ap); - return ; // bFALSE; - } - - if(shell_log_check(level, mod_name) == 0)//bFALSE) - { - return ; // bFALSE; - } - - va_copy(arg_list, ap); - buf_len = vsnprintf( NULL, 0, format, arg_list ) + 1; - va_end( arg_list ); - - if(mod_name != NULL) - buf_len += MOD_NAME_LEN + 2; - - packet_buf = alloc_log_blk(buf_len, &free_blk_tag); - - if(packet_buf == NULL) - { - log_hint_out(); - return ; // bFALSE; - } - - log_len = 0; - - if(mod_name != NULL) - { - memcpy(&packet_buf[0], mod_name, MOD_NAME_LEN); - packet_buf[MOD_NAME_LEN] = 0; - log_len = strlen((char *)packet_buf); // log_len <= MOD_NAME_LEN; - packet_buf[log_len] = ':'; - log_len++; - packet_buf[log_len] = 0; - } - - log_len += vsnprintf( (char *)&packet_buf[log_len], buf_len - log_len, format, ap ); - if ( (log_len != 0) && (packet_buf[log_len - 1] == '\n') ) - { - if (log_len == 1 || packet_buf[log_len - 2] != '\r') - { - packet_buf[log_len] = '\n'; - packet_buf[log_len - 1] = '\r'; - log_len++; - } - } - - u32 int_mask = rtos_disable_int(); - - // push to pending queue. - push_pending_queue(free_blk_tag, log_len); - - //set_shell_event(SHELL_EVENT_TX_REQ); // notify shell task to process the log tx. - tx_req_process(); - - rtos_enable_int(int_mask); - - return ; // bTRUE;; -} - -int shell_log_out(u8 level, char *mod_name, const char *format, ...) -{ - va_list arg_list; - - if ( !shell_init_ok ) - return 0; // bFALSE; - - if (shell_log_check(level, mod_name) == 0) - { - return 0; // bFALSE; - } - - va_start(arg_list, format); - shell_log_out_port(level, mod_name, format, arg_list); - va_end(arg_list); - - return 1; // bTRUE;; -} - -int shell_trace_out( u32 trace_id, ... ) -{ - u8 * packet_buf; - u16 free_blk_tag; - u16 trace_len = 0, buf_len; - - va_list arg_list; - u32 arg_num, i, temp; - - if( !shell_init_ok ) - return 0; //bFALSE; - - /* init variable length argument list */ - va_start( arg_list, trace_id ); - arg_num = ( u32 ) va_arg( arg_list, u32 ); - /* clean up variable argument pointer */ - va_end( arg_list ); - - if(arg_num > MAX_TRACE_ARGS) - arg_num = MAX_TRACE_ARGS; - - arg_num++; /* one u32 for system time. */ - - /* treat trace_id as u16 type. */ - - buf_len = (sizeof(u16) + arg_num * sizeof(u32)) * 2 + 2; /* +2 for hdr&tail, *2 for the worst case of escape every byte. */ - - packet_buf = alloc_log_blk(buf_len, &free_blk_tag); - - if(packet_buf == NULL) - { - log_hint_out(); - return 0; // bFALSE; - } - - packet_buf[0] = HEX_SYNC_CHAR; - trace_len = 1; - trace_len += append_link_data_byte(&packet_buf[trace_len], buf_len - trace_len, (u8 *)&trace_id, sizeof(u16)); - - temp = rtos_get_time(); - trace_len += append_link_data_byte(&packet_buf[trace_len], buf_len - trace_len, (u8 *)&temp, sizeof(u32)); - - /* init variable length argument list */ - va_start( arg_list, trace_id ); - arg_num = ( u32 ) va_arg( arg_list, u32 ); - - for (i = 0; (i < arg_num) && (i < MAX_TRACE_ARGS); i++) - { - temp = ( u32 ) va_arg( arg_list, u32 ); - trace_len += append_link_data_byte(&packet_buf[trace_len], buf_len - trace_len, (u8 *)&temp, sizeof(u32)); - } - - packet_buf[trace_len] = HEX_SYNC_CHAR; - trace_len++; - - /* clean up variable argument pointer */ - va_end( arg_list ); - - u32 int_mask = rtos_disable_int(); - - // push to pending queue. - push_pending_queue(free_blk_tag, trace_len); - - //set_shell_event(SHELL_EVENT_TX_REQ); // notify shell task to process the log tx. - tx_req_process(); - - rtos_enable_int(int_mask); - - return 1;//bTRUE;; -} - -int shell_spy_out( u16 spy_id, u8 * data_buf, u16 data_len) -{ - u8 * packet_buf; - u16 free_blk_tag; - u16 spy_len = 0, buf_len; - - u32 temp; - - if( !shell_init_ok ) - return 0; //bFALSE; - - buf_len = (sizeof(u16) + sizeof(u32) + data_len) * 2 + 2; /* +2 for hdr&tail, *2 for the worst case of escape every byte. */ - - packet_buf = alloc_log_blk(buf_len, &free_blk_tag); - - if(packet_buf == NULL) - { - log_hint_out(); - return 0; // bFALSE; - } - - packet_buf[0] = HEX_SYNC_CHAR; - spy_len = 1; - spy_len += append_link_data_byte(&packet_buf[spy_len], buf_len - spy_len, (u8 *)&spy_id, sizeof(u16)); - - temp = rtos_get_time(); - spy_len += append_link_data_byte(&packet_buf[spy_len], buf_len - spy_len, (u8 *)&temp, sizeof(u32)); - - spy_len += append_link_data_byte(&packet_buf[spy_len], buf_len - spy_len, data_buf, data_len); - - packet_buf[spy_len] = HEX_SYNC_CHAR; - spy_len++; - - u32 int_mask = rtos_disable_int(); - - // push to pending queue. - push_pending_queue(free_blk_tag, spy_len); - - //set_shell_event(SHELL_EVENT_TX_REQ); // notify shell task to process the log tx. - tx_req_process(); - - rtos_enable_int(int_mask); - - return 1;//bTRUE;; -} - -int shell_assert_out(bool bContinue, char * format, ...) -{ - u32 int_mask; - char *pbuf; - u16 data_len, buf_len; - va_list arg_list; - - pbuf = (char *)&cmd_line_buf.assert_buff[0]; - buf_len = sizeof(cmd_line_buf.assert_buff); - - int_mask = rtos_disable_int(); - - va_start( arg_list, format ); - - data_len = vsnprintf( pbuf, buf_len - 1, format, arg_list ); - - va_end( arg_list ); - - log_dev->dev_drv->write_sync(log_dev, (u8 *)pbuf, data_len); - - if( bContinue ) - { - rtos_enable_int(int_mask); - } - else - { - while(bTRUE) - { - } - } - - return 1;//bTRUE;; - -} - -int shell_assert_raw(bool bContinue, char * data_buff, u16 data_len) -{ - u32 int_mask; - - int_mask = rtos_disable_int(); - - log_dev->dev_drv->write_sync(log_dev, (u8 *)data_buff, data_len); - - if( bContinue ) - { - rtos_enable_int(int_mask); - } - else - { - while(1) - { - } - } - - return 1;//bTRUE;; - -} - -#ifdef CONFIG_MASTER_CORE -static int shell_ipc_rx_indication(u16 cmd, u8 *data, u16 data_len) -{ - if(cmd == MB_CMD_LOG_OUT) - { - return shell_log_raw_data(data, data_len); - } - - if(cmd == MB_CMD_ASSERT_OUT) - { - return shell_assert_raw(true, (char *)data, data_len); - } - - /* no cmd handler. */ - return 0; -} - -int shell_cmd_forward(char *cmd, u16 cmd_len) -{ - ipc_dev->dev_drv->write_sync(ipc_dev, (u8 *)cmd, cmd_len); - - return 1;//bTRUE; -} -#endif - -void shell_echo_set(int en_flag) -{ - if(en_flag != 0) - cmd_line_buf.echo_enable = bTRUE; - else - cmd_line_buf.echo_enable = bFALSE; -} - -int shell_echo_get(void) -{ - if(cmd_line_buf.echo_enable) - return 1; - - return 0; -} - -void shell_set_log_level(int level) -{ - cmd_line_buf.log_level = level; -} - -int shell_get_log_level(void) -{ - return cmd_line_buf.log_level; -} - -int shell_get_log_statist(u32 * info_list, u32 num) -{ - int cnt = 0; - if(num > 0) - { - info_list[0] = shell_log_overflow; - cnt++; - } - if(num > 1) - { - info_list[1] = shell_log_count; - cnt++; - } - if(num > 2) - { - info_list[2] = free_queue[0].empty_cnt; - cnt++; - } - if(num > 3) - { - info_list[3] = free_queue[1].empty_cnt; - cnt++; - } - if(num > 4) - { - info_list[4] = free_queue[2].empty_cnt; - cnt++; - } - - return cnt; -} - -void shell_log_flush(void) -{ - u32 int_mask; - - int_mask = rtos_disable_int(); - - log_dev->dev_drv->io_ctrl(log_dev, SHELL_IO_CTRL_FLUSH, NULL); - - rtos_enable_int(int_mask); -} - -void shell_set_uart_port(uint8_t uart_port) { -#if (!CONFIG_SLAVE_CORE) - if (bk_get_printf_port() != uart_port && uart_port < UART_ID_MAX) { - u32 int_mask = rtos_disable_int(); - - shell_log_flush(); - bk_set_printf_port(uart_port); - - log_dev->dev_drv->close(log_dev); - log_dev->dev_drv->io_ctrl(log_dev, SHELL_IO_CTRL_SET_UART_PORT, &uart_port); - log_dev->dev_drv->init(log_dev); - log_dev->dev_drv->open(log_dev, shell_tx_complete, shell_rx_indicate); - - rtos_enable_int(int_mask); - } -#endif -} diff --git a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/shell_uart.c b/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/shell_uart.c deleted file mode 100755 index ed4ff2ba49292fa1ebf7d6f25629d0c3c8ff02be..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/bk_cli/shell_uart.c +++ /dev/null @@ -1,522 +0,0 @@ - -#include -#include - -#include "cli.h" -#include "shell_drv.h" - -#define TX_QUEUE_LEN 8 -#define RX_BUFF_SIZE 160 -#define ECHO_BUFF_SIZE 64 - - -typedef struct -{ - u8 * packet; - u16 len; - u16 tag; -} dev_tx_packet_t; - - -typedef struct -{ - u8 uart_id; - - /* ======== TX channel ======= */ - /* tx queue */ - dev_tx_packet_t tx_list[TX_QUEUE_LEN]; - u16 list_out_idx; - u16 list_in_idx; - - /* currently tx packet info */ - u8 *cur_packet; - u16 packet_len; - u16 packet_tag; - u16 packet_tx_len; - - u8 tx_stopped; - - u8 echo_buff[ECHO_BUFF_SIZE]; - u8 echo_wr_idx; - u8 echo_rd_idx; - - tx_complete_t tx_complete_callback; - - /* ======== RX channel ======= */ - /* rx buffer */ - u8 rx_buff[RX_BUFF_SIZE]; - u16 rx_buff_wr_idx; - u16 rx_buff_rd_idx; - - u8 rx_over_flow; - - rx_indicate_t rx_indicate_callback; - -} shell_uart_ext_t; - -static bool_t shell_uart_init(shell_dev_t * shell_dev); -static bool_t shell_uart_open(shell_dev_t * shell_dev, tx_complete_t tx_callback, rx_indicate_t rx_callback); -static u16 shell_uart_write_async(shell_dev_t * shell_dev, u8 * pBuf, u16 BufLen, u16 Tag); -static u16 shell_uart_read(shell_dev_t * shell_dev, u8 * pBuf, u16 BufLen); -static u16 shell_uart_write_sync(shell_dev_t * shell_dev, u8 * pBuf, u16 BufLen); -static u16 shell_uart_write_echo(shell_dev_t * shell_dev, u8 * pBuf, u16 BufLen); -static bool_t shell_uart_ctrl(shell_dev_t * shell_dev, u8 cmd, void *param); -static bool_t shell_uart_close(shell_dev_t * shell_dev); - -static const shell_dev_drv_t shell_uart_drv = - { - .init = shell_uart_init, - .open = shell_uart_open, - .write_async = shell_uart_write_async, - .read = shell_uart_read, - .write_sync = shell_uart_write_sync, - .write_echo = shell_uart_write_echo, - .io_ctrl = shell_uart_ctrl, - .close = shell_uart_close - }; - -static shell_uart_ext_t uart1_ext = - { - .uart_id = CONFIG_UART_PRINT_PORT - }; - -shell_dev_t shell_uart = - { - .dev_drv = (struct _shell_dev_drv *)&shell_uart_drv, - .dev_type = SHELL_DEV_UART, - .dev_ext = &uart1_ext - }; - -#if 0 -static shell_uart_ext_t uart3_ext = - { - .uart_id = UART_ID_2 - }; - -shell_dev_t shell_uart3 = - { - .dev_drv = (struct _shell_dev_drv *)&shell_uart_drv, - .dev_type = SHELL_DEV_UART, - .dev_ext = &uart3_ext - }; -#endif - -/* =============================== internal functions =========================== */ - -static void shell_uart_rx_isr(int uartn, shell_uart_ext_t *uart_ext) -{ - u16 free_buff_len, rx_cnt = 0; - u8 rx_data; - int ret = -1; - - (void)uartn; - - if(uart_ext->rx_buff_wr_idx >= uart_ext->rx_buff_rd_idx) - { - free_buff_len = RX_BUFF_SIZE - uart_ext->rx_buff_wr_idx + uart_ext->rx_buff_rd_idx; - } - else - { - free_buff_len = uart_ext->rx_buff_rd_idx - uart_ext->rx_buff_wr_idx; - } - - while(bTRUE) /* read all data from rx-FIFO. */ - { - ret = uart_read_byte_ex(uart_ext->uart_id, &rx_data); - if (ret == -1) - break; - - rx_cnt++; - - /* rx_buff_wr_idx == rx_buff_rd_idx means empty, so reserve one byte. */ - if(rx_cnt < free_buff_len) /* reserved one byte space. */ - { - uart_ext->rx_buff[uart_ext->rx_buff_wr_idx] = rx_data; - - uart_ext->rx_buff_wr_idx = (uart_ext->rx_buff_wr_idx + 1) % RX_BUFF_SIZE; - - } - else - { - /* discard rx-data, rx overflow. */ - uart_ext->rx_over_flow = 1; // bTRUE; // rx overflow, disable rx interrupt to stop rx. - } - } - - if(uart_ext->rx_indicate_callback != NULL) - { - uart_ext->rx_indicate_callback(); - } -} - -static void shell_uart_tx_isr(int uartn, shell_uart_ext_t *uart_ext) -{ - int ret; - (void)uartn; - - while(bTRUE) /* write data to tx-FIFO. */ - { - ret = uart_write_ready(uart_ext->uart_id); - if(ret != 0) - break; - - /* previous packet tx complete, check ECHO before new packet. */ - if((uart_ext->cur_packet == NULL) || (uart_ext->packet_len == 0)) - { - if(uart_ext->echo_rd_idx != uart_ext->echo_wr_idx) /* tx echo firstly. */ - { - uart_write_byte(uart_ext->uart_id, uart_ext->echo_buff[uart_ext->echo_rd_idx]); - - uart_ext->echo_rd_idx = (uart_ext->echo_rd_idx + 1) % ECHO_BUFF_SIZE; - - continue; /* continue to ECHO next byte to tx-FIFO. */ - } - else - { - if(uart_ext->list_out_idx != uart_ext->list_in_idx) - { - uart_ext->cur_packet = uart_ext->tx_list[uart_ext->list_out_idx].packet; - uart_ext->packet_len = uart_ext->tx_list[uart_ext->list_out_idx].len; - uart_ext->packet_tag = uart_ext->tx_list[uart_ext->list_out_idx].tag; - uart_ext->packet_tx_len = 0; - } - else - { - /* all packets tx complete. */ - /* disable tx interrupt ? */ // disable TX firstly, then set tx_stopped to 1. - bk_uart_disable_tx_interrupt(uart_ext->uart_id); - - uart_ext->tx_stopped = 1; /* bTRUE;*/ /* all data tranferred, tx stopped.*/ - break; - } - } - } - - if(uart_ext->packet_tx_len < uart_ext->packet_len) - { - uart_write_byte(uart_ext->uart_id, uart_ext->cur_packet[uart_ext->packet_tx_len]); - - uart_ext->packet_tx_len++; - - continue; /* continue to TX next byte to tx-FIFO. */ - } - else - { - /* sent the whole packet, notify app. */ - if(uart_ext->tx_complete_callback != NULL) - { - uart_ext->tx_complete_callback(uart_ext->cur_packet, uart_ext->packet_tag); - } - - uart_ext->cur_packet = NULL; - uart_ext->packet_len = 0; - uart_ext->packet_tx_len = 0; - - /* to next packet. */ - uart_ext->list_out_idx = (uart_ext->list_out_idx + 1) % TX_QUEUE_LEN; - - continue; /* continue to TX next packet. */ - } - } - -} - -static void shell_uart_flush(shell_uart_ext_t *uart_ext) -{ - int ret; - - while(uart_ext->tx_stopped == 0) /* log tx pending. */ - { - ret = uart_write_ready(uart_ext->uart_id); - if(ret == BK_OK) - { - shell_uart_tx_isr(uart_ext->uart_id, uart_ext); - } - } -} - -static void shell_uart_tx_trigger(shell_uart_ext_t *uart_ext) -{ - if(uart_ext->tx_stopped == 0) - return; - - uart_ext->tx_stopped = 0; // set tx_stopped to 0 firstly, then enable TX. - - bk_uart_enable_tx_interrupt(uart_ext->uart_id); -} - -/* =============================== shell uart driver APIs =========================== */ - -static bool_t shell_uart_init(shell_dev_t * shell_dev) -{ - u8 uart_id; - shell_uart_ext_t *uart_ext; - - if(shell_dev == NULL) - return bFALSE; - - uart_ext = (shell_uart_ext_t *)shell_dev->dev_ext; - uart_id = uart_ext->uart_id; - - memset(uart_ext, 0, sizeof(shell_uart_ext_t)); - uart_ext->rx_over_flow = 0; - uart_ext->tx_stopped = 1; - uart_ext->uart_id = uart_id; - - return bTRUE; -} - -static bool_t shell_uart_open(shell_dev_t * shell_dev, tx_complete_t tx_callback, rx_indicate_t rx_callback) -{ - shell_uart_ext_t *uart_ext; - - if(shell_dev == NULL) - return bFALSE; - - uart_ext = (shell_uart_ext_t *)shell_dev->dev_ext; - - uart_ext->tx_complete_callback = tx_callback; - uart_ext->rx_indicate_callback = rx_callback; - - bk_uart_disable_sw_fifo(uart_ext->uart_id); - - // call uart driver to register isr callback; - bk_uart_register_rx_isr(uart_ext->uart_id, (uart_isr_t)shell_uart_rx_isr, uart_ext); - bk_uart_register_tx_isr(uart_ext->uart_id, (uart_isr_t)shell_uart_tx_isr, uart_ext); - - bk_uart_enable_rx_interrupt(uart_ext->uart_id); - - return bTRUE; -} - -static u16 shell_uart_write_async(shell_dev_t * shell_dev, u8 * pBuf, u16 BufLen, u16 Tag) -{ - u16 free_items; - shell_uart_ext_t *uart_ext; - - if(shell_dev == NULL) - return 0; - - uart_ext = (shell_uart_ext_t *)shell_dev->dev_ext; - - if((pBuf == NULL) /*|| (BufLen == 0)*/) - return 0; - - /* enqueue pBuf even if BufLen is 0, upper layer need tx-complete-callback to free this pBuf. */ - - if(uart_ext->list_out_idx > uart_ext->list_in_idx) - free_items = uart_ext->list_out_idx - uart_ext->list_in_idx; - else - free_items = TX_QUEUE_LEN - uart_ext->list_in_idx + uart_ext->list_out_idx; - - /* list_out_idx == list_in_idx means empty, so reserved one item. */ - if(free_items > 1) - { - uart_ext->tx_list[uart_ext->list_in_idx].packet = pBuf; - uart_ext->tx_list[uart_ext->list_in_idx].len = BufLen; - uart_ext->tx_list[uart_ext->list_in_idx].tag = Tag; - - uart_ext->list_in_idx = (uart_ext->list_in_idx + 1) % TX_QUEUE_LEN; - - shell_uart_tx_trigger(uart_ext); - - return 1; - } - else - { - return 0; - } -} - -static u16 shell_uart_read(shell_dev_t * shell_dev, u8 * pBuf, u16 BufLen) -{ - u16 read_cnt = 0; - - shell_uart_ext_t *uart_ext; - - if(shell_dev == NULL) - return 0; - - uart_ext = (shell_uart_ext_t *)shell_dev->dev_ext; - - if((pBuf == NULL) || (BufLen == 0)) - return 0; - - while(uart_ext->rx_buff_rd_idx != uart_ext->rx_buff_wr_idx) - { - pBuf[read_cnt] = uart_ext->rx_buff[uart_ext->rx_buff_rd_idx]; - - uart_ext->rx_buff_rd_idx = (uart_ext->rx_buff_rd_idx + 1) % RX_BUFF_SIZE; - - read_cnt++; - if(read_cnt >= BufLen) - break; - } - - return read_cnt; - -} - -/* call this after interrupt is DISABLED. */ -static u16 shell_uart_write_sync(shell_dev_t * shell_dev, u8 * pBuf, u16 BufLen) -{ - shell_uart_ext_t *uart_ext; - - if(shell_dev == NULL) - return 0; - - uart_ext = (shell_uart_ext_t *)shell_dev->dev_ext; - - if((pBuf == NULL) || (BufLen == 0)) - return 0; - - u16 wr_cnt = 0; - - while(bTRUE) /* write data to tx-FIFO. */ - { - uart_write_byte(uart_ext->uart_id, *pBuf); // it is macro define, do NOT use *pBuf++; - - pBuf++; wr_cnt++; - - if(wr_cnt >= BufLen) - break; - } - - return BufLen; -} - -static u16 shell_uart_write_echo(shell_dev_t * shell_dev, u8 * pBuf, u16 BufLen) -{ - u16 free_buff_len, wr_cnt = 0; - - shell_uart_ext_t *uart_ext; - - if(shell_dev == NULL) - return 0; - - uart_ext = (shell_uart_ext_t *)shell_dev->dev_ext; - - if((pBuf == NULL) || (BufLen == 0)) - return 0; - - if(uart_ext->echo_wr_idx >= uart_ext->echo_rd_idx) - { - free_buff_len = ECHO_BUFF_SIZE - uart_ext->echo_wr_idx + uart_ext->echo_rd_idx; - } - else - { - free_buff_len = uart_ext->echo_rd_idx - uart_ext->echo_wr_idx; - } - - /* echo_wr_idx == echo_rd_idx means empty, so reserved one byte. */ - while(free_buff_len > 1) - { - uart_ext->echo_buff[uart_ext->echo_wr_idx] = pBuf[wr_cnt]; - uart_ext->echo_wr_idx = (uart_ext->echo_wr_idx + 1) % ECHO_BUFF_SIZE; - - free_buff_len--; - - wr_cnt++; - if(wr_cnt >= BufLen) - break; - } - - if(wr_cnt > 0) - shell_uart_tx_trigger(uart_ext); - - return wr_cnt; - -} - -static bool_t shell_uart_ctrl(shell_dev_t * shell_dev, u8 cmd, void *param) -{ - shell_uart_ext_t *uart_ext; - - if(shell_dev == NULL) - return bFALSE; - - uart_ext = (shell_uart_ext_t *)shell_dev->dev_ext; - - switch(cmd) - { - case SHELL_IO_CTRL_GET_STATUS: - if(param == NULL) - return bFALSE; - - u16 free_items; - - if(uart_ext->list_out_idx > uart_ext->list_in_idx) - free_items = uart_ext->list_out_idx - uart_ext->list_in_idx; - else - free_items = TX_QUEUE_LEN - uart_ext->list_in_idx + uart_ext->list_out_idx; - - if(free_items > 1) - *((u16 *)param) = free_items - 1; - else - *((u16 *)param) = 0; - - break; - - case SHELL_IO_CTRL_RX_RESET: - uart_ext->rx_buff_rd_idx = 0; - uart_ext->rx_buff_wr_idx = 0; - break; - - case SHELL_IO_CTRL_TX_RESET: - uart_ext->list_out_idx = 0; - uart_ext->list_in_idx = 0; - - uart_ext->cur_packet = NULL; - uart_ext->packet_len = 0; - uart_ext->packet_tx_len = 0; - - break; - - case SHELL_IO_CTRL_FLUSH: - shell_uart_flush(uart_ext); - break; - - case SHELL_IO_CTRL_SET_UART_PORT: - if(param == NULL) { - return bFALSE; - } - u8 uart_port = *(u8 *)param; - uart_ext->uart_id = uart_port; - break; - - case SHELL_IO_CTRL_GET_RX_STATUS: - if(param == NULL) - return bFALSE; - - *((u16 *)param) = uart_ext->rx_over_flow; - uart_ext->rx_over_flow = 0; // clear it after read by user. - - break; - - default: - return bFALSE; - break; - } - - return bTRUE; -} - -static bool_t shell_uart_close(shell_dev_t * shell_dev) -{ - shell_uart_ext_t *uart_ext; - - if(shell_dev == NULL) - return bFALSE; - - uart_ext = (shell_uart_ext_t *)shell_dev->dev_ext; - - // call uart driver to register isr callback; - bk_uart_register_rx_isr(uart_ext->uart_id, NULL, NULL); - bk_uart_register_tx_isr(uart_ext->uart_id, NULL, NULL); - - uart_ext->tx_complete_callback = NULL; - uart_ext->rx_indicate_callback = NULL; - - return bTRUE; -} - diff --git a/bk7235/liteos_m/bk_sdk_armino/components/bk_event/event.c b/bk7235/liteos_m/bk_sdk_armino/components/bk_event/event.c index ec2e8bed497be89ec4b2309fbd9e7bff6e20733b..0b937f26cbf469cb3632afb49cf728dae7b36a77 100644 --- a/bk7235/liteos_m/bk_sdk_armino/components/bk_event/event.c +++ b/bk7235/liteos_m/bk_sdk_armino/components/bk_event/event.c @@ -1,3 +1,17 @@ +/* + * Copyright (C) 2022 Beken Corporation + * 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 #include #include "event.h" diff --git a/bk7235/liteos_m/bk_sdk_armino/components/bk_libs/bk7235_openharmony/config/sdkconfig.h b/bk7235/liteos_m/bk_sdk_armino/components/bk_libs/bk7235_openharmony/config/sdkconfig.h index 1cc95e2ffa3fab0dcb13f08b45ddf3dfb0d0bbd3..86cbd4fc2290b72e3205fa1ec049ae2a03dc55f2 100755 --- a/bk7235/liteos_m/bk_sdk_armino/components/bk_libs/bk7235_openharmony/config/sdkconfig.h +++ b/bk7235/liteos_m/bk_sdk_armino/components/bk_libs/bk7235_openharmony/config/sdkconfig.h @@ -1,3 +1,18 @@ +/* + * Copyright (C) 2022 Beken Corporation + * 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. + */ + /* * Automatically generated file. DO NOT EDIT. * Beken IoT Development Framework (BEKEN-ARMINO) Configuration Header diff --git a/bk7235/liteos_m/bk_sdk_armino/components/bk_libs/common/libairkiss.a b/bk7235/liteos_m/bk_sdk_armino/components/bk_libs/common/libairkiss.a deleted file mode 100644 index b8eb3ff9da6581c27f56d1c4f08dc16c30fd913d..0000000000000000000000000000000000000000 Binary files a/bk7235/liteos_m/bk_sdk_armino/components/bk_libs/common/libairkiss.a and /dev/null differ diff --git a/bk7235/liteos_m/bk_sdk_armino/components/bk_libs/config_checking.py b/bk7235/liteos_m/bk_sdk_armino/components/bk_libs/config_checking.py deleted file mode 100755 index 6889c2462567c8451943011bc47c02a14d3ed017..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/bk_libs/config_checking.py +++ /dev/null @@ -1,93 +0,0 @@ -#!/usr/bin/env python3 - -import argparse -import sys -import re -import os - -class ConfigChecking: - - def __init__(self, lib_sdkconfig=None, armino_sdkconfig=None): - self.lib_sdkconfig = lib_sdkconfig - self.armino_sdkconfig = armino_sdkconfig - print(f'properties lib sdkconfig: {self.lib_sdkconfig}') - print(f'armino sdkconfig: {self.armino_sdkconfig}') - - self.lib_configs = dict() - self.armino_configs = dict() - - def check_config(self): - - self.lib_configs = self.parse_sdkconfig(self.lib_sdkconfig) - self.armino_configs = self.parse_sdkconfig(self.armino_sdkconfig) - self.find_mismatch() - - def parse_sdkconfig(self, sdkconfig_path): - d = dict() - f = open(sdkconfig_path, 'r') - for l in f: - l = ' '.join(l.split()) - line_keys = l.split('=') - if len(line_keys) != 2: - continue - k = line_keys[0] - v = line_keys[1] - if k[0:7] != "CONFIG_": - continue - - d[k] = v - #print(f'add key={k} value={v}') - - f.close() - return (d) - - def find_mismatch(self): - mismatch_cnt = 0 - for lib_key,lib_value in self.lib_configs.items(): - for armino_key, armino_value in self.armino_configs.items(): - if (lib_key == armino_key) and (lib_value != armino_value): - print(f"mismatched config={lib_key} properties={lib_value} armino={armino_value}") - mismatch_cnt = mismatch_cnt + 1 - - if (mismatch_cnt != 0): - exit(1) - -def main(): - parser = argparse.ArgumentParser(description='sdkconfig_check - consistence checking between properties and armino') - - parser.add_argument( - '--lib_sdkconfig', help='absolute path of properties lib sdkconfig', - default=None, - dest='lib_sdkconfig') - - parser.add_argument( - '--armino_sdkconfig', help='absolute path of properties armino sdkconfig', - default=None, - dest='armino_sdkconfig') - - args = parser.parse_args() - - if args.lib_sdkconfig: - if os.path.exists(args.lib_sdkconfig) == False: - print(f'Properties lib config file {args.lib_sdkconfig} not exists') - exit(1) - else: - print(f'Missing properties lib sdkconfig') - exit(1) - - if args.armino_sdkconfig: - if os.path.exists(args.armino_sdkconfig) == False: - print(f'Armino config file {args.armino_sdkconfig} not exists') - exit(1) - else: - print(f'please provide armino sdkconfig') - exit(1) - - lib_sdkconfig = os.path.realpath(args.lib_sdkconfig) - armino_sdkconfig = os.path.realpath(args.armino_sdkconfig) - - cc = ConfigChecking(lib_sdkconfig, armino_sdkconfig) - cc.check_config() - -if __name__ == "__main__": - main() diff --git a/bk7235/liteos_m/bk_sdk_armino/components/bk_libs/include/sdk_version.h b/bk7235/liteos_m/bk_sdk_armino/components/bk_libs/include/sdk_version.h index b642539fbca82d38383b93b834bec50caf7279f7..78db3e30c9ab3517a1ccdfbb4a4e62d41c479e38 100644 --- a/bk7235/liteos_m/bk_sdk_armino/components/bk_libs/include/sdk_version.h +++ b/bk7235/liteos_m/bk_sdk_armino/components/bk_libs/include/sdk_version.h @@ -1,3 +1,17 @@ +/* + * Copyright (C) 2022 Beken Corporation + * 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. + */ #pragma once #define ARMINO_TAG_VERSION "v1.3.6" #define bk7231n_HASH_VERSION "674ed234177bfee92956887bbee45d8e" diff --git a/bk7235/liteos_m/bk_sdk_armino/components/bk_log/log.c b/bk7235/liteos_m/bk_sdk_armino/components/bk_log/log.c index ab353a8d8c1c1e1fc0d3a61ef0b2f1e8c22dfc59..f28d2666047b5a3ad8e9d60a0d14965ec3f460c6 100644 --- a/bk7235/liteos_m/bk_sdk_armino/components/bk_log/log.c +++ b/bk7235/liteos_m/bk_sdk_armino/components/bk_log/log.c @@ -1,3 +1,17 @@ +/* + * Copyright (C) 2022 Beken Corporation + * 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 void bk_mem_dump(const char *title, uint32_t start, uint32_t len) diff --git a/bk7235/liteos_m/bk_sdk_armino/components/bk_netif/bk_netif.c b/bk7235/liteos_m/bk_sdk_armino/components/bk_netif/bk_netif.c index df024a60cf8f4acd670deb90459995989dfa3440..932fdcf6f67fe03427c2595f9687676af8c3eb59 100644 --- a/bk7235/liteos_m/bk_sdk_armino/components/bk_netif/bk_netif.c +++ b/bk7235/liteos_m/bk_sdk_armino/components/bk_netif/bk_netif.c @@ -1,3 +1,17 @@ +/* + * Copyright (C) 2022 Beken Corporation + * 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 #include #include diff --git a/bk7235/liteos_m/bk_sdk_armino/components/bk_os/include/sys_rtos.h b/bk7235/liteos_m/bk_sdk_armino/components/bk_os/include/sys_rtos.h index 0d9cf23bd8e64b9f12976fb8ba7d0e71cd38e255..80ebf609b4e917b2f7b229d1a07986f2e4b2c614 100644 --- a/bk7235/liteos_m/bk_sdk_armino/components/bk_os/include/sys_rtos.h +++ b/bk7235/liteos_m/bk_sdk_armino/components/bk_os/include/sys_rtos.h @@ -1,3 +1,18 @@ +/* + * Copyright (C) 2022 Beken Corporation + * 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 _SYS_RTOS_H_ #define _SYS_RTOS_H_ #include diff --git a/bk7235/liteos_m/bk_sdk_armino/components/bk_os/liteos_m_mst/mem_arch.c b/bk7235/liteos_m/bk_sdk_armino/components/bk_os/liteos_m_mst/mem_arch.c index 4f226b6ac3a32bee38f50261fda5c43444a86d81..efae3f6d2c537cb89d0c082dbc081c11d9bcda4b 100755 --- a/bk7235/liteos_m/bk_sdk_armino/components/bk_os/liteos_m_mst/mem_arch.c +++ b/bk7235/liteos_m/bk_sdk_armino/components/bk_os/liteos_m_mst/mem_arch.c @@ -1,3 +1,18 @@ +/* + * Copyright (C) 2022 Beken Corporation + * 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 #include "arm_arch.h" #include @@ -123,4 +138,4 @@ void *psram_malloc_debug(const char *func_name, int line, size_t size, int need_ { return NULL; } -#endif \ No newline at end of file +#endif diff --git a/bk7235/liteos_m/bk_sdk_armino/components/bk_os/liteos_m_mst/portmacro.h b/bk7235/liteos_m/bk_sdk_armino/components/bk_os/liteos_m_mst/portmacro.h index 07663a767e6a01a9012366463099275caf5200cd..03641d2472bc29e6ddfae0946b7da2369f3d4663 100755 --- a/bk7235/liteos_m/bk_sdk_armino/components/bk_os/liteos_m_mst/portmacro.h +++ b/bk7235/liteos_m/bk_sdk_armino/components/bk_os/liteos_m_mst/portmacro.h @@ -1,3 +1,17 @@ +/* + * Copyright (C) 2022 Beken Corporation + * 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 __PORTMACRO_H__ #define __PORTMACRO_H__ diff --git a/bk7235/liteos_m/bk_sdk_armino/components/bk_os/liteos_m_mst/rtos_pub.c b/bk7235/liteos_m/bk_sdk_armino/components/bk_os/liteos_m_mst/rtos_pub.c index 7e859ef27bef21e586086834606d2613d233d148..78d976e40755d8b58ab2ecc16d2f45401f13c919 100755 --- a/bk7235/liteos_m/bk_sdk_armino/components/bk_os/liteos_m_mst/rtos_pub.c +++ b/bk7235/liteos_m/bk_sdk_armino/components/bk_os/liteos_m_mst/rtos_pub.c @@ -1,3 +1,18 @@ +/* + * Copyright (C) 2022 Beken Corporation + * 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 #include #include "los_config.h" diff --git a/bk7235/liteos_m/bk_sdk_armino/components/bk_os/liteos_m_mst/str_arch.c b/bk7235/liteos_m/bk_sdk_armino/components/bk_os/liteos_m_mst/str_arch.c deleted file mode 100755 index e36ffa27b70565714060f2d1f1d018038d6e0223..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/bk_os/liteos_m_mst/str_arch.c +++ /dev/null @@ -1,138 +0,0 @@ -#include - -#include -#include -#include -#include -#include - -char *os_strchr(const char *s, int c) -{ - return strchr(s, c); -} - -UINT32 os_strlen(const char *str) -{ - return strlen(str); -} - -INT32 os_strcmp(const char *s1, const char *s2) -{ - return strcmp(s1, s2); -} - -UINT32 os_strtoul(const char *nptr, char **endptr, int base) -{ - return strtoul(nptr, endptr, base); -} - -char *os_strcpy(char *out, const char *in) -{ - return strcpy(out, in); -} - -char *os_strncpy(char *out, const char *in, const UINT32 n) -{ - return strncpy(out, in, (unsigned int)n); -} - -size_t os_strlcpy(char *dest, const char *src, size_t siz) -{ - const char *s = src; - size_t left = siz; - - if (left) - { - /* Copy string up to the maximum size of the dest buffer */ - while (--left != 0) - { - if ((*dest++ = *s++) == '\0') - break; - } - } - - if (left == 0) - { - /* Not enough room for the string; force NUL-termination */ - if (siz != 0) - *dest = '\0'; - - while (*s++) - ; /* determine total src string length */ - } - - return s - src - 1; -} - -INT32 os_strncmp(const char *s1, const char *s2, const UINT32 n) -{ - return strncmp(s1, s2, (unsigned int)n); -} - -INT32 os_snprintf(char *buf, UINT32 size, const char *fmt, ...) -{ - va_list args; - INT32 rc; - - va_start(args, fmt); - rc = vsnprintf(buf, size, fmt, args); - va_end(args); - - /* if want to print more than the limitation */ - if (rc > size) - rc = (INT32)size - rc; - - return rc; -} - -INT32 os_vsnprintf(char *buf, UINT32 size, const char *fmt, va_list ap) -{ - return vsnprintf(buf, size, fmt, ap); -} - -char *os_strdup(const char *s) -{ - char *res; - size_t len; - - if (s == NULL) - return NULL; - - len = os_strlen(s); - res = os_malloc(len + 1); - if (res) - os_memcpy(res, s, len + 1); - - return res; -} - - -int os_strcasecmp(const char *s1, const char *s2) -{ - /* - * Ignoring case is not required for main functionality, so just use - * the case sensitive version of the function. - */ - return os_strcmp(s1, s2); -} - - -int os_strncasecmp(const char *s1, const char *s2, size_t n) -{ - /* - * Ignoring case is not required for main functionality, so just use - * the case sensitive version of the function. - */ - return os_strncmp(s1, s2, n); -} - -char *os_strrchr(const char *s, int c) -{ - return strrchr(s, c); -} - -char *os_strstr(const char *haystack, const char *needle) -{ - return strstr(haystack, needle); -} -// EOF diff --git a/bk7235/liteos_m/bk_sdk_armino/components/bk_ps/include/bk_mac_ps.h b/bk7235/liteos_m/bk_sdk_armino/components/bk_ps/include/bk_mac_ps.h index e0265147303e6b18f873900d446572d1d5fe265f..ba9a341999c5c999ab0bf74165235c524511f1b6 100644 --- a/bk7235/liteos_m/bk_sdk_armino/components/bk_ps/include/bk_mac_ps.h +++ b/bk7235/liteos_m/bk_sdk_armino/components/bk_ps/include/bk_mac_ps.h @@ -1,3 +1,17 @@ +/* + * Copyright (C) 2022 Beken Corporation + * 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. + */ void mac_ps_Command ( char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv ); int mac_ps_dtim_rf_ps_disable_send_msg ( void ); diff --git a/bk7235/liteos_m/bk_sdk_armino/components/bk_system/target_util.c b/bk7235/liteos_m/bk_sdk_armino/components/bk_system/target_util.c index 6b5edf4b80365d993c9aada1700bcf05a47eae0b..022c6cd4e0990737897e6873874e6a9334dbccec 100644 --- a/bk7235/liteos_m/bk_sdk_armino/components/bk_system/target_util.c +++ b/bk7235/liteos_m/bk_sdk_armino/components/bk_system/target_util.c @@ -1,3 +1,17 @@ +/* + * Copyright (C) 2022 Beken Corporation + * 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 #include "bk_arm_arch.h" diff --git a/bk7235/liteos_m/bk_sdk_armino/components/bk_system/tick_base.c b/bk7235/liteos_m/bk_sdk_armino/components/bk_system/tick_base.c index 747ffb6b02eddb8ac76fb60c07d9dc1a6f673015..26d6a360e77335691bac0b7446a0a027f96a5302 100644 --- a/bk7235/liteos_m/bk_sdk_armino/components/bk_system/tick_base.c +++ b/bk7235/liteos_m/bk_sdk_armino/components/bk_system/tick_base.c @@ -1,3 +1,17 @@ +/* + * Copyright (C) 2022 Beken Corporation + * 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 "sys_rtos.h" #include "bk_fake_clock.h" #include "bk_timer.h" diff --git a/bk7235/liteos_m/bk_sdk_armino/components/bk_wifi/include/bk_private/bk_wifi_wrapper.h b/bk7235/liteos_m/bk_sdk_armino/components/bk_wifi/include/bk_private/bk_wifi_wrapper.h index 5c3f6b3f4a031a270058c856080928f32e9eb8ee..ff4539229fcfa119a1ac0e402a896d82fc887bd3 100644 --- a/bk7235/liteos_m/bk_sdk_armino/components/bk_wifi/include/bk_private/bk_wifi_wrapper.h +++ b/bk7235/liteos_m/bk_sdk_armino/components/bk_wifi/include/bk_private/bk_wifi_wrapper.h @@ -1,3 +1,17 @@ +/* + * Copyright (C) 2022 Beken Corporation + * 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 _IEEE802_11_DEMO_H_ #define _IEEE802_11_DEMO_H_ diff --git a/bk7235/liteos_m/bk_sdk_armino/components/bk_wifi/include/bk_private/param_config.h b/bk7235/liteos_m/bk_sdk_armino/components/bk_wifi/include/bk_private/param_config.h index a6b840db3128c6eff7ba309ead9f9f17f355f532..4ef1028b40e6b944f1c3c5ff73045a667510f5c2 100644 --- a/bk7235/liteos_m/bk_sdk_armino/components/bk_wifi/include/bk_private/param_config.h +++ b/bk7235/liteos_m/bk_sdk_armino/components/bk_wifi/include/bk_private/param_config.h @@ -1,3 +1,17 @@ +/* + * Copyright (C) 2022 Beken Corporation + * 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 _ARCH_CONFIG_H_ #define _ARCH_CONFIG_H_ diff --git a/bk7235/liteos_m/bk_sdk_armino/components/bk_wifi/include/bk_private/sa_station.h b/bk7235/liteos_m/bk_sdk_armino/components/bk_wifi/include/bk_private/sa_station.h index 308fd1e48c18fe99b7fe513914289b818c4ff618..d27bfc2598850013c3cd8fa44c00f3e82d4c2827 100644 --- a/bk7235/liteos_m/bk_sdk_armino/components/bk_wifi/include/bk_private/sa_station.h +++ b/bk7235/liteos_m/bk_sdk_armino/components/bk_wifi/include/bk_private/sa_station.h @@ -1,3 +1,17 @@ +/* + * Copyright (C) 2022 Beken Corporation + * 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 _SA_STATION_H_ #define _SA_STATION_H_ diff --git a/bk7235/liteos_m/bk_sdk_armino/components/easy_flash/.gitattributes b/bk7235/liteos_m/bk_sdk_armino/components/easy_flash/.gitattributes deleted file mode 100644 index a6ec1ac29ee9ec4459a962fec9f0412e46b745e5..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/easy_flash/.gitattributes +++ /dev/null @@ -1,40 +0,0 @@ -* text=auto - -*.S text -*.asm text -*.c text -*.cc text -*.cpp text -*.cxx text -*.h text -*.htm text -*.html text -*.in text -*.ld text -*.m4 text -*.mak text -*.mk text -*.py text -*.rb text -*.s text -*.sct text -*.sh text -*.txt text -*.xml text -Makefile text -AUTHORS text -COPYING text - -*.LZO -text -*.Opt -text -*.Uv2 -text -*.ewp -text -*.eww -text -*.vcproj -text -*.bat -text -*.dos -text -*.icf -text -*.inf -text -*.ini -text -*.sct -text -*.xsd -text diff --git a/bk7235/liteos_m/bk_sdk_armino/components/easy_flash/CMakeLists.txt b/bk7235/liteos_m/bk_sdk_armino/components/easy_flash/CMakeLists.txt deleted file mode 100644 index 35b8e10944f99471daaf3883bba2799137e39866..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/easy_flash/CMakeLists.txt +++ /dev/null @@ -1,25 +0,0 @@ -set(incs - . - inc - port - ) - -set(srcs) - -if (CONFIG_EASY_FLASH) - list(APPEND srcs - bk_ef.c - src/easyflash.c - src/ef_env.c - src/ef_env_wl.c - src/ef_iap.c - src/ef_log.c - src/ef_utils.c - port/ef_port.c - ) -endif() - -armino_component_register(SRCS "${srcs}" - INCLUDE_DIRS "${incs}" - REQUIRES base64 - PRIV_REQUIRES bk_common) diff --git a/bk7235/liteos_m/bk_sdk_armino/components/easy_flash/Kconfig b/bk7235/liteos_m/bk_sdk_armino/components/easy_flash/Kconfig deleted file mode 100644 index d1a954e6903c1a18a7494659d4c99fb64c376a68..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/easy_flash/Kconfig +++ /dev/null @@ -1,3 +0,0 @@ -config EASY_FLASH - bool "Enable Easy Flash" - default n \ No newline at end of file diff --git a/bk7235/liteos_m/bk_sdk_armino/components/easy_flash/LICENSE b/bk7235/liteos_m/bk_sdk_armino/components/easy_flash/LICENSE deleted file mode 100644 index 9b802d2ba039dffbd17d9dac4802357ed7173df4..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/easy_flash/LICENSE +++ /dev/null @@ -1,22 +0,0 @@ -The MIT License (MIT) - -Copyright (c) 2014-2018 Armink (armink.ztl@gmail.com) - -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files (the -'Software'), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/bk7235/liteos_m/bk_sdk_armino/components/easy_flash/bk_ef.c b/bk7235/liteos_m/bk_sdk_armino/components/easy_flash/bk_ef.c deleted file mode 100644 index c9aef37b024021022e6544a0ec56c3b7c4c0b5c7..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/easy_flash/bk_ef.c +++ /dev/null @@ -1,96 +0,0 @@ -#include -#include "bk_ef.h" -#include "base_64.h" -#include -#include - -#if CONFIG_EASY_FLASH -char *bk_get_env(const char *key) -{ - return ef_get_env(key); -} - -EfErrCode bk_set_env(const char *key, const char *value) -{ - return ef_set_env(key, value); -} - -EfErrCode bk_save_env(void) -{ - return ef_save_env(); -} - -EfErrCode bk_set_buf_env(const char *key, const char *buf, int len) -{ - EfErrCode result; - unsigned char ret; - unsigned char *ef_value; - uint32_t buf_len; - int out_len; - - if ((0 == len) || (NULL == key) - || (NULL == buf)) - return EF_ENV_INIT_FAILED; - - buf_len = base64_calc_encode_length(len) + 4; - ef_value = os_zalloc(buf_len); - if (NULL == ef_value) - return EF_ENV_INIT_FAILED; - - ret = base64_encode((unsigned char *)buf, len, &out_len, ef_value); - if (0 == ret) { - os_free(ef_value); - ef_value = NULL; - return EF_ENV_INIT_FAILED; - } - - result = ef_set_env(key, (char *)ef_value); - - os_free(ef_value); - - return result; -} - -EfErrCode bk_get_buf_env(const char *key, const char *buf, int len) -{ - unsigned char *out_ptr; - unsigned char ret; - char *ef_value; - int out_buf_len, count; - int out_len, value_len; - - ef_value = ef_get_env(key); - if (NULL == ef_value) - return EF_ENV_NAME_ERR; - - value_len = os_strlen(ef_value); - if (0 == value_len) - return EF_ENV_INIT_FAILED; - - out_buf_len = base64_calc_decode_length((unsigned char *)ef_value, value_len); - out_ptr = (unsigned char *)os_zalloc(out_buf_len + 4); - if (NULL == out_ptr) - return EF_ENV_INIT_FAILED; - - ret = base64_decode((unsigned char *)ef_value, value_len, &out_len, out_ptr); - if (0 == ret) { - os_free(out_ptr); - out_ptr = NULL; - return EF_ENV_INIT_FAILED; - } - - if (out_len) { - count = min(len, out_len); - BK_ASSERT(len == out_len); - - os_memcpy((void *)buf, out_ptr, count); - } - - os_free(out_ptr); - - return EF_NO_ERR; -} -#endif // CONFIG_EASY_FLASH - -// eof - diff --git a/bk7235/liteos_m/bk_sdk_armino/components/easy_flash/bk_ef.h b/bk7235/liteos_m/bk_sdk_armino/components/easy_flash/bk_ef.h deleted file mode 100644 index db4c61aa7086fe2089ae1e5af7eefd27ae45d52b..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/easy_flash/bk_ef.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef _BK_EASY_FLASH_H_ -#define _BK_EASY_FLASH_H_ - -#include "easyflash.h" - -#if CONFIG_EASY_FLASH -EfErrCode bk_save_env(void); -char *bk_get_env(const char *key); -EfErrCode bk_set_env(const char *key, const char *value); -EfErrCode bk_set_buf_env(const char *key, const char *buf, int len); -EfErrCode bk_get_buf_env(const char *key, const char *buf, int len); -#endif // CONFIG_EASY_FLASH - -#endif // _BK_EASY_FLASH_H_ -// eof - diff --git a/bk7235/liteos_m/bk_sdk_armino/components/easy_flash/demo/iap/ymodem+rtt.c b/bk7235/liteos_m/bk_sdk_armino/components/easy_flash/demo/iap/ymodem+rtt.c deleted file mode 100644 index a1ecf3ca9b9fd203460379edc221b48fa1b708bb..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/easy_flash/demo/iap/ymodem+rtt.c +++ /dev/null @@ -1,125 +0,0 @@ -/* - * This file is part of the EasyFlash Library. - * - * Copyright (c) 2015, Armink, - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * 'Software'), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY - * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * Function: It's a demo for EasyFlash IAP fucnction. You must use RT-Thread to run this demo. - * Created on: 2015-07-06 - */ - - -/** - * IAP ²裺 - * 1RT-ThreadFinshն"update" - * 2Ymodem俪ʼʱͨymodem_on_beginصʹef_erase_bak_app洢Ӧã - * 3ʹef_write_data_to_bakյݱ浽FlashС̽YmodemݵĻصymodem_on_dataУ - * 4ɺ޸Ļ"iap_need_copy_app"ֵΪ1"change iap_copy_app_size"ֵΪAPPС滷 - * Ϊ˱֤ڸʱ´ϵȻԶָ£ - * 5ӦӦóڣ - * 6޸IJ滷"iap_need_copy_app""iap_copy_app_size"ֵΪ0 - * - * IAP update step: - * 1. Input "update" command in RT-Thread finsh terminal. - * 2. It will use ef_erase_bak_app to erase backup application section when ymodem_on_begin. - * 3. Save received data(ef_write_data_to_bak) to flash. - * This process is in Ymodem received data callback funciton ymodem_on_data. - * 4. After received finish. Change and save the Env "iap_need_copy_app to" 1 and "change iap_copy_app_size" to downloaded size. - * Make sure if update process case power-down, the update will auto resume on next reboot. - * 5. Erase and copy downloaded application to application entry. - * 6. Change and save the Env "iap_need_copy_app" and "iap_copy_app_size" to 0. - */ - -#include -#include -#include "finsh.h" -#include "ymodem.h" -#include "easyflash.h" -#include "stdlib.h" - -static uint32_t update_file_total_size, update_file_cur_size; -static enum rym_code ymodem_on_begin(struct rym_ctx *ctx, rt_uint8_t *buf, rt_size_t len) -{ - char *file_name, *file_size; - - /* calculate and store file size */ - file_name = (char *) &buf[0]; - file_size = (char *) &buf[rt_strlen(file_name) + 1]; - update_file_total_size = atol(file_size); - update_file_cur_size = 0; - - /* erase backup section */ - if (ef_erase_bak_app(update_file_total_size)) { - /* if erase fail then end session */ - return RYM_CODE_CAN; - } - - return RYM_CODE_ACK; -} - -static enum rym_code ymodem_on_data(struct rym_ctx *ctx, rt_uint8_t *buf, rt_size_t len) -{ - /* write data of application to backup section */ - if (ef_write_data_to_bak(buf, len, &update_file_cur_size, update_file_total_size)) { - /* if write fail then end session */ - return RYM_CODE_CAN; - } - return RYM_CODE_ACK; -} - -/** - * update command for RT-Thread finsh-msh command. - */ -void update(uint8_t argc, char **argv) -{ - uint16_t size; - char *recv_buff, c_file_size[11] = {0}; - struct rym_ctx rctx; - - os_printf("Please select a update file and use Ymodem to send.\r\n"); - - if (!rym_recv_on_device(&rctx, serial_get_device(), - RT_DEVICE_OFLAG_RDWR | RT_DEVICE_FLAG_INT_RX, ymodem_on_begin, ymodem_on_data, NULL, - bk_get_ticks_per_second())) { - /* wait some time for terminal response finish */ - rtos_delay_milliseconds(bk_get_ticks_per_second()); - /* set need copy application from backup section flag is 1, backup application length */ - ef_set_env("iap_need_copy_app", "1"); - rt_sprintf(c_file_size, "%ld", update_file_total_size); - ef_set_env("iap_copy_app_size", c_file_size); - ef_save_env(); - /* copy downloaded application to application entry */ - if (ef_erase_user_app(iap_get_app_addr(), update_file_total_size) - || ef_copy_app_from_bak(iap_get_app_addr(), update_file_total_size)) - os_printf("Update user app fail.\n"); - else - os_printf("Update user app success.\n"); - /* clean need copy application from backup section flag */ - ef_set_env("iap_need_copy_app", "0"); - ef_set_env("iap_copy_app_size", "0"); - ef_save_env(); - } else { - /* wait some time for terminal response finish */ - rtos_delay_milliseconds(bk_get_ticks_per_second()); - os_printf("Update user app fail.\n"); - } -} -MSH_CMD_EXPORT(update, Update user application); diff --git a/bk7235/liteos_m/bk_sdk_armino/components/easy_flash/demo/log/easylogger.c b/bk7235/liteos_m/bk_sdk_armino/components/easy_flash/demo/log/easylogger.c deleted file mode 100644 index 05d52d46aba0441056be36f9473314081d633c18..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/easy_flash/demo/log/easylogger.c +++ /dev/null @@ -1,94 +0,0 @@ -/* - * This file is part of the EasyFlash Library. - * - * Copyright (c) 2015-2017, Armink, - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * 'Software'), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY - * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * Function: It's a demo for EasyFlash Log fucnction. You must use EasyLogger(https://github.com/armink/EasyLogger). - * Created on: 2015-07-06 - */ - -#define LOG_TAG "main" - -#include "elog_flash.h" - -static void test_elog(void); -static void elog_user_assert_hook(const char *ex, const char *func, size_t line); - -int main(void) -{ - - /* initialize EasyFlash and EasyLogger */ - if ((easyflash_init() == EF_NO_ERR) && (elog_init() == ELOG_NO_ERR)) { - /* set EasyLogger log format */ - elog_set_fmt(ELOG_LVL_ASSERT, ELOG_FMT_ALL & ~ELOG_FMT_P_INFO); - elog_set_fmt(ELOG_LVL_ERROR, ELOG_FMT_LVL | ELOG_FMT_TAG | ELOG_FMT_TIME); - elog_set_fmt(ELOG_LVL_WARN, ELOG_FMT_LVL | ELOG_FMT_TAG | ELOG_FMT_TIME); - elog_set_fmt(ELOG_LVL_INFO, ELOG_FMT_LVL | ELOG_FMT_TAG | ELOG_FMT_TIME); - elog_set_fmt(ELOG_LVL_DEBUG, ELOG_FMT_ALL & ~(ELOG_FMT_FUNC | ELOG_FMT_P_INFO)); - elog_set_fmt(ELOG_LVL_VERBOSE, ELOG_FMT_ALL & ~(ELOG_FMT_FUNC | ELOG_FMT_P_INFO)); - /* set EasyLogger assert hook */ - elog_assert_set_hook(elog_user_assert_hook); - /* initialize EasyLogger Flash plugin */ - elog_flash_init(); - /* start EasyLogger */ - elog_start(); - /* set EasyLogger assert hook */ - elog_assert_set_hook(elog_user_assert_hook); - /* test logger output */ - test_elog(); - } - - return 0; -} - -/** - * Elog demo - */ -static void test_elog(void) -{ - /* output all saved log from flash */ - elog_flash_output_all(); - /* test log output for all level */ - log_a("Hello EasyLogger!"); - log_e("Hello EasyLogger!"); - log_w("Hello EasyLogger!"); - log_i("Hello EasyLogger!"); - log_d("Hello EasyLogger!"); - log_v("Hello EasyLogger!"); - elog_raw("Hello EasyLogger!"); - /* trigger assert. Now will run elog_user_assert_hook. All log information will save to flash. */ - ELOG_ASSERT(0); -} - -static void elog_user_assert_hook(const char *ex, const char *func, size_t line) -{ - rt_enter_critical(); - /* disable logger output lock */ - elog_output_lock_enabled(false); - /* disable flash plugin lock */ - elog_flash_lock_enabled(false); - /* output assert information */ - elog_a("elog", "(%s) has assert failed at %s:%ld.\n", ex, func, line); - /* write all buffered log to flash */ - elog_flash_flush(); - while (1); -} diff --git a/bk7235/liteos_m/bk_sdk_armino/components/easy_flash/docs/en/api.md b/bk7235/liteos_m/bk_sdk_armino/components/easy_flash/docs/en/api.md deleted file mode 100644 index f65681d75cab53c96f30e729d71b84e241dbd41a..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/easy_flash/docs/en/api.md +++ /dev/null @@ -1 +0,0 @@ -# Coming soon... \ No newline at end of file diff --git a/bk7235/liteos_m/bk_sdk_armino/components/easy_flash/docs/en/images/EnvDemo.gif b/bk7235/liteos_m/bk_sdk_armino/components/easy_flash/docs/en/images/EnvDemo.gif deleted file mode 100644 index ee93f118b5dcf31915c368bc4599138dd7988d33..0000000000000000000000000000000000000000 Binary files a/bk7235/liteos_m/bk_sdk_armino/components/easy_flash/docs/en/images/EnvDemo.gif and /dev/null differ diff --git a/bk7235/liteos_m/bk_sdk_armino/components/easy_flash/docs/en/images/IapDemo.gif b/bk7235/liteos_m/bk_sdk_armino/components/easy_flash/docs/en/images/IapDemo.gif deleted file mode 100644 index a35c6862029a7b34f832ffec7d9d54af71a9ea9f..0000000000000000000000000000000000000000 Binary files a/bk7235/liteos_m/bk_sdk_armino/components/easy_flash/docs/en/images/IapDemo.gif and /dev/null differ diff --git a/bk7235/liteos_m/bk_sdk_armino/components/easy_flash/docs/en/images/LogDemo.gif b/bk7235/liteos_m/bk_sdk_armino/components/easy_flash/docs/en/images/LogDemo.gif deleted file mode 100644 index b99b66220aceae86682d7d9441805b62160452ac..0000000000000000000000000000000000000000 Binary files a/bk7235/liteos_m/bk_sdk_armino/components/easy_flash/docs/en/images/LogDemo.gif and /dev/null differ diff --git a/bk7235/liteos_m/bk_sdk_armino/components/easy_flash/docs/en/readme.md b/bk7235/liteos_m/bk_sdk_armino/components/easy_flash/docs/en/readme.md deleted file mode 100644 index 916db5a853a3c01f67b957861e30e9607074504d..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/easy_flash/docs/en/readme.md +++ /dev/null @@ -1,3 +0,0 @@ -|File name |Description| -|:----- |:----| -|api.md |API description| \ No newline at end of file diff --git a/bk7235/liteos_m/bk_sdk_armino/components/easy_flash/docs/readme.md b/bk7235/liteos_m/bk_sdk_armino/components/easy_flash/docs/readme.md deleted file mode 100644 index da9229a0bf41c4c4ad48d4d4e863c7f5d68a63c4..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/easy_flash/docs/readme.md +++ /dev/null @@ -1,4 +0,0 @@ -|File or folder name |Description| -|:----- |:----| -|en |English documents| -|zh |中文文档(简体)| \ No newline at end of file diff --git a/bk7235/liteos_m/bk_sdk_armino/components/easy_flash/docs/zh/api.md b/bk7235/liteos_m/bk_sdk_armino/components/easy_flash/docs/zh/api.md deleted file mode 100644 index d7d65c877070149504038941231c448e2536eb52..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/easy_flash/docs/zh/api.md +++ /dev/null @@ -1,269 +0,0 @@ -# EasyFlash API 说明 - ---- - -所有支持的API接口都在[`\easyflash\inc\easyflash.h`](https://github.com/armink/EasyFlash/blob/master/easyflash/inc/easyflash.h)中声明。以下内容较多,建议使用 **CTRL+F** 搜索。 - -名词介绍: - -**备份区** :是EasyFlash定义的一个存放环境变量、已下载程序及日志的Flash区域,详细存储架构可以参考[`\easyflash\src\easyflash.c`](https://github.com/armink/EasyFlash/blob/master/easyflash/src/easyflash.c#L29-L58)文件头位置的注释说明或[移植文档中关于备份区参数配置](https://github.com/armink/EasyFlash/blob/master/docs/zh/port.md#55-备份区)。 - -**环境变量表** :负责存放所有的环境变量,该表在Flash及RAM中均存在,上电后需从Flash加载到RAM中,修改后,则需要保存其至Flash中。。 - -## 1、用户使用接口 - -### 1.1 初始化 - -初始化的EasyFlash的各个组件,初始化后才可以使用下面的API。 - -```C -EfErrCode easyflash_init(void) -``` - -### 1.2 环境变量 - -#### 1.2.1 加载环境变量 - -加载Flash中的所有环境变量到系统内存中。 - -```C -void ef_load_env(void) -``` - -#### 1.2.2 打印环境变量 - -通过在移植接口([`\easyflash\port\ef_port.c`](https://github.com/armink/EasyFlash/blob/master/easyflash/port/ef_port.c))中定义的`ef_print`打印方法,来将Flash中的所有环境变量输出出来。 - -```C -void ef_print_env(void) -``` - -#### 1.2.3 获取环境变量 - -通过环境变量的名字来获取其对应的值。(注意:此处的环境变量指代的已加载到内存中的环境变量) - -```C -char *ef_get_env(const char *key) -``` - -|参数 |描述| -|:----- |:----| -|key |环境变量名称| - -#### 1.2.4 设置环境变量 - -使用此方法可以实现对环境变量的增加、修改及删除功能。(注意:此处的环境变量指代的已加载到内存中的环境变量) - -- **增加** :当环境变量表中不存在该名称的环境变量时,则会执行新增操作; - -- **修改** :入参中的环境变量名称在当前环境变量表中存在,则把该环境变量值修改为入参中的值; - -- **删除** :当入参中的value为空时,则会删除入参名对应的环境变量。 - -```C -EfErrCode ef_set_env(const char *key, const char *value) -``` - -|参数 |描述| -|:----- |:----| -|key |环境变量名称| -|value |环境变量值| - -#### 1.2.5 保存环境变量 - -保存内存中的环境变量表到Flash中。 - -```C -EfErrCode ef_save_env(void) -``` - -#### 1.2.6 重置环境变量 -将内存中的环境变量表重置为默认值。 - -```C -EfErrCode ef_env_set_default(void) -``` - -#### 1.2.7 获取当前环境变量写入到Flash的字节大小 - -```C -size_t ef_get_env_write_bytes(void) -``` - -#### 1.2.8 设置并保存环境变量 - -设置环境变量成功后立刻保存。设置功能参考`ef_set_env`方法。 - -```C -EfErrCode ef_set_and_save_env(const char *key, const char *value) -``` - -|参数 |描述| -|:----- |:----| -|key |环境变量名称| -|value |环境变量值| - -### 1.3 在线升级 - -#### 1.3.1 擦除备份区中的应用程序 - -```C -EfErrCode ef_erase_bak_app(size_t app_size) -``` - -#### 1.3.2 擦除用户的应用程序 - -注意:请不要在应用程序中调用该方法 - -```C -EfErrCode ef_erase_user_app(uint32_t user_app_addr, size_t user_app_size) -``` - -|参数 |描述| -|:----- |:----| -|user_app_addr |用户应用程序入口地址| -|user_app_size |用户应用程序大小| - -#### 1.3.3 通过用户指定的擦除方法来擦除应用程序 - -当用户的应用程序与备份区 **不在同一个** Flash 时,则需要用户额外指定擦除应用程序的方法。而 `ef_erase_user_app` 会使用移植文件中的 `ef_port_erase` 方法进行擦除,除此之外的其余功能,两个方法均一致。 - -注意:请不要在应用程序中调用该方法 - -```C -EfErrCode ef_erase_spec_user_app(uint32_t user_app_addr, size_t app_size, - EfErrCode (*app_erase)(uint32_t addr, size_t size)); -``` - -|参数 |描述| -|:----- |:----| -|user_app_addr |用户应用程序入口地址| -|user_app_size |用户应用程序大小| -|app_erase |用户指定应用程序擦写方法| - -#### 1.3.4 擦除Bootloader - -注意:请不要在Bootloader中调用该方法 - -```C -EfErrCode ef_erase_bl(uint32_t bl_addr, size_t bl_size) -``` - -|参数 |描述| -|:----- |:----| -|bl_addr |Bootloader入口地址| -|bl_size |Bootloader大小| - -#### 1.3.5 写数据到备份区 - -为下载程序到备份区定制的Flash连续写方法。 -注意:写之前请先确认Flash已进行擦除。 - -```C -EfErrCode ef_write_data_to_bak(uint8_t *data, - size_t size, - size_t *cur_size, - size_t total_size) -``` - -|参数 |描述| -|:----- |:----| -|data |需要写入到备份区中的数据存储地址| -|size |此次写入数据的大小(字节)| -|cur_size |之前已写入到备份区中的数据大小(字节)| -|total_size |需要写入到备份区的数据总大小(字节)| - -#### 1.3.6 从备份拷贝应用程序 - -将备份区已下载好的应用程序拷贝至用户应用程序起始地址。 -注意: -1、拷贝前必须对原有的应用程序进行擦除 -2、不要在应用程序中调用该方法 - -```C -EfErrCode ef_copy_app_from_bak(uint32_t user_app_addr, size_t app_size) -``` - -|参数 |描述| -|:----- |:----| -|user_app_addr |用户应用程序入口地址| -|user_app_size |用户应用程序大小| - -#### 1.3.7 通过用户指定的写操作方法来拷贝应用程序 - -当用户的应用程序与备份区 **不在同一个** Flash 时,则需要用户额外指定写应用程序的方法。而 `ef_copy_app_from_bak` 会使用移植文件中的 `ef_port_write` 方法进行写操作,除此之外的其余功能,两个方法均一致。 - -```C -EfErrCode ef_copy_spec_app_from_bak(uint32_t user_app_addr, size_t app_size, - EfErrCode (*app_write)(uint32_t addr, const uint32_t *buf, size_t size)) -``` - -|参数 |描述| -|:----- |:----| -|user_app_addr |用户应用程序入口地址| -|user_app_size |用户应用程序大小| -|app_write |用户指定应用程序写操作方法| - -#### 1.3.8 从备份拷贝Bootloader - -将备份区已下载好的Bootloader拷贝至Bootloader起始地址。 -注意: -1、拷贝前必须对原有的Bootloader进行擦除 -2、不要在Bootloader中调用该方法 - -```C -EfErrCode ef_copy_bl_from_bak(uint32_t bl_addr, size_t bl_size) -``` - -|参数 |描述| -|:----- |:----| -|bl_addr |Bootloader入口地址| -|bl_size |Bootloader大小| - -### 1.4 日志存储 - -#### 1.4.1 从Flash中读取已存在的日志 - -```C -EfErrCode ef_log_read(size_t index, uint32_t *log, size_t size); -``` - -|参数 |描述| -|:----- |:----| -|index |日志读取的索引顺序| -|log |存储待读取日志的缓冲区| -|size |读取日志的大小| - -#### 1.4.2 往Flash中保存日志 - -```C -EfErrCode ef_log_write(const uint32_t *log, size_t size); -``` - -|参数 |描述| -|:----- |:----| -|log |存储待保存的日志| -|size |待保存日志的大小| - -#### 1.4.3 清空存储在Flash中全部日志 - -```C -EfErrCode ef_log_clean(void); -``` - -#### 1.4.4 获取已存储在Flash中的日志大小 - -```C -size_t ef_log_get_used_size(void); -``` - -## 2、配置 - -参照EasyFlash 移植说明([`\docs\zh\port.md`](https://github.com/armink/EasyFlash/blob/master/docs/zh/port.md#5设置参数))中的 `设置参数` 章节 - -## 3、注意 - -- 写数据前务必记得先擦除 -- 环境变量设置完后,只有调用`ef_save_env`才会保存在Flash中,否则开机会丢失修改的内容 -- 不要在应用程序及Bootloader中执行擦除及拷贝自身的动作 -- ENV及Log功能对Flash擦除和写入要求4个字节对齐,擦除的最小单位则需根据用户的平台来确定 diff --git a/bk7235/liteos_m/bk_sdk_armino/components/easy_flash/docs/zh/images/BackupAreaPartition.jpg b/bk7235/liteos_m/bk_sdk_armino/components/easy_flash/docs/zh/images/BackupAreaPartition.jpg deleted file mode 100644 index e5cb4bcbd732e0a0a611622cb191d149665f75a6..0000000000000000000000000000000000000000 Binary files a/bk7235/liteos_m/bk_sdk_armino/components/easy_flash/docs/zh/images/BackupAreaPartition.jpg and /dev/null differ diff --git a/bk7235/liteos_m/bk_sdk_armino/components/easy_flash/docs/zh/images/EnvDemo.gif b/bk7235/liteos_m/bk_sdk_armino/components/easy_flash/docs/zh/images/EnvDemo.gif deleted file mode 100644 index 92cdcc85742410f0b932bb9fb29bec31bae4ef5f..0000000000000000000000000000000000000000 Binary files a/bk7235/liteos_m/bk_sdk_armino/components/easy_flash/docs/zh/images/EnvDemo.gif and /dev/null differ diff --git a/bk7235/liteos_m/bk_sdk_armino/components/easy_flash/docs/zh/images/IapDemo.gif b/bk7235/liteos_m/bk_sdk_armino/components/easy_flash/docs/zh/images/IapDemo.gif deleted file mode 100644 index a35c6862029a7b34f832ffec7d9d54af71a9ea9f..0000000000000000000000000000000000000000 Binary files a/bk7235/liteos_m/bk_sdk_armino/components/easy_flash/docs/zh/images/IapDemo.gif and /dev/null differ diff --git a/bk7235/liteos_m/bk_sdk_armino/components/easy_flash/docs/zh/images/LogDemo.gif b/bk7235/liteos_m/bk_sdk_armino/components/easy_flash/docs/zh/images/LogDemo.gif deleted file mode 100644 index b99b66220aceae86682d7d9441805b62160452ac..0000000000000000000000000000000000000000 Binary files a/bk7235/liteos_m/bk_sdk_armino/components/easy_flash/docs/zh/images/LogDemo.gif and /dev/null differ diff --git a/bk7235/liteos_m/bk_sdk_armino/components/easy_flash/docs/zh/port.md b/bk7235/liteos_m/bk_sdk_armino/components/easy_flash/docs/zh/port.md deleted file mode 100644 index 2edb3e18b37d0174efb55d948f64a3bd622d02c9..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/easy_flash/docs/zh/port.md +++ /dev/null @@ -1,262 +0,0 @@ -# EasyFlash 移植说明 - ---- - -## 1、下载源码 - -[点击此链接](https://github.com/armink/EasyFlash/archive/master.zip)即可直接下载位于Github上的源码。 - -> 建议:点击项目主页 https://github.com/armink/EasyFlash 右上角 **Watch & Star**,这样项目有更新时,会及时以邮件形式通知你。 - -如果Github下载太慢,也可以点击项目位于的国内仓库下载的链接([OSChina](https://git.oschina.net/Armink/EasyFlash/repository/archive?ref=master)|[Coding](https://coding.net/u/armink/p/EasyFlash/git/archive/master))。 - -## 2、导入项目 - -在导入到项目前,先打开[`\demo\`](https://github.com/armink/EasyFlash/tree/master/demo)文件夹,检查下有没有与项目Flash规格一致的Demo。如果有则先直接跳过2、3、4章节,按照第5章的要求设置参数,并运行、验证Demo。验证通过再按照下面的导入项目要求,将Demo中的移植文件直接导入到项目中即可。 - -- 1、先解压下载好的源码包,文件的目录结构大致如下: - -|源文件 |描述 | -|:------------------------------ |:----- | -|\easyflash\src\ef_env.c |Env(常规模式)相关操作接口及实现源码| -|\easyflash\src\ef_env_wl.c |Env(磨损平衡模式)相关操作接口及实现源码| -|\easyflash\src\ef_iap.c |IAP 相关操作接口及实现源码| -|\easyflash\src\ef_log.c |Log 相关操作接口及实现源码| -|\easyflash\src\ef_utils.c |EasyFlash常用小工具,例如:CRC32| -|\easyflash\src\easyflash.c |目前只包含EasyFlash初始化方法| -|\easyflash\port\ef_port.c |不同平台下的EasyFlash移植接口| -|\demo\env\stm32f10x\non_os |stm32f10x裸机片内Flash的Env demo| -|\demo\env\stm32f10x\non_os_spi_flash |stm32f10x裸机SPI Flash的Env demo| -|\demo\env\stm32f10x\rtt |stm32f10x基于[RT-Thread](http://www.rt-thread.org/)的片内Flash Env demo| -|\demo\env\stm32f4xx |stm32f4xx基于[RT-Thread](http://www.rt-thread.org/)的片内Flash Env demo| -|\demo\iap\ymodem+rtt.c |使用[RT-Thread](http://www.rt-thread.org/)+[Ymodem](https://github.com/RT-Thread/rt-thread/tree/master/components/utilities/ymodem)的IAP Demo| -|\demo\log\easylogger.c |基于[EasyLogger](https://github.com/armink/EasyLogger)的Log Demo| - - -- 2、将`\easyflash\`(里面包含`inc`、`src`及`port`的那个)文件夹拷贝到项目中; -- 3、添加`\easyflash\src\easyflash.c`、`\easyflash\src\ef_utils.c`及`\easyflash\port\ef_port.c`这些文件到项目的编译路径中; -- 4、根据项目需求,选择性添加`\easyflash\src\`中的其他源码文件到项目的编译路径中; -- 5、添加`\easyflash\inc\`文件夹到编译的头文件目录列表中; - -## 3、Flash规格 - -在移植时务必先要了解项目的Flash规格,这里需要了解是规格是 **最小擦除单位** 及 **内部存储结构** ,各个厂家的Flash规格都有差异,同一厂家不同系列的规格也有差异。例如:stm32f10x系列中的大容量MCU自带Flash的页大小均为2K,而中小容量的页大小均为1K。在stm32f4xx系列中,每个页大小不是像stm32f10x那样平均分配,最大的有128K,最小的有16K。 - -> 注意:务必保证熟悉Flash规格后,再继续下章节。 - -## 4、移植接口 - -### 4.1 移植初始化 - -EasyFlash移植初始化。可以传递默认环境变量,初始化EasyFlash移植所需的资源等等。 - -```C -EfErrCode ef_port_init(ef_env const **default_env, size_t *default_env_size) -``` - -|参数 |描述| -|:----- |:----| -|default_env |默认的环境变量| -|default_env_size |默认环境变量的数量| - -### 4.2 读取Flash - -最小单位为4个字节。 - -```C -EfErrCode ef_port_read(uint32_t addr, uint32_t *buf, size_t size) -``` - -|参数 |描述| -|:----- |:----| -|addr |读取起始地址| -|buf |存放读取数据的缓冲区| -|size |读取数据的大小(字节)| - -### 4.3 擦除Flash - -```C -EfErrCode ef_port_erase(uint32_t addr, size_t size) -``` - -|参数 |描述| -|:----- |:----| -|addr |擦除起始地址| -|size |擦除数据的大小(字节)| - -### 4.4 写入Flash - -最小单位为4个字节。 - -```C -EfErrCode ef_port_write(uint32_t addr, const uint32_t *buf, size_t size) -``` - -|参数 |描述| -|:----- |:----| -|addr |写入的起始地址| -|buf |源数据的缓冲区| -|size |写入数据的大小(字节)| - -### 4.5 对环境变量缓冲区加锁 - -为了保证RAM缓冲区在并发执行的安全性,所以需要对其进行加锁(如果项目的使用场景不存在并发情况,则可以忽略)。有操作系统时可以使用获取信号量来加锁,裸机时可以通过关闭全局中断来加锁。 - -```C -void ef_port_env_lock(void) -``` - -### 4.6 对环境变量缓冲区解锁 - -有操作系统是可以使用释放信号量来解锁,裸机时可以通过开启全局中断来解锁。 - -```C -void ef_port_env_unlock(void) -``` - -### 4.7 打印调试日志信息 - -在定义`PRINT_DEBUG`宏后,打印调试日志信息。 - -```C -void ef_log_debug(const char *file, const long line, const char *format, ...) -``` - -|参数 |描述| -|:----- |:----| -|file |调用该方法的文件| -|line |调用该方法的行号| -|format |打印格式| -|... |不定参| - -### 4.8 打印普通日志信息 - -```C -void ef_log_info(const char *format, ...) -``` - -|参数 |描述| -|:----- |:----| -|format |打印格式| -|... |不定参| - -### 4.9 无格式打印信息 - -该方法输出无固定格式的打印信息,为`ef_print_env`方法所用(如果不使用`ef_print_env`则可以忽略)。而`ef_log_debug`及`ef_log_info`可以输出带指定前缀及格式的打印日志信息。 - -```C -void ef_print(const char *format, ...) -``` - -|参数 |描述| -|:----- |:----| -|format |打印格式| -|... |不定参| - -## 5、设置参数 - -配置时需要修改项目中的`ef_cfg.h`文件,开启、关闭、修改对应的宏即可。 - -### 5.1 环境变量功能 - -- 默认状态:开启 -- 操作方法:开启、关闭`EF_USING_ENV`宏即可 - -#### 5.1.1 磨损平衡/常规 模式 - -磨损平衡:由于flash在写操作之前需要擦除且使用寿命有限,所以需要设计合理的磨损平衡(写平衡)机制,来保证数据被安全的保存在未到擦写寿命的Flash区中。 - -- 默认状态:常规模式 -- 常规模式:关闭`EF_ENV_USING_WL_MODE` -- 磨损平衡模式:打开`EF_ENV_USING_WL_MODE` - -#### 5.1.2 掉电保护 - -掉电保护:Power Fail Safeguard,当此项设置为可用时,如果在环境变量保存过程中发生掉电,已保存在Flash中的环境变量将不会有丢失的危险。下次上电后,环境变量将会被自动还原至之前的状态。(注意:本保护是基于软件实现的保护功能,更加可靠的掉电保护功能需要通过硬件来实现) - -- 默认状态:关闭 -- 操作方法:开启、关闭`EF_ENV_USING_PFS_MODE`宏即可 - -### 5.2 在线升级功能 - -- 默认状态:开启 -- 操作方法:开启、关闭`EF_USING_IAP`宏即可 - -### 5.3 日志功能 - -- 默认状态:开启 -- 操作方法:开启、关闭`EF_USING_LOG`宏即可 - -### 5.4 Flash最小擦除单位 - -- 操作方法:修改`EF_ERASE_MIN_SIZE`宏对应值即可 - -### 5.5 备份区 - -备份区共计包含3个区域,依次为:环境变量区、日志区及在线升级区。分区方式如下图所示 - -![backup_area_partiton](http://git.oschina.net/Armink/EasyFlash/raw/master/docs/zh/images/BackupAreaPartition.jpg) - -在配置时需要注意以下几点: - -- 1、所有的区域必须按照`EF_ERASE_MIN_SIZE`对齐; -- 2、由于EasyFlash对所有的环境变量都会使用RAM缓存,但是在更多时候用户使用的环境变量大小会比`EF_ERASE_MIN_SIZE`小,所以需要再定义`ENV_USER_SETTING_SIZE`来指定用户设定的环境变量大小。 -- 3、环境变量区总容量在不同的模式下会有差异 - - 1、常规模式:没有差异; - - 2、擦写平衡模式:系统区将会占用1个`EF_ERASE_MIN_SIZE`大小,数据区至少等使用2个以上Flash扇区; - - 3、掉电保护模式:环境变量区将会被备份,所以总容量是常规模式的2倍; - - 4、擦写平衡+掉电保护模式:所需容量将会是擦写平衡模式下总容量的2倍。 - - 例如:`EF_ERASE_MIN_SIZE`是128K,`ENV_USER_SETTING_SIZE`是2K,那么你可以这样定义不同模式下的环境变量总容量: - - 1、常规模式:`1*EF_ERASE_MIN_SIZE`; - - 2、擦写平衡模式:`3*EF_ERASE_MIN_SIZE`(它将会有3个Flash扇区去存储环境变量,1个系统区,2个数据区,按照每个Flash扇区可被擦写10W次计算,那么当前配置至少可擦写20W次); - - 3、掉电保护模式:`2*EF_ERASE_MIN_SIZE`; - - 4、擦写平衡+掉电保护模式:`6*EF_ERASE_MIN_SIZE`; - -#### 5.5.1 备份区起始地址 - -- 操作方法:修改`EF_START_ADDR`宏对应值即可 - -#### 5.5.2 用户设定环境变量大小 - -- 操作方法:修改`ENV_USER_SETTING_SIZE`宏对应值即可 - -> 注意:不使用环境变量功能时,可以不定义此宏。 - -#### 5.5.3 环境变量区总容量 - -- 操作方法:修改`ENV_AREA_SIZE`宏对应值即可 - -> 注意:不使用环境变量功能时,可以不定义此宏。 - -#### 5.5.4 日志区总容量 - -- 操作方法:修改`LOG_AREA_SIZE`宏对应值即可 - -> 注意:不使用日志功能时,可以不定义此宏。 - -### 5.6 调试日志 - -开启后,将会库运行时自动输出调试日志 - -- 默认状态:开启 -- 操作方法:开启、关闭`PRINT_DEBUG`宏即可 - -## 6、测试验证 - -如果`\demo\`文件夹下有与项目Flash规格一致的Demo,则直接编译运行,观察测试结果即可。无需关注下面的步骤。 - -每次使用前,务必先执行`easyflash_init()`方法对EasyFlash库及所使用的Flash进行初始化,保证初始化没问题后,再使用各功能的API方法。如果出现错误或断言,需根据提示信息检查移植配置及接口。 - -### 6.1 环境变量 - -查看[`\demo\env\`](https://github.com/armink/EasyFlash/tree/master/demo/env)子文件夹中例子的`README.md`说明文档。测试时可以将`\demo\env\stm32f10x\non_os\app\src\app.c`中的`static void test_env(void)`方法体复制到项目中,然后运行测试。 - -### 6.2 在线升级 - -查看[`\demo\iap\README.md`](https://github.com/armink/EasyFlash/tree/master/demo/iap)说明文档。 - -### 6.3 日志 - -查看[`\demo\log\README.md`](https://github.com/armink/EasyFlash/tree/master/demo/log)说明文档。 - -> 注意:`easylogger.c`是使用[EasyLogger](https://github.com/armink/EasyLogger)与EasyFlash的无缝接口的例子,EasyLogger提供针对日志的很多常用功能封装,详细功能可以查看其介绍。使用这个例子时,务必记得将EasyLogger一并导入到项目中。 \ No newline at end of file diff --git a/bk7235/liteos_m/bk_sdk_armino/components/easy_flash/docs/zh/readme.md b/bk7235/liteos_m/bk_sdk_armino/components/easy_flash/docs/zh/readme.md deleted file mode 100644 index 167b423e1aee96b3ac966d1deb68278e7870523c..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/easy_flash/docs/zh/readme.md +++ /dev/null @@ -1,4 +0,0 @@ -|文件名 |描述| -|:----- |:----| -|api.md |API 说明| -|port.md |移植说明| \ No newline at end of file diff --git a/bk7235/liteos_m/bk_sdk_armino/components/easy_flash/inc/easyflash.h b/bk7235/liteos_m/bk_sdk_armino/components/easy_flash/inc/easyflash.h deleted file mode 100644 index 85419e85e71ff4ddff7d5bf64103a86c21236127..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/easy_flash/inc/easyflash.h +++ /dev/null @@ -1,149 +0,0 @@ -/* - * This file is part of the EasyFlash Library. - * - * Copyright (c) 2014-2018, Armink, - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * 'Software'), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY - * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * Function: It is an head file for this library. You can see all be called functions. - * Created on: 2014-09-10 - */ -#ifndef _EASYFLASH_H_ -#define _EASYFLASH_H_ - -#include -#include -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -#if defined(EF_USING_ENV) && (!defined(ENV_USER_SETTING_SIZE) || !defined(ENV_AREA_SIZE)) -#error "Please configure user setting ENV size or ENV area size (in ef_cfg.h)" -#endif - -#if defined(EF_USING_LOG) && !defined(LOG_AREA_SIZE) -#error "Please configure log area size (in ef_cfg.h)" -#endif - -#if !defined(EF_START_ADDR) -#error "Please configure backup area start address (in ef_cfg.h)" -#endif - -#if !defined(EF_ERASE_MIN_SIZE) -#error "Please configure minimum size of flash erasure (in ef_cfg.h)" -#endif - -/* EasyFlash debug print function. Must be implement by user. */ -#define EF_DEBUG(...) ef_log_debug(__FILE__, __LINE__, __VA_ARGS__) -/* EasyFlash routine print function. Must be implement by user. */ -#define EF_INFO(...) ef_log_info(__VA_ARGS__) -/* EasyFlash assert for developer. */ -#define EF_ASSERT(EXPR) \ - if (!(EXPR)) \ - { \ - EF_DEBUG("(%s) has assert failed at %s.\n", #EXPR, __FUNCTION__); \ - while (1); \ - } -/* EasyFlash software version number */ -#define EF_SW_VERSION "3.0.4" - -typedef struct _ef_env { - char *key; - char *value; -} ef_env, *ef_env_t; - -/* EasyFlash error code */ -typedef enum { - EF_NO_ERR, - EF_ERASE_ERR, - EF_WRITE_ERR, - EF_ENV_NAME_ERR, - EF_ENV_NAME_EXIST, - EF_ENV_FULL, - EF_ENV_INIT_FAILED, -} EfErrCode; - -/* the flash sector current status */ -typedef enum { - EF_SECTOR_EMPTY, - EF_SECTOR_USING, - EF_SECTOR_FULL, -} EfSecrorStatus; - -/* easyflash.c */ -EfErrCode easyflash_init(void); - -#ifdef EF_USING_ENV -/* ef_env.c ef_env_wl.c */ -EfErrCode ef_load_env(void); -void ef_print_env(void); -char *ef_get_env(const char *key); -EfErrCode ef_set_env(const char *key, const char *value); -EfErrCode ef_save_env(void); -EfErrCode ef_env_set_default(void); -size_t ef_get_env_write_bytes(void); -EfErrCode ef_set_and_save_env(const char *key, const char *value); -#endif - -#ifdef EF_USING_IAP -/* ef_iap.c */ -EfErrCode ef_erase_bak_app(size_t app_size); -EfErrCode ef_erase_user_app(uint32_t user_app_addr, size_t user_app_size); -EfErrCode ef_erase_spec_user_app(uint32_t user_app_addr, size_t app_size, - EfErrCode(*app_erase)(uint32_t addr, size_t size)); -EfErrCode ef_erase_bl(uint32_t bl_addr, size_t bl_size); -EfErrCode ef_write_data_to_bak(uint8_t *data, size_t size, size_t *cur_size, - size_t total_size); -EfErrCode ef_copy_app_from_bak(uint32_t user_app_addr, size_t app_size); -EfErrCode ef_copy_spec_app_from_bak(uint32_t user_app_addr, size_t app_size, - EfErrCode(*app_write)(uint32_t addr, const uint32_t *buf, size_t size)); -EfErrCode ef_copy_bl_from_bak(uint32_t bl_addr, size_t bl_size); -uint32_t ef_get_bak_app_start_addr(void); -#endif - -#ifdef EF_USING_LOG -/* ef_log.c */ -EfErrCode ef_log_read(size_t index, uint32_t *log, size_t size); -EfErrCode ef_log_write(const uint32_t *log, size_t size); -EfErrCode ef_log_clean(void); -size_t ef_log_get_used_size(void); -#endif - -/* ef_utils.c */ -uint32_t ef_calc_crc32(uint32_t crc, const void *buf, size_t size); - -/* ef_port.c */ -EfErrCode ef_port_read(uint32_t addr, uint32_t *buf, size_t size); -EfErrCode ef_port_erase(uint32_t addr, size_t size); -EfErrCode ef_port_write(uint32_t addr, const uint32_t *buf, size_t size); -void ef_port_env_lock(void); -void ef_port_env_unlock(void); -void ef_log_debug(const char *file, const long line, const char *format, ...); -void ef_log_info(const char *format, ...); -void ef_print(const char *format, ...); - -#ifdef __cplusplus -} -#endif - -#endif /* EASYFLASH_H_ */ diff --git a/bk7235/liteos_m/bk_sdk_armino/components/easy_flash/port/ef_cfg.h b/bk7235/liteos_m/bk_sdk_armino/components/easy_flash/port/ef_cfg.h deleted file mode 100644 index afed386186762116aeae7bb60a23af54a067e6b0..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/easy_flash/port/ef_cfg.h +++ /dev/null @@ -1,107 +0,0 @@ -/* - * This file is part of the EasyFlash Library. - * - * Copyright (c) 2015, Armink, - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * 'Software'), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY - * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * Function: It is the configure head file for this library. - * Created on: 2015-07-14 - */ -#ifndef _EF_CFG_H_ -#define _EF_CFG_H_ - -/* using ENV function */ -#define EF_USING_ENV - -/* using wear leveling mode for ENV */ -/* #define EF_ENV_USING_WL_MODE */ - -/* using power fail safeguard mode for ENV */ -#define EF_ENV_USING_PFS_MODE - -/* using IAP function */ -//#define EF_USING_IAP - -/* using save log function */ -//#define EF_USING_LOG - -/* the minimum size of flash erasure */ -#define EF_ERASE_MIN_SIZE 4096 - -/** - * - * This all Backup Area Flash storage index. All used flash area configure is under here. - * |----------------------------| Storage Size - * | Environment variables area | ENV area size @see ENV_AREA_SIZE - * | 1.system section | ENV_SYSTEM_SIZE - * | 2:data section | ENV_AREA_SIZE - ENV_SYSTEM_SIZE - * |----------------------------| - * | Saved log area | Log area size @see LOG_AREA_SIZE - * |----------------------------| - * |(IAP)Downloaded application | IAP already downloaded application, unfixed size - * |----------------------------| - * - * @note all area size must be aligned with EF_ERASE_MIN_SIZE - * @note EasyFlash will use ram to buffered the ENV. At some time flash's EF_ERASE_MIN_SIZE is so big, - * and you want use ENV size is less than it. So you must defined ENV_USER_SETTING_SIZE for ENV. - * @note ENV area size has some limitations in different modes. - * 1.Normal mode: no more limitations - * 2.Wear leveling mode: system section will used an flash section and the data section will used at least 2 flash sections - * 3.Power fail safeguard mode: ENV area will has an backup. It is twice as normal mode. - * 4.wear leveling and power fail safeguard mode: The required capacity will be 2 times the total capacity in wear leveling mode. - * For example: - * The EF_ERASE_MIN_SIZE is 128K and the ENV_USER_SETTING_SIZE: 2K. The ENV_AREA_SIZE in different mode you can define - * 1.Normal mode: 1*EF_ERASE_MIN_SIZE - * 2.Wear leveling mode: 3*EF_ERASE_MIN_SIZE (It has 2 data section to store ENV. So ENV can erase at least 200,000 times) - * 3.Power fail safeguard mode: 2*EF_ERASE_MIN_SIZE - * 4.Wear leveling and power fail safeguard mode: 6*EF_ERASE_MIN_SIZE - * @note the log area size must be more than twice of EF_ERASE_MIN_SIZE - */ -/* backup area start address */ /* start address of param partition */ -#define EF_START_ADDR 0x3FA000 //(0x400000 - 12*2*1024) //(0x1FC000) - -/* the user setting size of ENV, must be word alignment */ -#define ENV_USER_SETTING_SIZE (12 * 1024 - 20)//(8 * 1024 - 20) - -#ifndef EF_ENV_USING_PFS_MODE -#ifndef EF_ENV_USING_WL_MODE -/* ENV area total bytes size in normal mode. */ -#define ENV_AREA_SIZE (1 * EF_ERASE_MIN_SIZE) /* 4K */ -#else -/* ENV area total bytes size in wear leveling mode. */ -#define ENV_AREA_SIZE (4 * EF_ERASE_MIN_SIZE) /* 16K */ -#endif -#else -#ifndef EF_ENV_USING_WL_MODE -/* ENV area total bytes size in power fail safeguard mode. */ -#define ENV_AREA_SIZE ((12*2/4) * EF_ERASE_MIN_SIZE) /* 16K */ -#else -/* ENV area total bytes size in wear leveling and power fail safeguard mode. */ -#define ENV_AREA_SIZE (6 * EF_ERASE_MIN_SIZE) /* 24K */ -#endif -#endif -/* saved log area size */ -#define LOG_AREA_SIZE (254 * EF_ERASE_MIN_SIZE) /* 1016K */ - -/* print debug information of flash */ -//#define PRINT_DEBUG - -#endif /* EF_CFG_H_ */ diff --git a/bk7235/liteos_m/bk_sdk_armino/components/easy_flash/port/ef_port.c b/bk7235/liteos_m/bk_sdk_armino/components/easy_flash/port/ef_port.c deleted file mode 100644 index 27e5b8fb7873351a109411104d26c58dc49474a1..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/easy_flash/port/ef_port.c +++ /dev/null @@ -1,318 +0,0 @@ -/* - * This file is part of the EasyFlash Library. - * - * Copyright (c) 2015, Armink, - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * 'Software'), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY - * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * Function: Portable interface for stm32f4xx platform. - * Created on: 2015-01-16 - */ -#include -#include -#include -#include -#include - -#if CONFIG_FLASH_ORIGIN_API -#include "bk_flash.h" -#include "flash.h" -#else -#include "driver/flash.h" -#endif - -#include -#include "bk_uart.h" -#include "bk_drv_model.h" - -/* default ENV set for user */ -static const ef_env default_env_set[] = { - {"user", "user"}, -}; - -static beken_semaphore_t env_cache_lock = NULL; - -#ifdef PRINT_DEBUG -static char log_buf[256]; -#endif - -/** - * Flash port for hardware initialize. - * - * @param default_env default ENV set for user - * @param default_env_size default ENV size - * - * @return result - */ -EfErrCode ef_port_init(ef_env const **default_env, size_t *default_env_size) -{ - bk_err_t ret; - EfErrCode result = EF_NO_ERR; - - *default_env = default_env_set; - *default_env_size = sizeof(default_env_set) / sizeof(default_env_set[0]); - - ret = rtos_init_semaphore_adv(&env_cache_lock, 1, 1); - BK_ASSERT(kNoErr == ret); - - return result; -} - -/** - * Read data from flash. - * @note This operation's units is word. - * - * @param addr flash address - * @param buf buffer to store read data - * @param size read bytes size - * - * @return result - */ -EfErrCode ef_port_read(uint32_t addr, uint32_t *buf, size_t size) -{ - EfErrCode result = EF_NO_ERR; - - EF_ASSERT(size % 4 == 0); - -#if CONFIG_FLASH_ORIGIN_API - flash_read((char *)buf, (unsigned long)size, addr); -#else - bk_flash_read_bytes(addr, (uint8_t *)buf, (unsigned long)size); -#endif - - return result; -} - -/* - * size param: The flash size of you want to erase in bytes. - * return: Returns the size of the actual erase. - */ -static int bk_erase(uint32_t addr, size_t size) -{ -#if CONFIG_FLASH_ORIGIN_API - int param; - UINT32 status; - int protect_type; - DD_HANDLE flash_handle; -#else - flash_protect_type_t protect_type; -#endif - unsigned int _size = size; - -#if CONFIG_FLASH_ORIGIN_API - flash_handle = ddev_open(DD_DEV_TYPE_FLASH, &status, 0); - ddev_control(flash_handle, CMD_FLASH_GET_PROTECT, (void *)&protect_type); - - if (FLASH_PROTECT_NONE != protect_type) { - param = FLASH_PROTECT_NONE; - ddev_control(flash_handle, CMD_FLASH_SET_PROTECT, (void *)¶m); - } -#else - protect_type = bk_flash_get_protect_type(); - if (FLASH_PROTECT_NONE != protect_type) { - bk_flash_set_protect_type(FLASH_PROTECT_NONE); - } -#endif - - /* Calculate the start address of the flash sector(4kbytes) */ - addr = addr & 0x00FFF000; - - do { -#if CONFIG_FLASH_ORIGIN_API - flash_ctrl(CMD_FLASH_ERASE_SECTOR, &addr); -#else - bk_flash_erase_sector(addr); -#endif - addr += 4096; - - if (_size < 4096) - _size = 0; - else - _size -= 4096; - - } while (_size); - - if (FLASH_PROTECT_NONE != protect_type) { -#if CONFIG_FLASH_ORIGIN_API - param = protect_type; - ddev_control(flash_handle, CMD_FLASH_SET_PROTECT, (void *)¶m); -#else - bk_flash_set_protect_type(protect_type); -#endif - } - - return size; // return true erase size -} - -/** - * Erase data on flash. - * @note This operation is irreversible. - * @note This operation's units is different which on many chips. - * - * @param addr flash address - * @param size erase bytes size - * - * @return result - */ -EfErrCode ef_port_erase(uint32_t addr, size_t size) -{ - EfErrCode result = EF_NO_ERR; - - /* make sure the start address is a multiple of FLASH_ERASE_MIN_SIZE */ - EF_ASSERT(addr % EF_ERASE_MIN_SIZE == 0); - - bk_erase(addr, size); - - return result; -} - -/** - * Write data to flash. - * @note This operation's units is word. - * @note This operation must after erase. @see flash_erase. - * - * @param addr flash address - * @param buf the write data buffer - * @param size write bytes size - * - * @return result - */ -EfErrCode ef_port_write(uint32_t addr, const uint32_t *buf, size_t size) -{ -#if CONFIG_FLASH_ORIGIN_API - int param; - UINT32 status; - int protect_type; - DD_HANDLE flash_handle; -#else - flash_protect_type_t protect_type; -#endif - EfErrCode result = EF_NO_ERR; - - EF_ASSERT(size % 4 == 0); - -#if CONFIG_FLASH_ORIGIN_API - flash_handle = ddev_open(DD_DEV_TYPE_FLASH, &status, 0); - ddev_control(flash_handle, CMD_FLASH_GET_PROTECT, (void *)&protect_type); - - if (FLASH_PROTECT_NONE != protect_type) { - param = FLASH_PROTECT_NONE; - ddev_control(flash_handle, CMD_FLASH_SET_PROTECT, (void *)¶m); - } - - flash_write((char *)buf, (unsigned long)size, addr); - if (FLASH_PROTECT_NONE != protect_type) { - param = protect_type; - ddev_control(flash_handle, CMD_FLASH_SET_PROTECT, (void *)¶m); - } -#else - protect_type = bk_flash_get_protect_type(); - if (FLASH_PROTECT_NONE != protect_type) { - bk_flash_set_protect_type(FLASH_PROTECT_NONE); - } - - bk_flash_write_bytes(addr, (const uint8_t *)buf, size); - bk_flash_set_protect_type(protect_type); -#endif - - return result; -} - -/** - * lock the ENV ram cache - */ -void ef_port_env_lock(void) -{ - rtos_get_semaphore(&env_cache_lock, BEKEN_WAIT_FOREVER); -} - -/** - * unlock the ENV ram cache - */ -void ef_port_env_unlock(void) -{ - rtos_set_semaphore(&env_cache_lock); -} - -/** - * This function is print flash debug info. - * - * @param file the file which has call this function - * @param line the line number which has call this function - * @param format output format - * @param ... args - * - */ -void ef_log_debug(const char *file, const long line, const char *format, ...) -{ -#ifdef PRINT_DEBUG - va_list args; - - /* args point to the first variable parameter */ - va_start(args, format); - ef_print("[Flash](%s:%ld) ", file, line); - /* must use vprintf to print */ - vsprintf(log_buf, format, args); - ef_print("%s", log_buf); - va_end(args); -#endif -} - -/** - * This function is print flash routine info. - * - * @param format output format - * @param ... args - */ -void ef_log_info(const char *format, ...) -{ -#ifdef PRINT_DEBUG - va_list args; - - /* args point to the first variable parameter */ - va_start(args, format); - ef_print("[Flash]"); - /* must use vprintf to print */ - vsprintf(log_buf, format, args); - ef_print("%s", log_buf); - va_end(args); -#endif -} -/** - * This function is print flash non-package info. - * - * @param format output format - * @param ... args - */ -void ef_print(const char *format, ...) -{ -#ifdef PRINT_DEBUG - va_list args; - - /* args point to the first variable parameter */ - va_start(args, format); - /* must use vprintf to print */ - vsprintf(log_buf, format, args); - os_printf("%s", log_buf); - va_end(args); -#endif -} -// eof - diff --git a/bk7235/liteos_m/bk_sdk_armino/components/easy_flash/src/easyflash.c b/bk7235/liteos_m/bk_sdk_armino/components/easy_flash/src/easyflash.c deleted file mode 100644 index 1a0f2759fa71c9f756cb646cde8d8f0fa7892e01..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/easy_flash/src/easyflash.c +++ /dev/null @@ -1,102 +0,0 @@ -/* - * This file is part of the EasyFlash Library. - * - * Copyright (c) 2014-2016, Armink, - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * 'Software'), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY - * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * Function: Initialize interface for this library. - * Created on: 2014-09-09 - */ - -/** - * - * This all Backup Area Flash storage index. All used flash area configure is under here. - * |----------------------------| Storage Size - * | Environment variables area | ENV area size @see ENV_AREA_SIZE - * | 1.system section | ENV system section size - * | 2:data section | ENV_AREA_SIZE - ENV system section size - * |----------------------------| - * | Saved log area | Log area size @see LOG_AREA_SIZE - * |----------------------------| - * |(IAP)Downloaded application | IAP already downloaded application, unfixed size - * |----------------------------| - * - * @note all area size must be aligned with EF_ERASE_MIN_SIZE - * @note EasyFlash will use ram to buffered the ENV. At some time flash's EF_ERASE_MIN_SIZE is so big, - * and you want use ENV size is less than it. So you must defined ENV_USER_SETTING_SIZE for ENV. - * @note ENV area size has some limitations in different modes. - * 1.Normal mode: no more limitations - * 2.Wear leveling mode: system section will used an flash section and the data section will used at least 2 flash sections - * 3.Power fail safeguard mode: ENV area will has an backup. It is twice as normal mode. - * 4.wear leveling and power fail safeguard mode: The required capacity will be 2 times the total capacity in wear leveling mode. - * For example: - * The EF_ERASE_MIN_SIZE is 128K and the ENV_USER_SETTING_SIZE: 2K. The ENV_AREA_SIZE in different mode you can define - * 1.Normal mode: 1*EF_ERASE_MIN_SIZE - * 2.Wear leveling mode: 3*EF_ERASE_MIN_SIZE (It has 2 data section to store ENV. So ENV can erase at least 200,000 times) - * 3.Power fail safeguard mode: 2*EF_ERASE_MIN_SIZE - * 4.Wear leveling and power fail safeguard mode: 6*EF_ERASE_MIN_SIZE - * @note the log area size must be more than twice of EF_ERASE_MIN_SIZE - */ -#include - -/** - * EasyFlash system initialize. - * - * @return result - */ -EfErrCode easyflash_init(void) -{ - extern EfErrCode ef_port_init(ef_env const **default_env, size_t *default_env_size); - extern EfErrCode ef_env_init(ef_env const * default_env, size_t default_env_size); - extern EfErrCode ef_iap_init(void); - extern EfErrCode ef_log_init(void); - - size_t default_env_set_size = 0; - const ef_env *default_env_set; - EfErrCode result = EF_NO_ERR; - - result = ef_port_init(&default_env_set, &default_env_set_size); - -#ifdef EF_USING_ENV - if (result == EF_NO_ERR) - result = ef_env_init(default_env_set, default_env_set_size); -#endif - -#ifdef EF_USING_IAP - if (result == EF_NO_ERR) - result = ef_iap_init(); -#endif - -#ifdef EF_USING_LOG - if (result == EF_NO_ERR) - result = ef_log_init(); -#endif - - if (result == EF_NO_ERR) - EF_INFO("EasyFlash V%s is initialize success.\n", EF_SW_VERSION); - else - EF_INFO("EasyFlash V%s is initialize fail.\n", EF_SW_VERSION); - EF_INFO("You can get the latest version on https://github.com/armink/EasyFlash .\n"); - - return result; -} -// eof - diff --git a/bk7235/liteos_m/bk_sdk_armino/components/easy_flash/src/ef_env.c b/bk7235/liteos_m/bk_sdk_armino/components/easy_flash/src/ef_env.c deleted file mode 100644 index 4498653e9d5759493f56fada80e7045867b7271c..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/easy_flash/src/ef_env.c +++ /dev/null @@ -1,814 +0,0 @@ -/* - * This file is part of the EasyFlash Library. - * - * Copyright (c) 2014-2018, Armink, - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * 'Software'), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY - * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * Function: Environment variables operating interface. (normal mode) - * Created on: 2014-10-06 - */ - -#include -#include -#include - -#ifdef EF_USING_ENV - -#ifndef EF_ENV_USING_WL_MODE - -/** - * ENV area has 2 sections - * 1. System section - * It storage ENV parameters. (Units: Word) - * 2. Data section - * It storage all ENV. Storage format is key=value\0. - * All ENV must be 4 bytes alignment. The remaining part must fill '\0'. - * - * @note Word = 4 Bytes in this file - * @note It will has two ENV areas(Area0, Area1) when used power fail safeguard mode. - */ - -/* flash ENV parameters index and size in system section */ -enum { - /* data section ENV end address index in system section */ - ENV_PARAM_INDEX_END_ADDR = 0, - -#ifdef EF_ENV_USING_PFS_MODE - /* saved count for ENV area */ - ENV_PARAM_INDEX_SAVED_COUNT, -#endif - - /* data section CRC32 code index in system section */ - ENV_PARAM_INDEX_DATA_CRC, - /* flash ENV parameters word size */ - ENV_PARAM_WORD_SIZE, - /* flash ENV parameters byte size */ - ENV_PARAM_BYTE_SIZE = ENV_PARAM_WORD_SIZE * 4, -}; - -/* default ENV set, must be initialized by user */ -static ef_env const *default_env_set; -/* default ENV set size, must be initialized by user */ -static size_t default_env_set_size = 0; -/* ENV ram cache */ -static uint32_t env_cache[ENV_USER_SETTING_SIZE / 4] = { 0 }; -/* ENV start address in flash */ -static uint32_t env_start_addr = 0; -/* ENV ram cache has changed when ENV created, deleted and changed value. */ -static bool env_cache_changed = false; -/* initialize OK flag */ -static bool init_ok = false; - -#ifdef EF_ENV_USING_PFS_MODE -/* current load ENV area address */ -static uint32_t cur_load_area_addr = 0; -/* next save ENV area address */ -static uint32_t next_save_area_addr = 0; -#endif - -static uint32_t get_env_system_addr(void); -static uint32_t get_env_data_addr(void); -static uint32_t get_env_end_addr(void); -static void set_env_end_addr(uint32_t end_addr); -static EfErrCode write_env(const char *key, const char *value); -static char *find_env(const char *key); -static EfErrCode del_env(const char *key); -static size_t get_env_data_size(void); -static size_t get_env_user_used_size(void); -static EfErrCode create_env(const char *key, const char *value); -static uint32_t calc_env_crc(void); -static bool env_crc_is_ok(void); - -/** - * Flash ENV initialize. - * - * @param default_env default ENV set for user - * @param default_env_size default ENV set size - * - * @note user_size must equal with total_size in normal mode - * - * @return result - */ -EfErrCode ef_env_init(ef_env const *default_env, size_t default_env_size) -{ - EfErrCode result = EF_NO_ERR; - - EF_ASSERT(ENV_AREA_SIZE); - EF_ASSERT(ENV_USER_SETTING_SIZE); - EF_ASSERT(EF_ERASE_MIN_SIZE); - /* must be word alignment for ENV */ - EF_ASSERT(ENV_USER_SETTING_SIZE % 4 == 0); - EF_ASSERT(ENV_AREA_SIZE % 4 == 0); - EF_ASSERT(default_env); - EF_ASSERT(default_env_size < ENV_USER_SETTING_SIZE); - -#ifndef EF_ENV_USING_PFS_MODE - /* total_size must be aligned with erase_min_size */ - if (ENV_USER_SETTING_SIZE % EF_ERASE_MIN_SIZE == 0) - EF_ASSERT(ENV_USER_SETTING_SIZE == ENV_AREA_SIZE); - else - EF_ASSERT((ENV_USER_SETTING_SIZE / EF_ERASE_MIN_SIZE + 1)*EF_ERASE_MIN_SIZE == ENV_AREA_SIZE); -#else - /* total_size must be aligned with erase_min_size */ - if (ENV_USER_SETTING_SIZE % EF_ERASE_MIN_SIZE == 0) { - /* it has double area when used power fail safeguard mode */ - EF_ASSERT(2 * ENV_USER_SETTING_SIZE == ENV_AREA_SIZE); - } else { - /* it has double area when used power fail safeguard mode */ - EF_ASSERT(2 * (ENV_USER_SETTING_SIZE / EF_ERASE_MIN_SIZE + 1)*EF_ERASE_MIN_SIZE == ENV_AREA_SIZE); - } -#endif - - env_start_addr = EF_START_ADDR; - default_env_set = default_env; - default_env_set_size = default_env_size; - - EF_DEBUG("ENV start address is 0x%08X, size is %d bytes.\n", EF_START_ADDR, ENV_AREA_SIZE); - - result = ef_load_env(); - - if (result == EF_NO_ERR) - init_ok = true; - - return result; -} - -/** - * ENV set default. - * - * @return result - */ -EfErrCode ef_env_set_default(void) -{ - EfErrCode result = EF_NO_ERR; - size_t i; - - EF_ASSERT(default_env_set); - EF_ASSERT(default_env_set_size); - - /* lock the ENV cache */ - ef_port_env_lock(); - - /* set environment end address is at data section start address */ - set_env_end_addr(get_env_data_addr()); - -#ifdef EF_ENV_USING_PFS_MODE - /* set saved count to default 0 */ - env_cache[ENV_PARAM_INDEX_SAVED_COUNT] = 0; -#endif - - /* create default ENV */ - for (i = 0; i < default_env_set_size; i++) - create_env(default_env_set[i].key, default_env_set[i].value); - - /* unlock the ENV cache */ - ef_port_env_unlock(); - - result = ef_save_env(); - -#ifdef EF_ENV_USING_PFS_MODE - /* reset other PFS area's data */ - if (result == EF_NO_ERR) { - env_cache_changed = true; - result = ef_save_env(); - } -#endif - - - return result; -} - -/** - * Get ENV system section start address. - * - * @return system section start address - */ -static uint32_t get_env_system_addr(void) -{ -#ifndef EF_ENV_USING_PFS_MODE - return env_start_addr; -#else - return cur_load_area_addr; -#endif -} - -/** - * Get ENV data section start address. - * - * @return data section start address - */ -static uint32_t get_env_data_addr(void) -{ - return get_env_system_addr() + ENV_PARAM_BYTE_SIZE; -} - -/** - * Get ENV end address. - * It's the first word in ENV. - * - * @return ENV end address - */ -static uint32_t get_env_end_addr(void) -{ - /* it is the first word */ - return env_cache[ENV_PARAM_INDEX_END_ADDR]; -} - -/** - * Set ENV end address. - * It's the first word in ENV. - * - * @param end_addr ENV end address - */ -static void set_env_end_addr(uint32_t end_addr) -{ - env_cache[ENV_PARAM_INDEX_END_ADDR] = end_addr; -} - -/** - * Get current ENV data section size. - * - * @return size - */ -static size_t get_env_data_size(void) -{ - if (get_env_end_addr() > get_env_data_addr()) - return get_env_end_addr() - get_env_data_addr(); - else - return 0; -} - -/** - * Get current user used ENV size. - * - * @return bytes - */ -static size_t get_env_user_used_size(void) -{ - if (get_env_end_addr() > get_env_system_addr()) - return get_env_end_addr() - get_env_system_addr(); - else - return 0; -} - -/** - * Get current ENV already write bytes. - * - * @return write bytes - */ -size_t ef_get_env_write_bytes(void) -{ -#ifndef EF_ENV_USING_PFS_MODE - return get_env_user_used_size(); -#else - return get_env_user_used_size() * 2; -#endif -} - -/** - * Write an ENV at the end of cache. - * - * @param key ENV name - * @param value ENV value - * - * @return result - */ -static EfErrCode write_env(const char *key, const char *value) -{ - EfErrCode result = EF_NO_ERR; - size_t key_len = strlen(key), value_len = strlen(value), env_str_len; - char *env_cache_bak = (char *)env_cache; - - /* calculate ENV storage length, contain '=' and '\0'. */ - env_str_len = key_len + value_len + 2; - if (env_str_len % 4 != 0) - env_str_len = (env_str_len / 4 + 1) * 4; - /* check capacity of ENV */ - if (env_str_len + get_env_user_used_size() >= ENV_USER_SETTING_SIZE) - return EF_ENV_FULL; - - /* calculate current ENV ram cache end address */ - env_cache_bak += get_env_user_used_size(); - - /* copy key name */ - memmove(env_cache_bak, key, key_len); - env_cache_bak += key_len; - /* copy equal sign */ - *env_cache_bak = '='; - env_cache_bak++; - /* copy value */ - memmove(env_cache_bak, value, value_len); - env_cache_bak += value_len; - /* fill '\0' for string end sign */ - *env_cache_bak = '\0'; - env_cache_bak ++; - /* fill '\0' for word alignment */ - memset(env_cache_bak, 0, env_str_len - (key_len + value_len + 2)); - set_env_end_addr(get_env_end_addr() + env_str_len); - /* ENV ram cache has changed */ - env_cache_changed = true; - - return result; -} - -/** - * Find ENV. - * - * @param key ENV name - * - * @return found ENV in ram cache - */ -static char *find_env(const char *key) -{ - char *env_start, *env_end, *env, *found_env = NULL; - size_t key_len = strlen(key), env_len; - - if ((key == NULL) || (*key == 0)) { - EF_INFO("Flash ENV name must be not empty!\n"); - return NULL; - } - - /* from data section start to data section end */ - env_start = (char *)((char *) env_cache + ENV_PARAM_BYTE_SIZE); - env_end = (char *)((char *) env_cache + get_env_user_used_size()); - - /* ENV is null */ - if (env_start == env_end) - return NULL; - - env = env_start; - while (env < env_end) { - /* the key length must be equal */ - if (!strncmp(env, key, key_len) && (env[key_len] == '=')) { - found_env = env; - break; - } else { - /* calculate ENV length, contain '\0'. */ - env_len = strlen(env) + 1; - /* next ENV and word alignment */ - if (env_len % 4 == 0) - env += env_len; - else - env += (env_len / 4 + 1) * 4; - } - } - return found_env; -} - -/** - * If the ENV is not exist, create it. - * @see flash_write_env - * - * @param key ENV name - * @param value ENV value - * - * @return result - */ -static EfErrCode create_env(const char *key, const char *value) -{ - EfErrCode result = EF_NO_ERR; - - EF_ASSERT(key); - EF_ASSERT(value); - - if ((key == NULL) || (*key == 0)) { - EF_INFO("Flash ENV name must be not empty!\n"); - return EF_ENV_NAME_ERR; - } - - if (strchr(key, '=')) { - EF_INFO("Flash ENV name can't contain '='.\n"); - return EF_ENV_NAME_ERR; - } - - /* find ENV */ - if (find_env(key)) { - EF_INFO("The name of \"%s\" is already exist.\n", key); - return EF_ENV_NAME_EXIST; - } - /* write ENV at the end of cache */ - result = write_env(key, value); - - return result; -} - -/** - * Delete an ENV in cache. - * - * @param key ENV name - * - * @return result - */ -static EfErrCode del_env(const char *key) -{ - EfErrCode result = EF_NO_ERR; - char *del_env = NULL; - size_t del_env_length, remain_env_length; - - EF_ASSERT(key); - - if ((key == NULL) || (*key == 0)) { - EF_INFO("Flash ENV name must be not NULL!\n"); - return EF_ENV_NAME_ERR; - } - - if (strchr(key, '=')) { - EF_INFO("Flash ENV name or value can't contain '='.\n"); - return EF_ENV_NAME_ERR; - } - - /* find ENV */ - del_env = find_env(key); - - if (!del_env) { - EF_INFO("Not find \"%s\" in ENV.\n", key); - return EF_ENV_NAME_ERR; - } - del_env_length = strlen(del_env); - /* '\0' also must be as ENV length */ - del_env_length ++; - /* the address must multiple of 4 */ - if (del_env_length % 4 != 0) - del_env_length = (del_env_length / 4 + 1) * 4; - /* calculate remain ENV length */ - remain_env_length = get_env_data_size() - - (((uint32_t) del_env + del_env_length) - ((uint32_t) env_cache + ENV_PARAM_BYTE_SIZE)); - /* remain ENV move forward */ - memmove(del_env, del_env + del_env_length, remain_env_length); - /* reset ENV end address */ - set_env_end_addr(get_env_end_addr() - del_env_length); - /* ENV ram cache has changed */ - env_cache_changed = true; - - return result; -} - -/** - * Set an ENV. If it value is empty, delete it. - * If not find it in ENV table, then create it. - * - * @param key ENV name - * @param value ENV value - * - * @return result - */ -EfErrCode ef_set_env(const char *key, const char *value) -{ - EfErrCode result = EF_NO_ERR; - char *old_env, *old_value; - - if (!init_ok) { - EF_INFO("ENV isn't initialize OK.\n"); - return EF_ENV_INIT_FAILED; - } - - /* lock the ENV cache */ - ef_port_env_lock(); - - /* if ENV value is empty, delete it */ - if ((value == NULL) || (*value == 0)) - result = del_env(key); - else { - old_env = find_env(key); - /* If find this ENV, then compare the new value and old value. */ - if (old_env) { - /* find the old value address */ - old_env = strchr(old_env, '='); - old_value = old_env + 1; - /* If it is changed then delete it and recreate it */ - if (strcmp(old_value, value)) { - result = del_env(key); - if (result == EF_NO_ERR) - result = create_env(key, value); - } - } else - result = create_env(key, value); - } - /* unlock the ENV cache */ - ef_port_env_unlock(); - - return result; -} - -/** - * Get an ENV value by key name. - * - * @param key ENV name - * - * @return value - */ -char *ef_get_env(const char *key) -{ - char *env = NULL, *value = NULL; - - if (!init_ok) { - EF_INFO("ENV isn't initialize OK.\n"); - return NULL; - } - - /* find ENV */ - env = find_env(key); - - if (env == NULL) - return NULL; - /* get value address */ - value = strchr(env, '='); - if (value != NULL) { - /* the equal sign next character is value */ - value++; - } - return value; -} -/** - * Print ENV. - */ -void ef_print_env(void) -{ - uint32_t *env_cache_data_addr = env_cache + ENV_PARAM_WORD_SIZE, - *env_cache_end_addr = - (uint32_t *)(env_cache + ENV_PARAM_WORD_SIZE + get_env_data_size() / 4); - uint8_t j; - char c; - - if (!init_ok) { - EF_INFO("ENV isn't initialize OK.\n"); - return; - } - - for (; env_cache_data_addr < env_cache_end_addr; env_cache_data_addr += 1) { - for (j = 0; j < 4; j++) { - c = (*env_cache_data_addr) >> (8 * j); - ef_print("%c", c); - if (c == 0) { - ef_print("\n"); - break; - } - } - } - -#ifndef EF_ENV_USING_PFS_MODE - ef_print("\nENV size: %ld/%ld bytes.\n", get_env_user_used_size(), ENV_USER_SETTING_SIZE); -#else - ef_print("\nENV size: %ld/%ld bytes, write bytes %ld/%ld, saved count: %ld, mode: power fail safeguard.\n", - get_env_user_used_size(), ENV_USER_SETTING_SIZE, ef_get_env_write_bytes(), - ENV_AREA_SIZE, env_cache[ENV_PARAM_INDEX_SAVED_COUNT]); - -#endif -} - -/** - * Load flash ENV to ram. - * - * @return result - */ -#ifndef EF_ENV_USING_PFS_MODE -EfErrCode ef_load_env(void) -{ - EfErrCode result = EF_NO_ERR; - uint32_t *env_cache_bak, env_end_addr; - - /* read ENV end address from flash */ - ef_port_read(get_env_system_addr() + ENV_PARAM_INDEX_END_ADDR * 4, &env_end_addr, 4); - /* if ENV is not initialize or flash has dirty data, set default for it */ - if ((env_end_addr == 0xFFFFFFFF) || (env_end_addr < env_start_addr) - || (env_end_addr > env_start_addr + ENV_USER_SETTING_SIZE)) - result = ef_env_set_default(); - else { - /* set ENV end address */ - set_env_end_addr(env_end_addr); - - env_cache_bak = env_cache + ENV_PARAM_WORD_SIZE; - /* read all ENV from flash */ - ef_port_read(get_env_data_addr(), env_cache_bak, get_env_data_size()); - /* read ENV CRC code from flash */ - ef_port_read(get_env_system_addr() + ENV_PARAM_INDEX_DATA_CRC * 4, - &env_cache[ENV_PARAM_INDEX_DATA_CRC], 4); - /* if ENV CRC32 check is fault, set default for it */ - if (!env_crc_is_ok()) { - EF_INFO("Warning: ENV CRC check failed. Set it to default.\n"); - result = ef_env_set_default(); - } - } - return result; -} -#else -EfErrCode ef_load_env(void) -{ - EfErrCode result = EF_NO_ERR; - uint32_t area0_start_address = env_start_addr, area1_start_address = env_start_addr - + ENV_AREA_SIZE / 2; - uint32_t area0_end_addr, area1_end_addr, area0_crc, area1_crc, area0_saved_count, area1_saved_count; - bool area0_is_valid = true, area1_is_valid = true; - /* read ENV area end address from flash */ - ef_port_read(area0_start_address + ENV_PARAM_INDEX_END_ADDR * 4, &area0_end_addr, 4); - ef_port_read(area1_start_address + ENV_PARAM_INDEX_END_ADDR * 4, &area1_end_addr, 4); - if ((area0_end_addr == 0xFFFFFFFF) || (area0_end_addr < area0_start_address) - || (area0_end_addr > area0_start_address + ENV_USER_SETTING_SIZE)) - area0_is_valid = false; - if ((area1_end_addr == 0xFFFFFFFF) || (area1_end_addr < area1_start_address) - || (area1_end_addr > area1_start_address + ENV_USER_SETTING_SIZE)) - area1_is_valid = false; - /* check area0 CRC when it is valid */ - if (area0_is_valid) { - /* read ENV area0 crc32 code from flash */ - ef_port_read(area0_start_address + ENV_PARAM_INDEX_DATA_CRC * 4, &area0_crc, 4); - /* read ENV from ENV area0 */ - ef_port_read(area0_start_address, env_cache, area0_end_addr - area0_start_address); - /* current load ENV area address is area0 start address */ - cur_load_area_addr = area0_start_address; - if (!env_crc_is_ok()) - area0_is_valid = false; - } - /* check area1 CRC when it is valid */ - if (area1_is_valid) { - /* read ENV area1 crc32 code from flash */ - ef_port_read(area1_start_address + ENV_PARAM_INDEX_DATA_CRC * 4, &area1_crc, 4); - /* read ENV from ENV area1 */ - ef_port_read(area1_start_address, env_cache, area1_end_addr - area1_start_address); - /* current load ENV area address is area1 start address */ - cur_load_area_addr = area1_start_address; - if (!env_crc_is_ok()) - area1_is_valid = false; - } - /* all ENV area CRC is OK then compare saved count */ - if (area0_is_valid && area1_is_valid) { - /* read ENV area saved count from flash */ - ef_port_read(area0_start_address + ENV_PARAM_INDEX_SAVED_COUNT * 4, - &area0_saved_count, 4); - ef_port_read(area1_start_address + ENV_PARAM_INDEX_SAVED_COUNT * 4, - &area1_saved_count, 4); - /* the bigger saved count area is valid */ - if ((area0_saved_count > area1_saved_count) || ((area0_saved_count == 0) && (area1_saved_count == 0xFFFFFFFF))) - area1_is_valid = false; - else - area0_is_valid = false; - } - if (area0_is_valid) { - /* current load ENV area address is area0 start address */ - cur_load_area_addr = area0_start_address; - /* next save ENV area address is area1 start address */ - next_save_area_addr = area1_start_address; - /* read all ENV from area0 */ - ef_port_read(area0_start_address, env_cache, area0_end_addr - area0_start_address); - } else if (area1_is_valid) { - /* next save ENV area address is area0 start address */ - next_save_area_addr = area0_start_address; - } else { - /* current load ENV area address is area1 start address */ - cur_load_area_addr = area1_start_address; - /* next save ENV area address is area0 start address */ - next_save_area_addr = area0_start_address; - /* set the ENV to default */ - result = ef_env_set_default(); - } - return result; -} -#endif - -/** - * Save ENV to flash. - */ -EfErrCode ef_save_env(void) -{ - EfErrCode result = EF_NO_ERR; - uint32_t write_addr, write_size; - - /* ENV ram cache has not changed don't need to save */ - if (!env_cache_changed) - return result; - -#ifndef EF_ENV_USING_PFS_MODE - write_addr = get_env_system_addr(); - write_size = get_env_user_used_size(); - /* calculate and cache CRC32 code */ - env_cache[ENV_PARAM_INDEX_DATA_CRC] = calc_env_crc(); -#else - write_addr = next_save_area_addr; - write_size = get_env_user_used_size(); - /* replace next_save_area_addr with cur_load_area_addr */ - next_save_area_addr = cur_load_area_addr; - cur_load_area_addr = write_addr; - /* change the ENV end address to next save area address */ - set_env_end_addr(write_addr + write_size); - /* ENV area saved count +1 */ - env_cache[ENV_PARAM_INDEX_SAVED_COUNT]++; - /* calculate and cache CRC32 code */ - env_cache[ENV_PARAM_INDEX_DATA_CRC] = calc_env_crc(); -#endif - - /* erase ENV */ - result = ef_port_erase(write_addr, write_size); - switch (result) { - case EF_NO_ERR: { - EF_INFO("Erased ENV OK.\n"); - break; - } - case EF_ERASE_ERR: { - EF_INFO("Error: Erased ENV fault! Start address is 0x%08X, size is %ld.\n", write_addr, write_size); - /* will return when erase fault */ - return result; - } - default: - break; - } - - /* write ENV to flash */ - result = ef_port_write(write_addr, env_cache, write_size); - switch (result) { - case EF_NO_ERR: { - EF_INFO("Saved ENV OK.\n"); - break; - } - case EF_WRITE_ERR: { - EF_INFO("Error: Saved ENV fault! Start address is 0x%08X, size is %ld.\n", write_addr, write_size); - break; - } - default: - break; - } - - env_cache_changed = false; - - return result; -} - -/** - * Calculate the cached ENV CRC32 value. - * - * @return CRC32 value - */ -static uint32_t calc_env_crc(void) -{ - uint32_t crc32 = 0; - - /* Calculate the ENV end address CRC32. The 4 is ENV end address bytes size. */ - crc32 = ef_calc_crc32(crc32, &env_cache[ENV_PARAM_INDEX_END_ADDR], 4); - -#ifdef EF_ENV_USING_PFS_MODE - /* Calculate the ENV area saved count CRC32. */ - crc32 = ef_calc_crc32(crc32, &env_cache[ENV_PARAM_INDEX_SAVED_COUNT], 4); -#endif - - /* Calculate the all ENV data CRC32. */ - crc32 = ef_calc_crc32(crc32, &env_cache[ENV_PARAM_WORD_SIZE], get_env_data_size()); - - EF_DEBUG("Calculate ENV CRC32 number is 0x%08X.\n", crc32); - - return crc32; -} - -/** - * Check the ENV CRC32 - * - * @return true is ok - */ -static bool env_crc_is_ok(void) -{ - if (calc_env_crc() == env_cache[ENV_PARAM_INDEX_DATA_CRC]) { - EF_DEBUG("Verify ENV CRC32 result is OK.\n"); - return true; - } else - return false; -} - -/** - * Set and save an ENV. If set ENV is success then will save it. - * - * @param key ENV name - * @param value ENV value - * - * @return result - */ -EfErrCode ef_set_and_save_env(const char *key, const char *value) -{ - EfErrCode result = EF_NO_ERR; - - result = ef_set_env(key, value); - - if (result == EF_NO_ERR) - result = ef_save_env(); - - return result; -} - -#endif /* EF_ENV_USING_WL_MODE */ - -#endif /* EF_USING_ENV */ diff --git a/bk7235/liteos_m/bk_sdk_armino/components/easy_flash/src/ef_env_wl.c b/bk7235/liteos_m/bk_sdk_armino/components/easy_flash/src/ef_env_wl.c deleted file mode 100644 index eb2f32ac0b18e579f9b76350087ef51f25aa57c3..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/easy_flash/src/ef_env_wl.c +++ /dev/null @@ -1,973 +0,0 @@ -/* - * This file is part of the EasyFlash Library. - * - * Copyright (c) 2015-2018, Armink, - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * 'Software'), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY - * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * Function: Environment variables operating interface. (wear leveling mode) - * Created on: 2015-02-11 - */ - -#include -#include -#include - -#ifdef EF_USING_ENV - -#ifdef EF_ENV_USING_WL_MODE - -/** - * ENV area has 2 sections - * 1. System section - * Storage ENV current using data section address. - * Units: Word. Total size: @see EF_ERASE_MIN_SIZE. - * 2. Data section - * The data section storage ENV's parameters and detail. - * When an exception has occurred on flash erase or write. The current using data section - * address will move to next available position. This position depends on EF_ERASE_MIN_SIZE. - * 2.1 ENV parameters part - * It storage ENV's parameters. - * 2.2 ENV detail part - * It storage all ENV. Storage format is key=value\0. - * All ENV must be 4 bytes alignment. The remaining part must fill '\0'. - * - * @note Word = 4 Bytes in this file - * @note It will has two ENV areas(Area0, Area1) in data section when used power fail safeguard mode. - */ - -/* flash ENV parameters part index and size */ -enum { - /* data section ENV detail part end address index */ - ENV_PARAM_PART_INDEX_END_ADDR = 0, - -#ifdef EF_ENV_USING_PFS_MODE - /* saved count for ENV area */ - ENV_PARAM_PART_INDEX_SAVED_COUNT, -#endif - - /* data section CRC32 code index */ - ENV_PARAM_PART_INDEX_DATA_CRC, - /* ENV parameters part word size */ - ENV_PARAM_PART_WORD_SIZE, - /* ENV parameters part byte size */ - ENV_PARAM_PART_BYTE_SIZE = ENV_PARAM_PART_WORD_SIZE * 4, -}; - -/* default ENV set, must be initialized by user */ -static ef_env const *default_env_set; -/* default ENV set size, must be initialized by user */ -static size_t default_env_set_size = 0; -/* flash ENV data section size */ -static size_t env_data_section_size = 0; -/* ENV ram cache */ -static uint32_t env_cache[ENV_USER_SETTING_SIZE / 4] = { 0 }; -/* ENV start address in flash */ -static uint32_t env_start_addr = 0; -/* current using data section address */ -static uint32_t cur_using_data_addr = 0; -/* ENV ram cache has changed when ENV created, deleted and changed value. */ -static bool env_cache_changed = false; -/* initialize OK flag */ -static bool init_ok = false; - -#ifdef EF_ENV_USING_PFS_MODE -/* next save ENV area address */ -static uint32_t next_save_area_addr = 0; -#endif - -static uint32_t get_env_start_addr(void); -static uint32_t get_cur_using_data_addr(void); -static uint32_t get_env_detail_addr(void); -static uint32_t get_env_detail_end_addr(void); -static void set_cur_using_data_addr(uint32_t using_data_addr); -static void set_env_detail_end_addr(uint32_t end_addr); -static EfErrCode write_env(const char *key, const char *value); -static char *find_env(const char *key); -static size_t get_env_detail_size(void); -static size_t get_env_user_used_size(void); -static EfErrCode create_env(const char *key, const char *value); -static EfErrCode del_env(const char *key); -static EfErrCode save_cur_using_data_addr(uint32_t cur_data_addr); -static uint32_t calc_env_crc(void); -static bool env_crc_is_ok(void); - -/** - * Flash ENV initialize. - * - * @param default_env default ENV set for user - * @param default_env_size default ENV set size - * - * @return result - */ -EfErrCode ef_env_init(ef_env const *default_env, size_t default_env_size) -{ - EfErrCode result = EF_NO_ERR; - - EF_ASSERT(ENV_AREA_SIZE); - EF_ASSERT(ENV_USER_SETTING_SIZE); - /* must be word alignment for ENV */ - EF_ASSERT(ENV_USER_SETTING_SIZE % 4 == 0); - EF_ASSERT(ENV_AREA_SIZE % 4 == 0); - EF_ASSERT(default_env); - EF_ASSERT(default_env_size < ENV_USER_SETTING_SIZE); - -#ifndef EF_ENV_USING_PFS_MODE - /* system section size is erase_min_size, so last part is data section */ - env_data_section_size = ENV_AREA_SIZE - EF_ERASE_MIN_SIZE; -#else - /* system section size is erase_min_size, so last part is data section */ - env_data_section_size = ENV_AREA_SIZE / 2 - EF_ERASE_MIN_SIZE; - EF_ASSERT((ENV_AREA_SIZE / EF_ERASE_MIN_SIZE) % 2 == 0); -#endif - EF_ASSERT(env_data_section_size >= ENV_USER_SETTING_SIZE); - /* the ENV data section size should be an integral multiple of erase minimum size. */ - EF_ASSERT(env_data_section_size % EF_ERASE_MIN_SIZE == 0); - - - env_start_addr = EF_START_ADDR; - default_env_set = default_env; - default_env_set_size = default_env_size; - - EF_DEBUG("ENV start address is 0x%08X, size is %d bytes.\n", EF_START_ADDR, ENV_AREA_SIZE); - - result = ef_load_env(); - - if (result == EF_NO_ERR) - init_ok = true; - - return result; -} - -/** - * ENV set default. - * - * @return result - */ -EfErrCode ef_env_set_default(void) -{ - EfErrCode result = EF_NO_ERR; - size_t i; - - EF_ASSERT(default_env_set); - EF_ASSERT(default_env_set_size); - - /* lock the ENV cache */ - ef_port_env_lock(); - - /* set ENV detail part end address is at ENV detail part start address */ - set_env_detail_end_addr(get_env_detail_addr()); - -#ifdef EF_ENV_USING_PFS_MODE - /* set saved count to default 0 */ - env_cache[ENV_PARAM_PART_INDEX_SAVED_COUNT] = 0; -#endif - - /* create default ENV */ - for (i = 0; i < default_env_set_size; i++) - create_env(default_env_set[i].key, default_env_set[i].value); - - /* unlock the ENV cache */ - ef_port_env_unlock(); - - result = ef_save_env(); - -#ifdef EF_ENV_USING_PFS_MODE - /* reset other PFS area's data */ - if (result == EF_NO_ERR) { - env_cache_changed = true; - result = ef_save_env(); - } -#endif - - return result; -} - -/** - * Get ENV start address in flash. - * - * @return ENV start address in flash - */ -static uint32_t get_env_start_addr(void) -{ - return env_start_addr; -} -/** - * Get current using data section address. - * - * @return current using data section address - */ -static uint32_t get_cur_using_data_addr(void) -{ - return cur_using_data_addr; -} - -/** - * Set current using data section address. - * - * @param using_data_addr current using data section address - */ -static void set_cur_using_data_addr(uint32_t using_data_addr) -{ - cur_using_data_addr = using_data_addr; -} - -/** - * Get ENV detail part start address. - * - * @return detail part start address - */ -static uint32_t get_env_detail_addr(void) -{ - return get_cur_using_data_addr() + ENV_PARAM_PART_BYTE_SIZE; -} - -/** - * Get ENV detail part end address. - * It's the first word in ENV. - * - * @return ENV end address - */ -static uint32_t get_env_detail_end_addr(void) -{ - /* it is the first word */ - return env_cache[ENV_PARAM_PART_INDEX_END_ADDR]; -} - -/** - * Set ENV detail part end address. - * It's the first word in ENV. - * - * @param end_addr ENV end address - */ -static void set_env_detail_end_addr(uint32_t end_addr) -{ - env_cache[ENV_PARAM_PART_INDEX_END_ADDR] = end_addr; -} - -/** - * Get current ENV detail part size. - * - * @return size - */ -static size_t get_env_detail_size(void) -{ - if (get_env_detail_end_addr() > get_env_detail_addr()) - return get_env_detail_end_addr() - get_env_detail_addr(); - else - return 0; -} - -/** - * Get current user used ENV size. - * - * @see ENV_USER_SETTING_SIZE - * - * @return size - */ -/* must be initialized */ -static size_t get_env_user_used_size(void) -{ - if (get_env_detail_end_addr() > get_cur_using_data_addr()) - return get_env_detail_end_addr() - get_cur_using_data_addr(); - else - return 0; -} - -/** - * Get current ENV already write bytes. - * - * @return write bytes - */ -size_t ef_get_env_write_bytes(void) -{ -#ifndef EF_ENV_USING_PFS_MODE - return get_env_detail_end_addr() - get_env_start_addr(); -#else - return EF_ERASE_MIN_SIZE + get_env_detail_end_addr() - get_cur_using_data_addr(); -#endif -} - -/** - * Write an ENV at the end of cache. - * - * @param key ENV name - * @param value ENV value - * - * @return result - */ -static EfErrCode write_env(const char *key, const char *value) -{ - EfErrCode result = EF_NO_ERR; - size_t ker_len = strlen(key), value_len = strlen(value), env_str_len; - char *env_cache_bak = (char *)env_cache; - - /* calculate ENV storage length, contain '=' and '\0'. */ - env_str_len = ker_len + value_len + 2; - if (env_str_len % 4 != 0) - env_str_len = (env_str_len / 4 + 1) * 4; - /* check capacity of ENV */ - if (env_str_len + get_env_user_used_size() >= ENV_USER_SETTING_SIZE) - return EF_ENV_FULL; - /* calculate current ENV ram cache end address */ - env_cache_bak += ENV_PARAM_PART_BYTE_SIZE + get_env_detail_size(); - /* copy key name */ - memcpy(env_cache_bak, key, ker_len); - env_cache_bak += ker_len; - /* copy equal sign */ - *env_cache_bak = '='; - env_cache_bak++; - /* copy value */ - memcpy(env_cache_bak, value, value_len); - env_cache_bak += value_len; - /* fill '\0' for string end sign */ - *env_cache_bak = '\0'; - env_cache_bak ++; - /* fill '\0' for word alignment */ - memset(env_cache_bak, 0, env_str_len - (ker_len + value_len + 2)); - set_env_detail_end_addr(get_env_detail_end_addr() + env_str_len); - /* ENV ram cache has changed */ - env_cache_changed = true; - - return result; -} - -/** - * Find ENV. - * - * @param key ENV name - * - * @return found ENV in ram cache - */ -static char *find_env(const char *key) -{ - char *env_start, *env_end, *env, *found_env = NULL; - size_t key_len = strlen(key), env_len; - - if (*key == NULL) { - EF_INFO("Flash ENV name must be not empty!\n"); - return NULL; - } - - /* from data section start to data section end */ - env_start = (char *)((char *) env_cache + ENV_PARAM_PART_BYTE_SIZE); - env_end = (char *)((char *) env_cache + ENV_PARAM_PART_BYTE_SIZE + get_env_detail_size()); - - /* ENV is null */ - if (env_start == env_end) - return NULL; - - env = env_start; - while (env < env_end) { - /* the key length must be equal */ - if (!strncmp(env, key, key_len) && (env[key_len] == '=')) { - found_env = env; - break; - } else { - /* calculate ENV length, contain '\0'. */ - env_len = strlen(env) + 1; - /* next ENV and word alignment */ - if (env_len % 4 == 0) - env += env_len; - else - env += (env_len / 4 + 1) * 4; - } - } - - return found_env; -} - -/** - * If the ENV is not exist, create it. - * @see flash_write_env - * - * @param key ENV name - * @param value ENV value - * - * @return result - */ -static EfErrCode create_env(const char *key, const char *value) -{ - EfErrCode result = EF_NO_ERR; - - EF_ASSERT(key); - EF_ASSERT(value); - - if (*key == NULL) { - EF_INFO("Flash ENV name must be not empty!\n"); - return EF_ENV_NAME_ERR; - } - - if (strchr(key, '=')) { - EF_INFO("Flash ENV name can't contain '='.\n"); - return EF_ENV_NAME_ERR; - } - - /* find ENV */ - if (find_env(key)) { - EF_INFO("The name of \"%s\" is already exist.\n", key); - return EF_ENV_NAME_EXIST; - } - /* write ENV at the end of cache */ - result = write_env(key, value); - - return result; -} - -/** - * Delete an ENV in cache. - * - * @param key ENV name - * - * @return result - */ -static EfErrCode del_env(const char *key) -{ - EfErrCode result = EF_NO_ERR; - char *del_env = NULL; - size_t del_env_length, remain_env_length; - - EF_ASSERT(key); - - if (*key == NULL) { - EF_INFO("Flash ENV name must be not NULL!\n"); - return EF_ENV_NAME_ERR; - } - - if (strchr(key, '=')) { - EF_INFO("Flash ENV name or value can't contain '='.\n"); - return EF_ENV_NAME_ERR; - } - - /* find ENV */ - del_env = find_env(key); - - if (!del_env) { - EF_INFO("Not find \"%s\" in ENV.\n", key); - return EF_ENV_NAME_ERR; - } - del_env_length = strlen(del_env); - /* '\0' also must be as ENV length */ - del_env_length ++; - /* the address must multiple of 4 */ - if (del_env_length % 4 != 0) - del_env_length = (del_env_length / 4 + 1) * 4; - /* calculate remain ENV length */ - remain_env_length = get_env_detail_size() - - (((uint32_t) del_env + del_env_length) - ((uint32_t) env_cache + ENV_PARAM_PART_BYTE_SIZE)); - /* remain ENV move forward */ - memcpy(del_env, del_env + del_env_length, remain_env_length); - /* reset ENV end address */ - set_env_detail_end_addr(get_env_detail_end_addr() - del_env_length); - /* ENV ram cache has changed */ - env_cache_changed = true; - - return result; -} - -/** - * Set an ENV. If it value is empty, delete it. - * If not find it in ENV table, then create it. - * - * @param key ENV name - * @param value ENV value - * - * @return result - */ -EfErrCode ef_set_env(const char *key, const char *value) -{ - EfErrCode result = EF_NO_ERR; - char *old_env, *old_value; - - if (!init_ok) { - EF_INFO("ENV isn't initialize OK.\n"); - return EF_ENV_INIT_FAILED; - } - - /* lock the ENV cache */ - ef_port_env_lock(); - - /* if ENV value is empty, delete it */ - if (*value == NULL) - result = del_env(key); - else { - old_env = find_env(key); - /* If find this ENV, then compare the new value and old value. */ - if (old_env) { - /* find the old value address */ - old_env = strchr(old_env, '='); - old_value = old_env + 1; - /* If it is changed then delete it and recreate it */ - if (strcmp(old_value, value)) { - result = del_env(key); - if (result == EF_NO_ERR) - result = create_env(key, value); - } - } else - result = create_env(key, value); - } - /* unlock the ENV cache */ - ef_port_env_unlock(); - - return result; -} - -/** - * Get an ENV value by key name. - * - * @param key ENV name - * - * @return value - */ -char *ef_get_env(const char *key) -{ - char *env = NULL, *value = NULL; - - if (!init_ok) { - EF_INFO("ENV isn't initialize OK.\n"); - return NULL; - } - - /* find ENV */ - env = find_env(key); - - if (env == NULL) - return NULL; - /* get value address */ - value = strchr(env, '='); - if (value != NULL) { - /* the equal sign next character is value */ - value++; - } - return value; -} -/** - * Print ENV. - */ -void ef_print_env(void) -{ - uint32_t *env_cache_detail_addr = env_cache + ENV_PARAM_PART_WORD_SIZE, *env_cache_end_addr = - (uint32_t *)(env_cache + ENV_PARAM_PART_WORD_SIZE + get_env_detail_size() / 4); - uint8_t j; - char c; - - if (!init_ok) { - EF_INFO("ENV isn't initialize OK.\n"); - return; - } - - for (; env_cache_detail_addr < env_cache_end_addr; env_cache_detail_addr += 1) { - for (j = 0; j < 4; j++) { - c = (*env_cache_detail_addr) >> (8 * j); - ef_print("%c", c); - if (c == NULL) { - ef_print("\n"); - break; - } - } - } - -#ifndef EF_ENV_USING_PFS_MODE - ef_print("\nENV size: %ld/%ld bytes, write bytes %ld/%ld, mode: wear leveling.\n", - get_env_user_used_size(), ENV_USER_SETTING_SIZE, ef_get_env_write_bytes(), - ENV_AREA_SIZE); -#else - ef_print("\nENV size: %ld/%ld bytes, write bytes %ld/%ld, saved count: %ld, mode: wear leveling and power fail safeguard.\n", - get_env_user_used_size(), ENV_USER_SETTING_SIZE, ef_get_env_write_bytes(), - ENV_AREA_SIZE / 2, env_cache[ENV_PARAM_PART_INDEX_SAVED_COUNT]); -#endif -} - -/** - * Load flash ENV to ram. - * - * @return result - */ -#ifndef EF_ENV_USING_PFS_MODE -EfErrCode ef_load_env(void) -{ - EfErrCode result = EF_NO_ERR; - uint32_t *env_cache_bak, env_end_addr, using_data_addr; - - /* read current using data section address */ - ef_port_read(get_env_start_addr(), &using_data_addr, 4); - /* if ENV is not initialize or flash has dirty data, set default for it */ - if ((using_data_addr == 0xFFFFFFFF) - || (using_data_addr > get_env_start_addr() + ENV_AREA_SIZE) - || (using_data_addr < get_env_start_addr() + EF_ERASE_MIN_SIZE)) { - /* initialize current using data section address */ - set_cur_using_data_addr(get_env_start_addr() + EF_ERASE_MIN_SIZE); - /* save current using data section address to flash*/ - if ((result = save_cur_using_data_addr(get_cur_using_data_addr())) == EF_NO_ERR) { - /* set default ENV */ - result = ef_env_set_default(); - } - } else { - /* set current using data section address */ - set_cur_using_data_addr(using_data_addr); - /* read ENV detail part end address from flash */ - ef_port_read(get_cur_using_data_addr() + ENV_PARAM_PART_INDEX_END_ADDR * 4, &env_end_addr, 4); - /* if ENV end address has error, set default for ENV */ - if (env_end_addr > get_env_start_addr() + ENV_AREA_SIZE) { - /* initialize current using data section address */ - set_cur_using_data_addr(get_env_start_addr() + EF_ERASE_MIN_SIZE); - /* save current using data section address to flash*/ - if ((result = save_cur_using_data_addr(get_cur_using_data_addr())) == EF_NO_ERR) { - EF_INFO("Warning: ENV end address has error. Set it to default.\n"); - result = ef_env_set_default(); - } - } else { - /* set ENV detail part end address */ - set_env_detail_end_addr(env_end_addr); - - env_cache_bak = env_cache + ENV_PARAM_PART_WORD_SIZE; - /* read all ENV from flash */ - ef_port_read(get_env_detail_addr(), env_cache_bak, get_env_detail_size()); - /* read ENV CRC code from flash */ - ef_port_read(get_cur_using_data_addr() + ENV_PARAM_PART_INDEX_DATA_CRC * 4, - &env_cache[ENV_PARAM_PART_INDEX_DATA_CRC], 4); - /* if ENV CRC32 check is fault, set default for it */ - if (!env_crc_is_ok()) { - EF_INFO("Warning: ENV CRC check failed. Set it to default.\n"); - result = ef_env_set_default(); - } - } - - } - return result; -} -#else -EfErrCode ef_load_env(void) -{ - EfErrCode result = EF_NO_ERR; - /* ENV area0 current using address default value */ - uint32_t area0_default_cur_using_addr = get_env_start_addr() + EF_ERASE_MIN_SIZE; - /* ENV area1 current using address default value */ - uint32_t area1_default_cur_using_addr = area0_default_cur_using_addr + ENV_AREA_SIZE / 2; - uint32_t area0_cur_using_addr, area1_cur_using_addr, area0_end_addr, area1_end_addr; - uint32_t area0_crc, area1_crc, area0_saved_count, area1_saved_count; - bool area0_is_valid = true, area1_is_valid = true; - - /* read ENV area0 and area1 current using data section address */ - ef_port_read(get_env_start_addr(), &area0_cur_using_addr, 4); - ef_port_read(get_env_start_addr() + ENV_AREA_SIZE / 2, &area1_cur_using_addr, 4); - /* if ENV is not initialize or flash has dirty data, set it isn't valid */ - if ((area0_cur_using_addr == 0xFFFFFFFF) - || (area0_cur_using_addr > get_env_start_addr() + ENV_AREA_SIZE / 2) - || (area0_cur_using_addr < get_env_start_addr() + EF_ERASE_MIN_SIZE)) - area0_is_valid = false; - if ((area1_cur_using_addr == 0xFFFFFFFF) - || (area1_cur_using_addr > get_env_start_addr() + ENV_AREA_SIZE) - || (area1_cur_using_addr < get_env_start_addr() + ENV_AREA_SIZE / 2 + EF_ERASE_MIN_SIZE)) - area1_is_valid = false; - /* check area0 end address when it is valid */ - if (area0_is_valid) { - /* read ENV area end address from flash */ - ef_port_read(area0_cur_using_addr + ENV_PARAM_PART_INDEX_END_ADDR * 4, &area0_end_addr, 4); - if ((area0_end_addr == 0xFFFFFFFF) || (area0_end_addr < area0_cur_using_addr) - || (area0_end_addr > area0_cur_using_addr + ENV_USER_SETTING_SIZE)) - area0_is_valid = false; - } - /* check area1 end address when it is valid */ - if (area1_is_valid) { - /* read ENV area end address from flash */ - ef_port_read(area1_cur_using_addr + ENV_PARAM_PART_INDEX_END_ADDR * 4, &area1_end_addr, 4); - if ((area1_end_addr == 0xFFFFFFFF) || (area1_end_addr < area1_cur_using_addr) - || (area1_end_addr > area1_cur_using_addr + ENV_USER_SETTING_SIZE)) - area1_is_valid = false; - } - /* check area0 CRC when it is valid */ - if (area0_is_valid) { - /* read ENV area0 crc32 code from flash */ - ef_port_read(area0_cur_using_addr + ENV_PARAM_PART_INDEX_DATA_CRC * 4, &area0_crc, 4); - /* read ENV from ENV area0 */ - ef_port_read(area0_cur_using_addr, env_cache, area0_end_addr - area0_cur_using_addr); - /* current using data section address is area0 current using data section address */ - set_cur_using_data_addr(area0_cur_using_addr); - if (!env_crc_is_ok()) - area0_is_valid = false; - } - /* check area1 CRC when it is valid */ - if (area1_is_valid) { - /* read ENV area1 crc32 code from flash */ - ef_port_read(area1_cur_using_addr + ENV_PARAM_PART_INDEX_DATA_CRC * 4, &area1_crc, 4); - /* read ENV from ENV area1 */ - ef_port_read(area1_cur_using_addr, env_cache, area1_end_addr - area1_cur_using_addr); - /* current using data section address is area1 current using data section address */ - set_cur_using_data_addr(area1_cur_using_addr); - if (!env_crc_is_ok()) - area1_is_valid = false; - } - /* all ENV area CRC is OK then compare saved count */ - if (area0_is_valid && area1_is_valid) { - /* read ENV area saved count from flash */ - ef_port_read(area0_cur_using_addr + ENV_PARAM_PART_INDEX_SAVED_COUNT * 4, - &area0_saved_count, 4); - ef_port_read(area1_cur_using_addr + ENV_PARAM_PART_INDEX_SAVED_COUNT * 4, - &area1_saved_count, 4); - /* the bigger saved count area is valid */ - if ((area0_saved_count > area1_saved_count) || ((area0_saved_count == 0) && (area1_saved_count == 0xFFFFFFFF))) - area1_is_valid = false; - else - area0_is_valid = false; - } - if (area0_is_valid) { - /* current using data section address is area0 current using data section address */ - set_cur_using_data_addr(area0_cur_using_addr); - /* next save ENV area address is area1 current using address value */ - next_save_area_addr = area1_cur_using_addr; - /* read all ENV from area0 */ - ef_port_read(area0_cur_using_addr, env_cache, area0_end_addr - area0_cur_using_addr); - } else if (area1_is_valid) { - /* already read data section and set_cur_using_data_addr above current code, - * so just set next save ENV area address is area0 current using address value */ - next_save_area_addr = area0_cur_using_addr; - } else { - /* current using data section address is area1 current using address default value */ - set_cur_using_data_addr(area1_default_cur_using_addr); - /* next save ENV area address default is area0 current using address default value */ - next_save_area_addr = area0_default_cur_using_addr; - /* save current using data section address to flash*/ - if (((result = save_cur_using_data_addr(area0_default_cur_using_addr)) == EF_NO_ERR) - && ((result = save_cur_using_data_addr(area1_default_cur_using_addr)) == EF_NO_ERR)) { - /* set the ENV to default */ - result = ef_env_set_default(); - } - } - return result; -} -#endif - -/** - * Save ENV to flash. - */ -EfErrCode ef_save_env(void) -{ - EfErrCode result = EF_NO_ERR; - uint32_t cur_using_addr_bak, move_offset_addr; - size_t env_used_size = get_env_user_used_size(); - uint32_t data_sec_end_addr; - - /* ENV ram cache has not changed don't need to save */ - if (!env_cache_changed) - return result; - -#ifndef EF_ENV_USING_PFS_MODE - data_sec_end_addr = get_env_start_addr() + ENV_AREA_SIZE - 4; - cur_using_addr_bak = get_cur_using_data_addr(); -#else - cur_using_addr_bak = next_save_area_addr; - /* replace next_save_area_addr with cur_using_data_addr */ - next_save_area_addr = get_cur_using_data_addr(); - set_cur_using_data_addr(cur_using_addr_bak); - /* change the ENV detail end address to next save area address */ - set_env_detail_end_addr(get_cur_using_data_addr() + env_used_size); - /* area0 or area1 */ - if (get_cur_using_data_addr() < get_env_start_addr() + ENV_AREA_SIZE / 2) - data_sec_end_addr = get_env_start_addr() + ENV_AREA_SIZE / 2 - 4; - else - data_sec_end_addr = get_env_start_addr() + ENV_AREA_SIZE - 4; - /* ENV area saved count +1 */ - env_cache[ENV_PARAM_PART_INDEX_SAVED_COUNT]++; -#endif - - /* wear leveling process, automatic move ENV to next available position */ - while (get_cur_using_data_addr() + env_used_size < data_sec_end_addr) { - /* calculate and cache CRC32 code */ - env_cache[ENV_PARAM_PART_INDEX_DATA_CRC] = calc_env_crc(); - /* erase ENV */ - result = ef_port_erase(get_cur_using_data_addr(), env_used_size); - switch (result) { - case EF_NO_ERR: { - EF_INFO("Erased ENV OK.\n"); - break; - } - case EF_ERASE_ERR: { - EF_INFO("Warning: Erased ENV fault! Start address is 0x%08X, size is %ld.\n", - get_cur_using_data_addr(), env_used_size); - EF_INFO("Moving ENV to next available position.\n"); - /* Calculate move offset address. - * Current strategy is optimistic. It will offset the flash erasure minimum size. - */ - move_offset_addr = EF_ERASE_MIN_SIZE; - /* calculate and set next available data section address */ - set_cur_using_data_addr(get_cur_using_data_addr() + move_offset_addr); - /* calculate and set next available ENV detail part end address */ - set_env_detail_end_addr(get_env_detail_end_addr() + move_offset_addr); - continue; - } - } - /* write ENV to flash */ - result = ef_port_write(get_cur_using_data_addr(), env_cache, env_used_size); - switch (result) { - case EF_NO_ERR: { - EF_INFO("Saved ENV OK.\n"); - break; - } - case EF_WRITE_ERR: { - EF_INFO("Warning: Saved ENV fault! Start address is 0x%08X, size is %ld.\n", - get_cur_using_data_addr(), env_used_size); - EF_INFO("Moving ENV to next available position.\n"); - /* Calculate move offset address. - * Current strategy is optimistic. It will offset the flash erasure minimum size. - */ - move_offset_addr = EF_ERASE_MIN_SIZE; - /* calculate and set next available data section address */ - set_cur_using_data_addr(get_cur_using_data_addr() + move_offset_addr); - /* calculate and set next available ENV detail part end address */ - set_env_detail_end_addr(get_env_detail_end_addr() + move_offset_addr); - continue; - } - } - /* save ENV success */ - if (result == EF_NO_ERR) - break; - } - - if (get_cur_using_data_addr() + env_used_size < data_sec_end_addr) { - /* current using data section address has changed, save it */ - if (get_cur_using_data_addr() != cur_using_addr_bak) - result = save_cur_using_data_addr(get_cur_using_data_addr()); - } else { - result = EF_ENV_FULL; - EF_INFO("Error: The flash has no available space to save ENV.\n"); - } - - env_cache_changed = false; - - return result; -} - -/** - * Calculate the cached ENV CRC32 value. - * - * @return CRC32 value - */ -static uint32_t calc_env_crc(void) -{ - uint32_t crc32 = 0; - - /* Calculate the ENV end address and all ENV data CRC32. - * The 4 is ENV end address bytes size. */ - crc32 = ef_calc_crc32(crc32, &env_cache[ENV_PARAM_PART_INDEX_END_ADDR], 4); - crc32 = ef_calc_crc32(crc32, &env_cache[ENV_PARAM_PART_WORD_SIZE], get_env_detail_size()); - EF_DEBUG("Calculate ENV CRC32 number is 0x%08X.\n", crc32); - - return crc32; -} - -/** - * Check the ENV CRC32 - * - * @return true is ok - */ -static bool env_crc_is_ok(void) -{ - if (calc_env_crc() == env_cache[ENV_PARAM_PART_INDEX_DATA_CRC]) { - EF_DEBUG("Verify ENV CRC32 result is OK.\n"); - return true; - } else - return false; -} - -/** - * Save current using data section address to flash. - * - * @param cur_data_addr current using data section address - * - * @return result - */ -#ifndef EF_ENV_USING_PFS_MODE -static EfErrCode save_cur_using_data_addr(uint32_t cur_data_addr) -{ - EfErrCode result = EF_NO_ERR; - - /* erase ENV system section */ - result = ef_port_erase(get_env_start_addr(), 4); - if (result == EF_NO_ERR) { - /* write current using data section address to flash */ - result = ef_port_write(get_env_start_addr(), &cur_data_addr, 4); - if (result == EF_WRITE_ERR) { - EF_INFO("Error: Write system section fault! Start address is 0x%08X, size is %ld.\n", - get_env_start_addr(), 4); - EF_INFO("Note: The ENV can not be used.\n"); - } - } else { - EF_INFO("Error: Erased system section fault! Start address is 0x%08X, size is %ld.\n", - get_env_start_addr(), 4); - EF_INFO("Note: The ENV can not be used\n"); - } - return result; -} -#else -static EfErrCode save_cur_using_data_addr(uint32_t cur_data_addr) -{ - EfErrCode result = EF_NO_ERR; - uint32_t cur_system_sec_addr; - - if (cur_data_addr < get_env_start_addr() + ENV_AREA_SIZE / 2) { - /* current using system section is in ENV area0 */ - cur_system_sec_addr = get_env_start_addr(); - } else { - /* current using system section is in ENV area1 */ - cur_system_sec_addr = get_env_start_addr() + ENV_AREA_SIZE / 2; - } - /* erase ENV system section */ - result = ef_port_erase(cur_system_sec_addr, 4); - if (result == EF_NO_ERR) { - /* write area0 and area1 current using data section address to flash */ - result = ef_port_write(cur_system_sec_addr, &cur_data_addr, 4); - if (result == EF_WRITE_ERR) { - EF_INFO("Error: Write system section fault! Start address is 0x%08X, size is %ld.\n", - cur_system_sec_addr, 4); - EF_INFO("Note: The ENV can not be used.\n"); - } - } else { - EF_INFO("Error: Erased system section fault! Start address is 0x%08X, size is %ld.\n", - cur_system_sec_addr, 4); - EF_INFO("Note: The ENV can not be used\n"); - } - return result; -} -#endif - -/** - * Set and save an ENV. If set ENV is success then will save it. - * - * @param key ENV name - * @param value ENV value - * - * @return result - */ -EfErrCode ef_set_and_save_env(const char *key, const char *value) -{ - EfErrCode result = EF_NO_ERR; - - result = ef_set_env(key, value); - - if (result == EF_NO_ERR) - result = ef_save_env(); - - return result; -} - -#endif /* EF_ENV_USING_WL_MODE */ - -#endif /* EF_USING_ENV */ diff --git a/bk7235/liteos_m/bk_sdk_armino/components/easy_flash/src/ef_iap.c b/bk7235/liteos_m/bk_sdk_armino/components/easy_flash/src/ef_iap.c deleted file mode 100644 index 931ef1ac717d7b5f9c18f4830d6c95dd51237f44..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/easy_flash/src/ef_iap.c +++ /dev/null @@ -1,296 +0,0 @@ -/* - * This file is part of the EasyFlash Library. - * - * Copyright (c) 2015-2017, Armink, - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * 'Software'), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY - * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * Function: IAP(In-Application Programming) operating interface. - * Created on: 2015-01-05 - */ - -#include - -#ifdef EF_USING_IAP - -/* IAP section backup application section start address in flash */ -static uint32_t bak_app_start_addr = 0; - -/** - * Flash IAP function initialize. - * - * @return result - */ -EfErrCode ef_iap_init(void) -{ - EfErrCode result = EF_NO_ERR; - - bak_app_start_addr = EF_START_ADDR ; - -#if defined(EF_USING_ENV) - bak_app_start_addr += ENV_AREA_SIZE; -#endif - -#if defined(EF_USING_LOG) - bak_app_start_addr += LOG_AREA_SIZE; -#endif - - return result; -} - -/** - * Erase backup area application data. - * - * @param app_size application size - * - * @return result - */ -EfErrCode ef_erase_bak_app(size_t app_size) -{ - EfErrCode result = EF_NO_ERR; - - result = ef_port_erase(ef_get_bak_app_start_addr(), app_size); - switch (result) { - case EF_NO_ERR: { - EF_INFO("Erased backup area application OK.\n"); - break; - } - case EF_ERASE_ERR: { - EF_INFO("Warning: Erase backup area application fault!\n"); - /* will return when erase fault */ - return result; - } - } - - return result; -} - -/** - * Erase user old application by using specified erase function. - * - * @param user_app_addr application entry address - * @param app_size application size - * @param app_erase user specified application erase function - * - * @return result - */ -EfErrCode ef_erase_spec_user_app(uint32_t user_app_addr, size_t app_size, - EfErrCode(*app_erase)(uint32_t addr, size_t size)) -{ - EfErrCode result = EF_NO_ERR; - - result = app_erase(user_app_addr, app_size); - switch (result) { - case EF_NO_ERR: { - EF_INFO("Erased user application OK.\n"); - break; - } - case EF_ERASE_ERR: { - EF_INFO("Warning: Erase user application fault!\n"); - /* will return when erase fault */ - return result; - } - } - - return result; -} - -/** - * Erase user old application by using default `ef_port_erase` function. - * - * @param user_app_addr application entry address - * @param app_size application size - * - * @return result - */ -EfErrCode ef_erase_user_app(uint32_t user_app_addr, size_t app_size) -{ - return ef_erase_spec_user_app(user_app_addr, app_size, ef_port_erase); -} - -/** - * Erase old bootloader - * - * @param bl_addr bootloader entry address - * @param bl_size bootloader size - * - * @return result - */ -EfErrCode ef_erase_bl(uint32_t bl_addr, size_t bl_size) -{ - EfErrCode result = EF_NO_ERR; - - result = ef_port_erase(bl_addr, bl_size); - switch (result) { - case EF_NO_ERR: { - EF_INFO("Erased bootloader OK.\n"); - break; - } - case EF_ERASE_ERR: { - EF_INFO("Warning: Erase bootloader fault!\n"); - /* will return when erase fault */ - return result; - } - } - - return result; -} - -/** - * Write data of application to backup area. - * - * @param data a part of application - * @param size data size - * @param cur_size current write application size - * @param total_size application total size - * - * @return result - */ -EfErrCode ef_write_data_to_bak(uint8_t *data, size_t size, size_t *cur_size, - size_t total_size) -{ - EfErrCode result = EF_NO_ERR; - - /* make sure don't write excess data */ - if (*cur_size + size > total_size) - size = total_size - *cur_size; - - result = ef_port_write(ef_get_bak_app_start_addr() + *cur_size, (uint32_t *) data, size); - switch (result) { - case EF_NO_ERR: { - *cur_size += size; - EF_DEBUG("Write data to backup area OK.\n"); - break; - } - case EF_WRITE_ERR: { - EF_INFO("Warning: Write data to backup area fault!\n"); - break; - } - } - - return result; -} - -/** - * Copy backup area application to application entry by using specified write function. - * - * @param user_app_addr application entry address - * @param app_size application size - * @param app_write user specified application write function - * - * @return result - */ -EfErrCode ef_copy_spec_app_from_bak(uint32_t user_app_addr, size_t app_size, - EfErrCode(*app_write)(uint32_t addr, const uint32_t *buf, size_t size)) -{ - size_t cur_size; - uint32_t app_cur_addr, bak_cur_addr; - EfErrCode result = EF_NO_ERR; - /* 32 words size buffer */ - uint32_t buff[32]; - - /* cycle copy data */ - for (cur_size = 0; cur_size < app_size; cur_size += sizeof(buff)) { - app_cur_addr = user_app_addr + cur_size; - bak_cur_addr = ef_get_bak_app_start_addr() + cur_size; - ef_port_read(bak_cur_addr, buff, sizeof(buff)); - result = app_write(app_cur_addr, buff, sizeof(buff)); - if (result != EF_NO_ERR) - break; - } - - switch (result) { - case EF_NO_ERR: { - EF_INFO("Write data to application entry OK.\n"); - break; - } - case EF_WRITE_ERR: { - EF_INFO("Warning: Write data to application entry fault!\n"); - break; - } - } - - return result; -} - -/** - * Copy backup area application to application entry by using default `ef_port_write` function. - * - * @param user_app_addr application entry address - * @param app_size application size - * - * @return result - */ -EfErrCode ef_copy_app_from_bak(uint32_t user_app_addr, size_t app_size) -{ - return ef_copy_spec_app_from_bak(user_app_addr, app_size, ef_port_write); -} - -/** - * Copy backup area bootloader to bootloader entry. - * - * @param bl_addr bootloader entry address - * @param bl_size bootloader size - * - * @return result - */ -EfErrCode ef_copy_bl_from_bak(uint32_t bl_addr, size_t bl_size) -{ - size_t cur_size; - uint32_t bl_cur_addr, bak_cur_addr; - EfErrCode result = EF_NO_ERR; - /* 32 words buffer */ - uint32_t buff[32]; - - /* cycle copy data by 32bytes buffer */ - for (cur_size = 0; cur_size < bl_size; cur_size += sizeof(buff)) { - bl_cur_addr = bl_addr + cur_size; - bak_cur_addr = ef_get_bak_app_start_addr() + cur_size; - ef_port_read(bak_cur_addr, buff, sizeof(buff)); - result = ef_port_write(bl_cur_addr, buff, sizeof(buff)); - if (result != EF_NO_ERR) - break; - } - - switch (result) { - case EF_NO_ERR: { - EF_INFO("Write data to bootloader entry OK.\n"); - break; - } - case EF_WRITE_ERR: { - EF_INFO("Warning: Write data to bootloader entry fault!\n"); - break; - } - } - - return result; -} - -/** - * Get IAP section start address in flash. - * - * @return size - */ -uint32_t ef_get_bak_app_start_addr(void) -{ - return bak_app_start_addr; -} - -#endif /* EF_USING_IAP */ diff --git a/bk7235/liteos_m/bk_sdk_armino/components/easy_flash/src/ef_log.c b/bk7235/liteos_m/bk_sdk_armino/components/easy_flash/src/ef_log.c deleted file mode 100644 index 87fb9fda73177ea42847e1bcb3cbb763b623c281..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/easy_flash/src/ef_log.c +++ /dev/null @@ -1,700 +0,0 @@ -/* - * This file is part of the EasyFlash Library. - * - * Copyright (c) 2015-2017, Armink, - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * 'Software'), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY - * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * Function: Save logs to flash. - * Created on: 2015-06-04 - */ - -#include - -#ifdef EF_USING_LOG - -/* magic code on every sector header. 'EF' is 0x4546 */ -#define LOG_SECTOR_MAGIC 0x4546 -/* sector header size, include the sector magic code and status magic code */ -#define LOG_SECTOR_HEADER_SIZE 4 - -/** - * Sector status magic code - * The sector status is 16-Bits after LOG_SECTOR_MAGIC at every sector header. - * ======================= - * | header(4B) | status | - * ----------------------- - * | 0x4546FFFF | empty | - * | 0x4546FFFE | using | - * | 0x4546FFFC | full | - * ======================= - * - * State transition relationship: empty->using->full - * The FULL status will change to EMPTY after sector clean. - */ -enum { - SECTOR_STATUS_MAGIC_EMPUT = 0xFFFF, - SECTOR_STATUS_MAGIC_USING = 0xFFFE, - SECTOR_STATUS_MAGIC_FULL = 0xFFFC, -}; - -typedef enum { - SECTOR_STATUS_EMPUT, - SECTOR_STATUS_USING, - SECTOR_STATUS_FULL, - SECTOR_STATUS_HEADER_ERROR, -} SectorStatus; - -/* the stored logs start address and end address. It's like a ring buffer which implement by flash. */ -static uint32_t log_start_addr = 0, log_end_addr = 0; -/* saved log area address for flash */ -static uint32_t log_area_start_addr = 0; -/* initialize OK flag */ -static bool init_ok = false; - -static void find_start_and_end_addr(void); -static uint32_t get_next_flash_sec_addr(uint32_t cur_addr); - -/** - * The flash save log function initialize. - * - * @return result - */ -EfErrCode ef_log_init(void) -{ - EfErrCode result = EF_NO_ERR; - - EF_ASSERT(LOG_AREA_SIZE); - EF_ASSERT(EF_ERASE_MIN_SIZE); - /* the log area size must be an integral multiple of erase minimum size. */ - EF_ASSERT(LOG_AREA_SIZE % EF_ERASE_MIN_SIZE == 0); - /* the log area size must be more than twice of EF_ERASE_MIN_SIZE */ - EF_ASSERT(LOG_AREA_SIZE / EF_ERASE_MIN_SIZE >= 2); - -#ifdef EF_USING_ENV - log_area_start_addr = EF_START_ADDR + ENV_AREA_SIZE; -#else - log_area_start_addr = EF_START_ADDR; -#endif - - /* find the log store start address and end address */ - find_start_and_end_addr(); - /* initialize OK */ - init_ok = true; - - return result; -} - -/** - * Get flash sector current status. - * - * @param addr sector address, this function will auto calculate the sector header address by this address. - * - * @return the flash sector current status - */ -static SectorStatus get_sector_status(uint32_t addr) -{ - uint32_t header = 0, header_addr = 0; - uint16_t sector_magic = 0, status_magic = 0; - - /* calculate the sector header address */ - header_addr = addr / EF_ERASE_MIN_SIZE * EF_ERASE_MIN_SIZE; - - if (ef_port_read(header_addr, &header, sizeof(header)) == EF_NO_ERR) { - sector_magic = header >> 16; - status_magic = header; - } else { - EF_DEBUG("Error: Read sector header data error.\n"); - return SECTOR_STATUS_HEADER_ERROR; - } - /* compare header magic code */ - if (sector_magic == LOG_SECTOR_MAGIC) { - switch (status_magic) { - case SECTOR_STATUS_MAGIC_EMPUT: - return SECTOR_STATUS_EMPUT; - case SECTOR_STATUS_MAGIC_USING: - return SECTOR_STATUS_USING; - case SECTOR_STATUS_MAGIC_FULL: - return SECTOR_STATUS_FULL; - default: - return SECTOR_STATUS_HEADER_ERROR; - } - } else - return SECTOR_STATUS_HEADER_ERROR; -} - -/** - * Write flash sector current status. - * - * @param addr sector address, this function will auto calculate the sector header address by this address. - * @param status sector cur status - * - * @return result - */ -static EfErrCode write_sector_status(uint32_t addr, SectorStatus status) -{ - uint32_t header = 0, header_addr = 0; - uint16_t status_magic; - - /* calculate the sector header address */ - header_addr = addr / EF_ERASE_MIN_SIZE * EF_ERASE_MIN_SIZE; - - switch (status) { - case SECTOR_STATUS_EMPUT: { - status_magic = SECTOR_STATUS_MAGIC_EMPUT; - break; - } - case SECTOR_STATUS_USING: { - status_magic = SECTOR_STATUS_MAGIC_USING; - break; - } - case SECTOR_STATUS_FULL: { - status_magic = SECTOR_STATUS_MAGIC_FULL; - break; - } - } - header = (LOG_SECTOR_MAGIC << 16) | status_magic; - - return ef_port_write(header_addr, &header, sizeof(header)); -} - -/** - * Find the current flash sector using end address by continuous 0xFF. - * - * @param addr sector address - * - * @return current flash sector using end address - */ -static uint32_t find_sec_using_end_addr(uint32_t addr) -{ - /* read section data buffer size */ -#define READ_BUF_SIZE 32 - - uint32_t sector_start = addr, data_start = addr, continue_ff = 0, read_buf_size = 0, i; - uint8_t buf[READ_BUF_SIZE]; - - EF_ASSERT(READ_BUF_SIZE % 4 == 0); - /* calculate the sector start and data start address */ - sector_start = addr / EF_ERASE_MIN_SIZE * EF_ERASE_MIN_SIZE; - data_start = sector_start + LOG_SECTOR_HEADER_SIZE; - - /* counts continuous 0xFF which is end of sector */ - while (data_start < sector_start + EF_ERASE_MIN_SIZE) { - if (data_start + READ_BUF_SIZE < sector_start + EF_ERASE_MIN_SIZE) - read_buf_size = READ_BUF_SIZE; - else - read_buf_size = sector_start + EF_ERASE_MIN_SIZE - data_start; - ef_port_read(data_start, (uint32_t *)buf, read_buf_size); - for (i = 0; i < read_buf_size; i++) { - if (buf[i] == 0xFF) - continue_ff++; - else - continue_ff = 0; - } - data_start += read_buf_size; - } - /* calculate current flash sector using end address */ - if (continue_ff >= EF_ERASE_MIN_SIZE - LOG_SECTOR_HEADER_SIZE) { - /* from 0 to sec_size all sector is 0xFF, so the sector is empty */ - return sector_start + LOG_SECTOR_HEADER_SIZE; - } else if (continue_ff >= 4) { - /* form end_addr - 4 to sec_size length all area is 0xFF, so it's used part of the sector. - * the address must be word alignment. */ - if (continue_ff % 4 != 0) - continue_ff = (continue_ff / 4 + 1) * 4; - return sector_start + EF_ERASE_MIN_SIZE - continue_ff; - } else { - /* all sector not has continuous 0xFF, so the sector is full */ - return sector_start + EF_ERASE_MIN_SIZE; - } -} - -/** - * Find the log store start address and end address. - * It's like a ring buffer which implement by flash. - * The flash log area has two state when find start address and end address. - * state 1 state 2 - * |============| |============| - * log area start--> |############| <-- start address |############| <-- end address - * |############| | empty | - * |------------| |------------| - * |############| |############| <-- start address - * |############| |############| - * |------------| |------------| - * | . | | . | - * | . | | . | - * | . | | . | - * |------------| |------------| - * |############| <-- end address |############| - * | empty | |############| - * log area end --> |============| |============| - * - * LOG_AREA_SIZE = log area end - log area star - * - */ -static void find_start_and_end_addr(void) -{ - size_t cur_size = 0; - SectorStatus cur_sec_status, last_sec_status; - uint32_t cur_using_sec_addr = 0; - /* all status sector counts */ - size_t empty_sec_counts = 0, using_sec_counts = 0, full_sector_counts = 0; - /* total sector number */ - size_t total_sec_num = LOG_AREA_SIZE / EF_ERASE_MIN_SIZE; - /* see comment of find_start_and_end_addr function */ - uint8_t cur_log_sec_state = 0; - - /* get the first sector status */ - cur_sec_status = get_sector_status(log_area_start_addr); - last_sec_status = cur_sec_status; - - for (cur_size = EF_ERASE_MIN_SIZE; cur_size < LOG_AREA_SIZE; cur_size += EF_ERASE_MIN_SIZE) { - /* get current sector status */ - cur_sec_status = get_sector_status(log_area_start_addr + cur_size); - /* compare last and current status */ - switch (last_sec_status) { - case SECTOR_STATUS_EMPUT: { - switch (cur_sec_status) { - case SECTOR_STATUS_EMPUT: - break; - case SECTOR_STATUS_USING: - EF_DEBUG("Error: Log area error! Now will clean all log area.\n"); - ef_log_clean(); - return; - case SECTOR_STATUS_FULL: - EF_DEBUG("Error: Log area error! Now will clean all log area.\n"); - ef_log_clean(); - return; - } - empty_sec_counts++; - break; - } - case SECTOR_STATUS_USING: { - switch (cur_sec_status) { - case SECTOR_STATUS_EMPUT: - /* like state 1 */ - cur_log_sec_state = 1; - log_start_addr = log_area_start_addr; - cur_using_sec_addr = log_area_start_addr + cur_size - EF_ERASE_MIN_SIZE; - break; - case SECTOR_STATUS_USING: - EF_DEBUG("Error: Log area error! Now will clean all log area.\n"); - ef_log_clean(); - return; - case SECTOR_STATUS_FULL: - /* like state 2 */ - cur_log_sec_state = 2; - log_start_addr = log_area_start_addr + cur_size; - cur_using_sec_addr = log_area_start_addr + cur_size - EF_ERASE_MIN_SIZE; - break; - } - using_sec_counts++; - break; - } - case SECTOR_STATUS_FULL: { - switch (cur_sec_status) { - case SECTOR_STATUS_EMPUT: - /* like state 1 */ - if (cur_log_sec_state == 2) { - EF_DEBUG("Error: Log area error! Now will clean all log area.\n"); - ef_log_clean(); - return; - } else { - cur_log_sec_state = 1; - log_start_addr = log_area_start_addr; - log_end_addr = log_area_start_addr + cur_size; - cur_using_sec_addr = log_area_start_addr + cur_size - EF_ERASE_MIN_SIZE; - } - break; - case SECTOR_STATUS_USING: - if (total_sec_num <= 2) { - /* like state 1 */ - cur_log_sec_state = 1; - log_start_addr = log_area_start_addr; - cur_using_sec_addr = log_area_start_addr + cur_size; - } else { - /* like state 2 when the sector is the last one */ - if (cur_size + EF_ERASE_MIN_SIZE >= LOG_AREA_SIZE) { - cur_log_sec_state = 2; - log_start_addr = log_area_start_addr + cur_size; - cur_using_sec_addr = log_area_start_addr + cur_size - EF_ERASE_MIN_SIZE; - } - } - break; - case SECTOR_STATUS_FULL: - break; - } - full_sector_counts++; - break; - } - case SECTOR_STATUS_HEADER_ERROR: - EF_DEBUG("Error: Log sector header error! Now will clean all log area.\n"); - ef_log_clean(); - return; - } - last_sec_status = cur_sec_status; - } - - /* the last sector status counts */ - if (cur_sec_status == SECTOR_STATUS_EMPUT) - empty_sec_counts++; - else if (cur_sec_status == SECTOR_STATUS_USING) - using_sec_counts++; - else if (cur_sec_status == SECTOR_STATUS_FULL) - full_sector_counts++; - else if (cur_sec_status == SECTOR_STATUS_HEADER_ERROR) { - EF_DEBUG("Error: Log sector header error! Now will clean all log area.\n"); - ef_log_clean(); - return; - } - - if (using_sec_counts != 1) { - /* this state is almost impossible */ - EF_DEBUG("Error: There must be only one sector status is USING! Now will clean all log area.\n"); - ef_log_clean(); - } else { - /* find the end address */ - log_end_addr = find_sec_using_end_addr(cur_using_sec_addr); - } -} - -/** - * Get log used flash total size. - * - * @return log used flash total size. @note NOT contain sector headers - */ -size_t ef_log_get_used_size(void) -{ - size_t header_total_num = 0, physical_size = 0; - /* must be call this function after initialize OK */ - if (!init_ok) - return 0; - - if (log_start_addr < log_end_addr) - physical_size = log_end_addr - log_start_addr; - else - physical_size = LOG_AREA_SIZE - (log_start_addr - log_end_addr); - - header_total_num = physical_size / EF_ERASE_MIN_SIZE + 1; - - return physical_size - header_total_num * LOG_SECTOR_HEADER_SIZE; -} - -/** - * Sequential reading log data. It will ignore sector headers. - * - * @param addr address - * @param log log buffer - * @param size log size, not contain sector headers. - * - * @return result - */ -static EfErrCode log_seq_read(uint32_t addr, uint32_t *log, size_t size) -{ - EfErrCode result = EF_NO_ERR; - size_t read_size = 0, read_size_temp = 0; - - while (size) { - /* move to sector data address */ - if ((addr + read_size) % EF_ERASE_MIN_SIZE == 0) - addr += LOG_SECTOR_HEADER_SIZE; - /* calculate current sector last data size */ - read_size_temp = EF_ERASE_MIN_SIZE - (addr % EF_ERASE_MIN_SIZE); - if (size < read_size_temp) - read_size_temp = size; - result = ef_port_read(addr + read_size, log + read_size / 4, read_size_temp); - if (result != EF_NO_ERR) - return result; - read_size += read_size_temp; - size -= read_size_temp; - } - - return result; -} - -/** - * Calculate flash physical address by log index. - * - * @param index log index - * - * @return flash physical address - */ -static uint32_t log_index2addr(size_t index) -{ - size_t header_total_offset = 0; - /* total include sector number */ - size_t sector_num = index / (EF_ERASE_MIN_SIZE - LOG_SECTOR_HEADER_SIZE) + 1; - - header_total_offset = sector_num * LOG_SECTOR_HEADER_SIZE; - if (log_start_addr < log_end_addr) - return log_start_addr + index + header_total_offset; - else { - if (log_start_addr + index + header_total_offset < log_area_start_addr + LOG_AREA_SIZE) - return log_start_addr + index + header_total_offset; - else - return log_start_addr + index + header_total_offset - LOG_AREA_SIZE; - - } -} - -/** - * Read log from flash. - * - * @param index index for saved log. - * Minimum index is 0. - * Maximum index is ef_log_get_used_size() - 1. - * @param log the log which will read from flash - * @param size read bytes size - * - * @return result - */ -EfErrCode ef_log_read(size_t index, uint32_t *log, size_t size) -{ - EfErrCode result = EF_NO_ERR; - size_t cur_using_size = ef_log_get_used_size(); - size_t read_size_temp = 0; - size_t header_total_num = 0; - - if (!size) - return result; - - EF_ASSERT(size % 4 == 0); - EF_ASSERT(index < cur_using_size); - - if (index + size > cur_using_size) { - EF_DEBUG("Warning: Log read size out of bound. Cut read size.\n"); - size = cur_using_size - index; - } - /* must be call this function after initialize OK */ - if (!init_ok) - return EF_ENV_INIT_FAILED; - - if (log_start_addr < log_end_addr) - log_seq_read(log_index2addr(index), log, size); - else { - if (log_index2addr(index) + size <= log_area_start_addr + LOG_AREA_SIZE) { - /* Flash log area - * |--------------| - * log_area_start_addr --> |##############| - * |##############| - * |##############| - * |--------------| - * |##############| - * |##############| - * |##############| <-- log_end_addr - * |--------------| - * log_start_addr --> |##############| - * read start --> |**************| <-- read end - * |##############| - * |--------------| - * - * read from (log_start_addr + log_index2addr(index)) to (log_start_addr + index + log_index2addr(index)) - */ - result = log_seq_read(log_index2addr(index), log, size); - } else if (log_index2addr(index) < log_area_start_addr + LOG_AREA_SIZE) { - /* Flash log area - * |--------------| - * log_area_start_addr --> |**************| <-- read end - * |##############| - * |##############| - * |--------------| - * |##############| - * |##############| - * |##############| <-- log_end_addr - * |--------------| - * log_start_addr --> |##############| - * read start --> |**************| - * |**************| - * |--------------| - * read will by 2 steps - * step1: read from (log_start_addr + log_index2addr(index)) to flash log area end address - * step2: read from flash log area start address to read size's end address - */ - read_size_temp = (log_area_start_addr + LOG_AREA_SIZE) - log_index2addr(index); - header_total_num = read_size_temp / EF_ERASE_MIN_SIZE; - /* Minus some ignored bytes */ - read_size_temp -= header_total_num * LOG_SECTOR_HEADER_SIZE; - result = log_seq_read(log_index2addr(index), log, read_size_temp); - if (result == EF_NO_ERR) - result = log_seq_read(log_area_start_addr, log + read_size_temp / 4, size - read_size_temp); - } else { - /* Flash log area - * |--------------| - * log_area_start_addr --> |##############| - * read start --> |**************| - * |**************| <-- read end - * |--------------| - * |##############| - * |##############| - * |##############| <-- log_end_addr - * |--------------| - * log_start_addr --> |##############| - * |##############| - * |##############| - * |--------------| - * read from (log_start_addr + log_index2addr(index) - LOG_AREA_SIZE) to read size's end address - */ - result = log_seq_read(log_index2addr(index) - LOG_AREA_SIZE, log, size); - } - } - - return result; -} - -/** - * Write log to flash. - * - * @param log the log which will be write to flash - * @param size write bytes size - * - * @return result - */ -EfErrCode ef_log_write(const uint32_t *log, size_t size) -{ - EfErrCode result = EF_NO_ERR; - size_t write_size = 0, writable_size = 0; - uint32_t write_addr = log_end_addr, erase_addr; - SectorStatus sector_status; - - EF_ASSERT(size % 4 == 0); - /* must be call this function after initialize OK */ - if (!init_ok) - return EF_ENV_INIT_FAILED; - - if ((sector_status = get_sector_status(write_addr)) == SECTOR_STATUS_HEADER_ERROR) - return EF_WRITE_ERR; - /* write some log when current sector status is USING and EMPTY */ - if ((sector_status == SECTOR_STATUS_USING) || (sector_status == SECTOR_STATUS_EMPUT)) { - /* write the already erased but not used area */ - writable_size = EF_ERASE_MIN_SIZE - ((write_addr - log_area_start_addr) % EF_ERASE_MIN_SIZE); - if (size >= writable_size) { - result = ef_port_write(write_addr, log, writable_size); - if (result != EF_NO_ERR) - goto exit; - /* change the current sector status to FULL */ - result = write_sector_status(write_addr, SECTOR_STATUS_FULL); - if (result != EF_NO_ERR) - goto exit; - write_size += writable_size; - } else { - result = ef_port_write(write_addr, log, size); - log_end_addr = write_addr + size; - goto exit; - } - } - /* erase and write remain log */ - while (true) { - /* calculate next available sector address */ - erase_addr = write_addr = get_next_flash_sec_addr(write_addr - 4); - /* move the flash log start address to next available sector address */ - if (log_start_addr == erase_addr) - log_start_addr = get_next_flash_sec_addr(log_start_addr); - /* erase sector */ - result = ef_port_erase(erase_addr, EF_ERASE_MIN_SIZE); - if (result != EF_NO_ERR) - goto exit; - /* change the sector status to USING when write begin sector start address */ - result = write_sector_status(write_addr, SECTOR_STATUS_USING); - if (result == EF_NO_ERR) - write_addr += LOG_SECTOR_HEADER_SIZE; - else - goto exit; - /* calculate current sector writable data size */ - writable_size = EF_ERASE_MIN_SIZE - LOG_SECTOR_HEADER_SIZE; - if (size - write_size >= writable_size) { - result = ef_port_write(write_addr, log + write_size / 4, writable_size); - if (result != EF_NO_ERR) - goto exit; - /* change the current sector status to FULL */ - result = write_sector_status(write_addr, SECTOR_STATUS_FULL); - if (result != EF_NO_ERR) - goto exit; - log_end_addr = write_addr + writable_size; - write_size += writable_size; - write_addr += writable_size; - } else { - result = ef_port_write(write_addr, log + write_size / 4, size - write_size); - if (result != EF_NO_ERR) - goto exit; - log_end_addr = write_addr + (size - write_size); - break; - } - } - -exit: - return result; -} - -/** - * Get next flash sector address.The log total sector like ring buffer which implement by flash. - * - * @param cur_addr cur flash address - * - * @return next flash sector address - */ -static uint32_t get_next_flash_sec_addr(uint32_t cur_addr) -{ - size_t cur_sec_id = (cur_addr - log_area_start_addr) / EF_ERASE_MIN_SIZE; - size_t sec_total_num = LOG_AREA_SIZE / EF_ERASE_MIN_SIZE; - - if (cur_sec_id + 1 >= sec_total_num) { - /* return to ring head */ - return log_area_start_addr; - } else - return log_area_start_addr + (cur_sec_id + 1) * EF_ERASE_MIN_SIZE; -} - -/** - * Clean all log which in flash. - * - * @return result - */ -EfErrCode ef_log_clean(void) -{ - EfErrCode result = EF_NO_ERR; - uint32_t write_addr = log_area_start_addr; - - /* clean address */ - log_start_addr = log_area_start_addr; - log_end_addr = log_start_addr + LOG_SECTOR_HEADER_SIZE; - /* erase log flash area */ - result = ef_port_erase(log_area_start_addr, LOG_AREA_SIZE); - if (result != EF_NO_ERR) - goto exit; - /* setting first sector is USING */ - write_sector_status(write_addr, SECTOR_STATUS_USING); - if (result != EF_NO_ERR) - goto exit; - write_addr += EF_ERASE_MIN_SIZE; - /* add sector header */ - while (true) { - write_sector_status(write_addr, SECTOR_STATUS_EMPUT); - if (result != EF_NO_ERR) - goto exit; - write_addr += EF_ERASE_MIN_SIZE; - if (write_addr >= log_area_start_addr + LOG_AREA_SIZE) - break; - } - -exit: - return result; -} - -#endif /* EF_USING_LOG */ diff --git a/bk7235/liteos_m/bk_sdk_armino/components/easy_flash/src/ef_utils.c b/bk7235/liteos_m/bk_sdk_armino/components/easy_flash/src/ef_utils.c deleted file mode 100644 index 2ddd706f01aa16e64dae445d1f1a221038cbe896..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/easy_flash/src/ef_utils.c +++ /dev/null @@ -1,97 +0,0 @@ -/* - * This file is part of the EasyFlash Library. - * - * Copyright (c) 2015-2017, Armink, - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * 'Software'), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY - * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * Function: Some utils for this library. - * Created on: 2015-01-14 - */ - -#include - -static const uint32_t crc32_table[] = { - 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, - 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, - 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2, - 0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, - 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, - 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, - 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 0x35b5a8fa, 0x42b2986c, - 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59, - 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, - 0xcfba9599, 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, - 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, 0x01db7106, - 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433, - 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, - 0x91646c97, 0xe6635c01, 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, - 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950, - 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65, - 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7, - 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, - 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, - 0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, - 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81, - 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, - 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, 0xe3630b12, 0x94643b84, - 0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, - 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, - 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, - 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 0xd6d6a3e8, 0xa1d1937e, - 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b, - 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, - 0x316e8eef, 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, - 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, 0xb2bd0b28, - 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d, - 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f, - 0x72076785, 0x05005713, 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, - 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242, - 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777, - 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69, - 0x616bffd3, 0x166ccf45, 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, - 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, - 0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, - 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693, - 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, - 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d -}; - -/** - * Calculate the CRC32 value of a memory buffer. - * - * @param crc accumulated CRC32 value, must be 0 on first call - * @param buf buffer to calculate CRC32 value for - * @param size bytes in buffer - * - * @return calculated CRC32 value - */ -uint32_t ef_calc_crc32(uint32_t crc, const void *buf, size_t size) -{ - const uint8_t *p; - - p = (const uint8_t *)buf; - crc = crc ^ ~0U; - - while (size--) - crc = crc32_table[(crc ^ *p++) & 0xFF] ^ (crc >> 8); - - return crc ^ ~0U; -} diff --git a/bk7235/liteos_m/bk_sdk_armino/components/key/key_main.c b/bk7235/liteos_m/bk_sdk_armino/components/key/key_main.c index 7bb178228b1c8b35ffbfa176d6c226dc3679a9a9..534847aba53f5b2627cb86ab96e488df6f855852 100644 --- a/bk7235/liteos_m/bk_sdk_armino/components/key/key_main.c +++ b/bk7235/liteos_m/bk_sdk_armino/components/key/key_main.c @@ -1,3 +1,17 @@ +/* + * Copyright (C) 2022 Beken Corporation + * 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 #include #include "bk_arm_arch.h" diff --git a/bk7235/liteos_m/bk_sdk_armino/components/key/key_main.h b/bk7235/liteos_m/bk_sdk_armino/components/key/key_main.h index 7295e5c7f774a73cb7794ab0f3c64eadbd136729..774611ac37ba4ad0f0bbb2eabcca9fcf9a099e1e 100644 --- a/bk7235/liteos_m/bk_sdk_armino/components/key/key_main.h +++ b/bk7235/liteos_m/bk_sdk_armino/components/key/key_main.h @@ -1,3 +1,17 @@ +/* + * Copyright (C) 2022 Beken Corporation + * 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 _KEY_MAIN_H_ #define _KEY_MAIN_H_ diff --git a/bk7235/liteos_m/bk_sdk_armino/components/key/multi_button.c b/bk7235/liteos_m/bk_sdk_armino/components/key/multi_button.c index e6bb263781812e62ffbbe63fc0346e433c65b37e..6685ba63aacfed40218684d3cb259f4c05564915 100644 --- a/bk7235/liteos_m/bk_sdk_armino/components/key/multi_button.c +++ b/bk7235/liteos_m/bk_sdk_armino/components/key/multi_button.c @@ -1,3 +1,17 @@ +/* + * Copyright (C) 2022 Beken Corporation + * 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 #include #include "bk_arm_arch.h" diff --git a/bk7235/liteos_m/bk_sdk_armino/components/key/multi_button.h b/bk7235/liteos_m/bk_sdk_armino/components/key/multi_button.h index 1020dae4e12eecd982e32ee4355e6c22a26e704d..0feb9420b9908cdeffe7a298aa15105d90c790ae 100644 --- a/bk7235/liteos_m/bk_sdk_armino/components/key/multi_button.h +++ b/bk7235/liteos_m/bk_sdk_armino/components/key/multi_button.h @@ -1,3 +1,17 @@ +/* + * Copyright (C) 2022 Beken Corporation + * 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 _MULTI_BUTTON_H_ #define _MULTI_BUTTON_H_ diff --git a/bk7235/liteos_m/bk_sdk_armino/components/key_handle/key_handle.c b/bk7235/liteos_m/bk_sdk_armino/components/key_handle/key_handle.c deleted file mode 100644 index 6d4c6942df635259ae200799b308ff07de28cafc..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/key_handle/key_handle.c +++ /dev/null @@ -1,152 +0,0 @@ -#include "key_handle.h" -#include -#include -#include -#include "bk_arm_arch.h" -#include "bk_gpio.h" -#include "bk_uart.h" -#include "bk_music_msg.h" - -#if(CONFIG_MP3PLAYER == 1) -#define SD_DEBOUNCE_COUNT 50 -#define KEY_SCAN_INTERVAL_10MS 10 - -#if (CONFIG_SOC_BK7251) -#define SD_CARD_DETECT_PIN 31 -#else -#define SD_CARD_DETECT_PIN 25 -#endif - -#define KEY_PLAY_PAUSE_PIN 28 - -#define SD_CARD_OFFLINE 0 -#define SD_CARD_ONLINE 1 - -#define KEY_SHORTUP_COUNTER 3 //30ms -#define KEY_LONG_COUNTER 80 //800ms -#define KEY_LONGUP_COUNTER 84 //840ms -#define KEY_HOLD_COUNTER 110 //1100ms - -static void key_scan_callback(void *arg); -extern void bmsg_music_sender(void *arg); - -static UINT16 backup_keyval = MSG_NO_KEY; -static UINT16 keycount = 0; -static UINT16 sd_online = SD_CARD_OFFLINE; -static UINT16 detect_cnt = 0; -static beken_timer_t key_handle_timer = {0}; - - -void key_init(void) -{ - UINT32 param; - bk_err_t err; - - param = GPIO_CFG_PARAM(SD_CARD_DETECT_PIN, GMODE_INPUT_PULLUP); - sddev_control(DD_DEV_TYPE_GPIO, CMD_GPIO_CFG, ¶m); - - param = GPIO_CFG_PARAM(KEY_PLAY_PAUSE_PIN, GMODE_INPUT_PULLUP); - sddev_control(DD_DEV_TYPE_GPIO, CMD_GPIO_CFG, ¶m); - - - err = rtos_init_timer(&key_handle_timer, - KEY_SCAN_INTERVAL_10MS, - key_scan_callback, - (void *)0); - BK_ASSERT(kNoErr == err); - err = rtos_start_timer(&key_handle_timer); - BK_ASSERT(kNoErr == err); - - KEY_PRT("==key init==\r\n"); -} - -uint8 sd_is_attached(void) -{ - return (sd_online); -} - -static void sd_detect_handle() -{ - UINT32 sd_pin_level; - UINT32 sd_detect_pin = SD_CARD_DETECT_PIN; - - sd_pin_level = sddev_control(DD_DEV_TYPE_GPIO, CMD_GPIO_INPUT, &sd_detect_pin); - UINT32 msg; - if (sd_pin_level) { - if (sd_online == SD_CARD_ONLINE) { - detect_cnt = 0; - sd_online = SD_CARD_OFFLINE; - msg = MSG_SD_DETACH; - //?detach??? - bmsg_music_sender((void *)msg); - } - } else { - if (sd_online == SD_CARD_OFFLINE) { - if (detect_cnt < SD_DEBOUNCE_COUNT) - detect_cnt++; - else { - sd_online = SD_CARD_ONLINE; - msg = MSG_SD_ATTACH; - //?attach??? - bmsg_music_sender((void *)msg); - } - } - } -} - -static UINT16 keyIOdetect(void) -{ - UINT16 key_pin_level; - UINT16 keyValue = MSG_NO_KEY;; - UINT32 key_detect_pin = KEY_PLAY_PAUSE_PIN; - - key_pin_level = sddev_control(DD_DEV_TYPE_GPIO, CMD_GPIO_INPUT, &key_detect_pin); - if (key_pin_level == 0) - keyValue = MSG_KEY_PLAY; - - return keyValue; -} - - -static void key_detect_handle(void) -{ - UINT32 msg; - UINT16 keyval = keyIOdetect(); - - if (keyval == MSG_NO_KEY) { - if (keycount >= KEY_SHORTUP_COUNTER) { - if (keycount > KEY_LONG_COUNTER) - msg = KEY_LONG_UP | backup_keyval; - else - msg = backup_keyval; - bmsg_music_sender((void *)msg); - } - keycount = 0; - backup_keyval = MSG_NO_KEY; - } else { - if (keyval != backup_keyval) { - keycount = 0; - backup_keyval = keyval; - } - - keycount++; - - if ((keycount == KEY_LONG_COUNTER) || (keycount == KEY_HOLD_COUNTER)) { - if (keycount == KEY_LONG_COUNTER) - msg = KEY_LONG | keyval; - else { - keycount = KEY_LONGUP_COUNTER; - msg = KEY_HOLD | keyval; - } - bmsg_music_sender((void *)msg); - } - } -} - - -static void key_scan_callback(void *arg) -{ - sd_detect_handle(); - key_detect_handle(); -} -#endif diff --git a/bk7235/liteos_m/bk_sdk_armino/components/key_handle/key_handle.h b/bk7235/liteos_m/bk_sdk_armino/components/key_handle/key_handle.h index adbebf578961ffdfec12540cd4aa25b9e63a8a6f..c930a1bf565db8e08c0f917470384d8bdcb5b175 100644 --- a/bk7235/liteos_m/bk_sdk_armino/components/key_handle/key_handle.h +++ b/bk7235/liteos_m/bk_sdk_armino/components/key_handle/key_handle.h @@ -1,3 +1,17 @@ +/* + * Copyright (C) 2022 Beken Corporation + * 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 _KEY_HANDLE_H_ #define _KEY_HANDLE_H_ diff --git a/bk7235/liteos_m/bk_sdk_armino/components/lwip_intf_v2_1/CMakeLists.txt b/bk7235/liteos_m/bk_sdk_armino/components/lwip_intf_v2_1/CMakeLists.txt deleted file mode 100644 index 4607f8eb9f6a861caf891bb378fb73c3711098a8..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/lwip_intf_v2_1/CMakeLists.txt +++ /dev/null @@ -1,91 +0,0 @@ -set(incs) -set(srcs) - -if(CONFIG_HARMONY_LWIP) - set(lwip_dir "../../../../../../../../third_party/lwip") - set(liteos_dir "../../../../../../../../kernel/liteos_m") - set(extra_dir "../../../../../../../../device/soc/beken/bk7235/liteos_m") -else() - set(lwip_dir "lwip-2.1.2") -endif() - -if (CONFIG_LWIP_V2_1) - list(APPEND incs - ${lwip_dir}/src - lwip-2.1.2/port - ${lwip_dir}/src/include - ${lwip_dir}/src/include/netif - ${lwip_dir}/src/include/lwip - ${liteos_dir}/arch/risc-v/riscv32/gcc - ${liteos_dir}/arch/risc-v/riscv32/gcc/asm - ${liteos_dir}/arch/include - ${liteos_dir}/kernel/include - ${liteos_dir}/kal/cmsis - ${liteos_dir}/kal/posix/include - ${liteos_dir}/components/power - ${liteos_dir}/components/signal - ${liteos_dir}/utils - ${extra_dir}/inc - ) - - list(APPEND srcs - lwip-2.1.2/port/ethernetif.c - lwip-2.1.2/port/net.c - lwip-2.1.2/port/sys_arch.c - lwip-2.1.2/port/sockets.c - #lwip-2.1.2/port/ping.c - ${lwip_dir}/src/api/api_lib.c - ${lwip_dir}/src/api/api_msg.c - ${lwip_dir}/src/api/err.c - ${lwip_dir}/src/api/netbuf.c - ${lwip_dir}/src/api/netdb.c - ${lwip_dir}/src/api/netifapi.c - #${lwip_dir}/src/api/sockets.c - ${lwip_dir}/src/api/tcpip.c - ${lwip_dir}/src/apps/mdns/mdns.c - #lwip-2.1.2/src/apps/ping/ping.c - ${lwip_dir}/src/core/def.c - ${lwip_dir}/src/core/dns.c - ${lwip_dir}/src/core/inet_chksum.c - ${lwip_dir}/src/core/init.c - ${lwip_dir}/src/core/ip.c - ${lwip_dir}/src/core/ipv4/autoip.c - ${lwip_dir}/src/core/ipv4/dhcp.c - ${lwip_dir}/src/core/ipv4/etharp.c - ${lwip_dir}/src/core/ipv4/icmp.c - ${lwip_dir}/src/core/ipv4/igmp.c - ${lwip_dir}/src/core/ipv4/ip4_addr.c - ${lwip_dir}/src/core/ipv4/ip4.c - ${lwip_dir}/src/core/ipv4/ip4_frag.c - ${lwip_dir}/src/core/ipv6/dhcp6.c - ${lwip_dir}/src/core/ipv6/ethip6.c - ${lwip_dir}/src/core/ipv6/icmp6.c - ${lwip_dir}/src/core/ipv6/inet6.c - ${lwip_dir}/src/core/ipv6/ip6_addr.c - ${lwip_dir}/src/core/ipv6/ip6.c - ${lwip_dir}/src/core/ipv6/ip6_frag.c - ${lwip_dir}/src/core/ipv6/mld6.c - ${lwip_dir}/src/core/ipv6/nd6.c - ${lwip_dir}/src/core/mem.c - ${lwip_dir}/src/core/memp.c - ${lwip_dir}/src/core/netif.c - ${lwip_dir}/src/core/pbuf.c - ${lwip_dir}/src/core/raw.c - ${lwip_dir}/src/core/stats.c - ${lwip_dir}/src/core/sys.c - ${lwip_dir}/src/core/tcp.c - ${lwip_dir}/src/core/tcp_in.c - ${lwip_dir}/src/core/tcp_out.c - ${lwip_dir}/src/core/timeouts.c - ${lwip_dir}/src/core/udp.c - ${lwip_dir}/src/netif/ethernet.c - dhcpd/dhcp-server.c - dhcpd/dhcp-server-main.c - ) -endif() - -armino_component_register(SRCS "${srcs}" - INCLUDE_DIRS "${incs}" - REQUIRES driver - PRIV_REQUIRES bk_common bk_wifi - ) diff --git a/bk7235/liteos_m/bk_sdk_armino/components/lwip_intf_v2_1/Kconfig b/bk7235/liteos_m/bk_sdk_armino/components/lwip_intf_v2_1/Kconfig deleted file mode 100644 index 95b574c881f0b8d59877c280c9deb0702e050631..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/lwip_intf_v2_1/Kconfig +++ /dev/null @@ -1,57 +0,0 @@ -#TODO add depens for CONFIG_HOST (bk7231u) -menu "LwIP 2.1.2" - config LWIP - bool "Enable LWIP" - default y - - config IPV6 - bool "Enable IPV6" - default n - - config DHCP - bool "Enable DHCP" - depends on LWIP - default y - - config AUTOIP - bool "Enable AUTOIP" - depends on LWIP - default n - - config MDNS - bool "Enable MDNS" - depends on LWIP - default n - - config TASK_LWIP_PRIO - int "Priority of LwIP task" - depends on LWIP - range 1 10 - default 4 - - config MIDEA - bool "Enable MIDEA" - depends on LWIP - default n - - config LWIP_FAST_DHCP - bool "Enable Fast DHCP(use previous IP)" - default n - - config HARMONY_LWIP - bool "Enable harmony lwip" - default n - - #TODO optimize it - choice LWIP_MEM - depends on LWIP - prompt "LWIP Memory Policy" - default LWIP_MEM_DEFAULT - - config LWIP_MEM_DEFAULT - bool "Default Memory Policy" - config LWIP_MEM_REDUCE - bool "Reduced Memory Policy" - endchoice - -endmenu diff --git a/bk7235/liteos_m/bk_sdk_armino/components/lwip_intf_v2_1/dhcpd/dhcp-bootp.h b/bk7235/liteos_m/bk_sdk_armino/components/lwip_intf_v2_1/dhcpd/dhcp-bootp.h deleted file mode 100644 index 8489d251f7064b8a05b3d677d451e3b5c65379ad..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/lwip_intf_v2_1/dhcpd/dhcp-bootp.h +++ /dev/null @@ -1,84 +0,0 @@ -#ifndef __DHCP_BOOTP_H_ -#define __DHCP_BOOTP_H_ - -#define DHCP_SERVER_PORT 67 -#define DHCP_CLIENT_PORT 68 - -#define NAMESERVER_PORT 53 - -#define CTRL_PORT 12679 - -#define BOOTP_OP_REQUEST 1 -#define BOOTP_OP_RESPONSE 2 - -#define BOOTP_OPTION_SUBNET_MASK 1 -#define BOOTP_OPTION_ROUTER 3 -#define BOOTP_OPTION_NAMESERVER 6 -#define BOOTP_OPTION_REQUESTED_IP 50 -#define BOOTP_OPTION_ADDRESS_TIME 51 -#define BOOTP_OPTION_DHCP_MESSAGE 53 -#define BOOTP_OPTION_DHCP_SERVER_ID 54 -#define BOOTP_END_OPTION 0xFF - -enum dhcp_message_type { - DHCP_MESSAGE_DISCOVER = 1, - DHCP_MESSAGE_OFFER = 2, - DHCP_MESSAGE_REQUEST = 3, - DHCP_MESSAGE_DECLINE = 4, - DHCP_MESSAGE_ACK = 5, - DHCP_MESSAGE_NAK = 6, - DHCP_MESSAGE_RELEASE = 7, - DHCP_MESSAGE_INFORM = 8, - DHCP_NO_RESPONSE = 255 -}; - -struct bootp_header { - uint8_t op; /* message type */ - uint8_t htype; /* hardware type (1 = ethernet) */ - uint8_t hlen; /* hardware address length (6) */ - uint8_t hops; /* (0) */ - uint32_t xid; /* transaction ID */ - uint16_t secs; /* seconds elapsed */ - uint16_t flags; /* bootp flags */ - uint32_t ciaddr; /* client IP address */ - uint32_t yiaddr; /* your IP address */ - uint32_t siaddr; /* next server IP address */ - uint32_t riaddr; /* relay agent IP address */ - uint8_t chaddr[6]; /* client MAC address */ - uint8_t pad[10 + 192]; /* 10 octets of padding, 192 octets of - padding */ - uint32_t cookie; /* magic cookie */ -} __attribute__((packed)); - -struct bootp_option { - uint8_t type; - uint8_t length; - char value[0]; -} __attribute__((packed)); -#define ETH_P_RARP 0x8035 - -#define ETH_HW_ADDR_LEN 6 -#define IP_ADDR_LEN 4 -#define ARP_FRAME_TYPE 0x0806 -#define ETHER_HW_TYPE 1 -#define IP_PROTO_TYPE 0x0800 -#define OP_ARP_REQUEST 2 -#define SOCK_PACKET 10 - -struct arp_packet { - uint8_t targ_hw_addr[ETH_HW_ADDR_LEN]; - uint8_t src_hw_addr[ETH_HW_ADDR_LEN]; - uint16_t frame_type; - uint16_t hw_type; - uint16_t prot_type; - uint8_t hw_addr_size; - uint8_t prot_addr_size; - uint16_t op; - uint8_t sndr_hw_addr[ETH_HW_ADDR_LEN]; - char sndr_ip_addr[IP_ADDR_LEN]; - uint8_t rcpt_hw_addr[ETH_HW_ADDR_LEN]; - char rcpt_ip_addr[IP_ADDR_LEN]; - uint8_t padding[18]; -}; - -#endif diff --git a/bk7235/liteos_m/bk_sdk_armino/components/lwip_intf_v2_1/dhcpd/dhcp-priv.h b/bk7235/liteos_m/bk_sdk_armino/components/lwip_intf_v2_1/dhcpd/dhcp-priv.h deleted file mode 100644 index e4aa034f16ed762c5ecfc87eafc7eadcccb1e704..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/lwip_intf_v2_1/dhcpd/dhcp-priv.h +++ /dev/null @@ -1,61 +0,0 @@ -#ifndef __DHCP_PRIV_H__ -#define __DHCP_PRIV_H__ - -#include "lwip/sockets.h" - -#if 0 -#define dhcp_e(...) \ - LWIP_LOGI("dhcp: %s\r\n", ##__VA_ARGS__) -#define dhcp_w(...) \ - LWIP_LOGI("dhcp: %s\r\n", ##__VA_ARGS__) - -#define dhcp_d(...) \ - LWIP_LOGI("dhcp: %s\r\n", ##__VA_ARGS__) -#else -#define dhcp_d(...) //LWIP_LOGI -#define dhcp_e(...) //LWIP_LOGI -#define dhcp_w(...) //LWIP_LOGI -#endif - -#define SERVER_BUFFER_SIZE 1024 -#define MAC_IP_CACHE_SIZE 8 - -#if CONFIG_MALLOC_STATIS -#define DHCP_SERVER_TASK_STACK_SIZE 2048 -#else -#define DHCP_SERVER_TASK_STACK_SIZE 1536 -#endif - -struct client_mac_cache { - uint8_t client_mac[6]; /* mac address of the connected device */ - uint32_t client_ip; /* ip address of the connected device */ -}; - -struct dhcp_server_data { - int sock; - int dnssock; - int ctrlsock; - int count_clients; /* to keep count of cached devices */ - char *msg; - struct sockaddr_in saddr; /* dhcp server address */ - struct sockaddr_in dnsaddr; /* dns server address */ - struct sockaddr_in uaddr; /* unicast address */ - struct sockaddr_in baddr; /* broadcast address */ - struct sockaddr_in ctrladdr; - struct client_mac_cache ip_mac_mapping[MAC_IP_CACHE_SIZE]; - uint32_t netmask; /* network order */ - uint32_t my_ip; /* network order */ - uint32_t client_ip; /* last address that was requested, network - * order */ - uint32_t current_ip; /* keep track of assigned IP addresses */ - uint32_t router_ip; /* router IP addresses */ - void *prv; -}; - -void dhcp_enable_nack_dns_server(void); -int dhcp_server_init(void *intrfc_handle); -void dhcp_server(void* data); -int dhcp_send_halt(void); -int dhcp_free_allocations(void); - -#endif diff --git a/bk7235/liteos_m/bk_sdk_armino/components/lwip_intf_v2_1/dhcpd/dhcp-server-main.c b/bk7235/liteos_m/bk_sdk_armino/components/lwip_intf_v2_1/dhcpd/dhcp-server-main.c deleted file mode 100644 index a12fe38990469d27f8f12ad5edbcd8cbb9c25445..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/lwip_intf_v2_1/dhcpd/dhcp-server-main.c +++ /dev/null @@ -1,56 +0,0 @@ -#include -#include -#include "dhcp-priv.h" - -static beken_thread_t dhcpd_thread; -static bool dhcpd_running; - -int dhcp_server_start(void *intrfc_handle) -{ - int ret; - - dhcp_d("DHCP server start request \r\n"); - - dhcp_enable_nack_dns_server(); - - if (dhcpd_running || dhcp_server_init(intrfc_handle)) { - return -1; - } - - ret = rtos_create_thread(&dhcpd_thread, - BEKEN_APPLICATION_PRIORITY, - "dhcp-server", - (beken_thread_function_t)dhcp_server, - DHCP_SERVER_TASK_STACK_SIZE, - 0); - if (ret) { - dhcp_free_allocations(); - return -1; - } - - dhcpd_running = 1; - return 0; -} - -void dhcp_server_stop(void) -{ - dhcp_d("DHCP server stop request\r\n"); - if (dhcpd_running) - { - if (dhcp_send_halt() != 0) - { - dhcp_w("failed to send halt to DHCP thread\r\n"); - return; - } - - if (rtos_delete_thread(&dhcpd_thread) != 0) - dhcp_w("failed to delete thread\r\n"); - dhcpd_running = 0; - } - else - { - dhcp_w("server not dhcpd_running.\r\n"); - } -} -// eof - diff --git a/bk7235/liteos_m/bk_sdk_armino/components/lwip_intf_v2_1/dhcpd/dhcp-server.c b/bk7235/liteos_m/bk_sdk_armino/components/lwip_intf_v2_1/dhcpd/dhcp-server.c deleted file mode 100755 index 2942d97e9812655bec7179194e9fc4e5533b1078..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/lwip_intf_v2_1/dhcpd/dhcp-server.c +++ /dev/null @@ -1,892 +0,0 @@ -#include -#include -#include "dhcp-bootp.h" -#include "dns.h" -#include "dhcp-priv.h" -#include -#include -#include "lwip/etharp.h" -#include "lwip/sockets.h" -#include "opt.h" - -#define os_mem_alloc os_malloc -#define os_mem_free os_free -#define SEND_RESPONSE(w,x,y,z) send_response(w,x,y,z) - -#define DEFAULT_DHCP_ADDRESS_TIMEOUT (60U*60U*1U) /* 1 hour */ -#define CLIENT_IP_NOT_FOUND 0x00000000 - -uint32_t dhcp_address_timeout = DEFAULT_DHCP_ADDRESS_TIMEOUT; -static beken_mutex_t dhcpd_mutex; -static int (*dhcp_nack_dns_server_handler)(char *msg, int len, - struct sockaddr_in *fromaddr); - -struct dhcp_server_data dhcps; - -extern int net_get_if_macaddr(void *macaddr, void *intrfc_handle); -extern int net_get_if_ip_addr(uint32_t *ip, void *intrfc_handle); -extern int net_get_if_ip_mask(uint32_t *nm, void *intrfc_handle); -extern int net_get_if_gw_addr(uint32_t *ip, void *intrfc_handle); -static void get_broadcast_addr(struct sockaddr_in *addr); -static int get_ip_addr_from_interface(uint32_t *ip, void *interface_handle); -static int get_netmask_from_interface(uint32_t *nm, void *interface_handle); -static int get_mac_addr_from_interface(void *mac, void *interface_handle); -static int get_gateway_from_interface(uint32_t *gw, void *interface_handle); -static int send_gratuitous_arp(uint32_t ip); -static bool ac_add(uint8_t *chaddr, uint32_t client_ip); -static uint32_t ac_lookup_mac(uint8_t *chaddr); -static uint8_t *ac_lookup_ip(uint32_t client_ip); -static bool ac_not_full(); - -static bool ac_add(uint8_t *chaddr, uint32_t client_ip) -{ - /* adds ip-mac mapping in cache */ - if (ac_not_full()) { - dhcps.ip_mac_mapping[dhcps.count_clients].client_mac[0] - = chaddr[0]; - dhcps.ip_mac_mapping[dhcps.count_clients].client_mac[1] - = chaddr[1]; - dhcps.ip_mac_mapping[dhcps.count_clients].client_mac[2] - = chaddr[2]; - dhcps.ip_mac_mapping[dhcps.count_clients].client_mac[3] - = chaddr[3]; - dhcps.ip_mac_mapping[dhcps.count_clients].client_mac[4] - = chaddr[4]; - dhcps.ip_mac_mapping[dhcps.count_clients].client_mac[5] - = chaddr[5]; - dhcps.ip_mac_mapping[dhcps.count_clients].client_ip = client_ip; - dhcps.count_clients++; - return 0; - } - return -1; -} - -static uint32_t ac_lookup_mac(uint8_t *chaddr) -{ - /* returns ip address, if mac address is present in cache */ - int i; - for (i = 0; i < dhcps.count_clients && i < MAC_IP_CACHE_SIZE; i++) { - if ((dhcps.ip_mac_mapping[i].client_mac[0] == chaddr[0]) && - (dhcps.ip_mac_mapping[i].client_mac[1] == chaddr[1]) && - (dhcps.ip_mac_mapping[i].client_mac[2] == chaddr[2]) && - (dhcps.ip_mac_mapping[i].client_mac[3] == chaddr[3]) && - (dhcps.ip_mac_mapping[i].client_mac[4] == chaddr[4]) && - (dhcps.ip_mac_mapping[i].client_mac[5] == chaddr[5])) { - return dhcps.ip_mac_mapping[i].client_ip; - } - } - return CLIENT_IP_NOT_FOUND; -} - -static uint8_t *ac_lookup_ip(uint32_t client_ip) -{ - /* returns mac address, if ip address is present in cache */ - int i; - for (i = 0; i < dhcps.count_clients && i < MAC_IP_CACHE_SIZE; i++) { - if ((dhcps.ip_mac_mapping[i].client_ip) == client_ip) { - return dhcps.ip_mac_mapping[i].client_mac; - } - } - return NULL; -} - -static bool ac_not_full() -{ - /* returns true if cache is not full */ - return (dhcps.count_clients < MAC_IP_CACHE_SIZE); -} - -static bool ac_valid_ip(uint32_t requested_ip) -{ - /* skip over our own address, the network address or the - * broadcast address - */ - if (requested_ip == ntohl(dhcps.my_ip) || - (requested_ip == ntohl(dhcps.my_ip & - dhcps.netmask)) || - (requested_ip == ntohl((dhcps.my_ip | - (0xffffffff & ~dhcps.netmask))))) { - return false; - } - if (ac_lookup_ip(htonl(requested_ip)) != NULL) - return false; - return true; -} - -static void write_u32(char *dest, uint32_t be_value) -{ - *dest++ = be_value & 0xFF; - *dest++ = (be_value >> 8) & 0xFF; - *dest++ = (be_value >> 16) & 0xFF; - *dest = be_value >> 24; -} - -/* Configure the DHCP dynamic IP lease time*/ -int dhcp_server_lease_timeout(uint32_t val) -{ - if ((val == 0) || (val > (60U*60U*24U*49700U))) { - return -EINVAL; - } else { - dhcp_address_timeout = val; - return 0; - } -} - -/* calculate the address to give out to the next DHCP DISCOVER request - * - * DHCP clients will be assigned addresses in sequence in the subnet's address space. - */ -static unsigned int next_yiaddr() -{ -#ifdef CONFIG_DHCP_SERVER_DEBUG - struct in_addr ip; -#endif - uint32_t new_ip; - struct bootp_header *hdr = (struct bootp_header *)dhcps.msg; - - /* if device requesting for ip address is already registered, - * if yes, assign previous ip address to it - */ - new_ip = ac_lookup_mac(hdr->chaddr); - if (new_ip == (CLIENT_IP_NOT_FOUND)) { - /* next IP address in the subnet */ - dhcps.current_ip = ntohl(dhcps.my_ip & dhcps.netmask) | - ((dhcps.current_ip + 1) & ntohl(~dhcps.netmask)); - while (!ac_valid_ip(dhcps.current_ip)) { - dhcps.current_ip = ntohl(dhcps.my_ip & dhcps.netmask) | - ((dhcps.current_ip + 1) & - ntohl(~dhcps.netmask)); - } - - new_ip = htonl(dhcps.current_ip); - - if (ac_add(hdr->chaddr, new_ip) != - 0) - dhcp_w("No space to store new mapping..\r\n"); - } - -#ifdef CONFIG_DHCP_SERVER_DEBUG - ip.s_addr = new_ip; - dhcp_d("New client IP will be %s\r\n", inet_ntoa(ip)); - ip.s_addr = dhcps.my_ip & dhcps.netmask; -#endif - - return new_ip; -} - -static unsigned int make_response(char *msg, enum dhcp_message_type type) -{ - struct bootp_header *hdr; - struct bootp_option *opt; - char *offset = msg; - - hdr = (struct bootp_header *)offset; - hdr->op = BOOTP_OP_RESPONSE; - hdr->htype = 1; - hdr->hlen = 6; - hdr->hops = 0; - hdr->ciaddr = 0; - hdr->yiaddr = (type == DHCP_MESSAGE_ACK) ? dhcps.client_ip : 0; - hdr->yiaddr = (type == DHCP_MESSAGE_OFFER) ? - next_yiaddr() : hdr->yiaddr; - hdr->siaddr = 0; - hdr->riaddr = 0; - offset += sizeof(struct bootp_header); - - opt = (struct bootp_option *)offset; - opt->type = BOOTP_OPTION_DHCP_MESSAGE; - *(uint8_t *) opt->value = type; - opt->length = 1; - offset += sizeof(struct bootp_option) + opt->length; - - if (type == DHCP_MESSAGE_NAK) - return (unsigned int)(offset - msg); - - opt = (struct bootp_option *)offset; - opt->type = BOOTP_OPTION_SUBNET_MASK; - write_u32(opt->value, dhcps.netmask); - opt->length = 4; - offset += sizeof(struct bootp_option) + opt->length; - - opt = (struct bootp_option *)offset; - opt->type = BOOTP_OPTION_ADDRESS_TIME; - write_u32(opt->value, htonl(dhcp_address_timeout)); - opt->length = 4; - offset += sizeof(struct bootp_option) + opt->length; - - opt = (struct bootp_option *)offset; - opt->type = BOOTP_OPTION_DHCP_SERVER_ID; - write_u32(opt->value, dhcps.my_ip); - opt->length = 4; - offset += sizeof(struct bootp_option) + opt->length; - - opt = (struct bootp_option *)offset; - opt->type = BOOTP_OPTION_ROUTER; - write_u32(opt->value, dhcps.router_ip); - opt->length = 4; - offset += sizeof(struct bootp_option) + opt->length; - - opt = (struct bootp_option *)offset; - opt->type = BOOTP_OPTION_NAMESERVER; - if (dhcp_nack_dns_server_handler) - write_u32(opt->value, dhcps.router_ip); - else - write_u32(opt->value, 0); - opt->length = 4; - offset += sizeof(struct bootp_option) + opt->length; - - opt = (struct bootp_option *)offset; - opt->type = BOOTP_END_OPTION; - offset++; - - return (unsigned int)(offset - msg); -} - -int dhcp_get_ip_from_mac(uint8_t *client_mac, uint32_t *client_ip) -{ - *client_ip = ac_lookup_mac(client_mac); - if (*client_ip == CLIENT_IP_NOT_FOUND) { - return -1; - } - return 0; -} - -extern void ap_set_default_netif(void); -extern void reset_default_netif(void); - -static int send_response(int sock, struct sockaddr *addr, char *msg, int len) -{ - int nb; - unsigned int sent = 0; - // // in AP+STA mode, should set ap-netif as default - int dest_ip = ((struct sockaddr_in *)addr)->sin_addr.s_addr; - if ((dest_ip == IPADDR_ANY) || (dest_ip == IPADDR_BROADCAST)) - ap_set_default_netif(); - - while (sent < len) { - nb = lwip_sendto(sock, msg + sent, len - sent, 0, addr, - sizeof(struct sockaddr_in)); - if (nb < 0) { - dhcp_e("failed to send response, addr %p:%d\r\n", - ((struct sockaddr_in *)addr)->sin_addr, - ((struct sockaddr_in *)addr)->sin_port); - return -1; - } - sent += nb; - } - - // rest default netif to sta's netif - //if((dest_ip == IPADDR_ANY) || (dest_ip == IPADDR_BROADCAST)) - //reset_default_netif(); - - dhcp_d("sent response, %d bytes %s\r\n", sent, - inet_ntoa(((struct sockaddr_in *)addr)->sin_addr)); - return 0; -} - -#define ERROR_REFUSED 5 -static int process_dns_message(char *msg, int len, struct sockaddr_in *fromaddr) -{ - struct dns_header *hdr; - char *endp = msg + len; - int nq; - - if (len < sizeof(struct dns_header)) { - dhcp_e("DNS request is not complete, hence ignoring it\r\n"); - return -1; - } - - hdr = (struct dns_header *)msg; - - dhcp_d("DNS transaction id: 0x%x\r\n", htons(hdr->id)); - - if (hdr->flags.fields.qr) { - dhcp_e("ignoring this dns message (not a query)\r\n"); - return -1; - } - - nq = ntohs(hdr->num_questions); - dhcp_d("we were asked %d questions\r\n", nq); - - if (nq <= 0) { - dhcp_e("ignoring this dns msg (not a query or 0 questions)\r\n"); - return -1; - } - - /* make the header represent a response */ - hdr->flags.fields.qr = 1; - hdr->flags.fields.opcode = 0; - /* Errors are never authoritative (unless they are - NXDOMAINS, which this is not) */ - hdr->flags.fields.aa = 0; - hdr->flags.fields.tc = 0; - hdr->flags.fields.rd = 1; - hdr->flags.fields.ra = 0; - hdr->flags.fields.rcode = ERROR_REFUSED; - hdr->flags.num = htons(hdr->flags.num); - /* number of entries in questions section */ - hdr->num_questions = htons(0x01); - hdr->answer_rrs = 0; /* number of resource records in answer section */ - hdr->authority_rrs = 0; - hdr->additional_rrs = 0; - SEND_RESPONSE(dhcps.dnssock, (struct sockaddr *)fromaddr, - msg, endp - msg); - - return -1; -} - -static int process_dhcp_message(char *msg, int len) -{ - struct bootp_header *hdr; - struct bootp_option *opt; - uint8_t response_type = DHCP_NO_RESPONSE; - unsigned int consumed = 0; - bool got_ip = 0; - bool need_ip = 0; - bool got_client_ip = 0; - uint32_t new_ip; - - if (!msg || - len < sizeof(struct bootp_header) + sizeof(struct bootp_option) + 1) - return -1; - - hdr = (struct bootp_header *)msg; - - switch (hdr->op) { - case BOOTP_OP_REQUEST: - dhcp_d("bootp request\r\n"); - break; - case BOOTP_OP_RESPONSE: - dhcp_d("bootp response\r\n"); - break; - default: - dhcp_e("invalid op code: %d\r\n", hdr->op); - return -1; - } - - if (hdr->htype != 1 || hdr->hlen != 6) { - dhcp_e("invalid htype or hlen\r\n"); - return -1; - } - - dhcp_d("client MAC: %02X:%02X:%02X:%02X:%02X:%02X\r\n", hdr->chaddr[0], - hdr->chaddr[1], hdr->chaddr[2], hdr->chaddr[3], hdr->chaddr[4], - hdr->chaddr[5]); - - dhcp_d("magic cookie: 0x%X\r\n", hdr->cookie); - - len -= sizeof(struct bootp_header); - opt = (struct bootp_option *)(msg + sizeof(struct bootp_header)); - while (len > 0 && opt->type != BOOTP_END_OPTION) { - if (opt->type == BOOTP_OPTION_DHCP_MESSAGE && opt->length == 1) { - dhcp_d("found DHCP message option\r\n"); - switch (*(uint8_t *) opt->value) { - case DHCP_MESSAGE_DISCOVER: - LWIP_LOGI("DHCP discover\r\n"); - response_type = DHCP_MESSAGE_OFFER; - break; - - case DHCP_MESSAGE_REQUEST: - LWIP_LOGI("DHCP request\r\n"); - need_ip = 1; - if (hdr->ciaddr != 0x0000000) { - dhcps.client_ip = hdr->ciaddr; - got_client_ip = 1; - } - break; - - default: - LWIP_LOGI("ignoring message type %d\r\n", - *(uint8_t *) opt->value); - break; - } - } - if (opt->type == BOOTP_OPTION_REQUESTED_IP && opt->length == 4) { - dhcp_d("found REQUESTED IP option %hhu.%hhu.%hhu.%hhu\r\n", - (uint8_t)opt->value[0], - (uint8_t)opt->value[1], - (uint8_t)opt->value[2], - (uint8_t)opt->value[3]); - memcpy((uint8_t *) &dhcps.client_ip, (uint8_t *) opt->value, 4); - got_client_ip = 1; - } - - if (got_client_ip) { - /* requested address outside of subnet */ - if ((dhcps.client_ip & dhcps.netmask) == - (dhcps.my_ip & dhcps.netmask)) { - - /* When client requests an IP address, - * DHCP-server checks if the valid - * IP-MAC entry is present in the - * ip-mac cache, if yes, also checks - * if the requested IP is same as the - * IP address present in IP-MAC entry, - * if yes, it allows the device to - * continue with the requested IP - * address. - */ - new_ip = ac_lookup_mac(hdr->chaddr); - if (new_ip != (CLIENT_IP_NOT_FOUND)) { - /* if new_ip is equal to requested ip */ - if (new_ip == dhcps.client_ip) { - got_ip = 1; - } else { - got_ip = 0; - } - } else if (ac_valid_ip - (ntohl(dhcps.client_ip))) { - /* When client requests with an IP - * address that is within subnet range - * and not assigned to any other client, - * then dhcp-server allows that device - * to continue with that IP address. - * And if IP-MAC cache is not full then - * adds this entry in cache. - */ - if (ac_not_full()) { - ac_add(hdr->chaddr, - dhcps.client_ip); - } else { - dhcp_w("No space to store new \r\n" - "mapping..\r\n"); - } - got_ip = 1; - } - } - } - - /* look at the next option (if any) */ - consumed = sizeof(struct bootp_option) + opt->length; - len -= consumed; - opt = (struct bootp_option *)((char *)opt + consumed); - if (need_ip) - response_type = got_ip ? DHCP_MESSAGE_ACK : - DHCP_MESSAGE_NAK; - } - - if (response_type != DHCP_NO_RESPONSE) { - uint32_t dst_ip = 0, retry = 0; - int send_byte; - struct bootp_header *hdr; - if (response_type == DHCP_MESSAGE_OFFER) - LWIP_LOGI("DHCP should send offer\r\n"); - else if (response_type == DHCP_MESSAGE_ACK) - LWIP_LOGI("DHCP should send ack\r\n"); - send_byte = make_response(msg, (enum dhcp_message_type)response_type); - hdr = (struct bootp_header *)msg; - - dst_ip = hdr->yiaddr; - - if(dst_ip != 0) { - dhcps.uaddr.sin_addr.s_addr = dst_ip; - - //dhcps.baddr.sin_addr.s_addr = dst_ip; - dhcp_d("change dhcps.uaddr: %s\r\n", inet_ntoa(dhcps.uaddr.sin_addr)); - - etharp_add_static_entry((ip4_addr_t *)&dst_ip, (struct eth_addr *)hdr->chaddr); - - retry = 0; - - dhcp_d("this pkt resp is unicast\r\n"); - hdr->flags &= ~(htons(1<<15)); - while(1) { - SEND_RESPONSE(dhcps.sock, - (struct sockaddr *)&dhcps.uaddr, msg, send_byte); - - if(++retry == 1) - break; - } - etharp_remove_static_entry((ip4_addr_t *)&dst_ip); - } - - dhcp_d("this pkt resp is broadcast\r\n"); - hdr->flags |= (htons(1<<15)); - retry = 0; - while(1) { - SEND_RESPONSE(dhcps.sock, - (struct sockaddr *)&dhcps.baddr, msg, send_byte); - - if(++retry == 3) - break; - } - - if (response_type == DHCP_MESSAGE_ACK) - send_gratuitous_arp(dhcps.my_ip); - return 0; - } - - dhcp_d("ignoring DHCP packet\r\n"); - return 0; -} - -static void dhcp_clean_sockets(void) -{ - int ret; - - if (dhcps.sock != -1) - { - ret = lwip_close(dhcps.sock); - if (ret != 0) { - dhcp_w("Failed to close dhcp socket\r\n"); - } - dhcps.sock = -1; - } - - if ( dhcp_nack_dns_server_handler ) - { - if ( dhcps.dnssock != -1 ) - { - ret = lwip_close(dhcps.dnssock); - if ( ret != 0 ) - { - dhcp_w("Failed to close dns socket\r\n"); - } - dhcps.dnssock = -1; - } - } - - if ( dhcps.ctrlsock != -1 ) - { - ret = lwip_close(dhcps.ctrlsock); - if ( ret != 0 ) - { - dhcp_w("Failed to close ctrol port socket\r\n"); - } - dhcps.ctrlsock = -1; - } -} - -void dhcp_server(void* data) -{ - int ret, len; - struct sockaddr_in caddr; - int max_sock; - socklen_t flen = sizeof(caddr); - fd_set rfds; - - rtos_lock_mutex(&dhcpd_mutex); - - while (1) { - FD_ZERO(&rfds); - FD_SET(dhcps.sock, &rfds); - max_sock = dhcps.sock; - - if (dhcp_nack_dns_server_handler) { - FD_SET(dhcps.dnssock, &rfds); - max_sock = (dhcps.sock > dhcps.dnssock ? - dhcps.sock : dhcps.dnssock); - } - - FD_SET(dhcps.ctrlsock, &rfds); - max_sock = (dhcps.sock > dhcps.ctrlsock ? - dhcps.sock : dhcps.ctrlsock); - - ret = lwip_select(max_sock + 1, &rfds, NULL, NULL, NULL); - - /* Error in select? */ - if (ret < 0) { - dhcp_e("select failed\r\n", -1); - goto done; - } - - if (FD_ISSET(dhcps.sock, &rfds)) { - len = lwip_recvfrom(dhcps.sock, dhcps.msg, - SERVER_BUFFER_SIZE, - 0, (struct sockaddr *)&caddr, &flen); - if (len > 0) { - dhcp_d("recved msg on dhcp sock len: %d\r\n", len); - process_dhcp_message(dhcps.msg, len); - } - } - - if ( dhcp_nack_dns_server_handler ) - { - if (FD_ISSET(dhcps.dnssock, &rfds)) { - len = lwip_recvfrom(dhcps.dnssock, dhcps.msg, - SERVER_BUFFER_SIZE, - 0, (struct sockaddr *)&caddr, &flen); - if (len > 0) { - dhcp_d("recved msg on dns sock len: %d\r\n", len); - dhcp_nack_dns_server_handler(dhcps.msg, len, - &caddr); - } - } - } - - if ( FD_ISSET(dhcps.ctrlsock, &rfds) ) - { - len = lwip_recvfrom(dhcps.ctrlsock, dhcps.msg, - SERVER_BUFFER_SIZE, - 0, (struct sockaddr *)&caddr, &flen); - if ( len > 0 ) - { - if ( os_strcmp(dhcps.msg, "HALT") == 0 ) - { - goto done; - } - } - } - } - -done: - dhcp_clean_sockets(); - rtos_unlock_mutex(&dhcpd_mutex); - rtos_delete_thread(NULL); -} - -static int create_and_bind_udp_socket(struct sockaddr_in *address, - void *intrfc_handle) -{ - int one = 1; - int ret; - - int sock = lwip_socket(PF_INET, SOCK_DGRAM, 0); - if (sock == -1) { - dhcp_e("failed to create a socket\r\n"); - return -1; - } - - ret = setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char *)&one, - sizeof(int)); - if (ret == -1) { - /* This is unimplemented in lwIP, hence do not return */ - dhcp_e("failed to set SO_REUSEADDR\r\n"); - } - - if (setsockopt(sock, SOL_SOCKET, SO_BROADCAST, - (char *)&one, sizeof(one)) == -1) { - dhcp_e("failed to set SO_BROADCAST\r\n"); - lwip_close(sock); - return -1; - } - - ret = lwip_bind(sock, (struct sockaddr *)address, - sizeof(struct sockaddr)); - - if (ret) { - dhcp_e("failed to bind server socket\r\n"); - dhcp_e("socket err: %d\r\n", errno); - lwip_close(sock); - return -1; - } - return sock; -} - -int dhcp_server_init(void *intrfc_handle) -{ - int ret = 0; - - memset(&dhcps, 0, sizeof(dhcps)); - dhcps.msg = (char*)os_mem_alloc(SERVER_BUFFER_SIZE); - if (dhcps.msg == NULL) - return -1; - ret = rtos_init_mutex(&dhcpd_mutex); - if (ret != 0) - return -1; - - get_broadcast_addr(&dhcps.baddr); - dhcps.baddr.sin_port = htons(DHCP_CLIENT_PORT); - - get_broadcast_addr(&dhcps.uaddr); - dhcps.uaddr.sin_port = htons(DHCP_CLIENT_PORT); - - if (get_ip_addr_from_interface(&dhcps.my_ip, intrfc_handle) < 0) { - dhcp_e("failed to look up our IP address from interface\r\n"); - ret = -1; - goto out; - } - - if (get_netmask_from_interface(&dhcps.netmask, intrfc_handle) < 0) { - dhcp_e("failed to look up our netmask from interface\r\n"); - ret = -1; - goto out; - } - - if (get_gateway_from_interface(&dhcps.router_ip, intrfc_handle) < 0) { - dhcp_e("failed to look up our netmask from interface\r\n"); - ret = -1; - goto out; - } - - - dhcps.saddr.sin_family = AF_INET; - dhcps.saddr.sin_addr.s_addr = INADDR_ANY; - dhcps.saddr.sin_port = htons(DHCP_SERVER_PORT); - dhcps.sock = create_and_bind_udp_socket(&dhcps.saddr, intrfc_handle); - - if (dhcps.sock < 0) { - ret = -1; - goto out; - } - - if (dhcp_nack_dns_server_handler) { - dhcps.dnsaddr.sin_family = AF_INET; - dhcps.dnsaddr.sin_addr.s_addr = INADDR_ANY; - dhcps.dnsaddr.sin_port = htons(NAMESERVER_PORT); - dhcps.dnssock = create_and_bind_udp_socket(&dhcps.dnsaddr, - intrfc_handle); - if (dhcps.dnssock < 0) - return -1; - } - - dhcps.ctrladdr.sin_family = AF_INET; - dhcps.ctrladdr.sin_addr.s_addr = inet_addr("127.0.0.1"); - dhcps.ctrladdr.sin_port = htons(CTRL_PORT); - dhcps.ctrlsock = create_and_bind_udp_socket(&dhcps.ctrladdr, - intrfc_handle); - if ( dhcps.ctrlsock < 0 ) - { - ret = -1; - goto out; - } - - dhcps.prv = intrfc_handle; - - dhcps.current_ip = ntohl(dhcps.my_ip & dhcps.netmask) | ((99) & ntohl(~dhcps.netmask)); - //LWIP_LOGI("[abc] %x, %x, %x\r\n", dhcps.current_ip, dhcps.my_ip, dhcps.router_ip); - - return 0; - -out: - os_mem_free(dhcps.msg); - dhcps.msg = NULL; - rtos_deinit_mutex(&dhcpd_mutex); - return ret; -} - -void dhcp_enable_nack_dns_server(void) -{ - dhcp_nack_dns_server_handler = process_dns_message; -} - -static int send_ctrl_msg(const char *msg) -{ - int ret; - - ret = lwip_sendto(dhcps.ctrlsock, msg, os_strlen(msg)+1, 0, - (struct sockaddr *)&dhcps.ctrladdr, sizeof(struct sockaddr_in)); - - return ret; -} - -int dhcp_send_halt(void) -{ - int ret; - - ret = send_ctrl_msg("HALT"); - if ( ret < 0 ) - { - dhcp_w("Failed to send HALT: %d.\r\n", ret); - return -1; - } - - ret = dhcp_free_allocations(); - - return ret; -} - -int dhcp_free_allocations(void) -{ - /* Wait for 10 seconds */ - rtos_lock_mutex(&dhcpd_mutex); - - dhcp_clean_sockets(); - - rtos_unlock_mutex(&dhcpd_mutex); - - if (dhcps.msg) { - os_mem_free(dhcps.msg); - dhcps.msg = NULL; - } - return rtos_deinit_mutex(&dhcpd_mutex); -} - -static int send_gratuitous_arp(uint32_t ip) -{ - int sock; - struct arp_packet pkt; - struct sockaddr_in to_addr; - to_addr.sin_family = AF_INET; - to_addr.sin_addr.s_addr = ip; - pkt.frame_type = htons(ARP_FRAME_TYPE); - pkt.hw_type = htons(ETHER_HW_TYPE); - pkt.prot_type = htons(IP_PROTO_TYPE); - pkt.hw_addr_size = ETH_HW_ADDR_LEN; - pkt.prot_addr_size = IP_ADDR_LEN; - pkt.op = htons(OP_ARP_REQUEST); - - write_u32(pkt.sndr_ip_addr, ip); - write_u32(pkt.rcpt_ip_addr, ip); - - memset(pkt.targ_hw_addr, 0xff, ETH_HW_ADDR_LEN); - memset(pkt.rcpt_hw_addr, 0xff, ETH_HW_ADDR_LEN); - get_mac_addr_from_interface((void*)pkt.sndr_hw_addr, dhcps.prv); - get_mac_addr_from_interface((void*)pkt.src_hw_addr, dhcps.prv); - - sock = lwip_socket(AF_INET, SOCK_DGRAM, 0); - if (sock < 0) { - dhcp_e("Could not open socket to send Gratuitous ARP\r\n"); - return -1; - } - memset(pkt.padding, 0, sizeof(pkt.padding)); - - if (lwip_sendto(sock, (char *)&pkt, sizeof(pkt), 0, - (struct sockaddr *)&to_addr, sizeof(to_addr)) < 0) { - dhcp_e("Failed to send Gratuitous ARP\r\n"); - lwip_close(sock); - return -1; - } - dhcp_d("Gratuitous ARP sent\r\n"); - lwip_close(sock); - return 0; -} - -static void get_broadcast_addr(struct sockaddr_in *addr) -{ - addr->sin_family = AF_INET; - /* limited broadcast addr (255.255.255.255) */ - addr->sin_addr.s_addr = 0xffffffff; - addr->sin_len = sizeof(struct sockaddr_in); -} - -static int get_mac_addr_from_interface(void *mac, void *interface_handle) -{ - return net_get_if_macaddr(mac, interface_handle); -} - -static int get_ip_addr_from_interface(uint32_t *ip, void *interface_handle) -{ - return net_get_if_ip_addr(ip, interface_handle); -} - -static int get_netmask_from_interface(uint32_t *nm, void *interface_handle) -{ - return net_get_if_ip_mask(nm, interface_handle); -} - -static int get_gateway_from_interface(uint32_t *gw, void *interface_handle) -{ - return net_get_if_gw_addr(gw, interface_handle); -} - -uint8_t* dhcp_lookup_mac(uint8_t *chaddr) -{ - /* returns ip address, if mac address is present in cache */ - int i; - struct in_addr ip; - for (i = 0; i < dhcps.count_clients && i < MAC_IP_CACHE_SIZE; i++) { - if ((dhcps.ip_mac_mapping[i].client_mac[0] == chaddr[0]) && - (dhcps.ip_mac_mapping[i].client_mac[1] == chaddr[1]) && - (dhcps.ip_mac_mapping[i].client_mac[2] == chaddr[2]) && - (dhcps.ip_mac_mapping[i].client_mac[3] == chaddr[3]) && - (dhcps.ip_mac_mapping[i].client_mac[4] == chaddr[4]) && - (dhcps.ip_mac_mapping[i].client_mac[5] == chaddr[5])) { - - ip.s_addr = dhcps.ip_mac_mapping[i].client_ip; - - return (uint8_t*)inet_ntoa(ip); - } - } - return 0; -} diff --git a/bk7235/liteos_m/bk_sdk_armino/components/lwip_intf_v2_1/dhcpd/dns.h b/bk7235/liteos_m/bk_sdk_armino/components/lwip_intf_v2_1/dhcpd/dns.h deleted file mode 100644 index f792991db3ab842e9a35fb09c62793fdca8bf7c5..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/lwip_intf_v2_1/dhcpd/dns.h +++ /dev/null @@ -1,45 +0,0 @@ -#ifndef __DNS_H__ -#define __DNS_H__ - -struct dns_header { - uint16_t id; - union { - struct { - uint16_t rcode:4, /* response code */ - cd:1, /* checking disabled RFC-2535 */ - ad:1, /* authentic data RFC-2535 */ - z:1, /* zero */ - ra:1, /* recursion available */ - rd:1, /* recursion desired */ - tc:1, /* truncated */ - aa:1, /* authoritative answer */ - opcode:4, /* (should be 0 for normal DNS messages) */ - qr:1; /* query/response */ - } fields ; - uint16_t num; - } flags ; - uint16_t num_questions; - uint16_t answer_rrs; - uint16_t authority_rrs; - uint16_t additional_rrs; -} __attribute__((packed)); - -struct dns_question { - /* query name (label) field */ - uint16_t type; - uint16_t class; -} __attribute__((packed)); - -struct dns_rr { - uint16_t name_ptr; /* pointer to name */ - uint16_t type; /* resource type */ - uint16_t class; /* resource class */ - uint32_t ttl; /* time to live */ - uint16_t rdlength; /* resource data length */ - uint32_t rd; /* resource data: we only provide a - 4-byte data response (an IP - address) but this is actually a - field of length rdlength */ -} __attribute__((packed)); - -#endif /* __DNS_H__ */ diff --git a/bk7235/liteos_m/bk_sdk_armino/components/lwip_intf_v2_1/lwip-2.1.2/BUILD.gn b/bk7235/liteos_m/bk_sdk_armino/components/lwip_intf_v2_1/lwip-2.1.2/BUILD.gn deleted file mode 100755 index 87e4cac90d630690779be1708fe88682aa2cc511..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/lwip_intf_v2_1/lwip-2.1.2/BUILD.gn +++ /dev/null @@ -1,44 +0,0 @@ -# Copyright (c) 2021-2021 Huawei Device Co., Ltd. All rights reserved. -# -# Redistribution and use in source and binary forms, with or without modification, -# are permitted provided that the following conditions are met: -# -# 1. Redistributions of source code must retain the above copyright notice, this list of -# conditions and the following disclaimer. -# -# 2. Redistributions in binary form must reproduce the above copyright notice, this list -# of conditions and the following disclaimer in the documentation and/or other materials -# provided with the distribution. -# -# 3. Neither the name of the copyright holder nor the names of its contributors may be used -# to endorse or promote products derived from this software without specific prior written -# permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, -# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR -# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; -# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR -# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF -# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -import("//kernel/liteos_m/liteos.gni") -import("$LITEOSTHIRDPARTY/lwip/lwip.gni") -import("$LITEOSTOPDIR/components/net/lwip-2.1/lwip_porting.gni") - -module_switch = defined(LOSCFG_NET_LWIP_SACK) -module_name = "lwip" -kernel_module(module_name) { - sources = LWIP_PORTING_FILES + LWIPNOAPPSFILES - [ "$LWIPDIR/api/sockets.c" ] - defines = [ "LITEOS_LWIP=1" ] - include_dirs = [ "//commonlibrary/utils_lite/include" ] -} - -config("public") { - defines = [ "_BSD_SOURCE=1" ] - include_dirs = [ "include" ] + LWIP_PORTING_INCLUDE_DIRS + LWIP_INCLUDE_DIRS -} diff --git a/bk7235/liteos_m/bk_sdk_armino/components/lwip_intf_v2_1/lwip-2.1.2/port/arch/cc.h b/bk7235/liteos_m/bk_sdk_armino/components/lwip_intf_v2_1/lwip-2.1.2/port/arch/cc.h deleted file mode 100644 index 5163604bcc0bbaf817a806b17585857e96e60ed1..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/lwip_intf_v2_1/lwip-2.1.2/port/arch/cc.h +++ /dev/null @@ -1,113 +0,0 @@ -/* - * cc.h - Architecture environment, some compiler specific, some - * environment specific (probably should move env stuff - * to sys_arch.h.) - * - * Typedefs for the types used by lwip - - * u8_t, s8_t, u16_t, s16_t, u32_t, s32_t, mem_ptr_t - * - * Compiler hints for packing lwip's structures - - * PACK_STRUCT_FIELD(x) - * PACK_STRUCT_STRUCT - * PACK_STRUCT_BEGIN - * PACK_STRUCT_END - * - * Platform specific diagnostic output - - * LWIP_PLATFORM_DIAG(x) - non-fatal, print a message. - * LWIP_PLATFORM_ASSERT(x) - fatal, print message and abandon execution. - * Portability defines for printf formatters: - * U16_F, S16_F, X16_F, U32_F, S32_F, X32_F, SZT_F - * - * "lightweight" synchronization mechanisms - - * SYS_ARCH_DECL_PROTECT(x) - declare a protection state variable. - * SYS_ARCH_PROTECT(x) - enter protection mode. - * SYS_ARCH_UNPROTECT(x) - leave protection mode. - * - * If the compiler does not provide memset() this file must include a - * definition of it, or include a file which defines it. - * - * This file must either include a system-local which defines - * the standard *nix error codes, or it should #define LWIP_PROVIDE_ERRNO - * to make lwip/arch.h define the codes which are used throughout. - */ - -#ifndef __CC_H__ -#define __CC_H__ - -#include -#include "bk_uart.h" - -#define LWIP_NO_STDINT_H 1 -/* - * Typedefs for the types used by lwip - - * u8_t, s8_t, u16_t, s16_t, u32_t, s32_t, mem_ptr_t - */ -#ifndef LWIP_SIMPLE_TYPES -#define LWIP_SIMPLE_TYPES 1 -typedef uint8_t u8_t; -typedef int8_t s8_t; -typedef uint16_t u16_t; -typedef int16_t s16_t; -typedef uint32_t u32_t; -typedef int32_t s32_t; -#endif - -typedef int intptr_t; -typedef unsigned int uintptr_t; -typedef int sys_prot_t; -typedef uintptr_t mem_ptr_t; - -#if defined(__GNUC__) - #define PACK_STRUCT_BEGIN - #define PACK_STRUCT_STRUCT __attribute__((packed)) - #define PACK_STRUCT_FIELD(x) x -#elif defined(__ICCARM__) - #define PACK_STRUCT_BEGIN __packed - #define PACK_STRUCT_STRUCT - #define PACK_STRUCT_FIELD(x) x -#else - #define PACK_STRUCT_BEGIN - #define PACK_STRUCT_STRUCT - #define PACK_STRUCT_FIELD(x) x -#endif - - -/* - * Platform specific diagnostic output - - * LWIP_PLATFORM_DIAG(x) - non-fatal, print a message. - * LWIP_PLATFORM_ASSERT(x) - fatal, print message and abandon execution. - * Portability defines for printf formatters: - * U16_F, S16_F, X16_F, U32_F, S32_F, X32_F, SZT_F - */ -#ifndef LWIP_PLATFORM_ASSERT -#define LWIP_PLATFORM_ASSERT(x) \ - do \ - { fatal_prf("Assertion \"%s\" failed at line %d in %s\n", x, __LINE__, __FILE__); \ - } while(0) -#endif - -#ifndef LWIP_PLATFORM_DIAG -#define LWIP_PLATFORM_DIAG(x) do {fatal_prf x ;} while(0) -#endif - -#define U16_F "4d" -#define S16_F "4d" -#define X16_F "4x" -#define U32_F "8ld" -#define S32_F "8ld" -#define X32_F "8lx" - -/* - * unknow defination - */ -// cup byte order -#ifndef BYTE_ORDER -#define BYTE_ORDER LITTLE_ENDIAN -#endif - -extern int bk_rand(); /* FIXME: move to right place */ -#define LWIP_TIMEVAL_PRIVATE 0 -#define LWIP_RAND() ((uint32_t)bk_rand()) -#endif -// eof - diff --git a/bk7235/liteos_m/bk_sdk_armino/components/lwip_intf_v2_1/lwip-2.1.2/port/arch/sys_arch.h b/bk7235/liteos_m/bk_sdk_armino/components/lwip_intf_v2_1/lwip-2.1.2/port/arch/sys_arch.h deleted file mode 100644 index 3e19f50c6df7552546d691ce11bdf5985f68b61b..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/lwip_intf_v2_1/lwip-2.1.2/port/arch/sys_arch.h +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (c) 2001-2003 Swedish Institute of Computer Science. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT - * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT - * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING - * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY - * OF SUCH DAMAGE. - * - * This file is part of the lwIP TCP/IP stack. - * - * Author: Adam Dunkels - * - */ -#ifndef __SYS_RTXC_H__ -#define __SYS_RTXC_H__ - -#include "sys_rtos.h" - -#define SYS_MBOX_NULL (beken_queue_t)0 -#define SYS_SEM_NULL (beken_semaphore_t)0 -#define SYS_DEFAULT_THREAD_STACK_DEPTH 256 - -typedef beken_mutex_t sys_mutex_t; -typedef beken_semaphore_t sys_sem_t; -typedef beken_queue_t sys_mbox_t; -typedef beken_thread_t sys_thread_t; - -typedef struct _sys_arch_state_t -{ - // Task creation data. - char cTaskName[16]; - unsigned short nStackDepth; - unsigned short nTaskCount; -} sys_arch_state_t; - -/* Message queue constants. */ -#define archMESG_QUEUE_LENGTH ( 32 ) -#endif /* __SYS_RTXC_H__ */ - diff --git a/bk7235/liteos_m/bk_sdk_armino/components/lwip_intf_v2_1/lwip-2.1.2/port/ethernetif.c b/bk7235/liteos_m/bk_sdk_armino/components/lwip_intf_v2_1/lwip-2.1.2/port/ethernetif.c deleted file mode 100644 index 87d8d6eead7ae81461654a6bb8a6b6542db93ca3..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/lwip_intf_v2_1/lwip-2.1.2/port/ethernetif.c +++ /dev/null @@ -1,363 +0,0 @@ -/** - * @file - * Ethernet Interface Skeleton - * - */ - -/* - * Copyright (c) 2001-2004 Swedish Institute of Computer Science. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT - * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT - * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING - * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY - * OF SUCH DAMAGE. - * - * This file is part of the lwIP TCP/IP stack. - * - * Author: Adam Dunkels - * - */ - -/* - * This file is a skeleton for developing Ethernet network interface - * drivers for lwIP. Add code to the low_level functions and do a - * search-and-replace for the word "ethernetif" to replace it with - * something that better describes your network interface. - */ - -#include "common/bk_include.h" - -#include "lwip/opt.h" -#include "lwip/def.h" -#include "lwip/mem.h" -#include "lwip/pbuf.h" -#include "lwip/sys.h" -#include -#include -#ifdef CONFIG_IPV6 -#include -#endif - -#include "ethernetif.h" - -#include -#include - -#include "netif/etharp.h" - -#include "lwip_netif_address.h" - -#include "bk_drv_model.h" -#include - -#include - -/* Define those to better describe your network interface. */ -#define IFNAME0 'e' -#define IFNAME1 'n' - -#include "bk_uart.h" -#include "bk_wifi_netif.h" -#include "bk_private/bk_wifi.h" - -//TODO should use registered callback here!!! -extern int ke_l2_packet_tx(unsigned char *buf, int len, int flag); -extern int bmsg_tx_sender(struct pbuf *p, uint32_t vif_idx); -#if CONFIG_WIFI6_CODE_STACK -extern int bmsg_special_tx_sender(struct pbuf *p, uint32_t vif_idx); -#endif -/* Forward declarations. */ -void ethernetif_input(int iface, struct pbuf *p); - -/** - * In this function, the hardware should be initialized. - * Called from ethernetif_init(). - * - * @param netif the already initialized lwip network interface structure - * for this ethernetif - */ - -const char wlan_name[][6] = -{ - "wlan0\0", - "wlan1\0", - "wlan2\0", - "wlan3\0", -}; -static void low_level_init(struct netif *netif) -{ - void *vif = netif->state; - u8 *macptr = wifi_netif_vif_to_mac(vif); - int vif_index = wifi_netif_vif_to_vifid(vif); - -#if LWIP_NETIF_HOSTNAME - /* Initialize interface hostname */ - netif->hostname = (char*)&wlan_name[vif_index]; -#endif /* LWIP_NETIF_HOSTNAME */ - - /* set MAC hardware address length */ - LWIP_LOGI("enter low level!\r\n"); - LWIP_LOGI("mac %2x:%2x:%2x:%2x:%2x:%2x\r\n", macptr[0], macptr[1], macptr[2], - macptr[3], macptr[4], macptr[5]); - - netif->hwaddr_len = ETHARP_HWADDR_LEN; - os_memcpy(netif->hwaddr, macptr, ETHARP_HWADDR_LEN); - /* maximum transfer unit */ - netif->mtu = 1500; - /* device capabilities */ - /* don't set NETIF_FLAG_ETHARP if this device is not an ethernet one */ - netif->flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_LINK_UP; - #ifdef LWIP_IGMP - netif->flags |= NETIF_FLAG_IGMP; - #endif - #if defined (LWIP_IPV6_MLD) && (LWIP_IPV6_MLD == 1) - netif->flags |= NETIF_FLAG_MLD6; - #endif - LWIP_LOGI("leave low level!\r\n"); -} - -/** - * This function should do the actual transmission of the packet. The packet is - * contained in the pbuf that is passed to the function. This pbuf - * might be chained. - * - * @param netif the lwip network interface structure for this ethernetif - * @param p the MAC packet to send (e.g. IP packet including MAC addresses and type) - * @return ERR_OK if the packet could be sent - * an err_t value if the packet couldn't be sent - * - * @note Returning ERR_MEM here if a DMA queue of your MAC is full can lead to - * strange results. You might consider waiting for space in the DMA queue - * to become availale since the stack doesn't retry to send a packet - * dropped because of memory failure (except for the TCP timers). - */ -static err_t low_level_output(struct netif *netif, struct pbuf *p) -{ - int ret; - err_t err = ERR_OK; - uint8_t vif_idx = wifi_netif_vif_to_vifid(netif->state); -#if !CONFIG_HARMONY_LWIP -#if CONFIG_WIFI6_CODE_STACK - //LWIP_LOGI("output:%x\r\n", p); - extern bool special_arp_flag; - if(special_arp_flag) - { - ret = bmsg_special_tx_sender(p, (uint32_t)vif_idx); - special_arp_flag = false; - } - else -#endif -#endif - { - ret = bmsg_tx_sender(p, (uint32_t)vif_idx); - } - if(0 != ret) - { - err = ERR_TIMEOUT; - } - - return err; -} - -/** - * This function should be called when a packet is ready to be read - * from the interface. It uses the function low_level_input() that - * should handle the actual reception of bytes from the network - * interface. Then the type of the received packet is determined and - * the appropriate input function is called. - * - * @param netif the lwip network interface structure for this ethernetif - */ -void -ethernetif_input(int iface, struct pbuf *p) -{ - struct eth_hdr *ethhdr; - struct netif *netif; - void *vif; - - if (p->len <= SIZEOF_ETH_HDR) { - pbuf_free(p); - return; - } - - vif = wifi_netif_vifid_to_vif(iface); - netif = (struct netif *)wifi_netif_get_vif_private_data(vif); - if(!netif) { - //LWIP_LOGI("ethernetif_input no netif found %d\r\n", iface); - pbuf_free(p); - p = NULL; - return; - } - - /* points to packet payload, which starts with an Ethernet header */ - ethhdr = p->payload; - - if( (memcmp(netif->hwaddr,ethhdr->src.addr,NETIF_MAX_HWADDR_LEN)==0) && (htons(ethhdr->type) !=ETHTYPE_ARP) ) - { - LWIP_DEBUGF(ETHARP_DEBUG ,("ethernet_input frame is my send,drop it\r\n")); - pbuf_free(p); - return; - } - - switch (htons(ethhdr->type)) - { - /* IP or ARP packet? */ - case ETHTYPE_IP: - case ETHTYPE_ARP: -#ifdef CONFIG_IPV6 - case ETHTYPE_IPV6: - wlan_set_multicast_flag(); -#endif -#if PPPOE_SUPPORT - /* PPPoE packet? */ - case ETHTYPE_PPPOEDISC: - case ETHTYPE_PPPOE: -#endif /* PPPOE_SUPPORT */ - /* full packet send to tcpip_thread to process */ - if (netif->input(p, netif) != ERR_OK) // ethernet_input - { - LWIP_DEBUGF(NETIF_DEBUG, ("ethernetif_input: IP input error\r\n")); - pbuf_free(p); - p = NULL; - } - break; -#if CONFIG_HARMONY_LWIP - /* ETHTYPE_EAPOL */ - case 0x888EU: -#else - case ETHTYPE_EAPOL: -#endif - ke_l2_packet_tx(p->payload, p->len, iface); - pbuf_free(p); - p = NULL; - break; - - default: - pbuf_free(p); - p = NULL; - break; - } - -} - -/** - * Should be called at the beginning of the program to set up the - * network interface. It calls the function low_level_init() to do the - * actual setup of the hardware. - * - * This function should be passed as a parameter to netif_add(). - * - * @param netif the lwip network interface structure for this ethernetif - * @return ERR_OK if the loopif is initialized - * ERR_MEM if private data couldn't be allocated - * any other err_t on error - */ -err_t -ethernetif_init(struct netif *netif) -{ - LWIP_ASSERT("netif != NULL", (netif != NULL)); - - /* - * Initialize the snmp variables and counters inside the struct netif. - * The last argument should be replaced with your link speed, in units - * of bits per second. - */ - NETIF_INIT_SNMP(netif, snmp_ifType_ethernet_csmacd, 10000000); - - netif->name[0] = IFNAME0; - netif->name[1] = IFNAME1; - /* We directly use etharp_output() here to save a function call. - * You can instead declare your own function an call etharp_output() - * from it if you have to do some checks before sending (e.g. if link - * is available...) */ - netif->output = etharp_output; - netif->linkoutput = low_level_output; -#ifdef CONFIG_IPV6 - netif->output_ip6 = ethip6_output; -#endif - - /* initialize the hardware */ - low_level_init(netif); - - return ERR_OK; -} - -/** - * Should be called at the beginning of the program to set up the - * network interface. It calls the function low_level_init() to do the - * actual setup of the hardware. - * - * This function should be passed as a parameter to netifapi_netif_add(). - * - * @param netif the lwip network interface structure for this ethernetif - * @return ERR_OK if the loopif is initialized - * ERR_MEM if private data couldn't be allocated - * any other err_t on error - */ -err_t lwip_netif_init(struct netif *netif) -{ - LWIP_ASSERT("netif != NULL", (netif != NULL)); - - /* - * Initialize the snmp variables and counters inside the struct netif. - * The last argument should be replaced with your link speed, in units - * of bits per second. - */ - NETIF_INIT_SNMP(netif, snmp_ifType_ethernet_csmacd, 10000000); - - netif->name[0] = IFNAME0; - netif->name[1] = IFNAME1; - /* We directly use etharp_output() here to save a function call. - * You can instead declare your own function an call etharp_output() - * from it if you have to do some checks before sending (e.g. if link - * is available...) */ - netif->output = etharp_output; - netif->linkoutput = low_level_output; -#ifdef CONFIG_IPV6 - netif->output_ip6 = ethip6_output; -#endif - - /* initialize the hardware */ - low_level_init(netif); - return ERR_OK; -} - -err_t lwip_netif_uap_init(struct netif *netif) -{ - LWIP_ASSERT("netif != NULL", (netif != NULL)); - - //netif->state = NULL; - netif->name[0] = 'u'; - netif->name[1] = 'a'; - /* We directly use etharp_output() here to save a function call. - * You can instead declare your own function an call etharp_output() - * from it if you have to do some checks before sending (e.g. if link - * is available...) */ - netif->output = etharp_output; - netif->linkoutput = low_level_output; - - /* initialize the hardware */ - low_level_init(netif); - - return ERR_OK; -} - -// eof diff --git a/bk7235/liteos_m/bk_sdk_armino/components/lwip_intf_v2_1/lwip-2.1.2/port/ethernetif.h b/bk7235/liteos_m/bk_sdk_armino/components/lwip_intf_v2_1/lwip-2.1.2/port/ethernetif.h deleted file mode 100644 index 95e287b024b1276bfb117b65e9d4341fed7b9627..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/lwip_intf_v2_1/lwip-2.1.2/port/ethernetif.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef __ETHERNETIF_H__ -#define __ETHERNETIF_H__ - - -#include "lwip/err.h" -#include "lwip/netif.h" - - -void ethernetif_recv(struct netif *netif, int total_len); -err_t ethernetif_init(struct netif *netif); - - -#endif diff --git a/bk7235/liteos_m/bk_sdk_armino/components/lwip_intf_v2_1/lwip-2.1.2/port/lwip_hooks.c b/bk7235/liteos_m/bk_sdk_armino/components/lwip_intf_v2_1/lwip-2.1.2/port/lwip_hooks.c deleted file mode 100644 index 9c8cf4e671672032072a94e3d09e925c45e20c2f..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/lwip_intf_v2_1/lwip-2.1.2/port/lwip_hooks.c +++ /dev/null @@ -1,109 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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 -#include -#include "lwip/netif.h" -#include "lwip_hooks.h" - -extern struct netif *netif_list; - -bool ip4_netif_exist(const ip4_addr_t *dest, const ip4_addr_t *src) -{ - struct netif *netif = NULL; - - for (netif = netif_list; netif != NULL; netif = netif->next) { - /* is the netif up, does it have a link and a valid address? */ - if (netif_is_up(netif) && netif_is_link_up(netif) - && !ip4_addr_isany_val(*netif_ip4_addr(netif))) { - /* source netif and dest netif match? */ - if (ip4_addr_netcmp(src, netif_ip4_addr(netif), netif_ip4_netmask(netif)) - || ip4_addr_netcmp(dest, netif_ip4_addr(netif), netif_ip4_netmask(netif))) { - /* return false when both netif don't match */ - return true; - } - } - } - - return false; -} - -/** - * Source based IPv4 routing hook function. - * - * IP route algorithm: - * - * 1. Source IP based routing has highest priority - * 2. Then the destination IP based routing - * 3. Least priority is default netif - * - * - * Default netif in different scenario: - * - * | STA | AP | Default Netif | - * ----------------------------- - * | ON | OFF | STA | - * | ON | ON | STA | - * | OFF | ON | AP | - * - * - * Routing examples: - * - * | sta-ip | ap-ip | src-ip/netif | dst-ip | out netif | notes | - * --------------------------------------------------------------------------------------- - * | 192.168.0.5 | 10.10.10.1 | 10.10.10.1/ap | 10.10.10.2 | ap | src-ip-route | - * | 192.168.0.5 | 10.10.10.1 | 10.10.10.1/ap | 192.168.0.x | ap | src-ip-route | - * | 192.168.0.5 | 10.10.10.1 | 10.10.10.2/ap | 192.168.0.x | sta | dst-ip-route | - * | 192.168.0.5 | 10.10.10.1 | 10.10.10.2/ap | 192.168.1.x | sta | default netif| - * | 192.168.0.5 | 10.10.10.1 | 192.168.0.5/sta | 192.168.0.x | sta | src-ip-route | - * | 192.168.0.5 | 10.10.10.1 | 192.168.0.5/sta | 192.168.1.x | sta | src-ip-route | - * | 192.168.0.5 | 10.10.10.1 | 192.168.0.5/sta | 10.10.10.x | sta | src-ip-route | - * | unknown | 10.10.10.1 | unknown/sta | 10.10.10.x | ap | dst-ip-route | - * | unknown | 10.10.10.1 | unknown/sta | 10.10.9.x | sta | default netif| - * | 192.168.0.5 | 10.10.10.1 | 192.168.0.5/sta | 255.255.255.255 | sta | src-ip-route | - * | 192.168.0.5 | 10.10.10.1 | 10.10.10.1/ap | 255.255.255.255 | ap | src-ip-route | - * | unknown | 10.10.10.1 | unknown/sta | 255.255.255.255 | sta | default netif| - * - * - * General rules for STA/AP coexisting routing: - * - * 1. The IP of AP is always known, so if the AP netif want to send multicast/broadcast - * traffic, bind the AP's IP to the socket - * 2. Anytime if you want to send traffic that is different than the STA/IP's subnet via - * specific netif, bind the IP of the out netif to the socket - * 3. Avoid configuring the IP of AP's address to the same sub-net as STA's, suggest using - * the special local sub-net address scope. - */ -struct netif* ip4_route_src_hook(const ip4_addr_t *dest, const ip4_addr_t *src) -{ - struct netif *netif = NULL; - - /* destination IP is broadcast IP? */ - if ((src != NULL) && !ip4_addr_isany(src)) { - /* iterate through netifs */ - for (netif = netif_list; netif != NULL; netif = netif->next) { - /* is the netif up, does it have a link and a valid address? */ - if (netif_is_up(netif) && netif_is_link_up(netif) - && !ip4_addr_isany_val(*netif_ip4_addr(netif))) { - /* source IP matches? */ - if (ip4_addr_cmp(src, netif_ip4_addr(netif))) { - /* return netif on which to forward IP packet */ - return netif; - } - } - } - } - - return netif; -} diff --git a/bk7235/liteos_m/bk_sdk_armino/components/lwip_intf_v2_1/lwip-2.1.2/port/lwip_hooks.h b/bk7235/liteos_m/bk_sdk_armino/components/lwip_intf_v2_1/lwip-2.1.2/port/lwip_hooks.h deleted file mode 100644 index e6174ef5549f256f7c29d0685f8985e88fbf8609..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/lwip_intf_v2_1/lwip-2.1.2/port/lwip_hooks.h +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once -#include "lwip/ip_addr.h" -#include "lwip/arch.h" -#include "lwip/err.h" - -bool ip4_netif_exist(const ip4_addr_t *src, const ip4_addr_t *dest); -struct netif* ip4_route_src_hook(const ip4_addr_t *src,const ip4_addr_t *dest); diff --git a/bk7235/liteos_m/bk_sdk_armino/components/lwip_intf_v2_1/lwip-2.1.2/port/lwip_intf.h b/bk7235/liteos_m/bk_sdk_armino/components/lwip_intf_v2_1/lwip-2.1.2/port/lwip_intf.h deleted file mode 100644 index 803fbd4e601d3040d2395cdbe600d0ba9e15d173..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/lwip_intf_v2_1/lwip-2.1.2/port/lwip_intf.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef __LWIP_INTF_H__ -#define __LWIP_INTF_H__ - -#define LWIP_INTF_DEBUG -#ifdef LWIP_INTF_DEBUG -#define LWIP_INTF_PRT warning_prf -#define LWIP_INTF_WARN warning_prf -#define LWIP_INTF_FATAL fatal_prf -#else -#define LWIP_INTF_PRT null_prf -#define LWIP_INTF_WARN null_prf -#define LWIP_INTF_FATAL null_prf -#endif - -#endif -// eof - diff --git a/bk7235/liteos_m/bk_sdk_armino/components/lwip_intf_v2_1/lwip-2.1.2/port/lwip_netif_address.h b/bk7235/liteos_m/bk_sdk_armino/components/lwip_intf_v2_1/lwip-2.1.2/port/lwip_netif_address.h deleted file mode 100644 index 8d9767c601721d10ea72bd7fae3a6102688fd0a8..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/lwip_intf_v2_1/lwip-2.1.2/port/lwip_netif_address.h +++ /dev/null @@ -1,60 +0,0 @@ -#ifndef _MXCHIP_NETIF_ADDR_H_ -#define _MXCHIP_NETIF_ADDR_H_ -#include - -/** MLAN BSS type */ -typedef enum _wifi_interface_type -{ - WIFI_INTERFACE_TYPE_STA = 0, - WIFI_INTERFACE_TYPE_UAP = 1, - - WIFI_INTERFACE_TYPE_ANY = 0xff, -} wifi_interface_type; - -#define ADDR_TYPE_STATIC 1 -#define ADDR_TYPE_DHCP 0 - -/** This data structure represents an IPv4 address */ -struct ipv4_config { - /** DHCP_Disable DHCP_Client DHCP_Server */ - unsigned addr_type; - /** The system's IP address in network order. */ - unsigned address; - /** The system's default gateway in network order. */ - unsigned gw; - /** The system's subnet mask in network order. */ - unsigned netmask; - /** The system's primary dns server in network order. */ - unsigned dns1; - /** The system's secondary dns server in network order. */ - unsigned dns2; -}; - - -#ifdef CONFIG_IPV6 -#define MAX_IPV6_ADDRESSES 3 -struct ipv6_config { - ip6_addr_t address; - u8 addr_state; -}; - -#endif - - -/** Network IP configuration. - * - * This data structure represents the network IP configuration - * for IPv4 as well as IPv6 addresses - */ -struct wlan_ip_config { -#ifdef CONFIG_IPV6 - /** The network IPv6 address configuration that should be - * associated with this interface. */ - struct ipv6_config ipv6[MAX_IPV6_ADDRESSES]; -#endif - /** The network IPv4 address configuration that should be - * associated with this interface. */ - struct ipv4_config ipv4; -}; - -#endif diff --git a/bk7235/liteos_m/bk_sdk_armino/components/lwip_intf_v2_1/lwip-2.1.2/port/lwipopts.h b/bk7235/liteos_m/bk_sdk_armino/components/lwip_intf_v2_1/lwip-2.1.2/port/lwipopts.h deleted file mode 100755 index cc140728f3882fa729cc140b37917a8eff21c2c0..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/lwip_intf_v2_1/lwip-2.1.2/port/lwipopts.h +++ /dev/null @@ -1,526 +0,0 @@ -/* - * Copyright (c) 2001-2003 Swedish Institute of Computer Science. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT - * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT - * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING - * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY - * OF SUCH DAMAGE. - * - * This file is part of the lwIP TCP/IP stack. - * - * Author: Adam Dunkels - * - */ -#ifndef __LWIPOPTS_H__ -#define __LWIPOPTS_H__ - -#include -#include - - - -/** - * Loopback demo related options. - */ -#define LWIP_NETIF_LOOPBACK 1 -#define LWIP_HAVE_LOOPIF 1 -#define LWIP_NETIF_LOOPBACK_MULTITHREADING 1 -#define LWIP_LOOPBACK_MAX_PBUFS 8 - -#define TCPIP_THREAD_NAME "tcp/ip" -#ifdef CONFIG_KEYVALUE -#define TCPIP_THREAD_STACKSIZE 1024 -#else -#define TCPIP_THREAD_STACKSIZE 512 -#endif - -#if CONFIG_LITEOS_M -#define TCPIP_THREAD_PRIO 7 -#else -#define TCPIP_THREAD_PRIO 2 -#endif - -#define DEFAULT_THREAD_STACKSIZE 200 -#if CONFIG_LITEOS_M -#define DEFAULT_THREAD_PRIO 1 -#else -#define DEFAULT_THREAD_PRIO 8 -#endif - -/* Disable lwIP asserts */ -#define LWIP_NOASSERT 1 - -#define LWIP_DEBUG 0 -#define LWIP_DEBUG_TRACE 0 -#define SOCKETS_DEBUG LWIP_DBG_OFF -#define IP_DEBUG LWIP_DBG_OFF -#define ETHARP_DEBUG LWIP_DBG_OFF -#define NETIF_DEBUG LWIP_DBG_OFF -#define PBUF_DEBUG LWIP_DBG_OFF -#define MEMP_DEBUG LWIP_DBG_OFF -#define API_LIB_DEBUG LWIP_DBG_OFF -#define API_MSG_DEBUG LWIP_DBG_OFF -#define ICMP_DEBUG LWIP_DBG_OFF -#define IGMP_DEBUG LWIP_DBG_OFF -#define INET_DEBUG LWIP_DBG_OFF -#define IP_REASS_DEBUG LWIP_DBG_OFF -#define RAW_DEBUG LWIP_DBG_OFF -#define MEM_DEBUG LWIP_DBG_OFF -#define SYS_DEBUG LWIP_DBG_OFF -#define TCP_DEBUG LWIP_DBG_OFF -#define TCP_INPUT_DEBUG LWIP_DBG_OFF -#define TCP_FR_DEBUG LWIP_DBG_OFF -#define TCP_RTO_DEBUG LWIP_DBG_OFF -#define TCP_CWND_DEBUG LWIP_DBG_OFF -#define TCP_WND_DEBUG LWIP_DBG_OFF -#define TCP_OUTPUT_DEBUG LWIP_DBG_OFF -#define TCP_RST_DEBUG LWIP_DBG_OFF -#define TCP_QLEN_DEBUG LWIP_DBG_OFF -#define UDP_DEBUG LWIP_DBG_OFF -#define TCPIP_DEBUG LWIP_DBG_OFF -#define PPP_DEBUG LWIP_DBG_OFF -#define SLIP_DEBUG LWIP_DBG_OFF -#define DHCP_DEBUG LWIP_DBG_OFF -#define AUTOIP_DEBUG LWIP_DBG_OFF -#define SNMP_MSG_DEBUG LWIP_DBG_OFF -#define SNMP_MIB_DEBUG LWIP_DBG_OFF -#define DNS_DEBUG LWIP_DBG_OFF -#define IP6_DEBUG LWIP_DBG_OFF -#define MDNS_DEBUG LWIP_DBG_OFF - -//#define LWIP_COMPAT_MUTEX 1 -/** - * SYS_LIGHTWEIGHT_PROT==1: if you want inter-task protection for certain - * critical regions during buffer allocation, deallocation and memory - * allocation and deallocation. - */ -#define SYS_LIGHTWEIGHT_PROT 1 - -/* - ------------------------------------ - ---------- Memory options ---------- - ------------------------------------ -*/ - -#define MEM_TRX_DYNAMIC_EN 0 - -/** - * MEM_ALIGNMENT: should be set to the alignment of the CPU - * 4 byte alignment -> #define MEM_ALIGNMENT 4 - * 2 byte alignment -> #define MEM_ALIGNMENT 2 - */ -#define MEM_ALIGNMENT 4 - -#define MAX_SOCKETS_TCP 8 -#define MAX_LISTENING_SOCKETS_TCP 4 -#define MAX_SOCKETS_UDP 8 -#define TCP_SND_BUF_COUNT 5 - -/* Value of TCP_SND_BUF_COUNT denotes the number of buffers and is set by - * CONFIG option available in the SDK - */ -/* Buffer size needed for TCP: Max. number of TCP sockets * Size of pbuf * - * Max. number of TCP sender buffers per socket - * - * Listening sockets for TCP servers do not require the same amount buffer - * space. Hence do not consider these sockets for memory computation - */ -#define TCP_MEM_SIZE (MAX_SOCKETS_TCP * \ - PBUF_POOL_BUFSIZE * (TCP_SND_BUF/TCP_MSS)) - -/* Buffer size needed for UDP: Max. number of UDP sockets * Size of pbuf - */ -#define UDP_MEM_SIZE (MAX_SOCKETS_UDP * PBUF_POOL_BUFSIZE) - -/** - * MEM_SIZE: the size of the heap memory. If the application will send - * a lot of data that needs to be copied, this should be set high. - */ -#if (MEM_TRX_DYNAMIC_EN) -#define MEM_SIZE (60*1024) -#define MEM_MAX_TX_SIZE (MEM_SIZE*5)/6 -#define MEM_MAX_RX_SIZE (MEM_SIZE*3)/4 -#else -#if (CONFIG_LWIP_MEM_REDUCE) -#define MEM_SIZE (32*1024) -#else -#define MEM_SIZE (48*1024) -#endif //CONFIG_LWIP_MEM_REDUCE -#endif //MEM_TRX_DYNAMIC_EN - - -/* - ------------------------------------------------ - ---------- Internal Memory Pool Sizes ---------- - ------------------------------------------------ -*/ -/** - * MEMP_NUM_PBUF: the number of memp struct pbufs (used for PBUF_ROM and PBUF_REF). - * If the application sends a lot of data out of ROM (or other static memory), - * this should be set high. - */ -#define MEMP_NUM_PBUF 10 - -/** - * MEMP_NUM_TCP_PCB: the number of simulatenously active TCP connections. - * (requires the LWIP_TCP option) - */ -#define MEMP_NUM_TCP_PCB MAX_SOCKETS_TCP - -#define MEMP_NUM_TCP_PCB_LISTEN MAX_LISTENING_SOCKETS_TCP - -/** - * MEMP_NUM_TCP_SEG: the number of simultaneously queued TCP segments. - * (requires the LWIP_TCP option) - */ -//#define MEMP_NUM_TCP_SEG 12 - -/** - * MEMP_NUM_TCPIP_MSG_INPKT: the number of struct tcpip_msg, which are used - * for incoming packets. - * (only needed if you use tcpip.c) - */ - -#define MEMP_NUM_TCPIP_MSG_INPKT 16 - -/** - * MEMP_NUM_SYS_TIMEOUT: the number of simulateously active timeouts. - * (requires NO_SYS==0) - */ -#define MEMP_NUM_SYS_TIMEOUT 12 - -/** - * MEMP_NUM_NETBUF: the number of struct netbufs. - * (only needed if you use the sequential API, like api_lib.c) - */ -#if (MEM_TRX_DYNAMIC_EN) -#define MEMP_NUM_NETBUF 32 -#else -#define MEMP_NUM_NETBUF 16 -#endif -/** - * MEMP_NUM_NETCONN: the number of struct netconns. - * (only needed if you use the sequential API, like api_lib.c) - * - * This number corresponds to the maximum number of active sockets at any - * given point in time. This number must be sum of max. TCP sockets, max. TCP - * sockets used for listening, and max. number of UDP sockets - */ -#define MEMP_NUM_NETCONN (MAX_SOCKETS_TCP + \ - MAX_LISTENING_SOCKETS_TCP + MAX_SOCKETS_UDP) - - - -/** - * PBUF_POOL_SIZE: the number of buffers in the pbuf pool. - */ -#if (MEM_TRX_DYNAMIC_EN) -#define PBUF_POOL_SIZE 3 -#else -#define PBUF_POOL_SIZE 20 -#endif - -/* - ---------------------------------- - ---------- Pbuf options ---------- - ---------------------------------- -*/ - -/** - * PBUF_POOL_BUFSIZE: the size of each pbuf in the pbuf pool. The default is - * designed to accomodate single full size TCP frame in one pbuf, including - * TCP_MSS, IP header, and link header. - */ -#if CONFIG_WIFI6_CODE_STACK -#define PBUF_LINK_ENCAPSULATION_HLEN CONFIG_MSDU_RESV_HEAD_LENGTH -#define PBUF_POOL_BUFSIZE (1580 + PBUF_LINK_ENCAPSULATION_HLEN) -#else -#define PBUF_POOL_BUFSIZE 1580 -#endif - - -/* - --------------------------------- - ---------- RAW options ---------- - --------------------------------- -*/ -/** - * LWIP_RAW==1: Enable application layer to hook into the IP layer itself. - */ -#define LWIP_RAW 1 -#ifdef CONFIG_IPV6 -#define LWIP_IPV6 1 -#endif - -/* Enable IPv4 Auto IP */ -#ifdef CONFIG_AUTOIP -#define LWIP_AUTOIP 1 -#define LWIP_DHCP_AUTOIP_COOP 1 -#define LWIP_DHCP_AUTOIP_COOP_TRIES 5 -#endif - - -/* Enable MDNS */ -#ifdef CONFIG_MDNS -#define LWIP_MDNS_RESPONDER 1 -#define LWIP_NUM_NETIF_CLIENT_DATA (LWIP_MDNS_RESPONDER) -#endif - - - - -/* - ------------------------------------ - ---------- Socket options ---------- - ------------------------------------ -*/ -/** - * LWIP_SOCKET==1: Enable Socket API (require to use sockets.c) - */ -#define LWIP_SOCKET 1 -#define LWIP_NETIF_API 1 - -/** - * LWIP_RECV_CB==1: Enable callback when a socket receives data. - */ -#define LWIP_RECV_CB 1 -/** - * SO_REUSE==1: Enable SO_REUSEADDR option. - */ -#define SO_REUSE 1 -#define SO_REUSE_RXTOALL 1 - -/** - * Enable TCP_KEEPALIVE - */ -#define LWIP_TCP_KEEPALIVE 1 - -/* - ---------------------------------------- - ---------- Statistics options ---------- - ---------------------------------------- -*/ -/** - * LWIP_STATS==1: Enable statistics collection in lwip_stats. - */ -#define LWIP_STATS 1 - -/** - * LWIP_STATS_DISPLAY==1: Compile in the statistics output functions. - */ -#define LWIP_STATS_DISPLAY 1 - -/* - ---------------------------------- - ---------- DHCP options ---------- - ---------------------------------- -*/ -/** - * LWIP_DHCP==1: Enable DHCP module. - */ -#define LWIP_DHCP 1 -#define LWIP_NETIF_STATUS_CALLBACK 1 - -/** - * DNS related options, revisit later to fine tune. - */ -#define LWIP_DNS 1 -#define DNS_TABLE_SIZE 2 // number of table entries, default 4 -//#define DNS_MAX_NAME_LENGTH 64 // max. name length, default 256 -#define DNS_MAX_SERVERS 2 // number of DNS servers, default 2 -#define DNS_DOES_NAME_CHECK 1 // compare received name with given,def 0 -#define DNS_MSG_SIZE 512 -#define MDNS_MSG_SIZE 512 -#define MDNS_TABLE_SIZE 1 // number of mDNS table entries -#define MDNS_MAX_SERVERS 1 // number of mDNS multicast addresses -/* TODO: Number of active UDP PCBs is equal to number of active UDP sockets plus - * two. Need to find the users of these 2 PCBs - */ -#define MEMP_NUM_UDP_PCB (MAX_SOCKETS_UDP + 2) -/* NOTE: some times the socket() call for SOCK_DGRAM might fail if you dont - * have enough MEMP_NUM_UDP_PCB */ - -/* - ---------------------------------- - ---------- IGMP options ---------- - ---------------------------------- -*/ -/** - * LWIP_IGMP==1: Turn on IGMP module. - */ -#define LWIP_IGMP 1 - -/** - * LWIP_SO_CONTIMEO==1: Enable send timeout for sockets/netconns and - * SO_CONTIMEO processing. - */ -#define LWIP_SO_CONTIMEO 1 - -/** - * LWIP_SO_SNDTIMEO==1: Enable send timeout for sockets/netconns and - * SO_SNDTIMEO processing. - */ -#define LWIP_SO_SNDTIMEO 1 - -/** - * LWIP_SO_RCVTIMEO==1: Enable receive timeout for sockets/netconns and - * SO_RCVTIMEO processing. - */ -#define LWIP_SO_RCVTIMEO 1 -#define LWIP_SO_SNDTIMEO 1 -/** - * TCP_LISTEN_BACKLOG==1: Handle backlog connections. - */ -#define TCP_LISTEN_BACKLOG 1 -#define LWIP_PROVIDE_ERRNO 1 - -#include -#define ERRNO 1 - -//#define LWIP_SNMP 1 - - -/* - ------------------------------------------------ - ---------- Network Interfaces options ---------- - ------------------------------------------------ -*/ -/** - * LWIP_NETIF_HOSTNAME==1: use DHCP_OPTION_HOSTNAME with netif's hostname - * field. - */ -#define LWIP_NETIF_HOSTNAME 1 - - -/* -The STM32F107 allows computing and verifying the IP, UDP, TCP and ICMP checksums by hardware: - - To use this feature let the following define uncommented. - - To disable it and process by CPU comment the the checksum. -*/ -//#define CHECKSUM_BY_HARDWARE - - -#ifdef CHECKSUM_BY_HARDWARE - /* CHECKSUM_GEN_IP==0: Generate checksums by hardware for outgoing IP packets.*/ - #define CHECKSUM_GEN_IP 0 - /* CHECKSUM_GEN_UDP==0: Generate checksums by hardware for outgoing UDP packets.*/ - #define CHECKSUM_GEN_UDP 0 - /* CHECKSUM_GEN_TCP==0: Generate checksums by hardware for outgoing TCP packets.*/ - #define CHECKSUM_GEN_TCP 0 - /* CHECKSUM_CHECK_IP==0: Check checksums by hardware for incoming IP packets.*/ - #define CHECKSUM_CHECK_IP 0 - /* CHECKSUM_CHECK_UDP==0: Check checksums by hardware for incoming UDP packets.*/ - #define CHECKSUM_CHECK_UDP 0 - /* CHECKSUM_CHECK_TCP==0: Check checksums by hardware for incoming TCP packets.*/ - #define CHECKSUM_CHECK_TCP 0 -#else - /* CHECKSUM_GEN_IP==1: Generate checksums in software for outgoing IP packets.*/ - #define CHECKSUM_GEN_IP 1 - /* CHECKSUM_GEN_UDP==1: Generate checksums in software for outgoing UDP packets.*/ - #define CHECKSUM_GEN_UDP 1 - /* CHECKSUM_GEN_TCP==1: Generate checksums in software for outgoing TCP packets.*/ - #define CHECKSUM_GEN_TCP 1 - /* CHECKSUM_CHECK_IP==1: Check checksums in software for incoming IP packets.*/ - #define CHECKSUM_CHECK_IP 1 - /* CHECKSUM_CHECK_UDP==1: Check checksums in software for incoming UDP packets.*/ - #define CHECKSUM_CHECK_UDP 1 - /* CHECKSUM_CHECK_TCP==1: Check checksums in software for incoming TCP packets.*/ - #define CHECKSUM_CHECK_TCP 1 -#endif - -/** - * TCP_RESOURCE_FAIL_RETRY_LIMIT: limit for retrying sending of tcp segment - * on resource failure error returned by driver. - */ -#define TCP_RESOURCE_FAIL_RETRY_LIMIT 50 - -//#ifdef CONFIG_ENABLE_MXCHIP -/* save memory */ -#if (CONFIG_LWIP_MEM_REDUCE) -#define TCP_MSS (1500 - 40) -/* TCP receive window. */ -#define TCP_WND (10 * TCP_MSS) -/* TCP sender buffer space (bytes). */ -#define TCP_SND_BUF (10*TCP_MSS) - -#define TCP_SND_QUEUELEN (20) -#else -#define TCP_MSS (1500 - 40) -/* TCP receive window. */ -#define TCP_WND (10*TCP_MSS) -/* TCP sender buffer space (bytes). */ -#define TCP_SND_BUF (10*TCP_MSS) - -#define TCP_SND_QUEUELEN (20) -#endif - -/* ARP before DHCP causes multi-second delay - turn it off */ -#define DHCP_DOES_ARP_CHECK (0) - -#define TCP_MAX_ACCEPT_CONN 5 -#define MEMP_NUM_TCP_SEG (TCP_SND_QUEUELEN*2) - -#define IP_REASS_MAX_PBUFS 0 -#define IP_REASSEMBLY 0 -#define IP_REASS_MAX_PBUFS 0 -#define IP_REASSEMBLY 0 -#define MEMP_NUM_REASSDATA 0 -#define IP_FRAG 0 - -#define MEM_LIBC_MALLOC (0) - -#if (CONFIG_LWIP_MEM_REDUCE) -#define DEFAULT_UDP_RECVMBOX_SIZE 16 //each udp socket max buffer 3 packets. -#else -#define DEFAULT_UDP_RECVMBOX_SIZE 16 //each udp socket max buffer 16 packets. -#endif - -#define MEMP_MEM_MALLOC (0) -#define TCP_MSL (TCP_TMR_INTERVAL) - -#define LWIP_COMPAT_MUTEX_ALLOWED (1) - -#define MEMP_STATS 1 -#define MEM_STATS 1 - -#define LWIP_DONT_PROVIDE_BYTEORDER_FUNCTIONS - -#define ETHARP_SUPPORT_STATIC_ENTRIES 1 - -#define LWIP_RIPPLE20 1 - -/* Beken specific LWIP options */ -#define BK_DHCP 1 - -#define LWIP_TAG "lwip" -#define LWIP_LOGI(...) BK_LOGI(LWIP_TAG, ##__VA_ARGS__) -#define LWIP_LOGW(...) BK_LOGW(LWIP_TAG, ##__VA_ARGS__) -#define LWIP_LOGE(...) BK_LOGE(LWIP_TAG, ##__VA_ARGS__) -#define LWIP_LOGD(...) BK_LOGD(LWIP_TAG, ##__VA_ARGS__) -#if 0 -#define LWIP_HOOK_FILENAME "lwip_hooks.h" -#define LWIP_HOOK_IP4_ROUTE_SRC ip4_route_src_hook -#endif -#define BK_IP4_ROUTE 1 -#define BK_DHCPS_DNS 1 - -#endif /* __LWIPOPTS_H__ */ - diff --git a/bk7235/liteos_m/bk_sdk_armino/components/lwip_intf_v2_1/lwip-2.1.2/port/net.c b/bk7235/liteos_m/bk_sdk_armino/components/lwip_intf_v2_1/lwip-2.1.2/port/net.c deleted file mode 100755 index 6ea7221cba10430120b729861a1fc6a4bfac324c..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/lwip_intf_v2_1/lwip-2.1.2/port/net.c +++ /dev/null @@ -1,826 +0,0 @@ -#include -#include -#include - -#include -#include "netif/etharp.h" -#include "lwip/netif.h" -#include -#include -#include -#include -#include "lwip/prot/dhcp.h" -#include "lwip/apps/mdns.h" - -#include -#include "ethernetif.h" - -#include -#include "bk_drv_model.h" -#include -#include "bk_wifi_netif.h" //TODO use standard EVENT instead!!! -#include "lwip_netif_address.h" -#include -#include "net.h" - -#include "wlan_defs_pub.h" -#include "bk_wifi.h" -#include -#include -#include "wlan_ui_pub.h" - -/* forward declaration */ -FUNC_1PARAM_PTR bk_wlan_get_status_cb(void); - -struct ipv4_config sta_ip_settings = { - .addr_type = ADDR_TYPE_DHCP, - .address = 0, - .gw = 0, - .netmask = 0, - .dns1 = 0, - .dns2 = 0, -}; - -struct ipv4_config uap_ip_settings = { - .addr_type = ADDR_TYPE_STATIC, - .address = 0xc0a80001, //192.168.0.1 - .gw = 0xc0a80001, //192.168.0.1 - .netmask = 0xffffff00, //255.255.255.0 - .dns1 = 0xc0a80001, //192.168.0.1 - .dns2 = 0, -}; -static char up_iface; -uint8 sta_ip_start_flag = 0; -uint8 uap_ip_start_flag = 0; - -#ifdef CONFIG_IPV6 -#define IPV6_ADDR_STATE_TENTATIVE "Tentative" -#define IPV6_ADDR_STATE_PREFERRED "Preferred" -#define IPV6_ADDR_STATE_INVALID "Invalid" -#define IPV6_ADDR_STATE_VALID "Valid" -#define IPV6_ADDR_STATE_DEPRECATED "Deprecated" -#define IPV6_ADDR_TYPE_LINKLOCAL "Link-Local" -#define IPV6_ADDR_TYPE_GLOBAL "Global" -#define IPV6_ADDR_TYPE_UNIQUELOCAL "Unique-Local" -#define IPV6_ADDR_TYPE_SITELOCAL "Site-Local" -#define IPV6_ADDR_UNKNOWN "Unknown" -#endif - -typedef void (*net_sta_ipup_cb_fn)(void* data); - -struct interface { - struct netif netif; - ip_addr_t ipaddr; - ip_addr_t nmask; - ip_addr_t gw; -}; -FUNCPTR sta_connected_func; - -static struct interface g_mlan = {{0}}; -static struct interface g_uap = {{0}}; -net_sta_ipup_cb_fn sta_ipup_cb = NULL; - -extern void *net_get_sta_handle(void); -extern void *net_get_uap_handle(void); -extern err_t lwip_netif_init(struct netif *netif); -extern err_t lwip_netif_uap_init(struct netif *netif); -extern int net_get_if_ip_addr(uint32_t *ip, void *intrfc_handle); -extern int net_get_if_ip_mask(uint32_t *nm, void *intrfc_handle); -extern int net_configure_address(struct ipv4_config *addr, void *intrfc_handle); -extern int dhcp_server_start(void *intrfc_handle); -extern void dhcp_server_stop(void); -extern void net_configure_dns(struct wlan_ip_config *ip); -extern bk_err_t bk_wifi_get_ip_status(IPStatusTypedef *outNetpara, WiFi_Interface inInterface); - - -#ifdef CONFIG_IPV6 -char *ipv6_addr_state_to_desc(unsigned char addr_state) -{ - if (ip6_addr_istentative(addr_state)) - return IPV6_ADDR_STATE_TENTATIVE; - else if (ip6_addr_ispreferred(addr_state)) - return IPV6_ADDR_STATE_PREFERRED; - else if (ip6_addr_isinvalid(addr_state)) - return IPV6_ADDR_STATE_INVALID; - else if (ip6_addr_isvalid(addr_state)) - return IPV6_ADDR_STATE_VALID; - else if (ip6_addr_isdeprecated(addr_state)) - return IPV6_ADDR_STATE_DEPRECATED; - else - return IPV6_ADDR_UNKNOWN; -} - -char *ipv6_addr_type_to_desc(struct ipv6_config *ipv6_conf) -{ - if (ip6_addr_islinklocal((ip6_addr_t *)&ipv6_conf->address)) - return IPV6_ADDR_TYPE_LINKLOCAL; - else if (ip6_addr_isglobal((ip6_addr_t *)&ipv6_conf->address)) - return IPV6_ADDR_TYPE_GLOBAL; - else if (ip6_addr_isuniquelocal((ip6_addr_t *)&ipv6_conf->address)) - return IPV6_ADDR_TYPE_UNIQUELOCAL; - else if (ip6_addr_issitelocal((ip6_addr_t *)&ipv6_conf->address)) - return IPV6_ADDR_TYPE_SITELOCAL; - else - return IPV6_ADDR_UNKNOWN; -} -#endif /* CONFIG_IPV6 */ - -int net_dhcp_hostname_set(char *hostname) -{ - netif_set_hostname(&g_mlan.netif, hostname); - return 0; -} - -void net_ipv4stack_init(void) -{ - static bool tcpip_init_done = 0; - if (tcpip_init_done) - return; - - LWIP_LOGI("init TCP/IP\r\n"); - tcpip_init(NULL, NULL); - tcpip_init_done = true; -} - -#ifdef CONFIG_IPV6 -void net_ipv6stack_init(struct netif *netif) -{ - bk_get_mac(netif->hwaddr, MAC_TYPE_STA); - netif->hwaddr_len = 6; -} -#endif /* CONFIG_IPV6 */ - -void net_wlan_init(void) -{ - static int wlan_init_done = 0; - int ret; - - if (!wlan_init_done) { - net_ipv4stack_init(); - ip_addr_set_ip4_u32(&g_mlan.ipaddr,INADDR_ANY); - ret = netifapi_netif_add(&g_mlan.netif,ip_2_ip4(&g_mlan.ipaddr), - ip_2_ip4(&g_mlan.ipaddr), ip_2_ip4(&g_mlan.ipaddr), NULL, - lwip_netif_init, tcpip_input); - if (ret) { - /*FIXME: Handle the error case cleanly */ - LWIP_LOGE("sta netif add failed"); - } -#ifdef CONFIG_IPV6 - net_ipv6stack_init(&g_mlan.netif); -#endif /* CONFIG_IPV6 */ - - ret = netifapi_netif_add(&g_uap.netif, ip_2_ip4(&g_uap.ipaddr), - ip_2_ip4(&g_uap.ipaddr), ip_2_ip4(&g_uap.ipaddr), NULL, - lwip_netif_uap_init, tcpip_input); - if (ret) { - /*FIXME: Handle the error case cleanly */ - LWIP_LOGE("ap netif add failed"); - } - wlan_init_done = 1; - } - - return; -} - -void net_set_sta_ipup_callback(void *fn) -{ - sta_ipup_cb = (net_sta_ipup_cb_fn)fn; -} - -void user_connected_callback(FUNCPTR fn) -{ - sta_connected_func = fn; -} - -static void wm_netif_status_static_callback(struct netif *n) -{ - if (n->flags & NETIF_FLAG_UP) { - // static IP success; - LWIP_LOGI("using static ip...\n"); - wifi_netif_notify_sta_got_ip(); -#if CONFIG_LWIP_FAST_DHCP - /* read stored IP from flash as the static IP */ - struct wlan_fast_connect_info fci = {0}; - wlan_read_fast_connect_info(&fci); - os_memcpy((char *)&n->ip_addr, (char *)&fci.ip_addr, sizeof(fci.ip_addr)); - os_memcpy((char *)&n->netmask, (char *)&fci.netmask, sizeof(fci.netmask)); - os_memcpy((char *)&n->gw, (char *)&fci.gw, sizeof(fci.gw)); - os_memcpy((char *)&n->dns1, (char *)&fci.dns1, sizeof(fci.dns1)); - LWIP_LOGI("ip_addr: "BK_IP4_FORMAT" \r\n", BK_IP4_STR(ip_addr_get_ip4_u32(&n->ip_addr))); -#endif - -#if !CONFIG_DISABLE_DEPRECIATED_WIFI_API - if (sta_ipup_cb != NULL) - sta_ipup_cb(NULL); - - if (sta_connected_func != NULL) - (*sta_connected_func)(); -#endif - } else { - // static IP fail; - } -} - -extern wifi_connect_tick_t sta_tick; -static void wm_netif_status_callback(struct netif *n) -{ - struct dhcp *dhcp; - - if (n->flags & NETIF_FLAG_UP) { - dhcp = netif_dhcp_data(n); -#ifdef CONFIG_IPV6 - int i; - u8 *ipv6_addr; - - { - for (i = 0; i < MAX_IPV6_ADDRESSES; i++) { - if (ip6_addr_isvalid(netif_ip6_addr_state(n, i))) { - ipv6_addr = (u8*)(ip_2_ip6(&n->ip6_addr[i]))->addr; - bk_printf("ipv6_addr[%d] : %02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x\r\n", i, - ipv6_addr[0], ipv6_addr[1], ipv6_addr[2], ipv6_addr[3], - ipv6_addr[4], ipv6_addr[5], ipv6_addr[6], ipv6_addr[7], - ipv6_addr[8], ipv6_addr[9], ipv6_addr[10], ipv6_addr[11], - ipv6_addr[12], ipv6_addr[13], ipv6_addr[14], ipv6_addr[15]); - bk_printf("ipv6_type[%d] :0x%x\r\n", i, n->ip6_addr[i].type); - bk_printf("ipv6_state[%d] :0x%x\r\n", i, n->ip6_addr_state[i]); - } - } - } -#endif - -#ifdef CONFIG_MDNS - if(!ip_addr_isany(&n->ip_addr)){ - mdns_resp_restart(n); - } -#endif - - if(dhcp != NULL) { - /* dhcp success*/ - if (dhcp->state == DHCP_STATE_BOUND) { - LWIP_LOGI("ip_addr: "BK_IP4_FORMAT" \r\n", BK_IP4_STR(ip_addr_get_ip4_u32(&n->ip_addr))); - sta_tick.sta_ip_tick = rtos_get_time(); - LWIP_LOGI("STA assoc delta:%d, eapol delta:%d, dhcp delta:%d, total:%d\n", - sta_tick.sta_assoc_tick - sta_tick.sta_start_tick, - sta_tick.sta_eapol_tick - sta_tick.sta_assoc_tick, - sta_tick.sta_ip_tick - sta_tick.sta_eapol_tick, - sta_tick.sta_ip_tick - sta_tick.sta_start_tick); -#if !CONFIG_DISABLE_DEPRECIATED_WIFI_API - wifi_netif_call_status_cb_when_sta_got_ip(); -#endif - wifi_netif_notify_sta_got_ip(); - -#if CONFIG_LWIP_FAST_DHCP - /* store current IP to flash */ - const ip_addr_t *dns_server; - dns_server = dns_getserver(0); - n->dns1 = ip_addr_get_ip4_u32(dns_server); - struct wlan_fast_connect_info fci = {0}; - wlan_read_fast_connect_info(&fci); - os_memset(&fci.ip_addr, 0, sizeof(ip_addr_t)*4); - os_memcpy((char *)&fci.ip_addr, (char *)&n->ip_addr, sizeof(n->ip_addr)); - os_memcpy((char *)&fci.netmask, (char *)&n->netmask, sizeof(n->netmask)); - os_memcpy((char *)&fci.gw, (char *)&n->gw, sizeof(n->gw)); - os_memcpy((char *)&fci.dns1, (char *)&n->dns1, sizeof(n->dns1)); - wlan_write_fast_connect_info(&fci); -#endif - -#if !CONFIG_DISABLE_DEPRECIATED_WIFI_API - if(sta_ipup_cb != NULL) - sta_ipup_cb(NULL); - - if(sta_connected_func != NULL) - (*sta_connected_func)(); -#endif - } else { - // dhcp fail -#if !CONFIG_DISABLE_DEPRECIATED_WIFI_API - wifi_netif_call_status_cb_when_sta_dhcp_timeout(); -#endif - } - } else { - // static IP success; - } - } else { - // dhcp fail; - } -} - -static int check_iface_mask(void *handle, uint32_t ipaddr) -{ - uint32_t interface_ip, interface_mask; - net_get_if_ip_addr(&interface_ip, handle); - net_get_if_ip_mask(&interface_mask, handle); - if (interface_ip > 0) - if ((interface_ip & interface_mask) == - (ipaddr & interface_mask)) - return 0; - return -1; -} - -void *net_ip_to_interface(uint32_t ipaddr) -{ - int ret; - void *handle; - /* Check mlan handle */ - handle = net_get_sta_handle(); - ret = check_iface_mask(handle, ipaddr); - if (ret == 0) - return handle; - - /* Check uap handle */ - handle = net_get_uap_handle(); - ret = check_iface_mask(handle, ipaddr); - if (ret == 0) - return handle; - - /* If more interfaces are added then above check needs to done for - * those newly added interfaces - */ - return NULL; -} - -void *net_sock_to_interface(int sock) -{ - struct sockaddr_in peer; - unsigned long peerlen = sizeof(struct sockaddr_in); - void *req_iface = NULL; - - getpeername(sock, (struct sockaddr *)&peer, &peerlen); - req_iface = net_ip_to_interface(peer.sin_addr.s_addr); - return req_iface; -} - -void *net_get_sta_handle(void) -{ - return &g_mlan.netif; -} - -void *net_get_uap_handle(void) -{ - return &g_uap.netif; -} - -void *net_get_netif_handle(uint8_t iface) -{ - - return NULL; -} - -void net_interface_up(void *intrfc_handle) -{ - struct interface *if_handle = (struct interface *)intrfc_handle; - netifapi_netif_set_up(&if_handle->netif); -} - -void net_interface_down(void *intrfc_handle) -{ - struct interface *if_handle = (struct interface *)intrfc_handle; - netifapi_netif_set_down(&if_handle->netif); -} - - -void net_interface_dhcp_stop(void *intrfc_handle) -{ - struct interface *if_handle = (struct interface *)intrfc_handle; - netifapi_dhcp_stop(&if_handle->netif); - netif_set_status_callback(&if_handle->netif, NULL); -} - -void sta_ip_down(void) -{ - if(sta_ip_start_flag) - { - LWIP_LOGI("sta ip down\r\n"); - - sta_ip_start_flag = 0; - - netifapi_netif_set_down(&g_mlan.netif); - netif_set_status_callback(&g_mlan.netif, NULL); - netifapi_dhcp_stop(&g_mlan.netif); -#if LWIP_IPV6 - for(u8_t addr_idx = 1; addr_idx < LWIP_IPV6_NUM_ADDRESSES; addr_idx++) { - netif_ip6_addr_set(&g_mlan.netif, addr_idx, (const ip6_addr_t *)IP6_ADDR_ANY); - g_mlan.netif.ip6_addr_state[addr_idx] = IP6_ADDR_INVALID; - } -#endif - } -} - -void sta_ip_start(void) -{ - struct wlan_ip_config address = {0}; - - if(!sta_ip_start_flag) { - LWIP_LOGI("sta ip start\r\n"); - sta_ip_start_flag = 1; - net_configure_address(&sta_ip_settings, net_get_sta_handle()); - return; - } - - LWIP_LOGI("sta ip start: "BK_IP4_FORMAT" \r\n", BK_IP4_STR(address.ipv4.address)); - net_get_if_addr(&address, net_get_sta_handle()); - if(wifi_netif_sta_is_connected() - && (0 != address.ipv4.address)) { - wifi_netif_notify_sta_got_ip(); - } -} - -void sta_set_default_netif(void) -{ - netifapi_netif_set_default(net_get_sta_handle()); -} - -void ap_set_default_netif(void) -{ - // as the default netif is sta's netif, so ap need to send - // boardcast or not sub net packets, need set ap netif before - // send those packets, after finish sending, reset default netif - // to sat's netif. - netifapi_netif_set_default(net_get_uap_handle()); -} - -void reset_default_netif(void) -{ - netifapi_netif_set_default(NULL); -} - -uint32_t sta_ip_is_start(void) -{ - return sta_ip_start_flag; -} - -void uap_ip_down(void) -{ - if (uap_ip_start_flag ) - { - LWIP_LOGI("uap ip down\r\n"); - uap_ip_start_flag = 0; - - netifapi_netif_set_down(&g_uap.netif); - netif_set_status_callback(&g_uap.netif, NULL); - dhcp_server_stop(); - } -} - -void uap_ip_start(void) -{ - if ( !uap_ip_start_flag ) - { - LWIP_LOGI("uap ip start\r\n"); - uap_ip_start_flag = 1; - net_configure_address(&uap_ip_settings, net_get_uap_handle()); - } -} - -uint32_t uap_ip_is_start(void) -{ - return uap_ip_start_flag; -} - -#define DEF_UAP_IP 0xc0a80a01UL /* 192.168.10.1 */ - -void ip_address_set(int iface, int dhcp, char *ip, char *mask, char*gw, char*dns) -{ - uint32_t tmp; - struct ipv4_config addr; - - memset(&addr, 0, sizeof(struct ipv4_config)); - if (dhcp == 1) { - addr.addr_type = ADDR_TYPE_DHCP; - } else { - addr.addr_type = ADDR_TYPE_STATIC; - tmp = inet_addr((char*)ip); - addr.address = (tmp); - tmp = inet_addr((char*)mask); - if (tmp == 0xFFFFFFFF) - tmp = 0x00FFFFFF;// if not set valid netmask, set as 255.255.255.0 - addr.netmask= (tmp); - tmp = inet_addr((char*)gw); - addr.gw = (tmp); - - tmp = inet_addr((char*)dns); - addr.dns1 = (tmp); - } - - if (iface == 1) // Station - memcpy(&sta_ip_settings, &addr, sizeof(addr)); - else - memcpy(&uap_ip_settings, &addr, sizeof(addr)); -} - -void sta_ip_mode_set(int dhcp) -{ - if (dhcp == 1) { - ip_address_set(1, DHCP_CLIENT, NULL, NULL, NULL, NULL); - } else { - IPStatusTypedef ipStatus; - bk_err_t ret = kNoErr; - os_memset(&ipStatus, 0x0, sizeof(IPStatusTypedef)); - ret = bk_wifi_get_ip_status(&ipStatus, BK_STATION); - if (ret == kNoErr) - ip_address_set(1, DHCP_DISABLE, ipStatus.ip, ipStatus.mask, ipStatus.gate, ipStatus.dns); - } -} - -#if CONFIG_LWIP_FAST_DHCP -void net_restart_dhcp(void) -{ - sta_ip_down(); - ip_address_set(BK_STATION, DHCP_CLIENT, NULL, NULL, NULL, NULL); - sta_ip_start(); -} -#endif - -int net_configure_address(struct ipv4_config *addr, void *intrfc_handle) -{ - if (!intrfc_handle) - return -1; - - struct interface *if_handle = (struct interface *)intrfc_handle; - - LWIP_LOGI("configuring interface %s (with %s)\n", - (if_handle == &g_mlan) ? "sta" :"ap", - (addr->addr_type == ADDR_TYPE_DHCP) - ? "DHCP client" : "Static IP"); - netifapi_netif_set_down(&if_handle->netif); - - /* De-register previously registered DHCP Callback for correct - * address configuration. - */ - netif_set_status_callback(&if_handle->netif, NULL); - - switch (addr->addr_type) { - case ADDR_TYPE_STATIC: - ip_addr_set_ip4_u32(&if_handle->ipaddr , addr->address); - ip_addr_set_ip4_u32(&if_handle->nmask,addr->netmask); - ip_addr_set_ip4_u32(&if_handle->gw ,addr->gw); - - netifapi_netif_set_addr(&if_handle->netif, ip_2_ip4(&if_handle->ipaddr), - ip_2_ip4(&if_handle->nmask), ip_2_ip4(&if_handle->gw)); - - //AP never configure DNS server address!!! - - if(if_handle == &g_mlan) - { - netif_set_status_callback(&if_handle->netif, - wm_netif_status_static_callback); - } - netifapi_netif_set_up(&if_handle->netif); - net_configure_dns((struct wlan_ip_config *)addr); - break; - - case ADDR_TYPE_DHCP: - /* Reset the address since we might be transitioning from static to DHCP */ - memset(&if_handle->ipaddr, 0, sizeof(ip_addr_t)); - memset(&if_handle->nmask, 0, sizeof(ip_addr_t)); - memset(&if_handle->gw, 0, sizeof(ip_addr_t)); - netifapi_netif_set_addr(&if_handle->netif, ip_2_ip4(&if_handle->ipaddr), - ip_2_ip4(&if_handle->nmask), ip_2_ip4(&if_handle->gw)); - - netif_set_status_callback(&if_handle->netif, - wm_netif_status_callback); - netifapi_netif_set_up(&if_handle->netif); - netifapi_dhcp_start(&if_handle->netif); - break; - - default: - break; - } - /* Finally this should send the following event. */ - if (if_handle == &g_mlan) { - // static IP up; - - /* XXX For DHCP, the above event will only indicate that the - * DHCP address obtaining process has started. Once the DHCP - * address has been obtained, another event, - * WD_EVENT_NET_DHCP_CONFIG, should be sent to the wlcmgr. - */ - up_iface = 1; - - // we always set sta netif as the default. - sta_set_default_netif(); - } else { - // softap IP up, start dhcp server; - dhcp_server_start(net_get_uap_handle()); - up_iface = 0; - } - - return 0; -} - -int net_get_if_addr(struct wlan_ip_config *addr, void *intrfc_handle) -{ - const ip_addr_t *tmp; - struct interface *if_handle = (struct interface *)intrfc_handle; - - if(netif_is_up(&if_handle->netif)) { - addr->ipv4.address = ip_addr_get_ip4_u32(&if_handle->netif.ip_addr); - addr->ipv4.netmask = ip_addr_get_ip4_u32(&if_handle->netif.netmask); - addr->ipv4.gw = ip_addr_get_ip4_u32(&if_handle->netif.gw); - - tmp = dns_getserver(0); - addr->ipv4.dns1 = ip_addr_get_ip4_u32(tmp); - tmp = dns_getserver(1); - addr->ipv4.dns2 = ip_addr_get_ip4_u32(tmp); - } - - return 0; -} - -int net_get_if_macaddr(void *macaddr, void *intrfc_handle) -{ - struct interface *if_handle = (struct interface *)intrfc_handle; - - os_memcpy(macaddr, &if_handle->netif.hwaddr[0], if_handle->netif.hwaddr_len); - - return 0; -} - -#ifdef CONFIG_IPV6 -int net_get_if_ipv6_addr(struct wlan_ip_config *addr, void *intrfc_handle) -{ - struct interface *if_handle = (struct interface *)intrfc_handle; - int i; - - for (i = 0; i < MAX_IPV6_ADDRESSES; i++) { - memcpy(&addr->ipv6[i].address, - ip_2_ip6(&(if_handle->netif.ip6_addr[i])), 16); - addr->ipv6[i].addr_state = if_handle->netif.ip6_addr_state[i]; - } - /* TODO carry out more processing based on IPv6 fields in netif */ - return 0; -} - -int net_get_if_ipv6_pref_addr(struct wlan_ip_config *addr, void *intrfc_handle) -{ - int i, ret = 0; - struct interface *if_handle = (struct interface *)intrfc_handle; - - for (i = 0; i < MAX_IPV6_ADDRESSES; i++) { - if (if_handle->netif.ip6_addr_state[i] == IP6_ADDR_PREFERRED) { - memcpy(&addr->ipv6[ret++].address, - &(if_handle->netif.ip6_addr[i]), 16); - } - } - return ret; -} -#endif /* CONFIG_IPV6 */ - -int net_get_if_ip_addr(uint32_t *ip, void *intrfc_handle) -{ - struct interface *if_handle = (struct interface *)intrfc_handle; - - *ip = ip_addr_get_ip4_u32(&if_handle->netif.ip_addr); - return 0; -} - -int net_get_if_gw_addr(uint32_t *ip, void *intrfc_handle) -{ - struct interface *if_handle = (struct interface *)intrfc_handle; - - *ip = ip_addr_get_ip4_u32(&if_handle->netif.gw); - - return 0; -} - -int net_get_if_ip_mask(uint32_t *nm, void *intrfc_handle) -{ - struct interface *if_handle = (struct interface *)intrfc_handle; - - *nm = ip_addr_get_ip4_u32(&if_handle->netif.netmask); - return 0; -} - -void net_configure_dns(struct wlan_ip_config *ip) -{ - ip_addr_t tmp; - - if (ip->ipv4.addr_type == ADDR_TYPE_STATIC) { - - if (ip->ipv4.dns1 == 0){ -#ifdef CONFIG_LWIP_FAST_DHCP - struct wlan_fast_connect_info fci = {0}; - wlan_read_fast_connect_info(&fci); - os_memcpy((char *)&ip->ipv4.dns1, (char *)&fci.dns1, sizeof(fci.dns1)); -#else - ip->ipv4.dns1 = ip->ipv4.gw; -#endif - } - if (ip->ipv4.dns2 == 0) - ip->ipv4.dns2 = ip->ipv4.dns1; - - ip_addr_set_ip4_u32(&tmp,ip->ipv4.dns1); - dns_setserver(0, &tmp); - ip_addr_set_ip4_u32(&tmp, ip->ipv4.dns2); - dns_setserver(1, &tmp); - } - - /* DNS MAX Retries should be configured in lwip/dns.c to 3/4 */ - /* DNS Cache size of about 4 is sufficient */ -} - -void net_wlan_initial(void) -{ - net_ipv4stack_init(); - -#ifdef CONFIG_IPV6 - net_ipv6stack_init(&g_mlan.netif); -#endif /* CONFIG_IPV6 */ -} - -int net_wlan_add_netif(uint8_t *mac) -{ - struct interface *wlan_if = NULL; - netif_if_t netif_if; - void *vif = NULL; - int vifid = 0; - err_t err; - - vifid = wifi_netif_mac_to_vifid(mac); - vif = wifi_netif_mac_to_vif(mac); - netif_if = wifi_netif_vif_to_netif_type(vif); - if (netif_if == NETIF_IF_AP) { - wlan_if = &g_uap; - } else if(netif_if == NETIF_IF_STA) { - wlan_if = &g_mlan; - } else { - LWIP_LOGE("unknown netif(%d)\n", netif_if); - return ERR_ARG; - } - - ip_addr_set_ip4_u32(&wlan_if->ipaddr, INADDR_ANY); - err = netifapi_netif_add(&wlan_if->netif, - ip_2_ip4(&wlan_if->ipaddr), - ip_2_ip4(&wlan_if->ipaddr), - ip_2_ip4(&wlan_if->ipaddr), - vif, - ethernetif_init, - tcpip_input); - if (err) { - LWIP_LOGE("net_wlan_add_netif failed(%d)\n", err); - return err; - } else { - wifi_netif_set_vif_private_data(vif, &wlan_if->netif); - #if CONFIG_IPV6 - if(netif_if == NETIF_IF_STA) { - netif_create_ip6_linklocal_address(&wlan_if->netif, 1); - netif_set_ip6_autoconfig_enabled(&wlan_if->netif, 1); - } - #endif - } - - LWIP_LOGI("add vif%d\n", vifid); - return ERR_OK; -} - -int net_wlan_remove_netif(uint8_t *mac) -{ - struct netif *netif = NULL; - void *vif; - err_t err; - int vifid; - - vifid = wifi_netif_mac_to_vifid(mac); - vif = wifi_netif_mac_to_vif(mac); - if(!vif) { - LWIP_LOGE("remove netif, vif%d not found\n", vifid); - return ERR_ARG; - } - - netif = (struct netif *)wifi_netif_get_vif_private_data(vif); - if(!netif) { - LWIP_LOGE("remove netif, netif is null\n"); - return ERR_ARG; - } - - err = netifapi_netif_remove(netif); - if(err != ERR_OK) { - LWIP_LOGE("remove netif, failed(%d)\n", err); - return err; - } else { - netif->state = NULL; - } - - LWIP_LOGI("remove vif%d\n", vifid); - return ERR_OK; -} -#if CONFIG_WIFI6_CODE_STACK -bool etharp_tmr_flag = false; -void net_begin_send_arp_reply(bool is_send_arp, bool is_allow_send_req) -{ -#if !CONFIG_HARMONY_LWIP - //send reply - if(is_send_arp && !is_allow_send_req) { - etharp_tmr_flag = true; - LWIP_LOGI("send reply %s\n", __func__); - } - //stop send reply - if(!is_send_arp && is_allow_send_req) { - etharp_tmr_flag = false; - LWIP_LOGI("stop send reply %s\n", __func__); - return; - } - etharp_reply(); -#endif -} -#endif diff --git a/bk7235/liteos_m/bk_sdk_armino/components/lwip_intf_v2_1/lwip-2.1.2/port/net.h b/bk7235/liteos_m/bk_sdk_armino/components/lwip_intf_v2_1/lwip-2.1.2/port/net.h deleted file mode 100644 index 890be19886df729e3363250b23f5aab663b6c799..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/lwip_intf_v2_1/lwip-2.1.2/port/net.h +++ /dev/null @@ -1,36 +0,0 @@ -#ifndef _NET_H_ -#define _NET_H_ -#ifdef __cplusplus -extern "C" { -#endif - -#include "lwip_netif_address.h" - -extern void uap_ip_down(void); -extern void uap_ip_start(void); -extern void sta_ip_down(void); -extern void sta_ip_start(void); -extern uint32_t uap_ip_is_start(void); -extern uint32_t sta_ip_is_start(void); -extern void *net_get_sta_handle(void); -extern void *net_get_uap_handle(void); -extern int net_wlan_remove_netif(uint8_t *mac); -extern int net_get_if_macaddr(void *macaddr, void *intrfc_handle); -extern int net_get_if_addr(struct wlan_ip_config *addr, void *intrfc_handle); -extern void ip_address_set(int iface, int dhcp, char *ip, char *mask, char*gw, char*dns); -extern void sta_ip_mode_set(int dhcp); -#if CONFIG_WIFI6_CODE_STACK -extern bool etharp_tmr_flag; -extern void net_begin_send_arp_reply(bool is_send_arp, bool is_allow_send_req); -#endif -#if CONFIG_LWIP_FAST_DHCP -extern void net_restart_dhcp(void); -#endif - -#ifdef __cplusplus -} -#endif - -#endif // _NET_H_ -// eof - diff --git a/bk7235/liteos_m/bk_sdk_armino/components/lwip_intf_v2_1/lwip-2.1.2/port/ping.h b/bk7235/liteos_m/bk_sdk_armino/components/lwip_intf_v2_1/lwip-2.1.2/port/ping.h deleted file mode 100755 index bf0bb5e0f2d8e8daa53e88c702ade1504c735f29..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/lwip_intf_v2_1/lwip-2.1.2/port/ping.h +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef LWIP_PING_H -#define LWIP_PING_H - -extern int ping(char* target_name, uint32_t times, size_t size); -void ping_stop(void); -void ping_start(char* target_name, uint32_t times, size_t size); - - -#endif /* LWIP_PING_H */ diff --git a/bk7235/liteos_m/bk_sdk_armino/components/lwip_intf_v2_1/lwip-2.1.2/port/sockets.c b/bk7235/liteos_m/bk_sdk_armino/components/lwip_intf_v2_1/lwip-2.1.2/port/sockets.c deleted file mode 100755 index 1bf498138808107e688eaf3f1c1b8bc64c7f1aa7..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/lwip_intf_v2_1/lwip-2.1.2/port/sockets.c +++ /dev/null @@ -1,4232 +0,0 @@ -/** - * @file - * Sockets BSD-Like API module - */ - -/* - * Copyright (c) 2001-2004 Swedish Institute of Computer Science. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT - * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT - * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING - * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY - * OF SUCH DAMAGE. - * - * This file is part of the lwIP TCP/IP stack. - * - * Author: Adam Dunkels - * - * Improved by Marc Boucher and David Haas - * - */ - -#include "lwip/opt.h" - -#if LWIP_SOCKET /* don't build if not configured for use in lwipopts.h */ -#if 1 -int errno=0; -#endif - -#include "lwip/sockets.h" -#include "lwip/priv/sockets_priv.h" -#include "lwip/api.h" -#include "lwip/igmp.h" -#include "lwip/inet.h" -#include "lwip/tcp.h" -#include "lwip/raw.h" -#include "lwip/udp.h" -#include "lwip/memp.h" -#include "lwip/pbuf.h" -#include "lwip/netif.h" -#include "lwip/priv/tcpip_priv.h" -#include "lwip/mld6.h" -#if LWIP_ENABLE_DISTRIBUTED_NET -#include "lwip/distributed_net/distributed_net.h" -#include "lwip/distributed_net/distributed_net_core.h" -#endif /* LWIP_ENABLE_DISTRIBUTED_NET */ -#if LWIP_CHECKSUM_ON_COPY -#include "lwip/inet_chksum.h" -#endif - -#if LWIP_COMPAT_SOCKETS == 2 && LWIP_POSIX_SOCKETS_IO_NAMES -#include -#endif - -#include - -#ifdef LWIP_HOOK_FILENAME -#include LWIP_HOOK_FILENAME -#endif - -/* If the netconn API is not required publicly, then we include the necessary - files here to get the implementation */ -#if !LWIP_NETCONN -#undef LWIP_NETCONN -#define LWIP_NETCONN 1 -#include "api_msg.c" -#include "api_lib.c" -#include "netbuf.c" -#undef LWIP_NETCONN -#define LWIP_NETCONN 0 -#endif - -#define API_SELECT_CB_VAR_REF(name) API_VAR_REF(name) -#define API_SELECT_CB_VAR_DECLARE(name) API_VAR_DECLARE(struct lwip_select_cb, name) -#define API_SELECT_CB_VAR_ALLOC(name, retblock) API_VAR_ALLOC_EXT(struct lwip_select_cb, MEMP_SELECT_CB, name, retblock) -#define API_SELECT_CB_VAR_FREE(name) API_VAR_FREE(MEMP_SELECT_CB, name) - -#if LWIP_IPV4 -#define IP4ADDR_PORT_TO_SOCKADDR(sin, ipaddr, port) do { \ - (sin)->sin_len = sizeof(struct sockaddr_in); \ - (sin)->sin_family = AF_INET; \ - (sin)->sin_port = lwip_htons((port)); \ - inet_addr_from_ip4addr(&(sin)->sin_addr, ipaddr); \ - memset((sin)->sin_zero, 0, SIN_ZERO_LEN); }while(0) -#define SOCKADDR4_TO_IP4ADDR_PORT(sin, ipaddr, port) do { \ - inet_addr_to_ip4addr(ip_2_ip4(ipaddr), &((sin)->sin_addr)); \ - (port) = lwip_ntohs((sin)->sin_port); }while(0) -#endif /* LWIP_IPV4 */ - -#if LWIP_IPV6 -#define IP6ADDR_PORT_TO_SOCKADDR(sin6, ipaddr, port) do { \ - (sin6)->sin6_len = sizeof(struct sockaddr_in6); \ - (sin6)->sin6_family = AF_INET6; \ - (sin6)->sin6_port = lwip_htons((port)); \ - (sin6)->sin6_flowinfo = 0; \ - inet6_addr_from_ip6addr(&(sin6)->sin6_addr, ipaddr); \ - (sin6)->sin6_scope_id = ip6_addr_zone(ipaddr); }while(0) -#define SOCKADDR6_TO_IP6ADDR_PORT(sin6, ipaddr, port) do { \ - inet6_addr_to_ip6addr(ip_2_ip6(ipaddr), &((sin6)->sin6_addr)); \ - if (ip6_addr_has_scope(ip_2_ip6(ipaddr), IP6_UNKNOWN)) { \ - ip6_addr_set_zone(ip_2_ip6(ipaddr), (u8_t)((sin6)->sin6_scope_id)); \ - } \ - (port) = lwip_ntohs((sin6)->sin6_port); }while(0) -#endif /* LWIP_IPV6 */ - -#if LWIP_IPV4 && LWIP_IPV6 -static void sockaddr_to_ipaddr_port(const struct sockaddr *sockaddr, ip_addr_t *ipaddr, u16_t *port); - -#define IS_SOCK_ADDR_LEN_VALID(namelen) (((namelen) == sizeof(struct sockaddr_in)) || \ - ((namelen) == sizeof(struct sockaddr_in6))) -#define IS_SOCK_ADDR_TYPE_VALID(name) (((name)->sa_family == AF_INET) || \ - ((name)->sa_family == AF_INET6)) -#define SOCK_ADDR_TYPE_MATCH(name, sock) \ - ((((name)->sa_family == AF_INET) && !(NETCONNTYPE_ISIPV6((sock)->conn->type))) || \ - (((name)->sa_family == AF_INET6) && (NETCONNTYPE_ISIPV6((sock)->conn->type)))) -#define IPADDR_PORT_TO_SOCKADDR(sockaddr, ipaddr, port) do { \ - if (IP_IS_ANY_TYPE_VAL(*ipaddr) || IP_IS_V6_VAL(*ipaddr)) { \ - IP6ADDR_PORT_TO_SOCKADDR((struct sockaddr_in6*)(void*)(sockaddr), ip_2_ip6(ipaddr), port); \ - } else { \ - IP4ADDR_PORT_TO_SOCKADDR((struct sockaddr_in*)(void*)(sockaddr), ip_2_ip4(ipaddr), port); \ - } } while(0) -#define SOCKADDR_TO_IPADDR_PORT(sockaddr, ipaddr, port) sockaddr_to_ipaddr_port(sockaddr, ipaddr, &(port)) -#define DOMAIN_TO_NETCONN_TYPE(domain, type) (((domain) == AF_INET) ? \ - (type) : (enum netconn_type)((type) | NETCONN_TYPE_IPV6)) -#elif LWIP_IPV6 /* LWIP_IPV4 && LWIP_IPV6 */ -#define IS_SOCK_ADDR_LEN_VALID(namelen) ((namelen) == sizeof(struct sockaddr_in6)) -#define IS_SOCK_ADDR_TYPE_VALID(name) ((name)->sa_family == AF_INET6) -#define SOCK_ADDR_TYPE_MATCH(name, sock) 1 -#define IPADDR_PORT_TO_SOCKADDR(sockaddr, ipaddr, port) \ - IP6ADDR_PORT_TO_SOCKADDR((struct sockaddr_in6*)(void*)(sockaddr), ip_2_ip6(ipaddr), port) -#define SOCKADDR_TO_IPADDR_PORT(sockaddr, ipaddr, port) \ - SOCKADDR6_TO_IP6ADDR_PORT((const struct sockaddr_in6*)(const void*)(sockaddr), ipaddr, port) -#define DOMAIN_TO_NETCONN_TYPE(domain, netconn_type) (netconn_type) -#else /*-> LWIP_IPV4: LWIP_IPV4 && LWIP_IPV6 */ -#define IS_SOCK_ADDR_LEN_VALID(namelen) ((namelen) == sizeof(struct sockaddr_in)) -#define IS_SOCK_ADDR_TYPE_VALID(name) ((name)->sa_family == AF_INET) -#define SOCK_ADDR_TYPE_MATCH(name, sock) 1 -#define IPADDR_PORT_TO_SOCKADDR(sockaddr, ipaddr, port) \ - IP4ADDR_PORT_TO_SOCKADDR((struct sockaddr_in*)(void*)(sockaddr), ip_2_ip4(ipaddr), port) -#define SOCKADDR_TO_IPADDR_PORT(sockaddr, ipaddr, port) \ - SOCKADDR4_TO_IP4ADDR_PORT((const struct sockaddr_in*)(const void*)(sockaddr), ipaddr, port) -#define DOMAIN_TO_NETCONN_TYPE(domain, netconn_type) (netconn_type) -#endif /* LWIP_IPV6 */ - -#define IS_SOCK_ADDR_TYPE_VALID_OR_UNSPEC(name) (((name)->sa_family == AF_UNSPEC) || \ - IS_SOCK_ADDR_TYPE_VALID(name)) -#define SOCK_ADDR_TYPE_MATCH_OR_UNSPEC(name, sock) (((name)->sa_family == AF_UNSPEC) || \ - SOCK_ADDR_TYPE_MATCH(name, sock)) -#define IS_SOCK_ADDR_ALIGNED(name) ((((mem_ptr_t)(name)) % 4) == 0) - - -#define LWIP_SOCKOPT_CHECK_OPTLEN(sock, optlen, opttype) do { if ((optlen) < sizeof(opttype)) { done_socket(sock); return EINVAL; }}while(0) -#define LWIP_SOCKOPT_CHECK_OPTLEN_CONN(sock, optlen, opttype) do { \ - LWIP_SOCKOPT_CHECK_OPTLEN(sock, optlen, opttype); \ - if ((sock)->conn == NULL) { done_socket(sock); return EINVAL; } }while(0) -#define LWIP_SOCKOPT_CHECK_OPTLEN_CONN_PCB(sock, optlen, opttype) do { \ - LWIP_SOCKOPT_CHECK_OPTLEN(sock, optlen, opttype); \ - if (((sock)->conn == NULL) || ((sock)->conn->pcb.tcp == NULL)) { done_socket(sock); return EINVAL; } }while(0) -#define LWIP_SOCKOPT_CHECK_OPTLEN_CONN_PCB_TYPE(sock, optlen, opttype, netconntype) do { \ - LWIP_SOCKOPT_CHECK_OPTLEN_CONN_PCB(sock, optlen, opttype); \ - if (NETCONNTYPE_GROUP(netconn_type((sock)->conn)) != netconntype) { done_socket(sock); return ENOPROTOOPT; } }while(0) - - -#define LWIP_SETGETSOCKOPT_DATA_VAR_REF(name) API_VAR_REF(name) -#define LWIP_SETGETSOCKOPT_DATA_VAR_DECLARE(name) API_VAR_DECLARE(struct lwip_setgetsockopt_data, name) -#define LWIP_SETGETSOCKOPT_DATA_VAR_FREE(name) API_VAR_FREE(MEMP_SOCKET_SETGETSOCKOPT_DATA, name) -#if LWIP_MPU_COMPATIBLE -#define LWIP_SETGETSOCKOPT_DATA_VAR_ALLOC(name, sock) do { \ - name = (struct lwip_setgetsockopt_data *)memp_malloc(MEMP_SOCKET_SETGETSOCKOPT_DATA); \ - if (name == NULL) { \ - sock_set_errno(sock, ENOMEM); \ - done_socket(sock); \ - return -1; \ - } }while(0) -#else /* LWIP_MPU_COMPATIBLE */ -#define LWIP_SETGETSOCKOPT_DATA_VAR_ALLOC(name, sock) -#endif /* LWIP_MPU_COMPATIBLE */ - -#if LWIP_SO_SNDRCVTIMEO_NONSTANDARD -#define LWIP_SO_SNDRCVTIMEO_OPTTYPE int -#define LWIP_SO_SNDRCVTIMEO_SET(optval, val) (*(int *)(optval) = (val)) -#define LWIP_SO_SNDRCVTIMEO_GET_MS(optval) ((long)*(const int*)(optval)) -#else -#define LWIP_SO_SNDRCVTIMEO_OPTTYPE struct timeval -#define LWIP_SO_SNDRCVTIMEO_SET(optval, val) do { \ - u32_t loc = (val); \ - ((struct timeval *)(optval))->tv_sec = (long)((loc) / 1000U); \ - ((struct timeval *)(optval))->tv_usec = (long)(((loc) % 1000U) * 1000U); }while(0) -#define LWIP_SO_SNDRCVTIMEO_GET_MS(optval) ((((const struct timeval *)(optval))->tv_sec * 1000) + (((const struct timeval *)(optval))->tv_usec / 1000)) -#endif - - -/** A struct sockaddr replacement that has the same alignment as sockaddr_in/ - * sockaddr_in6 if instantiated. - */ -union sockaddr_aligned { - struct sockaddr sa; -#if LWIP_IPV6 - struct sockaddr_in6 sin6; -#endif /* LWIP_IPV6 */ -#if LWIP_IPV4 - struct sockaddr_in sin; -#endif /* LWIP_IPV4 */ -}; - -/* Define the number of IPv4 multicast memberships, default is one per socket */ -#ifndef LWIP_SOCKET_MAX_MEMBERSHIPS -#define LWIP_SOCKET_MAX_MEMBERSHIPS NUM_SOCKETS -#endif - -#if LWIP_IGMP -/* This is to keep track of IP_ADD_MEMBERSHIP calls to drop the membership when - a socket is closed */ -struct lwip_socket_multicast_pair { - /** the socket */ - struct lwip_sock *sock; - /** the interface address */ - ip4_addr_t if_addr; - /** the group address */ - ip4_addr_t multi_addr; -}; - -static struct lwip_socket_multicast_pair socket_ipv4_multicast_memberships[LWIP_SOCKET_MAX_MEMBERSHIPS]; - -static int lwip_socket_register_membership(int s, const ip4_addr_t *if_addr, const ip4_addr_t *multi_addr); -static void lwip_socket_unregister_membership(int s, const ip4_addr_t *if_addr, const ip4_addr_t *multi_addr); -static void lwip_socket_drop_registered_memberships(int s); -#endif /* LWIP_IGMP */ - -#if LWIP_IPV6_MLD -/* This is to keep track of IP_JOIN_GROUP calls to drop the membership when - a socket is closed */ -struct lwip_socket_multicast_mld6_pair { - /** the socket */ - struct lwip_sock *sock; - /** the interface index */ - u8_t if_idx; - /** the group address */ - ip6_addr_t multi_addr; -}; - -static struct lwip_socket_multicast_mld6_pair socket_ipv6_multicast_memberships[LWIP_SOCKET_MAX_MEMBERSHIPS]; - -static int lwip_socket_register_mld6_membership(int s, unsigned int if_idx, const ip6_addr_t *multi_addr); -static void lwip_socket_unregister_mld6_membership(int s, unsigned int if_idx, const ip6_addr_t *multi_addr); -static void lwip_socket_drop_registered_mld6_memberships(int s); -#endif /* LWIP_IPV6_MLD */ - -/** The global array of available sockets */ -static struct lwip_sock sockets[NUM_SOCKETS]; - -#if LWIP_SOCKET_SELECT || LWIP_SOCKET_POLL -#if LWIP_TCPIP_CORE_LOCKING -/* protect the select_cb_list using core lock */ -#define LWIP_SOCKET_SELECT_DECL_PROTECT(lev) -#define LWIP_SOCKET_SELECT_PROTECT(lev) LOCK_TCPIP_CORE() -#define LWIP_SOCKET_SELECT_UNPROTECT(lev) UNLOCK_TCPIP_CORE() -#else /* LWIP_TCPIP_CORE_LOCKING */ -/* protect the select_cb_list using SYS_LIGHTWEIGHT_PROT */ -#define LWIP_SOCKET_SELECT_DECL_PROTECT(lev) SYS_ARCH_DECL_PROTECT(lev) -#define LWIP_SOCKET_SELECT_PROTECT(lev) SYS_ARCH_PROTECT(lev) -#define LWIP_SOCKET_SELECT_UNPROTECT(lev) SYS_ARCH_UNPROTECT(lev) -/** This counter is increased from lwip_select when the list is changed - and checked in select_check_waiters to see if it has changed. */ -static volatile int select_cb_ctr; -#endif /* LWIP_TCPIP_CORE_LOCKING */ -/** The global list of tasks waiting for select */ -static struct lwip_select_cb *select_cb_list; -#endif /* LWIP_SOCKET_SELECT || LWIP_SOCKET_POLL */ - -#define sock_set_errno(sk, e) do { \ - const int sockerr = (e); \ - set_errno(sockerr); \ -} while (0) - -/* Forward declaration of some functions */ -#if LWIP_SOCKET_SELECT || LWIP_SOCKET_POLL -static void event_callback(struct netconn *conn, enum netconn_evt evt, u16_t len); -#define DEFAULT_SOCKET_EVENTCB event_callback -static void select_check_waiters(int s, int has_recvevent, int has_sendevent, int has_errevent); -#else -#define DEFAULT_SOCKET_EVENTCB NULL -#endif -#if !LWIP_TCPIP_CORE_LOCKING -static void lwip_getsockopt_callback(void *arg); -static void lwip_setsockopt_callback(void *arg); -#endif -static int lwip_getsockopt_impl(int s, int level, int optname, void *optval, socklen_t *optlen); -static int lwip_setsockopt_impl(int s, int level, int optname, const void *optval, socklen_t optlen); -static int free_socket_locked(struct lwip_sock *sock, int is_tcp, struct netconn **conn, - union lwip_sock_lastdata *lastdata); -static void free_socket_free_elements(int is_tcp, struct netconn *conn, union lwip_sock_lastdata *lastdata); - -#if LWIP_IPV4 && LWIP_IPV6 -static void -sockaddr_to_ipaddr_port(const struct sockaddr *sockaddr, ip_addr_t *ipaddr, u16_t *port) -{ - if ((sockaddr->sa_family) == AF_INET6) { - SOCKADDR6_TO_IP6ADDR_PORT((const struct sockaddr_in6 *)(const void *)(sockaddr), ipaddr, *port); - ipaddr->type = IPADDR_TYPE_V6; - } else { - SOCKADDR4_TO_IP4ADDR_PORT((const struct sockaddr_in *)(const void *)(sockaddr), ipaddr, *port); - ipaddr->type = IPADDR_TYPE_V4; - } -} -#endif /* LWIP_IPV4 && LWIP_IPV6 */ - -/** LWIP_NETCONN_SEM_PER_THREAD==1: initialize thread-local semaphore */ -void -lwip_socket_thread_init(void) -{ - netconn_thread_init(); -} - -/** LWIP_NETCONN_SEM_PER_THREAD==1: destroy thread-local semaphore */ -void -lwip_socket_thread_cleanup(void) -{ - netconn_thread_cleanup(); -} - -#if LWIP_NETCONN_FULLDUPLEX -/* Thread-safe increment of sock->fd_used, with overflow check */ -static int -sock_inc_used(struct lwip_sock *sock) -{ - int ret; - SYS_ARCH_DECL_PROTECT(lev); - - LWIP_ASSERT("sock != NULL", sock != NULL); - - SYS_ARCH_PROTECT(lev); - if (sock->fd_free_pending) { - /* prevent new usage of this socket if free is pending */ - ret = 0; - } else { - ++sock->fd_used; - ret = 1; - LWIP_ASSERT("sock->fd_used != 0", sock->fd_used != 0); - } - SYS_ARCH_UNPROTECT(lev); - return ret; -} - -/* Like sock_inc_used(), but called under SYS_ARCH_PROTECT lock. */ -static int -sock_inc_used_locked(struct lwip_sock *sock) -{ - LWIP_ASSERT("sock != NULL", sock != NULL); - - if (sock->fd_free_pending) { - LWIP_ASSERT("sock->fd_used != 0", sock->fd_used != 0); - return 0; - } - - ++sock->fd_used; - LWIP_ASSERT("sock->fd_used != 0", sock->fd_used != 0); - return 1; -} - -/* In full-duplex mode,sock->fd_used != 0 prevents a socket descriptor from being - * released (and possibly reused) when used from more than one thread - * (e.g. read-while-write or close-while-write, etc) - * This function is called at the end of functions using (try)get_socket*(). - */ -static void -done_socket(struct lwip_sock *sock) -{ - int freed = 0; - int is_tcp = 0; - struct netconn *conn = NULL; - union lwip_sock_lastdata lastdata; - SYS_ARCH_DECL_PROTECT(lev); - LWIP_ASSERT("sock != NULL", sock != NULL); - - SYS_ARCH_PROTECT(lev); - LWIP_ASSERT("sock->fd_used > 0", sock->fd_used > 0); - if (--sock->fd_used == 0) { - if (sock->fd_free_pending) { - /* free the socket */ - sock->fd_used = 1; - is_tcp = sock->fd_free_pending & LWIP_SOCK_FD_FREE_TCP; - freed = free_socket_locked(sock, is_tcp, &conn, &lastdata); - } - } - SYS_ARCH_UNPROTECT(lev); - - if (freed) { - free_socket_free_elements(is_tcp, conn, &lastdata); - } -} - -#else /* LWIP_NETCONN_FULLDUPLEX */ -#define sock_inc_used(sock) 1 -#define sock_inc_used_locked(sock) 1 -#define done_socket(sock) -#endif /* LWIP_NETCONN_FULLDUPLEX */ - -/* Translate a socket 'int' into a pointer (only fails if the index is invalid) */ -static struct lwip_sock * -tryget_socket_unconn_nouse(int fd) -{ - int s = fd - LWIP_SOCKET_OFFSET; - if ((s < 0) || (s >= NUM_SOCKETS)) { - LWIP_DEBUGF(SOCKETS_DEBUG, ("tryget_socket_unconn(%d): invalid\n", fd)); - return NULL; - } - return &sockets[s]; -} - -struct lwip_sock * -lwip_socket_dbg_get_socket(int fd) -{ - return tryget_socket_unconn_nouse(fd); -} - -/* Translate a socket 'int' into a pointer (only fails if the index is invalid) */ -static struct lwip_sock * -tryget_socket_unconn(int fd) -{ - struct lwip_sock *ret = tryget_socket_unconn_nouse(fd); - if (ret != NULL) { - if (!sock_inc_used(ret)) { - return NULL; - } - } - return ret; -} - -/* Like tryget_socket_unconn(), but called under SYS_ARCH_PROTECT lock. */ -static struct lwip_sock * -tryget_socket_unconn_locked(int fd) -{ - struct lwip_sock *ret = tryget_socket_unconn_nouse(fd); - if (ret != NULL) { - if (!sock_inc_used_locked(ret)) { - return NULL; - } - } - return ret; -} - -/** - * Same as get_socket but doesn't set errno - * - * @param fd externally used socket index - * @return struct lwip_sock for the socket or NULL if not found - */ -static struct lwip_sock * -tryget_socket(int fd) -{ - struct lwip_sock *sock = tryget_socket_unconn(fd); - if (sock != NULL) { - if (sock->conn) { - return sock; - } - done_socket(sock); - } - return NULL; -} - -/** - * Map a externally used socket index to the internal socket representation. - * - * @param fd externally used socket index - * @return struct lwip_sock for the socket or NULL if not found - */ -static struct lwip_sock * -get_socket(int fd) -{ - struct lwip_sock *sock = tryget_socket(fd); - if (!sock) { - if ((fd < LWIP_SOCKET_OFFSET) || (fd >= (LWIP_SOCKET_OFFSET + NUM_SOCKETS))) { - LWIP_DEBUGF(SOCKETS_DEBUG, ("get_socket(%d): invalid\n", fd)); - } - set_errno(EBADF); - return NULL; - } - return sock; -} - -/** - * Allocate a new socket for a given netconn. - * - * @param newconn the netconn for which to allocate a socket - * @param accepted 1 if socket has been created by accept(), - * 0 if socket has been created by socket() - * @return the index of the new socket; -1 on error - */ -static int -alloc_socket(struct netconn *newconn, int accepted) -{ - int i; - SYS_ARCH_DECL_PROTECT(lev); - LWIP_UNUSED_ARG(accepted); - - /* allocate a new socket identifier */ - for (i = 0; i < NUM_SOCKETS; ++i) { - /* Protect socket array */ - SYS_ARCH_PROTECT(lev); - if (!sockets[i].conn) { -#if LWIP_NETCONN_FULLDUPLEX - if (sockets[i].fd_used) { - SYS_ARCH_UNPROTECT(lev); - continue; - } - sockets[i].fd_used = 1; - sockets[i].fd_free_pending = 0; -#endif - sockets[i].conn = newconn; - /* The socket is not yet known to anyone, so no need to protect - after having marked it as used. */ - SYS_ARCH_UNPROTECT(lev); - sockets[i].lastdata.pbuf = NULL; -#if LWIP_SOCKET_SELECT || LWIP_SOCKET_POLL - LWIP_ASSERT("sockets[i].select_waiting == 0", sockets[i].select_waiting == 0); - sockets[i].rcvevent = 0; - /* TCP sendbuf is empty, but the socket is not yet writable until connected - * (unless it has been created by accept()). */ - sockets[i].sendevent = (NETCONNTYPE_GROUP(newconn->type) == NETCONN_TCP ? (accepted != 0) : 1); - sockets[i].errevent = 0; - // init_waitqueue_head(&sockets[i].wq); -#endif /* LWIP_SOCKET_SELECT || LWIP_SOCKET_POLL */ - return i + LWIP_SOCKET_OFFSET; - } - SYS_ARCH_UNPROTECT(lev); - } - return -1; -} - -/** Free a socket (under lock) - * - * @param sock the socket to free - * @param is_tcp != 0 for TCP sockets, used to free lastdata - * @param conn the socekt's netconn is stored here, must be freed externally - * @param lastdata lastdata is stored here, must be freed externally - */ -static int -free_socket_locked(struct lwip_sock *sock, int is_tcp, struct netconn **conn, - union lwip_sock_lastdata *lastdata) -{ -#if LWIP_NETCONN_FULLDUPLEX - LWIP_ASSERT("sock->fd_used > 0", sock->fd_used > 0); - sock->fd_used--; - if (sock->fd_used > 0) { - sock->fd_free_pending = LWIP_SOCK_FD_FREE_FREE | (is_tcp ? LWIP_SOCK_FD_FREE_TCP : 0); - return 0; - } -#else /* LWIP_NETCONN_FULLDUPLEX */ - LWIP_UNUSED_ARG(is_tcp); -#endif /* LWIP_NETCONN_FULLDUPLEX */ - - *lastdata = sock->lastdata; - sock->lastdata.pbuf = NULL; - *conn = sock->conn; - sock->conn = NULL; - return 1; -} - -/** Free a socket's leftover members. - */ -static void -free_socket_free_elements(int is_tcp, struct netconn *conn, union lwip_sock_lastdata *lastdata) -{ - if (lastdata->pbuf != NULL) { - if (is_tcp) { - pbuf_free(lastdata->pbuf); - } else { - netbuf_delete(lastdata->netbuf); - } - } - if (conn != NULL) { - /* netconn_prepare_delete() has already been called, here we only free the conn */ - netconn_delete(conn); - } -} - -/** Free a socket. The socket's netconn must have been - * delete before! - * - * @param sock the socket to free - * @param is_tcp != 0 for TCP sockets, used to free lastdata - */ -static void -free_socket(struct lwip_sock *sock, int is_tcp) -{ - int freed; - struct netconn *conn; - union lwip_sock_lastdata lastdata; - SYS_ARCH_DECL_PROTECT(lev); - - /* Protect socket array */ - SYS_ARCH_PROTECT(lev); - - freed = free_socket_locked(sock, is_tcp, &conn, &lastdata); - SYS_ARCH_UNPROTECT(lev); - /* don't use 'sock' after this line, as another task might have allocated it */ - - if (freed) { - free_socket_free_elements(is_tcp, conn, &lastdata); - } -} - -/* Below this, the well-known socket functions are implemented. - * Use google.com or opengroup.org to get a good description :-) - * - * Exceptions are documented! - */ - -int -lwip_accept(int s, struct sockaddr *addr, socklen_t *addrlen) -{ - struct lwip_sock *sock, *nsock; - struct netconn *newconn; - ip_addr_t naddr; - u16_t port = 0; - int newsock; - err_t err; - int recvevent; - SYS_ARCH_DECL_PROTECT(lev); - - LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_accept(%d)...\n", s)); - sock = get_socket(s); - if (!sock) { - return -1; - } - - /* wait for a new connection */ - err = netconn_accept(sock->conn, &newconn); - if (err != ERR_OK) { - LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_accept(%d): netconn_acept failed, err=%d\n", s, err)); - if (NETCONNTYPE_GROUP(netconn_type(sock->conn)) != NETCONN_TCP) { - sock_set_errno(sock, EOPNOTSUPP); - } else if (err == ERR_CLSD) { - sock_set_errno(sock, EINVAL); - } else { - sock_set_errno(sock, err_to_errno(err)); - } - done_socket(sock); - return -1; - } - LWIP_ASSERT("newconn != NULL", newconn != NULL); - - newsock = alloc_socket(newconn, 1); - if (newsock == -1) { - netconn_delete(newconn); - sock_set_errno(sock, ENFILE); - done_socket(sock); - return -1; - } - LWIP_ASSERT("invalid socket index", (newsock >= LWIP_SOCKET_OFFSET) && (newsock < NUM_SOCKETS + LWIP_SOCKET_OFFSET)); - nsock = &sockets[newsock - LWIP_SOCKET_OFFSET]; - - /* See event_callback: If data comes in right away after an accept, even - * though the server task might not have created a new socket yet. - * In that case, newconn->socket is counted down (newconn->socket--), - * so nsock->rcvevent is >= 1 here! - */ - SYS_ARCH_PROTECT(lev); - recvevent = (s16_t)(-1 - newconn->socket); - newconn->socket = newsock; - SYS_ARCH_UNPROTECT(lev); - - if (newconn->callback) { - LOCK_TCPIP_CORE(); - while (recvevent > 0) { - recvevent--; - newconn->callback(newconn, NETCONN_EVT_RCVPLUS, 0); - } - UNLOCK_TCPIP_CORE(); - } - - /* Note that POSIX only requires us to check addr is non-NULL. addrlen must - * not be NULL if addr is valid. - */ - if ((addr != NULL) && (addrlen != NULL)) { - union sockaddr_aligned tempaddr; - /* get the IP address and port of the remote host */ - err = netconn_peer(newconn, &naddr, &port); - if (err != ERR_OK) { - LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_accept(%d): netconn_peer failed, err=%d\n", s, err)); - netconn_delete(newconn); - free_socket(nsock, 1); - sock_set_errno(sock, err_to_errno(err)); - done_socket(sock); - return -1; - } - - IPADDR_PORT_TO_SOCKADDR(&tempaddr, &naddr, port); - if (*addrlen > tempaddr.sa.sa_len) { - *addrlen = tempaddr.sa.sa_len; - } - MEMCPY(addr, &tempaddr, *addrlen); - - LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_accept(%d) returning new sock=%d addr=", s, newsock)); - ip_addr_debug_print_val(SOCKETS_DEBUG, naddr); - LWIP_DEBUGF(SOCKETS_DEBUG, (" port=%"U16_F"\n", port)); - } else { - LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_accept(%d) returning new sock=%d", s, newsock)); - } - - sock_set_errno(sock, 0); - done_socket(sock); - done_socket(nsock); - return newsock; -} - -int -lwip_bind(int s, const struct sockaddr *name, socklen_t namelen) -{ - struct lwip_sock *sock; - ip_addr_t local_addr; - u16_t local_port; - err_t err; - - sock = get_socket(s); - if (!sock) { - return -1; - } - - if (!SOCK_ADDR_TYPE_MATCH(name, sock)) { - /* sockaddr does not match socket type (IPv4/IPv6) */ - sock_set_errno(sock, err_to_errno(ERR_VAL)); - done_socket(sock); - return -1; - } - - /* check size, family and alignment of 'name' */ - LWIP_ERROR("lwip_bind: invalid address", (IS_SOCK_ADDR_LEN_VALID(namelen) && - IS_SOCK_ADDR_TYPE_VALID(name) && IS_SOCK_ADDR_ALIGNED(name)), - sock_set_errno(sock, err_to_errno(ERR_ARG)); done_socket(sock); return -1;); - LWIP_UNUSED_ARG(namelen); - - SOCKADDR_TO_IPADDR_PORT(name, &local_addr, local_port); - LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_bind(%d, addr=", s)); - ip_addr_debug_print_val(SOCKETS_DEBUG, local_addr); - LWIP_DEBUGF(SOCKETS_DEBUG, (" port=%"U16_F")\n", local_port)); - -#if LWIP_IPV4 && LWIP_IPV6 - /* Dual-stack: Unmap IPv4 mapped IPv6 addresses */ - if (IP_IS_V6_VAL(local_addr) && ip6_addr_isipv4mappedipv6(ip_2_ip6(&local_addr))) { - unmap_ipv4_mapped_ipv6(ip_2_ip4(&local_addr), ip_2_ip6(&local_addr)); - IP_SET_TYPE_VAL(local_addr, IPADDR_TYPE_V4); - } -#endif /* LWIP_IPV4 && LWIP_IPV6 */ - - err = netconn_bind(sock->conn, &local_addr, local_port); - - if (err != ERR_OK) { - LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_bind(%d) failed, err=%d\n", s, err)); - sock_set_errno(sock, err_to_errno(err)); - done_socket(sock); - return -1; - } - - LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_bind(%d) succeeded\n", s)); - sock_set_errno(sock, 0); - done_socket(sock); - return 0; -} - -int -lwip_close(int s) -{ -#if LWIP_ENABLE_DISTRIBUTED_NET - if (!is_distributed_net_enabled()) { - return lwip_close_internal(s); - } - return distributed_net_close(s); -} - -int -lwip_close_internal(int s) -{ -#endif - struct lwip_sock *sock; - int is_tcp = 0; - err_t err; - - LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_close(%d)\n", s)); - - sock = get_socket(s); - if (!sock) { - return -1; - } - - if (sock->conn != NULL) { - is_tcp = NETCONNTYPE_GROUP(netconn_type(sock->conn)) == NETCONN_TCP; - } else { - LWIP_ASSERT("sock->lastdata == NULL", sock->lastdata.pbuf == NULL); - } - -#if LWIP_IGMP - /* drop all possibly joined IGMP memberships */ - lwip_socket_drop_registered_memberships(s); -#endif /* LWIP_IGMP */ -#if LWIP_IPV6_MLD - /* drop all possibly joined MLD6 memberships */ - lwip_socket_drop_registered_mld6_memberships(s); -#endif /* LWIP_IPV6_MLD */ - - err = netconn_prepare_delete(sock->conn); - if (err != ERR_OK) { - sock_set_errno(sock, err_to_errno(err)); - done_socket(sock); - return -1; - } - - free_socket(sock, is_tcp); - set_errno(0); - return 0; -} - -int -lwip_connect(int s, const struct sockaddr *name, socklen_t namelen) -{ -#if LWIP_ENABLE_DISTRIBUTED_NET - if (!is_distributed_net_enabled()) { - return lwip_connect_internal(s, name, namelen); - } - return distributed_net_connect(s, name, namelen); -} - -int -lwip_connect_internal(int s, const struct sockaddr *name, socklen_t namelen) -{ -#endif - struct lwip_sock *sock; - err_t err; - - sock = get_socket(s); - if (!sock) { - return -1; - } - - if (!SOCK_ADDR_TYPE_MATCH_OR_UNSPEC(name, sock)) { - /* sockaddr does not match socket type (IPv4/IPv6) */ - sock_set_errno(sock, err_to_errno(ERR_VAL)); - done_socket(sock); - return -1; - } - - LWIP_UNUSED_ARG(namelen); - if (name->sa_family == AF_UNSPEC) { - LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_connect(%d, AF_UNSPEC)\n", s)); - err = netconn_disconnect(sock->conn); - } else { - ip_addr_t remote_addr; - u16_t remote_port; - - /* check size, family and alignment of 'name' */ - LWIP_ERROR("lwip_connect: invalid address", IS_SOCK_ADDR_LEN_VALID(namelen) && - IS_SOCK_ADDR_TYPE_VALID_OR_UNSPEC(name) && IS_SOCK_ADDR_ALIGNED(name), - sock_set_errno(sock, err_to_errno(ERR_ARG)); done_socket(sock); return -1;); - - SOCKADDR_TO_IPADDR_PORT(name, &remote_addr, remote_port); - LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_connect(%d, addr=", s)); - ip_addr_debug_print_val(SOCKETS_DEBUG, remote_addr); - LWIP_DEBUGF(SOCKETS_DEBUG, (" port=%"U16_F")\n", remote_port)); - -#if LWIP_IPV4 && LWIP_IPV6 - /* Dual-stack: Unmap IPv4 mapped IPv6 addresses */ - if (IP_IS_V6_VAL(remote_addr) && ip6_addr_isipv4mappedipv6(ip_2_ip6(&remote_addr))) { - unmap_ipv4_mapped_ipv6(ip_2_ip4(&remote_addr), ip_2_ip6(&remote_addr)); - IP_SET_TYPE_VAL(remote_addr, IPADDR_TYPE_V4); - } -#endif /* LWIP_IPV4 && LWIP_IPV6 */ - - err = netconn_connect(sock->conn, &remote_addr, remote_port); - } - - if (err != ERR_OK) { - LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_connect(%d) failed, err=%d\n", s, err)); - sock_set_errno(sock, err_to_errno(err)); - done_socket(sock); - return -1; - } - - LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_connect(%d) succeeded\n", s)); - sock_set_errno(sock, 0); - done_socket(sock); - return 0; -} - -/** - * Set a socket into listen mode. - * The socket may not have been used for another connection previously. - * - * @param s the socket to set to listening mode - * @param backlog (ATTENTION: needs TCP_LISTEN_BACKLOG=1) - * @return 0 on success, non-zero on failure - */ -int -lwip_listen(int s, int backlog) -{ - struct lwip_sock *sock; - err_t err; - - LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_listen(%d, backlog=%d)\n", s, backlog)); - - sock = get_socket(s); - if (!sock) { - return -1; - } - - /* limit the "backlog" parameter to fit in an u8_t */ - backlog = LWIP_MIN(LWIP_MAX(backlog, 0), 0xff); - - err = netconn_listen_with_backlog(sock->conn, (u8_t)backlog); - - if (err != ERR_OK) { - LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_listen(%d) failed, err=%d\n", s, err)); - if (NETCONNTYPE_GROUP(netconn_type(sock->conn)) != NETCONN_TCP) { - sock_set_errno(sock, EOPNOTSUPP); - } else { - sock_set_errno(sock, err_to_errno(err)); - } - done_socket(sock); - return -1; - } - - sock_set_errno(sock, 0); - done_socket(sock); - return 0; -} - -#if LWIP_TCP -/* Helper function to loop over receiving pbufs from netconn - * until "len" bytes are received or we're otherwise done. - * Keeps sock->lastdata for peeking or partly copying. - */ -static ssize_t -lwip_recv_tcp(struct lwip_sock *sock, void *mem, size_t len, int flags) -{ - u8_t apiflags = NETCONN_NOAUTORCVD; - ssize_t recvd = 0; - ssize_t recv_left = (len <= SSIZE_MAX) ? (ssize_t)len : SSIZE_MAX; - - LWIP_ASSERT("no socket given", sock != NULL); - LWIP_ASSERT("this should be checked internally", NETCONNTYPE_GROUP(netconn_type(sock->conn)) == NETCONN_TCP); - - if (flags & MSG_DONTWAIT) { - apiflags |= NETCONN_DONTBLOCK; - } - - do { - struct pbuf *p; - err_t err; - u16_t copylen; - - LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_recv_tcp: top while sock->lastdata=%p\n", (void *)sock->lastdata.pbuf)); - /* Check if there is data left from the last recv operation. */ - if (sock->lastdata.pbuf) { - p = sock->lastdata.pbuf; - } else { - /* No data was left from the previous operation, so we try to get - some from the network. */ - err = netconn_recv_tcp_pbuf_flags(sock->conn, &p, apiflags); - LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_recv_tcp: netconn_recv err=%d, pbuf=%p\n", - err, (void *)p)); - - if (err != ERR_OK) { - if (recvd > 0) { - /* already received data, return that (this trusts in getting the same error from - netconn layer again next time netconn_recv is called) */ - goto lwip_recv_tcp_done; - } - /* We should really do some error checking here. */ - LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_recv_tcp: p == NULL, error is \"%s\"!\n", - lwip_strerr(err))); - sock_set_errno(sock, err_to_errno(err)); - if (err == ERR_CLSD) { - return 0; - } else { - return -1; - } - } - LWIP_ASSERT("p != NULL", p != NULL); - sock->lastdata.pbuf = p; - } - - LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_recv_tcp: buflen=%"U16_F" recv_left=%d off=%d\n", - p->tot_len, (int)recv_left, (int)recvd)); - - if (recv_left > p->tot_len) { - copylen = p->tot_len; - } else { - copylen = (u16_t)recv_left; - } - if (recvd + copylen < recvd) { - /* overflow */ - copylen = (u16_t)(SSIZE_MAX - recvd); - } - - /* copy the contents of the received buffer into - the supplied memory pointer mem */ - pbuf_copy_partial(p, (u8_t *)mem + recvd, copylen, 0); - - recvd += copylen; - - /* TCP combines multiple pbufs for one recv */ - LWIP_ASSERT("invalid copylen, len would underflow", recv_left >= copylen); - recv_left -= copylen; - - /* Unless we peek the incoming message... */ - if ((flags & MSG_PEEK) == 0) { - /* ... check if there is data left in the pbuf */ - LWIP_ASSERT("invalid copylen", p->tot_len >= copylen); - if (p->tot_len - copylen > 0) { - /* If so, it should be saved in the sock structure for the next recv call. - We store the pbuf but hide/free the consumed data: */ - sock->lastdata.pbuf = pbuf_free_header(p, copylen); - LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_recv_tcp: lastdata now pbuf=%p\n", (void *)sock->lastdata.pbuf)); - } else { - sock->lastdata.pbuf = NULL; - LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_recv_tcp: deleting pbuf=%p\n", (void *)p)); - pbuf_free(p); - } - } - /* once we have some data to return, only add more if we don't need to wait */ - apiflags |= NETCONN_DONTBLOCK | NETCONN_NOFIN; - /* @todo: do we need to support peeking more than one pbuf? */ - } while ((recv_left > 0) && !(flags & MSG_PEEK)); -lwip_recv_tcp_done: - if ((recvd > 0) && !(flags & MSG_PEEK)) { - /* ensure window update after copying all data */ - netconn_tcp_recvd(sock->conn, (size_t)recvd); - } - sock_set_errno(sock, 0); - return recvd; -} -#endif - -/* Convert a netbuf's address data to struct sockaddr */ -static int -lwip_sock_make_addr(struct netconn *conn, ip_addr_t *fromaddr, u16_t port, - struct sockaddr *from, socklen_t *fromlen) -{ - int truncated = 0; - union sockaddr_aligned saddr; - - LWIP_UNUSED_ARG(conn); - - LWIP_ASSERT("fromaddr != NULL", fromaddr != NULL); - LWIP_ASSERT("from != NULL", from != NULL); - LWIP_ASSERT("fromlen != NULL", fromlen != NULL); - -#if LWIP_IPV4 && LWIP_IPV6 - /* Dual-stack: Map IPv4 addresses to IPv4 mapped IPv6 */ - if (NETCONNTYPE_ISIPV6(netconn_type(conn)) && IP_IS_V4(fromaddr)) { - ip4_2_ipv4_mapped_ipv6(ip_2_ip6(fromaddr), ip_2_ip4(fromaddr)); - IP_SET_TYPE(fromaddr, IPADDR_TYPE_V6); - } -#endif /* LWIP_IPV4 && LWIP_IPV6 */ - - IPADDR_PORT_TO_SOCKADDR(&saddr, fromaddr, port); - //DF_NADDR(*fromaddr); - if (*fromlen < saddr.sa.sa_len) { - truncated = 1; - } else if (*fromlen > saddr.sa.sa_len) { - *fromlen = saddr.sa.sa_len; - } - MEMCPY(from, &saddr, *fromlen); - return truncated; -} - -#if LWIP_TCP -/* Helper function to get a tcp socket's remote address info */ -static int -lwip_recv_tcp_from(struct lwip_sock *sock, struct sockaddr *from, socklen_t *fromlen, const char *dbg_fn, int dbg_s, ssize_t dbg_ret) -{ - if (sock == NULL) { - return 0; - } - LWIP_UNUSED_ARG(dbg_fn); - LWIP_UNUSED_ARG(dbg_s); - LWIP_UNUSED_ARG(dbg_ret); - -#if !SOCKETS_DEBUG - if (from && fromlen) -#endif /* !SOCKETS_DEBUG */ - { - /* get remote addr/port from tcp_pcb */ - u16_t port; - ip_addr_t tmpaddr; - err_t err = netconn_getaddr(sock->conn, &tmpaddr, &port, 0); - LWIP_DEBUGF(SOCKETS_DEBUG, ("%s(%d): addr=", dbg_fn, dbg_s)); - ip_addr_debug_print_val(SOCKETS_DEBUG, tmpaddr); - LWIP_DEBUGF(SOCKETS_DEBUG, (" port=%"U16_F" len=%d\n", port, (int)dbg_ret)); - if (!err && from && fromlen) { - return lwip_sock_make_addr(sock->conn, &tmpaddr, port, from, fromlen); - } - } - return 0; -} -#endif - -/* Helper function to receive a netbuf from a udp or raw netconn. - * Keeps sock->lastdata for peeking. - */ -static err_t -lwip_recvfrom_udp_raw(struct lwip_sock *sock, int flags, struct msghdr *msg, u16_t *datagram_len, int dbg_s) -{ - struct netbuf *buf; - u8_t apiflags; - err_t err; - u16_t buflen, copylen, copied; - int i; - - LWIP_UNUSED_ARG(dbg_s); - LWIP_ERROR("lwip_recvfrom_udp_raw: invalid arguments", (msg->msg_iov != NULL) || (msg->msg_iovlen <= 0), return ERR_ARG;); - - if (flags & MSG_DONTWAIT) { - apiflags = NETCONN_DONTBLOCK; - } else { - apiflags = 0; - } - - LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_recvfrom_udp_raw[UDP/RAW]: top sock->lastdata=%p\n", (void *)sock->lastdata.netbuf)); - /* Check if there is data left from the last recv operation. */ - buf = sock->lastdata.netbuf; - if (buf == NULL) { - /* No data was left from the previous operation, so we try to get - some from the network. */ - err = netconn_recv_udp_raw_netbuf_flags(sock->conn, &buf, apiflags); - LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_recvfrom_udp_raw[UDP/RAW]: netconn_recv err=%d, netbuf=%p\n", - err, (void *)buf)); - - if (err != ERR_OK) { - return err; - } - LWIP_ASSERT("buf != NULL", buf != NULL); - sock->lastdata.netbuf = buf; - } - buflen = buf->p->tot_len; - LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_recvfrom_udp_raw: buflen=%"U16_F"\n", buflen)); - - copied = 0; - /* copy the pbuf payload into the iovs */ - for (i = 0; (i < msg->msg_iovlen) && (copied < buflen); i++) { - u16_t len_left = (u16_t)(buflen - copied); - if (msg->msg_iov[i].iov_len > len_left) { - copylen = len_left; - } else { - copylen = (u16_t)msg->msg_iov[i].iov_len; - } - - /* copy the contents of the received buffer into - the supplied memory buffer */ - pbuf_copy_partial(buf->p, (u8_t *)msg->msg_iov[i].iov_base, copylen, copied); - copied = (u16_t)(copied + copylen); - } - - /* Check to see from where the data was.*/ -#if !SOCKETS_DEBUG - if (msg->msg_name && msg->msg_namelen) -#endif /* !SOCKETS_DEBUG */ - { - LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_recvfrom_udp_raw(%d): addr=", dbg_s)); - ip_addr_debug_print_val(SOCKETS_DEBUG, *netbuf_fromaddr(buf)); - LWIP_DEBUGF(SOCKETS_DEBUG, (" port=%"U16_F" len=%d\n", netbuf_fromport(buf), copied)); - if (msg->msg_name && msg->msg_namelen) { - lwip_sock_make_addr(sock->conn, netbuf_fromaddr(buf), netbuf_fromport(buf), - (struct sockaddr *)msg->msg_name, &msg->msg_namelen); - } - } - - /* Initialize flag output */ - msg->msg_flags = 0; - - if (msg->msg_control) { - u8_t wrote_msg = 0; -#if LWIP_NETBUF_RECVINFO - /* Check if packet info was recorded */ - if (buf->flags & NETBUF_FLAG_DESTADDR) { - if (IP_IS_V4(&buf->toaddr)) { -#if LWIP_IPV4 - if (msg->msg_controllen >= CMSG_SPACE(sizeof(struct in_pktinfo))) { - struct cmsghdr *chdr = CMSG_FIRSTHDR(msg); /* This will always return a header!! */ - struct in_pktinfo *pkti = (struct in_pktinfo *)CMSG_DATA(chdr); - chdr->cmsg_level = IPPROTO_IP; - chdr->cmsg_type = IP_PKTINFO; - chdr->cmsg_len = CMSG_LEN(sizeof(struct in_pktinfo)); - pkti->ipi_ifindex = buf->p->if_idx; - inet_addr_from_ip4addr(&pkti->ipi_addr, ip_2_ip4(netbuf_destaddr(buf))); - msg->msg_controllen = CMSG_SPACE(sizeof(struct in_pktinfo)); - wrote_msg = 1; - } else { - msg->msg_flags |= MSG_CTRUNC; - } -#endif /* LWIP_IPV4 */ - } - } -#endif /* LWIP_NETBUF_RECVINFO */ - - if (!wrote_msg) { - msg->msg_controllen = 0; - } - } - - /* If we don't peek the incoming message: zero lastdata pointer and free the netbuf */ - if ((flags & MSG_PEEK) == 0) { - sock->lastdata.netbuf = NULL; - netbuf_delete(buf); - } - if (datagram_len) { - *datagram_len = buflen; - } - return ERR_OK; -} - -ssize_t -lwip_recvfrom(int s, void *mem, size_t len, int flags, - struct sockaddr *from, socklen_t *fromlen) -{ -#if LWIP_ENABLE_DISTRIBUTED_NET && LWIP_USE_GET_HOST_BY_NAME_EXTERNAL - if (!is_distributed_net_enabled()) { - return lwip_recvfrom_internal(s, mem, len, flags, from, fromlen); - } - return distributed_net_recvfrom(s, mem, len, flags, from, fromlen); -} - -ssize_t -lwip_recvfrom_internal(int s, void *mem, size_t len, int flags, - struct sockaddr *from, socklen_t *fromlen) -{ -#endif - struct lwip_sock *sock; - ssize_t ret; - - LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_recvfrom(%d, %p, %"SZT_F", 0x%x, ..)\n", s, mem, len, flags)); - sock = get_socket(s); - if (!sock) { - return -1; - } -#if LWIP_TCP - if (NETCONNTYPE_GROUP(netconn_type(sock->conn)) == NETCONN_TCP) { - ret = lwip_recv_tcp(sock, mem, len, flags); - lwip_recv_tcp_from(sock, from, fromlen, "lwip_recvfrom", s, ret); - done_socket(sock); - return ret; - } else -#endif - { - u16_t datagram_len = 0; - struct iovec vec; - struct msghdr msg; - err_t err; - vec.iov_base = mem; - vec.iov_len = len; - msg.msg_control = NULL; - msg.msg_controllen = 0; - msg.msg_flags = 0; - msg.msg_iov = &vec; - msg.msg_iovlen = 1; - msg.msg_name = from; - msg.msg_namelen = (fromlen ? *fromlen : 0); - err = lwip_recvfrom_udp_raw(sock, flags, &msg, &datagram_len, s); - if (err != ERR_OK) { - LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_recvfrom[UDP/RAW](%d): buf == NULL, error is \"%s\"!\n", - s, lwip_strerr(err))); - sock_set_errno(sock, err_to_errno(err)); - done_socket(sock); - return -1; - } - ret = (ssize_t)LWIP_MIN(LWIP_MIN(len, datagram_len), SSIZE_MAX); - if (fromlen) { - *fromlen = msg.msg_namelen; - } - } - - sock_set_errno(sock, 0); - done_socket(sock); - return ret; -} - -ssize_t -lwip_read(int s, void *mem, size_t len) -{ - return lwip_recvfrom(s, mem, len, 0, NULL, NULL); -} - -ssize_t -lwip_readv(int s, const struct iovec *iov, int iovcnt) -{ - struct msghdr msg; - - msg.msg_name = NULL; - msg.msg_namelen = 0; - /* Hack: we have to cast via number to cast from 'const' pointer to non-const. - Blame the opengroup standard for this inconsistency. */ - msg.msg_iov = LWIP_CONST_CAST(struct iovec *, iov); - msg.msg_iovlen = iovcnt; - msg.msg_control = NULL; - msg.msg_controllen = 0; - msg.msg_flags = 0; - return lwip_recvmsg(s, &msg, 0); -} - -ssize_t -lwip_recv(int s, void *mem, size_t len, int flags) -{ - return lwip_recvfrom(s, mem, len, flags, NULL, NULL); -} - -ssize_t -lwip_recvmsg(int s, struct msghdr *message, int flags) -{ - struct lwip_sock *sock; - int i; - ssize_t buflen; - - LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_recvmsg(%d, message=%p, flags=0x%x)\n", s, (void *)message, flags)); - LWIP_ERROR("lwip_recvmsg: invalid message pointer", message != NULL, return ERR_ARG;); - LWIP_ERROR("lwip_recvmsg: unsupported flags", (flags & ~(MSG_PEEK|MSG_DONTWAIT)) == 0, - set_errno(EOPNOTSUPP); return -1;); - - if ((message->msg_iovlen <= 0) || (message->msg_iovlen > IOV_MAX)) { - set_errno(EMSGSIZE); - return -1; - } - - sock = get_socket(s); - if (!sock) { - return -1; - } - - /* check for valid vectors */ - buflen = 0; - for (i = 0; i < message->msg_iovlen; i++) { - if ((message->msg_iov[i].iov_base == NULL) || ((ssize_t)message->msg_iov[i].iov_len <= 0) || - ((size_t)(ssize_t)message->msg_iov[i].iov_len != message->msg_iov[i].iov_len) || - ((ssize_t)(buflen + (ssize_t)message->msg_iov[i].iov_len) <= 0)) { - sock_set_errno(sock, err_to_errno(ERR_VAL)); - done_socket(sock); - return -1; - } - buflen = (ssize_t)(buflen + (ssize_t)message->msg_iov[i].iov_len); - } - - if (NETCONNTYPE_GROUP(netconn_type(sock->conn)) == NETCONN_TCP) { -#if LWIP_TCP - int recv_flags = flags; - message->msg_flags = 0; - /* recv the data */ - buflen = 0; - for (i = 0; i < message->msg_iovlen; i++) { - /* try to receive into this vector's buffer */ - ssize_t recvd_local = lwip_recv_tcp(sock, message->msg_iov[i].iov_base, message->msg_iov[i].iov_len, recv_flags); - if (recvd_local > 0) { - /* sum up received bytes */ - buflen += recvd_local; - } - if ((recvd_local < 0) || (recvd_local < (int)message->msg_iov[i].iov_len) || - (flags & MSG_PEEK)) { - /* returned prematurely (or peeking, which might actually be limitated to the first iov) */ - if (buflen <= 0) { - /* nothing received at all, propagate the error */ - buflen = recvd_local; - } - break; - } - /* pass MSG_DONTWAIT to lwip_recv_tcp() to prevent waiting for more data */ - recv_flags |= MSG_DONTWAIT; - } - if (buflen > 0) { - /* reset socket error since we have received something */ - sock_set_errno(sock, 0); - } - /* " If the socket is connected, the msg_name and msg_namelen members shall be ignored." */ - done_socket(sock); - return buflen; -#else /* LWIP_TCP */ - sock_set_errno(sock, err_to_errno(ERR_ARG)); - done_socket(sock); - return -1; -#endif /* LWIP_TCP */ - } - /* else, UDP and RAW NETCONNs */ -#if LWIP_UDP || LWIP_RAW - { - u16_t datagram_len = 0; - err_t err; - err = lwip_recvfrom_udp_raw(sock, flags, message, &datagram_len, s); - if (err != ERR_OK) { - LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_recvmsg[UDP/RAW](%d): buf == NULL, error is \"%s\"!\n", - s, lwip_strerr(err))); - sock_set_errno(sock, err_to_errno(err)); - done_socket(sock); - return -1; - } - if (datagram_len > buflen) { - message->msg_flags |= MSG_TRUNC; - } - - sock_set_errno(sock, 0); - done_socket(sock); - return (int)datagram_len; - } -#else /* LWIP_UDP || LWIP_RAW */ - sock_set_errno(sock, err_to_errno(ERR_ARG)); - done_socket(sock); - return -1; -#endif /* LWIP_UDP || LWIP_RAW */ -} - -ssize_t -lwip_send(int s, const void *data, size_t size, int flags) -{ - struct lwip_sock *sock; - err_t err; - u8_t write_flags; - size_t written; - - LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_send(%d, data=%p, size=%"SZT_F", flags=0x%x)\n", - s, data, size, flags)); - - sock = get_socket(s); - if (!sock) { - return -1; - } - - if (NETCONNTYPE_GROUP(netconn_type(sock->conn)) != NETCONN_TCP) { -#if (LWIP_UDP || LWIP_RAW) - done_socket(sock); -#if LWIP_ENABLE_DISTRIBUTED_NET && LWIP_USE_GET_HOST_BY_NAME_EXTERNAL - return lwip_sendto_internal(s, data, size, flags, NULL, 0); -#else - return lwip_sendto(s, data, size, flags, NULL, 0); -#endif -#else /* (LWIP_UDP || LWIP_RAW) */ - sock_set_errno(sock, err_to_errno(ERR_ARG)); - done_socket(sock); - return -1; -#endif /* (LWIP_UDP || LWIP_RAW) */ - } - - write_flags = (u8_t)(NETCONN_COPY | - ((flags & MSG_MORE) ? NETCONN_MORE : 0) | - ((flags & MSG_DONTWAIT) ? NETCONN_DONTBLOCK : 0)); - written = 0; - err = netconn_write_partly(sock->conn, data, size, write_flags, &written); - - LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_send(%d) err=%d written=%"SZT_F"\n", s, err, written)); - sock_set_errno(sock, err_to_errno(err)); - done_socket(sock); - /* casting 'written' to ssize_t is OK here since the netconn API limits it to SSIZE_MAX */ - return (err == ERR_OK ? (ssize_t)written : -1); -} - -ssize_t -lwip_sendmsg(int s, const struct msghdr *msg, int flags) -{ -#if LWIP_ENABLE_DISTRIBUTED_NET && LWIP_USE_GET_HOST_BY_NAME_EXTERNAL && LWIP_DISTRIBUTED_NET_ENABLE_SENDMSG - if (!is_distributed_net_enabled()) { - return lwip_sendmsg_internal(s, msg, flags); - } - return distributed_net_sendmsg(s, msg, flags); -} - -ssize_t -lwip_sendmsg_internal(int s, const struct msghdr *msg, int flags) -{ -#endif - struct lwip_sock *sock; -#if LWIP_TCP - u8_t write_flags; - size_t written; -#endif - err_t err = ERR_OK; - - sock = get_socket(s); - if (!sock) { - return -1; - } - - LWIP_ERROR("lwip_sendmsg: invalid msghdr", msg != NULL, - sock_set_errno(sock, err_to_errno(ERR_ARG)); done_socket(sock); return -1;); - LWIP_ERROR("lwip_sendmsg: invalid msghdr iov", msg->msg_iov != NULL, - sock_set_errno(sock, err_to_errno(ERR_ARG)); done_socket(sock); return -1;); - LWIP_ERROR("lwip_sendmsg: maximum iovs exceeded", (msg->msg_iovlen > 0) && (msg->msg_iovlen <= IOV_MAX), - sock_set_errno(sock, EMSGSIZE); done_socket(sock); return -1;); - LWIP_ERROR("lwip_sendmsg: unsupported flags", (flags & ~(MSG_DONTWAIT | MSG_MORE)) == 0, - sock_set_errno(sock, EOPNOTSUPP); done_socket(sock); return -1;); - - LWIP_UNUSED_ARG(msg->msg_control); - LWIP_UNUSED_ARG(msg->msg_controllen); - LWIP_UNUSED_ARG(msg->msg_flags); - - if (NETCONNTYPE_GROUP(netconn_type(sock->conn)) == NETCONN_TCP) { -#if LWIP_TCP - write_flags = (u8_t)(NETCONN_COPY | - ((flags & MSG_MORE) ? NETCONN_MORE : 0) | - ((flags & MSG_DONTWAIT) ? NETCONN_DONTBLOCK : 0)); - - written = 0; - err = netconn_write_vectors_partly(sock->conn, (struct netvector *)msg->msg_iov, (u16_t)msg->msg_iovlen, write_flags, &written); - sock_set_errno(sock, err_to_errno(err)); - done_socket(sock); - /* casting 'written' to ssize_t is OK here since the netconn API limits it to SSIZE_MAX */ - return (err == ERR_OK ? (ssize_t)written : -1); -#else /* LWIP_TCP */ - sock_set_errno(sock, err_to_errno(ERR_ARG)); - done_socket(sock); - return -1; -#endif /* LWIP_TCP */ - } - /* else, UDP and RAW NETCONNs */ -#if LWIP_UDP || LWIP_RAW - { - struct netbuf chain_buf; - int i; - ssize_t size = 0; - - LWIP_UNUSED_ARG(flags); - LWIP_ERROR("lwip_sendmsg: invalid msghdr name", (((msg->msg_name == NULL) && (msg->msg_namelen == 0)) || - IS_SOCK_ADDR_LEN_VALID(msg->msg_namelen)), - sock_set_errno(sock, err_to_errno(ERR_ARG)); done_socket(sock); return -1;); - - /* initialize chain buffer with destination */ - memset(&chain_buf, 0, sizeof(struct netbuf)); - if (msg->msg_name) { - u16_t remote_port; - SOCKADDR_TO_IPADDR_PORT((const struct sockaddr *)msg->msg_name, &chain_buf.addr, remote_port); - netbuf_fromport(&chain_buf) = remote_port; - } -#if LWIP_NETIF_TX_SINGLE_PBUF - for (i = 0; i < msg->msg_iovlen; i++) { - size += msg->msg_iov[i].iov_len; - if ((msg->msg_iov[i].iov_len > INT_MAX) || (size < (int)msg->msg_iov[i].iov_len)) { - /* overflow */ - goto sendmsg_emsgsize; - } - } - if (size > 0xFFFF) { - /* overflow */ - goto sendmsg_emsgsize; - } - /* Allocate a new netbuf and copy the data into it. */ - if (netbuf_alloc(&chain_buf, (u16_t)size) == NULL) { - err = ERR_MEM; - } else { - /* flatten the IO vectors */ - size_t offset = 0; - for (i = 0; i < msg->msg_iovlen; i++) { - MEMCPY(&((u8_t *)chain_buf.p->payload)[offset], msg->msg_iov[i].iov_base, msg->msg_iov[i].iov_len); - offset += msg->msg_iov[i].iov_len; - } -#if LWIP_CHECKSUM_ON_COPY - { - /* This can be improved by using LWIP_CHKSUM_COPY() and aggregating the checksum for each IO vector */ - u16_t chksum = ~inet_chksum_pbuf(chain_buf.p); - netbuf_set_chksum(&chain_buf, chksum); - } -#endif /* LWIP_CHECKSUM_ON_COPY */ - err = ERR_OK; - } -#else /* LWIP_NETIF_TX_SINGLE_PBUF */ - /* create a chained netbuf from the IO vectors. NOTE: we assemble a pbuf chain - manually to avoid having to allocate, chain, and delete a netbuf for each iov */ - for (i = 0; i < msg->msg_iovlen; i++) { - struct pbuf *p; - if (msg->msg_iov[i].iov_len > 0xFFFF) { - /* overflow */ - goto sendmsg_emsgsize; - } - p = pbuf_alloc(PBUF_TRANSPORT, 0, PBUF_REF); - if (p == NULL) { - err = ERR_MEM; /* let netbuf_delete() cleanup chain_buf */ - break; - } - p->payload = msg->msg_iov[i].iov_base; - p->len = p->tot_len = (u16_t)msg->msg_iov[i].iov_len; - /* netbuf empty, add new pbuf */ - if (chain_buf.p == NULL) { - chain_buf.p = chain_buf.ptr = p; - /* add pbuf to existing pbuf chain */ - } else { - if (chain_buf.p->tot_len + p->len > 0xffff) { - /* overflow */ - pbuf_free(p); - goto sendmsg_emsgsize; - } - pbuf_cat(chain_buf.p, p); - } - } - /* save size of total chain */ - if (err == ERR_OK) { - size = netbuf_len(&chain_buf); - } -#endif /* LWIP_NETIF_TX_SINGLE_PBUF */ - - if (err == ERR_OK) { -#if LWIP_IPV4 && LWIP_IPV6 - /* Dual-stack: Unmap IPv4 mapped IPv6 addresses */ - if (IP_IS_V6_VAL(chain_buf.addr) && ip6_addr_isipv4mappedipv6(ip_2_ip6(&chain_buf.addr))) { - unmap_ipv4_mapped_ipv6(ip_2_ip4(&chain_buf.addr), ip_2_ip6(&chain_buf.addr)); - IP_SET_TYPE_VAL(chain_buf.addr, IPADDR_TYPE_V4); - } -#endif /* LWIP_IPV4 && LWIP_IPV6 */ - - /* send the data */ - err = netconn_send(sock->conn, &chain_buf); - } - - /* deallocated the buffer */ - netbuf_free(&chain_buf); - - sock_set_errno(sock, err_to_errno(err)); - done_socket(sock); - return (err == ERR_OK ? size : -1); -sendmsg_emsgsize: - sock_set_errno(sock, EMSGSIZE); - netbuf_free(&chain_buf); - done_socket(sock); - return -1; - } -#else /* LWIP_UDP || LWIP_RAW */ - sock_set_errno(sock, err_to_errno(ERR_ARG)); - done_socket(sock); - return -1; -#endif /* LWIP_UDP || LWIP_RAW */ -} - -ssize_t -lwip_sendto(int s, const void *data, size_t size, int flags, - const struct sockaddr *to, socklen_t tolen) -{ -#if LWIP_ENABLE_DISTRIBUTED_NET && LWIP_USE_GET_HOST_BY_NAME_EXTERNAL - if (!is_distributed_net_enabled()) { - return lwip_sendto_internal(s, data, size, flags, to, tolen); - } - return distributed_net_sendto(s, data, size, flags, to, tolen); -} - -ssize_t -lwip_sendto_internal(int s, const void *data, size_t size, int flags, - const struct sockaddr *to, socklen_t tolen) -{ -#endif - struct lwip_sock *sock; - err_t err; - u16_t short_size; - u16_t remote_port; - struct netbuf buf; - - sock = get_socket(s); - if (!sock) { - return -1; - } - - if (NETCONNTYPE_GROUP(netconn_type(sock->conn)) == NETCONN_TCP) { -#if LWIP_TCP - done_socket(sock); - return lwip_send(s, data, size, flags); -#else /* LWIP_TCP */ - LWIP_UNUSED_ARG(flags); - sock_set_errno(sock, err_to_errno(ERR_ARG)); - done_socket(sock); - return -1; -#endif /* LWIP_TCP */ - } - - if (size > LWIP_MIN(0xFFFF, SSIZE_MAX)) { - /* cannot fit into one datagram (at least for us) */ - sock_set_errno(sock, EMSGSIZE); - done_socket(sock); - return -1; - } - short_size = (u16_t)size; - LWIP_ERROR("lwip_sendto: invalid address", (((to == NULL) && (tolen == 0)) || - (IS_SOCK_ADDR_LEN_VALID(tolen) && - ((to != NULL) && (IS_SOCK_ADDR_TYPE_VALID(to) && IS_SOCK_ADDR_ALIGNED(to))))), - sock_set_errno(sock, err_to_errno(ERR_ARG)); done_socket(sock); return -1;); - LWIP_UNUSED_ARG(tolen); - - /* initialize a buffer */ - buf.p = buf.ptr = NULL; -#if LWIP_CHECKSUM_ON_COPY - buf.flags = 0; -#endif /* LWIP_CHECKSUM_ON_COPY */ - if (to) { - SOCKADDR_TO_IPADDR_PORT(to, &buf.addr, remote_port); - } else { - remote_port = 0; - ip_addr_set_any(NETCONNTYPE_ISIPV6(netconn_type(sock->conn)), &buf.addr); - } - netbuf_fromport(&buf) = remote_port; - - - LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_sendto(%d, data=%p, short_size=%"U16_F", flags=0x%x to=", - s, data, short_size, flags)); - ip_addr_debug_print_val(SOCKETS_DEBUG, buf.addr); - LWIP_DEBUGF(SOCKETS_DEBUG, (" port=%"U16_F"\n", remote_port)); - - /* make the buffer point to the data that should be sent */ -#if LWIP_NETIF_TX_SINGLE_PBUF - /* Allocate a new netbuf and copy the data into it. */ - if (netbuf_alloc(&buf, short_size) == NULL) { - err = ERR_MEM; - } else { -#if LWIP_CHECKSUM_ON_COPY - if (NETCONNTYPE_GROUP(netconn_type(sock->conn)) != NETCONN_RAW) { - u16_t chksum = LWIP_CHKSUM_COPY(buf.p->payload, data, short_size); - netbuf_set_chksum(&buf, chksum); - } else -#endif /* LWIP_CHECKSUM_ON_COPY */ - { - MEMCPY(buf.p->payload, data, short_size); - } - err = ERR_OK; - } -#else /* LWIP_NETIF_TX_SINGLE_PBUF */ - err = netbuf_ref(&buf, data, short_size); -#endif /* LWIP_NETIF_TX_SINGLE_PBUF */ - if (err == ERR_OK) { -#if LWIP_IPV4 && LWIP_IPV6 - /* Dual-stack: Unmap IPv4 mapped IPv6 addresses */ - if (IP_IS_V6_VAL(buf.addr) && ip6_addr_isipv4mappedipv6(ip_2_ip6(&buf.addr))) { - unmap_ipv4_mapped_ipv6(ip_2_ip4(&buf.addr), ip_2_ip6(&buf.addr)); - IP_SET_TYPE_VAL(buf.addr, IPADDR_TYPE_V4); - } -#endif /* LWIP_IPV4 && LWIP_IPV6 */ - - /* send the data */ - err = netconn_send(sock->conn, &buf); - } - - /* deallocated the buffer */ - netbuf_free(&buf); - - sock_set_errno(sock, err_to_errno(err)); - done_socket(sock); - return (err == ERR_OK ? short_size : -1); -} - -int -lwip_socket(int domain, int type, int protocol) -{ - struct netconn *conn; - int i; - - LWIP_UNUSED_ARG(domain); /* @todo: check this */ - - /* create a netconn */ - switch (type) { - case SOCK_RAW: - conn = netconn_new_with_proto_and_callback(DOMAIN_TO_NETCONN_TYPE(domain, NETCONN_RAW), - (u8_t)protocol, DEFAULT_SOCKET_EVENTCB); - LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_socket(%s, SOCK_RAW, %d) = ", - domain == PF_INET ? "PF_INET" : "UNKNOWN", protocol)); - break; - case SOCK_DGRAM: - conn = netconn_new_with_callback(DOMAIN_TO_NETCONN_TYPE(domain, - ((protocol == IPPROTO_UDPLITE) ? NETCONN_UDPLITE : NETCONN_UDP)), - DEFAULT_SOCKET_EVENTCB); - LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_socket(%s, SOCK_DGRAM, %d) = ", - domain == PF_INET ? "PF_INET" : "UNKNOWN", protocol)); -#if LWIP_NETBUF_RECVINFO - if (conn) { - /* netconn layer enables pktinfo by default, sockets default to off */ - conn->flags &= ~NETCONN_FLAG_PKTINFO; - } -#endif /* LWIP_NETBUF_RECVINFO */ - break; - case SOCK_STREAM: - conn = netconn_new_with_callback(DOMAIN_TO_NETCONN_TYPE(domain, NETCONN_TCP), DEFAULT_SOCKET_EVENTCB); - LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_socket(%s, SOCK_STREAM, %d) = ", - domain == PF_INET ? "PF_INET" : "UNKNOWN", protocol)); - break; - default: - LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_socket(%d, %d/UNKNOWN, %d) = -1\n", - domain, type, protocol)); - set_errno(EINVAL); - return -1; - } - - if (!conn) { - LWIP_DEBUGF(SOCKETS_DEBUG, ("-1 / ENOBUFS (could not create netconn)\n")); - set_errno(ENOBUFS); - return -1; - } - - i = alloc_socket(conn, 0); - - if (i == -1) { - netconn_delete(conn); - set_errno(ENFILE); - return -1; - } - conn->socket = i; - done_socket(&sockets[i - LWIP_SOCKET_OFFSET]); - LWIP_DEBUGF(SOCKETS_DEBUG, ("%d\n", i)); - set_errno(0); - return i; -} - -ssize_t -lwip_write(int s, const void *data, size_t size) -{ - return lwip_send(s, data, size, 0); -} - -ssize_t -lwip_writev(int s, const struct iovec *iov, int iovcnt) -{ - struct msghdr msg; - - msg.msg_name = NULL; - msg.msg_namelen = 0; - /* Hack: we have to cast via number to cast from 'const' pointer to non-const. - Blame the opengroup standard for this inconsistency. */ - msg.msg_iov = LWIP_CONST_CAST(struct iovec *, iov); - msg.msg_iovlen = iovcnt; - msg.msg_control = NULL; - msg.msg_controllen = 0; - msg.msg_flags = 0; - return lwip_sendmsg(s, &msg, 0); -} - -#if LWIP_SOCKET_SELECT || LWIP_SOCKET_POLL -/* Add select_cb to select_cb_list. */ -static void -lwip_link_select_cb(struct lwip_select_cb *select_cb) -{ - LWIP_SOCKET_SELECT_DECL_PROTECT(lev); - - /* Protect the select_cb_list */ - LWIP_SOCKET_SELECT_PROTECT(lev); - - /* Put this select_cb on top of list */ - select_cb->next = select_cb_list; - if (select_cb_list != NULL) { - select_cb_list->prev = select_cb; - } - select_cb_list = select_cb; -#if !LWIP_TCPIP_CORE_LOCKING - /* Increasing this counter tells select_check_waiters that the list has changed. */ - select_cb_ctr++; -#endif - - /* Now we can safely unprotect */ - LWIP_SOCKET_SELECT_UNPROTECT(lev); -} - -/* Remove select_cb from select_cb_list. */ -static void -lwip_unlink_select_cb(struct lwip_select_cb *select_cb) -{ - LWIP_SOCKET_SELECT_DECL_PROTECT(lev); - - /* Take us off the list */ - LWIP_SOCKET_SELECT_PROTECT(lev); - if (select_cb->next != NULL) { - select_cb->next->prev = select_cb->prev; - } - if (select_cb_list == select_cb) { - LWIP_ASSERT("select_cb->prev == NULL", select_cb->prev == NULL); - select_cb_list = select_cb->next; - } else { - LWIP_ASSERT("select_cb->prev != NULL", select_cb->prev != NULL); - select_cb->prev->next = select_cb->next; - } -#if !LWIP_TCPIP_CORE_LOCKING - /* Increasing this counter tells select_check_waiters that the list has changed. */ - select_cb_ctr++; -#endif - LWIP_SOCKET_SELECT_UNPROTECT(lev); -} -#endif /* LWIP_SOCKET_SELECT || LWIP_SOCKET_POLL */ - -#if LWIP_SOCKET_SELECT -/** - * Go through the readset and writeset lists and see which socket of the sockets - * set in the sets has events. On return, readset, writeset and exceptset have - * the sockets enabled that had events. - * - * @param maxfdp1 the highest socket index in the sets - * @param readset_in set of sockets to check for read events - * @param writeset_in set of sockets to check for write events - * @param exceptset_in set of sockets to check for error events - * @param readset_out set of sockets that had read events - * @param writeset_out set of sockets that had write events - * @param exceptset_out set os sockets that had error events - * @return number of sockets that had events (read/write/exception) (>= 0) - */ -static int -lwip_selscan(int maxfdp1, fd_set *readset_in, fd_set *writeset_in, fd_set *exceptset_in, - fd_set *readset_out, fd_set *writeset_out, fd_set *exceptset_out) -{ - int i, nready = 0; - fd_set lreadset, lwriteset, lexceptset; - struct lwip_sock *sock; - SYS_ARCH_DECL_PROTECT(lev); - - FD_ZERO(&lreadset); - FD_ZERO(&lwriteset); - FD_ZERO(&lexceptset); - - /* Go through each socket in each list to count number of sockets which - currently match */ - for (i = LWIP_SOCKET_OFFSET; i < maxfdp1; i++) { - /* if this FD is not in the set, continue */ - if (!(readset_in && FD_ISSET(i, readset_in)) && - !(writeset_in && FD_ISSET(i, writeset_in)) && - !(exceptset_in && FD_ISSET(i, exceptset_in))) { - continue; - } - /* First get the socket's status (protected)... */ - SYS_ARCH_PROTECT(lev); - sock = tryget_socket_unconn_locked(i); - if (sock != NULL) { - void *lastdata = sock->lastdata.pbuf; - s16_t rcvevent = sock->rcvevent; - u16_t sendevent = sock->sendevent; - u16_t errevent = sock->errevent; - SYS_ARCH_UNPROTECT(lev); - - /* ... then examine it: */ - /* See if netconn of this socket is ready for read */ - if (readset_in && FD_ISSET(i, readset_in) && ((lastdata != NULL) || (rcvevent > 0))) { - FD_SET(i, &lreadset); - LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_selscan: fd=%d ready for reading\n", i)); - nready++; - } - /* See if netconn of this socket is ready for write */ - if (writeset_in && FD_ISSET(i, writeset_in) && (sendevent != 0)) { - FD_SET(i, &lwriteset); - LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_selscan: fd=%d ready for writing\n", i)); - nready++; - } - /* See if netconn of this socket had an error */ - if (exceptset_in && FD_ISSET(i, exceptset_in) && (errevent != 0)) { - FD_SET(i, &lexceptset); - LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_selscan: fd=%d ready for exception\n", i)); - nready++; - } - done_socket(sock); - } else { - SYS_ARCH_UNPROTECT(lev); - /* no a valid open socket */ - return -1; - } - } - /* copy local sets to the ones provided as arguments */ - *readset_out = lreadset; - *writeset_out = lwriteset; - *exceptset_out = lexceptset; - - LWIP_ASSERT("nready >= 0", nready >= 0); - return nready; -} - -#if LWIP_NETCONN_FULLDUPLEX -/* Mark all of the set sockets in one of the three fdsets passed to select as used. - * All sockets are marked (and later unmarked), whether they are open or not. - * This is OK as lwip_selscan aborts select when non-open sockets are found. - */ -static void -lwip_select_inc_sockets_used_set(int maxfdp, fd_set *fdset, fd_set *used_sockets) -{ - SYS_ARCH_DECL_PROTECT(lev); - if (fdset) { - int i; - for (i = LWIP_SOCKET_OFFSET; i < maxfdp; i++) { - /* if this FD is in the set, lock it (unless already done) */ - if (FD_ISSET(i, fdset) && !FD_ISSET(i, used_sockets)) { - struct lwip_sock *sock; - SYS_ARCH_PROTECT(lev); - sock = tryget_socket_unconn_locked(i); - if (sock != NULL) { - /* leave the socket used until released by lwip_select_dec_sockets_used */ - FD_SET(i, used_sockets); - } - SYS_ARCH_UNPROTECT(lev); - } - } - } -} - -/* Mark all sockets passed to select as used to prevent them from being freed - * from other threads while select is running. - * Marked sockets are added to 'used_sockets' to mark them only once an be able - * to unmark them correctly. - */ -static void -lwip_select_inc_sockets_used(int maxfdp, fd_set *fdset1, fd_set *fdset2, fd_set *fdset3, fd_set *used_sockets) -{ - FD_ZERO(used_sockets); - lwip_select_inc_sockets_used_set(maxfdp, fdset1, used_sockets); - lwip_select_inc_sockets_used_set(maxfdp, fdset2, used_sockets); - lwip_select_inc_sockets_used_set(maxfdp, fdset3, used_sockets); -} - -/* Let go all sockets that were marked as used when starting select */ -static void -lwip_select_dec_sockets_used(int maxfdp, fd_set *used_sockets) -{ - int i; - for (i = LWIP_SOCKET_OFFSET; i < maxfdp; i++) { - /* if this FD is not in the set, continue */ - if (FD_ISSET(i, used_sockets)) { - struct lwip_sock *sock = tryget_socket_unconn_nouse(i); - LWIP_ASSERT("socket gone at the end of select", sock != NULL); - if (sock != NULL) { - done_socket(sock); - } - } - } -} -#else /* LWIP_NETCONN_FULLDUPLEX */ -#define lwip_select_inc_sockets_used(maxfdp1, readset, writeset, exceptset, used_sockets) -#define lwip_select_dec_sockets_used(maxfdp1, used_sockets) -#endif /* LWIP_NETCONN_FULLDUPLEX */ - -int -lwip_select(int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset, - struct timeval *timeout) -{ - u32_t waitres = 0; - int nready; - fd_set lreadset, lwriteset, lexceptset; - u32_t msectimeout; - int i; - int maxfdp2; -#if LWIP_NETCONN_SEM_PER_THREAD - int waited = 0; -#endif -#if LWIP_NETCONN_FULLDUPLEX - fd_set used_sockets; -#endif - SYS_ARCH_DECL_PROTECT(lev); - - LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_select(%d, %p, %p, %p, tvsec=%"S32_F" tvusec=%"S32_F")\n", - maxfdp1, (void *)readset, (void *) writeset, (void *) exceptset, - timeout ? (s32_t)timeout->tv_sec : (s32_t) - 1, - timeout ? (s32_t)timeout->tv_usec : (s32_t) - 1)); - - if ((maxfdp1 < 0) || (maxfdp1 > LWIP_SELECT_MAXNFDS)) { - set_errno(EINVAL); - return -1; - } - - lwip_select_inc_sockets_used(maxfdp1, readset, writeset, exceptset, &used_sockets); - - /* Go through each socket in each list to count number of sockets which - currently match */ - nready = lwip_selscan(maxfdp1, readset, writeset, exceptset, &lreadset, &lwriteset, &lexceptset); - - if (nready < 0) { - /* one of the sockets in one of the fd_sets was invalid */ - set_errno(EBADF); - lwip_select_dec_sockets_used(maxfdp1, &used_sockets); - return -1; - } else if (nready > 0) { - /* one or more sockets are set, no need to wait */ - LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_select: nready=%d\n", nready)); - } else { - /* If we don't have any current events, then suspend if we are supposed to */ - if (timeout && timeout->tv_sec == 0 && timeout->tv_usec == 0) { - LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_select: no timeout, returning 0\n")); - /* This is OK as the local fdsets are empty and nready is zero, - or we would have returned earlier. */ - } else { - /* None ready: add our semaphore to list: - We don't actually need any dynamic memory. Our entry on the - list is only valid while we are in this function, so it's ok - to use local variables (unless we're running in MPU compatible - mode). */ - API_SELECT_CB_VAR_DECLARE(select_cb); - API_SELECT_CB_VAR_ALLOC(select_cb, set_errno(ENOMEM); lwip_select_dec_sockets_used(maxfdp1, &used_sockets); return -1); - memset(&API_SELECT_CB_VAR_REF(select_cb), 0, sizeof(struct lwip_select_cb)); - - API_SELECT_CB_VAR_REF(select_cb).readset = readset; - API_SELECT_CB_VAR_REF(select_cb).writeset = writeset; - API_SELECT_CB_VAR_REF(select_cb).exceptset = exceptset; -#if LWIP_NETCONN_SEM_PER_THREAD - API_SELECT_CB_VAR_REF(select_cb).sem = LWIP_NETCONN_THREAD_SEM_GET(); -#else /* LWIP_NETCONN_SEM_PER_THREAD */ - if (sys_sem_new(&API_SELECT_CB_VAR_REF(select_cb).sem, 0) != ERR_OK) { - /* failed to create semaphore */ - set_errno(ENOMEM); - lwip_select_dec_sockets_used(maxfdp1, &used_sockets); - API_SELECT_CB_VAR_FREE(select_cb); - return -1; - } -#endif /* LWIP_NETCONN_SEM_PER_THREAD */ - - lwip_link_select_cb(&API_SELECT_CB_VAR_REF(select_cb)); - - /* Increase select_waiting for each socket we are interested in */ - maxfdp2 = maxfdp1; - for (i = LWIP_SOCKET_OFFSET; i < maxfdp1; i++) { - if ((readset && FD_ISSET(i, readset)) || - (writeset && FD_ISSET(i, writeset)) || - (exceptset && FD_ISSET(i, exceptset))) { - struct lwip_sock *sock; - SYS_ARCH_PROTECT(lev); - sock = tryget_socket_unconn_locked(i); - if (sock != NULL) { - sock->select_waiting++; - if (sock->select_waiting == 0) { - /* overflow - too many threads waiting */ - sock->select_waiting--; - nready = -1; - maxfdp2 = i; - SYS_ARCH_UNPROTECT(lev); - done_socket(sock); - set_errno(EBUSY); - break; - } - SYS_ARCH_UNPROTECT(lev); - done_socket(sock); - } else { - /* Not a valid socket */ - nready = -1; - maxfdp2 = i; - SYS_ARCH_UNPROTECT(lev); - set_errno(EBADF); - break; - } - } - } - - if (nready >= 0) { - /* Call lwip_selscan again: there could have been events between - the last scan (without us on the list) and putting us on the list! */ - nready = lwip_selscan(maxfdp1, readset, writeset, exceptset, &lreadset, &lwriteset, &lexceptset); - if (!nready) { - /* Still none ready, just wait to be woken */ - if (timeout == 0) { - /* Wait forever */ - msectimeout = 0; - } else { - long msecs_long = ((timeout->tv_sec * 1000) + ((timeout->tv_usec + 500) / 1000)); - if (msecs_long <= 0) { - /* Wait 1ms at least (0 means wait forever) */ - msectimeout = 1; - } else { - msectimeout = (u32_t)msecs_long; - } - } - - waitres = sys_arch_sem_wait(SELECT_SEM_PTR(API_SELECT_CB_VAR_REF(select_cb).sem), msectimeout); -#if LWIP_NETCONN_SEM_PER_THREAD - waited = 1; -#endif - } - } - - /* Decrease select_waiting for each socket we are interested in */ - for (i = LWIP_SOCKET_OFFSET; i < maxfdp2; i++) { - if ((readset && FD_ISSET(i, readset)) || - (writeset && FD_ISSET(i, writeset)) || - (exceptset && FD_ISSET(i, exceptset))) { - struct lwip_sock *sock; - SYS_ARCH_PROTECT(lev); - sock = tryget_socket_unconn_locked(i); - if (sock != NULL) { - /* for now, handle select_waiting==0... */ - LWIP_ASSERT("sock->select_waiting > 0", sock->select_waiting > 0); - if (sock->select_waiting > 0) { - sock->select_waiting--; - } - SYS_ARCH_UNPROTECT(lev); - done_socket(sock); - } else { - SYS_ARCH_UNPROTECT(lev); - /* Not a valid socket */ - nready = -1; - set_errno(EBADF); - } - } - } - - lwip_unlink_select_cb(&API_SELECT_CB_VAR_REF(select_cb)); - -#if LWIP_NETCONN_SEM_PER_THREAD - if (API_SELECT_CB_VAR_REF(select_cb).sem_signalled && (!waited || (waitres == SYS_ARCH_TIMEOUT))) { - /* don't leave the thread-local semaphore signalled */ - sys_arch_sem_wait(API_SELECT_CB_VAR_REF(select_cb).sem, 1); - } -#else /* LWIP_NETCONN_SEM_PER_THREAD */ - sys_sem_free(&API_SELECT_CB_VAR_REF(select_cb).sem); -#endif /* LWIP_NETCONN_SEM_PER_THREAD */ - API_SELECT_CB_VAR_FREE(select_cb); - - if (nready < 0) { - /* This happens when a socket got closed while waiting */ - lwip_select_dec_sockets_used(maxfdp1, &used_sockets); - return -1; - } - - if (waitres == SYS_ARCH_TIMEOUT) { - /* Timeout */ - LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_select: timeout expired\n")); - /* This is OK as the local fdsets are empty and nready is zero, - or we would have returned earlier. */ - } else { - /* See what's set now after waiting */ - nready = lwip_selscan(maxfdp1, readset, writeset, exceptset, &lreadset, &lwriteset, &lexceptset); - LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_select: nready=%d\n", nready)); - } - } - } - - lwip_select_dec_sockets_used(maxfdp1, &used_sockets); - set_errno(0); - if (readset) { - *readset = lreadset; - } - if (writeset) { - *writeset = lwriteset; - } - if (exceptset) { - *exceptset = lexceptset; - } - return nready; -} -#endif /* LWIP_SOCKET_SELECT */ - -#if LWIP_SOCKET_POLL -/** Options for the lwip_pollscan function. */ -enum lwip_pollscan_opts -{ - /** Clear revents in each struct pollfd. */ - LWIP_POLLSCAN_CLEAR = 1, - - /** Increment select_waiting in each struct lwip_sock. */ - LWIP_POLLSCAN_INC_WAIT = 2, - - /** Decrement select_waiting in each struct lwip_sock. */ - LWIP_POLLSCAN_DEC_WAIT = 4 -}; - -/** - * Update revents in each struct pollfd. - * Optionally update select_waiting in struct lwip_sock. - * - * @param fds array of structures to update - * @param nfds number of structures in fds - * @param opts what to update and how - * @return number of structures that have revents != 0 - */ -static int -lwip_pollscan(struct pollfd *fds, nfds_t nfds, enum lwip_pollscan_opts opts) -{ - int nready = 0; - nfds_t fdi; - struct lwip_sock *sock; - SYS_ARCH_DECL_PROTECT(lev); - - /* Go through each struct pollfd in the array. */ - for (fdi = 0; fdi < nfds; fdi++) { - if ((opts & LWIP_POLLSCAN_CLEAR) != 0) { - fds[fdi].revents = 0; - } - - /* Negative fd means the caller wants us to ignore this struct. - POLLNVAL means we already detected that the fd is invalid; - if another thread has since opened a new socket with that fd, - we must not use that socket. */ - if (fds[fdi].fd >= 0 && (fds[fdi].revents & POLLNVAL) == 0) { - /* First get the socket's status (protected)... */ - SYS_ARCH_PROTECT(lev); - sock = tryget_socket_unconn_locked(fds[fdi].fd); - if (sock != NULL) { - void* lastdata = sock->lastdata.pbuf; - s16_t rcvevent = sock->rcvevent; - u16_t sendevent = sock->sendevent; - u16_t errevent = sock->errevent; - - if ((opts & LWIP_POLLSCAN_INC_WAIT) != 0) { - sock->select_waiting++; - if (sock->select_waiting == 0) { - /* overflow - too many threads waiting */ - sock->select_waiting--; - nready = -1; - SYS_ARCH_UNPROTECT(lev); - done_socket(sock); - break; - } - } else if ((opts & LWIP_POLLSCAN_DEC_WAIT) != 0) { - /* for now, handle select_waiting==0... */ - LWIP_ASSERT("sock->select_waiting > 0", sock->select_waiting > 0); - if (sock->select_waiting > 0) { - sock->select_waiting--; - } - } - SYS_ARCH_UNPROTECT(lev); - done_socket(sock); - - /* ... then examine it: */ - /* See if netconn of this socket is ready for read */ - if ((fds[fdi].events & POLLIN) != 0 && ((lastdata != NULL) || (rcvevent > 0))) { - fds[fdi].revents |= POLLIN; - LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_pollscan: fd=%d ready for reading\n", fds[fdi].fd)); - } - /* See if netconn of this socket is ready for write */ - if ((fds[fdi].events & POLLOUT) != 0 && (sendevent != 0)) { - fds[fdi].revents |= POLLOUT; - LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_pollscan: fd=%d ready for writing\n", fds[fdi].fd)); - } - /* See if netconn of this socket had an error */ - if (errevent != 0) { - /* POLLERR is output only. */ - fds[fdi].revents |= POLLERR; - LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_pollscan: fd=%d ready for exception\n", fds[fdi].fd)); - } - } else { - /* Not a valid socket */ - SYS_ARCH_UNPROTECT(lev); - /* POLLNVAL is output only. */ - fds[fdi].revents |= POLLNVAL; - return -1; - } - } - - /* Will return the number of structures that have events, - not the number of events. */ - if (fds[fdi].revents != 0) { - nready++; - } - } - - LWIP_ASSERT("nready >= 0", nready >= 0); - return nready; -} - -#if LWIP_NETCONN_FULLDUPLEX -/* Mark all sockets as used. - * - * All sockets are marked (and later unmarked), whether they are open or not. - * This is OK as lwip_pollscan aborts select when non-open sockets are found. - */ -static void -lwip_poll_inc_sockets_used(struct pollfd *fds, nfds_t nfds) -{ - nfds_t fdi; - - if(fds) { - /* Go through each struct pollfd in the array. */ - for (fdi = 0; fdi < nfds; fdi++) { - /* Increase the reference counter */ - tryget_socket_unconn(fds[fdi].fd); - } - } -} - -/* Let go all sockets that were marked as used when starting poll */ -static void -lwip_poll_dec_sockets_used(struct pollfd *fds, nfds_t nfds) -{ - nfds_t fdi; - - if(fds) { - /* Go through each struct pollfd in the array. */ - for (fdi = 0; fdi < nfds; fdi++) { - struct lwip_sock *sock = tryget_socket_unconn_nouse(fds[fdi].fd); - if (sock != NULL) { - done_socket(sock); - } - } - } -} -#else /* LWIP_NETCONN_FULLDUPLEX */ -#define lwip_poll_inc_sockets_used(fds, nfds) -#define lwip_poll_dec_sockets_used(fds, nfds) -#endif /* LWIP_NETCONN_FULLDUPLEX */ - -int -lwip_poll(struct pollfd *fds, nfds_t nfds, int timeout) -{ - u32_t waitres = 0; - int nready; - u32_t msectimeout; -#if LWIP_NETCONN_SEM_PER_THREAD - int waited = 0; -#endif - - LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_poll(%p, %d, %d)\n", - (void*)fds, (int)nfds, timeout)); - LWIP_ERROR("lwip_poll: invalid fds", ((fds != NULL && nfds > 0) || (fds == NULL && nfds == 0)), - set_errno(EINVAL); return -1;); - - lwip_poll_inc_sockets_used(fds, nfds); - - /* Go through each struct pollfd to count number of structures - which currently match */ - nready = lwip_pollscan(fds, nfds, LWIP_POLLSCAN_CLEAR); - - if (nready < 0) { - lwip_poll_dec_sockets_used(fds, nfds); - return -1; - } - - /* If we don't have any current events, then suspend if we are supposed to */ - if (!nready) { - API_SELECT_CB_VAR_DECLARE(select_cb); - - if (timeout == 0) { - LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_poll: no timeout, returning 0\n")); - goto return_success; - } - API_SELECT_CB_VAR_ALLOC(select_cb, set_errno(EAGAIN); lwip_poll_dec_sockets_used(fds, nfds); return -1); - memset(&API_SELECT_CB_VAR_REF(select_cb), 0, sizeof(struct lwip_select_cb)); - - /* None ready: add our semaphore to list: - We don't actually need any dynamic memory. Our entry on the - list is only valid while we are in this function, so it's ok - to use local variables. */ - - API_SELECT_CB_VAR_REF(select_cb).poll_fds = fds; - API_SELECT_CB_VAR_REF(select_cb).poll_nfds = nfds; -#if LWIP_NETCONN_SEM_PER_THREAD - API_SELECT_CB_VAR_REF(select_cb).sem = LWIP_NETCONN_THREAD_SEM_GET(); -#else /* LWIP_NETCONN_SEM_PER_THREAD */ - if (sys_sem_new(&API_SELECT_CB_VAR_REF(select_cb).sem, 0) != ERR_OK) { - /* failed to create semaphore */ - set_errno(EAGAIN); - lwip_poll_dec_sockets_used(fds, nfds); - API_SELECT_CB_VAR_FREE(select_cb); - return -1; - } -#endif /* LWIP_NETCONN_SEM_PER_THREAD */ - - lwip_link_select_cb(&API_SELECT_CB_VAR_REF(select_cb)); - - /* Increase select_waiting for each socket we are interested in. - Also, check for events again: there could have been events between - the last scan (without us on the list) and putting us on the list! */ - nready = lwip_pollscan(fds, nfds, LWIP_POLLSCAN_INC_WAIT); - - if (!nready) { - /* Still none ready, just wait to be woken */ - if (timeout < 0) { - /* Wait forever */ - msectimeout = 0; - } else { - /* timeout == 0 would have been handled earlier. */ - LWIP_ASSERT("timeout > 0", timeout > 0); - msectimeout = timeout; - } - waitres = sys_arch_sem_wait(SELECT_SEM_PTR(API_SELECT_CB_VAR_REF(select_cb).sem), msectimeout); -#if LWIP_NETCONN_SEM_PER_THREAD - waited = 1; -#endif - } - - /* Decrease select_waiting for each socket we are interested in, - and check which events occurred while we waited. */ - nready = lwip_pollscan(fds, nfds, LWIP_POLLSCAN_DEC_WAIT); - - lwip_unlink_select_cb(&API_SELECT_CB_VAR_REF(select_cb)); - -#if LWIP_NETCONN_SEM_PER_THREAD - if (select_cb.sem_signalled && (!waited || (waitres == SYS_ARCH_TIMEOUT))) { - /* don't leave the thread-local semaphore signalled */ - sys_arch_sem_wait(API_SELECT_CB_VAR_REF(select_cb).sem, 1); - } -#else /* LWIP_NETCONN_SEM_PER_THREAD */ - sys_sem_free(&API_SELECT_CB_VAR_REF(select_cb).sem); -#endif /* LWIP_NETCONN_SEM_PER_THREAD */ - API_SELECT_CB_VAR_FREE(select_cb); - - if (nready < 0) { - /* This happens when a socket got closed while waiting */ - lwip_poll_dec_sockets_used(fds, nfds); - return -1; - } - - if (waitres == SYS_ARCH_TIMEOUT) { - /* Timeout */ - LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_poll: timeout expired\n")); - goto return_success; - } - } - - LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_poll: nready=%d\n", nready)); -return_success: - lwip_poll_dec_sockets_used(fds, nfds); - set_errno(0); - return nready; -} - -/** - * Check whether event_callback should wake up a thread waiting in - * lwip_poll. - */ -static int -lwip_poll_should_wake(const struct lwip_select_cb *scb, int fd, int has_recvevent, int has_sendevent, int has_errevent) -{ - nfds_t fdi; - for (fdi = 0; fdi < scb->poll_nfds; fdi++) { - const struct pollfd *pollfd = &scb->poll_fds[fdi]; - if (pollfd->fd == fd) { - /* Do not update pollfd->revents right here; - that would be a data race because lwip_pollscan - accesses revents without protecting. */ - if (has_recvevent && (pollfd->events & POLLIN) != 0) { - return 1; - } - if (has_sendevent && (pollfd->events & POLLOUT) != 0) { - return 1; - } - if (has_errevent) { - /* POLLERR is output only. */ - return 1; - } - } - } - return 0; -} -#endif /* LWIP_SOCKET_POLL */ - -#if LWIP_SOCKET_SELECT || LWIP_SOCKET_POLL -/** - * Callback registered in the netconn layer for each socket-netconn. - * Processes recvevent (data available) and wakes up tasks waiting for select. - * - * @note for LWIP_TCPIP_CORE_LOCKING any caller of this function - * must have the core lock held when signaling the following events - * as they might cause select_list_cb to be checked: - * NETCONN_EVT_RCVPLUS - * NETCONN_EVT_SENDPLUS - * NETCONN_EVT_ERROR - * This requirement will be asserted in select_check_waiters() - */ -static void -event_callback(struct netconn *conn, enum netconn_evt evt, u16_t len) -{ - int s, check_waiters; - struct lwip_sock *sock; - SYS_ARCH_DECL_PROTECT(lev); - - LWIP_UNUSED_ARG(len); - - /* Get socket */ - if (conn) { - s = conn->socket; - if (s < 0) { - /* Data comes in right away after an accept, even though - * the server task might not have created a new socket yet. - * Just count down (or up) if that's the case and we - * will use the data later. Note that only receive events - * can happen before the new socket is set up. */ - SYS_ARCH_PROTECT(lev); - if (conn->socket < 0) { - if (evt == NETCONN_EVT_RCVPLUS) { - /* conn->socket is -1 on initialization - lwip_accept adjusts sock->recvevent if conn->socket < -1 */ - conn->socket--; - } - SYS_ARCH_UNPROTECT(lev); - return; - } - s = conn->socket; - SYS_ARCH_UNPROTECT(lev); - } - - sock = get_socket(s); - if (!sock) { - return; - } - } else { - return; - } - - check_waiters = 1; - SYS_ARCH_PROTECT(lev); - /* Set event as required */ - switch (evt) { - case NETCONN_EVT_RCVPLUS: - sock->rcvevent++; - if (sock->rcvevent > 1) { - check_waiters = 0; - } - break; - case NETCONN_EVT_RCVMINUS: - sock->rcvevent--; - check_waiters = 0; - break; - case NETCONN_EVT_SENDPLUS: - if (sock->sendevent) { - check_waiters = 0; - } - sock->sendevent = 1; - break; - case NETCONN_EVT_SENDMINUS: - sock->sendevent = 0; - check_waiters = 0; - break; - case NETCONN_EVT_ERROR: - sock->errevent = 1; - break; - default: - LWIP_ASSERT("unknown event", 0); - break; - } - - if (sock->select_waiting && check_waiters) { - /* Save which events are active */ - int has_recvevent, has_sendevent, has_errevent; - has_recvevent = sock->rcvevent > 0; - has_sendevent = sock->sendevent != 0; - has_errevent = sock->errevent != 0; - SYS_ARCH_UNPROTECT(lev); - /* Check any select calls waiting on this socket */ - select_check_waiters(s, has_recvevent, has_sendevent, has_errevent); - } else { - SYS_ARCH_UNPROTECT(lev); - } - // poll_check_waiters(s, check_waiters); - done_socket(sock); -} - -/** - * Check if any select waiters are waiting on this socket and its events - * - * @note on synchronization of select_cb_list: - * LWIP_TCPIP_CORE_LOCKING: the select_cb_list must only be accessed while holding - * the core lock. We do a single pass through the list and signal any waiters. - * Core lock should already be held when calling here!!!! - - * !LWIP_TCPIP_CORE_LOCKING: we use SYS_ARCH_PROTECT but unlock on each iteration - * of the loop, thus creating a possibility where a thread could modify the - * select_cb_list during our UNPROTECT/PROTECT. We use a generational counter to - * detect this change and restart the list walk. The list is expected to be small - */ -static void select_check_waiters(int s, int has_recvevent, int has_sendevent, int has_errevent) -{ - struct lwip_select_cb *scb; -#if !LWIP_TCPIP_CORE_LOCKING - int last_select_cb_ctr; - SYS_ARCH_DECL_PROTECT(lev); -#endif /* !LWIP_TCPIP_CORE_LOCKING */ - - LWIP_ASSERT_CORE_LOCKED(); - -#if !LWIP_TCPIP_CORE_LOCKING - SYS_ARCH_PROTECT(lev); -again: - /* remember the state of select_cb_list to detect changes */ - last_select_cb_ctr = select_cb_ctr; -#endif /* !LWIP_TCPIP_CORE_LOCKING */ - for (scb = select_cb_list; scb != NULL; scb = scb->next) { - if (scb->sem_signalled == 0) { - /* semaphore not signalled yet */ - int do_signal = 0; -#if LWIP_SOCKET_POLL - if (scb->poll_fds != NULL) { - do_signal = lwip_poll_should_wake(scb, s, has_recvevent, has_sendevent, has_errevent); - } -#endif /* LWIP_SOCKET_POLL */ -#if LWIP_SOCKET_SELECT && LWIP_SOCKET_POLL - else -#endif /* LWIP_SOCKET_SELECT && LWIP_SOCKET_POLL */ -#if LWIP_SOCKET_SELECT - { - /* Test this select call for our socket */ - if (has_recvevent) { - if (scb->readset && FD_ISSET(s, scb->readset)) { - do_signal = 1; - } - } - if (has_sendevent) { - if (!do_signal && scb->writeset && FD_ISSET(s, scb->writeset)) { - do_signal = 1; - } - } - if (has_errevent) { - if (!do_signal && scb->exceptset && FD_ISSET(s, scb->exceptset)) { - do_signal = 1; - } - } - } -#endif /* LWIP_SOCKET_SELECT */ - if (do_signal) { - scb->sem_signalled = 1; - /* For !LWIP_TCPIP_CORE_LOCKING, we don't call SYS_ARCH_UNPROTECT() before signaling - the semaphore, as this might lead to the select thread taking itself off the list, - invalidating the semaphore. */ - sys_sem_signal(SELECT_SEM_PTR(scb->sem)); - } - } -#if LWIP_TCPIP_CORE_LOCKING - } -#else - /* unlock interrupts with each step */ - SYS_ARCH_UNPROTECT(lev); - /* this makes sure interrupt protection time is short */ - SYS_ARCH_PROTECT(lev); - if (last_select_cb_ctr != select_cb_ctr) { - /* someone has changed select_cb_list, restart at the beginning */ - goto again; - } - /* remember the state of select_cb_list to detect changes */ - last_select_cb_ctr = select_cb_ctr; - } - SYS_ARCH_UNPROTECT(lev); -#endif -} -#endif /* LWIP_SOCKET_SELECT || LWIP_SOCKET_POLL */ - -/** - * Close one end of a full-duplex connection. - */ -int -lwip_shutdown(int s, int how) -{ - struct lwip_sock *sock; - err_t err; - u8_t shut_rx = 0, shut_tx = 0; - - LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_shutdown(%d, how=%d)\n", s, how)); - - sock = get_socket(s); - if (!sock) { - return -1; - } - - if (sock->conn != NULL) { - if (NETCONNTYPE_GROUP(netconn_type(sock->conn)) != NETCONN_TCP) { - sock_set_errno(sock, EOPNOTSUPP); - done_socket(sock); - return -1; - } - } else { - sock_set_errno(sock, ENOTCONN); - done_socket(sock); - return -1; - } - - if (how == SHUT_RD) { - shut_rx = 1; - } else if (how == SHUT_WR) { - shut_tx = 1; - } else if (how == SHUT_RDWR) { - shut_rx = 1; - shut_tx = 1; - } else { - sock_set_errno(sock, EINVAL); - done_socket(sock); - return -1; - } - err = netconn_shutdown(sock->conn, shut_rx, shut_tx); - - sock_set_errno(sock, err_to_errno(err)); - done_socket(sock); - return (err == ERR_OK ? 0 : -1); -} - -static int -lwip_getaddrname(int s, struct sockaddr *name, socklen_t *namelen, u8_t local) -{ - struct lwip_sock *sock; - union sockaddr_aligned saddr; - ip_addr_t naddr; - u16_t port; - err_t err; - - sock = get_socket(s); - if (!sock) { - return -1; - } - - /* get the IP address and port */ - err = netconn_getaddr(sock->conn, &naddr, &port, local); - if (err != ERR_OK) { - sock_set_errno(sock, err_to_errno(err)); - done_socket(sock); - return -1; - } - -#if LWIP_IPV4 && LWIP_IPV6 - /* Dual-stack: Map IPv4 addresses to IPv4 mapped IPv6 */ - if (NETCONNTYPE_ISIPV6(netconn_type(sock->conn)) && - IP_IS_V4_VAL(naddr)) { - ip4_2_ipv4_mapped_ipv6(ip_2_ip6(&naddr), ip_2_ip4(&naddr)); - IP_SET_TYPE_VAL(naddr, IPADDR_TYPE_V6); - } -#endif /* LWIP_IPV4 && LWIP_IPV6 */ - - IPADDR_PORT_TO_SOCKADDR(&saddr, &naddr, port); - - LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getaddrname(%d, addr=", s)); - ip_addr_debug_print_val(SOCKETS_DEBUG, naddr); - LWIP_DEBUGF(SOCKETS_DEBUG, (" port=%"U16_F")\n", port)); - - if (*namelen > saddr.sa.sa_len) { - *namelen = saddr.sa.sa_len; - } - MEMCPY(name, &saddr, *namelen); - - sock_set_errno(sock, 0); - done_socket(sock); - return 0; -} - -int -lwip_getpeername(int s, struct sockaddr *name, socklen_t *namelen) -{ - return lwip_getaddrname(s, name, namelen, 0); -} - -int -lwip_getsockname(int s, struct sockaddr *name, socklen_t *namelen) -{ - return lwip_getaddrname(s, name, namelen, 1); -} - -int -lwip_getsockopt(int s, int level, int optname, void *optval, socklen_t *optlen) -{ - int err; - struct lwip_sock *sock = get_socket(s); -#if !LWIP_TCPIP_CORE_LOCKING - err_t cberr; - LWIP_SETGETSOCKOPT_DATA_VAR_DECLARE(data); -#endif /* !LWIP_TCPIP_CORE_LOCKING */ - - if (!sock) { - return -1; - } - - if ((NULL == optval) || (NULL == optlen)) { - sock_set_errno(sock, EFAULT); - done_socket(sock); - return -1; - } - -#if LWIP_TCPIP_CORE_LOCKING - /* core-locking can just call the -impl function */ - LOCK_TCPIP_CORE(); - err = lwip_getsockopt_impl(s, level, optname, optval, optlen); - UNLOCK_TCPIP_CORE(); - -#else /* LWIP_TCPIP_CORE_LOCKING */ - -#if LWIP_MPU_COMPATIBLE - /* MPU_COMPATIBLE copies the optval data, so check for max size here */ - if (*optlen > LWIP_SETGETSOCKOPT_MAXOPTLEN) { - sock_set_errno(sock, ENOBUFS); - done_socket(sock); - return -1; - } -#endif /* LWIP_MPU_COMPATIBLE */ - - LWIP_SETGETSOCKOPT_DATA_VAR_ALLOC(data, sock); - LWIP_SETGETSOCKOPT_DATA_VAR_REF(data).s = s; - LWIP_SETGETSOCKOPT_DATA_VAR_REF(data).level = level; - LWIP_SETGETSOCKOPT_DATA_VAR_REF(data).optname = optname; - LWIP_SETGETSOCKOPT_DATA_VAR_REF(data).optlen = *optlen; -#if !LWIP_MPU_COMPATIBLE - LWIP_SETGETSOCKOPT_DATA_VAR_REF(data).optval.p = optval; -#endif /* !LWIP_MPU_COMPATIBLE */ - LWIP_SETGETSOCKOPT_DATA_VAR_REF(data).err = 0; -#if LWIP_NETCONN_SEM_PER_THREAD - LWIP_SETGETSOCKOPT_DATA_VAR_REF(data).completed_sem = LWIP_NETCONN_THREAD_SEM_GET(); -#else - LWIP_SETGETSOCKOPT_DATA_VAR_REF(data).completed_sem = &sock->conn->op_completed; -#endif - cberr = tcpip_callback(lwip_getsockopt_callback, &LWIP_SETGETSOCKOPT_DATA_VAR_REF(data)); - if (cberr != ERR_OK) { - LWIP_SETGETSOCKOPT_DATA_VAR_FREE(data); - sock_set_errno(sock, err_to_errno(cberr)); - done_socket(sock); - return -1; - } - sys_arch_sem_wait((sys_sem_t *)(LWIP_SETGETSOCKOPT_DATA_VAR_REF(data).completed_sem), 0); - - /* write back optlen and optval */ - *optlen = LWIP_SETGETSOCKOPT_DATA_VAR_REF(data).optlen; -#if LWIP_MPU_COMPATIBLE - MEMCPY(optval, LWIP_SETGETSOCKOPT_DATA_VAR_REF(data).optval, - LWIP_SETGETSOCKOPT_DATA_VAR_REF(data).optlen); -#endif /* LWIP_MPU_COMPATIBLE */ - - /* maybe lwip_getsockopt_internal has changed err */ - err = LWIP_SETGETSOCKOPT_DATA_VAR_REF(data).err; - LWIP_SETGETSOCKOPT_DATA_VAR_FREE(data); -#endif /* LWIP_TCPIP_CORE_LOCKING */ - - sock_set_errno(sock, err); - done_socket(sock); - return err ? -1 : 0; -} - -#if !LWIP_TCPIP_CORE_LOCKING -/** lwip_getsockopt_callback: only used without CORE_LOCKING - * to get into the tcpip_thread - */ -static void -lwip_getsockopt_callback(void *arg) -{ - struct lwip_setgetsockopt_data *data; - LWIP_ASSERT("arg != NULL", arg != NULL); - data = (struct lwip_setgetsockopt_data *)arg; - - data->err = lwip_getsockopt_impl(data->s, data->level, data->optname, -#if LWIP_MPU_COMPATIBLE - data->optval, -#else /* LWIP_MPU_COMPATIBLE */ - data->optval.p, -#endif /* LWIP_MPU_COMPATIBLE */ - &data->optlen); - - sys_sem_signal((sys_sem_t *)(data->completed_sem)); -} -#endif /* LWIP_TCPIP_CORE_LOCKING */ - -static int -lwip_sockopt_to_ipopt(int optname) -{ - /* Map SO_* values to our internal SOF_* values - * We should not rely on #defines in socket.h - * being in sync with ip.h. - */ - switch (optname) { - case SO_BROADCAST: - return SOF_BROADCAST; - case SO_KEEPALIVE: - return SOF_KEEPALIVE; - case SO_REUSEADDR: - return SOF_REUSEADDR; - default: - LWIP_ASSERT("Unknown socket option", 0); - return 0; - } -} - -/** lwip_getsockopt_impl: the actual implementation of getsockopt: - * same argument as lwip_getsockopt, either called directly or through callback - */ -static int -lwip_getsockopt_impl(int s, int level, int optname, void *optval, socklen_t *optlen) -{ - int err = 0; - struct lwip_sock *sock = tryget_socket(s); - if (!sock) { - return EBADF; - } - -#ifdef LWIP_HOOK_SOCKETS_GETSOCKOPT - if (LWIP_HOOK_SOCKETS_GETSOCKOPT(s, sock, level, optname, optval, optlen, &err)) { - return err; - } -#endif - - switch (level) { - - /* Level: SOL_SOCKET */ - case SOL_SOCKET: - switch (optname) { - -#if LWIP_TCP - case SO_ACCEPTCONN: - LWIP_SOCKOPT_CHECK_OPTLEN_CONN_PCB(sock, *optlen, int); - if (NETCONNTYPE_GROUP(sock->conn->type) != NETCONN_TCP) { - done_socket(sock); - return ENOPROTOOPT; - } - if ((sock->conn->pcb.tcp != NULL) && (sock->conn->pcb.tcp->state == LISTEN)) { - *(int *)optval = 1; - } else { - *(int *)optval = 0; - } - break; -#endif /* LWIP_TCP */ - - /* The option flags */ - case SO_BROADCAST: - case SO_KEEPALIVE: -#if SO_REUSE - case SO_REUSEADDR: -#endif /* SO_REUSE */ - if ((optname == SO_BROADCAST) && - (NETCONNTYPE_GROUP(sock->conn->type) != NETCONN_UDP)) { - done_socket(sock); - return ENOPROTOOPT; - } - - optname = lwip_sockopt_to_ipopt(optname); - - LWIP_SOCKOPT_CHECK_OPTLEN_CONN_PCB(sock, *optlen, int); - *(int *)optval = ip_get_option(sock->conn->pcb.ip, optname); - LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, SOL_SOCKET, optname=0x%x, ..) = %s\n", - s, optname, (*(int *)optval ? "on" : "off"))); - break; - - case SO_TYPE: - LWIP_SOCKOPT_CHECK_OPTLEN_CONN(sock, *optlen, int); - switch (NETCONNTYPE_GROUP(netconn_type(sock->conn))) { - case NETCONN_RAW: - *(int *)optval = SOCK_RAW; - break; - case NETCONN_TCP: - *(int *)optval = SOCK_STREAM; - break; - case NETCONN_UDP: - *(int *)optval = SOCK_DGRAM; - break; - default: /* unrecognized socket type */ - *(int *)optval = netconn_type(sock->conn); - LWIP_DEBUGF(SOCKETS_DEBUG, - ("lwip_getsockopt(%d, SOL_SOCKET, SO_TYPE): unrecognized socket type %d\n", - s, *(int *)optval)); - } /* switch (netconn_type(sock->conn)) */ - LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, SOL_SOCKET, SO_TYPE) = %d\n", - s, *(int *)optval)); - break; - - case SO_ERROR: - LWIP_SOCKOPT_CHECK_OPTLEN(sock, *optlen, int); - *(int *)optval = err_to_errno(netconn_err(sock->conn)); - LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, SOL_SOCKET, SO_ERROR) = %d\n", - s, *(int *)optval)); - break; - -#if LWIP_SO_SNDTIMEO - case SO_SNDTIMEO: - LWIP_SOCKOPT_CHECK_OPTLEN_CONN(sock, *optlen, LWIP_SO_SNDRCVTIMEO_OPTTYPE); - LWIP_SO_SNDRCVTIMEO_SET(optval, netconn_get_sendtimeout(sock->conn)); - break; -#endif /* LWIP_SO_SNDTIMEO */ -#if LWIP_SO_RCVTIMEO - case SO_RCVTIMEO: - LWIP_SOCKOPT_CHECK_OPTLEN_CONN(sock, *optlen, LWIP_SO_SNDRCVTIMEO_OPTTYPE); - LWIP_SO_SNDRCVTIMEO_SET(optval, netconn_get_recvtimeout(sock->conn)); - break; -#endif /* LWIP_SO_RCVTIMEO */ -#if LWIP_SO_RCVBUF - case SO_RCVBUF: - LWIP_SOCKOPT_CHECK_OPTLEN_CONN(sock, *optlen, int); - *(int *)optval = netconn_get_recvbufsize(sock->conn); - break; -#endif /* LWIP_SO_RCVBUF */ -#if LWIP_SO_LINGER - case SO_LINGER: { - s16_t conn_linger; - struct linger *linger = (struct linger *)optval; - LWIP_SOCKOPT_CHECK_OPTLEN_CONN(sock, *optlen, struct linger); - conn_linger = sock->conn->linger; - if (conn_linger >= 0) { - linger->l_onoff = 1; - linger->l_linger = (int)conn_linger; - } else { - linger->l_onoff = 0; - linger->l_linger = 0; - } - } - break; -#endif /* LWIP_SO_LINGER */ -#if LWIP_UDP - case SO_NO_CHECK: - LWIP_SOCKOPT_CHECK_OPTLEN_CONN_PCB_TYPE(sock, *optlen, int, NETCONN_UDP); -#if LWIP_UDPLITE - if (udp_is_flag_set(sock->conn->pcb.udp, UDP_FLAGS_UDPLITE)) { - /* this flag is only available for UDP, not for UDP lite */ - done_socket(sock); - return EAFNOSUPPORT; - } -#endif /* LWIP_UDPLITE */ - *(int *)optval = udp_is_flag_set(sock->conn->pcb.udp, UDP_FLAGS_NOCHKSUM) ? 1 : 0; - break; -#endif /* LWIP_UDP*/ - default: - LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, SOL_SOCKET, UNIMPL: optname=0x%x, ..)\n", - s, optname)); - err = ENOPROTOOPT; - break; - } /* switch (optname) */ - break; - - /* Level: IPPROTO_IP */ - case IPPROTO_IP: - switch (optname) { - case IP_TTL: - LWIP_SOCKOPT_CHECK_OPTLEN_CONN_PCB(sock, *optlen, int); - *(int *)optval = sock->conn->pcb.ip->ttl; - LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, IPPROTO_IP, IP_TTL) = %d\n", - s, *(int *)optval)); - break; - case IP_TOS: - LWIP_SOCKOPT_CHECK_OPTLEN_CONN_PCB(sock, *optlen, int); - *(int *)optval = sock->conn->pcb.ip->tos; - LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, IPPROTO_IP, IP_TOS) = %d\n", - s, *(int *)optval)); - break; -#if LWIP_IPV4 && LWIP_MULTICAST_TX_OPTIONS && LWIP_UDP - case IP_MULTICAST_TTL: - LWIP_SOCKOPT_CHECK_OPTLEN_CONN_PCB(sock, *optlen, u8_t); - if (NETCONNTYPE_GROUP(netconn_type(sock->conn)) != NETCONN_UDP) { - done_socket(sock); - return ENOPROTOOPT; - } - *(u8_t *)optval = udp_get_multicast_ttl(sock->conn->pcb.udp); - LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, IPPROTO_IP, IP_MULTICAST_TTL) = %d\n", - s, *(int *)optval)); - break; - case IP_MULTICAST_IF: - LWIP_SOCKOPT_CHECK_OPTLEN_CONN_PCB(sock, *optlen, struct in_addr); - if (NETCONNTYPE_GROUP(netconn_type(sock->conn)) != NETCONN_UDP) { - done_socket(sock); - return ENOPROTOOPT; - } - inet_addr_from_ip4addr((struct in_addr *)optval, udp_get_multicast_netif_addr(sock->conn->pcb.udp)); - LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, IPPROTO_IP, IP_MULTICAST_IF) = 0x%"X32_F"\n", - s, *(u32_t *)optval)); - break; - case IP_MULTICAST_LOOP: - LWIP_SOCKOPT_CHECK_OPTLEN_CONN_PCB(sock, *optlen, u8_t); - if ((sock->conn->pcb.udp->flags & UDP_FLAGS_MULTICAST_LOOP) != 0) { - *(u8_t *)optval = 1; - } else { - *(u8_t *)optval = 0; - } - LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, IPPROTO_IP, IP_MULTICAST_LOOP) = %d\n", - s, *(int *)optval)); - break; -#endif /* LWIP_IPV4 && LWIP_MULTICAST_TX_OPTIONS && LWIP_UDP */ - default: - LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, IPPROTO_IP, UNIMPL: optname=0x%x, ..)\n", - s, optname)); - err = ENOPROTOOPT; - break; - } /* switch (optname) */ - break; - -#if LWIP_TCP - /* Level: IPPROTO_TCP */ - case IPPROTO_TCP: - /* Special case: all IPPROTO_TCP option take an int */ - LWIP_SOCKOPT_CHECK_OPTLEN_CONN_PCB_TYPE(sock, *optlen, int, NETCONN_TCP); - if (sock->conn->pcb.tcp->state == LISTEN) { - done_socket(sock); - return EINVAL; - } - switch (optname) { - case TCP_NODELAY: - *(int *)optval = tcp_nagle_disabled(sock->conn->pcb.tcp); - LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, IPPROTO_TCP, TCP_NODELAY) = %s\n", - s, (*(int *)optval) ? "on" : "off") ); - break; - case TCP_KEEPALIVE: - *(int *)optval = (int)sock->conn->pcb.tcp->keep_idle; - LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, IPPROTO_TCP, TCP_KEEPALIVE) = %d\n", - s, *(int *)optval)); - break; - -#if LWIP_TCP_KEEPALIVE - case TCP_KEEPIDLE: - *(int *)optval = (int)(sock->conn->pcb.tcp->keep_idle / 1000); - LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, IPPROTO_TCP, TCP_KEEPIDLE) = %d\n", - s, *(int *)optval)); - break; - case TCP_KEEPINTVL: - *(int *)optval = (int)(sock->conn->pcb.tcp->keep_intvl / 1000); - LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, IPPROTO_TCP, TCP_KEEPINTVL) = %d\n", - s, *(int *)optval)); - break; - case TCP_KEEPCNT: - *(int *)optval = (int)sock->conn->pcb.tcp->keep_cnt; - LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, IPPROTO_TCP, TCP_KEEPCNT) = %d\n", - s, *(int *)optval)); - break; -#endif /* LWIP_TCP_KEEPALIVE */ - default: - LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, IPPROTO_TCP, UNIMPL: optname=0x%x, ..)\n", - s, optname)); - err = ENOPROTOOPT; - break; - } /* switch (optname) */ - break; -#endif /* LWIP_TCP */ - -#if LWIP_IPV6 - /* Level: IPPROTO_IPV6 */ - case IPPROTO_IPV6: - switch (optname) { - case IPV6_V6ONLY: - LWIP_SOCKOPT_CHECK_OPTLEN_CONN(sock, *optlen, int); - *(int *)optval = (netconn_get_ipv6only(sock->conn) ? 1 : 0); - LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, IPPROTO_IPV6, IPV6_V6ONLY) = %d\n", - s, *(int *)optval)); - break; - default: - LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, IPPROTO_IPV6, UNIMPL: optname=0x%x, ..)\n", - s, optname)); - err = ENOPROTOOPT; - break; - } /* switch (optname) */ - break; -#endif /* LWIP_IPV6 */ - -#if LWIP_UDP && LWIP_UDPLITE - /* Level: IPPROTO_UDPLITE */ - case IPPROTO_UDPLITE: - /* Special case: all IPPROTO_UDPLITE option take an int */ - LWIP_SOCKOPT_CHECK_OPTLEN_CONN_PCB(sock, *optlen, int); - /* If this is no UDP lite socket, ignore any options. */ - if (!NETCONNTYPE_ISUDPLITE(netconn_type(sock->conn))) { - done_socket(sock); - return ENOPROTOOPT; - } - switch (optname) { - case UDPLITE_SEND_CSCOV: - *(int *)optval = sock->conn->pcb.udp->chksum_len_tx; - LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, IPPROTO_UDPLITE, UDPLITE_SEND_CSCOV) = %d\n", - s, (*(int *)optval)) ); - break; - case UDPLITE_RECV_CSCOV: - *(int *)optval = sock->conn->pcb.udp->chksum_len_rx; - LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, IPPROTO_UDPLITE, UDPLITE_RECV_CSCOV) = %d\n", - s, (*(int *)optval)) ); - break; - default: - LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, IPPROTO_UDPLITE, UNIMPL: optname=0x%x, ..)\n", - s, optname)); - err = ENOPROTOOPT; - break; - } /* switch (optname) */ - break; -#endif /* LWIP_UDP */ - /* Level: IPPROTO_RAW */ - case IPPROTO_RAW: - switch (optname) { -#if LWIP_IPV6 && LWIP_RAW - case IPV6_CHECKSUM: - LWIP_SOCKOPT_CHECK_OPTLEN_CONN_PCB_TYPE(sock, *optlen, int, NETCONN_RAW); - if (sock->conn->pcb.raw->chksum_reqd == 0) { - *(int *)optval = -1; - } else { - *(int *)optval = sock->conn->pcb.raw->chksum_offset; - } - LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, IPPROTO_RAW, IPV6_CHECKSUM) = %d\n", - s, (*(int *)optval)) ); - break; -#endif /* LWIP_IPV6 && LWIP_RAW */ - default: - LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, IPPROTO_RAW, UNIMPL: optname=0x%x, ..)\n", - s, optname)); - err = ENOPROTOOPT; - break; - } /* switch (optname) */ - break; - default: - LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_getsockopt(%d, level=0x%x, UNIMPL: optname=0x%x, ..)\n", - s, level, optname)); - err = ENOPROTOOPT; - break; - } /* switch (level) */ - - done_socket(sock); - return err; -} - -int -lwip_setsockopt(int s, int level, int optname, const void *optval, socklen_t optlen) -{ - int err = 0; - struct lwip_sock *sock = get_socket(s); -#if !LWIP_TCPIP_CORE_LOCKING - err_t cberr; - LWIP_SETGETSOCKOPT_DATA_VAR_DECLARE(data); -#endif /* !LWIP_TCPIP_CORE_LOCKING */ - - if (!sock) { - return -1; - } - - if (NULL == optval) { - sock_set_errno(sock, EFAULT); - done_socket(sock); - return -1; - } - -#if LWIP_TCPIP_CORE_LOCKING - /* core-locking can just call the -impl function */ - LOCK_TCPIP_CORE(); - err = lwip_setsockopt_impl(s, level, optname, optval, optlen); - UNLOCK_TCPIP_CORE(); - -#else /* LWIP_TCPIP_CORE_LOCKING */ - -#if LWIP_MPU_COMPATIBLE - /* MPU_COMPATIBLE copies the optval data, so check for max size here */ - if (optlen > LWIP_SETGETSOCKOPT_MAXOPTLEN) { - sock_set_errno(sock, ENOBUFS); - done_socket(sock); - return -1; - } -#endif /* LWIP_MPU_COMPATIBLE */ - - LWIP_SETGETSOCKOPT_DATA_VAR_ALLOC(data, sock); - LWIP_SETGETSOCKOPT_DATA_VAR_REF(data).s = s; - LWIP_SETGETSOCKOPT_DATA_VAR_REF(data).level = level; - LWIP_SETGETSOCKOPT_DATA_VAR_REF(data).optname = optname; - LWIP_SETGETSOCKOPT_DATA_VAR_REF(data).optlen = optlen; -#if LWIP_MPU_COMPATIBLE - MEMCPY(LWIP_SETGETSOCKOPT_DATA_VAR_REF(data).optval, optval, optlen); -#else /* LWIP_MPU_COMPATIBLE */ - LWIP_SETGETSOCKOPT_DATA_VAR_REF(data).optval.pc = (const void *)optval; -#endif /* LWIP_MPU_COMPATIBLE */ - LWIP_SETGETSOCKOPT_DATA_VAR_REF(data).err = 0; -#if LWIP_NETCONN_SEM_PER_THREAD - LWIP_SETGETSOCKOPT_DATA_VAR_REF(data).completed_sem = LWIP_NETCONN_THREAD_SEM_GET(); -#else - LWIP_SETGETSOCKOPT_DATA_VAR_REF(data).completed_sem = &sock->conn->op_completed; -#endif - cberr = tcpip_callback(lwip_setsockopt_callback, &LWIP_SETGETSOCKOPT_DATA_VAR_REF(data)); - if (cberr != ERR_OK) { - LWIP_SETGETSOCKOPT_DATA_VAR_FREE(data); - sock_set_errno(sock, err_to_errno(cberr)); - done_socket(sock); - return -1; - } - sys_arch_sem_wait((sys_sem_t *)(LWIP_SETGETSOCKOPT_DATA_VAR_REF(data).completed_sem), 0); - - /* maybe lwip_getsockopt_internal has changed err */ - err = LWIP_SETGETSOCKOPT_DATA_VAR_REF(data).err; - LWIP_SETGETSOCKOPT_DATA_VAR_FREE(data); -#endif /* LWIP_TCPIP_CORE_LOCKING */ - - sock_set_errno(sock, err); - done_socket(sock); - return err ? -1 : 0; -} - -#if !LWIP_TCPIP_CORE_LOCKING -/** lwip_setsockopt_callback: only used without CORE_LOCKING - * to get into the tcpip_thread - */ -static void -lwip_setsockopt_callback(void *arg) -{ - struct lwip_setgetsockopt_data *data; - LWIP_ASSERT("arg != NULL", arg != NULL); - data = (struct lwip_setgetsockopt_data *)arg; - - data->err = lwip_setsockopt_impl(data->s, data->level, data->optname, -#if LWIP_MPU_COMPATIBLE - data->optval, -#else /* LWIP_MPU_COMPATIBLE */ - data->optval.pc, -#endif /* LWIP_MPU_COMPATIBLE */ - data->optlen); - - sys_sem_signal((sys_sem_t *)(data->completed_sem)); -} -#endif /* LWIP_TCPIP_CORE_LOCKING */ - -/** lwip_setsockopt_impl: the actual implementation of setsockopt: - * same argument as lwip_setsockopt, either called directly or through callback - */ -static int -lwip_setsockopt_impl(int s, int level, int optname, const void *optval, socklen_t optlen) -{ - int err = 0; - struct lwip_sock *sock = tryget_socket(s); - if (!sock) { - return EBADF; - } - -#ifdef LWIP_HOOK_SOCKETS_SETSOCKOPT - if (LWIP_HOOK_SOCKETS_SETSOCKOPT(s, sock, level, optname, optval, optlen, &err)) { - return err; - } -#endif - - switch (level) { - - /* Level: SOL_SOCKET */ - case SOL_SOCKET: - switch (optname) { - - /* SO_ACCEPTCONN is get-only */ - - /* The option flags */ - case SO_BROADCAST: - case SO_KEEPALIVE: -#if SO_REUSE - case SO_REUSEADDR: -#endif /* SO_REUSE */ - if ((optname == SO_BROADCAST) && - (NETCONNTYPE_GROUP(sock->conn->type) != NETCONN_UDP)) { - done_socket(sock); - return ENOPROTOOPT; - } - - optname = lwip_sockopt_to_ipopt(optname); - - LWIP_SOCKOPT_CHECK_OPTLEN_CONN_PCB(sock, optlen, int); - if (*(const int *)optval) { - ip_set_option(sock->conn->pcb.ip, optname); - } else { - ip_reset_option(sock->conn->pcb.ip, optname); - } - LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_setsockopt(%d, SOL_SOCKET, optname=0x%x, ..) -> %s\n", - s, optname, (*(const int *)optval ? "on" : "off"))); - break; - - /* SO_TYPE is get-only */ - /* SO_ERROR is get-only */ - -#if LWIP_SO_SNDTIMEO - case SO_SNDTIMEO: { - long ms_long; - LWIP_SOCKOPT_CHECK_OPTLEN_CONN(sock, optlen, LWIP_SO_SNDRCVTIMEO_OPTTYPE); - ms_long = LWIP_SO_SNDRCVTIMEO_GET_MS(optval); - if (ms_long < 0) { - done_socket(sock); - return EINVAL; - } - netconn_set_sendtimeout(sock->conn, ms_long); - break; - } -#endif /* LWIP_SO_SNDTIMEO */ -#if LWIP_SO_RCVTIMEO - case SO_RCVTIMEO: { - long ms_long; - LWIP_SOCKOPT_CHECK_OPTLEN_CONN(sock, optlen, LWIP_SO_SNDRCVTIMEO_OPTTYPE); - ms_long = LWIP_SO_SNDRCVTIMEO_GET_MS(optval); - if (ms_long < 0) { - done_socket(sock); - return EINVAL; - } - netconn_set_recvtimeout(sock->conn, (u32_t)ms_long); - break; - } -#endif /* LWIP_SO_RCVTIMEO */ -#if LWIP_SO_RCVBUF - case SO_RCVBUF: - LWIP_SOCKOPT_CHECK_OPTLEN_CONN(sock, optlen, int); - netconn_set_recvbufsize(sock->conn, *(const int *)optval); - break; -#endif /* LWIP_SO_RCVBUF */ -#if LWIP_SO_LINGER - case SO_LINGER: { - const struct linger *linger = (const struct linger *)optval; - LWIP_SOCKOPT_CHECK_OPTLEN_CONN(sock, optlen, struct linger); - if (linger->l_onoff) { - int lingersec = linger->l_linger; - if (lingersec < 0) { - done_socket(sock); - return EINVAL; - } - if (lingersec > 0xFFFF) { - lingersec = 0xFFFF; - } - sock->conn->linger = (s16_t)lingersec; - } else { - sock->conn->linger = -1; - } - } - break; -#endif /* LWIP_SO_LINGER */ -#if LWIP_UDP - case SO_NO_CHECK: - LWIP_SOCKOPT_CHECK_OPTLEN_CONN_PCB_TYPE(sock, optlen, int, NETCONN_UDP); -#if LWIP_UDPLITE - if (udp_is_flag_set(sock->conn->pcb.udp, UDP_FLAGS_UDPLITE)) { - /* this flag is only available for UDP, not for UDP lite */ - done_socket(sock); - return EAFNOSUPPORT; - } -#endif /* LWIP_UDPLITE */ - if (*(const int *)optval) { - udp_set_flags(sock->conn->pcb.udp, UDP_FLAGS_NOCHKSUM); - } else { - udp_clear_flags(sock->conn->pcb.udp, UDP_FLAGS_NOCHKSUM); - } - break; -#endif /* LWIP_UDP */ - case SO_BINDTODEVICE: { - const struct ifreq *iface; - struct netif *n = NULL; - - LWIP_SOCKOPT_CHECK_OPTLEN_CONN(sock, optlen, struct ifreq); - - iface = (const struct ifreq *)optval; - if (iface->ifr_name[0] != 0) { - n = netif_find(iface->ifr_name); - if (n == NULL) { - done_socket(sock); - return ENODEV; - } - } - - switch (NETCONNTYPE_GROUP(netconn_type(sock->conn))) { -#if LWIP_TCP - case NETCONN_TCP: - tcp_bind_netif(sock->conn->pcb.tcp, n); - break; -#endif -#if LWIP_UDP - case NETCONN_UDP: - udp_bind_netif(sock->conn->pcb.udp, n); - break; -#endif -#if LWIP_RAW - case NETCONN_RAW: - raw_bind_netif(sock->conn->pcb.raw, n); - break; -#endif - default: - LWIP_ASSERT("Unhandled netconn type in SO_BINDTODEVICE", 0); - break; - } - } - break; - default: - LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_setsockopt(%d, SOL_SOCKET, UNIMPL: optname=0x%x, ..)\n", - s, optname)); - err = ENOPROTOOPT; - break; - } /* switch (optname) */ - break; - - /* Level: IPPROTO_IP */ - case IPPROTO_IP: - switch (optname) { - case IP_TTL: - LWIP_SOCKOPT_CHECK_OPTLEN_CONN_PCB(sock, optlen, int); - sock->conn->pcb.ip->ttl = (u8_t)(*(const int *)optval); - LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_setsockopt(%d, IPPROTO_IP, IP_TTL, ..) -> %d\n", - s, sock->conn->pcb.ip->ttl)); - break; - case IP_TOS: - LWIP_SOCKOPT_CHECK_OPTLEN_CONN_PCB(sock, optlen, int); - sock->conn->pcb.ip->tos = (u8_t)(*(const int *)optval); - LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_setsockopt(%d, IPPROTO_IP, IP_TOS, ..)-> %d\n", - s, sock->conn->pcb.ip->tos)); - break; -#if LWIP_NETBUF_RECVINFO - case IP_PKTINFO: - LWIP_SOCKOPT_CHECK_OPTLEN_CONN_PCB_TYPE(sock, optlen, int, NETCONN_UDP); - if (*(const int *)optval) { - sock->conn->flags |= NETCONN_FLAG_PKTINFO; - } else { - sock->conn->flags &= ~NETCONN_FLAG_PKTINFO; - } - break; -#endif /* LWIP_NETBUF_RECVINFO */ -#if LWIP_IPV4 && LWIP_MULTICAST_TX_OPTIONS && LWIP_UDP - case IP_MULTICAST_TTL: - LWIP_SOCKOPT_CHECK_OPTLEN_CONN_PCB_TYPE(sock, optlen, u8_t, NETCONN_UDP); - udp_set_multicast_ttl(sock->conn->pcb.udp, (u8_t)(*(const u8_t *)optval)); - break; - case IP_MULTICAST_IF: { - ip4_addr_t if_addr; - LWIP_SOCKOPT_CHECK_OPTLEN_CONN_PCB_TYPE(sock, optlen, struct in_addr, NETCONN_UDP); - inet_addr_to_ip4addr(&if_addr, (const struct in_addr *)optval); - udp_set_multicast_netif_addr(sock->conn->pcb.udp, &if_addr); - } - break; - case IP_MULTICAST_LOOP: - LWIP_SOCKOPT_CHECK_OPTLEN_CONN_PCB_TYPE(sock, optlen, u8_t, NETCONN_UDP); - if (*(const u8_t *)optval) { - udp_set_flags(sock->conn->pcb.udp, UDP_FLAGS_MULTICAST_LOOP); - } else { - udp_clear_flags(sock->conn->pcb.udp, UDP_FLAGS_MULTICAST_LOOP); - } - break; -#endif /* LWIP_IPV4 && LWIP_MULTICAST_TX_OPTIONS && LWIP_UDP */ -#if LWIP_IGMP - case IP_ADD_MEMBERSHIP: - case IP_DROP_MEMBERSHIP: { - /* If this is a TCP or a RAW socket, ignore these options. */ - err_t igmp_err; - const struct ip_mreq *imr = (const struct ip_mreq *)optval; - ip4_addr_t if_addr; - ip4_addr_t multi_addr; - LWIP_SOCKOPT_CHECK_OPTLEN_CONN_PCB_TYPE(sock, optlen, struct ip_mreq, NETCONN_UDP); - inet_addr_to_ip4addr(&if_addr, &imr->imr_interface); - inet_addr_to_ip4addr(&multi_addr, &imr->imr_multiaddr); - if (optname == IP_ADD_MEMBERSHIP) { - if (!lwip_socket_register_membership(s, &if_addr, &multi_addr)) { - /* cannot track membership (out of memory) */ - err = ENOMEM; - igmp_err = ERR_OK; - } else { - igmp_err = igmp_joingroup(&if_addr, &multi_addr); - } - } else { - igmp_err = igmp_leavegroup(&if_addr, &multi_addr); - lwip_socket_unregister_membership(s, &if_addr, &multi_addr); - } - if (igmp_err != ERR_OK) { - err = EADDRNOTAVAIL; - } - } - break; -#endif /* LWIP_IGMP */ - default: - LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_setsockopt(%d, IPPROTO_IP, UNIMPL: optname=0x%x, ..)\n", - s, optname)); - err = ENOPROTOOPT; - break; - } /* switch (optname) */ - break; - -#if LWIP_TCP - /* Level: IPPROTO_TCP */ - case IPPROTO_TCP: - /* Special case: all IPPROTO_TCP option take an int */ - LWIP_SOCKOPT_CHECK_OPTLEN_CONN_PCB_TYPE(sock, optlen, int, NETCONN_TCP); - if (sock->conn->pcb.tcp->state == LISTEN) { - done_socket(sock); - return EINVAL; - } - switch (optname) { - case TCP_NODELAY: - if (*(const int *)optval) { - tcp_nagle_disable(sock->conn->pcb.tcp); - } else { - tcp_nagle_enable(sock->conn->pcb.tcp); - } - LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_setsockopt(%d, IPPROTO_TCP, TCP_NODELAY) -> %s\n", - s, (*(const int *)optval) ? "on" : "off") ); - break; - case TCP_KEEPALIVE: - sock->conn->pcb.tcp->keep_idle = (u32_t)(*(const int *)optval); - LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_setsockopt(%d, IPPROTO_TCP, TCP_KEEPALIVE) -> %"U32_F"\n", - s, sock->conn->pcb.tcp->keep_idle)); - break; - -#if LWIP_TCP_KEEPALIVE - case TCP_KEEPIDLE: - sock->conn->pcb.tcp->keep_idle = 1000 * (u32_t)(*(const int *)optval); - LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_setsockopt(%d, IPPROTO_TCP, TCP_KEEPIDLE) -> %"U32_F"\n", - s, sock->conn->pcb.tcp->keep_idle)); - break; - case TCP_KEEPINTVL: - sock->conn->pcb.tcp->keep_intvl = 1000 * (u32_t)(*(const int *)optval); - LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_setsockopt(%d, IPPROTO_TCP, TCP_KEEPINTVL) -> %"U32_F"\n", - s, sock->conn->pcb.tcp->keep_intvl)); - break; - case TCP_KEEPCNT: - sock->conn->pcb.tcp->keep_cnt = (u32_t)(*(const int *)optval); - LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_setsockopt(%d, IPPROTO_TCP, TCP_KEEPCNT) -> %"U32_F"\n", - s, sock->conn->pcb.tcp->keep_cnt)); - break; -#endif /* LWIP_TCP_KEEPALIVE */ - default: - LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_setsockopt(%d, IPPROTO_TCP, UNIMPL: optname=0x%x, ..)\n", - s, optname)); - err = ENOPROTOOPT; - break; - } /* switch (optname) */ - break; -#endif /* LWIP_TCP*/ - -#if LWIP_IPV6 - /* Level: IPPROTO_IPV6 */ - case IPPROTO_IPV6: - switch (optname) { - case IPV6_V6ONLY: - LWIP_SOCKOPT_CHECK_OPTLEN_CONN_PCB(sock, optlen, int); - if (*(const int *)optval) { - netconn_set_ipv6only(sock->conn, 1); - } else { - netconn_set_ipv6only(sock->conn, 0); - } - LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_setsockopt(%d, IPPROTO_IPV6, IPV6_V6ONLY, ..) -> %d\n", - s, (netconn_get_ipv6only(sock->conn) ? 1 : 0))); - break; -#if LWIP_IPV6_MLD - case IPV6_JOIN_GROUP: - case IPV6_LEAVE_GROUP: { - /* If this is a TCP or a RAW socket, ignore these options. */ - err_t mld6_err; - struct netif *netif; - ip6_addr_t multi_addr; - const struct ipv6_mreq *imr = (const struct ipv6_mreq *)optval; - LWIP_SOCKOPT_CHECK_OPTLEN_CONN_PCB_TYPE(sock, optlen, struct ipv6_mreq, NETCONN_UDP); - inet6_addr_to_ip6addr(&multi_addr, &imr->ipv6mr_multiaddr); - LWIP_ASSERT("Invalid netif index", imr->ipv6mr_interface <= 0xFFu); - netif = netif_get_by_index((u8_t)imr->ipv6mr_interface); - if (netif == NULL) { - err = EADDRNOTAVAIL; - break; - } - - if (optname == IPV6_JOIN_GROUP) { - if (!lwip_socket_register_mld6_membership(s, imr->ipv6mr_interface, &multi_addr)) { - /* cannot track membership (out of memory) */ - err = ENOMEM; - mld6_err = ERR_OK; - } else { - mld6_err = mld6_joingroup_netif(netif, &multi_addr); - } - } else { - mld6_err = mld6_leavegroup_netif(netif, &multi_addr); - lwip_socket_unregister_mld6_membership(s, imr->ipv6mr_interface, &multi_addr); - } - if (mld6_err != ERR_OK) { - err = EADDRNOTAVAIL; - } - } - break; -#endif /* LWIP_IPV6_MLD */ - default: - LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_setsockopt(%d, IPPROTO_IPV6, UNIMPL: optname=0x%x, ..)\n", - s, optname)); - err = ENOPROTOOPT; - break; - } /* switch (optname) */ - break; -#endif /* LWIP_IPV6 */ - -#if LWIP_UDP && LWIP_UDPLITE - /* Level: IPPROTO_UDPLITE */ - case IPPROTO_UDPLITE: - /* Special case: all IPPROTO_UDPLITE option take an int */ - LWIP_SOCKOPT_CHECK_OPTLEN_CONN_PCB(sock, optlen, int); - /* If this is no UDP lite socket, ignore any options. */ - if (!NETCONNTYPE_ISUDPLITE(netconn_type(sock->conn))) { - done_socket(sock); - return ENOPROTOOPT; - } - switch (optname) { - case UDPLITE_SEND_CSCOV: - if ((*(const int *)optval != 0) && ((*(const int *)optval < 8) || (*(const int *)optval > 0xffff))) { - /* don't allow illegal values! */ - sock->conn->pcb.udp->chksum_len_tx = 8; - } else { - sock->conn->pcb.udp->chksum_len_tx = (u16_t) * (const int *)optval; - } - LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_setsockopt(%d, IPPROTO_UDPLITE, UDPLITE_SEND_CSCOV) -> %d\n", - s, (*(const int *)optval)) ); - break; - case UDPLITE_RECV_CSCOV: - if ((*(const int *)optval != 0) && ((*(const int *)optval < 8) || (*(const int *)optval > 0xffff))) { - /* don't allow illegal values! */ - sock->conn->pcb.udp->chksum_len_rx = 8; - } else { - sock->conn->pcb.udp->chksum_len_rx = (u16_t) * (const int *)optval; - } - LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_setsockopt(%d, IPPROTO_UDPLITE, UDPLITE_RECV_CSCOV) -> %d\n", - s, (*(const int *)optval)) ); - break; - default: - LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_setsockopt(%d, IPPROTO_UDPLITE, UNIMPL: optname=0x%x, ..)\n", - s, optname)); - err = ENOPROTOOPT; - break; - } /* switch (optname) */ - break; -#endif /* LWIP_UDP */ - /* Level: IPPROTO_RAW */ - case IPPROTO_RAW: - switch (optname) { -#if LWIP_IPV6 && LWIP_RAW - case IPV6_CHECKSUM: - /* It should not be possible to disable the checksum generation with ICMPv6 - * as per RFC 3542 chapter 3.1 */ - if (sock->conn->pcb.raw->protocol == IPPROTO_ICMPV6) { - done_socket(sock); - return EINVAL; - } - - LWIP_SOCKOPT_CHECK_OPTLEN_CONN_PCB_TYPE(sock, optlen, int, NETCONN_RAW); - if (*(const int *)optval < 0) { - sock->conn->pcb.raw->chksum_reqd = 0; - } else if (*(const int *)optval & 1) { - /* Per RFC3542, odd offsets are not allowed */ - done_socket(sock); - return EINVAL; - } else { - sock->conn->pcb.raw->chksum_reqd = 1; - sock->conn->pcb.raw->chksum_offset = (u16_t) * (const int *)optval; - } - LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_setsockopt(%d, IPPROTO_RAW, IPV6_CHECKSUM, ..) -> %d\n", - s, sock->conn->pcb.raw->chksum_reqd)); - break; -#endif /* LWIP_IPV6 && LWIP_RAW */ - default: - LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_setsockopt(%d, IPPROTO_RAW, UNIMPL: optname=0x%x, ..)\n", - s, optname)); - err = ENOPROTOOPT; - break; - } /* switch (optname) */ - break; - default: - LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_setsockopt(%d, level=0x%x, UNIMPL: optname=0x%x, ..)\n", - s, level, optname)); - err = ENOPROTOOPT; - break; - } /* switch (level) */ - - done_socket(sock); - return err; -} - -int -lwip_ioctl(int s, long cmd, void *argp) -{ - struct lwip_sock *sock = get_socket(s); - u8_t val; -#if LWIP_SO_RCVBUF - int recv_avail; -#endif /* LWIP_SO_RCVBUF */ - - if (!sock) { - return -1; - } - - switch (cmd) { -#if LWIP_SO_RCVBUF || LWIP_FIONREAD_LINUXMODE - case FIONREAD: - if (!argp) { - sock_set_errno(sock, EINVAL); - done_socket(sock); - return -1; - } -#if LWIP_FIONREAD_LINUXMODE - if (NETCONNTYPE_GROUP(netconn_type(sock->conn)) != NETCONN_TCP) { - struct netbuf *nb; - if (sock->lastdata.netbuf) { - nb = sock->lastdata.netbuf; - *((int *)argp) = nb->p->tot_len; - } else { - struct netbuf *rxbuf; - err_t err = netconn_recv_udp_raw_netbuf_flags(sock->conn, &rxbuf, NETCONN_DONTBLOCK); - if (err != ERR_OK) { - *((int *)argp) = 0; - } else { - sock->lastdata.netbuf = rxbuf; - *((int *)argp) = rxbuf->p->tot_len; - } - } - done_socket(sock); - return 0; - } -#endif /* LWIP_FIONREAD_LINUXMODE */ - -#if LWIP_SO_RCVBUF - /* we come here if either LWIP_FIONREAD_LINUXMODE==0 or this is a TCP socket */ - SYS_ARCH_GET(sock->conn->recv_avail, recv_avail); - if (recv_avail < 0) { - recv_avail = 0; - } - - /* Check if there is data left from the last recv operation. /maq 041215 */ - if (sock->lastdata.netbuf) { - if (NETCONNTYPE_GROUP(netconn_type(sock->conn)) == NETCONN_TCP) { - recv_avail += sock->lastdata.pbuf->tot_len; - } else { - recv_avail += sock->lastdata.netbuf->p->tot_len; - } - } - *((int *)argp) = recv_avail; - - LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_ioctl(%d, FIONREAD, %p) = %"U16_F"\n", s, argp, *((u16_t *)argp))); - sock_set_errno(sock, 0); - done_socket(sock); - return 0; -#else /* LWIP_SO_RCVBUF */ - break; -#endif /* LWIP_SO_RCVBUF */ -#endif /* LWIP_SO_RCVBUF || LWIP_FIONREAD_LINUXMODE */ - - case (long)FIONBIO: - val = 0; - if (argp && *(int *)argp) { - val = 1; - } - netconn_set_nonblocking(sock->conn, val); - LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_ioctl(%d, FIONBIO, %d)\n", s, val)); - sock_set_errno(sock, 0); - done_socket(sock); - return 0; - - default: - // IOCTL_CMD_CASE_HANDLER(); - break; - } /* switch (cmd) */ - LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_ioctl(%d, UNIMPL: 0x%lx, %p)\n", s, cmd, argp)); - sock_set_errno(sock, ENOSYS); /* not yet implemented */ - done_socket(sock); - return -1; -} - -/** A minimal implementation of fcntl. - * Currently only the commands F_GETFL and F_SETFL are implemented. - * The flag O_NONBLOCK and access modes are supported for F_GETFL, only - * the flag O_NONBLOCK is implemented for F_SETFL. - */ -int -lwip_fcntl(int s, int cmd, int val) -{ - struct lwip_sock *sock = get_socket(s); - int ret = -1; - int op_mode = 0; - - if (!sock) { - return -1; - } - - switch (cmd) { - case F_GETFL: - ret = netconn_is_nonblocking(sock->conn) ? O_NONBLOCK : 0; - sock_set_errno(sock, 0); - - if (NETCONNTYPE_GROUP(netconn_type(sock->conn)) == NETCONN_TCP) { -#if LWIP_TCPIP_CORE_LOCKING - LOCK_TCPIP_CORE(); -#else - SYS_ARCH_DECL_PROTECT(lev); - /* the proper thing to do here would be to get into the tcpip_thread, - but locking should be OK as well since we only *read* some flags */ - SYS_ARCH_PROTECT(lev); -#endif -#if LWIP_TCP - if (sock->conn->pcb.tcp) { - if (!(sock->conn->pcb.tcp->flags & TF_RXCLOSED)) { - op_mode |= O_RDONLY; - } - if (!(sock->conn->pcb.tcp->flags & TF_FIN)) { - op_mode |= O_WRONLY; - } - } -#endif -#if LWIP_TCPIP_CORE_LOCKING - UNLOCK_TCPIP_CORE(); -#else - SYS_ARCH_UNPROTECT(lev); -#endif - } else { - op_mode |= O_RDWR; - } - - /* ensure O_RDWR for (O_RDONLY|O_WRONLY) != O_RDWR cases */ - ret |= (op_mode == (O_RDONLY | O_WRONLY)) ? O_RDWR : op_mode; - - break; - case F_SETFL: - /* Bits corresponding to the file access mode and the file creation flags [..] that are set in arg shall be ignored */ - val &= ~(O_RDONLY | O_WRONLY | O_RDWR); - if ((val & ~O_NONBLOCK) == 0) { - /* only O_NONBLOCK, all other bits are zero */ - netconn_set_nonblocking(sock->conn, val & O_NONBLOCK); - ret = 0; - sock_set_errno(sock, 0); - } else { - sock_set_errno(sock, ENOSYS); /* not yet implemented */ - } - break; - default: - LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_fcntl(%d, UNIMPL: %d, %d)\n", s, cmd, val)); - sock_set_errno(sock, ENOSYS); /* not yet implemented */ - break; - } - done_socket(sock); - return ret; -} - -#if LWIP_COMPAT_SOCKETS == 2 && LWIP_POSIX_SOCKETS_IO_NAMES -int -fcntl(int s, int cmd, ...) -{ - va_list ap; - int val; - - va_start(ap, cmd); - val = va_arg(ap, int); - va_end(ap); - return lwip_fcntl(s, cmd, val); -} -#endif - -const char * -lwip_inet_ntop(int af, const void *src, char *dst, socklen_t size) -{ - const char *ret = NULL; - int size_int = (int)size; - if (size_int < 0) { - set_errno(ENOSPC); - return NULL; - } - switch (af) { -#if LWIP_IPV4 - case AF_INET: - ret = ip4addr_ntoa_r((const ip4_addr_t *)src, dst, size_int); - if (ret == NULL) { - set_errno(ENOSPC); - } - break; -#endif -#if LWIP_IPV6 - case AF_INET6: - ret = ip6addr_ntoa_r((const ip6_addr_t *)src, dst, size_int); - if (ret == NULL) { - set_errno(ENOSPC); - } - break; -#endif - default: - set_errno(EAFNOSUPPORT); - break; - } - return ret; -} - -int -lwip_inet_pton(int af, const char *src, void *dst) -{ - int err; - switch (af) { -#if LWIP_IPV4 - case AF_INET: - err = ip4addr_aton(src, (ip4_addr_t *)dst); - break; -#endif -#if LWIP_IPV6 - case AF_INET6: { - /* convert into temporary variable since ip6_addr_t might be larger - than in6_addr when scopes are enabled */ - ip6_addr_t addr; - err = ip6addr_aton(src, &addr); - if (err) { - memcpy(dst, &addr.addr, sizeof(addr.addr)); - } - break; - } -#endif - default: - err = -1; - set_errno(EAFNOSUPPORT); - break; - } - return err; -} - -#if LWIP_IGMP -/** Register a new IGMP membership. On socket close, the membership is dropped automatically. - * - * ATTENTION: this function is called from tcpip_thread (or under CORE_LOCK). - * - * @return 1 on success, 0 on failure - */ -static int -lwip_socket_register_membership(int s, const ip4_addr_t *if_addr, const ip4_addr_t *multi_addr) -{ - struct lwip_sock *sock = get_socket(s); - int i; - - if (!sock) { - return 0; - } - - for (i = 0; i < LWIP_SOCKET_MAX_MEMBERSHIPS; i++) { - if (socket_ipv4_multicast_memberships[i].sock == NULL) { - socket_ipv4_multicast_memberships[i].sock = sock; - ip4_addr_copy(socket_ipv4_multicast_memberships[i].if_addr, *if_addr); - ip4_addr_copy(socket_ipv4_multicast_memberships[i].multi_addr, *multi_addr); - done_socket(sock); - return 1; - } - } - done_socket(sock); - return 0; -} - -/** Unregister a previously registered membership. This prevents dropping the membership - * on socket close. - * - * ATTENTION: this function is called from tcpip_thread (or under CORE_LOCK). - */ -static void -lwip_socket_unregister_membership(int s, const ip4_addr_t *if_addr, const ip4_addr_t *multi_addr) -{ - struct lwip_sock *sock = get_socket(s); - int i; - - if (!sock) { - return; - } - - for (i = 0; i < LWIP_SOCKET_MAX_MEMBERSHIPS; i++) { - if ((socket_ipv4_multicast_memberships[i].sock == sock) && - ip4_addr_cmp(&socket_ipv4_multicast_memberships[i].if_addr, if_addr) && - ip4_addr_cmp(&socket_ipv4_multicast_memberships[i].multi_addr, multi_addr)) { - socket_ipv4_multicast_memberships[i].sock = NULL; - ip4_addr_set_zero(&socket_ipv4_multicast_memberships[i].if_addr); - ip4_addr_set_zero(&socket_ipv4_multicast_memberships[i].multi_addr); - break; - } - } - done_socket(sock); -} - -/** Drop all memberships of a socket that were not dropped explicitly via setsockopt. - * - * ATTENTION: this function is NOT called from tcpip_thread (or under CORE_LOCK). - */ -static void -lwip_socket_drop_registered_memberships(int s) -{ - struct lwip_sock *sock = get_socket(s); - int i; - - if (!sock) { - return; - } - - for (i = 0; i < LWIP_SOCKET_MAX_MEMBERSHIPS; i++) { - if (socket_ipv4_multicast_memberships[i].sock == sock) { - ip_addr_t multi_addr, if_addr; - ip_addr_copy_from_ip4(multi_addr, socket_ipv4_multicast_memberships[i].multi_addr); - ip_addr_copy_from_ip4(if_addr, socket_ipv4_multicast_memberships[i].if_addr); - socket_ipv4_multicast_memberships[i].sock = NULL; - ip4_addr_set_zero(&socket_ipv4_multicast_memberships[i].if_addr); - ip4_addr_set_zero(&socket_ipv4_multicast_memberships[i].multi_addr); - - netconn_join_leave_group(sock->conn, &multi_addr, &if_addr, NETCONN_LEAVE); - } - } - done_socket(sock); -} -#endif /* LWIP_IGMP */ - -#if LWIP_IPV6_MLD -/** Register a new MLD6 membership. On socket close, the membership is dropped automatically. - * - * ATTENTION: this function is called from tcpip_thread (or under CORE_LOCK). - * - * @return 1 on success, 0 on failure - */ -static int -lwip_socket_register_mld6_membership(int s, unsigned int if_idx, const ip6_addr_t *multi_addr) -{ - struct lwip_sock *sock = get_socket(s); - int i; - - if (!sock) { - return 0; - } - - for (i = 0; i < LWIP_SOCKET_MAX_MEMBERSHIPS; i++) { - if (socket_ipv6_multicast_memberships[i].sock == NULL) { - socket_ipv6_multicast_memberships[i].sock = sock; - socket_ipv6_multicast_memberships[i].if_idx = (u8_t)if_idx; - ip6_addr_copy(socket_ipv6_multicast_memberships[i].multi_addr, *multi_addr); - done_socket(sock); - return 1; - } - } - done_socket(sock); - return 0; -} - -/** Unregister a previously registered MLD6 membership. This prevents dropping the membership - * on socket close. - * - * ATTENTION: this function is called from tcpip_thread (or under CORE_LOCK). - */ -static void -lwip_socket_unregister_mld6_membership(int s, unsigned int if_idx, const ip6_addr_t *multi_addr) -{ - struct lwip_sock *sock = get_socket(s); - int i; - - if (!sock) { - return; - } - - for (i = 0; i < LWIP_SOCKET_MAX_MEMBERSHIPS; i++) { - if ((socket_ipv6_multicast_memberships[i].sock == sock) && - (socket_ipv6_multicast_memberships[i].if_idx == if_idx) && - ip6_addr_cmp(&socket_ipv6_multicast_memberships[i].multi_addr, multi_addr)) { - socket_ipv6_multicast_memberships[i].sock = NULL; - socket_ipv6_multicast_memberships[i].if_idx = NETIF_NO_INDEX; - ip6_addr_set_zero(&socket_ipv6_multicast_memberships[i].multi_addr); - break; - } - } - done_socket(sock); -} - -/** Drop all MLD6 memberships of a socket that were not dropped explicitly via setsockopt. - * - * ATTENTION: this function is NOT called from tcpip_thread (or under CORE_LOCK). - */ -static void -lwip_socket_drop_registered_mld6_memberships(int s) -{ - struct lwip_sock *sock = get_socket(s); - int i; - - if (!sock) { - return; - } - - for (i = 0; i < LWIP_SOCKET_MAX_MEMBERSHIPS; i++) { - if (socket_ipv6_multicast_memberships[i].sock == sock) { - ip_addr_t multi_addr; - u8_t if_idx; - - ip_addr_copy_from_ip6(multi_addr, socket_ipv6_multicast_memberships[i].multi_addr); - if_idx = socket_ipv6_multicast_memberships[i].if_idx; - - socket_ipv6_multicast_memberships[i].sock = NULL; - socket_ipv6_multicast_memberships[i].if_idx = NETIF_NO_INDEX; - ip6_addr_set_zero(&socket_ipv6_multicast_memberships[i].multi_addr); - - netconn_join_leave_group_netif(sock->conn, &multi_addr, if_idx, NETCONN_LEAVE); - } - } - done_socket(sock); -} -#endif /* LWIP_IPV6_MLD */ - -#endif /* LWIP_SOCKET */ diff --git a/bk7235/liteos_m/bk_sdk_armino/components/lwip_intf_v2_1/lwip-2.1.2/port/sys_arch.c b/bk7235/liteos_m/bk_sdk_armino/components/lwip_intf_v2_1/lwip-2.1.2/port/sys_arch.c deleted file mode 100755 index 95006e226ec20f8c892d764444daa562b15c38df..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/lwip_intf_v2_1/lwip-2.1.2/port/sys_arch.c +++ /dev/null @@ -1,502 +0,0 @@ -/* - * Copyright (c) 2001-2003 Swedish Institute of Computer Science. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT - * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT - * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING - * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY - * OF SUCH DAMAGE. - * - * This file is part of the lwIP TCP/IP stack. - * - * Author: Adam Dunkels - * - */ - -/* lwIP includes. */ -#include "lwip/debug.h" -#include "lwip/def.h" -#include "lwip/sys.h" -#include "lwip/mem.h" -#include "lwip/stats.h" -#include "sys_rtos.h" -#include "lwip/timeouts.h" -#include -#include - -#define CFG_ENABLE_LWIP_MUTEX 1 - -#if CFG_ENABLE_LWIP_MUTEX -static sys_mutex_t sys_arch_mutex; -#endif - -/*-----------------------------------------------------------------------------------*/ -err_t sys_mbox_new(sys_mbox_t *mbox, int size) -{ - bk_err_t ret; - - if (size > 0) - ret = rtos_init_queue(mbox, NULL, sizeof( void * ), size); - else - ret = rtos_init_queue(mbox, NULL, sizeof( void * ), archMESG_QUEUE_LENGTH); - -#if SYS_STATS - ++lwip_stats.sys.mbox.used; - if (lwip_stats.sys.mbox.max < lwip_stats.sys.mbox.used) { - lwip_stats.sys.mbox.max = lwip_stats.sys.mbox.used; - } -#endif /* SYS_STATS */ - - if (kNoErr != ret) - return ERR_MEM; - - return ERR_OK; -} - -/*-----------------------------------------------------------------------------------*/ -/* - Deallocates a mailbox. If there are messages still present in the - mailbox when the mailbox is deallocated, it is an indication of a - programming error in lwIP and the developer should be notified. -*/ -void sys_mbox_free(sys_mbox_t *mbox) -{ - rtos_deinit_queue(mbox); - -#if SYS_STATS - --lwip_stats.sys.mbox.used; -#endif /* SYS_STATS */ -} - -/*-----------------------------------------------------------------------------------*/ -// Posts the "msg" to the mailbox. -void sys_mbox_post(sys_mbox_t *mbox, void *data) -{ - bk_err_t ret; - - ret = rtos_push_to_queue(mbox, &data, BEKEN_WAIT_FOREVER); - if (ret != kNoErr) { - LWIP_DEBUGF(SYS_DEBUG, ("%s: sys_mbox_post error %u\n", __FUNCTION__, ret)); - } -} - - -/*-----------------------------------------------------------------------------------*/ -// Try to post the "msg" to the mailbox. -err_t sys_mbox_trypost(sys_mbox_t *mbox, void *msg) -{ - err_t result; - bk_err_t ret; - - ret = rtos_push_to_queue(mbox, &msg, 0); - if (kNoErr == ret) - { - result = ERR_OK; - } - else - { - // could not post, queue must be full - result = ERR_MEM; - -#if SYS_STATS - lwip_stats.sys.mbox.err++; -#endif /* SYS_STATS */ - - } - - return result; -} - -/*-----------------------------------------------------------------------------------*/ -/* - Blocks the thread until a message arrives in the mailbox, but does - not block the thread longer than "timeout" milliseconds (similar to - the sys_arch_sem_wait() function). The "msg" argument is a result - parameter that is set by the function (i.e., by doing "*msg = - ptr"). The "msg" parameter maybe NULL to indicate that the message - should be dropped. - - The return values are the same as for the sys_arch_sem_wait() function: - Number of milliseconds spent waiting or SYS_ARCH_TIMEOUT if there was a - timeout. - - Note that a function with a similar name, sys_mbox_fetch(), is - implemented by lwIP. -*/ -u32_t sys_arch_mbox_fetch(sys_mbox_t *mbox, void **msg, u32_t timeout) -{ - void *dummyptr; - beken_time_t StartTime, EndTime, Elapsed; - - beken_time_get_time(&StartTime); - - if ( NULL == msg ) - { - msg = &dummyptr; - } - - if ( timeout != 0 ) - { - if ( kNoErr == rtos_pop_from_queue(mbox, &(*msg), timeout) ) - { - beken_time_get_time(&EndTime); - Elapsed = (EndTime - StartTime) * 1; - - return ( Elapsed ); - } - else // timed out blocking for message - { - *msg = NULL; - - return SYS_ARCH_TIMEOUT; - } - } - else // block forever for a message. - { - rtos_pop_from_queue(mbox, &(*msg), BEKEN_WAIT_FOREVER); - beken_time_get_time(&EndTime); - Elapsed = (EndTime - StartTime) * 1; - - return ( Elapsed ); // return time blocked TODO test - } -} - -/*-----------------------------------------------------------------------------------*/ -/* - Similar to sys_arch_mbox_fetch, but if message is not ready immediately, we'll - return with SYS_MBOX_EMPTY. On success, 0 is returned. -*/ -u32_t sys_arch_mbox_tryfetch(sys_mbox_t *mbox, void **msg) -{ -void *dummyptr; - - if ( msg == NULL ) - { - msg = &dummyptr; - } - - if ( kNoErr == rtos_pop_from_queue(mbox, &(*msg), 0) ) - { - return ERR_OK; - } - else - { - return SYS_MBOX_EMPTY; - } -} -/*----------------------------------------------------------------------------------*/ -int sys_mbox_valid(sys_mbox_t *mbox) -{ - if (*mbox == SYS_MBOX_NULL) - return 0; - else - return 1; -} -/*-----------------------------------------------------------------------------------*/ -void sys_mbox_set_invalid(sys_mbox_t *mbox) -{ - *mbox = SYS_MBOX_NULL; -} - -/*-----------------------------------------------------------------------------------*/ -// Creates a new semaphore. The "count" argument specifies -// the initial state of the semaphore. -err_t sys_sem_new(sys_sem_t *sem, u8_t count) -{ - bk_err_t ret; - - ret = rtos_init_semaphore_adv(sem, 0xff, count); - if(kNoErr != ret) - return ERR_ARG; - -#if SYS_STATS - ++lwip_stats.sys.sem.used; - if (lwip_stats.sys.sem.max < lwip_stats.sys.sem.used) { - lwip_stats.sys.sem.max = lwip_stats.sys.sem.used; - } -#endif /* SYS_STATS */ - - return ERR_OK; -} - -/*-----------------------------------------------------------------------------------*/ -/* - Blocks the thread while waiting for the semaphore to be - signaled. If the "timeout" argument is non-zero, the thread should - only be blocked for the specified time (measured in - milliseconds). - - If the timeout argument is non-zero, the return value is the number of - milliseconds spent waiting for the semaphore to be signaled. If the - semaphore wasn't signaled within the specified time, the return value is - SYS_ARCH_TIMEOUT. If the thread didn't have to wait for the semaphore - (i.e., it was already signaled), the function may return zero. - - Notice that lwIP implements a function with a similar name, - sys_sem_wait(), that uses the sys_arch_sem_wait() function. -*/ -u32_t sys_arch_sem_wait(sys_sem_t *sem, u32_t timeout) -{ - bk_err_t ret; - beken_time_t StartTime, EndTime, Elapsed; - - beken_time_get_time(&StartTime); - - if( timeout != 0) - { - ret = rtos_get_semaphore(sem, timeout); - if( kNoErr == ret ) - { - beken_time_get_time(&EndTime); - Elapsed = (EndTime - StartTime) * 1; - - return (Elapsed); // return time blocked TODO test - } - else - { - return SYS_ARCH_TIMEOUT; - } - } - else // must block without a timeout - { - ret = rtos_get_semaphore(sem, BEKEN_WAIT_FOREVER); - if( kNoErr != ret ) - return SYS_ARCH_TIMEOUT; - - beken_time_get_time(&EndTime); - Elapsed = (EndTime - StartTime) * 1; - - return ( Elapsed ); // return time blocked - } -} - -/*-----------------------------------------------------------------------------------*/ -// Signals a semaphore -void sys_sem_signal(sys_sem_t *sem) -{ - rtos_set_semaphore(sem); -} - -/*-----------------------------------------------------------------------------------*/ -// Deallocates a semaphore -void sys_sem_free(sys_sem_t *sem) -{ -#if SYS_STATS - --lwip_stats.sys.sem.used; -#endif /* SYS_STATS */ - - rtos_deinit_semaphore(sem); -} -/*-----------------------------------------------------------------------------------*/ -int sys_sem_valid(sys_sem_t *sem) -{ - if (*sem == SYS_SEM_NULL) - return 0; - else - return 1; -} - -/*-----------------------------------------------------------------------------------*/ -void sys_sem_set_invalid(sys_sem_t *sem) -{ - *sem = SYS_SEM_NULL; -} - -/*-----------------------------------------------------------------------------------*/ -err_t sys_mutex_trylock(sys_mutex_t *pxMutex) -{ - bk_err_t ret; - - ret = rtos_trylock_mutex(pxMutex); - if (kNoErr == ret) - return 0; - else - return -1; -} - -/*-----------------------------------------------------------------------------------*/ -// Initialize sys arch -void sys_init(void) -{ -#if CFG_ENABLE_LWIP_MUTEX - sys_mutex_new(&sys_arch_mutex); -#endif -} - -/*-----------------------------------------------------------------------------------*/ - /* Mutexes*/ -/*-----------------------------------------------------------------------------------*/ -err_t sys_mutex_new(sys_mutex_t *mutex) -{ - bk_err_t ret; - - ret = rtos_init_mutex(mutex); - if(kNoErr != ret) - return ERR_VAL; - -#if SYS_STATS - ++lwip_stats.sys.mutex.used; - if (lwip_stats.sys.mutex.max < lwip_stats.sys.mutex.used) { - lwip_stats.sys.mutex.max = lwip_stats.sys.mutex.used; - } -#endif /* SYS_STATS */ - - return ERR_OK; -} -/*-----------------------------------------------------------------------------------*/ -/* Deallocate a mutex*/ -void sys_mutex_free(sys_mutex_t *mutex) -{ -#if SYS_STATS - --lwip_stats.sys.mutex.used; -#endif /* SYS_STATS */ - - rtos_deinit_mutex(mutex); -} - -void sys_mutex_lock(sys_mutex_t *mutex) -{ - rtos_lock_mutex(mutex); -} - -void sys_mutex_unlock(sys_mutex_t *mutex) -{ - rtos_unlock_mutex(mutex); -} - -/*-----------------------------------------------------------------------------------*/ -// TODO -/*-----------------------------------------------------------------------------------*/ -/* - Starts a new thread with priority "prio" that will begin its execution in the - function "thread()". The "arg" argument will be passed as an argument to the - thread() function. The id of the new thread is returned. Both the id and - the priority are system dependent. -*/ -sys_thread_t sys_thread_new(const char *name, lwip_thread_fn thread , void *arg, int stacksize, int prio) -{ - sys_thread_t CreatedTask; - bk_err_t result; - - result = rtos_create_thread(&CreatedTask, prio, name, thread, stacksize * sizeof(uint32_t), arg); - if(result == kNoErr) - { - return CreatedTask; - } - else - { - return NULL; - } -} - -int sys_thread_delete(sys_thread_t pid) -{ - bk_err_t ret; - - ret = rtos_delete_thread(&pid); - if(kNoErr == ret) - { - return ERR_OK; - } - else - { - return ERR_ARG; - } -} - -/* - This optional function does a "fast" critical region protection and returns - the previous protection level. This function is only called during very short - critical regions. An embedded system which supports ISR-based drivers might - want to implement this function by disabling interrupts. Task-based systems - might want to implement this by using a mutex or disabling tasking. This - function should support recursive calls from the same task or interrupt. In - other words, sys_arch_protect() could be called while already protected. In - that case the return value indicates that it is already protected. - - sys_arch_protect() is only required if your port is supporting an operating - system. -*/ -sys_prot_t sys_arch_protect(void) -{ -#if CFG_ENABLE_LWIP_MUTEX - sys_mutex_lock(&sys_arch_mutex); - - return 0; -#else - return port_disable_interrupts_flag(); -#endif -} - -/* - This optional function does a "fast" set of critical region protection to the - value specified by pval. See the documentation for sys_arch_protect() for - more information. This function is only required if your port is supporting - an operating system. -*/ -void sys_arch_unprotect(sys_prot_t pval) -{ -#if CFG_ENABLE_LWIP_MUTEX - (void)pval; - sys_mutex_unlock(&sys_arch_mutex); -#else - port_enable_interrupts_flag(pval); -#endif -} - -/* - * Prints an assertion messages and aborts execution. - */ -void sys_assert( const char *msg ) -{ - (void) msg; - - /*FSL:only needed for debugging*/ - os_printf(msg); - os_printf("\n\r"); - - rtos_enter_critical(); - - for(;;) - ; -} - -u32_t sys_now(void) -{ - beken_time_t now_tick = 0; - - beken_time_get_time(&now_tick); - return now_tick * beken_ms_per_tick(); -} - -u32_t sys_jiffies(void) -{ - beken_time_t now_tick = 0; - - beken_time_get_time(&now_tick); - return now_tick; -} - -void sys_arch_msleep(int ms) -{ - rtos_delay_milliseconds(ms); -} - -// eof diff --git a/bk7235/liteos_m/bk_sdk_armino/components/lwip_intf_v2_1/tcp_server.c b/bk7235/liteos_m/bk_sdk_armino/components/lwip_intf_v2_1/tcp_server.c deleted file mode 100644 index 0f534fcda80bd1493ffcad9b580d9d8d5c229d97..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/lwip_intf_v2_1/tcp_server.c +++ /dev/null @@ -1,179 +0,0 @@ -/** - ****************************************************************************** - * @file tcp_server.c - * @version V1.0.0 - * @date 21-May-2015 - * @brief tcp server Demo - ****************************************************************************** - * - * The MIT License - * Copyright (c) 2014 BEKEN Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is furnished - * to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, - * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR - * IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - ****************************************************************************** - */ - -#include -#include -#include -#include "lwip/sockets.h" -#include -#include - -#define tcp_server_log(M, ...) LWIP_LOGI("TCP", M, ##__VA_ARGS__) - -#define SERVER_PORT 20000 /*set up a tcp server,port at 20000*/ - -int my_fd = -1; - - -int unw_recv(const int fd, void *buf, u32 nbytes) -{ - fd_set readfds, errfds; - int ret = 0; - - if (fd < 0) { - return -1;//UNW_FAIL; - } - - FD_ZERO(&readfds); - FD_ZERO(&errfds); - FD_SET(fd, &readfds); - FD_SET(fd, &errfds); - - ret = select(fd + 1, &readfds, NULL, &errfds, NULL); - LWIP_LOGI("select ret:%d, %d, %d\r\n", ret, FD_ISSET(fd, &readfds), FD_ISSET(fd, &errfds)); - - if (ret > 0 && FD_ISSET(fd, &readfds)) - return recv(fd, buf, nbytes, 0); - else - return -1;//UNW_FAIL; - -} - -void tcp_client_thread(beken_thread_arg_t arg) -{ - bk_err_t err = kNoErr; - int fd = (int) arg; - int len = 0; - fd_set readfds, errfds, readfds2; - char *buf = NULL; - - my_fd = fd; - - buf = (char *) os_malloc(1024); - ASSERT(buf); - - while (1) { - - { - len = recv(fd, buf, 1024, 0); - - if (len <= 0) { - LWIP_LOGI("TCP Client is disconnected, fd: %d", fd); - goto exit; - } - - len = send(fd, buf, len, 0); - } - } - -exit: - if (err != kNoErr) - tcp_server_log("TCP client thread exit with err: %d", err); - - if (buf != NULL) - os_free(buf); - - close(fd); - rtos_delete_thread(NULL); -} - -volatile u8 test_flag = 0; -void close_tcp_client(void) -{ - LWIP_LOGI("close_tcp_client:%d, %p\r\n", my_fd, rtos_get_current_thread()); - test_flag = 1; - close(my_fd); - my_fd = -1; -} - -/* TCP server listener thread */ -void tcp_server_thread(beken_thread_arg_t arg) -{ - (void)(arg); - bk_err_t err = kNoErr; - struct sockaddr_in server_addr, client_addr; - socklen_t sockaddr_t_size = sizeof(client_addr); - char client_ip_str[16]; - int tcp_listen_fd = -1, client_fd = -1; - fd_set readfds; - - tcp_listen_fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); - - server_addr.sin_family = AF_INET; - server_addr.sin_addr.s_addr = INADDR_ANY;/* Accept conenction request on all network interface */ - server_addr.sin_port = htons(SERVER_PORT); /* Server listen on port: 20000 */ - err = bind(tcp_listen_fd, (struct sockaddr *) &server_addr, sizeof(server_addr)); - - err = listen(tcp_listen_fd, 0); - - while (1) { - FD_ZERO(&readfds); - FD_SET(tcp_listen_fd, &readfds); - - select(tcp_listen_fd + 1, &readfds, NULL, NULL, NULL); - - if (FD_ISSET(tcp_listen_fd, &readfds)) { - client_fd = accept(tcp_listen_fd, (struct sockaddr *) &client_addr, &sockaddr_t_size); - if (client_fd >= 0) { - os_strcpy(client_ip_str, inet_ntoa(client_addr.sin_addr)); - tcp_server_log("TCP Client %s:%d connected, fd: %d", client_ip_str, client_addr.sin_port, client_fd); - if (kNoErr - != rtos_create_thread(NULL, BEKEN_APPLICATION_PRIORITY, - "TCP Clients", - (beken_thread_function_t)tcp_client_thread, - 0x800, - (beken_thread_arg_t)client_fd)) { - close(client_fd); - client_fd = -1; - } - } - } - } - - if (err != kNoErr) - tcp_server_log("Server listerner thread exit with err: %d", err); - - close(tcp_listen_fd); - rtos_delete_thread(NULL); -} - -void make_tcp_server_command(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - bk_err_t err = kNoErr; - - err = rtos_create_thread(NULL, BEKEN_APPLICATION_PRIORITY, - "TCP_server", - (beken_thread_function_t)tcp_server_thread, - 0x800, - (beken_thread_arg_t)0); - if (err != kNoErr) - LWIP_LOGE("create \"TCP_server\" thread failed!\r\n"); -} - diff --git a/bk7235/liteos_m/bk_sdk_armino/components/media/include/mlist.h b/bk7235/liteos_m/bk_sdk_armino/components/media/include/mlist.h index 222453b9b9bef66bcd73bfc59753985dde57489e..32ee68cc0a14a604671c7843b5cc9a2cba074b53 100755 --- a/bk7235/liteos_m/bk_sdk_armino/components/media/include/mlist.h +++ b/bk7235/liteos_m/bk_sdk_armino/components/media/include/mlist.h @@ -1,3 +1,18 @@ +/* + * Copyright (C) 2022 Beken Corporation + * 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. + */ + #pragma once #include diff --git a/bk7235/liteos_m/bk_sdk_armino/components/media/utils/mlist.c b/bk7235/liteos_m/bk_sdk_armino/components/media/utils/mlist.c deleted file mode 100755 index 9bf4a6332ea8b2246a467619ea61f5837f736937..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/media/utils/mlist.c +++ /dev/null @@ -1,346 +0,0 @@ -#include -#include -#include -#include - -#include "utils.h" -#include "mlist.h" - -struct mlist_node_t -{ - struct mlist_node_t *next; - void *data; -}; - -typedef struct mlist_t -{ - mlist_node_t *head; - mlist_node_t *tail; - size_t length; - mlist_free_cb free_cb; - const allocator_t *allocator; -} mlist_t; - -void *osi_malloc(size_t size); -void osi_free(void *ptr); - - -const allocator_t allocator_malloc = {osi_malloc, osi_free}; - -static mlist_node_t *mlist_free_node(mlist_t *mlist, mlist_node_t *node); - -// Hidden constructor, only to be used by the hash map for the allocation -// tracker. -// Behaves the same as |mlist_new|, except you get to specify the allocator. -mlist_t *mlist_new_internal(mlist_free_cb callback, - const allocator_t *zeroed_allocator) -{ - mlist_t *mlist = (mlist_t *)zeroed_allocator->alloc(sizeof(mlist_t)); - if (!mlist) - { - return NULL; - } - - mlist->free_cb = callback; - mlist->allocator = zeroed_allocator; - return mlist; -} - -mlist_t *mlist_new(mlist_free_cb callback) -{ - return mlist_new_internal(callback, &allocator_malloc); -} - -void mlist_free(mlist_t *mlist) -{ - if (!mlist) - { - return; - } - - mlist_clear(mlist); - mlist->allocator->free(mlist); -} - -bool mlist_is_empty(const mlist_t *mlist) -{ - BK_ASSERT(mlist != NULL); - return (mlist->length == 0); -} - -bool mlist_contains(const mlist_t *mlist, const void *data) -{ - BK_ASSERT(mlist != NULL); - BK_ASSERT(data != NULL); - - for (const mlist_node_t *node = mlist_begin(mlist); node != mlist_end(mlist); - node = mlist_next(node)) - { - if (mlist_node(node) == data) - { - return true; - } - } - - return false; -} - -size_t mlist_length(const mlist_t *mlist) -{ - BK_ASSERT(mlist != NULL); - return mlist->length; -} - -void *mlist_front(const mlist_t *mlist) -{ - BK_ASSERT(mlist != NULL); - BK_ASSERT(!mlist_is_empty(mlist)); - - return mlist->head->data; -} - -void *mlist_back(const mlist_t *mlist) -{ - BK_ASSERT(mlist != NULL); - BK_ASSERT(!mlist_is_empty(mlist)); - - return mlist->tail->data; -} - -mlist_node_t *mlist_back_node(const mlist_t *mlist) -{ - BK_ASSERT(mlist != NULL); - BK_ASSERT(!mlist_is_empty(mlist)); - - return mlist->tail; -} - -bool mlist_insert_after(mlist_t *mlist, mlist_node_t *prev_node, void *data) -{ - BK_ASSERT(mlist != NULL); - BK_ASSERT(prev_node != NULL); - BK_ASSERT(data != NULL); - - mlist_node_t *node = (mlist_node_t *)mlist->allocator->alloc(sizeof(mlist_node_t)); - if (!node) - { - return false; - } - - node->next = prev_node->next; - node->data = data; - prev_node->next = node; - if (mlist->tail == prev_node) - { - mlist->tail = node; - } - ++mlist->length; - return true; -} - -bool mlist_prepend(mlist_t *mlist, void *data) -{ - BK_ASSERT(mlist != NULL); - BK_ASSERT(data != NULL); - - mlist_node_t *node = (mlist_node_t *)mlist->allocator->alloc(sizeof(mlist_node_t)); - if (!node) - { - return false; - } - node->next = mlist->head; - node->data = data; - mlist->head = node; - if (mlist->tail == NULL) - { - mlist->tail = mlist->head; - } - ++mlist->length; - return true; -} - -bool mlist_append(mlist_t *mlist, void *data) -{ - BK_ASSERT(mlist != NULL); - BK_ASSERT(data != NULL); - - mlist_node_t *node = (mlist_node_t *)mlist->allocator->alloc(sizeof(mlist_node_t)); - if (!node) - { - return false; - } - node->next = NULL; - node->data = data; - if (mlist->tail == NULL) - { - mlist->head = node; - mlist->tail = node; - } - else - { - mlist->tail->next = node; - mlist->tail = node; - } - ++mlist->length; - return true; -} - -bool mlist_remove(mlist_t *mlist, void *data) -{ - BK_ASSERT(mlist != NULL); - BK_ASSERT(data != NULL); - - if (mlist_is_empty(mlist)) - { - return false; - } - - if (mlist->head->data == data) - { - mlist_node_t *next = mlist_free_node(mlist, mlist->head); - if (mlist->tail == mlist->head) - { - mlist->tail = next; - } - mlist->head = next; - return true; - } - - for (mlist_node_t *prev = mlist->head, *node = mlist->head->next; node; - prev = node, node = node->next) - if (node->data == data) - { - prev->next = mlist_free_node(mlist, node); - if (mlist->tail == node) - { - mlist->tail = prev; - } - return true; - } - - return false; -} - -void mlist_clear(mlist_t *mlist) -{ - BK_ASSERT(mlist != NULL); - for (mlist_node_t *node = mlist->head; node;) - { - node = mlist_free_node(mlist, node); - } - mlist->head = NULL; - mlist->tail = NULL; - mlist->length = 0; -} - -mlist_node_t *mlist_foreach(const mlist_t *mlist, mlist_iter_cb callback, - void *context) -{ - BK_ASSERT(mlist != NULL); - BK_ASSERT(callback != NULL); - - for (mlist_node_t *node = mlist->head; node;) - { - mlist_node_t *next = node->next; - if (!callback(node->data, context)) - { - return node; - } - node = next; - } - return NULL; -} - - -void *mlist_foreach_pop(mlist_t *mlist, mlist_iter_cb callback, - void *context) -{ - BK_ASSERT(mlist != NULL); - BK_ASSERT(callback != NULL); - void *data = NULL; - - if (mlist_is_empty(mlist)) - { - return false; - } - - if (callback(mlist->head->data, context)) - { - data = mlist->head->data; - - mlist_node_t *next = mlist_free_node(mlist, mlist->head); - if (mlist->tail == mlist->head) - { - mlist->tail = next; - } - mlist->head = next; - - return data; - } - - for (mlist_node_t *prev = mlist->head, *node = mlist->head->next; node; - prev = node, node = node->next) - if (callback(node->data, context)) - { - data = node->data; - prev->next = mlist_free_node(mlist, node); - if (mlist->tail == node) - { - mlist->tail = prev; - } - return data; - } - - return NULL; -} - -mlist_node_t *mlist_begin(const mlist_t *mlist) -{ - BK_ASSERT(mlist != NULL); - return mlist->head; -} - -mlist_node_t *mlist_end(UNUSED_ATTR const mlist_t *mlist) -{ - BK_ASSERT(mlist != NULL); - return NULL; -} - -mlist_node_t *mlist_next(const mlist_node_t *node) -{ - BK_ASSERT(node != NULL); - return node->next; -} - -void *mlist_node(const mlist_node_t *node) -{ - BK_ASSERT(node != NULL); - return node->data; -} - -static mlist_node_t *mlist_free_node(mlist_t *mlist, mlist_node_t *node) -{ - BK_ASSERT(mlist != NULL); - BK_ASSERT(node != NULL); - - mlist_node_t *next = node->next; - - if (mlist->free_cb) - { - mlist->free_cb(node->data); - } - mlist->allocator->free(node); - --mlist->length; - - return next; -} - -void *osi_malloc(size_t size) -{ - return os_malloc(size); -} - -void osi_free(void *ptr) -{ - os_free(ptr); -} diff --git a/bk7235/liteos_m/bk_sdk_armino/components/release/release.h b/bk7235/liteos_m/bk_sdk_armino/components/release/release.h index e965d390549b110e685f28d3a1595ac450968ba2..1766c815fbe632fb3beb12d0f3f4f732ccbc2589 100644 --- a/bk7235/liteos_m/bk_sdk_armino/components/release/release.h +++ b/bk7235/liteos_m/bk_sdk_armino/components/release/release.h @@ -1,3 +1,17 @@ +/* + * Copyright (C) 2022 Beken Corporation + * 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 _RELEASE_H_ #define _RELEASE_H_ diff --git a/bk7235/liteos_m/bk_sdk_armino/components/saradc_intf/saradc_intf.c b/bk7235/liteos_m/bk_sdk_armino/components/saradc_intf/saradc_intf.c deleted file mode 100644 index 37f740ff7ae43ac1eed7166f392051d3447186f4..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/saradc_intf/saradc_intf.c +++ /dev/null @@ -1,633 +0,0 @@ -#include -#include -#include "bk_arm_arch.h" -#include "bk_gpio.h" -#include "bk_uart.h" -#include "bk_saradc.h" -#include "temp_detect_pub.h" -#include "temp_detect.h" -#include "sys_rtos.h" -#include -#include "saradc_intf.h" -#include -#include "bk_fake_clock.h" -#include -#include "bk_sys_ctrl.h" - -#define TURING_ADC_TAG "saradc_intf" -#define TURING_ADC_TASK_PRIORITY (18) -#define TURING_ADC_TASK_STACK_SIZE (1024 * 1) -#define TURING_ADC_QITEM_COUNT (3) - -volatile uint8_t step_flag = 1; -volatile uint8_t adctest_flag = 1; -volatile uint8_t adc_accuracy = 0; - -enum { - TADC_TIMER_POLL = 0, - TADC_EXIT, -}; - -typedef struct tadc_message { - UINT32 data; -} TADC_MSG_T; - -typedef struct _tadc_entity_ { - beken_thread_t tadc_thread; - beken_queue_t msg_que; - beken_timer_t check_timer; - beken_semaphore_t sema_wait_end; - - ADC_OBJ *adc_obj_list; - beken_mutex_t obj_list_mutex; - - DD_HANDLE adc_handle; - saradc_desc_t adc_cfg; - UINT16 adc_data[ADC_TEMP_BUFFER_SIZE]; -} TADC_ENTITY_T; - -void saradc_calculate_step1(void); -void saradc_calculate_step2(void); - -static TADC_ENTITY_T *tadc_entity = NULL; - -void adc_obj_init(ADC_OBJ *handle, adc_obj_callback cb, UINT32 channel, void *user_data) -{ - if (handle) { - adc_obj_stop(handle); - os_memset(handle, 0, sizeof(ADC_OBJ)); - handle->channel = channel; - handle->user_data = user_data; - handle->cb = cb; - } -} - -int adc_obj_start(ADC_OBJ *handle) -{ - ADC_OBJ *target; - - if (!tadc_entity || (!tadc_entity->obj_list_mutex)) { - TADC_WARNING_PRINTF("adc obj start with no initial\r\n"); - return -1; - } - - rtos_lock_mutex(&tadc_entity->obj_list_mutex); - target = tadc_entity->adc_obj_list; - while (target) { - if (target == handle) { - rtos_unlock_mutex(&tadc_entity->obj_list_mutex); - return -1; //already exist. - } - target = target->next; - } - handle->next = tadc_entity->adc_obj_list; - tadc_entity->adc_obj_list = handle; - rtos_unlock_mutex(&tadc_entity->obj_list_mutex); - return 0; -} - -void adc_obj_stop(ADC_OBJ *handle) -{ - ADC_OBJ **curr; - - rtos_lock_mutex(&tadc_entity->obj_list_mutex); - for (curr = &tadc_entity->adc_obj_list; *curr;) { - ADC_OBJ *entry = *curr; - if (entry == handle) - *curr = entry->next; - else - curr = &entry->next; - } - rtos_unlock_mutex(&tadc_entity->obj_list_mutex); -} - -static void sadc_detect_handler(void) -{ - saradc_desc_t *p_ADC_drv_desc = &tadc_entity->adc_cfg; - - if (!p_ADC_drv_desc) - return; - - if (p_ADC_drv_desc->current_sample_data_cnt >= p_ADC_drv_desc->data_buff_size) { - UINT32 sum = 0, sum1, sum2; - - ddev_close(tadc_entity->adc_handle); - tadc_entity->adc_handle = DD_HANDLE_UNVALID; - saradc_ensure_close(); - - sum1 = p_ADC_drv_desc->pData[1] + p_ADC_drv_desc->pData[2]; - sum2 = p_ADC_drv_desc->pData[3] + p_ADC_drv_desc->pData[4]; - sum = sum1 / 2 + sum2 / 2; - sum = sum / 2; - - adc_accuracy = (uint8_t)saradc_check_accuracy(); - if (adc_accuracy != 0) - sum = sum >> (adc_accuracy - 1); - - p_ADC_drv_desc->pData[0] = sum; - - rtos_set_semaphore(&tadc_entity->sema_wait_end); - } -} - -void tadc_obj_handler(ADC_OBJ *handle) -{ - saradc_desc_t *p_ADC_drv_desc = NULL; - UINT32 status, ret; - GLOBAL_INT_DECLARATION(); - - p_ADC_drv_desc = &tadc_entity->adc_cfg; - - saradc_config_param_init(p_ADC_drv_desc); - - p_ADC_drv_desc->channel = handle->channel; - p_ADC_drv_desc->data_buff_size = ADC_TEMP_BUFFER_SIZE; - p_ADC_drv_desc->current_read_data_cnt = 0; - p_ADC_drv_desc->current_sample_data_cnt = 0; - p_ADC_drv_desc->has_data = 0; - p_ADC_drv_desc->pData = &tadc_entity->adc_data[0]; - os_memset(p_ADC_drv_desc->pData, 0x00, p_ADC_drv_desc->data_buff_size * sizeof(UINT16)); - - p_ADC_drv_desc->p_Int_Handler = sadc_detect_handler; - - ret = 0; - do { - GLOBAL_INT_DISABLE(); - if (saradc_check_busy() == 0) { - tadc_entity->adc_handle = ddev_open(DD_DEV_TYPE_SARADC, &status, (UINT32)p_ADC_drv_desc); - if (DD_HANDLE_UNVALID != tadc_entity->adc_handle) { - GLOBAL_INT_RESTORE(); - break; - } - } - GLOBAL_INT_RESTORE(); - rtos_delay_milliseconds(5); - ret++; - } while (ret < 5); - - if (ret == 5) { - TADC_WARNING_PRINTF("adc timeout\r\n"); - return; - } - - status = TURING_ADC_SCAN_INTERVALV; - ret = rtos_get_semaphore(&tadc_entity->sema_wait_end, status * bk_get_ticks_per_second()); - if (step_flag == 0) - saradc_calculate_step1(); - else - saradc_calculate_step2(); - - if (ret == kNoErr) { - - float voltage = 0.0; - int mv; - - if (adctest_flag == 0) - mv = p_ADC_drv_desc->pData[0]; - else { - voltage = saradc_calculate(p_ADC_drv_desc->pData[0]); - mv = voltage * 1000; - } - - if (handle->cb) - handle->cb(mv, handle->user_data); - } else - - TADC_WARNING_PRINTF("sema_wait_end timeout:%d\r\n", status); -} - -static void tadc_check_timer_poll_handle(void) -{ - ADC_OBJ *target; - - rtos_lock_mutex(&tadc_entity->obj_list_mutex); - for (target = tadc_entity->adc_obj_list; target; target = target->next) - tadc_obj_handler(target); - rtos_unlock_mutex(&tadc_entity->obj_list_mutex); -} - -void tadc_entity_deinit(TADC_ENTITY_T **adc_entity) -{ - TADC_WARNING_PRINTF("tadc_entity_deinit\r\n"); - if (*adc_entity) { - if ((*adc_entity)->sema_wait_end) { - rtos_deinit_semaphore(&((*adc_entity)->sema_wait_end)); - (*adc_entity)->sema_wait_end = NULL; - } - - if ((*adc_entity)->obj_list_mutex) { - rtos_deinit_mutex(&((*adc_entity)->obj_list_mutex)); - (*adc_entity)->obj_list_mutex = NULL; - } - - os_free((*adc_entity)); - *adc_entity = NULL; - } -} - -TADC_ENTITY_T *tadc_entity_init(void) -{ - TADC_ENTITY_T *adc_entity = NULL; - bk_err_t ret = 0; - - adc_entity = (TADC_ENTITY_T *) os_malloc(sizeof(TADC_ENTITY_T)); - if (adc_entity == NULL) { - TADC_FATAL_PRINTF("malloc TADC_ENTITY_T failed\r\n"); - return NULL; - } - - os_memset(adc_entity, 0, sizeof(TADC_ENTITY_T)); - TADC_WARNING_PRINTF("tc_entity_init\r\n"); - - ret = rtos_init_mutex(&adc_entity->obj_list_mutex); - if (ret != 0) { - TADC_FATAL_PRINTF("tc_entity->mutex error\r\n"); - tadc_entity_deinit(&adc_entity); - return NULL; - } - - ret = rtos_init_semaphore(&adc_entity->sema_wait_end, 1); - if (ret != 0) { - TADC_FATAL_PRINTF("tc_entity->sema_wait_end error\r\n"); - tadc_entity_deinit(&adc_entity); - return NULL; - } - - return adc_entity; -} - -#if (!CONFIG_SOC_BK7231) && (!CONFIG_SOC_BK7231N) && (!CONFIG_SOC_BK7236A) && (!CONFIG_SOC_BK7256XX) -/* -vol: PSRAM_VDD_1_8V - PSRAM_VDD_2_5V - PSRAM_VDD_3_3V -*/ -void saradc_config_vddram_voltage(UINT32 vol) -{ - UINT32 param; - - param = BLK_BIT_MIC_QSPI_RAM_OR_FLASH; - sddev_control(DD_DEV_TYPE_SCTRL, CMD_SCTRL_BLK_ENABLE, ¶m); - - param = vol; - sddev_control(DD_DEV_TYPE_SCTRL, CMD_QSPI_VDDRAM_VOLTAGE, ¶m); -} - -void saradc_disable_vddram_voltage(void) -{ - UINT32 param; - - param = BLK_BIT_MIC_QSPI_RAM_OR_FLASH; - sddev_control(DD_DEV_TYPE_SCTRL, CMD_SCTRL_BLK_DISABLE, ¶m); - -} -#endif - -void tadc_send_msg(UINT32 new_msg) -{ - bk_err_t ret; - TADC_MSG_T msg; - - if (tadc_entity->msg_que) { - msg.data = new_msg; - ret = rtos_push_to_queue(&tadc_entity->msg_que, &msg, BEKEN_NO_WAIT); - if (kNoErr != ret) - TADC_PRINTF("tadc_send_msg failed\r\n"); - } -} - -static void tadc_check_timer_callback(void *arg) -{ - UINT32 data = TADC_TIMER_POLL; - tadc_send_msg(data); -} - -static void tadc_thread_entry(beken_thread_arg_t data) -{ - bk_err_t err; - - TADC_WARNING_PRINTF("tadc_thread_entry\r\n"); - - err = rtos_init_queue(&tadc_entity->msg_que, - "tadc_msg_queue", - sizeof(TADC_MSG_T), - TURING_ADC_QITEM_COUNT); - if (kNoErr != err) { - TADC_FATAL_PRINTF("tadc_entity->msg_que\r\n"); - goto tadc_exit; - } - - err = rtos_init_timer(&tadc_entity->check_timer, - TURING_ADC_SCAN_INTERVALV, - tadc_check_timer_callback, - (void *)0); - BK_ASSERT(kNoErr == err); - - err = rtos_start_timer(&tadc_entity->check_timer); - BK_ASSERT(kNoErr == err); - - while (1) { - TADC_MSG_T msg; - err = rtos_pop_from_queue(&tadc_entity->msg_que, &msg, BEKEN_WAIT_FOREVER); - if (kNoErr == err) { - switch (msg.data) { - case TADC_TIMER_POLL: { - tadc_check_timer_poll_handle(); - break; - } - case TADC_EXIT: { - goto tadc_exit; - } - break; - default: - break; - } - } - } - -tadc_exit: - if (tadc_entity->check_timer.handle) { - err = rtos_deinit_timer(&tadc_entity->check_timer); - BK_ASSERT(kNoErr == err); - } - - if (tadc_entity->msg_que) { - rtos_deinit_queue(&tadc_entity->msg_que); - tadc_entity->msg_que = NULL; - } - - tadc_entity_deinit(&tadc_entity); - tadc_entity = NULL; - rtos_delete_thread(NULL); -} - -void saradc_work_create(void) -{ - bk_err_t result; - - TADC_WARNING_PRINTF("turing_adc_create\r\n"); - - if (tadc_entity) { - TADC_WARNING_PRINTF("aready turing_adc_create\r\n"); - return; - } - - tadc_entity = tadc_entity_init(); - if (NULL == tadc_entity) { - TADC_FATAL_PRINTF("turing_adc_create exceptional\r\n"); - goto create_exit; - } - - result = rtos_create_thread(&tadc_entity->tadc_thread, - TURING_ADC_TASK_PRIORITY, - TURING_ADC_TAG, - (beken_thread_function_t)tadc_thread_entry, - TURING_ADC_TASK_STACK_SIZE, - NULL); - if (result != kNoErr) { - TADC_FATAL_PRINTF("turing_adc_create exceptional\r\n"); - goto create_exit; - } - - TADC_WARNING_PRINTF("turing_adc_create done\r\n"); - return; - -create_exit: - - tadc_entity_deinit(&tadc_entity); -} - -#if (CONFIG_SARADC_CALI && (CONFIG_RTT)) -static void adc_check(int argc, char **argv) -{ - UINT32 status, ret; -#if CONFIG_FLASH_ORIGIN_API - DD_HANDLE flash_handle; -#endif - DD_HANDLE saradc_handle; - saradc_cal_val_t p_ADC_cal; - float voltage = 0.0; - saradc_desc_t *p_ADC_drv_desc = NULL; - GLOBAL_INT_DECLARATION(); - - if (argc < 2) - goto IDLE_CMD_ERR; - - if (0 == strcmp(argv[1], "read")) { - status = manual_cal_load_adc_cali_flash(); - if (status != 0) { - os_printf("Can't read cali value, use default!\r\n"); - os_printf("calibrate low value:[%x]\r\n", saradc_val.low); - os_printf("calibrate high value:[%x]\r\n", saradc_val.high); - } - } else if (0 == strcmp(argv[1], "set")) { - p_ADC_drv_desc = (saradc_desc_t *)malloc(sizeof(saradc_desc_t)); - if (p_ADC_drv_desc == NULL) { - os_printf("malloc1 failed!\r\n"); - return; - } - - os_memset(p_ADC_drv_desc, 0x00, sizeof(saradc_desc_t)); - saradc_config_param_init(p_ADC_drv_desc); - - p_ADC_drv_desc->channel = 1; - p_ADC_drv_desc->data_buff_size = ADC_TEMP_BUFFER_SIZE; - p_ADC_drv_desc->p_Int_Handler = NULL; - - p_ADC_drv_desc->has_data = 0; - p_ADC_drv_desc->current_read_data_cnt = 0; - p_ADC_drv_desc->current_sample_data_cnt = 0; - p_ADC_drv_desc->pData = (UINT16 *)malloc(p_ADC_drv_desc->data_buff_size * sizeof(UINT16)); - os_memset(p_ADC_drv_desc->pData, 0x00, p_ADC_drv_desc->data_buff_size * sizeof(UINT16)); - - if (p_ADC_drv_desc->pData == NULL) { - os_printf("malloc1 failed!\r\n"); - free(p_ADC_drv_desc); - return; - } - - ret = 0; - do { - GLOBAL_INT_DISABLE(); - if (saradc_check_busy() == 0) { - saradc_handle = ddev_open(DD_DEV_TYPE_SARADC, &status, (UINT32)p_ADC_drv_desc); - if (DD_HANDLE_UNVALID != saradc_handle) { - GLOBAL_INT_RESTORE(); - break; - } - } - GLOBAL_INT_RESTORE(); - - rtos_delay_milliseconds(5); - ret++; - } while (ret < 5); - - if (ret == 5) { - os_printf("saradc open failed!\r\n"); - free(p_ADC_drv_desc->pData); - free(p_ADC_drv_desc); - return; - } - - while (1) { - if (p_ADC_drv_desc->current_sample_data_cnt >= - p_ADC_drv_desc->data_buff_size) { - ddev_close(saradc_handle); - saradc_ensure_close(); - break; - } - } - - { - UINT32 sum = 0, sum1, sum2; - UINT16 *pData = p_ADC_drv_desc->pData; - sum1 = pData[1] + pData[2]; - sum2 = pData[3] + pData[4]; - sum = sum1 / 2 + sum2 / 2; - sum = sum / 2; - sum = sum / 4; - p_ADC_drv_desc->pData[0] = sum; - } - - if (0 == strcmp(argv[2], "low")) - p_ADC_cal.mode = SARADC_CALIBRATE_LOW; - else if (0 == strcmp(argv[2], "high")) - p_ADC_cal.mode = SARADC_CALIBRATE_HIGH; - else { - os_printf("invalid parameter\r\n"); - return; - } - p_ADC_cal.val = p_ADC_drv_desc->pData[0]; - if (SARADC_FAILURE == ddev_control(saradc_handle, SARADC_CMD_SET_CAL_VAL, (VOID *)&p_ADC_cal)) { - os_printf("set calibrate value failture\r\n"); - free(p_ADC_drv_desc->pData); - free(p_ADC_drv_desc); - return; - } - os_printf("set calibrate success\r\n"); - os_printf("type:[%s] value:[0x%x]\r\n", (p_ADC_cal.mode ? "high" : "low"), p_ADC_cal.val); - free(p_ADC_drv_desc->pData); - free(p_ADC_drv_desc); - } else if (0 == strcmp(argv[1], "write")) { - manual_cal_save_chipinfo_tab_to_flash(); - os_printf("calibrate low value:[%x]\r\n", saradc_val.low); - os_printf("calibrate high value:[%x]\r\n", saradc_val.high); - } else if (0 == strcmp(argv[1], "get")) { - p_ADC_drv_desc = (saradc_desc_t *)malloc(sizeof(saradc_desc_t)); - if (p_ADC_drv_desc == NULL) { - os_printf("malloc1 failed!\r\n"); - return; - } - - os_memset(p_ADC_drv_desc, 0x00, sizeof(saradc_desc_t)); - saradc_config_param_init(p_ADC_drv_desc); - p_ADC_drv_desc->p_Int_Handler = NULL; - - p_ADC_drv_desc->channel = 1; - if (argc > 2) - p_ADC_drv_desc->channel = atoi(argv[2]); - p_ADC_drv_desc->data_buff_size = ADC_TEMP_BUFFER_SIZE; - p_ADC_drv_desc->has_data = 0; - p_ADC_drv_desc->current_read_data_cnt = 0; - p_ADC_drv_desc->current_sample_data_cnt = 0; - p_ADC_drv_desc->pData = (UINT16 *)malloc(p_ADC_drv_desc->data_buff_size * sizeof(UINT16)); - os_memset(p_ADC_drv_desc->pData, 0x00, p_ADC_drv_desc->data_buff_size * sizeof(UINT16)); - - if (p_ADC_drv_desc->pData == NULL) { - os_printf("malloc1 failed!\r\n"); - free(p_ADC_drv_desc); - return; - } - - ret = 0; - do { - GLOBAL_INT_DISABLE(); - if (saradc_check_busy() == 0) { - saradc_handle = ddev_open(DD_DEV_TYPE_SARADC, &status, (UINT32)p_ADC_drv_desc); - if (DD_HANDLE_UNVALID != saradc_handle) { - GLOBAL_INT_RESTORE(); - break; - } - } - GLOBAL_INT_RESTORE(); - - rtos_delay_milliseconds(5); - ret++; - } while (ret < 5); - - if (ret == 5) { - os_printf("saradc open failed!\r\n"); - free(p_ADC_drv_desc->pData); - free(p_ADC_drv_desc); - return; - } - - while (1) { - if (p_ADC_drv_desc->current_sample_data_cnt >= p_ADC_drv_desc->data_buff_size) { - ddev_close(saradc_handle); - saradc_ensure_close(); - break; - } - } - - { - UINT32 sum = 0, sum1, sum2; - UINT16 *pData = p_ADC_drv_desc->pData; -#if (CONFIG_SOC_BK7231N) || (CONFIG_SOC_BK7236A) || (CONFIG_SOC_BK7256XX) - sum1 = pData[6] + pData[7]; - sum2 = pData[8] + pData[9]; -#else - sum1 = pData[1] + pData[2]; - sum2 = pData[3] + pData[4]; -#endif - sum = sum1 / 2 + sum2 / 2; - sum = sum / 2; - sum = sum / 4; - p_ADC_drv_desc->pData[0] = sum; - } - -#if (CONFIG_SOC_BK7231N) || (CONFIG_SOC_BK7236A) || (CONFIG_SOC_BK7256XX) - os_printf("saradc[ch%d]=%d\r\n", (UINT32)p_ADC_drv_desc->channel, (UINT32)p_ADC_drv_desc->pData[0]); -#else - voltage = saradc_calculate(p_ADC_drv_desc->pData[0]); - os_printf("voltage is [%d] mv\r\n", (UINT32)(voltage * 1000)); -#endif - free(p_ADC_drv_desc->pData); - free(p_ADC_drv_desc); - return; - } else - goto IDLE_CMD_ERR; - - return; -IDLE_CMD_ERR: - os_printf("Usage:ps [func] [param]\r\n"); -} - -MSH_CMD_EXPORT(adc_check, adc check); -#endif // (CONFIG_SARADC_CALI && (CONFIG_RTT)) - -static ADC_OBJ adc_test = {0}; - -void adc_detect_callback(int new_mv, void *user_data) -{ - ADC_OBJ *cfg = (ADC_OBJ *)user_data; - - TADC_WARNING_PRINTF("new:%d, %d\r\n", new_mv, cfg->channel); -} - -void adc_detect_configuration(UINT32 channel) -{ - TADC_WARNING_PRINTF("adc_detect %d, %d\r\n", channel, adc_test.channel); - - if (channel == adc_test.channel) - return; - - saradc_work_create(); - - if (adc_test.cb) - adc_obj_stop(&adc_test); - - adc_obj_init(&adc_test, adc_detect_callback, channel, &adc_test); - adc_obj_start(&adc_test); -} - diff --git a/bk7235/liteos_m/bk_sdk_armino/components/saradc_intf/saradc_intf.h b/bk7235/liteos_m/bk_sdk_armino/components/saradc_intf/saradc_intf.h index d6a40ecc5871ffa3c22461217049c13d4e334e7c..9cd5d18fbde1ece745e4eef4c8133c7a5313bd2f 100644 --- a/bk7235/liteos_m/bk_sdk_armino/components/saradc_intf/saradc_intf.h +++ b/bk7235/liteos_m/bk_sdk_armino/components/saradc_intf/saradc_intf.h @@ -1,3 +1,17 @@ +/* + * Copyright (C) 2022 Beken Corporation + * 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 __SARADC_INTF_H__ #define __SARADC_INTF_H__ diff --git a/bk7235/liteos_m/bk_sdk_armino/components/security/security_func.c b/bk7235/liteos_m/bk_sdk_armino/components/security/security_func.c deleted file mode 100644 index 3064e65a3142ced8551013698d6a10cb9505f0d9..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/components/security/security_func.c +++ /dev/null @@ -1,163 +0,0 @@ -#include "sys_rtos.h" -#include -#include - -#include -#include -#include "security_func.h" - -#include -#include "bk_uart.h" - -#if (CONFIG_SOC_BK7251) -#include "bk_security.h" -#endif - - -#if (CONFIG_SOC_BK7251) -void sec_Command(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -#if USE_SEC_TEST_CMD -{ - int sec = 0; - - if (argc > 5 || argc < 2) { - os_printf("Usage: sec.\r\n"); - return; - } - - if (0 == os_strcmp(argv[1], "aes")) { - unsigned char aes256_key[32] = {0x27, 0x73, 0x1a, 0xe6, 0x23, 0x4e, 0xd5, 0xab, 0xfb, 0x07, 0xd5, 0xc8, 0x69, 0x5f, 0x4a, 0x30, - 0x1c, 0x38, 0x2a, 0x09, 0x5b, 0x6f, 0x47, 0xd0, 0x2c, 0x9e, 0x1a, 0xf3, 0x0b, 0x54, 0x6d, 0x82 - }; - unsigned char aes256_block[16] = {0xa1, 0x2e, 0x84, 0x5c, 0x10, 0x93, 0xa6, 0x9f, 0x4e, 0xb0, 0x6d, 0xa4, 0x85, 0xa3, 0x8f, 0x5d}; - unsigned char aes256_ex_enc_expected[16] = {0x1b, 0x1e, 0x55, 0x4e, 0x65, 0xcb, 0x8d, 0x10, 0x9d, 0x95, 0x4e, 0xd4, 0x8d, 0xc2, 0xad, 0x6f}; - - - unsigned char aes256_enc_expected[16]; - unsigned char ex_aes256_block[16]; - void *ctx; - int i, key_len; - - if (argc == 3) { - key_len = os_strtoul(argv[2], NULL, 10);; - } else if (argc == 5) { - key_len = os_strtoul(argv[2], NULL, 10);; - - os_memset(aes256_block, 0, 16); - os_memset(aes256_key, 0, 32); - os_memcpy(aes256_block, argv[4], os_strlen(argv[4])); - os_memcpy(aes256_key, argv[3], os_strlen(argv[3])); - } else { - os_printf("Usage: sec aes_en key block\r\n"); - return; - } - - os_printf("key len%d: ", key_len); - for (i = 0; i < 32; i++) - os_printf("%x ", aes256_key[i]); - os_printf("\r\n"); - - os_printf("block: "); - for (i = 0; i < 16; i++) - os_printf("%x ", aes256_block[i]); - os_printf("\r\n"); - - os_printf("hw encrypt\r\n"); - ctx = hal_aes_init(aes256_key, key_len); - hal_aes_encrypt(ctx, aes256_block, aes256_enc_expected); - os_printf("en: "); - for (i = 0; i < 16; i++) - os_printf("%x ", aes256_enc_expected[i]); - os_printf("\r\n"); - - hal_aes_deinit(ctx); - - - os_printf("sw decrypt\r\n"); - ctx = aes_decrypt_init(aes256_key, key_len); - aes_decrypt(ctx, aes256_enc_expected, ex_aes256_block); - os_printf("de: "); - for (i = 0; i < 16; i++) - os_printf("%x ", ex_aes256_block[i]); - os_printf("\r\n"); - - aes_decrypt_deinit(ctx); - - if (0 != os_memcmp(aes256_block, ex_aes256_block, 16)) - os_printf("encrypt decrypt err\r\n"); - - - os_memset(aes256_enc_expected, 0, 16); - os_memset(ex_aes256_block, 0, 16); - - os_printf("sw encrypt\r\n"); - ctx = aes_encrypt_init(aes256_key, key_len); - aes_encrypt(ctx, aes256_block, aes256_enc_expected); - os_printf("en: "); - for (i = 0; i < 16; i++) - os_printf("%x ", aes256_enc_expected[i]); - os_printf("\r\n"); - - aes_encrypt_deinit(ctx); - - - os_printf("hw decrypt\r\n"); - ctx = hal_aes_init(aes256_key, key_len); - hal_aes_decrypt(ctx, aes256_enc_expected, ex_aes256_block); - os_printf("de: "); - for (i = 0; i < 16; i++) - os_printf("%x ", ex_aes256_block[i]); - os_printf("\r\n"); - hal_aes_deinit(ctx); - - } else if (0 == os_strcmp(argv[1], "sha1")) { - int i; - unsigned long sha_digst[16]; - void *ctx; - - os_memset(sha_digst, 0, 16 * 4); - - if (argc == 2) - argv[2] = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu"; - - ctx = hal_sha1_init(); - - hal_sha1_update(ctx, argv[2], os_strlen(argv[2])); - hal_sha1_finish(ctx, (UINT8 *)sha_digst); - - os_printf("RESULT:"); - for (i = 0; i < 16 * 4; i++) - os_printf("%x ", ((UINT8 *)sha_digst)[i]); - os_printf("\r\n"); - - } else if (0 == os_strcmp(argv[1], "sha256")) { - int i; - unsigned long sha_digst[16]; - void *ctx; - - os_memset(sha_digst, 0, 16 * 4); - - if (argc == 2) - argv[2] = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu"; - - ctx = hal_sha256_init(); - - hal_sha256_update(ctx, argv[2], os_strlen(argv[2])); - hal_sha256_finish(ctx, (UINT8 *)sha_digst); - - os_printf("RESULT:"); - for (i = 0; i < 16 * 4; i++) - os_printf("%x ", ((UINT8 *)sha_digst)[i]); - os_printf("\r\n"); - - - } else if (0 == os_strcmp(argv[1], "sha256_st")) - hal_sha256_self_test(1); -} -#else -{ -} -#endif - -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/components/security/security_func.h b/bk7235/liteos_m/bk_sdk_armino/components/security/security_func.h index 006fbb03132ae6ddf683d0d14100dc75ec3aa6ac..a50fa8c602b66e4e46e901c9651435563f50e960 100644 --- a/bk7235/liteos_m/bk_sdk_armino/components/security/security_func.h +++ b/bk7235/liteos_m/bk_sdk_armino/components/security/security_func.h @@ -1,3 +1,17 @@ +/* + * Copyright (C) 2022 Beken Corporation + * 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. + */ #define USE_SEC_TEST_CMD 0 extern int hal_sha256_self_test(int); diff --git a/bk7235/liteos_m/bk_sdk_armino/components/temp_detect/temp_detect.c b/bk7235/liteos_m/bk_sdk_armino/components/temp_detect/temp_detect.c index ee42dedd8fffb7cf63b8e0d968d0c759b02d9e8f..6ad77fe2bceebbda8460007ff65a842fe7f96c9f 100644 --- a/bk7235/liteos_m/bk_sdk_armino/components/temp_detect/temp_detect.c +++ b/bk7235/liteos_m/bk_sdk_armino/components/temp_detect/temp_detect.c @@ -1,3 +1,17 @@ +/* + * Copyright (C) 2022 Beken Corporation + * 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 #include "bk_arm_arch.h" #include "bk_misc.h" diff --git a/bk7235/liteos_m/bk_sdk_armino/components/utf8/conv_utf8.c b/bk7235/liteos_m/bk_sdk_armino/components/utf8/conv_utf8.c index 78b1ce499429b1fd520a965ce018ac98221fe786..8638d2f4d765083643aa328440d5d7e598c6794c 100644 --- a/bk7235/liteos_m/bk_sdk_armino/components/utf8/conv_utf8.c +++ b/bk7235/liteos_m/bk_sdk_armino/components/utf8/conv_utf8.c @@ -1,3 +1,17 @@ +/* + * Copyright (C) 2022 Beken Corporation + * 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 #include #include diff --git a/bk7235/liteos_m/bk_sdk_armino/components/utf8/conv_utf8_gb2312_table.h b/bk7235/liteos_m/bk_sdk_armino/components/utf8/conv_utf8_gb2312_table.h index 269a8d170e2819814344f22b8a3b52b48e790089..07b5048e9d3b61ade19c978a71cd3e5b9c8098a0 100644 --- a/bk7235/liteos_m/bk_sdk_armino/components/utf8/conv_utf8_gb2312_table.h +++ b/bk7235/liteos_m/bk_sdk_armino/components/utf8/conv_utf8_gb2312_table.h @@ -1,3 +1,17 @@ +/* + * Copyright (C) 2022 Beken Corporation + * 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 __T_GB2312_UTF8_H__ #define __T_GB2312_UTF8_H__ diff --git a/bk7235/liteos_m/bk_sdk_armino/components/utf8/conv_utf8_pub.h b/bk7235/liteos_m/bk_sdk_armino/components/utf8/conv_utf8_pub.h index 6f33c58b24f59d7a9847f11e5b648f871a5aabc1..3565f21daaa1b6c4fd730533d5260de84b800df1 100644 --- a/bk7235/liteos_m/bk_sdk_armino/components/utf8/conv_utf8_pub.h +++ b/bk7235/liteos_m/bk_sdk_armino/components/utf8/conv_utf8_pub.h @@ -1,3 +1,17 @@ +/* + * Copyright (C) 2022 Beken Corporation + * 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 __CONV_UTF8_PUB_H__ #define __CONV_UTF8_PUB_H__ diff --git a/bk7235/liteos_m/bk_sdk_armino/include/components/aud_intf.h b/bk7235/liteos_m/bk_sdk_armino/include/components/aud_intf.h index 04a872ba0bc9b324f2a6b52c2fd5dd78a1beeed9..e0ecefa0de2d5b118f96bd9860e0331de715b790 100755 --- a/bk7235/liteos_m/bk_sdk_armino/include/components/aud_intf.h +++ b/bk7235/liteos_m/bk_sdk_armino/include/components/aud_intf.h @@ -1,3 +1,17 @@ +/* + * Copyright (C) 2022 Beken Corporation + * 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. + */ #pragma once #include "aud_intf_types.h" diff --git a/bk7235/liteos_m/bk_sdk_armino/include/components/audio_transfer.h b/bk7235/liteos_m/bk_sdk_armino/include/components/audio_transfer.h index afcd10d83cc597e11be98eb8d971fac87e078f30..2a881aa58683513237b434b77cad7f22f39faeb3 100755 --- a/bk7235/liteos_m/bk_sdk_armino/include/components/audio_transfer.h +++ b/bk7235/liteos_m/bk_sdk_armino/include/components/audio_transfer.h @@ -1,3 +1,17 @@ +/* + * Copyright (C) 2022 Beken Corporation + * 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. + */ #pragma once #include diff --git a/bk7235/liteos_m/bk_sdk_armino/include/components/audio_transfer_types.h b/bk7235/liteos_m/bk_sdk_armino/include/components/audio_transfer_types.h index 337969d98e47dd3c809e6aeb243b7816cf0ba4fc..c44d74efe26cb2603c6a9b5c9437dfe718a0197c 100755 --- a/bk7235/liteos_m/bk_sdk_armino/include/components/audio_transfer_types.h +++ b/bk7235/liteos_m/bk_sdk_armino/include/components/audio_transfer_types.h @@ -1,3 +1,17 @@ +/* + * Copyright (C) 2022 Beken Corporation + * 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. + */ #pragma once #ifdef __cplusplus diff --git a/bk7235/liteos_m/bk_sdk_armino/include/components/shell_task.h b/bk7235/liteos_m/bk_sdk_armino/include/components/shell_task.h index 577f861628195d3f9857343834e600436cf06123..a087ab105d814211850300d43fdbbb4e100bf5b9 100755 --- a/bk7235/liteos_m/bk_sdk_armino/include/components/shell_task.h +++ b/bk7235/liteos_m/bk_sdk_armino/include/components/shell_task.h @@ -1,3 +1,17 @@ +/* + * Copyright (C) 2022 Beken Corporation + * 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 _shell_task_h_ #define _shell_task_h_ diff --git a/bk7235/liteos_m/bk_sdk_armino/include/driver/lcd_spi.h b/bk7235/liteos_m/bk_sdk_armino/include/driver/lcd_spi.h index 1844dc7c98f35d3a6b2de941ef9fab836c0ccd9d..ee5a48db3c4164431a5bd0ea7b62ca74fda37798 100755 --- a/bk7235/liteos_m/bk_sdk_armino/include/driver/lcd_spi.h +++ b/bk7235/liteos_m/bk_sdk_armino/include/driver/lcd_spi.h @@ -1,3 +1,17 @@ +/* + * Copyright (C) 2022 Beken Corporation + * 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. + */ #pragma once #include "driver/dvp_camera_types.h" diff --git a/bk7235/liteos_m/bk_sdk_armino/include/extra/easyflash.h b/bk7235/liteos_m/bk_sdk_armino/include/extra/easyflash.h deleted file mode 100755 index 85419e85e71ff4ddff7d5bf64103a86c21236127..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/extra/easyflash.h +++ /dev/null @@ -1,149 +0,0 @@ -/* - * This file is part of the EasyFlash Library. - * - * Copyright (c) 2014-2018, Armink, - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * 'Software'), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice shall be - * included in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY - * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE - * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * Function: It is an head file for this library. You can see all be called functions. - * Created on: 2014-09-10 - */ -#ifndef _EASYFLASH_H_ -#define _EASYFLASH_H_ - -#include -#include -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -#if defined(EF_USING_ENV) && (!defined(ENV_USER_SETTING_SIZE) || !defined(ENV_AREA_SIZE)) -#error "Please configure user setting ENV size or ENV area size (in ef_cfg.h)" -#endif - -#if defined(EF_USING_LOG) && !defined(LOG_AREA_SIZE) -#error "Please configure log area size (in ef_cfg.h)" -#endif - -#if !defined(EF_START_ADDR) -#error "Please configure backup area start address (in ef_cfg.h)" -#endif - -#if !defined(EF_ERASE_MIN_SIZE) -#error "Please configure minimum size of flash erasure (in ef_cfg.h)" -#endif - -/* EasyFlash debug print function. Must be implement by user. */ -#define EF_DEBUG(...) ef_log_debug(__FILE__, __LINE__, __VA_ARGS__) -/* EasyFlash routine print function. Must be implement by user. */ -#define EF_INFO(...) ef_log_info(__VA_ARGS__) -/* EasyFlash assert for developer. */ -#define EF_ASSERT(EXPR) \ - if (!(EXPR)) \ - { \ - EF_DEBUG("(%s) has assert failed at %s.\n", #EXPR, __FUNCTION__); \ - while (1); \ - } -/* EasyFlash software version number */ -#define EF_SW_VERSION "3.0.4" - -typedef struct _ef_env { - char *key; - char *value; -} ef_env, *ef_env_t; - -/* EasyFlash error code */ -typedef enum { - EF_NO_ERR, - EF_ERASE_ERR, - EF_WRITE_ERR, - EF_ENV_NAME_ERR, - EF_ENV_NAME_EXIST, - EF_ENV_FULL, - EF_ENV_INIT_FAILED, -} EfErrCode; - -/* the flash sector current status */ -typedef enum { - EF_SECTOR_EMPTY, - EF_SECTOR_USING, - EF_SECTOR_FULL, -} EfSecrorStatus; - -/* easyflash.c */ -EfErrCode easyflash_init(void); - -#ifdef EF_USING_ENV -/* ef_env.c ef_env_wl.c */ -EfErrCode ef_load_env(void); -void ef_print_env(void); -char *ef_get_env(const char *key); -EfErrCode ef_set_env(const char *key, const char *value); -EfErrCode ef_save_env(void); -EfErrCode ef_env_set_default(void); -size_t ef_get_env_write_bytes(void); -EfErrCode ef_set_and_save_env(const char *key, const char *value); -#endif - -#ifdef EF_USING_IAP -/* ef_iap.c */ -EfErrCode ef_erase_bak_app(size_t app_size); -EfErrCode ef_erase_user_app(uint32_t user_app_addr, size_t user_app_size); -EfErrCode ef_erase_spec_user_app(uint32_t user_app_addr, size_t app_size, - EfErrCode(*app_erase)(uint32_t addr, size_t size)); -EfErrCode ef_erase_bl(uint32_t bl_addr, size_t bl_size); -EfErrCode ef_write_data_to_bak(uint8_t *data, size_t size, size_t *cur_size, - size_t total_size); -EfErrCode ef_copy_app_from_bak(uint32_t user_app_addr, size_t app_size); -EfErrCode ef_copy_spec_app_from_bak(uint32_t user_app_addr, size_t app_size, - EfErrCode(*app_write)(uint32_t addr, const uint32_t *buf, size_t size)); -EfErrCode ef_copy_bl_from_bak(uint32_t bl_addr, size_t bl_size); -uint32_t ef_get_bak_app_start_addr(void); -#endif - -#ifdef EF_USING_LOG -/* ef_log.c */ -EfErrCode ef_log_read(size_t index, uint32_t *log, size_t size); -EfErrCode ef_log_write(const uint32_t *log, size_t size); -EfErrCode ef_log_clean(void); -size_t ef_log_get_used_size(void); -#endif - -/* ef_utils.c */ -uint32_t ef_calc_crc32(uint32_t crc, const void *buf, size_t size); - -/* ef_port.c */ -EfErrCode ef_port_read(uint32_t addr, uint32_t *buf, size_t size); -EfErrCode ef_port_erase(uint32_t addr, size_t size); -EfErrCode ef_port_write(uint32_t addr, const uint32_t *buf, size_t size); -void ef_port_env_lock(void); -void ef_port_env_unlock(void); -void ef_log_debug(const char *file, const long line, const char *format, ...); -void ef_log_info(const char *format, ...); -void ef_print(const char *format, ...); - -#ifdef __cplusplus -} -#endif - -#endif /* EASYFLASH_H_ */ diff --git a/bk7235/liteos_m/bk_sdk_armino/include/extra/shell_task.h b/bk7235/liteos_m/bk_sdk_armino/include/extra/shell_task.h index af4acc96a6ee8c9d55e331c982d3ae75760cee2a..066c6b560a46904c057cb2adad83d4cc1f40c62b 100755 --- a/bk7235/liteos_m/bk_sdk_armino/include/extra/shell_task.h +++ b/bk7235/liteos_m/bk_sdk_armino/include/extra/shell_task.h @@ -1,3 +1,17 @@ +/* + * Copyright (C) 2022 Beken Corporation + * 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 _shell_task_h_ #define _shell_task_h_ diff --git a/bk7235/liteos_m/bk_sdk_armino/include/modules/avilib.h b/bk7235/liteos_m/bk_sdk_armino/include/modules/avilib.h index 9b10e6d70882908fc9bbdf1c4cb7e40bcbf5cb42..41a1c38d89219fa1f73cf50654c56aee9d283ad3 100755 --- a/bk7235/liteos_m/bk_sdk_armino/include/modules/avilib.h +++ b/bk7235/liteos_m/bk_sdk_armino/include/modules/avilib.h @@ -1,3 +1,17 @@ +/* + * Copyright (C) 2022 Beken Corporation + * 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 AVILIB_H #define AVILIB_H #ifdef __cplusplus diff --git a/bk7235/liteos_m/bk_sdk_armino/include/modules/image_scale.h b/bk7235/liteos_m/bk_sdk_armino/include/modules/image_scale.h index 666e241d4f9f6ee2946e6f5033481bc7995f117a..ec66075f9e2b12a8758f8b61a60fba5226293661 100755 --- a/bk7235/liteos_m/bk_sdk_armino/include/modules/image_scale.h +++ b/bk7235/liteos_m/bk_sdk_armino/include/modules/image_scale.h @@ -1,3 +1,17 @@ +/* + * Copyright (C) 2022 Beken Corporation + * 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. + */ #pragma once #ifdef __cplusplus diff --git a/bk7235/liteos_m/bk_sdk_armino/include/modules/opus.h b/bk7235/liteos_m/bk_sdk_armino/include/modules/opus.h deleted file mode 100755 index d282f21d25a719ff0e443cd332f3c388f4647deb..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/modules/opus.h +++ /dev/null @@ -1,981 +0,0 @@ -/* Copyright (c) 2010-2011 Xiph.Org Foundation, Skype Limited - Written by Jean-Marc Valin and Koen Vos */ -/* - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - - Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER - OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -/** - * @file opus.h - * @brief Opus reference implementation API - */ - -#ifndef OPUS_H -#define OPUS_H - -#include "opus_types.h" -#include "opus_defines.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @mainpage Opus - * - * The Opus codec is designed for interactive speech and audio transmission over the Internet. - * It is designed by the IETF Codec Working Group and incorporates technology from - * Skype's SILK codec and Xiph.Org's CELT codec. - * - * The Opus codec is designed to handle a wide range of interactive audio applications, - * including Voice over IP, videoconferencing, in-game chat, and even remote live music - * performances. It can scale from low bit-rate narrowband speech to very high quality - * stereo music. Its main features are: - - * @li Sampling rates from 8 to 48 kHz - * @li Bit-rates from 6 kb/s to 510 kb/s - * @li Support for both constant bit-rate (CBR) and variable bit-rate (VBR) - * @li Audio bandwidth from narrowband to full-band - * @li Support for speech and music - * @li Support for mono and stereo - * @li Support for multichannel (up to 255 channels) - * @li Frame sizes from 2.5 ms to 60 ms - * @li Good loss robustness and packet loss concealment (PLC) - * @li Floating point and fixed-point implementation - * - * Documentation sections: - * @li @ref opus_encoder - * @li @ref opus_decoder - * @li @ref opus_repacketizer - * @li @ref opus_multistream - * @li @ref opus_libinfo - * @li @ref opus_custom - */ - -/** @defgroup opus_encoder Opus Encoder - * @{ - * - * @brief This page describes the process and functions used to encode Opus. - * - * Since Opus is a stateful codec, the encoding process starts with creating an encoder - * state. This can be done with: - * - * @code - * int error; - * OpusEncoder *enc; - * enc = opus_encoder_create(Fs, channels, application, &error); - * @endcode - * - * From this point, @c enc can be used for encoding an audio stream. An encoder state - * @b must @b not be used for more than one stream at the same time. Similarly, the encoder - * state @b must @b not be re-initialized for each frame. - * - * While opus_encoder_create() allocates memory for the state, it's also possible - * to initialize pre-allocated memory: - * - * @code - * int size; - * int error; - * OpusEncoder *enc; - * size = opus_encoder_get_size(channels); - * enc = malloc(size); - * error = opus_encoder_init(enc, Fs, channels, application); - * @endcode - * - * where opus_encoder_get_size() returns the required size for the encoder state. Note that - * future versions of this code may change the size, so no assuptions should be made about it. - * - * The encoder state is always continuous in memory and only a shallow copy is sufficient - * to copy it (e.g. memcpy()) - * - * It is possible to change some of the encoder's settings using the opus_encoder_ctl() - * interface. All these settings already default to the recommended value, so they should - * only be changed when necessary. The most common settings one may want to change are: - * - * @code - * opus_encoder_ctl(enc, OPUS_SET_BITRATE(bitrate)); - * opus_encoder_ctl(enc, OPUS_SET_COMPLEXITY(complexity)); - * opus_encoder_ctl(enc, OPUS_SET_SIGNAL(signal_type)); - * @endcode - * - * where - * - * @arg bitrate is in bits per second (b/s) - * @arg complexity is a value from 1 to 10, where 1 is the lowest complexity and 10 is the highest - * @arg signal_type is either OPUS_AUTO (default), OPUS_SIGNAL_VOICE, or OPUS_SIGNAL_MUSIC - * - * See @ref opus_encoderctls and @ref opus_genericctls for a complete list of parameters that can be set or queried. Most parameters can be set or changed at any time during a stream. - * - * To encode a frame, opus_encode() or opus_encode_float() must be called with exactly one frame (2.5, 5, 10, 20, 40 or 60 ms) of audio data: - * @code - * len = opus_encode(enc, audio_frame, frame_size, packet, max_packet); - * @endcode - * - * where - *
    - *
  • audio_frame is the audio data in opus_int16 (or float for opus_encode_float())
  • - *
  • frame_size is the duration of the frame in samples (per channel)
  • - *
  • packet is the byte array to which the compressed data is written
  • - *
  • max_packet is the maximum number of bytes that can be written in the packet (4000 bytes is recommended). - * Do not use max_packet to control VBR target bitrate, instead use the #OPUS_SET_BITRATE CTL.
  • - *
- * - * opus_encode() and opus_encode_float() return the number of bytes actually written to the packet. - * The return value can be negative, which indicates that an error has occurred. If the return value - * is 2 bytes or less, then the packet does not need to be transmitted (DTX). - * - * Once the encoder state if no longer needed, it can be destroyed with - * - * @code - * opus_encoder_destroy(enc); - * @endcode - * - * If the encoder was created with opus_encoder_init() rather than opus_encoder_create(), - * then no action is required aside from potentially freeing the memory that was manually - * allocated for it (calling free(enc) for the example above) - * - */ - -/** Opus encoder state. - * This contains the complete state of an Opus encoder. - * It is position independent and can be freely copied. - * @see opus_encoder_create,opus_encoder_init - */ -typedef struct OpusEncoder OpusEncoder; - -/** Gets the size of an OpusEncoder structure. - * @param[in] channels int: Number of channels. - * This must be 1 or 2. - * @returns The size in bytes. - */ -OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_encoder_get_size(int channels); - -/** - */ - -/** Allocates and initializes an encoder state. - * There are three coding modes: - * - * @ref OPUS_APPLICATION_VOIP gives best quality at a given bitrate for voice - * signals. It enhances the input signal by high-pass filtering and - * emphasizing formants and harmonics. Optionally it includes in-band - * forward error correction to protect against packet loss. Use this - * mode for typical VoIP applications. Because of the enhancement, - * even at high bitrates the output may sound different from the input. - * - * @ref OPUS_APPLICATION_AUDIO gives best quality at a given bitrate for most - * non-voice signals like music. Use this mode for music and mixed - * (music/voice) content, broadcast, and applications requiring less - * than 15 ms of coding delay. - * - * @ref OPUS_APPLICATION_RESTRICTED_LOWDELAY configures low-delay mode that - * disables the speech-optimized mode in exchange for slightly reduced delay. - * This mode can only be set on an newly initialized or freshly reset encoder - * because it changes the codec delay. - * - * This is useful when the caller knows that the speech-optimized modes will not be needed (use with caution). - * @param [in] Fs opus_int32: Sampling rate of input signal (Hz) - * This must be one of 8000, 12000, 16000, - * 24000, or 48000. - * @param [in] channels int: Number of channels (1 or 2) in input signal - * @param [in] application int: Coding mode (@ref OPUS_APPLICATION_VOIP/@ref OPUS_APPLICATION_AUDIO/@ref OPUS_APPLICATION_RESTRICTED_LOWDELAY) - * @param [out] error int*: @ref opus_errorcodes - * @note Regardless of the sampling rate and number channels selected, the Opus encoder - * can switch to a lower audio bandwidth or number of channels if the bitrate - * selected is too low. This also means that it is safe to always use 48 kHz stereo input - * and let the encoder optimize the encoding. - */ -OPUS_EXPORT OPUS_WARN_UNUSED_RESULT OpusEncoder *opus_encoder_create( - opus_int32 Fs, - int channels, - int application, - int *error -); - -/** Initializes a previously allocated encoder state - * The memory pointed to by st must be at least the size returned by opus_encoder_get_size(). - * This is intended for applications which use their own allocator instead of malloc. - * @see opus_encoder_create(),opus_encoder_get_size() - * To reset a previously initialized state, use the #OPUS_RESET_STATE CTL. - * @param [in] st OpusEncoder*: Encoder state - * @param [in] Fs opus_int32: Sampling rate of input signal (Hz) - * This must be one of 8000, 12000, 16000, - * 24000, or 48000. - * @param [in] channels int: Number of channels (1 or 2) in input signal - * @param [in] application int: Coding mode (OPUS_APPLICATION_VOIP/OPUS_APPLICATION_AUDIO/OPUS_APPLICATION_RESTRICTED_LOWDELAY) - * @retval #OPUS_OK Success or @ref opus_errorcodes - */ -OPUS_EXPORT int opus_encoder_init( - OpusEncoder *st, - opus_int32 Fs, - int channels, - int application -) OPUS_ARG_NONNULL(1); - -/** Encodes an Opus frame. - * @param [in] st OpusEncoder*: Encoder state - * @param [in] pcm opus_int16*: Input signal (interleaved if 2 channels). length is frame_size*channels*sizeof(opus_int16) - * @param [in] frame_size int: Number of samples per channel in the - * input signal. - * This must be an Opus frame size for - * the encoder's sampling rate. - * For example, at 48 kHz the permitted - * values are 120, 240, 480, 960, 1920, - * and 2880. - * Passing in a duration of less than - * 10 ms (480 samples at 48 kHz) will - * prevent the encoder from using the LPC - * or hybrid modes. - * @param [out] data unsigned char*: Output payload. - * This must contain storage for at - * least \a max_data_bytes. - * @param [in] max_data_bytes opus_int32: Size of the allocated - * memory for the output - * payload. This may be - * used to impose an upper limit on - * the instant bitrate, but should - * not be used as the only bitrate - * control. Use #OPUS_SET_BITRATE to - * control the bitrate. - * @returns The length of the encoded packet (in bytes) on success or a - * negative error code (see @ref opus_errorcodes) on failure. - */ -OPUS_EXPORT OPUS_WARN_UNUSED_RESULT opus_int32 opus_encode( - OpusEncoder *st, - const opus_int16 *pcm, - int frame_size, - unsigned char *data, - opus_int32 max_data_bytes -) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(2) OPUS_ARG_NONNULL(4); - -/** Encodes an Opus frame from floating point input. - * @param [in] st OpusEncoder*: Encoder state - * @param [in] pcm float*: Input in float format (interleaved if 2 channels), with a normal range of +/-1.0. - * Samples with a range beyond +/-1.0 are supported but will - * be clipped by decoders using the integer API and should - * only be used if it is known that the far end supports - * extended dynamic range. - * length is frame_size*channels*sizeof(float) - * @param [in] frame_size int: Number of samples per channel in the - * input signal. - * This must be an Opus frame size for - * the encoder's sampling rate. - * For example, at 48 kHz the permitted - * values are 120, 240, 480, 960, 1920, - * and 2880. - * Passing in a duration of less than - * 10 ms (480 samples at 48 kHz) will - * prevent the encoder from using the LPC - * or hybrid modes. - * @param [out] data unsigned char*: Output payload. - * This must contain storage for at - * least \a max_data_bytes. - * @param [in] max_data_bytes opus_int32: Size of the allocated - * memory for the output - * payload. This may be - * used to impose an upper limit on - * the instant bitrate, but should - * not be used as the only bitrate - * control. Use #OPUS_SET_BITRATE to - * control the bitrate. - * @returns The length of the encoded packet (in bytes) on success or a - * negative error code (see @ref opus_errorcodes) on failure. - */ -OPUS_EXPORT OPUS_WARN_UNUSED_RESULT opus_int32 opus_encode_float( - OpusEncoder *st, - const float *pcm, - int frame_size, - unsigned char *data, - opus_int32 max_data_bytes -) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(2) OPUS_ARG_NONNULL(4); - -/** Frees an OpusEncoder allocated by opus_encoder_create(). - * @param[in] st OpusEncoder*: State to be freed. - */ -OPUS_EXPORT void opus_encoder_destroy(OpusEncoder *st); - -/** Perform a CTL function on an Opus encoder. - * - * Generally the request and subsequent arguments are generated - * by a convenience macro. - * @param st OpusEncoder*: Encoder state. - * @param request This and all remaining parameters should be replaced by one - * of the convenience macros in @ref opus_genericctls or - * @ref opus_encoderctls. - * @see opus_genericctls - * @see opus_encoderctls - */ -OPUS_EXPORT int opus_encoder_ctl(OpusEncoder *st, int request, ...) OPUS_ARG_NONNULL(1); -/**@}*/ - -/** @defgroup opus_decoder Opus Decoder - * @{ - * - * @brief This page describes the process and functions used to decode Opus. - * - * The decoding process also starts with creating a decoder - * state. This can be done with: - * @code - * int error; - * OpusDecoder *dec; - * dec = opus_decoder_create(Fs, channels, &error); - * @endcode - * where - * @li Fs is the sampling rate and must be 8000, 12000, 16000, 24000, or 48000 - * @li channels is the number of channels (1 or 2) - * @li error will hold the error code in case of failure (or #OPUS_OK on success) - * @li the return value is a newly created decoder state to be used for decoding - * - * While opus_decoder_create() allocates memory for the state, it's also possible - * to initialize pre-allocated memory: - * @code - * int size; - * int error; - * OpusDecoder *dec; - * size = opus_decoder_get_size(channels); - * dec = malloc(size); - * error = opus_decoder_init(dec, Fs, channels); - * @endcode - * where opus_decoder_get_size() returns the required size for the decoder state. Note that - * future versions of this code may change the size, so no assuptions should be made about it. - * - * The decoder state is always continuous in memory and only a shallow copy is sufficient - * to copy it (e.g. memcpy()) - * - * To decode a frame, opus_decode() or opus_decode_float() must be called with a packet of compressed audio data: - * @code - * frame_size = opus_decode(dec, packet, len, decoded, max_size, 0); - * @endcode - * where - * - * @li packet is the byte array containing the compressed data - * @li len is the exact number of bytes contained in the packet - * @li decoded is the decoded audio data in opus_int16 (or float for opus_decode_float()) - * @li max_size is the max duration of the frame in samples (per channel) that can fit into the decoded_frame array - * - * opus_decode() and opus_decode_float() return the number of samples (per channel) decoded from the packet. - * If that value is negative, then an error has occurred. This can occur if the packet is corrupted or if the audio - * buffer is too small to hold the decoded audio. - * - * Opus is a stateful codec with overlapping blocks and as a result Opus - * packets are not coded independently of each other. Packets must be - * passed into the decoder serially and in the correct order for a correct - * decode. Lost packets can be replaced with loss concealment by calling - * the decoder with a null pointer and zero length for the missing packet. - * - * A single codec state may only be accessed from a single thread at - * a time and any required locking must be performed by the caller. Separate - * streams must be decoded with separate decoder states and can be decoded - * in parallel unless the library was compiled with NONTHREADSAFE_PSEUDOSTACK - * defined. - * - */ - -/** Opus decoder state. - * This contains the complete state of an Opus decoder. - * It is position independent and can be freely copied. - * @see opus_decoder_create,opus_decoder_init - */ -typedef struct OpusDecoder OpusDecoder; - -/** Gets the size of an OpusDecoder structure. - * @param [in] channels int: Number of channels. - * This must be 1 or 2. - * @returns The size in bytes. - */ -OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_decoder_get_size(int channels); - -/** Allocates and initializes a decoder state. - * @param [in] Fs opus_int32: Sample rate to decode at (Hz). - * This must be one of 8000, 12000, 16000, - * 24000, or 48000. - * @param [in] channels int: Number of channels (1 or 2) to decode - * @param [out] error int*: #OPUS_OK Success or @ref opus_errorcodes - * - * Internally Opus stores data at 48000 Hz, so that should be the default - * value for Fs. However, the decoder can efficiently decode to buffers - * at 8, 12, 16, and 24 kHz so if for some reason the caller cannot use - * data at the full sample rate, or knows the compressed data doesn't - * use the full frequency range, it can request decoding at a reduced - * rate. Likewise, the decoder is capable of filling in either mono or - * interleaved stereo pcm buffers, at the caller's request. - */ -OPUS_EXPORT OPUS_WARN_UNUSED_RESULT OpusDecoder *opus_decoder_create( - opus_int32 Fs, - int channels, - int *error -); - -/** Initializes a previously allocated decoder state. - * The state must be at least the size returned by opus_decoder_get_size(). - * This is intended for applications which use their own allocator instead of malloc. @see opus_decoder_create,opus_decoder_get_size - * To reset a previously initialized state, use the #OPUS_RESET_STATE CTL. - * @param [in] st OpusDecoder*: Decoder state. - * @param [in] Fs opus_int32: Sampling rate to decode to (Hz). - * This must be one of 8000, 12000, 16000, - * 24000, or 48000. - * @param [in] channels int: Number of channels (1 or 2) to decode - * @retval #OPUS_OK Success or @ref opus_errorcodes - */ -OPUS_EXPORT int opus_decoder_init( - OpusDecoder *st, - opus_int32 Fs, - int channels -) OPUS_ARG_NONNULL(1); - -/** Decode an Opus packet. - * @param [in] st OpusDecoder*: Decoder state - * @param [in] data char*: Input payload. Use a NULL pointer to indicate packet loss - * @param [in] len opus_int32: Number of bytes in payload* - * @param [out] pcm opus_int16*: Output signal (interleaved if 2 channels). length - * is frame_size*channels*sizeof(opus_int16) - * @param [in] frame_size Number of samples per channel of available space in \a pcm. - * If this is less than the maximum packet duration (120ms; 5760 for 48kHz), this function will - * not be capable of decoding some packets. In the case of PLC (data==NULL) or FEC (decode_fec=1), - * then frame_size needs to be exactly the duration of audio that is missing, otherwise the - * decoder will not be in the optimal state to decode the next incoming packet. For the PLC and - * FEC cases, frame_size must be a multiple of 2.5 ms. - * @param [in] decode_fec int: Flag (0 or 1) to request that any in-band forward error correction data be - * decoded. If no such data is available, the frame is decoded as if it were lost. - * @returns Number of decoded samples or @ref opus_errorcodes - */ -OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_decode( - OpusDecoder *st, - const unsigned char *data, - opus_int32 len, - opus_int16 *pcm, - int frame_size, - int decode_fec -) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(4); - -/** Decode an Opus packet with floating point output. - * @param [in] st OpusDecoder*: Decoder state - * @param [in] data char*: Input payload. Use a NULL pointer to indicate packet loss - * @param [in] len opus_int32: Number of bytes in payload - * @param [out] pcm float*: Output signal (interleaved if 2 channels). length - * is frame_size*channels*sizeof(float) - * @param [in] frame_size Number of samples per channel of available space in \a pcm. - * If this is less than the maximum packet duration (120ms; 5760 for 48kHz), this function will - * not be capable of decoding some packets. In the case of PLC (data==NULL) or FEC (decode_fec=1), - * then frame_size needs to be exactly the duration of audio that is missing, otherwise the - * decoder will not be in the optimal state to decode the next incoming packet. For the PLC and - * FEC cases, frame_size must be a multiple of 2.5 ms. - * @param [in] decode_fec int: Flag (0 or 1) to request that any in-band forward error correction data be - * decoded. If no such data is available the frame is decoded as if it were lost. - * @returns Number of decoded samples or @ref opus_errorcodes - */ -OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_decode_float( - OpusDecoder *st, - const unsigned char *data, - opus_int32 len, - float *pcm, - int frame_size, - int decode_fec -) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(4); - -/** Perform a CTL function on an Opus decoder. - * - * Generally the request and subsequent arguments are generated - * by a convenience macro. - * @param st OpusDecoder*: Decoder state. - * @param request This and all remaining parameters should be replaced by one - * of the convenience macros in @ref opus_genericctls or - * @ref opus_decoderctls. - * @see opus_genericctls - * @see opus_decoderctls - */ -OPUS_EXPORT int opus_decoder_ctl(OpusDecoder *st, int request, ...) OPUS_ARG_NONNULL(1); - -/** Frees an OpusDecoder allocated by opus_decoder_create(). - * @param[in] st OpusDecoder*: State to be freed. - */ -OPUS_EXPORT void opus_decoder_destroy(OpusDecoder *st); - -/** Parse an opus packet into one or more frames. - * Opus_decode will perform this operation internally so most applications do - * not need to use this function. - * This function does not copy the frames, the returned pointers are pointers into - * the input packet. - * @param [in] data char*: Opus packet to be parsed - * @param [in] len opus_int32: size of data - * @param [out] out_toc char*: TOC pointer - * @param [out] frames char*[48] encapsulated frames - * @param [out] size opus_int16[48] sizes of the encapsulated frames - * @param [out] payload_offset int*: returns the position of the payload within the packet (in bytes) - * @returns number of frames - */ -OPUS_EXPORT int opus_packet_parse( - const unsigned char *data, - opus_int32 len, - unsigned char *out_toc, - const unsigned char *frames[48], - opus_int16 size[48], - int *payload_offset -) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(5); - -/** Gets the bandwidth of an Opus packet. - * @param [in] data char*: Opus packet - * @retval OPUS_BANDWIDTH_NARROWBAND Narrowband (4kHz bandpass) - * @retval OPUS_BANDWIDTH_MEDIUMBAND Mediumband (6kHz bandpass) - * @retval OPUS_BANDWIDTH_WIDEBAND Wideband (8kHz bandpass) - * @retval OPUS_BANDWIDTH_SUPERWIDEBAND Superwideband (12kHz bandpass) - * @retval OPUS_BANDWIDTH_FULLBAND Fullband (20kHz bandpass) - * @retval OPUS_INVALID_PACKET The compressed data passed is corrupted or of an unsupported type - */ -OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_packet_get_bandwidth(const unsigned char *data) OPUS_ARG_NONNULL(1); - -/** Gets the number of samples per frame from an Opus packet. - * @param [in] data char*: Opus packet. - * This must contain at least one byte of - * data. - * @param [in] Fs opus_int32: Sampling rate in Hz. - * This must be a multiple of 400, or - * inaccurate results will be returned. - * @returns Number of samples per frame. - */ -OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_packet_get_samples_per_frame(const unsigned char *data, opus_int32 Fs) OPUS_ARG_NONNULL(1); - -/** Gets the number of channels from an Opus packet. - * @param [in] data char*: Opus packet - * @returns Number of channels - * @retval OPUS_INVALID_PACKET The compressed data passed is corrupted or of an unsupported type - */ -OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_packet_get_nb_channels(const unsigned char *data) OPUS_ARG_NONNULL(1); - -/** Gets the number of frames in an Opus packet. - * @param [in] packet char*: Opus packet - * @param [in] len opus_int32: Length of packet - * @returns Number of frames - * @retval OPUS_BAD_ARG Insufficient data was passed to the function - * @retval OPUS_INVALID_PACKET The compressed data passed is corrupted or of an unsupported type - */ -OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_packet_get_nb_frames(const unsigned char packet[], opus_int32 len) OPUS_ARG_NONNULL(1); - -/** Gets the number of samples of an Opus packet. - * @param [in] packet char*: Opus packet - * @param [in] len opus_int32: Length of packet - * @param [in] Fs opus_int32: Sampling rate in Hz. - * This must be a multiple of 400, or - * inaccurate results will be returned. - * @returns Number of samples - * @retval OPUS_BAD_ARG Insufficient data was passed to the function - * @retval OPUS_INVALID_PACKET The compressed data passed is corrupted or of an unsupported type - */ -OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_packet_get_nb_samples(const unsigned char packet[], opus_int32 len, opus_int32 Fs) OPUS_ARG_NONNULL(1); - -/** Gets the number of samples of an Opus packet. - * @param [in] dec OpusDecoder*: Decoder state - * @param [in] packet char*: Opus packet - * @param [in] len opus_int32: Length of packet - * @returns Number of samples - * @retval OPUS_BAD_ARG Insufficient data was passed to the function - * @retval OPUS_INVALID_PACKET The compressed data passed is corrupted or of an unsupported type - */ -OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_decoder_get_nb_samples(const OpusDecoder *dec, const unsigned char packet[], opus_int32 len) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(2); - -/** Applies soft-clipping to bring a float signal within the [-1,1] range. If - * the signal is already in that range, nothing is done. If there are values - * outside of [-1,1], then the signal is clipped as smoothly as possible to - * both fit in the range and avoid creating excessive distortion in the - * process. - * @param [in,out] pcm float*: Input PCM and modified PCM - * @param [in] frame_size int Number of samples per channel to process - * @param [in] channels int: Number of channels - * @param [in,out] softclip_mem float*: State memory for the soft clipping process (one float per channel, initialized to zero) - */ -OPUS_EXPORT void opus_pcm_soft_clip(float *pcm, int frame_size, int channels, float *softclip_mem); - - -/**@}*/ - -/** @defgroup opus_repacketizer Repacketizer - * @{ - * - * The repacketizer can be used to merge multiple Opus packets into a single - * packet or alternatively to split Opus packets that have previously been - * merged. Splitting valid Opus packets is always guaranteed to succeed, - * whereas merging valid packets only succeeds if all frames have the same - * mode, bandwidth, and frame size, and when the total duration of the merged - * packet is no more than 120 ms. The 120 ms limit comes from the - * specification and limits decoder memory requirements at a point where - * framing overhead becomes negligible. - * - * The repacketizer currently only operates on elementary Opus - * streams. It will not manipualte multistream packets successfully, except in - * the degenerate case where they consist of data from a single stream. - * - * The repacketizing process starts with creating a repacketizer state, either - * by calling opus_repacketizer_create() or by allocating the memory yourself, - * e.g., - * @code - * OpusRepacketizer *rp; - * rp = (OpusRepacketizer*)malloc(opus_repacketizer_get_size()); - * if (rp != NULL) - * opus_repacketizer_init(rp); - * @endcode - * - * Then the application should submit packets with opus_repacketizer_cat(), - * extract new packets with opus_repacketizer_out() or - * opus_repacketizer_out_range(), and then reset the state for the next set of - * input packets via opus_repacketizer_init(). - * - * For example, to split a sequence of packets into individual frames: - * @code - * unsigned char *data; - * int len; - * while (get_next_packet(&data, &len)) - * { - * unsigned char out[1276]; - * opus_int32 out_len; - * int nb_frames; - * int err; - * int i; - * err = opus_repacketizer_cat(rp, data, len); - * if (err != OPUS_OK) - * { - * release_packet(data); - * return err; - * } - * nb_frames = opus_repacketizer_get_nb_frames(rp); - * for (i = 0; i < nb_frames; i++) - * { - * out_len = opus_repacketizer_out_range(rp, i, i+1, out, sizeof(out)); - * if (out_len < 0) - * { - * release_packet(data); - * return (int)out_len; - * } - * output_next_packet(out, out_len); - * } - * opus_repacketizer_init(rp); - * release_packet(data); - * } - * @endcode - * - * Alternatively, to combine a sequence of frames into packets that each - * contain up to TARGET_DURATION_MS milliseconds of data: - * @code - * // The maximum number of packets with duration TARGET_DURATION_MS occurs - * // when the frame size is 2.5 ms, for a total of (TARGET_DURATION_MS*2/5) - * // packets. - * unsigned char *data[(TARGET_DURATION_MS*2/5)+1]; - * opus_int32 len[(TARGET_DURATION_MS*2/5)+1]; - * int nb_packets; - * unsigned char out[1277*(TARGET_DURATION_MS*2/2)]; - * opus_int32 out_len; - * int prev_toc; - * nb_packets = 0; - * while (get_next_packet(data+nb_packets, len+nb_packets)) - * { - * int nb_frames; - * int err; - * nb_frames = opus_packet_get_nb_frames(data[nb_packets], len[nb_packets]); - * if (nb_frames < 1) - * { - * release_packets(data, nb_packets+1); - * return nb_frames; - * } - * nb_frames += opus_repacketizer_get_nb_frames(rp); - * // If adding the next packet would exceed our target, or it has an - * // incompatible TOC sequence, output the packets we already have before - * // submitting it. - * // N.B., The nb_packets > 0 check ensures we've submitted at least one - * // packet since the last call to opus_repacketizer_init(). Otherwise a - * // single packet longer than TARGET_DURATION_MS would cause us to try to - * // output an (invalid) empty packet. It also ensures that prev_toc has - * // been set to a valid value. Additionally, len[nb_packets] > 0 is - * // guaranteed by the call to opus_packet_get_nb_frames() above, so the - * // reference to data[nb_packets][0] should be valid. - * if (nb_packets > 0 && ( - * ((prev_toc & 0xFC) != (data[nb_packets][0] & 0xFC)) || - * opus_packet_get_samples_per_frame(data[nb_packets], 48000)*nb_frames > - * TARGET_DURATION_MS*48)) - * { - * out_len = opus_repacketizer_out(rp, out, sizeof(out)); - * if (out_len < 0) - * { - * release_packets(data, nb_packets+1); - * return (int)out_len; - * } - * output_next_packet(out, out_len); - * opus_repacketizer_init(rp); - * release_packets(data, nb_packets); - * data[0] = data[nb_packets]; - * len[0] = len[nb_packets]; - * nb_packets = 0; - * } - * err = opus_repacketizer_cat(rp, data[nb_packets], len[nb_packets]); - * if (err != OPUS_OK) - * { - * release_packets(data, nb_packets+1); - * return err; - * } - * prev_toc = data[nb_packets][0]; - * nb_packets++; - * } - * // Output the final, partial packet. - * if (nb_packets > 0) - * { - * out_len = opus_repacketizer_out(rp, out, sizeof(out)); - * release_packets(data, nb_packets); - * if (out_len < 0) - * return (int)out_len; - * output_next_packet(out, out_len); - * } - * @endcode - * - * An alternate way of merging packets is to simply call opus_repacketizer_cat() - * unconditionally until it fails. At that point, the merged packet can be - * obtained with opus_repacketizer_out() and the input packet for which - * opus_repacketizer_cat() needs to be re-added to a newly reinitialized - * repacketizer state. - */ - -typedef struct OpusRepacketizer OpusRepacketizer; - -/** Gets the size of an OpusRepacketizer structure. - * @returns The size in bytes. - */ -OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_repacketizer_get_size(void); - -/** (Re)initializes a previously allocated repacketizer state. - * The state must be at least the size returned by opus_repacketizer_get_size(). - * This can be used for applications which use their own allocator instead of - * malloc(). - * It must also be called to reset the queue of packets waiting to be - * repacketized, which is necessary if the maximum packet duration of 120 ms - * is reached or if you wish to submit packets with a different Opus - * configuration (coding mode, audio bandwidth, frame size, or channel count). - * Failure to do so will prevent a new packet from being added with - * opus_repacketizer_cat(). - * @see opus_repacketizer_create - * @see opus_repacketizer_get_size - * @see opus_repacketizer_cat - * @param rp OpusRepacketizer*: The repacketizer state to - * (re)initialize. - * @returns A pointer to the same repacketizer state that was passed in. - */ -OPUS_EXPORT OpusRepacketizer *opus_repacketizer_init(OpusRepacketizer *rp) OPUS_ARG_NONNULL(1); - -/** Allocates memory and initializes the new repacketizer with - * opus_repacketizer_init(). - */ -OPUS_EXPORT OPUS_WARN_UNUSED_RESULT OpusRepacketizer *opus_repacketizer_create(void); - -/** Frees an OpusRepacketizer allocated by - * opus_repacketizer_create(). - * @param[in] rp OpusRepacketizer*: State to be freed. - */ -OPUS_EXPORT void opus_repacketizer_destroy(OpusRepacketizer *rp); - -/** Add a packet to the current repacketizer state. - * This packet must match the configuration of any packets already submitted - * for repacketization since the last call to opus_repacketizer_init(). - * This means that it must have the same coding mode, audio bandwidth, frame - * size, and channel count. - * This can be checked in advance by examining the top 6 bits of the first - * byte of the packet, and ensuring they match the top 6 bits of the first - * byte of any previously submitted packet. - * The total duration of audio in the repacketizer state also must not exceed - * 120 ms, the maximum duration of a single packet, after adding this packet. - * - * The contents of the current repacketizer state can be extracted into new - * packets using opus_repacketizer_out() or opus_repacketizer_out_range(). - * - * In order to add a packet with a different configuration or to add more - * audio beyond 120 ms, you must clear the repacketizer state by calling - * opus_repacketizer_init(). - * If a packet is too large to add to the current repacketizer state, no part - * of it is added, even if it contains multiple frames, some of which might - * fit. - * If you wish to be able to add parts of such packets, you should first use - * another repacketizer to split the packet into pieces and add them - * individually. - * @see opus_repacketizer_out_range - * @see opus_repacketizer_out - * @see opus_repacketizer_init - * @param rp OpusRepacketizer*: The repacketizer state to which to - * add the packet. - * @param[in] data const unsigned char*: The packet data. - * The application must ensure - * this pointer remains valid - * until the next call to - * opus_repacketizer_init() or - * opus_repacketizer_destroy(). - * @param len opus_int32: The number of bytes in the packet data. - * @returns An error code indicating whether or not the operation succeeded. - * @retval #OPUS_OK The packet's contents have been added to the repacketizer - * state. - * @retval #OPUS_INVALID_PACKET The packet did not have a valid TOC sequence, - * the packet's TOC sequence was not compatible - * with previously submitted packets (because - * the coding mode, audio bandwidth, frame size, - * or channel count did not match), or adding - * this packet would increase the total amount of - * audio stored in the repacketizer state to more - * than 120 ms. - */ -OPUS_EXPORT int opus_repacketizer_cat(OpusRepacketizer *rp, const unsigned char *data, opus_int32 len) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(2); - - -/** Construct a new packet from data previously submitted to the repacketizer - * state via opus_repacketizer_cat(). - * @param rp OpusRepacketizer*: The repacketizer state from which to - * construct the new packet. - * @param begin int: The index of the first frame in the current - * repacketizer state to include in the output. - * @param end int: One past the index of the last frame in the - * current repacketizer state to include in the - * output. - * @param[out] data const unsigned char*: The buffer in which to - * store the output packet. - * @param maxlen opus_int32: The maximum number of bytes to store in - * the output buffer. In order to guarantee - * success, this should be at least - * 1276 for a single frame, - * or for multiple frames, - * 1277*(end-begin). - * However, 1*(end-begin) plus - * the size of all packet data submitted to - * the repacketizer since the last call to - * opus_repacketizer_init() or - * opus_repacketizer_create() is also - * sufficient, and possibly much smaller. - * @returns The total size of the output packet on success, or an error code - * on failure. - * @retval #OPUS_BAD_ARG [begin,end) was an invalid range of - * frames (begin < 0, begin >= end, or end > - * opus_repacketizer_get_nb_frames()). - * @retval #OPUS_BUFFER_TOO_SMALL \a maxlen was insufficient to contain the - * complete output packet. - */ -OPUS_EXPORT OPUS_WARN_UNUSED_RESULT opus_int32 opus_repacketizer_out_range(OpusRepacketizer *rp, int begin, int end, unsigned char *data, opus_int32 maxlen) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(4); - -/** Return the total number of frames contained in packet data submitted to - * the repacketizer state so far via opus_repacketizer_cat() since the last - * call to opus_repacketizer_init() or opus_repacketizer_create(). - * This defines the valid range of packets that can be extracted with - * opus_repacketizer_out_range() or opus_repacketizer_out(). - * @param rp OpusRepacketizer*: The repacketizer state containing the - * frames. - * @returns The total number of frames contained in the packet data submitted - * to the repacketizer state. - */ -OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_repacketizer_get_nb_frames(OpusRepacketizer *rp) OPUS_ARG_NONNULL(1); - -/** Construct a new packet from data previously submitted to the repacketizer - * state via opus_repacketizer_cat(). - * This is a convenience routine that returns all the data submitted so far - * in a single packet. - * It is equivalent to calling - * @code - * opus_repacketizer_out_range(rp, 0, opus_repacketizer_get_nb_frames(rp), - * data, maxlen) - * @endcode - * @param rp OpusRepacketizer*: The repacketizer state from which to - * construct the new packet. - * @param[out] data const unsigned char*: The buffer in which to - * store the output packet. - * @param maxlen opus_int32: The maximum number of bytes to store in - * the output buffer. In order to guarantee - * success, this should be at least - * 1277*opus_repacketizer_get_nb_frames(rp). - * However, - * 1*opus_repacketizer_get_nb_frames(rp) - * plus the size of all packet data - * submitted to the repacketizer since the - * last call to opus_repacketizer_init() or - * opus_repacketizer_create() is also - * sufficient, and possibly much smaller. - * @returns The total size of the output packet on success, or an error code - * on failure. - * @retval #OPUS_BUFFER_TOO_SMALL \a maxlen was insufficient to contain the - * complete output packet. - */ -OPUS_EXPORT OPUS_WARN_UNUSED_RESULT opus_int32 opus_repacketizer_out(OpusRepacketizer *rp, unsigned char *data, opus_int32 maxlen) OPUS_ARG_NONNULL(1); - -/** Pads a given Opus packet to a larger size (possibly changing the TOC sequence). - * @param[in,out] data const unsigned char*: The buffer containing the - * packet to pad. - * @param len opus_int32: The size of the packet. - * This must be at least 1. - * @param new_len opus_int32: The desired size of the packet after padding. - * This must be at least as large as len. - * @returns an error code - * @retval #OPUS_OK \a on success. - * @retval #OPUS_BAD_ARG \a len was less than 1 or new_len was less than len. - * @retval #OPUS_INVALID_PACKET \a data did not contain a valid Opus packet. - */ -OPUS_EXPORT int opus_packet_pad(unsigned char *data, opus_int32 len, opus_int32 new_len); - -/** Remove all padding from a given Opus packet and rewrite the TOC sequence to - * minimize space usage. - * @param[in,out] data const unsigned char*: The buffer containing the - * packet to strip. - * @param len opus_int32: The size of the packet. - * This must be at least 1. - * @returns The new size of the output packet on success, or an error code - * on failure. - * @retval #OPUS_BAD_ARG \a len was less than 1. - * @retval #OPUS_INVALID_PACKET \a data did not contain a valid Opus packet. - */ -OPUS_EXPORT OPUS_WARN_UNUSED_RESULT opus_int32 opus_packet_unpad(unsigned char *data, opus_int32 len); - -/** Pads a given Opus multi-stream packet to a larger size (possibly changing the TOC sequence). - * @param[in,out] data const unsigned char*: The buffer containing the - * packet to pad. - * @param len opus_int32: The size of the packet. - * This must be at least 1. - * @param new_len opus_int32: The desired size of the packet after padding. - * This must be at least 1. - * @param nb_streams opus_int32: The number of streams (not channels) in the packet. - * This must be at least as large as len. - * @returns an error code - * @retval #OPUS_OK \a on success. - * @retval #OPUS_BAD_ARG \a len was less than 1. - * @retval #OPUS_INVALID_PACKET \a data did not contain a valid Opus packet. - */ -OPUS_EXPORT int opus_multistream_packet_pad(unsigned char *data, opus_int32 len, opus_int32 new_len, int nb_streams); - -/** Remove all padding from a given Opus multi-stream packet and rewrite the TOC sequence to - * minimize space usage. - * @param[in,out] data const unsigned char*: The buffer containing the - * packet to strip. - * @param len opus_int32: The size of the packet. - * This must be at least 1. - * @param nb_streams opus_int32: The number of streams (not channels) in the packet. - * This must be at least 1. - * @returns The new size of the output packet on success, or an error code - * on failure. - * @retval #OPUS_BAD_ARG \a len was less than 1 or new_len was less than len. - * @retval #OPUS_INVALID_PACKET \a data did not contain a valid Opus packet. - */ -OPUS_EXPORT OPUS_WARN_UNUSED_RESULT opus_int32 opus_multistream_packet_unpad(unsigned char *data, opus_int32 len, int nb_streams); - -/**@}*/ - -#ifdef __cplusplus -} -#endif - -#endif /* OPUS_H */ diff --git a/bk7235/liteos_m/bk_sdk_armino/include/modules/opus_custom.h b/bk7235/liteos_m/bk_sdk_armino/include/modules/opus_custom.h deleted file mode 100755 index 41f36bf2fbc90966935771c11093b7580cc4f912..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/modules/opus_custom.h +++ /dev/null @@ -1,342 +0,0 @@ -/* Copyright (c) 2007-2008 CSIRO - Copyright (c) 2007-2009 Xiph.Org Foundation - Copyright (c) 2008-2012 Gregory Maxwell - Written by Jean-Marc Valin and Gregory Maxwell */ -/* - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - - Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER - OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -/** - @file opus_custom.h - @brief Opus-Custom reference implementation API - */ - -#ifndef OPUS_CUSTOM_H -#define OPUS_CUSTOM_H - -#include "opus_defines.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifdef CUSTOM_MODES -# define OPUS_CUSTOM_EXPORT OPUS_EXPORT -# define OPUS_CUSTOM_EXPORT_STATIC OPUS_EXPORT -#else -# define OPUS_CUSTOM_EXPORT -# ifdef OPUS_BUILD -# define OPUS_CUSTOM_EXPORT_STATIC static OPUS_INLINE -# else -# define OPUS_CUSTOM_EXPORT_STATIC -# endif -#endif - -/** @defgroup opus_custom Opus Custom - * @{ - * Opus Custom is an optional part of the Opus specification and - * reference implementation which uses a distinct API from the regular - * API and supports frame sizes that are not normally supported.\ Use - * of Opus Custom is discouraged for all but very special applications - * for which a frame size different from 2.5, 5, 10, or 20 ms is needed - * (for either complexity or latency reasons) and where interoperability - * is less important. - * - * In addition to the interoperability limitations the use of Opus custom - * disables a substantial chunk of the codec and generally lowers the - * quality available at a given bitrate. Normally when an application needs - * a different frame size from the codec it should buffer to match the - * sizes but this adds a small amount of delay which may be important - * in some very low latency applications. Some transports (especially - * constant rate RF transports) may also work best with frames of - * particular durations. - * - * Libopus only supports custom modes if they are enabled at compile time. - * - * The Opus Custom API is similar to the regular API but the - * @ref opus_encoder_create and @ref opus_decoder_create calls take - * an additional mode parameter which is a structure produced by - * a call to @ref opus_custom_mode_create. Both the encoder and decoder - * must create a mode using the same sample rate (fs) and frame size - * (frame size) so these parameters must either be signaled out of band - * or fixed in a particular implementation. - * - * Similar to regular Opus the custom modes support on the fly frame size - * switching, but the sizes available depend on the particular frame size in - * use. For some initial frame sizes on a single on the fly size is available. - */ - -/** Contains the state of an encoder. One encoder state is needed - for each stream. It is initialized once at the beginning of the - stream. Do *not* re-initialize the state for every frame. - @brief Encoder state - */ -typedef struct OpusCustomEncoder OpusCustomEncoder; - -/** State of the decoder. One decoder state is needed for each stream. - It is initialized once at the beginning of the stream. Do *not* - re-initialize the state for every frame. - @brief Decoder state - */ -typedef struct OpusCustomDecoder OpusCustomDecoder; - -/** The mode contains all the information necessary to create an - encoder. Both the encoder and decoder need to be initialized - with exactly the same mode, otherwise the output will be - corrupted. - @brief Mode configuration - */ -typedef struct OpusCustomMode OpusCustomMode; - -/** Creates a new mode struct. This will be passed to an encoder or - * decoder. The mode MUST NOT BE DESTROYED until the encoders and - * decoders that use it are destroyed as well. - * @param [in] Fs int: Sampling rate (8000 to 96000 Hz) - * @param [in] frame_size int: Number of samples (per channel) to encode in each - * packet (64 - 1024, prime factorization must contain zero or more 2s, 3s, or 5s and no other primes) - * @param [out] error int*: Returned error code (if NULL, no error will be returned) - * @return A newly created mode - */ -OPUS_CUSTOM_EXPORT OPUS_WARN_UNUSED_RESULT OpusCustomMode *opus_custom_mode_create(opus_int32 Fs, int frame_size, int *error); - -/** Destroys a mode struct. Only call this after all encoders and - * decoders using this mode are destroyed as well. - * @param [in] mode OpusCustomMode*: Mode to be freed. - */ -OPUS_CUSTOM_EXPORT void opus_custom_mode_destroy(OpusCustomMode *mode); - - -#if !defined(OPUS_BUILD) || defined(CELT_ENCODER_C) - -/* Encoder */ -/** Gets the size of an OpusCustomEncoder structure. - * @param [in] mode OpusCustomMode *: Mode configuration - * @param [in] channels int: Number of channels - * @returns size - */ -OPUS_CUSTOM_EXPORT_STATIC OPUS_WARN_UNUSED_RESULT int opus_custom_encoder_get_size( - const OpusCustomMode *mode, - int channels -) OPUS_ARG_NONNULL(1); - -# ifdef CUSTOM_MODES -/** Initializes a previously allocated encoder state - * The memory pointed to by st must be the size returned by opus_custom_encoder_get_size. - * This is intended for applications which use their own allocator instead of malloc. - * @see opus_custom_encoder_create(),opus_custom_encoder_get_size() - * To reset a previously initialized state use the OPUS_RESET_STATE CTL. - * @param [in] st OpusCustomEncoder*: Encoder state - * @param [in] mode OpusCustomMode *: Contains all the information about the characteristics of - * the stream (must be the same characteristics as used for the - * decoder) - * @param [in] channels int: Number of channels - * @return OPUS_OK Success or @ref opus_errorcodes - */ -OPUS_CUSTOM_EXPORT int opus_custom_encoder_init( - OpusCustomEncoder *st, - const OpusCustomMode *mode, - int channels -) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(2); -# endif -#endif - - -/** Creates a new encoder state. Each stream needs its own encoder - * state (can't be shared across simultaneous streams). - * @param [in] mode OpusCustomMode*: Contains all the information about the characteristics of - * the stream (must be the same characteristics as used for the - * decoder) - * @param [in] channels int: Number of channels - * @param [out] error int*: Returns an error code - * @return Newly created encoder state. -*/ -OPUS_CUSTOM_EXPORT OPUS_WARN_UNUSED_RESULT OpusCustomEncoder *opus_custom_encoder_create( - const OpusCustomMode *mode, - int channels, - int *error -) OPUS_ARG_NONNULL(1); - - -/** Destroys a an encoder state. - * @param[in] st OpusCustomEncoder*: State to be freed. - */ -OPUS_CUSTOM_EXPORT void opus_custom_encoder_destroy(OpusCustomEncoder *st); - -/** Encodes a frame of audio. - * @param [in] st OpusCustomEncoder*: Encoder state - * @param [in] pcm float*: PCM audio in float format, with a normal range of +/-1.0. - * Samples with a range beyond +/-1.0 are supported but will - * be clipped by decoders using the integer API and should - * only be used if it is known that the far end supports - * extended dynamic range. There must be exactly - * frame_size samples per channel. - * @param [in] frame_size int: Number of samples per frame of input signal - * @param [out] compressed char *: The compressed data is written here. This may not alias pcm and must be at least maxCompressedBytes long. - * @param [in] maxCompressedBytes int: Maximum number of bytes to use for compressing the frame - * (can change from one frame to another) - * @return Number of bytes written to "compressed". - * If negative, an error has occurred (see error codes). It is IMPORTANT that - * the length returned be somehow transmitted to the decoder. Otherwise, no - * decoding is possible. - */ -OPUS_CUSTOM_EXPORT OPUS_WARN_UNUSED_RESULT int opus_custom_encode_float( - OpusCustomEncoder *st, - const float *pcm, - int frame_size, - unsigned char *compressed, - int maxCompressedBytes -) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(2) OPUS_ARG_NONNULL(4); - -/** Encodes a frame of audio. - * @param [in] st OpusCustomEncoder*: Encoder state - * @param [in] pcm opus_int16*: PCM audio in signed 16-bit format (native endian). - * There must be exactly frame_size samples per channel. - * @param [in] frame_size int: Number of samples per frame of input signal - * @param [out] compressed char *: The compressed data is written here. This may not alias pcm and must be at least maxCompressedBytes long. - * @param [in] maxCompressedBytes int: Maximum number of bytes to use for compressing the frame - * (can change from one frame to another) - * @return Number of bytes written to "compressed". - * If negative, an error has occurred (see error codes). It is IMPORTANT that - * the length returned be somehow transmitted to the decoder. Otherwise, no - * decoding is possible. - */ -OPUS_CUSTOM_EXPORT OPUS_WARN_UNUSED_RESULT int opus_custom_encode( - OpusCustomEncoder *st, - const opus_int16 *pcm, - int frame_size, - unsigned char *compressed, - int maxCompressedBytes -) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(2) OPUS_ARG_NONNULL(4); - -/** Perform a CTL function on an Opus custom encoder. - * - * Generally the request and subsequent arguments are generated - * by a convenience macro. - * @see opus_encoderctls - */ -OPUS_CUSTOM_EXPORT int opus_custom_encoder_ctl(OpusCustomEncoder * OPUS_RESTRICT st, int request, ...) OPUS_ARG_NONNULL(1); - - -#if !defined(OPUS_BUILD) || defined(CELT_DECODER_C) -/* Decoder */ - -/** Gets the size of an OpusCustomDecoder structure. - * @param [in] mode OpusCustomMode *: Mode configuration - * @param [in] channels int: Number of channels - * @returns size - */ -OPUS_CUSTOM_EXPORT_STATIC OPUS_WARN_UNUSED_RESULT int opus_custom_decoder_get_size( - const OpusCustomMode *mode, - int channels -) OPUS_ARG_NONNULL(1); - -/** Initializes a previously allocated decoder state - * The memory pointed to by st must be the size returned by opus_custom_decoder_get_size. - * This is intended for applications which use their own allocator instead of malloc. - * @see opus_custom_decoder_create(),opus_custom_decoder_get_size() - * To reset a previously initialized state use the OPUS_RESET_STATE CTL. - * @param [in] st OpusCustomDecoder*: Decoder state - * @param [in] mode OpusCustomMode *: Contains all the information about the characteristics of - * the stream (must be the same characteristics as used for the - * encoder) - * @param [in] channels int: Number of channels - * @return OPUS_OK Success or @ref opus_errorcodes - */ -OPUS_CUSTOM_EXPORT_STATIC int opus_custom_decoder_init( - OpusCustomDecoder *st, - const OpusCustomMode *mode, - int channels -) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(2); - -#endif - - -/** Creates a new decoder state. Each stream needs its own decoder state (can't - * be shared across simultaneous streams). - * @param [in] mode OpusCustomMode: Contains all the information about the characteristics of the - * stream (must be the same characteristics as used for the encoder) - * @param [in] channels int: Number of channels - * @param [out] error int*: Returns an error code - * @return Newly created decoder state. - */ -OPUS_CUSTOM_EXPORT OPUS_WARN_UNUSED_RESULT OpusCustomDecoder *opus_custom_decoder_create( - const OpusCustomMode *mode, - int channels, - int *error -) OPUS_ARG_NONNULL(1); - -/** Destroys a an decoder state. - * @param[in] st OpusCustomDecoder*: State to be freed. - */ -OPUS_CUSTOM_EXPORT void opus_custom_decoder_destroy(OpusCustomDecoder *st); - -/** Decode an opus custom frame with floating point output - * @param [in] st OpusCustomDecoder*: Decoder state - * @param [in] data char*: Input payload. Use a NULL pointer to indicate packet loss - * @param [in] len int: Number of bytes in payload - * @param [out] pcm float*: Output signal (interleaved if 2 channels). length - * is frame_size*channels*sizeof(float) - * @param [in] frame_size Number of samples per channel of available space in *pcm. - * @returns Number of decoded samples or @ref opus_errorcodes - */ -OPUS_CUSTOM_EXPORT OPUS_WARN_UNUSED_RESULT int opus_custom_decode_float( - OpusCustomDecoder *st, - const unsigned char *data, - int len, - float *pcm, - int frame_size -) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(4); - -/** Decode an opus custom frame - * @param [in] st OpusCustomDecoder*: Decoder state - * @param [in] data char*: Input payload. Use a NULL pointer to indicate packet loss - * @param [in] len int: Number of bytes in payload - * @param [out] pcm opus_int16*: Output signal (interleaved if 2 channels). length - * is frame_size*channels*sizeof(opus_int16) - * @param [in] frame_size Number of samples per channel of available space in *pcm. - * @returns Number of decoded samples or @ref opus_errorcodes - */ -OPUS_CUSTOM_EXPORT OPUS_WARN_UNUSED_RESULT int opus_custom_decode( - OpusCustomDecoder *st, - const unsigned char *data, - int len, - opus_int16 *pcm, - int frame_size -) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(4); - -/** Perform a CTL function on an Opus custom decoder. - * - * Generally the request and subsequent arguments are generated - * by a convenience macro. - * @see opus_genericctls - */ -OPUS_CUSTOM_EXPORT int opus_custom_decoder_ctl(OpusCustomDecoder * OPUS_RESTRICT st, int request, ...) OPUS_ARG_NONNULL(1); - -/**@}*/ - -#ifdef __cplusplus -} -#endif - -#endif /* OPUS_CUSTOM_H */ diff --git a/bk7235/liteos_m/bk_sdk_armino/include/modules/opus_defines.h b/bk7235/liteos_m/bk_sdk_armino/include/modules/opus_defines.h deleted file mode 100755 index d141418b2146cc9bcdc3d4230dba092cd3b0ab1e..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/modules/opus_defines.h +++ /dev/null @@ -1,799 +0,0 @@ -/* Copyright (c) 2010-2011 Xiph.Org Foundation, Skype Limited - Written by Jean-Marc Valin and Koen Vos */ -/* - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - - Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER - OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -/** - * @file opus_defines.h - * @brief Opus reference implementation constants - */ - -#ifndef OPUS_DEFINES_H -#define OPUS_DEFINES_H - -#include "opus_types.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/** @defgroup opus_errorcodes Error codes - * @{ - */ -/** No error @hideinitializer*/ -#define OPUS_OK 0 -/** One or more invalid/out of range arguments @hideinitializer*/ -#define OPUS_BAD_ARG -1 -/** Not enough bytes allocated in the buffer @hideinitializer*/ -#define OPUS_BUFFER_TOO_SMALL -2 -/** An internal error was detected @hideinitializer*/ -#define OPUS_INTERNAL_ERROR -3 -/** The compressed data passed is corrupted @hideinitializer*/ -#define OPUS_INVALID_PACKET -4 -/** Invalid/unsupported request number @hideinitializer*/ -#define OPUS_UNIMPLEMENTED -5 -/** An encoder or decoder structure is invalid or already freed @hideinitializer*/ -#define OPUS_INVALID_STATE -6 -/** Memory allocation has failed @hideinitializer*/ -#define OPUS_ALLOC_FAIL -7 -/**@}*/ - -/** @cond OPUS_INTERNAL_DOC */ -/**Export control for opus functions */ - -#ifndef OPUS_EXPORT -# if defined(WIN32) -# if defined(OPUS_BUILD) && defined(DLL_EXPORT) -# define OPUS_EXPORT __declspec(dllexport) -# else -# define OPUS_EXPORT -# endif -# elif defined(__GNUC__) && defined(OPUS_BUILD) -# define OPUS_EXPORT __attribute__ ((visibility ("default"))) -# else -# define OPUS_EXPORT -# endif -#endif - -# if !defined(OPUS_GNUC_PREREQ) -# if defined(__GNUC__)&&defined(__GNUC_MINOR__) -# define OPUS_GNUC_PREREQ(_maj,_min) \ - ((__GNUC__<<16)+__GNUC_MINOR__>=((_maj)<<16)+(_min)) -# else -# define OPUS_GNUC_PREREQ(_maj,_min) 0 -# endif -# endif - -#if (!defined(__STDC_VERSION__) || (__STDC_VERSION__ < 199901L) ) -# if OPUS_GNUC_PREREQ(3,0) -# define OPUS_RESTRICT __restrict__ -# elif (defined(_MSC_VER) && _MSC_VER >= 1400) -# define OPUS_RESTRICT __restrict -# else -# define OPUS_RESTRICT -# endif -#else -# define OPUS_RESTRICT restrict -#endif - -#if (!defined(__STDC_VERSION__) || (__STDC_VERSION__ < 199901L) ) -# if OPUS_GNUC_PREREQ(2,7) -# define OPUS_INLINE __inline__ -# elif (defined(_MSC_VER)) -# define OPUS_INLINE __inline -# else -# define OPUS_INLINE -# endif -#else -# define OPUS_INLINE inline -#endif - -/**Warning attributes for opus functions - * NONNULL is not used in OPUS_BUILD to avoid the compiler optimizing out - * some paranoid null checks. */ -#if defined(__GNUC__) && OPUS_GNUC_PREREQ(3, 4) -# define OPUS_WARN_UNUSED_RESULT __attribute__ ((__warn_unused_result__)) -#else -# define OPUS_WARN_UNUSED_RESULT -#endif -#if !defined(OPUS_BUILD) && defined(__GNUC__) && OPUS_GNUC_PREREQ(3, 4) -# define OPUS_ARG_NONNULL(_x) __attribute__ ((__nonnull__(_x))) -#else -# define OPUS_ARG_NONNULL(_x) -#endif - -/** These are the actual Encoder CTL ID numbers. - * They should not be used directly by applications. - * In general, SETs should be even and GETs should be odd.*/ -#define OPUS_SET_APPLICATION_REQUEST 4000 -#define OPUS_GET_APPLICATION_REQUEST 4001 -#define OPUS_SET_BITRATE_REQUEST 4002 -#define OPUS_GET_BITRATE_REQUEST 4003 -#define OPUS_SET_MAX_BANDWIDTH_REQUEST 4004 -#define OPUS_GET_MAX_BANDWIDTH_REQUEST 4005 -#define OPUS_SET_VBR_REQUEST 4006 -#define OPUS_GET_VBR_REQUEST 4007 -#define OPUS_SET_BANDWIDTH_REQUEST 4008 -#define OPUS_GET_BANDWIDTH_REQUEST 4009 -#define OPUS_SET_COMPLEXITY_REQUEST 4010 -#define OPUS_GET_COMPLEXITY_REQUEST 4011 -#define OPUS_SET_INBAND_FEC_REQUEST 4012 -#define OPUS_GET_INBAND_FEC_REQUEST 4013 -#define OPUS_SET_PACKET_LOSS_PERC_REQUEST 4014 -#define OPUS_GET_PACKET_LOSS_PERC_REQUEST 4015 -#define OPUS_SET_DTX_REQUEST 4016 -#define OPUS_GET_DTX_REQUEST 4017 -#define OPUS_SET_VBR_CONSTRAINT_REQUEST 4020 -#define OPUS_GET_VBR_CONSTRAINT_REQUEST 4021 -#define OPUS_SET_FORCE_CHANNELS_REQUEST 4022 -#define OPUS_GET_FORCE_CHANNELS_REQUEST 4023 -#define OPUS_SET_SIGNAL_REQUEST 4024 -#define OPUS_GET_SIGNAL_REQUEST 4025 -#define OPUS_GET_LOOKAHEAD_REQUEST 4027 -/* #define OPUS_RESET_STATE 4028 */ -#define OPUS_GET_SAMPLE_RATE_REQUEST 4029 -#define OPUS_GET_FINAL_RANGE_REQUEST 4031 -#define OPUS_GET_PITCH_REQUEST 4033 -#define OPUS_SET_GAIN_REQUEST 4034 -#define OPUS_GET_GAIN_REQUEST 4045 /* Should have been 4035 */ -#define OPUS_SET_LSB_DEPTH_REQUEST 4036 -#define OPUS_GET_LSB_DEPTH_REQUEST 4037 -#define OPUS_GET_LAST_PACKET_DURATION_REQUEST 4039 -#define OPUS_SET_EXPERT_FRAME_DURATION_REQUEST 4040 -#define OPUS_GET_EXPERT_FRAME_DURATION_REQUEST 4041 -#define OPUS_SET_PREDICTION_DISABLED_REQUEST 4042 -#define OPUS_GET_PREDICTION_DISABLED_REQUEST 4043 -/* Don't use 4045, it's already taken by OPUS_GET_GAIN_REQUEST */ -#define OPUS_SET_PHASE_INVERSION_DISABLED_REQUEST 4046 -#define OPUS_GET_PHASE_INVERSION_DISABLED_REQUEST 4047 -#define OPUS_GET_IN_DTX_REQUEST 4049 - -/** Defines for the presence of extended APIs. */ -#define OPUS_HAVE_OPUS_PROJECTION_H - -/* Macros to trigger compilation errors when the wrong types are provided to a CTL */ -#define __opus_check_int(x) (((void)((x) == (opus_int32)0)), (opus_int32)(x)) -#define __opus_check_int_ptr(ptr) ((ptr) + ((ptr) - (opus_int32*)(ptr))) -#define __opus_check_uint_ptr(ptr) ((ptr) + ((ptr) - (opus_uint32*)(ptr))) -#define __opus_check_val16_ptr(ptr) ((ptr) + ((ptr) - (opus_val16*)(ptr))) -/** @endcond */ - -/** @defgroup opus_ctlvalues Pre-defined values for CTL interface - * @see opus_genericctls, opus_encoderctls - * @{ - */ -/* Values for the various encoder CTLs */ -#define OPUS_AUTO -1000 /**opus_int32: Allowed values: 0-10, inclusive. - * - * @hideinitializer */ -#define OPUS_SET_COMPLEXITY(x) OPUS_SET_COMPLEXITY_REQUEST, __opus_check_int(x) -/** Gets the encoder's complexity configuration. - * @see OPUS_SET_COMPLEXITY - * @param[out] x opus_int32 *: Returns a value in the range 0-10, - * inclusive. - * @hideinitializer */ -#define OPUS_GET_COMPLEXITY(x) OPUS_GET_COMPLEXITY_REQUEST, __opus_check_int_ptr(x) - -/** Configures the bitrate in the encoder. - * Rates from 500 to 512000 bits per second are meaningful, as well as the - * special values #OPUS_AUTO and #OPUS_BITRATE_MAX. - * The value #OPUS_BITRATE_MAX can be used to cause the codec to use as much - * rate as it can, which is useful for controlling the rate by adjusting the - * output buffer size. - * @see OPUS_GET_BITRATE - * @param[in] x opus_int32: Bitrate in bits per second. The default - * is determined based on the number of - * channels and the input sampling rate. - * @hideinitializer */ -#define OPUS_SET_BITRATE(x) OPUS_SET_BITRATE_REQUEST, __opus_check_int(x) -/** Gets the encoder's bitrate configuration. - * @see OPUS_SET_BITRATE - * @param[out] x opus_int32 *: Returns the bitrate in bits per second. - * The default is determined based on the - * number of channels and the input - * sampling rate. - * @hideinitializer */ -#define OPUS_GET_BITRATE(x) OPUS_GET_BITRATE_REQUEST, __opus_check_int_ptr(x) - -/** Enables or disables variable bitrate (VBR) in the encoder. - * The configured bitrate may not be met exactly because frames must - * be an integer number of bytes in length. - * @see OPUS_GET_VBR - * @see OPUS_SET_VBR_CONSTRAINT - * @param[in] x opus_int32: Allowed values: - *
- *
0
Hard CBR. For LPC/hybrid modes at very low bit-rate, this can - * cause noticeable quality degradation.
- *
1
VBR (default). The exact type of VBR is controlled by - * #OPUS_SET_VBR_CONSTRAINT.
- *
- * @hideinitializer */ -#define OPUS_SET_VBR(x) OPUS_SET_VBR_REQUEST, __opus_check_int(x) -/** Determine if variable bitrate (VBR) is enabled in the encoder. - * @see OPUS_SET_VBR - * @see OPUS_GET_VBR_CONSTRAINT - * @param[out] x opus_int32 *: Returns one of the following values: - *
- *
0
Hard CBR.
- *
1
VBR (default). The exact type of VBR may be retrieved via - * #OPUS_GET_VBR_CONSTRAINT.
- *
- * @hideinitializer */ -#define OPUS_GET_VBR(x) OPUS_GET_VBR_REQUEST, __opus_check_int_ptr(x) - -/** Enables or disables constrained VBR in the encoder. - * This setting is ignored when the encoder is in CBR mode. - * @warning Only the MDCT mode of Opus currently heeds the constraint. - * Speech mode ignores it completely, hybrid mode may fail to obey it - * if the LPC layer uses more bitrate than the constraint would have - * permitted. - * @see OPUS_GET_VBR_CONSTRAINT - * @see OPUS_SET_VBR - * @param[in] x opus_int32: Allowed values: - *
- *
0
Unconstrained VBR.
- *
1
Constrained VBR (default). This creates a maximum of one - * frame of buffering delay assuming a transport with a - * serialization speed of the nominal bitrate.
- *
- * @hideinitializer */ -#define OPUS_SET_VBR_CONSTRAINT(x) OPUS_SET_VBR_CONSTRAINT_REQUEST, __opus_check_int(x) -/** Determine if constrained VBR is enabled in the encoder. - * @see OPUS_SET_VBR_CONSTRAINT - * @see OPUS_GET_VBR - * @param[out] x opus_int32 *: Returns one of the following values: - *
- *
0
Unconstrained VBR.
- *
1
Constrained VBR (default).
- *
- * @hideinitializer */ -#define OPUS_GET_VBR_CONSTRAINT(x) OPUS_GET_VBR_CONSTRAINT_REQUEST, __opus_check_int_ptr(x) - -/** Configures mono/stereo forcing in the encoder. - * This can force the encoder to produce packets encoded as either mono or - * stereo, regardless of the format of the input audio. This is useful when - * the caller knows that the input signal is currently a mono source embedded - * in a stereo stream. - * @see OPUS_GET_FORCE_CHANNELS - * @param[in] x opus_int32: Allowed values: - *
- *
#OPUS_AUTO
Not forced (default)
- *
1
Forced mono
- *
2
Forced stereo
- *
- * @hideinitializer */ -#define OPUS_SET_FORCE_CHANNELS(x) OPUS_SET_FORCE_CHANNELS_REQUEST, __opus_check_int(x) -/** Gets the encoder's forced channel configuration. - * @see OPUS_SET_FORCE_CHANNELS - * @param[out] x opus_int32 *: - *
- *
#OPUS_AUTO
Not forced (default)
- *
1
Forced mono
- *
2
Forced stereo
- *
- * @hideinitializer */ -#define OPUS_GET_FORCE_CHANNELS(x) OPUS_GET_FORCE_CHANNELS_REQUEST, __opus_check_int_ptr(x) - -/** Configures the maximum bandpass that the encoder will select automatically. - * Applications should normally use this instead of #OPUS_SET_BANDWIDTH - * (leaving that set to the default, #OPUS_AUTO). This allows the - * application to set an upper bound based on the type of input it is - * providing, but still gives the encoder the freedom to reduce the bandpass - * when the bitrate becomes too low, for better overall quality. - * @see OPUS_GET_MAX_BANDWIDTH - * @param[in] x opus_int32: Allowed values: - *
- *
OPUS_BANDWIDTH_NARROWBAND
4 kHz passband
- *
OPUS_BANDWIDTH_MEDIUMBAND
6 kHz passband
- *
OPUS_BANDWIDTH_WIDEBAND
8 kHz passband
- *
OPUS_BANDWIDTH_SUPERWIDEBAND
12 kHz passband
- *
OPUS_BANDWIDTH_FULLBAND
20 kHz passband (default)
- *
- * @hideinitializer */ -#define OPUS_SET_MAX_BANDWIDTH(x) OPUS_SET_MAX_BANDWIDTH_REQUEST, __opus_check_int(x) - -/** Gets the encoder's configured maximum allowed bandpass. - * @see OPUS_SET_MAX_BANDWIDTH - * @param[out] x opus_int32 *: Allowed values: - *
- *
#OPUS_BANDWIDTH_NARROWBAND
4 kHz passband
- *
#OPUS_BANDWIDTH_MEDIUMBAND
6 kHz passband
- *
#OPUS_BANDWIDTH_WIDEBAND
8 kHz passband
- *
#OPUS_BANDWIDTH_SUPERWIDEBAND
12 kHz passband
- *
#OPUS_BANDWIDTH_FULLBAND
20 kHz passband (default)
- *
- * @hideinitializer */ -#define OPUS_GET_MAX_BANDWIDTH(x) OPUS_GET_MAX_BANDWIDTH_REQUEST, __opus_check_int_ptr(x) - -/** Sets the encoder's bandpass to a specific value. - * This prevents the encoder from automatically selecting the bandpass based - * on the available bitrate. If an application knows the bandpass of the input - * audio it is providing, it should normally use #OPUS_SET_MAX_BANDWIDTH - * instead, which still gives the encoder the freedom to reduce the bandpass - * when the bitrate becomes too low, for better overall quality. - * @see OPUS_GET_BANDWIDTH - * @param[in] x opus_int32: Allowed values: - *
- *
#OPUS_AUTO
(default)
- *
#OPUS_BANDWIDTH_NARROWBAND
4 kHz passband
- *
#OPUS_BANDWIDTH_MEDIUMBAND
6 kHz passband
- *
#OPUS_BANDWIDTH_WIDEBAND
8 kHz passband
- *
#OPUS_BANDWIDTH_SUPERWIDEBAND
12 kHz passband
- *
#OPUS_BANDWIDTH_FULLBAND
20 kHz passband
- *
- * @hideinitializer */ -#define OPUS_SET_BANDWIDTH(x) OPUS_SET_BANDWIDTH_REQUEST, __opus_check_int(x) - -/** Configures the type of signal being encoded. - * This is a hint which helps the encoder's mode selection. - * @see OPUS_GET_SIGNAL - * @param[in] x opus_int32: Allowed values: - *
- *
#OPUS_AUTO
(default)
- *
#OPUS_SIGNAL_VOICE
Bias thresholds towards choosing LPC or Hybrid modes.
- *
#OPUS_SIGNAL_MUSIC
Bias thresholds towards choosing MDCT modes.
- *
- * @hideinitializer */ -#define OPUS_SET_SIGNAL(x) OPUS_SET_SIGNAL_REQUEST, __opus_check_int(x) -/** Gets the encoder's configured signal type. - * @see OPUS_SET_SIGNAL - * @param[out] x opus_int32 *: Returns one of the following values: - *
- *
#OPUS_AUTO
(default)
- *
#OPUS_SIGNAL_VOICE
Bias thresholds towards choosing LPC or Hybrid modes.
- *
#OPUS_SIGNAL_MUSIC
Bias thresholds towards choosing MDCT modes.
- *
- * @hideinitializer */ -#define OPUS_GET_SIGNAL(x) OPUS_GET_SIGNAL_REQUEST, __opus_check_int_ptr(x) - - -/** Configures the encoder's intended application. - * The initial value is a mandatory argument to the encoder_create function. - * @see OPUS_GET_APPLICATION - * @param[in] x opus_int32: Returns one of the following values: - *
- *
#OPUS_APPLICATION_VOIP
- *
Process signal for improved speech intelligibility.
- *
#OPUS_APPLICATION_AUDIO
- *
Favor faithfulness to the original input.
- *
#OPUS_APPLICATION_RESTRICTED_LOWDELAY
- *
Configure the minimum possible coding delay by disabling certain modes - * of operation.
- *
- * @hideinitializer */ -#define OPUS_SET_APPLICATION(x) OPUS_SET_APPLICATION_REQUEST, __opus_check_int(x) -/** Gets the encoder's configured application. - * @see OPUS_SET_APPLICATION - * @param[out] x opus_int32 *: Returns one of the following values: - *
- *
#OPUS_APPLICATION_VOIP
- *
Process signal for improved speech intelligibility.
- *
#OPUS_APPLICATION_AUDIO
- *
Favor faithfulness to the original input.
- *
#OPUS_APPLICATION_RESTRICTED_LOWDELAY
- *
Configure the minimum possible coding delay by disabling certain modes - * of operation.
- *
- * @hideinitializer */ -#define OPUS_GET_APPLICATION(x) OPUS_GET_APPLICATION_REQUEST, __opus_check_int_ptr(x) - -/** Gets the total samples of delay added by the entire codec. - * This can be queried by the encoder and then the provided number of samples can be - * skipped on from the start of the decoder's output to provide time aligned input - * and output. From the perspective of a decoding application the real data begins this many - * samples late. - * - * The decoder contribution to this delay is identical for all decoders, but the - * encoder portion of the delay may vary from implementation to implementation, - * version to version, or even depend on the encoder's initial configuration. - * Applications needing delay compensation should call this CTL rather than - * hard-coding a value. - * @param[out] x opus_int32 *: Number of lookahead samples - * @hideinitializer */ -#define OPUS_GET_LOOKAHEAD(x) OPUS_GET_LOOKAHEAD_REQUEST, __opus_check_int_ptr(x) - -/** Configures the encoder's use of inband forward error correction (FEC). - * @note This is only applicable to the LPC layer - * @see OPUS_GET_INBAND_FEC - * @param[in] x opus_int32: Allowed values: - *
- *
0
Disable inband FEC (default).
- *
1
Enable inband FEC.
- *
- * @hideinitializer */ -#define OPUS_SET_INBAND_FEC(x) OPUS_SET_INBAND_FEC_REQUEST, __opus_check_int(x) -/** Gets encoder's configured use of inband forward error correction. - * @see OPUS_SET_INBAND_FEC - * @param[out] x opus_int32 *: Returns one of the following values: - *
- *
0
Inband FEC disabled (default).
- *
1
Inband FEC enabled.
- *
- * @hideinitializer */ -#define OPUS_GET_INBAND_FEC(x) OPUS_GET_INBAND_FEC_REQUEST, __opus_check_int_ptr(x) - -/** Configures the encoder's expected packet loss percentage. - * Higher values trigger progressively more loss resistant behavior in the encoder - * at the expense of quality at a given bitrate in the absence of packet loss, but - * greater quality under loss. - * @see OPUS_GET_PACKET_LOSS_PERC - * @param[in] x opus_int32: Loss percentage in the range 0-100, inclusive (default: 0). - * @hideinitializer */ -#define OPUS_SET_PACKET_LOSS_PERC(x) OPUS_SET_PACKET_LOSS_PERC_REQUEST, __opus_check_int(x) -/** Gets the encoder's configured packet loss percentage. - * @see OPUS_SET_PACKET_LOSS_PERC - * @param[out] x opus_int32 *: Returns the configured loss percentage - * in the range 0-100, inclusive (default: 0). - * @hideinitializer */ -#define OPUS_GET_PACKET_LOSS_PERC(x) OPUS_GET_PACKET_LOSS_PERC_REQUEST, __opus_check_int_ptr(x) - -/** Configures the encoder's use of discontinuous transmission (DTX). - * @note This is only applicable to the LPC layer - * @see OPUS_GET_DTX - * @param[in] x opus_int32: Allowed values: - *
- *
0
Disable DTX (default).
- *
1
Enabled DTX.
- *
- * @hideinitializer */ -#define OPUS_SET_DTX(x) OPUS_SET_DTX_REQUEST, __opus_check_int(x) -/** Gets encoder's configured use of discontinuous transmission. - * @see OPUS_SET_DTX - * @param[out] x opus_int32 *: Returns one of the following values: - *
- *
0
DTX disabled (default).
- *
1
DTX enabled.
- *
- * @hideinitializer */ -#define OPUS_GET_DTX(x) OPUS_GET_DTX_REQUEST, __opus_check_int_ptr(x) -/** Configures the depth of signal being encoded. - * - * This is a hint which helps the encoder identify silence and near-silence. - * It represents the number of significant bits of linear intensity below - * which the signal contains ignorable quantization or other noise. - * - * For example, OPUS_SET_LSB_DEPTH(14) would be an appropriate setting - * for G.711 u-law input. OPUS_SET_LSB_DEPTH(16) would be appropriate - * for 16-bit linear pcm input with opus_encode_float(). - * - * When using opus_encode() instead of opus_encode_float(), or when libopus - * is compiled for fixed-point, the encoder uses the minimum of the value - * set here and the value 16. - * - * @see OPUS_GET_LSB_DEPTH - * @param[in] x opus_int32: Input precision in bits, between 8 and 24 - * (default: 24). - * @hideinitializer */ -#define OPUS_SET_LSB_DEPTH(x) OPUS_SET_LSB_DEPTH_REQUEST, __opus_check_int(x) -/** Gets the encoder's configured signal depth. - * @see OPUS_SET_LSB_DEPTH - * @param[out] x opus_int32 *: Input precision in bits, between 8 and - * 24 (default: 24). - * @hideinitializer */ -#define OPUS_GET_LSB_DEPTH(x) OPUS_GET_LSB_DEPTH_REQUEST, __opus_check_int_ptr(x) - -/** Configures the encoder's use of variable duration frames. - * When variable duration is enabled, the encoder is free to use a shorter frame - * size than the one requested in the opus_encode*() call. - * It is then the user's responsibility - * to verify how much audio was encoded by checking the ToC byte of the encoded - * packet. The part of the audio that was not encoded needs to be resent to the - * encoder for the next call. Do not use this option unless you really - * know what you are doing. - * @see OPUS_GET_EXPERT_FRAME_DURATION - * @param[in] x opus_int32: Allowed values: - *
- *
OPUS_FRAMESIZE_ARG
Select frame size from the argument (default).
- *
OPUS_FRAMESIZE_2_5_MS
Use 2.5 ms frames.
- *
OPUS_FRAMESIZE_5_MS
Use 5 ms frames.
- *
OPUS_FRAMESIZE_10_MS
Use 10 ms frames.
- *
OPUS_FRAMESIZE_20_MS
Use 20 ms frames.
- *
OPUS_FRAMESIZE_40_MS
Use 40 ms frames.
- *
OPUS_FRAMESIZE_60_MS
Use 60 ms frames.
- *
OPUS_FRAMESIZE_80_MS
Use 80 ms frames.
- *
OPUS_FRAMESIZE_100_MS
Use 100 ms frames.
- *
OPUS_FRAMESIZE_120_MS
Use 120 ms frames.
- *
- * @hideinitializer */ -#define OPUS_SET_EXPERT_FRAME_DURATION(x) OPUS_SET_EXPERT_FRAME_DURATION_REQUEST, __opus_check_int(x) -/** Gets the encoder's configured use of variable duration frames. - * @see OPUS_SET_EXPERT_FRAME_DURATION - * @param[out] x opus_int32 *: Returns one of the following values: - *
- *
OPUS_FRAMESIZE_ARG
Select frame size from the argument (default).
- *
OPUS_FRAMESIZE_2_5_MS
Use 2.5 ms frames.
- *
OPUS_FRAMESIZE_5_MS
Use 5 ms frames.
- *
OPUS_FRAMESIZE_10_MS
Use 10 ms frames.
- *
OPUS_FRAMESIZE_20_MS
Use 20 ms frames.
- *
OPUS_FRAMESIZE_40_MS
Use 40 ms frames.
- *
OPUS_FRAMESIZE_60_MS
Use 60 ms frames.
- *
OPUS_FRAMESIZE_80_MS
Use 80 ms frames.
- *
OPUS_FRAMESIZE_100_MS
Use 100 ms frames.
- *
OPUS_FRAMESIZE_120_MS
Use 120 ms frames.
- *
- * @hideinitializer */ -#define OPUS_GET_EXPERT_FRAME_DURATION(x) OPUS_GET_EXPERT_FRAME_DURATION_REQUEST, __opus_check_int_ptr(x) - -/** If set to 1, disables almost all use of prediction, making frames almost - * completely independent. This reduces quality. - * @see OPUS_GET_PREDICTION_DISABLED - * @param[in] x opus_int32: Allowed values: - *
- *
0
Enable prediction (default).
- *
1
Disable prediction.
- *
- * @hideinitializer */ -#define OPUS_SET_PREDICTION_DISABLED(x) OPUS_SET_PREDICTION_DISABLED_REQUEST, __opus_check_int(x) -/** Gets the encoder's configured prediction status. - * @see OPUS_SET_PREDICTION_DISABLED - * @param[out] x opus_int32 *: Returns one of the following values: - *
- *
0
Prediction enabled (default).
- *
1
Prediction disabled.
- *
- * @hideinitializer */ -#define OPUS_GET_PREDICTION_DISABLED(x) OPUS_GET_PREDICTION_DISABLED_REQUEST, __opus_check_int_ptr(x) - -/**@}*/ - -/** @defgroup opus_genericctls Generic CTLs - * - * These macros are used with the \c opus_decoder_ctl and - * \c opus_encoder_ctl calls to generate a particular - * request. - * - * When called on an \c OpusDecoder they apply to that - * particular decoder instance. When called on an - * \c OpusEncoder they apply to the corresponding setting - * on that encoder instance, if present. - * - * Some usage examples: - * - * @code - * int ret; - * opus_int32 pitch; - * ret = opus_decoder_ctl(dec_ctx, OPUS_GET_PITCH(&pitch)); - * if (ret == OPUS_OK) return ret; - * - * opus_encoder_ctl(enc_ctx, OPUS_RESET_STATE); - * opus_decoder_ctl(dec_ctx, OPUS_RESET_STATE); - * - * opus_int32 enc_bw, dec_bw; - * opus_encoder_ctl(enc_ctx, OPUS_GET_BANDWIDTH(&enc_bw)); - * opus_decoder_ctl(dec_ctx, OPUS_GET_BANDWIDTH(&dec_bw)); - * if (enc_bw != dec_bw) { - * printf("packet bandwidth mismatch!\n"); - * } - * @endcode - * - * @see opus_encoder, opus_decoder_ctl, opus_encoder_ctl, opus_decoderctls, opus_encoderctls - * @{ - */ - -/** Resets the codec state to be equivalent to a freshly initialized state. - * This should be called when switching streams in order to prevent - * the back to back decoding from giving different results from - * one at a time decoding. - * @hideinitializer */ -#define OPUS_RESET_STATE 4028 - -/** Gets the final state of the codec's entropy coder. - * This is used for testing purposes, - * The encoder and decoder state should be identical after coding a payload - * (assuming no data corruption or software bugs) - * - * @param[out] x opus_uint32 *: Entropy coder state - * - * @hideinitializer */ -#define OPUS_GET_FINAL_RANGE(x) OPUS_GET_FINAL_RANGE_REQUEST, __opus_check_uint_ptr(x) - -/** Gets the encoder's configured bandpass or the decoder's last bandpass. - * @see OPUS_SET_BANDWIDTH - * @param[out] x opus_int32 *: Returns one of the following values: - *
- *
#OPUS_AUTO
(default)
- *
#OPUS_BANDWIDTH_NARROWBAND
4 kHz passband
- *
#OPUS_BANDWIDTH_MEDIUMBAND
6 kHz passband
- *
#OPUS_BANDWIDTH_WIDEBAND
8 kHz passband
- *
#OPUS_BANDWIDTH_SUPERWIDEBAND
12 kHz passband
- *
#OPUS_BANDWIDTH_FULLBAND
20 kHz passband
- *
- * @hideinitializer */ -#define OPUS_GET_BANDWIDTH(x) OPUS_GET_BANDWIDTH_REQUEST, __opus_check_int_ptr(x) - -/** Gets the sampling rate the encoder or decoder was initialized with. - * This simply returns the Fs value passed to opus_encoder_init() - * or opus_decoder_init(). - * @param[out] x opus_int32 *: Sampling rate of encoder or decoder. - * @hideinitializer - */ -#define OPUS_GET_SAMPLE_RATE(x) OPUS_GET_SAMPLE_RATE_REQUEST, __opus_check_int_ptr(x) - -/** If set to 1, disables the use of phase inversion for intensity stereo, - * improving the quality of mono downmixes, but slightly reducing normal - * stereo quality. Disabling phase inversion in the decoder does not comply - * with RFC 6716, although it does not cause any interoperability issue and - * is expected to become part of the Opus standard once RFC 6716 is updated - * by draft-ietf-codec-opus-update. - * @see OPUS_GET_PHASE_INVERSION_DISABLED - * @param[in] x opus_int32: Allowed values: - *
- *
0
Enable phase inversion (default).
- *
1
Disable phase inversion.
- *
- * @hideinitializer */ -#define OPUS_SET_PHASE_INVERSION_DISABLED(x) OPUS_SET_PHASE_INVERSION_DISABLED_REQUEST, __opus_check_int(x) -/** Gets the encoder's configured phase inversion status. - * @see OPUS_SET_PHASE_INVERSION_DISABLED - * @param[out] x opus_int32 *: Returns one of the following values: - *
- *
0
Stereo phase inversion enabled (default).
- *
1
Stereo phase inversion disabled.
- *
- * @hideinitializer */ -#define OPUS_GET_PHASE_INVERSION_DISABLED(x) OPUS_GET_PHASE_INVERSION_DISABLED_REQUEST, __opus_check_int_ptr(x) -/** Gets the DTX state of the encoder. - * Returns whether the last encoded frame was either a comfort noise update - * during DTX or not encoded because of DTX. - * @param[out] x opus_int32 *: Returns one of the following values: - *
- *
0
The encoder is not in DTX.
- *
1
The encoder is in DTX.
- *
- * @hideinitializer */ -#define OPUS_GET_IN_DTX(x) OPUS_GET_IN_DTX_REQUEST, __opus_check_int_ptr(x) - -/**@}*/ - -/** @defgroup opus_decoderctls Decoder related CTLs - * @see opus_genericctls, opus_encoderctls, opus_decoder - * @{ - */ - -/** Configures decoder gain adjustment. - * Scales the decoded output by a factor specified in Q8 dB units. - * This has a maximum range of -32768 to 32767 inclusive, and returns - * OPUS_BAD_ARG otherwise. The default is zero indicating no adjustment. - * This setting survives decoder reset. - * - * gain = pow(10, x/(20.0*256)) - * - * @param[in] x opus_int32: Amount to scale PCM signal by in Q8 dB units. - * @hideinitializer */ -#define OPUS_SET_GAIN(x) OPUS_SET_GAIN_REQUEST, __opus_check_int(x) -/** Gets the decoder's configured gain adjustment. @see OPUS_SET_GAIN - * - * @param[out] x opus_int32 *: Amount to scale PCM signal by in Q8 dB units. - * @hideinitializer */ -#define OPUS_GET_GAIN(x) OPUS_GET_GAIN_REQUEST, __opus_check_int_ptr(x) - -/** Gets the duration (in samples) of the last packet successfully decoded or concealed. - * @param[out] x opus_int32 *: Number of samples (at current sampling rate). - * @hideinitializer */ -#define OPUS_GET_LAST_PACKET_DURATION(x) OPUS_GET_LAST_PACKET_DURATION_REQUEST, __opus_check_int_ptr(x) - -/** Gets the pitch of the last decoded frame, if available. - * This can be used for any post-processing algorithm requiring the use of pitch, - * e.g. time stretching/shortening. If the last frame was not voiced, or if the - * pitch was not coded in the frame, then zero is returned. - * - * This CTL is only implemented for decoder instances. - * - * @param[out] x opus_int32 *: pitch period at 48 kHz (or 0 if not available) - * - * @hideinitializer */ -#define OPUS_GET_PITCH(x) OPUS_GET_PITCH_REQUEST, __opus_check_int_ptr(x) - -/**@}*/ - -/** @defgroup opus_libinfo Opus library information functions - * @{ - */ - -/** Converts an opus error code into a human readable string. - * - * @param[in] error int: Error number - * @returns Error string - */ -OPUS_EXPORT const char *opus_strerror(int error); - -/** Gets the libopus version string. - * - * Applications may look for the substring "-fixed" in the version string to - * determine whether they have a fixed-point or floating-point build at - * runtime. - * - * @returns Version string - */ -OPUS_EXPORT const char *opus_get_version_string(void); -/**@}*/ - -#ifdef __cplusplus -} -#endif - -#endif /* OPUS_DEFINES_H */ diff --git a/bk7235/liteos_m/bk_sdk_armino/include/modules/opus_multistream.h b/bk7235/liteos_m/bk_sdk_armino/include/modules/opus_multistream.h deleted file mode 100755 index babcee6905bf9f70d922eb903d28a9151f053505..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/modules/opus_multistream.h +++ /dev/null @@ -1,660 +0,0 @@ -/* Copyright (c) 2011 Xiph.Org Foundation - Written by Jean-Marc Valin */ -/* - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - - Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER - OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -/** - * @file opus_multistream.h - * @brief Opus reference implementation multistream API - */ - -#ifndef OPUS_MULTISTREAM_H -#define OPUS_MULTISTREAM_H - -#include "opus.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/** @cond OPUS_INTERNAL_DOC */ - -/** Macros to trigger compilation errors when the wrong types are provided to a - * CTL. */ -/**@{*/ -#define __opus_check_encstate_ptr(ptr) ((ptr) + ((ptr) - (OpusEncoder**)(ptr))) -#define __opus_check_decstate_ptr(ptr) ((ptr) + ((ptr) - (OpusDecoder**)(ptr))) -/**@}*/ - -/** These are the actual encoder and decoder CTL ID numbers. - * They should not be used directly by applications. - * In general, SETs should be even and GETs should be odd.*/ -/**@{*/ -#define OPUS_MULTISTREAM_GET_ENCODER_STATE_REQUEST 5120 -#define OPUS_MULTISTREAM_GET_DECODER_STATE_REQUEST 5122 -/**@}*/ - -/** @endcond */ - -/** @defgroup opus_multistream_ctls Multistream specific encoder and decoder CTLs - * - * These are convenience macros that are specific to the - * opus_multistream_encoder_ctl() and opus_multistream_decoder_ctl() - * interface. - * The CTLs from @ref opus_genericctls, @ref opus_encoderctls, and - * @ref opus_decoderctls may be applied to a multistream encoder or decoder as - * well. - * In addition, you may retrieve the encoder or decoder state for an specific - * stream via #OPUS_MULTISTREAM_GET_ENCODER_STATE or - * #OPUS_MULTISTREAM_GET_DECODER_STATE and apply CTLs to it individually. - */ -/**@{*/ - -/** Gets the encoder state for an individual stream of a multistream encoder. - * @param[in] x opus_int32: The index of the stream whose encoder you - * wish to retrieve. - * This must be non-negative and less than - * the streams parameter used - * to initialize the encoder. - * @param[out] y OpusEncoder**: Returns a pointer to the given - * encoder state. - * @retval OPUS_BAD_ARG The index of the requested stream was out of range. - * @hideinitializer - */ -#define OPUS_MULTISTREAM_GET_ENCODER_STATE(x,y) OPUS_MULTISTREAM_GET_ENCODER_STATE_REQUEST, __opus_check_int(x), __opus_check_encstate_ptr(y) - -/** Gets the decoder state for an individual stream of a multistream decoder. - * @param[in] x opus_int32: The index of the stream whose decoder you - * wish to retrieve. - * This must be non-negative and less than - * the streams parameter used - * to initialize the decoder. - * @param[out] y OpusDecoder**: Returns a pointer to the given - * decoder state. - * @retval OPUS_BAD_ARG The index of the requested stream was out of range. - * @hideinitializer - */ -#define OPUS_MULTISTREAM_GET_DECODER_STATE(x,y) OPUS_MULTISTREAM_GET_DECODER_STATE_REQUEST, __opus_check_int(x), __opus_check_decstate_ptr(y) - -/**@}*/ - -/** @defgroup opus_multistream Opus Multistream API - * @{ - * - * The multistream API allows individual Opus streams to be combined into a - * single packet, enabling support for up to 255 channels. Unlike an - * elementary Opus stream, the encoder and decoder must negotiate the channel - * configuration before the decoder can successfully interpret the data in the - * packets produced by the encoder. Some basic information, such as packet - * duration, can be computed without any special negotiation. - * - * The format for multistream Opus packets is defined in - * RFC 7845 - * and is based on the self-delimited Opus framing described in Appendix B of - * RFC 6716. - * Normal Opus packets are just a degenerate case of multistream Opus packets, - * and can be encoded or decoded with the multistream API by setting - * streams to 1 when initializing the encoder or - * decoder. - * - * Multistream Opus streams can contain up to 255 elementary Opus streams. - * These may be either "uncoupled" or "coupled", indicating that the decoder - * is configured to decode them to either 1 or 2 channels, respectively. - * The streams are ordered so that all coupled streams appear at the - * beginning. - * - * A mapping table defines which decoded channel i - * should be used for each input/output (I/O) channel j. This table is - * typically provided as an unsigned char array. - * Let i = mapping[j] be the index for I/O channel j. - * If i < 2*coupled_streams, then I/O channel j is - * encoded as the left channel of stream (i/2) if i - * is even, or as the right channel of stream (i/2) if - * i is odd. Otherwise, I/O channel j is encoded as - * mono in stream (i - coupled_streams), unless it has the special - * value 255, in which case it is omitted from the encoding entirely (the - * decoder will reproduce it as silence). Each value i must either - * be the special value 255 or be less than streams + coupled_streams. - * - * The output channels specified by the encoder - * should use the - * Vorbis - * channel ordering. A decoder may wish to apply an additional permutation - * to the mapping the encoder used to achieve a different output channel - * order (e.g. for outputing in WAV order). - * - * Each multistream packet contains an Opus packet for each stream, and all of - * the Opus packets in a single multistream packet must have the same - * duration. Therefore the duration of a multistream packet can be extracted - * from the TOC sequence of the first stream, which is located at the - * beginning of the packet, just like an elementary Opus stream: - * - * @code - * int nb_samples; - * int nb_frames; - * nb_frames = opus_packet_get_nb_frames(data, len); - * if (nb_frames < 1) - * return nb_frames; - * nb_samples = opus_packet_get_samples_per_frame(data, 48000) * nb_frames; - * @endcode - * - * The general encoding and decoding process proceeds exactly the same as in - * the normal @ref opus_encoder and @ref opus_decoder APIs. - * See their documentation for an overview of how to use the corresponding - * multistream functions. - */ - -/** Opus multistream encoder state. - * This contains the complete state of a multistream Opus encoder. - * It is position independent and can be freely copied. - * @see opus_multistream_encoder_create - * @see opus_multistream_encoder_init - */ -typedef struct OpusMSEncoder OpusMSEncoder; - -/** Opus multistream decoder state. - * This contains the complete state of a multistream Opus decoder. - * It is position independent and can be freely copied. - * @see opus_multistream_decoder_create - * @see opus_multistream_decoder_init - */ -typedef struct OpusMSDecoder OpusMSDecoder; - -/**\name Multistream encoder functions */ -/**@{*/ - -/** Gets the size of an OpusMSEncoder structure. - * @param streams int: The total number of streams to encode from the - * input. - * This must be no more than 255. - * @param coupled_streams int: Number of coupled (2 channel) streams - * to encode. - * This must be no larger than the total - * number of streams. - * Additionally, The total number of - * encoded channels (streams + - * coupled_streams) must be no - * more than 255. - * @returns The size in bytes on success, or a negative error code - * (see @ref opus_errorcodes) on error. - */ -OPUS_EXPORT OPUS_WARN_UNUSED_RESULT opus_int32 opus_multistream_encoder_get_size( - int streams, - int coupled_streams -); - -OPUS_EXPORT OPUS_WARN_UNUSED_RESULT opus_int32 opus_multistream_surround_encoder_get_size( - int channels, - int mapping_family -); - - -/** Allocates and initializes a multistream encoder state. - * Call opus_multistream_encoder_destroy() to release - * this object when finished. - * @param Fs opus_int32: Sampling rate of the input signal (in Hz). - * This must be one of 8000, 12000, 16000, - * 24000, or 48000. - * @param channels int: Number of channels in the input signal. - * This must be at most 255. - * It may be greater than the number of - * coded channels (streams + - * coupled_streams). - * @param streams int: The total number of streams to encode from the - * input. - * This must be no more than the number of channels. - * @param coupled_streams int: Number of coupled (2 channel) streams - * to encode. - * This must be no larger than the total - * number of streams. - * Additionally, The total number of - * encoded channels (streams + - * coupled_streams) must be no - * more than the number of input channels. - * @param[in] mapping const unsigned char[channels]: Mapping from - * encoded channels to input channels, as described in - * @ref opus_multistream. As an extra constraint, the - * multistream encoder does not allow encoding coupled - * streams for which one channel is unused since this - * is never a good idea. - * @param application int: The target encoder application. - * This must be one of the following: - *
- *
#OPUS_APPLICATION_VOIP
- *
Process signal for improved speech intelligibility.
- *
#OPUS_APPLICATION_AUDIO
- *
Favor faithfulness to the original input.
- *
#OPUS_APPLICATION_RESTRICTED_LOWDELAY
- *
Configure the minimum possible coding delay by disabling certain modes - * of operation.
- *
- * @param[out] error int *: Returns #OPUS_OK on success, or an error - * code (see @ref opus_errorcodes) on - * failure. - */ -OPUS_EXPORT OPUS_WARN_UNUSED_RESULT OpusMSEncoder *opus_multistream_encoder_create( - opus_int32 Fs, - int channels, - int streams, - int coupled_streams, - const unsigned char *mapping, - int application, - int *error -) OPUS_ARG_NONNULL(5); - -OPUS_EXPORT OPUS_WARN_UNUSED_RESULT OpusMSEncoder *opus_multistream_surround_encoder_create( - opus_int32 Fs, - int channels, - int mapping_family, - int *streams, - int *coupled_streams, - unsigned char *mapping, - int application, - int *error -) OPUS_ARG_NONNULL(4) OPUS_ARG_NONNULL(5) OPUS_ARG_NONNULL(6); - -/** Initialize a previously allocated multistream encoder state. - * The memory pointed to by \a st must be at least the size returned by - * opus_multistream_encoder_get_size(). - * This is intended for applications which use their own allocator instead of - * malloc. - * To reset a previously initialized state, use the #OPUS_RESET_STATE CTL. - * @see opus_multistream_encoder_create - * @see opus_multistream_encoder_get_size - * @param st OpusMSEncoder*: Multistream encoder state to initialize. - * @param Fs opus_int32: Sampling rate of the input signal (in Hz). - * This must be one of 8000, 12000, 16000, - * 24000, or 48000. - * @param channels int: Number of channels in the input signal. - * This must be at most 255. - * It may be greater than the number of - * coded channels (streams + - * coupled_streams). - * @param streams int: The total number of streams to encode from the - * input. - * This must be no more than the number of channels. - * @param coupled_streams int: Number of coupled (2 channel) streams - * to encode. - * This must be no larger than the total - * number of streams. - * Additionally, The total number of - * encoded channels (streams + - * coupled_streams) must be no - * more than the number of input channels. - * @param[in] mapping const unsigned char[channels]: Mapping from - * encoded channels to input channels, as described in - * @ref opus_multistream. As an extra constraint, the - * multistream encoder does not allow encoding coupled - * streams for which one channel is unused since this - * is never a good idea. - * @param application int: The target encoder application. - * This must be one of the following: - *
- *
#OPUS_APPLICATION_VOIP
- *
Process signal for improved speech intelligibility.
- *
#OPUS_APPLICATION_AUDIO
- *
Favor faithfulness to the original input.
- *
#OPUS_APPLICATION_RESTRICTED_LOWDELAY
- *
Configure the minimum possible coding delay by disabling certain modes - * of operation.
- *
- * @returns #OPUS_OK on success, or an error code (see @ref opus_errorcodes) - * on failure. - */ -OPUS_EXPORT int opus_multistream_encoder_init( - OpusMSEncoder *st, - opus_int32 Fs, - int channels, - int streams, - int coupled_streams, - const unsigned char *mapping, - int application -) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(6); - -OPUS_EXPORT int opus_multistream_surround_encoder_init( - OpusMSEncoder *st, - opus_int32 Fs, - int channels, - int mapping_family, - int *streams, - int *coupled_streams, - unsigned char *mapping, - int application -) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(5) OPUS_ARG_NONNULL(6) OPUS_ARG_NONNULL(7); - -/** Encodes a multistream Opus frame. - * @param st OpusMSEncoder*: Multistream encoder state. - * @param[in] pcm const opus_int16*: The input signal as interleaved - * samples. - * This must contain - * frame_size*channels - * samples. - * @param frame_size int: Number of samples per channel in the input - * signal. - * This must be an Opus frame size for the - * encoder's sampling rate. - * For example, at 48 kHz the permitted values - * are 120, 240, 480, 960, 1920, and 2880. - * Passing in a duration of less than 10 ms - * (480 samples at 48 kHz) will prevent the - * encoder from using the LPC or hybrid modes. - * @param[out] data unsigned char*: Output payload. - * This must contain storage for at - * least \a max_data_bytes. - * @param [in] max_data_bytes opus_int32: Size of the allocated - * memory for the output - * payload. This may be - * used to impose an upper limit on - * the instant bitrate, but should - * not be used as the only bitrate - * control. Use #OPUS_SET_BITRATE to - * control the bitrate. - * @returns The length of the encoded packet (in bytes) on success or a - * negative error code (see @ref opus_errorcodes) on failure. - */ -OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_multistream_encode( - OpusMSEncoder *st, - const opus_int16 *pcm, - int frame_size, - unsigned char *data, - opus_int32 max_data_bytes -) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(2) OPUS_ARG_NONNULL(4); - -/** Encodes a multistream Opus frame from floating point input. - * @param st OpusMSEncoder*: Multistream encoder state. - * @param[in] pcm const float*: The input signal as interleaved - * samples with a normal range of - * +/-1.0. - * Samples with a range beyond +/-1.0 - * are supported but will be clipped by - * decoders using the integer API and - * should only be used if it is known - * that the far end supports extended - * dynamic range. - * This must contain - * frame_size*channels - * samples. - * @param frame_size int: Number of samples per channel in the input - * signal. - * This must be an Opus frame size for the - * encoder's sampling rate. - * For example, at 48 kHz the permitted values - * are 120, 240, 480, 960, 1920, and 2880. - * Passing in a duration of less than 10 ms - * (480 samples at 48 kHz) will prevent the - * encoder from using the LPC or hybrid modes. - * @param[out] data unsigned char*: Output payload. - * This must contain storage for at - * least \a max_data_bytes. - * @param [in] max_data_bytes opus_int32: Size of the allocated - * memory for the output - * payload. This may be - * used to impose an upper limit on - * the instant bitrate, but should - * not be used as the only bitrate - * control. Use #OPUS_SET_BITRATE to - * control the bitrate. - * @returns The length of the encoded packet (in bytes) on success or a - * negative error code (see @ref opus_errorcodes) on failure. - */ -OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_multistream_encode_float( - OpusMSEncoder *st, - const float *pcm, - int frame_size, - unsigned char *data, - opus_int32 max_data_bytes -) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(2) OPUS_ARG_NONNULL(4); - -/** Frees an OpusMSEncoder allocated by - * opus_multistream_encoder_create(). - * @param st OpusMSEncoder*: Multistream encoder state to be freed. - */ -OPUS_EXPORT void opus_multistream_encoder_destroy(OpusMSEncoder *st); - -/** Perform a CTL function on a multistream Opus encoder. - * - * Generally the request and subsequent arguments are generated by a - * convenience macro. - * @param st OpusMSEncoder*: Multistream encoder state. - * @param request This and all remaining parameters should be replaced by one - * of the convenience macros in @ref opus_genericctls, - * @ref opus_encoderctls, or @ref opus_multistream_ctls. - * @see opus_genericctls - * @see opus_encoderctls - * @see opus_multistream_ctls - */ -OPUS_EXPORT int opus_multistream_encoder_ctl(OpusMSEncoder *st, int request, ...) OPUS_ARG_NONNULL(1); - -/**@}*/ - -/**\name Multistream decoder functions */ -/**@{*/ - -/** Gets the size of an OpusMSDecoder structure. - * @param streams int: The total number of streams coded in the - * input. - * This must be no more than 255. - * @param coupled_streams int: Number streams to decode as coupled - * (2 channel) streams. - * This must be no larger than the total - * number of streams. - * Additionally, The total number of - * coded channels (streams + - * coupled_streams) must be no - * more than 255. - * @returns The size in bytes on success, or a negative error code - * (see @ref opus_errorcodes) on error. - */ -OPUS_EXPORT OPUS_WARN_UNUSED_RESULT opus_int32 opus_multistream_decoder_get_size( - int streams, - int coupled_streams -); - -/** Allocates and initializes a multistream decoder state. - * Call opus_multistream_decoder_destroy() to release - * this object when finished. - * @param Fs opus_int32: Sampling rate to decode at (in Hz). - * This must be one of 8000, 12000, 16000, - * 24000, or 48000. - * @param channels int: Number of channels to output. - * This must be at most 255. - * It may be different from the number of coded - * channels (streams + - * coupled_streams). - * @param streams int: The total number of streams coded in the - * input. - * This must be no more than 255. - * @param coupled_streams int: Number of streams to decode as coupled - * (2 channel) streams. - * This must be no larger than the total - * number of streams. - * Additionally, The total number of - * coded channels (streams + - * coupled_streams) must be no - * more than 255. - * @param[in] mapping const unsigned char[channels]: Mapping from - * coded channels to output channels, as described in - * @ref opus_multistream. - * @param[out] error int *: Returns #OPUS_OK on success, or an error - * code (see @ref opus_errorcodes) on - * failure. - */ -OPUS_EXPORT OPUS_WARN_UNUSED_RESULT OpusMSDecoder *opus_multistream_decoder_create( - opus_int32 Fs, - int channels, - int streams, - int coupled_streams, - const unsigned char *mapping, - int *error -) OPUS_ARG_NONNULL(5); - -/** Intialize a previously allocated decoder state object. - * The memory pointed to by \a st must be at least the size returned by - * opus_multistream_encoder_get_size(). - * This is intended for applications which use their own allocator instead of - * malloc. - * To reset a previously initialized state, use the #OPUS_RESET_STATE CTL. - * @see opus_multistream_decoder_create - * @see opus_multistream_deocder_get_size - * @param st OpusMSEncoder*: Multistream encoder state to initialize. - * @param Fs opus_int32: Sampling rate to decode at (in Hz). - * This must be one of 8000, 12000, 16000, - * 24000, or 48000. - * @param channels int: Number of channels to output. - * This must be at most 255. - * It may be different from the number of coded - * channels (streams + - * coupled_streams). - * @param streams int: The total number of streams coded in the - * input. - * This must be no more than 255. - * @param coupled_streams int: Number of streams to decode as coupled - * (2 channel) streams. - * This must be no larger than the total - * number of streams. - * Additionally, The total number of - * coded channels (streams + - * coupled_streams) must be no - * more than 255. - * @param[in] mapping const unsigned char[channels]: Mapping from - * coded channels to output channels, as described in - * @ref opus_multistream. - * @returns #OPUS_OK on success, or an error code (see @ref opus_errorcodes) - * on failure. - */ -OPUS_EXPORT int opus_multistream_decoder_init( - OpusMSDecoder *st, - opus_int32 Fs, - int channels, - int streams, - int coupled_streams, - const unsigned char *mapping -) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(6); - -/** Decode a multistream Opus packet. - * @param st OpusMSDecoder*: Multistream decoder state. - * @param[in] data const unsigned char*: Input payload. - * Use a NULL - * pointer to indicate packet - * loss. - * @param len opus_int32: Number of bytes in payload. - * @param[out] pcm opus_int16*: Output signal, with interleaved - * samples. - * This must contain room for - * frame_size*channels - * samples. - * @param frame_size int: The number of samples per channel of - * available space in \a pcm. - * If this is less than the maximum packet duration - * (120 ms; 5760 for 48kHz), this function will not be capable - * of decoding some packets. In the case of PLC (data==NULL) - * or FEC (decode_fec=1), then frame_size needs to be exactly - * the duration of audio that is missing, otherwise the - * decoder will not be in the optimal state to decode the - * next incoming packet. For the PLC and FEC cases, frame_size - * must be a multiple of 2.5 ms. - * @param decode_fec int: Flag (0 or 1) to request that any in-band - * forward error correction data be decoded. - * If no such data is available, the frame is - * decoded as if it were lost. - * @returns Number of samples decoded on success or a negative error code - * (see @ref opus_errorcodes) on failure. - */ -OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_multistream_decode( - OpusMSDecoder *st, - const unsigned char *data, - opus_int32 len, - opus_int16 *pcm, - int frame_size, - int decode_fec -) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(4); - -/** Decode a multistream Opus packet with floating point output. - * @param st OpusMSDecoder*: Multistream decoder state. - * @param[in] data const unsigned char*: Input payload. - * Use a NULL - * pointer to indicate packet - * loss. - * @param len opus_int32: Number of bytes in payload. - * @param[out] pcm opus_int16*: Output signal, with interleaved - * samples. - * This must contain room for - * frame_size*channels - * samples. - * @param frame_size int: The number of samples per channel of - * available space in \a pcm. - * If this is less than the maximum packet duration - * (120 ms; 5760 for 48kHz), this function will not be capable - * of decoding some packets. In the case of PLC (data==NULL) - * or FEC (decode_fec=1), then frame_size needs to be exactly - * the duration of audio that is missing, otherwise the - * decoder will not be in the optimal state to decode the - * next incoming packet. For the PLC and FEC cases, frame_size - * must be a multiple of 2.5 ms. - * @param decode_fec int: Flag (0 or 1) to request that any in-band - * forward error correction data be decoded. - * If no such data is available, the frame is - * decoded as if it were lost. - * @returns Number of samples decoded on success or a negative error code - * (see @ref opus_errorcodes) on failure. - */ -OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_multistream_decode_float( - OpusMSDecoder *st, - const unsigned char *data, - opus_int32 len, - float *pcm, - int frame_size, - int decode_fec -) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(4); - -/** Perform a CTL function on a multistream Opus decoder. - * - * Generally the request and subsequent arguments are generated by a - * convenience macro. - * @param st OpusMSDecoder*: Multistream decoder state. - * @param request This and all remaining parameters should be replaced by one - * of the convenience macros in @ref opus_genericctls, - * @ref opus_decoderctls, or @ref opus_multistream_ctls. - * @see opus_genericctls - * @see opus_decoderctls - * @see opus_multistream_ctls - */ -OPUS_EXPORT int opus_multistream_decoder_ctl(OpusMSDecoder *st, int request, ...) OPUS_ARG_NONNULL(1); - -/** Frees an OpusMSDecoder allocated by - * opus_multistream_decoder_create(). - * @param st OpusMSDecoder: Multistream decoder state to be freed. - */ -OPUS_EXPORT void opus_multistream_decoder_destroy(OpusMSDecoder *st); - -/**@}*/ - -/**@}*/ - -#ifdef __cplusplus -} -#endif - -#endif /* OPUS_MULTISTREAM_H */ diff --git a/bk7235/liteos_m/bk_sdk_armino/include/modules/opus_projection.h b/bk7235/liteos_m/bk_sdk_armino/include/modules/opus_projection.h deleted file mode 100755 index 9dabf4e85cf0be698f3215325bec40c5643b5241..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/modules/opus_projection.h +++ /dev/null @@ -1,568 +0,0 @@ -/* Copyright (c) 2017 Google Inc. - Written by Andrew Allen */ -/* - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - - Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER - OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ - -/** - * @file opus_projection.h - * @brief Opus projection reference API - */ - -#ifndef OPUS_PROJECTION_H -#define OPUS_PROJECTION_H - -#include "opus_multistream.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/** @cond OPUS_INTERNAL_DOC */ - -/** These are the actual encoder and decoder CTL ID numbers. - * They should not be used directly by applications.c - * In general, SETs should be even and GETs should be odd.*/ -/**@{*/ -#define OPUS_PROJECTION_GET_DEMIXING_MATRIX_GAIN_REQUEST 6001 -#define OPUS_PROJECTION_GET_DEMIXING_MATRIX_SIZE_REQUEST 6003 -#define OPUS_PROJECTION_GET_DEMIXING_MATRIX_REQUEST 6005 -/**@}*/ - - -/** @endcond */ - -/** @defgroup opus_projection_ctls Projection specific encoder and decoder CTLs - * - * These are convenience macros that are specific to the - * opus_projection_encoder_ctl() and opus_projection_decoder_ctl() - * interface. - * The CTLs from @ref opus_genericctls, @ref opus_encoderctls, - * @ref opus_decoderctls, and @ref opus_multistream_ctls may be applied to a - * projection encoder or decoder as well. - */ -/**@{*/ - -/** Gets the gain (in dB. S7.8-format) of the demixing matrix from the encoder. - * @param[out] x opus_int32 *: Returns the gain (in dB. S7.8-format) - * of the demixing matrix. - * @hideinitializer - */ -#define OPUS_PROJECTION_GET_DEMIXING_MATRIX_GAIN(x) OPUS_PROJECTION_GET_DEMIXING_MATRIX_GAIN_REQUEST, __opus_check_int_ptr(x) - - -/** Gets the size in bytes of the demixing matrix from the encoder. - * @param[out] x opus_int32 *: Returns the size in bytes of the - * demixing matrix. - * @hideinitializer - */ -#define OPUS_PROJECTION_GET_DEMIXING_MATRIX_SIZE(x) OPUS_PROJECTION_GET_DEMIXING_MATRIX_SIZE_REQUEST, __opus_check_int_ptr(x) - - -/** Copies the demixing matrix to the supplied pointer location. - * @param[out] x unsigned char *: Returns the demixing matrix to the - * supplied pointer location. - * @param y opus_int32: The size in bytes of the reserved memory at the - * pointer location. - * @hideinitializer - */ -#define OPUS_PROJECTION_GET_DEMIXING_MATRIX(x,y) OPUS_PROJECTION_GET_DEMIXING_MATRIX_REQUEST, x, __opus_check_int(y) - - -/**@}*/ - -/** Opus projection encoder state. - * This contains the complete state of a projection Opus encoder. - * It is position independent and can be freely copied. - * @see opus_projection_ambisonics_encoder_create - */ -typedef struct OpusProjectionEncoder OpusProjectionEncoder; - - -/** Opus projection decoder state. - * This contains the complete state of a projection Opus decoder. - * It is position independent and can be freely copied. - * @see opus_projection_decoder_create - * @see opus_projection_decoder_init - */ -typedef struct OpusProjectionDecoder OpusProjectionDecoder; - - -/**\name Projection encoder functions */ -/**@{*/ - -/** Gets the size of an OpusProjectionEncoder structure. - * @param channels int: The total number of input channels to encode. - * This must be no more than 255. - * @param mapping_family int: The mapping family to use for selecting - * the appropriate projection. - * @returns The size in bytes on success, or a negative error code - * (see @ref opus_errorcodes) on error. - */ -OPUS_EXPORT OPUS_WARN_UNUSED_RESULT opus_int32 opus_projection_ambisonics_encoder_get_size( - int channels, - int mapping_family -); - - -/** Allocates and initializes a projection encoder state. - * Call opus_projection_encoder_destroy() to release - * this object when finished. - * @param Fs opus_int32: Sampling rate of the input signal (in Hz). - * This must be one of 8000, 12000, 16000, - * 24000, or 48000. - * @param channels int: Number of channels in the input signal. - * This must be at most 255. - * It may be greater than the number of - * coded channels (streams + - * coupled_streams). - * @param mapping_family int: The mapping family to use for selecting - * the appropriate projection. - * @param[out] streams int *: The total number of streams that will - * be encoded from the input. - * @param[out] coupled_streams int *: Number of coupled (2 channel) - * streams that will be encoded from the input. - * @param application int: The target encoder application. - * This must be one of the following: - *
- *
#OPUS_APPLICATION_VOIP
- *
Process signal for improved speech intelligibility.
- *
#OPUS_APPLICATION_AUDIO
- *
Favor faithfulness to the original input.
- *
#OPUS_APPLICATION_RESTRICTED_LOWDELAY
- *
Configure the minimum possible coding delay by disabling certain modes - * of operation.
- *
- * @param[out] error int *: Returns #OPUS_OK on success, or an error - * code (see @ref opus_errorcodes) on - * failure. - */ -OPUS_EXPORT OPUS_WARN_UNUSED_RESULT OpusProjectionEncoder *opus_projection_ambisonics_encoder_create( - opus_int32 Fs, - int channels, - int mapping_family, - int *streams, - int *coupled_streams, - int application, - int *error -) OPUS_ARG_NONNULL(4) OPUS_ARG_NONNULL(5); - - -/** Initialize a previously allocated projection encoder state. - * The memory pointed to by \a st must be at least the size returned by - * opus_projection_ambisonics_encoder_get_size(). - * This is intended for applications which use their own allocator instead of - * malloc. - * To reset a previously initialized state, use the #OPUS_RESET_STATE CTL. - * @see opus_projection_ambisonics_encoder_create - * @see opus_projection_ambisonics_encoder_get_size - * @param st OpusProjectionEncoder*: Projection encoder state to initialize. - * @param Fs opus_int32: Sampling rate of the input signal (in Hz). - * This must be one of 8000, 12000, 16000, - * 24000, or 48000. - * @param channels int: Number of channels in the input signal. - * This must be at most 255. - * It may be greater than the number of - * coded channels (streams + - * coupled_streams). - * @param streams int: The total number of streams to encode from the - * input. - * This must be no more than the number of channels. - * @param coupled_streams int: Number of coupled (2 channel) streams - * to encode. - * This must be no larger than the total - * number of streams. - * Additionally, The total number of - * encoded channels (streams + - * coupled_streams) must be no - * more than the number of input channels. - * @param application int: The target encoder application. - * This must be one of the following: - *
- *
#OPUS_APPLICATION_VOIP
- *
Process signal for improved speech intelligibility.
- *
#OPUS_APPLICATION_AUDIO
- *
Favor faithfulness to the original input.
- *
#OPUS_APPLICATION_RESTRICTED_LOWDELAY
- *
Configure the minimum possible coding delay by disabling certain modes - * of operation.
- *
- * @returns #OPUS_OK on success, or an error code (see @ref opus_errorcodes) - * on failure. - */ -OPUS_EXPORT int opus_projection_ambisonics_encoder_init( - OpusProjectionEncoder *st, - opus_int32 Fs, - int channels, - int mapping_family, - int *streams, - int *coupled_streams, - int application -) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(5) OPUS_ARG_NONNULL(6); - - -/** Encodes a projection Opus frame. - * @param st OpusProjectionEncoder*: Projection encoder state. - * @param[in] pcm const opus_int16*: The input signal as interleaved - * samples. - * This must contain - * frame_size*channels - * samples. - * @param frame_size int: Number of samples per channel in the input - * signal. - * This must be an Opus frame size for the - * encoder's sampling rate. - * For example, at 48 kHz the permitted values - * are 120, 240, 480, 960, 1920, and 2880. - * Passing in a duration of less than 10 ms - * (480 samples at 48 kHz) will prevent the - * encoder from using the LPC or hybrid modes. - * @param[out] data unsigned char*: Output payload. - * This must contain storage for at - * least \a max_data_bytes. - * @param [in] max_data_bytes opus_int32: Size of the allocated - * memory for the output - * payload. This may be - * used to impose an upper limit on - * the instant bitrate, but should - * not be used as the only bitrate - * control. Use #OPUS_SET_BITRATE to - * control the bitrate. - * @returns The length of the encoded packet (in bytes) on success or a - * negative error code (see @ref opus_errorcodes) on failure. - */ -OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_projection_encode( - OpusProjectionEncoder *st, - const opus_int16 *pcm, - int frame_size, - unsigned char *data, - opus_int32 max_data_bytes -) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(2) OPUS_ARG_NONNULL(4); - - -/** Encodes a projection Opus frame from floating point input. - * @param st OpusProjectionEncoder*: Projection encoder state. - * @param[in] pcm const float*: The input signal as interleaved - * samples with a normal range of - * +/-1.0. - * Samples with a range beyond +/-1.0 - * are supported but will be clipped by - * decoders using the integer API and - * should only be used if it is known - * that the far end supports extended - * dynamic range. - * This must contain - * frame_size*channels - * samples. - * @param frame_size int: Number of samples per channel in the input - * signal. - * This must be an Opus frame size for the - * encoder's sampling rate. - * For example, at 48 kHz the permitted values - * are 120, 240, 480, 960, 1920, and 2880. - * Passing in a duration of less than 10 ms - * (480 samples at 48 kHz) will prevent the - * encoder from using the LPC or hybrid modes. - * @param[out] data unsigned char*: Output payload. - * This must contain storage for at - * least \a max_data_bytes. - * @param [in] max_data_bytes opus_int32: Size of the allocated - * memory for the output - * payload. This may be - * used to impose an upper limit on - * the instant bitrate, but should - * not be used as the only bitrate - * control. Use #OPUS_SET_BITRATE to - * control the bitrate. - * @returns The length of the encoded packet (in bytes) on success or a - * negative error code (see @ref opus_errorcodes) on failure. - */ -OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_projection_encode_float( - OpusProjectionEncoder *st, - const float *pcm, - int frame_size, - unsigned char *data, - opus_int32 max_data_bytes -) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(2) OPUS_ARG_NONNULL(4); - - -/** Frees an OpusProjectionEncoder allocated by - * opus_projection_ambisonics_encoder_create(). - * @param st OpusProjectionEncoder*: Projection encoder state to be freed. - */ -OPUS_EXPORT void opus_projection_encoder_destroy(OpusProjectionEncoder *st); - - -/** Perform a CTL function on a projection Opus encoder. - * - * Generally the request and subsequent arguments are generated by a - * convenience macro. - * @param st OpusProjectionEncoder*: Projection encoder state. - * @param request This and all remaining parameters should be replaced by one - * of the convenience macros in @ref opus_genericctls, - * @ref opus_encoderctls, @ref opus_multistream_ctls, or - * @ref opus_projection_ctls - * @see opus_genericctls - * @see opus_encoderctls - * @see opus_multistream_ctls - * @see opus_projection_ctls - */ -OPUS_EXPORT int opus_projection_encoder_ctl(OpusProjectionEncoder *st, int request, ...) OPUS_ARG_NONNULL(1); - - -/**@}*/ - -/**\name Projection decoder functions */ -/**@{*/ - -/** Gets the size of an OpusProjectionDecoder structure. - * @param channels int: The total number of output channels. - * This must be no more than 255. - * @param streams int: The total number of streams coded in the - * input. - * This must be no more than 255. - * @param coupled_streams int: Number streams to decode as coupled - * (2 channel) streams. - * This must be no larger than the total - * number of streams. - * Additionally, The total number of - * coded channels (streams + - * coupled_streams) must be no - * more than 255. - * @returns The size in bytes on success, or a negative error code - * (see @ref opus_errorcodes) on error. - */ -OPUS_EXPORT OPUS_WARN_UNUSED_RESULT opus_int32 opus_projection_decoder_get_size( - int channels, - int streams, - int coupled_streams -); - - -/** Allocates and initializes a projection decoder state. - * Call opus_projection_decoder_destroy() to release - * this object when finished. - * @param Fs opus_int32: Sampling rate to decode at (in Hz). - * This must be one of 8000, 12000, 16000, - * 24000, or 48000. - * @param channels int: Number of channels to output. - * This must be at most 255. - * It may be different from the number of coded - * channels (streams + - * coupled_streams). - * @param streams int: The total number of streams coded in the - * input. - * This must be no more than 255. - * @param coupled_streams int: Number of streams to decode as coupled - * (2 channel) streams. - * This must be no larger than the total - * number of streams. - * Additionally, The total number of - * coded channels (streams + - * coupled_streams) must be no - * more than 255. - * @param[in] demixing_matrix const unsigned char[demixing_matrix_size]: Demixing matrix - * that mapping from coded channels to output channels, - * as described in @ref opus_projection and - * @ref opus_projection_ctls. - * @param demixing_matrix_size opus_int32: The size in bytes of the - * demixing matrix, as - * described in @ref - * opus_projection_ctls. - * @param[out] error int *: Returns #OPUS_OK on success, or an error - * code (see @ref opus_errorcodes) on - * failure. - */ -OPUS_EXPORT OPUS_WARN_UNUSED_RESULT OpusProjectionDecoder *opus_projection_decoder_create( - opus_int32 Fs, - int channels, - int streams, - int coupled_streams, - unsigned char *demixing_matrix, - opus_int32 demixing_matrix_size, - int *error -) OPUS_ARG_NONNULL(5); - - -/** Intialize a previously allocated projection decoder state object. - * The memory pointed to by \a st must be at least the size returned by - * opus_projection_decoder_get_size(). - * This is intended for applications which use their own allocator instead of - * malloc. - * To reset a previously initialized state, use the #OPUS_RESET_STATE CTL. - * @see opus_projection_decoder_create - * @see opus_projection_deocder_get_size - * @param st OpusProjectionDecoder*: Projection encoder state to initialize. - * @param Fs opus_int32: Sampling rate to decode at (in Hz). - * This must be one of 8000, 12000, 16000, - * 24000, or 48000. - * @param channels int: Number of channels to output. - * This must be at most 255. - * It may be different from the number of coded - * channels (streams + - * coupled_streams). - * @param streams int: The total number of streams coded in the - * input. - * This must be no more than 255. - * @param coupled_streams int: Number of streams to decode as coupled - * (2 channel) streams. - * This must be no larger than the total - * number of streams. - * Additionally, The total number of - * coded channels (streams + - * coupled_streams) must be no - * more than 255. - * @param[in] demixing_matrix const unsigned char[demixing_matrix_size]: Demixing matrix - * that mapping from coded channels to output channels, - * as described in @ref opus_projection and - * @ref opus_projection_ctls. - * @param demixing_matrix_size opus_int32: The size in bytes of the - * demixing matrix, as - * described in @ref - * opus_projection_ctls. - * @returns #OPUS_OK on success, or an error code (see @ref opus_errorcodes) - * on failure. - */ -OPUS_EXPORT int opus_projection_decoder_init( - OpusProjectionDecoder *st, - opus_int32 Fs, - int channels, - int streams, - int coupled_streams, - unsigned char *demixing_matrix, - opus_int32 demixing_matrix_size -) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(6); - - -/** Decode a projection Opus packet. - * @param st OpusProjectionDecoder*: Projection decoder state. - * @param[in] data const unsigned char*: Input payload. - * Use a NULL - * pointer to indicate packet - * loss. - * @param len opus_int32: Number of bytes in payload. - * @param[out] pcm opus_int16*: Output signal, with interleaved - * samples. - * This must contain room for - * frame_size*channels - * samples. - * @param frame_size int: The number of samples per channel of - * available space in \a pcm. - * If this is less than the maximum packet duration - * (120 ms; 5760 for 48kHz), this function will not be capable - * of decoding some packets. In the case of PLC (data==NULL) - * or FEC (decode_fec=1), then frame_size needs to be exactly - * the duration of audio that is missing, otherwise the - * decoder will not be in the optimal state to decode the - * next incoming packet. For the PLC and FEC cases, frame_size - * must be a multiple of 2.5 ms. - * @param decode_fec int: Flag (0 or 1) to request that any in-band - * forward error correction data be decoded. - * If no such data is available, the frame is - * decoded as if it were lost. - * @returns Number of samples decoded on success or a negative error code - * (see @ref opus_errorcodes) on failure. - */ -OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_projection_decode( - OpusProjectionDecoder *st, - const unsigned char *data, - opus_int32 len, - opus_int16 *pcm, - int frame_size, - int decode_fec -) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(4); - - -/** Decode a projection Opus packet with floating point output. - * @param st OpusProjectionDecoder*: Projection decoder state. - * @param[in] data const unsigned char*: Input payload. - * Use a NULL - * pointer to indicate packet - * loss. - * @param len opus_int32: Number of bytes in payload. - * @param[out] pcm opus_int16*: Output signal, with interleaved - * samples. - * This must contain room for - * frame_size*channels - * samples. - * @param frame_size int: The number of samples per channel of - * available space in \a pcm. - * If this is less than the maximum packet duration - * (120 ms; 5760 for 48kHz), this function will not be capable - * of decoding some packets. In the case of PLC (data==NULL) - * or FEC (decode_fec=1), then frame_size needs to be exactly - * the duration of audio that is missing, otherwise the - * decoder will not be in the optimal state to decode the - * next incoming packet. For the PLC and FEC cases, frame_size - * must be a multiple of 2.5 ms. - * @param decode_fec int: Flag (0 or 1) to request that any in-band - * forward error correction data be decoded. - * If no such data is available, the frame is - * decoded as if it were lost. - * @returns Number of samples decoded on success or a negative error code - * (see @ref opus_errorcodes) on failure. - */ -OPUS_EXPORT OPUS_WARN_UNUSED_RESULT int opus_projection_decode_float( - OpusProjectionDecoder *st, - const unsigned char *data, - opus_int32 len, - float *pcm, - int frame_size, - int decode_fec -) OPUS_ARG_NONNULL(1) OPUS_ARG_NONNULL(4); - - -/** Perform a CTL function on a projection Opus decoder. - * - * Generally the request and subsequent arguments are generated by a - * convenience macro. - * @param st OpusProjectionDecoder*: Projection decoder state. - * @param request This and all remaining parameters should be replaced by one - * of the convenience macros in @ref opus_genericctls, - * @ref opus_decoderctls, @ref opus_multistream_ctls, or - * @ref opus_projection_ctls. - * @see opus_genericctls - * @see opus_decoderctls - * @see opus_multistream_ctls - * @see opus_projection_ctls - */ -OPUS_EXPORT int opus_projection_decoder_ctl(OpusProjectionDecoder *st, int request, ...) OPUS_ARG_NONNULL(1); - - -/** Frees an OpusProjectionDecoder allocated by - * opus_projection_decoder_create(). - * @param st OpusProjectionDecoder: Projection decoder state to be freed. - */ -OPUS_EXPORT void opus_projection_decoder_destroy(OpusProjectionDecoder *st); - - -/**@}*/ - -/**@}*/ - -#ifdef __cplusplus -} -#endif - -#endif /* OPUS_PROJECTION_H */ diff --git a/bk7235/liteos_m/bk_sdk_armino/include/modules/opus_types.h b/bk7235/liteos_m/bk_sdk_armino/include/modules/opus_types.h deleted file mode 100755 index 7cf675580ffb0ad9ba7b040a5c03eb2828910486..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/modules/opus_types.h +++ /dev/null @@ -1,166 +0,0 @@ -/* (C) COPYRIGHT 1994-2002 Xiph.Org Foundation */ -/* Modified by Jean-Marc Valin */ -/* - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - - Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - - - Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER - OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -*/ -/* opus_types.h based on ogg_types.h from libogg */ - -/** - @file opus_types.h - @brief Opus reference implementation types -*/ -#ifndef OPUS_TYPES_H -#define OPUS_TYPES_H - -#define opus_int int /* used for counters etc; at least 16 bits */ -#define opus_int64 long long -#define opus_int8 signed char - -#define opus_uint unsigned int /* used for counters etc; at least 16 bits */ -#define opus_uint64 unsigned long long -#define opus_uint8 unsigned char - -/* Use the real stdint.h if it's there (taken from Paul Hsieh's pstdint.h) */ -#if (defined(__STDC__) && __STDC__ && defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || (defined(__GNUC__) && (defined(_STDINT_H) || defined(_STDINT_H_)) || defined (HAVE_STDINT_H)) -#include -# undef opus_int64 -# undef opus_int8 -# undef opus_uint64 -# undef opus_uint8 - typedef int8_t opus_int8; - typedef uint8_t opus_uint8; - typedef int16_t opus_int16; - typedef uint16_t opus_uint16; - typedef int32_t opus_int32; - typedef uint32_t opus_uint32; - typedef int64_t opus_int64; - typedef uint64_t opus_uint64; -#elif defined(_WIN32) - -# if defined(__CYGWIN__) -# include <_G_config.h> - typedef _G_int32_t opus_int32; - typedef _G_uint32_t opus_uint32; - typedef _G_int16 opus_int16; - typedef _G_uint16 opus_uint16; -# elif defined(__MINGW32__) - typedef short opus_int16; - typedef unsigned short opus_uint16; - typedef int opus_int32; - typedef unsigned int opus_uint32; -# elif defined(__MWERKS__) - typedef int opus_int32; - typedef unsigned int opus_uint32; - typedef short opus_int16; - typedef unsigned short opus_uint16; -# else - /* MSVC/Borland */ - typedef __int32 opus_int32; - typedef unsigned __int32 opus_uint32; - typedef __int16 opus_int16; - typedef unsigned __int16 opus_uint16; -# endif - -#elif defined(__MACOS__) - -# include - typedef SInt16 opus_int16; - typedef UInt16 opus_uint16; - typedef SInt32 opus_int32; - typedef UInt32 opus_uint32; - -#elif (defined(__APPLE__) && defined(__MACH__)) /* MacOS X Framework build */ - -# include - typedef int16_t opus_int16; - typedef u_int16_t opus_uint16; - typedef int32_t opus_int32; - typedef u_int32_t opus_uint32; - -#elif defined(__BEOS__) - - /* Be */ -# include - typedef int16 opus_int16; - typedef u_int16 opus_uint16; - typedef int32_t opus_int32; - typedef u_int32_t opus_uint32; - -#elif defined (__EMX__) - - /* OS/2 GCC */ - typedef short opus_int16; - typedef unsigned short opus_uint16; - typedef int opus_int32; - typedef unsigned int opus_uint32; - -#elif defined (DJGPP) - - /* DJGPP */ - typedef short opus_int16; - typedef unsigned short opus_uint16; - typedef int opus_int32; - typedef unsigned int opus_uint32; - -#elif defined(R5900) - - /* PS2 EE */ - typedef int opus_int32; - typedef unsigned opus_uint32; - typedef short opus_int16; - typedef unsigned short opus_uint16; - -#elif defined(__SYMBIAN32__) - - /* Symbian GCC */ - typedef signed short opus_int16; - typedef unsigned short opus_uint16; - typedef signed int opus_int32; - typedef unsigned int opus_uint32; - -#elif defined(CONFIG_TI_C54X) || defined (CONFIG_TI_C55X) - - typedef short opus_int16; - typedef unsigned short opus_uint16; - typedef long opus_int32; - typedef unsigned long opus_uint32; - -#elif defined(CONFIG_TI_C6X) - - typedef short opus_int16; - typedef unsigned short opus_uint16; - typedef int opus_int32; - typedef unsigned int opus_uint32; - -#else - - /* Give up, take a reasonable guess */ - typedef short opus_int16; - typedef unsigned short opus_uint16; - typedef int opus_int32; - typedef unsigned int opus_uint32; - -#endif - -#endif /* OPUS_TYPES_H */ diff --git a/bk7235/liteos_m/bk_sdk_armino/include/modules/pm.h b/bk7235/liteos_m/bk_sdk_armino/include/modules/pm.h index 7bdb2d9852f1dcfe1f9e8dbbe73f84987a1a02ff..2a104daf2267d66dbd6a0ef1d332a07004bcc08c 100755 --- a/bk7235/liteos_m/bk_sdk_armino/include/modules/pm.h +++ b/bk7235/liteos_m/bk_sdk_armino/include/modules/pm.h @@ -1,3 +1,17 @@ +/* + * Copyright (C) 2022 Beken Corporation + * 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 _PM_H_ #define _PM_H_ diff --git a/bk7235/liteos_m/bk_sdk_armino/include/os/mem.h b/bk7235/liteos_m/bk_sdk_armino/include/os/mem.h index 434e054a17f6951a0c52d9ca162bd219ced3eb19..270c06b5ca1f1c59019f8d23256763078709867b 100644 --- a/bk7235/liteos_m/bk_sdk_armino/include/os/mem.h +++ b/bk7235/liteos_m/bk_sdk_armino/include/os/mem.h @@ -1,3 +1,17 @@ +/* + * Copyright (C) 2022 Beken Corporation + * 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 _MEM_PUB_H_ #define _MEM_PUB_H_ diff --git a/bk7235/liteos_m/bk_sdk_armino/include/os/str.h b/bk7235/liteos_m/bk_sdk_armino/include/os/str.h index 6698ef9ac7dcdd5b58ead80b4cac5bca28ed6bfa..e7005c9a5d98fa7301673839fa63b8a7dcedaf20 100644 --- a/bk7235/liteos_m/bk_sdk_armino/include/os/str.h +++ b/bk7235/liteos_m/bk_sdk_armino/include/os/str.h @@ -1,3 +1,17 @@ +/* + * Copyright (C) 2022 Beken Corporation + * 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 _STR_PUB_H_ #define _STR_PUB_H_ diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7231n/adc_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7231n/adc_cap.h deleted file mode 100644 index 0377a569f312f907ce91f52fb62b7d859f38df1e..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7231n/adc_cap.h +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -/* TODO - Frank check it - * 1. Whether ADC channel is begin from 1 - * 2. Whether analog channel is begin from 7 - **/ - -#define SOC_ADC_CHAN_MIN 1 -#define SOC_ADC_CHAN_MAX 6 -#define SOC_ADC_SAMPLE_CNT_MAX 32 - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7231n/aon_pmu_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7231n/aon_pmu_cap.h deleted file mode 100644 index d807a97dcfaed7fc32a8f050a0b9e8bdcab97860..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7231n/aon_pmu_cap.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -//#define SOC_SYSTEM_GPIO_FUNC_GROUP 1 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7231n/calendar_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7231n/calendar_cap.h deleted file mode 100644 index 82ddd33ea2cc95dc80235c082720b886239133cb..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7231n/calendar_cap.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_CALENDAR_UNIT_NUM 1 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7231n/dma_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7231n/dma_cap.h deleted file mode 100644 index f957c69c784ca9a830afacc5b554d2858f0588a2..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7231n/dma_cap.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_DMA_UNIT_NUM 1 -#define SOC_DMA_CHAN_NUM_PER_UNIT 6 - -#ifdef __cplusplus -} -#endif diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7231n/efuse_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7231n/efuse_cap.h deleted file mode 100644 index 6ec28cd053b59a2ad9e9c8ebc87c0c1f06487934..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7231n/efuse_cap.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_EFUSE_UNIT_NUM 1 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7231n/flash_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7231n/flash_cap.h deleted file mode 100644 index 0968373d28b9fd5a10402eaf963cb2467eb16aaf..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7231n/flash_cap.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_FLASH_UNIT_NUM 1 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7231n/gpio_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7231n/gpio_cap.h deleted file mode 100644 index 6ef8f40575e177b1573733088f31a98e0eef3aa8..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7231n/gpio_cap.h +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_GPIO_NUM 32 -#define SOC_GPIO_USE_NUM 29 -#define GPIO_PERI_FUNC_NUM 4 - -#ifdef __cplusplus -} -#endif diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7231n/i2c_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7231n/i2c_cap.h deleted file mode 100644 index 533c34e0e7a9771fff5a7b3cf58393980de4415d..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7231n/i2c_cap.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_I2C_UNIT_NUM 2 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7231n/icu_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7231n/icu_cap.h deleted file mode 100644 index b97c4f04485d7d9f59f93e1b926858a37e07de05..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7231n/icu_cap.h +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7231n/mapping.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7231n/mapping.h deleted file mode 100755 index b97c4f04485d7d9f59f93e1b926858a37e07de05..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7231n/mapping.h +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7231n/pwm_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7231n/pwm_cap.h deleted file mode 100644 index cdf4c0fbd3553b5c532f2bc3bd8f78a92e8712e5..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7231n/pwm_cap.h +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_PWM_UNIT_NUM 1 -#define SOC_PWM_CHAN_NUM_PER_UNIT 6 -#define SOC_PWM_CHAN_NUM_PER_GROUP 2 -#define SOC_PWM_GROUP_NUM 3 - -#ifdef __cplusplus -} -#endif diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7231n/soc.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7231n/soc.h deleted file mode 100644 index e1ba398d374605ae87f0ec44cc8a243a1aae97f2..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7231n/soc.h +++ /dev/null @@ -1,103 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#include -#include "soc_cap.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_SYS_CTRL_REG_BASE (0x00800000) -#define SOC_EFUSE_REG_BASE (SOC_SYS_CTRL_REG_BASE + 0x1D * 4) -#define SOC_CALENDAR_REG_BASE (SOC_SYS_CTRL_REG_BASE + 0x55 * 4) -#define SOC_ICU_REG_BASE (0x00802000) -#define SOC_UART_REG_BASE (0x00802100) -#define SOC_I2C0_REG_BASE (0x00802300) -#define SOC_TRNG_REG_BASE (0x00802480) -#define SOC_I2C1_REG_BASE (0x00802600) -#define SOC_SPI_REG_BASE (0x00802700) -#define SOC_GPIO_REG_BASE (0x00802800) -#define SOC_WDT_REG_BASE (0x00802900) -#define SOC_TIMER_REG_BASE (0x00802A00) -#define SOC_PWM_REG_BASE (0x00802B00) -#define SOC_ADC_REG_BASE (0x00802C00) -#define SOC_FLASH_REG_BASE (0x00803000) -#define SOC_DMA_REG_BASE (0x00809000) - -#define REG_WRITE(_r, _v) ({\ - (*(volatile uint32_t *)(_r)) = (_v);\ - }) - -#define REG_READ(_r) ({\ - (*(volatile uint32_t *)(_r));\ - }) - -#define REG_GET_BIT(_r, _b) ({\ - (*(volatile uint32_t*)(_r) & (_b));\ - }) - -#define REG_SET_BIT(_r, _b) ({\ - (*(volatile uint32_t*)(_r) |= (_b));\ - }) - -#define REG_CLR_BIT(_r, _b) ({\ - (*(volatile uint32_t*)(_r) &= ~(_b));\ - }) - -#define REG_SET_BITS(_r, _b, _m) ({\ - (*(volatile uint32_t*)(_r) = (*(volatile uint32_t*)(_r) & ~(_m)) | ((_b) & (_m)));\ - }) - -#define REG_GET_FIELD(_r, _f) ({\ - ((REG_READ(_r) >> (_f##_S)) & (_f##_V));\ - }) - -#define REG_SET_FIELD(_r, _f, _v) ({\ - (REG_WRITE((_r),((REG_READ(_r) & ~((_f##_V) << (_f##_S)))|(((_v) & (_f##_V))<<(_f##_S)))));\ - }) - -#define REG_MCHAN_GET_FIELD(_ch, _r, _f) ({\ - ((REG_READ(_r) >> (_f##_MS(_ch))) & (_f##_V));\ - }) - -#define REG_MCHAN_SET_FIELD(_ch, _r, _f, _v) ({\ - (REG_WRITE((_r), ((REG_READ(_r) & ~((_f##_V) << (_f##_MS(_ch))))|(((_v) & (_f##_V))<<(_f##_MS(_ch))))));\ - }) - -#define VALUE_GET_FIELD(_r, _f) (((_r) >> (_f##_S)) & (_f)) - -#define VALUE_GET_FIELD2(_r, _f) (((_r) & (_f))>> (_f##_S)) - -#define VALUE_SET_FIELD(_r, _f, _v) ((_r)=(((_r) & ~((_f) << (_f##_S)))|((_v)<<(_f##_S)))) - -#define VALUE_SET_FIELD2(_r, _f, _v) ((_r)=(((_r) & ~(_f))|((_v)<<(_f##_S)))) - -#define FIELD_TO_VALUE(_f, _v) (((_v)&(_f))<<_f##_S) - -#define FIELD_TO_VALUE2(_f, _v) (((_v)<<_f##_S) & (_f)) - -#ifndef BIT -#define BIT(i) (1<<(i)) -#endif - -#ifndef BIT64 -#define BIT64(i) (1LL << (i)) -#endif - -#ifdef __cplusplus -} -#endif diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7231n/soc_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7231n/soc_cap.h deleted file mode 100644 index c6f862f5cba3d1bb292bcf3f454684fdddb0318f..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7231n/soc_cap.h +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#include "adc_cap.h" -#include "aon_pmu_cap.h" -#include "calendar_cap.h" -#include "dma_cap.h" -#include "efuse_cap.h" -#include "gpio_cap.h" -#include "i2c_cap.h" -#include "icu_cap.h" -#include "pwm_cap.h" -#include "spi_cap.h" -#include "sys_cap.h" -#include "timer_cap.h" -#include "trng_cap.h" -#include "uart_cap.h" -#include "wdt_cap.h" diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7231n/spi_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7231n/spi_cap.h deleted file mode 100644 index 228993416709eae8525de88685f24a58dc684840..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7231n/spi_cap.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_SPI_UNIT_NUM 1 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7231n/sys_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7231n/sys_cap.h deleted file mode 100644 index 7a25dd27f1f1a2e9d7fd91580e1b7328ddce2433..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7231n/sys_cap.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_SYSTEM_GPIO_FUNC_GROUP 6 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7231n/timer_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7231n/timer_cap.h deleted file mode 100644 index 6a476fc8b05281a4a23c346cfe6e00b5154ca714..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7231n/timer_cap.h +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_TIMER_UNIT_NUM 1 -#define SOC_TIMER_CHAN_NUM_PER_UNIT 6 -#define SOC_TIMER_GROUP_NUM 2 -#define SOC_TIMER_CHAN_NUM_PER_GROUP 3 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7231n/trng_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7231n/trng_cap.h deleted file mode 100644 index 46505120e4eab86c79b97d16558f6ef4cae0cf5f..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7231n/trng_cap.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_TRNG_UNIT_NUM 1 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7231n/uart_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7231n/uart_cap.h deleted file mode 100644 index 47ecb5c1ce6aa5a1a5281ee411f71d16d1c9d97c..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7231n/uart_cap.h +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_UART_UNIT_NUM 1 -#define SOC_UART_ID_NUM_PER_UNIT 2 - -#ifdef __cplusplus -} -#endif - - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7231n/wdt_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7231n/wdt_cap.h deleted file mode 100644 index 335278317c6ad9cd7872b4306c6fe82f28e61591..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7231n/wdt_cap.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_WDT_UNIT_NUM 1 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7231u/mapping.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7231u/mapping.h deleted file mode 100755 index b97c4f04485d7d9f59f93e1b926858a37e07de05..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7231u/mapping.h +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7231u/soc.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7231u/soc.h deleted file mode 100755 index 8ffa6b9574e34496a8ed788340c465dc522a441c..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7231u/soc.h +++ /dev/null @@ -1,102 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_SYS_CTRL_REG_BASE (0x00800000) -#define SOC_EFUSE_REG_BASE (SOC_SYS_CTRL_REG_BASE + 0x1D * 4) -#define SOC_ICU_REG_BASE (0x00802000) -#define SOC_UART_REG_BASE (0x00802100) -#define SOC_I2C0_REG_BASE (0x00802300) -#define SOC_TRNG_REG_BASE (0x00802480) -#define SOC_I2C1_REG_BASE (0x00802600) -#define SOC_SPI_REG_BASE (0x00802700) -#define SOC_GPIO_REG_BASE (0x00802800) -#define SOC_WDT_REG_BASE (0x00802900) -#define SOC_TIMER_REG_BASE (0x00802A00) -#define SOC_PWM_REG_BASE (SOC_TIMER_REG_BASE + 0x20 * 4) /**< 0x802A80 */ -#define SOC_ADC_REG_BASE (0x00802C00) -#define SOC_DMA_REG_BASE (0x00809000) -#define SOC_JPEG_REG_BASE (0x0080A000) -#define SOC_QSPI_REG_BASE (0x0080D000) - -#define REG_WRITE(_r, _v) ({\ - (*(volatile uint32_t *)(_r)) = (_v);\ - }) - -#define REG_READ(_r) ({\ - (*(volatile uint32_t *)(_r));\ - }) - -#define REG_GET_BIT(_r, _b) ({\ - (*(volatile uint32_t*)(_r) & (_b));\ - }) - -#define REG_SET_BIT(_r, _b) ({\ - (*(volatile uint32_t*)(_r) |= (_b));\ - }) - -#define REG_CLR_BIT(_r, _b) ({\ - (*(volatile uint32_t*)(_r) &= ~(_b));\ - }) - -#define REG_SET_BITS(_r, _b, _m) ({\ - (*(volatile uint32_t*)(_r) = (*(volatile uint32_t*)(_r) & ~(_m)) | ((_b) & (_m)));\ - }) - -#define REG_GET_FIELD(_r, _f) ({\ - ((REG_READ(_r) >> (_f##_S)) & (_f##_V));\ - }) - -#define REG_SET_FIELD(_r, _f, _v) ({\ - (REG_WRITE((_r),((REG_READ(_r) & ~((_f##_V) << (_f##_S)))|(((_v) & (_f##_V))<<(_f##_S)))));\ - }) - -#define REG_MCHAN_GET_FIELD(_ch, _r, _f) ({\ - ((REG_READ(_r) >> (_f##_MS(_ch))) & (_f##_V));\ - }) - -#define REG_MCHAN_SET_FIELD(_ch, _r, _f, _v) ({\ - (REG_WRITE((_r), ((REG_READ(_r) & ~((_f##_V) << (_f##_MS(_ch))))|(((_v) & (_f##_V))<<(_f##_MS(_ch))))));\ - }) - -#define VALUE_GET_FIELD(_r, _f) (((_r) >> (_f##_S)) & (_f)) - -#define VALUE_GET_FIELD2(_r, _f) (((_r) & (_f))>> (_f##_S)) - -#define VALUE_SET_FIELD(_r, _f, _v) ((_r)=(((_r) & ~((_f) << (_f##_S)))|((_v)<<(_f##_S)))) - -#define VALUE_SET_FIELD2(_r, _f, _v) ((_r)=(((_r) & ~(_f))|((_v)<<(_f##_S)))) - -#define FIELD_TO_VALUE(_f, _v) (((_v)&(_f))<<_f##_S) - -#define FIELD_TO_VALUE2(_f, _v) (((_v)<<_f##_S) & (_f)) - -#ifndef BIT -#define BIT(i) ((1L)<<(i)) -#endif - -#ifndef BIT64 -#define BIT64(i) (1LL << (i)) -#endif - -#ifdef __cplusplus -} -#endif diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7235/reg_base.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7235/reg_base.h index 7fd95cd16548d07a86a7e9e3a963164d82bd8783..e6034dc6238d7e4e2573d9c6cff63843f40c83a4 100644 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7235/reg_base.h +++ b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7235/reg_base.h @@ -1,3 +1,17 @@ +/* + * Copyright (C) 2022 Beken Corporation + * 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 __REG_BASE_H__ #define __REG_BASE_H__ diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7235_cp1/adc_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7235_cp1/adc_cap.h deleted file mode 100755 index eac19c4001bb61a16dab85b3a174d44d514b8c6b..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7235_cp1/adc_cap.h +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -/* TODO - Frank check it - * 1. Whether ADC channel is begin from 1 - * 2. Whether analog channel is begin from 7 - **/ - -#define SOC_ADC_SAMPLE_CNT_MAX 32 - -#define SOC_ADC_FIFO_DATA_SUPPORT -#define SOC_ADC_DC_OFFSET_SUPPORT -#define SOC_ADC_GAIN_SUPPORT - - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7235_cp1/aon_pmu_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7235_cp1/aon_pmu_cap.h deleted file mode 100755 index 6eed470f4040d199fee045bbf852b37379e17a01..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7235_cp1/aon_pmu_cap.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define AON_PMU_GPIO_FUNC_GROUP 1 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7235_cp1/aon_rtc_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7235_cp1/aon_rtc_cap.h deleted file mode 100755 index 3c3443fd8fe85d62f6f3fd5dd96b0b3c2bf03d02..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7235_cp1/aon_rtc_cap.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_AON_RTC_UNIT_NUM 1 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7235_cp1/aud_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7235_cp1/aud_cap.h deleted file mode 100755 index 30647aca920dbb37add20d3b3e5687f94231a1c7..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7235_cp1/aud_cap.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_AUD_ISR_NUM 4 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7235_cp1/dma_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7235_cp1/dma_cap.h deleted file mode 100755 index 40f7942214ca5197ae0b8999004be6c55adb286b..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7235_cp1/dma_cap.h +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_DMA_UNIT_NUM 1 -#define SOC_DMA_CHAN_NUM_PER_UNIT 12 - - -#ifdef __cplusplus -} -#endif diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7235_cp1/efuse_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7235_cp1/efuse_cap.h deleted file mode 100755 index 6ec28cd053b59a2ad9e9c8ebc87c0c1f06487934..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7235_cp1/efuse_cap.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_EFUSE_UNIT_NUM 1 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7235_cp1/fft_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7235_cp1/fft_cap.h deleted file mode 100755 index 76a1966295bcd4b4dfe0fc81d4d2086faf404413..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7235_cp1/fft_cap.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_FFT_ISR_NUM 1 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7235_cp1/gpio_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7235_cp1/gpio_cap.h deleted file mode 100755 index 05dd5527b01562d98e9a72afb4ed069258fc69fb..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7235_cp1/gpio_cap.h +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_GPIO_0_31_NUM 32 -#define SOC_GPIO_32_47_NUM 16 -#define SOC_GPIO_NUM 48 -#define SOC_GPIO_SYSTEM_GROUP_NUM 6 -#define GPIO_PERI_FUNC_NUM 6 - -#ifdef __cplusplus -} -#endif diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7235_cp1/i2c_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7235_cp1/i2c_cap.h deleted file mode 100755 index 533c34e0e7a9771fff5a7b3cf58393980de4415d..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7235_cp1/i2c_cap.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_I2C_UNIT_NUM 2 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7235_cp1/i2s_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7235_cp1/i2s_cap.h deleted file mode 100755 index 35a73d9c44ef6fce68f61ad4f8458b13f11a2ec9..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7235_cp1/i2s_cap.h +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -//the max of channel number is 4 -#define SOC_I2S_CHANNEL_NUM 1 -#define SOC_I2S_ISR_NUM SOC_I2S_CHANNEL_NUM*4 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7235_cp1/icu_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7235_cp1/icu_cap.h deleted file mode 100755 index b97c4f04485d7d9f59f93e1b926858a37e07de05..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7235_cp1/icu_cap.h +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7235_cp1/jpeg_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7235_cp1/jpeg_cap.h deleted file mode 100755 index 43ddac0c4f32d0cfeaa5ecd9b1cff35396d318f8..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7235_cp1/jpeg_cap.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_JPEG_UNIT_NUM 1 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7235_cp1/mailbox_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7235_cp1/mailbox_cap.h deleted file mode 100755 index 4a13d9952ea40912a08154413e74fc18e396d0d2..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7235_cp1/mailbox_cap.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_MAILBOX_NUM 2 - -#ifdef __cplusplus -} -#endif - - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7235_cp1/mapping.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7235_cp1/mapping.h deleted file mode 100755 index b97c4f04485d7d9f59f93e1b926858a37e07de05..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7235_cp1/mapping.h +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7235_cp1/pwm_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7235_cp1/pwm_cap.h deleted file mode 100755 index cdf4c0fbd3553b5c532f2bc3bd8f78a92e8712e5..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7235_cp1/pwm_cap.h +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_PWM_UNIT_NUM 1 -#define SOC_PWM_CHAN_NUM_PER_UNIT 6 -#define SOC_PWM_CHAN_NUM_PER_GROUP 2 -#define SOC_PWM_GROUP_NUM 3 - -#ifdef __cplusplus -} -#endif diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7235_cp1/reg_base.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7235_cp1/reg_base.h deleted file mode 100755 index 7a229c58181eaa4bc2df45bd9f29d6e7a7aa3c6c..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7235_cp1/reg_base.h +++ /dev/null @@ -1,60 +0,0 @@ -#ifndef __REG_BASE_H__ -#define __REG_BASE_H__ - -/*********************************************************************************************************************************** -* This file is generated from BK7256_ADDR Mapping_20211224_format_change_highlight_20220113_update.xlsm automatically -* Modify it manually is not recommended -* CHIP ID:BK7256,GENARATE TIME:2022-01-17 15:34:58 -************************************************************************************************************************************/ - -#define SOC_SYSTEM_REG_BASE (0x44010000) -#define SOC_AON_PMU_REG_BASE (0x44000000) -#define SOC_CPU_PLIC_REG_BASE (0xE4000000) -#define SOC_AON_WDT_REG_BASE (0x44000600) -#define SOC_AON_GPIO_REG_BASE (0x44000400) -#define SOC_AON_RTC_REG_BASE (0x44000200) -#define SOC_FLASH_REG_BASE (0x44030000) -#define SOC_MBOX0_REG_BASE (0xA0000000) -#define SOC_MBOX1_REG_BASE (0xA0008000) -#define SOC_GENER_DMA_REG_BASE (0x44020000) -#define SOC_FFT_REG_BASE (0x47000000) -#define SOC_SBC_REG_BASE (0x47010000) -#define SOC_UART0_REG_BASE (0x44820000) -#define SOC_UART1_REG_BASE (0x45830000) -#define SOC_UART2_REG_BASE (0x45840000) -#define SOC_SPI_REG_BASE (0x44860000) -#define SOC_WDT_REG_BASE (0x44800000) -#define SOC_SPI1_REG_BASE (0x458C0000) -#define SOC_I2C0_REG_BASE (0x44850000) -#define SOC_I2C1_REG_BASE (0x45890000) -#define SOC_TIMER0_REG_BASE (0x44810000) -#define SOC_TIMER1_REG_BASE (0x45800000) -#define SOC_PWM01_REG_BASE (0x44840000) -#define SOC_PWM23_REG_BASE (0x44840040) -#define SOC_PWM45_REG_BASE (0x44840080) -#define SOC_SADC_REG_BASE (0x44870000) -#define SOC_EFUSE_REG_BASE (0x44880000) -#define SOC_IRDA_REG_BASE (0x44890000) -#define SOC_I2S_REG_BASE (0x47810000) -#define SOC_TRNG_REG_BASE (0x448A0000) -#define SOC_XVR_REG_BASE (0x4A800000) -#define SOC_AUD_REG_BASE (0x47800000) -#define SOC_LA_REG_BASE (0x45070000) -#define SOC_JPEG_REG_BASE (0x48000000) -#define SOC_JPEG_DEC_REG_BASE (0x48040000) -#define SOC_EIP130_REG_BASE (0x4b000000) -#define SOC_EIP130OTP_REG_BASE (0x4b004000) -#define SOC_EIP130REGITER_REG_BASE (0x4b008000) -#define SOC_QSPI_REG_BASE (0x46040000) -#define SOC_LCD_DISP_REG_BASE (0x48060000) -#define SOC_SDIO_REG_BASE (0x448B0000) -#define SOC_USB_REG_BASE (0x46002000) -#define SOC_RC_REG_BASE (0x4980C000) -#define SOC_TRX_REG_BASE (0x4980C200) -#define SOC_POWTBL_REG_BASE (0x4980C400) -#define SOC_DPDTBL_REG_BASE (0x4980C800) -#define SOC_AGCMEM_REG_BASE (0x4980A000) -#define SOC_PEAKCWMEM_REG_BASE (0x4980D000) -#define SOC_DMA2D_REG_BASE (0x48020000) -#define SOC_PSRAM_REG_BASE (0x46080000) -#endif //__REG_BASE_H__ diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7235_cp1/soc.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7235_cp1/soc.h deleted file mode 100755 index 6eaa0b62d2dc371d44c010518c0321bf91e9e4c5..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7235_cp1/soc.h +++ /dev/null @@ -1,117 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#include -#include "soc_cap.h" -#include "reg_base.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_VAULT_HOST_BASE (0x4B000000) -#define SOC_VAULT_OTP_BASE (0x4B004000) -#define SOC_VAULT_REG_BASE (0x4B008000) -#if 0 -#define SOC_EFUSE_REG_BASE (0x44880000) -#define SOC_SYSTEM_REG_BASE (0x44010000) -#define SOC_UART_REG_BASE (0x44820000) -#define SOC_TRNG_REG_BASE (0x448A0000) -#define SOC_WDT_REG_BASE (0x44800000) -#define SOC_TIMER_REG_BASE (0x44810000) -#define SOC_GPIO_REG_BASE (0x44000400) -#define SOC_DMA_REG_BASE (0x44020000) -#define SOC_ADC_REG_BASE (0x44870000) -#define SOC_SPI1_REG_BASE (0x44860000) -#define SOC_SPI2_REG_BASE (0x458C0000) -#define SOC_MAILBOX_REG_BASE (0xA0000000) -#define SOC_QSPI_REG_BASE (0x46040000) -#define SOC_QSPI_DATA_REG_BASE (0x68000000) -#endif -#define SOC_PWM_REG_BASE (0x44840000) -#define SOC_ICU_REG_BASE (0x44010000) -#define SOC_FLASH_REG_BASE (0x44030000) -#if 0 -#define SOC_AON_PMU_REG_BASE (0x44000000) -#define SOC_I2C0_REG_BASE (0x44850000) -#define SOC_I2C1_REG_BASE (0x45890000) -#define SOC_AUD_REG_BASE (0x47800000) -#endif -#define SOC_SDIO_REG_BASE (0x448B0000) - -#define REG_WRITE(_r, _v) ({\ - (*(volatile uint32_t *)(_r)) = (_v);\ - }) - -#define REG_READ(_r) ({\ - (*(volatile uint32_t *)(_r));\ - }) - -#define REG_GET_BIT(_r, _b) ({\ - (*(volatile uint32_t*)(_r) & (_b));\ - }) - -#define REG_SET_BIT(_r, _b) ({\ - (*(volatile uint32_t*)(_r) |= (_b));\ - }) - -#define REG_CLR_BIT(_r, _b) ({\ - (*(volatile uint32_t*)(_r) &= ~(_b));\ - }) - -#define REG_SET_BITS(_r, _b, _m) ({\ - (*(volatile uint32_t*)(_r) = (*(volatile uint32_t*)(_r) & ~(_m)) | ((_b) & (_m)));\ - }) - -#define REG_GET_FIELD(_r, _f) ({\ - ((REG_READ(_r) >> (_f##_S)) & (_f##_V));\ - }) - -#define REG_SET_FIELD(_r, _f, _v) ({\ - (REG_WRITE((_r),((REG_READ(_r) & ~((_f##_V) << (_f##_S)))|(((_v) & (_f##_V))<<(_f##_S)))));\ - }) - -#define REG_MCHAN_GET_FIELD(_ch, _r, _f) ({\ - ((REG_READ(_r) >> (_f##_MS(_ch))) & (_f##_V));\ - }) - -#define REG_MCHAN_SET_FIELD(_ch, _r, _f, _v) ({\ - (REG_WRITE((_r), ((REG_READ(_r) & ~((_f##_V) << (_f##_MS(_ch))))|(((_v) & (_f##_V))<<(_f##_MS(_ch))))));\ - }) - -#define VALUE_GET_FIELD(_r, _f) (((_r) >> (_f##_S)) & (_f)) - -#define VALUE_GET_FIELD2(_r, _f) (((_r) & (_f))>> (_f##_S)) - -#define VALUE_SET_FIELD(_r, _f, _v) ((_r)=(((_r) & ~((_f) << (_f##_S)))|((_v)<<(_f##_S)))) - -#define VALUE_SET_FIELD2(_r, _f, _v) ((_r)=(((_r) & ~(_f))|((_v)<<(_f##_S)))) - -#define FIELD_TO_VALUE(_f, _v) (((_v)&(_f))<<_f##_S) - -#define FIELD_TO_VALUE2(_f, _v) (((_v)<<_f##_S) & (_f)) - -#ifndef BIT -#define BIT(i) (1<<(i)) -#endif - -#ifndef BIT64 -#define BIT64(i) (1LL << (i)) -#endif - -#ifdef __cplusplus -} -#endif diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7235_cp1/soc_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7235_cp1/soc_cap.h deleted file mode 100755 index 7aad100961dc9e5005bc4b5e3e5f42a5cf2267a8..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7235_cp1/soc_cap.h +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#include "adc_cap.h" -#include "aon_pmu_cap.h" -#include "dma_cap.h" -#include "efuse_cap.h" -#include "gpio_cap.h" -#include "i2c_cap.h" -#include "icu_cap.h" -#include "pwm_cap.h" -#include "spi_cap.h" -#include "sys_cap.h" -#include "timer_cap.h" -#include "trng_cap.h" -#include "uart_cap.h" -#include "wdt_cap.h" -#include "mailbox_cap.h" -#include "aon_rtc_cap.h" -#include "i2s_cap.h" -#include "aud_cap.h" diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7235_cp1/spi_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7235_cp1/spi_cap.h deleted file mode 100755 index a777b8bd546d2e356f120da044b73091bb936424..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7235_cp1/spi_cap.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_SPI_UNIT_NUM 2 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7235_cp1/sys_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7235_cp1/sys_cap.h deleted file mode 100755 index 3d70982245ef48ab48a9f97010ed67a9218b57f3..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7235_cp1/sys_cap.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_SYSTEM_GPIO_FUNC_GROUP 6 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7235_cp1/timer_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7235_cp1/timer_cap.h deleted file mode 100755 index 64b3cfad064449bcac62ff95230860370f63378f..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7235_cp1/timer_cap.h +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_TIMER_UNIT_NUM 1 -#define SOC_TIMER_CHAN_NUM_PER_UNIT 6 -#define SOC_TIMER_GROUP_NUM 2 -#define SOC_TIMER_CHAN_NUM_PER_GROUP 3 -#define SOC_TIMER_INTERRUPT_NUM 2 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7235_cp1/trng_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7235_cp1/trng_cap.h deleted file mode 100755 index 46505120e4eab86c79b97d16558f6ef4cae0cf5f..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7235_cp1/trng_cap.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_TRNG_UNIT_NUM 1 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7235_cp1/uart_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7235_cp1/uart_cap.h deleted file mode 100755 index 8f8b3db159f4e43c9fd686216524c6b3c5583bd1..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7235_cp1/uart_cap.h +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_UART_UNIT_NUM 1 -#define SOC_UART_ID_NUM_PER_UNIT 3 - -#ifdef __cplusplus -} -#endif - - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7235_cp1/vault_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7235_cp1/vault_cap.h deleted file mode 100755 index ada03b2894920d7bde375f8c113e2300ec40553b..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7235_cp1/vault_cap.h +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_VAULT_UNIT_NUM 1 - -#ifdef __cplusplus -} -#endif - - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7235_cp1/wdt_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7235_cp1/wdt_cap.h deleted file mode 100755 index 335278317c6ad9cd7872b4306c6fe82f28e61591..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7235_cp1/wdt_cap.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_WDT_UNIT_NUM 1 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236/adc_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236/adc_cap.h deleted file mode 100755 index 0377a569f312f907ce91f52fb62b7d859f38df1e..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236/adc_cap.h +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -/* TODO - Frank check it - * 1. Whether ADC channel is begin from 1 - * 2. Whether analog channel is begin from 7 - **/ - -#define SOC_ADC_CHAN_MIN 1 -#define SOC_ADC_CHAN_MAX 6 -#define SOC_ADC_SAMPLE_CNT_MAX 32 - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236/aon_rtc_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236/aon_rtc_cap.h deleted file mode 100644 index 3c3443fd8fe85d62f6f3fd5dd96b0b3c2bf03d02..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236/aon_rtc_cap.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_AON_RTC_UNIT_NUM 1 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236/aon_wdt_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236/aon_wdt_cap.h deleted file mode 100644 index 87bd066b92ce015a1b70e636c13b6b4a297a7e26..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236/aon_wdt_cap.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_AON_WDT_UNIT_NUM 1 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236/calendar_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236/calendar_cap.h deleted file mode 100644 index 82ddd33ea2cc95dc80235c082720b886239133cb..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236/calendar_cap.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_CALENDAR_UNIT_NUM 1 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236/dma_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236/dma_cap.h deleted file mode 100755 index f957c69c784ca9a830afacc5b554d2858f0588a2..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236/dma_cap.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_DMA_UNIT_NUM 1 -#define SOC_DMA_CHAN_NUM_PER_UNIT 6 - -#ifdef __cplusplus -} -#endif diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236/efuse_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236/efuse_cap.h deleted file mode 100755 index 6ec28cd053b59a2ad9e9c8ebc87c0c1f06487934..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236/efuse_cap.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_EFUSE_UNIT_NUM 1 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236/flash_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236/flash_cap.h deleted file mode 100644 index 0968373d28b9fd5a10402eaf963cb2467eb16aaf..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236/flash_cap.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_FLASH_UNIT_NUM 1 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236/gpio_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236/gpio_cap.h deleted file mode 100755 index 4a6c633dded24c2d82401712d76461cdc6ba3fa7..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236/gpio_cap.h +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_GPIO_NUM 48 -#define GPIO_PERI_FUNC_NUM 4 -#define SOC_GPIO_SYSTEM_GROUP_NUM 6 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236/i2c_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236/i2c_cap.h deleted file mode 100644 index 533c34e0e7a9771fff5a7b3cf58393980de4415d..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236/i2c_cap.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_I2C_UNIT_NUM 2 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236/icu_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236/icu_cap.h deleted file mode 100755 index b97c4f04485d7d9f59f93e1b926858a37e07de05..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236/icu_cap.h +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236/jpeg_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236/jpeg_cap.h deleted file mode 100644 index 43ddac0c4f32d0cfeaa5ecd9b1cff35396d318f8..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236/jpeg_cap.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_JPEG_UNIT_NUM 1 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236/mapping.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236/mapping.h deleted file mode 100755 index b97c4f04485d7d9f59f93e1b926858a37e07de05..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236/mapping.h +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236/pwm_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236/pwm_cap.h deleted file mode 100755 index cdf4c0fbd3553b5c532f2bc3bd8f78a92e8712e5..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236/pwm_cap.h +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_PWM_UNIT_NUM 1 -#define SOC_PWM_CHAN_NUM_PER_UNIT 6 -#define SOC_PWM_CHAN_NUM_PER_GROUP 2 -#define SOC_PWM_GROUP_NUM 3 - -#ifdef __cplusplus -} -#endif diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236/reg_base.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236/reg_base.h deleted file mode 100644 index 9f251d4a4d66fdef1013d36556e3c48d5d45f231..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236/reg_base.h +++ /dev/null @@ -1,107 +0,0 @@ -// Copyright 2022-2023 Beken -// -// 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. - -#pragma once - -#define SOC_S_NS_ADDR_DIFF (0x10000000) - -#ifdef CONFIG_SPE -#define SOC_ADDR_OFFSET (0) -#define SOC_S_BASE(addr) (addr) -#define SOC_NS_BASE(addr) ((addr) + SOC_S_NS_ADDR_DIFF) -#else -#define SOC_ADDR_OFFSET SOC_S_NS_ADDR_DIFF -#define SOC_S_BASE(addr) ((addr) - SOC_S_NS_ADDR_DIFF) -#define SOC_NS_BASE(addr) (addr) -#endif - -#define SOC_FLASH_DATA_BASE (0x02000000 + SOC_ADDR_OFFSET) -#define SOC_ROM_DATA_BASE (0x06000000 + SOC_ADDR_OFFSET) -#define SOC_SRAM0_DATA_BASE (0x28000000 + SOC_ADDR_OFFSET) //64K -#define SOC_SRAM1_DATA_BASE (0x28010000 + SOC_ADDR_OFFSET) //64K -#define SOC_SRAM2_DATA_BASE (0x28020000 + SOC_ADDR_OFFSET) //64K -#define SOC_SRAM3_DATA_BASE (0x28040000 + SOC_ADDR_OFFSET) //128K -#define SOC_SRAM4_DATA_BASE (0x28060000 + SOC_ADDR_OFFSET) //128K - -#define SOC_PSRAM_DATA_BASE (0x60000000 + SOC_ADDR_OFFSET) -#define SOC_QSPI0_DATA_BASE (0x64000000 + SOC_ADDR_OFFSET) -#define SOC_QSPI1_DATA_BASE (0x68000000 + SOC_ADDR_OFFSET) - -#define SOC_SYSTEM_REG_BASE (0x44010000 + SOC_ADDR_OFFSET) -#define SOC_AON_PMU_REG_BASE (0x44000000 + SOC_ADDR_OFFSET) - -#define SOC_MPC_PSRAM_REG_BASE (0x41100000 + SOC_ADDR_OFFSET) -#define SOC_MPC_QSPI0_REG_BASE (0x41110000 + SOC_ADDR_OFFSET) -#define SOC_MPC_QSPI1_REG_BASE (0x41120000 + SOC_ADDR_OFFSET) -#define SOC_MPC_OTP_REG_BASE (0x41130000 + SOC_ADDR_OFFSET) -#define SOC_MPC_FLASH_REG_BASE (0x41200000 + SOC_ADDR_OFFSET) -#define SOC_MPC_SMEM0_REG_BASE (0x41210000 + SOC_ADDR_OFFSET) -#define SOC_MPC_SMEM1_REG_BASE (0x41220000 + SOC_ADDR_OFFSET) -#define SOC_MPC_SMEM2_REG_BASE (0x41230000 + SOC_ADDR_OFFSET) -#define SOC_MPC_SMEM3_REG_BASE (0x41240000 + SOC_ADDR_OFFSET) -#define SOC_MPC_SMEM4_REG_BASE (0x41250000 + SOC_ADDR_OFFSET) - -#define SOC_AON_WDT_REG_BASE (0x44000600 + SOC_ADDR_OFFSET) -#define SOC_AON_GPIO_REG_BASE (0x44000400 + SOC_ADDR_OFFSET) -#define SOC_AON_RTC_REG_BASE (0x44000200 + SOC_ADDR_OFFSET) -#define SOC_FLASH_REG_BASE (0x44030000 + SOC_ADDR_OFFSET) -#define SOC_MBOX0_REG_BASE (0x41000000 + SOC_ADDR_OFFSET) -#define SOC_MBOX1_REG_BASE (0x41020000 + SOC_ADDR_OFFSET) -#define SOC_GENER_DMA_REG_BASE (0x45020000 + SOC_ADDR_OFFSET) -#define SOC_PSRAM_REG_BASE (0x46080040 + SOC_ADDR_OFFSET) -#define SOC_SBC_REG_BASE (0x47010000 + SOC_ADDR_OFFSET) -#define SOC_UART0_REG_BASE (0x44820000 + SOC_ADDR_OFFSET) -#define SOC_UART1_REG_BASE (0x45830000 + SOC_ADDR_OFFSET) -#define SOC_UART2_REG_BASE (0x45840000 + SOC_ADDR_OFFSET) -#define SOC_CAN_REG_BASE (0x46020000 + SOC_ADDR_OFFSET) -#define SOC_WDT_REG_BASE (0x44800000 + SOC_ADDR_OFFSET) -#define SOC_SPI_REG_BASE (0x44870000 + SOC_ADDR_OFFSET) -#define SOC_SPI1_REG_BASE (0x45880000 + SOC_ADDR_OFFSET) -#define SOC_I2C0_REG_BASE (0x45850000 + SOC_ADDR_OFFSET) -#define SOC_I2C1_REG_BASE (0x45860000 + SOC_ADDR_OFFSET) -#define SOC_TIMER0_REG_BASE (0x44810000 + SOC_ADDR_OFFSET) -#define SOC_TIMER1_REG_BASE (0x45800000 + SOC_ADDR_OFFSET) -#define SOC_PWM01_REG_BASE (0x458a0000 + SOC_ADDR_OFFSET) -#define SOC_PWM23_REG_BASE (0x458f0000 + SOC_ADDR_OFFSET) -#define SOC_SDMADC_REG_BASE (0x45810000 + SOC_ADDR_OFFSET) -#define SOC_SADC_REG_BASE (0x44890000 + SOC_ADDR_OFFSET) -#define SOC_AUD_REG_BASE (0x47800000 + SOC_ADDR_OFFSET) -#define SOC_EFUSE_REG_BASE (0x44880000 + SOC_ADDR_OFFSET) -#define SOC_IRDA_REG_BASE (0x458b0000 + SOC_ADDR_OFFSET) -#define SOC_I2S_REG_BASE (0x47810000 + SOC_ADDR_OFFSET) -#define SOC_I2S1_REG_BASE (0x47820000 + SOC_ADDR_OFFSET) -#define SOC_I2S2_REG_BASE (0x47830000 + SOC_ADDR_OFFSET) -#define SOC_TRNG_REG_BASE (0x458C0000 + SOC_ADDR_OFFSET) -#define SOC_XVR_REG_BASE (0x4A800000 + SOC_ADDR_OFFSET) -#define SOC_LA_REG_BASE (0x45070000 + SOC_ADDR_OFFSET) -#define SOC_JPEG_REG_BASE (0x48000000 + SOC_ADDR_OFFSET) -#define SOC_JPEG_DEC_REG_BASE (0x48040000 + SOC_ADDR_OFFSET) -#define SOC_YUV_BUF_REG_BASE (0x48020000 + SOC_ADDR_OFFSET) -#define SOC_OTP_REG_BASE (0x0b100000 + SOC_ADDR_OFFSET) -#define SOC_PRRO_REG_BASE (0x41040000 + SOC_ADDR_OFFSET) -#define SOC_QSPI0_REG_BASE (0x46040000 + SOC_ADDR_OFFSET) -#define SOC_QSPI2_REG_BASE (0x46060000 + SOC_ADDR_OFFSET) -#define SOC_H264_REG_BASE (0x48080000 + SOC_ADDR_OFFSET) -#define SOC_LCD_DISP_REG_BASE (0x48060000 + SOC_ADDR_OFFSET) -#define SOC_SDIO_REG_BASE (0x458d0000 + SOC_ADDR_OFFSET) -#define SOC_SLCD_REG_BASE (0x458e0000 + SOC_ADDR_OFFSET) -#define SOC_USB_REG_BASE (0x46002000 + SOC_ADDR_OFFSET) -#define SOC_RC_REG_BASE (0x4980C000 + SOC_ADDR_OFFSET) -#define SOC_TRX_REG_BASE (0x4980C200 + SOC_ADDR_OFFSET) -#define SOC_POWTBL_REG_BASE (0x4980C400 + SOC_ADDR_OFFSET) -#define SOC_DPDTBL_REG_BASE (0x4980C800 + SOC_ADDR_OFFSET) -#define SOC_AGCMEM_REG_BASE (0x4980A000 + SOC_ADDR_OFFSET) -#define SOC_PEAKCWMEM_REG_BASE (0x4980D000 + SOC_ADDR_OFFSET) -#define SOC_DMA2D_REG_BASE (0x48020000 + SOC_ADDR_OFFSET) -#define SOC_BKRW_REG_BASE (0x4a010000 + SOC_ADDR_OFFSET) diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236/soc.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236/soc.h deleted file mode 100755 index f015441e1ebb3322805e81ecd0d7c80f8360ea5e..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236/soc.h +++ /dev/null @@ -1,102 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#include -#include "soc_cap.h" -#include "reg_base.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_ICU_REG_BASE (0x00802000) -#define SOC_PWM_REG_BASE (0x00802B00) -#define SOC_DMA_REG_BASE (0x00809000) -//#define SOC_EFUSE_REG_BASE (0x00800000 + 0x1D * 4) -//#define SOC_UART_REG_BASE (0x00802100) -#define SOC_CALENDAR_REG_BASE (0x00800000 + 0x55 * 4) - -#if 0 -#define SOC_SYS_CTRL_REG_BASE () -#define SOC_TRNG_REG_BASE (0x00802480) -#define SOC_WDT_REG_BASE (0x00802900) -#define SOC_FLASH_REG_BASE (0x00803000) -#define SOC_JPEG_REG_BASE (0x00807000) -#endif - -#define REG_WRITE(_r, _v) ({\ - (*(volatile uint32_t *)(_r)) = (_v);\ - }) - -#define REG_READ(_r) ({\ - (*(volatile uint32_t *)(_r));\ - }) - -#define REG_GET_BIT(_r, _b) ({\ - (*(volatile uint32_t*)(_r) & (_b));\ - }) - -#define REG_SET_BIT(_r, _b) ({\ - (*(volatile uint32_t*)(_r) |= (_b));\ - }) - -#define REG_CLR_BIT(_r, _b) ({\ - (*(volatile uint32_t*)(_r) &= ~(_b));\ - }) - -#define REG_SET_BITS(_r, _b, _m) ({\ - (*(volatile uint32_t*)(_r) = (*(volatile uint32_t*)(_r) & ~(_m)) | ((_b) & (_m)));\ - }) - -#define REG_GET_FIELD(_r, _f) ({\ - ((REG_READ(_r) >> (_f##_S)) & (_f##_V));\ - }) - -#define REG_SET_FIELD(_r, _f, _v) ({\ - (REG_WRITE((_r),((REG_READ(_r) & ~((_f##_V) << (_f##_S)))|(((_v) & (_f##_V))<<(_f##_S)))));\ - }) - -#define REG_MCHAN_GET_FIELD(_ch, _r, _f) ({\ - ((REG_READ(_r) >> (_f##_MS(_ch))) & (_f##_V));\ - }) - -#define REG_MCHAN_SET_FIELD(_ch, _r, _f, _v) ({\ - (REG_WRITE((_r), ((REG_READ(_r) & ~((_f##_V) << (_f##_MS(_ch))))|(((_v) & (_f##_V))<<(_f##_MS(_ch))))));\ - }) - -#define VALUE_GET_FIELD(_r, _f) (((_r) >> (_f##_S)) & (_f)) - -#define VALUE_GET_FIELD2(_r, _f) (((_r) & (_f))>> (_f##_S)) - -#define VALUE_SET_FIELD(_r, _f, _v) ((_r)=(((_r) & ~((_f) << (_f##_S)))|((_v)<<(_f##_S)))) - -#define VALUE_SET_FIELD2(_r, _f, _v) ((_r)=(((_r) & ~(_f))|((_v)<<(_f##_S)))) - -#define FIELD_TO_VALUE(_f, _v) (((_v)&(_f))<<_f##_S) - -#define FIELD_TO_VALUE2(_f, _v) (((_v)<<_f##_S) & (_f)) - -#ifndef BIT -#define BIT(i) (1<<(i)) -#endif - -#ifndef BIT64 -#define BIT64(i) (1LL << (i)) -#endif - -#ifdef __cplusplus -} -#endif diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236/soc_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236/soc_cap.h deleted file mode 100644 index 4dcf2fa5fe9cd1040d62c4ce8d5a1855bcbdbcc5..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236/soc_cap.h +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#include "sys_cap.h" -#include "adc_cap.h" -#include "calendar_cap.h" -#include "dma_cap.h" -#include "efuse_cap.h" -#include "gpio_cap.h" -#include "i2c_cap.h" -#include "icu_cap.h" -#include "pwm_cap.h" -#include "spi_cap.h" -#include "sys_cap.h" -#include "timer_cap.h" -#include "trng_cap.h" -#include "uart_cap.h" -#include "wdt_cap.h" -#include "aon_rtc_cap.h" - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236/spi_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236/spi_cap.h deleted file mode 100755 index a777b8bd546d2e356f120da044b73091bb936424..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236/spi_cap.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_SPI_UNIT_NUM 2 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236/sys_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236/sys_cap.h deleted file mode 100644 index 7a25dd27f1f1a2e9d7fd91580e1b7328ddce2433..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236/sys_cap.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_SYSTEM_GPIO_FUNC_GROUP 6 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236/timer_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236/timer_cap.h deleted file mode 100755 index 6a476fc8b05281a4a23c346cfe6e00b5154ca714..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236/timer_cap.h +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_TIMER_UNIT_NUM 1 -#define SOC_TIMER_CHAN_NUM_PER_UNIT 6 -#define SOC_TIMER_GROUP_NUM 2 -#define SOC_TIMER_CHAN_NUM_PER_GROUP 3 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236/trng_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236/trng_cap.h deleted file mode 100755 index 46505120e4eab86c79b97d16558f6ef4cae0cf5f..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236/trng_cap.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_TRNG_UNIT_NUM 1 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236/uart_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236/uart_cap.h deleted file mode 100755 index 47ecb5c1ce6aa5a1a5281ee411f71d16d1c9d97c..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236/uart_cap.h +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_UART_UNIT_NUM 1 -#define SOC_UART_ID_NUM_PER_UNIT 2 - -#ifdef __cplusplus -} -#endif - - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236/wdt_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236/wdt_cap.h deleted file mode 100755 index 335278317c6ad9cd7872b4306c6fe82f28e61591..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236/wdt_cap.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_WDT_UNIT_NUM 1 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236a/adc_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236a/adc_cap.h deleted file mode 100755 index 0377a569f312f907ce91f52fb62b7d859f38df1e..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236a/adc_cap.h +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -/* TODO - Frank check it - * 1. Whether ADC channel is begin from 1 - * 2. Whether analog channel is begin from 7 - **/ - -#define SOC_ADC_CHAN_MIN 1 -#define SOC_ADC_CHAN_MAX 6 -#define SOC_ADC_SAMPLE_CNT_MAX 32 - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236a/calendar_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236a/calendar_cap.h deleted file mode 100644 index 82ddd33ea2cc95dc80235c082720b886239133cb..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236a/calendar_cap.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_CALENDAR_UNIT_NUM 1 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236a/dma_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236a/dma_cap.h deleted file mode 100755 index f957c69c784ca9a830afacc5b554d2858f0588a2..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236a/dma_cap.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_DMA_UNIT_NUM 1 -#define SOC_DMA_CHAN_NUM_PER_UNIT 6 - -#ifdef __cplusplus -} -#endif diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236a/efuse_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236a/efuse_cap.h deleted file mode 100755 index 6ec28cd053b59a2ad9e9c8ebc87c0c1f06487934..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236a/efuse_cap.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_EFUSE_UNIT_NUM 1 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236a/flash_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236a/flash_cap.h deleted file mode 100644 index 0968373d28b9fd5a10402eaf963cb2467eb16aaf..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236a/flash_cap.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_FLASH_UNIT_NUM 1 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236a/gpio_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236a/gpio_cap.h deleted file mode 100755 index b9ecef128187fdc68a37dc361d399ce04a8044df..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236a/gpio_cap.h +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_GPIO_NUM 32 -#define SOC_GPIO_USE_NUM 29 -#define GPIO_PERI_FUNC_NUM 4 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236a/i2c_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236a/i2c_cap.h deleted file mode 100644 index 533c34e0e7a9771fff5a7b3cf58393980de4415d..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236a/i2c_cap.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_I2C_UNIT_NUM 2 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236a/icu_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236a/icu_cap.h deleted file mode 100755 index b97c4f04485d7d9f59f93e1b926858a37e07de05..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236a/icu_cap.h +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236a/jpeg_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236a/jpeg_cap.h deleted file mode 100644 index 43ddac0c4f32d0cfeaa5ecd9b1cff35396d318f8..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236a/jpeg_cap.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_JPEG_UNIT_NUM 1 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236a/mapping.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236a/mapping.h deleted file mode 100755 index b97c4f04485d7d9f59f93e1b926858a37e07de05..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236a/mapping.h +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236a/pwm_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236a/pwm_cap.h deleted file mode 100755 index cdf4c0fbd3553b5c532f2bc3bd8f78a92e8712e5..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236a/pwm_cap.h +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_PWM_UNIT_NUM 1 -#define SOC_PWM_CHAN_NUM_PER_UNIT 6 -#define SOC_PWM_CHAN_NUM_PER_GROUP 2 -#define SOC_PWM_GROUP_NUM 3 - -#ifdef __cplusplus -} -#endif diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236a/soc.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236a/soc.h deleted file mode 100644 index 0e30ab996773b6b899ca090193798ab44c410f0d..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236a/soc.h +++ /dev/null @@ -1,104 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#include -#include "soc_cap.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_SYS_CTRL_REG_BASE (0x00800000) -#define SOC_EFUSE_REG_BASE (SOC_SYS_CTRL_REG_BASE + 0x1D * 4) -#define SOC_CALENDAR_REG_BASE (SOC_SYS_CTRL_REG_BASE + 0x55 * 4) -#define SOC_ICU_REG_BASE (0x00802000) -#define SOC_UART_REG_BASE (0x00802100) -#define SOC_I2C0_REG_BASE (0x00802300) -#define SOC_TRNG_REG_BASE (0x00802480) -#define SOC_I2C1_REG_BASE (0x00802600) -#define SOC_SPI_REG_BASE (0x00802700) -#define SOC_GPIO_REG_BASE (0x00802800) -#define SOC_WDT_REG_BASE (0x00802900) -#define SOC_TIMER_REG_BASE (0x00802A00) -#define SOC_PWM_REG_BASE (0x00802B00) -#define SOC_ADC_REG_BASE (0x00802C00) -#define SOC_FLASH_REG_BASE (0x00803000) -#define SOC_JPEG_REG_BASE (0x00807000) -#define SOC_DMA_REG_BASE (0x00809000) - -#define REG_WRITE(_r, _v) ({\ - (*(volatile uint32_t *)(_r)) = (_v);\ - }) - -#define REG_READ(_r) ({\ - (*(volatile uint32_t *)(_r));\ - }) - -#define REG_GET_BIT(_r, _b) ({\ - (*(volatile uint32_t*)(_r) & (_b));\ - }) - -#define REG_SET_BIT(_r, _b) ({\ - (*(volatile uint32_t*)(_r) |= (_b));\ - }) - -#define REG_CLR_BIT(_r, _b) ({\ - (*(volatile uint32_t*)(_r) &= ~(_b));\ - }) - -#define REG_SET_BITS(_r, _b, _m) ({\ - (*(volatile uint32_t*)(_r) = (*(volatile uint32_t*)(_r) & ~(_m)) | ((_b) & (_m)));\ - }) - -#define REG_GET_FIELD(_r, _f) ({\ - ((REG_READ(_r) >> (_f##_S)) & (_f##_V));\ - }) - -#define REG_SET_FIELD(_r, _f, _v) ({\ - (REG_WRITE((_r),((REG_READ(_r) & ~((_f##_V) << (_f##_S)))|(((_v) & (_f##_V))<<(_f##_S)))));\ - }) - -#define REG_MCHAN_GET_FIELD(_ch, _r, _f) ({\ - ((REG_READ(_r) >> (_f##_MS(_ch))) & (_f##_V));\ - }) - -#define REG_MCHAN_SET_FIELD(_ch, _r, _f, _v) ({\ - (REG_WRITE((_r), ((REG_READ(_r) & ~((_f##_V) << (_f##_MS(_ch))))|(((_v) & (_f##_V))<<(_f##_MS(_ch))))));\ - }) - -#define VALUE_GET_FIELD(_r, _f) (((_r) >> (_f##_S)) & (_f)) - -#define VALUE_GET_FIELD2(_r, _f) (((_r) & (_f))>> (_f##_S)) - -#define VALUE_SET_FIELD(_r, _f, _v) ((_r)=(((_r) & ~((_f) << (_f##_S)))|((_v)<<(_f##_S)))) - -#define VALUE_SET_FIELD2(_r, _f, _v) ((_r)=(((_r) & ~(_f))|((_v)<<(_f##_S)))) - -#define FIELD_TO_VALUE(_f, _v) (((_v)&(_f))<<_f##_S) - -#define FIELD_TO_VALUE2(_f, _v) (((_v)<<_f##_S) & (_f)) - -#ifndef BIT -#define BIT(i) (1<<(i)) -#endif - -#ifndef BIT64 -#define BIT64(i) (1LL << (i)) -#endif - -#ifdef __cplusplus -} -#endif diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236a/soc_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236a/soc_cap.h deleted file mode 100644 index 0a880a11537895c8ff248d44bbcb5bcce295572f..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236a/soc_cap.h +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#include "adc_cap.h" -#include "aon_pmu_cap.h" -#include "calendar_cap.h" -#include "dma_cap.h" -#include "efuse_cap.h" -#include "gpio_cap.h" -#include "i2c_cap.h" -#include "icu_cap.h" -#include "pwm_cap.h" -#include "spi_cap.h" -#include "sys_cap.h" -#include "timer_cap.h" -#include "trng_cap.h" -#include "uart_cap.h" -#include "wdt_cap.h" - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236a/spi_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236a/spi_cap.h deleted file mode 100755 index 228993416709eae8525de88685f24a58dc684840..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236a/spi_cap.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_SPI_UNIT_NUM 1 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236a/sys_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236a/sys_cap.h deleted file mode 100644 index 7a25dd27f1f1a2e9d7fd91580e1b7328ddce2433..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236a/sys_cap.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_SYSTEM_GPIO_FUNC_GROUP 6 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236a/timer_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236a/timer_cap.h deleted file mode 100755 index 6a476fc8b05281a4a23c346cfe6e00b5154ca714..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236a/timer_cap.h +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_TIMER_UNIT_NUM 1 -#define SOC_TIMER_CHAN_NUM_PER_UNIT 6 -#define SOC_TIMER_GROUP_NUM 2 -#define SOC_TIMER_CHAN_NUM_PER_GROUP 3 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236a/trng_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236a/trng_cap.h deleted file mode 100755 index 46505120e4eab86c79b97d16558f6ef4cae0cf5f..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236a/trng_cap.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_TRNG_UNIT_NUM 1 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236a/uart_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236a/uart_cap.h deleted file mode 100755 index 47ecb5c1ce6aa5a1a5281ee411f71d16d1c9d97c..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236a/uart_cap.h +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_UART_UNIT_NUM 1 -#define SOC_UART_ID_NUM_PER_UNIT 2 - -#ifdef __cplusplus -} -#endif - - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236a/wdt_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236a/wdt_cap.h deleted file mode 100755 index 335278317c6ad9cd7872b4306c6fe82f28e61591..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7236a/wdt_cap.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_WDT_UNIT_NUM 1 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237/adc_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237/adc_cap.h deleted file mode 100755 index eac19c4001bb61a16dab85b3a174d44d514b8c6b..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237/adc_cap.h +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -/* TODO - Frank check it - * 1. Whether ADC channel is begin from 1 - * 2. Whether analog channel is begin from 7 - **/ - -#define SOC_ADC_SAMPLE_CNT_MAX 32 - -#define SOC_ADC_FIFO_DATA_SUPPORT -#define SOC_ADC_DC_OFFSET_SUPPORT -#define SOC_ADC_GAIN_SUPPORT - - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237/aon_pmu_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237/aon_pmu_cap.h deleted file mode 100644 index 6eed470f4040d199fee045bbf852b37379e17a01..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237/aon_pmu_cap.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define AON_PMU_GPIO_FUNC_GROUP 1 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237/aon_rtc_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237/aon_rtc_cap.h deleted file mode 100644 index 3c3443fd8fe85d62f6f3fd5dd96b0b3c2bf03d02..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237/aon_rtc_cap.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_AON_RTC_UNIT_NUM 1 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237/aud_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237/aud_cap.h deleted file mode 100644 index 30647aca920dbb37add20d3b3e5687f94231a1c7..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237/aud_cap.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_AUD_ISR_NUM 4 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237/dma_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237/dma_cap.h deleted file mode 100755 index 49926b51d769b69dd07e1f571e90e0207ede74da..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237/dma_cap.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_DMA_UNIT_NUM 1 -#define SOC_DMA_CHAN_NUM_PER_UNIT 12 - -#ifdef __cplusplus -} -#endif diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237/efuse_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237/efuse_cap.h deleted file mode 100755 index 6ec28cd053b59a2ad9e9c8ebc87c0c1f06487934..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237/efuse_cap.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_EFUSE_UNIT_NUM 1 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237/fft_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237/fft_cap.h deleted file mode 100755 index 76a1966295bcd4b4dfe0fc81d4d2086faf404413..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237/fft_cap.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_FFT_ISR_NUM 1 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237/flash_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237/flash_cap.h deleted file mode 100644 index 0968373d28b9fd5a10402eaf963cb2467eb16aaf..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237/flash_cap.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_FLASH_UNIT_NUM 1 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237/gpio_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237/gpio_cap.h deleted file mode 100755 index 05dd5527b01562d98e9a72afb4ed069258fc69fb..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237/gpio_cap.h +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_GPIO_0_31_NUM 32 -#define SOC_GPIO_32_47_NUM 16 -#define SOC_GPIO_NUM 48 -#define SOC_GPIO_SYSTEM_GROUP_NUM 6 -#define GPIO_PERI_FUNC_NUM 6 - -#ifdef __cplusplus -} -#endif diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237/i2c_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237/i2c_cap.h deleted file mode 100644 index 533c34e0e7a9771fff5a7b3cf58393980de4415d..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237/i2c_cap.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_I2C_UNIT_NUM 2 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237/i2s_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237/i2s_cap.h deleted file mode 100755 index 35a73d9c44ef6fce68f61ad4f8458b13f11a2ec9..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237/i2s_cap.h +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -//the max of channel number is 4 -#define SOC_I2S_CHANNEL_NUM 1 -#define SOC_I2S_ISR_NUM SOC_I2S_CHANNEL_NUM*4 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237/icu_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237/icu_cap.h deleted file mode 100755 index b97c4f04485d7d9f59f93e1b926858a37e07de05..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237/icu_cap.h +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237/jpeg_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237/jpeg_cap.h deleted file mode 100755 index 43ddac0c4f32d0cfeaa5ecd9b1cff35396d318f8..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237/jpeg_cap.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_JPEG_UNIT_NUM 1 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237/lcd_disp_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237/lcd_disp_cap.h deleted file mode 100644 index c22b0d292c87e4e0ee17b474ce278f92763b72b7..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237/lcd_disp_cap.h +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - - -#define SOC_LCD_UNIT_NUM 1 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237/mailbox_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237/mailbox_cap.h deleted file mode 100755 index 4a13d9952ea40912a08154413e74fc18e396d0d2..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237/mailbox_cap.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_MAILBOX_NUM 2 - -#ifdef __cplusplus -} -#endif - - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237/mapping.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237/mapping.h deleted file mode 100755 index b97c4f04485d7d9f59f93e1b926858a37e07de05..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237/mapping.h +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237/pwm_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237/pwm_cap.h deleted file mode 100755 index cdf4c0fbd3553b5c532f2bc3bd8f78a92e8712e5..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237/pwm_cap.h +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_PWM_UNIT_NUM 1 -#define SOC_PWM_CHAN_NUM_PER_UNIT 6 -#define SOC_PWM_CHAN_NUM_PER_GROUP 2 -#define SOC_PWM_GROUP_NUM 3 - -#ifdef __cplusplus -} -#endif diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237/reg_base.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237/reg_base.h deleted file mode 100644 index dda351fd4be3a8022d3b04a44a3d4b6fe788b239..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237/reg_base.h +++ /dev/null @@ -1,61 +0,0 @@ -#ifndef __REG_BASE_H__ -#define __REG_BASE_H__ - -/*********************************************************************************************************************************** -* This file is generated from BK7256_ADDR Mapping_20211224_format_change_highlight_20220113_update.xlsm automatically -* Modify it manually is not recommended -* CHIP ID:BK7256,GENARATE TIME:2022-01-17 15:34:58 -************************************************************************************************************************************/ - -#define SOC_SYSTEM_REG_BASE (0x44010000) -#define SOC_AON_PMU_REG_BASE (0x44000000) -#define SOC_CPU_PLIC_REG_BASE (0xE4000000) -#define SOC_AON_WDT_REG_BASE (0x44000600) -#define SOC_AON_GPIO_REG_BASE (0x44000400) -#define SOC_AON_RTC_REG_BASE (0x44000200) -#define SOC_FLASH_REG_BASE (0x44030000) -#define SOC_MBOX0_REG_BASE (0xA0000000) -#define SOC_MBOX1_REG_BASE (0xA0008000) -#define SOC_GENER_DMA_REG_BASE (0x44020000) -#define SOC_FFT_REG_BASE (0x47000000) -#define SOC_SBC_REG_BASE (0x47010000) -#define SOC_UART0_REG_BASE (0x44820000) -#define SOC_UART1_REG_BASE (0x45830000) -#define SOC_UART2_REG_BASE (0x45840000) -#define SOC_SPI_REG_BASE (0x44860000) -#define SOC_WDT_REG_BASE (0x44800000) -#define SOC_SPI1_REG_BASE (0x458C0000) -#define SOC_I2C0_REG_BASE (0x44850000) -#define SOC_I2C1_REG_BASE (0x45890000) -#define SOC_TIMER0_REG_BASE (0x44810000) -#define SOC_TIMER1_REG_BASE (0x45800000) -#define SOC_PWM01_REG_BASE (0x44840000) -#define SOC_PWM23_REG_BASE (0x44840040) -#define SOC_PWM45_REG_BASE (0x44840080) -#define SOC_SADC_REG_BASE (0x44870000) -#define SOC_EFUSE_REG_BASE (0x44880000) -#define SOC_IRDA_REG_BASE (0x44890000) -#define SOC_I2S_REG_BASE (0x47810000) -#define SOC_TRNG_REG_BASE (0x448A0000) -#define SOC_XVR_REG_BASE (0x4A800000) -#define SOC_AUD_REG_BASE (0x47800000) -#define SOC_LA_REG_BASE (0x45070000) -#define SOC_JPEG_REG_BASE (0x48000000) -#define SOC_JPEG_DEC_REG_BASE (0x48040000) -#define SOC_EIP130_REG_BASE (0x4b000000) -#define SOC_EIP130OTP_REG_BASE (0x4b004000) -#define SOC_EIP130REGITER_REG_BASE (0x4b008000) -#define SOC_QSPI_REG_BASE (0x46040000) -#define SOC_LCD_DISP_REG_BASE (0x48060000) -#define SOC_SDIO_REG_BASE (0x448B0000) -#define SOC_USB_REG_BASE (0x46002000) -#define SOC_RC_REG_BASE (0x4980C000) -#define SOC_TRX_REG_BASE (0x4980C200) -#define SOC_POWTBL_REG_BASE (0x4980C400) -#define SOC_DPDTBL_REG_BASE (0x4980C800) -#define SOC_AGCMEM_REG_BASE (0x4980A000) -#define SOC_PEAKCWMEM_REG_BASE (0x4980D000) -#define SOC_PSRAM_REG_BASE (0x46080000) -#define SOC_DMA2D_REG_BASE (0x48020000) - -#endif //__REG_BASE_H__ diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237/soc.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237/soc.h deleted file mode 100755 index 430985d0eb90db0c289c507be7a7466f71afc0ce..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237/soc.h +++ /dev/null @@ -1,118 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#include -#include "soc_cap.h" -#include "reg_base.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_VAULT_HOST_BASE (0x4B000000) -#define SOC_VAULT_OTP_BASE (0x4B004000) -#define SOC_VAULT_REG_BASE (0x4B008000) -#if 0 -#define SOC_EFUSE_REG_BASE (0x44880000) -#define SOC_SYSTEM_REG_BASE (0x44010000) -#define SOC_UART_REG_BASE (0x44820000) -#define SOC_TRNG_REG_BASE (0x448A0000) -#define SOC_WDT_REG_BASE (0x44800000) -#define SOC_TIMER_REG_BASE (0x44810000) -#define SOC_GPIO_REG_BASE (0x44000400) -#define SOC_DMA_REG_BASE (0x44020000) -#define SOC_ADC_REG_BASE (0x44870000) -#define SOC_SPI1_REG_BASE (0x44860000) -#define SOC_SPI2_REG_BASE (0x458C0000) -#define SOC_MAILBOX_REG_BASE (0xA0000000) -#define SOC_QSPI_REG_BASE (0x46040000) -#endif -#define SOC_QSPI_DATA_REG_BASE (0x68000000) -#define SOC_PWM_REG_BASE (0x44840000) -#define SOC_ICU_REG_BASE (0x44010000) -#define SOC_FLASH_REG_BASE (0x44030000) -#if 0 -#define SOC_AON_PMU_REG_BASE (0x44000000) -#define SOC_I2C0_REG_BASE (0x44850000) -#define SOC_I2C1_REG_BASE (0x45890000) -#define SOC_AUD_REG_BASE (0x47800000) -#endif -#define SOC_SDIO_REG_BASE (0x448B0000) -#define SOC_SDIO_HOST_REG_BASE (SOC_SDIO_REG_BASE) - -#define REG_WRITE(_r, _v) ({\ - (*(volatile uint32_t *)(_r)) = (_v);\ - }) - -#define REG_READ(_r) ({\ - (*(volatile uint32_t *)(_r));\ - }) - -#define REG_GET_BIT(_r, _b) ({\ - (*(volatile uint32_t*)(_r) & (_b));\ - }) - -#define REG_SET_BIT(_r, _b) ({\ - (*(volatile uint32_t*)(_r) |= (_b));\ - }) - -#define REG_CLR_BIT(_r, _b) ({\ - (*(volatile uint32_t*)(_r) &= ~(_b));\ - }) - -#define REG_SET_BITS(_r, _b, _m) ({\ - (*(volatile uint32_t*)(_r) = (*(volatile uint32_t*)(_r) & ~(_m)) | ((_b) & (_m)));\ - }) - -#define REG_GET_FIELD(_r, _f) ({\ - ((REG_READ(_r) >> (_f##_S)) & (_f##_V));\ - }) - -#define REG_SET_FIELD(_r, _f, _v) ({\ - (REG_WRITE((_r),((REG_READ(_r) & ~((_f##_V) << (_f##_S)))|(((_v) & (_f##_V))<<(_f##_S)))));\ - }) - -#define REG_MCHAN_GET_FIELD(_ch, _r, _f) ({\ - ((REG_READ(_r) >> (_f##_MS(_ch))) & (_f##_V));\ - }) - -#define REG_MCHAN_SET_FIELD(_ch, _r, _f, _v) ({\ - (REG_WRITE((_r), ((REG_READ(_r) & ~((_f##_V) << (_f##_MS(_ch))))|(((_v) & (_f##_V))<<(_f##_MS(_ch))))));\ - }) - -#define VALUE_GET_FIELD(_r, _f) (((_r) >> (_f##_S)) & (_f)) - -#define VALUE_GET_FIELD2(_r, _f) (((_r) & (_f))>> (_f##_S)) - -#define VALUE_SET_FIELD(_r, _f, _v) ((_r)=(((_r) & ~((_f) << (_f##_S)))|((_v)<<(_f##_S)))) - -#define VALUE_SET_FIELD2(_r, _f, _v) ((_r)=(((_r) & ~(_f))|((_v)<<(_f##_S)))) - -#define FIELD_TO_VALUE(_f, _v) (((_v)&(_f))<<_f##_S) - -#define FIELD_TO_VALUE2(_f, _v) (((_v)<<_f##_S) & (_f)) - -#ifndef BIT -#define BIT(i) (1<<(i)) -#endif - -#ifndef BIT64 -#define BIT64(i) (1LL << (i)) -#endif - -#ifdef __cplusplus -} -#endif diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237/soc_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237/soc_cap.h deleted file mode 100644 index 7aad100961dc9e5005bc4b5e3e5f42a5cf2267a8..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237/soc_cap.h +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#include "adc_cap.h" -#include "aon_pmu_cap.h" -#include "dma_cap.h" -#include "efuse_cap.h" -#include "gpio_cap.h" -#include "i2c_cap.h" -#include "icu_cap.h" -#include "pwm_cap.h" -#include "spi_cap.h" -#include "sys_cap.h" -#include "timer_cap.h" -#include "trng_cap.h" -#include "uart_cap.h" -#include "wdt_cap.h" -#include "mailbox_cap.h" -#include "aon_rtc_cap.h" -#include "i2s_cap.h" -#include "aud_cap.h" diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237/spi_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237/spi_cap.h deleted file mode 100644 index a777b8bd546d2e356f120da044b73091bb936424..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237/spi_cap.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_SPI_UNIT_NUM 2 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237/sys_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237/sys_cap.h deleted file mode 100644 index 3d70982245ef48ab48a9f97010ed67a9218b57f3..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237/sys_cap.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_SYSTEM_GPIO_FUNC_GROUP 6 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237/system_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237/system_cap.h deleted file mode 100755 index 3d70982245ef48ab48a9f97010ed67a9218b57f3..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237/system_cap.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_SYSTEM_GPIO_FUNC_GROUP 6 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237/timer_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237/timer_cap.h deleted file mode 100755 index 64b3cfad064449bcac62ff95230860370f63378f..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237/timer_cap.h +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_TIMER_UNIT_NUM 1 -#define SOC_TIMER_CHAN_NUM_PER_UNIT 6 -#define SOC_TIMER_GROUP_NUM 2 -#define SOC_TIMER_CHAN_NUM_PER_GROUP 3 -#define SOC_TIMER_INTERRUPT_NUM 2 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237/trng_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237/trng_cap.h deleted file mode 100755 index 46505120e4eab86c79b97d16558f6ef4cae0cf5f..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237/trng_cap.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_TRNG_UNIT_NUM 1 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237/uart_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237/uart_cap.h deleted file mode 100755 index 8f8b3db159f4e43c9fd686216524c6b3c5583bd1..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237/uart_cap.h +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_UART_UNIT_NUM 1 -#define SOC_UART_ID_NUM_PER_UNIT 3 - -#ifdef __cplusplus -} -#endif - - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237/vault_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237/vault_cap.h deleted file mode 100755 index ada03b2894920d7bde375f8c113e2300ec40553b..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237/vault_cap.h +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_VAULT_UNIT_NUM 1 - -#ifdef __cplusplus -} -#endif - - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237/wdt_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237/wdt_cap.h deleted file mode 100755 index 335278317c6ad9cd7872b4306c6fe82f28e61591..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237/wdt_cap.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_WDT_UNIT_NUM 1 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237_cp1/adc_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237_cp1/adc_cap.h deleted file mode 100755 index eac19c4001bb61a16dab85b3a174d44d514b8c6b..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237_cp1/adc_cap.h +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -/* TODO - Frank check it - * 1. Whether ADC channel is begin from 1 - * 2. Whether analog channel is begin from 7 - **/ - -#define SOC_ADC_SAMPLE_CNT_MAX 32 - -#define SOC_ADC_FIFO_DATA_SUPPORT -#define SOC_ADC_DC_OFFSET_SUPPORT -#define SOC_ADC_GAIN_SUPPORT - - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237_cp1/aon_pmu_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237_cp1/aon_pmu_cap.h deleted file mode 100755 index 6eed470f4040d199fee045bbf852b37379e17a01..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237_cp1/aon_pmu_cap.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define AON_PMU_GPIO_FUNC_GROUP 1 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237_cp1/aon_rtc_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237_cp1/aon_rtc_cap.h deleted file mode 100755 index 3c3443fd8fe85d62f6f3fd5dd96b0b3c2bf03d02..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237_cp1/aon_rtc_cap.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_AON_RTC_UNIT_NUM 1 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237_cp1/aud_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237_cp1/aud_cap.h deleted file mode 100755 index 30647aca920dbb37add20d3b3e5687f94231a1c7..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237_cp1/aud_cap.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_AUD_ISR_NUM 4 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237_cp1/dma_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237_cp1/dma_cap.h deleted file mode 100755 index 49926b51d769b69dd07e1f571e90e0207ede74da..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237_cp1/dma_cap.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_DMA_UNIT_NUM 1 -#define SOC_DMA_CHAN_NUM_PER_UNIT 12 - -#ifdef __cplusplus -} -#endif diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237_cp1/efuse_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237_cp1/efuse_cap.h deleted file mode 100755 index 6ec28cd053b59a2ad9e9c8ebc87c0c1f06487934..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237_cp1/efuse_cap.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_EFUSE_UNIT_NUM 1 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237_cp1/fft_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237_cp1/fft_cap.h deleted file mode 100755 index 76a1966295bcd4b4dfe0fc81d4d2086faf404413..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237_cp1/fft_cap.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_FFT_ISR_NUM 1 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237_cp1/gpio_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237_cp1/gpio_cap.h deleted file mode 100755 index 05dd5527b01562d98e9a72afb4ed069258fc69fb..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237_cp1/gpio_cap.h +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_GPIO_0_31_NUM 32 -#define SOC_GPIO_32_47_NUM 16 -#define SOC_GPIO_NUM 48 -#define SOC_GPIO_SYSTEM_GROUP_NUM 6 -#define GPIO_PERI_FUNC_NUM 6 - -#ifdef __cplusplus -} -#endif diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237_cp1/i2c_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237_cp1/i2c_cap.h deleted file mode 100755 index 533c34e0e7a9771fff5a7b3cf58393980de4415d..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237_cp1/i2c_cap.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_I2C_UNIT_NUM 2 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237_cp1/i2s_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237_cp1/i2s_cap.h deleted file mode 100755 index 35a73d9c44ef6fce68f61ad4f8458b13f11a2ec9..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237_cp1/i2s_cap.h +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -//the max of channel number is 4 -#define SOC_I2S_CHANNEL_NUM 1 -#define SOC_I2S_ISR_NUM SOC_I2S_CHANNEL_NUM*4 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237_cp1/icu_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237_cp1/icu_cap.h deleted file mode 100755 index b97c4f04485d7d9f59f93e1b926858a37e07de05..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237_cp1/icu_cap.h +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237_cp1/jpeg_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237_cp1/jpeg_cap.h deleted file mode 100755 index 43ddac0c4f32d0cfeaa5ecd9b1cff35396d318f8..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237_cp1/jpeg_cap.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_JPEG_UNIT_NUM 1 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237_cp1/mailbox_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237_cp1/mailbox_cap.h deleted file mode 100755 index 4a13d9952ea40912a08154413e74fc18e396d0d2..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237_cp1/mailbox_cap.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_MAILBOX_NUM 2 - -#ifdef __cplusplus -} -#endif - - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237_cp1/mapping.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237_cp1/mapping.h deleted file mode 100755 index b97c4f04485d7d9f59f93e1b926858a37e07de05..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237_cp1/mapping.h +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237_cp1/pwm_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237_cp1/pwm_cap.h deleted file mode 100755 index cdf4c0fbd3553b5c532f2bc3bd8f78a92e8712e5..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237_cp1/pwm_cap.h +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_PWM_UNIT_NUM 1 -#define SOC_PWM_CHAN_NUM_PER_UNIT 6 -#define SOC_PWM_CHAN_NUM_PER_GROUP 2 -#define SOC_PWM_GROUP_NUM 3 - -#ifdef __cplusplus -} -#endif diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237_cp1/reg_base.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237_cp1/reg_base.h deleted file mode 100755 index 7a229c58181eaa4bc2df45bd9f29d6e7a7aa3c6c..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237_cp1/reg_base.h +++ /dev/null @@ -1,60 +0,0 @@ -#ifndef __REG_BASE_H__ -#define __REG_BASE_H__ - -/*********************************************************************************************************************************** -* This file is generated from BK7256_ADDR Mapping_20211224_format_change_highlight_20220113_update.xlsm automatically -* Modify it manually is not recommended -* CHIP ID:BK7256,GENARATE TIME:2022-01-17 15:34:58 -************************************************************************************************************************************/ - -#define SOC_SYSTEM_REG_BASE (0x44010000) -#define SOC_AON_PMU_REG_BASE (0x44000000) -#define SOC_CPU_PLIC_REG_BASE (0xE4000000) -#define SOC_AON_WDT_REG_BASE (0x44000600) -#define SOC_AON_GPIO_REG_BASE (0x44000400) -#define SOC_AON_RTC_REG_BASE (0x44000200) -#define SOC_FLASH_REG_BASE (0x44030000) -#define SOC_MBOX0_REG_BASE (0xA0000000) -#define SOC_MBOX1_REG_BASE (0xA0008000) -#define SOC_GENER_DMA_REG_BASE (0x44020000) -#define SOC_FFT_REG_BASE (0x47000000) -#define SOC_SBC_REG_BASE (0x47010000) -#define SOC_UART0_REG_BASE (0x44820000) -#define SOC_UART1_REG_BASE (0x45830000) -#define SOC_UART2_REG_BASE (0x45840000) -#define SOC_SPI_REG_BASE (0x44860000) -#define SOC_WDT_REG_BASE (0x44800000) -#define SOC_SPI1_REG_BASE (0x458C0000) -#define SOC_I2C0_REG_BASE (0x44850000) -#define SOC_I2C1_REG_BASE (0x45890000) -#define SOC_TIMER0_REG_BASE (0x44810000) -#define SOC_TIMER1_REG_BASE (0x45800000) -#define SOC_PWM01_REG_BASE (0x44840000) -#define SOC_PWM23_REG_BASE (0x44840040) -#define SOC_PWM45_REG_BASE (0x44840080) -#define SOC_SADC_REG_BASE (0x44870000) -#define SOC_EFUSE_REG_BASE (0x44880000) -#define SOC_IRDA_REG_BASE (0x44890000) -#define SOC_I2S_REG_BASE (0x47810000) -#define SOC_TRNG_REG_BASE (0x448A0000) -#define SOC_XVR_REG_BASE (0x4A800000) -#define SOC_AUD_REG_BASE (0x47800000) -#define SOC_LA_REG_BASE (0x45070000) -#define SOC_JPEG_REG_BASE (0x48000000) -#define SOC_JPEG_DEC_REG_BASE (0x48040000) -#define SOC_EIP130_REG_BASE (0x4b000000) -#define SOC_EIP130OTP_REG_BASE (0x4b004000) -#define SOC_EIP130REGITER_REG_BASE (0x4b008000) -#define SOC_QSPI_REG_BASE (0x46040000) -#define SOC_LCD_DISP_REG_BASE (0x48060000) -#define SOC_SDIO_REG_BASE (0x448B0000) -#define SOC_USB_REG_BASE (0x46002000) -#define SOC_RC_REG_BASE (0x4980C000) -#define SOC_TRX_REG_BASE (0x4980C200) -#define SOC_POWTBL_REG_BASE (0x4980C400) -#define SOC_DPDTBL_REG_BASE (0x4980C800) -#define SOC_AGCMEM_REG_BASE (0x4980A000) -#define SOC_PEAKCWMEM_REG_BASE (0x4980D000) -#define SOC_DMA2D_REG_BASE (0x48020000) -#define SOC_PSRAM_REG_BASE (0x46080000) -#endif //__REG_BASE_H__ diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237_cp1/soc.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237_cp1/soc.h deleted file mode 100755 index 6eaa0b62d2dc371d44c010518c0321bf91e9e4c5..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237_cp1/soc.h +++ /dev/null @@ -1,117 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#include -#include "soc_cap.h" -#include "reg_base.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_VAULT_HOST_BASE (0x4B000000) -#define SOC_VAULT_OTP_BASE (0x4B004000) -#define SOC_VAULT_REG_BASE (0x4B008000) -#if 0 -#define SOC_EFUSE_REG_BASE (0x44880000) -#define SOC_SYSTEM_REG_BASE (0x44010000) -#define SOC_UART_REG_BASE (0x44820000) -#define SOC_TRNG_REG_BASE (0x448A0000) -#define SOC_WDT_REG_BASE (0x44800000) -#define SOC_TIMER_REG_BASE (0x44810000) -#define SOC_GPIO_REG_BASE (0x44000400) -#define SOC_DMA_REG_BASE (0x44020000) -#define SOC_ADC_REG_BASE (0x44870000) -#define SOC_SPI1_REG_BASE (0x44860000) -#define SOC_SPI2_REG_BASE (0x458C0000) -#define SOC_MAILBOX_REG_BASE (0xA0000000) -#define SOC_QSPI_REG_BASE (0x46040000) -#define SOC_QSPI_DATA_REG_BASE (0x68000000) -#endif -#define SOC_PWM_REG_BASE (0x44840000) -#define SOC_ICU_REG_BASE (0x44010000) -#define SOC_FLASH_REG_BASE (0x44030000) -#if 0 -#define SOC_AON_PMU_REG_BASE (0x44000000) -#define SOC_I2C0_REG_BASE (0x44850000) -#define SOC_I2C1_REG_BASE (0x45890000) -#define SOC_AUD_REG_BASE (0x47800000) -#endif -#define SOC_SDIO_REG_BASE (0x448B0000) - -#define REG_WRITE(_r, _v) ({\ - (*(volatile uint32_t *)(_r)) = (_v);\ - }) - -#define REG_READ(_r) ({\ - (*(volatile uint32_t *)(_r));\ - }) - -#define REG_GET_BIT(_r, _b) ({\ - (*(volatile uint32_t*)(_r) & (_b));\ - }) - -#define REG_SET_BIT(_r, _b) ({\ - (*(volatile uint32_t*)(_r) |= (_b));\ - }) - -#define REG_CLR_BIT(_r, _b) ({\ - (*(volatile uint32_t*)(_r) &= ~(_b));\ - }) - -#define REG_SET_BITS(_r, _b, _m) ({\ - (*(volatile uint32_t*)(_r) = (*(volatile uint32_t*)(_r) & ~(_m)) | ((_b) & (_m)));\ - }) - -#define REG_GET_FIELD(_r, _f) ({\ - ((REG_READ(_r) >> (_f##_S)) & (_f##_V));\ - }) - -#define REG_SET_FIELD(_r, _f, _v) ({\ - (REG_WRITE((_r),((REG_READ(_r) & ~((_f##_V) << (_f##_S)))|(((_v) & (_f##_V))<<(_f##_S)))));\ - }) - -#define REG_MCHAN_GET_FIELD(_ch, _r, _f) ({\ - ((REG_READ(_r) >> (_f##_MS(_ch))) & (_f##_V));\ - }) - -#define REG_MCHAN_SET_FIELD(_ch, _r, _f, _v) ({\ - (REG_WRITE((_r), ((REG_READ(_r) & ~((_f##_V) << (_f##_MS(_ch))))|(((_v) & (_f##_V))<<(_f##_MS(_ch))))));\ - }) - -#define VALUE_GET_FIELD(_r, _f) (((_r) >> (_f##_S)) & (_f)) - -#define VALUE_GET_FIELD2(_r, _f) (((_r) & (_f))>> (_f##_S)) - -#define VALUE_SET_FIELD(_r, _f, _v) ((_r)=(((_r) & ~((_f) << (_f##_S)))|((_v)<<(_f##_S)))) - -#define VALUE_SET_FIELD2(_r, _f, _v) ((_r)=(((_r) & ~(_f))|((_v)<<(_f##_S)))) - -#define FIELD_TO_VALUE(_f, _v) (((_v)&(_f))<<_f##_S) - -#define FIELD_TO_VALUE2(_f, _v) (((_v)<<_f##_S) & (_f)) - -#ifndef BIT -#define BIT(i) (1<<(i)) -#endif - -#ifndef BIT64 -#define BIT64(i) (1LL << (i)) -#endif - -#ifdef __cplusplus -} -#endif diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237_cp1/soc_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237_cp1/soc_cap.h deleted file mode 100755 index 7aad100961dc9e5005bc4b5e3e5f42a5cf2267a8..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237_cp1/soc_cap.h +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#include "adc_cap.h" -#include "aon_pmu_cap.h" -#include "dma_cap.h" -#include "efuse_cap.h" -#include "gpio_cap.h" -#include "i2c_cap.h" -#include "icu_cap.h" -#include "pwm_cap.h" -#include "spi_cap.h" -#include "sys_cap.h" -#include "timer_cap.h" -#include "trng_cap.h" -#include "uart_cap.h" -#include "wdt_cap.h" -#include "mailbox_cap.h" -#include "aon_rtc_cap.h" -#include "i2s_cap.h" -#include "aud_cap.h" diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237_cp1/spi_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237_cp1/spi_cap.h deleted file mode 100755 index a777b8bd546d2e356f120da044b73091bb936424..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237_cp1/spi_cap.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_SPI_UNIT_NUM 2 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237_cp1/sys_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237_cp1/sys_cap.h deleted file mode 100755 index 3d70982245ef48ab48a9f97010ed67a9218b57f3..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237_cp1/sys_cap.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_SYSTEM_GPIO_FUNC_GROUP 6 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237_cp1/timer_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237_cp1/timer_cap.h deleted file mode 100755 index 64b3cfad064449bcac62ff95230860370f63378f..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237_cp1/timer_cap.h +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_TIMER_UNIT_NUM 1 -#define SOC_TIMER_CHAN_NUM_PER_UNIT 6 -#define SOC_TIMER_GROUP_NUM 2 -#define SOC_TIMER_CHAN_NUM_PER_GROUP 3 -#define SOC_TIMER_INTERRUPT_NUM 2 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237_cp1/trng_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237_cp1/trng_cap.h deleted file mode 100755 index 46505120e4eab86c79b97d16558f6ef4cae0cf5f..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237_cp1/trng_cap.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_TRNG_UNIT_NUM 1 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237_cp1/uart_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237_cp1/uart_cap.h deleted file mode 100755 index 8f8b3db159f4e43c9fd686216524c6b3c5583bd1..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237_cp1/uart_cap.h +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_UART_UNIT_NUM 1 -#define SOC_UART_ID_NUM_PER_UNIT 3 - -#ifdef __cplusplus -} -#endif - - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237_cp1/vault_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237_cp1/vault_cap.h deleted file mode 100755 index ada03b2894920d7bde375f8c113e2300ec40553b..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237_cp1/vault_cap.h +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_VAULT_UNIT_NUM 1 - -#ifdef __cplusplus -} -#endif - - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237_cp1/wdt_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237_cp1/wdt_cap.h deleted file mode 100755 index 335278317c6ad9cd7872b4306c6fe82f28e61591..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7237_cp1/wdt_cap.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_WDT_UNIT_NUM 1 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7251/adc_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7251/adc_cap.h deleted file mode 100755 index ae3a4a250f1d48e5eaf1abb3763a5e6737d6c060..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7251/adc_cap.h +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#define SOC_ADC_CHAN_MIN 1 -#define SOC_ADC_CHAN_MAX 7 -#define SOC_ADC_SAMPLE_CNT_MAX 32 diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7251/dma_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7251/dma_cap.h deleted file mode 100755 index cc6ee40129edda7cf1cf42b64ae8fed1e73e55e0..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7251/dma_cap.h +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_DMA_UNIT_NUM 1 -#define SOC_DMA_CHAN_NUM_PER_UNIT 6 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7251/efuse_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7251/efuse_cap.h deleted file mode 100755 index 6ec28cd053b59a2ad9e9c8ebc87c0c1f06487934..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7251/efuse_cap.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_EFUSE_UNIT_NUM 1 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7251/flash_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7251/flash_cap.h deleted file mode 100644 index 0968373d28b9fd5a10402eaf963cb2467eb16aaf..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7251/flash_cap.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_FLASH_UNIT_NUM 1 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7251/gpio_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7251/gpio_cap.h deleted file mode 100755 index 81c8ee19692a4fd7a99952ae6164b37aec08f774..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7251/gpio_cap.h +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_GPIO_0_31_NUM 32 -#define SOC_GPIO_32_39_NUM 8 -#define SOC_GPIO_NUM 40 -#define GPIO_PERI_FUNC_NUM 4 - -#ifdef __cplusplus -} -#endif diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7251/i2c_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7251/i2c_cap.h deleted file mode 100644 index 533c34e0e7a9771fff5a7b3cf58393980de4415d..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7251/i2c_cap.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_I2C_UNIT_NUM 2 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7251/icu_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7251/icu_cap.h deleted file mode 100755 index b97c4f04485d7d9f59f93e1b926858a37e07de05..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7251/icu_cap.h +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7251/jpeg_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7251/jpeg_cap.h deleted file mode 100644 index 43ddac0c4f32d0cfeaa5ecd9b1cff35396d318f8..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7251/jpeg_cap.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_JPEG_UNIT_NUM 1 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7251/mapping.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7251/mapping.h deleted file mode 100755 index b97c4f04485d7d9f59f93e1b926858a37e07de05..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7251/mapping.h +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7251/pwm_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7251/pwm_cap.h deleted file mode 100755 index 39254d52df2ac145b43a88117a009b1c4556c5ea..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7251/pwm_cap.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_PWM_UNIT_NUM 1 -#define SOC_PWM_CHAN_NUM_PER_UNIT 6 - -#ifdef __cplusplus -} -#endif diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7251/qspi_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7251/qspi_cap.h deleted file mode 100755 index 2c6b75d3ae9b33b17b62e81f92fc026b42c5e270..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7251/qspi_cap.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_QSPI_UNIT_NUM 1 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7251/soc.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7251/soc.h deleted file mode 100644 index 8ba784858e4a358880112914047c64d8b1bceee0..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7251/soc.h +++ /dev/null @@ -1,104 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#include -#include "soc_cap.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_SYS_CTRL_REG_BASE (0x00800000) -#define SOC_EFUSE_REG_BASE (SOC_SYS_CTRL_REG_BASE + 0x1D * 4) -#define SOC_ICU_REG_BASE (0x00802000) -#define SOC_UART_REG_BASE (0x00802100) -#define SOC_I2C0_REG_BASE (0x00802300) -#define SOC_TRNG_REG_BASE (0x00802480) -#define SOC_I2C1_REG_BASE (0x00802600) -#define SOC_SPI_REG_BASE (0x00802700) -#define SOC_GPIO_REG_BASE (0x00802800) -#define SOC_WDT_REG_BASE (0x00802900) -#define SOC_TIMER_REG_BASE (0x00802A00) -#define SOC_PWM_REG_BASE (SOC_TIMER_REG_BASE + 0x20 * 4) /**< 0x802A80 */ -#define SOC_ADC_REG_BASE (0x00802C00) -#define SOC_FLASH_REG_BASE (0x00803000) -#define SOC_DMA_REG_BASE (0x00809000) -#define SOC_JPEG_REG_BASE (0x0080A000) -#define SOC_QSPI_REG_BASE (0x0080D000) - -#define REG_WRITE(_r, _v) ({\ - (*(volatile uint32_t *)(_r)) = (_v);\ - }) - -#define REG_READ(_r) ({\ - (*(volatile uint32_t *)(_r));\ - }) - -#define REG_GET_BIT(_r, _b) ({\ - (*(volatile uint32_t*)(_r) & (_b));\ - }) - -#define REG_SET_BIT(_r, _b) ({\ - (*(volatile uint32_t*)(_r) |= (_b));\ - }) - -#define REG_CLR_BIT(_r, _b) ({\ - (*(volatile uint32_t*)(_r) &= ~(_b));\ - }) - -#define REG_SET_BITS(_r, _b, _m) ({\ - (*(volatile uint32_t*)(_r) = (*(volatile uint32_t*)(_r) & ~(_m)) | ((_b) & (_m)));\ - }) - -#define REG_GET_FIELD(_r, _f) ({\ - ((REG_READ(_r) >> (_f##_S)) & (_f##_V));\ - }) - -#define REG_SET_FIELD(_r, _f, _v) ({\ - (REG_WRITE((_r),((REG_READ(_r) & ~((_f##_V) << (_f##_S)))|(((_v) & (_f##_V))<<(_f##_S)))));\ - }) - -#define REG_MCHAN_GET_FIELD(_ch, _r, _f) ({\ - ((REG_READ(_r) >> (_f##_MS(_ch))) & (_f##_V));\ - }) - -#define REG_MCHAN_SET_FIELD(_ch, _r, _f, _v) ({\ - (REG_WRITE((_r), ((REG_READ(_r) & ~((_f##_V) << (_f##_MS(_ch))))|(((_v) & (_f##_V))<<(_f##_MS(_ch))))));\ - }) - -#define VALUE_GET_FIELD(_r, _f) (((_r) >> (_f##_S)) & (_f)) - -#define VALUE_GET_FIELD2(_r, _f) (((_r) & (_f))>> (_f##_S)) - -#define VALUE_SET_FIELD(_r, _f, _v) ((_r)=(((_r) & ~((_f) << (_f##_S)))|((_v)<<(_f##_S)))) - -#define VALUE_SET_FIELD2(_r, _f, _v) ((_r)=(((_r) & ~(_f))|((_v)<<(_f##_S)))) - -#define FIELD_TO_VALUE(_f, _v) (((_v)&(_f))<<_f##_S) - -#define FIELD_TO_VALUE2(_f, _v) (((_v)<<_f##_S) & (_f)) - -#ifndef BIT -#define BIT(i) ((1L)<<(i)) -#endif - -#ifndef BIT64 -#define BIT64(i) (1LL << (i)) -#endif - -#ifdef __cplusplus -} -#endif diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7251/soc_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7251/soc_cap.h deleted file mode 100644 index b9bcce87672ccc31b4e754c25be81b7d8c2a9106..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7251/soc_cap.h +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#include "adc_cap.h" -#include "aon_pmu_cap.h" -#include "dma_cap.h" -#include "efuse_cap.h" -#include "gpio_cap.h" -#include "i2c_cap.h" -#include "icu_cap.h" -#include "pwm_cap.h" -#include "spi_cap.h" -#include "sys_cap.h" -#include "timer_cap.h" -#include "trng_cap.h" -#include "uart_cap.h" -#include "wdt_cap.h" diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7251/spi_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7251/spi_cap.h deleted file mode 100755 index 228993416709eae8525de88685f24a58dc684840..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7251/spi_cap.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_SPI_UNIT_NUM 1 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7251/sys_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7251/sys_cap.h deleted file mode 100644 index 3d70982245ef48ab48a9f97010ed67a9218b57f3..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7251/sys_cap.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_SYSTEM_GPIO_FUNC_GROUP 6 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7251/timer_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7251/timer_cap.h deleted file mode 100755 index 0792e7eb3f32a77e634338b61eaea534b1f1d248..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7251/timer_cap.h +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_TIMER_UNIT_NUM 1 -#define SOC_TIMER_CHAN_NUM_PER_UNIT 6 -#define SOC_TIMER_GROUP_NUM 2 -#define SOC_TIMER_CHAN_NUM_PER_GROUP 3 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7251/trng_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7251/trng_cap.h deleted file mode 100755 index 46505120e4eab86c79b97d16558f6ef4cae0cf5f..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7251/trng_cap.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_TRNG_UNIT_NUM 1 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7251/uart_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7251/uart_cap.h deleted file mode 100755 index 47ecb5c1ce6aa5a1a5281ee411f71d16d1c9d97c..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7251/uart_cap.h +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_UART_UNIT_NUM 1 -#define SOC_UART_ID_NUM_PER_UNIT 2 - -#ifdef __cplusplus -} -#endif - - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7251/wdt_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7251/wdt_cap.h deleted file mode 100755 index 335278317c6ad9cd7872b4306c6fe82f28e61591..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7251/wdt_cap.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_WDT_UNIT_NUM 1 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256/adc_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256/adc_cap.h deleted file mode 100755 index eac19c4001bb61a16dab85b3a174d44d514b8c6b..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256/adc_cap.h +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -/* TODO - Frank check it - * 1. Whether ADC channel is begin from 1 - * 2. Whether analog channel is begin from 7 - **/ - -#define SOC_ADC_SAMPLE_CNT_MAX 32 - -#define SOC_ADC_FIFO_DATA_SUPPORT -#define SOC_ADC_DC_OFFSET_SUPPORT -#define SOC_ADC_GAIN_SUPPORT - - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256/aon_pmu_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256/aon_pmu_cap.h deleted file mode 100644 index 6eed470f4040d199fee045bbf852b37379e17a01..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256/aon_pmu_cap.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define AON_PMU_GPIO_FUNC_GROUP 1 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256/aon_rtc_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256/aon_rtc_cap.h deleted file mode 100644 index 3c3443fd8fe85d62f6f3fd5dd96b0b3c2bf03d02..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256/aon_rtc_cap.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_AON_RTC_UNIT_NUM 1 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256/aud_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256/aud_cap.h deleted file mode 100644 index 30647aca920dbb37add20d3b3e5687f94231a1c7..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256/aud_cap.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_AUD_ISR_NUM 4 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256/dma_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256/dma_cap.h deleted file mode 100755 index 49926b51d769b69dd07e1f571e90e0207ede74da..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256/dma_cap.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_DMA_UNIT_NUM 1 -#define SOC_DMA_CHAN_NUM_PER_UNIT 12 - -#ifdef __cplusplus -} -#endif diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256/efuse_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256/efuse_cap.h deleted file mode 100755 index 6ec28cd053b59a2ad9e9c8ebc87c0c1f06487934..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256/efuse_cap.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_EFUSE_UNIT_NUM 1 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256/fft_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256/fft_cap.h deleted file mode 100755 index 76a1966295bcd4b4dfe0fc81d4d2086faf404413..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256/fft_cap.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_FFT_ISR_NUM 1 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256/flash_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256/flash_cap.h deleted file mode 100644 index 0968373d28b9fd5a10402eaf963cb2467eb16aaf..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256/flash_cap.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_FLASH_UNIT_NUM 1 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256/gpio_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256/gpio_cap.h deleted file mode 100755 index 05dd5527b01562d98e9a72afb4ed069258fc69fb..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256/gpio_cap.h +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_GPIO_0_31_NUM 32 -#define SOC_GPIO_32_47_NUM 16 -#define SOC_GPIO_NUM 48 -#define SOC_GPIO_SYSTEM_GROUP_NUM 6 -#define GPIO_PERI_FUNC_NUM 6 - -#ifdef __cplusplus -} -#endif diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256/i2c_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256/i2c_cap.h deleted file mode 100644 index 533c34e0e7a9771fff5a7b3cf58393980de4415d..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256/i2c_cap.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_I2C_UNIT_NUM 2 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256/i2s_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256/i2s_cap.h deleted file mode 100755 index 761f9f97df7130e654f73490e5402bc85cb0cd3a..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256/i2s_cap.h +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -//the max of channel number is 4 -#define SOC_I2S_CHANNEL_NUM 1 -#define SOC_I2S_ISR_NUM SOC_I2S_CHANNEL_NUM*4 -#define SOC_I2S_APLL_RATE 98304000 //98.304M - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256/icu_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256/icu_cap.h deleted file mode 100755 index b97c4f04485d7d9f59f93e1b926858a37e07de05..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256/icu_cap.h +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256/jpeg_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256/jpeg_cap.h deleted file mode 100755 index 43ddac0c4f32d0cfeaa5ecd9b1cff35396d318f8..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256/jpeg_cap.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_JPEG_UNIT_NUM 1 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256/mailbox_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256/mailbox_cap.h deleted file mode 100755 index 4a13d9952ea40912a08154413e74fc18e396d0d2..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256/mailbox_cap.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_MAILBOX_NUM 2 - -#ifdef __cplusplus -} -#endif - - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256/mapping.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256/mapping.h deleted file mode 100755 index 5f6cca47e5d4825edbfc1ba7fab8a6316cb873d0..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256/mapping.h +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#define DISPLAY_FRAME_SIZE (800 * 600 * 2) -#define DISPLAY_720P_FRAME_SIZE (1280 * 720 * 2) -#define JPEG_DEC_ALINE_SIZE (1024 * 64) - -#define JPEG_DEC_FRAME_SIZE ((DISPLAY_FRAME_SIZE / JPEG_DEC_ALINE_SIZE + 1) * JPEG_DEC_ALINE_SIZE) -#define JPEG_DEC_720P_FRAME_SIZE ((DISPLAY_720P_FRAME_SIZE / JPEG_DEC_ALINE_SIZE + 1) * JPEG_DEC_ALINE_SIZE) -#define JPEG_ENC_FRAME_SIZE (1024 * 250) -#define JPEG_ENC_FRAME_COUNT (4) -#define DISPLAY_FRAME_COUNT (4) -#define DISPLAY_720P_FRAME_COUNT (3) - -#define AUDIO_FRAME_SIZE (1024 * 10) - -#define PSRAM_NONCACHEABLE (0x60000000UL) -#define PSRAM_CACHEABLE (0x64000000UL) - -#define JPEG_SRAM_FRAME_COUNT (2) -#define JPEG_SRAM_ADDRESS (0x30000000) -#define JPEG_SRAM_BUFFER_SIZE (1024 * 60) - - -typedef struct -{ - uint8_t display[DISPLAY_FRAME_COUNT][JPEG_DEC_FRAME_SIZE]; - uint8_t jpeg_enc[JPEG_ENC_FRAME_COUNT][JPEG_ENC_FRAME_SIZE]; - uint8_t aud_adc[AUDIO_FRAME_SIZE]; - uint8_t aud_dac[AUDIO_FRAME_SIZE]; -} psram_map_t; - -typedef struct -{ - uint8_t display[DISPLAY_720P_FRAME_COUNT][JPEG_DEC_720P_FRAME_SIZE]; - uint8_t jpeg_enc[JPEG_ENC_FRAME_COUNT][JPEG_ENC_FRAME_SIZE]; - uint8_t aud_adc[AUDIO_FRAME_SIZE]; - uint8_t aud_dac[AUDIO_FRAME_SIZE]; -} psram_720p_map_t; - -#define psram_map ((psram_map_t*)PSRAM_NONCACHEABLE) -#define psram_720p_map ((psram_720p_map_t*)PSRAM_NONCACHEABLE) diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256/pwm_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256/pwm_cap.h deleted file mode 100755 index cdf4c0fbd3553b5c532f2bc3bd8f78a92e8712e5..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256/pwm_cap.h +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_PWM_UNIT_NUM 1 -#define SOC_PWM_CHAN_NUM_PER_UNIT 6 -#define SOC_PWM_CHAN_NUM_PER_GROUP 2 -#define SOC_PWM_GROUP_NUM 3 - -#ifdef __cplusplus -} -#endif diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256/reg_base.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256/reg_base.h deleted file mode 100644 index dda351fd4be3a8022d3b04a44a3d4b6fe788b239..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256/reg_base.h +++ /dev/null @@ -1,61 +0,0 @@ -#ifndef __REG_BASE_H__ -#define __REG_BASE_H__ - -/*********************************************************************************************************************************** -* This file is generated from BK7256_ADDR Mapping_20211224_format_change_highlight_20220113_update.xlsm automatically -* Modify it manually is not recommended -* CHIP ID:BK7256,GENARATE TIME:2022-01-17 15:34:58 -************************************************************************************************************************************/ - -#define SOC_SYSTEM_REG_BASE (0x44010000) -#define SOC_AON_PMU_REG_BASE (0x44000000) -#define SOC_CPU_PLIC_REG_BASE (0xE4000000) -#define SOC_AON_WDT_REG_BASE (0x44000600) -#define SOC_AON_GPIO_REG_BASE (0x44000400) -#define SOC_AON_RTC_REG_BASE (0x44000200) -#define SOC_FLASH_REG_BASE (0x44030000) -#define SOC_MBOX0_REG_BASE (0xA0000000) -#define SOC_MBOX1_REG_BASE (0xA0008000) -#define SOC_GENER_DMA_REG_BASE (0x44020000) -#define SOC_FFT_REG_BASE (0x47000000) -#define SOC_SBC_REG_BASE (0x47010000) -#define SOC_UART0_REG_BASE (0x44820000) -#define SOC_UART1_REG_BASE (0x45830000) -#define SOC_UART2_REG_BASE (0x45840000) -#define SOC_SPI_REG_BASE (0x44860000) -#define SOC_WDT_REG_BASE (0x44800000) -#define SOC_SPI1_REG_BASE (0x458C0000) -#define SOC_I2C0_REG_BASE (0x44850000) -#define SOC_I2C1_REG_BASE (0x45890000) -#define SOC_TIMER0_REG_BASE (0x44810000) -#define SOC_TIMER1_REG_BASE (0x45800000) -#define SOC_PWM01_REG_BASE (0x44840000) -#define SOC_PWM23_REG_BASE (0x44840040) -#define SOC_PWM45_REG_BASE (0x44840080) -#define SOC_SADC_REG_BASE (0x44870000) -#define SOC_EFUSE_REG_BASE (0x44880000) -#define SOC_IRDA_REG_BASE (0x44890000) -#define SOC_I2S_REG_BASE (0x47810000) -#define SOC_TRNG_REG_BASE (0x448A0000) -#define SOC_XVR_REG_BASE (0x4A800000) -#define SOC_AUD_REG_BASE (0x47800000) -#define SOC_LA_REG_BASE (0x45070000) -#define SOC_JPEG_REG_BASE (0x48000000) -#define SOC_JPEG_DEC_REG_BASE (0x48040000) -#define SOC_EIP130_REG_BASE (0x4b000000) -#define SOC_EIP130OTP_REG_BASE (0x4b004000) -#define SOC_EIP130REGITER_REG_BASE (0x4b008000) -#define SOC_QSPI_REG_BASE (0x46040000) -#define SOC_LCD_DISP_REG_BASE (0x48060000) -#define SOC_SDIO_REG_BASE (0x448B0000) -#define SOC_USB_REG_BASE (0x46002000) -#define SOC_RC_REG_BASE (0x4980C000) -#define SOC_TRX_REG_BASE (0x4980C200) -#define SOC_POWTBL_REG_BASE (0x4980C400) -#define SOC_DPDTBL_REG_BASE (0x4980C800) -#define SOC_AGCMEM_REG_BASE (0x4980A000) -#define SOC_PEAKCWMEM_REG_BASE (0x4980D000) -#define SOC_PSRAM_REG_BASE (0x46080000) -#define SOC_DMA2D_REG_BASE (0x48020000) - -#endif //__REG_BASE_H__ diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256/soc.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256/soc.h deleted file mode 100755 index 430985d0eb90db0c289c507be7a7466f71afc0ce..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256/soc.h +++ /dev/null @@ -1,118 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#include -#include "soc_cap.h" -#include "reg_base.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_VAULT_HOST_BASE (0x4B000000) -#define SOC_VAULT_OTP_BASE (0x4B004000) -#define SOC_VAULT_REG_BASE (0x4B008000) -#if 0 -#define SOC_EFUSE_REG_BASE (0x44880000) -#define SOC_SYSTEM_REG_BASE (0x44010000) -#define SOC_UART_REG_BASE (0x44820000) -#define SOC_TRNG_REG_BASE (0x448A0000) -#define SOC_WDT_REG_BASE (0x44800000) -#define SOC_TIMER_REG_BASE (0x44810000) -#define SOC_GPIO_REG_BASE (0x44000400) -#define SOC_DMA_REG_BASE (0x44020000) -#define SOC_ADC_REG_BASE (0x44870000) -#define SOC_SPI1_REG_BASE (0x44860000) -#define SOC_SPI2_REG_BASE (0x458C0000) -#define SOC_MAILBOX_REG_BASE (0xA0000000) -#define SOC_QSPI_REG_BASE (0x46040000) -#endif -#define SOC_QSPI_DATA_REG_BASE (0x68000000) -#define SOC_PWM_REG_BASE (0x44840000) -#define SOC_ICU_REG_BASE (0x44010000) -#define SOC_FLASH_REG_BASE (0x44030000) -#if 0 -#define SOC_AON_PMU_REG_BASE (0x44000000) -#define SOC_I2C0_REG_BASE (0x44850000) -#define SOC_I2C1_REG_BASE (0x45890000) -#define SOC_AUD_REG_BASE (0x47800000) -#endif -#define SOC_SDIO_REG_BASE (0x448B0000) -#define SOC_SDIO_HOST_REG_BASE (SOC_SDIO_REG_BASE) - -#define REG_WRITE(_r, _v) ({\ - (*(volatile uint32_t *)(_r)) = (_v);\ - }) - -#define REG_READ(_r) ({\ - (*(volatile uint32_t *)(_r));\ - }) - -#define REG_GET_BIT(_r, _b) ({\ - (*(volatile uint32_t*)(_r) & (_b));\ - }) - -#define REG_SET_BIT(_r, _b) ({\ - (*(volatile uint32_t*)(_r) |= (_b));\ - }) - -#define REG_CLR_BIT(_r, _b) ({\ - (*(volatile uint32_t*)(_r) &= ~(_b));\ - }) - -#define REG_SET_BITS(_r, _b, _m) ({\ - (*(volatile uint32_t*)(_r) = (*(volatile uint32_t*)(_r) & ~(_m)) | ((_b) & (_m)));\ - }) - -#define REG_GET_FIELD(_r, _f) ({\ - ((REG_READ(_r) >> (_f##_S)) & (_f##_V));\ - }) - -#define REG_SET_FIELD(_r, _f, _v) ({\ - (REG_WRITE((_r),((REG_READ(_r) & ~((_f##_V) << (_f##_S)))|(((_v) & (_f##_V))<<(_f##_S)))));\ - }) - -#define REG_MCHAN_GET_FIELD(_ch, _r, _f) ({\ - ((REG_READ(_r) >> (_f##_MS(_ch))) & (_f##_V));\ - }) - -#define REG_MCHAN_SET_FIELD(_ch, _r, _f, _v) ({\ - (REG_WRITE((_r), ((REG_READ(_r) & ~((_f##_V) << (_f##_MS(_ch))))|(((_v) & (_f##_V))<<(_f##_MS(_ch))))));\ - }) - -#define VALUE_GET_FIELD(_r, _f) (((_r) >> (_f##_S)) & (_f)) - -#define VALUE_GET_FIELD2(_r, _f) (((_r) & (_f))>> (_f##_S)) - -#define VALUE_SET_FIELD(_r, _f, _v) ((_r)=(((_r) & ~((_f) << (_f##_S)))|((_v)<<(_f##_S)))) - -#define VALUE_SET_FIELD2(_r, _f, _v) ((_r)=(((_r) & ~(_f))|((_v)<<(_f##_S)))) - -#define FIELD_TO_VALUE(_f, _v) (((_v)&(_f))<<_f##_S) - -#define FIELD_TO_VALUE2(_f, _v) (((_v)<<_f##_S) & (_f)) - -#ifndef BIT -#define BIT(i) (1<<(i)) -#endif - -#ifndef BIT64 -#define BIT64(i) (1LL << (i)) -#endif - -#ifdef __cplusplus -} -#endif diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256/soc_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256/soc_cap.h deleted file mode 100644 index 7aad100961dc9e5005bc4b5e3e5f42a5cf2267a8..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256/soc_cap.h +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#include "adc_cap.h" -#include "aon_pmu_cap.h" -#include "dma_cap.h" -#include "efuse_cap.h" -#include "gpio_cap.h" -#include "i2c_cap.h" -#include "icu_cap.h" -#include "pwm_cap.h" -#include "spi_cap.h" -#include "sys_cap.h" -#include "timer_cap.h" -#include "trng_cap.h" -#include "uart_cap.h" -#include "wdt_cap.h" -#include "mailbox_cap.h" -#include "aon_rtc_cap.h" -#include "i2s_cap.h" -#include "aud_cap.h" diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256/spi_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256/spi_cap.h deleted file mode 100644 index a777b8bd546d2e356f120da044b73091bb936424..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256/spi_cap.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_SPI_UNIT_NUM 2 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256/sys_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256/sys_cap.h deleted file mode 100644 index 3d70982245ef48ab48a9f97010ed67a9218b57f3..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256/sys_cap.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_SYSTEM_GPIO_FUNC_GROUP 6 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256/system_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256/system_cap.h deleted file mode 100755 index 3d70982245ef48ab48a9f97010ed67a9218b57f3..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256/system_cap.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_SYSTEM_GPIO_FUNC_GROUP 6 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256/timer_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256/timer_cap.h deleted file mode 100755 index 64b3cfad064449bcac62ff95230860370f63378f..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256/timer_cap.h +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_TIMER_UNIT_NUM 1 -#define SOC_TIMER_CHAN_NUM_PER_UNIT 6 -#define SOC_TIMER_GROUP_NUM 2 -#define SOC_TIMER_CHAN_NUM_PER_GROUP 3 -#define SOC_TIMER_INTERRUPT_NUM 2 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256/trng_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256/trng_cap.h deleted file mode 100755 index 46505120e4eab86c79b97d16558f6ef4cae0cf5f..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256/trng_cap.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_TRNG_UNIT_NUM 1 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256/uart_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256/uart_cap.h deleted file mode 100755 index 8f8b3db159f4e43c9fd686216524c6b3c5583bd1..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256/uart_cap.h +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_UART_UNIT_NUM 1 -#define SOC_UART_ID_NUM_PER_UNIT 3 - -#ifdef __cplusplus -} -#endif - - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256/vault_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256/vault_cap.h deleted file mode 100755 index ada03b2894920d7bde375f8c113e2300ec40553b..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256/vault_cap.h +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_VAULT_UNIT_NUM 1 - -#ifdef __cplusplus -} -#endif - - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256/wdt_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256/wdt_cap.h deleted file mode 100755 index 335278317c6ad9cd7872b4306c6fe82f28e61591..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256/wdt_cap.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_WDT_UNIT_NUM 1 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256_cp1/adc_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256_cp1/adc_cap.h deleted file mode 100644 index eac19c4001bb61a16dab85b3a174d44d514b8c6b..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256_cp1/adc_cap.h +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -/* TODO - Frank check it - * 1. Whether ADC channel is begin from 1 - * 2. Whether analog channel is begin from 7 - **/ - -#define SOC_ADC_SAMPLE_CNT_MAX 32 - -#define SOC_ADC_FIFO_DATA_SUPPORT -#define SOC_ADC_DC_OFFSET_SUPPORT -#define SOC_ADC_GAIN_SUPPORT - - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256_cp1/aon_pmu_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256_cp1/aon_pmu_cap.h deleted file mode 100644 index 6eed470f4040d199fee045bbf852b37379e17a01..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256_cp1/aon_pmu_cap.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define AON_PMU_GPIO_FUNC_GROUP 1 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256_cp1/aon_rtc_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256_cp1/aon_rtc_cap.h deleted file mode 100644 index 3c3443fd8fe85d62f6f3fd5dd96b0b3c2bf03d02..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256_cp1/aon_rtc_cap.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_AON_RTC_UNIT_NUM 1 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256_cp1/aud_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256_cp1/aud_cap.h deleted file mode 100755 index 30647aca920dbb37add20d3b3e5687f94231a1c7..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256_cp1/aud_cap.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_AUD_ISR_NUM 4 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256_cp1/dma_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256_cp1/dma_cap.h deleted file mode 100644 index 49926b51d769b69dd07e1f571e90e0207ede74da..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256_cp1/dma_cap.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_DMA_UNIT_NUM 1 -#define SOC_DMA_CHAN_NUM_PER_UNIT 12 - -#ifdef __cplusplus -} -#endif diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256_cp1/efuse_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256_cp1/efuse_cap.h deleted file mode 100644 index 6ec28cd053b59a2ad9e9c8ebc87c0c1f06487934..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256_cp1/efuse_cap.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_EFUSE_UNIT_NUM 1 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256_cp1/fft_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256_cp1/fft_cap.h deleted file mode 100755 index 76a1966295bcd4b4dfe0fc81d4d2086faf404413..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256_cp1/fft_cap.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_FFT_ISR_NUM 1 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256_cp1/gpio_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256_cp1/gpio_cap.h deleted file mode 100644 index 05dd5527b01562d98e9a72afb4ed069258fc69fb..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256_cp1/gpio_cap.h +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_GPIO_0_31_NUM 32 -#define SOC_GPIO_32_47_NUM 16 -#define SOC_GPIO_NUM 48 -#define SOC_GPIO_SYSTEM_GROUP_NUM 6 -#define GPIO_PERI_FUNC_NUM 6 - -#ifdef __cplusplus -} -#endif diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256_cp1/i2c_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256_cp1/i2c_cap.h deleted file mode 100644 index 533c34e0e7a9771fff5a7b3cf58393980de4415d..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256_cp1/i2c_cap.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_I2C_UNIT_NUM 2 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256_cp1/i2s_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256_cp1/i2s_cap.h deleted file mode 100755 index 35a73d9c44ef6fce68f61ad4f8458b13f11a2ec9..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256_cp1/i2s_cap.h +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -//the max of channel number is 4 -#define SOC_I2S_CHANNEL_NUM 1 -#define SOC_I2S_ISR_NUM SOC_I2S_CHANNEL_NUM*4 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256_cp1/icu_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256_cp1/icu_cap.h deleted file mode 100644 index b97c4f04485d7d9f59f93e1b926858a37e07de05..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256_cp1/icu_cap.h +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256_cp1/jpeg_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256_cp1/jpeg_cap.h deleted file mode 100755 index 43ddac0c4f32d0cfeaa5ecd9b1cff35396d318f8..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256_cp1/jpeg_cap.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_JPEG_UNIT_NUM 1 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256_cp1/mailbox_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256_cp1/mailbox_cap.h deleted file mode 100644 index 4a13d9952ea40912a08154413e74fc18e396d0d2..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256_cp1/mailbox_cap.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_MAILBOX_NUM 2 - -#ifdef __cplusplus -} -#endif - - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256_cp1/mapping.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256_cp1/mapping.h deleted file mode 100755 index bc8e432c073d768727f0527bd48b5130bfeb5a4f..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256_cp1/mapping.h +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#define DISPLAY_FRAME_SIZE (800 * 600 * 2) -#define DISPLAY_720P_FRAME_SIZE (1280 * 720 * 2) -#define JPEG_DEC_ALINE_SIZE (1024 * 64) - -#define JPEG_DEC_FRAME_SIZE ((DISPLAY_FRAME_SIZE / JPEG_DEC_ALINE_SIZE + 1) * JPEG_DEC_ALINE_SIZE) -#define JPEG_DEC_720P_FRAME_SIZE ((DISPLAY_720P_FRAME_SIZE / JPEG_DEC_ALINE_SIZE + 1) * JPEG_DEC_ALINE_SIZE) -#define JPEG_ENC_FRAME_SIZE (1024 * 250) -#define JPEG_ENC_FRAME_COUNT (4) -#define DISPLAY_FRAME_COUNT (4) -#define DISPLAY_720P_FRAME_COUNT (3) - -#define AUDIO_FRAME_SIZE (1024 * 10) - -#define PSRAM_NONCACHEABLE (0x60000000UL) -#define PSRAM_CACHEABLE (0x64000000UL) - -#define JPEG_SRAM_FRAME_COUNT (2) -#define JPEG_SRAM_ADDRESS (0x30000000) -#define JPEG_SRAM_BUFFER_SIZE (1024 * 60) - -typedef struct -{ - uint8_t display[DISPLAY_FRAME_COUNT][JPEG_DEC_FRAME_SIZE]; - uint8_t jpeg_enc[JPEG_ENC_FRAME_COUNT][JPEG_ENC_FRAME_SIZE]; - uint8_t aud_adc[AUDIO_FRAME_SIZE]; - uint8_t aud_dac[AUDIO_FRAME_SIZE]; -} psram_map_t; - -typedef struct -{ - uint8_t display[DISPLAY_720P_FRAME_COUNT][JPEG_DEC_720P_FRAME_SIZE]; - uint8_t jpeg_enc[JPEG_ENC_FRAME_COUNT][JPEG_ENC_FRAME_SIZE]; - uint8_t aud_adc[AUDIO_FRAME_SIZE]; - uint8_t aud_dac[AUDIO_FRAME_SIZE]; -} psram_720p_map_t; - -#define psram_map ((psram_map_t*)PSRAM_NONCACHEABLE) -#define psram_720p_map ((psram_720p_map_t*)PSRAM_NONCACHEABLE) - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256_cp1/pwm_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256_cp1/pwm_cap.h deleted file mode 100644 index cdf4c0fbd3553b5c532f2bc3bd8f78a92e8712e5..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256_cp1/pwm_cap.h +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_PWM_UNIT_NUM 1 -#define SOC_PWM_CHAN_NUM_PER_UNIT 6 -#define SOC_PWM_CHAN_NUM_PER_GROUP 2 -#define SOC_PWM_GROUP_NUM 3 - -#ifdef __cplusplus -} -#endif diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256_cp1/reg_base.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256_cp1/reg_base.h deleted file mode 100644 index 7a229c58181eaa4bc2df45bd9f29d6e7a7aa3c6c..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256_cp1/reg_base.h +++ /dev/null @@ -1,60 +0,0 @@ -#ifndef __REG_BASE_H__ -#define __REG_BASE_H__ - -/*********************************************************************************************************************************** -* This file is generated from BK7256_ADDR Mapping_20211224_format_change_highlight_20220113_update.xlsm automatically -* Modify it manually is not recommended -* CHIP ID:BK7256,GENARATE TIME:2022-01-17 15:34:58 -************************************************************************************************************************************/ - -#define SOC_SYSTEM_REG_BASE (0x44010000) -#define SOC_AON_PMU_REG_BASE (0x44000000) -#define SOC_CPU_PLIC_REG_BASE (0xE4000000) -#define SOC_AON_WDT_REG_BASE (0x44000600) -#define SOC_AON_GPIO_REG_BASE (0x44000400) -#define SOC_AON_RTC_REG_BASE (0x44000200) -#define SOC_FLASH_REG_BASE (0x44030000) -#define SOC_MBOX0_REG_BASE (0xA0000000) -#define SOC_MBOX1_REG_BASE (0xA0008000) -#define SOC_GENER_DMA_REG_BASE (0x44020000) -#define SOC_FFT_REG_BASE (0x47000000) -#define SOC_SBC_REG_BASE (0x47010000) -#define SOC_UART0_REG_BASE (0x44820000) -#define SOC_UART1_REG_BASE (0x45830000) -#define SOC_UART2_REG_BASE (0x45840000) -#define SOC_SPI_REG_BASE (0x44860000) -#define SOC_WDT_REG_BASE (0x44800000) -#define SOC_SPI1_REG_BASE (0x458C0000) -#define SOC_I2C0_REG_BASE (0x44850000) -#define SOC_I2C1_REG_BASE (0x45890000) -#define SOC_TIMER0_REG_BASE (0x44810000) -#define SOC_TIMER1_REG_BASE (0x45800000) -#define SOC_PWM01_REG_BASE (0x44840000) -#define SOC_PWM23_REG_BASE (0x44840040) -#define SOC_PWM45_REG_BASE (0x44840080) -#define SOC_SADC_REG_BASE (0x44870000) -#define SOC_EFUSE_REG_BASE (0x44880000) -#define SOC_IRDA_REG_BASE (0x44890000) -#define SOC_I2S_REG_BASE (0x47810000) -#define SOC_TRNG_REG_BASE (0x448A0000) -#define SOC_XVR_REG_BASE (0x4A800000) -#define SOC_AUD_REG_BASE (0x47800000) -#define SOC_LA_REG_BASE (0x45070000) -#define SOC_JPEG_REG_BASE (0x48000000) -#define SOC_JPEG_DEC_REG_BASE (0x48040000) -#define SOC_EIP130_REG_BASE (0x4b000000) -#define SOC_EIP130OTP_REG_BASE (0x4b004000) -#define SOC_EIP130REGITER_REG_BASE (0x4b008000) -#define SOC_QSPI_REG_BASE (0x46040000) -#define SOC_LCD_DISP_REG_BASE (0x48060000) -#define SOC_SDIO_REG_BASE (0x448B0000) -#define SOC_USB_REG_BASE (0x46002000) -#define SOC_RC_REG_BASE (0x4980C000) -#define SOC_TRX_REG_BASE (0x4980C200) -#define SOC_POWTBL_REG_BASE (0x4980C400) -#define SOC_DPDTBL_REG_BASE (0x4980C800) -#define SOC_AGCMEM_REG_BASE (0x4980A000) -#define SOC_PEAKCWMEM_REG_BASE (0x4980D000) -#define SOC_DMA2D_REG_BASE (0x48020000) -#define SOC_PSRAM_REG_BASE (0x46080000) -#endif //__REG_BASE_H__ diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256_cp1/soc.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256_cp1/soc.h deleted file mode 100644 index 6eaa0b62d2dc371d44c010518c0321bf91e9e4c5..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256_cp1/soc.h +++ /dev/null @@ -1,117 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#include -#include "soc_cap.h" -#include "reg_base.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_VAULT_HOST_BASE (0x4B000000) -#define SOC_VAULT_OTP_BASE (0x4B004000) -#define SOC_VAULT_REG_BASE (0x4B008000) -#if 0 -#define SOC_EFUSE_REG_BASE (0x44880000) -#define SOC_SYSTEM_REG_BASE (0x44010000) -#define SOC_UART_REG_BASE (0x44820000) -#define SOC_TRNG_REG_BASE (0x448A0000) -#define SOC_WDT_REG_BASE (0x44800000) -#define SOC_TIMER_REG_BASE (0x44810000) -#define SOC_GPIO_REG_BASE (0x44000400) -#define SOC_DMA_REG_BASE (0x44020000) -#define SOC_ADC_REG_BASE (0x44870000) -#define SOC_SPI1_REG_BASE (0x44860000) -#define SOC_SPI2_REG_BASE (0x458C0000) -#define SOC_MAILBOX_REG_BASE (0xA0000000) -#define SOC_QSPI_REG_BASE (0x46040000) -#define SOC_QSPI_DATA_REG_BASE (0x68000000) -#endif -#define SOC_PWM_REG_BASE (0x44840000) -#define SOC_ICU_REG_BASE (0x44010000) -#define SOC_FLASH_REG_BASE (0x44030000) -#if 0 -#define SOC_AON_PMU_REG_BASE (0x44000000) -#define SOC_I2C0_REG_BASE (0x44850000) -#define SOC_I2C1_REG_BASE (0x45890000) -#define SOC_AUD_REG_BASE (0x47800000) -#endif -#define SOC_SDIO_REG_BASE (0x448B0000) - -#define REG_WRITE(_r, _v) ({\ - (*(volatile uint32_t *)(_r)) = (_v);\ - }) - -#define REG_READ(_r) ({\ - (*(volatile uint32_t *)(_r));\ - }) - -#define REG_GET_BIT(_r, _b) ({\ - (*(volatile uint32_t*)(_r) & (_b));\ - }) - -#define REG_SET_BIT(_r, _b) ({\ - (*(volatile uint32_t*)(_r) |= (_b));\ - }) - -#define REG_CLR_BIT(_r, _b) ({\ - (*(volatile uint32_t*)(_r) &= ~(_b));\ - }) - -#define REG_SET_BITS(_r, _b, _m) ({\ - (*(volatile uint32_t*)(_r) = (*(volatile uint32_t*)(_r) & ~(_m)) | ((_b) & (_m)));\ - }) - -#define REG_GET_FIELD(_r, _f) ({\ - ((REG_READ(_r) >> (_f##_S)) & (_f##_V));\ - }) - -#define REG_SET_FIELD(_r, _f, _v) ({\ - (REG_WRITE((_r),((REG_READ(_r) & ~((_f##_V) << (_f##_S)))|(((_v) & (_f##_V))<<(_f##_S)))));\ - }) - -#define REG_MCHAN_GET_FIELD(_ch, _r, _f) ({\ - ((REG_READ(_r) >> (_f##_MS(_ch))) & (_f##_V));\ - }) - -#define REG_MCHAN_SET_FIELD(_ch, _r, _f, _v) ({\ - (REG_WRITE((_r), ((REG_READ(_r) & ~((_f##_V) << (_f##_MS(_ch))))|(((_v) & (_f##_V))<<(_f##_MS(_ch))))));\ - }) - -#define VALUE_GET_FIELD(_r, _f) (((_r) >> (_f##_S)) & (_f)) - -#define VALUE_GET_FIELD2(_r, _f) (((_r) & (_f))>> (_f##_S)) - -#define VALUE_SET_FIELD(_r, _f, _v) ((_r)=(((_r) & ~((_f) << (_f##_S)))|((_v)<<(_f##_S)))) - -#define VALUE_SET_FIELD2(_r, _f, _v) ((_r)=(((_r) & ~(_f))|((_v)<<(_f##_S)))) - -#define FIELD_TO_VALUE(_f, _v) (((_v)&(_f))<<_f##_S) - -#define FIELD_TO_VALUE2(_f, _v) (((_v)<<_f##_S) & (_f)) - -#ifndef BIT -#define BIT(i) (1<<(i)) -#endif - -#ifndef BIT64 -#define BIT64(i) (1LL << (i)) -#endif - -#ifdef __cplusplus -} -#endif diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256_cp1/soc_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256_cp1/soc_cap.h deleted file mode 100644 index 7aad100961dc9e5005bc4b5e3e5f42a5cf2267a8..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256_cp1/soc_cap.h +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#include "adc_cap.h" -#include "aon_pmu_cap.h" -#include "dma_cap.h" -#include "efuse_cap.h" -#include "gpio_cap.h" -#include "i2c_cap.h" -#include "icu_cap.h" -#include "pwm_cap.h" -#include "spi_cap.h" -#include "sys_cap.h" -#include "timer_cap.h" -#include "trng_cap.h" -#include "uart_cap.h" -#include "wdt_cap.h" -#include "mailbox_cap.h" -#include "aon_rtc_cap.h" -#include "i2s_cap.h" -#include "aud_cap.h" diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256_cp1/spi_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256_cp1/spi_cap.h deleted file mode 100644 index a777b8bd546d2e356f120da044b73091bb936424..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256_cp1/spi_cap.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_SPI_UNIT_NUM 2 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256_cp1/sys_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256_cp1/sys_cap.h deleted file mode 100644 index 3d70982245ef48ab48a9f97010ed67a9218b57f3..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256_cp1/sys_cap.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_SYSTEM_GPIO_FUNC_GROUP 6 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256_cp1/timer_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256_cp1/timer_cap.h deleted file mode 100644 index 64b3cfad064449bcac62ff95230860370f63378f..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256_cp1/timer_cap.h +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_TIMER_UNIT_NUM 1 -#define SOC_TIMER_CHAN_NUM_PER_UNIT 6 -#define SOC_TIMER_GROUP_NUM 2 -#define SOC_TIMER_CHAN_NUM_PER_GROUP 3 -#define SOC_TIMER_INTERRUPT_NUM 2 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256_cp1/trng_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256_cp1/trng_cap.h deleted file mode 100644 index 46505120e4eab86c79b97d16558f6ef4cae0cf5f..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256_cp1/trng_cap.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_TRNG_UNIT_NUM 1 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256_cp1/uart_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256_cp1/uart_cap.h deleted file mode 100644 index 8f8b3db159f4e43c9fd686216524c6b3c5583bd1..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256_cp1/uart_cap.h +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_UART_UNIT_NUM 1 -#define SOC_UART_ID_NUM_PER_UNIT 3 - -#ifdef __cplusplus -} -#endif - - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256_cp1/vault_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256_cp1/vault_cap.h deleted file mode 100644 index ada03b2894920d7bde375f8c113e2300ec40553b..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256_cp1/vault_cap.h +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_VAULT_UNIT_NUM 1 - -#ifdef __cplusplus -} -#endif - - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256_cp1/wdt_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256_cp1/wdt_cap.h deleted file mode 100644 index 335278317c6ad9cd7872b4306c6fe82f28e61591..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7256_cp1/wdt_cap.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_WDT_UNIT_NUM 1 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7271/adc_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7271/adc_cap.h deleted file mode 100644 index cf41b7f61ed93e01cbee63d9ca2c952a89a8f43b..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7271/adc_cap.h +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#define SOC_ADC_CHAN_MIN 1 -#define SOC_ADC_CHAN_MAX 13 -#define SOC_ADC_SAMPLE_CNT_MAX 32 - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7271/aon_pmu_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7271/aon_pmu_cap.h deleted file mode 100644 index d807a97dcfaed7fc32a8f050a0b9e8bdcab97860..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7271/aon_pmu_cap.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -//#define SOC_SYSTEM_GPIO_FUNC_GROUP 1 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7271/calendar_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7271/calendar_cap.h deleted file mode 100644 index 82ddd33ea2cc95dc80235c082720b886239133cb..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7271/calendar_cap.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_CALENDAR_UNIT_NUM 1 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7271/dma_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7271/dma_cap.h deleted file mode 100644 index cc6ee40129edda7cf1cf42b64ae8fed1e73e55e0..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7271/dma_cap.h +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_DMA_UNIT_NUM 1 -#define SOC_DMA_CHAN_NUM_PER_UNIT 6 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7271/efuse_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7271/efuse_cap.h deleted file mode 100644 index 6ec28cd053b59a2ad9e9c8ebc87c0c1f06487934..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7271/efuse_cap.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_EFUSE_UNIT_NUM 1 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7271/flash_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7271/flash_cap.h deleted file mode 100644 index 0968373d28b9fd5a10402eaf963cb2467eb16aaf..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7271/flash_cap.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_FLASH_UNIT_NUM 1 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7271/gpio_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7271/gpio_cap.h deleted file mode 100644 index 8580b7e6eb23d574157435b615b3ec5e63f29f14..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7271/gpio_cap.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_GPIO_NUM 40 -#define GPIO_PERI_FUNC_NUM 5 - -#ifdef __cplusplus -} -#endif diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7271/i2c_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7271/i2c_cap.h deleted file mode 100644 index 85f0d2a8d3eb2c25f51cf76721c35ab2a199f702..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7271/i2c_cap.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_I2C_UNIT_NUM 3 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7271/icu_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7271/icu_cap.h deleted file mode 100644 index b97c4f04485d7d9f59f93e1b926858a37e07de05..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7271/icu_cap.h +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7271/jpeg_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7271/jpeg_cap.h deleted file mode 100644 index 43ddac0c4f32d0cfeaa5ecd9b1cff35396d318f8..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7271/jpeg_cap.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_JPEG_UNIT_NUM 1 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7271/mailbox_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7271/mailbox_cap.h deleted file mode 100755 index 65eaa1049cedc4b7d29cf8b86ace050525ebe584..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7271/mailbox_cap.h +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once -#ifdef __cplusplus -extern "C" { -#endif -#define SOC_MAILBOX_NUM 4 - -#ifdef __cplusplus -} -#endif - - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7271/mapping.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7271/mapping.h deleted file mode 100755 index b97c4f04485d7d9f59f93e1b926858a37e07de05..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7271/mapping.h +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7271/pwm_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7271/pwm_cap.h deleted file mode 100644 index 43c1e4e6162bc60f85f02097078438d94e05c02b..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7271/pwm_cap.h +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_PWM_UNIT_NUM 1 -#define SOC_PWM_CHAN_NUM_PER_UNIT 12 -#define SOC_PWM_CHAN_NUM_PER_GROUP 3 -#define SOC_PWM_GROUP_NUM 4 - -#ifdef __cplusplus -} -#endif diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7271/sdio_host_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7271/sdio_host_cap.h deleted file mode 100644 index 3286e2fca9af8e0c30e55c4e6be524cd1d61435e..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7271/sdio_host_cap.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_SDIO_HOST_UNIT_NUM 1 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7271/soc.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7271/soc.h deleted file mode 100644 index 897e4812bd285160209beadf39b87611e75daed6..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7271/soc.h +++ /dev/null @@ -1,175 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#include -#include "soc_cap.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_PMU_REG_BASE (0x00800200) -#define SOC_GPIO_REG_BASE (0x00800300) -#define SOC_ICU_REG_BASE (0x00802000) -#define SOC_UART_REG_BASE (0x00802100) -#define SOC_I2C0_REG_BASE (0x00802200) -#define SOC_I2C1_REG_BASE (0x00802240) -#define SOC_I2C2_REG_BASE (0x00802280) -#define SOC_SDIO_HOST_REG_BASE (0x00802300) -#define SOC_SPI0_REG_BASE (0x00802500) -#define SOC_SPI1_REG_BASE (0x00802540) -#define SOC_SPI2_REG_BASE (0x00802580) -#define SOC_WDT_REG_BASE (0x00802700) -#define SOC_TRNG_REG_BASE (0x00802720) -#define SOC_EFUSE_REG_BASE (0x00802740) -#define SOC_TIMER_REG_BASE (0x00802780) -#define SOC_PWM_REG_BASE (0x00802800) -#define SOC_ADC_REG_BASE (0x00802900) -#define SOC_FLASH_REG_BASE (0x00803000) -#define SOC_DMA_REG_BASE (0x00805000) -#define SOC_JPEG_REG_BASE (0x00807000) -#define SOC_MAILBOX_REG_BASE (0x06000000) - -#define W_SYS_CTRL_BASE_ADDR 0x00800000 -#define W_PMU_BASE_ADDR 0x00800200 -#define W_LCD_BASE_ADDR 0x00800280 -#define W_GPIO_BASE_ADDR 0x00800300 -#define W_SDIO_DMA_BASE_ADDR 0x00801000 -#define W_APB_BUS_BASE_ADDR 0x00802000 -#define W_ICU_BASE_ADDR 0x00802000 -#define W_UART1_BASE_ADDR 0x00802100 -#define W_UART2_BASE_ADDR 0x00802140 -#define W_UART3_BASE_ADDR 0x00802180 -#define W_FM_I2C_BASE_ADDR 0x00802200 -#define W_I2C1_BASE_ADDR 0x00802240 -#define W_I2C2_BASE_ADDR 0x00802280 -#define W_SDIO_HOST_BASE_ADDR 0x00802300 -#define W_SPI1_BASE_ADDR 0x00802500 -#define W_SPI2_BASE_ADDR 0x00802540 -#define W_SPI3_BASE_ADDR 0x00802580 -#define W_WDT_BASE_ADDR 0x00802700 -#define W_TRNG_BASE_ADDR 0x00802720 -#define W_EFUSE_BASE_ADDR 0x00802740 -#define W_IRDA_BASE_ADDR 0x00802760 -#define W_TIMER1_BASE_ADDR 0x00802780 -#define W_TIMER2_BASE_ADDR 0x008027C0 -#define W_PWM1_BASE_ADDR 0x00802800 -#define W_PWM2_BASE_ADDR 0x00802840 -#define W_PWM3_BASE_ADDR 0x00802880 -#define W_PWM4_BASE_ADDR 0x008028C0 -#define W_SADC_BASE_ADDR 0x00802900 -#define W_CEC_BASE_ADDR 0x00802A00 -#define W_FLASH_BASE_ADDR 0x00803000 -#define W_USB1_BASE_ADDR 0x00804000 -#define W_USB2_BASE_ADDR 0x00804800 -#define W_GENER_DMA_BASE_ADDR 0x00805000 -#define W_SECURITY_BASE_ADDR 0x00806000 -#define W_JPEG_BASE_ADDR 0x00807000 -#define W_MDM_CFG_BASE_ADDR 0x00900000 -#define W_MDM_STAT_BASE_ADDR 0x00900000 -#define W_RC_BEKEN_BASE_ADDR 0x00950000 -#define W_TRX_BEKEN_BASE_ADDR 0x00950080 -#define W_MACPHY_BYPASS_BASE_ADDR 0x00960000 -#define W_MAC_CORE_BASE_ADDR 0x00A00000 -#define W_MAC_PL_BASE_ADDR 0x00A08000 -#define W_YUV_MEM_BASE_ADDR 0x00B00000 -#define W_WIFI_DTCM_512KB_BASE_ADDR 0x00400000 -#define W_WIFI_ITCM_32KB_BASE_ADDR 0x003F8000 -#define W_BUS_SMEM_128KB_BASE_ADDR 0x04000000 -#define W_DSP_DMEM_64KB_BASE_ADDR 0x0C000000 -#define W_DSP_CPM_BASE_ADDR 0x0C400000 -#define W_DSP_SMEM_1_5MB_BASE_ADDR 0x0C800000 -#define W_PSRAM_BASE_ADDR 0x0D000000 -#define W_DMA_BASE_ADDR 0x0E800000 -#define W_FFT_BASE_ADDR 0x0E810000 -#define W_APBD_BUS_BASE_ADDR 0x0E8F0000 -#define W_ICUD_BASE_ADDR 0x0E8F0000 -#define W_AUDIO_BASE_ADDR 0x0E8F1000 -#define W_SPDIF_BASE_ADDR 0x0E8F2000 -#define W_EQ_BASE_ADDR 0x0E8F3000 -#define W_I2S1_BASE_ADDR 0x0E8F4000 -#define W_WDTD_BASE_ADDR 0x0E8F5000 -#define W_RSV_BASE_ADDR 0x0E8F6000 -#define W_DSP_CTRL_BASE_ADDR 0x0E8F7000 -#define W_I2S2_BASE_ADDR 0x0E8F8000 -#define W_I2S3_BASE_ADDR 0x0E8F9000 -#define W_PSRAM_CTRL_BASE_ADDR 0x0E8FA000 -#define W_BT_IMEM_384KB_BASE_ADDR 0x10000000 -#define W_BT_DMEM_96KB_BASE_ADDR 0x10400000 - -#define REG_WRITE(_r, _v) ({\ - (*(volatile uint32_t *)(_r)) = (_v);\ - }) - -#define REG_READ(_r) ({\ - (*(volatile uint32_t *)(_r));\ - }) - -#define REG_GET_BIT(_r, _b) ({\ - (*(volatile uint32_t*)(_r) & (_b));\ - }) - -#define REG_SET_BIT(_r, _b) ({\ - (*(volatile uint32_t*)(_r) |= (_b));\ - }) - -#define REG_CLR_BIT(_r, _b) ({\ - (*(volatile uint32_t*)(_r) &= ~(_b));\ - }) - -#define REG_SET_BITS(_r, _b, _m) ({\ - (*(volatile uint32_t*)(_r) = (*(volatile uint32_t*)(_r) & ~(_m)) | ((_b) & (_m)));\ - }) - -#define REG_GET_FIELD(_r, _f) ({\ - ((REG_READ(_r) >> (_f##_S)) & (_f##_V));\ - }) - -#define REG_SET_FIELD(_r, _f, _v) ({\ - (REG_WRITE((_r),((REG_READ(_r) & ~((_f##_V) << (_f##_S)))|(((_v) & (_f##_V))<<(_f##_S)))));\ - }) - -#define REG_MCHAN_GET_FIELD(_ch, _r, _f) ({\ - ((REG_READ(_r) >> (_f##_MS(_ch))) & (_f##_V));\ - }) - -#define REG_MCHAN_SET_FIELD(_ch, _r, _f, _v) ({\ - (REG_WRITE((_r), ((REG_READ(_r) & ~((_f##_V) << (_f##_MS(_ch))))|(((_v) & (_f##_V))<<(_f##_MS(_ch))))));\ - }) - -#define VALUE_GET_FIELD(_r, _f) (((_r) >> (_f##_S)) & (_f)) - -#define VALUE_GET_FIELD2(_r, _f) (((_r) & (_f))>> (_f##_S)) - -#define VALUE_SET_FIELD(_r, _f, _v) ((_r)=(((_r) & ~((_f) << (_f##_S)))|((_v)<<(_f##_S)))) - -#define VALUE_SET_FIELD2(_r, _f, _v) ((_r)=(((_r) & ~(_f))|((_v)<<(_f##_S)))) - -#define FIELD_TO_VALUE(_f, _v) (((_v)&(_f))<<_f##_S) - -#define FIELD_TO_VALUE2(_f, _v) (((_v)<<_f##_S) & (_f)) - -#ifndef BIT -#define BIT(i) (1<<(i)) -#endif - -#ifndef BIT64 -#define BIT64(i) (1LL << (i)) -#endif - -#ifdef __cplusplus -} -#endif diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7271/soc_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7271/soc_cap.h deleted file mode 100644 index a1baf975734f10e1777b92ed0afe7a612f31c610..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7271/soc_cap.h +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#include "adc_cap.h" -#include "aon_pmu_cap.h" -#include "dma_cap.h" -#include "efuse_cap.h" -#include "gpio_cap.h" -#include "i2c_cap.h" -#include "icu_cap.h" -#include "pwm_cap.h" -#include "spi_cap.h" -#include "sys_cap.h" -#include "timer_cap.h" -#include "trng_cap.h" -#include "uart_cap.h" -#include "wdt_cap.h" -#include "mailbox_cap.h" -#include "pwm_cap.h" diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7271/spi_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7271/spi_cap.h deleted file mode 100644 index 87db5dde65dd3a15551e8c147718613ffe72d7b6..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7271/spi_cap.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_SPI_UNIT_NUM 3 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7271/sys_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7271/sys_cap.h deleted file mode 100644 index 3d70982245ef48ab48a9f97010ed67a9218b57f3..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7271/sys_cap.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_SYSTEM_GPIO_FUNC_GROUP 6 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7271/timer_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7271/timer_cap.h deleted file mode 100644 index 0792e7eb3f32a77e634338b61eaea534b1f1d248..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7271/timer_cap.h +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_TIMER_UNIT_NUM 1 -#define SOC_TIMER_CHAN_NUM_PER_UNIT 6 -#define SOC_TIMER_GROUP_NUM 2 -#define SOC_TIMER_CHAN_NUM_PER_GROUP 3 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7271/trng_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7271/trng_cap.h deleted file mode 100644 index 46505120e4eab86c79b97d16558f6ef4cae0cf5f..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7271/trng_cap.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_TRNG_UNIT_NUM 1 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7271/uart_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7271/uart_cap.h deleted file mode 100644 index 8f8b3db159f4e43c9fd686216524c6b3c5583bd1..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7271/uart_cap.h +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_UART_UNIT_NUM 1 -#define SOC_UART_ID_NUM_PER_UNIT 3 - -#ifdef __cplusplus -} -#endif - - diff --git a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7271/wdt_cap.h b/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7271/wdt_cap.h deleted file mode 100644 index 335278317c6ad9cd7872b4306c6fe82f28e61591..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/include/soc/bk7271/wdt_cap.h +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -#define SOC_WDT_UNIT_NUM 1 - -#ifdef __cplusplus -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/arch/riscv/boot_handlers_base.S b/bk7235/liteos_m/bk_sdk_armino/middleware/arch/riscv/boot_handlers_base.S index 809aed6ed15482b9e9beb26654a1c098e4e17fc9..342541e1fc53a956dfe4e745c1ffc331f18d9fd2 100755 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/arch/riscv/boot_handlers_base.S +++ b/bk7235/liteos_m/bk_sdk_armino/middleware/arch/riscv/boot_handlers_base.S @@ -1,16 +1,18 @@ -// Copyright 2020-2021 Beken -// -// 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. +/* + * Copyright (C) 2022 Beken Corporation + * 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. + */ + .globl entry_main .globl boot_reset diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/arch/riscv/boot_vectors_base.S b/bk7235/liteos_m/bk_sdk_armino/middleware/arch/riscv/boot_vectors_base.S index b4133fa004528d6bf7b0babfff74ccaa37c7812d..be60830415c545af9455781fbb8245e9d1cdfed1 100755 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/arch/riscv/boot_vectors_base.S +++ b/bk7235/liteos_m/bk_sdk_armino/middleware/arch/riscv/boot_vectors_base.S @@ -1,8 +1,18 @@ /* - * Copyright (c) 2012-2017 Andes Technology Corporation - * All rights reserved. + * Copyright (C) 2022 Beken Corporation + * 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 "core_v5.h" .section .nds_vector, "ax" diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/arch/riscv/boot_vectors_liteos_m.S b/bk7235/liteos_m/bk_sdk_armino/middleware/arch/riscv/boot_vectors_liteos_m.S index 22f2af6f5748587bb35002d7aa0036548a335de9..0c2534e2ec2c9c2359702ba4c2364b1132fb6036 100755 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/arch/riscv/boot_vectors_liteos_m.S +++ b/bk7235/liteos_m/bk_sdk_armino/middleware/arch/riscv/boot_vectors_liteos_m.S @@ -1,8 +1,18 @@ /* - * Copyright (c) 2012-2017 Andes Technology Corporation - * All rights reserved. + * Copyright (C) 2022 Beken Corporation + * 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 "core_v5.h" .section .nds_vector, "ax" diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/arch/riscv/cache.c b/bk7235/liteos_m/bk_sdk_armino/middleware/arch/riscv/cache.c index 2768ab2b099e9f4c334f979705ebb5d54ca5c9dc..8e95e321beced95027075b00590852f540721305 100755 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/arch/riscv/cache.c +++ b/bk7235/liteos_m/bk_sdk_armino/middleware/arch/riscv/cache.c @@ -1,3 +1,18 @@ +/* + * Copyright (C) 2022 Beken Corporation + * 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 #include "platform.h" #include diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/arch/riscv/cache.h b/bk7235/liteos_m/bk_sdk_armino/middleware/arch/riscv/cache.h index f9973505abea8e4dd3fa99726f68bf317da50aa4..c46f963349e83e5f969d945ff62d90efefb97d67 100755 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/arch/riscv/cache.h +++ b/bk7235/liteos_m/bk_sdk_armino/middleware/arch/riscv/cache.h @@ -1,3 +1,18 @@ +/* + * Copyright (C) 2022 Beken Corporation + * 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 __CACHE_H__ #define __CACHE_H__ diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/arch/riscv/include/BK7256_RegList.h b/bk7235/liteos_m/bk_sdk_armino/middleware/arch/riscv/include/BK7256_RegList.h index bd190a1e1ac2b929a29c6eb3d4e52a95b8e25d05..f94c35a5387beee53b80a2ca5a3026b15f2b26fc 100755 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/arch/riscv/include/BK7256_RegList.h +++ b/bk7235/liteos_m/bk_sdk_armino/middleware/arch/riscv/include/BK7256_RegList.h @@ -1,3 +1,18 @@ +/* + * Copyright (C) 2022 Beken Corporation + * 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 _BK7256_REGLIST_H_ #define _BK7256_REGLIST_H_ diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/arch/riscv/include/core_v5.h b/bk7235/liteos_m/bk_sdk_armino/middleware/arch/riscv/include/core_v5.h deleted file mode 100755 index 0203d3e2ceed04de2331adb0c789a1d3c021ba6d..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/arch/riscv/include/core_v5.h +++ /dev/null @@ -1,130 +0,0 @@ -#ifndef __CORE_V5_H__ -#define __CORE_V5_H__ - -#define MSTATUS_UIE 0x00000001 -#define MSTATUS_SIE 0x00000002 -#define MSTATUS_HIE 0x00000004 -#define MSTATUS_MIE 0x00000008 -#define MSTATUS_UPIE 0x00000010 -#define MSTATUS_SPIE 0x00000020 -#define MSTATUS_HPIE 0x00000040 -#define MSTATUS_MPIE 0x00000080 -#define MSTATUS_SPP 0x00000100 -#define MSTATUS_HPP 0x00000600 -#define MSTATUS_MPP 0x00001800 -#define MSTATUS_FS 0x00006000 -#define MSTATUS_XS 0x00018000 -#define MSTATUS_MPRV 0x00020000 -#define MSTATUS_PUM 0x00040000 -#define MSTATUS_MXR 0x00080000 -#define MSTATUS_VM 0x1F000000 -#define MSTATUS32_SD 0x80000000 -#define MSTATUS64_SD 0x8000000000000000 - -#if __riscv_xlen == 64 -#define MCAUSE_INT 0x8000000000000000UL -#define MCAUSE_CAUSE 0x7FFFFFFFFFFFFFFFUL -#else -#define MCAUSE_INT 0x80000000UL -#define MCAUSE_CAUSE 0x7FFFFFFFUL -#endif - -#define IRQ_S_SOFT 1 -#define IRQ_H_SOFT 2 -#define IRQ_M_SOFT 3 -#define IRQ_S_TIMER 5 -#define IRQ_H_TIMER 6 -#define IRQ_M_TIMER 7 -#define IRQ_S_EXT 9 -#define IRQ_H_EXT 10 -#define IRQ_M_EXT 11 -#define IRQ_COP 12 -#define IRQ_HOST 13 - -/* Machine mode MCAUSE */ -#define TRAP_M_I_ACC_FAULT 1 /* Instruction access fault */ -#define TRAP_M_L_ACC_FAULT 5 /* Data load access fault */ -#define TRAP_M_S_ACC_FAULT 7 /* Data store access fault */ -#define TRAP_U_ECALL 8 -#define TRAP_S_ECALL 9 -#define TRAP_H_ECALL 10 -#define TRAP_M_ECALL 11 -#define TRAP_M_I_PAGE_FAULT 12 /* Instruction page fault */ -#define TRAP_M_L_PAGE_FAULT 13 /* Data load page fault */ -#define TRAP_M_S_PAGE_FAULT 15 /* Data store page fault */ -#define TRAP_M_STACKOVF 32 -#define TRAP_M_STACKUDF 33 -#define TRAP_M_USER_ASSERT 0x77 -#define TRAP_M_USER_NP 0x88 -#define TRAP_M_USER_OTHER 0x99 - - -/* Supervisor mode SCAUSE */ -#define TRAP_S_I_ACC_FAULT 1 /* Instruction access fault */ -#define TRAP_S_L_ACC_FAULT 5 /* Data load access fault */ -#define TRAP_S_S_ACC_FAULT 7 /* Data store access fault */ -#define TRAP_S_I_PAGE_FAULT 12 /* Instruction page fault */ -#define TRAP_S_L_PAGE_FAULT 13 /* Data load page fault */ -#define TRAP_S_S_PAGE_FAULT 15 /* Data store page fault */ - -#define MIP_SSIP (1 << IRQ_S_SOFT) -#define MIP_HSIP (1 << IRQ_H_SOFT) -#define MIP_MSIP (1 << IRQ_M_SOFT) -#define MIP_STIP (1 << IRQ_S_TIMER) -#define MIP_HTIP (1 << IRQ_H_TIMER) -#define MIP_MTIP (1 << IRQ_M_TIMER) -#define MIP_SEIP (1 << IRQ_S_EXT) -#define MIP_HEIP (1 << IRQ_H_EXT) -#define MIP_MEIP (1 << IRQ_M_EXT) - -#if __riscv_xlen == 64 -# define SLL32 sllw -# define STORE sd -# define LOAD ld -# define LWU lwu -# define LOG_REGBYTES 3 -#else -# define SLL32 sll -# define STORE sw -# define LOAD lw -# define LWU lw -# define LOG_REGBYTES 2 -#endif -#ifndef REGBYTES -#define REGBYTES (1 << LOG_REGBYTES) -#endif - -#if __riscv_flen == 64 -# define FPSTORE fsd -# define FPLOAD fld -# define LOG_FPREGBYTES 3 -#else -# define FPSTORE fsw -# define FPLOAD flw -# define LOG_FPREGBYTES 2 -#endif -#define FPREGBYTES (1 << LOG_FPREGBYTES) - -#define STR(S) #S -#define XSTR(S) STR(S) - -#define PUSH XSTR(STORE) -#define POP XSTR(LOAD) -#define REGSIZE XSTR(REGBYTES) -#define FPPUSH XSTR(FPSTORE) -#define FPPOP XSTR(FPLOAD) -#define FPREGSIZE XSTR(FPREGBYTES) - -#ifndef __ASSEMBLER__ - -#include - -#define read_csr(reg) __nds__csrr(reg) -#define write_csr(reg, val) __nds__csrw(val, reg) -#define swap_csr(reg, val) __nds__csrrw(val, reg) -#define set_csr(reg, bit) __nds__csrrs(bit, reg) -#define clear_csr(reg, bit) __nds__csrrc(bit, reg) - -#endif - -#endif // __CORE_V5_H__ diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/arch/riscv/include/platform.h b/bk7235/liteos_m/bk_sdk_armino/middleware/arch/riscv/include/platform.h index ff73499cc9f318d02afa788b030da3a2f43a1ce2..648ccf0214c8085f0d6fdc4383618dca82293114 100755 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/arch/riscv/include/platform.h +++ b/bk7235/liteos_m/bk_sdk_armino/middleware/arch/riscv/include/platform.h @@ -1,9 +1,19 @@ /* - * Copyright (c) 2012-2017 Andes Technology Corporation - * All rights reserved. + * Copyright (C) 2022 Beken Corporation + * 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 __PLATFORM_H__ #define __PLATFORM_H__ diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/arch/riscv/initfini.c b/bk7235/liteos_m/bk_sdk_armino/middleware/arch/riscv/initfini.c index 5c73e6e1f8b8414e64d9cc69895729e722952675..2ebf70def2bab6bd861640b95773a9666a16cd4f 100755 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/arch/riscv/initfini.c +++ b/bk7235/liteos_m/bk_sdk_armino/middleware/arch/riscv/initfini.c @@ -1,3 +1,18 @@ +/* + * Copyright (C) 2022 Beken Corporation + * 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 #define USE_LIBC_INITFINI 0 diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/arch/riscv/pmp.c b/bk7235/liteos_m/bk_sdk_armino/middleware/arch/riscv/pmp.c index 1e6cbccc2aea5dea218cdca30495265baa0fed79..18a681bbaf213b30b5225dd3940b76a4ff90fc3e 100755 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/arch/riscv/pmp.c +++ b/bk7235/liteos_m/bk_sdk_armino/middleware/arch/riscv/pmp.c @@ -1,8 +1,19 @@ /* - * Copyright (c) 2012-2021 Andes Technology Corporation - * All rights reserved. + * Copyright (C) 2022 Beken Corporation + * 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 #include "platform.h" #include "pmp.h" diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/arch/riscv/pmp.h b/bk7235/liteos_m/bk_sdk_armino/middleware/arch/riscv/pmp.h index 97d49207750e17d7f735af03d0523057d2daf523..67efa90c02b53329514a61ceec4344fd446d35ad 100755 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/arch/riscv/pmp.h +++ b/bk7235/liteos_m/bk_sdk_armino/middleware/arch/riscv/pmp.h @@ -1,9 +1,19 @@ /* - * Copyright (c) 2012-2021 Andes Technology Corporation - * All rights reserved. + * Copyright (C) 2022 Beken Corporation + * 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 __PMP_H__ #define __PMP_H__ diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/arch/riscv/reset.c b/bk7235/liteos_m/bk_sdk_armino/middleware/arch/riscv/reset.c index 468efe62486281f311fc45419fd57d65f410419d..fabe55df57806982839bb65770d63fad500e254d 100755 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/arch/riscv/reset.c +++ b/bk7235/liteos_m/bk_sdk_armino/middleware/arch/riscv/reset.c @@ -1,8 +1,18 @@ /* - * Copyright (c) 2012-2018 Andes Technology Corporation - * All rights reserved. + * Copyright (C) 2022 Beken Corporation + * 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"platform.h" #include "cache.h" #include diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/arch/riscv/riscv_utility.S b/bk7235/liteos_m/bk_sdk_armino/middleware/arch/riscv/riscv_utility.S index eeabc8feff113260e872fb30ec43c5dc23a0f0a7..3cc0a81d0ac49b13a6bb4784f9269097dfede34d 100755 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/arch/riscv/riscv_utility.S +++ b/bk7235/liteos_m/bk_sdk_armino/middleware/arch/riscv/riscv_utility.S @@ -1,9 +1,19 @@ /* - * Copyright (c) 2021-2022 Beken Corporation - * All rights reserved. + * Copyright (C) 2022 Beken Corporation + * 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 "core_v5.h" #define MTIMER (0xE6000000) diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/arch/riscv/trap_base.c b/bk7235/liteos_m/bk_sdk_armino/middleware/arch/riscv/trap_base.c index c7e2219b769680cf3e1b1fded1cd634790d0615b..027146a2c7ba23261162ea618058570309271712 100755 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/arch/riscv/trap_base.c +++ b/bk7235/liteos_m/bk_sdk_armino/middleware/arch/riscv/trap_base.c @@ -1,9 +1,19 @@ /* - * Copyright (c) 2012-2021 Andes Technology Corporation - * All rights reserved. + * Copyright (C) 2022 Beken Corporation + * 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 #include "boot.h" #include "sdkconfig.h" diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/boards/bk7235/vnd_cal/include/vnd_cal.h b/bk7235/liteos_m/bk_sdk_armino/middleware/boards/bk7235/vnd_cal/include/vnd_cal.h index 357e080ef600452bc92eefb064b8e0a738eb1591..778d73ba6f3576e8bd4219a4bd155603ac148b2f 100755 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/boards/bk7235/vnd_cal/include/vnd_cal.h +++ b/bk7235/liteos_m/bk_sdk_armino/middleware/boards/bk7235/vnd_cal/include/vnd_cal.h @@ -1,3 +1,17 @@ +/* + * Copyright (C) 2022 Beken Corporation + * 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 VND_CAL_H #define VND_CAL_H diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/boards/bk7235/vnd_cal/vnd_cal.c b/bk7235/liteos_m/bk_sdk_armino/middleware/boards/bk7235/vnd_cal/vnd_cal.c index 19e2a732d52f0525589c3cb966404ab5c8f62360..6e255131968210e9b8fc8a6340592c5123c7c69d 100755 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/boards/bk7235/vnd_cal/vnd_cal.c +++ b/bk7235/liteos_m/bk_sdk_armino/middleware/boards/bk7235/vnd_cal/vnd_cal.c @@ -1,3 +1,17 @@ +/* + * Copyright (C) 2022 Beken Corporation + * 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 "vnd_cal.h" diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/common_io/CMakeLists.txt b/bk7235/liteos_m/bk_sdk_armino/middleware/compal/common_io/CMakeLists.txt deleted file mode 100755 index 68c426a12e42140a1b1834b95d24e04eff5cec7d..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/common_io/CMakeLists.txt +++ /dev/null @@ -1,79 +0,0 @@ -afr_module() - -set(inc_dir "${CMAKE_CURRENT_LIST_DIR}/include") -set(test_dir "${CMAKE_CURRENT_LIST_DIR}/test") - -afr_module_sources( - ${AFR_CURRENT_MODULE} - PUBLIC - "${inc_dir}/iot_adc.h" - "${inc_dir}/iot_battery.h" - "${inc_dir}/iot_efuse.h" - "${inc_dir}/iot_flash.h" - "${inc_dir}/iot_gpio.h" - "${inc_dir}/iot_hw.h" - "${inc_dir}/iot_i2c.h" - "${inc_dir}/iot_i2s.h" - "${inc_dir}/iot_perfcounter.h" - "${inc_dir}/iot_power.h" - "${inc_dir}/iot_pwm.h" - "${inc_dir}/iot_reset.h" - "${inc_dir}/iot_rtc.h" - "${inc_dir}/iot_sdio.h" - "${inc_dir}/iot_spi.h" - "${inc_dir}/iot_timer.h" - "${inc_dir}/iot_tsensor.h" - "${inc_dir}/iot_uart.h" - "${inc_dir}/iot_usb_device.h" - "${inc_dir}/iot_usb_host.h" - "${inc_dir}/iot_watchdog.h" -) - -afr_module_include_dirs( - ${AFR_CURRENT_MODULE} - PUBLIC - "${inc_dir}" -) - -afr_module_dependencies( - ${AFR_CURRENT_MODULE} - PUBLIC - AFR::common_io::mcu_port -) - -# Common I/O tests -afr_test_module() -afr_module_sources( - ${AFR_CURRENT_MODULE} - INTERFACE - "${test_dir}/iot_test_common_io_internal.h" - "${test_dir}/iot_test_common_io.c" - "${test_dir}/test_iot_adc.c" - "${test_dir}/test_iot_battery.c" - "${test_dir}/test_iot_efuse.c" - "${test_dir}/test_iot_flash.c" - "${test_dir}/test_iot_gpio.c" - "${test_dir}/test_iot_i2c.c" - "${test_dir}/test_iot_i2s.c" - "${test_dir}/test_iot_perfcounter.c" - "${test_dir}/test_iot_power.c" - "${test_dir}/test_iot_pwm.c" - "${test_dir}/test_iot_reset.c" - "${test_dir}/test_iot_rtc.c" - "${test_dir}/test_iot_sdio.c" - "${test_dir}/test_iot_spi.c" - "${test_dir}/test_iot_timer.c" - "${test_dir}/test_iot_tsensor.c" - "${test_dir}/test_iot_uart.c" - "${test_dir}/test_iot_watchdog.c" -) - -afr_module_include_dirs( - ${AFR_CURRENT_MODULE} - INTERFACE "${test_dir}" -) - -afr_module_dependencies( - ${AFR_CURRENT_MODULE} - INTERFACE AFR::common_io -) diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/common_io/component.mk b/bk7235/liteos_m/bk_sdk_armino/middleware/compal/common_io/component.mk deleted file mode 100755 index b5073c805a6c938cd9c2a538c9d4709a603397cb..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/common_io/component.mk +++ /dev/null @@ -1,10 +0,0 @@ -AMAZON_FREERTOS_COMMON_IO_DIR := ../../../../../../libraries/abstractions/common_io - -COMPONENT_SRCDIRS := . - -COMPONENT_ADD_INCLUDEDIRS := $(AMAZON_FREERTOS_COMMON_IO_DIR)/include \ - $(AMAZON_FREERTOS_COMMON_IO_DIR)/test \ - ./include - -CFLAGS += -Wno-format -Wno-maybe-uninitialized -Wno-pointer-sign -Wno-incompatible-pointer-types -Wno-unused-but-set-variable - diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/common_io/include/iot_adc.h b/bk7235/liteos_m/bk_sdk_armino/middleware/compal/common_io/include/iot_adc.h deleted file mode 100755 index f3981d6b880c12464efe07eaa9ce38e5572dd4ea..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/common_io/include/iot_adc.h +++ /dev/null @@ -1,359 +0,0 @@ -/* - * FreeRTOS Common IO V0.1.3 - * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * http://aws.amazon.com/freertos - * http://www.FreeRTOS.org - */ - -/** - * @file iot_adc.h - * @brief File for the HAL APIs of ADC called by application layer. - */ -#ifndef _IOT_ADC_H_ -#define _IOT_ADC_H_ - -/** - * @brief Error code returned by ADC driver - */ -#define IOT_ADC_SUCCESS ( 0 ) /*!< ADC operation completed successfully. */ -#define IOT_ADC_FAILED ( 1 ) /*!< ADC operation failed. */ -#define IOT_ADC_INVALID_VALUE ( 2 ) /*!< At least one parameter is invalid. */ -#define IOT_ADC_NOT_OPEN ( 3 ) /*!< ADC operation not possible unless ADC instance is opened. */ -#define IOT_ADC_FUNCTION_NOT_SUPPORTED ( 4 ) /*!< ADC operation not supported. */ -#define IOT_ADC_CH_BUSY ( 5 ) /*!< ADC channel is busy at current time. */ - -/** - * @brief The handle for a ADC peripheral, defined in the source file. - * This is an anonymous struct that is vendor/driver specific. - */ -struct IotAdcDescriptor; - -/** - * @brief IotAdcHandle_t is the handle type returned by calling iot_adc_open(). - * This is initialized in open and returned to caller. The caller must pass - * this pointer to the rest of the ADC APIs. - */ -typedef struct IotAdcDescriptor * IotAdcHandle_t; - -/** - * @brief ADC notification callback type - * - * @param[in] pvUserContext User Context passed when setting the callback. - * This is not used or modified by the driver. The context is - * provided by the caller when setting the callback, and is - * passed back to the caller in the callback. - * @param[out] pusConvertedData pointer to converted ADC sample data. - */ -typedef void ( * IotAdcCallback_t )( uint16_t * pusConvertedData, - void * pvUserContext ); - -/** - * @brief Initializes ADC controller with default configuration. - * init ADC controller, enable ADC clock, reset HW FIFO, set default - * configuration parameters, etc. Also allocate all required resources - * for ADC operation such as software data buffer etc. - * - * @warning Must be called prior to any other ADC api's so that a valid handle is obtained. - * @warning Once opened, the same ADC instance must be closed before calling open again. - * - * @param[in] lAdc The instance of ADC controller to initialize. - * - * @return - * - handle to the ADC controller on success - * - NULL, if - * - invalid instance number - * - open same instance more than once before closing it. - */ -IotAdcHandle_t iot_adc_open( int32_t lAdc ); - -/** - * @brief Close ADC controller. - * All pending operation will be cancelled, put ADC module in reset state or low - * power state if possible. Release all resources claimed during open call - * - * @param[in] pxAdc handle to ADC controller returned from iot_adc_open() call. - * - * @return - * - IOT_ADC_SUCCESS, on success; - * - IOT_I2C_INVALID_VALUE, if pxAdc is NULL - * - IOT_ADC_NOT_OPEN, if is not in open state (already closed). - */ -int32_t iot_adc_close( IotAdcHandle_t const pxAdc ); - -/** - * @brief Sets channel callback on availability of channel scan data. - * On availability of ADC scan data, the application is notified with a - * function callback. The callback function and user context for callback - * are set using iot_adc_set_callback. - * - * @note This callback is per AdcChannel for each handle. - * @note If input handle or AdcChannel is invalid, or if callback function is NULL, - * this function silently takes no action. - * - * @param[in] pxAdc The ADC handle returned in the open() call. - * @param[in] ucAdcChannel The ADC channel for which the callback is set - * @param[in] xAdcCallback The callback function to be called on availability of ADC channel data. - * @param[in] pvUserContext The user context to be passed when callback is called. - * - * Example Callback Function - * For asychronous ADC calls, a callback function is used to signal when the async - * task is complete. This example uses a Semaphore to signal the completion. - * @code{c} - * static void prvAdcChCallback( uint16_t * pusConvertedData, - * void * pvUserContext ) - * { - * BaseType_t xHigherPriorityTaskWoken; - * xSemaphoreGiveFromISR( xIotAdcSemaphore, &xHigherPriorityTaskWoken ); - * } - * @endcode - */ -void iot_adc_set_callback( IotAdcHandle_t const pxAdc, - uint8_t ucAdcChannel, - IotAdcCallback_t xAdcCallback, - void * pvUserContext ); - -/** - * @brief Start data acquisition for ADC channel until iot_adc_stop API is called. - * Data will be passed back to client using callback function. - * By default each callback will pass back one data sample, however if client has - * used ioctl to pass in data buffer, only when buffer is full will callback - * be triggered. - * - * @warning iot_adc_set_callback() must be called prior to this in order to get notification - * when ADC scan is complete and data is available. - * - * @note iot_adc_set_callback() must be called prior to iot_adc_start(). - * - * @param[in] pxAdc. The ADC handle returned in the open() call - * @param[in] ucAdcChannel. The ADC channel to start data acquisition - * - * @return - * - IOT_ADC_SUCCESS on success - * - IOT_ADC_INVALID_VALUE, on NULL handle or invalid AdcChannel - * - IOT_ADC_NOT_OPEN if ADC has not been opened yet. - * - IOT_ADC_CH_BUSY if ADC operation has started but is not complete - * - IOT_ADC_FAILED if not callback function has been set. - * Example Asynchronous read - * @code{c} - * // ADC Instance to open - * int32_t lAdcInstance = 0; - * - * // Return value of ADC functions - * int32_t lRetVal; - * - * // ADC Channel to read - * int32_t lAdcChannel = 0; - * - * // User/Driver context; if necessary - * void xUserContext = NULL; - * - * // Open the ADC instance and get a handle. - * xAdcHandle = iot_adc_open( lAdcInstance ); - * // assert(lRetVal == IOT_ADC_SUCCESS); - * - * // set the callback function - * iot_adc_set_callback( xAdcHandle, lAdcChannel, prvAdcChCallback, &xUserCntx ); - * - * // start channel data scan on channel - * lRetVal = iot_adc_start( xAdcHandle, lAdcChannel ); - * // assert( IOT_ADC_SUCCESS == lRetVal ); - * - * // wait for the ADC operation to complete - * lRetVal = xSemaphoreTake( xIotAdcSemaphore, lIotAdcChWaitTime ); - * // assert ( pdTRUE == lRetVal ); - * - * // stop channel data scan - * lRetVal = iot_adc_stop( xAdcHandle, lAdcChannel ); - * assert( IOT_ADC_SUCCESS == lRetVal ); - * - * // close ADC module - * lRetVal = iot_adc_close( xAdcHandle ); - * // assert( IOT_ADC_SUCCESS == lRetVal ); - * @endcode - */ -int32_t iot_adc_start( IotAdcHandle_t const pxAdc, - uint8_t ucAdcChannel ); - -/** - * @brief Stop data acquisition for ADC channel - * - * @param[in] pxAdc. The ADC handle returned in the open() call - * @param[in] ucAdcChannel. The ADC channel to stop data acquisition - * - * @return - * - IOT_ADC_SCUCCESS on success - * - IOT_ADC_INVALID_VALUE, on NULL handle or invalid AdcChannel - * - IOT_ADC_NOT_OPEN if ADC has been closed without re-opening. - */ -int32_t iot_adc_stop( IotAdcHandle_t const pxAdc, - uint8_t ucAdcChannel ); - -/** - * @brief read one ADC data sample. This API will return one ADC sample. - * - * @param[in] pxAdc. The ADC handle returned in the open() call. - * @param[in] ucAdcChannel. The ADC channel to read data from. - * @param[out] pusAdcSample. ADC channel read sample value. - * - * @return - * - IOT_ADC_SCUCCESS on success. - * - IOT_ADC_INVALID_VALUE, on NULL handle or invalid AdcChannel. - * - IOT_ADC_CH_BUSY if ADC operation not complete. - * - IOT_ADC_NOT_OPEN if ADC has been closed without re-opening. - * Example Synchronous read - * @code{c} - * // ADC Instance to open - * int32_t lAdcInstance = 0; - * - * // ADC Channel to read - * int32_t lAdcChannel = 0; - * - * // Declare and ADC handle - * IotAdcHandle_t xAdcHandle; - * - * // Return value of ADC functions - * int32_t lRetVal; - * - * // ADC value read - * uint16_t usSample; - * - * // Open the ADC instance and get a handle. - * xAdcHandle = iot_adc_open( lAdcInstance ); - * // assert(lRetVal == IOT_ADC_SUCCESS); - * - * // Read sample from ADC channel - * lRetVal = iot_adc_read_sample( xAdcHandle, lAdcChannel, &usSample); - * // assert(lRetVal == IOT_ADC_SUCCESS); - * - * // Close the ADC instance and get a handle. - * lRetVal = iot_adc_close( xAdcHandle ); - * // assert(lRetVal == IOT_ADC_SUCCESS); - * @endcode - * - */ -int32_t iot_adc_read_sample( IotAdcHandle_t const pxAdc, - uint8_t ucAdcChannel, - uint16_t * pusAdcSample ); - -/** - * @brief data structures for ioctl request - */ - -/** - * @brief data structure for ioctl SetAdcConfig and GetAdcConfig - */ -typedef struct IotAdcConfig_s -{ - uint32_t ulAdcSampleTime; /*!< Sample time in ADC clock cycles, apply to all channels. - *!< Shortest sample time maximize conversion speed for lower impedance input - *!< Extending sample time improve sample accuracy for higher impedance input. - *!< Sample time is reported as the closest possible value, rounded up, the hardware can support. */ - uint8_t ucAdcResolution; /*!< ADC channel resolution, reported as the closest possible value, rounded up. - *!< value = resolution bits; 12 = 12bit, 13 = 13bit, etc */ -} IotAdcConfig_t; - -typedef enum -{ - eChStateIdle, /*!< ADC channel is idle. */ - eChStateBusy, /*!< ADC channel is busy. */ -} IotAdcChState_t; - -/** - * @brief data structure for ioctl GetChStatus - */ -typedef struct IotAdcChStatus_s -{ - uint8_t ucAdcChannel; /*!< ADC Channel number */ - IotAdcChState_t xAdcChState; /*!< ADC Channel State */ -} IotAdcChStatus_t; - -/** - * @brief data structure for ioctl SetChBuffer - * setting channel data buffer is optional using this ioctl - * if client doesn't pass in data buffer for driver to use, callback is triggered - * for every ADC sample to pass data back to client as driver doesn't have buffer - * to accumulate data. As soon as callback returns, xConverted_Data becomes invalid. - * On the other hand however if client does pass a buffer for driver to use, - * callback is triggered only after driver has filled buffer with xBufLen samples, - * client buffer is passed back in callback as XConverted_Data whose life span is - * controlled by the client even after callback returns. - */ -typedef struct IotAdcChBuffer_s -{ - uint8_t ucAdcChannel; /*!< Adc Channel number */ - void * pvBuffer; /*!< Buffer to store adc results in */ - uint8_t ucBufLen; /*!< Max buffer length to write into pvBuffer */ -} IotAdcChBuffer_t; - -/** - * @brief Some ADC host controller supports grouping multiple ADC channels into a chain. - * When the chain is triggered to sample ADC data, all ADC channels in the group - * are sampled in sequence so that client doesn't need to trigger each channel - * individually. Converted ADC samples from such chain group can be passed back - * to the client with a single callback. - * This data structure is used for ioctl to define ADC chain setting. - */ -typedef struct IoTAdcChain_s -{ - uint8_t ucAdcChannel; /*!< logical ADC channel number as input to ioctl. It is recommended - *!< that client uses the first ADC channel number in the group as its - *!< logical number which client can use later to trigger group sampling */ - void * pvBuffer; /*!< data buffer used by driver to save converted sample data. - *!< The buffer is allocated by client and passed to driver to use. */ - uint8_t ucBufLen; /*!< Data buffer length, shall be large enough to hold group sample data. */ - uint16_t usChainMask; /*!< Define which ADC channels are in the chain group. - *!< e.g. 'x' bit set to 1 means ADC channel x is included in the group. - *!< Client shall manage potential ADC channel use conflict. */ -} IotAdcChain_t; - -/** - * @brief adc ioctl request types. - */ -typedef enum IotAdcIoctlRequest_s -{ - eSetAdcConfig, /*!< Set the ADC Configuration. Takes IotAdcConfig_t parameter. */ - eGetAdcConfig, /*!< Get the ADC Configuration. Returns results in IotAdcConfig_t parameter. */ - eGetChStatus, /*!< Get the Channel Status. Returns results in IotAdcChStatus_t parameter. */ - eSetChBuffer, /*!< Set the buffer for ADC values to be stored in. Takes IotAdcChBuffer_t parameter. */ - eSetAdcChain, /*!< ADC Chain for multiple ADC channels. Takes IotAdcChain_t parameter. */ -} IotAdcIoctlRequest_t; - -/** - * @brief Used for various ADC control functions. - * - * @param[in] pxAdc The ADC handle returned in the open() call. - * @param[in] xRequest ioctl request defined by IotAdcIoctlRequest_s enums. - * @param[in/out] pvBuffer data buffer for ioctl request. - * @param[in] pvBuffer size. - * - * @return - * - IOT_ADC_SCUCCESS on success - * - IOT_ADC_INVALID_VALUE, on NULL handle or invalid request or NULL or invalid buffer pointer - * - IOT_ADC_CH_BUSY if ADC operation not complete. - * - IOT_ADC_NOT_OPEN if ADC has been closed without re-opening. - * - IOT_ADC_FAILED if invalid ADC chain is requested. - * - IOT_ADC_FUNCTION_NOT_SUPPORTED only valid for eSetAdcChain, if feature is not supported. - */ -int32_t iot_adc_ioctl( IotAdcHandle_t const pxAdc, - IotAdcIoctlRequest_t xRequest, - void * const pvBuffer ); - -#endif /* _IOT_ADC_H_ */ diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/common_io/include/iot_battery.h b/bk7235/liteos_m/bk_sdk_armino/middleware/compal/common_io/include/iot_battery.h deleted file mode 100755 index 1a67d475109e56cc9c6b207a15b0b58f060572f3..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/common_io/include/iot_battery.h +++ /dev/null @@ -1,420 +0,0 @@ -/* - * FreeRTOS Common IO V0.1.3 - * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * http://aws.amazon.com/freertos - * http://www.FreeRTOS.org - */ - -/******************************************************************************* - * @file iot_battery.h - * - * @brief HAL APIs for Battery - ******************************************************************************* - */ - -/** - * @file iot_battery.h - * @brief This file contains all the Battery HAL API definitions. The APIs defined in this file - * helps with battery information and charging related functions. - */ - -#ifndef _IOT_BATTERY_H_ -#define _IOT_BATTERY_H_ - -/** - * @defgroup iot_battery BATTERY HAL APIs - * @{ - */ - -/** - * @brief Return values used by BATTERY driver - */ -#define IOT_BATTERY_SUCCESS ( 0 ) /*!< Battery operation completed successfully. */ -#define IOT_BATTERY_INVALID_VALUE ( 1 ) /*!< At least one parameter is invalid. */ -#define IOT_BATTERY_NOT_EXIST ( 2 ) /*!< No battery exists in this hardware. */ -#define IOT_BATTERY_READ_FAILED ( 3 ) /*!< Battery read operation failed. */ -#define IOT_BATTERY_FUNCTION_NOT_SUPPORTED ( 4 ) /*!< Battery operation not supported. */ - -/** - * @brief Battery Type - */ -typedef enum -{ - eBatteryChargeable, /*!< Re-chargeable batteries with charging enabled */ - eBatteryNotChargeable /*!< Not chargeable batteries */ -} IotBatteryType_t; - -/** - * @brief Charger type - */ -typedef enum -{ - eBatteryChargeNone, /*!< No Charge source, or non-chargeable battery */ - eBatteryChargeUSB, /*!< USB battery source */ - eBatteryChargePowerSupply, /*!< AC power supply source */ - erBatteryChargeWireless, /*!< Wireless charging source */ -} IotBatteryChargeSource_t; - -/** - * @brief Battery status - */ -typedef enum -{ - eBatteryCharging, /*!< Battery is Charging. Applicable only if the battery is chargeable */ - eBatteryDischarging, /*!< Battery is Discharging. This is the normal status of battery is no charger - * is connected */ - eBatteryNotCharging, /*!< Battery is not charging. This is set when charger is connected, but battery is not - * charging - usually an error condition */ - eBatteryChargeFull, /*!< Battery is fully charged. This status will be set only when the charger is connected - * and battery is fully charged */ - eBatteryChargeLow, /*!< Battery is low on charging and no charger connected. This status is set when battery - * is discharging and reaches a low cahrge value. Low charge value is defined by implementation */ - eBatteryOverVoltage, /*!< Battery maximum voltage limit reached. */ - eBatteryUnderVoltage, /*!< Battery low voltage limit reached. */ - eBatteryOverTemp, /*!< Battery maximum temperature limit reached. */ - eBatteryUnderTemp, /*!< Battery minimum temperature limit reached. */ - eBatteryOverChargingTemp, /*!< Battery maximum charging temperature limit reached. */ - eBatteryUnderhargingTemp, /*!< Battery minimum charging temperature limit reached. */ - eBatteryChargeTimeExpired, /*!< Battery charge timer expired. Charge timer can be set if the underlying hardware supports it using - * eSetBatteryChargeTimer IOCTL, and once the chargeTimer expires registered callback is called with this status set */ - eBatteryUnknown /*!< Unknown status. Default status if no battery is present */ -} IotBatteryStatus_t; - -/** - * @brief Battery information. - */ -typedef struct IotBatteryInfo -{ - IotBatteryType_t xBatteryType; /*!< Battery type. chargeable or non-chargeable */ - uint16_t usMinVoltage; /*!< minimum designed voltage battery can be used at */ - uint16_t usMaxVoltage; /*!< maximum designed voltage battery can be used at */ - int16_t sMinTemperature; /*!< lowest temperature the battery can be used at by design */ - int32_t lMaxTemperature; /*!< max temperature the battery can be used at by design */ - uint16_t usMaxCapacity; /*!< max capacity of battery by design */ - uint8_t ucAsyncSupported; /*!< Is asynchronous notifications supported by the driver. This will be - * set, if the battery/charging has an IC/battery and charging hw module that - * can atonomously monitor battery characterstics and generate interrupts */ -} IotBatteryInfo_t; - -/** - * @brief Ioctl request types. - */ -typedef enum IotBatteryIoctlRequest -{ - eSetBatteryMinVoltageThreshold, /*!< Set the battery minimum voltage threshold. When the voltage goes below this threshold - * value, the registered callback will be called with the status set to "eBatteryUnderVoltage". - * If battery management HW does not have a way to monitor voltage, this IOCTL will not be supported. - * Parameter is uint16_t value in milliVolt units. */ - eSetBatteryMaxVoltageThreshold, /*!< Set the battery mimimum voltage threshold. When the voltage goes below this threshold - * value, the registered callback will be called with the status set to "eBatteryOverVoltage". - * If battery management HW does not have a way to monitor voltage, this IOCTL will not be supported. - * Parameter is uint16_t value in milliVolt units. */ - eSetBatteryMinBatteryTempThreshold, /*!< Set the minimum battery temperature threshold. When the battery temperature goes below this value, - * the registered callback will be called with the status value "eBatteryUnderTemp". - * This IOCTL takes int16_t value as input in milliCelcius units. */ - eSetBatteryMaxBatteryTempThreshold, /*!< Set the maximum battery temperature threshold. When the battery temperature goes above this value, - * the registered callback will be called with the status value "eBatteryUnderTemp". - * This IOCTL takes int32_t value as input in milliCelcius units. */ - eSetBatteryMinChargeTempThreshold, /*!< Set the minimum charge temperature threshold. When the charging temperature goes below this value, - * the registered callback will be called with the status value "eBatteryUnderChargingTemp". - * This IOCTL takes int16_t value as input in milliCelcius units.*/ - eSetBatteryMaxChargeTempThreshold, /*!< Set the maximum charge temperature threshold. When the charging temperature goes above this value, - * the registered callback will be called with the status value "eBatteryOverChargingTemp". - * This IOCTL takes int32_t value as input in milliCelcius units. */ - eSetBatteryMaxOutputCurrent, /*!< Set the maximum output current limit from the battery. - * This IOCTL takes uint16_t value as input in milliAmp units. */ - eSetBatteryMaxInputChargeCurrent, /*!< Set the maximum input charging current limit to the battery. - * This IOCTL takes uint16_t value as input in milliAmp units. */ - eSetBatteryChargeTimer, /*!< Set the battery charging timer limit. AFter the timer expires charging will stop. - * This IOCTL takes uint32_t value as input in milliSec units. */ - eGetBatteryMinVoltageThreshold, /*!< Get the battery minimum thresold. - * This IOCTL returns uint16_t value in milliVolt units. */ - eGetBatteryMaxVoltageThreshold, /*!< Get the battery maximum thresold. - * This IOCTL returns uint16_t value in milliVolt units. */ - eGetBatteryOCV, /*!< Get the battery OCV (open circuit voltage) - * This IOCTL returns uint16_t value in milliVolt units. */ - eGetBatteryBootVoltage, /*!< Get the battery boot-up voltage - * This IOCTL returns uint16_t value in milliVolt units. */ - eGetBatteryMinBatteryTempThreshold, /*!< Get the minimum battery temperature thresholde - * This IOCTL returns int16_t value in milliCelcius units. */ - eGetBatteryMaxBatteryTempThreshold, /*!< Get the maximum battery temperature threshold. - * This IOCTL returns int32_t value in milliCelcius units. */ - eGetBatteryMinChargeTempThreshold, /*!< Get the minimum charging temperature threshold. - * This IOCTL returns int16_t value in milliCelcius units. */ - eGetBatteryMaxChargeTempThreshold, /*!< Get the maximum charging temperature threshold. - * This IOCTL returns int32_t value in milliCelcius units. */ - eGetBatteryMaxOutputCurrent, /*!< Get the battery output current limit. - * This IOCTL returns uint16_t value in milliAmp units. */ - eGetBatteryMaxInputChargeCurrent, /*!< Get the battery input charge current limit. - * This IOCTL returns uint16_t value in milliAmp units. */ - eGetBatteryChargeTimer, /*!< Get the current battery charge time limit. - * This IOCTL returns uint32_t value in milliSec units. */ - eGetBatteryChargeSource, /*!< Get the current battery charge source. - * This IOCTL returns a IotBatteryChargeSource_t as it's parameter. */ - eGetBatteryStatus /*!< Get the battery status. Returns one of the IotBatteryStatus_t values as it's parameter. */ -} IotBatteryIoctlRequest_t; - -/** - * @brief Battery descriptor type defined in the source file. - */ -struct IotBatteryDescriptor; - -/** - * @brief IotBatteryHandle_t type is the Battery handle returned by calling iot_battery_open() - * this is initialized in open and returned to caller. Caller must pass this pointer - * to the rest of the APIs. - */ -typedef struct IotBatteryDescriptor * IotBatteryHandle_t; - -/** - * @brief Battery notification callback type. This callback is passed - * to the driver by using iot_battery_set_callback API. The callback is - * used to get the notifications about battery status changes for ex: when charging starts, or - * when critical threshold is reached or when battery is full etc... - * The callback is only used if the driver supports the asynchronous notifications. The caller - * must get the batteryInfo to find if the asynchronous notifications are supported. - * On simiple underlying batteries, the caller/application must manage the battery conditions by - * periodically probing the battery using read APIs, and for sophisticated battery management service - * modules, these can be managed in the HW hence asyncrhonous notifications can be sent (using registered callback) - * - * @param[in] xStatus battery status from IotBatteryStatus_t - * @param[in] pvUserContext User Context passed when setting the callback. - * This is not used by the driver, but just passed back to the user - * in the callback. - */ -typedef void ( * IotBatteryCallback_t)( IotBatteryStatus_t xStatus, - void * pvUserContext ); - -/** - * @brief iot_battery_open is used to initialize the Battery and Charging driver. - * - * @param[in] lBatteryInstance The instance of the battery interface to initialize. - * Usually, there is only one battery interface. - * - * @return - * - handle to the Battery controller on success - * - NULL, if - * - invalid instance - * - open same instance more than once before closing it. - * - on failure. - */ -IotBatteryHandle_t iot_battery_open( int32_t lBatteryInstance ); - -/*! - * @brief iot_battery_set_callback is used to set the callback to be called when a notification - * needs to be sent to the caller. THe callback is only called if the battery supports async - * notifications. Caller must check isAsyncNotificationSupported value before registering - * for callbacks, if async is not supported, registering for callback has no affect, and the callback - * will never be called. - * - * @note Single callback is used for all features that support callback - * - eBatteryChargeTimeExpired, - * - eSetBatteryMinVoltageThreshold, eSetBatteryMaxVoltageThreshold, - * - eSetBatteryMinBatteryTempThreshold, eSetBatteryMaxBatteryTempThreshold, - * - eSetBatteryMinChargeTempThreshold, eSetBatteryMaxChargeTempThreshold, - * @note Newly set callback overrides the one previously set - * @note This callback is per handle. Each instance has its own callback. - * - * @warning If input handle or if callback function is NULL, this function silently takes no action. - * - * @param[in] pxBatteryHandle handle to Battery driver returned in - * iot_battery_open() - * @param[in] xCallback callback function to be called. - * @param[in] pvUserContext user context to be passed when callback is called. - * - */ -void iot_battery_set_callback( IotBatteryHandle_t const pxBatteryHandle, - IotBatteryCallback_t xCallback, - void * pvUserContext ); - -/*! - * @brief iot_battery_getInfo is used to get the battery info - * - * @param[in] pxBatteryHandle handle to Battery driver returned in - * iot_battery_open() - * - * @return - * - returns a pointer to the IotBatteryInfo structure on success - * - NULL on error - */ -IotBatteryInfo_t * iot_battery_getInfo( IotBatteryHandle_t const pxBatteryHandle ); - -/*! - * @brief iot_battery_current is used to get the battery current in mA. - * - * @param[in] pxBatteryHandle handle to Battery driver returned in - * iot_battery_open() - * @param[out] pusCurrent battery current value. - * - * @return - * - IOT_BATTERY_SUCCESS on success - * - IOT_BATTERY_INVALID_VALUE if pxBatteryHandle == NULL or pusCurrent == NULL - * - IOT_BATTERY_NOT_EXIST if no battery present. - * - IOT_BATTERY_READ_FAILED on error obtaining valid reading - * - IOT_BATTERY_FUNCTION_NOT_SUPPORTED if its not supported by the hardware. - */ -int32_t iot_battery_current( IotBatteryHandle_t const pxBatteryHandle, - uint16_t * pusCurrent ); - -/*! - * @brief iot_battery_voltage is used to get the battery voltage in milli-volts. - * - * @param[in] pxBatteryHandle handle to Battery driver returned in - * iot_battery_open() - * @param[out] pusVoltage battery voltage value. - * - * @return - * - IOT_BATTERY_SUCCESS on success - * - IOT_BATTERY_INVALID_VALUE if pxBatteryHandle == NULL or pusVoltage == NULL - * - IOT_BATTERY_NOT_EXIST if no battery in this hardware - * - IOT_BATTERY_READ_FAILED on error - * - IOT_BATTERY_FUNCTION_NOT_SUPPORTED if its not supported by the hardware. - */ -int32_t iot_battery_voltage( IotBatteryHandle_t const pxBatteryHandle, - uint16_t * pusVoltage ); - -/*! - * @brief iot_battery_chargeLevel is used to get the battery charging level in percentage (from 1 to 100). - * - * @param[in] pxBatteryHandle handle to Battery driver returned in - * iot_battery_open() - * @param[out] pucChargeLevel battery charging value. - * - * @return - * - IOT_BATTERY_SUCCESS on success - * - IOT_BATTERY_INVALID_VALUE if pxBatteryHandle == NULL or pusChargeLevel == NULL - * - IOT_BATTERY_NOT_EXIST if no battery in this hardware - * - IOT_BATTERY_READ_FAILED on error - * - IOT_BATTERY_FUNCTION_NOT_SUPPORTED if its not supported by the hardware. - */ -int32_t iot_battery_chargeLevel( IotBatteryHandle_t const pxBatteryHandle, - uint8_t * pucChargeLevel ); - - -/*! - * @brief iot_battery_capacity is used to get the current battery capacity value in mAh - * - * @param[in] pxBatteryHandle handle to Battery driver returned in - * iot_battery_open() - * @param[out] pusCapacity battery capacity value. - * - * @return - * - IOT_BATTERY_SUCCESS on success - * - IOT_BATTERY_INVALID_VALUE if pxBatteryHandle == NULL or pusCapacity == NULL - * - IOT_BATTERY_NOT_EXIST if no battery in this hardware - * - IOT_BATTERY_READ_FAILED on error - * - IOT_BATTERY_FUNCTION_NOT_SUPPORTED if its not supported by the hardware. - */ -int32_t iot_battery_capacity( IotBatteryHandle_t const pxBatteryHandle, - uint16_t * pusCapacity ); - -/*! - * @brief iot_battery_temp is used to get the battery temperature in milliCelcius - * - * @param[in] pxBatteryHandle handle to Battery driver returned in - * iot_battery_open() - * @param[out] plTemp battery temperature in milliCelcius - * - * @return - * - IOT_BATTERY_SUCCESS on success - * - IOT_BATTERY_INVALID_VALUE if pxBatteryHandle == NULL or psTemp == NULL - * - IOT_BATTERY_NOT_EXIST if no battery in this hardware - * - IOT_BATTERY_READ_FAILED on error - * - IOT_BATTERY_FUNCTION_NOT_SUPPORTED if its not supported by the hardware. - */ -int32_t iot_battery_temp( IotBatteryHandle_t const pxBatteryHandle, - int32_t * plTemp ); - -/*! - * @brief iot_battery_enable_charging is used to enable battery charging if charging is supported. - * if battery is already at full charge, enable will not charge battery until the charging level - * drops below 100, and even if battery is at critical level, and charging is not enabled, battery will - * not be charging. Charging is always enabled by default unless disabled by using this API. - * - * @param[in] pxBatteryHandle handle to Battery driver returned in - * iot_battery_open() - * @param[in] pucEnable Enable or Disable the charging of battery. set to 1 to enable, or 0 to disable. - * - * @return - * - IOT_BATTERY_SUCCESS on success - * - IOT_BATTERY_INVALID_VALUE if NULL handle or NULL voltage pointer - * - IOT_BATTERY_NOT_EXIST if no battery in this hardware - * - IOT_BATTERY_FUNCTION_NOT_SUPPORTED if its not supported by the hardware. - */ -int32_t iot_battery_enable_charging( IotBatteryHandle_t const pxBatteryHandle, - uint8_t * pucEnable ); - -/*! - * @brief iot_battery_is_charging is used to query if the battery is currently charging. - * - * @param[in] pxBatteryHandle handle to Battery driver returned in - * iot_battery_open() - * @param[out] pucCharging If charging this will contain value of 1 otherwise 0. - * - * @return - * - IOT_BATTERY_SUCCESS on success - * - IOT_BATTERY_INVALID_VALUE if pxBatteryHandle == NULL or pusCharging == NULL - * - IOT_BATTERY_NOT_EXIST if no battery in this hardware - * - IOT_BATTERY_FUNCTION_NOT_SUPPORTED if its not supported by the hardware. - */ -int32_t iot_battery_is_charging( IotBatteryHandle_t const pxBatteryHandle, - uint8_t * pucCharging ); - -/** - * @brief iot_battery_ioctl is used to set Battery configuration and - * Battery properties like battery threshold, temperature threshold, charging max, chargin min etc.. - * - * @param[in] pxBatteryHandle handle to Battery driver returned in - * iot_battery_open() - * @param[in] xRequest configuration request of type IotBatteryIoctlRequest_t - * @param[in,out] pvBuffer buffer holding Battery set and get values. - * - * @return - * - IOT_BATTERY_SUCCESS on success - * - IOT_BATTERY_INVALID_VALUE if - * - pxBatteryHandle == NULL - * - invalid xRequest - * - pvBuffer == NULL when required - * - IOT_BATTERY_NOT_EXIST if no battery in this hardware - * - IOT_BATTERY_FUNCTION_NOT_SUPPORTED valid for any ioctl if its not supported by the hardware. - */ -int32_t iot_battery_ioctl( IotBatteryHandle_t const pxBatteryHandle, - IotBatteryIoctlRequest_t xRequest, - void * const pvBuffer ); - -/** - * @brief iot_battery_close is used to de-Initialize Battery driver. - * - * @param[in] pxBatteryHandle handle to Battery interface. - * - * @return - * - IOT_BATTERY_SUCCESS on success - * - IOT_BATTERY_INVALID_VALUE if - * - pxBatteryHandle == NULL - * - if is not in open state (already closed). - */ -int32_t iot_battery_close( IotBatteryHandle_t const pxBatteryHandle ); - -/** - * @} - */ - -#endif /* ifndef _IOT_BATTERY_H_ */ diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/common_io/include/iot_board_gpio.h b/bk7235/liteos_m/bk_sdk_armino/middleware/compal/common_io/include/iot_board_gpio.h deleted file mode 100755 index 49b5a0884726835117a71862118eb86b4da9c18d..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/common_io/include/iot_board_gpio.h +++ /dev/null @@ -1,101 +0,0 @@ -// Copyright 2020 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at - -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#ifndef _BOARD_GPIO_H_ -#define _BOARD_GPIO_H_ - -#include "driver/gpio.h" - -#define ESP_GPIO_PORTS ( 2 ) -#define ESP_GPIO_PORT0 ( 0 ) -#define ESP_GPIO_PORT1 ( 1 ) -#define ESP_GPIO_PORT2 ( 2 ) - -#define ESP_MAX_UART_PORTS 3 -#define ESP_MAX_I2C_PORTS 2 -#define ESP_MAX_LED_NUM 3 -#define ESP_MAX_PWM_CHANNELS 3 /*Should be less then LEDC_CHANNEL_MAX(0-7)*/ -#define ESP_MAX_SPI_PORTS 2 - -struct esp_uart_pin_config { - uint8_t txd_pin; - uint8_t rxd_pin; -}; - -struct esp_i2c_pin_config { - uint8_t scl_pin; - uint8_t sda_pin; -}; - -struct esp_led_pin_config { - uint8_t led_num; -}; - -struct esp_pwm_pin_config { - uint8_t pwm_num; -}; - -struct esp_spi_pin_config { - uint8_t mosi_pin; - uint8_t miso_pin; - uint8_t clk_pin; - uint8_t cs_pin; -}; - -/* Configuration to be assigned internally for UART to pin mappings */ -#define ESP_UART_PIN_MAP { \ - /* UART 0 */ \ - { GPIO_NUM_1, GPIO_NUM_3 }, \ - /* UART 1: this ACK team's preference */ \ - { GPIO_NUM_19, GPIO_NUM_20 }, \ - /* UART 2 */ \ - { GPIO_NUM_17, GPIO_NUM_16 }, \ -} - -/* Configuration to be assigned internally for I2C to pin mappings */ -#define ESP_I2C_PIN_MAP { \ - /* I2C 0 */ \ - { GPIO_NUM_26, GPIO_NUM_27 }, \ - /* I2C 1 */ \ - { GPIO_NUM_19, GPIO_NUM_21 }, \ -} - -/* Configuration to be assigned internally for LED to pin mappings */ -#define ESP_LED_PIN_MAP { \ - {GPIO_NUM_10}, \ - {GPIO_NUM_11}, \ - {GPIO_NUM_12}, \ -} - -/* Configuration to be assigned internally for PWM to pin mappings */ -#define ESP_PWM_PIN_MAP { \ - {GPIO_NUM_5}, \ - {GPIO_NUM_0}, \ - {GPIO_NUM_27}, \ -} - -/* Configuration to be assigned internally for SPI to pin mappings */ -#define ESP_SPI_PIN_MAP { \ - /* SPI 1: MOSI, MISO, CLK, CS */ \ - { GPIO_NUM_12, GPIO_NUM_13, GPIO_NUM_14, GPIO_NUM_15 }, \ - /* SPI 2 */ \ - { GPIO_NUM_12, GPIO_NUM_13, GPIO_NUM_14, GPIO_NUM_15 }, \ -} - -/* define GPIO ports used for AFQP test */ -#define aws_hal_GPIO_TEST_PORT_A ( 3 ) -#define aws_hal_GPIO_TEST_PORT_B ( 4 ) - -#endif /* _BOARD_GPIO_H_ */ - diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/common_io/include/iot_efuse.h b/bk7235/liteos_m/bk_sdk_armino/middleware/compal/common_io/include/iot_efuse.h deleted file mode 100755 index 4606f92e16f2869ea2f6995a9ffce68569559f66..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/common_io/include/iot_efuse.h +++ /dev/null @@ -1,160 +0,0 @@ -/* - * FreeRTOS Common IO V0.1.3 - * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * http://aws.amazon.com/freertos - * http://www.FreeRTOS.org - */ - -/** - * @file iot_efuse.h - * @brief File for the APIs of efuse called by application layer. - */ -#ifndef _IOT_EFUSE_H_ -#define _IOT_EFUSE_H_ - -/** - * @defgroup iot_efuse EFUSE Abstraction APIs. - * @{ - */ - -/** - * The return codes for the functions in EFUSE. - */ -#define IOT_EFUSE_SUCCESS ( 0 ) /*!< Efuse operation completed successfully. */ -#define IOT_EFUSE_INVALID_VALUE ( 1 ) /*!< At least one parameter is invalid. */ -#define IOT_EFUSE_READ_FAIL ( 2 ) /*!< Error reading Efuse value. */ -#define IOT_EFUSE_WRITE_FAIL ( 3 ) /*!< Error writing Efuse value. */ -#define IOT_EFUSE_CLOSE_FAIL ( 4 ) /*!< Error closing Efuse instance. */ -#define IOT_EFUSE_FUNCTION_NOT_SUPPORTED ( 5 ) /*!< Efuse operation not supported. */ -#define IOT_EFUSE_ERROR ( 6 ) /*!< Error performing Efuse operation. */ - -/** - * @brief The Efuse descriptor type defined in the source file. - */ -struct IotEfuseDescriptor; - -/** - * @brief IotEfuseHandle_t is the handle type returned by calling iot_efuse_open(). - * This is initialized in open and returned to caller. The caller must pass - * this pointer to the rest of APIs. - */ -typedef struct IotEfuseDescriptor * IotEfuseHandle_t; - -/** - * @brief iot_efuse_open is used to Initialize things needed to access efuse. - * - * @return - * - Handle to IotEfuseHandle_t on success - * - NULL if the handle is already opened. handle must be closed before calling open again - */ -IotEfuseHandle_t iot_efuse_open( void ); - -/** - * @brief iot_efuse_close is used to de Initialize things needed to disable efuse access. - * - * @param[in] pxEfuseHandle handle to efuse interface returned in iot_efuse_open() - * - * @return - * - IOT_EFUSE_SUCCESS if succeeded, - * - IOT_EFUSE_INVALID_VALUE on NULL pxEfuseHandle - * - IOT_EFUSE_INVALID_VALUE if instance not previously opened. - * - IOT_EFUSE_CLOSE_FAIL if the underneath HW deinit api returns fail. - */ -int32_t iot_efuse_close( IotEfuseHandle_t const pxEfuseHandle ); - -/** - * @brief Read 32-bit efuse word from specified index. - * - * @param[in] pxEfuseHandle handle to efuse interface returned in iot_efuse_open() - * @param[in] ulIndex index of efuse word to read. Caller must know the underlying - * efuse mechanism and make sure index is a valid one. - * @param[out] ulValue The receive buffer to read the data into - * - * @return - * - IOT_EFUSE_SUCCESS if read succeeded, - * - IOT_EFUSE_READ_FAIL if read failed, - * - IOT_EFUSE_INVALID_VALUE if pxEfuseHandle is NULL, index is invalid, or ulValue is NULL. - * - IOT_EFUSE_FUNCTION_NOT_SUPPORTED if 32-bit efuse word is not supported - */ -int32_t iot_efuse_read_32bit_word( IotEfuseHandle_t const pxEfuseHandle, - uint32_t ulIndex, - uint32_t * ulValue ); - -/** - * @brief Write 32-bit value to the 32-bit efuse word at specified index. - * - * @param[in] pxEfuseHandle handle to efuse interface returned in iot_efuse_open() - * @param[in] ulIndex index of efuse word to write to. Caller must know the underlying - * efuse mechanism and make sure index is a valid one. - * @param[in] ulValue The 32-bit value to write. - * - * @return - * - IOT_EFUSE_SUCCESS if write succeeded, - * - IOT_EFUSE_WRITE_FAIL if write failed - * - IOT_EFUSE_INVALID_VALUE if pxEfuseHandle is NULL, or index is invalid. - * - IOT_EFUSE_FUNCTION_NOT_SUPPORTED if 32-bit efuse word is not supported - */ -int32_t iot_efuse_write_32bit_word( IotEfuseHandle_t const pxEfuseHandle, - uint32_t ulIndex, - uint32_t ulValue ); - -/** - * @brief Read 16-bit efuse word from specified index. - * - * @param[in] pxEfuseHandle handle to efuse interface returned in iot_efuse_open() - * @param[in] ulIndex index of efuse word to read. Caller must know the underlying - * efuse mechanism and make sure index is a valid one. - * @param[out] ulValue The receive buffer to read the data into - * - * @return - * - IOT_EFUSE_SUCCESS if read succeeded, - * - IOT_EFUSE_READ_FAIL if read failed - * - IOT_EFUSE_INVALID_VALUE if pxEfuseHandle or ulValue is NULL, or index is invalid - * - IOT_EFUSE_FUNCTION_NOT_SUPPORTED if 16-bit efuse word is not supported - */ -int32_t iot_efuse_read_16bit_word( IotEfuseHandle_t const pxEfuseHandle, - uint32_t ulIndex, - uint16_t * ulValue ); - -/** - * @brief Write 16-bit value to the 16-bit efuse word at specified index. - * - * @param[in] pxEfuseHandle handle to efuse interface returned in iot_efuse_open() - * @param[in] ulIndex index of efuse word to write to. Caller must know the underlying - * efuse mechanism and make sure index is a valid one. - * @param[in] ulValue The 16-bit value to write. - * - * @return - * - IOT_EFUSE_SUCCESS if write succeeded, - * - IOT_EFUSE_WRITE_FAIL if write failed - * - IOT_EFUSE_INVALID_VALUE if index is invalid, or pxEfuseHandle is NULL. - * - IOT_EFUSE_FUNCTION_NOT_SUPPORTED if 16-bit efuse word is not supported - */ -int32_t iot_efuse_write_16bit_word( IotEfuseHandle_t const pxEfuseHandle, - uint32_t ulIndex, - uint16_t value ); - -/** - * @} - */ -/* end of group iot_efuse */ - -#endif /* ifndef _IOT_EFUSE_H_ */ diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/common_io/include/iot_flash.h b/bk7235/liteos_m/bk_sdk_armino/middleware/compal/common_io/include/iot_flash.h deleted file mode 100755 index 02734dabe6a128c52c42ebd889afc93ba35bf75c..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/common_io/include/iot_flash.h +++ /dev/null @@ -1,437 +0,0 @@ -/* - * FreeRTOS Common IO V0.1.3 - * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * http://aws.amazon.com/freertos - * http://www.FreeRTOS.org - */ - -/** - * @file iot_flash.h - * @brief This file contains all the Flash HAL API definitions - */ - -#ifndef _IOT_FLASH_H_ -#define _IOT_FLASH_H_ - -/** - * @defgroup iot_flash Flash HAL APIs - * @{ - */ - -/** - * @brief Return values used by this driver - */ -#define IOT_FLASH_SUCCESS ( 0 ) /*!< Flash operation completed succesfully. */ -#define IOT_FLASH_INVALID_VALUE ( 1 ) /*!< At least one parameter is invalid. */ -#define IOT_FLASH_WRITE_FAILED ( 2 ) /*!< Flash write operation failed. */ -#define IOT_FLASH_READ_FAILED ( 3 ) /*!< Flash read operation failed. */ -#define IOT_FLASH_ERASE_FAILED ( 4 ) /*!< Flash erase operation failed. */ -#define IOT_FLASH_DEVICE_BUSY ( 5 ) /*!< Previous flash operation not complete yet. */ -#define IOT_FLASH_CTRL_OP_FAILED ( 6 ) /*!< Flash control operation failed. */ -#define IOT_FLASH_FUNCTION_NOT_SUPPORTED ( 7 ) /*!< Flash operation not supported. */ - -/** - * @brief Flash current status - */ -typedef enum -{ - eFlashIdle, /*!< Flash is idle. */ - eFlashCmdInProgress, /*!< Flash command in progress. */ - eFlashEraseFailed, /*!< Flash erase failed. */ - eFlashProgramSuspended, /*!< Flash program operation suspended. */ - eFlashEraseSuspended /*Example - * @code{c} - * IotFlashHandle_t xFlashHandle; - * IotFlashInfo_t* pxFlashInfo; - * int32_t lRetVal; - * uint32_t ulChunkOffset; - * - * // Open flash to initialize hardware. - * xFlashHandle = iot_flash_open(0); - * // assert(xFlashHandle == NULL ); - * - * // Get the flash information. - * pxFlashInfo = iot_flash_getinfo(xFlashHandle); - * // assert(pxFlashInfo == NULL); - * - * // If Erase asyc is supported, register a callback - * if ( pxFlashInfo->ucAsyncSupported ) - * { - * iot_flash_set_callback(xFlashHandle, - * prvIotFlashEraseCallback, - * NULL); - * } - * - * // Erase 2 sectors - * lRetVal = iot_flash_erase_sectors(xFlashHandle, - * ultestIotFlashStartOffset, - * pxFlashInfo->ulSectorSize * 2); - * //assert(IOT_FLASH_SUCCESS != lRetVal); - * - * if ( pxFlashInfo->ucAsyncSupported ) - * { - * // Wait for the Erase to be completed and callback is called. - * lRetVal = xSemaphoreTake(xtestIotFlashSemaphore, portMAX_DELAY); - * //assert(pdTRUE != lRetVal); - * } - * - * // Close the flash handle. - * lRetVal = iot_flash_close(xFlashHandle); - * //assert(IOT_FLASH_SUCCESS != lRetVal); - * - * @endcode - */ -int32_t iot_flash_erase_sectors( IotFlashHandle_t const pxFlashHandle, - uint32_t ulStartAddress, - size_t xSize ); - -/*! - * @brief iot_erase_chip is used to erase the entire flash chip. - * If there is another flash operation is in progress, the erase_chip API will return an error. - * - * @param[in] pxFlashHandle handle to flash driver returned in - * iot_flash_open() - * - * @return - * - IOT_FLASH_SUCCESS on success. - * - IOT_FLASH_INVALID_VALUE if any parameter is invalid. - * - IOT_FLASH_DEVICE_BUSY if another asynchronous operation is currently being executed. - * - IOT_FLASH_ERASE_FAILED on error. - */ -int32_t iot_flash_erase_chip( IotFlashHandle_t const pxFlashHandle ); - -/*! - * @brief iot_flash_write_sync is used to write data to flash starting at the address provided. - * The sector(s) being written to, must be erased first before any write can take place. - * This is a blocking operation and waits until the number of bytes are written before returning. - * If there is another flash operation is in progress, write will return an error. - * - * @warning writing to a sector that was not erased first, may result in incorrect data being written while - * the API returns IOT_FLASH_SUCCESS. - * - * @param[in] pxFlashHandle handle to flash driver returned in - * iot_flash_open() - * @param[in] ulAddress starting address(offset) in flash to write. - * @param[in] xBytes number of bytes to write. - * @param[in] pvBuffer data buffer to write to flash - * - * @return - * - IOT_FLASH_SUCCESS on success. - * - IOT_FLASH_INVALID_VALUE if any parameter is invalid. - * - IOT_FLASH_DEVICE_BUSY if another asynchronous operation is currently being executed. - * - IOT_FLASH_WRITE_FAILED on error. - */ -int32_t iot_flash_write_sync( IotFlashHandle_t const pxFlashHandle, - uint32_t ulAddress, - uint8_t * const pvBuffer, - size_t xBytes ); - -/*! - * @brief iot_flash_read_sync is used to read data from flash. This is a blocking operation - * and waits until the number of bytes are read before returning. - * If there is another flash operation is in progress, this will return an error. - * - * @param[in] pxFlashHandle handle to flash driver returned in - * iot_flash_open() - * @param[in] ulAddress starting address(offset) in flash to read. - * @param[in] xBytes number of bytes to be read. - * @param[out] pvBuffer data buffer to hold the data read from flash - * - * @return - * - IOT_FLASH_SUCCESS on success. - * - IOT_FLASH_INVALID_VALUE if any parameter is invalid. - * - IOT_FLASH_DEVICE_BUSY if another asynchronous operation is currently being executed. - * - IOT_FLASH_READ_FAILED on error. - */ -int32_t iot_flash_read_sync( IotFlashHandle_t const pxFlashHandle, - uint32_t ulAddress, - uint8_t * const pvBuffer, - size_t xBytes ); - -/*! - * @brief iot_flash_write_async is used to write data to flash starting at the address provided. - * The sector(s) being written to, must be erased first before any write can take place. - * This is an asynchronous (non-blocking) operation and returns as soon as the write - * operation is started. When the write is completed, user callback is called to - * notify that the write is complete. The caller can check the status of the operation - * by using eGetStatus IOCTL. User must register for a callback when using the non-blocking - * operations to know when they are complete. - * If there is another flash operation is in progress, write will return an error. - * - * @param[in] pxFlashHandle handle to flash driver returned in - * iot_flash_open() - * @param[in] ulAddress starting address(offset) in flash to write. - * @param[in] xBytes number of bytes to write. - * @param[in] pvBuffer data buffer to write to flash - * - * @return - * - IOT_FLASH_SUCCESS on success. - * - IOT_FLASH_INVALID_VALUE if any parameter is invalid. - * - IOT_FLASH_DEVICE_BUSY if another asynchronous operation is currently being executed. - * - IOT_FLASH_WRITE_FAILED on error. - * - IOT_FLASH_FUNCTION_NOT_SUPPORTED if asynchronous operation is not supported - * (i,e ucAsyncSupported is set to false) - */ -int32_t iot_flash_write_async( IotFlashHandle_t const pxFlashHandle, - uint32_t ulAddress, - uint8_t * const pvBuffer, - size_t xBytes ); - -/*! - * @brief iot_flash_read_async is used to read data from flash. - * This is an asynchronous (non-blocking) operation and returns as soon as the read - * operation is started. When the read is completed, user callback is called to - * notify that the read is complete. The caller can check the status of the operation - * by using eGetStatus IOCTL and use the buffer. User must register for a callback when - * using the non-blocking operations to know when they are complete. - * If there is another flash operation is in progress, this will return an error. - * - * @param[in] pxFlashHandle handle to flash driver returned in - * iot_flash_open() - * @param[in] ulAddress starting address(offset) in flash to read. - * @param[in] xBytes number of bytes to be read. - * @param[out] pvBuffer data buffer to hold the data read from flash - * - * @return - * - IOT_FLASH_SUCCESS on success. - * - IOT_FLASH_INVALID_VALUE if any parameter is invalid. - * - IOT_FLASH_DEVICE_BUSY if another asynchronous operation is currently being executed. - * - IOT_FLASH_READ_FAILED on error. - * - IOT_FLASH_FUNCTION_NOT_SUPPORTED if asynchronous operation is not supported - * (i,e ucAsyncSupported is set to false) - */ -int32_t iot_flash_read_async( IotFlashHandle_t const pxFlashHandle, - uint32_t ulAddress, - uint8_t * const pvBuffer, - size_t xBytes ); - -/*! - * @brief iot_flash_close is used to close the flash device. - * If any operations are in progress when close is called, - * flash driver aborts those if possible. - * - * @param[in] pxFlashHandle handle to flash driver returned in - * iot_flash_open() - * - * @return - * - IOT_FLASH_SUCCESS on success close - * - IOT_FLASH_INVALID_VALUE on invalid pxFlashHandle. - */ -int32_t iot_flash_close( IotFlashHandle_t const pxFlashHandle ); - -/** - * @} - */ - -#endif /* ifndef _IOT_FLASH_H_ */ diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/common_io/include/iot_gpio.h b/bk7235/liteos_m/bk_sdk_armino/middleware/compal/common_io/include/iot_gpio.h deleted file mode 100755 index 04f16cea764193e3ca8fb31453257bb79f94732a..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/common_io/include/iot_gpio.h +++ /dev/null @@ -1,243 +0,0 @@ -/* - * FreeRTOS Common IO V0.1.3 - * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * http://aws.amazon.com/freertos - * http://www.FreeRTOS.org - */ - -/** - * @file iot_gpio.h - * @brief This file contains all the GPIO HAL API definitions. - * This GPIO interface APIs only provides pin-level functions. To modify a GPIO pin, a handle must be obtained - * by calling the iot_gpio_open() function. This handle must be passed to other functions in this interface. - * Handling multiple GPIOs simultaneously in the same bank or different banks is outside of the scope of this file. - * User can modify multiple pins sequentially using this interface by iterating over multiple GPIOs in a loop. - */ - -#ifndef _IOT_GPIO_H_ -#define _IOT_GPIO_H_ - -/** - * @defgroup iot_gpio GPIO HAL APIs - * @{ - */ - -/** - * @brief Error codes - */ -#define IOT_GPIO_SUCCESS ( 0 ) /*!< GPIO operation completed succesfully. */ -#define IOT_GPIO_INVALID_VALUE ( 1 ) /*!< At least one parameter is invalid. */ -#define IOT_GPIO_READ_FAILED ( 2 ) /*!< GPIO read operation failed. */ -#define IOT_GPIO_WRITE_FAILED ( 3 ) /*!< GPIO write operation failed. */ -#define IOT_GPIO_FUNCTION_NOT_SUPPORTED ( 4 ) /*!< GPIO operation not supported. */ - -/** - * @brief enum for configuring GPIO input/output direction. - */ -typedef enum -{ - eGpioDirectionInput, /*!< Configure GPIO pin direction for input. */ - eGpioDirectionOutput /*!< Configure GPIO pin direction for output. */ -} IotGpioDirection_t; - -/** - * @brief enum for configuring GPIO output type. - */ -typedef enum -{ - eGpioOpenDrain, /*!< Configure GPIO pin mode as open drain. */ - eGpioPushPull /*!< Configure GPIO pin mode as push pull. */ -} IotGpioOutputMode_t; - -/** - * @brief GPIO pin internal pull state. Sets the default state for output pins. - */ -typedef enum -{ - eGpioPullNone, /*!< Configure GPIO pin with no pull direction. */ - eGpioPullUp, /*!< Configure GPIO pin as pull up. */ - eGpioPullDown /*!< Configure GPIO pin as pull down. */ -} IotGpioPull_t; - -/** - * @brief GPIO pin interrupt config types. - */ -typedef enum -{ - eGpioInterruptNone, /*!< Configure GPIO pin to not generate an interrupt. */ - eGpioInterruptRising, /*!< Configure GPIO pin to generate an interrupt when signal rises. */ - eGpioInterruptFalling, /*!< Configure GPIO pin to generate an interrupt when signal falls. */ - eGpioInterruptEdge, /*!< Configure GPIO pin to generate an interrupt when either rising or falling. */ - eGpioInterruptLow, /*!< Configure GPIO pin to generate an interrupt when signal is low. */ - eGpioInterruptHigh, /*!< Configure GPIO pin to generate an interrupt when signal is high. */ -} IotGpioInterrupt_t; - -/** - * @brief Ioctl request types. - */ -typedef enum -{ - eSetGpioFunction, /*!< Set GPIO function. Takes int32_t as input to set the alternate function. - * The value of the alternate function depends on the HW */ - eSetGpioDirection, /*!< Set GPIO Direction. Takes input type IotGpioDirection_t */ - eSetGpioPull, /*!< Set GPIO Pull mode. Takes input type IotGpioPull_t */ - eSetGpioOutputMode, /*!< Set GPIO output type. Takes input type IotGpioOutputType_t */ - eSetGpioInterrupt, /*!< Set GPIO Interrupt type. This configures the GPIO to generate an interrupt based on the configuration. - * Takes input type IotGpioInterrupt_t */ - eSetGpioSpeed, /*!< Set GPIO Speed. Takes a int32_t value based on the underlying HW support */ - eSetGpioDriveStrength, /*!< Set GPIO Drive Strength. Takes an int32_t value based on the underlying HW support */ - eGetGpioFunction, /*!< Get GPIO function setting. Returns an int32_t */ - eGetGpioDirection, /*!< Get GPIO Direction setting. Returns IotGpioDirection_t */ - eGetGpioPull, /*!< Get GPIO Pull mode setting. Returns IotGpioPull_t */ - eGetGpioOutputType, /*!< Get GPIO output type. Returns IotGpioOutputType_t */ - eGetGpioInterrupt, /*!< Get GPIO Interrupt config. Returns IotGpioInterrupt_t type */ - eGetGpioSpeed, /*!< Get GPIO Speed setting. Returns an int32_t type */ - eGetGpioDriveStrength /*!< Get GPIO Drive Strength. Returns int32_t type */ -} IotGpioIoctlRequest_t; - -/** - * @brief GPIO descriptor type defined in the source file. - */ -struct IotGpioDescriptor; - -/** - * @brief IotGpioHandle_t type is the GPIO handle returned by calling iot_gpio_open() - * this is initialized in open and returned to caller. Caller must pass this pointer - * to the rest of the APIs. - */ -typedef struct IotGpioDescriptor * IotGpioHandle_t; - -/** - * @brief GPIO interrupt callback type. This callback is passed - * to the driver by using iot_gpio_set_callback API. - * @param[out] ucPinState The variable which has state of the GPIO pin. - * @param[in] pvUserContext User Context passed when setting the callback. - * This is not used by the driver, but just passed back to the user - * in the callback. - */ -typedef void ( * IotGpioCallback_t )( uint8_t ucPinState, - void * pvUserContext ); - -/** - * @brief iot_gpio_open is used to open the GPIO handle. - * The application must call this function to open desired GPIO and use other functions. - * - * @param[in] lGpioNumber The logical GPIO number to open. It depends on the - * implementation to map logical GPIO number to physical GPIO port - * and pin. - * - * @return - * - handle to the GPIO peripheral if everything succeeds - * - NULL, if - * - invalid instance number - * - open same instance more than once before closing it. - */ -IotGpioHandle_t iot_gpio_open( int32_t lGpioNumber ); - -/** - * @brief iot_gpio_set_callback is used to set the callback to be called when an - * interrupt is tirggered. - * - * @note Single callback is used for both read_async and write_async. Newly set callback overrides the one previously set - * @note This callback will not be invoked when synchronous operation completes. - * @note This callback is per handle. Each instance has its own callback. - * - * @warning If input handle or if callback function is NULL, this function silently takes no action. - * - * @param[in] pxGpio The GPIO handle returned in the open() call. - * @param[in] xGpioCallback The callback function to be called on interrupt. - * @param[in] pvUserContext The user context to be passed back when callback is called. - */ -void iot_gpio_set_callback( IotGpioHandle_t const pxGpio, - IotGpioCallback_t xGpioCallback, - void * pvUserContext ); - -/** - * @brief iot_gpio_read_sync is used to read data from GPIO pin in blocking mode. - * - * @param[in] pxGpio The GPIO handle returned in the open() call. - * @param[out] pucPinState The variable which reads state of the GPIO pin. - * - * @return - * - IOT_GPIO_SUCCESS on success - * - IOT_GPIO_INVALID_VALUE if pxGpio or pucPinState are NULL - * - IOT_GPIO_READ_FAILED on failure. - * - */ -int32_t iot_gpio_read_sync( IotGpioHandle_t const pxGpio, - uint8_t * pucPinState ); - -/** - * @brief iot_gpio_write_sync is used to write data into the GPIO pin in blocking mode. - * - * @param[in] pxGpio The GPIO handle returned in the open() call. - * @param[in] ucState The value to write into the GPIO pin. - * - * @return - * - IOT_GPIO_SUCCESS on success - * - IOT_GPIO_INVALID_VALUE if pxGpio or pucPinState are NULL - * - IOT_GPIO_WRITE_FAILED on failure. - */ -int32_t iot_gpio_write_sync( IotGpioHandle_t const pxGpio, - uint8_t ucPinState ); - -/** - * @brief iot_gpio_close is used to deinitializes the GPIO pin to default value and close the handle. - * The application should call this function to reset and deinitialize the GPIO pin. - * - * @param[in] pxGpio The GPIO handle returned in the open() call. - * - * @return - * - IOT_GPIO_SUCCESS on success - * - IOT_GPIO_INVALID_VALUE if - * - pxGpio handle is NULL - * - if is not in open state (already closed). - */ -int32_t iot_gpio_close( IotGpioHandle_t const pxGpio ); - -/** - * @brief iot_gpio_ioctl is used to configure GPIO pin options. - * The application should call this function to configure various GPIO - * pin options: pin function, I/O direction, pin internal pull mode, - * drive strength, slew rate etc - * - * @param[in] pxGpio The GPIO handle returned in the open() call. - * @param[in] xRequest One of IotGpioIoctlRequest_t enum - * @param[in/out] pvBuffer Buffer holding GPIO set or get values. - * - * @return - * - IOT_GPIO_SUCCESS on success - * - IOT_GPIO_INVALID_VALUE on NULL handle, invalid request, or NULL buffer when required. - * - IOT_GPIO_FUNCTION_NOT_SUPPORTED is only valid for - * - eSetGpioFunction / eGetGpioFunction - * - eSetGpioSpeed / eGetGpioSpeed - * - eSetGpioDriveStrength / eGetGpioDriveStrength - * - eSetGpioInterrupt / eGetGpioInterrupt - */ -int32_t iot_gpio_ioctl( IotGpioHandle_t const pxGpio, - IotGpioIoctlRequest_t xRequest, - void * const pvBuffer ); - -/** - * @} - */ - -#endif /* _IOT_GPIO_H_ */ diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/common_io/include/iot_hw.h b/bk7235/liteos_m/bk_sdk_armino/middleware/compal/common_io/include/iot_hw.h deleted file mode 100755 index 0c28abe7444e64b0bdff24b9a70deb584a2a4385..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/common_io/include/iot_hw.h +++ /dev/null @@ -1,63 +0,0 @@ -/* - * FreeRTOS Common IO V0.1.3 - * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * http://aws.amazon.com/freertos - * http://www.FreeRTOS.org - */ - -/** - * @file iot_hw.h - * @brief Define common APIs to get hardware ID and hardware revision. - */ -#ifndef _IOT_HW_H_ -#define _IOT_HW_H_ - -/** - * @brief Error code returned by platform - * - * We assume that neither hardware ID nor hardware revision number will ever be greater than 255 - * it means that API is not implemented or supported if API returns 0xFF - */ -#define IOT_HW_UNSUPPORTED ( 0xFFFF ) - -/** - * @brief API to read hardware ID. - * - * @note: the format and contents of this field are specific - * to each vendor. With the expectation that they will - * be unique for each board. - * - * @return hardware ID number as unsigned byte - */ -uint16_t iot_hw_get_id( void ); - -/** - * @brief API to read hardware revision. - * - * @note: the format and contents of this field are specific - * to each vendor. With the expectation that they will - * be unique for each revision. - * - * @return hardware revision number as unsigned byte - */ -uint16_t iot_hw_get_rev( void ); - -#endif /* _IOT_HW_H_ */ diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/common_io/include/iot_i2c.h b/bk7235/liteos_m/bk_sdk_armino/middleware/compal/common_io/include/iot_i2c.h deleted file mode 100755 index b485ed007238e249f45f7af04fc3965e96dbb0ee..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/common_io/include/iot_i2c.h +++ /dev/null @@ -1,479 +0,0 @@ -/* - * FreeRTOS Common IO V0.1.3 - * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * http://aws.amazon.com/freertos - * http://www.FreeRTOS.org - */ - -/** - * @file iot_i2c.h - * @brief File for the APIs of I2C called by application layer. - */ -#ifndef _IOT_I2C_H_ -#define _IOT_I2C_H_ - -/* Standard includes. */ -#include -#include - -/** - * @defgroup iot_i2c I2C Abstraction APIs. - * @{ - */ - -/** - * The speeds supported by I2C bus. - */ -#define IOT_I2C_STANDARD_MODE_BPS ( 100000 ) /*!< Standard mode bits per second. */ -#define IOT_I2C_FAST_MODE_BPS ( 400000 ) /*!< Fast mode bits per second. */ -#define IOT_I2C_FAST_MODE_PLUS_BPS ( 1000000 ) /*!< Fast plus mode bits per second. */ -#define IOT_I2C_HIGH_SPEED_BPS ( 3400000 ) /*!< High speed mode bits per second. */ - -/** - * The return codes for the functions in I2C. - */ -#define IOT_I2C_SUCCESS ( 0 ) /*!< I2C operation completed successfully. */ -#define IOT_I2C_INVALID_VALUE ( 1 ) /*!< At least one parameter is invalid. */ -#define IOT_I2C_BUSY ( 2 ) /*!< I2C bus is busy at current time. */ -#define IOT_I2C_WRITE_FAILED ( 3 ) /*!< I2C driver returns error when performing write operation. */ -#define IOT_I2C_READ_FAILED ( 4 ) /*!< I2C driver returns error when performing read operation. */ -#define IOT_I2C_NACK ( 5 ) /*!< Unexpected NACK is caught. */ -#define IOT_I2C_BUS_TIMEOUT ( 6 ) /*!< I2C operation not completed within specified timeout. */ -#define IOT_I2C_NOTHING_TO_CANCEL ( 7 ) /*!< No ongoing transaction when cancel operation is performed. */ -#define IOT_I2C_FUNCTION_NOT_SUPPORTED ( 8 ) /*!< I2C operation is not supported. */ -#define IOT_I2C_SLAVE_ADDRESS_NOT_SET ( 9 ) /*!< Slave address is not set before calling I2C read or write operation. */ - -/** - * @brief I2C Bus status - */ -typedef enum -{ - eI2CBusIdle = 0, /*!< I2C bus is idle. */ - eI2cBusBusy = IOT_I2C_BUSY, /*!< I2C bus is busy. */ -} IotI2CBusStatus_t; - -/** - * @brief I2C operation status. - */ -typedef enum -{ - eI2CCompleted = IOT_I2C_SUCCESS, /*!< I2C operation completed successfully. */ - eI2CDriverFailed, /*!< I2C driver returns error during last operation. */ - eI2CNackFromSlave = IOT_I2C_NACK, /*!< Unexpected NACK is caught. */ - eI2CMasterTimeout = IOT_I2C_BUS_TIMEOUT, /*!< I2C operation not completed within specified timeout. */ -} IotI2COperationStatus_t; - -/** - * @brief I2C bus configuration - */ -typedef struct IotI2CConfig -{ - uint32_t ulMasterTimeout; /**Example - * @code{c} - * // Declare an I2C handle. - * IotI2CHandle_t xI2CHandle; - * - * // Return value of I2C functions. - * int32_t lRetVal = IOT_I2C_SUCCESS; - * - * // Register address on I2C slave device. - * uint8_t xDeviceRegisterAddress = 0x73; - * - * // Number of read/write bytes. - * uint16_t usReadBytes = 0; - * uint16_t usWriteBytes = 0; - * - * uint8_t ucReadBuffer[2] = {0}; - * - * // Configurations of I2C master device. - * IotI2CConfig_t xI2CConfig = - * { - * .ulBusFreq = IOT_I2C_FAST_MODE_BPS, - * .ulMasterTimeout = 500 - * }; - * - * // Open one of the I2C instance and get a handle. - * xI2CHandle = iot_i2c_open( 1 ); - * - * if ( xI2CHandle != NULL ) - * { - * // Set I2C configuration. - * lRetVal = iot_i2c_ioctl( xI2CHandle, eI2CSetMasterConfig, &xI2CConfig ); - * // assert(lRetVal == IOT_I2C_SUCCESS); - * - * // Set slave address. - * lRetVal = iot_i2c_ioctl( xI2CHandle, eI2CSetSlaveAddr, &uctestIotI2CSlaveAddr ); - * // assert(lRetVal == IOT_I2C_SUCCESS); - * - * // Write the register address as single byte, in a transaction. - * lRetVal = iot_i2c_write_sync( xI2CHandle, &xDeviceRegisterAddress, sizeof( xDeviceRegisterAddress ) ); - * - * if ( lRetVal == IOT_I2C_SUCCESS ) - * { - * // Get the number of written bytes in last transaction. - * lRetVal = iot_i2c_ioctl( xI2CHandle, eI2CGetTxNoOfbytes, &usWriteBytes ); - * // assert(lRetVal == IOT_I2C_SUCCESS); - * // assert(usWriteBytes == 1); - * - * // Read two bytes of data to allocated buffer, in a transaction. - * lRetVal = iot_i2c_read_sync( xI2CHandle, &ucReadBuffer, sizeof( ucReadBuffer ) ); - * - * if ( lRetVal == IOT_I2C_SUCCESS ) - * { - * // Get the number of read bytes in last transaction. - * lRetVal = iot_i2c_ioctl( xI2CHandle, eI2CGetRxNoOfbytes, &usReadBytes ); - * // assert(lRetVal == IOT_I2C_SUCCESS); - * // assert(usReadBytes == 2); - * } - * } - * - * lRetVal = iot_i2c_close( xI2CHandle ); - * // assert(lRetVal == IOT_I2C_SUCCESS); - * } - * @endcode - */ -int32_t iot_i2c_read_sync( IotI2CHandle_t const pxI2CPeripheral, - uint8_t * const pucBuffer, - size_t xBytes ); - -/** - * @brief Starts the I2C master write operation in synchronous mode. - * - * This function attempts to write certain number of bytes from a pre-allocated buffer to a slave device, in synchronous way. - * Partial write might happen, e.g. slave device unable to receive more data. - * And the number of bytes that have been actually written can be obtained by calling iot_i2c_ioctl. - * - * @note Usually, the first byte is treated as the register address and the following bytes are treated as data to be written. - * @note If eI2CSendNoStopFlag is set and this function returns, whether the actual transaction has been started is undefined. This is board-specific behavior. - * - * @warning Prior to this function, slave address must be already configured. - * @warning None of other read or write functions shall be called during this function. - * - * @param[in] pxI2CPeripheral The I2C handle returned in open() call. - * @param[in] pucBuffer The transmit buffer containing the data to be written. It must stay allocated before this function returns. - * @param[in] xBytes The number of bytes to write. - * - * @return - * - IOT_I2C_SUCCESS, on success (all the requested bytes have been written) - * - IOT_I2C_INVALID_VALUE, if - * - pxI2CPeripheral is NULL - * - pxI2CPeripheral is not opened yet - * - pucBuffer is NULL - * - xBytes is 0 - * - IOT_I2C_SLAVE_ADDRESS_NOT_SET, if slave address is not set yet - * - IOT_I2C_NACK or IOT_I2C_WRITE_FAILED, if - * - no device correspond to the slave address - * - the slave is unable to receive or transmit - * - the slave gets data or commands that it does not understand - * - there is some unknown driver error - * - IOT_I2C_BUS_TIMEOUT, if timeout is supported and slave device does not respond within configured timeout. - * - IOT_I2C_BUSY, if the bus is busy which means there is an ongoing transaction. - */ -int32_t iot_i2c_write_sync( IotI2CHandle_t const pxI2CPeripheral, - uint8_t * const pucBuffer, - size_t xBytes ); - -/** - * @brief Starts the I2C master read operation in asynchronous mode. - * - * This function attempts to read certain number of bytes from a pre-allocated buffer, in asynchronous way. - * It returns immediately when the operation is started and the status can be check by calling iot_i2c_ioctl. - * Once the operation completes, successful or not, the user callback will be invoked. - * - * Partial read might happen, e.g. slave device unable to receive more data. - * And the number of bytes that have been actually read can be obtained by calling iot_i2c_ioctl. - * - * @note Usually, the address of register needs to be written before calling this function. - * @note If eI2CSendNoStopFlag is set and this function returns, whether the actual transaction has been started is undefined. This is board-specific behavior. - * @note In order to get notification when the asynchronous call is completed, iot_i2c_set_callback must be called prior to this. - * - * @warning Prior to this function, slave address must be already configured. - * @warning pucBuffer must be valid before callback is invoked. - * @warning None of other read or write functions shall be called during this function or before user callback. - * - * @param[in] pxI2CPeripheral The I2C handle returned in open() call. - * @param[out] pucBuffer The receive buffer to read the data into - * @param[in] xBytes The number of bytes to read. - * - * @return - * - IOT_I2C_SUCCESS, on success - * - IOT_I2C_INVALID_VALUE, if - * - pxI2CPeripheral is NULL - * - pxI2CPeripheral is not opened yet - * - pucBuffer is NULL - * - xBytes is 0 - * - IOT_I2C_SLAVE_ADDRESS_NOT_SET, if slave address is not set yet - * - IOT_I2C_NACK or IOT_I2C_READ_FAILED, if - * - no device correspond to the slave address - * - the slave is unable to receive or transmit - * - the slave gets data or commands that it does not understand - * - there is some unknown driver error - */ -int32_t iot_i2c_read_async( IotI2CHandle_t const pxI2CPeripheral, - uint8_t * const pucBuffer, - size_t xBytes ); - -/** - * @brief Starts the I2C master write operation in asynchronous mode. - * - * This function attempts to write certain number of bytes from a pre-allocated buffer to a slave device, in asynchronous way. - * It returns immediately when the operation is started and the status can be check by calling iot_i2c_ioctl. - * Once the operation completes, successful or not, the user callback will be invoked. - * - * Partial write might happen, e.g. slave device unable to receive more data. - * And the number of bytes that have been actually written can be obtained by calling iot_i2c_ioctl. - * - * @note Usually, the first byte is treated as the register address and the following bytes are treated as data to be written. - * @note If eI2CSendNoStopFlag is set and this function returns, whether the actual transaction has been started is undefined. This is board-specific behavior. - * @note In order to get notification when the asynchronous call is completed, iot_i2c_set_callback must be called prior to this. - * - * @warning Prior to this function, slave address must be already configured. - * @warning None of other read or write functions shall be called during this function. - * - * @param[in] pxI2CPeripheral The I2C handle returned in open() call. - * @param[in] pucBuffer The transmit buffer containing the data to be written. It must stay allocated before this function returns. - * @param[in] xBytes The number of bytes to write. - * - * @return - * - IOT_I2C_SUCCESS, on success - * - IOT_I2C_INVALID_VALUE, if - * - pxI2CPeripheral is NULL - * - pxI2CPeripheral is not opened yet - * - pucBuffer is NULL - * - xBytes is 0 - * - IOT_I2C_SLAVE_ADDRESS_NOT_SET, if slave address is not set yet - * - IOT_I2C_NACK or IOT_I2C_WRITE_FAILED, if - * - no device correspond to the slave address - * - the slave is unable to receive or transmit - * - the slave gets data or commands that it does not understand - * - there is some unknown driver error - * - IOT_I2C_BUS_TIMEOUT, if timeout is supported and slave device does not respond within configured timeout. - * - IOT_I2C_BUSY, if the bus is busy which means there is an ongoing transaction. - */ -int32_t iot_i2c_write_async( IotI2CHandle_t const pxI2CPeripheral, - uint8_t * const pucBuffer, - size_t xBytes ); - -/** - * @brief Configures the I2C master with user configuration. - * - * @param[in] pxI2CPeripheral The I2C handle returned in open() call. - * @param[in] xI2CRequest Should be one of I2C_Ioctl_Request_t. - * @param[in,out] pvBuffer The configuration values for the IOCTL request. - * - * @note SetMasterConfig is expected only called once at beginning. - * This request expects the buffer with size of IotI2CConfig_t. - * - * @note eI2CGetMasterConfig gets the current configuration for I2C master. - * This request expects the buffer with size of IotI2CConfig_t. - * - * @note eI2CGetBusState gets the current bus state. - * This request expects buffer with size of IotI2CBusStatus_t. - * - * @note eI2CSendNoStopFlag is called at every operation you want to not send stop condition. - * - * @note eI2CSetSlaveAddr sets either 7-bit address or 10-bit address, according to hardware's capability. - * This request expects 2 bytes buffer (uint16_t) - * - * @note eI2CGetTxNoOfbytes returns the number of written bytes in last transaction. - * This is supposed to be called in the caller task or application callback, right after last transaction completes. - * This request expects 2 bytes buffer (uint16_t). - * - * - If the last transaction only did write, this returns the actual number of written bytes which might be smaller than the requested number (partial write). - * - If the last transaction only did read, this returns 0. - * - If the last transaction did both write and read, this returns the number of written bytes. - * - * @note eI2CGetRxNoOfbytes returns the number of read bytes in last transaction. - * This is supposed to be called in the caller task or application callback, right after last transaction completes. - * This request expects 2 bytes buffer (uint16_t). - * - * - If the last transaction only did read, this returns the actual number of read bytes which might be smaller than the requested number (partial read). - * - If the last transaction only did write, this returns 0. - * - If the last transaction did both write and read, this returns the number of read bytes. - * - * - * @return - * - IOT_I2C_SUCCESS, on success - * - IOT_I2C_INVALID_VALUE, if - * - pxI2CPeripheral is NULL - * - pxI2CPeripheral is not opened yet - * - pucBuffer is NULL with requests which needs buffer - * - IOT_I2C_FUNCTION_NOT_SUPPORTED, if this board doesn't support this feature. - * - eI2CSetSlaveAddr: 10-bit address is not supported - * - eI2CSendNoStopFlag: explicitly not sending stop condition is not supported - * - eI2CBusReset: reset bus is not supported - */ -int32_t iot_i2c_ioctl( IotI2CHandle_t const pxI2CPeripheral, - IotI2CIoctlRequest_t xI2CRequest, - void * const pvBuffer ); - - -/** - * @brief Stops the ongoing operation and de-initializes the I2C peripheral. - * - * @param[in] pxI2CPeripheral The I2C handle returned in open() call. - * - * @return - * - IOT_I2C_SUCCESS, on success - * - IOT_I2C_INVALID_VALUE, if - * - pxI2CPeripheral is NULL - * - pxI2CPeripheral is not opened yet - */ -int32_t iot_i2c_close( IotI2CHandle_t const pxI2CPeripheral ); - -/** - * @brief This function is used to cancel the current operation in progress, if possible. - * - * @param[in] pxI2CPeripheral The I2C handle returned in open() call. - * - * @return - * - IOT_I2C_SUCCESS, on success - * - IOT_I2C_INVALID_VALUE, if - * - pxI2CPeripheral is NULL - * - pxI2CPeripheral is not opened yet - * - IOT_I2C_NOTHING_TO_CANCEL, if there is no on-going transaction. - * - IOT_I2C_FUNCTION_NOT_SUPPORTED, if this board doesn't support this operation. - */ -int32_t iot_i2c_cancel( IotI2CHandle_t const pxI2CPeripheral ); - -/** - * @} - */ -/* end of group iot_i2c */ - -#endif /* ifndef _IOT_I2C_H_ */ diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/common_io/include/iot_i2s.h b/bk7235/liteos_m/bk_sdk_armino/middleware/compal/common_io/include/iot_i2s.h deleted file mode 100755 index a3bec940db7670db35bba221b5c08b0243af603f..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/common_io/include/iot_i2s.h +++ /dev/null @@ -1,311 +0,0 @@ -/* - * FreeRTOS Common IO V0.1.3 - * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * http://aws.amazon.com/freertos - * http://www.FreeRTOS.org - */ - -/******************************************************************************* - * @file iot_hal_i2s.h - * @brief File for the APIs of I2S called by application layer. - ******************************************************************************* - */ - -#ifndef _IOT_I2S_H_ -#define _IOT_I2S_H_ - -/** - * The return codes for the functions in I2S. - */ -#define IOT_I2S_SUCCESS ( 0 ) /*!< I2S operation completed successfully. */ -#define IOT_I2S_INVALID_VALUE ( 1 ) /*!< At least one parameter is invalid. */ -#define IOT_I2S_NOT_INITIALIZED ( 2 ) /*!< I2S interface not initialized. */ -#define IOT_I2S_BUSY ( 3 ) /*!< I2S operation can't be completed because another operation is happening. */ -#define IOT_I2S_WRITE_FAILED ( 4 ) /*!< I2S write operation failed. */ -#define IOT_I2S_READ_FAILED ( 5 ) /*!< I2S read operation failed. */ -#define IOT_I2S_NOTHING_TO_CANCEL ( 7 ) /*!< No active I2S operations to cancel. */ -#define IOT_I2S_FUNCTION_NOT_SUPPORTED ( 8 ) /*!< I2S operation not supported. */ - -/** - * @brief I2S Bus status - */ -typedef enum -{ - eI2SBusIdle = 0, /*!< I2S Bus status is idle. */ - eI2SBusBusy = IOT_I2S_BUSY, /*!< I2S Bus status is busy. */ -} IotI2SBusStatus_t; - -/** - * @brief I2S operation status. - */ -typedef enum -{ - eI2SCompleted = IOT_I2S_SUCCESS, /*!< I2S operation completed successfully. */ - eI2SLastWriteFailed = IOT_I2S_WRITE_FAILED, /*!< I2S write operation failed. */ - eI2SLastReadFailed = IOT_I2S_READ_FAILED, /*!< I2S read operation failed. */ -} IotI2SOperationStatus_t; - -/** - * @brief Ioctl request types. - */ -typedef enum -{ - eI2SSetConfig, /*!< Set I2S configuration taking the struct IotI2SIoctlConfig_t */ - eI2SGetConfig, /*!< Get I2S configuration returning the struct IotI2SIoctlConfig_t */ - eI2SGetBusState, /*!< Get the State of the I2S Bus returning the struct IotI2SBusStatus_t */ - eI2SGetTxNoOfbytes, /*!< Get the number of bytes sent in write operation. Returns uint32_t type. */ - eI2SGetRxNoOfbytes, /*!< Get the number of bytes received in read operation. Returns uint32_t type. */ -} IotI2SIoctlRequest_t; - -/** - * @brief I2S mode types. - */ -typedef enum -{ - eI2SNormalMode, /*!< HW uses normal mode for signal detection. */ - eI2SLeftJustifiedMode, /*!< HW uses left justified mode for signal detection. */ - eI2SRightJustifiedMode, /*!< HW uses right justified mode for signal detection. */ - eI2SPcmMode, /*!< HW uses PCM mode for signal detection. */ - eI2SDspMode, /*!< HW uses DSP mode for signal detection. */ -} IotI2SMode_t; - -/** - * @brief I2S channel types. - */ -typedef enum -{ - eI2SChannelStereo, /*!< Channel is in stereo. */ - eI2SChannelMono, /*!< Channel is in mono. */ -} IotI2SChannel_t; - -/** - * @brief I2S clock polarity for SCK and WS - */ -typedef enum -{ - eI2SFallingEdge, /*!< Clock polarity detected on falling edge of signal. */ - eI2SRisingEdge, /*!< Clock polarity detected on rising edge of signal. */ -} IotI2SClkPolarity_t; - -/** - * @brief I2S configuration - */ -typedef struct -{ - IotI2SMode_t xI2SMode; /*!< Set I2S mode using IotI2SMode_t */ - IotI2SChannel_t xI2SChannel; /*!< Set I2S channel using IotI2SChannel_t */ - IotI2SClkPolarity_t xI2SSckPolarity; /*!< Set I2S SCK polarity using IotI2SClkPolarity_t */ - IotI2SClkPolarity_t xI2SWsPolarity; /*!< Set I2S WS polarity using IotI2SClkPolarity_t */ - uint32_t ulI2SFrequency; /*!< Frequency to transfer/receive data*/ - uint32_t ulI2SDataLength; /*!< Number of data bits per sample */ - uint32_t ulI2SFrameLength; /*!< Number of data bits in the frames */ -} IotI2sIoctlConfig_t; - -/** - * @brief Opaque descriptor of I2C - */ -struct IotI2SDescriptor; - -/** - * @brief The handle for a I2S peripheral. - */ -typedef struct IotI2SDescriptor * IotI2SHandle_t; - -/** - * @brief The callback function for completion of I2C operation. - * - * @param[out] xOpStatus I2S asynchronous operation status. - * @param[in] pvUserContext User Context passed when setting the callback. - * This is not used or modified by the driver. The context - * is provided by the caller when setting the callback, and is - * passed back to the caller in the callback. - */ -typedef void ( * IotI2SCallback_t )( IotI2SOperationStatus_t xOpStatus, - void * pvUserContext ); - -/** - * @brief Initiates the I2S bus as. - * - * @param[in] lI2SInstance The index of I2S to initialize. - * - * @return - * - The handle to the I2S port if SUCCESS - * - NULL if - * - invalid lI2SInstance - * - lI2SInstance already open - */ -IotI2SHandle_t iot_i2s_open( int32_t lI2SInstance ); - -/** - * @brief Sets the application callback to be called on completion of an operation. - * - * @note Single callback is used per instance for iot_i2s_read_async() and iot_i2s_write_async() calls only. - * @note Newly set callback overrides the one previously set - * - * @warning If input handle or if callback function is NULL, this function silently takes no action. - * - * @param[in] pxI2SPeripheral The I2S handle returned in open() call. - * @param[in] xCallback The callback function to be called on completion of transaction. - * @param[in] pvUserContext The user context to be passed back when callback is called. - */ -void iot_i2s_set_callback( IotI2SHandle_t const pxI2SPeripheral, - IotI2SCallback_t xCallback, - void * pvUserContext ); - -/** - * @brief Starts the I2S read operation in non-blocking mode. - * - * @param[in] pxI2SPeripheral The I2S handle returned in open() call. - * @param[in] pvBuffer The receive buffer to read the data into. - * @param[in] xBytes The number of bytes to read. - * - * @return - * - IOT_I2S_SUCCESS on success - * - IOT_I2S_INVALID_VALUE if - * - pxI2SPeriperal or pvBuffer are NULL - * - xBytes == 0 - * - IOT_I2S_READ_FAIL if there was an error doing the read - * - IOT_I2S_NOT_INITIALIZED if I2S not first initialized with ioctl call eI2SSetConfig. - * - IOT_I2S_BUSY if another read (sync or async) is in process - */ -int32_t iot_i2s_read_async( IotI2SHandle_t const pxI2SPeripheral, - uint8_t * const pvBuffer, - size_t xBytes ); - -/** - * @brief Starts the I2S write operation in non-blocking mode. - * - * @param[in] pxI2SPeripheral The I2S handle returned in open() call. - * @param[in] pvBuffer The transmit buffer to write the data into. - * @param[in] xBytes The number of bytes to write. - * - * @return - * - IOT_I2S_SUCCESS on success - * - IOT_I2S_INVALID_VALUE if - * - pxI2SPeriperal or pvBuffer are NULL - * - xBytes == 0 - * - IOT_I2S_WRITE_FAIL if there was an error doing the write - * - IOT_I2S_NOT_INITIALIZED if I2S not first initialized with ioctl call eI2SSetConfig. - * - IOT_I2S_BUSY if another write (sync or async) is in process - */ -int32_t iot_i2s_write_async( IotI2SHandle_t const pxI2SPeripheral, - uint8_t * const pvBuffer, - size_t xBytes ); - -/** - * @brief Starts the I2S read operation in blocking mode. - * - * @param[in] pxI2SPeripheral The I2S handle returned in open() call. - * @param[in] pvBuffer The receive buffer to read the data into. - * @param[in] xBytes The number of bytes to read. - * - * @return - * - IOT_I2S_SUCCESS on success - * - IOT_I2S_INVALID_VALUE if - * - pxI2SPeriperal or pvBuffer are NULL - * - xBytes == 0 - * - IOT_I2S_READ_FAIL if there was an error doing the read - * - IOT_I2S_NOT_INITIALIZED if I2S not first initialized with ioctl call eI2SSetConfig. - * - IOT_I2S_BUSY if another read (sync or async) is in process - */ -int32_t iot_i2s_read_sync( IotI2SHandle_t const pxI2SPeripheral, - uint8_t * const pvBuffer, - size_t xBytes ); - -/** - * @brief Starts the I2S write operation in blocking mode. - * - * @param[in] pxI2SPeripheral The I2S handle returned in open() call. - * @param[in] pvBuffer The transmit buffer to write the data into. - * @param[in] xBytes The number of bytes to write. - * - * @return - * - IOT_I2S_SUCCESS on success - * - IOT_I2S_INVALID_VALUE if - * - pxI2SPeriperal or pvBuffer are NULL - * - xBytes == 0 - * - IOT_I2S_WRITE_FAIL if there was an error doing the write - * - IOT_I2S_NOT_INITIALIZED if I2S not first initialized with ioctl call eI2SSetConfig. - * - IOT_I2S_BUSY if another write (sync or async) is in process - */ -int32_t iot_i2s_write_sync( IotI2SHandle_t const pxI2SPeripheral, - uint8_t * const pvBuffer, - size_t xBytes ); - -/** - * @brief Stops the ongoing operation and deinitializes the I2S peripheral. - * - * @param[in] pxI2SPeripheral The I2S handle returned in open() call. - * - * @return - * - IOT_I2S_SUCCESS on success - * - IOT_I2S_INVALID_VALUE if - * - pxI2SPeriperal is NULL - * - instance not open (previously closed) - */ -int32_t iot_i2s_close( IotI2SHandle_t const pxI2SPeripheral ); - -/** - * @brief Configures the I2S with user configuration. - * - * @param[in] pxI2SPeripheral The I2S handle returned in open() call. - * @param[in] lRequest Should be one of I2S_Ioctl_Request_t. - * @param[in] pvBuffer The configuration values for the IOCTL request. - * - * @note eI2SGetTxNoOfbytes returns the number of written bytes in last operation. - * This is supposed to be called in the caller task or application callback, right after last operation completes. - * This request expects 4 bytes buffer (uint32_t). - * - * - If the last operation only did read, this returns 0. - * - * @note eI2SGetRxNoOfbytes returns the number of read bytes in last operation. - * This is supposed to be called in the caller task or application callback, right after last operation completes. - * This request expects 4 bytes buffer (uint32_t). - * - * - If the last operation was a read, this returns the actual number of read bytes which might be smaller than the requested number (partial read). - * - If the last operation was a write, this returns 0. - * - * @return - * - IOT_I2S_SUCCESS on success - * - IOT_I2S_INVALID_VALUE if - * - pxI2SPeriperal is NULL - * - xI2SRequest is invalid - * - pvBuffer is NULL - * - IOT_I2S_FUNCTION_NOT_SUPPORTED if designated IotI2SMode_t in eI2SSetConfig is not supported. - */ -int32_t iot_i2s_ioctl( IotI2SHandle_t const pxI2SPeripheral, - IotI2SIoctlRequest_t xI2SRequest, - void * const pvBuffer ); - -/** - * @brief This function is used to cancel the current operation in progress if possible. - * - * @param[in] pxI2SPeripheral The I2S handle returned in open() call. - * - * @return - * - IOT_I2S_SUCCESS on success - * - IOT_I2S_INVALID_VALUE if pxI2SPeriperal is NULL - * - IOT_I2S_NOTHING_TO_CANCEL if nothing to cancel. - * - IOT_I2S_FUNCTION_NOT_SUPPORTED if cancel operation not supported. - */ -int32_t iot_i2s_cancel( IotI2SHandle_t const pxI2SPeripheral ); - -#endif /* ifndef _IOT_HAL_I2S_H_ */ diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/common_io/include/iot_perfcounter.h b/bk7235/liteos_m/bk_sdk_armino/middleware/compal/common_io/include/iot_perfcounter.h deleted file mode 100755 index 705fa5ea704c935762ff59dac7247cae1368c0fc..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/common_io/include/iot_perfcounter.h +++ /dev/null @@ -1,88 +0,0 @@ -/* - * FreeRTOS Common IO V0.1.3 - * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * http://aws.amazon.com/freertos - * http://www.FreeRTOS.org - */ - -/******************************************************************************* - * @file iot_perfcounter.h - * - * @breif HAL APIs for Performance Counter - * - ******************************************************************************* - */ - -/** - * @file iot_perfcounter.h - * @brief This file contains all the Performance counters HAL API definitions - */ - -#ifndef _IOT_PERFCOUNTER_H -#define _IOT_PERFCOUNTER_H - -/** - * @defgroup iot_perfcounter PerfCounter HAL APIs - * @{ - * @brief The perf counter is generally used to measure the cycles (usually processor clock cycles ) - * taken between 2 places in code. perfcounters can be implemented using cycle counters if - * the processor supports, or any generic timer that is granular enough to measure the time - * between 2 points in code. - */ - -/** - * @brief iot_perfcounter_open is used to Initialize the performance counter. - * - */ -void iot_perfcounter_open( void ); - -/** - * @brief iot_perfcounter_get_value is used to get the current performance counter - * value. - * - * @return returns performance counter value as uint64 value. - */ -uint64_t iot_perfcounter_get_value( void ); - -/** - * @brief iot_perfcounter_get_frequency is used to get the current frequency - * performance counters are running at. This can be used to determine the - * time delta between two perfcounter values returned by valling iot_perfcounter_get_value() - * - * @return returns the frequency of the performance counter as a uint32 value. - * This can be used to deterime the period between perfcounter - * increments. - */ -uint32_t iot_perfcounter_get_frequency( void ); - - -/** - * @brief iot_perfcounter_close is used to de-initialize the perfcounter. - * It may reset the counter value in perfcounter. - * - */ -void iot_perfcounter_close( void ); - -/** - * @} - */ - -#endif /* ifndef _IOT_PERFCOUNTER_H */ diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/common_io/include/iot_power.h b/bk7235/liteos_m/bk_sdk_armino/middleware/compal/common_io/include/iot_power.h deleted file mode 100755 index 42ffba37d0090c30bcbdca045471ceab097225c4..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/common_io/include/iot_power.h +++ /dev/null @@ -1,285 +0,0 @@ -/* - * FreeRTOS Common IO V0.1.3 - * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * http://aws.amazon.com/freertos - * http://www.FreeRTOS.org - */ - -/** - * @file iot_power.h - * @brief This file contains all the Power HAL API definitions - */ - -#ifndef _IOT_HAL_POWER_H_ -#define _IOT_HAL_POWER_H_ - -#include -#include - -/** - * @defgroup iot_power Power HAL APIs - * @{ - */ - -/** - * @brief Return values used by the driver. - */ -#define IOT_POWER_SUCCESS ( 0 ) /*!< Power operation completed successfully. */ -#define IOT_POWER_INVALID_VALUE ( 1 ) /*!< At least one parameter is invalid. */ -#define IOT_POWER_NOT_INITIALIZED ( 2 ) /*!< Power operation completed successfully. */ -#define IOT_POWER_GET_FAILED ( 3 ) /*!< Power get operation failed. */ -#define IOT_POWER_SET_FAILED ( 4 ) /*!< Power set operation failed. */ -#define IOT_POWER_FUNCTION_NOT_SUPPORTED ( 5 ) /*!< Power operation not supported. */ - -/** - * @brief power descriptor type defined in the source file. - */ -struct IotPowerDescriptor; - -/** - * @brief IotPowerHandle_t type is the power handle returned by calling iot_power_open() - * this is initialized in open and returned to caller. Caller must pass this pointer - * to the rest of the APIs. - */ -typedef struct IotPowerDescriptor * IotPowerHandle_t; - -/** - * @brief Power modes supported by the driver. - * These power modes may perform different actions on - * different platforms based on the underlying HW support. - */ -typedef enum -{ - eHighPowerPerfMode, /*!< Set the high performance mode at the SoC level */ - eNormalPowerPerfMode, /*!< Set the Normal mode. power_open sets the system to this mode by default*/ - eLowPowerPerfMode, /*!< Set the lower performance mode at the Soc level */ - eUnknownPowerMode = 0xFFFF /*!< This mode cannot be set, and when a reset_mode is called currentMode will be set to eUnknown */ -} IotPowerMode_t; - -/** - * @brief Different Idle mode mappings to the threshold values set using the IOCTLs. - */ -typedef enum -{ - eIdleNoneMode, /*!< No Idle mode entered. */ - eIdlePCMode, /*!< Normal Idle mode with core collapsed or clock gated. Actual - * mode implementation may differ based on the underlying SoC support. */ - eIdleClkSrcOffModeMode, /*!< Source clock off in addition to core collapse. Actual - * mode implementation may differ based on the underlying SoC support. */ - eIdleVddOffMode /*!< Vddcore off in addition to clock source and core collapse. Actual - * mode implementation may differ based on the underlying SoC support. */ -} IotPowerIdleMode_t; - -/** - * @brief Wakeup source information. - */ -typedef struct IotPowerWakeupSources -{ - uint8_t * pucWakeupSources; /*!< Wakeup sources byte stream, where each bit in the bytes - * may indicate a different wakeup source and is platform dependent */ - uint16_t usLength; /*!< Length of the Wakeup sources in number of bytes.*/ -} IotPowerWakeupSources_t; - -/** - * @brief Ioctl request types. - */ -typedef enum IotPowerIoctlRequest -{ - eSetPCWakeThreshold, /*!< IdlePCMode is entered when expected idle time provided by RTOS - * is greater or equal to the PCWakeThreshold. For example - when - * IdleTask runs, all the other tasks are delayed by a time at least - * PCWakeThreshold and less than ClkSrcOffWakeThreshold then the - * device would enter PCMode. Threshold values are uint32_t in millisecond units.*/ - eGetPCWakeThreshold, /*!< Get Wakeup threshold time. Threshold values are uint32_t in millisecond units.*/ - eSetClkSrcOffWakeThreshold, /*!< ClkSrcOffModeMode is entered when expected idle time provided - * by RTOS is greater or equal to the ClkSrcOffWakeThreshold. For - * example - when IdleTask runs, SOC clock sources will be gated for - * the time you set to ClkSrcOffWakeThreshold then the device would - * enter ClkSrcOffModeMode. Threshold values are uint32_t in millisecond units.*/ - eGetClkSrcOffWakeThreshold, /*!< Get Clock off threshold time. Threshold values are uint32_t in millisecond units.*/ - eSetVddOfffWakeThreshold, /*!< VddOffMode is entered when expected idle time provided by RTOS - * is greater or equal to the VddOfffWakeThreshold. If all idleTask meet - * this condition, core will shut off to enter VddOffMode. - * Threshold values are uint32_t in millisecond units. */ - eGetVddOfffWakeThreshold, /*!< Get power off (vdd rails off - or lower input voltage etc..) threshold time. - * Threshold values are uint32_t in millisecond units. */ - eSetWakeupSources, /*!< Set wakeup sources that can wake-up the target from idle modes. Wakeup sources - * may only be needed for specific idle modes based on the thresholds set above - * and may are platform/SoC dependent. Takes input of type IotPowerWakeupSources_t */ - eGetWakeupSources, /*!< Get the current wakeup sources set to wakeup the target from idle mode. Returns the - * wake-up sources as IotPowerWakeupSources_t type */ - eGetLastIdleMode /*!< Get the last Idle mode entered when the target was idle. Returns one of the modes - * defined in IotPowerIdleMode_t */ -} IotPowerIoctlRequest_t; - -/** - * @brief This callback type is used to set a callback for idle enter and exit notification callback type. - * This callback is used for notifying the registered caller(s) before - * entering and after coming out of target low power state (i,e:idle/sleep). - * bIdleState is used to let the caller know if the callback is called when entering or exiting the low - * power mode. "true" indicates that target is entering idle and "false" indicates that its exiting. - * The callback is not used for any other mode transitions which are synchronous and blocking. - * For example when the caller calls a set_mode to eHighPerfMode, the mode is set in the same context and the call is blocking. - * - * @param[in] bIdleState IdleState set to "true" when entering idle and "false" when exiting. - * @param[in] pvUserContext User Context passed when setting the callback. - */ -typedef void ( * IotPowerCallback_t )( bool bIdleState, - void * pvUserContext ); - -/** - * @brief iot_power_open is used to Initialize the CPU power management driver. - * power_open sets up the default mode to eNomralMode, so when the power_open is called, - * the caller must set the mode using set_mode to a specific mode of interest. - * - * @return - * - handle to power interface on success - * - NULL if already open - */ -IotPowerHandle_t iot_power_open( void ); - -/** - * @brief iot_power_set_mode is used to set or change the power mode to a specific mode. The actual changes made as part - * of switching to a specific power mode are platform specific. When set_mode is called to switch - * from high mode to low mode, the target may go through several steps to enter low performance mode. - * The aggregation of switching to a particular mode must be made prior to calling this, as a call - * to this API may change the CPU frequency and voltage which may affect the software execution. - * This API is blocking and the mode switched in the same context as the caller and is a blocking call. - * - * @param[in] pxPowerHandle handle to power driver returned in - * iot_power_open - * @param[in] xMode power mode to be switched to. - * - * @return - * - IOT_POWER_SUCCESS on success - * - IOT_POWER_INVALID_VALUE if any parameter is invalid - * - IOT_POWER_SET_FAILED if unable to set to the desired mode - * - IOT_POWER_FUNCTION_NOT_SUPPORTED if specified mode is not supported. - */ -int32_t iot_power_set_mode( IotPowerHandle_t const pxPowerHandle, - IotPowerMode_t xMode ); - -/** - * @brief iot_power_reset_mode is used to reset the mode (i,e remove the vote to set mode). When reset mode is called, - * its implicitly notifying the OS to enter deepest low power mode possible in idle state based on - * existing timers. If a set_mode is called with any of the performance modes with out calling reset_mode, - * then when target enters idle state, it will not be able to enter deep power states since there is an - * existing vote for a performance mode from the caller. The target will still do clock gating of the core - * by doing a WFI and WFE. - * Additionally, if a reset_mode is called, followed by a get_mode, eUnKnownMode will be returned to the caller. - * But if reset_mode is called, and then target enters idle state, when coming out of the idle_state it will resume - * to a known previous state. - * For example, if we take the following flow: - * 1. set_mode(eHighPerformanceMode) - *  2. reset_modqe() -> At this point the current mode is set to eUnKnownMode - *  3. Idle checks to see if it can enter a deep power state based on existing timers. - *  4. If a callback is registered, the callback is called with bIdle set to "true" - * 4a. The callback can request a mode change causing idle to abort. - *  5. Target enters Idle state and goes to 'some' deep power state - *  6. Target wakes up due to external interrupt or scheduled timer interrupt. - *  7. If a callback is registered, the callback is called with bIdle set to "false" - *  8. At this point the caller can set the desired performance state. - *  9. Target is set to eHighPerformanceMode as this was the known mode before entering idle. (optional if mode was not set at #6) - * - * @param[in] pxPowerHandle handle to power driver returned in - * iot_power_open - * - * @return - * - IOT_POWER_SUCCESS on success - * - IOT_POWER_INVALID_VALUE on pxPowerHandle == NULL - * - IOT_POWER_FUNCTION_NOT_SUPPORTED if power reset not supported. - */ -int32_t iot_power_reset_mode( IotPowerHandle_t const pxPowerHandle ); - -/** - * @brief iot_power_set_callback is used to set the callback to be called when the target is entering low power mode, - * and when target is coming out of low power mode. Callback must not use any HW resources - * when this callback is called with out first requesting for a performance mode. - * - * @note Single callback is used for both entering and exiting low power mode. - * @note Newly set callback overrides the one previously set - * - * @warning If input handle or if callback function is NULL, this function silently takes no action. - * - * @param[in] pxPowerHandle handle to power driver returned in - * iot_power_open - * @param[in] xCallback The callback function to be called. - * @param[in] pvUserContext The user context to be passed when callback is called. - */ -void iot_power_set_callback( IotPowerHandle_t const pxPowerHandle, - IotPowerCallback_t xCallback, - void * pvUserContext ); - -/** - * @brief iot_power_ioctl is used to set power configuration and - * power properties like Wakeup time thresholds. - * Supported IOCTL requests are defined in iot_PowerIoctlRequest_t - * - * @param[in] pxPowerHandle handle to power driver returned in - * iot_power_open() - * @param[in] xRequest configuration request of type IotPowerIoctlRequest_t - * @param[in,out] pvBuffer buffer holding Power set and get values. - * - * @return - * - IOT_POWER_SUCCESS on success - * - IOT_POWER_INVALID_VALUE on any invalid parameter - * - IOT_POWER_FUNCTION_NOT_SUPPORTED for any IotPowerIoctlRequest_t not supported. - * - * @note: For any Set ioctl that is supported, the corresponding Get ioctl must also be supported. - */ -int32_t iot_power_ioctl( IotPowerHandle_t const pxPowerHandle, - IotPowerIoctlRequest_t xRequest, - void * const pvBuffer ); - -/** - * @brief iot_power_get_mode is used to get the current power mode the target is in. - * - * @param[in] pxPowerHandle handle to power driver returned in - * iot_power_open - * @param[out] xMode current power mode. - * - * @return - * - IOT_POWER_SUCCESS on success - * - IOT_POWER_INVALID_VALUE on pxPowerHandle or xMode being NULL - * - IOT_POWER_GET_FAILED on error. - */ -int32_t iot_power_get_mode( IotPowerHandle_t const pxPowerHandle, - IotPowerMode_t * xMode ); - -/** - * @brief iot_power_close is used to de-initialize power driver. - * - * @param[in] pxPowerHandle handle to power driver returned in - * iot_power_open - * - * @return - * - IOT_POWER_SUCCESS on success - * - IOT_POWER_INVALID_VALUE if - * - pxPowerHandle == NULL - * - not in open state (already closed). - */ -int32_t iot_power_close( IotPowerHandle_t const pxPowerHandle ); - -/** - * @} - */ - -#endif /* ifndef _IOT_HAL_POWER_H_ */ diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/common_io/include/iot_pwm.h b/bk7235/liteos_m/bk_sdk_armino/middleware/compal/common_io/include/iot_pwm.h deleted file mode 100755 index 3459de5a39795af99bda7cf5e49b07e6ad2639ef..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/common_io/include/iot_pwm.h +++ /dev/null @@ -1,161 +0,0 @@ -/* - * FreeRTOS Common IO V0.1.3 - * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * http://aws.amazon.com/freertos - * http://www.FreeRTOS.org - */ - -/** - * @file iot_pwm.h - * @brief This file contains all the PWM HAL API definitions - */ - -#ifndef _IOT_PWM_H_ -#define _IOT_PWM_H_ - -/** - * @defgroup iot_pwm PWM HAL APIs - * @{ - */ - -/** - * @brief Return values used by PWM driver. - */ -#define IOT_PWM_SUCCESS ( 0 ) /*!< PWM operation completed successfully. */ -#define IOT_PWM_INVALID_VALUE ( 1 ) /*!< At least one parameter is invalid. */ -#define IOT_PWM_NOT_CONFIGURED ( 2 ) /*!< PWM must be configured prior to start. */ -#define IOT_PWM_FUNCTION_NOT_SUPPORTED ( 3 ) /*!< PWM operation not supported. */ - - -/** - * @brief PWM configuration type. - */ -typedef struct IotPwmConfig -{ - uint32_t ulPwmFrequency; /*!< PWM frequency */ - uint8_t ucPwmDutyCycle; /*!< PWM duty cycle */ - uint8_t ucPwmChannel; /*!< PWM output channel. Depending on individual HW implementations, - * each pwm controller may have one or more channels, where the - * output signal can be directed. */ -} IotPwmConfig_t; - -/** - * @brief PWM descriptor type defined in the source file. - */ -struct IotPwmDescriptor; - -/** - * @brief IotPwmHandle_t type is the PWM handle returned by calling iot_pwm_open() - * this is initialized in open and returned to caller. Caller must pass this pointer - * to the rest of the APIs. - */ -typedef struct IotPwmDescriptor * IotPwmHandle_t; - -/** - * @brief iot_pwm_open is used to initialize the PWM driver instance. - * this API will configure PWM and may reset the PWM hardware. - * - * @param[in] lPwmInstance The instance of the PWM to initialize. - * PWM is output only. - * - * @return - * - Handle to PWM interface on success - * - NULL if - * - invalid instance - * - instance already open - */ -IotPwmHandle_t iot_pwm_open( int32_t lPwmInstance ); - -/** - * @brief iot_pwm_set_config sets up the PWM frequency and duty cycle - * to generate the PWM pulses required. - * - * @param[in] pxPwmHandle Handle to PWM driver returned in - * iot_pwm_open - * @param[in] xConfig PWM configuration to be setup. - * - * @return - * - IOT_PWM_SUCCESS on success - * - IOT_PWM_INVALID_VALUE if pxPwmHandle == NULL or invalid config setting - */ -int32_t iot_pwm_set_config( IotPwmHandle_t const pxPwmHandle, - const IotPwmConfig_t xConfig ); - -/** - * @brief iot_pwm_get_config returns the current PWM configuration - * - * @param[in] pxPwmHandle Handle to PWM driver returned in - * iot_pwm_open - * - * @return - * - pointer to current PWM configuration on success - * - NULL if pxPwmHandle == NULL - */ -IotPwmConfig_t * iot_pwm_get_config( IotPwmHandle_t const pxPwmHandle ); - -/*! - * @brief Start the PWM hardware. PWM configuration must be - * set before PWM is started. PWM signal availability - * on the configured output based on the PWMChannel configured - * in iot_pwm_set_config(). - * - * @param[in] pxPwmHandle Handle to PWM driver returned in - * iot_pwm_open - * - * @return - * - IOT_PWM_SUCCESS on success - * - IOT_PWM_INVALID_VALUE if pxPwmHandle == NULL - * - IOT_PWM_NOT_CONFIGURED if iot_pwm_set_config hasn't been called. - */ -int32_t iot_pwm_start( IotPwmHandle_t const pxPwmHandle ); - -/*! - * @brief Stop the PWM hardware. - * - * @param[in] pxPwmHandle Handle to PWM driver returned in - * iot_pwm_open - * - * @return - * - IOT_PWM_SUCCESS on success - * - IOT_PWM_INVALID_VALUE if pxPwmHandle == NULL - */ -int32_t iot_pwm_stop( IotPwmHandle_t const pxPwmHandle ); - -/** - * @brief iot_pwm_close de-initializes the PWM. - * - * @param[in] pxPwmHandle Handle to PWM driver returned in - * iot_pwm_open - * - * @return - * - IOT_PWM_SUCCESS on success - * - IOT_PWM_INVALID_VALUE if - * - pxPwmHandle == NULL - * - not in open state (already closed). - * - */ -int32_t iot_pwm_close( IotPwmHandle_t const pxPwmHandle ); - -/** - * @} - */ - -#endif /* ifndef _IOT_PWM_H_ */ diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/common_io/include/iot_reset.h b/bk7235/liteos_m/bk_sdk_armino/middleware/compal/common_io/include/iot_reset.h deleted file mode 100755 index a2cc3f74d50761f62a0b340d34a500cc4cbf1098..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/common_io/include/iot_reset.h +++ /dev/null @@ -1,110 +0,0 @@ -/* - * FreeRTOS Common IO V0.1.3 - * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * http://aws.amazon.com/freertos - * http://www.FreeRTOS.org - */ - -/** - * @file iot_reset.h - * @brief This file contains all the Reset HAL API definitions - */ - -#ifndef _IOT_RESET_H_ -#define _IOT_RESET_H_ - -#include - -/** - * @defgroup iot_reset Reset HAL APIs - * @{ - */ - -/** - * Return values used by reset driver - */ -#define IOT_RESET_SUCCESS ( 0 ) /**< Reset operation completed successfully. */ -#define IOT_RESET_FUNCTION_NOT_SUPPORTED ( 1 ) /**< Reset function not supported. */ -#define IOT_RESET_INVALID_VALUE ( 2 ) /**< At least one parameter is invalid. */ - -typedef enum -{ - eResetPowerOnBoot, /**< Normal power on Boot, when the power is applied to the device. */ - eResetWarmBoot, /**< Last reset triggered due to warm Reset. for ex: iot_reset_reboot(0) was called to reset the device */ - eResetColdBoot, /**< Last reset triggered due to cold Reset. for ex: iot_reset_reboot(1) */ - eResetWatchdog, /**< Last reset triggered due to watchdog expiration */ - eResetBusTimeout, /**< Last reset triggered due to internal bus timeout on the SoC */ - eResetPmic, /**< Last reset caused by power management IC */ - eResetBrownOut, /**< Last reset caused by power brown out */ - eResetOther, /**< Last reset caused by other reasons specific to the underlying hardware */ -} IotResetReason_t; - -typedef enum -{ - eResetWarmBootFlag, /**< Perform warm-reset */ - eResetColdBootFlag, /**< Perform cold-reset */ -} IotResetBootFlag_t; - -/** - * @brief iot_reset_reboot is used to reboot the device. - * - * @param[in] xResetBootFlag flag to determine either to do cold-reset or warm-reset. - * cold-reset means the device is restarted and does not keep - * any blocks of the SOC powered on i.e. device is shutdown and rebooted), - * and warm-reset means the device is restarted while keeping some of the SoC blocks - * powered on through the reboot process. - * For example warm-boot may keep the RAM contents valid after reset by keeping the power - * on for RAM banks, while cold-boot will wipe off the contents. - * One of the IotResetBootFlag_t value. - */ -void iot_reset_reboot( IotResetBootFlag_t xResetBootFlag ); - -/** - * @brief iot_reset_shutdown is used to shutdown the device. - * If the target does not support shutdown of the device, IOT_RESET_FUNCTION_NOT_SUPPORTED - * is returned to the user. - * - * @return - * - does not return and device shutdown on success - * - IOT_RESET_FUNCTION_NOT_SUPPORTED if shutdown not supported. - */ -int32_t iot_reset_shutdown( void ); - -/** - * @brief iot_get_reset_reason is used to get the last reset reason. - * If the underlying HW does not support the feature of persisting the - * reset reason, then this API will return IOT_RESET_FUNCTION_NOT_SUPPORTED - * error with the value in out as don't care. - * - * @param[out] xResetReason One of the reset reasons specified in IotResetReason_t types - * - * @return - * - IOT_RESET_SUCCESS on success. - * - IOT_RESET_FUNCTION_NOT_SUPPORTED if not supported. - * - IOT_RESET_INVALID_VALUE if xREsetReason == NULL - */ -int32_t iot_get_reset_reason( IotResetReason_t * xResetReason ); - -/** - * @} - */ - -#endif /* ifndef _IOT_RESET_H_ */ diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/common_io/include/iot_rtc.h b/bk7235/liteos_m/bk_sdk_armino/middleware/compal/common_io/include/iot_rtc.h deleted file mode 100755 index 6762d587918be8487fe023c6612e26a9376b434b..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/common_io/include/iot_rtc.h +++ /dev/null @@ -1,232 +0,0 @@ -/* - * FreeRTOS Common IO V0.1.3 - * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * http://aws.amazon.com/freertos - * http://www.FreeRTOS.org - */ - -/******************************************************************************* - * @file iot_rtc.h - * - * @brief HAL APIs for RTC - ******************************************************************************* - */ - -/** - * @file iot_rtc.h - * @brief This file contains all the RTC HAL API definitions - */ - -#ifndef _IOT_RTC_H_ -#define _IOT_RTC_H_ - -/** - * @defgroup iot_rtc RTC HAL APIs - * @{ - */ - -/** - * @brief Return values used by RTC driver - */ -#define IOT_RTC_SUCCESS ( 0 ) /*!< RTC operation completed successfully. */ -#define IOT_RTC_INVALID_VALUE ( 1 ) /*!< At least one parameter is invalid. */ -#define IOT_RTC_NOT_STARTED ( 2 ) /*!< RTC not started. */ -#define IOT_RTC_GET_FAILED ( 3 ) /*!< RTC get operation failed. */ -#define IOT_RTC_SET_FAILED ( 4 ) /*!< RTC set operation failed. */ -#define IOT_RTC_FUNCTION_NOT_SUPPORTED ( 5 ) /*!< RTC operation not supported. */ - -/** - * @brief RTC driver status values - */ -typedef enum -{ - eRtcTimerStopped, /*!< RTC Timer status: stopped. */ - eRtcTimerRunning, /*!< RTC Timer status: running. */ - eRtcTimerAlarmTriggered, /*!< RTC Timer status: alarm triggered. */ - eRtcTimerWakeupTriggered, /*!< RTC Timer status: wakeup triggered. */ -} IotRtcStatus_t; - -/** - * @brief RTC date and time format info. - */ -typedef struct IotRtcDatetime -{ - uint8_t ucSecond; /*!< Seconds - range from 0 to 59.*/ - uint8_t ucMinute; /*!< minutes - range from 0 to 59.*/ - uint8_t ucHour; /*!< hours - range from 0 to 23.*/ - uint8_t ucDay; /*!< date of month - range from 1 to 31 (depending on month).*/ - uint8_t ucMonth; /*!< months since January - range from 0 to 11.*/ - uint16_t usYear; /*!< years since 1900 */ - uint8_t ucWday; /*!< Week day from Sunday - range from 0 to 6 */ -} IotRtcDatetime_t; - -/** - * @brief Ioctl request types. - * - * @note: WakeupTime is a timer, in milliseconds in the future. AlarmTime is an exact time in the future. - */ -typedef enum IotRtcIoctlRequest -{ - eSetRtcAlarm, /*!< Set Alarm, date&time when Alarm need to occur. Takes input type IotRtcDatetime_t - * @warning time must be in the future.*/ - eGetRtcAlarm, /*!< Get Alarm, gives the date&time when Alarm will occur. Returns IotRtcDatetime_t */ - eCancelRtcAlarm, /*!< Cancel any scheduled Alarm */ - eSetRtcWakeupTime, /*!< Set Wakeup time in miliseconds. Maximum number of miliseconds depend on the platform. Value is uint32_t */ - eGetRtcWakeupTime, /*!< Get Wakeup time in milli-seconds */ - eCancelRtcWakeup, /*!< Cancel any scheduled wake-up */ - eGetRtcStatus /*!< Get the RTC timer status value. Returns IotRtcStatus_t type*/ -} IotRtcIoctlRequest_t; - -/** - * @brief RTC descriptor type defined in the source file. - */ -struct IotRtcDescriptor; - -/** - * @brief IotRtcHandle_t type is the RTC handle returned by calling iot_rtc_open() - * this is initialized in open and returned to caller. Caller must pass this pointer - * to the rest of the APIs. - */ -typedef struct IotRtcDescriptor * IotRtcHandle_t; - -/** - * @brief RTC notification callback type. This callback is passed - * to the driver by using iot_rtc_set_callback API. The callback is - * used to get the notifications for Alarm and Wakeup timers. - * - * @param[out] xStatus RTC timer status. - * @param[in] pvUserContext User Context passed when setting the callback. - * This is not used by the driver, but just passed back to the user - * in the callback. - */ -typedef void ( * IotRtcCallback_t)( IotRtcStatus_t xStatus, - void * pvUserContext ); - -/** - * @brief iot_rtc_open is used to initialize the RTC timer. - * It usually resets the RTC timer, sets up the clock for RTC etc... - * - * @param[in] lRtcInstance The instance of the RTC timer to initialize. - * - * @return - * - the handle IotRtcHandle_t on success - * - NULL if - * - if instance is already open - * - invalid instance - */ -IotRtcHandle_t iot_rtc_open( int32_t lRtcInstance ); - -/*! - * @brief iot_rtc_set_callback is used to set the callback to be called when alarmTime triggers. - * The caller must set the Alarm time using IOCTL to get the callback. - * - * @note Single callback is used for both rtc_alarm, and rtc_wakeup features. - * @note Newly set callback overrides the one previously set - * @note This callback is per handle. Each instance has its own callback. - * - * @param[in] pxRtcHandle handle to RTC driver returned in - * iot_rtc_open() - * @param[in] xCallback callback function to be called. - * @param[in] pvUserContext user context to be passed when callback is called. - * - */ -void iot_rtc_set_callback( IotRtcHandle_t const pxRtcHandle, - IotRtcCallback_t xCallback, - void * pvUserContext ); - -/** - * @brief iot_rtc_ioctl is used to set RTC configuration and - * RTC properties like Wakeup time, alarms etc. - * Supported IOCTL requests are defined in iot_RtcIoctlRequest_t - * - * @param[in] pxRtcHandle handle to RTC driver returned in - * iot_rtc_open() - * @param[in] xRequest configuration request of type IotRtcIoctlRequest_t - * @param[in,out] pvBuffer buffer holding RTC set and get values. - * - * @return - * - IOT_RTC_SUCCESS on success - * - IOT_RTC_INVALID_VALUE if - * - pxRtcHandle == NULL - * - xRequest is invalid - * - pvBuffer == NULL (excluding eCancelRtcAlarm, eCancelRtcWakeup) - * - if date/time is set in the past for eSetRtcAlarm - * - IOT_RTC_SET_FAILED if date/time is invalid for eSetRtcAlarm. - * - IOT_RTC_NOT_STARTED on error - * - IOT_RTC_FUNCTION_NOT_SUPPORTED if feature not supported - * - Only valid for eCancelRtcAlarm, eCancelRtcWakeup - */ -int32_t iot_rtc_ioctl( IotRtcHandle_t const pxRtcHandle, - IotRtcIoctlRequest_t xRequest, - void * const pvBuffer ); - -/** - * @brief iot_rtc_set_date_time is used to set the current time as a reference in RTC timer counter. - * - * @param[in] pxRtcHandle handle to RTC driver returned in - * iot_rtc_open() - * @param[in] pxDatetime pointer to IotRtcDatetime_t structure to set the date&time - * to be set in RTC counter. - * - * @return - * - IOT_RTC_SUCCESS on success - * - IOT_RTC_INVALID_VALUE if pxRtcHandle == NULL or pxDatetime == NULL - * - IOT_RTC_SET_FAILED on error. - */ -int32_t iot_rtc_set_datetime( IotRtcHandle_t const pxRtcHandle, - const IotRtcDatetime_t * pxDatetime ); - -/** - * @brief iot_rtc_get_datetime is used to get the current time from the RTC counter. - * The time must be set first as a reference to get the time. - * - * @param[in] pxRtcHandle handle to RTC driver returned in - * iot_rtc_open() - * @param[in] pxDatetime pointer to IotRtcDatetime_t structure to get the date&time - * from RTC counter. - * - * @return - * - IOT_RTC_SUCCESS on success - * - IOT_RTC_INVALID_VALUE if pxRtcHandle == NULL or pxDatetime == NULL - * - IOT_RTC_NOT_STARTED on error - */ -int32_t iot_rtc_get_datetime( IotRtcHandle_t const pxRtcHandle, - IotRtcDatetime_t * pxDatetime ); - -/** - * @brief iot_rtc_close is used to de-Initialize RTC Timer. - * it resets the RTC timer and may stop the timer. - * - * @param[in] pxRtcHandle handle to RTC interface. - * - * @return - * - IOT_RTC_SUCCESS on success - * - IOT_RTC_INVALID_VALUE if - * - pxRtcHandle == NULL - * - not in open state (already closed). - */ -int32_t iot_rtc_close( IotRtcHandle_t const pxRtcHandle ); - -/** - * @} - */ - -#endif /* ifndef _IOT_RTC_H_ */ diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/common_io/include/iot_sdio.h b/bk7235/liteos_m/bk_sdk_armino/middleware/compal/common_io/include/iot_sdio.h deleted file mode 100755 index a32ff3eaa8cdcb0312b2a4c820298e0ecdb88509..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/common_io/include/iot_sdio.h +++ /dev/null @@ -1,714 +0,0 @@ -/* - * FreeRTOS Common IO V0.1.3 - * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * http://aws.amazon.com/freertos - * http://www.FreeRTOS.org - */ - - -/** - * @file iot_sdio.h - * @brief This file contains all the SDIO HAL API definitions. - * Here we define SDIO driver as a protocol layer driver which builds on top of SDMMC - * host driver. SDMMC host driver operates at physical layer and provide APIs to send - * commands to the slave device and receive command responses, send and receive data, - * and handle error conditions on the bus. - * - * SD/SDIO/MMC driver can be built on top of SDMMC host. This interface only define - * the APIs for SDIO applications, the interface can be expanded to support SD/MMC either - * by expanding the APIs in this file or adding separate files for SD/MMC. - * - * @design consideration - * SDIO HAL APIs performs protocol layer tasks between SDIO host and SDIO card. - * Some APIs perform a single task and some APIs perform a sequence of tasks. - * For examples, iot_sdio_io_read_direct() API performs a single task of reading - * one byte from card register, and iot_sdio_card_connect() API performs all tasks - * required by card initialization as specified in section 3.1.2 in "SD Specification - * Part E1 SDIO". - * - * Upon calling iot_sdio_open() API, the user is a given a pxSdioHandle, a - * reference to the SDIO card slot that the user is interested in. Thereafter, user - * uses this handle to call other APIs to perform tasks associated with the target - * card slot. For example, iot_sdio_check_card_presence_status(pxSdioHandle, true) - * checks SDIO card presence, and iot_sdio_io_write_extended(pxSdioHandle) - * writes data to SDIO card in the slot, etc. - * - * @limitation - * SDIO HAL APIs are intended to be used in embedded systems where each SDIO host - * controller is connected to either a single hot swappable sido card slot or multiple - * eSDIO devices in a Shared Bus Configuration (Refer to Section 7.3 of "SD Specification - * Part E1 SDIO"). - * - * These APIs are not suitable for systems where a single SDIO host controller supports - * multiple hot swappable slots. With multiple hot swappable slots available on a single - * host controller, it is not possible pre-determine which card slot SDIO device will be - * inserted, and know which card slot handle to request. Since this type of host controller - * is very rare even in non-embedded world, it is not worth to add complexity to SDIO HAL - * APIs to support it. - */ - -#ifndef _IOT_SDIO_H_ -#define _IOT_SDIO_H_ - -#include -#include - - -/** - * @defgroup iot_sdio SDIO HAL APIs - * @{ - */ - -/** - * @brief The return codes for the functions in SDIO - */ -/*!< SDIO operation completed successfully. */ -#define IOT_SDIO_SUCCESS ( 0 ) - -/*!< SDIO ioctl failed. */ -#define IOT_SDIO_IOCTL_FAIL ( 1 ) - -/*!< SDIO host controller initialization failed. */ -#define IOT_SDIO_HOST_INIT_FAIL ( 2 ) - -/*!< At least one parameter is invalid. */ -#define IOT_SDIO_INVALID_VALUE ( 3 ) - -/*!< Sending command to or receive response from card failed. */ -#define IOT_SDIO_TRANSFER_FAIL ( 4 ) - -/*!< If the card is initialized in 3.3V signaling, and card support high speed - * mode (SHS ==1), host can issue CMD52 in RAW mode, setting EHS bit in CCCR - * to one to switch to high speed mode. This error code indicates that the - * sdio card supports high speed mode but failed to switch to high speed - * mode. The bus clock rate remains unchanged in this case. */ -#define IOT_SDIO_SWITCH_HIGH_SPEED_FAIL ( 5 ) - -/*!< If the card is initialized in 3.3V signaling, and card support high speed - * mode (SHS ==1), host can issue CMD52 in RAW mode, setting EHS bit in CCCR - * to one to switch to high speed mode. This error code indicates that the - * sdio card does not supports high speed mode. The bus clock rate will be - * set to the default 25MHz in this case. */ -#define IOT_SDIO_LOW_SPEED_CARD ( 6 ) - -/*!< If the card is initialized in 1.8V signaling, and card support UHS-I, host - * will try to set card's bus timing mode to the highest mode the card - * supports using CMD52, and set the max clock frequence for that mode. This - * error code indicates a failure of such operation */ -#define IOT_SDIO_SELECT_BUS_TIMING_FAIL ( 7 ) - -/*!< Setting block size for block transfer mode failed. */ -#define IOT_SDIO_SET_CARD_BLOCK_SIZE_FAIL ( 8 ) - -/*!< During card initializaton, A host that supports UHS-I use CMD5 to probe if - * card also supports UHS-I and ready to switch from 3.3v to 1.8v. Once - * voltage switch request is accepted, host sends CMD11 to initiate voltage - * switch sequence. This error code indicates either card failed to respond - * to CMD11 or card responded to CMD11 but failed to switch voltage.*/ -#define IOT_SDIO_SWITCH_VOLTAGE_FAIL ( 9 ) - -/*!< host controller not ready. */ -#define IOT_SDIO_HOST_NOT_READY ( 10 ) - -/*!< Not a valid SDIO card. */ -#define IOT_SDIO_INVALID_CARD ( 11 ) - -/*!< Send Relative Address (CMD3) failed. */ -#define IOT_SDIO_SEND_RELATIVE_ADDRESS_FAIL ( 12 ) - -/*!< Select Card (CMD7) failed. */ -#define IOT_SDIO_SELECT_CARD_FAIL ( 13 ) - -/*!< Read (via CMD52) CIS (Card Information - * Structure failed. */ -#define IOT_SDIO_READ_CIS_FAIL ( 14 ) - -/*!< Set (via CMD52) data bus width failed. */ -#define IOT_SDIO_SET_DATA_BUS_WIDTH_FAIL ( 15 ) - -/*!< Card does not support Asynchronous Interrupt. */ -#define IOT_SDIO_ASYNC_INT_NOT_SUPPORTED ( 16 ) - -/*!< Reading CCCR (function 0) or FBR (function 1-7) failed*/ -#define IOT_SDIO_GET_CARD_CAPABILITY_FAIL ( 17 ) - -/*!< Api function is not supported by platform */ -#define IOT_SDIO_FUNCTION_NOT_SUPPORTED ( 18 ) - -/** - * @brief sdio io bus width - */ - -#define IOT_SDIO_BUS_1BIT ( 0 ) /*!< 1 bit bus mode */ -/*!< 1 is reserved per SDIO specification*/ -#define IOT_SDIO_BUS_4BIT ( 2 ) /*!< 4 bit bus mode */ -#define IOT_SDIO_BUS_8BIT ( 3 ) /*!< 8 bit bus mode */ - -/** - * @brief sdio io read/write direction - */ -typedef enum IotSdioDirection -{ - eIORead = 0U, /*!< io read */ - eIOWrite = 1U, /*!< io write */ -} IotSdioDirection_t; - -/** - * @brief SDIO I/O function number type - * Each SDIO card can support up to 7 I/O functions. - * Each I/O function can implement one of the following: - * - SDIO Standard UART - * - SDIO Bluetooth Type-B standard interface - * - SDIO GPS standard interface - * - SDIO Camera standard interface - * - SDIO PHS standard interface - * - SDIO WLAN interface - * - Embedded SDIO-ATA standard interface - * - SDIO Bluetooth Type-A AMP standard interface - * - Other SDIO standard inferface type identified by - * Extended SDIO Standard Function interface code - */ -typedef enum IotSdioFunction -{ - eSdioFunction0, /*!< refer to common register area present on all I/O cards*/ - eSdioFunction1, /*!< refer to register area of 1st I/O function if card supports it*/ - eSdioFunction2, /*!< refer to register area of 2nd I/O function if card supports it*/ - eSdioFunction3, /*!< refer to register area of 3rd I/O function if card supports it*/ - eSdioFunction4, /*!< refer to register area of 4th I/O function if card supports it*/ - eSdioFunction5, /*!< refer to register area of 5th I/O function if card supports it*/ - eSdioFunction6, /*!< refer to register area of 6th I/O function if card supports it*/ - eSdioFunction7, /*!< refer to register area of 7th I/O function if card supports it*/ - eSdioFunctionMemory, /*!< refer to register area of memory function of a combo card*/ -} IotSdioFunction_t; - -/** - * @brief card detect type - */ -typedef enum IotSdioCardDetectType -{ - eDetectCardByGpioCD, /*!< sdio card detect by CD pin through GPIO */ - eDetectCardByHostCD, /*!< sdio card detect by CD pin through host */ - eDetectCardByHostDATA3, /*!< sdio card detect by DAT3 pin through host */ - eDetectCardNonStandard, /*!< sdio card detect by non standard method - * certain sdio host may support */ -} IotSdioCardDetectType_t; - -/** - * @brief common notify event types in sdio callback - */ -typedef enum IotSdioEventType -{ - eSdioCardInterruptEvent, /*!< Interrupt received from sdio card */ - eSdioCardInsertedEvent, /*!< Sdio card insertion is detected */ - eSdioCardRemovedEvent, /*!< Sdio card removal is detected */ - eSdioCardPowerOnEvent, /*!< Powering on sdio card */ - eSdioCardPowerOffEvent, /*!< Powering off sdio card */ -} IotSdioEventType_t; - -/** - * @brief IOCTL request types. - */ -typedef enum IotSdioIoctlRequest -{ - eSDIOSetDriverStrength, /*!< Set driver strength type - * input: SDIO card driver strength. - * input data type IotSdioSdDriverStrength_t */ - eSDIOSetCardInactive, /*!< put card in inactive state */ - eSDIOSwitchToHighSpeed, /*!< switch to high speed mode if card supports it */ - eSDIOSetDataBusWidth, /*!< set sdio card data bus width and change host setting to support it - * input: sdio bus width, input data type IotSdioBusWidth_t */ - eSDIOGetCardCapabilities, /*!< request host to learn capabilities of specified card function - * input: I/O function number, of type IotSdioFunction_t*/ - eSDIOSetCardDetectParams, /*!< Set card detect parameters - * input: card detect parameters. - * input data type IotSdioCardDetectParam_t*/ - eSDIOSetFuncBlockSize, /*!< Set transfer block size for a function - * input: I/O function and block size. - * input data type IotSdioFuncBlkSize_t*/ - eSDIOEnableIOFunctionIrq, /*!< enable/disable irq for individual io functions - * input: I/O function number and enable or disable, - * input data type IotSdioPerFuncEnable */ - eSDIOEnableAsyncIrqMode, /*!< enable/disable asynchronous interrupt mode - * input: boolean to indicate enable or disable */ - eSDIOEnableIo, /*!< enable/disable an I/O function on card - * input: I/O function number and boolean to indicate enable - * or disable, input data type IotSdioPerFuncEnable_t */ - eSDIOSelectIo, /*!< Select an I/O function for suspend/resume - * input: I/O function number, input data type IotSdioFunction_t */ - eSDIOAbortIo, /*!< Abort an ongoing transfer initiated by the specified I/O function - * input: I/O function number. Input data type IotSdioFunction_t */ - eSDIOReadCis, /*!< Host read list of tuples from card CIS - * input: I/O function number and tuple list to read, - * input data type IotSdioReadCis_t*/ - eSDIOPowerOnOffCard, /*!< Power on/off card - * input: boolean true for power on, false for power off - * boolean true to use board's default power method, - * false to use user defined power method via callback. - * input data type IoTSdioPowerOnOffCard_t */ - eSDIOCheckCardPresence, /*!< check card presence - * output: boolean to indicate card present or not present*/ -} IotSdioIoctlRequest_t; - -/** - * @brief sdio bus width, input parameter type for eSDIOSetDataBusWidth ioctl request - */ -typedef enum IotSdioBusWidth -{ - eDataBus1Bit = IOT_SDIO_BUS_1BIT, /*!< 1 bit bus mode */ - eDataBus4Bit = IOT_SDIO_BUS_4BIT, /*!< 4 bit bus mode*/ - eDataBus8Bit = IOT_SDIO_BUS_8BIT, /*!< 8 bit bus mode*/ -} IotSdioBusWidth_t; - -/** - * @brief input parameter type for eSDIOSetCardDetectParams ioctl request - */ -typedef struct IoTSdioCardDetectParam -{ - IotSdioCardDetectType_t eCardDetectType; /*!< One of the Sd card detect types supported by sdio host */ - bool bCallbackOnInsert; /*!< If true sdio callback will be invoked on card insert. */ - bool bCallbackOnRemoval; /*!< If true sdio callback will be invoked on card card removal. */ -} IotSdioCardDetectParam_t; - -/** - * @brief input parameter type for eSDIOPowerOnOffCard ioctl request - */ -typedef struct IoTSdioPowerOnOffCard -{ - bool bPowerOn; /*!< True to power on card, false to power off card. */ - bool bUseCallback; /*!< indicate if user callback should be used to power on/off card. */ -} IoTSdioPowerOnOffCard_t; - -/** - * @brief input parameter type for eSDIOSetFuncBlockSize ioctl request - */ -typedef struct IotSdioFuncBlkSize -{ - IotSdioFunction_t eFunc; /*!< IO function number range from eSdioFunction0 to eSdioFunction7*/ - uint32_t ulBlockSize; /*!< Block size to be set for I/O function. Must not be greater - * than the maximum block size supported by IO function.*/ -} IotSdioFuncBlkSize_t; - -/** - * @brief input parameter type for eSDIOEnableIOFunctionIrq ioctl request - * and for eSDIOEnableIo ioctl request - */ -typedef struct IotSdioPerFuncEnable -{ - IotSdioFunction_t eFunc; /*!< IO function number range from eSdioFunction0 to eSdioFunction7 */ - bool bEnable; /*!< true to enable, false to disable */ -} IotSdioPerFuncEnable_t; - -/** - * @brief input parameter type for eSDIOReadCis ioctl request - */ -typedef struct IotSdioReadCis -{ - IotSdioFunction_t eFunc; /*!< IO function number range from eSdioFunction0 to eSdioFunction7 */ - const uint32_t * pulTupleList; /*!< Point to a list of tuple codes to be read. - * Tuple code that is not supported by sdio card will be ignored. */ - uint32_t ulTupleNum; /*!< Number of tuple codes in the list. */ -} IotSdioReadCis_t; - -/** - * @brief SDIO card driver strength, input parameter type for eSDIOSetDriverStrength ioctl request - */ -typedef enum IotSdioSdDriverStrength -{ - eSdDriverStrengthTypeB = 0U, /*!< default driver strength (50 ohm x1)*/ - eSdDriverStrengthTypeA = 1U, /*!< driver strength TYPE A (33 ohm x1.5)*/ - eSdDriverStrengthTypeC = 2U, /*!< driver strength TYPE C (66 ohm x0.75)*/ - eSdDriverStrengthTypeD = 3U, /*!< driver strength TYPE D (100 ohm x0.5)*/ -} IotSdioSdDriverStrength_t; - -/** - * @brief SDIO descriptor type defined in the source file. - */ -struct IotSdioSlotDescriptor; - -/** - * @brief IotSdioSlotHandle_t type is the SDIO slot handle returned by calling iot_sdio_open() - */ -typedef struct IotSdioSlotDescriptor * IotSdioSlotHandle_t; - -/** - * @brief The callback function for sdio event operation. This callback is passed to - * driver by using iot_sdio_set_callback API. It's called when one of the events - * (IotSdioEventType_t) happens. - * - * @param[in] pxSdioHandle Handle to sdio card slot instance returned in iot_sdio_open(). - * @param[in] eSdioEvent sdio asynchronous event. - * @param[in] pvUserContext User Context passed when setting the callback. - * This is not used or modified by the driver. The context - * is provided by the caller when setting the callback, and is - * passed back to the caller in the callback. - * - */ -typedef void (* IotSdioCallback_t) ( IotSdioSlotHandle_t const pxSdioHandle, - IotSdioEventType_t eSdioEvent, - void * pvUserContext ); - -/** - * @brief SDIO I/O function callback type. User can call iot_sdio_set_io_function_callback() API - * to set one IOFunctionCallback per each standard SDIO function supported on a sdio card. - * - * Since the I/O function number is parameter to IOFunctionCallback, user can implement one - * single IOFunctionCallback and set it for all I/O functions. Inside the IOFunctionCallback, - * different action can be taken according the I/O function number. - * - * When there is a sdio card interrupt (eSdioCardInterruptEvent). The host should - * checks the interrupt pending status of each card I/O function and call that - * function's user defined IOFunctionCallback as needed. - * - * The job of a IOFunctionCallback is to service the interrupt condition caused by the - * corresponding I/O function. It should read/write to the function unique area on - * the card to clear pending interrupt. The specific implementation for each - * IOFunctionCallback should be according to the specification of SDIO function it is - * written for. - * - * @param[in] pxSdioHandle Handle to sdio card slot instance returned in iot_sdio_open(). - * @param[in] eFunc I/O Function number that are associated with IRQ. - * @param[in] pvUserContext User context passed when setting the callback - * This is not used by the driver, but just passed - * back to the user in the callback. - */ -typedef void (* IotSdioIOFunctionCallback_t) ( IotSdioSlotHandle_t const pxSdioHandle, - IotSdioFunction_t eFunc, - void * pvUserContext ); - -/*! - * @brief iot_sdio_open() is used to open a handle to a sdio card slot. - * - * This API must be called before using any other iot_sdio APIs. - * Upon successful return, the underline SDIO host controller should have - * been initialized properly. - * - * @param[in] ucHostIdx SDIO host controller index. - * Must be 0 if only single host available. - * Range from 0 to n-1 if n hosts available. - * @param[in] ucSlotIdx Card slot index. - * Must be 0 if only single slot is supported. - * Range from 0 to n-1 if n card slots is supported. - * - * @return - * - returns the handle IotSdioSlotHandle_t on success - * - NULL if - * - host index number is invalid - * - slot index number is invalid - * - if a handle on this card slot instance is already open. - */ -IotSdioSlotHandle_t iot_sdio_open( uint8_t ucHostIdx, - uint8_t ucSlotIdx ); - -/*! - * @brief iot_sdio_close() is used to close the sdio card slot handle. - * IO operation initiated through this handle before will - * not be aborted. Caller should call iot_sdio_abort_io() - * to abort IO operation. - * - * Up on a successful return of the API, the SDIO host controller should - * be regarded as uninitialized. All cards on this host should be regarded - * as disconnected. - * - * @param[in] pxSdioHandle Handle to sdio card slot instance returned in - * iot_sdio_open() - * - * @return - * - IOT_SDIO_SUCCESS on success close - * - IOT_SDIO_INVALID_VALUE on NULL pxSdioHandle or already closed handle. - */ -int32_t iot_sdio_close( IotSdioSlotHandle_t const pxSdioHandle ); - -/*! - * @brief iot_sdio_card_connect() is used to connect SDIO card. - * - * This API should perform card connection sequence as specified in - * section 3.1.2 in "SD Specification Part E1 SDIO" - * - * @param[in] pxSdioHandle Handle to sdio card slot instance returned in - * iot_sdio_open() - * - * @return - * - IOT_SDIO_SUCCESS if card if successfully connected. - * - IOT_SDIO_INVALID_VALUE if any parameter is invalid. - * - IOT_SDIO_HOST_NOT_READY if host controller is not initialized. - * - IOT_SDIO_SWITCH_VOLTAGE_FAIL if card failed to respond to voltage switch - * command (CMD11) or card responded to CMD11 but failed to switch voltage. - * - IOT_SDIO_INVALID_CARD if card is invalid (memory only card) - * - IOT_SDIO_SEND_RELATIVE_ADDRESS_FAIL if Send Relative Address (CMD3) failed. - * - IOT_SDIO_SELECT_CARD_FAIL if Select Card (CMD7) failed. - * - IOT_SDIO_GET_CARD_CAPABILITY_FAIL if failed to get card capability (CCCR). - * - IOT_SDIO_READ_CIS_FAIL if failed to read common CIS tuples from card. - * - IOT_SDIO_SET_DATA_BUS_WIDTH_FAIL if failed to set maximum data bus width. - * - IOT_SDIO_SELECT_BUS_TIMING_FAIL if failed to switch to card supported timing mode. - */ -int32_t iot_sdio_card_connect( IotSdioSlotHandle_t const pxSdioHandle ); - -/*! - * @brief iot_sdio_card_disconnect() is used to disconnect SDIO card. - * - * This API should soft reset all I/O functions in sdio card and de-select the - * the card. - * User is not required to call this api before trying to re-connect the card. - * - * @param[in] pxSdioHandle Handle to sdio card slot instance returned in - * iot_sdio_open() - * - * @return - * - IOT_SDIO_SUCCESS if sdio card is successfully reset and de-selected. - * - IOT_SDIO_INVALID_VALUE if any parameter is invalid. - * - IOT_SDIO_TRANSFER_FAIL is failed to reset(write CCCR reg) or de-select(CMD7) card. - */ -int32_t iot_sdio_card_disconnect( IotSdioSlotHandle_t const pxSdioHandle ); - -/*! - * @brief iot_sdio_card_reset() is used to reset the sdio card in the target slot. - * This API should soft reset all I/O functions in sdio card. - * - * @param[in] pxSdioHandle Handle to sdio card slot instance returned in - * iot_sdio_open() - * - * @return - * - IOT_SDIO_SUCCESS if sdio card is successfully reset. - * - IOT_SDIO_INVALID_VALUE if any parameter is invalid. - * - IOT_SDIO_TRANSFER_FAIL is failed to reset(write CCCR reg) card. - */ -int32_t iot_sdio_card_reset( IotSdioSlotHandle_t const pxSdioHandle ); - -/*! - * @brief iot_sdio_io_write_direct() implements the write portion of CMD52. - * It is used to write 1 byte to a single register within the - * register space of a card I/O function. - * - * @param[in] pxSdioHandle Handle to sdio card slot instance returned in - * iot_sdio_open(). - * @param[in] eFunc IO function number range from eSdioFunction0 - * to eSdioFunction7. - * @param[in] ulRegAddr The address of the byte of data inside of the - * selected function to write. - * Range is 0 - 0x1ffff. - * @param[in/out] pucData In: data to be written to selected address - * Out: If bRaw (read after write) is == false, - * it is same as the input data. - * If bRaw (read after write) is == true, - * it contains value read from the same - * address after write. - * @param[in] bRaw The read after write flag. - * - * @return - * - IOT_SDIO_SUCCESS on success. - * - IOT_SDIO_INVALID_VALUE if any parameter is invalid. - * - IOT_SDIO_TRANSFER_FAIL if failed to send command to for receive - * response from card. - */ -int32_t iot_sdio_io_write_direct( IotSdioSlotHandle_t const pxSdioHandle, - IotSdioFunction_t eFunc, - uint32_t ulRegAddr, - uint8_t * pucData, - bool bRaw ); - -/*! - * @brief iot_sdio_io_read_direct() implements the read portion of CMD52. - * It is used to read 1 byte from a single register within the - * register space of a card I/O function. - * - * @param[in] pxSdioHandle Handle to sdio card slot instance returned in - * iot_sdio_open(). - * @param[in] eFunc IO function number range from eSdioFunction0 - * to eSdioFunction7. - * @param[in] ulRegAddr The address of the byte of data inside of the - * selected function to read. - * Range is 0 - 0x1ffff. - * @param[out] pucData Contains data read when command succeeded. - * - * @return - * - IOT_SDIO_SUCCESS on success. - * - IOT_SDIO_INVALID_VALUE if any parameter is invalid. - * - IOT_SDIO_TRANSFER_FAIL if failed to send command or receive - * response from card. - */ -int32_t iot_sdio_io_read_direct( IotSdioSlotHandle_t const pxSdioHandle, - IotSdioFunction_t eFunc, - uint32_t ulRegAddr, - uint8_t * pucData ); - -/*! - * @brief iot_sdio_io_write_extended() implements the write portion of CMD53. - * It is used to write multiple bytes or blocks to a single address - * or incremental addresses within the register space in a I/O - * function. It provides highest transfer rate possible. - * - * @param[in] pxSdioHandle Handle to sdio card slot instance returned in - * iot_sdio_open(). - * @param[in] eFunc IO function number range from eSdioFunction0 - * to eSdioFunction7. - * @param[in] bBlockMode Set true to transfer on block basis. - * Set false to transfer on byte basis. - * @param[in] bOpcode Set true to write multiple bytes to - * incrementing addresses. - * Set false to write multiple bytes to a fixed - * address. - * @param[in] ulRegAddr Start Address of I/O register to write. - * Range is 0 - 0x1ffff. - * @param[in] pucBuf Buffer that contains data to write. - * @param[in] ulCount Number of bytes to write if bBlockMode is false. - * Number of blocks to write if bBlockMode is true. - * Range is 0 - 0x1ff - * When bBlockMode is false, a value of 0 shall - * cause 512 bytes to be written. - * When bBlockMode is true, a value of 0 shall - * cause infinite blocks to be written until - * iot_sdio_abort_io is called. - * - * @return - * - IOT_SDIO_SUCCESS on success. - * - IOT_SDIO_INVALID_VALUE if any parameter is invalid. - * - IOT_SDIO_TRANSFER_FAIL if failed to send command or receive - * response from card. - */ -int32_t iot_sdio_io_write_extended( IotSdioSlotHandle_t const pxSdioHandle, - IotSdioFunction_t eFunc, - bool bBlockMode, - bool bOpcode, - uint32_t ulRegAddr, - uint8_t * pucBuf, - uint32_t ulCount ); - -/*! - * @brief iot_sdio_io_read_extended() implements the read portion of CMD53. - * It is used to read multiple bytes or blocks from a single address - * or incremental addresses within the register space in a I/O - * function. It provides highest transfer rate possible. - * - * @param[in] pxSdioHandle Handle to sdio card slot instance returned in - * iot_sdio_open(). - * @param[in] eFunc IO function number range from eSdioFunction0 - * to eSdioFunction7. - * @param[in] bBlockMode Set true to transfer on block basis. - * Set false to transfer on byte basis. - * @param[in] bOpcode Set true to read multiple bytes from - * incrementing addresses. - * Set false to read multiple bytes from a fixed - * address. - * @param[in] ulRegAddr Start Address of I/O register to read. - * Range is 0 - 0x1ffff. - * @param[out] pucBuf Buffer to receive read data. - * @param[in] ulCount Number of bytes to read if bBlockMode is false. - * Number of blocks to read if bBlockMode is true. - * Range is 0 - 0x1ff - * When bBlockMode is false, a value of 0 shall - * cause 512 bytes to be read. - * When bBlockMode is true, a value of 0 shall - * cause infinite blocks to be read until - * iot_sdio_abort_io is called. - * - * @return - * - IOT_SDIO_SUCCESS on success. - * - IOT_SDIO_INVALID_VALUE if any parameter is invalid. - * - IOT_SDIO_TRANSFER_FAIL if failed to send command or receive - * response from card. - */ -int32_t iot_sdio_io_read_extended( IotSdioSlotHandle_t const pxSdioHandle, - IotSdioFunction_t eFunc, - bool bBlockMode, - bool bOpcode, - uint32_t ulRegAddr, - uint8_t * pucBuf, - uint32_t ulCount ); - -/*! - * @brief iot_sdio_set_io_function_callback() is used to set IOFunctionCallback for each I/O function the - * card supports. - * - * IOFunctionCallback for an card I/O function is invoked when the corresponding I/O function - * pending interrupt bit is set in the Card's CCCR. Since the I/O function number is parameter to - * IOFunctionCallback, user can also implement one single IOFunctionCallback and set it for all - * I/O functions. Inside the IOFunctionCallback, different action can be taken according the I/O - * function number. - * - * The job of a IOFunctionCallback is to service the interrupt condition caused by the - * corresponding I/O function. It should read/write to the function unique area on - * the card to clear pending interrupt. The specific implementation for each - * IOFunctionCallback should be according to the specification of SDIO function it is - * written for. - * - * @param[in] pxSdioHandle Handle to sdio card slot instance returned in - * iot_sdio_open(). - * @param[in] eFunc IO function number range from eSdioFunction0 - * to eSdioFunction7. - * @param[in] xIOFunctionCallback IOFunctionCallback to be set for I/O function eFunc. - * @param[in] pvIOFunctionCallbackUserContext User context to be passed when IOFunctionCallback is - * invoked. - * - * @return - * - IOT_SDIO_SUCCESS on success. - * - IOT_SDIO_INVALID_VALUE if any parameter is invalid. - */ -int32_t iot_sdio_set_io_function_callback( IotSdioSlotHandle_t const pxSdioHandle, - IotSdioFunction_t eFunc, - IotSdioIOFunctionCallback_t xIOFunctionCallback, - void * pvIOFunctionCallbackUserContext ); - -/*! - * @brief iot_sdio_set_sdio_callback() is used to set sdio card interrupt callback. - * - * @param[in] pxSdioHandle Handle to sdio card slot instance returned in - * iot_sdio_open(). - * @param[in] xSdioCallback Callback function to be called from driver. - * @param[in] pvSdioCallbackUserContext User context to be passed when callback is called. - * - * @return - * - IOT_SDIO_SUCCESS on success. - * - IOT_SDIO_INVALID_VALUE if any parameter is invalid. - */ -int32_t iot_sdio_set_sdio_callback( IotSdioSlotHandle_t const pxSdioHandle, - IotSdioCallback_t xSdioCallback, - void * pvSdioCallbackUserContext ); - -/** - * @brief iot_sdio_ioctl() is Used for various sdio control function. - * - * @param[in] pxSdioHandle Handle to sdio card slot instance returned in iot_sdio_open(). - * @param[in] xSdioIoctlRequest Should be one of IotSdioIoctlRequest_t. - * @param[in,out] pvBuffer The configuration values for the IOCTL request. - * - * @return - * - IOT_SDIO_SUCCESS on success. - * - IOT_SDIO_INVALID_VALUE if any parameter is invalid or not supported by host or card. - * - IOT_SDIO_TRANSFER_FAIL if failed to send command to or receive response from card. - * - IOT_SDIO_SET_CARD_BLOCK_SIZE_FAIL if eSDIOSetFuncBlockSize ioctl request failed. - * - IOT_SDIO_LOW_SPEED_CARD if switching speed failed due low speed only card. - * (for eSDIOSwitchToHighSpeed request only). - * - IOT_SDIO_SWITCH_HIGH_SPEED_FAIL if sdio card supports high speed mode but failed - * to switch to high speed mode. (for eSDIOSwitchToHighSpeed only). - * - IOT_SDIO_ASYNC_INT_NOT_SUPPORTED if card doesn't support async interrupt mode. - * (for eSDIOEnableAsyncIrqMode only). - * - IOT_SDIO_READ_CIS_FAIL if read cis command execution failed. (for eSDIOReadCis only) - * - IOT_SDIO_FAIL other failures that is unrelated to command execution. - */ -int32_t iot_sdio_ioctl( IotSdioSlotHandle_t const pxSdioHandle, - IotSdioIoctlRequest_t xSdioIoctlRequest, - void * const pvBuffer ); - -/** - * @} - */ - -#endif /* _IOT_SDIO_H_ */ diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/common_io/include/iot_spi.h b/bk7235/liteos_m/bk_sdk_armino/middleware/compal/common_io/include/iot_spi.h deleted file mode 100755 index 4ccf5ff4edd028eb9ab28cb8f6a0a377ccae2d15..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/common_io/include/iot_spi.h +++ /dev/null @@ -1,439 +0,0 @@ -/* - * FreeRTOS Common IO V0.1.3 - * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * http://aws.amazon.com/freertos - * http://www.FreeRTOS.org - */ - -/** - * @file iot_spi.h - * @brief File for the APIs of SPI called by application layer. - */ -#ifndef _IOT_SPI_H_ -#define _IOT_SPI_H_ - -/* Standard includes. */ -#include - -/** - * @defgroup iot_spi SPI Abstraction APIs. - * @{ - */ - -/** - * @brief The return codes for the methods in SPI. - */ -#define IOT_SPI_SUCCESS ( 0 ) /*!< SPI operation completed successfully. */ -#define IOT_SPI_INVALID_VALUE ( 1 ) /*!< At least one parameter is invalid. */ -#define IOT_SPI_WRITE_FAILED ( 2 ) /*!< SPI driver returns error when performing write operation. */ -#define IOT_SPI_READ_FAILED ( 3 ) /*!< SPI driver returns error when performing read operation. */ -#define IOT_SPI_TRANSFER_ERROR ( 4 ) /*!< SPI driver returns error when performing transfer. */ -#define IOT_SPI_BUS_BUSY ( 5 ) /*!< SPI bus is busy at current time. */ -#define IOT_SPI_NOTHING_TO_CANCEL ( 6 ) /*!< No ongoing operation when cancel operation is performed. */ -#define IOT_SPI_FUNCTION_NOT_SUPPORTED ( 7 ) /*!< SPI operation is not supported. */ - - -/** - * @brief The SPI return status from Async operations. - */ -typedef enum -{ - eSPISuccess = IOT_SPI_SUCCESS, /*!< SPI operation completed successfully. */ - eSPIWriteError = IOT_SPI_WRITE_FAILED, /*!< SPI driver returns error when performing write operation. */ - eSPIReadError = IOT_SPI_READ_FAILED, /*!< SPI driver returns error when performing read operation. */ - eSPITransferError = IOT_SPI_TRANSFER_ERROR, /*!< SPI driver returns error when performing transfer. */ -} IotSPITransactionStatus_t; - -/** - * @brief The SPI Modes denoting the clock polarity - * and clock phase. - */ -typedef enum -{ - eSPIMode0, /*!< CPOL = 0 and CPHA = 0 */ - eSPIMode1, /*!< CPOL = 0 and CPHA = 1 */ - eSPIMode2, /*!< CPOL = 1 and CPHA = 0 */ - eSPIMode3, /*!Example timer delay execution - * The callback function is called to signal when the timer reaches the count (delay) - * set by the caller. - * @code{c} - * - * IotTimerHandle_t xTimerHandle; - * - * xTimerHandle = iot_timer_open( ltestIotTimerInstance); - * // assert( xTimerHandle == NULL ); - * - * // Set the callback to call prvTimerCallbackFunction() when delay reached. - * iot_timer_set_callback(xTimerHandle, prvTimerCallbackFunction, NULL); - * - * // Set the timer delay to be TIMER_DEFAULT_DELAY_US - * lRetVal = iot_timer_delay(xTimerHandle, TIMER_DEFAULT_DELAY_US ); - * // assert( lRetVal != IOT_TIMER_SUCCESS ); - * - * //Start the timer - * lRetVal = iot_timer_start(xTimerHandle); - * // assert ( lRetVal != IOT_TIMER_SUCCESS); - * - * // Wait for the Delay callback to be called. Inside of prvTimerCallbackFunction() - * // the function will use xSemaphoreGive() to signal completion. - * lRetVal = xSemaphoreTake(IotTimerSemaphore, portMAX_DELAY); - * // assert( lRetVal != TRUE ); - * - * lRetVal = iot_timer_close(xTimerHandle); - * //assert ( lRetVal != IOT_TIMER_SUCCESS); - * @endcode - * - * @return - * - IOT_TIMER_SUCCESS on success - * - IOT_TIMER_INVALID_VALUE if pxTimerHandle or ulMicroSeconds pointers are NULL - * - IOT_TIMER_NOT_RUNNING if timer hasn't been started. - * - IOT_TIMER_SET_FAILED on error. - */ -int32_t iot_timer_delay( IotTimerHandle_t const pxTimerHandle, - uint32_t ulDelayMicroSeconds ); - -/** - * @brief iot_timer_cancel is used to cancel any existing delay call. - * If a call to iot_timer_delay() was made earlier, calling iot_timer_cancel - * will cancel that delay call, so no call-back will be called. - * - * @param[in] pxTimerHandle handle to Timer interface returned in - * iot_timer_open() - * - * @return - * - IOT_TIMER_SUCCESS on success - * - IOT_TIMER_INVALID_VALUE if pxTimerHandle is NULL - * - IOT_TIMER_FUNCTION_NOT_SUPPORTED if timer can't be cancelled. - * - IOT_TIMER_NOTHING_TO_CANCEL if there is no timer running to cancel. - */ -int32_t iot_timer_cancel( IotTimerHandle_t const pxTimerHandle ); - -/** - * @brief iot_timer_close is used to de-initializes the timer, stops the timer - * if it was started and cancels the delay calls, and resets the timer value. - * - * @param[in] pxTimerHandle handle to Timer interface returned in - * iot_timer_open() - * - * @return - * - IOT_TIMER_SUCCESS on success - * - IOT_TIMER_INVALID_VALUE if - * - pxTimerHandle is NULL. - * - pxTimerHandle not open (previously closed). - */ -int32_t iot_timer_close( IotTimerHandle_t const pxTimerHandle ); - -/** - * @} - */ - -#endif /* ifndef _IOT_TIMER_H_ */ diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/common_io/include/iot_tsensor.h b/bk7235/liteos_m/bk_sdk_armino/middleware/compal/common_io/include/iot_tsensor.h deleted file mode 100755 index cb4601f9d380c08413670169c476b99a7338317f..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/common_io/include/iot_tsensor.h +++ /dev/null @@ -1,223 +0,0 @@ -/* - * FreeRTOS Common IO V0.1.3 - * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * http://aws.amazon.com/freertos - * http://www.FreeRTOS.org - */ - -/** - * @file iot_tsensor.h - * @brief File for the APIs of TempSensor called by application layer. - */ - -#ifndef _IOT_TSENSOR_H_ -#define _IOT_TSENSOR_H_ - -/** - * @defgroup iot_tsensor TempSensor Abstraction APIs. - * @{ - */ - -#include - -/** - * @brief Return values used by tsensor driver - */ -#define IOT_TSENSOR_SUCCESS ( 0 ) /*!< TempSensor operation completed successfully.*/ -#define IOT_TSENSOR_INVALID_VALUE ( 1 ) /*!< At least one parameter is invalid.*/ -#define IOT_TSENSOR_DISABLED ( 2 ) /*!< TempSensor is disabled.*/ -#define IOT_TSENSOR_CLOSED ( 3 ) /*!< TempSensor instance is not open.*/ -#define IOT_TSENSOR_GET_TEMP_FAILED ( 4 ) /*!< TempSensor failed to get the temperature.*/ -#define IOT_TSENSOR_SET_FAILED ( 5 ) /*!< TempSensor set threshold operation failed.*/ -#define IOT_TSENSOR_NOT_SUPPORTED ( 6 ) /*!< TempSensor operation not supported.*/ - -/** - * @brief tsensor threshold reached status - */ -typedef enum -{ - eTsensorMinThresholdReached, /*!< min temperature threshold reached status */ - eTsensorMaxThresholdReached /*!< max temperature threshold reached status */ -} IotTsensorStatus_t; - -/** - * @brief Ioctl request types. - */ -typedef enum -{ - eTsensorSetMinThreshold, /*!< Set min temperature threshold using IotI2CIoctlConfig_t. Takes int32_t value in degrees celcius.*/ - eTsensorSetMaxThreshold, /*!< Set max temperature threshold using IotI2CIoctlConfig_t . Takes int32_t value in degrees celcius.*/ - eTsensorGetMinThreshold, /*!< Get min temperature threshold using IotI2CIoctlConfig_t. Returns int32_t value in degrees celcius.*/ - eTsensorGetMaxThreshold, /*!< Get max temperature threshold using IotI2CIoctlConfig_t. Returns int32_t value in degrees celcius.*/ - eTsensorPerformCalibration /*!< Perform calibration of the sensor */ -} IotTsensorIoctlRequest_t; - -/** - * @brief tsensor descriptor type defined in the source file. - */ -struct IotTsensorDescriptor; - -/** - * @brief IotTsensorHandle_t type is the tsensor handle returned by calling iot_tsensor_open() - * this is initialized in open and returned to caller. Caller must pass this pointer - * to the rest of the APIs. - */ -typedef struct IotTsensorDescriptor * IotTsensorHandle_t; - -/** - * @brief The callback function for completion of Tsensor operation. - * - * @param[in] xStatus tsensor threshold reached status - * @param[in] pvUserContext user provid context - */ -typedef void ( * IotTsensorCallback_t)( IotTsensorStatus_t xStatus, - void * pvUserContext ); - -/** - * @brief iot_tsensor_open is used to initialize the temperature sensor. - * It sets up the clocks and power etc, if the sensor is internal - * and sets up the communication channel if the sensor is external. - * - * @param[in] lTsensorInstance The instance of the tsensor to initialize. The instance - * number is platform specific. i,e if you have more than one temperature - * ensors, then 2 instances point to 2 different sensors. - * - * @return - * - Handle to tsensor interface on success. - * - NULL if - * - lTesnsorInstance is invalid. - * - instance is already open. - */ -IotTsensorHandle_t iot_tsensor_open( int32_t lTsensorInstance ); - -/** - * @brief Set the callback to be called when a threshold is reached on the sensor. - * The caller must set the threshold level using IOCTL before the callback can be called. - * - * @note Single callback is used per instance for both min and max threshold points being reached. - * @note Newly set callback overrides the one previously set - * - * @warning If input handle or if callback function is NULL, this function silently takes no action. - * - * @warning If threshold detection is not supported by the hardware, then the callback function will not work. - * - * @param[in] xTsensorHandle Handle to tsensor driver returned in open() call - * @param[in] xCallback The callback function to be called on completion of transaction. - * @param[in] pvUserContext user provid context - */ -void iot_tsensor_set_callback( IotTsensorHandle_t const xTsensorHandle, - IotTsensorCallback_t xCallback, - void * pvUserContext ); - -/** - * @brief iot_tsensor_enable is used to enable the temperature sensor - * to start reading the temperature and trigger thresholds (if any were set and supported) - * - * @param[in] xTsensorHandle Handle to tsensor driver returned in - * iot_tsensor_open - * - * @return - * - IOT_TSENSOR_SUCCESS on success - * - IOT_TSENSOR_INVALID_VALUE if xTsensorHandle is NULL. - */ -int32_t iot_tsensor_enable( IotTsensorHandle_t const xTsensorHandle ); - -/** - * @brief iot_tsensor_disable is used to disable the temperature sensor - * which stops monitoring the temperature. - * - * @param[in] xTsensorHandle Handle to tsensor driver returned in - * iot_tsensor_open - * - * @return - * - IOT_TSENSOR_SUCCESS on success - * - IOT_TSENSOR_INVALID_VALUE if xTsensorHandle is NULL. - */ -int32_t iot_tsensor_disable( IotTsensorHandle_t const xTsensorHandle ); - -/** - * @brief iot_tsensor_get_temp is used to get the current temperature - * read from the sensor. - * - * @param[in] xTsensorHandle handle to tsensor driver returned in - * iot_tsensor_open - * @param[out] plTemp temperature read from the sensor. - * - * @return - * - IOT_TSENSOR_SUCCESS on success - * - IOT_TSENSOR_INVALID_VALUE if - * - xTsensorHandle is NULL - * - lTemp is NULL - * - IOT_TSENSOR_DISABLED if tsensor instance has been disabled with call to iot_tsensor_disable(). - * - IOT_TSENSOR_GET_TEMP_FAILED if error occured reading the temperature. - */ -int32_t iot_tsensor_get_temp( IotTsensorHandle_t const xTsensorHandle, - int32_t * plTemp ); - -/** - * @brief iot_tsensor_ioctl is used to set tsensor configuration - * and tsensor properties like minimum threshold, maximum threshold value, etc. - * Supported IOCTL requests are defined in aws_hal_Tsensor_Ioctl_Request_t - * - * @param[in] xTsensorHandle handle to tsensor driver returned in - * iot_tsensor_open - * @param[in] xRequest configuration request. - * @param[in,out] pvBuffer buffer holding tsensor set and get values. - * - * @return - * - IOT_TSENSOR_SUCCESS on success - * - IOT_TSENSOR_INVALID_VALUE - * - xTsensorHandle is NULL - * - xRequest is invalid - * - pvBuffer is NULL (excluding eTsensorPerformCalibration) - * - IOT_TSENSOR_CLOSED if instance not in open state. - * - IOT_TSENSOR_DISABLED if tsensor instance has been disabled with call to iot_tsensor_disable(). - * - IOT_TSENSOR_GET_TEMP_FAILED if error occured reading the temperature. - * - IOT_TSENSOR_SET_FAILED if set threshold operation failed. - * - IOT_TSENSOR_NOT_SUPPORTED valid if xRequest feature not supported. - * @note: If eTsensorSetMinThreshold or eTsensorSetMaxThreshold ioctl is supported, then the - * corresponding eTsensorGetMinThreshold and eTsensorGetMaxThreshold must also be supported. - */ -int32_t iot_tsensor_ioctl( IotTsensorHandle_t const xTsensorHandle, - IotTsensorIoctlRequest_t xRequest, - void * const pvBuffer ); - -/** - * @brief iot_tsensor_close is used to de-initialize Tsensor. - * - * @param[in] xTsensorHandle handle to tsensor driver returned in - * iot_tsensor_open - * - * @return - * - IOT_TSENSOR_SUCCESS on success - * - IOT_TSENSOR_INVALID_VALUE if - * - xTensorHandle is NULL - * - not in open state (already closed) - */ -int32_t iot_tsensor_close( IotTsensorHandle_t const xTsensorHandle ); - - -/** - * @} - */ -/* end of group iot_tsensor */ - -#endif /* ifndef _IOT_TSENSOR_H_ */ diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/common_io/include/iot_uart.h b/bk7235/liteos_m/bk_sdk_armino/middleware/compal/common_io/include/iot_uart.h deleted file mode 100755 index f239a82fa1218675975fdef94c4020d3f1ca6a04..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/common_io/include/iot_uart.h +++ /dev/null @@ -1,411 +0,0 @@ -/* - * FreeRTOS Common IO V0.1.3 - * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * http://aws.amazon.com/freertos - * http://www.FreeRTOS.org - */ - -/** - * @file iot_uart.h - * @brief File for the HAL APIs of UART called by application layer. - */ -#ifndef _IOT_UART_H_ -#define _IOT_UART_H_ - -/* Standard includes. */ -#include -#include - -/** - * @defgroup IOT_UART UART Abstraction APIs. - * @{ - */ - -/** - * @brief The default baud rate for a given UART port. - */ -#define IOT_UART_BAUD_RATE_DEFAULT ( 115200 ) - -/** - * @brief Error codes returned by every function module in UART HAL. - */ -#define IOT_UART_SUCCESS ( 0 ) /*!< UART operation completed successfully. */ -#define IOT_UART_INVALID_VALUE ( 1 ) /*!< At least one parameter is invalid. */ -#define IOT_UART_WRITE_FAILED ( 2 ) /*!< UART driver returns error when performing write operation. */ -#define IOT_UART_READ_FAILED ( 3 ) /*!< UART driver returns error when performing read operation. */ -#define IOT_UART_BUSY ( 4 ) /*!< UART bus is busy at current time. */ -#define IOT_UART_NOTHING_TO_CANCEL ( 5 ) /*!< No ongoing operation when cancel is performed. */ -#define IOT_UART_FUNCTION_NOT_SUPPORTED ( 6 ) /*!< UART operation is not supported. */ - -/** - * @brief UART read/write operation status values - */ -typedef enum -{ - eUartWriteCompleted, /*!< UART operation write completed successfully. */ - eUartReadCompleted, /*!< UART operation read completed successfully. */ - eUartLastWriteFailed, /*!< UART driver returns error when performing write operation. */ - eUartLastReadFailed, /*!< UART driver returns error when performing read operation. */ -} IotUARTOperationStatus_t; - -/** - * @brief UART parity mode - */ -typedef enum -{ - eUartParityNone, /*!< UART parity as none. */ - eUartParityOdd, /*!< UART parity as odd. */ - eUartParityEven, /*!< UART parity as even. */ -} IotUARTParity_t; - -/** - * @brief UART stop bits - */ -typedef enum -{ - eUartStopBitsOne, /*!< UART character stop is one bit. */ - eUartStopBitsTwo, /*!< UART character stop is two bits. */ -} IotUARTStopBits_t; - -/** - * @brief The callback function for completion of UART operation. - * - * @param[out] xStatus UART asynchronous operation status. - * @param[in] pvUserContext User Context passed when setting the callback. - * This is not used or modified by the driver. The context - * is provided by the caller when setting the callback, and is - * passed back to the caller in the callback. - */ -typedef void ( * IotUARTCallback_t )( IotUARTOperationStatus_t xStatus, - void * pvUserContext ); - - -/** - * @brief The UART descriptor type defined in the source file. - */ -struct IotUARTDescriptor; - -/** - * @brief IotUARTHandle_t is the handle type returned by calling iot_uart_open(). - * This is initialized in open and returned to caller. The caller must pass - * this pointer to the rest of APIs. - */ -typedef struct IotUARTDescriptor * IotUARTHandle_t; - -/** - * @brief Ioctl requests for UART HAL. - */ -typedef enum -{ - eUartSetConfig, /** Sets the UART configuration according to @IotUARTConfig_t. */ - eUartGetConfig, /** Gets the UART configuration according to @IotUARTConfig_t. */ - eGetTxNoOfbytes, /** Get the number of bytes sent in write operation. */ - eGetRxNoOfbytes /** Get the number of bytes received in read operation. */ -} IotUARTIoctlRequest_t; - -/** - * @brief Configuration parameters for the UART. - * - * The application will send the user configuration in the form of the - * following structure in ioctl. - */ -typedef struct -{ - uint32_t ulBaudrate; /**< The baud rate to be set for the UART port. */ - IotUARTParity_t xParity; /**< The parity to be set for the UART port, defined in IotUARTParity_t. */ - IotUARTStopBits_t xStopbits; /**< The stop bits to be set for the UART port, defined in IotUARTStopBits_t. */ - uint8_t ucWordlength; /**< The word length to be set for the UART port. */ - uint8_t ucFlowControl; /**< The flow control to be set for the UART port: 0 is disabled and 1 is enabled. */ -} IotUARTConfig_t; - -/** - * @brief Initializes the UART peripheral of the board. - * - * The application should call this function to initialize the desired UART port. - * - * @warning Once opened, the same UART instance must be closed before calling open again. - * - * @param[in] lUartInstance The instance of the UART port to initialize. - * - * @return - * - 'the handle to the UART port (not NULL)', on success. - * - 'NULL', if - * - invalid instance number - * - open same instance more than once before closing it - * - * Example - * @code{c} - * // These two buffers can contain 32 bytes for reading and writing. - * uint8_t cpBuffer[ 32 ] = { 0 }; - * uint8_t cpBufferRead[ 32 ] = { 0 }; - * - * IotUARTHandle_t xOpen; - * int32_t lRead, lWrite, lClose; - * BaseType_t xCallbackReturn; - * uint8_t ucPort = 1; // Each UART peripheral will be assigned an integer. - * - * xOpen = iot_uart_open( ucPort ); - * if( xOpen != NULL ) - * { - * iot_uart_set_callback( xOpen, prvReadWriteCallback, NULL ); - * - * lWrite = iot_uart_write_async( xOpen, cpBuffer, testIotUART_READ_BUFFER_LENGTH ); - * // assert(IOT_UART_SUCCESS, lWrite) - * // Wait for asynchronous write to complete - * xCallbackReturn = xSemaphoreTake( ( SemaphoreHandle_t ) &xUartSemaphore, IotUART_DEFAULT_SEMPAHORE_DELAY ); - * // assert(xCallbackReturn, pdTrue) - * - * lRead = iot_uart_read_async( xOpen, cpBufferRead, testIotUART_READ_BUFFER_LENGTH ); - * // assert(IOT_UART_SUCCESS, lRead) - * - * // Wait for asynchronous read to complete - * xCallbackReturn = xSemaphoreTake( ( SemaphoreHandle_t ) &xUartSemaphore, IotUART_DEFAULT_SEMPAHORE_DELAY ); - * // assert(xCallbackReturn, pdTrue) - * } - * - * lClose = iot_uart_close( xOpen ); - * // assert(IOT_UART_SUCCESS, lClose) - * @endcode - */ -IotUARTHandle_t iot_uart_open( int32_t lUartInstance ); - -/** - * @brief Sets the application callback to be called on completion of an operation. - * - * The callback is guaranteed to be invoked when the current asynchronous operation completes, either successful or failed. - * This simply provides a notification mechanism to user's application. It has no impact if the callback is not set. - * - * @note This callback will not be invoked when synchronous operation completes. - * @note This callback is per handle. Each instance has its own callback. - * @note Single callback is used for both read_async and write_async. Newly set callback overrides the one previously set. - * @warning If the input handle is invalid, this function silently takes no action. - * - * @param[in] pxUartPeripheral The peripheral handle returned in the open() call. - * @param[in] xCallback The callback function to be called on completion of transaction (This can be NULL). - * @param[in] pvUserContext The user context to be passed back when callback is called (This can be NULL). - */ -void iot_uart_set_callback( IotUARTHandle_t const pxUartPeripheral, - IotUARTCallback_t xCallback, - void * pvUserContext ); - -/** - * @brief Starts receiving the data from UART synchronously. - * - * This function attempts to read certain number of bytes from transmitter device to a pre-allocated buffer, in synchronous way. - * Partial read might happen, e.g. no more data is available. - * And the number of bytes that have been actually read can be obtained by calling iot_uart_ioctl. - * - * @note If the number of bytes is not known, it is recommended that the application reads one byte at a time. - * - * @warning None of other read or write functions shall be called during this function. - * - * @param[in] pxUartPeripheral The peripheral handle returned in the open() call. - * @param[out] pvBuffer The buffer to store the received data. - * @param[in] xBytes The number of bytes to read. - * - * @return IOT_UART_SUCCESS on successful completion of synchronous read, - * else one of the IOT_UART_INVALID_VALUE, IOT_UART_BUSY, IOT_UART_READ_FAILED on error. - * @return - * - IOT_UART_SUCCESS, on success (all the requested bytes have been read) - * - IOT_UART_INVALID_VALUE, if - * - pxUartPeripheral is NULL - * - pxUartPeripheral is not opened yet - * - pucBuffer is NULL - * - xBytes is 0 - * - IOT_UART_READ_FAILED, if there is unknown driver error - * - IOT_UART_BUSY, if the bus is busy which means there is an ongoing operation. - */ -int32_t iot_uart_read_sync( IotUARTHandle_t const pxUartPeripheral, - uint8_t * const pvBuffer, - size_t xBytes ); - -/** - * @brief Starts the transmission of data from UART synchronously. - * - * This function attempts to write certain number of bytes from a pre-allocated buffer to a receiver device, in synchronous way. - * Partial write might happen, e.g. receiver device unable to receive more data. - * And the number of bytes that have been actually written can be obtained by calling iot_uart_ioctl. - * - * @warning None of other read or write functions shall be called during this function. - * - * @param[in] pxUartPeripheral The peripheral handle returned in the open() call. - * @param[in] pvBuffer The buffer with data to transmit. - * @param[in] xBytes The number of bytes to send. - * - * @return - * - IOT_UART_SUCCESS, on success (all the requested bytes have been write) - * - IOT_UART_INVALID_VALUE, if - * - pxUartPeripheral is NULL - * - pxUartPeripheral is not opened yet - * - pucBuffer is NULL - * - xBytes is 0 - * - IOT_UART_WRITE_FAILED, if there is unknown driver error - * - IOT_UART_BUSY, if the bus is busy which means there is an ongoing operation. - */ -int32_t iot_uart_write_sync( IotUARTHandle_t const pxUartPeripheral, - uint8_t * const pvBuffer, - size_t xBytes ); - -/** - * @brief Starts receiving the data from UART asynchronously. - * - * This function attempts to read certain number of bytes from a pre-allocated buffer, in asynchronous way. - * It returns immediately when the operation is started and the status can be check by calling iot_uart_ioctl. - * Once the operation completes, successful or not, the user callback will be invoked. - * - * Partial read might happen. - * And the number of bytes that have been actually read can be obtained by calling iot_uart_ioctl. - * - * @note In order to get notification when the asynchronous call is completed, iot_uart_set_callback must be called prior to this. - * @warning pucBuffer must be valid before callback is invoked. - * @warning None of other read or write functions shall be called during this function or before user callback. - * - * @param[in] pxUartPeripheral The peripheral handle returned in the open() call. - * @param[out] pvBuffer The buffer to store the received data. - * @param[in] xBytes The number of bytes to read. - * - * @return - * - IOT_UART_SUCCESS, on success - * - IOT_UART_INVALID_VALUE, if - * - pxUartPeripheral is NULL - * - pxUartPeripheral is not opened yet - * - pucBuffer is NULL - * - xBytes is 0 - * - IOT_UART_READ_FAILED, if there is unknown driver error - */ -int32_t iot_uart_read_async( IotUARTHandle_t const pxUartPeripheral, - uint8_t * const pvBuffer, - size_t xBytes ); - -/** - * @brief Starts the transmission of data from UART asynchronously. - * - * This function attempts to write certain number of bytes from a pre-allocated buffer to a receiver device, in asynchronous way. - * It returns immediately when the operation is started and the status can be check by calling iot_uart_ioctl. - * Once the operation completes, successful or not, the user callback will be invoked. - * - * Partial write might happen. - * And the number of bytes that have been actually written can be obtained by calling iot_uart_ioctl. - * - * @note In order to get notification when the asynchronous call is completed, iot_uart_set_callback must be called prior to this. - * - * @warning None of other read or write functions shall be called during this function. - * - * @param[in] pxUartPeripheral The peripheral handle returned in the open() call. - * @param[in] pvBuffer The buffer with data to transmit. - * @param[in] xBytes The number of bytes to send. - * - * @return - * - IOT_UART_SUCCESS, on success - * - IOT_UART_INVALID_VALUE, if - * - pxUartPeripheral is NULL - * - pxUartPeripheral is not opened yet - * - pucBuffer is NULL - * - xBytes is 0 - * - IOT_UART_WRITE_FAILED, if there is unknown driver error - */ -int32_t iot_uart_write_async( IotUARTHandle_t const pxUartPeripheral, - uint8_t * const pvBuffer, - size_t xBytes ); - -/** - * @brief Configures the UART port with user configuration. - * - * - * @note eUartSetConfig sets the UART configuration. - * This request expects the buffer with size of IotUARTConfig_t. - * - * @note eUartGetConfig gets the current UART configuration. - * This request expects the buffer with size of IotUARTConfig_t. - * - * @note eGetTxNoOfbytes returns the number of written bytes in last operation. - * This is supposed to be called in the caller task or application callback, right after last operation completes. - * This request expects 2 bytes buffer (uint16_t). - * - * - If the last operation was write, this returns the actual number of written bytes which might be smaller than the requested number (partial write). - * - If the last operation was read, this returns 0. - * - * @note eGetRxNoOfbytes returns the number of read bytes in last operation. - * This is supposed to be called in the caller task or application callback, right after last operation completes. - * This request expects 2 bytes buffer (uint16_t). - * - * - If the last operation was read, this returns the actual number of read bytes which might be smaller than the requested number (partial read). - * - If the last operation was write, this returns 0. - * - * @param[in] pxUartPeripheral The peripheral handle returned in the open() call. - * @param[in] xUartRequest The configuration request. Should be one of the values - * from IotUARTIoctlRequest_t. - * @param[in,out] pvBuffer The configuration values for the UART port. - * - * @return IOT_UART_SUCCESS on successful configuartion of UART port, - * else one of the IOT_UART_INVALID_VALUE, IOT_UART_BUSY, - * IOT_UART_FUNCTION_NOT_SUPPORTED on error. - * @return - * - IOT_UART_SUCCESS, on success - * - IOT_UART_INVALID_VALUE, if - * - pxUartPeripheral is NULL - * - pxUartPeripheral is not opened yet - * - pucBuffer is NULL with requests which needs buffer - * - IOT_UART_FUNCTION_NOT_SUPPORTED, if this board doesn't support this feature. - * - eUartSetConfig: specific configuration is not supported - */ -int32_t iot_uart_ioctl( IotUARTHandle_t const pxUartPeripheral, - IotUARTIoctlRequest_t xUartRequest, - void * const pvBuffer ); - -/** - * @brief Aborts the operation on the UART port if any underlying driver allows - * cancellation of the operation. - * - * The application should call this function to stop the ongoing operation. - * - * @param[in] pxUartPeripheral The peripheral handle returned in the open() call. - * - * @return - * - IOT_UART_SUCCESS, on success - * - IOT_UART_INVALID_VALUE, if - * - pxUartPeripheral is NULL - * - pxUartPeripheral is not opened yet - * - IOT_UART_NOTHING_TO_CANCEL, if there is no on-going transaction. - * - IOT_UART_FUNCTION_NOT_SUPPORTED, if this board doesn't support this operation. - */ -int32_t iot_uart_cancel( IotUARTHandle_t const pxUartPeripheral ); - -/** - * @brief Stops the operation and de-initializes the UART peripheral. - * - * - * @param[in] pxUartPeripheral The peripheral handle returned in the open() call. - * - * @return - * - IOT_UART_SUCCESS, on success - * - IOT_UART_INVALID_VALUE, if - * - pxUartPeripheral is NULL - * - pxUartPeripheral is not opened yet - */ -int32_t iot_uart_close( IotUARTHandle_t const pxUartPeripheral ); - - -/** - * @} - */ -/* end of group IOT_UART */ -#endif /* _IOT_UART_H_ */ diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/common_io/include/iot_usb_device.h b/bk7235/liteos_m/bk_sdk_armino/middleware/compal/common_io/include/iot_usb_device.h deleted file mode 100755 index 50d4dbe26405c1e199238a8faeaf2a1ac9758217..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/common_io/include/iot_usb_device.h +++ /dev/null @@ -1,568 +0,0 @@ -/* - * FreeRTOS Common IO V0.1.3 - * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * http://aws.amazon.com/freertos - * http://www.FreeRTOS.org - */ - -/** - * @file iot_usb_device.h - * @brief File for the APIs of USB device called by application or class layer. - */ -#ifndef _IOT_USB_DEVICE_H_ -#define _IOT_USB_DEVICE_H_ - -/** - * @brief Return values used by this driver - */ -#define IOT_USB_DEVICE_SUCCESS ( 0 ) /*!< USB operation completed successfully. */ -#define IOT_USB_DEVICE_ERROR ( 1 ) /*!< USB device error. */ -#define IOT_USB_DEVICE_BUSY ( 2 ) /*!< USB device busy. */ -#define IOT_USB_DEVICE_INVALID_VALUE ( 3 ) /*!< At least one parameter is invalid. */ -#define IOT_USB_DEVICE_WRITE_FAILED ( 4 ) /*!< USB device write operation failed. */ -#define IOT_USB_DEVICE_READ_FAILED ( 5 ) /*!< USB device read operation failed. */ -#define IOT_USB_DEVICE_FUNCTION_NOT_SUPPORTED ( 6 ) /*!< USB device function not supported. */ -#define IOT_USB_DEVICE_NOTHING_TO_CANCEL ( 7 ) /*!< No operation in progress to cancel. */ - -/** - * @brief Control endpoint index. - */ -#define IOT_USB_CONTROL_ENDPOINT ( 0U ) - -/** - * @brief The setup packet size of USB control transfer. - */ -#define IOT_USB_SETUP_PACKET_SIZE ( 8U ) - -/** - * @brief USB endpoint mask. - */ -#define IOT_USB_ENDPOINT_NUMBER_MASK ( 0x0FU ) - -/** - * @brief Default invalid value or the endpoint callback length of cancelled transfer. - */ -#define IOT_USB_UNINITIALIZED_VAL_32 ( 0xFFFFFFFFU ) - -/** - * @defgroup iot_usb_device usb device Abstraction APIs. - * @{ - */ - -/** - * @brief common notify event types in device callback. - */ -typedef enum -{ - eUSBDeviceBusResetEvent, /*!< USB bus reset signal detected. Signal is initiated from USB Host. */ - eUSBDeviceLPMState1Event, /*!< USB LPM (link power management) state 1 event: for usb 2.0, correspond to L1 sleep, host initialize - * LPM extended transaction; for usb 3.0, correspond to U1 standby, both device and host can initialize. */ - eUSBDeviceLPMState2Event, /*!< USB LPM state 2 event: for usb 2.0, correspond to L2 suspend, host nees to support to trigger it after - * 3ms of inactivity; for usb 3.0, correspond to U2 standby, both device and host can initialize. */ - eUSBDeviceLPMState3Event, /*!< USB LPM state 3 event: for usb 2.0, correspond to L3 off, disconnect or power off will trigger it; - * for usb 3.0, correspond to U3 suspend, it can only be initialized by host. */ - eUSBDeviceLPMState1ResumeEvent, /*!< USB resume event from LPM state 1: for usb 2.0 and 3.0, both device and host can initialize - * resume signaling. */ - eUSBDeviceLPMState2ResumeEvent, /*!< USB resume event from LPM state 2: for usb 2.0 and 3.0, both device and host can initialize - * resume signaling. */ - eUSBDeviceLPMState3ResumeEvent, /*!< USB resume event from LPM state 3: for usb 2.0, L3 is off state, port needs reset or power on; for usb 3.0, - * both device and host can initialize resume signaling.*/ - eUSBDeviceErrorEvent, /*!< An error is happened in the bus. */ - eUSBDeviceDetachEvent, /*!< USB device is disconnected from a host. */ - eUSBDeviceAttachEvent, /*!< USB device is connected to a host. */ -} IotUsbDeviceEvent_t; - -/** - * @brief Ioctl request types. - */ -typedef enum -{ - eUSBDeviceGetSpeed, /*!< Get device speed. Return uint8_t integer. */ - eUSBDeviceGetAddress, /*!< Get device address. Return an uint8_t integer range from 1~127. */ - eUSBDeviceSetAddress, /*!< Set device address. Take an uint8_t integer to set it as address. */ - eUSBDeviceGetEndpointStatus, /*!< Get endpoint status. Return IotUsbDeviceEndpointStatus_t type. */ - eUSBDeviceGetState, /*!< Get device state. Return IotUsbDeviceState_t. */ - eUSBDeviceGetStatus, /*!< Get device status. Return uint16_t. */ - eUSBDeviceGetSyncFrame, /*!< Get Sync frame. Returns the frame number of synchronization frame as uint16_t. */ - eUSBDeviceSetTestMode, /*!< Set device in test mode. For compliance testing defined in usb protocol. - * @warning Device needs to power cycle to exit test mode.*/ - eUSBDeviceSetState, /*!< Set device state. Take IotUsbDeviceState_t and set it*/ - eUSBDeviceLPMState1Suspend, /*!< Suspend usb to LPM state 1: for usb 2.0, it is L1 state; for usb 3.0, it is U1 state. */ - eUSBDeviceLPMState1Resume, /*!< Resume usb from LPM state 1: for usb 2.0, it is exit L1 state; for usb 3.0, it is exit U1 state. */ - eUSBDeviceLPMState2Suspend, /*!< Suspend usb to LPM state 2: for usb 2.0, it is L2 state; for usb 3.0, it is U2 state. */ - eUSBDeviceLPMState2Resume, /*!< Resume usb from LPM state 2: for usb 2.0, it is exit L2 state; for usb 3.0, it is exit U2 state. */ - eUSBDeviceLPMState3Suspend, /*!< Suspend usb to LPM state 3: for usb 2.0, it is L3 state; for usb 3.0, it is U3 state. */ - eUSBDeviceLPMState3Resume, /*!< Resume usb from LPM state 3: for usb 2.0, it is exit L3 state; for usb 3.0, it is exit U3 state. */ - eUSBDeviceRemoteWakeup, /*!< Remote wakeup host. */ -} IotUsbDeviceIoctlRequest_t; - -/** - * @brief USB device state. - */ -typedef enum -{ - eUsbDeviceStateConfigured, /*!< Device state, usb device is configured and ready for use by host*/ - eUsbDeviceStateAddress, /*!< Device state, usb device Address assigned*/ - eUsbDeviceStateDefault, /*!< Device state, usb device is reset, but address not assigned yet*/ - eUsbDeviceStateAddressing, /*!< Device state, usb device is undergoing assigning address*/ - eUsbDeviceStateTestMode, /*!< Device state, usb device is in test mode*/ -} IotUsbDeviceState_t; - -/** - * @brief Defines endpoint state. - */ -typedef enum -{ - eUsbDeviceEndpointStateIdle, /*!< Endpoint state, idle*/ - eUsbDeviceEndpointStateStalled, /*!< Endpoint state, stalled*/ - eUsbDeviceEndpointStateBusy, /*!< Endpoint state, busy*/ - eUsbDeviceEndpointStateClosed, /*!< Endpoint state, Closed, not configured*/ -} IotUsbDeviceEndpointStatus_t; - -/** - * @brief Define device controller ID. - */ -typedef enum -{ - eUsbDeviceControllerOHCI, /*!< Open Device Controller Interface */ - eUsbDeviceControllerUHCI, /*!< Universal Device Controller Interface */ - eUsbDeviceControllerEHCI, /*!< Enhanced Device Controller Interface */ - eUsbDeviceControllerXHCI, /*!< Extensible Device Controller Interface */ -} IotUsbHostController_t; - -/** - * @brief USB device driver operation status. - */ -typedef enum -{ - eUsbDeviceCompleted = IOT_USB_DEVICE_SUCCESS, /*!< Device operation completed successfully. */ - eUsbDeviceReadFailed = IOT_USB_DEVICE_READ_FAILED, /*!< Device read operation failed. */ - eUsbDeviceWriteFailed = IOT_USB_DEVICE_WRITE_FAILED, /*!< Device write operation failed. */ -} IotUsbDeviceOperationStatus_t; - -/** - * @brief The USB device type defined in the source file. - */ -struct IotUsbDevice; - -/** - * @brief IotUsbDeviceHandle_t is the handle type returned by calling iot_usb_device_open(). - * This is initialized in open and returned to caller. The caller must pass - * this pointer to the rest of APIs. - */ -typedef struct IotUsbDevice * IotUsbDeviceHandle_t; - -/** - * @brief The callback function for USB device event operation. This callback is passed to - * driver by using iot_usb_device_set_callback API. It's called when one of the events - * (IotUsbDeviceEvent_t) happen. This callback is used by upper layer to set up upper layer - * callback by calling iot_usb_device_set_device_callback. It is used when the bus state changes - * and an event is generated, e.g. an bus reset event happened, usb class layer needs to know such - * event and react accordingly. - * - * @param[in] pxUsbDevice The usb device peripheral handle returned in the open() call. - * @param[in] ulDeviceEvent USB device asynchronous event. - * @param[in] pvUserContext User Context passed when setting the callback. - * This is not used or modified by the driver. The context - * is provided by the caller when setting the callback, and is - * passed back to the caller in the callback. - * - */ -typedef int32_t (* IotUsbDeviceCallback_t) ( IotUsbDeviceHandle_t const pxUsbDevice, - uint32_t ulDeviceEvent, - void * pvUserContext ); - -/** - * @brief The callback typedef for USB device endpoint. For each endpoint, it's passed when user - * set endpoint callback by iot_usb_device_set_endpoint_callback API. - * This callback is used to notify the upper layer about the endpoint tranafer result. - * - * @param[out] xStatus Usb device asynchronous operation status. - * @param[in] pvUserContext User Context passed when setting the callback. - * This is not used or modified by the driver. The context - * is provided by the caller when setting the callback, and is - * passed back to the caller in the callback. - * - */ -typedef int32_t (* IotUsbDeviceEndpointCallbackFn_t) ( IotUsbDeviceOperationStatus_t xStatus, - void * pvUserContext ); - -/** - * @brief Endpoint configuration structure. - */ -typedef struct -{ - uint16_t usMaxPacketSize; /*!< Endpoint maximum packet size. Depends on the USB controller - * Control Transfer: - * Full Speed: 8, 16, 32, 64 - * High Speed: 64 - * Low Speed: 8 - * Isochronous Transfer: - * Full Speed: 1023 - * High Speed: 1024 - * Not supported for low speed device - * Interrupt Transfer: - * Full Speed: 64 - * High Speed: 1024 - * Low Speed: 8 - * Bulk Transfer: - * Full Speed: 8, 16, 32, 64 - * High Speed: 512 - * Not supported for low speed device */ - uint8_t ucEndpointAddress; /*!< Endpoint address*/ - uint8_t ucTransferType; /*!< Endpoint transfer type defined as: control EP is 0; - * Isochronous EP is 1; Bulk EP is 2; Interrupt EP is 3. */ - uint8_t ucZlt; /*!< ZLT flag*/ - uint8_t ucInterval; /*!< Endpoint polling interval of transfer*/ -} IotUsbDeviceEndpointConfig_t; - -/** - * @brief Endpoint status structure. - */ -typedef struct -{ - uint8_t ucEndpointAddress; /*!< Endpoint address */ - uint16_t usEndpointStatus; /*!< Endpoint status: IotUsbDeviceEndpointStatus_t*/ -} IotUsbDeviceEndpointInfo_t; - -/** - * @brief Initiates the usb device controller interface. - * - * @lUsbDeviceControllerInstance The instance of USB device controller to initialize. - * - * @return - * - The handle to the USB device if SUCCESS - * - NULL if - * - invalid lUsbDeviceControllerInstance - * - already open - */ -IotUsbDeviceHandle_t iot_usb_device_open( int32_t lUsbDeviceControllerInstance ); - -/** - * @brief Connect the USB device. - * - * The function enables the device functionality, so that the device can be recognized - * by the host when the device detects that it has been connected to a host. - * - * @warning this function must be called in order for USB to be recognized - * but not necessarily enumerated which requires the class to exchange control packets. - * - * @param[in] pxUsbDevice The usb device peripheral handle returned in the open() call. - * - * @return - * - IOT_USB_DEVICE_SUCCESS on success - * - IOT_USB_DEVICE_INVALID_VALUE if pxUsbDevice is NULL. - */ -int32_t iot_usb_device_connect( IotUsbDeviceHandle_t const pxUsbDevice ); - -/** - * @brief Disconnect the USB device. - * - * The function disables the device functionality, after this function called, even the - * device is attached to the host, and the device can't work. - * - * @param[in] pxUsbDevice The usb device peripheral handle returned in the open() call. - * - * @return - * - IOT_USB_DEVICE_SUCCESS on success - * - IOT_USB_DEVICE_INVALID_VALUE if pxUsbDevice is NULL. - */ -int32_t iot_usb_device_disconnect( IotUsbDeviceHandle_t const pxUsbDevice ); - -/** - * @brief Sets the application callback to be called on device event. - * - * @note Single callback is used, per instance. - * @note Newly set callback overrides the one previously set - * - * @warning If input handle or if callback function is NULL, this function silently takes no action. - * - * @param[in] pxUsbDevice The usb device peripheral handle returned in the open() call. - * @param[in] xCallback The callback function to be called on device event. - * @param[in] pvUserContext The user context to be passed back when callback is called. - */ -void iot_usb_device_set_device_callback( IotUsbDeviceHandle_t const pxUsbDevice, - IotUsbDeviceCallback_t xCallback, - void * pvUserContext ); - -/** - * @brief Initiates the usb device specific endpoint. - * - * @warning: Its the class codes responsibility to make sure the endpoint address is only opened once. - * - * @param[in] pxUsbDevice The USB device handle returned in open() call. - * @param[in] pxEpConfig Endpoint configuration. - * - * @return - * - IOT_USB_DEVICE_SUCCESS on success - * - IOT_USB_DEVICE_INVALID_VALUE if - * - pxUsbDevice is NULL. - * - pxEpConfig is NULL. - * - endpoint address is already open - * - endpoint config parameter is not supported - * - endpoint address is invalid - * - IOT_USB_DEVICE_ERROR if an error occurred with the device - */ -int32_t iot_usb_device_endpoint_open( IotUsbDeviceHandle_t const pxUsbDevice, - IotUsbDeviceEndpointConfig_t * pxEpConfig ); - -/** - * @brief Sets the endpoint callback to be called on endpoint transfer. - * - * @note Single callback is used, per instance. - * @note Newly set callback overrides the one previously set - * - * @warning If input handle or if callback function is NULL, or invalid EndpointAddress issued, - * this function silently takes no action. - * - * @param[in] pxUsbDevice The usb device peripheral handle returned in the open() call. - * @param[in] ucEndpointAddress Endpoint Address. - * @param[in] xCallback The callback function to be called on endpoint transfer. - * @param[in] pvUserContext The user context to be passed back when callback is called. - */ -void iot_usb_device_set_endpoint_callback( IotUsbDeviceHandle_t const pxUsbDevice, - uint8_t ucEndpointAddress, - IotUsbDeviceEndpointCallbackFn_t xCallback, - void * pvUserContext ); - -/** - * @brief De-initializes the usb device specific endpoint. - * - * @param[in] pxUsbDevice The USB device handle returned in open() call. - * @param[in] ucEndpointAddress Endpoint Address. - * - * @return - * - IOT_USB_DEVICE_SUCCESS on success - * - IOT_USB_DEVICE_INVALID_VALUE if - * - pxUsbDevice is NULL. - * - invalid ucEndpointAddress - */ -int32_t iot_usb_device_endpoint_close( IotUsbDeviceHandle_t const pxUsbDevice, - uint8_t ucEndpointAddress ); - -/** - * @brief Stall the usb device specific endpoint. - * This function is to set stall conditions for the specific endpoint. - * The STALL packet indicates that the endpoint has halted, or a control pipe - * does not support a certain request. - * A function uses the STALL handshake packet to indicate that it is unable to - * transmit or receive data. Besides the default control pipe, all of a function's - * endpoints are in an undefined state after the device issues a STALL handshake - * packet. The host must never issue a STALL handshake packet. - * Typically, the STALL handshake indicates a functional stall. A functional - * stall occurs when the halt feature of an endpoint is set. In this circumstance, - * host intervention is required via the default control pipe to clear the halt - * feature of the halted endpoint. Less often, the function returns a STALL - * handshake during a SETUP or DATA stage of a control transfer. This is called a - * protocol stall and is resolved when the host issues the next SETUP transaction - * - * @param[in] pxUsbDevice The USB device handle returned in open() call. - * @param[in] ucEndpointAddress Endpoint Address. - * - * @return - * - IOT_USB_DEVICE_SUCCESS on success - * - IOT_USB_DEVICE_INVALID_VALUE if - * - pxUsbDevice is NULL. - * - invalid ucEndpointAddress - */ -int32_t iot_usb_device_endpoint_stall( IotUsbDeviceHandle_t const pxUsbDevice, - uint8_t ucEndpointAddress ); - -/** - * @brief Unstall the usb device specific endpoint. - * - * @param[in] pxUsbDevice The USB device handle returned in open() call. - * @param[in] ucEndpointAddress Endpoint Address. - * - * @return - * - IOT_USB_DEVICE_SUCCESS on success - * - IOT_USB_DEVICE_INVALID_VALUE if - * - pxUsbDevice is NULL. - * - invalid ucEndpointAddress - */ -int32_t iot_usb_device_endpoint_unstall( IotUsbDeviceHandle_t const pxUsbDevice, - uint8_t ucEndpointAddress ); - -/** - * @brief Starts the USB device read operation in blocking mode. - * - * @note This function will block until all xBytes have been read. - * - * @param[in] pxUsbDevice The USB device handle returned in open() call. - * @param[in] ucEndpointAddress Endpoint index - * @param[out] pvBuffer The receive buffer to read the data into - * @param[in] xBytes The number of bytes to read. - * - * @return - * - IOT_USB_DEVICE_SUCCESS on success - * - IOT_USB_DEVICE_INVALID_VALUE if - * - pxUsbDevice is NULL. - * - invalid ucEndpointAddress - * - pvBuffer is NULL - * - xBytes == 0 - * - IOT_USB_DEVICE_BUSY if another operation is in progress on the same endpoint. - * - IOT_USB_DEVICE_READ_FAILED if unable to complete the read operation - */ -int32_t iot_usb_device_read_sync( IotUsbDeviceHandle_t const pxUsbDevice, - uint8_t ucEndpointAddress, - uint8_t * const pvBuffer, - size_t xBytes ); - -/** - * @brief Starts the USB device write operation in blocking mode. - * - * note: this function will block until all xBytes have been written. - * - * @param[in] pxUsbDevice The USB device handle returned in open() call. - * @param[in] ucEndpointAddress Endpoint index - * @param[out] pvBuffer The receive buffer to read the data into - * @param[in] xBytes The number of bytes to read. - * - * @return - * - IOT_USB_DEVICE_SUCCESS on success - * - IOT_USB_DEVICE_INVALID_VALUE if - * - pxUsbDevice is NULL. - * - invalid ucEndpointAddress - * - pvBuffer is NULL - * - xBytes == 0 - * - IOT_USB_DEVICE_BUSY if another operation is in progress on the same endpoint. - * - IOT_USB_DEVICE_WRITE_FAILED if unable to complete the write operation - */ -int32_t iot_usb_device_write_sync( IotUsbDeviceHandle_t const pxUsbDevice, - uint8_t ucEndpointAddress, - uint8_t * const pvBuffer, - size_t xBytes ); - -/** - * @brief Starts the USB device read operation in non-blocking mode. - * - * @note iot_usb_device_set_device_callback() must be called first in - * order for the callback function to be called to signal when the - * read is complete. - * - * @param[in] pxUsbDevice The USB device handle returned in open() call. - * @param[in] ucEndpointAddress Endpoint index - * @param[out] pvBuffer The receive buffer to read the data into - * @param[in] xBytes The number of bytes to read. - * - * @return - * - IOT_USB_DEVICE_SUCCESS on success - * - IOT_USB_DEVICE_INVALID_VALUE if - * - pxUsbDevice is NULL. - * - invalid ucEndpointAddress - * - pvBuffer is NULL - * - xBytes == 0 - * - IOT_USB_DEVICE_BUSY if another operation is in progress on the same endpoint. - * - IOT_USB_DEVICE_READ_FAILED if unable to complete the read operation - */ -int32_t iot_usb_device_read_async( IotUsbDeviceHandle_t const pxUsbDevice, - uint8_t ucEndpointAddress, - uint8_t * const pvBuffer, - size_t xBytes ); - -/** - * @brief Starts the USB device write operation in non-blocking mode. - * - * @note iot_usb_device_set_device_callback() must be called first in - * order for the callback function to be called to signal when the - * write is complete. - * - * @param[in] pxUsbDevice The USB device handle returned in open() call. - * @param[in] ucEndpointAddress Endpoint index - * @param[out] pvBuffer The receive buffer to read the data into - * @param[in] xBytes The number of bytes to read. - * - * @return - * - IOT_USB_DEVICE_SUCCESS on success - * - IOT_USB_DEVICE_INVALID_VALUE if - * - pxUsbDevice is NULL. - * - invalid ucEndpointAddress - * - pvBuffer is NULL - * - xBytes == 0 - * - IOT_USB_DEVICE_BUSY if another operation is in progress on the same endpoint. - * - IOT_USB_DEVICE_WRITE_FAILED if unable to complete the write operation - */ -int32_t iot_usb_device_write_async( IotUsbDeviceHandle_t const pxUsbDevice, - uint8_t ucEndpointAddress, - uint8_t * const pvBuffer, - size_t xBytes ); - -/** - * @brief Used for various USB device control function. - * - * @param[in] pxUsbDevice The USB device handle returned in open() call. - * @param[in] xUsbDeviceRequest Should be one of IotUsbDeviceIoctlRequest_t. - * @param[in,out] pvBuffer The configuration values for the IOCTL request. - * - * @return - * - IOT_USB_DEVICE_SUCCESS on success - * - IOT_USB_DEVICE_INVALID_VALUE if - * - pxUsbDevice is NULL. - * - invalid xUsbDeviceRequest - * - IOT_USB_DEVICE_FUNCTION_NOT_SUPPORTED if ioctl request not suported. - * - Only valid for - * - eUSBDeviceSleepBus - * - eUSBDeviceSuspendBus - * - eUSBDeviceResumeBus - * - eUSBDeviceRemoteWakeup - * - eUSBDeviceGetSyncFrame - * - or other USB Error. - */ -int32_t iot_usb_device_ioctl( IotUsbDeviceHandle_t const pxUsbDevice, - IotUsbDeviceIoctlRequest_t xUsbDeviceRequest, - void * const pvBuffer ); - -/** - * @brief This function is used to cancel the pending transfer for given endpoint. - * - * @param[in] pxUsbDevice The USB device handle returned in open() call. - * @param[in] ucEndpointAddress Endpoint Address. - * - * @return - * - IOT_USB_DEVICE_SUCCESS on success - * - IOT_USB_DEVICE_INVALID_VALUE if - * - pxUsbDevice is NULL. - * - invalid ucEndpointAddress - * - IOT_USB_DEVICE_FUNCTION_NOT_SUPPORTED if cancel transfer opertion not supported - * - IOT_USB_DEVICE_NOTHING_TO_CANCEL if nothing to cancel - */ -int32_t iot_usb_device_endpoint_cancel_transfer( IotUsbDeviceHandle_t const pxUsbDevice, - uint8_t ucEndpointAddress ); - -/** - * @brief Close the USB device peripheral. - * - * @param[in] pxUsbDevice The USB device handle returned in open() call. - * - * @return - * - IOT_USB_DEVICE_SUCCESS on success - * - IOT_USB_DEVICE_INVALID_VALUE if - * - pxUsbDevice is NULL. - * - pxUsbDevice not open (already closed). - */ -int32_t iot_usb_device_close( IotUsbDeviceHandle_t const pxUsbDevice ); - -/** - * @} - */ -/* end of group iot_usb_device */ - -#endif /* ifndef _IOT_USB_DEVICE_H_ */ diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/common_io/include/iot_usb_host.h b/bk7235/liteos_m/bk_sdk_armino/middleware/compal/common_io/include/iot_usb_host.h deleted file mode 100755 index 66e61a7e1801dcac1e31fee778b25d328a914236..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/common_io/include/iot_usb_host.h +++ /dev/null @@ -1,472 +0,0 @@ -/* - * FreeRTOS Common IO V0.1.3 - * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * http://aws.amazon.com/freertos - * http://www.FreeRTOS.org - */ - -/** - * @file iot_usb_host.h - * @brief File for the APIs of USB host called by application or class layer. - */ - -#ifndef _IOT_USB_HOST_H_ -#define _IOT_USB_HOST_H_ - -/** - * @defgroup iot_usb_host usb host Abstraction APIs. - * @{ - */ - -/** - * @brief Return values returned by this driver - */ -#define IOT_USB_HOST_SUCCESS ( 0 ) /*!< USB host operation completed successfully. */ -#define IOT_USB_HOST_ERROR ( 1 ) /*!< USB host error. */ -#define IOT_USB_HOST_BUSY ( 2 ) /*!< USB host busy. */ -#define IOT_USB_HOST_INVALID_VALUE ( 3 ) /*!< At least one paramter is invalid. */ -#define IOT_USB_HOST_WRITE_FAIL ( 4 ) /*!< USB host write operation failed. */ -#define IOT_USB_HOST_READ_FAIL ( 5 ) /*!< USB host read operation failed. */ -#define IOT_USB_HOST_CANCEL_FAILED ( 6 ) /*!< USB host cancel operation failed. */ -#define IOT_USB_HOST_FUNCTION_NOT_SUPPORTED ( 7 ) /*!< USB host function not supported. */ -#define IOT_USB_HOST_NOTHING_TO_CANCEL ( 8 ) /*!< No operation in progress to cancel. */ - -#define IOT_USB_HOST_MAX_ENDPOINTS ( 4 ) /*!< Maximum endpoint number for each interface. */ - -/** - * @brief common host notify event types in host callback. - */ -typedef enum -{ - eUSBHostAttachEvent, /*!< USB device is connected to host. */ - eUSBHostDetachEvent, /*!< USB device is detached to host. */ - eUSBHostEnumerationDoneEvent, /*!< USB device enumeration is done. */ - eUSBHostResetEvent, /*!< USB reset is done. */ - eUSBHostSuspendEvent, /*!< USB suspend happened. */ - eUSBHostResumeEvent, /*!< USB resume happened. */ - eUSBHostRemoteWakeEvent, /*!< USB remote wakeup is activated. */ -} IotUsbHostEvent_t; - -/** - * @brief Ioctl standard device request for USB Host HAL. - */ -typedef enum -{ - eUSBHostGetHosthandle, /*!< Get usb host handle. */ - eUSBHostGetDeviceControlPipe, /*!< Get usb device control pipe. */ - eUSBHostGetDeviceAddress, /*!< Get usb device address. */ - eUSBHostOpenDeviceInterface, /*!< Open usb device interface. */ - eUSBHostCloseDeviceInterface, /*!< Close usb device interface. */ - eUSBHostGetDeviceInfo, /*!< Get usb device information. */ - eUSBHostGetInterfaceInfo, /*!< Get usb interface information. */ - eUSBHostGetInterfaceDescriptor, /*!< Get usb device interface descriptor. */ - eUSBHostGetConfigureHandle, /*!< Get usb configure handle. */ - eUSBHostGetInterfaceHandle, /*!< Get usb interface handle. */ -} IotUsbHostIoctlRequest_t; - -/** - * @brief USB host type defined in the source file. - */ -struct IotUsbHost; - -/** - * @brief The USB pipe, interface, configuration and device type defined in the source file. - */ -struct IotUsbDevice; -struct IotUsbConfiguration; -struct IotUsbInterface; -struct IotUsbPipe; - -/** - * @brief IotUsbHostHandle_t is the handle type returned by calling iot_usb_host_open(). - * This is initialized in open and returned to caller. The caller must pass - * this pointer to the rest of APIs. - */ -typedef struct IotUsbHost * IotUsbHostHandle_t; - -/** - * @brief IotUsbDeviceHandle_t is the handle type returned when device attach and enumerated - * This device handle is needed for device operation. - */ -typedef struct IotUsbDevice * IotUsbDeviceHandle_t; - -/** - * @brief IotUsbConfigHandle_t is the configuration handle for device - * Only one configuration at run time. - */ -typedef struct IotUsbConfiguration * IotUsbConfigHandle_t; - -/** - * @brief IotUsbInterfaceHandle_t is the interface handle, which can be extracted from config - * One device may have more than one interface to be used. - */ -typedef struct IotUsbInterface * IotUsbInterfaceHandle_t; - -/** - * @brief IotPipeHandle_t is the pipe handle, which will be used for data and control transfer. - */ -typedef struct IotUsbPipe * IotPipeHandle_t; - -/** - * @brief USB Host attach/detach notify callback type. This callback is passed - * to the driver by calling iot_usb_host_set_host_callback. - * - * @param[in] pxUsbDevice USB device handle, returned when new device attached and enumerated. - * @param[in] xEvent USB host event. - * @param[in] pvUserContext User Context passed when setting the callback. - * This is not used by the driver, but just passed back to the user - * in the callback. - */ -typedef void (* IotUsbHostCallback_t) ( IotUsbDeviceHandle_t const pxUsbDevice, - IotUsbHostEvent_t xEvent, - void * pvUserContext ); - -/** - * @brief USB Host pipe transfer callback type. This callback is passed - * to the driver by calling iot_usb_host_set_pipe_callback. - * - * @param[in] ucStatus Usb host transfer status. - * @param[in] pvUserContext User Context passed when setting the callback. - * This is not used by the driver, but just passed back to the user - * in the callback. - */ -typedef void (* IotUsbHostTransferCallback_t) ( void * pvUserContext, - uint8_t ucStatus ); - -/** - * @brief Attached device endpoint configuration structure. - */ -typedef struct -{ - uint16_t usMaxPacketSize; /*!< Endpoint maximum packet size. Depends on the USB controller - * Control Transfer: - * Full Speed: 8, 16, 32, 64 - * High Speed: 64 - * Low Speed: 8 - * Isochronous Transfer: - * Full Speed: 1023 - * High Speed: 1024 - * Not supported for low speed device - * Interrupt Transfer: - * Full Speed: 64 - * High Speed: 1024 - * Low Speed: 8 - * Bulk Transfer: - * Full Speed: 8, 16, 32, 64 - * High Speed: 512 - * Not supported for low speed device */ - uint8_t ucEndpointAddress; /*!< Endpoint address*/ - uint8_t ucTransferType; /*!< Endpoint transfer type defined as: control EP is 0; - * Isochronous EP is 1; Bulk EP is 2; Interrupt EP is 3. */ - uint8_t ucZlt; /*!< ZLT flag*/ - uint8_t ucInterval; /*!< Endpoint polling interval of transfer*/ -} IotUsbDeviceEndpointConfig_t; - -/** - * @brief Attached device interface information. - */ -typedef struct IotUsbInterfaceInfo -{ - IotUsbDeviceEndpointConfig_t endpoint[ IOT_USB_HOST_MAX_ENDPOINTS ]; - uint8_t ucInterfaceIndex; - uint8_t ucEpCount; - uint8_t ucAlternateSettingNumber; -} IotUsbInterfaceInfo_t; - -/** - * @brief Attached device configuration information. - */ -typedef struct IotUsbConfigurationInfo -{ - IotUsbInterfaceInfo_t * pxInterface; - uint8_t ucInterfaceCount; -} IotUsbConfigurationInfo_t; - -/** - * @brief Attached device information. - */ -typedef struct IotUsbDeviceInfo -{ - uint8_t ucSpeed; /*!< Device speed */ - uint8_t ucDevAddress; /*!< Device address */ - uint16_t usPid; /*!< Usb product id */ - uint16_t usVid; /*!< Usb vendor id */ -} IotUsbDeviceInfo_t; - -/** - * @brief iot_usb_host_open is used to initialize the usb host driver. - * This must be called before using any other usb host APIs. - * - * @param[in] lUsbHostControllerInstance The instance of usb host controller to initialize. - * - * @return - * - The handle IotUsbHostHandle_t on success - * - NULL if - * - invalid lUsbHostControllerInstance - * - open failed - * - already opened - */ -IotUsbHostHandle_t iot_usb_host_open( int32_t lUsbHostControllerInstance ); - -/** - * @brief Set up usb host callback to be called on host event. - * - * @warning If input handle or if callback function is NULL, this function silently takes no action. - * - * @param[in] pxUsbHost The usb host peripheral handle returned in the iot_usb_host_open() function. - * @param[in] xCallback The callback function to be called on host event. - * @param[in] pvUserContext The user context to be passed back when callback is called. - */ -void iot_usb_host_set_host_callback( IotUsbHostHandle_t const pxUsbHost, - IotUsbHostCallback_t xCallback, - void * pvUserContext ); - -/** - * @brief set up usb pipe callback to be called on pipe transfer. - * - * @warning If input handle or if callback function is NULL, or invalid pipe handle, - * this function silently takes no action. - * - * @param[in] pxUsbHost The usb host peripheral handle returned in iot_usb_host_open() function. - * @param[in] pxPipe The usb pipe to be operated. - * @param[in] xCallback The callback function to be called on pipe transfer. - * @param[in] pvUserContext The user context to be passed back when callback is called. - */ -void iot_usb_host_set_pipe_callback( IotUsbHostHandle_t const pxUsbHost, - IotPipeHandle_t pxPipe, - IotUsbHostTransferCallback_t xCallback, - void * pvUserContext ); - -/** - * @brief This function is used to open a pipe per given device and endpoint descriptor. - * - * @param[in] pxUsbHost The usb host peripheral handle returned in iot_usb_host_open() function. - * @param[in] ucDevAddress The attached device address. - * @param[in] pxEpConfig Given endpoint configuration. - * - * @return - * - Pipe handle on success - * - NULL if - * - invalid pxUsbHost - * - invalid ucDevAddress - * - invalid pxEpConfig - */ -IotPipeHandle_t iot_usb_host_pipe_open( IotUsbHostHandle_t const pxUsbHost, - uint8_t ucDevAddress, - IotUsbDeviceEndpointConfig_t * pxEpConfig ); - -/** - * @brief This function is used to close given pipe. - * - * @param[in] pxUsbHost The usb host peripheral handle returned in iot_usb_host_open() function. - * @param[in] pxPipe The pipe handle to be closed. - * - * @return - * - IOT_USB_HOST_SUCCESS on success - * - IOT_USB_HOST_INVALID_VALUE if - * - pxUsbHost is NULL. - * - pxPipe is NULL. - */ -int32_t iot_usb_host_pipe_close( IotUsbHostHandle_t const pxUsbHost, - IotPipeHandle_t pxPipe ); - -/** - * @brief Starts the usb host read operation in non-blocking mode. - * - * @note iot_usb_host_set_pipe_callback() must be called first in order for - * the callback function to be called upon read is complete. - * - * @param[in] pxUsbHost The usb host peripheral handle returned in iot_usb_host_open() function. - * @param[in] pxPipe The pipe handle. - * @param[out] pvBuffer The receive buffer to read the data into. - * @param[in] xBytes The number of bytes to read. - * - * @return - * - IOT_USB_HOST_SUCCESS on success - * - IOT_USB_HOST_INVALID_VALUE if - * - pxUsbHost is NULL. - * - pxPipe is NULL. - * - pvBuffer is NULL. - * - xBytes == 0. - * - IOT_USB_HOST_BUSY if another operation is in progress on the same pipe. - * - IOT_USB_HOST_READ_FAIL if unable to complete the read operation. - */ -int32_t iot_usb_host_read_async( IotUsbHostHandle_t const pxUsbHost, - IotPipeHandle_t pxPipe, - void * const pvBuffer, - size_t xBytes ); - -/** - * @brief Starts the usb host write operation in non-blocking mode. - * - * @note iot_usb_host_set_pipe_callback() must be called first in order for - * the callback function to be called upon read is complete. - * - * @param[in] pxUsbHost The usb host peripheral handle returned in iot_usb_host_open() function. - * @param[in] pxPipe The pipe handle. - * @param[out] pvBuffer The transmit buffer containing the data to be written. It must be allocated by caller - * and remain valid before write complete. - * @param[in] xBytes The number of bytes to write. - * - * @return - * - IOT_USB_HOST_SUCCESS on success - * - IOT_USB_HOST_INVALID_VALUE if - * - pxUsbHost is NULL. - * - pxPipe is NULL. - * - pvBuffer is NULL. - * - xBytes == 0. - * - IOT_USB_HOST_BUSY if another operation is in progress on the same pipe. - * - IOT_USB_HOST_WRITE_FAIL if unable to complete the write operation. - */ -int32_t iot_usb_host_write_async( IotUsbHostHandle_t const pxUsbHost, - IotPipeHandle_t pxPipe, - void * const pvBuffer, - size_t xBytes ); - -/** - * @brief Starts the usb host read operation in blocking mode. - * - * @note This function will block untill all xBytes are read. - * - * @param[in] pxUsbHost The usb host peripheral handle returned in iot_usb_host_open() function. - * @param[in] pxPipe The pipe handle. - * @param[out] pvBuffer The receive buffer to read the data into. - * @param[in] xBytes The number of bytes to read. - * - * @return - * - IOT_USB_HOST_SUCCESS on success - * - IOT_USB_HOST_INVALID_VALUE if - * - pxUsbHost is NULL. - * - pxPipe is NULL. - * - pvBuffer is NULL. - * - xBytes == 0. - * - IOT_USB_HOST_BUSY if another operation is in progress on the same pipe. - * - IOT_USB_HOST_READ_FAIL if unable to complete the read operation. - */ -int32_t iot_usb_host_read_sync( IotUsbHostHandle_t const pxUsbHost, - IotPipeHandle_t pxPipe, - void * const pvBuffer, - size_t xBytes ); - -/** - * @brief Starts the usb host write operation in blocking mode. - * - * @note This function will block untill all xBytes are written. - * - * @param[in] pxUsbHost The usb host peripheral handle returned in iot_usb_host_open() function. - * @param[in] pxPipe The pipe handle. - * @param[out] pvBuffer The transmit buffer containing the data to be written. It must be allocated by caller - * and remain valid before write complete. - * @param[in] xBytes The number of bytes to write. - * - * @return - * - IOT_USB_HOST_SUCCESS on success - * - IOT_USB_HOST_INVALID_VALUE if - * - pxUsbHost is NULL. - * - pxPipe is NULL. - * - pvBuffer is NULL. - * - xBytes == 0. - * - IOT_USB_HOST_BUSY if another operation is in progress on the same pipe. - * - IOT_USB_HOST_WRITE_FAIL if unable to complete the write operation. - */ -int32_t iot_usb_host_write_sync( IotUsbHostHandle_t const pxUsbHost, - IotPipeHandle_t pxPipe, - void * const pvBuffer, - size_t xBytes ); - -/** - * @brief This function is used to cancel the current operation in progress. - * - * @param[in] pxUsbHost The USB Host peripheral handle returned in iot_usb_host_open() function. - * @param[in] pxPipe The usb pipe on which user want to cancel operation. - * - * @return - * - IOT_USB_HOST_SUCCESS on success - * - IOT_USB_HOST_INVALID_VALUE if - * - pxUsbHost is NULL. - * - pxPipe is NULL. - * - IOT_USB_HOST_FUNCTION_NOT_SUPPORTED if cancel transfer is not supported. - * - IOT_USB_HOST_NOTHING_TO_CANCEL if nothing to cancel. - */ -int32_t iot_usb_host_cancel( IotUsbHostHandle_t const pxUsbHost, - IotPipeHandle_t pxPipe ); - -/** - * @brief Used for various usb host control function. - * - * @param[in] pxUsbDevice The USB device peripheral handle for host to control. - * @param[in] IotUsbHostIoctlRequest_t The request should be one of IotUsbHostIoctlRequest_t. - * @param[in,out] pvBuffer The request values for the usb host. - * - * @return - * - IOT_USB_HOST_SUCCESS on success - * - IOT_USB_HOST_INVALID_VALUE if - * - pxUsbDevice is NULL. - * - xRequest is invalid. - * - pvBuffer is NULL. - * - IOT_USB_HOST_FUNCTION_NOT_SUPPORTED if ioctl request not supported. - * - IOT_USB_HOST_ERROR for other error. - */ -int32_t iot_usb_host_ioctl( IotUsbDeviceHandle_t pxUsbDevice, - IotUsbHostIoctlRequest_t xRequest, - void * const pvBuffer ); - -/** - * @brief Send setup packet to the pipe. - * - * @param[in] pxUsbHost The USB Host peripheral handle returned in iot_usb_host_open() function. - * @param[in] pxPipe The usb pipe on which we are operating. - * @param[in] pvSetup Setup packet. - * @param[in] pucData Data to be sent if needed. - * - * @return - * - IOT_USB_HOST_SUCCESS on success - * - IOT_USB_HOST_INVALID_VALUE if - * - pxUsbHost is NULL. - * - pxPipe is NULL. - * - pvSetup is NULL. - * - pvData is NULL. - * - IOT_USB_HOST_ERROR for other error. - */ -int32_t iot_usb_host_send_setup( IotUsbHostHandle_t const pxUsbHost, - IotPipeHandle_t pxPipe, - void * pvSetup, - uint8_t * pucData ); - -/** - * @brief Close the USB hsot peripheral. - * - * @param[in] pxUsbHost The USB host handle returned in open() call. - * - * @return - * - IOT_USB_HOST_SUCCESS on success - * - IOT_USB_HOST_INVALID_VALUE if - * - pxUsbHost is NULL. - * - pxUsbHost not open (already closed). - */ -int32_t iot_usb_host_close( IotUsbHostHandle_t const pxUsbHost ); - -/** - * @} - */ -/* end of group iot_usb_host */ - -#endif /* ifndef _IOT_USB_HOST_H_ */ diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/common_io/include/iot_watchdog.h b/bk7235/liteos_m/bk_sdk_armino/middleware/compal/common_io/include/iot_watchdog.h deleted file mode 100755 index bf4835694122f2a80461399b95a3f249688e391f..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/common_io/include/iot_watchdog.h +++ /dev/null @@ -1,257 +0,0 @@ -/* - * FreeRTOS Common IO V0.1.3 - * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of - * this software and associated documentation files (the "Software"), to deal in - * the Software without restriction, including without limitation the rights to - * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of - * the Software, and to permit persons to whom the Software is furnished to do so, - * subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS - * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR - * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER - * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * - * http://aws.amazon.com/freertos - * http://www.FreeRTOS.org - */ - -/******************************************************************************* - * @file iot_watchdog.h - * - * @brief HAL APIs for WatchDog driver - ******************************************************************************* - */ - -/** - * @file iot_watchdog.h - * @brief This file contains all the WatchDog HAL API definitions - */ - -#ifndef _IOT_WATCHDOG_H_ -#define _IOT_WATCHDOG_H_ - -/** - * @defgroup iot_watchdog WatchDog HAL APIs - * @{ - */ - -/** - * @brief Return values used by WatchDog driver - */ -#define IOT_WATCHDOG_SUCCESS ( 0 ) /*!< Watchdog operation completed successfully.*/ -#define IOT_WATCHDOG_INVALID_VALUE ( 1 ) /*!< At least one parameter is invalid.*/ -#define IOT_WATCHDOG_TIME_NOT_SET ( 2 ) /*!< Watchdog timeout value not set.*/ -#define IOT_WATCHDOG_FUNCTION_NOT_SUPPORTED ( 3 ) /*!< Watchdog operation not supported.*/ - -/** - * @brief WatchDog timer status values - */ -typedef enum -{ - eWatchdogTimerStopped, /*!< WatchDog is stopped */ - eWatchdogTimerRunning, /*!< WatchDog is running */ - eWatchdogTimerBarkExpired, /*!< WatchDog bark timer expired */ - eWatchdogTimerBiteExpired /*!< WatchDog bite timer expired */ -} IotWatchdogStatus_t; - -/** - * @brief WatchDog timer bite behavior setting - */ -typedef enum -{ - eWatchdogBiteTimerReset, /*!< Reset the device when WatchDog bite timer expires */ - eWatchdogBiteTimerInterrupt /*!< Generate Interrupt when WatchDog bite timer expires */ -} IotWatchdogBiteConfig_t; - -/** - * @brief WatchDog descriptor type defined in the source file. - */ -struct IotWatchdogDescriptor; - -/** - * @brief IotWatchdogHandle_t type is the WatchDog handle returned by calling iot_watchdog_open() - * this is initialized in open and returned to caller. Caller must pass this pointer - * to the rest of the APIs. - */ -typedef struct IotWatchdogDescriptor * IotWatchdogHandle_t; - -/** - * @brief Ioctl request types. - * - * @note BarkTime is the number of msec before a warning signaled in the form of an interrupt call to the - * set callback function. - * @note BiteTime is the number of msec before a critical condition is signaled in the form of an interrupt - * (If supported and configured), and usually ends with the system being reset. - * - * @warning the BarkTime must be less than or equal to the BiteTime - */ -typedef enum -{ - eSetWatchdogBarkTime, /*!< Set the WatchDog warning time (bark value) as uint32_t in msec. - * @warning The maximum value is limited to by the number of bits used for - * WatchDog counter in the HW. ex: at 24-bit Watchdog counter would have - * a maximum of 16,777,215 msec.*/ - eGetWatchdogBarkTime, /*!< Get the WatchDog warning time (bark value) as uint32_t in msec */ - eSetWatchdogBiteTime, /*!< Set the WatchDog expire time (bite value) as uint32_t in msec. - * @warning The maximum value is limited to by the number of bits used for - * WatchDog counter in the HW. ex: at 24-bit Watchdog counter would have - * a maximum of 16,777,215 msec.*/ - eGetWatchdogBiteTime, /*!< Get the WatchDog expire time (bite value) as uint32_t in msec */ - eGetWatchdogStatus, /*!< Returns the WatchDog timer status of type IotWatchdogStatus_t */ - eSetWatchdogBiteBehaviour /*!< Set the WatchDog bite behavior. Takes IotWatchdogBiteConfig_t type */ - /*!< @warning Not all platforms may support interrupt generation. */ -} IotWatchdogIoctlRequest_t; - -/** - * @brief WatchDog notification callback type. This callback is passed - * to the driver by using iot_watchdog_set_callback API. This callback is used for - * warning notification when the bark timer or bite timer expires based on the configuration. - * Caller can check the status of the WatchDog timer by using eGetStatus IOCTL - * - * @warning The callback will only be called if WatchdogBark is supported, or if WatchdogBite behavior - * is set to interrupt and is supported. - * - * @param[in] pvUserContext User Context passed when setting the callback. - * This is not used by the driver, but just passed back to the user - * in the callback. - */ -typedef void (* IotWatchdogCallback_t)( void * pvUserContext ); - -/** - * @brief iot_watchdog_open is used to initialize the WatchDog, - * This function will stop the timer if it was started and resets the timer - * if any was configured earlier. - * - * @param[in] lWatchdogInstance The instance of the WatchDog to initialize. - * - * @return - * - Handle to IotWatchdogHandle_t on success - * - NULL if - * - invalid lWatchdogInstance - * - instance is already open - */ -IotWatchdogHandle_t iot_watchdog_open( int32_t lWatchdogInstance ); - -/** - * @brief iot_watchdog_start is used to start the WatchDog timer counter. - * WatchDog expiry (bite) time must be set before starting the WatchDog counter. - * Set the bite time using eSetBiteTime IOCTL. - * - * @param[in] pxWatchdogHandle handle to WatchDog interface returned in - * iot_watchdog_open. - * - * @return - * - IOT_WATCHDOG_SUCCESS on success - * - IOT_WATCHDOG_INVALID_VALUE if pxWatchdogHandle is NULL - * - IOT_WATCHDOG_TIME_NOT_SET if bite time has not been set. - */ -int32_t iot_watchdog_start( IotWatchdogHandle_t const pxWatchdogHandle ); - -/** - * @brief iot_watchdog_stop is used to stop and resets the WatchDog timer counter. - * After stopping the timer and before starting the timer again, - * expireTime must be set. - * - * @param[in] pxWatchdogHandle handle to WatchDog interface returned in - * iot_watchdog_open. - * - * @return - * - IOT_WATCHDOG_SUCCESS on success - * - IOT_WATCHDOG_INVALID_VALUE if pxWatchdogHandle is NULL - * - IOT_WATCHDOG_NOT_SUPPORTED if stop operation not supported. - */ -int32_t iot_watchdog_stop( IotWatchdogHandle_t const pxWatchdogHandle ); - -/** - * @brief iot_watchdog_restart is used to restart the WatchDog timer to the - * originally programmed values. This function is usually used - * once the WatchDog timer (either bark or bite) expired and generated - * a callback, so caller can restart the timer to original values to restart - * the WatchDog timer. The main difference b/w iot_watchdog_start and iot_watchdog_restart - * APIs are, the former requires the time values are set using the IOCTLs and the latter - * re-uses the already programmed values and re-programs them. If restart_timer is used - * without first setting the timers, it will return an error. - * - * @param[in] pxWatchdogHandle handle to WatchDog interface returned in - * iot_watchdog_open. - * - * @return - * - IOT_WATCHDOG_SUCCESS on success - * - IOT_WATCHDOG_INVALID_VALUE if pxWatchdogHandle is NULL - * - IOT_WATCHDOG_TIME_NOT_SET if watchdog bark or bite time have not been set. - */ -int32_t iot_watchdog_restart( IotWatchdogHandle_t const pxWatchdogHandle ); - -/*! - * @brief iot_wathcdog_set_callback is used to set the callback to be called when - * bark time reaches the WatchDog counter or if the bite time is configured to - * generate interrupt (if supported by HW). The caller must set the timers using - * IOCTL and start the timer for the callback to be called back. - * Caller must restart the timer when bark timer expires and bite time is configured - * to reset the device to avoid the target reset. - * - * @note Single callback is used, per instance, if eWatchdogBiteTimerInterrupt has been configured or - * if the bark time reaches the WatchDog counter. - * @note Newly set callback overrides the one previously set - * - * @warning If input handle or if callback function is NULL, this function silently takes no action. - * - * @param[in] pxWatchdogHandle handle to WatchDog interface returned in - * iot_watchdog_open. - * @param[in] xCallback The callback function to be called. - * @param[in] pvUserContext The user context to be passed when callback is called. - */ -void iot_watchdog_set_callback( IotWatchdogHandle_t const pxWatchdogHandle, - IotWatchdogCallback_t xCallback, - void * pvUserContext ); - -/** - * @brief iot_watchdog_ioctl is used to configure the WatchDog timer properties - * like the WatchDog timeout value, WatchDog clock, handler for - * WatchDog interrupt etc. - * - * @param[in] pxWatchdogHandle handle to WatchDog interface returned in - * iot_watchdog_open. - * @param[in] xRequest configuration request of type IotFlashIoctlRequest_t - * @param[in,out] pvBuffer the configuration buffer to hold the request or response of IOCTL. - * - * @return - * - returns IOT_WATCHDOG_SUCCESS on success - * - IOT_WATCHDOG_INVALID_VALUE if - * - pxWatchdogHandle is NULL - * - xRequest is invalid - * - pvBuffer is NULL - * - IOT_WATCHDOG_TIME_NOT_SET on error - * - IOT_WATCHDOG_FUNCTION_NOT_SUPPORTED - */ -int32_t iot_watchdog_ioctl( IotWatchdogHandle_t const pxWatchdogHandle, - IotWatchdogIoctlRequest_t xRequest, - void * const pvBuffer ); - -/** - * @brief iot_watchdog_close is used to de-initializes the WatchDog, stops the timer - * if it was started and resets the timer value. - * - * @param[in] pxWatchdogHandle handle to WatchDog interface returned in - * iot_watchdog_open. - * @return - * - IOT_WATCHDOG_SUCCESS on success - * - IOT_WATCHDOG_INVALID_VALUE if - * - pxWatchdogHandle == NULL - * - pxWatchdogHandle is not open (previously closed). - */ -int32_t iot_watchdog_close( IotWatchdogHandle_t const pxWatchdogHandle ); - -/** - * @} - */ - -#endif /* ifndef _IOT_WATCHDOG_H_ */ diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/common_io/iot_adc.c b/bk7235/liteos_m/bk_sdk_armino/middleware/compal/common_io/iot_adc.c deleted file mode 100755 index da410f6a461edb4952644757976055f64613d1fb..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/common_io/iot_adc.c +++ /dev/null @@ -1,805 +0,0 @@ -/***************************************************************************//** - * @file iot_adc.c - * @brief Beken Corp implementation of Common I/O ADC API. - ******************************************************************************* - * # License - * Copyright 2020 Beken Corp Inc. - ******************************************************************************* - * 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. - - ******************************************************************************/ - -/******************************************************************************* - * INCLUDES - ******************************************************************************/ - -/* FreeRTOS kernel layer */ -#include "FreeRTOS.h" -#include "semphr.h" - -/* ADC driver layer */ -#include "driver/hal/hal_adc_types.h" -#include "adc_driver.h" - -/* ADC iot layer */ -#include "iot_adc.h" - -/******************************************************************************* - * DESCRIPTOR - ******************************************************************************/ - -typedef struct IotAdcDescriptor { - /**************************************/ - /* ADC CONFIG */ - /**************************************/ - - /* instance number */ - int32_t lInstNum; - - /* IotAdcConfig */ - IotAdcConfig_t xIotAdcCfg; - - /**************************************/ - /* ADC DRIVER */ - /**************************************/ - /* adc configure */ - adc_config_t *pxAdcCfg; - - /**************************************/ - /* ADC HAL */ - /**************************************/ - - /* busy status */ - uint8_t ucBusyStatus; - uint8_t ucBusyChannel; - - /* callback info */ - void *pvCallback; - void *pvContext; - - /* buffer info */ - uint16_t *pusBufPtr; - uint8_t ucBufMax; - uint8_t ucBufCtr; -} IotAdcDescriptor_t; - -IotAdcDescriptor_t g_IotAdcDescriptor; - -/******************************************************************************* - * iot_adc_open() - ******************************************************************************/ - -/** - * @brief Initializes ADC controller with default configuration. - * init ADC controller, enable ADC clock, reset HW FIFO, set default - * configuration parameters, etc. Also allocate all required resources - * for ADC operation such as software data buffer etc. - * - * @warning Must be called prior to any other ADC api's so that a valid handle is obtained. - * @warning Once opened, the same ADC instance must be closed before calling open again. - * - * @param[in] lAdc The instance of ADC controller to initialize. - * - * @return - * - handle to the ADC controller on success - * - NULL, if - * - invalid instance number - * - open same instance more than once before closing it. - */ -IotAdcHandle_t iot_adc_open(int32_t lAdc) -{ - /* local variables */ - IotAdcHandle_t xAdcHandle = &g_IotAdcDescriptor; - - /* xAdcHandle instance is valid? */ - if (BK_OK != bk_adc_is_valid_ch(lAdc)) { - return NULL; - } - - /* retrieve xAdcHandle by instance number */ - bk_adc_get_config(lAdc, &xAdcHandle->pxAdcCfg); - - if (xAdcHandle->pxAdcCfg->chan != lAdc) - { - return NULL; - } - - /* selected adc shouldn't be open */ - if (xAdcHandle->pxAdcCfg->is_open == pdTRUE) { - return NULL; - } - - /* initialize ADC driver */ - bk_adc_acquire(); - bk_adc_init(xAdcHandle->pxAdcCfg->chan); - bk_adc_set_config(xAdcHandle->pxAdcCfg); - - /* enter critical section */ - portENTER_CRITICAL(); - - /* reset ADC status */ - xAdcHandle->ucBusyStatus = pdFALSE; - xAdcHandle->ucBusyChannel = 0; - - /* reset ADC callback config */ - xAdcHandle->pvCallback = NULL; - xAdcHandle->pvContext = NULL; - - /* reset ADC buffer config */ - xAdcHandle->pusBufPtr = NULL; - xAdcHandle->ucBufMax = 0; - xAdcHandle->ucBufCtr = 0; - - /* finally mark ADC as open */ - xAdcHandle->pxAdcCfg->is_open = pdTRUE; - - /* exit critical section */ - portEXIT_CRITICAL(); - - /* done */ - return xAdcHandle; -} - -/******************************************************************************* - * iot_adc_close() - ******************************************************************************/ - -/** - * @brief Close ADC controller. - * All pending operation will be cancelled, put ADC module in reset state or low - * power state if possible. Release all resources claimed during open call - * - * @param[in] pxAdc handle to ADC controller returned from iot_adc_open() call. - * - * @return - * - IOT_ADC_SUCCESS, on success; - * - IOT_ADC_INVALID_VALUE, if pxAdc is NULL - * - IOT_ADC_NOT_OPEN, if is not in open state (already closed). - */ -int32_t iot_adc_close(IotAdcHandle_t const pxAdc) -{ - /* pxAdc can't be null */ - if (pxAdc == NULL) { - return IOT_ADC_INVALID_VALUE; - } - - /* enter critical section */ - portENTER_CRITICAL(); - - /* pxAdc must be already open */ - if (pxAdc->pxAdcCfg->is_open == pdFALSE) { - portEXIT_CRITICAL(); - return IOT_ADC_NOT_OPEN; - } - - /* any pending operation? */ - if (pxAdc->ucBusyStatus == pdTRUE) { - bk_adc_stop(); - - /* update status */ - pxAdc->ucBusyStatus = pdFALSE; - } - - /* exit critical section */ - portEXIT_CRITICAL(); - - bk_adc_deinit(pxAdc->pxAdcCfg->chan); - bk_adc_release(); - - /* enter critical section again */ - portENTER_CRITICAL(); - - /* reset ADC status */ - pxAdc->ucBusyStatus = pdFALSE; - pxAdc->ucBusyChannel = 0; - - /* reset ADC callback config */ - pxAdc->pvCallback = NULL; - pxAdc->pvContext = NULL; - - bk_adc_unregister_isr_iot_callback(); - - /* reset ADC buffer config */ - pxAdc->pusBufPtr = NULL; - pxAdc->ucBufMax = 0; - pxAdc->ucBufCtr = 0; - - /* mark as closed */ - pxAdc->pxAdcCfg->is_open = pdFALSE; - - /* exit critical section */ - portEXIT_CRITICAL(); - - /* done */ - return IOT_ADC_SUCCESS; -} - -/******************************************************************************* - * iot_adc_set_callback() - ******************************************************************************/ - -/** - * @brief Sets channel callback on availability of channel scan data. - * On availability of ADC scan data, the application is notified with a - * function callback. The callback function and user context for callback - * are set using iot_adc_set_callback. - * - * @note This callback is per AdcChannel for each handle. - * @note If input handle or AdcChannel is invalid, or if callback function is NULL, - * this function silently takes no action. - * - * @param[in] pxAdc The Adc handle returned in the open() call. - * @param[in] ucAdcChannel The Adc channel for which the callback is set - * @param[in] pvCallback The callback function to be called on availability of ADC channel data. - * @param[in] pvUserContext The user context to be passed when callback is called. - * - * Example Callback Function - * For asychronous ADC calls, a callback function is used to signal when the async - * task is complete. This example uses a Semaphore to signal the completion. - * @code{c} - * static void prvAdcChCallback( uint16_t * pusConvertedData, - * void * pvUserContext ) - * { - * BaseType_t xHigherPriorityTaskWoken; - * xSemaphoreGiveFromISR( xIotAdcSemaphore, &xHigherPriorityTaskWoken ); - * portYIELD_FROM_ISR( xHigherPriorityTaskWoken ); - * } - * @endcode - */ -void iot_adc_set_callback(IotAdcHandle_t const pxAdc, - uint8_t ucAdcChannel, - IotAdcCallback_t pvCallback, - void * pvUserContext) -{ - /* we only support one callback function */ - (void) ucAdcChannel; - - /* pxAdc can't be null */ - if (pxAdc == NULL) { - return; - } - - /* pvCallback can't be null */ - if (pvCallback == NULL) { - return; - } - - /* enter critical section */ - portENTER_CRITICAL(); - - /* pxAdc must be already open */ - if (pxAdc->pxAdcCfg->is_open == pdFALSE) { - portEXIT_CRITICAL(); - return; - } - - /* update callback info */ - pxAdc->pvCallback = pvCallback; - pxAdc->pvContext = pvUserContext; - - bk_adc_register_isr_iot_callback((void *)pvCallback, pvUserContext); - - /* exit critical section */ - portEXIT_CRITICAL(); -} - -/******************************************************************************* - * iot_adc_start() - ******************************************************************************/ - -/** - * @brief Start data acquisition for ADC channel until iot_adc_stop API is called. - * data will be passed back to client using callback function. - * by default each callback will pass back one data sample, however if client has - * used ioctl to pass in data buffer, only when buffer is full will callback - * be triggered - * - * @warning iot_adc_set_callback() must be called prior to this in order to get notification - * when adc scan is complete and data is available - * - * @note iot_adc_set_callback() must be called prior to iot_adc_start(). - * - * @param[in] pxAdc. The ADC handle returned in the open() call - * @param[in] ucAdcChannel. The ADC channel to start data acquisition - * - * @return - * - IOT_ADC_SUCCESS on success - * - IOT_ADC_INVALID_VALUE, on NULL handle or invalid AdcChannel - * - IOT_ADC_NOT_OPEN if ADC has not been opened yet. - * - IOT_ADC_CH_BUSY if ADC operation has started but is not complete - * - IOT_ADC_FAILED if not callback function has been set. - * Example Asynchronous read - * @code{c} - * // ADC Instance to open - * int32_t lAdcInstance = 0; - * - * // Return value of ADC functions - * int32_t lRetVal; - * - * // ADC Channel to read - * int32_t lAdcChannel = 0; - * - * // User/Driver context; if necessary - * void xUserContext = NULL; - * - * // Open the ADC instance and get a handle. - * xAdcHandle = iot_adc_open( lAdcInstance ); - * // assert(lRetVal == IOT_ADC_SUCCESS); - * - * // set the callback function - * iot_adc_set_callback( xAdcHandle, lAdcChannel, prvAdcChCallback, &xUserCntx ); - * - * // start channel data scan on channel - * lRetVal = iot_adc_start( xAdcHandle, lAdcChannel ); - * // assert( IOT_ADC_SUCCESS == lRetVal ); - * - * // wait for the Adc operation to complete - * lRetVal = xSemaphoreTake( xIotAdcSemaphore, lIotAdcChWaitTime ); - * // assert ( pdTRUE == lRetVal ); - * - * // stop channel data scan - * lRetVal = iot_adc_stop( xAdcHandle, lAdcChannel ); - * assert( IOT_ADC_SUCCESS == lRetVal ); - * - * // close ADC module - * lRetVal = iot_adc_close( xAdcHandle ); - * // assert( IOT_ADC_SUCCESS == lRetVal ); - * @endcode - */ -int32_t iot_adc_start(IotAdcHandle_t const pxAdc, - uint8_t ucAdcChannel) -{ - /* pxAdc can't be null */ - if (pxAdc == NULL) { - return IOT_ADC_INVALID_VALUE; - } - - /* ucAdcChannel valid? */ - if (BK_OK != bk_adc_is_valid_ch(ucAdcChannel)) { - return IOT_ADC_INVALID_VALUE; - } - - /* enter critical section */ - portENTER_CRITICAL(); - - /* pxAdc must be already open */ - if (pxAdc->pxAdcCfg->is_open == pdFALSE) { - portEXIT_CRITICAL(); - return IOT_ADC_NOT_OPEN; - } - - /* pxAdc is busy? */ - #if 0 - if (pxAdc->ucBusyStatus == pdTRUE) { - portEXIT_CRITICAL(); - return IOT_ADC_CH_BUSY; - } - #endif - - /* no callback function set? */ - if (pxAdc->pvCallback == NULL) { - portEXIT_CRITICAL(); - return IOT_ADC_FAILED; - } - - if(pxAdc->pxAdcCfg->chan != ucAdcChannel) - { - bk_adc_stop(); - /* mark current ADC channel as close */ - pxAdc->pxAdcCfg->is_open = pdFALSE; - - bk_adc_get_config(ucAdcChannel, &pxAdc->pxAdcCfg); - bk_adc_init(pxAdc->pxAdcCfg->chan); - bk_adc_set_config(pxAdc->pxAdcCfg); - - /*mark switched ADC channel as open */ - pxAdc->pxAdcCfg->is_open = pdTRUE; - } - - os_printf("iot_adc_start:ch:%d\n",ucAdcChannel); - - /* update status */ - pxAdc->ucBusyStatus = pdTRUE; - - /* store active channel */ - pxAdc->ucBusyChannel = ucAdcChannel; - - /* exit critical section */ - portEXIT_CRITICAL(); - - /* allocate analog bus */ - bk_adc_enable_bypass_clalibration(); - os_printf("bk_adc_enable_bypass_clalibration\n"); - bk_adc_start(); - os_printf("bk_adc_start\n"); - bk_adc_en(); - os_printf("bk_adc_en\n"); - /* done */ - return IOT_ADC_SUCCESS; -} - -/******************************************************************************* - * iot_adc_stop() - ******************************************************************************/ - -/** - * @brief Stop data acquisition for ADC channel - * - * @param[in] pxAdc. The ADC handle returned in the open() call - * @param[in] ucAdcChannel. The ADC channel to stop data acquisition - * - * @return - * - IOT_ADC_SCUCCESS on success - * - IOT_ADC_INVALID_VALUE, on NULL handle or invalid AdcChannel - * - IOT_ADC_NOT_OPEN if Adc has been closed without re-opening. - */ -int32_t iot_adc_stop(IotAdcHandle_t const pxAdc, - uint8_t ucAdcChannel) -{ - /* pxAdc can't be null */ - if (pxAdc == NULL) { - return IOT_ADC_INVALID_VALUE; - } - - /* ucAdcChannel valid? */ - if ((BK_OK != bk_adc_is_valid_ch(ucAdcChannel)) || (pxAdc->pxAdcCfg->chan != ucAdcChannel)) { - return IOT_ADC_INVALID_VALUE; - } - - /* enter critical section */ - portENTER_CRITICAL(); - - /* pxAdc must be already open */ - if (pxAdc->pxAdcCfg->is_open == pdFALSE) { - portEXIT_CRITICAL(); - return IOT_ADC_NOT_OPEN; - } - - /* disable IRQs */ - bk_adc_stop(); - //bk_adc_deinit(ucAdcChannel); - //bk_adc_release(); - - /* update status */ - pxAdc->ucBusyStatus = pdFALSE; - - /* clear buffer info */ - pxAdc->pusBufPtr = NULL; - pxAdc->ucBufMax = 0; - pxAdc->ucBufCtr = 0; - - /* exit critical section */ - portEXIT_CRITICAL(); - - /* done */ - return IOT_ADC_SUCCESS; -} - -/******************************************************************************* - * iot_adc_read_sample() - ******************************************************************************/ - -/** - * @brief read one ADC data sample. This API will return one ADC sample. - * - * @param[in] pxAdc. The ADC handle returned in the open() call - * @param[in] ucAdcChannel. The ADC channel to read data from - * @param[out] pusAdcSample. ADC channel read sample value - * - * @return - * - IOT_ADC_SCUCCESS on success - * - IOT_ADC_INVALID_VALUE, on NULL handle or invalid AdcChannel - * - IOT_ADC_CH_BUSY if ADC operation not complete. - * - IOT_ADC_NOT_OPEN if Adc has been closed without re-opening. - * Example Synchronous read - * @code{c} - * // ADC Instance to open - * int32_t lAdcInstance = 0; - * - * // ADC Channel to read - * int32_t lAdcChannel = 0; - * - * // Declare and ADC handle - * IotAdcHandle_t xAdcHandle; - * - * // Return value of ADC functions - * int32_t lRetVal; - * - * // ADC value read - * uint16_t usSample; - * - * // Open the ADC instance and get a handle. - * xAdcHandle = iot_adc_open( lAdcInstance ); - * // assert(lRetVal == IOT_ADC_SUCCESS); - * - * // Read sample from ADC channel - * lRetVal = iot_adc_read_sample( xAdcHandle, lAdcChannel, &usSample); - * // assert(lRetVal == IOT_ADC_SUCCESS); - * - * // Close the ADC instance and get a handle. - * lRetVal = iot_adc_close( xAdcHandle ); - * // assert(lRetVal == IOT_ADC_SUCCESS); - * @endcode - * - */ -int32_t iot_adc_read_sample(IotAdcHandle_t const pxAdc, - uint8_t ucAdcChannel, - uint16_t * pusAdcSample) -{ - /* pxAdc can't be null */ - if (pxAdc == NULL) { - return IOT_ADC_INVALID_VALUE; - } - - os_printf("desc_ch:%d,ch:%d \n",pxAdc->pxAdcCfg->chan, ucAdcChannel); - - /* ucAdcChannel valid? */ - if (BK_OK != bk_adc_is_valid_ch(ucAdcChannel)){ - return IOT_ADC_INVALID_VALUE; - } - - /* pxAdc must be already open */ - if (pxAdc->pxAdcCfg->is_open == pdFALSE) { - return IOT_ADC_NOT_OPEN; - } - - if(pxAdc->pxAdcCfg->chan != ucAdcChannel) - { - bk_adc_stop(); - /* mark current ADC channel as close */ - pxAdc->pxAdcCfg->is_open = pdFALSE; - - bk_adc_get_config(ucAdcChannel, &pxAdc->pxAdcCfg); - bk_adc_init(pxAdc->pxAdcCfg->chan); - bk_adc_set_config(pxAdc->pxAdcCfg); - - /*mark switched ADC channel as open */ - pxAdc->pxAdcCfg->is_open = pdTRUE; - } - - - bk_adc_enable_bypass_clalibration(); - os_printf("bk_adc_enable_bypass_clalibration\n"); - bk_adc_start(); - os_printf("bk_adc_start\n"); - - /* read samples */ - if ((NULL == pxAdc->pusBufPtr) || (0 == pxAdc->ucBufMax)) - { - os_printf("read sample no buf \n"); - bk_adc_read_raw(pusAdcSample,1,1000); - } - else - { - os_printf("read sample to buf \n"); - bk_adc_read_raw(pxAdc->pusBufPtr,pxAdc->ucBufMax,1000); - } - - /* done */ - return IOT_ADC_SUCCESS; -} - -/******************************************************************************* - * iot_adc_ioctl() - ******************************************************************************/ - -/** - * @brief Used for various ADC control functions. - * - * @param[in] pxAdc The Adc handle returned in the open() call. - * @param[in] xRequest ioctl request defined by IotAdcIoctlRequest_s enums - * @param[in/out] pvBuffer data buffer for ioctl request - * @param[in] pvBuffer size - * - * @return - * - IOT_ADC_SCUCCESS on success - * - IOT_ADC_INVALID_VALUE, on NULL handle or invalid request or NULL or invalid buffer pointer - * - IOT_ADC_CH_BUSY if ADC operation not complete. - * - IOT_ADC_NOT_OPEN if Adc has been closed without re-opening. - * - IOT_ADC_FAILED if invalid ADC chain is requested. - * - IOT_ADC_FUNCTION_NOT_SUPPORTED only valid for eSetAdcChain, if feature not supported - */ -int32_t iot_adc_ioctl(IotAdcHandle_t const pxAdc, - IotAdcIoctlRequest_t xRequest, - void * const pvBuffer) -{ - /* local variables */ - uint8_t ucAdcIsBusy = pdFALSE; - uint8_t ucAdcBusyCh = 0; - uint8_t ucAdcChannel = 0; - IotAdcChStatus_t *pxChStatus = NULL; - IotAdcConfig_t *pxConfig = NULL; - IotAdcChBuffer_t *pxChBuffer = NULL; - int32_t lStatus = IOT_ADC_SUCCESS; - - adc_config_t *pxAdcCfgTemp; - - /* pxAdc can't be null */ - if (pxAdc == NULL) { - return IOT_ADC_INVALID_VALUE; - } - - /* buffer can't be null */ - if (pvBuffer == NULL) { - return IOT_ADC_INVALID_VALUE; - } - - /* enter critical section */ - portENTER_CRITICAL(); - - /* pxAdc must be already open */ - if (pxAdc->pxAdcCfg->is_open == pdFALSE) { - lStatus = IOT_ADC_NOT_OPEN; - } - - /* exit critical section */ - portEXIT_CRITICAL(); - - /* process the request */ - switch(xRequest) { - /******************/ - /* set ADC config */ - /******************/ - case eSetAdcConfig: - /* set pxConfig to point to buffer */ - if (lStatus == IOT_ADC_SUCCESS) { - pxConfig = (IotAdcConfig_t *) pvBuffer; - } - /* validate ulAdcSampleTime */ - if (lStatus == IOT_ADC_SUCCESS) { - if ((79 < pxConfig->ulAdcSampleTime) || (16 > pxConfig->ulAdcSampleTime)) { - lStatus = IOT_ADC_INVALID_VALUE; - } - } - - pxAdc->pxAdcCfg->sample_rate = (pxConfig->ulAdcSampleTime - 16); - - /* validate ucAdcResolution */ - if (lStatus == IOT_ADC_SUCCESS) { - switch (pxConfig->ucAdcResolution) { - case 12: - break; - default: - lStatus = IOT_ADC_INVALID_VALUE; - break; - } - } - /* set driver config */ - if (lStatus == IOT_ADC_SUCCESS) { - bk_adc_set_config(pxAdc->pxAdcCfg); - } - /* done */ - break; - - /******************/ - /* get ADC config */ - /******************/ - case eGetAdcConfig: - /* set pxConfig to point to buffer */ - if (lStatus == IOT_ADC_SUCCESS) { - pxConfig = (IotAdcConfig_t *) pvBuffer; - } - /* get driver config */ - if (lStatus == IOT_ADC_SUCCESS) { - bk_adc_get_config(pxAdc->lInstNum, &pxAdcCfgTemp); - pxConfig->ucAdcResolution = 12; - pxConfig->ulAdcSampleTime = (pxAdcCfgTemp->sample_rate + 16); - } - /* done */ - break; - - /**********************/ - /* get channel status */ - /**********************/ - case eGetChStatus: - /* enter critical section */ - portENTER_CRITICAL(); - /* set pxChStatus to point to buffer */ - if (lStatus == IOT_ADC_SUCCESS) { - pxChStatus = (IotAdcChStatus_t *) pvBuffer; - } - /* read channel number */ - if (lStatus == IOT_ADC_SUCCESS) { - ucAdcChannel = pxChStatus->ucAdcChannel; - } - /* read bus status */ - if (lStatus == IOT_ADC_SUCCESS) { - ucAdcIsBusy = pxAdc->ucBusyStatus; - ucAdcBusyCh = pxAdc->ucBusyChannel; - } - /* store the result */ - if (lStatus == IOT_ADC_SUCCESS) { - if (ucAdcIsBusy == pdTRUE && ucAdcBusyCh == ucAdcChannel) { - pxChStatus->xAdcChState = eChStateBusy; - } else { - pxChStatus->xAdcChState = eChStateIdle; - } - } - /* exit critical section */ - portEXIT_CRITICAL(); - /* done */ - break; - - /**********************/ - /* set channel buffer */ - /**********************/ - case eSetChBuffer: - /* enter critical section */ - portENTER_CRITICAL(); - /* set pxChBuffer to point to buffer */ - if (lStatus == IOT_ADC_SUCCESS) { - pxChBuffer = (IotAdcChBuffer_t *) pvBuffer; - } - /* read channel number */ - if (lStatus == IOT_ADC_SUCCESS) { - ucAdcChannel = pxChBuffer->ucAdcChannel; - } - /* validate channel number */ - if (lStatus == IOT_ADC_SUCCESS) { - if (BK_OK != bk_adc_is_valid_ch(ucAdcChannel)) { - lStatus = IOT_ADC_INVALID_VALUE; - } - } - /* validate buffer pointer */ - if (lStatus == IOT_ADC_SUCCESS) { - if (pxChBuffer->pvBuffer == NULL) { - lStatus = IOT_ADC_INVALID_VALUE; - } - } - /* validate buffer length */ - if (lStatus == IOT_ADC_SUCCESS) { - if ( pxChBuffer->ucBufLen == 0) { - lStatus = IOT_ADC_INVALID_VALUE; - } - } - /* set buffer */ - if (lStatus == IOT_ADC_SUCCESS) { - bk_adc_get_config(ucAdcChannel, &pxAdcCfgTemp); - pxAdcCfgTemp->output_buf = pxChBuffer->pvBuffer; - pxAdcCfgTemp->output_buf_len = pxChBuffer->ucBufLen; - - if(ucAdcChannel == pxAdc->pxAdcCfg->chan) - { - pxAdc->pusBufPtr = pxChBuffer->pvBuffer; - pxAdc->ucBufMax = pxChBuffer->ucBufLen; - pxAdc->ucBufCtr = 0; - } - - } - /* exit critical section */ - portEXIT_CRITICAL(); - /* done */ - break; - - /*****************/ - /* set ADC chain */ - /*****************/ - case eSetAdcChain: - if (lStatus == IOT_ADC_SUCCESS) { - lStatus = IOT_ADC_FUNCTION_NOT_SUPPORTED; - } - break; - - /***********/ - /* INVALID */ - /***********/ - default: - if (lStatus == IOT_ADC_SUCCESS) { - lStatus = IOT_ADC_INVALID_VALUE; - } - break; - } - - /* done */ - return lStatus; -} diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/common_io/iot_efuse.c b/bk7235/liteos_m/bk_sdk_armino/middleware/compal/common_io/iot_efuse.c deleted file mode 100755 index 220102cd462d0b864f83ce5dde4ea7bbe94c0230..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/common_io/iot_efuse.c +++ /dev/null @@ -1,149 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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 -#include -#include - - -#include -#include -#include -#include -#include - - -#define COMMON_EFUSE_TAG "common_io_efuse" - - - -typedef struct IotEfuseDescriptor { - UINT32 status; -} IotEfuseDescriptor_t; - -static IotEfuseDescriptor_t efuse_desc={0}; - - -IotEfuseHandle_t iot_efuse_open( void ) -{ - BK_LOGD(COMMON_EFUSE_TAG, "efuse_open\r\n"); - bk_efuse_driver_init(); - if(efuse_desc.status){ - BK_LOGE(COMMON_EFUSE_TAG, "efuse_already_open\r\n"); - return NULL; - } - else{ - efuse_desc.status = 1; - return &efuse_desc; - } -} - -int32_t iot_efuse_read_32bit_word( IotEfuseHandle_t const pxEfuseHandle, - uint32_t ulIndex, - uint32_t * ulValue ) -{ - uint32_t idx=0, temp=0; - if (pxEfuseHandle == NULL || ulIndex > 7 || ulValue == NULL){ - BK_LOGE(COMMON_EFUSE_TAG, "Invalid arguments\r\n"); - return IOT_EFUSE_INVALID_VALUE; - } - BK_LOGD(COMMON_EFUSE_TAG, "efuse_read32\r\n"); - *ulValue = 0; - for(idx=0; idx<4; idx++){ - if(bk_efuse_read_byte((ulIndex * 4 + idx), (uint8 *)&temp) == BK_OK){ - *ulValue |= (temp << (idx * 8)); - } - else - return IOT_EFUSE_READ_FAIL; - } - return IOT_EFUSE_SUCCESS; -} - -int32_t iot_efuse_write_32bit_word( IotEfuseHandle_t const pxEfuseHandle, - uint32_t ulIndex, - uint32_t ulValue ) -{ - uint32_t idx=0; - if (pxEfuseHandle == NULL || ulIndex > 7){ - BK_LOGE(COMMON_EFUSE_TAG, "Invalid arguments\r\n"); - return IOT_EFUSE_INVALID_VALUE; - } - BK_LOGD(COMMON_EFUSE_TAG, "efuse_write32\r\n"); - for(idx=0; idx<4; idx++){ - if(bk_efuse_write_byte((ulIndex * 4 + idx), ulValue) == BK_OK){ - ulValue = ulValue>>8; - } - else - return IOT_EFUSE_WRITE_FAIL; - } - return IOT_EFUSE_SUCCESS; -} - -int32_t iot_efuse_read_16bit_word( IotEfuseHandle_t const pxEfuseHandle, - uint32_t ulIndex, - uint16_t * ulValue ) -{ - uint32_t idx=0, temp=0; - if (pxEfuseHandle == NULL || ulIndex > 15 || ulValue == NULL){ - BK_LOGE(COMMON_EFUSE_TAG, "Invalid arguments\r\n"); - return IOT_EFUSE_INVALID_VALUE; - } - BK_LOGD(COMMON_EFUSE_TAG, "efuse_read16\r\n"); - *ulValue = 0; - for(idx=0; idx<2; idx++){ - if(bk_efuse_read_byte((ulIndex * 2 + idx), (uint8 *)&temp) == BK_OK){ - *ulValue |= (temp << (idx * 8)); - } - else - return IOT_EFUSE_READ_FAIL; - } - return IOT_EFUSE_SUCCESS; -} - -int32_t iot_efuse_write_16bit_word( IotEfuseHandle_t const pxEfuseHandle, - uint32_t ulIndex, - uint16_t value ) -{ - uint32_t idx=0; - if (pxEfuseHandle == NULL || ulIndex > 15){ - BK_LOGE(COMMON_EFUSE_TAG, "Invalid arguments\r\n"); - return IOT_EFUSE_INVALID_VALUE; - } - BK_LOGD(COMMON_EFUSE_TAG, "efuse_write16\r\n"); - for(idx=0; idx<2; idx++){ - if(bk_efuse_write_byte((ulIndex * 2 + idx), value) == BK_OK){ - value = value>>8; - } - else - return IOT_EFUSE_WRITE_FAIL; - } - return IOT_EFUSE_SUCCESS; -} - -int32_t iot_efuse_close( IotEfuseHandle_t const pxEfuseHandle ) -{ - if (pxEfuseHandle == NULL){ - BK_LOGE(COMMON_EFUSE_TAG, "Invalid arguments\r\n"); - return IOT_EFUSE_INVALID_VALUE; - } - BK_LOGD(COMMON_EFUSE_TAG, "efuse_close\r\n"); - if(pxEfuseHandle->status){ - pxEfuseHandle->status = 0; - return IOT_EFUSE_SUCCESS; - } - else - return IOT_EFUSE_INVALID_VALUE; -} - diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/common_io/iot_flash.c b/bk7235/liteos_m/bk_sdk_armino/middleware/compal/common_io/iot_flash.c deleted file mode 100644 index 6b59f65cd38109d131bd4a5c36d2b605ffc2e286..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/common_io/iot_flash.c +++ /dev/null @@ -1,225 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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 "driver/flash.h" -#include "flash_driver.h" -#include "iot_flash.h" -#include "os/mem.h" - -#define SPI_FLASH_BLOCK_SIZE 0x10000 //64KB - -static IotFlashInfo_t s_flash_info; -static bool s_flash_drv_open; -static uint32_t s_flash_write_size; -static uint32_t s_flash_read_size; -extern int hal_flash_lock(); -extern int hal_flash_unlock(); - -static inline bool prv_is_alligned_4k( uint32_t dw_address) -{ - return (dw_address & FLASH_SECTOR_SIZE_MASK) == 0; -} - -IotFlashHandle_t iot_flash_open(int32_t lFlashInstance) -{ - if ((lFlashInstance == -1) || (s_flash_drv_open == true)) { - return NULL; - } - - // Since architecture is based on common driver, flash has already initialized - if((bk_flash_is_driver_inited() == true)) { - s_flash_drv_open = true; - } - else - { -#if CONFIG_FLASH - bk_flash_driver_init(); - extern int hal_flash_init(); - hal_flash_init(); - s_flash_drv_open = true; -#endif - } - - return (IotFlashHandle_t) 1; -} - -IotFlashInfo_t *iot_flash_getinfo(IotFlashHandle_t const pxFlashHandle) -{ - if (pxFlashHandle == NULL) { - return NULL; - } - - s_flash_info.ulFlashSize = bk_flash_get_current_total_size(); - s_flash_info.ulBlockSize = SPI_FLASH_BLOCK_SIZE; - s_flash_info.ulSectorSize = FLASH_SECTOR_SIZE; - s_flash_info.ulPageSize = FLASH_PAGE_SIZE; - s_flash_info.ulLockSupportSize = FLASH_SECTOR_SIZE; - s_flash_info.ucAsyncSupported = false; - - return &s_flash_info; -} - -void iot_flash_set_callback(IotFlashHandle_t const pxFlashHandle, IotFlashCallback_t xCallback, void *pvUserContext) -{ - // Not supported for BK7235 - return; -} - -int32_t iot_flash_ioctl(IotFlashHandle_t const pxFlashHandle, IotFlashIoctlRequest_t xRequest, void *const pvBuffer) -{ - int32_t dw_rtn = IOT_FLASH_INVALID_VALUE; - - if (pxFlashHandle == NULL || (int) xRequest < 0) { - return IOT_FLASH_INVALID_VALUE; - } - - switch (xRequest){ - - case eGetFlashStatus: - if(pvBuffer == NULL){ - return IOT_FLASH_INVALID_VALUE; - } - - hal_flash_lock(); - uint16_t status_value = bk_flash_read_status_reg(); - hal_flash_unlock(); - - os_memcpy(pvBuffer,&status_value,sizeof(status_value)); - dw_rtn = IOT_FLASH_SUCCESS; - break; - case eGetFlashTxNoOfbytes: - if(pvBuffer == NULL){ - return IOT_FLASH_INVALID_VALUE; - } - - os_memcpy(pvBuffer,&s_flash_write_size,sizeof(s_flash_write_size)); - dw_rtn = IOT_FLASH_SUCCESS; - break; - case eGetFlashRxNoOfbytes: - if(pvBuffer == NULL){ - return IOT_FLASH_INVALID_VALUE; - } - - os_memcpy(pvBuffer,&s_flash_read_size,sizeof(s_flash_read_size)); - dw_rtn = IOT_FLASH_SUCCESS; - break; - case eSetFlashBlockProtection: - case eGetFlashBlockProtection: - case eSuspendFlashProgramErase: - case eResumeFlashProgramErase: - default: - dw_rtn = IOT_FLASH_FUNCTION_NOT_SUPPORTED; - break; - } - - return dw_rtn; -} - -int32_t iot_flash_erase_sectors(IotFlashHandle_t const pxFlashHandle, uint32_t ulAddress, size_t lSize) -{ - uint32_t erase_times = 0; - uint32_t dw_loop = 0; - uint32_t dw_rtn = 0; - flash_protect_type_t project_type; - - if ((pxFlashHandle == NULL) || !(prv_is_alligned_4k(ulAddress)) || (lSize % FLASH_SECTOR_SIZE)) { - return IOT_FLASH_INVALID_VALUE; - } - - erase_times = lSize / FLASH_SECTOR_SIZE; - hal_flash_lock(); - bk_flash_write_enable(); - - project_type = bk_flash_get_protect_type(); - bk_flash_set_protect_type(FLASH_PROTECT_NONE); - for(dw_loop = 0; dw_loop < erase_times; dw_loop++){ - dw_rtn = bk_flash_erase_sector(ulAddress + dw_loop * FLASH_SECTOR_SIZE); - - if(dw_rtn != BK_OK){ - bk_flash_set_protect_type(project_type); - bk_flash_write_disable(); - hal_flash_unlock(); - return IOT_FLASH_INVALID_VALUE; - } - } - bk_flash_set_protect_type(project_type); - - bk_flash_write_disable(); - hal_flash_unlock(); - return IOT_FLASH_SUCCESS; -} - -int32_t iot_flash_erase_chip(IotFlashHandle_t const pxFlashHandle) -{ - if (pxFlashHandle == NULL) { - return IOT_FLASH_INVALID_VALUE; - } - - return IOT_FLASH_FUNCTION_NOT_SUPPORTED; -} - -int32_t iot_flash_write_sync(IotFlashHandle_t const pxFlashHandle, uint32_t ulAddress, uint8_t *const pvBuffer, size_t xBytes) -{ - flash_protect_type_t project_type; - if (pxFlashHandle == NULL || (int) ulAddress < 0 || pvBuffer == NULL) { - return IOT_FLASH_INVALID_VALUE; - } - - s_flash_write_size = xBytes; - hal_flash_lock(); - bk_flash_write_enable(); - - project_type = bk_flash_get_protect_type(); - bk_flash_set_protect_type(FLASH_PROTECT_NONE); - bk_err_t dw_rtn = bk_flash_write_bytes(ulAddress, (const uint8_t *)pvBuffer, xBytes); - bk_flash_set_protect_type(project_type); - - bk_flash_write_disable(); - hal_flash_unlock(); - - return (dw_rtn == BK_OK) ? IOT_FLASH_SUCCESS : IOT_FLASH_INVALID_VALUE; -} - -int32_t iot_flash_read_sync(IotFlashHandle_t const pxFlashHandle, uint32_t ulAddress, uint8_t *const pvBuffer, size_t xBytes) -{ - if (pxFlashHandle == NULL || (int) ulAddress < 0 || pvBuffer == NULL) { - return IOT_FLASH_INVALID_VALUE; - } - - s_flash_read_size = xBytes; - hal_flash_lock(); - bk_err_t dw_rtn = bk_flash_read_bytes(ulAddress, (uint8_t *)pvBuffer, xBytes); - hal_flash_unlock(); - - return (dw_rtn == BK_OK) ? IOT_FLASH_SUCCESS : IOT_FLASH_INVALID_VALUE; -} - -int32_t iot_flash_write_async(IotFlashHandle_t const pxFlashHandle, uint32_t ulAddress, uint8_t *const pvBuffer, size_t xBytes) -{ - return IOT_FLASH_FUNCTION_NOT_SUPPORTED; -} - -int32_t iot_flash_read_async(IotFlashHandle_t const pxFlashHandle, uint32_t ulAddress, uint8_t *const pvBuffer, size_t xBytes) -{ - return IOT_FLASH_FUNCTION_NOT_SUPPORTED; -} - - -int32_t iot_flash_close(IotFlashHandle_t const pxFlashHandle) -{ - if (s_flash_drv_open != true) { - return IOT_FLASH_INVALID_VALUE; - } - s_flash_drv_open = false; - return IOT_FLASH_SUCCESS; -} \ No newline at end of file diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/common_io/iot_gpio.c b/bk7235/liteos_m/bk_sdk_armino/middleware/compal/common_io/iot_gpio.c deleted file mode 100755 index bd1c2aabd5f12ddee866556aaa05274856166691..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/common_io/iot_gpio.c +++ /dev/null @@ -1,537 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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 -#include "FreeRTOS.h" -#include "semphr.h" -#include - - - -/*Common IO includes*/ -#include "iot_gpio.h" - -/* Beken Board includs. */ -#include "bk_gpio.h" -#include "driver/gpio.h" -#include "driver/hal/hal_gpio_types.h" -#include "gpio_hal.h" -#include "gpio_driver_base.h" -#include "gpio_driver.h" - -/************************************************************************************ -* Private Helpers -**************************************************************************************/ -/* The State of Gpio */ -typedef enum -{ - IOT_GPIO_CLOSED=0u, - IOT_GPIO_OPENED=1u, - - -}IotGpioState_t; - -#define IOT_TST_GPIO_NUM 2//set pin number const pin0 and pin1 -//#define IOT_TAG "IOT" -#ifdef IOT_TAG -#define IOT_LOGI(...) BK_LOGI(IOT_TAG, ##__VA_ARGS__) -#define IOT_LOGW(...) BK_LOGW(IOT_TAG, ##__VA_ARGS__) -#define IOT_LOGE(...) BK_LOGE(IOT_TAG, ##__VA_ARGS__) -#define IOT_LOGD(...) BK_LOGD(IOT_TAG, ##__VA_ARGS__) -#else -#define IOT_LOGI(...) -#define IOT_LOGW(...) -#define IOT_LOGE(...) -#define IOT_LOGD(...) - -#endif -/* The Property of Gpio */ -typedef struct IotGpioConfig -{ - IotGpioDirection_t xDirection; - IotGpioOutputMode_t xOutMode; - int32_t lDriveStrength;//equal to the value of capacity range:0~3 - IotGpioPull_t xPull; - IotGpioInterrupt_t xInterruptMode; - -}IotGpioConfig_t; - -typedef struct IotGpioDescriptor -{ - int32_t lGpioNumber; - IotGpioConfig_t xConfig; - IotGpioCallback_t xUserCallBack; - void *pvUserContext; - uint8_t ucState; - -}IotGpioDescriptor_t; - -static IotGpioDescriptor_t pxGpioDesc[IOT_TST_GPIO_NUM]={0}; - -static const IotGpioDescriptor_t xDefaultGpioDesc = -{ - .lGpioNumber=-1, - .xConfig = - { - .xDirection = eGpioDirectionInput, - .xOutMode = eGpioPushPull, - .lDriveStrength = 0, - .xPull = eGpioPullNone, - .xInterruptMode =eGpioInterruptNone, - }, - .xUserCallBack = NULL, - .pvUserContext = NULL, - .ucState =IOT_GPIO_CLOSED, -}; -static bool prvIsValidPinIndex(int32_t lGpioNumber) -{ - if((lGpioNumber<0)||(lGpioNumber>=IOT_TST_GPIO_NUM)) - { - return false; - } - - return true; - -} -static bool prvIsValidHandle(IotGpioHandle_t const pxGpio) -{ - return (pxGpio!=NULL)&&(pxGpio->ucState==IOT_GPIO_OPENED); -} - -static bool prvGetPullForHal(IotGpioPull_t xPull, - gpio_pull_mode_t *xPull_Bk) -{ - bool bRtnCd=true; - switch(xPull) - { - case eGpioPullNone: - *xPull_Bk=GPIO_PULL_DISABLE; - break; - case eGpioPullUp: - *xPull_Bk=GPIO_PULL_UP_EN; - break; - case eGpioPullDown: - *xPull_Bk=GPIO_PULL_DOWN_EN; - break; - default: - *xPull_Bk=GPIO_PULL_INVALID; - bRtnCd=false; - break; - } - return bRtnCd; -} - -static int32_t prvGetIntModeForHAL(IotGpioInterrupt_t xInterrupt, - gpio_int_type_t *xIntType) -{ - int32_t lRtdCd=IOT_GPIO_SUCCESS; - switch(xInterrupt) - { - case eGpioInterruptNone: - *xIntType=GPIO_INT_TYPE_MAX; - break; - case eGpioInterruptRising: - *xIntType=GPIO_INT_TYPE_RISING_EDGE; - break; - case eGpioInterruptFalling: - *xIntType=GPIO_INT_TYPE_FALLING_EDGE; - break; - case eGpioInterruptEdge: - lRtdCd=IOT_GPIO_FUNCTION_NOT_SUPPORTED; - break; - case eGpioInterruptLow: - *xIntType=GPIO_INT_TYPE_LOW_LEVEL; - break; - case eGpioInterruptHigh: - *xIntType=GPIO_INT_TYPE_HIGH_LEVEL; - break; - default: - lRtdCd=IOT_GPIO_INVALID_VALUE; - break; - } - return lRtdCd; - -} - -static void prvPinIntEventHandler(gpio_id_t xPin) -{ - IotGpioHandle_t pxGpio=NULL; - pxGpio=&pxGpioDesc[xPin]; - - if((pxGpio != NULL)&&(pxGpio->xUserCallBack != NULL)&&(pxGpio->xConfig.xInterruptMode != eGpioInterruptNone)) - { - pxGpio->xUserCallBack(bk_gpio_get_input(xPin),pxGpio->pvUserContext); - IOT_LOGI("RcvGpio[%d]Int\n",xPin); - } -} - - -static int32_t prvConfigureInputPin(IotGpioHandle_t const pxGpio, - IotGpioConfig_t* pxNewConfig - ) -{ - int32_t lRtnCode=IOT_GPIO_SUCCESS; - gpio_pull_mode_t xPull_Bk; - bk_err_t ret=BK_ERR_BUSY; - - if(!prvGetPullForHal(pxNewConfig->xPull,&xPull_Bk)) - { - lRtnCode=IOT_GPIO_INVALID_VALUE; - IOT_LOGI("GetPullFail:%d %d",pxNewConfig->xPull,xPull_Bk); - } - - gpio_int_type_t xGpioIntCfg; - - if(lRtnCode==IOT_GPIO_SUCCESS) - { - lRtnCode=prvGetIntModeForHAL(pxNewConfig->xInterruptMode,&xGpioIntCfg); - } - gpio_config_t xGpioBkCfg; - xGpioBkCfg.io_mode=GPIO_INPUT_ENABLE; - xGpioBkCfg.pull_mode=xPull_Bk; - xGpioBkCfg.func_mode=GPIO_SECOND_FUNC_DISABLE; - if(lRtnCode==IOT_GPIO_SUCCESS) - { - gpio_dev_unmap(pxGpio->lGpioNumber); - BK_LOG_ON_ERR(bk_gpio_disable_output(pxGpio->lGpioNumber));//fisrt time do with dev_unmap - ret=bk_gpio_set_config(pxGpio->lGpioNumber, &xGpioBkCfg); - if(ret==BK_OK) - { - - if(pxNewConfig->xInterruptMode!=eGpioInterruptNone) - { - //check if gpio initialized first - IOT_LOGI("GPIO Int Mode:%d \n",xGpioIntCfg); - //bk_set_printf_sync(1);//add for debug remember to delete - //init interrupt - ret=bk_gpio_register_isr(pxGpio->lGpioNumber, prvPinIntEventHandler); - if(ret==BK_OK) - { - ret=bk_gpio_set_interrupt_type(pxGpio->lGpioNumber, xGpioIntCfg); - if(ret==BK_OK) - { - BK_LOG_ON_ERR(bk_gpio_enable_interrupt(pxGpio->lGpioNumber)); - lRtnCode=IOT_GPIO_SUCCESS; - IOT_LOGI("Test Gpio Int Set Ok\n"); - } - else - { - IOT_LOGE("ERR GPIO[%d] int type fail [%d]\n",pxGpio->lGpioNumber,ret); - lRtnCode=IOT_GPIO_INVALID_VALUE; - } - } - else - { - IOT_LOGE("ERR GPIO[%d] int register fail [%d]\n",pxGpio->lGpioNumber,ret); - lRtnCode=IOT_GPIO_INVALID_VALUE; - - } - } - - } - else - { - IOT_LOGE("ERR GPIO[%d] config fail [%d]\n",pxGpio->lGpioNumber,ret); - lRtnCode=IOT_GPIO_INVALID_VALUE; - } - } - else - { - IOT_LOGE("GpioIntModeFail:%d\n",pxNewConfig->xInterruptMode); - } - - return lRtnCode; -} - -static bool prvGetDriveStrengthForHal(int32_t lDrvStrength, - int32_t *lDrvStrength_Bk) -{ - bool bRtnCode=true; - if(lDrvStrength>3) - { - *lDrvStrength_Bk=3; - IOT_LOGE("GPIO Strength [%d] greater 3\r\n",lDrvStrength); - } - else - { - *lDrvStrength_Bk=lDrvStrength; - } - return bRtnCode; -} - -static int32_t prvConfigOutputPin(IotGpioHandle_t const pxGpio, - IotGpioConfig_t *pxNewConfig) -{ - int32_t lRetCd=IOT_GPIO_INVALID_VALUE; - gpio_pull_mode_t xPullBk; - bool bValidInputs ; - int32_t xDrive_Bk; - gpio_config_t xGpioCfgOut; - - if(pxNewConfig->xOutMode==eGpioOpenDrain) - { - pxNewConfig->xPull=eGpioPullNone; - } - bValidInputs=prvGetPullForHal(pxNewConfig->xPull,&xPullBk); - bValidInputs&=prvGetDriveStrengthForHal(pxNewConfig->lDriveStrength,&xDrive_Bk); - IOT_LOGI("%s valid:%d\n",__func__,bValidInputs); - - if(bValidInputs) - { - BK_LOG_ON_ERR(gpio_dev_unmap(pxGpio->lGpioNumber)); - BK_LOG_ON_ERR(bk_gpio_disable_input(pxGpio->lGpioNumber)); - BK_LOG_ON_ERR(bk_gpio_set_capacity(pxGpio->lGpioNumber, xDrive_Bk));//no matter - xGpioCfgOut.io_mode=GPIO_OUTPUT_ENABLE; - xGpioCfgOut.pull_mode=xPullBk; - xGpioCfgOut.func_mode=GPIO_SECOND_FUNC_DISABLE; - BK_LOG_ON_ERR(bk_gpio_set_config(pxGpio->lGpioNumber,&xGpioCfgOut)); -// BK_LOG_ON_ERR(bk_gpio_enable_output(pxGpio->lGpioNumber));// the same as the io_mode of GPIO_OUTPUT_ENABLE - lRetCd=IOT_GPIO_SUCCESS; - } - return lRetCd; - -} -static int32_t prvConfigurePin(IotGpioHandle_t const pxGpio, - IotGpioConfig_t *pxNewConfig) -{ - int32_t lRtnCode=IOT_GPIO_INVALID_VALUE; - - - if(pxNewConfig->xDirection==eGpioDirectionInput) - { - lRtnCode=prvConfigureInputPin(pxGpio,pxNewConfig); - } - else - { - lRtnCode=prvConfigOutputPin(pxGpio,pxNewConfig); - } - if(lRtnCode==IOT_GPIO_SUCCESS) - { - pxGpio->xConfig=*pxNewConfig; -// IOT_LOGI("%s\n",__func__); - } - - return lRtnCode; -} -/*---------------------------------------------------------------------------------* -* API Implementation * -*---------------------------------------------------------------------------------*/ - -IotGpioHandle_t iot_gpio_open( int32_t lGpioNumber ) -{ - IotGpioHandle_t xReturnHandle=NULL; - if(prvIsValidPinIndex(lGpioNumber)) - { - IotGpioHandle_t pxGpio=&pxGpioDesc[lGpioNumber]; - - if(pxGpio->ucState==IOT_GPIO_CLOSED) - { - *pxGpio=xDefaultGpioDesc; - pxGpio->lGpioNumber=lGpioNumber; - - //add for debug - if(pxGpio->xConfig.xInterruptMode!=eGpioInterruptNone) - { - BK_LOG_ON_ERR(bk_gpio_disable_interrupt(pxGpio->lGpioNumber)); - } - if(IOT_GPIO_SUCCESS==prvConfigurePin(pxGpio,&pxGpio->xConfig)) - { - pxGpio->ucState=IOT_GPIO_OPENED; - xReturnHandle=pxGpio; - IOT_LOGI("%s pin[%d] ok \r\n",__func__,pxGpio->lGpioNumber); - } - else - { - IOT_LOGE("%s Config Fail GPIO[%]\r\n",__func__,lGpioNumber); - } - - } - else - { - IOT_LOGE("%s Cannot open.GPIO[%d] is already opened\r\n",__func__,lGpioNumber); - } - } - else - { - IOT_LOGE("%s Incorrect Pin[%d] Index,Please vefy with IOT_TST_GPIO_NUM\r\n",__func__,lGpioNumber); - } - - return xReturnHandle; -} - -void iot_gpio_set_callback( IotGpioHandle_t const pxGpio, - IotGpioCallback_t xGpioCallback, - void * pvUserContext ) -{ - if(prvIsValidHandle(pxGpio)&&(xGpioCallback!=NULL)) - { - pxGpio->xUserCallBack=xGpioCallback; - pxGpio->pvUserContext=pvUserContext; - } -} - -int32_t iot_gpio_read_sync( IotGpioHandle_t const pxGpio, - uint8_t * pucPinState ) -{ - int32_t lRtnCd=IOT_GPIO_SUCCESS; - if(prvIsValidHandle(pxGpio)&&(pxGpio->xConfig.xDirection==eGpioDirectionInput)) - { - IOT_LOGI("%s pin[%d] ok\r\n",__func__,pxGpio->lGpioNumber); - *pucPinState=bk_gpio_get_input(pxGpio->lGpioNumber); - } - else - { - IOT_LOGI("%s pin[%d] Dir[%d] fail\r\n",__func__,pxGpio->lGpioNumber,pxGpio->xConfig.xDirection); - lRtnCd=IOT_GPIO_INVALID_VALUE; - } - return lRtnCd; -} - -int32_t iot_gpio_write_sync( IotGpioHandle_t const pxGpio, - uint8_t ucPinState ) -{ - int32_t lRetCd=IOT_GPIO_SUCCESS; - if(prvIsValidHandle(pxGpio)&&(pxGpio->xConfig.xDirection==eGpioDirectionOutput)) - { - IOT_LOGI("%s pin[%d] val:%d\r\n",__func__,pxGpio->lGpioNumber,ucPinState); - if(ucPinState) - { - BK_LOG_ON_ERR(bk_gpio_set_output_high(pxGpio->lGpioNumber)); - } - else - { - BK_LOG_ON_ERR(bk_gpio_set_output_low(pxGpio->lGpioNumber)); - } - } - else - { - IOT_LOGI("%s pin[%d] state[%d] fail\r\n",__func__,pxGpio->lGpioNumber,ucPinState); - lRetCd=IOT_GPIO_INVALID_VALUE; - } - return lRetCd; - -} - -int32_t iot_gpio_close( IotGpioHandle_t const pxGpio ) -{ - int32_t lRetCd=IOT_GPIO_SUCCESS; - IotGpioConfig_t xTmpGpioCfg; - - if(prvIsValidHandle(pxGpio)) - { - IOT_LOGI("%s pin[%d] ok\r\n",__func__,pxGpio->lGpioNumber); - //add for debug - if(pxGpio->xConfig.xInterruptMode!=eGpioInterruptNone) - { - BK_LOG_ON_ERR(bk_gpio_disable_interrupt(pxGpio->lGpioNumber)); - } - - os_memcpy(&xTmpGpioCfg,&xDefaultGpioDesc.xConfig,sizeof(IotGpioConfig_t)); - pxGpio->ucState=IOT_GPIO_CLOSED; - lRetCd=prvConfigurePin(pxGpio, &xTmpGpioCfg); - pxGpio->lGpioNumber=xDefaultGpioDesc.lGpioNumber; - pxGpio->xUserCallBack=xDefaultGpioDesc.xUserCallBack; - pxGpio->pvUserContext=xDefaultGpioDesc.pvUserContext; - - } - else - { - if(pxGpio!=NULL) - { - IOT_LOGE("%s pin[%d] state [%d]\r\n",__func__,pxGpio->lGpioNumber,pxGpio->ucState); - } - else - { - IOT_LOGI("%s NULL\r\n",__func__); - } - lRetCd=IOT_GPIO_INVALID_VALUE; - } - - return lRetCd; -} - -int32_t iot_gpio_ioctl( IotGpioHandle_t const pxGpio, - IotGpioIoctlRequest_t xRequest, - void * const pvBuffer ) -{ - int32_t lRetCd=IOT_GPIO_INVALID_VALUE; - - IOT_LOGI("%s pin[%d] \r\n",__func__,pxGpio->lGpioNumber); - if(prvIsValidHandle(pxGpio)) - { - IotGpioConfig_t xNewConfig=pxGpio->xConfig; - lRetCd=IOT_GPIO_SUCCESS; - switch(xRequest) - { - case eSetGpioDirection: - os_memcpy(&xNewConfig.xDirection,pvBuffer,sizeof(xNewConfig.xDirection)); - lRetCd=prvConfigurePin(pxGpio,&xNewConfig); - IOT_LOGI("eSetGpioDirection \r\n"); - break; - case eGetGpioDirection: - os_memcpy(pvBuffer,&pxGpio->xConfig.xDirection,sizeof(pxGpio->xConfig.xDirection)); - IOT_LOGI("eGetGpioDirection\r\n"); - break; - case eSetGpioPull: - os_memcpy(&xNewConfig.xPull,pvBuffer,sizeof(xNewConfig.xPull)); - lRetCd=prvConfigurePin(pxGpio,&xNewConfig); - IOT_LOGI("eSetGpioPull\r\n"); - break; - case eGetGpioPull: - os_memcpy(pvBuffer,&pxGpio->xConfig.xPull,sizeof(pxGpio->xConfig.xPull)); - IOT_LOGI("eGetGpioPull\r\n"); - break; - case eSetGpioOutputMode: - os_memcpy(&xNewConfig.xOutMode,pvBuffer,sizeof(xNewConfig.xOutMode)); - lRetCd=prvConfigurePin(pxGpio,&xNewConfig); - IOT_LOGI("eSetGpioOutputMode\r\n"); - break; - case eGetGpioOutputType: - os_memcpy(pvBuffer,&pxGpio->xConfig.xOutMode,sizeof(pxGpio->xConfig.xOutMode)); - IOT_LOGI("eGetGpioOutputType\r\n"); - break; - case eSetGpioInterrupt: - os_memcpy(&xNewConfig.xInterruptMode,pvBuffer,sizeof(xNewConfig.xInterruptMode)); - lRetCd=prvConfigurePin(pxGpio,&xNewConfig); - IOT_LOGI("eSetGpioInterrupt:%d Rlt:%d Dir:%d\n",xNewConfig.xInterruptMode,pxGpio->xConfig.xInterruptMode,xNewConfig.xDirection); - break; - case eGetGpioInterrupt: - os_memcpy(pvBuffer,&pxGpio->xConfig.xInterruptMode,sizeof(pxGpio->xConfig.xInterruptMode)); - IOT_LOGI("eGetGpioInterrupt:%d\n",pxGpio->xConfig.xInterruptMode); - break; - case eSetGpioDriveStrength: - os_memcpy(&xNewConfig.lDriveStrength,pvBuffer,sizeof(xNewConfig.lDriveStrength)); - lRetCd=prvConfigurePin(pxGpio,&xNewConfig); - IOT_LOGI("eSetGpioDriveStrength\r\n"); - break; - case eGetGpioDriveStrength: - os_memcpy(pvBuffer,&pxGpio->xConfig.lDriveStrength,sizeof(pxGpio->xConfig.lDriveStrength)); - IOT_LOGI("eGetGpioDriveStrength\r\n"); - break; - /*Unsupported functions*/ - case eSetGpioFunction: - case eGetGpioFunction: - case eSetGpioSpeed: - case eGetGpioSpeed: - default: - lRetCd=IOT_GPIO_FUNCTION_NOT_SUPPORTED; - IOT_LOGW("Warning:ioctlMode:[%d] is unsuppored\r\n",xRequest); - break; - - } - } - - return lRetCd; -} - diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/common_io/iot_i2c.c b/bk7235/liteos_m/bk_sdk_armino/middleware/compal/common_io/iot_i2c.c deleted file mode 100755 index eb980b94025e2aa403cc1e6ccdc885635c92c685..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/common_io/iot_i2c.c +++ /dev/null @@ -1,365 +0,0 @@ -// Copyright 2020 Beken Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at - -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include -#include "FreeRTOS.h" -#include "semphr.h" -#include "iot_i2c.h" -#include "driver/i2c.h" -#include "i2c_driver.h" - -#include - -//#define SEM_WAIT_TICKS 0 -#define WAITFOREVER 0xFFFFFFFF -#define WAITNOTICKS 0x02 -static volatile uint8_t i2c_bit_mask; - -typedef struct IotI2CDescriptor{ - IotI2CConfig_t iot_i2c_config; - int32_t i2c_port_num; - bool driver_installed; - void (*func)(IotI2COperationStatus_t arg1, void *arg2); - void *arg; - void *pvBuffer; - size_t xBytes; - bool is_slave_addr_set; - bool is_send_no_stop_flag_set; - uint32_t bytes_to_read; - uint32_t bytes_to_write; - uint8_t slave_addr; - unsigned async_op: 1; -} IotI2CDescriptor_t; - -typedef struct IotCallback{ - void (*func)(IotI2COperationStatus_t arg1, void *arg2); - void *arg; - int callbackset_flag; - beken2_timer_t myTimer; -} IotCallback_t; - -static IotCallback_t iottimercallback[SOC_I2C_UNIT_NUM] = {0}; - - -static void i2c_TimerCallback(void *param, unsigned int ulparam) -{ - IotI2CDescriptor_t * i2c_desc = (IotI2CDescriptor_t *) param; - int time_id = i2c_desc->i2c_port_num; - uint8_t status = bk_i2c_get_transstate(time_id); - - if (iottimercallback[time_id].callbackset_flag){ - if (iottimercallback[time_id].func) { - iottimercallback[time_id].func(status, iottimercallback[time_id].arg); - } - } -} - -IotI2CHandle_t iot_i2c_open(int32_t lI2CInstance) -{ - if (lI2CInstance < 0 || lI2CInstance > SOC_I2C_UNIT_NUM) { - I2C_LOGE("Invalid arguments(%d).\n",lI2CInstance); - return NULL; - } - if (0x01 & (i2c_bit_mask >> lI2CInstance)) { - I2C_LOGE( "I2C Handler is already initialised (%d).\n",lI2CInstance); - return NULL; - } - IotI2CDescriptor_t *i2c_ctx = (IotI2CDescriptor_t *)os_zalloc(sizeof(IotI2CDescriptor_t)); - if (i2c_ctx == NULL) { - I2C_LOGE("Could not allocate memory for i2c context(%d).\n",lI2CInstance); - return NULL; - } - IotI2CHandle_t iot_i2c_handler = (void *) i2c_ctx; - i2c_ctx->i2c_port_num = lI2CInstance; - i2c_bit_mask |= BIT(lI2CInstance); - - return iot_i2c_handler; -} - -int32_t iot_i2c_ioctl( IotI2CHandle_t const pxI2CPeripheral, IotI2CIoctlRequest_t xI2CRequest, void *const pvBuffer) -{ - bk_err_t ret; - I2C_LOGI ("iot_i2c_ioctl %d.\n",xI2CRequest); - if (xI2CRequest != eI2CSendNoStopFlag) { - if (pxI2CPeripheral == NULL || pvBuffer == NULL) { - I2C_LOGE("Invalid arguments %d.\n",xI2CRequest); - return IOT_I2C_INVALID_VALUE; - } - } - IotI2CDescriptor_t *i2c_ctx = (IotI2CDescriptor_t *) pxI2CPeripheral; - int32_t i2c_port_num = (int32_t) i2c_ctx->i2c_port_num; - - switch (xI2CRequest) { - case eI2CSetMasterConfig : { - - IotI2CConfig_t *iot_i2c_handler = (IotI2CConfig_t *) pvBuffer; - i2c_ctx->iot_i2c_config.ulBusFreq = iot_i2c_handler->ulBusFreq; - i2c_ctx->iot_i2c_config.ulMasterTimeout = iot_i2c_handler->ulMasterTimeout; - - if (i2c_ctx->driver_installed) { - if (bk_i2c_get_busstate(i2c_port_num)== pdFALSE) { - return IOT_I2C_BUSY; - } - bk_err_t ret = bk_i2c_deinit(i2c_port_num); - if (ret != BK_OK) { - I2C_LOGE("i2c driver delete failed.\n"); - return IOT_I2C_INVALID_VALUE; - } - i2c_ctx->driver_installed = false; - I2C_LOGI( "i2c driver delete success.\n"); - } - i2c_config_t i2c_conf = { - .baud_rate = i2c_ctx->iot_i2c_config.ulBusFreq, - .addr_mode = I2C_ADDR_MODE_7BIT, - }; - ret = bk_i2c_init(i2c_port_num, &i2c_conf); - if (ret != BK_OK) { - I2C_LOGE( "bk_i2c_init failed.\n"); - return IOT_I2C_INVALID_VALUE; - } - i2c_ctx->driver_installed = true; - I2C_LOGI("I2C(%d) init ok, baud_rate:%d ,timeout : %d \r\n", i2c_port_num, - i2c_ctx->iot_i2c_config.ulBusFreq ,i2c_ctx->iot_i2c_config.ulMasterTimeout); - return IOT_I2C_SUCCESS; - } - break; - case eI2CGetMasterConfig : { - IotI2CConfig_t *iot_i2c_handler = (IotI2CConfig_t *) pvBuffer; - iot_i2c_handler->ulBusFreq = i2c_ctx->iot_i2c_config.ulBusFreq; - iot_i2c_handler->ulMasterTimeout = i2c_ctx->iot_i2c_config.ulMasterTimeout; - return IOT_I2C_SUCCESS; - } - case eI2CSetSlaveAddr : { - if (bk_i2c_get_busstate(i2c_port_num)== pdFALSE) { - return IOT_I2C_BUSY; - } - i2c_ctx->slave_addr = (*(uint8_t *)pvBuffer); - i2c_ctx->is_slave_addr_set = true; - return IOT_I2C_SUCCESS; - } - case eI2CGetBusState : { - IotI2CBusStatus_t *bus_state = (IotI2CBusStatus_t *) pvBuffer; - *bus_state = (bk_i2c_get_busstate(i2c_port_num)== pdFALSE) ? eI2cBusBusy : eI2CBusIdle; - I2C_LOGI( "Get bus state [%d].\n" ,*bus_state ); - - return IOT_I2C_SUCCESS; - } - case eI2CGetTxNoOfbytes : { - uint16_t *tx_bytes = (uint16_t *) pvBuffer; - *tx_bytes = i2c_ctx->bytes_to_write; - return IOT_I2C_SUCCESS; - } - case eI2CGetRxNoOfbytes : { - uint16_t *rx_bytes = (uint16_t *) pvBuffer; - *rx_bytes = i2c_ctx->bytes_to_read; - return IOT_I2C_SUCCESS; - } - case eI2CSendNoStopFlag : { - i2c_ctx->is_send_no_stop_flag_set = true; - return IOT_I2C_SUCCESS; - } - default : - I2C_LOGE( "Invalid argument"); - return IOT_I2C_INVALID_VALUE; - } -} - -void iot_i2c_set_callback(IotI2CHandle_t const pxI2CPeripheral, IotI2CCallback_t xCallback, void *pvUserContext) -{ - if (pxI2CPeripheral == NULL || xCallback == NULL) { - I2C_LOGE( "Invalid arguments.\n"); - } - IotI2CDescriptor_t *iot_i2c_handler = (IotI2CDescriptor_t *) pxI2CPeripheral; - int i2c_id = iot_i2c_handler->i2c_port_num; - if(iottimercallback[i2c_id].callbackset_flag == 1){ - os_memset(&iottimercallback[i2c_id],0,sizeof(IotCallback_t)); - } - iottimercallback[i2c_id].arg = pvUserContext; - iottimercallback[i2c_id].func = (void *)xCallback; - iottimercallback[i2c_id].callbackset_flag = 1; - bk_err_t ret = rtos_init_oneshot_timer(&iottimercallback[i2c_id].myTimer, 200, - (timer_2handler_t)i2c_TimerCallback, - (void *) iot_i2c_handler, 0); - if (ret!= BK_OK) { - I2C_LOGE("error xTimerCreate.\n"); - } else { - bk_i2c_timer_callback(i2c_id, &iottimercallback[i2c_id].myTimer); - } - I2C_LOGD( "iot_i2c_set_callback ok.\n"); -} - -int32_t iot_i2c_read_async( IotI2CHandle_t const pxI2CPeripheral, uint8_t *const pvBuffer, size_t xBytes) -{ - bk_err_t ret = BK_OK; - if (pxI2CPeripheral == NULL || pvBuffer == NULL) { - I2C_LOGD( "Invalid arguments.\n"); - return IOT_I2C_INVALID_VALUE; - } - IotI2CDescriptor_t *iot_i2c_handler = (IotI2CDescriptor_t *) pxI2CPeripheral; - int32_t i2c_port_num = (int32_t) iot_i2c_handler->i2c_port_num; - uint8_t *src_buf = (uint8_t *) pvBuffer; - if (!iot_i2c_handler->is_slave_addr_set) { - I2C_LOGE( "Slave address not set.\n"); - return IOT_I2C_SLAVE_ADDRESS_NOT_SET; - } - if (!iot_i2c_handler->driver_installed) { - return IOT_I2C_INVALID_VALUE; - } - if ( bk_i2c_get_busstate(i2c_port_num) == pdFALSE) { - return IOT_I2C_BUSY; - } - iot_i2c_handler->async_op = true; - ret = bk_i2c_master_read(i2c_port_num, iot_i2c_handler->slave_addr,src_buf, xBytes, WAITNOTICKS ); - if (ret != BK_OK) { - I2C_LOGE( "i2c master read failed"); - return IOT_I2C_READ_FAILED; - } - iot_i2c_handler->is_send_no_stop_flag_set = false; - iot_i2c_handler->bytes_to_read = xBytes; - - I2C_LOGD( "iot_i2c_read_async.\n"); - return (ret == BK_OK) ? IOT_I2C_SUCCESS : IOT_I2C_READ_FAILED; -} - -int32_t iot_i2c_write_async( IotI2CHandle_t const pxI2CPeripheral, uint8_t *const pvBuffer, size_t xBytes) -{ - bk_err_t ret = BK_OK; - if (pxI2CPeripheral == NULL || pvBuffer == NULL) { - I2C_LOGE( "Invalid arguments.\n"); - return IOT_I2C_INVALID_VALUE; - } - IotI2CDescriptor_t *iot_i2c_handler = (IotI2CDescriptor_t *) pxI2CPeripheral; - int32_t i2c_port_num = (int32_t) iot_i2c_handler->i2c_port_num; - uint8_t *src_buf = (uint8_t *) pvBuffer; - if (!iot_i2c_handler->is_slave_addr_set) { - I2C_LOGE( "Slave address not set.\n"); - return IOT_I2C_SLAVE_ADDRESS_NOT_SET; - } - if (!iot_i2c_handler->driver_installed) { - return IOT_I2C_INVALID_VALUE; - } - if (bk_i2c_get_busstate(i2c_port_num)== pdFALSE) { - return IOT_I2C_BUSY; - } - iot_i2c_handler->async_op = true; - ret = bk_i2c_master_write(i2c_port_num, iot_i2c_handler->slave_addr,src_buf, xBytes, WAITNOTICKS); - if (ret != BK_OK) { - I2C_LOGE( "i2c master write failed"); - return IOT_I2C_WRITE_FAILED; - } - iot_i2c_handler->bytes_to_write = xBytes; - iot_i2c_handler->is_send_no_stop_flag_set = false; - I2C_LOGD( "iot_i2c_write_async.\n"); - return (ret == BK_OK) ? IOT_I2C_SUCCESS : IOT_I2C_WRITE_FAILED; -} - -int32_t iot_i2c_read_sync( IotI2CHandle_t const pxI2CPeripheral, uint8_t *const pvBuffer, size_t xBytes) -{ - bk_err_t ret = BK_OK; - if (pxI2CPeripheral == NULL || pvBuffer == NULL) { - I2C_LOGD( "Invalid arguments"); - return IOT_I2C_INVALID_VALUE; - } - IotI2CDescriptor_t *iot_i2c_handler = (IotI2CDescriptor_t *) pxI2CPeripheral; - int32_t i2c_port_num = (int32_t) iot_i2c_handler->i2c_port_num; - uint8_t *src_buf = (uint8_t *) pvBuffer; - if (!iot_i2c_handler->is_slave_addr_set) { - I2C_LOGE( "Slave address not set.\n"); - return IOT_I2C_SLAVE_ADDRESS_NOT_SET; - } - if (bk_i2c_get_busstate(i2c_port_num)== pdFALSE) { - return IOT_I2C_BUSY; - } - iot_i2c_handler->async_op = false; - - ret = bk_i2c_master_write(i2c_port_num, iot_i2c_handler->slave_addr,src_buf, xBytes, WAITFOREVER); - if (ret != BK_OK) { - I2C_LOGE( "i2c master read failed"); - return IOT_I2C_READ_FAILED; - } - iot_i2c_handler->is_send_no_stop_flag_set = false; - iot_i2c_handler->bytes_to_read = xBytes; - - I2C_LOGI( "iot_i2c_read_sync.\n"); - return (ret == BK_OK) ? IOT_I2C_SUCCESS : IOT_I2C_READ_FAILED; -} - -int32_t iot_i2c_write_sync( IotI2CHandle_t const pxI2CPeripheral, uint8_t *const pvBuffer, size_t xBytes) -{ - bk_err_t ret = BK_OK; - if (pxI2CPeripheral == NULL || pvBuffer == NULL) { - I2C_LOGE( "Invalid arguments"); - return IOT_I2C_INVALID_VALUE; - } - IotI2CDescriptor_t *iot_i2c_handler = (IotI2CDescriptor_t *) pxI2CPeripheral; - int32_t i2c_port_num = (int32_t) iot_i2c_handler->i2c_port_num; - uint8_t *src_buf = (uint8_t *) pvBuffer; - if (!iot_i2c_handler->is_slave_addr_set) { - I2C_LOGE( "Slave address not set.\n"); - return IOT_I2C_SLAVE_ADDRESS_NOT_SET; - } - if (bk_i2c_get_busstate(i2c_port_num) == pdFALSE) { - return IOT_I2C_BUSY; - } - iot_i2c_handler->async_op = false; - - ret = bk_i2c_master_write(i2c_port_num, iot_i2c_handler->slave_addr,src_buf, xBytes, WAITFOREVER ); - if (ret != BK_OK) { - I2C_LOGE( "i2c master write failed"); - return IOT_I2C_WRITE_FAILED; - } - iot_i2c_handler->bytes_to_write = xBytes; - iot_i2c_handler->is_send_no_stop_flag_set = false; - - I2C_LOGI( "iot_i2c_write_sync.\n"); - return (ret == BK_OK) ? IOT_I2C_SUCCESS : IOT_I2C_WRITE_FAILED; -} - -int32_t iot_i2c_close(IotI2CHandle_t const pxI2CPeripheral) -{ - bk_err_t ret ; - if (pxI2CPeripheral == NULL) { - I2C_LOGE( "Invalid I2C Handler.\n"); - return IOT_I2C_INVALID_VALUE; - } - IotI2CDescriptor_t *iot_i2c_handler = (IotI2CDescriptor_t *) pxI2CPeripheral; - if (!(0x01 & (i2c_bit_mask >> iot_i2c_handler->i2c_port_num))) { - I2C_LOGE( "I2C Handler is not initialised.\n"); - return IOT_I2C_INVALID_VALUE; - } - - i2c_bit_mask = i2c_bit_mask & ~(BIT(iot_i2c_handler->i2c_port_num)); - int32_t i2c_port_num = (int32_t) iot_i2c_handler->i2c_port_num; - if (iot_i2c_handler->driver_installed) { - if (bk_i2c_get_busstate(iot_i2c_handler->i2c_port_num) == pdFALSE) { - return IOT_I2C_BUSY; - } - ret = bk_i2c_deinit(i2c_port_num); - if (ret != BK_OK) { - I2C_LOGE( "bk_i2c_deinit failed.\n"); - return IOT_I2C_INVALID_VALUE; - } - //os_memset(&iottimercallback[i2c_port_num],0,sizeof(IotCallback_t)); - I2C_LOGI( "bk_i2c_deinit ok.\n"); - } - - os_free(pxI2CPeripheral); - return IOT_I2C_SUCCESS; -} - -int32_t iot_i2c_cancel(IotI2CHandle_t const pxI2CPeripheral) - -{ - return IOT_I2C_FUNCTION_NOT_SUPPORTED; -} diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/common_io/iot_power.c b/bk7235/liteos_m/bk_sdk_armino/middleware/compal/common_io/iot_power.c deleted file mode 100755 index acc823355611df81fd273eac074bdb338dcd8622..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/common_io/iot_power.c +++ /dev/null @@ -1,289 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - - -/* These APIs require the following menuconfig options enabled: - * - * CONFIG_PM_LIGHT_SLEEP=y - */ - -#include -#include -//#include -//#include -#include -#include - -#include -#include -#include "func_convert.h" - - -#define COMMON_POWER_TAG "bk-iot-power" - - -typedef struct IotPowerDescriptor { - UINT8 status; - UINT8 is_cb_supported; - IotPowerCallback_t idle_cb; - void *cb_args; - IotPowerMode_t power_mode; - IotPowerMode_t prev_power_mode; - IotPowerIdleMode_t idle_mode; - UINT32 PCWake_ms; - UINT32 ClkSrcOffWake_ms; - UINT32 VddOffWake_ms; - IotPowerWakeupSources_t wake_src; -}IotPowerDescriptor_t; - -static IotPowerDescriptor_t power_descriptor={0}; - -static int iot_power_idle_enter_cb(uint64_t expected_time_ms, void *args) -{ - if (power_descriptor.PCWake_ms > expected_time_ms) { - power_descriptor.idle_mode = eIdleNoneMode; - return -1; - } - os_printf("th = %d, delay = %d \r\n", power_descriptor.PCWake_ms, (uint32_t)expected_time_ms); - - if(power_descriptor.idle_cb != NULL) { - power_descriptor.idle_cb(true, power_descriptor.cb_args); - } - if((power_descriptor.VddOffWake_ms > 0) && (expected_time_ms > power_descriptor.VddOffWake_ms)) - power_descriptor.idle_mode = eIdleVddOffMode; - else if((power_descriptor.ClkSrcOffWake_ms > 0) && (expected_time_ms > power_descriptor.ClkSrcOffWake_ms)) - power_descriptor.idle_mode = eIdleClkSrcOffModeMode; - else - power_descriptor.idle_mode = eIdlePCMode; - return 0; -} - -static int iot_power_idle_exit_cb(uint64_t slept_time_ms, void *args) -{ - if(power_descriptor.idle_cb != NULL) { - power_descriptor.idle_cb(false, power_descriptor.cb_args); - if (power_descriptor.power_mode == eUnknownPowerMode) { - power_descriptor.power_mode = power_descriptor.prev_power_mode; - } - } - return 0; -} - - -IotPowerHandle_t iot_power_open(void) -{ - if (power_descriptor.status) { - BK_LOGE(COMMON_POWER_TAG, "iot_power_open err,already open\r\n"); - return NULL; - } - BK_LOGD(COMMON_POWER_TAG, "iot_power_open\r\n"); - //to do reg - pm_cb_conf_t enter_config={iot_power_idle_enter_cb, NULL}; - pm_cb_conf_t exit_config={iot_power_idle_exit_cb, NULL}; - if(bk_pm_light_sleep_register_cb(&enter_config, &exit_config) != BK_OK){ - BK_LOGD(COMMON_POWER_TAG, "iot_power sleep_register err\r\n"); - return NULL; - } - - memset(&power_descriptor, 0, sizeof(power_descriptor)); - power_descriptor.status = 1; - - power_descriptor.PCWake_ms = 2; - power_descriptor.power_mode = eNormalPowerPerfMode; - power_descriptor.idle_mode = eIdleNoneMode; - - return &power_descriptor; -} - -int32_t iot_power_set_mode(IotPowerHandle_t const pxPowerHandle, IotPowerMode_t xMode) -{ - if (pxPowerHandle == NULL) { - BK_LOGE(COMMON_POWER_TAG, "iot_power_set_mode err,invalid ptr\r\n"); - return IOT_POWER_SET_FAILED; - } - BK_LOGD(COMMON_POWER_TAG, "iot_power_set_mode\r\n"); - if (pxPowerHandle->power_mode == xMode) { - return IOT_POWER_SUCCESS; - } - - switch(xMode) { - case eHighPowerPerfMode: - // Power tests requires this mode so not returning - //return IOT_POWER_FUNCTION_NOT_SUPPORTED; - case eNormalPowerPerfMode: - break; - case eLowPowerPerfMode: - break; - default: - return IOT_POWER_INVALID_VALUE; - } - - pxPowerHandle->power_mode = xMode; - pxPowerHandle->idle_mode = eIdleNoneMode; - return IOT_POWER_SUCCESS; -} - -int32_t iot_power_reset_mode(IotPowerHandle_t const pxPowerHandle) -{ - if (pxPowerHandle == NULL) { - BK_LOGE(COMMON_POWER_TAG, "iot_power_reset_mode err,invalid ptr\r\n"); - return IOT_POWER_INVALID_VALUE; - } - BK_LOGD(COMMON_POWER_TAG, "iot_power_reset_mode\r\n"); - pxPowerHandle->prev_power_mode = pxPowerHandle->power_mode; - pxPowerHandle->power_mode = eUnknownPowerMode; - return IOT_POWER_SUCCESS; -} - -void iot_power_set_callback(IotPowerHandle_t const pxPowerHandle, IotPowerCallback_t xCallback, void *pvUserContext) -{ - if (pxPowerHandle == NULL || xCallback == NULL ) { - BK_LOGE(COMMON_POWER_TAG, "iot_power_set_callback err,invalid ptr\r\n"); - return; - } - BK_LOGD(COMMON_POWER_TAG, "iot_power_set_callback\r\n"); - pxPowerHandle->idle_cb = xCallback; - pxPowerHandle->cb_args = pvUserContext; - return; -} - - -static int iot_power_set_wakeup_sources(IotPowerWakeupSources_t *data) -{ - //bk_err_t ret = 0; - uint8_t *sources = data->pucWakeupSources; - - if (!data) { - return IOT_POWER_INVALID_VALUE; - } - - if (data->usLength < 8) { - return IOT_POWER_INVALID_VALUE; - } - uint8_t pm_wake_source = sources[0]; - rtc_wakeup_param_t rtc_wakeup_param = {0}; - system_wakeup_param_t system_wakeup_param = {0}; - gpio_wakeup_param_t gpio_wakeup_param = {0}; - touch_wakeup_param_t touch_wakeup_param = {0}; - usbplug_wakeup_param_t usbplug_wakeup_param = {0}; - void *wakeup_ptr = NULL; - - switch(pm_wake_source){ - case PM_WAKEUP_SOURCE_INT_GPIO: - wakeup_ptr = &gpio_wakeup_param; - gpio_wakeup_param.gpio_id = sources[1]; - gpio_wakeup_param.gpio_valid = PARAM_DATA_VALID; - gpio_wakeup_param.gpio_trigger_interrupt_type = sources[2]; - break; - case PM_WAKEUP_SOURCE_INT_RTC: - wakeup_ptr = &rtc_wakeup_param; - rtc_wakeup_param.period = array_to_uint32(sources+1); - //rtc_wakeup_param.isr_callback = cli_pm_rtc_callback; - break; - case PM_WAKEUP_SOURCE_INT_SYSTEM_WAKE: - wakeup_ptr = &system_wakeup_param; - if(sources[1] == WIFI_WAKEUP) - system_wakeup_param.wifi_bt_wakeup = WIFI_WAKEUP; - else - system_wakeup_param.wifi_bt_wakeup = BT_WAKEUP; - break; - case PM_WAKEUP_SOURCE_INT_USBPLUG: - wakeup_ptr = &usbplug_wakeup_param; - break; - case PM_WAKEUP_SOURCE_INT_TOUCHED: - wakeup_ptr = &touch_wakeup_param; - touch_wakeup_param.touch_channel = sources[1]; - break; - default: - pm_wake_source = PM_WAKEUP_SOURCE_INT_NONE; - break; - } - - if(pm_wake_source != PM_WAKEUP_SOURCE_INT_NONE){ - bk_pm_wakeup_source_set(pm_wake_source, wakeup_ptr); - } - return IOT_POWER_SUCCESS; -} - -int32_t iot_power_ioctl(IotPowerHandle_t const pxPowerHandle, IotPowerIoctlRequest_t xRequest, void *const pvBuffer) -{ - if (pxPowerHandle == NULL || pvBuffer == NULL) { - BK_LOGE(COMMON_POWER_TAG, "iot_power_ioctl err,invalid ptr\r\n"); - return IOT_POWER_INVALID_VALUE; - } - BK_LOGD(COMMON_POWER_TAG, "iot_power_ioctl\r\n"); - switch(xRequest) { - case eSetPCWakeThreshold: { - pxPowerHandle->PCWake_ms = (*(uint32_t *)pvBuffer); - break; - } - case eGetPCWakeThreshold: - *(uint32_t *)pvBuffer = pxPowerHandle->PCWake_ms; - break; - case eSetClkSrcOffWakeThreshold: - pxPowerHandle->ClkSrcOffWake_ms = (*(uint32_t *)pvBuffer); - break; - case eGetClkSrcOffWakeThreshold: - *(uint32_t *)pvBuffer = pxPowerHandle->ClkSrcOffWake_ms; - break; - case eSetVddOfffWakeThreshold: - pxPowerHandle->VddOffWake_ms = (*(uint32_t *)pvBuffer); - break; - case eGetVddOfffWakeThreshold: - *(uint32_t *)pvBuffer = pxPowerHandle->VddOffWake_ms; - break; - case eSetWakeupSources: - pxPowerHandle->wake_src = (*(IotPowerWakeupSources_t *)pvBuffer); - iot_power_set_wakeup_sources(&pxPowerHandle->wake_src); - break; - case eGetWakeupSources: - *(IotPowerWakeupSources_t *)pvBuffer = pxPowerHandle->wake_src; - break; - case eGetLastIdleMode: - *(uint32_t *)pvBuffer = pxPowerHandle->idle_mode; - break; - default: - return IOT_POWER_INVALID_VALUE; - } - return IOT_POWER_SUCCESS; -} - -int32_t iot_power_get_mode(IotPowerHandle_t const pxPowerHandle, IotPowerMode_t *xMode) -{ - if (pxPowerHandle == NULL || xMode == NULL) { - BK_LOGE(COMMON_POWER_TAG, "iot_power_get_mode err,invalid ptr\r\n"); - return IOT_POWER_GET_FAILED; - } - BK_LOGD(COMMON_POWER_TAG, "iot_power_get_mode\r\n"); - *xMode = pxPowerHandle->power_mode; - return IOT_POWER_SUCCESS; -} - -int32_t iot_power_close(IotPowerHandle_t const pxPowerHandle) -{ - if (pxPowerHandle == NULL) { - BK_LOGE(COMMON_POWER_TAG, "iot_power_close err,invalid ptr\r\n"); - return IOT_POWER_INVALID_VALUE; - } - if (pxPowerHandle->status == 0) { - BK_LOGE(COMMON_POWER_TAG, "iot_power_close err,already close\r\n"); - return IOT_POWER_NOT_INITIALIZED; - } - BK_LOGD(COMMON_POWER_TAG, "iot_power_close\r\n"); - pxPowerHandle->status = 0; - pxPowerHandle->idle_cb = NULL; - bk_pm_light_sleep_unregister_cb(true, true); - - return IOT_POWER_SUCCESS; -} diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/common_io/iot_pwm.c b/bk7235/liteos_m/bk_sdk_armino/middleware/compal/common_io/iot_pwm.c deleted file mode 100755 index 7b1f7d3170984437889704ec770c7f03e703a36f..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/common_io/iot_pwm.c +++ /dev/null @@ -1,192 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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 -#include -#include -#include -#include "iot_test_common_io_config.h" - -#include -#include -#include -#include -#include - - -#define COMMON_PWM_TAG "common_io_pwm" -#define PWM_CLK_FREQ (26000000UL) - - -typedef struct IotPwmDescriptor { - UINT32 id; - UINT8 set_flag; - IotPwmConfig_t config; -} IotPwmDescriptor_t; -static volatile uint8_t pwm_bit_mask=0; - - -static UINT8 bk_conver_config_to_internal(const IotPwmConfig_t *config, void *internal, bool init) -{ - UINT32 cycle,duty; - - if( (config->ulPwmFrequency == 0) || (config->ucPwmDutyCycle == 0) || (config->ucPwmDutyCycle >= 100) ) - return 0; - - cycle = PWM_CLK_FREQ /config->ulPwmFrequency; - duty = cycle * config->ucPwmDutyCycle / 100; - if(init) - { - ((pwm_init_config_t *)internal)->period_cycle = cycle; - ((pwm_init_config_t *)internal)->duty_cycle = duty; - } - else - { - ((pwm_period_duty_config_t *)internal)->period_cycle = cycle; - ((pwm_period_duty_config_t *)internal)->duty_cycle = duty; - } - return 1; -} - - - -IotPwmHandle_t iot_pwm_open( int32_t lPwmInstance ) -{ - IotPwmDescriptor_t *pwm_ctx; - pwm_init_config_t internal; - if ( (lPwmInstance < 0) || ( lPwmInstance >= PWM_ID_MAX ) ) - { - BK_LOGE(COMMON_PWM_TAG, "Invalid arguments\r\n"); - return NULL; - } - BK_LOGD(COMMON_PWM_TAG, "pwm_open\r\n"); - bk_pwm_driver_init(); - if(pwm_bit_mask & BIT(lPwmInstance)) - return NULL; - - pwm_ctx = (IotPwmDescriptor_t *) os_zalloc(sizeof(IotPwmDescriptor_t)); - if(pwm_ctx != NULL) - { - pwm_ctx->id = lPwmInstance; - pwm_ctx->config.ulPwmFrequency = 2000; - pwm_ctx->config.ucPwmDutyCycle = 20; - pwm_ctx->config.ucPwmChannel = 0; - memset(&internal, 0, sizeof(pwm_init_config_t)); - bk_conver_config_to_internal(&(pwm_ctx->config), &internal, 1); - if(bk_pwm_init(lPwmInstance, &internal) != BK_OK) - { - os_free(pwm_ctx); - BK_LOGE(COMMON_PWM_TAG, "!!!bk_pwm_init error\r\n"); - return NULL; - } - bk_pwm_set_init_signal_low(lPwmInstance); - pwm_bit_mask |= BIT(lPwmInstance); - } - else - { - BK_LOGE(COMMON_PWM_TAG,"!!!pwm zalloc fail \r\n"); - } - return pwm_ctx; -} - -int32_t iot_pwm_set_config( IotPwmHandle_t const pxPwmHandle, const IotPwmConfig_t xConfig ) -{ - if (pxPwmHandle == NULL) - { - BK_LOGE(COMMON_PWM_TAG, "Invalid arguments\r\n"); - return IOT_PWM_INVALID_VALUE; - } - BK_LOGD(COMMON_PWM_TAG, "pwm_set\r\n"); - pwm_period_duty_config_t internal; - memset(&internal, 0 , sizeof(pwm_period_duty_config_t)); - if(bk_conver_config_to_internal(&xConfig, &internal, 0)) - { - if(bk_pwm_set_period_duty(pxPwmHandle->id, &internal) != BK_OK) - { - BK_LOGE(COMMON_PWM_TAG, "!!!set_period_duty error\r\n"); - return IOT_PWM_INVALID_VALUE; - } - pxPwmHandle->config = xConfig; - pxPwmHandle->set_flag = 1; - return IOT_PWM_SUCCESS; - } - else - { - return IOT_PWM_INVALID_VALUE; - } -} - -IotPwmConfig_t * iot_pwm_get_config( IotPwmHandle_t const pxPwmHandle ) -{ - if (pxPwmHandle == NULL) - { - BK_LOGE(COMMON_PWM_TAG, "Invalid arguments\r\n"); - return NULL; - } - BK_LOGD(COMMON_PWM_TAG, "pwm_get\r\n"); - if(pxPwmHandle->set_flag) - return &(pxPwmHandle->config); - else - return NULL; -} - -int32_t iot_pwm_start( IotPwmHandle_t const pxPwmHandle ) -{ - if (pxPwmHandle == NULL) - { - BK_LOGE(COMMON_PWM_TAG, "Invalid arguments\r\n"); - return IOT_PWM_INVALID_VALUE; - } - BK_LOGD(COMMON_PWM_TAG, "pwm_start\r\n"); - if(pxPwmHandle->set_flag) - { - bk_pwm_start(pxPwmHandle->id); - return IOT_PWM_SUCCESS; - } - else - return IOT_PWM_NOT_CONFIGURED; -} - -int32_t iot_pwm_stop( IotPwmHandle_t const pxPwmHandle ) -{ - if (pxPwmHandle == NULL) - { - BK_LOGE(COMMON_PWM_TAG, "Invalid arguments\r\n"); - return IOT_PWM_INVALID_VALUE; - } - BK_LOGD(COMMON_PWM_TAG, "pwm_stop\r\n"); - bk_pwm_stop(pxPwmHandle->id); - return IOT_PWM_SUCCESS; -} - -int32_t iot_pwm_close( IotPwmHandle_t const pxPwmHandle ) -{ - if (pxPwmHandle == NULL) - { - BK_LOGE(COMMON_PWM_TAG, "Invalid arguments\r\n"); - return IOT_PWM_INVALID_VALUE; - } - BK_LOGD(COMMON_PWM_TAG, "pwm_close\r\n"); - if(pwm_bit_mask & BIT(pxPwmHandle->id)) - { - bk_pwm_deinit(pxPwmHandle->id); - os_free(pxPwmHandle); - pwm_bit_mask &= (~ BIT(pxPwmHandle->id)); - return IOT_PWM_SUCCESS; - } - else - return IOT_PWM_INVALID_VALUE; -} - diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/common_io/iot_reset.c b/bk7235/liteos_m/bk_sdk_armino/middleware/compal/common_io/iot_reset.c deleted file mode 100755 index 17cca071ffe6310a288dfa28027efaacefd057cb..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/common_io/iot_reset.c +++ /dev/null @@ -1,69 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - - -/* These APIs require the following menuconfig options enabled: - * - * CONFIG_PM_ENABLE=y - * CONFIG_PM_LIGHT_SLEEP_CALLBACKS=y - * CONFIG_FREERTOS_LEGACY_HOOKS=y - * CONFIG_FREERTOS_LEGACY_IDLE_HOOK=y - * CONFIG_FREERTOS_LEGACY_TICK_HOOK=y - * CONFIG_FREERTOS_USE_TICKLESS_IDLE=y - */ - -#include -#include -#include - -#include -#include -#include "reset_reason.h" - - - - -#define COMMON_RESET_TAG "bk-iot-reset" - -void iot_reset_reboot( IotResetBootFlag_t xResetBootFlag ) -{ - bk_reboot(); -} - -int32_t iot_reset_shutdown( void ) -{ - return IOT_RESET_FUNCTION_NOT_SUPPORTED; -} - -int32_t iot_get_reset_reason( IotResetReason_t * xResetReason ) -{ - if(xResetReason == NULL){ - BK_LOGE(COMMON_RESET_TAG, "iot_get_reset_reason err,invalid ptr\r\n"); - return IOT_RESET_INVALID_VALUE; - } - RESET_SOURCE_STATUS start_type = bk_misc_get_start_type(); - switch (start_type) { - case RESET_SOURCE_POWERON: - *xResetReason = eResetPowerOnBoot; - case RESET_SOURCE_REBOOT: - *xResetReason = eResetWarmBoot; - case RESET_SOURCE_WATCHDOG: - *xResetReason = eResetWatchdog; - default: - *xResetReason = eResetOther; - } - - return IOT_RESET_SUCCESS; -} - diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/common_io/iot_rtc.c b/bk7235/liteos_m/bk_sdk_armino/middleware/compal/common_io/iot_rtc.c deleted file mode 100755 index 0dc949ae0cbe8111d03d34dd7423c04467cab031..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/common_io/iot_rtc.c +++ /dev/null @@ -1,446 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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 -#include "FreeRTOS.h" -#include "semphr.h" -#include - -#include "iot_rtc.h" - -#include -#include "aon_rtc_driver.h" -#include "aon_rtc_hal.h" - -#include "sys_driver.h" -#include "portmacro.h" - -#include "sys/time.h" -#include "time.h" - - -#define RTC_TAG "RTC" -#ifdef RTC_TAG -#define RTC_LOGI(...) BK_LOGI(RTC_TAG, ##__VA_ARGS__) -#define RTC_LOGW(...) BK_LOGW(RTC_TAG, ##__VA_ARGS__) -#define RTC_LOGE(...) BK_LOGE(RTC_TAG, ##__VA_ARGS__) -#define RTC_LOGD(...) BK_LOGD(RTC_TAG, ##__VA_ARGS__) -#else -#define RTC_LOGI(...) -#define RTC_LOGW(...) -#define RTC_LOGE(...) -#define RTC_LOGD(...) - -#endif - -#define RTC_CLK_FREQ 32000 //unit:31us -#define USEC_TO_SEC (1000000) -#define INVALID_VAL_YEAR (0xFFFF) -#define LIMIT_VAL_MONTH (12) -#define LIMIT_VAL_DAY (31) -#define LIMIT_VAL_HOUR (23) -#define LIMIT_VAL_MINUTE (59) -#define LIMIT_VAL_SECOND (59) -#define LIMIT_VAL_WDAY (7) - - -typedef struct IotRtcDescriptor -{ - IotRtcStatus_t status;//work status - void (*func)(IotRtcStatus_t arg1,void *arg2); - void *arg2; - - time_t uUTC_time; - struct timeval seconds; - - uint8_t alarmName[ALARM_NAME_MAX_LEN]; - uint32_t uWakeUpTick; -}IotRtcDescriptor_t; - -int64_t s_microseconds_offset=0; -/*************************User driver related***********************************/ -int gettimeofday(struct timeval *tv, void *ptz) -{ - (void)ptz; - - if(tv!=NULL) - { - uint64_t uCurTimeUs=s_microseconds_offset+bk_aon_rtc_get_current_tick(AON_RTC_ID_1)*1000000LL/RTC_CLK_FREQ; - - tv->tv_sec=uCurTimeUs/1000000; - tv->tv_usec=uCurTimeUs%1000000; - RTC_LOGI("%s sec:%d us:%d \n",__func__,tv->tv_sec,tv->tv_usec); - } - - return IOT_RTC_SUCCESS; - -} - -int settimeofday(const struct timeval *tv,const struct timezone *tz) -{ - (void)tz; - if(tv) - { - uint64_t setTimeUs=((uint64_t)tv->tv_sec)*1000000LL+tv->tv_usec ; - uint64_t getCurTimeUs=bk_aon_rtc_get_current_tick(AON_RTC_ID_1)*1000000LL/RTC_CLK_FREQ; - s_microseconds_offset=setTimeUs-getCurTimeUs; - RTC_LOGI("%s sec:%d us:%d \n",__func__,tv->tv_sec,tv->tv_usec); - RTC_LOGI("%s set:%d cur:%d diff:%d \n",__func__,setTimeUs,getCurTimeUs,s_microseconds_offset); - - } - return IOT_RTC_SUCCESS; -} - - - -static bool is_rtc_opened=false; - -IotRtcHandle_t iot_rtc_open( int32_t lRtcInstance ) -{ - if(lRtcInstance!=0) - { - RTC_LOGE("%s Err idx\n",__func__); - return NULL; - } - if(is_rtc_opened==true) - { - RTC_LOGE("%s ReOpen Err\n",__func__); - return NULL; - } - - /*bk_aon_rtc_tick_init started in pm.c*/ - - IotRtcHandle_t time_rtc_instance=(IotRtcDescriptor_t*)os_zalloc(sizeof(IotRtcDescriptor_t)); - if(time_rtc_instance==NULL) - { - RTC_LOGE("There is not enough ememory for RTC\n"); - return NULL; - } - is_rtc_opened=true; - time_rtc_instance->status=eRtcTimerStopped; -// time_rtc_instance->rtc_status=IOT_RTC_NOT_STARTED; - RTC_LOGI("%s Opened\n",__func__); - return time_rtc_instance; -} - -int32_t iot_rtc_set_datetime( IotRtcHandle_t const pxRtcHandle, - const IotRtcDatetime_t * pxDatetime ) -{ - if((pxRtcHandle==NULL)||(pxDatetime==NULL)) - { - RTC_LOGE("%s handle err\n",__func__); - return IOT_RTC_INVALID_VALUE; - } - if(pxDatetime->usYear==INVALID_VAL_YEAR) - { - RTC_LOGE("%s param err\n",__func__); - return IOT_RTC_INVALID_VALUE; - } - if((pxDatetime->ucMonth>LIMIT_VAL_MONTH)||(pxDatetime->ucDay>LIMIT_VAL_DAY)||(pxDatetime->ucHour>LIMIT_VAL_HOUR) - ||(pxDatetime->ucMinute>LIMIT_VAL_MINUTE)||(pxDatetime->ucSecond>LIMIT_VAL_SECOND)||(pxDatetime->ucWday>LIMIT_VAL_WDAY)) - { - RTC_LOGE("%s over limit \n",__func__); - return IOT_RTC_SET_FAILED; - } - //do the action - struct tm tmp; - tmp.tm_sec=pxDatetime->ucSecond; - tmp.tm_min=pxDatetime->ucMinute; - tmp.tm_hour=pxDatetime->ucHour; - tmp.tm_mday=pxDatetime->ucDay; - tmp.tm_mon=pxDatetime->ucMonth; - tmp.tm_year=pxDatetime->usYear; - tmp.tm_wday=pxDatetime->ucWday; - - IotRtcHandle_t rtc_instance=pxRtcHandle; - rtc_instance->seconds.tv_sec=mktime(&tmp); - RTC_LOGI("%s set Sec %d us:%d \n",__func__,rtc_instance->seconds.tv_sec,rtc_instance->seconds.tv_usec); - - if(settimeofday(&rtc_instance->seconds,NULL)!=IOT_RTC_SUCCESS) - { - return IOT_RTC_SET_FAILED; - } - - rtc_instance->status=eRtcTimerRunning; -// rtc_instance->rtc_status=eRtcTimerRunning; - - return IOT_RTC_SUCCESS; -} - -int32_t iot_rtc_get_datetime( IotRtcHandle_t const pxRtcHandle, - IotRtcDatetime_t * pxDatetime ) -{ - if((pxRtcHandle==NULL)||(pxDatetime==NULL)) - { - RTC_LOGE("%s err value\n",__func__); - return IOT_RTC_INVALID_VALUE; - } - - IotRtcHandle_t rtc_instance=pxRtcHandle; - if(rtc_instance->status==eRtcTimerStopped) - { - RTC_LOGE("%s rtc not started\n",__func__); - return IOT_RTC_NOT_STARTED; - } - - struct timeval s_get_time; - - if(gettimeofday(&s_get_time,NULL)!=IOT_RTC_SUCCESS) - { - RTC_LOGE("%s get cur time err\n",__func__); - return IOT_RTC_GET_FAILED; - } - - struct tm *tmp; - tmp=gmtime(&s_get_time.tv_sec); - pxDatetime->usYear=tmp->tm_year; - pxDatetime->ucMonth=tmp->tm_mon; - pxDatetime->ucDay=tmp->tm_mday; - pxDatetime->ucHour=tmp->tm_hour; - pxDatetime->ucMinute=tmp->tm_min; - pxDatetime->ucSecond=tmp->tm_sec; - pxDatetime->ucWday=tmp->tm_wday; - RTC_LOGI("%s year:%d mon:%d day:%d hour:%d min:%d sec:%d wd:%d\n",__func__,pxDatetime->usYear,pxDatetime->ucMonth, - pxDatetime->ucDay,pxDatetime->ucHour,pxDatetime->ucMinute,pxDatetime->ucSecond,pxDatetime->ucWday); - return IOT_RTC_SUCCESS; -} -static void rtc_cb(aon_rtc_id_t id,uint8_t *name_p,void *param) -{ - RTC_LOGI("id:%d name:%s ",id,name_p); - IotRtcHandle_t rtc_instance=(IotRtcDescriptor_t*)param; - if(rtc_instance->func) - { - rtc_instance->func(rtc_instance->status,rtc_instance->arg2); - rtc_instance->func=NULL; - } - RTC_LOGI(" :%s\n",__func__); -} - -static void rtc_wake_cb(aon_rtc_id_t id,uint8_t *name_p,void *param) -{ - RTC_LOGI("%s ",__func__); - IotRtcHandle_t rtc_instance=(IotRtcDescriptor_t*)param; - if(rtc_instance->func) - { - rtc_instance->func(rtc_instance->status,rtc_instance->arg2); - rtc_instance->func=NULL; - - } - RTC_LOGI(" id:%d name:%s \n",id,name_p); -} - -void iot_rtc_set_callback( IotRtcHandle_t const pxRtcHandle, - IotRtcCallback_t xCallback, - void * pvUserContext ) -{ - if(pxRtcHandle==NULL) - { - RTC_LOGE("Callback Invalid Handle\n"); - return; - } - - IotRtcHandle_t rtc_instance=pxRtcHandle; - rtc_instance->func=xCallback; - rtc_instance->arg2=pvUserContext; -} - -int32_t iot_rtc_ioctl( IotRtcHandle_t const pxRtcHandle, - IotRtcIoctlRequest_t xRequest, - void * const pvBuffer ) -{ - if((pxRtcHandle==NULL)||(xRequest==-1)) - { - return IOT_RTC_INVALID_VALUE; - } - IotRtcHandle_t rtc_instance=pxRtcHandle; - - struct timeval get_time; - struct tm tmp; - - switch(xRequest) - { - case eSetRtcAlarm: - { - if(rtc_instance->status==eRtcTimerStopped) - { - RTC_LOGE("eSetRtcAlarm Rtc not start\n"); - return IOT_RTC_NOT_STARTED; - } - gettimeofday(&get_time,NULL); - IotRtcDatetime_t *user_time=(IotRtcDatetime_t*)pvBuffer; - if((user_time->ucMonth>LIMIT_VAL_MONTH)||(user_time->ucDay>LIMIT_VAL_DAY)||(user_time->ucHour>LIMIT_VAL_HOUR) - ||(user_time->ucMinute>LIMIT_VAL_MINUTE)||(user_time->ucSecond>LIMIT_VAL_SECOND)||(user_time->ucWday>LIMIT_VAL_WDAY)) - { - return IOT_RTC_SET_FAILED; - } - tmp.tm_sec=user_time->ucSecond; - tmp.tm_min=user_time->ucMinute; - tmp.tm_hour=user_time->ucHour; - tmp.tm_mday=user_time->ucDay; - tmp.tm_mon=user_time->ucMonth; - tmp.tm_year=user_time->usYear; - tmp.tm_wday=user_time->ucWday; - - rtc_instance->uUTC_time=mktime(&tmp)-get_time.tv_sec; - if(rtc_instance->uUTC_time<=0) - { - RTC_LOGE("Set Invalid Alarm \n"); - return IOT_RTC_INVALID_VALUE; - } - - alarm_info_t alarm_info; - alarm_info.name[0]='S'; - alarm_info.name[1]='e'; - alarm_info.name[2]='t'; - alarm_info.name[3]='R'; - alarm_info.name[4]='t'; - alarm_info.name[5]='c'; - - alarm_info.period_tick=(uint64_t)rtc_instance->uUTC_time*RTC_CLK_FREQ;//switch to tick cnt - RTC_LOGI("eSetRtcAlarm Tgt:%d period:%d ",rtc_instance->uUTC_time,alarm_info.period_tick); - alarm_info.period_cnt=1; - alarm_info.param_p=(void*)rtc_instance; - alarm_info.callback=rtc_cb; - bk_alarm_register(AON_RTC_ID_1,&alarm_info); - os_memcpy(rtc_instance->alarmName,alarm_info.name,ALARM_NAME_MAX_LEN); - rtc_instance->uUTC_time=mktime(&tmp); - rtc_instance->status=eRtcTimerAlarmTriggered; - RTC_LOGI(" status:%d",rtc_instance->status); - } - break; - case eGetRtcAlarm: - { - if(rtc_instance->status!=eRtcTimerAlarmTriggered) - { - return IOT_RTC_NOT_STARTED; - } - gettimeofday(&get_time,NULL); - struct tm *get_alarm; - get_alarm=gmtime(&rtc_instance->uUTC_time); - IotRtcDatetime_t *user_time=(IotRtcDatetime_t*)pvBuffer; - user_time->usYear=get_alarm->tm_year; - user_time->ucMonth=get_alarm->tm_mon; - user_time->ucDay=get_alarm->tm_mday; - user_time->ucHour=get_alarm->tm_hour; - user_time->ucMinute=get_alarm->tm_min; - user_time->ucSecond=get_alarm->tm_sec; - user_time->ucWday=get_alarm->tm_wday; - RTC_LOGI("eGetRtcAlarm status:%d \n",rtc_instance->status); - } - break; - case eCancelRtcAlarm: - { - if(rtc_instance->status!=eRtcTimerAlarmTriggered) - { - return IOT_RTC_SET_FAILED; - } - bk_alarm_unregister(AON_RTC_ID_1,rtc_instance->alarmName); - rtc_instance->status=eRtcTimerStopped; - } - break; - - case eGetRtcStatus: - { - IotRtcStatus_t *rtc_status=(IotRtcStatus_t *)pvBuffer; - *rtc_status=rtc_instance->status; - RTC_LOGI("eGetRtcStatus:%d\n",*rtc_status); - } - break; - case eSetRtcWakeupTime: - { - if(rtc_instance->status==eRtcTimerStopped) - { - RTC_LOGE("eSetRtcWakeupTime Rtc not start\n"); - return IOT_RTC_NOT_STARTED; - } -// return IOT_RTC_FUNCTION_NOT_SUPPORTED; - uint32_t *uWakeUpTimeMs=(uint32_t*)pvBuffer; - if((*uWakeUpTimeMs)<=0) - { - RTC_LOGE("eSetRtcWakeupTime param err:%d",(*uWakeUpTimeMs)); - return IOT_RTC_INVALID_VALUE; - } - alarm_info_t alarm_info; - alarm_info.name[0]='S'; - alarm_info.name[1]='e'; - alarm_info.name[2]='t'; - alarm_info.name[3]='W'; - alarm_info.name[4]='A'; - alarm_info.name[5]='K'; - - alarm_info.period_tick=(*uWakeUpTimeMs)*RTC_CLK_FREQ/1000;//switch to tick cnt - alarm_info.period_cnt=1; - alarm_info.param_p=(void*)rtc_instance; - alarm_info.callback=rtc_wake_cb; - bk_alarm_register(AON_RTC_ID_1,&alarm_info); - os_memcpy(rtc_instance->alarmName,alarm_info.name,ALARM_NAME_MAX_LEN); - rtc_instance->status=eRtcTimerWakeupTriggered; - rtc_instance->uWakeUpTick=alarm_info.period_tick;//(*uWakeUpTimeMs)*RTC_CLK_FREQ/1000; - RTC_LOGI("eSetRtcWakeupTime Tgt_ms:%d period:%d curTick:%d\n",(*uWakeUpTimeMs),rtc_instance->uWakeUpTick,alarm_info.period_tick); - } - break; - case eGetRtcWakeupTime: - { - if(rtc_instance->status!=eRtcTimerWakeupTriggered) - { - return IOT_RTC_NOT_STARTED; - } - // return IOT_RTC_FUNCTION_NOT_SUPPORTED; - uint32_t *uGetMs=(uint32_t *)pvBuffer; - (*uGetMs)=rtc_instance->uWakeUpTick*1000/RTC_CLK_FREQ; - - RTC_LOGI("eGetRtcWakeupTime :%dms \n",(*uGetMs)); - } - break; - case eCancelRtcWakeup: - { - if(rtc_instance->status!=eRtcTimerWakeupTriggered) - { - return IOT_RTC_SET_FAILED; - } - // return IOT_RTC_FUNCTION_NOT_SUPPORTED; - bk_alarm_unregister(AON_RTC_ID_1,rtc_instance->alarmName); - rtc_instance->status=eRtcTimerStopped; - } - break; - - default: - { - return IOT_RTC_INVALID_VALUE; - } - break; - } - - return IOT_RTC_SUCCESS; -} - -int32_t iot_rtc_close( IotRtcHandle_t const pxRtcHandle ) -{ - if(pxRtcHandle==NULL) - { - RTC_LOGE("%s Invalid Handler\n",__func__); - return IOT_RTC_INVALID_VALUE; - } - - if(is_rtc_opened==false) - { - RTC_LOGE("%s aleady closed\n",__func__); - return IOT_RTC_INVALID_VALUE; - } - is_rtc_opened=false; - os_free(pxRtcHandle); - RTC_LOGI("%s sucess\n",__func__); - return IOT_RTC_SUCCESS; -} - diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/common_io/iot_spi.c b/bk7235/liteos_m/bk_sdk_armino/middleware/compal/common_io/iot_spi.c deleted file mode 100755 index 44edaba3c4f04e2e3dc8063a9d81e5b4b4f2c466..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/common_io/iot_spi.c +++ /dev/null @@ -1,364 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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 -#include -#include -#include -#include "iot_test_common_io_config.h" - -#include -#include -#include -#include -#include - - -#define COMMON_SPI_TAG "common_io_spi" -#define _SELF_TEST_ 0 - - -typedef struct IotSPIDescriptor { - UINT32 id; - IotSPIMasterConfig_t config; - uint32_t bytes_read; - uint32_t bytes_written; - IotSPICallback_t func; - void * arg; - UINT8 *trans_read; - UINT32 trans_len; - IotSPITransactionStatus_t status; -} IotSPIDescriptor_t; -static volatile uint8_t spi_bit_mask=0; - - -static void bk_conver_config_to_internal(IotSPIMasterConfig_t *config, spi_config_t *internal) -{ - memset(internal, 0, sizeof(spi_config_t)); - internal->role = SPI_ROLE_MASTER; - internal->bit_width = SPI_BIT_WIDTH_8BITS; - internal->wire_mode = SPI_3WIRE_MODE; - - internal->bit_order = config->eSetBitOrder; - internal->baud_rate = config->ulFreq; - switch (config->eMode) { - case eSPIMode0: - internal->polarity = SPI_POLARITY_LOW; - internal->phase = SPI_PHASE_1ST_EDGE; - break; - case eSPIMode1: - internal->polarity = SPI_POLARITY_LOW; - internal->phase = SPI_PHASE_2ND_EDGE; - break; - case eSPIMode2: - internal->polarity = SPI_POLARITY_HIGH; - internal->phase = SPI_PHASE_1ST_EDGE; - break; - case eSPIMode3: - default: - internal->polarity = SPI_POLARITY_HIGH; - internal->phase = SPI_PHASE_2ND_EDGE; - break; - } -} - - -static void spi_rx_callback_dispatch(spi_id_t id, void *param) -{ - IotSPIDescriptor_t *spi_ctx = (IotSPIDescriptor_t *)param; - BK_LOGD(COMMON_SPI_TAG, "rx_callback\r\n"); - - spi_ctx->bytes_read = spi_ctx->trans_len; - if (spi_ctx->func) { - spi_ctx->func(spi_ctx->status, spi_ctx->arg); - } - - if(spi_ctx->trans_read != NULL) - { - -#if ( _SELF_TEST_ == 1 ) - spi_ctx->trans_read[0] = 1; - spi_ctx->trans_read[1] = 3; - spi_ctx->trans_read[2] = 5; - spi_ctx->trans_read[3] = 7; -#endif - spi_ctx->trans_read = NULL; - } - -} - -static void spi_tx_callback_dispatch(spi_id_t id, void *param) -{ - IotSPIDescriptor_t *spi_ctx = (IotSPIDescriptor_t *)param; - spi_ctx->bytes_written = spi_ctx->trans_len; - BK_LOGD(COMMON_SPI_TAG, "tx_callback\r\n"); - if(spi_ctx->trans_read != NULL) - { - bk_spi_register_rx_finish_isr(spi_ctx->id, spi_rx_callback_dispatch, spi_ctx); - bk_spi_read_bytes_async(spi_ctx->id, spi_ctx->trans_read, spi_ctx->trans_len); - } - else if (spi_ctx->func) - { - spi_ctx->func(spi_ctx->status, spi_ctx->arg); - } -} - - -IotSPIHandle_t iot_spi_open( int32_t lSPIInstance ) -{ - IotSPIDescriptor_t *spi_ctx; - spi_config_t internal; - if ( (lSPIInstance < 0) || ( lSPIInstance >= SPI_ID_MAX ) ) { - BK_LOGE(COMMON_SPI_TAG, "Invalid arguments\r\n"); - return NULL; - } - BK_LOGD(COMMON_SPI_TAG, "spi_open\r\n"); - bk_spi_driver_init(); - if(spi_bit_mask & BIT(lSPIInstance)) - return NULL; - - spi_ctx = (IotSPIDescriptor_t *) os_zalloc(sizeof(IotSPIDescriptor_t)); - if(spi_ctx != NULL) - { - spi_ctx->id = lSPIInstance; - spi_ctx->config.ulFreq = 500000; - spi_ctx->config.eMode = eSPIMode0; - spi_ctx->config.eSetBitOrder = eSPIMSBFirst; - spi_ctx->config.ucDummyValue = 0xff; - bk_conver_config_to_internal(&(spi_ctx->config),&internal); - bk_spi_init(lSPIInstance, &internal); - spi_bit_mask |= BIT(lSPIInstance); - } - else - { - BK_LOGE(COMMON_SPI_TAG,"!!!spi zalloc fail \r\n"); - } - return spi_ctx; -} - -void iot_spi_set_callback(IotSPIHandle_t const pxSPIPeripheral, IotSPICallback_t xCallback, void * pvUserContext) -{ - if (pxSPIPeripheral == NULL || xCallback == NULL) { - BK_LOGE(COMMON_SPI_TAG, "Invalid arguments\r\n"); - } - BK_LOGD(COMMON_SPI_TAG, "set_callback\r\n"); - IotSPIDescriptor_t *spi_ctx = (IotSPIDescriptor_t *) pxSPIPeripheral; - - spi_ctx->arg = pvUserContext; - spi_ctx->func = (void *)xCallback; -} - -int32_t iot_spi_ioctl( IotSPIHandle_t const pxSPIPeripheral, - IotSPIIoctlRequest_t xSPIRequest, - void * const pvBuffer ) -{ - if ( pxSPIPeripheral == NULL || pvBuffer == NULL ) { - BK_LOGE(COMMON_SPI_TAG, "Invalid arguments\r\n"); - return IOT_SPI_INVALID_VALUE; - } - BK_LOGD(COMMON_SPI_TAG, "spi_ioctl\r\n"); - IotSPIDescriptor_t *spi_ctx = (IotSPIDescriptor_t *) pxSPIPeripheral; - spi_config_t internal; - IotSPIMasterConfig_t *iot_spi_cfg; - uint32_t *bytes; - - - switch (xSPIRequest) - { - case eSPISetMasterConfig: - iot_spi_cfg = (IotSPIMasterConfig_t *) pvBuffer; - memcpy(&spi_ctx->config, iot_spi_cfg, sizeof(IotSPIMasterConfig_t)); - bk_conver_config_to_internal(iot_spi_cfg,&internal); - bk_spi_init(pxSPIPeripheral->id,&internal); - break; - - case eSPIGetMasterConfig: - iot_spi_cfg = (IotSPIMasterConfig_t *) pvBuffer; - memcpy(iot_spi_cfg, &spi_ctx->config, sizeof(IotSPIMasterConfig_t)); - break; - - case eSPIGetTxNoOfbytes: - bytes = (uint32_t*) pvBuffer; - *bytes = spi_ctx->bytes_written; - break; - - case eSPIGetRxNoOfbytes: - bytes = (uint32_t*) pvBuffer; - *bytes = spi_ctx->bytes_read; - break; - - default: - return IOT_SPI_INVALID_VALUE; - } - return IOT_SPI_SUCCESS; -} - -int32_t iot_spi_write_sync(IotSPIHandle_t const pxSPIPeripheral, uint8_t * const pvBuffer, size_t xBytes) -{ - bk_err_t ret; - if (pxSPIPeripheral == NULL || pvBuffer == NULL || xBytes == 0) { - BK_LOGE(COMMON_SPI_TAG,"Invalid arguments\r\n"); - return IOT_SPI_INVALID_VALUE; - } - BK_LOGD(COMMON_SPI_TAG, "write_sync\r\n"); - - IotSPIDescriptor_t * spi_ctx = (IotSPIDescriptor_t *) pxSPIPeripheral; - spi_ctx->bytes_read = 0; - - ret = bk_spi_write_bytes(spi_ctx->id, pvBuffer, xBytes); - if (ret != BK_OK) { - BK_LOGE(COMMON_SPI_TAG, "Failed to write SPI sync data \r\n"); - return IOT_SPI_WRITE_FAILED; - } - spi_ctx->bytes_written = xBytes; - - return IOT_SPI_SUCCESS; -} - -int32_t iot_spi_read_sync(IotSPIHandle_t const pxSPIPeripheral, uint8_t * const pvBuffer, size_t xBytes) -{ - bk_err_t ret; - if (pxSPIPeripheral == NULL || pvBuffer == NULL || xBytes == 0) { - BK_LOGE(COMMON_SPI_TAG,"Invalid arguments\r\n"); - return IOT_SPI_INVALID_VALUE; - } - BK_LOGD(COMMON_SPI_TAG, "read_sync\r\n"); - - IotSPIDescriptor_t * spi_ctx = (IotSPIDescriptor_t *) pxSPIPeripheral; - spi_ctx->bytes_written = 0; - ret = bk_spi_read_bytes(spi_ctx->id, pvBuffer, xBytes); - - if (ret != BK_OK) { - BK_LOGE(COMMON_SPI_TAG, "Failed to read SPI sync data \r\n"); - return IOT_SPI_READ_FAILED; - } - -#if ( _SELF_TEST_ == 1 ) - pvBuffer[0] = 1; - pvBuffer[1] = 3; - pvBuffer[2] = 5; - pvBuffer[3] = 7; -#endif - spi_ctx->bytes_read = xBytes; - - return IOT_SPI_SUCCESS; -} - -int32_t iot_spi_write_async(IotSPIHandle_t const pxSPIPeripheral, uint8_t * const pvBuffer, size_t xBytes) -{ - if (pxSPIPeripheral == NULL || pvBuffer == NULL || xBytes == 0) { - BK_LOGE(COMMON_SPI_TAG,"Invalid arguments\r\n"); - return IOT_SPI_INVALID_VALUE; - } - BK_LOGD(COMMON_SPI_TAG, "write_async\r\n"); - - IotSPIDescriptor_t * spi_ctx = (IotSPIDescriptor_t *) pxSPIPeripheral; - spi_ctx->bytes_read = 0; - spi_ctx->trans_len = xBytes; - bk_spi_register_tx_finish_isr(spi_ctx->id, spi_tx_callback_dispatch, spi_ctx); - bk_spi_write_bytes_async(spi_ctx->id, pvBuffer, xBytes); - - return IOT_SPI_SUCCESS; -} - -int32_t iot_spi_read_async(IotSPIHandle_t const pxSPIPeripheral, uint8_t * const pvBuffer, size_t xBytes) -{ - if (pxSPIPeripheral == NULL || pvBuffer == NULL || xBytes == 0) { - BK_LOGE(COMMON_SPI_TAG,"Invalid arguments\r\n"); - return IOT_SPI_INVALID_VALUE; - } - BK_LOGD(COMMON_SPI_TAG, "read_async\r\n"); - - IotSPIDescriptor_t * spi_ctx = (IotSPIDescriptor_t *) pxSPIPeripheral; - spi_ctx->bytes_written = 0; -#if ( _SELF_TEST_ == 1 ) - spi_ctx->trans_read = pvBuffer; -#endif - spi_ctx->trans_len = xBytes; - bk_spi_register_rx_finish_isr(spi_ctx->id, spi_rx_callback_dispatch, spi_ctx); - bk_spi_read_bytes_async(spi_ctx->id, pvBuffer, xBytes); - - return IOT_SPI_SUCCESS; -} - -int32_t iot_spi_transfer_sync( IotSPIHandle_t const pxSPIPeripheral, uint8_t * const pvTxBuffer, uint8_t * const pvRxBuffer, size_t xBytes ) -{ - bk_err_t ret; - if (pxSPIPeripheral == NULL || pvTxBuffer == NULL || pvRxBuffer == NULL || xBytes == 0) { - BK_LOGE(COMMON_SPI_TAG,"Invalid arguments\r\n"); - return IOT_SPI_INVALID_VALUE; - } - BK_LOGD(COMMON_SPI_TAG, "transfer_sync\r\n"); - - IotSPIDescriptor_t * spi_ctx = (IotSPIDescriptor_t *) pxSPIPeripheral; - ret = bk_spi_transmit(spi_ctx->id, pvTxBuffer, xBytes, pvRxBuffer, xBytes); - if (ret != BK_OK) { - BK_LOGE(COMMON_SPI_TAG, "Failed to transfer SPI data\r\n"); - return IOT_SPI_WRITE_FAILED; - } - -#if ( _SELF_TEST_ == 1 ) - pvRxBuffer[0] = 1; - pvRxBuffer[1] = 3; - pvRxBuffer[2] = 5; - pvRxBuffer[3] = 7; -#endif - spi_ctx->bytes_read = xBytes; - spi_ctx->bytes_written = xBytes; - - return IOT_SPI_SUCCESS; -} - -int32_t iot_spi_transfer_async(IotSPIHandle_t const pxSPIPeripheral, uint8_t * const pvTxBuffer, uint8_t * const pvRxBuffer, size_t xBytes) -{ - if (pxSPIPeripheral == NULL || pvTxBuffer == NULL || pvRxBuffer == NULL || xBytes == 0) { - BK_LOGE(COMMON_SPI_TAG,"Invalid arguments\r\n"); - return IOT_SPI_INVALID_VALUE; - } - BK_LOGD(COMMON_SPI_TAG, "transfer_async\r\n"); - - IotSPIDescriptor_t * spi_ctx = (IotSPIDescriptor_t *) pxSPIPeripheral; - spi_ctx->trans_read = pvRxBuffer; - spi_ctx->trans_len = xBytes; - bk_spi_register_tx_finish_isr(spi_ctx->id, spi_tx_callback_dispatch, spi_ctx); - bk_spi_write_bytes_async(spi_ctx->id, pvTxBuffer, xBytes); - - return IOT_SPI_SUCCESS; -} - -int32_t iot_spi_close( IotSPIHandle_t const pxSPIPeripheral ) -{ - if (pxSPIPeripheral == NULL) { - BK_LOGE(COMMON_SPI_TAG, "Invalid arguments\r\n"); - return IOT_SPI_INVALID_VALUE; - } - BK_LOGD(COMMON_SPI_TAG, "spi_close\r\n"); - if(spi_bit_mask & BIT(pxSPIPeripheral->id)) - { - bk_spi_unregister_rx_finish_isr(pxSPIPeripheral->id); - bk_spi_unregister_tx_finish_isr(pxSPIPeripheral->id); - bk_spi_deinit(pxSPIPeripheral->id); - os_free(pxSPIPeripheral); - spi_bit_mask &= (~ BIT(pxSPIPeripheral->id)); - return IOT_SPI_SUCCESS; - } - else - return IOT_SPI_INVALID_VALUE; -} - -int32_t iot_spi_cancel( IotSPIHandle_t const pxSPIPeripheral ) -{ - return IOT_SPI_FUNCTION_NOT_SUPPORTED; -} diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/common_io/iot_test_common_io_internal.c b/bk7235/liteos_m/bk_sdk_armino/middleware/compal/common_io/iot_test_common_io_internal.c deleted file mode 100755 index dfc75e35414758e58b360ff61610537a8ff90444..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/common_io/iot_test_common_io_internal.c +++ /dev/null @@ -1,69 +0,0 @@ -// Copyright 2020 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at - -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/* FreeRTOS includes. */ -#include "FreeRTOS.h" -#include "task.h" - -#include "iot_test_common_io_internal.h" -#include "iot_i2c.h" - -/* UART */ -const uint8_t uartTestPort[ UART_TEST_SET ] = { 1 }; -/* Following configurations are not being used for now. */ -const uint32_t uartIotUartFlowControl[ UART_TEST_SET ] = { 0 }; -const uint32_t uartIotUartParity[ UART_TEST_SET ] = { 0 }; -const uint32_t uartIotUartWordLength[ UART_TEST_SET ] = { 0 }; -const uint32_t uartIotUartStopBits[ UART_TEST_SET ] = { 0 }; - -void SET_TEST_IOT_UART_CONFIG( int testSet ) -{ - uctestIotUartPort = uartTestPort[ testSet ]; -} - -/* I2C */ -const uint8_t i2cTestSlaveAddr[ I2C_TEST_SET ] = { 0xD4 }; -const uint8_t i2cTestDeviceRegister[ I2C_TEST_SET ] = { 0x73 }; -const uint8_t i2cTestWriteVal[ I2C_TEST_SET ] = { 0b01101010 }; -const uint8_t i2cTestInstanceIdx[ I2C_TEST_SET ] = { 0 }; -const uint8_t i2cTestInstanceNum[ I2C_TEST_SET ] = { 2 }; - -/* Not used by tests in this code base. */ -IotI2CHandle_t gIotI2cHandle[ 4 ] = { NULL, NULL, NULL, NULL }; - -void SET_TEST_IOT_I2C_CONFIG( int testSet ) -{ - uctestIotI2CSlaveAddr = i2cTestSlaveAddr[ testSet ]; - uctestIotI2CDeviceRegister = i2cTestDeviceRegister[ testSet ]; - uctestIotI2CWriteVal = i2cTestWriteVal[ testSet ]; - uctestIotI2CInstanceIdx = i2cTestInstanceIdx[ testSet ]; - uctestIotI2CInstanceNum = i2cTestInstanceNum[ testSet ]; -} - -/* SPI */ - -const uint8_t spiTestPort[ SPI_TEST_SET ] = { 1 }; -const uint32_t spiIotMode[ SPI_TEST_SET ] = { eSPIMode0 }; -const uint32_t spiIotSpitBitOrder[ SPI_TEST_SET ] = { eSPIMSBFirst }; -const uint32_t spiIotFrequency[ SPI_TEST_SET ] = { 500000U }; -const uint32_t spiIotDummyValue[ SPI_TEST_SET ] = { 0 }; - -void SET_TEST_IOT_SPI_CONFIG(int testSet) -{ - ultestIotSpiInstance = spiTestPort[ testSet ] ; - xtestIotSPIDefaultConfigMode = spiIotMode[ testSet ]; - xtestIotSPIDefaultconfigBitOrder = spiIotSpitBitOrder[ testSet ]; - ultestIotSPIFrequency = spiIotFrequency[ testSet ]; - ultestIotSPIDummyValue = spiIotDummyValue[ testSet ]; -} diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/common_io/iot_timer.c b/bk7235/liteos_m/bk_sdk_armino/middleware/compal/common_io/iot_timer.c deleted file mode 100644 index 4383b7b042a290a2325a3f616458723e67e019ab..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/common_io/iot_timer.c +++ /dev/null @@ -1,218 +0,0 @@ -/** - * @file iot_timer.c - * @brief Beken Corp implementation of Common I/O timer API. - * - * @copyright Copyright (c) 2022 Beken Corp Inc. - * - */ - -/* FreeRTOS kernel layer */ -#include "FreeRTOS.h" -#include "semphr.h" - -/* timer driver layer */ -#include "driver/hal/hal_timer_types.h" -#include "timer_hal.h" -#include "driver/timer.h" -#include "driver/timer_types.h" - -/* timer iot layer */ -#include "iot_timer.h" - -#define IOT_TIMER_TAG "iot_timer" - -/* attention (copied from timer_driver.c, be careful to check and sync) - * 1. timer2 has been used for time cali - * 2. timer3 has been used for clock, but bk7271 use timer1 - * 3. bk7271 has used timer0(10ms) - */ -#define USED_TIMER_ID TIMER_ID0 - -static void timer_callback(timer_id_t id); - -typedef enum{ - IOT_TIMER_OPENED = 0, /*!< timer opened flag */ - IOT_TIMER_CLOSED, /*!< timer closed flag */ -} timer_status_t; - -typedef enum{ - IOT_COUNTER_STARTED = 0, /*!< timer counter started flag */ - IOT_COUNTER_STOPED, /*!< timer counter stoped flag */ -} counter_status_t; - -typedef struct IotTimerDescriptor -{ - timer_id_t timer_id; /*!< timer id */ - uint64_t timeout_us; /*!< timeout setting */ - uint32_t last_count; /*!< care about last count */ - timer_status_t timer_status; /*!< timer status */ - counter_status_t counter_status; /*!< counter status */ - timer_isr_t timer_isr; /*!< timer interrupt service routine */ - IotTimerCallback_t xTimerCallback; /*!< user defined callback function */ - void *pvUserContext; /*!< user defined parameters */ -} IotTimerDescriptor_t; - -static IotTimerDescriptor_t xDefaultTimerDesc = -{ - .timer_id = USED_TIMER_ID, - .timeout_us = 0, - .last_count = 0, - .timer_status = IOT_TIMER_CLOSED, - .counter_status = IOT_COUNTER_STOPED, - .timer_isr = NULL, - .xTimerCallback = NULL, - .pvUserContext = NULL, -}; - -IotTimerHandle_t iot_timer_open(int32_t lTimerInstance) -{ - if(USED_TIMER_ID != lTimerInstance){ - BK_LOGE(IOT_TIMER_TAG, "Invalid instance of timer %s\n", __func__); - return NULL; - } - - IotTimerHandle_t TimerDesc = &xDefaultTimerDesc; - TimerDesc->timer_status = IOT_TIMER_OPENED; - return TimerDesc; -} - -int32_t iot_timer_close( IotTimerHandle_t const pxTimerHandle ) -{ - if(NULL == pxTimerHandle){ - BK_LOGE(IOT_TIMER_TAG, "Invalid handler %s\n", __func__); - return IOT_TIMER_INVALID_VALUE; - } - if(IOT_TIMER_CLOSED == pxTimerHandle->timer_status){ - BK_LOGE(IOT_TIMER_TAG, "Timer handler is not open %s\n", __func__); - return IOT_TIMER_INVALID_VALUE; - } - if(BK_OK != bk_timer_stop(pxTimerHandle->timer_id)) - { - BK_LOGE(IOT_TIMER_TAG, "Timer stop failed %s\n", __func__); - return IOT_TIMER_SET_FAILED; - } - /* Reset the timer handler to default */ - pxTimerHandle->timer_status = IOT_TIMER_CLOSED; - pxTimerHandle->xTimerCallback = NULL; - pxTimerHandle->counter_status = IOT_COUNTER_STOPED; - pxTimerHandle->pvUserContext = NULL; - pxTimerHandle->timer_isr = NULL; - pxTimerHandle->timeout_us = 0; - pxTimerHandle->last_count = 0; - return IOT_TIMER_SUCCESS; -} - -static void timer_callback(timer_id_t id) -{ - IotTimerHandle_t TimerDesc = &xDefaultTimerDesc; - BK_LOGD(IOT_TIMER_TAG, "Timer %d callback\n", id); - if(NULL == TimerDesc->xTimerCallback){ - BK_LOGD(IOT_TIMER_TAG, "Null callback %s\n", __func__); - return; - } - TimerDesc->xTimerCallback(TimerDesc->pvUserContext); - - /* get the timer end count for time out setting*/ - TimerDesc->last_count = bk_timer_get_period(TimerDesc->timer_id); - TimerDesc->timeout_us = 0; - TimerDesc->xTimerCallback = NULL; - TimerDesc->pvUserContext = NULL; - bk_timer_cancel(id); -} - -void iot_timer_set_callback( IotTimerHandle_t const pxTimerHandle, - IotTimerCallback_t xCallback, - void * pvUserContext ) -{ - if(pxTimerHandle == NULL){ - BK_LOGE(IOT_TIMER_TAG, "Invalid handler %s\n", __func__); - return ; - } - pxTimerHandle->timer_isr = timer_callback; - pxTimerHandle->xTimerCallback = xCallback; - pxTimerHandle->pvUserContext = pvUserContext; -} - -int32_t iot_timer_start( IotTimerHandle_t const pxTimerHandle ) -{ - if(NULL == pxTimerHandle){ - BK_LOGE(IOT_TIMER_TAG, "Invalid handler %s\n", __func__); - return IOT_TIMER_INVALID_VALUE; - } - if(NULL == pxTimerHandle->timer_isr){ - if(BK_OK != bk_timer_enable(pxTimerHandle->timer_id)){ - BK_LOGE(IOT_TIMER_TAG, "Timer enable failed %s\n", __func__); - } - } else if(BK_OK != bk_timer_delay_with_callback(pxTimerHandle->timer_id, pxTimerHandle->timeout_us, pxTimerHandle->timer_isr)){ - BK_LOGE(IOT_TIMER_TAG, "Timer start failed %s\n", __func__); - return IOT_TIMER_SET_FAILED; - } - pxTimerHandle->counter_status = IOT_COUNTER_STARTED; - return IOT_TIMER_SUCCESS; -} - -int32_t iot_timer_stop( IotTimerHandle_t const pxTimerHandle ) -{ - if(NULL == pxTimerHandle){ - BK_LOGE(IOT_TIMER_TAG, "Invalid handler %s\n", __func__); - return IOT_TIMER_INVALID_VALUE; - } - if(BK_OK != bk_timer_stop(pxTimerHandle->timer_id)) { - BK_LOGE(IOT_TIMER_TAG, "Timer stop failed %s\n", __func__); - return IOT_TIMER_SET_FAILED; - } - pxTimerHandle->counter_status = IOT_COUNTER_STOPED; - /* reset the last count to zero */ - pxTimerHandle->last_count = 0; - return IOT_TIMER_SUCCESS; -} - -int32_t iot_timer_get_value( IotTimerHandle_t const pxTimerHandle, - uint64_t * ullMicroSeconds ) -{ - if(NULL == pxTimerHandle){ - BK_LOGE(IOT_TIMER_TAG, "Invalid handler %s\n", __func__); - return IOT_TIMER_INVALID_VALUE; - } - if(NULL == ullMicroSeconds){ - BK_LOGE(IOT_TIMER_TAG, "Time buffer is NULL %s\n", __func__); - return IOT_TIMER_INVALID_VALUE; - } - if(IOT_COUNTER_STOPED == pxTimerHandle->counter_status){ - BK_LOGE(IOT_TIMER_TAG, "Timer counter not running %s\n", __func__); - return IOT_TIMER_NOT_RUNNING; - } - *ullMicroSeconds = bk_timer_get_time(pxTimerHandle->timer_id, 1, pxTimerHandle->last_count, TIMER_UNIT_US); - return IOT_TIMER_SUCCESS; -} - -int32_t iot_timer_delay( IotTimerHandle_t const pxTimerHandle, - uint32_t ulDelayMicroSeconds ) -{ - if(NULL == pxTimerHandle){ - BK_LOGE(IOT_TIMER_TAG, "Invalid handler %s\n", __func__); - return IOT_TIMER_INVALID_VALUE; - } - /* set time out value */ - pxTimerHandle->timeout_us = (uint64_t)ulDelayMicroSeconds; - return IOT_TIMER_SUCCESS; -} - -int32_t iot_timer_cancel( IotTimerHandle_t const pxTimerHandle ) -{ - if(NULL == pxTimerHandle){ - BK_LOGE(IOT_TIMER_TAG, "Invalid handler %s\n", __func__); - return IOT_TIMER_INVALID_VALUE; - } - /* this will cancel the timer delay and continue counting without resetting the count to zero */ - if(BK_OK != bk_timer_cancel(pxTimerHandle->timer_id)){ - BK_LOGE(IOT_TIMER_TAG, "Timer delay cancel failed %s\n", __func__); - return IOT_TIMER_FUNCTION_NOT_SUPPORTED; - } - /* set time out to zero */ - pxTimerHandle->timeout_us = 0; - /* set the timer isr to NULL */ - pxTimerHandle->timer_isr = NULL; - return IOT_TIMER_SUCCESS; -} - diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/common_io/iot_tsensor.c b/bk7235/liteos_m/bk_sdk_armino/middleware/compal/common_io/iot_tsensor.c deleted file mode 100644 index 413f798057a2eadf5b1d6ac35b195df56dfb88b7..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/common_io/iot_tsensor.c +++ /dev/null @@ -1,145 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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 "common/bk_include.h" -#include "common/bk_err.h" -#include "temp_detect_pub.h" -#include "iot_tsensor.h" -#include "os/mem.h" -#include - -#define INIT_TEMPERATUE_VLAUE 25//the raw temperature - -static bool s_temp_active_flag; -static bool s_temp_en_disable_flag; - -IotTsensorHandle_t iot_tsensor_open(int32_t lTsensorInstance) -{ - uint32_t dw_rtn = 0; - - if((lTsensorInstance > 0) || (s_temp_active_flag == true)){ - return NULL; - } - else if (temp_detect_is_init() == true){ - s_temp_active_flag = true; - return (IotTsensorHandle_t) 1; - } - else{ - dw_rtn = temp_detect_init(INIT_TEMPERATUE_VLAUE); - - if(dw_rtn != BK_OK){ - return NULL; - } - else{ - s_temp_active_flag = true; - return (IotTsensorHandle_t) 1; - } - } -} - -void iot_tsensor_set_callback(IotTsensorHandle_t const xTsensorHandle, - IotTsensorCallback_t xCallback, - void * pvUserContext) -{ - //Not support call back. -} - -int32_t iot_tsensor_enable(IotTsensorHandle_t const xTsensorHandle) -{ - if((xTsensorHandle == NULL) || (s_temp_active_flag == false)){ - return IOT_TSENSOR_INVALID_VALUE; - } - - s_temp_en_disable_flag = true; - - return IOT_TSENSOR_SUCCESS; -} - -int32_t iot_tsensor_disable(IotTsensorHandle_t const xTsensorHandle) -{ - if((xTsensorHandle == NULL) || (s_temp_active_flag == false)){ - return IOT_TSENSOR_INVALID_VALUE; - } - s_temp_en_disable_flag = false; - return IOT_TSENSOR_SUCCESS; -} - -int32_t iot_tsensor_get_temp(IotTsensorHandle_t const xTsensorHandle, - int32_t * lTemp) -{ - int32_t temperature = 0; - - if((xTsensorHandle == NULL) || (lTemp == NULL) || (s_temp_active_flag == false)){ - return IOT_TSENSOR_INVALID_VALUE; - } - - if(s_temp_en_disable_flag == false){ - return IOT_TSENSOR_DISABLED; - } - - if(BK_OK == temp_detect_get_temperature((uint32_t *)&temperature)){ - os_memcpy(lTemp,&temperature,sizeof(int32_t)); - return IOT_TSENSOR_SUCCESS; - } - else{ - return IOT_TSENSOR_GET_TEMP_FAILED; - } -} - -int32_t iot_tsensor_ioctl(IotTsensorHandle_t const xTsensorHandle, - IotTsensorIoctlRequest_t xRequest, - void * const pvBuffer) -{ - uint32_t temperature = 0; - - if((xTsensorHandle == NULL) || - ((xRequest != eTsensorPerformCalibration) && (pvBuffer == NULL))){ - return IOT_TSENSOR_INVALID_VALUE; - } - - if(s_temp_active_flag == false){ - return IOT_TSENSOR_CLOSED; - } - - switch (xRequest) - { - case eTsensorGetMinThreshold: - temperature = ADC_TEMP_VAL_MIN; - os_memcpy( pvBuffer, &temperature, sizeof(temperature)); - break; - case eTsensorGetMaxThreshold: - temperature = ADC_TEMP_VAL_MAX; - os_memcpy( pvBuffer, &temperature, sizeof(temperature)); - break; - case eTsensorSetMinThreshold: - case eTsensorSetMaxThreshold: - case eTsensorPerformCalibration: - return IOT_TSENSOR_NOT_SUPPORTED; - break; - default: - return IOT_TSENSOR_INVALID_VALUE; - } - - return IOT_TSENSOR_SUCCESS; -} - -int32_t iot_tsensor_close( IotTsensorHandle_t const xTsensorHandle) -{ - if((xTsensorHandle == NULL) || (s_temp_active_flag == false)){ - return IOT_TSENSOR_INVALID_VALUE; - } - iot_tsensor_disable(xTsensorHandle);//before close we need disable the sesor. - s_temp_active_flag = false; - - return IOT_TSENSOR_SUCCESS; -} \ No newline at end of file diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/common_io/iot_uart.c b/bk7235/liteos_m/bk_sdk_armino/middleware/compal/common_io/iot_uart.c deleted file mode 100755 index 2318a146ac9b91e5006def589b24a3ddf2ee82ab..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/common_io/iot_uart.c +++ /dev/null @@ -1,550 +0,0 @@ -#include "FreeRTOS.h" -#include "semphr.h" -#include "iot_uart.h" -#include "driver/uart.h" -#include "uart_driver.h" - -#include - - -#define UART_FIFO_LEN (128) /*!< The UART hardware FIFO length */ -#define SEM_WAIT_TIME (60000 / portTICK_RATE_MS) - - -typedef struct IotUARTDescriptor { - IotUARTConfig_t iot_uart_conf; - void (*func)(IotUARTOperationStatus_t arg1, void *arg2); - void *arg; - uint8_t *read_buf; - uint8_t *write_buf; - size_t bytes_to_read; - size_t bytes_to_write; - size_t async_bytes_written; - size_t async_bytes_read; - int32_t uart_port_num; - beken2_timer_t uart_timer_wr_hdl; - beken2_timer_t uart_timer_rd_hdl; - SemaphoreHandle_t uart_rd_cb_wait; - SemaphoreHandle_t uart_wr_cb_wait; - unsigned wr_op_in_progress: 1; - unsigned rd_op_in_progress: 1; - unsigned uart_rd_op_cancel_req: 1; - unsigned uart_wr_op_cancel_req: 1; -} IotUARTDescriptor_t; - -static volatile uint8_t uart_bit_mask/*, uart_is_installed_bit_mask*/; - -static void bk_uart_write_cb(void *param, unsigned int ulparam) -{ - bk_err_t ret = BK_OK; - UART_LOGI("%s\n", __FUNCTION__); - IotUARTDescriptor_t *uart_desc = (IotUARTDescriptor_t *) param; - uint8_t *write_buffer = uart_desc->write_buf; - uint8_t op_status = eUartWriteCompleted; - int actual_bytes_to_write = 0; - if (uart_desc->uart_wr_op_cancel_req) { - UART_LOGI("cancel operation recieved"); - op_status = eUartLastWriteFailed; - if (uart_desc->func) { - UART_LOGI("%s invoking callback %p\n", __FUNCTION__, uart_desc->func); - uart_desc->func(op_status, uart_desc->arg); - } - uart_desc->bytes_to_write = 0; - uart_desc->wr_op_in_progress = false; - uart_desc->uart_wr_op_cancel_req = false; - xSemaphoreGive(uart_desc->uart_wr_cb_wait); - return; - } - - UART_LOGI("%s bytes_to_write %d\n", __FUNCTION__, uart_desc->bytes_to_write); - if (uart_desc->bytes_to_write == 0) { - if (uart_desc->func) { - UART_LOGI("%s invoking callback %p\n", __FUNCTION__, uart_desc->func); - uart_desc->func(op_status, uart_desc->arg); - } - uart_desc->bytes_to_write = 0; - uart_desc->wr_op_in_progress = false; - xSemaphoreGive(uart_desc->uart_wr_cb_wait); - return; - } - - actual_bytes_to_write = uart_desc->bytes_to_write < UART_FIFO_LEN ? uart_desc->bytes_to_write : UART_FIFO_LEN; - ret = bk_uart_write_bytes(uart_desc->uart_port_num, write_buffer, actual_bytes_to_write); - if (BK_OK == ret) { - uart_desc->write_buf += actual_bytes_to_write; - uart_desc->bytes_to_write -= actual_bytes_to_write; - uart_desc->async_bytes_written += actual_bytes_to_write; - } else { - UART_LOGI("%s bk_uart_write_bytes faild: %d\n", __FUNCTION__, ret); - } - - - UART_LOGI("%s bytes_to_write %d\n", __FUNCTION__, uart_desc->bytes_to_write); - if (uart_desc->bytes_to_write == 0) { - if (uart_desc->func) { - UART_LOGI("%s invoking callback %p\n", __FUNCTION__, uart_desc->func); - uart_desc->func(op_status, uart_desc->arg); - } - uart_desc->bytes_to_write = 0; - uart_desc->wr_op_in_progress = false; - xSemaphoreGive(uart_desc->uart_wr_cb_wait); - return; - } -} - -static void bk_uart_read_cb(void *param, unsigned int ulparam) -{ - UART_LOGI("%s\n", __FUNCTION__); - IotUARTDescriptor_t *uart_desc = (IotUARTDescriptor_t *) param; - uint8_t op_status = eUartReadCompleted; - uint8_t *read_buffer = uart_desc->read_buf; - int read_bytes = 0; - int actual_bytes_to_read = UART_FIFO_LEN * 2; - - if (uart_desc->uart_rd_op_cancel_req) { - UART_LOGI("cancel operation recieved"); - op_status = eUartLastReadFailed; - if (uart_desc->func) { - UART_LOGI("%s invoking callback %p\n", __FUNCTION__, uart_desc->func); - uart_desc->func(op_status, uart_desc->arg); - } - uart_desc->bytes_to_read = 0; - uart_desc->rd_op_in_progress = false; - uart_desc->uart_rd_op_cancel_req = false; - xSemaphoreGive(uart_desc->uart_rd_cb_wait); - return; - } - - if (actual_bytes_to_read > uart_desc->bytes_to_read) { - actual_bytes_to_read = uart_desc->bytes_to_read; - } - - read_bytes = bk_uart_read_bytes(uart_desc->uart_port_num, read_buffer, actual_bytes_to_read, 0); - if (read_bytes > 0) { - uart_desc->read_buf += read_bytes; - uart_desc->bytes_to_read -= read_bytes; - uart_desc->async_bytes_read += read_bytes; - } else { - UART_LOGI("%s bk_uart_read_bytes err %d\n", __FUNCTION__, read_bytes); - } - - UART_LOGI("%s bytes_to_read %d\n", __FUNCTION__, uart_desc->bytes_to_read); - if (uart_desc->bytes_to_read <= 0) { - op_status = eUartReadCompleted; - if (uart_desc->func) { - UART_LOGI("%s invoking callback %p\n", __FUNCTION__, uart_desc->func); - uart_desc->func(op_status, uart_desc->arg); - } - uart_desc->bytes_to_read = 0; - uart_desc->rd_op_in_progress = false; - uart_desc->uart_rd_op_cancel_req = false; - xSemaphoreGive(uart_desc->uart_rd_cb_wait); - return; - } - -} - -static bk_err_t bk_restart_rx_timer(IotUARTDescriptor_t *uart_desc) -{ - bk_err_t ret = BK_OK; - ret = rtos_oneshot_reload_timer_ex(&uart_desc->uart_timer_rd_hdl, 2, - (timer_2handler_t)bk_uart_read_cb, - (void *) uart_desc, 0); - ret |= rtos_start_oneshot_timer(&uart_desc->uart_timer_rd_hdl); - - return ret; -} - -static bk_err_t bk_restart_tx_timer(IotUARTDescriptor_t *uart_desc) -{ - bk_err_t ret = BK_OK; - ret = rtos_oneshot_reload_timer_ex(&uart_desc->uart_timer_wr_hdl, 2, - (timer_2handler_t)bk_uart_write_cb, - (void *) uart_desc, 0); - ret |= rtos_start_oneshot_timer(&uart_desc->uart_timer_wr_hdl); - - return ret; -} - -void bk_uart_rx_isr(int uart_port_num, void *param) -{ - IotUARTDescriptor_t *uart_desc = (IotUARTDescriptor_t *) param; - BaseType_t xHigherPriorityTaskWoken = pdFALSE; - - if (bk_restart_rx_timer(uart_desc)!= BK_OK) { - UART_LOGE("%s: failed to create timer for read async\n", __FUNCTION__); - xSemaphoreGiveFromISR(uart_desc->uart_rd_cb_wait, &xHigherPriorityTaskWoken); - return; - } - -} - -void bk_uart_tx_isr(int uart_port_num, void *param) -{ - IotUARTDescriptor_t *uart_desc = (IotUARTDescriptor_t *) param; - BaseType_t xHigherPriorityTaskWoken = pdFALSE; - if (uart_desc->wr_op_in_progress) { - if (bk_restart_tx_timer(uart_desc)!= BK_OK) { - xSemaphoreGiveFromISR(uart_desc->uart_wr_cb_wait, &xHigherPriorityTaskWoken); - return; - } - } -} - -IotUARTHandle_t iot_uart_open(int32_t lUartInstance) -{ - bk_err_t ret = BK_OK; - IotUARTDescriptor_t *uart_desc = NULL; - UART_LOGI("%s lUartInstance %d\n", __FUNCTION__, lUartInstance); - - if (lUartInstance < 0 || lUartInstance >= UART_ID_MAX) { - UART_LOGE("Invalid param: lUartInstance(%d).\n", lUartInstance); - return NULL; - } - - if ((0x01 & uart_bit_mask >> lUartInstance)) { - UART_LOGI("Uart already open for the instance(%d)\n", lUartInstance); - return NULL; - } - - if (bk_uart_is_in_used(lUartInstance)) { - UART_LOGI("uart already in used for the instance(%d)\n", lUartInstance); - return NULL; - } - - do { - uart_desc = (IotUARTDescriptor_t *) os_malloc(sizeof(IotUARTDescriptor_t)); - if (uart_desc == NULL) { - UART_LOGI("Could not allocate memory for uart context\n"); - ret = BK_ERR_NO_MEM; - break; - } - - os_memset((void *)uart_desc, 0x0, sizeof(IotUARTDescriptor_t)); - - //Set default configuration - uart_desc->uart_port_num = lUartInstance; - - uart_config_t uart_config = { - .baud_rate = UART_BAUD_RATE, - .data_bits = UART_DATA_8_BITS, - .parity = UART_PARITY_NONE, - .stop_bits = UART_STOP_BITS_1, - .flow_ctrl = UART_FLOWCTRL_DISABLE, - .src_clk = UART_SCLK_XTAL_26M - }; - - ret = bk_uart_init(lUartInstance, &uart_config); - if (ret == BK_FAIL) { - UART_LOGE("Failed to init uart.\n"); - break; - } - - uart_desc->uart_rd_cb_wait = xSemaphoreCreateBinary(); - if (uart_desc->uart_rd_cb_wait == NULL) { - UART_LOGI("Failed to create read binary semaphore\n"); - ret = BK_FAIL; - break; - } - - uart_desc->uart_wr_cb_wait = xSemaphoreCreateBinary(); - if (uart_desc->uart_wr_cb_wait == NULL) { - UART_LOGI("Failed to create write binary semaphore\n"); - vSemaphoreDelete(uart_desc->uart_rd_cb_wait); - ret = BK_FAIL; - break; - } - - bk_uart_disable_sw_fifo(lUartInstance); - - //Create a callback function to handle UART event from ISR - ret = bk_uart_register_rx_isr(lUartInstance, (uart_isr_t)bk_uart_rx_isr, (void *)uart_desc); - ret = bk_uart_register_tx_isr(lUartInstance, (uart_isr_t)bk_uart_tx_isr, (void *)uart_desc); - - bk_uart_enable_rx_interrupt(lUartInstance); - - /* Ensure first semaphore take could succeed */ - xSemaphoreGive(uart_desc->uart_rd_cb_wait); - xSemaphoreGive(uart_desc->uart_wr_cb_wait); - - //Create timer for write async - ret = rtos_init_oneshot_timer(&uart_desc->uart_timer_wr_hdl, 2, - (timer_2handler_t)bk_uart_write_cb, - (void *) uart_desc, 0); - if (ret != BK_OK) { - UART_LOGE("Failed to create uart write timer %d\n", ret); - break; - } - - //Create timer for read async - ret = rtos_init_oneshot_timer(&uart_desc->uart_timer_rd_hdl, 2, - (timer_2handler_t)bk_uart_read_cb, - (void *) uart_desc, 0); - if (ret != BK_OK) { - UART_LOGE("Failed to create uart write timer %d\n", ret); - break; - } - - - } while(0); - - if (BK_OK != ret) - { - if (NULL != uart_desc) { - if (NULL != uart_desc->uart_rd_cb_wait) { - vSemaphoreDelete(uart_desc->uart_rd_cb_wait); - } - if (NULL != uart_desc->uart_wr_cb_wait) { - vSemaphoreDelete(uart_desc->uart_wr_cb_wait); - } - os_free(uart_desc); - } - return NULL; - } - - UART_LOGI("%s OK. %d\n", __FUNCTION__, lUartInstance); - uart_bit_mask = uart_bit_mask | BIT(lUartInstance); - return (IotUARTHandle_t) uart_desc; -} - -int32_t iot_uart_ioctl(IotUARTHandle_t const pxUartPeripheral, IotUARTIoctlRequest_t xUartRequest, void * const pvBuffer) -{ - bk_err_t ret; - IotUARTDescriptor_t *iot_uart_handler = (IotUARTDescriptor_t *) pxUartPeripheral; - - if (pxUartPeripheral == NULL || pvBuffer == NULL) { - UART_LOGI("Invalid arguments.\n"); - return IOT_UART_INVALID_VALUE; - } - - IotUARTDescriptor_t *uart_desc = (IotUARTDescriptor_t *) pxUartPeripheral; - if (xUartRequest == eGetTxNoOfbytes) { - size_t *tx_bytes_write = (size_t *)pvBuffer; - *tx_bytes_write = uart_desc->async_bytes_written; - return IOT_UART_SUCCESS; - } else if (xUartRequest == eGetRxNoOfbytes) { - size_t *rx_bytes_read = (size_t *)pvBuffer; - *rx_bytes_read = uart_desc->async_bytes_read; - return IOT_UART_SUCCESS; - } - - if (!iot_uart_handler->wr_op_in_progress && !iot_uart_handler->rd_op_in_progress) { - switch(xUartRequest) { - case eUartSetConfig : { - int32_t uart_port_num = uart_desc->uart_port_num; - IotUARTConfig_t *iot_uart_config = (IotUARTConfig_t *) pvBuffer; - os_memcpy(&uart_desc->iot_uart_conf, iot_uart_config, sizeof(IotUARTConfig_t)); - uart_config_t uart_config; - uart_config.baud_rate = iot_uart_config->ulBaudrate; - uart_config.data_bits = iot_uart_config->ucWordlength; - if (iot_uart_config->ucFlowControl == true) { - uart_config.flow_ctrl = UART_FLOWCTRL_CTS_RTS; - } - switch (iot_uart_config->xParity) { - case eUartParityNone: - uart_config.parity = UART_PARITY_NONE; - break; - case eUartParityOdd: - uart_config.parity = UART_PARITY_ODD; - break; - case eUartParityEven: - uart_config.parity = UART_PARITY_EVEN; - break; - default: - uart_config.parity = UART_PARITY_NONE; - } - switch (iot_uart_config->xStopbits) { - case eUartStopBitsOne: - uart_config.stop_bits = UART_STOP_BITS_1; - break; - case eUartStopBitsTwo: - uart_config.stop_bits = UART_STOP_BITS_2; - break; - default: - uart_config.stop_bits = UART_STOP_BITS_1; - } - if (iot_uart_config->ulBaudrate == 0) { - uart_config.baud_rate = IOT_UART_BAUD_RATE_DEFAULT; - } - bk_uart_deinit(uart_port_num); - ret = bk_uart_init(uart_port_num, &uart_config); - //Create a callback function to handle UART event from ISR - ret = bk_uart_register_rx_isr(uart_port_num, (uart_isr_t)bk_uart_rx_isr, (void *)uart_desc); - ret = bk_uart_register_tx_isr(uart_port_num, (uart_isr_t)bk_uart_tx_isr, (void *)uart_desc); - return (ret == BK_OK) ? IOT_UART_SUCCESS : IOT_UART_INVALID_VALUE; - } - case eUartGetConfig : { - IotUARTConfig_t *iot_uart_config = (IotUARTConfig_t *) pvBuffer; - os_memcpy(iot_uart_config, &uart_desc->iot_uart_conf, sizeof(IotUARTConfig_t)); - return IOT_UART_SUCCESS; - } - default : - return IOT_UART_INVALID_VALUE; - } - } else { - return IOT_UART_BUSY; - } -} - -void iot_uart_set_callback(IotUARTHandle_t const pxUartPeripheral, IotUARTCallback_t xCallback, void * pvUserContext) -{ - UART_LOGI("%s xCallback = %p\n", __FUNCTION__, xCallback); - if (pxUartPeripheral == NULL || xCallback == NULL) { - UART_LOGI("Invalid arguments\n"); - } - IotUARTDescriptor_t *uart_desc = (IotUARTDescriptor_t *) pxUartPeripheral; - - uart_desc->arg = pvUserContext; - uart_desc->func = (void *)xCallback; -} - -int32_t iot_uart_read_async(IotUARTHandle_t const pxUartPeripheral, uint8_t * const pvBuffer, size_t xBytes) -{ - UART_LOGI("%s: %p %p %d\n", __FUNCTION__, pxUartPeripheral, pvBuffer, xBytes); - - if (pxUartPeripheral == NULL || pvBuffer == NULL || xBytes == 0) { - UART_LOGE("Invalid arguments\n"); - return IOT_UART_INVALID_VALUE; - } - - IotUARTDescriptor_t *uart_desc = (IotUARTDescriptor_t *) pxUartPeripheral; - //Read from another task to make async - if (!xSemaphoreTake(uart_desc->uart_rd_cb_wait, SEM_WAIT_TIME)) { - UART_LOGE("%s: failed to acquire read sem\n", __FUNCTION__); - return IOT_UART_READ_FAILED; - } - - uart_desc->read_buf = pvBuffer; - uart_desc->bytes_to_read = xBytes; - uart_desc->async_bytes_read = 0; - - bk_restart_rx_timer(uart_desc); - uart_desc->rd_op_in_progress = true; - return IOT_UART_SUCCESS; -} - -int32_t iot_uart_write_async(IotUARTHandle_t const pxUartPeripheral, uint8_t * const pvBuffer, size_t xBytes) -{ - UART_LOGI("%s: %p %p %d\n", __FUNCTION__, pxUartPeripheral, pvBuffer, xBytes); - - if (pxUartPeripheral == NULL || pvBuffer == NULL || xBytes == 0) { - UART_LOGI("Invalid arguments\n"); - return IOT_UART_INVALID_VALUE; - } - - IotUARTDescriptor_t *uart_desc = (IotUARTDescriptor_t *) pxUartPeripheral; - if (!xSemaphoreTake(uart_desc->uart_wr_cb_wait, SEM_WAIT_TIME)) { - UART_LOGE("%s: failed to acquire write sem\n", __FUNCTION__); - return IOT_UART_WRITE_FAILED; - } - uart_desc->wr_op_in_progress = true; - uart_desc->write_buf = pvBuffer; - uart_desc->bytes_to_write = xBytes; - uart_desc->async_bytes_written = 0; - bk_restart_tx_timer(uart_desc); - return IOT_UART_SUCCESS; -} - -int32_t iot_uart_read_sync(IotUARTHandle_t const pxUartPeripheral, uint8_t * const pvBuffer, size_t xBytes) -{ - UART_LOGI("%s pxUartPeripheral = %p\n", __FUNCTION__, pxUartPeripheral); - if (pxUartPeripheral == NULL || pvBuffer == NULL || xBytes == 0) { - UART_LOGI("Invalid arguments\n"); - return IOT_UART_INVALID_VALUE; - } - uint8_t *src_buf = (uint8_t *) pvBuffer; - int32_t uart_port_num = ((IotUARTDescriptor_t *)pxUartPeripheral)->uart_port_num; - int bytes_read = bk_uart_read_bytes(uart_port_num, src_buf, xBytes, portMAX_DELAY); - return (bytes_read == xBytes) ? IOT_UART_SUCCESS : IOT_UART_READ_FAILED; -} - -int32_t iot_uart_write_sync(IotUARTHandle_t const pxUartPeripheral, uint8_t * const pvBuffer, size_t xBytes) -{ - UART_LOGI("%s pxUartPeripheral = %p\n", __FUNCTION__, pxUartPeripheral); - if (pxUartPeripheral == NULL || pvBuffer == NULL || xBytes == 0) { - UART_LOGI("Invalid arguments\n"); - return IOT_UART_INVALID_VALUE; - } - char *src_buf = (char *) pvBuffer; - IotUARTDescriptor_t *uart_desc = (IotUARTDescriptor_t *) pxUartPeripheral; - int32_t uart_port_num = uart_desc->uart_port_num; - bk_uart_write_bytes(uart_port_num, src_buf, xBytes); - return IOT_UART_SUCCESS; -} - -int32_t iot_uart_close(IotUARTHandle_t const pxUartPeripheral) -{ - bk_err_t ret = BK_OK; - UART_LOGI("%s pxUartPeripheral = %p\n", __FUNCTION__, pxUartPeripheral); - if (pxUartPeripheral == NULL) { - UART_LOGE("Invalid arguments\n"); - return IOT_UART_INVALID_VALUE; - } - IotUARTDescriptor_t *uart_desc = (IotUARTDescriptor_t *) pxUartPeripheral; - int32_t uart_port_num = uart_desc->uart_port_num; - if (0x01 & uart_bit_mask >> uart_port_num) { - if (uart_desc->rd_op_in_progress) { - uart_desc->uart_rd_op_cancel_req = true; - } - if (uart_desc->wr_op_in_progress) { - uart_desc->uart_wr_op_cancel_req = true; - } - - bk_uart_disable_rx_interrupt(uart_port_num); - bk_uart_disable_tx_interrupt(uart_port_num); - ret |= bk_uart_deinit(uart_port_num); - - rtos_stop_oneshot_timer(&uart_desc->uart_timer_wr_hdl); - rtos_stop_oneshot_timer(&uart_desc->uart_timer_rd_hdl); - rtos_deinit_oneshot_timer(&uart_desc->uart_timer_wr_hdl); - rtos_deinit_oneshot_timer(&uart_desc->uart_timer_rd_hdl); - if (uart_desc->uart_rd_cb_wait) { - vSemaphoreDelete(uart_desc->uart_rd_cb_wait); - } - if (uart_desc->uart_wr_cb_wait) { - vSemaphoreDelete(uart_desc->uart_wr_cb_wait); - } - uart_bit_mask = uart_bit_mask & ~(BIT(uart_port_num)); - os_free(uart_desc); - return (ret == BK_OK) ? IOT_UART_SUCCESS : IOT_UART_INVALID_VALUE; - } else { - return IOT_UART_INVALID_VALUE; - } -} - -int32_t iot_uart_cancel(IotUARTHandle_t const pxUartPeripheral) -{ - bk_err_t ret = BK_OK; - UART_LOGI("%s pxUartPeripheral = %p\n", __FUNCTION__, pxUartPeripheral); - if (pxUartPeripheral == NULL) { - UART_LOGI("Invalid arguments\n"); - return IOT_UART_INVALID_VALUE; - } - IotUARTDescriptor_t *uart_desc = (IotUARTDescriptor_t *) pxUartPeripheral; - - if (!uart_desc->rd_op_in_progress && !uart_desc->wr_op_in_progress) { - return IOT_UART_NOTHING_TO_CANCEL; - } else if (uart_desc->rd_op_in_progress) { - uart_desc->uart_rd_op_cancel_req = true; - UART_LOGI("operation cancel request: %d\n", uart_desc->uart_rd_op_cancel_req); - - /* Start a timer to trigger the cancel operation. */ - if (bk_restart_rx_timer(uart_desc)!= BK_OK) { - UART_LOGE("%s: failed to create timer for cancel request\n", __FUNCTION__); - return IOT_UART_INVALID_VALUE; - } - - /* Ensure no active operations on UART before flusing all data */ - if (!xSemaphoreTake(uart_desc->uart_rd_cb_wait, SEM_WAIT_TIME)) { - UART_LOGE("%s: failed to acquire read sem\n", __FUNCTION__); - uart_desc->uart_rd_op_cancel_req = false; - return IOT_UART_INVALID_VALUE; - } - xSemaphoreGive(uart_desc->uart_rd_cb_wait); - - return (ret == BK_OK) ? IOT_UART_SUCCESS : IOT_UART_INVALID_VALUE; - } else { - UART_LOGE("write cancel not supported\n"); - return IOT_UART_FUNCTION_NOT_SUPPORTED; - } -} diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/common_io/iot_watchdog.c b/bk7235/liteos_m/bk_sdk_armino/middleware/compal/common_io/iot_watchdog.c deleted file mode 100644 index 2c6c4bbf2bd39854e28fcbad5d502fc66eb2b13a..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/common_io/iot_watchdog.c +++ /dev/null @@ -1,200 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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 -#include -#include "driver/wdt.h" -#include "iot_watchdog.h" -#include "os/mem.h" -#include "components/system.h" -#include "os/os.h" - -typedef struct { - void (*func)(void *arg); - void *arg; - IotWatchdogStatus_t status; -} wdt_ctx_t; - -wdt_ctx_t wdt_ctx = {0}; - -static bool s_wdt_driver_init_flag; -static uint32_t s_wdt_bite_time = 5000; - -IotWatchdogHandle_t iot_watchdog_open( int32_t lWatchdogInstance ) -{ - if(lWatchdogInstance < 0){ - return NULL; - } - - if (true == s_wdt_driver_init_flag){ - return NULL;; - } - - if(false == bk_wdt_is_driver_inited()){ - bk_wdt_driver_init(); - } - - s_wdt_driver_init_flag = true; - - return (IotWatchdogHandle_t) 1; -} - -int32_t iot_watchdog_start( IotWatchdogHandle_t const pxWatchdogHandle ) -{ - if(pxWatchdogHandle == NULL) { - return IOT_WATCHDOG_INVALID_VALUE; - } - - if(0 == s_wdt_bite_time){ - return IOT_WATCHDOG_TIME_NOT_SET; - } - - //if the bite time less than the bark time - if((s_wdt_bite_time <= bk_wdt_get_feed_time()) || (bk_wdt_start(s_wdt_bite_time) != BK_OK)) { - return IOT_WATCHDOG_INVALID_VALUE; - } - - wdt_ctx.status = eWatchdogTimerRunning; - - return IOT_WATCHDOG_SUCCESS; -} - -int32_t iot_watchdog_stop( IotWatchdogHandle_t const pxWatchdogHandle ) -{ - if((pxWatchdogHandle == NULL) || (bk_wdt_stop() != BK_OK)){ - return IOT_WATCHDOG_INVALID_VALUE; - } - - s_wdt_bite_time = 0; - wdt_ctx.status = eWatchdogTimerStopped; - - return IOT_WATCHDOG_SUCCESS; -} - -int32_t iot_watchdog_restart( IotWatchdogHandle_t const pxWatchdogHandle ) -{ - if(pxWatchdogHandle == NULL) { - return IOT_WATCHDOG_INVALID_VALUE; - } - - if(0 == s_wdt_bite_time){ - return IOT_WATCHDOG_TIME_NOT_SET; - } - - if(BK_OK != bk_wdt_feed()){ - return IOT_WATCHDOG_INVALID_VALUE; - } - - return IOT_WATCHDOG_SUCCESS; -} - -void bk_wdt_cb() -{ - if (wdt_ctx.func) { - wdt_ctx.status = eWatchdogTimerBarkExpired; - (wdt_ctx.func)(wdt_ctx.arg); - wdt_ctx.func = NULL; - } -} - -void iot_watchdog_set_callback( IotWatchdogHandle_t const pxWatchdogHandle, - IotWatchdogCallback_t xCallback, - void * pvUserContext ) -{ - if((pxWatchdogHandle == NULL) || (xCallback == NULL)){ - return ; - } - wdt_ctx.func = xCallback; - wdt_ctx.arg = pvUserContext; -} - -int32_t iot_watchdog_ioctl( IotWatchdogHandle_t const pxWatchdogHandle, - IotWatchdogIoctlRequest_t xRequest, - void * const pvBuffer ) -{ - uint32_t feed_wdt = 0; - - if((pxWatchdogHandle == NULL) || (pvBuffer == NULL)){ - return IOT_WATCHDOG_INVALID_VALUE; - } - - switch(xRequest){ - case eSetWatchdogBiteTime: - - if ((*(uint32_t *) pvBuffer) <= bk_wdt_get_feed_time()){ - return IOT_WATCHDOG_INVALID_VALUE; - } - - s_wdt_bite_time = *(uint32_t *) pvBuffer; - - break; - case eGetWatchdogBiteTime: - - os_memcpy(pvBuffer,&s_wdt_bite_time,sizeof(s_wdt_bite_time)); - - break; - case eSetWatchdogBarkTime: - - if ((s_wdt_bite_time != 0) && (*(uint32_t *) pvBuffer) >= s_wdt_bite_time){ - return IOT_WATCHDOG_INVALID_VALUE; - } - - feed_wdt = (*(uint32_t *) pvBuffer); - bk_wdt_set_feed_time(feed_wdt); - - break; - case eGetWatchdogBarkTime: - - feed_wdt = bk_wdt_get_feed_time(); - os_memcpy(pvBuffer,&feed_wdt,sizeof(feed_wdt)); - - break; - case eGetWatchdogStatus: - - os_memcpy(pvBuffer,&(wdt_ctx.status) ,sizeof(wdt_ctx.status)); - - break; - case eSetWatchdogBiteBehaviour: - return IOT_WATCHDOG_FUNCTION_NOT_SUPPORTED; - default: - return IOT_WATCHDOG_INVALID_VALUE; - } - - return IOT_WATCHDOG_SUCCESS; -} - -int32_t iot_watchdog_close( IotWatchdogHandle_t const pxWatchdogHandle ) -{ - int32_t rtn = IOT_WATCHDOG_SUCCESS; - - if(pxWatchdogHandle == NULL){ - return IOT_WATCHDOG_INVALID_VALUE; - } - - if((false == bk_wdt_is_driver_inited()) && (true == s_wdt_driver_init_flag)){ - s_wdt_driver_init_flag = false; - s_wdt_bite_time = 0; - } - else if (false == s_wdt_driver_init_flag){ - rtn = IOT_WATCHDOG_INVALID_VALUE; - } - else{ - if(iot_watchdog_stop( pxWatchdogHandle) != IOT_WATCHDOG_SUCCESS){ - return IOT_WATCHDOG_INVALID_VALUE; - } - bk_wdt_driver_deinit(); - s_wdt_driver_init_flag = false; - } - - return rtn; -} diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/homekit/.gitignore b/bk7235/liteos_m/bk_sdk_armino/middleware/compal/homekit/.gitignore deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/homekit/func_convert.c b/bk7235/liteos_m/bk_sdk_armino/middleware/compal/homekit/func_convert.c deleted file mode 100644 index 0b5d97ae8c5c93f428069d41736816c62c154411..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/homekit/func_convert.c +++ /dev/null @@ -1,204 +0,0 @@ - - -/** - **************************************************************************************** - * - * @file fuc_convert.c - * - * @brief This file contains fuc_convert. - * @author zhengyaohan - * @date 2021-11-10 - * - **************************************************************************************** - */ -#include -#include "common/bk_include.h" - - - - - -/** - ************************************************************ - * @brief uint16_to_array. - * - * @param[in] - * @param[out] - * @return - ************************************************************* - */ -void uint16_to_array(UINT16 val, UINT8 * array) -{ - - *array = val; - array++; - *array = val >> 8; -} - - -/** - ************************************************************ - * @brief array_to_uint16. - * - * @param[in] - * @param[out] - * @return - ************************************************************* - */ -UINT16 array_to_uint16(UINT8 * array) -{ - UINT16 val; - - val = * (array + 1); - val <<= 8; - val += (*array); - return val; -} - - -/** - ************************************************************ - * @brief uint32_to_array. - * - * @param[in] - * @param[out] - * @return - ************************************************************* - */ -void uint32_to_array(UINT32 val, UINT8 * array) -{ - UINT8 idx; - - for (idx = 0; idx < 4; idx++) - { - *array = val; - array++; - val >>= 8; - } - -} - - -/** - ************************************************************ - * @brief array_to_uint32. - * - * @param[in] - * @param[out] - * @return - ************************************************************* - */ -UINT32 array_to_uint32(UINT8 * array) -{ - UINT32 val = 0, idx; - - for (idx = 0; idx < 4; idx++) - { - val <<= 8; - val += (* (array + 3 - idx)); - } - return val; -} - - - - - - -/** - ************************************************************ - * @brief char_to_int. - * - * @param[in] - * @param[out] - * @return - ************************************************************* - */ -UINT8 char_to_int(char val) -{ - UINT8 ret = 0; - - if ((val >= '0') && (val <= '9')) - ret = val - '0'; - else - if ((val >= 'a') && (val <= 'f')) - ret = val - 'a' + 10; - else - if ((val >= 'A') && (val <= 'F')) - ret = val - 'A' + 10; - return ret; -} - - -/** - ************************************************************ - * @brief str_to_hex. - * - * @param[in] - * @param[out] - * @return - ************************************************************* - */ -UINT32 str_to_hexnum(char * str) -{ - UINT32 len, idx, val; - - - len = strlen(str); - if (len > 8) - len = 8; - - val = 0; - - for (idx = 0; idx < len; idx++) - { - val *= 16; - val += (char_to_int(* (str + idx))); - } - - return val; -} - - -/** - ************************************************************ - * @brief str_to_hexarray. - * - * @param[in] - * @param[out] - * @return - ************************************************************* - */ -UINT32 str_to_hexarray(char * str, UINT8 * hex) -{ - UINT32 len, idx, ret = 0; - - - len = strlen(str); - - for (idx = 0; idx < len; ) - { - *hex = char_to_int(* (str + idx)); - *hex = (*hex) << 4; - idx++; - if (idx >= len) - break; - - *hex = (*hex) +char_to_int(* (str + idx)); - idx++; - - hex++; - ret++; - } - - return ret; -} - - - - - - - - - diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/homekit/func_convert.h b/bk7235/liteos_m/bk_sdk_armino/middleware/compal/homekit/func_convert.h deleted file mode 100644 index b49d53b434de480646904d37b2f508ca813a9130..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/homekit/func_convert.h +++ /dev/null @@ -1,29 +0,0 @@ -/** - **************************************************************************************** - * - * @file fuc_convert.h - * - * @brief This file contains fuc_convert. - * @author zhengyaohan - * @date 2021-11-10 - * - **************************************************************************************** - */ - -#ifndef _FUNC_CONVERT_H_ -#define _FUNC_CONVERT_H_ - - -void uint16_to_array(UINT16 val, UINT8 * array); -UINT16 array_to_uint16(UINT8 * array); -void uint32_to_array(UINT32 val, UINT8 * array); -UINT32 array_to_uint32(UINT8 * array); - - -UINT8 char_to_int(char val); -UINT32 str_to_hexnum(char * str); -UINT32 str_to_hexarray(char * str, UINT8 * hex); - -#endif // _FUNC_CONVERT_H_ -// eof - diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/homekit/key_value.c b/bk7235/liteos_m/bk_sdk_armino/middleware/compal/homekit/key_value.c deleted file mode 100644 index bac7236c2cad8bbf37fefcc7186e89507b750c6a..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/homekit/key_value.c +++ /dev/null @@ -1,827 +0,0 @@ - - -/** - **************************************************************************************** - * - * @file key_value.c - * - * @brief This file contains key_value. - * @author zhengyaohan - * @date 2021-10-29 - * - **************************************************************************************** - */ -#include "common/bk_include.h" -#if CONFIG_FLASH_ORIGIN_API -#include "bk_flash.h" -#else -#include "driver/flash.h" -#include -#endif - -#include "bk_drv_model.h" -#include -#include - - - - -#define SECTOR_SIZE 0x1000 -#define DOMAIN_SECTOR_SIZE 0x2000 -#define DOMAIN_OFFSET 0x0A - -#define KEY_OFFSET 0x400 -#define KEY_MIN_SIZE 0x20 - -#define AUTH_USED_KEY 0xAA -#define AUTH_KEY 0xAF - - - - -enum KEY_CMD -{ - KEY_CMD_NONE = 0, - KEY_CMD_RM, - KEY_CMD_RENEW, -}; - - -typedef struct -{ - UINT8 auth; - UINT8 domain; - UINT8 offset; -} DOMAIN_HEAD_T; - - -typedef struct -{ - UINT8 auth; - UINT8 key; - UINT8 in_offset; - UINT8 in_count; -} KEY_HEAD_T; - - -/** - ************************************************************ - * @brief erase_flash. - * - * @param[in] - * @param[out] - * @return - ************************************************************* - */ -UINT8 erase_flash(UINT32 addr) -{ -#if CONFIG_FLASH_ORIGIN_API - UINT32 status, protect_flag, protect_param; - DD_HANDLE flash_hdl; - - addr = (addr & (~0x0000fff)); - flash_hdl = ddev_open(DD_DEV_TYPE_FLASH, &status, 0); - ddev_control(flash_hdl, CMD_FLASH_GET_PROTECT, &protect_flag); - protect_param = FLASH_PROTECT_NONE; - ddev_control(flash_hdl, CMD_FLASH_SET_PROTECT, &protect_param); - ddev_control(flash_hdl, CMD_FLASH_ERASE_SECTOR, &addr); - ddev_control(flash_hdl, CMD_FLASH_SET_PROTECT, &protect_flag); -#else - addr = (addr & (~0x0000fff)); - flash_protect_type_t protect_type; - protect_type = bk_flash_get_protect_type(); - bk_flash_set_protect_type(FLASH_PROTECT_NONE); - bk_flash_erase_sector(addr); - bk_flash_set_protect_type(protect_type); -#endif - - return 1; -} - -/** - ************************************************************ - * @brief wirte_flash. - * - * @param[in] - * @param[out] - * @return - ************************************************************* - */ -UINT8 write_flash(UINT32 addr ,UINT8 *data,UINT32 len) -{ -#if CONFIG_FLASH_ORIGIN_API - UINT32 status, protect_flag, protect_param,len_max,addr_t; - DD_HANDLE flash_hdl; - - flash_hdl = ddev_open(DD_DEV_TYPE_FLASH, &status, 0); - ddev_control(flash_hdl, CMD_FLASH_GET_PROTECT, &protect_flag); - protect_param = FLASH_PROTECT_NONE; - ddev_control(flash_hdl, CMD_FLASH_SET_PROTECT, &protect_param); -#else - UINT32 len_max,addr_t; - flash_protect_type_t protect_type; - protect_type = bk_flash_get_protect_type(); - bk_flash_set_protect_type(FLASH_PROTECT_NONE); -#endif - - while(len>0) - { - if(len>0x1000) - { - len_max = 0x1000; - } - else - { - len_max=len; - } - if( (addr+len_max)>=((addr & (~0x0000fff))+0x1000) ) - { - addr_t = (addr & (~0x0000fff))+0x1000; -#if CONFIG_FLASH_ORIGIN_API - ddev_control(flash_hdl, CMD_FLASH_ERASE_SECTOR, &addr_t); -#else - bk_flash_erase_sector(addr_t); -#endif - } -#if CONFIG_FLASH_ORIGIN_API - ddev_write(flash_hdl, (char *) data, len_max, addr); -#else - bk_flash_write_bytes(addr, (const uint8_t *)data, len_max); -#endif - addr+=len_max; - len-=len_max; - } - -#if CONFIG_FLASH_ORIGIN_API - ddev_control(flash_hdl, CMD_FLASH_SET_PROTECT, &protect_flag); -#else - bk_flash_set_protect_type(protect_type); -#endif - - return 1; -} - -/** - ************************************************************ - * @brief read_flash. - * - * @param[in] - * @param[out] - * @return - ************************************************************* - */ -UINT8 read_flash(UINT32 addr ,UINT8 *data,UINT32 len) -{ -#if CONFIG_FLASH_ORIGIN_API - UINT32 status; - DD_HANDLE flash_hdl; - - flash_hdl = ddev_open(DD_DEV_TYPE_FLASH, &status, 0); - ddev_read(flash_hdl, (char *) data, len, addr); -#else - bk_flash_read_bytes(addr, (uint8_t *)data, len); -#endif - return 1; -} - - -/** - ************************************************************ - * @brief domain_collect. - * - * @param[in] - * @param[out] - * @return - ************************************************************* - */ -UINT8 domain_collect(UINT8 domain, UINT32 addr_domain) -{ - UINT8 * ptr, *data; -#if CONFIG_FLASH_ORIGIN_API - DD_HANDLE flash_hdl; - UINT32 status, idx, key_addr, key_count = 0, all_len = 0, len = 0, offset = 0, first = 1; - UINT32 res_len, protect_flag, protect_param; -#else - UINT32 idx, key_addr, key_count = 0, all_len = 0, len = 0, offset = 0, first = 1; - UINT32 res_len; -#endif - - ptr = ((UINT8 *) os_malloc(0x400)); - data = ((UINT8 *) os_malloc(0x1000)); - if ((ptr == NULL) || (data == NULL)) - { - os_printf("domain_collect os_malloc fail.\r\n"); - os_free(ptr); - os_free(data); - return 0; - } - os_memset(ptr, 0xff, 0x400); - os_memset(data, 0xff, 0x1000); - - -#if CONFIG_FLASH_ORIGIN_API - flash_hdl = ddev_open(DD_DEV_TYPE_FLASH, &status, 0); - ddev_read(flash_hdl, (char *) ptr, 0x400, addr_domain); -#else - bk_flash_read_bytes(addr_domain, (uint8_t *)ptr, 0x400); -#endif - - os_printf("domain_collect= %02X: \r\n", domain); - - for (idx = 0; idx < 256; idx++) - { - if ((ptr[idx * 4] &0XF0) == 0XA0) - { - if (ptr[idx * 4] == AUTH_KEY) - { - os_printf("key = %02X, len = %d; ", ptr[1 + idx * 4],ptr[3 + idx * 4]*KEY_MIN_SIZE); - if (idx > key_count) - { - os_memcpy(ptr + key_count * 4, ptr + idx * 4, 4); - } - key_count++; - } - } - else break; - } - os_printf("end.\r\n"); - - for (idx = 0; idx < key_count; idx++) - { - len = ptr[3 + idx * 4] *KEY_MIN_SIZE; - all_len += len; - if (all_len > (DOMAIN_SECTOR_SIZE - KEY_OFFSET - 32)) - { - os_printf("domain_collect fail.all_len = %d.\r\n", all_len); - os_free(ptr); - os_free(data); - return 0; - } - } - os_printf("domain = %u ,all_len = %d, in collect.\r\n", domain, all_len); - -#if CONFIG_FLASH_ORIGIN_API - ddev_control(flash_hdl, CMD_FLASH_GET_PROTECT, &protect_flag); - protect_param = FLASH_PROTECT_NONE; - ddev_control(flash_hdl, CMD_FLASH_SET_PROTECT, &protect_param); -#else - flash_protect_type_t protect_type; - protect_type = bk_flash_get_protect_type(); - bk_flash_set_protect_type(FLASH_PROTECT_NONE); -#endif - - - for (idx = 0; idx < key_count; idx++) - { - key_addr = addr_domain + KEY_OFFSET + ptr[2 + idx * 4] *KEY_MIN_SIZE; - len = ptr[3 + idx * 4] *KEY_MIN_SIZE; - if (((offset + len) >= (SECTOR_SIZE - KEY_OFFSET)) && first) - { - first = 0; - - res_len = offset + len - ((SECTOR_SIZE - KEY_OFFSET)); -#if CONFIG_FLASH_ORIGIN_API - ddev_read(flash_hdl, (char *) data + offset, (len - res_len), key_addr); - ddev_control(flash_hdl, CMD_FLASH_ERASE_SECTOR, &addr_domain); - ddev_write(flash_hdl, (char *) data, (SECTOR_SIZE - KEY_OFFSET), addr_domain + KEY_OFFSET); -#else - bk_flash_read_bytes(key_addr, (uint8_t *)data + offset, (len - res_len)); - bk_flash_erase_sector(addr_domain); - bk_flash_write_bytes(addr_domain + KEY_OFFSET, (const uint8_t *)data, (SECTOR_SIZE - KEY_OFFSET)); -#endif - - offset = 0; -#if CONFIG_FLASH_ORIGIN_API - ddev_read(flash_hdl, (char *) data + offset, (res_len), key_addr + res_len); -#else - bk_flash_read_bytes(key_addr + res_len, (uint8_t *)data + offset, res_len); -#endif - offset += res_len; - continue; - } - -#if CONFIG_FLASH_ORIGIN_API - ddev_read(flash_hdl, (char *) data + offset, len, key_addr); -#else - bk_flash_read_bytes(key_addr, (uint8_t *)data + offset, len); -#endif - offset += len; - if (idx == 0) - { - ptr[2 + idx * 4] = 0; - } - else - { - ptr[2 + idx * 4] = (ptr[(idx - 1) * 4 + 2] +ptr[(idx - 1) * 4 + 3]); - } - - } - - if (all_len < (SECTOR_SIZE - KEY_OFFSET)) - { -#if CONFIG_FLASH_ORIGIN_API - ddev_control(flash_hdl, CMD_FLASH_ERASE_SECTOR, &addr_domain); - ddev_write(flash_hdl, (char *) data, offset, addr_domain + KEY_OFFSET); -#else - bk_flash_erase_sector(addr_domain); - bk_flash_write_bytes(addr_domain + KEY_OFFSET, (const uint8_t *)data, offset); -#endif - } -#if CONFIG_FLASH_ORIGIN_API - ddev_write(flash_hdl, (char *) ptr, key_count * 4, addr_domain); -#else - bk_flash_write_bytes(addr_domain, (const uint8_t *)ptr, key_count * 4); -#endif - - addr_domain += SECTOR_SIZE; -#if CONFIG_FLASH_ORIGIN_API - ddev_control(flash_hdl, CMD_FLASH_ERASE_SECTOR, &addr_domain); -#else - bk_flash_erase_sector(addr_domain); -#endif - if (all_len > (DOMAIN_SECTOR_SIZE - (SECTOR_SIZE - KEY_OFFSET))) - { -#if CONFIG_FLASH_ORIGIN_API - ddev_write(flash_hdl, (char *) data, offset, addr_domain); -#else - bk_flash_write_bytes(addr_domain, (const uint8_t *)data, offset); -#endif - } - -#if CONFIG_FLASH_ORIGIN_API - ddev_control(flash_hdl, CMD_FLASH_SET_PROTECT, &protect_flag); -#else - bk_flash_set_protect_type(protect_type); -#endif - os_free(ptr); - os_free(data); - return 1; - -} - - - - -/** - ************************************************************ - * @brief get_domain_addr. - * - * @param[in] - * @param[out] - * @return - ************************************************************* - */ -UINT8 get_domain_addr(UINT32 addr_base, UINT8 domain, UINT8 need, UINT32 * addr) -{ - UINT8 * ptr, find = 0; -#if CONFIG_FLASH_ORIGIN_API - DD_HANDLE flash_hdl; - UINT32 status, idx, protect_flag, protect_param,tmp; -#else - UINT32 idx, tmp; -#endif - DOMAIN_HEAD_T domain_item; - - ptr = ((UINT8 *) os_malloc(0x400)); - addr_base = addr_base & (~0x0fff); - -#if CONFIG_FLASH_ORIGIN_API - flash_hdl = ddev_open(DD_DEV_TYPE_FLASH, &status, 0); - ddev_control(flash_hdl, CMD_FLASH_GET_PROTECT, &protect_flag); - protect_param = FLASH_PROTECT_NONE; - ddev_control(flash_hdl, CMD_FLASH_SET_PROTECT, &protect_param); - ddev_read(flash_hdl, (char *) ptr, 0x400, addr_base); -#else - flash_protect_type_t protect_type; - protect_type = bk_flash_get_protect_type(); - bk_flash_set_protect_type(FLASH_PROTECT_NONE); - bk_flash_read_bytes(addr_base, (uint8_t *)ptr, 0x400); -#endif - - if (os_memcmp(ptr, "beken", 5) != 0) - { -#if CONFIG_FLASH_ORIGIN_API - ddev_control(flash_hdl, CMD_FLASH_ERASE_SECTOR, (void *) &addr_base); - ddev_write(flash_hdl, "beken", 5, addr_base); -#else - bk_flash_erase_sector(addr_base); - bk_flash_write_bytes(addr_base, (const uint8_t *)"beken", 5); -#endif - os_memset(ptr + 10, 0xff, 10); - } - - for (idx = 0; idx < 256; idx++) - { - if (ptr[10 + idx * 3] == AUTH_KEY) - { - if (ptr[10 + 1 + idx * 3] == domain) - { - find = 1; - *addr = addr_base + SECTOR_SIZE + idx * DOMAIN_SECTOR_SIZE; - break; - } - } - else break; - } - - if (need && (find == 0)) - { - domain_item.auth = AUTH_KEY; - domain_item.domain = domain; - domain_item.offset = 0xff; - *addr = addr_base + SECTOR_SIZE + idx * DOMAIN_SECTOR_SIZE; -#if CONFIG_FLASH_ORIGIN_API - ddev_control(flash_hdl, CMD_FLASH_ERASE_SECTOR, addr); - tmp = *addr + SECTOR_SIZE; - ddev_control(flash_hdl, CMD_FLASH_ERASE_SECTOR, &tmp); - ddev_write(flash_hdl, (char *) &domain_item, 3, addr_base + 10 + idx * 3); -#else - bk_flash_erase_sector(*addr); - tmp = *addr + SECTOR_SIZE; - bk_flash_erase_sector(tmp); - bk_flash_write_bytes(addr_base + 10 + idx * 3, (const uint8_t *)&domain_item, 3); -#endif - find = 1; - } -#if CONFIG_FLASH_ORIGIN_API - ddev_control(flash_hdl, CMD_FLASH_SET_PROTECT, &protect_flag); -#else - bk_flash_set_protect_type(protect_type); -#endif - os_free(ptr); - return find; -} - - -/** - ************************************************************ - * @brief get_key_addr. - * - * @param[in] - * @param[out] - * @return - ************************************************************* - */ -UINT8 get_key_addr(UINT32 addr_base, UINT8 key, UINT8 erase_need, UINT32 size, UINT32 * addr) -{ - UINT8 * ptr, find = 0; -#if CONFIG_FLASH_ORIGIN_API - DD_HANDLE flash_hdl; - UINT32 status, idx, protect_flag, protect_param; -#else - UINT32 idx; -#endif - KEY_HEAD_T key_item; - - ptr = ((UINT8 *) os_malloc(0x400)); - addr_base = addr_base & (~0x0fff); -#if CONFIG_FLASH_ORIGIN_API - flash_hdl = ddev_open(DD_DEV_TYPE_FLASH, &status, 0); - ddev_control(flash_hdl, CMD_FLASH_GET_PROTECT, &protect_flag); - protect_param = FLASH_PROTECT_NONE; - ddev_control(flash_hdl, CMD_FLASH_SET_PROTECT, &protect_param); - ddev_read(flash_hdl, (char *) ptr, 0x400, addr_base); -#else - flash_protect_type_t protect_type; - protect_type = bk_flash_get_protect_type(); - bk_flash_set_protect_type(FLASH_PROTECT_NONE); - bk_flash_read_bytes(addr_base, (uint8_t *)ptr, 0x400); -#endif - - for (idx = 0; idx < 256; idx++) - { - if ((ptr[idx * 4] &0XF0) == 0XA0) - { - if ((ptr[idx * 4] == AUTH_KEY) && (ptr[1 + idx * 4] == key)) - { - find = 1; - *addr = addr_base + KEY_OFFSET + ptr[2 + idx * 4] *KEY_MIN_SIZE; - - if (erase_need > 0) - { - key_item.auth = AUTH_USED_KEY; -#if CONFIG_FLASH_ORIGIN_API - ddev_write(flash_hdl, (char *) &key_item.auth, 1, addr_base + idx * 4); -#else - bk_flash_write_bytes(addr_base + idx * 4, (const uint8_t *)&key_item.auth, 1); -#endif - } - if (erase_need <= KEY_CMD_RM) break; - } - } - else break; - } - - if ((erase_need > KEY_CMD_RM)) - { - key_item.auth = AUTH_KEY; - key_item.key = key; - if (idx > 0) - { - key_item.in_offset = (ptr[(idx - 1) * 4 + 2] +ptr[(idx - 1) * 4 + 3]); - } - else - { - key_item.in_offset = 0; - } - *addr = addr_base + KEY_OFFSET + key_item.in_offset * KEY_MIN_SIZE; - if ((KEY_OFFSET + key_item.in_offset * KEY_MIN_SIZE) > DOMAIN_SECTOR_SIZE) - { - os_printf("!!! key = %02X is full,please erase \r\n", key); - os_free(ptr); - return 0; - } - - key_item.in_count = (size + KEY_MIN_SIZE - 1) / KEY_MIN_SIZE; -#if CONFIG_FLASH_ORIGIN_API - ddev_write(flash_hdl, (char *) &key_item, 4, addr_base + idx * 4); -#else - bk_flash_write_bytes(addr_base + idx * 4, (const uint8_t *)&key_item, 4); -#endif - find = 1; - } -#if CONFIG_FLASH_ORIGIN_API - ddev_control(flash_hdl, CMD_FLASH_SET_PROTECT, &protect_flag); -#else - bk_flash_set_protect_type(protect_type); -#endif - os_free(ptr); - return find; -} - - - -/** - ************************************************************ - * @brief rm_domain_key. - * - * @param[in] - * @param[out] - * @return - ************************************************************* - */ -UINT8 rm_domain_key(UINT32 addr_base, UINT8 domain, UINT8 key) -{ - UINT32 addr_domain, addr_key; - - os_printf("rm key %02X.%02X . \r\n", domain, key); - - if (get_domain_addr(addr_base, domain, 0, &addr_domain)) - { - get_key_addr(addr_domain, key, KEY_CMD_RM, 0, &addr_key); - } - return 1; -} - - -/** - ************************************************************ - * @brief rm_domain. - * - * @param[in] - * @param[out] - * @return - ************************************************************* - */ -UINT8 rm_domain(UINT32 addr_base, UINT8 domain) -{ -#if CONFIG_FLASH_ORIGIN_API - DD_HANDLE flash_hdl; - UINT32 status, protect_flag, addr_domain, protect_param, idx; -#else - UINT32 addr_domain, idx; -#endif - - os_printf("rm domain %02X. \r\n", domain); - -#if CONFIG_FLASH_ORIGIN_API - flash_hdl = ddev_open(DD_DEV_TYPE_FLASH, &status, 0); -#endif - - if (get_domain_addr(addr_base, domain, 0, &addr_domain)) - { - os_printf("addr_domain= %08X: \r\n", addr_domain); -#if CONFIG_FLASH_ORIGIN_API - ddev_control(flash_hdl, CMD_FLASH_GET_PROTECT, &protect_flag); - protect_param = FLASH_PROTECT_NONE; - ddev_control(flash_hdl, CMD_FLASH_SET_PROTECT, &protect_param); -#else - flash_protect_type_t protect_type; - protect_type = bk_flash_get_protect_type(); - bk_flash_set_protect_type(FLASH_PROTECT_NONE); -#endif - for (idx = 0; idx < (DOMAIN_SECTOR_SIZE / SECTOR_SIZE); idx++) - { -#if CONFIG_FLASH_ORIGIN_API - ddev_control(flash_hdl, CMD_FLASH_ERASE_SECTOR, &addr_domain); - addr_domain += SECTOR_SIZE; - ddev_control(flash_hdl, CMD_FLASH_ERASE_SECTOR, &addr_domain); -#else - bk_flash_erase_sector(addr_domain); - addr_domain += SECTOR_SIZE; - bk_flash_erase_sector(addr_domain); -#endif - } -#if CONFIG_FLASH_ORIGIN_API - ddev_control(flash_hdl, CMD_FLASH_SET_PROTECT, &protect_flag); -#else - bk_flash_set_protect_type(protect_type); -#endif - } - return 1; -} - - - -/** - ************************************************************ - * @brief get_domain_key_value. - * - * @param[in] - * @param[out] - * @return - ************************************************************* - */ -UINT8 get_domain_key_value(UINT32 addr_base, UINT8 domain, UINT8 key, UINT8 * buf, UINT32 size, UINT32 * ret_size) -{ -#if CONFIG_FLASH_ORIGIN_API - DD_HANDLE flash_hdl; - UINT32 addr_domain, status, addr_key, len = 0; -#else - UINT32 addr_domain, addr_key, len = 0; -#endif - - - - os_printf("get key %02X.%02X . \r\n", domain, key); - -#if CONFIG_FLASH_ORIGIN_API - flash_hdl = ddev_open(DD_DEV_TYPE_FLASH, &status, 0); -#endif - - if (get_domain_addr(addr_base, domain, 0, &addr_domain)) - { - if (get_key_addr(addr_domain, key, KEY_CMD_NONE, 0, &addr_key)) - { -#if CONFIG_FLASH_ORIGIN_API - ddev_read(flash_hdl, (char *) &len, 2, addr_key); -#else - bk_flash_read_bytes(addr_key, (uint8_t *)&len, 2); -#endif - os_printf("key %02X.%02X addr = %08X,len=%d. \r\n", domain, key, addr_key, len); - if (len > size) len = size; - if (ret_size) - { - *ret_size = len; - } -#if CONFIG_FLASH_ORIGIN_API - if (buf) ddev_read(flash_hdl, (char *) buf, len, addr_key + 2); -#else - if (buf) bk_flash_read_bytes(addr_key + 2, (uint8_t *)buf, len); -#endif - return 1; - } - } - return 0; -} - - -/** - ************************************************************ - * @brief set_domain_key_value. - * - * @param[in] - * @param[out] - * @return - ************************************************************* - */ -UINT8 set_domain_key_value(UINT32 addr_base, UINT8 domain, UINT8 key, UINT8 * buf, UINT32 size) -{ - -#if CONFIG_FLASH_ORIGIN_API - DD_HANDLE flash_hdl; - UINT32 status, protect_flag, protect_param, addr_domain, addr_key; -#else - UINT32 addr_domain, addr_key; -#endif - -#if CONFIG_FLASH_ORIGIN_API - flash_hdl = ddev_open(DD_DEV_TYPE_FLASH, &status, 0); -#endif - - os_printf("set key %02X.%02X . \r\n", domain, key); - - if (get_domain_addr(addr_base, domain, 1, &addr_domain)) - { - if (get_key_addr(addr_domain, key, KEY_CMD_RENEW, size + 2, &addr_key)) - { - os_printf("key %02X.%02X addr = %08X \r\n", domain, key, addr_key); -#if CONFIG_FLASH_ORIGIN_API - ddev_control(flash_hdl, CMD_FLASH_GET_PROTECT, &protect_flag); - protect_param = FLASH_PROTECT_NONE; - ddev_control(flash_hdl, CMD_FLASH_SET_PROTECT, &protect_param); - ddev_write(flash_hdl, (char *) &size, 2, addr_key); - ddev_write(flash_hdl, (char *) buf, size, addr_key + 2); - ddev_control(flash_hdl, CMD_FLASH_SET_PROTECT, &protect_flag); -#else - flash_protect_type_t protect_type; - protect_type = bk_flash_get_protect_type(); - bk_flash_set_protect_type(FLASH_PROTECT_NONE); - bk_flash_write_bytes(addr_key, (uint8_t *)&size, 2); - bk_flash_write_bytes(addr_key + 2, (uint8_t *)buf, size); - bk_flash_set_protect_type(protect_type); -#endif - return 1; - } - else - { - os_printf("!!! domain = %02X is full,domain_collect\r\n", domain); - if (domain_collect(domain, addr_domain)) - { - if (get_key_addr(addr_domain, key, KEY_CMD_RENEW, size + 2, &addr_key)) - { - os_printf("key %02X.%02X addr = %08X \r\n", domain, key, addr_key); -#if CONFIG_FLASH_ORIGIN_API - ddev_control(flash_hdl, CMD_FLASH_GET_PROTECT, &protect_flag); - protect_param = FLASH_PROTECT_NONE; - ddev_control(flash_hdl, CMD_FLASH_SET_PROTECT, &protect_param); - ddev_write(flash_hdl, (char *) &size, 2, addr_key); - ddev_write(flash_hdl, (char *) buf, size, addr_key + 2); - ddev_control(flash_hdl, CMD_FLASH_SET_PROTECT, &protect_flag); -#else - flash_protect_type_t protect_type; - protect_type = bk_flash_get_protect_type(); - bk_flash_set_protect_type(FLASH_PROTECT_NONE); - bk_flash_write_bytes(addr_key, (uint8_t *)&size, 2); - bk_flash_write_bytes(addr_key + 2, (uint8_t *)buf, size); - bk_flash_set_protect_type(protect_type); -#endif - return 1; - } - else - { - os_printf("!!! domain = %02X is full,please erase \r\n", domain); - return 0; - } - } - - } - } - return 0; -} - - -/** - ************************************************************ - * @brief search_domain_key. - * - * @param[in] - * @param[out] - * @return - ************************************************************* - */ -UINT32 search_domain_key(UINT32 addr_base, UINT8 domain, UINT8 * key) -{ - UINT8 * ptr; -#if CONFIG_FLASH_ORIGIN_API - DD_HANDLE flash_hdl; - UINT32 status, idx, addr_domain, key_count = 0; -#else - UINT32 idx, addr_domain, key_count = 0; -#endif - - ptr = ((UINT8 *) os_malloc(0x400)); - - if (get_domain_addr(addr_base, domain, 1, &addr_domain)) - { - os_printf("addr_domain= %08X: \r\n", addr_domain); -#if CONFIG_FLASH_ORIGIN_API - flash_hdl = ddev_open(DD_DEV_TYPE_FLASH, &status, 0); - ddev_read(flash_hdl, (char *) ptr, 0x400, addr_domain); -#else - bk_flash_read_bytes(addr_domain, (uint8_t *)ptr, 0x400); -#endif - os_printf("search_domain %02X: \r\n", domain); - - for (idx = 0; idx < 256; idx++) - { - if ((ptr[idx * 4] &0XF0) == 0XA0) - { - if (ptr[idx * 4] == AUTH_KEY) - { - os_printf(" %02X, ", ptr[1 + idx * 4]); - key[key_count++] = ptr[1 + idx * 4]; - if (key_count >= 255) break; - } - } - else break; - } - os_printf(" end.\r\n"); - } - os_free(ptr); - return key_count; -} - - - - diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/homekit/key_value.h b/bk7235/liteos_m/bk_sdk_armino/middleware/compal/homekit/key_value.h deleted file mode 100644 index 927df978b9512bc090415ae33a3a483079edda62..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/homekit/key_value.h +++ /dev/null @@ -1,43 +0,0 @@ -/** - **************************************************************************************** - * - * @file key_value.h - * - * @brief This file contains key_value. - * @author zhengyaohan - * @date 2021-10-29 - * - **************************************************************************************** - */ - -#ifndef _KEY_VALUE_H_ -#define _KEY_VALUE_H_ -#include - -#if (CONFIG_SOC_BK7256XX) -#define KV_BASE_ADDR 0x03DA000 -#else -#define KV_BASE_ADDR 0x0180000 -#endif - -UINT8 erase_flash(UINT32 addr); -UINT8 write_flash(UINT32 addr ,UINT8 *data,UINT32 len); -UINT8 read_flash(UINT32 addr ,UINT8 *data,UINT32 len); - - - - -UINT8 domain_collect(UINT8 domain, UINT32 addr_domain); - -UINT8 rm_domain(UINT32 addr_base, UINT8 domain); -UINT8 rm_domain_key(UINT32 addr_base, UINT8 domain, UINT8 key); - - -UINT8 get_domain_key_value(UINT32 addr_base, UINT8 domain, UINT8 key, UINT8 * buf, UINT32 size,UINT32 *ret_size); -UINT8 set_domain_key_value(UINT32 addr_base, UINT8 domain, UINT8 key, UINT8 * buf, UINT32 size); -UINT32 search_domain_key(UINT32 addr_base, UINT8 domain, UINT8 * key); - - -#endif // _KEY_VALUE_H_ -// eof - diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/matter/flash_namespace_value.c b/bk7235/liteos_m/bk_sdk_armino/middleware/compal/matter/flash_namespace_value.c deleted file mode 100755 index 28d19c65f694b9c520dcdd4274c94cf88b947b6f..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/matter/flash_namespace_value.c +++ /dev/null @@ -1,1601 +0,0 @@ -#include -#include - -#include "common/bk_include.h" -#include "common/bk_err.h" -#include -#include -#if CONFIG_FLASH_ORIGIN_API -#include "bk_flash.h" -#else -#include "driver/flash.h" -#include -#endif -#include "bk_drv_model.h" - -//#include "wpa_supplicant_i.h" - -#include "flash_namespace_value.h" - - -/************************************************************************* -************************************************************************* - Matter flash map - ---|-----------------------------START----------------------------------------| - | | | - 4KB | --------------flash_option_arr header[FLASH_NAME_SPACE_MAX_ARRAY]----------| //sizeof(namesapce_data_arr) - | | | --- - | - | | | -80KB| --------------flash_option_arr data[FLASH_NAME_SPACE_MAX_ARRAY]------------| //Depends on the actual amount of data ---- | 4KB * FLASH_NAME_SPACE_MAX_ARRAY | ---- |--- ----------------------------------------------------------------------| - ---- |----------------------------DATA START ------ -------------------------| -80KB|--------------------4KB * FLASH_NAME_SPACE_MAX_ARRAY----------------------| ---- |------------------------------DATA END------------------------------------| - ---- |------------------------------END-----------------------------------------| -************************************************************************** -*************************************************************************/ - - -/********************************************************************* - * Funtion Name:get_matter_flash_base_addr - * - * Funtion Discription:Get Flash data into global variables - * - * - * - * - * Date:2021-12-22 - *******************************************************************/ -uint32_t bk_strnlen (const char *ucdata,uint32_t dwLenMax) -{ - uint32_t dwDataLen = 0; - - dwDataLen = strlen(ucdata); - - return (dwDataLen >= dwLenMax ? dwLenMax : dwDataLen ); -} - -/************************************************************************* -*************************************************************************/ -/********************************************************************* - * Funtion Name:get_matter_flash_base_addr - * - * Funtion Discription:Get Flash data into global variables - * - * - * - * - * Date:2021-12-22 - *******************************************************************/ -uint32_t get_matter_flash_base_addr (uint32_t *base_addr) -{ - bk_logic_partition_t *partition_info = NULL; - - BK_CHECK_POINTER_NULL(base_addr); -#if CONFIG_FLASH_ORIGIN_API - partition_info = bk_flash_get_info(BK_PARTITION_MATTER_FLASH); -#else - partition_info = bk_flash_partition_get_info(BK_PARTITION_MATTER_FLASH); -#endif - BK_CHECK_POINTER_NULL(partition_info); - - *base_addr = partition_info->partition_start_addr; - - return kNoErr; -} - -/********************************************************************* - * Funtion Name:get_namespace_addr - * - * Funtion Discription:Get Flash data into global variables - * - * - * - * - * Date:2021-12-22 - *******************************************************************/ -uint32_t get_namespace_addr ( const char * ucnamespace,uint32_t np_base_addr,uint32_t *addr,uint32_t *block) //base_addr 要用上 -{ -#if CONFIG_FLASH_ORIGIN_API - DD_HANDLE flash_hdl = 0; - uint32_t status = 0,protect_param = 0,protect_flag = 0; -#endif - uint32_t dw_start_addr = 0 ; - namespace_flash_t *namespace_data_arr = NULL; - uint32_t dw_loop = 0 ; - uint32_t dw_rtn = 0 ; - - BK_CHECK_POINTER_NULL(ucnamespace); - BK_CHECK_POINTER_NULL(addr); - BK_CHECK_POINTER_NULL(block); - - namespace_data_arr = (namespace_flash_t *)os_malloc(NAME_SPACE_FLASH_ACTUAL_USE_SIZE); - if(NULL == namespace_data_arr) - { - bk_printf("[%s] [%d] os_malloc failed \r\n", __FUNCTION__,__LINE__); - return kGeneralErr; - } - bk_flash_debug_printf("ptr = 0x%x size=%d \r\n",namespace_data_arr,NAME_SPACE_FLASH_ACTUAL_USE_SIZE); - memset((char *)namespace_data_arr,0,NAME_SPACE_FLASH_ACTUAL_USE_SIZE); - - dw_start_addr = np_base_addr; - -#if CONFIG_FLASH_ORIGIN_API - flash_hdl = ddev_open(DD_DEV_TYPE_FLASH, (UINT32 *)&status, 0); - ddev_control(flash_hdl, CMD_FLASH_GET_PROTECT, &protect_flag); - protect_param = FLASH_PROTECT_NONE; - ddev_control(flash_hdl, CMD_FLASH_SET_PROTECT, &protect_param); - ddev_read(flash_hdl,(char *) namespace_data_arr, NAME_SPACE_FLASH_ACTUAL_USE_SIZE, dw_start_addr); - ddev_control(flash_hdl, CMD_FLASH_SET_PROTECT, &protect_flag); -#else - flash_protect_type_t protect_type; - protect_type = bk_flash_get_protect_type(); - bk_flash_set_protect_type(FLASH_PROTECT_NONE); - bk_flash_read_bytes(dw_start_addr, (uint8_t *) namespace_data_arr, NAME_SPACE_FLASH_ACTUAL_USE_SIZE); - bk_flash_set_protect_type(protect_type); -#endif - - for(dw_loop = 0;dw_loop < FLASH_NAME_SPACE_MAX_ARRAY;dw_loop++) - { - if(namespace_data_arr[dw_loop].dwUsingFlag != FLASH_SPACE_USING) - { - continue; - } - - if(0 == memcmp(namespace_data_arr[dw_loop].ucNamespace,ucnamespace,bk_strnlen(ucnamespace,sizeof(namespace_data_arr[dw_loop].ucNamespace) - 1))) - { - if(strlen(namespace_data_arr[dw_loop].ucNamespace) != strlen(ucnamespace))//针对前面的几个字符相同,后面不相同的情况 - { - continue; - } - //*addr = dw_loop * NAME_FLASH_TOTAL_SIZE + NAME_SPACE_FLASH_TOTAL_SIZE; - *addr = namespace_data_arr[dw_loop].dwOffsetByByte; - *block = dw_loop;//namespace 所在的空间偏移 - dw_rtn = kNoErr; - break; - } - } - - if(dw_loop == FLASH_NAME_SPACE_MAX_ARRAY) - { - dw_rtn = kGeneralErr; - } - - os_free(namespace_data_arr); - namespace_data_arr = NULL; - - return dw_rtn; -} - -/********************************************************************* - * Funtion Name:get_name_addr - * - * Funtion Discription:Get Flash data into global variables - * - * - * - * - * Date:2021-12-22 - *******************************************************************/ -uint32_t get_name_addr ( const char * ucname,uint32_t base_addr,uint32_t *offset_addr ,uint32_t *data_offset_addr) -{ -#if CONFIG_FLASH_ORIGIN_API - DD_HANDLE flash_hdl = 0; - uint32_t status = 0,protect_param = 0,protect_flag = 0; -#endif - uint32_t dw_loop = 0 ; - name_flash_t *name_data_arr = NULL; - uint32_t dw_rtn = 0 ; - - BK_CHECK_POINTER_NULL(ucname); - BK_CHECK_POINTER_NULL(offset_addr); - BK_CHECK_POINTER_NULL(data_offset_addr); - - name_data_arr = (name_flash_t *)os_malloc(NAME_FLASH_TOTAL_SIZE); - if(NULL == name_data_arr) - { - bk_printf("[%s] [%d] os_malloc failed \r\n", __FUNCTION__,__LINE__); - return kGeneralErr; - } - bk_flash_debug_printf("ptr = 0x%x size=%d addr =0x%x \r\n",name_data_arr,NAME_FLASH_TOTAL_SIZE,base_addr); - memset((char *)name_data_arr,0,NAME_FLASH_TOTAL_SIZE); - -#if CONFIG_FLASH_ORIGIN_API - flash_hdl = ddev_open(DD_DEV_TYPE_FLASH, (UINT32 *)&status, 0); - ddev_control(flash_hdl, CMD_FLASH_GET_PROTECT, &protect_flag); - protect_param = FLASH_PROTECT_NONE; - ddev_control(flash_hdl, CMD_FLASH_SET_PROTECT, &protect_param); - ddev_read(flash_hdl,(char *) name_data_arr, NAME_FLASH_TOTAL_SIZE, base_addr); - ddev_control(flash_hdl, CMD_FLASH_SET_PROTECT, &protect_flag); -#else - flash_protect_type_t protect_type; - protect_type = bk_flash_get_protect_type(); - bk_flash_set_protect_type(FLASH_PROTECT_NONE); - bk_flash_read_bytes(base_addr, (uint8_t *) name_data_arr, NAME_FLASH_TOTAL_SIZE); - bk_flash_set_protect_type(protect_type); -#endif - - bk_flash_debug_printf("[%s] [%d] data_offset_addr %u %u \r\n", __FUNCTION__,__LINE__,base_addr,NAME_FLASH_TOTAL_SIZE); - - for(dw_loop = 0;dw_loop < FLASH_NAME_MAX_ARRAY;dw_loop++) - { - if(name_data_arr[dw_loop].dwUsingFlag != FLASH_SPACE_USING)//如果不是正在使用的,直接跳到下一次循环 - { - continue; - } - else //name_flash_arr[dw_loop].dwUsingFlag == FLASH_SPACE_USING //如果此时是正在用的 - { - // *data_offset_addr = name_flash_arr[dw_loop].dwOffsetByByte + name_flash_arr[dw_loop].dwlength; - *data_offset_addr = name_data_arr[dw_loop].dwOffsetByByte; - bk_flash_debug_printf("[%s] [%d] data_offset_addr %u %u \r\n", __FUNCTION__,__LINE__,dw_loop,*data_offset_addr); - } - - bk_flash_debug_printf("[%s] [%d] data_offset_addr %u %x %u \r\n", __FUNCTION__,__LINE__,dw_loop,name_data_arr[dw_loop].dwUsingFlag,name_data_arr[dw_loop].dwOffsetByByte); - bk_flash_debug_printf("[%s] [%d] data_offset_addr %s %u \r\n", __FUNCTION__,__LINE__,name_data_arr[dw_loop].ucName,name_data_arr[dw_loop].dwlength); - - if(0 == memcmp(name_data_arr[dw_loop].ucName,ucname,bk_strnlen(ucname,sizeof(name_data_arr[dw_loop].ucName) - 1))) - { - if(strlen(name_data_arr[dw_loop].ucName) != strlen(ucname))//针对前面的几个字符相同,后面不相同的情况 - { - continue; - } - *offset_addr = dw_loop * PER_NAME_FLASH_SIZE; - //*addr = name_flash_arr[dw_loop].dwOffsetByByte; - dw_rtn = kNoErr; - break; - } - } - - if(dw_loop == FLASH_NAME_MAX_ARRAY) - { - dw_rtn = kGeneralErr; - } - - os_free(name_data_arr); - name_data_arr = NULL; - - return dw_rtn; -} - -/********************************************************************* - * Funtion Name:bk_erase_name_data - * - * Funtion Discription:Get Flash data into global variables - * base_addr --二级目录的地址 - * - * - * - * Date:2021-12-22 - *******************************************************************/ -uint32_t bk_erase_name_data( uint32_t n_base_addr,uint32_t data_sector_addr)//清除二级目录的数据 -{ -#if CONFIG_FLASH_ORIGIN_API - DD_HANDLE flash_hdl = 0; - uint32_t status = 0,protect_param = 0,protect_flag = 0; - - flash_hdl = ddev_open(DD_DEV_TYPE_FLASH, (UINT32 *)&status, 0); - ddev_control(flash_hdl, CMD_FLASH_GET_PROTECT, &protect_flag); - protect_param = FLASH_PROTECT_NONE; - ddev_control(flash_hdl, CMD_FLASH_SET_PROTECT, &protect_param); - ddev_control(flash_hdl, CMD_FLASH_ERASE_SECTOR, &n_base_addr);//将这块二级目录的数据erase掉 - ddev_control(flash_hdl, CMD_FLASH_ERASE_SECTOR, &data_sector_addr);//将二级目录对应的数据区erase掉 - - ddev_control(flash_hdl, CMD_FLASH_SET_PROTECT, &protect_flag); -#else - flash_protect_type_t protect_type; - protect_type = bk_flash_get_protect_type(); - bk_flash_set_protect_type(FLASH_PROTECT_NONE); - bk_flash_erase_sector(n_base_addr); - bk_flash_erase_sector(data_sector_addr); - bk_flash_set_protect_type(protect_type); -#endif - - return kNoErr; -} - -/********************************************************************* - * Funtion Name:bk_reorganize_name_data - * - * Funtion Discription:Get Flash data into global variables - * base_addr --二级目录的地址 - * - * - * - * Date:2021-12-22 - *******************************************************************/ -uint32_t bk_reorganize_name_data( uint32_t n_base_addr,name_flash_t *name_temp ,char *databuf,uint32_t data_sector_addr, - char *indata,uint32_t dw_data_len,name_flash_t name_data)//清除二级目录的数据 -{ -#if CONFIG_FLASH_ORIGIN_API - DD_HANDLE flash_hdl = 0; - uint32_t status = 0,protect_param = 0,protect_flag = 0; -#endif - uint32_t dw_loop = 0 ; - uint32_t dw_data_addr = data_sector_addr; - uint32_t dw_name_addr = n_base_addr; - uint32_t dw_offset = 0;//计数 - uint32_t dw_rtn = kNoErr; - //name_flash_t name_temp_2 = {0}; - - BK_CHECK_POINTER_NULL(name_temp); - BK_CHECK_POINTER_NULL(databuf); - BK_CHECK_POINTER_NULL(indata); - -#if CONFIG_FLASH_ORIGIN_API - flash_hdl = ddev_open(DD_DEV_TYPE_FLASH, (UINT32 *)&status, 0); - ddev_control(flash_hdl, CMD_FLASH_GET_PROTECT, &protect_flag); - protect_param = FLASH_PROTECT_NONE; - ddev_control(flash_hdl, CMD_FLASH_SET_PROTECT, &protect_param); - ddev_control(flash_hdl, CMD_FLASH_ERASE_SECTOR, &n_base_addr);//将这块二级目录的数据erase掉 - ddev_control(flash_hdl, CMD_FLASH_ERASE_SECTOR, &data_sector_addr);//将二级目录对应的数据区erase掉 - #else - flash_protect_type_t protect_type; - protect_type = bk_flash_get_protect_type(); - bk_flash_set_protect_type(FLASH_PROTECT_NONE); - bk_flash_erase_sector(n_base_addr); - bk_flash_erase_sector(data_sector_addr); -#endif - - for(dw_loop = 0;dw_loop < FLASH_NAME_MAX_ARRAY;dw_loop++) - { - if(name_temp[dw_loop].dwUsingFlag == FLASH_SPACE_USING)//表示该段数据有效 - { -#if CONFIG_FLASH_ORIGIN_API - ddev_write(flash_hdl, (char *)(&databuf[name_temp[dw_loop].dwOffsetByByte]), name_temp[dw_loop].dwlength, dw_data_addr);//先写数据 -#else - bk_flash_write_bytes(dw_data_addr, (uint8_t *)(&databuf[name_temp[dw_loop].dwOffsetByByte]), name_temp[dw_loop].dwlength); -#endif - dw_data_addr += name_temp[dw_loop].dwlength; - - name_temp[dw_loop].dwOffsetByByte = dw_offset; - dw_offset += name_temp[dw_loop].dwlength; -#if CONFIG_FLASH_ORIGIN_API - ddev_write(flash_hdl, (char *)(&name_temp[dw_loop]), PER_NAME_FLASH_SIZE, dw_name_addr);//写二级目录的数据 -#else - bk_flash_write_bytes(dw_name_addr, (uint8_t *)(&name_temp[dw_loop]), PER_NAME_FLASH_SIZE); -#endif - dw_name_addr += PER_NAME_FLASH_SIZE; - } - } - - if((dw_offset + dw_data_len) >= FLASH_SECTOR_SIZE)//如果整理之后,还是不够存下,则表明已经满了 - { - bk_printf("[%s] [%d] mem is full, dw_data_len:%d \r\n", __FUNCTION__,__LINE__, dw_data_len); - dw_rtn = kGeneralErr; - } - else//将数据直接写到更新之后的空间中 - { -#if CONFIG_FLASH_ORIGIN_API - ddev_write(flash_hdl, indata, dw_data_len, dw_data_addr);//先写三级目录的数据dw_thir_addr -#else - bk_flash_write_bytes(dw_data_addr, (uint8_t *)indata, dw_data_len); -#endif - name_data.dwlength = dw_data_len; - name_data.dwOffsetByByte = dw_offset; - name_data.dwUsingFlag = FLASH_SPACE_USING; -#if CONFIG_FLASH_ORIGIN_API - ddev_write(flash_hdl, (char *)(&name_data), PER_NAME_FLASH_SIZE, dw_name_addr);//先写二级目录的数据 -#else - bk_flash_write_bytes(dw_name_addr, (uint8_t *)(&name_data), PER_NAME_FLASH_SIZE); -#endif - //ddev_read(flash_hdl,(char *)(&name_temp_2), PER_NAME_FLASH_SIZE, dw_name_addr);//将缓存区中的数据读出来 - //bk_flash_debug_printf("[%s] [%d] %s [%u] {%u} [%x] \r\n", __FUNCTION__,__LINE__,name_temp_2.ucName,name_temp_2.dwlength,name_temp_2.dwOffsetByByte,name_temp_2.dwUsingFlag); - } - -#if CONFIG_FLASH_ORIGIN_API - ddev_control(flash_hdl, CMD_FLASH_SET_PROTECT, &protect_flag); -#else - bk_flash_set_protect_type(protect_type); -#endif - return dw_rtn; -} - -/********************************************************************* - * Funtion Name:get_name_new_addr - * - * Funtion Discription:Get Flash data into global variables - * - * - * - * - * Date:2021-12-22 - *******************************************************************/ -uint32_t bk_set_name_data_new_addr( uint32_t data_sector_addr,uint32_t base_addr,char * indata,uint32_t dw_data_len,name_flash_t name_data) -{ -#if CONFIG_FLASH_ORIGIN_API - DD_HANDLE flash_hdl = 0; - uint32_t status = 0,protect_param = 0,protect_flag = 0; -#endif - uint32_t dw_loop = 0; - name_flash_t *name_temp = NULL; - char *data_buff = NULL;//data buf - uint32_t data_offset_addr = 0; - uint32_t dw_rtn = 0; - uint32_t dw_mask_count = 0; - //name_flash_t name_temp_2 = {0}; - - name_temp = (name_flash_t *) os_malloc(NAME_FLASH_TOTAL_SIZE); - data_buff = (char *) os_malloc(FLASH_SECTOR_SIZE); - if ((NULL == name_temp) || (NULL == data_buff)) - { - bk_printf("[%s] [%d] os_malloc fail \r\n", __FUNCTION__,__LINE__); - return kGeneralErr; - } - memset((char *)name_temp,0,NAME_FLASH_TOTAL_SIZE); - memset((char *)data_buff,0,FLASH_SECTOR_SIZE); - -#if CONFIG_FLASH_ORIGIN_API - flash_hdl = ddev_open(DD_DEV_TYPE_FLASH, (UINT32 *)&status, 0); - ddev_control(flash_hdl, CMD_FLASH_GET_PROTECT, &protect_flag); - protect_param = FLASH_PROTECT_NONE; - ddev_control(flash_hdl, CMD_FLASH_SET_PROTECT, &protect_param); - ddev_read(flash_hdl,(char *)name_temp, NAME_FLASH_TOTAL_SIZE, base_addr); -#else - flash_protect_type_t protect_type; - protect_type = bk_flash_get_protect_type(); - bk_flash_set_protect_type(FLASH_PROTECT_NONE); - bk_flash_read_bytes(base_addr, (uint8_t *) name_temp, NAME_FLASH_TOTAL_SIZE); -#endif - - bk_flash_debug_printf("[%s] [%d] [%u] {%u} \r\n", __FUNCTION__,__LINE__,base_addr,NAME_FLASH_TOTAL_SIZE); - - for(dw_loop = 0;dw_loop < FLASH_NAME_MAX_ARRAY;dw_loop++) - { - bk_flash_debug_printf("[%s] [%d] [%u] {%x} \r\n", __FUNCTION__,__LINE__,dw_loop,name_temp[dw_loop].dwUsingFlag); - //如果此时即不是被MASK或者被正在用的,表明这个空间可能是第一次使用时的数据,或者是为FLASH_SPACE_UNUSED的数据 - if((name_temp[dw_loop].dwUsingFlag != FLASH_SPACE_USING ) && (name_temp[dw_loop].dwUsingFlag != FLASH_SPACE_MASK)) - { - bk_flash_debug_printf("[%s] [%d] [%u] {%u} \r\n", __FUNCTION__,__LINE__,data_offset_addr,dw_data_len); - if((data_offset_addr + dw_data_len) >= FLASH_SECTOR_SIZE) //如果当前的地址可用,判断当前的空间是否可以存贮下,如果存储不下,则进一步处理 - { -#if CONFIG_FLASH_ORIGIN_API - ddev_read(flash_hdl,(char *)data_buff, FLASH_SECTOR_SIZE, data_sector_addr);//将缓存区中的数据读出来 -#else - bk_flash_read_bytes(data_sector_addr, (uint8_t *)data_buff, FLASH_SECTOR_SIZE); -#endif - dw_rtn = bk_reorganize_name_data( base_addr,name_temp ,data_buff, data_sector_addr,indata,dw_data_len,name_data);//clean 二级目录的数据 - break;//跳出循环 - } - else//如果能够存储下,则直接将数据写进去 - { -#if CONFIG_FLASH_ORIGIN_API - ddev_write(flash_hdl, indata, dw_data_len, data_sector_addr + data_offset_addr);//先写三级目录的数据 -#else - bk_flash_write_bytes(data_sector_addr + data_offset_addr, (uint8_t *)(indata), dw_data_len); -#endif - name_data.dwlength = dw_data_len; - name_data.dwOffsetByByte = data_offset_addr; - name_data.dwUsingFlag = FLASH_SPACE_USING; - -#if CONFIG_FLASH_ORIGIN_API - ddev_write(flash_hdl, (char *)&name_data, PER_NAME_FLASH_SIZE, base_addr + dw_loop * PER_NAME_FLASH_SIZE);//先写二级目录的数据 -#else - bk_flash_write_bytes(base_addr + dw_loop * PER_NAME_FLASH_SIZE, (uint8_t *)(&name_data), PER_NAME_FLASH_SIZE); -#endif - - //ddev_read(flash_hdl,(char *)(&name_temp_2), PER_NAME_FLASH_SIZE, base_addr + dw_loop * PER_NAME_FLASH_SIZE);//将缓存区中的数据读出来 - //bk_flash_debug_printf("[%s] [%d] %s %u %u %x \r\n", __FUNCTION__,__LINE__,name_temp_2.ucName,name_temp_2.dwlength,name_temp_2.dwOffsetByByte,name_temp_2.dwUsingFlag); - break;//跳出循环 - } - } - else//如果是是被MASK或者被正在用的,则计算他们的偏移地址 - { - data_offset_addr = name_temp[dw_loop].dwOffsetByByte + name_temp[dw_loop].dwlength;//给下一次的不是unused或者没有写过的数据使用偏移 - bk_flash_debug_printf("[%s] [%d] %u %u\r\n", __FUNCTION__,__LINE__,name_temp[dw_loop].dwOffsetByByte,name_temp[dw_loop].dwlength); - bk_flash_debug_printf("[%s] [%d] %u %x\r\n", __FUNCTION__,__LINE__,data_offset_addr,name_temp[dw_loop].dwUsingFlag); - - if(name_temp[dw_loop].dwUsingFlag == FLASH_SPACE_MASK)//如果前面有MASK的则计数加一 - { - dw_mask_count++; - } - } - } - - if(dw_loop == FLASH_NAME_MAX_ARRAY) - { - if(dw_mask_count > 0)//如果names的空间全部都满了,且前面还有被MASK掉的空间,则继续整理 - { - bk_flash_debug_printf("[%s] [%d] %u %u %s \r\n", __FUNCTION__,__LINE__,data_sector_addr,dw_data_len,indata); - -#if CONFIG_FLASH_ORIGIN_API - ddev_read(flash_hdl,(char *)data_buff, FLASH_SECTOR_SIZE, data_sector_addr);//将缓存区中的数据读出来 -#else - bk_flash_read_bytes(data_sector_addr, (uint8_t *)data_buff, FLASH_SECTOR_SIZE); -#endif - dw_rtn = bk_reorganize_name_data( base_addr,name_temp ,data_buff, data_sector_addr,indata,dw_data_len,name_data);//clean 二级目录的数据 - } - else - { - bk_printf("[%s] [%d] set name fail \r\n", __FUNCTION__,__LINE__); - dw_rtn = kGeneralErr; - } - } - - os_free(name_temp); - os_free(data_buff); - name_temp = NULL; - data_buff = NULL; -#if CONFIG_FLASH_ORIGIN_API - ddev_control(flash_hdl, CMD_FLASH_SET_PROTECT, &protect_flag); -#else - bk_flash_set_protect_type(protect_type); -#endif - - return dw_rtn; -} - -/********************************************************************* - * Funtion Name:set_namespace_addr - * - * Funtion Discription:Get Flash data into global variables - * - * - * - * - * Date:2021-12-22 - *******************************************************************/ -uint32_t bk_set_namespace ( const char * ucnamespace,uint32_t np_base_addr,uint32_t *addr,uint32_t *block) //base_addr 要用上 -{ - uint32_t dw_rtn = kNoErr ; -#if CONFIG_FLASH_ORIGIN_API - DD_HANDLE flash_hdl = 0; - uint32_t status = 0,protect_param = 0,protect_flag = 0; -#endif - uint32_t dw_offset_addr = 0; - uint32_t dw_loop = 0 ; - //namespace_flash_t namespace_temp = {0}; - uint32_t dw_set_flag = NAME_SPACE_ADDR_SET_FAIL; - namespace_flash_t *namespace_data_arr = NULL; - - BK_CHECK_POINTER_NULL(ucnamespace); - namespace_data_arr = (namespace_flash_t *)os_malloc(NAME_SPACE_FLASH_ACTUAL_USE_SIZE); - if(NULL == namespace_data_arr) - { - bk_printf("[%s] [%d] os_malloc failed \r\n", __FUNCTION__,__LINE__); - return kGeneralErr; - } - memset((char *)namespace_data_arr,0,NAME_SPACE_FLASH_ACTUAL_USE_SIZE); - -#if CONFIG_FLASH_ORIGIN_API - flash_hdl = ddev_open(DD_DEV_TYPE_FLASH, (UINT32 *)&status, 0); - ddev_control(flash_hdl, CMD_FLASH_GET_PROTECT, &protect_flag); - protect_param = FLASH_PROTECT_NONE; - ddev_control(flash_hdl, CMD_FLASH_SET_PROTECT, &protect_param); - ddev_read(flash_hdl,(char *) namespace_data_arr, NAME_SPACE_FLASH_ACTUAL_USE_SIZE, np_base_addr); -#else - flash_protect_type_t protect_type; - protect_type = bk_flash_get_protect_type(); - bk_flash_set_protect_type(FLASH_PROTECT_NONE); - bk_flash_read_bytes(np_base_addr, (uint8_t *) namespace_data_arr, NAME_SPACE_FLASH_ACTUAL_USE_SIZE); -#endif - - //not found - for(dw_loop = 0;dw_loop < FLASH_NAME_SPACE_MAX_ARRAY;dw_loop++) - { - if(namespace_data_arr[dw_loop].dwUsingFlag != FLASH_SPACE_USING) - { - namespace_data_arr[dw_loop].dwUsingFlag = FLASH_SPACE_USING; - namespace_data_arr[dw_loop].dwOffsetByByte = dw_loop * NAME_FLASH_TOTAL_SIZE + NAME_SPACE_FLASH_TOTAL_SIZE; - memset(namespace_data_arr[dw_loop].ucNamespace, 0, sizeof(namespace_data_arr[dw_loop].ucNamespace)); - memcpy(namespace_data_arr[dw_loop].ucNamespace, ucnamespace, bk_strnlen(ucnamespace,sizeof(namespace_data_arr[dw_loop].ucNamespace) - 1)); - dw_set_flag = NAME_SPACE_ADDR_SET_SUCCESS; - break; - } - bk_flash_debug_printf("[%s] [%d] namespace [%s ] \r\n", __FUNCTION__,__LINE__,namespace_data_arr[dw_loop].ucNamespace); - } - - if(NAME_SPACE_ADDR_SET_SUCCESS == dw_set_flag) - { - dw_offset_addr = np_base_addr + dw_loop * PER_NAME_SPACE_FLASH_SIZE; - - *addr = namespace_data_arr[dw_loop].dwOffsetByByte; - *block = dw_loop; - - bk_flash_debug_printf("[%s] [%d] np_base_addr is [%u] [%u] \r\n", __FUNCTION__,__LINE__,dw_offset_addr,PER_NAME_SPACE_FLASH_SIZE); -#if CONFIG_FLASH_ORIGIN_API - ddev_write(flash_hdl,(char *) &(namespace_data_arr[dw_loop]), PER_NAME_SPACE_FLASH_SIZE, dw_offset_addr); -#else - bk_flash_write_bytes(dw_offset_addr, (uint8_t *)(&(namespace_data_arr[dw_loop])), PER_NAME_SPACE_FLASH_SIZE); -#endif - //ddev_read(flash_hdl,(char *) (&namespace_temp), PER_NAME_SPACE_FLASH_SIZE, dw_offset_addr); - //bk_flash_debug_printf("[%s] [%d] namespace %u %x [%s] \r\n", __FUNCTION__,__LINE__,namespace_temp.dwOffsetByByte,namespace_temp.dwUsingFlag,namespace_temp.ucNamespace); - } - else - { - bk_printf("[%s] [%d] namespace [%s ] set addr fail\r\n", __FUNCTION__,__LINE__,ucnamespace); - dw_rtn = kGeneralErr; - } - -#if CONFIG_FLASH_ORIGIN_API - ddev_control(flash_hdl, CMD_FLASH_SET_PROTECT, &protect_flag); -#else - bk_flash_set_protect_type(protect_type); -#endif - - os_free(namespace_data_arr); - namespace_data_arr = NULL; - - return dw_rtn; -} - -/********************************************************************* - * Funtion Name:set_name_addr - * - * Funtion Discription:Get Flash data into global variables - * - * - * - * - * Date:2021-12-22 - *******************************************************************/ -uint32_t bk_set_name_data( const char * ucnamespace,const char * ucname,uint32_t np_base_addr, char * indata,uint32_t dw_data_len,uint32_t dw_n_offset_addr, - uint32_t dw_offset_block) -{ -#if CONFIG_FLASH_ORIGIN_API - DD_HANDLE flash_hdl = 0; - uint32_t status = 0,protect_param = 0,protect_flag = 0; -#endif - uint32_t dw_offset_addr = 0,dw_actual_addr = 0,dw_data_offset_addr = 0; - uint32_t dw_sec_addr = 0; - name_flash_t name_temp = {0}; - char data_buf[2048] = {0};//数据最大2048个字节, 以后会优化最快 - uint32_t dw_rtn = kNoErr; - //uint32_t dw_sec_flag = FLASH_SPACE_MASK; - - BK_CHECK_POINTER_NULL(ucnamespace); - BK_CHECK_POINTER_NULL(ucname); - BK_CHECK_POINTER_NULL(indata); - - dw_actual_addr = np_base_addr + dw_n_offset_addr;//如果找到,继续找二级目录 - dw_sec_addr = dw_actual_addr;//二级目录的地址 - - bk_flash_debug_printf("[%s] [%d] NO NAME SPACE[%u] ucnamespace:%s , ucname:%s \r\n", __FUNCTION__,__LINE__,dw_data_len, ucnamespace, ucname); - bk_flash_debug_printf("[%s] [%d] NO NAME SPACE [%u] \r\n", __FUNCTION__,__LINE__,dw_actual_addr); - - if(kNoErr == get_name_addr(ucname, dw_actual_addr,&dw_offset_addr,&dw_data_offset_addr))//如果二级目录找到,将这个地址中的数据取出来 - { - dw_actual_addr += dw_offset_addr;//找到对应二级目录对应的数据 - -#if CONFIG_FLASH_ORIGIN_API - flash_hdl = ddev_open(DD_DEV_TYPE_FLASH, (UINT32 *)&status, 0); - ddev_control(flash_hdl, CMD_FLASH_GET_PROTECT, &protect_flag); - protect_param = FLASH_PROTECT_NONE; - ddev_control(flash_hdl, CMD_FLASH_SET_PROTECT, &protect_param); - ddev_read(flash_hdl,(char *) &name_temp, sizeof(name_temp), dw_actual_addr); -#else - flash_protect_type_t protect_type; - protect_type = bk_flash_get_protect_type(); - bk_flash_set_protect_type(FLASH_PROTECT_NONE); - bk_flash_read_bytes(dw_actual_addr, (uint8_t *) &name_temp, sizeof(name_temp)); -#endif - - dw_actual_addr = np_base_addr + dw_offset_block * FLASH_SECTOR_SIZE + NAME_FLASH_DATA_BASE_ADDR + dw_data_offset_addr ; - -#if CONFIG_FLASH_ORIGIN_API - ddev_read(flash_hdl,(char *) data_buf,name_temp.dwlength, dw_actual_addr); -#else - bk_flash_read_bytes(dw_actual_addr, (uint8_t *) data_buf, name_temp.dwlength); -#endif - bk_flash_debug_printf("[%s] [%d] NAME [%u] [%u] \r\n", __FUNCTION__,__LINE__,dw_data_len,name_temp.dwlength); - - if((name_temp.dwlength != dw_data_len) || (0 != memcmp(data_buf,indata,dw_data_len))) //长度不相等,切数据不一样,则重新找新的地址进行存储 - { - name_temp.dwUsingFlag = FLASH_SPACE_MASK; -#if CONFIG_FLASH_ORIGIN_API - ddev_write(flash_hdl,(char *) &name_temp, sizeof(name_temp), (dw_sec_addr + dw_offset_addr));//将这二级目录空间对应的Flag置位无效 - ddev_read(flash_hdl,(char *) &name_temp, sizeof(name_temp), (dw_sec_addr + dw_offset_addr)); -#else - bk_flash_write_bytes((dw_sec_addr + dw_offset_addr), (uint8_t *) &name_temp, sizeof(name_temp)); - bk_flash_read_bytes((dw_sec_addr + dw_offset_addr), (uint8_t *) &name_temp, sizeof(name_temp)); -#endif - - bk_flash_debug_printf("[%s] [%d] NAME [%u] [%u] \r\n", __FUNCTION__,__LINE__,dw_sec_addr,dw_offset_addr); - bk_flash_debug_printf("[%s] [%d] NAME [%x] [%u] [%u] \r\n", __FUNCTION__,__LINE__,name_temp.dwUsingFlag,name_temp.dwOffsetByByte,name_temp.dwlength); - dw_rtn = bk_set_name_data_new_addr( dw_actual_addr - dw_data_offset_addr, dw_sec_addr,indata,dw_data_len,name_temp); - } -#if CONFIG_FLASH_ORIGIN_API - ddev_control(flash_hdl, CMD_FLASH_SET_PROTECT, &protect_flag); -#else - bk_flash_set_protect_type(protect_type); -#endif - - } - else//如果没有找到,新建一个二级和三级目录 - { - name_temp.dwlength = dw_data_len; - name_temp.dwOffsetByByte = 0; - name_temp.dwUsingFlag = FLASH_SPACE_USING; - memset(name_temp.ucName,0,sizeof(name_temp.ucName)); - memcpy(name_temp.ucName,ucname,bk_strnlen(ucname,sizeof(name_temp.ucName) - 1)); - - dw_actual_addr = np_base_addr + dw_offset_block * FLASH_SECTOR_SIZE + NAME_FLASH_DATA_BASE_ADDR; //数据所在的位置 - - bk_flash_debug_printf("[%s] [%d] NAME [%u] [%u] \r\n", __FUNCTION__,__LINE__,dw_sec_addr,dw_offset_block); - - bk_flash_debug_printf("[%s] [%d] NAME [%u] [%u] \r\n", __FUNCTION__,__LINE__,dw_actual_addr,dw_data_len); - - dw_rtn = bk_set_name_data_new_addr( dw_actual_addr,dw_sec_addr,indata,dw_data_len,name_temp); - } - - return dw_rtn; -} - -/********************************************************************* - * Funtion Name:bk_clean_data - * - * Funtion Discription:clean data in the flash - * - * - * - * - * Date:2021-12-22 - *******************************************************************/ -uint32_t bk_clean_data ( const char * ucnamespace,const char * ucname) -{ -#if CONFIG_FLASH_ORIGIN_API - DD_HANDLE flash_hdl = 0; - uint32_t status = 0,protect_param = 0,protect_flag = 0; -#endif - uint32_t dw_offset_addr = 0,dw_actual_addr = 0,dw_offset_block = 0,dw_data_offset_addr = 0; - //uint32_t dw_sec_addr = 0; - uint32_t dw_rtn = kNoErr; - uint32_t dw_sec_flag = FLASH_SPACE_MASK; - uint32_t np_base_addr = 0; - uint32_t dw_name_offset = 0; - //name_flash_t name_temp = {0}; - - BK_CHECK_POINTER_NULL(ucnamespace); - BK_CHECK_POINTER_NULL(ucname); - - dw_rtn = get_matter_flash_base_addr(&np_base_addr); - BK_CHECK_RETURN_VAULEL(dw_rtn); - -#if CONFIG_FLASH_ORIGIN_API - flash_hdl = ddev_open(DD_DEV_TYPE_FLASH, (UINT32 *)&status, 0); -#else - flash_protect_type_t protect_type; - protect_type = bk_flash_get_protect_type(); -#endif - if(kNoErr == get_namespace_addr(ucnamespace, np_base_addr,(uint32_t *)&dw_offset_addr,(uint32_t *)&dw_offset_block))//看是否在一级目录中找到对应namespace - { - dw_actual_addr = np_base_addr + dw_offset_addr;//如果找到,继续找二级目录 - //dw_sec_addr = dw_actual_addr;//二级目录的地址 - - if(kNoErr == get_name_addr(ucname, dw_actual_addr,&dw_name_offset,&dw_data_offset_addr))//如果二级目录找到,将这个地址中的数据取出来 - { - dw_actual_addr += dw_name_offset;//找到对应目录对应的数据 - bk_flash_debug_printf("[%s] [%d] [%u] [%u] [%u] \r\n", __FUNCTION__,__LINE__,dw_name_offset,dw_actual_addr); -#if CONFIG_FLASH_ORIGIN_API - ddev_control(flash_hdl, CMD_FLASH_GET_PROTECT, &protect_flag); - protect_param = FLASH_PROTECT_NONE; - ddev_control(flash_hdl, CMD_FLASH_SET_PROTECT, &protect_param); - //ddev_read(flash_hdl,(char *) &name_temp, sizeof(name_temp), dw_actual_addr); - //bk_flash_debug_printf("[%s] [%d] [%s] [%u] [%u] [%u] [%u] \r\n", __FUNCTION__,__LINE__,name_temp.ucName,name_temp.dwUsingFlag,name_temp.dwOffsetByByte,name_temp.dwlength); - ddev_write(flash_hdl,(char *)&dw_sec_flag, sizeof(dw_sec_flag), dw_actual_addr);//将这二级目录空间对应的Flag置位无效 - //ddev_read(flash_hdl,(char *) &name_temp, sizeof(name_temp), dw_actual_addr); - //bk_flash_debug_printf("[%s] [%d] [%s] [%u] [%u] [%u] [%u] \r\n", __FUNCTION__,__LINE__,name_temp.ucName,name_temp.dwUsingFlag,name_temp.dwOffsetByByte,name_temp.dwlength); -#else - bk_flash_set_protect_type(FLASH_PROTECT_NONE); - bk_flash_write_bytes(dw_actual_addr, (uint8_t *) &dw_sec_flag, sizeof(dw_sec_flag)); -#endif - } - else - { - bk_printf("[%s] [%d] No Such Name \r\n", __FUNCTION__,__LINE__); - dw_rtn = kGeneralErr; - } - } - else - { - bk_printf("[%s] [%d] No Such Namespace \r\n", __FUNCTION__,__LINE__); - dw_rtn = kGeneralErr; - } - -#if CONFIG_FLASH_ORIGIN_API - ddev_control(flash_hdl, CMD_FLASH_SET_PROTECT, &protect_flag); -#else - bk_flash_set_protect_type(protect_type); -#endif - - return dw_rtn; -} - -/********************************************************************* - * Funtion Name:bK_clear_namespace - * - * Funtion Discription:Clear namespace - * - * - * - * Date:2021-12-22 - *******************************************************************/ -uint32_t bK_clear_namespace ( const char * ucnamespace) //base_addr 要用上 -{ - uint32_t dw_rtn = kNoErr ; - -#if CONFIG_FLASH_ORIGIN_API - DD_HANDLE flash_hdl = 0; - uint32_t status = 0,protect_param = 0,protect_flag = 0; -#endif - uint32_t dw_offset_addr = 0 ,dw_off_block = 0; - uint32_t dw_start_addr = 0 ; - uint32_t np_base_addr = 0; - uint32_t data_sector_addr = 0; - uint32_t dwLoop = 0; - namespace_flash_t *namespace_temp = NULL; - - BK_CHECK_POINTER_NULL(ucnamespace); - dw_rtn = get_matter_flash_base_addr(&np_base_addr); - BK_CHECK_RETURN_VAULEL(dw_rtn); - - namespace_temp =(namespace_flash_t *) os_malloc(NAME_SPACE_FLASH_ACTUAL_USE_SIZE); - if(NULL == namespace_temp) - { - bk_printf("[%s] [%d] os_malloc failed \r\n", __FUNCTION__,__LINE__); - return kGeneralErr; - } - memset((char *)namespace_temp,0,NAME_SPACE_FLASH_ACTUAL_USE_SIZE); - - if(kNoErr == get_namespace_addr(ucnamespace, np_base_addr,&dw_offset_addr,&dw_off_block))//found namespace - { -#if CONFIG_FLASH_ORIGIN_API - flash_hdl = ddev_open(DD_DEV_TYPE_FLASH, (UINT32 *)&status, 0); - ddev_control(flash_hdl, CMD_FLASH_GET_PROTECT, &protect_flag); - protect_param = FLASH_PROTECT_NONE; - ddev_control(flash_hdl, CMD_FLASH_SET_PROTECT, &protect_param); - ddev_read(flash_hdl,(char *) namespace_temp, NAME_SPACE_FLASH_ACTUAL_USE_SIZE, np_base_addr); -#else - flash_protect_type_t protect_type; - protect_type = bk_flash_get_protect_type(); - bk_flash_set_protect_type(FLASH_PROTECT_NONE); - bk_flash_write_bytes(np_base_addr, (uint8_t *) namespace_temp, NAME_SPACE_FLASH_ACTUAL_USE_SIZE); -#endif - - dw_start_addr = np_base_addr + NAME_SPACE_FLASH_TOTAL_SIZE + dw_off_block * NAME_FLASH_TOTAL_SIZE; - data_sector_addr = np_base_addr + dw_off_block * FLASH_SECTOR_SIZE + NAME_FLASH_DATA_BASE_ADDR;//数据区域的地址 - bk_erase_name_data(dw_start_addr,data_sector_addr);//清除二级目录的数据,把二级目录和其对应的数据全部擦掉 - -#if CONFIG_FLASH_ORIGIN_API - ddev_control(flash_hdl, CMD_FLASH_ERASE_SECTOR, &np_base_addr);//将一级目录对应的数据区erase掉 -#else - bk_flash_erase_sector(np_base_addr); -#endif - namespace_temp[dw_off_block].dwUsingFlag = FLASH_SPACE_MASK; - - for(dwLoop = 0;dwLoop < FLASH_NAME_SPACE_MAX_ARRAY;dwLoop++) - { - if(FLASH_SPACE_USING == namespace_temp[dwLoop].dwUsingFlag)//如果该命名空间有效,则在写回去,改命名空间的位置不做改变 - { -#if CONFIG_FLASH_ORIGIN_API - ddev_write(flash_hdl, (char *)(&namespace_temp[dwLoop]), PER_NAME_SPACE_FLASH_SIZE,np_base_addr + dwLoop * PER_NAME_SPACE_FLASH_SIZE);//先写一级目录的数据 -#else - bk_flash_write_bytes(np_base_addr + dwLoop * PER_NAME_SPACE_FLASH_SIZE, (uint8_t *)(&namespace_temp[dwLoop]), PER_NAME_SPACE_FLASH_SIZE); -#endif - } - } -#if CONFIG_FLASH_ORIGIN_API - ddev_control(flash_hdl, CMD_FLASH_SET_PROTECT, &protect_flag); -#else - bk_flash_set_protect_type(protect_type); -#endif - } - else - { - bk_printf("[%s] [%d] No Such Namespace \r\n", __FUNCTION__,__LINE__); - dw_rtn = kGeneralErr; - } - os_free(namespace_temp); - namespace_temp = NULL; - - return dw_rtn; -} - -/********************************************************************* - * Funtion Name:bk_read_data - * - * Funtion Discription:read data from flash - * - * - * - * - * Date:2021-12-22 - *******************************************************************/ -uint32_t bk_read_data( const char * ucnamespace,const char * ucname,char * out_data,uint32_t dw_read_len,uint32_t *out_length) -{ - uint32_t dw_rtn = kNoErr; -#if CONFIG_FLASH_ORIGIN_API - DD_HANDLE flash_hdl = 0; - uint32_t status = 0,protect_param = 0,protect_flag = 0; -#endif - uint32_t dw_offset_addr = 0,dw_off_block = 0; - uint32_t dw_sec_base_addr = 0,dw_data_offset_addr = 0,dw_data_addr = 0; - name_flash_t name_temp = {0}; - uint32_t np_base_addr = 0; - uint32_t dw_actual_len = 0; - - BK_CHECK_POINTER_NULL(ucnamespace); - BK_CHECK_POINTER_NULL(ucname); - BK_CHECK_POINTER_NULL(out_data); - BK_CHECK_POINTER_NULL(out_length); - bk_flash_debug_printf("read %s.%s \r\n",ucnamespace,ucname); - dw_rtn = get_matter_flash_base_addr(&np_base_addr); - BK_CHECK_RETURN_VAULEL(dw_rtn); - - if(kNoErr == get_namespace_addr(ucnamespace, np_base_addr,&dw_offset_addr,&dw_off_block))//如果找到对应的namespace,继续找二级目录 - { - dw_sec_base_addr = np_base_addr + dw_offset_addr;//获取二级目录的地址 - if(kNoErr == get_name_addr(ucname, dw_sec_base_addr,&dw_offset_addr,&dw_data_offset_addr))//如果二级目录找到,将这个地址中的数据取出来 - { - bk_flash_debug_printf("[%s] [%d] read [%u] [%u] [%u] \r\n", __FUNCTION__,__LINE__,dw_sec_base_addr,dw_offset_addr,dw_data_offset_addr); - dw_data_addr = dw_sec_base_addr + dw_offset_addr;///找到对应二级目录块存在的位置 -#if CONFIG_FLASH_ORIGIN_API - flash_hdl = ddev_open(DD_DEV_TYPE_FLASH, (UINT32 *)&status, 0); - ddev_control(flash_hdl, CMD_FLASH_GET_PROTECT, &protect_flag); - protect_param = FLASH_PROTECT_NONE; - ddev_control(flash_hdl, CMD_FLASH_SET_PROTECT, &protect_param); - ddev_read(flash_hdl,(char *) &name_temp, sizeof(name_temp), dw_data_addr); -#else - flash_protect_type_t protect_type; - protect_type = bk_flash_get_protect_type(); - bk_flash_set_protect_type(FLASH_PROTECT_NONE); - bk_flash_read_bytes(dw_data_addr, (uint8_t *) &name_temp, sizeof(name_temp)); -#endif - dw_actual_len = ((dw_read_len > name_temp.dwlength) ? name_temp.dwlength : dw_read_len);//取最小的长度读数据 - *out_length = dw_actual_len; - - dw_data_addr = np_base_addr + dw_off_block * FLASH_SECTOR_SIZE + NAME_FLASH_DATA_BASE_ADDR + dw_data_offset_addr ;;//找到对应二级目录中对应数据的位置 -#if CONFIG_FLASH_ORIGIN_API - ddev_read(flash_hdl,(char *) out_data, dw_actual_len, dw_data_addr);//读取的长度有外面的变量传进来 -#else - bk_flash_read_bytes(dw_data_addr, (uint8_t *) out_data, dw_actual_len); -#endif - bk_flash_debug_printf("[%s] [%d] read [%s] [%u] [%u] \r\n", __FUNCTION__,__LINE__,out_data,dw_data_addr,dw_actual_len); - -#if CONFIG_FLASH_ORIGIN_API - ddev_control(flash_hdl, CMD_FLASH_SET_PROTECT, &protect_flag); -#else - bk_flash_set_protect_type(protect_type); -#endif - } - else//表示没有找到name - { - dw_rtn = kGeneralErr; - bk_flash_debug_printf("[%s] [%d] NO NAME [%u] [%u] [%u] \r\n", __FUNCTION__,__LINE__,dw_sec_base_addr,dw_offset_addr,dw_data_offset_addr); - } - } - else//表示没有找到namespace - { - dw_rtn = kGeneralErr; - bk_flash_debug_printf("[%s] [%d] NO NAME SPACE [%u] [%u] [%u] \r\n", __FUNCTION__,__LINE__,np_base_addr,dw_offset_addr,dw_off_block); - } - - return dw_rtn; -} - -/********************************************************************* - * Funtion Name:bk_write_data - * - * Funtion Discription:read data from flash - * - * - * - * - * Date:2021-12-22 - *******************************************************************/ -uint32_t bk_write_data( const char * ucnamespace,const char * ucname, char * indata,uint32_t data_size) -{ - uint32_t dw_rtn = kNoErr; - uint32_t dw_offset_addr = 0,dw_off_block = 0; - uint32_t np_base_addr = 0; - - BK_CHECK_POINTER_NULL(ucnamespace); - BK_CHECK_POINTER_NULL(ucname); - BK_CHECK_POINTER_NULL(indata); - bk_flash_debug_printf("write %s.%s \r\n",ucnamespace,ucname); - - dw_rtn = get_matter_flash_base_addr(&np_base_addr); - BK_CHECK_RETURN_VAULEL(dw_rtn); - bk_flash_debug_printf("[%s] [%d] np_base_addr is [%u] \r\n", __FUNCTION__,__LINE__,np_base_addr); - if(kNoErr != get_namespace_addr(ucnamespace, np_base_addr,&dw_offset_addr,&dw_off_block)) - { - bk_flash_debug_printf("[%s] [%d] np_base_addr is [%u] [%u] [%u] \r\n", __FUNCTION__,__LINE__,np_base_addr,dw_offset_addr,dw_off_block); - dw_rtn = bk_set_namespace(ucnamespace, np_base_addr,&dw_offset_addr,&dw_off_block); - BK_CHECK_RETURN_VAULEL(dw_rtn); - } - - bk_flash_debug_printf("[%s] [%d] np_base_addr is [%u] [%u] [%u] data_size:%d \r\n", __FUNCTION__,__LINE__,np_base_addr,dw_offset_addr,dw_off_block, data_size); - dw_rtn = bk_set_name_data(ucnamespace, ucname, np_base_addr, indata,data_size,dw_offset_addr,dw_off_block); - BK_CHECK_RETURN_VAULEL(dw_rtn); - - - return dw_rtn; -} - -/********************************************************************* - * Funtion Name:bk_ensure_namespace - * Funtion Discription:check namespace exit or not - * - * - * - * - * Date:2021-12-22 - *******************************************************************/ -uint32_t bk_ensure_namespace( const char * ucnamespace) -{ - uint32_t dw_rtn = kGeneralErr; - uint32_t dw_offset_addr = 0,dw_off_block = 0; - uint32_t np_base_addr = 0; - - BK_CHECK_POINTER_NULL(ucnamespace); - dw_rtn = get_matter_flash_base_addr(&np_base_addr); - BK_CHECK_RETURN_VAULEL(dw_rtn); - bk_flash_debug_printf("check for %s \r\n",ucnamespace); - if(kNoErr == get_namespace_addr(ucnamespace, np_base_addr,&dw_offset_addr,&dw_off_block))//如果找到对应的namespace,继续找二级目录 - { - bk_flash_debug_printf("check %s find addr = %d \r\n",ucnamespace,dw_offset_addr); - dw_rtn = kNoErr; - } - else - { - if(kNoErr == bk_set_namespace ( ucnamespace, np_base_addr,&dw_offset_addr,&dw_off_block)) - { - dw_rtn = kNoErr; - } - else - { - dw_rtn = kGeneralErr; - } - bk_flash_debug_printf("check %s set addr = %d \r\n",ucnamespace,dw_offset_addr); - } - - return dw_rtn; -} -/********************************************************************* - * Funtion Name:bk_ensure_name_data - * - * Funtion Discription:check data exit or not - * - * - * - * - * Date:2021-12-22 - *******************************************************************/ -uint32_t bk_ensure_name_data( const char * ucnamespace,const char * ucname) -{ - uint32_t dw_rtn = kGeneralErr; - uint32_t dw_offset_addr = 0,dw_off_block = 0; - uint32_t np_base_addr = 0; - uint32_t dw_actual_addr = 0; - uint32_t dw_data_offset_addr = 0; - - BK_CHECK_POINTER_NULL(ucnamespace); - dw_rtn = get_matter_flash_base_addr(&np_base_addr); - BK_CHECK_RETURN_VAULEL(dw_rtn); - bk_flash_debug_printf("check for %s.%s \r\n",ucnamespace,ucname); - - if(kNoErr == get_namespace_addr(ucnamespace, np_base_addr,&dw_offset_addr,&dw_off_block))//如果找到对应的namespace,继续找二级目录 - { - dw_actual_addr = np_base_addr + dw_offset_addr;//如果找到,继续找二级目录 - bk_flash_debug_printf("check %s.%s.b_addr=0x%x \r\n",ucnamespace,ucname,dw_actual_addr); - if(kNoErr == get_name_addr(ucname, dw_actual_addr,&dw_offset_addr,&dw_data_offset_addr)) - { - os_printf("find addr = dw_offset_addr \r\n "); - dw_rtn = kNoErr; - } - else - { - os_printf("find fail\r\n "); - dw_rtn = kGeneralErr; - } - } - else - { - bk_flash_debug_printf("check fail\r\n "); - dw_rtn = kGeneralErr; - } - - return dw_rtn; -} - -/********************************************************************* - * Funtion Name:bk_erase_all - * - * Funtion Discription:Erase all Matter Flash data - * - * - * - * Date:2022-02-07 - *******************************************************************/ -uint32_t bk_erase_all( bk_partition_t type ) -{ -#if CONFIG_FLASH_ORIGIN_API - DD_HANDLE flash_hdl = 0; - uint32_t status = 0,protect_param = 0,protect_flag = 0; -#endif - uint32_t flash_occu_length = 0; - uint32_t operation_addr = 0; - uint32_t dw_loop = 0; - bk_logic_partition_t *partition_info = NULL; - -#if CONFIG_FLASH_ORIGIN_API - partition_info = bk_flash_get_info(type); -#else - partition_info = bk_flash_partition_get_info(type); -#endif - BK_CHECK_POINTER_NULL(partition_info); - - operation_addr = partition_info->partition_start_addr; - flash_occu_length = partition_info->partition_length; - -#if CONFIG_FLASH_ORIGIN_API - flash_hdl = ddev_open(DD_DEV_TYPE_FLASH, (UINT32 *)&status, 0); - ddev_control(flash_hdl, CMD_FLASH_GET_PROTECT, &protect_flag); - protect_param = FLASH_PROTECT_NONE; - ddev_control(flash_hdl, CMD_FLASH_SET_PROTECT, &protect_param); -#else - flash_protect_type_t protect_type; - protect_type = bk_flash_get_protect_type(); - bk_flash_set_protect_type(FLASH_PROTECT_NONE); -#endif - - for(dw_loop = 0;dw_loop < flash_occu_length / NAME_SPACE_FLASH_TOTAL_SIZE;dw_loop++) - { -#if CONFIG_FLASH_ORIGIN_API - ddev_control(flash_hdl, CMD_FLASH_ERASE_SECTOR, &operation_addr); -#else - bk_flash_erase_sector(operation_addr); -#endif - operation_addr += NAME_SPACE_FLASH_TOTAL_SIZE; - } - -#if CONFIG_FLASH_ORIGIN_API - ddev_control(flash_hdl, CMD_FLASH_SET_PROTECT, &protect_flag); -#else - bk_flash_set_protect_type(protect_type); -#endif - - return kNoErr; -} - -/********************************************************************* - * Funtion Name:bk_write_ota_data_to_flash - * - * Funtion Discription:write ota data to flash - * - * - * - * - * Date:2022-02-10 - *******************************************************************/ -uint32_t bk_write_ota_data_to_flash( char * indata,uint32_t data_offset_addr,uint32_t data_length) -{ - uint32_t dw_rtn = kNoErr; - - BK_CHECK_POINTER_NULL(indata); - - bk_flash_debug_printf("[%s] [%d] NAME [%u] [%u] \r\n", __FUNCTION__,__LINE__,data_offset_addr,data_length); -#if (CONFIG_FLASH_ORIGIN_API) - dw_rtn = bk_flash_write( BK_PARTITION_OTA, data_offset_addr, (uint8_t *)indata , data_length); -#else - bk_logic_partition_t *pt = bk_flash_partition_get_info(BK_PARTITION_OTA); - dw_rtn = bk_flash_write_bytes((pt->partition_start_addr + data_offset_addr), (uint8_t *)indata, data_length); -#endif - - return dw_rtn; -} - -/********************************************************************* - * Funtion Name:bk_read_ota_data_in_flash - * - * Funtion Discription:read ota data in flash - * - * - * - * - * Date:2022-02-10 - *******************************************************************/ -uint32_t bk_read_ota_data_in_flash( char * outdata,uint32_t data_offset_addr,uint32_t data_length) -{ - uint32_t dw_rtn = kNoErr; - - BK_CHECK_POINTER_NULL(outdata); -#if (CONFIG_FLASH_ORIGIN_API) - dw_rtn = bk_flash_read( BK_PARTITION_OTA, data_offset_addr, (uint8_t *)outdata, data_length); - #else - bk_logic_partition_t *pt = bk_flash_partition_get_info(BK_PARTITION_OTA); - dw_rtn = bk_flash_read_bytes((pt->partition_start_addr + data_offset_addr), (uint8_t *)outdata, data_length); -#endif - - return dw_rtn; -} - -/********************************************************************* - * Funtion Name:bk_erase_ota_data_in_flash - * - * Funtion Discription:erase ota data in flash - * - * - * - * - * Date:2022-02-10 - *******************************************************************/ -uint32_t bk_erase_ota_data_in_flash( ) -{ - uint32_t dw_rtn = kNoErr; - - dw_rtn = bk_erase_all( BK_PARTITION_OTA); - - return dw_rtn; -} - -#if 1 -/********************************************************************* - * Funtion Name:test bk_flash write - * - * Funtion Discription:check data exit or not - * - * - * - * - * Date:2021-12-22 - *******************************************************************/ -void bk_write_data_test(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv ) -{ - uint32_t dwRtn = 0; - uint32_t dwLoop = 0; - - name_flash_test_t temp_value[] = { \ - {"bekenspace1" ,"beken_name1" ,"1188888888888811",0}, \ - {"bekenspace2" ,"beken_name2" ,"2288888888888822",0}, \ - {"bekenspace3" ,"beken_name3" ,"3388888888888833",0},}; - - name_flash_test_t temp_value1[] = { \ - {"bekenspace1" ,"beken_name1" ,"1188888888888811909090",0}, }; - - - uint32_t dwDataLen = sizeof(temp_value) / sizeof(temp_value[0]); - uint32_t dwDataLen1 = sizeof(temp_value1) / sizeof(temp_value1[0]); - - uint32_t dwData = 0; - char cmd0 = 0; - char cmd1 = 0; - - for(dwLoop = 0; dwLoop < argc; dwLoop++) - { - bk_printf("Argument %d = %s\r\n", dwLoop + 1, argv[dwLoop]); - } - - if(argc == 2) - { - cmd0 = argv[1][0] - 0x30; - cmd1 = argv[1][1] - 0x30; - - dwData = (uint32_t)(cmd0 * 10 + cmd1); - bk_printf("---%u \r\n", dwData); - } - else - { - bk_printf("cmd param error \r\n"); - return ; - } - - if(dwData == 0) - { - for(dwLoop = 0;dwLoop < dwDataLen;dwLoop++) - { - dwRtn = bk_write_data( temp_value[dwLoop].ucNamespace,temp_value[dwLoop].ucName, temp_value[dwLoop].ucData,strlen(temp_value[dwLoop].ucData)); - BK_CHECK_NO_RETURN(dwRtn); - } - } - else - { - for(dwLoop = 0;dwLoop < dwDataLen1;dwLoop++) - { - dwRtn = bk_write_data( temp_value1[dwLoop].ucNamespace,temp_value1[dwLoop].ucName, temp_value1[dwLoop].ucData,strlen(temp_value1[dwLoop].ucData)); - BK_CHECK_NO_RETURN(dwRtn); - } - } - - return ; -} - -/********************************************************************* - * Funtion Name:test bk_flash read - * - * Funtion Discription:check data exit or not - * - * - * - * - * Date:2021-12-22 - *******************************************************************/ -void bk_read_data_test(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - uint32_t dwRtn = 0; - uint32_t dwLoop = 0; - uint32_t dwOut_length = 0; - name_flash_test_t temp_value[10] = { \ - {"bekenspace1" ,"beken_name1" ,"",16},\ - {"bekenspace2" ,"beken_name2" ,"",16},\ - {"bekenspace3" ,"beken_name3" ,"",16},}; - - uint32_t dwDataLen = sizeof(temp_value) / sizeof(temp_value[0]); - uint32_t dwData = 0; - char cmd0 = 0; - char cmd1 = 0; - - for(dwLoop = 0; dwLoop < argc; dwLoop++) - { - bk_printf("Argument %d = %s\r\n", dwLoop + 1, argv[dwLoop]); - } - - if(argc == 2) - { - cmd0 = argv[1][0] - 0x30; - cmd1 = argv[1][1] - 0x30; - - dwData = (uint32_t)(cmd0 * 10 + cmd1); - bk_printf("---%u \r\n", dwData); - } - else - { - bk_printf("cmd param error \r\n"); - return ; - } - - if(dwData >= dwDataLen) - { - bk_printf("dwData [%u] is overflow,the max is %u \r\n",dwData,dwDataLen); - return ; - } - - dwRtn = bk_read_data(temp_value[dwData].ucNamespace,temp_value[dwData].ucName, temp_value[dwData].ucData, 50 ,&dwOut_length); - BK_CHECK_NO_RETURN(dwRtn); - - bk_printf("Namespace is [%s] \r\n",temp_value[dwData].ucNamespace); - - bk_printf("Name is [%s] \r\n",temp_value[dwData].ucName); - - bk_printf("Data is [%s] \r\n",temp_value[dwData].ucData); - - bk_printf("Length is [%u] \r\n",dwOut_length); - - return ; -} - -/********************************************************************* - * Funtion Name:test bk_erase_namespace_test - * - * Funtion Discription:check data exit or not - * - * - * - * - * Date:2021-12-22 - *******************************************************************/ -void bk_erase_namespace_test(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - uint32_t dwRtn = 0; - uint32_t dwLoop = 0; - name_flash_test_t temp_value[10] = { \ - {"bekenspace1" ,"beken_name1" ,"1188888888888811",16}, \ - {"bekenspace2" ,"beken_name2" ,"2288888888888822",16}, \ - {"bekenspace3" ,"beken_name3" ,"3388888888888833",16},}; - - uint32_t dwDataLen = sizeof(temp_value) / sizeof(temp_value[0]); - uint32_t dwData = 0; - char cmd0 = 0; - char cmd1 = 0; - - for(dwLoop = 0; dwLoop < argc; dwLoop++) - { - bk_printf("Argument %d = %s\r\n", dwLoop + 1, argv[dwLoop]); - } - - if(argc == 2) - { - cmd0 = argv[1][0] - 0x30; - cmd1 = argv[1][1] - 0x30; - - dwData = (uint32_t)(cmd0 * 10 + cmd1); - bk_printf("---%u \r\n", dwData); - } - else - { - bk_printf("cmd param error \r\n"); - return ; - } - - if(dwData >= dwDataLen) - { - bk_printf("dwData [%u] is overflow,the max is %u \r\n",dwData,dwDataLen); - return ; - } - - dwRtn = bK_clear_namespace(temp_value[dwData].ucNamespace); - BK_CHECK_NO_RETURN(dwRtn); - - return ; -} - -/********************************************************************* - * Funtion Name:bk_erase_name_test - * - * Funtion Discription:check data exit or not - * - * - * - * - * Date:2021-12-22 - *******************************************************************/ -void bk_erase_name_test(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - name_flash_test_t temp_value[10] = { \ - {"bekenspace1" ,"beken_name1" ,"1188888888888811",16}, \ - {"bekenspace2" ,"beken_name2" ,"2288888888888822",16}, \ - {"bekenspace3" ,"beken_name3" ,"3388888888888833",16},}; - - uint32_t dwDataLen = sizeof(temp_value) / sizeof(temp_value[0]); - uint32_t dwRtn = 0; - uint32_t dwData = 0; - uint32_t dwLoop = 0; - char cmd0 = 0; - char cmd1 = 0; - - for(dwLoop = 0; dwLoop < argc; dwLoop++) - { - bk_printf("Argument %d = %s\r\n", dwLoop + 1, argv[dwLoop]); - } - - if(argc == 2) - { - cmd0 = argv[1][0] - 0x30; - cmd1 = argv[1][1] - 0x30; - - dwData = (uint32_t)(cmd0 * 10 + cmd1); - bk_printf("---%u \r\n", dwData); - } - else - { - bk_printf("cmd param error \r\n"); - return ; - } - - if(dwData >= dwDataLen) - { - bk_printf("dwData [%u] is overflow,the max is %u \r\n",dwData,dwDataLen); - return ; - } - - dwRtn = bk_clean_data ( temp_value[dwData].ucNamespace,temp_value[dwData].ucName); - BK_CHECK_NO_RETURN(dwRtn); - - return; -} - -/********************************************************************* - * Funtion Name:bk_erase_name_test - * - * Funtion Discription:check data exit or not - * - * - * - * - * Date:2021-12-22 - *******************************************************************/ -void bk_name_data_exits(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - name_flash_test_t temp_value[10] = { \ - {"bekenspace1" ,"beken_name1" ,"1188888888888811",16},\ - {"bekenspace2" ,"beken_name2" ,"2288888888888822",16},\ - {"bekenspace3" ,"beken_name3" ,"3388888888888833",16},}; - - uint32_t dwDataLen = sizeof(temp_value) / sizeof(temp_value[0]); - uint32_t dwRtn = 0; - uint32_t dwData = 0; - uint32_t dwLoop = 0; - char cmd0 = 0; - char cmd1 = 0; - - for(dwLoop = 0; dwLoop < argc; dwLoop++) - { - bk_printf("Argument %d = %s\r\n", dwLoop + 1, argv[dwLoop]); - } - - if(argc == 2) - { - cmd0 = argv[1][0] - 0x30; - cmd1 = argv[1][1] - 0x30; - - dwData = (uint32_t)(cmd0 * 10 + cmd1); - bk_printf("---%u \r\n", dwData); - } - else - { - bk_printf("cmd param error \r\n"); - return ; - } - - if(dwData >= dwDataLen) - { - bk_printf("dwData [%u] is overflow,the max is %u \r\n",dwData,dwDataLen); - return ; - } - - dwRtn = bk_ensure_name_data( temp_value[dwData].ucNamespace,temp_value[dwData].ucName); - - if (kNoErr ==dwRtn) - { - bk_printf("Namespace [%s] Name [%s] exits \r\n",temp_value[dwData].ucNamespace,temp_value[dwData].ucName); - } - else - { - bk_printf("Namespace [%s] Name [%s] is not exits \r\n",temp_value[dwData].ucNamespace,temp_value[dwData].ucName); - } - - return ; -} -/********************************************************************* - * Funtion Name:bk_erase_all_test - * - * Funtion Discription:Erase all Matter Flash data - * - * - * - * - * Date:2021-12-22 - *******************************************************************/ -void bk_erase_all_test(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv) -{ - uint32_t dwRtn = 0; - - dwRtn = bk_erase_all(BK_PARTITION_MATTER_FLASH); - - if (kNoErr ==dwRtn) - { - bk_printf("bk_erase_all_test succeed \r\n"); - } - else - { - bk_printf("bk_erase_all_test fialed \r\n"); - } - - return ; -} - -#endif -#if 0 -extern struct wpa_supplicant *wpa_suppliant_ctrl_get_wpas(); -/********************************************************************* - * Funtion Name:bk_wifi_info_read - * - * Funtion Discription:read wifi data from flash - * - * - * - * - * Date:2021-12-22 - *******************************************************************/ -uint32_t wpa_ssid_key_get(ssid_key_save_t *wpas_get) -{ - struct wpa_supplicant *wpa_s = NULL; - - if(wpas_get == NULL) - { - bk_printf("%s %d the pointer is null \r\n",__FUNCTION__,__LINE__); - return 1; - } - - wpa_s = wpa_suppliant_ctrl_get_wpas(); - memcpy((char*)wpas_get->ucssid, wpa_s->current_ssid->ssid, wpa_s->current_ssid->ssid_len); - strcpy((char*)wpas_get->ucKey, wpa_s->current_ssid->passphrase); - return 0; -} -#endif diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/matter/flash_namespace_value.h b/bk7235/liteos_m/bk_sdk_armino/middleware/compal/matter/flash_namespace_value.h deleted file mode 100755 index 19e99fd7f015f91f1b906e4ecf9df2a88a0610b8..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/matter/flash_namespace_value.h +++ /dev/null @@ -1,179 +0,0 @@ -#ifndef __FLASH_NAMESAPCE_VALUE__ -#define __FLASH_NAMESAPCE_VALUE__ - -#ifdef __cplusplus -extern"C" { -#endif -#if CONFIG_FLASH_ORIGIN_API -#include "BkDriverFlash.h" -#else -#include -#endif -#if 0 -#define bk_flash_debug_printf(...) bk_printf(__VA_ARGS__) -#else -#define bk_flash_debug_printf(...) -#endif - -typedef struct namespace_flash -{ - uint32_t dwUsingFlag;//FLASH_SPACE_USING or FLASH_SPACE_UNUSED - uint32_t dwOffsetByByte; - char ucNamespace[56];//The maximum length of the string in namaspace -}namespace_flash_t; - -typedef struct name_flash -{ - uint32_t dwUsingFlag;//FLASH_SPACE_USING or FLASH_SPACE_UNUSED - uint32_t dwOffsetByByte; - uint32_t dwlength;//By Size - char ucName[52];//The maximum length of the string in namaspace -}name_flash_t; - - -typedef struct name_flash_test -{ - char ucNamespace[56];//The maximum length of the string in namaspace - char ucName[52];//The maximum length of the string in namaspace - char ucData[112];//The maximum length of the string in namaspace - uint32_t dwDatalen;//数据的实际长度 -}name_flash_test_t; - - -typedef struct ssid_key_save -{ - char ucssid[33]; - char ucKey[64]; -}ssid_key_save_t; - -/** - * OTA firmware encryption algorithm and compression algorithm - */ -enum rt_ota_algo -{ - RT_OTA_CRYPT_ALGO_NONE = 0x0L, /**< no encryption algorithm and no compression algorithm */ - RT_OTA_CRYPT_ALGO_XOR = 0x1L, /**< XOR encryption */ - RT_OTA_CRYPT_ALGO_AES256 = 0x2L, /**< AES256 encryption */ - RT_OTA_CMPRS_ALGO_GZIP = 0x1L << 8, /**< Gzip: zh.wikipedia.org/wiki/Gzip */ - RT_OTA_CMPRS_ALGO_QUICKLZ = 0x2L << 8, /**< QuickLZ: www.quicklz.com */ - RT_OTA_CMPRS_ALGO_FASTLZ = 0x3L << 8, /**< FastLZ: fastlz.org/ */ - - RT_OTA_CRYPT_STAT_MASK = 0xFL, - RT_OTA_CMPRS_STAT_MASK = 0xFL << 8, -}; -typedef enum rt_ota_algo rt_ota_algo_t; - - -typedef struct ota_data_struct -{ - char magic[4]; - - rt_ota_algo_t algo; - uint32_t timestamp; - char name[16]; - char version[24]; - - char sn[24]; - - /* crc32(aes(zip(rtt.bin))) */ - uint32_t crc32; - /* hash(rtt.bin) */ - uint32_t hash; - - /* len(rtt.bin) */ - uint32_t size_raw; - /* len(aes(zip(rtt.bin))) */ - uint32_t size_package; - - /* crc32(rbl_hdr - info_crc32) */ - uint32_t info_crc32; - -}ota_data_struct_t; - - - -#define BK_CHECK_POINTER_NULL(pointer) \ -do{ \ - if(NULL == pointer) \ - {\ - bk_printf("[%s] [%d] pointer is null \r\n", __FUNCTION__,__LINE__);\ - return kGeneralErr;\ - }\ - }while(0) - -#define BK_CHECK_POINTER_NULL_TO_VOID(pointer) \ - do{ \ - if(NULL == pointer) \ - {\ - bk_printf("[%s] [%d] pointer is null \r\n", __FUNCTION__,__LINE__);\ - return ;\ - }\ - }while(0) - -#define BK_CHECK_RETURN_VAULEL(dwRtn) \ -do{ \ - if(kNoErr != dwRtn) \ - {\ - bk_printf("[%s] [%d] return value is [%u] \r\n", __FUNCTION__,__LINE__,dwRtn);\ - return kGeneralErr;\ - }\ -}while(0) - -#define BK_CHECK_NO_RETURN(dwRtn) \ - do{ \ - if(kNoErr != dwRtn) \ - {\ - bk_printf("[%s] [%d] return value is [%u] \r\n", __FUNCTION__,__LINE__,dwRtn);\ - }\ - }while(0) - -#define FLASH_NAME_SPACE_MAX_ARRAY 10 -#define FLASH_NAME_MAX_ARRAY 64 -#define PER_NAME_SPACE_FLASH_SIZE sizeof(namespace_flash_t) -#define PER_NAME_FLASH_SIZE sizeof(name_flash_t) -#define NAME_SPACE_FLASH_TOTAL_SIZE (0x1000) //Do not modify this immediate number unless you understand the code -#define NAME_SPACE_FLASH_ACTUAL_USE_SIZE (sizeof(namespace_flash_t) * FLASH_NAME_SPACE_MAX_ARRAY) //Do not modify this immediate number unless you understand the code -#define NAME_FLASH_TOTAL_SIZE (sizeof(name_flash_t) * FLASH_NAME_MAX_ARRAY)//Do not modify this immediate number unless you understand the code -#define NAME_FLASH_TOTAL_HEADER (NAME_SPACE_FLASH_TOTAL_SIZE + NAME_FLASH_TOTAL_SIZE * FLASH_NAME_SPACE_MAX_ARRAY) - - -#define NAME_FLASH_DATA_BASE_ADDR ((NAME_FLASH_TOTAL_HEADER & 0xFFF) ? ((NAME_FLASH_TOTAL_HEADER & (~0xFFF)) + 0x1000) : (NAME_FLASH_TOTAL_HEADER & (~0xFFF))) - - -#define NAME_SPACE_NOT_FOUND 0 -#define NAME_SPACE_FOUND 1 -#define NAME_SPACE_ADDR_SET_SUCCESS 1 -#define NAME_SPACE_ADDR_SET_FAIL 0 -#define FLASH_SECTOR_SIZE 0x1000 //4*1024 - - -#define FLASH_SPACE_USING 0xFFFFFF55//依据flash只能写零,不能写1的原则 -#define FLASH_SPACE_MASK 0xFFFF5555 - -#define WRITE_OTA_DATA_TO_FLASH_TIMES 2 //写flash失败时的最大重复次数 - -uint32_t bk_write_data( const char * ucnamespace,const char * ucname, char * indata,uint32_t data_size); -uint32_t bk_read_data( const char * ucnamespace,const char * ucname,char * out_data,uint32_t dw_read_len,uint32_t *out_length); -uint32_t bk_clean_data ( const char * ucnamespace,const char * ucname); -uint32_t bK_clear_namespace ( const char * ucnamespace); -uint32_t bk_ensure_namespace( const char * ucnamespace); -uint32_t bk_ensure_name_data( const char * ucnamespace,const char * ucname); -uint32_t wpa_ssid_key_get(ssid_key_save_t *wpas_get); -uint32_t bk_erase_all( bk_partition_t type ); -uint32_t bk_write_ota_data_to_flash( char * indata,uint32_t data_offset_addr,uint32_t data_length); -uint32_t bk_read_ota_data_in_flash( char * outdata,uint32_t data_offset_addr,uint32_t data_length); -uint32_t bk_erase_ota_data_in_flash(); - -#if 1 -void bk_write_data_test(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv ); -void bk_read_data_test(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv); -void bk_erase_namespace_test(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv); -void bk_erase_name_test(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv); -void bk_name_data_exits(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv); -void bk_erase_all_test(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv); -#endif -#ifdef __cplusplus -} -#endif - -#endif diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/unity/.editorconfig b/bk7235/liteos_m/bk_sdk_armino/middleware/compal/unity/.editorconfig deleted file mode 100755 index 7b7a47a01d609e7eec11bb301dc4ee0c39d6e5b2..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/unity/.editorconfig +++ /dev/null @@ -1,27 +0,0 @@ -############################################################################### -# Unity Project - A Test Framework for C -# .editorconfig - F. Zahn 2019 -############################################################################### - -# This is the topmost .editorconfig file -root = true - -# Settings that apply to all languages / files -[*] -charset = utf-8 -indent_size = 4 -indent_style = space -insert_final_newline = true -trim_trailing_whitespace = true - -[*.md] -trim_trailing_whitespace = false - -[*.txt] -trim_trailing_whitespace = false - -[*.rb] -indent_size = 2 - -[*.yml] -indent_size = 2 diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/unity/.travis.yml b/bk7235/liteos_m/bk_sdk_armino/middleware/compal/unity/.travis.yml deleted file mode 100755 index 8d32264a3836df1d1baa9e0b426920c9523986e0..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/unity/.travis.yml +++ /dev/null @@ -1,29 +0,0 @@ -language: c - -matrix: - include: - - os: osx - compiler: clang - osx_image: xcode7.3 - - os: linux - dist: trusty - compiler: gcc - -before_install: - - if [ "$TRAVIS_OS_NAME" == "osx" ]; then rvm install 2.3 && rvm use 2.3 && ruby -v; fi - - if [ "$TRAVIS_OS_NAME" == "linux" ]; then sudo apt-get install --assume-yes --quiet gcc-multilib; fi -install: - - gem install rspec - - gem install rubocop -v 0.57.2 -script: - - cd test && rake ci - - make -s - - make -s DEBUG=-m32 #32-bit architecture with 64-bit support - - make -s DEBUG=-m32 UNITY_SUPPORT_64= #32-bit build without 64-bit types - - make -s UNITY_INCLUDE_DOUBLE= # without double - - cd ../extras/fixture/test && rake ci - - make -s default noStdlibMalloc - - make -s C89 - - cd ../../../examples/example_1 && make -s ci - - cd ../example_2 && make -s ci - - cd ../example_3 && rake diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/unity/CMakeLists.txt b/bk7235/liteos_m/bk_sdk_armino/middleware/compal/unity/CMakeLists.txt deleted file mode 100755 index bf74cecc3e9b3ffe6c81a8e2081db14833c04d4f..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/unity/CMakeLists.txt +++ /dev/null @@ -1,69 +0,0 @@ -################################################################################### -# # -# NAME: CMakeLsits.txt # -# # -# AUTHOR: Mike Karlesky, Mark VanderVoord, Greg Williams. # -# WRITTEN BY: Michael Brockus. # -# # -# License: MIT # -# # -################################################################################### -cmake_minimum_required(VERSION 3.13.2.0 FATAL_ERROR) - - - -# -# CMake: Declare project -# -project(unity LANGUAGES C DESCRIPTION "C Unit testing framework.") - - - -# -# CMake: Creation of library -# -add_library("unity" STATIC) - - - -# -# CMake: Adding source to target -# -target_sources("unity" PRIVATE "src/unity.c") - - - -# -# CMake: Including directories to target -# -target_include_directories("unity" - PUBLIC - "$" - "$" - - PRIVATE "src" -) - - - -# -# CMake: Give target an alias -# -add_library("unity::framework" ALIAS "unity") - - - -# -# CMake: export project -# -install(TARGETS "unity" EXPORT "unityConfig" - ARCHIVE DESTINATION "${CMAKE_CURRENT_SOURCE_DIR}/${CMAKE_INSTALL_LIBDIR}" - LIBRARY DESTINATION "${CMAKE_CURRENT_SOURCE_DIR}/${CMAKE_INSTALL_LIBDIR}" - RUNTIME DESTINATION "${CMAKE_CURRENT_SOURCE_DIR}/${CMAKE_INSTALL_BINDIR}" - INCLUDES DESTINATION "${CMAKE_INSTALL_LIBDIR}") - -install(DIRECTORY src/ DESTINATION src) -install(EXPORT unityConfig DESTINATION share/unityConfig/cmake) - -# This makes the project importable from the build directory -export(TARGETS unity FILE unityConfig.cmake) diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/unity/LICENSE.txt b/bk7235/liteos_m/bk_sdk_armino/middleware/compal/unity/LICENSE.txt deleted file mode 100755 index d66fba53e5845843ad40ee19442894db4448dcd8..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/unity/LICENSE.txt +++ /dev/null @@ -1,21 +0,0 @@ -The MIT License (MIT) - -Copyright (c) 2007-14 Mike Karlesky, Mark VanderVoord, Greg Williams - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/unity/auto/colour_prompt.rb b/bk7235/liteos_m/bk_sdk_armino/middleware/compal/unity/auto/colour_prompt.rb deleted file mode 100755 index bf09d028d5a1bb878981136280d4d4959248d81b..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/unity/auto/colour_prompt.rb +++ /dev/null @@ -1,118 +0,0 @@ -# ========================================== -# Unity Project - A Test Framework for C -# Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams -# [Released under MIT License. Please refer to license.txt for details] -# ========================================== - -if RUBY_PLATFORM =~ /(win|w)32$/ - begin - require 'Win32API' - rescue LoadError - puts 'ERROR! "Win32API" library not found' - puts '"Win32API" is required for colour on a windows machine' - puts ' try => "gem install Win32API" on the command line' - puts - end - # puts - # puts 'Windows Environment Detected...' - # puts 'Win32API Library Found.' - # puts -end - -class ColourCommandLine - def initialize - return unless RUBY_PLATFORM =~ /(win|w)32$/ - get_std_handle = Win32API.new('kernel32', 'GetStdHandle', ['L'], 'L') - @set_console_txt_attrb = - Win32API.new('kernel32', 'SetConsoleTextAttribute', %w[L N], 'I') - @hout = get_std_handle.call(-11) - end - - def change_to(new_colour) - if RUBY_PLATFORM =~ /(win|w)32$/ - @set_console_txt_attrb.call(@hout, win32_colour(new_colour)) - else - "\033[30;#{posix_colour(new_colour)};22m" - end - end - - def win32_colour(colour) - case colour - when :black then 0 - when :dark_blue then 1 - when :dark_green then 2 - when :dark_cyan then 3 - when :dark_red then 4 - when :dark_purple then 5 - when :dark_yellow, :narrative then 6 - when :default_white, :default, :dark_white then 7 - when :silver then 8 - when :blue then 9 - when :green, :success then 10 - when :cyan, :output then 11 - when :red, :failure then 12 - when :purple then 13 - when :yellow then 14 - when :white then 15 - else - 0 - end - end - - def posix_colour(colour) - # ANSI Escape Codes - Foreground colors - # | Code | Color | - # | 39 | Default foreground color | - # | 30 | Black | - # | 31 | Red | - # | 32 | Green | - # | 33 | Yellow | - # | 34 | Blue | - # | 35 | Magenta | - # | 36 | Cyan | - # | 37 | Light gray | - # | 90 | Dark gray | - # | 91 | Light red | - # | 92 | Light green | - # | 93 | Light yellow | - # | 94 | Light blue | - # | 95 | Light magenta | - # | 96 | Light cyan | - # | 97 | White | - - case colour - when :black then 30 - when :red, :failure then 31 - when :green, :success then 32 - when :yellow then 33 - when :blue, :narrative then 34 - when :purple, :magenta then 35 - when :cyan, :output then 36 - when :white, :default_white then 37 - when :default then 39 - else - 39 - end - end - - def out_c(mode, colour, str) - case RUBY_PLATFORM - when /(win|w)32$/ - change_to(colour) - $stdout.puts str if mode == :puts - $stdout.print str if mode == :print - change_to(:default_white) - else - $stdout.puts("#{change_to(colour)}#{str}\033[0m") if mode == :puts - $stdout.print("#{change_to(colour)}#{str}\033[0m") if mode == :print - end - end -end - -def colour_puts(role, str) - ColourCommandLine.new.out_c(:puts, role, str) -end - -def colour_print(role, str) - ColourCommandLine.new.out_c(:print, role, str) -end diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/unity/auto/colour_reporter.rb b/bk7235/liteos_m/bk_sdk_armino/middleware/compal/unity/auto/colour_reporter.rb deleted file mode 100755 index 1c3bc2162703b5b6041c6f1fcb2d0030da7f6d7d..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/unity/auto/colour_reporter.rb +++ /dev/null @@ -1,39 +0,0 @@ -# ========================================== -# Unity Project - A Test Framework for C -# Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams -# [Released under MIT License. Please refer to license.txt for details] -# ========================================== - -require_relative 'colour_prompt' - -$colour_output = true - -def report(message) - if !$colour_output - $stdout.puts(message) - else - message = message.join('\n') if message.class == Array - message.each_line do |line| - line.chomp! - colour = case line - when /(?:total\s+)?tests:?\s+(\d+)\s+(?:total\s+)?failures:?\s+\d+\s+Ignored:?/i - Regexp.last_match(1).to_i.zero? ? :green : :red - when /PASS/ - :green - when /^OK$/ - :green - when /(?:FAIL|ERROR)/ - :red - when /IGNORE/ - :yellow - when /^(?:Creating|Compiling|Linking)/ - :white - else - :silver - end - colour_puts(colour, line) - end - end - $stdout.flush - $stderr.flush -end diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/unity/auto/generate_config.yml b/bk7235/liteos_m/bk_sdk_armino/middleware/compal/unity/auto/generate_config.yml deleted file mode 100755 index 4a5e47424561d6acca50fc1388e40967b9fcb3a3..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/unity/auto/generate_config.yml +++ /dev/null @@ -1,36 +0,0 @@ -#this is a sample configuration file for generate_module -#you would use it by calling generate_module with the -ygenerate_config.yml option -#files like this are useful for customizing generate_module to your environment -:generate_module: - :defaults: - #these defaults are used in place of any missing options at the command line - :path_src: ../src/ - :path_inc: ../src/ - :path_tst: ../test/ - :update_svn: true - :includes: - #use [] for no additional includes, otherwise list the includes on separate lines - :src: - - Defs.h - - Board.h - :inc: [] - :tst: - - Defs.h - - Board.h - - Exception.h - :boilerplates: - #these are inserted at the top of generated files. - #just comment out or remove if not desired. - #use %1$s where you would like the file name to appear (path/extension not included) - :src: | - //------------------------------------------- - // %1$s.c - //------------------------------------------- - :inc: | - //------------------------------------------- - // %1$s.h - //------------------------------------------- - :tst: | - //------------------------------------------- - // Test%1$s.c : Units tests for %1$s.c - //------------------------------------------- diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/unity/auto/generate_module.rb b/bk7235/liteos_m/bk_sdk_armino/middleware/compal/unity/auto/generate_module.rb deleted file mode 100755 index def5d088008033d4c8f67bf3c97e002f0bcdaa21..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/unity/auto/generate_module.rb +++ /dev/null @@ -1,307 +0,0 @@ -# ========================================== -# Unity Project - A Test Framework for C -# Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams -# [Released under MIT License. Please refer to license.txt for details] -# ========================================== - -# This script creates all the files with start code necessary for a new module. -# A simple module only requires a source file, header file, and test file. -# Triad modules require a source, header, and test file for each triad type (like model, conductor, and hardware). - -require 'rubygems' -require 'fileutils' -require 'pathname' - -# TEMPLATE_TST -TEMPLATE_TST ||= '#include "unity.h" - -%2$s#include "%1$s.h" - -void setUp(void) -{ -} - -void tearDown(void) -{ -} - -void test_%1$s_NeedToImplement(void) -{ - TEST_IGNORE_MESSAGE("Need to Implement %1$s"); -} -'.freeze - -# TEMPLATE_SRC -TEMPLATE_SRC ||= '%2$s#include "%1$s.h" -'.freeze - -# TEMPLATE_INC -TEMPLATE_INC ||= '#ifndef %3$s_H -#define %3$s_H -%2$s - -#endif // %3$s_H -'.freeze - -class UnityModuleGenerator - ############################ - def initialize(options = nil) - @options = UnityModuleGenerator.default_options - case options - when NilClass then @options - when String then @options.merge!(UnityModuleGenerator.grab_config(options)) - when Hash then @options.merge!(options) - else raise 'If you specify arguments, it should be a filename or a hash of options' - end - - # Create default file paths if none were provided - @options[:path_src] = "#{__dir__}/../src/" if @options[:path_src].nil? - @options[:path_inc] = @options[:path_src] if @options[:path_inc].nil? - @options[:path_tst] = "#{__dir__}/../test/" if @options[:path_tst].nil? - @options[:path_src] += '/' unless @options[:path_src][-1] == 47 - @options[:path_inc] += '/' unless @options[:path_inc][-1] == 47 - @options[:path_tst] += '/' unless @options[:path_tst][-1] == 47 - - # Built in patterns - @patterns = { - 'src' => { - '' => { inc: [] } - }, - 'test' => { - '' => { inc: [] } - }, - 'dh' => { - 'Driver' => { inc: [create_filename('%1$s', 'Hardware.h')] }, - 'Hardware' => { inc: [] } - }, - 'dih' => { - 'Driver' => { inc: [create_filename('%1$s', 'Hardware.h'), create_filename('%1$s', 'Interrupt.h')] }, - 'Interrupt' => { inc: [create_filename('%1$s', 'Hardware.h')] }, - 'Hardware' => { inc: [] } - }, - 'mch' => { - 'Model' => { inc: [] }, - 'Conductor' => { inc: [create_filename('%1$s', 'Model.h'), create_filename('%1$s', 'Hardware.h')] }, - 'Hardware' => { inc: [] } - }, - 'mvp' => { - 'Model' => { inc: [] }, - 'Presenter' => { inc: [create_filename('%1$s', 'Model.h'), create_filename('%1$s', 'View.h')] }, - 'View' => { inc: [] } - } - } - end - - ############################ - def self.default_options - { - pattern: 'src', - includes: { - src: [], - inc: [], - tst: [] - }, - update_svn: false, - boilerplates: {}, - test_prefix: 'Test', - mock_prefix: 'Mock' - } - end - - ############################ - def self.grab_config(config_file) - options = default_options - unless config_file.nil? || config_file.empty? - require 'yaml' - yaml_guts = YAML.load_file(config_file) - options.merge!(yaml_guts[:unity] || yaml_guts[:cmock]) - raise "No :unity or :cmock section found in #{config_file}" unless options - end - options - end - - ############################ - def files_to_operate_on(module_name, pattern = nil) - # strip any leading path information from the module name and save for later - subfolder = File.dirname(module_name) - module_name = File.basename(module_name) - - # create triad definition - prefix = @options[:test_prefix] || 'Test' - triad = [{ ext: '.c', path: @options[:path_src], prefix: '', template: TEMPLATE_SRC, inc: :src, boilerplate: @options[:boilerplates][:src] }, - { ext: '.h', path: @options[:path_inc], prefix: '', template: TEMPLATE_INC, inc: :inc, boilerplate: @options[:boilerplates][:inc] }, - { ext: '.c', path: @options[:path_tst], prefix: prefix, template: TEMPLATE_TST, inc: :tst, boilerplate: @options[:boilerplates][:tst] }] - - # prepare the pattern for use - pattern = (pattern || @options[:pattern] || 'src').downcase - patterns = @patterns[pattern] - raise "ERROR: The design pattern '#{pattern}' specified isn't one that I recognize!" if patterns.nil? - - # single file patterns (currently just 'test') can reject the other parts of the triad - triad.select! { |v| v[:inc] == :tst } if pattern == 'test' - - # Assemble the path/names of the files we need to work with. - files = [] - triad.each do |cfg| - patterns.each_pair do |pattern_file, pattern_traits| - submodule_name = create_filename(module_name, pattern_file) - filename = cfg[:prefix] + submodule_name + cfg[:ext] - files << { - path: (Pathname.new("#{cfg[:path]}#{subfolder}") + filename).cleanpath, - name: submodule_name, - template: cfg[:template], - boilerplate: cfg[:boilerplate], - includes: case (cfg[:inc]) - when :src then (@options[:includes][:src] || []) | (pattern_traits[:inc].map { |f| format(f, module_name) }) - when :inc then (@options[:includes][:inc] || []) - when :tst then (@options[:includes][:tst] || []) | (pattern_traits[:inc].map { |f| format("#{@options[:mock_prefix]}#{f}", module_name) }) - end - } - end - end - - files - end - - ############################ - def create_filename(part1, part2 = '') - if part2.empty? - case (@options[:naming]) - when 'bumpy' then part1 - when 'camel' then part1 - when 'snake' then part1.downcase - when 'caps' then part1.upcase - else part1 - end - else - case (@options[:naming]) - when 'bumpy' then part1 + part2 - when 'camel' then part1 + part2 - when 'snake' then part1.downcase + '_' + part2.downcase - when 'caps' then part1.upcase + '_' + part2.upcase - else part1 + '_' + part2 - end - end - end - - ############################ - def generate(module_name, pattern = nil) - files = files_to_operate_on(module_name, pattern) - - # Abort if all of the module files already exist - all_files_exist = true - files.each do |file| - all_files_exist = false unless File.exist?(file[:path]) - end - raise "ERROR: File #{files[0][:name]} already exists. Exiting." if all_files_exist - - # Create Source Modules - files.each_with_index do |file, _i| - # If this file already exists, don't overwrite it. - if File.exist?(file[:path]) - puts "File #{file[:path]} already exists!" - next - end - # Create the path first if necessary. - FileUtils.mkdir_p(File.dirname(file[:path]), verbose: false) - File.open(file[:path], 'w') do |f| - f.write("#{file[:boilerplate]}\n" % [file[:name]]) unless file[:boilerplate].nil? - f.write(file[:template] % [file[:name], - file[:includes].map { |ff| "#include \"#{ff}\"\n" }.join, - file[:name].upcase]) - end - if @options[:update_svn] - `svn add \"#{file[:path]}\"` - if $!.exitstatus.zero? - puts "File #{file[:path]} created and added to source control" - else - puts "File #{file[:path]} created but FAILED adding to source control!" - end - else - puts "File #{file[:path]} created" - end - end - puts 'Generate Complete' - end - - ############################ - def destroy(module_name, pattern = nil) - files_to_operate_on(module_name, pattern).each do |filespec| - file = filespec[:path] - if File.exist?(file) - if @options[:update_svn] - `svn delete \"#{file}\" --force` - puts "File #{file} deleted and removed from source control" - else - FileUtils.remove(file) - puts "File #{file} deleted" - end - else - puts "File #{file} does not exist so cannot be removed." - end - end - puts 'Destroy Complete' - end -end - -############################ -# Handle As Command Line If Called That Way -if $0 == __FILE__ - destroy = false - options = {} - module_name = nil - - # Parse the command line parameters. - ARGV.each do |arg| - case arg - when /^-d/ then destroy = true - when /^-u/ then options[:update_svn] = true - when /^-p\"?(\w+)\"?/ then options[:pattern] = Regexp.last_match(1) - when /^-s\"?(.+)\"?/ then options[:path_src] = Regexp.last_match(1) - when /^-i\"?(.+)\"?/ then options[:path_inc] = Regexp.last_match(1) - when /^-t\"?(.+)\"?/ then options[:path_tst] = Regexp.last_match(1) - when /^-n\"?(.+)\"?/ then options[:naming] = Regexp.last_match(1) - when /^-y\"?(.+)\"?/ then options = UnityModuleGenerator.grab_config(Regexp.last_match(1)) - when /^(\w+)/ - raise "ERROR: You can't have more than one Module name specified!" unless module_name.nil? - module_name = arg - when /^-(h|-help)/ - ARGV = [].freeze - else - raise "ERROR: Unknown option specified '#{arg}'" - end - end - - unless ARGV[0] - puts ["\nGENERATE MODULE\n-------- ------", - "\nUsage: ruby generate_module [options] module_name", - " -i\"include\" sets the path to output headers to 'include' (DEFAULT ../src)", - " -s\"../src\" sets the path to output source to '../src' (DEFAULT ../src)", - " -t\"C:/test\" sets the path to output source to 'C:/test' (DEFAULT ../test)", - ' -p"MCH" sets the output pattern to MCH.', - ' dh - driver hardware.', - ' dih - driver interrupt hardware.', - ' mch - model conductor hardware.', - ' mvp - model view presenter.', - ' src - just a source module, header and test. (DEFAULT)', - ' test - just a test file.', - ' -d destroy module instead of creating it.', - ' -n"camel" sets the file naming convention.', - ' bumpy - BumpyCaseFilenames.', - ' camel - camelCaseFilenames.', - ' snake - snake_case_filenames.', - ' caps - CAPS_CASE_FILENAMES.', - ' -u update subversion too (requires subversion command line)', - ' -y"my.yml" selects a different yaml config file for module generation', - ''].join("\n") - exit - end - - raise 'ERROR: You must have a Module name specified! (use option -h for help)' if module_name.nil? - if destroy - UnityModuleGenerator.new(options).destroy(module_name) - else - UnityModuleGenerator.new(options).generate(module_name) - end - -end diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/unity/auto/generate_test_runner.rb b/bk7235/liteos_m/bk_sdk_armino/middleware/compal/unity/auto/generate_test_runner.rb deleted file mode 100755 index 6dc90e0558bdac9ee6cb0c8062d5cecb6a11a132..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/unity/auto/generate_test_runner.rb +++ /dev/null @@ -1,472 +0,0 @@ -# ========================================== -# Unity Project - A Test Framework for C -# Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams -# [Released under MIT License. Please refer to license.txt for details] -# ========================================== - -class UnityTestRunnerGenerator - def initialize(options = nil) - @options = UnityTestRunnerGenerator.default_options - case options - when NilClass then @options - when String then @options.merge!(UnityTestRunnerGenerator.grab_config(options)) - when Hash then @options.merge!(options) - else raise 'If you specify arguments, it should be a filename or a hash of options' - end - require_relative 'type_sanitizer' - end - - def self.default_options - { - includes: [], - defines: [], - plugins: [], - framework: :unity, - test_prefix: 'test|spec|should', - mock_prefix: 'Mock', - mock_suffix: '', - setup_name: 'setUp', - teardown_name: 'tearDown', - test_reset_name: 'resetTest', - main_name: 'main', # set to :auto to automatically generate each time - main_export_decl: '', - cmdline_args: false, - use_param_tests: false - } - end - - def self.grab_config(config_file) - options = default_options - unless config_file.nil? || config_file.empty? - require 'yaml' - yaml_guts = YAML.load_file(config_file) - options.merge!(yaml_guts[:unity] || yaml_guts[:cmock]) - raise "No :unity or :cmock section found in #{config_file}" unless options - end - options - end - - def run(input_file, output_file, options = nil) - @options.merge!(options) unless options.nil? - - # pull required data from source file - source = File.read(input_file) - source = source.force_encoding('ISO-8859-1').encode('utf-8', replace: nil) - tests = find_tests(source) - headers = find_includes(source) - testfile_includes = (headers[:local] + headers[:system]) - used_mocks = find_mocks(testfile_includes) - testfile_includes = (testfile_includes - used_mocks) - testfile_includes.delete_if { |inc| inc =~ /(unity|cmock)/ } - - # build runner file - generate(input_file, output_file, tests, used_mocks, testfile_includes) - - # determine which files were used to return them - all_files_used = [input_file, output_file] - all_files_used += testfile_includes.map { |filename| filename + '.c' } unless testfile_includes.empty? - all_files_used += @options[:includes] unless @options[:includes].empty? - all_files_used += headers[:linkonly] unless headers[:linkonly].empty? - all_files_used.uniq - end - - def generate(input_file, output_file, tests, used_mocks, testfile_includes) - File.open(output_file, 'w') do |output| - create_header(output, used_mocks, testfile_includes) - create_externs(output, tests, used_mocks) - create_mock_management(output, used_mocks) - create_suite_setup(output) - create_suite_teardown(output) - create_reset(output, used_mocks) - create_main(output, input_file, tests, used_mocks) - end - - return unless @options[:header_file] && !@options[:header_file].empty? - - File.open(@options[:header_file], 'w') do |output| - create_h_file(output, @options[:header_file], tests, testfile_includes, used_mocks) - end - end - - def find_tests(source) - tests_and_line_numbers = [] - - # contains characters which will be substituted from within strings, doing - # this prevents these characters from interferring with scrubbers - # @ is not a valid C character, so there should be no clashes with files genuinely containing these markers - substring_subs = { '{' => '@co@', '}' => '@cc@', ';' => '@ss@', '/' => '@fs@' } - substring_re = Regexp.union(substring_subs.keys) - substring_unsubs = substring_subs.invert # the inverse map will be used to fix the strings afterwords - substring_unsubs['@quote@'] = '\\"' - substring_unsubs['@apos@'] = '\\\'' - substring_unre = Regexp.union(substring_unsubs.keys) - source_scrubbed = source.clone - source_scrubbed = source_scrubbed.gsub(/\\"/, '@quote@') # hide escaped quotes to allow capture of the full string/char - source_scrubbed = source_scrubbed.gsub(/\\'/, '@apos@') # hide escaped apostrophes to allow capture of the full string/char - source_scrubbed = source_scrubbed.gsub(/("[^"\n]*")|('[^'\n]*')/) { |s| s.gsub(substring_re, substring_subs) } # temporarily hide problematic characters within strings - source_scrubbed = source_scrubbed.gsub(/\/\/(?:.+\/\*|\*(?:$|[^\/])).*$/, '') # remove line comments that comment out the start of blocks - source_scrubbed = source_scrubbed.gsub(/\/\*.*?\*\//m, '') # remove block comments - source_scrubbed = source_scrubbed.gsub(/\/\/.*$/, '') # remove line comments (all that remain) - lines = source_scrubbed.split(/(^\s*\#.*$) | (;|\{|\}) /x) # Treat preprocessor directives as a logical line. Match ;, {, and } as end of lines - .map { |line| line.gsub(substring_unre, substring_unsubs) } # unhide the problematic characters previously removed - - lines.each_with_index do |line, _index| - # find tests - next unless line =~ /^((?:\s*TEST_CASE\s*\(.*?\)\s*)*)\s*void\s+((?:#{@options[:test_prefix]}).*)\s*\(\s*(.*)\s*\)/m - arguments = Regexp.last_match(1) - name = Regexp.last_match(2) - call = Regexp.last_match(3) - params = Regexp.last_match(4) - args = nil - if @options[:use_param_tests] && !arguments.empty? - args = [] - arguments.scan(/\s*TEST_CASE\s*\((.*)\)\s*$/) { |a| args << a[0] } - end - tests_and_line_numbers << { test: name, args: args, call: call, params: params, line_number: 0 } - end - tests_and_line_numbers.uniq! { |v| v[:test] } - - # determine line numbers and create tests to run - source_lines = source.split("\n") - source_index = 0 - tests_and_line_numbers.size.times do |i| - source_lines[source_index..-1].each_with_index do |line, index| - next unless line =~ /\s+#{tests_and_line_numbers[i][:test]}(?:\s|\()/ - source_index += index - tests_and_line_numbers[i][:line_number] = source_index + 1 - break - end - end - - tests_and_line_numbers - end - - def find_includes(source) - # remove comments (block and line, in three steps to ensure correct precedence) - source.gsub!(/\/\/(?:.+\/\*|\*(?:$|[^\/])).*$/, '') # remove line comments that comment out the start of blocks - source.gsub!(/\/\*.*?\*\//m, '') # remove block comments - source.gsub!(/\/\/.*$/, '') # remove line comments (all that remain) - - # parse out includes - includes = { - local: source.scan(/^\s*#include\s+\"\s*(.+)\.[hH]\s*\"/).flatten, - system: source.scan(/^\s*#include\s+<\s*(.+)\s*>/).flatten.map { |inc| "<#{inc}>" }, - linkonly: source.scan(/^TEST_FILE\(\s*\"\s*(.+)\.[cC]\w*\s*\"/).flatten - } - includes - end - - def find_mocks(includes) - mock_headers = [] - includes.each do |include_path| - include_file = File.basename(include_path) - mock_headers << include_path if include_file =~ /^#{@options[:mock_prefix]}.*#{@options[:mock_suffix]}$/i - end - mock_headers - end - - def create_header(output, mocks, testfile_includes = []) - output.puts('/* AUTOGENERATED FILE. DO NOT EDIT. */') - create_runtest(output, mocks) - output.puts("\n/*=======Automagically Detected Files To Include=====*/") - output.puts('#define UNITY_INCLUDE_SETUP_STUBS') if @options[:suite_setup].nil? - output.puts("#include \"#{@options[:framework]}.h\"") - output.puts('#include "cmock.h"') unless mocks.empty? - output.puts('#ifndef UNITY_EXCLUDE_SETJMP_H') - output.puts('#include ') - output.puts('#endif') - output.puts('#include ') - if @options[:defines] && !@options[:defines].empty? - @options[:defines].each { |d| output.puts("#ifndef #{d}\n#define #{d}\n#endif /* #{d} */") } - end - if @options[:header_file] && !@options[:header_file].empty? - output.puts("#include \"#{File.basename(@options[:header_file])}\"") - else - @options[:includes].flatten.uniq.compact.each do |inc| - output.puts("#include #{inc.include?('<') ? inc : "\"#{inc.gsub('.h', '')}.h\""}") - end - testfile_includes.each do |inc| - output.puts("#include #{inc.include?('<') ? inc : "\"#{inc.gsub('.h', '')}.h\""}") - end - end - mocks.each do |mock| - output.puts("#include \"#{mock.gsub('.h', '')}.h\"") - end - output.puts('#include "CException.h"') if @options[:plugins].include?(:cexception) - - return unless @options[:enforce_strict_ordering] - - output.puts('') - output.puts('int GlobalExpectCount;') - output.puts('int GlobalVerifyOrder;') - output.puts('char* GlobalOrderError;') - end - - def create_externs(output, tests, _mocks) - output.puts("\n/*=======External Functions This Runner Calls=====*/") - output.puts("extern void #{@options[:setup_name]}(void);") - output.puts("extern void #{@options[:teardown_name]}(void);") - output.puts("\n#ifdef __cplusplus\nextern \"C\"\n{\n#endif") if @options[:externc] - tests.each do |test| - output.puts("extern void #{test[:test]}(#{test[:call] || 'void'});") - end - output.puts("#ifdef __cplusplus\n}\n#endif") if @options[:externc] - output.puts('') - end - - def create_mock_management(output, mock_headers) - return if mock_headers.empty? - - output.puts("\n/*=======Mock Management=====*/") - output.puts('static void CMock_Init(void)') - output.puts('{') - - if @options[:enforce_strict_ordering] - output.puts(' GlobalExpectCount = 0;') - output.puts(' GlobalVerifyOrder = 0;') - output.puts(' GlobalOrderError = NULL;') - end - - mocks = mock_headers.map { |mock| File.basename(mock) } - mocks.each do |mock| - mock_clean = TypeSanitizer.sanitize_c_identifier(mock) - output.puts(" #{mock_clean}_Init();") - end - output.puts("}\n") - - output.puts('static void CMock_Verify(void)') - output.puts('{') - mocks.each do |mock| - mock_clean = TypeSanitizer.sanitize_c_identifier(mock) - output.puts(" #{mock_clean}_Verify();") - end - output.puts("}\n") - - output.puts('static void CMock_Destroy(void)') - output.puts('{') - mocks.each do |mock| - mock_clean = TypeSanitizer.sanitize_c_identifier(mock) - output.puts(" #{mock_clean}_Destroy();") - end - output.puts("}\n") - end - - def create_suite_setup(output) - output.puts("\n/*=======Suite Setup=====*/") - output.puts('static void suite_setup(void)') - output.puts('{') - if @options[:suite_setup].nil? - # New style, call suiteSetUp() if we can use weak symbols - output.puts('#if defined(UNITY_WEAK_ATTRIBUTE) || defined(UNITY_WEAK_PRAGMA)') - output.puts(' suiteSetUp();') - output.puts('#endif') - else - # Old style, C code embedded in the :suite_setup option - output.puts(@options[:suite_setup]) - end - output.puts('}') - end - - def create_suite_teardown(output) - output.puts("\n/*=======Suite Teardown=====*/") - output.puts('static int suite_teardown(int num_failures)') - output.puts('{') - if @options[:suite_teardown].nil? - # New style, call suiteTearDown() if we can use weak symbols - output.puts('#if defined(UNITY_WEAK_ATTRIBUTE) || defined(UNITY_WEAK_PRAGMA)') - output.puts(' return suiteTearDown(num_failures);') - output.puts('#else') - output.puts(' return num_failures;') - output.puts('#endif') - else - # Old style, C code embedded in the :suite_teardown option - output.puts(@options[:suite_teardown]) - end - output.puts('}') - end - - def create_runtest(output, used_mocks) - cexception = @options[:plugins].include? :cexception - va_args1 = @options[:use_param_tests] ? ', ...' : '' - va_args2 = @options[:use_param_tests] ? '__VA_ARGS__' : '' - output.puts("\n/*=======Test Runner Used To Run Each Test Below=====*/") - output.puts('#define RUN_TEST_NO_ARGS') if @options[:use_param_tests] - output.puts("#define RUN_TEST(TestFunc, TestLineNum#{va_args1}) \\") - output.puts('{ \\') - output.puts(" Unity.CurrentTestName = #TestFunc#{va_args2.empty? ? '' : " \"(\" ##{va_args2} \")\""}; \\") - output.puts(' Unity.CurrentTestLineNumber = TestLineNum; \\') - output.puts(' if (UnityTestMatches()) { \\') if @options[:cmdline_args] - output.puts(' Unity.NumberOfTests++; \\') - output.puts(' UNITY_EXEC_TIME_START(); \\') - output.puts(' CMock_Init(); \\') unless used_mocks.empty? - output.puts(' UNITY_CLR_DETAILS(); \\') unless used_mocks.empty? - output.puts(' if (TEST_PROTECT()) \\') - output.puts(' { \\') - output.puts(' CEXCEPTION_T e; \\') if cexception - output.puts(' Try { \\') if cexception - output.puts(" #{@options[:setup_name]}(); \\") - output.puts(" TestFunc(#{va_args2}); \\") - output.puts(' } Catch(e) { TEST_ASSERT_EQUAL_HEX32_MESSAGE(CEXCEPTION_NONE, e, "Unhandled Exception!"); } \\') if cexception - output.puts(' } \\') - output.puts(' if (TEST_PROTECT()) \\') - output.puts(' { \\') - output.puts(" #{@options[:teardown_name]}(); \\") - output.puts(' CMock_Verify(); \\') unless used_mocks.empty? - output.puts(' } \\') - output.puts(' CMock_Destroy(); \\') unless used_mocks.empty? - output.puts(' UNITY_EXEC_TIME_STOP(); \\') - output.puts(' UnityConcludeTest(); \\') - output.puts(' } \\') if @options[:cmdline_args] - output.puts("}\n") - end - - def create_reset(output, used_mocks) - output.puts("\n/*=======Test Reset Option=====*/") - output.puts("void #{@options[:test_reset_name]}(void);") - output.puts("void #{@options[:test_reset_name]}(void)") - output.puts('{') - output.puts(' CMock_Verify();') unless used_mocks.empty? - output.puts(' CMock_Destroy();') unless used_mocks.empty? - output.puts(" #{@options[:teardown_name]}();") - output.puts(' CMock_Init();') unless used_mocks.empty? - output.puts(" #{@options[:setup_name]}();") - output.puts('}') - end - - def create_main(output, filename, tests, used_mocks) - output.puts("\n\n/*=======MAIN=====*/") - main_name = @options[:main_name].to_sym == :auto ? "main_#{filename.gsub('.c', '')}" : (@options[:main_name]).to_s - if @options[:cmdline_args] - if main_name != 'main' - output.puts("#{@options[:main_export_decl]} int #{main_name}(int argc, char** argv);") - end - output.puts("#{@options[:main_export_decl]} int #{main_name}(int argc, char** argv)") - output.puts('{') - output.puts(' int parse_status = UnityParseOptions(argc, argv);') - output.puts(' if (parse_status != 0)') - output.puts(' {') - output.puts(' if (parse_status < 0)') - output.puts(' {') - output.puts(" UnityPrint(\"#{filename.gsub('.c', '')}.\");") - output.puts(' UNITY_PRINT_EOL();') - if @options[:use_param_tests] - tests.each do |test| - if test[:args].nil? || test[:args].empty? - output.puts(" UnityPrint(\" #{test[:test]}(RUN_TEST_NO_ARGS)\");") - output.puts(' UNITY_PRINT_EOL();') - else - test[:args].each do |args| - output.puts(" UnityPrint(\" #{test[:test]}(#{args})\");") - output.puts(' UNITY_PRINT_EOL();') - end - end - end - else - tests.each { |test| output.puts(" UnityPrint(\" #{test[:test]}\");\n UNITY_PRINT_EOL();") } - end - output.puts(' return 0;') - output.puts(' }') - output.puts(' return parse_status;') - output.puts(' }') - else - if main_name != 'main' - output.puts("#{@options[:main_export_decl]} int #{main_name}(void);") - end - output.puts("int #{main_name}(void)") - output.puts('{') - end - output.puts(' suite_setup();') - output.puts(" UnityBegin(\"#{filename.gsub(/\\/, '\\\\\\')}\");") - if @options[:use_param_tests] - tests.each do |test| - if test[:args].nil? || test[:args].empty? - output.puts(" RUN_TEST(#{test[:test]}, #{test[:line_number]}, RUN_TEST_NO_ARGS);") - else - test[:args].each { |args| output.puts(" RUN_TEST(#{test[:test]}, #{test[:line_number]}, #{args});") } - end - end - else - tests.each { |test| output.puts(" RUN_TEST(#{test[:test]}, #{test[:line_number]});") } - end - output.puts - output.puts(' CMock_Guts_MemFreeFinal();') unless used_mocks.empty? - output.puts(' return suite_teardown(UnityEnd());') - output.puts('}') - end - - def create_h_file(output, filename, tests, testfile_includes, used_mocks) - filename = File.basename(filename).gsub(/[-\/\\\.\,\s]/, '_').upcase - output.puts('/* AUTOGENERATED FILE. DO NOT EDIT. */') - output.puts("#ifndef _#{filename}") - output.puts("#define _#{filename}\n\n") - output.puts("#include \"#{@options[:framework]}.h\"") - output.puts('#include "cmock.h"') unless used_mocks.empty? - @options[:includes].flatten.uniq.compact.each do |inc| - output.puts("#include #{inc.include?('<') ? inc : "\"#{inc.gsub('.h', '')}.h\""}") - end - testfile_includes.each do |inc| - output.puts("#include #{inc.include?('<') ? inc : "\"#{inc.gsub('.h', '')}.h\""}") - end - output.puts "\n" - tests.each do |test| - if test[:params].nil? || test[:params].empty? - output.puts("void #{test[:test]}(void);") - else - output.puts("void #{test[:test]}(#{test[:params]});") - end - end - output.puts("#endif\n\n") - end -end - -if $0 == __FILE__ - options = { includes: [] } - - # parse out all the options first (these will all be removed as we go) - ARGV.reject! do |arg| - case arg - when '-cexception' - options[:plugins] = [:cexception] - true - when /\.*\.ya?ml/ - options = UnityTestRunnerGenerator.grab_config(arg) - true - when /--(\w+)=\"?(.*)\"?/ - options[Regexp.last_match(1).to_sym] = Regexp.last_match(2) - true - when /\.*\.h/ - options[:includes] << arg - true - else false - end - end - - # make sure there is at least one parameter left (the input file) - unless ARGV[0] - puts ["\nusage: ruby #{__FILE__} (files) (options) input_test_file (output)", - "\n input_test_file - this is the C file you want to create a runner for", - ' output - this is the name of the runner file to generate', - ' defaults to (input_test_file)_Runner', - ' files:', - ' *.yml / *.yaml - loads configuration from here in :unity or :cmock', - ' *.h - header files are added as #includes in runner', - ' options:', - ' -cexception - include cexception support', - ' -externc - add extern "C" for cpp support', - ' --setup_name="" - redefine setUp func name to something else', - ' --teardown_name="" - redefine tearDown func name to something else', - ' --main_name="" - redefine main func name to something else', - ' --test_prefix="" - redefine test prefix from default test|spec|should', - ' --test_reset_name="" - redefine resetTest func name to something else', - ' --suite_setup="" - code to execute for setup of entire suite', - ' --suite_teardown="" - code to execute for teardown of entire suite', - ' --use_param_tests=1 - enable parameterized tests (disabled by default)', - ' --header_file="" - path/name of test header file to generate too'].join("\n") - exit 1 - end - - # create the default test runner name if not specified - ARGV[1] = ARGV[0].gsub('.c', '_Runner.c') unless ARGV[1] - - UnityTestRunnerGenerator.new(options).run(ARGV[0], ARGV[1]) -end diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/unity/auto/parse_output.rb b/bk7235/liteos_m/bk_sdk_armino/middleware/compal/unity/auto/parse_output.rb deleted file mode 100755 index fa07b7dbecea6b4e67464a684cac5ec80b79c406..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/unity/auto/parse_output.rb +++ /dev/null @@ -1,322 +0,0 @@ -#============================================================ -# Author: John Theofanopoulos -# A simple parser. Takes the output files generated during the -# build process and extracts information relating to the tests. -# -# Notes: -# To capture an output file under VS builds use the following: -# devenv [build instructions] > Output.txt & type Output.txt -# -# To capture an output file under Linux builds use the following: -# make | tee Output.txt -# -# This script can handle the following output formats: -# - normal output (raw unity) -# - fixture output (unity_fixture.h/.c) -# - fixture output with verbose flag set ("-v") -# -# To use this parser use the following command -# ruby parseOutput.rb [options] [file] -# options: -xml : produce a JUnit compatible XML file -# file: file to scan for results -#============================================================ - -# Parser class for handling the input file -class ParseOutput - def initialize - # internal data - @class_name_idx = 0 - @path_delim = nil - - # xml output related - @xml_out = false - @array_list = false - - # current suite name and statistics - @test_suite = nil - @total_tests = 0 - @test_passed = 0 - @test_failed = 0 - @test_ignored = 0 - end - - # Set the flag to indicate if there will be an XML output file or not - def set_xml_output - @xml_out = true - end - - # If write our output to XML - def write_xml_output - output = File.open('report.xml', 'w') - output << "\n" - @array_list.each do |item| - output << item << "\n" - end - end - - # Pushes the suite info as xml to the array list, which will be written later - def push_xml_output_suite_info - # Insert opening tag at front - heading = '' - @array_list.insert(0, heading) - # Push back the closing tag - @array_list.push '' - end - - # Pushes xml output data to the array list, which will be written later - def push_xml_output_passed(test_name) - @array_list.push ' ' - end - - # Pushes xml output data to the array list, which will be written later - def push_xml_output_failed(test_name, reason) - @array_list.push ' ' - @array_list.push ' ' + reason + '' - @array_list.push ' ' - end - - # Pushes xml output data to the array list, which will be written later - def push_xml_output_ignored(test_name, reason) - @array_list.push ' ' - @array_list.push ' ' + reason + '' - @array_list.push ' ' - end - - # This function will try and determine when the suite is changed. This is - # is the name that gets added to the classname parameter. - def test_suite_verify(test_suite_name) - # Split the path name - test_name = test_suite_name.split(@path_delim) - - # Remove the extension and extract the base_name - base_name = test_name[test_name.size - 1].split('.')[0] - - # Return if the test suite hasn't changed - return unless base_name.to_s != @test_suite.to_s - - @test_suite = base_name - printf "New Test: %s\n", @test_suite - end - - # Prepares the line for verbose fixture output ("-v") - def prepare_fixture_line(line) - line = line.sub('IGNORE_TEST(', '') - line = line.sub('TEST(', '') - line = line.sub(')', ',') - line = line.chomp - array = line.split(',') - array.map { |x| x.to_s.lstrip.chomp } - end - - # Test was flagged as having passed so format the output. - # This is using the Unity fixture output and not the original Unity output. - def test_passed_unity_fixture(array) - class_name = array[0] - test_name = array[1] - test_suite_verify(class_name) - printf "%-40s PASS\n", test_name - - push_xml_output_passed(test_name) if @xml_out - end - - # Test was flagged as having failed so format the output. - # This is using the Unity fixture output and not the original Unity output. - def test_failed_unity_fixture(array) - class_name = array[0] - test_name = array[1] - test_suite_verify(class_name) - reason_array = array[2].split(':') - reason = reason_array[-1].lstrip.chomp + ' at line: ' + reason_array[-4] - - printf "%-40s FAILED\n", test_name - - push_xml_output_failed(test_name, reason) if @xml_out - end - - # Test was flagged as being ignored so format the output. - # This is using the Unity fixture output and not the original Unity output. - def test_ignored_unity_fixture(array) - class_name = array[0] - test_name = array[1] - reason = 'No reason given' - if array.size > 2 - reason_array = array[2].split(':') - tmp_reason = reason_array[-1].lstrip.chomp - reason = tmp_reason == 'IGNORE' ? 'No reason given' : tmp_reason - end - test_suite_verify(class_name) - printf "%-40s IGNORED\n", test_name - - push_xml_output_ignored(test_name, reason) if @xml_out - end - - # Test was flagged as having passed so format the output - def test_passed(array) - last_item = array.length - 1 - test_name = array[last_item - 1] - test_suite_verify(array[@class_name_idx]) - printf "%-40s PASS\n", test_name - - return unless @xml_out - - push_xml_output_passed(test_name) if @xml_out - end - - # Test was flagged as having failed so format the line - def test_failed(array) - last_item = array.length - 1 - test_name = array[last_item - 2] - reason = array[last_item].chomp.lstrip + ' at line: ' + array[last_item - 3] - class_name = array[@class_name_idx] - - if test_name.start_with? 'TEST(' - array2 = test_name.split(' ') - - test_suite = array2[0].sub('TEST(', '') - test_suite = test_suite.sub(',', '') - class_name = test_suite - - test_name = array2[1].sub(')', '') - end - - test_suite_verify(class_name) - printf "%-40s FAILED\n", test_name - - push_xml_output_failed(test_name, reason) if @xml_out - end - - # Test was flagged as being ignored so format the output - def test_ignored(array) - last_item = array.length - 1 - test_name = array[last_item - 2] - reason = array[last_item].chomp.lstrip - class_name = array[@class_name_idx] - - if test_name.start_with? 'TEST(' - array2 = test_name.split(' ') - - test_suite = array2[0].sub('TEST(', '') - test_suite = test_suite.sub(',', '') - class_name = test_suite - - test_name = array2[1].sub(')', '') - end - - test_suite_verify(class_name) - printf "%-40s IGNORED\n", test_name - - push_xml_output_ignored(test_name, reason) if @xml_out - end - - # Adjusts the os specific members according to the current path style - # (Windows or Unix based) - def detect_os_specifics(line) - if line.include? '\\' - # Windows X:\Y\Z - @class_name_idx = 1 - @path_delim = '\\' - else - # Unix Based /X/Y/Z - @class_name_idx = 0 - @path_delim = '/' - end - end - - # Main function used to parse the file that was captured. - def process(file_name) - @array_list = [] - - puts 'Parsing file: ' + file_name - - @test_passed = 0 - @test_failed = 0 - @test_ignored = 0 - puts '' - puts '=================== RESULTS =====================' - puts '' - File.open(file_name).each do |line| - # Typical test lines look like these: - # ---------------------------------------------------- - # 1. normal output: - # /.c:36:test_tc1000_opsys:FAIL: Expected 1 Was 0 - # /.c:112:test_tc5004_initCanChannel:IGNORE: Not Yet Implemented - # /.c:115:test_tc5100_initCanVoidPtrs:PASS - # - # 2. fixture output - # /.c:63:TEST(, ):FAIL: Expected 0x00001234 Was 0x00005A5A - # /.c:36:TEST(, ):IGNORE - # Note: "PASS" information won't be generated in this mode - # - # 3. fixture output with verbose information ("-v") - # TEST()/:168::FAIL: Expected 0x8D Was 0x8C - # TEST(, )/:22::IGNORE: This Test Was Ignored On Purpose - # IGNORE_TEST() - # TEST() PASS - # - # Note: Where path is different on Unix vs Windows devices (Windows leads with a drive letter)! - detect_os_specifics(line) - line_array = line.split(':') - - # If we were able to split the line then we can look to see if any of our target words - # were found. Case is important. - next unless (line_array.size >= 4) || (line.start_with? 'TEST(') || (line.start_with? 'IGNORE_TEST(') - - # check if the output is fixture output (with verbose flag "-v") - if (line.start_with? 'TEST(') || (line.start_with? 'IGNORE_TEST(') - line_array = prepare_fixture_line(line) - if line.include? ' PASS' - test_passed_unity_fixture(line_array) - @test_passed += 1 - elsif line.include? 'FAIL' - test_failed_unity_fixture(line_array) - @test_failed += 1 - elsif line.include? 'IGNORE' - test_ignored_unity_fixture(line_array) - @test_ignored += 1 - end - # normal output / fixture output (without verbose "-v") - elsif line.include? ':PASS' - test_passed(line_array) - @test_passed += 1 - elsif line.include? ':FAIL' - test_failed(line_array) - @test_failed += 1 - elsif line.include? ':IGNORE:' - test_ignored(line_array) - @test_ignored += 1 - elsif line.include? ':IGNORE' - line_array.push('No reason given') - test_ignored(line_array) - @test_ignored += 1 - end - @total_tests = @test_passed + @test_failed + @test_ignored - end - puts '' - puts '=================== SUMMARY =====================' - puts '' - puts 'Tests Passed : ' + @test_passed.to_s - puts 'Tests Failed : ' + @test_failed.to_s - puts 'Tests Ignored : ' + @test_ignored.to_s - - return unless @xml_out - - # push information about the suite - push_xml_output_suite_info - # write xml output file - write_xml_output - end -end - -# If the command line has no values in, used a default value of Output.txt -parse_my_file = ParseOutput.new - -if ARGV.size >= 1 - ARGV.each do |arg| - if arg == '-xml' - parse_my_file.set_xml_output - else - parse_my_file.process(arg) - break - end - end -end diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/unity/auto/stylize_as_junit.rb b/bk7235/liteos_m/bk_sdk_armino/middleware/compal/unity/auto/stylize_as_junit.rb deleted file mode 100755 index a53f85f75d71829eb2225f7bf180a38f1cefeb79..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/unity/auto/stylize_as_junit.rb +++ /dev/null @@ -1,248 +0,0 @@ -#!/usr/bin/ruby -# -# unity_to_junit.rb -# -require 'fileutils' -require 'optparse' -require 'ostruct' -require 'set' - -require 'pp' - -VERSION = 1.0 - -class ArgvParser - # - # Return a structure describing the options. - # - def self.parse(args) - # The options specified on the command line will be collected in *options*. - # We set default values here. - options = OpenStruct.new - options.results_dir = '.' - options.root_path = '.' - options.out_file = 'results.xml' - - opts = OptionParser.new do |o| - o.banner = 'Usage: unity_to_junit.rb [options]' - - o.separator '' - o.separator 'Specific options:' - - o.on('-r', '--results ', 'Look for Unity Results files here.') do |results| - # puts "results #{results}" - options.results_dir = results - end - - o.on('-p', '--root_path ', 'Prepend this path to files in results.') do |root_path| - options.root_path = root_path - end - - o.on('-o', '--output ', 'XML file to generate.') do |out_file| - # puts "out_file: #{out_file}" - options.out_file = out_file - end - - o.separator '' - o.separator 'Common options:' - - # No argument, shows at tail. This will print an options summary. - o.on_tail('-h', '--help', 'Show this message') do - puts o - exit - end - - # Another typical switch to print the version. - o.on_tail('--version', 'Show version') do - puts "unity_to_junit.rb version #{VERSION}" - exit - end - end - - opts.parse!(args) - options - end -end - -class UnityToJUnit - include FileUtils::Verbose - attr_reader :report, :total_tests, :failures, :ignored - attr_writer :targets, :root, :out_file - - def initialize - @report = '' - @unit_name = '' - end - - def run - # Clean up result file names - results = @targets.map { |target| target.tr('\\', '/') } - # puts "Output File: #{@out_file}" - f = File.new(@out_file, 'w') - write_xml_header(f) - write_suites_header(f) - results.each do |result_file| - lines = File.readlines(result_file).map(&:chomp) - - raise "Empty test result file: #{result_file}" if lines.empty? - - result_output = get_details(result_file, lines) - tests, failures, ignored = parse_test_summary(lines) - result_output[:counts][:total] = tests - result_output[:counts][:failed] = failures - result_output[:counts][:ignored] = ignored - result_output[:counts][:passed] = (result_output[:counts][:total] - result_output[:counts][:failed] - result_output[:counts][:ignored]) - - # use line[0] from the test output to get the test_file path and name - test_file_str = lines[0].tr('\\', '/') - test_file_str = test_file_str.split(':') - test_file = if test_file_str.length < 2 - result_file - else - test_file_str[0] + ':' + test_file_str[1] - end - result_output[:source][:path] = File.dirname(test_file) - result_output[:source][:file] = File.basename(test_file) - - # save result_output - @unit_name = File.basename(test_file, '.*') - - write_suite_header(result_output[:counts], f) - write_failures(result_output, f) - write_tests(result_output, f) - write_ignored(result_output, f) - write_suite_footer(f) - end - write_suites_footer(f) - f.close - end - - def usage(err_msg = nil) - puts "\nERROR: " - puts err_msg if err_msg - puts 'Usage: unity_to_junit.rb [options]' - puts '' - puts 'Specific options:' - puts ' -r, --results Look for Unity Results files here.' - puts ' -p, --root_path Prepend this path to files in results.' - puts ' -o, --output XML file to generate.' - puts '' - puts 'Common options:' - puts ' -h, --help Show this message' - puts ' --version Show version' - - exit 1 - end - - protected - - def get_details(_result_file, lines) - results = results_structure - lines.each do |line| - line = line.tr('\\', '/') - _src_file, src_line, test_name, status, msg = line.split(/:/) - case status - when 'IGNORE' then results[:ignores] << { test: test_name, line: src_line, message: msg } - when 'FAIL' then results[:failures] << { test: test_name, line: src_line, message: msg } - when 'PASS' then results[:successes] << { test: test_name, line: src_line, message: msg } - end - end - results - end - - def parse_test_summary(summary) - raise "Couldn't parse test results: #{summary}" unless summary.find { |v| v =~ /(\d+) Tests (\d+) Failures (\d+) Ignored/ } - [Regexp.last_match(1).to_i, Regexp.last_match(2).to_i, Regexp.last_match(3).to_i] - end - - private - - def results_structure - { - source: { path: '', file: '' }, - successes: [], - failures: [], - ignores: [], - counts: { total: 0, passed: 0, failed: 0, ignored: 0 }, - stdout: [] - } - end - - def write_xml_header(stream) - stream.puts "" - end - - def write_suites_header(stream) - stream.puts '' - end - - def write_suite_header(counts, stream) - stream.puts "\t" - end - - def write_failures(results, stream) - result = results[:failures] - result.each do |item| - filename = File.join(results[:source][:path], File.basename(results[:source][:file], '.*')) - stream.puts "\t\t" - stream.puts "\t\t\t" - stream.puts "\t\t\t [File] #{filename} [Line] #{item[:line]} " - stream.puts "\t\t" - end - end - - def write_tests(results, stream) - result = results[:successes] - result.each do |item| - stream.puts "\t\t" - end - end - - def write_ignored(results, stream) - result = results[:ignores] - result.each do |item| - filename = File.join(results[:source][:path], File.basename(results[:source][:file], '.*')) - puts "Writing ignored tests for test harness: #{filename}" - stream.puts "\t\t" - stream.puts "\t\t\t" - stream.puts "\t\t\t [File] #{filename} [Line] #{item[:line]} " - stream.puts "\t\t" - end - end - - def write_suite_footer(stream) - stream.puts "\t" - end - - def write_suites_footer(stream) - stream.puts '' - end -end - -if $0 == __FILE__ - # parse out the command options - options = ArgvParser.parse(ARGV) - - # create an instance to work with - utj = UnityToJUnit.new - begin - # look in the specified or current directory for result files - targets = "#{options.results_dir.tr('\\', '/')}**/*.test*" - - results = Dir[targets] - raise "No *.testpass, *.testfail, or *.testresults files found in '#{targets}'" if results.empty? - utj.targets = results - - # set the root path - utj.root = options.root_path - - # set the output XML file name - # puts "Output File from options: #{options.out_file}" - utj.out_file = options.out_file - - # run the summarizer - puts utj.run - rescue StandardError => e - utj.usage e.message - end -end diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/unity/auto/test_file_filter.rb b/bk7235/liteos_m/bk_sdk_armino/middleware/compal/unity/auto/test_file_filter.rb deleted file mode 100755 index 5c3a79fc67958cda8883ae3e6917496f6db4f883..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/unity/auto/test_file_filter.rb +++ /dev/null @@ -1,25 +0,0 @@ -# ========================================== -# Unity Project - A Test Framework for C -# Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams -# [Released under MIT License. Please refer to license.txt for details] -# ========================================== - -require'yaml' - -module RakefileHelpers - class TestFileFilter - def initialize(all_files = false) - @all_files = all_files - - return unless @all_files - return unless File.exist?('test_file_filter.yml') - - filters = YAML.load_file('test_file_filter.yml') - @all_files = filters[:all_files] - @only_files = filters[:only_files] - @exclude_files = filters[:exclude_files] - end - - attr_accessor :all_files, :only_files, :exclude_files - end -end diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/unity/auto/type_sanitizer.rb b/bk7235/liteos_m/bk_sdk_armino/middleware/compal/unity/auto/type_sanitizer.rb deleted file mode 100755 index dafb8826e71ceb74afa2c4a1563ce66e659b230a..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/unity/auto/type_sanitizer.rb +++ /dev/null @@ -1,6 +0,0 @@ -module TypeSanitizer - def self.sanitize_c_identifier(unsanitized) - # convert filename to valid C identifier by replacing invalid chars with '_' - unsanitized.gsub(/[-\/\\\.\,\s]/, '_') - end -end diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/unity/auto/unity_test_summary.py b/bk7235/liteos_m/bk_sdk_armino/middleware/compal/unity/auto/unity_test_summary.py deleted file mode 100755 index 00c0da8cc3a7a3fbe2e17abe28948e1b2a4d7322..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/unity/auto/unity_test_summary.py +++ /dev/null @@ -1,139 +0,0 @@ -#! python3 -# ========================================== -# Unity Project - A Test Framework for C -# Copyright (c) 2015 Alexander Mueller / XelaRellum@web.de -# [Released under MIT License. Please refer to license.txt for details] -# Based on the ruby script by Mike Karlesky, Mark VanderVoord, Greg Williams -# ========================================== -import sys -import os -import re -from glob import glob - -class UnityTestSummary: - def __init__(self): - self.report = '' - self.total_tests = 0 - self.failures = 0 - self.ignored = 0 - - def run(self): - # Clean up result file names - results = [] - for target in self.targets: - results.append(target.replace('\\', '/')) - - # Dig through each result file, looking for details on pass/fail: - failure_output = [] - ignore_output = [] - - for result_file in results: - lines = list(map(lambda line: line.rstrip(), open(result_file, "r").read().split('\n'))) - if len(lines) == 0: - raise Exception("Empty test result file: %s" % result_file) - - details = self.get_details(result_file, lines) - failures = details['failures'] - ignores = details['ignores'] - if len(failures) > 0: failure_output.append('\n'.join(failures)) - if len(ignores) > 0: ignore_output.append('n'.join(ignores)) - tests,failures,ignored = self.parse_test_summary('\n'.join(lines)) - self.total_tests += tests - self.failures += failures - self.ignored += ignored - - if self.ignored > 0: - self.report += "\n" - self.report += "--------------------------\n" - self.report += "UNITY IGNORED TEST SUMMARY\n" - self.report += "--------------------------\n" - self.report += "\n".join(ignore_output) - - if self.failures > 0: - self.report += "\n" - self.report += "--------------------------\n" - self.report += "UNITY FAILED TEST SUMMARY\n" - self.report += "--------------------------\n" - self.report += '\n'.join(failure_output) - - self.report += "\n" - self.report += "--------------------------\n" - self.report += "OVERALL UNITY TEST SUMMARY\n" - self.report += "--------------------------\n" - self.report += "{total_tests} TOTAL TESTS {failures} TOTAL FAILURES {ignored} IGNORED\n".format(total_tests = self.total_tests, failures=self.failures, ignored=self.ignored) - self.report += "\n" - - return self.report - - def set_targets(self, target_array): - self.targets = target_array - - def set_root_path(self, path): - self.root = path - - def usage(self, err_msg=None): - print("\nERROR: ") - if err_msg: - print(err_msg) - print("\nUsage: unity_test_summary.py result_file_directory/ root_path/") - print(" result_file_directory - The location of your results files.") - print(" Defaults to current directory if not specified.") - print(" Should end in / if specified.") - print(" root_path - Helpful for producing more verbose output if using relative paths.") - sys.exit(1) - - def get_details(self, result_file, lines): - results = { 'failures': [], 'ignores': [], 'successes': [] } - for line in lines: - parts = line.split(':') - if len(parts) == 5: - src_file,src_line,test_name,status,msg = parts - elif len(parts) == 4: - src_file,src_line,test_name,status = parts - msg = '' - else: - continue - if len(self.root) > 0: - line_out = "%s%s" % (self.root, line) - else: - line_out = line - if status == 'IGNORE': - results['ignores'].append(line_out) - elif status == 'FAIL': - results['failures'].append(line_out) - elif status == 'PASS': - results['successes'].append(line_out) - return results - - def parse_test_summary(self, summary): - m = re.search(r"([0-9]+) Tests ([0-9]+) Failures ([0-9]+) Ignored", summary) - if not m: - raise Exception("Couldn't parse test results: %s" % summary) - - return int(m.group(1)), int(m.group(2)), int(m.group(3)) - - -if __name__ == '__main__': - uts = UnityTestSummary() - try: - #look in the specified or current directory for result files - if len(sys.argv) > 1: - targets_dir = sys.argv[1] - else: - targets_dir = './' - targets = list(map(lambda x: x.replace('\\', '/'), glob(targets_dir + '**/*.test*', recursive=True))) - if len(targets) == 0: - raise Exception("No *.testpass or *.testfail files found in '%s'" % targets_dir) - uts.set_targets(targets) - - #set the root path - if len(sys.argv) > 2: - root_path = sys.argv[2] - else: - root_path = os.path.split(__file__)[0] - uts.set_root_path(root_path) - - #run the summarizer - print(uts.run()) - except Exception as e: - uts.usage(e) diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/unity/auto/unity_test_summary.rb b/bk7235/liteos_m/bk_sdk_armino/middleware/compal/unity/auto/unity_test_summary.rb deleted file mode 100755 index 810fdbd1b387676bcdc27783e93a4353aec1c789..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/unity/auto/unity_test_summary.rb +++ /dev/null @@ -1,132 +0,0 @@ -# ========================================== -# Unity Project - A Test Framework for C -# Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams -# [Released under MIT License. Please refer to license.txt for details] -# ========================================== - -# !/usr/bin/ruby -# -# unity_test_summary.rb -# -require 'fileutils' -require 'set' - -class UnityTestSummary - include FileUtils::Verbose - - attr_reader :report, :total_tests, :failures, :ignored - attr_writer :targets, :root - - def initialize(_opts = {}) - @report = '' - @total_tests = 0 - @failures = 0 - @ignored = 0 - end - - def run - # Clean up result file names - results = @targets.map { |target| target.tr('\\', '/') } - - # Dig through each result file, looking for details on pass/fail: - failure_output = [] - ignore_output = [] - - results.each do |result_file| - lines = File.readlines(result_file).map(&:chomp) - - raise "Empty test result file: #{result_file}" if lines.empty? - - output = get_details(result_file, lines) - failure_output << output[:failures] unless output[:failures].empty? - ignore_output << output[:ignores] unless output[:ignores].empty? - tests, failures, ignored = parse_test_summary(lines) - @total_tests += tests - @failures += failures - @ignored += ignored - end - - if @ignored > 0 - @report += "\n" - @report += "--------------------------\n" - @report += "UNITY IGNORED TEST SUMMARY\n" - @report += "--------------------------\n" - @report += ignore_output.flatten.join("\n") - end - - if @failures > 0 - @report += "\n" - @report += "--------------------------\n" - @report += "UNITY FAILED TEST SUMMARY\n" - @report += "--------------------------\n" - @report += failure_output.flatten.join("\n") - end - - @report += "\n" - @report += "--------------------------\n" - @report += "OVERALL UNITY TEST SUMMARY\n" - @report += "--------------------------\n" - @report += "#{@total_tests} TOTAL TESTS #{@failures} TOTAL FAILURES #{@ignored} IGNORED\n" - @report += "\n" - end - - def usage(err_msg = nil) - puts "\nERROR: " - puts err_msg if err_msg - puts "\nUsage: unity_test_summary.rb result_file_directory/ root_path/" - puts ' result_file_directory - The location of your results files.' - puts ' Defaults to current directory if not specified.' - puts ' Should end in / if specified.' - puts ' root_path - Helpful for producing more verbose output if using relative paths.' - exit 1 - end - - protected - - def get_details(_result_file, lines) - results = { failures: [], ignores: [], successes: [] } - lines.each do |line| - _src_file, _src_line, _test_name, status, _msg = line.split(/:/) - line_out = (@root && (@root != 0) ? "#{@root}#{line}" : line).gsub(/\//, '\\') - case status - when 'IGNORE' then results[:ignores] << line_out - when 'FAIL' then results[:failures] << line_out - when 'PASS' then results[:successes] << line_out - end - end - results - end - - def parse_test_summary(summary) - raise "Couldn't parse test results: #{summary}" unless summary.find { |v| v =~ /(\d+) Tests (\d+) Failures (\d+) Ignored/ } - [Regexp.last_match(1).to_i, Regexp.last_match(2).to_i, Regexp.last_match(3).to_i] - end -end - -if $0 == __FILE__ - - # parse out the command options - opts, args = ARGV.partition { |v| v =~ /^--\w+/ } - opts.map! { |v| v[2..-1].to_sym } - - # create an instance to work with - uts = UnityTestSummary.new(opts) - - begin - # look in the specified or current directory for result files - args[0] ||= './' - targets = "#{ARGV[0].tr('\\', '/')}**/*.test*" - results = Dir[targets] - raise "No *.testpass, *.testfail, or *.testresults files found in '#{targets}'" if results.empty? - uts.targets = results - - # set the root path - args[1] ||= Dir.pwd + '/' - uts.root = ARGV[1] - - # run the summarizer - puts uts.run - rescue StandardError => e - uts.usage e.message - end -end diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/unity/auto/unity_to_junit.py b/bk7235/liteos_m/bk_sdk_armino/middleware/compal/unity/auto/unity_to_junit.py deleted file mode 100755 index 71dd568883d7e55ab5a7b539f86d3d350c4748d3..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/unity/auto/unity_to_junit.py +++ /dev/null @@ -1,146 +0,0 @@ -import sys -import os -from glob import glob - -from pyparsing import * -from junit_xml import TestSuite, TestCase - - -class UnityTestSummary: - def __init__(self): - self.report = '' - self.total_tests = 0 - self.failures = 0 - self.ignored = 0 - self.targets = 0 - self.root = None - self.test_suites = dict() - - def run(self): - # Clean up result file names - results = [] - for target in self.targets: - results.append(target.replace('\\', '/')) - - # Dig through each result file, looking for details on pass/fail: - for result_file in results: - lines = list(map(lambda line: line.rstrip(), open(result_file, "r").read().split('\n'))) - if len(lines) == 0: - raise Exception("Empty test result file: %s" % result_file) - - # define an expression for your file reference - entry_one = Combine( - oneOf(list(alphas)) + ':/' + - Word(alphanums + '_-./')) - - entry_two = Word(printables + ' ', excludeChars=':') - entry = entry_one | entry_two - - delimiter = Literal(':').suppress() - tc_result_line = Group(entry.setResultsName('tc_file_name') + delimiter + entry.setResultsName( - 'tc_line_nr') + delimiter + entry.setResultsName('tc_name') + delimiter + entry.setResultsName( - 'tc_status') + Optional( - delimiter + entry.setResultsName('tc_msg'))).setResultsName("tc_line") - - eol = LineEnd().suppress() - sol = LineStart().suppress() - blank_line = sol + eol - - tc_summary_line = Group(Word(nums).setResultsName("num_of_tests") + "Tests" + Word(nums).setResultsName( - "num_of_fail") + "Failures" + Word(nums).setResultsName("num_of_ignore") + "Ignored").setResultsName( - "tc_summary") - tc_end_line = Or(Literal("FAIL"), Literal('Ok')).setResultsName("tc_result") - - # run it and see... - pp1 = tc_result_line | Optional(tc_summary_line | tc_end_line) - pp1.ignore(blank_line | OneOrMore("-")) - - result = list() - for l in lines: - result.append((pp1.parseString(l)).asDict()) - # delete empty results - result = filter(None, result) - - tc_list = list() - for r in result: - if 'tc_line' in r: - tmp_tc_line = r['tc_line'] - - # get only the file name which will be used as the classname - file_name = tmp_tc_line['tc_file_name'].split('\\').pop().split('/').pop().rsplit('.', 1)[0] - tmp_tc = TestCase(name=tmp_tc_line['tc_name'], classname=file_name) - if 'tc_status' in tmp_tc_line: - if str(tmp_tc_line['tc_status']) == 'IGNORE': - if 'tc_msg' in tmp_tc_line: - tmp_tc.add_skipped_info(message=tmp_tc_line['tc_msg'], - output=r'[File]={0}, [Line]={1}'.format( - tmp_tc_line['tc_file_name'], tmp_tc_line['tc_line_nr'])) - else: - tmp_tc.add_skipped_info(message=" ") - elif str(tmp_tc_line['tc_status']) == 'FAIL': - if 'tc_msg' in tmp_tc_line: - tmp_tc.add_failure_info(message=tmp_tc_line['tc_msg'], - output=r'[File]={0}, [Line]={1}'.format( - tmp_tc_line['tc_file_name'], tmp_tc_line['tc_line_nr'])) - else: - tmp_tc.add_failure_info(message=" ") - - tc_list.append((str(result_file), tmp_tc)) - - for k, v in tc_list: - try: - self.test_suites[k].append(v) - except KeyError: - self.test_suites[k] = [v] - ts = [] - for suite_name in self.test_suites: - ts.append(TestSuite(suite_name, self.test_suites[suite_name])) - - with open('result.xml', 'w') as f: - TestSuite.to_file(f, ts, prettyprint='True', encoding='utf-8') - - return self.report - - def set_targets(self, target_array): - self.targets = target_array - - def set_root_path(self, path): - self.root = path - - @staticmethod - def usage(err_msg=None): - print("\nERROR: ") - if err_msg: - print(err_msg) - print("\nUsage: unity_test_summary.py result_file_directory/ root_path/") - print(" result_file_directory - The location of your results files.") - print(" Defaults to current directory if not specified.") - print(" Should end in / if specified.") - print(" root_path - Helpful for producing more verbose output if using relative paths.") - sys.exit(1) - - -if __name__ == '__main__': - uts = UnityTestSummary() - try: - # look in the specified or current directory for result files - if len(sys.argv) > 1: - targets_dir = sys.argv[1] - else: - targets_dir = './' - targets = list(map(lambda x: x.replace('\\', '/'), glob(targets_dir + '*.test*'))) - if len(targets) == 0: - raise Exception("No *.testpass or *.testfail files found in '%s'" % targets_dir) - uts.set_targets(targets) - - # set the root path - if len(sys.argv) > 2: - root_path = sys.argv[2] - else: - root_path = os.path.split(__file__)[0] - uts.set_root_path(root_path) - - # run the summarizer - print(uts.run()) - except Exception as e: - UnityTestSummary.usage(e) diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/unity/extras/eclipse/error_parsers.txt b/bk7235/liteos_m/bk_sdk_armino/middleware/compal/unity/extras/eclipse/error_parsers.txt deleted file mode 100755 index 94e34ff385f92fb7999ac1bc0356d2daac97d841..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/unity/extras/eclipse/error_parsers.txt +++ /dev/null @@ -1,26 +0,0 @@ -Eclipse error parsers -===================== - -These are a godsend for extracting & quickly navigating to -warnings & error messages from console output. Unforunately -I don't know how to write an Eclipse plugin so you'll have -to add them manually. - -To add a console parser to Eclipse, go to Window --> Preferences ---> C/C++ --> Build --> Settings. Click on the 'Error Parsers' -tab and then click the 'Add...' button. See the table below for -the parser fields to add. - -Eclipse will only parse the console output during a build, so -running your unit tests must be part of your build process. -Either add this to your make/rakefile, or add it as a post- -build step in your Eclipse project settings. - - -Unity unit test error parsers ------------------------------ -Severity Pattern File Line Description -------------------------------------------------------------------------------- -Error (\.+)(.*?):(\d+):(.*?):FAIL: (.*) $2 $3 $5 -Warning (\.+)(.*?):(\d+):(.*?):IGNORE: (.*) $2 $3 $5 -Warning (\.+)(.*?):(\d+):(.*?):IGNORE\s*$ $2 $3 Ignored test diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/unity/extras/fixture/rakefile.rb b/bk7235/liteos_m/bk_sdk_armino/middleware/compal/unity/extras/fixture/rakefile.rb deleted file mode 100755 index 8b5319c58d9250c92dccfede6f22ae219175a291..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/unity/extras/fixture/rakefile.rb +++ /dev/null @@ -1,46 +0,0 @@ -# ========================================== -# Unity Project - A Test Framework for C -# Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams -# [Released under MIT License. Please refer to license.txt for details] -# ========================================== - -require 'rake' -require 'rake/clean' -require 'rake/testtask' -require_relative 'rakefile_helper' - -TEMP_DIRS = [ - File.join(__dir__, 'build') -].freeze - -TEMP_DIRS.each do |dir| - directory(dir) - CLOBBER.include(dir) -end - -task prepare_for_tests: TEMP_DIRS - -include RakefileHelpers - -# Load default configuration, for now -DEFAULT_CONFIG_FILE = 'gcc_auto_stdint.yml'.freeze -configure_toolchain(DEFAULT_CONFIG_FILE) - -task unit: [:prepare_for_tests] do - run_tests -end - -desc 'Build and test Unity Framework' -task all: %i[clean unit] -task default: %i[clobber all] -task ci: %i[no_color default] -task cruise: %i[no_color default] - -desc 'Load configuration' -task :config, :config_file do |_t, args| - configure_toolchain(args[:config_file]) -end - -task :no_color do - $colour_output = false -end diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/unity/extras/fixture/rakefile_helper.rb b/bk7235/liteos_m/bk_sdk_armino/middleware/compal/unity/extras/fixture/rakefile_helper.rb deleted file mode 100755 index 71e752b920c1d17659af5a79ed6d37af480fb2cc..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/unity/extras/fixture/rakefile_helper.rb +++ /dev/null @@ -1,178 +0,0 @@ -# ========================================== -# Unity Project - A Test Framework for C -# Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams -# [Released under MIT License. Please refer to license.txt for details] -# ========================================== - -require 'yaml' -require 'fileutils' -require_relative '../../auto/unity_test_summary' -require_relative '../../auto/generate_test_runner' -require_relative '../../auto/colour_reporter' - -module RakefileHelpers - C_EXTENSION = '.c'.freeze - - def load_configuration(config_file) - return if $configured - - $cfg_file = "#{__dir__}/../../test/targets/#{config_file}" unless config_file =~ /[\\|\/]/ - $cfg = YAML.load(File.read($cfg_file)) - $colour_output = false unless $cfg['colour'] - $configured = true if config_file != DEFAULT_CONFIG_FILE - end - - def configure_clean - CLEAN.include($cfg['compiler']['build_path'] + '*.*') unless $cfg['compiler']['build_path'].nil? - end - - def configure_toolchain(config_file = DEFAULT_CONFIG_FILE) - config_file += '.yml' unless config_file =~ /\.yml$/ - config_file = config_file unless config_file =~ /[\\|\/]/ - load_configuration(config_file) - configure_clean - end - - def tackit(strings) - result = if strings.is_a?(Array) - "\"#{strings.join}\"" - else - strings - end - result - end - - def squash(prefix, items) - result = '' - items.each { |item| result += " #{prefix}#{tackit(item)}" } - result - end - - def build_compiler_fields - command = tackit($cfg['compiler']['path']) - defines = if $cfg['compiler']['defines']['items'].nil? - '' - else - squash($cfg['compiler']['defines']['prefix'], $cfg['compiler']['defines']['items'] + ['UNITY_OUTPUT_CHAR=UnityOutputCharSpy_OutputChar'] + ['UNITY_OUTPUT_CHAR_HEADER_DECLARATION=UnityOutputCharSpy_OutputChar\(int\)']) - end - options = squash('', $cfg['compiler']['options']) - includes = squash($cfg['compiler']['includes']['prefix'], $cfg['compiler']['includes']['items']) - includes = includes.gsub(/\\ /, ' ').gsub(/\\\"/, '"').gsub(/\\$/, '') # Remove trailing slashes (for IAR) - - { command: command, defines: defines, options: options, includes: includes } - end - - def compile(file, _defines = []) - compiler = build_compiler_fields - unity_include = $cfg['compiler']['includes']['prefix'] + '../../src' - cmd_str = "#{compiler[:command]}#{compiler[:defines]}#{compiler[:options]}#{compiler[:includes]} #{unity_include} #{file} " \ - "#{$cfg['compiler']['object_files']['prefix']}#{$cfg['compiler']['object_files']['destination']}" \ - "#{File.basename(file, C_EXTENSION)}#{$cfg['compiler']['object_files']['extension']}" - - execute(cmd_str) - end - - def build_linker_fields - command = tackit($cfg['linker']['path']) - options = if $cfg['linker']['options'].nil? - '' - else - squash('', $cfg['linker']['options']) - end - includes = if $cfg['linker']['includes'].nil? || $cfg['linker']['includes']['items'].nil? - '' - else - squash($cfg['linker']['includes']['prefix'], $cfg['linker']['includes']['items']) - end.gsub(/\\ /, ' ').gsub(/\\\"/, '"').gsub(/\\$/, '') # Remove trailing slashes (for IAR) - - { command: command, options: options, includes: includes } - end - - def link_it(exe_name, obj_list) - linker = build_linker_fields - cmd_str = "#{linker[:command]}#{linker[:options]}#{linker[:includes]} " + - (obj_list.map { |obj| "#{$cfg['linker']['object_files']['path']}#{obj} " }).join + - $cfg['linker']['bin_files']['prefix'] + ' ' + - $cfg['linker']['bin_files']['destination'] + - exe_name + $cfg['linker']['bin_files']['extension'] - execute(cmd_str) - end - - def build_simulator_fields - return nil if $cfg['simulator'].nil? - command = if $cfg['simulator']['path'].nil? - '' - else - (tackit($cfg['simulator']['path']) + ' ') - end - pre_support = if $cfg['simulator']['pre_support'].nil? - '' - else - squash('', $cfg['simulator']['pre_support']) - end - post_support = if $cfg['simulator']['post_support'].nil? - '' - else - squash('', $cfg['simulator']['post_support']) - end - { command: command, pre_support: pre_support, post_support: post_support } - end - - def execute(command_string, verbose = true) - report command_string - output = `#{command_string}`.chomp - report(output) if verbose && !output.nil? && !output.empty? - raise "Command failed. (Returned #{$?.exitstatus})" if $?.exitstatus != 0 - output - end - - def report_summary - summary = UnityTestSummary.new - summary.root = __dir__ - results_glob = "#{$cfg['compiler']['build_path']}*.test*" - results_glob.tr!('\\', '/') - results = Dir[results_glob] - summary.targets = results - summary.run - end - - def run_tests - report 'Running Unity system tests...' - - # Tack on TEST define for compiling unit tests - load_configuration($cfg_file) - test_defines = ['TEST'] - $cfg['compiler']['defines']['items'] = [] if $cfg['compiler']['defines']['items'].nil? - - # Get a list of all source files needed - src_files = Dir["#{__dir__}/src/*.c"] - src_files += Dir["#{__dir__}/test/*.c"] - src_files += Dir["#{__dir__}/test/main/*.c"] - src_files << '../../src/unity.c' - - # Build object files - src_files.each { |f| compile(f, test_defines) } - obj_list = src_files.map { |f| File.basename(f.ext($cfg['compiler']['object_files']['extension'])) } - - # Link the test executable - test_base = 'framework_test' - link_it(test_base, obj_list) - - # Execute unit test and generate results file - simulator = build_simulator_fields - executable = $cfg['linker']['bin_files']['destination'] + test_base + $cfg['linker']['bin_files']['extension'] - cmd_str = if simulator.nil? - executable + ' -v -r' - else - "#{simulator[:command]} #{simulator[:pre_support]} #{executable} #{simulator[:post_support]}" - end - output = execute(cmd_str) - test_results = $cfg['compiler']['build_path'] + test_base - test_results += if output.match(/OK$/m).nil? - '.testfail' - else - '.testpass' - end - File.open(test_results, 'w') { |f| f.print output } - end -end diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/unity/extras/fixture/readme.txt b/bk7235/liteos_m/bk_sdk_armino/middleware/compal/unity/extras/fixture/readme.txt deleted file mode 100755 index 6b9a78c17f7e54108ca9c61e9435c063b522fc87..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/unity/extras/fixture/readme.txt +++ /dev/null @@ -1,9 +0,0 @@ -Copyright (c) 2010 James Grenning and Contributed to Unity Project - -Unity Project - A Test Framework for C -Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams -[Released under MIT License. Please refer to license.txt for details] - -This Framework is an optional add-on to Unity. By including unity_framework.h in place of unity.h, -you may now work with Unity in a manner similar to CppUTest. This framework adds the concepts of -test groups and gives finer control of your tests over the command line. \ No newline at end of file diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/unity/extras/fixture/src/unity_fixture.c b/bk7235/liteos_m/bk_sdk_armino/middleware/compal/unity/extras/fixture/src/unity_fixture.c deleted file mode 100755 index 67807e151a71badcafdd41e157b6bbd16f366012..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/unity/extras/fixture/src/unity_fixture.c +++ /dev/null @@ -1,453 +0,0 @@ -/* Copyright (c) 2010 James Grenning and Contributed to Unity Project - * ========================================== - * Unity Project - A Test Framework for C - * Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams - * [Released under MIT License. Please refer to license.txt for details] - * ========================================== */ - -#include "unity_fixture.h" -#include "unity_internals.h" -#include - -struct UNITY_FIXTURE_T UnityFixture; - -/* If you decide to use the function pointer approach. - * Build with -D UNITY_OUTPUT_CHAR=outputChar and include - * int (*outputChar)(int) = putchar; */ - -void setUp(void) { /*does nothing*/ } -void tearDown(void) { /*does nothing*/ } - -static void announceTestRun(unsigned int runNumber) -{ - UnityPrint("Unity test run "); - UnityPrintNumberUnsigned(runNumber+1); - UnityPrint(" of "); - UnityPrintNumberUnsigned(UnityFixture.RepeatCount); - UNITY_PRINT_EOL(); -} - -int UnityMain(int argc, const char* argv[], void (*runAllTests)(void)) -{ - int result = UnityGetCommandLineOptions(argc, argv); - unsigned int r; - if (result != 0) - return result; - - for (r = 0; r < UnityFixture.RepeatCount; r++) - { - UnityBegin(argv[0]); - announceTestRun(r); - runAllTests(); - if (!UnityFixture.Verbose) UNITY_PRINT_EOL(); - UnityEnd(); - } - - return (int)Unity.TestFailures; -} - -static int selected(const char* filter, const char* name) -{ - if (filter == 0) - return 1; - return strstr(name, filter) ? 1 : 0; -} - -static int testSelected(const char* test) -{ - return selected(UnityFixture.NameFilter, test); -} - -static int groupSelected(const char* group) -{ - return selected(UnityFixture.GroupFilter, group); -} - -void UnityTestRunner(unityfunction* setup, - unityfunction* testBody, - unityfunction* teardown, - const char* printableName, - const char* group, - const char* name, - const char* file, - unsigned int line) -{ - if (testSelected(name) && groupSelected(group)) - { - Unity.TestFile = file; - Unity.CurrentTestName = printableName; - Unity.CurrentTestLineNumber = line; - if (UnityFixture.Verbose) - { - UnityPrint(printableName); - #ifndef UNITY_REPEAT_TEST_NAME - Unity.CurrentTestName = NULL; - #endif - } - else if (UnityFixture.Silent) - { - /* Do Nothing */ - } - else - { - UNITY_OUTPUT_CHAR('.'); - } - - Unity.NumberOfTests++; - UnityMalloc_StartTest(); - UnityPointer_Init(); - - UNITY_EXEC_TIME_START(); - - if (TEST_PROTECT()) - { - setup(); - testBody(); - } - if (TEST_PROTECT()) - { - teardown(); - } - if (TEST_PROTECT()) - { - UnityPointer_UndoAllSets(); - if (!Unity.CurrentTestFailed) - UnityMalloc_EndTest(); - } - UnityConcludeFixtureTest(); - } -} - -void UnityIgnoreTest(const char* printableName, const char* group, const char* name) -{ - if (testSelected(name) && groupSelected(group)) - { - Unity.NumberOfTests++; - Unity.TestIgnores++; - if (UnityFixture.Verbose) - { - UnityPrint(printableName); - UNITY_PRINT_EOL(); - } - else if (UnityFixture.Silent) - { - /* Do Nothing */ - } - else - { - UNITY_OUTPUT_CHAR('!'); - } - } -} - - -/*------------------------------------------------- */ -/* Malloc and free stuff */ -#define MALLOC_DONT_FAIL -1 -static int malloc_count; -static int malloc_fail_countdown = MALLOC_DONT_FAIL; - -void UnityMalloc_StartTest(void) -{ - malloc_count = 0; - malloc_fail_countdown = MALLOC_DONT_FAIL; -} - -void UnityMalloc_EndTest(void) -{ - malloc_fail_countdown = MALLOC_DONT_FAIL; - if (malloc_count != 0) - { - UNITY_TEST_FAIL(Unity.CurrentTestLineNumber, "This test leaks!"); - } -} - -void UnityMalloc_MakeMallocFailAfterCount(int countdown) -{ - malloc_fail_countdown = countdown; -} - -/* These definitions are always included from unity_fixture_malloc_overrides.h */ -/* We undef to use them or avoid conflict with per the C standard */ -#undef malloc -#undef free -#undef calloc -#undef realloc - -#ifdef UNITY_EXCLUDE_STDLIB_MALLOC -static unsigned char unity_heap[UNITY_INTERNAL_HEAP_SIZE_BYTES]; -static size_t heap_index; -#else -#include -#endif - -typedef struct GuardBytes -{ - size_t size; - size_t guard_space; -} Guard; - - -static const char end[] = "END"; - -void* unity_malloc(size_t size) -{ - char* mem; - Guard* guard; - size_t total_size = size + sizeof(Guard) + sizeof(end); - - if (malloc_fail_countdown != MALLOC_DONT_FAIL) - { - if (malloc_fail_countdown == 0) - return NULL; - malloc_fail_countdown--; - } - - if (size == 0) return NULL; -#ifdef UNITY_EXCLUDE_STDLIB_MALLOC - if (heap_index + total_size > UNITY_INTERNAL_HEAP_SIZE_BYTES) - { - guard = NULL; - } - else - { - guard = (Guard*)&unity_heap[heap_index]; - heap_index += total_size; - } -#else - guard = (Guard*)UNITY_FIXTURE_MALLOC(total_size); -#endif - if (guard == NULL) return NULL; - malloc_count++; - guard->size = size; - guard->guard_space = 0; - mem = (char*)&(guard[1]); - memcpy(&mem[size], end, sizeof(end)); - - return (void*)mem; -} - -static int isOverrun(void* mem) -{ - Guard* guard = (Guard*)mem; - char* memAsChar = (char*)mem; - guard--; - - return guard->guard_space != 0 || strcmp(&memAsChar[guard->size], end) != 0; -} - -static void release_memory(void* mem) -{ - Guard* guard = (Guard*)mem; - guard--; - - malloc_count--; -#ifdef UNITY_EXCLUDE_STDLIB_MALLOC - if (mem == unity_heap + heap_index - guard->size - sizeof(end)) - { - heap_index -= (guard->size + sizeof(Guard) + sizeof(end)); - } -#else - UNITY_FIXTURE_FREE(guard); -#endif -} - -void unity_free(void* mem) -{ - int overrun; - - if (mem == NULL) - { - return; - } - - overrun = isOverrun(mem); - release_memory(mem); - if (overrun) - { - UNITY_TEST_FAIL(Unity.CurrentTestLineNumber, "Buffer overrun detected during free()"); - } -} - -void* unity_calloc(size_t num, size_t size) -{ - void* mem = unity_malloc(num * size); - if (mem == NULL) return NULL; - memset(mem, 0, num * size); - return mem; -} - -void* unity_realloc(void* oldMem, size_t size) -{ - Guard* guard = (Guard*)oldMem; - void* newMem; - - if (oldMem == NULL) return unity_malloc(size); - - guard--; - if (isOverrun(oldMem)) - { - release_memory(oldMem); - UNITY_TEST_FAIL(Unity.CurrentTestLineNumber, "Buffer overrun detected during realloc()"); - } - - if (size == 0) - { - release_memory(oldMem); - return NULL; - } - - if (guard->size >= size) return oldMem; - -#ifdef UNITY_EXCLUDE_STDLIB_MALLOC /* Optimization if memory is expandable */ - if (oldMem == unity_heap + heap_index - guard->size - sizeof(end) && - heap_index + size - guard->size <= UNITY_INTERNAL_HEAP_SIZE_BYTES) - { - release_memory(oldMem); /* Not thread-safe, like unity_heap generally */ - return unity_malloc(size); /* No memcpy since data is in place */ - } -#endif - newMem = unity_malloc(size); - if (newMem == NULL) return NULL; /* Do not release old memory */ - memcpy(newMem, oldMem, guard->size); - release_memory(oldMem); - return newMem; -} - - -/*-------------------------------------------------------- */ -/*Automatic pointer restoration functions */ -struct PointerPair -{ - void** pointer; - void* old_value; -}; - -static struct PointerPair pointer_store[UNITY_MAX_POINTERS]; -static int pointer_index = 0; - -void UnityPointer_Init(void) -{ - pointer_index = 0; -} - -void UnityPointer_Set(void** pointer, void* newValue, UNITY_LINE_TYPE line) -{ - if (pointer_index >= UNITY_MAX_POINTERS) - { - UNITY_TEST_FAIL(line, "Too many pointers set"); - } - else - { - pointer_store[pointer_index].pointer = pointer; - pointer_store[pointer_index].old_value = *pointer; - *pointer = newValue; - pointer_index++; - } -} - -void UnityPointer_UndoAllSets(void) -{ - while (pointer_index > 0) - { - pointer_index--; - *(pointer_store[pointer_index].pointer) = - pointer_store[pointer_index].old_value; - } -} - -int UnityGetCommandLineOptions(int argc, const char* argv[]) -{ - int i; - UnityFixture.Verbose = 0; - UnityFixture.Silent = 0; - UnityFixture.GroupFilter = 0; - UnityFixture.NameFilter = 0; - UnityFixture.RepeatCount = 1; - - if (argc == 1) - return 0; - - for (i = 1; i < argc; ) - { - if (strcmp(argv[i], "-v") == 0) - { - UnityFixture.Verbose = 1; - i++; - } - else if (strcmp(argv[i], "-s") == 0) - { - UnityFixture.Silent = 1; - i++; - } - else if (strcmp(argv[i], "-g") == 0) - { - i++; - if (i >= argc) - return 1; - UnityFixture.GroupFilter = argv[i]; - i++; - } - else if (strcmp(argv[i], "-n") == 0) - { - i++; - if (i >= argc) - return 1; - UnityFixture.NameFilter = argv[i]; - i++; - } - else if (strcmp(argv[i], "-r") == 0) - { - UnityFixture.RepeatCount = 2; - i++; - if (i < argc) - { - if (*(argv[i]) >= '0' && *(argv[i]) <= '9') - { - unsigned int digit = 0; - UnityFixture.RepeatCount = 0; - while (argv[i][digit] >= '0' && argv[i][digit] <= '9') - { - UnityFixture.RepeatCount *= 10; - UnityFixture.RepeatCount += (unsigned int)argv[i][digit++] - '0'; - } - i++; - } - } - } - else - { - /* ignore unknown parameter */ - i++; - } - } - return 0; -} - -void UnityConcludeFixtureTest(void) -{ - if (Unity.CurrentTestIgnored) - { - Unity.TestIgnores++; - UNITY_PRINT_EOL(); - } - else if (!Unity.CurrentTestFailed) - { - if (UnityFixture.Verbose) - { - UnityPrint(" "); - UnityPrint(UnityStrPass); - UNITY_EXEC_TIME_STOP(); - UNITY_PRINT_EXEC_TIME(); - UNITY_PRINT_EOL(); - } - } - else /* Unity.CurrentTestFailed */ - { - Unity.TestFailures++; - UNITY_PRINT_EOL(); - } - - Unity.CurrentTestFailed = 0; - Unity.CurrentTestIgnored = 0; -} diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/unity/extras/fixture/src/unity_fixture.h b/bk7235/liteos_m/bk_sdk_armino/middleware/compal/unity/extras/fixture/src/unity_fixture.h deleted file mode 100755 index 2dcf473c7f2697c843a31cbbc597bf52541f3dbc..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/unity/extras/fixture/src/unity_fixture.h +++ /dev/null @@ -1,83 +0,0 @@ -/* Copyright (c) 2010 James Grenning and Contributed to Unity Project - * ========================================== - * Unity Project - A Test Framework for C - * Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams - * [Released under MIT License. Please refer to license.txt for details] - * ========================================== */ - -#ifndef UNITY_FIXTURE_H_ -#define UNITY_FIXTURE_H_ - -#include "unity.h" -#include "unity_internals.h" -#include "unity_fixture_malloc_overrides.h" -#include "unity_fixture_internals.h" - -int UnityMain(int argc, const char* argv[], void (*runAllTests)(void)); - - -#define TEST_GROUP(group)\ - static const char* TEST_GROUP_##group = #group - -#define TEST_SETUP(group) void TEST_##group##_SETUP(void);\ - void TEST_##group##_SETUP(void) - -#define TEST_TEAR_DOWN(group) void TEST_##group##_TEAR_DOWN(void);\ - void TEST_##group##_TEAR_DOWN(void) - - -#define TEST(group, name) \ - void TEST_##group##_##name##_(void);\ - void TEST_##group##_##name##_run(void);\ - void TEST_##group##_##name##_run(void)\ - {\ - UnityTestRunner(TEST_##group##_SETUP,\ - TEST_##group##_##name##_,\ - TEST_##group##_TEAR_DOWN,\ - "TEST(" #group ", " #name ")",\ - TEST_GROUP_##group, #name,\ - __FILE__, __LINE__);\ - }\ - void TEST_##group##_##name##_(void) - -#define IGNORE_TEST(group, name) \ - void TEST_##group##_##name##_(void);\ - void TEST_##group##_##name##_run(void);\ - void TEST_##group##_##name##_run(void)\ - {\ - UnityIgnoreTest("IGNORE_TEST(" #group ", " #name ")", TEST_GROUP_##group, #name);\ - }\ - void TEST_##group##_##name##_(void) - -/* Call this for each test, insider the group runner */ -#define RUN_TEST_CASE(group, name) \ - { void TEST_##group##_##name##_run(void);\ - TEST_##group##_##name##_run(); } - -/* This goes at the bottom of each test file or in a separate c file */ -#define TEST_GROUP_RUNNER(group)\ - void TEST_##group##_GROUP_RUNNER(void);\ - void TEST_##group##_GROUP_RUNNER(void) - -/* Call this from main */ -#define RUN_TEST_GROUP(group)\ - { void TEST_##group##_GROUP_RUNNER(void);\ - TEST_##group##_GROUP_RUNNER(); } - -/* CppUTest Compatibility Macros */ -#ifndef UNITY_EXCLUDE_CPPUTEST_ASSERTS -/* Sets a pointer and automatically restores it to its old value after teardown */ -#define UT_PTR_SET(ptr, newPointerValue) UnityPointer_Set((void**)&(ptr), (void*)(newPointerValue), __LINE__) -#define TEST_ASSERT_POINTERS_EQUAL(expected, actual) TEST_ASSERT_EQUAL_PTR((expected), (actual)) -#define TEST_ASSERT_BYTES_EQUAL(expected, actual) TEST_ASSERT_EQUAL_HEX8(0xff & (expected), 0xff & (actual)) -#define FAIL(message) TEST_FAIL_MESSAGE((message)) -#define CHECK(condition) TEST_ASSERT_TRUE((condition)) -#define LONGS_EQUAL(expected, actual) TEST_ASSERT_EQUAL_INT((expected), (actual)) -#define STRCMP_EQUAL(expected, actual) TEST_ASSERT_EQUAL_STRING((expected), (actual)) -#define DOUBLES_EQUAL(expected, actual, delta) TEST_ASSERT_DOUBLE_WITHIN((delta), (expected), (actual)) -#endif - -/* You must compile with malloc replacement, as defined in unity_fixture_malloc_overrides.h */ -void UnityMalloc_MakeMallocFailAfterCount(int countdown); - -#endif /* UNITY_FIXTURE_H_ */ diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/unity/extras/fixture/src/unity_fixture_internals.h b/bk7235/liteos_m/bk_sdk_armino/middleware/compal/unity/extras/fixture/src/unity_fixture_internals.h deleted file mode 100755 index 98d4d4430dcdea5cd081c1154e839be10337c748..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/unity/extras/fixture/src/unity_fixture_internals.h +++ /dev/null @@ -1,52 +0,0 @@ -/* Copyright (c) 2010 James Grenning and Contributed to Unity Project - * ========================================== - * Unity Project - A Test Framework for C - * Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams - * [Released under MIT License. Please refer to license.txt for details] - * ========================================== */ - -#ifndef UNITY_FIXTURE_INTERNALS_H_ -#define UNITY_FIXTURE_INTERNALS_H_ - -#ifdef __cplusplus -extern "C" -{ -#endif - -struct UNITY_FIXTURE_T -{ - int Verbose; - int Silent; - unsigned int RepeatCount; - const char* NameFilter; - const char* GroupFilter; -}; -extern struct UNITY_FIXTURE_T UnityFixture; - -typedef void unityfunction(void); -void UnityTestRunner(unityfunction* setup, - unityfunction* testBody, - unityfunction* teardown, - const char* printableName, - const char* group, - const char* name, - const char* file, unsigned int line); - -void UnityIgnoreTest(const char* printableName, const char* group, const char* name); -void UnityMalloc_StartTest(void); -void UnityMalloc_EndTest(void); -int UnityGetCommandLineOptions(int argc, const char* argv[]); -void UnityConcludeFixtureTest(void); - -void UnityPointer_Set(void** pointer, void* newValue, UNITY_LINE_TYPE line); -void UnityPointer_UndoAllSets(void); -void UnityPointer_Init(void); -#ifndef UNITY_MAX_POINTERS -#define UNITY_MAX_POINTERS 5 -#endif - -#ifdef __cplusplus -} -#endif - -#endif /* UNITY_FIXTURE_INTERNALS_H_ */ diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/unity/extras/fixture/src/unity_fixture_malloc_overrides.h b/bk7235/liteos_m/bk_sdk_armino/middleware/compal/unity/extras/fixture/src/unity_fixture_malloc_overrides.h deleted file mode 100755 index 7daba50aae5b84441096c72b7290fc20e94c0b6f..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/unity/extras/fixture/src/unity_fixture_malloc_overrides.h +++ /dev/null @@ -1,47 +0,0 @@ -/* Copyright (c) 2010 James Grenning and Contributed to Unity Project - * ========================================== - * Unity Project - A Test Framework for C - * Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams - * [Released under MIT License. Please refer to license.txt for details] - * ========================================== */ - -#ifndef UNITY_FIXTURE_MALLOC_OVERRIDES_H_ -#define UNITY_FIXTURE_MALLOC_OVERRIDES_H_ - -#include - -#ifdef UNITY_EXCLUDE_STDLIB_MALLOC -/* Define this macro to remove the use of stdlib.h, malloc, and free. - * Many embedded systems do not have a heap or malloc/free by default. - * This internal unity_malloc() provides allocated memory deterministically from - * the end of an array only, unity_free() only releases from end-of-array, - * blocks are not coalesced, and memory not freed in LIFO order is stranded. */ - #ifndef UNITY_INTERNAL_HEAP_SIZE_BYTES - #define UNITY_INTERNAL_HEAP_SIZE_BYTES 256 - #endif -#endif - -/* These functions are used by the Unity Fixture to allocate and release memory - * on the heap and can be overridden with platform-specific implementations. - * For example, when using FreeRTOS UNITY_FIXTURE_MALLOC becomes pvPortMalloc() - * and UNITY_FIXTURE_FREE becomes vPortFree(). */ -#if !defined(UNITY_FIXTURE_MALLOC) || !defined(UNITY_FIXTURE_FREE) - #include - #define UNITY_FIXTURE_MALLOC(size) malloc(size) - #define UNITY_FIXTURE_FREE(ptr) free(ptr) -#else - extern void* UNITY_FIXTURE_MALLOC(size_t size); - extern void UNITY_FIXTURE_FREE(void* ptr); -#endif - -#define malloc unity_malloc -#define calloc unity_calloc -#define realloc unity_realloc -#define free unity_free - -void* unity_malloc(size_t size); -void* unity_calloc(size_t num, size_t size); -void* unity_realloc(void * oldMem, size_t size); -void unity_free(void * mem); - -#endif /* UNITY_FIXTURE_MALLOC_OVERRIDES_H_ */ diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/unity/extras/fixture/test/Makefile b/bk7235/liteos_m/bk_sdk_armino/middleware/compal/unity/extras/fixture/test/Makefile deleted file mode 100755 index e6c62552f6f53b58e9ab2d19acc70c5db5e83bbf..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/unity/extras/fixture/test/Makefile +++ /dev/null @@ -1,75 +0,0 @@ -CC = gcc -ifeq ($(shell uname -s), Darwin) -CC = clang -endif -#DEBUG = -O0 -g -CFLAGS += -std=c99 -pedantic -Wall -Wextra -Werror -CFLAGS += $(DEBUG) -DEFINES = -D UNITY_OUTPUT_CHAR=UnityOutputCharSpy_OutputChar -DEFINES += -D UNITY_OUTPUT_CHAR_HEADER_DECLARATION=UnityOutputCharSpy_OutputChar\(int\) -SRC = ../src/unity_fixture.c \ - ../../../src/unity.c \ - unity_fixture_Test.c \ - unity_fixture_TestRunner.c \ - unity_output_Spy.c \ - main/AllTests.c - -INC_DIR = -I../src -I../../../src/ -BUILD_DIR = ../build -TARGET = ../build/fixture_tests.exe - -all: default noStdlibMalloc 32bits - -default: $(BUILD_DIR) - $(CC) $(CFLAGS) $(DEFINES) $(SRC) $(INC_DIR) -o $(TARGET) -D UNITY_SUPPORT_64 - @ echo "default build" - ./$(TARGET) - -32bits: $(BUILD_DIR) - $(CC) $(CFLAGS) $(DEFINES) $(SRC) $(INC_DIR) -o $(TARGET) -m32 - @ echo "32bits build" - ./$(TARGET) - -noStdlibMalloc: $(BUILD_DIR) - $(CC) $(CFLAGS) $(DEFINES) $(SRC) $(INC_DIR) -o $(TARGET) -D UNITY_EXCLUDE_STDLIB_MALLOC - @ echo "build with noStdlibMalloc" - ./$(TARGET) - -C89: CFLAGS += -D UNITY_EXCLUDE_STDINT_H # C89 did not have type 'long long', -C89: $(BUILD_DIR) - $(CC) $(CFLAGS) $(DEFINES) $(SRC) $(INC_DIR) -o $(TARGET) -std=c89 && ./$(TARGET) - $(CC) $(CFLAGS) $(DEFINES) $(SRC) $(INC_DIR) -o $(TARGET) -D UNITY_EXCLUDE_STDLIB_MALLOC -std=c89 - ./$(TARGET) - -$(BUILD_DIR): - mkdir -p $(BUILD_DIR) - -clean: - rm -f $(TARGET) $(BUILD_DIR)/*.gc* - -cov: $(BUILD_DIR) - cd $(BUILD_DIR) && \ - $(CC) $(DEFINES) $(foreach i, $(SRC), ../test/$(i)) $(INC_DIR) -o $(TARGET) -fprofile-arcs -ftest-coverage - rm -f $(BUILD_DIR)/*.gcda - ./$(TARGET) > /dev/null ; ./$(TARGET) -v > /dev/null - cd $(BUILD_DIR) && \ - gcov unity_fixture.c | head -3 - grep '###' $(BUILD_DIR)/unity_fixture.c.gcov -C2 || true # Show uncovered lines - -# These extended flags DO get included before any target build runs -CFLAGS += -Wbad-function-cast -CFLAGS += -Wcast-qual -CFLAGS += -Wconversion -CFLAGS += -Wformat=2 -CFLAGS += -Wmissing-prototypes -CFLAGS += -Wold-style-definition -CFLAGS += -Wpointer-arith -CFLAGS += -Wshadow -CFLAGS += -Wstrict-overflow=5 -CFLAGS += -Wstrict-prototypes -CFLAGS += -Wswitch-default -CFLAGS += -Wundef -CFLAGS += -Wno-error=undef # Warning only, this should not stop the build -CFLAGS += -Wunreachable-code -CFLAGS += -Wunused -CFLAGS += -fstrict-aliasing diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/unity/extras/fixture/test/main/AllTests.c b/bk7235/liteos_m/bk_sdk_armino/middleware/compal/unity/extras/fixture/test/main/AllTests.c deleted file mode 100755 index e30dd853d123ccdc1bc9f6b95c9ea92fb1de7585..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/unity/extras/fixture/test/main/AllTests.c +++ /dev/null @@ -1,22 +0,0 @@ -/* Copyright (c) 2010 James Grenning and Contributed to Unity Project - * ========================================== - * Unity Project - A Test Framework for C - * Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams - * [Released under MIT License. Please refer to license.txt for details] - * ========================================== */ - -#include "unity_fixture.h" - -static void runAllTests(void) -{ - RUN_TEST_GROUP(UnityFixture); - RUN_TEST_GROUP(UnityCommandOptions); - RUN_TEST_GROUP(LeakDetection); - RUN_TEST_GROUP(InternalMalloc); -} - -int main(int argc, const char* argv[]) -{ - return UnityMain(argc, argv, runAllTests); -} - diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/unity/extras/fixture/test/template_fixture_tests.c b/bk7235/liteos_m/bk_sdk_armino/middleware/compal/unity/extras/fixture/test/template_fixture_tests.c deleted file mode 100755 index 18bbb89e899ccb3c3d7199bffa56026a168f3c79..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/unity/extras/fixture/test/template_fixture_tests.c +++ /dev/null @@ -1,39 +0,0 @@ -/* Copyright (c) 2010 James Grenning and Contributed to Unity Project - * ========================================== - * Unity Project - A Test Framework for C - * Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams - * [Released under MIT License. Please refer to license.txt for details] - * ========================================== */ - -#include "unity_fixture.h" - -static int data = -1; - -TEST_GROUP(mygroup); - -TEST_SETUP(mygroup) -{ - data = 0; -} - -TEST_TEAR_DOWN(mygroup) -{ - data = -1; -} - -TEST(mygroup, test1) -{ - TEST_ASSERT_EQUAL_INT(0, data); -} - -TEST(mygroup, test2) -{ - TEST_ASSERT_EQUAL_INT(0, data); - data = 5; -} - -TEST(mygroup, test3) -{ - data = 7; - TEST_ASSERT_EQUAL_INT(7, data); -} diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/unity/extras/fixture/test/unity_fixture_Test.c b/bk7235/liteos_m/bk_sdk_armino/middleware/compal/unity/extras/fixture/test/unity_fixture_Test.c deleted file mode 100755 index a842b08537e7cc371af23eb346d8b1ba20ed135a..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/unity/extras/fixture/test/unity_fixture_Test.c +++ /dev/null @@ -1,543 +0,0 @@ -/* Copyright (c) 2010 James Grenning and Contributed to Unity Project - * ========================================== - * Unity Project - A Test Framework for C - * Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams - * [Released under MIT License. Please refer to license.txt for details] - * ========================================== */ - -#include "unity_fixture.h" -#include "unity_output_Spy.h" -#include -#include - -TEST_GROUP(UnityFixture); - -TEST_SETUP(UnityFixture) -{ -} - -TEST_TEAR_DOWN(UnityFixture) -{ -} - -static int* pointer1 = 0; -static int* pointer2 = (int*)2; -static int* pointer3 = (int*)3; -static int int1; -static int int2; -static int int3; -static int int4; - -TEST(UnityFixture, PointerSetting) -{ - TEST_ASSERT_POINTERS_EQUAL(pointer1, 0); - UT_PTR_SET(pointer1, &int1); - UT_PTR_SET(pointer2, &int2); - UT_PTR_SET(pointer3, &int3); - TEST_ASSERT_POINTERS_EQUAL(pointer1, &int1); - TEST_ASSERT_POINTERS_EQUAL(pointer2, &int2); - TEST_ASSERT_POINTERS_EQUAL(pointer3, &int3); - UT_PTR_SET(pointer1, &int4); - UnityPointer_UndoAllSets(); - TEST_ASSERT_POINTERS_EQUAL(pointer1, 0); - TEST_ASSERT_POINTERS_EQUAL(pointer2, (int*)2); - TEST_ASSERT_POINTERS_EQUAL(pointer3, (int*)3); -} - -TEST(UnityFixture, ForceMallocFail) -{ - void* m; - void* mfails; - UnityMalloc_MakeMallocFailAfterCount(1); - m = malloc(10); - CHECK(m); - mfails = malloc(10); - TEST_ASSERT_POINTERS_EQUAL(0, mfails); - free(m); -} - -TEST(UnityFixture, ReallocSmallerIsUnchanged) -{ - void* m1 = malloc(10); - void* m2 = realloc(m1, 5); - TEST_ASSERT_POINTERS_EQUAL(m1, m2); - free(m2); -} - -TEST(UnityFixture, ReallocSameIsUnchanged) -{ - void* m1 = malloc(10); - void* m2 = realloc(m1, 10); - TEST_ASSERT_POINTERS_EQUAL(m1, m2); - free(m2); -} - -TEST(UnityFixture, ReallocLargerNeeded) -{ - void* m1 = malloc(10); - void* m2; - CHECK(m1); - strcpy((char*)m1, "123456789"); - m2 = realloc(m1, 15); - /* CHECK(m1 != m2); //Depends on implementation */ - STRCMP_EQUAL("123456789", m2); - free(m2); -} - -TEST(UnityFixture, ReallocNullPointerIsLikeMalloc) -{ - void* m = realloc(0, 15); - CHECK(m != 0); - free(m); -} - -TEST(UnityFixture, ReallocSizeZeroFreesMemAndReturnsNullPointer) -{ - void* m1 = malloc(10); - void* m2 = realloc(m1, 0); - TEST_ASSERT_POINTERS_EQUAL(0, m2); -} - -TEST(UnityFixture, CallocFillsWithZero) -{ - void* m = calloc(3, sizeof(char)); - char* s = (char*)m; - CHECK(m); - TEST_ASSERT_BYTES_EQUAL(0, s[0]); - TEST_ASSERT_BYTES_EQUAL(0, s[1]); - TEST_ASSERT_BYTES_EQUAL(0, s[2]); - free(m); -} - -static char *p1; -static char *p2; - -TEST(UnityFixture, PointerSet) -{ - char c1; - char c2; - char newC1; - char newC2; - p1 = &c1; - p2 = &c2; - - UnityPointer_Init(); - UT_PTR_SET(p1, &newC1); - UT_PTR_SET(p2, &newC2); - TEST_ASSERT_POINTERS_EQUAL(&newC1, p1); - TEST_ASSERT_POINTERS_EQUAL(&newC2, p2); - UnityPointer_UndoAllSets(); - TEST_ASSERT_POINTERS_EQUAL(&c1, p1); - TEST_ASSERT_POINTERS_EQUAL(&c2, p2); -} - -TEST(UnityFixture, FreeNULLSafety) -{ - free(NULL); -} - -TEST(UnityFixture, ConcludeTestIncrementsFailCount) -{ - UNITY_UINT savedFails = Unity.TestFailures; - UNITY_UINT savedIgnores = Unity.TestIgnores; - UnityOutputCharSpy_Enable(1); - Unity.CurrentTestFailed = 1; - UnityConcludeFixtureTest(); /* Resets TestFailed for this test to pass */ - Unity.CurrentTestIgnored = 1; - UnityConcludeFixtureTest(); /* Resets TestIgnored */ - UnityOutputCharSpy_Enable(0); - TEST_ASSERT_EQUAL(savedFails + 1, Unity.TestFailures); - TEST_ASSERT_EQUAL(savedIgnores + 1, Unity.TestIgnores); - Unity.TestFailures = savedFails; - Unity.TestIgnores = savedIgnores; -} - -/*------------------------------------------------------------ */ - -TEST_GROUP(UnityCommandOptions); - -static int savedVerbose; -static unsigned int savedRepeat; -static const char* savedName; -static const char* savedGroup; - -TEST_SETUP(UnityCommandOptions) -{ - savedVerbose = UnityFixture.Verbose; - savedRepeat = UnityFixture.RepeatCount; - savedName = UnityFixture.NameFilter; - savedGroup = UnityFixture.GroupFilter; -} - -TEST_TEAR_DOWN(UnityCommandOptions) -{ - UnityFixture.Verbose = savedVerbose; - UnityFixture.RepeatCount= savedRepeat; - UnityFixture.NameFilter = savedName; - UnityFixture.GroupFilter = savedGroup; -} - - -static const char* noOptions[] = { - "testrunner.exe" -}; - -TEST(UnityCommandOptions, DefaultOptions) -{ - UnityGetCommandLineOptions(1, noOptions); - TEST_ASSERT_EQUAL(0, UnityFixture.Verbose); - TEST_ASSERT_POINTERS_EQUAL(0, UnityFixture.GroupFilter); - TEST_ASSERT_POINTERS_EQUAL(0, UnityFixture.NameFilter); - TEST_ASSERT_EQUAL(1, UnityFixture.RepeatCount); -} - -static const char* verbose[] = { - "testrunner.exe", - "-v" -}; - -TEST(UnityCommandOptions, OptionVerbose) -{ - TEST_ASSERT_EQUAL(0, UnityGetCommandLineOptions(2, verbose)); - TEST_ASSERT_EQUAL(1, UnityFixture.Verbose); -} - -static const char* group[] = { - "testrunner.exe", - "-g", "groupname" -}; - -TEST(UnityCommandOptions, OptionSelectTestByGroup) -{ - TEST_ASSERT_EQUAL(0, UnityGetCommandLineOptions(3, group)); - STRCMP_EQUAL("groupname", UnityFixture.GroupFilter); -} - -static const char* name[] = { - "testrunner.exe", - "-n", "testname" -}; - -TEST(UnityCommandOptions, OptionSelectTestByName) -{ - TEST_ASSERT_EQUAL(0, UnityGetCommandLineOptions(3, name)); - STRCMP_EQUAL("testname", UnityFixture.NameFilter); -} - -static const char* repeat[] = { - "testrunner.exe", - "-r", "99" -}; - -TEST(UnityCommandOptions, OptionSelectRepeatTestsDefaultCount) -{ - TEST_ASSERT_EQUAL(0, UnityGetCommandLineOptions(2, repeat)); - TEST_ASSERT_EQUAL(2, UnityFixture.RepeatCount); -} - -TEST(UnityCommandOptions, OptionSelectRepeatTestsSpecificCount) -{ - TEST_ASSERT_EQUAL(0, UnityGetCommandLineOptions(3, repeat)); - TEST_ASSERT_EQUAL(99, UnityFixture.RepeatCount); -} - -static const char* multiple[] = { - "testrunner.exe", - "-v", - "-g", "groupname", - "-n", "testname", - "-r", "98" -}; - -TEST(UnityCommandOptions, MultipleOptions) -{ - TEST_ASSERT_EQUAL(0, UnityGetCommandLineOptions(8, multiple)); - TEST_ASSERT_EQUAL(1, UnityFixture.Verbose); - STRCMP_EQUAL("groupname", UnityFixture.GroupFilter); - STRCMP_EQUAL("testname", UnityFixture.NameFilter); - TEST_ASSERT_EQUAL(98, UnityFixture.RepeatCount); -} - -static const char* dashRNotLast[] = { - "testrunner.exe", - "-v", - "-g", "gggg", - "-r", - "-n", "tttt", -}; - -TEST(UnityCommandOptions, MultipleOptionsDashRNotLastAndNoValueSpecified) -{ - TEST_ASSERT_EQUAL(0, UnityGetCommandLineOptions(7, dashRNotLast)); - TEST_ASSERT_EQUAL(1, UnityFixture.Verbose); - STRCMP_EQUAL("gggg", UnityFixture.GroupFilter); - STRCMP_EQUAL("tttt", UnityFixture.NameFilter); - TEST_ASSERT_EQUAL(2, UnityFixture.RepeatCount); -} - -static const char* unknownCommand[] = { - "testrunner.exe", - "-v", - "-g", "groupname", - "-n", "testname", - "-r", "98", - "-z" -}; -TEST(UnityCommandOptions, UnknownCommandIsIgnored) -{ - TEST_ASSERT_EQUAL(0, UnityGetCommandLineOptions(9, unknownCommand)); - TEST_ASSERT_EQUAL(1, UnityFixture.Verbose); - STRCMP_EQUAL("groupname", UnityFixture.GroupFilter); - STRCMP_EQUAL("testname", UnityFixture.NameFilter); - TEST_ASSERT_EQUAL(98, UnityFixture.RepeatCount); -} - -TEST(UnityCommandOptions, GroupOrNameFilterWithoutStringFails) -{ - TEST_ASSERT_EQUAL(1, UnityGetCommandLineOptions(3, unknownCommand)); - TEST_ASSERT_EQUAL(1, UnityGetCommandLineOptions(5, unknownCommand)); - TEST_ASSERT_EQUAL(1, UnityMain(3, unknownCommand, NULL)); -} - -TEST(UnityCommandOptions, GroupFilterReallyFilters) -{ - UNITY_UINT saved = Unity.NumberOfTests; - TEST_ASSERT_EQUAL(0, UnityGetCommandLineOptions(4, unknownCommand)); - UnityIgnoreTest(NULL, "non-matching", NULL); - TEST_ASSERT_EQUAL(saved, Unity.NumberOfTests); -} - -IGNORE_TEST(UnityCommandOptions, TestShouldBeIgnored) -{ - TEST_FAIL_MESSAGE("This test should not run!"); -} - -/*------------------------------------------------------------ */ - -TEST_GROUP(LeakDetection); - -TEST_SETUP(LeakDetection) -{ -#ifdef UNITY_EXCLUDE_STDLIB_MALLOC - UnityOutputCharSpy_Create(200); -#else - UnityOutputCharSpy_Create(1000); -#endif -} - -TEST_TEAR_DOWN(LeakDetection) -{ - UnityOutputCharSpy_Destroy(); -} - -#define EXPECT_ABORT_BEGIN \ - { \ - jmp_buf TestAbortFrame; \ - memcpy(TestAbortFrame, Unity.AbortFrame, sizeof(jmp_buf)); \ - if (TEST_PROTECT()) \ - { - -#define EXPECT_ABORT_END \ - } \ - memcpy(Unity.AbortFrame, TestAbortFrame, sizeof(jmp_buf)); \ - } - -/* This tricky set of defines lets us see if we are using the Spy, returns 1 if true */ -#ifdef __STDC_VERSION__ - -#if __STDC_VERSION__ >= 199901L -#define USING_SPY_AS(a) EXPAND_AND_USE_2ND(ASSIGN_VALUE(a), 0) -#define ASSIGN_VALUE(a) VAL_##a -#define VAL_UnityOutputCharSpy_OutputChar 0, 1 -#define EXPAND_AND_USE_2ND(a, b) SECOND_PARAM(a, b, throwaway) -#define SECOND_PARAM(a, b, ...) b -#if USING_SPY_AS(UNITY_OUTPUT_CHAR) - #define USING_OUTPUT_SPY /* UNITY_OUTPUT_CHAR = UnityOutputCharSpy_OutputChar */ -#endif -#endif /* >= 199901 */ - -#else /* __STDC_VERSION__ else */ -#define UnityOutputCharSpy_OutputChar 42 -#if UNITY_OUTPUT_CHAR == UnityOutputCharSpy_OutputChar /* Works if no -Wundef -Werror */ - #define USING_OUTPUT_SPY -#endif -#undef UnityOutputCharSpy_OutputChar -#endif /* __STDC_VERSION__ */ - -TEST(LeakDetection, DetectsLeak) -{ -#ifndef USING_OUTPUT_SPY - TEST_IGNORE_MESSAGE("Build with '-D UNITY_OUTPUT_CHAR=UnityOutputCharSpy_OutputChar' to enable tests"); -#else - void* m = malloc(10); - TEST_ASSERT_NOT_NULL(m); - UnityOutputCharSpy_Enable(1); - EXPECT_ABORT_BEGIN - UnityMalloc_EndTest(); - EXPECT_ABORT_END - UnityOutputCharSpy_Enable(0); - Unity.CurrentTestFailed = 0; - CHECK(strstr(UnityOutputCharSpy_Get(), "This test leaks!")); - free(m); -#endif -} - -TEST(LeakDetection, BufferOverrunFoundDuringFree) -{ -#ifndef USING_OUTPUT_SPY - TEST_IGNORE(); -#else - void* m = malloc(10); - char* s = (char*)m; - TEST_ASSERT_NOT_NULL(m); - s[10] = (char)0xFF; - UnityOutputCharSpy_Enable(1); - EXPECT_ABORT_BEGIN - free(m); - EXPECT_ABORT_END - UnityOutputCharSpy_Enable(0); - Unity.CurrentTestFailed = 0; - CHECK(strstr(UnityOutputCharSpy_Get(), "Buffer overrun detected during free()")); -#endif -} - -TEST(LeakDetection, BufferOverrunFoundDuringRealloc) -{ -#ifndef USING_OUTPUT_SPY - TEST_IGNORE(); -#else - void* m = malloc(10); - char* s = (char*)m; - TEST_ASSERT_NOT_NULL(m); - s[10] = (char)0xFF; - UnityOutputCharSpy_Enable(1); - EXPECT_ABORT_BEGIN - m = realloc(m, 100); - EXPECT_ABORT_END - UnityOutputCharSpy_Enable(0); - Unity.CurrentTestFailed = 0; - CHECK(strstr(UnityOutputCharSpy_Get(), "Buffer overrun detected during realloc()")); -#endif -} - -TEST(LeakDetection, BufferGuardWriteFoundDuringFree) -{ -#ifndef USING_OUTPUT_SPY - TEST_IGNORE(); -#else - void* m = malloc(10); - char* s = (char*)m; - TEST_ASSERT_NOT_NULL(m); - s[-1] = (char)0x00; /* Will not detect 0 */ - s[-2] = (char)0x01; - UnityOutputCharSpy_Enable(1); - EXPECT_ABORT_BEGIN - free(m); - EXPECT_ABORT_END - UnityOutputCharSpy_Enable(0); - Unity.CurrentTestFailed = 0; - CHECK(strstr(UnityOutputCharSpy_Get(), "Buffer overrun detected during free()")); -#endif -} - -TEST(LeakDetection, BufferGuardWriteFoundDuringRealloc) -{ -#ifndef USING_OUTPUT_SPY - TEST_IGNORE(); -#else - void* m = malloc(10); - char* s = (char*)m; - TEST_ASSERT_NOT_NULL(m); - s[-1] = (char)0x0A; - UnityOutputCharSpy_Enable(1); - EXPECT_ABORT_BEGIN - m = realloc(m, 100); - EXPECT_ABORT_END - UnityOutputCharSpy_Enable(0); - Unity.CurrentTestFailed = 0; - CHECK(strstr(UnityOutputCharSpy_Get(), "Buffer overrun detected during realloc()")); -#endif -} - -TEST(LeakDetection, PointerSettingMax) -{ -#ifndef USING_OUTPUT_SPY - TEST_IGNORE(); -#else - int i; - for (i = 0; i < UNITY_MAX_POINTERS; i++) UT_PTR_SET(pointer1, &int1); - UnityOutputCharSpy_Enable(1); - EXPECT_ABORT_BEGIN - UT_PTR_SET(pointer1, &int1); - EXPECT_ABORT_END - UnityOutputCharSpy_Enable(0); - Unity.CurrentTestFailed = 0; - CHECK(strstr(UnityOutputCharSpy_Get(), "Too many pointers set")); -#endif -} - -/*------------------------------------------------------------ */ - -TEST_GROUP(InternalMalloc); -#define TEST_ASSERT_MEMORY_ALL_FREE_LIFO_ORDER(first_mem_ptr, ptr) \ - ptr = malloc(10); free(ptr); \ - TEST_ASSERT_EQUAL_PTR_MESSAGE(first_mem_ptr, ptr, "Memory was stranded, free in LIFO order"); - - -TEST_SETUP(InternalMalloc) { } -TEST_TEAR_DOWN(InternalMalloc) { } - -TEST(InternalMalloc, MallocPastBufferFails) -{ -#ifdef UNITY_EXCLUDE_STDLIB_MALLOC - void* m = malloc(UNITY_INTERNAL_HEAP_SIZE_BYTES/2 + 1); - void* n = malloc(UNITY_INTERNAL_HEAP_SIZE_BYTES/2); - free(m); - TEST_ASSERT_NOT_NULL(m); - TEST_ASSERT_NULL(n); - TEST_ASSERT_MEMORY_ALL_FREE_LIFO_ORDER(m, n); -#endif -} - -TEST(InternalMalloc, CallocPastBufferFails) -{ -#ifdef UNITY_EXCLUDE_STDLIB_MALLOC - void* m = calloc(1, UNITY_INTERNAL_HEAP_SIZE_BYTES/2 + 1); - void* n = calloc(1, UNITY_INTERNAL_HEAP_SIZE_BYTES/2); - free(m); - TEST_ASSERT_NOT_NULL(m); - TEST_ASSERT_NULL(n); - TEST_ASSERT_MEMORY_ALL_FREE_LIFO_ORDER(m, n); -#endif -} - -TEST(InternalMalloc, MallocThenReallocGrowsMemoryInPlace) -{ -#ifdef UNITY_EXCLUDE_STDLIB_MALLOC - void* m = malloc(UNITY_INTERNAL_HEAP_SIZE_BYTES/2 + 1); - void* n = realloc(m, UNITY_INTERNAL_HEAP_SIZE_BYTES/2 + 9); - free(n); - TEST_ASSERT_NOT_NULL(m); - TEST_ASSERT_EQUAL(m, n); - TEST_ASSERT_MEMORY_ALL_FREE_LIFO_ORDER(m, n); -#endif -} - -TEST(InternalMalloc, ReallocFailDoesNotFreeMem) -{ -#ifdef UNITY_EXCLUDE_STDLIB_MALLOC - void* m = malloc(UNITY_INTERNAL_HEAP_SIZE_BYTES/2); - void* n1 = malloc(10); - void* out_of_mem = realloc(n1, UNITY_INTERNAL_HEAP_SIZE_BYTES/2 + 1); - void* n2 = malloc(10); - - free(n2); - if (out_of_mem == NULL) free(n1); - free(m); - - TEST_ASSERT_NOT_NULL(m); /* Got a real memory location */ - TEST_ASSERT_NULL(out_of_mem); /* The realloc should have failed */ - TEST_ASSERT_NOT_EQUAL(n2, n1); /* If n1 != n2 then realloc did not free n1 */ - TEST_ASSERT_MEMORY_ALL_FREE_LIFO_ORDER(m, n2); -#endif -} diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/unity/extras/fixture/test/unity_fixture_TestRunner.c b/bk7235/liteos_m/bk_sdk_armino/middleware/compal/unity/extras/fixture/test/unity_fixture_TestRunner.c deleted file mode 100755 index e8713e1bc4c00205118f9a47fac36f7bec95aeb2..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/unity/extras/fixture/test/unity_fixture_TestRunner.c +++ /dev/null @@ -1,57 +0,0 @@ -/* Copyright (c) 2010 James Grenning and Contributed to Unity Project - * ========================================== - * Unity Project - A Test Framework for C - * Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams - * [Released under MIT License. Please refer to license.txt for details] - * ========================================== */ - -#include "unity_fixture.h" - -TEST_GROUP_RUNNER(UnityFixture) -{ - RUN_TEST_CASE(UnityFixture, PointerSetting); - RUN_TEST_CASE(UnityFixture, ForceMallocFail); - RUN_TEST_CASE(UnityFixture, ReallocSmallerIsUnchanged); - RUN_TEST_CASE(UnityFixture, ReallocSameIsUnchanged); - RUN_TEST_CASE(UnityFixture, ReallocLargerNeeded); - RUN_TEST_CASE(UnityFixture, ReallocNullPointerIsLikeMalloc); - RUN_TEST_CASE(UnityFixture, ReallocSizeZeroFreesMemAndReturnsNullPointer); - RUN_TEST_CASE(UnityFixture, CallocFillsWithZero); - RUN_TEST_CASE(UnityFixture, PointerSet); - RUN_TEST_CASE(UnityFixture, FreeNULLSafety); - RUN_TEST_CASE(UnityFixture, ConcludeTestIncrementsFailCount); -} - -TEST_GROUP_RUNNER(UnityCommandOptions) -{ - RUN_TEST_CASE(UnityCommandOptions, DefaultOptions); - RUN_TEST_CASE(UnityCommandOptions, OptionVerbose); - RUN_TEST_CASE(UnityCommandOptions, OptionSelectTestByGroup); - RUN_TEST_CASE(UnityCommandOptions, OptionSelectTestByName); - RUN_TEST_CASE(UnityCommandOptions, OptionSelectRepeatTestsDefaultCount); - RUN_TEST_CASE(UnityCommandOptions, OptionSelectRepeatTestsSpecificCount); - RUN_TEST_CASE(UnityCommandOptions, MultipleOptions); - RUN_TEST_CASE(UnityCommandOptions, MultipleOptionsDashRNotLastAndNoValueSpecified); - RUN_TEST_CASE(UnityCommandOptions, UnknownCommandIsIgnored); - RUN_TEST_CASE(UnityCommandOptions, GroupOrNameFilterWithoutStringFails); - RUN_TEST_CASE(UnityCommandOptions, GroupFilterReallyFilters); - RUN_TEST_CASE(UnityCommandOptions, TestShouldBeIgnored); -} - -TEST_GROUP_RUNNER(LeakDetection) -{ - RUN_TEST_CASE(LeakDetection, DetectsLeak); - RUN_TEST_CASE(LeakDetection, BufferOverrunFoundDuringFree); - RUN_TEST_CASE(LeakDetection, BufferOverrunFoundDuringRealloc); - RUN_TEST_CASE(LeakDetection, BufferGuardWriteFoundDuringFree); - RUN_TEST_CASE(LeakDetection, BufferGuardWriteFoundDuringRealloc); - RUN_TEST_CASE(LeakDetection, PointerSettingMax); -} - -TEST_GROUP_RUNNER(InternalMalloc) -{ - RUN_TEST_CASE(InternalMalloc, MallocPastBufferFails); - RUN_TEST_CASE(InternalMalloc, CallocPastBufferFails); - RUN_TEST_CASE(InternalMalloc, MallocThenReallocGrowsMemoryInPlace); - RUN_TEST_CASE(InternalMalloc, ReallocFailDoesNotFreeMem); -} diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/unity/extras/fixture/test/unity_output_Spy.c b/bk7235/liteos_m/bk_sdk_armino/middleware/compal/unity/extras/fixture/test/unity_output_Spy.c deleted file mode 100755 index be87bd58f4a32d8d58bc8bc9b26b265a4e0c6502..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/unity/extras/fixture/test/unity_output_Spy.c +++ /dev/null @@ -1,57 +0,0 @@ -/* Copyright (c) 2010 James Grenning and Contributed to Unity Project - * ========================================== - * Unity Project - A Test Framework for C - * Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams - * [Released under MIT License. Please refer to license.txt for details] - * ========================================== */ - - -#include "unity_output_Spy.h" -#include "unity_fixture.h" - -#include -#include - -static int size; -static int count; -static char* buffer; -static int spy_enable; - -void UnityOutputCharSpy_Create(int s) -{ - size = (s > 0) ? s : 0; - count = 0; - spy_enable = 0; - buffer = malloc((size_t)size); - TEST_ASSERT_NOT_NULL_MESSAGE(buffer, "Internal malloc failed in Spy Create():" __FILE__); - memset(buffer, 0, (size_t)size); -} - -void UnityOutputCharSpy_Destroy(void) -{ - size = 0; - free(buffer); -} - -void UnityOutputCharSpy_OutputChar(int c) -{ - if (spy_enable) - { - if (count < (size-1)) - buffer[count++] = (char)c; - } - else - { - putchar(c); - } -} - -const char * UnityOutputCharSpy_Get(void) -{ - return buffer; -} - -void UnityOutputCharSpy_Enable(int enable) -{ - spy_enable = enable; -} diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/unity/extras/fixture/test/unity_output_Spy.h b/bk7235/liteos_m/bk_sdk_armino/middleware/compal/unity/extras/fixture/test/unity_output_Spy.h deleted file mode 100755 index b30a7f13bbecc65637ce7fb7a1a38e93fc8aebfd..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/unity/extras/fixture/test/unity_output_Spy.h +++ /dev/null @@ -1,17 +0,0 @@ -/* Copyright (c) 2010 James Grenning and Contributed to Unity Project - * ========================================== - * Unity Project - A Test Framework for C - * Copyright (c) 2007 Mike Karlesky, Mark VanderVoord, Greg Williams - * [Released under MIT License. Please refer to license.txt for details] - * ========================================== */ - -#ifndef D_unity_output_Spy_H -#define D_unity_output_Spy_H - -void UnityOutputCharSpy_Create(int s); -void UnityOutputCharSpy_Destroy(void); -void UnityOutputCharSpy_OutputChar(int c); -const char * UnityOutputCharSpy_Get(void); -void UnityOutputCharSpy_Enable(int enable); - -#endif diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/unity/meson.build b/bk7235/liteos_m/bk_sdk_armino/middleware/compal/unity/meson.build deleted file mode 100755 index 7b9732a18e85adc935ee919d5ae189752520a660..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/unity/meson.build +++ /dev/null @@ -1,80 +0,0 @@ -################################################################################### -# # -# NAME: meson.build # -# # -# AUTHOR: Mike Karlesky, Mark VanderVoord, Greg Williams. # -# WRITTEN BY: Michael Brockus. # -# # -# License: MIT # -# # -################################################################################### - - - -project('unity', 'c', - version : '2.4.3', - license : 'MIT', - meson_version : '>=0.50.0', - default_options : - [ - 'werror=true', - 'optimization=3', - 'warning_level=3', - 'b_sanitize=address,undefined', - 'b_lto=true', - 'b_lundef=true' - ]) -cc = meson.get_compiler('c') -args_for_langs = 'c' - -if cc.get_id() == 'clang' - add_project_arguments( - '-Wweak-vtables', - '-Wexit-time-destructors', - '-Wglobal-constructors', - '-Wmissing-noreturn', language: args_for_langs) -endif - -if cc.get_argument_syntax() == 'gcc' - add_project_arguments( - '-Wall', - '-Wextra', - '-Wunreachable-code', - '-Wmissing-declarations', - '-Wmissing-prototypes', - '-Wredundant-decls', - '-Wundef', - '-Wwrite-strings', - '-Wformat', - '-Wformat-nonliteral', - '-Wformat-security', - '-Wold-style-definition', - '-Winit-self', - '-Wmissing-include-dirs', - '-Waddress', - '-Waggregate-return', - '-Wno-multichar', - '-Wdeclaration-after-statement', - '-Wvla', - '-Wpointer-arith',language: args_for_langs) -endif - -if cc.get_id() == 'msvc' - add_project_arguments( - '/W4', - '/w44265', - '/w44061', - '/w44062', - '/wd4018', # implicit signed/unsigned conversion - '/wd4146', # unary minus on unsigned (beware INT_MIN) - '/wd4244', # lossy type conversion (e.g. double -> int) - '/wd4305', # truncating type conversion (e.g. double -> float) - mesno.get_supported_arguments(['/utf-8']), language: args_for_langs) -endif - -subdir('src') - -unity_dep = declare_dependency( - version: meson.project_version(), - link_with: unity_lib, - include_directories: unity_dir) \ No newline at end of file diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/unity/release/build.info b/bk7235/liteos_m/bk_sdk_armino/middleware/compal/unity/release/build.info deleted file mode 100755 index 56d5912866763b85122b7ea4de5769081e4f7e55..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/unity/release/build.info +++ /dev/null @@ -1,2 +0,0 @@ -122 - diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/unity/release/version.info b/bk7235/liteos_m/bk_sdk_armino/middleware/compal/unity/release/version.info deleted file mode 100755 index b2031148232d4a6b0562fda4f83db5b3b3b08481..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/unity/release/version.info +++ /dev/null @@ -1,2 +0,0 @@ -2.4.4 - diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/unity/src/meson.build b/bk7235/liteos_m/bk_sdk_armino/middleware/compal/unity/src/meson.build deleted file mode 100755 index 5d8c4528be9f988d92fd81e4801556180e66bd9a..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/unity/src/meson.build +++ /dev/null @@ -1,20 +0,0 @@ -################################################################################### -# # -# NAME: src/meson.build # -# # -# AUTHOR: Mike Karlesky, Mark VanderVoord, Greg Williams. # -# WRITTEN BY: Michael Brockus. # -# # -# License: MIT # -# # -################################################################################### - - - -unity_src = files('unity.c') - -unity_dir = include_directories('.') - -unity_lib = library(meson.project_name(), - sources: unity_src, - include_directories: unity_dir) \ No newline at end of file diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/unity/src/unity.c b/bk7235/liteos_m/bk_sdk_armino/middleware/compal/unity/src/unity.c deleted file mode 100755 index 17a3f613f561f125681c3352ef054820aed7cd0f..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/unity/src/unity.c +++ /dev/null @@ -1,2027 +0,0 @@ -/* ========================================================================= - Unity Project - A Test Framework for C - Copyright (c) 2007-19 Mike Karlesky, Mark VanderVoord, Greg Williams - [Released under MIT License. Please refer to license.txt for details] -============================================================================ */ - -#include "unity.h" -#include - -#include "driver/uart.h" -#include "uart_driver.h" -#include - -#ifdef AVR -#include -#else -#define PROGMEM -#endif - -/* If omitted from header, declare overrideable prototypes here so they're ready for use */ -#ifdef UNITY_OMIT_OUTPUT_CHAR_HEADER_DECLARATION -void UNITY_OUTPUT_CHAR(int); -#endif - -#undef UNITY_OUTPUT_CHAR -extern bk_err_t uart_write_byte(uart_id_t id, uint8_t data); - -void UNITY_OUTPUT_CHAR(int data) -{ - (void)uart_write_byte(bk_get_printf_port(), (unsigned char)data); -} - -/* Helpful macros for us to use here in Assert functions */ -#define UNITY_FAIL_AND_BAIL { Unity.CurrentTestFailed = 1; UNITY_OUTPUT_FLUSH(); TEST_ABORT(); } -#define UNITY_IGNORE_AND_BAIL { Unity.CurrentTestIgnored = 1; UNITY_OUTPUT_FLUSH(); TEST_ABORT(); } -#define RETURN_IF_FAIL_OR_IGNORE if (Unity.CurrentTestFailed || Unity.CurrentTestIgnored) return - -struct UNITY_STORAGE_T Unity; - -#ifdef UNITY_OUTPUT_COLOR -const char PROGMEM UnityStrOk[] = "\033[42mOK\033[00m"; -const char PROGMEM UnityStrPass[] = "\033[42mPASS\033[00m"; -const char PROGMEM UnityStrFail[] = "\033[41mFAIL\033[00m"; -const char PROGMEM UnityStrIgnore[] = "\033[43mIGNORE\033[00m"; -#else -const char PROGMEM UnityStrOk[] = "OK"; -const char PROGMEM UnityStrPass[] = "PASS"; -const char PROGMEM UnityStrFail[] = "FAIL"; -const char PROGMEM UnityStrIgnore[] = "IGNORE"; -#endif -static const char PROGMEM UnityStrNull[] = "NULL"; -static const char PROGMEM UnityStrSpacer[] = ". "; -static const char PROGMEM UnityStrExpected[] = " Expected "; -static const char PROGMEM UnityStrWas[] = " Was "; -static const char PROGMEM UnityStrGt[] = " to be greater than "; -static const char PROGMEM UnityStrLt[] = " to be less than "; -static const char PROGMEM UnityStrOrEqual[] = "or equal to "; -static const char PROGMEM UnityStrElement[] = " Element "; -static const char PROGMEM UnityStrByte[] = " Byte "; -static const char PROGMEM UnityStrMemory[] = " Memory Mismatch."; -static const char PROGMEM UnityStrDelta[] = " Values Not Within Delta "; -static const char PROGMEM UnityStrPointless[] = " You Asked Me To Compare Nothing, Which Was Pointless."; -static const char PROGMEM UnityStrNullPointerForExpected[] = " Expected pointer to be NULL"; -static const char PROGMEM UnityStrNullPointerForActual[] = " Actual pointer was NULL"; -#ifndef UNITY_EXCLUDE_FLOAT -static const char PROGMEM UnityStrNot[] = "Not "; -static const char PROGMEM UnityStrInf[] = "Infinity"; -static const char PROGMEM UnityStrNegInf[] = "Negative Infinity"; -static const char PROGMEM UnityStrNaN[] = "NaN"; -static const char PROGMEM UnityStrDet[] = "Determinate"; -static const char PROGMEM UnityStrInvalidFloatTrait[] = "Invalid Float Trait"; -#endif -const char PROGMEM UnityStrErrShorthand[] = "Unity Shorthand Support Disabled"; -const char PROGMEM UnityStrErrFloat[] = "Unity Floating Point Disabled"; -const char PROGMEM UnityStrErrDouble[] = "Unity Double Precision Disabled"; -const char PROGMEM UnityStrErr64[] = "Unity 64-bit Support Disabled"; -static const char PROGMEM UnityStrBreaker[] = "-----------------------"; -static const char PROGMEM UnityStrResultsTests[] = " Tests "; -static const char PROGMEM UnityStrResultsFailures[] = " Failures "; -static const char PROGMEM UnityStrResultsIgnored[] = " Ignored "; -static const char PROGMEM UnityStrDetail1Name[] = UNITY_DETAIL1_NAME " "; -static const char PROGMEM UnityStrDetail2Name[] = " " UNITY_DETAIL2_NAME " "; - -/*----------------------------------------------- - * Pretty Printers & Test Result Output Handlers - *-----------------------------------------------*/ - -/*-----------------------------------------------*/ -/* Local helper function to print characters. */ -static void UnityPrintChar(const char* pch) -{ - /* printable characters plus CR & LF are printed */ - if ((*pch <= 126) && (*pch >= 32)) - { - UNITY_OUTPUT_CHAR(*pch); - } - /* write escaped carriage returns */ - else if (*pch == 13) - { - UNITY_OUTPUT_CHAR('\\'); - UNITY_OUTPUT_CHAR('r'); - } - /* write escaped line feeds */ - else if (*pch == 10) - { - UNITY_OUTPUT_CHAR('\\'); - UNITY_OUTPUT_CHAR('n'); - } - /* unprintable characters are shown as codes */ - else - { - UNITY_OUTPUT_CHAR('\\'); - UNITY_OUTPUT_CHAR('x'); - UnityPrintNumberHex((UNITY_UINT)*pch, 2); - } -} - -/*-----------------------------------------------*/ -/* Local helper function to print ANSI escape strings e.g. "\033[42m". */ -#ifdef UNITY_OUTPUT_COLOR -static UNITY_UINT UnityPrintAnsiEscapeString(const char* string) -{ - const char* pch = string; - UNITY_UINT count = 0; - - while (*pch && (*pch != 'm')) - { - UNITY_OUTPUT_CHAR(*pch); - pch++; - count++; - } - UNITY_OUTPUT_CHAR('m'); - count++; - - return count; -} -#endif - -/*-----------------------------------------------*/ -void UnityPrint(const char* string) -{ - const char* pch = string; - - if (pch != NULL) - { - while (*pch) - { -#ifdef UNITY_OUTPUT_COLOR - /* print ANSI escape code */ - if ((*pch == 27) && (*(pch + 1) == '[')) - { - pch += UnityPrintAnsiEscapeString(pch); - continue; - } -#endif - UnityPrintChar(pch); - pch++; - } - } -} - -/*-----------------------------------------------*/ -#ifdef UNITY_INCLUDE_PRINT_FORMATTED -void UnityPrintFormatted(const char* format, ...) -{ - const char* pch = format; - va_list va; - va_start(va, format); - - if (pch != NULL) - { - while (*pch) - { - /* format identification character */ - if (*pch == '%') - { - pch++; - - if (pch != NULL) - { - switch (*pch) - { - case 'd': - case 'i': - { - const int number = va_arg(va, int); - UnityPrintNumber((UNITY_INT)number); - break; - } -#ifndef UNITY_EXCLUDE_FLOAT_PRINT - case 'f': - case 'g': - { - const double number = va_arg(va, double); - UnityPrintFloat((UNITY_DOUBLE)number); - break; - } -#endif - case 'u': - { - const unsigned int number = va_arg(va, unsigned int); - UnityPrintNumberUnsigned((UNITY_UINT)number); - break; - } - case 'b': - { - const unsigned int number = va_arg(va, unsigned int); - const UNITY_UINT mask = (UNITY_UINT)0 - (UNITY_UINT)1; - UNITY_OUTPUT_CHAR('0'); - UNITY_OUTPUT_CHAR('b'); - UnityPrintMask(mask, (UNITY_UINT)number); - break; - } - case 'x': - case 'X': - case 'p': - { - const unsigned int number = va_arg(va, unsigned int); - UNITY_OUTPUT_CHAR('0'); - UNITY_OUTPUT_CHAR('x'); - UnityPrintNumberHex((UNITY_UINT)number, 8); - break; - } - case 'c': - { - const int ch = va_arg(va, int); - UnityPrintChar((const char *)&ch); - break; - } - case 's': - { - const char * string = va_arg(va, const char *); - UnityPrint(string); - break; - } - case '%': - { - UnityPrintChar(pch); - break; - } - default: - { - /* print the unknown format character */ - UNITY_OUTPUT_CHAR('%'); - UnityPrintChar(pch); - break; - } - } - } - } -#ifdef UNITY_OUTPUT_COLOR - /* print ANSI escape code */ - else if ((*pch == 27) && (*(pch + 1) == '[')) - { - pch += UnityPrintAnsiEscapeString(pch); - continue; - } -#endif - else if (*pch == '\n') - { - UNITY_PRINT_EOL(); - } - else - { - UnityPrintChar(pch); - } - - pch++; - } - } - - va_end(va); -} -#endif /* ! UNITY_INCLUDE_PRINT_FORMATTED */ - -/*-----------------------------------------------*/ -void UnityPrintLen(const char* string, const UNITY_UINT32 length) -{ - const char* pch = string; - - if (pch != NULL) - { - while (*pch && ((UNITY_UINT32)(pch - string) < length)) - { - /* printable characters plus CR & LF are printed */ - if ((*pch <= 126) && (*pch >= 32)) - { - UNITY_OUTPUT_CHAR(*pch); - } - /* write escaped carriage returns */ - else if (*pch == 13) - { - UNITY_OUTPUT_CHAR('\\'); - UNITY_OUTPUT_CHAR('r'); - } - /* write escaped line feeds */ - else if (*pch == 10) - { - UNITY_OUTPUT_CHAR('\\'); - UNITY_OUTPUT_CHAR('n'); - } - /* unprintable characters are shown as codes */ - else - { - UNITY_OUTPUT_CHAR('\\'); - UNITY_OUTPUT_CHAR('x'); - UnityPrintNumberHex((UNITY_UINT)*pch, 2); - } - pch++; - } - } -} - -/*-----------------------------------------------*/ -void UnityPrintNumberByStyle(const UNITY_INT number, const UNITY_DISPLAY_STYLE_T style) -{ - if ((style & UNITY_DISPLAY_RANGE_INT) == UNITY_DISPLAY_RANGE_INT) - { - UnityPrintNumber(number); - } - else if ((style & UNITY_DISPLAY_RANGE_UINT) == UNITY_DISPLAY_RANGE_UINT) - { - UnityPrintNumberUnsigned((UNITY_UINT)number); - } - else - { - UNITY_OUTPUT_CHAR('0'); - UNITY_OUTPUT_CHAR('x'); - UnityPrintNumberHex((UNITY_UINT)number, (char)((style & 0xF) * 2)); - } -} - -/*-----------------------------------------------*/ -void UnityPrintNumber(const UNITY_INT number_to_print) -{ - UNITY_UINT number = (UNITY_UINT)number_to_print; - - if (number_to_print < 0) - { - /* A negative number, including MIN negative */ - UNITY_OUTPUT_CHAR('-'); - number = (UNITY_UINT)-number_to_print; - } - UnityPrintNumberUnsigned(number); -} - -/*----------------------------------------------- - * basically do an itoa using as little ram as possible */ -void UnityPrintNumberUnsigned(const UNITY_UINT number) -{ - UNITY_UINT divisor = 1; - - /* figure out initial divisor */ - while (number / divisor > 9) - { - divisor *= 10; - } - - /* now mod and print, then divide divisor */ - do - { - UNITY_OUTPUT_CHAR((char)('0' + (number / divisor % 10))); - divisor /= 10; - } while (divisor > 0); -} - -/*-----------------------------------------------*/ -void UnityPrintNumberHex(const UNITY_UINT number, const char nibbles_to_print) -{ - int nibble; - char nibbles = nibbles_to_print; - - if ((unsigned)nibbles > UNITY_MAX_NIBBLES) - { - nibbles = UNITY_MAX_NIBBLES; - } - - while (nibbles > 0) - { - nibbles--; - nibble = (int)(number >> (nibbles * 4)) & 0x0F; - if (nibble <= 9) - { - UNITY_OUTPUT_CHAR((char)('0' + nibble)); - } - else - { - UNITY_OUTPUT_CHAR((char)('A' - 10 + nibble)); - } - } -} - -/*-----------------------------------------------*/ -void UnityPrintMask(const UNITY_UINT mask, const UNITY_UINT number) -{ - UNITY_UINT current_bit = (UNITY_UINT)1 << (UNITY_INT_WIDTH - 1); - UNITY_INT32 i; - - for (i = 0; i < UNITY_INT_WIDTH; i++) - { - if (current_bit & mask) - { - if (current_bit & number) - { - UNITY_OUTPUT_CHAR('1'); - } - else - { - UNITY_OUTPUT_CHAR('0'); - } - } - else - { - UNITY_OUTPUT_CHAR('X'); - } - current_bit = current_bit >> 1; - } -} - -/*-----------------------------------------------*/ -#ifndef UNITY_EXCLUDE_FLOAT_PRINT -/* - * This function prints a floating-point value in a format similar to - * printf("%.7g") on a single-precision machine or printf("%.9g") on a - * double-precision machine. The 7th digit won't always be totally correct - * in single-precision operation (for that level of accuracy, a more - * complicated algorithm would be needed). - */ -void UnityPrintFloat(const UNITY_DOUBLE input_number) -{ -#ifdef UNITY_INCLUDE_DOUBLE - static const int sig_digits = 9; - static const UNITY_INT32 min_scaled = 100000000; - static const UNITY_INT32 max_scaled = 1000000000; -#else - static const int sig_digits = 7; - static const UNITY_INT32 min_scaled = 1000000; - static const UNITY_INT32 max_scaled = 10000000; -#endif - - UNITY_DOUBLE number = input_number; - - /* print minus sign (including for negative zero) */ - if ((number < 0.0f) || ((number == 0.0f) && ((1.0f / number) < 0.0f))) - { - UNITY_OUTPUT_CHAR('-'); - number = -number; - } - - /* handle zero, NaN, and +/- infinity */ - if (number == 0.0f) - { - UnityPrint("0"); - } - else if (isnan(number)) - { - UnityPrint("nan"); - } - else if (isinf(number)) - { - UnityPrint("inf"); - } - else - { - UNITY_INT32 n_int = 0, n; - int exponent = 0; - int decimals, digits; - char buf[16] = {0}; - - /* - * Scale up or down by powers of 10. To minimize rounding error, - * start with a factor/divisor of 10^10, which is the largest - * power of 10 that can be represented exactly. Finally, compute - * (exactly) the remaining power of 10 and perform one more - * multiplication or division. - */ - if (number < 1.0f) - { - UNITY_DOUBLE factor = 1.0f; - - while (number < (UNITY_DOUBLE)max_scaled / 1e10f) { number *= 1e10f; exponent -= 10; } - while (number * factor < (UNITY_DOUBLE)min_scaled) { factor *= 10.0f; exponent--; } - - number *= factor; - } - else if (number > (UNITY_DOUBLE)max_scaled) - { - UNITY_DOUBLE divisor = 1.0f; - - while (number > (UNITY_DOUBLE)min_scaled * 1e10f) { number /= 1e10f; exponent += 10; } - while (number / divisor > (UNITY_DOUBLE)max_scaled) { divisor *= 10.0f; exponent++; } - - number /= divisor; - } - else - { - /* - * In this range, we can split off the integer part before - * doing any multiplications. This reduces rounding error by - * freeing up significant bits in the fractional part. - */ - UNITY_DOUBLE factor = 1.0f; - n_int = (UNITY_INT32)number; - number -= (UNITY_DOUBLE)n_int; - - while (n_int < min_scaled) { n_int *= 10; factor *= 10.0f; exponent--; } - - number *= factor; - } - - /* round to nearest integer */ - n = ((UNITY_INT32)(number + number) + 1) / 2; - -#ifndef UNITY_ROUND_TIES_AWAY_FROM_ZERO - /* round to even if exactly between two integers */ - if ((n & 1) && (((UNITY_DOUBLE)n - number) == 0.5f)) - n--; -#endif - - n += n_int; - - if (n >= max_scaled) - { - n = min_scaled; - exponent++; - } - - /* determine where to place decimal point */ - decimals = ((exponent <= 0) && (exponent >= -(sig_digits + 3))) ? (-exponent) : (sig_digits - 1); - exponent += decimals; - - /* truncate trailing zeroes after decimal point */ - while ((decimals > 0) && ((n % 10) == 0)) - { - n /= 10; - decimals--; - } - - /* build up buffer in reverse order */ - digits = 0; - while ((n != 0) || (digits < (decimals + 1))) - { - buf[digits++] = (char)('0' + n % 10); - n /= 10; - } - while (digits > 0) - { - if (digits == decimals) { UNITY_OUTPUT_CHAR('.'); } - UNITY_OUTPUT_CHAR(buf[--digits]); - } - - /* print exponent if needed */ - if (exponent != 0) - { - UNITY_OUTPUT_CHAR('e'); - - if (exponent < 0) - { - UNITY_OUTPUT_CHAR('-'); - exponent = -exponent; - } - else - { - UNITY_OUTPUT_CHAR('+'); - } - - digits = 0; - while ((exponent != 0) || (digits < 2)) - { - buf[digits++] = (char)('0' + exponent % 10); - exponent /= 10; - } - while (digits > 0) - { - UNITY_OUTPUT_CHAR(buf[--digits]); - } - } - } -} -#endif /* ! UNITY_EXCLUDE_FLOAT_PRINT */ - -/*-----------------------------------------------*/ -static void UnityTestResultsBegin(const char* file, const UNITY_LINE_TYPE line) -{ - UnityPrint(file); - UNITY_OUTPUT_CHAR(':'); - UnityPrintNumber((UNITY_INT)line); - UNITY_OUTPUT_CHAR(':'); - UnityPrint(Unity.CurrentTestName); - UNITY_OUTPUT_CHAR(':'); -} - -/*-----------------------------------------------*/ -static void UnityTestResultsFailBegin(const UNITY_LINE_TYPE line) -{ - UnityTestResultsBegin(Unity.TestFile, line); - UnityPrint(UnityStrFail); - UNITY_OUTPUT_CHAR(':'); -} - -/*-----------------------------------------------*/ -void UnityConcludeTest(void) -{ - if (Unity.CurrentTestIgnored) - { - Unity.TestIgnores++; - } - else if (!Unity.CurrentTestFailed) - { - UnityTestResultsBegin(Unity.TestFile, Unity.CurrentTestLineNumber); - UnityPrint(UnityStrPass); - } - else - { - Unity.TestFailures++; - } - - Unity.CurrentTestFailed = 0; - Unity.CurrentTestIgnored = 0; - UNITY_PRINT_EXEC_TIME(); - UNITY_PRINT_EOL(); - UNITY_FLUSH_CALL(); -} - -/*-----------------------------------------------*/ -static void UnityAddMsgIfSpecified(const char* msg) -{ - if (msg) - { - UnityPrint(UnityStrSpacer); -#ifndef UNITY_EXCLUDE_DETAILS - if (Unity.CurrentDetail1) - { - UnityPrint(UnityStrDetail1Name); - UnityPrint(Unity.CurrentDetail1); - if (Unity.CurrentDetail2) - { - UnityPrint(UnityStrDetail2Name); - UnityPrint(Unity.CurrentDetail2); - } - UnityPrint(UnityStrSpacer); - } -#endif - UnityPrint(msg); - } -} - -/*-----------------------------------------------*/ -static void UnityPrintExpectedAndActualStrings(const char* expected, const char* actual) -{ - UnityPrint(UnityStrExpected); - if (expected != NULL) - { - UNITY_OUTPUT_CHAR('\''); - UnityPrint(expected); - UNITY_OUTPUT_CHAR('\''); - } - else - { - UnityPrint(UnityStrNull); - } - UnityPrint(UnityStrWas); - if (actual != NULL) - { - UNITY_OUTPUT_CHAR('\''); - UnityPrint(actual); - UNITY_OUTPUT_CHAR('\''); - } - else - { - UnityPrint(UnityStrNull); - } -} - -/*-----------------------------------------------*/ -static void UnityPrintExpectedAndActualStringsLen(const char* expected, - const char* actual, - const UNITY_UINT32 length) -{ - UnityPrint(UnityStrExpected); - if (expected != NULL) - { - UNITY_OUTPUT_CHAR('\''); - UnityPrintLen(expected, length); - UNITY_OUTPUT_CHAR('\''); - } - else - { - UnityPrint(UnityStrNull); - } - UnityPrint(UnityStrWas); - if (actual != NULL) - { - UNITY_OUTPUT_CHAR('\''); - UnityPrintLen(actual, length); - UNITY_OUTPUT_CHAR('\''); - } - else - { - UnityPrint(UnityStrNull); - } -} - -/*----------------------------------------------- - * Assertion & Control Helpers - *-----------------------------------------------*/ - -/*-----------------------------------------------*/ -static int UnityIsOneArrayNull(UNITY_INTERNAL_PTR expected, - UNITY_INTERNAL_PTR actual, - const UNITY_LINE_TYPE lineNumber, - const char* msg) -{ - /* Both are NULL or same pointer */ - if (expected == actual) { return 0; } - - /* print and return true if just expected is NULL */ - if (expected == NULL) - { - UnityTestResultsFailBegin(lineNumber); - UnityPrint(UnityStrNullPointerForExpected); - UnityAddMsgIfSpecified(msg); - return 1; - } - - /* print and return true if just actual is NULL */ - if (actual == NULL) - { - UnityTestResultsFailBegin(lineNumber); - UnityPrint(UnityStrNullPointerForActual); - UnityAddMsgIfSpecified(msg); - return 1; - } - - return 0; /* return false if neither is NULL */ -} - -/*----------------------------------------------- - * Assertion Functions - *-----------------------------------------------*/ - -/*-----------------------------------------------*/ -void UnityAssertBits(const UNITY_INT mask, - const UNITY_INT expected, - const UNITY_INT actual, - const char* msg, - const UNITY_LINE_TYPE lineNumber) -{ - RETURN_IF_FAIL_OR_IGNORE; - - if ((mask & expected) != (mask & actual)) - { - UnityTestResultsFailBegin(lineNumber); - UnityPrint(UnityStrExpected); - UnityPrintMask((UNITY_UINT)mask, (UNITY_UINT)expected); - UnityPrint(UnityStrWas); - UnityPrintMask((UNITY_UINT)mask, (UNITY_UINT)actual); - UnityAddMsgIfSpecified(msg); - UNITY_FAIL_AND_BAIL; - } -} - -/*-----------------------------------------------*/ -void UnityAssertEqualNumber(const UNITY_INT expected, - const UNITY_INT actual, - const char* msg, - const UNITY_LINE_TYPE lineNumber, - const UNITY_DISPLAY_STYLE_T style) -{ - RETURN_IF_FAIL_OR_IGNORE; - - if (expected != actual) - { - UnityTestResultsFailBegin(lineNumber); - UnityPrint(UnityStrExpected); - UnityPrintNumberByStyle(expected, style); - UnityPrint(UnityStrWas); - UnityPrintNumberByStyle(actual, style); - UnityAddMsgIfSpecified(msg); - UNITY_FAIL_AND_BAIL; - } -} - -/*-----------------------------------------------*/ -void UnityAssertGreaterOrLessOrEqualNumber(const UNITY_INT threshold, - const UNITY_INT actual, - const UNITY_COMPARISON_T compare, - const char *msg, - const UNITY_LINE_TYPE lineNumber, - const UNITY_DISPLAY_STYLE_T style) -{ - int failed = 0; - RETURN_IF_FAIL_OR_IGNORE; - - if ((threshold == actual) && (compare & UNITY_EQUAL_TO)) { return; } - if ((threshold == actual)) { failed = 1; } - - if ((style & UNITY_DISPLAY_RANGE_INT) == UNITY_DISPLAY_RANGE_INT) - { - if ((actual > threshold) && (compare & UNITY_SMALLER_THAN)) { failed = 1; } - if ((actual < threshold) && (compare & UNITY_GREATER_THAN)) { failed = 1; } - } - else /* UINT or HEX */ - { - if (((UNITY_UINT)actual > (UNITY_UINT)threshold) && (compare & UNITY_SMALLER_THAN)) { failed = 1; } - if (((UNITY_UINT)actual < (UNITY_UINT)threshold) && (compare & UNITY_GREATER_THAN)) { failed = 1; } - } - - if (failed) - { - UnityTestResultsFailBegin(lineNumber); - UnityPrint(UnityStrExpected); - UnityPrintNumberByStyle(actual, style); - if (compare & UNITY_GREATER_THAN) { UnityPrint(UnityStrGt); } - if (compare & UNITY_SMALLER_THAN) { UnityPrint(UnityStrLt); } - if (compare & UNITY_EQUAL_TO) { UnityPrint(UnityStrOrEqual); } - UnityPrintNumberByStyle(threshold, style); - UnityAddMsgIfSpecified(msg); - UNITY_FAIL_AND_BAIL; - } -} - -#define UnityPrintPointlessAndBail() \ -{ \ - UnityTestResultsFailBegin(lineNumber); \ - UnityPrint(UnityStrPointless); \ - UnityAddMsgIfSpecified(msg); \ - UNITY_FAIL_AND_BAIL; } - -/*-----------------------------------------------*/ -void UnityAssertEqualIntArray(UNITY_INTERNAL_PTR expected, - UNITY_INTERNAL_PTR actual, - const UNITY_UINT32 num_elements, - const char* msg, - const UNITY_LINE_TYPE lineNumber, - const UNITY_DISPLAY_STYLE_T style, - const UNITY_FLAGS_T flags) -{ - UNITY_UINT32 elements = num_elements; - unsigned int length = style & 0xF; - unsigned int increment = 0; - - RETURN_IF_FAIL_OR_IGNORE; - - if (num_elements == 0) - { - UnityPrintPointlessAndBail(); - } - - if (expected == actual) - { - return; /* Both are NULL or same pointer */ - } - - if (UnityIsOneArrayNull(expected, actual, lineNumber, msg)) - { - UNITY_FAIL_AND_BAIL; - } - - while ((elements > 0) && (elements--)) - { - UNITY_INT expect_val; - UNITY_INT actual_val; - - switch (length) - { - case 1: - expect_val = *(UNITY_PTR_ATTRIBUTE const UNITY_INT8*)expected; - actual_val = *(UNITY_PTR_ATTRIBUTE const UNITY_INT8*)actual; - increment = sizeof(UNITY_INT8); - break; - - case 2: - expect_val = *(UNITY_PTR_ATTRIBUTE const UNITY_INT16*)expected; - actual_val = *(UNITY_PTR_ATTRIBUTE const UNITY_INT16*)actual; - increment = sizeof(UNITY_INT16); - break; - -#ifdef UNITY_SUPPORT_64 - case 8: - expect_val = *(UNITY_PTR_ATTRIBUTE const UNITY_INT64*)expected; - actual_val = *(UNITY_PTR_ATTRIBUTE const UNITY_INT64*)actual; - increment = sizeof(UNITY_INT64); - break; -#endif - - default: /* default is length 4 bytes */ - case 4: - expect_val = *(UNITY_PTR_ATTRIBUTE const UNITY_INT32*)expected; - actual_val = *(UNITY_PTR_ATTRIBUTE const UNITY_INT32*)actual; - increment = sizeof(UNITY_INT32); - length = 4; - break; - } - - if (expect_val != actual_val) - { - if ((style & UNITY_DISPLAY_RANGE_UINT) && (length < (UNITY_INT_WIDTH / 8))) - { /* For UINT, remove sign extension (padding 1's) from signed type casts above */ - UNITY_INT mask = 1; - mask = (mask << 8 * length) - 1; - expect_val &= mask; - actual_val &= mask; - } - UnityTestResultsFailBegin(lineNumber); - UnityPrint(UnityStrElement); - UnityPrintNumberUnsigned(num_elements - elements - 1); - UnityPrint(UnityStrExpected); - UnityPrintNumberByStyle(expect_val, style); - UnityPrint(UnityStrWas); - UnityPrintNumberByStyle(actual_val, style); - UnityAddMsgIfSpecified(msg); - UNITY_FAIL_AND_BAIL; - } - /* Walk through array by incrementing the pointers */ - if (flags == UNITY_ARRAY_TO_ARRAY) - { - expected = (UNITY_INTERNAL_PTR)((const char*)expected + increment); - } - actual = (UNITY_INTERNAL_PTR)((const char*)actual + increment); - } -} - -/*-----------------------------------------------*/ -#ifndef UNITY_EXCLUDE_FLOAT -/* Wrap this define in a function with variable types as float or double */ -#define UNITY_FLOAT_OR_DOUBLE_WITHIN(delta, expected, actual, diff) \ - if (isinf(expected) && isinf(actual) && (((expected) < 0) == ((actual) < 0))) return 1; \ - if (UNITY_NAN_CHECK) return 1; \ - (diff) = (actual) - (expected); \ - if ((diff) < 0) (diff) = -(diff); \ - if ((delta) < 0) (delta) = -(delta); \ - return !(isnan(diff) || isinf(diff) || ((diff) > (delta))) - /* This first part of this condition will catch any NaN or Infinite values */ -#ifndef UNITY_NAN_NOT_EQUAL_NAN - #define UNITY_NAN_CHECK isnan(expected) && isnan(actual) -#else - #define UNITY_NAN_CHECK 0 -#endif - -#ifndef UNITY_EXCLUDE_FLOAT_PRINT - #define UNITY_PRINT_EXPECTED_AND_ACTUAL_FLOAT(expected, actual) \ - { \ - UnityPrint(UnityStrExpected); \ - UnityPrintFloat(expected); \ - UnityPrint(UnityStrWas); \ - UnityPrintFloat(actual); } -#else - #define UNITY_PRINT_EXPECTED_AND_ACTUAL_FLOAT(expected, actual) \ - UnityPrint(UnityStrDelta) -#endif /* UNITY_EXCLUDE_FLOAT_PRINT */ - -/*-----------------------------------------------*/ -static int UnityFloatsWithin(UNITY_FLOAT delta, UNITY_FLOAT expected, UNITY_FLOAT actual) -{ - UNITY_FLOAT diff; - UNITY_FLOAT_OR_DOUBLE_WITHIN(delta, expected, actual, diff); -} - -/*-----------------------------------------------*/ -void UnityAssertEqualFloatArray(UNITY_PTR_ATTRIBUTE const UNITY_FLOAT* expected, - UNITY_PTR_ATTRIBUTE const UNITY_FLOAT* actual, - const UNITY_UINT32 num_elements, - const char* msg, - const UNITY_LINE_TYPE lineNumber, - const UNITY_FLAGS_T flags) -{ - UNITY_UINT32 elements = num_elements; - UNITY_PTR_ATTRIBUTE const UNITY_FLOAT* ptr_expected = expected; - UNITY_PTR_ATTRIBUTE const UNITY_FLOAT* ptr_actual = actual; - - RETURN_IF_FAIL_OR_IGNORE; - - if (elements == 0) - { - UnityPrintPointlessAndBail(); - } - - if (expected == actual) - { - return; /* Both are NULL or same pointer */ - } - - if (UnityIsOneArrayNull((UNITY_INTERNAL_PTR)expected, (UNITY_INTERNAL_PTR)actual, lineNumber, msg)) - { - UNITY_FAIL_AND_BAIL; - } - - while (elements--) - { - if (!UnityFloatsWithin(*ptr_expected * UNITY_FLOAT_PRECISION, *ptr_expected, *ptr_actual)) - { - UnityTestResultsFailBegin(lineNumber); - UnityPrint(UnityStrElement); - UnityPrintNumberUnsigned(num_elements - elements - 1); - UNITY_PRINT_EXPECTED_AND_ACTUAL_FLOAT((UNITY_DOUBLE)*ptr_expected, (UNITY_DOUBLE)*ptr_actual); - UnityAddMsgIfSpecified(msg); - UNITY_FAIL_AND_BAIL; - } - if (flags == UNITY_ARRAY_TO_ARRAY) - { - ptr_expected++; - } - ptr_actual++; - } -} - -/*-----------------------------------------------*/ -void UnityAssertFloatsWithin(const UNITY_FLOAT delta, - const UNITY_FLOAT expected, - const UNITY_FLOAT actual, - const char* msg, - const UNITY_LINE_TYPE lineNumber) -{ - RETURN_IF_FAIL_OR_IGNORE; - - - if (!UnityFloatsWithin(delta, expected, actual)) - { - UnityTestResultsFailBegin(lineNumber); - UNITY_PRINT_EXPECTED_AND_ACTUAL_FLOAT((UNITY_DOUBLE)expected, (UNITY_DOUBLE)actual); - UnityAddMsgIfSpecified(msg); - UNITY_FAIL_AND_BAIL; - } -} - -/*-----------------------------------------------*/ -void UnityAssertFloatSpecial(const UNITY_FLOAT actual, - const char* msg, - const UNITY_LINE_TYPE lineNumber, - const UNITY_FLOAT_TRAIT_T style) -{ - const char* trait_names[] = {UnityStrInf, UnityStrNegInf, UnityStrNaN, UnityStrDet}; - UNITY_INT should_be_trait = ((UNITY_INT)style & 1); - UNITY_INT is_trait = !should_be_trait; - UNITY_INT trait_index = (UNITY_INT)(style >> 1); - - RETURN_IF_FAIL_OR_IGNORE; - - switch (style) - { - case UNITY_FLOAT_IS_INF: - case UNITY_FLOAT_IS_NOT_INF: - is_trait = isinf(actual) && (actual > 0); - break; - case UNITY_FLOAT_IS_NEG_INF: - case UNITY_FLOAT_IS_NOT_NEG_INF: - is_trait = isinf(actual) && (actual < 0); - break; - - case UNITY_FLOAT_IS_NAN: - case UNITY_FLOAT_IS_NOT_NAN: - is_trait = isnan(actual) ? 1 : 0; - break; - - case UNITY_FLOAT_IS_DET: /* A determinate number is non infinite and not NaN. */ - case UNITY_FLOAT_IS_NOT_DET: - is_trait = !isinf(actual) && !isnan(actual); - break; - - default: - trait_index = 0; - trait_names[0] = UnityStrInvalidFloatTrait; - break; - } - - if (is_trait != should_be_trait) - { - UnityTestResultsFailBegin(lineNumber); - UnityPrint(UnityStrExpected); - if (!should_be_trait) - { - UnityPrint(UnityStrNot); - } - UnityPrint(trait_names[trait_index]); - UnityPrint(UnityStrWas); -#ifndef UNITY_EXCLUDE_FLOAT_PRINT - UnityPrintFloat((UNITY_DOUBLE)actual); -#else - if (should_be_trait) - { - UnityPrint(UnityStrNot); - } - UnityPrint(trait_names[trait_index]); -#endif - UnityAddMsgIfSpecified(msg); - UNITY_FAIL_AND_BAIL; - } -} - -#endif /* not UNITY_EXCLUDE_FLOAT */ - -/*-----------------------------------------------*/ -#ifndef UNITY_EXCLUDE_DOUBLE -static int UnityDoublesWithin(UNITY_DOUBLE delta, UNITY_DOUBLE expected, UNITY_DOUBLE actual) -{ - UNITY_DOUBLE diff; - UNITY_FLOAT_OR_DOUBLE_WITHIN(delta, expected, actual, diff); -} - -/*-----------------------------------------------*/ -void UnityAssertEqualDoubleArray(UNITY_PTR_ATTRIBUTE const UNITY_DOUBLE* expected, - UNITY_PTR_ATTRIBUTE const UNITY_DOUBLE* actual, - const UNITY_UINT32 num_elements, - const char* msg, - const UNITY_LINE_TYPE lineNumber, - const UNITY_FLAGS_T flags) -{ - UNITY_UINT32 elements = num_elements; - UNITY_PTR_ATTRIBUTE const UNITY_DOUBLE* ptr_expected = expected; - UNITY_PTR_ATTRIBUTE const UNITY_DOUBLE* ptr_actual = actual; - - RETURN_IF_FAIL_OR_IGNORE; - - if (elements == 0) - { - UnityPrintPointlessAndBail(); - } - - if (expected == actual) - { - return; /* Both are NULL or same pointer */ - } - - if (UnityIsOneArrayNull((UNITY_INTERNAL_PTR)expected, (UNITY_INTERNAL_PTR)actual, lineNumber, msg)) - { - UNITY_FAIL_AND_BAIL; - } - - while (elements--) - { - if (!UnityDoublesWithin(*ptr_expected * UNITY_DOUBLE_PRECISION, *ptr_expected, *ptr_actual)) - { - UnityTestResultsFailBegin(lineNumber); - UnityPrint(UnityStrElement); - UnityPrintNumberUnsigned(num_elements - elements - 1); - UNITY_PRINT_EXPECTED_AND_ACTUAL_FLOAT(*ptr_expected, *ptr_actual); - UnityAddMsgIfSpecified(msg); - UNITY_FAIL_AND_BAIL; - } - if (flags == UNITY_ARRAY_TO_ARRAY) - { - ptr_expected++; - } - ptr_actual++; - } -} - -/*-----------------------------------------------*/ -void UnityAssertDoublesWithin(const UNITY_DOUBLE delta, - const UNITY_DOUBLE expected, - const UNITY_DOUBLE actual, - const char* msg, - const UNITY_LINE_TYPE lineNumber) -{ - RETURN_IF_FAIL_OR_IGNORE; - - if (!UnityDoublesWithin(delta, expected, actual)) - { - UnityTestResultsFailBegin(lineNumber); - UNITY_PRINT_EXPECTED_AND_ACTUAL_FLOAT(expected, actual); - UnityAddMsgIfSpecified(msg); - UNITY_FAIL_AND_BAIL; - } -} - -/*-----------------------------------------------*/ -void UnityAssertDoubleSpecial(const UNITY_DOUBLE actual, - const char* msg, - const UNITY_LINE_TYPE lineNumber, - const UNITY_FLOAT_TRAIT_T style) -{ - const char* trait_names[] = {UnityStrInf, UnityStrNegInf, UnityStrNaN, UnityStrDet}; - UNITY_INT should_be_trait = ((UNITY_INT)style & 1); - UNITY_INT is_trait = !should_be_trait; - UNITY_INT trait_index = (UNITY_INT)(style >> 1); - - RETURN_IF_FAIL_OR_IGNORE; - - switch (style) - { - case UNITY_FLOAT_IS_INF: - case UNITY_FLOAT_IS_NOT_INF: - is_trait = isinf(actual) && (actual > 0); - break; - case UNITY_FLOAT_IS_NEG_INF: - case UNITY_FLOAT_IS_NOT_NEG_INF: - is_trait = isinf(actual) && (actual < 0); - break; - - case UNITY_FLOAT_IS_NAN: - case UNITY_FLOAT_IS_NOT_NAN: - is_trait = isnan(actual) ? 1 : 0; - break; - - case UNITY_FLOAT_IS_DET: /* A determinate number is non infinite and not NaN. */ - case UNITY_FLOAT_IS_NOT_DET: - is_trait = !isinf(actual) && !isnan(actual); - break; - - default: - trait_index = 0; - trait_names[0] = UnityStrInvalidFloatTrait; - break; - } - - if (is_trait != should_be_trait) - { - UnityTestResultsFailBegin(lineNumber); - UnityPrint(UnityStrExpected); - if (!should_be_trait) - { - UnityPrint(UnityStrNot); - } - UnityPrint(trait_names[trait_index]); - UnityPrint(UnityStrWas); -#ifndef UNITY_EXCLUDE_FLOAT_PRINT - UnityPrintFloat(actual); -#else - if (should_be_trait) - { - UnityPrint(UnityStrNot); - } - UnityPrint(trait_names[trait_index]); -#endif - UnityAddMsgIfSpecified(msg); - UNITY_FAIL_AND_BAIL; - } -} - -#endif /* not UNITY_EXCLUDE_DOUBLE */ - -/*-----------------------------------------------*/ -void UnityAssertNumbersWithin(const UNITY_UINT delta, - const UNITY_INT expected, - const UNITY_INT actual, - const char* msg, - const UNITY_LINE_TYPE lineNumber, - const UNITY_DISPLAY_STYLE_T style) -{ - RETURN_IF_FAIL_OR_IGNORE; - - if ((style & UNITY_DISPLAY_RANGE_INT) == UNITY_DISPLAY_RANGE_INT) - { - if (actual > expected) - { - Unity.CurrentTestFailed = (((UNITY_UINT)actual - (UNITY_UINT)expected) > delta); - } - else - { - Unity.CurrentTestFailed = (((UNITY_UINT)expected - (UNITY_UINT)actual) > delta); - } - } - else - { - if ((UNITY_UINT)actual > (UNITY_UINT)expected) - { - Unity.CurrentTestFailed = (((UNITY_UINT)actual - (UNITY_UINT)expected) > delta); - } - else - { - Unity.CurrentTestFailed = (((UNITY_UINT)expected - (UNITY_UINT)actual) > delta); - } - } - - if (Unity.CurrentTestFailed) - { - UnityTestResultsFailBegin(lineNumber); - UnityPrint(UnityStrDelta); - UnityPrintNumberByStyle((UNITY_INT)delta, style); - UnityPrint(UnityStrExpected); - UnityPrintNumberByStyle(expected, style); - UnityPrint(UnityStrWas); - UnityPrintNumberByStyle(actual, style); - UnityAddMsgIfSpecified(msg); - UNITY_FAIL_AND_BAIL; - } -} - -/*-----------------------------------------------*/ -void UnityAssertNumbersArrayWithin(const UNITY_UINT delta, - UNITY_INTERNAL_PTR expected, - UNITY_INTERNAL_PTR actual, - const UNITY_UINT32 num_elements, - const char* msg, - const UNITY_LINE_TYPE lineNumber, - const UNITY_DISPLAY_STYLE_T style, - const UNITY_FLAGS_T flags) -{ - UNITY_UINT32 elements = num_elements; - unsigned int length = style & 0xF; - unsigned int increment = 0; - - RETURN_IF_FAIL_OR_IGNORE; - - if (num_elements == 0) - { - UnityPrintPointlessAndBail(); - } - - if (expected == actual) - { - return; /* Both are NULL or same pointer */ - } - - if (UnityIsOneArrayNull(expected, actual, lineNumber, msg)) - { - UNITY_FAIL_AND_BAIL; - } - - while ((elements > 0) && (elements--)) - { - UNITY_INT expect_val; - UNITY_INT actual_val; - - switch (length) - { - case 1: - expect_val = *(UNITY_PTR_ATTRIBUTE const UNITY_INT8*)expected; - actual_val = *(UNITY_PTR_ATTRIBUTE const UNITY_INT8*)actual; - increment = sizeof(UNITY_INT8); - break; - - case 2: - expect_val = *(UNITY_PTR_ATTRIBUTE const UNITY_INT16*)expected; - actual_val = *(UNITY_PTR_ATTRIBUTE const UNITY_INT16*)actual; - increment = sizeof(UNITY_INT16); - break; - -#ifdef UNITY_SUPPORT_64 - case 8: - expect_val = *(UNITY_PTR_ATTRIBUTE const UNITY_INT64*)expected; - actual_val = *(UNITY_PTR_ATTRIBUTE const UNITY_INT64*)actual; - increment = sizeof(UNITY_INT64); - break; -#endif - - default: /* default is length 4 bytes */ - case 4: - expect_val = *(UNITY_PTR_ATTRIBUTE const UNITY_INT32*)expected; - actual_val = *(UNITY_PTR_ATTRIBUTE const UNITY_INT32*)actual; - increment = sizeof(UNITY_INT32); - length = 4; - break; - } - - if ((style & UNITY_DISPLAY_RANGE_INT) == UNITY_DISPLAY_RANGE_INT) - { - if (actual_val > expect_val) - { - Unity.CurrentTestFailed = (((UNITY_UINT)actual_val - (UNITY_UINT)expect_val) > delta); - } - else - { - Unity.CurrentTestFailed = (((UNITY_UINT)expect_val - (UNITY_UINT)actual_val) > delta); - } - } - else - { - if ((UNITY_UINT)actual_val > (UNITY_UINT)expect_val) - { - Unity.CurrentTestFailed = (((UNITY_UINT)actual_val - (UNITY_UINT)expect_val) > delta); - } - else - { - Unity.CurrentTestFailed = (((UNITY_UINT)expect_val - (UNITY_UINT)actual_val) > delta); - } - } - - if (Unity.CurrentTestFailed) - { - if ((style & UNITY_DISPLAY_RANGE_UINT) && (length < (UNITY_INT_WIDTH / 8))) - { /* For UINT, remove sign extension (padding 1's) from signed type casts above */ - UNITY_INT mask = 1; - mask = (mask << 8 * length) - 1; - expect_val &= mask; - actual_val &= mask; - } - UnityTestResultsFailBegin(lineNumber); - UnityPrint(UnityStrDelta); - UnityPrintNumberByStyle((UNITY_INT)delta, style); - UnityPrint(UnityStrElement); - UnityPrintNumberUnsigned(num_elements - elements - 1); - UnityPrint(UnityStrExpected); - UnityPrintNumberByStyle(expect_val, style); - UnityPrint(UnityStrWas); - UnityPrintNumberByStyle(actual_val, style); - UnityAddMsgIfSpecified(msg); - UNITY_FAIL_AND_BAIL; - } - /* Walk through array by incrementing the pointers */ - if (flags == UNITY_ARRAY_TO_ARRAY) - { - expected = (UNITY_INTERNAL_PTR)((const char*)expected + increment); - } - actual = (UNITY_INTERNAL_PTR)((const char*)actual + increment); - } -} - -/*-----------------------------------------------*/ -void UnityAssertEqualString(const char* expected, - const char* actual, - const char* msg, - const UNITY_LINE_TYPE lineNumber) -{ - UNITY_UINT32 i; - - RETURN_IF_FAIL_OR_IGNORE; - - /* if both pointers not null compare the strings */ - if (expected && actual) - { - for (i = 0; expected[i] || actual[i]; i++) - { - if (expected[i] != actual[i]) - { - Unity.CurrentTestFailed = 1; - break; - } - } - } - else - { /* handle case of one pointers being null (if both null, test should pass) */ - if (expected != actual) - { - Unity.CurrentTestFailed = 1; - } - } - - if (Unity.CurrentTestFailed) - { - UnityTestResultsFailBegin(lineNumber); - UnityPrintExpectedAndActualStrings(expected, actual); - UnityAddMsgIfSpecified(msg); - UNITY_FAIL_AND_BAIL; - } -} - -/*-----------------------------------------------*/ -void UnityAssertEqualStringLen(const char* expected, - const char* actual, - const UNITY_UINT32 length, - const char* msg, - const UNITY_LINE_TYPE lineNumber) -{ - UNITY_UINT32 i; - - RETURN_IF_FAIL_OR_IGNORE; - - /* if both pointers not null compare the strings */ - if (expected && actual) - { - for (i = 0; (i < length) && (expected[i] || actual[i]); i++) - { - if (expected[i] != actual[i]) - { - Unity.CurrentTestFailed = 1; - break; - } - } - } - else - { /* handle case of one pointers being null (if both null, test should pass) */ - if (expected != actual) - { - Unity.CurrentTestFailed = 1; - } - } - - if (Unity.CurrentTestFailed) - { - UnityTestResultsFailBegin(lineNumber); - UnityPrintExpectedAndActualStringsLen(expected, actual, length); - UnityAddMsgIfSpecified(msg); - UNITY_FAIL_AND_BAIL; - } -} - -/*-----------------------------------------------*/ -void UnityAssertEqualStringArray(UNITY_INTERNAL_PTR expected, - const char** actual, - const UNITY_UINT32 num_elements, - const char* msg, - const UNITY_LINE_TYPE lineNumber, - const UNITY_FLAGS_T flags) -{ - UNITY_UINT32 i = 0; - UNITY_UINT32 j = 0; - const char* expd = NULL; - const char* act = NULL; - - RETURN_IF_FAIL_OR_IGNORE; - - /* if no elements, it's an error */ - if (num_elements == 0) - { - UnityPrintPointlessAndBail(); - } - - if ((const void*)expected == (const void*)actual) - { - return; /* Both are NULL or same pointer */ - } - - if (UnityIsOneArrayNull((UNITY_INTERNAL_PTR)expected, (UNITY_INTERNAL_PTR)actual, lineNumber, msg)) - { - UNITY_FAIL_AND_BAIL; - } - - if (flags != UNITY_ARRAY_TO_ARRAY) - { - expd = (const char*)expected; - } - - do - { - act = actual[j]; - if (flags == UNITY_ARRAY_TO_ARRAY) - { - expd = ((const char* const*)expected)[j]; - } - - /* if both pointers not null compare the strings */ - if (expd && act) - { - for (i = 0; expd[i] || act[i]; i++) - { - if (expd[i] != act[i]) - { - Unity.CurrentTestFailed = 1; - break; - } - } - } - else - { /* handle case of one pointers being null (if both null, test should pass) */ - if (expd != act) - { - Unity.CurrentTestFailed = 1; - } - } - - if (Unity.CurrentTestFailed) - { - UnityTestResultsFailBegin(lineNumber); - if (num_elements > 1) - { - UnityPrint(UnityStrElement); - UnityPrintNumberUnsigned(j); - } - UnityPrintExpectedAndActualStrings(expd, act); - UnityAddMsgIfSpecified(msg); - UNITY_FAIL_AND_BAIL; - } - } while (++j < num_elements); -} - -/*-----------------------------------------------*/ -void UnityAssertEqualMemory(UNITY_INTERNAL_PTR expected, - UNITY_INTERNAL_PTR actual, - const UNITY_UINT32 length, - const UNITY_UINT32 num_elements, - const char* msg, - const UNITY_LINE_TYPE lineNumber, - const UNITY_FLAGS_T flags) -{ - UNITY_PTR_ATTRIBUTE const unsigned char* ptr_exp = (UNITY_PTR_ATTRIBUTE const unsigned char*)expected; - UNITY_PTR_ATTRIBUTE const unsigned char* ptr_act = (UNITY_PTR_ATTRIBUTE const unsigned char*)actual; - UNITY_UINT32 elements = num_elements; - UNITY_UINT32 bytes; - - RETURN_IF_FAIL_OR_IGNORE; - - if ((elements == 0) || (length == 0)) - { - UnityPrintPointlessAndBail(); - } - - if (expected == actual) - { - return; /* Both are NULL or same pointer */ - } - - if (UnityIsOneArrayNull(expected, actual, lineNumber, msg)) - { - UNITY_FAIL_AND_BAIL; - } - - while (elements--) - { - bytes = length; - while (bytes--) - { - if (*ptr_exp != *ptr_act) - { - UnityTestResultsFailBegin(lineNumber); - UnityPrint(UnityStrMemory); - if (num_elements > 1) - { - UnityPrint(UnityStrElement); - UnityPrintNumberUnsigned(num_elements - elements - 1); - } - UnityPrint(UnityStrByte); - UnityPrintNumberUnsigned(length - bytes - 1); - UnityPrint(UnityStrExpected); - UnityPrintNumberByStyle(*ptr_exp, UNITY_DISPLAY_STYLE_HEX8); - UnityPrint(UnityStrWas); - UnityPrintNumberByStyle(*ptr_act, UNITY_DISPLAY_STYLE_HEX8); - UnityAddMsgIfSpecified(msg); - UNITY_FAIL_AND_BAIL; - } - ptr_exp++; - ptr_act++; - } - if (flags == UNITY_ARRAY_TO_VAL) - { - ptr_exp = (UNITY_PTR_ATTRIBUTE const unsigned char*)expected; - } - } -} - -/*-----------------------------------------------*/ - -static union -{ - UNITY_INT8 i8; - UNITY_INT16 i16; - UNITY_INT32 i32; -#ifdef UNITY_SUPPORT_64 - UNITY_INT64 i64; -#endif -#ifndef UNITY_EXCLUDE_FLOAT - float f; -#endif -#ifndef UNITY_EXCLUDE_DOUBLE - double d; -#endif -} UnityQuickCompare; - -UNITY_INTERNAL_PTR UnityNumToPtr(const UNITY_INT num, const UNITY_UINT8 size) -{ - switch(size) - { - case 1: - UnityQuickCompare.i8 = (UNITY_INT8)num; - return (UNITY_INTERNAL_PTR)(&UnityQuickCompare.i8); - - case 2: - UnityQuickCompare.i16 = (UNITY_INT16)num; - return (UNITY_INTERNAL_PTR)(&UnityQuickCompare.i16); - -#ifdef UNITY_SUPPORT_64 - case 8: - UnityQuickCompare.i64 = (UNITY_INT64)num; - return (UNITY_INTERNAL_PTR)(&UnityQuickCompare.i64); -#endif - - default: /* 4 bytes */ - UnityQuickCompare.i32 = (UNITY_INT32)num; - return (UNITY_INTERNAL_PTR)(&UnityQuickCompare.i32); - } -} - -#ifndef UNITY_EXCLUDE_FLOAT -/*-----------------------------------------------*/ -UNITY_INTERNAL_PTR UnityFloatToPtr(const float num) -{ - UnityQuickCompare.f = num; - return (UNITY_INTERNAL_PTR)(&UnityQuickCompare.f); -} -#endif - -#ifndef UNITY_EXCLUDE_DOUBLE -/*-----------------------------------------------*/ -UNITY_INTERNAL_PTR UnityDoubleToPtr(const double num) -{ - UnityQuickCompare.d = num; - return (UNITY_INTERNAL_PTR)(&UnityQuickCompare.d); -} -#endif - -/*----------------------------------------------- - * Control Functions - *-----------------------------------------------*/ - -/*-----------------------------------------------*/ -void UnityFail(const char* msg, const UNITY_LINE_TYPE line) -{ - RETURN_IF_FAIL_OR_IGNORE; - - UnityTestResultsBegin(Unity.TestFile, line); - UnityPrint(UnityStrFail); - if (msg != NULL) - { - UNITY_OUTPUT_CHAR(':'); - -#ifndef UNITY_EXCLUDE_DETAILS - if (Unity.CurrentDetail1) - { - UnityPrint(UnityStrDetail1Name); - UnityPrint(Unity.CurrentDetail1); - if (Unity.CurrentDetail2) - { - UnityPrint(UnityStrDetail2Name); - UnityPrint(Unity.CurrentDetail2); - } - UnityPrint(UnityStrSpacer); - } -#endif - if (msg[0] != ' ') - { - UNITY_OUTPUT_CHAR(' '); - } - UnityPrint(msg); - } - - UNITY_FAIL_AND_BAIL; -} - -/*-----------------------------------------------*/ -void UnityIgnore(const char* msg, const UNITY_LINE_TYPE line) -{ - RETURN_IF_FAIL_OR_IGNORE; - - UnityTestResultsBegin(Unity.TestFile, line); - UnityPrint(UnityStrIgnore); - if (msg != NULL) - { - UNITY_OUTPUT_CHAR(':'); - UNITY_OUTPUT_CHAR(' '); - UnityPrint(msg); - } - UNITY_IGNORE_AND_BAIL; -} - -/*-----------------------------------------------*/ -void UnityMessage(const char* msg, const UNITY_LINE_TYPE line) -{ - UnityTestResultsBegin(Unity.TestFile, line); - UnityPrint("INFO"); - if (msg != NULL) - { - UNITY_OUTPUT_CHAR(':'); - UNITY_OUTPUT_CHAR(' '); - UnityPrint(msg); - } - UNITY_PRINT_EOL(); -} - -/*-----------------------------------------------*/ -void UnityDefaultTestRun(UnityTestFunction Func, const char* FuncName, const int FuncLineNum) -{ - Unity.CurrentTestName = FuncName; - Unity.CurrentTestLineNumber = (UNITY_LINE_TYPE)FuncLineNum; - Unity.NumberOfTests++; - UNITY_CLR_DETAILS(); - UNITY_EXEC_TIME_START(); - if (TEST_PROTECT()) - { - setUp(); - Func(); - } - if (TEST_PROTECT()) - { - tearDown(); - } - UNITY_EXEC_TIME_STOP(); - UnityConcludeTest(); -} - -/*-----------------------------------------------*/ -void UnityBegin(const char* filename) -{ - Unity.TestFile = filename; - Unity.CurrentTestName = NULL; - Unity.CurrentTestLineNumber = 0; - Unity.NumberOfTests = 0; - Unity.TestFailures = 0; - Unity.TestIgnores = 0; - Unity.CurrentTestFailed = 0; - Unity.CurrentTestIgnored = 0; - - UNITY_CLR_DETAILS(); - UNITY_OUTPUT_START(); -} - -/*-----------------------------------------------*/ -int UnityEnd(void) -{ - UNITY_PRINT_EOL(); - UnityPrint(UnityStrBreaker); - UNITY_PRINT_EOL(); - UnityPrintNumber((UNITY_INT)(Unity.NumberOfTests)); - UnityPrint(UnityStrResultsTests); - UnityPrintNumber((UNITY_INT)(Unity.TestFailures)); - UnityPrint(UnityStrResultsFailures); - UnityPrintNumber((UNITY_INT)(Unity.TestIgnores)); - UnityPrint(UnityStrResultsIgnored); - UNITY_PRINT_EOL(); - if (Unity.TestFailures == 0U) - { - UnityPrint(UnityStrOk); - } - else - { - UnityPrint(UnityStrFail); -#ifdef UNITY_DIFFERENTIATE_FINAL_FAIL - UNITY_OUTPUT_CHAR('E'); UNITY_OUTPUT_CHAR('D'); -#endif - } - UNITY_PRINT_EOL(); - UNITY_FLUSH_CALL(); - UNITY_OUTPUT_COMPLETE(); - return (int)(Unity.TestFailures); -} - -/*----------------------------------------------- - * Command Line Argument Support - *-----------------------------------------------*/ -#ifdef UNITY_USE_COMMAND_LINE_ARGS - -char* UnityOptionIncludeNamed = NULL; -char* UnityOptionExcludeNamed = NULL; -int UnityVerbosity = 1; - -/*-----------------------------------------------*/ -int UnityParseOptions(int argc, char** argv) -{ - UnityOptionIncludeNamed = NULL; - UnityOptionExcludeNamed = NULL; - int i; - - for (i = 1; i < argc; i++) - { - if (argv[i][0] == '-') - { - switch (argv[i][1]) - { - case 'l': /* list tests */ - return -1; - case 'n': /* include tests with name including this string */ - case 'f': /* an alias for -n */ - if (argv[i][2] == '=') - { - UnityOptionIncludeNamed = &argv[i][3]; - } - else if (++i < argc) - { - UnityOptionIncludeNamed = argv[i]; - } - else - { - UnityPrint("ERROR: No Test String to Include Matches For"); - UNITY_PRINT_EOL(); - return 1; - } - break; - case 'q': /* quiet */ - UnityVerbosity = 0; - break; - case 'v': /* verbose */ - UnityVerbosity = 2; - break; - case 'x': /* exclude tests with name including this string */ - if (argv[i][2] == '=') - { - UnityOptionExcludeNamed = &argv[i][3]; - } - else if (++i < argc) - { - UnityOptionExcludeNamed = argv[i]; - } - else - { - UnityPrint("ERROR: No Test String to Exclude Matches For"); - UNITY_PRINT_EOL(); - return 1; - } - break; - default: - UnityPrint("ERROR: Unknown Option "); - UNITY_OUTPUT_CHAR(argv[i][1]); - UNITY_PRINT_EOL(); - return 1; - } - } - } - - return 0; -} - -/*-----------------------------------------------*/ -int IsStringInBiggerString(const char* longstring, const char* shortstring) -{ - const char* lptr = longstring; - const char* sptr = shortstring; - const char* lnext = lptr; - - if (*sptr == '*') - { - return 1; - } - - while (*lptr) - { - lnext = lptr + 1; - - /* If they current bytes match, go on to the next bytes */ - while (*lptr && *sptr && (*lptr == *sptr)) - { - lptr++; - sptr++; - - /* We're done if we match the entire string or up to a wildcard */ - if (*sptr == '*') - return 1; - if (*sptr == ',') - return 1; - if (*sptr == '"') - return 1; - if (*sptr == '\'') - return 1; - if (*sptr == ':') - return 2; - if (*sptr == 0) - return 1; - } - - /* Otherwise we start in the long pointer 1 character further and try again */ - lptr = lnext; - sptr = shortstring; - } - - return 0; -} - -/*-----------------------------------------------*/ -int UnityStringArgumentMatches(const char* str) -{ - int retval; - const char* ptr1; - const char* ptr2; - const char* ptrf; - - /* Go through the options and get the substrings for matching one at a time */ - ptr1 = str; - while (ptr1[0] != 0) - { - if ((ptr1[0] == '"') || (ptr1[0] == '\'')) - { - ptr1++; - } - - /* look for the start of the next partial */ - ptr2 = ptr1; - ptrf = 0; - do - { - ptr2++; - if ((ptr2[0] == ':') && (ptr2[1] != 0) && (ptr2[0] != '\'') && (ptr2[0] != '"') && (ptr2[0] != ',')) - { - ptrf = &ptr2[1]; - } - } while ((ptr2[0] != 0) && (ptr2[0] != '\'') && (ptr2[0] != '"') && (ptr2[0] != ',')); - - while ((ptr2[0] != 0) && ((ptr2[0] == ':') || (ptr2[0] == '\'') || (ptr2[0] == '"') || (ptr2[0] == ','))) - { - ptr2++; - } - - /* done if complete filename match */ - retval = IsStringInBiggerString(Unity.TestFile, ptr1); - if (retval == 1) - { - return retval; - } - - /* done if testname match after filename partial match */ - if ((retval == 2) && (ptrf != 0)) - { - if (IsStringInBiggerString(Unity.CurrentTestName, ptrf)) - { - return 1; - } - } - - /* done if complete testname match */ - if (IsStringInBiggerString(Unity.CurrentTestName, ptr1) == 1) - { - return 1; - } - - ptr1 = ptr2; - } - - /* we couldn't find a match for any substrings */ - return 0; -} - -/*-----------------------------------------------*/ -int UnityTestMatches(void) -{ - /* Check if this test name matches the included test pattern */ - int retval; - if (UnityOptionIncludeNamed) - { - retval = UnityStringArgumentMatches(UnityOptionIncludeNamed); - } - else - { - retval = 1; - } - - /* Check if this test name matches the excluded test pattern */ - if (UnityOptionExcludeNamed) - { - if (UnityStringArgumentMatches(UnityOptionExcludeNamed)) - { - retval = 0; - } - } - - return retval; -} - -#endif /* UNITY_USE_COMMAND_LINE_ARGS */ -/*-----------------------------------------------*/ diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/unity/src/unity.h b/bk7235/liteos_m/bk_sdk_armino/middleware/compal/unity/src/unity.h deleted file mode 100755 index 8f1fe2e5ab808fb0012fff0bfbacb35d15cf682c..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/unity/src/unity.h +++ /dev/null @@ -1,581 +0,0 @@ -/* ========================================== - Unity Project - A Test Framework for C - Copyright (c) 2007-19 Mike Karlesky, Mark VanderVoord, Greg Williams - [Released under MIT License. Please refer to license.txt for details] -========================================== */ - -#ifndef UNITY_FRAMEWORK_H -#define UNITY_FRAMEWORK_H -#define UNITY - -#ifdef __cplusplus -extern "C" -{ -#endif - -#include "unity_internals.h" - -/*------------------------------------------------------- - * Test Setup / Teardown - *-------------------------------------------------------*/ - -/* These functions are intended to be called before and after each test. */ -void setUp(void); -void tearDown(void); - -/* These functions are intended to be called at the beginning and end of an - * entire test suite. suiteTearDown() is passed the number of tests that - * failed, and its return value becomes the exit code of main(). */ -void suiteSetUp(void); -int suiteTearDown(int num_failures); - -/* If the compiler supports it, the following block provides stub - * implementations of the above functions as weak symbols. Note that on - * some platforms (MinGW for example), weak function implementations need - * to be in the same translation unit they are called from. This can be - * achieved by defining UNITY_INCLUDE_SETUP_STUBS before including unity.h. */ -#ifdef UNITY_INCLUDE_SETUP_STUBS - #ifdef UNITY_WEAK_ATTRIBUTE - UNITY_WEAK_ATTRIBUTE void setUp(void) { } - UNITY_WEAK_ATTRIBUTE void tearDown(void) { } - UNITY_WEAK_ATTRIBUTE void suiteSetUp(void) { } - UNITY_WEAK_ATTRIBUTE int suiteTearDown(int num_failures) { return num_failures; } - #elif defined(UNITY_WEAK_PRAGMA) - #pragma weak setUp - void setUp(void) { } - #pragma weak tearDown - void tearDown(void) { } - #pragma weak suiteSetUp - void suiteSetUp(void) { } - #pragma weak suiteTearDown - int suiteTearDown(int num_failures) { return num_failures; } - #endif -#endif - -/*------------------------------------------------------- - * Configuration Options - *------------------------------------------------------- - * All options described below should be passed as a compiler flag to all files using Unity. If you must add #defines, place them BEFORE the #include above. - - * Integers/longs/pointers - * - Unity attempts to automatically discover your integer sizes - * - define UNITY_EXCLUDE_STDINT_H to stop attempting to look in - * - define UNITY_EXCLUDE_LIMITS_H to stop attempting to look in - * - If you cannot use the automatic methods above, you can force Unity by using these options: - * - define UNITY_SUPPORT_64 - * - set UNITY_INT_WIDTH - * - set UNITY_LONG_WIDTH - * - set UNITY_POINTER_WIDTH - - * Floats - * - define UNITY_EXCLUDE_FLOAT to disallow floating point comparisons - * - define UNITY_FLOAT_PRECISION to specify the precision to use when doing TEST_ASSERT_EQUAL_FLOAT - * - define UNITY_FLOAT_TYPE to specify doubles instead of single precision floats - * - define UNITY_INCLUDE_DOUBLE to allow double floating point comparisons - * - define UNITY_EXCLUDE_DOUBLE to disallow double floating point comparisons (default) - * - define UNITY_DOUBLE_PRECISION to specify the precision to use when doing TEST_ASSERT_EQUAL_DOUBLE - * - define UNITY_DOUBLE_TYPE to specify something other than double - * - define UNITY_EXCLUDE_FLOAT_PRINT to trim binary size, won't print floating point values in errors - - * Output - * - by default, Unity prints to standard out with putchar. define UNITY_OUTPUT_CHAR(a) with a different function if desired - * - define UNITY_DIFFERENTIATE_FINAL_FAIL to print FAILED (vs. FAIL) at test end summary - for automated search for failure - - * Optimization - * - by default, line numbers are stored in unsigned shorts. Define UNITY_LINE_TYPE with a different type if your files are huge - * - by default, test and failure counters are unsigned shorts. Define UNITY_COUNTER_TYPE with a different type if you want to save space or have more than 65535 Tests. - - * Test Cases - * - define UNITY_SUPPORT_TEST_CASES to include the TEST_CASE macro, though really it's mostly about the runner generator script - - * Parameterized Tests - * - you'll want to create a define of TEST_CASE(...) which basically evaluates to nothing - - * Tests with Arguments - * - you'll want to define UNITY_USE_COMMAND_LINE_ARGS if you have the test runner passing arguments to Unity - - *------------------------------------------------------- - * Basic Fail and Ignore - *-------------------------------------------------------*/ - -#define TEST_FAIL_MESSAGE(message) UNITY_TEST_FAIL(__LINE__, (message)) -#define TEST_FAIL() UNITY_TEST_FAIL(__LINE__, NULL) -#define TEST_IGNORE_MESSAGE(message) UNITY_TEST_IGNORE(__LINE__, (message)) -#define TEST_IGNORE() UNITY_TEST_IGNORE(__LINE__, NULL) -#define TEST_MESSAGE(message) UnityMessage((message), __LINE__) -#define TEST_ONLY() - -/* It is not necessary for you to call PASS. A PASS condition is assumed if nothing fails. - * This method allows you to abort a test immediately with a PASS state, ignoring the remainder of the test. */ -#define TEST_PASS() TEST_ABORT() -#define TEST_PASS_MESSAGE(message) do { UnityMessage((message), __LINE__); TEST_ABORT(); } while(0) - -/* This macro does nothing, but it is useful for build tools (like Ceedling) to make use of this to figure out - * which files should be linked to in order to perform a test. Use it like TEST_FILE("sandwiches.c") */ -#define TEST_FILE(a) - -/*------------------------------------------------------- - * Test Asserts (simple) - *-------------------------------------------------------*/ - -/* Boolean */ -#define TEST_ASSERT(condition) UNITY_TEST_ASSERT( (condition), __LINE__, " Expression Evaluated To FALSE") -#define TEST_ASSERT_TRUE(condition) UNITY_TEST_ASSERT( (condition), __LINE__, " Expected TRUE Was FALSE") -#define TEST_ASSERT_UNLESS(condition) UNITY_TEST_ASSERT( !(condition), __LINE__, " Expression Evaluated To TRUE") -#define TEST_ASSERT_FALSE(condition) UNITY_TEST_ASSERT( !(condition), __LINE__, " Expected FALSE Was TRUE") -#define TEST_ASSERT_NULL(pointer) UNITY_TEST_ASSERT_NULL( (pointer), __LINE__, " Expected NULL") -#define TEST_ASSERT_NOT_NULL(pointer) UNITY_TEST_ASSERT_NOT_NULL((pointer), __LINE__, " Expected Non-NULL") - -/* Integers (of all sizes) */ -#define TEST_ASSERT_EQUAL_INT(expected, actual) UNITY_TEST_ASSERT_EQUAL_INT((expected), (actual), __LINE__, NULL) -#define TEST_ASSERT_EQUAL_INT8(expected, actual) UNITY_TEST_ASSERT_EQUAL_INT8((expected), (actual), __LINE__, NULL) -#define TEST_ASSERT_EQUAL_INT16(expected, actual) UNITY_TEST_ASSERT_EQUAL_INT16((expected), (actual), __LINE__, NULL) -#define TEST_ASSERT_EQUAL_INT32(expected, actual) UNITY_TEST_ASSERT_EQUAL_INT32((expected), (actual), __LINE__, NULL) -#define TEST_ASSERT_EQUAL_INT64(expected, actual) UNITY_TEST_ASSERT_EQUAL_INT64((expected), (actual), __LINE__, NULL) -#define TEST_ASSERT_EQUAL_UINT(expected, actual) UNITY_TEST_ASSERT_EQUAL_UINT( (expected), (actual), __LINE__, NULL) -#define TEST_ASSERT_EQUAL_UINT8(expected, actual) UNITY_TEST_ASSERT_EQUAL_UINT8( (expected), (actual), __LINE__, NULL) -#define TEST_ASSERT_EQUAL_UINT16(expected, actual) UNITY_TEST_ASSERT_EQUAL_UINT16( (expected), (actual), __LINE__, NULL) -#define TEST_ASSERT_EQUAL_UINT32(expected, actual) UNITY_TEST_ASSERT_EQUAL_UINT32( (expected), (actual), __LINE__, NULL) -#define TEST_ASSERT_EQUAL_UINT64(expected, actual) UNITY_TEST_ASSERT_EQUAL_UINT64( (expected), (actual), __LINE__, NULL) -#define TEST_ASSERT_EQUAL_HEX(expected, actual) UNITY_TEST_ASSERT_EQUAL_HEX32((expected), (actual), __LINE__, NULL) -#define TEST_ASSERT_EQUAL_HEX8(expected, actual) UNITY_TEST_ASSERT_EQUAL_HEX8( (expected), (actual), __LINE__, NULL) -#define TEST_ASSERT_EQUAL_HEX16(expected, actual) UNITY_TEST_ASSERT_EQUAL_HEX16((expected), (actual), __LINE__, NULL) -#define TEST_ASSERT_EQUAL_HEX32(expected, actual) UNITY_TEST_ASSERT_EQUAL_HEX32((expected), (actual), __LINE__, NULL) -#define TEST_ASSERT_EQUAL_HEX64(expected, actual) UNITY_TEST_ASSERT_EQUAL_HEX64((expected), (actual), __LINE__, NULL) -#define TEST_ASSERT_BITS(mask, expected, actual) UNITY_TEST_ASSERT_BITS((mask), (expected), (actual), __LINE__, NULL) -#define TEST_ASSERT_BITS_HIGH(mask, actual) UNITY_TEST_ASSERT_BITS((mask), (UNITY_UINT32)(-1), (actual), __LINE__, NULL) -#define TEST_ASSERT_BITS_LOW(mask, actual) UNITY_TEST_ASSERT_BITS((mask), (UNITY_UINT32)(0), (actual), __LINE__, NULL) -#define TEST_ASSERT_BIT_HIGH(bit, actual) UNITY_TEST_ASSERT_BITS(((UNITY_UINT32)1 << (bit)), (UNITY_UINT32)(-1), (actual), __LINE__, NULL) -#define TEST_ASSERT_BIT_LOW(bit, actual) UNITY_TEST_ASSERT_BITS(((UNITY_UINT32)1 << (bit)), (UNITY_UINT32)(0), (actual), __LINE__, NULL) - -/* Integer Greater Than/ Less Than (of all sizes) */ -#define TEST_ASSERT_GREATER_THAN(threshold, actual) UNITY_TEST_ASSERT_GREATER_THAN_INT((threshold), (actual), __LINE__, NULL) -#define TEST_ASSERT_GREATER_THAN_INT(threshold, actual) UNITY_TEST_ASSERT_GREATER_THAN_INT((threshold), (actual), __LINE__, NULL) -#define TEST_ASSERT_GREATER_THAN_INT8(threshold, actual) UNITY_TEST_ASSERT_GREATER_THAN_INT8((threshold), (actual), __LINE__, NULL) -#define TEST_ASSERT_GREATER_THAN_INT16(threshold, actual) UNITY_TEST_ASSERT_GREATER_THAN_INT16((threshold), (actual), __LINE__, NULL) -#define TEST_ASSERT_GREATER_THAN_INT32(threshold, actual) UNITY_TEST_ASSERT_GREATER_THAN_INT32((threshold), (actual), __LINE__, NULL) -#define TEST_ASSERT_GREATER_THAN_INT64(threshold, actual) UNITY_TEST_ASSERT_GREATER_THAN_INT64((threshold), (actual), __LINE__, NULL) -#define TEST_ASSERT_GREATER_THAN_UINT(threshold, actual) UNITY_TEST_ASSERT_GREATER_THAN_UINT((threshold), (actual), __LINE__, NULL) -#define TEST_ASSERT_GREATER_THAN_UINT8(threshold, actual) UNITY_TEST_ASSERT_GREATER_THAN_UINT8((threshold), (actual), __LINE__, NULL) -#define TEST_ASSERT_GREATER_THAN_UINT16(threshold, actual) UNITY_TEST_ASSERT_GREATER_THAN_UINT16((threshold), (actual), __LINE__, NULL) -#define TEST_ASSERT_GREATER_THAN_UINT32(threshold, actual) UNITY_TEST_ASSERT_GREATER_THAN_UINT32((threshold), (actual), __LINE__, NULL) -#define TEST_ASSERT_GREATER_THAN_UINT64(threshold, actual) UNITY_TEST_ASSERT_GREATER_THAN_UINT64((threshold), (actual), __LINE__, NULL) -#define TEST_ASSERT_GREATER_THAN_HEX8(threshold, actual) UNITY_TEST_ASSERT_GREATER_THAN_HEX8((threshold), (actual), __LINE__, NULL) -#define TEST_ASSERT_GREATER_THAN_HEX16(threshold, actual) UNITY_TEST_ASSERT_GREATER_THAN_HEX16((threshold), (actual), __LINE__, NULL) -#define TEST_ASSERT_GREATER_THAN_HEX32(threshold, actual) UNITY_TEST_ASSERT_GREATER_THAN_HEX32((threshold), (actual), __LINE__, NULL) -#define TEST_ASSERT_GREATER_THAN_HEX64(threshold, actual) UNITY_TEST_ASSERT_GREATER_THAN_HEX64((threshold), (actual), __LINE__, NULL) - -#define TEST_ASSERT_LESS_THAN(threshold, actual) UNITY_TEST_ASSERT_SMALLER_THAN_INT((threshold), (actual), __LINE__, NULL) -#define TEST_ASSERT_LESS_THAN_INT(threshold, actual) UNITY_TEST_ASSERT_SMALLER_THAN_INT((threshold), (actual), __LINE__, NULL) -#define TEST_ASSERT_LESS_THAN_INT8(threshold, actual) UNITY_TEST_ASSERT_SMALLER_THAN_INT8((threshold), (actual), __LINE__, NULL) -#define TEST_ASSERT_LESS_THAN_INT16(threshold, actual) UNITY_TEST_ASSERT_SMALLER_THAN_INT16((threshold), (actual), __LINE__, NULL) -#define TEST_ASSERT_LESS_THAN_INT32(threshold, actual) UNITY_TEST_ASSERT_SMALLER_THAN_INT32((threshold), (actual), __LINE__, NULL) -#define TEST_ASSERT_LESS_THAN_INT64(threshold, actual) UNITY_TEST_ASSERT_SMALLER_THAN_INT64((threshold), (actual), __LINE__, NULL) -#define TEST_ASSERT_LESS_THAN_UINT(threshold, actual) UNITY_TEST_ASSERT_SMALLER_THAN_UINT((threshold), (actual), __LINE__, NULL) -#define TEST_ASSERT_LESS_THAN_UINT8(threshold, actual) UNITY_TEST_ASSERT_SMALLER_THAN_UINT8((threshold), (actual), __LINE__, NULL) -#define TEST_ASSERT_LESS_THAN_UINT16(threshold, actual) UNITY_TEST_ASSERT_SMALLER_THAN_UINT16((threshold), (actual), __LINE__, NULL) -#define TEST_ASSERT_LESS_THAN_UINT32(threshold, actual) UNITY_TEST_ASSERT_SMALLER_THAN_UINT32((threshold), (actual), __LINE__, NULL) -#define TEST_ASSERT_LESS_THAN_UINT64(threshold, actual) UNITY_TEST_ASSERT_SMALLER_THAN_UINT64((threshold), (actual), __LINE__, NULL) -#define TEST_ASSERT_LESS_THAN_HEX8(threshold, actual) UNITY_TEST_ASSERT_SMALLER_THAN_HEX8((threshold), (actual), __LINE__, NULL) -#define TEST_ASSERT_LESS_THAN_HEX16(threshold, actual) UNITY_TEST_ASSERT_SMALLER_THAN_HEX16((threshold), (actual), __LINE__, NULL) -#define TEST_ASSERT_LESS_THAN_HEX32(threshold, actual) UNITY_TEST_ASSERT_SMALLER_THAN_HEX32((threshold), (actual), __LINE__, NULL) -#define TEST_ASSERT_LESS_THAN_HEX64(threshold, actual) UNITY_TEST_ASSERT_SMALLER_THAN_HEX64((threshold), (actual), __LINE__, NULL) - -#define TEST_ASSERT_GREATER_OR_EQUAL(threshold, actual) UNITY_TEST_ASSERT_GREATER_OR_EQUAL_INT((threshold), (actual), __LINE__, NULL) -#define TEST_ASSERT_GREATER_OR_EQUAL_INT(threshold, actual) UNITY_TEST_ASSERT_GREATER_OR_EQUAL_INT((threshold), (actual), __LINE__, NULL) -#define TEST_ASSERT_GREATER_OR_EQUAL_INT8(threshold, actual) UNITY_TEST_ASSERT_GREATER_OR_EQUAL_INT8((threshold), (actual), __LINE__, NULL) -#define TEST_ASSERT_GREATER_OR_EQUAL_INT16(threshold, actual) UNITY_TEST_ASSERT_GREATER_OR_EQUAL_INT16((threshold), (actual), __LINE__, NULL) -#define TEST_ASSERT_GREATER_OR_EQUAL_INT32(threshold, actual) UNITY_TEST_ASSERT_GREATER_OR_EQUAL_INT32((threshold), (actual), __LINE__, NULL) -#define TEST_ASSERT_GREATER_OR_EQUAL_INT64(threshold, actual) UNITY_TEST_ASSERT_GREATER_OR_EQUAL_INT64((threshold), (actual), __LINE__, NULL) -#define TEST_ASSERT_GREATER_OR_EQUAL_UINT(threshold, actual) UNITY_TEST_ASSERT_GREATER_OR_EQUAL_UINT((threshold), (actual), __LINE__, NULL) -#define TEST_ASSERT_GREATER_OR_EQUAL_UINT8(threshold, actual) UNITY_TEST_ASSERT_GREATER_OR_EQUAL_UINT8((threshold), (actual), __LINE__, NULL) -#define TEST_ASSERT_GREATER_OR_EQUAL_UINT16(threshold, actual) UNITY_TEST_ASSERT_GREATER_OR_EQUAL_UINT16((threshold), (actual), __LINE__, NULL) -#define TEST_ASSERT_GREATER_OR_EQUAL_UINT32(threshold, actual) UNITY_TEST_ASSERT_GREATER_OR_EQUAL_UINT32((threshold), (actual), __LINE__, NULL) -#define TEST_ASSERT_GREATER_OR_EQUAL_UINT64(threshold, actual) UNITY_TEST_ASSERT_GREATER_OR_EQUAL_UINT64((threshold), (actual), __LINE__, NULL) -#define TEST_ASSERT_GREATER_OR_EQUAL_HEX8(threshold, actual) UNITY_TEST_ASSERT_GREATER_OR_EQUAL_HEX8((threshold), (actual), __LINE__, NULL) -#define TEST_ASSERT_GREATER_OR_EQUAL_HEX16(threshold, actual) UNITY_TEST_ASSERT_GREATER_OR_EQUAL_HEX16((threshold), (actual), __LINE__, NULL) -#define TEST_ASSERT_GREATER_OR_EQUAL_HEX32(threshold, actual) UNITY_TEST_ASSERT_GREATER_OR_EQUAL_HEX32((threshold), (actual), __LINE__, NULL) -#define TEST_ASSERT_GREATER_OR_EQUAL_HEX64(threshold, actual) UNITY_TEST_ASSERT_GREATER_OR_EQUAL_HEX64((threshold), (actual), __LINE__, NULL) - -#define TEST_ASSERT_LESS_OR_EQUAL(threshold, actual) UNITY_TEST_ASSERT_SMALLER_OR_EQUAL_INT((threshold), (actual), __LINE__, NULL) -#define TEST_ASSERT_LESS_OR_EQUAL_INT(threshold, actual) UNITY_TEST_ASSERT_SMALLER_OR_EQUAL_INT((threshold), (actual), __LINE__, NULL) -#define TEST_ASSERT_LESS_OR_EQUAL_INT8(threshold, actual) UNITY_TEST_ASSERT_SMALLER_OR_EQUAL_INT8((threshold), (actual), __LINE__, NULL) -#define TEST_ASSERT_LESS_OR_EQUAL_INT16(threshold, actual) UNITY_TEST_ASSERT_SMALLER_OR_EQUAL_INT16((threshold), (actual), __LINE__, NULL) -#define TEST_ASSERT_LESS_OR_EQUAL_INT32(threshold, actual) UNITY_TEST_ASSERT_SMALLER_OR_EQUAL_INT32((threshold), (actual), __LINE__, NULL) -#define TEST_ASSERT_LESS_OR_EQUAL_INT64(threshold, actual) UNITY_TEST_ASSERT_SMALLER_OR_EQUAL_INT64((threshold), (actual), __LINE__, NULL) -#define TEST_ASSERT_LESS_OR_EQUAL_UINT(threshold, actual) UNITY_TEST_ASSERT_SMALLER_OR_EQUAL_UINT((threshold), (actual), __LINE__, NULL) -#define TEST_ASSERT_LESS_OR_EQUAL_UINT8(threshold, actual) UNITY_TEST_ASSERT_SMALLER_OR_EQUAL_UINT8((threshold), (actual), __LINE__, NULL) -#define TEST_ASSERT_LESS_OR_EQUAL_UINT16(threshold, actual) UNITY_TEST_ASSERT_SMALLER_OR_EQUAL_UINT16((threshold), (actual), __LINE__, NULL) -#define TEST_ASSERT_LESS_OR_EQUAL_UINT32(threshold, actual) UNITY_TEST_ASSERT_SMALLER_OR_EQUAL_UINT32((threshold), (actual), __LINE__, NULL) -#define TEST_ASSERT_LESS_OR_EQUAL_UINT64(threshold, actual) UNITY_TEST_ASSERT_SMALLER_OR_EQUAL_UINT64((threshold), (actual), __LINE__, NULL) -#define TEST_ASSERT_LESS_OR_EQUAL_HEX8(threshold, actual) UNITY_TEST_ASSERT_SMALLER_OR_EQUAL_HEX8((threshold), (actual), __LINE__, NULL) -#define TEST_ASSERT_LESS_OR_EQUAL_HEX16(threshold, actual) UNITY_TEST_ASSERT_SMALLER_OR_EQUAL_HEX16((threshold), (actual), __LINE__, NULL) -#define TEST_ASSERT_LESS_OR_EQUAL_HEX32(threshold, actual) UNITY_TEST_ASSERT_SMALLER_OR_EQUAL_HEX32((threshold), (actual), __LINE__, NULL) -#define TEST_ASSERT_LESS_OR_EQUAL_HEX64(threshold, actual) UNITY_TEST_ASSERT_SMALLER_OR_EQUAL_HEX64((threshold), (actual), __LINE__, NULL) - -/* Integer Ranges (of all sizes) */ -#define TEST_ASSERT_INT_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_INT_WITHIN((delta), (expected), (actual), __LINE__, NULL) -#define TEST_ASSERT_INT8_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_INT8_WITHIN((delta), (expected), (actual), __LINE__, NULL) -#define TEST_ASSERT_INT16_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_INT16_WITHIN((delta), (expected), (actual), __LINE__, NULL) -#define TEST_ASSERT_INT32_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_INT32_WITHIN((delta), (expected), (actual), __LINE__, NULL) -#define TEST_ASSERT_INT64_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_INT64_WITHIN((delta), (expected), (actual), __LINE__, NULL) -#define TEST_ASSERT_UINT_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_UINT_WITHIN((delta), (expected), (actual), __LINE__, NULL) -#define TEST_ASSERT_UINT8_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_UINT8_WITHIN((delta), (expected), (actual), __LINE__, NULL) -#define TEST_ASSERT_UINT16_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_UINT16_WITHIN((delta), (expected), (actual), __LINE__, NULL) -#define TEST_ASSERT_UINT32_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_UINT32_WITHIN((delta), (expected), (actual), __LINE__, NULL) -#define TEST_ASSERT_UINT64_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_UINT64_WITHIN((delta), (expected), (actual), __LINE__, NULL) -#define TEST_ASSERT_HEX_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_HEX32_WITHIN((delta), (expected), (actual), __LINE__, NULL) -#define TEST_ASSERT_HEX8_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_HEX8_WITHIN((delta), (expected), (actual), __LINE__, NULL) -#define TEST_ASSERT_HEX16_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_HEX16_WITHIN((delta), (expected), (actual), __LINE__, NULL) -#define TEST_ASSERT_HEX32_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_HEX32_WITHIN((delta), (expected), (actual), __LINE__, NULL) -#define TEST_ASSERT_HEX64_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_HEX64_WITHIN((delta), (expected), (actual), __LINE__, NULL) - -/* Integer Array Ranges (of all sizes) */ -#define TEST_ASSERT_INT_ARRAY_WITHIN(delta, expected, actual, num_elements) UNITY_TEST_ASSERT_INT_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, NULL) -#define TEST_ASSERT_INT8_ARRAY_WITHIN(delta, expected, actual, num_elements) UNITY_TEST_ASSERT_INT8_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, NULL) -#define TEST_ASSERT_INT16_ARRAY_WITHIN(delta, expected, actual, num_elements) UNITY_TEST_ASSERT_INT16_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, NULL) -#define TEST_ASSERT_INT32_ARRAY_WITHIN(delta, expected, actual, num_elements) UNITY_TEST_ASSERT_INT32_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, NULL) -#define TEST_ASSERT_INT64_ARRAY_WITHIN(delta, expected, actual, num_elements) UNITY_TEST_ASSERT_INT64_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, NULL) -#define TEST_ASSERT_UINT_ARRAY_WITHIN(delta, expected, actual, num_elements) UNITY_TEST_ASSERT_UINT_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, NULL) -#define TEST_ASSERT_UINT8_ARRAY_WITHIN(delta, expected, actual, num_elements) UNITY_TEST_ASSERT_UINT8_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, NULL) -#define TEST_ASSERT_UINT16_ARRAY_WITHIN(delta, expected, actual, num_elements) UNITY_TEST_ASSERT_UINT16_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, NULL) -#define TEST_ASSERT_UINT32_ARRAY_WITHIN(delta, expected, actual, num_elements) UNITY_TEST_ASSERT_UINT32_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, NULL) -#define TEST_ASSERT_UINT64_ARRAY_WITHIN(delta, expected, actual, num_elements) UNITY_TEST_ASSERT_UINT64_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, NULL) -#define TEST_ASSERT_HEX_ARRAY_WITHIN(delta, expected, actual, num_elements) UNITY_TEST_ASSERT_HEX32_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, NULL) -#define TEST_ASSERT_HEX8_ARRAY_WITHIN(delta, expected, actual, num_elements) UNITY_TEST_ASSERT_HEX8_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, NULL) -#define TEST_ASSERT_HEX16_ARRAY_WITHIN(delta, expected, actual, num_elements) UNITY_TEST_ASSERT_HEX16_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, NULL) -#define TEST_ASSERT_HEX32_ARRAY_WITHIN(delta, expected, actual, num_elements) UNITY_TEST_ASSERT_HEX32_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, NULL) -#define TEST_ASSERT_HEX64_ARRAY_WITHIN(delta, expected, actual, num_elements) UNITY_TEST_ASSERT_HEX64_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, NULL) - - -/* Structs and Strings */ -#define TEST_ASSERT_EQUAL_PTR(expected, actual) UNITY_TEST_ASSERT_EQUAL_PTR((expected), (actual), __LINE__, NULL) -#define TEST_ASSERT_EQUAL_STRING(expected, actual) UNITY_TEST_ASSERT_EQUAL_STRING((expected), (actual), __LINE__, NULL) -#define TEST_ASSERT_EQUAL_STRING_LEN(expected, actual, len) UNITY_TEST_ASSERT_EQUAL_STRING_LEN((expected), (actual), (len), __LINE__, NULL) -#define TEST_ASSERT_EQUAL_MEMORY(expected, actual, len) UNITY_TEST_ASSERT_EQUAL_MEMORY((expected), (actual), (len), __LINE__, NULL) - -/* Arrays */ -#define TEST_ASSERT_EQUAL_INT_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_INT_ARRAY((expected), (actual), (num_elements), __LINE__, NULL) -#define TEST_ASSERT_EQUAL_INT8_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_INT8_ARRAY((expected), (actual), (num_elements), __LINE__, NULL) -#define TEST_ASSERT_EQUAL_INT16_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_INT16_ARRAY((expected), (actual), (num_elements), __LINE__, NULL) -#define TEST_ASSERT_EQUAL_INT32_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_INT32_ARRAY((expected), (actual), (num_elements), __LINE__, NULL) -#define TEST_ASSERT_EQUAL_INT64_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_INT64_ARRAY((expected), (actual), (num_elements), __LINE__, NULL) -#define TEST_ASSERT_EQUAL_UINT_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_UINT_ARRAY((expected), (actual), (num_elements), __LINE__, NULL) -#define TEST_ASSERT_EQUAL_UINT8_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_UINT8_ARRAY((expected), (actual), (num_elements), __LINE__, NULL) -#define TEST_ASSERT_EQUAL_UINT16_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_UINT16_ARRAY((expected), (actual), (num_elements), __LINE__, NULL) -#define TEST_ASSERT_EQUAL_UINT32_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_UINT32_ARRAY((expected), (actual), (num_elements), __LINE__, NULL) -#define TEST_ASSERT_EQUAL_UINT64_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_UINT64_ARRAY((expected), (actual), (num_elements), __LINE__, NULL) -#define TEST_ASSERT_EQUAL_HEX_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_HEX32_ARRAY((expected), (actual), (num_elements), __LINE__, NULL) -#define TEST_ASSERT_EQUAL_HEX8_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_HEX8_ARRAY((expected), (actual), (num_elements), __LINE__, NULL) -#define TEST_ASSERT_EQUAL_HEX16_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_HEX16_ARRAY((expected), (actual), (num_elements), __LINE__, NULL) -#define TEST_ASSERT_EQUAL_HEX32_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_HEX32_ARRAY((expected), (actual), (num_elements), __LINE__, NULL) -#define TEST_ASSERT_EQUAL_HEX64_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_HEX64_ARRAY((expected), (actual), (num_elements), __LINE__, NULL) -#define TEST_ASSERT_EQUAL_PTR_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_PTR_ARRAY((expected), (actual), (num_elements), __LINE__, NULL) -#define TEST_ASSERT_EQUAL_STRING_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_STRING_ARRAY((expected), (actual), (num_elements), __LINE__, NULL) -#define TEST_ASSERT_EQUAL_MEMORY_ARRAY(expected, actual, len, num_elements) UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY((expected), (actual), (len), (num_elements), __LINE__, NULL) - -/* Arrays Compared To Single Value */ -#define TEST_ASSERT_EACH_EQUAL_INT(expected, actual, num_elements) UNITY_TEST_ASSERT_EACH_EQUAL_INT((expected), (actual), (num_elements), __LINE__, NULL) -#define TEST_ASSERT_EACH_EQUAL_INT8(expected, actual, num_elements) UNITY_TEST_ASSERT_EACH_EQUAL_INT8((expected), (actual), (num_elements), __LINE__, NULL) -#define TEST_ASSERT_EACH_EQUAL_INT16(expected, actual, num_elements) UNITY_TEST_ASSERT_EACH_EQUAL_INT16((expected), (actual), (num_elements), __LINE__, NULL) -#define TEST_ASSERT_EACH_EQUAL_INT32(expected, actual, num_elements) UNITY_TEST_ASSERT_EACH_EQUAL_INT32((expected), (actual), (num_elements), __LINE__, NULL) -#define TEST_ASSERT_EACH_EQUAL_INT64(expected, actual, num_elements) UNITY_TEST_ASSERT_EACH_EQUAL_INT64((expected), (actual), (num_elements), __LINE__, NULL) -#define TEST_ASSERT_EACH_EQUAL_UINT(expected, actual, num_elements) UNITY_TEST_ASSERT_EACH_EQUAL_UINT((expected), (actual), (num_elements), __LINE__, NULL) -#define TEST_ASSERT_EACH_EQUAL_UINT8(expected, actual, num_elements) UNITY_TEST_ASSERT_EACH_EQUAL_UINT8((expected), (actual), (num_elements), __LINE__, NULL) -#define TEST_ASSERT_EACH_EQUAL_UINT16(expected, actual, num_elements) UNITY_TEST_ASSERT_EACH_EQUAL_UINT16((expected), (actual), (num_elements), __LINE__, NULL) -#define TEST_ASSERT_EACH_EQUAL_UINT32(expected, actual, num_elements) UNITY_TEST_ASSERT_EACH_EQUAL_UINT32((expected), (actual), (num_elements), __LINE__, NULL) -#define TEST_ASSERT_EACH_EQUAL_UINT64(expected, actual, num_elements) UNITY_TEST_ASSERT_EACH_EQUAL_UINT64((expected), (actual), (num_elements), __LINE__, NULL) -#define TEST_ASSERT_EACH_EQUAL_HEX(expected, actual, num_elements) UNITY_TEST_ASSERT_EACH_EQUAL_HEX32((expected), (actual), (num_elements), __LINE__, NULL) -#define TEST_ASSERT_EACH_EQUAL_HEX8(expected, actual, num_elements) UNITY_TEST_ASSERT_EACH_EQUAL_HEX8((expected), (actual), (num_elements), __LINE__, NULL) -#define TEST_ASSERT_EACH_EQUAL_HEX16(expected, actual, num_elements) UNITY_TEST_ASSERT_EACH_EQUAL_HEX16((expected), (actual), (num_elements), __LINE__, NULL) -#define TEST_ASSERT_EACH_EQUAL_HEX32(expected, actual, num_elements) UNITY_TEST_ASSERT_EACH_EQUAL_HEX32((expected), (actual), (num_elements), __LINE__, NULL) -#define TEST_ASSERT_EACH_EQUAL_HEX64(expected, actual, num_elements) UNITY_TEST_ASSERT_EACH_EQUAL_HEX64((expected), (actual), (num_elements), __LINE__, NULL) -#define TEST_ASSERT_EACH_EQUAL_PTR(expected, actual, num_elements) UNITY_TEST_ASSERT_EACH_EQUAL_PTR((expected), (actual), (num_elements), __LINE__, NULL) -#define TEST_ASSERT_EACH_EQUAL_STRING(expected, actual, num_elements) UNITY_TEST_ASSERT_EACH_EQUAL_STRING((expected), (actual), (num_elements), __LINE__, NULL) -#define TEST_ASSERT_EACH_EQUAL_MEMORY(expected, actual, len, num_elements) UNITY_TEST_ASSERT_EACH_EQUAL_MEMORY((expected), (actual), (len), (num_elements), __LINE__, NULL) - -/* Floating Point (If Enabled) */ -#define TEST_ASSERT_FLOAT_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_FLOAT_WITHIN((delta), (expected), (actual), __LINE__, NULL) -#define TEST_ASSERT_EQUAL_FLOAT(expected, actual) UNITY_TEST_ASSERT_EQUAL_FLOAT((expected), (actual), __LINE__, NULL) -#define TEST_ASSERT_EQUAL_FLOAT_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_FLOAT_ARRAY((expected), (actual), (num_elements), __LINE__, NULL) -#define TEST_ASSERT_EACH_EQUAL_FLOAT(expected, actual, num_elements) UNITY_TEST_ASSERT_EACH_EQUAL_FLOAT((expected), (actual), (num_elements), __LINE__, NULL) -#define TEST_ASSERT_FLOAT_IS_INF(actual) UNITY_TEST_ASSERT_FLOAT_IS_INF((actual), __LINE__, NULL) -#define TEST_ASSERT_FLOAT_IS_NEG_INF(actual) UNITY_TEST_ASSERT_FLOAT_IS_NEG_INF((actual), __LINE__, NULL) -#define TEST_ASSERT_FLOAT_IS_NAN(actual) UNITY_TEST_ASSERT_FLOAT_IS_NAN((actual), __LINE__, NULL) -#define TEST_ASSERT_FLOAT_IS_DETERMINATE(actual) UNITY_TEST_ASSERT_FLOAT_IS_DETERMINATE((actual), __LINE__, NULL) -#define TEST_ASSERT_FLOAT_IS_NOT_INF(actual) UNITY_TEST_ASSERT_FLOAT_IS_NOT_INF((actual), __LINE__, NULL) -#define TEST_ASSERT_FLOAT_IS_NOT_NEG_INF(actual) UNITY_TEST_ASSERT_FLOAT_IS_NOT_NEG_INF((actual), __LINE__, NULL) -#define TEST_ASSERT_FLOAT_IS_NOT_NAN(actual) UNITY_TEST_ASSERT_FLOAT_IS_NOT_NAN((actual), __LINE__, NULL) -#define TEST_ASSERT_FLOAT_IS_NOT_DETERMINATE(actual) UNITY_TEST_ASSERT_FLOAT_IS_NOT_DETERMINATE((actual), __LINE__, NULL) - -/* Double (If Enabled) */ -#define TEST_ASSERT_DOUBLE_WITHIN(delta, expected, actual) UNITY_TEST_ASSERT_DOUBLE_WITHIN((delta), (expected), (actual), __LINE__, NULL) -#define TEST_ASSERT_EQUAL_DOUBLE(expected, actual) UNITY_TEST_ASSERT_EQUAL_DOUBLE((expected), (actual), __LINE__, NULL) -#define TEST_ASSERT_EQUAL_DOUBLE_ARRAY(expected, actual, num_elements) UNITY_TEST_ASSERT_EQUAL_DOUBLE_ARRAY((expected), (actual), (num_elements), __LINE__, NULL) -#define TEST_ASSERT_EACH_EQUAL_DOUBLE(expected, actual, num_elements) UNITY_TEST_ASSERT_EACH_EQUAL_DOUBLE((expected), (actual), (num_elements), __LINE__, NULL) -#define TEST_ASSERT_DOUBLE_IS_INF(actual) UNITY_TEST_ASSERT_DOUBLE_IS_INF((actual), __LINE__, NULL) -#define TEST_ASSERT_DOUBLE_IS_NEG_INF(actual) UNITY_TEST_ASSERT_DOUBLE_IS_NEG_INF((actual), __LINE__, NULL) -#define TEST_ASSERT_DOUBLE_IS_NAN(actual) UNITY_TEST_ASSERT_DOUBLE_IS_NAN((actual), __LINE__, NULL) -#define TEST_ASSERT_DOUBLE_IS_DETERMINATE(actual) UNITY_TEST_ASSERT_DOUBLE_IS_DETERMINATE((actual), __LINE__, NULL) -#define TEST_ASSERT_DOUBLE_IS_NOT_INF(actual) UNITY_TEST_ASSERT_DOUBLE_IS_NOT_INF((actual), __LINE__, NULL) -#define TEST_ASSERT_DOUBLE_IS_NOT_NEG_INF(actual) UNITY_TEST_ASSERT_DOUBLE_IS_NOT_NEG_INF((actual), __LINE__, NULL) -#define TEST_ASSERT_DOUBLE_IS_NOT_NAN(actual) UNITY_TEST_ASSERT_DOUBLE_IS_NOT_NAN((actual), __LINE__, NULL) -#define TEST_ASSERT_DOUBLE_IS_NOT_DETERMINATE(actual) UNITY_TEST_ASSERT_DOUBLE_IS_NOT_DETERMINATE((actual), __LINE__, NULL) - -/* Shorthand */ -#ifdef UNITY_SHORTHAND_AS_OLD -#define TEST_ASSERT_EQUAL(expected, actual) UNITY_TEST_ASSERT_EQUAL_INT((expected), (actual), __LINE__, NULL) -#define TEST_ASSERT_NOT_EQUAL(expected, actual) UNITY_TEST_ASSERT(((expected) != (actual)), __LINE__, " Expected Not-Equal") -#endif -#ifdef UNITY_SHORTHAND_AS_INT -#define TEST_ASSERT_EQUAL(expected, actual) UNITY_TEST_ASSERT_EQUAL_INT((expected), (actual), __LINE__, NULL) -#define TEST_ASSERT_NOT_EQUAL(expected, actual) UNITY_TEST_FAIL(__LINE__, UnityStrErrShorthand) -#endif -#ifdef UNITY_SHORTHAND_AS_MEM -#define TEST_ASSERT_EQUAL(expected, actual) UNITY_TEST_ASSERT_EQUAL_MEMORY((&expected), (&actual), sizeof(expected), __LINE__, NULL) -#define TEST_ASSERT_NOT_EQUAL(expected, actual) UNITY_TEST_FAIL(__LINE__, UnityStrErrShorthand) -#endif -#ifdef UNITY_SHORTHAND_AS_RAW -#define TEST_ASSERT_EQUAL(expected, actual) UNITY_TEST_ASSERT(((expected) == (actual)), __LINE__, " Expected Equal") -#define TEST_ASSERT_NOT_EQUAL(expected, actual) UNITY_TEST_ASSERT(((expected) != (actual)), __LINE__, " Expected Not-Equal") -#endif -#ifdef UNITY_SHORTHAND_AS_NONE -#define TEST_ASSERT_EQUAL(expected, actual) UNITY_TEST_FAIL(__LINE__, UnityStrErrShorthand) -#define TEST_ASSERT_NOT_EQUAL(expected, actual) UNITY_TEST_FAIL(__LINE__, UnityStrErrShorthand) -#endif - -/*------------------------------------------------------- - * Test Asserts (with additional messages) - *-------------------------------------------------------*/ - -/* Boolean */ -#define TEST_ASSERT_MESSAGE(condition, message) UNITY_TEST_ASSERT( (condition), __LINE__, (message)) -#define TEST_ASSERT_TRUE_MESSAGE(condition, message) UNITY_TEST_ASSERT( (condition), __LINE__, (message)) -#define TEST_ASSERT_UNLESS_MESSAGE(condition, message) UNITY_TEST_ASSERT( !(condition), __LINE__, (message)) -#define TEST_ASSERT_FALSE_MESSAGE(condition, message) UNITY_TEST_ASSERT( !(condition), __LINE__, (message)) -#define TEST_ASSERT_NULL_MESSAGE(pointer, message) UNITY_TEST_ASSERT_NULL( (pointer), __LINE__, (message)) -#define TEST_ASSERT_NOT_NULL_MESSAGE(pointer, message) UNITY_TEST_ASSERT_NOT_NULL((pointer), __LINE__, (message)) - -/* Integers (of all sizes) */ -#define TEST_ASSERT_EQUAL_INT_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_INT((expected), (actual), __LINE__, (message)) -#define TEST_ASSERT_EQUAL_INT8_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_INT8((expected), (actual), __LINE__, (message)) -#define TEST_ASSERT_EQUAL_INT16_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_INT16((expected), (actual), __LINE__, (message)) -#define TEST_ASSERT_EQUAL_INT32_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_INT32((expected), (actual), __LINE__, (message)) -#define TEST_ASSERT_EQUAL_INT64_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_INT64((expected), (actual), __LINE__, (message)) -#define TEST_ASSERT_EQUAL_UINT_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_UINT( (expected), (actual), __LINE__, (message)) -#define TEST_ASSERT_EQUAL_UINT8_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_UINT8( (expected), (actual), __LINE__, (message)) -#define TEST_ASSERT_EQUAL_UINT16_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_UINT16( (expected), (actual), __LINE__, (message)) -#define TEST_ASSERT_EQUAL_UINT32_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_UINT32( (expected), (actual), __LINE__, (message)) -#define TEST_ASSERT_EQUAL_UINT64_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_UINT64( (expected), (actual), __LINE__, (message)) -#define TEST_ASSERT_EQUAL_HEX_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_HEX32((expected), (actual), __LINE__, (message)) -#define TEST_ASSERT_EQUAL_HEX8_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_HEX8( (expected), (actual), __LINE__, (message)) -#define TEST_ASSERT_EQUAL_HEX16_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_HEX16((expected), (actual), __LINE__, (message)) -#define TEST_ASSERT_EQUAL_HEX32_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_HEX32((expected), (actual), __LINE__, (message)) -#define TEST_ASSERT_EQUAL_HEX64_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_HEX64((expected), (actual), __LINE__, (message)) -#define TEST_ASSERT_BITS_MESSAGE(mask, expected, actual, message) UNITY_TEST_ASSERT_BITS((mask), (expected), (actual), __LINE__, (message)) -#define TEST_ASSERT_BITS_HIGH_MESSAGE(mask, actual, message) UNITY_TEST_ASSERT_BITS((mask), (UNITY_UINT32)(-1), (actual), __LINE__, (message)) -#define TEST_ASSERT_BITS_LOW_MESSAGE(mask, actual, message) UNITY_TEST_ASSERT_BITS((mask), (UNITY_UINT32)(0), (actual), __LINE__, (message)) -#define TEST_ASSERT_BIT_HIGH_MESSAGE(bit, actual, message) UNITY_TEST_ASSERT_BITS(((UNITY_UINT32)1 << (bit)), (UNITY_UINT32)(-1), (actual), __LINE__, (message)) -#define TEST_ASSERT_BIT_LOW_MESSAGE(bit, actual, message) UNITY_TEST_ASSERT_BITS(((UNITY_UINT32)1 << (bit)), (UNITY_UINT32)(0), (actual), __LINE__, (message)) - -/* Integer Greater Than/ Less Than (of all sizes) */ -#define TEST_ASSERT_GREATER_THAN_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_GREATER_THAN_INT((threshold), (actual), __LINE__, (message)) -#define TEST_ASSERT_GREATER_THAN_INT_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_GREATER_THAN_INT((threshold), (actual), __LINE__, (message)) -#define TEST_ASSERT_GREATER_THAN_INT8_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_GREATER_THAN_INT8((threshold), (actual), __LINE__, (message)) -#define TEST_ASSERT_GREATER_THAN_INT16_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_GREATER_THAN_INT16((threshold), (actual), __LINE__, (message)) -#define TEST_ASSERT_GREATER_THAN_INT32_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_GREATER_THAN_INT32((threshold), (actual), __LINE__, (message)) -#define TEST_ASSERT_GREATER_THAN_INT64_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_GREATER_THAN_INT64((threshold), (actual), __LINE__, (message)) -#define TEST_ASSERT_GREATER_THAN_UINT_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_GREATER_THAN_UINT((threshold), (actual), __LINE__, (message)) -#define TEST_ASSERT_GREATER_THAN_UINT8_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_GREATER_THAN_UINT8((threshold), (actual), __LINE__, (message)) -#define TEST_ASSERT_GREATER_THAN_UINT16_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_GREATER_THAN_UINT16((threshold), (actual), __LINE__, (message)) -#define TEST_ASSERT_GREATER_THAN_UINT32_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_GREATER_THAN_UINT32((threshold), (actual), __LINE__, (message)) -#define TEST_ASSERT_GREATER_THAN_UINT64_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_GREATER_THAN_UINT64((threshold), (actual), __LINE__, (message)) -#define TEST_ASSERT_GREATER_THAN_HEX8_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_GREATER_THAN_HEX8((threshold), (actual), __LINE__, (message)) -#define TEST_ASSERT_GREATER_THAN_HEX16_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_GREATER_THAN_HEX16((threshold), (actual), __LINE__, (message)) -#define TEST_ASSERT_GREATER_THAN_HEX32_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_GREATER_THAN_HEX32((threshold), (actual), __LINE__, (message)) -#define TEST_ASSERT_GREATER_THAN_HEX64_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_GREATER_THAN_HEX64((threshold), (actual), __LINE__, (message)) - -#define TEST_ASSERT_LESS_THAN_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_SMALLER_THAN_INT((threshold), (actual), __LINE__, (message)) -#define TEST_ASSERT_LESS_THAN_INT_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_SMALLER_THAN_INT((threshold), (actual), __LINE__, (message)) -#define TEST_ASSERT_LESS_THAN_INT8_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_SMALLER_THAN_INT8((threshold), (actual), __LINE__, (message)) -#define TEST_ASSERT_LESS_THAN_INT16_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_SMALLER_THAN_INT16((threshold), (actual), __LINE__, (message)) -#define TEST_ASSERT_LESS_THAN_INT32_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_SMALLER_THAN_INT32((threshold), (actual), __LINE__, (message)) -#define TEST_ASSERT_LESS_THAN_INT64_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_SMALLER_THAN_INT64((threshold), (actual), __LINE__, (message)) -#define TEST_ASSERT_LESS_THAN_UINT_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_SMALLER_THAN_UINT((threshold), (actual), __LINE__, (message)) -#define TEST_ASSERT_LESS_THAN_UINT8_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_SMALLER_THAN_UINT8((threshold), (actual), __LINE__, (message)) -#define TEST_ASSERT_LESS_THAN_UINT16_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_SMALLER_THAN_UINT16((threshold), (actual), __LINE__, (message)) -#define TEST_ASSERT_LESS_THAN_UINT32_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_SMALLER_THAN_UINT32((threshold), (actual), __LINE__, (message)) -#define TEST_ASSERT_LESS_THAN_UINT64_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_SMALLER_THAN_UINT64((threshold), (actual), __LINE__, (message)) -#define TEST_ASSERT_LESS_THAN_HEX8_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_SMALLER_THAN_HEX8((threshold), (actual), __LINE__, (message)) -#define TEST_ASSERT_LESS_THAN_HEX16_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_SMALLER_THAN_HEX16((threshold), (actual), __LINE__, (message)) -#define TEST_ASSERT_LESS_THAN_HEX32_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_SMALLER_THAN_HEX32((threshold), (actual), __LINE__, (message)) -#define TEST_ASSERT_LESS_THAN_HEX64_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_SMALLER_THAN_HEX64((threshold), (actual), __LINE__, (message)) - -#define TEST_ASSERT_GREATER_OR_EQUAL_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_GREATER_OR_EQUAL_INT((threshold), (actual), __LINE__, (message)) -#define TEST_ASSERT_GREATER_OR_EQUAL_INT_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_GREATER_OR_EQUAL_INT((threshold), (actual), __LINE__, (message)) -#define TEST_ASSERT_GREATER_OR_EQUAL_INT8_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_GREATER_OR_EQUAL_INT8((threshold), (actual), __LINE__, (message)) -#define TEST_ASSERT_GREATER_OR_EQUAL_INT16_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_GREATER_OR_EQUAL_INT16((threshold), (actual), __LINE__, (message)) -#define TEST_ASSERT_GREATER_OR_EQUAL_INT32_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_GREATER_OR_EQUAL_INT32((threshold), (actual), __LINE__, (message)) -#define TEST_ASSERT_GREATER_OR_EQUAL_INT64_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_GREATER_OR_EQUAL_INT64((threshold), (actual), __LINE__, (message)) -#define TEST_ASSERT_GREATER_OR_EQUAL_UINT_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_GREATER_OR_EQUAL_UINT((threshold), (actual), __LINE__, (message)) -#define TEST_ASSERT_GREATER_OR_EQUAL_UINT8_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_GREATER_OR_EQUAL_UINT8((threshold), (actual), __LINE__, (message)) -#define TEST_ASSERT_GREATER_OR_EQUAL_UINT16_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_GREATER_OR_EQUAL_UINT16((threshold), (actual), __LINE__, (message)) -#define TEST_ASSERT_GREATER_OR_EQUAL_UINT32_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_GREATER_OR_EQUAL_UINT32((threshold), (actual), __LINE__, (message)) -#define TEST_ASSERT_GREATER_OR_EQUAL_UINT64_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_GREATER_OR_EQUAL_UINT64((threshold), (actual), __LINE__, (message)) -#define TEST_ASSERT_GREATER_OR_EQUAL_HEX8_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_GREATER_OR_EQUAL_HEX8((threshold), (actual), __LINE__, (message)) -#define TEST_ASSERT_GREATER_OR_EQUAL_HEX16_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_GREATER_OR_EQUAL_HEX16((threshold), (actual), __LINE__, (message)) -#define TEST_ASSERT_GREATER_OR_EQUAL_HEX32_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_GREATER_OR_EQUAL_HEX32((threshold), (actual), __LINE__, (message)) -#define TEST_ASSERT_GREATER_OR_EQUAL_HEX64_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_GREATER_OR_EQUAL_HEX64((threshold), (actual), __LINE__, (message)) - -#define TEST_ASSERT_LESS_OR_EQUAL_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_SMALLER_OR_EQUAL_INT((threshold), (actual), __LINE__, (message)) -#define TEST_ASSERT_LESS_OR_EQUAL_INT_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_SMALLER_OR_EQUAL_INT((threshold), (actual), __LINE__, (message)) -#define TEST_ASSERT_LESS_OR_EQUAL_INT8_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_SMALLER_OR_EQUAL_INT8((threshold), (actual), __LINE__, (message)) -#define TEST_ASSERT_LESS_OR_EQUAL_INT16_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_SMALLER_OR_EQUAL_INT16((threshold), (actual), __LINE__, (message)) -#define TEST_ASSERT_LESS_OR_EQUAL_INT32_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_SMALLER_OR_EQUAL_INT32((threshold), (actual), __LINE__, (message)) -#define TEST_ASSERT_LESS_OR_EQUAL_INT64_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_SMALLER_OR_EQUAL_INT64((threshold), (actual), __LINE__, (message)) -#define TEST_ASSERT_LESS_OR_EQUAL_UINT_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_SMALLER_OR_EQUAL_UINT((threshold), (actual), __LINE__, (message)) -#define TEST_ASSERT_LESS_OR_EQUAL_UINT8_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_SMALLER_OR_EQUAL_UINT8((threshold), (actual), __LINE__, (message)) -#define TEST_ASSERT_LESS_OR_EQUAL_UINT16_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_SMALLER_OR_EQUAL_UINT16((threshold), (actual), __LINE__, (message)) -#define TEST_ASSERT_LESS_OR_EQUAL_UINT32_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_SMALLER_OR_EQUAL_UINT32((threshold), (actual), __LINE__, (message)) -#define TEST_ASSERT_LESS_OR_EQUAL_UINT64_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_SMALLER_OR_EQUAL_UINT64((threshold), (actual), __LINE__, (message)) -#define TEST_ASSERT_LESS_OR_EQUAL_HEX8_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_SMALLER_OR_EQUAL_HEX8((threshold), (actual), __LINE__, (message)) -#define TEST_ASSERT_LESS_OR_EQUAL_HEX16_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_SMALLER_OR_EQUAL_HEX16((threshold), (actual), __LINE__, (message)) -#define TEST_ASSERT_LESS_OR_EQUAL_HEX32_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_SMALLER_OR_EQUAL_HEX32((threshold), (actual), __LINE__, (message)) -#define TEST_ASSERT_LESS_OR_EQUAL_HEX64_MESSAGE(threshold, actual, message) UNITY_TEST_ASSERT_SMALLER_OR_EQUAL_HEX64((threshold), (actual), __LINE__, (message)) - -/* Integer Ranges (of all sizes) */ -#define TEST_ASSERT_INT_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_INT_WITHIN((delta), (expected), (actual), __LINE__, (message)) -#define TEST_ASSERT_INT8_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_INT8_WITHIN((delta), (expected), (actual), __LINE__, (message)) -#define TEST_ASSERT_INT16_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_INT16_WITHIN((delta), (expected), (actual), __LINE__, (message)) -#define TEST_ASSERT_INT32_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_INT32_WITHIN((delta), (expected), (actual), __LINE__, (message)) -#define TEST_ASSERT_INT64_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_INT64_WITHIN((delta), (expected), (actual), __LINE__, (message)) -#define TEST_ASSERT_UINT_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_UINT_WITHIN((delta), (expected), (actual), __LINE__, (message)) -#define TEST_ASSERT_UINT8_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_UINT8_WITHIN((delta), (expected), (actual), __LINE__, (message)) -#define TEST_ASSERT_UINT16_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_UINT16_WITHIN((delta), (expected), (actual), __LINE__, (message)) -#define TEST_ASSERT_UINT32_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_UINT32_WITHIN((delta), (expected), (actual), __LINE__, (message)) -#define TEST_ASSERT_UINT64_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_UINT64_WITHIN((delta), (expected), (actual), __LINE__, (message)) -#define TEST_ASSERT_HEX_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_HEX32_WITHIN((delta), (expected), (actual), __LINE__, (message)) -#define TEST_ASSERT_HEX8_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_HEX8_WITHIN((delta), (expected), (actual), __LINE__, (message)) -#define TEST_ASSERT_HEX16_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_HEX16_WITHIN((delta), (expected), (actual), __LINE__, (message)) -#define TEST_ASSERT_HEX32_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_HEX32_WITHIN((delta), (expected), (actual), __LINE__, (message)) -#define TEST_ASSERT_HEX64_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_HEX64_WITHIN((delta), (expected), (actual), __LINE__, (message)) - -/* Integer Array Ranges (of all sizes) */ -#define TEST_ASSERT_INT_ARRAY_WITHIN_MESSAGE(delta, expected, actual, num_elements, message) UNITY_TEST_ASSERT_INT_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, (message)) -#define TEST_ASSERT_INT8_ARRAY_WITHIN_MESSAGE(delta, expected, actual, num_elements, message) UNITY_TEST_ASSERT_INT8_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, (message)) -#define TEST_ASSERT_INT16_ARRAY_WITHIN_MESSAGE(delta, expected, actual, num_elements, message) UNITY_TEST_ASSERT_INT16_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, (message)) -#define TEST_ASSERT_INT32_ARRAY_WITHIN_MESSAGE(delta, expected, actual, num_elements, message) UNITY_TEST_ASSERT_INT32_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, (message)) -#define TEST_ASSERT_INT64_ARRAY_WITHIN_MESSAGE(delta, expected, actual, num_elements, message) UNITY_TEST_ASSERT_INT64_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, (message)) -#define TEST_ASSERT_UINT_ARRAY_WITHIN_MESSAGE(delta, expected, actual, num_elements, message) UNITY_TEST_ASSERT_UINT_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, (message)) -#define TEST_ASSERT_UINT8_ARRAY_WITHIN_MESSAGE(delta, expected, actual, num_elements, message) UNITY_TEST_ASSERT_UINT8_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, (message)) -#define TEST_ASSERT_UINT16_ARRAY_WITHIN_MESSAGE(delta, expected, actual, num_elements, message) UNITY_TEST_ASSERT_UINT16_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, (message)) -#define TEST_ASSERT_UINT32_ARRAY_WITHIN_MESSAGE(delta, expected, actual, num_elements, message) UNITY_TEST_ASSERT_UINT32_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, (message)) -#define TEST_ASSERT_UINT64_ARRAY_WITHIN_MESSAGE(delta, expected, actual, num_elements, message) UNITY_TEST_ASSERT_UINT64_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, (message)) -#define TEST_ASSERT_HEX_ARRAY_WITHIN_MESSAGE(delta, expected, actual, num_elements, message) UNITY_TEST_ASSERT_HEX32_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, (message)) -#define TEST_ASSERT_HEX8_ARRAY_WITHIN_MESSAGE(delta, expected, actual, num_elements, message) UNITY_TEST_ASSERT_HEX8_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, (message)) -#define TEST_ASSERT_HEX16_ARRAY_WITHIN_MESSAGE(delta, expected, actual, num_elements, message) UNITY_TEST_ASSERT_HEX16_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, (message)) -#define TEST_ASSERT_HEX32_ARRAY_WITHIN_MESSAGE(delta, expected, actual, num_elements, message) UNITY_TEST_ASSERT_HEX32_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, (message)) -#define TEST_ASSERT_HEX64_ARRAY_WITHIN_MESSAGE(delta, expected, actual, num_elements, message) UNITY_TEST_ASSERT_HEX64_ARRAY_WITHIN((delta), (expected), (actual), num_elements, __LINE__, (message)) - - -/* Structs and Strings */ -#define TEST_ASSERT_EQUAL_PTR_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_PTR((expected), (actual), __LINE__, (message)) -#define TEST_ASSERT_EQUAL_STRING_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_STRING((expected), (actual), __LINE__, (message)) -#define TEST_ASSERT_EQUAL_STRING_LEN_MESSAGE(expected, actual, len, message) UNITY_TEST_ASSERT_EQUAL_STRING_LEN((expected), (actual), (len), __LINE__, (message)) -#define TEST_ASSERT_EQUAL_MEMORY_MESSAGE(expected, actual, len, message) UNITY_TEST_ASSERT_EQUAL_MEMORY((expected), (actual), (len), __LINE__, (message)) - -/* Arrays */ -#define TEST_ASSERT_EQUAL_INT_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_INT_ARRAY((expected), (actual), (num_elements), __LINE__, (message)) -#define TEST_ASSERT_EQUAL_INT8_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_INT8_ARRAY((expected), (actual), (num_elements), __LINE__, (message)) -#define TEST_ASSERT_EQUAL_INT16_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_INT16_ARRAY((expected), (actual), (num_elements), __LINE__, (message)) -#define TEST_ASSERT_EQUAL_INT32_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_INT32_ARRAY((expected), (actual), (num_elements), __LINE__, (message)) -#define TEST_ASSERT_EQUAL_INT64_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_INT64_ARRAY((expected), (actual), (num_elements), __LINE__, (message)) -#define TEST_ASSERT_EQUAL_UINT_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_UINT_ARRAY((expected), (actual), (num_elements), __LINE__, (message)) -#define TEST_ASSERT_EQUAL_UINT8_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_UINT8_ARRAY((expected), (actual), (num_elements), __LINE__, (message)) -#define TEST_ASSERT_EQUAL_UINT16_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_UINT16_ARRAY((expected), (actual), (num_elements), __LINE__, (message)) -#define TEST_ASSERT_EQUAL_UINT32_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_UINT32_ARRAY((expected), (actual), (num_elements), __LINE__, (message)) -#define TEST_ASSERT_EQUAL_UINT64_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_UINT64_ARRAY((expected), (actual), (num_elements), __LINE__, (message)) -#define TEST_ASSERT_EQUAL_HEX_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_HEX32_ARRAY((expected), (actual), (num_elements), __LINE__, (message)) -#define TEST_ASSERT_EQUAL_HEX8_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_HEX8_ARRAY((expected), (actual), (num_elements), __LINE__, (message)) -#define TEST_ASSERT_EQUAL_HEX16_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_HEX16_ARRAY((expected), (actual), (num_elements), __LINE__, (message)) -#define TEST_ASSERT_EQUAL_HEX32_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_HEX32_ARRAY((expected), (actual), (num_elements), __LINE__, (message)) -#define TEST_ASSERT_EQUAL_HEX64_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_HEX64_ARRAY((expected), (actual), (num_elements), __LINE__, (message)) -#define TEST_ASSERT_EQUAL_PTR_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_PTR_ARRAY((expected), (actual), (num_elements), __LINE__, (message)) -#define TEST_ASSERT_EQUAL_STRING_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_STRING_ARRAY((expected), (actual), (num_elements), __LINE__, (message)) -#define TEST_ASSERT_EQUAL_MEMORY_ARRAY_MESSAGE(expected, actual, len, num_elements, message) UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY((expected), (actual), (len), (num_elements), __LINE__, (message)) - -/* Arrays Compared To Single Value*/ -#define TEST_ASSERT_EACH_EQUAL_INT_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EACH_EQUAL_INT((expected), (actual), (num_elements), __LINE__, (message)) -#define TEST_ASSERT_EACH_EQUAL_INT8_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EACH_EQUAL_INT8((expected), (actual), (num_elements), __LINE__, (message)) -#define TEST_ASSERT_EACH_EQUAL_INT16_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EACH_EQUAL_INT16((expected), (actual), (num_elements), __LINE__, (message)) -#define TEST_ASSERT_EACH_EQUAL_INT32_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EACH_EQUAL_INT32((expected), (actual), (num_elements), __LINE__, (message)) -#define TEST_ASSERT_EACH_EQUAL_INT64_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EACH_EQUAL_INT64((expected), (actual), (num_elements), __LINE__, (message)) -#define TEST_ASSERT_EACH_EQUAL_UINT_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EACH_EQUAL_UINT((expected), (actual), (num_elements), __LINE__, (message)) -#define TEST_ASSERT_EACH_EQUAL_UINT8_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EACH_EQUAL_UINT8((expected), (actual), (num_elements), __LINE__, (message)) -#define TEST_ASSERT_EACH_EQUAL_UINT16_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EACH_EQUAL_UINT16((expected), (actual), (num_elements), __LINE__, (message)) -#define TEST_ASSERT_EACH_EQUAL_UINT32_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EACH_EQUAL_UINT32((expected), (actual), (num_elements), __LINE__, (message)) -#define TEST_ASSERT_EACH_EQUAL_UINT64_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EACH_EQUAL_UINT64((expected), (actual), (num_elements), __LINE__, (message)) -#define TEST_ASSERT_EACH_EQUAL_HEX_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EACH_EQUAL_HEX32((expected), (actual), (num_elements), __LINE__, (message)) -#define TEST_ASSERT_EACH_EQUAL_HEX8_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EACH_EQUAL_HEX8((expected), (actual), (num_elements), __LINE__, (message)) -#define TEST_ASSERT_EACH_EQUAL_HEX16_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EACH_EQUAL_HEX16((expected), (actual), (num_elements), __LINE__, (message)) -#define TEST_ASSERT_EACH_EQUAL_HEX32_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EACH_EQUAL_HEX32((expected), (actual), (num_elements), __LINE__, (message)) -#define TEST_ASSERT_EACH_EQUAL_HEX64_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EACH_EQUAL_HEX64((expected), (actual), (num_elements), __LINE__, (message)) -#define TEST_ASSERT_EACH_EQUAL_PTR_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EACH_EQUAL_PTR((expected), (actual), (num_elements), __LINE__, (message)) -#define TEST_ASSERT_EACH_EQUAL_STRING_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EACH_EQUAL_STRING((expected), (actual), (num_elements), __LINE__, (message)) -#define TEST_ASSERT_EACH_EQUAL_MEMORY_MESSAGE(expected, actual, len, num_elements, message) UNITY_TEST_ASSERT_EACH_EQUAL_MEMORY((expected), (actual), (len), (num_elements), __LINE__, (message)) - -/* Floating Point (If Enabled) */ -#define TEST_ASSERT_FLOAT_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_FLOAT_WITHIN((delta), (expected), (actual), __LINE__, (message)) -#define TEST_ASSERT_EQUAL_FLOAT_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_FLOAT((expected), (actual), __LINE__, (message)) -#define TEST_ASSERT_EQUAL_FLOAT_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_FLOAT_ARRAY((expected), (actual), (num_elements), __LINE__, (message)) -#define TEST_ASSERT_EACH_EQUAL_FLOAT_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EACH_EQUAL_FLOAT((expected), (actual), (num_elements), __LINE__, (message)) -#define TEST_ASSERT_FLOAT_IS_INF_MESSAGE(actual, message) UNITY_TEST_ASSERT_FLOAT_IS_INF((actual), __LINE__, (message)) -#define TEST_ASSERT_FLOAT_IS_NEG_INF_MESSAGE(actual, message) UNITY_TEST_ASSERT_FLOAT_IS_NEG_INF((actual), __LINE__, (message)) -#define TEST_ASSERT_FLOAT_IS_NAN_MESSAGE(actual, message) UNITY_TEST_ASSERT_FLOAT_IS_NAN((actual), __LINE__, (message)) -#define TEST_ASSERT_FLOAT_IS_DETERMINATE_MESSAGE(actual, message) UNITY_TEST_ASSERT_FLOAT_IS_DETERMINATE((actual), __LINE__, (message)) -#define TEST_ASSERT_FLOAT_IS_NOT_INF_MESSAGE(actual, message) UNITY_TEST_ASSERT_FLOAT_IS_NOT_INF((actual), __LINE__, (message)) -#define TEST_ASSERT_FLOAT_IS_NOT_NEG_INF_MESSAGE(actual, message) UNITY_TEST_ASSERT_FLOAT_IS_NOT_NEG_INF((actual), __LINE__, (message)) -#define TEST_ASSERT_FLOAT_IS_NOT_NAN_MESSAGE(actual, message) UNITY_TEST_ASSERT_FLOAT_IS_NOT_NAN((actual), __LINE__, (message)) -#define TEST_ASSERT_FLOAT_IS_NOT_DETERMINATE_MESSAGE(actual, message) UNITY_TEST_ASSERT_FLOAT_IS_NOT_DETERMINATE((actual), __LINE__, (message)) - -/* Double (If Enabled) */ -#define TEST_ASSERT_DOUBLE_WITHIN_MESSAGE(delta, expected, actual, message) UNITY_TEST_ASSERT_DOUBLE_WITHIN((delta), (expected), (actual), __LINE__, (message)) -#define TEST_ASSERT_EQUAL_DOUBLE_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_DOUBLE((expected), (actual), __LINE__, (message)) -#define TEST_ASSERT_EQUAL_DOUBLE_ARRAY_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EQUAL_DOUBLE_ARRAY((expected), (actual), (num_elements), __LINE__, (message)) -#define TEST_ASSERT_EACH_EQUAL_DOUBLE_MESSAGE(expected, actual, num_elements, message) UNITY_TEST_ASSERT_EACH_EQUAL_DOUBLE((expected), (actual), (num_elements), __LINE__, (message)) -#define TEST_ASSERT_DOUBLE_IS_INF_MESSAGE(actual, message) UNITY_TEST_ASSERT_DOUBLE_IS_INF((actual), __LINE__, (message)) -#define TEST_ASSERT_DOUBLE_IS_NEG_INF_MESSAGE(actual, message) UNITY_TEST_ASSERT_DOUBLE_IS_NEG_INF((actual), __LINE__, (message)) -#define TEST_ASSERT_DOUBLE_IS_NAN_MESSAGE(actual, message) UNITY_TEST_ASSERT_DOUBLE_IS_NAN((actual), __LINE__, (message)) -#define TEST_ASSERT_DOUBLE_IS_DETERMINATE_MESSAGE(actual, message) UNITY_TEST_ASSERT_DOUBLE_IS_DETERMINATE((actual), __LINE__, (message)) -#define TEST_ASSERT_DOUBLE_IS_NOT_INF_MESSAGE(actual, message) UNITY_TEST_ASSERT_DOUBLE_IS_NOT_INF((actual), __LINE__, (message)) -#define TEST_ASSERT_DOUBLE_IS_NOT_NEG_INF_MESSAGE(actual, message) UNITY_TEST_ASSERT_DOUBLE_IS_NOT_NEG_INF((actual), __LINE__, (message)) -#define TEST_ASSERT_DOUBLE_IS_NOT_NAN_MESSAGE(actual, message) UNITY_TEST_ASSERT_DOUBLE_IS_NOT_NAN((actual), __LINE__, (message)) -#define TEST_ASSERT_DOUBLE_IS_NOT_DETERMINATE_MESSAGE(actual, message) UNITY_TEST_ASSERT_DOUBLE_IS_NOT_DETERMINATE((actual), __LINE__, (message)) - -/* Shorthand */ -#ifdef UNITY_SHORTHAND_AS_OLD -#define TEST_ASSERT_EQUAL_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_INT((expected), (actual), __LINE__, (message)) -#define TEST_ASSERT_NOT_EQUAL_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT(((expected) != (actual)), __LINE__, (message)) -#endif -#ifdef UNITY_SHORTHAND_AS_INT -#define TEST_ASSERT_EQUAL_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_INT((expected), (actual), __LINE__, message) -#define TEST_ASSERT_NOT_EQUAL_MESSAGE(expected, actual, message) UNITY_TEST_FAIL(__LINE__, UnityStrErrShorthand) -#endif -#ifdef UNITY_SHORTHAND_AS_MEM -#define TEST_ASSERT_EQUAL_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT_EQUAL_MEMORY((&expected), (&actual), sizeof(expected), __LINE__, message) -#define TEST_ASSERT_NOT_EQUAL_MESSAGE(expected, actual, message) UNITY_TEST_FAIL(__LINE__, UnityStrErrShorthand) -#endif -#ifdef UNITY_SHORTHAND_AS_RAW -#define TEST_ASSERT_EQUAL_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT(((expected) == (actual)), __LINE__, message) -#define TEST_ASSERT_NOT_EQUAL_MESSAGE(expected, actual, message) UNITY_TEST_ASSERT(((expected) != (actual)), __LINE__, message) -#endif -#ifdef UNITY_SHORTHAND_AS_NONE -#define TEST_ASSERT_EQUAL_MESSAGE(expected, actual, message) UNITY_TEST_FAIL(__LINE__, UnityStrErrShorthand) -#define TEST_ASSERT_NOT_EQUAL_MESSAGE(expected, actual, message) UNITY_TEST_FAIL(__LINE__, UnityStrErrShorthand) -#endif - -/* end of UNITY_FRAMEWORK_H */ -#ifdef __cplusplus -} -#endif -#endif diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/unity/src/unity_internals.h b/bk7235/liteos_m/bk_sdk_armino/middleware/compal/unity/src/unity_internals.h deleted file mode 100755 index 0dd08fb5480861dbe0cde3fa0297a5ba22438286..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/compal/unity/src/unity_internals.h +++ /dev/null @@ -1,1003 +0,0 @@ -/* ========================================== - Unity Project - A Test Framework for C - Copyright (c) 2007-19 Mike Karlesky, Mark VanderVoord, Greg Williams - [Released under MIT License. Please refer to license.txt for details] -========================================== */ - -#ifndef UNITY_INTERNALS_H -#define UNITY_INTERNALS_H - -#ifdef UNITY_INCLUDE_CONFIG_H -#include "unity_config.h" -#endif - -#ifndef UNITY_EXCLUDE_SETJMP_H -#include -#endif - -#ifndef UNITY_EXCLUDE_MATH_H -#include -#endif - -#ifndef UNITY_EXCLUDE_STDDEF_H -#include -#endif - -#ifdef UNITY_INCLUDE_PRINT_FORMATTED -#include -#endif - -/* Unity Attempts to Auto-Detect Integer Types - * Attempt 1: UINT_MAX, ULONG_MAX in , or default to 32 bits - * Attempt 2: UINTPTR_MAX in , or default to same size as long - * The user may override any of these derived constants: - * UNITY_INT_WIDTH, UNITY_LONG_WIDTH, UNITY_POINTER_WIDTH */ -#ifndef UNITY_EXCLUDE_STDINT_H -#include -#endif - -#ifndef UNITY_EXCLUDE_LIMITS_H -#include -#endif - -/*------------------------------------------------------- - * Guess Widths If Not Specified - *-------------------------------------------------------*/ - -/* Determine the size of an int, if not already specified. - * We cannot use sizeof(int), because it is not yet defined - * at this stage in the translation of the C program. - * Also sizeof(int) does return the size in addressable units on all platforms, - * which may not necessarily be the size in bytes. - * Therefore, infer it from UINT_MAX if possible. */ -#ifndef UNITY_INT_WIDTH - #ifdef UINT_MAX - #if (UINT_MAX == 0xFFFF) - #define UNITY_INT_WIDTH (16) - #elif (UINT_MAX == 0xFFFFFFFF) - #define UNITY_INT_WIDTH (32) - #elif (UINT_MAX == 0xFFFFFFFFFFFFFFFF) - #define UNITY_INT_WIDTH (64) - #endif - #else /* Set to default */ - #define UNITY_INT_WIDTH (32) - #endif /* UINT_MAX */ -#endif - -/* Determine the size of a long, if not already specified. */ -#ifndef UNITY_LONG_WIDTH - #ifdef ULONG_MAX - #if (ULONG_MAX == 0xFFFF) - #define UNITY_LONG_WIDTH (16) - #elif (ULONG_MAX == 0xFFFFFFFF) - #define UNITY_LONG_WIDTH (32) - #elif (ULONG_MAX == 0xFFFFFFFFFFFFFFFF) - #define UNITY_LONG_WIDTH (64) - #endif - #else /* Set to default */ - #define UNITY_LONG_WIDTH (32) - #endif /* ULONG_MAX */ -#endif - -/* Determine the size of a pointer, if not already specified. */ -#ifndef UNITY_POINTER_WIDTH - #ifdef UINTPTR_MAX - #if (UINTPTR_MAX <= 0xFFFF) - #define UNITY_POINTER_WIDTH (16) - #elif (UINTPTR_MAX <= 0xFFFFFFFF) - #define UNITY_POINTER_WIDTH (32) - #elif (UINTPTR_MAX <= 0xFFFFFFFFFFFFFFFF) - #define UNITY_POINTER_WIDTH (64) - #endif - #else /* Set to default */ - #define UNITY_POINTER_WIDTH UNITY_LONG_WIDTH - #endif /* UINTPTR_MAX */ -#endif - -/*------------------------------------------------------- - * Int Support (Define types based on detected sizes) - *-------------------------------------------------------*/ - -#if (UNITY_INT_WIDTH == 32) - typedef unsigned char UNITY_UINT8; - typedef unsigned short UNITY_UINT16; - typedef unsigned int UNITY_UINT32; - typedef signed char UNITY_INT8; - typedef signed short UNITY_INT16; - typedef signed int UNITY_INT32; -#elif (UNITY_INT_WIDTH == 16) - typedef unsigned char UNITY_UINT8; - typedef unsigned int UNITY_UINT16; - typedef unsigned long UNITY_UINT32; - typedef signed char UNITY_INT8; - typedef signed int UNITY_INT16; - typedef signed long UNITY_INT32; -#else - #error Invalid UNITY_INT_WIDTH specified! (16 or 32 are supported) -#endif - -/*------------------------------------------------------- - * 64-bit Support - *-------------------------------------------------------*/ - -/* Auto-detect 64 Bit Support */ -#ifndef UNITY_SUPPORT_64 - #if UNITY_LONG_WIDTH == 64 || UNITY_POINTER_WIDTH == 64 - #define UNITY_SUPPORT_64 - #endif -#endif - -/* 64-Bit Support Dependent Configuration */ -#ifndef UNITY_SUPPORT_64 - /* No 64-bit Support */ - typedef UNITY_UINT32 UNITY_UINT; - typedef UNITY_INT32 UNITY_INT; - #define UNITY_MAX_NIBBLES (8) /* Maximum number of nibbles in a UNITY_(U)INT */ -#else - /* 64-bit Support */ - #if (UNITY_LONG_WIDTH == 32) - typedef unsigned long long UNITY_UINT64; - typedef signed long long UNITY_INT64; - #elif (UNITY_LONG_WIDTH == 64) - typedef unsigned long UNITY_UINT64; - typedef signed long UNITY_INT64; - #else - #error Invalid UNITY_LONG_WIDTH specified! (32 or 64 are supported) - #endif - typedef UNITY_UINT64 UNITY_UINT; - typedef UNITY_INT64 UNITY_INT; - #define UNITY_MAX_NIBBLES (16) /* Maximum number of nibbles in a UNITY_(U)INT */ -#endif - -/*------------------------------------------------------- - * Pointer Support - *-------------------------------------------------------*/ - -#if (UNITY_POINTER_WIDTH == 32) - #define UNITY_PTR_TO_INT UNITY_INT32 - #define UNITY_DISPLAY_STYLE_POINTER UNITY_DISPLAY_STYLE_HEX32 -#elif (UNITY_POINTER_WIDTH == 64) - #define UNITY_PTR_TO_INT UNITY_INT64 - #define UNITY_DISPLAY_STYLE_POINTER UNITY_DISPLAY_STYLE_HEX64 -#elif (UNITY_POINTER_WIDTH == 16) - #define UNITY_PTR_TO_INT UNITY_INT16 - #define UNITY_DISPLAY_STYLE_POINTER UNITY_DISPLAY_STYLE_HEX16 -#else - #error Invalid UNITY_POINTER_WIDTH specified! (16, 32 or 64 are supported) -#endif - -#ifndef UNITY_PTR_ATTRIBUTE - #define UNITY_PTR_ATTRIBUTE -#endif - -#ifndef UNITY_INTERNAL_PTR - #define UNITY_INTERNAL_PTR UNITY_PTR_ATTRIBUTE const void* -#endif - -/*------------------------------------------------------- - * Float Support - *-------------------------------------------------------*/ - -#ifdef UNITY_EXCLUDE_FLOAT - -/* No Floating Point Support */ -#ifndef UNITY_EXCLUDE_DOUBLE -#define UNITY_EXCLUDE_DOUBLE /* Remove double when excluding float support */ -#endif -#ifndef UNITY_EXCLUDE_FLOAT_PRINT -#define UNITY_EXCLUDE_FLOAT_PRINT -#endif - -#else - -/* Floating Point Support */ -#ifndef UNITY_FLOAT_PRECISION -#define UNITY_FLOAT_PRECISION (0.00001f) -#endif -#ifndef UNITY_FLOAT_TYPE -#define UNITY_FLOAT_TYPE float -#endif -typedef UNITY_FLOAT_TYPE UNITY_FLOAT; - -/* isinf & isnan macros should be provided by math.h */ -#ifndef isinf -/* The value of Inf - Inf is NaN */ -#define isinf(n) (isnan((n) - (n)) && !isnan(n)) -#endif - -#ifndef isnan -/* NaN is the only floating point value that does NOT equal itself. - * Therefore if n != n, then it is NaN. */ -#define isnan(n) ((n != n) ? 1 : 0) -#endif - -#endif - -/*------------------------------------------------------- - * Double Float Support - *-------------------------------------------------------*/ - -/* unlike float, we DON'T include by default */ -#if defined(UNITY_EXCLUDE_DOUBLE) || !defined(UNITY_INCLUDE_DOUBLE) - - /* No Floating Point Support */ - #ifndef UNITY_EXCLUDE_DOUBLE - #define UNITY_EXCLUDE_DOUBLE - #else - #undef UNITY_INCLUDE_DOUBLE - #endif - - #ifndef UNITY_EXCLUDE_FLOAT - #ifndef UNITY_DOUBLE_TYPE - #define UNITY_DOUBLE_TYPE double - #endif - typedef UNITY_FLOAT UNITY_DOUBLE; - /* For parameter in UnityPrintFloat(UNITY_DOUBLE), which aliases to double or float */ - #endif - -#else - - /* Double Floating Point Support */ - #ifndef UNITY_DOUBLE_PRECISION - #define UNITY_DOUBLE_PRECISION (1e-12) - #endif - - #ifndef UNITY_DOUBLE_TYPE - #define UNITY_DOUBLE_TYPE double - #endif - typedef UNITY_DOUBLE_TYPE UNITY_DOUBLE; - -#endif - -/*------------------------------------------------------- - * Output Method: stdout (DEFAULT) - *-------------------------------------------------------*/ -#ifndef UNITY_OUTPUT_CHAR - /* Default to using putchar, which is defined in stdio.h */ - #include - #define UNITY_OUTPUT_CHAR(a) (void)putchar(a) -#else - /* If defined as something else, make sure we declare it here so it's ready for use */ - #ifdef UNITY_OUTPUT_CHAR_HEADER_DECLARATION - extern void UNITY_OUTPUT_CHAR_HEADER_DECLARATION; - #endif -#endif - -#ifndef UNITY_OUTPUT_FLUSH - #ifdef UNITY_USE_FLUSH_STDOUT - /* We want to use the stdout flush utility */ - #include - #define UNITY_OUTPUT_FLUSH() (void)fflush(stdout) - #else - /* We've specified nothing, therefore flush should just be ignored */ - #define UNITY_OUTPUT_FLUSH() - #endif -#else - /* If defined as something else, make sure we declare it here so it's ready for use */ - #ifdef UNITY_OUTPUT_FLUSH_HEADER_DECLARATION - extern void UNITY_OUTPUT_FLUSH_HEADER_DECLARATION; - #endif -#endif - -#ifndef UNITY_OUTPUT_FLUSH -#define UNITY_FLUSH_CALL() -#else -#define UNITY_FLUSH_CALL() UNITY_OUTPUT_FLUSH() -#endif - -#ifndef UNITY_PRINT_EOL -#define UNITY_PRINT_EOL() UNITY_OUTPUT_CHAR('\n') -#endif - -#ifndef UNITY_OUTPUT_START -#define UNITY_OUTPUT_START() -#endif - -#ifndef UNITY_OUTPUT_COMPLETE -#define UNITY_OUTPUT_COMPLETE() -#endif - -#ifdef UNITY_INCLUDE_EXEC_TIME - #if !defined(UNITY_EXEC_TIME_START) && \ - !defined(UNITY_EXEC_TIME_STOP) && \ - !defined(UNITY_PRINT_EXEC_TIME) && \ - !defined(UNITY_TIME_TYPE) - /* If none any of these macros are defined then try to provide a default implementation */ - - #if defined(UNITY_CLOCK_MS) - /* This is a simple way to get a default implementation on platforms that support getting a millisecond counter */ - #define UNITY_TIME_TYPE UNITY_UINT - #define UNITY_EXEC_TIME_START() Unity.CurrentTestStartTime = UNITY_CLOCK_MS() - #define UNITY_EXEC_TIME_STOP() Unity.CurrentTestStopTime = UNITY_CLOCK_MS() - #define UNITY_PRINT_EXEC_TIME() { \ - UNITY_UINT execTimeMs = (Unity.CurrentTestStopTime - Unity.CurrentTestStartTime); \ - UnityPrint(" ("); \ - UnityPrintNumberUnsigned(execTimeMs); \ - UnityPrint(" ms)"); \ - } - #elif defined(_WIN32) - #include - #define UNITY_TIME_TYPE clock_t - #define UNITY_GET_TIME(t) t = (clock_t)((clock() * 1000) / CLOCKS_PER_SEC) - #define UNITY_EXEC_TIME_START() UNITY_GET_TIME(Unity.CurrentTestStartTime) - #define UNITY_EXEC_TIME_STOP() UNITY_GET_TIME(Unity.CurrentTestStopTime) - #define UNITY_PRINT_EXEC_TIME() { \ - UNITY_UINT execTimeMs = (Unity.CurrentTestStopTime - Unity.CurrentTestStartTime); \ - UnityPrint(" ("); \ - UnityPrintNumberUnsigned(execTimeMs); \ - UnityPrint(" ms)"); \ - } - #elif defined(__unix__) - #include - #define UNITY_TIME_TYPE struct timespec - #define UNITY_GET_TIME(t) clock_gettime(CLOCK_MONOTONIC, &t) - #define UNITY_EXEC_TIME_START() UNITY_GET_TIME(Unity.CurrentTestStartTime) - #define UNITY_EXEC_TIME_STOP() UNITY_GET_TIME(Unity.CurrentTestStopTime) - #define UNITY_PRINT_EXEC_TIME() { \ - UNITY_UINT execTimeMs = ((Unity.CurrentTestStopTime.tv_sec - Unity.CurrentTestStartTime.tv_sec) * 1000L); \ - execTimeMs += ((Unity.CurrentTestStopTime.tv_nsec - Unity.CurrentTestStartTime.tv_nsec) / 1000000L); \ - UnityPrint(" ("); \ - UnityPrintNumberUnsigned(execTimeMs); \ - UnityPrint(" ms)"); \ - } - #endif - #endif -#endif - -#ifndef UNITY_EXEC_TIME_START -#define UNITY_EXEC_TIME_START() do{}while(0) -#endif - -#ifndef UNITY_EXEC_TIME_STOP -#define UNITY_EXEC_TIME_STOP() do{}while(0) -#endif - -#ifndef UNITY_TIME_TYPE -#define UNITY_TIME_TYPE UNITY_UINT -#endif - -#ifndef UNITY_PRINT_EXEC_TIME -#define UNITY_PRINT_EXEC_TIME() do{}while(0) -#endif - -/*------------------------------------------------------- - * Footprint - *-------------------------------------------------------*/ - -#ifndef UNITY_LINE_TYPE -#define UNITY_LINE_TYPE UNITY_UINT -#endif - -#ifndef UNITY_COUNTER_TYPE -#define UNITY_COUNTER_TYPE UNITY_UINT -#endif - -/*------------------------------------------------------- - * Language Features Available - *-------------------------------------------------------*/ -#if !defined(UNITY_WEAK_ATTRIBUTE) && !defined(UNITY_WEAK_PRAGMA) -# if defined(__GNUC__) || defined(__ghs__) /* __GNUC__ includes clang */ -# if !(defined(__WIN32__) && defined(__clang__)) && !defined(__TMS470__) -# define UNITY_WEAK_ATTRIBUTE __attribute__((weak)) -# endif -# endif -#endif - -#ifdef UNITY_NO_WEAK -# undef UNITY_WEAK_ATTRIBUTE -# undef UNITY_WEAK_PRAGMA -#endif - -/*------------------------------------------------------- - * Internal Structs Needed - *-------------------------------------------------------*/ - -typedef void (*UnityTestFunction)(void); - -#define UNITY_DISPLAY_RANGE_INT (0x10) -#define UNITY_DISPLAY_RANGE_UINT (0x20) -#define UNITY_DISPLAY_RANGE_HEX (0x40) - -typedef enum -{ - UNITY_DISPLAY_STYLE_INT = (UNITY_INT_WIDTH / 8) + UNITY_DISPLAY_RANGE_INT, - UNITY_DISPLAY_STYLE_INT8 = 1 + UNITY_DISPLAY_RANGE_INT, - UNITY_DISPLAY_STYLE_INT16 = 2 + UNITY_DISPLAY_RANGE_INT, - UNITY_DISPLAY_STYLE_INT32 = 4 + UNITY_DISPLAY_RANGE_INT, -#ifdef UNITY_SUPPORT_64 - UNITY_DISPLAY_STYLE_INT64 = 8 + UNITY_DISPLAY_RANGE_INT, -#endif - - UNITY_DISPLAY_STYLE_UINT = (UNITY_INT_WIDTH / 8) + UNITY_DISPLAY_RANGE_UINT, - UNITY_DISPLAY_STYLE_UINT8 = 1 + UNITY_DISPLAY_RANGE_UINT, - UNITY_DISPLAY_STYLE_UINT16 = 2 + UNITY_DISPLAY_RANGE_UINT, - UNITY_DISPLAY_STYLE_UINT32 = 4 + UNITY_DISPLAY_RANGE_UINT, -#ifdef UNITY_SUPPORT_64 - UNITY_DISPLAY_STYLE_UINT64 = 8 + UNITY_DISPLAY_RANGE_UINT, -#endif - - UNITY_DISPLAY_STYLE_HEX8 = 1 + UNITY_DISPLAY_RANGE_HEX, - UNITY_DISPLAY_STYLE_HEX16 = 2 + UNITY_DISPLAY_RANGE_HEX, - UNITY_DISPLAY_STYLE_HEX32 = 4 + UNITY_DISPLAY_RANGE_HEX, -#ifdef UNITY_SUPPORT_64 - UNITY_DISPLAY_STYLE_HEX64 = 8 + UNITY_DISPLAY_RANGE_HEX, -#endif - - UNITY_DISPLAY_STYLE_UNKNOWN -} UNITY_DISPLAY_STYLE_T; - -typedef enum -{ - UNITY_WITHIN = 0x0, - UNITY_EQUAL_TO = 0x1, - UNITY_GREATER_THAN = 0x2, - UNITY_GREATER_OR_EQUAL = 0x2 + UNITY_EQUAL_TO, - UNITY_SMALLER_THAN = 0x4, - UNITY_SMALLER_OR_EQUAL = 0x4 + UNITY_EQUAL_TO, - UNITY_UNKNOWN -} UNITY_COMPARISON_T; - -#ifndef UNITY_EXCLUDE_FLOAT -typedef enum UNITY_FLOAT_TRAIT -{ - UNITY_FLOAT_IS_NOT_INF = 0, - UNITY_FLOAT_IS_INF, - UNITY_FLOAT_IS_NOT_NEG_INF, - UNITY_FLOAT_IS_NEG_INF, - UNITY_FLOAT_IS_NOT_NAN, - UNITY_FLOAT_IS_NAN, - UNITY_FLOAT_IS_NOT_DET, - UNITY_FLOAT_IS_DET, - UNITY_FLOAT_INVALID_TRAIT -} UNITY_FLOAT_TRAIT_T; -#endif - -typedef enum -{ - UNITY_ARRAY_TO_VAL = 0, - UNITY_ARRAY_TO_ARRAY, - UNITY_ARRAY_UNKNOWN -} UNITY_FLAGS_T; - -struct UNITY_STORAGE_T -{ - const char* TestFile; - const char* CurrentTestName; -#ifndef UNITY_EXCLUDE_DETAILS - const char* CurrentDetail1; - const char* CurrentDetail2; -#endif - UNITY_LINE_TYPE CurrentTestLineNumber; - UNITY_COUNTER_TYPE NumberOfTests; - UNITY_COUNTER_TYPE TestFailures; - UNITY_COUNTER_TYPE TestIgnores; - UNITY_COUNTER_TYPE CurrentTestFailed; - UNITY_COUNTER_TYPE CurrentTestIgnored; -#ifdef UNITY_INCLUDE_EXEC_TIME - UNITY_TIME_TYPE CurrentTestStartTime; - UNITY_TIME_TYPE CurrentTestStopTime; -#endif -#ifndef UNITY_EXCLUDE_SETJMP_H - jmp_buf AbortFrame; -#endif -}; - -extern struct UNITY_STORAGE_T Unity; - -/*------------------------------------------------------- - * Test Suite Management - *-------------------------------------------------------*/ - -void UnityBegin(const char* filename); -int UnityEnd(void); -void UnityConcludeTest(void); -void UnityDefaultTestRun(UnityTestFunction Func, const char* FuncName, const int FuncLineNum); - -/*------------------------------------------------------- - * Details Support - *-------------------------------------------------------*/ - -#ifdef UNITY_EXCLUDE_DETAILS -#define UNITY_CLR_DETAILS() -#define UNITY_SET_DETAIL(d1) -#define UNITY_SET_DETAILS(d1,d2) -#else -#define UNITY_CLR_DETAILS() { Unity.CurrentDetail1 = 0; Unity.CurrentDetail2 = 0; } -#define UNITY_SET_DETAIL(d1) { Unity.CurrentDetail1 = (d1); Unity.CurrentDetail2 = 0; } -#define UNITY_SET_DETAILS(d1,d2) { Unity.CurrentDetail1 = (d1); Unity.CurrentDetail2 = (d2); } - -#ifndef UNITY_DETAIL1_NAME -#define UNITY_DETAIL1_NAME "Function" -#endif - -#ifndef UNITY_DETAIL2_NAME -#define UNITY_DETAIL2_NAME "Argument" -#endif -#endif - -/*------------------------------------------------------- - * Test Output - *-------------------------------------------------------*/ - -void UnityPrint(const char* string); - -#ifdef UNITY_INCLUDE_PRINT_FORMATTED -void UnityPrintFormatted(const char* format, ...); -#endif - -void UnityPrintLen(const char* string, const UNITY_UINT32 length); -void UnityPrintMask(const UNITY_UINT mask, const UNITY_UINT number); -void UnityPrintNumberByStyle(const UNITY_INT number, const UNITY_DISPLAY_STYLE_T style); -void UnityPrintNumber(const UNITY_INT number_to_print); -void UnityPrintNumberUnsigned(const UNITY_UINT number); -void UnityPrintNumberHex(const UNITY_UINT number, const char nibbles_to_print); - -#ifndef UNITY_EXCLUDE_FLOAT_PRINT -void UnityPrintFloat(const UNITY_DOUBLE input_number); -#endif - -/*------------------------------------------------------- - * Test Assertion Functions - *------------------------------------------------------- - * Use the macros below this section instead of calling - * these directly. The macros have a consistent naming - * convention and will pull in file and line information - * for you. */ - -void UnityAssertEqualNumber(const UNITY_INT expected, - const UNITY_INT actual, - const char* msg, - const UNITY_LINE_TYPE lineNumber, - const UNITY_DISPLAY_STYLE_T style); - -void UnityAssertGreaterOrLessOrEqualNumber(const UNITY_INT threshold, - const UNITY_INT actual, - const UNITY_COMPARISON_T compare, - const char *msg, - const UNITY_LINE_TYPE lineNumber, - const UNITY_DISPLAY_STYLE_T style); - -void UnityAssertEqualIntArray(UNITY_INTERNAL_PTR expected, - UNITY_INTERNAL_PTR actual, - const UNITY_UINT32 num_elements, - const char* msg, - const UNITY_LINE_TYPE lineNumber, - const UNITY_DISPLAY_STYLE_T style, - const UNITY_FLAGS_T flags); - -void UnityAssertBits(const UNITY_INT mask, - const UNITY_INT expected, - const UNITY_INT actual, - const char* msg, - const UNITY_LINE_TYPE lineNumber); - -void UnityAssertEqualString(const char* expected, - const char* actual, - const char* msg, - const UNITY_LINE_TYPE lineNumber); - -void UnityAssertEqualStringLen(const char* expected, - const char* actual, - const UNITY_UINT32 length, - const char* msg, - const UNITY_LINE_TYPE lineNumber); - -void UnityAssertEqualStringArray( UNITY_INTERNAL_PTR expected, - const char** actual, - const UNITY_UINT32 num_elements, - const char* msg, - const UNITY_LINE_TYPE lineNumber, - const UNITY_FLAGS_T flags); - -void UnityAssertEqualMemory( UNITY_INTERNAL_PTR expected, - UNITY_INTERNAL_PTR actual, - const UNITY_UINT32 length, - const UNITY_UINT32 num_elements, - const char* msg, - const UNITY_LINE_TYPE lineNumber, - const UNITY_FLAGS_T flags); - -void UnityAssertNumbersWithin(const UNITY_UINT delta, - const UNITY_INT expected, - const UNITY_INT actual, - const char* msg, - const UNITY_LINE_TYPE lineNumber, - const UNITY_DISPLAY_STYLE_T style); - -void UnityAssertNumbersArrayWithin(const UNITY_UINT delta, - UNITY_INTERNAL_PTR expected, - UNITY_INTERNAL_PTR actual, - const UNITY_UINT32 num_elements, - const char* msg, - const UNITY_LINE_TYPE lineNumber, - const UNITY_DISPLAY_STYLE_T style, - const UNITY_FLAGS_T flags); - -void UnityFail(const char* message, const UNITY_LINE_TYPE line); -void UnityIgnore(const char* message, const UNITY_LINE_TYPE line); -void UnityMessage(const char* message, const UNITY_LINE_TYPE line); - -#ifndef UNITY_EXCLUDE_FLOAT -void UnityAssertFloatsWithin(const UNITY_FLOAT delta, - const UNITY_FLOAT expected, - const UNITY_FLOAT actual, - const char* msg, - const UNITY_LINE_TYPE lineNumber); - -void UnityAssertEqualFloatArray(UNITY_PTR_ATTRIBUTE const UNITY_FLOAT* expected, - UNITY_PTR_ATTRIBUTE const UNITY_FLOAT* actual, - const UNITY_UINT32 num_elements, - const char* msg, - const UNITY_LINE_TYPE lineNumber, - const UNITY_FLAGS_T flags); - -void UnityAssertFloatSpecial(const UNITY_FLOAT actual, - const char* msg, - const UNITY_LINE_TYPE lineNumber, - const UNITY_FLOAT_TRAIT_T style); -#endif - -#ifndef UNITY_EXCLUDE_DOUBLE -void UnityAssertDoublesWithin(const UNITY_DOUBLE delta, - const UNITY_DOUBLE expected, - const UNITY_DOUBLE actual, - const char* msg, - const UNITY_LINE_TYPE lineNumber); - -void UnityAssertEqualDoubleArray(UNITY_PTR_ATTRIBUTE const UNITY_DOUBLE* expected, - UNITY_PTR_ATTRIBUTE const UNITY_DOUBLE* actual, - const UNITY_UINT32 num_elements, - const char* msg, - const UNITY_LINE_TYPE lineNumber, - const UNITY_FLAGS_T flags); - -void UnityAssertDoubleSpecial(const UNITY_DOUBLE actual, - const char* msg, - const UNITY_LINE_TYPE lineNumber, - const UNITY_FLOAT_TRAIT_T style); -#endif - -/*------------------------------------------------------- - * Helpers - *-------------------------------------------------------*/ - -UNITY_INTERNAL_PTR UnityNumToPtr(const UNITY_INT num, const UNITY_UINT8 size); -#ifndef UNITY_EXCLUDE_FLOAT -UNITY_INTERNAL_PTR UnityFloatToPtr(const float num); -#endif -#ifndef UNITY_EXCLUDE_DOUBLE -UNITY_INTERNAL_PTR UnityDoubleToPtr(const double num); -#endif - -/*------------------------------------------------------- - * Error Strings We Might Need - *-------------------------------------------------------*/ - -extern const char UnityStrOk[]; -extern const char UnityStrPass[]; -extern const char UnityStrFail[]; -extern const char UnityStrIgnore[]; - -extern const char UnityStrErrFloat[]; -extern const char UnityStrErrDouble[]; -extern const char UnityStrErr64[]; -extern const char UnityStrErrShorthand[]; - -/*------------------------------------------------------- - * Test Running Macros - *-------------------------------------------------------*/ - -#ifndef UNITY_EXCLUDE_SETJMP_H -#define TEST_PROTECT() (setjmp(Unity.AbortFrame) == 0) -#define TEST_ABORT() longjmp(Unity.AbortFrame, 1) -#else -#define TEST_PROTECT() 1 -#define TEST_ABORT() return -#endif - -/* This tricky series of macros gives us an optional line argument to treat it as RUN_TEST(func, num=__LINE__) */ -#ifndef RUN_TEST -#ifdef __STDC_VERSION__ -#if __STDC_VERSION__ >= 199901L -#define RUN_TEST(...) UnityDefaultTestRun(RUN_TEST_FIRST(__VA_ARGS__), RUN_TEST_SECOND(__VA_ARGS__)) -#define RUN_TEST_FIRST(...) RUN_TEST_FIRST_HELPER(__VA_ARGS__, throwaway) -#define RUN_TEST_FIRST_HELPER(first, ...) (first), #first -#define RUN_TEST_SECOND(...) RUN_TEST_SECOND_HELPER(__VA_ARGS__, __LINE__, throwaway) -#define RUN_TEST_SECOND_HELPER(first, second, ...) (second) -#endif -#endif -#endif - -/* If we can't do the tricky version, we'll just have to require them to always include the line number */ -#ifndef RUN_TEST -#ifdef CMOCK -#define RUN_TEST(func, num) UnityDefaultTestRun(func, #func, num) -#else -#define RUN_TEST(func) UnityDefaultTestRun(func, #func, __LINE__) -#endif -#endif - -#define TEST_LINE_NUM (Unity.CurrentTestLineNumber) -#define TEST_IS_IGNORED (Unity.CurrentTestIgnored) -#define UNITY_NEW_TEST(a) \ - Unity.CurrentTestName = (a); \ - Unity.CurrentTestLineNumber = (UNITY_LINE_TYPE)(__LINE__); \ - Unity.NumberOfTests++; - -#ifndef UNITY_BEGIN -#define UNITY_BEGIN() UnityBegin(__FILE__) -#endif - -#ifndef UNITY_END -#define UNITY_END() UnityEnd() -#endif - -#ifndef UNITY_SHORTHAND_AS_INT -#ifndef UNITY_SHORTHAND_AS_MEM -#ifndef UNITY_SHORTHAND_AS_NONE -#ifndef UNITY_SHORTHAND_AS_RAW -#define UNITY_SHORTHAND_AS_OLD -#endif -#endif -#endif -#endif - -/*----------------------------------------------- - * Command Line Argument Support - *-----------------------------------------------*/ - -#ifdef UNITY_USE_COMMAND_LINE_ARGS -int UnityParseOptions(int argc, char** argv); -int UnityTestMatches(void); -#endif - -/*------------------------------------------------------- - * Basic Fail and Ignore - *-------------------------------------------------------*/ - -#define UNITY_TEST_FAIL(line, message) UnityFail( (message), (UNITY_LINE_TYPE)(line)) -#define UNITY_TEST_IGNORE(line, message) UnityIgnore( (message), (UNITY_LINE_TYPE)(line)) - -/*------------------------------------------------------- - * Test Asserts - *-------------------------------------------------------*/ - -#define UNITY_TEST_ASSERT(condition, line, message) if (condition) {} else {UNITY_TEST_FAIL((UNITY_LINE_TYPE)(line), (message));} -#define UNITY_TEST_ASSERT_NULL(pointer, line, message) UNITY_TEST_ASSERT(((pointer) == NULL), (UNITY_LINE_TYPE)(line), (message)) -#define UNITY_TEST_ASSERT_NOT_NULL(pointer, line, message) UNITY_TEST_ASSERT(((pointer) != NULL), (UNITY_LINE_TYPE)(line), (message)) - -#define UNITY_TEST_ASSERT_EQUAL_INT(expected, actual, line, message) UnityAssertEqualNumber((UNITY_INT)(expected), (UNITY_INT)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT) -#define UNITY_TEST_ASSERT_EQUAL_INT8(expected, actual, line, message) UnityAssertEqualNumber((UNITY_INT)(UNITY_INT8 )(expected), (UNITY_INT)(UNITY_INT8 )(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT8) -#define UNITY_TEST_ASSERT_EQUAL_INT16(expected, actual, line, message) UnityAssertEqualNumber((UNITY_INT)(UNITY_INT16)(expected), (UNITY_INT)(UNITY_INT16)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT16) -#define UNITY_TEST_ASSERT_EQUAL_INT32(expected, actual, line, message) UnityAssertEqualNumber((UNITY_INT)(UNITY_INT32)(expected), (UNITY_INT)(UNITY_INT32)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT32) -#define UNITY_TEST_ASSERT_EQUAL_UINT(expected, actual, line, message) UnityAssertEqualNumber((UNITY_INT)(expected), (UNITY_INT)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT) -#define UNITY_TEST_ASSERT_EQUAL_UINT8(expected, actual, line, message) UnityAssertEqualNumber((UNITY_INT)(UNITY_UINT8 )(expected), (UNITY_INT)(UNITY_UINT8 )(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT8) -#define UNITY_TEST_ASSERT_EQUAL_UINT16(expected, actual, line, message) UnityAssertEqualNumber((UNITY_INT)(UNITY_UINT16)(expected), (UNITY_INT)(UNITY_UINT16)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT16) -#define UNITY_TEST_ASSERT_EQUAL_UINT32(expected, actual, line, message) UnityAssertEqualNumber((UNITY_INT)(UNITY_UINT32)(expected), (UNITY_INT)(UNITY_UINT32)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT32) -#define UNITY_TEST_ASSERT_EQUAL_HEX8(expected, actual, line, message) UnityAssertEqualNumber((UNITY_INT)(UNITY_INT8 )(expected), (UNITY_INT)(UNITY_INT8 )(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_HEX8) -#define UNITY_TEST_ASSERT_EQUAL_HEX16(expected, actual, line, message) UnityAssertEqualNumber((UNITY_INT)(UNITY_INT16)(expected), (UNITY_INT)(UNITY_INT16)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_HEX16) -#define UNITY_TEST_ASSERT_EQUAL_HEX32(expected, actual, line, message) UnityAssertEqualNumber((UNITY_INT)(UNITY_INT32)(expected), (UNITY_INT)(UNITY_INT32)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_HEX32) -#define UNITY_TEST_ASSERT_BITS(mask, expected, actual, line, message) UnityAssertBits((UNITY_INT)(mask), (UNITY_INT)(expected), (UNITY_INT)(actual), (message), (UNITY_LINE_TYPE)(line)) - -#define UNITY_TEST_ASSERT_GREATER_THAN_INT(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(threshold), (UNITY_INT)(actual), UNITY_GREATER_THAN, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT) -#define UNITY_TEST_ASSERT_GREATER_THAN_INT8(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(UNITY_INT8 )(threshold), (UNITY_INT)(UNITY_INT8 )(actual), UNITY_GREATER_THAN, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT8) -#define UNITY_TEST_ASSERT_GREATER_THAN_INT16(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(UNITY_INT16)(threshold), (UNITY_INT)(UNITY_INT16)(actual), UNITY_GREATER_THAN, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT16) -#define UNITY_TEST_ASSERT_GREATER_THAN_INT32(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(UNITY_INT32)(threshold), (UNITY_INT)(UNITY_INT32)(actual), UNITY_GREATER_THAN, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT32) -#define UNITY_TEST_ASSERT_GREATER_THAN_UINT(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(threshold), (UNITY_INT)(actual), UNITY_GREATER_THAN, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT) -#define UNITY_TEST_ASSERT_GREATER_THAN_UINT8(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(UNITY_UINT8 )(threshold), (UNITY_INT)(UNITY_UINT8 )(actual), UNITY_GREATER_THAN, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT8) -#define UNITY_TEST_ASSERT_GREATER_THAN_UINT16(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(UNITY_UINT16)(threshold), (UNITY_INT)(UNITY_UINT16)(actual), UNITY_GREATER_THAN, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT16) -#define UNITY_TEST_ASSERT_GREATER_THAN_UINT32(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(UNITY_UINT32)(threshold), (UNITY_INT)(UNITY_UINT32)(actual), UNITY_GREATER_THAN, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT32) -#define UNITY_TEST_ASSERT_GREATER_THAN_HEX8(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(UNITY_UINT8 )(threshold), (UNITY_INT)(UNITY_UINT8 )(actual), UNITY_GREATER_THAN, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_HEX8) -#define UNITY_TEST_ASSERT_GREATER_THAN_HEX16(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(UNITY_UINT16)(threshold), (UNITY_INT)(UNITY_UINT16)(actual), UNITY_GREATER_THAN, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_HEX16) -#define UNITY_TEST_ASSERT_GREATER_THAN_HEX32(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(UNITY_UINT32)(threshold), (UNITY_INT)(UNITY_UINT32)(actual), UNITY_GREATER_THAN, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_HEX32) - -#define UNITY_TEST_ASSERT_SMALLER_THAN_INT(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(threshold), (UNITY_INT)(actual), UNITY_SMALLER_THAN, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT) -#define UNITY_TEST_ASSERT_SMALLER_THAN_INT8(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(UNITY_INT8 )(threshold), (UNITY_INT)(UNITY_INT8 )(actual), UNITY_SMALLER_THAN, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT8) -#define UNITY_TEST_ASSERT_SMALLER_THAN_INT16(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(UNITY_INT16)(threshold), (UNITY_INT)(UNITY_INT16)(actual), UNITY_SMALLER_THAN, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT16) -#define UNITY_TEST_ASSERT_SMALLER_THAN_INT32(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(UNITY_INT32)(threshold), (UNITY_INT)(UNITY_INT32)(actual), UNITY_SMALLER_THAN, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT32) -#define UNITY_TEST_ASSERT_SMALLER_THAN_UINT(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(threshold), (UNITY_INT)(actual), UNITY_SMALLER_THAN, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT) -#define UNITY_TEST_ASSERT_SMALLER_THAN_UINT8(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(UNITY_UINT8 )(threshold), (UNITY_INT)(UNITY_UINT8 )(actual), UNITY_SMALLER_THAN, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT8) -#define UNITY_TEST_ASSERT_SMALLER_THAN_UINT16(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(UNITY_UINT16)(threshold), (UNITY_INT)(UNITY_UINT16)(actual), UNITY_SMALLER_THAN, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT16) -#define UNITY_TEST_ASSERT_SMALLER_THAN_UINT32(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(UNITY_UINT32)(threshold), (UNITY_INT)(UNITY_UINT32)(actual), UNITY_SMALLER_THAN, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT32) -#define UNITY_TEST_ASSERT_SMALLER_THAN_HEX8(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(UNITY_UINT8 )(threshold), (UNITY_INT)(UNITY_UINT8 )(actual), UNITY_SMALLER_THAN, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_HEX8) -#define UNITY_TEST_ASSERT_SMALLER_THAN_HEX16(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(UNITY_UINT16)(threshold), (UNITY_INT)(UNITY_UINT16)(actual), UNITY_SMALLER_THAN, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_HEX16) -#define UNITY_TEST_ASSERT_SMALLER_THAN_HEX32(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(UNITY_UINT32)(threshold), (UNITY_INT)(UNITY_UINT32)(actual), UNITY_SMALLER_THAN, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_HEX32) - -#define UNITY_TEST_ASSERT_GREATER_OR_EQUAL_INT(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT) (threshold), (UNITY_INT) (actual), UNITY_GREATER_OR_EQUAL, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT) -#define UNITY_TEST_ASSERT_GREATER_OR_EQUAL_INT8(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(UNITY_INT8 ) (threshold), (UNITY_INT)(UNITY_INT8 ) (actual), UNITY_GREATER_OR_EQUAL, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT8) -#define UNITY_TEST_ASSERT_GREATER_OR_EQUAL_INT16(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(UNITY_INT16) (threshold), (UNITY_INT)(UNITY_INT16) (actual), UNITY_GREATER_OR_EQUAL, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT16) -#define UNITY_TEST_ASSERT_GREATER_OR_EQUAL_INT32(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(UNITY_INT32) (threshold), (UNITY_INT)(UNITY_INT32) (actual), UNITY_GREATER_OR_EQUAL, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT32) -#define UNITY_TEST_ASSERT_GREATER_OR_EQUAL_UINT(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT) (threshold), (UNITY_INT) (actual), UNITY_GREATER_OR_EQUAL, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT) -#define UNITY_TEST_ASSERT_GREATER_OR_EQUAL_UINT8(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(UNITY_UINT8 )(threshold), (UNITY_INT)(UNITY_UINT8 )(actual), UNITY_GREATER_OR_EQUAL, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT8) -#define UNITY_TEST_ASSERT_GREATER_OR_EQUAL_UINT16(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(UNITY_UINT16)(threshold), (UNITY_INT)(UNITY_UINT16)(actual), UNITY_GREATER_OR_EQUAL, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT16) -#define UNITY_TEST_ASSERT_GREATER_OR_EQUAL_UINT32(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(UNITY_UINT32)(threshold), (UNITY_INT)(UNITY_UINT32)(actual), UNITY_GREATER_OR_EQUAL, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT32) -#define UNITY_TEST_ASSERT_GREATER_OR_EQUAL_HEX8(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(UNITY_UINT8 )(threshold), (UNITY_INT)(UNITY_UINT8 )(actual), UNITY_GREATER_OR_EQUAL, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_HEX8) -#define UNITY_TEST_ASSERT_GREATER_OR_EQUAL_HEX16(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(UNITY_UINT16)(threshold), (UNITY_INT)(UNITY_UINT16)(actual), UNITY_GREATER_OR_EQUAL, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_HEX16) -#define UNITY_TEST_ASSERT_GREATER_OR_EQUAL_HEX32(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(UNITY_UINT32)(threshold), (UNITY_INT)(UNITY_UINT32)(actual), UNITY_GREATER_OR_EQUAL, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_HEX32) - -#define UNITY_TEST_ASSERT_SMALLER_OR_EQUAL_INT(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT) (threshold), (UNITY_INT) (actual), UNITY_SMALLER_OR_EQUAL, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT) -#define UNITY_TEST_ASSERT_SMALLER_OR_EQUAL_INT8(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(UNITY_INT8 )(threshold), (UNITY_INT)(UNITY_INT8 ) (actual), UNITY_SMALLER_OR_EQUAL, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT8) -#define UNITY_TEST_ASSERT_SMALLER_OR_EQUAL_INT16(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(UNITY_INT16)(threshold), (UNITY_INT)(UNITY_INT16) (actual), UNITY_SMALLER_OR_EQUAL, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT16) -#define UNITY_TEST_ASSERT_SMALLER_OR_EQUAL_INT32(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(UNITY_INT32)(threshold), (UNITY_INT)(UNITY_INT32) (actual), UNITY_SMALLER_OR_EQUAL, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT32) -#define UNITY_TEST_ASSERT_SMALLER_OR_EQUAL_UINT(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT) (threshold), (UNITY_INT) (actual), UNITY_SMALLER_OR_EQUAL, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT) -#define UNITY_TEST_ASSERT_SMALLER_OR_EQUAL_UINT8(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(UNITY_UINT8 )(threshold), (UNITY_INT)(UNITY_UINT8 )(actual), UNITY_SMALLER_OR_EQUAL, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT8) -#define UNITY_TEST_ASSERT_SMALLER_OR_EQUAL_UINT16(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(UNITY_UINT16)(threshold), (UNITY_INT)(UNITY_UINT16)(actual), UNITY_SMALLER_OR_EQUAL, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT16) -#define UNITY_TEST_ASSERT_SMALLER_OR_EQUAL_UINT32(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(UNITY_UINT32)(threshold), (UNITY_INT)(UNITY_UINT32)(actual), UNITY_SMALLER_OR_EQUAL, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT32) -#define UNITY_TEST_ASSERT_SMALLER_OR_EQUAL_HEX8(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(UNITY_UINT8 )(threshold), (UNITY_INT)(UNITY_UINT8 )(actual), UNITY_SMALLER_OR_EQUAL, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_HEX8) -#define UNITY_TEST_ASSERT_SMALLER_OR_EQUAL_HEX16(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(UNITY_UINT16)(threshold), (UNITY_INT)(UNITY_UINT16)(actual), UNITY_SMALLER_OR_EQUAL, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_HEX16) -#define UNITY_TEST_ASSERT_SMALLER_OR_EQUAL_HEX32(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(UNITY_UINT32)(threshold), (UNITY_INT)(UNITY_UINT32)(actual), UNITY_SMALLER_OR_EQUAL, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_HEX32) - -#define UNITY_TEST_ASSERT_INT_WITHIN(delta, expected, actual, line, message) UnityAssertNumbersWithin( (delta), (UNITY_INT) (expected), (UNITY_INT) (actual), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT) -#define UNITY_TEST_ASSERT_INT8_WITHIN(delta, expected, actual, line, message) UnityAssertNumbersWithin((UNITY_UINT8 )(delta), (UNITY_INT)(UNITY_INT8 ) (expected), (UNITY_INT)(UNITY_INT8 ) (actual), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT8) -#define UNITY_TEST_ASSERT_INT16_WITHIN(delta, expected, actual, line, message) UnityAssertNumbersWithin((UNITY_UINT16)(delta), (UNITY_INT)(UNITY_INT16) (expected), (UNITY_INT)(UNITY_INT16) (actual), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT16) -#define UNITY_TEST_ASSERT_INT32_WITHIN(delta, expected, actual, line, message) UnityAssertNumbersWithin((UNITY_UINT32)(delta), (UNITY_INT)(UNITY_INT32) (expected), (UNITY_INT)(UNITY_INT32) (actual), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT32) -#define UNITY_TEST_ASSERT_UINT_WITHIN(delta, expected, actual, line, message) UnityAssertNumbersWithin( (delta), (UNITY_INT) (expected), (UNITY_INT) (actual), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT) -#define UNITY_TEST_ASSERT_UINT8_WITHIN(delta, expected, actual, line, message) UnityAssertNumbersWithin((UNITY_UINT8 )(delta), (UNITY_INT)(UNITY_UINT)(UNITY_UINT8 )(expected), (UNITY_INT)(UNITY_UINT)(UNITY_UINT8 )(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT8) -#define UNITY_TEST_ASSERT_UINT16_WITHIN(delta, expected, actual, line, message) UnityAssertNumbersWithin((UNITY_UINT16)(delta), (UNITY_INT)(UNITY_UINT)(UNITY_UINT16)(expected), (UNITY_INT)(UNITY_UINT)(UNITY_UINT16)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT16) -#define UNITY_TEST_ASSERT_UINT32_WITHIN(delta, expected, actual, line, message) UnityAssertNumbersWithin((UNITY_UINT32)(delta), (UNITY_INT)(UNITY_UINT)(UNITY_UINT32)(expected), (UNITY_INT)(UNITY_UINT)(UNITY_UINT32)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT32) -#define UNITY_TEST_ASSERT_HEX8_WITHIN(delta, expected, actual, line, message) UnityAssertNumbersWithin((UNITY_UINT8 )(delta), (UNITY_INT)(UNITY_UINT)(UNITY_UINT8 )(expected), (UNITY_INT)(UNITY_UINT)(UNITY_UINT8 )(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_HEX8) -#define UNITY_TEST_ASSERT_HEX16_WITHIN(delta, expected, actual, line, message) UnityAssertNumbersWithin((UNITY_UINT16)(delta), (UNITY_INT)(UNITY_UINT)(UNITY_UINT16)(expected), (UNITY_INT)(UNITY_UINT)(UNITY_UINT16)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_HEX16) -#define UNITY_TEST_ASSERT_HEX32_WITHIN(delta, expected, actual, line, message) UnityAssertNumbersWithin((UNITY_UINT32)(delta), (UNITY_INT)(UNITY_UINT)(UNITY_UINT32)(expected), (UNITY_INT)(UNITY_UINT)(UNITY_UINT32)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_HEX32) - - -#define UNITY_TEST_ASSERT_INT_ARRAY_WITHIN(delta, expected, actual, num_elements, line, message) UnityAssertNumbersArrayWithin( (delta), (UNITY_INTERNAL_PTR)(expected), (UNITY_INTERNAL_PTR)(actual), ((UNITY_UINT32)(num_elements)), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT, UNITY_ARRAY_TO_ARRAY) -#define UNITY_TEST_ASSERT_INT8_ARRAY_WITHIN(delta, expected, actual, num_elements, line, message) UnityAssertNumbersArrayWithin((UNITY_UINT8 )(delta), (UNITY_INTERNAL_PTR)(expected), (UNITY_INTERNAL_PTR)(actual), ((UNITY_UINT32)(num_elements)), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT8, UNITY_ARRAY_TO_ARRAY) -#define UNITY_TEST_ASSERT_INT16_ARRAY_WITHIN(delta, expected, actual, num_elements, line, message) UnityAssertNumbersArrayWithin((UNITY_UINT16)(delta), (UNITY_INTERNAL_PTR)(expected), (UNITY_INTERNAL_PTR)(actual), ((UNITY_UINT32)(num_elements)), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT16, UNITY_ARRAY_TO_ARRAY) -#define UNITY_TEST_ASSERT_INT32_ARRAY_WITHIN(delta, expected, actual, num_elements, line, message) UnityAssertNumbersArrayWithin((UNITY_UINT32)(delta), (UNITY_INTERNAL_PTR)(expected), (UNITY_INTERNAL_PTR)(actual), ((UNITY_UINT32)(num_elements)), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT32, UNITY_ARRAY_TO_ARRAY) -#define UNITY_TEST_ASSERT_UINT_ARRAY_WITHIN(delta, expected, actual, num_elements, line, message) UnityAssertNumbersArrayWithin( (delta), (UNITY_INTERNAL_PTR)(expected), (UNITY_INTERNAL_PTR)(actual), ((UNITY_UINT32)(num_elements)), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT, UNITY_ARRAY_TO_ARRAY) -#define UNITY_TEST_ASSERT_UINT8_ARRAY_WITHIN(delta, expected, actual, num_elements, line, message) UnityAssertNumbersArrayWithin( (UNITY_UINT16)(delta), (UNITY_INTERNAL_PTR)(expected), (UNITY_INTERNAL_PTR)(actual), ((UNITY_UINT32)(num_elements)), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT8, UNITY_ARRAY_TO_ARRAY) -#define UNITY_TEST_ASSERT_UINT16_ARRAY_WITHIN(delta, expected, actual, num_elements, line, message) UnityAssertNumbersArrayWithin((UNITY_UINT16)(delta), (UNITY_INTERNAL_PTR)(expected), (UNITY_INTERNAL_PTR)(actual), ((UNITY_UINT32)(num_elements)), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT16, UNITY_ARRAY_TO_ARRAY) -#define UNITY_TEST_ASSERT_UINT32_ARRAY_WITHIN(delta, expected, actual, num_elements, line, message) UnityAssertNumbersArrayWithin((UNITY_UINT32)(delta), (UNITY_INTERNAL_PTR)(expected), (UNITY_INTERNAL_PTR)(actual), ((UNITY_UINT32)(num_elements)), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT32, UNITY_ARRAY_TO_ARRAY) -#define UNITY_TEST_ASSERT_HEX8_ARRAY_WITHIN(delta, expected, actual, num_elements, line, message) UnityAssertNumbersArrayWithin((UNITY_UINT8 )(delta), (UNITY_INTERNAL_PTR)(expected), (UNITY_INTERNAL_PTR)(actual), ((UNITY_UINT32)(num_elements)), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_HEX8, UNITY_ARRAY_TO_ARRAY) -#define UNITY_TEST_ASSERT_HEX16_ARRAY_WITHIN(delta, expected, actual, num_elements, line, message) UnityAssertNumbersArrayWithin((UNITY_UINT16)(delta), (UNITY_INTERNAL_PTR)(expected), (UNITY_INTERNAL_PTR)(actual), ((UNITY_UINT32)(num_elements)), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_HEX16, UNITY_ARRAY_TO_ARRAY) -#define UNITY_TEST_ASSERT_HEX32_ARRAY_WITHIN(delta, expected, actual, num_elements, line, message) UnityAssertNumbersArrayWithin((UNITY_UINT32)(delta), (UNITY_INTERNAL_PTR)(expected), (UNITY_INTERNAL_PTR)(actual), ((UNITY_UINT32)(num_elements)), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_HEX32, UNITY_ARRAY_TO_ARRAY) - - -#define UNITY_TEST_ASSERT_EQUAL_PTR(expected, actual, line, message) UnityAssertEqualNumber((UNITY_PTR_TO_INT)(expected), (UNITY_PTR_TO_INT)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_POINTER) -#define UNITY_TEST_ASSERT_EQUAL_STRING(expected, actual, line, message) UnityAssertEqualString((const char*)(expected), (const char*)(actual), (message), (UNITY_LINE_TYPE)(line)) -#define UNITY_TEST_ASSERT_EQUAL_STRING_LEN(expected, actual, len, line, message) UnityAssertEqualStringLen((const char*)(expected), (const char*)(actual), (UNITY_UINT32)(len), (message), (UNITY_LINE_TYPE)(line)) -#define UNITY_TEST_ASSERT_EQUAL_MEMORY(expected, actual, len, line, message) UnityAssertEqualMemory((UNITY_INTERNAL_PTR)(expected), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(len), 1, (message), (UNITY_LINE_TYPE)(line), UNITY_ARRAY_TO_ARRAY) - -#define UNITY_TEST_ASSERT_EQUAL_INT_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((UNITY_INTERNAL_PTR)(expected), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT, UNITY_ARRAY_TO_ARRAY) -#define UNITY_TEST_ASSERT_EQUAL_INT8_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((UNITY_INTERNAL_PTR)(expected), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT8, UNITY_ARRAY_TO_ARRAY) -#define UNITY_TEST_ASSERT_EQUAL_INT16_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((UNITY_INTERNAL_PTR)(expected), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT16, UNITY_ARRAY_TO_ARRAY) -#define UNITY_TEST_ASSERT_EQUAL_INT32_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((UNITY_INTERNAL_PTR)(expected), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT32, UNITY_ARRAY_TO_ARRAY) -#define UNITY_TEST_ASSERT_EQUAL_UINT_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((UNITY_INTERNAL_PTR)(expected), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT, UNITY_ARRAY_TO_ARRAY) -#define UNITY_TEST_ASSERT_EQUAL_UINT8_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((UNITY_INTERNAL_PTR)(expected), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT8, UNITY_ARRAY_TO_ARRAY) -#define UNITY_TEST_ASSERT_EQUAL_UINT16_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((UNITY_INTERNAL_PTR)(expected), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT16, UNITY_ARRAY_TO_ARRAY) -#define UNITY_TEST_ASSERT_EQUAL_UINT32_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((UNITY_INTERNAL_PTR)(expected), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT32, UNITY_ARRAY_TO_ARRAY) -#define UNITY_TEST_ASSERT_EQUAL_HEX8_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((UNITY_INTERNAL_PTR)(expected), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_HEX8, UNITY_ARRAY_TO_ARRAY) -#define UNITY_TEST_ASSERT_EQUAL_HEX16_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((UNITY_INTERNAL_PTR)(expected), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_HEX16, UNITY_ARRAY_TO_ARRAY) -#define UNITY_TEST_ASSERT_EQUAL_HEX32_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((UNITY_INTERNAL_PTR)(expected), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_HEX32, UNITY_ARRAY_TO_ARRAY) -#define UNITY_TEST_ASSERT_EQUAL_PTR_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((UNITY_INTERNAL_PTR)(expected), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_POINTER, UNITY_ARRAY_TO_ARRAY) -#define UNITY_TEST_ASSERT_EQUAL_STRING_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualStringArray((UNITY_INTERNAL_PTR)(expected), (const char**)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_ARRAY_TO_ARRAY) -#define UNITY_TEST_ASSERT_EQUAL_MEMORY_ARRAY(expected, actual, len, num_elements, line, message) UnityAssertEqualMemory((UNITY_INTERNAL_PTR)(expected), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(len), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_ARRAY_TO_ARRAY) - -#define UNITY_TEST_ASSERT_EACH_EQUAL_INT(expected, actual, num_elements, line, message) UnityAssertEqualIntArray(UnityNumToPtr((UNITY_INT) (expected), (UNITY_INT_WIDTH / 8)), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT, UNITY_ARRAY_TO_VAL) -#define UNITY_TEST_ASSERT_EACH_EQUAL_INT8(expected, actual, num_elements, line, message) UnityAssertEqualIntArray(UnityNumToPtr((UNITY_INT)(UNITY_INT8 )(expected), 1), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT8, UNITY_ARRAY_TO_VAL) -#define UNITY_TEST_ASSERT_EACH_EQUAL_INT16(expected, actual, num_elements, line, message) UnityAssertEqualIntArray(UnityNumToPtr((UNITY_INT)(UNITY_INT16 )(expected), 2), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT16, UNITY_ARRAY_TO_VAL) -#define UNITY_TEST_ASSERT_EACH_EQUAL_INT32(expected, actual, num_elements, line, message) UnityAssertEqualIntArray(UnityNumToPtr((UNITY_INT)(UNITY_INT32 )(expected), 4), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT32, UNITY_ARRAY_TO_VAL) -#define UNITY_TEST_ASSERT_EACH_EQUAL_UINT(expected, actual, num_elements, line, message) UnityAssertEqualIntArray(UnityNumToPtr((UNITY_INT) (expected), (UNITY_INT_WIDTH / 8)), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT, UNITY_ARRAY_TO_VAL) -#define UNITY_TEST_ASSERT_EACH_EQUAL_UINT8(expected, actual, num_elements, line, message) UnityAssertEqualIntArray(UnityNumToPtr((UNITY_INT)(UNITY_UINT8 )(expected), 1), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT8, UNITY_ARRAY_TO_VAL) -#define UNITY_TEST_ASSERT_EACH_EQUAL_UINT16(expected, actual, num_elements, line, message) UnityAssertEqualIntArray(UnityNumToPtr((UNITY_INT)(UNITY_UINT16)(expected), 2), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT16, UNITY_ARRAY_TO_VAL) -#define UNITY_TEST_ASSERT_EACH_EQUAL_UINT32(expected, actual, num_elements, line, message) UnityAssertEqualIntArray(UnityNumToPtr((UNITY_INT)(UNITY_UINT32)(expected), 4), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT32, UNITY_ARRAY_TO_VAL) -#define UNITY_TEST_ASSERT_EACH_EQUAL_HEX8(expected, actual, num_elements, line, message) UnityAssertEqualIntArray(UnityNumToPtr((UNITY_INT)(UNITY_INT8 )(expected), 1), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_HEX8, UNITY_ARRAY_TO_VAL) -#define UNITY_TEST_ASSERT_EACH_EQUAL_HEX16(expected, actual, num_elements, line, message) UnityAssertEqualIntArray(UnityNumToPtr((UNITY_INT)(UNITY_INT16 )(expected), 2), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_HEX16, UNITY_ARRAY_TO_VAL) -#define UNITY_TEST_ASSERT_EACH_EQUAL_HEX32(expected, actual, num_elements, line, message) UnityAssertEqualIntArray(UnityNumToPtr((UNITY_INT)(UNITY_INT32 )(expected), 4), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_HEX32, UNITY_ARRAY_TO_VAL) -#define UNITY_TEST_ASSERT_EACH_EQUAL_PTR(expected, actual, num_elements, line, message) UnityAssertEqualIntArray(UnityNumToPtr((UNITY_PTR_TO_INT) (expected), (UNITY_POINTER_WIDTH / 8)), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_POINTER, UNITY_ARRAY_TO_VAL) -#define UNITY_TEST_ASSERT_EACH_EQUAL_STRING(expected, actual, num_elements, line, message) UnityAssertEqualStringArray((UNITY_INTERNAL_PTR)(expected), (const char**)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_ARRAY_TO_VAL) -#define UNITY_TEST_ASSERT_EACH_EQUAL_MEMORY(expected, actual, len, num_elements, line, message) UnityAssertEqualMemory((UNITY_INTERNAL_PTR)(expected), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(len), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_ARRAY_TO_VAL) - -#ifdef UNITY_SUPPORT_64 -#define UNITY_TEST_ASSERT_EQUAL_INT64(expected, actual, line, message) UnityAssertEqualNumber((UNITY_INT)(expected), (UNITY_INT)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT64) -#define UNITY_TEST_ASSERT_EQUAL_UINT64(expected, actual, line, message) UnityAssertEqualNumber((UNITY_INT)(expected), (UNITY_INT)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT64) -#define UNITY_TEST_ASSERT_EQUAL_HEX64(expected, actual, line, message) UnityAssertEqualNumber((UNITY_INT)(expected), (UNITY_INT)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_HEX64) -#define UNITY_TEST_ASSERT_EQUAL_INT64_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((UNITY_INTERNAL_PTR)(expected), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT64, UNITY_ARRAY_TO_ARRAY) -#define UNITY_TEST_ASSERT_EQUAL_UINT64_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((UNITY_INTERNAL_PTR)(expected), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT64, UNITY_ARRAY_TO_ARRAY) -#define UNITY_TEST_ASSERT_EQUAL_HEX64_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualIntArray((UNITY_INTERNAL_PTR)(expected), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_HEX64, UNITY_ARRAY_TO_ARRAY) -#define UNITY_TEST_ASSERT_EACH_EQUAL_INT64(expected, actual, num_elements, line, message) UnityAssertEqualIntArray(UnityNumToPtr((UNITY_INT)(UNITY_INT64)(expected), 8), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT64, UNITY_ARRAY_TO_VAL) -#define UNITY_TEST_ASSERT_EACH_EQUAL_UINT64(expected, actual, num_elements, line, message) UnityAssertEqualIntArray(UnityNumToPtr((UNITY_INT)(UNITY_UINT64)(expected), 8), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT64, UNITY_ARRAY_TO_VAL) -#define UNITY_TEST_ASSERT_EACH_EQUAL_HEX64(expected, actual, num_elements, line, message) UnityAssertEqualIntArray(UnityNumToPtr((UNITY_INT)(UNITY_INT64)(expected), 8), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_HEX64, UNITY_ARRAY_TO_VAL) -#define UNITY_TEST_ASSERT_INT64_WITHIN(delta, expected, actual, line, message) UnityAssertNumbersWithin((delta), (UNITY_INT)(expected), (UNITY_INT)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT64) -#define UNITY_TEST_ASSERT_UINT64_WITHIN(delta, expected, actual, line, message) UnityAssertNumbersWithin((delta), (UNITY_INT)(expected), (UNITY_INT)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT64) -#define UNITY_TEST_ASSERT_HEX64_WITHIN(delta, expected, actual, line, message) UnityAssertNumbersWithin((delta), (UNITY_INT)(expected), (UNITY_INT)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_HEX64) -#define UNITY_TEST_ASSERT_GREATER_THAN_INT64(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(threshold), (UNITY_INT)(actual), UNITY_GREATER_THAN, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT64) -#define UNITY_TEST_ASSERT_GREATER_THAN_UINT64(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(threshold), (UNITY_INT)(actual), UNITY_GREATER_THAN, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT64) -#define UNITY_TEST_ASSERT_GREATER_THAN_HEX64(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(threshold), (UNITY_INT)(actual), UNITY_GREATER_THAN, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_HEX64) -#define UNITY_TEST_ASSERT_GREATER_OR_EQUAL_INT64(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(threshold), (UNITY_INT)(actual), UNITY_GREATER_OR_EQUAL, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT64) -#define UNITY_TEST_ASSERT_GREATER_OR_EQUAL_UINT64(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(threshold), (UNITY_INT)(actual), UNITY_GREATER_OR_EQUAL, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT64) -#define UNITY_TEST_ASSERT_GREATER_OR_EQUAL_HEX64(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(threshold), (UNITY_INT)(actual), UNITY_GREATER_OR_EQUAL, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_HEX64) -#define UNITY_TEST_ASSERT_SMALLER_THAN_INT64(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(threshold), (UNITY_INT)(actual), UNITY_SMALLER_THAN, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT64) -#define UNITY_TEST_ASSERT_SMALLER_THAN_UINT64(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(threshold), (UNITY_INT)(actual), UNITY_SMALLER_THAN, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT64) -#define UNITY_TEST_ASSERT_SMALLER_THAN_HEX64(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(threshold), (UNITY_INT)(actual), UNITY_SMALLER_THAN, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_HEX64) -#define UNITY_TEST_ASSERT_SMALLER_OR_EQUAL_INT64(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(threshold), (UNITY_INT)(actual), UNITY_SMALLER_OR_EQUAL, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT64) -#define UNITY_TEST_ASSERT_SMALLER_OR_EQUAL_UINT64(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(threshold), (UNITY_INT)(actual), UNITY_SMALLER_OR_EQUAL, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT64) -#define UNITY_TEST_ASSERT_SMALLER_OR_EQUAL_HEX64(threshold, actual, line, message) UnityAssertGreaterOrLessOrEqualNumber((UNITY_INT)(threshold), (UNITY_INT)(actual), UNITY_SMALLER_OR_EQUAL, (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_HEX64) -#define UNITY_TEST_ASSERT_INT64_ARRAY_WITHIN(delta, expected, actual, num_elements, line, message) UnityAssertNumbersArrayWithin((UNITY_UINT32)(delta), (UNITY_INTERNAL_PTR)(expected), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_INT32, UNITY_ARRAY_TO_ARRAY) -#define UNITY_TEST_ASSERT_UINT64_ARRAY_WITHIN(delta, expected, actual, num_elements, line, message) UnityAssertNumbersArrayWithin((UNITY_UINT32)(delta), (UNITY_INTERNAL_PTR)(expected), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_UINT32, UNITY_ARRAY_TO_ARRAY) -#define UNITY_TEST_ASSERT_HEX64_ARRAY_WITHIN(delta, expected, actual, num_elements, line, message) UnityAssertNumbersArrayWithin((UNITY_UINT32)(delta), (UNITY_INTERNAL_PTR)(expected), (UNITY_INTERNAL_PTR)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_DISPLAY_STYLE_HEX64, UNITY_ARRAY_TO_ARRAY) -#else -#define UNITY_TEST_ASSERT_EQUAL_INT64(expected, actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)(line), UnityStrErr64) -#define UNITY_TEST_ASSERT_EQUAL_UINT64(expected, actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)(line), UnityStrErr64) -#define UNITY_TEST_ASSERT_EQUAL_HEX64(expected, actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)(line), UnityStrErr64) -#define UNITY_TEST_ASSERT_EQUAL_INT64_ARRAY(expected, actual, num_elements, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)(line), UnityStrErr64) -#define UNITY_TEST_ASSERT_EQUAL_UINT64_ARRAY(expected, actual, num_elements, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)(line), UnityStrErr64) -#define UNITY_TEST_ASSERT_EQUAL_HEX64_ARRAY(expected, actual, num_elements, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)(line), UnityStrErr64) -#define UNITY_TEST_ASSERT_INT64_WITHIN(delta, expected, actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)(line), UnityStrErr64) -#define UNITY_TEST_ASSERT_UINT64_WITHIN(delta, expected, actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)(line), UnityStrErr64) -#define UNITY_TEST_ASSERT_HEX64_WITHIN(delta, expected, actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)(line), UnityStrErr64) -#define UNITY_TEST_ASSERT_GREATER_THAN_INT64(threshold, actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)(line), UnityStrErr64) -#define UNITY_TEST_ASSERT_GREATER_THAN_UINT64(threshold, actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)(line), UnityStrErr64) -#define UNITY_TEST_ASSERT_GREATER_THAN_HEX64(threshold, actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)(line), UnityStrErr64) -#define UNITY_TEST_ASSERT_GREATER_OR_EQUAL_INT64(threshold, actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)(line), UnityStrErr64) -#define UNITY_TEST_ASSERT_GREATER_OR_EQUAL_UINT64(threshold, actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)(line), UnityStrErr64) -#define UNITY_TEST_ASSERT_GREATER_OR_EQUAL_HEX64(threshold, actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)(line), UnityStrErr64) -#define UNITY_TEST_ASSERT_SMALLER_THAN_INT64(threshold, actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)(line), UnityStrErr64) -#define UNITY_TEST_ASSERT_SMALLER_THAN_UINT64(threshold, actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)(line), UnityStrErr64) -#define UNITY_TEST_ASSERT_SMALLER_THAN_HEX64(threshold, actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)(line), UnityStrErr64) -#define UNITY_TEST_ASSERT_SMALLER_OR_EQUAL_INT64(threshold, actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)(line), UnityStrErr64) -#define UNITY_TEST_ASSERT_SMALLER_OR_EQUAL_UINT64(threshold, actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)(line), UnityStrErr64) -#define UNITY_TEST_ASSERT_SMALLER_OR_EQUAL_HEX64(threshold, actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)(line), UnityStrErr64) -#define UNITY_TEST_ASSERT_INT64_ARRAY_WITHIN(delta, expected, actual, num_elements, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)(line), UnityStrErr64) -#define UNITY_TEST_ASSERT_UINT64_ARRAY_WITHIN(delta, expected, actual, num_elements, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)(line), UnityStrErr64) -#define UNITY_TEST_ASSERT_HEX64_ARRAY_WITHIN(delta, expected, actual, num_elements, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)(line), UnityStrErr64) -#endif - -#ifdef UNITY_EXCLUDE_FLOAT -#define UNITY_TEST_ASSERT_FLOAT_WITHIN(delta, expected, actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)(line), UnityStrErrFloat) -#define UNITY_TEST_ASSERT_EQUAL_FLOAT(expected, actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)(line), UnityStrErrFloat) -#define UNITY_TEST_ASSERT_EQUAL_FLOAT_ARRAY(expected, actual, num_elements, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)(line), UnityStrErrFloat) -#define UNITY_TEST_ASSERT_EACH_EQUAL_FLOAT(expected, actual, num_elements, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)(line), UnityStrErrFloat) -#define UNITY_TEST_ASSERT_FLOAT_IS_INF(actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)(line), UnityStrErrFloat) -#define UNITY_TEST_ASSERT_FLOAT_IS_NEG_INF(actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)(line), UnityStrErrFloat) -#define UNITY_TEST_ASSERT_FLOAT_IS_NAN(actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)(line), UnityStrErrFloat) -#define UNITY_TEST_ASSERT_FLOAT_IS_DETERMINATE(actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)(line), UnityStrErrFloat) -#define UNITY_TEST_ASSERT_FLOAT_IS_NOT_INF(actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)(line), UnityStrErrFloat) -#define UNITY_TEST_ASSERT_FLOAT_IS_NOT_NEG_INF(actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)(line), UnityStrErrFloat) -#define UNITY_TEST_ASSERT_FLOAT_IS_NOT_NAN(actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)(line), UnityStrErrFloat) -#define UNITY_TEST_ASSERT_FLOAT_IS_NOT_DETERMINATE(actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)(line), UnityStrErrFloat) -#else -#define UNITY_TEST_ASSERT_FLOAT_WITHIN(delta, expected, actual, line, message) UnityAssertFloatsWithin((UNITY_FLOAT)(delta), (UNITY_FLOAT)(expected), (UNITY_FLOAT)(actual), (message), (UNITY_LINE_TYPE)(line)) -#define UNITY_TEST_ASSERT_EQUAL_FLOAT(expected, actual, line, message) UNITY_TEST_ASSERT_FLOAT_WITHIN((UNITY_FLOAT)(expected) * (UNITY_FLOAT)UNITY_FLOAT_PRECISION, (UNITY_FLOAT)(expected), (UNITY_FLOAT)(actual), (UNITY_LINE_TYPE)(line), (message)) -#define UNITY_TEST_ASSERT_EQUAL_FLOAT_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualFloatArray((UNITY_FLOAT*)(expected), (UNITY_FLOAT*)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_ARRAY_TO_ARRAY) -#define UNITY_TEST_ASSERT_EACH_EQUAL_FLOAT(expected, actual, num_elements, line, message) UnityAssertEqualFloatArray(UnityFloatToPtr(expected), (UNITY_FLOAT*)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_ARRAY_TO_VAL) -#define UNITY_TEST_ASSERT_FLOAT_IS_INF(actual, line, message) UnityAssertFloatSpecial((UNITY_FLOAT)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_FLOAT_IS_INF) -#define UNITY_TEST_ASSERT_FLOAT_IS_NEG_INF(actual, line, message) UnityAssertFloatSpecial((UNITY_FLOAT)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_FLOAT_IS_NEG_INF) -#define UNITY_TEST_ASSERT_FLOAT_IS_NAN(actual, line, message) UnityAssertFloatSpecial((UNITY_FLOAT)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_FLOAT_IS_NAN) -#define UNITY_TEST_ASSERT_FLOAT_IS_DETERMINATE(actual, line, message) UnityAssertFloatSpecial((UNITY_FLOAT)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_FLOAT_IS_DET) -#define UNITY_TEST_ASSERT_FLOAT_IS_NOT_INF(actual, line, message) UnityAssertFloatSpecial((UNITY_FLOAT)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_FLOAT_IS_NOT_INF) -#define UNITY_TEST_ASSERT_FLOAT_IS_NOT_NEG_INF(actual, line, message) UnityAssertFloatSpecial((UNITY_FLOAT)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_FLOAT_IS_NOT_NEG_INF) -#define UNITY_TEST_ASSERT_FLOAT_IS_NOT_NAN(actual, line, message) UnityAssertFloatSpecial((UNITY_FLOAT)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_FLOAT_IS_NOT_NAN) -#define UNITY_TEST_ASSERT_FLOAT_IS_NOT_DETERMINATE(actual, line, message) UnityAssertFloatSpecial((UNITY_FLOAT)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_FLOAT_IS_NOT_DET) -#endif - -#ifdef UNITY_EXCLUDE_DOUBLE -#define UNITY_TEST_ASSERT_DOUBLE_WITHIN(delta, expected, actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)(line), UnityStrErrDouble) -#define UNITY_TEST_ASSERT_EQUAL_DOUBLE(expected, actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)(line), UnityStrErrDouble) -#define UNITY_TEST_ASSERT_EQUAL_DOUBLE_ARRAY(expected, actual, num_elements, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)(line), UnityStrErrDouble) -#define UNITY_TEST_ASSERT_EACH_EQUAL_DOUBLE(expected, actual, num_elements, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)(line), UnityStrErrDouble) -#define UNITY_TEST_ASSERT_DOUBLE_IS_INF(actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)(line), UnityStrErrDouble) -#define UNITY_TEST_ASSERT_DOUBLE_IS_NEG_INF(actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)(line), UnityStrErrDouble) -#define UNITY_TEST_ASSERT_DOUBLE_IS_NAN(actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)(line), UnityStrErrDouble) -#define UNITY_TEST_ASSERT_DOUBLE_IS_DETERMINATE(actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)(line), UnityStrErrDouble) -#define UNITY_TEST_ASSERT_DOUBLE_IS_NOT_INF(actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)(line), UnityStrErrDouble) -#define UNITY_TEST_ASSERT_DOUBLE_IS_NOT_NEG_INF(actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)(line), UnityStrErrDouble) -#define UNITY_TEST_ASSERT_DOUBLE_IS_NOT_NAN(actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)(line), UnityStrErrDouble) -#define UNITY_TEST_ASSERT_DOUBLE_IS_NOT_DETERMINATE(actual, line, message) UNITY_TEST_FAIL((UNITY_LINE_TYPE)(line), UnityStrErrDouble) -#else -#define UNITY_TEST_ASSERT_DOUBLE_WITHIN(delta, expected, actual, line, message) UnityAssertDoublesWithin((UNITY_DOUBLE)(delta), (UNITY_DOUBLE)(expected), (UNITY_DOUBLE)(actual), (message), (UNITY_LINE_TYPE)(line)) -#define UNITY_TEST_ASSERT_EQUAL_DOUBLE(expected, actual, line, message) UNITY_TEST_ASSERT_DOUBLE_WITHIN((UNITY_DOUBLE)(expected) * (UNITY_DOUBLE)UNITY_DOUBLE_PRECISION, (UNITY_DOUBLE)(expected), (UNITY_DOUBLE)(actual), (UNITY_LINE_TYPE)(line), (message)) -#define UNITY_TEST_ASSERT_EQUAL_DOUBLE_ARRAY(expected, actual, num_elements, line, message) UnityAssertEqualDoubleArray((UNITY_DOUBLE*)(expected), (UNITY_DOUBLE*)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_ARRAY_TO_ARRAY) -#define UNITY_TEST_ASSERT_EACH_EQUAL_DOUBLE(expected, actual, num_elements, line, message) UnityAssertEqualDoubleArray(UnityDoubleToPtr(expected), (UNITY_DOUBLE*)(actual), (UNITY_UINT32)(num_elements), (message), (UNITY_LINE_TYPE)(line), UNITY_ARRAY_TO_VAL) -#define UNITY_TEST_ASSERT_DOUBLE_IS_INF(actual, line, message) UnityAssertDoubleSpecial((UNITY_DOUBLE)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_FLOAT_IS_INF) -#define UNITY_TEST_ASSERT_DOUBLE_IS_NEG_INF(actual, line, message) UnityAssertDoubleSpecial((UNITY_DOUBLE)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_FLOAT_IS_NEG_INF) -#define UNITY_TEST_ASSERT_DOUBLE_IS_NAN(actual, line, message) UnityAssertDoubleSpecial((UNITY_DOUBLE)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_FLOAT_IS_NAN) -#define UNITY_TEST_ASSERT_DOUBLE_IS_DETERMINATE(actual, line, message) UnityAssertDoubleSpecial((UNITY_DOUBLE)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_FLOAT_IS_DET) -#define UNITY_TEST_ASSERT_DOUBLE_IS_NOT_INF(actual, line, message) UnityAssertDoubleSpecial((UNITY_DOUBLE)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_FLOAT_IS_NOT_INF) -#define UNITY_TEST_ASSERT_DOUBLE_IS_NOT_NEG_INF(actual, line, message) UnityAssertDoubleSpecial((UNITY_DOUBLE)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_FLOAT_IS_NOT_NEG_INF) -#define UNITY_TEST_ASSERT_DOUBLE_IS_NOT_NAN(actual, line, message) UnityAssertDoubleSpecial((UNITY_DOUBLE)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_FLOAT_IS_NOT_NAN) -#define UNITY_TEST_ASSERT_DOUBLE_IS_NOT_DETERMINATE(actual, line, message) UnityAssertDoubleSpecial((UNITY_DOUBLE)(actual), (message), (UNITY_LINE_TYPE)(line), UNITY_FLOAT_IS_NOT_DET) -#endif - -/* End of UNITY_INTERNALS_H */ -#endif diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/aon_wdt/aon_wdt_driver.c b/bk7235/liteos_m/bk_sdk_armino/middleware/driver/aon_wdt/aon_wdt_driver.c index 23b70ba8bd9122c2037d6774b594197c391b5b4e..ec9dfd85f2c9b97510dee877fddeb43896794cd8 100644 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/aon_wdt/aon_wdt_driver.c +++ b/bk7235/liteos_m/bk_sdk_armino/middleware/driver/aon_wdt/aon_wdt_driver.c @@ -1,16 +1,17 @@ -// Copyright 2020-2022 Beken -// -// 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. +/* + * Copyright (C) 2022 Beken Corporation + * 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 #include diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/aon_wdt/aon_wdt_driver.h b/bk7235/liteos_m/bk_sdk_armino/middleware/driver/aon_wdt/aon_wdt_driver.h index ad2baeb0749837133c29f5639ae889f0765a6567..526eb1ea08dde72750ea92cd46007dc6349e8d01 100644 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/aon_wdt/aon_wdt_driver.h +++ b/bk7235/liteos_m/bk_sdk_armino/middleware/driver/aon_wdt/aon_wdt_driver.h @@ -1,16 +1,17 @@ -// Copyright 2020-2021 Beken -// -// 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. +/* + * Copyright (C) 2022 Beken Corporation + * 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. + */ #pragma once diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/bk7235/gpio_driver.c b/bk7235/liteos_m/bk_sdk_armino/middleware/driver/bk7235/gpio_driver.c index b16b5434045ca20c8df83f5a21001c0f0c9401c5..5ecb371ffd4c88832930dae6e0e1dd31b3731000 100755 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/bk7235/gpio_driver.c +++ b/bk7235/liteos_m/bk_sdk_armino/middleware/driver/bk7235/gpio_driver.c @@ -1,16 +1,17 @@ -// Copyright 2020-2021 Beken -// -// 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. +/* + * Copyright (C) 2022 Beken Corporation + * 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 #include "bk_intc.h" diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/bk7235/gpio_driver.h b/bk7235/liteos_m/bk_sdk_armino/middleware/driver/bk7235/gpio_driver.h index 568200a28c9d2bc99aebc130eb656aef21fecc6f..01f468cceaf668d1312908d682c26cc1324fa77a 100755 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/bk7235/gpio_driver.h +++ b/bk7235/liteos_m/bk_sdk_armino/middleware/driver/bk7235/gpio_driver.h @@ -1,17 +1,17 @@ -// Copyright 2020-2021 Beken -// -// 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. - +/* + * Copyright (C) 2022 Beken Corporation + * 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. + */ #pragma once #include "gpio_hal.h" diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/bk7235/interrupt.c b/bk7235/liteos_m/bk_sdk_armino/middleware/driver/bk7235/interrupt.c index a4eb2f78e5d6425229af535dac22b4c42ec251da..0765ead6e5b3e28051392a3748c1bc1efb4d4638 100755 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/bk7235/interrupt.c +++ b/bk7235/liteos_m/bk_sdk_armino/middleware/driver/bk7235/interrupt.c @@ -1,16 +1,18 @@ -// Copyright 2020-2021 Beken -// -// 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. +/* + * Copyright (C) 2022 Beken Corporation + * 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 "icu_driver.h" #include "interrupt_base.h" #include diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/bk7235/interrupt.h b/bk7235/liteos_m/bk_sdk_armino/middleware/driver/bk7235/interrupt.h index 2be4a3d5493e8feb39a5017cb95cb1e872f904a4..edf6fbb073a262b76c8b2d0368c76bc0fa9cf26b 100755 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/bk7235/interrupt.h +++ b/bk7235/liteos_m/bk_sdk_armino/middleware/driver/bk7235/interrupt.h @@ -1,16 +1,17 @@ -// Copyright 2020-2021 Beken -// -// 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. +/* + * Copyright (C) 2022 Beken Corporation + * 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. + */ #pragma once diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/bk7235/interrupt_statis.c b/bk7235/liteos_m/bk_sdk_armino/middleware/driver/bk7235/interrupt_statis.c index 8968b300d4682308ec5a101194ac3126e5d3f6af..ee8e15bfc992858ec8b65c1ae3b68d4942b86ee3 100755 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/bk7235/interrupt_statis.c +++ b/bk7235/liteos_m/bk_sdk_armino/middleware/driver/bk7235/interrupt_statis.c @@ -1,16 +1,17 @@ -// Copyright 2020-2021 Beken -// -// 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. +/* + * Copyright (C) 2022 Beken Corporation + * 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 #include "interrupt_base.h" diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/bk7235/mailbox_base_map.h b/bk7235/liteos_m/bk_sdk_armino/middleware/driver/bk7235/mailbox_base_map.h index f1124462aab458bd4359df6838258db471fef55d..8eb7b14a0dc8a01dcedebf80f252d44dcfb841ea 100755 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/bk7235/mailbox_base_map.h +++ b/bk7235/liteos_m/bk_sdk_armino/middleware/driver/bk7235/mailbox_base_map.h @@ -1,17 +1,17 @@ -// Copyright 2020-2021 Beken -// -// 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. - +/* + * Copyright (C) 2022 Beken Corporation + * 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. + */ #pragma once #include "mailbox_driver_base.h" diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/bk7235/mailbox_driver.c b/bk7235/liteos_m/bk_sdk_armino/middleware/driver/bk7235/mailbox_driver.c index 5a35139162118e41bd8b39f89d4b92aeb2d857bd..ec08c45719ada934f6a8f6057d1be3b358fe55ad 100755 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/bk7235/mailbox_driver.c +++ b/bk7235/liteos_m/bk_sdk_armino/middleware/driver/bk7235/mailbox_driver.c @@ -1,16 +1,17 @@ -// Copyright 2020-2021 Beken -// -// 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. +/* + * Copyright (C) 2022 Beken Corporation + * 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 #include diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/bk7235/mailbox_driver.h b/bk7235/liteos_m/bk_sdk_armino/middleware/driver/bk7235/mailbox_driver.h index 49df7014842181f4dd505886c083159fb2ed2640..4ff69fa3ed132ce1816703eca454b71484aef749 100755 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/bk7235/mailbox_driver.h +++ b/bk7235/liteos_m/bk_sdk_armino/middleware/driver/bk7235/mailbox_driver.h @@ -1,17 +1,17 @@ -// Copyright 2020-2021 Beken -// -// 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. - +/* + * Copyright (C) 2022 Beken Corporation + * 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. + */ #pragma once #include diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/bk7256/gpio_driver.c b/bk7235/liteos_m/bk_sdk_armino/middleware/driver/bk7256/gpio_driver.c deleted file mode 100755 index 653ac1b40f150bdc4ab46c68e00c537307f0fe2c..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/bk7256/gpio_driver.c +++ /dev/null @@ -1,167 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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 -#include "bk_intc.h" -#include "bk_icu.h" -#include -#include "gpio_hal.h" -#include "gpio_map.h" -#include "gpio_driver.h" -#include "gpio_driver_base.h" -#include "icu_driver.h" -#include "amp_lock_api.h" -#include - -extern gpio_driver_t s_gpio; - -#define GPIO_REG_LOCK_WAIT_TIME_MS 6 -#define GPIO_RETURN_ON_INVALID_PERIAL_MODE(mode, mode_max) do {\ - if ((mode) >= (mode_max)) {\ - return BK_ERR_GPIO_SET_INVALID_FUNC_MODE;\ - }\ - } while(0) - -bk_err_t gpio_dev_map(gpio_id_t gpio_id, gpio_dev_t dev) -{ - uint32_t ret_val = 1; - - ret_val = amp_res_acquire(AMP_RES_ID_GPIO, GPIO_REG_LOCK_WAIT_TIME_MS); - GPIO_LOGD("amp_res_acquire:ret=%d\r\n", ret_val); - if(ret_val != BK_OK) - return ret_val; - - /* Restore a configuration that is not a secondary function to its initial state. */ - gpio_hal_output_enable(&s_gpio.hal, gpio_id, 0); - gpio_hal_input_enable(&s_gpio.hal, gpio_id, 0); - gpio_hal_pull_enable(&s_gpio.hal, gpio_id, 0); - gpio_hal_disable_interrupt(&s_gpio.hal, gpio_id); - gpio_hal_func_map(&s_gpio.hal, gpio_id, dev); - - ret_val = amp_res_release(AMP_RES_ID_GPIO); - GPIO_LOGD("amp res release:ret=%d\r\n", ret_val); - if(ret_val != BK_OK) - return ret_val; - - return BK_OK; -} - -bk_err_t gpio_dev_unmap(gpio_id_t gpio_id) -{ - uint32_t ret_val = 1; - - ret_val = amp_res_acquire(AMP_RES_ID_GPIO, GPIO_REG_LOCK_WAIT_TIME_MS); - GPIO_LOGD("amp_res_acquire:ret=%d\r\n", ret_val); - if(ret_val != BK_OK) - return ret_val; - - /* Restore a configuration that is not a secondary function to its initial state. */ - gpio_hal_output_enable(&s_gpio.hal, gpio_id, 0); - gpio_hal_input_enable(&s_gpio.hal, gpio_id, 0); - gpio_hal_pull_enable(&s_gpio.hal, gpio_id, 0); - gpio_hal_disable_interrupt(&s_gpio.hal, gpio_id); - gpio_hal_func_unmap(&s_gpio.hal, gpio_id); - - ret_val = amp_res_release(AMP_RES_ID_GPIO); - GPIO_LOGD("amp res release:ret=%d\r\n", ret_val); - if(ret_val != BK_OK) - return ret_val; - - return BK_OK; -} - -bk_err_t gpio_i2c1_sel(gpio_i2c1_map_mode_t mode) -{ - GPIO_RETURN_ON_INVALID_PERIAL_MODE(mode, GPIO_I2C1_MAP_MODE_MAX); - - GPIO_MAP_TABLE(GPIO_I2C1_USED_GPIO_NUM, GPIO_I2C1_MAP_MODE_MAX, i2c1_gpio_map) = GPIO_I2C1_MAP_TABLE; - - gpio_hal_devs_map(&s_gpio.hal, i2c1_gpio_map[mode].gpio_bits, i2c1_gpio_map[mode].devs, GPIO_I2C1_USED_GPIO_NUM); - - return BK_OK; -} - -bk_err_t gpio_i2s_sel(gpio_i2s_map_mode_t mode) -{ - GPIO_RETURN_ON_INVALID_PERIAL_MODE(mode, GPIO_I2S_MAP_MODE_MAX); - - GPIO_MAP_TABLE(GPIO_I2S_USED_GPIO_NUM, GPIO_I2S_MAP_MODE_MAX, i2s_gpio_map) = GPIO_I2S_MAP_TABLE; - - gpio_hal_devs_map(&s_gpio.hal, i2s_gpio_map[mode].gpio_bits, i2s_gpio_map[mode].devs, GPIO_I2S_USED_GPIO_NUM); - - return BK_OK; -} - -bk_err_t gpio_spi_sel(gpio_spi1_map_mode_t mode) -{ - GPIO_RETURN_ON_INVALID_PERIAL_MODE(mode, GPIO_SPI_MAP_MODE_MAX); - - GPIO_MAP_TABLE(GPIO_SPI0_USED_GPIO_NUM, GPIO_SPI_MAP_MODE_MAX, spi_gpio_map) = GPIO_SPI0_MAP_TABLE; - - gpio_hal_devs_map(&s_gpio.hal, spi_gpio_map[mode].gpio_bits, spi_gpio_map[mode].devs, GPIO_SPI0_USED_GPIO_NUM); - - return BK_OK; -} - -bk_err_t gpio_sdio_sel(gpio_sdio_map_mode_t mode) -{ - GPIO_RETURN_ON_INVALID_PERIAL_MODE(mode, GPIO_SDIO_MAP_MODE_MAX); - - GPIO_MAP_TABLE(GPIO_SDIO_USED_GPIO_NUM, GPIO_SDIO_MAP_MODE_MAX, sdio_gpio_map) = GPIO_SDIO_MAP_TABLE; - - gpio_hal_devs_map(&s_gpio.hal, sdio_gpio_map[mode].gpio_bits, sdio_gpio_map[mode].devs, GPIO_SDIO_USED_GPIO_NUM); - - return BK_OK; -} - -bk_err_t gpio_sdio_one_line_sel(gpio_sdio_map_mode_t mode) -{ - GPIO_RETURN_ON_INVALID_PERIAL_MODE(mode, GPIO_SDIO_MAP_MODE_MAX); - - GPIO_MAP_TABLE(GPIO_SDIO_ONE_LINE_USED_GPIO_NUM, GPIO_SDIO_MAP_MODE_MAX, sdio_gpio_map) = GPIO_SDIO_ONE_LINE_MAP_TABLE; - - gpio_hal_devs_map(&s_gpio.hal, sdio_gpio_map[mode].gpio_bits, sdio_gpio_map[mode].devs, GPIO_SDIO_ONE_LINE_USED_GPIO_NUM); - - return BK_OK; -} - -static gpio_jtag_map_mode_t gpio_jtag_default_mode = GPIO_JTAG_MAP_MODE; -bk_err_t gpio_jtag_sel(gpio_jtag_map_mode_t mode) -{ - GPIO_RETURN_ON_INVALID_PERIAL_MODE(mode, GPIO_JTAG_MAP_MODE_MAX); - if(gpio_jtag_default_mode == mode) - return BK_OK; - else - gpio_jtag_default_mode = mode; - - GPIO_MAP_TABLE(GPIO_JTAG_USED_GPIO_NUM, GPIO_JTAG_MAP_MODE_MAX, jtag_gpio_map) = GPIO_JTAG_MAP_TABLE; - - for(gpio_jtag_map_mode_t sel_mode = GPIO_JTAG_MAP_MODE; sel_mode < GPIO_JTAG_MAP_MODE_MAX; sel_mode++) - { - for(int gpio_index = 0; gpio_index < GPIO_NUM; gpio_index++) - { - if (jtag_gpio_map[sel_mode].gpio_bits & BIT64(gpio_index)) { - GPIO_LOGI("gpio_jtag_sel unmap gpio_index = %d\r\n", gpio_index); - gpio_hal_func_unmap(&s_gpio.hal, gpio_index); - } - } - } - - gpio_hal_devs_map(&s_gpio.hal, jtag_gpio_map[mode].gpio_bits, jtag_gpio_map[mode].devs, GPIO_JTAG_USED_GPIO_NUM); - - GPIO_LOGD("Warning bk7256 USE PLIC NOT icu\n"); - - return BK_OK; -} - diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/bk7256/gpio_driver.h b/bk7235/liteos_m/bk_sdk_armino/middleware/driver/bk7256/gpio_driver.h deleted file mode 100755 index f54df9a0fb3ea245a58f99011b8c45e0340142db..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/bk7256/gpio_driver.h +++ /dev/null @@ -1,85 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once -#include "gpio_hal.h" - -typedef enum { - GPIO_SDIO_MAP_MODE0 = 0, /** - - -void soc_isr_init(void) -{ - arch_isr_entry_init(); -} - -void soc_isr_deinit(void) -{ - /*to do something*/ -} diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/bk7256/interrupt.h b/bk7235/liteos_m/bk_sdk_armino/middleware/driver/bk7256/interrupt.h deleted file mode 100755 index 2be4a3d5493e8feb39a5017cb95cb1e872f904a4..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/bk7256/interrupt.h +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -void soc_isr_init(void); -void soc_isr_deinit(void); diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/bk7256/interrupt_statis.c b/bk7235/liteos_m/bk_sdk_armino/middleware/driver/bk7256/interrupt_statis.c deleted file mode 100755 index 8968b300d4682308ec5a101194ac3126e5d3f6af..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/bk7256/interrupt_statis.c +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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 -#include "interrupt_base.h" -#include "icu_driver.h" -#include - -#if CONFIG_INT_STATIS -extern int_statis_t g_int_statis_num; - -int_statis_t * bk_get_int_statis(void) -{ - return &g_int_statis_num; -} - -bk_err_t bk_dump_int_statis(int_statis_t *int_statistic) -{ - ICU_LOGI(" irq:int_statis:%x\r\n", int_statistic->irq_int_statis); - ICU_LOGI(" uart1 int_num=%d\n", int_statistic->irq_int_statis[0]); - ICU_LOGI(" uart2 int_num=%d\n", int_statistic->irq_int_statis[1]); - ICU_LOGI(" i2c1 int_num=%d\n", int_statistic->irq_int_statis[2]); - ICU_LOGI(" irda int_num=%d\n", int_statistic->irq_int_statis[3]); - ICU_LOGI(" i2c2 int_num=%d\n", int_statistic->irq_int_statis[5]); - ICU_LOGI(" spi int_num=%d\n", int_statistic->irq_int_statis[6]); - ICU_LOGI(" gpio int_num=%d\n", int_statistic->irq_int_statis[7]); - ICU_LOGI(" timer int_num=%d\n", int_statistic->irq_int_statis[8]); - ICU_LOGI(" pwm int_num=%d\n", int_statistic->irq_int_statis[9]); - ICU_LOGI(" saradc int_num=%d\n", int_statistic->irq_int_statis[11]); - ICU_LOGI(" sdio int_num=%d\n", int_statistic->irq_int_statis[12]); - ICU_LOGI(" sercurity int_num=%d\n", int_statistic->irq_int_statis[13]); - ICU_LOGI(" LA int_num=%d\n", int_statistic->irq_int_statis[14]); - ICU_LOGI(" general_dma int_num=%d\n", int_statistic->irq_int_statis[15]); - - ICU_LOGI(" fiq : int_statis:%x\r\n", int_statistic->fiq_int_statis); - ICU_LOGI(" modem int_num=%d\n", int_statistic->fiq_int_statis[0]); - ICU_LOGI(" mac_txrx_timer int_num=%d\n", int_statistic->fiq_int_statis[1]); - ICU_LOGI(" mac_txrx_misc int_num=%d\n", int_statistic->fiq_int_statis[2]); - ICU_LOGI(" mac_rx_triggerint_num=%d\n", int_statistic->fiq_int_statis[3]); - ICU_LOGI(" mac_tx_trigger int_num=%d\n", int_statistic->fiq_int_statis[4]); - ICU_LOGI(" mac_prot_trigger int_num=%d\n", int_statistic->fiq_int_statis[5]); - ICU_LOGI(" mac_general int_num=%d\n", int_statistic->fiq_int_statis[6]); - ICU_LOGI(" mac_wakeup int_num=%d\n", int_statistic->fiq_int_statis[10]); - ICU_LOGI(" pll_unlock int_num=%d\n", int_statistic->fiq_int_statis[12]); - ICU_LOGI(" btdm int_num=%d\n", int_statistic->fiq_int_statis[13]); - ICU_LOGI(" ble int_num=%d\n", int_statistic->fiq_int_statis[14]); - ICU_LOGI(" bt int_num=%d\n", int_statistic->fiq_int_statis[15]); - - return BK_OK; -} -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/bk7256/mailbox_base_map.h b/bk7235/liteos_m/bk_sdk_armino/middleware/driver/bk7256/mailbox_base_map.h deleted file mode 100755 index f1124462aab458bd4359df6838258db471fef55d..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/bk7256/mailbox_base_map.h +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#include "mailbox_driver_base.h" - -//struct mailbox_direction_t: -#define MAILBAOX_CONFIG_INFO_TABLE \ -{ \ - {MAILBOX0, INT_SRC_NONE, MAILBOX_CPU0, MAILBOX_CPU1},\ - {MAILBOX1, INT_SRC_MAILBOX1, MAILBOX_CPU1, MAILBOX_CPU0},\ -} - diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/bk7256/mailbox_driver.c b/bk7235/liteos_m/bk_sdk_armino/middleware/driver/bk7256/mailbox_driver.c deleted file mode 100644 index 5a35139162118e41bd8b39f89d4b92aeb2d857bd..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/bk7256/mailbox_driver.c +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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 -#include -#include "sys_driver.h" -#include "mailbox_driver.h" - -void mailbox_interrupt_enable(mailbox_endpoint_t src) -{ - switch(src) { - case MAILBOX_CPU0: - sys_drv_int_group2_enable(MBOX0_INTERRUPT_CTRL_BIT); - break; - case MAILBOX_CPU1: - sys_drv_int_group2_enable(MBOX1_INTERRUPT_CTRL_BIT); - break; - default: - break; - } -} - -void mailbox_interrupt_disable(mailbox_endpoint_t src) -{ - switch(src) { - case MAILBOX_CPU0: - sys_drv_int_group2_disable(MBOX0_INTERRUPT_CTRL_BIT); - break; - case MAILBOX_CPU1: - sys_drv_int_group2_disable(MBOX1_INTERRUPT_CTRL_BIT); - break; - default: - break; - } -} - diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/bk7256/mailbox_driver.h b/bk7235/liteos_m/bk_sdk_armino/middleware/driver/bk7256/mailbox_driver.h deleted file mode 100644 index 49df7014842181f4dd505886c083159fb2ed2640..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/bk7256/mailbox_driver.h +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright 2020-2021 Beken -// -// 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. - -#pragma once - -#include - -void mailbox_interrupt_enable(mailbox_endpoint_t src); -void mailbox_interrupt_disable(mailbox_endpoint_t src); - diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/common/dd.c b/bk7235/liteos_m/bk_sdk_armino/middleware/driver/common/dd.c index 25aa926bef1a9e9219e2fb17d8b2119d57076e01..694955f66f70d43f4712c845ffab5f0cabd49dac 100644 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/common/dd.c +++ b/bk7235/liteos_m/bk_sdk_armino/middleware/driver/common/dd.c @@ -1,3 +1,17 @@ +/* + * Copyright (C) 2022 Beken Corporation + * 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 #include "bk_arm_arch.h" #include "dd_pub.h" diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/common/drv_model.c b/bk7235/liteos_m/bk_sdk_armino/middleware/driver/common/drv_model.c index 69a1827cb6ef3179041145c6986cbe664f58dd02..8525334b553afa8b33efeb96afa9bfd2ddf487cf 100644 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/common/drv_model.c +++ b/bk7235/liteos_m/bk_sdk_armino/middleware/driver/common/drv_model.c @@ -1,3 +1,17 @@ +/* + * Copyright (C) 2022 Beken Corporation + * 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 #include "bk_arm_arch.h" diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/common/drv_model.h b/bk7235/liteos_m/bk_sdk_armino/middleware/driver/common/drv_model.h index 01fe9b81d4d4e4d5d5b7a2fbd5c1b6e9597b2250..9c996ad83facd20e2e800dbdadca33b1d47226fa 100644 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/common/drv_model.h +++ b/bk7235/liteos_m/bk_sdk_armino/middleware/driver/common/drv_model.h @@ -1,3 +1,17 @@ +/* + * Copyright (C) 2022 Beken Corporation + * 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 _DRV_MODEL_H_ #define _DRV_MODEL_H_ diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/dsp/dsp.c b/bk7235/liteos_m/bk_sdk_armino/middleware/driver/dsp/dsp.c deleted file mode 100755 index 1a38f7af57def98f52151f969a903f970788a63e..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/dsp/dsp.c +++ /dev/null @@ -1,126 +0,0 @@ -#include -#include "bk_arm_arch.h" -//#include "bk_arm_mcu.h" -#include "bk_lbus.h" -#include "bk_dsp.h" -#include "dsp.h" -#include -#include "pmu.h" -#include -#include -#include - -#define TAG "dsp" - -#if (CONFIG_SOC_BK7271) -int g_dsp_inited = 0; - -#if CONFIG_DSP -void dsp_start(void) -{ - uint32 i; - uint32 src_code_offset = 0; - uint32 src_code_len = 0; - uint32 src_data_offset = 0; - uint32 src_data_len = 0; - uint32 src_ext_data_offset = 0; - uint32 src_ext_data_len = 0; - uint32 dst_code_base = W_DSP_DMEM_64KB_BASE_ADDR; - uint32 dst_code_offset = 0x0; - uint32 dst_data_base = W_DSP_DMEM_64KB_BASE_ADDR; - uint32 dst_data_offset = 0x0; - uint32 dst_ext_data_base = W_DSP_DMEM_64KB_BASE_ADDR; - uint32 dst_ext_data_offset = 0; - - src_code_offset = REG_READ(CONFIG_DSP_SRC_ADD); - src_code_len = REG_READ(CONFIG_DSP_SRC_ADD + 4); - dst_code_offset = REG_READ(CONFIG_DSP_SRC_ADD + 8); - - src_data_offset = REG_READ(CONFIG_DSP_SRC_ADD + 16); - src_data_len = REG_READ(CONFIG_DSP_SRC_ADD + 20); - dst_data_offset = REG_READ(CONFIG_DSP_SRC_ADD + 24); - - src_ext_data_offset = REG_READ(CONFIG_DSP_SRC_ADD + 32); - src_ext_data_len = REG_READ(CONFIG_DSP_SRC_ADD + 36); - dst_ext_data_offset = REG_READ(CONFIG_DSP_SRC_ADD + 40); - - BK_LOGI(TAG, "code:0x%08x 0x%08x\r\n" "dst_code_offset:0x%08x \r\n" - "data:0x%08x 0x%08x\r\n" "dst_data_offset:0x%08x \r\n" - "ext_data:0x%08x 0x%08x\r\n" "dst_ext_data_offset:0x%08x \r\n" - , src_code_offset, src_code_len, dst_code_offset - , src_data_offset, src_data_len, dst_data_offset - , src_ext_data_offset, src_ext_data_len, dst_ext_data_offset); - - /* LBUS should be ready when copy dsp and bluetooth data */ - *((volatile unsigned long *) PMU_CO_MCU_CONFIG) |= 0x15; - - BK_LOGI(TAG, "start code DL !! \r\n"); - i = 0; - while (i < src_code_len) { - *((volatile unsigned long *)(dst_code_base + dst_code_offset + i)) = - *((volatile unsigned long *)(CONFIG_DSP_SRC_ADD + src_code_offset + i)); - i += 4; - } - - BK_LOGI(TAG, "start data DL !! \r\n"); - i = 0; - while (i < src_data_len) { - *((volatile unsigned long *)(dst_data_base + dst_data_offset + i)) = - *((volatile unsigned long *)(CONFIG_DSP_SRC_ADD + src_data_offset + i)); - i += 4; - } - - if (*((volatile unsigned long *)(dst_data_base + dst_data_offset + i - 4)) != - *((volatile unsigned long *)(CONFIG_DSP_SRC_ADD + src_data_offset + i - 4))) - BK_LOGI(TAG, "last dst data error \r\n"); - - BK_LOGI(TAG, "start ext data DL !! \r\n"); - i = 0; - while (i < src_ext_data_len) { - *((volatile unsigned long *)(dst_ext_data_base + dst_ext_data_offset + i)) = - *((volatile unsigned long *)(CONFIG_DSP_SRC_ADD + src_ext_data_offset + i)); - i += 4; - } - - if (*((volatile unsigned long *)(dst_ext_data_base + dst_ext_data_offset + i - 4)) != - *((volatile unsigned long *)(CONFIG_DSP_SRC_ADD + src_ext_data_offset + i - 4))) - BK_LOGI(TAG, "last dst ext data error \r\n"); - - *((volatile unsigned long *) PMU_CO_MCU_CONFIG) &= ~(0x1 << 0); -} - -void dsp_reset(void) -{ - *((volatile unsigned long *) LBUS_CONF0_REG) |= DSP_DOWNLOAD_ENABLE; - - rtos_delay_milliseconds(100); - - *((volatile unsigned long *) LBUS_CONF0_REG) &= ~DSP_DOWNLOAD_ENABLE; -} -#endif - -void dsp_init(void) -{ - if (ate_is_enabled()) - return; -#if CONFIG_DSP - BK_LOGI(TAG, "dsp_init\r\n"); - dsp_start(); - g_dsp_inited = 1; -#endif -} - -uint32_t dsp_is_inited(void) -{ - return g_dsp_inited; -} - - -void dsp_exit(void) -{ -} -#endif // (CONFIG_SOC_BK7271) -// eof - - - diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/dsp/dsp.h b/bk7235/liteos_m/bk_sdk_armino/middleware/driver/dsp/dsp.h deleted file mode 100644 index d46c4c9163866db4def55f30a9568bd1e48afaa1..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/dsp/dsp.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef _DSP__H_ -#define _DSP__H_ -#include "bk_uart.h" - -#endif //_DSP__H_ - diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/fft/fft.c b/bk7235/liteos_m/bk_sdk_armino/middleware/driver/fft/fft.c deleted file mode 100755 index 5047743bfb74c991e5844ebdeeddefda655ab81b..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/fft/fft.c +++ /dev/null @@ -1,167 +0,0 @@ -#include -#include "bk_arm_arch.h" - -#include "fft.h" -#include "bk_fft.h" - -#include "bk_drv_model.h" -#include - -#if CONFIG_FFT -static driver_fft_t driver_fft; -static const DD_OPERATIONS fft_op = { - NULL, - NULL, - NULL, - NULL, - fft_ctrl -}; - -static int fft_busy(void) -{ - return driver_fft.busy_flag; -} - -static void fft_enable(input_fft_t *fft_conf) -{ - int i; - UINT32 value = 0; - - REG_WRITE(FIR_CONF, 0); - REG_WRITE(FFT_CONF, 0); - - if (fft_conf->mode == FFT_MODE_FFT) - value = FFT_CONF_INT_EN | FFT_CONF_ENABLE; - else if (fft_conf->mode == FFT_MODE_IFFT) - value = FFT_CONF_IFFT | FFT_CONF_INT_EN | FFT_CONF_ENABLE; - REG_WRITE(FFT_CONF, value); - - driver_fft.in = fft_conf->inbuf; - driver_fft.out = fft_conf->outbuf; - driver_fft.size = fft_conf->size; - driver_fft.busy_flag = 1; - - for (i = 0; i < fft_conf->size; i++) { - value = (UINT16)(fft_conf->inbuf[i]) << 16 | (UINT16)(fft_conf->outbuf[i]); - Fft_Write_Data(value); - } - - Fft_Set_Start(); -} - -static void fir_single_enable(input_fir_t *fir_conf) -{ - int i; - UINT32 value = 0; - - if (fir_conf->fir_len > 64) - return; - - REG_WRITE(FIR_CONF, 0); - REG_WRITE(FFT_CONF, 0); - - value = (fir_conf->fir_len << FIR_CONF_LEN_POSI) - | (fir_conf->fir_cwidth << FIR_CONF_CWIDTH_POSI) - | (fir_conf->fir_dwidth << FIR_CONF_DWIDTH_POSI) - | FIR_CONF_INT_EN - | FIR_CONF_ENABLE; - REG_WRITE(FIR_CONF, value); - - driver_fft.mac_out = fir_conf->mac; - driver_fft.busy_flag = 1; - - for (i = 0; i < fir_conf->fir_len + 1; i++) { - Fft_Write_Coef(fir_conf->coef[i]); - Fft_Write_Data(fir_conf->input[i]); - } - - Fft_Set_Start(); - - return; -} - -static __inline INT16 f_sat(int din) -{ - if (din > 32767) - return 32767; - if (din < -32767) - return -32767; - else - return (din); -} - -void fft_init(void) -{ - bk_int_isr_register(INT_SRC_FFT, fft_isr, NULL); - - sddev_register_dev(DD_DEV_TYPE_FFT, (DD_OPERATIONS *)&fft_op); -} - -void fft_exit(void) -{ - sddev_unregister_dev(DD_DEV_TYPE_FFT); -} - -UINT32 fft_ctrl(UINT32 cmd, void *param) -{ - int ret = FFT_SUCCESS; - - switch (cmd) { - case CMD_FFT_BUSY: - *((int *)param) = fft_busy(); - break; - case CMD_FFT_ENABLE: - fft_enable((input_fft_t *)param); - break; - case CMD_FIR_SIGNLE_ENABLE: - fir_single_enable((input_fir_t *)param); - break; - default: - ret = FFT_FAILURE; - break; - } - - return ret; -} - -void fft_isr(void) -{ - UINT32 int_status; - UINT8 FFT_int, FIR_int; - - int_status = REG_READ(FFT_STATUS); - FFT_int = int_status & FFT_STATUS_DONE; - FIR_int = int_status & FIR_STATUS_DONE; - - if (FFT_int) { - int i; - int bit_ext; - INT32 temp, temp_out; - - bit_ext = (int_status & 0x00001fff) >> 7; - - if (bit_ext & 0x20) - bit_ext = 64 - bit_ext; - else - bit_ext = 0; - - for (i = 0; i < driver_fft.size; i++) { - temp = Fft_Read_Data(); - temp_out = ((temp << 16) >> 16) << bit_ext ; - driver_fft.out[i] = f_sat(temp_out); - temp_out = (temp >> 16) << bit_ext; - driver_fft.in[i] = f_sat(temp_out); - } - - driver_fft.busy_flag = 0; - REG_WRITE(FFT_CONF, 0); - } - - if (FIR_int) { - *driver_fft.mac_out = REG_READ(FFT_MAC_LOW); - - driver_fft.busy_flag = 0; - REG_WRITE(FIR_CONF, 0); - } -} -#endif diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/fft/fft.h b/bk7235/liteos_m/bk_sdk_armino/middleware/driver/fft/fft.h index 4401a9c17b08c162cc698f34d287ab23e60a47c4..2788ec12855bbc09c354c051562c8794c1d0cf4c 100644 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/fft/fft.h +++ b/bk7235/liteos_m/bk_sdk_armino/middleware/driver/fft/fft.h @@ -1,3 +1,17 @@ +/* + * Copyright (C) 2022 Beken Corporation + * 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 _FFT_H_ #define _FFT_H_ diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/flash/flash.c b/bk7235/liteos_m/bk_sdk_armino/middleware/driver/flash/flash.c index 5bdd7167ec007c47dd2474bc212883765dbec532..5d8febe73e3f3330b44a84880a2dd241bae209ea 100755 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/flash/flash.c +++ b/bk7235/liteos_m/bk_sdk_armino/middleware/driver/flash/flash.c @@ -1,3 +1,17 @@ +/* + * Copyright (C) 2022 Beken Corporation + * 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 #include "bk_arm_arch.h" #include diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/flash/flash.h b/bk7235/liteos_m/bk_sdk_armino/middleware/driver/flash/flash.h index bc25cf8fa23082df4847d2b958e2311ec309c315..e45c55605669bac759f31146de481de1a3f57034 100644 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/flash/flash.h +++ b/bk7235/liteos_m/bk_sdk_armino/middleware/driver/flash/flash.h @@ -1,3 +1,17 @@ +/* + * Copyright (C) 2022 Beken Corporation + * 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 _FLASH_H_ #define _FLASH_H_ diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/flash/flash_bypass.c b/bk7235/liteos_m/bk_sdk_armino/middleware/driver/flash/flash_bypass.c index ca6b62ebf9a06bbc1d31f9c39f79911c67ea6b21..7d860574a0fcf9139ca2e12b4b23fa76062e6be7 100755 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/flash/flash_bypass.c +++ b/bk7235/liteos_m/bk_sdk_armino/middleware/driver/flash/flash_bypass.c @@ -1,3 +1,17 @@ +/* + * Copyright (C) 2022 Beken Corporation + * 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 #include "bk_arm_arch.h" #include diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/flash/flash_bypass.h b/bk7235/liteos_m/bk_sdk_armino/middleware/driver/flash/flash_bypass.h index 293ac32cb360f16e3f1684d660038a1a4a3f2c2e..e7ec1a1aac234803de7b3a6553c4d765154689fc 100755 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/flash/flash_bypass.h +++ b/bk7235/liteos_m/bk_sdk_armino/middleware/driver/flash/flash_bypass.h @@ -1,3 +1,17 @@ +/* + * Copyright (C) 2022 Beken Corporation + * 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 __FLASH_BYPASS_H__ #define __FLASH_BYPASS_H__ diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/i2s/i2s.c b/bk7235/liteos_m/bk_sdk_armino/middleware/driver/i2s/i2s.c index 426b5c332dbbd2c7420ffe0a5ee43f777060da41..bf96f97c25b600dab5c87dc8b6ae6a1dfa91c858 100755 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/i2s/i2s.c +++ b/bk7235/liteos_m/bk_sdk_armino/middleware/driver/i2s/i2s.c @@ -1,3 +1,17 @@ +/* + * Copyright (C) 2022 Beken Corporation + * 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 #include "bk_arm_arch.h" #include diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/i2s/i2s.h b/bk7235/liteos_m/bk_sdk_armino/middleware/driver/i2s/i2s.h index a85d1adbf48f8d97bd3e2b11081bc78ba1833d97..25ef1deceaa6b9d331b77bc5d4687ea3870e2dde 100644 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/i2s/i2s.h +++ b/bk7235/liteos_m/bk_sdk_armino/middleware/driver/i2s/i2s.h @@ -1,3 +1,17 @@ +/* + * Copyright (C) 2022 Beken Corporation + * 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 _I2S_H_ #define _I2S_H_ diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/include/bk_private/bk_pm_control.h b/bk7235/liteos_m/bk_sdk_armino/middleware/driver/include/bk_private/bk_pm_control.h index 982435238fd9704b58dbe16f77a6bf04cba000a9..2a5fa6258f4851ce390ef0a6f24395fd3b77a114 100644 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/include/bk_private/bk_pm_control.h +++ b/bk7235/liteos_m/bk_sdk_armino/middleware/driver/include/bk_private/bk_pm_control.h @@ -1,3 +1,17 @@ +/* + * Copyright (C) 2022 Beken Corporation + * 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. + */ enum { diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/include/bk_private/bk_pm_model.h b/bk7235/liteos_m/bk_sdk_armino/middleware/driver/include/bk_private/bk_pm_model.h index 942a0146763a39e28e7be61ae310086223de14ab..82b438a7b4cce39ed46ace15cd45e3f1142cb3b9 100644 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/include/bk_private/bk_pm_model.h +++ b/bk7235/liteos_m/bk_sdk_armino/middleware/driver/include/bk_private/bk_pm_model.h @@ -1,3 +1,17 @@ +/* + * Copyright (C) 2022 Beken Corporation + * 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. + */ typedef enum _pm_dev_state_ { PM_UNUSABLE = 0, diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/include/bk_private/bk_rf_ps.h b/bk7235/liteos_m/bk_sdk_armino/middleware/driver/include/bk_private/bk_rf_ps.h index d0abf7818c73a4a3bc267abe93010528188da27b..fc548e252a87c86588c61bb22ffd545cf33cb9e8 100644 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/include/bk_private/bk_rf_ps.h +++ b/bk7235/liteos_m/bk_sdk_armino/middleware/driver/include/bk_private/bk_rf_ps.h @@ -1,3 +1,17 @@ +/* + * Copyright (C) 2022 Beken Corporation + * 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. + */ #define RF_DEV_NAME "rf_ctrl" diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/irda/irda.c b/bk7235/liteos_m/bk_sdk_armino/middleware/driver/irda/irda.c index 1b6e276d46d4a6ad6c14dcb9d70fe778d63b6680..66978df231b02e32129ed0567f9dc3b269d393f5 100755 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/irda/irda.c +++ b/bk7235/liteos_m/bk_sdk_armino/middleware/driver/irda/irda.c @@ -1,3 +1,17 @@ +/* + * Copyright (C) 2022 Beken Corporation + * 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 #include "bk_arm_arch.h" diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/irda/irda.h b/bk7235/liteos_m/bk_sdk_armino/middleware/driver/irda/irda.h index 7b734cdff7f320df0d91b0123dfdc6c2f6234ea1..676f84b555169399ed0ccc5deac29b391b8bd4ca 100644 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/irda/irda.h +++ b/bk7235/liteos_m/bk_sdk_armino/middleware/driver/irda/irda.h @@ -1,3 +1,17 @@ +/* + * Copyright (C) 2022 Beken Corporation + * 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 _IRDA_H_ #define _IRDA_H_ diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/lcd/lcd_spi.c b/bk7235/liteos_m/bk_sdk_armino/middleware/driver/lcd/lcd_spi.c index 514f572657c50b28283cbfd1bafd510381697731..13c7224b88ae5f046bfda90c1f1af2508f7ae9b6 100755 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/lcd/lcd_spi.c +++ b/bk7235/liteos_m/bk_sdk_armino/middleware/driver/lcd/lcd_spi.c @@ -1,3 +1,17 @@ +/* + * Copyright (C) 2022 Beken Corporation + * 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 #include #include diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/pmu/aon_pmu_driver.c b/bk7235/liteos_m/bk_sdk_armino/middleware/driver/pmu/aon_pmu_driver.c index 9b756c7c39fde370744c972c9cae2c786d6df054..bd1d136cc3561c6869edf2f6bab28790f166a047 100644 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/pmu/aon_pmu_driver.c +++ b/bk7235/liteos_m/bk_sdk_armino/middleware/driver/pmu/aon_pmu_driver.c @@ -12,20 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -// Copyright 2020-2021 Beken -// -// 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 #include "aon_pmu_hal.h" diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/pmu/pmu.h b/bk7235/liteos_m/bk_sdk_armino/middleware/driver/pmu/pmu.h index 53580326b7d16aeeac8a860a3d8905720bca6460..8edf34f1c31277549a4aa31970973b285fe5d46f 100644 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/pmu/pmu.h +++ b/bk7235/liteos_m/bk_sdk_armino/middleware/driver/pmu/pmu.h @@ -1,3 +1,17 @@ +/* + * Copyright (C) 2022 Beken Corporation + * 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 __PMU_H__ #define __PMU_H__ diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/port/mem_port.c b/bk7235/liteos_m/bk_sdk_armino/middleware/driver/port/mem_port.c index 6946858aa87ea6083103dcc695c1a9bf5ef6e2b4..cd744724f000e0e911076300e698fc891b45873e 100644 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/port/mem_port.c +++ b/bk7235/liteos_m/bk_sdk_armino/middleware/driver/port/mem_port.c @@ -1,3 +1,17 @@ +/* + * Copyright (C) 2022 Beken Corporation + * 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 #include #include diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/port/os_port.c b/bk7235/liteos_m/bk_sdk_armino/middleware/driver/port/os_port.c index b346f0ddefe34b76cc5ff5ef9c17b31762ecbbe0..876cde8d6148a0e8799cf5f612152347d20532f2 100644 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/port/os_port.c +++ b/bk7235/liteos_m/bk_sdk_armino/middleware/driver/port/os_port.c @@ -1,3 +1,17 @@ +/* + * Copyright (C) 2022 Beken Corporation + * 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 #include #include diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/reset_reason/reset_reason.c b/bk7235/liteos_m/bk_sdk_armino/middleware/driver/reset_reason/reset_reason.c index 8e1d9962e52f8e8528871a2ebc2e93e875d19d49..c5cab2fd37601d760396e5bec52005c45cb5016d 100644 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/reset_reason/reset_reason.c +++ b/bk7235/liteos_m/bk_sdk_armino/middleware/driver/reset_reason/reset_reason.c @@ -1,3 +1,17 @@ +/* + * Copyright (C) 2022 Beken Corporation + * 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 #include "bk_fake_clock.h" #include "bk_icu.h" diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/sdcard/sdcard.c b/bk7235/liteos_m/bk_sdk_armino/middleware/driver/sdcard/sdcard.c index f1b580786007e2af13d0f90c86960b3e0c661a5d..35103a80da02be6b549c4a4b417bf1bb0d64fb76 100755 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/sdcard/sdcard.c +++ b/bk7235/liteos_m/bk_sdk_armino/middleware/driver/sdcard/sdcard.c @@ -1,3 +1,18 @@ +/* + * Copyright (C) 2022 Beken Corporation + * 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 #include "sys_rtos.h" #include diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/sdcard/sdcard.h b/bk7235/liteos_m/bk_sdk_armino/middleware/driver/sdcard/sdcard.h index 1021f57d9ac82129b3a4b43b1ec48d4e98cc48c2..e9127685efa64657054a59ffe951537a5867e38f 100644 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/sdcard/sdcard.h +++ b/bk7235/liteos_m/bk_sdk_armino/middleware/driver/sdcard/sdcard.h @@ -1,3 +1,18 @@ +/* + * Copyright (C) 2022 Beken Corporation + * 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 _SDCARD_H_ #define _SDCARD_H_ diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/sdcard/sdcard_pub.h b/bk7235/liteos_m/bk_sdk_armino/middleware/driver/sdcard/sdcard_pub.h index 1f4fb319c010e6605ef76461479a2a2864599111..37609a00d68d49ec1e7882822ddadce7d7cab862 100644 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/sdcard/sdcard_pub.h +++ b/bk7235/liteos_m/bk_sdk_armino/middleware/driver/sdcard/sdcard_pub.h @@ -1,3 +1,18 @@ +/* + * Copyright (C) 2022 Beken Corporation + * 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 _SDCARD_PUB_H_ #define _SDCARD_PUB_H_ diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/sdcard/sdcard_test.c b/bk7235/liteos_m/bk_sdk_armino/middleware/driver/sdcard/sdcard_test.c index 8527a07b4569864ca37efaa6d5f6dd772dab46a8..86315909c947e8da32b56eae71b5c413a1870409 100755 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/sdcard/sdcard_test.c +++ b/bk7235/liteos_m/bk_sdk_armino/middleware/driver/sdcard/sdcard_test.c @@ -1,3 +1,18 @@ +/* + * Copyright (C) 2022 Beken Corporation + * 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 #include "bk_arm_arch.h" diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/sdcard/sdcard_test.h b/bk7235/liteos_m/bk_sdk_armino/middleware/driver/sdcard/sdcard_test.h deleted file mode 100755 index 6432b7a31a2bccbbdff6461fea60f0173d8105f4..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/sdcard/sdcard_test.h +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef __SDCARD_TEST_H__ -#define __SDCARD_TEST_H__ - -UINT32 sdcard_intf_test(void); - -void sdcard_intf_close(void); - -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/sdcard/sdio_driver.c b/bk7235/liteos_m/bk_sdk_armino/middleware/driver/sdcard/sdio_driver.c index a130bf3bb2bcda98331d01a001b0e7a1f5c3cbcf..11c8e8e093c8f22712af015970317a65fce8e725 100644 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/sdcard/sdio_driver.c +++ b/bk7235/liteos_m/bk_sdk_armino/middleware/driver/sdcard/sdio_driver.c @@ -1,3 +1,18 @@ +/* + * Copyright (C) 2022 Beken Corporation + * 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 #include "bk_arm_arch.h" diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/sdcard/sdio_driver.h b/bk7235/liteos_m/bk_sdk_armino/middleware/driver/sdcard/sdio_driver.h index 8f78ab8214fed9304bdf7aeda91bb7f2edec997e..d26f29bc2f3d44928bc354ac2b38c8e7421dabd2 100644 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/sdcard/sdio_driver.h +++ b/bk7235/liteos_m/bk_sdk_armino/middleware/driver/sdcard/sdio_driver.h @@ -1,3 +1,18 @@ +/* + * Copyright (C) 2022 Beken Corporation + * 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 __SDIO_DRIVER_H__ #define __SDIO_DRIVER_H__ diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/sdio/ReadMe.txt b/bk7235/liteos_m/bk_sdk_armino/middleware/driver/sdio/ReadMe.txt deleted file mode 100755 index cfafe4dab1e78cb71769009446c8f4fdb69692ad..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/sdio/ReadMe.txt +++ /dev/null @@ -1,5 +0,0 @@ -v1p0: -The SDIO v1 is used for BK7271 project. - -v2p0: -The SDIO v2 is used for BK7256 project. \ No newline at end of file diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/sdio/v1p0/sdio.c b/bk7235/liteos_m/bk_sdk_armino/middleware/driver/sdio/v1p0/sdio.c deleted file mode 100755 index 87c97135a9a51e295213ca534b4d562aa7ea9b7d..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/sdio/v1p0/sdio.c +++ /dev/null @@ -1,720 +0,0 @@ -#include -#include "bk_arm_arch.h" - -#include "bk_sdio.h" -#include "sdio.h" -#include "sutil.h" -#include "sdma_pub.h" -#include "bk_drv_model.h" -#include "bk_uart.h" -#include "bk_icu.h" -#include -//#include "co_math.h" -#include "bk_gpio.h" -#include "sdma.h" -//#include "mac.h" -#include"icu_driver.h" -#if CFG_WMM_PATCH -//#include "mm_timer.h" -//#include "ke_timer.h" -#endif - -#if CONFIG_SDIO || CONFIG_SDIO_TRANS -#if CONFIG_SDIO_BLOCK_512 -#include "sdio_intf.h" -UINT8 beken_tx_sdio_s = 1; -UINT8 da_hd_err = 0; -#endif -STATIC SDIO_S sdio; - -#ifdef SDIO_MEM_DEBUG -#define SDIO_MAGIC_TAIL_STR "\xAA\xBB\xCC\xDD\xEE\xFF" -#endif - -int sdio_ac_credits[AC_MAX]; - -STATIC const DD_OPERATIONS sdio_op = { - sdio_open, - sdio_close, - sdio_read, - sdio_write, - sdio_ctrl -}; - -SDIO_NODE_PTR sdio_alloc_valid_node(UINT32 buf_size) -{ - SDIO_NODE_PTR temp_node_ptr; - SDIO_NODE_PTR mem_node_ptr = 0; - - if (0 == buf_size) - goto av_exit; - -#ifdef SUPPORT_STM32 - buf_size = su_align_power2(buf_size); -#endif - - temp_node_ptr = su_pop_node(&sdio.free_nodes); - if (temp_node_ptr) { -#ifdef SDIO_PREALLOC - BK_ASSERT(buf_size <= 1600); - temp_node_ptr->addr = temp_node_ptr->orig_addr + CONFIG_MSDU_RESV_HEAD_LENGTH; - temp_node_ptr->length = buf_size; - mem_node_ptr = temp_node_ptr; -#else - UINT8 *buff_ptr = (UINT8 *)os_malloc(CONFIG_MSDU_RESV_HEAD_LENGTH + buf_size - + CONFIG_MSDU_RESV_TAIL_LEN - + MALLOC_MAGIC_LEN); - if (buff_ptr) { -#ifdef SDIO_MEM_DEBUG - if ((UINT32)buff_ptr > 0x00400020 + 262112) - BK_ASSERT(0); -#endif - //if(MALLOC_MAGIC_LEN) - //{ - //buff_ptr[(buf_size + MALLOC_MAGIC_LEN) - 1] = magic_byte0 ++; // MALLOC_MAGIC_BYTE0; - //} - - temp_node_ptr->orig_addr = buff_ptr; - temp_node_ptr->addr = (UINT8 *)((UINT32)buff_ptr + CONFIG_MSDU_RESV_HEAD_LENGTH); - temp_node_ptr->length = buf_size; - - temp_node_ptr->ac = -1; - mem_node_ptr = temp_node_ptr; - } else { - fatal_prf("alloc_null:%d\n", buf_size); - su_push_node(&sdio.free_nodes, temp_node_ptr); - } -#endif - } else - fatal_prf("*"); - -av_exit: - return mem_node_ptr; -} - - -void sdio_free_valid_node(SDIO_NODE_PTR node_ptr) -{ - //UINT8 *buff_ptr; - - //buff_ptr = node_ptr->addr; - if (MALLOC_MAGIC_LEN) { - //BK_ASSERT(buff_ptr[node_ptr->length + MALLOC_MAGIC_LEN - 1] == (magic_byte00 ++)/*MALLOC_MAGIC_BYTE0*/); - //buff_ptr[node_ptr->length + MALLOC_MAGIC_LEN - 1] = MALLOC_MAGIC_BYTE1; - //os_memset(node_ptr->addr, MALLOC_MAGIC_BYTE1, node_ptr->length + MALLOC_MAGIC_LEN - 1); - } - -#ifndef SDIO_PREALLOC - os_free(node_ptr->orig_addr); - node_ptr->orig_addr = 0; -#endif - node_ptr->addr = 0; - node_ptr->length = 0; - - su_push_node(&sdio.free_nodes, node_ptr); -} - -#define SDIO_PATCH -#ifdef SDIO_PATCH -static UINT8 null_data[8] = {0}; -#endif - -/* in IRQ */ -void sdio_cmd_handler(void *buf, UINT32 len) -{ - UINT32 count; - UINT32 txlen; - SDIO_PTR sdio_ptr; - SDIO_DCMD_PTR cmd_ptr; - SDIO_CMD_PTR reg_cmd_ptr; - SDIO_NODE_PTR mem_node_ptr = NULL; -#ifdef SDIO_MEM_DEBUG - int tnf = 0, rnf = 0; - UINT8 *end; -#endif - - BK_ASSERT(NULL != buf); - BK_ASSERT(buf == &sdio.cmd); - cmd_ptr = (SDIO_DCMD_PTR)buf; - reg_cmd_ptr = (SDIO_CMD_PTR)buf; - - //BK_LOG_RAW("C\n"); - - if (sdio_debug_level) { - int pl; - u8 *cbuf; - cbuf = buf; - - pl = len; - if (pl > 16) - pl = 16; - print_hex_dump("CMD: ", cbuf, pl); - } - - sdma_fake_stop_dma(); - - sdio_ptr = &sdio; - switch (cmd_ptr->op_code) { - - /* Host -> Target */ - case OPC_WR_DTCM : { -#ifdef SDIO_MEM_DEBUG - if (sdio_ptr->rx_len) { - BK_LOG_RAW("RnF\n"); - rnf = 1; - } -#endif - sdio_ptr->rx_len = cmd_ptr->data_len; - count = su_get_node_count(&sdio.rxing_list); -#ifdef SDIO_MEM_DEBUG - if (rnf) - os_printf("rc %d\n", count); -#endif - - if (count) { - mem_node_ptr = su_pop_node(&sdio.rxing_list); - /* Delete current node */ - sdio_free_valid_node(mem_node_ptr); - } - - mem_node_ptr = sdio_alloc_valid_node(cmd_ptr->data_len + 20/* dummy len*/); - - sdio_ptr->rc_len = 0; - sdio_ptr->rx_transaction_len = 0; - if (mem_node_ptr) { - sdio_ptr->next_seq = 0; - //sdio_ptr->rc_len = 0; - sdio_ptr->rx_status = RX_NODE_OK; - //BK_ASSERT(cmd_ptr->size == cmd_ptr->data_len); - sdio_ptr->rx_transaction_len = MIN(BLOCK_LEN - SDIO_TAIL_LEN, cmd_ptr->data_len); - - su_push_node(&sdio.rxing_list, mem_node_ptr); -#ifdef SDIO_MEM_DEBUG - end = mem_node_ptr->addr + cmd_ptr->data_len + SDIO_TAIL_LEN + 2; - os_memcpy(end, SDIO_MAGIC_TAIL_STR, 6); -#endif - sdio_ptr->rx_addr = (UINT32)mem_node_ptr->addr; - sdma_start_rx(mem_node_ptr->addr, sdio_ptr->rx_transaction_len); - } else - sdio_ptr->rx_status = RX_NO_NODE; - break; - } - - case OPC_RD_DTCM : { -#ifdef SDIO_MEM_DEBUG - if (sdio_ptr->tx_len) { - BK_LOG_RAW("TnF %d\n", sdio_ptr->tx_len); - tnf = 1; - } -#endif -#ifdef SDIO_PATCH - if (su_get_node_count(&sdio.tx_dat) == 0) - sdio_ctrl(SDIO_CMD_CLEAR_TX_VALID, 0); -#else - if (su_get_node_count(&sdio.tx_dat) <= 1) - sdio_ctrl(SDIO_CMD_CLEAR_TX_VALID, 0); -#endif - //sdio_ptr->tx_len = cmd_ptr->data_len; - - count = su_get_node_count(&sdio.txing_list); -#ifdef SDIO_MEM_DEBUG - if (tnf) - BK_LOG_RAW("tc %d\n", count); -#endif - - if (count >= 2) - SDIO_WPRT("txing_list:%d\n", count); - BK_ASSERT(count < 2); - - if (count) { - mem_node_ptr = su_pop_node(&sdio.txing_list); - sdio_free_valid_node(mem_node_ptr); - } - - mem_node_ptr = su_pop_node(&sdio.tx_dat); - - if (mem_node_ptr) { -#if CONFIG_SDIO_CREDITS - int ac = mem_node_ptr->ac; - if (ac >= 0) - sdio_ac_credits[ac]++; -#endif - - sdio_ptr->tc_len = 0; - sdio_ptr->tx_status = TX_NODE_OK; - //BK_LOG_RAW("l:%d/%d\n", sdio_ptr->tx_len, mem_node_ptr->length); - - //if (mem_node_ptr->length < sdio_ptr->tx_len) - sdio_ptr->tx_len = mem_node_ptr->length; - txlen = sdio_ptr->tx_len; - - sdio_ctrl(SDIO_CMD_SET_TX_LEN, &txlen); - - sdio_ptr->tx_transaction_len = MIN(BLOCK_LEN, txlen); - su_push_node(&sdio.txing_list, mem_node_ptr); - sdma_start_tx(mem_node_ptr->addr, sdio_ptr->tx_transaction_len); - } else { -#ifdef SDIO_PATCH - txlen = sizeof(null_data); - sdio_ctrl(SDIO_CMD_SET_TX_LEN, &txlen); - sdma_start_tx(null_data, sizeof(null_data)); -#endif - sdio_ptr->tx_status = TX_NO_NODE; - } - - break; - } - - case OPC_WR_REG : { - UINT8 reg_numb = (reg_cmd_ptr->len - 4) >> 3; - UINT8 i; - UINT32 reg_addr, reg_val; - for (i = 0; i < reg_numb; i++) { - reg_addr = reg_cmd_ptr->content[i]; - reg_val = reg_cmd_ptr->content[i + reg_numb]; - *((UINT32 *)reg_addr) = reg_val; - } - - break; - } - - case OPC_RD_REG : { - UINT8 reg_numb = (reg_cmd_ptr->len - 4) >> 2; - UINT8 i; - UINT32 reg_addr, reg_val[16]; - for (i = 0; i < reg_numb; i++) { - reg_addr = reg_cmd_ptr->content[i]; - reg_val[i] = *((UINT32 *)reg_addr); - } - - sdio_ptr->transaction_len = MIN(64, reg_numb << 2); - sdma_start_tx((UINT8 *)reg_val, sdio_ptr->transaction_len); - - break; - } - - default: { - SDIO_WPRT("Exceptional cmd of sdio\n"); - break; - } - } -} - - -void sdio_tx_cb(void) -{ - UINT32 remain; - SDIO_PTR sdio_ptr; - SDIO_NODE_PTR mem_node_ptr; - sdio_ptr = &sdio; - - //BK_LOG_RAW("T\n"); - mem_node_ptr = su_pop_node(&sdio.txing_list); - if (0 == mem_node_ptr && (TX_NO_NODE == sdio_ptr->tx_status)) { -#ifdef SDIO_MEM_DEBUG - UINT32 addr = REG_READ(REG_SDMA_ADDR); -#ifdef SDIO_PATCH - if (addr == (UINT32)null_data) - sdio_ptr->tx_len = 0; -#endif -#endif - SDIO_PRT("tx_cb_no_node\n"); - sdio_ptr->tx_status = TX_NODE_OK; - return; - } - - BK_ASSERT(mem_node_ptr); - sdio_ptr->tc_len += sdio_ptr->tx_transaction_len; - - if (sdio_ptr->tc_len >= mem_node_ptr->length) { - /* all data are sent */ - if (mem_node_ptr->callback) - (mem_node_ptr->callback)(mem_node_ptr->Lparam, mem_node_ptr->Rparam); - - mem_node_ptr->callback = NULLPTR; - mem_node_ptr->Lparam = NULL; - mem_node_ptr->Rparam = NULL; - sdma_fake_stop_dma(); - sdio_ptr->tx_len = 0; - - sdio_free_valid_node(mem_node_ptr); - } else { - remain = sdio_ptr->tx_len - sdio_ptr->tc_len; - sdio_ptr->tx_transaction_len = MIN(BLOCK_LEN, remain); - - su_push_node(&sdio.txing_list, mem_node_ptr); - sdma_start_tx(mem_node_ptr->addr + sdio_ptr->tc_len, sdio_ptr->tx_transaction_len); - } -} - - -/** - * SDMA has received packets. - * - * @count: SDIO/DMA receive data counter. - */ -void sdio_rx_cb(UINT32 count) -{ - UINT32 remain; - SDIO_PTR sdio_ptr; - SDIO_NODE_PTR mem_node_ptr; - struct stm32_frame_hdr *hdr; - sdio_ptr = &sdio; - UINT32 addr; -#ifdef SDIO_MEM_DEBUG - UINT8 *buf; -#endif - - mem_node_ptr = su_pop_node(&sdio.rxing_list); - if (!mem_node_ptr && sdio_ptr->rx_status == RX_NO_NODE) { - SDIO_WPRT("rx_cb_no_node\n"); - sdio_ptr->rx_status = RX_NODE_OK; - return; - } - - if (!mem_node_ptr) { - SDIO_WPRT("rx_no_nd %d\n", sdio_ptr->rc_len); - SDIO_WPRT("rxing_list:%d txing_list:%d\n", su_get_node_count(&sdio.rxing_list), - su_get_node_count(&sdio.txing_list)); - - sdio_ptr->rx_status = RX_NODE_OK; - return; - } - - if (unlikely(sdio_ptr->rc_len > 2000)) - BK_ASSERT(0); - - if (unlikely(sdio_ptr->rx_transaction_len > 512)) - BK_ASSERT(0); - - addr = REG_READ(REG_SDMA_ADDR); - - if (unlikely(sdio_ptr->rx_addr != addr)) { - BK_LOG_RAW("rx_addr 0x%x, tx_addr 0x%x, hw addr 0x%x\n", - sdio_ptr->rx_addr, sdio_ptr->tx_addr, addr); - BK_ASSERT(0); - } - - /* check data */ - hdr = (struct stm32_frame_hdr *)(mem_node_ptr->addr + sdio_ptr->rc_len + sdio_ptr->rx_transaction_len); - if (unlikely(hdr->seq != sdio_ptr->next_seq)) { - BK_LOG_RAW("se %d %d\n", hdr->seq, sdio_ptr->next_seq); - return; - } - if (unlikely(hdr->type != 0xAB)) { - BK_LOG_RAW("te\n"); - return; - } - if (unlikely(hdr->len != sdio_ptr->rx_transaction_len)) { - BK_LOG_RAW("le %d %d\n", hdr->len, sdio_ptr->rx_transaction_len); - return; - } - - sdio_ptr->next_seq++; - - //sdio_ptr->rc_len += count; count is function 1's data len - sdio_ptr->rc_len += sdio_ptr->rx_transaction_len; - if (unlikely(sdio_ptr->rc_len > 2000)) - BK_ASSERT(0); - -#if 0 - if (hdr->remain > sdio_ptr->rx_len - sdio_ptr->rc_len) { - BK_LOG_RAW("ex: %d %d\n", hdr->remain > sdio_ptr->rx_len, sdio_ptr->rc_len); - return; - } -#endif - - if (sdio_ptr->rc_len >= sdio_ptr->rx_len) { -#ifdef SDIO_MEM_DEBUG - buf = mem_node_ptr->addr + sdio_ptr->rx_len + SDIO_TAIL_LEN + 2; - if (os_memcmp(buf, SDIO_MAGIC_TAIL_STR, 6)) { - BK_LOG_RAW("sdma corrupt memory\n"); - BK_ASSERT(0); - } - os_memcpy(buf, "\xEE\xEE\xEE\xEE", 4); - buf += 4; - REG_PL_WR(buf, mem_node_ptr); - //buf += 4; - //REG_PL_WR(buf, mem_node_ptr->addr); - buf += 4; - REG_PL_WR(buf, sdio_ptr->rx_len); - buf += 4; - REG_PL_WR(buf, sdio_ptr->rc_len); - //buf += 4; - //REG_PL_WR(buf, sdio_ptr->rx_transaction_len); - mm_magic_match(mem_node_ptr->orig_addr); -#endif - - su_push_node(&sdio.rx_dat, mem_node_ptr); - if (sdio_ptr->rx_cb) - (sdio_ptr->rx_cb)(); - sdma_fake_stop_dma(); - - sdio_ptr->rx_len = 0; - sdio_ptr->rx_addr = 0; - } else { - remain = sdio_ptr->rx_len - sdio_ptr->rc_len; - sdio_ptr->rx_transaction_len = MIN(BLOCK_LEN - SDIO_TAIL_LEN, remain); - su_push_node(&sdio.rxing_list, mem_node_ptr); - sdio_ptr->rx_addr = (UINT32)(mem_node_ptr->addr + sdio_ptr->rc_len); - sdma_start_rx(mem_node_ptr->addr + sdio_ptr->rc_len, sdio_ptr->rx_transaction_len); - } -} - -void sdio_register_rx_cb(FUNCPTR func) -{ - sdio.rx_cb = func; // sdio_rxed_trigger_evt -} - -static void sdio_intfer_gpio_config(void) -{ - UINT32 param; - - param = GFUNC_MODE_SD_DMA; - sddev_control(DD_DEV_TYPE_GPIO, CMD_GPIO_ENABLE_SECOND, ¶m); -} - -/**********************************************************************/ -void sdio_init(void) -{ - sdio_intfer_gpio_config(); - - os_memset(&sdio, 0, sizeof(sdio)); - - INIT_LIST_HEAD(&sdio.tx_dat); - INIT_LIST_HEAD(&sdio.rx_dat); - INIT_LIST_HEAD(&sdio.txing_list); - INIT_LIST_HEAD(&sdio.rxing_list); - - su_init(&sdio); - -#if CONFIG_SDIO_BLOCK_512 - sdio.rc_len = 0; - sdio.tc_len = 0; -#endif - sdma_register_handler(sdio_tx_cb, sdio_rx_cb, sdio_cmd_handler); - sdma_init(); - - ddev_register_dev(DD_DEV_TYPE_SDIO, (DD_OPERATIONS *)&sdio_op); - - //sdio.int_gpio = GPIO32; - sdio.int_gpio = GPIO24; - BkGpioInitialize(sdio.int_gpio, OUTPUT_NORMAL); - - sdio_ac_credits[AC_BK] = 8; - sdio_ac_credits[AC_BE] = 10; - sdio_ac_credits[AC_VI] = 12; - sdio_ac_credits[AC_VO] = 14; - - SDIO_PRT("sdio_init\n"); -} - - -void sdio_exit(void) -{ - BkGpioFinalize(sdio.int_gpio); - - sdma_uninit(); - - ddev_unregister_dev(DD_DEV_TYPE_SDIO); -} - -UINT32 sdio_open(UINT32 op_flag) -{ - UINT32 reg; - - sdma_open(); - sdma_start_cmd((UINT8 *)&sdio.cmd, sizeof(sdio.cmd)); - - reg = *((volatile UINT32 *)((0x00802000 + 16 * 4))); - if (reg & (1 << FIQ_SDIO_DMA)) { - //BK_ASSERT(0); - os_printf("already enabled sdio fiq\n"); - } - - icu_enable_sdio_dma_interrupt(); - - return SDIO_SUCCESS; -} - -UINT32 sdio_close(void) -{ - sdma_close(); - - return SDIO_SUCCESS; -} - -UINT32 sdio_read(char *user_buf, UINT32 count, UINT32 op_flag) -{ - UINT32 ret; - UINT32 len; - SDIO_NODE_PTR mem_node_ptr; - - ret = SDIO_FAILURE; - if (H2S_RD_SYNC == op_flag) { - if (!user_buf || !count) - goto rd_exit; - - mem_node_ptr = su_pop_node(&sdio.rx_dat); - if (mem_node_ptr) { - len = MIN(count, mem_node_ptr->length); - os_memcpy(user_buf, mem_node_ptr->addr, len); - ret = mem_node_ptr->length; - - sdio_free_valid_node(mem_node_ptr); - } else - ret = SDIO_FAILURE; - } else if (H2S_RD_SPECIAL == op_flag) { - mem_node_ptr = su_pop_node(&sdio.rx_dat); - if (mem_node_ptr) { - mem_node_ptr->Lparam = &sdio.free_nodes; - mem_node_ptr->Rparam = mem_node_ptr; - - ret = (UINT32)mem_node_ptr; - } else - ret = SDIO_FAILURE; - } - -rd_exit: - return ret; -} - -static void sdio_set_interrupt_host() -{ - BkGpioOutputHigh(sdio.int_gpio); -} - -static void sdio_clear_interrupt_host() -{ - BkGpioOutputLow(sdio.int_gpio); -} - -UINT32 sdio_write(char *user_buf, UINT32 count, UINT32 op_flag) -{ - UINT32 ret; - SDIO_NODE_PTR mem_node_ptr; - - ret = SDIO_FAILURE; - - if (S2H_WR_SYNC == op_flag) { - if (!user_buf || !count) - goto exit_wr; - - mem_node_ptr = sdio_alloc_valid_node(count); - if (mem_node_ptr) { - //strcpy(mem_node_ptr->caller, "sdio_write"); - os_memcpy(mem_node_ptr->addr, user_buf, count); - //BK_LOG_RAW("%s %d: len %d\n", __func__, __LINE__, mem_node_ptr->length); - su_push_node(&sdio.tx_dat, mem_node_ptr); - sdio_ctrl(SDIO_CMD_SET_TX_VALID, 0); - - ret = SDIO_SUCCESS; - } else - ret = SDIO_FAILURE; - } else if (S2H_WR_SPECIAL == op_flag) { - if (!user_buf || !count) - goto exit_wr; - - mem_node_ptr = (SDIO_NODE_PTR)user_buf; - su_push_node(&sdio.tx_dat, mem_node_ptr); - sdio_ctrl(SDIO_CMD_SET_TX_VALID, 0); - - ret = SDIO_SUCCESS; - } - -exit_wr: - return ret; -} - - -UINT32 sdio_ctrl(UINT32 cmd, void *param) -{ - UINT32 ret; - SDIO_NODE_PTR mem_node_ptr; - - ret = SDIO_SUCCESS; - - switch (cmd) { - case SDIO_CMD_PUSH_FREE_NODE: - mem_node_ptr = (SDIO_NODE_PTR)param; - - sdio_free_valid_node(mem_node_ptr); - break; - - case SDIO_CMD_GET_FREE_NODE: { - struct get_free_node_param *_param = (struct get_free_node_param *)param; -#if CONFIG_SDIO_CREDITS - int ac = mac_tid2ac[_param->tid]; - int credits; - GLOBAL_INT_DECLARATION(); - - GLOBAL_INT_DISABLE(); - credits = sdio_ac_credits[ac]; - GLOBAL_INT_RESTORE(); - - if (credits <= 0) - mem_node_ptr = 0; - else { - mem_node_ptr = sdio_alloc_valid_node(_param->size); - if (mem_node_ptr) { - mem_node_ptr->ac = ac; - GLOBAL_INT_DISABLE(); - sdio_ac_credits[ac]--; - GLOBAL_INT_RESTORE(); - } - } -#else /* !CONFIG_SDIO_CREDITS */ - mem_node_ptr = sdio_alloc_valid_node(_param->size); -#endif -#if 0 - if (su_get_node_count(&sdio.tx_dat) > (CELL_COUNT >> 1)) - mem_node_ptr = NULL; - else - mem_node_ptr = sdio_alloc_valid_node(_param->size, _param->force); -#endif - //if (mem_node_ptr) - // strcpy(mem_node_ptr->caller, "rw"); - - ret = (UINT32)mem_node_ptr; - } - break; - - case SDIO_CMD_REG_RX_CALLBACK: - sdio_register_rx_cb((FUNCPTR)param); - break; - - case SDIO_CMD_GET_CNT_FREE_NODE: - *((UINT32 *)param) = su_get_node_count(&sdio.free_nodes); - break; - - case SDIO_CMD_CLEAR_TX_VALID: - sdma_clr_tx_valid(); - sdio_clear_interrupt_host(); - break; - - case SDIO_CMD_PEEK_S2H_COUNT: - ret = su_get_node_count(&sdio.tx_dat); - break; - - case SDIO_CMD_PEEK_H2S_COUNT: - ret = su_get_node_count(&sdio.rx_dat); - break; - - case SDIO_CMD_SET_TX_VALID: - sdma_set_tx_valid(); - sdio_set_interrupt_host(); - break; - - case SDIO_CMD_SET_TX_LEN: - sdma_set_tx_dat_count(*(UINT32 *)param); - break; - - default: - break; - } - - return ret; -} - -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/sdio/v1p0/sdio.h b/bk7235/liteos_m/bk_sdk_armino/middleware/driver/sdio/v1p0/sdio.h deleted file mode 100644 index 988871b0a78aa357b074f1554e2156f32b8033fd..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/sdio/v1p0/sdio.h +++ /dev/null @@ -1,167 +0,0 @@ -#ifndef _SDIO_H_ -#define _SDIO_H_ - -#include "bk_list.h" -//#include "rwnx_config.h" -#include "BkDriverGpio.h" - -#define SDIO_DEBUG -//#define SDIO_MEM_DEBUG - -#ifdef SDIO_DEBUG -#define SDIO_PRT os_printf -#define SDIO_WPRT os_printf -#define STATIC -#else -#define SDIO_PRT os_null_printf -#define SDIO_WPRT os_null_printf -#define STATIC static -#endif - -//#define SDIO_PREALLOC - -#ifdef SDIO_DEBUG -#define MALLOC_MAGIC_LEN (8) -#else -#define MALLOC_MAGIC_LEN (0) -#endif - -#define MALLOC_MAGIC_BYTE0 (0xAA) -#define MALLOC_MAGIC_BYTE1 (0xBB) - -/*CMD BUFFER space: 64bytes*/ -#define MAX_CONTENT_COUNT (15) - -#define DIR_TO_DTCM (0x55) -#define DIR_FROM_DTCM (0xAA) - -typedef struct _sdio_cmd { - UINT8 op_code; - UINT8 len; - UINT8 flag; - UINT8 status; - - UINT32 content[MAX_CONTENT_COUNT]; -} SDIO_CMD_S, *SDIO_CMD_PTR; - - -typedef struct _sdio_dcmd { - UINT8 op_code; - UINT8 cmd_len; - UINT8 flag; - UINT8 status; - - UINT16 data_len; /* Rd/Wr Data length */ - UINT16 reserve; - UINT32 content[MAX_CONTENT_COUNT - 1]; -} SDIO_DCMD_S, *SDIO_DCMD_PTR; - -#define RX_NODE_OK (0x1) -#define TX_NODE_OK (0x2) -#define RX_NO_NODE (0xA) -#define TX_NO_NODE (0xB) - -extern int sdio_ac_credits[]; - -struct wmm_fc { - int ac; - int per; /* 0-9*/ - uint32_t count; - uint32_t count_detect; - uint32_t dropped; -}; - -extern struct wmm_fc wmm_fc_tx[]; -extern struct wmm_fc wmm_fc_rx[]; -int wmm_fc_set(int tx, int ac, int per, int reset); -void dump_wmm_fc(); -void wmm_fc_reset(); -int wmm_fc_process(int tx, int ac); -void wmm_fc_set_reverse(); - - -typedef struct _sdio_entity_ { - UINT16 rx_status; - UINT16 tx_status; - UINT32 tc_len; - UINT32 rc_len; /* offset */ - UINT8 next_seq; - - /* @rx_len: host send multiple packets as one logical packet */ - UINT32 rx_len; - UINT32 rx_addr; - UINT32 tx_len; - UINT32 tx_addr; - - /* current transaction len, such as one CMD53 data len */ - UINT32 tx_transaction_len; - UINT32 rx_transaction_len; - UINT32 transaction_len; - - SDIO_NODE_T snode[64];//TODO fix CELL_COUNT - - LIST_HEADER_T tx_dat; /* tx list, not ready for tx */ - LIST_HEADER_T txing_list; /* for incomplete tx */ - - LIST_HEADER_T rx_dat; /* complete rx list */ - LIST_HEADER_T rxing_list; /* for incomplete rx */ - FUNCPTR rx_cb; - - LIST_HEADER_T free_nodes; - - SDIO_CMD_S cmd; - - bk_gpio_t int_gpio; -} SDIO_S, *SDIO_PTR; - -/* the same as _stm32_frame_hdr */ -struct stm32_frame_hdr { - UINT16 len; - UINT8 type; - UINT8 seq; -} __packed; - -#define SDIO_TAIL_LEN sizeof(struct stm32_frame_hdr) - -#define OPC_WR_REG (0xC5) -#define OPC_RD_REG (0x5C) -/* Host Write DTCM: Tx Command + Tx Data */ -#define OPC_WR_DTCM (0xE3) -/* Host Read DTCM: Tx Command + Rx Data */ -#define OPC_RD_DTCM (0x3E) - - -/*hardware access: sdio internal register*/ -#define SDIO_REG_CONFIG (0x10) -#define SDIO_CFG_BLK_MASK (0x07) -#define SDIO_CFG_BLK_POS (0) -#define SDIO_CFG_DATA_WIDTH_MASK (0x03) -#define SDIO_CFG_DATA_WIDTH_POS (4) - -#define SDIO_REG_RETRY_DIR (0x11) -#define RETRY_DIR_H2M (1 << 0) - -#define SDIO_REG_DATA_STOP (0x12) -#define DATA_STOP_RTX (1 << 0) - -#define SDIO_REG_PROG_PROTECT1 (0x13) -#define PROG_PROTECT_WORD1 (0xa5) - -#define SDIO_REG_PROG_PROTECT2 (0x14) -#define PROG_PROTECT_WORD2 (0xc3) - -#define SDIO_REG_SYS_CTRL (0x15) -#define SYS_CTRL_RESET (1 << 0) - - -/******************************************************************************* - * Function Declarations - *******************************************************************************/ -extern UINT32 sdio_open(UINT32 op_flag); -extern UINT32 sdio_close(void); -extern UINT32 sdio_read(char *user_buf, UINT32 count, UINT32 op_flag); -extern UINT32 sdio_write(char *user_buf, UINT32 count, UINT32 op_flag); -extern UINT32 sdio_ctrl(UINT32 cmd, void *parm); - -#endif // _SDIO_H_ - diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/sdio/v1p0/sdma.c b/bk7235/liteos_m/bk_sdk_armino/middleware/driver/sdio/v1p0/sdma.c deleted file mode 100644 index 7aeac47c2f8e965123b3533a335313272da5112a..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/sdio/v1p0/sdma.c +++ /dev/null @@ -1,286 +0,0 @@ -#include -#include "bk_arm_arch.h" - -#include "bk_uart.h" -#include "sdma_pub.h" -#include "sdma.h" - -#include -#include - -#if CONFIG_SDIO || CONFIG_SDIO_TRANS -TX_FUNC intr_tx_func = 0; -RX_FUNC intr_rx_func = 0; -CMD_FUNC intr_cmd_func = 0; - -UINT8 *cmd_buf = 0; - -volatile UINT32 cmd_data_dir = SDMA_DIR_IDLE; - -void sdma_init(void) -{ - UINT32 reg; - -#if CONFIG_REAL_SDIO - bk_int_isr_register(INT_SRC_SDIO_DMA, sdma_isr, NULL); -#endif - - reg = REG_READ(REG_SDMA_INTR_STATUS); - REG_WRITE(REG_SDMA_INTR_STATUS, reg); - sdma_clr_tx_valid(); -} - -void sdma_open(void) -{ - UINT32 reg; - - reg = SDMA_CONFIG_INTR_EN_TX - | SDMA_CONFIG_INTR_EN_RX - | SDMA_CONFIG_INTR_EN_CMD; - REG_WRITE(REG_SDMA_CONFIG, reg); -} - -void sdma_uninit(void) -{ -} - -void sdma_close(void) -{ - UINT32 reg; - - reg = REG_READ(REG_SDMA_CONFIG); - reg &= ~(SDMA_CONFIG_INTR_EN_TX - | SDMA_CONFIG_INTR_EN_RX - | SDMA_CONFIG_INTR_EN_CMD); - REG_WRITE(REG_SDMA_CONFIG, reg); -} - -#ifdef SDMA_INTERACT_WITH_HOST -UINT32 sdma_get_blk_len(void) -{ - UINT32 reg; - UINT32 power; - UINT32 blk_len; - - /* Rd Only */ - reg = REG_READ(REG_SDMA_INTERACTIVE_HOST); - power = (reg >> INTERACTIVE_BLK_LEN_POSI) & INTERACTIVE_BLK_LEN_MASK; - - blk_len = 2 << (power + 8); - - return blk_len; -} - -void sdma_set_tx_valid(void) -{ - UINT32 reg; - - reg = REG_READ(REG_SDMA_INTERACTIVE_HOST); - reg |= INTERACTIVE_RX_VALID_BIT; - REG_WRITE(REG_SDMA_INTERACTIVE_HOST, reg); -} - -void sdma_clr_tx_valid(void) -{ - UINT32 reg; - - reg = REG_READ(REG_SDMA_INTERACTIVE_HOST); - reg &= ~INTERACTIVE_RX_VALID_BIT; - REG_WRITE(REG_SDMA_INTERACTIVE_HOST, reg); -} - -void sdma_set_tx_dat_count(UINT32 val) -{ - UINT32 reg; - - reg = REG_READ(REG_SDMA_INTERACTIVE_HOST); - reg &= ~(INTERACTIVE_RX_COUNT_MASK << INTERACTIVE_RX_COUNT_POSI); - reg |= (val & INTERACTIVE_RX_COUNT_MASK) << INTERACTIVE_RX_COUNT_POSI; - REG_WRITE(REG_SDMA_INTERACTIVE_HOST, reg); -} -#endif // SDMA_INTERACT_WITH_HOST - -void sdma_register_handler(TX_FUNC tx_callback, - RX_FUNC rx_callback, - CMD_FUNC cmd_callback) -{ - if (tx_callback) - intr_tx_func = tx_callback; - - if (rx_callback) - intr_rx_func = rx_callback; - - if (cmd_callback) - intr_cmd_func = cmd_callback; - - return; -} - -UINT32 sdma_dma_start(UINT8 *buf, UINT32 len) -{ - UINT32 reg; - UINT32 addr; - - BK_ASSERT(len); - BK_ASSERT(buf); - - addr = (UINT32)buf; - - REG_WRITE(REG_SDMA_ADDR, addr); - - reg = REG_READ(REG_SDMA_CONFIG); - reg |= SDMA_CONFIG_ADDR_READY; - - REG_WRITE(REG_SDMA_CONFIG, reg); - - return 0; -} - -UINT32 sdma_start_tx(UINT8 *buf, UINT32 len) -{ - cmd_data_dir = SDMA_DIR_TX; - - return sdma_dma_start(buf, len); -} - -UINT32 sdma_start_rx(UINT8 *buf, UINT32 len) -{ - cmd_data_dir = SDMA_DIR_RX; - - return sdma_dma_start(buf, len); -} - -void sdma_fake_stop_dma(void) -{ - cmd_data_dir = SDMA_DIR_IDLE; -} - -UINT32 sdma_start_cmd(UINT8 *cmd, UINT32 len) -{ - UINT32 reg; - - if (len != CMD_BUF_MAX_LEN) - return SDMA_FAILURE; - - cmd_buf = cmd; - - /*startup dma*/ - reg = REG_READ(REG_SDMA_CONFIG); - if (reg & SDMA_CONFIG_ADDR_READY) - return SDMA_BUSY; - - reg |= SDMA_CONFIG_DMA_EN; - REG_WRITE(REG_SDMA_CONFIG, reg); - - return 0; -} - -void sdma_rd_cmd_content(void *buf, UINT32 len) -{ - UINT8 *src; - - if (len > CMD_BUF_MAX_LEN) { - warning_prf("cmd_len_exception:%d\r\n", len); - len = CMD_BUF_MAX_LEN; - } - - src = (UINT8 *)REG_SDMA_CMD_BA; - os_memcpy(buf, src, len); - - return; -} - -/* Target -> Host */ -void sdma_tx_isr_handler(UINT32 irq_status) -{ - if (irq_status & SDMA_INTR_TX_DATA_BIT) { - SDMA_PRT("sdma_tx\r\n"); - REG_WRITE(REG_SDMA_INTR_STATUS, SDMA_INTR_TX_DATA_BIT); - cmd_data_dir = SDMA_DIR_IDLE; - if (intr_tx_func) - (*intr_tx_func)(); - } -} - -/* Host -> Target */ -void sdma_rx_isr_handler(UINT32 irq_status) -{ - UINT32 rx_count; - - if (irq_status & SDMA_INTR_RX_DATA_BIT) { - SDMA_PRT("sdma_rx\r\n"); - REG_WRITE(REG_SDMA_INTR_STATUS, SDMA_INTR_RX_DATA_BIT); - - cmd_data_dir = SDMA_DIR_IDLE; - - if (intr_rx_func) { - rx_count = (REG_READ(REG_SDMA_COUNT)) & SDMA_COUNT_MASK; - (*intr_rx_func)(rx_count); - } - } -} - -void sdma_cmd_isr_handler(UINT32 irq_status) -{ - UINT32 rx_count; - - if (irq_status & SDMA_INTR_CMD_BIT) { - SDMA_PRT("sdma_cmd\r\n"); - - if (intr_cmd_func) { - rx_count = (REG_READ(REG_SDMA_COUNT)) & SDMA_COUNT_MASK; - - sdma_rd_cmd_content(cmd_buf, rx_count); - - (*intr_cmd_func)(cmd_buf, rx_count); - } - REG_WRITE(REG_SDMA_INTR_STATUS, SDMA_INTR_CMD_BIT); - } -} - -void sdma_isr(void) -{ - UINT32 irq_sta; - - /*0, get isr status*/ - irq_sta = REG_READ(REG_SDMA_INTR_STATUS); -#if 0 - BK_LOG_RAW("%c%c%c\n", irq_sta & SDMA_INTR_CMD_BIT ? 'C' : '-', - irq_sta & SDMA_INTR_RX_DATA_BIT ? 'R' : '-', - irq_sta & SDMA_INTR_TX_DATA_BIT ? 'T' : '-'); -#endif - -#if 0 // DON'T DELETE ME - /*1, handle isr branch*/ - if (SDMA_DIR_TX == cmd_data_dir) { - sdma_tx_isr_handler(irq_sta); - sdma_cmd_isr_handler(irq_sta); - sdma_rx_isr_handler(irq_sta); - } else if (SDMA_DIR_RX == cmd_data_dir) { - sdma_rx_isr_handler(irq_sta); - sdma_cmd_isr_handler(irq_sta); - sdma_tx_isr_handler(irq_sta); - } else { - sdma_cmd_isr_handler(irq_sta); - sdma_rx_isr_handler(irq_sta); - sdma_tx_isr_handler(irq_sta); - } -#else - sdma_rx_isr_handler(irq_sta); - sdma_tx_isr_handler(irq_sta); - - /* handle cmd last */ - sdma_cmd_isr_handler(irq_sta); -#endif - - if (!((irq_sta & SDMA_INTR_CMD_BIT) - || (irq_sta & SDMA_INTR_RX_DATA_BIT) - || (irq_sta & SDMA_INTR_TX_DATA_BIT))) - warning_prf("sdma:contrary to expectation:%x\r\n", irq_sta); - - return; -} - -#endif - -// EOF diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/sdio/v1p0/sdma.h b/bk7235/liteos_m/bk_sdk_armino/middleware/driver/sdio/v1p0/sdma.h deleted file mode 100644 index 88841f82a98a35f8d73cb9ce01527b0a4ed952a3..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/sdio/v1p0/sdma.h +++ /dev/null @@ -1,74 +0,0 @@ -#ifndef _SDMA_H_ -#define _SDMA_H_ - -#define SDMA_DEBUG - -#ifdef SDMA_DEBUG -#define SDMA_PRT os_printf -#else -#define SDMA_PRT os_null_printf -#define SDMA_WPRT warning_prf -#endif - -#define SDMA_DIR_IDLE (0) -#define SDMA_DIR_TX (1) -#define SDMA_DIR_RX (2) - -#define SDIO_DMA_BASE (0x00801000) - -#define REG_SDMA_RESERVE (SDIO_DMA_BASE + 00*4) - -#define REG_SDMA_CONFIG (SDIO_DMA_BASE + 01*4) -#define SDMA_CONFIG_DMA_EN (1 << 0) -#define SDMA_CONFIG_ADDR_READY (1 << 1) -#define SDMA_CONFIG_INTR_EN_TX (1 << 5) -#define SDMA_CONFIG_INTR_EN_RX (1 << 6) -#define SDMA_CONFIG_INTR_EN_CMD (1 << 7) - -#define REG_SDMA_ADDR (SDIO_DMA_BASE + 02*4) - -#define REG_SDMA_COUNT (SDIO_DMA_BASE + 03*4) -#define SDMA_COUNT_MASK (0xFFFF) - -#define REG_SDMA_CMD_BA (SDIO_DMA_BASE + 04*4) - -#define REG_SDMA_CMD_BUF0 (SDIO_DMA_BASE + 04*4) -#define REG_SDMA_CMD_BUF1 (SDIO_DMA_BASE + 05*4) -#define REG_SDMA_CMD_BUF2 (SDIO_DMA_BASE + 06*4) -#define REG_SDMA_CMD_BUF3 (SDIO_DMA_BASE + 07*4) -#define REG_SDMA_CMD_BUF4 (SDIO_DMA_BASE + 08*4) -#define REG_SDMA_CMD_BUF5 (SDIO_DMA_BASE + 09*4) -#define REG_SDMA_CMD_BUF6 (SDIO_DMA_BASE + 10*4) -#define REG_SDMA_CMD_BUF7 (SDIO_DMA_BASE + 11*4) -#define REG_SDMA_CMD_BUF8 (SDIO_DMA_BASE + 12*4) -#define REG_SDMA_CMD_BUF9 (SDIO_DMA_BASE + 13*4) -#define REG_SDMA_CMD_BUF10 (SDIO_DMA_BASE + 14*4) -#define REG_SDMA_CMD_BUF11 (SDIO_DMA_BASE + 15*4) -#define REG_SDMA_CMD_BUF12 (SDIO_DMA_BASE + 16*4) -#define REG_SDMA_CMD_BUF13 (SDIO_DMA_BASE + 17*4) -#define REG_SDMA_CMD_BUF14 (SDIO_DMA_BASE + 18*4) -#define REG_SDMA_CMD_BUF15 (SDIO_DMA_BASE + 19*4) - -#define REG_SDMA_INTR_STATUS (SDIO_DMA_BASE + 20*4) -/* Target -> Host */ -#define SDMA_INTR_TX_DATA_BIT (1 << 0) -/* Host -> Target */ -#define SDMA_INTR_RX_DATA_BIT (1 << 1) -/* Host -> Target */ -#define SDMA_INTR_CMD_BIT (1 << 2) - -#define REG_SDMA_INTERACTIVE_HOST (SDIO_DMA_BASE + 21*4) -#define INTERACTIVE_BLK_LEN_POSI (24) -#define INTERACTIVE_BLK_LEN_MASK (0x7) -#define INTERACTIVE_RX_VALID_BIT (1 << 23) -#define INTERACTIVE_RX_COUNT_POSI (0) -#define INTERACTIVE_RX_COUNT_MASK (0xFFFFF) - -/*sdm driver macro*/ -#define CMD_BUF_MAX_LEN (64) - -#define SDMA_BUSY ((UINT32)-2) -#define SDMA_FAILURE ((UINT32)-1) -#define SDMA_SUCCESS (0 - -#endif // _SDMA_H_ diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/sdio/v1p0/sdma_pub.h b/bk7235/liteos_m/bk_sdk_armino/middleware/driver/sdio/v1p0/sdma_pub.h deleted file mode 100644 index 803f9d7c0e4cc2574cfd3a14270f751546c09589..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/sdio/v1p0/sdma_pub.h +++ /dev/null @@ -1,38 +0,0 @@ -#ifndef _SDMA_PUB_H_ -#define _SDMA_PUB_H_ - -#define SDMA_INTERACT_WITH_HOST - -typedef void (*TX_FUNC)(void); -typedef void (*CMD_FUNC)(void *buf, UINT32 len); -typedef void (*RX_FUNC)(UINT32 count); - -/******************************************************************************* -* Function Declarations -*******************************************************************************/ -extern void sdma_init(void); - -extern void sdma_open(void); - -extern void sdma_uninit(void); - -extern void sdma_close(void); - -#ifdef SDMA_INTERACT_WITH_HOST -extern UINT32 sdma_get_blk_len(void); -extern void sdma_set_tx_valid(void); -extern void sdma_clr_tx_valid(void); -extern void sdma_set_tx_dat_count(UINT32 val); -#endif // SDMA_INTERACT_WITH_HOST - -extern void sdma_register_handler(TX_FUNC tx_callback, - RX_FUNC rx_callback, - CMD_FUNC cmd_callback); - -extern UINT32 sdma_start_rx(UINT8 *buf, UINT32 len); -extern UINT32 sdma_start_tx(UINT8 *buf, UINT32 len); - -extern UINT32 sdma_start_cmd(UINT8 *cmd, UINT32 len); -extern void sdma_fake_stop_dma(void); -extern void sdma_isr(void); -#endif // _SDMA_PUB_H_ diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/sdio/v1p0/sutil.c b/bk7235/liteos_m/bk_sdk_armino/middleware/driver/sdio/v1p0/sutil.c deleted file mode 100644 index 394c8c8ff033127a193420b2ee6f9510310cd1e9..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/sdio/v1p0/sutil.c +++ /dev/null @@ -1,110 +0,0 @@ -#include -#include "bk_arm_arch.h" - -#include "bk_uart.h" -#include "bk_sdio.h" -#include "sdio.h" -//#include "ll.h" -#include "sutil.h" -#include - -//#include "rwnx_config.h" - -#if CONFIG_SDIO || CONFIG_SDIO_TRANS -void su_init(SDIO_PTR sdio_ptr) -{ - UINT32 i; - SDIO_NODE_PTR node_ptr; - -#ifdef SDIO_PREALLOC - UINT8 *buff_ptr; - UINT32 buf_size = 1600; -#endif - - INIT_LIST_HEAD(&sdio_ptr->free_nodes); - - for (i = 0; i < CELL_COUNT; i ++) { - node_ptr = &sdio_ptr->snode[i]; - - node_ptr->callback = NULLPTR; - node_ptr->Lparam = NULL; - node_ptr->Rparam = NULL; - node_ptr->addr = 0; - node_ptr->node_list.next = NULLPTR; - node_ptr->node_list.prev = NULLPTR; - -#ifdef SDIO_PREALLOC - buff_ptr = (UINT8 *)os_malloc(CONFIG_MSDU_RESV_HEAD_LENGTH + buf_size - + CONFIG_MSDU_RESV_TAIL_LEN - + MALLOC_MAGIC_LEN); - BK_ASSERT(buff_ptr); - node_ptr->orig_addr = buff_ptr; -#endif - - su_push_node(&sdio_ptr->free_nodes, node_ptr); - } -} - -void su_push_node(LIST_HEADER_T *head, SDIO_NODE_PTR node) -{ - GLOBAL_INT_DECLARATION(); - - GLOBAL_INT_DISABLE(); - list_add_tail(&node->node_list, head); - GLOBAL_INT_RESTORE(); -} - -SDIO_NODE_PTR su_pop_node(LIST_HEADER_T *head) -{ - LIST_HEADER_T *tmp; - LIST_HEADER_T *pos; - SDIO_NODE_PTR node; - - GLOBAL_INT_DECLARATION(); - - GLOBAL_INT_DISABLE(); - - node = NULLPTR; - list_for_each_safe(pos, tmp, head) { - list_del(pos); - node = list_entry(pos, SDIO_NODE_T, node_list); - - break; - } - - GLOBAL_INT_RESTORE(); - - - return node; -} - -UINT32 su_get_node_count(LIST_HEADER_T *head) -{ - UINT32 count = 0; - LIST_HEADER_T *tmp; - LIST_HEADER_T *pos; - - GLOBAL_INT_DECLARATION(); - - GLOBAL_INT_DISABLE(); - list_for_each_safe(pos, tmp, head) { - count ++; - } - - - GLOBAL_INT_RESTORE(); - return count; -} - -UINT32 su_align_power2(UINT32 size) -{ - UINT32 i = 1; - - while (i < size) - i <<= 1; - - return i; -} -#endif -// EOF - diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/sdio/v1p0/sutil.h b/bk7235/liteos_m/bk_sdk_armino/middleware/driver/sdio/v1p0/sutil.h deleted file mode 100644 index 907e259dd049b65b197d603073e10e5031cea188..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/sdio/v1p0/sutil.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef _SDIO_UTIL_H_ -#define _SDIO_UTIL_H_ - -/******************************************************************************* -* Function Declarations -*******************************************************************************/ -extern void su_init(SDIO_PTR sdio_ptr); - -extern void su_push_node(LIST_HEADER_T *head, SDIO_NODE_PTR node); - -extern SDIO_NODE_PTR su_pop_node(LIST_HEADER_T *head); - -extern UINT32 su_get_node_count(LIST_HEADER_T *head); - -extern UINT32 su_align_power2(UINT32 size); - -#endif // _SDIO_UTIL_H_ diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/sdio/v2p0/sdio_slave_driver.c b/bk7235/liteos_m/bk_sdk_armino/middleware/driver/sdio/v2p0/sdio_slave_driver.c deleted file mode 100755 index a85881a560990546ec57e78a51417a3c8cce0b50..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/sdio/v2p0/sdio_slave_driver.c +++ /dev/null @@ -1,2000 +0,0 @@ -// Copyright 2022-2023 Beken -// -// 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 -#include "string.h" - -#include -#include -#include -#include "sys_driver.h" - -#include "bk_uart.h" -#include "bk_gpio.h" -#include - -#include "gpio_driver.h" -#if CONFIG_SDIO_GDMA_EN -#include "driver/dma.h" -#include -#endif - -#include "driver/sdio_types.h" -#include "sdio_hal.h" -#include "sdio_utils.h" -#include "sdio_slave_driver.h" - - -#if CONFIG_SDIO_V2P0 - -static sdio_driver_t s_sdio_driver; -static bool s_sdio_driver_is_init = false; -static beken_queue_t s_sdio_msg_que = NULL; -static beken_thread_t s_sdio_thread = NULL; - - -#define SDIO_RETURN_ON_NOT_INIT() do {\ - if (!s_sdio_driver_is_init) {\ - SDIO_LOG_ERR("driver not init\r\n");\ - return BK_ERR_SDIO_NOT_INIT;\ - }\ - } while(0) - -#define SDIO_RETURN_CHAN_ID(chan_id) do {\ - if (chan_id >= SDIO_CHAN_MAX_CNT) {\ - SDIO_LOG_ERR("chan id %d\r\n", chan_id);\ - return BK_ERR_SDIO_CHAN_ID_INVALID;\ - }\ - } while(0) - -#define SDIO_RETURN_CHAN_DIRECT(direct) do {\ - if (direct > SDIO_CHAN_RX) {\ - SDIO_LOG_ERR("direct %d\r\n", direct);\ - return BK_ERR_SDIO_DIRECT_INVALID;\ - }\ - } while(0) - - -#if CONFIG_SDIO_GDMA_EN -void sdio_slave_tx_finish(dma_id_t dma_id) -{ - -} - -static bk_err_t sdio_tx_dma_set_src_buf(uint8_t *psrc, uint32_t count) -{ - return bk_dma_set_src_addr(DMA_ID_5, (uint32_t)psrc, (uint32_t)(psrc+count)); - //BK_LOG_ON_ERR(bk_dma_set_transfer_len(DMA_ID_5, count)); -} - -static bk_err_t sdio_dma_tx_init(void) -{ - dma_config_t dma_config = {0}; - - SDIO_LOG_DEBUG_FUNCTION_ENTRY(); - - dma_config.mode = DMA_WORK_MODE_SINGLE; - dma_config.chan_prio = 0; - - dma_config.src.dev = DMA_DEV_DTCM; - dma_config.src.width = DMA_DATA_WIDTH_32BITS; - //dma_config.src.start_addr = (uint32) psrc; - //dma_config.src.end_addr = (uint32) psrc + count; - - dma_config.dst.dev = DMA_DEV_SDIO; - dma_config.dst.width = DMA_DATA_WIDTH_32BITS; - dma_config.dst.start_addr = (uint32_t) SDIO_REG0XB_ADDR; - dma_config.dst.end_addr = (uint32_t) SDIO_REG0XB_ADDR; - - BK_LOG_ON_ERR(bk_dma_init(DMA_ID_5, &dma_config)); - BK_LOG_ON_ERR(bk_dma_register_isr(DMA_ID_5, NULL, sdio_slave_tx_finish)); - BK_LOG_ON_ERR(bk_dma_enable_finish_interrupt(DMA_ID_5)); - - SDIO_LOG_DEBUG_FUNCTION_EXIT(); - - return BK_OK; -} - -void sdio_slave_rx_finish(dma_id_t dma_id) -{ - -} - -static bk_err_t sdio_rx_dma_set_dst_buf(uint8_t *pdst, uint32_t count) -{ - return bk_dma_set_dest_addr(DMA_ID_5, (uint32_t)pdst, (uint32_t)(pdst+count)); -} - -static bk_err_t sdio_dma_rx_init() -{ - dma_config_t dma_config = {0}; - - SDIO_LOG_DEBUG_FUNCTION_ENTRY(); - - dma_config.mode = DMA_WORK_MODE_SINGLE; - dma_config.chan_prio = 0; - - dma_config.src.dev = DMA_DEV_SDIO; - dma_config.src.width = DMA_DATA_WIDTH_32BITS; - dma_config.src.start_addr = (uint32) SDIO_REG0XC_ADDR; - dma_config.src.end_addr = (uint32) SDIO_REG0XC_ADDR; - - dma_config.dst.dev = DMA_DEV_DTCM; - dma_config.dst.width = DMA_DATA_WIDTH_32BITS; - //dma_config.dst.start_addr = (uint32) pbuf; - //dma_config.dst.end_addr = (uint32) pbuf + count; - - BK_LOG_ON_ERR(bk_dma_init(DMA_ID_5, &dma_config)); - //BK_LOG_ON_ERR(bk_dma_set_transfer_len(DMA_ID_5, count)); - BK_LOG_ON_ERR(bk_dma_register_isr(DMA_ID_5, NULL, sdio_slave_rx_finish)); - BK_LOG_ON_ERR(bk_dma_enable_finish_interrupt(DMA_ID_5)); - - SDIO_LOG_DEBUG_FUNCTION_EXIT(); - - return BK_OK; -} - -/* It doesn't config the SRC/DST address in APP's buffer */ -static bk_err_t sdio_dma_init() -{ - bk_err_t ret = BK_OK; - - //SDIO DMA TX init - sdio_dma_tx_init(); - - //SDIO DMA RX init - sdio_dma_rx_init(); - - return ret; -} - -static bk_err_t sdio_dma_deinit() -{ - //TODO: - bk_err_t ret = BK_OK; - return ret; -} - -#endif - -#if CONFIG_GPIO_NOTIFY_TRANSACTION_EN -static uint8_t gpio_to_host_num = GPIO_SDIO_NOTIFY_HOST, gpio_from_host_num = GPIO_SDIO_HOST_WAKEUP_SLAVE; -static volatile uint32_t allow_sleep = 1; //default:host whether allow ctrl sleep -static uint64_t last_rx_data_time = 0; -static wk_slp_fail_callback wk_host_fail_cb; -static beken_semaphore_t s_sdio_host_ack; - -void register_wake_host_fail_func(wk_slp_fail_callback cb) -{ - SDIO_LOG_DEBUG_FUNCTION_ENTRY(); - wk_host_fail_cb = cb; - SDIO_LOG_DEBUG_FUNCTION_EXIT(); -} - -static void sdio_wake_host_fail(void) //do nothing until now -{ - SDIO_LOG_DEBUG_FUNCTION_ENTRY(); - if(wk_host_fail_cb) - wk_host_fail_cb(); - SDIO_LOG_DEBUG_FUNCTION_EXIT(); -} - -static bk_err_t sdio_slave_tx_recv_host_ack_notification(void) -{ - bk_err_t ret = BK_OK; - - ret = rtos_set_semaphore(&s_sdio_host_ack); - if(ret != BK_OK) - { - SDIO_LOG_ERR("set sema"); - return ret; - } - - return ret; -} - -/** - * @brief Pullup GPIO to notify host, slave will send data. - * - * This API Pullup GPIO to notify host, slave will send data. - * - Pullup GPIO to notify host - * - Slave wait "host send CMD52 to get slave will transaction data length". - * If 100ms doesn't get CMD52 mean's host timeout. - * - * @attention 1. This API should be called after SDIO init. - * - * @return - * - BK_OK: succeed - * - others: other errors. - */ -bk_err_t sdio_slave_notify_host(void) -{ - bk_err_t ret = BK_OK; - - SDIO_LOG_DEBUG_FUNCTION_ENTRY(); - - if(WAKEUP_LEVEL) - bk_gpio_set_output_high(gpio_to_host_num); - else - bk_gpio_set_output_low(gpio_to_host_num); - - //wait here - ret = rtos_get_semaphore(&s_sdio_host_ack, WAIT_HOST_ACK_TIMEOUT); - if(ret != BK_OK) - { - SDIO_LOG_ERR("get sema"); - sdio_wake_host_fail(); - - //TODO: Assert? - return ret; - } - - //clear wake host - if(WAKEUP_LEVEL) - bk_gpio_set_output_low(gpio_to_host_num); - else - bk_gpio_set_output_high(gpio_to_host_num); - - SDIO_LOG_DEBUG_FUNCTION_EXIT(); - - return ret; -} - -static void sdio_gpio_notify_to_host_init(uint8_t gpio_num) -{ - SDIO_LOG_DEBUG_FUNCTION_ENTRY(); - gpio_to_host_num = gpio_num; - bk_gpio_enable_output(gpio_to_host_num); //output - bk_gpio_set_output_low(gpio_to_host_num); //to low, means allow peer side enter sleep. - SDIO_LOG_DEBUG_FUNCTION_EXIT(); -} - -static void sdio_gpio_notify_to_host_deinit(uint8_t gpio_num) -{ - SDIO_LOG_DEBUG_FUNCTION_ENTRY(); - - gpio_dev_unmap(gpio_num); - - SDIO_LOG_DEBUG_FUNCTION_EXIT(); -} - - -static void sdio_gpio_notify_from_host_init(uint8_t gpio_num) -{ - SDIO_LOG_DEBUG_FUNCTION_ENTRY(); - gpio_from_host_num = gpio_num; - bk_gpio_enable_input(gpio_from_host_num); - bk_gpio_pull_down(gpio_from_host_num); - - //maybe host pull up the gpio before controller finish bootup. - if(get_controller_wk_slp_status()) - { - bk_gpio_enable_interrupt(gpio_from_host_num); //default check high level - } - else - { - bk_gpio_disable_interrupt(gpio_from_host_num); //maybe host pull up the gpio before controller finish bootup. - } - - SDIO_LOG_DEBUG_FUNCTION_EXIT(); -} - -static void sdio_gpio_notify_from_host_deinit(uint8_t gpio_num) -{ - SDIO_LOG_DEBUG_FUNCTION_ENTRY(); - - gpio_dev_unmap(gpio_num); - bk_gpio_disable_interrupt(gpio_num); //default check high level - bk_gpio_register_isr(gpio_num, (gpio_isr_t)NULL); - - SDIO_LOG_DEBUG_FUNCTION_EXIT(); -} - -/** - * @brief Just update software allow sleep status, used to check gpio irq is - * whether sync with software status. - * - * This API .... - * - 1:means allow sleep, 0 means host vote bk7256 don't go to sleep. - * - * @attention 1. This API should be called after SDIO init. - * - * @return - * - BK_OK: succeed - * - others: other errors. - */ -static void set_controller_wk_slp_status(uint32_t allow_slp) -{ - SDIO_LOG_DEBUG("v=%d\r\n", allow_slp); - allow_sleep = allow_slp; -} - -/** - * @brief Get host whether allow slave goto sleep - * - * This API .... - * - * @attention 1. This API should be called after SDIO init. - * - * @return - * - 1:means allow sleep, 0 means host vote bk7256 don't go to sleep. - * - - */ -uint32_t get_controller_wk_slp_status(void) -{ - uint32_t cur_sts = bk_gpio_get_input(gpio_from_host_num); - - SDIO_LOG_DEBUG_FUNCTION_ENTRY("cur_sts=%d,allow_sleep=%d", cur_sts, allow_sleep); - - if(cur_sts) // !bk_gpio_get_input: it's optimized by compiler? the value maybe equal=0x100 - cur_sts = 0; - else - cur_sts = 1; - if(allow_sleep != cur_sts) - { - SDIO_LOG_DEBUG("cur_sts=%d,allow_sleep=%d", cur_sts, allow_sleep); - allow_sleep = cur_sts; - } - - return (allow_sleep); -} - -static void sdio_slave_response_host_wake_slave_ack(void) -{ - //do nothing now, no need to ack host - SDIO_LOG_DEBUG_FUNCTION_ENTRY(); -} - -static void sdio_slave_response_host_sleep_slave_ack(void) -{ - //do nothing now, no need to ack host - SDIO_LOG_DEBUG_FUNCTION_ENTRY(); -} - -/** - * @brief Host pull up/down GPIO to wakeup/clear wakeup slave. - * slave get the GPIO interrupt and run this handler. - * - * This API .... - * - * @attention 1. This API should be called after SDIO init. - * - * @return - * - - * - - */ -void wk_slp_controller_handler(void) -{ - uint32_t v27=bk_gpio_get_input(gpio_from_host_num); - - SDIO_LOG_DEBUG_FUNCTION_ENTRY(); - - { - if(v27) //now is high:check to low - { - SDIO_LOG_DEBUG("wakeup:low to high"); - set_controller_wk_slp_status(0); - set_last_receive_data_time(); //update wakeup time. - - sdio_slave_response_host_wake_slave_ack(); - - bk_gpio_enable_input(gpio_from_host_num); - bk_gpio_pull_up(gpio_from_host_num); - bk_gpio_disable_interrupt(gpio_from_host_num); - } - else - { - SDIO_LOG_DEBUG("sleep:high to low"); - set_controller_wk_slp_status(1); - //set_last_receive_data_time(); //update wakeup time. - - sdio_slave_response_host_sleep_slave_ack(); - bk_gpio_enable_input(gpio_from_host_num); - bk_gpio_pull_down(gpio_from_host_num); - bk_gpio_enable_interrupt(gpio_from_host_num); - } - } - - SDIO_LOG_DEBUG_FUNCTION_EXIT(); -} - -void set_last_receive_data_time(void) -{ - SDIO_LOG_DEBUG_FUNCTION_ENTRY(); - last_rx_data_time = bk_get_tick(); -} - -uint64_t get_last_receive_data_time(void) -{ - SDIO_LOG_DEBUG("last_time=%d", last_rx_data_time); - return last_rx_data_time; -} - -uint64_t check_wakeup_contorller_validity_timeout(void) -{ - uint8_t timeout; - - //LOG_D(GWS, "%s[+],last_time=%d\r\n", __func__, last_rx_data_time); - if(get_controller_wk_slp_status() == 0) - { - timeout = (bk_get_tick() > (last_rx_data_time + FORBID_SLEEP_TIMEOUT) ? 1 : 0); - if(timeout) - { - #define PRINT_INTERAL_TIME 10 - static uint64_t last_print_time = 0; - - if(bk_get_tick() - last_print_time > PRINT_INTERAL_TIME) - SDIO_LOG_ERR("cur_time=%d,last_time=%d", __func__, bk_get_tick(), last_rx_data_time); - last_print_time = bk_get_tick(); - } - } - - return (bk_get_tick() - last_rx_data_time); -} - -/** - * @brief wake,allow sleep by gpio feature resources init - * - * This API .... - * - * @param to_host: the gpio num which is used to wake up host or allow host sleep. - * @param from_host: the gpio num which is used to wake up controller or allow controller sleep from host. - * - * - * @attention 1. This API should be called after SDIO init. - * - * @return - * - - * - - */ -void sdio_gpio_notify_transaction_init(uint8_t to_host, uint8_t from_host) -{ - SDIO_LOG_DEBUG_FUNCTION_ENTRY(); - - sdio_gpio_notify_to_host_init(to_host); - sdio_gpio_notify_from_host_init(from_host); - bk_gpio_register_isr(from_host, (gpio_isr_t)wk_slp_controller_handler); - - SDIO_LOG_DEBUG_FUNCTION_EXIT(); -} - -void sdio_gpio_notify_transaction_deinit(uint8_t to_host, uint8_t from_host) -{ - SDIO_LOG_DEBUG_FUNCTION_ENTRY(); - - sdio_gpio_notify_to_host_deinit(to_host); - sdio_gpio_notify_from_host_deinit(from_host); - - SDIO_LOG_DEBUG_FUNCTION_EXIT(); -} - -#endif //CONFIG_GPIO_NOTIFY_TRANSACTION_EN - -static void sdio_send_msg(sdio_msg_t *msg_p) -{ - bk_err_t ret; - - if (s_sdio_msg_que) { - ret = rtos_push_to_queue(&s_sdio_msg_que, msg_p, BEKEN_NO_WAIT); - if (kNoErr != ret) - SDIO_LOG_ERR("sdio send msg failed"); - } -} - -static bk_err_t sdio_gpio_init(void) -{ -#if CONFIG_SDIO_4LINES_EN - return gpio_sdio_sel(GPIO_SDIO_MAP_MODE0); -#else - return gpio_sdio_one_line_sel(GPIO_SDIO_MAP_MODE0); -#endif -} - -static bk_err_t sdio_gpio_deinit(void) -{ -#if CONFIG_SDIO_4LINES_EN - return gpio_sdio_sel(GPIO_SDIO_MAP_MODE0); -#else - return gpio_sdio_one_line_sel(GPIO_SDIO_MAP_MODE0); -#endif -} - -/** - * @brief sdio set controller clock. - * - * This API set the sdio clock as slave device. - * - 1.The sdio slave default clock is setted as 26M. - * 2.The transfer data clock on the lines is decided by host side, - * not this clock which is used for sdio-controller. - * - * @attention - * - * @return - * - BK_OK: succeed - * - others: other errors. - */ -bk_err_t bk_sdio_set_clk(SDIO_CLK_SEL_T sel, SDIO_CLK_DIV_T div) -{ - uint32_t int_level = 0; - - int_level = rtos_disable_int(); - - sys_driver_set_sdio_clk_sel((uint32_t)sel); - sys_driver_set_sdio_clk_div((uint32_t)div); - - rtos_enable_int(int_level); - return BK_OK; -} - -/** - * @brief Log out the SDIO REGs value without the "Data Read Reg(REG0xC)". - * - * This API log out SDIO REGs value without the "Data Read Reg(REG0xC)". - * - * @attention 1. This API doesn't log out the value of "Data Read Reg(REG0xC)", - * because if read REG0xC will cause FIFO data out. - * - * @return - * - None. - */ -void bk_sdio_driver_dump_sdio_regs(void) -{ - uint32_t reg_addr = 0; - - SDIO_LOG_DEBUG_FUNCTION_ENTRY(); - - for(reg_addr = SDIO_LL_REG_BASE; reg_addr < SDIO_LL_REG_END; reg_addr += 4) - { - if(reg_addr != SDIO_REG0XC_ADDR) //skip read data out. - { - SDIO_LOG_DUMP("Reg0x%x=0x%x\r\n", (reg_addr - SDIO_LL_REG_BASE)/4, *(volatile uint32_t *)reg_addr); - } - } - - SDIO_LOG_DEBUG_FUNCTION_EXIT(); -} - -#if CONFIG_SDIO_CHANNEL_EN - -/** - * @brief Push the data use finish link list to free list. - * - * This API Push the data use finish link list to free list. - * - Link the link list to free list. - * - - * - * @param chan_id The selected chan id. - * @param direct The channel used for TX data or RX data - * @param head_p The list head of which node will be to free list - * @param tail_p The list tail of which data will be to free list - * @param count How many nodes will be to free list - * - * @attention - * - * @return - * - BK_OK: succeed - * - others: other errors. - */ -bk_err_t bk_sdio_chan_push_free_list( - sdio_chan_id_t chan_id, - chan_direct_t direct, - sdio_node_ptr_t head_p, - sdio_node_ptr_t tail_p, - uint32_t count - ) -{ - bk_err_t ret = BK_OK; - uint32_t int_level = 0; -#if SDIO_BIDIRECT_CHANNEL_EN - uint32_t buf_index = direct; -#else - uint32_t buf_index = 0; -#endif - sdio_chan_buf_t *chan_buf_p = NULL; - - SDIO_RETURN_CHAN_ID(chan_id); - SDIO_RETURN_CHAN_DIRECT(direct); - - int_level = rtos_disable_int(); - - chan_buf_p = &s_sdio_driver.chan[chan_id].chan_buf[buf_index]; - sdio_list_push_list(&chan_buf_p->free_list, head_p, tail_p, count); - chan_buf_p->free_list.count += count; - - rtos_enable_int(int_level); - - return ret; -} - -/** - * @brief Pop a free node from the selected channel and direct. - * - * This API Pop a free node from the selected channel and direct. - * - Get a free node from the selected channel and direct. - * - Update the free node list to next node. - * - * @param chan_id The selected chan id. - * @param direct The channel used for TX data or RX data - * @param node_p Saved the getted free buffer node. - * @param size_p Saved the getted free buffer node capacity(How many bytes data can be saved). - * - * @attention - * - * @return - * - BK_OK: succeed - * - others: other errors. - */ -bk_err_t bk_sdio_chan_pop_free_node(sdio_chan_id_t chan_id, chan_direct_t direct, sdio_node_ptr_t *node_p, uint32_t *size_p) -{ - bk_err_t ret = BK_OK; - uint32_t int_level = 0; -#if SDIO_BIDIRECT_CHANNEL_EN - uint32_t buf_index = direct; -#else - uint32_t buf_index = 0; -#endif - sdio_chan_buf_t *chan_buf_p = NULL; - - SDIO_RETURN_CHAN_ID(chan_id); - SDIO_RETURN_CHAN_DIRECT(direct); - if(node_p == NULL) - { - SDIO_LOG_ERR("null pointer"); - return BK_ERR_SDIO_NULL_POINTER_PARAM; - } - - int_level = rtos_disable_int(); - chan_buf_p = &s_sdio_driver.chan[chan_id].chan_buf[buf_index]; - - if(chan_buf_p->free_list.count) - { - sdio_node_ptr_t tmp_node_p; - - ret = sdio_list_pop_node(&chan_buf_p->free_list, &tmp_node_p); - if(ret != BK_OK) - { - SDIO_LOG_ERR("no free buf"); - return BK_ERR_SDIO_NO_BUFFER; - } - *node_p = tmp_node_p; - *size_p = chan_buf_p->buf_size; - } - else - { - *size_p = 0; - *node_p = NULL; - SDIO_LOG_ERR("no free node"); - return BK_ERR_SDIO_NO_BUFFER; - } - - rtos_enable_int(int_level); - return BK_OK; -} - -void sdio_chan_push_ongoing_node( - sdio_chan_id_t chan_id, - chan_direct_t direct, - sdio_node_ptr_t head_p, - sdio_node_ptr_t tail_p, - uint32_t count - ) -{ - uint32_t int_level = 0; -#if SDIO_BIDIRECT_CHANNEL_EN - uint32_t buf_index = direct; -#else - uint32_t buf_index = 0; -#endif - sdio_chan_buf_t *chan_buf_p = NULL; - - //TODO: check chan_id and direct is whether valid - - int_level = rtos_disable_int(); - chan_buf_p = &s_sdio_driver.chan[chan_id].chan_buf[buf_index]; - - sdio_list_push_list(&chan_buf_p->ongoing_list, head_p, tail_p, count); - chan_buf_p->ongoing_list.count += count; - - rtos_enable_int(int_level); -} - -bk_err_t sdio_chan_pop_ongoing_node(sdio_chan_id_t chan_id, chan_direct_t direct, sdio_node_ptr_t *node_p) -{ - bk_err_t ret = BK_OK; - uint32_t int_level = 0; -#if SDIO_BIDIRECT_CHANNEL_EN - uint32_t buf_index = direct; -#else - uint32_t buf_index = 0; -#endif - sdio_chan_buf_t *chan_buf_p = NULL; - - SDIO_RETURN_CHAN_ID(chan_id); - SDIO_RETURN_CHAN_DIRECT(direct); - - int_level = rtos_disable_int(); - chan_buf_p = &s_sdio_driver.chan[chan_id].chan_buf[buf_index]; - if(chan_buf_p->ongoing_list.count) - { - sdio_node_ptr_t tmp_node_p; - ret = sdio_list_pop_node(&chan_buf_p->ongoing_list, &tmp_node_p); - if(ret != BK_OK) - { - SDIO_LOG_ERR("no transaction finish node"); - return BK_ERR_SDIO_NO_TRANSACTION_FINISH_NODE; - } - - *node_p = tmp_node_p; - } - else - { - rtos_enable_int(int_level); - return BK_FAIL; - } - - rtos_enable_int(int_level); - - return BK_OK; -} - -bk_err_t sdio_chan_push_finish_list( - sdio_chan_id_t chan_id, - chan_direct_t direct, - sdio_node_ptr_t head_p, - sdio_node_ptr_t tail_p, - uint32_t count - ) -{ - uint32_t int_level = 0; -#if SDIO_BIDIRECT_CHANNEL_EN - uint32_t buf_index = direct; -#else - uint32_t buf_index = 0; -#endif - sdio_chan_buf_t *chan_buf_p = NULL; - - SDIO_RETURN_CHAN_ID(chan_id); - SDIO_RETURN_CHAN_DIRECT(direct); - - int_level = rtos_disable_int(); - chan_buf_p = &s_sdio_driver.chan[chan_id].chan_buf[buf_index]; - - sdio_list_push_list(&chan_buf_p->finish_list, head_p, tail_p, count); - chan_buf_p->finish_list.count += count; - - rtos_enable_int(int_level); - - return BK_OK; -} - -bk_err_t sdio_chan_pop_finish_node(sdio_chan_id_t chan_id, chan_direct_t direct, sdio_node_ptr_t *node_p) -{ - bk_err_t ret = BK_OK; - uint32_t int_level = 0; -#if SDIO_BIDIRECT_CHANNEL_EN - uint32_t buf_index = direct; -#else - uint32_t buf_index = 0; -#endif - sdio_chan_buf_t *chan_buf_p = NULL; - - SDIO_RETURN_CHAN_ID(chan_id); - SDIO_RETURN_CHAN_DIRECT(direct); - - int_level = rtos_disable_int(); - chan_buf_p = &s_sdio_driver.chan[chan_id].chan_buf[buf_index]; - - if(chan_buf_p->finish_list.count) - { - sdio_node_ptr_t tmp_node_p; - ret = sdio_list_pop_node(&chan_buf_p->ongoing_list, &tmp_node_p); - if(ret != BK_OK) - { - SDIO_LOG_ERR("no free buf"); - return BK_ERR_SDIO_NO_BUFFER; - } - - *node_p = tmp_node_p; - } - - rtos_enable_int(int_level); - - return BK_OK; -} - -/** - * @brief Register the clalback function for sdio selected channel and direct. - * - * This API register the clalback function for sdio selected channel and direct. - * - Save the callback in channel. - * - When tx/rx data finish, it will call this callback function. - * - * @param chan_id The selected chan id. - * @param direct The channel used for TX data or RX data - * @param cb Registered callback function. - * - * @attention - * - * @return - * - BK_OK: succeed - * - others: other errors. - */ -bk_err_t bk_sdio_register_chan_cb(sdio_chan_id_t chan_id, chan_direct_t direct, sdio_chan_cb_t cb) -{ - uint32_t int_level = 0; -#if SDIO_BIDIRECT_CHANNEL_EN - uint32_t buf_index = direct; -#else - uint32_t buf_index = 0; -#endif - sdio_chan_buf_t *chan_buf_p = NULL; - - SDIO_RETURN_CHAN_ID(chan_id); - SDIO_RETURN_CHAN_DIRECT(direct); - - int_level = rtos_disable_int(); - chan_buf_p = &s_sdio_driver.chan[chan_id].chan_buf[buf_index]; - chan_buf_p->cb = cb; - - rtos_enable_int(int_level); - - return BK_OK; -} - -//should call sdio_chan_push_free_node after finish use -static bk_err_t sdio_chan_notify_cb(sdio_chan_id_t chan_id, chan_direct_t direct) -{ - bk_err_t ret = BK_OK; -#if SDIO_BIDIRECT_CHANNEL_EN - uint32_t buf_index = direct; -#else - uint32_t buf_index = 0; -#endif - sdio_chan_buf_t *chan_buf_p = &s_sdio_driver.chan[chan_id].chan_buf[buf_index]; - - if(chan_buf_p->cb) - { - chan_buf_p->cb(&chan_buf_p->finish_list.head, &chan_buf_p->finish_list.tail, chan_buf_p->finish_list.count); - } - - ret = rtos_set_semaphore(&chan_buf_p->semaphore); - if(ret != BK_OK) - { - SDIO_LOG_ERR("set sema"); - return ret; - } - - return ret; -} - -static bool sdio_chan_direct_is_inited(sdio_chan_id_t chan_id, chan_direct_t direct) -{ -#if SDIO_BIDIRECT_CHANNEL_EN - uint32_t buf_index = direct; -#else - uint32_t buf_index = 0; -#endif - - if((s_sdio_driver.chan[chan_id].tx_direct == (1<buf_cnt, chan_buf_p->buf_size); - goto err_exit; - } - -#if 0 //TODO:check whether needs it. - if(chan_buf_p->lock_p == NULL) - { - ret = rtos_init_mutex(&chan_buf_p->lock_p); - if (kNoErr != ret) - { - SDIO_LOG_ERR("mutex init"); - goto err_exit; - } - } -#endif - - if(count) - sema_count = count; - ret = rtos_init_semaphore(&chan_buf_p->semaphore, sema_count); - if (kNoErr != ret) - { - SDIO_LOG_ERR("semaphore init"); - goto err_exit; - } - - if(count) //driver support buffer - { - ret = sdio_list_init(count, size, &chan_buf_p->free_list.head, &chan_buf_p->free_list.tail); - if (BK_OK != ret) - { - SDIO_LOG_ERR("list init"); - goto err_exit; - } - } - - //save channel info - s_sdio_driver.chan[chan_id].chan_id = chan_id; - if(direct == SDIO_CHAN_TX) - s_sdio_driver.chan[chan_id].tx_direct = 1; - else - s_sdio_driver.chan[chan_id].rx_direct = 1; - - //save buf info - chan_buf_p->buf_cnt = count; - chan_buf_p->buf_size = size; - chan_buf_p->free_list.count = count; - chan_buf_p->transaction_len = 0; - - //add this to avoid modify err_exit involve issue. - rtos_enable_int(int_level); - return ret; - -err_exit: - rtos_enable_int(int_level); - return ret; -} - -/** - * @brief Deinit a sdio channel. - * - * This API deinit a sdio channel. - * - Init a single list for buffers - * - Create a mutex lock to protect concurrence operate link list - * - * @param chan_id The selected chan id. - * @param direct The channel used for TX data or RX data - * - * @attention - * - * @return - * - BK_OK: succeed - * - others: other errors. - */ -bk_err_t bk_sdio_deinit_channel(sdio_chan_id_t chan_id, chan_direct_t direct) -{ - bk_err_t ret = BK_OK; - uint32_t int_level = 0; -#if SDIO_BIDIRECT_CHANNEL_EN - uint32_t buf_index = direct; -#else - uint32_t buf_index = 0; -#endif - sdio_chan_buf_t *chan_buf_p = NULL; - - SDIO_RETURN_CHAN_ID(chan_id); - SDIO_RETURN_CHAN_DIRECT(direct); - - int_level = rtos_disable_int(); - - chan_buf_p = &s_sdio_driver.chan[chan_id].chan_buf[buf_index]; - if(sdio_chan_direct_is_inited(chan_id, direct) == false) - { - SDIO_LOG_INFO("chan%d,direct %d isn't inited", chan_id, direct); - goto err_exit; - } - - if(chan_buf_p->buf_cnt) //driver support buffer - { - ret = sdio_list_deinit(&chan_buf_p->free_list); - if (BK_OK != ret) - { - SDIO_LOG_ERR("list deinit"); - goto err_exit; - } - chan_buf_p->free_list.head = NULL; - - ret = sdio_list_deinit(&chan_buf_p->ongoing_list); - if (BK_OK != ret) - { - SDIO_LOG_ERR("list deinit"); - goto err_exit; - } - chan_buf_p->ongoing_list.head = NULL; - - ret = sdio_list_deinit(&chan_buf_p->finish_list); - if (BK_OK != ret) - { - SDIO_LOG_ERR("list deinit"); - goto err_exit; - } - chan_buf_p->finish_list.head = NULL; - } - - if(chan_buf_p->semaphore) - { - ret = rtos_deinit_semaphore(&chan_buf_p->semaphore); - if (kNoErr != ret) - { - SDIO_LOG_ERR("semaphore deinit"); - goto err_exit; - } - - chan_buf_p->semaphore = NULL; - } - -#if 0 //TODO:check whether needs it. - if(chan_buf_p->lock_p == NULL) - { - ret = rtos_deinit_mutex(&chan_buf_p->lock_p); - if (kNoErr != ret) - { - SDIO_LOG_ERR("mutex deinit"); - goto err_exit; - } - } -#endif - - //save channel info - s_sdio_driver.chan[chan_id].chan_id = SDIO_CHAN_MAX_CNT; - if(direct == SDIO_CHAN_TX) - s_sdio_driver.chan[chan_id].tx_direct = 0; - else - s_sdio_driver.chan[chan_id].rx_direct = 0; - - //save buf info - chan_buf_p->buf_cnt = 0; - chan_buf_p->buf_size = 0; - chan_buf_p->free_list.count = 0; - chan_buf_p->transaction_len = 0; - - //add this to avoid modify err_exit involve issue. - rtos_enable_int(int_level); - return ret; - -err_exit: - rtos_enable_int(int_level); - return ret; -} - -static bk_err_t sdio_slave_get_valid_ongoing_rx_buf_ptr(sdio_chan_id_t chan_id, uint32_t count, uint8_t **buf_p) -{ - bk_err_t ret = BK_OK; - uint32_t int_level = 0; - uint32_t left_size = 0; -#if SDIO_BIDIRECT_CHANNEL_EN - uint32_t buf_index = SDIO_CHAN_RX; -#else - uint32_t buf_index = 0; -#endif - sdio_chan_buf_t *chan_buf_p = NULL; - - SDIO_RETURN_CHAN_ID(chan_id); - - int_level = rtos_disable_int(); - chan_buf_p = &s_sdio_driver.chan[chan_id].chan_buf[buf_index]; - - if(count > chan_buf_p->buf_size) - { - //TODO:Assert - return BK_FAIL; - } - - //*trans_len_p = s_sdio_driver.chan[chan_id].chan_buf[buf_index].transaction_len; - left_size = chan_buf_p->buf_size - s_sdio_driver.chan[chan_id].chan_buf[buf_index].transaction_len; - if(left_size >= count) - { - *buf_p = (uint8_t *)chan_buf_p->ongoing_list.head + sizeof(sdio_node_t) + s_sdio_driver.chan[chan_id].chan_buf[buf_index].transaction_len; - } - else //current node left size isn't enough, save data to next node - { - sdio_node_ptr_t head_p = NULL; - - //pop out the buffer node from ongoing list - ret = sdio_chan_pop_ongoing_node(chan_id, SDIO_CHAN_RX, &head_p); - - //push current node to rx finish list - //here can't confirm this is one packet as maybe host packet size is large then slave node capacity. - sdio_chan_push_finish_list(chan_id, SDIO_CHAN_RX, head_p, NULL, 1); - - //get next valid node - s_sdio_driver.chan[chan_id].chan_buf[buf_index].transaction_len = 0; - *buf_p = (uint8_t *)chan_buf_p->ongoing_list.head + sizeof(sdio_node_t); - } - - rtos_enable_int(int_level); - - return ret; -} - -static bk_err_t sdio_slave_get_valid_ongoing_tx_buf_ptr(sdio_chan_id_t chan_id, uint32_t len, uint8_t **buf_p) -{ - bk_err_t ret = BK_OK; - uint32_t int_level = 0; - uint32_t left_size = 0; -#if SDIO_BIDIRECT_CHANNEL_EN - uint32_t buf_index = SDIO_CHAN_TX; -#else - uint32_t buf_index = 0; -#endif - sdio_chan_buf_t *chan_buf_p = NULL; - - SDIO_LOG_DEBUG_FUNCTION_ENTRY(); - - SDIO_RETURN_CHAN_ID(chan_id); - - int_level = rtos_disable_int(); - chan_buf_p = &s_sdio_driver.chan[chan_id].chan_buf[buf_index]; - left_size = chan_buf_p->ongoing_list.head->len - s_sdio_driver.chan[chan_id].chan_buf[buf_index].transaction_len; - if(left_size > 0) //current head node tx isn't finish - { - *buf_p = (uint8_t *)chan_buf_p->ongoing_list.head + sizeof(sdio_node_t) + s_sdio_driver.chan[chan_id].chan_buf[buf_index].transaction_len; - } - else //this packet finish, next packet - { - sdio_node_ptr_t head_p = NULL; - sdio_msg_t msg; - - //pop out the buffer node from ongoing list -#if CONFIG_SDIO_CHANNEL_EN - ret = sdio_chan_pop_ongoing_node(chan_id, SDIO_CHAN_TX, &head_p); - if(ret != BK_OK) - { - SDIO_LOG_ERR("pop node"); - rtos_enable_int(int_level); - return ret; - } - - //push to tx finish list - ret = sdio_chan_push_finish_list(chan_id, SDIO_CHAN_TX, head_p, NULL, 1); - if(ret != BK_OK) - { - SDIO_LOG_ERR("push lish"); - rtos_enable_int(int_level); - return ret; - } -#endif - //notify application can release buffer - msg.id = SDIO_WRITE_NODE_FINISH; - sdio_send_msg(&msg); - - //get next tx node - s_sdio_driver.chan[chan_id].chan_buf[buf_index].transaction_len = 0; - *buf_p = (uint8_t *)chan_buf_p->ongoing_list.head + sizeof(sdio_node_t); - } - - rtos_enable_int(int_level); - - SDIO_LOG_DEBUG_FUNCTION_EXIT(); - - return ret; -} - -static bk_err_t sdio_slave_add_ongoing_buf_trans_len(sdio_chan_id_t chan_id, chan_direct_t direct, uint32_t trans_len) -{ - bk_err_t ret = BK_OK; - uint32_t int_level = 0; -#if SDIO_BIDIRECT_CHANNEL_EN - uint32_t buf_index = direct; -#else - uint32_t buf_index = 0; -#endif - sdio_chan_buf_t *chan_buf_p = NULL; - - SDIO_RETURN_CHAN_ID(chan_id); - SDIO_RETURN_CHAN_DIRECT(direct); - - int_level = rtos_disable_int(); - - chan_buf_p = &s_sdio_driver.chan[chan_id].chan_buf[buf_index]; - chan_buf_p->transaction_len += trans_len; - rtos_enable_int(int_level); - - SDIO_LOG_DEBUG("chan_id=%d,tx/rx=%d,tarns_len=%d,total_len=%d", chan_id, direct, trans_len, chan_buf_p->transaction_len); - - return ret; -} - -#endif - -//WARNING:Becard 4bytes align issue -static bk_err_t sdio_slave_rx_fifo_to_buf(uint8_t *tar_addr_p, uint32_t count) -{ - //TODO:DMA not support until now. -#ifdef CONFIG_SDIO_GDMA_EN - sdio_rx_dma_set_dst_buf(tar_addr_p, count); - return bk_dma_start(DMA_ID_5); -#else //if not use GDMA, here will block IRQ too much time - uint32_t i, byte_cnt = count % 4, word_cnt = count/4; - uint8_t *cur_p = tar_addr_p; - - //read data from SDIO REG to buffer - for(i = 0; i < word_cnt; i = i + 4) - { - while(sdio_hal_get_read_ready() == 0) - { - - } - - *(uint32_t *)cur_p = sdio_hal_slave_read_data(); - cur_p += 4; - } - - if(byte_cnt) - { - while(sdio_hal_get_read_ready() == 0) - { - - } - - //though here write 4 bytes, but the buffer should not use this length if not align 4 bytes - *(uint32_t *)cur_p = sdio_hal_slave_read_data(); - } - -#endif - - return BK_OK; -} - -static bk_err_t sdio_slave_rx(uint32_t count) -{ - uint8_t *tar_addr_p = NULL; - //TODO: As SW doesn't check header chan_id, so here use default value. -#if CONFIG_SDIO_CHANNEL_EN - sdio_chan_id_t chan_id = SDIO_CHAN_PLATFORM; -#endif - //search current channel - //TODO:uses CHAN_ID_PLATFORM - - //get current channel rx ptr -#if CONFIG_SDIO_CHANNEL_EN - sdio_slave_get_valid_ongoing_rx_buf_ptr(chan_id, count, &tar_addr_p); -#endif - - //save data to rx buffer - if(tar_addr_p) - { - sdio_slave_rx_fifo_to_buf(tar_addr_p, count); - } - else - { - return BK_FAIL; - } - - //update rx transaction len -#if CONFIG_SDIO_CHANNEL_EN - sdio_slave_add_ongoing_buf_trans_len(chan_id, SDIO_CHAN_RX, count); -#endif - - return BK_OK; -} - -/** - * @brief SDIO sync read data from peer side(From Host) - * - * This API SDIO sync read data from peer side(From Host). - * - Push the read link list to rxing list, after finish read, it will run out, or blocked by sema. - * - - * @param chan_id The selected chan id. - * @param head_p The list head of which data will be save read data from peer side - * @param tail_p The list tail of which data will be save read data from peer side - * @param count How many nodes will be used to save data. - * - * @attention 1. - * - * @return - * - BK_OK: succeed - * - others: other errors. - */ -bk_err_t bk_sdio_slave_sync_read(sdio_chan_id_t chan_id, sdio_node_ptr_t head_p, sdio_node_ptr_t tail_p, uint32_t count) -{ - bk_err_t ret = BK_OK; - uint32_t int_level = 0; -#if SDIO_BIDIRECT_CHANNEL_EN - uint32_t buf_index = SDIO_CHAN_RX; -#else - uint32_t buf_index = 0; -#endif - sdio_chan_buf_t *chan_buf_p = NULL; - - SDIO_RETURN_CHAN_ID(chan_id); - - int_level = rtos_disable_int(); - chan_buf_p = &s_sdio_driver.chan[chan_id].chan_buf[buf_index]; - - ret = sdio_list_push_list(&chan_buf_p->ongoing_list, head_p, tail_p, count); - { - SDIO_LOG_ERR("push list"); - goto err_exit; - } - - chan_buf_p->ongoing_list.count += count; - - //CMD start - sdio_hal_slave_cmd_start(1); - - //TODO:wait read finish - ret = rtos_get_semaphore(&chan_buf_p->semaphore, BEKEN_WAIT_FOREVER); - if(ret != BK_OK) - { - SDIO_LOG_ERR("get sema"); - goto err_exit; - } - - //add this to avoid modify err_exit involve issue. - rtos_enable_int(int_level); - return ret; - -err_exit: - rtos_enable_int(int_level); - return ret; -} - -/** - * @brief - * - * This API . - * - - * - - * - * @attention 1. - * - * @return - * - BK_OK: succeed - * - others: other errors. - */ -bk_err_t sdio_slave_async_read(sdio_chan_id_t chan_id, sdio_node_ptr_t head_p, sdio_node_ptr_t tail_p, uint32_t count) -{ - bk_err_t ret = BK_OK; - - return ret; -} - -//WARNING:Becare 4bytes align issue -static bk_err_t sdio_slave_tx_buf_to_fifo(uint8_t *src_addr_p, uint32_t count) -{ - //TODO:DMA not support until now. -#ifdef CONFIG_SDIO_GDMA_EN - sdio_tx_dma_set_src_buf(src_addr_p, count); - return bk_dma_start(DMA_ID_5); -#else //if not use GDMA, here will block IRQ too much time - uint32_t i, byte_cnt = count % 4, word_cnt = count/4; - uint8_t *cur_p = src_addr_p; - - //read data from buffer to SDIO REG(SDIO FIFO) - for(i = 0; i < word_cnt; i = i + 4) - { - while(sdio_hal_get_write_ready() == 0) - { - - } - - sdio_hal_slave_write_data(*(uint32_t *)cur_p); - cur_p += 4; - } - - if(byte_cnt) - { - while(sdio_hal_get_write_ready() == 0) - { - - } - //though here write 4 bytes, but the buffer should not use this length if not align 4 bytes - sdio_hal_slave_write_data(*(uint32_t *)cur_p); - } - -#endif - - return BK_OK; -} - -static bk_err_t sdio_slave_tx(sdio_chan_id_t chan_id, uint32_t len) -{ - uint8_t *src_addr_p = NULL; - - //get current channel tx ptr -#if CONFIG_SDIO_CHANNEL_EN - sdio_slave_get_valid_ongoing_tx_buf_ptr(chan_id, len, &src_addr_p); -#endif - - //save data to tx fifo - if(src_addr_p) - { - sdio_slave_tx_buf_to_fifo(src_addr_p, len); - } - else - { - return BK_FAIL; - } - - //update tx transaction len -#if CONFIG_SDIO_CHANNEL_EN - sdio_slave_add_ongoing_buf_trans_len(chan_id, SDIO_CHAN_TX, len); -#endif - - return BK_OK; -} - -/** - * @brief SDIO sync write data to peer side(To Host) - * - * This API SDIO sync write data to peer side(To Host) . - * - Push the write link list to write list, after finish write, it will run out, or blocked by sema. - * - - * @param chan_id The selected chan id. - * @param head_p The list head of which data will be write - * @param tail_p The list tail of which data will be write - * @param count How many nodes will be write - * - * @attention 1. - * - * @return - * - BK_OK: succeed - * - others: other errors. - */ -bk_err_t bk_sdio_slave_sync_write(sdio_chan_id_t chan_id, sdio_node_ptr_t head_p, sdio_node_ptr_t tail_p, uint32_t count) -{ - bk_err_t ret = BK_OK; - uint32_t int_level = 0; -#if SDIO_BIDIRECT_CHANNEL_EN - uint32_t buf_index = SDIO_CHAN_TX; -#else - uint32_t buf_index = 0; -#endif - sdio_chan_buf_t *chan_buf_p = NULL; - - SDIO_RETURN_CHAN_ID(chan_id); - - int_level = rtos_disable_int(); - - chan_buf_p = &s_sdio_driver.chan[chan_id].chan_buf[buf_index]; - - ret = sdio_list_push_list(&chan_buf_p->ongoing_list, head_p, tail_p, count); - if(ret != BK_OK) - { - SDIO_LOG_ERR("push list fail"); - goto err_exit; - } - - //Slave set TX length, CMD start - //be care:maybe the sdio is transaction head node now. - sdio_hal_slave_set_tx_length(chan_buf_p->ongoing_list.head->len); - sdio_hal_slave_cmd_start(1); - - //Notify host:slave will send data -#if CONFIG_GPIO_NOTIFY_TRANSACTION_EN - sdio_slave_notify_host(); -#endif - - //TODO:wait write finish - ret = rtos_get_semaphore(&chan_buf_p->semaphore, BEKEN_WAIT_FOREVER); - if(ret != BK_OK) - { - SDIO_LOG_ERR("get sema"); - goto err_exit; - } - - //add this to avoid modify err_exit involve issue. - rtos_enable_int(int_level); - return ret; - -err_exit: - rtos_enable_int(int_level); - return ret; -} - - -/** - * @brief - * - * This API . - * - - * - - * - * @attention 1. - * - * @return - * - BK_OK: succeed - * - others: other errors. - */ -bk_err_t sdio_slave_async_write(sdio_chan_id_t chan_id, sdio_node_ptr_t head_p, sdio_node_ptr_t tail_p, uint32_t count) -{ - bk_err_t ret = BK_OK; - - return ret; -} - -static void sdio_thread(void *arg) -{ - bk_err_t ret; - - while(1) - { - sdio_msg_t msg; - ret = rtos_pop_from_queue(&s_sdio_msg_que, &msg, BEKEN_WAIT_FOREVER); - if (kNoErr == ret) - { - switch(msg.id) - { - case SDIO_READ_NODE_FINISH: - { -#if CONFIG_SDIO_CHANNEL_EN - sdio_chan_notify_cb(SDIO_CHAN_PLATFORM, SDIO_CHAN_RX); -#endif - break; - } - - case SDIO_WRITE_NODE_FINISH: - { -#if CONFIG_SDIO_CHANNEL_EN - sdio_chan_notify_cb(SDIO_CHAN_PLATFORM, SDIO_CHAN_TX); -#endif - break; - } - - //DMA INT notify - - default: - break; - } - } - } -} - -static bk_err_t sdio_sw_init(void) -{ - bk_err_t ret = BK_OK; - - ret = rtos_init_queue( - &s_sdio_msg_que, - SDIO_MSG_QUEUE_NAME, - sizeof(sdio_msg_t), - SDIO_MSG_QUEUE_COUNT - ); - if (kNoErr != ret) - { - SDIO_LOG_ERR("init queue ret=%d", ret); - goto err_exit; - } - - ret = rtos_create_thread( - &s_sdio_thread, - SDIO_THREAD_PRIORITY, - SDIO_THREAD_NAME, - sdio_thread, - SDIO_THREAD_STACK_SIZE, - NULL - ); - if (kNoErr != ret) - { - SDIO_LOG_ERR("init thread ret=%d", ret); - goto err_exit; - } - - //confirm to 0 as maybe crash value by other app. - memset(&s_sdio_driver, 0, sizeof(s_sdio_driver)); - SDIO_LOG_DEBUG("sizeof(s_sdio_driver)=%d", sizeof(s_sdio_driver)); - - //return, or err_exit release resources caused bug. - return ret; - -err_exit: - if(s_sdio_msg_que) - { - rtos_deinit_queue(&s_sdio_msg_que); - } - - if(s_sdio_thread) - { - rtos_delete_thread(&s_sdio_thread); - } - - return ret; -} - -static void sdio_slave_isr(void) -{ - uint32_t reg0x9_v = sdio_hal_get_int_status(); - uint8_t cmd_index = (reg0x9_v >> 14) & (0x3f); - //uint32_t cmd_arg0 = 0; - //uint32_t cmd_arg1 = 0; - - os_printf("SDIO enter interrupt Reg0x9=0x%x \r\n", reg0x9_v); - - //Slave response end int - if(sdio_hal_slave_get_cmd_response_end_int()) - { - switch (cmd_index) - { - case SDIO_CMD_INDEX_52: - { - uint32_t cmd52_arg0 = sdio_hal_slave_get_func_reg_value(); - - //host write func reg0 to 1, notify slave stop, which means one packet send finish. - if(((sdio_cmd52_func_arg0_t) cmd52_arg0).stop == 1) - { - sdio_msg_t msg; - -#if CONFIG_SDIO_CHANNEL_EN - sdio_node_ptr_t head_p = NULL; - //pop out the buffer node from ongoing list - //TODO:channel value is fixed. - sdio_chan_pop_ongoing_node(SDIO_CHAN_PLATFORM, SDIO_CHAN_RX, &head_p); - - //push to rx finish list - //TODO:channel value is fixed. - sdio_chan_push_finish_list(SDIO_CHAN_PLATFORM, SDIO_CHAN_RX, head_p, NULL, 1); -#endif - //notify data finish - msg.id = SDIO_READ_NODE_FINISH; - sdio_send_msg(&msg); - - //clear stop status - sdio_hal_slave_clear_stop(); - } - //host read:get slave tx length - { - //do nothing, just wait next cmd:cmd53 - -#if CONFIG_GPIO_NOTIFY_TRANSACTION_EN - //notify Slave that Host has response TX. - sdio_slave_tx_recv_host_ack_notification(); -#endif - } - break; - } - - case SDIO_CMD_INDEX_53: - { - uint32_t cmd53_arg = sdio_hal_slave_get_cmd_arg0(); - - if(((sdio_cmd53_arg_t)cmd53_arg).rw) //host read, slave write - { - //TODO:CHAN ID is fixed. - //save data to sdio fifo - sdio_slave_tx(SDIO_CHAN_PLATFORM, (uint32_t)((sdio_cmd53_arg_t)cmd53_arg).count); - //start transaction en, wait host read - sdio_hal_slave_tx_transaction_en(); - } - else //host write, slave read - { - //donothing, just wait next cmd - } - break; - } - - default: - break; - } - - sdio_hal_slave_clear_cmd_response_end_int(); //CMD_S_RES_END_INT - os_printf("CMD%d Respond end \r\n", cmd_index); - - sdio_hal_slave_cmd_start(1); //wait to receive next CMD. - - //TODO:need to check whether return. - //return; - } - - //slave rx full or finish data int - if(sdio_hal_slave_get_read_int_status()) - { - uint32_t cmd53_arg = sdio_hal_slave_get_cmd_arg0(); - uint32_t rx_cnt = ((sdio_cmd53_arg_t)cmd53_arg).count; - - //clear self int status - sdio_hal_slave_clear_read_int_status(); - - //save data from sdio to buffer - rx_cnt = sdio_hal_slave_get_rx_count(); - sdio_slave_rx(rx_cnt); - - //slave can receive data again - sdio_hal_slave_rx_clear_host_wait_write_data(); - - //allow host send next block - sdio_hal_slave_notify_host_next_block(); - - //TODO:need to check whether return. - //return; - } - -//TODO: -#if 0 - if(SDIO_REG0X9_ADDR & (1<<4)){ - SDIO_REG0X9_ADDR = (1<<4); //SD_DATA_WR_END_INT - os_printf("write end \r\n"); - s_write_end = 1; - } - - if(SDIO_REG0X9_ADDR & (1<<3)){ - SDIO_REG0X9_ADDR = (1<<3); //TX_FIFO_NEED_WRITE - } - - if(SDIO_REG0X9_ADDR & (1<<7)){ - SDIO_REG0X9_ADDR = (1<<7); //TX_FIFO_NEED_WRITE - } - - if(SDIO_REG0X9_ADDR & (1<<9)){ //TX_FIFO_EMPT - SDIO_REG0XA_ADDR &= ~(1<<9); //TX_FIFO_EMPT_MASK - } -#endif - -} - -static bk_err_t sdio_slave_hw_init(void) -{ - bk_err_t ret = BK_OK; - - sdio_hal_set_host_slave_mode(SDIO_SLAVE_MODE); - - sdio_hal_slave_set_samp_sel(1); - - //clock - sys_hal_set_sdio_clk_en(true); - sys_hal_set_sdio_clk_sel((uint32_t)SDIO_CLK_XTL); - sys_hal_set_sdio_clk_div((uint32_t)SDIO_CLK_DIV_1); - - //pin - ret = sdio_gpio_init(); - if(ret != BK_OK) - { - SDIO_LOG_ERR("gpio init"); - return ret; - } -#if CONFIG_GPIO_NOTIFY_TRANSACTION_EN - sdio_gpio_notify_transaction_init(GPIO_SDIO_NOTIFY_HOST, GPIO_SDIO_HOST_WAKEUP_SLAVE); -#endif - - //dma -#if CONFIG_SDIO_GDMA_EN - ret = sdio_dma_init(); - if(ret != BK_OK) - { - SDIO_LOG_ERR("dma init"); - return ret; - } -#endif - - //interrupt - bk_int_isr_register(INT_SRC_SDIO, sdio_slave_isr, NULL); -#if (defined CONFIG_DUAL_CORE && defined CONFIG_SLAVE_CORE) - sys_driver_set_cpu1_sdio_int_en(true); -#else - sys_driver_set_cpu0_sdio_int_en(true); -#endif - - return ret; -} - -/** - * @brief Init the sdio driver as slave device. - * - * This API init the sdio driver as slave device. - * - Init SDIO slave SW: Thread, Semaphore, Event. - * - Init SDIO slave HW: GPIO,CLOCK,DMA,IRQ ... - * - * @attention 1. This API should be called before any other SDIO SLAVE APIs. - * - * @return - * - BK_OK: succeed - * - others: other errors. - */ -bk_err_t bk_sdio_slave_driver_init(void) -{ - bk_err_t ret = BK_OK; - uint32_t int_level = 0; - - SDIO_LOG_DEBUG_FUNCTION_ENTRY(); - - int_level = rtos_disable_int(); - - if(s_sdio_driver_is_init) - { - rtos_enable_int(int_level); - SDIO_LOG_INFO("has inited"); - return BK_OK; - } - - ret = sdio_sw_init(); - if(ret != BK_OK) - { - SDIO_LOG_ERR("sw init fail"); - goto err_exit; - } - - ret = sdio_slave_hw_init(); - if(ret != BK_OK) - { - SDIO_LOG_ERR("sw init fail"); - goto err_exit; - } - - s_sdio_driver_is_init = true; - - bk_sdio_driver_dump_sdio_regs(); - - SDIO_LOG_DEBUG_FUNCTION_EXIT(); - - //add this to avoid modify err_exit involve issue. - rtos_enable_int(int_level); - return ret; - -err_exit: - rtos_enable_int(int_level); - return ret; -} - -static bk_err_t sdio_sw_deinit(void) -{ - bk_err_t ret = BK_OK; - - if(s_sdio_msg_que) - { - rtos_deinit_queue(&s_sdio_msg_que); - if (BK_OK != ret) - { - SDIO_LOG_ERR("deinit queue ret=%d", ret); - return ret; - } - - s_sdio_msg_que = NULL; - } - - if(s_sdio_thread) - { - ret = rtos_delete_thread(&s_sdio_thread); - if (BK_OK != ret) - { - SDIO_LOG_ERR("delete thread ret=%d", ret); - return ret; - } - - s_sdio_msg_que = NULL; - } - - return BK_OK; -} - -static bk_err_t sdio_hw_deinit(void) -{ - bk_err_t ret = BK_OK; - - sdio_hal_set_host_slave_mode(SDIO_HOST_MODE); - - //clock - sys_hal_set_sdio_clk_en(false); - sys_hal_set_sdio_clk_sel((uint32_t)SDIO_CLK_XTL); - sys_hal_set_sdio_clk_div((uint32_t)SDIO_CLK_DIV_1); - - //pin - ret = sdio_gpio_deinit(); - if(ret != BK_OK) - { - SDIO_LOG_ERR("gpio deinit"); - return ret; - } - - //TODO: -#if CONFIG_GPIO_NOTIFY_TRANSACTION_EN - sdio_gpio_notify_transaction_deinit(GPIO_SDIO_NOTIFY_HOST, GPIO_SDIO_HOST_WAKEUP_SLAVE); -#endif - - //dma -#if CONFIG_SDIO_GDMA_EN - ret = sdio_dma_deinit(); - if(ret != BK_OK) - { - SDIO_LOG_ERR("dma deinit"); - return ret; - } -#endif - - //interrupt - bk_int_isr_unregister(INT_SRC_SDIO); -#if (defined CONFIG_DUAL_CORE && defined CONFIG_SLAVE_CORE) - sys_driver_set_cpu1_sdio_int_en(false); -#else - sys_driver_set_cpu0_sdio_int_en(false); -#endif - - return ret; -} - - -/** - * @brief Deinit the sdio driver as slave device. - * - * This API deinit the sdio driver as slave device. - * - Deinit SDIO slave HW: GPIO,DMA,IRQ ... - * - Deinit SDIO slave SW: Thread, Queue... - * - * @attention 1. This API should be called after any other SDIO SLAVE APIs. - * - * @return - * - BK_OK: succeed - * - others: other errors. - */ -bk_err_t sdio_slave_driver_deinit(void) -{ - bk_err_t ret = BK_OK; - uint32_t int_level = 0; - - SDIO_LOG_DEBUG_FUNCTION_ENTRY(); - - int_level = rtos_disable_int(); - - ret = sdio_sw_deinit(); - if (BK_OK != ret) - { - SDIO_LOG_ERR("sw deinit ret=%d", ret); - rtos_enable_int(int_level); - return ret; - } - - ret = sdio_hw_deinit(); - if (BK_OK != ret) - { - SDIO_LOG_ERR("hw deinit ret=%d", ret); - rtos_enable_int(int_level); - return ret; - } - - bk_sdio_driver_dump_sdio_regs(); - - SDIO_LOG_DEBUG_FUNCTION_EXIT(); - - rtos_enable_int(int_level); - return ret; -} - -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/sdio/v2p0/sdio_slave_driver.h b/bk7235/liteos_m/bk_sdk_armino/middleware/driver/sdio/v2p0/sdio_slave_driver.h deleted file mode 100755 index 28e7d59adf70c7f291553c12c94e71d7532e0a56..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/sdio/v2p0/sdio_slave_driver.h +++ /dev/null @@ -1,528 +0,0 @@ -// Copyright 2022-2023 Beken -// -// 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 _SDIO_SLAVE_DRIVER_H_ -#define _SDIO_SLAVE_DRIVER_H_ - -#include -#include "bk_list.h" -#include "sdio_utils.h" - -//LOG's -typedef enum -{ - SDIO_LOG_DEBUG_LEVEL = 0, - SDIO_LOG_INFO_LEVEL, - SDIO_LOG_WARNING_LEVEL, - SDIO_LOG_ERR_LEVEL -}SDIO_LOG_LEVEL_T; - -#define SDIO_LOG_OUTPUT_LEVEL (SDIO_LOG_DEBUG_LEVEL) - -#define SDIO_LOG_ERR(...) {if(SDIO_LOG_OUTPUT_LEVEL <= SDIO_LOG_ERR_LEVEL) { \ - BK_LOG_RAW("SDIO Err(%s:%d) ", __FUNCTION__, __LINE__); \ - BK_LOG_RAW(__VA_ARGS__); \ - BK_LOG_RAW("\r\n"); \ -}} -#define SDIO_LOG_WARNING(...) {if(SDIO_LOG_OUTPUT_LEVEL <= SDIO_LOG_WARNING_LEVEL) { \ - BK_LOG_RAW("SDIO WARN"); \ - BK_LOG_RAW(__VA_ARGS__); \ - BK_LOG_RAW("\r\n"); \ -}} -#define SDIO_LOG_INFO(...) {if(SDIO_LOG_OUTPUT_LEVEL <= SDIO_LOG_INFO_LEVEL) { \ - BK_LOG_RAW("SDIO INFO"); \ - BK_LOG_RAW(__VA_ARGS__); \ - BK_LOG_RAW("\r\n"); \ -}} -#define SDIO_LOG_DEBUG(...) {if(SDIO_LOG_OUTPUT_LEVEL <= SDIO_LOG_DEBUG_LEVEL) { \ - BK_LOG_RAW("SDIO DBG"); \ - BK_LOG_RAW(__VA_ARGS__); \ - BK_LOG_RAW("\r\n"); \ -}} -#define SDIO_LOG_DUMP(...) {if(SDIO_LOG_OUTPUT_LEVEL <= SDIO_LOG_DEBUG_LEVEL) { \ - BK_LOG_RAW(__VA_ARGS__); \ - }} - -#define SDIO_LOG_DEBUG_FUNCTION_ENTRY(...) {if(SDIO_LOG_OUTPUT_LEVEL <= SDIO_LOG_DEBUG_LEVEL) { \ - BK_LOG_RAW("SDIO DEBUG(%s:Entry)\r\n", __FUNCTION__); \ -}} -#define SDIO_LOG_DEBUG_FUNCTION_EXIT(...) {if(SDIO_LOG_OUTPUT_LEVEL <= SDIO_LOG_DEBUG_LEVEL) { \ - BK_LOG_RAW("SDIO DEBUG(%s:Entry)\r\n", __FUNCTION__); \ -}} - - -#ifdef CONFIG_SDIO_DEBUG_EN -#define SDIO_DMA_DEBUG -#define SDIO_DEBUG -#endif - - -#define SDIO_THREAD_PRIORITY (2) -#define SDIO_THREAD_NAME "sdio_thread" -#define SDIO_THREAD_STACK_SIZE (0x4<<10) //Bytes - -#define SDIO_MSG_QUEUE_NAME "sdio_queue" -#define SDIO_MSG_QUEUE_COUNT (8) //Temp value,exact value should be tested out. -#define SDIO_CHAN_SEMAPHORE_COUNT (8) //default semaphore count if APP supports buffer - -#define SDIO_CMD_INDEX_52 (52) -#define SDIO_CMD_INDEX_53 (53) - -#define SDIO_MAX_BLOCK_SIZE (0x200) //512 bytes per round - -//#define SDIO_IS_CHAN_SUPPORT_BUF (0) //const value, dont change it - -typedef enum -{ - SDIO_CHAN_TX = 0, - SDIO_CHAN_RX, -}chan_direct_t; - -typedef enum -{ -#ifdef CONFIG_SDIO_CHANNEL_EN - SDIO_CHAN_PLATFORM, - SDIO_CHAN_WIFI, - SDIO_CHAN_MAX_CNT -#else - SDIO_CHAN_PLATFORM, - SDIO_CHAN_MAX_CNT -#endif -}sdio_chan_id_t; - -typedef enum -{ - //CTRL - SDIO_CHANNEL_INIT, - - //READ - //SDIO_READ_CYCLE_FINISH, //sdio block finish - SDIO_READ_NODE_FINISH, //the first node is finish/full - SDIO_MSG_SYNC_READ, - SDIO_MSG_ASYNC_READ, - - //WRITE - SDIO_WRITE_NODE_FINISH, - SDIO_MSG_SYNC_WRITE, - SDIO_MSG_ASYNC_WRITE - -}sdio_msg_id_t; - -typedef union -{ - struct - { - uint32_t stop : 8; //1:write, 0:read - uint32_t reserve : 24; //block/byte mode, how many blocks/bytes - }; - - uint32_t v; -}sdio_cmd52_func_arg0_t; - -typedef union -{ - struct - { - uint32_t rw : 1; //1:write, 0:read - uint32_t func_num : 3; - uint32_t block_mode : 1; //1:block mode, 0:byte mode - uint32_t op_mode : 1; //1:multi-byte read/write increase address, 0:fixed address - uint32_t addr : 17; - uint32_t count : 9; //block/byte mode, how many blocks/bytes - }; - - uint32_t v; -}sdio_cmd53_arg_t; - -typedef bk_err_t (*sdio_chan_cb_t)(sdio_node_ptr_t *head_p, sdio_node_ptr_t *tail_p, uint32_t count); - -typedef struct -{ - // - uint32_t buf_cnt; - uint32_t buf_size; - - //free list - sdio_list_t free_list; - - //txing/rxing list - sdio_list_t ongoing_list; - //As SDIO each cycle read/write <= 512Bytes, transaction_len record has read/write how many bytes data addr in buffer - uint32_t transaction_len; - - //tx/rx finish list - sdio_list_t finish_list; - - //notify app:callback - sdio_chan_cb_t cb; - void *semaphore; - void *lock_p; -}sdio_chan_buf_t; - -typedef struct -{ - uint32 tx_direct:1; //1:enable tx - uint32 rx_direct:1; - uint32 chan_id:6; - uint32 misc_reserve:24; - -#ifdef SDIO_BIDIRECT_CHANNEL_EN - sdio_chan_buf_t chan_buf[2]; //index 0:tx & index 1:rx -#else - sdio_chan_buf_t chan_buf[1]; //tx or rx -#endif -}sdio_chan_t; - -typedef struct -{ - sdio_chan_t chan[SDIO_CHAN_MAX_CNT]; - void *lock_p; -}sdio_driver_t; - -typedef struct { - uint32_t id; - uint32_t param; -} sdio_msg_t; - -//#define SDIO_MEM_DEBUG - -#ifdef SDIO_DEBUG -#define SDIO_PRT os_printf -#define SDIO_WPRT os_printf -#define STATIC -#else -#define SDIO_PRT os_null_printf -#define SDIO_WPRT os_null_printf -#define STATIC static -#endif - -//#define SDIO_PREALLOC - -#ifdef SDIO_DEBUG -#define MALLOC_MAGIC_LEN (8) -#else -#define MALLOC_MAGIC_LEN (0) -#endif - -#define MALLOC_MAGIC_BYTE0 (0xAA) -#define MALLOC_MAGIC_BYTE1 (0xBB) - -/*CMD BUFFER space: 64bytes*/ -#define MAX_CONTENT_COUNT (15) - - - -#if CONFIG_GPIO_NOTIFY_TRANSACTION_EN - -#define WAKEUP_LEVEL (1) -#define ALLOW_SLEEP_LEVEL (0) -#define FORBID_SLEEP_TIMEOUT (2000) -#define WAIT_HOST_ACK_TIMEOUT (100) -#define GPIO_SDIO_HOST_WAKEUP_SLAVE (GPIO_27) // == gpio_wk_receive_num -#define GPIO_SDIO_NOTIFY_HOST (GPIO_24) // == gpio_wk_send_num - -typedef void (*wk_slp_fail_callback)(void); - -void register_wake_host_fail_func(wk_slp_fail_callback cb); - -/** - * @brief Pullup GPIO to notify host, slave will send data. - * - * This API Pullup GPIO to notify host, slave will send data. - * - Pullup GPIO to notify host - * - Slave wait "host send CMD52 to get slave will transaction data length". - * If 100ms doesn't get CMD52 mean's host timeout. - * - * @attention 1. This API should be called after SDIO init. - * - * @return - * - BK_OK: succeed - * - others: other errors. - */ -bk_err_t sdio_slave_notify_host(void); - -/** - * @brief Get host whether allow slave goto sleep - * - * This API .... - * - * @attention 1. This API should be called after SDIO init. - * - * @return - * - 1:means allow sleep, 0 means host vote bk7256 don't go to sleep. - * - - */ -uint32_t get_controller_wk_slp_status(void); - -/** - * @brief Host pull up/down GPIO to wakeup/clear wakeup slave. - * slave get the GPIO interrupt and run this handler. - * - * This API .... - * - * @attention 1. This API should be called after SDIO init. - * - * @return - * - - * - - */ -void wk_slp_controller_handler(void); - -void set_last_receive_data_time(void); - -uint64_t get_last_receive_data_time(void); - -uint64_t check_wakeup_contorller_validity_timeout(void); - -/** - * @brief wake,allow sleep by gpio feature resources init - * - * This API .... - * - * @param to_host: the gpio num which is used to wake up host or allow host sleep. - * @param from_host: the gpio num which is used to wake up controller or allow controller sleep from host. - * - * - * @attention 1. This API should be called after SDIO init. - * - * @return - * - - * - - */ -void sdio_gpio_notify_transaction_init(uint8_t to_host, uint8_t from_host); - -void sdio_gpio_notify_transaction_deinit(uint8_t to_host, uint8_t from_host); - -#endif //CONFIG_GPIO_NOTIFY_TRANSACTION_EN - - -/** - * @brief Init the sdio driver as slave device. - * - * This API init the sdio driver as slave device. - * - Init SDIO slave HW: GPIO,CLOCK,DMA,IRQ ... - * - Init SDIO slave SW: Thread, Semaphore, Event. - * - * @attention 1. This API should be called before any other SDIO SLAVE APIs. - * - * @return - * - BK_OK: succeed - * - others: other errors. - */ -bk_err_t bk_sdio_slave_driver_init(void); - -/** - * @brief Init a sdio channel. - * - * This API init a sdio channel. - * - Init a single list for buffers - * - Create a mutex lock to protect concurrence operate link list - * @param chan_id The selected chan id. - * @param direct The channel used for TX data or RX data - * @param count How many buffers will be malloced. - * @param size Each buffer size for data which doesn't include SDIO header,it should be 4 bytes align - * - * @attention - * - * @return - * - BK_OK: succeed - * - others: other errors. - */ -bk_err_t bk_sdio_init_channel(sdio_chan_id_t chan_id, chan_direct_t direct, uint32_t count, uint32_t size); - -/** - * @brief Deinit a sdio channel. - * - * This API deinit a sdio channel. - * - Init a single list for buffers - * - Create a mutex lock to protect concurrence operate link list - * - * @param chan_id The selected chan id. - * @param direct The channel used for TX data or RX data - * - * @attention - * - * @return - * - BK_OK: succeed - * - others: other errors. - */ -bk_err_t bk_sdio_deinit_channel(sdio_chan_id_t chan_id, chan_direct_t direct); - -/** - * @brief Register the clalback function for sdio selected channel and direct. - * - * This API register the clalback function for sdio selected channel and direct. - * - Save the callback in channel. - * - When tx/rx data finish, it will call this callback function. - * - * @param chan_id The selected chan id. - * @param direct The channel used for TX data or RX data - * @param cb Registered callback function. - * - * @attention - * - * @return - * - BK_OK: succeed - * - others: other errors. - */ -bk_err_t bk_sdio_register_chan_cb(sdio_chan_id_t chan_id, chan_direct_t direct, sdio_chan_cb_t cb); - -bk_err_t bk_sdio_slave_sync_read(sdio_chan_id_t chan_id, sdio_node_ptr_t head_p, sdio_node_ptr_t tail_p, uint32_t count); - -/** - * @brief - * - * This API . - * - - * - - * - * @attention 1. - * - * @return - * - BK_OK: succeed - * - others: other errors. - */ -bk_err_t sdio_slave_async_read(sdio_chan_id_t chan_id, sdio_node_ptr_t head_p, sdio_node_ptr_t tail_p, uint32_t count); - -/** - * @brief - * - * This API . - * - - * - - * - * @attention 1. - * - * @return - * - BK_OK: succeed - * - others: other errors. - */ -bk_err_t bk_sdio_slave_sync_write(sdio_chan_id_t chan_id, sdio_node_ptr_t head_p, sdio_node_ptr_t tail_p, uint32_t count); - - -/** - * @brief - * - * This API . - * - - * - - * - * @attention 1. - * - * @return - * - BK_OK: succeed - * - others: other errors. - */ -bk_err_t sdio_slave_async_write(sdio_chan_id_t chan_id, sdio_node_ptr_t head_p, sdio_node_ptr_t tail_p, uint32_t count); - -/** - * @brief Push the data use finish link list to free list. - * - * This API Push the data use finish link list to free list. - * - Link the link list to free list. - * - - * - * @param chan_id The selected chan id. - * @param direct The channel used for TX data or RX data - * @param head_p The list head of which node will be to free list - * @param tail_p The list tail of which data will be to free list - * @param count How many nodes will be to free list - * - * @attention - * - * @return - * - BK_OK: succeed - * - others: other errors. - */ -bk_err_t bk_sdio_chan_push_free_list( - sdio_chan_id_t chan_id, - chan_direct_t direct, - sdio_node_ptr_t head_p, - sdio_node_ptr_t tail_p, - uint32_t count - ); - -/** - * @brief Pop a free node from the selected channel and direct. - * - * This API Pop a free node from the selected channel and direct. - * - Get a free node from the selected channel and direct. - * - Update the free node list to next node. - * - * @param chan_id The selected chan id. - * @param direct The channel used for TX data or RX data - * @param node_p Saved the getted free buffer node. - * @param size_p Saved the getted free buffer node capacity(How many bytes data can be saved). - * - * @attention - * - * @return - * - BK_OK: succeed - * - others: other errors. - */ -bk_err_t bk_sdio_chan_pop_free_node(sdio_chan_id_t chan_id, chan_direct_t direct, sdio_node_ptr_t *node_p, uint32_t *size_p); - -void sdio_chan_push_ongoing_node( - sdio_chan_id_t chan_id, - chan_direct_t direct, - sdio_node_ptr_t head_p, - sdio_node_ptr_t tail_p, - uint32_t count - ); - -bk_err_t sdio_chan_pop_ongoing_node(sdio_chan_id_t chan_id, chan_direct_t direct, sdio_node_ptr_t *head_p); - -bk_err_t sdio_chan_push_finish_list( - sdio_chan_id_t chan_id, - chan_direct_t direct, - sdio_node_ptr_t head_p, - sdio_node_ptr_t tail_p, - uint32_t count - ); - -bk_err_t sdio_chan_pop_finish_node(sdio_chan_id_t chan_id, chan_direct_t direct, sdio_node_ptr_t *node_p); - -/** - * @brief Log out the SDIO REGs value without the "Data Read Reg(REG0xC)". - * - * This API log out SDIO REGs value without the "Data Read Reg(REG0xC)". - * - * @attention 1. This API doesn't log out the value of "Data Read Reg(REG0xC)", - * because if read REG0xC will cause FIFO data out. - * - * @return - * - None. - */ -void bk_sdio_driver_dump_sdio_regs(void); - -/** - * @brief Deinit the sdio driver as slave device. - * - * This API deinit the sdio driver as slave device. - * - Deinit SDIO slave HW: GPIO,DMA,IRQ ... - * - Deinit SDIO slave SW: Thread, Queue... - * - * @attention 1. This API should be called after any other SDIO SLAVE APIs. - * - * @return - * - BK_OK: succeed - * - others: other errors. - */ -bk_err_t sdio_slave_driver_deinit(void); - - -#endif // _SDIO_H_ - diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/sdio/v2p0/sdio_test.c b/bk7235/liteos_m/bk_sdk_armino/middleware/driver/sdio/v2p0/sdio_test.c deleted file mode 100755 index 34180f8db81c33108ef5732dce74534098a62d56..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/sdio/v2p0/sdio_test.c +++ /dev/null @@ -1,499 +0,0 @@ -// Copyright 2022-2023 Beken -// -// 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 -#include "string.h" - -#include - -#include "bk_uart.h" - -#include "sdio_utils.h" -#include "sdio_slave_driver.h" -#include "sdio_test.h" - -#if CONFIG_SDIO_TEST_EN - -static bool s_sdio_test_inited = false; -static beken_queue_t s_sdio_test_msg_que = NULL; -static beken_thread_t s_test_sdio_thread = NULL; - -static volatile uint8_t s_sdio_test_main_case; -static volatile uint8_t s_sdio_test_sub_case; - -static bk_err_t sdio_test_tx_cb(sdio_node_ptr_t head_p, sdio_node_ptr_t tail_p, uint32_t count) -{ - bk_err_t ret = BK_OK; - sdio_node_ptr_t cur_p = head_p; - uint32_t i = count, j = 0; - - SDIO_LOG_DEBUG_FUNCTION_ENTRY(); - - //just check data - while(cur_p && i > 0) - { - for(j = 0; i < cur_p->len; j++) - { - os_printf("%x ", (uint8_t *)cur_p + (sizeof(sdio_node_t)) + i); - if(i % 16 == 0) - os_printf("\r\n"); - } - - cur_p = cur_p->next; - i--; - } - - //TODO:release buffer - //WARNING: Application should should use self CHAN_ID and CHAN_DIRECT. - bk_sdio_chan_push_free_list(SDIO_CHAN_PLATFORM, SDIO_CHAN_TX, head_p, tail_p, count); - - //notify app task finish read - - SDIO_LOG_DEBUG_FUNCTION_EXIT(); - return ret; -} - -static bk_err_t sdio_test_tx_init(uint32_t chan_id, uint32_t buf_cnt, uint32_t buf_size) -{ - bk_err_t ret = BK_OK; - - SDIO_LOG_DEBUG_FUNCTION_ENTRY(); - - ret = bk_sdio_init_channel(chan_id, SDIO_CHAN_TX, buf_cnt, buf_size); - if(ret != BK_OK) - { - SDIO_LOG_ERR("init channel"); - return ret; - } - bk_sdio_register_chan_cb(chan_id, SDIO_CHAN_TX, (sdio_chan_cb_t)sdio_test_tx_cb); - - SDIO_LOG_DEBUG_FUNCTION_EXIT(); - return ret; -} - -static bk_err_t sdio_test_tx_sub_case(SDIO_TEST_MSG_T *msg_p) -{ - bk_err_t ret = BK_OK; - - SDIO_LOG_DEBUG_FUNCTION_ENTRY(); - - switch(msg_p->sub_case) - { - //chan id, buf_cnt, buf_size - case SDIO_TEST_TX_INIT: - { - sdio_chan_id_t id = msg_p->param1; - uint32_t buf_cnt = msg_p->param2; - uint32_t buf_size = msg_p->param3; - - ret = sdio_test_tx_init(id, buf_cnt, buf_size); - break; - } - - //len, value - case SDIO_TEST_TX_SINGLE_PACKET: - { - sdio_node_ptr_t buf_p = NULL; - uint32_t len = msg_p->param1; - uint8_t value = (uint8_t)msg_p->param2; - uint32_t size; - - ret = bk_sdio_chan_pop_free_node(SDIO_CHAN_PLATFORM, SDIO_CHAN_TX, &buf_p, &size); - if(buf_p) - { - //fill data - if(len > size) - { - len = size; - SDIO_LOG_ERR("max packet size=%d, len=%d", size, len); - } - - memset((uint8_t *)buf_p + sizeof(sdio_node_t), value, len); - buf_p->len = len; - - //request write - ret = bk_sdio_slave_sync_write(SDIO_CHAN_PLATFORM, buf_p, NULL, 1); - } - else - { - SDIO_LOG_ERR("no free buff"); - ret = BK_FAIL; - } - - break; - } - - case SDIO_TEST_TX_MANY_SINGLE_PACKETS: - { - break; - } - - case SDIO_TEST_TX_MULTI_PACKETS: - { - break; - } - - default: - break; - } - - SDIO_LOG_DEBUG_FUNCTION_EXIT(); - - return ret; -} - -static bk_err_t sdio_test_rx_cb(sdio_node_ptr_t head_p, sdio_node_ptr_t tail_p, uint32_t count) -{ - bk_err_t ret = BK_OK; - sdio_node_ptr_t cur_p = head_p; - uint32_t i = count, j = 0; - - SDIO_LOG_DEBUG_FUNCTION_ENTRY(); - - //deal data - while(cur_p && i > 0) - { - for(j = 0; i < cur_p->len; j++) - { - os_printf("%x ", (uint8_t *)cur_p + (sizeof(sdio_node_t)) + i); - if(i % 16 == 0) - os_printf("\r\n"); - } - - cur_p = cur_p->next; - i--; - } - - //TODO:release buffer to free list mem-pool - //WARNING: Application should should use self CHAN_ID and CHAN_DIRECT. - ret = bk_sdio_chan_push_free_list(SDIO_CHAN_PLATFORM, SDIO_CHAN_RX, head_p, tail_p, count); - - SDIO_LOG_DEBUG_FUNCTION_EXIT(); - return ret; -} - -static bk_err_t sdio_test_rx_init(uint32_t chan_id, uint32_t buf_cnt, uint32_t buf_size) -{ - bk_err_t ret = BK_OK; - - SDIO_LOG_DEBUG_FUNCTION_ENTRY(); - - ret = bk_sdio_init_channel(chan_id, SDIO_CHAN_RX, buf_cnt, buf_size); - if(ret != BK_OK) - { - SDIO_LOG_ERR("init channel"); - return ret; - } - - ret = bk_sdio_register_chan_cb(chan_id, SDIO_CHAN_RX, (sdio_chan_cb_t)sdio_test_rx_cb); - - SDIO_LOG_DEBUG_FUNCTION_EXIT(); - return ret; -} - -static bk_err_t sdio_test_rx_sub_case(SDIO_TEST_MSG_T *msg_p) -{ - bk_err_t ret = BK_OK; - - SDIO_LOG_DEBUG_FUNCTION_ENTRY(); - - switch(msg_p->sub_case) - { - //chan id, buf_cnt, buf_size - case SDIO_TEST_RX_INIT: - { - sdio_chan_id_t id = msg_p->param1; - uint32_t buf_cnt = msg_p->param2; - uint32_t buf_size = msg_p->param3; - - ret = sdio_test_rx_init(id, buf_cnt, buf_size); - break; - } - - //len, value - case SDIO_TEST_RX_SINGLE_PACKET: - { - sdio_node_ptr_t buf_p; - uint32_t len = msg_p->param1; - uint8_t value = (uint8_t)msg_p->param2; - uint32_t size = 0; - - ret = bk_sdio_chan_pop_free_node(SDIO_CHAN_PLATFORM, SDIO_CHAN_RX, &buf_p, &size); - if(buf_p) - { - //fill dirty data - memset((uint8_t *)buf_p + sizeof(sdio_node_t), value, len); - buf_p->len = len; - - //request read - ret = bk_sdio_slave_sync_read(SDIO_CHAN_PLATFORM, buf_p, NULL, 1); - } - else - { - SDIO_LOG_ERR("no free buff"); - ret = BK_FAIL; - } - - break; - } - - case SDIO_TEST_RX_MANY_SINGLE_PACKETS: - { - break; - } - - case SDIO_TEST_RX_MULTI_PACKETS: - { - break; - } - - default: - break; - } - - SDIO_LOG_DEBUG_FUNCTION_EXIT(); - return ret; -} - -static bk_err_t sdio_test_send_msg(SDIO_TEST_MSG_T *msg_p) -{ - bk_err_t ret = BK_FAIL; - - SDIO_LOG_DEBUG_FUNCTION_ENTRY(); - - if (s_sdio_test_msg_que) - { - ret = rtos_push_to_queue(&s_sdio_test_msg_que, msg_p, BEKEN_NO_WAIT); - if (kNoErr != ret) - SDIO_LOG_ERR("sdio test send msg failed\r\n"); - } - - SDIO_LOG_DEBUG_FUNCTION_EXIT(); - return ret; -} - -/** - * @brief Set the sdio test case. - * - * This API set the sdio driver test case. - * - It will tested with the selected case. - * - Every case param has itself mean. - * - * @attention 1. This API should be called after sdio test inited. - * - * @return - * - BK_OK: succeed - * - others: other errors. - */ -bk_err_t bk_sdio_set_test_case( - uint8_t main_case, - uint8_t sub_case, - uint32_t param1, - uint32_t param2, - uint32_t param3, - uint32_t param4 - ) -{ - SDIO_TEST_MSG_T msg; - - if(main_case >= SDIO_TEST_MAX_MAIN_CASE) - { - SDIO_LOG_ERR("main case id %d is big then %d", main_case, SDIO_TEST_MAX_MAIN_CASE); - return BK_FAIL; - } - - msg.main_case = main_case; - msg.sub_case = sub_case; - msg.param1 = param1; - msg.param2 = param2; - msg.param3 = param3; - msg.param4 = param4; - - return sdio_test_send_msg(&msg); -} - -static void sdio_test_thread(void *arg) -{ - bk_err_t ret = BK_OK; - - SDIO_LOG_DEBUG_FUNCTION_ENTRY(); - - while(1) - { - SDIO_TEST_MSG_T msg; - - ret = rtos_pop_from_queue(&s_sdio_test_msg_que, &msg, BEKEN_WAIT_FOREVER); - if (kNoErr == ret) - { - // - switch(msg.main_case) - { - case SDIO_TEST_TX: - { - if(msg.sub_case >= SDIO_TEST_TX_MAX_SUB_CASE) - { - SDIO_LOG_ERR("sub case id %d is big then %d", msg.sub_case, SDIO_TEST_TX_MAX_SUB_CASE); - break; - } - - sdio_test_tx_sub_case(&msg); - break; - } - - case SDIO_TEST_RX: - { - if(msg.sub_case >= SDIO_TEST_RX_MAX_SUB_CASE) - { - SDIO_LOG_ERR("sub case id %d is big then %d", msg.sub_case, SDIO_TEST_RX_MAX_SUB_CASE); - break; - } - - sdio_test_rx_sub_case(&msg); - break; - } - - default: - break; - } - } - } - - SDIO_LOG_DEBUG_FUNCTION_EXIT(); - - //TODO: Assert -} - -/** - * @brief Init the sdio driver test program. - * - * This API init the sdio driver test program. - * - It will create a task do selected test case. - * - It can select test case by command line. - * - * @attention 1. This API should be called after sdio inited finish. - * - * @return - * - BK_OK: succeed - * - others: other errors. - */ -bk_err_t bk_sdio_test_init(void) -{ - bk_err_t ret = BK_OK; - - SDIO_LOG_DEBUG_FUNCTION_ENTRY(); - - if(s_sdio_test_inited) - { - SDIO_LOG_INFO("has inited"); - return ret; - } - - ret = rtos_init_queue( - &s_sdio_test_msg_que, - SDIO_TEST_MSG_QUEUE_NAME, - sizeof(SDIO_TEST_MSG_T), - SDIO_TEST_MSG_QUEUE_COUNT - ); - if (kNoErr != ret) - { - SDIO_LOG_ERR("init queue ret=%d", ret); - goto err_exit; - } - - ret = rtos_create_thread( - &s_test_sdio_thread, - SDIO_TEST_PRIORITY, - SDIO_TEST_THREAD_NAME, - sdio_test_thread, - SDIO_TEST_THREAD_STACK_SIZE, - NULL - ); - if (kNoErr != ret) - { - SDIO_LOG_ERR("init thread ret=%d", ret); - goto err_exit; - } - - s_sdio_test_inited = true; - - SDIO_LOG_DEBUG_FUNCTION_EXIT(); - - //return, or err_exit release resources caused bug. - return ret; - -err_exit: - if(s_sdio_test_msg_que) - { - rtos_deinit_queue(&s_sdio_test_msg_que); - s_sdio_test_msg_que = NULL; - } - - if(s_test_sdio_thread) - { - rtos_delete_thread(&s_test_sdio_thread); - s_test_sdio_thread = NULL; - } - - return ret; -} - -/** - * @brief Deinit the sdio driver test program. - * - * This API init the sdio driver test program. - * - It will delete the test thread and queue. - * - * @attention 1. This API should be called after sdio inited finish. - * - * @return - * - BK_OK: succeed - * - others: other errors. - */ -bk_err_t bk_sdio_test_deinit(void) -{ - bk_err_t ret = BK_OK; - - SDIO_LOG_DEBUG_FUNCTION_ENTRY(); - - if(s_sdio_test_msg_que) - { - ret = rtos_deinit_queue(&s_sdio_test_msg_que); - if (BK_OK != ret) - { - SDIO_LOG_ERR("deinit queue ret=%d", ret); - return ret; - } - - s_sdio_test_msg_que = NULL; - } - - if(s_test_sdio_thread) - { - ret = rtos_delete_thread(&s_test_sdio_thread); - if (BK_OK != ret) - { - SDIO_LOG_ERR("delete thread ret=%d", ret); - return ret; - } - - s_test_sdio_thread = NULL; - } - - SDIO_LOG_DEBUG_FUNCTION_EXIT(); - - return BK_OK; -} - -#endif //CONFIG_SDIO_TEST_EN diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/sdio/v2p0/sdio_test.h b/bk7235/liteos_m/bk_sdk_armino/middleware/driver/sdio/v2p0/sdio_test.h deleted file mode 100755 index 80b6c3257af48a87730af16f638a2e73dfcdd699..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/sdio/v2p0/sdio_test.h +++ /dev/null @@ -1,96 +0,0 @@ -// Copyright 2022-2023 Beken -// -// 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 _SDIO_TEST_H_ -#define _SDIO_TEST_H_ - -#define SDIO_TEST_PRIORITY (27) -#define SDIO_TEST_THREAD_NAME "sdio_test" -#define SDIO_TEST_THREAD_STACK_SIZE (0x1<<10) //Bytes - -#define SDIO_TEST_MSG_QUEUE_NAME "sdio_test_queue" -#define SDIO_TEST_MSG_QUEUE_COUNT (8) - -#define SDIO_TEST_BUFFER_CNT (4) -#define SDIO_TEST_BUFFER_SIZE (512) - -typedef struct { - uint8_t main_case; - uint8_t sub_case; - uint16_t reserved; - uint32_t param1; - uint32_t param2; - uint32_t param3; - uint32_t param4; -} SDIO_TEST_MSG_T; - -typedef enum -{ - SDIO_TEST_TX, - SDIO_TEST_RX, - SDIO_TEST_TX_THROUGH_PUT, - SDIO_TEST_RX_THROUGH_PUT, - SDIO_TEST_MAX_MAIN_CASE, -}SDIO_TEST_MAIN_CASE_ID_T; - -typedef enum -{ - SDIO_TEST_TX_INIT, - SDIO_TEST_TX_SINGLE_PACKET, - SDIO_TEST_TX_MANY_SINGLE_PACKETS, - SDIO_TEST_TX_MULTI_PACKETS, - SDIO_TEST_TX_MAX_SUB_CASE, -}SDIO_TEST_TX_CASE_ID_T; - -typedef enum -{ - SDIO_TEST_RX_INIT, - SDIO_TEST_RX_SINGLE_PACKET, - SDIO_TEST_RX_MANY_SINGLE_PACKETS, - SDIO_TEST_RX_MULTI_PACKETS, - SDIO_TEST_RX_MAX_SUB_CASE, -}SDIO_TEST_RX_CASE_ID_T; - -/** - * @brief Init the sdio driver test program. - * - * This API init the sdio driver test program. - * - It will create a task do selected test case. - * - It can select test case by command line. - * - * @attention 1. This API should be called after sdio inited finish. - * - * @return - * - BK_OK: succeed - * - others: other errors. - */ -bk_err_t bk_sdio_test_init(void); - -/** - * @brief Deinit the sdio driver test program. - * - * This API init the sdio driver test program. - * - It will delete the test thread and queue. - * - * @attention 1. This API should be called after sdio inited finish. - * - * @return - * - BK_OK: succeed - * - others: other errors. - */ -bk_err_t bk_sdio_test_deinit(void); - -#endif // _SDIO_SLAVE_TEST_H_ diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/sdio/v2p0/sdio_utils.c b/bk7235/liteos_m/bk_sdk_armino/middleware/driver/sdio/v2p0/sdio_utils.c deleted file mode 100755 index 9715d61fabd6d77695218a0f7b578798855acfaf..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/sdio/v2p0/sdio_utils.c +++ /dev/null @@ -1,337 +0,0 @@ -// Copyright 2022-2023 Beken -// -// 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 - -#include "bk_sdio.h" -//#include "sdio.h" -#include "sdio_utils.h" -#include "sdio_slave_driver.h" -#include -#include "driver/sdio_types.h" - - -#if CONFIG_SDIO_SLAVE - -#ifdef CONFIG_SDIO_DEBUG_EN -int32_t sdio_list_dump_info(sdio_node_t *head, sdio_node_t *tail, uint32_t count) -{ - sdio_node_t *cur_p = head; - - //TODO:log out each node info. - for(uint32_t i = 0; i < count; i++) - { - if(cur_p) - { - SDIO_LOG_INFO("nd%d=0x%x,next=0x%x len=%d", i, cur_p, cur_p->next, cur_p->len); - } - else - break; - } - - if(tail && cur_p != tail) - SDIO_LOG_INFO("tail=0x%x, len=%d", tail, tail->len); - - return 0; -} -#endif - -/** - * @brief Init a sdio single link list which includes the buffers. - * - * This API init a sdio single link list which includes the buffers. - * - Malloc buffers - * - Reserved the header for SDIO - * - Linked the buffers with single list - * - - * @param count How many buffers will be malloced. - * @param size Each buffer size for data which doesn't include SDIO header,it should be 4 bytes align - * @param head Saved the list head - * @param tail Saved the list tail - * - * @attention - * - * @return - * - BK_OK: succeed - * - others: other errors. - */ -bk_err_t sdio_list_init(uint32_t count, uint32_t size, sdio_node_ptr_t *head_p, sdio_node_ptr_t *tail_p) -{ - uint32_t i = 0; - sdio_node_t *cur_p = NULL, *next_p; - uint32_t buf_len = 0; - - if(head_p == NULL || tail_p == NULL) - { - SDIO_LOG_ERR("list init"); - return BK_ERR_SDIO_LIST_INIT; - } - - size = ((size + 3) / 4) * 4; //align to 4 bytes - buf_len = sizeof(sdio_node_t) + size; -#ifdef CONFIG_SDIO_DEBUG_EN - buf_len += SDIO_DEBUG_BUFFER_TAIL_LEN; -#endif - //first node - { - cur_p = *head_p = *tail_p = (sdio_node_t *)os_malloc(buf_len); - if(*head_p == NULL) - { - SDIO_LOG_ERR("mem malloc"); - return BK_ERR_SDIO_NO_MEM; - } - - cur_p->len = 0; -#ifdef CONFIG_SDIO_DEBUG_EN - //TODO:log info - *(uint32_t *)(((uint8_t *)cur_p+buf_len-SDIO_DEBUG_BUFFER_TAIL_LEN)) = SDIO_DEBUG_MAGIC_VALUE; -#endif - } - - for(i = 1; i < count; i++) - { - next_p = (sdio_node_t *)os_malloc(buf_len); - if(next_p == NULL) - { - SDIO_LOG_ERR("mem malloc"); - return BK_ERR_SDIO_NO_MEM; - } - next_p->len = 0; -#ifdef CONFIG_SDIO_DEBUG_EN - *(uint32_t *)((uint8_t *)(cur_p+buf_len-SDIO_DEBUG_BUFFER_TAIL_LEN)) = SDIO_DEBUG_MAGIC_VALUE; -#endif - - cur_p->next = next_p; - cur_p = cur_p->next; - } - cur_p->next = NULL; - *tail_p = cur_p; - -#ifdef CONFIG_SDIO_DEBUG_EN - sdio_list_dump_info(*head_p, *tail_p, count); -#endif - - return BK_OK; -} - -/** - * @brief Deinit a sdio single link list which includes the buffers. - * - * This API deinit a sdio single link list which includes the buffers. - * - Free buffers - * - - * @param list_p The list will be deinited - * - * @attention - * - * @return - * - BK_OK: succeed - * - others: other errors. - */ -bk_err_t sdio_list_deinit(sdio_list_t *list_p) -{ - uint32_t count = 0; - sdio_node_t *cur_p = NULL, *next_p; - - if(list_p) - { - cur_p = list_p->head; - while(cur_p) - { - next_p = cur_p->next; - os_free(cur_p); - cur_p = next_p; - - count++; - } - - if(count == list_p->count) - { - return BK_OK; - } - } - - return BK_FAIL; -} - -static bk_err_t sdio_list_check(sdio_node_t *push_head, sdio_node_t *push_tail, uint32_t count) -{ - sdio_node_t *cur_p = push_head; - uint32_t compute = 0; - - if(push_head == NULL) - { - SDIO_LOG_ERR("head null"); - return BK_ERR_SDIO_LIST; - } - - if(push_tail && push_tail->next != NULL) - { - SDIO_LOG_ERR("tail invalid"); - return BK_ERR_SDIO_LIST; - } - - while(cur_p) - { - cur_p = cur_p->next; - compute++; - if(compute == count) - { - if(cur_p == push_tail) - { - return BK_OK; - } - else - { - SDIO_LOG_ERR("list is invalid"); - return BK_ERR_SDIO_LIST; - } - } - } - - return BK_OK; -} - -/** - * @brief Pop a node from the selected list. - * - * This API Pop a node from the selected list. - * - Pop out a node from the selected list - * - Update the list info - * - - * @param list_p Selected pop node list - * @param node_p Save the pop out node - * - * @attention - * - * @return - * - BK_OK: succeed - * - others: other errors. - */ -bk_err_t sdio_list_pop_node(sdio_list_t *list_p, sdio_node_ptr_t *node_p) -{ - bk_err_t ret = BK_OK; - - ret = sdio_list_check(list_p->head, list_p->tail, list_p->count); - if(ret != BK_OK) - { - SDIO_LOG_ERR("list fail"); - goto err_exit; - } - - if(list_p->count) - { - sdio_node_ptr_t tmp_node_p = list_p->head; - *node_p = tmp_node_p; - if(list_p->head == list_p->tail) //last one - { - list_p->head = list_p->tail =NULL; - } - else - { - list_p->head = list_p->head->next; - } - tmp_node_p->next = NULL; - - list_p->count--; - } - -#ifdef CONFIG_SDIO_DEBUG_EN - sdio_list_dump_info(list_p->head, NULL, 1); -#endif - -err_exit: - *node_p = NULL; - return ret; -} - -/** - * @brief Push a source list to target list. - * - * This API Push a source list to target list. - * - Check list is whether valid - * - Link two list together - * - Update the list info - * - - * @param list_p Selected target list - * @param head_p Source list header node - * @param tail_p Source list tail node - * @param count How many nodes of source list - * - * @attention - * - * @return - * - BK_OK: succeed - * - others: other errors. - */ -bk_err_t sdio_list_push_list(sdio_list_t *list_p, sdio_node_t *head_p, sdio_node_t *tail_p, uint32_t count) -{ - bk_err_t ret = BK_OK; - - ret = sdio_list_check(head_p, tail_p, count); - if(ret != BK_OK) - { - SDIO_LOG_ERR("list fail"); - return ret; - } - - if(list_p->head == NULL) //ongoing is null, first in - { - list_p->head = head_p; - list_p->tail = tail_p; - list_p->count = count; - } - else - { - ret = sdio_list_check(list_p->head, - list_p->tail, - list_p->count); - if(ret != BK_OK) - { - SDIO_LOG_ERR("list fail"); - return ret; - } - - list_p->tail->next = head_p; - list_p->tail = tail_p; - list_p->count += count; - } - - //TODO:Just debug - ret = sdio_list_check(list_p->head, - list_p->tail, - list_p->count); - if(ret != BK_OK) - { - SDIO_LOG_ERR("list fail"); - return ret; - } - - return ret; -} - -sdio_node_t *sdio_list_pop_list(sdio_node_t *head, uint32_t count) -{ - return 0; -} - -uint32_t sdio_list_get_node_count(sdio_list_t *list_p) -{ - return list_p->count; -} -#endif -// EOF - diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/sdio/v2p0/sdio_utils.h b/bk7235/liteos_m/bk_sdk_armino/middleware/driver/sdio/v2p0/sdio_utils.h deleted file mode 100755 index c754801f1dfb435d0f8b6a78bb2b370b6c8d6ab7..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/sdio/v2p0/sdio_utils.h +++ /dev/null @@ -1,120 +0,0 @@ -// Copyright 2022-2023 Beken -// -// 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 _SDIO_UTIL_H_ -#define _SDIO_UTIL_H_ - -#define SDIO_DEBUG_BUFFER_TAIL_LEN (4) -#define SDIO_DEBUG_MAGIC_VALUE (0xA0A05050) - -typedef struct _sdio_node_t -{ - struct _sdio_node_t *next; - uint32_t len; - uint32_t priv; - uint32_t rsvd; -}sdio_node_t, *sdio_node_ptr_t; - -typedef struct _sdio_list_t -{ - sdio_node_ptr_t head; - sdio_node_ptr_t tail; - uint32_t count; -}sdio_list_t; - -int32_t sdio_list_dump_info(sdio_node_t *head, sdio_node_t *tail, uint32_t count); - -/** - * @brief Init a sdio single link list which includes the buffers. - * - * This API init a sdio single link list which includes the buffers. - * - Malloc buffers - * - Reserved the header for SDIO - * - Linked the buffers with single list - * - - * @param count How many buffers will be malloced. - * @param size Each buffer size for data which doesn't include SDIO header,it should be 4 bytes align - * @param head Saved the list head - * @param tail Saved the list tail - * - * @attention - * - * @return - * - BK_OK: succeed - * - others: other errors. - */ -bk_err_t sdio_list_init(uint32_t count, uint32_t size, sdio_node_ptr_t *head_p, sdio_node_ptr_t *tail_p); - -/** - * @brief Deinit a sdio single link list which includes the buffers. - * - * This API deinit a sdio single link list which includes the buffers. - * - Free buffers - * - - * @param list_p The list will be deinited - * - * @attention - * - * @return - * - BK_OK: succeed - * - others: other errors. - */ -bk_err_t sdio_list_deinit(sdio_list_t *list_p); - -/** - * @brief Pop a node from the selected list. - * - * This API Pop a node from the selected list. - * - Pop out a node from the selected list - * - Update the list info - * - - * @param list_p Selected pop node list - * @param node_p Save the pop out node - * - * @attention - * - * @return - * - BK_OK: succeed - * - others: other errors. - */ -bk_err_t sdio_list_pop_node(sdio_list_t *list_p, sdio_node_ptr_t *node_p); - -/** - * @brief Push a source list to target list. - * - * This API Push a source list to target list. - * - Check list is whether valid - * - Link two list together - * - Update the list info - * - - * @param list_p Selected target list - * @param head_p Source list header node - * @param tail_p Source list tail node - * @param count How many nodes of source list - * - * @attention - * - * @return - * - BK_OK: succeed - * - others: other errors. - */ -bk_err_t sdio_list_push_list(sdio_list_t *list_p, sdio_node_t *head_p, sdio_node_t *tail_p, uint32_t count); - -sdio_node_t *sdio_list_pop_list(sdio_node_t *head, uint32_t count); - -uint32_t sdio_list_get_node_count(sdio_list_t *list_p); - -#endif // _SDIO_UTIL_H_ diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/security/hal_aes.c b/bk7235/liteos_m/bk_sdk_armino/middleware/driver/security/hal_aes.c index e6f8b429c5eff45705f8c91cd5378c87232aa640..7b5ef99613935897fa7b4ad699bdeb050449a18b 100644 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/security/hal_aes.c +++ b/bk7235/liteos_m/bk_sdk_armino/middleware/driver/security/hal_aes.c @@ -1,3 +1,17 @@ +/* + * Copyright (C) 2022 Beken Corporation + * 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 #if (CONFIG_SOC_BK7251) #include diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/security/hal_aes.h b/bk7235/liteos_m/bk_sdk_armino/middleware/driver/security/hal_aes.h index 09e59d20ae0668f2c43c48abcb78bd46b6bc11ec..a50788bbf11b320ac34740601c53e6882bd1cc10 100644 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/security/hal_aes.h +++ b/bk7235/liteos_m/bk_sdk_armino/middleware/driver/security/hal_aes.h @@ -1,3 +1,17 @@ +/* + * Copyright (C) 2022 Beken Corporation + * 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 _BK_AES_H_ #define _BK_AES_H_ diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/security/hal_rsa.h b/bk7235/liteos_m/bk_sdk_armino/middleware/driver/security/hal_rsa.h index a21686efa2d36ac8a99dec54ad3ac8add49607f9..5b11643b6d35b68570e39bbe657fce9234e44526 100644 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/security/hal_rsa.h +++ b/bk7235/liteos_m/bk_sdk_armino/middleware/driver/security/hal_rsa.h @@ -1,4 +1,17 @@ - +/* + * Copyright (C) 2022 Beken Corporation + * 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 _BK_RSA_H_ #define _BK_RSA_H_ diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/security/hal_sha.c b/bk7235/liteos_m/bk_sdk_armino/middleware/driver/security/hal_sha.c deleted file mode 100644 index 9557073deea3cd57206e9fc9b84ba12af4fad973..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/security/hal_sha.c +++ /dev/null @@ -1,281 +0,0 @@ -#include - -#if 0//(CONFIG_SOC_BK7251) -#include -#include "bk_uart.h" -#include "bk_arm_arch.h" -#include "bk_icu.h" -#include -#include -#include "bk_drv_model.h" - -#include "bk_security.h" -#include "security.h" - - -void bk_sha_encrypt(hal_sha_context *ctx, const unsigned char *input) -{ - int err_num; - - SECURITY_SHA_DRV_DESC SHA_drv_desc; - - SHA_drv_desc.mode = ctx->mode; - SHA_drv_desc.step = ctx->step; - SHA_drv_desc.sha_block = (unsigned long *)input; - if (security_sha_init(&SHA_drv_desc) != 0) { - os_printf("sha failed \r\n"); - return; - } - - while (is_secrity_sha_busy() == 0) { - } - - if (ctx->step == STEP1) - ctx->step = STEP2; - -} - -void bk_sha256_finish(hal_sha_context *ctx, - unsigned char output[32]) -{ - get_security_sha_data(ctx, (unsigned long *)output); -} - - -void *hal_sha256_init(void) -{ - hal_sha_context *ctx; - - ctx = (hal_sha_context *)os_malloc(sizeof(hal_sha_context)); - if (ctx == NULL) - return NULL; - - os_memset(ctx, 0, sizeof(hal_sha_context)); - ctx->mode = SHA256; - ctx->total[0] = 0; - ctx->total[1] = 0; - ctx->step = STEP1; -} - -void *hal_sha1_init(void) -{ - hal_sha_context *ctx; - - ctx = (hal_sha_context *)os_malloc(sizeof(hal_sha_context)); - if (ctx == NULL) - return NULL; - - os_memset(ctx, 0, sizeof(hal_sha_context)); - ctx->mode = SHA1; - ctx->total[0] = 0; - ctx->total[1] = 0; - ctx->step = STEP1; - - return (void *)ctx; -} - -void hal_sha_update(void *ct, const unsigned char *input, - size_t ilen) -{ - size_t fill; - UINT32 left; - hal_sha_context *ctx = ct; - - if (ilen == 0) - return; - - left = ctx->total[0] & 0x3F; - fill = 64 - left; - - ctx->total[0] += (UINT32) ilen; - ctx->total[0] &= 0xFFFFFFFF; - - if (ctx->total[0] < (UINT32) ilen) - ctx->total[1]++; - - if (left && ilen >= fill) { - os_memcpy((void *)(ctx->buffer + left), input, fill); - bk_sha_encrypt(ctx, ctx->buffer); - input += fill; - ilen -= fill; - left = 0; - } - - while (ilen >= 64) { - bk_sha_encrypt(ctx, input); - input += 64; - ilen -= 64; - } - - if (ilen > 0) - os_memcpy((void *)(ctx->buffer + left), input, ilen); -} - -static const unsigned char sha256_padding[64] = { - 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 -}; - -/* - * SHA-256 final digest - */ -void hal_sha_finish(void *ct, unsigned char output[32]) -{ - UINT32 last, padn; - UINT32 high, low; - unsigned char msglen[8]; - hal_sha_context *ctx = ct; - - high = (ctx->total[0] >> 29) - | (ctx->total[1] << 3); - low = (ctx->total[0] << 3); - - PUT_UINT32_BE(high, msglen, 0); - PUT_UINT32_BE(low, msglen, 4); - - last = ctx->total[0] & 0x3F; - padn = (last < 56) ? (56 - last) : (120 - last); - - hal_sha256_update(ctx, sha256_padding, padn); - hal_sha256_update(ctx, msglen, 8); - - bk_sha256_finish(ctx, output); - - os_memset(ctx, 0, sizeof(hal_sha_context)); - os_free(ctx); - ctx = NULL; - -} - -static void hal_zeroize(void *v, size_t n) -{ - volatile unsigned char *p = v; - while (n--) *p++ = 0; -} - - -void hal_sha_free(hal_sha_context *ctx) -{ - if (ctx == NULL) - return; - - hal_zeroize(ctx, sizeof(hal_sha_context)); -} - -#if 1 - -static const unsigned char sha256_test_buf[3][57] = { - { "abc" }, - { "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" }, - { "" } -}; - -static const int sha256_test_buflen[3] = { - 3, 56, 1000 -}; - -static const unsigned char sha256_test_sum[6][32] = { - /* - * SHA-1 test vectors - */ - { - 0xA9, 0x99, 0x3E, 0x36, 0x47, 0x06, 0x81, 0x6A, 0xBA, 0x3E, - 0x25, 0x71, 0x78, 0x50, 0xC2, 0x6C, 0x9C, 0xD0, 0xD8, 0x9D - }, - { - 0x84, 0x98, 0x3E, 0x44, 0x1C, 0x3B, 0xD2, 0x6E, 0xBA, 0xAE, - 0x4A, 0xA1, 0xF9, 0x51, 0x29, 0xE5, 0xE5, 0x46, 0x70, 0xF1 - }, - { - 0x34, 0xAA, 0x97, 0x3C, 0xD4, 0xC4, 0xDA, 0xA4, 0xF6, 0x1E, - 0xEB, 0x2B, 0xDB, 0xAD, 0x27, 0x31, 0x65, 0x34, 0x01, 0x6F - }, - - /* - * SHA-256 test vectors - */ - { - 0xBA, 0x78, 0x16, 0xBF, 0x8F, 0x01, 0xCF, 0xEA, - 0x41, 0x41, 0x40, 0xDE, 0x5D, 0xAE, 0x22, 0x23, - 0xB0, 0x03, 0x61, 0xA3, 0x96, 0x17, 0x7A, 0x9C, - 0xB4, 0x10, 0xFF, 0x61, 0xF2, 0x00, 0x15, 0xAD - }, - { - 0x24, 0x8D, 0x6A, 0x61, 0xD2, 0x06, 0x38, 0xB8, - 0xE5, 0xC0, 0x26, 0x93, 0x0C, 0x3E, 0x60, 0x39, - 0xA3, 0x3C, 0xE4, 0x59, 0x64, 0xFF, 0x21, 0x67, - 0xF6, 0xEC, 0xED, 0xD4, 0x19, 0xDB, 0x06, 0xC1 - }, - { - 0xCD, 0xC7, 0x6E, 0x5C, 0x99, 0x14, 0xFB, 0x92, - 0x81, 0xA1, 0xC7, 0xE2, 0x84, 0xD7, 0x3E, 0x67, - 0xF1, 0x80, 0x9A, 0x48, 0xA4, 0x97, 0x20, 0x0E, - 0x04, 0x6D, 0x39, 0xCC, 0xC7, 0x11, 0x2C, 0xD0 - } -}; - - -int hal_sha256_self_test(int verbose) -{ - int i, j, k, buflen, ret = 0; - unsigned char *buf; - unsigned char sha256sum[32]; - void *ctx; - - buf = (unsigned char *)os_zalloc(1024); - if (NULL == buf) { - if (verbose != 0) - os_printf("Buffer allocation failed\n"); - - return (1); - } - - - for (i = 3; i < 6; i++) { - j = i % 3; - k = i < 3; - - - if (verbose != 0) - os_printf(" SHA-%d test #%d: ", 256 - k * 32, j + 1); - - ctx = hal_sha256_init(); - - if (j == 2) { - os_memset(buf, 'a', buflen = 1000); - - for (j = 0; j < 1000; j++) - hal_sha256_update(ctx, buf, buflen); - } else - hal_sha256_update(ctx, sha256_test_buf[j], - sha256_test_buflen[j]); - - hal_sha256_finish(ctx, sha256sum); - - if (os_memcmp(sha256sum, sha256_test_sum[i], 32 - k * 4) != 0) { - if (verbose != 0) - os_printf("failed\n"); - - ret = 1; - goto exit; - } - - if (verbose != 0) - os_printf("passed\n"); - } - - if (verbose != 0) - os_printf("\n"); - -exit: - os_free(buf); - - return (ret); -} - -#endif - -#endif - diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/security/hal_sha.h b/bk7235/liteos_m/bk_sdk_armino/middleware/driver/security/hal_sha.h index 50af839655e3bf6652c03d11af76475d919f07d5..62ef59b2aeee498d1a0748e7e0febf6a465c7949 100644 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/security/hal_sha.h +++ b/bk7235/liteos_m/bk_sdk_armino/middleware/driver/security/hal_sha.h @@ -1,3 +1,17 @@ +/* + * Copyright (C) 2022 Beken Corporation + * 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 _BK_SHA_H_ #define _BK_SHA_H_ diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/security/security.c b/bk7235/liteos_m/bk_sdk_armino/middleware/driver/security/security.c index 648cd2fd8cf5d715fcf5d28ee55d6db21e1c15a7..3d19bc78f8d4a4dc86039873d63089fef8065a7d 100644 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/security/security.c +++ b/bk7235/liteos_m/bk_sdk_armino/middleware/driver/security/security.c @@ -1,3 +1,17 @@ +/* + * Copyright (C) 2022 Beken Corporation + * 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 #if (CONFIG_SOC_BK7251) #include diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/security/security.h b/bk7235/liteos_m/bk_sdk_armino/middleware/driver/security/security.h index 04e06234a3665c06935609f4fe39002c736156f6..0482a981191b5da1fb40a0509e9c31d6eb7a4319 100644 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/security/security.h +++ b/bk7235/liteos_m/bk_sdk_armino/middleware/driver/security/security.h @@ -1,3 +1,17 @@ +/* + * Copyright (C) 2022 Beken Corporation + * 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 _SEC_H_ #define _SEC_H_ diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/security/security_reg.h b/bk7235/liteos_m/bk_sdk_armino/middleware/driver/security/security_reg.h index 66b9efacafe9b7b4a261c50b83f3f23f7375bddb..7db817fa25baa3ca387ffce8c9f7457c023f1d0c 100644 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/security/security_reg.h +++ b/bk7235/liteos_m/bk_sdk_armino/middleware/driver/security/security_reg.h @@ -1,3 +1,17 @@ +/* + * Copyright (C) 2022 Beken Corporation + * 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 _BK_SEC_H_ #define _BK_SEC_H_ diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/sys_ctrl/sys_ctrl.c b/bk7235/liteos_m/bk_sdk_armino/middleware/driver/sys_ctrl/sys_ctrl.c index e94f3e83c1d7c432c4e1fe17a22129daf1f574bd..14a0a1940e23e7e5d0e66ccdd7f804f5fe9bf5da 100755 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/sys_ctrl/sys_ctrl.c +++ b/bk7235/liteos_m/bk_sdk_armino/middleware/driver/sys_ctrl/sys_ctrl.c @@ -1,3 +1,17 @@ +/* + * Copyright (C) 2022 Beken Corporation + * 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 #include "bk_arm_arch.h" #include "bk_sys_ctrl.h" diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/sys_ctrl/sys_ctrl.h b/bk7235/liteos_m/bk_sdk_armino/middleware/driver/sys_ctrl/sys_ctrl.h index c1eaea0a87e02cdaa9fb9ebb5b2d4249492c04f4..d5c7e8245677e1f70c6a49ee65544754cf434eef 100755 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/sys_ctrl/sys_ctrl.h +++ b/bk7235/liteos_m/bk_sdk_armino/middleware/driver/sys_ctrl/sys_ctrl.h @@ -1,4 +1,18 @@ -#ifndef _SCTRL_H_ +/* + * Copyright (C) 2022 Beken Corporation + * 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 _SCTRL_H_ #define _SCTRL_H_ #include diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/sys_ctrl/sys_driver.h b/bk7235/liteos_m/bk_sdk_armino/middleware/driver/sys_ctrl/sys_driver.h index c4ef933bb7de9e5bfbd77b9bc38cf89549469fbc..316e4a75eada8618dd2eead48eb809f587165f7b 100644 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/sys_ctrl/sys_driver.h +++ b/bk7235/liteos_m/bk_sdk_armino/middleware/driver/sys_ctrl/sys_driver.h @@ -1,3 +1,17 @@ +/* + * Copyright (C) 2022 Beken Corporation + * 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 _SYS_DRV_H_ #define _SYS_DRV_H_ diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/uart/printf.c b/bk7235/liteos_m/bk_sdk_armino/middleware/driver/uart/printf.c deleted file mode 100644 index 700b3706949c38bbb722abc835ad395899c53f4e..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/driver/uart/printf.c +++ /dev/null @@ -1,1250 +0,0 @@ -/* - * Copyright (c) 1995 Patrick Powell. - * - * This code is based on code written by Patrick Powell . - * It may be used for any purpose as long as this notice remains intact on all - * source code distributions. - */ - -/* - * Copyright (c) 2008 Holger Weiss. - * - * This version of the code is maintained by Holger Weiss . - * My changes to the code may freely be used, modified and/or redistributed for - * any purpose. It would be nice if additions and fixes to this file (including - * trivial code cleanups) would be sent back in order to let me include them in - * the version available at . - * However, this is not a requirement for using or redistributing (possibly - * modified) versions of this file, nor is leaving this notice intact mandatory. - */ - -#include -#include /* For *_MAX. */ -#include /* For intmax_t (if not defined in ). */ -#include /* For ptrdiff_t. */ -#include /* For intmax_t. */ -#include /* For pow(3), NAN, and INFINITY. */ -#include /* For strcmp(3). */ -#include -#include "bk_uart.h" -#include - -#define VA_START(ap, last) va_start(ap, last) -#define VA_SHIFT(ap, value, type) /* No-op for ANSI C. */ - -/* Support for unsigned long long int. We may also need ULLONG_MAX. */ -#ifndef ULONG_MAX /* We may need ULONG_MAX as a fallback. */ -#ifdef UINT_MAX -#define ULONG_MAX UINT_MAX -#else -#define ULONG_MAX INT_MAX -#endif /* defined(UINT_MAX) */ -#endif /* !defined(ULONG_MAX) */ -#ifdef ULLONG -#undef ULLONG -#endif /* defined(ULLONG) */ -#if HAVE_UNSIGNED_LONG_LONG_INT -#define ULLONG unsigned long long int -#ifndef ULLONG_MAX -#define ULLONG_MAX ULONG_MAX -#endif /* !defined(ULLONG_MAX) */ -#else -#define ULLONG unsigned long int -#ifdef ULLONG_MAX -#undef ULLONG_MAX -#endif /* defined(ULLONG_MAX) */ -#define ULLONG_MAX ULONG_MAX -#endif /* HAVE_LONG_LONG_INT */ - -/* Support for uintmax_t. We also need UINTMAX_MAX. */ -#ifdef UINTMAX_T -#undef UINTMAX_T -#endif /* defined(UINTMAX_T) */ -#if HAVE_UINTMAX_T || defined(uintmax_t) -#define UINTMAX_T uintmax_t -#ifndef UINTMAX_MAX -#define UINTMAX_MAX ULLONG_MAX -#endif /* !defined(UINTMAX_MAX) */ -#else -#define UINTMAX_T ULLONG -#ifdef UINTMAX_MAX -#undef UINTMAX_MAX -#endif /* defined(UINTMAX_MAX) */ -#define UINTMAX_MAX ULLONG_MAX -#endif /* HAVE_UINTMAX_T || defined(uintmax_t) */ - -/* Support for long double. */ -#ifndef LDOUBLE -#if HAVE_LONG_DOUBLE -#define LDOUBLE long double -#else -#define LDOUBLE double -#endif /* HAVE_LONG_DOUBLE */ -#endif /* !defined(LDOUBLE) */ - -/* Support for long long int. */ -#ifndef LLONG -#if HAVE_LONG_LONG_INT -#define LLONG long long int -#else -#define LLONG long int -#endif /* HAVE_LONG_LONG_INT */ -#endif /* !defined(LLONG) */ - -/* Support for intmax_t. */ -#ifndef INTMAX_T -#if HAVE_INTMAX_T || defined(intmax_t) -#define INTMAX_T intmax_t -#else -#define INTMAX_T LLONG -#endif /* HAVE_INTMAX_T || defined(intmax_t) */ -#endif /* !defined(INTMAX_T) */ - -/* Support for uintptr_t. */ -#ifndef UINTPTR_T -#if HAVE_UINTPTR_T || defined(uintptr_t) -#define UINTPTR_T uintptr_t -#else -#define UINTPTR_T unsigned long int -#endif /* HAVE_UINTPTR_T || defined(uintptr_t) */ -#endif /* !defined(UINTPTR_T) */ - -/* Support for ptrdiff_t. */ -#ifndef PTRDIFF_T -#if HAVE_PTRDIFF_T || defined(ptrdiff_t) -#define PTRDIFF_T ptrdiff_t -#else -#define PTRDIFF_T long int -#endif /* HAVE_PTRDIFF_T || defined(ptrdiff_t) */ -#endif /* !defined(PTRDIFF_T) */ - -/* - * We need an unsigned integer type corresponding to ptrdiff_t (cf. C99: - * 7.19.6.1, 7). However, we'll simply use PTRDIFF_T and convert it to an - * unsigned type if necessary. This should work just fine in practice. - */ -#ifndef UPTRDIFF_T -#define UPTRDIFF_T PTRDIFF_T -#endif /* !defined(UPTRDIFF_T) */ - -/* - * We need a signed integer type corresponding to size_t (cf. C99: 7.19.6.1, 7). - * However, we'll simply use size_t and convert it to a signed type if - * necessary. This should work just fine in practice. - */ -#ifndef SSIZE_T -#define SSIZE_T size_t -#endif /* !defined(SSIZE_T) */ - -/* - * Buffer size to hold the octal string representation of UINT128_MAX without - * nul-termination ("3777777777777777777777777777777777777777777"). - */ -#ifdef MAX_CONVERT_LENGTH -#undef MAX_CONVERT_LENGTH -#endif /* defined(MAX_CONVERT_LENGTH) */ -#define MAX_CONVERT_LENGTH 43 - -/* Format read states. */ -#define PRINT_S_DEFAULT 0 -#define PRINT_S_FLAGS 1 -#define PRINT_S_WIDTH 2 -#define PRINT_S_DOT 3 -#define PRINT_S_PRECISION 4 -#define PRINT_S_MOD 5 -#define PRINT_S_CONV 6 - -/* Format flags. */ -#define PRINT_F_MINUS (1 << 0) -#define PRINT_F_PLUS (1 << 1) -#define PRINT_F_SPACE (1 << 2) -#define PRINT_F_NUM (1 << 3) -#define PRINT_F_ZERO (1 << 4) -#define PRINT_F_QUOTE (1 << 5) -#define PRINT_F_UP (1 << 6) -#define PRINT_F_UNSIGNED (1 << 7) -#define PRINT_F_TYPE_G (1 << 8) -#define PRINT_F_TYPE_E (1 << 9) - -/* Conversion flags. */ -#define PRINT_C_CHAR 1 -#define PRINT_C_SHORT 2 -#define PRINT_C_LONG 3 -#define PRINT_C_LLONG 4 -#define PRINT_C_LDOUBLE 5 -#define PRINT_C_SIZE 6 -#define PRINT_C_PTRDIFF 7 -#define PRINT_C_INTMAX 8 - -#ifndef MAX -#define MAX(x, y) ((x >= y) ? x : y) -#endif /* !defined(MAX) */ -#ifndef CHARTOINT -#define CHARTOINT(ch) (ch - '0') -#endif /* !defined(CHARTOINT) */ -#ifndef ISDIGIT -#define ISDIGIT(ch) ('0' <= (unsigned char)ch && (unsigned char)ch <= '9') -#endif /* !defined(ISDIGIT) */ -#ifndef ISNAN -#define ISNAN(x) (x != x) -#endif /* !defined(ISNAN) */ -#ifndef ISINF -#define ISINF(x) (x != 0.0 && x + x == x) -#endif /* !defined(ISINF) */ - -#ifdef OUTCHAR -#undef OUTCHAR -#endif /* defined(OUTCHAR) */ -#define OUTCHAR(str, len, size, ch) \ - do { \ - if (len + 1 < size) \ - str[len] = ch; \ - (len)++; \ - } while (/* CONSTCOND */ 0) - -static void fmtstr(char *, size_t *, size_t, const char *, int, int, int); -static void fmtint(char *, size_t *, size_t, INTMAX_T, int, int, int, int); -static void fmtflt(char *, size_t *, size_t, LDOUBLE, int, int, int, int *); -static void printsep(char *, size_t *, size_t); -static int getnumsep(int); -static int getexponent(LDOUBLE); -static int convert(UINTMAX_T, char *, size_t, int, int); -static UINTMAX_T cast(LDOUBLE); -static UINTMAX_T myround(LDOUBLE); -static LDOUBLE mypow10(int); -static void fmtmac(char *buf, size_t *len, size_t size, const unsigned char *mac, int caps); -static void fmtip(char *buf, size_t *len, size_t size, unsigned int value); - -int __wrap_vsnprintf(char *str, size_t size, const char *format, va_list args) -{ - LDOUBLE fvalue; - INTMAX_T value; - unsigned char cvalue; - const char *strvalue; - INTMAX_T *intmaxptr; - PTRDIFF_T *ptrdiffptr; - SSIZE_T *sizeptr; - LLONG *llongptr; - long int *longptr; - int *intptr; - short int *shortptr; - signed char *charptr; - size_t len = 0; - int overflow = 0; - int base = 0; - int cflags = 0; - int flags = 0; - int width = 0; - int precision = -1; - int state = PRINT_S_DEFAULT; - char ch = *format++; - - /* - * C99 says: "If `n' is zero, nothing is written, and `s' may be a null - * pointer." (7.19.6.5, 2) We're forgiving and allow a NULL pointer - * even if a size larger than zero was specified. At least NetBSD's - * snprintf(3) does the same, as well as other versions of this file. - * (Though some of these versions will write to a non-NULL buffer even - * if a size of zero was specified, which violates the standard.) - */ - if (str == NULL && size != 0) - size = 0; - - while (ch != '\0') { - switch (state) { - case PRINT_S_DEFAULT: - if (ch == '%') - state = PRINT_S_FLAGS; - else - OUTCHAR(str, len, size, ch); - ch = *format++; - break; - case PRINT_S_FLAGS: - switch (ch) { - case '-': - flags |= PRINT_F_MINUS; - ch = *format++; - break; - case '+': - flags |= PRINT_F_PLUS; - ch = *format++; - break; - case ' ': - flags |= PRINT_F_SPACE; - ch = *format++; - break; - case '#': - flags |= PRINT_F_NUM; - ch = *format++; - break; - case '0': - flags |= PRINT_F_ZERO; - ch = *format++; - break; - case '\'': /* SUSv2 flag (not in C99). */ - flags |= PRINT_F_QUOTE; - ch = *format++; - break; - default: - state = PRINT_S_WIDTH; - break; - } - break; - case PRINT_S_WIDTH: - if (ISDIGIT(ch)) { - ch = CHARTOINT(ch); - if (width > (INT_MAX - ch) / 10) { - overflow = 1; - goto out; - } - width = 10 * width + ch; - ch = *format++; - } else if (ch == '*') { - /* - * C99 says: "A negative field width argument is - * taken as a `-' flag followed by a positive - * field width." (7.19.6.1, 5) - */ - if ((width = va_arg(args, int)) < 0) { - flags |= PRINT_F_MINUS; - width = -width; - } - ch = *format++; - state = PRINT_S_DOT; - } else - state = PRINT_S_DOT; - break; - case PRINT_S_DOT: - if (ch == '.') { - state = PRINT_S_PRECISION; - ch = *format++; - } else - state = PRINT_S_MOD; - break; - case PRINT_S_PRECISION: - if (precision == -1) - precision = 0; - if (ISDIGIT(ch)) { - ch = CHARTOINT(ch); - if (precision > (INT_MAX - ch) / 10) { - overflow = 1; - goto out; - } - precision = 10 * precision + ch; - ch = *format++; - } else if (ch == '*') { - /* - * C99 says: "A negative precision argument is - * taken as if the precision were omitted." - * (7.19.6.1, 5) - */ - if ((precision = va_arg(args, int)) < 0) - precision = -1; - ch = *format++; - state = PRINT_S_MOD; - } else - state = PRINT_S_MOD; - break; - case PRINT_S_MOD: - switch (ch) { - case 'h': - ch = *format++; - if (ch == 'h') { /* It's a char. */ - ch = *format++; - cflags = PRINT_C_CHAR; - } else - cflags = PRINT_C_SHORT; - break; - case 'l': - ch = *format++; - if (ch == 'l') { /* It's a long long. */ - ch = *format++; - cflags = PRINT_C_LLONG; - } else - cflags = PRINT_C_LONG; - break; - case 'L': - cflags = PRINT_C_LDOUBLE; - ch = *format++; - break; - case 'j': - cflags = PRINT_C_INTMAX; - ch = *format++; - break; - case 't': - cflags = PRINT_C_PTRDIFF; - ch = *format++; - break; - case 'z': - cflags = PRINT_C_SIZE; - ch = *format++; - break; - } - state = PRINT_S_CONV; - break; - case PRINT_S_CONV: - switch (ch) { - case 'd': - /* FALLTHROUGH */ - case 'i': - switch (cflags) { - case PRINT_C_CHAR: - value = (signed char)va_arg(args, int); - break; - case PRINT_C_SHORT: - value = (short int)va_arg(args, int); - break; - case PRINT_C_LONG: - value = va_arg(args, long int); - break; - case PRINT_C_LLONG: - value = va_arg(args, LLONG); - break; - case PRINT_C_SIZE: - value = va_arg(args, SSIZE_T); - break; - case PRINT_C_INTMAX: - value = va_arg(args, INTMAX_T); - break; - case PRINT_C_PTRDIFF: - value = va_arg(args, PTRDIFF_T); - break; - default: - value = va_arg(args, int); - break; - } - fmtint(str, &len, size, value, 10, width, - precision, flags); - break; - case 'X': - flags |= PRINT_F_UP; - /* FALLTHROUGH */ - case 'x': - base = 16; - /* FALLTHROUGH */ - case 'o': - if (base == 0) - base = 8; - /* FALLTHROUGH */ - case 'u': - if (base == 0) - base = 10; - flags |= PRINT_F_UNSIGNED; - switch (cflags) { - case PRINT_C_CHAR: - value = (unsigned char)va_arg(args, - unsigned int); - break; - case PRINT_C_SHORT: - value = (unsigned short int)va_arg(args, - unsigned int); - break; - case PRINT_C_LONG: - value = va_arg(args, unsigned long int); - break; - case PRINT_C_LLONG: - value = va_arg(args, ULLONG); - break; - case PRINT_C_SIZE: - value = va_arg(args, size_t); - break; - case PRINT_C_INTMAX: - value = va_arg(args, UINTMAX_T); - break; - case PRINT_C_PTRDIFF: - value = va_arg(args, UPTRDIFF_T); - break; - default: - value = va_arg(args, unsigned int); - break; - } - fmtint(str, &len, size, (UINTMAX_T)value, base, width, - precision, flags); - break; - case 'A': - /* Not yet supported, we'll use "%F". */ - /* FALLTHROUGH */ - case 'F': - flags |= PRINT_F_UP; - case 'a': - /* Not yet supported, we'll use "%f". */ - /* FALLTHROUGH */ - case 'f': - if (cflags == PRINT_C_LDOUBLE) - fvalue = va_arg(args, LDOUBLE); - else - fvalue = va_arg(args, double); - fmtflt(str, &len, size, fvalue, width, - precision, flags, &overflow); - if (overflow) - goto out; - break; - case 'E': - flags |= PRINT_F_UP; - /* FALLTHROUGH */ - case 'e': - flags |= PRINT_F_TYPE_E; - if (cflags == PRINT_C_LDOUBLE) - fvalue = va_arg(args, LDOUBLE); - else - fvalue = va_arg(args, double); - fmtflt(str, &len, size, fvalue, width, - precision, flags, &overflow); - if (overflow) - goto out; - break; - case 'G': - flags |= PRINT_F_UP; - /* FALLTHROUGH */ - case 'g': - flags |= PRINT_F_TYPE_G; - if (cflags == PRINT_C_LDOUBLE) - fvalue = va_arg(args, LDOUBLE); - else - fvalue = va_arg(args, double); - /* - * If the precision is zero, it is treated as - * one (cf. C99: 7.19.6.1, 8). - */ - if (precision == 0) - precision = 1; - fmtflt(str, &len, size, fvalue, width, - precision, flags, &overflow); - if (overflow) - goto out; - break; - case 'c': - cvalue = va_arg(args, int); - OUTCHAR(str, len, size, cvalue); - break; - case 's': - strvalue = va_arg(args, char *); - fmtstr(str, &len, size, strvalue, width, - precision, flags); - break; - case 'p': - /* - * C99 says: "The value of the pointer is - * converted to a sequence of printing - * characters, in an implementation-defined - * manner." (C99: 7.19.6.1, 8) - */ - if (*format == 'm' || *format == 'M') { - unsigned char *macstr; - if (*format == 'M') - flags |= PRINT_F_UP; - format++; - if ((macstr = va_arg(args, unsigned char *)) == NULL) - macstr = (unsigned char *)"\x00\x00\x00\x00\x00\x00"; - fmtmac(str, &len, size, macstr, flags & PRINT_F_UP); - - break; - } else if (*format == 'i' || *format == 'I') { - format++; - value = va_arg(args, unsigned int); - fmtip(str, &len, size, (unsigned int)value); - break; - } else { - if ((strvalue = va_arg(args, void *)) == NULL) { - /* - * We use the glibc format. BSD prints - * "0x0", SysV "0". - */ - fmtstr(str, &len, size, "(nil)", width, - -1, flags); - } else { - /* - * We use the BSD/glibc format. SysV - * omits the "0x" prefix (which we emit - * using the PRINT_F_NUM flag). - */ - flags |= PRINT_F_NUM; - flags |= PRINT_F_UNSIGNED; - fmtint(str, &len, size, - (UINTPTR_T)strvalue, 16, width, - precision, flags); - } - } - break; - case 'n': - switch (cflags) { - case PRINT_C_CHAR: - charptr = va_arg(args, signed char *); - *charptr = len; - break; - case PRINT_C_SHORT: - shortptr = va_arg(args, short int *); - *shortptr = len; - break; - case PRINT_C_LONG: - longptr = va_arg(args, long int *); - *longptr = len; - break; - case PRINT_C_LLONG: - llongptr = va_arg(args, LLONG *); - *llongptr = len; - break; - case PRINT_C_SIZE: - /* - * C99 says that with the "z" length - * modifier, "a following `n' conversion - * specifier applies to a pointer to a - * signed integer type corresponding to - * size_t argument." (7.19.6.1, 7) - */ - sizeptr = va_arg(args, SSIZE_T *); - *sizeptr = len; - break; - case PRINT_C_INTMAX: - intmaxptr = va_arg(args, INTMAX_T *); - *intmaxptr = len; - break; - case PRINT_C_PTRDIFF: - ptrdiffptr = va_arg(args, PTRDIFF_T *); - *ptrdiffptr = len; - break; - default: - intptr = va_arg(args, int *); - *intptr = len; - break; - } - break; - case '%': /* Print a "%" character verbatim. */ - OUTCHAR(str, len, size, ch); - break; - default: /* Skip other characters. */ - break; - } - ch = *format++; - state = PRINT_S_DEFAULT; - base = cflags = flags = width = 0; - precision = -1; - break; - } - } -out: - if (len < size) - str[len] = '\0'; - else if (size > 0) - str[size - 1] = '\0'; - - if (overflow || len >= INT_MAX) { - //errno = overflow ? EOVERFLOW : ERANGE; - return -1; - } - return (int)len; -} - -static void fmtstr(char *str, size_t *len, size_t size, const char *value, int width, - int precision, int flags) -{ - int padlen, strln; /* Amount to pad. */ - int noprecision = (precision == -1); - - if (value == NULL) /* We're forgiving. */ - value = "(null)"; - - /* If a precision was specified, don't read the string past it. */ - for (strln = 0; value[strln] != '\0' && - (noprecision || strln < precision); strln++) - continue; - - if ((padlen = width - strln) < 0) - padlen = 0; - if (flags & PRINT_F_MINUS) /* Left justify. */ - padlen = -padlen; - - while (padlen > 0) { /* Leading spaces. */ - OUTCHAR(str, *len, size, ' '); - padlen--; - } - while (*value != '\0' && (noprecision || precision-- > 0)) { - OUTCHAR(str, *len, size, *value); - value++; - } - while (padlen < 0) { /* Trailing spaces. */ - OUTCHAR(str, *len, size, ' '); - padlen++; - } -} - -static void fmtint(char *str, size_t *len, size_t size, INTMAX_T value, int base, int width, - int precision, int flags) -{ - UINTMAX_T uvalue; - char iconvert[MAX_CONVERT_LENGTH]; - char sign = 0; - char hexprefix = 0; - int spadlen = 0; /* Amount to space pad. */ - int zpadlen = 0; /* Amount to zero pad. */ - int pos; - int separators = (flags & PRINT_F_QUOTE); - int noprecision = (precision == -1); - - if (flags & PRINT_F_UNSIGNED) - uvalue = value; - else { - uvalue = (value >= 0) ? value : -value; - if (value < 0) - sign = '-'; - else if (flags & PRINT_F_PLUS) /* Do a sign. */ - sign = '+'; - else if (flags & PRINT_F_SPACE) - sign = ' '; - } - - pos = convert(uvalue, iconvert, sizeof(iconvert), base, - flags & PRINT_F_UP); - - if (flags & PRINT_F_NUM && uvalue != 0) { - /* - * C99 says: "The result is converted to an `alternative form'. - * For `o' conversion, it increases the precision, if and only - * if necessary, to force the first digit of the result to be a - * zero (if the value and precision are both 0, a single 0 is - * printed). For `x' (or `X') conversion, a nonzero result has - * `0x' (or `0X') prefixed to it." (7.19.6.1, 6) - */ - switch (base) { - case 8: - if (precision <= pos) - precision = pos + 1; - break; - case 16: - hexprefix = (flags & PRINT_F_UP) ? 'X' : 'x'; - break; - } - } - - if (separators) /* Get the number of group separators we'll print. */ - separators = getnumsep(pos); - - zpadlen = precision - pos - separators; - spadlen = width /* Minimum field width. */ - - separators /* Number of separators. */ - - MAX(precision, pos) /* Number of integer digits. */ - - ((sign != 0) ? 1 : 0) /* Will we print a sign? */ - - ((hexprefix != 0) ? 2 : 0); /* Will we print a prefix? */ - - if (zpadlen < 0) - zpadlen = 0; - if (spadlen < 0) - spadlen = 0; - - /* - * C99 says: "If the `0' and `-' flags both appear, the `0' flag is - * ignored. For `d', `i', `o', `u', `x', and `X' conversions, if a - * precision is specified, the `0' flag is ignored." (7.19.6.1, 6) - */ - if (flags & PRINT_F_MINUS) /* Left justify. */ - spadlen = -spadlen; - else if (flags & PRINT_F_ZERO && noprecision) { - zpadlen += spadlen; - spadlen = 0; - } - while (spadlen > 0) { /* Leading spaces. */ - OUTCHAR(str, *len, size, ' '); - spadlen--; - } - if (sign != 0) /* Sign. */ - OUTCHAR(str, *len, size, sign); - if (hexprefix != 0) { /* A "0x" or "0X" prefix. */ - OUTCHAR(str, *len, size, '0'); - OUTCHAR(str, *len, size, hexprefix); - } - while (zpadlen > 0) { /* Leading zeros. */ - OUTCHAR(str, *len, size, '0'); - zpadlen--; - } - while (pos > 0) { /* The actual digits. */ - pos--; - OUTCHAR(str, *len, size, iconvert[pos]); - if (separators > 0 && pos > 0 && pos % 3 == 0) - printsep(str, len, size); - } - while (spadlen < 0) { /* Trailing spaces. */ - OUTCHAR(str, *len, size, ' '); - spadlen++; - } -} - -static void fmtflt(char *str, size_t *len, size_t size, LDOUBLE fvalue, int width, - int precision, int flags, int *overflow) -{ - LDOUBLE ufvalue; - UINTMAX_T intpart; - UINTMAX_T fracpart; - UINTMAX_T mask; - const char *infnan = NULL; - char iconvert[MAX_CONVERT_LENGTH]; - char fconvert[MAX_CONVERT_LENGTH]; - char econvert[4]; /* "e-12" (without nul-termination). */ - char esign = 0; - char sign = 0; - int leadfraczeros = 0; - int exponent = 0; - int emitpoint = 0; - int omitzeros = 0; - int omitcount = 0; - int padlen = 0; - int epos = 0; - int fpos = 0; - int ipos = 0; - int separators = (flags & PRINT_F_QUOTE); - int estyle = (flags & PRINT_F_TYPE_E); - - /* - * AIX' man page says the default is 0, but C99 and at least Solaris' - * and NetBSD's man pages say the default is 6, and sprintf(3) on AIX - * defaults to 6. - */ - if (precision == -1) - precision = 6; - - if (fvalue < 0.0) - sign = '-'; - else if (flags & PRINT_F_PLUS) /* Do a sign. */ - sign = '+'; - else if (flags & PRINT_F_SPACE) - sign = ' '; - - if (ISNAN(fvalue)) - infnan = (flags & PRINT_F_UP) ? "NAN" : "nan"; - else if (ISINF(fvalue)) - infnan = (flags & PRINT_F_UP) ? "INF" : "inf"; - - if (infnan != NULL) { - if (sign != 0) - iconvert[ipos++] = sign; - while (*infnan != '\0') - iconvert[ipos++] = *infnan++; - fmtstr(str, len, size, iconvert, width, ipos, flags); - return; - } - - /* "%e" (or "%E") or "%g" (or "%G") conversion. */ - if (flags & PRINT_F_TYPE_E || flags & PRINT_F_TYPE_G) { - if (flags & PRINT_F_TYPE_G) { - /* - * For "%g" (and "%G") conversions, the precision - * specifies the number of significant digits, which - * includes the digits in the integer part. The - * conversion will or will not be using "e-style" (like - * "%e" or "%E" conversions) depending on the precision - * and on the exponent. However, the exponent can be - * affected by rounding the converted value, so we'll - * leave this decision for later. Until then, we'll - * assume that we're going to do an "e-style" conversion - * (in order to get the exponent calculated). For - * "e-style", the precision must be decremented by one. - */ - precision--; - /* - * For "%g" (and "%G") conversions, trailing zeros are - * removed from the fractional portion of the result - * unless the "#" flag was specified. - */ - if (!(flags & PRINT_F_NUM)) - omitzeros = 1; - } - exponent = getexponent(fvalue); - estyle = 1; - } - -again: - /* - * Sorry, we only support 9, 19, or 38 digits (that is, the number of - * digits of the 32-bit, the 64-bit, or the 128-bit UINTMAX_MAX value - * minus one) past the decimal point due to our conversion method. - */ - switch (sizeof(UINTMAX_T)) { - case 16: - if (precision > 38) - precision = 38; - break; - case 8: - if (precision > 19) - precision = 19; - break; - default: - if (precision > 9) - precision = 9; - break; - } - - ufvalue = (fvalue >= 0.0) ? fvalue : -fvalue; - if (estyle) /* We want exactly one integer digit. */ - ufvalue /= mypow10(exponent); - - if ((intpart = cast(ufvalue)) == UINTMAX_MAX) { - *overflow = 1; - return; - } - - /* - * Factor of ten with the number of digits needed for the fractional - * part. For example, if the precision is 3, the mask will be 1000. - */ - mask = mypow10(precision); - /* - * We "cheat" by converting the fractional part to integer by - * multiplying by a factor of ten. - */ - if ((fracpart = myround(mask * (ufvalue - intpart))) >= mask) { - /* - * For example, ufvalue = 2.99962, intpart = 2, and mask = 1000 - * (because precision = 3). Now, myround(1000 * 0.99962) will - * return 1000. So, the integer part must be incremented by one - * and the fractional part must be set to zero. - */ - intpart++; - fracpart = 0; - if (estyle && intpart == 10) { - /* - * The value was rounded up to ten, but we only want one - * integer digit if using "e-style". So, the integer - * part must be set to one and the exponent must be - * incremented by one. - */ - intpart = 1; - exponent++; - } - } - - /* - * Now that we know the real exponent, we can check whether or not to - * use "e-style" for "%g" (and "%G") conversions. If we don't need - * "e-style", the precision must be adjusted and the integer and - * fractional parts must be recalculated from the original value. - * - * C99 says: "Let P equal the precision if nonzero, 6 if the precision - * is omitted, or 1 if the precision is zero. Then, if a conversion - * with style `E' would have an exponent of X: - * - * - if P > X >= -4, the conversion is with style `f' (or `F') and - * precision P - (X + 1). - * - * - otherwise, the conversion is with style `e' (or `E') and precision - * P - 1." (7.19.6.1, 8) - * - * Note that we had decremented the precision by one. - */ - if (flags & PRINT_F_TYPE_G && estyle && - precision + 1 > exponent && exponent >= -4) { - precision -= exponent; - estyle = 0; - goto again; - } - - if (estyle) { - if (exponent < 0) { - exponent = -exponent; - esign = '-'; - } else - esign = '+'; - - /* - * Convert the exponent. The sizeof(econvert) is 4. So, the - * econvert buffer can hold e.g. "e+99" and "e-99". We don't - * support an exponent which contains more than two digits. - * Therefore, the following stores are safe. - */ - epos = convert(exponent, econvert, 2, 10, 0); - /* - * C99 says: "The exponent always contains at least two digits, - * and only as many more digits as necessary to represent the - * exponent." (7.19.6.1, 8) - */ - if (epos == 1) - econvert[epos++] = '0'; - econvert[epos++] = esign; - econvert[epos++] = (flags & PRINT_F_UP) ? 'E' : 'e'; - } - - /* Convert the integer part and the fractional part. */ - ipos = convert(intpart, iconvert, sizeof(iconvert), 10, 0); - if (fracpart != 0) /* convert() would return 1 if fracpart == 0. */ - fpos = convert(fracpart, fconvert, sizeof(fconvert), 10, 0); - - leadfraczeros = precision - fpos; - - if (omitzeros) { - if (fpos > 0) /* Omit trailing fractional part zeros. */ - while (omitcount < fpos && fconvert[omitcount] == '0') - omitcount++; - else { /* The fractional part is zero, omit it completely. */ - omitcount = precision; - leadfraczeros = 0; - } - precision -= omitcount; - } - - /* - * Print a decimal point if either the fractional part is non-zero - * and/or the "#" flag was specified. - */ - if (precision > 0 || flags & PRINT_F_NUM) - emitpoint = 1; - if (separators) /* Get the number of group separators we'll print. */ - separators = getnumsep(ipos); - - padlen = width /* Minimum field width. */ - - ipos /* Number of integer digits. */ - - epos /* Number of exponent characters. */ - - precision /* Number of fractional digits. */ - - separators /* Number of group separators. */ - - (emitpoint ? 1 : 0) /* Will we print a decimal point? */ - - ((sign != 0) ? 1 : 0); /* Will we print a sign character? */ - - if (padlen < 0) - padlen = 0; - - /* - * C99 says: "If the `0' and `-' flags both appear, the `0' flag is - * ignored." (7.19.6.1, 6) - */ - if (flags & PRINT_F_MINUS) /* Left justifty. */ - padlen = -padlen; - else if (flags & PRINT_F_ZERO && padlen > 0) { - if (sign != 0) { /* Sign. */ - OUTCHAR(str, *len, size, sign); - sign = 0; - } - while (padlen > 0) { /* Leading zeros. */ - OUTCHAR(str, *len, size, '0'); - padlen--; - } - } - while (padlen > 0) { /* Leading spaces. */ - OUTCHAR(str, *len, size, ' '); - padlen--; - } - if (sign != 0) /* Sign. */ - OUTCHAR(str, *len, size, sign); - while (ipos > 0) { /* Integer part. */ - ipos--; - OUTCHAR(str, *len, size, iconvert[ipos]); - if (separators > 0 && ipos > 0 && ipos % 3 == 0) - printsep(str, len, size); - } - if (emitpoint) /* Decimal point. */ - OUTCHAR(str, *len, size, '.'); - while (leadfraczeros > 0) { /* Leading fractional part zeros. */ - OUTCHAR(str, *len, size, '0'); - leadfraczeros--; - } - while (fpos > omitcount) { /* The remaining fractional part. */ - fpos--; - OUTCHAR(str, *len, size, fconvert[fpos]); - } - while (epos > 0) { /* Exponent. */ - epos--; - OUTCHAR(str, *len, size, econvert[epos]); - } - while (padlen < 0) { /* Trailing spaces. */ - OUTCHAR(str, *len, size, ' '); - padlen++; - } -} - -static void printsep(char *str, size_t *len, size_t size) -{ - OUTCHAR(str, *len, size, ','); -} - -static int getnumsep(int digits) -{ - int separators = (digits - ((digits % 3 == 0) ? 1 : 0)) / 3; - - return separators; -} - -static int getexponent(LDOUBLE value) -{ - LDOUBLE tmp = (value >= 0.0) ? value : -value; - int exponent = 0; - - /* - * We check for 99 > exponent > -99 in order to work around possible - * endless loops which could happen (at least) in the second loop (at - * least) if we're called with an infinite value. However, we checked - * for infinity before calling this function using our ISINF() macro, so - * this might be somewhat paranoid. - */ - while (tmp < 1.0 && tmp > 0.0 && --exponent > -99) - tmp *= 10; - while (tmp >= 10.0 && ++exponent < 99) - tmp /= 10; - - return exponent; -} - -static int convert(UINTMAX_T value, char *buf, size_t size, int base, int caps) -{ - const char *digits = caps ? "0123456789ABCDEF" : "0123456789abcdef"; - size_t pos = 0; - - /* We return an unterminated buffer with the digits in reverse order. */ - do { - buf[pos++] = digits[value % base]; - value /= base; - } while (value != 0 && pos < size); - - return (int)pos; -} - -static int convert_ip(unsigned int value, char *buf, size_t size) -{ - const char *digits = "0123456789"; - int i; - unsigned char c; - size_t pos = 0; - - for (i = 0; i < 4; i++) { - c = (value >> (i * 8)) & 0xff; - - /* We return an unterminated buffer with the digits in reverse order. */ - do { - buf[pos++] = digits[c % 10]; - c /= 10; - } while (c != 0 && pos < size); - - if (i != 3 && pos < size) - buf[pos++] = '.'; - } - - return (int)pos; -} - -/* TODO: IPv6 */ -static void fmtip(char *buf, size_t *len, size_t size, unsigned int value) -{ - int pos; - char ip_buf[18]; - - pos = convert_ip(value, ip_buf, sizeof(ip_buf)); - if (pos > 0) pos--; - for (; pos >= 0; pos--) - OUTCHAR(buf, *len, size, ip_buf[pos]); -} - -static void fmtmac(char *buf, size_t *len, size_t size, const unsigned char *mac, int caps) -{ - const char *digits = caps ? "0123456789ABCDEF" : "0123456789abcdef"; - int i; - unsigned char c; - - for (i = 0; i < 6; i++) { - c = mac[i]; - OUTCHAR(buf, *len, size, digits[(c >> 4) & 0xf]); - OUTCHAR(buf, *len, size, digits[c & 0xf]); - if (i != 5) - OUTCHAR(buf, *len, size, ':'); - } -} - -static UINTMAX_T cast(LDOUBLE value) -{ - UINTMAX_T result; - - /* - * We check for ">=" and not for ">" because if UINTMAX_MAX cannot be - * represented exactly as an LDOUBLE value (but is less than LDBL_MAX), - * it may be increased to the nearest higher representable value for the - * comparison (cf. C99: 6.3.1.4, 2). It might then equal the LDOUBLE - * value although converting the latter to UINTMAX_T would overflow. - */ - if (value >= UINTMAX_MAX) - return UINTMAX_MAX; - - result = value; - /* - * At least on NetBSD/sparc64 3.0.2 and 4.99.30, casting long double to - * an integer type converts e.g. 1.9 to 2 instead of 1 (which violates - * the standard). Sigh. - */ - return (result <= value) ? result : result - 1; -} - -static UINTMAX_T myround(LDOUBLE value) -{ - UINTMAX_T intpart = cast(value); - - return ((value -= intpart) < 0.5) ? intpart : intpart + 1; -} - -static LDOUBLE mypow10(int exponent) -{ - LDOUBLE result = 1; - - while (exponent > 0) { - result *= 10; - exponent--; - } - while (exponent < 0) { - result /= 10; - exponent++; - } - return result; -} - -int __wrap_vasprintf(char **ret, const char *format, va_list ap) -{ - size_t size; - int len; - va_list aq; - - va_copy(aq, ap); - len = __wrap_vsnprintf(NULL, 0, format, aq); - va_end(aq); - - if (len < 0 || (*ret = os_malloc(size = len + 1)) == NULL) - return -1; - - return __wrap_vsnprintf(*ret, size, format, ap); -} - -int __wrap_snprintf(char *str, size_t size, const char *format, ...) -{ - va_list ap; - int len; - - va_start(ap, format); - len = __wrap_vsnprintf(str, size, format, ap); - va_end(ap); - - return len; -} - -int __wrap_asprintf(char **ret, const char *format, ...) -{ - va_list ap; - int len; - - va_start(ap, format); - len = __wrap_vasprintf(ret, format, ap); - va_end(ap); - return len; -} - -int __wrap_sprintf(char *str, const char *format, ...) -{ - va_list ap; - int len; - - va_start(ap, format); - len = __wrap_vsnprintf(str, INT_MAX, format, ap); - va_end(ap); - - return len; -} - - - -int __wrap_puts(const char *s) -{ - uart_write_string(bk_get_printf_port(), s); - - return 1; /* non-negative value returned */ -} - diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/soc/bk7235/soc/dma2d_reg.h b/bk7235/liteos_m/bk_sdk_armino/middleware/soc/bk7235/soc/dma2d_reg.h index 6948f20e073e87b4cc03d26518684e8b7df02518..38dca461090e8089a1701260fda9c0a7d7647990 100755 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/soc/bk7235/soc/dma2d_reg.h +++ b/bk7235/liteos_m/bk_sdk_armino/middleware/soc/bk7235/soc/dma2d_reg.h @@ -1,3 +1,17 @@ +/* + * Copyright (C) 2022 Beken Corporation + * 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. + */ #ifdef __cplusplus extern "C" { diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/soc/bk7235/stub.c b/bk7235/liteos_m/bk_sdk_armino/middleware/soc/bk7235/stub.c index b0fe776cffb014489d3ac7e5fc24d7b4eb7ef614..09dd09db7842c094d08aaf2cbf39fa1daee98948 100755 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/soc/bk7235/stub.c +++ b/bk7235/liteos_m/bk_sdk_armino/middleware/soc/bk7235/stub.c @@ -1,3 +1,17 @@ +/* + * Copyright (C) 2022 Beken Corporation + * 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 #define TAG "stub" diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/soc/common/hal/adc_hal.c b/bk7235/liteos_m/bk_sdk_armino/middleware/soc/common/hal/adc_hal.c index 9d2653874187aa76e04dd59dd29bb6f9cc94181c..3163e3cc7240be26958e6dcc46fe55db95fa65c9 100755 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/soc/common/hal/adc_hal.c +++ b/bk7235/liteos_m/bk_sdk_armino/middleware/soc/common/hal/adc_hal.c @@ -1,3 +1,17 @@ +/* + * Copyright (C) 2022 Beken Corporation + * 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 #include "adc_hal.h" #include "power_driver.h" diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/soc/common/hal/icu_hal.c b/bk7235/liteos_m/bk_sdk_armino/middleware/soc/common/hal/icu_hal.c index 7377d0f3b126777ee86573fd39eb5d9673f78a8d..16118420b6d77ad9d33b2447ff2c85f33371f4ef 100755 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/soc/common/hal/icu_hal.c +++ b/bk7235/liteos_m/bk_sdk_armino/middleware/soc/common/hal/icu_hal.c @@ -1,3 +1,17 @@ +/* + * Copyright (C) 2022 Beken Corporation + * 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 #include "bk_arm_arch.h" #include "icu_hal.h" diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/soc/common/hal/include/sys_hal.h b/bk7235/liteos_m/bk_sdk_armino/middleware/soc/common/hal/include/sys_hal.h index a6bb6b8e7df44c9f75c5a203bf3c321bcc2bc7bf..d6869d5b6107500b6593137986d2f35b8839fde5 100644 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/soc/common/hal/include/sys_hal.h +++ b/bk7235/liteos_m/bk_sdk_armino/middleware/soc/common/hal/include/sys_hal.h @@ -1,3 +1,17 @@ +/* + * Copyright (C) 2022 Beken Corporation + * 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. + */ #pragma once diff --git a/bk7235/liteos_m/bk_sdk_armino/middleware/soc/common/hal/pwm_hal.c b/bk7235/liteos_m/bk_sdk_armino/middleware/soc/common/hal/pwm_hal.c index 7c555d86511663819e57642d93634a5b98a8be40..ede17a2186c73209b9a92024382a17cee996e55c 100755 --- a/bk7235/liteos_m/bk_sdk_armino/middleware/soc/common/hal/pwm_hal.c +++ b/bk7235/liteos_m/bk_sdk_armino/middleware/soc/common/hal/pwm_hal.c @@ -1,3 +1,17 @@ +/* + * Copyright (C) 2022 Beken Corporation + * 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 #include "bk_gpio.h" #include "pwm_hal.h" diff --git a/bk7235/liteos_m/bk_sdk_armino/projects/openharmony/main/harmony_main.c b/bk7235/liteos_m/bk_sdk_armino/projects/openharmony/main/harmony_main.c index 7736982efca80c7b0482fe8d1de855cc55ba0a62..9f6cf6bc5cc5a3a7ef4af6c05ffd0bcadb153a57 100755 --- a/bk7235/liteos_m/bk_sdk_armino/projects/openharmony/main/harmony_main.c +++ b/bk7235/liteos_m/bk_sdk_armino/projects/openharmony/main/harmony_main.c @@ -1,3 +1,17 @@ +/* + * Copyright (C) 2022 Beken Corporation + * 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 "bk_private/legacy_init.h" #include #include diff --git a/bk7235/liteos_m/bk_sdk_armino/tools/build_tools/armino_actions/constants.py b/bk7235/liteos_m/bk_sdk_armino/tools/build_tools/armino_actions/constants.py deleted file mode 100644 index 880659887d8affd84f68bc1d02b1159544f44dfd..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/tools/build_tools/armino_actions/constants.py +++ /dev/null @@ -1,42 +0,0 @@ -import collections -import multiprocessing -import os -import platform - -# Make flavors, across the various kinds of Windows environments & POSIX... -if 'MSYSTEM' in os.environ: # MSYS - MAKE_CMD = 'make' - MAKE_GENERATOR = 'MSYS Makefiles' -elif os.name == 'nt': # other Windows - MAKE_CMD = 'mingw32-make' - MAKE_GENERATOR = 'MinGW Makefiles' -elif platform.system() == 'FreeBSD': - MAKE_CMD = 'gmake' - MAKE_GENERATOR = 'Unix Makefiles' -else: - MAKE_CMD = 'make' - MAKE_GENERATOR = 'Unix Makefiles' - -GENERATORS = collections.OrderedDict([ - # - command: build command line - # - version: version command line - # - dry_run: command to run in dry run mode - # - verbose_flag: verbose flag - ('Ninja', { - 'command': ['ninja'], - 'version': ['ninja', '--version'], - 'dry_run': ['ninja', '-n'], - 'verbose_flag': '-v' - }), - (MAKE_GENERATOR, { - 'command': [MAKE_CMD, '-j', str(multiprocessing.cpu_count() + 2)], - 'version': [MAKE_CMD, '--version'], - 'dry_run': [MAKE_CMD, '-n'], - 'verbose_flag': 'VERBOSE=1', - }) -]) - - -SUPPORTED_TARGETS = os.environ["SOC_SUPPORTED_TARGETS"].split(" ") - -PREVIEW_TARGETS = [''] diff --git a/bk7235/liteos_m/bk_sdk_armino/tools/build_tools/armino_actions/tools.py b/bk7235/liteos_m/bk_sdk_armino/tools/build_tools/armino_actions/tools.py deleted file mode 100644 index e45c391ecea866cf0c360927338f4a763089888b..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/tools/build_tools/armino_actions/tools.py +++ /dev/null @@ -1,352 +0,0 @@ -import os -import re -import subprocess -import sys -from io import open - -import click - -from .constants import GENERATORS -from .errors import FatalError - - -def executable_exists(args): - try: - subprocess.check_output(args) - return True - - except Exception: - return False - - -def realpath(path): - """ - Return the cannonical path with normalized case. - - It is useful on Windows to comparision paths in case-insensitive manner. - On Unix and Mac OS X it works as `os.path.realpath()` only. - """ - return os.path.normcase(os.path.realpath(path)) - - -def _armino_version_from_cmake(): - version_path = os.path.join(os.environ['ARMINO_PATH'], 'tools/cmake/version.cmake') - regex = re.compile(r'^\s*set\s*\(\s*ARMINO_VERSION_([A-Z]{5})\s+(\d+)') - ver = {} - try: - with open(version_path) as f: - for line in f: - m = regex.match(line) - - if m: - ver[m.group(1)] = m.group(2) - - return 'v%s.%s.%s' % (ver['MAJOR'], ver['MINOR'], ver['PATCH']) - except (KeyError, OSError): - sys.stderr.write('WARNING: Cannot find BEKEN-ARMINO version in version.cmake\n') - return None - - -def armino_version(): - """Print version of BEKEN-ARMINO""" - - # Try to get version from git: - try: - version = subprocess.check_output([ - 'git', - '--git-dir=%s' % os.path.join(os.environ['ARMINO_PATH'], '.git'), - '--work-tree=%s' % os.environ['ARMINO_PATH'], - 'describe', '--tags', '--dirty', '--match', 'v*.*', - ]).decode('utf-8', 'ignore').strip() - except (subprocess.CalledProcessError, UnicodeError): - # if failed, then try to parse cmake.version file - sys.stderr.write('WARNING: Git version unavailable, reading from source\n') - version = _armino_version_from_cmake() - - return version - - -def run_tool(tool_name, args, cwd, env=dict()): - def quote_arg(arg): - " Quote 'arg' if necessary " - if ' ' in arg and not (arg.startswith('"') or arg.startswith("'")): - return "'" + arg + "'" - return arg - - args = [str(arg) for arg in args] - display_args = ' '.join(quote_arg(arg) for arg in args) - print('Running %s in directory %s' % (tool_name, quote_arg(cwd))) - print('Executing "%s"...' % str(display_args)) - - env_copy = dict(os.environ) - env_copy.update(env) - - if sys.version_info[0] < 3: - # The subprocess lib cannot accept environment variables as "unicode". Convert to str. - # This encoding step is required only in Python 2. - for (key, val) in env_copy.items(): - if not isinstance(val, str): - env_copy[key] = val.encode(sys.getfilesystemencoding() or 'utf-8') - - try: - # Note: we explicitly pass in os.environ here, as we may have set ARMINO_PATH there during startup - subprocess.check_call(args, env=env_copy, cwd=cwd) - except subprocess.CalledProcessError as e: - raise FatalError('%s failed with exit code %d' % (tool_name, e.returncode)) - - -def run_target(target_name, args, env=dict()): - generator_cmd = GENERATORS[args.generator]['command'] - - if args.verbose: - generator_cmd += [GENERATORS[args.generator]['verbose_flag']] - - run_tool(generator_cmd[0], generator_cmd + [target_name], args.build_dir, env) - - -def _strip_quotes(value, regexp=re.compile(r"^\"(.*)\"$|^'(.*)'$|^(.*)$")): - """ - Strip quotes like CMake does during parsing cache entries - """ - - return [x for x in regexp.match(value).groups() if x is not None][0].rstrip() - - -def parse_cmakecache(path): - """ - Parse the CMakeCache file at 'path'. - - Returns a dict of name:value. - - CMakeCache entries also each have a "type", but this is currently ignored. - """ - result = {} - with open(path, encoding='utf-8') as f: - for line in f: - # cmake cache lines look like: CMAKE_CXX_FLAGS_DEBUG:STRING=-g - # groups are name, type, value - m = re.match(r'^([^#/:=]+):([^:=]+)=(.*)\n$', line) - if m: - result[m.group(1)] = m.group(3) - return result - - -def _new_cmakecache_entries(cache_path, new_cache_entries): - if not os.path.exists(cache_path): - return True - - if new_cache_entries: - current_cache = parse_cmakecache(cache_path) - - for entry in new_cache_entries: - key, value = entry.split('=', 1) - current_value = current_cache.get(key, None) - if current_value is None or _strip_quotes(value) != current_value: - return True - - return False - - -def _detect_cmake_generator(prog_name): - """ - Find the default cmake generator, if none was specified. Raises an exception if no valid generator is found. - """ - for (generator_name, generator) in GENERATORS.items(): - if executable_exists(generator['version']): - return generator_name - raise FatalError("To use %s, either the 'ninja' or 'GNU make' build tool must be available in the PATH" % prog_name) - - -def ensure_build_directory(args, prog_name, always_run_cmake=False): - """Check the build directory exists and that cmake has been run there. - - If this isn't the case, create the build directory (if necessary) and - do an initial cmake run to configure it. - - This function will also check args.generator parameter. If the parameter is incompatible with - the build directory, an error is raised. If the parameter is None, this function will set it to - an auto-detected default generator or to the value already configured in the build directory. - """ - project_dir = args.project_dir - # Verify the project directory - if not os.path.isdir(project_dir): - if not os.path.exists(project_dir): - raise FatalError('Project directory %s does not exist' % project_dir) - else: - raise FatalError('%s must be a project directory' % project_dir) - if not os.path.exists(os.path.join(project_dir, 'CMakeLists.txt')): - raise FatalError('CMakeLists.txt not found in project directory %s' % project_dir) - - # Verify/create the build directory - build_dir = args.build_dir - if not os.path.isdir(build_dir): - os.makedirs(build_dir) - - # Parse CMakeCache, if it exists - cache_path = os.path.join(build_dir, 'CMakeCache.txt') - cache = parse_cmakecache(cache_path) if os.path.exists(cache_path) else {} - - # Validate or set ARMINO_SOC - #_guess_or_check_armino_target(args, prog_name, cache) - - args.define_cache_entry.append('CCACHE_ENABLE=%d' % args.ccache) - - toolchain_dir = realpath(args.toolchain_dir) - - if always_run_cmake or _new_cmakecache_entries(cache_path, args.define_cache_entry): - if args.generator is None: - args.generator = _detect_cmake_generator(prog_name) - try: - cmake_args = [ - 'cmake', - '-G', - args.generator, - '-DPYTHON_DEPS_CHECKED=1', - '-DBEKEN_PLATFORM=1', - ] - if args.cmake_warn_uninitialized: - cmake_args += ['--warn-uninitialized'] - - if args.define_cache_entry: - cmake_args += ['-D' + d for d in args.define_cache_entry] - - cmake_args += [project_dir] - - run_tool('cmake', cmake_args, cwd=args.build_dir) - except Exception: - # don't allow partially valid CMakeCache.txt files, - # to keep the "should I run cmake?" logic simple - if os.path.exists(cache_path): - os.remove(cache_path) - raise - - # need to update cache so subsequent access in this method would reflect the result of the previous cmake run - cache = parse_cmakecache(cache_path) if os.path.exists(cache_path) else {} - - try: - generator = cache['CMAKE_GENERATOR'] - except KeyError: - generator = _detect_cmake_generator(prog_name) - if args.generator is None: - args.generator = (generator) # reuse the previously configured generator, if none was given - if generator != args.generator: - raise FatalError("Build is configured for generator '%s' not '%s'. Run '%s fullclean' to start again." % - (generator, args.generator, prog_name)) - - try: - home_dir = cache['CMAKE_HOME_DIRECTORY'] - if realpath(home_dir) != realpath(project_dir): - raise FatalError( - "Build directory '%s' configured for project '%s' not '%s'. Run '%s fullclean' to start again." % - (build_dir, realpath(home_dir), realpath(project_dir), prog_name)) - except KeyError: - pass # if cmake failed part way, CMAKE_HOME_DIRECTORY may not be set yet - - -def merge_action_lists(*action_lists): - merged_actions = { - 'global_options': [], - 'actions': {}, - 'global_action_callbacks': [], - } - for action_list in action_lists: - merged_actions['global_options'].extend(action_list.get('global_options', [])) - merged_actions['actions'].update(action_list.get('actions', {})) - merged_actions['global_action_callbacks'].extend(action_list.get('global_action_callbacks', [])) - return merged_actions - - -def get_sdkconfig_value(sdkconfig_file, key): - """ - Return the value of given key from sdkconfig_file. - If sdkconfig_file does not exist or the option is not present, returns None. - """ - assert key.startswith('CONFIG_') - if not os.path.exists(sdkconfig_file): - return None - # keep track of the last seen value for the given key - value = None - # if the value is quoted, this excludes the quotes from the value - pattern = re.compile(r"^{}=\"?([^\"]*)\"?$".format(key)) - with open(sdkconfig_file, 'r') as f: - for line in f: - match = re.match(pattern, line) - if match: - value = match.group(1) - return value - - -def is_target_supported(project_path, supported_targets): - """ - Returns True if the active target is supported, or False otherwise. - """ - return get_sdkconfig_value(os.path.join(project_path, 'sdkconfig'), 'CONFIG_SOC_STR') in supported_targets - - -def _guess_or_check_armino_target(args, prog_name, cache): - """ - If CMakeCache.txt doesn't exist, and ARMINO_SOC is not set in the environment, guess the value from - sdkconfig or sdkconfig.defaults, and pass it to CMake in ARMINO_SOC variable. - - Otherwise, cross-check the three settings (sdkconfig, CMakeCache, environment) and if there is - mismatch, fail with instructions on how to fix this. - """ - # Default locations of sdkconfig files. - # FIXME: they may be overridden in the project or by a CMake variable (ARMINO-1369). - sdkconfig_path = os.path.join(args.project_dir, 'sdkconfig') - sdkconfig_defaults_path = os.path.join(args.project_dir, 'sdkconfig.defaults') - - # These are used to guess the target from sdkconfig, or set the default target by sdkconfig.defaults. - armino_target_from_sdkconfig = get_sdkconfig_value(sdkconfig_path, 'CONFIG_SOC_STR') - armino_target_from_sdkconfig_defaults = get_sdkconfig_value(sdkconfig_defaults_path, 'CONFIG_SOC_STR') - armino_target_from_env = os.environ.get('ARMINO_SOC') - armino_target_from_cache = cache.get('ARMINO_SOC') - - if not cache and not armino_target_from_env: - # CMakeCache.txt does not exist yet, and ARMINO_SOC is not set in the environment. - guessed_target = armino_target_from_sdkconfig or armino_target_from_sdkconfig_defaults - if guessed_target: - if args.verbose: - print("ARMINO_SOC is not set, guessed '%s' from sdkconfig" % (guessed_target)) - args.define_cache_entry.append('ARMINO_SOC=' + guessed_target) - - elif armino_target_from_env: - # Let's check that ARMINO_SOC values are consistent - if armino_target_from_sdkconfig and armino_target_from_sdkconfig != armino_target_from_env: - raise FatalError("Project sdkconfig was generated for target '{t_conf}', but environment variable ARMINO_SOC " - "is set to '{t_env}'. Run '{prog} set-target {t_env}' to generate new sdkconfig file for target {t_env}." - .format(t_conf=armino_target_from_sdkconfig, t_env=armino_target_from_env, prog=prog_name)) - - if armino_target_from_cache and armino_target_from_cache != armino_target_from_env: - raise FatalError("Target settings are not consistent: '{t_env}' in the environment, '{t_cache}' in CMakeCache.txt. " - "Run '{prog} fullclean' to start again." - .format(t_env=armino_target_from_env, t_cache=armino_target_from_cache, prog=prog_name)) - - elif armino_target_from_cache and armino_target_from_sdkconfig and armino_target_from_cache != armino_target_from_sdkconfig: - # This shouldn't happen, unless the user manually edits CMakeCache.txt or sdkconfig, but let's check anyway. - raise FatalError("Project sdkconfig was generated for target '{t_conf}', but CMakeCache.txt contains '{t_cache}'. " - "To keep the setting in sdkconfig ({t_conf}) and re-generate CMakeCache.txt, run '{prog} fullclean'. " - "To re-generate sdkconfig for '{t_cache}' target, run '{prog} set-target {t_cache}'." - .format(t_conf=armino_target_from_sdkconfig, t_cache=armino_target_from_cache, prog=prog_name)) - - -class TargetChoice(click.Choice): - """ - A version of click.Choice with two special features: - - ignores hyphens - - not case sensitive - """ - def __init__(self, choices): - super(TargetChoice, self).__init__(choices, case_sensitive=False) - - def convert(self, value, param, ctx): - def normalize(str): - return str.lower().replace('-', '') - - saved_token_normalize_func = ctx.token_normalize_func - ctx.token_normalize_func = normalize - - try: - return super(TargetChoice, self).convert(value, param, ctx) - finally: - ctx.token_normalize_func = saved_token_normalize_func diff --git a/bk7235/liteos_m/bk_sdk_armino/tools/build_tools/cmake/convert_to_cmake.py b/bk7235/liteos_m/bk_sdk_armino/tools/build_tools/cmake/convert_to_cmake.py deleted file mode 100755 index 083f8ac1ea9ddfafc7cafe4c3bb7d487514714db..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/tools/build_tools/cmake/convert_to_cmake.py +++ /dev/null @@ -1,205 +0,0 @@ -#!/usr/bin/env python -# -# Command line tool to convert simple BEKEN-ARMINO Makefile & component.mk files to -# CMakeLists.txt files -# -import argparse -import subprocess -import re -import os.path -import glob - -debug = False - - -def get_make_variables(path, makefile="Makefile", expected_failure=False, variables={}): - """ - Given the path to a Makefile of some kind, return a dictionary of all variables defined in this Makefile - - Uses 'make' to parse the Makefile syntax, so we don't have to! - - Overrides ARMINO_PATH= to avoid recursively evaluating the entire project Makefile structure. - """ - variable_setters = [("%s=%s" % (k,v)) for (k,v) in variables.items()] - - cmdline = ["make", "-rpn", "-C", path, "-f", makefile] + variable_setters - if debug: - print("Running %s..." % (" ".join(cmdline))) - - p = subprocess.Popen(cmdline, stdout=subprocess.PIPE, stderr=subprocess.PIPE) - (output, stderr) = p.communicate("\n") - - if (not expected_failure) and p.returncode != 0: - raise RuntimeError("Unexpected make failure, result %d" % p.returncode) - - if debug: - print("Make stdout:") - print(output) - print("Make stderr:") - print(stderr) - - next_is_makefile = False # is the next line a makefile variable? - result = {} - BUILT_IN_VARS = set(["MAKEFILE_LIST", "SHELL", "CURDIR", "MAKEFLAGS"]) - - for line in output.decode('utf-8').split("\n"): - if line.startswith("# makefile"): # this line appears before any variable defined in the makefile itself - next_is_makefile = True - elif next_is_makefile: - next_is_makefile = False - m = re.match(r"(?P[^ ]+) :?= (?P.+)", line) - if m is not None: - if not m.group("var") in BUILT_IN_VARS: - result[m.group("var")] = m.group("val").strip() - - return result - - -def get_component_variables(project_path, component_path): - make_vars = get_make_variables(component_path, - os.path.join(os.environ["ARMINO_PATH"], - "make", - "component_wrapper.mk"), - expected_failure=True, - variables={ - "COMPONENT_MAKEFILE": os.path.join(component_path, "component.mk"), - "COMPONENT_NAME": os.path.basename(component_path), - "PROJECT_PATH": project_path, - }) - - if "COMPONENT_OBJS" in make_vars: # component.mk specifies list of object files - # Convert to sources - def find_src(obj): - obj = os.path.splitext(obj)[0] - for ext in ["c", "cpp", "S"]: - if os.path.exists(os.path.join(component_path, obj) + "." + ext): - return obj + "." + ext - print("WARNING: Can't find source file for component %s COMPONENT_OBJS %s" % (component_path, obj)) - return None - - srcs = [] - for obj in make_vars["COMPONENT_OBJS"].split(): - src = find_src(obj) - if src is not None: - srcs.append(src) - make_vars["COMPONENT_SRCS"] = " ".join(srcs) - else: - component_srcs = list() - for component_srcdir in make_vars.get("COMPONENT_SRCDIRS", ".").split(): - component_srcdir_path = os.path.abspath(os.path.join(component_path, component_srcdir)) - - srcs = list() - srcs += glob.glob(os.path.join(component_srcdir_path, "*.[cS]")) - srcs += glob.glob(os.path.join(component_srcdir_path, "*.cpp")) - srcs = [('"%s"' % str(os.path.relpath(s, component_path))) for s in srcs] - - make_vars["COMPONENT_ADD_INCLUDEDIRS"] = make_vars.get("COMPONENT_ADD_INCLUDEDIRS", "include") - component_srcs += srcs - make_vars["COMPONENT_SRCS"] = " ".join(component_srcs) - - return make_vars - - -def convert_project(project_path): - if not os.path.exists(project_path): - raise RuntimeError("Project directory '%s' not found" % project_path) - if not os.path.exists(os.path.join(project_path, "Makefile")): - raise RuntimeError("Directory '%s' doesn't contain a project Makefile" % project_path) - - project_cmakelists = os.path.join(project_path, "CMakeLists.txt") - if os.path.exists(project_cmakelists): - raise RuntimeError("This project already has a CMakeLists.txt file") - - project_vars = get_make_variables(project_path, expected_failure=True) - if "PROJECT_NAME" not in project_vars: - raise RuntimeError("PROJECT_NAME does not appear to be defined in ARMINO project Makefile at %s" % project_path) - - component_paths = project_vars["COMPONENT_PATHS"].split() - - converted_components = 0 - - # Convert components as needed - for p in component_paths: - if "MSYSTEM" in os.environ: - cmd = ["cygpath", "-w", p] - p = subprocess.check_output(cmd).decode('utf-8').strip() - - converted_components += convert_component(project_path, p) - - project_name = project_vars["PROJECT_NAME"] - - # Generate the project CMakeLists.txt file - with open(project_cmakelists, "w") as f: - f.write(""" -# (Automatically converted from project Makefile by convert_to_cmake.py.) - -# The following lines of boilerplate have to be in your project's CMakeLists -# in this exact order for cmake to work correctly -cmake_minimum_required(VERSION 3.5) - -""") - f.write(""" -include($ENV{ARMINO_PATH}/tools/cmake/project.cmake) -""") - f.write("project(%s)\n" % project_name) - - print("Converted project %s" % project_cmakelists) - - if converted_components > 0: - print("Note: Newly created component CMakeLists.txt do not have any REQUIRES or PRIV_REQUIRES " - "lists to declare their component requirements. Builds may fail to include other " - "components' header files. If so requirements need to be added to the components' " - "CMakeLists.txt files. See the 'Component Requirements' section of the " - "Build System docs for more details.") - - -def convert_component(project_path, component_path): - if debug: - print("Converting %s..." % (component_path)) - cmakelists_path = os.path.join(component_path, "CMakeLists.txt") - if os.path.exists(cmakelists_path): - print("Skipping already-converted component %s..." % cmakelists_path) - return 0 - v = get_component_variables(project_path, component_path) - - # Look up all the variables before we start writing the file, so it's not - # created if there's an erro - component_srcs = v.get("COMPONENT_SRCS", None) - - component_add_includedirs = v["COMPONENT_ADD_INCLUDEDIRS"] - cflags = v.get("CFLAGS", None) - - with open(cmakelists_path, "w") as f: - if component_srcs is not None: - f.write("armino_component_register(SRCS %s)\n" % component_srcs) - f.write(" INCLUDE_DIRS %s" % component_add_includedirs) - f.write(" # Edit following two lines to set component requirements (see docs)\n") - f.write(" REQUIRES "")\n") - f.write(" PRIV_REQUIRES "")\n\n") - else: - f.write("armino_component_register()\n") - if cflags is not None: - f.write("target_compile_options(${COMPONENT_LIB} PRIVATE %s)\n" % cflags) - - print("Converted %s" % cmakelists_path) - return 1 - - -def main(): - global debug - - parser = argparse.ArgumentParser(description='convert_to_cmake.py - BEKEN-ARMINO Project Makefile to CMakeLists.txt converter', prog='convert_to_cmake') - - parser.add_argument('--debug', help='Display debugging output', - action='store_true') - - parser.add_argument('project', help='Path to project to convert (defaults to CWD)', default=os.getcwd(), metavar='project path', nargs='?') - - args = parser.parse_args() - debug = args.debug - print("Converting %s..." % args.project) - convert_project(args.project) - - -if __name__ == "__main__": - main() diff --git a/bk7235/liteos_m/bk_sdk_armino/tools/build_tools/kconfig_new/confserver.py b/bk7235/liteos_m/bk_sdk_armino/tools/build_tools/kconfig_new/confserver.py deleted file mode 100755 index 04f27a6d83a0583789335137cf4b2e9aa4ca61bc..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/tools/build_tools/kconfig_new/confserver.py +++ /dev/null @@ -1,328 +0,0 @@ -#!/usr/bin/env python -# -# Long-running server process uses stdin & stdout to communicate JSON -# with a caller -# -from __future__ import print_function -import argparse -import confgen -import json -import os -import sys -import tempfile -from confgen import FatalError, __version__ - -try: - from . import kconfiglib -except Exception: - sys.path.insert(0, os.path.dirname(os.path.realpath(__file__))) - import kconfiglib - -# Min/Max supported protocol versions -MIN_PROTOCOL_VERSION = 1 -MAX_PROTOCOL_VERSION = 2 - - -def main(): - parser = argparse.ArgumentParser(description='confserver.py v%s - Config Generation Tool' % __version__, prog=os.path.basename(sys.argv[0])) - - parser.add_argument('--config', - help='Project configuration settings', - required=True) - - parser.add_argument('--kconfig', - help='KConfig file with config item definitions', - required=True) - - parser.add_argument('--sdkconfig-rename', - help='File with deprecated Kconfig options', - required=False) - - parser.add_argument('--env', action='append', default=[], - help='Environment to set when evaluating the config file', metavar='NAME=VAL') - - parser.add_argument('--env-file', type=argparse.FileType('r'), - help='Optional file to load environment variables from. Contents ' - 'should be a JSON object where each key/value pair is a variable.') - - parser.add_argument('--version', help='Set protocol version to use on initial status', - type=int, default=MAX_PROTOCOL_VERSION) - - args = parser.parse_args() - - if args.version < MIN_PROTOCOL_VERSION: - print("Version %d is older than minimum supported protocol version %d. Client is much older than BEKEN-ARMINO version?" % - (args.version, MIN_PROTOCOL_VERSION)) - - if args.version > MAX_PROTOCOL_VERSION: - print("Version %d is newer than maximum supported protocol version %d. Client is newer than BEKEN-ARMINO version?" % - (args.version, MAX_PROTOCOL_VERSION)) - - try: - args.env = [(name,value) for (name,value) in (e.split("=",1) for e in args.env)] - except ValueError: - print("--env arguments must each contain =. To unset an environment variable, use 'ENV='") - sys.exit(1) - - for name, value in args.env: - os.environ[name] = value - - if args.env_file is not None: - env = json.load(args.env_file) - os.environ.update(confgen.dict_enc_for_env(env)) - - run_server(args.kconfig, args.config, args.sdkconfig_rename) - - -def run_server(kconfig, sdkconfig, sdkconfig_rename, default_version=MAX_PROTOCOL_VERSION): - config = kconfiglib.Kconfig(kconfig) - sdkconfig_renames = [sdkconfig_rename] if sdkconfig_rename else [] - sdkconfig_renames += os.environ.get("COMPONENT_SDKCONFIG_RENAMES", "").split() - deprecated_options = confgen.DeprecatedOptions(config.config_prefix, path_rename_files=sdkconfig_renames) - f_o = tempfile.NamedTemporaryFile(mode='w+b', delete=False) - try: - with open(sdkconfig, mode='rb') as f_i: - f_o.write(f_i.read()) - f_o.close() # need to close as DeprecatedOptions will reopen, and Windows only allows one open file - deprecated_options.replace(sdkconfig_in=f_o.name, sdkconfig_out=sdkconfig) - finally: - os.unlink(f_o.name) - config.load_config(sdkconfig) - - print("Server running, waiting for requests on stdin...", file=sys.stderr) - - config_dict = confgen.get_json_values(config) - ranges_dict = get_ranges(config) - visible_dict = get_visible(config) - - if default_version == 1: - # V1: no 'visibility' key, send value None for any invisible item - values_dict = dict((k, v if visible_dict[k] else False) for (k,v) in config_dict.items()) - json.dump({"version": 1, "values": values_dict, "ranges": ranges_dict}, sys.stdout) - else: - # V2 onwards: separate visibility from version - json.dump({"version": default_version, "values": config_dict, "ranges": ranges_dict, "visible": visible_dict}, sys.stdout) - print("\n") - sys.stdout.flush() - - while True: - line = sys.stdin.readline() - if not line: - break - try: - req = json.loads(line) - except ValueError as e: # json module throws JSONDecodeError (sublcass of ValueError) on Py3 but ValueError on Py2 - response = {"version": default_version, "error": ["JSON formatting error: %s" % e]} - json.dump(response, sys.stdout) - print("\n") - sys.stdout.flush() - continue - before = confgen.get_json_values(config) - before_ranges = get_ranges(config) - before_visible = get_visible(config) - - if "load" in req: # load a new sdkconfig - - if req.get("version", default_version) == 1: - # for V1 protocol, send all items when loading new sdkconfig. - # (V2+ will only send changes, same as when setting an item) - before = {} - before_ranges = {} - before_visible = {} - - # if no new filename is supplied, use existing sdkconfig path, otherwise update the path - if req["load"] is None: - req["load"] = sdkconfig - else: - sdkconfig = req["load"] - - if "save" in req: - if req["save"] is None: - req["save"] = sdkconfig - else: - sdkconfig = req["save"] - - error = handle_request(deprecated_options, config, req) - - after = confgen.get_json_values(config) - after_ranges = get_ranges(config) - after_visible = get_visible(config) - - values_diff = diff(before, after) - ranges_diff = diff(before_ranges, after_ranges) - visible_diff = diff(before_visible, after_visible) - if req["version"] == 1: - # V1 response, invisible items have value None - for k in (k for (k,v) in visible_diff.items() if not v): - values_diff[k] = None - response = {"version": 1, "values": values_diff, "ranges": ranges_diff} - else: - # V2+ response, separate visibility values - response = {"version": req["version"], "values": values_diff, "ranges": ranges_diff, "visible": visible_diff} - if error: - for e in error: - print("Error: %s" % e, file=sys.stderr) - response["error"] = error - json.dump(response, sys.stdout) - print("\n") - sys.stdout.flush() - - -def handle_request(deprecated_options, config, req): - if "version" not in req: - return ["All requests must have a 'version'"] - - if req["version"] < MIN_PROTOCOL_VERSION or req["version"] > MAX_PROTOCOL_VERSION: - return ["Unsupported request version %d. Server supports versions %d-%d" % ( - req["version"], - MIN_PROTOCOL_VERSION, - MAX_PROTOCOL_VERSION)] - - error = [] - - if "load" in req: - print("Loading config from %s..." % req["load"], file=sys.stderr) - try: - config.load_config(req["load"]) - except Exception as e: - error += ["Failed to load from %s: %s" % (req["load"], e)] - - if "set" in req: - handle_set(config, error, req["set"]) - - if "save" in req: - try: - print("Saving config to %s..." % req["save"], file=sys.stderr) - confgen.write_config(deprecated_options, config, req["save"]) - except Exception as e: - error += ["Failed to save to %s: %s" % (req["save"], e)] - - return error - - -def handle_set(config, error, to_set): - missing = [k for k in to_set if k not in config.syms] - if missing: - error.append("The following config symbol(s) were not found: %s" % (", ".join(missing))) - # replace name keys with the full config symbol for each key: - to_set = dict((config.syms[k],v) for (k,v) in to_set.items() if k not in missing) - - # Work through the list of values to set, noting that - # some may not be immediately applicable (maybe they depend - # on another value which is being set). Therefore, defer - # knowing if any value is unsettable until then end - - while len(to_set): - set_pass = [(k,v) for (k,v) in to_set.items() if k.visibility] - if not set_pass: - break # no visible keys left - for (sym,val) in set_pass: - if sym.type in (kconfiglib.BOOL, kconfiglib.TRISTATE): - if val is True: - sym.set_value(2) - elif val is False: - sym.set_value(0) - else: - error.append("Boolean symbol %s only accepts true/false values" % sym.name) - elif sym.type == kconfiglib.HEX: - try: - if not isinstance(val, int): - val = int(val, 16) # input can be a decimal JSON value or a string of hex digits - sym.set_value(hex(val)) - except ValueError: - error.append("Hex symbol %s can accept a decimal integer or a string of hex digits, only") - else: - sym.set_value(str(val)) - print("Set %s" % sym.name) - del to_set[sym] - - if len(to_set): - error.append("The following config symbol(s) were not visible so were not updated: %s" % (", ".join(s.name for s in to_set))) - - -def diff(before, after): - """ - Return a dictionary with the difference between 'before' and 'after', - for items which are present in 'after' dictionary - """ - diff = dict((k,v) for (k,v) in after.items() if before.get(k, None) != v) - return diff - - -def get_ranges(config): - ranges_dict = {} - - def is_base_n(i, n): - try: - int(i, n) - return True - except ValueError: - return False - - def get_active_range(sym): - """ - Returns a tuple of (low, high) integer values if a range - limit is active for this symbol, or (None, None) if no range - limit exists. - """ - base = kconfiglib._TYPE_TO_BASE[sym.orig_type] if sym.orig_type in kconfiglib._TYPE_TO_BASE else 0 - - try: - for low_expr, high_expr, cond in sym.ranges: - if kconfiglib.expr_value(cond): - low = int(low_expr.str_value, base) if is_base_n(low_expr.str_value, base) else 0 - high = int(high_expr.str_value, base) if is_base_n(high_expr.str_value, base) else 0 - return (low, high) - except ValueError: - pass - return (None, None) - - def handle_node(node): - sym = node.item - if not isinstance(sym, kconfiglib.Symbol): - return - active_range = get_active_range(sym) - if active_range[0] is not None: - ranges_dict[sym.name] = active_range - - for n in config.node_iter(): - handle_node(n) - return ranges_dict - - -def get_visible(config): - """ - Return a dict mapping node IDs (config names or menu node IDs) to True/False for their visibility - """ - result = {} - menus = [] - - # when walking the menu the first time, only - # record whether the config symbols are visible - # and make a list of menu nodes (that are not symbols) - def handle_node(node): - sym = node.item - try: - visible = (sym.visibility != 0) - result[node] = visible - except AttributeError: - menus.append(node) - for n in config.node_iter(): - handle_node(n) - - # now, figure out visibility for each menu. A menu is visible if any of its children are visible - for m in reversed(menus): # reverse to start at leaf nodes - result[m] = any(v for (n,v) in result.items() if n.parent == m) - - # return a dict mapping the node ID to its visibility. - result = dict((confgen.get_menu_node_id(n),v) for (n,v) in result.items()) - - return result - - -if __name__ == '__main__': - try: - main() - except FatalError as e: - print("A fatal error occurred: %s" % e, file=sys.stderr) - sys.exit(2) diff --git a/bk7235/liteos_m/bk_sdk_armino/tools/build_tools/kconfig_new/kconfiglib.py b/bk7235/liteos_m/bk_sdk_armino/tools/build_tools/kconfig_new/kconfiglib.py deleted file mode 100644 index c0a5b2ab6973523c0f311a70937e30456c120452..0000000000000000000000000000000000000000 --- a/bk7235/liteos_m/bk_sdk_armino/tools/build_tools/kconfig_new/kconfiglib.py +++ /dev/null @@ -1,7153 +0,0 @@ -# Copyright (c) 2011-2019, Ulf Magnusson -# SPDX-License-Identifier: ISC - -""" -Overview -======== - -Kconfiglib is a Python 2/3 library for scripting and extracting information -from Kconfig (https://www.kernel.org/doc/Documentation/kbuild/kconfig-language.txt) -configuration systems. - -See the homepage at https://github.com/ulfalizer/Kconfiglib for a longer -overview. - -Since Kconfiglib 12.0.0, the library version is available in -kconfiglib.VERSION, which is a (, , ) tuple, e.g. -(12, 0, 0). - - -Using Kconfiglib on the Linux kernel with the Makefile targets -============================================================== - -For the Linux kernel, a handy interface is provided by the -scripts/kconfig/Makefile patch, which can be applied with either 'git am' or -the 'patch' utility: - - $ wget -qO- https://raw.githubusercontent.com/ulfalizer/Kconfiglib/master/makefile.patch | git am - $ wget -qO- https://raw.githubusercontent.com/ulfalizer/Kconfiglib/master/makefile.patch | patch -p1 - -Warning: Not passing -p1 to patch will cause the wrong file to be patched. - -Please tell me if the patch does not apply. It should be trivial to apply -manually, as it's just a block of text that needs to be inserted near the other -*conf: targets in scripts/kconfig/Makefile. - -Look further down for a motivation for the Makefile patch and for instructions -on how you can use Kconfiglib without it. - -If you do not wish to install Kconfiglib via pip, the Makefile patch is set up -so that you can also just clone Kconfiglib into the kernel root: - - $ git clone git://github.com/ulfalizer/Kconfiglib.git - $ git am Kconfiglib/makefile.patch (or 'patch -p1 < Kconfiglib/makefile.patch') - -Warning: The directory name Kconfiglib/ is significant in this case, because -it's added to PYTHONPATH by the new targets in makefile.patch. - -The targets added by the Makefile patch are described in the following -sections. - - -make kmenuconfig ----------------- - -This target runs the curses menuconfig interface with Python 3. As of -Kconfiglib 12.2.0, both Python 2 and Python 3 are supported (previously, only -Python 3 was supported, so this was a backport). - - -make guiconfig --------------- - -This target runs the Tkinter menuconfig interface. Both Python 2 and Python 3 -are supported. To change the Python interpreter used, pass -PYTHONCMD= to 'make'. The default is 'python'. - - -make [ARCH=] iscriptconfig --------------------------------- - -This target gives an interactive Python prompt where a Kconfig instance has -been preloaded and is available in 'kconf'. To change the Python interpreter -used, pass PYTHONCMD= to 'make'. The default is 'python'. - -To get a feel for the API, try evaluating and printing the symbols in -kconf.defined_syms, and explore the MenuNode menu tree starting at -kconf.top_node by following 'next' and 'list' pointers. - -The item contained in a menu node is found in MenuNode.item (note that this can -be one of the constants kconfiglib.MENU and kconfiglib.COMMENT), and all -symbols and choices have a 'nodes' attribute containing their menu nodes -(usually only one). Printing a menu node will print its item, in Kconfig -format. - -If you want to look up a symbol by name, use the kconf.syms dictionary. - - -make scriptconfig SCRIPT=