?? cc2420hal.c
字號:
#include <msp430x16x.h>
#include "cc2420const.h"
#include "port_config_CC2420.h"
int isTxEmpty(){//發送緩沖區為空返回true
if (U0TCTL & TXEPT) {
return 1;
}
return 0;
}
int isTxIntrPending() //TXFIFO EMPTY 返回true
{
if (IFG1 & UTXIFG0){
IFG1 &= ~UTXIFG0;
return 1;
}
return 0;
}
int isRxIntrPending()//RXFIFO FULL 返回true
{
if (IFG1 & URXIFG0){
IFG1 &= ~URXIFG0;
return 1;
}
return 0;
}
void SPI_Tx(unsigned char data) //SPI tx
{
while((UTCTL0 & 0x01 )!=0x01); //等待直到沒有數據發送
TXBUF0 = data;
}
unsigned char SPI_Rx() //SPI rx
{
unsigned char data;
data = RXBUF0;
return data;
}
void HPLCC2420_cmd(char addr) {
P4OUT &= ~0x04;
isTxIntrPending();
SPI_Rx();
SPI_Tx(addr);
while(!(isRxIntrPending())) ;
P4OUT |= 0x04;
}
/**
* Read 16-bit data
*
* @return 16-bit register value
*/
int HPLCC2420_read(char addr) {
int data = 0;
PHY_Selected();
isTxIntrPending();
SPI_Rx();
SPI_Tx(addr | 0x40);
while(!isRxIntrPending()) ;
SPI_Rx();
SPI_Tx(0);
while(!(isRxIntrPending())) ;
data = SPI_Rx();
SPI_Tx(0);
while( !(isRxIntrPending())) ;
data = ((data << 8) & 0x0FF00 )| (SPI_Rx() & 0x0FF);
PHY_Deselected();
return data;
}
void flushRxfifo(void)
{
HPLCC2420_read(CC2420_RXFIFO); //flush Rx fifo
HPLCC2420_cmd(0x08);//FASTSPI_STROBE(CC2420_SFLUSHRX);
HPLCC2420_cmd(0x08);//FASTSPI_STROBE(CC2420_SFLUSHRX);
}
char HPLCC2420_write(char addr, int data) {
char status = 0;
PHY_Selected();
isTxIntrPending();
SPI_Rx();
SPI_Tx(addr);
while(!(isRxIntrPending())) ;
status = (SPI_Rx()&0x7E);
SPI_Tx((data >> 8) & 0x0FF);
while( !(isTxIntrPending())) ;
SPI_Tx(data & 0x0FF);
while(!(isTxEmpty())) ;
PHY_Deselected();
return status;
}
void HPLCC2420_RAMread(signed short Raddr, unsigned char length, unsigned char *addr)
{
char i = 0,ramlen;signed short ramaddr;unsigned char *addrbuf;
ramaddr = Raddr;
ramlen = length;
addrbuf =addr;
PHY_Selected();
// clear the RX flag if set
isTxIntrPending();
SPI_Rx(); //isRxIntrPending();
SPI_Tx((ramaddr & 0x7F) | 0x80);
while(!(isRxIntrPending())) ;
SPI_Rx();
SPI_Tx(((ramaddr >> 1) & 0xC0) | 0x20);
while( !(isRxIntrPending())) ;
SPI_Rx();
if (ramlen > 0) {
for (i = 0; i < ramlen; i++) {
SPI_Tx(0);
while(!(isRxIntrPending())) ;
addrbuf[i] = SPI_Rx();
}
}
PHY_Deselected();
}
void HPLCC2420_RAMwrite(signed short Raddr, unsigned char length, unsigned char *addr) {
unsigned char i = 0,ramlen;signed short ramaddr;unsigned char *addrbuf;
ramaddr = Raddr;
ramlen = length;
addrbuf = addr;
PHY_Selected();
// clear the RX flag if set
isTxIntrPending();
SPI_Rx(); //isRxIntrPending();
SPI_Tx((ramaddr & 0x7F) | 0x80);
while( !(isTxIntrPending())) ;
SPI_Tx(((ramaddr >> 1) & 0xC0));
while( !(isTxIntrPending())) ;
for (i = 0; i < ramlen; i++) {
SPI_Tx(addrbuf[i]);
while(!(isTxIntrPending())) ;
}
while(!(isTxEmpty())) ;
PHY_Deselected();
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -