UT EE 345M - Real Time Operating Systems Lecture 1.1

Unformatted text preview:

Real Time Operating Systems Lecture 1.1 by Jonathan W. Valvano Objectives • Parallel processing, distributed processing, multithreading • Modular programming • Call graphs, • Flow charts, • Data flow graphs, • Device drivers: serial port, • uVision4 compiler, • Quality software Open uart_echo Draw a call graph Draw a data flow graph Open UART2_4F120 Draw a call graph Draw a data flow graph Highlight the serial port input and output. A) How to do decimal input/output? 1) Write your own, like UART2 2) Use sprintf to create strings then output string 3) Link to Standard library function printf(), Your_putchar is your implementation that outputs one byte fputc _ttywrch are mapped to Your_putchar Standard library function getchar() Your_getchar is your implementation that input fgetc is mapped to Your_getchar Look at the style of ST7735_4F120Real Time Operating Systems Lecture 1.2 by Jonathan W. Valvano B) How much driverlib code do you use? driverlib code will have fewer bugs than any you or I write You will have to certify all code having no critical sections Most students will want to fit code into 32k All students must understand everything Why private versus public? Information hiding Reduce coupling Separate mechanisms from policy Essence of modular design How in C Public name has Module Name and underline Public object has Prototype in header file Private globals have static modifier Use call graphs to identify potential conflicts Module 7GPIOBModule 3 GPIOBChannel 3Channel 7 Flowcharts Block 1Sequence Conditional While-loopBlock 2Block 1 Block 2Block Figure 2.1. Flowchart showing the basic building blocks of structured programming.Real Time Operating Systems Lecture 1.3 by Jonathan W. Valvano ForkJoinTriggerinterruptReturn from interruptmain1Init1Body1main2Init2Body2mainInitBodyParallel Distributed Interrupt-driven concurrent Figure 2.2. Flowchart symbols to describe parallel, distributed, and concurrent programming. See FIFO_xxx.zip Reset tempPtFifo_PuttempPtwithin bufferbeyond buffertempPt = PutPtStore data at tempPttempPt++PutPt = tempPttempPt=GetPt!= GetPtreturn(1)return(0)fullReset GetPtFifo_GetGetPtwithin bufferbeyond bufferRetreive data at GetPtGetPt++GetPt=PutPt!= PutPtreturn(1)return(0)empty Figure 3.19. Flowcharts of the pointer implementation of the FIFO queue. // Two-index implementation of the FIFO // can hold 0 to FIFOSIZE elements #define FIFOSIZE 16 // must be a power of 2 #define FIFOSUCCESS 1 #define FIFOFAIL 0 typedef char dataType; unsigned long volatile PutI; // put next unsigned long volatile GetI; // get next dataType static Fifo[FIFOSIZE]; void Fifo_Init(void){ // this is critical // should make atomic PutI = GetI = 0; // Empty // end of critical section } // Two-pointer implementation of the FIFO // can hold 0 to FIFOSIZE-1 elements #define FIFOSIZE 16 // can be any size #define FIFOSUCCESS 1 #define FIFOFAIL 0 typedef char dataType; dataType volatile *PutPt; // put next dataType volatile *GetPt; // get next dataType static Fifo[FIFOSIZE]; void Fifo_Init(void){ // this is critical // should make atomic PutPt = GetPt = &Fifo[0]; // Empty // end of critical section }Real Time Operating Systems Lecture 1.4 by Jonathan W. Valvano // return FIFOSUCCESS if successful int Fifo_Put(dataType data){ if((PutI-GetI) & ~(FIFOSIZE-1)){ return(FIFOFAIL); // Failed, fifo full } Fifo[PutI&(FIFOSIZE-1)] = data; // put PutI++; // Success, update return(FIFOSUCCESS); } // return FIFOSUCCESS if successful int Fifo_Get(dataType *datapt){ if(PutI == GetI ){ return(FIFOFAIL); // Empty if PutI=GetI } *datapt = Fifo[GetI&(FIFOSIZE-1)]; GetI++; // Success, update return(FIFOSUCCESS); } // number of elements currently stored // 0 to FIFOSIZE-1 unsigned short Fifo_Size(void){ return ((unsigned short)(PutI-GetI)); } int Fifo_Put(dataType data){ dataType volatile *nextPutPt; nextPutPt = PutPt+1; if(nextPutPt ==&Fifo[FIFOSIZE]){ nextPutPt = &Fifo[0]; // wrap } if(nextPutPt == GetPt){ return(FIFOFAIL); // Failed, fifo full } else{ *(PutPt) = data; // Put PutPt = nextPutPt; // Success, update return(FIFOSUCCESS); } } int Fifo_Get(dataType *datapt){ if(PutPt == GetPt ){ return(FIFOFAIL);// Empty if PutPt=GetPt } else{ *datapt = *(GetPt++); if(GetPt==&Fifo[FIFOSIZE]){ GetPt = &Fifo[0]; // wrap } return(FIFOSUCCESS); } } Program 3.3. Two-pointer implementation of a FIFO. How do you make an object in C? Polymorphic Inheritance Encapulation #define AddFifo(NAME,SIZE,TYPE, SUCCESS,FAIL) \ unsigned long volatile PutI ## NAME; \ unsigned long volatile GetI ## NAME; \ TYPE static Fifo ## NAME [SIZE]; \ void NAME ## Fifo_Init(void){ \ PutI ## NAME= GetI ## NAME = 0; \ } \ int NAME ## Fifo_Put (TYPE data){ \ if(( PutI ## NAME - GetI ## NAME ) & ~(SIZE-1)){ \ return(FAIL); \ } \ Fifo ## NAME[ PutI ## NAME &(SIZE-1)] = data; \ PutI ## NAME ## ++; \ return(SUCCESS); \ } \ int NAME ## Fifo_Get (TYPE *datapt){ \ if( PutI ## NAME == GetI ## NAME ){ \ return(FAIL); \ } \Real Time Operating Systems Lecture 1.5 by Jonathan W. Valvano *datapt = Fifo ## NAME[ GetI ## NAME &(SIZE-1)]; \ GetI ## NAME ## ++; \ return(SUCCESS); \ } AddFifo(Tx,32,unsigned char, 1,0) Data Flow graphs RxFifo_GetTxFifo_PutRxFifoUARTinputRxFifo_PutRxISRInCharTxFifoUARToutputTxFifo_GetTxISROutCharmainProducerProducerConsumerConsumer Figure 3.3. A data flow graph showing two FIFOs that buffer data between producers and consumers. FIFO queues can be used to pass data between threads. Arm outputWrite datato outputDisarmoutputFullTxFifoNot emptyEmptyTxFifo_PutNot fullTxFifo_GetTxFifoRead datafrom inputERRORNot emptyEmptyInputRxFifo_GetRxFifo_PutNot fullFullRxFifoRxFifoInput ISROutputreturnOutput ISRreturn Volume 2 Figure 5.4. In a producer/consumer system, FIFO queues can be used to pass data between threads.Real Time Operating Systems Lecture 1.6 by Jonathan W. Valvano I/O bound input device InputdeviceMainprogrambusy done busyInterruptserviceroutineadonebcd abc daElements in FIFOempty 1 1empty empty Volume 2 Figure 5.6. Hardware/software timing of an I/O bound input interface. I/O bound output device (buffered I/O)


View Full Document

UT EE 345M - Real Time Operating Systems Lecture 1.1

Download Real Time Operating Systems Lecture 1.1
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Real Time Operating Systems Lecture 1.1 and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Real Time Operating Systems Lecture 1.1 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?