版本 66ce3d3af89fd9e9937acaaff9d5621341bfba0c
nuttx
組員
- 翁振育
- 黃亮穎
- 蘇偉嘉
- 李英碩
Nuttx 參考應用
PX4 autopilot<http://pixhawk.org/dev/nuttx/start>
_
NuttX 架構
* 可混用task跟thread。 * 支援FPU。 * 可混用FIFO跟RR。
與平台相關
Run Nuttx on STM32F429-Disco
Task state
.. code-block:: c
enum tstate_e { TSTATE_TASK_INVALID = 0, /* INVALID - The TCB is uninitialized / TSTATE_TASK_PENDING, / READY_TO_RUN - Pending preemption unlock / TSTATE_TASK_READYTORUN, / READY-TO-RUN - But not running / TSTATE_TASK_RUNNING, / READY_TO_RUN - And running / TSTATE_TASK_INACTIVE, / BLOCKED - Initialized but not yet activated / TSTATE_WAIT_SEM, / BLOCKED - Waiting for a semaphore / #ifndef CONFIG_DISABLE_SIGNALS TSTATE_WAIT_SIG, / BLOCKED - Waiting for a signal / #endif #ifndef CONFIG_DISABLE_MQUEUE TSTATE_WAIT_MQNOTEMPTY, / BLOCKED - Waiting for a MQ to become not empty. / TSTATE_WAIT_MQNOTFULL, / BLOCKED - Waiting for a MQ to become not full. / #endif #ifdef CONFIG_PAGING TSTATE_WAIT_PAGEFILL, / BLOCKED - Waiting for page fill / #endif NUM_TASK_STATES / Must be last */ };
Task list
.. code-block:: c
typedef struct tasklist_s tasklist_t;
extern volatile dq_queue_t g_readytorun; extern volatile dq_queue_t g_pendingtasks; extern volatile dq_queue_t g_waitingforsemaphore; #ifndef CONFIG_DISABLE_SIGNALS extern volatile dq_queue_t g_waitingforsignal; #endif #ifndef CONFIG_DISABLE_MQUEUE extern volatile dq_queue_t g_waitingformqnotempty; #endif #ifndef CONFIG_DISABLE_MQUEUE extern volatile dq_queue_t g_waitingformqnotfull; #endif #ifdef CONFIG_PAGING extern volatile dq_queue_t g_waitingforfill; #endif extern volatile dq_queue_t g_inactivetasks; extern volatile sq_queue_t g_delayed_kufree; #if defined(CONFIG_NUTTX_KERNEL) && defined(CONFIG_MM_KERNEL_HEAP) extern volatile sq_queue_t g_delayed_kfree; #endif extern volatile pid_t g_lastpid; extern pidhash_t g_pidhash[CONFIG_MAX_TASKS]; extern const tasklist_t g_tasklisttable[NUM_TASK_STATES];
TCB
.. code-block:: c
struct tcb_s { /* Fields used to support list management *************************************/ FAR struct tcb_s flink; / Doubly linked list / FAR struct tcb_s blink;
/* Task Management Fields *****************************************************/
pid_t pid; /* This is the ID of the thread */
start_t start; /* Thread start function / entry_t entry; / Entry Point into the thread / uint8_t sched_priority; / Current priority of the thread */
uint8_t task_state; /* Current state of the thread / uint16_t flags; / Misc. general status flags / int16_t lockcount; / 0=preemptable (not-locked) */
#if CONFIG_RR_INTERVAL > 0 int timeslice; /* RR timeslice interval remaining */ #endif
/* Stack-Related Fields *******************************************************/
#ifndef CONFIG_CUSTOM_STACK size_t adj_stack_size; /* Stack size after adjustment / / for hardware, processor, etc. / / (for debug purposes only) / FAR void stack_alloc_ptr; /* Pointer to allocated stack / / Need to deallocate stack / FAR void adj_stack_ptr; /* Adjusted stack_alloc_ptr for HW / / The initial stack pointer value */ #endif
/* POSIX Semaphore Control Fields *********************************************/
sem_t waitsem; / Semaphore ID waiting on */
/* POSIX Signal Control Fields ************************************************/
#ifndef CONFIG_DISABLE_SIGNALS sigset_t sigprocmask; /* Signals that are blocked / sigset_t sigwaitmask; / Waiting for pending signals / sq_queue_t sigactionq; / List of actions for signals / sq_queue_t sigpendactionq; / List of pending signal actions / sq_queue_t sigpostedq; / List of posted signals / siginfo_t sigunbinfo; / Signal info when task unblocked */ #endif
/* POSIX Named Message Queue Fields *******************************************/
#ifndef CONFIG_DISABLE_MQUEUE FAR msgq_t msgwaitq; / Waiting for this message queue */ #endif
/* The form and content of these fields are processor-specific. */
struct xcptcontext xcp; /* Interrupt register save area */
#if CONFIG_TASK_NAME_SIZE > 0 char name[CONFIG_TASK_NAME_SIZE]; /* Task name */ #endif : : : : : : };
Communication
Scheduling
Interrupt handler
測試環境架設
硬體驅動原理
UART<embedded/USART>
_- FPU (Floating Point Unit)
效能表現
參考資料
- https://github.com/deadbeefcafe/nuttx-stm32f4disc-bb
- http://bibliodigital.itcr.ac.cr/xmlui/bitstream/handle/2238/3051/FinalReport.pdf