📄 hw.c
字号:
/*
**********************************************************************
* Micrium, Inc.
* 949 Crestview Circle
* Weston, FL 33327-1848
*
* uC/USB-Bulk
*
* (c) Copyright 2003 - 2004, Micrium, Inc.
* All rights reserved.
*
***********************************************************************
--------- END-OF-HEADER ---------------------------------*/
#include "RTOS.H"
#include "IOM30245.h"
/*********************************************************************
*
* Local functions
*
**********************************************************************
*/
/*********************************************************************
*
* StartPll
*
* DESCRIPTION: Starts the onboard PLL for the USB core's use.
*
* RETURNS: Nothing
*/
static void _StartPll(void) {
unsigned char DelayOne = 0xff; // Temporary delay variables
unsigned char DelayTwo = 0xff;
PRCR = 0x03; // Disable protection of the clock & PLL registers
FSP = 0x01; // Xin = 16MHz -> Fpin = 4MHz
FSM = 0x05; // Fpin = 4MHz -> Fvco/Fusb = 48MHz
FSD = 0x01; // Fvco = 48MHz -> Fsyn = 12MHz (if necessary)
FSC = 0x43; // debug....
while ( DelayTwo != 0 ){ // Simple DO->WHILE to count while the
while ( DelayOne != 0 ){ // PLL comes online and stabilizes
DelayOne--; // These values should give us a delay of
} // Approxiamtely 3mS or so before we check
DelayOne = 0xff; // Reload small delay
DelayTwo--; // and one tick off large delay
}
while ( !(FSC & (1<<7)) ){ // Check to see if PLL is locked in
DelayOne = 0x32; // if not wait 0.1 mS and check again
DelayTwo = 0x0b;
while ( DelayTwo != 0){ // Simple DO->WHILE to count while the
while ( DelayOne != 0 ){
DelayOne--; // These values should give us a delay of
} // Approxiamtely 0.1 mS or before we check
DelayOne = 0xff; // Reload small delay
DelayTwo--; // and one tick off large delay
}
}
}
/*********************************************************************
*
* Global functions
*
**********************************************************************
*/
/*********************************************************************
*
* __low_level_init(void)
*
* DESCRIPTION: Loads default values into specific registers for startup
* mainly used for Vbus detect to provide signal that the
* device is ready to run USB operations.
*
* RETURNS: 1 to tell startup-code to initilize segments
* 0 to tell startup-code not to initialize segments
*/
unsigned char __low_level_init(void){
PRCR = 0x03; // Disable protection of the clock & PLL registers
CM0 = 0x08; // Enable CM16 & CM17 for high speed mode
CM1 = 0x00; // BCLK/1. Should = 16MHz
PRCR = 0x00; // Enable protection of the clock & PLL registers
PUR2 |= (1<<0); // Enable pullups on P8_0 to P8_4
PUR2 |= (1<<5); // Enable pullups on P10_4-P10_7
USBAD = 0x81; // Enable P90 for D+ pullup and enable Vbus detect
// VBDIC = 0; // Clear the Vbus detect interrupt (per spec)
// VBDIC = 0x04; // Enable the Vbus detect interrupt (level 4)
_StartPll();
// Enable USB core
USBC = 0x20; // Enable USB core clock
USBC = 0xe0; // Enable USB core clock & SOF output
// Purpose: Initialize Hardware of JTAG interface to target. Set all outputs to
// default values.
// Initialize Ports used for JTAG / target interface
PUR0 = (0<<7) // Pull-Up port P34..P37
|(0<<6) // Pull-Up port P30..P33
|(1<<5) // Pull-Up port P24..P27
|(1<<4) // Pull-Up port P20..P23
|(0<<3) // Pull-Up port P14..P17
|(0<<2) // Pull-Up port P10..P13
|(0<<1) // Pull-Up port P04..P07
|(0<<0); // Pull-Up port P00..P03
P7D = (0<<7) // Not used, input
|(0<<6) // Not used, input
|(0<<5) // Not used, input
|(0<<4) // Not used, input
|(1<<3) // LED, output
|(0<<2) // Not used, input
|(0<<1) // Not used, input
|(0<<0); // Not used, input
return 1;
}
/*********************************************************************
*
* LED functions
*/
void HW_SetLED0(void) { P7 &= ~(1<<3); }
void HW_ClrLED0(void) { P7 |= (1<<3); }
void HW_ToggleLED0(void) { P7 ^= (1<<3); }
/****** EOF *********************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -