Beruflich Dokumente
Kultur Dokumente
Final Project
6/9/2013
Rebecca Chu
Phongsakorn Liewsrisuk
Wuyue Liu
Haiyu Shi
1
Table of Contents
INTRODUCTION ................................................................................................................................. 3
DESIGN SPECIFICATION.................................................................................................................. 3
Part 1 Main.......................................................................................................................................... 3
Part 2 Schedule .................................................................................................................................... 4
Part 3 Train Communication ................................................................................................................ 5
Part 4 Current Train ............................................................................................................................. 7
Part 5 Switch Control......................................................................................................................... 13
Part 6 Serial Communication ............................................................................................................. 13
Part 7 Passengers ............................................................................................................................... 14
Part 8 ENET ...................................................................................................................................... 16
Part 9 JavaScript for Display.............................................................................................................. 16
EXTRA CREDIT (3 extra credits)...................................................................................................... 17
Analog Converter .............................................................................................................................. 17
Enhanced Internet Interface ............................................................................................................... 18
Improved User Usability .................................................................................................................... 19
ERROR ANALYSIS: .......................................................................................................................... 19
CONTRIBUTION AND ESTIMATED HOURS................................................................................ 20
CONCLUSION.................................................................................................................................... 20
INTRODUCTION
The final project is a combination of the results from lab 4 and lab 5 which is also the
continuation of the train system we have been working on for the past quarter. Like the previous
labs, this project is still worked from IAR IDE development tool to build and debug the software
and then download on the targeted Stellaris board. The biggest change from our previous train
system is that we now manage the tasks from dynamic task queues to a real-time operating
system called FreeRTOS. In RTOS, tasks are now always continuously running unless
suspended or resumed by built in FreeRTOS functions. Unlike non-preemptive round robin task
schedule, tasks also now have priority to determine which tasks to run first. In addition to the
transition to RTOS, the train system also have several new features.
The new feature introduced in lab 4 is a new task, passenger that simulates passenger
load on the train through measurements from the function generator. This is achieved through
reading from the GPIO pins and measurements are to be displayed on the OLED display along
with all the information. In lab 5, we have a major change in the train system where we removed
the gridlock feature. However, our train system now supports up to two train, while one is
traversing the intersection, the other one that arrived later will have to wait for the first train to
finish traversing before it can cross the intersection. With this new feature, there are two new
accompanying function. If there is a second train, the train system will display the train wait
time. Also, there is an additional flag if the waiting time for the train exceeds the traversal time
of a train with train size of 6. The final project also now have a web-based interface in a browser
that display train information.
All the mandatory features of the final project are met. We also attempt to complete all
three of the extra credits. We were successful in completing the analog measurement where we
read voltage through GPIO pins. We also implemented enhanced internet interface where we not
only display train information, we also support commands that allow controls of the train system
such as starting or pausing the tasks, displaying or not displaying information, and refreshing the
page. Lastly, we attempt to create a more user-friendly web page as an improvement to the
overall train system.
DESIGN SPECIFICATION
Part 1 Main
The main file for this lab is build up on the freeRTOS structure, similar to our previous
projects, we initialized all the global variables and the interrupt function before the actually main
function. we included more global variables to store the information of the second train, also we
took away those global variables relate to gridlock. In freeRTOS, it has its own timer function,
so we got rid of our old hardware timer interrupt in the main, left only the push button and
frequency interrupt.
3
Inside of the main function, first we would call the ENET function which will set up the web
server for the board and then like previous labs we set up all the hardware we would be using in
this project. after hardware setup section, we need to create tasks. In freeRTOS, Task is created
in the following syntax:
xTaskCreate(passanger, "passanger", 100, NULL, 1, &passangersHandle);
the last 2 parameters are relatively more important in this project, the first one is the priority of
the task, we assigned our tasks priority as following:
passanger,1
SerialCom,2
CurrentTrain,3
SwitchControl,4
TrainCom,5
Schedule,6
The last parameter is the suspend/resume task handler which we will need in our
scheduler and web Server command, we just set up all handlers in the main so we can easily
suspend or resume tasks in other tasks.
Part 2 Schedule
In the schedule task, this is the task that contains the logic that determines each of the
function task (ie train com, current train, switch control, serial communication, and passenger).
The logic is similar to the previous versions train system, which instead of being allocated in
designated schedule task like the current version is, it was in main to determine which task to add
to the task queue. The schedule task is like the boss task running in FreeRTOS that tells the
operating system what task to suspend and what task to resume. Schedule task will keep running
and not get suspended. This schedule work as expected and does make the overall train system
behavior function as expected by determining what task to run and what not to run.
Pseudocode:
while (1){
increment global count
if (train 2 not present and one of the buttons pressed){
resume train task
}else {
suspend train task
}
if (train 1 present){
suspend passenger task
}else{
resume passenger task
}
if (train 1 not present){
suspend switch control task
}else {
resume switch control task
}
if (train 1 present){
resume current train
}else {
clear display for from direction information on OLED
suspend current train
}
display global count
ulvalue = value from ADC for voltage load
display ulvalue
if (train 1 present){
show moving on display
}else{
show train not present on display
}
}
Part 3 Train Communication
TrainCom is the function that creates a train. The logic in TrainCom for each train
information is basically same as the previous version. the train size and train to direction is still
determined by the random number generator. at same time, all of the four possible from direction
are determined by the push buttons. Pressing different push buttons will set variable to 1. We
assigned each push buttons to variables: State, State1, State2, and State3. When State is 1, the
train is coming from the North. When State1 is 1, the train is coming from South. When State2 is
1, the train is coming from West. When State3 is 1, the train is coming from East. The difference
here is we added a new Train. So we need to reconsider the condition. If there is no Train1, we
create Train1. If there is a train one, we want to create another Train2 and give it from direction
and to direction like what we did in for the train 1.
Pseudocode:
TrainCom
if there is no train in the intersection
Train1 present
trainSize1 = random integer between 2 to 9
direction1 = random integer between 0 to 3
if (direction1 is 0)
direction1 is west
else if (direction1 is 1)
direction1 is north
else if (direction1 is 2)
direction1 is east
else
direction1 is south
if (State is 1)
fromDirection1 is North
else if (State1 is 1)
fromDirection1 is South
else if (State2 is 1)
fromDirection1 is West
else if (State3 is 1)
fromDirection1 is East
set State, State1, State2, State3 all to zero
else if(train1 in the intersection)
set train2 present
trainSize = random integer between 2 to 9
direction = random integer between 0 to 3
if (direction2 is 0)
direction2 is west
else if (direction2 is 1)
direction2 is north
else if (direction2 is 3)
direction2 is east
else
direction2 is south
if (State is 1)
6
fromDirection2 is North
else if (State1 is 1)
fromDirection2 is South
else if (State2 is 1)
fromDirection2 is West
else if (State3 is 1)
fromDirection2 is East
set State, State1, State2, State3 all to zero
Part 4 Current Train
This function is almost same as the previous version the mainly difference for lab5 is we
need to show the information for not only the train1 but also the train 2. Sounds always depends
on the train1 because train1 is the only train moving. This function mainly provide the OLED
status display and speaker annunciation. When you push one button, then it will create a
correspond direction of train1. If there is train 1 already, the second push on the push buttons
signal will be set for the form direction of train 2. Patterns of annunciation and the OLED are
always same.
When the train goes to north east west and south Train. As similar as the project 2. We
need 2 long blast of 2 seconds followed by 3 short blasts of 1 second each and display flashing at
a 1.0 second rate.
Pseudocode
if (there is no train)
cleanDisplay();
stopsound();
if (there is train1 look at the to directiontrain1)
if train1 to south
give sound and display for to south
if train1 to west
give sound and display for to west
if train1 to east
give sound and display for to south
if train1 to north
give sound and display for to north
if(at this time train 1 and train 2 both at the intersection)
if train2 to south
give sound and display for T2tosouth
if train2 to west
give sound and display for T2towest
if train2 to east
NorthTrain
soundtime
displaytime
displaytime % 6
soundtime % 20
sound on / off
100
90
99
89
19
98
88
18
97
87
17
96
86
16
95
85
15
94
84
14
93
83
13
92
82
12
91
81
11
ns
90
80
10
89
79
88
78
87
77
86
76
85
75
84
74
83
73
82
72
81
71
ns
ns
ns
displaytime
displaytime % 8
soundtime%26
sound on / off
52
40
51
39
25
50
38
24
49
37
23
48
36
22
47
35
21
ns
46
34
20
45
33
19
44
32
18
43
31
17
42
30
16
41
29
15
40
28
14
39
27
13
38
26
12
37
25
11
36
24
10
35
23
34
22
33
21
32
20
31
19
30
18
29
17
28
16
27
15
10
ns
ns
ns
ns
To South:
We need 2 long blast of 2 seconds followed by 3 short blasts of 1 second each. and
display flashing at a 1.0 second rate.
int soundtime=localCounter-*(mycurrentTrainData->globalCount)+24-(traversalTime%24)+1;
displaytime=localCounter-*(mycurrentTrainData->globalCount)+4-(traversalTime%4)+1;
By having this equation, whenever there is a WestTrain first coming in, the soundtime % 24 will
counts by following this trends: 0 23 22 21
soundtime
display time
display time %4
soundtime%24
sound on / off
48
48
47
47
23
46
46
22
45
45
21
44
44
20
43
43
19
42
42
18
41
41
17
40
40
16
39
39
15
38
38
14
37
37
13
36
36
12
35
35
11
34
34
10
33
33
32
32
31
31
11
ns
ns
ns
30
30
29
29
28
28
27
27
26
26
25
25
ns
ns
To West:
WestTrain should consist of 1 long blasts of 2 seconds each followed by 2 short blast of 1
second each.
The entire functional behavior for sounds needs 14 time units. Display will change every 2 units
so we need 4 time units.
In our code, we use
soundtime=localCounter-*(myWest->globalCount)+14-(traversalTime%14)+1;
By having this equation, whenever there is a WestTrain first coming in, the soundtime % 14 will
counts by following this trends: 0 13 12 11
In this equation localCounter is given from the switch control, it aim to tell the WestTrain
function that the certain time point when the WestTrain is completely passed.
soundtime
display time
display time %4
soundtime%14
sound on / off
28
28
27
27
13
26
26
12
25
25
11
24
24
10
23
23
22
22
12
ns
21
21
20
20
19
19
18
18
17
17
16
16
15
15
ns
ns
13
Pseudocode:
while(1)
{
if(train1Present)
{
print out trainsize
print out trainTo
print out trainFrom
if (fromNorth2)
{
if(waitingTime>72)
print long wait time
}
print passangers
}else
print train not present
print global count
vTaskDelay(500);
}
Part 7 Passengers
The function generator input is being connected to the GPIO port A pin 0 with the square
wave of 1k - 2k HZ. The frequency of the digital signal are counted by the interrupt. Then, we
converted the these counts and interpreted them into the number of passengers.
(1kHz representing 0 passengers to 2kHz representing 300 passengers )
The method we used to measure is relatively simple, it only relates to the function
generator interrupt. In the main file, we set that once the interrupt occurs, our frequency counter
would increase by 1, also, we have another variable called pastFrequencyCounter, its used to
record the value of frequencyCounter 0.5s ago, so we can calculate the frequency based on the
difference these 2 variables. pastFrequencyCounter will be updated every time after the current
frequency is been calculated, and in trainCom, when the train is just been created.
14
Pseudocode:
while(1)
{
if passangerCheck is equal to zero
{
passangerCheck++
passangers=((frequencyCounter-pastFrequencyCounter)*2-1000)*3/10;
pastFrequencyCounter=frequencyCounter;
}
print passenger
vTaskDelay(500);
}
15
Part 8 ENET
In ENET function, we set up the Ethernet connection. In this part, we need to combine
the sample code of ENET with our freeRTOS. Before we combine them, we need to remove the
default Ethernet setup inside the freeRTOS, which include remove all the hardware setup in
order to make sure there will not have any confliction between the setup in ENET and set-up
inside freeRTOS.
We didnt change too much ENET sample code. We changed the name of main function
to ENET function, deleted OLED display in the ENET, in order to save enough space for train
information, and remove the while loop at the end of this function. Also, we combined the startewarm of previous project with start-ewarm of ENET.
After we combined the ENET with freeRTOS, we then move on to modify the lmi_fs.c
file, this file contains all the functions that connecting the OLED and web server, since we want
to display our own information on the website, so we need to add our own display functions in
this file. For the display functions in fs, we basically just assign ptFiles data to the information
we would to display, since ptFiles data is a char array, so in order to display number, we also
need to convert the number into char array, we did it exactly the same way as we did for the
global counter in previous lab. those display functions would be called in the javascript, so the
rest work of display information on the web site is in the Html code.
Overall all, combine ENET with freeRTOS and then add our own display functions in
lmi_fs are the 2 major steps we did on ENET.
Part 9 JavaScript for Display
For the internet interface, we need to display information about the train system on the
browser. Therefore, we need to write JavaScript functions in the html page to communicate with
the ENET c code in IAR in order to obtain values for each component. In the display page, we
need to show the two trains information that was shown on the OLED, such as train status, to
direction, from direction, train size. For train 2, there is also waiting time as well as long wait
flag. On top of these, there are also global count that shows incrementation in the application.
For each value that we need from the c code to the html page, we write a function in
JavaScript. The JavaScript functions we have are: global counter, passenger, wait time, train 1
status, size, to from direction and train 2 status, size to from direction. The functions will be
called (and displayed information on page will be updated) every time the page is refreshed. In
my html code, there is a table that organizes all these information for train 1 and train 2 to
display to the user. (The C code side of display is explained in the ENET section above)
16
17
18
19
Design: 8 hours
Coding: 10 hours
Test/debug: 15 hours
Documentation: 5 hours
CONCLUSION
Through this project, we learnt the concept of real-time scheduling, internet interface,
analog to digital converter and the integration of the overall system. With FreeRtos, all the tasks
are now preemptive with priority queue which can be set through suspend and resume. Also, new
features were added to the train system such as Passengers task, the web interface, Analog to
digital converter as well as the second train function. More GPIO pins and LAN cable were used
to connect with the external these new interfaces.
One of the biggest challenges that we faced was the integration of the FreeRTOS
environment with ENET. Many library files were missing, thus, giving definition error.
However, we managed to solve the problems with the TA and sampling code on the driver
library. Many steps were solved by try and error with logical reasoning and pattern.
In the end, with the combined team effort and dedicated team members we managed to
complete all the required tasks with all the extra credits.
20