-
Notifications
You must be signed in to change notification settings - Fork 486
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
115 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
#include <avm_core.h> | ||
|
||
static unsigned char avm_core_init(void *arg); | ||
|
||
avm_module_t avm_core_module_st = { | ||
0, | ||
NULL, | ||
avm_core_init, | ||
NULL, | ||
NULL | ||
}; | ||
|
||
void jump2ISP() { | ||
__set_MSP(*(unsigned int *)ISP_ADDR); | ||
((void (*)(void))*((unsigned int *)(ISP_ADDR + 4)))(); | ||
} | ||
|
||
void delay_ms(unsigned int t) { | ||
SysTick->LOAD = 9000 * t; | ||
SysTick->VAL = 0; | ||
SysTick->CTRL = 0x01; | ||
for(unsigned int tmp = SysTick->CTRL;(tmp&0x01)&&(!(tmp&SysTick_CTRL_COUNTFLAG));tmp = SysTick->CTRL); | ||
SysTick->CTRL = 0; | ||
SysTick->VAL = 0; | ||
} | ||
|
||
// 延时函数, 单位为微秒 | ||
void delay_us(unsigned int t) { | ||
SysTick->LOAD = 9 * t; | ||
SysTick->VAL = 0; | ||
SysTick->CTRL = 0x01; | ||
for(unsigned int tmp = SysTick->CTRL;(tmp&0x01)&&(!(tmp&SysTick_CTRL_COUNTFLAG));tmp = SysTick->CTRL); | ||
SysTick->CTRL = 0; | ||
SysTick->VAL = 0; | ||
} | ||
|
||
avm_module_t *avm_modules_pool[] = { | ||
&avm_core_module_st, | ||
&avm_uart_module_st, | ||
&avm_i2c_module_st, | ||
&avm_motor_module_st, | ||
&avm_mpu_module_st, | ||
NULL | ||
}; | ||
|
||
static unsigned char avm_core_init(void *arg) { | ||
NVIC_SetPriorityGrouping(0x07 - NVIC_GROUPING); | ||
|
||
avm_module_t *p_core = avm_modules_pool[0]; | ||
// Count | ||
static unsigned char avm_modules_num = 0; | ||
for(;avm_modules_pool[avm_modules_num] != NULL;avm_modules_num++) { | ||
avm_modules_pool[avm_modules_num]->index = avm_modules_num; | ||
} | ||
|
||
p_core->confs = (void *)&avm_modules_num; // Stored | ||
// Initial | ||
avm_module_t **this = &avm_modules_pool[1]; | ||
for(;*this != NULL;this++) { | ||
(*this)->init_module((*this)->confs); | ||
} | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#ifndef _AVM_CORE_H_ | ||
#define _AVM_CORE_H_ | ||
|
||
typedef struct avm_module_s avm_module_t; | ||
// typedef struct avm_string_s avm_string_t; | ||
|
||
#include <math.h> | ||
#include <stm32f10x.h> | ||
// #include <avm_string.h> | ||
#include <avm_bit.h> | ||
#include <avm_mpu6050.h> | ||
#include <avm_motor.h> | ||
#include <avm_uart.h> | ||
#include <avm_wifi.h> | ||
#include <avm_pid.h> | ||
#include <avm_i2c.h> | ||
#include <avm_tty.h> | ||
|
||
struct avm_module_s { | ||
unsigned short index; | ||
unsigned int *confs; | ||
unsigned char (*init_module)(void *arg); | ||
unsigned char (*enable_module)(void); | ||
unsigned char (*disable_module)(void); | ||
}; | ||
|
||
extern avm_module_t *avm_modules_pool[]; | ||
extern avm_module_t avm_core_module_st; | ||
|
||
void delay_ms(unsigned int t); | ||
void delay_us(unsigned int t); | ||
|
||
#define NVIC_GROUPING 3 | ||
// Jump to built-in bootloader | ||
#define ISP_ADDR 0x1FFFF000 | ||
void jump2ISP(); | ||
|
||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#ifndef _AVM_STRING_H_ | ||
#define _AVM_STRING_H_ | ||
|
||
struct avm_string_s { | ||
unsigned char * string; | ||
unsigned int len; | ||
}; | ||
|
||
#define avm_string(str) { (unsigned char *)(str), sizeof((str) - 1) } | ||
#define avm_null_string { 0, NULL } | ||
|
||
#endif |