Browse Source

sys/saul_reg: made registry a global variable

pr/gpio
Hauke Petersen 7 years ago
parent
commit
3d63db5aed
  1. 13
      sys/include/saul_reg.h
  2. 29
      sys/saul_reg/saul_reg.c
  3. 4
      sys/shell/commands/sc_saul_reg.c

13
sys/include/saul_reg.h

@ -48,6 +48,11 @@ typedef struct {
const char *name; /**< string identifier for a device */
} saul_reg_info_t;
/**
* @brief Export the SAUL registry as global variable
*/
extern saul_reg_t *saul_reg;
/**
* @brief Register a device with the SAUL registry
*
@ -72,14 +77,6 @@ int saul_reg_add(saul_reg_t *dev);
*/
int saul_reg_rm(saul_reg_t *dev);
/**
* @brief Get the first device from the list of registered devices
*
* @return pointer to the first device in the list
* @return NULL if list is empty
*/
saul_reg_t *saul_reg_get(void);
/**
* @brief Find a device by it's position in the registry
*

29
sys/saul_reg/saul_reg.c

@ -25,14 +25,14 @@
#include "saul_reg.h"
/**
* @brief Keep the head of the device list
* @brief Keep the head of the device list as global variable
*/
static saul_reg_t *reg = NULL;
saul_reg_t *saul_reg = NULL;
int saul_reg_add(saul_reg_t *dev)
{
saul_reg_t *tmp = reg;
saul_reg_t *tmp = saul_reg;
if (dev == NULL) {
return -ENODEV;
@ -41,8 +41,8 @@ int saul_reg_add(saul_reg_t *dev)
/* prepare new entry */
dev->next = NULL;
/* add to registry */
if (reg == NULL) {
reg = dev;
if (saul_reg == NULL) {
saul_reg = dev;
}
else {
while (tmp->next != NULL) {
@ -55,13 +55,13 @@ int saul_reg_add(saul_reg_t *dev)
int saul_reg_rm(saul_reg_t *dev)
{
saul_reg_t *tmp = reg;
saul_reg_t *tmp = saul_reg;
if (reg == NULL || dev == NULL) {
if (saul_reg == NULL || dev == NULL) {
return -EINVAL;
}
if (reg == dev) {
reg = dev->next;
if (saul_reg == dev) {
saul_reg = dev->next;
}
while (tmp->next && (tmp->next != dev)) {
tmp = tmp->next;
@ -75,14 +75,9 @@ int saul_reg_rm(saul_reg_t *dev)
return 0;
}
saul_reg_t *saul_reg_get(void)
{
return reg;
}
saul_reg_t *saul_reg_find_nth(int pos)
{
saul_reg_t *tmp = reg;
saul_reg_t *tmp = saul_reg;
for (int i = 0; (i < pos) && tmp; i++) {
tmp = tmp->next;
@ -92,7 +87,7 @@ saul_reg_t *saul_reg_find_nth(int pos)
saul_reg_t *saul_reg_find_type(uint8_t type)
{
saul_reg_t *tmp = reg;
saul_reg_t *tmp = saul_reg;
while (tmp) {
if (tmp->driver->type == type) {
@ -105,7 +100,7 @@ saul_reg_t *saul_reg_find_type(uint8_t type)
saul_reg_t *saul_reg_find_name(const char *name)
{
saul_reg_t *tmp = reg;
saul_reg_t *tmp = saul_reg;
while (tmp) {
if (strcmp(tmp->name, name) == 0) {

4
sys/shell/commands/sc_saul_reg.c

@ -44,7 +44,7 @@ static void probe(int num, saul_reg_t *dev)
static void probe_all(void)
{
saul_reg_t *dev = saul_reg_get();
saul_reg_t *dev = saul_reg;
int i = 0;
while (dev) {
@ -56,7 +56,7 @@ static void probe_all(void)
static void list(void)
{
saul_reg_t *dev = saul_reg_get();
saul_reg_t *dev = saul_reg;
int i = 0;
if (dev) {

Loading…
Cancel
Save