📄 test.cpp
字号:
#include <iostream>
#include "common\common.h"
#include "intrmgr\event.h"
#include "intrmgr\evtmgr.h"
#include "core_event\core_event.h"
#include "sys_event\gpio\gpio.h"
static void Hello(const ID* pID)
{
cout << "Hello, world!" << endl;
remove_core_timer_event(*pID);
}
static ERR Initial(void *param)
{
cout << "The initial code is: " << (unsigned)param << endl;
return VALID_SUCCESS;
}
static ERR Ready(void *param)
{
cout << "The ready code is: " << (char*)param << endl;
return VALID_SUCCESS;
}
int main(void)
{
// Initialization
set_imask(IVG_ID(5) | IVG_ID(6) | IVG_ID(7) | IVG_ID(12) | IVG_ID(13) | IVG_ID(14));
init_interrupt_vector();
asm("raise 14;");
init_timer();
set_sys_mask(PORTFG_A_INT);
reg_sys_intrv(&sys_button_handler, POS_PORTFG_A_INT);
reg_event(MSG_PORTFG_A_INT, msg_button_event_handler);
init_gpio();
queue_init();
// test message
reg_event(0, &Initial);
reg_event(1, &Ready);
post_message(0, (void*)100);
post_message(1, (void*)"I'm ready!\n");
MSG_HANDLER my_handler;
void *param;
for(int i=0; i<2; i++)
{
ERR err;
if((err = receive_message(&my_handler, ¶m)) == VALID_SUCCESS)
(*my_handler)(param);
else
cout << "The error code occurred: " << err << endl;
}
unreg_event(0);
unreg_event(1);
if(add_core_timer_event(&Hello, 1) != -1)
{
add_core_timer_event(&Hello, 0);
start_core_timer();
}
// BEGIN_SAFE_REGION
int count = 0;
while(1)
{
asm("idle;");
if(count == 20)
stop_core_timer();
else
count++;
ERR result = execute_message();
if(result != VALID_SUCCESS)
cout << "There's something wrong! " << result << endl;
}
// END_REGION
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -