📄 irda_api.c
字号:
///////////////////////////////////////////////////////////////////////////////
//
// ROCKWELL SEMICONDUCTOR SYSTEMS - WIRELESS COMMUNICATIONS DIVISION
//
///////////////////////////////////////////////////////////////////////////////
//
//
// irdaapi.c - Irda API for porting
//
//
// DESCRIPTION
//
// Irda API for porting
//
//
// REVISION HISTORY (ORIGINAL AUTHOR: luw)
//
// Rev 1.0 29 Mar 2003 luw
// Intial CheckIn
//
//
///////////////////////////////////////////////////////////////////////////////
//
// ROCKWELL CONFIDENTIAL AND PROPRIETARY
//
// This source is the sole property of Rockwell International. Reproduction
// or utilization of this source in whole or in part is forbidden without
// the written consent of Rockwell International.
//
// (c) Copyright Rockwell International, 1996. All Rights Reserved.
//
///////////////////////////////////////////////////////////////////////////////
// ---------------------------- Headers Include -------------------------------
// Standard includes.
#include "wcdtypes.h"
#include <stdarg.h>
#include "apitypes.h"
#include "sysutil.h"
#include "globlapi.h"
#include "uhapi.h"
#include "..\..\Include\MMI_Inc\idevapi.h"
#include "..\..\Include\MMI_Inc\iusart.h"
#include "..\..\Include\MMI_Inc\isds.h"
#include "devgpio.h"
// ------------------- Global Definitions and Declarations --------------------
#define SDS_BASE ((void*)0x41200) /* Serial Port 2 */
#define IRDA_BASE ((void*)0x40340) /* IRDA Translator */
#define CLK_FRC1_REG 0x40904
#define CLKFRC1_IR 0x8000 // Force IR Clock
#define IR_EN 0x0001 // 1 - enabled
#define IR_NO_BYPASS_MODE 0x0008 // 1 - NO BYPASS
#define IR_INVERT_INPUT 0x0002 // 1 - inverted
#define IR_RX_9P6_BAUDS_3P9 404
#define IR_RX_9P6_BAUDS_19P5 2029
#define IR_TX_PULSE_3P9 5
#define IR_TX_PULSE_19P5 27
#define IR_RX_PULSE_3P9 (1<<8)
#define IR_RX_PULSE_19P5 (21<<8)
#define IR_RX_115P2_BAUDS_3P9 32
#define IR_RX_115P2_BAUDS_19P5 167
#define IR_RX_9P6_BAUDS_3P9 404
#define IR_RX_9P6_BAUDS_19P5 2029
#define IR_RX_57P6_BAUDS_3P9 66
#define IR_RX_38P4_BAUDS_3P9 100
#define IR_RX_19P2_BAUDS_3P9 201
#define IR_RX_57P6_BAUDS_19P5 337
#define IR_RX_38P4_BAUDS_19P5 506
#define IR_RX_19P2_BAUDS_19P5 1013
typedef enum
{
eCLKEN1_NONE = 0x0000,
eCLKEN1_ARM = 0x0001, // Enable ARM Clock
eCLKEN1_AMBA = 0x0002, // Enable AMBA Clock
eCLKEN1_SLEEP = 0x0004, // Enable Sleep
eCLKEN1_SIM = 0x0008, // Enable SIM Clock
eCLKEN1_PWM = 0x0010, // Enable PWM Clock
eCLKEN1_TMR1 = 0x0020, // Enable Timer1 Clock
eCLKEN1_CRC = 0x0040, // Enable CRC Clock
eCLKEN1_GIE = 0x0080, // Enable Global Interrupt
eCLKEN1_3P9M = 0x0100, // Enable 3.9 Mhz Clock
eCLKEN1_DBG = 0x0200, // Enable Debug USART Clock
eCLKEN1_SDS = 0x0400, // Enable SDS USART Clock
eCLKEN1_AB = 0x0800, // Enable Autobaud Clock
eCLKEN1_DMA = 0x1000, // Enable DMA Clock
eCLKEN1_ESC = 0x2000, // Enable ESC Detect Clock
eCLKEN1_DSP = 0x4000, // Enable DSP Clock
eCLKEN1_IR = 0x8000 // Enable IR Clock
} t_ClockControl1;
typedef enum
{
eCLKEN2_NONE = 0x0000,
eCLKEN2_SPV_MASK = 0x000F, // Supervisory Mask
eCLKEN2_SPV_EN = 0x0005, // Enable Supervisory Mode
eCLKEN2_SPV_DIS = 0x0000, // Disable Supervisory Mode
eCLKEN2_GDX = 0x0010, // Enable GENDEX Clock
eCLKEN2_TMR2 = 0x0020, // Enable Timer2 Clock
eCLKEN2_FRM = 0x0040, // Enable Framer Clock
eCLKEN2_FRM_HI = 0x0080, // Enable Framer's High Clock
eCLKEN2_SLOW = 0x0100, // Enable (1Mhz) Slow Clock
eCLKEN2_DBG_FAST = 0x0200, // Enable FAST CLOCK FOR DBG
eCLKEN2_SDS_FAST = 0x0400, // Enable FAST CLOCK FOR SDS
eCLKEN2_SSP = 0x0800, // SSP clock 815 ONLY
eCLKEN2_PROTHEX = 0x2000, // PPP Framer Clock 815 ONLY
eCLKEN2_DSP_PCMP = 0x4000, // DSP PCMP Clock 815 ONLY
eCLKEN2_WD = 0x8000 // Watchdog Timer Clock 815 ONLY
} t_ClockControl2;
typedef void (*t_FcnPtr_SetClockControl)(t_ClockControl1 inEnableClk1,
t_ClockControl2 inEnableClk2,
t_ClockControl1 inDisableClk1,
t_ClockControl2 inDisableClk2);
#define DEVICE_SPEC_SetClockControl (*gFcnPtr_SetClockControl)
// ----------------------- Constant / Macro Definitons -----------------------
// ---------------------------- Type Declarations -----------------------------
typedef struct tagSDS_REG_STRUCT
{
HUREG16 TxControl; // Tx Control
HUREG16 TxBaud; // Tx Baud Rate
HUREG16 TxHold; // Tx Data/Holding
HUREG16 TxStatus; // Tx Status
HUREG16 RxControl; // Rx Control
HUREG16 RxBaud; // Rx Baud Rate
HUREG16 RxHold; // Rx Data/Holding
HUREG16 RxStatus; // Rx Status
HUREG16 RxTimeout; // Rx Time Out value
HUREG16 RxTimer; // Timer for Rx Timeout
HUREG16 Reserved[6]; // Reserved addresses
HUREG16 ABBaudTable[8]; // Autobaud rates
}
SDS_REG_STRUCT;
typedef struct tagSDS_IRDA_REG_STRUCT
{
HUREG16 Control; // Irda control register
HUREG16 RxBaud; // Rx bit baud rate expected
HUREG16 PulseConfig; // Configuration of Tx/Rx pulses length
} SDS_IRDA_REG_STRUCT;
// -------------------------- Variable Declarations ---------------------------
static SDS_REG_STRUCT *pUartRegs = SDS_BASE; // Uart Registers base address.
static SDS_IRDA_REG_STRUCT *pIrdaRegs = IRDA_BASE; // Irda Registers base address.
static USHORT ClockSource = USART_LO_CLK; // 3.9 Mhz clock;
// --------------------------- Function Prototypes ----------------------------
extern GPIO_HANDLE_TYPE IrDa;
extern const BOOLEAN IrDaEnabled;
extern t_FcnPtr_SetClockControl gFcnPtr_SetClockControl;
extern UHERR uhGPIOSystemWrite (GPIO_HANDLE_TYPE handle, GPIO_STATE state, BOOLEAN enabled);
extern DEVSTATUS SetBaudRate (VOID *USARTAddr,
USHORT ClockSource,
USART_RATES BaudRate);
// ------------------------------ Implementation ------------------------------
static DEVSTATUS SetIrBaudRate (VOID *IrAddr,
USHORT ClockSource,
USART_RATES BaudRate)
{
DEVSTATUS Status = DEV_OK;
switch (BaudRate)
{
case USART_9600:
((SDS_IRDA_REG_STRUCT *) IrAddr)->RxBaud = (ClockSource == USART_LO_CLK) ?
IR_RX_9P6_BAUDS_3P9 : IR_RX_9P6_BAUDS_19P5;
break;
case USART_115200:
((SDS_IRDA_REG_STRUCT *) IrAddr)->RxBaud = (ClockSource == USART_LO_CLK) ?
IR_RX_115P2_BAUDS_3P9 : IR_RX_115P2_BAUDS_19P5;
break;
case USART_19200:
((SDS_IRDA_REG_STRUCT *) IrAddr)->RxBaud = (ClockSource == USART_LO_CLK) ?
IR_RX_19P2_BAUDS_3P9 : IR_RX_19P2_BAUDS_19P5;
break;
case USART_38400:
((SDS_IRDA_REG_STRUCT *) IrAddr)->RxBaud = (ClockSource == USART_LO_CLK) ?
IR_RX_38P4_BAUDS_3P9 : IR_RX_38P4_BAUDS_19P5;
break;
case USART_57600:
((SDS_IRDA_REG_STRUCT *) IrAddr)->RxBaud = (ClockSource == USART_LO_CLK) ?
IR_RX_57P6_BAUDS_3P9 : IR_RX_57P6_BAUDS_19P5;
break;
default:
Status = DEV_BADPARAMS;
break;
}
return (Status);
}
DEVSTATUS SDSOpenIrDA (USHORT DevNumber, DEVRWMODE Mode, VOID *pParams)
{
DEVSTATUS IrdaStatus;
DEVSTATUS Status = DEV_OK; // Initialize the returned status to OK...
//Enable IrDA Chip Select
uhGPIOSystemWrite(IrDa, LOW_STATE, IrDaEnabled);
// ENABLE LO CLOCK ON IR FOR PULSE SHAPER
DEVICE_SPEC_SetClockControl(eCLKEN1_IR, eCLKEN2_NONE,
eCLKEN1_NONE, eCLKEN2_NONE);
// ENABLE CLOCK FORCE ON IR PULSE SHAPER
*((HUREG16*)(CLK_FRC1_REG)) |= CLKFRC1_IR;
// Program the registers
pIrdaRegs->Control = 0;
pIrdaRegs->Control = IR_EN | IR_NO_BYPASS_MODE | IR_INVERT_INPUT;
IrdaStatus = SetIrBaudRate ((VOID *) pIrdaRegs,
(USHORT) ClockSource,
USART_9600 );
// The open baud rate can only be 9.6 for IRDA link
pIrdaRegs->RxBaud = (ClockSource == USART_LO_CLK) ?
IR_RX_9P6_BAUDS_3P9 : IR_RX_9P6_BAUDS_19P5;
pIrdaRegs->PulseConfig = 0;
pIrdaRegs->PulseConfig = (ClockSource == USART_LO_CLK) ?
IR_TX_PULSE_3P9 | IR_RX_PULSE_3P9 :
IR_TX_PULSE_19P5 | IR_RX_PULSE_19P5;
return Status;
}
DEVSTATUS SDSSetIrDABaudRate(DEVHANDLE DevHandle, ULONG BaudRate)
{
DEVSTATUS Status;
SDS_PRTCL_PARAMS SDSParams;
UINT32 Length;
UINT32 LenMax;
// Set UART baudrate
Status = SetBaudRate ((VOID *) pUartRegs,(USHORT) ClockSource,BaudRate);
// For the CX8xx, change IrDA baudrate (in the pIrdaRegs) also to 115200 ???
Status = SetIrBaudRate ((VOID *) pIrdaRegs,(USHORT) ClockSource,BaudRate);
//Update the baud rate variable
LenMax = Length = sizeof(SDS_PRTCL_PARAMS);
Status = DevIOControl(DevHandle, SDS_GET_PROTOCOL, LenMax, &Length, (void *)&SDSParams);
//reset SDS port protocal
SDSParams.BaudRate = BaudRate;
Length=sizeof(SDS_PRTCL_PARAMS);
LenMax=Length;
Status = DevIOControl(DevHandle, SDS_SET_PROTOCOL, LenMax, &Length, (VOID *)&SDSParams);
return Status;
}
DEVSTATUS SDSCloseIrDA(USHORT DevNumber)
{
DEVSTATUS Status = DEV_OK;
pIrdaRegs->Control = 0; // Disable Irda
// DISABLE LO CLOCK ON IR FOR PULSE SHAPER
DEVICE_SPEC_SetClockControl(eCLKEN1_NONE, eCLKEN2_NONE,
eCLKEN1_IR, eCLKEN2_NONE);
// DISABLE CLOCK FORCE ON IR PULSE SHAPER
*((HUREG16*)(CLK_FRC1_REG)) &= ~CLKFRC1_IR;
//Disable IrDA Chip Select
uhGPIOSystemWrite(IrDa, HIGH_STATE, IrDaEnabled);
return Status;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -