mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
Merge pull request #1395 from LudwigOrtmann/transceiver_unregister
sys/transceiver: add transceiver_unregister and refactor transceiver_register
This commit is contained in:
commit
f33dc4601b
@ -228,5 +228,15 @@ int transceiver_start(void);
|
||||
*/
|
||||
uint8_t transceiver_register(transceiver_type_t transceivers, int pid);
|
||||
|
||||
/**
|
||||
* @brief unregister a thread for events from certain transceivers
|
||||
*
|
||||
* @param transceivers The transceiver types to register for
|
||||
* @param pid The pid of the thread to register
|
||||
*
|
||||
* @return 1 on success, 0 otherwise
|
||||
*/
|
||||
uint8_t transceiver_unregister(transceiver_type_t transceivers, int pid);
|
||||
|
||||
#endif /* TRANSCEIVER_H */
|
||||
/** @} */
|
||||
|
@ -233,22 +233,37 @@ int transceiver_start(void)
|
||||
/* Register an upper layer thread */
|
||||
uint8_t transceiver_register(transceiver_type_t t, int pid)
|
||||
{
|
||||
uint8_t i;
|
||||
|
||||
/* find pid in registered threads or first unused space */
|
||||
for (i = 0; ((i < TRANSCEIVER_MAX_REGISTERED) &&
|
||||
(reg[i].pid != pid) &&
|
||||
(reg[i].transceivers != TRANSCEIVER_NONE)); i++);
|
||||
|
||||
if (i >= TRANSCEIVER_MAX_REGISTERED) {
|
||||
return ENOMEM;
|
||||
int result = 0;
|
||||
int state = disableIRQ();
|
||||
for (size_t i = 0; i < TRANSCEIVER_MAX_REGISTERED; i++) {
|
||||
if ((reg[i].pid == pid) || (reg[i].transceivers == TRANSCEIVER_NONE)) {
|
||||
reg[i].transceivers |= t;
|
||||
reg[i].pid = pid;
|
||||
DEBUG("transceiver: Thread %i registered for %i\n", reg[i].pid, reg[i].transceivers);
|
||||
restoreIRQ(state);
|
||||
result = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
reg[i].transceivers |= t;
|
||||
reg[i].pid = pid;
|
||||
DEBUG("transceiver: Thread %i registered for %i\n", reg[i].pid, reg[i].transceivers);
|
||||
return 1;
|
||||
restoreIRQ(state);
|
||||
return result;
|
||||
}
|
||||
|
||||
/* Unregister an upper layer thread */
|
||||
uint8_t transceiver_unregister(transceiver_type_t t, int pid)
|
||||
{
|
||||
int result = 0;
|
||||
int state = disableIRQ();
|
||||
for (size_t i = 0; i < TRANSCEIVER_MAX_REGISTERED; ++i) {
|
||||
if (reg[i].pid == pid) {
|
||||
reg[i].transceivers &= ~t;
|
||||
restoreIRQ(state);
|
||||
result = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
restoreIRQ(state);
|
||||
return result;
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------------------------*/
|
||||
@ -465,7 +480,7 @@ static void receive_packet(uint16_t type, uint8_t pos)
|
||||
|
||||
#ifdef DBG_IGNORE
|
||||
|
||||
for (uint8_t i = 0; (i < TRANSCEIVER_MAX_IGNORED_ADDR) && (transceiver_ignored_addr[i]); i++) {
|
||||
for (size_t i = 0; (i < TRANSCEIVER_MAX_IGNORED_ADDR) && (transceiver_ignored_addr[i]); i++) {
|
||||
DEBUG("check if source (%u) is ignored -> %u\n", transceiver_buffer[transceiver_buffer_pos].src, transceiver_ignored_addr[i]);
|
||||
|
||||
if (transceiver_buffer[transceiver_buffer_pos].src == transceiver_ignored_addr[i]) {
|
||||
@ -1223,7 +1238,7 @@ static int16_t ignore_add(transceiver_type_t transceiver, void *address)
|
||||
(void) transceiver;
|
||||
radio_address_t addr = *((radio_address_t *)address);
|
||||
|
||||
for (uint8_t i = 0; i < TRANSCEIVER_MAX_IGNORED_ADDR; i++) {
|
||||
for (size_t i = 0; i < TRANSCEIVER_MAX_IGNORED_ADDR; i++) {
|
||||
if (transceiver_ignored_addr[i] == 0) {
|
||||
transceiver_ignored_addr[i] = addr;
|
||||
DEBUG("addr %u will be ignored (%u)\n", addr, i);
|
||||
|
Loading…
Reference in New Issue
Block a user