KyungHee Univ. 2-0 Chapter 2 Design of Software Systems
KyungHee Univ Device Drivers Basic Concept of Device Drivers I/O 를 직접 수행하는 Routine 으로 시스템 또는 이용자 프로그램에 의하여 Call 된다. 여기서는 간단한 Serial Port 를 제어하는 Device Driver 를 예로 하여 설명 한다. Device Driver 는 아래 예와 같은 Gate 기능을 수행하는 함수에 의하여 상위 레벨 Routine 과 연결 된다.
KyungHee Univ 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)
KyungHee Univ 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 에 포함 한다.
KyungHee Univ Design of a Serial Communications Interface (SCI) Device Drivers 3.Regular I/O call (public, called by client to perform I/O) 예
KyungHee Univ Design of a Serial Communications Interface (SCI) Device Drivers 3.Regular I/O call (public, called by client to perform I/O) 예
KyungHee Univ 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 등
KyungHee Univ Object-Oriented Interfacing 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 Main program with three modules.
KyungHee Univ Object-Oriented Interfacing 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 을 표시함
KyungHee Univ Object-Oriented Interfacing 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.
KyungHee Univ 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 를 증가 시킨다.
KyungHee Univ 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.
KyungHee Univ 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 를 공유하지 않음. 서로 독립된 목표를 갖는다.
KyungHee Univ Thread Single-Threaded Execution Thread 컴퓨터 프로그램 수행 시 프로세스 내부에 존재하는 수행 경로, 즉 일련의 실행 코드 Foreground Thread Embedded system 에서는 많은 경우 무한 Loop 를 포함함.
KyungHee Univ Thread Multithreading and Reentrancy 두개 이상의 Thread 에서 동시에 실행될 수 있는 Program Segment 는 Reentrant 한 Code 이다. Timmer INT 에 의 의하여 Background 에서 실행되는 INT Service Routine Key Stroke INT 에 의 의하여 Background 에서 실행되는 INT Service Routine
KyungHee Univ Recursion Recursive Program 자기 자신을 Call 할 수 있는 Program 이다. Recursive routine 은 Reentrant 한 코드 이다. Recursive algorithms 은 프로그램 메모리를 적게 필요로 하고 효과적인 프로그램을 작성하게 한다. 그러나 큰 Stack space 를 필요로 하고, 실행 속도가 느리다.
KyungHee Univ Debugging Strategies Debugging Tools Logic Analyzer 직접 Address/Data Bus 에 접속 하여 실시간 실행 결과를 관찰 할 수 있다. 관찰을 시작하는 순간에 Trigger ( 동기 ) 방법을 이해하여야 한다. 원 프로그램에 포함 되어 있는 Debugging 정보를 볼 수 없기 때문에 프로그램 내용을 이해하기 어렵다. 내부 Cache, Multiple instruction queues, Branch prediction, Internal Bus 등 고급 기능의 관찰이 어렵다.
KyungHee Univ Debugging Strategies Debugging Tools In-circuit emulator(ICE) Processor 를 제거하고 해당 소켓에 Emulator 케이블을 연결. ICE 는 보통 PC 와 연동하여 PC 의 자원 (Editor, 하드 디스크, 프린터 등을 이용하여 효과적으로 Debugging 한다.
KyungHee Univ Debugging Strategies Debugging Tools In-circuit ROM emulator 대부분의 Software-based Debugger 는 Software trap( 6812 에서 swi 명령 ) 을 이용하여 Breakpoint 기능을 실현한다. 프로그램이 ROM 에서 실행 되는 경우 이 기능을 이용할 수 없기 때문에 ROM emulator 를 필요로 한다.
KyungHee Univ Debugging Strategies Functional Debugging Functional Debugging 가능한 Input 에 대하여 Output 이 예상되는 결과와 일치하는지를 검증한다 Single Stepping or Trace Breakpoints without Filtering Conditional Breakpoints Ex. If(count == 32) bkpt Instrumentation : Print Statements
KyungHee Univ Debugging Strategies Functional Debugging Instrumentation : Dump into Array without Filtering 조건 없이 Buffer 에 여유가 있는 한 무조건 Dump 함
KyungHee Univ Debugging Strategies Functional Debugging Instrumentation : Dump into Array with Filtering 조건을 만족하는 경우에만 Dump 함 Buffer 에 여유가 있는 경우에만 Dump 함
KyungHee Univ Debugging Strategies Functional Debugging Monitor using Fast Displays Output Port 이용
KyungHee Univ Debugging Strategies Performance Debugging System 의 Time Behavior 를 검증한다. System 이 Run 하고 있는 중, 예상 시간 내에 예상되는 I/O 가 얻어 지는 검증 한다 Instrumentation Measuring with an Independent Counter : TCNT 16 Bit counter TCNT 를 이용하여 시간 정보를 측정한다.
KyungHee Univ Performance Debugging Instrumentation Measuring with an Independent Counter : TCNT Instrumentation Output Port 프로그램 실행 속도 측정을 위한 신호를 Output Port 에 출력하고 오실로스코프 등의 장비로 시간을 측정한다 Measurement of Dynamic Efficiency 아래와 같은 3 가지 방법을 사용 할 수 있다. Assembly Listing 을 이용한 Bus cycles count 방법 Internal Timer(TCNT) 를 이용한 처리 시간 측정 방법 Output pin 에 신호를 출력하고 Oscilloscope 또는 Logic Analyzer 를 이용한 시간 측정 방법
KyungHee Univ Debugging Strategies Performance Debugging Instrumentation Output Port 프로그램 실행 속도 측정을 위한 신호를 Output Port 에 출력하고 오실로스코프 등의 장비로 시간을 측정한다. 예 : Loop jsr Set jsr Calculate ; function under test jsr Clr bra loop
KyungHee Univ Measurement of Dynamic Effiency Assembly Listing 을 이용한 Bus cycles count 방법
KyungHee Univ Debugging Strategies Performance Debugging Internal Timer(TCNT) 를 이용한 처리 시간 측정 방법
KyungHee Univ Debugging Strategies Performance Debugging Output pin 에 신호를 출력하고 Oscilloscope 또는 Logic Analyzer 를 이용한 시간 측정 방법
KyungHee Univ Profiling Profiling 은 관심을 갖는 사항에 대하여 Time history 정보를 수집하여 분석하는 디버깅 방법이다 A Time/Position profile dumping into a data array 시간과 위치가 관심 사항 임
KyungHee Univ Profiling Profiling Using an Output Port Output port 를 이용하여 Profile 을 관찰함.
KyungHee Univ Profiling Thread Profile Multiple Threads 가 실행될 경우 각 Thread 를 Output port pin 에 할당하여 각 Thread 가 실행되는 동안 해당 Pin 에 1 를 출력하여 이 신호를 Multiple-channel scope 로 관측하여 각 Thread 의 실행 Profile 를 알 수 있다.