实时操作系统Nuttx学习笔记(手册学习部分)

前言:由于目前nuttx有关的书籍太少,仅有的参考的资料就只有他的一个操作手册和官网,所以自学就以这两个为参考


一。手册的概述

手册分为三个部分:

1.总体的介绍部分
2.操作系统的接口
3.操作系统的数据结构


二。Task Control Interfaces具体的函数

1.task_create:

Function Prototype:

#include <sched.h>
int task_create(char *name, int priority, int stack_size, main_t entry,
const char *argv[]);

Description: This function creates and activates a new task with
a specified priority and returns its system-assigned ID.


2.task_init:

Function Prototype:

#include <sched.h>
int task_init(_TCB *tcb, char *name, int priority, uint32_t *stack,
uint32_t stack_size,
maint_t entry, const char *argv[]);

Description:
This function initializes a Task Control Block (TCB) in
preparation for starting a new thread. It performs a subset of
the functionality of task_create() (see above).
Unlike task_create(), task_init() does not activate the task.
This must be done by calling task_activate().


3.task_activate:

Function Prototype:

#include <sched.h>
int task_activate( _TCB *tcb );

Description:
This function activates tasks created by
task_init(). Without activation, a task is ineligible for
execution by the scheduler.


4.task_delete

Function Prototype:

#include <sched.h>
int task_delete( pid_t pid );

Description:

This function causes a specified task to cease to
exist – its stack and TCB will be deallocated. This function is
the companion to task_create().


5.exit:

Function Prototype:

#include <sched.h>
void exit( int code );
#include <nuttx/unistd.h>
void _exit( int code );

Description:
This function causes the calling task to cease to
exist – its stack and TCB will be deallocated. exit differs from_exit in that it flushes streams, closes file descriptors and will
execute any function registered with atexit().


6.task_restart:

Function Prototype:

#include <sched.h>
int task_restart( pid_t pid );

Description:
This function “restarts” a task. The task is first
terminated and then reinitialized with same ID, priority,original entry point, stack size, and parameters it had when it
was first started.


7.getpid

Function Prototype:

#include <unistd.h> pid_t getpid( void );

Description:
This function returns the task ID of the calling
task. The task ID will be invalid if called at the interrupt level.


三。Task Scheduling Interfaces具体函数

1.sched_setparam

Function Prototype:

#include <sched.h>
int sched_setparam(pid_t pid, const struct sched_param *param);

Description:

This function sets the priority of the task
specified by pid input parameter.


2.sched_getparam

Function Prototype:

#include <sched.h>
int sched_getparam (pid_t pid, struct sched_param *param);

Description:

This function gets the scheduling priority of the
task specified by pid.


3.sched_setscheduler:

Function Prototype:

#include <sched.h>
int sched_setscheduler (pid_t pid, int policy, const struct
sched_param *param);

Description:

sched_setscheduler() sets both the scheduling
policy and the priority for the task identified by pid. If pid
equals zero, the scheduler of the calling thread will be set. The
parameter ‘param’ holds the priority of the thread under the new
policy.


4.sched_getscheduler:

Function Prototype:

#include <sched.h>
int sched_getscheduler (pid_t pid);

Description:

sched_getscheduler() returns the scheduling policy currently applied to
the task identified by pid. If pid equals zero, the policy of the calling process will be
retrieved. * * Inputs: * * Return Value: This function returns the current scheduling
policy.


5.sched_yield

Function Prototype:

#include <sched.h>
int sched_yield( void );

Description:

This function forces the calling task to give up the CPU (only to other
tasks at the same priority).


6.sched_get_priority_max:

Function Prototype:

#include <sched.h>
int sched_get_priority_max (int policy)

Description:

This function returns the value of the highest possible task priority for a
specified scheduling policy.


7.sched_get_priority_min

Function Prototype:

#include <sched.h>
int sched_get_priority_min (int policy);

Description:

This function returns the value of the lowest possible task priority for a
specified scheduling policy.


8.sched_get_rr_interval

Function Prototype:

#include <sched.h>
int sched_get_rr_interval (pid_t pid, struct timespec *interval);

Description:

sched_rr_get_interval() writes the timeslice interval for task identified
by pid into the timespec structure pointed to by interval. If pid is zero, the timeslice
for the calling process is written into ‘interval. The identified process should be
running under the SCHED_RR scheduling policy.


四。Task Switching Interfaces具体函数

1.sched_lock

Function Prototype:

#include <sched.h>
int sched_lock( void );

Description:

This function disables context switching by Disabling addition of new
tasks to the ready-to-run task list. The task that calls this function will be the only task
that is allowed to run until it either calls sched_unlock (the appropriate number of
times) or until it blocks itself.


2.sched_unlock

Function Prototype:

#include <sched.h>
int sched_unlock( void );

Description:

This function decrements the preemption lock count. Typically this is
paired with sched_lock() and concludes a critical section of code. Preemption will not
be unlocked until sched_unlock() has been called as many times as sched_lock().When the lockCount is decremented to zero, any tasks that were eligible to preempt
the current task will execute.


3.sched_lockcount

Function Prototype:

#include <sched.h>
int32_t sched_lockcount( void )

Description:

This function returns the current value of the lockCount. If zero,
preemption is enabled; if non-zero, this value indicates the number of times that
sched_lock() has been called on this thread of execution.

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值