This post has been edited 1 times, last edit by "suppgrg" (Dec 21st 2007, 9:08am)
|
|
C/C++ Source code |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 |
/********************************************************************* * SEGGER MICROCONTROLLER SYSTEME GmbH * * Solutions for real time microcontroller applications * ********************************************************************** * * * (c) 2006 -2007 SEGGER Microcontroller Systeme GmbH * * * * Internet: www.segger.com Support: support@segger.com * * * ********************************************************************** ---------------------------------------------------------------------- File : JLINKDCC_Process.c Purpose : Data handler for ARM J-Link type communication via DCC Notes : (1) How to use In order to use the DCC communication to read / write memory, the following needs to be done: * Add this file to the project / make-file * Make sure this data handler is called regularly * Add the JLINKDCC data abort handler (optional) For details, refer to the documentation or see file JLINKDCC_HandleDataAbort.s79. (2) Compatibility The J-Link ARM DCC handler is compatible to the DCC communication protocol used by IAR in the embedded workbench for ARM and allows using the live data window in C-Spy ---------------------------END-OF-HEADER------------------------------ */ #include "JLINKDCC.h" extern unsigned long CP14_ReadDCCStat(void); extern unsigned long CP14_ReadDCC(void); extern void CP14_WriteDCC(unsigned long Data); /********************************************************************* * * Defines, configurable * ********************************************************************** */ #define SUPPORT_READ_U8 1 // Support byte reads if 1. 0 to disable. #define SUPPORT_READ_U16 1 // Support half word reads if 1. 0 to disable. #define SUPPORT_READ_U32 1 // Support word reads if 1. 0 to disable. #define SUPPORT_WRITE_U8 1 // Support byte writes if 1. 0 to disable. #define SUPPORT_WRITE_U16 1 // Support half word writes if 1. 0 to disable. #define SUPPORT_WRITE_U32 1 // Support word writes if 1. 0 to disable. #define SUPPORT_ABORT 1 // Support aborts. /********************************************************************* * * Defines, non- configurable * ********************************************************************** */ #define U8 unsigned char #define U16 unsigned short #define U32 unsigned int #define DCC_OP_READ_U32 0x01000000 #define DCC_OP_READ_U16 0x02000000 #define DCC_OP_READ_U8 0x04000000 #define DCC_OP_GET_CAPS 0x08000000 #define DCC_OP_WRITE_U32 0x10000000 #define DCC_OP_WRITE_U16 0x20000000 #define DCC_OP_WRITE_U8 0x40000000 #define DCC_OP_ODD_ADDR 0x80000000 #define DCC_OP_COMMAND 0x00000001 #define DCC_CAP_READ_U32 0x01 #define DCC_CAP_READ_U16 0x02 #define DCC_CAP_READ_U8 0x04 #define DCC_CAP_ABORT 0x08 #define DCC_CAP_WRITE_U32 0x10 #define DCC_CAP_WRITE_U16 0x20 #define DCC_CAP_WRITE_U8 0x40 #define DCC_SIGNATURE 0x91CA0000 #define DCC_CONFIG ((DCC_CAP_READ_U8 * SUPPORT_READ_U8) \ | (DCC_CAP_READ_U16 * SUPPORT_READ_U16) \ | (DCC_CAP_READ_U32 * SUPPORT_READ_U32) \ | (DCC_CAP_WRITE_U8 * SUPPORT_WRITE_U8) \ | (DCC_CAP_WRITE_U16 * SUPPORT_WRITE_U16) \ | (DCC_CAP_WRITE_U32 * SUPPORT_WRITE_U32) \ | (DCC_CAP_ABORT * SUPPORT_ABORT)) #define SUPPORT_WRITE (SUPPORT_WRITE_U8 | SUPPORT_WRITE_U16 | SUPPORT_WRITE_U32) /********************************************************************* * * Global data * ********************************************************************** */ U8 JLINKDCC_IsInHandler; U8 JLINKDCC_AbortOccurred; /********************************************************************* * * Static data * ********************************************************************** */ static U16 _NumReadItems; static U32 _Command; static U32 _Addr; static char _acBuffer[256]; static int _RdPos; static int _WrPos; #if (SUPPORT_WRITE) static U32 _Data; #endif /********************************************************************* * * Public code * ********************************************************************** */ /********************************************************************* * * DCC_Process * * Function description * This function should be called more or less regularily to allow * memory reads while the application progam is running. * The more often it is called, the higher the memory read speed. */ void DCC_Process(void) { U32 Data; // // Avoid problems if this code is called from multiple threads or interrupts // if (JLINKDCC_IsInHandler) { return; } JLINKDCC_IsInHandler = 1; // // Perform communication for memory read / write as far as configured // if (CP14_ReadDCCStat() & 1) { Data = CP14_ReadDCC(); if (Data & DCC_OP_COMMAND) { _Command = Data; #if (DCC_CONFIG & (DCC_CAP_READ_U8 | DCC_CAP_WRITE_U8)) if (_Command & DCC_OP_ODD_ADDR) { _Addr |= 1; } #endif if (_Command & (DCC_OP_READ_U32 | DCC_OP_READ_U16 | DCC_OP_READ_U8 | DCC_OP_GET_CAPS)) { _NumReadItems = (_Command >> 2) & 0xffff; } else { #if (DCC_CONFIG & DCC_CAP_WRITE_U32) if (_Command & DCC_OP_WRITE_U32) { _Data |= (_Command << 14) & 0xffff0000; } else #endif #if (SUPPORT_WRITE) { _Data = (_Command >> 2) & 0xffff; } #endif #if (DCC_CONFIG & DCC_CAP_WRITE_U8) if (_Command & DCC_OP_WRITE_U8) { *(U8*)_Addr = _Data; _Addr += 1; } #endif #if (DCC_CONFIG & DCC_CAP_WRITE_U16) if (_Command & DCC_OP_WRITE_U16) { *(U16*)_Addr = _Data; _Addr += 2; } #endif #if (DCC_CONFIG & DCC_CAP_WRITE_U32) if (_Command & DCC_OP_WRITE_U32) { *(U32*)_Addr =_Data; _Addr += 4; } #endif } goto Done; } _Addr = Data; } if (_NumReadItems) { if ((CP14_ReadDCCStat() & 2) == 0) { Data = (DCC_CONFIG | DCC_SIGNATURE); #if (DCC_CONFIG & DCC_CAP_ABORT) Data |= (JLINKDCC_AbortOccurred << 8); if (_Command & DCC_OP_GET_CAPS) { JLINKDCC_AbortOccurred = 0; } #endif #if (DCC_CONFIG & DCC_CAP_READ_U8) if (_Command & DCC_OP_READ_U8) { Data = *(U8*)_Addr; _Addr += 1; } #endif #if (DCC_CONFIG & DCC_CAP_READ_U16) if (_Command & DCC_OP_READ_U16) { Data = *(U16*)_Addr; _Addr += 2; } #endif #if (DCC_CONFIG & DCC_CAP_READ_U32) if (_Command & DCC_OP_READ_U32) { Data = *(U32*)_Addr; _Addr += 4; } #endif CP14_WriteDCC(Data); _NumReadItems--; } } Done: // // Handle terminal out. Up to 3 bytes in one 32-bit unit // if ((CP14_ReadDCCStat() & 2) == 0) { int NumBytes; NumBytes = _WrPos - _RdPos; if (NumBytes < 0) { NumBytes += sizeof(_acBuffer); } if (NumBytes) { int i; if (NumBytes > 3) { NumBytes = 3; } Data = 0; for (i = 0; i < NumBytes; i++) { Data |= _acBuffer[_RdPos] << (8*i); _RdPos++; if (_RdPos == sizeof(_acBuffer)) { _RdPos = 0; } } Data |= (NumBytes - 1) << 24; CP14_WriteDCC(Data); } } JLINKDCC_IsInHandler = 0; } /********************************************************************* * * JLINKDCC_SendChar * * Function description */ void JLINKDCC_SendChar(char c) { int Pos; Pos = _WrPos + 1; if (Pos == sizeof(_acBuffer)) { Pos = 0; } if (Pos == _RdPos) { return; } _acBuffer[_WrPos] = c; _WrPos = Pos; } /********************************************************************* * * JLINKDCC_SendString * * Function description */ void JLINKDCC_SendString(const char * s) { char c; while (1) { c = *s++; if (c == 0) { break; } JLINKDCC_SendChar(c); } } /*************************** end of file ****************************/ |
|
|
Source code |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
/**********************************************************
* SEGGER MICROCONTROLLER SYSTEME GmbH
* Solutions for real time microcontroller applications
***********************************************************
*
* File : JLINKDCC_Process_ASM.s
* Purpose : Routines for setting and writing co-processor register CP14
(DCC-communication) (GNU ARM tool suite)
--------- END-OF-HEADER ---------------------------------
*/
/*********************************************************************
*
* GNU ARM
*
*/
.text
.global CP14_ReadDCCStat
.global CP14_ReadDCC
.global CP14_WriteDCC
.arm
.section .text, "ax"
/*********************************************************************
*
* Public code
*
**********************************************************************
*/
/*********************************************************************
*
* CP14_ReadDCCStat
*/
CP14_ReadDCCStat:
mrc P14,0,R0,C0,C0,0
bx lr
/*********************************************************************
*
* CP14_ReadDCC
*/
CP14_ReadDCC:
mrc P14,0,R0,C1,C0,0
bx lr
/*********************************************************************
*
* CP14_WriteDCC
*/
CP14_WriteDCC:
mcr P14,0,R0,C1,C0,0
bx lr
.end
/**************************** End of file ***************************/
|
Beginner
Date of registration: Jan 7th 2008
Location: Trieste
Occupation: Senior Embedded Software Engineer