1 Build
1.1 eCos編譯
1)
apt-get install dos2unix
tar -jxvf 2016_0905_eCos_SDK_V3.1.4.0_DPA.tar.bz2
2)
cd eCos_SDK
make clean; make
3)
eCos.img is produced in the “ra305x_ap_adv/ra305x_router”directory
4)
make module_clean; make module
1.2 eCos make menuconfig
執行make menuconfig時會產生一個ra305x_ap_adv/ra305x_router/include/autoconf.h文件,由於很多用戶一般不會用make menuconfig來做配置,那麼可以直接修改該文件添加需要的模塊。
1.3 APP自定義一個目錄
at ra305x_ap_adv/ra305x_router/oem_iot
包含include、Makefile、src
at ra305x_ap_adv/ra305x_router/Makefile
[…]
# oem-begin
APPSUBDIRS += oem_iot
# oem-end
[…]
2 eCos APP自定義section
1)
[at ra305x_ap_adv/ra305x_router/arch/mips/target.ld]
at ra305x_ap_adv/ra305x_router/target.ld
SECTIONS
{
[...]
.text ALIGN (0x4) :
{
[...]
. = ALIGN(4);
PROVIDE (__core_initcall = .);
KEEP(*(.core.initcall))
PROVIDE (__core_initcall_end = .);
. = ALIGN(4);
PROVIDE (__module_initcall = .);
KEEP(*(.module.initcall))
PROVIDE (__module_initcall_end = .);
. = ALIGN(4);
PROVIDE (__late_initcall = .);
KEEP(*(.late.initcall))
PROVIDE (__late_initcall_end = .);
[...]
} > ram =0
[...]
}
2)
at ra305x_ap_adv/ra305x_router/oem_iot/include/oem_portmisc.h
[…]
typedef void (*initcall_t)(void);
extern initcall_t __core_initcall[];
extern initcall_t __core_initcall_end[];
extern initcall_t __module_initcall[];
extern initcall_t __module_initcall_end[];
extern initcall_t __late_initcall[];
extern initcall_t __late_initcall_end[];
#if 1
#define core_initcall(fn) \
static initcall_t __initcall_##fn \
__attribute__((used,section(".core.initcall"))) = fn
#define module_init(fn) \
static initcall_t __initcall_##fn \
__attribute__((used,section(".module.initcall"))) = fn
#define late_initcall(fn) \
static initcall_t __initcall_##fn \
__attribute__((used,section(".late.initcall"))) = fn
#else
#define core_initcall(fn) \
void fn(void) __attribute__((unused))
#define module_init(fn) \
void fn(void) __attribute__((unused))
#define late_initcall(fn) \
void fn(void) __attribute__((unused))
#endif
[…]
3)
at ra305x_ap_adv/ra305x_router/init/main.c
/* oem-begin */
#include "../oem_iot/include/oem_portmisc.h"
/* oem-end */
static void section_core_init(void)
{
initcall_t *initcall;
for (initcall = __core_initcall;
initcall < __core_initcall_end;
initcall++) {
(*initcall)();
}
}
static void section_module_init(void)
{
initcall_t *initcall;
for (initcall = __module_initcall;
initcall < __module_initcall_end;
initcall++) {
(*initcall)();
}
}
static void section_late_init(void)
{
initcall_t *initcall;
for (initcall = __late_initcall;
initcall < __late_initcall_end;
initcall++) {
(*initcall)();
}
}
3 eCos標準驅動框架
1)驅動路徑
at packages/devs/serial/mips/vrc437x/
2)修改ecos.db,將驅動編譯進靜態庫
at packages/ecos.db
package CYGPKG_IO_SERIAL_MIPS_VRC437X {
alias { "VRC437X serial device drivers"
devs_serial_mips_vrc437x vrc437x_serial_driver }
hardware
directory devs/serial/mips/vrc437x
script ser_mips_vrc437x.cdl
description "VRC437X serial device drivers"
}
3)中斷處理頭文件
#include <cyg/hal/hal_intr.h>
#include <cyg/hal/drv_api.h>
4 eCos API
4.1 線程同步
Mailbox(cyg_mbox_create)
Mailbox的結構是一個FIFO類型的循環隊列,存儲的是指針。
4.2 CFG API
static void api_usage_test(void)
{
cyg_uint64 c_time;
char line[8];
unsigned long tv_sec, tv_usec;
c_time = cyg_current_time();
tv_sec = (u_long)(c_time/100);
tv_usec = (((u_long)ctime)%100) * 10000;
diag_printf("tv_sec: %ld, tv_usec: %ld\n", tv_sec, tv_usec);
// interface_config();
CFG_get_str(CFG_SYS_OPMODE, line);
diag_printf("opmode: %d\n", strtol(line, NULL, 10));
CFG_reset_default();
//mon_snd_cmd(MON_CMD_REBOOT);
}
4.3 打印UTC時間
#if TIME_WITH_SYS_TIME
# include <sys/time.h>
# include <time.h>
#else
# if HAVE_SYS_TIME_H
# include <sys/time.h>
# else
# include <time.h>
# endif
#endif
// time_t gmt_translate2localtime(time_t gmt_time)
// struct tm *gmtime(const time_t *timep)
/* 將時間結構體struct tm的值轉化爲經過的秒數 */
// time_t mktime(struct tm *tm)
/* translate " DD-mth-YY HH:MM:SS GMT" to elapsed seconds */
// time_t tdate_parse( char* str)
API void get_now_time(void)
{
struct timespec time;
struct tm nowtime;
clock_gettime(CLOCK_REALTIME, &time); //獲取相對於1970到現在的秒數
localtime_r(&time.tv_sec, &nowtime);
diag_printf("%04d%02d%02d%02d:%02d:%02d\n", nowtime.tm_year + 1900,
nowtime.tm_mon + 1, nowtime.tm_mday,
nowtime.tm_hour, nowtime.tm_min, nowtime.tm_sec);
}
5 Taglist
5.1 Download taglist.vim from Internet
需要註冊賬號
5.2 Install
5.2.1 ~/.vimrc Setting
Copy the following comment to ~/.vimrc
以下的"(左雙引號)後面的表示註釋
例如:" show Tlist always
" show Tlist always
let Tlist_Show_One_File=1
let Tlist_Exit_OnlyWindow=1
let Tlist_Auto_Open=1
let Tlist_WinWidth=30
5.2.2 taglist.vim
mkdir ~/.vim/plugin
cp taglist.vim ~/.vim/plugin
5.2.3 taglist快捷鍵
跳到左邊函數list窗口:ctrl + 按2次w鍵
跳到右邊源碼窗口:選擇函數,按回車鍵
當左邊函數list窗口被關閉時,可以在vim中用如下命令打開:“:TlistOpen”
需要關閉左邊函數list窗口時,可以在vim中用如下命令關閉:“:TlistClose”
或者使用 ” ctrl + 按2次w鍵“ 跳轉到左邊窗口,然後輸入如下命令:“:q”
5.3 Show the Whitespace
Copy the following comment to ~/.vimrc
以下的"(左雙引號)後面的表示註釋
例如:" whitespace
" whitespace
highlight whitespaceEOF ctermbg=red guibg=red
match whitespaceEOF /\s\+$/
vim看代碼詳細配置,請參考另一篇博文《Cscope How-to》
MT7628K eCos開發入門
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.