├── Source ├── Key │ ├── key_driver.c │ └── key_driver.h ├── Display │ ├── 新建文本文档.txt │ ├── display_device.c │ ├── display_device.h │ ├── display_driver.h │ └── display_driver.c ├── Task │ ├── task_open_loop.c │ ├── task_display.c │ ├── task_key.h │ ├── task_display.h │ ├── task_state_machine.h │ ├── task_open_loop.h │ ├── task_main.h │ ├── task_motor_control.h │ ├── task_key.c │ ├── task_state_machine.c │ └── task_main.c ├── Test │ ├── test_encoder.c │ ├── test_event.c │ ├── test_usart.c │ └── test_dispaly.c ├── User │ ├── user_flash.c │ ├── user_banner.h │ ├── user_state_machine.c │ ├── user_flash.h │ ├── user_state_machine.h │ ├── user_banner.c │ ├── user_config.h │ ├── motor_protocol.h │ ├── stm32f10x_it.h │ ├── main.c │ ├── stm32f10x_conf.h │ ├── motor_protocol.c │ ├── user_config.c │ └── stm32f10x_it.c ├── Doc │ └── pin_map ├── Scripts │ ├── copy_firmware.py │ ├── create_bin.bat │ └── copy_firmware.bat ├── Statemachine │ ├── state_machine.c │ └── state_machine.h ├── Bin │ ├── cygwin1.dll │ ├── hex2bin.exe │ ├── hextobin.bat │ ├── arm-elf-objcopy.exe │ └── axftobin.bat ├── Encoder │ ├── encoder_driver.h │ └── encoder_driver.c ├── Project │ └── MDK │ │ ├── ARMCC │ │ ├── script.bat │ │ ├── EventRecorderStub.scvd │ │ ├── RTE │ │ │ └── _PMSM │ │ │ │ └── RTE_Components.h │ │ ├── STM32F103CB-PMSM-BOOTLOADER.srt │ │ └── DebugConfig │ │ │ └── PMSM_STM32F103CB_1.0.0.dbgconf │ │ └── GCC │ │ ├── EventRecorderStub.scvd │ │ ├── RTE │ │ └── _PMSM │ │ │ └── RTE_Components.h │ │ ├── DebugConfig │ │ └── PMSM_STM32F103CB_1.0.0.dbgconf │ │ ├── syscalls.c │ │ └── Ld │ │ └── STM32F10X_MD.ld ├── Libraries │ ├── CMSIS │ │ ├── License.doc │ │ ├── CMSIS debug support.htm │ │ ├── Documentation │ │ │ └── CMSIS_Core.htm │ │ └── CM3 │ │ │ └── DeviceSupport │ │ │ └── ST │ │ │ └── STM32F10x │ │ │ ├── stm32f10x.h │ │ │ └── system_stm32f10x.h │ └── STM32F10x_StdPeriph_Driver │ │ ├── src │ │ ├── stm32f10x_i2c.c │ │ ├── stm32f10x_flash.c │ │ ├── stm32f10x_usart.c │ │ ├── stm32f10x_crc.c │ │ ├── stm32f10x_iwdg.c │ │ ├── stm32f10x_dbgmcu.c │ │ └── stm32f10x_wwdg.c │ │ └── inc │ │ ├── stm32f10x_crc.h │ │ ├── stm32f10x_wwdg.h │ │ ├── stm32f10x_dbgmcu.h │ │ ├── stm32f10x_iwdg.h │ │ ├── stm32f10x_rtc.h │ │ ├── stm32f10x_pwr.h │ │ ├── stm32f10x_cec.h │ │ └── stm32f10x_exti.h ├── Firmware │ ├── STM32F103CB-PMSM.bin │ └── STM32F103CB-PMSM.i64 ├── Foc │ ├── motor_control.c │ ├── motor_control.h │ └── foc.h ├── Control │ ├── velocity_curve.h │ ├── feed_forward.c │ ├── feed_forward.h │ └── velocity_curve.c ├── SVPWM │ ├── svpwm_driver.h │ └── svpwm_module.h ├── Feedback │ ├── position.h │ ├── current.h │ ├── encoder.h │ └── position.c ├── GwDebug │ ├── SDS.h │ ├── SDS.c │ └── gw_log.h ├── Usart │ └── usart_driver.h ├── GwOS │ ├── gw_hal.h │ ├── gw_timer.h │ ├── gw_timer.c │ ├── gw_fifo.h │ ├── gw_type.h │ ├── gw_list.h │ ├── gw_hal.c │ ├── gw_event.h │ ├── gw_tasks.h │ ├── gw_msgs.h │ ├── gw_fifo.c │ ├── gw_list.c │ ├── gw_event.c │ ├── gw_msgs.c │ └── gw_tasks.c └── Math │ └── svpwm_math.h ├── Res └── img │ ├── iaibidiq.png │ └── centeralign.png └── README.md /Source/Key/key_driver.c: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Source/Key/key_driver.h: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Source/Display/新建文本文档.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Source/Task/task_open_loop.c: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Source/Test/test_encoder.c: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Source/Test/test_event.c: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Source/Test/test_usart.c: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Source/User/user_flash.c: -------------------------------------------------------------------------------- 1 | #include "user_flash.h" 2 | 3 | -------------------------------------------------------------------------------- /Source/Doc/pin_map: -------------------------------------------------------------------------------- 1 | DLW 2 | DLV 3 | DLU 4 | DHW 5 | DHV 6 | DHU -------------------------------------------------------------------------------- /Source/Task/task_display.c: -------------------------------------------------------------------------------- 1 | #include "task_display.h" 2 | 3 | -------------------------------------------------------------------------------- /Source/Display/display_device.c: -------------------------------------------------------------------------------- 1 | #include "display_device.h" 2 | 3 | -------------------------------------------------------------------------------- /Source/Scripts/copy_firmware.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | import os 3 | import sys 4 | 5 | -------------------------------------------------------------------------------- /Source/Statemachine/state_machine.c: -------------------------------------------------------------------------------- 1 | #include "state_machine.h" 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Source/Task/task_key.h: -------------------------------------------------------------------------------- 1 | #ifndef TASK_KEY_H 2 | #define TASK_KEY_H 3 | 4 | #endif 5 | -------------------------------------------------------------------------------- /Source/Task/task_display.h: -------------------------------------------------------------------------------- 1 | #ifndef TASK_DISPALY_H 2 | #define TASK_DISPALY_H 3 | 4 | #endif 5 | -------------------------------------------------------------------------------- /Res/img/iaibidiq.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hotsauce1861/STM32-PMSM/HEAD/Res/img/iaibidiq.png -------------------------------------------------------------------------------- /Source/Bin/cygwin1.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hotsauce1861/STM32-PMSM/HEAD/Source/Bin/cygwin1.dll -------------------------------------------------------------------------------- /Source/Bin/hex2bin.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hotsauce1861/STM32-PMSM/HEAD/Source/Bin/hex2bin.exe -------------------------------------------------------------------------------- /Res/img/centeralign.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hotsauce1861/STM32-PMSM/HEAD/Res/img/centeralign.png -------------------------------------------------------------------------------- /Source/Bin/hextobin.bat: -------------------------------------------------------------------------------- 1 | if exist .\..\STM3210B-EVAL\*.hex (.\hex2bin.exe .\..\STM3210B-EVAL\*.hex ) 2 | exit 3 | -------------------------------------------------------------------------------- /Source/Display/display_device.h: -------------------------------------------------------------------------------- 1 | #ifndef DISPLAY_DEVICE_H 2 | #define DISPLAY_DEVICE_H 3 | 4 | 5 | #endif 6 | -------------------------------------------------------------------------------- /Source/Encoder/encoder_driver.h: -------------------------------------------------------------------------------- 1 | #ifndef __ENCODER_DRIVER_H 2 | #define __ENCODER_DRIVER_H 3 | 4 | #endif 5 | -------------------------------------------------------------------------------- /Source/Task/task_state_machine.h: -------------------------------------------------------------------------------- 1 | #ifndef TASK_STATE_MACHINE_H 2 | #define TASK_STATE_MACHINE_H 3 | 4 | #endif 5 | -------------------------------------------------------------------------------- /Source/Bin/arm-elf-objcopy.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hotsauce1861/STM32-PMSM/HEAD/Source/Bin/arm-elf-objcopy.exe -------------------------------------------------------------------------------- /Source/Project/MDK/ARMCC/script.bat: -------------------------------------------------------------------------------- 1 | XCOPY /Y /S /F .\Out\obj\*.hex .\ 2 | XCOPY /Y /S /F .\Out\obj\*.hex C:\Users\zhaoj\ -------------------------------------------------------------------------------- /Source/Libraries/CMSIS/License.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hotsauce1861/STM32-PMSM/HEAD/Source/Libraries/CMSIS/License.doc -------------------------------------------------------------------------------- /Source/Firmware/STM32F103CB-PMSM.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hotsauce1861/STM32-PMSM/HEAD/Source/Firmware/STM32F103CB-PMSM.bin -------------------------------------------------------------------------------- /Source/Firmware/STM32F103CB-PMSM.i64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hotsauce1861/STM32-PMSM/HEAD/Source/Firmware/STM32F103CB-PMSM.i64 -------------------------------------------------------------------------------- /Source/User/user_banner.h: -------------------------------------------------------------------------------- 1 | #ifndef USER_BANNER_H 2 | #define USER_BANNER_H 3 | 4 | void user_banner_show(void); 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /Source/Libraries/CMSIS/CMSIS debug support.htm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hotsauce1861/STM32-PMSM/HEAD/Source/Libraries/CMSIS/CMSIS debug support.htm -------------------------------------------------------------------------------- /Source/Libraries/CMSIS/Documentation/CMSIS_Core.htm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hotsauce1861/STM32-PMSM/HEAD/Source/Libraries/CMSIS/Documentation/CMSIS_Core.htm -------------------------------------------------------------------------------- /Source/Foc/motor_control.c: -------------------------------------------------------------------------------- 1 | #include "motor_control.h" 2 | 3 | 4 | 5 | void motor_run(void){ 6 | 7 | } 8 | 9 | void motor_stop(void){ 10 | 11 | } 12 | 13 | 14 | -------------------------------------------------------------------------------- /Source/Task/task_open_loop.h: -------------------------------------------------------------------------------- 1 | #ifndef TASK_OPEN_LOOP_H 2 | #define TASK_OPEN_LOOP_H 3 | 4 | void task_openloop_init(void); 5 | void task_openloop_create(void); 6 | 7 | #endif -------------------------------------------------------------------------------- /Source/Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_i2c.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hotsauce1861/STM32-PMSM/HEAD/Source/Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_i2c.c -------------------------------------------------------------------------------- /Source/Libraries/CMSIS/CM3/DeviceSupport/ST/STM32F10x/stm32f10x.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hotsauce1861/STM32-PMSM/HEAD/Source/Libraries/CMSIS/CM3/DeviceSupport/ST/STM32F10x/stm32f10x.h -------------------------------------------------------------------------------- /Source/Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_flash.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hotsauce1861/STM32-PMSM/HEAD/Source/Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_flash.c -------------------------------------------------------------------------------- /Source/Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_usart.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hotsauce1861/STM32-PMSM/HEAD/Source/Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_usart.c -------------------------------------------------------------------------------- /Source/Encoder/encoder_driver.c: -------------------------------------------------------------------------------- 1 | #include "encoder_driver.h" 2 | 3 | static void rcc_init(void){ 4 | 5 | } 6 | 7 | static void gpio_init(void){ 8 | 9 | } 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /Source/Task/task_main.h: -------------------------------------------------------------------------------- 1 | #ifndef TASK_MAIN_H 2 | #define TASK_MAIN_H 3 | 4 | void task_system_init(void); 5 | void task_bsp_init(void); 6 | void task_init(void); 7 | void task_create(void); 8 | void task_main(void); 9 | 10 | #endif 11 | 12 | -------------------------------------------------------------------------------- /Source/Control/velocity_curve.h: -------------------------------------------------------------------------------- 1 | #ifndef VELOCITY_CURE_H 2 | #define VELOCITY_CURE_H 3 | #include 4 | 5 | int16_t t_curve(int16_t a, int16_t t,int16_t p0,int16_t vm, int16_t v); 6 | int16_t s_curve(int16_t a, int16_t t, int16_t spd); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /Source/Foc/motor_control.h: -------------------------------------------------------------------------------- 1 | #ifndef MOTOR_CONTROL_H 2 | #define MOTOR_CONTROL_H 3 | #include 4 | 5 | struct motor_module{ 6 | int16_t pair_num; 7 | }; 8 | typedef struct motor_module motor_module_typedef; 9 | 10 | void motor_run(void); 11 | void motor_stop(void); 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /Source/Scripts/create_bin.bat: -------------------------------------------------------------------------------- 1 | echo %cd% 2 | set ROOT_PATH=.\..\.. 3 | set OUT_NAME=firmware.bin 4 | 5 | set SRC=%ROOT_PATH%\..\Project\MDK\ARMCC\Out\obj\*.hex 6 | set TOOL=%ROOT_PATH%\..\Bin\hex2bin.exe 7 | set DST=%ROOT_PATH%\..\Firmware\%OUT_NAME% 8 | 9 | if exist %SRC% (%TOOL% %SRC%) 10 | exit -------------------------------------------------------------------------------- /Source/Statemachine/state_machine.h: -------------------------------------------------------------------------------- 1 | #ifndef STATE_MACHINE_h 2 | #define STATE_MACHINE_h 3 | 4 | 5 | #include 6 | 7 | 8 | enum state_mod{ 9 | IDLE = 0x0001U, 10 | STOP = 0x0010U, 11 | ANY_STOP = 0x0020U, 12 | STOP_IDLE = 0x0030U, 13 | 14 | }; 15 | 16 | typedef enum state_mod moto_state_t; 17 | 18 | 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /Source/Scripts/copy_firmware.bat: -------------------------------------------------------------------------------- 1 | echo %cd% 2 | set ROOT_PATH=.\..\.. 3 | set HEX_FILE=%ROOT_PATH%\..\Project\MDK\ARMCC\Out\obj\*.hex 4 | set BIN_FILE=%ROOT_PATH%\..\Project\MDK\ARMCC\Out\obj\*.bin 5 | set DST_DIR=%ROOT_PATH%\..\Firmware\ 6 | if exist %HEX_FILE% (XCOPY /Y /S /F %HEX_FILE% %DST_DIR%) 7 | if exist %BIN_FILE% (XCOPY /Y /S /F %BIN_FILE% %DST_DIR%) 8 | exit -------------------------------------------------------------------------------- /Source/Control/feed_forward.c: -------------------------------------------------------------------------------- 1 | #include "feed_forward.h" 2 | 3 | int16_t ff_calc_result(ff_mod_t *ff){ 4 | 5 | int16_t result = 0; 6 | result = ff->a_factor*(ff->ein - ff->last_ein) 7 | + ff->b_factor*(ff->ein - 2*ff->last_ein + ff->last_last_ein); 8 | 9 | ff->last_last_ein = ff->last_ein; 10 | ff->last_ein = ff->ein; 11 | 12 | return result; 13 | } 14 | -------------------------------------------------------------------------------- /Source/Project/MDK/ARMCC/EventRecorderStub.scvd: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /Source/Project/MDK/GCC/EventRecorderStub.scvd: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /Source/Project/MDK/GCC/RTE/_PMSM/RTE_Components.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Auto generated Run-Time-Environment Component Configuration File 4 | * *** Do not modify ! *** 5 | * 6 | * Project: 'STM32F103CB-PMSM' 7 | * Target: 'PMSM' 8 | */ 9 | 10 | #ifndef RTE_COMPONENTS_H 11 | #define RTE_COMPONENTS_H 12 | 13 | 14 | /* 15 | * Define the Device Header File: 16 | */ 17 | #define CMSIS_device_header "stm32f10x.h" 18 | 19 | 20 | #endif /* RTE_COMPONENTS_H */ 21 | -------------------------------------------------------------------------------- /Source/Control/feed_forward.h: -------------------------------------------------------------------------------- 1 | #ifndef FEED_FORWARD_H 2 | #define FEED_FORWARD_H 3 | #include 4 | 5 | //https://www.cnblogs.com/foxclever/p/9311124.html 6 | struct ff_mod{ 7 | int16_t ein; 8 | int16_t last_ein; 9 | int16_t last_last_ein; 10 | 11 | int16_t result; 12 | //Gff(s) = as^2 + bs 13 | int16_t a_factor; 14 | int16_t b_factor; 15 | }; 16 | 17 | typedef struct ff_mod ff_mod_t; 18 | 19 | int16_t ff_calc_result(ff_mod_t *ff); 20 | 21 | #endif 22 | -------------------------------------------------------------------------------- /Source/Project/MDK/ARMCC/RTE/_PMSM/RTE_Components.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * Auto generated Run-Time-Environment Component Configuration File 4 | * *** Do not modify ! *** 5 | * 6 | * Project: 'STM32F103CB-PMSM' 7 | * Target: 'PMSM' 8 | */ 9 | 10 | #ifndef RTE_COMPONENTS_H 11 | #define RTE_COMPONENTS_H 12 | 13 | 14 | /* 15 | * Define the Device Header File: 16 | */ 17 | #define CMSIS_device_header "stm32f10x.h" 18 | 19 | 20 | #endif /* RTE_COMPONENTS_H */ 21 | -------------------------------------------------------------------------------- /Source/Control/velocity_curve.c: -------------------------------------------------------------------------------- 1 | #include "velocity_curve.h" 2 | 3 | int16_t t_curve(int16_t a, int16_t t,int16_t p0,int16_t vm, int16_t v){ 4 | 5 | static uint8_t step = 0; 6 | 7 | switch (step) 8 | { 9 | case 0: 10 | if(v>=vm){ 11 | step = 1; 12 | } 13 | break; 14 | case 1: 15 | break; 16 | case 2: 17 | break; 18 | } 19 | return 0; 20 | } 21 | 22 | int16_t s_curve(int16_t a, int16_t t, int16_t spd){ 23 | 24 | return 0; 25 | } 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /Source/Test/test_dispaly.c: -------------------------------------------------------------------------------- 1 | #include "task_display.h" 2 | #include "user_config.h" 3 | #include "gw_tasks.h" 4 | 5 | void task_display_init(void); 6 | void task_display(void* args); 7 | 8 | void task_display_create(void){ 9 | gw_task_args_create("display", TASK_ID_DISPLAY, 10 | TYPE_POLL, GW_DISABLE, 5, 11 | task_display_init, 12 | task_display); 13 | } 14 | 15 | void task_display_init(void){ 16 | 17 | } 18 | 19 | void task_display(void* args){ 20 | 21 | } 22 | 23 | 24 | -------------------------------------------------------------------------------- /Source/SVPWM/svpwm_driver.h: -------------------------------------------------------------------------------- 1 | #ifndef SVPWM_DRIVER_H 2 | #define SVPWM_DRIVER_H 3 | #include 4 | 5 | #define PWM_DUTY 50L // 0--100 6 | #define PWM_MAX_LIMIT 98L 7 | #define PWM_FRQ 10000L 8 | #define SYS_FRQ 72000000L 9 | 10 | void pwm_init(void); 11 | void pwm_reset_duty_cnt(uint8_t index, int16_t cnt); 12 | int32_t get_pwm_period(void); 13 | void pwm_disable(void); 14 | void pwm_enable(void); 15 | uint16_t pwm_get_max_limit(void); 16 | uint16_t get_pwm_limit_period(void); 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /Source/Project/MDK/ARMCC/STM32F103CB-PMSM-BOOTLOADER.srt: -------------------------------------------------------------------------------- 1 | ; ************************************************************* 2 | ; *** Scatter-Loading Description File generated by uVision *** 3 | ; ************************************************************* 4 | 5 | LR_IROM1 0x08003000 0x0001D000 { ; load region size_region 6 | ER_IROM1 0x08003000 0x0001D000 { ; load address = execution address 7 | *.o (RESET, +First) 8 | *(InRoot$$Sections) 9 | .ANY (+RO) 10 | .ANY (+XO) 11 | } 12 | RW_IRAM1 0x20000000 0x00005000 { ; RW data 13 | .ANY (+RW +ZI) 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Source/Feedback/position.h: -------------------------------------------------------------------------------- 1 | #ifndef POSITION_H 2 | #define POSITION_H 3 | #include 4 | 5 | /** 6 | PHA--->PB0 7 | PHB--->PB1 8 | PHC--->PB2 9 | */ 10 | 11 | #define PHA GPIO_Pin_0 12 | #define PHB GPIO_Pin_1 13 | #define PHC GPIO_Pin_2 14 | 15 | extern int16_t phase_signal_angle_matrix[6]; 16 | 17 | //初始化电角三相信号的状态值 18 | #define INIT_PHA_VALUE 1 19 | #define INIT_PHB_VALUE 1 20 | #define INIT_PHC_VALUE 0 21 | 22 | typedef void (*PFUNC)(void*); //到达初始位置时候回调函数 23 | 24 | uint8_t get_pos_rotor(void); 25 | uint8_t get_pos_rotor_2(void); 26 | uint8_t get_pos_rotor_3(void); 27 | void pos_init(void); 28 | void pos_set_cbk(PFUNC p,void *pargs); 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /Source/Display/display_driver.h: -------------------------------------------------------------------------------- 1 | #ifndef __DISPLAY_DRIVER_H 2 | #define __DISPLAY_DRIVER_H 3 | 4 | #include 5 | 6 | struct dirver_74hc595 { 7 | uint8_t sck; //serial clock 8 | uint8_t rck; 9 | uint8_t sdi; //serial_data_input 10 | // hardware spec 11 | // pin out interface 12 | void (*init)(struct dirver_74hc595*); 13 | 14 | void (*write)(struct dirver_74hc595*, uint8_t); 15 | void (*output_sck)(uint8_t); 16 | void (*output_rck)(uint8_t); 17 | void (*output_sdi)(uint8_t); 18 | }; 19 | #if 0 20 | void hc595_init(struct dirver_74hc595* pdev); 21 | void hc595_write(struct dirver_74hc595* pdev, uint8_t data); 22 | void hc595_output(struct dirver_74hc595* pdev); 23 | #endif 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /Source/User/user_state_machine.c: -------------------------------------------------------------------------------- 1 | #include "user_state_machine.h" 2 | 3 | state_machine_mod_t motor_state; 4 | 5 | static state_e ustm_get_cur_state(void); 6 | static void ustm_set_next_state(state_e e); 7 | 8 | void state_machine_init(state_machine_mod_t* sm){ 9 | sm->state = IDLE; 10 | sm->super = sm; 11 | sm->get_cur_state = ustm_get_cur_state; 12 | sm->set_next_state = ustm_set_next_state; 13 | } 14 | 15 | static state_e ustm_get_cur_state(void){ 16 | return IDLE; 17 | } 18 | 19 | static void ustm_set_next_state(state_e e){ 20 | 21 | } 22 | 23 | state_e stm_get_cur_state(state_machine_mod_t* pstm){ 24 | return pstm->state; 25 | } 26 | 27 | void stm_set_next_state(state_machine_mod_t* pstm, state_e e){ 28 | pstm->state = e; 29 | } 30 | 31 | -------------------------------------------------------------------------------- /Source/Task/task_motor_control.h: -------------------------------------------------------------------------------- 1 | #ifndef TASK_MOTOR_CONTORL_H 2 | #define TASK_MOTOR_CONTORL_H 3 | 4 | #include "current.h" 5 | #include "svpwm_math.h" 6 | 7 | void task_motor_stop(void); 8 | void task_motor_pwm_enable(void); 9 | 10 | void task_motor_control_init(void); 11 | void task_motor_control(void* args); 12 | 13 | extern void task_motor_cur_loop(Curr_Components cur_ab); 14 | 15 | extern void task_motor_startup(Curr_Components cur_ab,uint16_t timeout); 16 | extern void task_motor_startup_02(Curr_Components cur_ab,uint16_t timeout);//不理想 17 | extern void task_motor_startup_03(Curr_Components cur_ab,uint16_t timeout);//不理想 18 | extern void task_motor_startup_04(Curr_Components cur_ab,uint16_t timeout); 19 | extern void task_motor_startup_05(Curr_Components cur_ab,uint16_t timeout); 20 | #endif 21 | -------------------------------------------------------------------------------- /Source/GwDebug/SDS.h: -------------------------------------------------------------------------------- 1 | /************************************************************************** 2 | Module Name: Serial Digital Scope Module 3 | Module Date: 2013/4/2 4 | Module Auth: XiaoGo_O Modulated 5 | Description: Serial Digital Scope For XS128 6 | Others: Modulate for S12XS128 112PINS. 7 | DEBUG SUCCESS IN 2013/4/7 8 | in 32M Bus Speed. 9 | Revision History: 10 | 11 | WARN! 12 | SRS.c depend on USART 13 | please ensure that uart_putchar() has been implemented 14 | Ensure that SCI has been configured in 9600bps mode. 15 | **************************************************************************/ 16 | #ifndef SDS_outputdata_H 17 | #define SDS_outputdata_H 18 | /*------------------------------------Extern Variables------------------------------------*/ 19 | void SDS_OutPut_Data(float S_Out[]); 20 | void SDS_OutPut_Data_INT(int S_Out[]); 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /Source/User/user_flash.h: -------------------------------------------------------------------------------- 1 | #ifndef USER_FLASH_H 2 | #define USER_FLASH_H 3 | #include 4 | 5 | #define FLASH_PAGE_SIZE ((uint16_t)0x400) 6 | 7 | #define BANK1_WRITE_START_ADDR ((uint32_t)0x0801E000) 8 | #define BANK1_WRITE_END_ADDR ((uint32_t)0x08020000) 9 | 10 | #define PID_CUR_KP_ADDR ((uint16_t)0x0004) 11 | #define PID_CUR_KI_ADDR ((uint16_t)0x0008) 12 | #define PID_CUR_KD_ADDR ((uint16_t)0x000C) 13 | 14 | #define PID_SPD_KP_ADDR ((uint16_t)0x0010) 15 | #define PID_SPD_KI_ADDR ((uint16_t)0x0014) 16 | #define PID_SPD_KD_ADDR ((uint16_t)0x0018) 17 | 18 | #define PID_POS_KP_ADDR ((uint16_t)0x001C) 19 | #define PID_POS_KI_ADDR ((uint16_t)0x0020) 20 | #define PID_POS_KD_ADDR ((uint16_t)0x0024) 21 | 22 | #define FF_FACTOR_A ((uint16_t)0x0028) 23 | #define FF_FACTOR_B ((uint16_t)0x002C) 24 | 25 | void user_flash_clear_all_data(void); 26 | void user_flash_earse_page(uint16_t index); 27 | 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /Source/SVPWM/svpwm_module.h: -------------------------------------------------------------------------------- 1 | #ifndef _SVPWM_MODULE_H 2 | #define _SVPWM_MODULE_H 3 | #include 4 | #include "svpwm_math.h" 5 | 6 | struct svpwm_mod { 7 | 8 | //确定转子象限 9 | int16_t Udc; 10 | int32_t sector; 11 | //克拉克变换OAB坐标 12 | int16_t UAlpha; //输入,静止坐标系Alpha轴定子电压 13 | int16_t UBeta; //输入,静止坐标系Beta轴定子电压 14 | int16_t pwm_period; 15 | uint16_t Tcm1; //A相打开的时间 16 | uint16_t Tcm2; //B相打开的时间 17 | uint16_t Tcm3; //C相打开的时间 18 | int16_t Angle; 19 | uint16_t Tpwm; 20 | int32_t Ua; 21 | int32_t Ub; 22 | 23 | }; 24 | 25 | typedef struct svpwm_mod svpwm_mod_t; 26 | 27 | void svpwm_init(void); 28 | //uint16_t swpwm_setphase_vol( struct svpwm_mod *pHandle , Volt_Components Valfa_beta ); 29 | void svpwm_main_run1(struct svpwm_mod* const svpwm); 30 | void svpwm_main_run2(struct svpwm_mod* const svpwm); 31 | void svpwm_get_sector(struct svpwm_mod* const svpwm); 32 | void svpwm_reset_pwm_duty(struct svpwm_mod* const svpwm); 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /Source/User/user_state_machine.h: -------------------------------------------------------------------------------- 1 | #ifndef USER_STATE_MACHINE_H 2 | #define USER_STATE_MACHINE_H 3 | 4 | //ERROR CODE 5 | #define ERROR_OVER_VOLT 0x0001 6 | 7 | 8 | typedef enum { 9 | IDLE = 0x00, 10 | START_UP = 0x01, 11 | RUN = 0x02, 12 | STOP = 0x03, 13 | WAIT = 0x04, 14 | FAULT = 0x05, 15 | TEST = 0x06 16 | }state_e; 17 | 18 | typedef state_e (*hcbk_get_cur_state)(void); 19 | typedef void (*hcbk_set_next_state)(state_e); 20 | 21 | 22 | struct state_machine_mod{ 23 | 24 | struct state_machine_mod* super; 25 | state_e state; 26 | 27 | hcbk_get_cur_state get_cur_state; 28 | hcbk_set_next_state set_next_state; 29 | 30 | }; 31 | 32 | typedef struct state_machine_mod state_machine_mod_t; 33 | 34 | extern state_machine_mod_t motor_state; 35 | 36 | void state_machine_init(state_machine_mod_t* sm); 37 | 38 | state_e stm_get_cur_state(state_machine_mod_t* pstm); 39 | void stm_set_next_state(state_machine_mod_t* pstm, state_e e); 40 | 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # STM32-PMSM ![](./QPano3/Resources/bt428.svg) ![](./QPano3/Resources/plug.svg) 2 | Project of driving permanent magnet synchronous motor based on STM32F103XXX. 3 | 4 | If you think this project has helped you, please give me a star, which is the greatest encouragement to me. 5 | 6 | ## Tree of source 7 | . 8 | ├── Bin 9 | ├── Control 10 | ├── Display 11 | ├── Doc 12 | ├── Encoder 13 | ├── Feedback 14 | ├── Firmware 15 | ├── Foc 16 | ├── GwDebug 17 | ├── GwOS 18 | ├── Key 19 | ├── Libraries 20 | ├── Math 21 | ├── Pid 22 | ├── Project 23 | ├── Scripts 24 | ├── Statemachine 25 | ├── SVPWM 26 | ├── Task 27 | ├── Test 28 | ├── Usart 29 | └── User 30 | 31 | ||| 32 | |---|---| 33 | |Bin| Tools for change file format | 34 | |Control| Source of control motor | 35 | |Display| Interface of Display | 36 | |Encoder| Driver of Encoder | 37 | |Feedback|Adc for current and get \theta elec | 38 | |Firmware|Build project will create bin file and hex file in this directory| 39 | |Foc| Interface of Foc | 40 | 41 | 42 | ## 简介 43 | 基于`stm32`驱动永磁同步电机的项目,`FOC`磁场矢量控制算法,双电阻采样,双闭环PI控制 44 | 45 | 果你觉得该项目帮助到了你,请给我一颗星星,这是对我最大的鼓励。 46 | -------------------------------------------------------------------------------- /Source/Bin/axftobin.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | if exist C:\Keil\ARM\BIN40\fromelf.exe ( 4 | if exist .\..\MDK-ARM\STM32100B-EVAL\STM32100B-EVAL.axf (C:\Keil\ARM\BIN40\fromelf.exe ".\..\MDK-ARM\STM32100B-EVAL\STM32100B-EVAL.axf" --bin --output ".\STM32100B-EVAL_SysTick.bin") 5 | if exist .\..\MDK-ARM\STM3210C-EVAL\STM3210C-EVAL.axf (C:\Keil\ARM\BIN40\fromelf.exe ".\..\MDK-ARM\STM3210C-EVAL\STM3210C-EVAL.axf" --bin --output ".\STM3210C-EVAL_SysTick.bin") 6 | if exist .\..\MDK-ARM\STM3210B-EVAL\STM3210B-EVAL.axf (C:\Keil\ARM\BIN40\fromelf.exe ".\..\MDK-ARM\STM3210B-EVAL\STM3210B-EVAL.axf" --bin --output ".\STM3210B-EVAL_SysTick.bin") 7 | if exist .\..\MDK-ARM\STM3210E-EVAL\STM3210E-EVAL.axf (C:\Keil\ARM\BIN40\fromelf.exe ".\..\MDK-ARM\STM3210E-EVAL\STM3210E-EVAL.axf" --bin --output ".\STM3210E-EVAL_SysTick.bin") 8 | if exist .\..\MDK-ARM\STM3210E-EVAL_XL\STM3210E-EVAL_XL.axf (C:\Keil\ARM\BIN40\fromelf.exe ".\..\MDK-ARM\STM3210E-EVAL_XL\STM3210E-EVAL_XL.axf" --bin --output ".\STM3210E-EVAL_XL_SysTick.bin") 9 | if exist .\..\MDK-ARM\STM32100E-EVAL\STM32100E-EVAL.axf (C:\Keil\ARM\BIN40\fromelf.exe ".\..\MDK-ARM\STM32100E-EVAL\STM32100E-EVAL.axf" --bin --output ".\STM32100E-EVAL_SysTick.bin") 10 | 11 | ) 12 | 13 | pause 14 | 15 | -------------------------------------------------------------------------------- /Source/Task/task_key.c: -------------------------------------------------------------------------------- 1 | #include "task_key.h" 2 | #include "user_config.h" 3 | #include "gw_tasks.h" 4 | 5 | void task_key_init(void); 6 | void task_key(void* args); 7 | 8 | void task_key_create(void){ 9 | gw_task_args_create("display", TASK_ID_KEY, 10 | TYPE_POLL, GW_DISABLE, 5, 11 | task_key_init, 12 | task_key); 13 | } 14 | 15 | void task_key_init(void){ 16 | 17 | } 18 | 19 | void task_key(void* args){ 20 | struct gw_event *pev = (struct gw_event *)args; 21 | gw_msg_fifo_t * const pmsg_fifo = &msg_fifo; 22 | gw_msg_t msg; 23 | if(gw_msg_receive(pev->id, pmsg_fifo, &msg) == GW_TRUE){ 24 | /** 25 | TODO 26 | */ 27 | printf("%016d: name:[%s] id:[%d] msg:[%s]\n", pev->g_timer->timestamp, 28 | pev->name, pev->id,(uint8_t*)msg.pstr); 29 | } 30 | 31 | pev->msg.pstr = "MSG from task_04: Hello I am task 04"; 32 | 33 | if(gw_msg_send_msg(TASK_ID_MOTOR, pmsg_fifo, &pev->msg) == GW_TRUE){ 34 | /** 35 | TODO 36 | */ 37 | } 38 | 39 | if(gw_msg_send_msg(TASK_ID_DISPLAY, pmsg_fifo, &pev->msg) == GW_TRUE){ 40 | /** 41 | TODO 42 | */ 43 | } 44 | 45 | } 46 | 47 | -------------------------------------------------------------------------------- /Source/User/user_banner.c: -------------------------------------------------------------------------------- 1 | #include "user_banner.h" 2 | #include "usart_driver.h" 3 | 4 | void user_banner_show(void){ 5 | 6 | usart_printf(" \r\n ============== PMSM Version 0.01 =============="); 7 | 8 | usart_printf("\r\n ____ __ ________ __ ___ "); 9 | usart_printf("\r\n / __ \\/ |/ / ___// |/ / "); 10 | usart_printf("\r\n / /_/ / /|_/ /\\__ \\/ /|_/ / "); 11 | usart_printf("\r\n / ____/ / / /___/ / / / / "); 12 | usart_printf("\r\n /_/ /_/ /_//____/_/ /_/ "); 13 | usart_printf("\r\n"); 14 | usart_printf("\r\n __ __ __"); 15 | usart_printf("\r\n / /_ ____ ____ ____ ______/ /_ ___ ____ ____ ____ / /__ _________ ____ ___"); 16 | usart_printf("\r\n / __ \\/ __ \\/ __ \\/ __ `/ ___/ __ \\/ _ \\/ __ \\/ __ `/ _ \\/ / _ \\ / ___/ __ \\/ __ `__ \\"); 17 | usart_printf("\r\n / / / / /_/ / / / / /_/ (__ ) / / / __/ / / / /_/ / __/ / __// /__/ /_/ / / / / / /"); 18 | usart_printf("\r\n/_/ /_/\\____/_/ /_/\\__, /____/_/ /_/\\___/_/ /_/\\__, /\\___/_/\\___(_)___/\\____/_/ /_/ /_/"); 19 | usart_printf("\r\n /____/ /____/"); 20 | usart_printf(" \r\n hongshengele.com"); 21 | usart_printf(" \r\n ==============================================="); 22 | } -------------------------------------------------------------------------------- /Source/Task/task_state_machine.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "task_state_machine.h" 4 | 5 | #include "stm32f10x.h" 6 | #include "user_config.h" 7 | #include "gw_tasks.h" 8 | #include "user_state_machine.h" 9 | 10 | 11 | void task_state_machine_init(void); 12 | void task_state_machine(void* args); 13 | 14 | void task_state_machine_create(){ 15 | gw_task_args_create("state_machine", TASK_ID_STATE_MACHINE, 16 | TYPE_POLL, GW_DISABLE, 10, 17 | task_state_machine_init, 18 | task_state_machine); 19 | } 20 | /** 21 | * @brief Initialize motor control task 22 | */ 23 | void task_state_machine_init(void){ 24 | 25 | 26 | } 27 | 28 | void task_state_machine(void* args){ 29 | struct gw_event *pev = (struct gw_event *)args; 30 | gw_msg_fifo_t * const pmsg_fifo = &msg_fifo; 31 | gw_msg_t msg; 32 | if(gw_msg_receive(pev->id, pmsg_fifo, &msg) == GW_TRUE){ 33 | /** 34 | TODO 35 | */ 36 | printf("%016d: name:[%s] id:[%d] msg:[%s]\n", pev->g_timer->timestamp, 37 | pev->name, pev->id,(uint8_t*)msg.pstr); 38 | } 39 | 40 | pev->msg.pstr = "MSG from task_04: Hello I am task 04"; 41 | if(gw_msg_send_msg(TASK_ID_DISPLAY, pmsg_fifo, &pev->msg) == GW_TRUE){ 42 | /** 43 | TODO 44 | */ 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /Source/User/user_config.h: -------------------------------------------------------------------------------- 1 | #ifndef USER_CONFIG_H 2 | #define USER_CONFIG_H 3 | 4 | /** 5 | include file gw_os 6 | */ 7 | #include "gw_type.h" 8 | #include "gw_fifo.h" 9 | #include "gw_tasks.h" 10 | #include "gw_type.h" 11 | #include "gw_tasks.h" 12 | #include "gw_hal.h" 13 | #include "gw_log.h" 14 | 15 | #define USE_TASK_LIST 1 16 | 17 | #define TASK_ID_MOTOR 1 18 | #define TASK_ID_KEY 2 19 | #define TASK_ID_DISPLAY 3 20 | #define TASK_ID_STATE_MACHINE 4 21 | 22 | #define USE_PID 1 23 | #define USE_CUR_PID 1 24 | #define USE_SPEED_PID 0 25 | #define USE_POSITION_PID 0 26 | #define USE_FEED_FORWARD 0 27 | #define USE_STARTUP_ID_FLUX 0 //1:[Id=1 Iq=0]启动 0:[Id=0 Iq=1]启动 28 | #define MAX_RPM 75 29 | #define MIN_RPM 5 30 | 31 | #define MAX_POSITION 2100 32 | #define MIN_POSITION 50 33 | 34 | #define PN 2 35 | 36 | #define SPEED_PID_2MS 2 37 | #define SPEED_PID_5MS 5 38 | #define SPEED_PID_10MS 10 39 | 40 | #define SPEED_PID_SAMPLE SPEED_PID_2MS 41 | /* 42 | #if (SPEED_PID_SAMPLE == SPEED_PID_2MS) 43 | #define ENCODER_SPEED_FACTOR 500 44 | #elif (SPEED_PID_SAMPLE == SPEED_PID_5MS) 45 | #define ENCODER_SPEED_FACTOR 200 46 | #elif (SPEED_PID_SAMPLE == SPEED_PID_10MS) 47 | #define ENCODER_SPEED_FACTOR 100 48 | #else 49 | #endif 50 | */ 51 | #define __maybe_unused __attribute__((unused)) 52 | 53 | void pid_config(int8_t index); 54 | void soft_reset(void); 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /Source/Feedback/current.h: -------------------------------------------------------------------------------- 1 | #ifndef _CURRENT_H 2 | #define _CURRENT_H 3 | #include 4 | 5 | #if 1 6 | #define IA_CHANNEL_DRI ADC_Channel_0 7 | //#define IA_INJECT_CHANNEL_DRI ADC_InjectedChannel_1 8 | #define IA_INJECT_CHANNEL_DRI ADC_InjectedChannel_1 9 | #define IB_CHANNEL_DRI ADC_Channel_1 10 | //#define IB_INJECT_CHANNEL_DRI ADC_InjectedChannel_2 11 | #define IB_INJECT_CHANNEL_DRI ADC_InjectedChannel_2 12 | #else 13 | #define IA_CHANNEL_DRI ADC_Channel_3 14 | #define IB_CHANNEL_DRI ADC_Channel_2 15 | #endif 16 | 17 | #define IA_VALUE_REG ADC1->JDR1 18 | #define IB_VALUE_REG ADC1->JDR2 19 | 20 | #define RES_IA 1024 //采样电阻A 21 | #define RES_IB 1024 //采样电阻B 22 | 23 | #define USE_POLL_MECH 1 24 | 25 | /** 26 | * OC1 ---> Ic 27 | * OC2 ---> Ib ---> PA0/ADC0 28 | * OC3 ---> Ia ---> PA1/ADC1 29 | * Ib--->PA0/ADC0 30 | * |------------>PA2/ADC2 31 | * Ia--->PA1/ADC1 32 | * |------------>PA3/ADC3 33 | */ 34 | 35 | void cur_fbk_init(void); 36 | 37 | uint16_t cur_fbk_get_Ia(void); 38 | uint16_t cur_fbk_get_Ia_avl(uint8_t sample_times); 39 | uint16_t cur_fbk_get_Ib(void); 40 | uint16_t cur_fbk_get_Ib_avl(uint8_t sample_times); 41 | 42 | uint16_t get_inject_ia(void); 43 | uint16_t get_inject_ib(void); 44 | 45 | void set_inject_ib(uint16_t ib); 46 | void set_inject_ia(uint16_t ia); 47 | 48 | int16_t cur_fbk_get_theta(void); 49 | 50 | int16_t get_ia_offset(void); 51 | int16_t get_ib_offset(void); 52 | int16_t get_ia_asc_offset(void); 53 | int16_t get_ib_asc_offset(void); 54 | 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /Source/Usart/usart_driver.h: -------------------------------------------------------------------------------- 1 | #ifndef _USART_DRIVER_H 2 | #define _USART_DRIVER_H 3 | #include 4 | #include 5 | 6 | /* Private function prototypes -----------------------------------------------*/ 7 | #define USE_MICROLIB_USART 1 8 | 9 | #if USE_MICROLIB_USART 10 | 11 | #ifdef __GNUC__ 12 | /* With GCC/RAISONANCE, small printf (option LD Linker->Libraries->Small printf 13 | set to 'Yes') calls __io_putchar() */ 14 | #define PUTCHAR_PROTOTYPE int __io_putchar(int ch) 15 | #else 16 | #define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f) 17 | //#define GETCHAR_PROTOTYPE int fgetc(FILE *f) 18 | 19 | #endif /* __GNUC__ */ 20 | extern PUTCHAR_PROTOTYPE; 21 | #else 22 | 23 | #endif 24 | 25 | //default 8N1 26 | #define COM_PORT USART3 27 | #define TX_PIN GPIO_Pin_10 28 | #define RX_PIN GPIO_Pin_11 29 | #define BAUDRATE 115200 30 | 31 | #define IRQ_UART_PRE 3 32 | #define IRQ_UART_SUB 3 33 | 34 | #define USART_Rx_DMA_Channel DMA1_Channel3 35 | #define USART_Rx_DMA_FLAG DMA1_FLAG_TC3 36 | #define USART_DR_Base 0x40004804 37 | #define USART_BUF_SIZE ((uint16_t)16) 38 | 39 | typedef void (*rx_cbk)(void* args); 40 | struct uart_mod { 41 | 42 | uint8_t rx_buf[USART_BUF_SIZE]; 43 | uint8_t rx_dat_len; 44 | uint8_t head; 45 | uint8_t tail; 46 | 47 | void (*init)(void); 48 | 49 | void *pargs; 50 | rx_cbk pfunc_rx_cbk; 51 | }; 52 | typedef struct uart_mod uart_mod_t; 53 | 54 | extern uart_mod_t user_uart_mod; 55 | void usart_init(void); 56 | void usart_set_rx_cbk(uart_mod_t *pmod, rx_cbk pfunc,void *pargs); 57 | void usart_send_char(char ch); 58 | void usart_test_echo(void); 59 | uint8_t usart_recv_char(void); 60 | int usart_printf(const char *fmt, ...); 61 | 62 | //extern GETCHAR_PROTOTYPE; 63 | 64 | #endif 65 | -------------------------------------------------------------------------------- /Source/GwOS/gw_hal.h: -------------------------------------------------------------------------------- 1 | /** 2 | ************************************************************************************************ 3 | * @file : gw_hal.h 4 | * @brief : 5 | * @details : 6 | * @date : 11-09-2018 7 | * @version : v1.0.0.0 8 | * @author : UncleMac 9 | * @email : zhaojunhui1861@163.com 10 | * 11 | * @license : GNU General Public License, version 3 (GPL-3.0) 12 | * 13 | * Copyright (C)2019 UncleMac. 14 | * 15 | * This code is open source: you can redistribute it and/or modify 16 | * it under the terms of the GNU General Public License as published by 17 | * the Free Software Foundation, either version 3 of the License, or 18 | * (at your option) any later version. 19 | * 20 | * This code is distributed in the hope that it will be useful, 21 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 22 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the 23 | * GNU General Public License for more details. 24 | * 25 | * You should have received a copy of the GNU General Public License 26 | * along with this program.If not, see < https://www.gnu.org/licenses/>. 27 | ************************************************************************************************* 28 | */ 29 | 30 | #ifndef GW_HAL_H 31 | #define GW_HAL_H 32 | #include "gw_type.h" 33 | #if 1 34 | #define HAL_ENABLE_IRQ __enable_irq 35 | #define HAL_DISABLE_IRQ __disable_irq 36 | #define HAL_SLEEP __WFI() 37 | #define HAL_WAKEUP __WFE() 38 | #else 39 | #define HAL_ENABLE_IRQ {} 40 | #define HAL_DISABLE_IRQ {} 41 | #define HAL_SLEEP {} 42 | #define HAL_WAKEUP {} 43 | #endif 44 | 45 | void gw_hal_delay(volatile uint32_t ntime); 46 | void gw_hal_dec(void); 47 | 48 | #endif 49 | 50 | -------------------------------------------------------------------------------- /Source/GwOS/gw_timer.h: -------------------------------------------------------------------------------- 1 | /** 2 | ************************************************************************************************ 3 | * @file : gw_timer.h 4 | * @brief : 5 | * @details : 6 | * @date : 11-09-2018 7 | * @version : v1.0.0.0 8 | * @author : UncleMac 9 | * @email : zhaojunhui1861@163.com 10 | * 11 | * @license : GNU General Public License, version 3 (GPL-3.0) 12 | * 13 | * Copyright (C)2019 UncleMac. 14 | * 15 | * This code is open source: you can redistribute it and/or modify 16 | * it under the terms of the GNU General Public License as published by 17 | * the Free Software Foundation, either version 3 of the License, or 18 | * (at your option) any later version. 19 | * 20 | * This code is distributed in the hope that it will be useful, 21 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 22 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the 23 | * GNU General Public License for more details. 24 | * 25 | * You should have received a copy of the GNU General Public License 26 | * along with this program.If not, see < https://www.gnu.org/licenses/>. 27 | ************************************************************************************************* 28 | */ 29 | 30 | #ifndef GW_TIMER_H 31 | #define GW_TIMER_H 32 | #include 33 | /** 34 | * timebase-1ms 进行一次累加 35 | */ 36 | struct gw_timer{ 37 | uint32_t timestamp; 38 | }; 39 | 40 | extern struct gw_timer global_timer; 41 | 42 | extern void hal_system_timer_config(void); 43 | 44 | void timer_base_init(void); 45 | void timer_reset(struct gw_timer *timer); 46 | void timer_add(struct gw_timer *timer); 47 | uint32_t get_timer_stamp(struct gw_timer *timer); 48 | void set_timer_value(struct gw_timer *timer, uint32_t value); 49 | 50 | #endif 51 | 52 | -------------------------------------------------------------------------------- /Source/Task/task_main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "stm32f10x.h" 3 | #include "svpwm_module.h" 4 | #include "svpwm_math.h" 5 | #include "usart_driver.h" 6 | #include "task_display.h" 7 | #include "task_motor_control.h" 8 | #include "task_key.h" 9 | #include "task_main.h" 10 | #include "user_config.h" 11 | //gw_os include 12 | #include "gw_timer.h" 13 | #include "gw_fifo.h" 14 | #include "gw_log.h" 15 | #include "gw_tasks.h" 16 | #include "gw_event.h" 17 | #include "gw_fifo.h" 18 | 19 | //bsp include 20 | #include "usart_driver.h" 21 | #include "encoder.h" 22 | #include "position.h" 23 | #include "motor_protocol.h" 24 | 25 | //user file 26 | #include "user_banner.h" 27 | #include "foc.h" 28 | 29 | extern void task_key_create(void); 30 | extern void task_display_create(void); 31 | extern void task_motor_control_create(void); 32 | 33 | void task_bsp_init(void){ 34 | 35 | #if defined(USE_BOOTLOADER) 36 | SCB->VTOR = FLASH_BASE | 0x3000; //重定向Vector Table 37 | #endif 38 | 39 | timer_base_init(); 40 | 41 | /* init usart*/ 42 | usart_init(); 43 | usart_set_rx_cbk(&user_uart_mod, motor_get_cmd_from_uart,&user_uart_mod); 44 | 45 | encoder_init(); 46 | encoder_set_cbk(&user_encoder,foc_encoder_get_zero_line_offset,&user_encoder); 47 | 48 | 49 | 50 | } 51 | 52 | 53 | void task_system_init(void){ 54 | 55 | // gw_os init 56 | gw_task_list_init(); 57 | gw_msg_fifo_init(&msg_fifo); 58 | } 59 | 60 | void task_create(void){ 61 | 62 | //task_key_create(); 63 | //task_display_create(); 64 | task_motor_control_create(); 65 | } 66 | 67 | void task_main(void){ 68 | /** 69 | gw os init here 70 | */ 71 | #if USE_TASK_LIST 72 | gw_task_init_process(); 73 | #else 74 | gw_event_fifo_init(); 75 | #endif 76 | while (1) 77 | { 78 | #if USE_TASK_LIST 79 | gw_task_process(); 80 | #else 81 | gw_execute_event_task(); 82 | #endif 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /Source/GwOS/gw_timer.c: -------------------------------------------------------------------------------- 1 | /** 2 | ************************************************************************************************ 3 | * @file : gw_timer.c 4 | * @brief : Timer management API 5 | * @details : None 6 | * @date : 11-09-2018 7 | * @version : v1.0.0.0 8 | * @author : UncleMac 9 | * @email : zhaojunhui1861@163.com 10 | * 11 | * @license : GNU General Public License, version 3 (GPL-3.0) 12 | * 13 | * Copyright (C)2019 UncleMac. 14 | * 15 | * This code is open source: you can redistribute it and/or modify 16 | * it under the terms of the GNU General Public License as published by 17 | * the Free Software Foundation, either version 3 of the License, or 18 | * (at your option) any later version. 19 | * 20 | * This code is distributed in the hope that it will be useful, 21 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 22 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the 23 | * GNU General Public License for more details. 24 | * 25 | * You should have received a copy of the GNU General Public License 26 | * along with this program.If not, see < https://www.gnu.org/licenses/>. 27 | ************************************************************************************************* 28 | */ 29 | #include "gw_timer.h" 30 | 31 | struct gw_timer global_timer; 32 | 33 | static void ll_time_init(void){ 34 | hal_system_timer_config(); 35 | } 36 | 37 | void timer_base_init(void){ 38 | ll_time_init(); 39 | } 40 | 41 | void timer_reset(struct gw_timer *timer){ 42 | timer->timestamp = 0; 43 | } 44 | 45 | void timer_add(struct gw_timer *timer){ 46 | timer->timestamp++; 47 | } 48 | 49 | uint32_t get_timer_stamp(struct gw_timer *timer){ 50 | return timer->timestamp; 51 | } 52 | 53 | void set_timer_value(struct gw_timer *timer, uint32_t value){ 54 | timer->timestamp = value; 55 | } 56 | -------------------------------------------------------------------------------- /Source/GwOS/gw_fifo.h: -------------------------------------------------------------------------------- 1 | /** 2 | ************************************************************************************************ 3 | * @file : gw_fifo.h 4 | * @brief : Interface to manage events 5 | * @details : None 6 | * @date : 11-09-2018 7 | * @version : v1.0.0.0 8 | * @author : UncleMac 9 | * @email : zhaojunhui1861@163.com 10 | * 11 | * @license : GNU General Public License, version 3 (GPL-3.0) 12 | * 13 | * Copyright (C)2019 UncleMac. 14 | * 15 | * This code is open source: you can redistribute it and/or modify 16 | * it under the terms of the GNU General Public License as published by 17 | * the Free Software Foundation, either version 3 of the License, or 18 | * (at your option) any later version. 19 | * 20 | * This code is distributed in the hope that it will be useful, 21 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 22 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the 23 | * GNU General Public License for more details. 24 | * 25 | * You should have received a copy of the GNU General Public License 26 | * along with this program.If not, see < https://www.gnu.org/licenses/>. 27 | ************************************************************************************************* 28 | */ 29 | 30 | #ifndef GW_FIFO_H 31 | #define GW_FIFO_H 32 | #include "stdint.h" 33 | #include "gw_event.h" 34 | 35 | #define GW_FIFO_SIZE 20 36 | #define EVENT_SIZE 3 37 | 38 | struct gw_table{ 39 | const uint8_t size; 40 | struct gw_event event_table[GW_FIFO_SIZE]; 41 | uint8_t rear; 42 | uint8_t front; 43 | }; 44 | 45 | typedef struct gw_table gw_fifo_typedef; 46 | 47 | void gw_event_fifo_init(void); 48 | void gw_reset_event_status(void); 49 | void gw_poll_event_task(void); 50 | void gw_execute_event_task(void); 51 | void gw_global_timer_add(void); 52 | //__weak void task_init(void); 53 | 54 | void gw_list_add_event(struct gw_event envent); 55 | 56 | #endif 57 | 58 | -------------------------------------------------------------------------------- /Source/User/motor_protocol.h: -------------------------------------------------------------------------------- 1 | #ifndef MOTOR_PROTOCOL_H 2 | #define MOTOR_PROTOCOL_H 3 | #include 4 | 5 | #ifdef __cplusplus 6 | extern "C" { 7 | #endif 8 | /** 9 | command package format 10 | ------------------------------------ 11 | Head command option data Tail 12 | % 2 bytes 1 byte 4 byte & 13 | */ 14 | 15 | #define PACKAGE_HEAD '%' 16 | #define PACKAGE_TAIL '&' 17 | #define PACKAGE_SIZE 9 18 | 19 | #define MOTOR_CMD_MASK 0xF000 20 | #define MOTOR_CMD_SHIFT 12 21 | enum motor_cmd { 22 | //basic_cmd 23 | M_SYS_RESET = 0x000F, 24 | M_STOP = 0x0001, 25 | M_RUN_RPM = 0x0002, 26 | M_RUN_POS = 0x0003, 27 | M_STARTUP = 0x0004, 28 | 29 | //pid of current loop 30 | PID_CUR_KP = 0x1000, 31 | PID_CUR_KPDIV = 0x1001, 32 | PID_CUR_KI = 0x1002, 33 | PID_CUR_KIDIV = 0x1003, 34 | 35 | //pid of speed loop 36 | PID_SPD_KP = 0x2000, 37 | PID_SPD_KPDIV = 0x2001, 38 | PID_SPD_KI = 0x2002, 39 | PID_SPD_KIDIV = 0x2003, 40 | 41 | //pid of position loop 42 | PID_POS_KP = 0x3000, 43 | PID_POS_KPDIV = 0x3001, 44 | PID_POS_KI = 0x3002, 45 | PID_POS_KIDIV = 0x3003, 46 | PID_POS_UP_LIM = 0x3003, 47 | PID_POS_LOW_LIM = 0x3004, 48 | 49 | FFC_A_FACTOR = 0x4000, 50 | FFC_B_FACTOR = 0x4001 51 | }; 52 | 53 | enum motor_run_option{ 54 | DIR_FORWARD = 0x01, 55 | DIR_BACK = 0x02, 56 | }; 57 | 58 | union motor_cmd_data { 59 | int32_t value; 60 | uint8_t value_n[4]; 61 | }; 62 | 63 | union motor_cmd_cmd { 64 | int16_t value; 65 | uint8_t value_n[2]; 66 | }; 67 | 68 | 69 | struct motor_cmd_mod{ 70 | uint8_t head; 71 | union motor_cmd_cmd cmd; 72 | uint8_t option; 73 | union motor_cmd_data data; 74 | uint8_t tail; 75 | int8_t process_flag; 76 | }; 77 | 78 | typedef struct motor_cmd_mod motor_cmd_mod_t; 79 | 80 | extern motor_cmd_mod_t user_cmd_mod; 81 | int8_t motor_cmd_is_valid(motor_cmd_mod_t *pcmd); 82 | void motor_cmd_process(motor_cmd_mod_t *pcmd); 83 | 84 | void motor_get_cmd_from_uart(void *pargs); 85 | 86 | #ifdef __cplusplus 87 | } 88 | #endif 89 | 90 | #endif 91 | -------------------------------------------------------------------------------- /Source/GwOS/gw_type.h: -------------------------------------------------------------------------------- 1 | /** 2 | ************************************************************************************************ 3 | * @file : gw_type.h 4 | * @brief : 5 | * @details : 6 | * @date : 11-09-2018 7 | * @version : v1.0.0.0 8 | * @author : UncleMac 9 | * @email : zhaojunhui1861@163.com 10 | * 11 | * @license : GNU General Public License, version 3 (GPL-3.0) 12 | * 13 | * Copyright (C)2019 UncleMac. 14 | * 15 | * This code is open source: you can redistribute it and/or modify 16 | * it under the terms of the GNU General Public License as published by 17 | * the Free Software Foundation, either version 3 of the License, or 18 | * (at your option) any later version. 19 | * 20 | * This code is distributed in the hope that it will be useful, 21 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 22 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the 23 | * GNU General Public License for more details. 24 | * 25 | * You should have received a copy of the GNU General Public License 26 | * along with this program.If not, see < https://www.gnu.org/licenses/>. 27 | ************************************************************************************************* 28 | */ 29 | 30 | #ifndef GW_TYPE_H 31 | #define GW_TYPE_H 32 | #include 33 | #include 34 | 35 | #include "gw_hal.h" 36 | 37 | #define GW_DISABLE 0 38 | #define GW_ENABLE 1 39 | 40 | #define GW_RESULT int8_t 41 | 42 | #define GW_ERROR -1 43 | #define GW_ERROR_TASK -2 44 | 45 | #define GW_SUCCESS 1 46 | 47 | #define GW_TRUE 1 48 | #define GW_FALSE 0 49 | 50 | #define TYPE_IRQ 0x01 51 | #define TYPE_POLL 0x02 52 | 53 | #define DATA_TYPE uint32_t 54 | 55 | #define GW_ENABLE_INTERRUPTS HAL_ENABLE_IRQ 56 | #define GW_DISABLE_INTERRUPTS HAL_DISABLE_IRQ 57 | 58 | #define GW_ENTER_CRITICAL_AREA HAL_DISABLE_IRQ 59 | #define GW_EXIT_CRITICAL_AREA HAL_ENABLE_IRQ 60 | 61 | //#define GW_MALLOC((x)) malloc((x)) 62 | //#define GW_FREE((x)) free((x)) 63 | 64 | #define GW_MALLOC(x) malloc(x) 65 | #define GW_FREE(x) free(x) 66 | 67 | #endif 68 | -------------------------------------------------------------------------------- /Source/GwDebug/SDS.c: -------------------------------------------------------------------------------- 1 | #include "SDS.h" 2 | #include "usart_driver.h" 3 | //#include "uart.h" //LINK TO UART 4 | 5 | #define uart_putchar(x) usart_send_char(x) 6 | 7 | 8 | //float SDS_OutData[4] = { 0 }; 9 | 10 | unsigned short CRC_CHECK(unsigned char *Buf, unsigned char CRC_CNT) 11 | { 12 | unsigned short CRC_Temp; 13 | unsigned char i,j; 14 | CRC_Temp = 0xffff; 15 | 16 | for (i=0;i>1 ) ^ 0xa001; 21 | else 22 | CRC_Temp = CRC_Temp >> 1; 23 | } 24 | } 25 | return(CRC_Temp); 26 | } 27 | 28 | 29 | void SDS_OutPut_Data_INT(int S_Out[]) 30 | { 31 | int temp[4] = {0}; 32 | unsigned int temp1[4] = {0}; 33 | unsigned char databuf[10] = {0}; 34 | unsigned char i; 35 | unsigned short CRC16 = 0; 36 | int SDS_OutData[4]; 37 | for(i=0;i<4;i++) { 38 | SDS_OutData[i%4]=S_Out[i%4]; 39 | } 40 | for(i=0;i<4;i++) 41 | { 42 | 43 | temp[i%4] = (int)SDS_OutData[i%4]; 44 | temp1[i%4] = (unsigned int)temp[i%4]; 45 | 46 | } 47 | 48 | for(i=0;i<4;i++) 49 | { 50 | databuf[(i*2)%10] = (unsigned char)(temp1[i]%256); 51 | databuf[(i*2+1)%10] = (unsigned char)(temp1[i]/256); 52 | } 53 | 54 | CRC16 = CRC_CHECK(databuf,8); 55 | databuf[8] = CRC16%256; 56 | databuf[9] = CRC16/256; 57 | 58 | for(i=0;i<10;i++) 59 | uart_putchar(databuf[i%10]); //LINK TO UART 60 | } 61 | 62 | void SDS_OutPut_Data(float S_Out[]) 63 | { 64 | int temp[4] = {0}; 65 | unsigned int temp1[4] = {0}; 66 | unsigned char databuf[10] = {0}; 67 | unsigned char i; 68 | unsigned short CRC16 = 0; 69 | float SDS_OutData[4]; 70 | for(i=0;i<4;i++) { 71 | SDS_OutData[i%4]=S_Out[i%4]; 72 | } 73 | for(i=0;i<4;i++) 74 | { 75 | 76 | temp[i%4] = (int)SDS_OutData[i%4]; 77 | temp1[i%4] = (unsigned int)temp[i%4]; 78 | 79 | } 80 | 81 | for(i=0;i<4;i++) 82 | { 83 | databuf[(i*2)%10] = (unsigned char)(temp1[i%4]%256); 84 | databuf[(i*2+1)%10] = (unsigned char)(temp1[i%4]/256); 85 | } 86 | 87 | CRC16 = CRC_CHECK(databuf,8); 88 | databuf[8] = CRC16%256; 89 | databuf[9] = CRC16/256; 90 | 91 | for(i=0;i<10;i++) 92 | uart_putchar(databuf[i%10]); //LINK TO UART 93 | } 94 | -------------------------------------------------------------------------------- /Source/GwOS/gw_list.h: -------------------------------------------------------------------------------- 1 | /** 2 | ************************************************************************************************ 3 | * @file : gw_list.h 4 | * @brief : 5 | * @details : 6 | * @date : 11-09-2018 7 | * @version : v1.0.0.0 8 | * @author : UncleMac 9 | * @email : zhaojunhui1861@163.com 10 | * 11 | * @license : GNU General Public License, version 3 (GPL-3.0) 12 | * 13 | * Copyright (C)2019 UncleMac. 14 | * 15 | * This code is open source: you can redistribute it and/or modify 16 | * it under the terms of the GNU General Public License as published by 17 | * the Free Software Foundation, either version 3 of the License, or 18 | * (at your option) any later version. 19 | * 20 | * This dll is distributed in the hope that it will be useful, 21 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 22 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the 23 | * GNU General Public License for more details. 24 | * 25 | * You should have received a copy of the GNU General Public License 26 | * along with this program.If not, see < https://www.gnu.org/licenses/>. 27 | ************************************************************************************************* 28 | */ 29 | 30 | #ifndef GW_LIST_H 31 | #define GW_LIST_H 32 | 33 | #include "gw_event.h" 34 | #include "gw_type.h" 35 | struct gw_list_node{ 36 | struct gw_list_node *next; 37 | gw_event_t event; 38 | DATA_TYPE data; 39 | }; 40 | 41 | typedef struct gw_list_node gw_list_node; 42 | typedef struct gw_list_node gw_list; 43 | 44 | gw_list* gw_list_init(void); 45 | gw_list_node* gw_list_node_init(DATA_TYPE data); 46 | GW_RESULT gw_list_insert_node_last(gw_list* const plist, gw_list_node* const pnode); 47 | GW_RESULT gw_list_insert_node_first(gw_list* const plist, gw_list_node* const pnode); 48 | GW_RESULT gw_list_insert_node_by_index(gw_list* const plist, gw_list_node* const pnode, uint8_t index); 49 | GW_RESULT gw_list_remove_node_last(gw_list* plist); 50 | GW_RESULT gw_list_remove_node_first(gw_list* const plist); 51 | GW_RESULT gw_list_remove_node_by_index(gw_list* plist, uint8_t index); 52 | GW_RESULT gw_list_free(gw_list* plist); 53 | GW_RESULT gw_list_node_free(gw_list_node* const pnode); 54 | GW_RESULT gw_list_is_empty(gw_list* const plist); 55 | DATA_TYPE gw_list_length(gw_list* const plist); 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /Source/Libraries/CMSIS/CM3/DeviceSupport/ST/STM32F10x/system_stm32f10x.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file system_stm32f10x.h 4 | * @author MCD Application Team 5 | * @version V3.5.0 6 | * @date 11-March-2011 7 | * @brief CMSIS Cortex-M3 Device Peripheral Access Layer System Header File. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 12 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE 13 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY 14 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING 15 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE 16 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 17 | * 18 | *

