You are on page 1of 51

Design Examples and Case Studies of

Program Modeling and Programming with


RTOS-1:

Lesson-1
CASE STUDY OF EMBEDDED SYSTEM
DESIGN AND CODING FOR AN
AUTOMATIC CHOCOLATE VENDING
MACHINE (AVCM) USING µC/OS-II
RTOS

Chapter-11 L01: "Embedded Systems - Architecture,


2008 Programming and Design" , Raj Kamal, Publs.: McGraw-Hill, 1
Inc.
1. ACVM Specifications

Chapter-11 L01: "Embedded Systems - Architecture,


2008 Programming and Design" , Raj Kamal, Publs.: McGraw-Hill, 2
Inc.
Alphanumeric keypad and Display
λ Alphanumeric keypad on the top of
the machine.
λ A child interaction with it when
buying a chocolate.
λ Owner commands and interaction
with the machine.

Chapter-11 L01: "Embedded Systems - Architecture,


2008 Programming and Design" , Raj Kamal, Publs.: McGraw-Hill, 3
Inc.
Alphanumeric keypad and Display…
λ Three line LCD display unit on the
top of the machine.
λ Displays menus, entered text,
pictograms, and welcome, thank and
other messages, and time and date.
λ Child as well as the ACVM owner
GUIs with the machine using keypad
and display.

Chapter-11 L01: "Embedded Systems - Architecture,


2008 Programming and Design" , Raj Kamal, Publs.: McGraw-Hill, 4
Inc.
Coin insertion and delivery slots, and
Internet port
λ Coin insertion slot so that the child
can insert the coins to buy a
chocolate
λ Delivery slot to collect the chocolate,
and coins if refunded
λ Internet connection port so that
owner can interact with ACVM
from remote
Chapter-11 L01: "Embedded Systems - Architecture,
2008 Programming and Design" , Raj Kamal, Publs.: McGraw-Hill, 5
Inc.
Basic system in ACVM

Chapter-11 L01: "Embedded Systems - Architecture,


2008 Programming and Design" , Raj Kamal, Publs.: McGraw-Hill, 6
Inc.
Reprogram of the codes and relocation
of the codes
λ The system ROM or flash or
EPROM whenever the following
happens: (i) the price of chocolate
increases, (ii) the message lines or
menus or advertisement graphics
needs to be changed or (iii) machine
features change.

Chapter-11 L01: "Embedded Systems - Architecture,


2008 Programming and Design" , Raj Kamal, Publs.: McGraw-Hill, 7
Inc.
RTOS

λ An RTOS has to schedule the buying


tasks from start to finish.
λ Let µC/OS-II be the RTOS used in
ACVM

Chapter-11 L01: "Embedded Systems - Architecture,


2008 Programming and Design" , Raj Kamal, Publs.: McGraw-Hill, 8
Inc.
2. ACVM Requirements

Chapter-11 L01: "Embedded Systems - Architecture,


2008 Programming and Design" , Raj Kamal, Publs.: McGraw-Hill, 9
Inc.
Purpose

λ To sell chocolate through an ACVM


from which children can automatically
purchase the chocolates.
λ The payment is by inserting the coins
of appropriate amount into a coin-slot

Chapter-11 L01: "Embedded Systems - Architecture,


2008 Programming and Design" , Raj Kamal, Publs.: McGraw-Hill, 10
Inc.
Inputs

λ Coins of different denominations


through a coin slot
λ User commands

Chapter-11 L01: "Embedded Systems - Architecture,


2008 Programming and Design" , Raj Kamal, Publs.: McGraw-Hill, 11
Inc.
Signals, Events and Notifications
λ A mechanical system directs each coin to its
appropriate port− Port_1, Port_2 or Port_5.
λ Each port generates an interrupt on
receiving the coin at input.
λ Each port interrupt starts an ISR, which
increase value of amount collected by 1 or
2 or 5 and posts an IPC to a waiting task the
system
λ Each selected menu choice gives a
notification to the system
Chapter-11 L01: "Embedded Systems - Architecture,
2008 Programming and Design" , Raj Kamal, Publs.: McGraw-Hill, 12
Inc.
Outputs

λ Chocolate and signal (IPC) to the


system that subtracts the cost from the
value of amount collected
λ Display of the menus for GUIs, time
and date, advertisements, welcome and
thank messages

Chapter-11 L01: "Embedded Systems - Architecture,


2008 Programming and Design" , Raj Kamal, Publs.: McGraw-Hill, 13
Inc.
Input and Output Ports at the ACVM

Chapter-11 L01: "Embedded Systems - Architecture,


2008 Programming and Design" , Raj Kamal, Publs.: McGraw-Hill, 14
Inc.
Functions of the system
λ A child sends commands to the system
using a GUI (graphic user interface).
λ GUI consists of the LCD display and
keypad units.
λ The child inserts the coins for cost of
chocolate and the machine delivers the
chocolate.
λ If the coins are not inserted as per the cost
of chocolate in reasonable times then all
coins are refunded.
Chapter-11 L01: "Embedded Systems - Architecture,
2008 Programming and Design" , Raj Kamal, Publs.: McGraw-Hill, 15
Inc.
Functions of the system…

λ If the coins are inserted of amount


more than the cost of chocolate, the
excess amount is refunded along with
chocolate.
λ The coins for the chocolates purchased
collect inside the machine in a
collector channel, so that owner can
get the money, again through
appropriate commands using the GUI.
Chapter-11 L01: "Embedded Systems - Architecture,
2008 Programming and Design" , Raj Kamal, Publs.: McGraw-Hill, 16
Inc.
Functions of the system…

λ USB wireless modem enables


communication through Internet to the
ACVM owner

Chapter-11 L01: "Embedded Systems - Architecture,


2008 Programming and Design" , Raj Kamal, Publs.: McGraw-Hill, 17
Inc.
Design metrics
λ Power Dissipation: As required by
mechanical units, display units and
computer system
λ Performance: One chocolate in two
minutes and 256 chocolates before next
filling of chocolates into the machine.
[Assumed]
λ Process Deadlines: Machine waits for
maximum 30 s for the coins and machine
should deliver the chocolate within 60 s.
Chapter-11 L01: "Embedded Systems - Architecture,
2008 Programming and Design" , Raj Kamal, Publs.: McGraw-Hill, 18
Inc.
Design metrics…

λ User Interfaces: Graphic at LCD or touch


screen display on LCD and commands by
children or machine owner through
fingers on keypad or touch screen
λ Engineering Cost: US$ 50000 (assumed)
λ Manufacturing Cost: US$ 1000
(assumed)

Chapter-11 L01: "Embedded Systems - Architecture,


2008 Programming and Design" , Raj Kamal, Publs.: McGraw-Hill, 19
Inc.
Test and validation conditions

λ All user commands must function


correctly
λ All graphic displays and menus should
appear as per the program.
λ Each task should be tested with test
inputs
λ Tested for 60 users per hour
Chapter-11 L01: "Embedded Systems - Architecture,
2008 Programming and Design" , Raj Kamal, Publs.: McGraw-Hill, 20
Inc.
3. Specifications Modeling Using UML

Chapter-11 L01: "Embedded Systems - Architecture,


2008 Programming and Design" , Raj Kamal, Publs.: McGraw-Hill, 21
Inc.
Class diagram for ACVM Part-1

Chapter-11 L01: "Embedded Systems - Architecture,


2008 Programming and Design" , Raj Kamal, Publs.: McGraw-Hill, 22
Inc.
Class diagram for ACVM Part-2

Chapter-11 L01: "Embedded Systems - Architecture,


2008 Programming and Design" , Raj Kamal, Publs.: McGraw-Hill, 23
Inc.
4. Classes Display_Output
and User_Keypad_Input and Objects
task_Display and taskUser_KeypadInput

Chapter-11 L01: "Embedded Systems - Architecture,


2008 Programming and Design" , Raj Kamal, Publs.: McGraw-Hill, 24
Inc.
Classes Display_Output and User_Keypad_Input

Chapter-11 L01: "Embedded Systems - Architecture,


2008 Programming and Design" , Raj Kamal, Publs.: McGraw-Hill, 25
Inc.
Objects Task_Display and TaskUser_KeypadInput

Chapter-11 L01: "Embedded Systems - Architecture,


2008 Programming and Design" , Raj Kamal, Publs.: McGraw-Hill, 26
Inc.
5. State Diagram

Chapter-11 L01: "Embedded Systems - Architecture,


2008 Programming and Design" , Raj Kamal, Publs.: McGraw-Hill, 27
Inc.
State Diagram Part-1

Chapter-11 L01: "Embedded Systems - Architecture,


2008 Programming and Design" , Raj Kamal, Publs.: McGraw-Hill, 28
Inc.
State Diagram Part-2

Chapter-11 L01: "Embedded Systems - Architecture,


2008 Programming and Design" , Raj Kamal, Publs.: McGraw-Hill, 29
Inc.
6. Hardware Architecture

Chapter-11 L01: "Embedded Systems - Architecture,


2008 Programming and Design" , Raj Kamal, Publs.: McGraw-Hill, 30
Inc.
Block diagram of ACVM hardware
including Microcontroller

Chapter-11 L01: "Embedded Systems - Architecture,


2008 Programming and Design" , Raj Kamal, Publs.: McGraw-Hill, 31
Inc.
ACVM hardware

λ ACVM specific hardware to sort the


coins of different denomination and
each denomination
λ Main Power supply 220 V 50 Hz or
110 V 60 Hz. Internal circuits drive
by supply of 5 V 50mA for electronic
and 12 V 2 A for mechanical
systems.
Chapter-11 L01: "Embedded Systems - Architecture,
2008 Programming and Design" , Raj Kamal, Publs.: McGraw-Hill, 32
Inc.
ACVM hardware
λ A TCP/IP port
λ A 1 s resolution timer is obtained by
programming 8051 timer
λ Flash memory part of ROM and
RAM for storing temporary variables
and stack
λ 8 MB ROM for application codes
and RTOS codes
λ Microcontroller 8051MX
Chapter-11 L01: "Embedded Systems - Architecture,
2008 Programming and Design" , Raj Kamal, Publs.: McGraw-Hill, 33
Inc.
7. Software Architecture

Chapter-11 L01: "Embedded Systems - Architecture,


2008 Programming and Design" , Raj Kamal, Publs.: McGraw-Hill, 34
Inc.
Software architecture (ISRs and Tasks) for ACVM

Chapter-11 L01: "Embedded Systems - Architecture,


2008 Programming and Design" , Raj Kamal, Publs.: McGraw-Hill, 35
Inc.
8. Multiple tasks and their
synchronization model

Chapter-11 L01: "Embedded Systems - Architecture,


2008 Programming and Design" , Raj Kamal, Publs.: McGraw-Hill, 36
Inc.
Multiple tasks and their synchronization model using
semaphores and mailbox messages

Chapter-11 L01: "Embedded Systems - Architecture,


2008 Programming and Design" , Raj Kamal, Publs.: McGraw-Hill, 37
Inc.
9. Tasks and their priority, action and
IPCs

Chapter-11 L01: "Embedded Systems - Architecture,


2008 Programming and Design" , Raj Kamal, Publs.: McGraw-Hill, 38
Inc.
Task_ReadPorts

λ Priority ─ 9
λ Action─ Waits for the coins and action
as per coins collected
λ IPC pending: Event signal (s) from
Port_1, Port_2 and Port_5;
SemStimeout,
λ IPC posted: *MboxAmount
Chapter-11 L01: "Embedded Systems - Architecture,
2008 Programming and Design" , Raj Kamal, Publs.: McGraw-Hill, 39
Inc.
Task_Collect

λ Priority ─ 11
λ Action─ Waits for coins = or > cost till
timeout and act accordingly
λ IPC pending: SemFlag1;
*MboxAmount
λ IPC posted: SemFlag2, SemFlag3,
*MboxAmount, *Str1
Chapter-11 L01: "Embedded Systems - Architecture,
2008 Programming and Design" , Raj Kamal, Publs.: McGraw-Hill, 40
Inc.
Task_Deliver

λ Priority ─ 12
λ Action─ Waits for SemFlag2, delivers
chocolate, and decreases coins’ amount
after delivery
λ IPC pending: SemFlag2
λ IPC posted: SemFlag2, *Str2

Chapter-11 L01: "Embedded Systems - Architecture,


2008 Programming and Design" , Raj Kamal, Publs.: McGraw-Hill, 41
Inc.
Task_Refund

λ Priority ─ 17
λ Action─ Waits for refund event and
refunds the amount
λ IPC pending: SemFlag3
λ IPC posted: *Str3

Chapter-11 L01: "Embedded Systems - Architecture,


2008 Programming and Design" , Raj Kamal, Publs.: McGraw-Hill, 42
Inc.
Task_ExcessRefund

λ Priority ─ 13
λ Action─ Refunds the Excess excess
amount
λ IPC pending: SemFlag2,
*MboxAmount
λ IPC posted: *Str4

Chapter-11 L01: "Embedded Systems - Architecture,


2008 Programming and Design" , Raj Kamal, Publs.: McGraw-Hill, 43
Inc.
Task_Display

λ Priority ─ 15
λ Action─ Waits for the message mails
and display as per message
λ IPC pending: *collect, *delivered,
*refund, *excessRefund, Str2, Str3,
Str4 and *TimeDate
λ IPC posted: ─
Chapter-11 L01: "Embedded Systems - Architecture,
2008 Programming and Design" , Raj Kamal, Publs.: McGraw-Hill, 44
Inc.
10. Coding using µC/OS-II RTOS

Chapter-11 L01: "Embedded Systems - Architecture,


2008 Programming and Design" , Raj Kamal, Publs.: McGraw-Hill, 45
Inc.
Coding using µC/OS-II RTOS

• Refer Example 11.1 in Section 11.1.3


• At each step the explanation for the set
of statements given there.

Chapter-11 L01: "Embedded Systems - Architecture,


2008 Programming and Design" , Raj Kamal, Publs.: McGraw-Hill, 46
Inc.
Summary

Chapter-11 L01: "Embedded Systems - Architecture,


2008 Programming and Design" , Raj Kamal, Publs.: McGraw-Hill, 47
Inc.
We learnt
λ case study for the automatic chocolate
vending machine
λ specifications and requirements ,
λ Class diagrams, classes and objects
λ State diagram
λ Hardware and software architecture
λ Tasks synchronization model

Chapter-11 L01: "Embedded Systems - Architecture,


2008 Programming and Design" , Raj Kamal, Publs.: McGraw-Hill, 48
Inc.
We learnt
λ Tasks, ISRs and IPCs required for the
system
λ Task_ReadPorts
λ Task_Collect
λ Task_Deliver
λ Task_Refund
λ Task_ExcessRefund
λ Task_Display
Chapter-11 L01: "Embedded Systems - Architecture,
2008 Programming and Design" , Raj Kamal, Publs.: McGraw-Hill, 49
Inc.
We learnt
• Application of semaphores in
µC/OSII as event flag, resource key
and counter.
• Application of µC/OSII mailboxes
and system clock.
λ Coding using µC/OSII

Chapter-11 L01: "Embedded Systems - Architecture,


2008 Programming and Design" , Raj Kamal, Publs.: McGraw-Hill, 50
Inc.
End of Lesson-1 of chapter 11 on
CASE STUDY OF EMBEDDED
SYSTEM DESIGN, MODELING AND
CODING FOR AN ACVM

Chapter-11 L01: "Embedded Systems - Architecture,


2008 Programming and Design" , Raj Kamal, Publs.: McGraw-Hill, 51
Inc.

You might also like