1 Star 0 Fork 21

Socko.Li/raw-os

forked from jorya_txj/raw-os 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
raw_sched.c 6.06 KB
一键复制 编辑 原始数据 按行查看 历史
jorya_txj 提交于 2016-06-09 23:11 +08:00 . adjust raw_os_init_hook position
/*
raw os - Copyright (C) Lingjun Chen(jorya_txj).
This file is part of raw os.
raw os is free software; you can redistribute it it under the terms of the
GNU General Public License as published by the Free Software Foundation;
either version 3 of the License, or (at your option) any later version.
raw os is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. if not, write email to jorya.txj@gmail.com
---
A special exception to the LGPL can be applied should you wish to distribute
a combined work that includes raw os, without being obliged to provide
the source code for any proprietary components. See the file exception.txt
for full details of how and when the exception can be applied.
*/
/* 2012-4 Created by jorya_txj
* xxxxxx please added here
*/
#include <raw_api.h>
void raw_sched(void)
{
RAW_SR_ALLOC();
USER_CPU_INT_DISABLE();
/*if it is in interrupt just return*/
if (raw_int_nesting > 0u) {
USER_CPU_INT_ENABLE();
return;
}
/*if system is locked just return*/
if (raw_sched_lock > 0u) {
USER_CPU_INT_ENABLE();
return;
}
get_ready_task(&raw_ready_queue);
/*if highest task is currently task, then no need to do switch and just return*/
if (high_ready_obj == raw_task_active) {
USER_CPU_INT_ENABLE();
return;
}
TRACE_TASK_SWITCH(raw_task_active, high_ready_obj);
CONTEXT_SWITCH();
USER_CPU_INT_ENABLE();
}
static void debug_head_list_init(void)
{
/*Init the task debug head list*/
list_init(&(raw_task_debug.task_head));
list_init(&(raw_task_debug.mutex_head));
#if (CONFIG_RAW_SEMAPHORE > 0)
/*Init the semaphore debug head list*/
list_init(&(raw_task_debug.sem_head));
#endif
#if (CONFIG_RAW_QUEUE > 0)
list_init(&(raw_task_debug.queue_head));
#endif
#if (CONFIG_RAW_QUEUE_SIZE > 0)
list_init(&(raw_task_debug.queue_size_head));
#endif
#if (CONFIG_RAW_EVENT > 0)
list_init(&(raw_task_debug.event_head));
#endif
#if (CONFIG_RAW_QUEUE_BUFFER > 0)
list_init(&(raw_task_debug.queue_buffer_head));
#endif
}
/*
************************************************************************************************************************
* Init raw os
*
* Description: This function is called to init raw os.
*
* Arguments :None
* -----
*
*
*
* Returns RAW_U16: RAW_SUCCESS.
*
* Note(s)
*
*
************************************************************************************************************************
*/
RAW_OS_ERROR raw_os_init(void)
{
#if (CONFIG_RAW_USER_HOOK > 0)
raw_os_init_hook();
#endif
TRACE_INIT();
raw_os_active = RAW_OS_STOPPED;
run_queue_init(&raw_ready_queue);
/*Init the tick heart system*/
tick_list_init();
debug_head_list_init();
/*Start the first idle task*/
raw_task_create(&raw_idle_obj, (RAW_U8 *)"idle_task", 0,
IDLE_PRIORITY, 0, idle_stack,
IDLE_STACK_SIZE, raw_idle_task, 1);
/*The timer module need mutex*/
#if (CONFIG_RAW_TIMER > 0)
raw_timer_init();
raw_mutex_create(&timer_mutex, (RAW_U8 *)"timer_mutex", RAW_MUTEX_INHERIT_POLICY, 0);
#endif
/*tick task to reduce interrupt time*/
#if (CONFIG_RAW_TICK_TASK > 0)
tick_task_start();
#endif
/*For statistic*/
#if (RAW_CONFIG_CPU_TASK > 0)
cpu_task_start();
#endif
return RAW_SUCCESS;
}
/*
************************************************************************************************************************
* Start raw os first task
*
* Description: This function is called to start raw os first task.
*
* Arguments :None
* -----
*
*
*
* Returns RAW_U16: RAW_SYSTEM_ERROR.
*
* Note(s) This function shoud not returned!
*
*
************************************************************************************************************************
*/
RAW_OS_ERROR raw_os_start(void)
{
if (raw_os_active == RAW_OS_STOPPED) {
get_ready_task(&raw_ready_queue);
/*done it here, so doesn't need do it in raw_start_first_task*/
raw_task_active = high_ready_obj;
raw_os_active = RAW_OS_RUNNING;
#if (CONFIG_RAW_USER_HOOK > 0)
raw_os_start_hook();
#endif
raw_start_first_task();
}
else {
return RAW_OS_RUNNING;
}
return RAW_SYSTEM_ERROR;
}
#if (CONFIG_SCHED_FIFO_RR > 0)
void calculate_time_slice(RAW_U8 task_prio)
{
RAW_TASK_OBJ *task_ptr;
LIST *head;
RAW_SR_ALLOC();
head = &raw_ready_queue.task_ready_list[task_prio];
RAW_CRITICAL_ENTER();
/*if ready list is empty then just return because nothing is to be caculated*/
if (is_list_empty(head)) {
RAW_CRITICAL_EXIT();
return;
}
/*Always look at the first task on the ready list*/
task_ptr = raw_list_entry(head->next, RAW_TASK_OBJ, task_list);
/*SCHED_FIFO does not has timeslice, just return*/
if (task_ptr->sched_way == SCHED_FIFO) {
RAW_CRITICAL_EXIT();
return;
}
/*there is only one task on this ready list, so do not need to caculate time slice*/
/*idle task must satisfy this condition*/
if (head->next->next == head) {
RAW_CRITICAL_EXIT();
return;
}
if (task_ptr->time_slice) {
task_ptr->time_slice--;
}
/*if current active task has time_slice, just return*/
if (task_ptr->time_slice) {
RAW_CRITICAL_EXIT();
return;
}
/*Move current active task to the end of ready list for the same priority*/
move_to_ready_list_end(&raw_ready_queue, task_ptr);
/*restore the task time slice*/
task_ptr->time_slice = task_ptr->time_total;
RAW_CRITICAL_EXIT();
}
#endif
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/lichao23/raw-os.git
git@gitee.com:lichao23/raw-os.git
lichao23
raw-os
raw-os
master

搜索帮助