亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? main_lpcusbboot.c

?? NXP(原飛利浦)的LPC214X系列ARM上的USB在系統(tǒng)升級的源代碼,極力推薦!!開發(fā)者主頁: http://www.simonqian.com/en/LPCUSBBoot/
?? C
?? 第 1 頁 / 共 2 頁
字號:
/*
	LPC ISP protocol on a Serial Interface implemented on USB CDC class.
	This file is rewrited from main_serial.c
*/


#include <string.h>			// memcpy

#include "type.h"
#include "usbdebug.h"

#include "iap.h"

#include "console.h"
#include "usbapi.h"
#include "startup.h"

#include "serial_fifo.h"

#include "lpcisp.h"

#include "uu_codec.h"

#ifdef DEBUG
#define DBG_LEVEL				2
#else
#define DBG_LEVEL				0
#endif



// Chip related
#define LPCARM_MaxSect			26
#define LPCARM_MemTop			0x40008000
#define LPCARM_FlashSize		(512 * 1024)
// Bootloader related
#define Boot_Position_TOP		0		// bootloader located in the top of Flash(from 0x00000000)
#define Boot_Position_BOTTOM	1		// bootloader located in the bottom of Flash
#define Boot_Position			Boot_Position_TOP
#define Boot_Sect_Begin			0
#define Boot_Sect_Num			4
#define BOOT_START				0x00000000
#define APP_START				0x00004000





#define BAUD_RATE				115200

#define INT_IN_EP				0x81
#define BULK_OUT_EP				0x02
#define BULK_IN_EP				0x82

#define MAX_PACKET_SIZE			MAX_PACKET_SIZE0

#define CMD_LINE_LEN			MAX_PACKET_SIZE0

#define LE_WORD(x)				((x)&0xFF),((x)>>8)

// CDC definitions
#define CS_INTERFACE			0x24
#define CS_ENDPOINT				0x25

#define	SET_LINE_CODING			0x20
#define	GET_LINE_CODING			0x21
#define	SET_CONTROL_LINE_STATE	0x22

#define LPCARM_Unlock_Code		0x5A5A

// Boot Sector, MUST be protected
#define Boot_Sect_End			(Boot_Sect_Begin + Boot_Sect_Num - 1)

#if Boot_Position == Boot_Position_TOP
#	define APP_END				LPCARM_FlashSize
#	undef Boot_Sect_Begin
#	define Boot_Sect_Begin		0
#elif Boot_Position == Boot_Position_BOTTOM
#	define APP_END				BOOT_START
#else
#error "Boot_Position MUST be either Boot_Position_TOP or Boot_Position_BOTTOM"
#endif

// check
#if Boot_Sect_Num < 1
#error "Please give me some Flash for the Bootloader"
#endif
#if (Boot_Sect_End > LPCARM_MaxSect) || (APP_START >= LPCARM_FlashSize)
#error "R U kidding?"
#endif

// data structure for GET_LINE_CODING / SET_LINE_CODING class requests
typedef struct {
	U32		dwDTERate;
	U8		bCharFormat;
	U8		bParityType;
	U8		bDataBits;
} TLineCoding;

static TLineCoding LineCoding = {115200, 0, 0, 8};
static U8 abBulkBuf[MAX_PACKET_SIZE];
static U8 abClassReqData[8];

static U8 txdata[VCOM_FIFO_SIZE];
static U8 rxdata[VCOM_FIFO_SIZE];

static fifo_t txfifo;
static fifo_t rxfifo;

#define Sync_Mode_WaitSync		0
#define Sync_Mode_SendSync		1
#define Sync_Mode_WaitOSC		2
#define Sync_Mode_ReadOSC		3
#define Sync_Mode_Synced		4
static int Sync_Mode;
static int bUnlocked;
static int bChipEncrypted;

static int CDC_enable_echo = 0;

