⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cul.h

📁 TI(德州仪器公司)的CC2430芯片的库函数以及一些应用
💻 H
📖 第 1 页 / 共 3 页
字号:
* @brief
*      This function initialises the Simple Packet Protocol (SPP). Two DMA
*      channels are requested from the DMA administrator and set up to transfer
*      data to and from the Rx FiFo and Tx FiFo respectively. The Timer 4
*      administrator is also set up, and this unit will be used to generate
*      interrupts when a packet is not ACK'ed by the recipient whithin some time.
*      The radio is configured to transmit at a given frequency and to
*      automatically calculate and insert a CRC value when in transmit and to
*      check the CRC value in receive.
*
* Parameters:
*
* @param  UINT32 frequency
*         The desired Radio Frequency in kHz.
* @param  BYTE	 address
*         This nodes address.
*
* @return BOOL
*         Returns TRUE if the configuration is successful and FALSE otherwise.
*
******************************************************************************/
BOOL sppInit(UINT32 frequency, BYTE address);


/******************************************************************************
* @fn  spp_rf_IRQ
*
* @brief
*      This ISR handles the possible RF interrupts that may occur when using the
*      SPP. When the start of a packet is received, the RX-state will be set
*      accordingly.When a packet is sent and no ACK is requested, the TX_DONE
*      interrupt will be run. Reception of a complete packet will only be used
*      for receiving an ACK. This ISR will handle the ACK reception.
*
* Parameters:
*
* @param  void
*
* @return void
*
******************************************************************************/
__interrupt void spp_rf_IRQ(void);

/******************************************************************************
* @fn  rf_error_IRQ(
*
* @brief
*      This function is run if an Radio error interrupt (RFIF) is generated.
*      If TX underrun or RX overflow occurs, the corresponding FIFO is flushed.
*
* Parameters:
*
* @param  void
*
* @return void
*
******************************************************************************/
__interrupt void rf_error_IRQ(void);

/******************************************************************************
* @fn  sppSetAddress
*
* @brief
*      This function changes the local address.
*
* Parameters:
*
* @param  BYTE	 address
*         This nodes new address.
*
* @return void
*
******************************************************************************/
void sppSetAddress(BYTE address);


/******************************************************************************
* @fn  sppSend
*
* @brief
*      This function transfers _length_ bytes (up to 122) starting at
*      _pTransferData_ to the _recipient_. The number of bytes to be
*      transferred, flags, and destination- and source-address are inserted
*      before the Tx DMA channel is set up to transfer the payload to the Tx
*      FiFo. After the DMA channel is started, the transmitter is turned on.
*      If an ACK is expected in response, the corresponding flags and settings
*      are configured.
*
* Parameters:
*
* @param  SPP_TX_STRUCT*	 pPacketPointer
*         Pointer to the struct containing the transfer data.
*
* @return BYTE
*         Returns TRUE if the transfer is successful, TOO_LONG if the length of
*         the data is too long and CHANNEL_BUSY if the channel is not available.
*
******************************************************************************/
BYTE sppSend(SPP_TX_STRUCT* pPacketPointer);



/******************************************************************************
* @fn  sppReceive
*
* @brief
*      This function enables reception of up to 128 bytes including header and
*      trailer. The received data will be transferred by the DMA to the data
*      space starting at _pReceiveData_. The DMA is armed and reception is
*      turned on. The reception of data will generate DMA triggers. When the
*      whole packet has been received and transferred, the DMA will generate an
*      interrupt and run the function _rxCallBack_, which is defined above.
*
* Parameters:
*
* @param  SPP_RX_STRUCT*	 pReceiveData
*         Pointer to where the received data are to be stored.
*
* @return void
*
******************************************************************************/
void sppReceive(SPP_RX_STRUCT *pReceiveData);


/******************************************************************************
* @fn  setRxCallBackFunction
*
* @brief
*     This function is used to set a user-specified call-back function
*     to be run when a correct packet addressed for me is received.
*
* Parameters:
*
* @param  FUNCTION	 callBackFunction
*
* @return void
*
******************************************************************************/
void sppSetRxCallBackFunction(FUNCTION callBackFunction);




/******************************************************************************
*******************       Radio (simple usage of SPP)       *******************
******************************************************************************/

//------------------------------------------------------------------------------------------------------
// void radioInit(...);
//
//  Description:
//      This function initializes the radio by calling sppInit. The frequency of operation is set and
//      this nodes address is stored. The radio is set up for handling non-IEEE 802.15.4 packets.
//
//  Arguments:
//      UINT32 frequency
//          The radio frequency to be used.
//      BYTE localAddress
//          The address of this node.
//
//  Return value:
//      void
//------------------------------------------------------------------------------------------------------
void radioInit(UINT32 frequency, BYTE localAddress);

//------------------------------------------------------------------------------------------------------
// BYTE radioSend(...);
//
//  Description:
//      This function sends data of a given length either to a specified recipient (may be broadcast)
//      using the radio. If the number of bytes to be transferred is larger than the size of the TX FIFO,
//      the data is split over an adequate number of packets. The function uses the SPP library. If the
//      radio is busy, or the packet is sent but not ACK'ed, the transmission is retried. If the retires
//      fails, the function returns FALSE. If the packet is ACK'ed correctly by the receiver, the
//      function returns TRUE.
//
//  Arguments:
//      BYTE* transmitData
//                      Pointer to the data to be sent.
//      WORD dataLenght
//          The number of bytes to be transferred.
//      BYTE remoteAddress
//          The address of the node to receive the packet. 0 is broadcast address (BROADCAST_ADDRESS).
//      BYTE doAck
//          Set to DO_ACK if the packet is to be ACK'ed and DO_NOT_ACK otherwise.
//
//  Return value:
//      BOOL
//          TRUE if the sent packet is acked by the recipient and false otherwise.
//------------------------------------------------------------------------------------------------------
BOOL radioSend(BYTE* transmitData, WORD dataLength, BYTE remoteAddress, BYTE doAck);


//------------------------------------------------------------------------------------------------------
// BYTE radioReceive(...);
//
//  Description:
//      This function turns on the radio receiver and waits until either a correctly addressed packet
//      packet is received or the unit has been waiting for a specified time period. The function employs
//      the SPP library for radio access.
//
//  Arguments:
//      BYTE** receiveData
//                      Double pointer to the received data. This way of reference reduces the RAM requirement.
//      BYTE* lenght
//          Pointer to the length of the received data.
//      WORD timeout
//          Value indicating how long the receiver will wait for a packet in ms. If no packet is received
//          within this timeout period, false is returned.
//          If timeout is set to 0, the function will not return before a packet is received.
//      BYTE* sender
//          The function will fill in the packets source address at this location.
//
//  Return value:
//      BOOL
//          TRUE if a packet has been received and FALSE if no packet has been received within the timeout
//          period.
//------------------------------------------------------------------------------------------------------
BOOL radioReceive(BYTE** receiveData, BYTE* length, WORD timeout, BYTE* sender);



/******************************************************************************
*******************       FLASH LIFE EXTENDER (FLEX)       ********************
******************************************************************************/
typedef struct{
    enum{
        ERASED          = 3,
        VALID           = 2,
        OBSOLETE        = 0,
    }pageState;//: 2;
    enum{
        VERSION_0       = 0,
        VERSION_1       = 1,
        VERSION_2       = 2,
        VERSION_3       = 3,
    } version;//: 6;
    BYTE identifier;
    WORD eraseCounter;
}FLEX_PAGE_HEADER;




#define FLEX_ALLOC(kb)                                              \
    BYTE __code flexPages = (kb/2);                                 \
    BYTE __code flexBuf[kb/2 * 2048] _at_ (0x10000 - (kb/2 * 2048)) \


/******************************************************************************
* @fn  flexFetch
*
* @brief
*
* Parameters:
*
* @param  void* pDataPointer
* @param  BYTE	 id
* @param  BYTE	 length
* @param  void* initValue
*
* @return BOOL
*
******************************************************************************/
BOOL flexFetch(void* pDataPointer, BYTE id, BYTE length, void* initValue);


/******************************************************************************
* @fn  flexCommit
*
* @brief       Description of the function.
*
* Parameters:
*
* @param  void*
* @param  BYTE	 id
* @param  BYTE	 length
*
* @return BOOL
*
******************************************************************************/
BOOL flexCommit(void* pDataPointer, BYTE id, BYTE length);

#define FLASH_WRITE_BUFFER_LENGTH    60


#define FLEX_NOT_FOUND      0x08
#define FLEX_DATA_VALID     0x02
#define FLEX_DATA_UNUSED    0xFF
#define FLEX_DATA_OBSOLETE  0x00

#endif  // CUL_H

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -