ANSI-C/cC++ Compiler for HC12 V-5.0.30 Build 6037, Feb 7 2006 1: // filename *************RxFifo.c******** 2: // Pointer implementation of the receive FIFO 3: // Jonathan W. Valvano 1/30/07 4: 5: // This example accompanies the books 6: // "Embedded Microcomputer Systems: Real Time Interfacing", 7: // Thompson, copyright (c) 2006, 8: // "Introduction to Embedded Microcomputer Systems: 9: // Motorola 6811 and 6812 Simulation", Brooks-Cole, copyright (c) 2002 10: 11: // Copyright 2007 by Jonathan W. Valvano, valvano@mail.utexas.edu 12: // You may use, edit, run or distribute this file 13: // as long as the above copyright notice remains 14: 15: #include "RxFifo.h" 16: /* Number of characters in the Fifo 17: the FIFO is full when it has FifoSize-1 characters */ 18: unsigned char static volatile *RxPutPt; /* Pointer of where to put next */ 19: unsigned char static volatile *RxGetPt; /* Pointer of where to get next */ 20: /* FIFO is empty if PutPt=GetPt */ 21: /* FIFO is full if PutPt+1=GetPt */ 22: unsigned char static RxFifo[RXFIFOSIZE]; /* The statically allocated fifo data */ 23: 24: /*-----------------------RxFifo_Init---------------------------- 25: Initialize fifo to be empty 26: Inputs: none 27: Outputs: none */ 28: void RxFifo_Init(void){ Function: RxFifo_Init Source : D:\EE345L\Solutions\Lab2g\Sources\RXFIFO.C Options : -Cc -D_HCS12 -D__NO_FLOAT__ -D_HCS12_SERIALMON -Env"GENPATH=D:\EE345L\Solutions\Lab2g;D:\EE345L\Solutions\Lab2g\bin;D:\EE345L\Solutions\Lab2g\prm;D:\EE345L\Solutions\Lab2g\cmd;D:\EE345L\Solutions\Lab2g\Sources;C:\Program Files\Freescale\CW for HC12 V4.5\lib\HC12c\lib;C:\Program Files\Freescale\CW for HC12 V4.5\lib\HC12c\src;C:\Program Files\Freescale\CW for HC12 V4.5\lib\HC12c\include" -Env"LIBPATH=C:\Program Files\Freescale\CW for HC12 V4.5\lib\HC12c\include" -EnvOBJPATH=D:\EE345L\Solutions\Lab2g\bin -EnvTEXTPATH=D:\EE345L\Solutions\Lab2g\bin -Lasm=%n.lst -Ms -ObjN=D:\EE345L\Solutions\Lab2g\Lab2g_Data\Monitor\ObjectCode\RXFIFO.C.o 0000 36 [2] PSHA 29: unsigned char SaveCCR; 30: asm tpa 0001 b720 [1] TPA 31: asm staa SaveCCR 0003 6a80 [2] STAA 0,SP 32: asm sei // make atomic 0005 1410 [1] SEI 33: RxPutPt=RxGetPt=&RxFifo[0]; // Empty when PutPt=GetPt 0007 180300000000 [5] MOVW #RxFifo,RxGetPt 000d fc0000 [3] LDD RxGetPt 0010 7c0000 [3] STD RxPutPt 34: asm ldaa SaveCCR 0013 a680 [3] LDAA 0,SP 35: asm tap // end critical section 0015 b702 [1] TAP 36: } 0017 32 [3] PULA 0018 3d [5] RTS 37: 38: /*-----------------------RxFifo_Put---------------------------- 39: Enter one character into the fifo 40: Inputs: 8-bit data 41: Outputs: true if data is properly saved, 42: false if data not saved because it was previously full*/ 43: int RxFifo_Put(unsigned char data){ Function: RxFifo_Put Source : D:\EE345L\Solutions\Lab2g\Sources\RXFIFO.C Options : -Cc -D_HCS12 -D__NO_FLOAT__ -D_HCS12_SERIALMON -Env"GENPATH=D:\EE345L\Solutions\Lab2g;D:\EE345L\Solutions\Lab2g\bin;D:\EE345L\Solutions\Lab2g\prm;D:\EE345L\Solutions\Lab2g\cmd;D:\EE345L\Solutions\Lab2g\Sources;C:\Program Files\Freescale\CW for HC12 V4.5\lib\HC12c\lib;C:\Program Files\Freescale\CW for HC12 V4.5\lib\HC12c\src;C:\Program Files\Freescale\CW for HC12 V4.5\lib\HC12c\include" -Env"LIBPATH=C:\Program Files\Freescale\CW for HC12 V4.5\lib\HC12c\include" -EnvOBJPATH=D:\EE345L\Solutions\Lab2g\bin -EnvTEXTPATH=D:\EE345L\Solutions\Lab2g\bin -Lasm=%n.lst -Ms -ObjN=D:\EE345L\Solutions\Lab2g\Lab2g_Data\Monitor\ObjectCode\RXFIFO.C.o 0000 3b [2] PSHD 44: unsigned char volatile *tempPt; 45: tempPt = RxPutPt; 46: *(tempPt) = data; // try to Put data into fifo 0001 fe0000 [3] LDX RxPutPt 0004 6b30 [2] STAB 1,X+ 47: tempPt++; 0006 6e80 [2] STX 0,SP 48: if(tempPt == &RxFifo[RXFIFOSIZE]){ // need to wrap? 0008 8e0000 [2] CPX #RxFifo:24 000b 2605 [3/1] BNE *+7 ;abs = 0012 49: tempPt = &RxFifo[0]; 000d cc0000 [2] LDD #RxFifo 0010 6c80 [2] STD 0,SP 50: } 51: if(tempPt == RxGetPt){ 0012 fc0000 [3] LDD RxGetPt 0015 ac80 [3] CPD 0,SP 0017 2603 [3/1] BNE *+5 ;abs = 001c 52: return(0); // Failed, fifo was previously full 0019 c7 [1] CLRB 001a 2007 [3] BRA *+9 ;abs = 0023 53: } 54: else{ 55: RxPutPt = tempPt; // Success, so update pointer 001c ec80 [3] LDD 0,SP 001e 7c0000 [3] STD RxPutPt 56: return(1); 0021 c601 [1] LDAB #1 0023 87 [1] CLRA 57: } 58: } 0024 30 [3] PULX 0025 3d [5] RTS 59: 60: /*-----------------------RxFifo_Get---------------------------- 61: Remove one character from the fifo 62: Inputs: pointer to place to return 8-bit data 63: Outputs: true if data is valid, 64: false if fifo was empty at the time of the call*/ 65: int RxFifo_Get(unsigned char *datapt){ Function: RxFifo_Get Source : D:\EE345L\Solutions\Lab2g\Sources\RXFIFO.C Options : -Cc -D_HCS12 -D__NO_FLOAT__ -D_HCS12_SERIALMON -Env"GENPATH=D:\EE345L\Solutions\Lab2g;D:\EE345L\Solutions\Lab2g\bin;D:\EE345L\Solutions\Lab2g\prm;D:\EE345L\Solutions\Lab2g\cmd;D:\EE345L\Solutions\Lab2g\Sources;C:\Program Files\Freescale\CW for HC12 V4.5\lib\HC12c\lib;C:\Program Files\Freescale\CW for HC12 V4.5\lib\HC12c\src;C:\Program Files\Freescale\CW for HC12 V4.5\lib\HC12c\include" -Env"LIBPATH=C:\Program Files\Freescale\CW for HC12 V4.5\lib\HC12c\include" -EnvOBJPATH=D:\EE345L\Solutions\Lab2g\bin -EnvTEXTPATH=D:\EE345L\Solutions\Lab2g\bin -Lasm=%n.lst -Ms -ObjN=D:\EE345L\Solutions\Lab2g\Lab2g_Data\Monitor\ObjectCode\RXFIFO.C.o 0000 3b [2] PSHD 66: if(RxPutPt == RxGetPt){ 0001 fc0000 [3] LDD RxPutPt 0004 bc0000 [3] CPD RxGetPt 0007 2603 [3/1] BNE *+5 ;abs = 000c 67: return(0); // Empty if PutPt=GetPt 0009 c7 [1] CLRB 000a 201c [3] BRA *+30 ;abs = 0028 68: } 69: else{ 70: *datapt = *(RxGetPt); // return by reference 000c ee80 [3] LDX 0,SP 000e e6fb0000 [6] LDAB [RxGetPt,PCR] 0012 6b00 [2] STAB 0,X 71: RxGetPt++; // removes data from fifo 0014 fe0000 [3] LDX RxGetPt 0017 08 [1] INX 0018 7e0000 [3] STX RxGetPt 72: if(RxGetPt == &RxFifo[RXFIFOSIZE]){ 001b 8e0000 [2] CPX #RxFifo:24 001e 2606 [3/1] BNE *+8 ;abs = 0026 73: RxGetPt = &RxFifo[0]; // wrap 0020 180300000000 [5] MOVW #RxFifo,RxGetPt 74: } 75: return(1); 0026 c601 [1] LDAB #1 0028 87 [1] CLRA 76: } 77: } 0029 30 [3] PULX 002a 3d [5] RTS 78: 79: /*-----------------------RxFifo_Status---------------------------- 80: Check the status of the fifo 81: Inputs: none 82: Outputs: true if there is any data in the fifo */ 83: int RxFifo_Status(void){ Function: RxFifo_Status Source : D:\EE345L\Solutions\Lab2g\Sources\RXFIFO.C Options : -Cc -D_HCS12 -D__NO_FLOAT__ -D_HCS12_SERIALMON -Env"GENPATH=D:\EE345L\Solutions\Lab2g;D:\EE345L\Solutions\Lab2g\bin;D:\EE345L\Solutions\Lab2g\prm;D:\EE345L\Solutions\Lab2g\cmd;D:\EE345L\Solutions\Lab2g\Sources;C:\Program Files\Freescale\CW for HC12 V4.5\lib\HC12c\lib;C:\Program Files\Freescale\CW for HC12 V4.5\lib\HC12c\src;C:\Program Files\Freescale\CW for HC12 V4.5\lib\HC12c\include" -Env"LIBPATH=C:\Program Files\Freescale\CW for HC12 V4.5\lib\HC12c\include" -EnvOBJPATH=D:\EE345L\Solutions\Lab2g\bin -EnvTEXTPATH=D:\EE345L\Solutions\Lab2g\bin -Lasm=%n.lst -Ms -ObjN=D:\EE345L\Solutions\Lab2g\Lab2g_Data\Monitor\ObjectCode\RXFIFO.C.o 84: return (RxPutPt != RxGetPt); 0000 fc0000 [3] LDD RxPutPt 0003 bc0000 [3] CPD RxGetPt 0006 2602 [3/1] BNE *+4 ;abs = 000a 0008 c7 [1] CLRB 0009 8f [2] SKIP2 000a c601 [1] LDAB #1 000c 87 [1] CLRA 85: } 000d 3d [5] RTS 86: