1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of the License "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // omap3530/omap3530_drivers/uart/omap3530_uart.h
15 // This file is part of the Beagle Base port
18 #ifndef __OMAP3530_UART_H__
19 #define __OMAP3530_UART_H__
21 #include <assp/omap3530_assp/omap3530_hardware_base.h>
22 #include <assp/omap3530_assp/omap3530_prcm.h>
23 //#include "assp/omap3530_assp/omap3530_prm.h"
24 #include <assp/omap3530_assp/omap3530_irqmap.h>
26 //#include "omap3530_prm.h"
29 namespace Omap3530Uart
31 using namespace TexasInstruments::Omap3530;
41 template< const TUartNumber aUartNumber >
47 struct TUartTraits< EUart0 >
49 static const TUint32 KBaseAddress = Omap3530HwBase::KL4_Core + 0x0006A000;
50 static const TInt KInterruptId = EOmap3530_IRQ72_UART1_IRQ;
51 static const Prcm::TClock KInterfaceClock = Prcm::EClkUart1_I;
52 static const Prcm::TClock KFunctionClock = Prcm::EClkUart1_F;
53 // static const Omap3530Prm::TPrmId KPrmInterfaceClock = Omap3530Prm::EPrmClkUart1_I;
54 // static const Omap3530Prm::TPrmId KPrmFunctionClock = Omap3530Prm::EPrmClkUart1_F;
58 struct TUartTraits< EUart1 >
60 static const TUint32 KBaseAddress = Omap3530HwBase::KL4_Core + 0x0006C000;
61 static const TInt KInterruptId = EOmap3530_IRQ73_UART2_IRQ;
62 static const Prcm::TClock KInterfaceClock = Prcm::EClkUart2_I;
63 static const Prcm::TClock KFunctionClock = Prcm::EClkUart2_F;
64 // static const Omap3530Prm::TPrmId KPrmInterfaceClock = Omap3530Prm::EPrmClkUart2_I;
65 // static const Omap3530Prm::TPrmId KPrmFunctionClock = Omap3530Prm::EPrmClkUart2_F;
69 struct TUartTraits< EUart2 >
71 static const TUint32 KBaseAddress = Omap3530HwBase::KL4_Per + 0x00020000;
72 static const TInt KInterruptId = EOmap3530_IRQ74_UART3_IRQ;
73 static const Prcm::TClock KInterfaceClock = Prcm::EClkUart3_I;
74 static const Prcm::TClock KFunctionClock = Prcm::EClkUart3_F;
75 // static const Omap3530Prm::TPrmId KPrmInterfaceClock = Omap3530Prm::EPrmClkUart3_I;
76 // static const Omap3530Prm::TPrmId KPrmFunctionClock = Omap3530Prm::EPrmClkUart3_F;
79 // Forward declaration
83 /** Representation of general UART register set */
86 static const TInt KOffset = 0x00;
87 static TDynReg8_RW< TUart, KOffset > iMem;
88 typedef TBitField<0,8> CLOCK_LSB;
93 static const TInt KOffset = 0x00;
94 static TDynReg8_R< TUart, KOffset > iMem;
95 typedef TBitField<0,8> Value;
100 static const TInt KOffset = 0x00;
101 static TDynReg8_W< TUart, KOffset > iMem;
102 typedef TBitField<0,8> Value;
107 static const TInt KOffset = 0x04;
108 static TDynReg8_RW< TUart, KOffset > iMem;
109 typedef TSingleBitField<7> CTS_IT;
110 typedef TSingleBitField<6> RTS_IT;
111 typedef TSingleBitField<5> XOFF_IT;
112 typedef TSingleBitField<4> SLEEP_MODE;
113 typedef TSingleBitField<3> MODEM_STS_IT;
114 typedef TSingleBitField<2> LINE_STS_IT;
115 typedef TSingleBitField<1> THR_IT;
116 typedef TSingleBitField<0> RHR_IT;
121 static const TInt KOffset = 0x04;
122 static TDynReg8_RW< TUart, KOffset > iMem;
123 typedef TSingleBitField<7> EOF_IT;
124 typedef TSingleBitField<6> LINE_STS_IT;
125 typedef TSingleBitField<5> TX_STATUS_IT;
126 typedef TSingleBitField<4> STS_FIFO_TRIG_IT;
127 typedef TSingleBitField<3> RX_OVERRUN_IT;
128 typedef TSingleBitField<2> LAST_RX_BYTE_IT;
129 typedef TSingleBitField<1> THR_IT;
130 typedef TSingleBitField<0> RHR_IT;
135 static const TInt KOffset = 0x04;
136 static TDynReg8_RW< TUart, KOffset > iMem;
137 typedef TBitField<0,6> CLOCK_MSB;
142 static const TInt KOffset = 0x08;
143 static TDynReg8_W< TUart, KOffset > iMem;
144 typedef TSingleBitField<0> FIFO_EN;
145 typedef TSingleBitField<1> RX_FIFO_CLEAR;
146 typedef TSingleBitField<2> TX_FIFO_CLEAR;
147 typedef TSingleBitField<3> DMA_MODE;
148 struct TX_FIFO_TRIG : public TBitField<4,2>
152 K8Char = 0 << KShift,
153 K16Char = 1 << KShift,
154 K32Char = 2 << KShift,
155 K56Char = 3 << KShift
158 struct RX_FIFO_TRIG : public TBitField<6,2>
160 static const TUint8 K8Char = 0 << KShift;
161 static const TUint8 K16Char = 1 << KShift;
162 static const TUint8 K56Char = 2 << KShift;
163 static const TUint8 K60Char = 3 << KShift;
169 static const TInt KOffset = 0x08;
170 static TDynReg8_R< TUart, KOffset > iMem;
171 typedef TBitField<6,2> FCR_MIRROR;
172 struct IT_TYPE : public TBitField<1,5>
176 EModem = 0 << KShift,
179 ERxLineStatus = 3 << KShift,
180 ERxTimeout = 6 << KShift,
182 ECtsRts = 16 << KShift
185 typedef TSingleBitField<0> IT_PENDING;
190 static const TInt KOffset = 0x08;
191 static TDynReg8_RW< TUart, KOffset > iMem;
192 typedef TSingleBitField<7> AUTO_CTS_EN;
193 typedef TSingleBitField<6> AUTO_RTS_EN;
194 typedef TSingleBitField<5> SPEC_CHAR;
195 typedef TSingleBitField<4> ENHANCED_EN;
196 struct SW_FLOW_CONTROL : public TBitField<0,4>
203 EXonXoffBoth = 8 + 4,
210 static const TInt KOffset = 0x0c;
211 static TDynReg8_RW< TUart, KOffset > iMem;
212 typedef TSingleBitField<7> DIV_EN;
213 typedef TSingleBitField<6> BREAK_EN;
214 typedef TSingleBitField<5> PARITY_TYPE2;
215 typedef TSingleBitField<4> PARITY_TYPE1;
216 typedef TSingleBitField<3> PARITY_EN;
217 struct NB_STOP : public TSingleBitField<2>
221 E1Stop = 0 << KShift,
222 E1_5Stop = 1 << KShift,
226 struct CHAR_LENGTH : public TBitField<0,2>
237 /** Special magic number to enter MODEA */
238 static const TUint8 KConfigModeA = 0x80;
240 /** Special magic number to enter MODEB */
241 static const TUint8 KConfigModeB = 0xBF;
243 /** Special magic number to enter operational mode */
244 static const TUint8 KConfigModeOperational = 0x00;
249 static const TInt KOffset = 0x10;
250 static TDynReg8_RW< TUart, KOffset > iMem;
251 typedef TSingleBitField<6> TCR_TLR;
252 typedef TSingleBitField<5> XON_EN;
253 typedef TSingleBitField<4> LOOPBACK_EN;
254 typedef TSingleBitField<3> CD_STS_CH;
255 typedef TSingleBitField<2> RI_STS_CH;
256 typedef TSingleBitField<1> RTS;
257 typedef TSingleBitField<0> DTR;
262 static const TInt KOffset = 0x10;
263 static TDynReg8_RW< TUart, KOffset > iMem;
264 typedef TBitField<0,8> Value;
269 static const TInt KOffset = 0x14;
270 static TDynReg8_R< TUart, KOffset > iMem;
271 typedef TSingleBitField<7> RX_FIFO_STS;
272 typedef TSingleBitField<6> TX_SR_E;
273 typedef TSingleBitField<5> TX_FIFO_E;
274 typedef TSingleBitField<4> RX_BI;
275 typedef TSingleBitField<3> RX_FE;
276 typedef TSingleBitField<2> RX_PE;
277 typedef TSingleBitField<1> RX_OE;
278 typedef TSingleBitField<0> RX_FIFO_E;
283 static const TInt KOffset = 0x14;
284 static TDynReg8_RW< TUart, KOffset > iMem;
285 typedef TBitField<0,8> Value;
290 static const TInt KOffset = 0x18;
291 static TDynReg8_RW< TUart, KOffset > iMem;
292 typedef TBitField<0,8> Value;
297 static const TInt KOffset = 0x18;
298 static TDynReg8_RW< TUart, KOffset > iMem;
299 typedef TBitField<4,4> RX_FIFO_TRIG_START;
300 typedef TBitField<0,4> RX_FIFO_TRIG_HALT;
305 static const TInt KOffset = 0x18;
306 static TDynReg8_R< TUart, KOffset > iMem;
307 typedef TSingleBitField<7> NCD_STS;
308 typedef TSingleBitField<6> NRI_STS;
309 typedef TSingleBitField<5> NDSR_STS;
310 typedef TSingleBitField<4> NCTS_STS;
311 typedef TSingleBitField<3> DCD_STS;
312 typedef TSingleBitField<2> RI_STS;
313 typedef TSingleBitField<1> DSR_STS;
314 typedef TSingleBitField<0> CTS_STS;
319 static const TInt KOffset = 0x1c;
320 static TDynReg8_RW< TUart, KOffset > iMem;
321 typedef TBitField<0,8> SPR_WORD;
326 static const TInt KOffset = 0x1c;
327 static TDynReg8_RW< TUart, KOffset > iMem;
328 typedef TBitField<0,8> Value;
333 static const TInt KOffset = 0x1c;
334 static TDynReg8_RW< TUart, KOffset > iMem;
335 typedef TBitField<4,4> RX_FIFO_TRIG_DMA;
336 typedef TBitField<0,4> TX_FIFO_TRIG_DMA;
341 static const TInt KOffset = 0x20;
342 static TDynReg8_RW< TUart, KOffset > iMem;
343 typedef TSingleBitField<7> FRAME_END_MODE;
344 typedef TSingleBitField<6> SIP_MODE;
345 typedef TSingleBitField<5> SCT;
346 typedef TSingleBitField<4> SET_TXIR;
347 typedef TSingleBitField<3> IR_SLEEP;
348 struct MODE_SELECT : public TBitField<0,3>
354 EUart16xAutoBaud = 2,
366 static const TInt KOffset = 0x24;
367 static TDynReg8_RW< TUart, KOffset > iMem;
368 typedef TSingleBitField<6> IRRXINVERT;
369 struct CIR_PULSE_MODE : public TBitField<4,2>
379 typedef TSingleBitField<3> UART_PULSE;
380 struct STS_FIFO_TRIG : public TBitField<1,2>
384 E1Entry = 0 << KShift,
385 E4Entry = 1 << KShift,
386 E7Entry = 2 << KShift,
387 E8Entry = 3 << KShift
390 typedef TSingleBitField<0> IRTX_UNDERRUN;
395 static const TInt KOffset = 0x28;
396 static TDynReg8_W< TUart, KOffset > iMem;
397 typedef TBitField<0,8> TX_FLL;
402 static const TInt KOffset = 0x28;
403 static TDynReg8_R< TUart, KOffset > iMem;
404 typedef TSingleBitField<4> OE_ERROR;
405 typedef TSingleBitField<3> FTL_ERROR;
406 typedef TSingleBitField<2> ABORT_DETECT;
407 typedef TSingleBitField<1> CRC_ERROR;
412 static const TInt KOffset = 0x2c;
413 static TDynReg8_R< TUart, KOffset > iMem;
414 typedef TBitField<0,8> Value;
419 static const TInt KOffset = 0x2c;
420 static TDynReg8_W< TUart, KOffset > iMem;
421 typedef TBitField<0,5> TX_FLH;
426 static const TInt KOffset = 0x30;
427 static TDynReg8_W< TUart, KOffset > iMem;
428 typedef TBitField<0,8> RX_FLL;
433 static const TInt KOffset = 0x30;
434 static TDynReg8_R< TUart, KOffset > iMem;
435 typedef TBitField<0,8> Value;
440 static const TInt KOffset = 0x34;
441 static TDynReg8_R< TUart, KOffset > iMem;
442 typedef TBitField<0,4> Value;
447 static const TInt KOffset = 0x34;
448 static TDynReg8_W< TUart, KOffset > iMem;
449 typedef TBitField<0,4> RX_FLH;
454 typedef TSingleBitField<7> STS_FIFO_RESET;
455 typedef TSingleBitField<6> XBOF_TYPE;
460 static const TInt KOffset = 0x38;
461 static TDynReg8_R< TUart, KOffset > iMem;
462 struct PARITY_TYPE : public TBitField<6,2>
467 ESpace = 1 << KShift,
472 struct BIT_BY_CHAR : public TSingleBitField<5>
480 struct SPEED : public TBitField<0,5>
501 static const TInt KOffset = 0x3c;
502 static TDynReg8_RW< TUart, KOffset > iMem;
503 typedef TSingleBitField<7> PULSE_TYPE;
504 typedef TSingleBitField<6> SID_MOD;
505 typedef TSingleBitField<5> DIS_IR_RX;
506 typedef TSingleBitField<4> DIS_TX_UNDERRUN;
507 typedef TSingleBitField<3> SEND_SIP;
508 typedef TSingleBitField<2> SCTX_EN;
509 typedef TSingleBitField<1> ABORT_EN;
510 typedef TSingleBitField<0> EOT_EN;
515 static const TInt KOffset = 0x40;
516 static TDynReg8_RW< TUart, KOffset > iMem;
517 typedef TSingleBitField<7> RX_TRIG_GRANU1;
518 typedef TSingleBitField<6> TX_TRIG_GRANU1;
519 typedef TSingleBitField<4> RX_CTS_WU_EN;
520 typedef TSingleBitField<3> TX_EMPTY_CTL_IT;
521 typedef TBitField<1,2> DMA_MODE2;
522 typedef TSingleBitField<0> DMA_MODE_CTL;
527 static const TInt KOffset = 0x44;
528 static TDynReg8_R< TUart, KOffset > iMem;
529 typedef TSingleBitField<1> RX_CTS_WU_STS;
530 typedef TSingleBitField<0> TX_FIFO_FULL;
535 static const TInt KOffset = 0x48;
536 static TDynReg8_RW< TUart, KOffset > iMem;
537 typedef TBitField<0,8> Value;
542 static const TInt KOffset = 0x54;
543 static TDynReg8_RW< TUart, KOffset > iMem;
544 struct IDLE_MODE : public TBitField<3,2>
548 EForceIdle = 0 << KShift,
549 ENoIdle = 1 << KShift,
550 ESmartIdle = 2 << KShift
553 typedef TSingleBitField<2> ENAWAKEUP;
554 typedef TSingleBitField<1> SOFTRESET;
555 typedef TSingleBitField<0> AUTOIDLE;
560 static const TInt KOffset = 0x58;
561 static TDynReg8_R< TUart, KOffset > iMem;
562 typedef TSingleBitField<0> RESETDONE;
567 static const TInt KOffset = 0x5c;
568 static TDynReg8_RW< TUart, KOffset > iMem;
569 typedef TSingleBitField<6> EVENT_6_RLS_INTERRUPT;
570 typedef TSingleBitField<5> EVENT_5_RHR_INTERRUPT;
571 typedef TSingleBitField<4> EVENT_4_RX_ACTIVITY;
572 typedef TSingleBitField<2> EVENT_2_RI_ACTIVITY;
573 typedef TSingleBitField<0> EVENT_0_CTS_ACTIVITY;
578 static const TInt KOffset = 0x60;
579 static TDynReg8_RW< TUart, KOffset > iMem;
580 typedef TBitField<0,8> Value;
620 E5Data = ::Omap3530Uart::LCR::CHAR_LENGTH::E5Bits,
621 E6Data = ::Omap3530Uart::LCR::CHAR_LENGTH::E6Bits,
622 E7Data = ::Omap3530Uart::LCR::CHAR_LENGTH::E7Bits,
623 E8Data = ::Omap3530Uart::LCR::CHAR_LENGTH::E8Bits,
628 E1Stop = ::Omap3530Uart::LCR::NB_STOP::E1Stop,
629 E1_5Stop = ::Omap3530Uart::LCR::NB_STOP::E1_5Stop,
630 E2Stop = ::Omap3530Uart::LCR::NB_STOP::E2Stop,
673 inline TUart( const TUartNumber aUartNumber )
674 : iBase( (aUartNumber == EUart0 ) ? TUartTraits<EUart0>::KBaseAddress
675 : (aUartNumber == EUart1 ) ? TUartTraits<EUart1>::KBaseAddress
676 : (aUartNumber == EUart2 ) ? TUartTraits<EUart2>::KBaseAddress
678 iUartNumber( aUartNumber )
681 FORCE_INLINE TLinAddr Base() const
684 IMPORT_C TInt InterruptId() const;
686 IMPORT_C Prcm::TClock PrcmInterfaceClk() const;
688 IMPORT_C Prcm::TClock PrcmFunctionClk() const;
690 // IMPORT_C TInt PrmInterfaceClk() const;
692 // IMPORT_C TInt PrmFunctionClk() const;
694 /** Reset and initialize the UART
695 * On return the UART will be in disable mode */
696 IMPORT_C void Init();
698 /** Defines which mode the UART will run in when enabled, but does not configure that mode
699 * You must call this before calling SetBaud to ensure that correct baud rate multiplier is used */
700 IMPORT_C void DefineMode( const TUartMode aMode );
702 /** Enabled the UART in the defined mode
703 * You must call DefineMode() and SetBaud() before calling Enable()
705 IMPORT_C void Enable();
707 /** Disables the UART */
708 IMPORT_C void Disable();
710 /** Set the baud rate
711 * Do not call this while the UART is enabled
712 * You must have previously called DefineMode()
714 IMPORT_C void SetBaud( const TBaud aBaud );
716 /** Set the data length, parity and stop bits */
717 IMPORT_C void SetDataFormat( const TDataBits aDataBits, const TStopBits aStopBits, const TParity aParity );
719 /** Setup the FIFO configuration */
720 IMPORT_C void EnableFifo( const TEnableState aState, const TFifoTrigger aRxTrigger = ETriggerUnchanged, const TFifoTrigger aTxTrigger = ETriggerUnchanged );
722 /** Enable a particular interrupt source */
723 IMPORT_C void EnableInterrupt( const TInterrupt aWhich );
725 /** Disable a particular interrupt source */
726 IMPORT_C void DisableInterrupt( const TInterrupt aWhich );
728 /** Disable all interrupts */
729 IMPORT_C void DisableAllInterrupts();
731 inline TBool TxFifoFull()
732 { return SSR::iMem.Read(*this) bitand SSR::TX_FIFO_FULL::KMask; }
734 inline TBool TxFifoEmpty()
735 { return LSR::iMem.Read(*this) bitand LSR::TX_FIFO_E::KMask; }
737 inline TBool RxFifoEmpty()
738 { return !(LSR::iMem.Read(*this) bitand LSR::RX_FIFO_E::KMask); }
740 inline void Write( TUint8 aByte )
741 { THR::iMem.Write( *this, aByte ); }
744 { return RHR::iMem.Read( *this ); }
750 const TLinAddr iBase;
751 const TUartNumber iUartNumber : 8;
753 ::Omap3530Uart::MDR1::MODE_SELECT::TMode iTargetMode : 8;
759 #endif // ndef __OMAP3530_UART_H__