static const U8 abDescriptors[] = {

// device descriptor
	0x12,
	DESC_DEVICE,
	LE_WORD(0x0101),			// bcdUSB
	0x02,						// bDeviceClass
	0x00,						// bDeviceSubClass
	0x00,						// bDeviceProtocol
	MAX_PACKET_SIZE0,			// bMaxPacketSize
	LE_WORD(0xFFFF),			// idVendor
	LE_WORD(0x0005),			// idProduct
	LE_WORD(0x0100),			// bcdDevice
	0x01,						// iManufacturer
	0x02,						// iProduct
	0x03,						// iSerialNumber
	0x01,						// bNumConfigurations

// configuration descriptor
	0x09,
	DESC_CONFIGURATION,
	LE_WORD(67),				// wTotalLength
	0x02,						// bNumInterfaces
	0x01,						// bConfigurationValue
	0x00,						// iConfiguration
	0xC0,						// bmAttributes
	0x32,						// bMaxPower
// control class interface
	0x09,
	DESC_INTERFACE,
	0x00,						// bInterfaceNumber
	0x00,						// bAlternateSetting
	0x01,						// bNumEndPoints
	0x02,						// bInterfaceClass
	0x02,						// bInterfaceSubClass
	0x01,						// bInterfaceProtocol, linux requires value of 1 for the cdc_acm module
	0x00,						// iInterface
// header functional descriptor
	0x05,
	CS_INTERFACE,
	0x00,
	LE_WORD(0x0110),
// call management functional descriptor
	0x05,
	CS_INTERFACE,
	0x01,
	0x01,						// bmCapabilities = device handles call management
	0x01,						// bDataInterface
// ACM functional descriptor
	0x04,
	CS_INTERFACE,
	0x02,
	0x02,						// bmCapabilities
// union functional descriptor
	0x05,
	CS_INTERFACE,
	0x06,
	0x00,						// bMasterInterface
	0x01,						// bSlaveInterface0
// notification EP
	0x07,
	DESC_ENDPOINT,
	INT_IN_EP,					// bEndpointAddress
	0x03,						// bmAttributes = intr
	LE_WORD(8),					// wMaxPacketSize
	0x0A,						// bInterval
// data class interface descriptor
	0x09,
	DESC_INTERFACE,
	0x01,						// bInterfaceNumber
	0x00,						// bAlternateSetting
	0x02,						// bNumEndPoints
	0x0A,						// bInterfaceClass = data
	0x00,						// bInterfaceSubClass
	0x00,						// bInterfaceProtocol
	0x00,						// iInterface
// data EP OUT
	0x07,
	DESC_ENDPOINT,
	BULK_OUT_EP,				// bEndpointAddress
	0x02,						// bmAttributes = bulk
	LE_WORD(MAX_PACKET_SIZE),	// wMaxPacketSize
	0x00,						// bInterval
// data EP in
	0x07,
	DESC_ENDPOINT,
	BULK_IN_EP,					// bEndpointAddress
	0x02,						// bmAttributes = bulk
	LE_WORD(MAX_PACKET_SIZE),	// wMaxPacketSize
	0x00,						// bInterval
	
	// string descriptors
	0x04,
	DESC_STRING,
	LE_WORD(0x0409),

	0x0E,
	DESC_STRING,
	'L', 0, 'P', 0, 'C', 0, 'U', 0, 'S', 0, 'B', 0,

	0x14,
	DESC_STRING,
	'U', 0, 'S', 0, 'B', 0, 'S', 0, 'e', 0, 'r', 0, 'i', 0, 'a', 0, 'l', 0,

	0x12,
	DESC_STRING,
	'D', 0, 'E', 0, 'A', 0, 'D', 0, 'C', 0, '0', 0, 'D', 0, 'E', 0,

// terminating zero
	0
};


/**
	Local function to handle bulk data
		
	@param [in] bEP
	@param [in] bEPStatus
 */
static void BulkIO(U8 bEP, U8 bEPStatus)
{
	int i, iLen;

	bEPStatus = bEPStatus;

	if(bEP & 0x80)
	{
		// Bulk IN
		if (fifo_avail(&txfifo) == 0) {
			// no more data, disable further NAK interrupts until next USB frame
			USBHwNakIntEnable(0);
			return;
		}

		// get bytes from transmit FIFO into intermediate buffer
		for (i = 0; i < MAX_PACKET_SIZE; i++) {
			if (!fifo_get(&txfifo, &abBulkBuf[i])) {
				break;
			}
		}
		iLen = i;
	
		// send over USB
		if (iLen > 0) {
			USBHwEPWrite(bEP, abBulkBuf, iLen);
		}
	}
	else
	{
		// Bulk OUT
		if (fifo_free(&rxfifo) < MAX_PACKET_SIZE) {
			// may not fit into fifo
			return;
		}

		// get data from USB into intermediate buffer
		iLen = USBHwEPRead(bEP, abBulkBuf, sizeof(abBulkBuf));
		for (i = 0; i < iLen; i++) {
			// put into FIFO
			if (!fifo_put(&rxfifo, abBulkBuf[i])) {
				// overflow... :(
				ASSERT(FALSE);
				break;
			}
		}
	}
}


