52 lines
1.1 KiB
C
52 lines
1.1 KiB
C
|
#ifndef USER_CALL_H
|
||
|
#define USER_CALL_H
|
||
|
|
||
|
/**
|
||
|
* How to use this driver
|
||
|
* 1. add follows to SECTIONS in link.ld such us "STM32F407ZGTx_FLASH.ld"
|
||
|
*
|
||
|
..........................
|
||
|
SECTIONS
|
||
|
{
|
||
|
...
|
||
|
.text{:
|
||
|
. = ALIGN(4);
|
||
|
__cmd_call_start = .;
|
||
|
KEEP(*(__cmd_call))
|
||
|
__cmd_call_end = .;
|
||
|
. = ALIGN(4);
|
||
|
..................
|
||
|
* 2. use CMD_EXPORT to bangding the cmd and function
|
||
|
exanple
|
||
|
#define CMD_ADC 1
|
||
|
int abc_deal(void){
|
||
|
return 0;
|
||
|
}
|
||
|
CMD_EXPORT(CMD_ADC,abc_deal);
|
||
|
|
||
|
* 3. add
|
||
|
*/
|
||
|
typedef struct cfg_call_t
|
||
|
{
|
||
|
int __cmd;
|
||
|
int (*__func)(void);
|
||
|
}cfg_call_t;
|
||
|
|
||
|
#if defined(__CC_ARM) || defined(__CLANG_ARM) || defined(__GNUC__) || defined(__ADSPBLACKFIN__)
|
||
|
#define __SECTION(x) __attribute__((section(x)))
|
||
|
#define __USED __attribute__((used))
|
||
|
#elif defined(__IAR_SYSTEMS_ICC__)
|
||
|
#define __SECTION(x) @x
|
||
|
#define __USED __root
|
||
|
#else
|
||
|
#define __SECTION(x)
|
||
|
#define __USED
|
||
|
#endif
|
||
|
|
||
|
#define CMD_EXPORT(cmd, fuction) __USED const cfg_call_t cmd##_func __SECTION("__cmd_call") = { \
|
||
|
.__cmd = cmd, \
|
||
|
.__func = fuction}
|
||
|
|
||
|
|
||
|
|
||
|
#endif
|