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 for(i=0, pTmpS = pSrc; i<len; i++) {
00169 *pTmpD++ = *pTmpS++;
00170 }
00171 for(i=0, pTmpS = pSrc; i<len; i++) {
00172 *pTmpD++ = *pTmpS++;
00173 }
00174 for(i=0, pTmpS = pSrc; i<len; i++) {
00175 *pTmpD++ = *pTmpS++;
00176 }
00177 }
00178 GET_CYCLE_COUNTER(CycleCounter);
00179 return CycleCounter ;
00180 }
00181
00182
00183 static uint32_t Normal_memcpy(uint8_t *pDest, uint8_t *pSrc, uint16_t len)
00184 {
00185 memset(SrcBuff, 0, len);
00186 __DSB();
00187 __ISB();
00188 memset(DestBuff, 0, len);
00189 __DSB();
00190 __ISB();
00191 memcpy(SrcBuff, pBuffer,len);
00192 __DSB();
00193 __ISB();
00194
00195
00196 RESET_CYCLE_COUNTER();
00197
00198 {
00199 uint32_t i;
00200 uint8_t * pTmpD = pDest;
00201 uint8_t * pTmpS;
00202 for(i=0, pTmpS = pSrc; i<len; i++) {
00203 *pTmpD++ = *pTmpS++;
00204 }
00205 for(i=0, pTmpS = pSrc; i<len; i++) {
00206 *pTmpD++ = *pTmpS++;
00207 }
00208 for(i=0, pTmpS = pSrc; i<len; i++) {
00209 *pTmpD++ = *pTmpS++;
00210 }
00211 }
00212 GET_CYCLE_COUNTER(CycleCounter);
00213 return CycleCounter ;
00214 }
00215
00216 static uint32_t Recursive(uint32_t n)
00217 {
00218 volatile uint32_t tmp = n;
00219 if(0 == tmp)
00220 return 0;
00221 else
00222 return n + Recursive(tmp - 1);
00223 }
00224
00225 static uint32_t Stack_Test(uint32_t n)
00226 {
00227 uint32_t sum;
00228 RESET_CYCLE_COUNTER();
00229 sum = Recursive(n);
00230 GET_CYCLE_COUNTER(CycleCounter);
00231 printf("\r\n Sum of 1 to %u is %u, ", (unsigned)n, (unsigned)sum);
00232 return CycleCounter;
00233 }
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243 extern int main( void )
00244 {
00245 uint32_t CycleCounterOffset = 0;
00246 uint32_t Cycles=0;
00247
00248
00249 WDT_Disable( WDT ) ;
00250
00251
00252 printf( "\n\r-- TCM memory Example %s --\n\r", SOFTPACK_VERSION ) ;
00253 printf( "-- %s\n\r", BOARD_NAME ) ;
00254 printf( "-- Compiled: %s %s With %s--\n\r", __DATE__, __TIME__ , COMPILER_NAME) ;
00255
00256 RESET_CYCLE_COUNTER();
00257 __NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();__NOP();
00258 CycleCounterOffset = DWT->CYCCNT;
00259 __DMB();
00260 CycleCounterOffset -=10;
00261
00262 printf("\n\r");
00263 TRACE_INFO(" ------ ICache & DCache Disabled ------\n\r");
00264 TRACE_INFO(" ------ Stack In SRAM ------\n\r");
00265
00266
00267 Cycles = Stack_Test(100);
00268 printf("Inst Cycles passed is %u\r\n", (unsigned)(CycleCounter - CycleCounterOffset));
00269
00270 Cycles = Stack_Test(100);
00271 printf("Inst Cycles passed is %u\r\n", (unsigned)(CycleCounter - CycleCounterOffset));
00272
00273 printf("\n\r");
00274 TRACE_INFO(" ------ Stack In DTCM ------\n\r");
00275 TCM_StackInit();
00276
00277 Cycles = Stack_Test(100);
00278 printf("Inst Cycles passed is %u\r\n", (unsigned)(CycleCounter - CycleCounterOffset));
00279
00280 Cycles = Stack_Test(100);
00281 printf("Inst Cycles passed is %u\r\n", (unsigned)(CycleCounter - CycleCounterOffset));
00282
00283
00284 Cycles = Normal_memcpy(DestBuff, SrcBuff, BUFF_SIZE);
00285 printf("\n\r Number of Inst Cycles passed without TCM is %u \n\r",
00286 (unsigned)(Cycles - CycleCounterOffset) );
00287
00288 Cycles = TCM_memcpy(TCM_DestBuff, TCM_SrcBuff, BUFF_SIZE);
00289 printf("\n\r Number of Inst Cycles passed with TCM is %u \n\r",
00290 (unsigned)(Cycles - CycleCounterOffset) );
00291
00292 SCB_EnableICache();
00293 SCB_EnableDCache();
00294
00295 printf("\n\r");
00296 TRACE_INFO(" ------ ICache & DCache Enabled ------\n\r");
00297
00298 Cycles = Normal_memcpy(DestBuff, SrcBuff, BUFF_SIZE);
00299 printf("\n\r Number of Inst Cycles passed without TCM is %u \n\r",
00300 (unsigned)(Cycles - CycleCounterOffset));
00301
00302 Cycles = TCM_memcpy(TCM_DestBuff, TCM_SrcBuff, BUFF_SIZE);
00303 printf("\n\r Number of Inst Cycles passed with TCM is %u \n\r",
00304 (unsigned)(Cycles - CycleCounterOffset));
00305
00306 while ( 1 );
00307 }