⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 agdi.cpp

📁 KEIL的例程
💻 CPP
📖 第 1 页 / 共 5 页
字号:
  pM = &Menu[0];
  while (pM->nDelim != -1)  {
    if (pM->pDlg && pM->pDlg->hw)  {        // Dialog is visible
      pM->pDlg->Kill (pM->pDlg);            // update contents
    }
    ++pM;
  }
}




//--- Interface functions between AGDI and target follow
//------------------------------------------------------


/*
 *  Read 'len' bytes out of data space into buffer 'pB'
 *  return: 0:=Ok
 */

UL32 read_block (UL32 staddr, UL32 len) {
//---TODO: read from Addr = staddr len bytes
//---if Ok, then return 0, else error-address
  return(0);   // say ok 
}


/*
 *  Write 'len' bytes into Target memory at adress staddr
 *  return: 0:=Ok
 */

UL32 write_block (UL32 staddr, UL32 len) {
//---TODO: write len bytes at Adress = staddr
//---if Ok, then return 0, else error-address
  return(0);   // say ok 
}


/*
 * Initialize your target communication
 * Return 0 if Ok, 1 if failed.
 */

U32 InitTarget (void)  {
//---TODO:
  return (0);            // say 'Ok.'
}


/*
 * Target settings have changed (Baudrate or ComPort for example)
 * Return 0 if Ok, 1 if failed.
 */

U32 ReInitTarget (void)  {
//---TODO: shutdown target
//---      reinit communication with current 'MonConf' values
  return (0);            // say 'Ok.'
}

/*
 * Stop your target communication
 * Free all resources (dynamic memory, ...)
 */

void StopTarget (void)  {
  FreeCache();                 // free allocated cache memory.
//---TODO: add code for cleanup
}

/*
 * Write Register value
 * initregnum :=  number of the Register
 * bytes      :=  size of the reg
 * value      :=  pointer to the value to write
 * Return    0 = Ok
 */

int WriteRegister(unsigned int initregnum,unsigned char bytes,unsigned long *value) {
//---TODO----
  return 0;
}

/*
 * Write PC out to target
 */

void WritePC (UL32 nPC)  {
//---TODO: write PC to target
  REGARM.cur[15] = nPC;                // keep in shadow registers
}

/*
 * Reset your target. Set PC to whatever required value
 */

void ResetTarget (void)  {
//---TODO: add code for target reset

#if 0
  DWORD val;
  int   i;

  REGARM.cur[15] = 0;
  *pCURPC = 0;
  WritePC(0);  // Set IP to 0 if not already done via reset

  REGARM.cpsr = 0x000000D3;
  pBom->Thumb = (REGARM.cpsr & 0x20) ? 1 : 0;
  val = DSWAP32(REGARM.cpsr);
  WriteRegister(DSWAP16(CPSR),4, &val);
  switch (REGARM.cpsr & 0x1F) {
    case 0x1F:
    case 0x10:
      for (i=8;i<15;i++) REGARM.cur[i] = REGARM.usr[i-8];
      break;
    case 0x11:
      for (i=8;i<15;i++) REGARM.cur[i] = REGARM.fiq[i-8];
      REGARM.spsr = REGARM.fiq[7];
      break;
    case 0x12:
      for (i=8;i<13;i++) REGARM.cur[i] = REGARM.usr[i-8];
      REGARM.cur[13] = REGARM.irq[0];
	    REGARM.cur[14] = REGARM.irq[1];
	    REGARM.spsr    = REGARM.irq[2];
      break;
    case 0x13:
      for (i=8;i<13;i++) REGARM.cur[i] = REGARM.usr[i-8];
      REGARM.cur[13] = REGARM.svc[0];
	    REGARM.cur[14] = REGARM.svc[1];
	    REGARM.spsr    = REGARM.svc[2];
	    break;
    case 0x17:
	    for (i=8;i<13;i++) REGARM.cur[i] = REGARM.usr[i-8];
	    REGARM.cur[13] = REGARM.abt[0];
	    REGARM.cur[14] = REGARM.abt[1];
	    REGARM.spsr    = REGARM.abt[2];
	    break;
    case 0x1B:
	    for (i=8;i<13;i++) REGARM.cur[i] = REGARM.usr[i-8];
	    REGARM.cur[13] = REGARM.und[0];
	    REGARM.cur[14] = REGARM.und[1];
	    REGARM.spsr    = REGARM.und[2];
	    break;
  }
#endif  
}


/*
 * Read PC out of target
 */

UL32 ReadPC (void)  {
  UL32   nPC = 0;

//---TODO: read PC out of target

  REGARM.cur[15] = nPC;         // we use shadow PC for now...
  return (nPC);
}


/*
 * Read all registers out of target and fill the REG51 structure
 */

void GetRegs (void)  {
  if (RegUpToDate) return;        // already up to date
  if (iRun) return;               // currently executing, can't access
  curPC = REGARM.cur[15] = ReadPC();
 
//---TODO: fetch regs from target and put them into REGARM
//---if connection is broken for some reason, then set PlayDead:=1 !
}



/*
 * Write all registers to target
 */

void SetRegs (RgARM *pR)  { 
//--- write pR->cur[0] ... pR->cur[14]
  WritePC (pR->cur[15]);
  REGARM = *pR;
//---if connection is broken for some reason, then set PlayDead:=1 !
}


/*
 * Stop execution of user program
 */

U32 StopExec (void)  {
  if (iRun)  {                  // if currently executing
//---TODO: Stop exec
//---if successful, return (1), else (0)
  }
  return (1);                   // 'Stopped'
}

/*
 * Invalidate everything which may be invalid after Go or Step
 *  (Registers, Caches, etc.)
 */

void Invalidate (void)  {
  RegUpToDate = 0;                    // invalidate Registers
  InvalidateMemory();                // invalidate memory
}


/*
 * Execute a single instruction, return 1 if ok, else 0
 */
UL32 Step (void)  {
  return (1);
}



/*
 * Start execution.  Stop when a Bp is reached
 */
void GoCmd (void)  {
}


/*
 * Set/Clear Breakpoint at address pB->Adr
 */

int SetClrBp (int set, AG_BP *pB)  {
  int       nR;

  nR = 1;
  if (set)  {                   // set address break
//---TODO: give target a message about Set-Bp at address 'pB->Adr'
//---      if ok, then return (1), else (0)
//  if (failed)  {
//    MessageBeep (MB_OK);
//    txtout ((char *) szNBP, pB->Adr);
//    nR = 0;
//  }
  }
  else  {                       // clear address break
//---TODO: give target a message about Clear-Bp at address 'pB->Adr'
//---      if ok, then return (1), else (0)
  }
  return (nR);
}




/*
 *----------- AGDI Basic Functions -----------------
 */

static AG_SCOPE   ac;

static DWORD Find_Line (DWORD nAddr)  {
  DWORD       n;
  AG_LINE   *pL;

  pL = ac.pLines;
  for ( n = 0 ; n < ac.nLines ; ++n, ++pL )  {
    if (pL->addr == nAddr)  {
      return (pL->line);
    }
  }
  return (0);                     // no line number found for address 'nAddr'
}


/*
 * Application: get Scope-Info (Function-address range, line-numbers and full-path-src)
 */
static void TestScope (DWORD nAddr)  {
  U32    nE, line;

  ac.AddrIn = nAddr;              // Input-Parameter: Address to get Scope-Info for.
  nE = pCbFunc (AG_CB_GETSCOPEINFO, (void *) &ac);    // send data to uVision
  if (nE == 0)  {                 // Scope-Mapping failed...
    return;
  }
//---Now, ag_scope has the following info:
// 
//  ac.pModule    := Name of Module
//  ac.pFunc      := Name of Function
//  ac.lowPC      := start address of function
//  ac.higPC      := last valid address of function
//  ac.nLines     := number of lines in Module 'pModule'
//  ac.curLine    := nAddr maps to line 'ac.curLine' in File 'ac.szPath[]'
//  ac.pLines     := Array[ac.nLines] of Linenumber/address pairs for module 'ac.pModule' 
//  ac.szPath     := full path name of associated source file

  line = Find_Line (nAddr);
  if (line != 0)  {               // found line
//---TODO:  access file 'ac.szPath', line-number = line and fetch the source-code line.
  }
}



static AG_BLOCK  ab;

static void TestEnumScopes (void)  {
  UL32     nE;
  char    szB[512];

  memset (&ab, 0, sizeof (ab));             // clear -->  ***REQUIRED!!!***
  nE = pCbFunc (AG_CB_ENUMFUNCTIONS, (void *) &ab);    // initialize for enumeration
  if (nE == 0)  {                                      // failed...
    return;
  }
  while (1)  {                              // while more enumerations...
    nE = pCbFunc (AG_CB_ENUMFUNCTIONS, (void *) &ab);    // send data to uVision
    if (nE == 0) break;                     // Enumeration finished.
    sprintf (szB, "AGDI: \\\\%s\\%s\\%s(): lowPC=0x%08X, higPC=0x%08X\n",
                    ab.pApp, ab.pModule, ab.pFunc, ab.lowPC, ab.higPC);
    txtout (szB);                           // write result into command-output-Window.
  }
}





/*
 * Logic-Analyzer Helper Functions
 */
static DWORD SaveAdr;

I32 QueryLaSig (AGDI_LA *pLA)  {
  DWORD     nAdr;
  DWORD    nSize;

  nAdr  = (U32) pLA->nAdr;         // Memory-Address
  nSize = (U32) pLA->nSize;        // Size in Bytes
SaveAdr = nAdr;

//---TODO:
//if (cannot_set tracking-range nAdr...nAdr+nSize-1)  {
//  strcpy (pLA->szError, "Error-Text");   // Reason for 'not supported'
//  return (AGDI_LA_NOTSUPPORTED);
//}


//---OK:
  return (AGDI_LA_OK);             // LA-Signal accepted
}


/*
 * Given LA-Signal has been killed.
 */
U32 KilledLaSig (AGDI_LA *pLA)  {
//---TODO: whatever cleanup is required.
  return (AGDI_LA_OK);
}


/*
 * Send a Data-Record to uVision
 *  uVision will look for the matching LA-Signal based on the write-address
 *  and assign the data record to that La-signal.
 */
U32 SendLaDataRecord (AGDI_LAREC *pLA)  {
  U32    nE;

  nE = pCbFunc (AG_CB_LAREC_DATA, (void *) pLA);  // send data to uVision
  switch (nE)  {
    default:
    case 0:                       // could not find a matching Signal (pLA->nAdr)
      break;
    case AGDI_LA_OK:
      break;
  }
  return (nE);
}


static AGDI_LAREC  la;

static void SineSig (void)  {
  int       i;
  double    volts, frequ, offs, dur, val;

  memset (&la, 0, sizeof (la));
  la.nAdr   = SaveAdr;
  la.tStamp  = 10;
  la.totTime = 10;

  volts =  2.0;         // peak-to-peak voltage
  offs  =  2.5;         // voltage offset
  frequ = 1000;         // frequency
  dur   =  0.2;         // duration in seconds

  for ( i = 0 ; i < (dur * 100000) ; ++i )  {
    val = (float) sin (frequ * (((double) la.totTime) / 33e6) * 2 * 3.14159);
    la.v.f32  = (float) ((val * volts) + offs);
    SendLaDataRecord (&la);                    // send data to uVision
    la.totTime += 10;
    la.tStamp  += 10;
  }
}



/*
 * AGDI-Init Function
 */

U32 _EXPO_ AG_Init (U16 nCode, void *vp)  {
  U32     nE;

  nE = 0;
  switch (nCode & 0xFF00)  {
    case AG_INITFEATURES:     // Initialize & start the target
      PlayDead = 0;           // clear some variables...

//---We don't have special features here, so all variables are cleared.
//---uVision2 will query these features lateron.
//---Note: the 'supp' structure is defined in 'AGDI.H'

      supp.MemAccR  = 0;         // memory-access while running
      supp.RegAccR  = 0;         // register-access while running

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -