From 58390d6ee43d5cd529456c3a26b0cec906a5fa6f Mon Sep 17 00:00:00 2001 From: wlyu Date: Wed, 9 Mar 2022 16:51:47 +0800 Subject: [PATCH] 1. optimize plc relative codes 2. fixed ShowChannel exception 3. optimize RTC codes 4. compatible memory lds with USB --- .../Applications/app_test/test_adc.c | 5 +- .../control_app/plc_demo/plc_control_demo.c | 2 - .../control_app/plc_demo/plc_demo.h | 3 + .../control_app/plc_demo/plc_show_demo.c | 67 ++--- .../plc/interoperability/opcua/open62541.c | 12 - .../Framework/control/plc/shared/Makefile | 2 +- .../Framework/control/plc/shared/plc_ch.c | 129 --------- .../Framework/control/plc/shared/plc_ch.h | 64 ----- .../plc/shared/{channel.c => plc_channel.c} | 107 +++++++- .../plc/shared/{channel.h => plc_channel.h} | 37 ++- .../plc/shared/{plc_dev.c => plc_device.c} | 4 +- .../plc/shared/{plc_dev.h => plc_device.h} | 2 +- .../plc/shared/{plc_drv.c => plc_driver.c} | 4 +- Ubiquitous/XiZi/board/ok1052-c/board.c | 16 ++ Ubiquitous/XiZi/board/ok1052-c/config.mk | 12 +- Ubiquitous/XiZi/board/ok1052-c/link-usb.lds | 250 ++++++++++++++++++ Ubiquitous/XiZi/board/ok1052-c/link.lds | 4 +- .../third_party_driver/include/connect_rtc.h | 3 +- .../third_party_driver/rtc/connect_rtc.c | 194 ++++++++++++-- Ubiquitous/XiZi/tool/shell/Kconfig | 16 +- 20 files changed, 647 insertions(+), 286 deletions(-) delete mode 100755 APP_Framework/Framework/control/plc/shared/plc_ch.c delete mode 100755 APP_Framework/Framework/control/plc/shared/plc_ch.h rename APP_Framework/Framework/control/plc/shared/{channel.c => plc_channel.c} (78%) rename APP_Framework/Framework/control/plc/shared/{channel.h => plc_channel.h} (86%) rename APP_Framework/Framework/control/plc/shared/{plc_dev.c => plc_device.c} (98%) rename APP_Framework/Framework/control/plc/shared/{plc_dev.h => plc_device.h} (99%) rename APP_Framework/Framework/control/plc/shared/{plc_drv.c => plc_driver.c} (97%) create mode 100755 Ubiquitous/XiZi/board/ok1052-c/link-usb.lds diff --git a/APP_Framework/Applications/app_test/test_adc.c b/APP_Framework/Applications/app_test/test_adc.c index 1ff547f9c..e6ab38ec1 100644 --- a/APP_Framework/Applications/app_test/test_adc.c +++ b/APP_Framework/Applications/app_test/test_adc.c @@ -56,5 +56,6 @@ void test_adc() return; } -// SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN), -// test_adc, test_adc, read 3.3 voltage data from adc); + + SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN), + adc, test_adc, read 3.3 voltage data from adc); diff --git a/APP_Framework/Applications/control_app/plc_demo/plc_control_demo.c b/APP_Framework/Applications/control_app/plc_demo/plc_control_demo.c index cec5d53e1..d8f480d59 100755 --- a/APP_Framework/Applications/control_app/plc_demo/plc_control_demo.c +++ b/APP_Framework/Applications/control_app/plc_demo/plc_control_demo.c @@ -22,8 +22,6 @@ #include "open62541.h" #include "ua_api.h" #include "sys_arch.h" -#include "plc_ch.h" -#include "plc_dev.h" #include "plc_demo.h" #define PLC_NS_FORMAT "n%d,%s" diff --git a/APP_Framework/Applications/control_app/plc_demo/plc_demo.h b/APP_Framework/Applications/control_app/plc_demo/plc_demo.h index 45df0f4fa..12096936e 100755 --- a/APP_Framework/Applications/control_app/plc_demo/plc_demo.h +++ b/APP_Framework/Applications/control_app/plc_demo/plc_demo.h @@ -21,6 +21,9 @@ #ifndef __PLC_DEMO_H_ #define __PLC_DEMO_H_ +#include "plc_channel.h" +#include "plc_device.h" + #define PLC_CH_NAME "PLC" #define PLC_DRV_NAME "OPCUA" diff --git a/APP_Framework/Applications/control_app/plc_demo/plc_show_demo.c b/APP_Framework/Applications/control_app/plc_demo/plc_show_demo.c index 87864b3b8..71a15a20d 100755 --- a/APP_Framework/Applications/control_app/plc_demo/plc_show_demo.c +++ b/APP_Framework/Applications/control_app/plc_demo/plc_show_demo.c @@ -24,8 +24,6 @@ #include "open62541.h" #include "ua_api.h" #include "sys_arch.h" -#include "plc_ch.h" -#include "plc_dev.h" #include "plc_demo.h" @@ -59,6 +57,8 @@ static char* const channel_type_str[] = extern DoublelistType plcdev_list; extern DoublelistType ch_linklist; +/**********************************************************************************************************************/ + void PlcShowTitle(const char* item_array[]) { int i = 0, max_len = 65; @@ -94,6 +94,37 @@ static ChDrvType ShowChannelFindDriver(struct Channel* ch) return NONE; } +static void PlcShowDemoInit(void) +{ + static uint8_t init_flag = 0; + int i; + PlcDemoChannelDrvInit(); + + for(i = 0; i < PLC_DEMO_NUM; i++) + { + // register plc device + plc_demo_array[i].state = CHDEV_INIT; + snprintf(plc_demo_array[i].name, PLC_NAME_SIZE, "PLC Demo %d", i); + plc_demo_array[i].info.vendor = plc_demo_param[i].vector; + plc_demo_array[i].info.model = plc_demo_param[i].model; + plc_demo_array[i].info.id = plc_demo_param[i].id; + plc_demo_array[i].info.product = plc_demo_param[i].product; + plc_demo_array[i].net = PLC_IND_ENET_OPCUA; + } + + if(init_flag) + return; + init_flag = 1; + + for(i = 0; i < PLC_DEMO_NUM; i++) + { + if(PlcDevRegister(&plc_demo_array[i], NULL, plc_demo_array[i].name) == EOK) + { + PlcDeviceAttachToChannel(plc_demo_array[i].name, PLC_CH_NAME); + } + } +} + void PlcShowChannel(void) { ChannelType ch; @@ -103,6 +134,7 @@ void PlcShowChannel(void) DoublelistType* ch_node = NONE; DoublelistType* ch_head = &ch_linklist; const char* item_array[] = {"ch_type", "ch_name", "drv_name", "dev_name", "cnt"}; + PlcShowDemoInit(); PlcShowTitle(item_array); ch_node = ch_head->node_next; @@ -184,37 +216,6 @@ void PlcShowChannel(void) SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0) | SHELL_CMD_TYPE(SHELL_TYPE_CMD_MAIN) | SHELL_CMD_PARAM_NUM(3), ShowChannel, PlcShowChannel, Show PLC information); -static void PlcShowDemoInit(void) -{ - static uint8_t init_flag = 0; - int i; - PlcDemoChannelDrvInit(); - - for(i = 0; i < PLC_DEMO_NUM; i++) - { - // register plc device - plc_demo_array[i].state = CHDEV_INIT; - snprintf(plc_demo_array[i].name, PLC_NAME_SIZE, "PLC Demo %d", i); - plc_demo_array[i].info.vendor = plc_demo_param[i].vector; - plc_demo_array[i].info.model = plc_demo_param[i].model; - plc_demo_array[i].info.id = plc_demo_param[i].id; - plc_demo_array[i].info.product = plc_demo_param[i].product; - plc_demo_array[i].net = PLC_IND_ENET_OPCUA; - } - - if(init_flag) - return; - init_flag = 1; - - for(i = 0; i < PLC_DEMO_NUM; i++) - { - if(PlcDevRegister(&plc_demo_array[i], NULL, plc_demo_array[i].name) == EOK) - { - PlcDeviceAttachToChannel(plc_demo_array[i].name, PLC_CH_NAME); - } - } -} - void PlcShowDev(void) { PlcDeviceType* plc_dev; diff --git a/APP_Framework/Framework/control/plc/interoperability/opcua/open62541.c b/APP_Framework/Framework/control/plc/interoperability/opcua/open62541.c index 83d4b6732..3da01d2b7 100755 --- a/APP_Framework/Framework/control/plc/interoperability/opcua/open62541.c +++ b/APP_Framework/Framework/control/plc/interoperability/opcua/open62541.c @@ -15,18 +15,6 @@ * A PARTICULAR PURPOSE. */ -/* - * Copyright (c) 2021 AIIT XUOS Lab - * XiUOS is licensed under Mulan PSL v2. - * You can use this software according to the terms and conditions of the Mulan PSL v2. - * You may obtain a copy of Mulan PSL v2 at: - * http://license.coscl.org.cn/MulanPSL2 - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, - * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, - * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. - * See the Mulan PSL v2 for more details. - */ - /** * @file open62541.c * @brief Support OPCUA protocol diff --git a/APP_Framework/Framework/control/plc/shared/Makefile b/APP_Framework/Framework/control/plc/shared/Makefile index e72134886..1a56440e3 100755 --- a/APP_Framework/Framework/control/plc/shared/Makefile +++ b/APP_Framework/Framework/control/plc/shared/Makefile @@ -1,4 +1,4 @@ -SRC_FILES := plc_dev.c plc_ch.c plc_drv.c channel.c +SRC_FILES := plc_device.c plc_channel.c plc_driver.c include $(KERNEL_ROOT)/compiler.mk diff --git a/APP_Framework/Framework/control/plc/shared/plc_ch.c b/APP_Framework/Framework/control/plc/shared/plc_ch.c deleted file mode 100755 index f2b83abd5..000000000 --- a/APP_Framework/Framework/control/plc/shared/plc_ch.c +++ /dev/null @@ -1,129 +0,0 @@ -/* -* Copyright (c) 2022 AIIT XUOS Lab -* XiUOS is licensed under Mulan PSL v2. -* You can use this software according to the terms and conditions of the Mulan PSL v2. -* You may obtain a copy of Mulan PSL v2 at: -* http://license.coscl.org.cn/MulanPSL2 -* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, -* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, -* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. -* See the Mulan PSL v2 for more details. -*/ - -/** -* @file plc_ch.c -* @brief register plc channel function using channel driver framework -* @version 1.0 -* @author AIIT XUOS Lab -* @date 2022-01-24 -*/ - -#include "string.h" -#include "plc_ch.h" -#include "plc_dev.h" - -/******************************************************************************/ - -int PlcChannelInit(struct PlcChannel* plc_ch, const char* ch_name) -{ - CHECK_CH_PARAM(plc_ch); - CHECK_CH_PARAM(ch_name); - int ret = EOK; - - if(CHANNEL_INSTALL != plc_ch->ch.ch_state) - { - strncpy(plc_ch->ch.ch_name, ch_name, NAME_NUM_MAX); - plc_ch->ch.ch_type = CH_PLC_TYPE; - plc_ch->ch.ch_state = CHANNEL_INSTALL; - plc_ch->ch.private_data = plc_ch->private_data; - ret = ChannelRegister(&plc_ch->ch); - - if(EOK != ret) - { - KPrintf("PlcChannelInit ChannelRegister error %u\n", ret); - return ret; - } - } - else - { - KPrintf("PlcChannelInit ChannelRegister channel has been register state %u\n", - plc_ch->ch.ch_state); - } - - return ret; -} - -int PlcDriverInit(struct PlcDriver* plc_driver, const char* driver_name) -{ - CHECK_CH_PARAM(plc_driver); - CHECK_CH_PARAM(driver_name); - int ret = EOK; - - if(CHDRV_INSTALL != plc_driver->driver.driver_state) - { - plc_driver->driver.driver_type = CHDRV_PLC_TYPE; - plc_driver->driver.driver_state = CHDRV_INSTALL; - strncpy(plc_driver->driver.drv_name, driver_name, NAME_NUM_MAX); - plc_driver->driver.configure = plc_driver->configure; - ret = PlcDriverRegister(&plc_driver->driver); - - if(EOK != ret) - { - KPrintf("PlcDriverInit DriverRegister error %u\n", ret); - return ret; - } - } - else - { - KPrintf("PlcDriverInit Driver %s has been register state %u\n", - driver_name, plc_driver->driver.driver_state); - } - - return ret; -} - -int PlcReleaseChannel(struct PlcChannel* plc_ch) -{ - CHECK_CH_PARAM(plc_ch); - return ChannelRelease(&plc_ch->ch); -} - -int PlcDriverAttachToChannel(const char* drv_name, const char* ch_name) -{ - CHECK_CH_PARAM(drv_name); - CHECK_CH_PARAM(ch_name); - int ret = EOK; - struct Channel* ch; - struct ChDrv* driver; - ch = ChannelFind(ch_name); - - if(NONE == ch) - { - KPrintf("PlcDriverAttachToChannel find plc channel error!name %s\n", ch_name); - return ERROR; - } - - if(CH_PLC_TYPE == ch->ch_type) - { - driver = PlcDriverFind(drv_name, CHDRV_PLC_TYPE); - - if(NONE == driver) - { - KPrintf("PlcDriverAttachToChannel find plc driver error!name %s\n", drv_name); - return ERROR; - } - - if(CHDRV_PLC_TYPE == driver->driver_type) - { - ret = DriverRegisterToChannel(ch, driver); - - if(EOK != ret) - { - KPrintf("PlcDriverAttachToChannel DriverRegisterToBus error %u\n", ret); - return ERROR; - } - } - } - - return ret; -} diff --git a/APP_Framework/Framework/control/plc/shared/plc_ch.h b/APP_Framework/Framework/control/plc/shared/plc_ch.h deleted file mode 100755 index f32817138..000000000 --- a/APP_Framework/Framework/control/plc/shared/plc_ch.h +++ /dev/null @@ -1,64 +0,0 @@ -/* -* Copyright (c) 2020 AIIT XUOS Lab -* XiUOS is licensed under Mulan PSL v2. -* You can use this software according to the terms and conditions of the Mulan PSL v2. -* You may obtain a copy of Mulan PSL v2 at: -* http://license.coscl.org.cn/MulanPSL2 -* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, -* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, -* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. -* See the Mulan PSL v2 for more details. -*/ - -/** -* @file plc_ch.h -* @brief define plc bus and drv function using bus driver framework -* @version 1.0 -* @author AIIT XUOS Lab -* @date 2022-01-24 -*/ - -#ifndef __PLC_CH_H_ -#define __PLC_CH_H_ - -#include "channel.h" - -#ifdef __cplusplus -extern "C" { -#endif - -struct PlcDriver -{ - struct ChDrv driver; - uint32 (*configure) (void *drv, struct ChConfigInfo *cfg); -}; - -struct PlcChannel -{ - struct Channel ch; - void *private_data; -}; - -/*Register the plc bus*/ -int PlcChannelInit(struct PlcChannel *plc_ch, const char *ch_name); - -/*Register the plc driver*/ -int PlcDriverInit(struct PlcDriver *plc_driver, const char *driver_name); - -/*Release the plc device*/ -int PlcReleaseChannel(struct PlcChannel *plc_ch); - -/*Register the plc driver to the plc bus*/ -int PlcDriverAttachToChannel(const char *drv_name, const char *ch_name); - -/*Register the driver, manage with the double linklist*/ -int PlcDriverRegister(struct ChDrv *driver); - -/*Find the register driver*/ -ChDrvType PlcDriverFind(const char *drv_name, enum ChDrvType_e drv_type); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/APP_Framework/Framework/control/plc/shared/channel.c b/APP_Framework/Framework/control/plc/shared/plc_channel.c similarity index 78% rename from APP_Framework/Framework/control/plc/shared/channel.c rename to APP_Framework/Framework/control/plc/shared/plc_channel.c index 22b76fbfb..3fe084514 100755 --- a/APP_Framework/Framework/control/plc/shared/channel.c +++ b/APP_Framework/Framework/control/plc/shared/plc_channel.c @@ -18,7 +18,8 @@ */ #include "string.h" -#include "channel.h" +#include "plc_channel.h" +#include "plc_device.h" #include "transform.h" DoublelistType ch_linklist; @@ -431,3 +432,107 @@ uint32 ChannelDrvConfigure(struct ChDrv *drv, struct ChConfigInfo *config) return ret; } + +int PlcChannelInit(struct PlcChannel* plc_ch, const char* ch_name) +{ + CHECK_CH_PARAM(plc_ch); + CHECK_CH_PARAM(ch_name); + int ret = EOK; + + if(CHANNEL_INSTALL != plc_ch->ch.ch_state) + { + strncpy(plc_ch->ch.ch_name, ch_name, NAME_NUM_MAX); + plc_ch->ch.ch_type = CH_PLC_TYPE; + plc_ch->ch.ch_state = CHANNEL_INSTALL; + plc_ch->ch.private_data = plc_ch->private_data; + ret = ChannelRegister(&plc_ch->ch); + + if(EOK != ret) + { + KPrintf("PlcChannelInit ChannelRegister error %u\n", ret); + return ret; + } + } + else + { + KPrintf("PlcChannelInit ChannelRegister channel has been register state %u\n", + plc_ch->ch.ch_state); + } + + return ret; +} + +int PlcDriverInit(struct PlcDriver* plc_driver, const char* driver_name) +{ + CHECK_CH_PARAM(plc_driver); + CHECK_CH_PARAM(driver_name); + int ret = EOK; + + if(CHDRV_INSTALL != plc_driver->driver.driver_state) + { + plc_driver->driver.driver_type = CHDRV_PLC_TYPE; + plc_driver->driver.driver_state = CHDRV_INSTALL; + strncpy(plc_driver->driver.drv_name, driver_name, NAME_NUM_MAX); + plc_driver->driver.configure = plc_driver->configure; + ret = PlcDriverRegister(&plc_driver->driver); + + if(EOK != ret) + { + KPrintf("PlcDriverInit DriverRegister error %u\n", ret); + return ret; + } + } + else + { + KPrintf("PlcDriverInit Driver %s has been register state %u\n", + driver_name, plc_driver->driver.driver_state); + } + + return ret; +} + +int PlcReleaseChannel(struct PlcChannel* plc_ch) +{ + CHECK_CH_PARAM(plc_ch); + return ChannelRelease(&plc_ch->ch); +} + +int PlcDriverAttachToChannel(const char* drv_name, const char* ch_name) +{ + CHECK_CH_PARAM(drv_name); + CHECK_CH_PARAM(ch_name); + int ret = EOK; + struct Channel* ch; + struct ChDrv* driver; + ch = ChannelFind(ch_name); + + if(NONE == ch) + { + KPrintf("PlcDriverAttachToChannel find plc channel error!name %s\n", ch_name); + return ERROR; + } + + if(CH_PLC_TYPE == ch->ch_type) + { + driver = PlcDriverFind(drv_name, CHDRV_PLC_TYPE); + + if(NONE == driver) + { + KPrintf("PlcDriverAttachToChannel find plc driver error!name %s\n", drv_name); + return ERROR; + } + + if(CHDRV_PLC_TYPE == driver->driver_type) + { + ret = DriverRegisterToChannel(ch, driver); + + if(EOK != ret) + { + KPrintf("PlcDriverAttachToChannel DriverRegisterToBus error %u\n", ret); + return ERROR; + } + } + } + + return ret; +} diff --git a/APP_Framework/Framework/control/plc/shared/channel.h b/APP_Framework/Framework/control/plc/shared/plc_channel.h similarity index 86% rename from APP_Framework/Framework/control/plc/shared/channel.h rename to APP_Framework/Framework/control/plc/shared/plc_channel.h index c87134d03..a00262bf1 100755 --- a/APP_Framework/Framework/control/plc/shared/channel.h +++ b/APP_Framework/Framework/control/plc/shared/plc_channel.h @@ -11,15 +11,15 @@ */ /** -* @file channel.h +* @file plc_channel.h * @brief define ch driver framework function and common API * @version 1.0 * @author AIIT XUOS Lab * @date 2022-03-01 */ -#ifndef __CHANNEL_H_ -#define __CHANNEL_H_ +#ifndef __PLC_CHANNEL_H_ +#define __PLC_CHANNEL_H_ #include "list.h" @@ -240,6 +240,37 @@ uint32 ChannelDrvConfigure(struct ChDrv *drv, struct ChConfigInfo *config); /*Obtain the ch using a certain dev*/ int DeviceObtainChannel(struct Channel *ch, struct ChDev *dev, const char *drv_name, struct ChConfigInfo *config); + +struct PlcDriver +{ + struct ChDrv driver; + uint32 (*configure) (void *drv, struct ChConfigInfo *cfg); +}; + +struct PlcChannel +{ + struct Channel ch; + void *private_data; +}; + +/*Register the plc bus*/ +int PlcChannelInit(struct PlcChannel *plc_ch, const char *ch_name); + +/*Register the plc driver*/ +int PlcDriverInit(struct PlcDriver *plc_driver, const char *driver_name); + +/*Release the plc device*/ +int PlcReleaseChannel(struct PlcChannel *plc_ch); + +/*Register the plc driver to the plc bus*/ +int PlcDriverAttachToChannel(const char *drv_name, const char *ch_name); + +/*Register the driver, manage with the double linklist*/ +int PlcDriverRegister(struct ChDrv *driver); + +/*Find the register driver*/ +ChDrvType PlcDriverFind(const char *drv_name, enum ChDrvType_e drv_type); + #ifdef __cplusplus } #endif diff --git a/APP_Framework/Framework/control/plc/shared/plc_dev.c b/APP_Framework/Framework/control/plc/shared/plc_device.c similarity index 98% rename from APP_Framework/Framework/control/plc/shared/plc_dev.c rename to APP_Framework/Framework/control/plc/shared/plc_device.c index ed44b5b7b..670452e2a 100755 --- a/APP_Framework/Framework/control/plc/shared/plc_dev.c +++ b/APP_Framework/Framework/control/plc/shared/plc_device.c @@ -19,8 +19,8 @@ */ #include "ua_api.h" -#include "plc_ch.h" -#include "plc_dev.h" +#include "plc_channel.h" +#include "plc_device.h" DoublelistType plcdev_list; diff --git a/APP_Framework/Framework/control/plc/shared/plc_dev.h b/APP_Framework/Framework/control/plc/shared/plc_device.h similarity index 99% rename from APP_Framework/Framework/control/plc/shared/plc_dev.h rename to APP_Framework/Framework/control/plc/shared/plc_device.h index f17b78f3b..6744a1474 100755 --- a/APP_Framework/Framework/control/plc/shared/plc_dev.h +++ b/APP_Framework/Framework/control/plc/shared/plc_device.h @@ -22,7 +22,7 @@ #define __PLC_DEV_H_ #include "list.h" -#include "plc_ch.h" +#include "plc_channel.h" #undef open #undef close diff --git a/APP_Framework/Framework/control/plc/shared/plc_drv.c b/APP_Framework/Framework/control/plc/shared/plc_driver.c similarity index 97% rename from APP_Framework/Framework/control/plc/shared/plc_drv.c rename to APP_Framework/Framework/control/plc/shared/plc_driver.c index f58d3afb5..358856b8b 100755 --- a/APP_Framework/Framework/control/plc/shared/plc_drv.c +++ b/APP_Framework/Framework/control/plc/shared/plc_driver.c @@ -19,8 +19,8 @@ */ #include "transform.h" -#include "plc_ch.h" -#include "plc_dev.h" +#include "plc_channel.h" +#include "plc_device.h" static DoublelistType plcdrv_linklist; diff --git a/Ubiquitous/XiZi/board/ok1052-c/board.c b/Ubiquitous/XiZi/board/ok1052-c/board.c index bea4a887c..55786560d 100644 --- a/Ubiquitous/XiZi/board/ok1052-c/board.c +++ b/Ubiquitous/XiZi/board/ok1052-c/board.c @@ -23,6 +23,7 @@ Author: AIIT XUOS Lab Modification: 1. support imxrt1052-board MPU、clock、memory init 2. support imxrt1052-board uart、semc、sdio driver init +3. support imxrt1052-board I2C, SPI, ADC, RTC driver init *************************************************/ #include "fsl_common.h" @@ -67,6 +68,9 @@ int MountSDCard(void) #include #include +#include +#include +#include #define NVIC_PRIORITYGROUP_0 0x00000007U /*!< 0 bits for pre-emption priority 4 bits for subpriority */ @@ -660,6 +664,18 @@ void InitBoardHardware() Imrt1052HwUartInit(); #endif +#ifdef BSP_USING_ADC + Imrt1052HwAdcInit(); +#endif + +#ifdef BSP_USING_SPI + Imrt1052HwSpiInit(); +#endif + +#ifdef BSP_USING_RTC + Imrt1052HwRtcInit(); +#endif + InstallConsole(KERNEL_CONSOLE_BUS_NAME, KERNEL_CONSOLE_DRV_NAME, KERNEL_CONSOLE_DEVICE_NAME); #ifdef BSP_USING_SDIO diff --git a/Ubiquitous/XiZi/board/ok1052-c/config.mk b/Ubiquitous/XiZi/board/ok1052-c/config.mk index e6b243e19..f57b78739 100644 --- a/Ubiquitous/XiZi/board/ok1052-c/config.mk +++ b/Ubiquitous/XiZi/board/ok1052-c/config.mk @@ -1,9 +1,17 @@ export CROSS_COMPILE ?=/usr/bin/arm-none-eabi- -export CFLAGS := -mcpu=cortex-m7 -mthumb -ffunction-sections -fdata-sections -Dgcc -O0 -gdwarf-2 -g -fgnu89-inline -Wa,-mimplicit-it=thumb +export CFLAGS := -mcpu=cortex-m7 -mthumb -ffunction-sections -fdata-sections -Dgcc -O0 -gdwarf-2 -g -fgnu89-inline -Wa,-mimplicit-it=thumb export AFLAGS := -c -mcpu=cortex-m7 -mthumb -ffunction-sections -fdata-sections -x assembler-with-cpp -Wa,-mimplicit-it=thumb -gdwarf-2 + +### if use USB function, use special lds file because USB uses ITCM + +ifeq ($(CONFIG_BSP_USING_USB),y) +export LFLAGS := -mcpu=cortex-m7 -mthumb -ffunction-sections -fdata-sections -Wl,--gc-sections,-Map=XiZi_ok1052-c.map,-cref,-u,Reset_Handler -T $(BSP_ROOT)/link-usb.lds +else export LFLAGS := -mcpu=cortex-m7 -mthumb -ffunction-sections -fdata-sections -Wl,--gc-sections,-Map=XiZi_ok1052-c.map,-cref,-u,Reset_Handler -T $(BSP_ROOT)/link.lds -export CXXFLAGS := -mcpu=cortex-m7 -mthumb -ffunction-sections -fdata-sections -Dgcc -O0 -gdwarf-2 -g +endif + +export CXXFLAGS := -mcpu=cortex-m7 -mthumb -ffunction-sections -fdata-sections -Dgcc -O0 -gdwarf-2 -g export APPLFLAGS := -mcpu=cortex-m7 -mthumb -ffunction-sections -fdata-sections -Wl,--gc-sections,-Map=XiZi_app.map,-cref,-u, -T $(BSP_ROOT)/link_userspace.lds diff --git a/Ubiquitous/XiZi/board/ok1052-c/link-usb.lds b/Ubiquitous/XiZi/board/ok1052-c/link-usb.lds new file mode 100755 index 000000000..41649a29f --- /dev/null +++ b/Ubiquitous/XiZi/board/ok1052-c/link-usb.lds @@ -0,0 +1,250 @@ +/* +** ################################################################### +** Processors: MIMXRT1052CVJ5B +** MIMXRT1052CVL5B +** MIMXRT1052DVJ6B +** MIMXRT1052DVL6B +** +** Compiler: GNU C Compiler +** Reference manual: IMXRT1050RM Rev.1, 03/2018 +** Version: rev. 1.0, 2018-09-21 +** Build: b180921 +** +** Abstract: +** Linker file for the GNU C Compiler +** +** Copyright 2016 Freescale Semiconductor, Inc. +** Copyright 2016-2018 NXP +** All rights reserved. +** +** SPDX-License-Identifier: BSD-3-Clause +** +** http: www.nxp.com +** mail: support@nxp.com +** +** ################################################################### +*/ + + +/** +* @file link.lds +* @brief ok1052-c Linker script +* @version 1.0 +* @author AIIT XUOS Lab +* @date 2021-05-28 +*/ + +/************************************************* +File name: link.lds +Description: ok1052-c Linker script +Others: take MIMXRT1052xxxxx_flexspi_nor.ld for references +History: +1. Date: 2021-05-28 +Author: AIIT XUOS Lab +Modification: +1. add shell cmd table and g_service_table +*************************************************/ + +/* Entry Point */ +ENTRY(Reset_Handler) + +HEAP_SIZE = DEFINED(__heap_size__) ? __heap_size__ : 0x0400; +STACK_SIZE = DEFINED(__stack_size__) ? __stack_size__ : 0x1000; + +/* Specify the memory areas */ +MEMORY +{ + m_interrupts (RX) : ORIGIN = 0x60002000, LENGTH = 0x00000400 + m_text (RX) : ORIGIN = 0x60002400, LENGTH = 0x03FFDC00 + m_data (RW) : ORIGIN = 0x20000000, LENGTH = 0x00020000 + m_data2 (RW) : ORIGIN = 0x20200000, LENGTH = 0x00060000 +} + +/* Define output sections */ +SECTIONS +{ + + /* The startup code goes first into internal RAM */ + .interrupts : + { + __VECTOR_TABLE = .; + . = ALIGN(4); + KEEP(*(.isr_vector)) /* Startup code */ + . = ALIGN(4); + } > m_interrupts + + __VECTOR_RAM = __VECTOR_TABLE; + __RAM_VECTOR_TABLE_SIZE_BYTES = 0x0; + + /* The program code and other data goes into internal RAM */ + .text : + { + . = ALIGN(4); + *(.text) /* .text sections (code) */ + *(.text*) /* .text* sections (code) */ + *(.rodata) /* .rodata sections (constants, strings, etc.) */ + *(.rodata*) /* .rodata* sections (constants, strings, etc.) */ + *(.glue_7) /* glue arm to thumb code */ + *(.glue_7t) /* glue thumb to arm code */ + *(.eh_frame) + KEEP (*(.init)) + KEEP (*(.fini)) + . = ALIGN(4); + + + /* section information for shell */ + . = ALIGN(4); + _shell_command_start = .; + KEEP (*(shellCommand)) + _shell_command_end = .; + . = ALIGN(4); + + __isrtbl_idx_start = .; + KEEP(*(.isrtbl.idx)) + __isrtbl_start = .; + KEEP(*(.isrtbl)) + __isrtbl_end = .; + . = ALIGN(4); + + PROVIDE(g_service_table_start = ABSOLUTE(.)); + KEEP(*(.g_service_table)) + PROVIDE(g_service_table_end = ABSOLUTE(.)); + } > m_text + + .ARM.extab : + { + *(.ARM.extab* .gnu.linkonce.armextab.*) + } > m_text + + .ARM : + { + __exidx_start = .; + *(.ARM.exidx*) + __exidx_end = .; + } > m_text + + .ctors : + { + __CTOR_LIST__ = .; + /* gcc uses crtbegin.o to find the start of + the constructors, so we make sure it is + first. Because this is a wildcard, it + doesn't matter if the user does not + actually link against crtbegin.o; the + linker won't look for a file to match a + wildcard. The wildcard also means that it + doesn't matter which directory crtbegin.o + is in. */ + KEEP (*crtbegin.o(.ctors)) + KEEP (*crtbegin?.o(.ctors)) + /* We don't want to include the .ctor section from + from the crtend.o file until after the sorted ctors. + The .ctor section from the crtend file contains the + end of ctors marker and it must be last */ + KEEP (*(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors)) + KEEP (*(SORT(.ctors.*))) + KEEP (*(.ctors)) + __CTOR_END__ = .; + } > m_text + + .dtors : + { + __DTOR_LIST__ = .; + KEEP (*crtbegin.o(.dtors)) + KEEP (*crtbegin?.o(.dtors)) + KEEP (*(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors)) + KEEP (*(SORT(.dtors.*))) + KEEP (*(.dtors)) + __DTOR_END__ = .; + } > m_text + + .preinit_array : + { + PROVIDE_HIDDEN (__preinit_array_start = .); + KEEP (*(.preinit_array*)) + PROVIDE_HIDDEN (__preinit_array_end = .); + } > m_text + + .init_array : + { + PROVIDE_HIDDEN (__init_array_start = .); + KEEP (*(SORT(.init_array.*))) + KEEP (*(.init_array*)) + PROVIDE_HIDDEN (__init_array_end = .); + } > m_text + + .fini_array : + { + PROVIDE_HIDDEN (__fini_array_start = .); + KEEP (*(SORT(.fini_array.*))) + KEEP (*(.fini_array*)) + PROVIDE_HIDDEN (__fini_array_end = .); + } > m_text + + __etext = .; /* define a global symbol at end of code */ + __DATA_ROM = .; /* Symbol is used by startup for data initialization */ + + .data : AT(__DATA_ROM) + { + . = ALIGN(4); + __DATA_RAM = .; + __data_start__ = .; /* create a global symbol at data start */ + *(m_usb_dma_init_data) + *(.data) /* .data sections */ + *(.data*) /* .data* sections */ + KEEP(*(.jcr*)) + . = ALIGN(4); + __data_end__ = .; /* define a global symbol at data end */ + } > m_data + + __NDATA_ROM = __DATA_ROM + (__data_end__ - __data_start__); + .ncache.init : AT(__NDATA_ROM) + { + __noncachedata_start__ = .; /* create a global symbol at ncache data start */ + *(NonCacheable.init) + . = ALIGN(4); + __noncachedata_init_end__ = .; /* create a global symbol at initialized ncache data end */ + } > m_data + . = __noncachedata_init_end__; + .ncache : + { + *(NonCacheable) + . = ALIGN(4); + __noncachedata_end__ = .; /* define a global symbol at ncache data end */ + } > m_data + + __DATA_END = __NDATA_ROM + (__noncachedata_init_end__ - __noncachedata_start__); + text_end = ORIGIN(m_text) + LENGTH(m_text); + ASSERT(__DATA_END <= text_end, "region m_text overflowed with text and data") + + /* Uninitialized data section */ + .bss : + { + /* This is used by the startup in order to initialize the .bss section */ + . = ALIGN(4); + __START_BSS = .; + __bss_start__ = .; + *(m_usb_dma_noninit_data) + *(.bss) + *(.bss*) + *(COMMON) + . = ALIGN(4); + __bss_end__ = .; + __END_BSS = .; + } > m_data + + .stack : + { + . = ALIGN(8); + stack_start = .; + . += STACK_SIZE; + stack_end = .; + __StackTop = .; + heap_start = .; + } > m_data + + PROVIDE(heap_end = ORIGIN(m_data) + LENGTH(m_data)); + + .ARM.attributes 0 : { *(.ARM.attributes) } +} + diff --git a/Ubiquitous/XiZi/board/ok1052-c/link.lds b/Ubiquitous/XiZi/board/ok1052-c/link.lds index 41649a29f..0d3ab2a58 100644 --- a/Ubiquitous/XiZi/board/ok1052-c/link.lds +++ b/Ubiquitous/XiZi/board/ok1052-c/link.lds @@ -241,9 +241,9 @@ SECTIONS stack_end = .; __StackTop = .; heap_start = .; - } > m_data + } > m_data2 - PROVIDE(heap_end = ORIGIN(m_data) + LENGTH(m_data)); + PROVIDE(heap_end = ORIGIN(m_data2) + LENGTH(m_data2)); .ARM.attributes 0 : { *(.ARM.attributes) } } diff --git a/Ubiquitous/XiZi/board/ok1052-c/third_party_driver/include/connect_rtc.h b/Ubiquitous/XiZi/board/ok1052-c/third_party_driver/include/connect_rtc.h index 47fa830ab..7f3a8c66e 100755 --- a/Ubiquitous/XiZi/board/ok1052-c/third_party_driver/include/connect_rtc.h +++ b/Ubiquitous/XiZi/board/ok1052-c/third_party_driver/include/connect_rtc.h @@ -31,8 +31,7 @@ void RtcI2cInit(void); status_t RtcI2cWrite(LPI2C_Type *base, uint32_t sub_addr, uint8_t *buf, uint16_t size); uint32_t RtcI2cRead(LPI2C_Type *base, uint32_t sub_addr, uint8_t *buf, uint16_t size); -int RtcSetTime(uint8_t* asc_date); -int RtcGetTime(void); +int Imrt1052HwRtcInit(void); #endif diff --git a/Ubiquitous/XiZi/board/ok1052-c/third_party_driver/rtc/connect_rtc.c b/Ubiquitous/XiZi/board/ok1052-c/third_party_driver/rtc/connect_rtc.c index 3662c8265..dd9982f0a 100755 --- a/Ubiquitous/XiZi/board/ok1052-c/third_party_driver/rtc/connect_rtc.c +++ b/Ubiquitous/XiZi/board/ok1052-c/third_party_driver/rtc/connect_rtc.c @@ -52,16 +52,19 @@ Modification: *************************************************/ #include "board.h" +#include "bus_rtc.h" #include "pin_mux.h" +#include "dev_rtc.h" #include "connect_rtc.h" /******************************************************************************* * Definitions ******************************************************************************/ -#define EXAMPLE_DELAY_COUNT 8000000 #define rtc_print KPrintf +#define MAX_TIME_STR_SIZE 50 + ///////////RX8010/////////// #define RX8010_SEC 0x10 @@ -246,50 +249,201 @@ int RtcSetTime(uint8_t* asc_date) } // get rx8010 time -int RtcGetTime(void) +int RtcGetTime(struct tm *ct) { - uint8_t date[7]; - uint8_t dateRsul[7]; - uint8_t flagreg; + uint8_t rtc_data[7]; + uint8_t time_str[7]; + uint8_t flag_reg; int err; - err = RtcI2cRead(I2C_RTC_BASE, RX8010_FLAG, &flagreg, 1); + err = RtcI2cRead(I2C_RTC_BASE, RX8010_FLAG, &flag_reg, 1); - if(flagreg & RX8010_FLAG_VLF) + if(flag_reg & RX8010_FLAG_VLF) { rtc_print("\r\n Frequency stop was detected\r\n"); return 1; } - err = RtcI2cRead(I2C_RTC_BASE, RX8010_SEC, date, 7); - dateRsul[0] = bcd2bin(date[RX8010_SEC - RX8010_SEC] & 0x7f); - dateRsul[1] = bcd2bin(date[RX8010_MIN - RX8010_SEC] & 0x7f); - dateRsul[2] = bcd2bin(date[RX8010_HOUR - RX8010_SEC] & 0x3f); - dateRsul[4] = bcd2bin(date[RX8010_MDAY - RX8010_SEC] & 0x3f); - dateRsul[5] = bcd2bin(date[RX8010_MONTH - RX8010_SEC] & 0x1f); - dateRsul[6] = bcd2bin(date[RX8010_YEAR - RX8010_SEC]); - dateRsul[3] = date[RX8010_WDAY - RX8010_SEC] & 0x7f; + err = RtcI2cRead(I2C_RTC_BASE, RX8010_SEC, rtc_data, 7); + time_str[0] = bcd2bin(rtc_data[RX8010_SEC - RX8010_SEC] & 0x7f); + time_str[1] = bcd2bin(rtc_data[RX8010_MIN - RX8010_SEC] & 0x7f); + time_str[2] = bcd2bin(rtc_data[RX8010_HOUR - RX8010_SEC] & 0x3f); + time_str[4] = bcd2bin(rtc_data[RX8010_MDAY - RX8010_SEC] & 0x3f); + time_str[5] = bcd2bin(rtc_data[RX8010_MONTH - RX8010_SEC] & 0x1f); + time_str[6] = bcd2bin(rtc_data[RX8010_YEAR - RX8010_SEC]); + time_str[3] = rtc_data[RX8010_WDAY - RX8010_SEC] & 0x7f; + rtc_print("RX8010 Time: 20%d%d-%d%d-%d%d %d%d:%d%d:%d%d\r\n", - dateRsul[6]/10, dateRsul[6]%10, dateRsul[5]/10, dateRsul[5]%10, dateRsul[4]/10, dateRsul[4]%10, - dateRsul[2]/10, dateRsul[2]%10, dateRsul[1]/10, dateRsul[1]%10, dateRsul[0]/10, dateRsul[0]%10); + time_str[6]/10, time_str[6]%10, time_str[5]/10, time_str[5]%10, time_str[4]/10, time_str[4]%10, + time_str[2]/10, time_str[2]%10, time_str[1]/10, time_str[1]%10, time_str[0]/10, time_str[0]%10); + + ct->tm_year = time_str[6]; + ct->tm_mon = time_str[5]; + ct->tm_mday = time_str[4]; + ct->tm_wday = time_str[3]; + ct->tm_hour = time_str[2]; + ct->tm_min = time_str[1]; + ct->tm_sec = time_str[0]; return 0; } -void RtcTestRx8010(int argc, char* argv[]) +static int GetWeekDay(int year, int month, int day) +{ + if(month==1||month==2) + { + year -=1; + month +=12; + } + + return (day+1+2*month+3*(month+1)/5+year+(year/4)-year/100+year/400)%7+1; +} + +static uint32 RtcConfigure(void* drv, struct BusConfigureInfo* configure_info) +{ + NULL_PARAM_CHECK(drv); + struct RtcDriver* rtc_drv = (struct RtcDriver*)drv; + struct RtcDrvConfigureParam* drv_param = (struct RtcDrvConfigureParam*)configure_info->private_data; + int cmd = drv_param->rtc_operation_cmd; + time_t* time = drv_param->time; + + switch(cmd) + { + case OPER_RTC_GET_TIME: + { + struct tm ct; + RtcGetTime(&ct); + *time = mktime(&ct); + } + break; + + case OPER_RTC_SET_TIME: + { + char time_str[MAX_TIME_STR_SIZE] = {0}; + struct tm *ct = localtime(time); + strftime(time_str, MAX_TIME_STR_SIZE, "%y-%m-%d %H:%M:%S", ct); + RtcSetTime(time_str); + } + break; + } + + return EOK; +} + +int RtcConfiguration(void) { BOARD_InitI2C1Pins(); RtcI2cInit(); RtcInit(); + return 0; +} +/*manage the rtc device operations*/ +static const struct RtcDevDone dev_done = +{ + .open = NONE, + .close = NONE, + .write = NONE, + .read = NONE, +}; + +static int BoardRtcBusInit(struct RtcBus* rtc_bus, struct RtcDriver* rtc_driver) +{ + x_err_t ret = EOK; + /*Init the rtc bus */ + ret = RtcBusInit(rtc_bus, RTC_BUS_NAME); + + if(EOK != ret) + { + KPrintf("hw_rtc_init RtcBusInit error %d\n", ret); + return ERROR; + } + + /*Init the rtc driver*/ + ret = RtcDriverInit(rtc_driver, RTC_DRV_NAME); + + if(EOK != ret) + { + KPrintf("hw_rtc_init RtcDriverInit error %d\n", ret); + return ERROR; + } + + /*Attach the rtc driver to the rtc bus*/ + ret = RtcDriverAttachToBus(RTC_DRV_NAME, RTC_BUS_NAME); + + if(EOK != ret) + { + KPrintf("hw_rtc_init RtcDriverAttachToBus error %d\n", ret); + return ERROR; + } + + return ret; +} + +/*Attach the rtc device to the rtc bus*/ +static int BoardRtcDevBend(void) +{ + x_err_t ret = EOK; + static struct RtcHardwareDevice rtc_device; + memset(&rtc_device, 0, sizeof(struct RtcHardwareDevice)); + rtc_device.dev_done = &(dev_done); + ret = RtcDeviceRegister(&rtc_device, NONE, RTC_DEVICE_NAME); + + if(EOK != ret) + { + KPrintf("hw_rtc_init RtcDeviceInit device %s error %d\n", RTC_DEVICE_NAME, ret); + return ERROR; + } + + ret = RtcDeviceAttachToBus(RTC_DEVICE_NAME, RTC_BUS_NAME); + + if(EOK != ret) + { + KPrintf("hw_rtc_init RtcDeviceAttachToBus device %s error %d\n", RTC_DEVICE_NAME, ret); + return ERROR; + } + + return ret; +} + +int Imrt1052HwRtcInit(void) +{ + x_err_t ret = EOK; + static struct RtcBus rtc_bus; + memset(&rtc_bus, 0, sizeof(struct RtcBus)); + static struct RtcDriver rtc_driver; + memset(&rtc_driver, 0, sizeof(struct RtcDriver)); + rtc_driver.configure = &(RtcConfigure); + ret = BoardRtcBusInit(&rtc_bus, &rtc_driver); + + if(EOK != ret) + { + KPrintf("hw_rtc_init error ret %u\n", ret); + return ERROR; + } + + ret = BoardRtcDevBend(); + + if(EOK != ret) + { + KPrintf("hw_rtc_init error ret %u\n", ret); + return ERROR; + } + + RtcConfiguration(); + return ret; +} + +void RtcTestRx8010(int argc, char* argv[]) +{ if(argc == 2) { if(RtcSetTime(argv[1]) == 0) { - RtcGetTime(); + RtcGetTime(NULL); } } else { - RtcGetTime(); + RtcGetTime(NULL); } } diff --git a/Ubiquitous/XiZi/tool/shell/Kconfig b/Ubiquitous/XiZi/tool/shell/Kconfig index babd9edd1..19c3fe9d0 100644 --- a/Ubiquitous/XiZi/tool/shell/Kconfig +++ b/Ubiquitous/XiZi/tool/shell/Kconfig @@ -9,16 +9,16 @@ if TOOL_SHELL bool config SHELL_ENTER_LF bool - + choice prompt "Set shell end-of-line markers :" default SHELL_ENTER_CR_AND_LF - + config SHELL_ENTER_CR_AND_LF bool "Using CR And LF as end-of-line markers" select SHELL_ENTER_CR - select SHELL_ENTER_LF - + select SHELL_ENTER_LF + config SHELL_ENTER_CRLF bool "Using CRLF as end-of-line markers" endchoice @@ -27,7 +27,7 @@ if TOOL_SHELL config SHELL_DEFAULT_USER string "Set default user's name" default "letter" - + config SHELL_DEFAULT_USER_PASSWORD string "Set default user's password(none for unnecessary)" default "" @@ -41,13 +41,13 @@ if TOOL_SHELL config SHELL_TASK_STACK_SIZE int "Set the stack size for shell " default 4096 - + config SHELL_TASK_PRIORITY int default 5 if KTASK_PRIORITY_8 default 20 if KTASK_PRIORITY_32 default 120 if KTASK_PRIORITY_256 - + config SHELL_MAX_NUMBER int "Set the max shell count" default 5 @@ -57,7 +57,7 @@ if TOOL_SHELL default 8 help The max number of parameter in shell. We support up to eight including command name. - + config SHELL_HISTORY_MAX_NUMBER int "Set the max number of command history" default 5