© COPYRIGHT 2011 STMicroelectronics

19 | ****************************************************************************** 20 | */ 21 | 22 | /** @addtogroup CMSIS 23 | * @{ 24 | */ 25 | 26 | /** @addtogroup stm32f10x_system 27 | * @{ 28 | */ 29 | 30 | /** 31 | * @brief Define to prevent recursive inclusion 32 | */ 33 | #ifndef __SYSTEM_STM32F10X_H 34 | #define __SYSTEM_STM32F10X_H 35 | 36 | #ifdef __cplusplus 37 | extern "C" { 38 | #endif 39 | 40 | /** @addtogroup STM32F10x_System_Includes 41 | * @{ 42 | */ 43 | 44 | /** 45 | * @} 46 | */ 47 | 48 | 49 | /** @addtogroup STM32F10x_System_Exported_types 50 | * @{ 51 | */ 52 | 53 | extern uint32_t SystemCoreClock; /*!< System Clock Frequency (Core Clock) */ 54 | 55 | /** 56 | * @} 57 | */ 58 | 59 | /** @addtogroup STM32F10x_System_Exported_Constants 60 | * @{ 61 | */ 62 | 63 | /** 64 | * @} 65 | */ 66 | 67 | /** @addtogroup STM32F10x_System_Exported_Macros 68 | * @{ 69 | */ 70 | 71 | /** 72 | * @} 73 | */ 74 | 75 | /** @addtogroup STM32F10x_System_Exported_Functions 76 | * @{ 77 | */ 78 | 79 | extern void SystemInit(void); 80 | extern void SystemCoreClockUpdate(void); 81 | /** 82 | * @} 83 | */ 84 | 85 | #ifdef __cplusplus 86 | } 87 | #endif 88 | 89 | #endif /*__SYSTEM_STM32F10X_H */ 90 | 91 | /** 92 | * @} 93 | */ 94 | 95 | /** 96 | * @} 97 | */ 98 | /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ 99 | -------------------------------------------------------------------------------- /Source/Libraries/STM32F10x_StdPeriph_Driver/inc/stm32f10x_crc.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f10x_crc.h 4 | * @author MCD Application Team 5 | * @version V3.5.0 6 | * @date 11-March-2011 7 | * @brief This file contains all the functions prototypes for the CRC firmware 8 | * library. 9 | ****************************************************************************** 10 | * @attention 11 | * 12 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 13 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE 14 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY 15 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING 16 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE 17 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 18 | * 19 | *

