Skip to content

gnrc_lwmac: port to gnrc_netif2#7895

Merged
miri64 merged 1 commit intoRIOT-OS:gnrc_netif2_integration/masterfrom
zhuoshuguo:lwmac_port_to_netif2
Nov 1, 2017
Merged

gnrc_lwmac: port to gnrc_netif2#7895
miri64 merged 1 commit intoRIOT-OS:gnrc_netif2_integration/masterfrom
zhuoshuguo:lwmac_port_to_netif2

Conversation

@zhuoshuguo
Copy link
Copy Markdown
Contributor

@zhuoshuguo zhuoshuguo commented Oct 27, 2017

Port LwMAC protocol to netif2.

@zhuoshuguo
Copy link
Copy Markdown
Contributor Author

@miri64 Hi, Martine, can I bother you for help correcting the initialization? I get a wrong idea about it.

@miri64 miri64 changed the base branch from master to gnrc_netif2_integration/master October 27, 2017 16:53
@miri64 miri64 changed the title Lwmac port to netif2 gnrc_lwmac: port to gnrc_netif2 Oct 27, 2017
@miri64 miri64 added Process: API change Integration Process: PR contains or issue proposes an API change. Should be handled with care. GNRC Area: network Area: Networking labels Oct 27, 2017
Copy link
Copy Markdown
Member

@miri64 miri64 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hope this helps

const char *name, gnrc_netdev_t *dev);
gnrc_netif2_t *gnrc_lwmac_init(char *stack, int stacksize, char priority,
const char *name, netdev_t *dev,
const gnrc_netif2_ops_t *ops);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ops-parameter shouldn't be needed here (just use a static definition in your c-file)

* support on-chip CSMA and this flag is set for requiring CSMA transmission,
* then, the device will run software CSMA using `csma_sender` APIs.
*/
#define GNRC_NETDEV_MAC_INFO_CSMA_ENABLED (0x0100U)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For all: GNRC_NETIF2 instead of GNRC_NETDEV ;-)

netif->mac.mac_info &= ~GNRC_NETDEV_MAC_INFO_TX_FEEDBACK_MASK;
netif->mac.mac_info |= (uint16_t)(txf & GNRC_NETDEV_MAC_INFO_TX_FEEDBACK_MASK);
}
#endif
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These function belong into the net/gnrc/mac/mac.h header.

_update_l2addr_from_dev(netif);
}

////////netif2
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This all shouldn't be required.

netif->mac.lwmac.system_start_time_ticks = rtt_get_counter();
netif->mac.lwmac.last_radio_on_time_ticks = netif->mac.lwmac.system_start_time_ticks;
netif->mac.lwmac.awake_duration_sum_ticks = 0;
netif->mac.lwmac.lwmac_info |= GNRC_LWMAC_RADIO_IS_ON;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of the lwmac-related code can go into gnrc_netif2_ops_t::init() so you don't need the thread anymore.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, Martine, what do you mean I don't need the thread anymore? Do you mean, (after I implemented ops-parameters with LwMAC features), there will be no LwMAC thread anymore (and there will be only the thread that created in sys/net/gnrc/netif2/gnrc_netif2.c), ?

Copy link
Copy Markdown
Contributor Author

@zhuoshuguo zhuoshuguo Oct 30, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, is the idea like this: LwMAC should be ported to the thread created in sys/net/gnrc/netif2/gnrc_netif2.c (the thread, maybe the real MAC thread then?), with replacement of the ops-parameters (like _init(), _send...) of my own LwMAC implementation?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. That is one of the main features of gnrc_netif2, to simplify MAC porting and to avoid code duplication ;-).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(you've done this this is just not as visible in the diff so everything alright here ;-))

_lwmac_thread, (void *)netif, name);
(void)res;
assert(res > 0);
return netif;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just call gnrc_netif2_create() with your ops struct here.

puts("init lwmac");
return gnrc_lwmac_init(stack, stacksize, priority, "at86rf2xx-lwmac", dev,
&ieee802154_ops);
#else
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No :P

