Moving to miosix kernel: adapted GDx drivers and part of the common code to new configuration

replace/4cf7dce31281868b514fc77d9776caf7e137dd64
Silvano Seva 2021-03-10 13:31:49 +01:00
rodzic 7992b4abca
commit 093640478c
7 zmienionych plików z 27 dodań i 109 usunięć

Wyświetl plik

@ -24,7 +24,7 @@
#include <datatypes.h>
#include <stdint.h>
#include <cps.h>
#include <os.h>
#include <pthread.h>
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

Wyświetl plik

@ -22,7 +22,6 @@
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include <os.h>
#include <interfaces/gpio.h>
#include <interfaces/display.h>
#include <interfaces/delays.h>
@ -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;
}

Wyświetl plik

@ -19,11 +19,10 @@
***************************************************************************/
#include "I2C0.h"
#include <os.h>
#include <pthread.h>
#include <MK22F51212.h>
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);
}

Wyświetl plik

@ -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 <http://www.gnu.org/licenses/> *
***************************************************************************/
#include <os.h>
#include <interfaces/rtc.h>
/*
* 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() { }

Wyświetl plik

@ -25,12 +25,11 @@
#include <ADC0_GDx.h>
#include <string.h>
#include <I2C0.h>
#include <os.h>
#include <pthread.h>
#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;
}

Wyświetl plik

@ -25,12 +25,10 @@
#include <ADC0_GDx.h>
#include <string.h>
#include <I2C0.h>
#include <os.h>
#include <pthread.h>
#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;
}

Wyświetl plik

@ -19,7 +19,6 @@
#include <interfaces/platform.h>
#include <interfaces/gpio.h>
#include <os.h>
#include <hwconfig.h>
#include <string.h>
#include <ADC1_MDx.h>
@ -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