/**
	Local function to handle the USB-CDC class requests
		
	@param [in] pSetup
	@param [out] piLen
	@param [out] ppbData
 */
static BOOL HandleClassRequest(TSetupPacket *pSetup, int *piLen, U8 **ppbData)
{
	switch (pSetup->bRequest) {

	// set line coding
	case SET_LINE_CODING:
#if DBG_LEVEL >= 3
DBG("SET_LINE_CODING\n");
#endif
		memcpy((U8 *)&LineCoding, *ppbData, 7);
		*piLen = 7;
#if DBG_LEVEL >= 3
DBG("dwDTERate=%u, bCharFormat=%u, bParityType=%u, bDataBits=%u\n",
	LineCoding.dwDTERate,
	LineCoding.bCharFormat,
	LineCoding.bParityType,
	LineCoding.bDataBits);
#endif

		Sync_Mode = Sync_Mode_WaitSync;
		CDC_enable_echo = 0;
		break;

	// get line coding
	case GET_LINE_CODING:
#if DBG_LEVEL >= 3
DBG("GET_LINE_CODING\n");
#endif
		*ppbData = (U8 *)&LineCoding;
		*piLen = 7;
		break;

	// set control line state
	case SET_CONTROL_LINE_STATE:
		// bit0 = DTR, bit = RTS
#if DBG_LEVEL >= 3
DBG("SET_CONTROL_LINE_STATE %X\n", pSetup->wValue);
#endif
		break;

	default:
		return FALSE;
	}
	return TRUE;
}


/**
	Initialises the VCOM port.
	Call this function before using VCOM_putchar or VCOM_getchar
 */
void VCOM_init(void)
{
	fifo_init(&txfifo, txdata);
	fifo_init(&rxfifo, rxdata);
}


/**
	Writes one character to VCOM port
	
	@param [in] c character to write
	@returns character written
 */
void VCOM_putchar(int c)
{
	while(!fifo_put(&txfifo, c))
		USBHwISR();

#if DBG_LEVEL >= 3
	DBG("putchar: 0x%02X\n", c);
#endif
}


/**
	Writes one string to VCOM port
	
	@param [in] s string to write
 */
void VCOM_putstr(char *s)
{
	while(*s)
		VCOM_putchar(*s++);
}


/**
	Writes one line to VCOM port
	
	@param [in] s string to write
 */
void VCOM_putln(char *s)
{
#if DBG_LEVEL >= 2
	DBG("putln: %s\n", s);
#endif

	VCOM_putstr(s);
	VCOM_putstr("\r\n");
}



/**
	Reads one character from VCOM port
	
	@returns character read
 */
int VCOM_getchar(void)
{
	U8 c;

	while (!fifo_get(&rxfifo, &c))
		USBHwISR();

#if DBG_LEVEL >= 3
	DBG("getchar: 0x%02X\n", c);
#endif

	if (CDC_enable_echo)
		VCOM_putchar(c);

	return c;
}


/**
	Reads one line from VCOM port

	@param [in] s buff to store data
	@param [in] iLen max length of data
	@returns length of string(\r\n is not included)
 */
int VCOM_getln(char *s, int iLen)
{
	int idx = 0;

	while ((*(s + idx) = VCOM_getchar()) != '\r') {
		if(Sync_Mode == Sync_Mode_WaitSync) {
			if (*(s + idx) == '?')
				Sync_Mode = Sync_Mode_SendSync;
			return 0;
		}
		if (*(s + idx) == 0x1B) {
			idx = 0;
#if DBG_LEVEL >= 2
			DBG("Aborted\n");
#endif
			continue;
		}
		if (idx < (iLen - 1))
			idx++;
		else
			return 0;
	}
	if (VCOM_getchar() != '\n') {
		return 0;
	}
	*(s + idx) = 0;

#if DBG_LEVEL >= 2
	DBG("getln: %s\n", s);
#endif

	return idx;
}


static void USBFrameHandler(U16 wFrame)
{
	wFrame = wFrame;

	if (fifo_avail(&txfifo) > 0) {
		// data available, enable NAK interrupt on bulk in
		USBHwNakIntEnable(INACK_BI);
	}
}












static int getNum(const char *s, U32 *num, char cEnd) {
	int i, ret = 0;
	U32 r = 1;

	*num = 0;

	while ((s[ret] != cEnd) && (s[ret] != '\0')) {
		ret++;
	}
	if (s[ret] != cEnd) {
		return 0;
	}

	i = ret - 1;
	while (i >= 0) {
		if ((s[i] < '0') || (s[i] > '9')) {
			return 0;
		}

		*num += (s[i] - '0') * r;
		r *= 10;
		i--;
	}

	return ret;
}


static int getPara(const char *s, U32 *Para, char cEnd) {
	if (s[0] != ' ') {
		return 0;
	}

	return getNum(s + 1, Para, cEnd) + 1;
}

static int parseParas(const char *s, int num, U32 *para, char cEnd) {
	int i, tmp, p = 0;

	for (i=0 ; i<num; i++) {
		if (i == (num - 1))
			tmp = getPara(&s[p], &para[i], cEnd);
		else
			tmp = getPara(&s[p], &para[i], ' ');
		p += tmp;
		if (!tmp)
			return 0;
	}

	return p;
}






