Abstract: In the EPA communication protocol stack design, the memory management and the timer queue management is affects the agreement stack performance the important aspect. This article in view of the embedded system under the EPA network’s characteristic, proposed the classified chain type memory formation’s dynamic memory management method and the simple increasing Clock queue’s clock management model, the test result indicated that this design method can the effective enhancement EPA agreement stack stability and timeliness.
Key word: EPA; Embedded real time system; Memory management; Fixed time formation;
[Abstract] In the design of EPA stack, memory management and timer queue is the key aspects which impact the performance of stack. According to the characteristic of EPA networks under embedded systems, the method of classified chain memory management and simple increment timer queue models are issued. Which provides a resolve method for enhancing the stabilization and real-time performance of EPA stack.
[Key words] EPA, Embedded real time system, Memory management, Timer queue
1. Foreword
Under the national 863 plan’s continual trundle supports, Chongqing Posts and telecommunications University participation as the core unit formulates the national standards - “To use in the Commercial measurement And Control system’s EPA (Ethernet for plant automation) System structure And Correspondence Standard” (i.e. “the EPA standard”). As a result of the industry field apparatus’s special request, the agreement stack which moves in the EPA network must stabilize highly effective, this needs us to explore the good optimization unceasingly and to realize the method. This article in has analyzed in the EPA network characteristic foundation, realized the memory to the EPA communication protocol stack, the clock management and so on key technologies has conducted the research, and proposed corresponding realized the plan.
2. EPA network
Along with the Internet technology’s development and the popularization promotion, the Ethernet technology also obtained the rapid development, the Ethernet transmission speed enhancement and the exchange technology development, for solved the Ethernet correspondence non-definite problem to bring the hope, and caused Ethernet to apply comprehensively in the industrial control domain possibly becomes. At present EPA does one of for industry ethernet technology solutions, it mainly has the following several aspect characteristic:
2.1 Correspondence determinism and timeliness
Because the ethernet uses CSMA/CD (carrier interception multiple access/collision detection) the medium access control mechanism, therefore has the correspondence “the uncertainty” the characteristic, and becomes it to apply in the industrial data communication network chief obstacle. EPA applies the open networking which corresponds in the industry field apparatus, uses the partition system structure and the definite correspondence dispatch control policy, can meet the industry scene special need, has solved the ethernet correspondence uncertainty problem, has satisfied system’s timely request.
2.2 Stability and reliability
Ethernet enters the industrial control domain another subject matter is, it uses the connector, the concentrator, the switchboard and the electric cable and so on are for the commercial domain design, but has not aimed at the bad industry scene environment to design (for example redundancy direct-current power supply input, high temperature, low temperature, dustproof and so on), therefore the commercial network product cannot apply, in has compares the redundant reliable request in the bad industry scene environment. But EPA does to apply in the industry scene network standard, the stability and the reliability are also its essential characteristic.
3. In EPA agreement memory management
In the embedded system software design adopts the memory management plan has two kind of - static assignments and the dynamic allocation. Generally speaking, the embedded system always two kind of plan’s combinations, the pure static assignment generally only uses in does not count the cost to guarantee the strict timely situation, moreover the static assignment easy to cause the system to lose the flexibility. Considered the EPA agreement stack mainly applies in the industry network equipment, therefore we mainly select the dynamic memory management method in the EPA agreement stack design. The dynamic memory management mechanism in the embedded software design is a difficulty, is also the direct relation overall system performance key.
In the EPA agreement stack design, in view of the network part and the non-network part’s memory requirements, we divides into the overall system memory the text buffer and the general buffer two different regions. Does first from the system application fixed measure’s static memory for the text buffer and the general buffer, defines own memory allocation and the recycling algorithm in each memory area, through this kind of design, can guarantee that the network system will not use the system available memory, the application procedure will not use the network to use the memory completely, thus has realized the memory region isolation, also prevented the agreement stack to exhaust all system memory, enhanced system’s stability and the reliability.
3.1 text buffers
In the EPA agreement the user data transmits from the local embedded equipment to the long-distance equipment’s process, must pass through each agreement, to the news seal, seals and the copy operation is nearly inevitable. But usually uses will save with a section of continual memory area, transmits the data the procedure to have the flaw: For example works as when from strike lower level transmission data, the lower level agreement needs to carry on the seal to the data, but upper formation when applies for the memory will not consider the lower level the need. This will cause when the lower level protocol processing needs to apply for the memory and to carry on the memory copy, thus influence procedure efficiency. Moreover along with data cascade processing, its content possibly has additions and deletions, but the continual memory is very difficult to process such dynamic data additions and deletions. Therefore, must have one kind to be able to adapt the data dynamic additions and deletions, but presents the continuous in logic construction of data, satisfies each between the data transfer, but carries on the memory copy. Therefore the text memory management plan which adopts in the EPA agreement stack design must satisfy the following request: (1) suits the depositing different length the data. (2) operates conveniently lengthens the buffer. (3) reduces as far as possible to complete the data copy which these operations do.
The overall evaluation system efficiency and the EPA network message’s characteristic, in the EPA agreement stack design, each cushion block length which we design is fixed, the size take satisfies in the EPA network the majority text lengths as a standard, here we establish each cushion block the length are 128 bytes, is bigger than this length the text, uses the cushion chain which many cushion blocks form to satisfy.
The EPA_BUFFER type’s buffer is the text buffer, this structure including two indicators, two length territories, next the territory indicator direction next EPA_BUFFER cushion block, the pdata territory aims in EPA_BUFFER the data outset position, the tot_len territory including the entire data chain’s data length, the len territory contains in this cushion block the data length. The EPA_BUFFER entire structure’s size is decided in the processor architecture which the territory uses an indicator’s size and the possible smallest alignment size. Is having 32 indicators and 4 byte alignment architecture, the entire size is 16 bytes. A EPA_BUFFER chain, as shown in Figure 1:

Figure 1. EPA_BUFFER chain structure
Buffer operation function:
void buf_init (void);
epa_buf_t * buf_alloc (void);
epa_buf_t * buf_new (u16_t tot_len);
void buf_delete (epa_buf_t *buffer);
epa_buf_t * buf_adjust (epa_buf_t *buffer, s16_t flen, s16_t blen);
void buf_read (epa_buf_t *buffer, u8_t *pdata, u16_t *len);
void buf_write (epa_buf_t *buffer, u8_t *pdata, u16_t *len);
Uses this design method for the text buffer, can realize from the interrupt transmission, to the protocol processing, the user receive and so on the entire process, the data only needs one time the copy, reduced (has not needed to the data space demand to make data hard copy frequently), thus enhanced the EPA protocol processing timeliness.
3.2 general buffers
In the EPA agreement stack design, the general buffer management realizes is very simple, it assigns and recycles the neighbor the memory region, and adjusts already the memory block which assigns. It uses in the system the complete memory specific region, the EPA_MEM type buffer is the general buffer, mainly satisfies in the agreement stack the memory requirements which has nothing to do with the text.
In EPA_RAM, the memory management through lays aside one kind of small structure in each memory block peak which assigns is come up the tracing assignment memory, this structure (Figure 2) establishes in two indicator direction memory next and the preceding assignment block, but also some used symbol uses for to instruct that this memory block was assigned whether already. The use the suitable principle, through searches a use the memory block not to assign the memory first. When a memory block is released, used symbolized that supposes is 0, to prevent the fragment, the examination next and on memory block’s used symbolized, if they have not been used, several blocks merge a big use block.

Figure 2 EPA_RAM structure
4. In EPA agreement clock management
In the EPA agreement stack design, timer’s effective management especially important, specially realizes the aspect in the definite dispatch, can carry on the reasonable management to the timer often to become enhances the entire agreement stack real-time performance the bottleneck. The way is adopts advanced to timer’s organization and the management simple leaves the (FIFO) way the first chain form formation, this organization mode of administration will have next two questions: The formation was too fixed time long, finds possesses to timer’s time expenses accepts with difficulty; When the timer interrupt occurs must carry on the subtraction operation to all timer’s time long territory, this part of timely expenses are also very big. Moreover, in the industry scene’s embedded equipment, the peripheral device resources are relatively limited, to enable this agreement stack the widespread application in many kinds of hardware platforms, we use a hardware timer are the datum clocks, then has designed the simple increasing Clock queue in its foundation, satisfies the EPA system to the definite dispatch as well as the time synchronism request.
When the system, applies for a simple relative increasing Clock queue for each task allocation, in formation’s node fixed time according to fixed time the long arrangement order, when the length before, as shown in Figure 3, fixed time the node 1 time length is 5 ticks, fixed time the node 2 time lengths are 2ticks, fixed time the node 3 time lengths are 4ticks, when the formation, fixed time the node long value changes the relative preceding fixed time node the long differential value, namely relative when is long. When the clock interrupt occurs, only need carry on to the team head’s time long territory reduces 1 operation, to designation when the node also concentrates in formation’s front. In each formation may have many clock nodes. In logic Clock queue, each fixed time node’s construction of data as follows shows:
typedef void (* timer_fun) (void *arg);
struct timer_node {
struct timer_node *next; /* directional next fixed time node */
u32 time; /* fixed time time */
timer_fun hander; /* fixed time time after carries out function */
void *arg; /* fixed time time after carries out function parameter */
}
A Clock queue following chart shows:

Figure 3 EPA Clock queue
Logic Clock queue’s processing function includes:
void time_queue_init (void);
u8_t time_task_add (u32_t msec, time_fun hander, void *arg);
u8_t time_task_delete (time_fun hander, void *arg);
In the EPA agreement stack design, uses this kind of fixed time formation, can use a datum timer to be possible to be simple, effective the function which fixed time realizes the definite dispatch and the time synchronism needs.
5. conclusion
This agreement stack design uses standard C to carry on the development, and unified UCOS-II in the ARM platform to carry on the test, the test result had indicated: Uses the classified chain type memory management and the relative increasing Clock queue’s memory and the clock management EPA communication protocol stack course of communications is stable, the speed is quick.
Reference:
[1] the EPA national standards draft the work team. Uses in the commercial measurement and control system’s EPA system structure and correspondence standard [S]. Beijing: Chinese Standard Publishing house .2005.
[2] Qing Li and Carolyn Yao, embedded system’s real-time concept [M], Beijing: Aerospace publishing house, 2004.
[3] morning breeze. Embedded real-time multi-duty software development foundation [M]. Beijing: Tsinghua University publishing house. 2004.09
[4] EAN J.LABROSSE, Shao Beibei translates. µ C/OS-II - sound code public real-time embedded operating system. Chinese Electric power Publishing house, 2003.04
[5] Hu outline, Wang Lei. The far-end memory exchange’s design with realizes [J]. Micro computer information, 2006,10-3:21-23
[6] Jams Noble&Charles Weir. The memory is limited of software development [M]. Central China science and technology publishing house the system, 2003.03
[7] Andrew N.Sloss, Shen Jianhua translates. ARM embedded system development - software design and optimization. Beijing University of Aeronautics and Astronautics Publishing house, 2005.05.