© COPYRIGHT 2011 STMicroelectronics

20 | ****************************************************************************** 21 | */ 22 | 23 | /* Define to prevent recursive inclusion -------------------------------------*/ 24 | #ifndef __STM32F10x_CRC_H 25 | #define __STM32F10x_CRC_H 26 | 27 | #ifdef __cplusplus 28 | extern "C" { 29 | #endif 30 | 31 | /* Includes ------------------------------------------------------------------*/ 32 | #include "stm32f10x.h" 33 | 34 | /** @addtogroup STM32F10x_StdPeriph_Driver 35 | * @{ 36 | */ 37 | 38 | /** @addtogroup CRC 39 | * @{ 40 | */ 41 | 42 | /** @defgroup CRC_Exported_Types 43 | * @{ 44 | */ 45 | 46 | /** 47 | * @} 48 | */ 49 | 50 | /** @defgroup CRC_Exported_Constants 51 | * @{ 52 | */ 53 | 54 | /** 55 | * @} 56 | */ 57 | 58 | /** @defgroup CRC_Exported_Macros 59 | * @{ 60 | */ 61 | 62 | /** 63 | * @} 64 | */ 65 | 66 | /** @defgroup CRC_Exported_Functions 67 | * @{ 68 | */ 69 | 70 | void CRC_ResetDR(void); 71 | uint32_t CRC_CalcCRC(uint32_t Data); 72 | uint32_t CRC_CalcBlockCRC(uint32_t pBuffer[], uint32_t BufferLength); 73 | uint32_t CRC_GetCRC(void); 74 | void CRC_SetIDRegister(uint8_t IDValue); 75 | uint8_t CRC_GetIDRegister(void); 76 | 77 | #ifdef __cplusplus 78 | } 79 | #endif 80 | 81 | #endif /* __STM32F10x_CRC_H */ 82 | /** 83 | * @} 84 | */ 85 | 86 | /** 87 | * @} 88 | */ 89 | 90 | /** 91 | * @} 92 | */ 93 | 94 | /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ 95 | -------------------------------------------------------------------------------- /Source/Project/MDK/GCC/DebugConfig/PMSM_STM32F103CB_1.0.0.dbgconf: -------------------------------------------------------------------------------- 1 | // File: STM32F101_102_103_105_107.dbgconf 2 | // Version: 1.0.0 3 | // Note: refer to STM32F101xx STM32F102xx STM32F103xx STM32F105xx STM32F107xx Reference manual (RM0008) 4 | // STM32F101xx STM32F102xx STM32F103xx STM32F105xx STM32F107xx datasheets 5 | 6 | // <<< Use Configuration Wizard in Context Menu >>> 7 | 8 | // Debug MCU configuration register (DBGMCU_CR) 9 | // Reserved bits must be kept at reset value 10 | // DBG_TIM11_STOP TIM11 counter stopped when core is halted 11 | // DBG_TIM10_STOP TIM10 counter stopped when core is halted 12 | // DBG_TIM9_STOP TIM9 counter stopped when core is halted 13 | // DBG_TIM14_STOP TIM14 counter stopped when core is halted 14 | // DBG_TIM13_STOP TIM13 counter stopped when core is halted 15 | // DBG_TIM12_STOP TIM12 counter stopped when core is halted 16 | // DBG_CAN2_STOP Debug CAN2 stopped when core is halted 17 | // DBG_TIM7_STOP TIM7 counter stopped when core is halted 18 | // DBG_TIM6_STOP TIM6 counter stopped when core is halted 19 | // DBG_TIM5_STOP TIM5 counter stopped when core is halted 20 | // DBG_TIM8_STOP TIM8 counter stopped when core is halted 21 | // DBG_I2C2_SMBUS_TIMEOUT SMBUS timeout mode stopped when core is halted 22 | // DBG_I2C1_SMBUS_TIMEOUT SMBUS timeout mode stopped when core is halted 23 | // DBG_CAN1_STOP Debug CAN1 stopped when Core is halted 24 | // DBG_TIM4_STOP TIM4 counter stopped when core is halted 25 | // DBG_TIM3_STOP TIM3 counter stopped when core is halted 26 | // DBG_TIM2_STOP TIM2 counter stopped when core is halted 27 | // DBG_TIM1_STOP TIM1 counter stopped when core is halted 28 | // DBG_WWDG_STOP Debug window watchdog stopped when core is halted 29 | // DBG_IWDG_STOP Debug independent watchdog stopped when core is halted 30 | // DBG_STANDBY Debug standby mode 31 | // DBG_STOP Debug stop mode 32 | // DBG_SLEEP Debug sleep mode 33 | // 34 | DbgMCU_CR = 0x00000007; 35 | 36 | // <<< end of configuration section >>> 37 | -------------------------------------------------------------------------------- /Source/Project/MDK/ARMCC/DebugConfig/PMSM_STM32F103CB_1.0.0.dbgconf: -------------------------------------------------------------------------------- 1 | // File: STM32F101_102_103_105_107.dbgconf 2 | // Version: 1.0.0 3 | // Note: refer to STM32F101xx STM32F102xx STM32F103xx STM32F105xx STM32F107xx Reference manual (RM0008) 4 | // STM32F101xx STM32F102xx STM32F103xx STM32F105xx STM32F107xx datasheets 5 | 6 | // <<< Use Configuration Wizard in Context Menu >>> 7 | 8 | // Debug MCU configuration register (DBGMCU_CR) 9 | // Reserved bits must be kept at reset value 10 | // DBG_TIM11_STOP TIM11 counter stopped when core is halted 11 | // DBG_TIM10_STOP TIM10 counter stopped when core is halted 12 | // DBG_TIM9_STOP TIM9 counter stopped when core is halted 13 | // DBG_TIM14_STOP TIM14 counter stopped when core is halted 14 | // DBG_TIM13_STOP TIM13 counter stopped when core is halted 15 | // DBG_TIM12_STOP TIM12 counter stopped when core is halted 16 | // DBG_CAN2_STOP Debug CAN2 stopped when core is halted 17 | // DBG_TIM7_STOP TIM7 counter stopped when core is halted 18 | // DBG_TIM6_STOP TIM6 counter stopped when core is halted 19 | // DBG_TIM5_STOP TIM5 counter stopped when core is halted 20 | // DBG_TIM8_STOP TIM8 counter stopped when core is halted 21 | // DBG_I2C2_SMBUS_TIMEOUT SMBUS timeout mode stopped when core is halted 22 | // DBG_I2C1_SMBUS_TIMEOUT SMBUS timeout mode stopped when core is halted 23 | // DBG_CAN1_STOP Debug CAN1 stopped when Core is halted 24 | // DBG_TIM4_STOP TIM4 counter stopped when core is halted 25 | // DBG_TIM3_STOP TIM3 counter stopped when core is halted 26 | // DBG_TIM2_STOP TIM2 counter stopped when core is halted 27 | // DBG_TIM1_STOP TIM1 counter stopped when core is halted 28 | // DBG_WWDG_STOP Debug window watchdog stopped when core is halted 29 | // DBG_IWDG_STOP Debug independent watchdog stopped when core is halted 30 | // DBG_STANDBY Debug standby mode 31 | // DBG_STOP Debug stop mode 32 | // DBG_SLEEP Debug sleep mode 33 | // 34 | DbgMCU_CR = 0x00000007; 35 | 36 | // <<< end of configuration section >>> 37 | -------------------------------------------------------------------------------- /Source/User/stm32f10x_it.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file Project/STM32F10x_StdPeriph_Template/stm32f10x_it.h 4 | * @author MCD Application Team 5 | * @version V3.5.0 6 | * @date 08-April-2011 7 | * @brief This file contains the headers of the interrupt handlers. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 12 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE 13 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY 14 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING 15 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE 16 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 17 | * 18 | *

© COPYRIGHT 2011 STMicroelectronics

19 | ****************************************************************************** 20 | */ 21 | 22 | /* Define to prevent recursive inclusion -------------------------------------*/ 23 | #ifndef __STM32F10x_IT_H 24 | #define __STM32F10x_IT_H 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | /* Includes ------------------------------------------------------------------*/ 31 | #include "stm32f10x.h" 32 | #include "svpwm_driver.h" 33 | #include "svpwm_module.h" 34 | #include "svpwm_math.h" 35 | #include "gw_timer.h" 36 | 37 | /* Exported types ------------------------------------------------------------*/ 38 | /* Exported constants --------------------------------------------------------*/ 39 | /* Exported macro ------------------------------------------------------------*/ 40 | extern struct gw_timer global_timer; 41 | //extern struct gw_event event_table[]; 42 | extern struct svpwm_mod *psvpwm; 43 | /* Exported functions ------------------------------------------------------- */ 44 | extern void TimingDelay_Decrement(void); 45 | 46 | void NMI_Handler(void); 47 | void HardFault_Handler(void); 48 | void MemManage_Handler(void); 49 | void BusFault_Handler(void); 50 | void UsageFault_Handler(void); 51 | void SVC_Handler(void); 52 | void DebugMon_Handler(void); 53 | void PendSV_Handler(void); 54 | void SysTick_Handler(void); 55 | 56 | 57 | #ifdef __cplusplus 58 | } 59 | #endif 60 | 61 | #endif /* __STM32F10x_IT_H */ 62 | 63 | /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ 64 | -------------------------------------------------------------------------------- /Source/Feedback/encoder.h: -------------------------------------------------------------------------------- 1 | #ifndef ENCODER_H 2 | #define ENCODER_H 3 | #include 4 | 5 | #define ALIGNMENT_ANGLE (uint16_t) 0 //Degrees [0..359] 6 | 7 | #define SPEED_SAMPLING_FREQ 500 8 | 9 | #define ENCODER_ONE_CIRCLE_CNT 2160 10 | #define ENCODER_ZERO_CIRCLE_CNT 1580 11 | #define SAMPLE_FRQ 10000L 12 | #define SYS_FRQ 72000000L 13 | #define ENCODER_MAX_CNT 0xFFFF 14 | #define ENCODER_ZERO_VAL (int16_t)((int32_t)(ALIGNMENT_ANGLE)*65536/360) 15 | //#define ENCODER_ZERO_VAL 0 16 | #define START_SECTOR 5 17 | 18 | typedef void (*pFunc)(void *pargs); 19 | 20 | struct encoder_mod { 21 | const uint16_t one_circle_lines_num; 22 | 23 | const uint8_t align_angle; 24 | int8_t first_zero_signal_flag; 25 | int8_t first_start_sector_flag; 26 | int16_t zero_signal_offset; 27 | pFunc first_zero_signal_cbk; 28 | void *pargs; 29 | }; 30 | 31 | typedef struct encoder_mod encoder_mod_t; 32 | extern encoder_mod_t user_encoder; 33 | /* 34 | QPEA--->PA6/TIM3C1 35 | QPEB--->PA7/TIM3C1 36 | --------------------------- 37 | TIM3_UPDATE_IRQ 38 | EXTI_PA5 39 | --------------------------- 40 | */ 41 | typedef enum{ 42 | FORWARD = 0, 43 | BACK 44 | }MOTO_DIR; 45 | 46 | /** 47 | * @brief init encoder pin for pha pab and zero 48 | * and interrpts 49 | */ 50 | void encoder_init(void); 51 | 52 | void encoder_set_cbk(encoder_mod_t *p, pFunc cbk,void* pargs); 53 | /** 54 | * @brief get encoder capture signal counts 55 | */ 56 | int32_t encoder_get_signal_cnt(void); 57 | 58 | /** 59 | * @brief get encoder running direction 60 | */ 61 | MOTO_DIR encoder_get_motor_dir(void); 62 | 63 | /** 64 | * @brief get angular position 65 | * @retval angle in q1.15 format 66 | */ 67 | int16_t encoder_get_angular_pos(void); 68 | 69 | 70 | void encoder_set_to_zero_position(void); 71 | 72 | uint8_t encoder_get_zero_pos_flag(void); 73 | 74 | int16_t encoder_get_first_zero_cnt(void); 75 | 76 | int16_t encoder_get_timecounter_cnt(void); 77 | 78 | void encoder_set_zero_pos_flag(uint8_t flag); 79 | 80 | void encoder_clear_timercounter(void); 81 | 82 | /** 83 | * @brief convert encoder count to angular posiong 84 | * @retval angle in format Q15 85 | */ 86 | int16_t encoder_conv_angular_pos(int16_t enc_cnt); 87 | 88 | int16_t encoder_get_m_theta(void); 89 | 90 | int16_t encoder_get_e_theta(void); 91 | 92 | void encoder_reset_aligment(void); 93 | 94 | void enconder_get_rpm(int16_t *pdata); 95 | 96 | int16_t enconder_calc_rot_speed(void); 97 | 98 | int16_t enconder_get_ave_speed(void); 99 | 100 | void encoder_set_first_start_sector_flag(encoder_mod_t *p, int8_t val); 101 | 102 | int8_t encoder_get_first_start_sector_flag(encoder_mod_t *p); 103 | 104 | void encoder_set_first_zero_signal_flag(encoder_mod_t *p, int8_t val); 105 | 106 | int8_t encoder_get_first_zero_signal_flag(encoder_mod_t *p); 107 | 108 | #endif 109 | -------------------------------------------------------------------------------- /Source/User/main.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file Project/STM32F10x_StdPeriph_Template/main.c 4 | * @author MCD Application Team 5 | * @version V3.5.0 6 | * @date 08-April-2011 7 | * @brief Main program body 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 12 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE 13 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY 14 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING 15 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE 16 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 17 | * 18 | *

© COPYRIGHT 2011 STMicroelectronics

19 | ****************************************************************************** 20 | */ 21 | 22 | /* Includes ------------------------------------------------------------------*/ 23 | #include "stm32f10x.h" 24 | #include "task_main.h" 25 | /** @addtogroup STM32F10x_StdPeriph_Template 26 | * @{ 27 | */ 28 | 29 | /* Private typedef -----------------------------------------------------------*/ 30 | /* Private define ------------------------------------------------------------*/ 31 | /* Private function prototypes -----------------------------------------------*/ 32 | 33 | /* Private macro -------------------------------------------------------------*/ 34 | /* Private variables ---------------------------------------------------------*/ 35 | /* Private function prototypes -----------------------------------------------*/ 36 | 37 | /* Private functions ---------------------------------------------------------*/ 38 | extern void user_banner_show(void); 39 | 40 | int main(void) 41 | { 42 | /** 43 | add user hard environment init here 44 | */ 45 | 46 | /** 47 | task code 48 | */ 49 | task_bsp_init(); 50 | 51 | task_system_init(); 52 | 53 | task_create(); 54 | 55 | task_main(); 56 | 57 | return 0; 58 | } 59 | 60 | #ifdef USE_FULL_ASSERT 61 | 62 | /** 63 | * @brief Reports the name of the source file and the source line number 64 | * where the assert_param error has occurred. 65 | * @param file: pointer to the source file name 66 | * @param line: assert_param error line source number 67 | * @retval None 68 | */ 69 | void assert_failed(uint8_t* file, uint32_t line) 70 | { 71 | /* User can add his own implementation to report the file name and line number, 72 | ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ 73 | 74 | /* Infinite loop */ 75 | while (1) 76 | { 77 | 78 | } 79 | } 80 | #endif 81 | 82 | /** 83 | * @} 84 | */ 85 | 86 | 87 | /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ 88 | -------------------------------------------------------------------------------- /Source/Display/display_driver.c: -------------------------------------------------------------------------------- 1 | #include "display_driver.h" 2 | #include "stm32f10x_gpio.h" 3 | #include "stddef.h" 4 | 5 | #if 0 6 | GPIO_InitTypeDef GPIO_InitStructure; 7 | 8 | 9 | #define TAR_IO_GROUP GPIOB 10 | #define PIN_SCK GPIO_Pin_7 11 | #define PIN_RCK GPIO_Pin_6 12 | #define PIN_SI GPIO_Pin_5 13 | 14 | static void output_sck(uint8_t dat){ 15 | GPIO_WriteBit (TAR_IO_GROUP, PIN_SCK, dat); 16 | } 17 | 18 | static void output_rck(uint8_t dat){ 19 | GPIO_WriteBit (TAR_IO_GROUP, PIN_SCK, dat); 20 | } 21 | 22 | static void output_sdi(uint8_t dat){ 23 | GPIO_WriteBit (TAR_IO_GROUP, PIN_SI, dat); 24 | } 25 | 26 | void init(struct dirver_74hc595* pdev){ 27 | RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE); 28 | 29 | /* Configure PD0 and PD2 in output pushpull mode */ 30 | GPIO_InitStructure.GPIO_Pin = PIN_SCK 31 | | PIN_RCK 32 | | PIN_SI; 33 | GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; 34 | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; 35 | GPIO_Init(TAR_IO_GROUP, &GPIO_InitStructure); 36 | 37 | pdev->output_sck = output_sck; 38 | pdev->output_rck = output_rck; 39 | pdev->output_sdi = output_sdi; 40 | 41 | } 42 | 43 | void hc595_init(struct dirver_74hc595* pdev){ 44 | pdev->init = init; 45 | pdev->init(pdev); 46 | } 47 | 48 | void hc595_write(struct dirver_74hc595* pdev, uint8_t data){ 49 | 50 | for(int i=0; i<8; i++){ 51 | pdev->output_sdi((data >> i)&0x01); 52 | pdev->output_rck(0x00); 53 | pdev->output_rck(0x01); 54 | } 55 | } 56 | 57 | void hc595_output(struct dirver_74hc595* pdev){ 58 | 59 | } 60 | 61 | 62 | GPIO_InitTypeDef GPIO_InitStr; 63 | 64 | #define TAR_IO_GROUP GPIOB 65 | #define PIN_SCK GPIO_Pin_7 66 | #define PIN_RCK GPIO_Pin_6 67 | #define PIN_SI GPIO_Pin_5 68 | 69 | 70 | void gpio_init(){ 71 | RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE); 72 | 73 | /* Configure PD0 and PD2 in output pushpull mode */ 74 | GPIO_InitStr.GPIO_Pin = PIN_SCK 75 | | PIN_RCK 76 | | PIN_SI; 77 | GPIO_InitStr.GPIO_Speed = GPIO_Speed_50MHz; 78 | GPIO_InitStr.GPIO_Mode = GPIO_Mode_Out_PP; 79 | GPIO_Init(TAR_IO_GROUP, &GPIO_InitStr); 80 | } 81 | 82 | #define SCK_LOW() GPIO_WriteBit (TAR_IO_GROUP, PIN_SCK, Bit_RESET) 83 | #define RCK_LOW() GPIO_WriteBit (TAR_IO_GROUP, PIN_RCK, Bit_RESET) 84 | #define SDI_LOW() GPIO_WriteBit (TAR_IO_GROUP, PIN_SI, Bit_RESET) 85 | 86 | #define SCK_HIGH() GPIO_WriteBit (TAR_IO_GROUP, PIN_SCK, Bit_SET) 87 | #define RCK_HIGH() GPIO_WriteBit (TAR_IO_GROUP, PIN_RCK, Bit_SET) 88 | #define SDI_HIGH() GPIO_WriteBit (TAR_IO_GROUP, PIN_SI, Bit_SET) 89 | 90 | void delay(int16_t time){ 91 | 92 | int16_t i = 2000; 93 | while(time-- > 0){ 94 | while (i--); 95 | } 96 | } 97 | void hc595_wr_data(int8_t dat){ 98 | 99 | for(int8_t i = 0; i<8; i++){ 100 | if( (dat >> i) & 0x01 ){ 101 | SDI_HIGH(); 102 | }else{ 103 | SDI_LOW (); 104 | } 105 | delay(5); 106 | SCK_HIGH (); 107 | delay (5); 108 | SCK_LOW (); 109 | } 110 | 111 | RCK_HIGH (); 112 | delay (5); 113 | RCK_LOW (); 114 | } 115 | 116 | 117 | #endif 118 | 119 | 120 | -------------------------------------------------------------------------------- /Source/GwOS/gw_hal.c: -------------------------------------------------------------------------------- 1 | /** 2 | ************************************************************************************************ 3 | * @file : gw_msgs.c 4 | * @brief : 5 | * @details : 6 | * @date : 11-09-2019 7 | * @version : v1.0.0.0 8 | * @author : UncleMac 9 | * @email : zhaojunhui1861@163.com 10 | * 11 | * @license : GNU General Public License, version 3 (GPL-3.0) 12 | * 13 | * Copyright (C)2019 UncleMac. 14 | * 15 | * This code is open source: you can redistribute it and/or modify 16 | * it under the terms of the GNU General Public License as published by 17 | * the Free Software Foundation, either version 3 of the License, or 18 | * (at your option) any later version. 19 | * 20 | * This code is distributed in the hope that it will be useful, 21 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 22 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the 23 | * GNU General Public License for more details. 24 | * 25 | * You should have received a copy of the GNU General Public License 26 | * along with this program.If not, see < https://www.gnu.org/licenses/>. 27 | ************************************************************************************************* 28 | */ 29 | #include "stm32f10x.h" 30 | #include "core_cm3.h" 31 | #include "system_stm32f10x.h" 32 | #include "gw_hal.h" 33 | 34 | volatile uint32_t time_cnt = 0; 35 | 36 | void gw_hal_delay(volatile uint32_t ntime){ 37 | 38 | time_cnt = ntime; 39 | while(time_cnt != 0); 40 | 41 | } 42 | 43 | void gw_hal_dec(void){ 44 | if (time_cnt != 0x00) 45 | { 46 | time_cnt--; 47 | } 48 | } 49 | 50 | 51 | void hal_system_timer_config(void){ 52 | /* Setup SysTick Timer for 1 msec interrupts. 53 | ------------------------------------------ 54 | 1. The SysTick_Config() function is a CMSIS function which configure: 55 | - The SysTick Reload register with value passed as function parameter. 56 | - Configure the SysTick IRQ priority to the lowest value (0x0F). 57 | - Reset the SysTick Counter register. 58 | - Configure the SysTick Counter clock source to be Core Clock Source (HCLK). 59 | - Enable the SysTick Interrupt. 60 | - Start the SysTick Counter. 61 | 62 | 2. You can change the SysTick Clock source to be HCLK_Div8 by calling the 63 | SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK_Div8) just after the 64 | SysTick_Config() function call. The SysTick_CLKSourceConfig() is defined 65 | inside the misc.c file. 66 | 67 | 3. You can change the SysTick IRQ priority by calling the 68 | NVIC_SetPriority(SysTick_IRQn,...) just after the SysTick_Config() function 69 | call. The NVIC_SetPriority() is defined inside the core_cm3.h file. 70 | 71 | 4. To adjust the SysTick time base, use the following formula: 72 | 73 | Reload Value = SysTick Counter Clock (Hz) x Desired Time base (s) 74 | 75 | - Reload Value is the parameter to be passed for SysTick_Config() function 76 | - Reload Value should not exceed 0xFFFFFF 77 | */ 78 | if (SysTick_Config(SystemCoreClock / 1000)) 79 | { 80 | /* Capture error */ 81 | while (1); 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /Source/User/stm32f10x_conf.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file GPIO/IOToggle/stm32f10x_conf.h 4 | * @author MCD Application Team 5 | * @version V3.5.0 6 | * @date 08-April-2011 7 | * @brief Library configuration file. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 12 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE 13 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY 14 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING 15 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE 16 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 17 | * 18 | *

© COPYRIGHT 2011 STMicroelectronics

19 | ****************************************************************************** 20 | */ 21 | 22 | /* Define to prevent recursive inclusion -------------------------------------*/ 23 | #ifndef __STM32F10x_CONF_H 24 | #define __STM32F10x_CONF_H 25 | 26 | /* Includes ------------------------------------------------------------------*/ 27 | /* Uncomment/Comment the line below to enable/disable peripheral header file inclusion */ 28 | #include "stm32f10x_adc.h" 29 | #include "stm32f10x_bkp.h" 30 | //#include "stm32f10x_can.h" 31 | //#include "stm32f10x_cec.h" 32 | //#include "stm32f10x_crc.h" 33 | //#include "stm32f10x_dac.h" 34 | //#include "stm32f10x_dbgmcu.h" 35 | #include "stm32f10x_dma.h" 36 | #include "stm32f10x_exti.h" 37 | //#include "stm32f10x_flash.h" 38 | //#include "stm32f10x_fsmc.h" 39 | #include "stm32f10x_gpio.h" 40 | //#include "stm32f10x_i2c.h" 41 | //#include "stm32f10x_iwdg.h" 42 | //#include "stm32f10x_pwr.h" 43 | #include "stm32f10x_rcc.h" 44 | //#include "stm32f10x_rtc.h" 45 | //#include "stm32f10x_sdio.h" 46 | //#include "stm32f10x_spi.h" 47 | #include "stm32f10x_tim.h" 48 | #include "stm32f10x_usart.h" 49 | //#include "stm32f10x_wwdg.h" 50 | #include "misc.h" /* High level functions for NVIC and SysTick (add-on to CMSIS functions) */ 51 | 52 | /* Exported types ------------------------------------------------------------*/ 53 | /* Exported constants --------------------------------------------------------*/ 54 | /* Uncomment the line below to expanse the "assert_param" macro in the 55 | Standard Peripheral Library drivers code */ 56 | /* #define USE_FULL_ASSERT 1 */ 57 | 58 | /* Exported macro ------------------------------------------------------------*/ 59 | #ifdef USE_FULL_ASSERT 60 | 61 | /** 62 | * @brief The assert_param macro is used for function's parameters check. 63 | * @param expr: If expr is false, it calls assert_failed function which reports 64 | * the name of the source file and the source line number of the call 65 | * that failed. If expr is true, it returns no value. 66 | * @retval None 67 | */ 68 | #define assert_param(expr) ((expr) ? (void)0 : assert_failed((uint8_t *)__FILE__, __LINE__)) 69 | /* Exported functions ------------------------------------------------------- */ 70 | void assert_failed(uint8_t* file, uint32_t line); 71 | #else 72 | #define assert_param(expr) ((void)0) 73 | #endif /* USE_FULL_ASSERT */ 74 | 75 | #endif /* __STM32F10x_CONF_H */ 76 | 77 | /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ 78 | -------------------------------------------------------------------------------- /Source/Libraries/STM32F10x_StdPeriph_Driver/inc/stm32f10x_wwdg.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f10x_wwdg.h 4 | * @author MCD Application Team 5 | * @version V3.5.0 6 | * @date 11-March-2011 7 | * @brief This file contains all the functions prototypes for the WWDG firmware 8 | * library. 9 | ****************************************************************************** 10 | * @attention 11 | * 12 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 13 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE 14 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY 15 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING 16 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE 17 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 18 | * 19 | *

© COPYRIGHT 2011 STMicroelectronics

20 | ****************************************************************************** 21 | */ 22 | 23 | /* Define to prevent recursive inclusion -------------------------------------*/ 24 | #ifndef __STM32F10x_WWDG_H 25 | #define __STM32F10x_WWDG_H 26 | 27 | #ifdef __cplusplus 28 | extern "C" { 29 | #endif 30 | 31 | /* Includes ------------------------------------------------------------------*/ 32 | #include "stm32f10x.h" 33 | 34 | /** @addtogroup STM32F10x_StdPeriph_Driver 35 | * @{ 36 | */ 37 | 38 | /** @addtogroup WWDG 39 | * @{ 40 | */ 41 | 42 | /** @defgroup WWDG_Exported_Types 43 | * @{ 44 | */ 45 | 46 | /** 47 | * @} 48 | */ 49 | 50 | /** @defgroup WWDG_Exported_Constants 51 | * @{ 52 | */ 53 | 54 | /** @defgroup WWDG_Prescaler 55 | * @{ 56 | */ 57 | 58 | #define WWDG_Prescaler_1 ((uint32_t)0x00000000) 59 | #define WWDG_Prescaler_2 ((uint32_t)0x00000080) 60 | #define WWDG_Prescaler_4 ((uint32_t)0x00000100) 61 | #define WWDG_Prescaler_8 ((uint32_t)0x00000180) 62 | #define IS_WWDG_PRESCALER(PRESCALER) (((PRESCALER) == WWDG_Prescaler_1) || \ 63 | ((PRESCALER) == WWDG_Prescaler_2) || \ 64 | ((PRESCALER) == WWDG_Prescaler_4) || \ 65 | ((PRESCALER) == WWDG_Prescaler_8)) 66 | #define IS_WWDG_WINDOW_VALUE(VALUE) ((VALUE) <= 0x7F) 67 | #define IS_WWDG_COUNTER(COUNTER) (((COUNTER) >= 0x40) && ((COUNTER) <= 0x7F)) 68 | 69 | /** 70 | * @} 71 | */ 72 | 73 | /** 74 | * @} 75 | */ 76 | 77 | /** @defgroup WWDG_Exported_Macros 78 | * @{ 79 | */ 80 | /** 81 | * @} 82 | */ 83 | 84 | /** @defgroup WWDG_Exported_Functions 85 | * @{ 86 | */ 87 | 88 | void WWDG_DeInit(void); 89 | void WWDG_SetPrescaler(uint32_t WWDG_Prescaler); 90 | void WWDG_SetWindowValue(uint8_t WindowValue); 91 | void WWDG_EnableIT(void); 92 | void WWDG_SetCounter(uint8_t Counter); 93 | void WWDG_Enable(uint8_t Counter); 94 | FlagStatus WWDG_GetFlagStatus(void); 95 | void WWDG_ClearFlag(void); 96 | 97 | #ifdef __cplusplus 98 | } 99 | #endif 100 | 101 | #endif /* __STM32F10x_WWDG_H */ 102 | 103 | /** 104 | * @} 105 | */ 106 | 107 | /** 108 | * @} 109 | */ 110 | 111 | /** 112 | * @} 113 | */ 114 | 115 | /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ 116 | -------------------------------------------------------------------------------- /Source/GwOS/gw_event.h: -------------------------------------------------------------------------------- 1 | /** 2 | ************************************************************************************************ 3 | * @file : gw_event.h 4 | * @brief : Interface to manage events 5 | * @details : None 6 | * @date : 11-09-2018 7 | * @version : v1.0.0.0 8 | * @author : UncleMac 9 | * @email : zhaojunhui1861@163.com 10 | * 11 | * @license : GNU General Public License, version 3 (GPL-3.0) 12 | * 13 | * Copyright (C)2019 UncleMac. 14 | * 15 | * This code is open source: you can redistribute it and/or modify 16 | * it under the terms of the GNU General Public License as published by 17 | * the Free Software Foundation, either version 3 of the License, or 18 | * (at your option) any later version. 19 | * 20 | * This code is distributed in the hope that it will be useful, 21 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 22 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the 23 | * GNU General Public License for more details. 24 | * 25 | * You should have received a copy of the GNU General Public License 26 | * along with this program.If not, see < https://www.gnu.org/licenses/>. 27 | ************************************************************************************************* 28 | */ 29 | 30 | #ifndef GW_EVENT_H 31 | #define GW_EVENT_H 32 | #include 33 | 34 | #include "gw_timer.h" 35 | #include "gw_msgs.h" 36 | #include "gw_type.h" 37 | 38 | #define GW_ENABLE 1 39 | #define GW_DISABLE 0 40 | 41 | typedef void (*p_init_func)(void); 42 | typedef void (*p_exec_func)(void); 43 | 44 | typedef void (*p_exec_args_func)(void* args); 45 | 46 | struct gw_event { 47 | const char* name; //事件名称 48 | uint32_t id; //时间ID 49 | uint8_t type; //事件类型 50 | uint8_t status; //事件状态 51 | uint32_t priority; //事件优先级 52 | uint32_t timestamp; //时间戳 53 | uint32_t poll_time; //轮询执行时间 54 | gw_msg_t msg; //消息 55 | p_init_func init_task; //任务初始化函数 56 | p_exec_func exec_task; //轮询任务回调函数 57 | p_exec_args_func exec_args_task;//带参数的回调函数 58 | struct gw_timer* g_timer; //全局定时器 59 | }; 60 | 61 | typedef struct gw_event gw_event_t; 62 | 63 | void gw_event_init(gw_event_t *pev, const char* name, DATA_TYPE id); 64 | void gw_event_set_id(gw_event_t *pev, DATA_TYPE id); 65 | void gw_event_set_type(gw_event_t *pev, uint8_t type); 66 | void gw_event_set_msg(gw_event_t *pev, const gw_msg_t msg); 67 | void gw_event_set_status(gw_event_t *pev, uint8_t status); 68 | void gw_event_set_init_func(gw_event_t *pev, p_init_func init_task); 69 | void gw_event_set_exec_task(gw_event_t *pev, p_exec_func exec_task); 70 | void gw_event_set_exec_args_task(gw_event_t *pev, p_exec_args_func exec_args_task); 71 | void gw_event_set_poll_time(gw_event_t *pev, uint32_t poll_time); 72 | void gw_event_set_priority(gw_event_t *pev, uint32_t priority); 73 | void gw_event_set_timer(gw_event_t *pev, struct gw_timer* ptimer); 74 | void gw_event_set_timestamp(gw_event_t *pev, uint32_t timestamp); 75 | 76 | DATA_TYPE gw_event_get_id(gw_event_t *pev); 77 | uint8_t gw_event_get_type(gw_event_t *pev); 78 | gw_msg_t gw_event_get_msg(gw_event_t *pev); 79 | uint8_t gw_event_get_status(gw_event_t *pev); 80 | uint32_t gw_event_get_poll_time(gw_event_t *pev); 81 | uint32_t gw_event_get_priority(gw_event_t *pev); 82 | p_init_func gw_event_get_init_func(gw_event_t *pev); 83 | p_exec_func gw_event_get_exec_task(gw_event_t *pev); 84 | p_exec_args_func gw_event_get_exec_args_task(gw_event_t *pev); 85 | struct gw_timer* gw_event_get_timer(gw_event_t *pev); 86 | 87 | #endif 88 | -------------------------------------------------------------------------------- /Source/GwDebug/gw_log.h: -------------------------------------------------------------------------------- 1 | /** 2 | ************************************************************************************************ 3 | * @file : gw_log.h 4 | * @brief : Interface to manage events 5 | * @details : None 6 | * @date : 11-09-2018 7 | * @version : v1.0.0.0 8 | * @author : UncleMac 9 | * @email : zhaojunhui1861@163.com 10 | * 11 | * @license : GNU General Public License, version 3 (GPL-3.0) 12 | * 13 | * Copyright (C)2019 UncleMac. 14 | * 15 | * This code is open source: you can redistribute it and/or modify 16 | * it under the terms of the GNU General Public License as published by 17 | * the Free Software Foundation, either version 3 of the License, or 18 | * (at your option) any later version. 19 | * 20 | * This code is distributed in the hope that it will be useful, 21 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 22 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the 23 | * GNU General Public License for more details. 24 | * 25 | * You should have received a copy of the GNU General Public License 26 | * along with this program.If not, see < https://www.gnu.org/licenses/>. 27 | ************************************************************************************************* 28 | */ 29 | #ifndef GW_LOG_H 30 | #define GW_LOG_H 31 | 32 | #include 33 | 34 | /* define compiler specific symbols */ 35 | #if defined ( __CC_ARM ) 36 | #if USE_PRINTF 37 | extern int printf(const char *, ...); 38 | #define fprintf(fmt, args...) printf( ##args) 39 | #else 40 | extern int usart_printf(const char *, ...); 41 | #define fprintf(fmt, args...) usart_printf( ##args) 42 | #endif 43 | #elif defined ( __GNUC__ ) 44 | 45 | #if USE_PRINTF 46 | extern int printf(const char *, ...); 47 | #define fprintf(fmt, args...) printf( ##args) 48 | #else 49 | extern int usart_printf(const char *, ...); 50 | #define fprintf(fmt, args...) usart_printf(##args) 51 | #endif 52 | 53 | #endif //endif of __CC_ARM __GNUC__ 54 | 55 | 56 | #define LOG_OUTPUT 1 57 | 58 | #define LOG_DEBUG 1 59 | #define LOG_INFO 2 60 | #define LOG_KEY 3 61 | #define DEBUG_WARRING 4 62 | #define DEBUG_ERROR 5 63 | 64 | 65 | #if LOG_OUTPUT 66 | #if (LOG_OUTPUT == LOG_DEBUG) 67 | #define Log_d(tag, format, ...) fprintf (tag " Debug:<%s @%d @%s> "format"\r\n", __func__, __LINE__, __FILE__, ##__VA_ARGS__) 68 | #else 69 | #define Log_d(tag, format, ...) 70 | #endif 71 | #if (LOG_OUTPUT == LOG_INFO) 72 | #define Log_i(tag, format, ...) fprintf (tag " Info:<%s @%d @%s> "format"\r\n", __func__, __LINE__, __FILE__, ##__VA_ARGS__) 73 | #else 74 | #define Log_i(tag, format, ...) 75 | #endif 76 | #if (LOG_OUTPUT == LOG_KEY) 77 | #define Log_k(tag, format, ...) fprintf (tag " Key:<%s @%d @%s> "format"\r\n", __func__, __LINE__, __FILE__, ##__VA_ARGS__) 78 | #else 79 | #define Log_k(tag, format, ...) 80 | #endif 81 | #if (LOG_OUTPUT == DEBUG_WARRING) 82 | #define Log_w(tag, format, ...) fprintf (tag " Warring:<%s @%d @%s> "format"\r\n", __func__, __LINE__, __FILE__, ##__VA_ARGS__) 83 | #else 84 | #define Log_w(tag, format, ...) 85 | #endif 86 | #if (LOG_OUTPUT == DEBUG_ERROR) 87 | #define Log_e(tag, format, ...) fprintf (tag " Error:<%s @%d @%s> "format"\r\n", __func__, __LINE__, __FILE__, ##__VA_ARGS__) 88 | #else 89 | #define Log_e(tag, format, ...) 90 | #endif 91 | #else /* LOG_OUTPUT */ 92 | #define Log_d(tag, format, ...) 93 | #define Log_i(tag, format, ...) 94 | #define Log_k(tag, format, ...) 95 | #define Log_w(tag, format, ...) 96 | #define Log_e(tag, format, ...) 97 | 98 | #endif 99 | 100 | #endif //endif for GW_LOG_H 101 | -------------------------------------------------------------------------------- /Source/Foc/foc.h: -------------------------------------------------------------------------------- 1 | #ifndef FOC_H 2 | #define FOC_H 3 | #include 4 | #include "pid_regulator.h" 5 | #include "svpwm_module.h" 6 | #include "svpwm_math.h" 7 | #include "feed_forward.h" 8 | 9 | #define SPEED_CONTROL (uint32_t)0x0001 10 | #define FIRST_START (uint32_t)0x0002 11 | #define START_UP_FAILURE (uint32_t)0x0004 12 | #define SPEED_FEEDBACK (uint32_t)0x0008 13 | #define BRAKE_ON (uint32_t)0x0010 14 | #define OVERHEAT (uint32_t)0x0100 15 | #define OVER_CURRENT (uint32_t)0x0200 16 | #define OVER_VOLTAGE (uint32_t)0x0400 17 | #define UNDER_VOLTAGE (uint32_t)0x0800 18 | 19 | // 20 | 21 | int16_t set_up_current(int16_t c); 22 | 23 | /* default values for Torque control loop */ 24 | #define PID_TORQUE_REFERENCE (int16_t)set_up_current(0) //(N.b: that's the reference init 25 | //value in both torque and speed control) 26 | //Vq 27 | #define PID_TORQUE_KP_DEFAULT (int16_t)1 28 | #define PID_TORQUE_KI_DEFAULT (int16_t)1 29 | #define PID_TORQUE_KD_DEFAULT (int16_t)10 30 | 31 | /* default values for Flux control loop */ 32 | //Vd 33 | #define PID_FLUX_REFERENCE (int16_t)set_up_current(500) 34 | 35 | #define PID_FLUX_KP_DEFAULT (int16_t)1 36 | #define PID_FLUX_KI_DEFAULT (int16_t)1 37 | #define PID_FLUX_KD_DEFAULT (int16_t)10 38 | 39 | // Toruqe/Flux PID parameter dividers 40 | #define TF_KPDIV ((uint16_t)(0)) 41 | #define TF_KIDIV ((uint16_t)(0)) 42 | #define TF_KDDIV ((uint16_t)(8192)) 43 | 44 | struct motor_param { 45 | int16_t Pn; 46 | int16_t In; 47 | int16_t Un; 48 | int16_t Flux; 49 | }; 50 | typedef struct motor_param motor_param_t; 51 | 52 | struct fdbk_mod { 53 | int16_t udc; 54 | int16_t theta; 55 | int16_t theta_offset; 56 | int16_t rpm; 57 | int16_t sector; 58 | 59 | int16_t ia; 60 | int16_t ib; 61 | 62 | int16_t ia_asc; 63 | int16_t ib_asc; 64 | 65 | Curr_Components cur_offset; 66 | }; 67 | typedef struct fdbk_mod fdbk_mod_t; 68 | 69 | struct foc_mod { 70 | 71 | PID_Handle_t speed_pi; // speed loop Id controller 72 | PID_Handle_t cur_d_pi; // current loop Id controller 73 | PID_Handle_t cur_q_pi; // current loop Iq controller 74 | PID_Handle_t position_pi; // positon loop pi controller 75 | 76 | ff_mod_t ffc; // feed forward controller 77 | 78 | Curr_Components cur_pre_set_dq; // current loop reference dq value 79 | Curr_Components cur_park_dq; // current loop feedback ab---park--->dq value 80 | Curr_Components cur_clark_ab; // current loop feedback AB---clark->ab value 81 | Curr_Components cur_ab; // current loop feedback AB value 82 | 83 | Volt_Components vol_pre_set_dq; 84 | Volt_Components vol_ab; 85 | Volt_Components vol_dq; 86 | Volt_Components vol_pi_out; 87 | svpwm_mod_t svpwm; // svpwm module 88 | motor_param_t motor_cfg; 89 | fdbk_mod_t feedback; 90 | int16_t angle_cnt; 91 | int16_t angle_cnt_detal; 92 | int16_t rpm_speed_set; 93 | int16_t position_set; 94 | int16_t e_theta; 95 | 96 | }; 97 | typedef struct foc_mod foc_mod_t; 98 | 99 | void foc_get_feedback(fdbk_mod_t * const pfbk); 100 | 101 | void foc_set_rpm_ref(foc_mod_t *p, int16_t data); 102 | int16_t foc_get_rpm_ref(foc_mod_t *p); 103 | void foc_set_position_ref(foc_mod_t *p, int16_t data); 104 | int16_t foc_get_position_ref(foc_mod_t *p); 105 | 106 | void foc_motor_start(foc_mod_t * const foc,uint16_t timeout, 107 | void (* const time_cbk)(int16_t)); 108 | void foc_start_up(foc_mod_t *foc,uint16_t timeout, 109 | void (* const time_cbk)(int16_t)); 110 | 111 | void foc_start_up_02(foc_mod_t *foc,uint16_t timeout,void (* const time_cbk)(int16_t)); 112 | 113 | void foc_encoder_get_zero_line_offset(void *pargs); 114 | 115 | #endif 116 | -------------------------------------------------------------------------------- /Source/Project/MDK/GCC/syscalls.c: -------------------------------------------------------------------------------- 1 | #if defined ( __GNUC__ ) 2 | /* Support files for GNU libc. Files in the system namespace go here. 3 | Files in the C namespace (ie those that do not start with an 4 | underscore) go in .c. */ 5 | 6 | //#include <_ansi.h> 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | //#include 17 | #include 18 | #include 19 | 20 | #undef errno 21 | extern int errno; 22 | 23 | #define MAX_STACK_SIZE 0x2000 24 | 25 | extern int __io_putchar(int ch) __attribute__((weak)); 26 | extern int __io_getchar(void) __attribute__((weak)); 27 | 28 | #ifndef FreeRTOS 29 | register char* stack_ptr asm("sp"); 30 | #endif 31 | 32 | caddr_t _sbrk(int incr) { 33 | extern char end asm("end"); 34 | static char* heap_end; 35 | char* prev_heap_end, *min_stack_ptr; 36 | 37 | if (heap_end == 0) { 38 | heap_end = &end; 39 | } 40 | 41 | prev_heap_end = heap_end; 42 | 43 | #ifdef FreeRTOS 44 | /* Use the NVIC offset register to locate the main stack pointer. */ 45 | min_stack_ptr = (char*)(*(unsigned int*) * (unsigned int*)0xE000ED08); 46 | /* Locate the STACK bottom address */ 47 | min_stack_ptr -= MAX_STACK_SIZE; 48 | 49 | if (heap_end + incr > min_stack_ptr) 50 | #else 51 | if (heap_end + incr > stack_ptr) 52 | #endif 53 | { 54 | // write(1, "Heap and stack collision\n", 25); 55 | // abort(); 56 | errno = ENOMEM; 57 | return (caddr_t) - 1; 58 | } 59 | 60 | heap_end += incr; 61 | 62 | return (caddr_t) prev_heap_end; 63 | } 64 | 65 | /* 66 | * _gettimeofday primitive (Stub function) 67 | * */ 68 | int _gettimeofday (struct timeval* tp, struct timezone* tzp) { 69 | /* Return fixed data for the timezone. */ 70 | if (tzp) { 71 | tzp->tz_minuteswest = 0; 72 | tzp->tz_dsttime = 0; 73 | } 74 | 75 | return 0; 76 | } 77 | void initialise_monitor_handles() { 78 | } 79 | 80 | int _getpid(void) { 81 | return 1; 82 | } 83 | 84 | int _kill(int pid, int sig) { 85 | errno = EINVAL; 86 | return -1; 87 | } 88 | 89 | void _exit (int status) { 90 | _kill(status, -1); 91 | while (1) {} 92 | } 93 | 94 | int _write(int file, char* ptr, int len) { 95 | int DataIdx; 96 | 97 | for (DataIdx = 0; DataIdx < len; DataIdx++) { 98 | __io_putchar( *ptr++ ); 99 | } 100 | return len; 101 | } 102 | 103 | int _close(int file) { 104 | return -1; 105 | } 106 | 107 | int _fstat(int file, struct stat* st) { 108 | st->st_mode = S_IFCHR; 109 | return 0; 110 | } 111 | 112 | int _isatty(int file) { 113 | return 1; 114 | } 115 | 116 | int _lseek(int file, int ptr, int dir) { 117 | return 0; 118 | } 119 | 120 | int _read(int file, char* ptr, int len) { 121 | int DataIdx; 122 | 123 | for (DataIdx = 0; DataIdx < len; DataIdx++) { 124 | *ptr++ = __io_getchar(); 125 | } 126 | 127 | return len; 128 | } 129 | 130 | int _open(char* path, int flags, ...) { 131 | /* Pretend like we always fail */ 132 | return -1; 133 | } 134 | 135 | int _wait(int* status) { 136 | errno = ECHILD; 137 | return -1; 138 | } 139 | 140 | int _unlink(char* name) { 141 | errno = ENOENT; 142 | return -1; 143 | } 144 | 145 | int _times(struct tms* buf) { 146 | return -1; 147 | } 148 | 149 | int _stat(char* file, struct stat* st) { 150 | st->st_mode = S_IFCHR; 151 | return 0; 152 | } 153 | 154 | int _link(char* old, char* new) { 155 | errno = EMLINK; 156 | return -1; 157 | } 158 | 159 | int _fork(void) { 160 | errno = EAGAIN; 161 | return -1; 162 | } 163 | 164 | int _execve(char* name, char** argv, char** env) { 165 | errno = ENOMEM; 166 | return -1; 167 | } 168 | 169 | #endif -------------------------------------------------------------------------------- /Source/Feedback/position.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "position.h" 3 | #include "stm32f10x.h" 4 | #include "stm32f10x_gpio.h" 5 | #include "stm32f10x_rcc.h" 6 | 7 | int16_t phase_signal_angle_matrix[6] = {0xd556,0x2aaa,0x0000,0x8000,0xaaac,0x5554}; 8 | 9 | volatile uint8_t first_startup_flag = 1; 10 | volatile PFUNC callback = NULL; 11 | volatile void* pargs = NULL; 12 | 13 | static void pos_rcc_init(void){ 14 | 15 | RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB | RCC_APB2Periph_AFIO,ENABLE); 16 | 17 | } 18 | 19 | static void pos_pin_init(void){ 20 | 21 | GPIO_InitTypeDef GPIO_InitStructure; 22 | GPIO_InitStructure.GPIO_Pin = PHA | PHB | PHC; 23 | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; 24 | GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; 25 | GPIO_Init(GPIOB, &GPIO_InitStructure); 26 | } 27 | 28 | static void pos_irq_init(void){ 29 | NVIC_InitTypeDef NVIC_InitStructure; 30 | EXTI_InitTypeDef EXTI_InitStructure; 31 | 32 | GPIO_EXTILineConfig(GPIO_PortSourceGPIOB, GPIO_PinSource0); 33 | EXTI_InitStructure.EXTI_Line = EXTI_Line0; 34 | EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; 35 | EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising; 36 | EXTI_Init(&EXTI_InitStructure); 37 | NVIC_InitStructure.NVIC_IRQChannel = EXTI0_IRQn; 38 | NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 3; 39 | NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2; 40 | NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; 41 | NVIC_Init(&NVIC_InitStructure); 42 | } 43 | 44 | uint8_t get_pos_pha(void){ 45 | return GPIO_ReadInputDataBit(GPIOB, PHA); 46 | } 47 | 48 | uint8_t get_pos_phb(void){ 49 | return GPIO_ReadInputDataBit(GPIOB, PHB); 50 | } 51 | 52 | uint8_t get_pos_phc(void){ 53 | return GPIO_ReadInputDataBit(GPIOB, PHC); 54 | } 55 | 56 | 57 | void pos_init(void){ 58 | pos_rcc_init(); 59 | pos_pin_init(); 60 | pos_irq_init(); 61 | } 62 | 63 | uint8_t get_pos_rotor(void){ 64 | int8_t a,b,c; 65 | a = get_pos_pha(); 66 | b = get_pos_phb(); 67 | c = get_pos_phc(); 68 | return 4*c+b*2+a; 69 | } 70 | 71 | uint8_t get_pos_rotor_2(void){ 72 | int8_t a,b,c,sector; 73 | a = get_pos_pha(); 74 | b = get_pos_phb(); 75 | c = get_pos_phc(); 76 | sector = 4*c+b*2+a; 77 | 78 | switch (sector) 79 | { 80 | case 1: 81 | sector = 2; 82 | break; 83 | case 2: 84 | sector = 6; 85 | break; 86 | case 3: 87 | sector = 1; 88 | break; 89 | case 4: 90 | sector = 4; 91 | break; 92 | case 5: 93 | sector = 3; 94 | break; 95 | case 6: 96 | sector = 5; 97 | break; 98 | } 99 | return sector; 100 | } 101 | 102 | uint8_t get_pos_rotor_3(void){ 103 | int8_t a,b,c,sector; 104 | a = get_pos_pha(); 105 | b = get_pos_phb(); 106 | c = get_pos_phc(); 107 | sector = 4*c+b*2+a; 108 | 109 | switch (sector) 110 | { 111 | case 1: 112 | sector = 6; 113 | break; 114 | case 2: 115 | sector = 2; 116 | break; 117 | case 3: 118 | sector = 1; 119 | break; 120 | case 4: 121 | sector = 4; 122 | break; 123 | case 5: 124 | sector = 5; 125 | break; 126 | case 6: 127 | sector = 3; 128 | break; 129 | } 130 | return sector; 131 | } 132 | 133 | void pos_set_cbk(PFUNC p,void *pargs){ 134 | callback = p; 135 | pargs = pargs; 136 | } 137 | void EXTI0_IRQHandler(void){ 138 | 139 | if(EXTI_GetITStatus(EXTI_Line0) == SET){ 140 | //只在启动的时候开启 141 | if(first_startup_flag == 1){ 142 | 143 | if(get_pos_pha() == INIT_PHA_VALUE 144 | && get_pos_phb() == INIT_PHB_VALUE 145 | && get_pos_phc() == INIT_PHC_VALUE){ 146 | if(callback != NULL){ 147 | #if USE_POLL_MECH 148 | first_startup_flag = 0; 149 | callback((void *)pargs); 150 | #endif 151 | } 152 | } 153 | } 154 | // TODO disable exti here 155 | } 156 | EXTI_ClearITPendingBit(EXTI_Line0); 157 | } 158 | 159 | -------------------------------------------------------------------------------- /Source/Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_crc.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f10x_crc.c 4 | * @author MCD Application Team 5 | * @version V3.5.0 6 | * @date 11-March-2011 7 | * @brief This file provides all the CRC firmware functions. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 12 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE 13 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY 14 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING 15 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE 16 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 17 | * 18 | *

© COPYRIGHT 2011 STMicroelectronics

19 | ****************************************************************************** 20 | */ 21 | 22 | /* Includes ------------------------------------------------------------------*/ 23 | #include "stm32f10x_crc.h" 24 | 25 | /** @addtogroup STM32F10x_StdPeriph_Driver 26 | * @{ 27 | */ 28 | 29 | /** @defgroup CRC 30 | * @brief CRC driver modules 31 | * @{ 32 | */ 33 | 34 | /** @defgroup CRC_Private_TypesDefinitions 35 | * @{ 36 | */ 37 | 38 | /** 39 | * @} 40 | */ 41 | 42 | /** @defgroup CRC_Private_Defines 43 | * @{ 44 | */ 45 | 46 | /** 47 | * @} 48 | */ 49 | 50 | /** @defgroup CRC_Private_Macros 51 | * @{ 52 | */ 53 | 54 | /** 55 | * @} 56 | */ 57 | 58 | /** @defgroup CRC_Private_Variables 59 | * @{ 60 | */ 61 | 62 | /** 63 | * @} 64 | */ 65 | 66 | /** @defgroup CRC_Private_FunctionPrototypes 67 | * @{ 68 | */ 69 | 70 | /** 71 | * @} 72 | */ 73 | 74 | /** @defgroup CRC_Private_Functions 75 | * @{ 76 | */ 77 | 78 | /** 79 | * @brief Resets the CRC Data register (DR). 80 | * @param None 81 | * @retval None 82 | */ 83 | void CRC_ResetDR(void) 84 | { 85 | /* Reset CRC generator */ 86 | CRC->CR = CRC_CR_RESET; 87 | } 88 | 89 | /** 90 | * @brief Computes the 32-bit CRC of a given data word(32-bit). 91 | * @param Data: data word(32-bit) to compute its CRC 92 | * @retval 32-bit CRC 93 | */ 94 | uint32_t CRC_CalcCRC(uint32_t Data) 95 | { 96 | CRC->DR = Data; 97 | 98 | return (CRC->DR); 99 | } 100 | 101 | /** 102 | * @brief Computes the 32-bit CRC of a given buffer of data word(32-bit). 103 | * @param pBuffer: pointer to the buffer containing the data to be computed 104 | * @param BufferLength: length of the buffer to be computed 105 | * @retval 32-bit CRC 106 | */ 107 | uint32_t CRC_CalcBlockCRC(uint32_t pBuffer[], uint32_t BufferLength) 108 | { 109 | uint32_t index = 0; 110 | 111 | for(index = 0; index < BufferLength; index++) 112 | { 113 | CRC->DR = pBuffer[index]; 114 | } 115 | return (CRC->DR); 116 | } 117 | 118 | /** 119 | * @brief Returns the current CRC value. 120 | * @param None 121 | * @retval 32-bit CRC 122 | */ 123 | uint32_t CRC_GetCRC(void) 124 | { 125 | return (CRC->DR); 126 | } 127 | 128 | /** 129 | * @brief Stores a 8-bit data in the Independent Data(ID) register. 130 | * @param IDValue: 8-bit value to be stored in the ID register 131 | * @retval None 132 | */ 133 | void CRC_SetIDRegister(uint8_t IDValue) 134 | { 135 | CRC->IDR = IDValue; 136 | } 137 | 138 | /** 139 | * @brief Returns the 8-bit data stored in the Independent Data(ID) register 140 | * @param None 141 | * @retval 8-bit value of the ID register 142 | */ 143 | uint8_t CRC_GetIDRegister(void) 144 | { 145 | return (CRC->IDR); 146 | } 147 | 148 | /** 149 | * @} 150 | */ 151 | 152 | /** 153 | * @} 154 | */ 155 | 156 | /** 157 | * @} 158 | */ 159 | 160 | /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ 161 | -------------------------------------------------------------------------------- /Source/Math/svpwm_math.h: -------------------------------------------------------------------------------- 1 | #ifndef SVPWM_MATH_H 2 | #define SVPWM_MATH_H 3 | #include 4 | 5 | #define FULL_MISRA_C_COMPLIANCY 1 6 | 7 | #define QTYPE int16_t 8 | #define QWTYPE int32_t 9 | #if Q_HEX 10 | #define Q15 (QTYPE)0x8000 11 | #define Q14 (QTYPE)0x4000 12 | #define Q13 (QTYPE)0x2000 13 | #define Q12 (QTYPE)0x1000 14 | #define Q11 (QTYPE)0x0800 15 | #define Q10 (QTYPE)0x0400 16 | #define Q9 (QTYPE)0x0200 17 | #define Q8 (QTYPE)0x0100 18 | #define Q7 (QTYPE)0x0080 19 | #define Q6 (QTYPE)0x0040 20 | #define Q5 (QTYPE)0x0020 21 | #define Q4 (QTYPE)0x0010 22 | #define Q3 (QTYPE)0x0008 23 | #define Q2 (QTYPE)0x0004 24 | #define Q1 (QTYPE)0x0002 25 | #define Q0 (QTYPE)0x0001 26 | #else 27 | #define Q17 (QWTYPE)131072 28 | #define Q16 (QWTYPE)65536 29 | #define Q15 (QWTYPE)32768 30 | #define Q14 (QWTYPE)16384 31 | #define Q13 (QWTYPE)8192 32 | #define Q12 (QWTYPE)4096 33 | #define Q11 (QWTYPE)2048 34 | #define Q10 (QWTYPE)1024 35 | #define Q9 (QWTYPE)512 36 | #define Q8 (QWTYPE)256 37 | #define Q7 (QWTYPE)128 38 | #define Q6 (QWTYPE)64 39 | #define Q5 (QWTYPE)32 40 | #define Q4 (QWTYPE)16 41 | #define Q3 (QWTYPE)8 42 | #define Q2 (QWTYPE)4 43 | #define Q1 (QWTYPE)2 44 | #define Q0 (QWTYPE)1 45 | #endif 46 | 47 | #define SQRT3_Q14 0x6ED9 48 | 49 | /** 50 | * @brief Two components stator current type definition 51 | */ 52 | typedef struct 53 | { 54 | int16_t qI_Component1; 55 | int16_t qI_Component2; 56 | } Curr_Components; 57 | 58 | /** 59 | * @brief Two components stator voltage type definition 60 | */ 61 | typedef struct 62 | { 63 | int16_t qV_Component1; 64 | int16_t qV_Component2; 65 | } Volt_Components; 66 | 67 | /** 68 | * @brief Trigonometrical functions type definition 69 | */ 70 | typedef struct 71 | { 72 | int16_t hCos; 73 | int16_t hSin; 74 | } Trig_Components; 75 | 76 | 77 | /** 78 | * @brief This function transforms stator currents Ia and qIb (which are 79 | * directed along axes each displaced by 120 degrees) into currents 80 | * Ialpha and Ibeta in a stationary qd reference frame. 81 | * Ialpha = Ia 82 | * Ibeta = -(2*Ib+Ia)/sqrt(3) 83 | * @param Curr_Input: stator current Ia and Ib in Curr_Components format 84 | * @retval Stator current Ialpha and Ibeta in Curr_Components format 85 | */ 86 | Curr_Components clarke( Curr_Components Curr_Input ); 87 | 88 | /** 89 | * @brief This function transforms stator currents Ialpha and Ibeta, which 90 | * belong to a stationary qd reference frame, to a rotor flux 91 | * synchronous reference frame (properly oriented), so as Iq and Id. 92 | * Id= Ialpha *sin(theta)+qIbeta *cos(Theta) 93 | * Iq=qIalpha *cos(Theta)-qIbeta *sin(Theta) 94 | * @param Curr_Input: stator current Ialpha and Ibeta in Curr_Components format 95 | * @param Theta: rotating frame angular position in q1.15 format 96 | * @retval Stator current Iq and Id in Curr_Components format 97 | */ 98 | Curr_Components park( Curr_Components Curr_Input, int16_t Theta ); 99 | 100 | /** 101 | * @brief This function transforms stator voltage qVq and qVd, that belong to 102 | * a rotor flux synchronous rotating frame, to a stationary reference 103 | * frame, so as to obtain qValpha and qVbeta: 104 | * Valfa= Vq*Cos(theta)+ Vd*Sin(theta) 105 | * Vbeta=-Vq*Sin(theta)+ Vd*Cos(theta) 106 | * @param Curr_Input: stator voltage Vq and Vd in Volt_Components format 107 | * @param Theta: rotating frame angular position in q1.15 format 108 | * @retval Stator voltage Valpha and Vbeta in Volt_Components format 109 | */ 110 | Volt_Components park_rev( Volt_Components Volt_Input, int16_t Theta ); 111 | 112 | 113 | /** 114 | * @brief This function returns cosine and sine functions of the angle fed in 115 | * input 116 | * @param hAngle: angle in q1.15 format 117 | * @retval Trig_Components Cos(angle) and Sin(angle) in Trig_Components format 118 | */ 119 | Trig_Components trig_functions( int16_t hAngle ); 120 | 121 | 122 | 123 | #endif 124 | -------------------------------------------------------------------------------- /Source/GwOS/gw_tasks.h: -------------------------------------------------------------------------------- 1 | /** 2 | ************************************************************************************************ 3 | * @file : gw_tasks.h 4 | * @brief : none 5 | * @details : none 6 | * @date : 11-09-2019 7 | * @version : v1.0.0.0 8 | * @author : UncleMac 9 | * @email : zhaojunhui1861@163.com 10 | * 11 | * @license : GNU General Public License, version 3 (GPL-3.0) 12 | * 13 | * Copyright (C)2019 UncleMac. 14 | * 15 | * This code is open source: you can redistribute it and/or modify 16 | * it under the terms of the GNU General Public License as published by 17 | * the Free Software Foundation, either version 3 of the License, or 18 | * (at your option) any later version. 19 | * 20 | * This dll is distributed in the hope that it will be useful, 21 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 22 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the 23 | * GNU General Public License for more details. 24 | * 25 | * You should have received a copy of the GNU General Public License 26 | * along with this program.If not, see < https://www.gnu.org/licenses/>. 27 | ************************************************************************************************* 28 | */ 29 | 30 | #ifndef GW_TASKS_H 31 | #define GW_TASKS_H 32 | #include "gw_event.h" 33 | 34 | /** 35 | * @brief Initialize the task list 36 | */ 37 | void gw_task_list_init(void); 38 | 39 | /** 40 | * @brief create a task 41 | * @param name - pointer to ths string of task name 42 | * @param taskid - task id 43 | * @param type - task type, see gw_type.h 44 | * @param status - task status, see gw_type.h 45 | * @param poll_time - time circle to schedule task 46 | * @param priority - priority of task, low value is high priority 47 | * @param init_func - callback when initialization 48 | * @param p_exec_func - callback without args 49 | * @param p_exec_args_func - callback with args 50 | */ 51 | void gw_task_create(const char *name, DATA_TYPE taskid,uint8_t type, 52 | uint8_t status, uint32_t poll_time,uint32_t priority, 53 | p_init_func init_func, 54 | p_exec_func exec_task, 55 | p_exec_args_func exec_args_task); 56 | 57 | /** 58 | * @brief Creates a callback function without parameters for the task 59 | * @param name - pointer to ths string of task name 60 | * @param taskid - task id 61 | * @param type - task type, see gw_type.h 62 | * @param status - task status, see gw_type.h 63 | * @param poll_time - time circle to schedule task 64 | * @param priority - priority of task, low value is high priority 65 | * @param init_func - callback when initialization 66 | * @param p_exec_func - callback without args 67 | */ 68 | void gw_task_void_create(const char *name, DATA_TYPE taskid,uint8_t type, uint8_t status, uint32_t poll_time, 69 | p_init_func init_func, 70 | p_exec_func exec_func); 71 | 72 | /** 73 | * @brief Creates a callback function with parameters for the task 74 | * @param name - pointer to ths string of task name 75 | * @param taskid - task id 76 | * @param type - task type, see gw_type.h 77 | * @param status - task status, see gw_type.h 78 | * @param poll_time - time circle to schedule task 79 | * @param priority - priority of task, low value is high priority 80 | * @param init_func - callback when initialization 81 | * @param p_exec_args_func - callback with args 82 | */ 83 | void gw_task_args_create(const char *name, DATA_TYPE taskid,uint8_t type, uint8_t status, uint32_t poll_time, 84 | p_init_func init_func, 85 | p_exec_args_func exec_func); 86 | 87 | /** 88 | * @brief Task scheduling function 89 | * if task is ready, status will be set GW_ENABLE 90 | */ 91 | void gw_task_schedule(void); 92 | 93 | /** 94 | * @brief Task execution function 95 | * The ready task will be executed 96 | */ 97 | void gw_task_process(void); 98 | 99 | /** 100 | * @brief The initialization task will be executed 101 | */ 102 | void gw_task_init_process(void); 103 | 104 | #endif 105 | 106 | -------------------------------------------------------------------------------- /Source/Libraries/STM32F10x_StdPeriph_Driver/inc/stm32f10x_dbgmcu.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f10x_dbgmcu.h 4 | * @author MCD Application Team 5 | * @version V3.5.0 6 | * @date 11-March-2011 7 | * @brief This file contains all the functions prototypes for the DBGMCU 8 | * firmware library. 9 | ****************************************************************************** 10 | * @attention 11 | * 12 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 13 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE 14 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY 15 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING 16 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE 17 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 18 | * 19 | *

© COPYRIGHT 2011 STMicroelectronics

20 | ****************************************************************************** 21 | */ 22 | 23 | /* Define to prevent recursive inclusion -------------------------------------*/ 24 | #ifndef __STM32F10x_DBGMCU_H 25 | #define __STM32F10x_DBGMCU_H 26 | 27 | #ifdef __cplusplus 28 | extern "C" { 29 | #endif 30 | 31 | /* Includes ------------------------------------------------------------------*/ 32 | #include "stm32f10x.h" 33 | 34 | /** @addtogroup STM32F10x_StdPeriph_Driver 35 | * @{ 36 | */ 37 | 38 | /** @addtogroup DBGMCU 39 | * @{ 40 | */ 41 | 42 | /** @defgroup DBGMCU_Exported_Types 43 | * @{ 44 | */ 45 | 46 | /** 47 | * @} 48 | */ 49 | 50 | /** @defgroup DBGMCU_Exported_Constants 51 | * @{ 52 | */ 53 | 54 | #define DBGMCU_SLEEP ((uint32_t)0x00000001) 55 | #define DBGMCU_STOP ((uint32_t)0x00000002) 56 | #define DBGMCU_STANDBY ((uint32_t)0x00000004) 57 | #define DBGMCU_IWDG_STOP ((uint32_t)0x00000100) 58 | #define DBGMCU_WWDG_STOP ((uint32_t)0x00000200) 59 | #define DBGMCU_TIM1_STOP ((uint32_t)0x00000400) 60 | #define DBGMCU_TIM2_STOP ((uint32_t)0x00000800) 61 | #define DBGMCU_TIM3_STOP ((uint32_t)0x00001000) 62 | #define DBGMCU_TIM4_STOP ((uint32_t)0x00002000) 63 | #define DBGMCU_CAN1_STOP ((uint32_t)0x00004000) 64 | #define DBGMCU_I2C1_SMBUS_TIMEOUT ((uint32_t)0x00008000) 65 | #define DBGMCU_I2C2_SMBUS_TIMEOUT ((uint32_t)0x00010000) 66 | #define DBGMCU_TIM8_STOP ((uint32_t)0x00020000) 67 | #define DBGMCU_TIM5_STOP ((uint32_t)0x00040000) 68 | #define DBGMCU_TIM6_STOP ((uint32_t)0x00080000) 69 | #define DBGMCU_TIM7_STOP ((uint32_t)0x00100000) 70 | #define DBGMCU_CAN2_STOP ((uint32_t)0x00200000) 71 | #define DBGMCU_TIM15_STOP ((uint32_t)0x00400000) 72 | #define DBGMCU_TIM16_STOP ((uint32_t)0x00800000) 73 | #define DBGMCU_TIM17_STOP ((uint32_t)0x01000000) 74 | #define DBGMCU_TIM12_STOP ((uint32_t)0x02000000) 75 | #define DBGMCU_TIM13_STOP ((uint32_t)0x04000000) 76 | #define DBGMCU_TIM14_STOP ((uint32_t)0x08000000) 77 | #define DBGMCU_TIM9_STOP ((uint32_t)0x10000000) 78 | #define DBGMCU_TIM10_STOP ((uint32_t)0x20000000) 79 | #define DBGMCU_TIM11_STOP ((uint32_t)0x40000000) 80 | 81 | #define IS_DBGMCU_PERIPH(PERIPH) ((((PERIPH) & 0x800000F8) == 0x00) && ((PERIPH) != 0x00)) 82 | /** 83 | * @} 84 | */ 85 | 86 | /** @defgroup DBGMCU_Exported_Macros 87 | * @{ 88 | */ 89 | 90 | /** 91 | * @} 92 | */ 93 | 94 | /** @defgroup DBGMCU_Exported_Functions 95 | * @{ 96 | */ 97 | 98 | uint32_t DBGMCU_GetREVID(void); 99 | uint32_t DBGMCU_GetDEVID(void); 100 | void DBGMCU_Config(uint32_t DBGMCU_Periph, FunctionalState NewState); 101 | 102 | #ifdef __cplusplus 103 | } 104 | #endif 105 | 106 | #endif /* __STM32F10x_DBGMCU_H */ 107 | /** 108 | * @} 109 | */ 110 | 111 | /** 112 | * @} 113 | */ 114 | 115 | /** 116 | * @} 117 | */ 118 | 119 | /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ 120 | -------------------------------------------------------------------------------- /Source/Libraries/STM32F10x_StdPeriph_Driver/inc/stm32f10x_iwdg.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f10x_iwdg.h 4 | * @author MCD Application Team 5 | * @version V3.5.0 6 | * @date 11-March-2011 7 | * @brief This file contains all the functions prototypes for the IWDG 8 | * firmware library. 9 | ****************************************************************************** 10 | * @attention 11 | * 12 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 13 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE 14 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY 15 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING 16 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE 17 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 18 | * 19 | *

© COPYRIGHT 2011 STMicroelectronics

20 | ****************************************************************************** 21 | */ 22 | 23 | /* Define to prevent recursive inclusion -------------------------------------*/ 24 | #ifndef __STM32F10x_IWDG_H 25 | #define __STM32F10x_IWDG_H 26 | 27 | #ifdef __cplusplus 28 | extern "C" { 29 | #endif 30 | 31 | /* Includes ------------------------------------------------------------------*/ 32 | #include "stm32f10x.h" 33 | 34 | /** @addtogroup STM32F10x_StdPeriph_Driver 35 | * @{ 36 | */ 37 | 38 | /** @addtogroup IWDG 39 | * @{ 40 | */ 41 | 42 | /** @defgroup IWDG_Exported_Types 43 | * @{ 44 | */ 45 | 46 | /** 47 | * @} 48 | */ 49 | 50 | /** @defgroup IWDG_Exported_Constants 51 | * @{ 52 | */ 53 | 54 | /** @defgroup IWDG_WriteAccess 55 | * @{ 56 | */ 57 | 58 | #define IWDG_WriteAccess_Enable ((uint16_t)0x5555) 59 | #define IWDG_WriteAccess_Disable ((uint16_t)0x0000) 60 | #define IS_IWDG_WRITE_ACCESS(ACCESS) (((ACCESS) == IWDG_WriteAccess_Enable) || \ 61 | ((ACCESS) == IWDG_WriteAccess_Disable)) 62 | /** 63 | * @} 64 | */ 65 | 66 | /** @defgroup IWDG_prescaler 67 | * @{ 68 | */ 69 | 70 | #define IWDG_Prescaler_4 ((uint8_t)0x00) 71 | #define IWDG_Prescaler_8 ((uint8_t)0x01) 72 | #define IWDG_Prescaler_16 ((uint8_t)0x02) 73 | #define IWDG_Prescaler_32 ((uint8_t)0x03) 74 | #define IWDG_Prescaler_64 ((uint8_t)0x04) 75 | #define IWDG_Prescaler_128 ((uint8_t)0x05) 76 | #define IWDG_Prescaler_256 ((uint8_t)0x06) 77 | #define IS_IWDG_PRESCALER(PRESCALER) (((PRESCALER) == IWDG_Prescaler_4) || \ 78 | ((PRESCALER) == IWDG_Prescaler_8) || \ 79 | ((PRESCALER) == IWDG_Prescaler_16) || \ 80 | ((PRESCALER) == IWDG_Prescaler_32) || \ 81 | ((PRESCALER) == IWDG_Prescaler_64) || \ 82 | ((PRESCALER) == IWDG_Prescaler_128)|| \ 83 | ((PRESCALER) == IWDG_Prescaler_256)) 84 | /** 85 | * @} 86 | */ 87 | 88 | /** @defgroup IWDG_Flag 89 | * @{ 90 | */ 91 | 92 | #define IWDG_FLAG_PVU ((uint16_t)0x0001) 93 | #define IWDG_FLAG_RVU ((uint16_t)0x0002) 94 | #define IS_IWDG_FLAG(FLAG) (((FLAG) == IWDG_FLAG_PVU) || ((FLAG) == IWDG_FLAG_RVU)) 95 | #define IS_IWDG_RELOAD(RELOAD) ((RELOAD) <= 0xFFF) 96 | /** 97 | * @} 98 | */ 99 | 100 | /** 101 | * @} 102 | */ 103 | 104 | /** @defgroup IWDG_Exported_Macros 105 | * @{ 106 | */ 107 | 108 | /** 109 | * @} 110 | */ 111 | 112 | /** @defgroup IWDG_Exported_Functions 113 | * @{ 114 | */ 115 | 116 | void IWDG_WriteAccessCmd(uint16_t IWDG_WriteAccess); 117 | void IWDG_SetPrescaler(uint8_t IWDG_Prescaler); 118 | void IWDG_SetReload(uint16_t Reload); 119 | void IWDG_ReloadCounter(void); 120 | void IWDG_Enable(void); 121 | FlagStatus IWDG_GetFlagStatus(uint16_t IWDG_FLAG); 122 | 123 | #ifdef __cplusplus 124 | } 125 | #endif 126 | 127 | #endif /* __STM32F10x_IWDG_H */ 128 | /** 129 | * @} 130 | */ 131 | 132 | /** 133 | * @} 134 | */ 135 | 136 | /** 137 | * @} 138 | */ 139 | 140 | /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ 141 | -------------------------------------------------------------------------------- /Source/Libraries/STM32F10x_StdPeriph_Driver/inc/stm32f10x_rtc.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f10x_rtc.h 4 | * @author MCD Application Team 5 | * @version V3.5.0 6 | * @date 11-March-2011 7 | * @brief This file contains all the functions prototypes for the RTC firmware 8 | * library. 9 | ****************************************************************************** 10 | * @attention 11 | * 12 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 13 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE 14 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY 15 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING 16 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE 17 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 18 | * 19 | *

© COPYRIGHT 2011 STMicroelectronics

20 | ****************************************************************************** 21 | */ 22 | 23 | /* Define to prevent recursive inclusion -------------------------------------*/ 24 | #ifndef __STM32F10x_RTC_H 25 | #define __STM32F10x_RTC_H 26 | 27 | #ifdef __cplusplus 28 | extern "C" { 29 | #endif 30 | 31 | /* Includes ------------------------------------------------------------------*/ 32 | #include "stm32f10x.h" 33 | 34 | /** @addtogroup STM32F10x_StdPeriph_Driver 35 | * @{ 36 | */ 37 | 38 | /** @addtogroup RTC 39 | * @{ 40 | */ 41 | 42 | /** @defgroup RTC_Exported_Types 43 | * @{ 44 | */ 45 | 46 | /** 47 | * @} 48 | */ 49 | 50 | /** @defgroup RTC_Exported_Constants 51 | * @{ 52 | */ 53 | 54 | /** @defgroup RTC_interrupts_define 55 | * @{ 56 | */ 57 | 58 | #define RTC_IT_OW ((uint16_t)0x0004) /*!< Overflow interrupt */ 59 | #define RTC_IT_ALR ((uint16_t)0x0002) /*!< Alarm interrupt */ 60 | #define RTC_IT_SEC ((uint16_t)0x0001) /*!< Second interrupt */ 61 | #define IS_RTC_IT(IT) ((((IT) & (uint16_t)0xFFF8) == 0x00) && ((IT) != 0x00)) 62 | #define IS_RTC_GET_IT(IT) (((IT) == RTC_IT_OW) || ((IT) == RTC_IT_ALR) || \ 63 | ((IT) == RTC_IT_SEC)) 64 | /** 65 | * @} 66 | */ 67 | 68 | /** @defgroup RTC_interrupts_flags 69 | * @{ 70 | */ 71 | 72 | #define RTC_FLAG_RTOFF ((uint16_t)0x0020) /*!< RTC Operation OFF flag */ 73 | #define RTC_FLAG_RSF ((uint16_t)0x0008) /*!< Registers Synchronized flag */ 74 | #define RTC_FLAG_OW ((uint16_t)0x0004) /*!< Overflow flag */ 75 | #define RTC_FLAG_ALR ((uint16_t)0x0002) /*!< Alarm flag */ 76 | #define RTC_FLAG_SEC ((uint16_t)0x0001) /*!< Second flag */ 77 | #define IS_RTC_CLEAR_FLAG(FLAG) ((((FLAG) & (uint16_t)0xFFF0) == 0x00) && ((FLAG) != 0x00)) 78 | #define IS_RTC_GET_FLAG(FLAG) (((FLAG) == RTC_FLAG_RTOFF) || ((FLAG) == RTC_FLAG_RSF) || \ 79 | ((FLAG) == RTC_FLAG_OW) || ((FLAG) == RTC_FLAG_ALR) || \ 80 | ((FLAG) == RTC_FLAG_SEC)) 81 | #define IS_RTC_PRESCALER(PRESCALER) ((PRESCALER) <= 0xFFFFF) 82 | 83 | /** 84 | * @} 85 | */ 86 | 87 | /** 88 | * @} 89 | */ 90 | 91 | /** @defgroup RTC_Exported_Macros 92 | * @{ 93 | */ 94 | 95 | /** 96 | * @} 97 | */ 98 | 99 | /** @defgroup RTC_Exported_Functions 100 | * @{ 101 | */ 102 | 103 | void RTC_ITConfig(uint16_t RTC_IT, FunctionalState NewState); 104 | void RTC_EnterConfigMode(void); 105 | void RTC_ExitConfigMode(void); 106 | uint32_t RTC_GetCounter(void); 107 | void RTC_SetCounter(uint32_t CounterValue); 108 | void RTC_SetPrescaler(uint32_t PrescalerValue); 109 | void RTC_SetAlarm(uint32_t AlarmValue); 110 | uint32_t RTC_GetDivider(void); 111 | void RTC_WaitForLastTask(void); 112 | void RTC_WaitForSynchro(void); 113 | FlagStatus RTC_GetFlagStatus(uint16_t RTC_FLAG); 114 | void RTC_ClearFlag(uint16_t RTC_FLAG); 115 | ITStatus RTC_GetITStatus(uint16_t RTC_IT); 116 | void RTC_ClearITPendingBit(uint16_t RTC_IT); 117 | 118 | #ifdef __cplusplus 119 | } 120 | #endif 121 | 122 | #endif /* __STM32F10x_RTC_H */ 123 | /** 124 | * @} 125 | */ 126 | 127 | /** 128 | * @} 129 | */ 130 | 131 | /** 132 | * @} 133 | */ 134 | 135 | /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ 136 | -------------------------------------------------------------------------------- /Source/User/motor_protocol.c: -------------------------------------------------------------------------------- 1 | #include "motor_protocol.h" 2 | #include "user_config.h" 3 | #include "user_state_machine.h" 4 | #include "task_motor_control.h" 5 | 6 | #include "usart_driver.h" 7 | #include "foc.h" 8 | 9 | extern foc_mod_t foc_obj; 10 | 11 | motor_cmd_mod_t user_cmd_mod = { 12 | .head = 0, 13 | .cmd = 0, 14 | .option = 0, 15 | .data = 0, 16 | .tail = 0, 17 | .process_flag = 0 18 | }; 19 | 20 | static __maybe_unused void process_basic_cmd(motor_cmd_mod_t *pcmd); 21 | static __maybe_unused void process_cur_pid_cmd(motor_cmd_mod_t *pcmd); 22 | static __maybe_unused void process_spd_pid_cmd(motor_cmd_mod_t *pcmd); 23 | static __maybe_unused void process_pos_pid_cmd(motor_cmd_mod_t *pcmd); 24 | static __maybe_unused void process_ffc_cmd(motor_cmd_mod_t *pcmd); 25 | 26 | int8_t motor_cmd_is_valid(motor_cmd_mod_t *pcmd){ 27 | if(pcmd->head == PACKAGE_HEAD && pcmd->tail == PACKAGE_TAIL){ 28 | return 1; 29 | } 30 | return -1; 31 | } 32 | 33 | void motor_get_cmd_from_uart(void *pargs){ 34 | 35 | if(pargs == NULL){ 36 | return; 37 | } 38 | uart_mod_t *p = pargs; 39 | if(p->rx_dat_len > 0 && p->rx_dat_len == PACKAGE_SIZE){ 40 | if(p->rx_buf[0] == PACKAGE_HEAD 41 | && p->rx_buf[PACKAGE_SIZE - 1] == PACKAGE_TAIL){ 42 | user_cmd_mod.head = p->rx_buf[0]; 43 | user_cmd_mod.cmd.value_n[0] = p->rx_buf[1]; 44 | user_cmd_mod.cmd.value_n[1] = p->rx_buf[2]; 45 | 46 | user_cmd_mod.option = p->rx_buf[3]; 47 | 48 | user_cmd_mod.data.value_n[0] = p->rx_buf[4]; 49 | user_cmd_mod.data.value_n[1] = p->rx_buf[5]; 50 | user_cmd_mod.data.value_n[2] = p->rx_buf[6]; 51 | user_cmd_mod.data.value_n[3] = p->rx_buf[7]; 52 | 53 | user_cmd_mod.tail = p->rx_buf[PACKAGE_SIZE - 1]; 54 | user_cmd_mod.process_flag = 1; 55 | } 56 | } 57 | p->rx_dat_len = 0; 58 | 59 | } 60 | 61 | void motor_cmd_process(motor_cmd_mod_t *pcmd){ 62 | uint16_t cmd_type = 0x0000; 63 | pcmd->process_flag = 0; 64 | cmd_type = (pcmd->cmd.value & MOTOR_CMD_MASK)>>MOTOR_CMD_SHIFT; 65 | switch(cmd_type){ 66 | case 0: 67 | process_basic_cmd(pcmd); 68 | break; 69 | case 1: 70 | process_cur_pid_cmd(pcmd); 71 | break; 72 | case 2: 73 | process_spd_pid_cmd(pcmd); 74 | break; 75 | case 3: 76 | process_pos_pid_cmd(pcmd); 77 | break; 78 | case 4: 79 | process_ffc_cmd(pcmd); 80 | break; 81 | } 82 | } 83 | 84 | static void process_basic_cmd(motor_cmd_mod_t *pcmd){ 85 | switch(pcmd->cmd.value){ 86 | case M_SYS_RESET: 87 | soft_reset(); 88 | break; 89 | case M_STOP: 90 | if(stm_get_cur_state(&motor_state) == RUN){ 91 | stm_set_next_state(&motor_state, STOP); 92 | } 93 | break; 94 | case M_RUN_RPM: 95 | if(stm_get_cur_state(&motor_state) == STOP){ 96 | stm_set_next_state(&motor_state, RUN); 97 | task_motor_pwm_enable(); 98 | } 99 | if(pcmd->option == DIR_FORWARD){ 100 | foc_set_rpm_ref(&foc_obj, pcmd->data.value); 101 | }else{ 102 | foc_set_rpm_ref(&foc_obj, -pcmd->data.value); 103 | } 104 | break; 105 | case M_RUN_POS: 106 | if(stm_get_cur_state(&motor_state) == STOP){ 107 | stm_set_next_state(&motor_state, RUN); 108 | task_motor_pwm_enable(); 109 | } 110 | foc_set_position_ref(&foc_obj,pcmd->data.value); 111 | 112 | break; 113 | case M_STARTUP: 114 | if(stm_get_cur_state(&motor_state) == IDLE){ 115 | stm_set_next_state(&motor_state, START_UP); 116 | } 117 | break; 118 | } 119 | } 120 | 121 | static void process_cur_pid_cmd(motor_cmd_mod_t *pcmd){ 122 | 123 | switch(pcmd->cmd.value){ 124 | case PID_CUR_KI: 125 | break; 126 | case PID_CUR_KIDIV: 127 | break; 128 | case PID_CUR_KP: 129 | break; 130 | case PID_CUR_KPDIV: 131 | break; 132 | } 133 | } 134 | 135 | static void process_spd_pid_cmd(motor_cmd_mod_t *pcmd){ 136 | 137 | switch(pcmd->cmd.value){ 138 | case PID_SPD_KI: 139 | break; 140 | case PID_SPD_KIDIV: 141 | break; 142 | case PID_SPD_KP: 143 | break; 144 | case PID_SPD_KPDIV: 145 | break; 146 | } 147 | } 148 | 149 | static void process_pos_pid_cmd(motor_cmd_mod_t *pcmd){ 150 | 151 | switch(pcmd->cmd.value){ 152 | case PID_POS_KI: 153 | break; 154 | case PID_POS_KIDIV: 155 | break; 156 | case PID_POS_KP: 157 | break; 158 | case PID_POS_KPDIV: 159 | break; 160 | } 161 | } 162 | 163 | static void process_ffc_cmd(motor_cmd_mod_t *pcmd){ 164 | switch(pcmd->cmd.value){ 165 | case FFC_A_FACTOR: 166 | break; 167 | case FFC_B_FACTOR: 168 | break; 169 | 170 | } 171 | } -------------------------------------------------------------------------------- /Source/GwOS/gw_msgs.h: -------------------------------------------------------------------------------- 1 | /** 2 | ************************************************************************************************ 3 | * @file : gw_msgs.h 4 | * @brief : 5 | * @details : 6 | * @date : 11-09-2019 7 | * @version : v1.0.0.0 8 | * @author : UncleMac 9 | * @email : zhaojunhui1861@163.com 10 | * 11 | * @license : GNU General Public License, version 3 (GPL-3.0) 12 | * 13 | * Copyright (C)2019 UncleMac. 14 | * 15 | * This code is open source: you can redistribute it and/or modify 16 | * it under the terms of the GNU General Public License as published by 17 | * the Free Software Foundation, either version 3 of the License, or 18 | * (at your option) any later version. 19 | * 20 | * This code is distributed in the hope that it will be useful, 21 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 22 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the 23 | * GNU General Public License for more details. 24 | * 25 | * You should have received a copy of the GNU General Public License 26 | * along with this program.If not, see < https://www.gnu.org/licenses/>. 27 | ************************************************************************************************* 28 | */ 29 | 30 | #ifndef GW_MSGS_H 31 | #define GW_MSGS_H 32 | 33 | #define MSGS_FIFO_SIZE 10 34 | #include "gw_type.h" 35 | 36 | struct gw_msg_mod{ 37 | DATA_TYPE task_id; 38 | void* pstr; 39 | }; 40 | typedef struct gw_msg_mod gw_msg_t; 41 | 42 | struct gw_msg_fifo_mod{ 43 | uint8_t size; 44 | gw_msg_t msgs[MSGS_FIFO_SIZE]; 45 | uint8_t front; 46 | uint8_t rear; 47 | }; 48 | 49 | typedef struct gw_msg_fifo_mod gw_msg_fifo_t; 50 | 51 | extern gw_msg_fifo_t msg_fifo; 52 | 53 | /** 54 | * @brief Initialize the ring fifo queue 55 | */ 56 | void gw_msg_fifo_init(gw_msg_fifo_t * const pfifo); 57 | 58 | /** 59 | * @brief Gets a pointer to the global message queue 60 | */ 61 | gw_msg_fifo_t* gw_msg_fifo_get_pointer(void); 62 | 63 | /** 64 | * @brief Empty the ring fifo queue 65 | */ 66 | void gw_msg_fifo_clear(gw_msg_fifo_t * const pfifo); 67 | 68 | /** 69 | * @brief Initialize a single message 70 | * @param pmsg - pointer to the msg 71 | * @param id - the id of task 72 | */ 73 | void gw_msg_init(gw_msg_t* const pmsg, DATA_TYPE id); 74 | 75 | /** 76 | * @brief Check if the queue is full 77 | * @param pfifo - pointer to the fifo 78 | * @return GW_RESULT 79 | */ 80 | GW_RESULT gw_msg_fifo_is_full(gw_msg_fifo_t* const pfifo); 81 | 82 | /** 83 | * @brief Check if the queue is empty 84 | * @param pfifo - pointer to the fifo 85 | * @return GW_RESULT 86 | */ 87 | GW_RESULT gw_msg_fifo_is_empty(gw_msg_fifo_t* const pfifo); 88 | 89 | /** 90 | * @brief Enqueue up for a message 91 | * @param pfifo - pointer to the fifo 92 | * @param pmsg - the pointer to the intput message 93 | * @return GW_RESULT 94 | */ 95 | GW_RESULT gw_msg_fifo_enqueue(gw_msg_fifo_t* const pfifo, 96 | gw_msg_t* const pmsg); 97 | 98 | /** 99 | * @brief Queue up for a message 100 | * @param pfifo - pointer to the fifo 101 | * @param pmsg - the pointer to the output message 102 | * @return GW_RESULT 103 | */ 104 | GW_RESULT gw_msg_fifo_dequeue(gw_msg_fifo_t* const pfifo, 105 | gw_msg_t* const pmsg); 106 | 107 | /** 108 | * @brief Sends a message to the task with the specified ID 109 | * @param taskid - the specified ID of the target task 110 | * @param pfifo - pointer to the fifo 111 | * @param pmsg - the pointer to the message will be sent 112 | * @return GW_RESULT 113 | */ 114 | GW_RESULT gw_msg_send_msg(uint32_t taskid, gw_msg_fifo_t* const pfifo, 115 | gw_msg_t* const pmsg); 116 | 117 | /** 118 | * @brief Sends a string to the task with the specified ID 119 | * @param taskid - the specified ID of the target task 120 | * @param pfifo - pointer to the fifo 121 | * @param pmsg - the pointer to the string will be sent 122 | * @return GW_RESULT 123 | */ 124 | GW_RESULT gw_msg_send_str(uint32_t taskid, gw_msg_fifo_t* const pfifo, 125 | const char *pstr); 126 | 127 | /** 128 | * @brief Receives a message with the specified task ID from the message queue 129 | * @param taskid - the specified ID of the target task 130 | * @param pfifo - pointer to the fifo 131 | * @param pmsg - pmsg - the pointer to the output message 132 | * @return GW_RESULT 133 | */ 134 | GW_RESULT gw_msg_receive(uint32_t taskid, gw_msg_fifo_t* const pfifo, 135 | gw_msg_t* const pmsg); 136 | 137 | #endif 138 | -------------------------------------------------------------------------------- /Source/GwOS/gw_fifo.c: -------------------------------------------------------------------------------- 1 | /** 2 | ************************************************************************************************ 3 | * @file : gw_fifo.c 4 | * @brief : Event container management API 5 | * @details : None 6 | * @date : 11-09-2018 7 | * @version : v1.0.0.0 8 | * @author : UncleMac 9 | * @email : zhaojunhui1861@163.com 10 | * 11 | * @license : GNU General Public License, version 3 (GPL-3.0) 12 | * 13 | * Copyright (C)2019 UncleMac. 14 | * 15 | * This code is open source: you can redistribute it and/or modify 16 | * it under the terms of the GNU General Public License as published by 17 | * the Free Software Foundation, either version 3 of the License, or 18 | * (at your option) any later version. 19 | * 20 | * This code is distributed in the hope that it will be useful, 21 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 22 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the 23 | * GNU General Public License for more details. 24 | * 25 | * You should have received a copy of the GNU General Public License 26 | * along with this program.If not, see < https://www.gnu.org/licenses/>. 27 | ************************************************************************************************* 28 | */ 29 | 30 | #include 31 | #include "gw_fifo.h" 32 | #include "gw_event.h" 33 | #include "gw_timer.h" 34 | #include "gw_tasks.h" 35 | #include "gw_type.h" 36 | 37 | #define EVENT_MAX 3 38 | //extern struct gw_event event_table[EVENT_SIZE]; 39 | struct gw_event event_table[EVENT_SIZE]; 40 | #if 0 41 | static struct gw_event event_table[EVENT_SIZE] = 42 | { 43 | 44 | { 45 | .name = "event1", 46 | .type = TYPE_IRQ, 47 | .status = ENABLE, 48 | .exec_task = task_svpwm, 49 | .poll_time = 20, 50 | .g_timer = &global_timer, 51 | }, 52 | 53 | { 54 | .name = "event2", 55 | .type = TYPE_IRQ, 56 | .status = DISABLE, 57 | .exec_task = task_idle, 58 | .poll_time = 10, 59 | .g_timer = &global_timer, 60 | }, 61 | 62 | { 63 | .name = "get_rpm", 64 | .type = TYPE_IRQ, 65 | .status = DISABLE, 66 | .exec_task = task_get_rpm, 67 | .poll_time = 10, 68 | .g_timer = &global_timer, 69 | }, 70 | 71 | }; 72 | #endif 73 | //#define EVENT_SIZE gw_get_event_list_size() 74 | 75 | uint8_t gw_get_event_list_size(void){ 76 | return sizeof(event_table)/sizeof(struct gw_event); 77 | } 78 | 79 | uint8_t gw_is_event_empty(void){ 80 | if(gw_get_event_list_size() == 0){ 81 | return 1; 82 | } 83 | return 0; 84 | } 85 | 86 | void gw_event_fifo_init(void){ 87 | 88 | uint8_t i = 0; 89 | uint8_t size = EVENT_SIZE; 90 | struct gw_event *p_event; 91 | for(; istatus = GW_DISABLE; 94 | p_event->timestamp = 0; 95 | } 96 | global_timer.timestamp = 0; 97 | } 98 | 99 | void gw_reset_event_status(void){ 100 | uint8_t i = 0; 101 | uint8_t size = EVENT_SIZE; 102 | for(; ipoll_time + p_event->timestamp < p_event->g_timer->timestamp){ 118 | p_event->timestamp = p_event->g_timer->timestamp; 119 | p_event->status = GW_ENABLE; 120 | } 121 | } 122 | //GW_EXIT_CRITICAL_AREA; 123 | } 124 | 125 | void gw_execute_event_task(void){ 126 | uint8_t i = 0; 127 | uint8_t size = EVENT_SIZE; 128 | struct gw_event *p_event; 129 | //GW_ENTER_CRITICAL_AREA; 130 | for(; istatus == GW_ENABLE && p_event->exec_task != NULL){ 133 | p_event->exec_task(); 134 | p_event->status = GW_DISABLE; 135 | } 136 | } 137 | //GW_EXIT_CRITICAL_AREA; 138 | } 139 | 140 | void gw_global_timer_add(void){ 141 | timer_add(&global_timer); 142 | } 143 | 144 | uint8_t gw_fifo_is_empty(gw_fifo_typedef *pfifo){ 145 | 146 | if((pfifo->rear + 1) % GW_FIFO_SIZE == pfifo->front){ 147 | return GW_TRUE; 148 | } 149 | return GW_FALSE; 150 | } 151 | 152 | uint8_t gw_fifo_is_full(gw_fifo_typedef *pfifo){ 153 | 154 | if(pfifo->rear == pfifo->front){ 155 | return GW_TRUE; 156 | } 157 | return GW_FALSE; 158 | } 159 | 160 | -------------------------------------------------------------------------------- /Source/Libraries/STM32F10x_StdPeriph_Driver/inc/stm32f10x_pwr.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f10x_pwr.h 4 | * @author MCD Application Team 5 | * @version V3.5.0 6 | * @date 11-March-2011 7 | * @brief This file contains all the functions prototypes for the PWR firmware 8 | * library. 9 | ****************************************************************************** 10 | * @attention 11 | * 12 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 13 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE 14 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY 15 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING 16 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE 17 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 18 | * 19 | *

© COPYRIGHT 2011 STMicroelectronics

20 | ****************************************************************************** 21 | */ 22 | 23 | /* Define to prevent recursive inclusion -------------------------------------*/ 24 | #ifndef __STM32F10x_PWR_H 25 | #define __STM32F10x_PWR_H 26 | 27 | #ifdef __cplusplus 28 | extern "C" { 29 | #endif 30 | 31 | /* Includes ------------------------------------------------------------------*/ 32 | #include "stm32f10x.h" 33 | 34 | /** @addtogroup STM32F10x_StdPeriph_Driver 35 | * @{ 36 | */ 37 | 38 | /** @addtogroup PWR 39 | * @{ 40 | */ 41 | 42 | /** @defgroup PWR_Exported_Types 43 | * @{ 44 | */ 45 | 46 | /** 47 | * @} 48 | */ 49 | 50 | /** @defgroup PWR_Exported_Constants 51 | * @{ 52 | */ 53 | 54 | /** @defgroup PVD_detection_level 55 | * @{ 56 | */ 57 | 58 | #define PWR_PVDLevel_2V2 ((uint32_t)0x00000000) 59 | #define PWR_PVDLevel_2V3 ((uint32_t)0x00000020) 60 | #define PWR_PVDLevel_2V4 ((uint32_t)0x00000040) 61 | #define PWR_PVDLevel_2V5 ((uint32_t)0x00000060) 62 | #define PWR_PVDLevel_2V6 ((uint32_t)0x00000080) 63 | #define PWR_PVDLevel_2V7 ((uint32_t)0x000000A0) 64 | #define PWR_PVDLevel_2V8 ((uint32_t)0x000000C0) 65 | #define PWR_PVDLevel_2V9 ((uint32_t)0x000000E0) 66 | #define IS_PWR_PVD_LEVEL(LEVEL) (((LEVEL) == PWR_PVDLevel_2V2) || ((LEVEL) == PWR_PVDLevel_2V3)|| \ 67 | ((LEVEL) == PWR_PVDLevel_2V4) || ((LEVEL) == PWR_PVDLevel_2V5)|| \ 68 | ((LEVEL) == PWR_PVDLevel_2V6) || ((LEVEL) == PWR_PVDLevel_2V7)|| \ 69 | ((LEVEL) == PWR_PVDLevel_2V8) || ((LEVEL) == PWR_PVDLevel_2V9)) 70 | /** 71 | * @} 72 | */ 73 | 74 | /** @defgroup Regulator_state_is_STOP_mode 75 | * @{ 76 | */ 77 | 78 | #define PWR_Regulator_ON ((uint32_t)0x00000000) 79 | #define PWR_Regulator_LowPower ((uint32_t)0x00000001) 80 | #define IS_PWR_REGULATOR(REGULATOR) (((REGULATOR) == PWR_Regulator_ON) || \ 81 | ((REGULATOR) == PWR_Regulator_LowPower)) 82 | /** 83 | * @} 84 | */ 85 | 86 | /** @defgroup STOP_mode_entry 87 | * @{ 88 | */ 89 | 90 | #define PWR_STOPEntry_WFI ((uint8_t)0x01) 91 | #define PWR_STOPEntry_WFE ((uint8_t)0x02) 92 | #define IS_PWR_STOP_ENTRY(ENTRY) (((ENTRY) == PWR_STOPEntry_WFI) || ((ENTRY) == PWR_STOPEntry_WFE)) 93 | 94 | /** 95 | * @} 96 | */ 97 | 98 | /** @defgroup PWR_Flag 99 | * @{ 100 | */ 101 | 102 | #define PWR_FLAG_WU ((uint32_t)0x00000001) 103 | #define PWR_FLAG_SB ((uint32_t)0x00000002) 104 | #define PWR_FLAG_PVDO ((uint32_t)0x00000004) 105 | #define IS_PWR_GET_FLAG(FLAG) (((FLAG) == PWR_FLAG_WU) || ((FLAG) == PWR_FLAG_SB) || \ 106 | ((FLAG) == PWR_FLAG_PVDO)) 107 | 108 | #define IS_PWR_CLEAR_FLAG(FLAG) (((FLAG) == PWR_FLAG_WU) || ((FLAG) == PWR_FLAG_SB)) 109 | /** 110 | * @} 111 | */ 112 | 113 | /** 114 | * @} 115 | */ 116 | 117 | /** @defgroup PWR_Exported_Macros 118 | * @{ 119 | */ 120 | 121 | /** 122 | * @} 123 | */ 124 | 125 | /** @defgroup PWR_Exported_Functions 126 | * @{ 127 | */ 128 | 129 | void PWR_DeInit(void); 130 | void PWR_BackupAccessCmd(FunctionalState NewState); 131 | void PWR_PVDCmd(FunctionalState NewState); 132 | void PWR_PVDLevelConfig(uint32_t PWR_PVDLevel); 133 | void PWR_WakeUpPinCmd(FunctionalState NewState); 134 | void PWR_EnterSTOPMode(uint32_t PWR_Regulator, uint8_t PWR_STOPEntry); 135 | void PWR_EnterSTANDBYMode(void); 136 | FlagStatus PWR_GetFlagStatus(uint32_t PWR_FLAG); 137 | void PWR_ClearFlag(uint32_t PWR_FLAG); 138 | 139 | #ifdef __cplusplus 140 | } 141 | #endif 142 | 143 | #endif /* __STM32F10x_PWR_H */ 144 | /** 145 | * @} 146 | */ 147 | 148 | /** 149 | * @} 150 | */ 151 | 152 | /** 153 | * @} 154 | */ 155 | 156 | /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ 157 | -------------------------------------------------------------------------------- /Source/User/user_config.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "stm32f10x.h" 3 | #include "user_config.h" 4 | #include "pid_regulator.h" 5 | #include "encoder.h" 6 | #include "current.h" 7 | #include "position.h" 8 | #include "foc.h" 9 | #include "SDS.h" 10 | 11 | extern foc_mod_t foc_obj; 12 | 13 | void soft_reset(void) 14 | { 15 | __set_FAULTMASK(1); // 关闭所有中断 16 | NVIC_SystemReset(); // 复位 17 | } 18 | 19 | void pid_config(int8_t index){ 20 | 21 | #if USE_PID 22 | switch(index){ 23 | case 1: 24 | //cur PI 25 | //spd PI 26 | //pos P 27 | PID_HandleInit(&foc_obj.speed_pi); 28 | foc_obj.speed_pi.hKpGain = 300; 29 | foc_obj.speed_pi.hKiGain = 9; 30 | foc_obj.speed_pi.hKdGain = 0; 31 | foc_obj.speed_pi.wLowerIntegralLimit = -32768*10; 32 | foc_obj.speed_pi.wUpperIntegralLimit = 32767*10; 33 | foc_obj.speed_pi.hLowerOutputLimit = -32768; 34 | foc_obj.speed_pi.hUpperOutputLimit = 32767; 35 | foc_obj.speed_pi.hKpDivisor = 0; 36 | foc_obj.speed_pi.hKiDivisor = 0; 37 | foc_obj.speed_pi.hKdDivisor = 0; 38 | 39 | PID_HandleInit(&foc_obj.cur_d_pi); 40 | foc_obj.cur_d_pi.hKpGain = PID_FLUX_KP_DEFAULT; 41 | foc_obj.cur_d_pi.hKiGain = PID_FLUX_KI_DEFAULT; 42 | foc_obj.cur_d_pi.hKpDivisor = TF_KPDIV; 43 | foc_obj.cur_d_pi.hKiDivisor = TF_KIDIV; 44 | foc_obj.cur_d_pi.wLowerIntegralLimit = -32768*100; 45 | foc_obj.cur_d_pi.wUpperIntegralLimit = 32767*100; 46 | 47 | foc_obj.cur_d_pi.hKdGain = 0; 48 | foc_obj.cur_d_pi.hLowerOutputLimit = -32768; 49 | foc_obj.cur_d_pi.hUpperOutputLimit = 32767; 50 | foc_obj.cur_d_pi.hKpDivisorPOW2 = 1; 51 | foc_obj.cur_d_pi.hKiDivisorPOW2 = 8; 52 | 53 | PID_HandleInit(&foc_obj.cur_q_pi); 54 | foc_obj.cur_q_pi.hKpGain = PID_TORQUE_KP_DEFAULT; 55 | foc_obj.cur_q_pi.hKiGain = PID_TORQUE_KI_DEFAULT; 56 | foc_obj.cur_q_pi.hKpDivisor = TF_KPDIV; 57 | foc_obj.cur_q_pi.hKiDivisor = TF_KIDIV; 58 | foc_obj.cur_q_pi.hKpDivisorPOW2 = 1; 59 | foc_obj.cur_q_pi.hKiDivisorPOW2 = 8; 60 | foc_obj.cur_q_pi.hKdGain = 0; 61 | foc_obj.cur_q_pi.hLowerOutputLimit = -32768; 62 | foc_obj.cur_q_pi.hUpperOutputLimit = 32767; 63 | foc_obj.cur_q_pi.wLowerIntegralLimit = -32768*100; 64 | foc_obj.cur_q_pi.wUpperIntegralLimit = 32767*100; 65 | 66 | PID_HandleInit(&foc_obj.position_pi); 67 | foc_obj.position_pi.hKpGain = 3; 68 | foc_obj.position_pi.hKiGain = 0; 69 | foc_obj.position_pi.hKpDivisor = 0; 70 | foc_obj.position_pi.hKiDivisor = 0; 71 | foc_obj.position_pi.hKpDivisorPOW2 = 4; 72 | foc_obj.position_pi.hKiDivisorPOW2 = 0; 73 | foc_obj.position_pi.hKdGain = 0; 74 | foc_obj.position_pi.hLowerOutputLimit = -MAX_RPM; 75 | foc_obj.position_pi.hUpperOutputLimit = MAX_RPM; 76 | foc_obj.position_pi.wLowerIntegralLimit = -32768*100; 77 | foc_obj.position_pi.wUpperIntegralLimit = 32767*100; 78 | break; 79 | case 2: 80 | //cur P 81 | //spd PI 82 | //pos P 83 | PID_HandleInit(&foc_obj.speed_pi); 84 | foc_obj.speed_pi.hKpGain = 50; 85 | foc_obj.speed_pi.hKiGain = 2; 86 | foc_obj.speed_pi.hKdGain = 0; 87 | foc_obj.speed_pi.wLowerIntegralLimit = -32768*10; 88 | foc_obj.speed_pi.wUpperIntegralLimit = 32767*10; 89 | foc_obj.speed_pi.hLowerOutputLimit = -32768; 90 | foc_obj.speed_pi.hUpperOutputLimit = 32767; 91 | foc_obj.speed_pi.hKpDivisor = 1; 92 | foc_obj.speed_pi.hKiDivisor = 1; 93 | foc_obj.speed_pi.hKdDivisor = 1; 94 | 95 | PID_HandleInit(&foc_obj.cur_d_pi); 96 | foc_obj.cur_d_pi.hKpGain = PID_FLUX_KP_DEFAULT; 97 | foc_obj.cur_d_pi.hKiGain = 0; 98 | foc_obj.cur_d_pi.hKpDivisor = TF_KPDIV; 99 | foc_obj.cur_d_pi.hKiDivisor = TF_KIDIV; 100 | 101 | foc_obj.cur_d_pi.hKdGain = 0; 102 | foc_obj.cur_d_pi.hLowerOutputLimit = -32768; 103 | foc_obj.cur_d_pi.hUpperOutputLimit = 32767; 104 | foc_obj.cur_d_pi.hKpDivisorPOW2 = 0; 105 | foc_obj.cur_d_pi.hKiDivisorPOW2 = 7; 106 | 107 | PID_HandleInit(&foc_obj.cur_q_pi); 108 | foc_obj.cur_q_pi.hKpGain = PID_TORQUE_KP_DEFAULT; 109 | foc_obj.cur_q_pi.hKiGain = 0; 110 | foc_obj.cur_q_pi.hKpDivisor = TF_KPDIV; 111 | foc_obj.cur_q_pi.hKiDivisor = TF_KIDIV; 112 | foc_obj.cur_q_pi.hKpDivisorPOW2 = 0; 113 | foc_obj.cur_q_pi.hKiDivisorPOW2 = 7; 114 | foc_obj.cur_q_pi.hKdGain = 0; 115 | foc_obj.cur_q_pi.hLowerOutputLimit = -32768; 116 | foc_obj.cur_q_pi.hUpperOutputLimit = 32767; 117 | 118 | PID_HandleInit(&foc_obj.position_pi); 119 | foc_obj.position_pi.hKpGain = 3; 120 | foc_obj.position_pi.hKiGain = 0; 121 | foc_obj.position_pi.hKpDivisor = 0; 122 | foc_obj.position_pi.hKiDivisor = 0; 123 | foc_obj.position_pi.hKpDivisorPOW2 = 0; 124 | foc_obj.position_pi.hKiDivisorPOW2 = 6; 125 | foc_obj.position_pi.hKdGain = 0; 126 | foc_obj.position_pi.hLowerOutputLimit = -75; 127 | foc_obj.position_pi.hUpperOutputLimit = 75; 128 | 129 | foc_obj.position_pi.wLowerIntegralLimit = -32768*100; 130 | foc_obj.position_pi.wUpperIntegralLimit = 32767*100; 131 | 132 | break; 133 | } 134 | #endif 135 | } 136 | -------------------------------------------------------------------------------- /Source/Project/MDK/GCC/Ld/STM32F10X_MD.ld: -------------------------------------------------------------------------------- 1 | /* 2 | ***************************************************************************** 3 | ** 4 | ** File : stm32_flash.ld 5 | ** 6 | ** Abstract : Linker script for STM32F103VB Device with 7 | ** 128KByte FLASH, 20KByte RAM 8 | ** 9 | ** Set heap size, stack size and stack location according 10 | ** to application requirements. 11 | ** 12 | ** Set memory bank area and size if external memory is used. 13 | ** 14 | ** Target : STMicroelectronics STM32 15 | ** 16 | ** Environment : Atollic TrueSTUDIO(R) 17 | ** 18 | ** Distribution: The file is distributed 揳s is,?without any warranty 19 | ** of any kind. 20 | ** 21 | ** (c)Copyright Atollic AB. 22 | ** You may use this file as-is or modify it according to the needs of your 23 | ** project. Distribution of this file (unmodified or modified) is not 24 | ** permitted. Atollic AB permit registered Atollic TrueSTUDIO(R) users the 25 | ** rights to distribute the assembled, compiled & linked contents of this 26 | ** file as part of an application binary file, provided that it is built 27 | ** using the Atollic TrueSTUDIO(R) toolchain. 28 | ** 29 | ***************************************************************************** 30 | */ 31 | 32 | /* Entry Point */ 33 | ENTRY(Reset_Handler) 34 | 35 | /* Highest address of the user mode stack */ 36 | _estack = 0x20005000; /* end of 20K RAM */ 37 | 38 | /* Generate a link error if heap and stack don't fit into RAM */ 39 | _Min_Heap_Size = 0x0; /* required amount of heap */ 40 | _Min_Stack_Size = 0x200; /* required amount of stack */ 41 | 42 | /* Specify the memory areas */ 43 | MEMORY 44 | { 45 | FLASH (rx) : ORIGIN = 0x08000000, LENGTH = 128K 46 | RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 20K 47 | MEMORY_B1 (rx) : ORIGIN = 0x60000000, LENGTH = 0K 48 | } 49 | 50 | /* Define output sections */ 51 | SECTIONS 52 | { 53 | /* The startup code goes first into FLASH */ 54 | .isr_vector : 55 | { 56 | . = ALIGN(4); 57 | KEEP(*(.isr_vector)) /* Startup code */ 58 | . = ALIGN(4); 59 | } >FLASH 60 | 61 | /* The program code and other data goes into FLASH */ 62 | .text : 63 | { 64 | . = ALIGN(4); 65 | *(.text) /* .text sections (code) */ 66 | *(.text*) /* .text* sections (code) */ 67 | *(.rodata) /* .rodata sections (constants, strings, etc.) */ 68 | *(.rodata*) /* .rodata* sections (constants, strings, etc.) */ 69 | *(.glue_7) /* glue arm to thumb code */ 70 | *(.glue_7t) /* glue thumb to arm code */ 71 | 72 | KEEP (*(.init)) 73 | KEEP (*(.fini)) 74 | 75 | . = ALIGN(4); 76 | _etext = .; /* define a global symbols at end of code */ 77 | } >FLASH 78 | 79 | 80 | .ARM.extab : { *(.ARM.extab* .gnu.linkonce.armextab.*) } >FLASH 81 | .ARM : { 82 | __exidx_start = .; 83 | *(.ARM.exidx*) 84 | __exidx_end = .; 85 | } >FLASH 86 | 87 | .ARM.attributes : { *(.ARM.attributes) } > FLASH 88 | 89 | .preinit_array : 90 | { 91 | PROVIDE_HIDDEN (__preinit_array_start = .); 92 | KEEP (*(.preinit_array*)) 93 | PROVIDE_HIDDEN (__preinit_array_end = .); 94 | } >FLASH 95 | .init_array : 96 | { 97 | PROVIDE_HIDDEN (__init_array_start = .); 98 | KEEP (*(SORT(.init_array.*))) 99 | KEEP (*(.init_array*)) 100 | PROVIDE_HIDDEN (__init_array_end = .); 101 | } >FLASH 102 | .fini_array : 103 | { 104 | PROVIDE_HIDDEN (__fini_array_start = .); 105 | KEEP (*(.fini_array*)) 106 | KEEP (*(SORT(.fini_array.*))) 107 | PROVIDE_HIDDEN (__fini_array_end = .); 108 | } >FLASH 109 | 110 | /* used by the startup to initialize data */ 111 | _sidata = .; 112 | 113 | /* Initialized data sections goes into RAM, load LMA copy after code */ 114 | .data : AT ( _sidata ) 115 | { 116 | . = ALIGN(4); 117 | _sdata = .; /* create a global symbol at data start */ 118 | *(.data) /* .data sections */ 119 | *(.data*) /* .data* sections */ 120 | 121 | . = ALIGN(4); 122 | _edata = .; /* define a global symbol at data end */ 123 | } >RAM 124 | 125 | /* Uninitialized data section */ 126 | . = ALIGN(4); 127 | .bss : 128 | { 129 | /* This is used by the startup in order to initialize the .bss secion */ 130 | _sbss = .; /* define a global symbol at bss start */ 131 | __bss_start__ = _sbss; 132 | *(.bss) 133 | *(.bss*) 134 | *(COMMON) 135 | 136 | . = ALIGN(4); 137 | _ebss = .; /* define a global symbol at bss end */ 138 | __bss_end__ = _ebss; 139 | } >RAM 140 | 141 | PROVIDE ( end = _ebss ); 142 | PROVIDE ( _end = _ebss ); 143 | 144 | /* User_heap_stack section, used to check that there is enough RAM left */ 145 | ._user_heap_stack : 146 | { 147 | . = ALIGN(4); 148 | . = . + _Min_Heap_Size; 149 | . = . + _Min_Stack_Size; 150 | . = ALIGN(4); 151 | } >RAM 152 | 153 | /* MEMORY_bank1 section, code must be located here explicitly */ 154 | /* Example: extern int foo(void) __attribute__ ((section (".mb1text"))); */ 155 | .memory_b1_text : 156 | { 157 | *(.mb1text) /* .mb1text sections (code) */ 158 | *(.mb1text*) /* .mb1text* sections (code) */ 159 | *(.mb1rodata) /* read-only data (constants) */ 160 | *(.mb1rodata*) 161 | } >MEMORY_B1 162 | 163 | /* Remove information from the standard libraries */ 164 | /DISCARD/ : 165 | { 166 | libc.a ( * ) 167 | /* libm.a ( * ) */ 168 | libgcc.a ( * ) 169 | } 170 | } 171 | -------------------------------------------------------------------------------- /Source/Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_iwdg.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f10x_iwdg.c 4 | * @author MCD Application Team 5 | * @version V3.5.0 6 | * @date 11-March-2011 7 | * @brief This file provides all the IWDG firmware functions. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 12 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE 13 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY 14 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING 15 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE 16 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 17 | * 18 | *

© COPYRIGHT 2011 STMicroelectronics

19 | ****************************************************************************** 20 | */ 21 | 22 | /* Includes ------------------------------------------------------------------*/ 23 | #include "stm32f10x_iwdg.h" 24 | 25 | /** @addtogroup STM32F10x_StdPeriph_Driver 26 | * @{ 27 | */ 28 | 29 | /** @defgroup IWDG 30 | * @brief IWDG driver modules 31 | * @{ 32 | */ 33 | 34 | /** @defgroup IWDG_Private_TypesDefinitions 35 | * @{ 36 | */ 37 | 38 | /** 39 | * @} 40 | */ 41 | 42 | /** @defgroup IWDG_Private_Defines 43 | * @{ 44 | */ 45 | 46 | /* ---------------------- IWDG registers bit mask ----------------------------*/ 47 | 48 | /* KR register bit mask */ 49 | #define KR_KEY_Reload ((uint16_t)0xAAAA) 50 | #define KR_KEY_Enable ((uint16_t)0xCCCC) 51 | 52 | /** 53 | * @} 54 | */ 55 | 56 | /** @defgroup IWDG_Private_Macros 57 | * @{ 58 | */ 59 | 60 | /** 61 | * @} 62 | */ 63 | 64 | /** @defgroup IWDG_Private_Variables 65 | * @{ 66 | */ 67 | 68 | /** 69 | * @} 70 | */ 71 | 72 | /** @defgroup IWDG_Private_FunctionPrototypes 73 | * @{ 74 | */ 75 | 76 | /** 77 | * @} 78 | */ 79 | 80 | /** @defgroup IWDG_Private_Functions 81 | * @{ 82 | */ 83 | 84 | /** 85 | * @brief Enables or disables write access to IWDG_PR and IWDG_RLR registers. 86 | * @param IWDG_WriteAccess: new state of write access to IWDG_PR and IWDG_RLR registers. 87 | * This parameter can be one of the following values: 88 | * @arg IWDG_WriteAccess_Enable: Enable write access to IWDG_PR and IWDG_RLR registers 89 | * @arg IWDG_WriteAccess_Disable: Disable write access to IWDG_PR and IWDG_RLR registers 90 | * @retval None 91 | */ 92 | void IWDG_WriteAccessCmd(uint16_t IWDG_WriteAccess) 93 | { 94 | /* Check the parameters */ 95 | assert_param(IS_IWDG_WRITE_ACCESS(IWDG_WriteAccess)); 96 | IWDG->KR = IWDG_WriteAccess; 97 | } 98 | 99 | /** 100 | * @brief Sets IWDG Prescaler value. 101 | * @param IWDG_Prescaler: specifies the IWDG Prescaler value. 102 | * This parameter can be one of the following values: 103 | * @arg IWDG_Prescaler_4: IWDG prescaler set to 4 104 | * @arg IWDG_Prescaler_8: IWDG prescaler set to 8 105 | * @arg IWDG_Prescaler_16: IWDG prescaler set to 16 106 | * @arg IWDG_Prescaler_32: IWDG prescaler set to 32 107 | * @arg IWDG_Prescaler_64: IWDG prescaler set to 64 108 | * @arg IWDG_Prescaler_128: IWDG prescaler set to 128 109 | * @arg IWDG_Prescaler_256: IWDG prescaler set to 256 110 | * @retval None 111 | */ 112 | void IWDG_SetPrescaler(uint8_t IWDG_Prescaler) 113 | { 114 | /* Check the parameters */ 115 | assert_param(IS_IWDG_PRESCALER(IWDG_Prescaler)); 116 | IWDG->PR = IWDG_Prescaler; 117 | } 118 | 119 | /** 120 | * @brief Sets IWDG Reload value. 121 | * @param Reload: specifies the IWDG Reload value. 122 | * This parameter must be a number between 0 and 0x0FFF. 123 | * @retval None 124 | */ 125 | void IWDG_SetReload(uint16_t Reload) 126 | { 127 | /* Check the parameters */ 128 | assert_param(IS_IWDG_RELOAD(Reload)); 129 | IWDG->RLR = Reload; 130 | } 131 | 132 | /** 133 | * @brief Reloads IWDG counter with value defined in the reload register 134 | * (write access to IWDG_PR and IWDG_RLR registers disabled). 135 | * @param None 136 | * @retval None 137 | */ 138 | void IWDG_ReloadCounter(void) 139 | { 140 | IWDG->KR = KR_KEY_Reload; 141 | } 142 | 143 | /** 144 | * @brief Enables IWDG (write access to IWDG_PR and IWDG_RLR registers disabled). 145 | * @param None 146 | * @retval None 147 | */ 148 | void IWDG_Enable(void) 149 | { 150 | IWDG->KR = KR_KEY_Enable; 151 | } 152 | 153 | /** 154 | * @brief Checks whether the specified IWDG flag is set or not. 155 | * @param IWDG_FLAG: specifies the flag to check. 156 | * This parameter can be one of the following values: 157 | * @arg IWDG_FLAG_PVU: Prescaler Value Update on going 158 | * @arg IWDG_FLAG_RVU: Reload Value Update on going 159 | * @retval The new state of IWDG_FLAG (SET or RESET). 160 | */ 161 | FlagStatus IWDG_GetFlagStatus(uint16_t IWDG_FLAG) 162 | { 163 | FlagStatus bitstatus = RESET; 164 | /* Check the parameters */ 165 | assert_param(IS_IWDG_FLAG(IWDG_FLAG)); 166 | if ((IWDG->SR & IWDG_FLAG) != (uint32_t)RESET) 167 | { 168 | bitstatus = SET; 169 | } 170 | else 171 | { 172 | bitstatus = RESET; 173 | } 174 | /* Return the flag status */ 175 | return bitstatus; 176 | } 177 | 178 | /** 179 | * @} 180 | */ 181 | 182 | /** 183 | * @} 184 | */ 185 | 186 | /** 187 | * @} 188 | */ 189 | 190 | /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ 191 | -------------------------------------------------------------------------------- /Source/Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_dbgmcu.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f10x_dbgmcu.c 4 | * @author MCD Application Team 5 | * @version V3.5.0 6 | * @date 11-March-2011 7 | * @brief This file provides all the DBGMCU firmware functions. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 12 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE 13 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY 14 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING 15 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE 16 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 17 | * 18 | *

© COPYRIGHT 2011 STMicroelectronics

19 | ****************************************************************************** 20 | */ 21 | 22 | /* Includes ------------------------------------------------------------------*/ 23 | #include "stm32f10x_dbgmcu.h" 24 | 25 | /** @addtogroup STM32F10x_StdPeriph_Driver 26 | * @{ 27 | */ 28 | 29 | /** @defgroup DBGMCU 30 | * @brief DBGMCU driver modules 31 | * @{ 32 | */ 33 | 34 | /** @defgroup DBGMCU_Private_TypesDefinitions 35 | * @{ 36 | */ 37 | 38 | /** 39 | * @} 40 | */ 41 | 42 | /** @defgroup DBGMCU_Private_Defines 43 | * @{ 44 | */ 45 | 46 | #define IDCODE_DEVID_MASK ((uint32_t)0x00000FFF) 47 | /** 48 | * @} 49 | */ 50 | 51 | /** @defgroup DBGMCU_Private_Macros 52 | * @{ 53 | */ 54 | 55 | /** 56 | * @} 57 | */ 58 | 59 | /** @defgroup DBGMCU_Private_Variables 60 | * @{ 61 | */ 62 | 63 | /** 64 | * @} 65 | */ 66 | 67 | /** @defgroup DBGMCU_Private_FunctionPrototypes 68 | * @{ 69 | */ 70 | 71 | /** 72 | * @} 73 | */ 74 | 75 | /** @defgroup DBGMCU_Private_Functions 76 | * @{ 77 | */ 78 | 79 | /** 80 | * @brief Returns the device revision identifier. 81 | * @param None 82 | * @retval Device revision identifier 83 | */ 84 | uint32_t DBGMCU_GetREVID(void) 85 | { 86 | return(DBGMCU->IDCODE >> 16); 87 | } 88 | 89 | /** 90 | * @brief Returns the device identifier. 91 | * @param None 92 | * @retval Device identifier 93 | */ 94 | uint32_t DBGMCU_GetDEVID(void) 95 | { 96 | return(DBGMCU->IDCODE & IDCODE_DEVID_MASK); 97 | } 98 | 99 | /** 100 | * @brief Configures the specified peripheral and low power mode behavior 101 | * when the MCU under Debug mode. 102 | * @param DBGMCU_Periph: specifies the peripheral and low power mode. 103 | * This parameter can be any combination of the following values: 104 | * @arg DBGMCU_SLEEP: Keep debugger connection during SLEEP mode 105 | * @arg DBGMCU_STOP: Keep debugger connection during STOP mode 106 | * @arg DBGMCU_STANDBY: Keep debugger connection during STANDBY mode 107 | * @arg DBGMCU_IWDG_STOP: Debug IWDG stopped when Core is halted 108 | * @arg DBGMCU_WWDG_STOP: Debug WWDG stopped when Core is halted 109 | * @arg DBGMCU_TIM1_STOP: TIM1 counter stopped when Core is halted 110 | * @arg DBGMCU_TIM2_STOP: TIM2 counter stopped when Core is halted 111 | * @arg DBGMCU_TIM3_STOP: TIM3 counter stopped when Core is halted 112 | * @arg DBGMCU_TIM4_STOP: TIM4 counter stopped when Core is halted 113 | * @arg DBGMCU_CAN1_STOP: Debug CAN2 stopped when Core is halted 114 | * @arg DBGMCU_I2C1_SMBUS_TIMEOUT: I2C1 SMBUS timeout mode stopped when Core is halted 115 | * @arg DBGMCU_I2C2_SMBUS_TIMEOUT: I2C2 SMBUS timeout mode stopped when Core is halted 116 | * @arg DBGMCU_TIM5_STOP: TIM5 counter stopped when Core is halted 117 | * @arg DBGMCU_TIM6_STOP: TIM6 counter stopped when Core is halted 118 | * @arg DBGMCU_TIM7_STOP: TIM7 counter stopped when Core is halted 119 | * @arg DBGMCU_TIM8_STOP: TIM8 counter stopped when Core is halted 120 | * @arg DBGMCU_CAN2_STOP: Debug CAN2 stopped when Core is halted 121 | * @arg DBGMCU_TIM15_STOP: TIM15 counter stopped when Core is halted 122 | * @arg DBGMCU_TIM16_STOP: TIM16 counter stopped when Core is halted 123 | * @arg DBGMCU_TIM17_STOP: TIM17 counter stopped when Core is halted 124 | * @arg DBGMCU_TIM9_STOP: TIM9 counter stopped when Core is halted 125 | * @arg DBGMCU_TIM10_STOP: TIM10 counter stopped when Core is halted 126 | * @arg DBGMCU_TIM11_STOP: TIM11 counter stopped when Core is halted 127 | * @arg DBGMCU_TIM12_STOP: TIM12 counter stopped when Core is halted 128 | * @arg DBGMCU_TIM13_STOP: TIM13 counter stopped when Core is halted 129 | * @arg DBGMCU_TIM14_STOP: TIM14 counter stopped when Core is halted 130 | * @param NewState: new state of the specified peripheral in Debug mode. 131 | * This parameter can be: ENABLE or DISABLE. 132 | * @retval None 133 | */ 134 | void DBGMCU_Config(uint32_t DBGMCU_Periph, FunctionalState NewState) 135 | { 136 | /* Check the parameters */ 137 | assert_param(IS_DBGMCU_PERIPH(DBGMCU_Periph)); 138 | assert_param(IS_FUNCTIONAL_STATE(NewState)); 139 | 140 | if (NewState != DISABLE) 141 | { 142 | DBGMCU->CR |= DBGMCU_Periph; 143 | } 144 | else 145 | { 146 | DBGMCU->CR &= ~DBGMCU_Periph; 147 | } 148 | } 149 | 150 | /** 151 | * @} 152 | */ 153 | 154 | /** 155 | * @} 156 | */ 157 | 158 | /** 159 | * @} 160 | */ 161 | 162 | /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ 163 | -------------------------------------------------------------------------------- /Source/GwOS/gw_list.c: -------------------------------------------------------------------------------- 1 | /** 2 | ************************************************************************************************ 3 | * @file : gw_list.c 4 | * @brief : 5 | * @details : 6 | * @date : 11-09-2018 7 | * @version : v1.0.0.0 8 | * @author : UncleMac 9 | * @email : zhaojunhui1861@163.com 10 | * 11 | * @license : GNU General Public License, version 3 (GPL-3.0) 12 | * 13 | * Copyright (C)2019 UncleMac. 14 | * 15 | * This code is open source: you can redistribute it and/or modify 16 | * it under the terms of the GNU General Public License as published by 17 | * the Free Software Foundation, either version 3 of the License, or 18 | * (at your option) any later version. 19 | * 20 | * This code is distributed in the hope that it will be useful, 21 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 22 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the 23 | * GNU General Public License for more details. 24 | * 25 | * You should have received a copy of the GNU General Public License 26 | * along with this program.If not, see < https://www.gnu.org/licenses/>. 27 | ************************************************************************************************* 28 | */ 29 | 30 | #include "gw_list.h" 31 | #include "gw_type.h" 32 | 33 | /** 34 | * @brief Initialization list 35 | * @return gw_list - The pointer to the list 36 | */ 37 | gw_list* gw_list_init(void){ 38 | //gw_list* phead = (gw_list*)GW_MALLOC(sizeof(gw_list_node)); 39 | gw_list* phead = (gw_list*)malloc(sizeof(gw_list_node)); 40 | if(phead == NULL){ 41 | return NULL; 42 | } 43 | phead->next = NULL; 44 | phead->data = 0; 45 | return phead; 46 | } 47 | 48 | /** 49 | * @brief Initialization list node 50 | * @return gw_list - The pointer to the list node 51 | */ 52 | gw_list_node* gw_list_node_init(DATA_TYPE data){ 53 | gw_list_node* pnode = (gw_list*)GW_MALLOC(sizeof(gw_list_node)); 54 | pnode->next = NULL; 55 | pnode->data = data; 56 | return pnode; 57 | } 58 | 59 | /** 60 | * @brief insert a node behind head node and before second node 61 | */ 62 | GW_RESULT gw_list_insert_node_last(gw_list* plist, gw_list_node* const pnode){ 63 | if(plist == NULL){ 64 | return GW_ERROR; 65 | } 66 | plist->data++; 67 | while(plist->next != NULL){ 68 | plist = plist->next; 69 | } 70 | plist->next = pnode; 71 | return GW_SUCCESS; 72 | } 73 | /** 74 | * @brief insert a node behind head node and before second node 75 | */ 76 | GW_RESULT gw_list_insert_node_first(gw_list* plist, gw_list_node* const pnode){ 77 | if(plist == NULL){ 78 | return GW_ERROR; 79 | } 80 | plist->data++; 81 | pnode->next = plist->next; 82 | plist->next = pnode; 83 | return GW_SUCCESS; 84 | } 85 | 86 | /** 87 | * @brief insert a node behind head node and before second node 88 | * @param plist 89 | * @param gw_list_node 90 | * @param index 91 | */ 92 | GW_RESULT gw_list_insert_node_by_index(gw_list* plist, gw_list_node* const pnode, uint8_t index){ 93 | 94 | uint8_t i = 0; 95 | if(plist == NULL){ 96 | return GW_ERROR; 97 | } 98 | if(plist->data < index){ 99 | return GW_ERROR; 100 | } 101 | plist->data++; 102 | while(i++next; 104 | } 105 | pnode->next = plist->next; 106 | plist->next = pnode; 107 | return GW_SUCCESS; 108 | } 109 | 110 | /** 111 | * @brief remove last node in list 112 | * @param plist 113 | */ 114 | GW_RESULT gw_list_remove_node_last(gw_list* plist){ 115 | 116 | gw_list_node* pnode_tmp = NULL; 117 | if(plist == NULL){ 118 | return GW_ERROR; 119 | } 120 | if(plist->data < 1){ 121 | return GW_ERROR; 122 | } 123 | plist->data--; 124 | while(plist->next != NULL){ 125 | pnode_tmp = plist; 126 | plist = plist->next; 127 | } 128 | pnode_tmp->next = NULL; 129 | gw_list_node_free(plist); 130 | return GW_SUCCESS; 131 | } 132 | 133 | /** 134 | * @brief remove a node behind head node and before second node 135 | * @param plist 136 | */ 137 | GW_RESULT gw_list_remove_node_first(gw_list* const plist){ 138 | gw_list_node* pnode_tmp = NULL; 139 | if(plist == NULL){ 140 | return GW_ERROR; 141 | } 142 | if(plist->data < 1){ 143 | return GW_ERROR; 144 | } 145 | plist->data--; 146 | 147 | pnode_tmp = plist->next; 148 | plist->next = pnode_tmp->next; 149 | gw_list_node_free(pnode_tmp); 150 | return GW_SUCCESS; 151 | } 152 | /** 153 | * @brief remove a node by index 154 | * @param plist 155 | * @param index 156 | */ 157 | GW_RESULT gw_list_remove_node_by_index(gw_list* plist, uint8_t index){ 158 | uint16_t i = 0; 159 | gw_list_node* pnode_tmp = NULL; 160 | if(plist == NULL){ 161 | return GW_ERROR; 162 | } 163 | if(plist->data < index){ 164 | return GW_ERROR; 165 | } 166 | plist->data--; 167 | while(i++next; 169 | } 170 | pnode_tmp = plist->next; 171 | plist->next = pnode_tmp->next; 172 | gw_list_node_free(pnode_tmp); 173 | return GW_SUCCESS; 174 | } 175 | /** 176 | * @brief free memory of one node 177 | * @param pnode 178 | */ 179 | GW_RESULT gw_list_node_free(gw_list_node* const pnode){ 180 | 181 | if(pnode == NULL){ 182 | return GW_ERROR; 183 | } 184 | GW_FREE(pnode); 185 | return GW_SUCCESS; 186 | } 187 | 188 | /** 189 | * @brief free memory of list 190 | */ 191 | GW_RESULT gw_list_free(gw_list* plist){ 192 | 193 | gw_list_node* pnode_tmp = NULL; 194 | 195 | if(plist == NULL){ 196 | return GW_ERROR; 197 | } 198 | while(plist->next != NULL){ 199 | pnode_tmp = plist; 200 | plist = plist->next; 201 | gw_list_node_free(pnode_tmp); 202 | } 203 | return GW_SUCCESS; 204 | } 205 | /** 206 | * @brief get list node length 207 | */ 208 | DATA_TYPE gw_list_length(gw_list* const plist){ 209 | return plist->data; 210 | } 211 | 212 | 213 | 214 | -------------------------------------------------------------------------------- /Source/GwOS/gw_event.c: -------------------------------------------------------------------------------- 1 | /** 2 | ************************************************************************************************ 3 | * @file : gw_event.c 4 | * @brief : Interface to manage events 5 | * @details : None 6 | * @date : 11-09-2018 7 | * @version : v1.0.0.0 8 | * @author : UncleMac 9 | * @email : zhaojunhui1861@163.com 10 | * 11 | * @license : GNU General Public License, version 3 (GPL-3.0) 12 | * 13 | * Copyright (C)2019 UncleMac. 14 | * 15 | * This code is open source: you can redistribute it and/or modify 16 | * it under the terms of the GNU General Public License as published by 17 | * the Free Software Foundation, either version 3 of the License, or 18 | * (at your option) any later version. 19 | * 20 | * This code is distributed in the hope that it will be useful, 21 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 22 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the 23 | * GNU General Public License for more details. 24 | * 25 | * You should have received a copy of the GNU General Public License 26 | * along with this program.If not, see < https://www.gnu.org/licenses/>. 27 | ************************************************************************************************* 28 | */ 29 | 30 | #include "gw_event.h" 31 | #include "gw_type.h" 32 | 33 | #define GLOBAL_TIMER global_timer 34 | 35 | /* 36 | struct gw_event { 37 | const char* name; //事件名称 38 | uint32_t id; //时间ID 39 | uint8_t type; //事件类型 40 | uint8_t status; //事件状态 41 | uint32_t priority; //事件优先级 42 | uint32_t timestamp; //时间戳 43 | uint32_t poll_time; //轮询执行时间 44 | gw_msg_t msg; //消息 45 | p_init_func init_task; //任务初始化函数 46 | p_exec_func exec_task; //轮询任务回调函数 47 | p_exec_args_func exec_args_task;//带参数的回调函数 48 | struct gw_timer* g_timer; //全局定时器 49 | }; 50 | */ 51 | 52 | #define GW_DEFAULT_EV_ID 0 53 | #define GW_DEFAULT_EV_PRIORITY 0 54 | #define GW_DEFAULT_EV_POLLTIME 5 55 | #define GW_DEFAULT_EV_TYPE TYPE_POLL 56 | #define GW_DEFAULT_EV_STATUS DISABLE 57 | #define GW_DEFAULT_EV_INIT_FUNC NULL 58 | #define GW_DEFAULT_EV_EXEC_FUNC NULL 59 | #define GW_DEFAULT_EV_EXEC_ARGS_FUNC NULL 60 | 61 | void gw_event_init_default(gw_event_t *pev, const char* name, DATA_TYPE id){ 62 | pev->name = name; 63 | gw_event_set_id(pev, id); 64 | gw_event_set_type(pev, TYPE_POLL); 65 | gw_event_set_priority(pev, GW_DEFAULT_EV_PRIORITY); 66 | gw_event_set_poll_time(pev, GW_DEFAULT_EV_POLLTIME); 67 | gw_event_set_init_func(pev, GW_DEFAULT_EV_INIT_FUNC); 68 | gw_event_set_exec_task(pev, GW_DEFAULT_EV_EXEC_FUNC); 69 | gw_event_set_exec_args_task(pev, GW_DEFAULT_EV_EXEC_ARGS_FUNC); 70 | gw_event_set_timer(pev, &GLOBAL_TIMER); 71 | gw_event_set_timestamp(pev,GLOBAL_TIMER.timestamp); 72 | gw_msg_init(&pev->msg,id); 73 | } 74 | 75 | void gw_event_init(gw_event_t *pev, const char* name, DATA_TYPE id){ 76 | pev->name = name; 77 | gw_event_set_id(pev, id); 78 | gw_event_set_type(pev, TYPE_POLL); 79 | gw_event_set_priority(pev, GW_DEFAULT_EV_PRIORITY); 80 | gw_event_set_poll_time(pev, GW_DEFAULT_EV_POLLTIME); 81 | gw_event_set_init_func(pev, GW_DEFAULT_EV_INIT_FUNC); 82 | gw_event_set_exec_task(pev, GW_DEFAULT_EV_EXEC_FUNC); 83 | gw_event_set_exec_args_task(pev, GW_DEFAULT_EV_EXEC_ARGS_FUNC); 84 | gw_event_set_timer(pev, &GLOBAL_TIMER); 85 | gw_event_set_timestamp(pev,GLOBAL_TIMER.timestamp); 86 | gw_msg_init(&pev->msg,id); 87 | } 88 | 89 | void gw_event_set_timer(gw_event_t *pev, struct gw_timer* ptimer){ 90 | pev->g_timer = ptimer; 91 | } 92 | 93 | void gw_event_set_timestamp(gw_event_t *pev, uint32_t timestamp){ 94 | pev->timestamp = timestamp; 95 | } 96 | 97 | void gw_event_set_id(gw_event_t *pev, DATA_TYPE id){ 98 | pev->id = id; 99 | } 100 | 101 | void gw_event_set_type(gw_event_t *pev, uint8_t type){ 102 | pev->type = type; 103 | } 104 | 105 | void gw_event_set_msg(gw_event_t *pev, const gw_msg_t msg){ 106 | pev->msg = msg; 107 | } 108 | 109 | void gw_event_set_status(gw_event_t *pev, uint8_t status){ 110 | pev->status = status; 111 | } 112 | 113 | void gw_event_set_init_func(gw_event_t *pev, p_init_func init_task){ 114 | pev->init_task = init_task; 115 | } 116 | 117 | void gw_event_set_exec_task(gw_event_t *pev, p_exec_func exec_task){ 118 | pev->exec_task = exec_task; 119 | } 120 | 121 | void gw_event_set_exec_args_task(gw_event_t *pev, p_exec_args_func exec_args_task){ 122 | pev->exec_args_task = exec_args_task; 123 | } 124 | 125 | void gw_event_set_poll_time(gw_event_t *pev, uint32_t poll_time){ 126 | pev->poll_time = poll_time; 127 | } 128 | 129 | void gw_event_set_priority(gw_event_t *pev, uint32_t priority){ 130 | pev->priority = priority; 131 | } 132 | 133 | DATA_TYPE gw_event_get_id(gw_event_t *pev){ 134 | return pev->id; 135 | } 136 | 137 | uint8_t gw_event_get_type(gw_event_t *pev){ 138 | return pev->type; 139 | } 140 | 141 | gw_msg_t gw_event_get_msg(gw_event_t *pev){ 142 | return pev->msg; 143 | } 144 | 145 | uint8_t gw_event_get_status(gw_event_t *pev){ 146 | return pev->status; 147 | } 148 | 149 | uint32_t gw_event_get_poll_time(gw_event_t *pev){ 150 | return pev->poll_time; 151 | } 152 | 153 | uint32_t gw_event_get_priority(gw_event_t *pev){ 154 | return pev->priority; 155 | } 156 | 157 | p_init_func gw_event_get_init_func(gw_event_t *pev){ 158 | return pev->init_task; 159 | } 160 | 161 | p_exec_func gw_event_get_exec_task(gw_event_t *pev){ 162 | return pev->exec_task; 163 | } 164 | 165 | p_exec_args_func gw_event_get_exec_args_task(gw_event_t *pev){ 166 | return pev->exec_args_task; 167 | } 168 | 169 | struct gw_timer* gw_event_get_timer(gw_event_t *pev){ 170 | return pev->g_timer; 171 | } 172 | 173 | -------------------------------------------------------------------------------- /Source/GwOS/gw_msgs.c: -------------------------------------------------------------------------------- 1 | /** 2 | ************************************************************************************************ 3 | * @file : gw_msgs.c 4 | * @brief : 5 | * @details : 6 | * @date : 11-09-2019 7 | * @version : v1.0.0.0 8 | * @author : UncleMac 9 | * @email : zhaojunhui1861@163.com 10 | * 11 | * @license : GNU General Public License, version 3 (GPL-3.0) 12 | * 13 | * Copyright (C)2019 UncleMac. 14 | * 15 | * This code is open source: you can redistribute it and/or modify 16 | * it under the terms of the GNU General Public License as published by 17 | * the Free Software Foundation, either version 3 of the License, or 18 | * (at your option) any later version. 19 | * 20 | * This code is distributed in the hope that it will be useful, 21 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 22 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the 23 | * GNU General Public License for more details. 24 | * 25 | * You should have received a copy of the GNU General Public License 26 | * along with this program.If not, see < https://www.gnu.org/licenses/>. 27 | ************************************************************************************************* 28 | */ 29 | #include "gw_msgs.h" 30 | 31 | gw_msg_fifo_t msg_fifo; 32 | 33 | /** 34 | * @brief Initialize the ring fifo queue 35 | */ 36 | void gw_msg_fifo_init(gw_msg_fifo_t * const pfifo){ 37 | pfifo->size = MSGS_FIFO_SIZE; 38 | pfifo->front = pfifo->rear = 0; 39 | for(int i = 0; imsgs[i].pstr = NULL; 41 | } 42 | } 43 | 44 | 45 | /** 46 | * @brief Gets a pointer to the global message queue 47 | */ 48 | gw_msg_fifo_t* gw_msg_fifo_get_pointer(void){ 49 | return &msg_fifo; 50 | } 51 | 52 | 53 | /** 54 | * @brief Empty the ring fifo queue 55 | */ 56 | void gw_msg_fifo_clear(gw_msg_fifo_t * const pfifo){ 57 | pfifo->front = pfifo->rear = 0; 58 | for(int i = 0; imsgs[i].pstr = NULL; 60 | } 61 | } 62 | 63 | /** 64 | * @brief Initialize a single message 65 | * @param pmsg - pointer to the msg 66 | * @param id - the id of task 67 | */ 68 | void gw_msg_init(gw_msg_t* const pmsg,DATA_TYPE id){ 69 | pmsg->pstr = NULL; 70 | pmsg->task_id = id; 71 | } 72 | 73 | /** 74 | * @brief Check if the queue is full 75 | * @param pfifo - pointer to the fifo 76 | * @return GW_RESULT 77 | */ 78 | GW_RESULT gw_msg_fifo_is_full(gw_msg_fifo_t* const pfifo){ 79 | 80 | if( (pfifo->rear + 1) % pfifo->size == pfifo->front){ 81 | return GW_TRUE; 82 | } 83 | return GW_FALSE; 84 | } 85 | 86 | /** 87 | * @brief Check if the queue is empty 88 | * @param pfifo - pointer to the fifo 89 | * @return GW_RESULT 90 | */ 91 | GW_RESULT gw_msg_fifo_is_empty(gw_msg_fifo_t* const pfifo){ 92 | if(pfifo->front == pfifo->rear){ 93 | return GW_TRUE; 94 | } 95 | return GW_FALSE; 96 | } 97 | 98 | /** 99 | * @brief Enqueue up for a message 100 | * @param pfifo - pointer to the fifo 101 | * @param pmsg - the pointer to the intput message 102 | * @return GW_RESULT 103 | */ 104 | GW_RESULT gw_msg_fifo_enqueue(gw_msg_fifo_t* const pfifo,gw_msg_t* const pmsg){ 105 | //判断队列非满可入队 106 | if(gw_msg_fifo_is_full(pfifo) == GW_TRUE){ 107 | return GW_ERROR; 108 | } 109 | pfifo->msgs[pfifo->rear++%pfifo->size] = *pmsg; 110 | return GW_SUCCESS; 111 | } 112 | 113 | /** 114 | * @brief Queue up for a message 115 | * @param pfifo - pointer to the fifo 116 | * @param pmsg - the pointer to the output message 117 | * @return GW_RESULT 118 | */ 119 | GW_RESULT gw_msg_fifo_dequeue(gw_msg_fifo_t* const pfifo,gw_msg_t* const pmsg){ 120 | 121 | //判断队列非空可出队 122 | if(gw_msg_fifo_is_empty(pfifo) == GW_TRUE){ 123 | return GW_ERROR; 124 | } 125 | *pmsg = pfifo->msgs[pfifo->front++ % pfifo->size]; 126 | return GW_SUCCESS; 127 | } 128 | 129 | /** 130 | * @brief Sends a message to the task with the specified ID 131 | * @param taskid - the specified ID of the target task 132 | * @param pfifo - pointer to the fifo 133 | * @param pmsg - the pointer to the message will be sent 134 | * @return GW_RESULT 135 | */ 136 | GW_RESULT gw_msg_send_msg(uint32_t taskid, gw_msg_fifo_t* const pfifo, 137 | gw_msg_t* const pmsg){ 138 | 139 | if(gw_msg_fifo_is_full(pfifo) == GW_TRUE){ 140 | return GW_ERROR; 141 | } 142 | pmsg->task_id = taskid; 143 | gw_msg_fifo_enqueue(pfifo, pmsg); 144 | 145 | return GW_SUCCESS; 146 | } 147 | 148 | /** 149 | * @brief Sends a string to the task with the specified ID 150 | * @param taskid - the specified ID of the target task 151 | * @param pfifo - pointer to the fifo 152 | * @param pmsg - the pointer to the string will be sent 153 | * @return GW_RESULT 154 | */ 155 | GW_RESULT gw_msg_send_str(uint32_t taskid, gw_msg_fifo_t* const pfifo, 156 | const char *pstr){ 157 | 158 | if(gw_msg_fifo_is_full(pfifo) == GW_TRUE){ 159 | return GW_ERROR; 160 | } 161 | gw_msg_t msg; 162 | msg.pstr = (char *)pstr; 163 | msg.task_id = taskid; 164 | gw_msg_fifo_enqueue(pfifo, &msg); 165 | 166 | return GW_SUCCESS; 167 | } 168 | 169 | /** 170 | * @brief Receives a message with the specified task ID from the message queue 171 | * @param taskid - the specified ID of the target task 172 | * @param pfifo - pointer to the fifo 173 | * @param pmsg - pmsg - the pointer to the output message 174 | * @return GW_RESULT 175 | */ 176 | GW_RESULT gw_msg_receive(uint32_t taskid, gw_msg_fifo_t* const pfifo, 177 | gw_msg_t* const pmsg){ 178 | 179 | gw_msg_t* pmsg_tmp = NULL; 180 | uint8_t front = 0; 181 | if(gw_msg_fifo_is_empty(pfifo) == GW_TRUE){ 182 | pmsg->pstr = NULL; 183 | pmsg->task_id = 0; 184 | return GW_ERROR; 185 | } 186 | front = pfifo->front%pfifo->size; 187 | 188 | pmsg_tmp = &(pfifo->msgs[front]); 189 | if(pmsg_tmp->task_id == taskid){ 190 | //*pmsg = pfifo->msgs[front]; 191 | gw_msg_fifo_dequeue(pfifo, pmsg); 192 | return GW_SUCCESS; 193 | }else{ 194 | pmsg->pstr = NULL; 195 | return GW_ERROR; 196 | } 197 | } 198 | 199 | -------------------------------------------------------------------------------- /Source/Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_wwdg.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f10x_wwdg.c 4 | * @author MCD Application Team 5 | * @version V3.5.0 6 | * @date 11-March-2011 7 | * @brief This file provides all the WWDG firmware functions. 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 12 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE 13 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY 14 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING 15 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE 16 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 17 | * 18 | *

© COPYRIGHT 2011 STMicroelectronics

19 | ****************************************************************************** 20 | */ 21 | 22 | /* Includes ------------------------------------------------------------------*/ 23 | #include "stm32f10x_wwdg.h" 24 | #include "stm32f10x_rcc.h" 25 | 26 | /** @addtogroup STM32F10x_StdPeriph_Driver 27 | * @{ 28 | */ 29 | 30 | /** @defgroup WWDG 31 | * @brief WWDG driver modules 32 | * @{ 33 | */ 34 | 35 | /** @defgroup WWDG_Private_TypesDefinitions 36 | * @{ 37 | */ 38 | 39 | /** 40 | * @} 41 | */ 42 | 43 | /** @defgroup WWDG_Private_Defines 44 | * @{ 45 | */ 46 | 47 | /* ----------- WWDG registers bit address in the alias region ----------- */ 48 | #define WWDG_OFFSET (WWDG_BASE - PERIPH_BASE) 49 | 50 | /* Alias word address of EWI bit */ 51 | #define CFR_OFFSET (WWDG_OFFSET + 0x04) 52 | #define EWI_BitNumber 0x09 53 | #define CFR_EWI_BB (PERIPH_BB_BASE + (CFR_OFFSET * 32) + (EWI_BitNumber * 4)) 54 | 55 | /* --------------------- WWDG registers bit mask ------------------------ */ 56 | 57 | /* CR register bit mask */ 58 | #define CR_WDGA_Set ((uint32_t)0x00000080) 59 | 60 | /* CFR register bit mask */ 61 | #define CFR_WDGTB_Mask ((uint32_t)0xFFFFFE7F) 62 | #define CFR_W_Mask ((uint32_t)0xFFFFFF80) 63 | #define BIT_Mask ((uint8_t)0x7F) 64 | 65 | /** 66 | * @} 67 | */ 68 | 69 | /** @defgroup WWDG_Private_Macros 70 | * @{ 71 | */ 72 | 73 | /** 74 | * @} 75 | */ 76 | 77 | /** @defgroup WWDG_Private_Variables 78 | * @{ 79 | */ 80 | 81 | /** 82 | * @} 83 | */ 84 | 85 | /** @defgroup WWDG_Private_FunctionPrototypes 86 | * @{ 87 | */ 88 | 89 | /** 90 | * @} 91 | */ 92 | 93 | /** @defgroup WWDG_Private_Functions 94 | * @{ 95 | */ 96 | 97 | /** 98 | * @brief Deinitializes the WWDG peripheral registers to their default reset values. 99 | * @param None 100 | * @retval None 101 | */ 102 | void WWDG_DeInit(void) 103 | { 104 | RCC_APB1PeriphResetCmd(RCC_APB1Periph_WWDG, ENABLE); 105 | RCC_APB1PeriphResetCmd(RCC_APB1Periph_WWDG, DISABLE); 106 | } 107 | 108 | /** 109 | * @brief Sets the WWDG Prescaler. 110 | * @param WWDG_Prescaler: specifies the WWDG Prescaler. 111 | * This parameter can be one of the following values: 112 | * @arg WWDG_Prescaler_1: WWDG counter clock = (PCLK1/4096)/1 113 | * @arg WWDG_Prescaler_2: WWDG counter clock = (PCLK1/4096)/2 114 | * @arg WWDG_Prescaler_4: WWDG counter clock = (PCLK1/4096)/4 115 | * @arg WWDG_Prescaler_8: WWDG counter clock = (PCLK1/4096)/8 116 | * @retval None 117 | */ 118 | void WWDG_SetPrescaler(uint32_t WWDG_Prescaler) 119 | { 120 | uint32_t tmpreg = 0; 121 | /* Check the parameters */ 122 | assert_param(IS_WWDG_PRESCALER(WWDG_Prescaler)); 123 | /* Clear WDGTB[1:0] bits */ 124 | tmpreg = WWDG->CFR & CFR_WDGTB_Mask; 125 | /* Set WDGTB[1:0] bits according to WWDG_Prescaler value */ 126 | tmpreg |= WWDG_Prescaler; 127 | /* Store the new value */ 128 | WWDG->CFR = tmpreg; 129 | } 130 | 131 | /** 132 | * @brief Sets the WWDG window value. 133 | * @param WindowValue: specifies the window value to be compared to the downcounter. 134 | * This parameter value must be lower than 0x80. 135 | * @retval None 136 | */ 137 | void WWDG_SetWindowValue(uint8_t WindowValue) 138 | { 139 | __IO uint32_t tmpreg = 0; 140 | 141 | /* Check the parameters */ 142 | assert_param(IS_WWDG_WINDOW_VALUE(WindowValue)); 143 | /* Clear W[6:0] bits */ 144 | 145 | tmpreg = WWDG->CFR & CFR_W_Mask; 146 | 147 | /* Set W[6:0] bits according to WindowValue value */ 148 | tmpreg |= WindowValue & (uint32_t) BIT_Mask; 149 | 150 | /* Store the new value */ 151 | WWDG->CFR = tmpreg; 152 | } 153 | 154 | /** 155 | * @brief Enables the WWDG Early Wakeup interrupt(EWI). 156 | * @param None 157 | * @retval None 158 | */ 159 | void WWDG_EnableIT(void) 160 | { 161 | *(__IO uint32_t *) CFR_EWI_BB = (uint32_t)ENABLE; 162 | } 163 | 164 | /** 165 | * @brief Sets the WWDG counter value. 166 | * @param Counter: specifies the watchdog counter value. 167 | * This parameter must be a number between 0x40 and 0x7F. 168 | * @retval None 169 | */ 170 | void WWDG_SetCounter(uint8_t Counter) 171 | { 172 | /* Check the parameters */ 173 | assert_param(IS_WWDG_COUNTER(Counter)); 174 | /* Write to T[6:0] bits to configure the counter value, no need to do 175 | a read-modify-write; writing a 0 to WDGA bit does nothing */ 176 | WWDG->CR = Counter & BIT_Mask; 177 | } 178 | 179 | /** 180 | * @brief Enables WWDG and load the counter value. 181 | * @param Counter: specifies the watchdog counter value. 182 | * This parameter must be a number between 0x40 and 0x7F. 183 | * @retval None 184 | */ 185 | void WWDG_Enable(uint8_t Counter) 186 | { 187 | /* Check the parameters */ 188 | assert_param(IS_WWDG_COUNTER(Counter)); 189 | WWDG->CR = CR_WDGA_Set | Counter; 190 | } 191 | 192 | /** 193 | * @brief Checks whether the Early Wakeup interrupt flag is set or not. 194 | * @param None 195 | * @retval The new state of the Early Wakeup interrupt flag (SET or RESET) 196 | */ 197 | FlagStatus WWDG_GetFlagStatus(void) 198 | { 199 | return (FlagStatus)(WWDG->SR); 200 | } 201 | 202 | /** 203 | * @brief Clears Early Wakeup interrupt flag. 204 | * @param None 205 | * @retval None 206 | */ 207 | void WWDG_ClearFlag(void) 208 | { 209 | WWDG->SR = (uint32_t)RESET; 210 | } 211 | 212 | /** 213 | * @} 214 | */ 215 | 216 | /** 217 | * @} 218 | */ 219 | 220 | /** 221 | * @} 222 | */ 223 | 224 | /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ 225 | -------------------------------------------------------------------------------- /Source/User/stm32f10x_it.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file Project/STM32F10x_StdPeriph_Template/stm32f10x_it.c 4 | * @author MCD Application Team 5 | * @version V3.5.0 6 | * @date 08-April-2011 7 | * @brief Main Interrupt Service Routines. 8 | * This file provides template for all exceptions handler and 9 | * peripherals interrupt service routine. 10 | ****************************************************************************** 11 | * @attention 12 | * 13 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 14 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE 15 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY 16 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING 17 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE 18 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 19 | * 20 | *

