Download presentation
Presentation is loading. Please wait.
Published byEthelbert Campbell Modified over 9 years ago
1
KyungHee Univ. 2-0 Chapter 2 Design of Software Systems
2
KyungHee Univ. 2-1 2.7 Device Drivers 2.7.1 Basic Concept of Device Drivers I/O 를 직접 수행하는 Routine 으로 시스템 또는 이용자 프로그램에 의하여 Call 된다. 여기서는 간단한 Serial Port 를 제어하는 Device Driver 를 예로 하여 설명 한다. Device Driver 는 아래 예와 같은 Gate 기능을 수행하는 함수에 의하여 상위 레벨 Routine 과 연결 된다.
3
KyungHee Univ. 2-2 2.7.2 Design of a Serial Communications Interface (SCI) Device Drivers 1.Data structures: global (Private) Private global data structures Private 의 의미는 오직 Driver 프로그램 내에서만 직접 Access 가능 Device Driver 의 이용자는 Driver 내의 Public function 을 통하여 Access 할 수 있다. 예 : OpenFlag, FIFO queue 2.Initialization routine (public, called by client once in the beginning)
4
KyungHee Univ. 2-3 2.7.2 Design of a Serial Communications Interface (SCI) Device Drivers 3.Regular I/O call (public, called by client to perform I/O) Device 의 I/O 기능을 수행하는 Public function 으로 Prototypes 은 Header File (SCI.H) 에 작성 된다. 이용자는 이 함수를 통하여 Device Driver 를 이용하게 된다. 이용자를 위한 Prototypes 과 Document 는 SCI.H File 에 개발자를 위한 기능 설명은 SCI.C File 에 포함 한다.
5
KyungHee Univ. 2-4 2.7.2 Design of a Serial Communications Interface (SCI) Device Drivers 3.Regular I/O call (public, called by client to perform I/O) 예
6
KyungHee Univ. 2-5 2.7.2 Design of a Serial Communications Interface (SCI) Device Drivers 3.Regular I/O call (public, called by client to perform I/O) 예
7
KyungHee Univ. 2-6 2.7.2 Design of a Serial Communications Interface (SCI) Device Drivers 4.Support software (private) Device Driver 기능 구현에 필요한 ( 도움이 되는 ) Private Function 과 Private Function : Private Function 의 Prototype 은 Header File 에 포함되지 않는다. 예 : Helper Function, Interrupt service routine 등
8
KyungHee Univ. 2-7 2.8 Object-Oriented Interfacing 2.8.1 Encapsulated Objects Using Standard C Encapsulation : 함수와 변수를 하나의 class 에 포함하도록함. #include "HC12.H" #include "LCD12.H" #include "COP12.H" #include "Timer.H" void main(void){ char letter; int n=0; COPinit(); // Enable TOF interrupt to make COP happy LCDinit(); TimerInit() LCDString("Adapt812 LCD"); TimerMsWait(1000); LCDclear(); letter='a'-1; while(1){ if (letter=='z') letter='a'; else letter++; LCDputchar(letter); TimerMsWait(250); if(++n==16){ n=0; LCDclear(); }}} #include "LCD12.C" #include "COP12.C" #include "Timer.C" #include "VECTORS.C" Program 2.19. Main program with three modules.
9
KyungHee Univ. 2-8 2.8 Object-Oriented Interfacing 2.8.1 Encapsulated Objects Using Standard C void TimerInit(void); void TimerMsWait(unsigned int time); Program 2.20 Timer.H header file has public functions. 이 Public function 함수를 포함하고 있는 File Name 을 표시함
10
KyungHee Univ. 2-9 2.8 Object-Oriented Interfacing 2.8.1 Encapsulated Objects Using Standard C unsigned int TimerClock; // private global, 이 파일 내에서만 access 됨 void TimerInit(void){ // public function TSCR |=0x80; // TEN(enable) TMSK2=0xA2; // TOI arm, TPU(pullup) timer/4 (500ns) TimerClock=2000; // 2000 counts per ms } void TimerWait(unsigned int time){ // private function TC5=TCNT+TimerClock; // 1.00ms wait TFLG1 = 0x20; // clear C5F while((TFLG1&0x20)==0){};} void TimerMsWait(unsigned int time){ // public function for(;time>0;time--) TimerWait(TimerClock); // 1.00ms wait } Program 2.20 Timer.C implementation file defines all functions.
11
KyungHee Univ. 2-10 2.8.3 Portability Using Standard C /* 6812 PortC bits 1,0 are input, Port B bits 1,0 are output */ #defineOutPort (*(unsigned char volatile *)(0x0001)) #defineOutDDR (*(unsigned char volatile *)(0x0003)) #defineInPort (*(unsigned char volatile *)(0x0004)) #defineInDDR (*(unsigned char volatile *)(0x0006)) /* rate is the number of cycles/100usec */ #define rate 800 const struct State{ unsigned char Out; /* Output values */ unsigned int Time; /* Time in 100 탎 ec to wait in this state */ const struct State *Next[4]; /* Next state if input=0,1,2,3 */ }; typedef const struct State StateType; #define SA &fsm[0] #define SB &fsm[1] #define SC &fsm[2] StateType fsm[3]={ {0x01,5*rate,{SB,SA,SB,SC}}, /* SA out=1, wait= 500usec, next states */ {0x02,10*rate,{SC,SA,SB,SC}}, /* SB out=2, wait=1000usec, next states */ {0x03,20*rate,{SA,SA,SB,SA}} /* SC out=3, wait=2000usec, next states */ }; Program 2.22 Enhanced C implementation of a Mealy Finite State Machine. 변경 될 수 있는 Parameters 인 경우 #define macros 를 이용하여 정의 하면 Portability 를 증가 시킨다.
12
KyungHee Univ. 2-11 2.8.3 Portability Using Standard C void Wait(unsigned int delay){ int Endt; Endt=TCNT+delay; /* Time (125ns cycles) to wait */ while((Endt-(int)TCNT)>0); /* wait */ }; void main(void){ StateType *Pt; unsigned char Input; Pt=SA; /* Initial State */ OutDDR=0xFF; /* Make Output port outputs */ InDDR=0x00; /* Make Input port inputs */ TSCR=0x80; /* Enable TCNT, default rate 8 MHz */ while(1){ OutPort=Pt->Out; Wait(Pt->Time); /* Time to wait in this state */ Input=InPort&0x03; /* Input=0,1,2,or 3 */ Pt=Pt->Next[Input]; } }; Program 2.22 Enhanced C implementation of a Mealy Finite State Machine.
13
KyungHee Univ. 2-12 2.9 Thread Thread 와 Process 의 차이 Thread I/O Device 와 Global variables 를 공유함. Interrupt service routine 은 Background thread 이다. FIFO 는 Thread 사이의 Communication 에 이용될 수 있다. FIFO 을 이용한 Key Input Thread 와 Printing Thread 사이의 Communication Process I/O Device 와 Global variables 를 공유하지 않음. 서로 독립된 목표를 갖는다.
14
KyungHee Univ. 2-13 2.9 Thread 2.9.1 Single-Threaded Execution Thread 컴퓨터 프로그램 수행 시 프로세스 내부에 존재하는 수행 경로, 즉 일련의 실행 코드 Foreground Thread Embedded system 에서는 많은 경우 무한 Loop 를 포함함.
15
KyungHee Univ. 2-14 2.9 Thread 2.9.2 Multithreading and Reentrancy 두개 이상의 Thread 에서 동시에 실행될 수 있는 Program Segment 는 Reentrant 한 Code 이다. Timmer INT 에 의 의하여 Background 에서 실행되는 INT Service Routine Key Stroke INT 에 의 의하여 Background 에서 실행되는 INT Service Routine
16
KyungHee Univ. 2-15 2.10 Recursion Recursive Program 자기 자신을 Call 할 수 있는 Program 이다. Recursive routine 은 Reentrant 한 코드 이다. Recursive algorithms 은 프로그램 메모리를 적게 필요로 하고 효과적인 프로그램을 작성하게 한다. 그러나 큰 Stack space 를 필요로 하고, 실행 속도가 느리다.
17
KyungHee Univ. 2-16 2.11 Debugging Strategies 2.11.1 Debugging Tools Logic Analyzer 직접 Address/Data Bus 에 접속 하여 실시간 실행 결과를 관찰 할 수 있다. 관찰을 시작하는 순간에 Trigger ( 동기 ) 방법을 이해하여야 한다. 원 프로그램에 포함 되어 있는 Debugging 정보를 볼 수 없기 때문에 프로그램 내용을 이해하기 어렵다. 내부 Cache, Multiple instruction queues, Branch prediction, Internal Bus 등 고급 기능의 관찰이 어렵다.
18
KyungHee Univ. 2-17 2.11 Debugging Strategies 2.11.1 Debugging Tools In-circuit emulator(ICE) Processor 를 제거하고 해당 소켓에 Emulator 케이블을 연결. ICE 는 보통 PC 와 연동하여 PC 의 자원 (Editor, 하드 디스크, 프린터 등을 이용하여 효과적으로 Debugging 한다.
19
KyungHee Univ. 2-18 2.11 Debugging Strategies 2.11.1 Debugging Tools In-circuit ROM emulator 대부분의 Software-based Debugger 는 Software trap( 6812 에서 swi 명령 ) 을 이용하여 Breakpoint 기능을 실현한다. 프로그램이 ROM 에서 실행 되는 경우 이 기능을 이용할 수 없기 때문에 ROM emulator 를 필요로 한다.
20
KyungHee Univ. 2-19 2.11 Debugging Strategies 2.11.3 Functional Debugging Functional Debugging 가능한 Input 에 대하여 Output 이 예상되는 결과와 일치하는지를 검증한다. 2.11.3.1 Single Stepping or Trace 2.11.3.2 Breakpoints without Filtering 2.11.3.3 Conditional Breakpoints Ex. If(count == 32) bkpt 2.11.3.4 Instrumentation : Print Statements
21
KyungHee Univ. 2-20 2.11 Debugging Strategies 2.11.3 Functional Debugging 2.11.3.5 Instrumentation : Dump into Array without Filtering 조건 없이 Buffer 에 여유가 있는 한 무조건 Dump 함
22
KyungHee Univ. 2-21 2.11 Debugging Strategies 2.11.3 Functional Debugging 2.11.3.6 Instrumentation : Dump into Array with Filtering 조건을 만족하는 경우에만 Dump 함 Buffer 에 여유가 있는 경우에만 Dump 함
23
KyungHee Univ. 2-22 2.11 Debugging Strategies 2.11.3 Functional Debugging 2.11.3.7 Monitor using Fast Displays Output Port 이용
24
KyungHee Univ. 2-23 2.11 Debugging Strategies 2.11.4 Performance Debugging System 의 Time Behavior 를 검증한다. System 이 Run 하고 있는 중, 예상 시간 내에 예상되는 I/O 가 얻어 지는 검증 한다. 2.11.4.1 Instrumentation Measuring with an Independent Counter : TCNT 16 Bit counter TCNT 를 이용하여 시간 정보를 측정한다.
25
KyungHee Univ. 2-24 2.11.4 Performance Debugging 2.11.4.1 Instrumentation Measuring with an Independent Counter : TCNT 2.11.4.2 Instrumentation Output Port 프로그램 실행 속도 측정을 위한 신호를 Output Port 에 출력하고 오실로스코프 등의 장비로 시간을 측정한다. 2.11.4.3 Measurement of Dynamic Efficiency 아래와 같은 3 가지 방법을 사용 할 수 있다. Assembly Listing 을 이용한 Bus cycles count 방법 Internal Timer(TCNT) 를 이용한 처리 시간 측정 방법 Output pin 에 신호를 출력하고 Oscilloscope 또는 Logic Analyzer 를 이용한 시간 측정 방법
26
KyungHee Univ. 2-25 2.11 Debugging Strategies 2.11.4 Performance Debugging 2.11.4.2 Instrumentation Output Port 프로그램 실행 속도 측정을 위한 신호를 Output Port 에 출력하고 오실로스코프 등의 장비로 시간을 측정한다. 예 : Loop jsr Set jsr Calculate ; function under test jsr Clr bra loop
27
KyungHee Univ. 2-26 2.11.4.3 Measurement of Dynamic Effiency Assembly Listing 을 이용한 Bus cycles count 방법
28
KyungHee Univ. 2-27 2.11 Debugging Strategies 2.11.4 Performance Debugging Internal Timer(TCNT) 를 이용한 처리 시간 측정 방법
29
KyungHee Univ. 2-28 2.11 Debugging Strategies 2.11.4 Performance Debugging Output pin 에 신호를 출력하고 Oscilloscope 또는 Logic Analyzer 를 이용한 시간 측정 방법
30
KyungHee Univ. 2-29 2.11.5 Profiling Profiling 은 관심을 갖는 사항에 대하여 Time history 정보를 수집하여 분석하는 디버깅 방법이다. 2.11.5.1 A Time/Position profile dumping into a data array 시간과 위치가 관심 사항 임
31
KyungHee Univ. 2-30 2.11.5 Profiling 2.11.5.2 Profiling Using an Output Port Output port 를 이용하여 Profile 을 관찰함.
32
KyungHee Univ. 2-31 2.11.5 Profiling 2.11.5.3 Thread Profile Multiple Threads 가 실행될 경우 각 Thread 를 Output port pin 에 할당하여 각 Thread 가 실행되는 동안 해당 Pin 에 1 를 출력하여 이 신호를 Multiple-channel scope 로 관측하여 각 Thread 의 실행 Profile 를 알 수 있다.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.