1 Star 0 Fork 0

hanhai-modules/hrt-timer-server

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
main.c 3.48 KB
一键复制 编辑 原始数据 按行查看 历史
yanjin.wu 提交于 2024-07-26 17:28 . feat:timer open source #92189
/*
*Copyright (c) 2024 Black Sesame Technologies
*
*Licensed under the Apache License, Version 2.0 (the "License");
*you may not use this file except in compliance with the License.
*You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*Unless required by applicable law or agreed to in writing, software
*distributed under the License is distributed on an "AS IS" BASIS,
*WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*See the License for the specific language governing permissions and
*limitations under the License.
*/
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <unistd.h>
#include <pthread.h>
#include <sys/msg.h>
#include <sys/systemlog.h>
// #include <devctl.h>
#include <hw/timer_server.h>
#include <resmsg.h>
#include <irq.h>
#include <of.h>
#include <semaphore.h>
#include <listservice.h>
#include <sys/mman.h>
#include <hw/timer_server.h>
#include "include/timer_function.h"
timer_dev_t *dev;
void timer_message_handler(dispatch_context_t* ctp)
{
while(1)
{
int32_t dispatchRet= 0;
dispatchRet = dispatch_handler (ctp);
if (dispatchRet != 1)
{
printf("timer dispatch_handler failed\r\n");
}
}
}
int main(int argc, char *argv[])
{
pthread_t ptd1;
pthread_attr_t a;
int32_t dispatchRet;
int32_t resmgr_id = -1;
dev = (timer_dev_t *)malloc(sizeof(timer_dev_t));
timer_sem_init();
/* get opts */
bst_timer_getfuncs(&dev->funcs,sizeof(dev->funcs));
dev->node_name = argv[0];
dev->drv_info.pbase = strtol( argv[1], NULL, 16);
/* init first D list node */
dlist_init(drv_info_list);
/* creat default timer node */
for(int i=0; i<((sizeof(timer_node_map))/sizeof(timer_node_map_t));i++)
{
if (0 == strcmp(dev->node_name, (char *)timer_node_map[i].node_name))
{
strcpy(dev->name, timer_node_map[i].port_name);
dev->drv_info.channel = timer_node_map[i].channel;
dev->drv_info.intr_num = timer_node_map[i].irq;
break;
}
}
// dev->drv_info.mode = TIMERS_MODE_USER;
dev->dpp = dispatch_create();
(void)memset( &dev->resmgr_attr, 0, sizeof(dev->resmgr_attr));
dev->resmgr_attr.process_priority = 55;
dev->resmgr_attr.process_thread_num = 1;
dev->ioFunc.devctl = (void *)timer_server_io_devctl;
iofunc_func_init( _RESMGR_CONNECT_NFUNCS, &dev->connectFunc, _RESMGR_IO_NFUNCS, &dev->ioFunc);
/* set resource manager parameter*/
dispatchRet = 0;
dev->ctp = dispatch_context_alloc(dev->dpp);
/* establish a name in the pathname space */
resmgr_id = resmgr_attach( dev->dpp,
&dev->resmgr_attr,
dev->name,
_FTYPE_ANY,
0,
&dev->connectFunc,
&dev->ioFunc,
NULL);
dev->ctp->resmgr_context.id = resmgr_id;
Timer_attach(dev);
/* load dts message */
timer_dts_process(dev);
/* mmap vbase */
timer_mmap(dev);
dev->iid = InterruptAttach(dev->drv_info.intr_num, (void *)timer_intr_handler, dev, 0, 0);
dev->funcs.init(&dev->drv_info);
dev->funcs.timer_disable(&dev->drv_info);
pthread_attr_init(&a);
pthread_attr_setstacksize(&a, 4096*10);
struct sched_param s_param = {.sched_priority = 50 };
pthread_attr_setschedparam(&a, &s_param);
pthread_create(&ptd1, &a, (void *)timer_message_handler, dev->ctp);
pthread_detach(ptd1);
dm_startup(dev->name);
while(1)
{
usleep(100000);
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/hanhai-modules/hrt-timer-server.git
git@gitee.com:hanhai-modules/hrt-timer-server.git
hanhai-modules
hrt-timer-server
hrt-timer-server
release-open-source

搜索帮助