?? jtagdrv.cpp
字號:
//*-----------------------------------------------------------------------------
//* ATMEL Microcontroller Software Support - ROUSSET -
//*-----------------------------------------------------------------------------
//* The software is delivered "AS IS" without warranty or condition of any
//* kind, either express, implied or statutory. This includes without
//* limitation any warranty or condition with respect to merchantability or
//* fitness for any particular purpose, or against the infringements of
//* intellectual property rights of others.
//*-----------------------------------------------------------------------------
//* File Name : Usartdrv.cpp
//* Object : Usart Driver
//*
//* 1.0 06/06/01 IH : Creation
//*-----------------------------------------------------------------------------
//*----- Files to be included Definition -----*/
#include "stdafx.h"
#include <winbase.h>
#include <stdio.h>
#include "at91jtg.h"
#include "jtagdrv.h"
#include "dfu.h"
// Following definitions define the Debug Comm Control register
#define W_BIT (1 << 1)
#define R_BIT (1 << 0)
//*----------------------------------------------------------------------------
//* Function Name : writeCom
//* Object : Send a buffer through a JTAG port
//* Input Parameters : Address of message, Len
//* Output Parameters : FALSE or TRUE
//* Functions called : ReadFile, displayError,closeCom
//*----------------------------------------------------------------------------
#define MAX_WDOG 10
BOOL Jtag_Write(IN HANDLE hcom, PVOID IN buffer, IN DWORD len)
{
unsigned int ctl = R_BIT;
int wDog = MAX_WDOG;
unsigned int *pInt = (unsigned int *) buffer;
for (DWORD i = 0; i < len; i += 4) {
// Wait for the R bit to be cleared
while (wDog--) {
if (!JtagRunMacro("CTL_COMM", 0, &ctl)) {
SetLastError(ERROR_TX_NOT_COMPLETE);
return FALSE;
}
if ( !(ctl & R_BIT) )
break;
Sleep(100); // Sleep 100 ms
}
// Exit due to watch dog
if (!wDog) {
SetLastError(ERROR_TX_NOT_COMPLETE);
return FALSE;
}
else
wDog = MAX_WDOG;
// Write in the COMM data register
if (!JtagRunMacro("WRITE_COMM", *pInt++, NULL)) {
SetLastError(ERROR_TX_NOT_COMPLETE);
return FALSE;
}
}
return TRUE;
}
//*----------------------------------------------------------------------------
//* Function Name : Jtag_Read
//* Object :
//* Input Parameters :
//* Output Parameters :
//* Functions called :
//*----------------------------------------------------------------------------
BOOL Jtag_Read(IN HANDLE hcom, PVOID buffer, IN DWORD len)
{
unsigned int ctl = W_BIT;
int wDog = 10;
unsigned int *pInt = (unsigned int *) buffer;
for (DWORD i = 0; i < len; i += 4) {
// Wait for the W bit to be set
while (wDog--) {
if (!JtagRunMacro("CTL_COMM", 0, &ctl)) {
SetLastError(ERROR_RX_NOT_COMPLETE);
return FALSE;
}
if (ctl & W_BIT)
break;
Sleep(100); // Sleep 100 ms
}
// Exit due to watch dog
if (!wDog) {
SetLastError(ERROR_RX_NOT_COMPLETE);
return FALSE;
}
// Read in the COMM data register
if (!JtagRunMacro("READ_COMM", 0, pInt++)) {
SetLastError(ERROR_RX_NOT_COMPLETE);
return FALSE;
}
}
return TRUE;
}
//*----------------------------------------------------------------------------
//* Function Name : Usart_Download
//* Object :
//* Input Parameters :
//* Output Parameters :
//* Functions called :
//*----------------------------------------------------------------------------
ULONG Jtag_Download(const char *com ,PVOID IN buffer, IN ULONG bufferSize)
{
ULONG bytesWritten = bufferSize;
CHAR errorMessage[100];
PIPE jtagPipe;
// Open the communication channel and init pipe structure
if (!JtagLoadMacro("arm.lst")) {
sprintf(errorMessage, "Installation is not correct.\nCan not load arm.lst");
MessageBox(NULL, errorMessage, "ERROR", MB_OK);
return 0;
}
jtagPipe.read = Jtag_Read;
jtagPipe.write = Jtag_Write;
// RESET the JTAG macrocell
if (!JtagRunMacro("RESET_TAP", 0, NULL)) {
sprintf(errorMessage, "Can not reset the TAP controller...");
MessageBox(NULL, errorMessage, "ERROR", MB_OK);
return 0;
}
// RESET the JTAG macrocell
if (!JtagRunMacro("SELECT_SC2", 0, NULL)) {
sprintf(errorMessage, "Can not access to the BKRU...");
MessageBox(NULL, errorMessage, "ERROR", MB_OK);
return 0;
}
// Download the buffer
if (!DownloadUploadFirmware(&jtagPipe, buffer, bufferSize, FALSE)) {
sprintf(errorMessage, "Error downloading firmware: %X", GetLastError());
MessageBox(NULL, errorMessage, "ERROR", MB_OK);
bytesWritten = 0;
}
return bufferSize;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -