From 093640478c675623c3a8142bc7dfdc11c8d3c04f Mon Sep 17 00:00:00 2001 From: Silvano Seva Date: Wed, 10 Mar 2021 13:31:49 +0100 Subject: [PATCH] Moving to miosix kernel: adapted GDx drivers and part of the common code to new configuration --- openrtx/include/rtx.h | 4 +- platform/drivers/display/UC1701_GD77.c | 3 +- platform/mcu/MK22FN512xxx12/drivers/I2C0.c | 17 +++-- platform/mcu/MK22FN512xxx12/drivers/rtc.c | 72 ---------------------- platform/targets/DM-1801/platform.c | 16 ++--- platform/targets/GD-77/platform.c | 17 +++-- platform/targets/MD-UV380/platform.c | 7 +-- 7 files changed, 27 insertions(+), 109 deletions(-) delete mode 100644 platform/mcu/MK22FN512xxx12/drivers/rtc.c diff --git a/openrtx/include/rtx.h b/openrtx/include/rtx.h index 2147dbf3..88675c10 100644 --- a/openrtx/include/rtx.h +++ b/openrtx/include/rtx.h @@ -24,7 +24,7 @@ #include #include #include -#include +#include typedef struct { @@ -83,7 +83,7 @@ enum opstatus * @param m: pointer to the mutex protecting the shared configuration data * structure. */ -void rtx_init(OS_MUTEX *m); +void rtx_init(pthread_mutex_t *m); /** * Shut down rtx stage diff --git a/platform/drivers/display/UC1701_GD77.c b/platform/drivers/display/UC1701_GD77.c index 964313cc..235a711d 100644 --- a/platform/drivers/display/UC1701_GD77.c +++ b/platform/drivers/display/UC1701_GD77.c @@ -22,7 +22,6 @@ #include #include #include -#include #include #include #include @@ -65,7 +64,7 @@ void display_init() frameBuffer = (uint8_t *) malloc(fbSize); if(frameBuffer == NULL) { - printf("*** LCD ERROR: cannot allocate framebuffer! ***"); + puts("*** LCD ERROR: cannot allocate framebuffer! ***"); return; } diff --git a/platform/mcu/MK22FN512xxx12/drivers/I2C0.c b/platform/mcu/MK22FN512xxx12/drivers/I2C0.c index 181cbe50..d7bdd7cc 100644 --- a/platform/mcu/MK22FN512xxx12/drivers/I2C0.c +++ b/platform/mcu/MK22FN512xxx12/drivers/I2C0.c @@ -19,11 +19,10 @@ ***************************************************************************/ #include "I2C0.h" -#include +#include #include -OS_MUTEX i2c_mutex; -OS_ERR err; +pthread_mutex_t mutex; void i2c0_init() { @@ -33,7 +32,7 @@ void i2c0_init() I2C0->F = 0x2C; /* Divide bus clock by 576 */ I2C0->C1 |= I2C_C1_IICEN(1); /* Enable I2C module */ - OSMutexCreate(&i2c_mutex, "", &err); + pthread_mutex_init(&mutex, NULL); } void i2c0_terminate() @@ -43,7 +42,7 @@ void i2c0_terminate() I2C0->C1 &= ~I2C_C1_IICEN(1); SIM->SCGC4 &= ~SIM_SCGC4_I2C0(1); - OSMutexDel(&i2c_mutex, OS_OPT_DEL_NO_PEND, &err); + pthread_mutex_destroy(&mutex); } void i2c0_write(uint8_t addr, void* buf, size_t len, bool sendStop) @@ -121,9 +120,7 @@ bool i2c0_busy() bool i2c0_lockDevice() { - OSMutexPend(&i2c_mutex, 0, OS_OPT_PEND_NON_BLOCKING, NULL, &err); - - if(err == OS_ERR_NONE) + if(pthread_mutex_trylock(&mutex) == 0) { return true; } @@ -133,10 +130,10 @@ bool i2c0_lockDevice() void i2c0_lockDeviceBlocking() { - OSMutexPend(&i2c_mutex, 0, OS_OPT_PEND_BLOCKING, NULL, &err); + pthread_mutex_lock(&mutex); } void i2c0_releaseDevice() { - OSMutexPost(&i2c_mutex, OS_OPT_POST_NONE, &err); + pthread_mutex_unlock(&mutex); } diff --git a/platform/mcu/MK22FN512xxx12/drivers/rtc.c b/platform/mcu/MK22FN512xxx12/drivers/rtc.c deleted file mode 100644 index 2fc852f0..00000000 --- a/platform/mcu/MK22FN512xxx12/drivers/rtc.c +++ /dev/null @@ -1,72 +0,0 @@ -/*************************************************************************** - * Copyright (C) 2020 by Federico Amedeo Izzo IU2NUO, * - * Niccolò Izzo IU2KIN * - * Frederik Saraci IU2NRO * - * Silvano Seva IU2KWO * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 3 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, see * - ***************************************************************************/ - -#include -#include - -/* - * NOTE: even if the MK22FN512 MCU has an RTC, it is unusable in GDx platforms - * because they lacks of the proper hardware necessary to run the RTC also when - * the MCU is powered off. - * We thus provide a stub implementation of the RTC API to avoid cluttering the - * main code with #ifdefs checking wheter or not the RTC can be actually used. - */ - -void rtc_init() { } - -void rtc_terminate() { } - -void rtc_setTime(curTime_t t) -{ - (void) t; -} - -void rtc_setHour(uint8_t hours, uint8_t minutes, uint8_t seconds) -{ - (void) hours; - (void) minutes; - (void) seconds; -} - -void rtc_setDate(uint8_t date, uint8_t month, uint8_t year) -{ - (void) date; - (void) month; - (void) year; -} - -curTime_t rtc_getTime() -{ - curTime_t t; - - t.hour = 12; - t.minute = 12; - t.second = 12; - t.year = 20; - t.day = 4; - t.month = 12; - t.date = 12; - - return t; -} - -void rtc_dstSet() { } - -void rtc_dstClear() { } diff --git a/platform/targets/DM-1801/platform.c b/platform/targets/DM-1801/platform.c index 20bfdd6d..884b204c 100644 --- a/platform/targets/DM-1801/platform.c +++ b/platform/targets/DM-1801/platform.c @@ -25,12 +25,11 @@ #include #include #include -#include +#include #include "hwconfig.h" /* Mutex for concurrent access to ADC0 */ -OS_MUTEX adc_mutex; -OS_ERR e; +pthread_mutex_t adc_mutex; gdxCalibration_t calibration; hwInfo_t hwInfo; @@ -68,7 +67,7 @@ void platform_init() * Initialise ADC */ adc0_init(); - OSMutexCreate(&adc_mutex, "", &e); + pthread_mutex_init(&adc_mutex, NULL); /* * Initialise I2C driver, once for all the modules @@ -104,6 +103,7 @@ void platform_terminate() gpio_clearPin(GREEN_LED); adc0_terminate(); + pthread_mutex_destroy(&adc_mutex); /* Finally, remove power supply */ gpio_clearPin(PWR_SW); @@ -112,9 +112,9 @@ void platform_terminate() float platform_getVbat() { float value = 0.0f; - OSMutexPend(&adc_mutex, 0u, OS_OPT_PEND_BLOCKING, 0u, &e); + pthread_mutex_lock(&adc_mutex); value = adc0_getMeasurement(1); - OSMutexPost(&adc_mutex, OS_OPT_POST_NONE, &e); + pthread_mutex_unlock(&adc_mutex); return (value * 3.0f)/1000.0f; } @@ -122,9 +122,9 @@ float platform_getVbat() float platform_getMicLevel() { float value = 0.0f; - OSMutexPend(&adc_mutex, 0u, OS_OPT_PEND_BLOCKING, 0u, &e); + pthread_mutex_lock(&adc_mutex); value = adc0_getMeasurement(3); - OSMutexPost(&adc_mutex, OS_OPT_POST_NONE, &e); + pthread_mutex_unlock(&adc_mutex); return value; } diff --git a/platform/targets/GD-77/platform.c b/platform/targets/GD-77/platform.c index 9d2877fd..69572a1b 100644 --- a/platform/targets/GD-77/platform.c +++ b/platform/targets/GD-77/platform.c @@ -25,12 +25,10 @@ #include #include #include -#include +#include #include "hwconfig.h" -/* Mutex for concurrent access to ADC0 */ -OS_MUTEX adc_mutex; -OS_ERR e; +pthread_mutex_t adc_mutex; gdxCalibration_t calibration; hwInfo_t hwInfo; @@ -68,7 +66,7 @@ void platform_init() * Initialise ADC */ adc0_init(); - OSMutexCreate(&adc_mutex, "", &e); + pthread_mutex_init(&adc_mutex, NULL); /* * Initialise I2C driver, once for all the modules @@ -104,6 +102,7 @@ void platform_terminate() gpio_clearPin(GREEN_LED); adc0_terminate(); + pthread_mutex_destroy(&adc_mutex); /* Finally, remove power supply */ gpio_clearPin(PWR_SW); @@ -112,9 +111,9 @@ void platform_terminate() float platform_getVbat() { float value = 0.0f; - OSMutexPend(&adc_mutex, 0u, OS_OPT_PEND_BLOCKING, 0u, &e); + pthread_mutex_lock(&adc_mutex); value = adc0_getMeasurement(1); - OSMutexPost(&adc_mutex, OS_OPT_POST_NONE, &e); + pthread_mutex_unlock(&adc_mutex); return (value * 3.0f)/1000.0f; } @@ -122,9 +121,9 @@ float platform_getVbat() float platform_getMicLevel() { float value = 0.0f; - OSMutexPend(&adc_mutex, 0u, OS_OPT_PEND_BLOCKING, 0u, &e); + pthread_mutex_lock(&adc_mutex); value = adc0_getMeasurement(3); - OSMutexPost(&adc_mutex, OS_OPT_POST_NONE, &e); + pthread_mutex_unlock(&adc_mutex); return value; } diff --git a/platform/targets/MD-UV380/platform.c b/platform/targets/MD-UV380/platform.c index 8cf6555e..f6662126 100644 --- a/platform/targets/MD-UV380/platform.c +++ b/platform/targets/MD-UV380/platform.c @@ -19,7 +19,6 @@ #include #include -#include #include #include #include @@ -31,10 +30,8 @@ mduv3x0Calib_t calibration; hwInfo_t hwInfo; #ifdef ENABLE_BKLIGHT_DIMMING -void TIM1_TRG_COM_TIM11_IRQHandler() +void _Z29TIM1_TRG_COM_TIM11_IRQHandlerv() { - OSIntEnter(); - if(TIM11->SR & TIM_SR_CC1IF) { gpio_clearPin(LCD_BKLIGHT); /* Clear pin on compare match */ @@ -46,8 +43,6 @@ void TIM1_TRG_COM_TIM11_IRQHandler() } TIM11->SR = 0; - - OSIntExit(); } #endif