diff --git a/sdk/OpenRTL87X0C b/sdk/OpenRTL87X0C index 29dc19b7c..8fd7e42d5 160000 --- a/sdk/OpenRTL87X0C +++ b/sdk/OpenRTL87X0C @@ -1 +1 @@ -Subproject commit 29dc19b7cd4511ca1ff036863c6f513205606d72 +Subproject commit 8fd7e42d57a8e4db0a3c57a49e8b37c5cd3ae395 diff --git a/src/driver/drv_bl0937.c b/src/driver/drv_bl0937.c index 1e85c87bf..cc8d5e835 100644 --- a/src/driver/drv_bl0937.c +++ b/src/driver/drv_bl0937.c @@ -40,7 +40,6 @@ extern rtlPinMapping_t g_pins[]; rtlPinMapping_t* rtl_cf; rtlPinMapping_t* rtl_cf1; -gpio_irq_t irqcf, irqcf1; #else @@ -221,8 +220,12 @@ void BL0937_Shutdown_Pins() #elif PLATFORM_RTL87X0C - gpio_irq_free(&irqcf1); - gpio_irq_free(&irqcf); + gpio_irq_free(rtl_cf1->irq); + gpio_irq_free(rtl_cf->irq); + os_free(rtl_cf1->irq); + os_free(rtl_cf->irq); + rtl_cf1->irq = NULL; + rtl_cf->irq = NULL; #endif } @@ -257,16 +260,22 @@ void BL0937_Init_Pins() rtl_cf = g_pins + GPIO_HLW_CF; rtl_cf1 = g_pins + GPIO_HLW_CF1; - if(rtl_cf->isInit) + if(rtl_cf->gpio != NULL) { hal_pinmux_unregister(rtl_cf->pin, PID_GPIO); + os_free(rtl_cf->gpio); + rtl_cf->gpio = NULL; } - if(rtl_cf1->isInit) + if(rtl_cf1->gpio != NULL) { hal_pinmux_unregister(rtl_cf1->pin, PID_GPIO); + os_free(rtl_cf1->gpio); + rtl_cf1->gpio = NULL; } - rtl_cf->isInit = true; - rtl_cf1->isInit = true; + rtl_cf1->irq = os_malloc(sizeof(gpio_irq_t)); + rtl_cf->irq = os_malloc(sizeof(gpio_irq_t)); + memset(rtl_cf1->irq, 0, sizeof(gpio_irq_t)); + memset(rtl_cf->irq, 0, sizeof(gpio_irq_t)); #endif @@ -300,9 +309,9 @@ void BL0937_Init_Pins() #elif PLATFORM_RTL87X0C - gpio_irq_init(&irqcf1, rtl_cf1->pin, cf1_irq_handler, NULL); - gpio_irq_set(&irqcf1, IRQ_FALL, 1); - gpio_irq_enable(&irqcf1); + gpio_irq_init(rtl_cf1->irq, rtl_cf1->pin, cf1_irq_handler, NULL); + gpio_irq_set(rtl_cf1->irq, IRQ_FALL, 1); + gpio_irq_enable(rtl_cf1->irq); #endif @@ -331,9 +340,9 @@ void BL0937_Init_Pins() #elif PLATFORM_RTL87X0C - gpio_irq_init(&irqcf, rtl_cf->pin, cf_irq_handler, NULL); - gpio_irq_set(&irqcf, IRQ_FALL, 1); - gpio_irq_enable(&irqcf); + gpio_irq_init(rtl_cf->irq, rtl_cf->pin, cf_irq_handler, NULL); + gpio_irq_set(rtl_cf->irq, IRQ_FALL, 1); + gpio_irq_enable(rtl_cf->irq); #endif diff --git a/src/hal/rtl87x0c/hal_generic_rtl87x0c.h b/src/hal/rtl87x0c/hal_generic_rtl87x0c.h index 7201ca277..abab2a3b3 100644 --- a/src/hal/rtl87x0c/hal_generic_rtl87x0c.h +++ b/src/hal/rtl87x0c/hal_generic_rtl87x0c.h @@ -7,9 +7,9 @@ typedef struct rtlPinMapping_s { const char* name; PinName pin; - bool isInit; - gpio_t gpio; - pwmout_t pwm; + gpio_t* gpio; + gpio_irq_t* irq; + pwmout_t* pwm; } rtlPinMapping_t; #endif // PLATFORM_RTL87X0C diff --git a/src/hal/rtl87x0c/hal_pins_rtl87x0c.c b/src/hal/rtl87x0c/hal_pins_rtl87x0c.c index 0d918c083..425bfe1cc 100644 --- a/src/hal/rtl87x0c/hal_pins_rtl87x0c.c +++ b/src/hal/rtl87x0c/hal_pins_rtl87x0c.c @@ -9,30 +9,30 @@ extern int g_pwmFrequency; rtlPinMapping_t g_pins[] = { - { "PA0 (RX1)", PA_0, false }, - { "PA1 (TX1)", PA_1, false }, - { "PA2 (RX1)", PA_2, false }, - { "PA3 (TX1)", PA_3, false }, - { "PA4", PA_4, false }, - { "PA5", PA_5, false }, - { "PA6", PA_6, false }, - { "PA7", PA_7, false }, - { "PA8", PA_8, false }, - { "PA9", PA_9, false }, - { "PA10", PA_10, false }, - { "PA11", PA_11, false }, - { "PA12", PA_12, false }, - { "PA13 (RX0)", PA_13, false }, - { "PA14 (TX0)", PA_14, false }, - { "PA15 (RX2)", PA_15, false }, - { "PA16 (TX2)", PA_16, false }, - { "PA17", PA_17, false }, - { "PA18", PA_18, false }, - { "PA19", PA_19, false }, - { "PA20", PA_20, false }, - { "PA21", PA_21, false }, - { "PA22", PA_22, false }, - { "PA23", PA_23, false }, + { "PA0 (RX1)", PA_0, NULL, NULL }, + { "PA1 (TX1)", PA_1, NULL, NULL }, + { "PA2 (RX1)", PA_2, NULL, NULL }, + { "PA3 (TX1)", PA_3, NULL, NULL }, + { "PA4", PA_4, NULL, NULL }, + { "PA5", PA_5, NULL, NULL }, + { "PA6", PA_6, NULL, NULL }, + { "PA7", PA_7, NULL, NULL }, + { "PA8", PA_8, NULL, NULL }, + { "PA9", PA_9, NULL, NULL }, + { "PA10", PA_10, NULL, NULL }, + { "PA11", PA_11, NULL, NULL }, + { "PA12", PA_12, NULL, NULL }, + { "PA13 (RX0)", PA_13, NULL, NULL }, + { "PA14 (TX0)", PA_14, NULL, NULL }, + { "PA15 (RX2)", PA_15, NULL, NULL }, + { "PA16 (TX2)", PA_16, NULL, NULL }, + { "PA17", PA_17, NULL, NULL }, + { "PA18", PA_18, NULL, NULL }, + { "PA19", PA_19, NULL, NULL }, + { "PA20", PA_20, NULL, NULL }, + { "PA21", PA_21, NULL, NULL }, + { "PA22", PA_22, NULL, NULL }, + { "PA23", PA_23, NULL, NULL }, }; static int g_numPins = sizeof(g_pins) / sizeof(g_pins[0]); @@ -55,14 +55,25 @@ int HAL_PIN_CanThisPinBePWM(int index) return 1; } -void RTL_Gpio_Init(rtlPinMapping_t* pin) +void RTL_GPIO_Init(rtlPinMapping_t* pin) { - if(pin->isInit) + if(pin->gpio != NULL) { return; } - gpio_init(&pin->gpio, pin->pin); - pin->isInit = true; + //if(pin->irq != NULL) + //{ + // hal_pinmux_unregister(pin->pin, PID_GPIO); + // pin->irq = NULL; + //} + //if(pin->pwm != NULL) + //{ + // pwmout_free(pin->pwm); + // pin->pwm = NULL; + //} + pin->gpio = os_malloc(sizeof(gpio_t)); + memset(pin->gpio, 0, sizeof(gpio_t)); + gpio_init(pin->gpio, pin->pin); } void HAL_PIN_SetOutputValue(int index, int iVal) @@ -70,7 +81,7 @@ void HAL_PIN_SetOutputValue(int index, int iVal) if(index >= g_numPins) return; rtlPinMapping_t* pin = g_pins + index; - gpio_write(&pin->gpio, iVal ? 1 : 0); + gpio_write(pin->gpio, iVal ? 1 : 0); } int HAL_PIN_ReadDigitalInput(int index) @@ -78,7 +89,7 @@ int HAL_PIN_ReadDigitalInput(int index) if(index >= g_numPins) return 0; rtlPinMapping_t* pin = g_pins + index; - return gpio_read(&pin->gpio); + return gpio_read(pin->gpio); } void HAL_PIN_Setup_Input_Pullup(int index) @@ -86,9 +97,9 @@ void HAL_PIN_Setup_Input_Pullup(int index) if(index >= g_numPins) return; rtlPinMapping_t* pin = g_pins + index; - RTL_Gpio_Init(pin); - gpio_dir(&pin->gpio, PIN_INPUT); - gpio_mode(&pin->gpio, PullUp); + RTL_GPIO_Init(pin); + gpio_dir(pin->gpio, PIN_INPUT); + gpio_mode(pin->gpio, PullUp); } void HAL_PIN_Setup_Input_Pulldown(int index) @@ -96,9 +107,9 @@ void HAL_PIN_Setup_Input_Pulldown(int index) if(index >= g_numPins) return; rtlPinMapping_t* pin = g_pins + index; - RTL_Gpio_Init(pin); - gpio_dir(&pin->gpio, PIN_INPUT); - gpio_mode(&pin->gpio, PullDown); + RTL_GPIO_Init(pin); + gpio_dir(pin->gpio, PIN_INPUT); + gpio_mode(pin->gpio, PullDown); } void HAL_PIN_Setup_Input(int index) @@ -106,9 +117,9 @@ void HAL_PIN_Setup_Input(int index) if(index >= g_numPins) return; rtlPinMapping_t* pin = g_pins + index; - RTL_Gpio_Init(pin); - gpio_dir(&pin->gpio, PIN_INPUT); - gpio_mode(&pin->gpio, PullNone); + RTL_GPIO_Init(pin); + gpio_dir(pin->gpio, PIN_INPUT); + gpio_mode(pin->gpio, PullNone); } void HAL_PIN_Setup_Output(int index) @@ -116,9 +127,9 @@ void HAL_PIN_Setup_Output(int index) if(index >= g_numPins) return; rtlPinMapping_t* pin = g_pins + index; - RTL_Gpio_Init(pin); - gpio_dir(&pin->gpio, PIN_OUTPUT); - gpio_mode(&pin->gpio, PullUp); + RTL_GPIO_Init(pin); + gpio_dir(pin->gpio, PIN_OUTPUT); + gpio_mode(pin->gpio, PullUp); } void HAL_PIN_PWM_Stop(int index) @@ -126,9 +137,11 @@ void HAL_PIN_PWM_Stop(int index) if(index >= g_numPins || !HAL_PIN_CanThisPinBePWM(index)) return; rtlPinMapping_t* pin = g_pins + index; - //pwmout_stop(&pin->pwm); - pwmout_free(&pin->pwm); - pin->isInit = false; + if(pin->pwm == NULL) return; + //pwmout_stop(pin->pwm); + pwmout_free(pin->pwm); + os_free(pin->pwm); + pin->pwm = NULL; } void HAL_PIN_PWM_Start(int index) @@ -136,10 +149,12 @@ void HAL_PIN_PWM_Start(int index) if(index >= g_numPins || !HAL_PIN_CanThisPinBePWM(index)) return; rtlPinMapping_t* pin = g_pins + index; - pwmout_init(&pin->pwm, pin->pin); - pwmout_period_us(&pin->pwm, g_pwmFrequency); - pwmout_start(&pin->pwm); - pin->isInit = true; + if(pin->pwm != NULL) return; + pin->pwm = os_malloc(sizeof(pwmout_t)); + memset(pin->pwm, 0, sizeof(pwmout_t)); + pwmout_init(pin->pwm, pin->pin); + pwmout_period_us(pin->pwm, g_pwmFrequency); + pwmout_start(pin->pwm); } void HAL_PIN_PWM_Update(int index, float value) @@ -147,7 +162,8 @@ void HAL_PIN_PWM_Update(int index, float value) if(index >= g_numPins || !HAL_PIN_CanThisPinBePWM(index)) return; rtlPinMapping_t* pin = g_pins + index; - pwmout_write(&pin->pwm, value / 100); + if(pin->pwm == NULL || !pin->pwm->is_init) return; + pwmout_write(pin->pwm, value / 100); } unsigned int HAL_GetGPIOPin(int index) diff --git a/src/new_common.h b/src/new_common.h index 1a7275ebd..90ae761c2 100644 --- a/src/new_common.h +++ b/src/new_common.h @@ -521,8 +521,8 @@ typedef unsigned int UINT32; #undef ASSERT #define ASSERT -#define os_malloc malloc -#define os_free free +#define os_malloc pvPortMalloc +#define os_free vPortFree #define os_memset memset #define os_strcpy strcpy