© COPYRIGHT 2011 STMicroelectronics

21 | ****************************************************************************** 22 | */ 23 | 24 | /* Includes ------------------------------------------------------------------*/ 25 | #include 26 | #include "stm32f10x_it.h" 27 | #include "user_config.h" 28 | #include "foc.h" 29 | #include "user_state_machine.h" 30 | #include "current.h" 31 | #include "task_motor_control.h" 32 | 33 | extern foc_mod_t foc_obj; 34 | 35 | 36 | /** @addtogroup STM32F10x_StdPeriph_Template 37 | * @{ 38 | */ 39 | 40 | /******************************************************************************/ 41 | /* Cortex-M3 Processor Exceptions Handlers */ 42 | /******************************************************************************/ 43 | 44 | /** 45 | * @brief This function handles NMI exception. 46 | * @param None 47 | * @retval None 48 | */ 49 | void NMI_Handler(void) 50 | { 51 | 52 | } 53 | 54 | /** 55 | * @brief This function handles Hard Fault exception. 56 | * @param None 57 | * @retval None 58 | */ 59 | void HardFault_Handler(void) 60 | { 61 | /* Go to infinite loop when Hard Fault exception occurs */ 62 | while (1) 63 | { 64 | //printf("HardFault_Handler\n"); 65 | } 66 | } 67 | 68 | /** 69 | * @brief This function handles Memory Manage exception. 70 | * @param None 71 | * @retval None 72 | */ 73 | void MemManage_Handler(void) 74 | { 75 | /* Go to infinite loop when Memory Manage exception occurs */ 76 | while (1) 77 | { 78 | 79 | } 80 | } 81 | 82 | /** 83 | * @brief This function handles Bus Fault exception. 84 | * @param None 85 | * @retval None 86 | */ 87 | void BusFault_Handler(void) 88 | { 89 | /* Go to infinite loop when Bus Fault exception occurs */ 90 | while (1) 91 | { 92 | } 93 | } 94 | 95 | /** 96 | * @brief This function handles Usage Fault exception. 97 | * @param None 98 | * @retval None 99 | */ 100 | void UsageFault_Handler(void) 101 | { 102 | /* Go to infinite loop when Usage Fault exception occurs */ 103 | while (1) 104 | { 105 | } 106 | } 107 | 108 | /** 109 | * @brief This function handles SVCall exception. 110 | * @param None 111 | * @retval None 112 | */ 113 | void SVC_Handler(void) 114 | { 115 | } 116 | 117 | /** 118 | * @brief This function handles Debug Monitor exception. 119 | * @param None 120 | * @retval None 121 | */ 122 | void DebugMon_Handler(void) 123 | { 124 | } 125 | 126 | /** 127 | * @brief This function handles PendSVC exception. 128 | * @param None 129 | * @retval None 130 | */ 131 | void PendSV_Handler(void) 132 | { 133 | } 134 | 135 | /** 136 | * @brief This function handles SysTick Handler. 137 | * @param None 138 | * @retval None 139 | */ 140 | void SysTick_Handler(void) 141 | { 142 | //timer_add(&global_timer); 143 | #if USE_TASK_LIST 144 | gw_task_schedule(); 145 | #else 146 | if(time_cricle++%1 == 0){ 147 | gw_poll_event_task(); 148 | } 149 | #endif 150 | gw_global_timer_add(); 151 | gw_hal_dec(); 152 | } 153 | 154 | 155 | /******************************************************************************/ 156 | /* STM32F10x Peripherals Interrupt Handlers */ 157 | /* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */ 158 | /* available peripheral interrupt handler's name please refer to the startup */ 159 | /* file (startup_stm32f10x_xx.s). */ 160 | /******************************************************************************/ 161 | 162 | /** 163 | * @brief This function handles PPP interrupt request. 164 | * @param None 165 | * @retval None 166 | */ 167 | /*void PPP_IRQHandler(void) 168 | { 169 | }*/ 170 | 171 | /* 172 | void TIM1_UP_IRQHandler(void){ 173 | //static uint32_t i=0; 174 | if(TIM_GetFlagStatus(TIM1, TIM_IT_Update) == SET){ 175 | //set_inject_ia(cur_fbk_get_Ia()); 176 | //set_inject_ib(cur_fbk_get_Ib()); 177 | } 178 | TIM_ClearITPendingBit(TIM1, TIM_IT_Update); 179 | } 180 | */ 181 | void ADC1_2_IRQHandler(void) 182 | { 183 | Curr_Components cur_ab; 184 | int32_t wia = 0, wib = 0; 185 | if(ADC_GetITStatus(ADC1, ADC_IT_JEOC) == SET){ 186 | #if 0 187 | cur_ab.qI_Component1 = ADC_GetInjectedConversionValue(ADC1, IA_INJECT_CHANNEL_DRI); 188 | cur_ab.qI_Component2 = ADC_GetInjectedConversionValue(ADC1, IB_INJECT_CHANNEL_DRI); 189 | set_inject_ia(cur_ab.qI_Component1); 190 | set_inject_ib(cur_ab.qI_Component2); 191 | #else 192 | ADC_ITConfig(ADC1, ADC_IT_JEOC, DISABLE); 193 | set_inject_ia(IA_VALUE_REG); 194 | set_inject_ib(IB_VALUE_REG); 195 | 196 | /* 197 | ST坐标 a/b 198 | 199 | a 200 | ^ 201 | | 202 | | 203 | | 204 | --------------> b 205 | */ 206 | wia = (int32_t)((int32_t)(IA_VALUE_REG - foc_obj.feedback.cur_offset.qI_Component1)*Q14/2048*165/454*5); 207 | wib = (int32_t)((int32_t)(IB_VALUE_REG - foc_obj.feedback.cur_offset.qI_Component2)*Q14/2048*165/454*5); 208 | 209 | cur_ab.qI_Component1 = (int16_t)wib; 210 | cur_ab.qI_Component2 = (int16_t)wia; 211 | 212 | if(stm_get_cur_state(&motor_state) == TEST){ 213 | 214 | } 215 | if(stm_get_cur_state(&motor_state) == START_UP){ 216 | task_motor_startup_05(cur_ab,50000); 217 | //task_motor_startup_04(cur_ab,50000); 218 | //task_motor_startup_03(cur_ab,50000); 219 | //task_motor_startup_02(cur_ab,5000); 220 | //task_motor_startup(cur_ab,5000); 221 | }else if(stm_get_cur_state(&motor_state) == RUN){ 222 | task_motor_cur_loop(cur_ab); 223 | }else if (stm_get_cur_state(&motor_state) == STOP){ 224 | task_motor_stop(); 225 | } 226 | ADC_ITConfig(ADC1, ADC_IT_JEOC, ENABLE); 227 | #endif 228 | } 229 | 230 | /* Clear ADC1 JEOC pending interrupt bit */ 231 | ADC_ClearITPendingBit(ADC1, ADC_IT_JEOC); 232 | } 233 | 234 | 235 | /** 236 | * @} 237 | */ 238 | 239 | /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ 240 | -------------------------------------------------------------------------------- /Source/Libraries/STM32F10x_StdPeriph_Driver/inc/stm32f10x_cec.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f10x_cec.h 4 | * @author MCD Application Team 5 | * @version V3.5.0 6 | * @date 11-March-2011 7 | * @brief This file contains all the functions prototypes for the CEC firmware 8 | * library. 9 | ****************************************************************************** 10 | * @attention 11 | * 12 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 13 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE 14 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY 15 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING 16 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE 17 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 18 | * 19 | *

© COPYRIGHT 2011 STMicroelectronics

20 | ****************************************************************************** 21 | */ 22 | 23 | /* Define to prevent recursive inclusion -------------------------------------*/ 24 | #ifndef __STM32F10x_CEC_H 25 | #define __STM32F10x_CEC_H 26 | 27 | #ifdef __cplusplus 28 | extern "C" { 29 | #endif 30 | 31 | /* Includes ------------------------------------------------------------------*/ 32 | #include "stm32f10x.h" 33 | 34 | /** @addtogroup STM32F10x_StdPeriph_Driver 35 | * @{ 36 | */ 37 | 38 | /** @addtogroup CEC 39 | * @{ 40 | */ 41 | 42 | 43 | /** @defgroup CEC_Exported_Types 44 | * @{ 45 | */ 46 | 47 | /** 48 | * @brief CEC Init structure definition 49 | */ 50 | typedef struct 51 | { 52 | uint16_t CEC_BitTimingMode; /*!< Configures the CEC Bit Timing Error Mode. 53 | This parameter can be a value of @ref CEC_BitTiming_Mode */ 54 | uint16_t CEC_BitPeriodMode; /*!< Configures the CEC Bit Period Error Mode. 55 | This parameter can be a value of @ref CEC_BitPeriod_Mode */ 56 | }CEC_InitTypeDef; 57 | 58 | /** 59 | * @} 60 | */ 61 | 62 | /** @defgroup CEC_Exported_Constants 63 | * @{ 64 | */ 65 | 66 | /** @defgroup CEC_BitTiming_Mode 67 | * @{ 68 | */ 69 | #define CEC_BitTimingStdMode ((uint16_t)0x00) /*!< Bit timing error Standard Mode */ 70 | #define CEC_BitTimingErrFreeMode CEC_CFGR_BTEM /*!< Bit timing error Free Mode */ 71 | 72 | #define IS_CEC_BIT_TIMING_ERROR_MODE(MODE) (((MODE) == CEC_BitTimingStdMode) || \ 73 | ((MODE) == CEC_BitTimingErrFreeMode)) 74 | /** 75 | * @} 76 | */ 77 | 78 | /** @defgroup CEC_BitPeriod_Mode 79 | * @{ 80 | */ 81 | #define CEC_BitPeriodStdMode ((uint16_t)0x00) /*!< Bit period error Standard Mode */ 82 | #define CEC_BitPeriodFlexibleMode CEC_CFGR_BPEM /*!< Bit period error Flexible Mode */ 83 | 84 | #define IS_CEC_BIT_PERIOD_ERROR_MODE(MODE) (((MODE) == CEC_BitPeriodStdMode) || \ 85 | ((MODE) == CEC_BitPeriodFlexibleMode)) 86 | /** 87 | * @} 88 | */ 89 | 90 | 91 | /** @defgroup CEC_interrupts_definition 92 | * @{ 93 | */ 94 | #define CEC_IT_TERR CEC_CSR_TERR 95 | #define CEC_IT_TBTRF CEC_CSR_TBTRF 96 | #define CEC_IT_RERR CEC_CSR_RERR 97 | #define CEC_IT_RBTF CEC_CSR_RBTF 98 | #define IS_CEC_GET_IT(IT) (((IT) == CEC_IT_TERR) || ((IT) == CEC_IT_TBTRF) || \ 99 | ((IT) == CEC_IT_RERR) || ((IT) == CEC_IT_RBTF)) 100 | /** 101 | * @} 102 | */ 103 | 104 | 105 | /** @defgroup CEC_Own_Address 106 | * @{ 107 | */ 108 | #define IS_CEC_ADDRESS(ADDRESS) ((ADDRESS) < 0x10) 109 | /** 110 | * @} 111 | */ 112 | 113 | /** @defgroup CEC_Prescaler 114 | * @{ 115 | */ 116 | #define IS_CEC_PRESCALER(PRESCALER) ((PRESCALER) <= 0x3FFF) 117 | 118 | /** 119 | * @} 120 | */ 121 | 122 | /** @defgroup CEC_flags_definition 123 | * @{ 124 | */ 125 | 126 | /** 127 | * @brief ESR register flags 128 | */ 129 | #define CEC_FLAG_BTE ((uint32_t)0x10010000) 130 | #define CEC_FLAG_BPE ((uint32_t)0x10020000) 131 | #define CEC_FLAG_RBTFE ((uint32_t)0x10040000) 132 | #define CEC_FLAG_SBE ((uint32_t)0x10080000) 133 | #define CEC_FLAG_ACKE ((uint32_t)0x10100000) 134 | #define CEC_FLAG_LINE ((uint32_t)0x10200000) 135 | #define CEC_FLAG_TBTFE ((uint32_t)0x10400000) 136 | 137 | /** 138 | * @brief CSR register flags 139 | */ 140 | #define CEC_FLAG_TEOM ((uint32_t)0x00000002) 141 | #define CEC_FLAG_TERR ((uint32_t)0x00000004) 142 | #define CEC_FLAG_TBTRF ((uint32_t)0x00000008) 143 | #define CEC_FLAG_RSOM ((uint32_t)0x00000010) 144 | #define CEC_FLAG_REOM ((uint32_t)0x00000020) 145 | #define CEC_FLAG_RERR ((uint32_t)0x00000040) 146 | #define CEC_FLAG_RBTF ((uint32_t)0x00000080) 147 | 148 | #define IS_CEC_CLEAR_FLAG(FLAG) ((((FLAG) & (uint32_t)0xFFFFFF03) == 0x00) && ((FLAG) != 0x00)) 149 | 150 | #define IS_CEC_GET_FLAG(FLAG) (((FLAG) == CEC_FLAG_BTE) || ((FLAG) == CEC_FLAG_BPE) || \ 151 | ((FLAG) == CEC_FLAG_RBTFE) || ((FLAG)== CEC_FLAG_SBE) || \ 152 | ((FLAG) == CEC_FLAG_ACKE) || ((FLAG) == CEC_FLAG_LINE) || \ 153 | ((FLAG) == CEC_FLAG_TBTFE) || ((FLAG) == CEC_FLAG_TEOM) || \ 154 | ((FLAG) == CEC_FLAG_TERR) || ((FLAG) == CEC_FLAG_TBTRF) || \ 155 | ((FLAG) == CEC_FLAG_RSOM) || ((FLAG) == CEC_FLAG_REOM) || \ 156 | ((FLAG) == CEC_FLAG_RERR) || ((FLAG) == CEC_FLAG_RBTF)) 157 | 158 | /** 159 | * @} 160 | */ 161 | 162 | /** 163 | * @} 164 | */ 165 | 166 | /** @defgroup CEC_Exported_Macros 167 | * @{ 168 | */ 169 | 170 | /** 171 | * @} 172 | */ 173 | 174 | /** @defgroup CEC_Exported_Functions 175 | * @{ 176 | */ 177 | void CEC_DeInit(void); 178 | void CEC_Init(CEC_InitTypeDef* CEC_InitStruct); 179 | void CEC_Cmd(FunctionalState NewState); 180 | void CEC_ITConfig(FunctionalState NewState); 181 | void CEC_OwnAddressConfig(uint8_t CEC_OwnAddress); 182 | void CEC_SetPrescaler(uint16_t CEC_Prescaler); 183 | void CEC_SendDataByte(uint8_t Data); 184 | uint8_t CEC_ReceiveDataByte(void); 185 | void CEC_StartOfMessage(void); 186 | void CEC_EndOfMessageCmd(FunctionalState NewState); 187 | FlagStatus CEC_GetFlagStatus(uint32_t CEC_FLAG); 188 | void CEC_ClearFlag(uint32_t CEC_FLAG); 189 | ITStatus CEC_GetITStatus(uint8_t CEC_IT); 190 | void CEC_ClearITPendingBit(uint16_t CEC_IT); 191 | 192 | #ifdef __cplusplus 193 | } 194 | #endif 195 | 196 | #endif /* __STM32F10x_CEC_H */ 197 | 198 | /** 199 | * @} 200 | */ 201 | 202 | /** 203 | * @} 204 | */ 205 | 206 | /** 207 | * @} 208 | */ 209 | 210 | /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ 211 | -------------------------------------------------------------------------------- /Source/GwOS/gw_tasks.c: -------------------------------------------------------------------------------- 1 | /** 2 | ************************************************************************************************ 3 | * @file : gw_task.c 4 | * @brief : Task management API 5 | * @details : None 6 | * @date : 11-09-2018 7 | * @version : v1.0.0.0 8 | * @author : UncleMac 9 | * @email : zhaojunhui1861@163.com 10 | * 11 | * @license : GNU General Public License, version 3 (GPL-3.0) 12 | * 13 | * Copyright (C)2019 UncleMac. 14 | * 15 | * This code is open source: you can redistribute it and/or modify 16 | * it under the terms of the GNU General Public License as published by 17 | * the Free Software Foundation, either version 3 of the License, or 18 | * (at your option) any later version. 19 | * 20 | * This code is distributed in the hope that it will be useful, 21 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 22 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the 23 | * GNU General Public License for more details. 24 | * 25 | * You should have received a copy of the GNU General Public License 26 | * along with this program.If not, see < https://www.gnu.org/licenses/>. 27 | ************************************************************************************************* 28 | */ 29 | #include "gw_tasks.h" 30 | #include "gw_list.h" 31 | #include "gw_timer.h" 32 | #include "gw_log.h" 33 | static gw_list* ptask_list = NULL; 34 | 35 | /** 36 | * @brief Initialize the task list 37 | */ 38 | void gw_task_list_init(void){ 39 | ptask_list = gw_list_init(); 40 | ptask_list->event.g_timer = &global_timer; 41 | } 42 | 43 | /** 44 | * @brief create a task 45 | * @param name - pointer to ths string of task name 46 | * @param taskid - task id 47 | * @param type - task type, see gw_type.h 48 | * @param status - task status, see gw_type.h 49 | * @param poll_time - time circle to schedule task 50 | * @param priority - priority of task, low value is high priority 51 | * @param init_func - callback when initialization 52 | * @param p_exec_func - callback without args 53 | * @param p_exec_args_func - callback with args 54 | */ 55 | void gw_task_create(const char *name,DATA_TYPE taskid,uint8_t type, 56 | uint8_t status, uint32_t poll_time,uint32_t priority, 57 | p_init_func init_func, 58 | p_exec_func exec_task, 59 | p_exec_args_func exec_args_task){ 60 | 61 | DATA_TYPE task_id = taskid; 62 | if(task_id == 0){ 63 | task_id = global_timer.timestamp + ptask_list->data; 64 | } 65 | gw_list_node *pnode = gw_list_node_init(task_id); 66 | 67 | gw_event_init(&pnode->event,name, task_id); 68 | 69 | gw_event_set_type(&pnode->event, type); 70 | gw_event_set_status(&pnode->event, status); 71 | gw_event_set_priority(&pnode->event, priority); 72 | gw_event_set_poll_time(&pnode->event, poll_time); 73 | gw_event_set_init_func(&pnode->event, init_func); 74 | gw_event_set_exec_task(&pnode->event, exec_task); 75 | gw_event_set_exec_args_task(&pnode->event, exec_args_task); 76 | gw_event_set_timer(&pnode->event, &global_timer); 77 | gw_event_set_timestamp(&pnode->event, global_timer.timestamp); 78 | gw_msg_init(&pnode->event.msg,task_id); 79 | 80 | gw_list_insert_node_first(ptask_list, pnode); 81 | } 82 | 83 | /** 84 | * @brief Creates a callback function without parameters for the task 85 | * @param name - pointer to ths string of task name 86 | * @param taskid - task id 87 | * @param type - task type, see gw_type.h 88 | * @param status - task status, see gw_type.h 89 | * @param poll_time - time circle to schedule task 90 | * @param priority - priority of task, low value is high priority 91 | * @param init_func - callback when initialization 92 | * @param p_exec_func - callback without args 93 | */ 94 | void gw_task_void_create(const char *name, DATA_TYPE taskid,uint8_t type, 95 | uint8_t status, uint32_t poll_time, 96 | p_init_func init_func, 97 | p_exec_func exec_func){ 98 | gw_task_create(name,taskid,type,status,poll_time,0, 99 | init_func,exec_func, NULL); 100 | } 101 | 102 | /** 103 | * @brief Creates a callback function with parameters for the task 104 | * @param name - pointer to ths string of task name 105 | * @param taskid - task id 106 | * @param type - task type, see gw_type.h 107 | * @param status - task status, see gw_type.h 108 | * @param poll_time - time circle to schedule task 109 | * @param priority - priority of task, low value is high priority 110 | * @param init_func - callback when initialization 111 | * @param p_exec_args_func - callback with args 112 | */ 113 | void gw_task_args_create(const char *name, DATA_TYPE taskid,uint8_t type, 114 | uint8_t status, uint32_t poll_time, 115 | p_init_func init_func, 116 | p_exec_args_func exec_args_func){ 117 | 118 | gw_task_create(name,taskid,type, 119 | status,poll_time,0, 120 | init_func, NULL, exec_args_func); 121 | } 122 | 123 | /** 124 | * @brief The initialization task will be executed 125 | */ 126 | void gw_task_init_process(void){ 127 | gw_list* plist_tmp = NULL; 128 | struct gw_event *p_event = NULL; 129 | if(ptask_list->data < 1){ 130 | return; 131 | } 132 | //GW_ENTER_CRITICAL_AREA; 133 | plist_tmp = ptask_list->next; 134 | while(plist_tmp != NULL){ 135 | p_event = &plist_tmp->event; 136 | if(p_event->init_task != NULL){ 137 | p_event->init_task(); 138 | } 139 | plist_tmp = plist_tmp->next; 140 | //GW_EXIT_CRITICAL_AREA; 141 | } 142 | } 143 | /** 144 | * @brief Task execution function 145 | * The ready task will be executed 146 | */ 147 | void gw_task_process(void){ 148 | gw_list* plist_tmp = NULL; 149 | struct gw_event *p_event = NULL; 150 | if(ptask_list->data < 1){ 151 | return; 152 | } 153 | //GW_ENTER_CRITICAL_AREA; 154 | plist_tmp = ptask_list->next; 155 | while(plist_tmp != NULL){ 156 | p_event = &plist_tmp->event; 157 | if(p_event->status == GW_ENABLE ){ 158 | if( p_event->exec_task != NULL){ 159 | p_event->exec_task(); 160 | } 161 | if(p_event->exec_args_task != NULL){ 162 | p_event->exec_args_task((struct gw_event *)p_event); 163 | } 164 | p_event->status = GW_DISABLE; 165 | } 166 | plist_tmp = plist_tmp->next; 167 | //GW_EXIT_CRITICAL_AREA; 168 | } 169 | } 170 | 171 | /** 172 | * @brief Task scheduling function 173 | * if task is ready, status will be set GW_ENABLE 174 | */ 175 | void gw_task_schedule(void){ 176 | gw_list* plist_tmp = NULL; 177 | struct gw_event *p_event = NULL; 178 | if(ptask_list->data < 1){ 179 | return; 180 | } 181 | //GW_ENTER_CRITICAL_AREA; 182 | plist_tmp = ptask_list->next; 183 | while(plist_tmp != NULL){ 184 | p_event = &plist_tmp->event; 185 | if(p_event->poll_time + p_event->timestamp < p_event->g_timer->timestamp ){ 186 | p_event->timestamp = p_event->g_timer->timestamp; 187 | p_event->status = GW_ENABLE; 188 | } 189 | plist_tmp = plist_tmp->next; 190 | } 191 | //GW_EXIT_CRITICAL_AREA; 192 | } 193 | -------------------------------------------------------------------------------- /Source/Libraries/STM32F10x_StdPeriph_Driver/inc/stm32f10x_exti.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file stm32f10x_exti.h 4 | * @author MCD Application Team 5 | * @version V3.5.0 6 | * @date 11-March-2011 7 | * @brief This file contains all the functions prototypes for the EXTI firmware 8 | * library. 9 | ****************************************************************************** 10 | * @attention 11 | * 12 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 13 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE 14 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY 15 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING 16 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE 17 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 18 | * 19 | *

© COPYRIGHT 2011 STMicroelectronics

20 | ****************************************************************************** 21 | */ 22 | 23 | /* Define to prevent recursive inclusion -------------------------------------*/ 24 | #ifndef __STM32F10x_EXTI_H 25 | #define __STM32F10x_EXTI_H 26 | 27 | #ifdef __cplusplus 28 | extern "C" { 29 | #endif 30 | 31 | /* Includes ------------------------------------------------------------------*/ 32 | #include "stm32f10x.h" 33 | 34 | /** @addtogroup STM32F10x_StdPeriph_Driver 35 | * @{ 36 | */ 37 | 38 | /** @addtogroup EXTI 39 | * @{ 40 | */ 41 | 42 | /** @defgroup EXTI_Exported_Types 43 | * @{ 44 | */ 45 | 46 | /** 47 | * @brief EXTI mode enumeration 48 | */ 49 | 50 | typedef enum 51 | { 52 | EXTI_Mode_Interrupt = 0x00, 53 | EXTI_Mode_Event = 0x04 54 | }EXTIMode_TypeDef; 55 | 56 | #define IS_EXTI_MODE(MODE) (((MODE) == EXTI_Mode_Interrupt) || ((MODE) == EXTI_Mode_Event)) 57 | 58 | /** 59 | * @brief EXTI Trigger enumeration 60 | */ 61 | 62 | typedef enum 63 | { 64 | EXTI_Trigger_Rising = 0x08, 65 | EXTI_Trigger_Falling = 0x0C, 66 | EXTI_Trigger_Rising_Falling = 0x10 67 | }EXTITrigger_TypeDef; 68 | 69 | #define IS_EXTI_TRIGGER(TRIGGER) (((TRIGGER) == EXTI_Trigger_Rising) || \ 70 | ((TRIGGER) == EXTI_Trigger_Falling) || \ 71 | ((TRIGGER) == EXTI_Trigger_Rising_Falling)) 72 | /** 73 | * @brief EXTI Init Structure definition 74 | */ 75 | 76 | typedef struct 77 | { 78 | uint32_t EXTI_Line; /*!< Specifies the EXTI lines to be enabled or disabled. 79 | This parameter can be any combination of @ref EXTI_Lines */ 80 | 81 | EXTIMode_TypeDef EXTI_Mode; /*!< Specifies the mode for the EXTI lines. 82 | This parameter can be a value of @ref EXTIMode_TypeDef */ 83 | 84 | EXTITrigger_TypeDef EXTI_Trigger; /*!< Specifies the trigger signal active edge for the EXTI lines. 85 | This parameter can be a value of @ref EXTIMode_TypeDef */ 86 | 87 | FunctionalState EXTI_LineCmd; /*!< Specifies the new state of the selected EXTI lines. 88 | This parameter can be set either to ENABLE or DISABLE */ 89 | }EXTI_InitTypeDef; 90 | 91 | /** 92 | * @} 93 | */ 94 | 95 | /** @defgroup EXTI_Exported_Constants 96 | * @{ 97 | */ 98 | 99 | /** @defgroup EXTI_Lines 100 | * @{ 101 | */ 102 | 103 | #define EXTI_Line0 ((uint32_t)0x00001) /*!< External interrupt line 0 */ 104 | #define EXTI_Line1 ((uint32_t)0x00002) /*!< External interrupt line 1 */ 105 | #define EXTI_Line2 ((uint32_t)0x00004) /*!< External interrupt line 2 */ 106 | #define EXTI_Line3 ((uint32_t)0x00008) /*!< External interrupt line 3 */ 107 | #define EXTI_Line4 ((uint32_t)0x00010) /*!< External interrupt line 4 */ 108 | #define EXTI_Line5 ((uint32_t)0x00020) /*!< External interrupt line 5 */ 109 | #define EXTI_Line6 ((uint32_t)0x00040) /*!< External interrupt line 6 */ 110 | #define EXTI_Line7 ((uint32_t)0x00080) /*!< External interrupt line 7 */ 111 | #define EXTI_Line8 ((uint32_t)0x00100) /*!< External interrupt line 8 */ 112 | #define EXTI_Line9 ((uint32_t)0x00200) /*!< External interrupt line 9 */ 113 | #define EXTI_Line10 ((uint32_t)0x00400) /*!< External interrupt line 10 */ 114 | #define EXTI_Line11 ((uint32_t)0x00800) /*!< External interrupt line 11 */ 115 | #define EXTI_Line12 ((uint32_t)0x01000) /*!< External interrupt line 12 */ 116 | #define EXTI_Line13 ((uint32_t)0x02000) /*!< External interrupt line 13 */ 117 | #define EXTI_Line14 ((uint32_t)0x04000) /*!< External interrupt line 14 */ 118 | #define EXTI_Line15 ((uint32_t)0x08000) /*!< External interrupt line 15 */ 119 | #define EXTI_Line16 ((uint32_t)0x10000) /*!< External interrupt line 16 Connected to the PVD Output */ 120 | #define EXTI_Line17 ((uint32_t)0x20000) /*!< External interrupt line 17 Connected to the RTC Alarm event */ 121 | #define EXTI_Line18 ((uint32_t)0x40000) /*!< External interrupt line 18 Connected to the USB Device/USB OTG FS 122 | Wakeup from suspend event */ 123 | #define EXTI_Line19 ((uint32_t)0x80000) /*!< External interrupt line 19 Connected to the Ethernet Wakeup event */ 124 | 125 | #define IS_EXTI_LINE(LINE) ((((LINE) & (uint32_t)0xFFF00000) == 0x00) && ((LINE) != (uint16_t)0x00)) 126 | #define IS_GET_EXTI_LINE(LINE) (((LINE) == EXTI_Line0) || ((LINE) == EXTI_Line1) || \ 127 | ((LINE) == EXTI_Line2) || ((LINE) == EXTI_Line3) || \ 128 | ((LINE) == EXTI_Line4) || ((LINE) == EXTI_Line5) || \ 129 | ((LINE) == EXTI_Line6) || ((LINE) == EXTI_Line7) || \ 130 | ((LINE) == EXTI_Line8) || ((LINE) == EXTI_Line9) || \ 131 | ((LINE) == EXTI_Line10) || ((LINE) == EXTI_Line11) || \ 132 | ((LINE) == EXTI_Line12) || ((LINE) == EXTI_Line13) || \ 133 | ((LINE) == EXTI_Line14) || ((LINE) == EXTI_Line15) || \ 134 | ((LINE) == EXTI_Line16) || ((LINE) == EXTI_Line17) || \ 135 | ((LINE) == EXTI_Line18) || ((LINE) == EXTI_Line19)) 136 | 137 | 138 | /** 139 | * @} 140 | */ 141 | 142 | /** 143 | * @} 144 | */ 145 | 146 | /** @defgroup EXTI_Exported_Macros 147 | * @{ 148 | */ 149 | 150 | /** 151 | * @} 152 | */ 153 | 154 | /** @defgroup EXTI_Exported_Functions 155 | * @{ 156 | */ 157 | 158 | void EXTI_DeInit(void); 159 | void EXTI_Init(EXTI_InitTypeDef* EXTI_InitStruct); 160 | void EXTI_StructInit(EXTI_InitTypeDef* EXTI_InitStruct); 161 | void EXTI_GenerateSWInterrupt(uint32_t EXTI_Line); 162 | FlagStatus EXTI_GetFlagStatus(uint32_t EXTI_Line); 163 | void EXTI_ClearFlag(uint32_t EXTI_Line); 164 | ITStatus EXTI_GetITStatus(uint32_t EXTI_Line); 165 | void EXTI_ClearITPendingBit(uint32_t EXTI_Line); 166 | 167 | #ifdef __cplusplus 168 | } 169 | #endif 170 | 171 | #endif /* __STM32F10x_EXTI_H */ 172 | /** 173 | * @} 174 | */ 175 | 176 | /** 177 | * @} 178 | */ 179 | 180 | /** 181 | * @} 182 | */ 183 | 184 | /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ 185 | --------------------------------------------------------------------------------