00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083 #include "board.h"
00084
00085 #include <stdbool.h>
00086 #include <stdio.h>
00087 #include <stdlib.h>
00088 #include <string.h>
00089 #include "..\..\..\..\utils\utility.h"
00090
00091
00092
00093 extern void TCM_StackInit(void);
00094
00095
00096
00097
00098 #define BUFF_SIZE 0x1000
00099
00100
00101
00102
00103
00104 #if defined ( __ICCARM__ )
00105 #pragma location = ".data_TCM"
00106 #elif defined ( __GNUC__ ) || defined (__CC_ARM)
00107 __attribute__((__section__(".data_TCM")))
00108 #endif
00109 uint8_t TCM_DestBuff[3*BUFF_SIZE];
00110
00111 #if defined ( __ICCARM__ )
00112 #pragma location = ".data_TCM"
00113 #elif defined ( __GNUC__ ) || defined (__CC_ARM)
00114 __attribute__((__section__(".data_TCM")))
00115 #endif
00116 uint8_t TCM_SrcBuff[BUFF_SIZE];
00117
00118 const char *pBuffer = "The ARM architecture is defined in a hierarchical manner,\
00119 where the features are described in Chapter A2\
00120 Application Level Programmers?Model at the application level,\
00121 with underlying system support. What features are available and how they are \
00122 supported is defined in the architecture profiles, making the system \
00123 level support profile specific. Deprecated features can be found in an \
00124 appendix to this manual. See page. As stated in Privileged execution on page \
00125 A2-13, programs can execute in a privileged or unprivileged manner. System \
00126 level support requires privileged access, allowing it the access permissions \
00127 to configure and control the resources. This is typically supported by an \
00128 operating system, which provides system services to the applications, either \
00129 transparently, or through application initiated service calls. The operating \
00130 system is also responsible for servicing interrupts and other system events, \
00131 making exceptions a key component of the system level programmers?model.";
00132
00133 uint8_t DestBuff[3*BUFF_SIZE], SrcBuff[BUFF_SIZE];
00134
00135 static uint32_t CycleCounter;
00136
00137
00138
00139
00140
00141 #if defined ( __ICCARM__ )
00142 #pragma default_function_attributes = @ ".code_TCM"
00143 #elif defined ( __GNUC__ ) || defined (__CC_ARM)
00144 __attribute__((__section__(".code_TCM")))
00145 #endif
00146 static uint32_t TCM_memcpy(uint8_t *pDest, uint8_t *pSrc, uint16_t len)
00147 {
00148
00149 memset(TCM_SrcBuff, 0, len);
00150 __DSB();
00151 __ISB();
00152 memset(TCM_DestBuff, 0, len);
00153 __DSB();
00154 __ISB();
00155
00156
00157 memcpy(pSrc, pBuffer,len);
00158 __DSB();
00159 __ISB();
00160
00161
00162 RESET_CYCLE_COUNTER();
00163
00164 {
00165 uint32_t i;
00166 uint8_t * pTmpD = pDest;
00167 uint8_t * pTmpS;
00168
00169 for (i = 0, pTmpS = pSrc; i < len; i++)
00170 *pTmpD++ = *pTmpS++;
00171 for (i = 0, pTmpS = pSrc; i < len; i++)
00172 *pTmpD++ = *pTmpS++;
00173 for (i = 0, pTmpS = pSrc; i < len; i++)
00174 *pTmpD++ = *pTmpS++;
00175 }
00176 GET_CYCLE_COUNTER(CycleCounter);
00177 return CycleCounter;
00178 }
00179
00180
00181 static uint32_t Normal_memcpy(uint8_t *pDest, uint8_t *pSrc, uint16_t len)
00182 {
00183 memset(SrcBuff, 0, len);
00184 __DSB();
00185 __ISB();
00186 memset(DestBuff, 0, len);
00187 __DSB();
00188 __ISB();
00189 memcpy(SrcBuff, pBuffer,len);
00190 __DSB();
00191 __ISB();
00192
00193
00194 RESET_CYCLE_COUNTER();
00195
00196 {
00197 uint32_t i;
00198 uint8_t * pTmpD = pDest;
00199 uint8_t * pTmpS;
00200 for (i = 0, pTmpS = pSrc; i < len; i++)
00201 *pTmpD++ = *pTmpS++;
00202 for (i = 0, pTmpS = pSrc; i < len; i++)
00203 *pTmpD++ = *pTmpS++;
00204 for (i = 0, pTmpS = pSrc; i < len; i++)
00205 *pTmpD++ = *pTmpS++;
00206 }
00207 GET_CYCLE_COUNTER(CycleCounter);
00208 return CycleCounter;
00209 }
00210
00211 static uint32_t Recursive(uint32_t n)
00212 {
00213 volatile uint32_t tmp = n;
00214
00215 if (0 == tmp)
00216 return 0;
00217 else
00218 return n + Recursive(tmp - 1);
00219 }
00220
00221 static uint32_t Stack_Test(uint32_t n)
00222 {
00223 uint32_t sum;
00224 RESET_CYCLE_COUNTER();
00225 sum = Recursive(n);
00226 GET_CYCLE_COUNTER(CycleCounter);
00227 printf("\r\n Sum of 1 to %u is %u, ", (unsigned)n, (unsigned)sum);
00228 return CycleCounter;
00229 }
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239 extern int main( void )
00240 {
00241 uint32_t CycleCounterOffset = 0;
00242 uint32_t Cycles=0;
00243
00244
00245 WDT_Disable(WDT);
00246
00247
00248 printf("\n\r-- TCM memory Example %s --\n\r", SOFTPACK_VERSION);
00249 printf("-- %s\n\r", BOARD_NAME);
00250 printf("-- Compiled: %s %s With %s--\n\r", __DATE__, __TIME__, COMPILER_NAME);
00251
00252 RESET_CYCLE_COUNTER();
00253 __NOP();
00254 __NOP();
00255 __NOP();
00256 __NOP();
00257 __NOP();
00258 __NOP();
00259 __NOP();
00260 __NOP();
00261 __NOP();
00262 __NOP();
00263
00264 CycleCounterOffset = DWT->CYCCNT;
00265 __DMB();
00266 CycleCounterOffset -=10;
00267
00268 printf("\n\r");
00269 TRACE_INFO(" ------ ICache & DCache Disabled ------\n\r");
00270 TRACE_INFO(" ------ Stack In SRAM ------\n\r");
00271
00272
00273 Cycles = Stack_Test(100);
00274 printf("Inst Cycles passed is %u\r\n", (unsigned)(CycleCounter - CycleCounterOffset));
00275
00276 Cycles = Stack_Test(100);
00277 printf("Inst Cycles passed is %u\r\n", (unsigned)(CycleCounter - CycleCounterOffset));
00278
00279 printf("\n\r");
00280 TRACE_INFO(" ------ Stack In DTCM ------\n\r");
00281 TCM_StackInit();
00282
00283 Cycles = Stack_Test(100);
00284 printf("Inst Cycles passed is %u\r\n", (unsigned)(CycleCounter - CycleCounterOffset));
00285
00286 Cycles = Stack_Test(100);
00287 printf("Inst Cycles passed is %u\r\n", (unsigned)(CycleCounter - CycleCounterOffset));
00288
00289
00290 Cycles = Normal_memcpy(DestBuff, SrcBuff, BUFF_SIZE);
00291 printf("\n\r Number of Inst Cycles passed without TCM is %u \n\r",
00292 (unsigned)(Cycles - CycleCounterOffset));
00293
00294 Cycles = TCM_memcpy(TCM_DestBuff, TCM_SrcBuff, BUFF_SIZE);
00295 printf("\n\r Number of Inst Cycles passed with TCM is %u \n\r",
00296 (unsigned)(Cycles - CycleCounterOffset));
00297
00298 SCB_EnableICache();
00299 SCB_EnableDCache();
00300
00301 printf("\n\r");
00302 TRACE_INFO(" ------ ICache & DCache Enabled ------\n\r");
00303
00304 Cycles = Normal_memcpy(DestBuff, SrcBuff, BUFF_SIZE);
00305 printf("\n\r Number of Inst Cycles passed without TCM is %u \n\r",
00306 (unsigned)(Cycles - CycleCounterOffset));
00307
00308 Cycles = TCM_memcpy(TCM_DestBuff, TCM_SrcBuff, BUFF_SIZE);
00309 printf("\n\r Number of Inst Cycles passed with TCM is %u \n\r",
00310 (unsigned)(Cycles - CycleCounterOffset));
00311
00312 while (1);
00313 }