mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
csma_sender: port to netdev2
This commit is contained in:
parent
925013cd4c
commit
a3f2cdd6ea
@ -10,7 +10,7 @@ ifneq (,$(filter ccn-lite,$(USEPKG)))
|
||||
export CFLAGS += -DCCNL_RIOT
|
||||
endif
|
||||
|
||||
ifneq (,$(filter gnrc_csma_sender,$(USEMODULE)))
|
||||
ifneq (,$(filter csma_sender,$(USEMODULE)))
|
||||
USEMODULE += random
|
||||
USEMODULE += xtimer
|
||||
endif
|
||||
|
@ -1,3 +1,6 @@
|
||||
ifneq (,$(filter csma_sender,$(USEMODULE)))
|
||||
DIRS += net/link_layer/csma_sender
|
||||
endif
|
||||
ifneq (,$(filter posix_semaphore,$(USEMODULE)))
|
||||
DIRS += posix/semaphore
|
||||
endif
|
||||
|
@ -7,8 +7,8 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup net_gnrc_csma_sender CSMA/CA helper
|
||||
* @ingroup net_gnrc
|
||||
* @defgroup net_csma_sender CSMA/CA helper
|
||||
* @ingroup net
|
||||
* @brief This interface allows code from layer 2 (MAC) or higher
|
||||
* to send packets with CSMA/CA, whatever the abilities and/or
|
||||
* configuration of a given radio transceiver device are.
|
||||
@ -20,11 +20,12 @@
|
||||
* @author Kévin Roussel <Kevin.Roussel@inria.fr>
|
||||
*/
|
||||
|
||||
#ifndef GNRC_CSMA_SENDER_H_
|
||||
#define GNRC_CSMA_SENDER_H_
|
||||
#ifndef CSMA_SENDER_H_
|
||||
#define CSMA_SENDER_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "net/gnrc.h"
|
||||
#include "net/netdev2.h"
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
@ -84,9 +85,8 @@ void csma_sender_set_max_backoffs(uint8_t val);
|
||||
* CSMA/CA, this feature is used. Otherwise, a software procedure is used.
|
||||
*
|
||||
* @param[in] dev netdev device, needs to be already initialized
|
||||
* @param[in] pkt pointer to the data in the packet buffer;
|
||||
* it must be a complete 802.15.4-compliant frame,
|
||||
* ready to be sent to the radio transceiver
|
||||
* @param[in] vector pointer to the data
|
||||
* @param[in] count number of elements in @p vector
|
||||
*
|
||||
* @return number of bytes that were actually send out
|
||||
* @return -ENODEV if @p dev is invalid
|
||||
@ -97,7 +97,8 @@ void csma_sender_set_max_backoffs(uint8_t val);
|
||||
* @return -EBUSY if radio medium never was available
|
||||
* to send the given data
|
||||
*/
|
||||
int csma_sender_csma_ca_send(gnrc_netdev_t *dev, gnrc_pktsnip_t *pkt);
|
||||
int csma_sender_csma_ca_send(netdev2_t *dev, struct iovec *vector,
|
||||
unsigned count);
|
||||
|
||||
/**
|
||||
* @brief Sends a 802.15.4 frame when medium is avaiable.
|
||||
@ -114,9 +115,8 @@ int csma_sender_csma_ca_send(gnrc_netdev_t *dev, gnrc_pktsnip_t *pkt);
|
||||
* @ref csma_sender_csma_ca_send().
|
||||
*
|
||||
* @param[in] dev netdev device, needs to be already initialized
|
||||
* @param[in] pkt pointer to the data in the packet buffer;
|
||||
* it must be a complete 802.15.4-compliant frame,
|
||||
* ready to be sent to the radio transceiver
|
||||
* @param[in] vector pointer to the data
|
||||
* @param[in] count number of elements in @p vector
|
||||
*
|
||||
* @return number of bytes that were actually send out
|
||||
* @return -ENODEV if @p dev is invalid
|
||||
@ -127,13 +127,13 @@ int csma_sender_csma_ca_send(gnrc_netdev_t *dev, gnrc_pktsnip_t *pkt);
|
||||
* @return -EBUSY if radio medium was not available
|
||||
* to send the given data
|
||||
*/
|
||||
int csma_sender_cca_send(gnrc_netdev_t *dev, gnrc_pktsnip_t *pkt);
|
||||
int csma_sender_cca_send(netdev2_t *dev, struct iovec *vector, unsigned count);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* GNRC_CSMA_SENDER_H_ */
|
||||
#endif /* CSMA_SENDER_H_ */
|
||||
|
||||
/** @} */
|
@ -7,9 +7,6 @@ endif
|
||||
ifneq (,$(filter gnrc_conn_udp,$(USEMODULE)))
|
||||
DIRS += conn/udp
|
||||
endif
|
||||
ifneq (,$(filter gnrc_csma_sender,$(USEMODULE)))
|
||||
DIRS += link_layer/csma_sender
|
||||
endif
|
||||
ifneq (,$(filter gnrc_icmpv6,$(USEMODULE)))
|
||||
DIRS += network_layer/icmpv6
|
||||
endif
|
||||
|
@ -1,3 +1 @@
|
||||
MODULE := gnrc_csma_sender
|
||||
|
||||
include $(RIOTBASE)/Makefile.base
|
@ -21,10 +21,11 @@
|
||||
|
||||
#include "xtimer.h"
|
||||
#include "random.h"
|
||||
#include "net/gnrc/csma_sender.h"
|
||||
#include "net/gnrc.h"
|
||||
#include "net/netdev2.h"
|
||||
#include "net/netopt.h"
|
||||
|
||||
#include "net/csma_sender.h"
|
||||
|
||||
#define ENABLE_DEBUG (0)
|
||||
#include "debug.h"
|
||||
|
||||
@ -77,18 +78,17 @@ static inline uint32_t choose_backoff_period(int be)
|
||||
* @brief Perform a CCA and send the given packet if medium is available
|
||||
*
|
||||
* @param[in] device netdev device, needs to be already initialized
|
||||
* @param[in] data pointer to the data in the packet buffer;
|
||||
* it must be a complete 802.15.4-compliant frame,
|
||||
* ready to be sent to the radio transceiver
|
||||
* @param[in] vector pointer to the data
|
||||
* @param[in] count number of elements in @p vector
|
||||
*
|
||||
* @return the return value of device driver's
|
||||
* gnrc_netdev_driver_t::send_data()
|
||||
* function if medium was available
|
||||
* netdev2_driver_t::send() function if medium was
|
||||
* available
|
||||
* @return -ECANCELED if an internal driver error occurred
|
||||
* @return -EBUSY if radio medium was not available
|
||||
* to send the given data
|
||||
*/
|
||||
static int send_if_cca(gnrc_netdev_t *device, gnrc_pktsnip_t *data)
|
||||
static int send_if_cca(netdev2_t *device, struct iovec *vector, unsigned count)
|
||||
{
|
||||
netopt_enable_t hwfeat;
|
||||
|
||||
@ -107,7 +107,7 @@ static int send_if_cca(gnrc_netdev_t *device, gnrc_pktsnip_t *data)
|
||||
/* if medium is clear, send the packet and return */
|
||||
if (hwfeat == NETOPT_ENABLE) {
|
||||
DEBUG("csma: Radio medium available: sending packet.\n");
|
||||
return device->driver->send_data(device, data);
|
||||
return device->driver->send(device, vector, count);
|
||||
}
|
||||
|
||||
/* if we arrive here, medium was not available for transmission */
|
||||
@ -133,7 +133,8 @@ void csma_sender_set_max_backoffs(uint8_t val)
|
||||
}
|
||||
|
||||
|
||||
int csma_sender_csma_ca_send(gnrc_netdev_t *dev, gnrc_pktsnip_t *pkt)
|
||||
int csma_sender_csma_ca_send(netdev2_t *dev, struct iovec *vector,
|
||||
unsigned count)
|
||||
{
|
||||
netopt_enable_t hwfeat;
|
||||
|
||||
@ -163,7 +164,7 @@ int csma_sender_csma_ca_send(gnrc_netdev_t *dev, gnrc_pktsnip_t *pkt)
|
||||
if (ok) {
|
||||
/* device does CSMA/CA all by itself: let it do its job */
|
||||
DEBUG("csma: Network device does hardware CSMA/CA\n");
|
||||
return dev->driver->send_data(dev, pkt);
|
||||
return dev->driver->send(dev, vector, count);
|
||||
}
|
||||
|
||||
/* if we arrive here, then we must perform the CSMA/CA procedure
|
||||
@ -179,7 +180,7 @@ int csma_sender_csma_ca_send(gnrc_netdev_t *dev, gnrc_pktsnip_t *pkt)
|
||||
xtimer_usleep(bp);
|
||||
|
||||
/* try to send after a CCA */
|
||||
res = send_if_cca(dev, pkt);
|
||||
res = send_if_cca(dev, vector, count);
|
||||
if (res >= 0) {
|
||||
/* TX done */
|
||||
return res;
|
||||
@ -205,7 +206,7 @@ int csma_sender_csma_ca_send(gnrc_netdev_t *dev, gnrc_pktsnip_t *pkt)
|
||||
}
|
||||
|
||||
|
||||
int csma_sender_cca_send(gnrc_netdev_t *dev, gnrc_pktsnip_t *pkt)
|
||||
int csma_sender_cca_send(netdev2_t *dev, struct iovec *vector, unsigned count)
|
||||
{
|
||||
netopt_enable_t hwfeat;
|
||||
|
||||
@ -235,12 +236,12 @@ int csma_sender_cca_send(gnrc_netdev_t *dev, gnrc_pktsnip_t *pkt)
|
||||
if (ok) {
|
||||
/* device does auto-CCA: let him do its job */
|
||||
DEBUG("csma: Network device does auto-CCA checking.\n");
|
||||
return dev->driver->send_data(dev, pkt);
|
||||
return dev->driver->send(dev, vector, count);
|
||||
}
|
||||
|
||||
/* if we arrive here, we must do CCA ourselves to see if radio medium
|
||||
is clear before sending */
|
||||
res = send_if_cca(dev, pkt);
|
||||
res = send_if_cca(dev, vector, count);
|
||||
if (res == -EBUSY) {
|
||||
DEBUG("csma: Transmission cancelled!\n");
|
||||
}
|
Loading…
Reference in New Issue
Block a user