int sprintf(char *out, const char *format, ...);
static U32 UU_chksum_val;
static int UU_getdata(int iLen, char *buf) {
	int i = 0, j, k,l = 0, n, resend_addr = 0;
	U32 chk_sum;
	char tmp[11], tmp_code[3];

	UU_chksum_val = 0;
	while(i < iLen) {
		n = (VCOM_getchar() - 0x20) & 0x3F;
		if((n < 1) || (n > 45))
			return 0;

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
日本中文字幕一区二区有限公司| 波多野结衣中文字幕一区二区三区| 激情都市一区二区| 91免费版pro下载短视频| 日韩情涩欧美日韩视频| 一区二区三区在线视频免费| 国产综合久久久久久鬼色| 在线观看视频一区二区| 亚洲国产成人在线| 韩国理伦片一区二区三区在线播放| 色综合网色综合| 国产精品五月天| 狠狠色丁香久久婷婷综合_中| 欧美性色黄大片| 亚洲色欲色欲www在线观看| 国产黑丝在线一区二区三区| 欧美电影精品一区二区| 亚洲国产成人91porn| 99久久综合色| 国产精品午夜春色av| 国产成人精品一区二| 欧美成人一区二区三区在线观看| 亚洲国产精品久久久久秋霞影院| 91在线免费看| 亚洲精品免费一二三区| 97精品视频在线观看自产线路二| 国产精品天天看| www.欧美日韩| 亚洲免费毛片网站| 91丨九色porny丨蝌蚪| 亚洲视频一区二区在线| 99久久精品国产网站| 国产精品国产三级国产三级人妇 | 亚洲精品在线免费观看视频| 欧美aaa在线| 精品国产a毛片| 国产在线日韩欧美| 国产精品视频九色porn| 波多野结衣亚洲| 亚洲摸摸操操av| 在线观看欧美日本| 日韩国产欧美视频| 精品国产乱码久久久久久闺蜜| 久久精品国产免费看久久精品| 精品久久人人做人人爽| 国产丶欧美丶日本不卡视频| 国产精品色眯眯| 91国偷自产一区二区三区观看| 一区二区欧美国产| 欧美一区二区三区电影| 久草精品在线观看| 国产精品毛片久久久久久久| 91在线你懂得| 日本不卡高清视频| 国产日韩精品一区| 色偷偷久久人人79超碰人人澡| 亚洲午夜免费福利视频| 欧美变态口味重另类| 波多野结衣亚洲| 亚洲成人免费视频| 国产性天天综合网| 欧美系列一区二区| 国产精品一区二区在线观看不卡| 亚洲同性同志一二三专区| 欧美精品 国产精品| 国产成人啪免费观看软件| 一区2区3区在线看| 精品国产亚洲在线| 欧美性受xxxx黑人xyx性爽| 美腿丝袜亚洲三区| 亚洲美腿欧美偷拍| 久久亚洲精品小早川怜子| 在线一区二区观看| 国产成人a级片| 日本91福利区| 亚洲综合一区二区三区| 精品国产一区二区精华| 在线免费观看视频一区| 国产黑丝在线一区二区三区| 图片区小说区国产精品视频| 国产精品美日韩| 日韩一区二区三区观看| 色偷偷久久人人79超碰人人澡| 久久国产精品色| 亚洲国产人成综合网站| 中文字幕国产一区二区| www成人在线观看| 91精品国产综合久久福利| 欧美性三三影院| 91影视在线播放| 成人看片黄a免费看在线| 激情伊人五月天久久综合| 亚洲二区在线视频| 亚洲精品国产第一综合99久久| 国产视频一区二区在线观看| 91精品国产欧美一区二区18| 欧美性高清videossexo| 91免费国产在线| 本田岬高潮一区二区三区| 国产精品一二三区在线| 九九九久久久精品| 日本不卡一二三区黄网| 亚洲成精国产精品女| 亚洲综合一区二区三区| 亚洲少妇最新在线视频| 亚洲图片欧美激情| 亚洲色图19p| 日韩一区欧美小说| 亚洲女爱视频在线| 亚洲视频一二区| 亚洲欧美一区二区三区国产精品 | 26uuu国产一区二区三区| 日韩欧美在线观看一区二区三区| 欧美日韩精品系列| 欧美精品1区2区| 日韩欧美中文字幕公布| 欧美一级久久久久久久大片| 91麻豆精品国产无毒不卡在线观看| 欧美日韩国产色站一区二区三区| 欧美亚洲国产一卡| 777奇米四色成人影色区| 91精品视频网| xfplay精品久久| 亚洲国产成人私人影院tom| 国产精品美女视频| 亚洲视频一区在线观看| 艳妇臀荡乳欲伦亚洲一区| 亚洲一级片在线观看| 日韩主播视频在线| 久久99国产精品尤物| 国产精品一区二区在线播放| 成a人片亚洲日本久久| 欧美中文字幕一区二区三区| 在线播放中文字幕一区| 久久久久久久久97黄色工厂| 国产精品久久久久精k8| 亚洲图片有声小说| 国产一区在线看| 91麻豆自制传媒国产之光| 欧美高清视频不卡网| 国产欧美一区二区三区在线老狼 | 国产亚洲一区二区三区| 18成人在线视频| 日本欧美加勒比视频| 国产不卡高清在线观看视频| 一本久久综合亚洲鲁鲁五月天| 欧美日韩高清在线播放| 精品欧美一区二区在线观看| 一色桃子久久精品亚洲| 五月天丁香久久| 成人午夜视频福利| 在线播放日韩导航| 亚洲国产精华液网站w| 午夜精品aaa| 成人性生交大片免费看中文| 欧美日韩精品三区| 久久精品亚洲一区二区三区浴池| 综合色中文字幕| 国产综合久久久久影院| 欧美性色黄大片手机版| 欧美国产精品劲爆| 美国av一区二区| 欧美视频一区在线| 亚洲欧洲精品天堂一级| 久久99在线观看| 欧美性受xxxx黑人xyx性爽| 欧美高清在线一区二区| 日本欧美加勒比视频| 欧美性一区二区| 中文字幕一区在线观看| 狠狠狠色丁香婷婷综合激情| 欧美日韩精品一区二区天天拍小说| 欧美国产欧美综合| 国产综合一区二区| 91精品国产品国语在线不卡| 一区二区三区日韩| 丁香一区二区三区| 精品久久国产97色综合| 午夜激情一区二区三区| 日本乱码高清不卡字幕| 亚洲国产激情av| 国产米奇在线777精品观看| 欧美一区二区免费观在线| 亚洲日本在线a| www.亚洲精品| 中文字幕在线一区二区三区| 麻豆视频观看网址久久| 337p亚洲精品色噜噜噜| 亚洲国产你懂的| 欧美色图免费看| 一区二区三区四区中文字幕| 91蜜桃在线免费视频| 亚洲欧美日韩久久| 99在线精品观看| 亚洲日本成人在线观看| 91丨porny丨蝌蚪视频| ●精品国产综合乱码久久久久| 国产精品小仙女| 中文字幕在线观看不卡视频| 不卡在线视频中文字幕|