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

📄 radioserver.h

📁 simulink real-time workshop for dragon12 development board from
💻 H
字号:
/**
 * Header for server nRF24L01 code.
 *
 * @author Stephen Craig, 25/07/2006
 */

#ifndef _RADIO_SERVER_H_
#define _RADIO_SERVER_H_

#include "spi.h"                   /* support for SPI */

/* payload length */
#define PAYLOAD_LEN 32             /* maximum is 32, minimum is 5 */

/* default baud rate */
#define RADIO_DEFAULT_BAUD_RATE    SPI_BAUD_6000000


// there can be up to '5' clients
#define CLIENT_COUNT_MAX  5

// flags set in the clientFlags register which to signify what clients
// are active (for a server), and used by clients to determine what
// the LSB of their address should be.
// match the EN_RXADDR flags
#define CLIENT_FLAG_0     0x02
#define CLIENT_FLAG_1     0x04
#define CLIENT_FLAG_2     0x08
#define CLIENT_FLAG_3     0x10
#define CLIENT_FLAG_4     0x20

#define INIT_NO_ERROR             0
#define INIT_ERROR_NO_POWER       1
#define INIT_ERROR_NO_CLIENTS_SET 2

#define NULL                   ((void *) 0)

/**
 * Initialises the radio transceiver.
 * @param baudRate rate at which to comm with module on SPI
 * @param rf_channel should be between 0 and 127
 * @param serverAddressHeader first four bytes of server address
 * @param clientAddressHeader first four bytes of client addresses
 * @param client one of CLIENT_FLAG_0, CLIENT_FLAG_1, etc.
 * @return one of the INIT_XXX values
 */
unsigned char RadioServer_Init(unsigned char baudRate,
                               unsigned char rfChannel,
                               unsigned long serverAddressHeader,
                               unsigned long clientAddressHeader,
                               unsigned char clientFlags);

/**
 * ISR for when the radio module should be polled.
 */
__interrupt extern void RadioServer_OnTick(void);

/**
 * This method will cycle through all the channels and increment an array
 * element corresponding to an RF channel if a signal is detected on that channel.
 * The lower the number of carrier detects, the better choice that channel is.
 * Advisable to let this run for about 10 minutes...
 * Use hyperterminal to output this to "CAPTURE.csv" file. Open in Excel. Remove
 * all but the last 128 rows. Then sort on the second column (CD count). The
 * channels will be sorted by their relative superiority.
 */
extern void RadioServer_CheckCarrier(void);

/**
 * Use this method to dynamically enable a certain client on the
 * network.
 */
extern void RadioServer_AddClient(unsigned char client);

/**
 * Use this method to dynamically disable a certain client on the
 * network.
 */
extern void RadioServer_RemoveClient(unsigned char client);

/**
 * Will add val to the end of the transmit FIFO buffer of the selected
 * client. This function will return 1 if the buffer was full and the
 * character was not added to the transmit buffer.
 */
extern unsigned char RadioServer_OutChar(unsigned char client,
                                         unsigned char val);

/**
 * Will add val[0], val[1], ... val[len-1] to the end of the transmit
 * FIFO buffer. This function will busy-wait if the buffer is full.
 */
extern void RadioServer_OutCharArray(unsigned char client,
                                     unsigned char *pt,
                                     unsigned char len);

/**
 * Will add the \0 terminated string to the end of the transmit FIFO
 * buffer. This function will busy-wait if the buffer is full.
 */
extern void RadioServer_OutString(unsigned char client,
                                  unsigned char *pt);

/**
 * Will empty the transmit buffer.
 */
extern void RadioServer_CleanOut(unsigned char client);

/**
 * Will empty the receive buffer.
 */
extern void RadioServer_CleanIn(unsigned char client);

/**
 * Returns true if the transmit buffer is full.
 */
extern unsigned char RadioServer_IsOutFull(unsigned char client);

/**
 * Returns true if the transmit buffer is empty.
 */
extern unsigned char RadioServer_IsOutEmpty(unsigned char client);

/**
 * Returns true if the receive buffer is full.
 */
extern unsigned char RadioServer_IsInFull(unsigned char client);

/**
 * Returns true if the receive buffer is empty.
 */
extern unsigned char RadioServer_IsInEmpty(unsigned char client);

/**
 * Returns the number of elements stored in a receive buffer.
 */
extern unsigned char RadioServer_HasElements(unsigned char client);

/**
 * Clean the input buffer of the selected client.
 */
extern void RadioServer_CleanIn(unsigned char client);

/**
 * Clean the output buffer of the selected client.
 */
extern void RadioServer_CleanOut(unsigned char client);

/**
 * Returns the byte at the head of the receive FIFO buffer, and
 * removes it from the buffer. If the buffer is empty, this method
 * will busy wait until there is data available.
 */
extern unsigned char RadioServer_InChar(unsigned char client);

/**
 * Removes len bytes from the head of the receive FIFO buffer, and
 * writes them to charArray. If the buffer is empty, this method
 * will busy wait until there is data available.
 */
extern void RadioServer_InCharArray(unsigned char client,
                                    unsigned char *pt,
                                    unsigned char len);

/**
 * Returns the number of times the selected client has timed out since
 * server/client reset.
 */
extern unsigned short RadioServer_GetFailureCount(unsigned char client);

extern void RadioServer_OutStatusClient(unsigned char client);

#endif // _RADIO_SERVER_H_

⌨️ 快捷键说明

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