void
clock_init()
{
if (SysTick_Config(SystemCoreClock /CLOCK_SECOND))
{
while(1);
}
}
void
SysTick_handler(void)
{current_clock++;
if(etimer_pending() && etimer_next_expiration_time() <=current_clock) {
etimer_request_poll();
/*printf("%d,%d\n", clock_time(),etimer_next_expiration_time ());*/
}
if(--second_countdown == 0) {
current_seconds++;
second_countdown = CLOCK_SECOND;
}
}
将圈红的两个文件复制到user目录下面
其他文件的填写参考野火建立工程的方式
#include "stm32f10x.h"
#include "led.h"
#include
#include
//#include
#include
#include
#include
#include
#include
#include "contiki.h"
unsigned int idle_count = 0;
//事件的声明
static process_event_t event_ledoff;
static process_event_t event_ledon;
//函数声明
void Delay(__IO u32 nCount);
//两个进程的声明
PROCESS(led_on, "led_on");
PROCESS(led_off, "led_off");
//将两个进程加入AUTOSTART_PROCESSES
AUTOSTART_PROCESSES(&led_on, &led_off);
//进程1的函数主体
PROCESS_THREAD(led_on, ev, data)
{
//进程开始
PROCESS_BEGIN();
//获得一个事件或者是初始化
event_ledoff = process_alloc_event();
while(1)
{
//等待事件发生进入,若没有事件发生系统调度到其他地方
PROCESS_WAIT_EVENT_UNTIL(ev == event_ledon);
//打开LED 注意延时
LED1(ON);
//Delay(0xFFFEF);
Delay_us(2);
//发送一个事件,这里是唤醒了第二个进程
process_post(&led_off, event_ledoff, NULL);
}
//进程结束
PROCESS_END();
}
PROCESS_THREAD(led_off, ev, data)
{
PROCESS_BEGIN();
event_ledon = process_alloc_event();
while(1)
{
PROCESS_WAIT_EVENT_UNTIL(ev == event_ledoff);
//打开LED 注意延时
LED1(OFF);
//Delay(0xFFFEF);
Delay_us(2);
process_post(&led_on, event_ledon, NULL);
}
PROCESS_END();
}
int main(void)
{
LED_GPIO_Config();
//做指示灯
LED2(ON);
clock_init();
process_init();
//etimer_process 是系统进程
process_start(&etimer_process,NULL);
//下面这句后面的都不能执行,加锁就可以
autostart_start(autostart_processes);
event_ledon = process_alloc_event();
process_post(&led_on, event_ledon, NULL);
while(1) {
do
{
}
while(process_run()> 0);
idle_count++;
}
return 0;
}
void Delay(__IO u32 nCount)
{
for(;nCount != 0; nCount--);
}
例:在clock.c 中添加
#include "stm32f10x.h"
#include "stm32f10x_it.h"
删除原来的
#include
#include
http://blog.chinaunix.net/uid-9112803-id-2978041.html
『本文转载自网络,版权归原作者所有,如有侵权请联系删除』