if (netif->mac_info & GNRC_NETDEV_MAC_INFO_CSMA_ENABLED) {
res = csma_sender_csma_ca_send(dev, vector, n, &netif->csma_conf);
if (netif->mac.mac_info & GNRC_NETDEV_MAC_INFO_CSMA_ENABLED) {
res = csma_sender_csma_ca_send(dev, vector, n, &netif->mac.csma_conf);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops ^^"

#endif
if (netif->ops->init) {
netif->ops->init(netif);
puts("inti device");
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, this is just for debug, forget to remove it.. :-P Will remove!

DEBUG("gnrc_netif2: GNRC_NETAPI_MSG_TYPE_GET received. opt=%s\n",
opt->opt);
#endif
puts("get!!");
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is debug output ;-)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeap~

@zhuoshuguo
Copy link
Copy Markdown
Contributor Author

Sorry, Martine, 😅 I know there are some mess in this PR . I just did a quick porting (and some debug runing) to see if my way of porting (and understanding) is corrent. Will clean out all the mess myself of cause. You don't have to focus on those debuging mess now. ;-)

@miri64 miri64 self-assigned this Oct 28, 2017
@zhuoshuguo
Copy link
Copy Markdown
Contributor Author

Hi, Martine, I don't know I understand it corrently, but do I still need to use #ifdef MODULE_GNRC_LWMAC and put my gnrc_lwmac_netif2_create() in here, namely, in sys/auto_init/netif/auto_init_at86rf2xx.c ?? Namely, to replace gnrc_netif2_ieee802154_create() when MODULE_GNRC_LWMAC is defined?

@zhuoshuguo
Copy link
Copy Markdown
Contributor Author

Adapted, should be closer to the way it is expected to be.

@miri64
Copy link
Copy Markdown
Member

miri64 commented Nov 1, 2017

Hi, Martine, I don't know I understand it corrently, but do I still need to use #ifdef MODULE_GNRC_LWMAC and put my gnrc_lwmac_netif2_create() in here, namely, in sys/auto_init/netif/auto_init_at86rf2xx.c ?? Namely, to replace gnrc_netif2_ieee802154_create() when MODULE_GNRC_LWMAC is defined?

Do it with an #ifdef for now. We will do it with a more generic approach later.

@zhuoshuguo
Copy link
Copy Markdown
Contributor Author

Do it with an #ifdef for now. We will do it with a more generic approach later.

Thanks, @miri64 , have done it, like this.

Copy link
Copy Markdown
Member

@miri64 miri64 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested successfully with tests/lwmac (I'm not sure examples/gnrc_networking_mac can work at the moment so I did not bother testing it for now), but some (minor) issues still left.

AT86RF2XX_MAC_STACKSIZE,
AT86RF2XX_MAC_PRIO, "at86rf2xx-lwmac",
(netdev_t *)&at86rf2xx_devs[i]);
#else
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move this into the #ifdef MODULE_GNRC_NETIF2 below, please

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done it~

#else
int res = gnrc_netdev_ieee802154_init(&gnrc_adpt[i],
(netdev_ieee802154_t *)&at86rf2xx_devs[i]);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please leave this be ;-)

* @param[in] priority Priority for the network interface's thread.
* @param[in] name Name for the network interface. May be NULL.
* @param[in] dev Device for the interface.
* @param[in] ops Operations for the LWMAC network interface.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ops isn't a parameter below.

* @param[in] name name of the thread housing the LWMAC instance
* @param[in] dev netdev device, needs to be already initialized
* @note If @ref DEVELHELP is defined netif_params_t::name is used as the
* name of the network interface's thread.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is netif_params_t?

* (e.g. empty payload with Ethernet).
* @return Any negative error code reported by gnrc_netif2_t::dev.
*/
int _gnrc_lwmac_transmit(gnrc_netif2_t *netif, gnrc_pktsnip_t *pkt);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(optional) since the function name starts with a _: Maybe add @internal tag to the doc?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about I just change this function to gnrc_lwmac_transmit()??

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added @internal tag to the doc.

netif->mac.lwmac.system_start_time_ticks = rtt_get_counter();
netif->mac.lwmac.last_radio_on_time_ticks = netif->mac.lwmac.system_start_time_ticks;
netif->mac.lwmac.awake_duration_sum_ticks = 0;
netif->mac.lwmac.lwmac_info |= GNRC_LWMAC_RADIO_IS_ON;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(you've done this this is just not as visible in the diff so everything alright here ;-))

@zhuoshuguo
Copy link
Copy Markdown
Contributor Author

Addressed new comments~

Copy link
Copy Markdown
Member

@miri64 miri64 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes look all good now. This might be merged before the actual GNRC integration of gnrc_netif2 ^^: ACK

@miri64 miri64 added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Nov 1, 2017
@zhuoshuguo
Copy link
Copy Markdown
Contributor Author

OK~ Thanks! Martine!~ Could you wait a minute before trigger the merge button. I want to pope all the LWMAC codes through uncrustify, to tackle potential remaining coding style issues~ Also, I need to squash. ^^

@miri64
Copy link
Copy Markdown
Member

miri64 commented Nov 1, 2017

Sure! Squash is necessary anyway ;-)

@miri64
Copy link
Copy Markdown
Member

miri64 commented Nov 1, 2017

Also: checkout some whitespace issues, that Murdock found.

@zhuoshuguo
Copy link
Copy Markdown
Contributor Author

Also: checkout some whitespace issues, that Murdock found.

OK, I suppose uncrustify will do the job. :-)

@miri64 miri64 added the CI: needs squashing Commits in this PR need to be squashed; If set, CI systems will mark this PR as unmergable label Nov 1, 2017
@zhuoshuguo
Copy link
Copy Markdown
Contributor Author

Poped through uncrustify, squash immediately.

@miri64 miri64 added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR and removed CI: needs squashing Commits in this PR need to be squashed; If set, CI systems will mark this PR as unmergable CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Nov 1, 2017
@zhuoshuguo zhuoshuguo force-pushed the lwmac_port_to_netif2 branch from ce74a9b to c554d30 Compare November 1, 2017 14:42
@zhuoshuguo
Copy link
Copy Markdown
Contributor Author

Squashed!~ ;-)

@zhuoshuguo
Copy link
Copy Markdown
Contributor Author

Everything looks OK now, let's go for merge?~ 😃

@miri64 miri64 merged commit ea27fe3 into RIOT-OS:gnrc_netif2_integration/master Nov 1, 2017
@miri64
Copy link
Copy Markdown
Member

miri64 commented Nov 1, 2017

Yapp

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: network Area: Networking CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Process: API change Integration Process: PR contains or issue proposes an API change. Should be handled with care.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants