02.01.2015 Views

CooCox CoOS User's Guide

CooCox CoOS User's Guide

CooCox CoOS User's Guide

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

4 Memory Management<br />

4.1 Static Memory Allocation<br />

Static memory allocation applies to the condition that you know how much<br />

memory you need to occupy while compiling, and the static memory can’t be<br />

released or redistributed while system running. Compared with the dynamic<br />

memory allocation, static memory allocation does not need to consume CPU<br />

resources. At the same time, it would not lead to allocate unsuccessfully<br />

(because allocating unsuccessfully will directly result in the failure of the<br />

compiler). Therefore it is faster and more secure.<br />

In <strong>CooCox</strong> <strong>CoOS</strong>, the memory that each module’s control block needs is<br />

allocated statically, such as the task control block(TCB),event control<br />

block(ECB) ,flag control block(FCB),flag node(FLAG_NODE)and so on.<br />

Code 1 <strong>CooCox</strong> <strong>CoOS</strong>’s space allocation of the TCB<br />

config.h<br />

#define CFG_MAX_USER_TASKS (8) // Determine the largest number of<br />

// user’s task in the system<br />

task.h<br />

#define SYS_TASK_NUM (1) // Determine the number of system tasks<br />

task.c<br />

// Allocate TCB space statically<br />

OSTCB TCBTbl[CFG_MAX_USER_TASKS+SYS_TASK_NUM];<br />

25

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!