?? rt_agent.c
字號:
/******************************************************************************/
/* RT_Agent.C: Real-Time Agent V1.0 */
/******************************************************************************/
/* */
/******************************************************************************/
/* This file is part of the uVision/ARM development tools. */
/* Copyright (c) 2006 Keil - An ARM Company. All rights reserved. */
/* This software may only be used under the terms of a valid, current, */
/* end user licence from KEIL for a compatible version of KEIL software */
/* development tools. Nothing else gives you the right to use this software. */
/******************************************************************************/
#pragma arm
// Real-Time Agent Version
#define RTA_VERSION 1
// <<< Use Configuration Wizard in Context Menu >>>
// <e0>Real-Time Agent
// <i>Enable Real-Time Agent to obtain run-time debug information
#define RTA_ENABLED 1
#define RTA_HW_LPC21xx 1
#define RTA_HW_LPC23xx 2
#define RTA_HW_STR91x 3
#define RTA_HW_AT91SAM7Sx 4
#define RTA_HW_CUSTOM 100
// <o0>Hardware Type <i>Select the target MCU you are using
// <1=> NXP (Philips) LPC21xx
// <2=> NXP (Philips) LPC23xx
// <3=> STMicroelectronics STR91x
// <4=> Atmel AT91SAM7Sx
// <100=> Custom
// (for custom hardware you need to set macros in the hardware section)
//
#define RTA_HW_TYPE 2
// <o0>Output Buffer Size (bytes) <i>A slower JTAG and/or greater amount of data requires a larger buffer
// <256=>256
// <512=>512
// <1024=>1024
#define RTA_OUT_SIZE_BYTES 256
#define RTA_OUT_SIZE (RTA_OUT_SIZE_BYTES / 4)
// <o> Invalid Memory Pattern <0x0-0xFFFFFFFF>
// <i> This pattern is shown at inaccesible locations in the memory window at run-time
#define RTA_NO_MEM_FLAG 0xCCCCCCCC
// <e0>Enable Terminal Emulation (for RTA_Term commands)
// <o1>Input Buffer Size (bytes) <i>A faster JTAG and/or greater amount of data requires a larger buffer
// <2=>2
// <4=>4
// <8=>8
// <16=>16
// <o2.0>Echo Characters Automatically<i>Echoes back characters typed in the serial window
// <o3.0>Block on Write<i>Waits for serial buffer to have available space to send data
// </e>
#define RTA_TERM_SUPPORT 1
/* Terminal Emulator input buffer size (must be a power of 2)
This should be modified based on the amount of
data being sent, and the speed of the JTAG. A faster
JTAG and/or greater amount of data would require a
larger buffer size. */
#define RTA_TERM_IN_SIZE 16
/* Echo characters back to the serial window automatically */
#define RTA_TERM_ECHO 0
/* Blocking writes - write blocks when output buffer full*/
#define RTA_TERM_W_BLOCKING 1
// </e>
// <<< end of configuration section >>>
/*==============================================================================
DO NOT EDIT BELOW HERE (unless using custom hardware)
==============================================================================*/
/*==============================================================================
RTA Hardware Specific Section
==============================================================================*/
#if (RTA_HW_TYPE == RTA_HW_LPC21xx)
#include <LPC21xx.H> /* LPC21xx definitions */
#define RTA_EXPORT_IRQS 0
#define TX_IRQ_INIT() VICVectAddr13 = (unsigned long)RTA_tx_word; \
VICVectCntl13 = 0x20 | 3;
#define TX_IRQ_ACK() VICVectAddr = 0;
#define TX_IRQ_ENABLE() VICIntEnable = 0x00000008;
#define TX_IRQ_DISABLE() VICIntEnClr = 0x00000008;
#define RX_IRQ_INIT() VICVectAddr14 = (unsigned long)RTA_rx_word; \
VICVectCntl14 = 0x20 | 2;
#define RX_IRQ_ACK() VICVectAddr = 0;
#define RX_IRQ_ENABLE() VICIntEnable = 0x00000004;
#define RX_IRQ_DISABLE() VICIntEnClr = 0x00000004;
#define DEF_IRQ_INIT() VICDefVectAddr= (unsigned long)RTA_def_irq;
#define DEF_IRQ_ACK() VICVectAddr = 0;
#define TX_WORD() __asm { MCR p14, 0, tx_word, c1, c0 }
#define RX_WORD() __asm { MRC p14, 0, rx_word, c1, c0 }
#elif (RTA_HW_TYPE == RTA_HW_LPC23xx)
#include <LPC23xx.H> /* LPC23xx definitions */
#pragma diag_suppress 177
#define RTA_EXPORT_IRQS 0
#define TX_IRQ_INIT() VICVectAddr3 = (unsigned long)RTA_tx_word; \
VICVectCntl3 = 0x0f;
#define TX_IRQ_ACK() VICVectAddr = 0;
#define TX_IRQ_ENABLE() VICIntEnable = 0x00000008;
#define TX_IRQ_DISABLE() VICIntEnClr = 0x00000008;
#define RX_IRQ_INIT() VICVectAddr2 = (unsigned long)RTA_rx_word; \
VICVectCntl2 = 0x0f;
#define RX_IRQ_ACK() VICVectAddr = 0;
#define RX_IRQ_ENABLE() VICIntEnable = 0x00000004;
#define RX_IRQ_DISABLE() VICIntEnClr = 0x00000004;
#define DEF_IRQ_INIT()
#define DEF_IRQ_ACK()
#define TX_WORD() __asm { MCR p14, 0, tx_word, c1, c0 }
#define RX_WORD() __asm { MRC p14, 0, rx_word, c1, c0 }
#elif (RTA_HW_TYPE == RTA_HW_STR91x)
#include <91x_lib.h> /* STR91x definitions */
#define RTA_EXPORT_IRQS 0
#define TX_IRQ_INIT() VIC0->VAiR[3] = (unsigned int)RTA_tx_word; \
VIC0->INTSR &= ~(0x01 << (ARMTX_ITLine)); \
VIC0->VCiR[3] = 0x20 | (ARMTX_ITLine);
#define TX_IRQ_ACK() VIC0->VAR = 0; \
VIC1->VAR = 0;
#define TX_IRQ_ENABLE() VIC0->INTER |= (0x01 << (ARMTX_ITLine));
#define TX_IRQ_DISABLE() VIC0->INTECR |= (0x01 << (ARMTX_ITLine));
#define RX_IRQ_INIT() VIC0->VAiR[2] = (unsigned int)RTA_rx_word; \
VIC0->INTSR &= ~(0x01 << (ARMRX_ITLine)); \
VIC0->VCiR[2] = 0x20 | (ARMRX_ITLine);
#define RX_IRQ_ACK() VIC0->VAR = 0; \
VIC1->VAR = 0;
#define RX_IRQ_ENABLE() VIC0->INTER |= (0x01 << (ARMRX_ITLine));
#define RX_IRQ_DISABLE() VIC0->INTECR |= (0x01 << (ARMRX_ITLine));
#define DEF_IRQ_INIT() VIC0->DVAR = (unsigned long)RTA_def_irq;
#define DEF_IRQ_ACK() VIC0->VAR = 0; \
VIC1->VAR = 0;
#define TX_WORD() __asm { MCR p14, 0, tx_word, c1, c0 }
#define RX_WORD() __asm { MRC p14, 0, rx_word, c1, c0 }
#elif (RTA_HW_TYPE == RTA_HW_AT91SAM7Sx)
#include <AT91SAM7S64.H> /* AT91SAM7Sx definitions */
#define RTA_EXPORT_IRQS 1
#define TX_IRQ_INIT() // In user code
#define TX_IRQ_ACK() // In user code
#define TX_IRQ_ENABLE() *AT91C_DBGU_IER = AT91C_US_COMM_TX;
#define TX_IRQ_DISABLE() *AT91C_DBGU_IDR = AT91C_US_COMM_TX;
#define RX_IRQ_INIT() // In user code
#define RX_IRQ_ACK() // In user code
#define RX_IRQ_ENABLE() *AT91C_DBGU_IER = AT91C_US_COMM_RX;
#define RX_IRQ_DISABLE() *AT91C_DBGU_IDR = AT91C_US_COMM_RX;
#define DEF_IRQ_INIT() *AT91C_AIC_SPU = (unsigned long) RTA_def_irq;
#define DEF_IRQ_ACK() *AT91C_AIC_EOICR = 0;
#define TX_WORD() __asm { MCR p14, 0, tx_word, c1, c0 }
#define RX_WORD() __asm { MRC p14, 0, rx_word, c1, c0 }
#elif (RTA_HW_TYPE == RTA_HW_CUSTOM) /* Custom hardare */
#define RTA_EXPORT_IRQS 0
#define TX_IRQ_INIT()
#define TX_IRQ_ACK()
#define TX_IRQ_ENABLE()
#define TX_IRQ_DISABLE()
#define RX_IRQ_INIT()
#define RX_IRQ_ACK()
#define RX_IRQ_ENABLE()
#define RX_IRQ_DISABLE()
#define TX_WORD() __asm { MCR p14, 0, tx_word, c1, c0 }
#define RX_WORD() __asm { MRC p14, 0, rx_word, c1, c0 }
#endif /* RTA_HW_TYPE */
/*==============================================================================
Real-Time Agent Includes
==============================================================================*/
#include "RT_Agent.H"
#if (RTA_TERM_SUPPORT)
#include <stdio.h>
#endif
/*==============================================================================
Real-Time Agent Definitions
==============================================================================*/
// Protocol Constants
#define RTA_TX_MAGIC_NO 0xFA
#define RTA_INITIAL_SEQ_NO 0xCE
#define RTA_SYNC_WORD 0x00FACE00
#define RTA_SYNC_MSG_SIZE 2
#define DVA_REQ_RSP_BIT 0x08
#define RTA_MAX_DATA_LEN 120
#define RTA_MAX_MSG_LEN (RTA_MAX_DATA_LEN + 8) // Message = Header + Data + Checksum = 128 (32 words)
// Buffer masks
#define RTA_OUT_MASK (RTA_OUT_SIZE-1ul)
#define RTA_TERM_IN_MASK (RTA_TERM_IN_SIZE-1ul)
// Functional macros
#define RTA_RESET() {unsigned int iZero = 0; RTA_Msg(RTA_CMD_UNKNOWN, &iZero, RTA_SHORT_MSG); } // Reset RTA communications
#define RTA_SYNC() RTA_Msg(RTA_CMD_SYNC, (unsigned int *)&sync_msg_data, RTA_SYNC_MSG_SIZE); // Sync RTA communications
// RTA Internal (private) command definitions
typedef enum __RTA_INTERNAL_COMMANDS
{
RTA_CMD_SYNC = 0x00,
RTA_CMD_ERROR = 0x01,
RTA_CMD_TERM_DATA = 0x02,
RTA_CMD_SET_ADDRESS = 0x03,
RTA_CMD_MEM_WRITE_8 = 0x04,
RTA_CMD_MEM_WRITE_16 = 0x05,
RTA_CMD_MEM_WRITE_32 = 0x06,
RTA_CMD_GET_VERSION = 0x09,
RTA_CMD_MEM_READ_8 = 0x0A,
RTA_CMD_MEM_READ_16 = 0x0B,
RTA_CMD_MEM_READ_32 = 0x0C,
RTA_CMD_UNKNOWN = 0x0F /* Speical Unknown command definition for reset */
} RTA_INTERNAL_COMMANDS;
// RTA RTX Kernel command definitions
typedef enum __RTA_KERNEL_COMMANDS
{
RTA_CMD_RTX_TASK_SWITCH = 0x10,
RTA_CMD_RTX_MON_START = 0x11,
RTA_CMD_RTX_MON_STOP = 0x12
} RTA_KERNEL_COMMANDS;
// RTA message formats
typedef enum __MSG_FORMAT {
MSG_FORMAT_SHORT = 0,
MSG_FORMAT_LONG
} MSG_FORMAT;
// RTA state machine states
typedef enum __RTA_STATES
{
RTA_STATE_COMMAND = 0,
RTA_STATE_ADDRESS,
RTA_STATE_MEM_WRITE_8,
RTA_STATE_MEM_WRITE_16,
RTA_STATE_MEM_WRITE_32,
RTA_STATE_COUNT // Always leave at end
} RTA_STATES;
// RTA message header split
typedef struct __msg_header_t {
unsigned int length : 8; // 0x000000XX
unsigned int seq_no : 8; // 0x0000XX00
unsigned int fixed : 8; // 0x00XX0000
unsigned int type : 8; // 0xXX000000
} msg_header_t;
// RTA message header union
typedef union __msg_header_u {
msg_header_t split;
unsigned int raw;
} msg_header_u;
// RTA message structure
typedef struct __RTA_msg_t {
msg_header_u header;
const unsigned int* data;
unsigned int checksum;
} RTA_msg_t;
// RTA RX state machine function pointers typedef
typedef void (*state_fp)(unsigned int rx_word);
// RTA output buffer
typedef struct __RTA_out_t {
unsigned int data[RTA_OUT_SIZE];
unsigned int wr_idx;
unsigned int rd_idx;
} RTA_out_t;
// RTA Terminal Emulator buffer
typedef struct __RTA_term_in_t {
unsigned char data[RTA_TERM_IN_SIZE];
unsigned char wr_idx;
unsigned char rd_idx;
} RTA_term_in_t;
// RTA structure
typedef struct __RTA_t {
unsigned int state; // RTA state machine state
unsigned char tx_seq_no; // Transmit sequence number
unsigned char rtx_mon; // RTX monitoring enabled
unsigned int rw_addr; // Read/Write address
unsigned int w_end_addr; // Write end address
RTA_out_t out; // Output buffer
} RTA_t;
/*==============================================================================
Real-Time Agent Exported Variables
==============================================================================*/
// File pointers for the RTA terminal emulation (RTA_printf, etc)
void * fpRTADbgIn = 0;
void * fpRTADbgOut = 0;
#if RTA_ENABLED
/*==============================================================================
ENABLED CODE SECTION
==============================================================================*/
// RTA variables
static volatile RTA_t rta; // Agent state structure
static int initialised = 0; // Initialised boolean
#if (RTA_TERM_SUPPORT)
static volatile RTA_term_in_t term_in; // Terminal Emulator input buffer
#endif
// Function prototypes
static RTA_STATUS send_msg_raw (RTA_msg_t *msg, MSG_FORMAT format);
#if (RTA_EXPORT_IRQS)
void RTA_rx_word_ext (void);
void RTA_tx_word_ext (void);
#else
static __irq void RTA_rx_word (void);
static __irq void RTA_tx_word (void);
#endif
static __irq void RTA_def_irq (void);
static void main_cmd(unsigned int rx_word);
static void main_addr(unsigned int rx_word);
static void main_mem_rd_32(unsigned int rx_word);
static void main_mem_wr_8(unsigned int rx_word);
static void main_mem_wr_16(unsigned int rx_word);
static void main_mem_wr_32(unsigned int rx_word);
// RTA RX state machine function pointers
static state_fp const state_funcs[RTA_STATE_COUNT] = {
main_cmd,
main_addr,
main_mem_wr_8,
main_mem_wr_16,
main_mem_wr_32
};
static const unsigned int sync_msg_data[RTA_SYNC_MSG_SIZE] = {0x52415365,
0x77656C6C};
/*==============================================================================
RTA External Functions
==============================================================================*/
/*
* Initialise Real-Time Agent
* Parameters: None
* Return Value: RTA_STATUS (0 = OK)
*/
RTA_STATUS RTA_Init (void) {
if (!initialised) {
DEF_IRQ_INIT(); // Set up the default (suprious) interrupt
TX_IRQ_INIT(); // Set up the RTA TX interrupt
RX_IRQ_INIT(); // Set up the RTA RX interrupt
rta.state = RTA_STATE_COMMAND; // Reset the states and buffer pointers
rta.tx_seq_no = RTA_INITIAL_SEQ_NO;
rta.out.rd_idx = rta.out.wr_idx = 0; // Set buffer empty conditions
#if (RTA_TERM_SUPPORT)
term_in.rd_idx = term_in.wr_idx = 0; // Reset terminal buffer
fpRTADbgIn = fopen("RTADBGIN", "r"); // Open RTA dbg in for reading
fpRTADbgOut = fopen("RTADBGOUT", "w"); // Open RTA dbg out for writeing
#endif
RX_IRQ_ENABLE(); // Enable RTA Rx Interrupt
initialised = 1;
}
return (RTA_OK);
}
/*
* Send a message to the host via Real-Time Agent
* Parameters: type: type code of command/message
* data: pointer to message buffer to send
* length: length of data message buffer in words,
* or 0 for a short message
* Return Value: RTA_STATUS (0 = OK)
*/
RTA_STATUS RTA_Msg (unsigned int type, unsigned int *data, unsigned int length) {
RTA_STATUS status = RTA_OK;
MSG_FORMAT format;
RTA_msg_t msg;
if (initialised) {
// Create header
msg.header.split.type = type;
msg.header.split.fixed = RTA_TX_MAGIC_NO;
// Add data
if (length) { // Long Message
//if (data == 0) return (RTA_ERR_PARAM); // Parameter check
// *data may be 0 for a memory read at address 0! - can't check
msg.header.split.length = length;
msg.data = data;
format = MSG_FORMAT_LONG;
}
else { // Short Message
if (data == 0) return (RTA_ERR_PARAM); // Parameter check
msg.header.split.length = *data;
format = MSG_FORMAT_SHORT; // Indicates short message
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -