diff options
author | AlejandroColomar <colomar.6.4.3@gmail.com> | 2019-01-13 01:01:19 +0100 |
---|---|---|
committer | AlejandroColomar <colomar.6.4.3@gmail.com> | 2019-01-13 01:01:19 +0100 |
commit | bd022f40f38535cb063f49ff18492d566f9c792b (patch) | |
tree | cc887c7f00d452cc2adf7ad0cd0a572c38eee0a0 | |
parent | bd6b90f6907f8f81ad04b61b082d841fb60f46e2 (diff) |
Restructure includes; Remove callbacks
-rw-r--r-- | Makefile | 2 | ||||
-rwxr-xr-x | inc/actuators.h | 2 | ||||
-rwxr-xr-x | inc/ctrl.h | 2 | ||||
-rwxr-xr-x | src/actuators.c | 87 | ||||
-rwxr-xr-x | src/ctrl.c | 85 | ||||
-rwxr-xr-x | src/main.c | 43 | ||||
-rwxr-xr-x | src/stm32l4xx_it.c | 1 | ||||
-rwxr-xr-x | src/test.c | 24 | ||||
m--------- | stm32l4-modules | 0 | ||||
-rwxr-xr-x | tmp/Makefile | 85 |
10 files changed, 131 insertions, 200 deletions
@@ -132,7 +132,7 @@ export SIZE # CFLAGS CFLAGS_STD = -std=c11 -#CFLAGS_OPT = -Os +CFLAGS_OPT = -Os CFLAGS_MCU = -mlittle-endian CFLAGS_MCU += -march=armv7e-m diff --git a/inc/actuators.h b/inc/actuators.h index 4baacc0..78379f4 100755 --- a/inc/actuators.h +++ b/inc/actuators.h @@ -34,7 +34,7 @@ ******* macros *************************************************************** ******************************************************************************/ # define ACT_REFRESH_PERIOD_US (20000u) - # define ACT_TASK_MODE_IT (false) + # define ACT_TASK_MODE_IT (true) /****************************************************************************** @@ -34,7 +34,7 @@ ******* macros *************************************************************** ******************************************************************************/ # define CTRL_REFRESH_PERIOD_US (20000u) - # define CTRL_TASK_MODE_IT (false) + # define CTRL_TASK_MODE_IT (true) /****************************************************************************** diff --git a/src/actuators.c b/src/actuators.c index 3f5dc93..92d8ea3 100755 --- a/src/actuators.c +++ b/src/actuators.c @@ -18,22 +18,21 @@ /****************************************************************************** ******* headers ************************************************************** ******************************************************************************/ -/* Standard C ----------------------------------------------------------------*/ #include <stdbool.h> #include <stddef.h> #include <stdint.h> -/* Drivers -------------------------------------------------------------------*/ + #include "stm32l4xx_hal.h" -/* libalx --------------------------------------------------------------------*/ + #include "libalx/alx_math.h" -/* STM32L4 modules -----------------------------------------------------------*/ - #include "can.h" - #include "delay.h" - #include "errors.h" - #include "led.h" - #include "servo.h" - #include "tim.h" -/* project -------------------------------------------------------------------*/ + + #include "stm32l4-modules/can.h" + #include "stm32l4-modules/delay.h" + #include "stm32l4-modules/errors.h" + #include "stm32l4-modules/led.h" + #include "stm32l4-modules/tim.h" + #include "stm32l4-modules/dev/servo.h" + #include "actuators.h" @@ -69,8 +68,6 @@ static float yaw; ******************************************************************************/ static int modules_init (void); static int modules_deinit (void); -static int proc_init (void); -static void proc_deinit (void); static int proc_actuators_it (void); static int proc_actuators_delay (void); static int proc_ref_read (void *data); @@ -97,16 +94,12 @@ int proc_actuators_init (void) if (modules_init()) { goto err_mod; } - if (proc_init()) { - goto err_proc; - } return ERROR_OK; -err_proc: - modules_deinit(); err_mod: + init_pending = true; return ERROR_NOK; } @@ -128,7 +121,6 @@ int proc_actuators_deinit (void) return status; } - proc_deinit(); if (modules_deinit()) { status = ERROR_NOK; } @@ -175,12 +167,6 @@ static int modules_init (void) goto err_delay; } - if (ACT_TASK_MODE_IT) { - if (tim_tim3_init(ACT_REFRESH_PERIOD_US)) { - goto err_tim; - } - } - if (can_init()) { goto err_can; } @@ -188,17 +174,23 @@ static int modules_init (void) goto err_servo; } + if (ACT_TASK_MODE_IT) { + if (tim_tim3_init(ACT_REFRESH_PERIOD_US)) { + goto err_tim; + } + } + return ERROR_OK; +err_tim: + servo_deinit(); err_servo: can_deinit(); err_can: delay_us_deinit(); err_delay: led_deinit(); - tim_tim3_deinit(); -err_tim: return ERROR_NOK; } @@ -226,39 +218,6 @@ static int modules_deinit (void) return status; } -static int proc_init (void) -{ - - if (ACT_TASK_MODE_IT) { - if (tim_callback_push(&proc_ref_read, NULL)) { - goto err_push; - } - if (tim_callback_push(&proc_actuators_set, NULL)) { - goto err_push; - } - - return ERROR_OK; - } else { - return ERROR_OK; - } - - -err_push: - proc_deinit(); - - return ERROR_NOK; -} - -static void proc_deinit (void) -{ - - if (ACT_TASK_MODE_IT) { - while (tim_callback_pop()) { - ; - } - } -} - static int proc_actuators_it (void) { @@ -267,9 +226,12 @@ static int proc_actuators_it (void) // __WFI(); if (tim_tim3_interrupt) { - if (tim_callback_exe()) { - return ERROR_NOK; + if (!proc_ref_read(NULL)) { + if (proc_actuators_set(NULL)) { + return ERROR_NOK; + } } + tim_tim3_interrupt = false; } } @@ -286,7 +248,6 @@ static int proc_actuators_delay (void) return ERROR_NOK; } } -//prj_error_handle(); } } @@ -22,22 +22,21 @@ /****************************************************************************** ******* headers ************************************************************** ******************************************************************************/ -/* Standard C ----------------------------------------------------------------*/ #include <stdbool.h> #include <stddef.h> #include <stdint.h> -/* Drivers -------------------------------------------------------------------*/ + #include "stm32l4xx_hal.h" -/* libalx --------------------------------------------------------------------*/ + #include "libalx/alx_math.h" -/* STM32L4 modules -----------------------------------------------------------*/ - #include "can.h" - #include "delay.h" - #include "errors.h" - #include "led.h" - #include "nunchuk.h" - #include "tim.h" -/* project -------------------------------------------------------------------*/ + + #include "stm32l4-modules/can.h" + #include "stm32l4-modules/delay.h" + #include "stm32l4-modules/errors.h" + #include "stm32l4-modules/led.h" + #include "stm32l4-modules/tim.h" + #include "stm32l4-modules/dev/nunchuk.h" + #include "ctrl.h" @@ -74,8 +73,6 @@ static bool level; ******************************************************************************/ static int modules_init (void); static int modules_deinit (void); -static int proc_init (void); -static void proc_deinit (void); static int proc_ctrl_it (void); static int proc_ctrl_delay (void); static int proc_ctrl_read (void *data); @@ -102,18 +99,14 @@ int proc_ctrl_init (void) if (modules_init()) { goto err_mod; } - if (proc_init()) { - goto err_proc; - } level = true; return ERROR_OK; -err_proc: - modules_deinit(); err_mod: + init_pending = true; return ERROR_NOK; } @@ -135,7 +128,6 @@ int proc_ctrl_deinit (void) return status; } - proc_deinit(); if (modules_deinit()) { status = ERROR_NOK; } @@ -182,12 +174,6 @@ static int modules_init (void) goto err_delay; } - if (CTRL_TASK_MODE_IT) { - if (tim_tim3_init(CTRL_REFRESH_PERIOD_US)) { - goto err_tim; - } - } - if (can_init()) { goto err_can; } @@ -195,17 +181,23 @@ static int modules_init (void) goto err_nunchuk; } + if (CTRL_TASK_MODE_IT) { + if (tim_tim3_init(CTRL_REFRESH_PERIOD_US)) { + goto err_tim; + } + } + return ERROR_OK; +err_tim: + nunchuk_deinit(); err_nunchuk: can_deinit(); err_can: delay_us_deinit(); err_delay: led_deinit(); - tim_tim3_deinit(); -err_tim: return ERROR_NOK; } @@ -234,39 +226,6 @@ static int modules_deinit (void) return status; } -static int proc_init (void) -{ - - if (CTRL_TASK_MODE_IT) { - if (tim_callback_push(&proc_ctrl_read, NULL)) { - goto err_push; - } - if (tim_callback_push(&proc_ctrl_report, NULL)) { - goto err_push; - } - - return ERROR_OK; - } else { - return ERROR_OK; - } - - -err_push: - proc_deinit(); - - return ERROR_NOK; -} - -static void proc_deinit (void) -{ - - if (CTRL_TASK_MODE_IT) { - while (tim_callback_pop()) { - ; - } - } -} - static int proc_ctrl_it (void) { @@ -275,9 +234,13 @@ static int proc_ctrl_it (void) // __WFI(); if (tim_tim3_interrupt) { - if (tim_callback_exe()) { + if (proc_ctrl_read(NULL)) { return ERROR_NOK; } + if (proc_ctrl_report(NULL)) { + return ERROR_NOK; + } + tim_tim3_interrupt = false; } } @@ -19,32 +19,29 @@ /****************************************************************************** ******* headers ************************************************************** ******************************************************************************/ -/* Standard C ----------------------------------------------------------------*/ #include <stdbool.h> #include <stdnoreturn.h> -/* Drivers -------------------------------------------------------------------*/ + #include "stm32l4xx_hal.h" -/* libalx --------------------------------------------------------------------*/ -/* STM32L4 modules -----------------------------------------------------------*/ - #include "can.h" - #include "clk.h" - #include "delay.h" - #include "display.h" - #include "errors.h" - #include "led.h" - #include "nunchuk.h" - #include "servo.h" - #include "tim.h" - - #include "can_test.h" - #include "display_test.h" - #include "led_test.h" - #include "nunchuk_test.h" - #include "servo_test.h" - #include "tim_test.h" -/* project -------------------------------------------------------------------*/ - #include "ctrl.h" + + #include "stm32l4-modules/can.h" + #include "stm32l4-modules/clk.h" + #include "stm32l4-modules/delay.h" + #include "stm32l4-modules/errors.h" + #include "stm32l4-modules/led.h" + #include "stm32l4-modules/tim.h" + #include "stm32l4-modules/dev/display.h" + #include "stm32l4-modules/dev/nunchuk.h" + #include "stm32l4-modules/dev/servo.h" + #include "stm32l4-modules/test/can_test.h" + #include "stm32l4-modules/test/display_test.h" + #include "stm32l4-modules/test/led_test.h" + #include "stm32l4-modules/test/nunchuk_test.h" + #include "stm32l4-modules/test/servo_test.h" + #include "stm32l4-modules/test/tim_test.h" + #include "actuators.h" + #include "ctrl.h" #include "test.h" @@ -53,7 +50,7 @@ ******************************************************************************/ # define DEBUG_MODE (false) - # define PROJECT_CTRL (true) + # define PROJECT_CTRL (false) # define PROJECT_ACT (!PROJECT_CTRL) diff --git a/src/stm32l4xx_it.c b/src/stm32l4xx_it.c index 6aade74..ade6457 100755 --- a/src/stm32l4xx_it.c +++ b/src/stm32l4xx_it.c @@ -39,6 +39,7 @@ /* Includes ------------------------------------------------------------------*/ #include <stdbool.h> + #include "stm32l4xx_hal.h" /******************************************************************************/ @@ -17,28 +17,22 @@ /****************************************************************************** ******* headers ************************************************************** ******************************************************************************/ -/* Standard C ----------------------------------------------------------------*/ #include <stdbool.h> #include <stddef.h> #include <stdint.h> -/* Drivers -------------------------------------------------------------------*/ #include "stm32l4xx_hal.h" -/* libalx --------------------------------------------------------------------*/ -/* STM32L4 modules -----------------------------------------------------------*/ - #include "delay.h" - #include "errors.h" - #include "led.h" + #include "stm32l4-modules/delay.h" + #include "stm32l4-modules/errors.h" + #include "stm32l4-modules/led.h" + #include "stm32l4-modules/test/can_test.h" + #include "stm32l4-modules/test/display_test.h" + #include "stm32l4-modules/test/led_test.h" + #include "stm32l4-modules/test/nunchuk_test.h" + #include "stm32l4-modules/test/servo_test.h" + #include "stm32l4-modules/test/tim_test.h" - #include "can_test.h" - #include "display_test.h" - #include "led_test.h" - #include "nunchuk_test.h" - #include "servo_test.h" - #include "tim_test.h" - -/* project -------------------------------------------------------------------*/ #include "test.h" diff --git a/stm32l4-modules b/stm32l4-modules -Subproject 83946ef2ec31ffdf8d9f07ae71028fa21e247d3 +Subproject 48d19e45b2220a40fa48c692c8d31dac5231374 diff --git a/tmp/Makefile b/tmp/Makefile index cc17390..e132ec8 100755 --- a/tmp/Makefile +++ b/tmp/Makefile @@ -10,10 +10,7 @@ LIBALX_INC_DIR = $(LIBALX_DIR)/inc/ STM32_CMSIS_INC_DIR = $(STM32_CMSIS_DIR)/Include/ STM32L4_CMSIS_INC_DIR = $(STM32L4_CMSIS_DIR)/Include/ STM32L4_HAL_INC_DIR = $(STM32L4_HAL_DIR)/Inc/ - -MODULES_BASE_INC_DIR = $(MODULES_DIR)/inc/ -MODULES_DEV_INC_DIR = $(MODULES_DIR)/inc/dev/ -MODULES_TST_INC_DIR = $(MODULES_DIR)/inc/test/ +MODULES_INC_DIR = $(MODULES_DIR)/inc/ SRC_DIR = $(MAIN_DIR)/src/ INC_DIR = $(MAIN_DIR)/inc/ @@ -50,72 +47,90 @@ IT_INC_DIRS = \ $(COMMON_INC_DIRS) -MAIN_INC_BASE = can.h clk.h delay.h errors.h led.h tim.h -MAIN_INC_DEV = display.h nunchuk.h servo.h -MAIN_INC_TST = \ - can_test.h led_test.h tim_test.h \ - display_test.h nunchuk_test.h servo_test.h +MAIN_INC_MOD = \ + stm32l4-modules/can.h \ + stm32l4-modules/clk.h \ + stm32l4-modules/delay.h \ + stm32l4-modules/errors.h \ + stm32l4-modules/led.h \ + stm32l4-modules/tim.h \ + stm32l4-modules/dev/display.h \ + stm32l4-modules/dev/nunchuk.h \ + stm32l4-modules/dev/servo.h \ + stm32l4-modules/test/can_test.h \ + stm32l4-modules/test/led_test.h \ + stm32l4-modules/test/tim_test.h \ + stm32l4-modules/test/display_test.h \ + stm32l4-modules/test/nunchuk_test.h \ + stm32l4-modules/test/servo_test.h MAIN_INC = ctrl.h actuators.h MAIN_DEPS = $(SRC_DIR)/main.c \ $(COMMON_DEPS) \ - $(patsubst %,$(MODULES_BASE_INC_DIR)/%,$(MAIN_INC_BASE)) \ - $(patsubst %,$(MODULES_DEV_INC_DIR)/%,$(MAIN_INC_DEV)) \ - $(patsubst %,$(MODULES_TST_INC_DIR)/%,$(MAIN_INC_TST)) \ + $(patsubst %,$(MODULES_INC_DIR)/%,$(MAIN_INC_MOD)) \ $(patsubst %,$(INC_DIR)/%,$(MAIN_INC)) MAIN_INC_DIRS = -I $(INC_DIR) \ - -I $(MODULES_BASE_INC_DIR) \ - -I $(MODULES_DEV_INC_DIR) \ - -I $(MODULES_TST_INC_DIR) \ + -I $(MODULES_INC_DIR) \ $(COMMON_INC_DIRS) CTRL_INC_LIBALX = libalx/alx_math.h -CTRL_INC_BASE = can.h delay.h errors.h led.h tim.h -CTRL_INC_DEV = nunchuk.h +CTRL_INC_MOD = \ + stm32l4-modules/can.h \ + stm32l4-modules/delay.h \ + stm32l4-modules/errors.h \ + stm32l4-modules/led.h \ + stm32l4-modules/tim.h \ + stm32l4-modules/dev/nunchuk.h +CTRL_INC_MOD = CTRL_INC = ctrl.h CTRL_DEPS = $(SRC_DIR)/ctrl.c \ $(COMMON_DEPS) \ $(patsubst %,$(LIBALX_INC_DIR)/%,$(CTRL_INC_LIBALX)) \ - $(patsubst %,$(MODULES_BASE_INC_DIR)/%,$(CTRL_INC_BASE)) \ - $(patsubst %,$(MODULES_DEV_INC_DIR)/%,$(CTRL_INC_DEV)) \ + $(patsubst %,$(MODULES_INC_DIR)/%,$(CTRL_INC_MOD)) \ $(patsubst %,$(INC_DIR)/%,$(CTRL_INC)) CTRL_INC_DIRS = -I $(INC_DIR) \ -I $(LIBALX_INC_DIR) \ - -I $(MODULES_BASE_INC_DIR) \ - -I $(MODULES_DEV_INC_DIR) \ + -I $(MODULES_INC_DIR) \ $(COMMON_INC_DIRS) ACT_INC_LIBALX = libalx/alx_math.h -ACT_INC_BASE = can.h delay.h errors.h led.h tim.h -ACT_INC_DEV = servo.h +ACT_INC_MOD = \ + stm32l4-modules/can.h \ + stm32l4-modules/delay.h \ + stm32l4-modules/errors.h \ + stm32l4-modules/led.h \ + stm32l4-modules/tim.h \ + stm32l4-modules/dev/servo.h ACT_INC = actuators.h ACT_DEPS = $(SRC_DIR)/actuators.c \ $(COMMON_DEPS) \ $(patsubst %,$(LIBALX_INC_DIR)/%,$(ACT_INC_LIBALX)) \ - $(patsubst %,$(MODULES_BASE_INC_DIR)/%,$(ACT_INC_BASE)) \ - $(patsubst %,$(MODULES_DEV_INC_DIR)/%,$(ACT_INC_DEV)) \ + $(patsubst %,$(MODULES_INC_DIR)/%,$(ACT_INC_MOD)) \ $(patsubst %,$(INC_DIR)/%,$(ACT_INC)) ACT_INC_DIRS = -I $(INC_DIR) \ -I $(LIBALX_INC_DIR) \ - -I $(MODULES_BASE_INC_DIR) \ - -I $(MODULES_DEV_INC_DIR) \ + -I $(MODULES_INC_DIR) \ $(COMMON_INC_DIRS) -TST_INC_BASE = delay.h errors.h led.h -TST_INC_TST = \ - can_test.h led_test.h tim_test.h \ - display_test.h nunchuk_test.h servo_test.h +TST_INC_MOD = \ + stm32l4-modules/delay.h \ + stm32l4-modules/errors.h \ + stm32l4-modules/led.h \ + stm32l4-modules/test/can_test.h \ + stm32l4-modules/test/led_test.h \ + stm32l4-modules/test/tim_test.h \ + stm32l4-modules/test/display_test.h \ + stm32l4-modules/test/nunchuk_test.h \ + stm32l4-modules/test/servo_test.h TST_INC = test.h TST_DEPS = $(SRC_DIR)/test.c \ $(COMMON_DEPS) \ - $(patsubst %,$(MODULES_BASE_INC_DIR)/%,$(TST_INC_BASE)) \ - $(patsubst %,$(MODULES_TST_INC_DIR)/%,$(TST_INC_TST)) \ + $(patsubst %,$(MODULES_INC_DIR)/%,$(TST_INC_MOD)) \ $(patsubst %,$(INC_DIR)/%,$(TST_INC)) TST_INC_DIRS = -I $(INC_DIR) \ - -I $(MODULES_BASE_INC_DIR) \ - -I $(MODULES_TST_INC_DIR) \ + -I $(MODULES_INC_DIR) \ $(COMMON_INC_DIRS) |