From 30c122eecd2f835d9c67e3054b8ee1c477d469b8 Mon Sep 17 00:00:00 2001 From: vsfos Date: Tue, 21 Dec 2021 23:49:28 +0800 Subject: [PATCH] add PikaVSF package --- package/PikaVSF/PikaVSF.py | 24 +++++++++++++ package/PikaVSF/PikaVSF_GPIO.c | 63 ++++++++++++++++++++++++++++++++++ package/PikaVSF/pika_config.c | 61 ++++++++++++++++++++++++++++++++ package/PikaVSF/pika_config.h | 23 +++++++++++++ 4 files changed, 171 insertions(+) create mode 100644 package/PikaVSF/PikaVSF.py create mode 100644 package/PikaVSF/PikaVSF_GPIO.c create mode 100644 package/PikaVSF/pika_config.c create mode 100644 package/PikaVSF/pika_config.h diff --git a/package/PikaVSF/PikaVSF.py b/package/PikaVSF/PikaVSF.py new file mode 100644 index 000000000..fa8a1fe00 --- /dev/null +++ b/package/PikaVSF/PikaVSF.py @@ -0,0 +1,24 @@ +import PikaStdDevice + +// kernel +// TODO + +// hal +class GPIO(PikaStdDevice.GPIO): + def platformHigh(): + pass + + def platformLow(): + pass + + def platformEnable(): + pass + + def platformDisable(): + pass + + def platformSetMode(): + pass + + def platformRead(): + pass \ No newline at end of file diff --git a/package/PikaVSF/PikaVSF_GPIO.c b/package/PikaVSF/PikaVSF_GPIO.c new file mode 100644 index 000000000..70b75ad58 --- /dev/null +++ b/package/PikaVSF/PikaVSF_GPIO.c @@ -0,0 +1,63 @@ +#include "pika_config.h" +#include "PikaObj.h" + +#if VSF_HAL_USE_GPIO == ENABLED && GPIO_COUNT > 0 +# define __PIKA_VSF_GPIO ENABLED +#endif + +#if __PIKA_VSF_GPIO == ENABLED +static int __vsf_gpio_pin_get(char *pin) { + int hw_port = 0, hw_pin = 0; + return vsf_hw_io_mapper_pin(hw_port, hw_pin); +} +#endif + +void PikaVSF_GPIO_platformEnable(PikaObj *self) { + +} +void PikaVSF_GPIO_platformDisable(PikaObj *self) { + +} +void PikaVSF_GPIO_platformHigh(PikaObj *self) { +#if __PIKA_VSF_GPIO == ENABLED + char *pin = obj_getStr(self, "pin"); + int pin_idx = __vsf_gpio_pin_get(pin); + vsf_io_mapper_set(&vsf_hw_io_mapper, pin_idx); +#else + vsf_trace_error("%s: platform has no gpio or gpio is disabled" VSF_TRACE_CFG_LINEEND); +#endif +} +void PikaVSF_GPIO_platformLow(PikaObj *self) { +#if __PIKA_VSF_GPIO == ENABLED + char *pin = obj_getStr(self, "pin"); + int pin_idx = __vsf_gpio_pin_get(pin); + vsf_io_mapper_clear(&vsf_hw_io_mapper, pin_idx); +#else + vsf_trace_error("%s: platform has no gpio or gpio is disabled" VSF_TRACE_CFG_LINEEND); +#endif +} +void PikaVSF_GPIO_platformRead(PikaObj *self) { +#if __PIKA_VSF_GPIO == ENABLED + char *pin = obj_getStr(self, "pin"); + int pin_idx = __vsf_gpio_pin_get(pin); + int pin_value = vsf_io_mapper_read(&vsf_hw_io_mapper, pin_idx); + obj_setInt(self, "readBuff", pin_value); +#else + vsf_trace_error("%s: platform has no gpio or gpio is disabled" VSF_TRACE_CFG_LINEEND); +#endif +} +void PikaVSF_GPIO_platformSetMode(PikaObj *self) { +#if __PIKA_VSF_GPIO == ENABLED + char *pin = obj_getStr(self, "pin"); + char *mode = obj_getStr(self, "mode"); + int pin_idx = __vsf_gpio_pin_get(pin); + + if (strEqu(mode, "out")) { + vsf_io_mapper_set_output(&vsf_hw_io_mapper, pin_idx); + } else if (strEqu(mode, "in")) { + vsf_io_mapper_set_input(&vsf_hw_io_mapper, pin_idx); + } +#else + vsf_trace_error("%s: platform has no gpio or gpio is disabled" VSF_TRACE_CFG_LINEEND); +#endif +} diff --git a/package/PikaVSF/pika_config.c b/package/PikaVSF/pika_config.c new file mode 100644 index 000000000..c23b8e7d0 --- /dev/null +++ b/package/PikaVSF/pika_config.c @@ -0,0 +1,61 @@ +/***************************************************************************** + * Copyright(C)2009-2019 by VSF Team * + * * + * Licensed under the Apache License, Version 2.0 (the "License"); * + * you may not use this file except in compliance with the License. * + * You may obtain a copy of the License at * + * * + * http://www.apache.org/licenses/LICENSE-2.0 * + * * + * Unless required by applicable law or agreed to in writing, software * + * distributed under the License is distributed on an "AS IS" BASIS, * + * WITHOUT 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 ======================================*/ + +#include "pika_config.h" +#include "PikaPlatform.h" + +/*============================ MACROS ========================================*/ + +#if VSF_USE_HEAP != ENABLED +# error "Please enable VSF_USE_HEAP" +#endif + +/*============================ MACROFIED FUNCTIONS ===========================*/ +/*============================ TYPES =========================================*/ +/*============================ GLOBAL VARIABLES ==============================*/ +/*============================ LOCAL VARIABLES ===============================*/ + +static unsigned int __crit_cnt = 0U; +static vsf_arch_prio_t __crit_saved = 0U; + +/*============================ PROTOTYPES ====================================*/ +/*============================ IMPLEMENTATION ================================*/ + +void __platform_disable_irq_handle(void) +{ + if (0U == __crit_cnt) { + __crit_saved = vsf_disable_interrupt(); + } + __crit_cnt++; +} + +void __platform_enable_irq_handle(void) +{ + __crit_cnt--; + if (0U == __crit_cnt) { + vsf_set_interrupt(__crit_saved); + } +} + +void * __platform_malloc(size_t size) { + return vsf_heap_malloc(size); +} +void __platform_free(void* ptr) { + vsf_heap_free(ptr); +} diff --git a/package/PikaVSF/pika_config.h b/package/PikaVSF/pika_config.h new file mode 100644 index 000000000..646be8eaf --- /dev/null +++ b/package/PikaVSF/pika_config.h @@ -0,0 +1,23 @@ +/***************************************************************************** + * Copyright(C)2009-2019 by VSF Team * + * * + * Licensed under the Apache License, Version 2.0 (the "License"); * + * you may not use this file except in compliance with the License. * + * You may obtain a copy of the License at * + * * + * http://www.apache.org/licenses/LICENSE-2.0 * + * * + * Unless required by applicable law or agreed to in writing, software * + * distributed under the License is distributed on an "AS IS" BASIS, * + * WITHOUT 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 __VSF_PIKA_PORT_H__ +#define __VSF_PIKA_PORT_H__ + +#include "vsf.h" + +#endif // __VSF_PIKA_PORT_H__