1. 找一个STM32
的UART
的打印例程,最好支持printf
函数。
2. 将contiki\core\sys
目录下的autostart.c
、etimer.c
、process.c
和timer.c
加入到工程中。
3. 在include
路径中,加入contiki\core
、contiki\core\sys
、contiki\core\lib
、contiki\cpu
。
4. 把cpu\arm\stm32f103
目录下的clock.c
加入到工程中。
5. 在clock.c
中,用#include "stm32f10x.h"
和#include "stm32f10x_it.h"
替换原来的#include <stm32f10x_map.h>
和#include <nvic.h>
。
6. 把platform\stm32test
目录下的contiki_conf.h
加入到include
路径中。
7. 把systick
初始化函数改为:
void clock_init() {
if ( SysTick_Config ( SystemCoreClock / CLOCK_SECOND ) ) {
while ( 1 );
}
}
把systick
中断函数改为:
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;
}
}
最后把stm32f10x_it.c
的void SysTick_Handler(void){}
删除。
8. 将main.c
修改如下:
#include "delay.h"
#include "sys.h"
#include "usart.h"
#include "led.h"
#include <sys/process.h>
#include <sys/procinit.h>
#include <sys/etimer.h>
#include <sys/autostart.h>
#include <sys/clock.h>
PROCESS ( blink_process, "Blink" );
PROCESS_THREAD ( blink_process, ev, data ) {
PROCESS_BEGIN();
while ( 1 ) {
static struct etimer et;
etimer_set ( &et, CLOCK_SECOND );
PROCESS_WAIT_EVENT_UNTIL ( etimer_expired ( &et ) );
LED0 = !LED0;
}
PROCESS_END();
}
PROCESS ( blink_process_2, "Blink" );
PROCESS_THREAD ( blink_process_2, ev, data ) {
PROCESS_BEGIN();
while ( 1 ) {
static struct etimer et_2;
etimer_set ( &et_2, CLOCK_SECOND / 2 );
printf ( "I am running\r\n" );
PROCESS_WAIT_EVENT_UNTIL ( etimer_expired ( &et_2 ) );
LED1 = !LED1;
}
PROCESS_END();
}
unsigned int idle_count = 0;
AUTOSTART_PROCESSES ( &blink_process, &blink_process_2 );
int main ( void ) {
NVIC_Configuration();
uart_init ( 9600 );
LED_Init();
clock_init();
process_init();
process_start ( &etimer_process, NULL );
autostart_start ( autostart_processes );
printf ( "Processes running\n" );
while ( 1 ) {
do {
} while ( process_run() > 0 );
idle_count++;
/* Idle! */
/* Stop processor clock */
/* asm("wfi"::); */
}
}