Contiki移植到STM32F103VC

Contiki系统简单介绍

Contiki 是一个小型的,开源的,极易移植的多任务电脑操作系统。它专门设计以适用于一系列的内存受限的网络系统,包括从8位电脑到微型控制器的嵌入系统。它的名字来自于托尔·海尔达尔的康提基号。

Contiki只需几kilobyte的代码和几百字节的内存就能提供多任务环境和内建TCP/IP支持。

  • Contiki官网下载V2.5源码http://www.contiki-os.org/

  • contiki-2.5源码中,stm32移植的相关内容分散在两个文件夹中,第一, cpu\arm\stm32f103,这个文件夹存放的stm32移植的相关文件;第二,platform\stm32test,这个文件夹中有一个不是那么完整的例子。

  • 在Contiki-2.5源码文件夹下用到的有:\core\sys\下面所有文件,\cpu\arm\stm32f103\clock.c文件主要修改,\platform\stm32test\contiki-conf.h文件。
  • STM32工程下主要用到的文件:core_cm3.c,system_stm32f10x.c,startup_stm32f10_hd.s,stm32f10x_it.c

    • 例子代码如下:
#include <stm32f10x_map.h>
#include <stm32f10x_dma.h>
#include <gpio.h>
#include <nvic.h>
#include <stdint.h>
#include <stdio.h>
#include <debug-uart.h>
#include <sys/process.h>
#include <sys/procinit.h>
#include <etimer.h>
#include <sys/autostart.h>
#include <clock.h>
unsigned int idle_count = 0;
int
main()
{
  dbg_setup_uart();
  printf("Initialising\n");

  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"::); */ 
  }
  return 0;
}

Contiki 系统移植步骤

  • 在cpu\arm\stm32f10\clock.c文件中添加:
    #include "stm32f10x.h"
  • 在cpu\arm\stm32f10\clock.c文件中删除:
#include <stm32f10x_map.h>
#include <nvic.h>
  • 修改void clock_init()函数为:
void
clock_init()
{
    //every msec got int
    if (SysTick_Config(SystemCoreClock / CLOCK_SECOND))
  { 
    /* Capture error */ 
    while (1);
  }
}
  • 修改void SysTick_Handler(void)函数为:
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;
  }
}
  • 在keil中新建一个工程,就可以了。
  • 新建测试工程主函数:
#include <stdint.h>
#include <stdio.h>
#include <debug-uart.h>
#include <sys/process.h>
#include <sys/procinit.h>
#include <sys/etimer.h>
#include <sys/autostart.h>
#include <sys/clock.h>
#include "bsp.h"

PROCESS_NAME(led_process);

AUTOSTART_PROCESSES(&led_process);

void
main()
{
  bsp_init();

    dbg_setup_uart();
  printf("Initialising...\r\n");

  clock_init();
  process_init();
  process_start(&etimer_process, NULL);
  autostart_start(autostart_processes);
  printf("Processes running...\r\n");
  while(1) {
    do {
    } while(process_run() > 0);
  }
  //return 0;
}
  • 一个点灯的线程:
#include <stdio.h>
#include <sys/process.h>
#include <sys/etimer.h>
#include <sys/stimer.h>
#include "bsp.h"

PROCESS(led_process, "Led");
PROCESS_THREAD(led_process,ev,data){
    static struct etimer et;
    PROCESS_BEGIN();

    etimer_set(&et, (CLOCK_SECOND*2));
    while(1){
        printf("-->Waiting .......\r\n");
        //PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&et));
        PROCESS_WAIT_EVENT_UNTIL(ev==PROCESS_EVENT_TIMER);
        printf("-->Timer Got.\r\n");
        bsp_led_toggle(BOARD_LED_ALL);
        etimer_reset(&et);
    }
    PROCESS_END();
}

以下图片为keil工程结构的参考
工程结构

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值