#include "USBModule_Driver.h"
|
#include "Delay.h"
|
#include "STM32U.h"
|
#include "TFT_Driver.h"
|
#include "Define.h"
|
#include "DS1302_Driver.h"
|
#include <string.h>
|
#include <avr/wdt.h>
|
#include "CRC16.h"
|
#include "SAMD21U.h"
|
|
static unsigned char s_UDiskType = Def_UDisk_Ch376;
|
unsigned char countbak = 0;
|
|
unsigned char ReadUDiskType(void)
|
{
|
unsigned char VerCMD[8] = {0x57,0xAB,0x01,0x04,0x00,0x00,0x00,0x00};
|
|
unsigned int crc = CalCRC16(&VerCMD[2], 4);
|
VerCMD[6] = crc&255;
|
VerCMD[7] = crc>>8;
|
|
Config_M64USART1(1152);
|
Delay_MS(1);
|
|
unsigned char i = 5;
|
while(i)
|
{
|
SendSTR_M64USART1( VerCMD, 8 );
|
s_UDiskType = ReceiveByte_M64USART2();
|
if(s_UDiskType != 0xff)
|
{
|
break;
|
}
|
i--;
|
wdt_reset(); //ι¹·
|
_delay_ms(100);
|
}
|
// PrintValue(0, 0, i, " ", 16, 300, 300, blue, white);
|
countbak = i;
|
|
if((s_UDiskType & 0xc0)==0x80)
|
s_UDiskType = Def_UDisk_STM32U;
|
else if((s_UDiskType & 0xc0)==0x40)
|
s_UDiskType = Def_UDisk_Ch376;
|
else
|
s_UDiskType = Def_UDisk_SAMD21U;
|
|
|
return s_UDiskType;
|
}
|
|
unsigned char getUDiskType(void)
|
{
|
return s_UDiskType;
|
}
|
|
unsigned char mInitCHSTM32UDisk(void)
|
{
|
unsigned char Tab[6] = {0x57,0xAB,0x06,0x04,0x00,0x00};
|
unsigned char temp;
|
|
SendSTR_M64USART1( Tab, 6 );
|
temp = ReceiveByte_M64USART1();
|
|
if(0xFB == temp)
|
return pdTRUE;
|
|
return pdFALSE;
|
}
|
|
unsigned char saveSTM32UDiskBaund(unsigned short baund)
|
{
|
unsigned char Tab[6] = {0x57,0xAB,0x02,0x04,0xCC,0x03};
|
unsigned char temp=0;
|
|
if(96 == baund)
|
{
|
Tab[4] = 0xB2;
|
Tab[5] = 0x02;
|
}
|
else if(192 == baund)
|
{
|
Tab[4] = 0xD9;
|
Tab[5] = 0x02;
|
}
|
else if(576 == baund)
|
{
|
Tab[4] = 0x98;
|
Tab[5] = 0x03;
|
}
|
else if(1152 == baund)
|
{
|
Tab[4] = 0xCC;
|
Tab[5] = 0x03;
|
}
|
|
SendSTR_M64USART1( Tab, 6 );
|
temp = ReceiveByte_M64USART1();
|
|
if(0x51 == temp)
|
return pdTRUE;
|
|
return pdFALSE;
|
}
|
|
unsigned char checkDiskConnect(void)
|
{
|
unsigned char Tab[13] = {0x57,0xAB,0x30,0x0A,0x00,0x00};
|
unsigned char temp = 0;
|
Date_Time mDateTime;
|
GetDateTime(&mDateTime);
|
//PrintTime(&mDateTime, ':', YYMDHMS,0,0, blue, white);
|
|
Tab[6] = 20+mDateTime.year;//µ±Ç°Äê·Ý-1980 20´ú±í2000Äê
|
Tab[7] = mDateTime.month; //1ÔÂ
|
Tab[8] = mDateTime.day; //1ÈÕ
|
Tab[9] = mDateTime.hour; //1ʱ
|
Tab[10] = mDateTime.minute; //1·Ö
|
Tab[11] = mDateTime.second; //1Ãë
|
|
SendSTR_M64USART1( Tab, 12 );
|
|
temp = ReceiveByte_M64USART1();
|
|
if(0x15 == temp)
|
return pdTRUE;
|
|
return pdFALSE;
|
}
|
|
unsigned char STM32U_creatFile(unsigned char *pLongName, unsigned short length)
|
{
|
unsigned char LongNameBuf[128] = { 0x57,0xAB,0x34,0x13,0x0F,0x00,
|
'2',':','\\','F',
|
'2','0','1','6',
|
'-','0','1',
|
'-','1','9',0x00,
|
0x20,0x31,0x34,0x3A,0x33,0x32,0x3A,0x30,0x30,0x2E,
|
0x46,0x42,0x4F,0x00};
|
unsigned char temp=66;
|
|
LongNameBuf[3] = (length+3) + 4;
|
LongNameBuf[4] = (length+3) % 256;
|
LongNameBuf[5] = (length+3) / 256;
|
|
memcpy(&LongNameBuf[9], (char*)pLongName, length);
|
|
SendSTR_M64USART1( LongNameBuf, length+9 );
|
temp = ReceiveByte_M64USART1();
|
|
|
if( 0 == temp )
|
{
|
STM32U_closeFile();////2016-4-11ÐÞ¸Ä
|
return pdTRUE;
|
}
|
|
return pdFALSE;
|
}
|
|
unsigned char STM32U_OpenFile(unsigned char *pLongName, unsigned short length)
|
{
|
unsigned char LongNameBuf[128] = { 0x57,0xAB,0x34,0x13,0x0F,0x00,
|
'2',':','\\','F',
|
'2','0','1','6',
|
'-','0','1',
|
'-','1','9',0x00,
|
0x20,0x31,0x34,0x3A,0x33,0x32,0x3A,0x30,0x30,0x2E,
|
0x46,0x42,0x4F,0x00};
|
unsigned char temp=66;
|
|
LongNameBuf[3] = (length+3) + 4;
|
LongNameBuf[4] = (length+3) % 256;
|
LongNameBuf[5] = (length+3) / 256;
|
|
memcpy(&LongNameBuf[9], pLongName, length);
|
|
SendSTR_M64USART1( LongNameBuf, length+9 );
|
|
temp = ReceiveByte_M64USART1();
|
|
if( 0 == temp )
|
return pdTRUE;
|
|
return pdFALSE;
|
}
|
|
unsigned char STM32U_closeFile(void)
|
{
|
unsigned char Tab[6]={0x57,0xAB,0x36,0x04,0x00,0x00};
|
unsigned char temp = 66;
|
|
SendSTR_M64USART1( Tab, 6 );
|
temp = ReceiveByte_M64USART1();
|
|
if( 0 == temp )
|
return pdTRUE;
|
|
return pdFALSE;
|
}
|
|
unsigned char creatFileManage(unsigned char *pLongName, unsigned short length)
|
{
|
unsigned char temp = pdTRUE;
|
Config_M64USART1(1152);
|
Delay_MS(1);
|
|
if( pdFALSE == mInitCHSTM32UDisk() ) //ÊÇ·ñ½¨Á¢Í¨ÐÅ
|
{
|
Config_M64USART1(192);
|
return 100;
|
}
|
Delay_MS(1);
|
if( pdFALSE == checkDiskConnect() ) //Á´½ÓUÅÌ
|
{
|
Config_M64USART1(192);
|
return 101;
|
}
|
Delay_MS(1);
|
if( pdFALSE == STM32U_creatFile(pLongName, length) )
|
{
|
Config_M64USART1(192);
|
return 102;
|
}
|
Delay_MS(10);
|
if( pdFALSE == STM32U_OpenFile(pLongName, length) )
|
{
|
Config_M64USART1(192);
|
return 103;
|
}
|
Delay_MS(1000);
|
wdt_reset(); //ι¹·
|
/*STM32U_writeFile(&temp,1);
|
|
Delay_MS(150);
|
if( pdFALSE == STM32U_closeFile() )
|
{
|
Config_M64USART1(192);
|
return 103;
|
}*/
|
|
return temp;
|
}
|
|
unsigned char STM32U_writeFile(volatile void *data, unsigned short length)
|
{
|
unsigned short temp = 8;
|
unsigned char Tab[600] = { 0x57,0xAB,0x4C,0x04,0x08,0x00,
|
0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38};
|
|
Tab[4] = length % 256;
|
Tab[5] = length / 256;
|
|
memcpy(&Tab[6], (unsigned char*)data, length);
|
|
SendSTR_M64USART1( Tab, 6 );
|
_delay_ms(10);
|
SendSTR_M64USART1( &Tab[6], length );
|
|
temp = ReceiveByte_M64USART1();
|
temp = temp+256*ReceiveByte_M64USART1();
|
|
//PrintValue(0, 0, temp, "C", 16, 0, 24, blue, red);
|
_delay_ms(5);
|
|
if( length == temp )
|
return pdTRUE;
|
|
return pdFALSE;
|
}
|