program1 变量为指向指针的指针。用于遍历section.
int LED_state1(void)
{
rt_thread_sleep(1200);
rt_pin_write(LED0_PIN,1);
rt_pin_write(LED1_PIN,1);
rt_pin_write(LED2_PIN,1);
rt_thread_sleep(1000);
rt_pin_write(LED0_PIN,0);
rt_pin_write(LED1_PIN,1);
rt_pin_write(LED2_PIN,1);
return 0;
}
int LED_state2(void)
{
rt_thread_sleep(1000);
rt_pin_write(LED0_PIN,1);
rt_pin_write(LED1_PIN,1);
rt_pin_write(LED2_PIN,1);
rt_thread_sleep(1000);
rt_pin_write(LED0_PIN,1);
rt_pin_write(LED1_PIN,0);
rt_pin_write(LED2_PIN,1);
return 0;
}
int LED_state3(void)
{
rt_thread_sleep(1000);
rt_pin_write(LED0_PIN,1);
rt_pin_write(LED1_PIN,1);
rt_pin_write(LED2_PIN,1);
rt_thread_sleep(1000);
rt_pin_write(LED0_PIN,1);
rt_pin_write(LED1_PIN,1);
rt_pin_write(LED2_PIN,0);
return 0;
}
typedef int (*Led_ptr)(void);
Led_ptr program;
Led_ptr *program1;
__attribute__((used))Led_ptr (p1) __attribute__((section(".ledsection.")))= LED_state1;
__attribute__((used))Led_ptr (p2) __attribute__((section(".ledsection")))= LED_state2;
__attribute__((used))Led_ptr (p3) __attribute__((section(".ledsection")))= LED_state3;
/*
i.LED_state1 0x080026ea Section 0 main.o(i.LED_state1)
i.LED_state2 0x08002730 Section 0 main.o(i.LED_state2)
i.LED_state3 0x08002776 Section
p1 0x20000244 Data 4 main.o(.ledsection)
p2 0x20000248 Data 4 main.o(.ledsection)
p3 0x2000024c Data 4 main.o(.ledsection)
*/
void app_user_process(void)
{
int i;
while(1)
{
#if 0
for(i=0;i<3;i++)
{
if(i ==0) program = p1;
if(i ==1) program = p2;
if(i ==2) program = p3;
rt_kprintf("program add:%x value %x rn",&program,program);
(*program)();
}
#else
program1 = &p1;
for(i=0;i<3;i++)
{
(*program1)();
program1++;
rt_kprintf(" II program add:%x value %x rn",&program1,program1);
rt_thread_sleep(1000);
}
#endif
}
}
原作者:dengjingg