em_msc.h
Go to the documentation of this file.00001
00034 #ifndef __EM_MSC_H
00035 #define __EM_MSC_H
00036
00037 #include "em_device.h"
00038 #if defined(MSC_COUNT) && (MSC_COUNT > 0)
00039
00040 #include <stdint.h>
00041 #include <stdbool.h>
00042 #include "em_bitband.h"
00043
00044 #ifdef __cplusplus
00045 extern "C" {
00046 #endif
00047
00048
00053
00059
00060
00061
00062
00073 #define MSC_PROGRAM_TIMEOUT 10000000ul
00074
00075
00076
00077
00078
00080 typedef enum
00081 {
00082 mscReturnOk = 0,
00083 mscReturnInvalidAddr = -1,
00084 mscReturnLocked = -2,
00085 mscReturnTimeOut = -3,
00086 mscReturnUnaligned = -4
00087 } msc_Return_TypeDef;
00088
00089
00090 #if defined( _MSC_READCTRL_BUSSTRATEGY_MASK )
00091
00092 typedef enum {
00093 mscBusStrategyCPU = MSC_READCTRL_BUSSTRATEGY_CPU,
00094 mscBusStrategyDMA = MSC_READCTRL_BUSSTRATEGY_DMA,
00095 mscBusStrategyDMAEM1 = MSC_READCTRL_BUSSTRATEGY_DMAEM1,
00096 mscBusStrategyNone = MSC_READCTRL_BUSSTRATEGY_NONE
00097 } mscBusStrategy_Typedef;
00098 #endif
00099
00100
00101
00102
00103
00104 void MSC_Deinit(void);
00105 void MSC_Init(void);
00106
00107
00115 __STATIC_INLINE void MSC_IntClear(uint32_t flags)
00116 {
00117 MSC->IFC = flags;
00118 }
00119
00120
00128 __STATIC_INLINE void MSC_IntDisable(uint32_t flags)
00129 {
00130 MSC->IEN &= ~(flags);
00131 }
00132
00133
00134
00147 __STATIC_INLINE void MSC_IntEnable(uint32_t flags)
00148 {
00149 MSC->IEN |= flags;
00150 }
00151
00152
00153
00164 __STATIC_INLINE uint32_t MSC_IntGet(void)
00165 {
00166 return(MSC->IF);
00167 }
00168
00169
00170
00178 __STATIC_INLINE void MSC_IntSet(uint32_t flags)
00179 {
00180 MSC->IFS = flags;
00181 }
00182
00183
00184 #if defined( MSC_IF_CHOF ) && defined( MSC_IF_CMOF )
00185
00192 __STATIC_INLINE void MSC_StartCacheMeasurement(void)
00193 {
00194
00195 MSC->IFC = MSC_IF_CHOF | MSC_IF_CMOF;
00196
00197
00198 MSC->CMD = MSC_CMD_STARTPC;
00199 }
00200
00201
00202
00249 __STATIC_INLINE int32_t MSC_GetCacheMeasurement(void)
00250 {
00251 int32_t total;
00252
00253 MSC->CMD = MSC_CMD_STOPPC;
00254
00255
00256 if (MSC->IF & (MSC_IF_CHOF | MSC_IF_CMOF))
00257 return -2;
00258
00259
00260
00261
00262 total = MSC->CACHEHITS;
00263 total += MSC->CACHEMISSES;
00264
00265
00266 if (total == 0)
00267 return -1;
00268
00269 return (MSC->CACHEHITS * 100) / total;
00270 }
00271
00272
00273
00277 __STATIC_INLINE void MSC_FlushCache(void)
00278 {
00279 MSC->CMD = MSC_CMD_INVCACHE;
00280 }
00281
00282
00283
00289 __STATIC_INLINE void MSC_EnableCache(bool enable)
00290 {
00291 BITBAND_Peripheral(&(MSC->READCTRL), _MSC_READCTRL_IFCDIS_SHIFT, ~enable);
00292 }
00293
00294
00295 #if defined( MSC_READCTRL_ICCDIS )
00296
00302 __STATIC_INLINE void MSC_EnableCacheIRQs(bool enable)
00303 {
00304 BITBAND_Peripheral(&(MSC->READCTRL), _MSC_READCTRL_ICCDIS_SHIFT, ~enable);
00305 }
00306 #endif
00307
00308
00309
00315 __STATIC_INLINE void MSC_EnableAutoCacheFlush(bool enable)
00316 {
00317 BITBAND_Peripheral(&(MSC->READCTRL), _MSC_READCTRL_AIDIS_SHIFT, ~enable);
00318 }
00319 #endif
00320
00321
00322 #if defined( _MSC_READCTRL_BUSSTRATEGY_MASK )
00323
00329 __STATIC_INLINE void MSC_BusStrategy(mscBusStrategy_Typedef mode)
00330 {
00331 MSC->READCTRL = (MSC->READCTRL & ~(_MSC_READCTRL_BUSSTRATEGY_MASK))|mode;
00332 }
00333 #endif
00334
00335 #ifdef __CC_ARM
00336 msc_Return_TypeDef MSC_WriteWord(uint32_t *address, void const *data, int numBytes);
00337 msc_Return_TypeDef MSC_ErasePage(uint32_t *startAddress);
00338
00339 #if defined( _MSC_MASSLOCK_MASK )
00340 msc_Return_TypeDef MSC_MassErase(void);
00341 #endif
00342 #endif
00343
00344 #ifdef __ICCARM__
00345 __ramfunc msc_Return_TypeDef MSC_WriteWord(uint32_t *address, void const *data, int numBytes);
00346 __ramfunc msc_Return_TypeDef MSC_ErasePage(uint32_t *startAddress);
00347
00348 #if defined( _MSC_MASSLOCK_MASK )
00349 __ramfunc msc_Return_TypeDef MSC_MassErase(void);
00350 #endif
00351 #endif
00352
00353 #ifdef __GNUC__
00354 #ifdef __CROSSWORKS_ARM
00355 msc_Return_TypeDef MSC_WriteWord(uint32_t *address, void const *data, int numBytes) __attribute__ ((section(".fast")));
00356 msc_Return_TypeDef MSC_ErasePage(uint32_t *startAddress) __attribute__ ((section(".fast")));
00357
00358 #if defined( _MSC_MASSLOCK_MASK )
00359 msc_Return_TypeDef MSC_MassErase(void) __attribute__ ((section(".fast")));
00360 #endif
00361
00362 #else
00363 msc_Return_TypeDef MSC_WriteWord(uint32_t *address, void const *data, int numBytes) __attribute__ ((section(".ram")));
00364 msc_Return_TypeDef MSC_ErasePage(uint32_t *startAddress) __attribute__ ((section(".ram")));
00365
00366 #if defined( _MSC_MASSLOCK_MASK )
00367 msc_Return_TypeDef MSC_MassErase(void) __attribute__ ((section(".ram")));
00368 #endif
00369
00370 #endif
00371 #endif
00372
00376 #ifdef __cplusplus
00377 }
00378 #endif
00379
00380 #endif
00381 #endif