diff --git a/src/adccmds.c b/src/adccmds.c index 49e195ac..81a7fff5 100644 --- a/src/adccmds.c +++ b/src/adccmds.c @@ -4,7 +4,7 @@ // // 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/irq.h" // irq_disable #include "command.h" // DECL_COMMAND @@ -50,7 +50,7 @@ analog_in_event(struct timer *timer) void 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)); a->timer.func = analog_in_event; 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 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); gpio_adc_cancel_sample(a->pin); a->next_begin_time = args[1]; diff --git a/src/basecmd.c b/src/basecmd.c index 639add97..1b7bff75 100644 --- a/src/basecmd.c +++ b/src/basecmd.c @@ -6,7 +6,7 @@ #include // malloc #include // memset -#include "basecmd.h" // lookup_oid +#include "basecmd.h" // oid_lookup #include "board/irq.h" // irq_save #include "board/misc.h" // alloc_maxsize #include "command.h" // DECL_COMMAND @@ -105,43 +105,43 @@ struct oid_s { }; static struct oid_s *oids; -static uint8_t num_oid; +static uint8_t oid_count; 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"); return oids[oid].data; } 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"); oids[oid].type = type; oids[oid].data = data; } 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); if (!data) shutdown("malloc failed"); memset(data, 0, size); - assign_oid(oid, type, data); + oid_assign(oid, type, data); return data; } void * -next_oid(uint8_t *i, void *type) +oid_next(uint8_t *i, void *type) { uint8_t oid = *i; for (;;) { oid++; - if (oid >= num_oid) + if (oid >= oid_count) return NULL; if (oids[oid].type == type) { *i = oid; @@ -160,7 +160,7 @@ command_allocate_oids(uint32_t *args) if (!oids) shutdown("malloc failed"); memset(oids, 0, sizeof(oids[0]) * count); - num_oid = count; + oid_count = count; } DECL_COMMAND(command_allocate_oids, "allocate_oids count=%c"); diff --git a/src/basecmd.h b/src/basecmd.h index b795e4db..987d7498 100644 --- a/src/basecmd.h +++ b/src/basecmd.h @@ -6,11 +6,11 @@ void move_free(void *m); void *move_alloc(void); void move_request_size(int size); -void *lookup_oid(uint8_t oid, void *type); -void *alloc_oid(uint8_t oid, void *type, uint16_t size); -void *next_oid(uint8_t *i, void *type); +void *oid_lookup(uint8_t oid, void *type); +void *oid_alloc(uint8_t oid, void *type, uint16_t size); +void *oid_next(uint8_t *i, void *type); #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 diff --git a/src/endstop.c b/src/endstop.c index fc63f123..ae41656a 100644 --- a/src/endstop.c +++ b/src/endstop.c @@ -4,7 +4,7 @@ // // 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/irq.h" // irq_disable #include "command.h" // DECL_COMMAND @@ -40,8 +40,8 @@ end_stop_event(struct timer *t) void command_config_end_stop(uint32_t *args) { - struct end_stop *e = alloc_oid(args[0], command_config_end_stop, sizeof(*e)); - struct stepper *s = lookup_oid(args[3], command_config_stepper); + struct end_stop *e = oid_alloc(args[0], command_config_end_stop, sizeof(*e)); + struct stepper *s = oid_lookup(args[3], command_config_stepper); e->time.func = end_stop_event; e->stepper = s; e->pin = gpio_in_setup(args[1], args[2]); @@ -53,7 +53,7 @@ DECL_COMMAND(command_config_end_stop, void 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); e->time.waketime = args[1]; e->rest_time = args[2]; @@ -87,7 +87,7 @@ void command_end_stop_query(uint32_t *args) { 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); } DECL_COMMAND(command_end_stop_query, "end_stop_query oid=%c"); diff --git a/src/gpiocmds.c b/src/gpiocmds.c index a86e12c9..259a7a5f 100644 --- a/src/gpiocmds.c +++ b/src/gpiocmds.c @@ -4,7 +4,7 @@ // // 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/irq.h" // irq_disable #include "command.h" // DECL_COMMAND @@ -43,7 +43,7 @@ digital_out_event(struct timer *timer) void 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)); d->default_value = args[2]; d->pin = gpio_out_setup(args[1], d->default_value); @@ -56,7 +56,7 @@ DECL_COMMAND(command_config_digital_out, void 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); d->timer.func = digital_out_event; d->timer.waketime = args[1]; @@ -155,7 +155,7 @@ soft_pwm_load_event(struct timer *timer) void 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)); s->cycle_time = args[2]; s->pulse_time = s->cycle_time / 255; @@ -171,7 +171,7 @@ DECL_COMMAND(command_config_soft_pwm_out, void 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]; uint8_t value = args[2]; uint8_t next_flags = SPF_CHECK_END | SPF_HAVE_NEXT; diff --git a/src/pwmcmds.c b/src/pwmcmds.c index bc9fec03..2865b62a 100644 --- a/src/pwmcmds.c +++ b/src/pwmcmds.c @@ -4,7 +4,7 @@ // // 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 "command.h" // DECL_COMMAND #include "sched.h" // sched_timer @@ -37,7 +37,7 @@ pwm_event(struct timer *timer) void 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->pin = gpio_pwm_setup(args[1], args[2], p->default_value); p->max_duration = args[4]; @@ -49,7 +49,7 @@ DECL_COMMAND(command_config_pwm_out, void 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); p->timer.func = pwm_event; p->timer.waketime = args[1]; diff --git a/src/stepper.c b/src/stepper.c index b97a7a69..39fdab54 100644 --- a/src/stepper.c +++ b/src/stepper.c @@ -5,7 +5,7 @@ // This file may be distributed under the terms of the GNU GPLv3 license. #include "autoconf.h" // CONFIG_* -#include "basecmd.h" // alloc_oid +#include "basecmd.h" // oid_alloc #include "board/gpio.h" // gpio_out_write #include "board/irq.h" // irq_disable #include "command.h" // DECL_COMMAND @@ -145,7 +145,7 @@ reschedule_min: void 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) s->time.func = stepper_event; s->flags = args[4] ? SF_INVERT_STEP : 0; @@ -163,7 +163,7 @@ DECL_COMMAND(command_config_stepper, void 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(); m->interval = args[1]; m->count = args[2]; @@ -204,7 +204,7 @@ DECL_COMMAND(command_queue_step, void 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; irq_disable(); 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 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]; irq_disable(); if (s->count)