]> rtime.felk.cvut.cz Git - pes-rpp/rpp-lib.git/commitdiff
Unify ADC among targets
authorMichal Sojka <sojkam1@fel.cvut.cz>
Sun, 2 Aug 2015 07:21:20 +0000 (09:21 +0200)
committerMichal Sojka <sojkam1@fel.cvut.cz>
Fri, 7 Aug 2015 17:57:03 +0000 (19:57 +0200)
There was little need to have ADC files different for each board. This
way it is simpler. The only difference is the number of pins and we now
keep this difference in port_def.h.

23 files changed:
Makefile.var
rpp/include/drv/_rm48_hdk/port_def.h
rpp/include/drv/_tms570_hdk/port_def.h
rpp/include/drv/_tms570_hydctr/port_def.h
rpp/include/drv/_tms570_rpp/port_def.h
rpp/include/drv/adc.h
rpp/include/drv/port.h
rpp/src/drv/_rm48_hdk/adc.c [deleted file]
rpp/src/drv/_rm48_hdk/port_def.c
rpp/src/drv/_tms570_hdk/adc.c [deleted file]
rpp/src/drv/_tms570_hdk/port_def.c
rpp/src/drv/_tms570_hydctr/adc.c [deleted file]
rpp/src/drv/_tms570_hydctr/port_def.c
rpp/src/drv/_tms570_rpp/port_def.c
rpp/src/drv/adc.c [moved from rpp/src/drv/_tms570_rpp/adc.c with 50% similarity]
rpp/src/rpp/.gitattributes
rpp/src/rpp/_rm48_hdk/.gitattributes [deleted file]
rpp/src/rpp/_tms570_hdk/.gitattributes [deleted file]
rpp/src/rpp/_tms570_hdk/adc.c [deleted file]
rpp/src/rpp/_tms570_hydctr/.gitattributes [deleted file]
rpp/src/rpp/_tms570_hydctr/adc.c [deleted file]
rpp/src/rpp/_tms570_rpp/adc.c [deleted file]
rpp/src/rpp/adc.c [moved from rpp/src/rpp/_rm48_hdk/adc.c with 70% similarity]

index d279cef61e90a30bd9e25626c4997339c09fd5cc..5b2428d25410b65688a017412024ad3e1b7d30a0 100644 (file)
@@ -33,11 +33,11 @@ rpp_lib_SOURCES += \
 target_or_common = $(if $(wildcard ../../../$(dir $(1))/_$(TARGET)/$(notdir $(1))),$(dir $(1))/_$(TARGET)/$(notdir $(1)),$(1))
 
 rpp_lib_SOURCES +=                                                             \
-       rpp/src/rpp/_$(TARGET)/adc.c                            \
+       rpp/src/rpp/adc.c                                               \
        rpp/src/rpp/can.c                                               \
        rpp/src/rpp/gio.c                                               \
        rpp/src/rpp/sci.c                                               \
-       rpp/src/drv/_$(TARGET)/adc.c                            \
+       rpp/src/drv/adc.c                                               \
        rpp/src/drv/_$(TARGET)/port_def.c               \
        rpp/src/drv/gio.c                                               \
        rpp/src/drv/gio_tab.c                                   \
index 9e688799c3344965bcacd9e5ec5ccb2c93e07715..cc400b6972efb7b7f251b22e2ada61d7ac410f95 100644 (file)
@@ -14,6 +14,8 @@
 #ifndef DRV_TGT_PORT_DEF_H
 #define DRV_TGT_PORT_DEF_H
 
+#include <stdint.h>
+
 /* Port names */
 enum port_id {
        PORT_ID_GIOA,
@@ -24,4 +26,11 @@ enum port_id {
        _PORT_COUNT,
 };
 
+#define PORT_ADC_CHANNELS 16
+
+static double port_adc_lsb2volts(uint16_t lsb)
+{
+       return ((double)lsb + 0.0)*2.5/4095*2;
+}
+
 #endif
index 9e688799c3344965bcacd9e5ec5ccb2c93e07715..cc400b6972efb7b7f251b22e2ada61d7ac410f95 100644 (file)
@@ -14,6 +14,8 @@
 #ifndef DRV_TGT_PORT_DEF_H
 #define DRV_TGT_PORT_DEF_H
 
+#include <stdint.h>
+
 /* Port names */
 enum port_id {
        PORT_ID_GIOA,
@@ -24,4 +26,11 @@ enum port_id {
        _PORT_COUNT,
 };
 
+#define PORT_ADC_CHANNELS 16
+
+static double port_adc_lsb2volts(uint16_t lsb)
+{
+       return ((double)lsb + 0.0)*2.5/4095*2;
+}
+
 #endif
index 9e688799c3344965bcacd9e5ec5ccb2c93e07715..cc400b6972efb7b7f251b22e2ada61d7ac410f95 100644 (file)
@@ -14,6 +14,8 @@
 #ifndef DRV_TGT_PORT_DEF_H
 #define DRV_TGT_PORT_DEF_H
 
+#include <stdint.h>
+
 /* Port names */
 enum port_id {
        PORT_ID_GIOA,
@@ -24,4 +26,11 @@ enum port_id {
        _PORT_COUNT,
 };
 
+#define PORT_ADC_CHANNELS 16
+
+static double port_adc_lsb2volts(uint16_t lsb)
+{
+       return ((double)lsb + 0.0)*2.5/4095*2;
+}
+
 #endif
index 68973ee5119e4dd835d71099eb50db797636f05e..5d61d459d2ea43ca7bcda661b575602cb5cdd591 100644 (file)
@@ -14,6 +14,8 @@
 #ifndef _TMS570_RPP_PORT_DEF_H
 #define _TMS570_RPP_PORT_DEF_H
 
+#include <stdint.h>
+
 /* Port names */
 enum port_id {
        PORT_ID_DINMCU,
@@ -35,4 +37,11 @@ enum port_id {
        _PORT_COUNT,
 };
 
+#define PORT_ADC_CHANNELS 12
+
+static double port_adc_lsb2volts(uint16_t lsb)
+{
+       return ((double)lsb + 0.0)*2.5/4095*10;
+}
+
 #endif
index 96b8fa7707808d19ef23d88f2ff9acdb5f3dd92e..2ac30e81c8e7aacaa2072d97cbbee0bada05f6b8 100644 (file)
 #define ADC_MAX_CHANNELS 24
 
 void drv_adc_init();
-uint32_t drv_adc_read_adc(adcData_t *data);
 
-#ifdef TARGET_TMS570_RPP
-uint32_t drv_adc_read_houtifbk(adcData_t *data);
-#endif
-
-uint32_t adc_get_port_val(uint32_t *config, uint32_t num_channels,
-                                                 uint32_t *values);
 int8_t port_adc_get(const struct port_desc *port, void *values, size_t size);
 
 #endif /* __DRV_ADC_H */
index 545e1285a27367d74bb63508c678578eadc214e8..892b76c43689fedfabe83f2c0b304432021f9826 100644 (file)
@@ -79,7 +79,6 @@ struct port_desc {
                struct {
                        adcBASE_t *reg;
                        uint32_t group;
-                       uint32_t sem;           /* TODO: Remove this. This is the same information as group. */
                } adc;
                gioPORT_t *gio_reg;
        } cfg;
diff --git a/rpp/src/drv/_rm48_hdk/adc.c b/rpp/src/drv/_rm48_hdk/adc.c
deleted file mode 100644 (file)
index 550f974..0000000
+++ /dev/null
@@ -1,167 +0,0 @@
-/* Copyright (C) 2012-2013 Czech Technical University in Prague
- *
- * Authors:
- *     - Michal Horn
- *     - Carlos Jenkins <carlos@jenkins.co.cr>
- *
- * This document contains proprietary information belonging to Czech
- * Technical University in Prague. Passing on and copying of this
- * document, and communication of its contents is not permitted
- * without prior written authorization.
- *
- * File : adc.c
- * Abstract:
- *     RPP driver implementation for ADC.
- *
- * References:
- *     ti_drv_adc.c
- */
-
-
-#include "drv/drv.h"
-
-// Binary semaphore for ADC1 GRP1 conversion (AIN)
-xSemaphoreHandle adcSemaphore_ADC1GRP1;
-// Binary semaphore for ADC2 GRP1 conversion (HOUT-IFBK)
-xSemaphoreHandle adcSemaphore_ADC2GRP1;
-
-// Mutex for AIN read control
-xSemaphoreHandle adcMutex_ADC;
-
-void drv_adc_init()
-{
-       // Create semaphores
-       vSemaphoreCreateBinary(adcSemaphore_ADC1GRP1);
-       xSemaphoreTake(adcSemaphore_ADC1GRP1, 0);
-       vSemaphoreCreateBinary(adcSemaphore_ADC2GRP1);
-       xSemaphoreTake(adcSemaphore_ADC2GRP1, 0);
-
-       adcMutex_ADC       = xSemaphoreCreateMutex();
-
-       // Low level init
-       adcInit();
-}
-
-
-/**
- * ADC notification called by ADC conversion finished ISR.
- *
- * This procedure will just give semaphore.
- *
- *   @param[in] adc Pointer to ADC module:
- *              - adcREG1: ADC1 module pointer
- *              - adcREG2: ADC2 module pointer
- *   @param[in] group Hardware group of ADC module:
- *              - adcGROUP0: ADC event group
- *              - adcGROUP1: ADC group 1
- *              - adcGROUP2: ADC group 2
- */
-void adcNotification(adcBASE_t *adc, uint32_t group)
-{
-       if (adcIsConversionComplete(adc, group) == ADC_CONVERSION_IS_FINISHED) {
-
-               // ADC1
-               if (adc == adcREG1) {
-                       switch (group) {
-                       case adcGROUP0:
-                               // Group0 is unused on RPP
-                               break;
-                       case adcGROUP1:
-                               // According to FreeRTOS documentation second parameter is
-                               // optional (and can be set to NULL) from FreeRTOS
-                               // V7.3.0. We are using 7.0.2. I confirmed this in the
-                               // source code: src/os/queue.c line 821. - Carlos
-                       {
-                               signed portBASE_TYPE dummy;
-                               xSemaphoreGiveFromISR(adcSemaphore_ADC1GRP1, &dummy);
-                       }
-                       break;
-                       default:
-                               // Group2 is unused on RPP
-                               break;
-                       }
-                       // ADC2
-               }
-               else {
-                       switch (group) {
-                       case adcGROUP0:
-                               // Group0 is unused on RPP
-                               break;
-                       case adcGROUP1:
-                       {
-                               signed portBASE_TYPE dummy;
-                               xSemaphoreGiveFromISR(adcSemaphore_ADC2GRP1, &dummy);
-                       }
-                       break;
-                       default:
-                               // Group2 is unused on RPP
-                               break;
-                       }
-               }
-       }
-}
-
-
-uint32_t drv_adc_generic_read(adcBASE_t *adc, uint32_t group,
-                                                         xSemaphoreHandle adcSemaphore, adcData_t *data)
-{
-       // Calibrate
-       adcCalibration(adc);
-       adcMidPointCalibration(adc);
-
-       // Start conversion
-       adcEnableNotification(adc, group);
-       adcStartConversion(adc, group);
-
-       // Wait for conversion to complete
-       xSemaphoreTake(adcSemaphore, portMAX_DELAY);
-       adcDisableNotification(adc, group);
-
-       // Get data
-       uint32_t channels = adcGetData(adc, group, data);
-
-       // Check if memory overrun
-       if (adcIsFifoFull(adc, group) == ADC_FIFO_OVERFLOW)
-               // FIXME Should report somehow.
-               adcResetFiFo(adc, group);
-
-       return channels;
-}
-
-
-uint32_t drv_adc_read_adc(adcData_t *data)
-{
-       xSemaphoreTake(adcMutex_ADC, portMAX_DELAY);
-       uint32_t result = drv_adc_generic_read(
-               adcREG1,
-               adcGROUP1,
-               adcSemaphore_ADC1GRP1,
-               data
-               );
-       xSemaphoreGive(adcMutex_ADC);
-       return result;
-}
-
-uint32_t adc_get_port_val(uint32_t *config, uint32_t num_channels,
-                                                 uint32_t *values)
-{
-       uint32_t i;
-       adcBASE_t *adcReg = (adcBASE_t *)config[0];
-       uint32_t adcGroup = config[1];
-       uint32_t adcSemaphore = config[2];
-       adcData_t data[ADC_MAX_CHANNELS];
-
-       drv_adc_generic_read(
-               adcReg,
-               adcGroup,
-               (adcSemaphore == 1) ? adcSemaphore_ADC1GRP1 : adcSemaphore_ADC2GRP1,
-               data
-               );
-
-       for (i = 0; i < num_channels; i++) {
-               values[i] = data[i].value;
-               values[i+num_channels] = data[i].id;
-       }
-
-       return 0;
-}
index a5e801202dea94d5a46bb9c81f2b72b699db5da1..d7adfe16d26604270c8fc7ec4f62928a899f9b56 100644 (file)
@@ -66,8 +66,8 @@ const struct port_desc port_desc[] = {
        },
        [PORT_ID_ADC] = {
                .name = "ADC",
-               .cfg = { .adc = { .reg = adcREG1, .group = adcGROUP1, .sem = 1 } },
-               .numchn = 16,
+               .cfg = { .adc = { .reg = adcREG1, .group = adcGROUP1 } },
+               .numchn = PORT_ADC_CHANNELS,
                .bpch = 16,
                .get = port_adc_get,
                .set = NULL,
diff --git a/rpp/src/drv/_tms570_hdk/adc.c b/rpp/src/drv/_tms570_hdk/adc.c
deleted file mode 100644 (file)
index 550f974..0000000
+++ /dev/null
@@ -1,167 +0,0 @@
-/* Copyright (C) 2012-2013 Czech Technical University in Prague
- *
- * Authors:
- *     - Michal Horn
- *     - Carlos Jenkins <carlos@jenkins.co.cr>
- *
- * This document contains proprietary information belonging to Czech
- * Technical University in Prague. Passing on and copying of this
- * document, and communication of its contents is not permitted
- * without prior written authorization.
- *
- * File : adc.c
- * Abstract:
- *     RPP driver implementation for ADC.
- *
- * References:
- *     ti_drv_adc.c
- */
-
-
-#include "drv/drv.h"
-
-// Binary semaphore for ADC1 GRP1 conversion (AIN)
-xSemaphoreHandle adcSemaphore_ADC1GRP1;
-// Binary semaphore for ADC2 GRP1 conversion (HOUT-IFBK)
-xSemaphoreHandle adcSemaphore_ADC2GRP1;
-
-// Mutex for AIN read control
-xSemaphoreHandle adcMutex_ADC;
-
-void drv_adc_init()
-{
-       // Create semaphores
-       vSemaphoreCreateBinary(adcSemaphore_ADC1GRP1);
-       xSemaphoreTake(adcSemaphore_ADC1GRP1, 0);
-       vSemaphoreCreateBinary(adcSemaphore_ADC2GRP1);
-       xSemaphoreTake(adcSemaphore_ADC2GRP1, 0);
-
-       adcMutex_ADC       = xSemaphoreCreateMutex();
-
-       // Low level init
-       adcInit();
-}
-
-
-/**
- * ADC notification called by ADC conversion finished ISR.
- *
- * This procedure will just give semaphore.
- *
- *   @param[in] adc Pointer to ADC module:
- *              - adcREG1: ADC1 module pointer
- *              - adcREG2: ADC2 module pointer
- *   @param[in] group Hardware group of ADC module:
- *              - adcGROUP0: ADC event group
- *              - adcGROUP1: ADC group 1
- *              - adcGROUP2: ADC group 2
- */
-void adcNotification(adcBASE_t *adc, uint32_t group)
-{
-       if (adcIsConversionComplete(adc, group) == ADC_CONVERSION_IS_FINISHED) {
-
-               // ADC1
-               if (adc == adcREG1) {
-                       switch (group) {
-                       case adcGROUP0:
-                               // Group0 is unused on RPP
-                               break;
-                       case adcGROUP1:
-                               // According to FreeRTOS documentation second parameter is
-                               // optional (and can be set to NULL) from FreeRTOS
-                               // V7.3.0. We are using 7.0.2. I confirmed this in the
-                               // source code: src/os/queue.c line 821. - Carlos
-                       {
-                               signed portBASE_TYPE dummy;
-                               xSemaphoreGiveFromISR(adcSemaphore_ADC1GRP1, &dummy);
-                       }
-                       break;
-                       default:
-                               // Group2 is unused on RPP
-                               break;
-                       }
-                       // ADC2
-               }
-               else {
-                       switch (group) {
-                       case adcGROUP0:
-                               // Group0 is unused on RPP
-                               break;
-                       case adcGROUP1:
-                       {
-                               signed portBASE_TYPE dummy;
-                               xSemaphoreGiveFromISR(adcSemaphore_ADC2GRP1, &dummy);
-                       }
-                       break;
-                       default:
-                               // Group2 is unused on RPP
-                               break;
-                       }
-               }
-       }
-}
-
-
-uint32_t drv_adc_generic_read(adcBASE_t *adc, uint32_t group,
-                                                         xSemaphoreHandle adcSemaphore, adcData_t *data)
-{
-       // Calibrate
-       adcCalibration(adc);
-       adcMidPointCalibration(adc);
-
-       // Start conversion
-       adcEnableNotification(adc, group);
-       adcStartConversion(adc, group);
-
-       // Wait for conversion to complete
-       xSemaphoreTake(adcSemaphore, portMAX_DELAY);
-       adcDisableNotification(adc, group);
-
-       // Get data
-       uint32_t channels = adcGetData(adc, group, data);
-
-       // Check if memory overrun
-       if (adcIsFifoFull(adc, group) == ADC_FIFO_OVERFLOW)
-               // FIXME Should report somehow.
-               adcResetFiFo(adc, group);
-
-       return channels;
-}
-
-
-uint32_t drv_adc_read_adc(adcData_t *data)
-{
-       xSemaphoreTake(adcMutex_ADC, portMAX_DELAY);
-       uint32_t result = drv_adc_generic_read(
-               adcREG1,
-               adcGROUP1,
-               adcSemaphore_ADC1GRP1,
-               data
-               );
-       xSemaphoreGive(adcMutex_ADC);
-       return result;
-}
-
-uint32_t adc_get_port_val(uint32_t *config, uint32_t num_channels,
-                                                 uint32_t *values)
-{
-       uint32_t i;
-       adcBASE_t *adcReg = (adcBASE_t *)config[0];
-       uint32_t adcGroup = config[1];
-       uint32_t adcSemaphore = config[2];
-       adcData_t data[ADC_MAX_CHANNELS];
-
-       drv_adc_generic_read(
-               adcReg,
-               adcGroup,
-               (adcSemaphore == 1) ? adcSemaphore_ADC1GRP1 : adcSemaphore_ADC2GRP1,
-               data
-               );
-
-       for (i = 0; i < num_channels; i++) {
-               values[i] = data[i].value;
-               values[i+num_channels] = data[i].id;
-       }
-
-       return 0;
-}
index a5e801202dea94d5a46bb9c81f2b72b699db5da1..d7adfe16d26604270c8fc7ec4f62928a899f9b56 100644 (file)
@@ -66,8 +66,8 @@ const struct port_desc port_desc[] = {
        },
        [PORT_ID_ADC] = {
                .name = "ADC",
-               .cfg = { .adc = { .reg = adcREG1, .group = adcGROUP1, .sem = 1 } },
-               .numchn = 16,
+               .cfg = { .adc = { .reg = adcREG1, .group = adcGROUP1 } },
+               .numchn = PORT_ADC_CHANNELS,
                .bpch = 16,
                .get = port_adc_get,
                .set = NULL,
diff --git a/rpp/src/drv/_tms570_hydctr/adc.c b/rpp/src/drv/_tms570_hydctr/adc.c
deleted file mode 100644 (file)
index 550f974..0000000
+++ /dev/null
@@ -1,167 +0,0 @@
-/* Copyright (C) 2012-2013 Czech Technical University in Prague
- *
- * Authors:
- *     - Michal Horn
- *     - Carlos Jenkins <carlos@jenkins.co.cr>
- *
- * This document contains proprietary information belonging to Czech
- * Technical University in Prague. Passing on and copying of this
- * document, and communication of its contents is not permitted
- * without prior written authorization.
- *
- * File : adc.c
- * Abstract:
- *     RPP driver implementation for ADC.
- *
- * References:
- *     ti_drv_adc.c
- */
-
-
-#include "drv/drv.h"
-
-// Binary semaphore for ADC1 GRP1 conversion (AIN)
-xSemaphoreHandle adcSemaphore_ADC1GRP1;
-// Binary semaphore for ADC2 GRP1 conversion (HOUT-IFBK)
-xSemaphoreHandle adcSemaphore_ADC2GRP1;
-
-// Mutex for AIN read control
-xSemaphoreHandle adcMutex_ADC;
-
-void drv_adc_init()
-{
-       // Create semaphores
-       vSemaphoreCreateBinary(adcSemaphore_ADC1GRP1);
-       xSemaphoreTake(adcSemaphore_ADC1GRP1, 0);
-       vSemaphoreCreateBinary(adcSemaphore_ADC2GRP1);
-       xSemaphoreTake(adcSemaphore_ADC2GRP1, 0);
-
-       adcMutex_ADC       = xSemaphoreCreateMutex();
-
-       // Low level init
-       adcInit();
-}
-
-
-/**
- * ADC notification called by ADC conversion finished ISR.
- *
- * This procedure will just give semaphore.
- *
- *   @param[in] adc Pointer to ADC module:
- *              - adcREG1: ADC1 module pointer
- *              - adcREG2: ADC2 module pointer
- *   @param[in] group Hardware group of ADC module:
- *              - adcGROUP0: ADC event group
- *              - adcGROUP1: ADC group 1
- *              - adcGROUP2: ADC group 2
- */
-void adcNotification(adcBASE_t *adc, uint32_t group)
-{
-       if (adcIsConversionComplete(adc, group) == ADC_CONVERSION_IS_FINISHED) {
-
-               // ADC1
-               if (adc == adcREG1) {
-                       switch (group) {
-                       case adcGROUP0:
-                               // Group0 is unused on RPP
-                               break;
-                       case adcGROUP1:
-                               // According to FreeRTOS documentation second parameter is
-                               // optional (and can be set to NULL) from FreeRTOS
-                               // V7.3.0. We are using 7.0.2. I confirmed this in the
-                               // source code: src/os/queue.c line 821. - Carlos
-                       {
-                               signed portBASE_TYPE dummy;
-                               xSemaphoreGiveFromISR(adcSemaphore_ADC1GRP1, &dummy);
-                       }
-                       break;
-                       default:
-                               // Group2 is unused on RPP
-                               break;
-                       }
-                       // ADC2
-               }
-               else {
-                       switch (group) {
-                       case adcGROUP0:
-                               // Group0 is unused on RPP
-                               break;
-                       case adcGROUP1:
-                       {
-                               signed portBASE_TYPE dummy;
-                               xSemaphoreGiveFromISR(adcSemaphore_ADC2GRP1, &dummy);
-                       }
-                       break;
-                       default:
-                               // Group2 is unused on RPP
-                               break;
-                       }
-               }
-       }
-}
-
-
-uint32_t drv_adc_generic_read(adcBASE_t *adc, uint32_t group,
-                                                         xSemaphoreHandle adcSemaphore, adcData_t *data)
-{
-       // Calibrate
-       adcCalibration(adc);
-       adcMidPointCalibration(adc);
-
-       // Start conversion
-       adcEnableNotification(adc, group);
-       adcStartConversion(adc, group);
-
-       // Wait for conversion to complete
-       xSemaphoreTake(adcSemaphore, portMAX_DELAY);
-       adcDisableNotification(adc, group);
-
-       // Get data
-       uint32_t channels = adcGetData(adc, group, data);
-
-       // Check if memory overrun
-       if (adcIsFifoFull(adc, group) == ADC_FIFO_OVERFLOW)
-               // FIXME Should report somehow.
-               adcResetFiFo(adc, group);
-
-       return channels;
-}
-
-
-uint32_t drv_adc_read_adc(adcData_t *data)
-{
-       xSemaphoreTake(adcMutex_ADC, portMAX_DELAY);
-       uint32_t result = drv_adc_generic_read(
-               adcREG1,
-               adcGROUP1,
-               adcSemaphore_ADC1GRP1,
-               data
-               );
-       xSemaphoreGive(adcMutex_ADC);
-       return result;
-}
-
-uint32_t adc_get_port_val(uint32_t *config, uint32_t num_channels,
-                                                 uint32_t *values)
-{
-       uint32_t i;
-       adcBASE_t *adcReg = (adcBASE_t *)config[0];
-       uint32_t adcGroup = config[1];
-       uint32_t adcSemaphore = config[2];
-       adcData_t data[ADC_MAX_CHANNELS];
-
-       drv_adc_generic_read(
-               adcReg,
-               adcGroup,
-               (adcSemaphore == 1) ? adcSemaphore_ADC1GRP1 : adcSemaphore_ADC2GRP1,
-               data
-               );
-
-       for (i = 0; i < num_channels; i++) {
-               values[i] = data[i].value;
-               values[i+num_channels] = data[i].id;
-       }
-
-       return 0;
-}
index a5e801202dea94d5a46bb9c81f2b72b699db5da1..d7adfe16d26604270c8fc7ec4f62928a899f9b56 100644 (file)
@@ -66,8 +66,8 @@ const struct port_desc port_desc[] = {
        },
        [PORT_ID_ADC] = {
                .name = "ADC",
-               .cfg = { .adc = { .reg = adcREG1, .group = adcGROUP1, .sem = 1 } },
-               .numchn = 16,
+               .cfg = { .adc = { .reg = adcREG1, .group = adcGROUP1 } },
+               .numchn = PORT_ADC_CHANNELS,
                .bpch = 16,
                .get = port_adc_get,
                .set = NULL,
index 8a14edea8a3c3a987e7603147101d3183367ac04..a127ed413fd1fea8b633579437226255d8dda833 100644 (file)
@@ -79,15 +79,15 @@ const struct port_desc port_desc[] = {
                .bpch = 16,
                .get = port_adc_get,
                .set = NULL,
-               .cfg = { .adc = { .reg = adcREG2, .group = adcGROUP1, .sem = 0 } },
+               .cfg = { .adc = { .reg = adcREG2, .group = adcGROUP1 } },
        },
        [PORT_ID_ADC] = {
                .name = "ADC",
-               .numchn = 12,
+               .numchn = PORT_ADC_CHANNELS,
                .bpch = 16,
                .get = port_adc_get,
                .set = NULL,
-               .cfg = { .adc = { .reg = adcREG1, .group = adcGROUP1, .sem = 1 } },
+               .cfg = { .adc = { .reg = adcREG1, .group = adcGROUP1 } },
        },
        [PORT_ID_LOUT] = {
                .name = "LOUT",
similarity index 50%
rename from rpp/src/drv/_tms570_rpp/adc.c
rename to rpp/src/drv/adc.c
index 54763e27f424bf575b997b59f19e3d09776e6344..7089cfa56144662b232e707e29eac12a0f1e965b 100644 (file)
 #include "drv/drv.h"
 #include "drv/port.h"
 
-// Binary semaphore for ADC1 GRP1 conversion (AIN)
-xSemaphoreHandle adcSemaphore_ADC1GRP1;
-// Binary semaphore for ADC2 GRP1 conversion (HOUT-IFBK)
-xSemaphoreHandle adcSemaphore_ADC2GRP1;
+// Binary semaphores for finish notifications
+static xSemaphoreHandle sem[2][2];
 
-// Mutex for AIN read control
-xSemaphoreHandle adcMutex_ADC;
-// Mutex for HOUTIFBK control
-xSemaphoreHandle adcMutex_HOUTIFBK;
+// Mutex for two ADCs
+xSemaphoreHandle mutex[2];
 
 void drv_adc_init()
 {
-       // Create semaphores
-       vSemaphoreCreateBinary(adcSemaphore_ADC1GRP1);
-       xSemaphoreTake(adcSemaphore_ADC1GRP1, 0);
-       vSemaphoreCreateBinary(adcSemaphore_ADC2GRP1);
-       xSemaphoreTake(adcSemaphore_ADC2GRP1, 0);
-
-       adcMutex_ADC       = xSemaphoreCreateMutex();
-       adcMutex_HOUTIFBK  = xSemaphoreCreateMutex();
+       int adc, grp;
 
+       for (adc = 0; adc < 2; adc++) {
+               for (grp = 0; grp < 2; grp++) {
+                       vSemaphoreCreateBinary(sem[adc][grp]);
+                       xSemaphoreTake(sem[adc][grp], 0);
+               }
+               mutex[adc] = xSemaphoreCreateMutex();
+       }
        // Low level init
        adcInit();
 }
@@ -63,52 +59,22 @@ void drv_adc_init()
 void adcNotification(adcBASE_t *adc, uint32_t group)
 {
        if (adcIsConversionComplete(adc, group) == ADC_CONVERSION_IS_FINISHED) {
-
-               // ADC1
-               if (adc == adcREG1) {
-                       switch (group) {
-                       case adcGROUP0:
-                               // Group0 is unused on RPP
-                               break;
-                       case adcGROUP1:
-                               // According to FreeRTOS documentation second parameter is
-                               // optional (and can be set to NULL) from FreeRTOS
-                               // V7.3.0. We are using 7.0.2. I confirmed this in the
-                               // source code: src/os/queue.c line 821. - Carlos
-                       {
-                               signed portBASE_TYPE dummy;
-                               xSemaphoreGiveFromISR(adcSemaphore_ADC1GRP1, &dummy);
-                       }
-                       break;
-                       default:
-                               // Group2 is unused on RPP
-                               break;
-                       }
-                       // ADC2
-               }
-               else {
-                       switch (group) {
-                       case adcGROUP0:
-                               // Group0 is unused on RPP
-                               break;
-                       case adcGROUP1:
-                       {
-                               signed portBASE_TYPE dummy;
-                               xSemaphoreGiveFromISR(adcSemaphore_ADC2GRP1, &dummy);
-                       }
-                       break;
-                       default:
-                               // Group2 is unused on RPP
-                               break;
-                       }
-               }
+               signed portBASE_TYPE dummy;
+               int adc_idx = (adc == adcREG1) ? 0 : 1;
+               int grp_idx = (group == adcGROUP1) ? 0 : 1;
+               xSemaphoreGiveFromISR(sem[adc_idx][grp_idx], &dummy);
        }
 }
 
 
 uint32_t drv_adc_generic_read(adcBASE_t *adc, uint32_t group,
-                                                         xSemaphoreHandle adcSemaphore, adcData_t *data)
+                                                         adcData_t *data)
 {
+       int adc_idx = (adc == adcREG1) ? 0 : 1;
+       int grp_idx = (group == adcGROUP1) ? 0 : 1;
+
+       xSemaphoreTake(mutex[adc_idx], portMAX_DELAY);
+
        // Calibrate
        adcCalibration(adc);
        adcMidPointCalibration(adc);
@@ -118,7 +84,7 @@ uint32_t drv_adc_generic_read(adcBASE_t *adc, uint32_t group,
        adcStartConversion(adc, group);
 
        // Wait for conversion to complete
-       xSemaphoreTake(adcSemaphore, portMAX_DELAY);
+       xSemaphoreTake(sem[adc_idx][grp_idx], portMAX_DELAY);
        adcDisableNotification(adc, group);
 
        // Get data
@@ -129,34 +95,9 @@ uint32_t drv_adc_generic_read(adcBASE_t *adc, uint32_t group,
                // FIXME Should report somehow.
                adcResetFiFo(adc, group);
 
-       return channels;
-}
-
-
-uint32_t drv_adc_read_adc(adcData_t *data)
-{
-       xSemaphoreTake(adcMutex_ADC, portMAX_DELAY);
-       uint32_t result = drv_adc_generic_read(
-               adcREG1,
-               adcGROUP1,
-               adcSemaphore_ADC1GRP1,
-               data
-               );
-       xSemaphoreGive(adcMutex_ADC);
-       return result;
-}
+       xSemaphoreGive(mutex[adc_idx]);
 
-uint32_t drv_adc_read_houtifbk(adcData_t *data)
-{
-       xSemaphoreTake(adcMutex_HOUTIFBK, portMAX_DELAY);
-       uint32_t result = drv_adc_generic_read(
-               adcREG2,
-               adcGROUP1,
-               adcSemaphore_ADC2GRP1,
-               data
-               );
-       xSemaphoreGive(adcMutex_HOUTIFBK);
-       return result;
+       return channels;
 }
 
 #define MIN(a,b) ((a) < (b) ? (a) : (b))
@@ -174,7 +115,6 @@ int8_t port_adc_get(const struct port_desc *port, void *values, size_t size)
        drv_adc_generic_read(
                port->cfg.adc.reg,
                port->cfg.adc.group,
-               (port->cfg.adc.sem == 1) ? adcSemaphore_ADC1GRP1 : adcSemaphore_ADC2GRP1,
                data
                );
 
index d96f9a9713e2bd5b2557bf31d5128d40a3dab4d9..23c96f30bb512378a1782f0894c3ec863ef144d3 100644 (file)
@@ -1,3 +1,4 @@
+/adc.c eaton
 /can.c eaton
 /gio.c eaton
 /rpp.c eaton
diff --git a/rpp/src/rpp/_rm48_hdk/.gitattributes b/rpp/src/rpp/_rm48_hdk/.gitattributes
deleted file mode 100644 (file)
index 744c6a5..0000000
+++ /dev/null
@@ -1 +0,0 @@
-/adc.c eaton
diff --git a/rpp/src/rpp/_tms570_hdk/.gitattributes b/rpp/src/rpp/_tms570_hdk/.gitattributes
deleted file mode 100644 (file)
index 744c6a5..0000000
+++ /dev/null
@@ -1 +0,0 @@
-/adc.c eaton
diff --git a/rpp/src/rpp/_tms570_hdk/adc.c b/rpp/src/rpp/_tms570_hdk/adc.c
deleted file mode 100644 (file)
index 8f0ede0..0000000
+++ /dev/null
@@ -1,73 +0,0 @@
-/* Copyright (C) 2013 Czech Technical University in Prague
- *
- * Authors:
- *     - Carlos Jenkins <carlos@jenkins.co.cr>
- *
- * This document contains proprietary information belonging to Czech
- * Technical University in Prague. Passing on and copying of this
- * document, and communication of its contents is not permitted
- * without prior written authorization.
- *
- * File : adc.c
- * Abstract:
- *     Analog Input RPP API implementation file.
- *
- * References:
- *     adc.h
- *     RPP API documentation.
- */
-
-
-#include "rpp/rpp.h"
-
-#ifndef FREERTOS_POSIX
-#include "drv/drv.h"
-
-// RPP has 12 ADC channels
-// See s_adcSelect and s_adcFiFoSize in ti_drv_adc.c for hardware configuration.
-#define ADC_CHANNELS 16
-static adcData_t in_cache[ADC_CHANNELS];
-#endif
-
-static boolean_t initialized = FALSE;
-
-int8_t rpp_adc_init()
-{
-       if (initialized)
-               return FAILURE;
-       initialized = TRUE;
-
-#ifndef FREERTOS_POSIX
-       drv_adc_init();
-#endif
-
-       return SUCCESS;
-}
-
-
-int16_t rpp_adc_get(uint8_t pin)
-{
-       if ((pin < 1) || (pin > 16))
-               return -1;
-
-       int16_t result = 0;
-
-#ifndef FREERTOS_POSIX
-       // This conversion uint16_t -> int16_t is safe because we know values
-       // are 12bits. Here we are masking those 12bits just in case.
-       result = (int16_t)(in_cache[pin - 1].value & 0xFFF);
-#endif
-
-       return result;
-}
-
-
-int8_t rpp_adc_update()
-{
-#ifndef FREERTOS_POSIX
-       // in_cache is thread safe because it's only write operation is mutexed
-       drv_adc_read_adc((adcData_t *)&in_cache);
-#endif
-
-       return SUCCESS;
-}
diff --git a/rpp/src/rpp/_tms570_hydctr/.gitattributes b/rpp/src/rpp/_tms570_hydctr/.gitattributes
deleted file mode 100644 (file)
index 744c6a5..0000000
+++ /dev/null
@@ -1 +0,0 @@
-/adc.c eaton
diff --git a/rpp/src/rpp/_tms570_hydctr/adc.c b/rpp/src/rpp/_tms570_hydctr/adc.c
deleted file mode 100644 (file)
index 8f0ede0..0000000
+++ /dev/null
@@ -1,73 +0,0 @@
-/* Copyright (C) 2013 Czech Technical University in Prague
- *
- * Authors:
- *     - Carlos Jenkins <carlos@jenkins.co.cr>
- *
- * This document contains proprietary information belonging to Czech
- * Technical University in Prague. Passing on and copying of this
- * document, and communication of its contents is not permitted
- * without prior written authorization.
- *
- * File : adc.c
- * Abstract:
- *     Analog Input RPP API implementation file.
- *
- * References:
- *     adc.h
- *     RPP API documentation.
- */
-
-
-#include "rpp/rpp.h"
-
-#ifndef FREERTOS_POSIX
-#include "drv/drv.h"
-
-// RPP has 12 ADC channels
-// See s_adcSelect and s_adcFiFoSize in ti_drv_adc.c for hardware configuration.
-#define ADC_CHANNELS 16
-static adcData_t in_cache[ADC_CHANNELS];
-#endif
-
-static boolean_t initialized = FALSE;
-
-int8_t rpp_adc_init()
-{
-       if (initialized)
-               return FAILURE;
-       initialized = TRUE;
-
-#ifndef FREERTOS_POSIX
-       drv_adc_init();
-#endif
-
-       return SUCCESS;
-}
-
-
-int16_t rpp_adc_get(uint8_t pin)
-{
-       if ((pin < 1) || (pin > 16))
-               return -1;
-
-       int16_t result = 0;
-
-#ifndef FREERTOS_POSIX
-       // This conversion uint16_t -> int16_t is safe because we know values
-       // are 12bits. Here we are masking those 12bits just in case.
-       result = (int16_t)(in_cache[pin - 1].value & 0xFFF);
-#endif
-
-       return result;
-}
-
-
-int8_t rpp_adc_update()
-{
-#ifndef FREERTOS_POSIX
-       // in_cache is thread safe because it's only write operation is mutexed
-       drv_adc_read_adc((adcData_t *)&in_cache);
-#endif
-
-       return SUCCESS;
-}
diff --git a/rpp/src/rpp/_tms570_rpp/adc.c b/rpp/src/rpp/_tms570_rpp/adc.c
deleted file mode 100644 (file)
index 161700e..0000000
+++ /dev/null
@@ -1,73 +0,0 @@
-/* Copyright (C) 2013 Czech Technical University in Prague
- *
- * Authors:
- *     - Carlos Jenkins <carlos@jenkins.co.cr>
- *
- * This document contains proprietary information belonging to Czech
- * Technical University in Prague. Passing on and copying of this
- * document, and communication of its contents is not permitted
- * without prior written authorization.
- *
- * File : adc.c
- * Abstract:
- *     Analog Input RPP API implementation file.
- *
- * References:
- *     adc.h
- *     RPP API documentation.
- */
-
-
-#include "rpp/rpp.h"
-
-#ifndef FREERTOS_POSIX
-#include "drv/drv.h"
-
-// RPP has 12 ADC channels
-// See s_adcSelect and s_adcFiFoSize in ti_drv_adc.c for hardware configuration.
-#define ADC_CHANNELS 12
-static adcData_t in_cache[ADC_CHANNELS];
-#endif
-
-static boolean_t initialized = FALSE;
-
-int8_t rpp_adc_init()
-{
-       if (initialized)
-               return FAILURE;
-       initialized = TRUE;
-
-#ifndef FREERTOS_POSIX
-       drv_adc_init();
-#endif
-
-       return SUCCESS;
-}
-
-
-int16_t rpp_adc_get(uint8_t pin)
-{
-       if ((pin < 1) || (pin > 12))
-               return -1;
-
-       int16_t result = 0;
-
-#ifndef FREERTOS_POSIX
-       // This conversion uint16_t -> int16_t is safe because we know values
-       // are 12bits. Here we are masking those 12bits just in case.
-       result = (int16_t)(in_cache[pin - 1].value & 0xFFF);
-#endif
-
-       return result;
-}
-
-
-int8_t rpp_adc_update()
-{
-#ifndef FREERTOS_POSIX
-       // in_cache is thread safe because it's only write operation is mutexed
-       drv_adc_read_adc((adcData_t *)&in_cache);
-#endif
-
-       return SUCCESS;
-}
similarity index 70%
rename from rpp/src/rpp/_rm48_hdk/adc.c
rename to rpp/src/rpp/adc.c
index 8f0ede023e7c5a8ed43784d1923e6c923131d71d..30e180d7294ee2de45ffffb7096a58fed099789c 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 2013 Czech Technical University in Prague
+/* Copyright (C) 2013, 2015 Czech Technical University in Prague
  *
  * Authors:
  *     - Carlos Jenkins <carlos@jenkins.co.cr>
 
 #ifndef FREERTOS_POSIX
 #include "drv/drv.h"
+#include "drv/port.h"
 
-// RPP has 12 ADC channels
-// See s_adcSelect and s_adcFiFoSize in ti_drv_adc.c for hardware configuration.
-#define ADC_CHANNELS 16
-static adcData_t in_cache[ADC_CHANNELS];
+static uint16_t in_cache[PORT_ADC_CHANNELS];
 #endif
 
 static boolean_t initialized = FALSE;
@@ -47,7 +45,7 @@ int8_t rpp_adc_init()
 
 int16_t rpp_adc_get(uint8_t pin)
 {
-       if ((pin < 1) || (pin > 16))
+       if ((pin < 1) || (pin > PORT_ADC_CHANNELS))
                return -1;
 
        int16_t result = 0;
@@ -55,7 +53,7 @@ int16_t rpp_adc_get(uint8_t pin)
 #ifndef FREERTOS_POSIX
        // This conversion uint16_t -> int16_t is safe because we know values
        // are 12bits. Here we are masking those 12bits just in case.
-       result = (int16_t)(in_cache[pin - 1].value & 0xFFF);
+       result = in_cache[pin - 1] & 0xFFF;
 #endif
 
        return result;
@@ -65,8 +63,8 @@ int16_t rpp_adc_get(uint8_t pin)
 int8_t rpp_adc_update()
 {
 #ifndef FREERTOS_POSIX
-       // in_cache is thread safe because it's only write operation is mutexed
-       drv_adc_read_adc((adcData_t *)&in_cache);
+       const struct port_desc *port = &port_desc[PORT_ID_ADC];
+       port->get(port, in_cache, sizeof(in_cache));
 #endif
 
        return SUCCESS;