basecmd: Use oid_ prefix for the oid manipulation functions
Consistently use an "oid_" prefix on the oid functions - this makes them similar to other functions with a common prefix. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
d5fc594317
commit
60a4bda9d4
|
@ -4,7 +4,7 @@
|
||||||
//
|
//
|
||||||
// This file may be distributed under the terms of the GNU GPLv3 license.
|
// This file may be distributed under the terms of the GNU GPLv3 license.
|
||||||
|
|
||||||
#include "basecmd.h" // alloc_oid
|
#include "basecmd.h" // oid_alloc
|
||||||
#include "board/gpio.h" // struct gpio_adc
|
#include "board/gpio.h" // struct gpio_adc
|
||||||
#include "board/irq.h" // irq_disable
|
#include "board/irq.h" // irq_disable
|
||||||
#include "command.h" // DECL_COMMAND
|
#include "command.h" // DECL_COMMAND
|
||||||
|
@ -50,7 +50,7 @@ analog_in_event(struct timer *timer)
|
||||||
void
|
void
|
||||||
command_config_analog_in(uint32_t *args)
|
command_config_analog_in(uint32_t *args)
|
||||||
{
|
{
|
||||||
struct analog_in *a = alloc_oid(
|
struct analog_in *a = oid_alloc(
|
||||||
args[0], command_config_analog_in, sizeof(*a));
|
args[0], command_config_analog_in, sizeof(*a));
|
||||||
a->timer.func = analog_in_event;
|
a->timer.func = analog_in_event;
|
||||||
a->pin = gpio_adc_setup(args[1]);
|
a->pin = gpio_adc_setup(args[1]);
|
||||||
|
@ -61,7 +61,7 @@ DECL_COMMAND(command_config_analog_in, "config_analog_in oid=%c pin=%u");
|
||||||
void
|
void
|
||||||
command_query_analog_in(uint32_t *args)
|
command_query_analog_in(uint32_t *args)
|
||||||
{
|
{
|
||||||
struct analog_in *a = lookup_oid(args[0], command_config_analog_in);
|
struct analog_in *a = oid_lookup(args[0], command_config_analog_in);
|
||||||
sched_del_timer(&a->timer);
|
sched_del_timer(&a->timer);
|
||||||
gpio_adc_cancel_sample(a->pin);
|
gpio_adc_cancel_sample(a->pin);
|
||||||
a->next_begin_time = args[1];
|
a->next_begin_time = args[1];
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
#include <stdlib.h> // malloc
|
#include <stdlib.h> // malloc
|
||||||
#include <string.h> // memset
|
#include <string.h> // memset
|
||||||
#include "basecmd.h" // lookup_oid
|
#include "basecmd.h" // oid_lookup
|
||||||
#include "board/irq.h" // irq_save
|
#include "board/irq.h" // irq_save
|
||||||
#include "board/misc.h" // alloc_maxsize
|
#include "board/misc.h" // alloc_maxsize
|
||||||
#include "command.h" // DECL_COMMAND
|
#include "command.h" // DECL_COMMAND
|
||||||
|
@ -105,43 +105,43 @@ struct oid_s {
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct oid_s *oids;
|
static struct oid_s *oids;
|
||||||
static uint8_t num_oid;
|
static uint8_t oid_count;
|
||||||
|
|
||||||
void *
|
void *
|
||||||
lookup_oid(uint8_t oid, void *type)
|
oid_lookup(uint8_t oid, void *type)
|
||||||
{
|
{
|
||||||
if (oid >= num_oid || type != oids[oid].type)
|
if (oid >= oid_count || type != oids[oid].type)
|
||||||
shutdown("Invalid oid type");
|
shutdown("Invalid oid type");
|
||||||
return oids[oid].data;
|
return oids[oid].data;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
assign_oid(uint8_t oid, void *type, void *data)
|
oid_assign(uint8_t oid, void *type, void *data)
|
||||||
{
|
{
|
||||||
if (oid >= num_oid || oids[oid].type || is_finalized())
|
if (oid >= oid_count || oids[oid].type || is_finalized())
|
||||||
shutdown("Can't assign oid");
|
shutdown("Can't assign oid");
|
||||||
oids[oid].type = type;
|
oids[oid].type = type;
|
||||||
oids[oid].data = data;
|
oids[oid].data = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *
|
void *
|
||||||
alloc_oid(uint8_t oid, void *type, uint16_t size)
|
oid_alloc(uint8_t oid, void *type, uint16_t size)
|
||||||
{
|
{
|
||||||
void *data = malloc(size);
|
void *data = malloc(size);
|
||||||
if (!data)
|
if (!data)
|
||||||
shutdown("malloc failed");
|
shutdown("malloc failed");
|
||||||
memset(data, 0, size);
|
memset(data, 0, size);
|
||||||
assign_oid(oid, type, data);
|
oid_assign(oid, type, data);
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *
|
void *
|
||||||
next_oid(uint8_t *i, void *type)
|
oid_next(uint8_t *i, void *type)
|
||||||
{
|
{
|
||||||
uint8_t oid = *i;
|
uint8_t oid = *i;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
oid++;
|
oid++;
|
||||||
if (oid >= num_oid)
|
if (oid >= oid_count)
|
||||||
return NULL;
|
return NULL;
|
||||||
if (oids[oid].type == type) {
|
if (oids[oid].type == type) {
|
||||||
*i = oid;
|
*i = oid;
|
||||||
|
@ -160,7 +160,7 @@ command_allocate_oids(uint32_t *args)
|
||||||
if (!oids)
|
if (!oids)
|
||||||
shutdown("malloc failed");
|
shutdown("malloc failed");
|
||||||
memset(oids, 0, sizeof(oids[0]) * count);
|
memset(oids, 0, sizeof(oids[0]) * count);
|
||||||
num_oid = count;
|
oid_count = count;
|
||||||
}
|
}
|
||||||
DECL_COMMAND(command_allocate_oids, "allocate_oids count=%c");
|
DECL_COMMAND(command_allocate_oids, "allocate_oids count=%c");
|
||||||
|
|
||||||
|
|
|
@ -6,11 +6,11 @@
|
||||||
void move_free(void *m);
|
void move_free(void *m);
|
||||||
void *move_alloc(void);
|
void *move_alloc(void);
|
||||||
void move_request_size(int size);
|
void move_request_size(int size);
|
||||||
void *lookup_oid(uint8_t oid, void *type);
|
void *oid_lookup(uint8_t oid, void *type);
|
||||||
void *alloc_oid(uint8_t oid, void *type, uint16_t size);
|
void *oid_alloc(uint8_t oid, void *type, uint16_t size);
|
||||||
void *next_oid(uint8_t *i, void *type);
|
void *oid_next(uint8_t *i, void *type);
|
||||||
|
|
||||||
#define foreach_oid(pos,data,oidtype) \
|
#define foreach_oid(pos,data,oidtype) \
|
||||||
for (pos=-1; (data=next_oid(&pos, oidtype)); )
|
for (pos=-1; (data=oid_next(&pos, oidtype)); )
|
||||||
|
|
||||||
#endif // basecmd.h
|
#endif // basecmd.h
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
//
|
//
|
||||||
// This file may be distributed under the terms of the GNU GPLv3 license.
|
// This file may be distributed under the terms of the GNU GPLv3 license.
|
||||||
|
|
||||||
#include "basecmd.h" // alloc_oid
|
#include "basecmd.h" // oid_alloc
|
||||||
#include "board/gpio.h" // struct gpio
|
#include "board/gpio.h" // struct gpio
|
||||||
#include "board/irq.h" // irq_disable
|
#include "board/irq.h" // irq_disable
|
||||||
#include "command.h" // DECL_COMMAND
|
#include "command.h" // DECL_COMMAND
|
||||||
|
@ -40,8 +40,8 @@ end_stop_event(struct timer *t)
|
||||||
void
|
void
|
||||||
command_config_end_stop(uint32_t *args)
|
command_config_end_stop(uint32_t *args)
|
||||||
{
|
{
|
||||||
struct end_stop *e = alloc_oid(args[0], command_config_end_stop, sizeof(*e));
|
struct end_stop *e = oid_alloc(args[0], command_config_end_stop, sizeof(*e));
|
||||||
struct stepper *s = lookup_oid(args[3], command_config_stepper);
|
struct stepper *s = oid_lookup(args[3], command_config_stepper);
|
||||||
e->time.func = end_stop_event;
|
e->time.func = end_stop_event;
|
||||||
e->stepper = s;
|
e->stepper = s;
|
||||||
e->pin = gpio_in_setup(args[1], args[2]);
|
e->pin = gpio_in_setup(args[1], args[2]);
|
||||||
|
@ -53,7 +53,7 @@ DECL_COMMAND(command_config_end_stop,
|
||||||
void
|
void
|
||||||
command_end_stop_home(uint32_t *args)
|
command_end_stop_home(uint32_t *args)
|
||||||
{
|
{
|
||||||
struct end_stop *e = lookup_oid(args[0], command_config_end_stop);
|
struct end_stop *e = oid_lookup(args[0], command_config_end_stop);
|
||||||
sched_del_timer(&e->time);
|
sched_del_timer(&e->time);
|
||||||
e->time.waketime = args[1];
|
e->time.waketime = args[1];
|
||||||
e->rest_time = args[2];
|
e->rest_time = args[2];
|
||||||
|
@ -87,7 +87,7 @@ void
|
||||||
command_end_stop_query(uint32_t *args)
|
command_end_stop_query(uint32_t *args)
|
||||||
{
|
{
|
||||||
uint8_t oid = args[0];
|
uint8_t oid = args[0];
|
||||||
struct end_stop *e = lookup_oid(oid, command_config_end_stop);
|
struct end_stop *e = oid_lookup(oid, command_config_end_stop);
|
||||||
end_stop_report(oid, e);
|
end_stop_report(oid, e);
|
||||||
}
|
}
|
||||||
DECL_COMMAND(command_end_stop_query, "end_stop_query oid=%c");
|
DECL_COMMAND(command_end_stop_query, "end_stop_query oid=%c");
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
//
|
//
|
||||||
// This file may be distributed under the terms of the GNU GPLv3 license.
|
// This file may be distributed under the terms of the GNU GPLv3 license.
|
||||||
|
|
||||||
#include "basecmd.h" // alloc_oid
|
#include "basecmd.h" // oid_alloc
|
||||||
#include "board/gpio.h" // struct gpio_out
|
#include "board/gpio.h" // struct gpio_out
|
||||||
#include "board/irq.h" // irq_disable
|
#include "board/irq.h" // irq_disable
|
||||||
#include "command.h" // DECL_COMMAND
|
#include "command.h" // DECL_COMMAND
|
||||||
|
@ -43,7 +43,7 @@ digital_out_event(struct timer *timer)
|
||||||
void
|
void
|
||||||
command_config_digital_out(uint32_t *args)
|
command_config_digital_out(uint32_t *args)
|
||||||
{
|
{
|
||||||
struct digital_out_s *d = alloc_oid(args[0], command_config_digital_out
|
struct digital_out_s *d = oid_alloc(args[0], command_config_digital_out
|
||||||
, sizeof(*d));
|
, sizeof(*d));
|
||||||
d->default_value = args[2];
|
d->default_value = args[2];
|
||||||
d->pin = gpio_out_setup(args[1], d->default_value);
|
d->pin = gpio_out_setup(args[1], d->default_value);
|
||||||
|
@ -56,7 +56,7 @@ DECL_COMMAND(command_config_digital_out,
|
||||||
void
|
void
|
||||||
command_schedule_digital_out(uint32_t *args)
|
command_schedule_digital_out(uint32_t *args)
|
||||||
{
|
{
|
||||||
struct digital_out_s *d = lookup_oid(args[0], command_config_digital_out);
|
struct digital_out_s *d = oid_lookup(args[0], command_config_digital_out);
|
||||||
sched_del_timer(&d->timer);
|
sched_del_timer(&d->timer);
|
||||||
d->timer.func = digital_out_event;
|
d->timer.func = digital_out_event;
|
||||||
d->timer.waketime = args[1];
|
d->timer.waketime = args[1];
|
||||||
|
@ -155,7 +155,7 @@ soft_pwm_load_event(struct timer *timer)
|
||||||
void
|
void
|
||||||
command_config_soft_pwm_out(uint32_t *args)
|
command_config_soft_pwm_out(uint32_t *args)
|
||||||
{
|
{
|
||||||
struct soft_pwm_s *s = alloc_oid(args[0], command_config_soft_pwm_out
|
struct soft_pwm_s *s = oid_alloc(args[0], command_config_soft_pwm_out
|
||||||
, sizeof(*s));
|
, sizeof(*s));
|
||||||
s->cycle_time = args[2];
|
s->cycle_time = args[2];
|
||||||
s->pulse_time = s->cycle_time / 255;
|
s->pulse_time = s->cycle_time / 255;
|
||||||
|
@ -171,7 +171,7 @@ DECL_COMMAND(command_config_soft_pwm_out,
|
||||||
void
|
void
|
||||||
command_schedule_soft_pwm_out(uint32_t *args)
|
command_schedule_soft_pwm_out(uint32_t *args)
|
||||||
{
|
{
|
||||||
struct soft_pwm_s *s = lookup_oid(args[0], command_config_soft_pwm_out);
|
struct soft_pwm_s *s = oid_lookup(args[0], command_config_soft_pwm_out);
|
||||||
uint32_t time = args[1];
|
uint32_t time = args[1];
|
||||||
uint8_t value = args[2];
|
uint8_t value = args[2];
|
||||||
uint8_t next_flags = SPF_CHECK_END | SPF_HAVE_NEXT;
|
uint8_t next_flags = SPF_CHECK_END | SPF_HAVE_NEXT;
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
//
|
//
|
||||||
// This file may be distributed under the terms of the GNU GPLv3 license.
|
// This file may be distributed under the terms of the GNU GPLv3 license.
|
||||||
|
|
||||||
#include "basecmd.h" // alloc_oid
|
#include "basecmd.h" // oid_alloc
|
||||||
#include "board/gpio.h" // struct gpio_pwm
|
#include "board/gpio.h" // struct gpio_pwm
|
||||||
#include "command.h" // DECL_COMMAND
|
#include "command.h" // DECL_COMMAND
|
||||||
#include "sched.h" // sched_timer
|
#include "sched.h" // sched_timer
|
||||||
|
@ -37,7 +37,7 @@ pwm_event(struct timer *timer)
|
||||||
void
|
void
|
||||||
command_config_pwm_out(uint32_t *args)
|
command_config_pwm_out(uint32_t *args)
|
||||||
{
|
{
|
||||||
struct pwm_out_s *p = alloc_oid(args[0], command_config_pwm_out, sizeof(*p));
|
struct pwm_out_s *p = oid_alloc(args[0], command_config_pwm_out, sizeof(*p));
|
||||||
p->default_value = args[3];
|
p->default_value = args[3];
|
||||||
p->pin = gpio_pwm_setup(args[1], args[2], p->default_value);
|
p->pin = gpio_pwm_setup(args[1], args[2], p->default_value);
|
||||||
p->max_duration = args[4];
|
p->max_duration = args[4];
|
||||||
|
@ -49,7 +49,7 @@ DECL_COMMAND(command_config_pwm_out,
|
||||||
void
|
void
|
||||||
command_schedule_pwm_out(uint32_t *args)
|
command_schedule_pwm_out(uint32_t *args)
|
||||||
{
|
{
|
||||||
struct pwm_out_s *p = lookup_oid(args[0], command_config_pwm_out);
|
struct pwm_out_s *p = oid_lookup(args[0], command_config_pwm_out);
|
||||||
sched_del_timer(&p->timer);
|
sched_del_timer(&p->timer);
|
||||||
p->timer.func = pwm_event;
|
p->timer.func = pwm_event;
|
||||||
p->timer.waketime = args[1];
|
p->timer.waketime = args[1];
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
// This file may be distributed under the terms of the GNU GPLv3 license.
|
// This file may be distributed under the terms of the GNU GPLv3 license.
|
||||||
|
|
||||||
#include "autoconf.h" // CONFIG_*
|
#include "autoconf.h" // CONFIG_*
|
||||||
#include "basecmd.h" // alloc_oid
|
#include "basecmd.h" // oid_alloc
|
||||||
#include "board/gpio.h" // gpio_out_write
|
#include "board/gpio.h" // gpio_out_write
|
||||||
#include "board/irq.h" // irq_disable
|
#include "board/irq.h" // irq_disable
|
||||||
#include "command.h" // DECL_COMMAND
|
#include "command.h" // DECL_COMMAND
|
||||||
|
@ -145,7 +145,7 @@ reschedule_min:
|
||||||
void
|
void
|
||||||
command_config_stepper(uint32_t *args)
|
command_config_stepper(uint32_t *args)
|
||||||
{
|
{
|
||||||
struct stepper *s = alloc_oid(args[0], command_config_stepper, sizeof(*s));
|
struct stepper *s = oid_alloc(args[0], command_config_stepper, sizeof(*s));
|
||||||
if (!CONFIG_INLINE_STEPPER_HACK)
|
if (!CONFIG_INLINE_STEPPER_HACK)
|
||||||
s->time.func = stepper_event;
|
s->time.func = stepper_event;
|
||||||
s->flags = args[4] ? SF_INVERT_STEP : 0;
|
s->flags = args[4] ? SF_INVERT_STEP : 0;
|
||||||
|
@ -163,7 +163,7 @@ DECL_COMMAND(command_config_stepper,
|
||||||
void
|
void
|
||||||
command_queue_step(uint32_t *args)
|
command_queue_step(uint32_t *args)
|
||||||
{
|
{
|
||||||
struct stepper *s = lookup_oid(args[0], command_config_stepper);
|
struct stepper *s = oid_lookup(args[0], command_config_stepper);
|
||||||
struct stepper_move *m = move_alloc();
|
struct stepper_move *m = move_alloc();
|
||||||
m->interval = args[1];
|
m->interval = args[1];
|
||||||
m->count = args[2];
|
m->count = args[2];
|
||||||
|
@ -204,7 +204,7 @@ DECL_COMMAND(command_queue_step,
|
||||||
void
|
void
|
||||||
command_set_next_step_dir(uint32_t *args)
|
command_set_next_step_dir(uint32_t *args)
|
||||||
{
|
{
|
||||||
struct stepper *s = lookup_oid(args[0], command_config_stepper);
|
struct stepper *s = oid_lookup(args[0], command_config_stepper);
|
||||||
uint8_t nextdir = args[1] ? SF_NEXT_DIR : 0;
|
uint8_t nextdir = args[1] ? SF_NEXT_DIR : 0;
|
||||||
irq_disable();
|
irq_disable();
|
||||||
s->flags = (s->flags & ~SF_NEXT_DIR) | nextdir;
|
s->flags = (s->flags & ~SF_NEXT_DIR) | nextdir;
|
||||||
|
@ -216,7 +216,7 @@ DECL_COMMAND(command_set_next_step_dir, "set_next_step_dir oid=%c dir=%c");
|
||||||
void
|
void
|
||||||
command_reset_step_clock(uint32_t *args)
|
command_reset_step_clock(uint32_t *args)
|
||||||
{
|
{
|
||||||
struct stepper *s = lookup_oid(args[0], command_config_stepper);
|
struct stepper *s = oid_lookup(args[0], command_config_stepper);
|
||||||
uint32_t waketime = args[1];
|
uint32_t waketime = args[1];
|
||||||
irq_disable();
|
irq_disable();
|
||||||
if (s->count)
|
if (s->count)
|
||||||
|
|
Loading…
Reference in New Issue