From 000b556500e67711420fe5aa7728bd1873c162df Mon Sep 17 00:00:00 2001
From: Sasan Golchin <ahmad.golchin@mail.polimi.it>
Date: Wed, 14 Sep 2016 15:58:17 +0200
Subject: [PATCH] EFM32GG dependent code (DMA and so) are removed from common
 portability.h and moved to
 /arch/cortexM3_efm32gg/common/interfaces-impl/fixme_dma.h and also some parts
 in kernel.cpp are surrounded with #ifdef BOARD_efm32gg332f1024_wandstem

---
 .../common/interfaces-impl/fixme_dma.h        | 123 ++++++++++++++++++
 miosix/interfaces/portability.h               | 115 +---------------
 miosix/kernel/kernel.cpp                      |   8 +-
 3 files changed, 130 insertions(+), 116 deletions(-)
 create mode 100644 miosix/arch/cortexM3_efm32gg/common/interfaces-impl/fixme_dma.h

diff --git a/miosix/arch/cortexM3_efm32gg/common/interfaces-impl/fixme_dma.h b/miosix/arch/cortexM3_efm32gg/common/interfaces-impl/fixme_dma.h
new file mode 100644
index 00000000..87587c1c
--- /dev/null
+++ b/miosix/arch/cortexM3_efm32gg/common/interfaces-impl/fixme_dma.h
@@ -0,0 +1,123 @@
+/***************************************************************************
+ *  FIXXX ME
+ ***************************************************************************/
+
+#ifndef PORTABILITY_H
+#define	PORTABILITY_H
+
+
+#define DMA_CHANNEL_ADC                   0
+
+#if ( ( DMA_CHAN_COUNT > 4 ) && ( DMA_CHAN_COUNT <= 8 ) )
+#define DMACTRL_CH_CNT      8
+#define DMACTRL_ALIGNMENT   256
+
+#elif ( ( DMA_CHAN_COUNT > 8 ) && ( DMA_CHAN_COUNT <= 16 ) )
+#define DMACTRL_CH_CNT      16
+#define DMACTRL_ALIGNMENT   512
+
+#endif
+
+typedef enum
+{
+  dmaDataInc1    = _DMA_CTRL_SRC_INC_BYTE,     /**< Increment address 1 byte. */
+  dmaDataInc2    = _DMA_CTRL_SRC_INC_HALFWORD, /**< Increment address 2 bytes. */
+  dmaDataInc4    = _DMA_CTRL_SRC_INC_WORD,     /**< Increment address 4 bytes. */
+  dmaDataIncNone = _DMA_CTRL_SRC_INC_NONE      /**< Do not increment address. */
+} DMA_DataInc_TypeDef;
+
+typedef enum
+{
+  dmaDataSize1 = _DMA_CTRL_SRC_SIZE_BYTE,     /**< 1 byte DMA transfer size. */
+  dmaDataSize2 = _DMA_CTRL_SRC_SIZE_HALFWORD, /**< 2 byte DMA transfer size. */
+  dmaDataSize4 = _DMA_CTRL_SRC_SIZE_WORD      /**< 4 byte DMA transfer size. */
+} DMA_DataSize_TypeDef;
+
+
+typedef enum
+{
+    dmaCycleCtrlBasic            = _DMA_CTRL_CYCLE_CTRL_BASIC,
+    dmaCycleCtrlAuto             = _DMA_CTRL_CYCLE_CTRL_AUTO,
+    dmaCycleCtrlPingPong         = _DMA_CTRL_CYCLE_CTRL_PINGPONG,
+    dmaCycleCtrlMemScatterGather = _DMA_CTRL_CYCLE_CTRL_MEM_SCATTER_GATHER,
+    dmaCycleCtrlPerScatterGather = _DMA_CTRL_CYCLE_CTRL_PER_SCATTER_GATHER
+          
+} DMA_CycleCtrl_TypeDef;
+
+typedef enum
+{
+    dmaArbitrate1    = _DMA_CTRL_R_POWER_1,    /**< Arbitrate after 1 DMA transfer. */
+    dmaArbitrate2    = _DMA_CTRL_R_POWER_2,    /**< Arbitrate after 2 DMA transfers. */
+    dmaArbitrate4    = _DMA_CTRL_R_POWER_4,    /**< Arbitrate after 4 DMA transfers. */
+    dmaArbitrate8    = _DMA_CTRL_R_POWER_8,    /**< Arbitrate after 8 DMA transfers. */
+    dmaArbitrate16   = _DMA_CTRL_R_POWER_16,   /**< Arbitrate after 16 DMA transfers. */
+    dmaArbitrate32   = _DMA_CTRL_R_POWER_32,   /**< Arbitrate after 32 DMA transfers. */
+    dmaArbitrate64   = _DMA_CTRL_R_POWER_64,   /**< Arbitrate after 64 DMA transfers. */
+    dmaArbitrate128  = _DMA_CTRL_R_POWER_128,  /**< Arbitrate after 128 DMA transfers. */
+    dmaArbitrate256  = _DMA_CTRL_R_POWER_256,  /**< Arbitrate after 256 DMA transfers. */
+    dmaArbitrate512  = _DMA_CTRL_R_POWER_512,  /**< Arbitrate after 512 DMA transfers. */
+    dmaArbitrate1024 = _DMA_CTRL_R_POWER_1024  /**< Arbitrate after 1024 DMA transfers. */
+
+} DMA_ArbiterConfig_TypeDef;
+
+typedef struct
+{
+  uint8_t hprot;    //priviliged or not
+  DMA_DESCRIPTOR_TypeDef *controlBlock;
+} DMA_Init_TypeDef;
+
+typedef struct
+{
+    DMA_DataInc_TypeDef       dstInc;
+    DMA_DataInc_TypeDef       srcInc;
+    DMA_DataSize_TypeDef      size;
+    DMA_ArbiterConfig_TypeDef arbRate;
+    uint8_t hprot;
+    
+} DMA_CfgDescr_TypeDef;
+
+typedef void (*DMA_FuncPtr_TypeDef)(unsigned int channel, bool primary, void *user);
+
+typedef struct
+{
+     DMA_FuncPtr_TypeDef cbFunc;
+    void                *userPtr;
+    uint8_t             primary;
+    
+} DMA_CB_TypeDef;
+
+typedef struct
+{
+    bool     highPri;
+    bool     enableInt;
+    uint32_t select;
+    DMA_CB_TypeDef *cb;
+    
+} DMA_CfgChannel_TypeDef;
+
+void DMA_Pause(void);
+void DMA_begin(void);
+
+void setup_DMA(DMA_CB_TypeDef cbtemp);
+void DMA_CfgChannel(unsigned int channel, DMA_CfgChannel_TypeDef *cfg);
+void DMA_Reset(void);
+void DMA_CfgDescr(unsigned int channel, bool primary,DMA_CfgDescr_TypeDef *cfg);
+void DMA_Init(DMA_Init_TypeDef *init);
+
+void DMA_ActivatePingPong(unsigned int channel,bool useBurst,
+                          void *primDst,void *primSrc,unsigned int primNMinus1,
+                          void *altDst,void *altSrc,unsigned int altNMinus1);
+
+void DMA_RefreshPingPong(unsigned int channel, bool primary,bool useBurst,
+                         void *dst, void *src, unsigned int nMinus1,bool stop);
+
+void DMA_Prepare(unsigned int channel,DMA_CycleCtrl_TypeDef cycleCtrl,
+                 bool primary,bool useBurst,void *dst,void *src,unsigned int nMinus1);
+    
+void waitRtc(int val);
+void initRtc(); 
+void IRQdeepSleep();
+    
+
+
+#endif
diff --git a/miosix/interfaces/portability.h b/miosix/interfaces/portability.h
index 835495e6..bf8bfa86 100644
--- a/miosix/interfaces/portability.h
+++ b/miosix/interfaces/portability.h
@@ -33,7 +33,6 @@
 //For MPUConfiguration
 #include "core/memory_protection.h"
 #include <cstddef>
