📄 hwsetup.c
字号:
/******************************************************************************/
/* Renesas Technology America, Inc. Legal Disclaimer */
/******************************************************************************/
/* THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY */
/* KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE */
/* IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR */
/* PURPOSE. */
/* */
/* BY USING THE SOFTWARE HEREIN, YOU (AND YOUR COMPANY) AGREE TO BE BOUND BY */
/* THE TERMS AND CONDITIONS OF RENESAS TECHNOLOGY AMERICA, INC.'S SOURCE CODE */
/* LICENSE AGREEMENT. PLEASE READ THIS AGREEMENT CAREFULLY. IF YOU (OR YOUR */
/* COMPANY) DO NOT AGREE TO ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT, */
/* DO NOT INSTALL OR USE THIS SOFTWARE AND ASSOCIATED DOCUMENTATION. */
/* */
/* Copyright (c) 2003, 2004, 2005 and 2006 Renesas Technology America, Inc. */
/*******************************************************************************
tab space = 4
***********************************************************************************
FILE NAME : HWSetup.C
DESCRIPTION : Hardware Setup functions
Copyright : 2006 Renesas Technology Europe Ltd.
Copyright : 2006 Renesas Solutions Corporation.
Copyright : 2006 Renesas Technology Corporation.
All Rights Reserved
***********************************************************************************/
/***********************************************************************************
Revision History
DD.MM.YYYY OSO-UID Description
02.05.2006 RTE-NPS First Release
***********************************************************************************/
/***********************************************************************************
System Includes
***********************************************************************************/
/***********************************************************************************
User Includes
***********************************************************************************/
/* sfr_r823.h provides a structure to access all of the device registers. */
#include "sfr_r823.h"
/* RSKR8C23def.h provides common defines for widely used items. */
#include "rskR8C23def.h"
/* This node's lin_dev.h */
#include "lin_dev.h"
/***********************************************************************************
User Program Code Prototypes
***********************************************************************************/
/* These fuctions are private so their prototypes are defined locally */
void ConfigureInternalOperatingFrequency(void);
void ConfigureExternalOperatingFrequency(void);
void EnablePeripheralModules(void);
void ConfigurePortPins(void);
/***********************************************************************************
User Program Code
***********************************************************************************/
/***********************************************************************************
Function Name: HardwareSetup
Description: Sets up hardware
Parameters: none
Return value: none
***********************************************************************************/
void HardwareSetup(void)
{
#if (LIN_MASTER_NODE == LIN_MY_NODE_NAME)
ConfigureExternalOperatingFrequency();
#else
/* Note: The ConfigureInternalOperatingFrequency() function is only to be used
for slaves, when SYNC_AUTO_MODE is enabled. */
ConfigureInternalOperatingFrequency();
#endif
ConfigurePortPins();
EnablePeripheralModules();
}
/***********************************************************************************
End of function HardwareSetup
***********************************************************************************/
/***********************************************************************************
Function Name: ConfigureExternalOperatingFrequency
Description: Sets up operating speed
Parameters: none
Return value: none
***********************************************************************************/
void ConfigureExternalOperatingFrequency(void)
{
/* Interrupt disable */
asm("FCLR I");
/* Protect off */
prcr = 1;
/* Xin Xout */
cm13 = 1;
/* XCIN-XCOUT drive capacity select bit : HIGH */
cm15 = 1;
/* Xin on */
cm05 = 0;
/* Main clock = No division mode */
cm16 = 0;
/* Main clock = No division mode */
cm17 = 0;
/* CM16 and CM17 enable */
cm06 = 0;
/* Wait for stable oscillation */
asm("nop");
asm("nop");
asm("nop");
asm("nop");
/* Main clock change */
ocd2 = 0;
/* Protect on */
prcr = 0;
}
/***********************************************************************************
Function Name: ConfigureInternalOperatingFrequency
Description: Sets up operating speed
Parameters: none
Return value: none
***********************************************************************************/
void ConfigureInternalOperatingFrequency(void)
{
/* Interrupt disable */
asm("FCLR I");
/* Setting of a clock ( High-speed Ring Oscillator / 10MHz ) */
/* Manip. clock permission */
prc0 = 1;
/* System clock control register 0. Enable clock div. with cm16&17 */
cm0 = 0x28;
/* System clock control register 1. */
cm1 = 0x00; /* Div. by 1 */
/* Oscillation stoppage detect register */
ocd = 0x04;
/* 40MHz On chip oscillator control register 0 */
fra0 = 0x03;
/* 40MHz On chip oscillator control register 2 */
fra2 = 0x02; /* Divide-by-4 mode is min. */
/* Manip. clock prohibit */
prc0 = 0;
}
/***********************************************************************************
Function Name: EnablePeripheralModules
Description: Enables Peripheral Modules before use
Parameters: none
Return value: none
***********************************************************************************/
void EnablePeripheralModules(void)
{
/* All modules are active in the M16C device */
}
/***********************************************************************************
End of function EnablePeripheralModules
***********************************************************************************/
/***********************************************************************************
Function Name: ConfigurePortPins
Description: Sets up operating speed
Parameters: none
Return value: none
***********************************************************************************/
void ConfigurePortPins(void)
{
/* Port pins default to inputs. To ensure safe initialisation set the pin states
before changing the data direction registers. This will avoid any unintentional
state changes on the external ports.
Many peripheral modules will override the setting of the port registers. Ensure
that the state is safe for external devices if the internal peripheral module is
disabled or powered down. */
/* Configure unused pins as output low */
prc2 = 1; /* Enable writes to PD0, cleared by following write operation. */
p0=p1=p2=p3=p4=p6=0x0;
pd0=pd1=pd2=pd3=pd4=pd6=0xFF;
/* LED Port configuration */
p2 = 0xff;
pd2 = 0xf0;
/* SW Port configuration */
pd1_7 = 0;
pd1_3 = 0;
pd4_5 = 0;
pur0 = 0x04;
/* LCD Module Port configuration */
/* Set control = outputs */
pd1 = 0x06;
/* disenable PD0 protect bit */
prc2 = 1;
/* Set data = outputs */
pd0 = 0x0f;
/* Port 1_4, 1_5, 1_6 are used UART0 (LIN) ports */
/* UART0 (LIN) ports 1_4=TX, 1_5=RX, 1_6=Clock */
//pd1_4=1; //done by l_sys_init
//pd1_5=0; //done by l_sys_init
/* Set transceiver to not sleep NSLP */
//pd1_6=1; //done by l_sys_init
//p1_6=1; //done by l_sys_init
}
/***********************************************************************************
End of function ConfigurePortPins
***********************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -