/** * Copyright (c) 2004, Freescale Semiconductor * Freescale Confidential Proprietary * * File name : SCI.c * Project name: SMAC (Simple Media Access Controller) * * Department : Freescale Radio Products Division * * Description : SCI module functions. * * $Author: b06623 $ * $Date: 2008/01/17 16:35:32 $ * $Name: $ */ #include #include "derivative.h" #include "SCI.h" UINT8 gu8SCIData[128] ; UINT8 gu8SCIDataFlag; void SCIInit(void) { SCIBDH = 0x00; SCIBDL = BAUD_38400; SCIC2 = INIT_SCI2C2; } /************************************************************ Function: SCIInitGeneric arg types (u16, u16, u8) Function initializing the SCI to the requested baud rate based on the supplied busclock in kilohertz on the com port that is selected ************************************************************/ void SCIInitGeneric(UINT32 u32BusClock, UINT32 u32BaudRate, UINT8 u8ComNumber) { UINT16 u16Sbr = 0; u16Sbr = (UINT16) ((u32BusClock) / (u32BaudRate * 16)); switch (u8ComNumber) { case 1: SCI1BDL = (UINT8) u16Sbr; u16Sbr = u16Sbr >> 8; SCI1BDH = (UINT8) u16Sbr; SCI1C2 = INIT_SCI2C2; break; case 2: SCI2BDL = (UINT8) u16Sbr; u16Sbr = u16Sbr >> 8; SCI2BDH = (UINT8) u16Sbr; SCI2C2 = INIT_SCI2C2; break; default: SCI1BDL = (UINT8) u16Sbr; u16Sbr = u16Sbr >> 8; SCI1BDH = (UINT8) u16Sbr; SCI1C2 = INIT_SCI2C2; break; } } interrupt void Vscirx() { UINT8 u8status, u8dummy; /* ensure Rx data buffer is full */ do { u8status = SCIS1; } while ((u8status & 0x20) == 0); /* Check for Errors (Framing, Noise, Parity) */ if ((u8status & 0x07) != 0) { u8dummy = SCID; return; } /* Good Data. */ gu8SCIData[0] = SCID; /* load SCI register to data */ gu8SCIData[1] = 0; gu8SCIDataFlag = 1; } void SCITransmitArray(UINT8 *pStr, UINT8 length) { UINT8 i; for (i=0; i> 4; if (hi_nibble <= 9) { SCIStartTransmit(hi_nibble + 0x30); } else { SCIStartTransmit(hi_nibble + 0x37); } if (low_nibble <= 9) { SCIStartTransmit(low_nibble + 0x30); } else { SCIStartTransmit(low_nibble + 0x37); } } }