-#include "interfaces-impl/portability_impl.h"
 
 /**
  * \addtogroup Interfaces
@@ -63,18 +62,6 @@ class Process; //Forward decl
 
 #endif //WITH_PROCESSES
 
-#define DMA_CHANNEL_ADC                   0
-
-#if ( ( DMA_CHAN_COUNT > 4 ) && ( DMA_CHAN_COUNT <= 8 ) )
-#define DMACTRL_CH_CNT      8
-#define DMACTRL_ALIGNMENT   256
-
-#elif ( ( DMA_CHAN_COUNT > 8 ) && ( DMA_CHAN_COUNT <= 16 ) )
-#define DMACTRL_CH_CNT      16
-#define DMACTRL_ALIGNMENT   512
-
-#endif
-
 /**
  * \}
  */
@@ -97,106 +84,6 @@ namespace miosix_private {
 
    
   
-typedef enum
-{
-  dmaDataInc1    = _DMA_CTRL_SRC_INC_BYTE,     /**< Increment address 1 byte. */
-  dmaDataInc2    = _DMA_CTRL_SRC_INC_HALFWORD, /**< Increment address 2 bytes. */
-  dmaDataInc4    = _DMA_CTRL_SRC_INC_WORD,     /**< Increment address 4 bytes. */
-  dmaDataIncNone = _DMA_CTRL_SRC_INC_NONE      /**< Do not increment address. */
-} DMA_DataInc_TypeDef;
-
-typedef enum
-{
-  dmaDataSize1 = _DMA_CTRL_SRC_SIZE_BYTE,     /**< 1 byte DMA transfer size. */
-  dmaDataSize2 = _DMA_CTRL_SRC_SIZE_HALFWORD, /**< 2 byte DMA transfer size. */
-  dmaDataSize4 = _DMA_CTRL_SRC_SIZE_WORD      /**< 4 byte DMA transfer size. */
-} DMA_DataSize_TypeDef;
-
-
-typedef enum
-{
-    dmaCycleCtrlBasic            = _DMA_CTRL_CYCLE_CTRL_BASIC,
-    dmaCycleCtrlAuto             = _DMA_CTRL_CYCLE_CTRL_AUTO,
-    dmaCycleCtrlPingPong         = _DMA_CTRL_CYCLE_CTRL_PINGPONG,
-    dmaCycleCtrlMemScatterGather = _DMA_CTRL_CYCLE_CTRL_MEM_SCATTER_GATHER,
-    dmaCycleCtrlPerScatterGather = _DMA_CTRL_CYCLE_CTRL_PER_SCATTER_GATHER
-          
-} DMA_CycleCtrl_TypeDef;
-
-typedef enum
-{
-    dmaArbitrate1    = _DMA_CTRL_R_POWER_1,    /**< Arbitrate after 1 DMA transfer. */
-    dmaArbitrate2    = _DMA_CTRL_R_POWER_2,    /**< Arbitrate after 2 DMA transfers. */
-    dmaArbitrate4    = _DMA_CTRL_R_POWER_4,    /**< Arbitrate after 4 DMA transfers. */
-    dmaArbitrate8    = _DMA_CTRL_R_POWER_8,    /**< Arbitrate after 8 DMA transfers. */
-    dmaArbitrate16   = _DMA_CTRL_R_POWER_16,   /**< Arbitrate after 16 DMA transfers. */
-    dmaArbitrate32   = _DMA_CTRL_R_POWER_32,   /**< Arbitrate after 32 DMA transfers. */
-    dmaArbitrate64   = _DMA_CTRL_R_POWER_64,   /**< Arbitrate after 64 DMA transfers. */
-    dmaArbitrate128  = _DMA_CTRL_R_POWER_128,  /**< Arbitrate after 128 DMA transfers. */
-    dmaArbitrate256  = _DMA_CTRL_R_POWER_256,  /**< Arbitrate after 256 DMA transfers. */
-    dmaArbitrate512  = _DMA_CTRL_R_POWER_512,  /**< Arbitrate after 512 DMA transfers. */
-    dmaArbitrate1024 = _DMA_CTRL_R_POWER_1024  /**< Arbitrate after 1024 DMA transfers. */
-
-} DMA_ArbiterConfig_TypeDef;
-
-typedef struct
-{
-  uint8_t hprot;    //priviliged or not
-  DMA_DESCRIPTOR_TypeDef *controlBlock;
-} DMA_Init_TypeDef;
-
-typedef struct
-{
-    DMA_DataInc_TypeDef       dstInc;
-    DMA_DataInc_TypeDef       srcInc;
-    DMA_DataSize_TypeDef      size;
-    DMA_ArbiterConfig_TypeDef arbRate;
-    uint8_t hprot;
-    
-} DMA_CfgDescr_TypeDef;
-
-typedef void (*DMA_FuncPtr_TypeDef)(unsigned int channel, bool primary, void *user);
-
-typedef struct
-{
-     DMA_FuncPtr_TypeDef cbFunc;
-    void                *userPtr;
-    uint8_t             primary;
-    
-} DMA_CB_TypeDef;
-
-typedef struct
-{
-    bool     highPri;
-    bool     enableInt;
-    uint32_t select;
-    DMA_CB_TypeDef *cb;
-    
-} DMA_CfgChannel_TypeDef;
-
-void DMA_Pause(void);
-void DMA_begin(void);
-
-void setup_DMA(DMA_CB_TypeDef cbtemp);
-void DMA_CfgChannel(unsigned int channel, DMA_CfgChannel_TypeDef *cfg);
-void DMA_Reset(void);
-void DMA_CfgDescr(unsigned int channel, bool primary,DMA_CfgDescr_TypeDef *cfg);
-void DMA_Init(DMA_Init_TypeDef *init);
-
-void DMA_ActivatePingPong(unsigned int channel,bool useBurst,
-                          void *primDst,void *primSrc,unsigned int primNMinus1,
-                          void *altDst,void *altSrc,unsigned int altNMinus1);
-
-void DMA_RefreshPingPong(unsigned int channel, bool primary,bool useBurst,
-                         void *dst, void *src, unsigned int nMinus1,bool stop);
-
-void DMA_Prepare(unsigned int channel,DMA_CycleCtrl_TypeDef cycleCtrl,
-                 bool primary,bool useBurst,void *dst,void *src,unsigned int nMinus1);
-    
-void waitRtc(int val);
-void initRtc(); 
-void IRQdeepSleep();
-    
 /**
  * \internal
  * Used after an unrecoverable error condition to restart the system, even from
@@ -453,6 +340,6 @@ private:
 } //namespace miosix_private
 
 // This contains the macros and the implementation of inline functions
-
+#include "interfaces-impl/portability_impl.h"
 
 #endif //PORTABILITY_H
diff --git a/miosix/kernel/kernel.cpp b/miosix/kernel/kernel.cpp
index 2d288bd8..2b275ca2 100644
--- a/miosix/kernel/kernel.cpp
+++ b/miosix/kernel/kernel.cpp
@@ -119,7 +119,7 @@ void *idleThread(void *argv)
         #ifndef JTAG_DISABLE_SLEEP
         //JTAG debuggers lose communication with the device if it enters sleep
         //mode, so to use debugging it is necessary to remove this instruction
-        
+#ifdef BOARD_efm32gg332f1024_wandstem
         bool sleep=false;
         {
             FastInterruptDisableLock lock;
@@ -131,6 +131,9 @@ void *idleThread(void *argv)
                 sleep=true;
         }
         if (sleep) miosix_private::sleepCpu();
+#else
+        miosix_private::sleepCpu();
+#endif
         
         #endif
     }
@@ -190,6 +193,7 @@ bool areInterruptsEnabled()
     return miosix_private::checkAreInterruptsEnabled();
 }
 
+#ifdef BOARD_efm32gg332f1024_wandstem
 void deepSleepLock()
 {
     atomicAdd(&deepSleepCounter,1);
@@ -199,7 +203,7 @@ void deepSleepUnlock()
 { 
     atomicAdd(&deepSleepCounter,-1);
 }
-
+#endif
 void startKernel()
 {
     #ifdef USE_CSTIMER
-- 
GitLab