Embedded Sys- Auto Choco Machine

51
2008 Chapter-11 L01: "Embedded Systems - Architecture, Programming and Design" , Raj Kamal, Publs.: McGraw-Hill, Inc. 1 Design Examples and Case Studies of Design Examples and Case Studies of Program Modeling and Programming with Program Modeling and Programming with RTOS RTOS - - 1: 1: Lesson-1 CASE STUDY OF EMBEDDED SYSTEM DESIGN AND CODING FOR AN AUTOMATIC CHOCOLATE VENDING MACHINE (AVCM) USING µC/OS-II RTOS

Transcript of Embedded Sys- Auto Choco Machine

Page 1: Embedded Sys- Auto Choco Machine

2008Chapter-11 L01: "Embedded Systems - Architecture,

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

1

Design Examples and Case Studies of Design Examples and Case Studies of Program Modeling and Programming with Program Modeling and Programming with

RTOSRTOS--1:1:

Lesson-1 CASE STUDY OF EMBEDDED SYSTEM

DESIGN AND CODING FOR AN AUTOMATIC CHOCOLATE VENDING

MACHINE (AVCM) USING µC/OS-II RTOS

Page 2: Embedded Sys- Auto Choco Machine

2008Chapter-11 L01: "Embedded Systems - Architecture,

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

2

1. ACVM Specifications1. ACVM Specifications

Page 3: Embedded Sys- Auto Choco Machine

2008Chapter-11 L01: "Embedded Systems - Architecture,

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

3

Alphanumeric keypad and DisplayAlphanumeric 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.

Page 4: Embedded Sys- Auto Choco Machine

2008Chapter-11 L01: "Embedded Systems - Architecture,

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

4

Alphanumeric keypad and Display…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.

Page 5: Embedded Sys- Auto Choco Machine

2008Chapter-11 L01: "Embedded Systems - Architecture,

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

5

Coin insertion and delivery slots, and Coin insertion and delivery slots, and Internet portInternet 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

Page 6: Embedded Sys- Auto Choco Machine

2008Chapter-11 L01: "Embedded Systems - Architecture,

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

6

Basic system in ACVM

Page 7: Embedded Sys- Auto Choco Machine

2008Chapter-11 L01: "Embedded Systems - Architecture,

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

7

Reprogram of the codes and relocation Reprogram of the codes and relocation of the codesof 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.

Page 8: Embedded Sys- Auto Choco Machine

2008Chapter-11 L01: "Embedded Systems - Architecture,

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

8

RTOSRTOS

� An RTOS has to schedule the buying tasks from start to finish.

� Let µC/OS-II be the RTOS used in ACVM

Page 9: Embedded Sys- Auto Choco Machine

2008Chapter-11 L01: "Embedded Systems - Architecture,

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

9

2. ACVM Requirements2. ACVM Requirements

Page 10: Embedded Sys- Auto Choco Machine

2008Chapter-11 L01: "Embedded Systems - Architecture,

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

10

Purpose 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

Page 11: Embedded Sys- Auto Choco Machine

2008Chapter-11 L01: "Embedded Systems - Architecture,

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

11

Inputs Inputs

� Coins of different denominations through a coin slot

� User commands

Page 12: Embedded Sys- Auto Choco Machine

2008Chapter-11 L01: "Embedded Systems - Architecture,

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

12

Signals, Events and Notifications 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

Page 13: Embedded Sys- Auto Choco Machine

2008Chapter-11 L01: "Embedded Systems - Architecture,

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

13

Outputs 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

Page 14: Embedded Sys- Auto Choco Machine

2008Chapter-11 L01: "Embedded Systems - Architecture,

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

14

Input and Output Ports at the ACVM

Page 15: Embedded Sys- Auto Choco Machine

2008Chapter-11 L01: "Embedded Systems - Architecture,

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

15

Functions of the system 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.

Page 16: Embedded Sys- Auto Choco Machine

2008Chapter-11 L01: "Embedded Systems - Architecture,

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

16

Functions of the system… 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.

Page 17: Embedded Sys- Auto Choco Machine

2008Chapter-11 L01: "Embedded Systems - Architecture,

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

17

Functions of the system…Functions of the system…

� USB wireless modem enables communication through Internet to the ACVM owner

Page 18: Embedded Sys- Auto Choco Machine

2008Chapter-11 L01: "Embedded Systems - Architecture,

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

18

Design metrics 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.

Page 19: Embedded Sys- Auto Choco Machine

2008Chapter-11 L01: "Embedded Systems - Architecture,

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

19

Design metrics… 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)

Page 20: Embedded Sys- Auto Choco Machine

2008Chapter-11 L01: "Embedded Systems - Architecture,

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

20

Test and validation conditions 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

Page 21: Embedded Sys- Auto Choco Machine

2008Chapter-11 L01: "Embedded Systems - Architecture,

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

21

3. Specifications Modeling Using UML3. Specifications Modeling Using UML

Page 22: Embedded Sys- Auto Choco Machine

2008Chapter-11 L01: "Embedded Systems - Architecture,

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

22

Class diagram for ACVM Part-1

Page 23: Embedded Sys- Auto Choco Machine

2008Chapter-11 L01: "Embedded Systems - Architecture,

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

23

Class diagram for ACVM Part-2

Page 24: Embedded Sys- Auto Choco Machine

2008Chapter-11 L01: "Embedded Systems - Architecture,

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

24

4. Classes 4. Classes Display_OutputDisplay_Outputand and User_Keypad_InputUser_Keypad_Input and Objects and Objects

task_Displaytask_Display and and taskUser_KeypadInputtaskUser_KeypadInput

Page 25: Embedded Sys- Auto Choco Machine

2008Chapter-11 L01: "Embedded Systems - Architecture,

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

25

Classes Display_Output and User_Keypad_Input

:

Page 26: Embedded Sys- Auto Choco Machine

2008Chapter-11 L01: "Embedded Systems - Architecture,

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

26

Objects Task_Display and TaskUser_KeypadInput

Page 27: Embedded Sys- Auto Choco Machine

2008Chapter-11 L01: "Embedded Systems - Architecture,

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

27

5. State Diagram5. State Diagram

Page 28: Embedded Sys- Auto Choco Machine

2008Chapter-11 L01: "Embedded Systems - Architecture,

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

28

State Diagram Part-1

Page 29: Embedded Sys- Auto Choco Machine

2008Chapter-11 L01: "Embedded Systems - Architecture,

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

29

State Diagram Part-2

Page 30: Embedded Sys- Auto Choco Machine

2008Chapter-11 L01: "Embedded Systems - Architecture,

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

30

6. Hardware Architecture6. Hardware Architecture

Page 31: Embedded Sys- Auto Choco Machine

2008Chapter-11 L01: "Embedded Systems - Architecture,

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

31

Block diagram of ACVM hardware including Microcontroller

Page 32: Embedded Sys- Auto Choco Machine

2008Chapter-11 L01: "Embedded Systems - Architecture,

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

32

ACVM hardwareACVM 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.

Page 33: Embedded Sys- Auto Choco Machine

2008Chapter-11 L01: "Embedded Systems - Architecture,

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

33

ACVM hardwareACVM 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

Page 34: Embedded Sys- Auto Choco Machine

2008Chapter-11 L01: "Embedded Systems - Architecture,

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

34

7. Software Architecture7. Software Architecture

Page 35: Embedded Sys- Auto Choco Machine

2008Chapter-11 L01: "Embedded Systems - Architecture,

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

35

Software architecture (ISRs and Tasks) for ACVM

Page 36: Embedded Sys- Auto Choco Machine

2008Chapter-11 L01: "Embedded Systems - Architecture,

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

36

8. Multiple tasks and their 8. Multiple tasks and their synchronization modelsynchronization model

Page 37: Embedded Sys- Auto Choco Machine

2008Chapter-11 L01: "Embedded Systems - Architecture,

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

37

Multiple tasks and their synchronization model using Multiple tasks and their synchronization model using semaphores and mailbox messages semaphores and mailbox messages

Page 38: Embedded Sys- Auto Choco Machine

2008Chapter-11 L01: "Embedded Systems - Architecture,

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

38

9. Tasks and their priority, action and 9. Tasks and their priority, action and IPCsIPCs

Page 39: Embedded Sys- Auto Choco Machine

2008Chapter-11 L01: "Embedded Systems - Architecture,

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

39

Task_ReadPortsTask_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

Page 40: Embedded Sys- Auto Choco Machine

2008Chapter-11 L01: "Embedded Systems - Architecture,

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

40

Task_CollectTask_Collect

� Priority ─ 11� Action─Waits for coins = or > cost till

timeout and act accordingly � IPC pending: SemFlag1;

*MboxAmount� IPC posted: SemFlag2, SemFlag3,

*MboxAmount, *Str1

Page 41: Embedded Sys- Auto Choco Machine

2008Chapter-11 L01: "Embedded Systems - Architecture,

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

41

Task_DeliverTask_Deliver

� Priority ─ 12� Action─Waits for SemFlag2, delivers

chocolate, and decreases coins’ amount after delivery

� IPC pending: SemFlag2� IPC posted: SemFlag2, *Str2

Page 42: Embedded Sys- Auto Choco Machine

2008Chapter-11 L01: "Embedded Systems - Architecture,

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

42

Task_RefundTask_Refund

� Priority ─ 17� Action─Waits for refund event and

refunds the amount � IPC pending: SemFlag3� IPC posted: *Str3

Page 43: Embedded Sys- Auto Choco Machine

2008Chapter-11 L01: "Embedded Systems - Architecture,

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

43

Task_ExcessRefundTask_ExcessRefund

� Priority ─ 13� Action─ Refunds the Excess excess

amount � IPC pending: SemFlag2,

*MboxAmount� IPC posted: *Str4

Page 44: Embedded Sys- Auto Choco Machine

2008Chapter-11 L01: "Embedded Systems - Architecture,

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

44

Task_DisplayTask_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: ─

Page 45: Embedded Sys- Auto Choco Machine

2008Chapter-11 L01: "Embedded Systems - Architecture,

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

45

10. Coding using µC/OS-II RTOS

Page 46: Embedded Sys- Auto Choco Machine

2008Chapter-11 L01: "Embedded Systems - Architecture,

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

46

Coding using Coding using µµC/OSC/OS--II RTOSII RTOS

• Refer Example 11.1 in Section 11.1.3• At each step the explanation for the set of statements given there.

Page 47: Embedded Sys- Auto Choco Machine

2008Chapter-11 L01: "Embedded Systems - Architecture,

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

47

SummarySummary

Page 48: Embedded Sys- Auto Choco Machine

2008Chapter-11 L01: "Embedded Systems - Architecture,

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

48

We learntWe 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

Page 49: Embedded Sys- Auto Choco Machine

2008Chapter-11 L01: "Embedded Systems - Architecture,

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

49

We learntWe learnt� Tasks, ISRs and IPCs required for the

system� Task_ReadPorts� Task_Collect� Task_Deliver� Task_Refund� Task_ExcessRefund� Task_Display

Page 50: Embedded Sys- Auto Choco Machine

2008Chapter-11 L01: "Embedded Systems - Architecture,

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

50

We learntWe 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

Page 51: Embedded Sys- Auto Choco Machine

2008Chapter-11 L01: "Embedded Systems - Architecture,

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

51

End of Lesson-1 of chapter 11 onCASE STUDY OF EMBEDDED

SYSTEM DESIGN, MODELING AND CODING FOR AN ACVM