diff --git a/software/library/Makefile b/software/library/Makefile index 8ad19548da93ef801065e82597bde59e365bf556..4d18749bfc8d234485ea4bef5184ee2332380f6d 100644 --- a/software/library/Makefile +++ b/software/library/Makefile @@ -1 +1 @@ -subdirs = boards +subdirs = boards otoroshi diff --git a/software/library/bmaaa.build b/software/library/bmaaa.build index 45e8379a9db8c29d3f02f43103f06f97995ec6df..66fe58d1bdd22c1680d68dc12b40e1d59c42fdf8 100644 --- a/software/library/bmaaa.build +++ b/software/library/bmaaa.build @@ -3,6 +3,7 @@ CONFIG_COMPILE_FRAMEPTR undefined CONFIG_COMPILE_OPTIMIZE s %include boards/board.build +%include otoroshi/otoroshi.build %section ble-* CONFIG_NET diff --git a/software/library/boards/brain.c b/software/library/boards/brain.c index af6c0dafe0c400a62d8270d3a9305124e3f21c64..5892a94cbebb619bdfd0ee62a396d47b79255b16 100644 --- a/software/library/boards/brain.c +++ b/software/library/boards/brain.c @@ -36,7 +36,6 @@ DEV_DECLARE_STATIC(cpu_dev, "cpu", DEVICE_FLAG_CPU, arm32m_drv, DEV_STATIC_RES_ID(0, 0), - DEV_STATIC_RES_FREQ(72000000, 1) ); @@ -68,7 +67,7 @@ DEV_DECLARE_STATIC(uart2_dev, "uart4", 0, stm32_usart_drv, DEV_STATIC_RES_UART(19200, 8, DEV_UART_PARITY_NONE, 1, 0, 0) ); -/* UART 4 */ +/* Timer 4 */ DEV_DECLARE_STATIC(timer4_dev, "timer4", 0, stm32_timer_drv, DEV_STATIC_RES_MEM(STM32_TIM4_ADDR, STM32_TIM4_ADDR + STM32_TIM4_SIZE), @@ -209,132 +208,3 @@ void stm32_clock_init(void) cpu_mem_write_32(STM32_RCC_ADDR + STM32_RCC_AHBRSTR_ADDR, -1); cpu_mem_write_32(STM32_RCC_ADDR + STM32_RCC_AHBRSTR_ADDR, 0); } - -#include -#include - -enum shell_otoroshi_opts_e -{ - OTOROSHI_OPT_RELAY = 0x1, - OTOROSHI_OPT_STATE = 0x2, - OTOROSHI_OPT_CLOSED = 0x4, - OTOROSHI_OPT_OPEN = 0x8, - OTOROSHI_OPT_PULSE = 0x10, - OTOROSHI_OPT_DELAY = 0x20, -}; - -struct termui_optctx_otoroshi_opts -{ - uint8_t relay; - bool_t state; - size_t delay; -}; - -static TERMUI_CON_COMMAND_PROTOTYPE(shell_otoroshi_relay) -{ - struct termui_optctx_otoroshi_opts * c = ctx; - - struct device_timer_s timer; - dev_timer_delay_t msec; - - struct device_gpio_s gpio; - - error_t err = 0; - - err = device_get_accessor_by_path(&gpio.base, NULL, "/gpio", DRIVER_CLASS_GPIO); - if (err) - return err; - - err = device_get_accessor_by_path(&timer.base, NULL, "/timer*", DRIVER_CLASS_TIMER); - if (err) - goto gpio_cleanup; - - err = dev_timer_init_sec(&timer, &msec, 0, 1, 1000); - if (err) - goto timer_cleanup; - - DEVICE_OP(&gpio, set_output, STM32_PE8, STM32_PE15, dev_gpio_mask0, dev_gpio_mask0); - DEVICE_OP(&gpio, set_mode, STM32_PE8, STM32_PE15, dev_gpio_mask1, DEV_PIN_PUSHPULL); - - if (used & OTOROSHI_OPT_PULSE) - { - uint8_t id = STM32_PE8 + c->relay * 2; - - static uint8_t door_open_mask[1] = { 0x2 }; - static uint8_t door_close_mask[1] = { 0x1 }; - - DEVICE_OP(&gpio, set_output, id, id + 1, door_open_mask, door_open_mask); - dev_timer_wait_delay(&timer, msec * 100, 0); - DEVICE_OP(&gpio, set_output, id, id, dev_gpio_mask0, dev_gpio_mask0); - - dev_timer_wait_delay(&timer, msec * c->delay, 0); - - DEVICE_OP(&gpio, set_output, id, id + 1, door_close_mask, door_close_mask); - dev_timer_wait_delay(&timer, msec * 100, 0); - DEVICE_OP(&gpio, set_output, id, id, dev_gpio_mask0, dev_gpio_mask0); - } - else - { - bool_t state = 0; - - if (used & OTOROSHI_OPT_STATE) - state = c->state; - else if (used & OTOROSHI_OPT_CLOSED) - state = 0; - else if (used & OTOROSHI_OPT_OPEN) - state = 1; - - uint8_t id = STM32_PE8 + c->relay * 2 + state; - DEVICE_OP(&gpio, set_output, id, id, dev_gpio_mask1, dev_gpio_mask1); - dev_timer_wait_delay(&timer, msec * 100, 0); - DEVICE_OP(&gpio, set_output, id, id, dev_gpio_mask0, dev_gpio_mask0); - } - -timer_cleanup: - device_put_accessor(&timer.base); -gpio_cleanup: - device_put_accessor(&gpio.base); - return err; -} - -static TERMUI_CON_OPT_DECL(otoroshi_opts) = -{ - TERMUI_CON_OPT_INTEGER_RANGE_ENTRY("-r", "--relay", OTOROSHI_OPT_RELAY, - struct termui_optctx_otoroshi_opts, relay, 1, 0, 3, - TERMUI_CON_OPT_CONSTRAINTS(OTOROSHI_OPT_RELAY, 0)) - - TERMUI_CON_OPT_INTEGER_RANGE_ENTRY("-s", "--state", OTOROSHI_OPT_STATE, - struct termui_optctx_otoroshi_opts, state, 1, 0, 1, - TERMUI_CON_OPT_CONSTRAINTS(OTOROSHI_OPT_STATE, OTOROSHI_OPT_RELAY)) - - TERMUI_CON_OPT_ENTRY("-c", "--closed", OTOROSHI_OPT_CLOSED, - TERMUI_CON_OPT_CONSTRAINTS(OTOROSHI_OPT_CLOSED | OTOROSHI_OPT_OPEN | OTOROSHI_OPT_STATE, - OTOROSHI_OPT_RELAY)) - - TERMUI_CON_OPT_ENTRY("-o", "--open", OTOROSHI_OPT_OPEN, - TERMUI_CON_OPT_CONSTRAINTS(OTOROSHI_OPT_CLOSED | OTOROSHI_OPT_OPEN | OTOROSHI_OPT_STATE, - OTOROSHI_OPT_RELAY)) - - TERMUI_CON_OPT_ENTRY("-p", "--pulse", OTOROSHI_OPT_PULSE, - TERMUI_CON_OPT_CONSTRAINTS(OTOROSHI_OPT_CLOSED | OTOROSHI_OPT_OPEN | OTOROSHI_OPT_STATE | OTOROSHI_OPT_PULSE, - OTOROSHI_OPT_RELAY)) - - TERMUI_CON_OPT_INTEGER_ENTRY("-d", "--delay", OTOROSHI_OPT_DELAY, - struct termui_optctx_otoroshi_opts, delay, 1, - TERMUI_CON_OPT_CONSTRAINTS(OTOROSHI_OPT_CLOSED | OTOROSHI_OPT_OPEN | OTOROSHI_OPT_STATE | OTOROSHI_OPT_DELAY, - OTOROSHI_OPT_RELAY | OTOROSHI_OPT_PULSE)) - - TERMUI_CON_LIST_END -}; - -static TERMUI_CON_GROUP_DECL(shell_otoroshi_subgroup) = -{ - TERMUI_CON_ENTRY(shell_otoroshi_relay, "relay", - TERMUI_CON_OPTS_CTX(otoroshi_opts, OTOROSHI_OPT_RELAY, - OTOROSHI_OPT_STATE | OTOROSHI_OPT_CLOSED | OTOROSHI_OPT_OPEN - | OTOROSHI_OPT_PULSE | OTOROSHI_OPT_DELAY, NULL)) - - TERMUI_CON_LIST_END -}; - -MUTEK_SHELL_ROOT_GROUP(shell_otoroshi_subgroup, "otoroshi"); diff --git a/software/library/otoroshi/Makefile b/software/library/otoroshi/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..9075a263dd35d5637b0157b90642ef656f5787d6 --- /dev/null +++ b/software/library/otoroshi/Makefile @@ -0,0 +1 @@ +objs-$(CONFIG_OTOROSHI_SHELL) += shell.o diff --git a/software/library/otoroshi/otoroshi.build b/software/library/otoroshi/otoroshi.build new file mode 100644 index 0000000000000000000000000000000000000000..b98482d920a5eca94b0dd2dd76510f910a14e113 --- /dev/null +++ b/software/library/otoroshi/otoroshi.build @@ -0,0 +1,4 @@ +%section otoroshi-shell + CONFIG_OTOROSHI + CONFIG_OTOROSHI_SHELL + %inherit shell diff --git a/software/library/otoroshi/otoroshi.config b/software/library/otoroshi/otoroshi.config new file mode 100644 index 0000000000000000000000000000000000000000..63d81dcc0892d824c6d3e620e5cdff084b2cee54 --- /dev/null +++ b/software/library/otoroshi/otoroshi.config @@ -0,0 +1,16 @@ +%config CONFIG_OTOROSHI + parent CONFIG_BMAAA + desc Otoroshi utilities +%config end + +%config CONFIG_OTOROSHI_SHELL + parent CONFIG_OTOROSHI + desc Otoroshi shell commands +%config end + +%init INIT_OTOROSHI_STARTUP + parent CONFIG_OTOROSHI_SHELL + during INIT_DEVREADY + function otoroshi_startup + before INIT_MUTEK_SHELL_THREAD +%config end diff --git a/software/library/otoroshi/shell.c b/software/library/otoroshi/shell.c new file mode 100644 index 0000000000000000000000000000000000000000..c197903979a90d3ee6a1def7c1a3121bb7185fd8 --- /dev/null +++ b/software/library/otoroshi/shell.c @@ -0,0 +1,186 @@ +/* + This file is part of MutekH. + + MutekH is free software; you can redistribute it and/or modify it + under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation; version 2.1 of the + License. + + MutekH is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this program. If not, see + . + + Copyright Julien Peeters (c) 2016 +*/ + +#include +#include +#include + +#include +#include +#include +#include + +#include +#include +#include +#include + +#include + +#define FIRST STM32_PE8 +#define LAST STM32_PE15 + +static struct device_gpio_s gpio; +static struct device_timer_s timer; + +static dev_timer_delay_t msec; + +static uint8_t brain_gpio_init_mask[] = { 0x55, 0x55 }; + +void otoroshi_startup(void) +{ + printk("bmaaa: brain firmware started!\n"); + + ensure(!device_get_accessor_by_path(&gpio.base, NULL, "/gpio", DRIVER_CLASS_GPIO)); + ensure(!device_get_accessor_by_path(&timer.base, NULL, "/timer4", DRIVER_CLASS_TIMER)); + + ensure(!dev_timer_init_sec(&timer, &msec, 0, 1, 1000)); + + DEVICE_OP(&gpio, set_output, FIRST, LAST, brain_gpio_init_mask, dev_gpio_mask0); + DEVICE_OP(&gpio, set_mode, FIRST, LAST, dev_gpio_mask1, DEV_PIN_PUSHPULL); + dev_timer_busy_wait_delay(&timer, msec * 100); + DEVICE_OP(&gpio, set_output, FIRST, LAST, dev_gpio_mask0, dev_gpio_mask0); +} + +enum shell_otoroshi_opts_e +{ + OTOROSHI_OPT_RELAY = 0x1, + OTOROSHI_OPT_STATE = 0x2, + OTOROSHI_OPT_CLOSED = 0x4, + OTOROSHI_OPT_OPEN = 0x8, + OTOROSHI_OPT_PULSE = 0x10, + OTOROSHI_OPT_DELAY = 0x20, +}; + +struct termui_optctx_otoroshi_opts +{ + uint8_t relay; + bool_t state; + size_t delay; +}; + +static TERMUI_CON_COMMAND_PROTOTYPE(shell_otoroshi_relay) +{ + struct termui_optctx_otoroshi_opts * c = ctx; + + struct device_timer_s timer; + dev_timer_delay_t msec; + + struct device_gpio_s gpio; + + error_t err = 0; + + err = device_get_accessor_by_path(&gpio.base, NULL, "/gpio", DRIVER_CLASS_GPIO); + if (err) + return err; + + err = device_get_accessor_by_path(&timer.base, NULL, "/timer*", DRIVER_CLASS_TIMER); + if (err) + goto gpio_cleanup; + + err = dev_timer_init_sec(&timer, &msec, 0, 1, 1000); + if (err) + goto timer_cleanup; + + DEVICE_OP(&gpio, set_output, STM32_PE8, STM32_PE15, dev_gpio_mask0, dev_gpio_mask0); + DEVICE_OP(&gpio, set_mode, STM32_PE8, STM32_PE15, dev_gpio_mask1, DEV_PIN_PUSHPULL); + + if (used & OTOROSHI_OPT_PULSE) + { + uint8_t id = STM32_PE8 + c->relay * 2; + + static uint8_t door_open_mask[1] = { 0x2 }; + static uint8_t door_close_mask[1] = { 0x1 }; + + DEVICE_OP(&gpio, set_output, id, id + 1, door_open_mask, door_open_mask); + dev_timer_wait_delay(&timer, msec * 100, 0); + DEVICE_OP(&gpio, set_output, id, id, dev_gpio_mask0, dev_gpio_mask0); + + dev_timer_wait_delay(&timer, msec * c->delay, 0); + + DEVICE_OP(&gpio, set_output, id, id + 1, door_close_mask, door_close_mask); + dev_timer_wait_delay(&timer, msec * 100, 0); + DEVICE_OP(&gpio, set_output, id, id, dev_gpio_mask0, dev_gpio_mask0); + } + else + { + bool_t state = 0; + + if (used & OTOROSHI_OPT_STATE) + state = c->state; + else if (used & OTOROSHI_OPT_CLOSED) + state = 0; + else if (used & OTOROSHI_OPT_OPEN) + state = 1; + + uint8_t id = STM32_PE8 + c->relay * 2 + state; + DEVICE_OP(&gpio, set_output, id, id, dev_gpio_mask1, dev_gpio_mask1); + dev_timer_wait_delay(&timer, msec * 100, 0); + DEVICE_OP(&gpio, set_output, id, id, dev_gpio_mask0, dev_gpio_mask0); + } + +timer_cleanup: + device_put_accessor(&timer.base); +gpio_cleanup: + device_put_accessor(&gpio.base); + return err; +} + +static TERMUI_CON_OPT_DECL(otoroshi_opts) = +{ + TERMUI_CON_OPT_INTEGER_RANGE_ENTRY("-r", "--relay", OTOROSHI_OPT_RELAY, + struct termui_optctx_otoroshi_opts, relay, 1, 0, 3, + TERMUI_CON_OPT_CONSTRAINTS(OTOROSHI_OPT_RELAY, 0)) + + TERMUI_CON_OPT_INTEGER_RANGE_ENTRY("-s", "--state", OTOROSHI_OPT_STATE, + struct termui_optctx_otoroshi_opts, state, 1, 0, 1, + TERMUI_CON_OPT_CONSTRAINTS(OTOROSHI_OPT_STATE, OTOROSHI_OPT_RELAY)) + + TERMUI_CON_OPT_ENTRY("-c", "--closed", OTOROSHI_OPT_CLOSED, + TERMUI_CON_OPT_CONSTRAINTS(OTOROSHI_OPT_CLOSED | OTOROSHI_OPT_OPEN | OTOROSHI_OPT_STATE, + OTOROSHI_OPT_RELAY)) + + TERMUI_CON_OPT_ENTRY("-o", "--open", OTOROSHI_OPT_OPEN, + TERMUI_CON_OPT_CONSTRAINTS(OTOROSHI_OPT_CLOSED | OTOROSHI_OPT_OPEN | OTOROSHI_OPT_STATE, + OTOROSHI_OPT_RELAY)) + + TERMUI_CON_OPT_ENTRY("-p", "--pulse", OTOROSHI_OPT_PULSE, + TERMUI_CON_OPT_CONSTRAINTS(OTOROSHI_OPT_CLOSED | OTOROSHI_OPT_OPEN | OTOROSHI_OPT_STATE | OTOROSHI_OPT_PULSE, + OTOROSHI_OPT_RELAY)) + + TERMUI_CON_OPT_INTEGER_ENTRY("-d", "--delay", OTOROSHI_OPT_DELAY, + struct termui_optctx_otoroshi_opts, delay, 1, + TERMUI_CON_OPT_CONSTRAINTS(OTOROSHI_OPT_CLOSED | OTOROSHI_OPT_OPEN | OTOROSHI_OPT_STATE | OTOROSHI_OPT_DELAY, + OTOROSHI_OPT_RELAY | OTOROSHI_OPT_PULSE)) + + TERMUI_CON_LIST_END +}; + +static TERMUI_CON_GROUP_DECL(shell_otoroshi_subgroup) = +{ + TERMUI_CON_ENTRY(shell_otoroshi_relay, "relay", + TERMUI_CON_OPTS_CTX(otoroshi_opts, OTOROSHI_OPT_RELAY, + OTOROSHI_OPT_STATE | OTOROSHI_OPT_CLOSED | OTOROSHI_OPT_OPEN + | OTOROSHI_OPT_PULSE | OTOROSHI_OPT_DELAY, NULL)) + + TERMUI_CON_LIST_END +}; + +MUTEK_SHELL_ROOT_GROUP(shell_otoroshi_subgroup, "otoroshi"); diff --git a/software/tests/brain_relay/Makefile b/software/tests/brain_relay/Makefile index 5e5dfd33e332a8d267c1d5a3de8d39b77a17aa09..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 100644 --- a/software/tests/brain_relay/Makefile +++ b/software/tests/brain_relay/Makefile @@ -1,2 +0,0 @@ - -objs += main.o diff --git a/software/tests/brain_relay/config b/software/tests/brain_relay/config index e201545cfa567318c47c10461260f60850086382..43845c1f698c435dbf8ea388e1fe81b990b29710 100644 --- a/software/tests/brain_relay/config +++ b/software/tests/brain_relay/config @@ -1,9 +1,8 @@ - %set OUTPUT_NAME bmaaa-brain - %append MODULES $(OUTPUT_NAME):$(CONFIGPATH) +%set OUTPUT_NAME bmaaa-brain +%append MODULES $(OUTPUT_NAME):$(CONFIGPATH) - CONFIG_LICENSE_APP_BSD +CONFIG_LICENSE_APP_BSD - %include bmaaa.build - - CONFIG_PTHREAD - CONFIG_PTHREAD_MAIN +%inherit otoroshi-shell +%inherit bmaaa-brain +%include bmaaa.build diff --git a/software/tests/brain_relay/main.c b/software/tests/brain_relay/main.c deleted file mode 100644 index 789286b7427aba39f553129fff4d342036367b33..0000000000000000000000000000000000000000 --- a/software/tests/brain_relay/main.c +++ /dev/null @@ -1,30 +0,0 @@ -#include -#include - -#include - -#define FIRST STM32_PE8 -#define LAST STM32_PE15 - -static struct device_gpio_s gpio; -static struct device_timer_s timer; - -static dev_timer_delay_t msec; - -static uint8_t brain_gpio_init_mask[] = { 0x55, 0x55 }; - -void main() -{ - printk("bmaaa: brain firmware started!\n"); - - ensure(!device_get_accessor_by_path(&gpio.base, NULL, "/gpio", DRIVER_CLASS_GPIO)); - ensure(!device_get_accessor_by_path(&timer.base, NULL, "/timer4", DRIVER_CLASS_TIMER)); - - ensure(!dev_timer_init_sec(&timer, &msec, 0, 1, 1000)); - - DEVICE_OP(&gpio, set_output, FIRST, LAST, brain_gpio_init_mask, dev_gpio_mask0); - DEVICE_OP(&gpio, set_mode, FIRST, LAST, dev_gpio_mask1, DEV_PIN_PUSHPULL); - dev_timer_wait_delay(&timer, msec * 100, 0); - DEVICE_OP(&gpio, set_output, FIRST, LAST, dev_gpio_mask0, dev_gpio_mask0); -} -