/*---------------------------------------------------------------------------* * Routine: LPC1768_Serial_Configure *---------------------------------------------------------------------------* * Description: * Link the serial port to a pair of callback routines and an * associated callback workspace. The callbacks are called when * a byte is received and when the transmit buffer becomes empty. * Inputs: * void *aWorkspace -- Serial port workspace * void *aCallbackWorkspace -- Callback's workspace * HAL_Serial_Callback_Received_Byte aReceivedByteCallback * -- Callback routine for received bytes * HAL_Serial_Callback_Transmit_Empty aTransmitEmptyCallback * -- Callback routine for transmit empty * Outputs: * T_uezError -- Error code *---------------------------------------------------------------------------*/ T_uezError LPC1768_Serial_Configure( void *aWorkspace, void *aCallbackWorkspace, HAL_Serial_Callback_Received_Byte aReceivedByteCallback, HAL_Serial_Callback_Transmit_Empty aTransmitEmptyCallback) { T_Serial_LPC1768_Workspace *p = (T_Serial_LPC1768_Workspace *)aWorkspace; const T_Serial_LPC1768_SerialInfo *p_info = p->iInfo; TUInt32 divider ; InterruptDisable(p->iInfo->iInterruptChannel); // Ensure power is on to the part // PCONP |= p->iPowerBit; // Configure the PCLK divider here to be CCLK/1 on UART0, 1/ // TBD: UART3 and 4 should be CCLK/1! SC->PCLKSEL0 = (SC->PCLKSEL0 & ~(3<<6)) | (1<<6); SC->PCLKSEL0 = (SC->PCLKSEL0 & ~(3<<8)) | (1<<8); SC->PCLKSEL1 = (SC->PCLKSEL1 & ~(3<<16)) | (1<<16); SC->PCLKSEL1 = (SC->PCLKSEL1 & ~(3<<18)) | (1<<18); p->iReceivedByteFunc = aReceivedByteCallback; p->iTransmitEmptyFunc = aTransmitEmptyCallback; p->iCallbackWorkspace = aCallbackWorkspace; divider = BAUD_DIVIDER(SERIAL_PORTS_DEFAULT_BAUD); // Set the FIFO enable bit in the FCR register. This bit must be set for // proper UART operation. p_info->iUART->u3.FCR = 7; // FCRFE|RFR|TFR // Set baudrate p_info->iUART->LCR |= 0x80; p_info->iUART->u1.DLL = divider & 0x00ff; p_info->iUART->u2.DLM = (divider >> 8) & 0x00ff; p_info->iUART->LCR &= ~0x80; // Set default mode (8 bits, 1 stop bit, no parity) p_info->iUART->LCR = 0x03; //Enable UART0 interrupts p_info->iUART->u2.IER = 0x03; // Interrupts and TX and RX InterruptRegister( p_info->iInterruptChannel, p_info->iISR, p_info->iPriority, p->iHAL->iInterface.iName); //TBD: For now, leave serial port deactivated // InterruptEnable(p_info->iInterruptChannel); return UEZ_ERROR_NONE; }
/*---------------------------------------------------------------------------* * Routine: LPC2478_Serial_Configure *---------------------------------------------------------------------------* * Description: * Link the serial port to a pair of callback routines and an * associated callback workspace. The callbacks are called when * a byte is received and when the transmit buffer becomes empty. * Inputs: * void *aWorkspace -- Serial port workspace * void *aCallbackWorkspace -- Callback's workspace * HAL_Serial_Callback_Received_Byte aReceivedByteCallback * -- Callback routine for received bytes * HAL_Serial_Callback_Transmit_Empty aTransmitEmptyCallback * -- Callback routine for transmit empty * Outputs: * T_uezError -- Error code *---------------------------------------------------------------------------*/ T_uezError LPC2478_Serial_Configure( void *aWorkspace, void *aCallbackWorkspace, HAL_Serial_Callback_Received_Byte aReceivedByteCallback, HAL_Serial_Callback_Transmit_Empty aTransmitEmptyCallback) { T_Serial_LPC2478_Workspace *p = (T_Serial_LPC2478_Workspace *)aWorkspace; const T_Serial_LPC2478_SerialInfo *p_info = p->iInfo; TUInt32 divider ; InterruptDisable(p->iInfo->iInterruptChannel); // Ensure power is on to the part LPC2478PowerOn(1UL << p->iInfo->iPowerBitIndex); p->iReceivedByteFunc = aReceivedByteCallback; p->iTransmitEmptyFunc = aTransmitEmptyCallback; p->iCallbackWorkspace = aCallbackWorkspace; divider = PROCESSOR_OSCILLATOR_FREQUENCY; divider = BAUD_DIVIDER(SERIAL_PORTS_DEFAULT_BAUD); // Set the FIFO enable bit in the FCR register. This bit must be set for // proper UART operation. p_info->iUART->reg08.FCR = 7; // FCRFE|RFR|TFR // Set baudrate p_info->iUART->LCR |= 0x80; p_info->iUART->reg00.DLL = divider & 0x00ff; p_info->iUART->reg04.DLM = (divider >> 8) & 0x00ff; p_info->iUART->LCR &= ~0x80; // Set default mode (8 bits, 1 stop bit, no parity) p_info->iUART->LCR = 0x03; //Enable UART0 interrupts p_info->iUART->reg04.IER = 0x03; // Interrupts and TX and RX InterruptRegister( p_info->iInterruptChannel, p_info->iISR, p_info->iPriority, p->iHAL->iInterface.iName); //TBD: For now, leave serial port deactivated // InterruptEnable(p_info->iInterruptChannel); return UEZ_ERROR_NONE; }
/*---------------------------------------------------------------------------* * Routine: LPC1768_Serial_SetSerialSettings *---------------------------------------------------------------------------* * Description: * Configure the serial port settings * Inputs: * void *aWorkspace -- Serial port workspace * T_Serial_Settings *aSettings -- Settings to use for serial port * Outputs: * T_uezError -- Error code *---------------------------------------------------------------------------*/ T_uezError LPC1768_Serial_SetSerialSettings( void *aWorkspace, T_Serial_Settings *aSettings) { T_Serial_LPC1768_Workspace *p = (T_Serial_LPC1768_Workspace *)aWorkspace; const T_Serial_LPC1768_SerialInfo *p_info = p->iInfo; TUInt32 divider ; // Record these settings p->iSettings = *aSettings; //TBD: Do the other settings! // Change the baud rate divider = BAUD_DIVIDER(aSettings->iBaud); p_info->iUART->LCR |= 0x80; p_info->iUART->u1.DLL = divider & 0x00ff; p_info->iUART->u2.DLM = (divider >> 8) & 0x00ff; p_info->iUART->LCR &= ~0x80; return UEZ_ERROR_NONE; }
/*---------------------------------------------------------------------------* * Routine: LPC17xx_40xx_Serial_SetSerialSettings *---------------------------------------------------------------------------* * Description: * Configure the serial port settings * Inputs: * void *aWorkspace -- Serial port workspace * T_Serial_Settings *aSettings -- Settings to use for serial port * Outputs: * T_uezError -- Error code *---------------------------------------------------------------------------*/ T_uezError LPC17xx_40xx_Serial_SetSerialSettings( void *aWorkspace, T_Serial_Settings *aSettings) { T_Serial_LPC17xx_40xx_Workspace *p = (T_Serial_LPC17xx_40xx_Workspace *)aWorkspace; const T_Serial_LPC17xx_40xx_SerialInfo *p_info = p->iInfo; TUInt32 divider; // Record these settings p->iSettings = *aSettings; //TBD: Do the other settings! // Change the baud rate divider = BAUD_DIVIDER(aSettings->iBaud); p_info->iUART->LCR |= 0x80; p_info->iUART->reg00.DLL = divider & 0x00ff; p_info->iUART->reg04.DLM = (divider >> 8) & 0x00ff; p_info->iUART->LCR &= 0x00; switch (aSettings->iParity) { case SERIAL_PARITY_ODD: p_info->iUART->LCR |= ((1 << 3) | (0 << 4)); break; case SERIAL_PARITY_EVEN: p_info->iUART->LCR |= ((1 << 3) | (1 << 4)); break; case SERIAL_PARITY_MARK: p_info->iUART->LCR |= ((1 << 3) | (2 << 4)); break; case SERIAL_PARITY_SPACE: p_info->iUART->LCR |= ((1 << 3) | (3 << 4)); break; case SERIAL_PARITY_NONE: p_info->iUART->LCR |= ((0 << 3) | (0 << 4)); break; default: return UEZ_ERROR_INVALID_PARAMETER; } switch (aSettings->iStopBit) { case SERIAL_STOP_BITS_1: p_info->iUART->LCR |= (0 << 2); break; case SERIAL_STOP_BITS_2: p_info->iUART->LCR |= (1 << 2); break; case SERIAL_STOP_BITS_1_POINT_5: return UEZ_ERROR_NOT_SUPPORTED; default: return UEZ_ERROR_INVALID_PARAMETER; } switch (aSettings->iWordLength) { case 5: p_info->iUART->LCR |= (0 << 0); break; case 6: p_info->iUART->LCR |= (1 << 0); break; case 7: p_info->iUART->LCR |= (2 << 0); break; case 8: p_info->iUART->LCR |= (3 << 0); break; default: return UEZ_ERROR_NOT_SUPPORTED; } return UEZ_ERROR_NONE; }