外部mcu通过调试接口对CC2530进行编程,基本的功能函数如下:
<p>
//--cc2530 Debug commands---
#define CMD_CHIP_ERASE 0x10
#define CMD_WR_CONFIG 0x18
#define CMD_RD_CONFIG 0x20
#define CMD_READ_STATUS 0x30
#define CMD_RESUME 0x48
#define CMD_DEBUG_INSTR 0x50
#define CMD_BURST_WRITE 0x80
#define CMD_GET_CHIP_ID 0x68
//---------------------------
#define LOBYTE(w) ((unsigned char)(w))
#define HIBYTE(w) ((unsigned char)(((unsigned short)(w) >> 8) & 0xFF))
#define FCTL 0x6270
#define FADDRL 0x6271
#define FADDRH 0x6272
#define FWDATA 0x6273
#define DBGDATA 0x6260 //DMA register
#define X_DMAARM 0x70D6 // DMA Channel Arm
#define X_DMAREQ 0x70D7
#define X_DMA1CFGL 0x70D2 // DMA Channel 1-4 Configuration Address Low Byte
#define X_DMA1CFGH 0x70D3 // DMA Channel 1-4 Configuration Address High Byte
// Buffers
#define ADDR_BUF0 0x0000 // 1K,存放来自调试接口的数据,长度为1K,0x0000--0x03FF
#define ADDR_DMA_DESC 0x0400 // 从0x0400地址开始存放16字节的数据
#define PROG_BLOCK_SIZE 0xFD
// DMA Channels
#define CH_DBG_TO_BUF0 0x02 //使用通道1
#define CH_BUF0_TO_FLASH 0x04 //使用通道2
//--mcu使用的下载接口引脚,可以根据具体的mcu修改----
sbit DcPin = PADBUF^5;
sbit DdPin = PADBUF^3;
sbit ResetPin = PADBUF^1;
sbit DcPinDir = PADCON1^5;
sbit DdPinDir = PADCON1^3;
sbit ResetPinDir = PADCON1^1;
//-------------------------------------------------------------------------
void Delayus(unsigned short us)
{
while(us--)
{
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
}
}
/*********************************************************************************
* Writes a byte on the debug interface. Sets the direction of port 0 at the end.
* DdPin must be output when this function is called.
* param:
num---Byte to write
dir---Direction of all pins on port 0 that is to be written at the end.
*********************************************************************************/
void cc2530_Write_Debug_Byte(unsigned char num, unsigned char dir)
{
unsigned char i;
for (i=0; i<8; i++)
{
DdPin = (num&0x80) ? 1 : 0;
DcPin = 1;
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
num <<= 1;
DcPin = 0; //在时钟的下降沿把数据输出
}
DdPinDir = dir;
}
/*****************************************************
* Reads a byte from the debug interface.
* Requires DdPin to be input when function is called.
* return:
Byte read
*****************************************************/
unsigned char cc2530_Read_Debug_Byte(void)
{
unsigned char i,num;
for (i = 0; i < 8; i++)
{
DcPin = 1; // clock out data
num <<= 1;
num |= DdPin;
DcPin = 0;
}
return num;
}
/********************************