Implementation of Embedded OS
-
Upload
lisandra-lambert -
Category
Documents
-
view
50 -
download
0
description
Transcript of Implementation of Embedded OS
Implementation of Embedded OS
Lab5 Real-time Programming on μC/OS-III
/132 Lab5
Goal Practice real-time programming on μC/OS-III.
2014/5/20
Source: http://micrium.com/page/home
/133 Lab5
Environment Host System
Windows XP Build System
VirtualBox + Ubuntu 8.04 Target System
PTK development board (STM32F207) Software
Reference codes You can download them from RSWiki IEOS Course
Software
2014/5/20
/134 Lab5
Scenario
2014/5/20
In sensor network, the main job of sensors is to transmit collected data to a server.
It is common to use multiple communication channels with different levels of priority between a sensor and the server. Monitoring data versus alarm events Control messages versus data traffic …
Sensor
Server
Message Channel (higher priority)
Data Channel (lower priority)
/135 Lab5
Problem
2014/5/20
In this lab, we would like to implement the following communication model.
PTK UbuntuRequest1
Response1
Request2
Response2
⁞Request100
Response100
20ms10ms
Message ChannelPTK Ubuntu
Packet1
Packet2
⁞
random (ms)
Data Channel
TCP SocketsSens
or(PTK)
Server(Ubuntu
)
Message Channel
Data Channel
/136 Lab5
Specification (1/8)
2014/5/20
Request Message Format REQ_TS_SEC: a four-byte unsigned integer
representing the time when the request is sent in seconds
REQ_TS_USEC: a four-byte unsigned integer representing the fractional part of the time when the request is sent in microseconds
Request Message
REQ_TS_SEC 4 bytesREQ_TS_USEC 4 bytes
/137 Lab5
Specification (2/8)
2014/5/20
Response Message Format RECV_TS_TICK: a four-byte unsigned integer
representing the arrival time of the request in ticks*
RECV_TS_CYCLE: a four-byte unsigned integer representing the arrival time of the request in cycles*
REP_TS_TICK: a four-byte unsigned integer representing the time when the response is sent in ticks
REP_TS_CYCLE: a four-byte unsigned integer representing the time when the response is sent in cycles
RECV_TS_TICK 4 bytes
Response Message
RECV_TS_CYCLE 4 bytes
REP_TS_TICK 4 bytes
REP_TS_CYCLE 4 bytes
*Please refer to P.11 for how to obtain these values.
/138 Lab5
Specification (3/8)
2014/5/20
Data Packet Format LEN: a two-byte unsigned short integer
representing the length of data payload The value of LEN should range from 1 to 4095.
DATA[0..LEN-1]: data payload of LEN bytes You should fill DATA with the values [0, 255] in
sequence and wrapping around when LEN is larger than 255.
The data length and transmission interval are generated randomly by the algorithm shown on the next page.
Data Packet
LEN 2 bytes
DATA LEN bytes
/139 Lab5
Specification (4/8)
2014/5/20
Random Number Generator Please use the following C codes to generate
random numbers. Use (my_rand(0) % PACKET_SIZE) to generate
random numbers for LEN, PACKET_SIZE <= 4096.
Use (my_rand(1) % TRANS_INT) to generate random numbers for transmission interval, TRANS_INT = 20.
unsigned int my_seed[2] = {0x1234, 0x5678};
unsigned int my_rand(int idx){ my_seed[idx] = ((my_seed[idx] * 1103515245) + 12345) & 0x7fffffff;
return my_seed[idx];}
/1310 Lab5
Specification (5/8)
2014/5/20
Timing You need to measure the time of the following events for
all messages and data. In μC/OS-III
Receiving time of each message request Sending time of each message response
In Linux Sending time of each message request Receiving time of each message response Start time of each incoming data transmission Finish time of each data transmission
All measurement should be done right before the socket function send or after the socket function read.
You should stop the measurement as soon as the last response is processed.
/1311 Lab5
Specification (6/8)
2014/5/20
Timing Functions In μC/OS-III, you should use OSTimeGet to obtain
the current value of the tick counter, and use OS_TS_GET to obtain the current value of the CPU cycle counter.
In Linux, you should use gettimeofday for all timing.
/1312 Lab5
Specification (7/8)
2014/5/20
Program Input N, PACKET_SIZE,TRANS_INT
Program Output In Linux, for each pair of request/response
messages, output a comma-separated list per line as follows. MSG_NO, REQ_TS_SEC, REQ_TS_USEC,
RECV_TS_TICK, RECV_TS_CYCLE, REP_TS_TICK, REP_TS_CYCLE, REP_RECV_TS_SEC, REP_RECV_TS_USEC
MSG_NO is the message number from 1 to N. REP_RECV_TS_SEC/REP_RECV_TS_USEC is the time
when the response is received in Linux. Others are specified in the message formats.
/1313 Lab5
Specification (8/8)
2014/5/20
Program Output (cont’d) After the process receives N messages, output the statistics as
follows. REQ_INT_AVG, REQ_INT_VAR, REP_INT_AVG, REP_INT_VAR,
DATA_RECV_SUM, DATA_RECV_INT_SUM, MESG_TRANS_INT_MAX
REQ_INT_AVG and REP_INT_AVG are the averages of time interval between two consecutive request and response in microseconds.
REQ_INT_VAR and REP_INT_VAR are the variance of time interval between two consecutive request and response, where the variance is calculated as .
DATA_RECV_SUM is the total number of received data in bytes. DATA_RECV_INT_SUM is the sum of receiving time for all data
packets in microseconds, where the receiving time is calculated as (finished time – start time) of that data transmission.
MESG_TRANS_INT_MAX is the maximum time of sending or receiving a message, the difference of start time on each side in microseconds.