⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 usb_utlities.c

📁 文件包含了开发motorola mc9s12uf32单片机一些源码。  1、USB device 实现  2、CF卡读取  3、SD卡读取  4、ATA硬盘读取
💻 C
字号:
/******************************************************************************
*                                                  
*  (c) copyright Freescale Semiconductor Hong Kong Ltd 2004
*  ALL RIGHTS RESERVED
*                                                                       
*******************************************************************************  
** THIS  CODE IS ONLY INTENDED AS AN EXAMPLE FOR DEMONSTRATING THE FREESCALE **
** MICROCONTROLLERS.  IT  HAS ONLY BEEN GIVEN A MIMIMUM LEVEL OF TEST. IT IS **
** PROVIDED  'AS  SEEN'  WITH  NO  GUARANTEES  AND  NO  PROMISE  OF SUPPORT. **
*******************************************************************************  
*                                                                           
* FILE:        usb_utilites.c	 REVISION 0.1
*  
* DESCRIPTION: This module handles the USB state machine & command processor
*              applicaton tasks for the system
*
* NOTES:       All modules remain at their reset addresses
*                                                  
* UPDATED HISTORY:
*
* REV   YYYY.MM.DD  AUTHOR        DESCRIPTION OF CHANGE
* ---   ----------  ------        --------------------- 
* 0.0   2003.03.01  Vincent Ko    Initial version
* 0.1   2004.04.12  Derek Lau     Demo version
*
******************************************************************************/                                                                        
/* Freescale  is  not  obligated  to  provide  any  support, upgrades or new */
/* releases  of  the Software. Freescale may make changes to the Software at */
/* any time, without any obligation to notify or provide updated versions of */
/* the  Software  to you. Freescale expressly disclaims any warranty for the */
/* Software.  The  Software is provided as is, without warranty of any kind, */
/* either  express  or  implied,  including, without limitation, the implied */
/* warranties  of  merchantability,  fitness  for  a  particular purpose, or */
/* non-infringement.  You  assume  the entire risk arising out of the use or */
/* performance of the Software, or any systems you design using the software */
/* (if  any).  Nothing  may  be construed as a warranty or representation by */
/* Freescale  that  the  Software  or  any derivative work developed with or */
/* incorporating  the  Software  will  be  free  from  infringement  of  the */
/* intellectual property rights of third parties. In no event will Freescale */
/* be  liable,  whether in contract, tort, or otherwise, for any incidental, */
/* special,  indirect, consequential or punitive damages, including, but not */
/* limited  to,  damages  for  any loss of use, loss of time, inconvenience, */
/* commercial loss, or lost profits, savings, or revenues to the full extent */
/* such  may be disclaimed by law. The Software is not fault tolerant and is */
/* not  designed,  manufactured  or  intended by Freescale for incorporation */
/* into  products intended for use or resale in on-line control equipment in */
/* hazardous, dangerous to life or potentially life-threatening environments */
/* requiring  fail-safe  performance,  such  as  in the operation of nuclear */
/* facilities,  aircraft  navigation  or  communication systems, air traffic */
/* control,  direct  life  support machines or weapons systems, in which the */
/* failure  of  products  could  lead  directly to death, personal injury or */
/* severe  physical  or  environmental  damage  (High  Risk Activities). You */
/* specifically  represent and warrant that you will not use the Software or */
/* any  derivative  work of the Software for High Risk Activities.           */
/* Freescale  and the Freescale logos are registered trademarks of Freescale */
/* Semiconductor Inc.                                                        */ 
/*****************************************************************************/

#include	"FreescaleDef.h"			// Get my definitions (Constants & Macros)
#include	"UF32reg.h"			// Get the UF32 registers.
#include	"mk_extern.h"		// Get Mini-Kernel global prototypes
#include	"usb_includes.h"	// Get USB module Configuration
#include	"usb_extern.h"		// Get External variable


// code is placed in the main code area.
#pragma CODE_SEG	DEFAULT
//#pragma CODE_SEG	CodeForceToPseudo_ROM2									 

// ===========================================================
//   USB_StallEP() -
//  
//		STALL Endpoint #.
//		
//
// ===========================================================
void USB_StallEP(muint8 PhyEPNo)
{
	switch (PhyEPNo)
	{
		case PHY5:
			mUSBSetBit(STALL, UEPCSR5A);	// Stall Endpoint 5
			break;
		case PHY4:
			mUSBSetBit(STALL, UEPCSR4A);	// Stall Endpoint 4
			break;
		case PHY1IN:
			mUSBSetBit(STALL, UEPCSR0); 	// Stall Endpoint 0 IN
			break;
		case PHY1OUT:
			mUSBSetBit(STALL, UEPCSR1); 	// Stall Endpoint 0 OUT
			break;
		case PHY2:
			mUSBSetBit(STALL, UEPCSR2); 	// Stall Endpoint 2
			break;
		case PHY3:
			mUSBSetBit(STALL, UEPCSR3);	// Stall Endpoint 3
			break;
		case PHY6:
			mUSBSetBit(STALL, UEPCSR6);	// Stall Endpoint 6
			break;
		default:
			break;				
	}
}

// ===========================================================
//   USB_UnStallEP() -
//  
//		UNSTALL Endpoint #.
//		
//
// ===========================================================
void USB_UnStallEP(muint8 PhyEPNo) {
		switch (PhyEPNo) {
			case PHY1IN:
				mUSBClearBit(STALL, UEPCSR0); 	// Stall Endpoint 0 IN
				break;
			case PHY1OUT:
				mUSBClearBit(STALL, UEPCSR1); 	// Stall Endpoint 0 OUT
				break;
			case PHY2:
				mUSBClearBit(STALL, UEPCSR2); 	// Stall Endpoint 2
				break;
			case PHY3:
				mUSBClearBit(STALL, UEPCSR3);		// Stall Endpoint 3
				break;
			case PHY4:
				mUSBClearBit(STALL, UEPCSR4A);	// Stall Endpoint 4
				break;
			case PHY5:
				mUSBClearBit(STALL, UEPCSR5A);	// Stall Endpoint 5
				break;
			case PHY6:
				mClearBit(STALL, UEPCSR6);		// Stall Endpoint 6
				break;
			default:
				break;				
			};
};

// ===========================================================
//   USB_SetControlPtr() -
//  
//		Enable Control pointer.
//		
//
// ===========================================================
volatile muint16 *USB_SetControlPtr(muint8 PhyEPNo) {
		switch (PhyEPNo) {
			case PHY1IN:
				return &UEPCSR0;		// Control via Control Status Register 0
				break;
			case PHY1OUT:
				return &UEPCSR1;		// Control via Control Status Register 1
				break;
			case PHY2:
				return &UEPCSR2;		// Control via Control Status Register 2
				break;
			case PHY3:
				return &UEPCSR3;		// Control via Control Status Register 3
				break;
			case PHY4:
				return &UEPCSR4A;		// Control via Control Status Register 4A
				break;
			case PHY5:
				return &UEPCSR5A;		// Control via Control Status Register 5A
				break;
			case PHY6:
				return &UEPCSR6;		// Control via Control Status Register 6
				break;
			default:
				return 0x0000;			// Default to nothing
				break;				
			};
};

// ===========================================================
//   USB_SetBufferPtr() -
//  
//		Enable Buffer pointer.
//		
//
// ===========================================================
volatile muint8 *USB_SetBufferPtr(muint8 PhyEPNo) {
		switch (PhyEPNo) {
			case PHY1IN:
				UEPCSELR_l = 0x10;		// Select acessing through UEPLB0
				return &UEPLB0;
				break;
			case PHY1OUT:
				UEPCSELR_l = 0x10;		// Select acessing through UEPLB1
				return &UEPLB1;
				break;
			case PHY2:
				UEPCSELR_l = 0x12;		// Select acessing through UEPLB0
				return &UEPLB0;
				break;
			case PHY3:
				UEPCSELR_l = 0x13;		// Select acessing through UEPLB0
				return &UEPLB0;
				break;
			case PHY4:
				return &QC1DR_H;			// Select QUE channel 1
				break;
			case PHY5:
				return &QC2DR_H;			// Select QUE channel 2
				break;
			case PHY6:
				UEPCSELR_l = 0x16;		// Select acessing through UEPLB0
				return &UEPLB0;
				break;
			default:
				UEPCSELR_l = 0x10;		// PHY1IN default to UEPLB0
				return &UEPLB0;			// PHY1OUT default to UEPLB1
				break;				
			};
};

// ===========================================================
//   USB_Move2LocalBuffer(FR_ptr, TO_ptr, Len) -
//  
//		Move data with Length "len" from pointer FR_ptr to 
//		Local buffer pointer TO_ptr.
//
// ===========================================================
void USB_Move2LocalBuffer(muint8 *FR_ptr, muint8 *TO_ptr, muint16 Len) {

	muint16 i=0;
	
	for (i=0; i<Len; i=i+2) 
	{
		#ifdef	_kUF32isMPW_
			*(TO_ptr+i+1) = *(FR_ptr+i);
			*(TO_ptr+i) = *(FR_ptr+i+1);			// H byte and L byte is swapped
		#else
			*(TO_ptr+i) = *(FR_ptr+i);
			*(TO_ptr+i+1) = *(FR_ptr+i+1);
		#endif		
	};
};

// ===========================================================
//   USB_Move2QUE3(FR_ptr, Len) -
//  
//		Move data with Length "len" from pointer FR_ptr to 
//		QUE1 FIFO.
//
// ===========================================================
void USB_Move2QUE3(muint8 *FR_ptr, muint16 Len) {

	muint16 i=0;
	
	for (i=0; i<Len; i=i+2) {

		QC3DR = ( (muint16) *(FR_ptr+i) << 8) | *(FR_ptr+i+1);
	};
};

// ===========================================================
//   USB_MinLen -
//  
//		
//
// ===========================================================
muint16	USB_GetMin(muint16 Value1, muint16 Value2)
{
	if (Value1 > Value2)
		return(Value2);
	else
		return(Value1);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -