/******************** (C) COPYRIGHT 2011 Ò°»ðÇ¶ÈëÊ½¿ª·¢¹¤×÷ÊÒ ********************
 * ÎÄ¼þÃû       £ºNRF24L0.h
 * ÃèÊö         £ºNRF24L0º¯Êý¿â
 *
 * ÊµÑéÆ½Ì¨     £ºÒ°»ðkinetis¿ª·¢°å
 * ¿â°æ±¾       £º
 * Ç¶ÈëÏµÍ³     £º
 *
 * ×÷Õß         £ºÒ°»ðÇ¶ÈëÊ½¿ª·¢¹¤×÷ÊÒ
 * ÌÔ±¦µê       £ºhttp://firestm32.taobao.com
 * ¼¼ÊõÖ§³ÖÂÛÌ³ £ºhttp://www.ourdev.cn/bbs/bbs_list.jsp?bbs_id=1008
**********************************************************************************/
#ifndef _NRF24L0_H_
#define _NRF24L0_H_     1

#include "spi.h"



typedef enum
{
    TX_ISR_NULL,    //Ã»·¢ËÍ
    TX_ISR_SEND,    //·¢ËÍÖÐ
    TX_ISR_SUCCEED, //·¢ËÍ³É¹¦
    TX_ISR_FAIL,    //·¢ËÍÊ§°Ü
}tx_isr_state_e;

#define NRF_CFG     SPI_CFG
#define NRF_SPI     SPI0

//ÒÔÏÂÊÇÓÃ»§ÅäÖÃµÄÑ¡Ïî

#define MAX_ONCE_TX_NUM     32      //Ò»´Î´«Êä×î´ó¿ÉÖ§³ÖµÄ×Ö½ÚÊý£¨0~32£©
#define ADR_WIDTH           5       //¶¨ÒåµØÖ·³¤¶È£¨3~5£©
#define IS_CRC16            1       //1±íÊ¾Ê¹ÓÃ CRC16£¬0±íÊ¾ Ê¹ÓÃCRC8 (0~1)
#define IS_AUTO_RX_MODE     1       //1±íÊ¾·¢ËÍÍê³É´óÐ¡ºó£¬»á×Ô¶¯½øÈë½ÓÊÕÄ£Ê½£¨·¢ËÍµÄÊ±ºò»á×Ô¶¯½øÈë·¢ËÍÄ£Ê½£©¡£
                                    //0±íÊ¾²»ÐèÒª×Ô¶¯½øÈë½ÓÊÕÄ£Ê½

//ÖÐ¶Ï½ÓÊÕºÍ·¢ËÍµÄÅäÖÃ
#define IS_USE_ISR          1      //ÊÇ·ñÊ¹ÓÃISRÖÐ¶Ï·¢ËÍºÍ½ÓÊÕ¡£0£º²»Ê¹ÓÃ£¬1£ºÊ¹ÓÃ
#define RX_ISR_FIFO_PACKET  (20)    //ÖÐ¶Ï½ÓÊÕµÄ»º³åÇø¿É½ÓÊÕ°üµÄÊýÄ¿£¨°üµÄ´óÐ¡ÓÉ MAX_ONCE_TX_NUM ¾ö¶¨£©¡£Ò»¸±Í¼ÏñµÄ´óÐ¡Îª80*60/8 = 18.75*32
//#define TX_ISR_NUM          10      //ÖÐ¶Ï·¢ËÍµÄ»º³åÇøÄÜÍ¬Ê±ÓÐ¶àÉÙ¸ö·¢ËÍÇëÇó.³¬¹ýÁËÔò²»´¦Àí¡£


//ÅäÖÃµ½ÕâÀï½áÊø


#define MAX_RT              0x10    //´ïµ½×î´óÖØ·¢´ÎÊýÖÐ¶Ï±êÖ¾Î»
#define TX_DS		        0x20    //·¢ËÍÍê³ÉÖÐ¶Ï±êÖ¾Î»	  // 
#define RX_DR		        0x40    //½ÓÊÕµ½Êý¾ÝÖÐ¶Ï±êÖ¾Î»


//#define NRF_PACKET_SIZE     (  1  +  ADR_WIDTH  +  9  +  MAX_ONCE_TX_NUM  + IS_CRC16  )




//ÖÐ¶Ï·¢ËÍ²¿·Ö
extern  u8 RX_ISR_FIFO[RX_ISR_FIFO_PACKET][MAX_ONCE_TX_NUM];






extern  void NRF_Init(void);
//extern  u8 NRF_Check(void);
extern  u8 NRF_Tx_Dat(u8 *txbuf,u32 len);               //len ±ØÐëÊÇ MAX_ONCE_TX_NUM ÕûÊý±¶£¬Ê£ÏÂ²»×ã32Î»µÄ£¬Êý¾ÝÎÞÐ§
extern  u8 NRF_Rx_Dat(u8 *rxbuf);                       //Ã¿´Î¶ÁÈ¡ MAX_ONCE_TX_NUM ¸ö×Ö½Ú£¨·µ»Ø½ÓÊÕ½á¹û£º³É¹¦»òÕßÊ§°Ü£©




extern  void    NRF_Handler(void);
extern  void    NRF_ISR_Tx_Dat(u8 *txbuf,u32 len);      //ÖÐ¶Ï·½Ê½·¢ËÍÊý¾Ý
extern  u8      NRF_ISR_Tx_State(void);                 //²éÑ¯·¢ËÍ×´Ì¬

extern  u8      NRF_ISR_Rx_Dat(u8 *rxbuf);              //Ã¿´Î¶ÁÈ¡ MAX_ONCE_TX_NUM ¸ö×Ö½Ú£¨·µ»Ø½ÓÊÕ½á¹û£º³É¹¦»òÕßÊ§°Ü£¬³É¹¦ÁË£¬»¹ÓÐ²»¶Ï¼ì²éÊÇ·ñÓÐÊý¾Ý½ÓÊÕµ½£©




//·¢ËÍºÍ½ÓÊÕµÄÊ±ºò£¬»á×Ô¶¯ÉèÖÃ¶ÔÓ¦µÄÄ£Ê½¡£
//Í¨³£Çé¿öÏÂ²»ÐèÒªÎÒÃÇÊÖ¶¯ÉèÖÃ
extern  void NRF_RX_Mode(void);
extern  void NRF_TX_Mode(void);

#endif      //_NRF24L0_H_