This commit is contained in:
2026-04-23 10:50:18 +08:00
commit a436fda935
844 changed files with 272643 additions and 0 deletions

339
IAPV1.1/Driver/BC25/BC25.c Normal file
View File

@ -0,0 +1,339 @@
#include "general_type.h"
#include "bc25.h"
#include "delay.h"
#include "bsp.h"
BC25 BC25_Status;
void BC25CTR_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;
GPIO_Init(GPIOA, &GPIO_InitStructure);
PWRKEY_L;
}
//ģ<><EFBFBD><E9BFAA>
void BC25_PWRKEY_ON(void)
{
GPIO_SetBits(GPIOA, GPIO_Pin_1);
delay_ms(200);
delay_ms(1000);
GPIO_ResetBits(GPIOA, GPIO_Pin_1);
}
void BC25_POWERON(void)
{
PWR_CTRLBC25_H;
}
void BC25_POWEROFF(void)
{
PWR_CTRLBC25_L;
}
u8 BC25_Init(void)
{
u8 i=0;
char *strx;
BC25CTR_Init();
BC25_POWERON();
delay_ms(1000);
BC25_PWRKEY_ON();
strx=NULL;
while((!strx)&(i<10))
{
i++;
strx=strstr((const char*)USART2_RX_BUF,"+CPIN: READY");//<2F><><EFBFBD><EFBFBD>OK
delay_ms(1000);
}
strx=NULL;
while((!strx)&(i<10))
{
USART2_ReceiveBuff_Clear();
printf("AT\r\n");
delay_ms(500);
strx=strstr((const char*)USART2_RX_BUF,"OK");//<2F><><EFBFBD><EFBFBD>OK
if(!strx)
{
// BC25_POWEROFF();
// delay_ms(300);
BC25_POWERON();
delay_ms(500);
BC25_PWRKEY_ON();
// delay_ms(500);
}
u5_printf("AT....\r\n");
i++;
// if(i>9)return 1;
}
printf("AT+QSELFREGISTER=1\r\n"); //<2F>Զ<EFBFBD>ע<EFBFBD><D7A2>
delay_ms(300);
printf("ATE0\r\n"); //<2F>رջ<D8B1><D5BB><EFBFBD>
delay_ms(1000);
strx=strstr((const char*)USART2_RX_BUF,(const char*)"OK");//<2F><><EFBFBD><EFBFBD>OK
printf("AT+CPSMS=0\r\n");//<2F><><EFBFBD><EFBFBD>PSM
delay_ms(1000);
strx=strstr((const char*)USART2_RX_BUF,(const char*)"OK");//<2F><><EFBFBD><EFBFBD>OK
printf("AT+CPIN=?\r\n");//<2F><><EFBFBD><EFBFBD>SIM<49><4D>
delay_ms(300);
strx=strstr((const char*)USART2_RX_BUF,(const char*)"OK");//<2F><><EFBFBD><EFBFBD>OK
if(!strx)//<2F><><EFBFBD><EFBFBD>ʧ<EFBFBD><CAA7>
{
u5_printf("AT+CPIN=fail\r\n");//<2F><><EFBFBD><EFBFBD>SIM<49><4D>
return 1;
}
USART2_ReceiveBuff_Clear();
printf("AT+CGATT?\r\n");//<2F><>ѯ<EFBFBD><D1AF><EFBFBD><EFBFBD>״̬
delay_ms(1000);
strx=strstr((const char*)USART2_RX_BUF,(const char*)"+CGATT: 1");//<2F><>1
i=0;
while((i<15)&(!strx))
{
USART2_ReceiveBuff_Clear();
printf("AT+CGATT?\r\n");//<2F><>ѯ<EFBFBD><D1AF><EFBFBD><EFBFBD>״̬
delay_ms(2000);
strx=strstr((const char*)USART2_RX_BUF,(const char*)"+CGATT: 1");//<2F><>1
i++;
}
printf("AT+CESQ\r\n");//<2F><EFBFBD><E9BFB4>ȡCSQֵ
delay_ms(300);
strx=strstr((const char*)USART2_RX_BUF,(const char*)"+CESQ");//<2F><><EFBFBD><EFBFBD>CSQ
if(strx)
{
BC25_Status.CSQ=(strx[7]-0x30)*10+(strx[8]-0x30);//<2F><>ȡCSQ
if((BC25_Status.CSQ==99)||((strx[7]-0x30)==0))//˵<><CBB5>ɨ<EFBFBD><C9A8>ʧ<EFBFBD><CAA7>
{
return 7;
}
else
{
BC25_Status.netstatus=1;
}
}
USART2_ReceiveBuff_Clear();
printf("AT+CSQ\r\n");//
delay_ms(500);
u5_printf("AT+CSQ:%s\r\n",(const char*)USART2_RX_BUF);
return 0; //<2F><>ʼ<EFBFBD><CABC><EFBFBD>ɹ<EFBFBD>
}
void BC25_CloseSocket(void)
{
char *strx;
u8 i=0;
USART2_ReceiveBuff_Clear();
printf("AT+QICLOSE=0\r\n");//<2F>ر<EFBFBD>socekt<6B><74><EFBFBD><EFBFBD>
delay_ms(500);
strx=strstr((const char*)USART2_RX_BUF,(const char*)"CLOSE OK");//<2F><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD>
while((!strx)&(i<3))
{
USART2_ReceiveBuff_Clear();
printf("AT+QICLOSE=0\r\n");//<2F>ر<EFBFBD>socekt<6B><74><EFBFBD><EFBFBD>
delay_ms(500);
strx=strstr((const char*)USART2_RX_BUF,(const char*)"CLOSE OK");//<2F><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD>
u5_printf("BC25_CloseSocket %d\r\n",i);
u5_printf("USART2_RX_BUF:%s\r\n",(const char*)USART2_RX_BUF);
i++;
}
if(strx)
{
u5_printf("BC25_CloseSocket OK");
return;
}
if(!strx)
{
USART2_ReceiveBuff_Clear();
printf("AT+QICLOSE=0\r\n");//<2F>ر<EFBFBD>socekt<6B><74><EFBFBD><EFBFBD>
delay_ms(500);
u5_printf("BC25_CloseSocket 2");
}
}
void BC25_CreateSokcet(char *ip,char *port)//<2F><><EFBFBD><EFBFBD>sokcet
{
char *strx;
u8 i=0;
USART2_ReceiveBuff_Clear();
// printf("AT+QIOPEN=1,0,\"TCP\",\"219.238.240.58\",9022,0,1\r\n");//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>TCP,<2C><><EFBFBD><EFBFBD>IP<49>Լ<EFBFBD><D4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˿ں<CBBF><DABA><EFBFBD> ,<2C><><EFBFBD><EFBFBD>ֱ<EFBFBD><D6B1><EFBFBD>³<EFBFBD><C2B3>ķ<EFBFBD>ʽ
printf("AT+QIOPEN=1,0,\"TCP\",%s,%s,0,1\r\n",Init_Data_Equipment.Bc25_Ip,Init_Data_Equipment.Bc25_Port);
delay_ms(1000);
strx=strstr((const char*)USART2_RX_BUF,(const char*)"+QIOPEN: 0,0");//<2F><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD>½<EFBFBD>ɹ<EFBFBD>
while((!strx)&(i<5))
{
BC25_CloseSocket();
delay_ms(500);
USART2_ReceiveBuff_Clear();
printf("AT+QIOPEN=1,0,\"TCP\",%s,%s,0,1\r\n",Init_Data_Equipment.Bc25_Ip,Init_Data_Equipment.Bc25_Port);//219.238.240.58 9022
delay_ms(1000);
strx=strstr((const char*)USART2_RX_BUF,(const char*)"+QIOPEN: 0,0");//<2F><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD>½<EFBFBD>ɹ<EFBFBD>
i++;
}
if(strx)
{
BC25_Status.socket=1;
u5_printf("BC25_CreateSokcet sucess\r\n");
}
if(!strx)
{
BC25_Status.socket=0;
u5_printf("BC25_CreateSokcet fail\r\n");
}
}
/*
<EFBFBD><EFBFBD><EFBFBD>ܣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģʽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
int len <20><><EFBFBD>ݳ<EFBFBD><DDB3><EFBFBD>
char *data <20><><EFBFBD><EFBFBD>
*/
void BC25_Senddata(int len,char *data)
{
char *strx;
char lens[5]={'\0'};
u8 times=0;
USART2_ReceiveBuff_Clear();
sprintf(lens,"%d",len);
u5_printf("BC25_Senddata_lens:%s\r\n",lens);
printf("AT+QISEND=0,%s,\"%s\"\r\n",lens,data);//AT+QISEND
delay_ms(1000);
strx=strstr((const char*)USART2_RX_BUF,(const char*)"SEND OK");//<2F><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD>ͳɹ<CDB3>
while((!strx)&&(times<10))
{
delay_ms(1000);
strx=strstr((const char*)USART2_RX_BUF,(const char*)"SEND OK");//<2F><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD>ͳɹ<CDB3>
times++;
}
}
/*
<EFBFBD><EFBFBD><EFBFBD>ܣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģʽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
int len <20><><EFBFBD>ݳ<EFBFBD><DDB3><EFBFBD>
char *data <20><><EFBFBD><EFBFBD>
*/
u8 BC25_Senddata_mode(int len,char *data)
{
char *strx;
// char lens[5]={'\0'};
u8 times=0;
USART2_ReceiveBuff_Clear();
// sprintf(lens,"%d",len);
// printf("AT+QISEND=0,%s\r\n",lens);
printf("AT+QISEND=0,%d\r\n",len);
delay_ms(300);
strx=strstr((const char*)USART2_RX_BUF,(const char*)">");//<2F><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7>յ<EFBFBD>>
while((!strx)&&times<20)
{
times++;
// printf("AT+QISEND=0,%d\r\n",len);
delay_ms(500);
strx=strstr((const char*)USART2_RX_BUF,(const char*)">");//<2F><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7>յ<EFBFBD>>
if(!strx)
{
USART2_ReceiveBuff_Clear();
printf("AT+QISEND=0,%d\r\n",len);
}
}
delay_ms(500);
printf("%s",data);
delay_ms(300);
times=0;
strx=strstr((const char*)USART2_RX_BUF,(const char*)"SEND OK");//<2F><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD>ͳɹ<CDB3>
while((!strx)&&times<20)
{
times++;
// printf("%s",data);
delay_ms(300);
strx=strstr((const char*)USART2_RX_BUF,(const char*)"SEND OK");//<2F><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD>ͳɹ<CDB3>
if(!strx)
{
USART2_ReceiveBuff_Clear();
printf("%s",data);
}
}
if(strx)return 0;
else return 1;
}
void BC25_RECData(void)
{
char *strx;
strx=strstr((const char*)USART2_RX_BUF,(const char*)"+QIURC");//<2F><><EFBFBD><EFBFBD>+QIURC
if(strx)
{
USART2_ReceiveBuff_Clear(); //<2F><>д<EFBFBD><D0B4><EFBFBD><EFBFBD>
}
}
void BC25_time_RTC(void)
{
int set_years, set_mons, set_days, set_hours, set_mins , set_secs;
u8 i=0;
char *strx;
BC25CTR_Init();
BC25_POWERON();
delay_ms(1000);
BC25_PWRKEY_ON();
delay_ms(8000);
//printf("AT+QSELFREGISTER=1\r\n"); //<2F>Զ<EFBFBD>ע<EFBFBD><D7A2>
strx=NULL;
while((i<60)&(!strx))
{
i++;
USART2_ReceiveBuff_Clear();
printf("AT+CGATT?\r\n");//<2F><>ѯ<EFBFBD><D1AF><EFBFBD><EFBFBD>״̬
delay_ms(500);
strx=strstr((const char*)USART2_RX_BUF,(const char*)"+CGATT: 1");//<2F><>1
}
if(!strx)return;
strx=NULL;
while((i<60)&(!strx))
{
USART2_ReceiveBuff_Clear();
printf("AT+CCLK?\r\n");//<2F><>ѯ<EFBFBD><D1AF><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
delay_ms(500);
strx=strstr((const char*)USART2_RX_BUF,(const char*)"+CCLK:");//<2F><>1
}
if(!strx)return;
strx=strstr((const char*)USART2_RX_BUF,(const char*)"\"");//
strx++;
set_years=(strx[0]-'0')*10+(strx[1]-'0');//<2F><>
set_mons=(strx[3]-'0')*10+(strx[4]-'0');//<2F><>
set_days=(strx[6]-'0')*10+(strx[7]-'0');//<2F><>
set_hours=(strx[9]-'0')*10+(strx[10]-'0');//ʱ
set_mins=(strx[12]-'0')*10+(strx[13]-'0');//<2F><>
set_secs=(strx[15]-'0')*10+(strx[16]-'0');//<2F><>
if(set_years>20)
SetRTC(set_years,set_mons,set_days,set_hours,set_mins,set_secs);
// printf("AT+QENG=0\r\n");//
// delay_ms(500);
// u5_printf("AT+QENG=0:%s\r\n",(const char*)USART2_RX_BUF);
// USART2_ReceiveBuff_Clear();
// printf("AT+CSQ\r\n");//
// delay_ms(500);
// u5_printf("AT+CSQ:%s\r\n",(const char*)USART2_RX_BUF);
// USART2_ReceiveBuff_Clear();
// printf("ATI\r\n");//
// delay_ms(500);
// u5_printf("ATI:%s\r\n",(const char*)USART2_RX_BUF);
}
void BC25_Process(void)
{
BC25_Init(); //<2F><>ʼ<EFBFBD><CABC>
BC25_CloseSocket();//<2F>ر<EFBFBD><D8B1><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
BC25_CreateSokcet(Init_Data_Equipment.Bc25_Ip,Init_Data_Equipment.Bc25_Port);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
BC25_Senddata_mode(4,"Pub-");
BC25_Senddata_mode(strlen(data_common1.Pack_data),(data_common1.Pack_data));
BC25_Senddata_mode(2,"\r\n");
}

View File

@ -0,0 +1,40 @@
#ifndef __BC25_H
#define __BC25_H
#include "sys.h"
#include "general_type.h"
#include "stm32l1xx.h"
#include "stm32l1xx_gpio.h"
#include "stm32l1xx_rcc.h"
#define PWRKEY_H GPIO_SetBits(GPIOA,GPIO_Pin_1) //BC25<32><35>Դ<EFBFBD><D4B4><EFBFBD><EFBFBD>
#define PWRKEY_L GPIO_ResetBits(GPIOA,GPIO_Pin_1)
void BC25CTR_Init(void);
void BC25_PWRKEY_ON(void);
void BC25_RECData(void);
void BC25_Senddata(int len,char *data);
void BC25_CreateSokcet(char *ip,char *port);
void BC25_CloseSocket(void);
u8 BC25_Init(void);
void BC25_POWERON(void);
void BC25_POWEROFF(void);
void BC25_Process(void);
u8 BC25_Senddata_mode(int len,char *data);
void BC25_time_RTC(void);
typedef struct
{
uint8_t CSQ;
uint8_t Socketnum; //<2F><><EFBFBD><EFBFBD>
uint8_t reclen[10]; //<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD>ݵij<DDB5><C4B3><EFBFBD>
uint8_t res;
uint8_t recdatalen[10];
uint8_t recdata[100];
uint8_t netstatus;//<2F><><EFBFBD><EFBFBD>ָʾ<D6B8><CABE>
uint8_t socket;//<2F><><EFBFBD><EFBFBD>ָʾ<D6B8><CABE>
} BC25;
extern BC25 BC25_Status;
#endif

View File

@ -0,0 +1,425 @@
#include "spi.h"
//#include "delay.h"
//#include "timerx.h"
#include <stdio.h>
#include "enc28j60.h"
//////////////////////////////////////////////////////////////////////////////////
//ALIENTEKս<4B><D5BD>STM32<33><32><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//ENC28J60<36><30><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
//<2F><><EFBFBD><EFBFBD>ԭ<EFBFBD><D4AD>@ALIENTEK
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̳:www.openedv.com
//<2F>޸<EFBFBD><DEB8><EFBFBD><EFBFBD><EFBFBD>:2012/9/28
//<2F><EFBFBD><E6B1BE>V1.0
//////////////////////////////////////////////////////////////////////////////////
static u8 ENC28J60BANK;
static u32 NextPacketPtr;
//<2F><>λENC28J60
//<2F><><EFBFBD><EFBFBD>SPI<50><49>ʼ<EFBFBD><CABC>/IO<49><4F>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>
static void ENC28J60_SPI2_Init(void)
{
// SPI_InitTypeDef SPI_InitStructure;
// GPIO_InitTypeDef GPIO_InitStructure;
// RCC_APB1PeriphClockCmd( RCC_APB1Periph_SPI2, ENABLE );//SPI2ʱ<32><CAB1>ʹ<EFBFBD><CAB9>
// RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOD|RCC_APB2Periph_GPIOG, ENABLE );//PORTB,D,Gʱ<47><CAB1>ʹ<EFBFBD><CAB9>
//
// GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; // <20>˿<EFBFBD><CBBF><EFBFBD><EFBFBD><EFBFBD>
// GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //IO<49><4F><EFBFBD>ٶ<EFBFBD>Ϊ50MHz
// GPIO_Init(GPIOD, &GPIO_InitStructure); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E8B6A8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>GPIOD.2
// GPIO_SetBits(GPIOD,GPIO_Pin_2); //PD.2<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//
// //<2F><><EFBFBD><EFBFBD>PG7<47><37>PB12<31><32><EFBFBD><EFBFBD>,<2C><>Ϊ<EFBFBD>˷<EFBFBD>ֹNRF24L01<30><31>SPI FLASHӰ<48><D3B0>.
// //<2F><>Ϊ<EFBFBD><CEAA><EFBFBD>ǹ<EFBFBD><C7B9><EFBFBD>һ<EFBFBD><D2BB>SPI<50><49>.
// GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12; // PB12 <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
// GPIO_Init(GPIOB, &GPIO_InitStructure); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E8B6A8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>GPIOB.12
// GPIO_SetBits(GPIOB,GPIO_Pin_12); //PB.12<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6|GPIO_Pin_7|GPIO_Pin_8;//PG6/7/8 <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
// GPIO_Init(GPIOG, &GPIO_InitStructure); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E8B6A8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>//PG6/7/8
// GPIO_SetBits(GPIOG,GPIO_Pin_6|GPIO_Pin_7|GPIO_Pin_8);//PG6/7/8<><38><EFBFBD><EFBFBD>
//
// GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15;
// GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //PB13/14/15<31><35><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
// GPIO_Init(GPIOB, &GPIO_InitStructure);//<2F><>ʼ<EFBFBD><CABC>GPIOB
// GPIO_SetBits(GPIOB,GPIO_Pin_13|GPIO_Pin_14|GPIO_Pin_15); //PB13/14/15<31><35><EFBFBD><EFBFBD>
// SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex; //<2F><><EFBFBD><EFBFBD>SPI<50><49><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˫<EFBFBD><CBAB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģʽ:SPI<50><49><EFBFBD><EFBFBD>Ϊ˫<CEAA><CBAB>˫<EFBFBD><CBAB>ȫ˫<C8AB><CBAB>
// SPI_InitStructure.SPI_Mode = SPI_Mode_Master; //<2F><><EFBFBD><EFBFBD>SPI<50><49><EFBFBD><EFBFBD>ģʽ:<3A><><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>SPI
// SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b; //<2F><><EFBFBD><EFBFBD>SPI<50><49><EFBFBD><EFBFBD><EFBFBD>ݴ<EFBFBD>С:SPI<50><49><EFBFBD>ͽ<EFBFBD><CDBD><EFBFBD>8λ֡<CEBB>
// SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low; //<2F><><EFBFBD><EFBFBD>ͬ<EFBFBD><CDAC>ʱ<EFBFBD>ӵĿ<D3B5><C4BF><EFBFBD>״̬Ϊ<CCAC>͵<EFBFBD>ƽ
// SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge; //<2F><><EFBFBD><EFBFBD>ͬ<EFBFBD><CDAC>ʱ<EFBFBD>ӵĵ<D3B5>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>أ<EFBFBD><D8A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>½<EFBFBD><C2BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݱ<EFBFBD><DDB1><EFBFBD><EFBFBD><EFBFBD>
// SPI_InitStructure.SPI_NSS = SPI_NSS_Soft; //NSS<53>ź<EFBFBD><C5BA><EFBFBD>Ӳ<EFBFBD><D3B2><EFBFBD><EFBFBD>NSS<53>ܽţ<DCBD><C5A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9>SSIλ<49><CEBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:<3A>ڲ<EFBFBD>NSS<53>ź<EFBFBD><C5BA><EFBFBD>SSIλ<49><CEBB><EFBFBD><EFBFBD>
// SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_256; //<2F><><EFBFBD><EFBFBD><E5B2A8><EFBFBD><EFBFBD>Ԥ<EFBFBD><D4A4>Ƶ<EFBFBD><C6B5>ֵ:<3A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ԥ<EFBFBD><D4A4>ƵֵΪ256
// SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB; //ָ<><D6B8><EFBFBD><EFBFBD><EFBFBD>ݴ<EFBFBD><DDB4><EFBFBD><EFBFBD><EFBFBD>MSBλ<42><CEBB><EFBFBD><EFBFBD>LSBλ<42><CEBB>ʼ:<3A><><EFBFBD>ݴ<EFBFBD><DDB4><EFBFBD><EFBFBD><EFBFBD>MSBλ<42><CEBB>ʼ
// SPI_InitStructure.SPI_CRCPolynomial = 7; //CRCֵ<43><D6B5><EFBFBD><EFBFBD><EFBFBD>Ķ<EFBFBD><C4B6><EFBFBD>ʽ
// SPI_Init(SPI2, &SPI_InitStructure); //<2F><><EFBFBD><EFBFBD>SPI_InitStruct<63><74>ָ<EFBFBD><D6B8><EFBFBD>IJ<EFBFBD><C4B2><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>SPIx<49>Ĵ<EFBFBD><C4B4><EFBFBD>
//
// SPI_Cmd(SPI2, ENABLE); //ʹ<><CAB9>SPI<50><49><EFBFBD><EFBFBD>
//
// SPI2_ReadWriteByte(0xff);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
}
void ENC28J60_Reset(void)
{
// ENC28J60_SPI2_Init();//SPI2<49><32>ʼ<EFBFBD><CABC>
// SPI2_SetSpeed(SPI_BaudRatePrescaler_4); //SPI2 SCKƵ<4B><C6B5>Ϊ36M/4=9Mhz
// TIM6_Int_Init(1000,719);//100Khz<68><7A><EFBFBD><EFBFBD>Ƶ<EFBFBD>ʣ<EFBFBD><CAA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>1000Ϊ10ms
// ENC28J60_RST=0; //<2F><>λENC28J60
// delay_ms(10);
// ENC28J60_RST=1; //<2F><>λ<EFBFBD><CEBB><EFBFBD><EFBFBD>
// delay_ms(10);
}
//<2F><>ȡENC28J60<36>Ĵ<EFBFBD><C4B4><EFBFBD>(<28><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>)
//op<6F><70><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//addr:<3A>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD>ַ/<2F><><EFBFBD><EFBFBD>
//<2F><><EFBFBD><EFBFBD>ֵ:<3A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
u8 ENC28J60_Read_Op(u8 op,u8 addr)
{
u8 dat=0;
ENC28J60_CSL ;
dat=op|(addr&ADDR_MASK);
SPI1_ReadWrite(dat);
dat=SPI1_ReadWrite(0xFF);
//<2F><><EFBFBD><EFBFBD><EFBFBD>Ƕ<EFBFBD>ȡMAC/MII<49>Ĵ<EFBFBD><C4B4><EFBFBD>,<2C><><EFBFBD>ڶ<EFBFBD><DAB6>ζ<EFBFBD><CEB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݲ<EFBFBD><DDB2><EFBFBD><EFBFBD><EFBFBD>ȷ<EFBFBD><C8B7>,<2C><><EFBFBD>ֲ<EFBFBD>29ҳ
if(addr&0x80)dat=SPI1_ReadWrite(0xFF);
ENC28J60_CSH;
return dat;
}
//<2F><>ȡENC28J60<36>Ĵ<EFBFBD><C4B4><EFBFBD>(<28><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>)
//op<6F><70><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//addr:<3A>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD>ַ
//data:<3A><><EFBFBD><EFBFBD>
void ENC28J60_Write_Op(u8 op,u8 addr,u8 data)
{
u8 dat = 0;
ENC28J60_CSL;
dat=op|(addr&ADDR_MASK);
SPI1_ReadWrite(dat);
SPI1_ReadWrite(data);
ENC28J60_CSH;
}
//<2F><>ȡENC28J60<36><30><EFBFBD>ջ<EFBFBD><D5BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//len:Ҫ<><D2AA>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><DDB3><EFBFBD>
//data:<3A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݻ<EFBFBD><DDBB><EFBFBD><EFBFBD><EFBFBD>(ĩβ<C4A9>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD>ӽ<EFBFBD><D3BD><EFBFBD><EFBFBD><EFBFBD>)
void ENC28J60_Read_Buf(u32 len,u8* data)
{
ENC28J60_CSL;
SPI1_ReadWrite(ENC28J60_READ_BUF_MEM);
while(len)
{
len--;
*data=(u8)SPI1_ReadWrite(0);
data++;
}
*data='\0';
ENC28J60_CSL;
}
//<2F><>ENC28J60д<30><D0B4><EFBFBD>ͻ<EFBFBD><CDBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//len:Ҫд<D2AA><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><DDB3><EFBFBD>
//data:<3A><><EFBFBD>ݻ<EFBFBD><DDBB><EFBFBD><EFBFBD><EFBFBD>
void ENC28J60_Write_Buf(u32 len,u8* data)
{
ENC28J60_CSL;
SPI1_ReadWrite(ENC28J60_WRITE_BUF_MEM);
while(len)
{
len--;
SPI1_ReadWrite(*data);
data++;
}
ENC28J60_CSH;
}
//<2F><><EFBFBD><EFBFBD>ENC28J60<36>Ĵ<EFBFBD><C4B4><EFBFBD>Bank
//ban:Ҫ<><D2AA><EFBFBD>õ<EFBFBD>bank
void ENC28J60_Set_Bank(u8 bank)
{
if((bank&BANK_MASK)!=ENC28J60BANK)//<2F>͵<EFBFBD>ǰbank<6E><6B>һ<EFBFBD>µ<EFBFBD>ʱ<EFBFBD><CAB1>,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
ENC28J60_Write_Op(ENC28J60_BIT_FIELD_CLR,ECON1,(ECON1_BSEL1|ECON1_BSEL0));
ENC28J60_Write_Op(ENC28J60_BIT_FIELD_SET,ECON1,(bank&BANK_MASK)>>5);
ENC28J60BANK=(bank&BANK_MASK);
}
}
//<2F><>ȡENC28J60ָ<30><D6B8><EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD>
//addr:<3A>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD>ַ
//<2F><><EFBFBD><EFBFBD>ֵ:<3A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
u8 ENC28J60_Read(u8 addr)
{
ENC28J60_Set_Bank(addr);//<2F><><EFBFBD><EFBFBD>BANK
return ENC28J60_Read_Op(ENC28J60_READ_CTRL_REG,addr);
}
//<2F><>ENC28J60ָ<30><D6B8><EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD>
//addr:<3A>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD>ַ
//data:Ҫд<D2AA><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
void ENC28J60_Write(u8 addr,u8 data)
{
ENC28J60_Set_Bank(addr);
ENC28J60_Write_Op(ENC28J60_WRITE_CTRL_REG,addr,data);
}
//<2F><>ENC28J60<36><30>PHY<48>Ĵ<EFBFBD><C4B4><EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//addr:<3A>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD>ַ
//data:Ҫд<D2AA><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
void ENC28J60_PHY_Write(u8 addr,u32 data)
{
u16 retry=0;
ENC28J60_Write(MIREGADR,addr); //<2F><><EFBFBD><EFBFBD>PHY<48>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD>ַ
ENC28J60_Write(MIWRL,data); //д<><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
ENC28J60_Write(MIWRH,data>>8);
while((ENC28J60_Read(MISTAT)&MISTAT_BUSY)&&retry<0XFFF)retry++;//<2F>ȴ<EFBFBD>д<EFBFBD><D0B4>PHY<48><59><EFBFBD><EFBFBD>
}
//<2F><>ʼ<EFBFBD><CABC>ENC28J60
//macaddr:MAC<41><43>ַ
//<2F><><EFBFBD><EFBFBD>ֵ:0,<2C><>ʼ<EFBFBD><CABC><EFBFBD>ɹ<EFBFBD>;
// 1,<2C><>ʼ<EFBFBD><CABC>ʧ<EFBFBD><CAA7>;
u8 ENC28J60_Init(u8* macaddr)
{
u16 retry=0;
ENC28J60_Reset();
ENC28J60_Write_Op(ENC28J60_SOFT_RESET,0,ENC28J60_SOFT_RESET);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ
while(!(ENC28J60_Read(ESTAT)&ESTAT_CLKRDY)&&retry<500)//<2F>ȴ<EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD>ȶ<EFBFBD>
{
retry++;
// delay_ms(1);
};
if(retry>=500)return 1;//ENC28J60<36><30>ʼ<EFBFBD><CABC>ʧ<EFBFBD><CAA7>
// do bank 0 stuff
// initialize receive buffer
// 16-bit transfers,must write low byte first
// set receive buffer start address <20><><EFBFBD>ý<EFBFBD><C3BD>ջ<EFBFBD><D5BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ 8K<38>ֽ<EFBFBD><D6BD><EFBFBD><EFBFBD><EFBFBD>
NextPacketPtr=RXSTART_INIT;
// Rx start
//<2F><><EFBFBD>ջ<EFBFBD><D5BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>Ӳ<EFBFBD><D3B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѭ<EFBFBD><D1AD>FIFO <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɡ<EFBFBD>
//<2F>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD>ERXSTH:ERXSTL <20><>ERXNDH:ERXNDL <20><>
//Ϊָ<CEAA><EFBFBD><EBA3AC><EFBFBD><EFBFBD><E5BBBA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ洢<DAB4><E6B4A2><EFBFBD>е<EFBFBD>λ<EFBFBD>á<EFBFBD>
//ERXST<53><54>ERXNDָ<44><D6B8><EFBFBD><EFBFBD><EFBFBD>ֽھ<D6BD><DABE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>FIFO<46><4F><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڡ<EFBFBD>
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̫<EFBFBD><CCAB><EFBFBD>ӿڽ<D3BF><DABD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֽ<EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>Щ<EFBFBD>ֽڱ<D6BD>˳<EFBFBD><CBB3>д<EFBFBD><D0B4>
//<2F><><EFBFBD>ջ<EFBFBD><D5BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD>ǵ<EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD>ERXND ָ<><D6B8><EFBFBD>Ĵ洢<C4B4><E6B4A2>Ԫ
//<2F><><EFBFBD><EFBFBD>Ӳ<EFBFBD><D3B2><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>յ<EFBFBD><D5B5><EFBFBD>һ<EFBFBD>ֽ<EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD>ERXST ָ<><D6B8>
//<2F>Ĵ洢<C4B4><E6B4A2>Ԫ<EFBFBD><D4AA> <20><><EFBFBD>˽<EFBFBD><CBBD><EFBFBD>Ӳ<EFBFBD><D3B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><D0B4>FIFO <20><><EFBFBD><EFBFBD><EFBFBD>ĵ<EFBFBD>
//Ԫ<><D4AA>
//<2F><><EFBFBD>ý<EFBFBD><C3BD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD>ֽ<EFBFBD>
ENC28J60_Write(ERXSTL,RXSTART_INIT&0xFF);
ENC28J60_Write(ERXSTH,RXSTART_INIT>>8);
//ERXWRPTH:ERXWRPTL <20>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӳ<EFBFBD><D3B2><EFBFBD><EFBFBD>FIFO <20><>
//<2F><><EFBFBD>ĸ<EFBFBD>λ<EFBFBD><CEBB>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD>ֽڡ<D6BD> ָ<><D6B8><EFBFBD><EFBFBD>ֻ<EFBFBD><D6BB><EFBFBD>ģ<EFBFBD><C4A3>ڳ<EFBFBD>
//<2F><><EFBFBD><EFBFBD><EFBFBD>յ<EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD>ݰ<EFBFBD><DDB0><EFBFBD><EFBFBD><EFBFBD>Ӳ<EFBFBD><D3B2><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD>롣 ָ<><D6B8><EFBFBD><EFBFBD>
//<2F><><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>FIFO <20><>ʣ<EFBFBD><CAA3><EFBFBD>ռ<EFBFBD><D5BC>Ĵ<EFBFBD>С 8K-1500<30><30>
//<2F><><EFBFBD>ý<EFBFBD><C3BD>ն<EFBFBD>ָ<EFBFBD><D6B8><EFBFBD>ֽ<EFBFBD>
ENC28J60_Write(ERXRDPTL,RXSTART_INIT&0xFF);
ENC28J60_Write(ERXRDPTH,RXSTART_INIT>>8);
//<2F><><EFBFBD>ý<EFBFBD><C3BD>ս<EFBFBD><D5BD><EFBFBD><EFBFBD>ֽ<EFBFBD>
ENC28J60_Write(ERXNDL,RXSTOP_INIT&0xFF);
ENC28J60_Write(ERXNDH,RXSTOP_INIT>>8);
//<2F><><EFBFBD>÷<EFBFBD><C3B7><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD>ֽ<EFBFBD>
ENC28J60_Write(ETXSTL,TXSTART_INIT&0xFF);
ENC28J60_Write(ETXSTH,TXSTART_INIT>>8);
//<2F><><EFBFBD>÷<EFBFBD><C3B7>ͽ<EFBFBD><CDBD><EFBFBD><EFBFBD>ֽ<EFBFBD>
ENC28J60_Write(ETXNDL,TXSTOP_INIT&0xFF);
ENC28J60_Write(ETXNDH,TXSTOP_INIT>>8);
// do bank 1 stuff,packet filter:
// For broadcast packets we allow only ARP packtets
// All other packets should be unicast only for our mac (MAADR)
//
// The pattern to match on is therefore
// Type ETH.DST
// ARP BROADCAST
// 06 08 -- ff ff ff ff ff ff -> ip checksum for theses bytes=f7f9
// in binary these poitions are:11 0000 0011 1111
// This is hex 303F->EPMM0=0x3f,EPMM1=0x30
//<2F><><EFBFBD>չ<EFBFBD><D5B9><EFBFBD><EFBFBD><EFBFBD>
//UCEN<45><4E><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9>λ
//<2F><>ANDOR = 1 ʱ<><CAB1>
//1 = Ŀ<><C4BF><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EBB1BE>MAC <20><>ַ<EFBFBD><D6B7>ƥ<EFBFBD><C6A5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݰ<EFBFBD><DDB0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//0 = <20><>ֹ<EFBFBD><D6B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//<2F><>ANDOR = 0 ʱ<><CAB1>
//1 = Ŀ<><C4BF><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EBB1BE>MAC <20><>ַƥ<D6B7><C6A5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݰ<EFBFBD><DDB0><EFBFBD><E1B1BB><EFBFBD><EFBFBD>
//0 = <20><>ֹ<EFBFBD><D6B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//CRCEN<45><4E><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>CRC У<><D0A3>ʹ<EFBFBD><CAB9>λ
//1 = <20><><EFBFBD><EFBFBD>CRC <20><>Ч<EFBFBD><D0A7><EFBFBD><EFBFBD><EFBFBD>ݰ<EFBFBD><DDB0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//0 = <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>CRC <20>Ƿ<EFBFBD><C7B7><EFBFBD>Ч
//PMEN<45><4E><EFBFBD><EFBFBD>ʽƥ<CABD><C6A5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9>λ
//<2F><>ANDOR = 1 ʱ<><CAB1>
//1 = <20><><EFBFBD>ݰ<EFBFBD><DDB0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϸ<EFBFBD>ʽƥ<CABD><C6A5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>򽫱<EFBFBD><F2BDABB1><EFBFBD><EFBFBD><EFBFBD>
//0 = <20><>ֹ<EFBFBD><D6B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//<2F><>ANDOR = 0 ʱ<><CAB1>
//1 = <20><><EFBFBD>ϸ<EFBFBD>ʽƥ<CABD><C6A5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݰ<EFBFBD><DDB0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//0 = <20><>ֹ<EFBFBD><D6B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
ENC28J60_Write(ERXFCON,ERXFCON_UCEN|ERXFCON_CRCEN|ERXFCON_PMEN);
ENC28J60_Write(EPMM0,0x3f);
ENC28J60_Write(EPMM1,0x30);
ENC28J60_Write(EPMCSL,0xf9);
ENC28J60_Write(EPMCSH,0xf7);
// do bank 2 stuff
// enable MAC receive
//bit 0 MARXEN<45><4E>MAC <20><><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9>λ
//1 = <20><><EFBFBD><EFBFBD>MAC <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݰ<EFBFBD>
//0 = <20><>ֹ<EFBFBD><D6B9><EFBFBD>ݰ<EFBFBD><DDB0><EFBFBD><EFBFBD><EFBFBD>
//bit 3 TXPAUS<55><53><EFBFBD><EFBFBD>ͣ<EFBFBD><CDA3><EFBFBD><EFBFBD>֡<EFBFBD><D6A1><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9>λ
//1 = <20><><EFBFBD><EFBFBD>MAC <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͣ<EFBFBD><CDA3><EFBFBD><EFBFBD>֡<EFBFBD><D6A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȫ˫<C8AB><CBAB>ģʽ<C4A3>µ<EFBFBD><C2B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƣ<EFBFBD>
//0 = <20><>ֹ<EFBFBD><D6B9>ͣ֡<CDA3><D6A1><EFBFBD><EFBFBD>
//bit 2 RXPAUS<55><53><EFBFBD><EFBFBD>ͣ<EFBFBD><CDA3><EFBFBD><EFBFBD>֡<EFBFBD><D6A1><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9>λ
//1 = <20><><EFBFBD><EFBFBD><EFBFBD>յ<EFBFBD><D5B5><EFBFBD>ͣ<EFBFBD><CDA3><EFBFBD><EFBFBD>֡ʱ<D6A1><CAB1><EFBFBD><EFBFBD>ֹ<EFBFBD><D6B9><EFBFBD>ͣ<EFBFBD><CDA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//0 = <20><><EFBFBD>Խ<EFBFBD><D4BD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD><EFBFBD>ͣ<EFBFBD><CDA3><EFBFBD><EFBFBD>֡
ENC28J60_Write(MACON1,MACON1_MARXEN|MACON1_TXPAUS|MACON1_RXPAUS);
// bring MAC out of reset
//<2F><>MACON2 <20>е<EFBFBD>MARST λ<><CEBB><EFBFBD>ʹMAC <20>˳<EFBFBD><CBB3><EFBFBD>λ״̬<D7B4><CCAC>
ENC28J60_Write(MACON2,0x00);
// enable automatic padding to 60bytes and CRC operations
//bit 7-5 PADCFG2:PACDFG0<47><30><EFBFBD>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>CRC <20><><EFBFBD><EFBFBD>λ
//111 = <20><>0 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>֡<EFBFBD><D6A1>64 <20>ֽڳ<D6BD><DAB3><EFBFBD><EFBFBD><EFBFBD>׷<EFBFBD><D7B7>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>Ч<EFBFBD><D0A7>CRC
//110 = <20><><EFBFBD>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֡
//101 = MAC <20>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>8100h <20><><EFBFBD><EFBFBD><EFBFBD>ֶε<D6B6>VLAN Э<><D0AD>֡<EFBFBD><D6A1><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD>䵽64 <20>ֽڳ<D6BD><DAB3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//<2F><>VLAN ֡<><D6A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>60 <20>ֽڳ<D6BD><DAB3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ׷<D2AA><D7B7>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>Ч<EFBFBD><D0A7>CRC
//100 = <20><><EFBFBD>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֡
//011 = <20><>0 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>֡<EFBFBD><D6A1>64 <20>ֽڳ<D6BD><DAB3><EFBFBD><EFBFBD><EFBFBD>׷<EFBFBD><D7B7>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>Ч<EFBFBD><D0A7>CRC
//010 = <20><><EFBFBD>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֡
//001 = <20><>0 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>֡<EFBFBD><D6A1>60 <20>ֽڳ<D6BD><DAB3><EFBFBD><EFBFBD><EFBFBD>׷<EFBFBD><D7B7>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>Ч<EFBFBD><D0A7>CRC
//000 = <20><><EFBFBD>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֡
//bit 4 TXCRCEN<45><4E><EFBFBD><EFBFBD><EFBFBD><EFBFBD>CRC ʹ<><CAB9>λ
//1 = <20><><EFBFBD><EFBFBD>PADCFG<46><47><EFBFBD>Σ<EFBFBD>MAC<41><43><EFBFBD><EFBFBD><EFBFBD>ڷ<EFBFBD><DAB7><EFBFBD>֡<EFBFBD><D6A1>ĩβ׷<CEB2><D7B7>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>Ч<EFBFBD><D0A7>CRC<52><43> <20><><EFBFBD><EFBFBD>PADCFG<46>涨Ҫ
//׷<><D7B7><EFBFBD><EFBFBD>Ч<EFBFBD><D0A7>CRC<52><43><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>뽫TXCRCEN <20><>1<EFBFBD><31>
//0 = MAC<41><43><EFBFBD><EFBFBD>׷<EFBFBD><D7B7>CRC<52><43> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>4 <20><><EFBFBD>ֽڣ<D6BD><DAA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ч<EFBFBD><D0A7>CRC <20>򱨸<EFBFBD><F2B1A8B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬<D7B4><CCAC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//bit 0 FULDPX<50><58>MAC ȫ˫<C8AB><CBAB>ʹ<EFBFBD><CAB9>λ
//1 = MAC<41><43><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȫ˫<C8AB><CBAB>ģʽ<C4A3>¡<EFBFBD> PHCON1.PDPXMD λ<><CEBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>1<EFBFBD><31>
//0 = MAC<41><43><EFBFBD><EFBFBD><EFBFBD>ڰ<EFBFBD>˫<EFBFBD><CBAB>ģʽ<C4A3>¡<EFBFBD> PHCON1.PDPXMD λ<><CEBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
ENC28J60_Write_Op(ENC28J60_BIT_FIELD_SET,MACON3,MACON3_PADCFG0|MACON3_TXCRCEN|MACON3_FRMLNEN|MACON3_FULDPX);
// set inter-frame gap (non-back-to-back)
//<2F><><EFBFBD>÷DZ<C3B7><C7B1>Ա<EFBFBD><D4B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD>ĵ<EFBFBD><C4B5>ֽ<EFBFBD>
//MAIPGL<47><4C> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><D3A6>ʹ<EFBFBD><CAB9>12h <20><><EFBFBD≯üĴ<C3BC><C4B4><EFBFBD><EFBFBD><EFBFBD>
//<2F><><EFBFBD><EFBFBD>ʹ<EFBFBD>ð<EFBFBD>˫<EFBFBD><CBAB>ģʽ<C4A3><CABD>Ӧ<EFBFBD><D3A6><EFBFBD>̷DZ<CCB7><C7B1>Ա<EFBFBD><D4B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//<2F>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD>ĸ<EFBFBD><C4B8>ֽ<EFBFBD>MAIPGH<47><48> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><D3A6>ʹ<EFBFBD><CAB9>0Ch
//<2F><><EFBFBD≯üĴ<C3BC><C4B4><EFBFBD><EFBFBD><EFBFBD>
ENC28J60_Write(MAIPGL,0x12);
ENC28J60_Write(MAIPGH,0x0C);
// set inter-frame gap (back-to-back)
//<2F><><EFBFBD>ñ<EFBFBD><C3B1>Ա<EFBFBD><D4B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD>MABBIPG<50><47><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9>
//ȫ˫<C8AB><CBAB>ģʽʱ<CABD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><D3A6>ʹ<EFBFBD><CAB9>15h <20><><EFBFBD≯üĴ<C3BC>
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD>ð<EFBFBD>˫<EFBFBD><CBAB>ģʽʱ<CABD><CAB1>ʹ<EFBFBD><CAB9>12h <20><><EFBFBD>б<EFBFBD><D0B1>̡<EFBFBD>
ENC28J60_Write(MABBIPG,0x15);
// Set the maximum packet size which the controller will accept
// Do not send packets longer than MAX_FRAMELEN:
// <20><><EFBFBD><EFBFBD>֡<EFBFBD><D6A1><EFBFBD><EFBFBD> 1500
ENC28J60_Write(MAMXFLL,MAX_FRAMELEN&0xFF);
ENC28J60_Write(MAMXFLH,MAX_FRAMELEN>>8);
// do bank 3 stuff
// write MAC address
// NOTE: MAC address in ENC28J60 is byte-backward
//<2F><><EFBFBD><EFBFBD>MAC<41><43>ַ
ENC28J60_Write(MAADR5,macaddr[0]);
ENC28J60_Write(MAADR4,macaddr[1]);
ENC28J60_Write(MAADR3,macaddr[2]);
ENC28J60_Write(MAADR2,macaddr[3]);
ENC28J60_Write(MAADR1,macaddr[4]);
ENC28J60_Write(MAADR0,macaddr[5]);
//<2F><><EFBFBD><EFBFBD>PHYΪȫ˫<C8AB><CBAB> LEDBΪ<42><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
ENC28J60_PHY_Write(PHCON1,PHCON1_PDPXMD);
// no loopback of transmitted frames <20><>ֹ<EFBFBD><D6B9><EFBFBD><EFBFBD>
//HDLDIS<49><53>PHY <20><>˫<EFBFBD><CBAB><EFBFBD><EFBFBD><EFBFBD>ؽ<EFBFBD>ֹλ
//<2F><>PHCON1.PDPXMD = 1 <20><>PHCON1.PLOOPBK = 1 ʱ<><CAB1>
//<2F><>λ<EFBFBD>ɱ<EFBFBD><C9B1><EFBFBD><EFBFBD>ԡ<EFBFBD>
//<2F><>PHCON1.PDPXMD = 0 <20><>PHCON1.PLOOPBK = 0 ʱ<><CAB1>
//1 = Ҫ<><D2AA><EFBFBD>͵<EFBFBD><CDB5><EFBFBD><EFBFBD>ݽ<EFBFBD>ͨ<EFBFBD><CDA8>˫<EFBFBD><CBAB><EFBFBD>߽ӿڷ<D3BF><DAB7><EFBFBD>
//0 = Ҫ<><D2AA><EFBFBD>͵<EFBFBD><CDB5><EFBFBD><EFBFBD>ݻỷ<DDBB>ص<EFBFBD>MAC <20><>ͨ<EFBFBD><CDA8>˫<EFBFBD><CBAB><EFBFBD>߽ӿڷ<D3BF><DAB7><EFBFBD>
ENC28J60_PHY_Write(PHCON2,PHCON2_HDLDIS);
// switch to bank 0
//ECON1 <20>Ĵ<EFBFBD><C4B4><EFBFBD>
//<2F>Ĵ<EFBFBD><C4B4><EFBFBD>3-1 <20><>ʾΪECON1 <20>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڿ<EFBFBD><DABF><EFBFBD>
//ENC28J60 <20><><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD>ܡ<EFBFBD> ECON1 <20>а<EFBFBD><D0B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD>ܡ<EFBFBD><DCA1><EFBFBD>
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>DMA <20><><EFBFBD>ƺʹ<CDB4><E6B4A2>ѡ<EFBFBD><D1A1>λ<EFBFBD><CEBB>
ENC28J60_Set_Bank(ECON1);
// enable interrutps
//EIE<49><45> <20><>̫<EFBFBD><CCAB><EFBFBD>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD>
//bit 7 INTIE<49><45> ȫ<><C8AB>INT <20>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD>λ
//1 = <20><><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD><D0B6>¼<EFBFBD><C2BC><EFBFBD><EFBFBD><EFBFBD>INT <20><><EFBFBD><EFBFBD>
//0 = <20><>ֹ<EFBFBD><D6B9><EFBFBD><EFBFBD>INT <20><><EFBFBD>ŵĻ<C4BB><EEB6AF><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD>ձ<EFBFBD><D5B1><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD>ߵ<EFBFBD>ƽ<EFBFBD><C6BD>
//bit 6 PKTIE<49><45> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݰ<EFBFBD><DDB0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD>λ
//1 = <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݰ<EFBFBD><DDB0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
//0 = <20><>ֹ<EFBFBD><D6B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݰ<EFBFBD><DDB0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
ENC28J60_Write_Op(ENC28J60_BIT_FIELD_SET,EIE,EIE_INTIE|EIE_PKTIE);
// enable packet reception
//bit 2 RXEN<45><4E><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9>λ
//1 = ͨ<><CDA8><EFBFBD><EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݰ<EFBFBD><DDB0><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD>ջ<EFBFBD><D5BB><EFBFBD><EFBFBD><EFBFBD>
//0 = <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>н<EFBFBD><D0BD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD>ݰ<EFBFBD>
ENC28J60_Write_Op(ENC28J60_BIT_FIELD_SET,ECON1,ECON1_RXEN);
if(ENC28J60_Read(MAADR5)== macaddr[0])return 0;//<2F><>ʼ<EFBFBD><CABC><EFBFBD>ɹ<EFBFBD>
else return 1;
}
//<2F><>ȡEREVID
u8 ENC28J60_Get_EREVID(void)
{
//<2F><>EREVID <20><>Ҳ<EFBFBD><EFBFBD>˰汾<CBB0><E6B1BE>Ϣ<EFBFBD><CFA2> EREVID <20><>һ<EFBFBD><D2BB>ֻ<EFBFBD><D6BB><EFBFBD><EFBFBD>
//<2F>ƼĴ<C6BC><C4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>5 λ<><CEBB>ʶ<EFBFBD><CAB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʶ<EFBFBD><CAB6><EFBFBD><EFBFBD><EFBFBD>ض<EFBFBD><D8B6><EFBFBD>Ƭ
//<2F>İ汾<C4B0><E6B1BE>
return ENC28J60_Read(EREVID);
}
//#include "uip.h"
//ͨ<><CDA8>ENC28J60<36><30><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݰ<EFBFBD><DDB0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//len:<3A><><EFBFBD>ݰ<EFBFBD><DDB0><EFBFBD>С
//packet:<3A><><EFBFBD>ݰ<EFBFBD>
void ENC28J60_Packet_Send(u32 len,u8* packet)
{
//<2F><><EFBFBD>÷<EFBFBD><C3B7>ͻ<EFBFBD><CDBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַдָ<D0B4><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
ENC28J60_Write(EWRPTL,TXSTART_INIT&0xFF);
ENC28J60_Write(EWRPTH,TXSTART_INIT>>8);
//<2F><><EFBFBD><EFBFBD>TXNDָ<44><EFBFBD>Զ<EFBFBD>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݰ<EFBFBD><DDB0><EFBFBD>С
ENC28J60_Write(ETXNDL,(TXSTART_INIT+len)&0xFF);
ENC28J60_Write(ETXNDH,(TXSTART_INIT+len)>>8);
//дÿ<D0B4><C3BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֽڣ<D6BD>0x00<30><30>ʾʹ<CABE><CAB9>macon3<6E><33><EFBFBD><EFBFBD><EFBFBD>ã<EFBFBD>
ENC28J60_Write_Op(ENC28J60_WRITE_BUF_MEM,0,0x00);
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݰ<EFBFBD><DDB0><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͻ<EFBFBD><CDBB><EFBFBD><EFBFBD><EFBFBD>
//printf("len:%d\r\n",len); //<2F><><EFBFBD>ӷ<EFBFBD><D3B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><DDB3><EFBFBD>
ENC28J60_Write_Buf(len,packet);
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD><DDB5><EFBFBD><EFBFBD><EFBFBD>
ENC28J60_Write_Op(ENC28J60_BIT_FIELD_SET,ECON1,ECON1_TXRTS);
//<2F><>λ<EFBFBD><CEBB><EFBFBD><EFBFBD><EFBFBD>߼<EFBFBD><DFBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>μ<EFBFBD>Rev. B4 Silicon Errata point 12.
if((ENC28J60_Read(EIR)&EIR_TXERIF))ENC28J60_Write_Op(ENC28J60_BIT_FIELD_CLR,ECON1,ECON1_TXRTS);
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡһ<C8A1><D2BB><EFBFBD><EFBFBD><EFBFBD>ݰ<EFBFBD><DDB0><EFBFBD><EFBFBD><EFBFBD>
//maxlen:<3A><><EFBFBD>ݰ<EFBFBD><DDB0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ճ<EFBFBD><D5B3><EFBFBD>
//packet:<3A><><EFBFBD>ݰ<EFBFBD><DDB0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//<2F><><EFBFBD><EFBFBD>ֵ:<3A>յ<EFBFBD><D5B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݰ<EFBFBD><DDB0><EFBFBD><EFBFBD><EFBFBD>(<28>ֽ<EFBFBD>)
u32 ENC28J60_Packet_Receive(u32 maxlen,u8* packet)
{
u32 rxstat;
u32 len;
if(ENC28J60_Read(EPKTCNT)==0)return 0; //<2F>Ƿ<EFBFBD><C7B7>յ<EFBFBD><D5B5><EFBFBD><EFBFBD>ݰ<EFBFBD>?
//<2F><><EFBFBD>ý<EFBFBD><C3BD>ջ<EFBFBD><D5BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8>
ENC28J60_Write(ERDPTL,(NextPacketPtr));
ENC28J60_Write(ERDPTH,(NextPacketPtr)>>8);
// <20><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8>
NextPacketPtr=ENC28J60_Read_Op(ENC28J60_READ_BUF_MEM,0);
NextPacketPtr|=ENC28J60_Read_Op(ENC28J60_READ_BUF_MEM,0)<<8;
//<2F><><EFBFBD><EFBFBD><EFBFBD>ij<EFBFBD><C4B3><EFBFBD>
len=ENC28J60_Read_Op(ENC28J60_READ_BUF_MEM,0);
len|=ENC28J60_Read_Op(ENC28J60_READ_BUF_MEM,0)<<8;
len-=4; //ȥ<><C8A5>CRC<52><43><EFBFBD><EFBFBD>
//<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>״̬
rxstat=ENC28J60_Read_Op(ENC28J60_READ_BUF_MEM,0);
rxstat|=ENC28J60_Read_Op(ENC28J60_READ_BUF_MEM,0)<<8;
//<2F><><EFBFBD>ƽ<EFBFBD><C6BD>ճ<EFBFBD><D5B3><EFBFBD>
if (len>maxlen-1)len=maxlen-1;
//<2F><><EFBFBD><EFBFBD>CRC<52>ͷ<EFBFBD><CDB7>Ŵ<EFBFBD><C5B4><EFBFBD>
// ERXFCON.CRCENΪĬ<CEAA><C4AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,һ<><D2BB><EFBFBD><EFBFBD><EFBFBD>Dz<EFBFBD><C7B2><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD>.
if((rxstat&0x80)==0)len=0;//<2F><>Ч
else ENC28J60_Read_Buf(len,packet);//<2F>ӽ<EFBFBD><D3BD>ջ<EFBFBD><D5BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>и<EFBFBD><D0B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݰ<EFBFBD>
//RX<52><58>ָ<EFBFBD><D6B8><EFBFBD>ƶ<EFBFBD><C6B6><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݰ<EFBFBD><DDB0>Ŀ<EFBFBD>ʼλ<CABC><CEBB>
//<2F><><EFBFBD>ͷ<EFBFBD><CDB7><EFBFBD><EFBFBD>ǸղŶ<D5B2><C5B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>
ENC28J60_Write(ERXRDPTL,(NextPacketPtr));
ENC28J60_Write(ERXRDPTH,(NextPacketPtr)>>8);
//<2F>ݼ<EFBFBD><DDBC><EFBFBD><EFBFBD>ݰ<EFBFBD><DDB0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־<EFBFBD><D6BE><EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD><D1BE>õ<EFBFBD><C3B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
ENC28J60_Write_Op(ENC28J60_BIT_FIELD_SET,ECON2,ECON2_PKTDEC);
return(len);
}

View File

@ -0,0 +1,300 @@
//#include "sys.h"
#include "stm32l1xx.h"
#ifndef __ENC28J60_H
#define __ENC28J60_H
#include "stm32l1xx.h"
#include "General_type.h"
//////////////////////////////////////////////////////////////////////////////////
//ALIENTEKս<4B><D5BD>STM32<33><32><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//ENC28J60<36><30><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
//<2F><><EFBFBD><EFBFBD>ԭ<EFBFBD><D4AD>@ALIENTEK
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̳:www.openedv.com
//<2F>޸<EFBFBD><DEB8><EFBFBD><EFBFBD><EFBFBD>:2012/9/28
//<2F><EFBFBD><E6B1BE>V1.0
//////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// ENC28J60 Control Registers
// Control register definitions are a combination of address,
// bank number, and Ethernet/MAC/PHY indicator bits.
// - Register address (bits 0-4)
// - Bank number (bits 5-6)
// - MAC/PHY indicator (bit 7)
#define ADDR_MASK 0x1F
#define BANK_MASK 0x60
#define SPRD_MASK 0x80
// All-bank registers
#define EIE 0x1B
#define EIR 0x1C
#define ESTAT 0x1D
#define ECON2 0x1E
#define ECON1 0x1F
// Bank 0 registers
#define ERDPTL (0x00|0x00)
#define ERDPTH (0x01|0x00)
#define EWRPTL (0x02|0x00)
#define EWRPTH (0x03|0x00)
#define ETXSTL (0x04|0x00)
#define ETXSTH (0x05|0x00)
#define ETXNDL (0x06|0x00)
#define ETXNDH (0x07|0x00)
#define ERXSTL (0x08|0x00)
#define ERXSTH (0x09|0x00)
#define ERXNDL (0x0A|0x00)
#define ERXNDH (0x0B|0x00)
//ERXWRPTH:ERXWRPTL <20>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӳ<EFBFBD><D3B2><EFBFBD><EFBFBD>FIFO <20><>
//<2F><><EFBFBD>ĸ<EFBFBD>λ<EFBFBD><CEBB>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD>ֽڡ<D6BD> ָ<><D6B8><EFBFBD><EFBFBD>ֻ<EFBFBD><D6BB><EFBFBD>ģ<EFBFBD><C4A3>ڳ<EFBFBD>
//<2F><><EFBFBD><EFBFBD><EFBFBD>յ<EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD>ݰ<EFBFBD><DDB0><EFBFBD><EFBFBD><EFBFBD>Ӳ<EFBFBD><D3B2><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD>롣 ָ<><D6B8><EFBFBD><EFBFBD>
//<2F><><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>FIFO <20><>ʣ<EFBFBD><CAA3><EFBFBD>ռ<EFBFBD><D5BC>Ĵ<EFBFBD>С<EFBFBD><D0A1>
#define ERXRDPTL (0x0C|0x00)
#define ERXRDPTH (0x0D|0x00)
#define ERXWRPTL (0x0E|0x00)
#define ERXWRPTH (0x0F|0x00)
#define EDMASTL (0x10|0x00)
#define EDMASTH (0x11|0x00)
#define EDMANDL (0x12|0x00)
#define EDMANDH (0x13|0x00)
#define EDMADSTL (0x14|0x00)
#define EDMADSTH (0x15|0x00)
#define EDMACSL (0x16|0x00)
#define EDMACSH (0x17|0x00)
// Bank 1 registers
#define EHT0 (0x00|0x20)
#define EHT1 (0x01|0x20)
#define EHT2 (0x02|0x20)
#define EHT3 (0x03|0x20)
#define EHT4 (0x04|0x20)
#define EHT5 (0x05|0x20)
#define EHT6 (0x06|0x20)
#define EHT7 (0x07|0x20)
#define EPMM0 (0x08|0x20)
#define EPMM1 (0x09|0x20)
#define EPMM2 (0x0A|0x20)
#define EPMM3 (0x0B|0x20)
#define EPMM4 (0x0C|0x20)
#define EPMM5 (0x0D|0x20)
#define EPMM6 (0x0E|0x20)
#define EPMM7 (0x0F|0x20)
#define EPMCSL (0x10|0x20)
#define EPMCSH (0x11|0x20)
#define EPMOL (0x14|0x20)
#define EPMOH (0x15|0x20)
#define EWOLIE (0x16|0x20)
#define EWOLIR (0x17|0x20)
#define ERXFCON (0x18|0x20)
#define EPKTCNT (0x19|0x20)
// Bank 2 registers
#define MACON1 (0x00|0x40|0x80)
#define MACON2 (0x01|0x40|0x80)
#define MACON3 (0x02|0x40|0x80)
#define MACON4 (0x03|0x40|0x80)
#define MABBIPG (0x04|0x40|0x80)
#define MAIPGL (0x06|0x40|0x80)
#define MAIPGH (0x07|0x40|0x80)
#define MACLCON1 (0x08|0x40|0x80)
#define MACLCON2 (0x09|0x40|0x80)
#define MAMXFLL (0x0A|0x40|0x80)
#define MAMXFLH (0x0B|0x40|0x80)
#define MAPHSUP (0x0D|0x40|0x80)
#define MICON (0x11|0x40|0x80)
#define MICMD (0x12|0x40|0x80)
#define MIREGADR (0x14|0x40|0x80)
#define MIWRL (0x16|0x40|0x80)
#define MIWRH (0x17|0x40|0x80)
#define MIRDL (0x18|0x40|0x80)
#define MIRDH (0x19|0x40|0x80)
// Bank 3 registers
#define MAADR1 (0x00|0x60|0x80)
#define MAADR0 (0x01|0x60|0x80)
#define MAADR3 (0x02|0x60|0x80)
#define MAADR2 (0x03|0x60|0x80)
#define MAADR5 (0x04|0x60|0x80)
#define MAADR4 (0x05|0x60|0x80)
#define EBSTSD (0x06|0x60)
#define EBSTCON (0x07|0x60)
#define EBSTCSL (0x08|0x60)
#define EBSTCSH (0x09|0x60)
#define MISTAT (0x0A|0x60|0x80)
#define EREVID (0x12|0x60)
#define ECOCON (0x15|0x60)
#define EFLOCON (0x17|0x60)
#define EPAUSL (0x18|0x60)
#define EPAUSH (0x19|0x60)
// PHY registers
#define PHCON1 0x00
#define PHSTAT1 0x01
#define PHHID1 0x02
#define PHHID2 0x03
#define PHCON2 0x10
#define PHSTAT2 0x11
#define PHIE 0x12
#define PHIR 0x13
#define PHLCON 0x14
// ENC28J60 ERXFCON Register Bit Definitions
#define ERXFCON_UCEN 0x80
#define ERXFCON_ANDOR 0x40
#define ERXFCON_CRCEN 0x20
#define ERXFCON_PMEN 0x10
#define ERXFCON_MPEN 0x08
#define ERXFCON_HTEN 0x04
#define ERXFCON_MCEN 0x02
#define ERXFCON_BCEN 0x01
// ENC28J60 EIE Register Bit Definitions
#define EIE_INTIE 0x80
#define EIE_PKTIE 0x40
#define EIE_DMAIE 0x20
#define EIE_LINKIE 0x10
#define EIE_TXIE 0x08
#define EIE_WOLIE 0x04
#define EIE_TXERIE 0x02
#define EIE_RXERIE 0x01
// ENC28J60 EIR Register Bit Definitions
#define EIR_PKTIF 0x40
#define EIR_DMAIF 0x20
#define EIR_LINKIF 0x10
#define EIR_TXIF 0x08
#define EIR_WOLIF 0x04
#define EIR_TXERIF 0x02
#define EIR_RXERIF 0x01
// ENC28J60 ESTAT Register Bit Definitions
#define ESTAT_INT 0x80
#define ESTAT_LATECOL 0x10
#define ESTAT_RXBUSY 0x04
#define ESTAT_TXABRT 0x02
#define ESTAT_CLKRDY 0x01
// ENC28J60 ECON2 Register Bit Definitions
#define ECON2_AUTOINC 0x80
#define ECON2_PKTDEC 0x40
#define ECON2_PWRSV 0x20
#define ECON2_VRPS 0x08
// ENC28J60 ECON1 Register Bit Definitions
#define ECON1_TXRST 0x80
#define ECON1_RXRST 0x40
#define ECON1_DMAST 0x20
#define ECON1_CSUMEN 0x10
#define ECON1_TXRTS 0x08
#define ECON1_RXEN 0x04
#define ECON1_BSEL1 0x02
#define ECON1_BSEL0 0x01
// ENC28J60 MACON1 Register Bit Definitions
#define MACON1_LOOPBK 0x10
#define MACON1_TXPAUS 0x08
#define MACON1_RXPAUS 0x04
#define MACON1_PASSALL 0x02
#define MACON1_MARXEN 0x01
// ENC28J60 MACON2 Register Bit Definitions
#define MACON2_MARST 0x80
#define MACON2_RNDRST 0x40
#define MACON2_MARXRST 0x08
#define MACON2_RFUNRST 0x04
#define MACON2_MATXRST 0x02
#define MACON2_TFUNRST 0x01
// ENC28J60 MACON3 Register Bit Definitions
#define MACON3_PADCFG2 0x80
#define MACON3_PADCFG1 0x40
#define MACON3_PADCFG0 0x20
#define MACON3_TXCRCEN 0x10
#define MACON3_PHDRLEN 0x08
#define MACON3_HFRMLEN 0x04
#define MACON3_FRMLNEN 0x02
#define MACON3_FULDPX 0x01
// ENC28J60 MICMD Register Bit Definitions
#define MICMD_MIISCAN 0x02
#define MICMD_MIIRD 0x01
// ENC28J60 MISTAT Register Bit Definitions
#define MISTAT_NVALID 0x04
#define MISTAT_SCAN 0x02
#define MISTAT_BUSY 0x01
// ENC28J60 PHY PHCON1 Register Bit Definitions
#define PHCON1_PRST 0x8000
#define PHCON1_PLOOPBK 0x4000
#define PHCON1_PPWRSV 0x0800
#define PHCON1_PDPXMD 0x0100
// ENC28J60 PHY PHSTAT1 Register Bit Definitions
#define PHSTAT1_PFDPX 0x1000
#define PHSTAT1_PHDPX 0x0800
#define PHSTAT1_LLSTAT 0x0004
#define PHSTAT1_JBSTAT 0x0002
// ENC28J60 PHY PHCON2 Register Bit Definitions
#define PHCON2_FRCLINK 0x4000
#define PHCON2_TXDIS 0x2000
#define PHCON2_JABBER 0x0400
#define PHCON2_HDLDIS 0x0100
// ENC28J60 Packet Control Byte Bit Definitions
#define PKTCTRL_PHUGEEN 0x08
#define PKTCTRL_PPADEN 0x04
#define PKTCTRL_PCRCEN 0x02
#define PKTCTRL_POVERRIDE 0x01
// SPI operation codes
#define ENC28J60_READ_CTRL_REG 0x00
#define ENC28J60_READ_BUF_MEM 0x3A
#define ENC28J60_WRITE_CTRL_REG 0x40
#define ENC28J60_WRITE_BUF_MEM 0x7A
#define ENC28J60_BIT_FIELD_SET 0x80
#define ENC28J60_BIT_FIELD_CLR 0xA0
#define ENC28J60_SOFT_RESET 0xFF
// The RXSTART_INIT should be zero. See Rev. B4 Silicon Errata
// buffer boundaries applied to internal 8K ram
// the entire available packet buffer space is allocated
//
// start with recbuf at 0/
#define RXSTART_INIT 0x0
// receive buffer end
#define RXSTOP_INIT (0x1FFF-1518-1)
// start TX buffer at 0x1FFF-0x0600, pace for one full ethernet frame (0~1518 bytes)
#define TXSTART_INIT (0x1FFF-1518)
// stp TX buffer at end of mem
#define TXSTOP_INIT 0x1FFF
// max frame length which the conroller will accept:
#define MAX_FRAMELEN 1518 // (note: maximum ethernet frame length would be 1518)
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//GPIOA->ODR |= (unsigned int)(1<<ENC28J60_CS);
//#define ENC28J60_CS PGout(8) //ENC28J60Ƭѡ<C6AC>ź<EFBFBD>
//#define ENC28J60_RST PGout(6) //ENC28J60<36><30>λ<EFBFBD>ź<EFBFBD>
#define ENC28J60_CSH (GPIOA->ODR |= (unsigned int)(1<<4))
#define ENC28J60_CSL (GPIOA->ODR &= ~((unsigned int)(1<<4)))
//SPI1<49><31>ʼ<EFBFBD><CABC>
void ENC28J60_Reset(void);
u8 ENC28J60_Read_Op(u8 op,u8 addr);
void ENC28J60_Write_Op(u8 op,u8 addr,u8 data);
void ENC28J60_Read_Buf(u32 len,u8* data);
void ENC28J60_Write_Buf(u32 len,u8* data);
void ENC28J60_Set_Bank(u8 bank);
u8 ENC28J60_Read(u8 addr);
void ENC28J60_Write(u8 addr,u8 data);
void ENC28J60_PHY_Write(u8 addr,u32 data);
u8 ENC28J60_Init(u8* macaddr);
u8 ENC28J60_Get_EREVID(void);
void ENC28J60_Packet_Send(u32 len,u8* packet);
u32 ENC28J60_Packet_Receive(u32 maxlen,u8* packet);
#endif

View File

@ -0,0 +1,155 @@
#include "bsp.h"
data_common data_common1;
FIL fp; /* Pointer to the blank file object */
FATFS fs;
UINT btw; /* Number of bytes to write */
UINT bws;
u32 send_pos=0;
DIR DirInf;
FILINFO FileInf;
/*
<EFBFBD><EFBFBD><EFBFBD>ܣ<EFBFBD>TF<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><EFBFBD>
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>fname
dat
len
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*/
void FATFS_WriteFile(char *fname,char *dat,u16 len) //д<><D0B4><EFBFBD>ݵ<EFBFBD>SD<53><44>
{
UINT br;
char name[20];
sprintf(name,"%s%s",fname,".txt");
f_mount(0,&fs);
f_open (&fp,fname,FA_READ|FA_WRITE|FA_OPEN_ALWAYS);
f_lseek(&fp,f_size(&fp)); //<2F>ƶ<EFBFBD><C6B6><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>ĩβ--׷<><D7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
f_write(&fp,dat,len,&br);
f_close(&fp);
f_mount(0,NULL);
}
/*
<EFBFBD><EFBFBD><EFBFBD>ܣ<EFBFBD>TF<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><EFBFBD> ʱ<><EFBFBD><E4A1A2>ѹ<EFBFBD><D1B9><EFBFBD><EFBFBD>γ<EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>Ρ<EFBFBD><CEA1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>fname
dat
len
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*/
FRESULT Data_Write_TF(void)//,char *dat,u16 len
{
FRESULT res;
u8 i=0;
char name[10]="\0";
f_mount(0,&fs);
res=f_open(&fp,name,FA_READ | FA_WRITE | FA_OPEN_ALWAYS );//0:/
if(res!=FR_OK) //<2F><><EFBFBD><EFBFBD>ʧ<EFBFBD><CAA7>
{
i=0;
while((res!=FR_OK)&(i<100))
{
i++;
f_close(&fp);
f_mount(0,NULL);
f_mount(0,&fs);
res=f_open(&fp,name,FA_READ | FA_WRITE | FA_OPEN_ALWAYS );//0:/
}
if(i>98)return FR_NO_PATH ;
}
f_lseek (&fp,f_size(&fp));
f_write(&fp,data_common1.Pack_data,strlen(data_common1.Pack_data),&bws);
f_write(&fp,"\r\n",2,&bws);
f_close(&fp);
return FR_OK;
}
/*************<2A>ļ<EFBFBD>ɾ<EFBFBD><C9BE>*******************************/
FRESULT Fil_delete(char *names)
{
FRESULT result;
char namebuff[10]="\0";
sprintf(namebuff,"%s",names);
f_mount(0,&fs);
result = f_unlink(namebuff);
f_close(&fp);
f_mount(0,NULL);
return result;
}
//<2F><>ȡ<EFBFBD>ļ<EFBFBD><C4BC>Ĵ<EFBFBD>Сbyte
u32 txt_size_read(char *fname)
{
// u8 i=0;
FRESULT res;
u32 txt_size;
char name[20];
sprintf(name,"%s%s",fname,".txt");
res=f_mount(0,&fs);
res=f_open(&fp,"APP.bin",FA_READ);//0:/
if(res!=FR_OK) //<2F><><EFBFBD><EFBFBD>ʧ<EFBFBD><CAA7>
{
return FR_NO_FILE;
}
txt_size=f_size(&fp);
res=f_close(&fp);
f_mount(0,NULL);
return txt_size;
}
/*
<EFBFBD><EFBFBD><EFBFBD>ܣ<EFBFBD>TF<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݶ<EFBFBD>ȡ
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>start_pos
len
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD>ԣ<EFBFBD><EFBFBD>ô<EFBFBD><EFBFBD><EFBFBD>1<EFBFBD><EFBFBD>ӡ <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD>ض<EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*/
void FATFS_Read_TF(char *fname,u32 start_pos,u32 len)
{
//u16 time1=0;
FRESULT res;
u32 tf_sendpos=0;
u8 times;
u32 i,lens_quotient,len_remainder;//<2F>̣<EFBFBD><CCA3><EFBFBD><EFBFBD><EFBFBD>
uint8_t Tf_Read_Buff[max_transmission+1];
lens_quotient=len/max_transmission;
len_remainder=len%max_transmission;
memset(Tf_Read_Buff,0,sizeof(Tf_Read_Buff));
res=f_mount(0,&fs);
res=f_open(&fp,fname,FA_READ);
times=0;
while((res!=FR_OK)&(times<100))
{
res=f_close(&fp);
res=f_mount(0,&fs);
res=f_open(&fp,fname,FA_READ);
times++;
if(times==100)return;
}
f_lseek(&fp, start_pos+tf_sendpos);
for(i=0;i<lens_quotient;i++)//<2F><><EFBFBD>ʹ<EFBFBD><CDB4><EFBFBD><EFBFBD><EFBFBD>max_transmission<6F>ֽ<EFBFBD>
{
res=f_read(&fp,Tf_Read_Buff,max_transmission,&bws);
FLASH_WriteWord(APP_ADDR+(i*max_transmission),Tf_Read_Buff,max_transmission);
}
memset(Tf_Read_Buff,0,sizeof(Tf_Read_Buff));
f_read(&fp,Tf_Read_Buff,len_remainder,&bws);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֽ<EFBFBD>
FLASH_WriteWord(APP_ADDR+(i*max_transmission),Tf_Read_Buff,len_remainder);
res=f_close(&fp);
f_mount(0,NULL);
}
u8 App_check(void)
{
uint8_t buff[10];
f_mount(0,&fs);
f_open(&fp,"AAP.bin",FA_READ);
f_read(&fp,buff,10,&bws);
if(((*(vu32*)(buff+4))&0xFF000000)==0x08000000)//<2F>ж<EFBFBD><D0B6>Ƿ<EFBFBD>Ϊ0X08XXXXXX.
{
return 0;
}
return 1;
}

View File

@ -0,0 +1,26 @@
#ifndef _DATA_HANDLE_H
#define _DATA_HANDLE_H
#include "bsp.h"
#define max_transmission 200
typedef struct
{
char Pack_data[500];
char Time_DATA[30];
char ADC_DATA[10];
char GPS_DATA[100];
char SDI_DATA[300];
//char GSM_DATA[100];
// char RS485_DATA[10];
// char WIFI_DATA[100];
}data_common;
extern data_common data_common1;
FRESULT Data_Write_TF(void);//,char *dat,u16 len
void FATFS_Read_TF(char *fname,u32 start_pos,u32 len);
u32 txt_size_read(char *fname);
void FATFS_WriteFile(char *fname,char *dat,u16 len); //д<><D0B4><EFBFBD>ݵ<EFBFBD>SD<53><44>
void Common_Data_Pack(void);//<2F><><EFBFBD>ɼ<EFBFBD><C9BC><EFBFBD><EFBFBD><EFBFBD>ȫ<EFBFBD><C8AB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
static void ViewRootDir(void);//<2F><>ȡ<EFBFBD>ļ<EFBFBD>Ŀ¼ <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
FRESULT Fil_delete(char *names);//ɾ<><C9BE><EFBFBD><EFBFBD>Ŀ¼<C4BF>ļ<EFBFBD>
#endif

View File

@ -0,0 +1,59 @@
* {margin: 0; padding: 0; border-width: 0;}
body {margin: 8px; background-color: #e0ffff; font-color: black; font-family: serif; line-height: 133%; max-width: 1024px;}
a:link {color: blue;}
a:visited {color: darkmagenta;}
a:hover {background-color: #a0ffff;}
a:active {color: darkmagenta; overflow: hidden; outline:none; position: relative; top: 1px; left: 1px;}
abbr {border-width: 1px;}
p {margin: 0 0 0.3em 1em;}
em {font-style: normal; font-weight: bold; margin: 0 0.1em;}
pre em {font-style: italic; font-weight: normal;}
strong {}
pre {border: 1px dashed gray; margin: 0.5em 1em; padding: 0.5em; line-height: 1.2em; font-family: monospace; background-color: white;}
pre span.c {color: green;}
pre span.k {color: blue;}
tt {margin: 0 0.2em; font-family: monospace; }
ol {margin: 0 2.5em;}
ul {margin: 0 2em;}
dl {margin: 0 1em;}
dt {font-family: monospace;}
dl.par dt {margin: 0.5em 0 0 0 ; font-style: italic; }
dl.ret dt {margin: 0.5em 0 0 0 ; font-weight: bold;}
dd {margin: 0 2em;}
hr {border-width: 1px; margin: 1em;}
div.abst {font-family: sans-serif;}
div.para {clear: both; font-family: serif;}
div.ret a {font-family: monospace; }
.equ {text-indent: 0; margin: 1em 2em 1em;}
.indent {margin-left: 2em;}
.rset {float: right; margin: 0 0 0.5em 0.5em;}
.lset {float: left; margin: 0 0.5em 0.5em 0.5em;}
ul.flat li {list-style-type: none; margin: 0;}
a.imglnk img {border: 1px solid;}
.iequ {white-space: nowrap; font-weight: bold;}
.clr {clear: both;}
.it {font-style: italic;}
.mfd {font-size: 0.7em; padding: 0 1px; border: 1px solid; white-space : nowrap}
h1 {line-height: 1em; font-size: 2em; font-family: sans-serif; padding: 0.3em 0 0.3em;}
p.hdd {float: right; text-align: right; margin-top: 0.5em;}
hr.hds {clear: both; margin-bottom: 1em;}
h2 {font-size: 1.6em; font-family: sans-serif; background-color: #d8d8FF; padding: 0.2em 0.5em; margin: 0 0 0.5em;}
h3 {font-size: 1.5em; font-family: sans-serif; margin: 1.5em 0 0.5em;}
h4 {font-size: 1.2em; font-family: sans-serif; margin: 1em 0 0.2em;}
h5 {font-size: 1em; font-family: sans-serif; margin: 0.5em 0 0em;}
small {font-size: 80%;}
.indent {margin-left: 2em;}
/* Tables */
table {margin: 0.5em 1em; border-collapse: collapse; border: 2px solid black; }
th {background-color: white; border-style: solid; border-width: 1px 1px 2px; border-color: black; padding: 0 3px; vertical-align: top; white-space: nowrap;}
td {background-color: white; border: 1px solid black; padding: 0 3px; vertical-align: top; line-height: 1.3em;}
table.lst td:first-child {font-family: monospace;}
table.lst2 td {font-family: monospace;}
table caption {font-family: sans-serif; font-weight: bold;}
tr.lst3 td { border-width: 2px 1px 1px; }
p.foot {clear: both; text-indent: 0; margin: 1em 0.5em 1em;}

View File

@ -0,0 +1,62 @@
@charset "Shift_JIS";
/* Common style sheet for Tech Notes */
* {margin: 0; padding: 0; border-width: 0;}
body {margin: 8px; background-color: #e0ffff; font-color: black; font-family:"<22>l<EFBFBD>r <20>o<EFBFBD><6F><EFBFBD><EFBFBD>", serif; line-height: 150%; letter-spacing: 1px; max-width: 1024px;}
a:link {color: blue;}
a:visited {color: darkmagenta;}
a:hover {background-color: #a0ffff;}
a:active {color: darkmagenta; overflow: hidden; outline:none; position: relative; top: 1px; left: 1px;}
abbr {border-width: 1px;}
p {text-indent: 1em; margin: 0 0 0.3em 0.5em;}
em {font-style: normal; font-weight: bold; margin: 0 0.1em;}
pre em {font-style: italic; font-weight: normal;}
strong {}
pre {border: 1px dashed gray; margin: 0.5em 1em; padding: 0.5em; line-height: 1.2em; letter-spacing: 0; font-family: monospace; background-color: white;}
pre span.c {color: green;}
pre span.k {color: blue;}
tt {margin: 0 0.2em; letter-spacing: 0; font-family: monospace; }
ol {margin: 0 2.5em;}
ul {margin: 0 2em;}
dl {margin: 0 1em;}
dt {font-family: monospace;}
dl.par dt {margin: 0.5em 0 0 0 ; font-style: italic; letter-spacing: 0;}
dl.ret dt {margin: 0.5em 0 0 0 ; font-family: monospace; letter-spacing: 0; font-weight: bold;}
dd {margin: 0 2em;}
hr {border-width: 1px; margin: 1em;}
div.abst {font-family: "<22>l<EFBFBD>r <20>o<EFBFBD>S<EFBFBD>V<EFBFBD>b<EFBFBD>N",sans-serif;}
div.para {clear: both; font-family: "<22>l<EFBFBD>r <20>o<EFBFBD><6F><EFBFBD><EFBFBD>",serif;}
div.ret a {font-family: monospace; }
.equ {text-indent: 0; margin: 1em 2em 1em;}
.indent {margin-left: 2em;}
.rset {float: right; margin: 0 0 0.5em 0.5em;}
.lset {float: left; margin: 0 0.5em 0.5em 0.5em;}
ul.flat li {list-style-type: none; margin: 0;}
a.imglnk img {border: 1px solid;}
.iequ {white-space: nowrap; font-weight: bold;}
.clr {clear: both;}
.it {font-style: italic;}
.mfd {font-size: 0.7em; padding: 0 1px; border: 1px solid; white-space : nowrap}
h1 {line-height: 1em; font-size: 2em; font-family: sans-serif; padding: 0.3em 0 0.3em;}
p.hdd {float: right; text-align: right; margin-top: 0.5em;}
hr.hds {clear: both; margin-bottom: 1em;}
h2 {font-size: 1.6em; font-family: "<22>l<EFBFBD>r <20>o<EFBFBD>S<EFBFBD>V<EFBFBD>b<EFBFBD>N",sans-serif; background-color: #d8d8FF; padding: 0.2em 0.5em; margin: 0 0 0.5em;}
h3 {font-size: 1.5em; font-family: "<22>l<EFBFBD>r <20>o<EFBFBD>S<EFBFBD>V<EFBFBD>b<EFBFBD>N",sans-serif; margin: 1.5em 0 0.5em;}
h4 {font-size: 1.2em; font-family: "<22>l<EFBFBD>r <20>o<EFBFBD>S<EFBFBD>V<EFBFBD>b<EFBFBD>N",sans-serif; margin: 1em 0 0.2em;}
h5 {font-size: 1em; font-family: "<22>l<EFBFBD>r <20>o<EFBFBD>S<EFBFBD>V<EFBFBD>b<EFBFBD>N",sans-serif; margin: 0.5em 0 0em;}
small {font-size: 80%;}
.indent {margin-left: 2em;}
/* Tables */
table {margin: 0.5em 1em; border-collapse: collapse; border: 2px solid black; letter-spacing: 0;}
th {background-color: white; border-style: solid; border-width: 1px 1px 2px; border-color: black; padding: 0 3px; vertical-align: top;}
td {background-color: white; border: 1px solid black; padding: 0 3px; vertical-align: top; line-height: 1.3em;}
table.lst td:first-child {font-family: monospace; white-space: nowrap;}
table.lst2 td {font-family: monospace; white-space: nowrap;}
table caption {font-family: sans-serif; font-weight: bold;}
tr.lst3 td {border-width: 2px 1px 1px; }
p.foot {clear: both; text-indent: 0; margin: 1em 0.5em 1em;}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

View File

@ -0,0 +1,114 @@
R0.09, Sep 6, 2011
f_mkfs() supports multiple partition to finish the multiple partition feature.
Added f_fdisk(). (_MULTI_PARTITION = 2)
R0.08b, Jan 15, 2011
Fast seek feature is also applied to f_read() and f_write().
f_lseek() reports required table size on creating CLMP.
Extended format syntax of f_printf function.
Ignores duplicated directory separators in given path names.
R0.08a, Aug 16, 2010
Added f_getcwd(). (_FS_RPATH = 2)
Added sector erase feature. (_USE_ERASE)
Moved file lock semaphore table from fs object to the bss.
Fixed a wrong directory entry is created on non-LFN cfg when the given name contains ';'.
Fixed f_mkfs() creates wrong FAT32 volume.
R0.08, May 15, 2010
Added a memory configuration option. (_USE_LFN)
Added file lock feature. (_FS_SHARE)
Added fast seek feature. (_USE_FASTSEEK)
Changed some types on the API, XCHAR->TCHAR.
Changed fname member in the FILINFO structure on Unicode cfg.
String functions support UTF-8 encoding files on Unicode cfg.
R0.07e, Nov 3, 2009
Separated out configuration options from ff.h to ffconf.h.
Added a configuration option, _LFN_UNICODE.
Fixed f_unlink() fails to remove a sub-dir on _FS_RPATH.
Fixed name matching error on the 13 char boundary.
Changed f_readdir() to return the SFN with always upper case on non-LFN cfg.
R0.07c, Jun 21, 2009
Fixed f_unlink() may return FR_OK on error.
Fixed wrong cache control in f_lseek().
Added relative path feature.
Added f_chdir().
Added f_chdrive().
Added proper case conversion to extended characters.
R0.07a, Apr 14, 2009
Separated out OS dependent code on re-entrant configuration.
Added multiple sector size support.
R0.07, Apr 01, 2009
Merged Tiny-FatFs into FatFs as a buffer configuration option.
Added long file name support.
Added multiple code page support.
Added re-entrancy for multitask operation.
Added auto cluster size selection to f_mkfs().
Added rewind option to f_readdir().
Changed result code of critical errors.
Renamed string functions to avoid name collision.
R0.06, Apr 01, 2008
Added f_forward. (Tiny-FatFs)
Added string functions: fgets, fputc, fputs and fprintf.
Improved performance of f_lseek on moving to the same or following cluster.
R0.05a, Feb 03, 2008
Added f_truncate.
Added f_utime.
Fixed off by one error at FAT sub-type determination.
Fixed btr in f_read can be mistruncated.
Fixed cached sector is left not flushed when create and close without write.
R0.05, Aug 26, 2007
Changed arguments of f_read, f_write.
Changed arguments of f_mkfs. (FatFs)
Fixed f_mkfs on FAT32 creates incorrect FSInfo. (FatFs)
Fixed f_mkdir on FAT32 creates incorrect directory. (FatFs)
R0.04b, May 05, 2007
Added _USE_NTFLAG option.
Added FSInfo support.
Fixed some problems corresponds to FAT32. (Tiny-FatFs)
Fixed DBCS name can result FR_INVALID_NAME.
Fixed short seek (<= csize) collapses the file object.
R0.04a, Apr 01, 2007
Supported multiple partitions on a plysical drive. (FatFs)
Added minimization level 3.
Added a capability of extending file size to f_lseek.
Fixed an endian sensitive code in f_mkfs. (FatFs)
Fixed a problem corresponds to FAT32 support. (Tiny-FatFs)
R0.04, Feb 04, 2007
Supported multiple drive system. (FatFs)
Changed some APIs for multiple drive system.
Added f_mkfs. (FatFs)
Added _USE_FAT32 option. (Tiny-FatFs)
R0.03a, Dec 11, 2006
Improved cluster scan algolithm to write files fast.
Fixed f_mkdir creates incorrect directory on FAT32.
R0.03, Sep 22, 2006
Added f_rename.
Changed option _FS_MINIMUM to _FS_MINIMIZE.
R0.02a, Jun 10, 2006
Added a configuration option _FS_MINIMUM.
R0.02, Jun 01, 2006
Added FAT12.
Removed unbuffered mode.
Fixed a problem on small (<32M) patition.
R0.01, Apr 29, 2006
First release
R0.00, Feb 26, 2006
Prototype (not released)

View File

@ -0,0 +1,147 @@
#include "string.h"
#include "exfuns.h"
#include "fattester.h"
#include "malloc.h"
#include "usart.h"
//////////////////////////////////////////////////////////////////////////////////
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֻ<EFBFBD><D6BB>ѧϰʹ<CFB0>ã<EFBFBD>δ<EFBFBD><CEB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɣ<EFBFBD><C9A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>κ<EFBFBD><CEBA><EFBFBD>;
//ALIENTEKս<4B><D5BD>STM32<33><32><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//FATFS <20><>չ<EFBFBD><D5B9><EFBFBD><EFBFBD>
//<2F><><EFBFBD><EFBFBD>ԭ<EFBFBD><D4AD>@ALIENTEK
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̳:www.openedv.com
//<2F>޸<EFBFBD><DEB8><EFBFBD><EFBFBD><EFBFBD>:2012/9/18
//<2F><EFBFBD><E6B1BE>V1.0
//<2F><>Ȩ<EFBFBD><C8A8><EFBFBD>У<EFBFBD><D0A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ؾ<EFBFBD><D8BE><EFBFBD>
//Copyright(C) <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӿƼ<D3BF><C6BC><EFBFBD><EFBFBD>޹<EFBFBD>˾ 2009-2019
//All rights reserved
//////////////////////////////////////////////////////////////////////////////////
//<2F>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>б<EFBFBD>
const u8 *FILE_TYPE_TBL[6][13]=
{
{"BIN"}, //BIN<49>ļ<EFBFBD>
{"LRC"}, //LRC<52>ļ<EFBFBD>
{"NES"}, //NES<45>ļ<EFBFBD>
{"TXT","C","H"}, //<2F>ı<EFBFBD><C4B1>ļ<EFBFBD>
{"MP1","MP2","MP3","MP4","M4A","3GP","3G2","OGG","ACC","WMA","WAV","MID","FLAC"},//<2F><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>
{"BMP","JPG","JPEG","GIF"},//ͼƬ<CDBC>ļ<EFBFBD>
};
///////////////////////////////<2F><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>,ʹ<><CAB9>malloc<6F><63>ʱ<EFBFBD><CAB1>////////////////////////////////////////////
FATFS *fs[2]; //<2F>߼<EFBFBD><DFBC><EFBFBD><EFBFBD>̹<EFBFBD><CCB9><EFBFBD><EFBFBD><EFBFBD>.
FIL *file; //<2F>ļ<EFBFBD>1
FIL *ftemp; //<2F>ļ<EFBFBD>2.
UINT br,bw; //<2F><>д<EFBFBD><D0B4><EFBFBD><EFBFBD>
FILINFO fileinfo; //<2F>ļ<EFBFBD><C4BC><EFBFBD>Ϣ
DIR dir; //Ŀ¼
u8 *fatbuf; //SD<53><44><EFBFBD><EFBFBD><EFBFBD>ݻ<EFBFBD><DDBB><EFBFBD><EFBFBD><EFBFBD>
///////////////////////////////////////////////////////////////////////////////////////
//Ϊexfuns<6E><73><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>
//<2F><><EFBFBD><EFBFBD>ֵ:0,<2C>ɹ<EFBFBD>
//1,ʧ<><CAA7>
u8 exfuns_init(void)
{
fs[0]=(FATFS*)mymalloc(SRAMIN,sizeof(FATFS)); //Ϊ<><CEAA><EFBFBD><EFBFBD>0<EFBFBD><30><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>
fs[1]=(FATFS*)mymalloc(SRAMIN,sizeof(FATFS)); //Ϊ<><CEAA><EFBFBD><EFBFBD>1<EFBFBD><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>
file=(FIL*)mymalloc(SRAMIN,sizeof(FIL)); //Ϊfile<6C><65><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>
ftemp=(FIL*)mymalloc(SRAMIN,sizeof(FIL)); //Ϊftemp<6D><70><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>
fatbuf=(u8*)mymalloc(SRAMIN,512); //Ϊfatbuf<75><66><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>
if(fs[0]&&fs[1]&&file&&ftemp&&fatbuf)return 0; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>ʧ<EFBFBD><CAA7>,<2C><>ʧ<EFBFBD><CAA7>.
else return 1;
}
//<2F><>Сд<D0A1><D0B4>ĸתΪ<D7AA><CEAA>д<EFBFBD><D0B4>ĸ,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<2C>򱣳ֲ<F2B1A3B3><D6B2><EFBFBD>.
u8 char_upper(u8 c)
{
if(c<'A')return c;//<2F><><EFBFBD><EFBFBD>,<2C><><EFBFBD>ֲ<EFBFBD><D6B2><EFBFBD>.
if(c>='a')return c-0x20;//<2F><>Ϊ<EFBFBD><CEAA>д.
else return c;//<2F><>д,<2C><><EFBFBD>ֲ<EFBFBD><D6B2><EFBFBD>
}
//<2F><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//fname:<3A>ļ<EFBFBD><C4BC><EFBFBD>
//<2F><><EFBFBD><EFBFBD>ֵ:0XFF,<2C><>ʾ<EFBFBD>޷<EFBFBD>ʶ<EFBFBD><CAB6><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD>ͱ<EFBFBD><CDB1><EFBFBD>.
// <20><><EFBFBD><EFBFBD>,<2C><><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<2C><><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD>С<EFBFBD><D0A1>.
u8 f_typetell(u8 *fname)
{
u8 tbuf[5];
u8 *attr='\0';//<2F><>׺<EFBFBD><D7BA>
u8 i=0,j;
while(i<250)
{
i++;
if(*fname=='\0')break;//ƫ<>Ƶ<EFBFBD><C6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.
fname++;
}
if(i==250)return 0XFF;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>.
for(i=0;i<5;i++)//<2F>õ<EFBFBD><C3B5><EFBFBD>׺<EFBFBD><D7BA>
{
fname--;
if(*fname=='.')
{
fname++;
attr=fname;
break;
}
}
strcpy((char *)tbuf,(const char*)attr);//copy
for(i=0;i<4;i++)tbuf[i]=char_upper(tbuf[i]);//ȫ<><C8AB><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>д
for(i=0;i<6;i++)
{
for(j=0;j<13;j++)
{
if(*FILE_TYPE_TBL[i][j]==0)break;//<2F><><EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD>û<EFBFBD>пɶԱȵij<C8B5>Ա<EFBFBD><D4B1>.
if(strcmp((const char *)FILE_TYPE_TBL[i][j],(const char *)tbuf)==0)//<2F>ҵ<EFBFBD><D2B5><EFBFBD>
{
return (i<<4)|j;
}
}
}
return 0XFF;//û<>ҵ<EFBFBD>
}
//<2F>õ<EFBFBD><C3B5><EFBFBD><EFBFBD><EFBFBD>ʣ<EFBFBD><CAA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//drv:<3A><><EFBFBD>̱<EFBFBD><CCB1><EFBFBD>("0:"/"1:")
//total:<3A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>λKB<4B><42>
//free:ʣ<><CAA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>λKB<4B><42>
//<2F><><EFBFBD><EFBFBD>ֵ:0,<2C><><EFBFBD><EFBFBD>.<2E><><EFBFBD><EFBFBD>,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
u8 exf_getfree(u8 *drv,u32 *total,u32 *free)
{
FATFS *fs1;
u8 res;
DWORD fre_clust=0, fre_sect=0, tot_sect=0;
//<2F>õ<EFBFBD><C3B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD>
res = f_getfree((const TCHAR*)drv, &fre_clust, &fs1);
if(res==0)
{
tot_sect=(fs1->n_fatent-2)*fs1->csize; //<2F>õ<EFBFBD><C3B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
fre_sect=fre_clust*fs1->csize; //<2F>õ<EFBFBD><C3B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
#if _MAX_SS!=512 //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>С<EFBFBD><D0A1><EFBFBD><EFBFBD>512<31>ֽ<EFBFBD>,<2C><>ת<EFBFBD><D7AA>Ϊ512<31>ֽ<EFBFBD>
tot_sect*=fs1->ssize/512;
fre_sect*=fs1->ssize/512;
#endif
*total=tot_sect>>1; //<2F><>λΪKB
*free=fre_sect>>1; //<2F><>λΪKB
}
return res;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////

View File

@ -0,0 +1,42 @@
#ifndef __EXFUNS_H
#define __EXFUNS_H
//#include "sys.h"
#include "ff.h"
/////////////////////////////////////////////////////////////////////////////////////////////////////
extern FATFS *fs[2];
extern FIL *file;
extern FIL *ftemp;
extern UINT br,bw;
extern FILINFO fileinfo;
extern DIR dir;
extern u8 *fatbuf;//SD<53><44><EFBFBD><EFBFBD><EFBFBD>ݻ<EFBFBD><DDBB><EFBFBD><EFBFBD><EFBFBD>
//f_typetell<6C><6C><EFBFBD>ص<EFBFBD><D8B5><EFBFBD><EFBFBD>Ͷ<EFBFBD><CDB6><EFBFBD>
//<2F><><EFBFBD>ݱ<EFBFBD>FILE_TYPE_TBL<42><4C><EFBFBD><EFBFBD>.<2E><>exfuns.c<><63><EFBFBD><EFBFBD><E6B6A8>
#define T_BIN 0X00 //bin<69>ļ<EFBFBD>
#define T_LRC 0X10 //lrc<72>ļ<EFBFBD>
#define T_NES 0X20 //nes<65>ļ<EFBFBD>
#define T_TEXT 0X30 //.txt<78>ļ<EFBFBD>
#define T_C 0X31 //.c<>ļ<EFBFBD>
#define T_H 0X32 //.h<>ļ<EFBFBD>
#define T_FLAC 0X4C //flac<61>ļ<EFBFBD>
#define T_BMP 0X50 //bmp<6D>ļ<EFBFBD>
#define T_JPG 0X51 //jpg<70>ļ<EFBFBD>
#define T_JPEG 0X52 //jpeg<65>ļ<EFBFBD>
#define T_GIF 0X53 //gif<69>ļ<EFBFBD>
u8 exfuns_init(void); //<2F><><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>
u8 f_typetell(u8 *fname); //ʶ<><CAB6><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>
u8 exf_getfree(u8 *drv,u32 *total,u32 *free);//<2F>õ<EFBFBD><C3B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʣ<EFBFBD><CAA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
u32 exf_fdsize(u8 *fdname); //<2F>õ<EFBFBD><C3B5>ļ<EFBFBD><C4BC>д<EFBFBD>С
u8* exf_get_src_dname(u8* dpfn);
u8 exf_copy(u8(*fcpymsg)(u8*pname,u8 pct,u8 mode),u8 *psrc,u8 *pdst,u32 totsize,u32 cpdsize,u8 fwmode); //<2F>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>
u8 exf_fdcopy(u8(*fcpymsg)(u8*pname,u8 pct,u8 mode),u8 *psrc,u8 *pdst,u32 *totsize,u32 *cpdsize,u8 fwmode);//<2F>ļ<EFBFBD><C4BC>и<EFBFBD><D0B8><EFBFBD>
#endif

View File

@ -0,0 +1,308 @@
#include "fattester.h"
#include "mmc_sd.h"
#include "usmart.h"
#include "usart.h"
#include "exfuns.h"
#include "malloc.h"
#include "ff.h"
#include "string.h"
//////////////////////////////////////////////////////////////////////////////////
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֻ<EFBFBD><D6BB>ѧϰʹ<CFB0>ã<EFBFBD>δ<EFBFBD><CEB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɣ<EFBFBD><C9A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>κ<EFBFBD><CEBA><EFBFBD>;
//ALIENTEKս<4B><D5BD>STM32<33><32><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//FATFS <20><><EFBFBD>Դ<EFBFBD><D4B4><EFBFBD>
//<2F><><EFBFBD><EFBFBD>ԭ<EFBFBD><D4AD>@ALIENTEK
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̳:www.openedv.com
//<2F>޸<EFBFBD><DEB8><EFBFBD><EFBFBD><EFBFBD>:2012/9/18
//<2F><EFBFBD><E6B1BE>V1.0
//<2F><>Ȩ<EFBFBD><C8A8><EFBFBD>У<EFBFBD><D0A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ؾ<EFBFBD><D8BE><EFBFBD>
//Copyright(C) <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӿƼ<D3BF><C6BC><EFBFBD><EFBFBD>޹<EFBFBD>˾ 2009-2019
//All rights reserved
//////////////////////////////////////////////////////////////////////////////////
//Ϊ<><CEAA><EFBFBD><EFBFBD>ע<EFBFBD><EFBFBD><E1B9A4><EFBFBD><EFBFBD>
//drv:<3A>̷<EFBFBD>
//<2F><><EFBFBD><EFBFBD>ֵ:ִ<>н<EFBFBD><D0BD><EFBFBD>
u8 mf_mount(u8 drv)
{
return f_mount(drv,fs[drv]);
}
//<2F><><EFBFBD><EFBFBD>·<EFBFBD><C2B7><EFBFBD>µ<EFBFBD><C2B5>ļ<EFBFBD>
//path:·<><C2B7>+<2B>ļ<EFBFBD><C4BC><EFBFBD>
//mode:<3A><><EFBFBD><EFBFBD>ģʽ
//<2F><><EFBFBD><EFBFBD>ֵ:ִ<>н<EFBFBD><D0BD><EFBFBD>
u8 mf_open(u8*path,u8 mode)
{
u8 res;
res=f_open(file,(const TCHAR*)path,mode);//<2F><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>
return res;
}
//<2F>ر<EFBFBD><D8B1>ļ<EFBFBD>
//<2F><><EFBFBD><EFBFBD>ֵ:ִ<>н<EFBFBD><D0BD><EFBFBD>
u8 mf_close(void)
{
f_close(file);
return 0;
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//len:<3A><><EFBFBD><EFBFBD><EFBFBD>ij<EFBFBD><C4B3><EFBFBD>
//<2F><><EFBFBD><EFBFBD>ֵ:ִ<>н<EFBFBD><D0BD><EFBFBD>
u8 mf_read(u16 len)
{
u16 i,t;
u8 res=0;
u16 tlen=0;
printf("\r\nRead file data is:\r\n");
for(i=0;i<len/512;i++)
{
res=f_read(file,fatbuf,512,&br);
if(res)
{
printf("Read Error:%d\r\n",res);
break;
}else
{
tlen+=br;
for(t=0;t<br;t++)printf("%c",fatbuf[t]);
}
}
if(len%512)
{
res=f_read(file,fatbuf,len%512,&br);
if(res) //<2F><><EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><DDB3><EFBFBD><EFBFBD><EFBFBD>
{
printf("\r\nRead Error:%d\r\n",res);
}else
{
tlen+=br;
for(t=0;t<br;t++)printf("%c",fatbuf[t]);
}
}
if(tlen)printf("\r\nReaded data len:%d\r\n",tlen);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><DDB3><EFBFBD>
printf("Read data over\r\n");
return res;
}
//д<><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//dat:<3A><><EFBFBD>ݻ<EFBFBD><DDBB><EFBFBD><EFBFBD><EFBFBD>
//len:д<><EFBFBD><EBB3A4>
//<2F><><EFBFBD><EFBFBD>ֵ:ִ<>н<EFBFBD><D0BD><EFBFBD>
u8 mf_write(u8*dat,u16 len)
{
u8 res;
printf("\r\nBegin Write file...\r\n");
printf("Write data len:%d\r\n",len);
res=f_write(file,dat,len,&bw);
if(res)
{
printf("Write Error:%d\r\n",res);
}else printf("Writed data len:%d\r\n",bw);
printf("Write data over.\r\n");
return res;
}
//<2F><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>
//path:·<><C2B7>
//<2F><><EFBFBD><EFBFBD>ֵ:ִ<>н<EFBFBD><D0BD><EFBFBD>
u8 mf_opendir(u8* path)
{
return f_opendir(&dir,(const TCHAR*)path);
}
//<2F><><EFBFBD><EFBFBD>ȡ<EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>
//<2F><><EFBFBD><EFBFBD>ֵ:ִ<>н<EFBFBD><D0BD><EFBFBD>
u8 mf_readdir(void)
{
u8 res;
char *fn;
#if _USE_LFN
fileinfo.lfsize = _MAX_LFN * 2 + 1;
fileinfo.lfname = mymalloc(SRAMIN,fileinfo.lfsize);
#endif
res=f_readdir(&dir,&fileinfo);//<2F><>ȡһ<C8A1><D2BB><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>Ϣ
if(res!=FR_OK||fileinfo.fname[0]==0)
{
myfree(SRAMIN,fileinfo.lfname);
return res;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.
}
#if _USE_LFN
fn=*fileinfo.lfname ? fileinfo.lfname : fileinfo.fname;
#else
fn=fileinfo.fname;;
#endif
printf("\r\n DIR info:\r\n");
printf("dir.id:%d\r\n",dir.id);
printf("dir.index:%d\r\n",dir.index);
printf("dir.sclust:%d\r\n",dir.sclust);
printf("dir.clust:%d\r\n",dir.clust);
printf("dir.sect:%d\r\n",dir.sect);
printf("\r\n");
printf("File Name is:%s\r\n",fn);
printf("File Size is:%d\r\n",fileinfo.fsize);
printf("File data is:%d\r\n",fileinfo.fdate);
printf("File time is:%d\r\n",fileinfo.ftime);
printf("File Attr is:%d\r\n",fileinfo.fattrib);
printf("\r\n");
myfree(SRAMIN,fileinfo.lfname);
return 0;
}
//<2F><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>
//path:·<><C2B7>
//<2F><><EFBFBD><EFBFBD>ֵ:ִ<>н<EFBFBD><D0BD><EFBFBD>
u8 mf_scan_files(u8 * path)
{
FRESULT res;
char *fn; /* This function is assuming non-Unicode cfg. */
#if _USE_LFN
fileinfo.lfsize = _MAX_LFN * 2 + 1;
fileinfo.lfname = mymalloc(SRAMIN,fileinfo.lfsize);
#endif
res = f_opendir(&dir,(const TCHAR*)path); //<2F><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>Ŀ¼
if (res == FR_OK)
{
printf("\r\n");
while(1)
{
res = f_readdir(&dir, &fileinfo); //<2F><>ȡĿ¼<C4BF>µ<EFBFBD>һ<EFBFBD><D2BB><EFBFBD>ļ<EFBFBD>
if (res != FR_OK || fileinfo.fname[0] == 0) break; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>/<2F><>ĩβ<C4A9><CEB2>,<2C>˳<EFBFBD>
//if (fileinfo.fname[0] == '.') continue; //<2F><><EFBFBD><EFBFBD><EFBFBD>ϼ<EFBFBD>Ŀ¼
#if _USE_LFN
fn = *fileinfo.lfname ? fileinfo.lfname : fileinfo.fname;
#else
fn = fileinfo.fname;
#endif /* It is a file. */
printf("%s/", path);//<2F><>ӡ·<D3A1><C2B7>
printf("%s\r\n", fn);//<2F><>ӡ<EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>
}
}
myfree(SRAMIN,fileinfo.lfname);
return res;
}
//<2F><>ʾʣ<CABE><CAA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//drv:<3A>̷<EFBFBD>
//<2F><><EFBFBD><EFBFBD>ֵ:ʣ<><CAA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(<28>ֽ<EFBFBD>)
u32 mf_showfree(u8 *drv)
{
FATFS *fs1;
u8 res;
DWORD fre_clust=0, fre_sect=0, tot_sect=0;
//<2F>õ<EFBFBD><C3B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD>
res = f_getfree((const TCHAR*)drv, &fre_clust, &fs1);
if(res==0)
{
tot_sect = (fs1->n_fatent - 2) * fs1->csize;//<2F>õ<EFBFBD><C3B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
fre_sect = fre_clust * fs1->csize; //<2F>õ<EFBFBD><C3B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
#if _MAX_SS!=512
tot_sect*=fs1->ssize/512;
fre_sect*=fs1->ssize/512;
#endif
if(tot_sect<20480)//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>С<EFBFBD><D0A1>10M
{
/* Print free space in unit of KB (assuming 512 bytes/sector) */
printf("\r\n<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:%d KB\r\n"
"<EFBFBD><EFBFBD><EFBFBD>ÿռ<EFBFBD>:%d KB\r\n",
tot_sect>>1,fre_sect>>1);
}else
{
/* Print free space in unit of KB (assuming 512 bytes/sector) */
printf("\r\n<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:%d MB\r\n"
"<EFBFBD><EFBFBD><EFBFBD>ÿռ<EFBFBD>:%d MB\r\n",
tot_sect>>11,fre_sect>>11);
}
}
return fre_sect;
}
//<2F>ļ<EFBFBD><C4BC><EFBFBD>дָ<D0B4><D6B8>ƫ<EFBFBD><C6AB>
//offset:<3A><><EFBFBD><EFBFBD><EFBFBD>׵<EFBFBD>ַ<EFBFBD><D6B7>ƫ<EFBFBD><C6AB><EFBFBD><EFBFBD>
//<2F><><EFBFBD><EFBFBD>ֵ:ִ<>н<EFBFBD><D0BD><EFBFBD>.
u8 mf_lseek(u32 offset)
{
return f_lseek(file,offset);
}
//<2F><>ȡ<EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>ǰ<EFBFBD><C7B0>дָ<D0B4><D6B8><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>.
//<2F><><EFBFBD><EFBFBD>ֵ:λ<><CEBB>
u32 mf_tell(void)
{
return f_tell(file);
}
//<2F><>ȡ<EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>С
//<2F><><EFBFBD><EFBFBD>ֵ:<3A>ļ<EFBFBD><C4BC><EFBFBD>С
u32 mf_size(void)
{
return f_size(file);
}
//<2F><><EFBFBD><EFBFBD>Ŀ¼
//pname:Ŀ¼·<C2BC><C2B7>+<2B><><EFBFBD><EFBFBD>
//<2F><><EFBFBD><EFBFBD>ֵ:ִ<>н<EFBFBD><D0BD><EFBFBD>
u8 mf_mkdir(u8*pname)
{
return f_mkdir((const TCHAR *)pname);
}
//<2F><>ʽ<EFBFBD><CABD>
//drv:<3A>̷<EFBFBD>
//mode:ģʽ
//au:<3A>ش<EFBFBD>С
//<2F><><EFBFBD><EFBFBD>ֵ:ִ<>н<EFBFBD><D0BD><EFBFBD>
u8 mf_fmkfs(u8 drv,u8 mode,u16 au)
{
return f_mkfs(drv,mode,au);//<2F><>ʽ<EFBFBD><CABD>,drv:<3A>̷<EFBFBD>;mode:ģʽ;au:<3A>ش<EFBFBD>С
}
//ɾ<><C9BE><EFBFBD>ļ<EFBFBD>/Ŀ¼
//pname:<3A>ļ<EFBFBD>/Ŀ¼·<C2BC><C2B7>+<2B><><EFBFBD><EFBFBD>
//<2F><><EFBFBD><EFBFBD>ֵ:ִ<>н<EFBFBD><D0BD><EFBFBD>
u8 mf_unlink(u8 *pname)
{
return f_unlink((const TCHAR *)pname);
}
//<2F>޸<EFBFBD><DEB8>ļ<EFBFBD>/Ŀ¼<C4BF><C2BC><EFBFBD><EFBFBD>(<28><><EFBFBD><EFBFBD>Ŀ¼<C4BF><C2BC>ͬ,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƶ<EFBFBD><C6B6>ļ<EFBFBD>Ŷ!)
//oldname:֮ǰ<D6AE><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//newname:<3A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//<2F><><EFBFBD><EFBFBD>ֵ:ִ<>н<EFBFBD><D0BD><EFBFBD>
u8 mf_rename(u8 *oldname,u8* newname)
{
return f_rename((const TCHAR *)oldname,(const TCHAR *)newname);
}
//<2F><><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡһ<C8A1><D2BB><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>
//size:Ҫ<><D2AA>ȡ<EFBFBD>ij<EFBFBD><C4B3><EFBFBD>
void mf_gets(u16 size)
{
TCHAR* rbuf;
rbuf=f_gets((TCHAR*)fatbuf,size,file);
if(*rbuf==0)return ;//û<><C3BB><EFBFBD><EFBFBD><EFBFBD>ݶ<EFBFBD><DDB6><EFBFBD>
else
{
printf("\r\nThe String Readed Is:%s\r\n",rbuf);
}
}
//<2F><>Ҫ_USE_STRFUNC>=1
//дһ<D0B4><D2BB><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD>ļ<EFBFBD>
//c:Ҫд<D2AA><D0B4><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD>
//<2F><><EFBFBD><EFBFBD>ֵ:ִ<>н<EFBFBD><D0BD><EFBFBD>
u8 mf_putc(u8 c)
{
return f_putc((TCHAR)c,file);
}
//д<>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>
//c:Ҫд<D2AA><D0B4><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>
//<2F><><EFBFBD><EFBFBD>ֵ:д<><D0B4><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
u8 mf_puts(u8*c)
{
return f_puts((TCHAR*)c,file);
}

View File

@ -0,0 +1,56 @@
#ifndef __FATTESTER_H
#define __FATTESTER_H
#include "ff.h"
#include "sys.h"
u8 mf_mount(u8 drv);
u8 mf_open(u8*path,u8 mode);
u8 mf_close(void);
u8 mf_read(u16 len);
u8 mf_write(u8*dat,u16 len);
u8 mf_opendir(u8* path);
u8 mf_readdir(void);
u8 mf_scan_files(u8 * path);
u32 mf_showfree(u8 *drv);
u8 mf_lseek(u32 offset);
u32 mf_tell(void);
u32 mf_size(void);
u8 mf_mkdir(u8*pname);
u8 mf_fmkfs(u8 drv,u8 mode,u16 au);
u8 mf_unlink(u8 *pname);
u8 mf_rename(u8 *oldname,u8* newname);
void mf_gets(u16 size);
u8 mf_putc(u8 c);
u8 mf_puts(u8*c);
#endif

View File

@ -0,0 +1,62 @@
#include "ff.h"
#include "fontupd.h"
//#include "flash.h"
WCHAR ff_convert ( /* Converted code, 0 means conversion error */
WCHAR src, /* Character code to be converted */
UINT dir /* 0: Unicode to OEMCP, 1: OEMCP to Unicode */
)
{
WCHAR t[2];
WCHAR c;
u32 i, li, hi;
u16 n;
u32 gbk2uni_offset=0;
if (src < 0x80)c = src;//ASCII,ֱ<>Ӳ<EFBFBD><D3B2><EFBFBD>ת<EFBFBD><D7AA>.
else
{
if(dir) //GBK 2 UNICODE
{
gbk2uni_offset=ftinfo.ugbksize/2;
}else //UNICODE 2 GBK
{
gbk2uni_offset=0;
}
//if(UK_FLAG)//<2F><><EFBFBD><EFBFBD>
{
/* Unicode to OEMCP */
hi=ftinfo.ugbksize/2;//<2F>԰뿪.
hi =hi / 4 - 1;
li = 0;
for (n = 16; n; n--)
{
i = li + (hi - li) / 2;
SPI_Flash_Read((u8*)&t,ftinfo.ugbkaddr+i*4+gbk2uni_offset,4);//<2F><><EFBFBD><EFBFBD>8<EFBFBD><38><EFBFBD>ֽ<EFBFBD>
if (src == t[0]) break;
if (src > t[0])li = i;
else hi = i;
}
c = n ? t[1] : 0;
}
//else c=0;
}
return c;
}
WCHAR ff_wtoupper ( /* Upper converted character */
WCHAR chr /* Input character */
)
{
static const WCHAR tbl_lower[] = { 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A, 0xA1, 0x00A2, 0x00A3, 0x00A5, 0x00AC, 0x00AF, 0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF, 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0x0FF, 0x101, 0x103, 0x105, 0x107, 0x109, 0x10B, 0x10D, 0x10F, 0x111, 0x113, 0x115, 0x117, 0x119, 0x11B, 0x11D, 0x11F, 0x121, 0x123, 0x125, 0x127, 0x129, 0x12B, 0x12D, 0x12F, 0x131, 0x133, 0x135, 0x137, 0x13A, 0x13C, 0x13E, 0x140, 0x142, 0x144, 0x146, 0x148, 0x14B, 0x14D, 0x14F, 0x151, 0x153, 0x155, 0x157, 0x159, 0x15B, 0x15D, 0x15F, 0x161, 0x163, 0x165, 0x167, 0x169, 0x16B, 0x16D, 0x16F, 0x171, 0x173, 0x175, 0x177, 0x17A, 0x17C, 0x17E, 0x192, 0x3B1, 0x3B2, 0x3B3, 0x3B4, 0x3B5, 0x3B6, 0x3B7, 0x3B8, 0x3B9, 0x3BA, 0x3BB, 0x3BC, 0x3BD, 0x3BE, 0x3BF, 0x3C0, 0x3C1, 0x3C3, 0x3C4, 0x3C5, 0x3C6, 0x3C7, 0x3C8, 0x3C9, 0x3CA, 0x430, 0x431, 0x432, 0x433, 0x434, 0x435, 0x436, 0x437, 0x438, 0x439, 0x43A, 0x43B, 0x43C, 0x43D, 0x43E, 0x43F, 0x440, 0x441, 0x442, 0x443, 0x444, 0x445, 0x446, 0x447, 0x448, 0x449, 0x44A, 0x44B, 0x44C, 0x44D, 0x44E, 0x44F, 0x451, 0x452, 0x453, 0x454, 0x455, 0x456, 0x457, 0x458, 0x459, 0x45A, 0x45B, 0x45C, 0x45E, 0x45F, 0x2170, 0x2171, 0x2172, 0x2173, 0x2174, 0x2175, 0x2176, 0x2177, 0x2178, 0x2179, 0x217A, 0x217B, 0x217C, 0x217D, 0x217E, 0x217F, 0xFF41, 0xFF42, 0xFF43, 0xFF44, 0xFF45, 0xFF46, 0xFF47, 0xFF48, 0xFF49, 0xFF4A, 0xFF4B, 0xFF4C, 0xFF4D, 0xFF4E, 0xFF4F, 0xFF50, 0xFF51, 0xFF52, 0xFF53, 0xFF54, 0xFF55, 0xFF56, 0xFF57, 0xFF58, 0xFF59, 0xFF5A, 0 };
static const WCHAR tbl_upper[] = { 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x21, 0xFFE0, 0xFFE1, 0xFFE5, 0xFFE2, 0xFFE3, 0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF, 0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0x178, 0x100, 0x102, 0x104, 0x106, 0x108, 0x10A, 0x10C, 0x10E, 0x110, 0x112, 0x114, 0x116, 0x118, 0x11A, 0x11C, 0x11E, 0x120, 0x122, 0x124, 0x126, 0x128, 0x12A, 0x12C, 0x12E, 0x130, 0x132, 0x134, 0x136, 0x139, 0x13B, 0x13D, 0x13F, 0x141, 0x143, 0x145, 0x147, 0x14A, 0x14C, 0x14E, 0x150, 0x152, 0x154, 0x156, 0x158, 0x15A, 0x15C, 0x15E, 0x160, 0x162, 0x164, 0x166, 0x168, 0x16A, 0x16C, 0x16E, 0x170, 0x172, 0x174, 0x176, 0x179, 0x17B, 0x17D, 0x191, 0x391, 0x392, 0x393, 0x394, 0x395, 0x396, 0x397, 0x398, 0x399, 0x39A, 0x39B, 0x39C, 0x39D, 0x39E, 0x39F, 0x3A0, 0x3A1, 0x3A3, 0x3A4, 0x3A5, 0x3A6, 0x3A7, 0x3A8, 0x3A9, 0x3AA, 0x410, 0x411, 0x412, 0x413, 0x414, 0x415, 0x416, 0x417, 0x418, 0x419, 0x41A, 0x41B, 0x41C, 0x41D, 0x41E, 0x41F, 0x420, 0x421, 0x422, 0x423, 0x424, 0x425, 0x426, 0x427, 0x428, 0x429, 0x42A, 0x42B, 0x42C, 0x42D, 0x42E, 0x42F, 0x401, 0x402, 0x403, 0x404, 0x405, 0x406, 0x407, 0x408, 0x409, 0x40A, 0x40B, 0x40C, 0x40E, 0x40F, 0x2160, 0x2161, 0x2162, 0x2163, 0x2164, 0x2165, 0x2166, 0x2167, 0x2168, 0x2169, 0x216A, 0x216B, 0x216C, 0x216D, 0x216E, 0x216F, 0xFF21, 0xFF22, 0xFF23, 0xFF24, 0xFF25, 0xFF26, 0xFF27, 0xFF28, 0xFF29, 0xFF2A, 0xFF2B, 0xFF2C, 0xFF2D, 0xFF2E, 0xFF2F, 0xFF30, 0xFF31, 0xFF32, 0xFF33, 0xFF34, 0xFF35, 0xFF36, 0xFF37, 0xFF38, 0xFF39, 0xFF3A, 0 };
int i;
for (i = 0; tbl_lower[i] && chr != tbl_lower[i]; i++) ;
return tbl_lower[i] ? tbl_upper[i] : chr;
}

View File

@ -0,0 +1,299 @@
#include "fattester.h"
#include "mmc_sd.h"
#include "usmart.h"
#include "usart.h"
#include "malloc.h"
#include "ff.h"
FATFS *fs[2]; // Work area (file system object) for logical drive
FIL *file;
FIL *ftemp;
UINT br,bw;
FILINFO fileinfo;
DIR dir;
u8 *fatbuf;//SD<53><44><EFBFBD><EFBFBD><EFBFBD>ݻ<EFBFBD><DDBB><EFBFBD><EFBFBD><EFBFBD>
u8 test_init(void)
{
fs[0]=(FATFS*)mymalloc(SRAMIN,sizeof(FATFS)); //Ϊ<><CEAA><EFBFBD><EFBFBD>0<EFBFBD><30><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>
fs[1]=(FATFS*)mymalloc(SRAMIN,sizeof(FATFS)); //Ϊ<><CEAA><EFBFBD><EFBFBD>1<EFBFBD><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>
file=(FIL*)mymalloc(SRAMIN,sizeof(FIL)); //Ϊfile<6C><65><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>
ftemp=(FIL*)mymalloc(SRAMIN,sizeof(FIL)); //Ϊftemp<6D><70><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>
fatbuf=(u8*)mymalloc(SRAMIN,512); //Ϊfatbuf<75><66><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>
if(fs[0]&&fs[1]&&file&&ftemp&&fatbuf)return 0; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>ʧ<EFBFBD><CAA7>,<2C><>ʧ<EFBFBD><CAA7>.
else return 1;
}
//<2F><><EFBFBD>ش<EFBFBD><D8B4><EFBFBD>
u8 mf_mount(u8 drv)
{
return f_mount(drv,fs[drv]);
}
//<2F><><EFBFBD><EFBFBD>·<EFBFBD><C2B7><EFBFBD>µ<EFBFBD><C2B5>ļ<EFBFBD>
u8 mf_open(u8*path,u8 mode)
{
u8 res;
res=f_open(file,(const TCHAR*)path,mode);//<2F><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>
return res;
}
//<2F>ر<EFBFBD><D8B1>ļ<EFBFBD>
u8 mf_close(void)
{
f_close(file);
return 0;
}
u8 mf_read(u16 len)
{
u16 i,t;
u8 res=0;
u16 tlen=0;
printf("\r\nRead file data is:\r\n");
for(i=0;i<len/512;i++)
{
res=f_read(file,fatbuf,512,&br);
if(res)
{
printf("Read Error:%d\r\n",res);
break;
}else
{
tlen+=br;
for(t=0;t<br;t++)printf("%c",fatbuf[t]);
}
}
if(len%512)
{
res=f_read(file,fatbuf,len%512,&br);
if(res) //<2F><><EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><DDB3><EFBFBD><EFBFBD><EFBFBD>
{
printf("Read Error:%d\r\n",res);
}else
{
tlen+=br;
for(t=0;t<br;t++)printf("%c",fatbuf[t]);
}
}
if(tlen)printf("Readed data len:%d\r\n",tlen);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><DDB3><EFBFBD>
printf("Read data over\r\n");
return res;
}
//д<><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
u8 mf_write(u8*dat,u16 len)
{
u8 res;
printf("\r\nWriting file data.\r\n");
printf("Write data len:%d\r\n",len);
res=f_write(file,dat,len,&bw);
if(res)
{
printf("Write Error:%d\r\n",res);
}else printf("Writed data len:%d\r\n",bw);
printf("Write data over.\r\n");
return res;
}
//<2F><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>
u8 mf_opendir(u8* path)
{
return f_opendir(&dir,(const TCHAR*)path);
}
//<2F><><EFBFBD><EFBFBD>ȡ<EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>
u8 mf_readdir(void)
{
u8 res;
char *fn;
#if _USE_LFN
fileinfo.lfsize = _MAX_LFN * 2 + 1;
fileinfo.lfname = mymalloc(SRAMIN,fileinfo.lfsize);
#endif
res=f_readdir(&dir,&fileinfo);//<2F><>ȡһ<C8A1><D2BB><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>Ϣ
if(res!=FR_OK||fileinfo.fname[0]==0)
{
myfree(SRAMIN,fileinfo.lfname);
return res;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.
}
#if _USE_LFN
fn=*fileinfo.lfname ? fileinfo.lfname : fileinfo.fname;
#else
fn=fileinfo.fname;;
#endif
printf("\r\n DIR info:\r\n");
printf("dir.id:%d\r\n",dir.id);
printf("dir.index:%d\r\n",dir.index);
printf("dir.sclust:%d\r\n",dir.sclust);
printf("dir.clust:%d\r\n",dir.clust);
printf("dir.sect:%d\r\n",dir.sect);
printf("\r\n");
printf("File Name is:%s\r\n",fn);
printf("File Size is:%d\r\n",fileinfo.fsize);
printf("File data is:%d\r\n",fileinfo.fdate);
printf("File time is:%d\r\n",fileinfo.ftime);
printf("File Attr is:%d\r\n",fileinfo.fattrib);
printf("\r\n");
myfree(SRAMIN,fileinfo.lfname);
return 0;
}
//<2F><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>
u8 mf_scan_files(u8 * path)
{
FRESULT res;
char *fn; /* This function is assuming non-Unicode cfg. */
#if _USE_LFN
fileinfo.lfsize = _MAX_LFN * 2 + 1;
fileinfo.lfname = mymalloc(SRAMIN,fileinfo.lfsize);
#endif
res = f_opendir(&dir,(const TCHAR*)path); //<2F><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>Ŀ¼
if (res == FR_OK)
{
printf("\r\n");
while(1)
{
res = f_readdir(&dir, &fileinfo); //<2F><>ȡĿ¼<C4BF>µ<EFBFBD>һ<EFBFBD><D2BB><EFBFBD>ļ<EFBFBD>
if (res != FR_OK || fileinfo.fname[0] == 0) break; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>/<2F><>ĩβ<C4A9><CEB2>,<2C>˳<EFBFBD>
//if (fileinfo.fname[0] == '.') continue; //<2F><><EFBFBD><EFBFBD><EFBFBD>ϼ<EFBFBD>Ŀ¼
#if _USE_LFN
fn = *fileinfo.lfname ? fileinfo.lfname : fileinfo.fname;
#else
fn = fileinfo.fname;
#endif /* It is a file. */
printf("%s/", path);//<2F><>ӡ·<D3A1><C2B7>
printf("%s\r\n", fn);//<2F><>ӡ<EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>
}
}
myfree(SRAMIN,fileinfo.lfname);
return res;
}
//<2F><>ʾʣ<CABE><CAA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
u32 mf_showfree(u8 *drv)
{
FATFS *fs1;
u8 res;
u32 fre_clust=0, fre_sect=0, tot_sect=0;
//<2F>õ<EFBFBD><C3B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD>
res = f_getfree((const TCHAR*)drv, &fre_clust, &fs1);
if(res==0)
{
tot_sect = (fs1->n_fatent - 2) * fs1->csize;//<2F>õ<EFBFBD><C3B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
fre_sect = fre_clust * fs1->csize; //<2F>õ<EFBFBD><C3B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
#if _MAX_SS!=512
tot_sect*=fs1->ssize/512;
fre_sect*=fs1->ssize/512;
#endif
if(tot_sect<20480)//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>С<EFBFBD><D0A1>10M
{
/* Print free space in unit of KB (assuming 512 bytes/sector) */
printf("\r\n<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:%d KB\r\n"
"<EFBFBD><EFBFBD><EFBFBD>ÿռ<EFBFBD>:%d KB\r\n",
tot_sect>>1,fre_sect>>1);
}else
{
/* Print free space in unit of KB (assuming 512 bytes/sector) */
printf("\r\n<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:%d MB\r\n"
"<EFBFBD><EFBFBD><EFBFBD>ÿռ<EFBFBD>:%d MB\r\n",
tot_sect>>11,fre_sect>>11);
}
}
return fre_sect;
}
//<2F>ļ<EFBFBD><C4BC><EFBFBD>дָ<D0B4><D6B8>ƫ<EFBFBD><C6AB>
//offset:<3A>׵<EFBFBD>ַƫ<D6B7>Ƶ<EFBFBD><C6B5><EFBFBD>
//<2F><><EFBFBD><EFBFBD>ֵ:ִ<>н<EFBFBD><D0BD><EFBFBD>.
u8 mf_lseek(u32 offset)
{
return f_lseek(file,offset);
}
//<2F><>ȡ<EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>ǰ<EFBFBD><C7B0>дָ<D0B4><D6B8><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>.
//<2F><><EFBFBD><EFBFBD>ֵ:λ<><CEBB>
u32 mf_tell(void)
{
return f_tell(file);
}
//<2F><>ȡ<EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>С
//<2F><><EFBFBD><EFBFBD>ֵ:<3A>ļ<EFBFBD><C4BC><EFBFBD>С
u32 mf_size(void)
{
return f_size(file);
}
//<2F><><EFBFBD><EFBFBD>Ŀ¼
u8 mf_mkdir(u8*name)
{
return f_mkdir((const TCHAR *)name);
}
//<2F><>ʽ<EFBFBD><CABD>
u8 mf_fmkfs(u8 drv,u8 mode,u16 au)
{
return f_mkfs(drv,mode,au);//<2F><>ʽ<EFBFBD><CABD>,drv:<3A>̷<EFBFBD>;mode:ģʽ;au:<3A>ش<EFBFBD>С
}
//ɾ<><C9BE><EFBFBD>ļ<EFBFBD>/Ŀ¼
u8 mf_unlink(u8 *name)
{
return f_unlink((const TCHAR *)name);
}
//<2F>޸<EFBFBD><DEB8>ļ<EFBFBD>/Ŀ¼<C4BF><C2BC><EFBFBD><EFBFBD>(<28><><EFBFBD><EFBFBD>Ŀ¼<C4BF><C2BC>ͬ,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƶ<EFBFBD><C6B6>ļ<EFBFBD>Ŷ!)
//oldname:֮ǰ<D6AE><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//newname:<3A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
u8 mf_rename(u8 *oldname,u8* newname)
{
return f_rename((const TCHAR *)oldname,(const TCHAR *)newname);
}
//<2F><><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡһ<C8A1><D2BB><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>
void mf_gets(u16 size)
{
TCHAR* rbuf;
rbuf=f_gets((TCHAR*)fatbuf,size,file);
if(*rbuf==0)return ;//û<><C3BB><EFBFBD><EFBFBD><EFBFBD>ݶ<EFBFBD><DDB6><EFBFBD>
else
{
printf("\r\nThe String Readed Is:%s\r\n",rbuf);
}
}
//<2F><>Ҫ_USE_STRFUNC>=1
//дһ<D0B4><D2BB><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD>ļ<EFBFBD>
u8 mf_putc(u8 c)
{
return f_putc((TCHAR)c,file);
}
//д<>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD>
u8 mf_puts(u8*c)
{
return f_puts((TCHAR*)c,file);
}
//<2F>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2>ʾ
//mode:
//[0]:<3A><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>
//[1]:<3A><><EFBFBD>°ٷֱ<D9B7>pct
//[2]:<3A><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>
//[3~7]:<3A><><EFBFBD><EFBFBD>
//<2F><><EFBFBD><EFBFBD>ֵ:0,<2C><><EFBFBD><EFBFBD>;
// 1,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
u8 mf_cpymsg(u8*pname,u8 pct,u8 mode)
{
if(mode&0X01)printf("\r\nCopy File:%s\r\n",pname);
if(mode&0X02)printf("File Copyed:%d\r\n",pct);
if(mode&0X04)printf("Copy Folder:%s\r\n",pname);
return 0;
}

View File

@ -0,0 +1,67 @@
#ifndef __FATTESTER_H
#define __FATTESTER_H
#include "ff.h"
#include "sys.h"
u8 mf_mount(u8 drv);
u8 mf_open(u8*path,u8 mode);
u8 mf_close(void);
u8 mf_read(u16 len);
u8 mf_write(u8*dat,u16 len);
u8 mf_opendir(u8* path);
u8 mf_readdir(void);
u8 mf_scan_files(u8 * path);
u32 mf_showfree(u8 *drv);
u8 mf_lseek(u32 offset);
u32 mf_tell(void);
u32 mf_size(void);
u8 mf_mkdir(u8*name);
u8 mf_fmkfs(u8 drv,u8 mode,u16 au);
u8 mf_unlink(u8 *name);
u8 mf_rename(u8 *oldname,u8* newname);
void mf_gets(u16 size);
u8 mf_putc(u8 c);
u8 mf_puts(u8*c);
u8 mf_pfnmg_init(u8*path,u8 type);
u8 mf_pfnmg_get_pname(void);
u8 mf_pfnmg_get_plfname(void);
u8 mf_pfnmg_get_lfname(void);
u8 mf_pfnmg_get_ifname(u16 index);
u8 mf_cpymsg(u8*pname,u8 pct,u8 mode);
u32 mf_fdsize(u8 *fdname);//<2F>õ<EFBFBD><C3B5>ļ<EFBFBD><C4BC>д<EFBFBD>С
u8 mf_fcopy(u8 *psrc,u8 *pdst);
u8 mf_fdcopy(u8 *psrc,u8 *pdst);
#endif

View File

@ -0,0 +1,130 @@
FatFs Module Source Files R0.09 (C)ChaN, 2011
FILES
ffconf.h Configuration file for FatFs module.
ff.h Common include file for FatFs and application module.
ff.c FatFs module.
diskio.h Common include file for FatFs and disk I/O module.
integer.h Alternative type definitions for integer variables.
option Optional external functions.
Low level disk I/O module is not included in this archive because the FatFs
module is only a generic file system layer and not depend on any specific
storage device. You have to provide a low level disk I/O module that written
to control your storage device.
AGREEMENTS
FatFs module is an open source software to implement FAT file system to
small embedded systems. This is a free software and is opened for education,
research and commercial developments under license policy of following trems.
Copyright (C) 2011, ChaN, all right reserved.
* The FatFs module is a free software and there is NO WARRANTY.
* No restriction on use. You can use, modify and redistribute it for
personal, non-profit or commercial product UNDER YOUR RESPONSIBILITY.
* Redistributions of source code must retain the above copyright notice.
REVISION HISTORY
Feb 26, 2006 R0.00 Prototype
Apr 29, 2006 R0.01 First release.
Jun 01, 2006 R0.02 Added FAT12.
Removed unbuffered mode.
Fixed a problem on small (<32M) patition.
Jun 10, 2006 R0.02a Added a configuration option _FS_MINIMUM.
Sep 22, 2006 R0.03 Added f_rename.
Changed option _FS_MINIMUM to _FS_MINIMIZE.
Dec 11, 2006 R0.03a Improved cluster scan algolithm to write files fast.
Fixed f_mkdir creates incorrect directory on FAT32.
Feb 04, 2007 R0.04 Supported multiple drive system. (FatFs)
Changed some APIs for multiple drive system.
Added f_mkfs. (FatFs)
Added _USE_FAT32 option. (Tiny-FatFs)
Apr 01, 2007 R0.04a Supported multiple partitions on a plysical drive. (FatFs)
Fixed an endian sensitive code in f_mkfs. (FatFs)
Added a capability of extending the file size to f_lseek.
Added minimization level 3.
Fixed a problem that can collapse a sector when recreate an
existing file in any sub-directory at non FAT32 cfg. (Tiny-FatFs)
May 05, 2007 R0.04b Added _USE_NTFLAG option.
Added FSInfo support.
Fixed some problems corresponds to FAT32. (Tiny-FatFs)
Fixed DBCS name can result FR_INVALID_NAME.
Fixed short seek (0 < ofs <= csize) collapses the file object.
Aug 25, 2007 R0.05 Changed arguments of f_read, f_write.
Changed arguments of f_mkfs. (FatFs)
Fixed f_mkfs on FAT32 creates incorrect FSInfo. (FatFs)
Fixed f_mkdir on FAT32 creates incorrect directory. (FatFs)
Feb 03, 2008 R0.05a Added f_truncate().
Added f_utime().
Fixed off by one error at FAT sub-type determination.
Fixed btr in f_read() can be mistruncated.
Fixed cached sector is not flushed when create and close without write.
Apr 01, 2008 R0.06 Added f_forward(). (Tiny-FatFs)
Added string functions: fputc(), fputs(), fprintf() and fgets().
Improved performance of f_lseek() on move to the same or following cluster.
Apr 01, 2009, R0.07 Merged Tiny-FatFs as a buffer configuration option.
Added long file name support.
Added multiple code page support.
Added re-entrancy for multitask operation.
Added auto cluster size selection to f_mkfs().
Added rewind option to f_readdir().
Changed result code of critical errors.
Renamed string functions to avoid name collision.
Apr 14, 2009, R0.07a Separated out OS dependent code on reentrant cfg.
Added multiple sector size support.
Jun 21, 2009, R0.07c Fixed f_unlink() may return FR_OK on error.
Fixed wrong cache control in f_lseek().
Added relative path feature.
Added f_chdir().
Added f_chdrive().
Added proper case conversion for extended characters.
Nov 03, 2009 R0.07e Separated out configuration options from ff.h to ffconf.h.
Added a configuration option, _LFN_UNICODE.
Fixed f_unlink() fails to remove a sub-dir on _FS_RPATH.
Fixed name matching error on the 13 char boundary.
Changed f_readdir() to return the SFN with always upper case on non-LFN cfg.
May 15, 2010, R0.08 Added a memory configuration option. (_USE_LFN)
Added file lock feature. (_FS_SHARE)
Added fast seek feature. (_USE_FASTSEEK)
Changed some types on the API, XCHAR->TCHAR.
Changed fname member in the FILINFO structure on Unicode cfg.
String functions support UTF-8 encoding files on Unicode cfg.
Aug 16,'10 R0.08a Added f_getcwd(). (_FS_RPATH = 2)
Added sector erase feature. (_USE_ERASE)
Moved file lock semaphore table from fs object to the bss.
Fixed a wrong directory entry is created on non-LFN cfg when the given name contains ';'.
Fixed f_mkfs() creates wrong FAT32 volume.
Jan 15,'11 R0.08b Fast seek feature is also applied to f_read() and f_write().
f_lseek() reports required table size on creating CLMP.
Extended format syntax of f_printf function.
Ignores duplicated directory separators in given path names.
Sep 06,'11 R0.09 f_mkfs() supports multiple partition to finish the multiple partition feature.
Added f_fdisk(). (_MULTI_PARTITION = 2)

View File

@ -0,0 +1,225 @@
#include "SPI_SD_driver.h"
#include "diskio.h"
//#include "flash.h"
#include "spi.h"
//#include "malloc.h"
//////////////////////////////////////////////////////////////////////////////////
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֻ<EFBFBD><D6BB>ѧϰʹ<CFB0>ã<EFBFBD>δ<EFBFBD><CEB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɣ<EFBFBD><C9A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>κ<EFBFBD><CEBA><EFBFBD>;
//ALIENTEKս<4B><D5BD>STM32<33><32><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//FATFS disio.c <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//<2F><><EFBFBD><EFBFBD>ԭ<EFBFBD><D4AD>@ALIENTEK
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̳:www.openedv.com
//<2F>޸<EFBFBD><DEB8><EFBFBD><EFBFBD><EFBFBD>:2012/9/18
//<2F><EFBFBD><E6B1BE>V1.0
//<2F><>Ȩ<EFBFBD><C8A8><EFBFBD>У<EFBFBD><D0A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ؾ<EFBFBD><D8BE><EFBFBD>
//Copyright(C) <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӿƼ<D3BF><C6BC><EFBFBD><EFBFBD>޹<EFBFBD>˾ 2009-2019
//All rights reserved
//////////////////////////////////////////////////////////////////////////////////
#define SD_CARD 0 //SD<53><44>,<2C><><EFBFBD><EFBFBD>Ϊ0
#define EX_FLASH 1 //<2F>ⲿflash,<2C><><EFBFBD><EFBFBD>Ϊ1
#define FLASH_SECTOR_SIZE 512
//<2F><><EFBFBD><EFBFBD>W25Q64
//ǰ6M<36>ֽڸ<D6BD>fatfs<66><73>,6M<36>ֽں<D6BD>~6M+500K<30><4B><EFBFBD>û<EFBFBD><C3BB><EFBFBD>,6M+500K<30>Ժ<EFBFBD>,<2C><><EFBFBD>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD>ֿ<EFBFBD>,<2C>ֿ<EFBFBD>ռ<EFBFBD><D5BC>1.5M.
u16 FLASH_SECTOR_COUNT=2048*6;//6M<36>ֽ<EFBFBD><><C4AC>ΪW25Q64
#define FLASH_BLOCK_SIZE 8 //ÿ<><C3BF>BLOCK<43><4B>8<EFBFBD><38><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//<2F><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
DSTATUS disk_initialize (
BYTE drv /* Physical drive nmuber (0..) */
)
{
u8 res=0;
switch(drv)
{
case SD_CARD://SD<53><44>
res = SD_Initialize();//SD_Initialize()
if(res)//STM32 SPI<50><49>bug,<2C><>sd<73><64><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD>ܵ<EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ִ<EFBFBD><D6B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<2C><><EFBFBD>ܵ<EFBFBD><DCB5><EFBFBD>SPI<50><49>д<EFBFBD>
{
SD_SPI_SpeedLow();
SD_SPI_ReadWriteByte(0xff);//<2F><EFBFBD><E1B9A9><EFBFBD><EFBFBD><EFBFBD><EFBFBD>8<EFBFBD><38>ʱ<EFBFBD><CAB1>
SD_SPI_SpeedHigh();
}
break;
case EX_FLASH://<2F>ⲿflash
//SPI_Flash_Init();
// if(SPI_FLASH_TYPE==W25Q64)FLASH_SECTOR_COUNT=2048*6;//W25Q64
// else FLASH_SECTOR_COUNT=2048*2; //<2F><><EFBFBD><EFBFBD>
break;
default:
res=1;
}
if(res)return STA_NOINIT;
else return 0; //<2F><>ʼ<EFBFBD><CABC><EFBFBD>ɹ<EFBFBD>
}
//<2F><><EFBFBD>ô<EFBFBD><C3B4><EFBFBD>״̬
DSTATUS disk_status (
BYTE drv /* Physical drive nmuber (0..) */
)
{
return 0;
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//drv:<3A><><EFBFBD>̱<EFBFBD><CCB1><EFBFBD>0~9
//*buff:<3A><><EFBFBD>ݽ<EFBFBD><DDBD>ջ<EFBFBD><D5BB><EFBFBD><EFBFBD>׵<EFBFBD>ַ
//sector:<3A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ
//count:<3A><>Ҫ<EFBFBD><D2AA>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
DRESULT disk_read (
BYTE drv, /* Physical drive nmuber (0..) */
BYTE *buff, /* Data buffer to store read data */
DWORD sector, /* Sector address (LBA) */
BYTE count /* Number of sectors to read (1..255) */
)
{
u8 res=0;
if (!count)return RES_PARERR;//count<6E><74><EFBFBD>ܵ<EFBFBD><DCB5><EFBFBD>0<EFBFBD><30><EFBFBD><EFBFBD><EFBFBD>򷵻ز<F2B7B5BB><D8B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
switch(drv)
{
case SD_CARD://SD<53><44>
res=SD_ReadDisk(buff,sector,count);
if(res)//STM32 SPI<50><49>bug,<2C><>sd<73><64><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD>ܵ<EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ִ<EFBFBD><D6B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<2C><><EFBFBD>ܵ<EFBFBD><DCB5><EFBFBD>SPI<50><49>д<EFBFBD>
{
SD_SPI_SpeedLow();
SD_SPI_ReadWriteByte(0xff);//<2F><EFBFBD><E1B9A9><EFBFBD><EFBFBD><EFBFBD><EFBFBD>8<EFBFBD><38>ʱ<EFBFBD><CAB1>
SD_SPI_SpeedHigh();
}
break;
case EX_FLASH://<2F>ⲿflash
for(;count>0;count--)
{
//SPI_Flash_Read(buff,sector*FLASH_SECTOR_SIZE,FLASH_SECTOR_SIZE);
sector++;
buff+=FLASH_SECTOR_SIZE;
}
res=0;
break;
default:
res=1;
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD>SPI_SD_driver.c<>ķ<EFBFBD><C4B7><EFBFBD>ֵת<D6B5><D7AA>ff.c<>ķ<EFBFBD><C4B7><EFBFBD>ֵ
if(res==0x00)return RES_OK;
else return RES_ERROR;
}
//д<><D0B4><EFBFBD><EFBFBD>
//drv:<3A><><EFBFBD>̱<EFBFBD><CCB1><EFBFBD>0~9
//*buff:<3A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>׵<EFBFBD>ַ
//sector:<3A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ
//count:<3A><>Ҫд<D2AA><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
#if _READONLY == 0
DRESULT disk_write (
BYTE drv, /* Physical drive nmuber (0..) */
const BYTE *buff, /* Data to be written */
DWORD sector, /* Sector address (LBA) */
BYTE count /* Number of sectors to write (1..255) */
)
{
u8 res=0;
if (!count)return RES_PARERR;//count<6E><74><EFBFBD>ܵ<EFBFBD><DCB5><EFBFBD>0<EFBFBD><30><EFBFBD><EFBFBD><EFBFBD>򷵻ز<F2B7B5BB><D8B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
switch(drv)
{
case SD_CARD://SD<53><44>
res=SD_WriteDisk((u8*)buff,sector,count);
break;
case EX_FLASH://<2F>ⲿflash
for(;count>0;count--)
{
//SPI_Flash_Write((u8*)buff,sector*FLASH_SECTOR_SIZE,FLASH_SECTOR_SIZE);
sector++;
buff+=FLASH_SECTOR_SIZE;
}
res=0;
break;
default:
res=1;
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD>SPI_SD_driver.c<>ķ<EFBFBD><C4B7><EFBFBD>ֵת<D6B5><D7AA>ff.c<>ķ<EFBFBD><C4B7><EFBFBD>ֵ
if(res == 0x00)return RES_OK;
else return RES_ERROR;
}
#endif /* _READONLY */
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ļ<EFBFBD><C4BB><EFBFBD>
//drv:<3A><><EFBFBD>̱<EFBFBD><CCB1><EFBFBD>0~9
//ctrl:<3A><><EFBFBD>ƴ<EFBFBD><C6B4><EFBFBD>
//*buff:<3A><><EFBFBD><EFBFBD>/<2F><><EFBFBD>ջ<EFBFBD><D5BB><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8>
DRESULT disk_ioctl (
BYTE drv, /* Physical drive nmuber (0..) */
BYTE ctrl, /* Control code */
void *buff /* Buffer to send/receive control data */
)
{
DRESULT res;
if(drv==SD_CARD)//SD<53><44>
{
switch(ctrl)
{
case CTRL_SYNC:
SD_CS_ENABLE();
if(SD_WaitReady()==0)res = RES_OK;
else res = RES_ERROR;
SD_CS_DISABLE();
break;
case GET_SECTOR_SIZE:
*(WORD*)buff = 512;
res = RES_OK;
break;
case GET_BLOCK_SIZE:
*(WORD*)buff = 8;
res = RES_OK;
break;
case GET_SECTOR_COUNT:
*(DWORD*)buff = SD_GetSectorCount();
res = RES_OK;
break;
default:
res = RES_PARERR;
break;
}
}else if(drv==EX_FLASH) //<2F>ⲿFLASH
{
switch(ctrl)
{
case CTRL_SYNC:
res = RES_OK;
break;
case GET_SECTOR_SIZE:
*(WORD*)buff = FLASH_SECTOR_SIZE;
res = RES_OK;
break;
case GET_BLOCK_SIZE:
*(WORD*)buff = FLASH_BLOCK_SIZE;
res = RES_OK;
break;
case GET_SECTOR_COUNT:
*(DWORD*)buff = FLASH_SECTOR_COUNT;
res = RES_OK;
break;
default:
res = RES_PARERR;
break;
}
}else res=RES_ERROR;//<2F><><EFBFBD><EFBFBD><EFBFBD>IJ<EFBFBD>֧<EFBFBD><D6A7>
return res;
}
//<2F><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
//User defined function to give a current time to fatfs module */
//31-25: Year(0-127 org.1980), 24-21: Month(1-12), 20-16: Day(1-31) */
//15-11: Hour(0-23), 10-5: Minute(0-59), 4-0: Second(0-29 *2) */
DWORD get_fattime (void)
{
return 0;
}
//<2F><>̬<EFBFBD><CCAC><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>
//void *ff_memalloc (UINT size)
//{
// return (void*)mymalloc(SRAMIN,size);
//}
////<2F>ͷ<EFBFBD><CDB7>ڴ<EFBFBD>
//void ff_memfree (void* mf)
//{
// myfree(SRAMIN,mf);
//}

View File

@ -0,0 +1,78 @@
/*-----------------------------------------------------------------------
/ Low level disk interface modlue include file
/-----------------------------------------------------------------------*/
#ifndef _DISKIO
#define _READONLY 0 /* 1: Remove write functions */
#define _USE_IOCTL 1 /* 1: Use disk_ioctl fucntion */
#include "integer.h"
/* Status of Disk Functions */
typedef BYTE DSTATUS;
/* Results of Disk Functions */
typedef enum {
RES_OK = 0, /* 0: Successful */
RES_ERROR, /* 1: R/W Error */
RES_WRPRT, /* 2: Write Protected */
RES_NOTRDY, /* 3: Not Ready */
RES_PARERR /* 4: Invalid Parameter */
} DRESULT;
/*---------------------------------------*/
/* Prototypes for disk control functions */
int assign_drives (int, int);
DSTATUS disk_initialize (BYTE);
DSTATUS disk_status (BYTE);
DRESULT disk_read (BYTE, BYTE*, DWORD, BYTE);
#if _READONLY == 0
DRESULT disk_write (BYTE, const BYTE*, DWORD, BYTE);
#endif
DRESULT disk_ioctl (BYTE, BYTE, void*);
/* Disk Status Bits (DSTATUS) */
#define STA_NOINIT 0x01 /* Drive not initialized */
#define STA_NODISK 0x02 /* No medium in the drive */
#define STA_PROTECT 0x04 /* Write protected */
/* Command code for disk_ioctrl fucntion */
/* Generic command (defined for FatFs) */
#define CTRL_SYNC 0 /* Flush disk cache (for write functions) */
#define GET_SECTOR_COUNT 1 /* Get media size (for only f_mkfs()) */
#define GET_SECTOR_SIZE 2 /* Get sector size (for multiple sector size (_MAX_SS >= 1024)) */
#define GET_BLOCK_SIZE 3 /* Get erase block size (for only f_mkfs()) */
#define CTRL_ERASE_SECTOR 4 /* Force erased a block of sectors (for only _USE_ERASE) */
/* Generic command */
#define CTRL_POWER 5 /* Get/Set power status */
#define CTRL_LOCK 6 /* Lock/Unlock media removal */
#define CTRL_EJECT 7 /* Eject media */
/* MMC/SDC specific ioctl command */
#define MMC_GET_TYPE 10 /* Get card type */
#define MMC_GET_CSD 11 /* Get CSD */
#define MMC_GET_CID 12 /* Get CID */
#define MMC_GET_OCR 13 /* Get OCR */
#define MMC_GET_SDSTAT 14 /* Get SD status */
/* ATA/CF specific ioctl command */
#define ATA_GET_REV 20 /* Get F/W revision */
#define ATA_GET_MODEL 21 /* Get model name */
#define ATA_GET_SN 22 /* Get serial number */
/* NAND specific ioctl command */
#define NAND_FORMAT 30 /* Create physical format */
#define _DISKIO
#endif

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,337 @@
/*---------------------------------------------------------------------------/
/ FatFs - FAT file system module include file R0.09 (C)ChaN, 2011
/----------------------------------------------------------------------------/
/ FatFs module is a generic FAT file system module for small embedded systems.
/ This is a free software that opened for education, research and commercial
/ developments under license policy of following trems.
/
/ Copyright (C) 2011, ChaN, all right reserved.
/
/ * The FatFs module is a free software and there is NO WARRANTY.
/ * No restriction on use. You can use, modify and redistribute it for
/ personal, non-profit or commercial product UNDER YOUR RESPONSIBILITY.
/ * Redistributions of source code must retain the above copyright notice.
/
/----------------------------------------------------------------------------*/
#ifndef _FATFS
#define _FATFS 6502 /* Revision ID */
#ifdef __cplusplus
extern "C" {
#endif
#include "integer.h" /* Basic integer types */
#include "ffconf.h" /* FatFs configuration options */
#if _FATFS != _FFCONF
#error Wrong configuration file (ffconf.h).
#endif
/* Definitions of volume management */
#if _MULTI_PARTITION /* Multiple partition configuration */
typedef struct {
BYTE pd; /* Physical drive number */
BYTE pt; /* Partition: 0:Auto detect, 1-4:Forced partition) */
} PARTITION;
extern PARTITION VolToPart[]; /* Volume - Partition resolution table */
#define LD2PD(vol) (VolToPart[vol].pd) /* Get physical drive number */
#define LD2PT(vol) (VolToPart[vol].pt) /* Get partition index */
#else /* Single partition configuration */
#define LD2PD(vol) (vol) /* Each logical drive is bound to the same physical drive number */
#define LD2PT(vol) 0 /* Always mounts the 1st partition or in SFD */
#endif
/* Type of path name strings on FatFs API */
#if _LFN_UNICODE /* Unicode string */
#if !_USE_LFN
#error _LFN_UNICODE must be 0 in non-LFN cfg.
#endif
#ifndef _INC_TCHAR
typedef WCHAR TCHAR;
#define _T(x) L ## x
#define _TEXT(x) L ## x
#endif
#else /* ANSI/OEM string */
#ifndef _INC_TCHAR
typedef char TCHAR;
#define _T(x) x
#define _TEXT(x) x
#endif
#endif
/* File system object structure (FATFS) */
typedef struct {
BYTE fs_type; /* FAT sub-type (0:Not mounted) */
BYTE drv; /* Physical drive number */
BYTE csize; /* Sectors per cluster (1,2,4...128) */
BYTE n_fats; /* Number of FAT copies (1,2) */
BYTE wflag; /* win[] dirty flag (1:must be written back) */
BYTE fsi_flag; /* fsinfo dirty flag (1:must be written back) */
WORD id; /* File system mount ID */
WORD n_rootdir; /* Number of root directory entries (FAT12/16) */
#if _MAX_SS != 512
WORD ssize; /* Bytes per sector (512, 1024, 2048 or 4096) */
#endif
#if _FS_REENTRANT
_SYNC_t sobj; /* Identifier of sync object */
#endif
#if !_FS_READONLY
DWORD last_clust; /* Last allocated cluster */
DWORD free_clust; /* Number of free clusters */
DWORD fsi_sector; /* fsinfo sector (FAT32) */
#endif
#if _FS_RPATH
DWORD cdir; /* Current directory start cluster (0:root) */
#endif
DWORD n_fatent; /* Number of FAT entries (= number of clusters + 2) */
DWORD fsize; /* Sectors per FAT */
DWORD fatbase; /* FAT start sector */
DWORD dirbase; /* Root directory start sector (FAT32:Cluster#) */
DWORD database; /* Data start sector */
DWORD winsect; /* Current sector appearing in the win[] */
BYTE win[_MAX_SS]; /* Disk access window for Directory, FAT (and Data on tiny cfg) */
} FATFS;
/* File object structure (FIL) */
typedef struct {
FATFS* fs; /* Pointer to the owner file system object */
WORD id; /* Owner file system mount ID */
BYTE flag; /* File status flags */
BYTE pad1;
DWORD fptr; /* File read/write pointer (0 on file open) */
DWORD fsize; /* File size */
DWORD sclust; /* File start cluster (0 when fsize==0) */
DWORD clust; /* Current cluster */
DWORD dsect; /* Current data sector */
#if !_FS_READONLY
DWORD dir_sect; /* Sector containing the directory entry */
BYTE* dir_ptr; /* Ponter to the directory entry in the window */
#endif
#if _USE_FASTSEEK
DWORD* cltbl; /* Pointer to the cluster link map table (null on file open) */
#endif
#if _FS_SHARE
UINT lockid; /* File lock ID (index of file semaphore table) */
#endif
#if !_FS_TINY
BYTE buf[_MAX_SS]; /* File data read/write buffer */
#endif
} FIL;
/* Directory object structure (DIR) */
typedef struct {
FATFS* fs; /* Pointer to the owner file system object */
WORD id; /* Owner file system mount ID */
WORD index; /* Current read/write index number */
DWORD sclust; /* Table start cluster (0:Root dir) */
DWORD clust; /* Current cluster */
DWORD sect; /* Current sector */
BYTE* dir; /* Pointer to the current SFN entry in the win[] */
BYTE* fn; /* Pointer to the SFN (in/out) {file[8],ext[3],status[1]} */
#if _USE_LFN
WCHAR* lfn; /* Pointer to the LFN working buffer */
WORD lfn_idx; /* Last matched LFN index number (0xFFFF:No LFN) */
#endif
} DIR;
/* File status structure (FILINFO) */
typedef struct {
DWORD fsize; /* File size */
WORD fdate; /* Last modified date */
WORD ftime; /* Last modified time */
BYTE fattrib; /* Attribute */
TCHAR fname[13]; /* Short file name (8.3 format) */
#if _USE_LFN
TCHAR* lfname; /* Pointer to the LFN buffer */
UINT lfsize; /* Size of LFN buffer in TCHAR */
#endif
} FILINFO;
/* File function return code (FRESULT) */
typedef enum {
FR_OK = 0, /* (0) Succeeded */
FR_DISK_ERR, /* (1) A hard error occured in the low level disk I/O layer */
FR_INT_ERR, /* (2) Assertion failed */
FR_NOT_READY, /* (3) The physical drive cannot work */
FR_NO_FILE, /* (4) Could not find the file */
FR_NO_PATH, /* (5) Could not find the path */
FR_INVALID_NAME, /* (6) The path name format is invalid */
FR_DENIED, /* (7) Acces denied due to prohibited access or directory full */
FR_EXIST, /* (8) Acces denied due to prohibited access */
FR_INVALID_OBJECT, /* (9) The file/directory object is invalid */
FR_WRITE_PROTECTED, /* (10) The physical drive is write protected */
FR_INVALID_DRIVE, /* (11) The logical drive number is invalid */
FR_NOT_ENABLED, /* (12) The volume has no work area */
FR_NO_FILESYSTEM, /* (13) There is no valid FAT volume */
FR_MKFS_ABORTED, /* (14) The f_mkfs() aborted due to any parameter error */
FR_TIMEOUT, /* (15) Could not get a grant to access the volume within defined period */
FR_LOCKED, /* (16) The operation is rejected according to the file shareing policy */
FR_NOT_ENOUGH_CORE, /* (17) LFN working buffer could not be allocated */
FR_TOO_MANY_OPEN_FILES, /* (18) Number of open files > _FS_SHARE */
FR_INVALID_PARAMETER /* (19) Given parameter is invalid */
} FRESULT;
/*--------------------------------------------------------------*/
/* FatFs module application interface */
FRESULT f_mount (BYTE, FATFS*); /* Mount/Unmount a logical drive */
FRESULT f_open (FIL*, const TCHAR*, BYTE); /* Open or create a file */
FRESULT f_read (FIL*, void*, UINT, UINT*); /* Read data from a file */
FRESULT f_lseek (FIL*, DWORD); /* Move file pointer of a file object */
FRESULT f_close (FIL*); /* Close an open file object */
FRESULT f_opendir (DIR*, const TCHAR*); /* Open an existing directory */
FRESULT f_readdir (DIR*, FILINFO*); /* Read a directory item */
FRESULT f_stat (const TCHAR*, FILINFO*); /* Get file status */
FRESULT f_write (FIL*, const void*, UINT, UINT*); /* Write data to a file */
FRESULT f_getfree (const TCHAR*, DWORD*, FATFS**); /* Get number of free clusters on the drive */
FRESULT f_truncate (FIL*); /* Truncate file */
FRESULT f_sync (FIL*); /* Flush cached data of a writing file */
FRESULT f_unlink (const TCHAR*); /* Delete an existing file or directory */
FRESULT f_mkdir (const TCHAR*); /* Create a new directory */
FRESULT f_chmod (const TCHAR*, BYTE, BYTE); /* Change attriburte of the file/dir */
FRESULT f_utime (const TCHAR*, const FILINFO*); /* Change timestamp of the file/dir */
FRESULT f_rename (const TCHAR*, const TCHAR*); /* Rename/Move a file or directory */
FRESULT f_chdrive (BYTE); /* Change current drive */
FRESULT f_chdir (const TCHAR*); /* Change current directory */
FRESULT f_getcwd (TCHAR*, UINT); /* Get current directory */
FRESULT f_forward (FIL*, UINT(*)(const BYTE*,UINT), UINT, UINT*); /* Forward data to the stream */
FRESULT f_mkfs (BYTE, BYTE, UINT); /* Create a file system on the drive */
FRESULT f_fdisk (BYTE, const DWORD[], void*); /* Divide a physical drive into some partitions */
int f_putc (TCHAR, FIL*); /* Put a character to the file */
int f_puts (const TCHAR*, FIL*); /* Put a string to the file */
int f_printf (FIL*, const TCHAR*, ...); /* Put a formatted string to the file */
TCHAR* f_gets (TCHAR*, int, FIL*); /* Get a string from the file */
#define f_eof(fp) (((fp)->fptr == (fp)->fsize) ? 1 : 0)
#define f_error(fp) (((fp)->flag & FA__ERROR) ? 1 : 0)
#define f_tell(fp) ((fp)->fptr)
#define f_size(fp) ((fp)->fsize)
#ifndef EOF
#define EOF (-1)
#endif
/*--------------------------------------------------------------*/
/* Additional user defined functions */
/* RTC function */
#if !_FS_READONLY
DWORD get_fattime (void);
#endif
/* Unicode support functions */
#if _USE_LFN /* Unicode - OEM code conversion */
WCHAR ff_convert (WCHAR, UINT); /* OEM-Unicode bidirectional conversion */
WCHAR ff_wtoupper (WCHAR); /* Unicode upper-case conversion */
#if _USE_LFN == 3 /* Memory functions */
//void* ff_memalloc (UINT); /* Allocate memory block */
//void ff_memfree (void*); /* Free memory block */
#endif
#endif
/* Sync functions */
#if _FS_REENTRANT
int ff_cre_syncobj (BYTE, _SYNC_t*);/* Create a sync object */
int ff_req_grant (_SYNC_t); /* Lock sync object */
void ff_rel_grant (_SYNC_t); /* Unlock sync object */
int ff_del_syncobj (_SYNC_t); /* Delete a sync object */
#endif
/*--------------------------------------------------------------*/
/* Flags and offset address */
/* File access control and file status flags (FIL.flag) */
#define FA_READ 0x01
#define FA_OPEN_EXISTING 0x00
#define FA__ERROR 0x80
#if !_FS_READONLY
#define FA_WRITE 0x02
#define FA_CREATE_NEW 0x04
#define FA_CREATE_ALWAYS 0x08
#define FA_OPEN_ALWAYS 0x10
#define FA__WRITTEN 0x20
#define FA__DIRTY 0x40
#endif
/* FAT sub type (FATFS.fs_type) */
#define FS_FAT12 1
#define FS_FAT16 2
#define FS_FAT32 3
/* File attribute bits for directory entry */
#define AM_RDO 0x01 /* Read only */
#define AM_HID 0x02 /* Hidden */
#define AM_SYS 0x04 /* System */
#define AM_VOL 0x08 /* Volume label */
#define AM_LFN 0x0F /* LFN entry */
#define AM_DIR 0x10 /* Directory */
#define AM_ARC 0x20 /* Archive */
#define AM_MASK 0x3F /* Mask of defined bits */
/* Fast seek feature */
#define CREATE_LINKMAP 0xFFFFFFFF
/*--------------------------------*/
/* Multi-byte word access macros */
#if _WORD_ACCESS == 1 /* Enable word access to the FAT structure */
#define LD_WORD(ptr) (WORD)(*(WORD*)(BYTE*)(ptr))
#define LD_DWORD(ptr) (DWORD)(*(DWORD*)(BYTE*)(ptr))
#define ST_WORD(ptr,val) *(WORD*)(BYTE*)(ptr)=(WORD)(val)
#define ST_DWORD(ptr,val) *(DWORD*)(BYTE*)(ptr)=(DWORD)(val)
#else /* Use byte-by-byte access to the FAT structure */
#define LD_WORD(ptr) (WORD)(((WORD)*((BYTE*)(ptr)+1)<<8)|(WORD)*(BYTE*)(ptr))
#define LD_DWORD(ptr) (DWORD)(((DWORD)*((BYTE*)(ptr)+3)<<24)|((DWORD)*((BYTE*)(ptr)+2)<<16)|((WORD)*((BYTE*)(ptr)+1)<<8)|*(BYTE*)(ptr))
#define ST_WORD(ptr,val) *(BYTE*)(ptr)=(BYTE)(val); *((BYTE*)(ptr)+1)=(BYTE)((WORD)(val)>>8)
#define ST_DWORD(ptr,val) *(BYTE*)(ptr)=(BYTE)(val); *((BYTE*)(ptr)+1)=(BYTE)((WORD)(val)>>8); *((BYTE*)(ptr)+2)=(BYTE)((DWORD)(val)>>16); *((BYTE*)(ptr)+3)=(BYTE)((DWORD)(val)>>24)
#endif
#ifdef __cplusplus
}
#endif
#endif /* _FATFS */

View File

@ -0,0 +1,190 @@
/*---------------------------------------------------------------------------/
/ FatFs - FAT file system module configuration file R0.09 (C)ChaN, 2011
/----------------------------------------------------------------------------/
/
/ CAUTION! Do not forget to make clean the project after any changes to
/ the configuration options.
/
/----------------------------------------------------------------------------*/
#ifndef _FFCONF
#define _FFCONF 6502 /* Revision ID */
/*---------------------------------------------------------------------------/
/ Functions and Buffer Configurations
/----------------------------------------------------------------------------*/
#define _FS_TINY 0 /* 0:Normal or 1:Tiny */
/* When _FS_TINY is set to 1, FatFs uses the sector buffer in the file system
/ object instead of the sector buffer in the individual file object for file
/ data transfer. This reduces memory consumption 512 bytes each file object. */
#define _FS_READONLY 0 /* 0:Read/Write or 1:Read only */
/* Setting _FS_READONLY to 1 defines read only configuration. This removes
/ writing functions, f_write, f_sync, f_unlink, f_mkdir, f_chmod, f_rename,
/ f_truncate and useless f_getfree. */
#define _FS_MINIMIZE 0 /* 0 to 3 */
/* The _FS_MINIMIZE option defines minimization level to remove some functions.
/
/ 0: Full function.
/ 1: f_stat, f_getfree, f_unlink, f_mkdir, f_chmod, f_truncate and f_rename
/ are removed.
/ 2: f_opendir and f_readdir are removed in addition to 1.
/ 3: f_lseek is removed in addition to 2. */
#define _USE_STRFUNC 1 /* 0:Disable or 1-2:Enable */
/* To enable string functions, set _USE_STRFUNC to 1 or 2. */
#define _USE_MKFS 1 /* 0:Disable or 1:Enable */
/* To enable f_mkfs function, set _USE_MKFS to 1 and set _FS_READONLY to 0 */
#define _USE_FORWARD 0 /* 0:Disable or 1:Enable */
/* To enable f_forward function, set _USE_FORWARD to 1 and set _FS_TINY to 1. */
#define _USE_FASTSEEK 1 /* 0:Disable or 1:Enable */
/* To enable fast seek feature, set _USE_FASTSEEK to 1. */
/*---------------------------------------------------------------------------/
/ Locale and Namespace Configurations
/----------------------------------------------------------------------------*/
#define _CODE_PAGE 936
/* The _CODE_PAGE specifies the OEM code page to be used on the target system.
/ Incorrect setting of the code page can cause a file open failure.
/
/ 932 - Japanese Shift-JIS (DBCS, OEM, Windows)
/ 936 - Simplified Chinese GBK (DBCS, OEM, Windows)
/ 949 - Korean (DBCS, OEM, Windows)
/ 950 - Traditional Chinese Big5 (DBCS, OEM, Windows)
/ 1250 - Central Europe (Windows)
/ 1251 - Cyrillic (Windows)
/ 1252 - Latin 1 (Windows)
/ 1253 - Greek (Windows)
/ 1254 - Turkish (Windows)
/ 1255 - Hebrew (Windows)
/ 1256 - Arabic (Windows)
/ 1257 - Baltic (Windows)
/ 1258 - Vietnam (OEM, Windows)
/ 437 - U.S. (OEM)
/ 720 - Arabic (OEM)
/ 737 - Greek (OEM)
/ 775 - Baltic (OEM)
/ 850 - Multilingual Latin 1 (OEM)
/ 858 - Multilingual Latin 1 + Euro (OEM)
/ 852 - Latin 2 (OEM)
/ 855 - Cyrillic (OEM)
/ 866 - Russian (OEM)
/ 857 - Turkish (OEM)
/ 862 - Hebrew (OEM)
/ 874 - Thai (OEM, Windows)
/ 1 - ASCII only (Valid for non LFN cfg.)
*/
#define _USE_LFN 0 /* 0 to 3 */
#define _MAX_LFN 255 /* Maximum LFN length to handle (12 to 255) */
/* The _USE_LFN option switches the LFN support.
/
/ 0: Disable LFN feature. _MAX_LFN and _LFN_UNICODE have no effect.
/ 1: Enable LFN with static working buffer on the BSS. Always NOT reentrant.
/ 2: Enable LFN with dynamic working buffer on the STACK.
/ 3: Enable LFN with dynamic working buffer on the HEAP.
/
/ The LFN working buffer occupies (_MAX_LFN + 1) * 2 bytes. To enable LFN,
/ Unicode handling functions ff_convert() and ff_wtoupper() must be added
/ to the project. When enable to use heap, memory control functions
/ ff_memalloc() and ff_memfree() must be added to the project. */
#define _LFN_UNICODE 0 /* 0:ANSI/OEM or 1:Unicode */
/* To switch the character code set on FatFs API to Unicode,
/ enable LFN feature and set _LFN_UNICODE to 1. */
#define _FS_RPATH 1 /* 0 to 2 */
/* The _FS_RPATH option configures relative path feature.
/
/ 0: Disable relative path feature and remove related functions.
/ 1: Enable relative path. f_chdrive() and f_chdir() are available.
/ 2: f_getcwd() is available in addition to 1.
/
/ Note that output of the f_readdir fnction is affected by this option. */
/*---------------------------------------------------------------------------/
/ Physical Drive Configurations
/----------------------------------------------------------------------------*/
#define _VOLUMES 1
/* Number of volumes (logical drives) to be used. */
#define _MAX_SS 512 /* 512, 1024, 2048 or 4096 */
/* Maximum sector size to be handled.
/ Always set 512 for memory card and hard disk but a larger value may be
/ required for on-board flash memory, floppy disk and optical disk.
/ When _MAX_SS is larger than 512, it configures FatFs to variable sector size
/ and GET_SECTOR_SIZE command must be implememted to the disk_ioctl function. */
#define _MULTI_PARTITION 0 /* 0:Single partition, 1/2:Enable multiple partition */
/* When set to 0, each volume is bound to the same physical drive number and
/ it can mount only first primaly partition. When it is set to 1, each volume
/ is tied to the partitions listed in VolToPart[]. */
#define _USE_ERASE 0 /* 0:Disable or 1:Enable */
/* To enable sector erase feature, set _USE_ERASE to 1. CTRL_ERASE_SECTOR command
/ should be added to the disk_ioctl functio. */
/*---------------------------------------------------------------------------/
/ System Configurations
/----------------------------------------------------------------------------*/
#define _WORD_ACCESS 0 /* 0 or 1 */
/* Set 0 first and it is always compatible with all platforms. The _WORD_ACCESS
/ option defines which access method is used to the word data on the FAT volume.
/
/ 0: Byte-by-byte access.
/ 1: Word access. Do not choose this unless following condition is met.
/
/ When the byte order on the memory is big-endian or address miss-aligned word
/ access results incorrect behavior, the _WORD_ACCESS must be set to 0.
/ If it is not the case, the value can also be set to 1 to improve the
/ performance and code size.
*/
/* A header file that defines sync object types on the O/S, such as
/ windows.h, ucos_ii.h and semphr.h, must be included prior to ff.h. */
#define _FS_REENTRANT 0 /* 0:Disable or 1:Enable */
#define _FS_TIMEOUT 1000 /* Timeout period in unit of time ticks */
#define _SYNC_t HANDLE /* O/S dependent type of sync object. e.g. HANDLE, OS_EVENT*, ID and etc.. */
/* The _FS_REENTRANT option switches the reentrancy (thread safe) of the FatFs module.
/
/ 0: Disable reentrancy. _SYNC_t and _FS_TIMEOUT have no effect.
/ 1: Enable reentrancy. Also user provided synchronization handlers,
/ ff_req_grant, ff_rel_grant, ff_del_syncobj and ff_cre_syncobj
/ function must be added to the project. */
#define _FS_SHARE 0 /* 0:Disable or >=1:Enable */
/* To enable file shareing feature, set _FS_SHARE to 1 or greater. The value
defines how many files can be opened simultaneously. */
#endif /* _FFCONFIG */

View File

@ -0,0 +1,37 @@
/*-------------------------------------------*/
/* Integer type definitions for FatFs module */
/*-------------------------------------------*/
#ifndef _INTEGER
#define _INTEGER
#ifdef _WIN32 /* FatFs development platform */
#include <windows.h>
#include <tchar.h>
#else /* Embedded platform */
/* These types must be 16-bit, 32-bit or larger integer */
typedef int INT;
typedef unsigned int UINT;
/* These types must be 8-bit integer */
typedef char CHAR;
typedef unsigned char UCHAR;
typedef unsigned char BYTE;
/* These types must be 16-bit integer */
typedef short SHORT;
typedef unsigned short USHORT;
typedef unsigned short WORD;
typedef unsigned short WCHAR;
/* These types must be 32-bit integer */
typedef long LONG;
typedef unsigned long ULONG;
typedef unsigned long DWORD;
#endif
#endif

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,540 @@
/*------------------------------------------------------------------------*/
/* Unicode - Local code bidirectional converter (C)ChaN, 2009 */
/* (SBCS code pages) */
/*------------------------------------------------------------------------*/
/* 437 U.S. (OEM)
/ 720 Arabic (OEM)
/ 1256 Arabic (Windows)
/ 737 Greek (OEM)
/ 1253 Greek (Windows)
/ 1250 Central Europe (Windows)
/ 775 Baltic (OEM)
/ 1257 Baltic (Windows)
/ 850 Multilingual Latin 1 (OEM)
/ 852 Latin 2 (OEM)
/ 1252 Latin 1 (Windows)
/ 855 Cyrillic (OEM)
/ 1251 Cyrillic (Windows)
/ 866 Russian (OEM)
/ 857 Turkish (OEM)
/ 1254 Turkish (Windows)
/ 858 Multilingual Latin 1 + Euro (OEM)
/ 862 Hebrew (OEM)
/ 1255 Hebrew (Windows)
/ 874 Thai (OEM, Windows)
/ 1258 Vietnam (OEM, Windows)
*/
#include "../ff.h"
#if _CODE_PAGE == 437
#define _TBLDEF 1
static
const WCHAR Tbl[] = { /* CP437(0x80-0xFF) to Unicode conversion table */
0x00C7, 0x00FC, 0x00E9, 0x00E2, 0x00E4, 0x00E0, 0x00E5, 0x00E7,
0x00EA, 0x00EB, 0x00E8, 0x00EF, 0x00EE, 0x00EC, 0x00C4, 0x00C5,
0x00C9, 0x00E6, 0x00C6, 0x00F4, 0x00F6, 0x00F2, 0x00FB, 0x00F9,
0x00FF, 0x00D6, 0x00DC, 0x00A2, 0x00A3, 0x00A5, 0x20A7, 0x0192,
0x00E1, 0x00ED, 0x00F3, 0x00FA, 0x00F1, 0x00D1, 0x00AA, 0x00BA,
0x00BF, 0x2310, 0x00AC, 0x00BD, 0x00BC, 0x00A1, 0x00AB, 0x00BB,
0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x2561, 0x2562, 0x2556,
0x2555, 0x2563, 0x2551, 0x2557, 0x255D, 0x255C, 0x255B, 0x2510,
0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x255E, 0x255F,
0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x2567,
0x2568, 0x2564, 0x2565, 0x2559, 0x2558, 0x2552, 0x2553, 0x256B,
0x256A, 0x2518, 0x250C, 0x2588, 0x2584, 0x258C, 0x2590, 0x2580,
0x03B1, 0x00DF, 0x0393, 0x03C0, 0x03A3, 0x03C3, 0x00B5, 0x03C4,
0x03A6, 0x0398, 0x03A9, 0x03B4, 0x221E, 0x03C6, 0x03B5, 0x2229,
0x2261, 0x00B1, 0x2265, 0x2264, 0x2320, 0x2321, 0x00F7, 0x2248,
0x00B0, 0x2219, 0x00B7, 0x221A, 0x207F, 0x00B2, 0x25A0, 0x00A0
};
#elif _CODE_PAGE == 720
#define _TBLDEF 1
static
const WCHAR Tbl[] = { /* CP720(0x80-0xFF) to Unicode conversion table */
0x0000, 0x0000, 0x00E9, 0x00E2, 0x0000, 0x00E0, 0x0000, 0x00E7,
0x00EA, 0x00EB, 0x00E8, 0x00EF, 0x00EE, 0x0000, 0x0000, 0x0000,
0x0000, 0x0651, 0x0652, 0x00F4, 0x00A4, 0x0640, 0x00FB, 0x00F9,
0x0621, 0x0622, 0x0623, 0x0624, 0x00A3, 0x0625, 0x0626, 0x0627,
0x0628, 0x0629, 0x062A, 0x062B, 0x062C, 0x062D, 0x062E, 0x062F,
0x0630, 0x0631, 0x0632, 0x0633, 0x0634, 0x0635, 0x00AB, 0x00BB,
0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x2561, 0x2562, 0x2556,
0x2555, 0x2563, 0x2551, 0x2557, 0x255D, 0x255C, 0x255B, 0x2510,
0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x255E, 0x255F,
0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x2567,
0x2568, 0x2564, 0x2565, 0x2559, 0x2558, 0x2552, 0x2553, 0x256B,
0x256A, 0x2518, 0x250C, 0x2588, 0x2584, 0x258C, 0x2590, 0x2580,
0x0636, 0x0637, 0x0638, 0x0639, 0x063A, 0x0641, 0x00B5, 0x0642,
0x0643, 0x0644, 0x0645, 0x0646, 0x0647, 0x0648, 0x0649, 0x064A,
0x2261, 0x064B, 0x064C, 0x064D, 0x064E, 0x064F, 0xO650, 0x2248,
0x00B0, 0x2219, 0x00B7, 0x221A, 0x207F, 0x00B2, 0x25A0, 0x00A0
};
#elif _CODE_PAGE == 737
#define _TBLDEF 1
static
const WCHAR Tbl[] = { /* CP737(0x80-0xFF) to Unicode conversion table */
0x0391, 0x0392, 0x0393, 0x0394, 0x0395, 0x0396, 0x0397, 0x0398,
0x0399, 0x039A, 0x039B, 0x039C, 0x039D, 0x039E, 0x039F, 0x03A0,
0x03A1, 0x03A3, 0x03A4, 0x03A5, 0x03A6, 0x03A7, 0x03A8, 0x03A9,
0x03B1, 0x03B2, 0x03B3, 0x03B4, 0x03B5, 0x03B6, 0x03B7, 0x03B8,
0x03B9, 0x03BA, 0x03BB, 0x03BC, 0x03BD, 0x03BE, 0x03BF, 0x03C0,
0x03C1, 0x03C3, 0x03C2, 0x03C4, 0x03C5, 0x03C6, 0x03C7, 0x03C8,
0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x2561, 0x2562, 0x2556,
0x2555, 0x2563, 0x2551, 0x2557, 0x255D, 0x255C, 0x255B, 0x2510,
0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x255E, 0x255F,
0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x2567,
0x2568, 0x2564, 0x2565, 0x2559, 0x2558, 0x2552, 0x2553, 0x256B,
0x256A, 0x2518, 0x250C, 0x2588, 0x2584, 0x258C, 0x2590, 0x2580,
0x03C9, 0x03AC, 0x03AD, 0x03AE, 0x03CA, 0x03AF, 0x03CC, 0x03CD,
0x03CB, 0x03CE, 0x0386, 0x0388, 0x0389, 0x038A, 0x038C, 0x038E,
0x038F, 0x00B1, 0x2265, 0x2264, 0x03AA, 0x03AB, 0x00F7, 0x2248,
0x00B0, 0x2219, 0x00B7, 0x221A, 0x207F, 0x00B2, 0x25A0, 0x00A0
};
#elif _CODE_PAGE == 775
#define _TBLDEF 1
static
const WCHAR Tbl[] = { /* CP775(0x80-0xFF) to Unicode conversion table */
0x0106, 0x00FC, 0x00E9, 0x0101, 0x00E4, 0x0123, 0x00E5, 0x0107,
0x0142, 0x0113, 0x0156, 0x0157, 0x012B, 0x0179, 0x00C4, 0x00C5,
0x00C9, 0x00E6, 0x00C6, 0x014D, 0x00F6, 0x0122, 0x00A2, 0x015A,
0x015B, 0x00D6, 0x00DC, 0x00F8, 0x00A3, 0x00D8, 0x00D7, 0x00A4,
0x0100, 0x012A, 0x00F3, 0x017B, 0x017C, 0x017A, 0x201D, 0x00A6,
0x00A9, 0x00AE, 0x00AC, 0x00BD, 0x00BC, 0x0141, 0x00AB, 0x00BB,
0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x0104, 0x010C, 0x0118,
0x0116, 0x2563, 0x2551, 0x2557, 0x255D, 0x012E, 0x0160, 0x2510,
0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x0172, 0x016A,
0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x017D,
0x0105, 0x010D, 0x0119, 0x0117, 0x012F, 0x0161, 0x0173, 0x016B,
0x017E, 0x2518, 0x250C, 0x2588, 0x2584, 0x258C, 0x2590, 0x2580,
0x00D3, 0x00DF, 0x014C, 0x0143, 0x00F5, 0x00D5, 0x00B5, 0x0144,
0x0136, 0x0137, 0x013B, 0x013C, 0x0146, 0x0112, 0x0145, 0x2019,
0x00AD, 0x00B1, 0x201C, 0x00BE, 0x00B6, 0x00A7, 0x00F7, 0x201E,
0x00B0, 0x2219, 0x00B7, 0x00B9, 0x00B3, 0x00B2, 0x25A0, 0x00A0
};
#elif _CODE_PAGE == 850
#define _TBLDEF 1
static
const WCHAR Tbl[] = { /* CP850(0x80-0xFF) to Unicode conversion table */
0x00C7, 0x00FC, 0x00E9, 0x00E2, 0x00E4, 0x00E0, 0x00E5, 0x00E7,
0x00EA, 0x00EB, 0x00E8, 0x00EF, 0x00EE, 0x00EC, 0x00C4, 0x00C5,
0x00C9, 0x00E6, 0x00C6, 0x00F4, 0x00F6, 0x00F2, 0x00FB, 0x00F9,
0x00FF, 0x00D6, 0x00DC, 0x00F8, 0x00A3, 0x00D8, 0x00D7, 0x0192,
0x00E1, 0x00ED, 0x00F3, 0x00FA, 0x00F1, 0x00D1, 0x00AA, 0x00BA,
0x00BF, 0x00AE, 0x00AC, 0x00BD, 0x00BC, 0x00A1, 0x00AB, 0x00BB,
0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x00C1, 0x00C2, 0x00C0,
0x00A9, 0x2563, 0x2551, 0x2557, 0x255D, 0x00A2, 0x00A5, 0x2510,
0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x00E3, 0x00C3,
0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x00A4,
0x00F0, 0x00D0, 0x00CA, 0x00CB, 0x00C8, 0x0131, 0x00CD, 0x00CE,
0x00CF, 0x2518, 0x250C, 0x2588, 0x2584, 0x00A6, 0x00CC, 0x2580,
0x00D3, 0x00DF, 0x00D4, 0x00D2, 0x00F5, 0x00D5, 0x00B5, 0x00FE,
0x00DE, 0x00DA, 0x00DB, 0x00D9, 0x00FD, 0x00DD, 0x00AF, 0x00B4,
0x00AD, 0x00B1, 0x2017, 0x00BE, 0x00B6, 0x00A7, 0x00F7, 0x00B8,
0x00B0, 0x00A8, 0x00B7, 0x00B9, 0x00B3, 0x00B2, 0x25A0, 0x00A0
};
#elif _CODE_PAGE == 852
#define _TBLDEF 1
static
const WCHAR Tbl[] = { /* CP852(0x80-0xFF) to Unicode conversion table */
0x00C7, 0x00FC, 0x00E9, 0x00E2, 0x00E4, 0x016F, 0x0107, 0x00E7,
0x0142, 0x00EB, 0x0150, 0x0151, 0x00EE, 0x0179, 0x00C4, 0x0106,
0x00C9, 0x0139, 0x013A, 0x00F4, 0x00F6, 0x013D, 0x013E, 0x015A,
0x015B, 0x00D6, 0x00DC, 0x0164, 0x0165, 0x0141, 0x00D7, 0x010D,
0x00E1, 0x00ED, 0x00F3, 0x00FA, 0x0104, 0x0105, 0x017D, 0x017E,
0x0118, 0x0119, 0x00AC, 0x017A, 0x010C, 0x015F, 0x00AB, 0x00BB,
0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x00C1, 0x00C2, 0x011A,
0x015E, 0x2563, 0x2551, 0x2557, 0x255D, 0x017B, 0x017C, 0x2510,
0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x0102, 0x0103,
0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x00A4,
0x0111, 0x0110, 0x010E, 0x00CB, 0x010F, 0x0147, 0x00CD, 0x00CE,
0x011B, 0x2518, 0x250C, 0x2588, 0x2584, 0x0162, 0x016E, 0x2580,
0x00D3, 0x00DF, 0x00D4, 0x0143, 0x0144, 0x0148, 0x0160, 0x0161,
0x0154, 0x00DA, 0x0155, 0x0170, 0x00FD, 0x00DD, 0x0163, 0x00B4,
0x00AD, 0x02DD, 0x02DB, 0x02C7, 0x02D8, 0x00A7, 0x00F7, 0x00B8,
0x00B0, 0x00A8, 0x02D9, 0x0171, 0x0158, 0x0159, 0x25A0, 0x00A0
};
#elif _CODE_PAGE == 855
#define _TBLDEF 1
static
const WCHAR Tbl[] = { /* CP855(0x80-0xFF) to Unicode conversion table */
0x0452, 0x0402, 0x0453, 0x0403, 0x0451, 0x0401, 0x0454, 0x0404,
0x0455, 0x0405, 0x0456, 0x0406, 0x0457, 0x0407, 0x0458, 0x0408,
0x0459, 0x0409, 0x045A, 0x040A, 0x045B, 0x040B, 0x045C, 0x040C,
0x045E, 0x040E, 0x045F, 0x040F, 0x044E, 0x042E, 0x044A, 0x042A,
0x0430, 0x0410, 0x0431, 0x0411, 0x0446, 0x0426, 0x0434, 0x0414,
0x0435, 0x0415, 0x0444, 0x0424, 0x0433, 0x0413, 0x00AB, 0x00BB,
0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x0445, 0x0425, 0x0438,
0x0418, 0x2563, 0x2551, 0x2557, 0x255D, 0x0439, 0x0419, 0x2510,
0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x043A, 0x041A,
0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x00A4,
0x043B, 0x041B, 0x043C, 0x041C, 0x043D, 0x041D, 0x043E, 0x041E,
0x043F, 0x2518, 0x250C, 0x2588, 0x2584, 0x041F, 0x044F, 0x2580,
0x042F, 0x0440, 0x0420, 0x0441, 0x0421, 0x0442, 0x0422, 0x0443,
0x0423, 0x0436, 0x0416, 0x0432, 0x0412, 0x044C, 0x042C, 0x2116,
0x00AD, 0x044B, 0x042B, 0x0437, 0x0417, 0x0448, 0x0428, 0x044D,
0x042D, 0x0449, 0x0429, 0x0447, 0x0427, 0x00A7, 0x25A0, 0x00A0
};
#elif _CODE_PAGE == 857
#define _TBLDEF 1
static
const WCHAR Tbl[] = { /* CP857(0x80-0xFF) to Unicode conversion table */
0x00C7, 0x00FC, 0x00E9, 0x00E2, 0x00E4, 0x00E0, 0x00E5, 0x00E7,
0x00EA, 0x00EB, 0x00E8, 0x00EF, 0x00EE, 0x0131, 0x00C4, 0x00C5,
0x00C9, 0x00E6, 0x00C6, 0x00F4, 0x00F6, 0x00F2, 0x00FB, 0x00F9,
0x0130, 0x00D6, 0x00DC, 0x00F8, 0x00A3, 0x00D8, 0x015E, 0x015F,
0x00E1, 0x00ED, 0x00F3, 0x00FA, 0x00F1, 0x00D1, 0x011E, 0x011F,
0x00BF, 0x00AE, 0x00AC, 0x00BD, 0x00BC, 0x00A1, 0x00AB, 0x00BB,
0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x00C1, 0x00C2, 0x00C0,
0x00A9, 0x2563, 0x2551, 0x2557, 0x255D, 0x00A2, 0x00A5, 0x2510,
0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x00E3, 0x00C3,
0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x00A4,
0x00BA, 0x00AA, 0x00CA, 0x00CB, 0x00C8, 0x0000, 0x00CD, 0x00CE,
0x00CF, 0x2518, 0x250C, 0x2588, 0x2584, 0x00A6, 0x00CC, 0x2580,
0x00D3, 0x00DF, 0x00D4, 0x00D2, 0x00F5, 0x00D5, 0x00B5, 0x0000,
0x00D7, 0x00DA, 0x00DB, 0x00D9, 0x00EC, 0x00FF, 0x00AF, 0x00B4,
0x00AD, 0x00B1, 0x0000, 0x00BE, 0x00B6, 0x00A7, 0x00F7, 0x00B8,
0x00B0, 0x00A8, 0x00B7, 0x00B9, 0x00B3, 0x00B2, 0x25A0, 0x00A0
};
#elif _CODE_PAGE == 858
#define _TBLDEF 1
static
const WCHAR Tbl[] = { /* CP858(0x80-0xFF) to Unicode conversion table */
0x00C7, 0x00FC, 0x00E9, 0x00E2, 0x00E4, 0x00E0, 0x00E5, 0x00E7,
0x00EA, 0x00EB, 0x00E8, 0x00EF, 0x00EE, 0x00EC, 0x00C4, 0x00C5,
0x00C9, 0x00E6, 0x00C6, 0x00F4, 0x00F6, 0x00F2, 0x00FB, 0x00F9,
0x00FF, 0x00D6, 0x00DC, 0x00F8, 0x00A3, 0x00D8, 0x00D7, 0x0192,
0x00E1, 0x00ED, 0x00F3, 0x00FA, 0x00F1, 0x00D1, 0x00AA, 0x00BA,
0x00BF, 0x00AE, 0x00AC, 0x00BD, 0x00BC, 0x00A1, 0x00AB, 0x00BB,
0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x00C1, 0x00C2, 0x00C0,
0x00A9, 0x2563, 0x2551, 0x2557, 0x2550, 0x00A2, 0x00A5, 0x2510,
0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x00E3, 0x00C3,
0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x00A4,
0x00F0, 0x00D0, 0x00CA, 0x00CB, 0x00C8, 0x20AC, 0x00CD, 0x00CE,
0x00CF, 0x2518, 0x250C, 0x2588, 0x2584, 0x00C6, 0x00CC, 0x2580,
0x00D3, 0x00DF, 0x00D4, 0x00D2, 0x00F5, 0x00D5, 0x00B5, 0x00FE,
0x00DE, 0x00DA, 0x00DB, 0x00D9, 0x00FD, 0x00DD, 0x00AF, 0x00B4,
0x00AD, 0x00B1, 0x2017, 0x00BE, 0x00B6, 0x00A7, 0x00F7, 0x00B8,
0x00B0, 0x00A8, 0x00B7, 0x00B9, 0x00B3, 0x00B2, 0x25A0, 0x00A0
};
#elif _CODE_PAGE == 862
#define _TBLDEF 1
static
const WCHAR Tbl[] = { /* CP862(0x80-0xFF) to Unicode conversion table */
0x05D0, 0x05D1, 0x05D2, 0x05D3, 0x05D4, 0x05D5, 0x05D6, 0x05D7,
0x05D8, 0x05D9, 0x05DA, 0x05DB, 0x05DC, 0x05DD, 0x05DE, 0x05DF,
0x05E0, 0x05E1, 0x05E2, 0x05E3, 0x05E4, 0x05E5, 0x05E6, 0x05E7,
0x05E8, 0x05E9, 0x05EA, 0x00A2, 0x00A3, 0x00A5, 0x20A7, 0x0192,
0x00E1, 0x00ED, 0x00F3, 0x00FA, 0x00F1, 0x00D1, 0x00AA, 0x00BA,
0x00BF, 0x2310, 0x00AC, 0x00BD, 0x00BC, 0x00A1, 0x00AB, 0x00BB,
0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x2561, 0x2562, 0x2556,
0x2555, 0x2563, 0x2551, 0x2557, 0x255D, 0x255C, 0x255B, 0x2510,
0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x255E, 0x255F,
0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x2567,
0x2568, 0x2564, 0x2565, 0x2559, 0x2558, 0x2552, 0x2553, 0x256B,
0x256A, 0x2518, 0x250C, 0x2588, 0x2584, 0x258C, 0x2590, 0x2580,
0x03B1, 0x00DF, 0x0393, 0x03C0, 0x03A3, 0x03C3, 0x00B5, 0x03C4,
0x03A6, 0x0398, 0x03A9, 0x03B4, 0x221E, 0x03C6, 0x03B5, 0x2229,
0x2261, 0x00B1, 0x2265, 0x2264, 0x2320, 0x2321, 0x00F7, 0x2248,
0x00B0, 0x2219, 0x00B7, 0x221A, 0x207F, 0x00B2, 0x25A0, 0x00A0
};
#elif _CODE_PAGE == 866
#define _TBLDEF 1
static
const WCHAR Tbl[] = { /* CP866(0x80-0xFF) to Unicode conversion table */
0x0410, 0x0411, 0x0412, 0x0413, 0x0414, 0x0415, 0x0416, 0x0417,
0x0418, 0x0419, 0x041A, 0x041B, 0x041C, 0x041D, 0x041E, 0x041F,
0x0420, 0x0421, 0x0422, 0x0423, 0x0424, 0x0425, 0x0426, 0x0427,
0x0428, 0x0429, 0x042A, 0x042B, 0x042C, 0x042D, 0x042E, 0x042F,
0x0430, 0x0431, 0x0432, 0x0433, 0x0434, 0x0435, 0x0436, 0x0437,
0x0438, 0x0439, 0x043A, 0x043B, 0x043C, 0x043D, 0x043E, 0x043F,
0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x2561, 0x2562, 0x2556,
0x2555, 0x2563, 0x2551, 0x2557, 0x255D, 0x255C, 0x255B, 0x2510,
0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x255E, 0x255F,
0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x2567,
0x2568, 0x2564, 0x2565, 0x2559, 0x2558, 0x2552, 0x2553, 0x256B,
0x256A, 0x2518, 0x250C, 0x2588, 0x2584, 0x258C, 0x2590, 0x2580,
0x0440, 0x0441, 0x0442, 0x0443, 0x0444, 0x0445, 0x0446, 0x0447,
0x0448, 0x0449, 0x044A, 0x044B, 0x044C, 0x044D, 0x044E, 0x044F,
0x0401, 0x0451, 0x0404, 0x0454, 0x0407, 0x0457, 0x040E, 0x045E,
0x00B0, 0x2219, 0x00B7, 0x221A, 0x2116, 0x00A4, 0x25A0, 0x00A0
};
#elif _CODE_PAGE == 874
#define _TBLDEF 1
static
const WCHAR Tbl[] = { /* CP874(0x80-0xFF) to Unicode conversion table */
0x20AC, 0x0000, 0x0000, 0x0000, 0x0000, 0x2026, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x00A0, 0x0E01, 0x0E02, 0x0E03, 0x0E04, 0x0E05, 0x0E06, 0x0E07,
0x0E08, 0x0E09, 0x0E0A, 0x0E0B, 0x0E0C, 0x0E0D, 0x0E0E, 0x0E0F,
0x0E10, 0x0E11, 0x0E12, 0x0E13, 0x0E14, 0x0E15, 0x0E16, 0x0E17,
0x0E18, 0x0E19, 0x0E1A, 0x0E1B, 0x0E1C, 0x0E1D, 0x0E1E, 0x0E1F,
0x0E20, 0x0E21, 0x0E22, 0x0E23, 0x0E24, 0x0E25, 0x0E26, 0x0E27,
0x0E28, 0x0E29, 0x0E2A, 0x0E2B, 0x0E2C, 0x0E2D, 0x0E2E, 0x0E2F,
0x0E30, 0x0E31, 0x0E32, 0x0E33, 0x0E34, 0x0E35, 0x0E36, 0x0E37,
0x0E38, 0x0E39, 0x0E3A, 0x0000, 0x0000, 0x0000, 0x0000, 0x0E3F,
0x0E40, 0x0E41, 0x0E42, 0x0E43, 0x0E44, 0x0E45, 0x0E46, 0x0E47,
0x0E48, 0x0E49, 0x0E4A, 0x0E4B, 0x0E4C, 0x0E4D, 0x0E4E, 0x0E4F,
0x0E50, 0x0E51, 0x0E52, 0x0E53, 0x0E54, 0x0E55, 0x0E56, 0x0E57,
0x0E58, 0x0E59, 0x0E5A, 0x0E5B, 0x0000, 0x0000, 0x0000, 0x0000
};
#elif _CODE_PAGE == 1250
#define _TBLDEF 1
static
const WCHAR Tbl[] = { /* CP1250(0x80-0xFF) to Unicode conversion table */
0x20AC, 0x0000, 0x201A, 0x0000, 0x201E, 0x2026, 0x2020, 0x2021,
0x0000, 0x2030, 0x0160, 0x2039, 0x015A, 0x0164, 0x017D, 0x0179,
0x0000, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
0x0000, 0x2122, 0x0161, 0x203A, 0x015B, 0x0165, 0x017E, 0x017A,
0x00A0, 0x02C7, 0x02D8, 0x0141, 0x00A4, 0x0104, 0x00A6, 0x00A7,
0x00A8, 0x00A9, 0x015E, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x017B,
0x00B0, 0x00B1, 0x02DB, 0x0142, 0x00B4, 0x00B5, 0x00B6, 0x00B7,
0x00B8, 0x0105, 0x015F, 0x00BB, 0x013D, 0x02DD, 0x013E, 0x017C,
0x0154, 0x00C1, 0x00C2, 0x0102, 0x00C4, 0x0139, 0x0106, 0x00C7,
0x010C, 0x00C9, 0x0118, 0x00CB, 0x011A, 0x00CD, 0x00CE, 0x010E,
0x0110, 0x0143, 0x0147, 0x00D3, 0x00D4, 0x0150, 0x00D6, 0x00D7,
0x0158, 0x016E, 0x00DA, 0x0170, 0x00DC, 0x00DD, 0x0162, 0x00DF,
0x0155, 0x00E1, 0x00E2, 0x0103, 0x00E4, 0x013A, 0x0107, 0x00E7,
0x010D, 0x00E9, 0x0119, 0x00EB, 0x011B, 0x00ED, 0x00EE, 0x010F,
0x0111, 0x0144, 0x0148, 0x00F3, 0x00F4, 0x0151, 0x00F6, 0x00F7,
0x0159, 0x016F, 0x00FA, 0x0171, 0x00FC, 0x00FD, 0x0163, 0x02D9
};
#elif _CODE_PAGE == 1251
#define _TBLDEF 1
static
const WCHAR Tbl[] = { /* CP1251(0x80-0xFF) to Unicode conversion table */
0x0402, 0x0403, 0x201A, 0x0453, 0x201E, 0x2026, 0x2020, 0x2021,
0x20AC, 0x2030, 0x0409, 0x2039, 0x040A, 0x040C, 0x040B, 0x040F,
0x0452, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
0x0000, 0x2111, 0x0459, 0x203A, 0x045A, 0x045C, 0x045B, 0x045F,
0x00A0, 0x040E, 0x045E, 0x0408, 0x00A4, 0x0490, 0x00A6, 0x00A7,
0x0401, 0x00A9, 0x0404, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x0407,
0x00B0, 0x00B1, 0x0406, 0x0456, 0x0491, 0x00B5, 0x00B6, 0x00B7,
0x0451, 0x2116, 0x0454, 0x00BB, 0x0458, 0x0405, 0x0455, 0x0457,
0x0410, 0x0411, 0x0412, 0x0413, 0x0414, 0x0415, 0x0416, 0x0417,
0x0418, 0x0419, 0x041A, 0x041B, 0x041C, 0x041D, 0x041E, 0x041F,
0x0420, 0x0421, 0x0422, 0x0423, 0x0424, 0x0425, 0x0426, 0x0427,
0x0428, 0x0429, 0x042A, 0x042B, 0x042C, 0x042D, 0x042E, 0x042F,
0x0430, 0x0431, 0x0432, 0x0433, 0x0434, 0x0435, 0x0436, 0x0437,
0x0438, 0x0439, 0x043A, 0x043B, 0x043C, 0x043D, 0x043E, 0x043F,
0x0440, 0x0441, 0x0442, 0x0443, 0x0444, 0x0445, 0x0446, 0x0447,
0x0448, 0x0449, 0x044A, 0x044B, 0x044C, 0x044D, 0x044E, 0x044F
};
#elif _CODE_PAGE == 1252
#define _TBLDEF 1
static
const WCHAR Tbl[] = { /* CP1252(0x80-0xFF) to Unicode conversion table */
0x20AC, 0x0000, 0x201A, 0x0192, 0x201E, 0x2026, 0x2020, 0x2021,
0x02C6, 0x2030, 0x0160, 0x2039, 0x0152, 0x0000, 0x017D, 0x0000,
0x0000, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
0x02DC, 0x2122, 0x0161, 0x203A, 0x0153, 0x0000, 0x017E, 0x0178,
0x00A0, 0x00A1, 0x00A2, 0x00A3, 0x00A4, 0x00A5, 0x00A6, 0x00A7,
0x00A8, 0x00A9, 0x00AA, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x00AF,
0x00B0, 0x00B1, 0x00B2, 0x00B3, 0x00B4, 0x00B5, 0x00B6, 0x00B7,
0x00B8, 0x00B9, 0x00BA, 0x00BB, 0x00BC, 0x00BD, 0x00BE, 0x00BF,
0x00C0, 0x00C1, 0x00C2, 0x00C3, 0x00C4, 0x00C5, 0x00C6, 0x00C7,
0x00C8, 0x00C9, 0x00CA, 0x00CB, 0x00CC, 0x00CD, 0x00CE, 0x00CF,
0x00D0, 0x00D1, 0x00D2, 0x00D3, 0x00D4, 0x00D5, 0x00D6, 0x00D7,
0x00D8, 0x00D9, 0x00DA, 0x00DB, 0x00DC, 0x00DD, 0x00DE, 0x00DF,
0x00E0, 0x00E1, 0x00E2, 0x00E3, 0x00E4, 0x00E5, 0x00E6, 0x00E7,
0x00E8, 0x00E9, 0x00EA, 0x00EB, 0x00EC, 0x00ED, 0x00EE, 0x00EF,
0x00F0, 0x00F1, 0x00F2, 0x00F3, 0x00F4, 0x00F5, 0x00F6, 0x00F7,
0x00F8, 0x00F9, 0x00FA, 0x00FB, 0x00FC, 0x00FD, 0x00FE, 0x00FF
};
#elif _CODE_PAGE == 1253
#define _TBLDEF 1
static
const WCHAR Tbl[] = { /* CP1253(0x80-0xFF) to Unicode conversion table */
0x20AC, 0x0000, 0x201A, 0x0192, 0x201E, 0x2026, 0x2020, 0x2021,
0x0000, 0x2030, 0x0000, 0x2039, 0x000C, 0x0000, 0x0000, 0x0000,
0x0000, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
0x0000, 0x2122, 0x0000, 0x203A, 0x0000, 0x0000, 0x0000, 0x0000,
0x00A0, 0x0385, 0x0386, 0x00A3, 0x00A4, 0x00A5, 0x00A6, 0x00A7,
0x00A8, 0x00A9, 0x0000, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x2015,
0x00B0, 0x00B1, 0x00B2, 0x00B3, 0x0384, 0x00B5, 0x00B6, 0x00B7,
0x0388, 0x0389, 0x038A, 0x00BB, 0x038C, 0x00BD, 0x038E, 0x038F,
0x0390, 0x0391, 0x0392, 0x0393, 0x0394, 0x0395, 0x0396, 0x0397,
0x0398, 0x0399, 0x039A, 0x039B, 0x039C, 0x039D, 0x039E, 0x039F,
0x03A0, 0x03A1, 0x0000, 0x03A3, 0x03A4, 0x03A5, 0x03A6, 0x03A7,
0x03A8, 0x03A9, 0x03AA, 0x03AD, 0x03AC, 0x03AD, 0x03AE, 0x03AF,
0x03B0, 0x03B1, 0x03B2, 0x03B3, 0x03B4, 0x03B5, 0x03B6, 0x03B7,
0x03B8, 0x03B9, 0x03BA, 0x03BB, 0x03BC, 0x03BD, 0x03BE, 0x03BF,
0x03C0, 0x03C1, 0x03C2, 0x03C3, 0x03C4, 0x03C5, 0x03C6, 0x03C7,
0x03C8, 0x03C9, 0x03CA, 0x03CB, 0x03CC, 0x03CD, 0x03CE, 0x0000
};
#elif _CODE_PAGE == 1254
#define _TBLDEF 1
static
const WCHAR Tbl[] = { /* CP1254(0x80-0xFF) to Unicode conversion table */
0x20AC, 0x0000, 0x210A, 0x0192, 0x201E, 0x2026, 0x2020, 0x2021,
0x02C6, 0x2030, 0x0160, 0x2039, 0x0152, 0x0000, 0x0000, 0x0000,
0x0000, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
0x02DC, 0x2122, 0x0161, 0x203A, 0x0153, 0x0000, 0x0000, 0x0178,
0x00A0, 0x00A1, 0x00A2, 0x00A3, 0x00A4, 0x00A5, 0x00A6, 0x00A7,
0x00A8, 0x00A9, 0x00AA, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x00AF,
0x00B0, 0x00B1, 0x00B2, 0x00B3, 0x00B4, 0x00B5, 0x00B6, 0x00B7,
0x00B8, 0x00B9, 0x00BA, 0x00BB, 0x00BC, 0x00BD, 0x00BE, 0x00BF,
0x00C0, 0x00C1, 0x00C2, 0x00C3, 0x00C4, 0x00C5, 0x00C6, 0x00C7,
0x00C8, 0x00C9, 0x00CA, 0x00CB, 0x00CC, 0x00CD, 0x00CE, 0x00CF,
0x011E, 0x00D1, 0x00D2, 0x00D3, 0x00D4, 0x00D5, 0x00D6, 0x00D7,
0x00D8, 0x00D9, 0x00DA, 0x00BD, 0x00DC, 0x0130, 0x015E, 0x00DF,
0x00E0, 0x00E1, 0x00E2, 0x00E3, 0x00E4, 0x00E5, 0x00E6, 0x00E7,
0x00E8, 0x00E9, 0x00EA, 0x00EB, 0x00EC, 0x00ED, 0x00EE, 0x00EF,
0x011F, 0x00F1, 0x00F2, 0x00F3, 0x00F4, 0x00F5, 0x00F6, 0x00F7,
0x00F8, 0x00F9, 0x00FA, 0x00FB, 0x00FC, 0x0131, 0x015F, 0x00FF
};
#elif _CODE_PAGE == 1255
#define _TBLDEF 1
static
const WCHAR Tbl[] = { /* CP1255(0x80-0xFF) to Unicode conversion table */
0x20AC, 0x0000, 0x201A, 0x0192, 0x201E, 0x2026, 0x2020, 0x2021,
0x02C6, 0x2030, 0x0000, 0x2039, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
0x02DC, 0x2122, 0x0000, 0x203A, 0x0000, 0x0000, 0x0000, 0x0000,
0x00A0, 0x00A1, 0x00A2, 0x00A3, 0x00A4, 0x00A5, 0x00A6, 0x00A7,
0x00A8, 0x00A9, 0x00D7, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x00AF,
0x00B0, 0x00B1, 0x00B2, 0x00B3, 0x00B4, 0x00B5, 0x00B6, 0x00B7,
0x00B8, 0x00B9, 0x00F7, 0x00BB, 0x00BC, 0x00BD, 0x00BE, 0x00BF,
0x05B0, 0x05B1, 0x05B2, 0x05B3, 0x05B4, 0x05B5, 0x05B6, 0x05B7,
0x05B8, 0x05B9, 0x0000, 0x05BB, 0x05BC, 0x05BD, 0x05BE, 0x05BF,
0x05C0, 0x05C1, 0x05C2, 0x05C3, 0x05F0, 0x05F1, 0x05F2, 0x05F3,
0x05F4, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x05D0, 0x05D1, 0x05D2, 0x05D3, 0x05D4, 0x05D5, 0x05D6, 0x05D7,
0x05D8, 0x05D9, 0x05DA, 0x05DB, 0x05DC, 0x05DD, 0x05DE, 0x05DF,
0x05E0, 0x05E1, 0x05E2, 0x05E3, 0x05E4, 0x05E5, 0x05E6, 0x05E7,
0x05E8, 0x05E9, 0x05EA, 0x0000, 0x0000, 0x200E, 0x200F, 0x0000
};
#elif _CODE_PAGE == 1256
#define _TBLDEF 1
static
const WCHAR Tbl[] = { /* CP1256(0x80-0xFF) to Unicode conversion table */
0x20AC, 0x067E, 0x201A, 0x0192, 0x201E, 0x2026, 0x2020, 0x2021,
0x02C6, 0x2030, 0x0679, 0x2039, 0x0152, 0x0686, 0x0698, 0x0688,
0x06AF, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
0x06A9, 0x2122, 0x0691, 0x203A, 0x0153, 0x200C, 0x200D, 0x06BA,
0x00A0, 0x060C, 0x00A2, 0x00A3, 0x00A4, 0x00A5, 0x00A6, 0x00A7,
0x00A8, 0x00A9, 0x06BE, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x00AF,
0x00B0, 0x00B1, 0x00B2, 0x00B3, 0x00B4, 0x00B5, 0x00B6, 0x00B7,
0x00B8, 0x00B9, 0x061B, 0x00BB, 0x00BC, 0x00BD, 0x00BE, 0x061F,
0x06C1, 0x0621, 0x0622, 0x0623, 0x0624, 0x0625, 0x0626, 0x0627,
0x0628, 0x0629, 0x062A, 0x062B, 0x062C, 0x062D, 0x062E, 0x062F,
0x0630, 0x0631, 0x0632, 0x0633, 0x0634, 0x0635, 0x0636, 0x00D7,
0x0637, 0x0638, 0x0639, 0x063A, 0x0640, 0x0640, 0x0642, 0x0643,
0x00E0, 0x0644, 0x00E2, 0x0645, 0x0646, 0x0647, 0x0648, 0x00E7,
0x00E8, 0x00E9, 0x00EA, 0x00EB, 0x0649, 0x064A, 0x00EE, 0x00EF,
0x064B, 0x064C, 0x064D, 0x064E, 0x00F4, 0x064F, 0x0650, 0x00F7,
0x0651, 0x00F9, 0x0652, 0x00FB, 0x00FC, 0x200E, 0x200F, 0x06D2
}
#elif _CODE_PAGE == 1257
#define _TBLDEF 1
static
const WCHAR Tbl[] = { /* CP1257(0x80-0xFF) to Unicode conversion table */
0x20AC, 0x0000, 0x201A, 0x0000, 0x201E, 0x2026, 0x2020, 0x2021,
0x0000, 0x2030, 0x0000, 0x2039, 0x0000, 0x00A8, 0x02C7, 0x00B8,
0x0000, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
0x0000, 0x2122, 0x0000, 0x203A, 0x0000, 0x00AF, 0x02DB, 0x0000,
0x00A0, 0x0000, 0x00A2, 0x00A3, 0x00A4, 0x0000, 0x00A6, 0x00A7,
0x00D8, 0x00A9, 0x0156, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x00AF,
0x00B0, 0x00B1, 0x00B2, 0x00B3, 0x00B4, 0x00B5, 0x00B6, 0x00B7,
0x00B8, 0x00B9, 0x0157, 0x00BB, 0x00BC, 0x00BD, 0x00BE, 0x00E6,
0x0104, 0x012E, 0x0100, 0x0106, 0x00C4, 0x00C5, 0x0118, 0x0112,
0x010C, 0x00C9, 0x0179, 0x0116, 0x0122, 0x0136, 0x012A, 0x013B,
0x0160, 0x0143, 0x0145, 0x00D3, 0x014C, 0x00D5, 0x00D6, 0x00D7,
0x0172, 0x0141, 0x015A, 0x016A, 0x00DC, 0x017B, 0x017D, 0x00DF,
0x0105, 0x012F, 0x0101, 0x0107, 0x00E4, 0x00E5, 0x0119, 0x0113,
0x010D, 0x00E9, 0x017A, 0x0117, 0x0123, 0x0137, 0x012B, 0x013C,
0x0161, 0x0144, 0x0146, 0x00F3, 0x014D, 0x00F5, 0x00F6, 0x00F7,
0x0173, 0x014E, 0x015B, 0x016B, 0x00FC, 0x017C, 0x017E, 0x02D9
};
#elif _CODE_PAGE == 1258
#define _TBLDEF 1
static
const WCHAR Tbl[] = { /* CP1258(0x80-0xFF) to Unicode conversion table */
0x20AC, 0x0000, 0x201A, 0x0192, 0x201E, 0x2026, 0x2020, 0x2021,
0x02C6, 0x2030, 0x0000, 0x2039, 0x0152, 0x0000, 0x0000, 0x0000,
0x0000, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
0x02DC, 0x2122, 0x0000, 0x203A, 0x0153, 0x0000, 0x0000, 0x0178,
0x00A0, 0x00A1, 0x00A2, 0x00A3, 0x00A4, 0x00A5, 0x00A6, 0x00A7,
0x00A8, 0x00A9, 0x00AA, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x00AF,
0x00B0, 0x00B1, 0x00B2, 0x00B3, 0x00B4, 0x00B5, 0x00B6, 0x00B7,
0x00B8, 0x00B9, 0x00BA, 0x00BB, 0x00BC, 0x00BD, 0x00BE, 0x00BF,
0x00C0, 0x00C1, 0x00C2, 0x0102, 0x00C4, 0x00C5, 0x00C6, 0x00C7,
0x00C8, 0x00C9, 0x00CA, 0x00CB, 0x0300, 0x00CD, 0x00CE, 0x00CF,
0x0110, 0x00D1, 0x0309, 0x00D3, 0x00D4, 0x01A0, 0x00D6, 0x00D7,
0x00D8, 0x00D9, 0x00DA, 0x00DB, 0x00DC, 0x01AF, 0x0303, 0x00DF,
0x00E0, 0x00E1, 0x00E2, 0x0103, 0x00E4, 0x00E5, 0x00E6, 0x00E7,
0x00E8, 0x00E9, 0x00EA, 0x00EB, 0x0301, 0x00ED, 0x00EE, 0x00EF,
0x0111, 0x00F1, 0x0323, 0x00F3, 0x00F4, 0x01A1, 0x00F6, 0x00F7,
0x00F8, 0x00F9, 0x00FA, 0x00FB, 0x00FC, 0x01B0, 0x20AB, 0x00FF
};
#endif
#if !_TBLDEF || !_USE_LFN
#error This file is not needed in current configuration. Remove from the project.
#endif
WCHAR ff_convert ( /* Converted character, Returns zero on error */
WCHAR src, /* Character code to be converted */
UINT dir /* 0: Unicode to OEMCP, 1: OEMCP to Unicode */
)
{
WCHAR c;
if (src < 0x80) { /* ASCII */
c = src;
} else {
if (dir) { /* OEMCP to Unicode */
c = (src >= 0x100) ? 0 : Tbl[src - 0x80];
} else { /* Unicode to OEMCP */
for (c = 0; c < 0x80; c++) {
if (src == Tbl[c]) break;
}
c = (c + 0x80) & 0xFF;
}
}
return c;
}
WCHAR ff_wtoupper ( /* Upper converted character */
WCHAR chr /* Input character */
)
{
static const WCHAR tbl_lower[] = { 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A, 0xA1, 0x00A2, 0x00A3, 0x00A5, 0x00AC, 0x00AF, 0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF, 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0x0FF, 0x101, 0x103, 0x105, 0x107, 0x109, 0x10B, 0x10D, 0x10F, 0x111, 0x113, 0x115, 0x117, 0x119, 0x11B, 0x11D, 0x11F, 0x121, 0x123, 0x125, 0x127, 0x129, 0x12B, 0x12D, 0x12F, 0x131, 0x133, 0x135, 0x137, 0x13A, 0x13C, 0x13E, 0x140, 0x142, 0x144, 0x146, 0x148, 0x14B, 0x14D, 0x14F, 0x151, 0x153, 0x155, 0x157, 0x159, 0x15B, 0x15D, 0x15F, 0x161, 0x163, 0x165, 0x167, 0x169, 0x16B, 0x16D, 0x16F, 0x171, 0x173, 0x175, 0x177, 0x17A, 0x17C, 0x17E, 0x192, 0x3B1, 0x3B2, 0x3B3, 0x3B4, 0x3B5, 0x3B6, 0x3B7, 0x3B8, 0x3B9, 0x3BA, 0x3BB, 0x3BC, 0x3BD, 0x3BE, 0x3BF, 0x3C0, 0x3C1, 0x3C3, 0x3C4, 0x3C5, 0x3C6, 0x3C7, 0x3C8, 0x3C9, 0x3CA, 0x430, 0x431, 0x432, 0x433, 0x434, 0x435, 0x436, 0x437, 0x438, 0x439, 0x43A, 0x43B, 0x43C, 0x43D, 0x43E, 0x43F, 0x440, 0x441, 0x442, 0x443, 0x444, 0x445, 0x446, 0x447, 0x448, 0x449, 0x44A, 0x44B, 0x44C, 0x44D, 0x44E, 0x44F, 0x451, 0x452, 0x453, 0x454, 0x455, 0x456, 0x457, 0x458, 0x459, 0x45A, 0x45B, 0x45C, 0x45E, 0x45F, 0x2170, 0x2171, 0x2172, 0x2173, 0x2174, 0x2175, 0x2176, 0x2177, 0x2178, 0x2179, 0x217A, 0x217B, 0x217C, 0x217D, 0x217E, 0x217F, 0xFF41, 0xFF42, 0xFF43, 0xFF44, 0xFF45, 0xFF46, 0xFF47, 0xFF48, 0xFF49, 0xFF4A, 0xFF4B, 0xFF4C, 0xFF4D, 0xFF4E, 0xFF4F, 0xFF50, 0xFF51, 0xFF52, 0xFF53, 0xFF54, 0xFF55, 0xFF56, 0xFF57, 0xFF58, 0xFF59, 0xFF5A, 0 };
static const WCHAR tbl_upper[] = { 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x21, 0xFFE0, 0xFFE1, 0xFFE5, 0xFFE2, 0xFFE3, 0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF, 0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0x178, 0x100, 0x102, 0x104, 0x106, 0x108, 0x10A, 0x10C, 0x10E, 0x110, 0x112, 0x114, 0x116, 0x118, 0x11A, 0x11C, 0x11E, 0x120, 0x122, 0x124, 0x126, 0x128, 0x12A, 0x12C, 0x12E, 0x130, 0x132, 0x134, 0x136, 0x139, 0x13B, 0x13D, 0x13F, 0x141, 0x143, 0x145, 0x147, 0x14A, 0x14C, 0x14E, 0x150, 0x152, 0x154, 0x156, 0x158, 0x15A, 0x15C, 0x15E, 0x160, 0x162, 0x164, 0x166, 0x168, 0x16A, 0x16C, 0x16E, 0x170, 0x172, 0x174, 0x176, 0x179, 0x17B, 0x17D, 0x191, 0x391, 0x392, 0x393, 0x394, 0x395, 0x396, 0x397, 0x398, 0x399, 0x39A, 0x39B, 0x39C, 0x39D, 0x39E, 0x39F, 0x3A0, 0x3A1, 0x3A3, 0x3A4, 0x3A5, 0x3A6, 0x3A7, 0x3A8, 0x3A9, 0x3AA, 0x410, 0x411, 0x412, 0x413, 0x414, 0x415, 0x416, 0x417, 0x418, 0x419, 0x41A, 0x41B, 0x41C, 0x41D, 0x41E, 0x41F, 0x420, 0x421, 0x422, 0x423, 0x424, 0x425, 0x426, 0x427, 0x428, 0x429, 0x42A, 0x42B, 0x42C, 0x42D, 0x42E, 0x42F, 0x401, 0x402, 0x403, 0x404, 0x405, 0x406, 0x407, 0x408, 0x409, 0x40A, 0x40B, 0x40C, 0x40E, 0x40F, 0x2160, 0x2161, 0x2162, 0x2163, 0x2164, 0x2165, 0x2166, 0x2167, 0x2168, 0x2169, 0x216A, 0x216B, 0x216C, 0x216D, 0x216E, 0x216F, 0xFF21, 0xFF22, 0xFF23, 0xFF24, 0xFF25, 0xFF26, 0xFF27, 0xFF28, 0xFF29, 0xFF2A, 0xFF2B, 0xFF2C, 0xFF2D, 0xFF2E, 0xFF2F, 0xFF30, 0xFF31, 0xFF32, 0xFF33, 0xFF34, 0xFF35, 0xFF36, 0xFF37, 0xFF38, 0xFF39, 0xFF3A, 0 };
int i;
for (i = 0; tbl_lower[i] && chr != tbl_lower[i]; i++) ;
return tbl_lower[i] ? tbl_upper[i] : chr;
}

View File

@ -0,0 +1,78 @@
#include "ff.h"
#include "sys.h"
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA>Լ512<31>ֽ<EFBFBD><D6BD><EFBFBD><EFBFBD>ҵ<EFBFBD><D2B5>ڴ<EFBFBD>.
//<2F><><EFBFBD>ڴ治<DAB4><E6B2BB><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>,<2C><><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9>ָ<EFBFBD>ʽ,<2C>Խ<EFBFBD>ʡ<EFBFBD><CAA1><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>
//<2F><><EFBFBD><EFBFBD><EFBFBD>ں<EFBFBD><DABA><EFBFBD><EFBFBD>ڲ<EFBFBD><DAB2><EFBFBD><EFBFBD><EFBFBD>,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><DAB2><EFBFBD><EFBFBD><EFBFBD>,<2C>뱣֤<EBB1A3><D6A4>ջ<EFBFBD><D5BB>С<EFBFBD><D0A1><EFBFBD><EFBFBD>512<31>ֽ<EFBFBD>.
//<2F><>.s<>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.
//<2F><><EFBFBD><EFBFBD>ע<EFBFBD><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:UNI2GBK<42><4B><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>GBK2UNI<4E><49><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Сһ<D0A1><D2BB>Ҫһ<D2AA><D2BB>!!!.
FIL UK_FILE;
u8 UK_FLAG=0; //<2F><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>UNIGBK.BIN
const u8 *UNIGBK_PATH="1:/SYSTEM/FONT/UNIGBK.BIN"; //UNIGBK <20><><EFBFBD><EFBFBD>·<EFBFBD><C2B7>
WCHAR ff_convert ( /* Converted code, 0 means conversion error */
WCHAR src, /* Character code to be converted */
UINT dir /* 0: Unicode to OEMCP, 1: OEMCP to Unicode */
)
{
WCHAR t[2];
WCHAR c;
u32 i, li, hi;
u16 n;
unsigned int cout;
u32 gbk2uni_offset=0;
if (src < 0x80)c = src;//ASCII,ֱ<>Ӳ<EFBFBD><D3B2><EFBFBD>ת<EFBFBD><D7AA>.
else
{
if(!UK_FLAG)//<2F><><EFBFBD><EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD>UNIGBK.BIN.
{
if(f_open(&UK_FILE,(const TCHAR*)UNIGBK_PATH,FA_READ)!=FR_OK)UK_FLAG=0;
else UK_FLAG=1;
}
if(dir) //GBK 2 UNICODE
{
gbk2uni_offset=UK_FILE.fsize/2;
}else //UNICODE 2 GBK
{
gbk2uni_offset=0;
}
if(UK_FLAG)//<2F><><EFBFBD><EFBFBD>
{
/* Unicode to OEMCP */
hi=UK_FILE.fsize/2;//<2F>԰뿪.
hi =hi / 4 - 1;
li = 0;
for (n = 16; n; n--)
{
i = li + (hi - li) / 2;
f_lseek(&UK_FILE,i*4+gbk2uni_offset);
f_read(&UK_FILE,&t,4,&cout);
if (src == t[0]) break;
if (src > t[0])li = i;
else hi = i;
}
c = n ? t[1] : 0;
}else c=0;
}
return c;
}
WCHAR ff_wtoupper ( /* Upper converted character */
WCHAR chr /* Input character */
)
{
static const WCHAR tbl_lower[] = { 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A, 0xA1, 0x00A2, 0x00A3, 0x00A5, 0x00AC, 0x00AF, 0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF, 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0x0FF, 0x101, 0x103, 0x105, 0x107, 0x109, 0x10B, 0x10D, 0x10F, 0x111, 0x113, 0x115, 0x117, 0x119, 0x11B, 0x11D, 0x11F, 0x121, 0x123, 0x125, 0x127, 0x129, 0x12B, 0x12D, 0x12F, 0x131, 0x133, 0x135, 0x137, 0x13A, 0x13C, 0x13E, 0x140, 0x142, 0x144, 0x146, 0x148, 0x14B, 0x14D, 0x14F, 0x151, 0x153, 0x155, 0x157, 0x159, 0x15B, 0x15D, 0x15F, 0x161, 0x163, 0x165, 0x167, 0x169, 0x16B, 0x16D, 0x16F, 0x171, 0x173, 0x175, 0x177, 0x17A, 0x17C, 0x17E, 0x192, 0x3B1, 0x3B2, 0x3B3, 0x3B4, 0x3B5, 0x3B6, 0x3B7, 0x3B8, 0x3B9, 0x3BA, 0x3BB, 0x3BC, 0x3BD, 0x3BE, 0x3BF, 0x3C0, 0x3C1, 0x3C3, 0x3C4, 0x3C5, 0x3C6, 0x3C7, 0x3C8, 0x3C9, 0x3CA, 0x430, 0x431, 0x432, 0x433, 0x434, 0x435, 0x436, 0x437, 0x438, 0x439, 0x43A, 0x43B, 0x43C, 0x43D, 0x43E, 0x43F, 0x440, 0x441, 0x442, 0x443, 0x444, 0x445, 0x446, 0x447, 0x448, 0x449, 0x44A, 0x44B, 0x44C, 0x44D, 0x44E, 0x44F, 0x451, 0x452, 0x453, 0x454, 0x455, 0x456, 0x457, 0x458, 0x459, 0x45A, 0x45B, 0x45C, 0x45E, 0x45F, 0x2170, 0x2171, 0x2172, 0x2173, 0x2174, 0x2175, 0x2176, 0x2177, 0x2178, 0x2179, 0x217A, 0x217B, 0x217C, 0x217D, 0x217E, 0x217F, 0xFF41, 0xFF42, 0xFF43, 0xFF44, 0xFF45, 0xFF46, 0xFF47, 0xFF48, 0xFF49, 0xFF4A, 0xFF4B, 0xFF4C, 0xFF4D, 0xFF4E, 0xFF4F, 0xFF50, 0xFF51, 0xFF52, 0xFF53, 0xFF54, 0xFF55, 0xFF56, 0xFF57, 0xFF58, 0xFF59, 0xFF5A, 0 };
static const WCHAR tbl_upper[] = { 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x21, 0xFFE0, 0xFFE1, 0xFFE5, 0xFFE2, 0xFFE3, 0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF, 0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0x178, 0x100, 0x102, 0x104, 0x106, 0x108, 0x10A, 0x10C, 0x10E, 0x110, 0x112, 0x114, 0x116, 0x118, 0x11A, 0x11C, 0x11E, 0x120, 0x122, 0x124, 0x126, 0x128, 0x12A, 0x12C, 0x12E, 0x130, 0x132, 0x134, 0x136, 0x139, 0x13B, 0x13D, 0x13F, 0x141, 0x143, 0x145, 0x147, 0x14A, 0x14C, 0x14E, 0x150, 0x152, 0x154, 0x156, 0x158, 0x15A, 0x15C, 0x15E, 0x160, 0x162, 0x164, 0x166, 0x168, 0x16A, 0x16C, 0x16E, 0x170, 0x172, 0x174, 0x176, 0x179, 0x17B, 0x17D, 0x191, 0x391, 0x392, 0x393, 0x394, 0x395, 0x396, 0x397, 0x398, 0x399, 0x39A, 0x39B, 0x39C, 0x39D, 0x39E, 0x39F, 0x3A0, 0x3A1, 0x3A3, 0x3A4, 0x3A5, 0x3A6, 0x3A7, 0x3A8, 0x3A9, 0x3AA, 0x410, 0x411, 0x412, 0x413, 0x414, 0x415, 0x416, 0x417, 0x418, 0x419, 0x41A, 0x41B, 0x41C, 0x41D, 0x41E, 0x41F, 0x420, 0x421, 0x422, 0x423, 0x424, 0x425, 0x426, 0x427, 0x428, 0x429, 0x42A, 0x42B, 0x42C, 0x42D, 0x42E, 0x42F, 0x401, 0x402, 0x403, 0x404, 0x405, 0x406, 0x407, 0x408, 0x409, 0x40A, 0x40B, 0x40C, 0x40E, 0x40F, 0x2160, 0x2161, 0x2162, 0x2163, 0x2164, 0x2165, 0x2166, 0x2167, 0x2168, 0x2169, 0x216A, 0x216B, 0x216C, 0x216D, 0x216E, 0x216F, 0xFF21, 0xFF22, 0xFF23, 0xFF24, 0xFF25, 0xFF26, 0xFF27, 0xFF28, 0xFF29, 0xFF2A, 0xFF2B, 0xFF2C, 0xFF2D, 0xFF2E, 0xFF2F, 0xFF30, 0xFF31, 0xFF32, 0xFF33, 0xFF34, 0xFF35, 0xFF36, 0xFF37, 0xFF38, 0xFF39, 0xFF3A, 0 };
int i;
for (i = 0; tbl_lower[i] && chr != tbl_lower[i]; i++) ;
return tbl_lower[i] ? tbl_upper[i] : chr;
}

View File

@ -0,0 +1,151 @@
/*------------------------------------------------------------------------*/
/* Sample code of OS dependent controls for FatFs R0.08b */
/* (C)ChaN, 2011 */
/*------------------------------------------------------------------------*/
#include <stdlib.h> /* ANSI memory controls */
#include <malloc.h> /* ANSI memory controls */
#include "../ff.h"
#if _FS_REENTRANT
/*------------------------------------------------------------------------*/
/* Create a Synchronization Object
/*------------------------------------------------------------------------*/
/* This function is called in f_mount function to create a new
/ synchronization object, such as semaphore and mutex. When a zero is
/ returned, the f_mount function fails with FR_INT_ERR.
*/
int ff_cre_syncobj ( /* TRUE:Function succeeded, FALSE:Could not create due to any error */
BYTE vol, /* Corresponding logical drive being processed */
_SYNC_t *sobj /* Pointer to return the created sync object */
)
{
int ret;
*sobj = CreateMutex(NULL, FALSE, NULL); /* Win32 */
ret = (*sobj != INVALID_HANDLE_VALUE);
// *sobj = SyncObjects[vol]; /* uITRON (give a static sync object) */
// ret = 1; /* The initial value of the semaphore must be 1. */
// *sobj = OSMutexCreate(0, &err); /* uC/OS-II */
// ret = (err == OS_NO_ERR);
// *sobj = xSemaphoreCreateMutex(); /* FreeRTOS */
// ret = (*sobj != NULL);
return ret;
}
/*------------------------------------------------------------------------*/
/* Delete a Synchronization Object */
/*------------------------------------------------------------------------*/
/* This function is called in f_mount function to delete a synchronization
/ object that created with ff_cre_syncobj function. When a zero is
/ returned, the f_mount function fails with FR_INT_ERR.
*/
int ff_del_syncobj ( /* TRUE:Function succeeded, FALSE:Could not delete due to any error */
_SYNC_t sobj /* Sync object tied to the logical drive to be deleted */
)
{
BOOL ret;
ret = CloseHandle(sobj); /* Win32 */
// ret = 1; /* uITRON (nothing to do) */
// OSMutexDel(sobj, OS_DEL_ALWAYS, &err); /* uC/OS-II */
// ret = (err == OS_NO_ERR);
// ret = 1; /* FreeRTOS (nothing to do) */
return ret;
}
/*------------------------------------------------------------------------*/
/* Request Grant to Access the Volume */
/*------------------------------------------------------------------------*/
/* This function is called on entering file functions to lock the volume.
/ When a zero is returned, the file function fails with FR_TIMEOUT.
*/
int ff_req_grant ( /* TRUE:Got a grant to access the volume, FALSE:Could not get a grant */
_SYNC_t sobj /* Sync object to wait */
)
{
int ret;
ret = (WaitForSingleObject(sobj, _FS_TIMEOUT) == WAIT_OBJECT_0); /* Win32 */
// ret = (wai_sem(sobj) == E_OK); /* uITRON */
// OSMutexPend(sobj, _FS_TIMEOUT, &err)); /* uC/OS-II */
// ret = (err == OS_NO_ERR);
// ret = (xSemaphoreTake(sobj, _FS_TIMEOUT) == pdTRUE); /* FreeRTOS */
return ret;
}
/*------------------------------------------------------------------------*/
/* Release Grant to Access the Volume */
/*------------------------------------------------------------------------*/
/* This function is called on leaving file functions to unlock the volume.
*/
void ff_rel_grant (
_SYNC_t sobj /* Sync object to be signaled */
)
{
ReleaseMutex(sobj); /* Win32 */
// sig_sem(sobj); /* uITRON */
// OSMutexPost(sobj); /* uC/OS-II */
// xSemaphoreGive(sobj); /* FreeRTOS */
}
#endif
#if _USE_LFN == 3 /* LFN with a working buffer on the heap */
/*------------------------------------------------------------------------*/
/* Allocate a memory block */
/*------------------------------------------------------------------------*/
/* If a NULL is returned, the file function fails with FR_NOT_ENOUGH_CORE.
*/
void* ff_memalloc ( /* Returns pointer to the allocated memory block */
UINT size /* Number of bytes to allocate */
)
{
return malloc(size);
}
/*------------------------------------------------------------------------*/
/* Free a memory block */
/*------------------------------------------------------------------------*/
void ff_memfree(
void* mblock /* Pointer to the memory block to free */
)
{
free(mblock);
}
#endif

353
IAPV1.1/Driver/L76X/L76X.c Normal file
View File

@ -0,0 +1,353 @@
#include "L76X.h"
#include "usart.h"
#include <math.h>
_SaveData Save_Data;
static const double pi = 3.14159265358979324;
static const double a = 6378245.0;
static const double ee = 0.00669342162296594323;
static const double x_pi = 3.14159265358979324 * 3000.0 / 180.0;
static double Lat_f,Lon_f;
void L76X_POWER_ON(void)
{
PWR_CTRLL76C_H;
}
void L76X_POWER_OFF(void)
{
PWR_CTRLL76C_L;
}
/******************************************************************************
function:
Latitude conversion
******************************************************************************/
static double transformLat(double x,double y)
{
double ret = -100.0 + 2.0 * x + 3.0 * y + 0.2 * y * y + 0.1 * x * y + 0.2 *sqrt(abs(x));
ret += (20.0 * sin(6.0 * x * pi) + 20.0 * sin(2.0 * x * pi)) * 2.0 / 3.0;
ret += (20.0 * sin(y * pi) + 40.0 * sin(y / 3.0 * pi)) * 2.0 / 3.0;
ret += (160.0 * sin(y / 12.0 * pi) + 320 * sin(y * pi / 30.0)) * 2.0 / 3.0;
return ret;
}
/******************************************************************************
function:
Longitude conversion
******************************************************************************/
static double transformLon(double x,double y)
{
double ret = 300.0 + x + 2.0 * y + 0.1 * x * x + 0.1 * x * y + 0.1 * sqrt(abs(x));
ret += (20.0 * sin(6.0 * x * pi) + 20.0 * sin(2.0 * x * pi)) * 2.0 / 3.0;
ret += (20.0 * sin(x * pi) + 40.0 * sin(x / 3.0 * pi)) * 2.0 / 3.0;
ret += (150.0 * sin(x / 12.0 * pi) + 300.0 * sin(x / 30.0 * pi)) * 2.0 / 3.0;
return ret;
}
/******************************************************************************
function:
GCJ-02 international standard converted to Baidu map BD-09 standard
******************************************************************************/
static Coordinates bd_encrypt(Coordinates gg)
{
Coordinates bd;
double x = gg.Lon, y = gg.Lat;
double z = sqrt(x * x + y * y) + 0.00002 * sin(y * x_pi);
double theta = atan2(y, x) + 0.000003 * cos(x * x_pi);
bd.Lon = z * cos(theta) + 0.0065;
bd.Lat = z * sin(theta) + 0.006;
return bd;
}
/******************************************************************************
function:
GPS's WGS-84 standard is converted into GCJ-02 international standard
******************************************************************************/
static Coordinates transform(Coordinates gps)
{
Coordinates gg;
double sqrtMagic;
double dLat = transformLat(gps.Lon - 105.0, gps.Lat - 35.0);
double dLon = transformLon(gps.Lon - 105.0, gps.Lat - 35.0);
double radLat = gps.Lat / 180.0 * pi;
double magic = sin(radLat);
magic = 1 - ee * magic * magic;
sqrtMagic = sqrt(magic);
dLat = (dLat * 180.0) / ((a * (1 - ee)) / (magic * sqrtMagic) * pi);
dLon = (dLon * 180.0) / (a / sqrtMagic * cos(radLat) * pi);
gg.Lat = gps.Lat + dLat;
gg.Lon = gps.Lon + dLon;
return gg;
}
/******************************************************************************
function:
Convert GPS latitude and longitude into GPS84 coordinates
******************************************************************************/
Coordinates L76X_GPS84_Coordinates()
{
Coordinates temp;
temp.Lat =((int)(Lat_f)) + (Lat_f - ((int)(Lat_f)))*100 / 60;
temp.Lon =((int)(Lon_f)) + (Lon_f - ((int)(Lon_f)))*100 / 60;
// temp = transform(temp);
return temp;
}
/******************************************************************************
function:
Convert GPS latitude and longitude into Google Maps coordinates
******************************************************************************/
Coordinates L76X_Google_Coordinates()
{
Coordinates temp;
temp.Lat =((int)(Lat_f)) + (Lat_f - ((int)(Lat_f)))*100 / 60;
temp.Lon =((int)(Lon_f)) + (Lon_f - ((int)(Lon_f)))*100 / 60;
temp = transform(temp);
return temp;
}
/******************************************************************************
function:
Convert GPS latitude and longitude into Baidu map coordinates
******************************************************************************/
Coordinates L76X_Baidu_Coordinates()
{
Coordinates temp;
temp.Lat =((int)(Lat_f)) + (Lat_f - ((int)(Lat_f)))*100 / 60;
temp.Lon =(int)(Lon_f) + (Lon_f - ((int)(Lon_f)))*100 / 60;
temp = transform(temp);
temp = bd_encrypt(temp);
return temp;
}
/******************************************************************************
function:
Send a command to the L76XAutomatic calculation of the code
parameter:
data The end of the command ends with \0 or it will go wrong,
no need to increase the validation code.
******************************************************************************/
void L76X_Send_Command(char *data)
{
// char Check = data[1], Check_char[3]={0};
// u8 i = 0;
// //printf(" 1i = %d Check =%x \n", i, Check);
// for(i=2; data[i] != '\0'; i++){
// Check ^= data[i]; //Calculate the check value
// }
//printf(" i = %d Check =%x \n", i, Check);
// Check_char[0] = Temp[Check/16%16];
// Check_char[1] = Temp[Check%16];
// Check_char[2] = '\0';
// DEV_Uart_SendString(data);
// DEV_Uart_SendByte('*');
// DEV_Uart_SendString(Check_char);
// DEV_Uart_SendByte('\r');
// DEV_Uart_SendByte('\n');
}
/**************清除GPS数据***********************/
void L76X_Sturct_Clear(void)
{
memset(Save_Data.GPS_Buffer,0,GPS_Buffer_Length-1) ;
Save_Data.isGetData=0;
Save_Data.isParseData=0;
memset(Save_Data.UTCTime,0,UTCTime_Length) ;
memset(Save_Data.latitude,0,latitude_Length) ;
memset(Save_Data.N_S,0,N_S_Length) ;
memset(Save_Data.longitude,0,longitude_Length) ;
memset(Save_Data.E_W,0,E_W_Length) ;
Save_Data.isUsefull=0;
}
void parseGpsBuffer(void)
{
char *subString;
char *subStringNext;
char i = 0;
char TempBuffer[10];
char temp_time;
if (Save_Data.isGetData)
{
Save_Data.isGetData = false;
for (i = 0 ; i <= 9 ; i++)
{
if (i == 0)
{
if ((subString = strstr(Save_Data.GPS_Buffer, ",")) == NULL)
;//解析错误
}
else
{
subString++;
if ((subStringNext = strstr(subString, ",")) != NULL)
{
char usefullBuffer[2];
char spdBuffer[10];
char cogBuffer[10];
switch(i)
{
case 1:memcpy(Save_Data.UTCTime, subString, subStringNext - subString);break; //获取UTC时间
case 2:memcpy(usefullBuffer, subString, subStringNext - subString);break; //获取UTC时间
case 3:memcpy(Save_Data.latitude, subString, subStringNext - subString);break; //获取纬度信息
case 4:memcpy(Save_Data.N_S, subString, subStringNext - subString);break; //获取N/S
case 5:memcpy(Save_Data.longitude, subString, subStringNext - subString);break; //获取经度信息
case 6:memcpy(Save_Data.E_W, subString, subStringNext - subString);break; //获取E/W
case 7:memcpy(spdBuffer, subString, subStringNext - subString);break; //获取E/W
case 8:memcpy(cogBuffer, subString, subStringNext - subString);break; //获取E/W
case 9:memcpy(Save_Data.UTCData, subString, subStringNext - subString);break; //获取E/W
default:break;
}
subString = subStringNext;
Save_Data.isParseData = true;
if((usefullBuffer[0] == 'A')&(Save_Data.UTCData[0]!=0))
{
Save_Data.isUsefull = true;
}
else if(usefullBuffer[0] == 'V')
Save_Data.isUsefull = false;
}
else
{
//解析错误
}
Lat_f=(Save_Data.latitude[0]-'0')*10000000.0+(Save_Data.latitude[1]-'0')*1000000.0+(Save_Data.latitude[2]-'0')*100000.0+(Save_Data.latitude[3]-'0')*10000.0+(Save_Data.latitude[5]-'0')*1000.0
+(Save_Data.latitude[6]-'0')*100.0+(Save_Data.latitude[7]-'0')*10.0+(Save_Data.latitude[8]-'0')*1.0;
Lon_f=(Save_Data.longitude[0]-'0')*100000000.0+(Save_Data.longitude[1]-'0')*10000000.0+(Save_Data.longitude[2]-'0')*1000000.0+(Save_Data.longitude[3]-'0')*100000.0+(Save_Data.longitude[4]-'0')*10000.0
+(Save_Data.longitude[6]-'0')*1000.0+(Save_Data.longitude[7]-'0')*100.0+(Save_Data.longitude[8]-'0')*10.0+(Save_Data.longitude[9]-'0')*1.0;
Lat_f=Lat_f/1000000.0;
Lon_f=Lon_f/1000000.0;
}
}
}
//转换日期
memset(TempBuffer,0,10);
TempBuffer[0] = Save_Data.UTCData[4];
TempBuffer[1] = Save_Data.UTCData[5];
TempBuffer[2] = '-';
TempBuffer[3] = Save_Data.UTCData[2];
TempBuffer[4] = Save_Data.UTCData[3];
TempBuffer[5] = '-';
TempBuffer[6] = Save_Data.UTCData[0];
TempBuffer[7] = Save_Data.UTCData[1];
memcpy(Save_Data.UTCData,TempBuffer,strlen(TempBuffer));
memset(TempBuffer,0,10);
//转换时间
temp_time=(Save_Data.UTCTime[0]-'0')*10+(Save_Data.UTCTime[1]-'0')+8;
Save_Data.UTCTime[0]=(char)((temp_time/10)+'0');
Save_Data.UTCTime[1]=(char)((temp_time%10)+'0');
TempBuffer[0] = Save_Data.UTCTime[0];
TempBuffer[1] = Save_Data.UTCTime[1];
TempBuffer[2] = ':';
TempBuffer[3] = Save_Data.UTCTime[2];
TempBuffer[4] = Save_Data.UTCTime[3];
TempBuffer[5] = ':';
TempBuffer[6] = Save_Data.UTCTime[4];
TempBuffer[7] = Save_Data.UTCTime[5];
memset(Save_Data.UTCTime,0,UTCTime_Length);
memcpy(Save_Data.UTCTime,TempBuffer,strlen(TempBuffer));
memset(TempBuffer,0,10);
}
void printGpsBuffer(void)
{
int i=0;
//输出UTC时间
if (Save_Data.isParseData)
{
i=0;
Save_Data.isParseData = false;
printf("Save_Data.UTCTime = ");
while(Save_Data.UTCTime[i] != 0)
{
printf("%c",Save_Data.UTCTime[i]);
i++;
}
printf("\r\n");
//如果定位可用,输出定位信息
if(Save_Data.isUsefull)
{
Save_Data.isUsefull = false;
i=0;
printf("Save_Data.latitude = ");
while(Save_Data.latitude[i] != 0)
{
printf("%c",Save_Data.latitude[i]);
i++;
}
printf("\r\n");
i=0;
printf("Save_Data.N_S = ");
printf("%c",Save_Data.N_S[0]);
printf("%c",Save_Data.N_S[1]);
printf("\r\n");
i=0;
printf("Save_Data.longitude = ");
while(Save_Data.longitude[i]!=0)
{
printf("%c",Save_Data.longitude[i]);
i++;
}
printf("\r\n");
printf("Save_Data.E_W = ");
printf("%c",Save_Data.E_W[0]);
printf("%c",Save_Data.E_W[1]);
printf("\r\n");
}
else
{
printf("GPS DATA is not usefull!\r\n");
}
}
}
void L76C_Process(void)
{
u8 times=0;
Coordinates GPS;
Save_Data.Flag_finish_gnss=0;
while(times<35)
{
//等待GPS信号
delay_ms(1000);
if(Save_Data.isGetData)
parseGpsBuffer();
times++;
if(Save_Data.isUsefull)
{
GPS=L76X_GPS84_Coordinates();
times=61;
}
else
{
GPS.Lat=0.0;
GPS.Lon=0.0;
}
// Set_GNSSTIME_Rtc();//RTC校准
}
//GPS=L76X_GPS84_Coordinates();
sprintf(data_common1.GPS_DATA,"%.7f%c%s%c%.7f%c%s%c",GPS.Lat,',',Save_Data.N_S,',', GPS.Lon,',',Save_Data.E_W,',');//经纬度
L76X_Sturct_Clear();
USART_DeInit(USART1);
Save_Data.Flag_finish_gnss=1;
}

View File

@ -0,0 +1,53 @@
#ifndef _L76X_H_
#define _L76X_H_
//#include "DEV_Config.h"
#include <math.h>
#include <stdlib.h>
#include "bsp.h"
#include <stdio.h>
#define BUFFSIZE 800
#define false 0
#define true 1
//定义数组长度
#define GPS_Buffer_Length 80
#define UTCTime_Length 11
#define latitude_Length 11
#define N_S_Length 2
#define longitude_Length 12
#define E_W_Length 2
#define UTCData_Length 11
typedef struct SaveData
{
char GPS_Buffer[GPS_Buffer_Length];
char GGA_Buffer[GPS_Buffer_Length];
char isGetData; //是否获取到GPS数据
char isParseData; //是否解析完成
char UTCTime[UTCTime_Length]; //UTC时间
char latitude[latitude_Length]; //纬度
char N_S[N_S_Length]; //N/S
char longitude[longitude_Length]; //经度
char E_W[E_W_Length]; //E/W
char isUsefull; //定位信息是否有效
char UTCData[UTCData_Length];
char Flag_finish_gnss;
} _SaveData;
typedef struct {
double Lon;
double Lat;
}Coordinates;
extern _SaveData Save_Data;
extern double Lat_f,Lon_f;
void parseGpsBuffer(void);
void printGpsBuffer(void);
void L76X_Sturct_Clear(void);
Coordinates L76X_Baidu_Coordinates(void);
Coordinates L76X_Google_Coordinates(void);
Coordinates L76X_GPS84_Coordinates(void);
void L76X_POWER_ON(void);
void L76X_POWER_OFF(void);
void L76C_Process(void);
#endif

489
IAPV1.1/Driver/RTC/rtc.c Normal file
View File

@ -0,0 +1,489 @@
#include "rtc.h"
//ƽ<><C6BD><EFBFBD><EFBFBD><EFBFBD>·<EFBFBD><C2B7><EFBFBD><EFBFBD>ڱ<EFBFBD> <20><><EFBFBD><EFBFBD>2<EFBFBD>·<EFBFBD>29<32><39>
const u8 mon_table[12]={31,28,31,30,31,30,31,31,30,31,30,31};
MYITStatus_Struct MYITStatus1;
// u8 time[3]={0};
void NVIC_EXTI_CONFIG(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
EXTI_InitTypeDef EXTI_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOC, ENABLE);
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IN;
GPIO_InitStructure.GPIO_OType=GPIO_OType_PP;
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_13;
GPIO_InitStructure.GPIO_PuPd=GPIO_PuPd_DOWN;
GPIO_Init(GPIOC,&GPIO_InitStructure);
//enable syscfg clock
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
// connect EXTI10 line to PA0 pin
SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOC, EXTI_PinSource13);
EXTI_ClearITPendingBit(EXTI_Line13);
EXTI_InitStructure.EXTI_Line=EXTI_Line13;//RTC wakeup
EXTI_InitStructure.EXTI_LineCmd=ENABLE;
EXTI_InitStructure.EXTI_Mode=EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger=EXTI_Trigger_Rising;
EXTI_Init(&EXTI_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel=EXTI15_10_IRQn;
NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=0x00;
NVIC_InitStructure.NVIC_IRQChannelSubPriority=0x00;
NVIC_Init(&NVIC_InitStructure);
}
void RTC_NVIC_CONFIG(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
EXTI_InitTypeDef EXTI_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOC, ENABLE);
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IN;
GPIO_InitStructure.GPIO_OType=GPIO_OType_PP;
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_13;
GPIO_InitStructure.GPIO_PuPd=GPIO_PuPd_DOWN;
GPIO_Init(GPIOC,&GPIO_InitStructure);
GPIO_PinAFConfig(GPIOC,GPIO_PinSource13,GPIO_AF_WKUP);
EXTI_ClearITPendingBit(EXTI_Line20);
EXTI_InitStructure.EXTI_Line=EXTI_Line20;//RTC wakeup
EXTI_InitStructure.EXTI_LineCmd=ENABLE;
EXTI_InitStructure.EXTI_Mode=EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger=EXTI_Trigger_Rising;
EXTI_Init(&EXTI_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel=RTC_WKUP_IRQn;
NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=0x00;
NVIC_InitStructure.NVIC_IRQChannelSubPriority=0x00;
NVIC_Init(&NVIC_InitStructure);
/* EXTI configuration */
EXTI_ClearITPendingBit(EXTI_Line17);
EXTI_InitStructure.EXTI_Line = EXTI_Line17;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
/* Enable the RTC Alarm Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = RTC_Alarm_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
void RTC_Time_Init(void)
{
RTC_InitTypeDef RTC_InitStructure;
//RTC_TimeTypeDef RTC_TimeStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
/*!< Allow access to RTC */
PWR_RTCAccessCmd(ENABLE);
/*!< ʹ<><CAB9><EFBFBD>ⲿ<EFBFBD><E2B2BF><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1> */
RCC_LSEConfig(RCC_LSE_ON);
// RCC_LSICmd(ENABLE);
/*!< <20>ȴ<EFBFBD><C8B4>ⲿ<EFBFBD><E2B2BF><EFBFBD><EFBFBD>ʱ<EFBFBD>Ӿ<EFBFBD><D3BE><EFBFBD> */
while (RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET);
RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);//ѡ<><D1A1><EFBFBD>ⲿLES<45><53>ΪRTCʱ<43><CAB1>Դ
RCC_RTCCLKCmd(ENABLE);
/*!< Wait for RTC APB registers synchronisation */
RTC_WaitForSynchro();
RTC_InitStructure.RTC_AsynchPrediv=127;
RTC_InitStructure.RTC_HourFormat=RTC_HourFormat_24;
RTC_InitStructure.RTC_SynchPrediv=255;
RTC_Init(&RTC_InitStructure);//RTC<54><43>ʱ<EFBFBD><CAB1>1HZ
RTC_NVIC_CONFIG();
}
void rtc_std_init(void)
{
/* Enable the PWR clock */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
/* Allow access to RTC */
PWR_RTCAccessCmd(ENABLE);
/* Wait for RTC APB registers synchronisation */
RTC_WaitForSynchro();
}
//<2F><><EFBFBD>ñ<EFBFBD><C3B1><EFBFBD>Ӳ<EFBFBD><D3B2>RTCʱ<43><CAB1>
void SetRTC(int set_year,int set_mon,int set_day,int set_hour,int set_min ,int set_sec)
{
RTC_TimeTypeDef RTC_TimeStruct;
RTC_DateTypeDef RTC_DateStruct;
RTC_TimeStruct.RTC_Hours = set_hour;
RTC_TimeStruct.RTC_Minutes = set_min;
RTC_TimeStruct.RTC_Seconds = set_sec;
RTC_TimeStruct.RTC_H12 = 0; //<2F><><EFBFBD><EFBFBD><EFBFBD>в<EFBFBD>ʹ<EFBFBD><CAB9><EFBFBD><EFBFBD><EFBFBD><EFBFBD>/<2F><><EFBFBD><EFBFBD>
RTC_SetTime(RTC_Format_BIN,&RTC_TimeStruct);
RTC_DateStruct.RTC_Year = set_year;
RTC_DateStruct.RTC_Month = set_mon;
RTC_DateStruct.RTC_Date = set_day;
RTC_DateStruct.RTC_WeekDay = 1;//<2F><><EFBFBD><EFBFBD><EFBFBD>в<EFBFBD>ʹ<EFBFBD><CAB9><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
RTC_SetDate(RTC_Format_BIN,&RTC_DateStruct);
// RTC_WaitForSynchro();
RTC_WriteBackupRegister(RTC_BKP_DR0, 0x32F2);
}
void Set_GNSSTIME_Rtc(void)
{
int set_years, set_mons, set_days, set_hours, set_mins , set_secs;
if(Save_Data.isUsefull)//<2F><>λ<EFBFBD><CEBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ч
{
set_years=(Save_Data.UTCData[0]-'0')*10+(Save_Data.UTCData[1]-'0');//<2F><>
set_mons=(Save_Data.UTCData[2]-'0')*10+(Save_Data.UTCData[3]-'0');//<2F><>
set_days=(Save_Data.UTCData[4]-'0')*10+(Save_Data.UTCData[5]-'0');//<2F><>
set_hours=(Save_Data.UTCTime[0]-'0')*10+(Save_Data.UTCTime[1]-'0')+8;//ʱ
set_mins=(Save_Data.UTCTime[2]-'0')*10+(Save_Data.UTCTime[3]-'0');//<2F><>
set_secs=(Save_Data.UTCTime[4]-'0')*10+(Save_Data.UTCTime[5]-'0');//<2F><>
SetRTC(set_years,set_mons,set_days,set_hours,set_mins,set_secs);
}
}
//<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>Ӳ<EFBFBD><D3B2>RTCʱ<43><CAB1>
void GetRTC(char *hhmmss,char *yymmdd)
{
RTC_TimeTypeDef time;
RTC_DateTypeDef date;
RTC_GetTime(RTC_Format_BIN,&time);
RTC_GetDate(RTC_Format_BIN,&date);
yymmdd[0]=date.RTC_Year/10+0x30; //<2F><>ʮλ
yymmdd[1]=date.RTC_Year%10+0x30; //<2F><><EFBFBD><EFBFBD>λ
yymmdd[2]=date.RTC_Month/10+0x30; //<2F><>ʮλ
yymmdd[3]=date.RTC_Month%10+0x30; //<2F><>ʮλ
yymmdd[4]=date.RTC_Date/10+0x30; //<2F><>ʮλ
yymmdd[5]=date.RTC_Date%10+0x30; //<2F><>ʮλ
hhmmss[0]=time.RTC_Hours/10+0x30; //Сʱʮλ
hhmmss[1]=time.RTC_Hours%10+0x30; //Сʱ<D0A1><CAB1>λ
hhmmss[2]=time.RTC_Minutes/10+0x30; //<2F><><EFBFBD><EFBFBD>ʮλ
hhmmss[3]=time.RTC_Minutes%10+0x30; //<2F><><EFBFBD><EFBFBD>ʮλ
hhmmss[4]=time.RTC_Seconds/10+0x30; //<2F><>ʮλ
hhmmss[5]=time.RTC_Seconds%10+0x30; //<2F><>ʮλ
}
u32 RTC_GetSeconds(void)
{
u32 secondss;
RTC_TimeTypeDef time;
RTC_GetTime(RTC_Format_BIN,&time);
secondss= time.RTC_Hours*3600 + time.RTC_Minutes*60 + time.RTC_Seconds;
return secondss;
}
void RtcWakeUpConfig(u32 temp)
{
RTC_NVIC_CONFIG();
RTC_WakeUpCmd(DISABLE);
RTC_ClearFlag(RTC_FLAG_WUTF);
if(temp>65535)RTC_WakeUpClockConfig(RTC_WakeUpClock_CK_SPRE_17bits);
else RTC_WakeUpClockConfig(RTC_WakeUpClock_CK_SPRE_16bits);
RTC_SetWakeUpCounter(temp); //<2F><><EFBFBD>û<EFBFBD><C3BB><EFBFBD>ʱ<EFBFBD><CAB1>--S,<2C><><EFBFBD><EFBFBD>65536s=18Сʱ 2^17=131072 131072/3600s=36.4h
RTC_ClearITPendingBit(RTC_IT_WUT);
RTC_ITConfig(RTC_IT_WUT,ENABLE); //<2F><>Ҫʹ<D2AA><CAB9><EFBFBD>жϣ<D0B6><CFA3><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD>жϺ<D0B6><CFBA><EFBFBD>
RTC_WakeUpCmd(ENABLE);
}
//<2F>ж<EFBFBD><D0B6>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EABAAF>
//<2F>·<EFBFBD> 1 2 3 4 5 6 7 8 9 10 11 12
//<2F><><EFBFBD><EFBFBD> 31 29 31 30 31 30 31 31 30 31 30 31
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 31 28 31 30 31 30 31 31 30 31 30 31
//<2F><><EFBFBD><EFBFBD>:<3A><><EFBFBD><EFBFBD>
//<2F><><EFBFBD><EFBFBD>:<3A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Dz<EFBFBD><C7B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.1,<2C><>.0,<2C><><EFBFBD><EFBFBD>
u8 Is_Leap_Year(u16 year)
{
year=year+2000;
// year=0x14ff&year;
if(year%4==0) //<2F><><EFBFBD><EFBFBD><EFBFBD>ܱ<EFBFBD>4<EFBFBD><34><EFBFBD><EFBFBD>
{
if(year%100==0)
{
if(year%400==0)return 1;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>00<30><30>β,<2C><>Ҫ<EFBFBD>ܱ<EFBFBD>400<30><30><EFBFBD><EFBFBD>
else return 0;
}else return 1;
}else return 0;
}
void MYRTC_Init(void)
{
RTC_NVIC_CONFIG();
RTC_Time_Init();
PWR_ClearFlag(PWR_FLAG_WU);//<2F><><EFBFBD><EFBFBD>֮<EFBFBD><D6AE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
}
void RTC_AlarmAConfig(u32 seconds)
{
int month_day;
RTC_TimeTypeDef nowtimes;
RTC_DateTypeDef nowdatas;
RTC_AlarmTypeDef RTC_AlarmStructure;
RTC_ClearFlag(RTC_FLAG_ALRAF);
RTC_ClearITPendingBit(RTC_IT_ALRA);
RTC_AlarmCmd(RTC_Alarm_A, DISABLE);
RTC_GetTime(RTC_Format_BIN,&nowtimes);//<2F><>ȡʱ<C8A1><CAB1>
RTC_GetDate(RTC_Format_BIN,&nowdatas);//<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>
month_day=mon_table[nowdatas.RTC_Month-1];//<2F><>ȡ<EFBFBD>µ<EFBFBD><C2B5><EFBFBD><EFBFBD><EFBFBD>
if(nowdatas.RTC_Month==2)
{
if(!Is_Leap_Year(nowdatas.RTC_Year))//<2F><><EFBFBD><EFBFBD>
month_day+=1; //<2F><><EFBFBD>·<EFBFBD><C2B7><EFBFBD><EFBFBD><EFBFBD>-1
}
seconds+=nowtimes.RTC_Hours*3600+nowtimes.RTC_Minutes*60+nowtimes.RTC_Seconds+nowdatas.RTC_Date*86400;
if((seconds/86400)>month_day)//<2F>ж<EFBFBD><D0B6>Ƿ񳬹<C7B7><F1B3ACB9><EFBFBD><EFBFBD>·ݵ<C2B7><DDB5><EFBFBD><EFBFBD><EFBFBD>
{
month_day=(seconds/86400)-month_day;
RTC_AlarmStructure.RTC_AlarmDateWeekDay = month_day;
}else
RTC_AlarmStructure.RTC_AlarmDateWeekDay = seconds/86400; //<2F><>
/* Set the alarmA Masks */
RTC_AlarmStructure.RTC_AlarmDateWeekDaySel = RTC_AlarmDateWeekDaySel_Date;
RTC_AlarmStructure.RTC_AlarmMask = RTC_AlarmMask_None; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
/* Set the alarmA time */
RTC_AlarmStructure.RTC_AlarmTime.RTC_H12=RTC_H12_AM; //24H
RTC_AlarmStructure.RTC_AlarmTime.RTC_Hours=(seconds%86400)/3600;//ʱ
RTC_AlarmStructure.RTC_AlarmTime.RTC_Minutes=(seconds%86400)%3600/60;//<2F><>
RTC_AlarmStructure.RTC_AlarmTime.RTC_Seconds=(seconds%86400)%3600%60;//<2F><>
RTC_SetAlarm(RTC_Format_BIN, RTC_Alarm_A, &RTC_AlarmStructure);
/* Enable AlarmA interrupt */
RTC_ITConfig(RTC_IT_ALRA, ENABLE);
/* Enable the alarmA */
RTC_AlarmCmd(RTC_Alarm_A, ENABLE);
}
//<2F><><EFBFBD><EFBFBD>B<EFBFBD><42><EFBFBD><EFBFBD>
void RTC_AlarmBConfig(int set_year,int set_mon,int set_day,int set_hour,int set_min ,int set_sec)
{
RTC_AlarmTypeDef RTC_AlarmStructure;
RTC_ClearFlag(RTC_FLAG_ALRBF);
RTC_ClearITPendingBit(RTC_IT_ALRB);
RTC_AlarmCmd(RTC_Alarm_B, DISABLE);
/* Set the alarmB Masks */
RTC_AlarmStructure.RTC_AlarmDateWeekDay = set_day;//<2F><>1-31
RTC_AlarmStructure.RTC_AlarmDateWeekDaySel = RTC_AlarmDateWeekDaySel_Date; //ѡ<><D1A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
RTC_AlarmStructure.RTC_AlarmMask = RTC_AlarmMask_None; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
/* Set the alarmB time */
RTC_AlarmStructure.RTC_AlarmTime.RTC_H12=RTC_H12_AM; //24H
RTC_AlarmStructure.RTC_AlarmTime.RTC_Hours=set_hour;
RTC_AlarmStructure.RTC_AlarmTime.RTC_Minutes=set_min;
RTC_AlarmStructure.RTC_AlarmTime.RTC_Seconds=set_sec;
RTC_SetAlarm(RTC_Format_BIN, RTC_Alarm_B, &RTC_AlarmStructure);
/* Set AlarmA subseconds and enable SubSec Alarm : generate 8 interripts per Second */
// RTC_AlarmSubSecondConfig(RTC_Alarm_A, 0xFF, RTC_AlarmSubSecondMask_SS14_5);
/* Enable AlarmA interrupt */
RTC_ITConfig(RTC_IT_ALRB, ENABLE);
/* Enable the alarmA */
RTC_AlarmCmd(RTC_Alarm_B, ENABLE);
}
/*************<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E8B1B8><EFBFBD><EFBFBD>Դ******************/
STB_ITStatus Get_Wkup_MYITstatus(void)
{
if(RTC_GetITStatus(RTC_IT_ALRA))
{
EXTI_ClearITPendingBit(EXTI_Line17);
RTC_ClearITPendingBit(RTC_IT_ALRA);
MYITStatus1.AlarmA_ITStatus=1;
// return AlarmA_ITHP;
}
if(RTC_GetITStatus(RTC_IT_ALRB))
{
EXTI_ClearITPendingBit(EXTI_Line17);
RTC_ClearITPendingBit(RTC_IT_ALRB);
MYITStatus1.AlarmB_ITStatus=1;
//return AlarmB_ITHP;
}
if(RTC_GetITStatus(RTC_IT_WUT))
{
EXTI_ClearITPendingBit(EXTI_Line20);
RTC_ClearITPendingBit(RTC_IT_WUT);
MYITStatus1.WUT_ITStatus=1;
//return WUT_ITHP;
}
if(GPIO_ReadInputDataBit(GPIOC,GPIO_Pin_13))
{
delay_ms(2000);
if(GPIO_ReadInputDataBit(GPIOC,GPIO_Pin_13))
{
EXTI_ClearITPendingBit(EXTI_Line20);
MYITStatus1.WKUP1_ITStatus=1;
// return WKUP1_ITHP;
}
}
if(MYITStatus1.AlarmA_ITStatus | MYITStatus1.AlarmB_ITStatus | MYITStatus1.WUT_ITStatus | MYITStatus1.WKUP1_ITStatus)
{
if(MYITStatus1.AlarmA_ITStatus)return AlarmA_ITHP;
if(MYITStatus1.AlarmB_ITStatus)return AlarmA_ITHP;
if(MYITStatus1.WUT_ITStatus)return AlarmA_ITHP;
if(MYITStatus1.WKUP1_ITStatus)return AlarmA_ITHP;
}
else
{
MYITStatus1.WKUP_POWBUTTON=1;//<2F><>Դ<EFBFBD>ϵ<EFBFBD>
return Power_ON;
}
return Power_ON;
}
/**
* @brief This function handles RTC Alarm interrupt (A and B) request.
* @param None
* @retval None
*/
void RTC_Alarm_IRQHandler(void)
{
/* Check on the AlarmA falg and on the number of interrupts per Second (60*8) */
if(RTC_GetITStatus(RTC_IT_ALRA) != RESET)
{
/* Clear RTC AlarmA Flags */
RTC_ClearITPendingBit(RTC_IT_ALRA);
MYITStatus1.AlarmA_ITStatus=1;
RTC_AlarmCmd(RTC_Alarm_A, DISABLE);
u5_printf("alarmA hp\r\n");
}
/* Check on the AlarmA falg and on the number of interrupts per Second (60*8) */
if(RTC_GetITStatus(RTC_IT_ALRB) != RESET)
{
/* Clear RTC AlarmB Flags */
RTC_ClearITPendingBit(RTC_IT_ALRB);
RTC_AlarmCmd(RTC_IT_ALRB, DISABLE);
MYITStatus1.AlarmB_ITStatus=1;
}
/* Clear the EXTIL line 17 */
EXTI_ClearITPendingBit(EXTI_Line17);
}
void RTC_WKUP_IRQHandler(void)
{
if(RTC_GetITStatus(RTC_IT_WUT) != RESET)
{
RTC_ClearITPendingBit(RTC_IT_WUT);
RTC_WakeUpCmd(DISABLE);
EXTI_ClearITPendingBit(EXTI_Line20);
MYITStatus1.WUT_ITStatus=1;
u5_printf("WUT hp\r\n");
u5_printf("wut_PROS1_RUN:%d\r\n",TASKRUNSS.PROS1_RUN);
}
}
void EXTI15_10_IRQHandler(void)
{
if(EXTI_GetITStatus(EXTI_Line13) != RESET)
{
EXTI_ClearITPendingBit(EXTI_Line13);
MYITStatus1.WKUP1_ITStatus=1;
u5_printf("WAKEUP2 is HP");
}
}
u8 Check_WKUP(void)
{
// u8 t=0; //<2F><>¼<EFBFBD><C2BC><EFBFBD>µ<EFBFBD>ʱ<EFBFBD><CAB1>
// while(WKUP_KD)
// {
// t++; //<2F>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// delay_ms(100);
// if(t>=100) //<2F><><EFBFBD>³<EFBFBD><C2B3><EFBFBD>10<31><30><EFBFBD><EFBFBD>
// {
// return 1; //<2F><><EFBFBD><EFBFBD>10s<30><73><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// }
// }
// if(t>10)return 2; //<2F><><EFBFBD><EFBFBD>3s<33><73><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// else return 0;
if(WKUP_KD)return 1;
return 0;
}
/**
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̰<EFBFBD><CCB0>ͳ<EFBFBD><CDB3><EFBFBD><EFBFBD>¼<EFBFBD>
* <20>̰<EFBFBD><CCB0><EFBFBD>ʱ<EFBFBD><CAB1> 10ms < T < 1 s, <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1> T >1 s
* <20><><EFBFBD>ܣ<EFBFBD>ʹ<EFBFBD><CAB9>״̬<D7B4><CCAC><EFBFBD><EFBFBD>ʽ<EFBFBD><CABD>ɨ<EFBFBD><EFBFBD><E8B5A5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɨ<EFBFBD><C9A8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ10ms,10ms<6D>պ<EFBFBD><D5BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* ״̬<D7B4><CCAC>ʹ<EFBFBD><CAB9>switch case<73><65><EFBFBD><EFBFBD>ʵ<EFBFBD><CAB5>״̬֮<CCAC><D6AE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ת
* lock<63><6B><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD><D0B6>Ƿ<EFBFBD><C7B7>ǵ<EFBFBD>һ<EFBFBD>ν<EFBFBD><CEBD>а<EFBFBD><D0B0><EFBFBD>ȷ<EFBFBD><C8B7>״̬
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><C2BC><EFBFBD>ǰִ<C7B0>У<EFBFBD><D0A3>̰<EFBFBD><CCB0><EFBFBD><EFBFBD>¼<EFBFBD><C2BC>ͷź<CDB7><C5BA><EFBFBD>ִ<EFBFBD><D6B4>
*/
u8 Key_Scan(void)
{
static KEY_STATE KeyState =KEY_CHECK;
static u8 TimeCnt = 0;
u8 key_return = 0;
switch (KeyState)
{
//<2F><><EFBFBD><EFBFBD>δ<EFBFBD><CEB4><EFBFBD><EFBFBD>״̬<D7B4><CCAC><EFBFBD><EFBFBD>ʱ<EFBFBD>ж<EFBFBD>WKUP_KD<4B><44>ֵ
case KEY_CHECK:
if(WKUP_KD)
{
KeyState = KEY_COMFIRM; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>WKUP_KDֵΪ1<CEAA><31>˵<EFBFBD><CBB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD>£<EFBFBD><C2A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>״̬
}
else
{
KeyState = KEY_CHECK;
}
TimeCnt = 0; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ
key_return=0;
break;
case KEY_COMFIRM:
if(WKUP_KD) //<2F><EFBFBD><E9BFB4>ǰWKUP_KD<4B>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>1<EFBFBD><31><EFBFBD>ٴ<EFBFBD>ȷ<EFBFBD><C8B7><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>
{
TimeCnt++;
if(TimeCnt>=200)TimeCnt=200;
}
else
{
KeyState = KEY_RELEASE; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>״̬
}
break;
case KEY_RELEASE:
if(!WKUP_KD) //<2F><>ǰWKUP_KDֵΪ0<CEAA><30>˵<EFBFBD><CBB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD><D1BE>ͷţ<CDB7><C5A3><EFBFBD><EFBFBD>ؿ<EFBFBD>ʼ״̬
{
KeyState = KEY_CHECK;
if(TimeCnt>10 ) key_return = KEY_SHORT;
if(TimeCnt>100) key_return = KEY_LONG;
u5_printf("TimeCnt:%d\r\n",TimeCnt);
}
break;
default: break;
}
return key_return;
}

72
IAPV1.1/Driver/RTC/rtc.h Normal file
View File

@ -0,0 +1,72 @@
#ifndef __RTC_H
#define __RTC_H
#include "sys.h"
#include "general_type.h"
#include "stm32l1xx.h"
#include "stm32l1xx_gpio.h"
#include "stm32l1xx_rcc.h"
#include "stm32l1xx_exti.h"
#include "stm32l1xx_rtc.h"
#include "stm32l1xx_pwr.h"
#include "bsp.h"
//#define WKUP_KD PCin(13) //PC13 <20><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7>ⲿWK_UP<55><50><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
#define WKUP_KD GPIO_ReadInputDataBit(GPIOC,GPIO_Pin_13)
void RTC_NVIC_CONFIG(void);
void RTC_Time_Init(void);
void Sleep_Mode(void);
void RtcWakeUpConfig(u32 temp);
void MYRTC_Init(void);
u8 Check_WKUP(void);
void SetRTC(int set_year,int set_mon,int set_day,int set_hour,int set_min ,int set_sec) ;
void Set_GNSSTIME_Rtc(void);
void GetRTC(char *hhmmss,char *yymmdd);
u32 RTC_GetSeconds(void);
void RTC_AlarmAConfig(u32 seconds);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
void NVIC_EXTI_CONFIG(void);
void RTC_AlarmBConfig(int set_year,int set_mon,int set_day,int set_hour,int set_min ,int set_sec);
u8 Is_Leap_Year(u16 year);
u8 Key_Scan(void);
void rtc_std_init(void);
typedef struct MYITStatu
{
unsigned char AlarmA_ITStatus :1;
unsigned char AlarmB_ITStatus :1;
unsigned char WUT_ITStatus :1;
unsigned char WKUP1_ITStatus :1;
unsigned char WKUP_POWBUTTON :1;
unsigned char WKUP_MEA_WIFI :1;
}MYITStatus_Struct; //<2F><><EFBFBD><EFBFBD><EFBFBD>жϵĽṹ<C4BD><E1B9B9>
typedef enum
{
AlarmA_ITHP=1,
AlarmB_ITHP=2,
WUT_ITHP=3,
WKUP1_ITHP=4,
Power_ON=0,
}STB_ITStatus;
typedef enum
{
KEY_CHECK = 0,
KEY_COMFIRM = 1,
KEY_RELEASE = 2,
KEY_SHORT=3,
KEY_LONG=4,
}KEY_STATE; //<2F><><EFBFBD><EFBFBD>״̬
typedef enum
{
NULL_KEY = 0,
SHORT_KEY =1,
LONG_KEY =2,
}KEY_TYPE;//<2F><><EFBFBD><EFBFBD>ֵ
extern MYITStatus_Struct MYITStatus1;//<2F>жϵ<D0B6>״̬<D7B4><CCAC>ʾ
STB_ITStatus Get_Wkup_MYITstatus(void);
#endif

View File

@ -0,0 +1,105 @@
#include "flash.h"
uint8_t Write_Buff[STM32L_PAGES_SIZE];
//读取FLASHYIGE 字节的数据
uint8_t FLASH_ReadByte(uint32_t Addr)
{
return *(__IO uint8_t*)Addr;
}
//读取FLASH多个字节的数据
void FLASH_ReadNByte(uint32_t Addr,uint8_t *pBuff,uint32_t Len)
{
uint32_t i;
for(i = 0;i < Len;i++)
{
pBuff[i] = FLASH_ReadByte(Addr);
Addr ++;
}
}
/*************************************
函数名称:
函数功能向FLASH指地址写
入数据
函数参数:页号,写入缓冲区
函数返回值:
**************************************/
void FLASH_WriteWord(uint32_t add,uint8_t *pBuff,uint32_t length)
{
unsigned short int i;
if(add < STM32L_FLASH_BASE)
return;
FLASH_Unlock();
FLASH_ClearFlag(FLASH_FLAG_EOP|FLASH_FLAG_WRPERR|FLASH_FLAG_PGAERR\
|FLASH_FLAG_SIZERR|FLASH_FLAG_OPTVERR|FLASH_FLAG_OPTVERRUSR);
//FLASH_ErasePage(Addr);
/*******************************************/
for(i = 0;i < length;i+=4)
{
FLASH_FastProgramWord(add+i,*(uint32_t *)pBuff);
//add += 4;
pBuff += 4;
}
/*******************************************/
FLASH_Lock();
}
/*************************************
函数名称:
函数功能向FLASH指定页写
入数据
函数参数:页号,写入缓冲区
函数返回值:
**************************************/
void FLASH_WritePage(uint16_t Page_Num,uint8_t *pBuff)
{
uint32_t Addr;
unsigned short int i;
if(Page_Num > STM32L_PAGES_NUM)
return;
Addr = Page_Num * STM32L_PAGES_SIZE + APP_ADDR;
FLASH_Unlock();
FLASH_ClearFlag(FLASH_FLAG_EOP|FLASH_FLAG_WRPERR|FLASH_FLAG_PGAERR\
|FLASH_FLAG_SIZERR|FLASH_FLAG_OPTVERR|FLASH_FLAG_OPTVERRUSR);
FLASH_ErasePage(Addr);
/*******************************************/
for(i = 0;i < STM32L_PAGES_SIZE;i+=4)
{
FLASH_FastProgramWord(Addr,*(unsigned long int *)pBuff);
Addr += 4;
pBuff += 4;
}
/*******************************************/
FLASH_Lock();
}
void Flash_Erase_Pages(uint32_t pagestart,uint16_t number)
{
uint32_t Addr;
if(pagestart > STM32L_PAGES_NUM)
return;
//Addr = pagestart * STM32L_PAGES_SIZE + APP_ADDR;
FLASH_Unlock();
FLASH_ClearFlag(FLASH_FLAG_EOP|FLASH_FLAG_WRPERR|FLASH_FLAG_PGAERR\
|FLASH_FLAG_SIZERR|FLASH_FLAG_OPTVERR|FLASH_FLAG_OPTVERRUSR);
for( uint16_t i=0;i<number;i++)
{
//Addr = (pagestart+i) * STM32L_PAGES_SIZE + APP_ADDR;
Addr = (pagestart+i) * STM32L_PAGES_SIZE + STM32L_FLASH_BASE;
FLASH_ErasePage(Addr);
}
FLASH_Lock();
}

View File

@ -0,0 +1,23 @@
#include "bsp.h"
/******************************
flash<73>ռ<EFBFBD><D5BC><EFBFBD><EFBFBD><EFBFBD>
0X08000000-0X0800FFFF BootLoader 64K
0X08010000-0X0802FFFF App1 128K
0X08030000-0X0804FFFF App2 128K
*/
#define APP_ADDR 0X08010000
#define APP2_ADDR 0X08030000
#define STM32L_PAGES_SIZE 256
#define STM32L_PAGES_NUM 1536
#define STM32L_FLASH_BASE 0X08000000
uint8_t FLASH_ReadByte(uint32_t Addr);
void FLASH_ReadNByte(uint32_t Addr,uint8_t *pBuff,uint32_t Len);
void FLASH_WritePage(uint16_t Page_Num,uint8_t *pBuff);
void FLASH_WriteWord(uint32_t add,uint8_t *pBuff,uint32_t length);
void Flash_Erase_Pages(uint32_t pagestart,uint16_t number);

View File

@ -0,0 +1,142 @@
#include "stmflash.h"
#include "delay.h"
#include "usart.h"
//////////////////////////////////////////////////////////////////////////////////
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֻ<EFBFBD><D6BB>ѧϰʹ<CFB0>ã<EFBFBD>δ<EFBFBD><CEB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɣ<EFBFBD><C9A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>κ<EFBFBD><CEBA><EFBFBD>;
//ALIENTEKս<4B><D5BD>STM32<33><32><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//STM32 FLASH <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//<2F><><EFBFBD><EFBFBD>ԭ<EFBFBD><D4AD>@ALIENTEK
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̳:www.openedv.com
//<2F>޸<EFBFBD><DEB8><EFBFBD><EFBFBD><EFBFBD>:2012/9/13
//<2F><EFBFBD><E6B1BE>V1.0
//<2F><>Ȩ<EFBFBD><C8A8><EFBFBD>У<EFBFBD><D0A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ؾ<EFBFBD><D8BE><EFBFBD>
//Copyright(C) <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӿƼ<D3BF><C6BC><EFBFBD><EFBFBD>޹<EFBFBD>˾ 2009-2019
//All rights reserved
//////////////////////////////////////////////////////////////////////////////////
//<2F><>ȡָ<C8A1><D6B8><EFBFBD><EFBFBD>ַ<EFBFBD>İ<EFBFBD><C4B0><EFBFBD>(16λ<36><CEBB><EFBFBD><EFBFBD>)
//faddr:<3A><><EFBFBD><EFBFBD>ַ(<28>˵<EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD>Ϊ2<CEAA>ı<EFBFBD><C4B1><EFBFBD>!!)
//<2F><><EFBFBD><EFBFBD>ֵ:<3A><>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD>.
u16 STMFLASH_ReadHalfWord(u32 faddr)
{
return *(vu16*)faddr;
}
#if STM32_FLASH_WREN //<2F><><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9><EFBFBD><EFBFBD>д
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><D0B4>
//WriteAddr:<3A><>ʼ<EFBFBD><CABC>ַ
//pBuffer:<3A><><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8>
//NumToWrite:<3A><>(32λ)<29><>
void STMFLASH_Write_NoCheck(u32 WriteAddr,u32 *pBuffer,u32 NumToWrite)
{
u16 i;
FLASH_Unlock();
for(i=0;i<NumToWrite;i++)
{
FLASH_FastProgramWord(WriteAddr,pBuffer[i]);
WriteAddr+=4;//<2F><>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD>4.
}
FLASH_Lock();
}
//<2F><><EFBFBD><EFBFBD>ҳ
void STMFLASH_Erase(u8 pagenum)
{
uint32_t address;
FLASH_Unlock();
address=pagenum*4096+STM32_FLASH_BASE;
FLASH_ErasePage(address);
FLASH_Lock();
}
//<2F><>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7>ʼд<CABC><D0B4>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD>ȵ<EFBFBD><C8B5><EFBFBD><EFBFBD><EFBFBD>
//WriteAddr:<3A><>ʼ<EFBFBD><CABC>ַ(<28>˵<EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD>Ϊ2<CEAA>ı<EFBFBD><C4B1><EFBFBD>!!)
//pBuffer:<3A><><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8>
//NumToWrite:<3A><><EFBFBD><EFBFBD>(16λ)<29><>(<28><><EFBFBD><EFBFBD>Ҫд<D2AA><D0B4><EFBFBD><EFBFBD>16λ<36><CEBB><EFBFBD>ݵĸ<DDB5><C4B8><EFBFBD>.)
#if STM32_FLASH_SIZE<256
#define STM_SECTOR_SIZE 1024 //<2F>ֽ<EFBFBD>
#else
#define STM_SECTOR_SIZE 2048
#endif
u16 STMFLASH_BUF[STM_SECTOR_SIZE/2];//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>2K<32>ֽ<EFBFBD>
void STMFLASH_Write(u32 WriteAddr,u16 *pBuffer,u16 NumToWrite)
{
u32 secpos; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ
u16 secoff; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƫ<EFBFBD>Ƶ<EFBFBD>ַ(16λ<36>ּ<EFBFBD><D6BC><EFBFBD>)
u16 secremain; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʣ<EFBFBD><CAA3><EFBFBD><EFBFBD>ַ(16λ<36>ּ<EFBFBD><D6BC><EFBFBD>)
u16 i;
u32 offaddr; //ȥ<><C8A5>0X08000000<30><30><EFBFBD>ĵ<EFBFBD>ַ
if(WriteAddr<STM32_FLASH_BASE||(WriteAddr>=(STM32_FLASH_BASE+1024*STM32_FLASH_SIZE)))return;//<2F>Ƿ<EFBFBD><C7B7><EFBFBD>ַ
FLASH_Unlock(); //<2F><><EFBFBD><EFBFBD>
offaddr=WriteAddr-STM32_FLASH_BASE; //ʵ<><CAB5>ƫ<EFBFBD>Ƶ<EFBFBD>ַ.
secpos=offaddr/STM_SECTOR_SIZE; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ 0~127 for STM32F103RBT6
secoff=(offaddr%STM_SECTOR_SIZE)/2; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڵ<EFBFBD>ƫ<EFBFBD><C6AB>(2<><32><EFBFBD>ֽ<EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λ.)
secremain=STM_SECTOR_SIZE/2-secoff; //<2F><><EFBFBD><EFBFBD>ʣ<EFBFBD><CAA3><EFBFBD>ռ<EFBFBD><D5BC><EFBFBD>С
if(NumToWrite<=secremain)secremain=NumToWrite;//<2F><><EFBFBD><EFBFBD><EFBFBD>ڸ<EFBFBD><DAB8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Χ
while(1)
{
STMFLASH_Read(secpos*STM_SECTOR_SIZE+STM32_FLASH_BASE,STMFLASH_BUF,STM_SECTOR_SIZE/2);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
for(i=0;i<secremain;i++)//У<><D0A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
if(STMFLASH_BUF[secoff+i]!=0XFFFF)break;//<2F><>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD>
}
if(i<secremain)//<2F><>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD>
{
FLASH_ErasePage(secpos*STM_SECTOR_SIZE+STM32_FLASH_BASE);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
for(i=0;i<secremain;i++)//<2F><><EFBFBD><EFBFBD>
{
STMFLASH_BUF[i+secoff]=pBuffer[i];
}
STMFLASH_Write_NoCheck(secpos*STM_SECTOR_SIZE+STM32_FLASH_BASE,STMFLASH_BUF,STM_SECTOR_SIZE/2);//д<><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
}else STMFLASH_Write_NoCheck(WriteAddr,pBuffer,secremain);//д<>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><><D6B1>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʣ<EFBFBD><CAA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>.
if(NumToWrite==secremain)break;//д<><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
else//д<><D0B4>δ<EFBFBD><CEB4><EFBFBD><EFBFBD>
{
secpos++; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7>1
secoff=0; //ƫ<><C6AB>λ<EFBFBD><CEBB>Ϊ0
pBuffer+=secremain; //ָ<><D6B8>ƫ<EFBFBD><C6AB>
WriteAddr+=secremain; //д<><D0B4>ַƫ<D6B7><C6AB>
NumToWrite-=secremain; //<2F>ֽ<EFBFBD>(16λ)<29><><EFBFBD>ݼ<EFBFBD>
if(NumToWrite>(STM_SECTOR_SIZE/2))secremain=STM_SECTOR_SIZE/2;//<2F><>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD>
else secremain=NumToWrite;//<2F><>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD>
}
};
FLASH_Lock();//<2F><><EFBFBD><EFBFBD>
}
#endif
//<2F><>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD>ȵ<EFBFBD><C8B5><EFBFBD><EFBFBD><EFBFBD>
//ReadAddr:<3A><>ʼ<EFBFBD><CABC>ַ
//pBuffer:<3A><><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8>
//NumToWrite:<3A><><EFBFBD><EFBFBD>(16λ)<29><>
void STMFLASH_Read(u32 ReadAddr,u16 *pBuffer,u16 NumToRead)
{
u16 i;
for(i=0;i<NumToRead;i++)
{
pBuffer[i]=STMFLASH_ReadHalfWord(ReadAddr);//<2F><>ȡ2<C8A1><32><EFBFBD>ֽ<EFBFBD>.
ReadAddr+=2;//ƫ<><C6AB>2<EFBFBD><32><EFBFBD>ֽ<EFBFBD>.
}
}
//////////////////////////////////////////////////////////////////////////////////////////////////////
//WriteAddr:<3A><>ʼ<EFBFBD><CABC>ַ
//WriteData:Ҫд<D2AA><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
void Test_Write(u32 WriteAddr,u16 WriteData)
{
STMFLASH_Write(WriteAddr,&WriteData,1);//д<><D0B4>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>
}

View File

@ -0,0 +1,53 @@
#ifndef __STMFLASH_H__
#define __STMFLASH_H__
#include "bsp.h"
//////////////////////////////////////////////////////////////////////////////////
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֻ<EFBFBD><D6BB>ѧϰʹ<CFB0>ã<EFBFBD>δ<EFBFBD><CEB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɣ<EFBFBD><C9A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>κ<EFBFBD><CEBA><EFBFBD>;
//ALIENTEKս<4B><D5BD>STM32<33><32><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//STM32 FLASH <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//<2F><><EFBFBD><EFBFBD>ԭ<EFBFBD><D4AD>@ALIENTEK
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̳:www.openedv.com
//<2F>޸<EFBFBD><DEB8><EFBFBD><EFBFBD><EFBFBD>:2012/9/13
//<2F><EFBFBD><E6B1BE>V1.0
//<2F><>Ȩ<EFBFBD><C8A8><EFBFBD>У<EFBFBD><D0A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ؾ<EFBFBD><D8BE><EFBFBD>
//Copyright(C) <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӿƼ<D3BF><C6BC><EFBFBD><EFBFBD>޹<EFBFBD>˾ 2009-2019
//All rights reserved
//////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////
//<2F>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Լ<EFBFBD><D4BC><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD>
#define STM32_FLASH_SIZE 384 //<2F><>ѡSTM32<33><32>FLASH<53><48><EFBFBD><EFBFBD><EFBFBD><EFBFBD>С(<28><>λΪK)
#define STM32_FLASH_WREN 1 //ʹ<><CAB9>FLASHд<48><D0B4>(0<><30><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>;1<><31>ʹ<EFBFBD><CAB9>)
//////////////////////////////////////////////////////////////////////////////////////////////////////
//FLASH<53><48>ʼ<EFBFBD><CABC>ַ
#define STM32_FLASH_BASE 0x08000000 //STM32 FLASH<53><48><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>ַ
//FLASH<53><48><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ
u16 STMFLASH_ReadHalfWord(u32 faddr); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
void STMFLASH_WriteLenByte(u32 WriteAddr,u32 DataToWrite,u16 Len); //ָ<><D6B8><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7>ʼд<CABC><D0B4>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD>ȵ<EFBFBD><C8B5><EFBFBD><EFBFBD><EFBFBD>
u32 STMFLASH_ReadLenByte(u32 ReadAddr,u16 Len); //ָ<><D6B8><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7>ʼ<EFBFBD><CABC>ȡָ<C8A1><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
void STMFLASH_Write(u32 WriteAddr,u16 *pBuffer,u16 NumToWrite); //<2F><>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7>ʼд<CABC><D0B4>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD>ȵ<EFBFBD><C8B5><EFBFBD><EFBFBD><EFBFBD>
void STMFLASH_Read(u32 ReadAddr,u16 *pBuffer,u16 NumToRead); //<2F><>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD>ȵ<EFBFBD><C8B5><EFBFBD><EFBFBD><EFBFBD>
//<2F><><EFBFBD><EFBFBD>д<EFBFBD><D0B4>
void Test_Write(u32 WriteAddr,u16 WriteData);
#endif

121
IAPV1.1/Driver/adc/adc.c Normal file
View File

@ -0,0 +1,121 @@
#include "adc.h"
#include "stm32l1xx_adc.h"
#include "bsp.h"
//PB0-ADC8,PB1-ADC9
__IO uint16_t VREFINT_CAL;
__IO uint16_t VREFINT_DATA;
__IO float VDDA_VAL;
void ADC15_Init(void)
{
ADC_CommonInitTypeDef ADC_CommonInitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
ADC_InitTypeDef ADC_InitStructure;
/*----------------- ADC1 configuration with DMA enabled --------------------*/
/* Enable the HSI oscillator */
RCC_HSICmd(ENABLE);
ADC_CommonInitStructure.ADC_Prescaler=ADC_Prescaler_Div4;
ADC_CommonInit(&ADC_CommonInitStructure);
/* Enable GPIOB clock */
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOC, ENABLE);
/* Configure PB.14 (ADC Channe20) in analog mode */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOC, &GPIO_InitStructure);
/* Check that HSI oscillator is ready */
while(RCC_GetFlagStatus(RCC_FLAG_HSIRDY) == RESET);
/* Enable ADC1 clock */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);
/* ADC1 configuration */
ADC_InitStructure.ADC_ScanConvMode = DISABLE;
ADC_InitStructure.ADC_ContinuousConvMode = DISABLE;
ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConvEdge_None;
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
// ADC_InitStructure.ADC_Resolution=ADC_Resolution_12b;//12λ
ADC_InitStructure.ADC_NbrOfConversion = 1;
ADC_Init(ADC1, &ADC_InitStructure);
ADC_TempSensorVrefintCmd(ENABLE);//<2F>ڲ<EFBFBD>ͨ<EFBFBD><CDA8>17ʹ<37><CAB9>
ADC_Cmd(ADC1, ENABLE);
VREFINT_CAL = *(__IO uint16_t *)(0X1FF800F8);
}
//<2F><><EFBFBD><EFBFBD>ADCֵ
//ch:ͨ<><CDA8>ֵ 0~3
u16 Get_Adc(u8 ch)
{
PWR_CTRLADC_H;//<2F><><EFBFBD><EFBFBD>ADC<44><43>Դ
//<2F><><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8>ADC<44>Ĺ<EFBFBD><C4B9><EFBFBD><EFBFBD><EFBFBD>ͨ<EFBFBD><CDA8><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD>У<EFBFBD><D0A3><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
ADC_RegularChannelConfig(ADC1, ch, 1, ADC_SampleTime_384Cycles ); //ADC1,ADCͨ<43><CDA8>
ADC_SoftwareStartConv(ADC1); //ʹ<><CAB9>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD>ADC1<43><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD><D7AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
while(!ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC ));//<2F>ȴ<EFBFBD>ת<EFBFBD><D7AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
return ADC_GetConversionValue(ADC1); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>ADC1<43><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD><D7AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
}
//<2F><>ȡ<EFBFBD><C8A1><EFBFBD>ο<EFBFBD><CEBF><EFBFBD>ѹ<EFBFBD><D1B9>ADCֵ
float Get_Adc_Ref(u8 ch)
{
float ADC_V;
u16 adc_ch;
PWR_CTRLADC_H;//<2F><><EFBFBD><EFBFBD>ADC<44><43>Դ
// Get_Adc(ch);
VREFINT_DATA=Get_Adc(17);
adc_ch=Get_Adc(ch);
VDDA_VAL=(float)3*VREFINT_CAL/VREFINT_DATA;//<2F><>ȡVDDA<44><41>ѹ
ADC_V=((float)adc_ch/4095)*VDDA_VAL;
return ADC_V;
}
float Get_Adc_Average(u8 ch,u8 times)
{
float temp_val=0;
u8 t;
for(t=0;t<times;t++)
{
//temp_val+=Get_Adc_Ref(ch);
temp_val+=Get_Adc(ch);
delay_ms(10);
}
temp_val=((temp_val/times)/4095)*3.35;
return temp_val;
//return ((temp_val/times));
}
void ADC15_POWERON(void)
{
PWR_CTRLADC_H;
};
void ADC15_POWEROFF(void)
{
PWR_CTRLADC_L;
};
void ADC15_Process(void)
{
float ADC_VALUVE;
ADC_VALUVE=Get_Adc_Average(15,10);
delay_ms(500);
ADC_VALUVE=Get_Adc_Average(15,10);
ADC_VALUVE*=(float)4.2;
sprintf(data_common1.ADC_DATA,"%.3f,",ADC_VALUVE);
}

37
IAPV1.1/Driver/adc/adc.h Normal file
View File

@ -0,0 +1,37 @@
#ifndef __ADC_H
#define __ADC_H
#include "general_type.h"
#include "pbdata.h"
//#include "stdint.h"
//#define ADC_CH1 1 //ͨ<><CDA8>1
//#define ADC_CH_TEMP 16 //<2F>¶ȴ<C2B6><C8B4><EFBFBD><EFBFBD><EFBFBD>ͨ<EFBFBD><CDA8>
void Adc_Get_Voltage(void);
u16 Get_Adc(u8 ch); //<2F><><EFBFBD><EFBFBD>ij<EFBFBD><C4B3>ͨ<EFBFBD><CDA8>ֵ
float Get_Adc_Average(u8 ch,u8 times);//<2F>õ<EFBFBD>ij<EFBFBD><C4B3>ͨ<EFBFBD><CDA8>10<31>β<EFBFBD><CEB2><EFBFBD><EFBFBD><EFBFBD>ƽ<EFBFBD><C6BD>ֵ
u16 Get_Adc2(u8 ch) ;
extern float ADC_VALUVE;
extern __IO uint16_t VREFINT_CAL;
extern __IO uint16_t VREFINT_DATA;
extern __IO float VDDA_VAL;
void ADC15_Init(void);
float Get_Adc_Ref(u8 ch);
void ADC15_POWERON(void);
void ADC15_POWEROFF(void);
void ADC15_Process(void);
#endif

12
IAPV1.1/Driver/bsp/bsp.c Normal file
View File

@ -0,0 +1,12 @@
#include "bsp.h"
//<2F><><EFBFBD>̳<EFBFBD>ʼ<EFBFBD><CABC>
u8 Par_store_flag=0; //<2F><EFBFBD><E8B1B8><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD>־
void bsp_init(void)
{
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);
bsp_InitDWT(); //<2F><>ʱ<EFBFBD><CAB1>DWT<57><54>ʼ<EFBFBD><CABC>
PWR_CTRL_Init(); //ϵͳ<CFB5><CDB3>Դ<EFBFBD><D4B4>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD>ã<EFBFBD><C3A3>رյ<D8B1>·<EFBFBD><C2B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>е<EFBFBD>Դ
PWR_CTRL3V3_H; //<2F><><EFBFBD><EFBFBD>3.3V<EFBFBD>ܵ<EFBFBD>Դ
Usart5_Configuration(9600); //485<38><35><EFBFBD>ڳ<EFBFBD>ʼ<EFBFBD><CABC>
//USART1_Configuration(115200);
}

45
IAPV1.1/Driver/bsp/bsp.h Normal file
View File

@ -0,0 +1,45 @@
#ifndef _bsp_H
#define _bsp_H
#include "STM32L1xx_PWR.h"
#include "stm32l1xx_exti.h"
#include "stm32l1xx_tim.h"
#include "stm32l1xx_syscfg.h"
#include "misc.h"
#include "stm32l1xx_flash.h"
#include "delay.h"
#include "usart.h"
//#include "usart3.h"
//#include "usart1_sdi.h"
//#include "usart2.h"
//#include "usart4.h"
#include "usart5.h"
#include "iap.h"
#include "pwr_ctrl.h"
#include "eeprom.h"
#include "spi.h"
#include "flash.h"
#include "SPI_SD_driver.h"
#include "ff.h"
#include "ffconf.h"
#include "data_handle.h"
#include "stdint.h"
#include "bsp_dwt.h"
#include "stdio.h"
#include "stdarg.h"
#include "string.h"
void bsp_init(void);
void bsp_init_wakeup(void);
#endif

View File

@ -0,0 +1,131 @@
/*
*********************************************************************************************************
*
* ģ<><C4A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD> : <20><><EFBFBD>ݹ۲<DDB9><DBB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(DWT)ģ<><C4A3>
* <09>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD> : bsp_dwt.c
* <09><> <20><> : V1.0
* ˵ <20><> : <20><>CM3<4D><33>CM4<4D>п<EFBFBD><D0BF><EFBFBD><EFBFBD><EFBFBD>3<EFBFBD>ָ<EFBFBD><D6B8><EFBFBD>Դ<EFBFBD><D4B4>ETM, ITM <20><>DWT<57><54><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫʵ<D2AA><CAB5>
* DWT<57>е<EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD>ڣ<EFBFBD>CYCCNT<4E><54><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܣ<EFBFBD><DCA3>˹<EFBFBD><CBB9>ܷdz<DCB7><C7B3><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD>Ժܷ<D4BA><DCB7><EFBFBD><EFBFBD><EFBFBD>
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ִ<EFBFBD>е<EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD>ڸ<EFBFBD><DAB8><EFBFBD><EFBFBD><EFBFBD>
* <09>޸ļ<DEB8>¼ :
* <09><EFBFBD><E6B1BE> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> ˵<><CBB5>
* V1.0 2015-08-18 Eric2013 <20><>ʽ<EFBFBD><CABD><EFBFBD><EFBFBD>
*
* Copyright (C), 2015-2020, <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> www.armfly.com
*
*********************************************************************************************************
*/
#include "bsp.h"
/*
*********************************************************************************************************
* <20>Ĵ<EFBFBD><C4B4><EFBFBD>
*********************************************************************************************************
*/
#define DWT_CYCCNT *(volatile unsigned int *)0xE0001004
#define DWT_CR *(volatile unsigned int *)0xE0001000
#define DEM_CR *(volatile unsigned int *)0xE000EDFC
#define DBGMCU_CR *(volatile unsigned int *)0xE0042004
#define DEM_CR_TRCENA (1 << 24)
#define DWT_CR_CYCCNTENA (1 << 0)
/*
*********************************************************************************************************
* <09><> <20><> <20><>: bsp_InitDWT
* <09><><EFBFBD><EFBFBD>˵<EFBFBD><CBB5>: <20><>ʼ<EFBFBD><CABC>DWT. <20>ú<EFBFBD><C3BA><EFBFBD><EFBFBD><EFBFBD> bsp_Init() <20><><EFBFBD>á<EFBFBD>
* <09><> <20><>: <20><>
* <09><> <20><> ֵ: <20><>
*********************************************************************************************************
*/
void bsp_InitDWT(void)
{
DEM_CR |= (unsigned int)DEM_CR_TRCENA; /* Enable Cortex-M4's DWT CYCCNT reg. */
DWT_CYCCNT = (unsigned int)0u;
DWT_CR |= (unsigned int)DWT_CR_CYCCNTENA;
}
/*
*********************************************************************************************************
* <09><> <20><> <20><>: bsp_DelayUS
* <09><><EFBFBD><EFBFBD>˵<EFBFBD><CBB5>: <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>CPU<50><55><EFBFBD>ڲ<EFBFBD><DAB2><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD>֣<EFBFBD>32λ<32><CEBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* OSSchedLock(&err);
* bsp_DelayUS(5);
* OSSchedUnlock(&err); <20><><EFBFBD><EFBFBD>ʵ<EFBFBD><CAB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD>Ҫ<EFBFBD>ӵ<EFBFBD><D3B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
* <09><> <20><>: _ulDelayTime <20>ӳٳ<D3B3><D9B3>ȣ<EFBFBD><C8A3><EFBFBD>λ1 us
* <09><> <20><> ֵ: <20><>
* ˵ <20><>: 1. <20><>Ƶ168MHz<48><7A><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>£<EFBFBD>32λ<32><CEBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>2^32/168000000 = 25.565<EFBFBD><EFBFBD>
* <20><><EFBFBD><EFBFBD>ʹ<EFBFBD>ñ<EFBFBD><C3B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӳٵĻ<D9B5><C4BB><EFBFBD><EFBFBD>ӳ<EFBFBD><D3B3><EFBFBD>1<EFBFBD><31><EFBFBD><EFBFBD><EFBFBD>¡<EFBFBD>
* 2. ʵ<><CAB5>ͨ<EFBFBD><CDA8>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ԣ<EFBFBD>΢<EFBFBD><CEA2><EFBFBD>ӳٺ<D3B3><D9BA><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD><CAB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʵ<EFBFBD>ʶ<EFBFBD><CAB6><EFBFBD><EFBFBD><EFBFBD>0.25us<EFBFBD><EFBFBD><EFBFBD>ҵ<EFBFBD>ʱ<EFBFBD>
* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݲ<EFBFBD><DDB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* <20><>1<EFBFBD><31>. MDK5.15<EFBFBD><EFBFBD><EFBFBD>Ż<EFBFBD><EFBFBD>ȼ<EFBFBD>0, <20><>ͬ<EFBFBD><CDAC>MDK<44>Ż<EFBFBD><C5BB>ȼ<EFBFBD><C8BC><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD><C3BB>Ӱ<EFBFBD>
* <20><>2<EFBFBD><32>. STM32F407IGT6
* <20><>3<EFBFBD><33>. <20><><EFBFBD>Է<EFBFBD><D4B7><EFBFBD><EFBFBD><EFBFBD>
* GPIOI->BSRRL = GPIO_Pin_8;
* bsp_DelayUS(10);
* GPIOI->BSRRH = GPIO_Pin_8;
* -------------------------------------------
* <20><><EFBFBD><EFBFBD> ʵ<><CAB5>ִ<EFBFBD><D6B4>
* bsp_DelayUS(1) 1.2360us
* bsp_DelayUS(2) 2.256us
* bsp_DelayUS(3) 3.256us
* bsp_DelayUS(4) 4.256us
* bsp_DelayUS(5) 5.276us
* bsp_DelayUS(6) 6.276us
* bsp_DelayUS(7) 7.276us
* bsp_DelayUS(8) 8.276us
* bsp_DelayUS(9) 9.276us
* bsp_DelayUS(10) 10.28us
* 3. <20><><EFBFBD><EFBFBD>32λ<32>޷<EFBFBD><DEB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡ<EFBFBD>Ľ<EFBFBD><C4BD><EFBFBD><EFBFBD>ٸ<EFBFBD>ֵ<EFBFBD><D6B5>32λ<32>޷<EFBFBD><DEB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ȼ<EFBFBD><C8BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȷ<EFBFBD>Ļ<EFBFBD>ȡ<EFBFBD><C8A1>ֵ<EFBFBD><D6B5>
* <20><><EFBFBD><EFBFBD>A,B,C<><43><EFBFBD><EFBFBD>32λ<32>޷<EFBFBD><DEB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* <20><><EFBFBD><EFBFBD>A > B <20><>ôA - B = C<><43><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܺ<EFBFBD><DCBA><EFBFBD><EFBFBD><EFBFBD><E2A3AC>ȫû<C8AB><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* <20><><EFBFBD><EFBFBD>A < B <20><>ôA - B = C<><43> C<><43><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD>0xFFFFFFFF - B + A + 1<><31><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>Ҫ<EFBFBD>ر<EFBFBD>ע<EFBFBD><EFBFBD><E2A3AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڱ<EFBFBD><DAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*********************************************************************************************************
*/
void bsp_DelayUS(uint32_t _ulDelayTime)
{
uint32_t tCnt, tDelayCnt;
uint32_t tStart;
tStart = DWT_CYCCNT; /* <20>ս<EFBFBD><D5BD><EFBFBD>ʱ<EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>ֵ */
tCnt = 0;
tDelayCnt = _ulDelayTime * (SystemCoreClock / 1000000); /* <20><>Ҫ<EFBFBD>Ľ<EFBFBD><C4BD><EFBFBD><EFBFBD><EFBFBD> */
while(tCnt < tDelayCnt)
{
tCnt = DWT_CYCCNT - tStart; /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>У<EFBFBD><D0A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>32λ<32><CEBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><C2BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ȼ<EFBFBD><C8BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȷ<EFBFBD><C8B7><EFBFBD><EFBFBD> */
}
}
/*
*********************************************************************************************************
* <09><> <20><> <20><>: bsp_DelayMS
* <09><><EFBFBD><EFBFBD>˵<EFBFBD><CBB5>: Ϊ<><CEAA><EFBFBD>õײ<C3B5><D7B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>RTOS<4F><53><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>и<EFBFBD><D0B8>õļ<C3B5><C4BC><EFBFBD><EFBFBD><EFBFBD>
* ר<><D7A8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ<EFBFBD><CABD><EFBFBD>ӳٺ<D3B3><D9BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڵײ<DAB5><D7B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ms<6D><73><EFBFBD><EFBFBD><EFBFBD>ӳ<EFBFBD><D3B3><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD>ڳ<EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӱ<EFBFBD><D3B0>ʵʱ<CAB5>ԡ<EFBFBD>
* <09><> <20><>: n <20>ӳٳ<D3B3><D9B3>ȣ<EFBFBD><C8A3><EFBFBD>λ1 ms
* <09><> <20><> ֵ: <20><>
*********************************************************************************************************
*/
void bsp_DelayMS(uint32_t _ulDelayTime)
{
bsp_DelayUS(1000*_ulDelayTime);
}
void bsp_DelayDWT(uint32_t _ulDelayTime)
{
uint32_t tCnt, tDelayCnt;
uint32_t tStart;
tCnt = 0;
tDelayCnt = _ulDelayTime; /* <20><>Ҫ<EFBFBD>Ľ<EFBFBD><C4BD><EFBFBD><EFBFBD><EFBFBD> */
tStart = DWT_CYCCNT; /* <20>ս<EFBFBD><D5BD><EFBFBD>ʱ<EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>ֵ */
while(tCnt < tDelayCnt)
{
tCnt = DWT_CYCCNT - tStart; /* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>У<EFBFBD><D0A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>32λ<32><CEBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><C2BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ȼ<EFBFBD><C8BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȷ<EFBFBD><C8B7><EFBFBD><EFBFBD> */
}
}
/***************************** <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> www.armfly.com (END OF FILE) *********************************/

View File

@ -0,0 +1,27 @@
/*
*********************************************************************************************************
*
* ģ<><C4A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD> : <20><><EFBFBD>ݹ۲<DDB9><DBB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(DWT)ģ<><C4A3>
* <09>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD> : bsp_dwt.h
* <09><> <20><> : V1.0
* ˵ <20><> : ͷ<>ļ<EFBFBD>
* <09>޸ļ<DEB8>¼ :
* <09><EFBFBD><E6B1BE> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> ˵<><CBB5>
* V1.0 2015-08-18 Eric2013 <20><>ʽ<EFBFBD><CABD><EFBFBD><EFBFBD>
*
* Copyright (C), 2015-2020, <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> www.armfly.com
*
*********************************************************************************************************
*/
#ifndef __BSP_DWT_H
#define __BSP_DWT_H
#include "bsp.h"
void bsp_InitDWT(void);
void bsp_DelayDWT(uint32_t _ulDelayTime);
void bsp_DelayUS(uint32_t _ulDelayTime);
void bsp_DelayMS(uint32_t _ulDelayTime);
#endif
/***************************** <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> www.armfly.com (END OF FILE) *********************************/

View File

@ -0,0 +1,115 @@
/*********<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD>дͨ<D0B4><CDA8>***********/
#include "eeprom.h"
#include "bsp.h"
#include "stm32l1xx_flash.h"
Init_Data Init_Data_Equipment;
/*------------------------------------------------------------
Func: EEPROM<4F><4D><EFBFBD>ݰ<EFBFBD><DDB0>ֽڶ<D6BD><DAB6><EFBFBD>
Note:
-------------------------------------------------------------*/
void EEPROM_ReadBytes(u16 Addr,u8 *Buffer,u16 Length)
{
u8 *wAddr;
wAddr=(u8 *)(EEPROM_BASE_ADDR+Addr);
while(Length--){
*Buffer++=*wAddr++;
}
}
/*------------------------------------------------------------
Func: EEPROM<4F><4D><EFBFBD>ݶ<EFBFBD><DDB6><EFBFBD>
Note:
-------------------------------------------------------------*/
void EEPROM_ReadWords(u16 Addr,u16 *Buffer,u16 Length)
{
u32 *wAddr;
wAddr=(u32 *)(EEPROM_BASE_ADDR+Addr);
while(Length--){
*Buffer++=*wAddr;
wAddr+=2;
}
}
/*------------------------------------------------------------
Func: EEPROM<4F><4D><EFBFBD>ݶ<EFBFBD><DDB6><EFBFBD>˫<EFBFBD><CBAB>
Note:
-------------------------------------------------------------*/
void EEPROM_ReadDWords(u16 Addr,u32 *Buffer,u16 Length)
{
u32 *wAddr;
wAddr=(u32 *)(EEPROM_BASE_ADDR+Addr);
while(Length--){
*Buffer++=*wAddr;
wAddr+=4;
}
}
/*------------------------------------------------------------
Func: EEPROM<4F><4D><EFBFBD>ݰ<EFBFBD><DDB0>ֽ<EFBFBD>д<EFBFBD><D0B4>
Note:
-------------------------------------------------------------*/
void EEPROM_WriteBytes(u16 Addr,u8 *Buffer,u16 Length)
{
u8 *wAddr;
wAddr=(u8 *)(EEPROM_BASE_ADDR+Addr);
FLASH->PEKEYR=PEKEY1; //unlock
FLASH->PEKEYR=PEKEY2;
while(FLASH->PECR&FLASH_PECR_PELOCK);
FLASH->PECR|=FLASH_PECR_FTDW; //not fast write
while(Length--){
*wAddr++=*Buffer++;
while(FLASH->SR&FLASH_SR_BSY);
}
FLASH->PECR|=FLASH_PECR_PELOCK;
}
/*------------------------------------------------------------
Func: EEPROM<4F><4D><EFBFBD>ݰ<EFBFBD><DDB0><EFBFBD>д<EFBFBD><D0B4>
Note: <20>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
-------------------------------------------------------------*/
void EEPROM_WriteWords(u16 Addr,u16 *Buffer,u16 Length)
{
u32 *wAddr;
wAddr=(u32 *)(EEPROM_BASE_ADDR+Addr);
FLASH->PEKEYR=PEKEY1; //unlock
FLASH->PEKEYR=PEKEY2;
while(FLASH->PECR&FLASH_PECR_PELOCK);
FLASH->PECR|=FLASH_PECR_FTDW; //not fast write
while(Length--){
*wAddr=*Buffer++;
wAddr+=2;
while(FLASH->SR&FLASH_SR_BSY);
}
FLASH->PECR|=FLASH_PECR_PELOCK;
}
/*------------------------------------------------------------
Func: EEPROM<4F><4D><EFBFBD>ݰ<EFBFBD>˫<EFBFBD><CBAB>д<EFBFBD><D0B4>
Note:
-------------------------------------------------------------*/
void EEPROM_WriteDWords(u16 Addr,u32 *Buffer,u16 Length)
{
u32 *wAddr;
wAddr=(u32 *)(EEPROM_BASE_ADDR+Addr);
FLASH->PEKEYR=PEKEY1; //unlock
FLASH->PEKEYR=PEKEY2;
while(FLASH->PECR&FLASH_PECR_PELOCK);
FLASH->PECR|=FLASH_PECR_FTDW; //not fast write
while(Length--){
*wAddr=*Buffer++;
wAddr+=4;
while(FLASH->SR&FLASH_SR_BSY);
}
FLASH->PECR|=FLASH_PECR_PELOCK;
}

View File

@ -0,0 +1,87 @@
#ifndef _eeprom_H
#define _eeprom_H
#include "bsp.h"
#include "stm32l1xx_flash.h"
/****************<2A><><EFBFBD><EFBFBD>EEPROM<4F>Ĵ洢<C4B4><E6B4A2><EFBFBD><EFBFBD>*************
<EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><>ַ Ĭ<><C4AC>ֵ
IOT-IP 0-19 219.238.240.58 (Զ<><D4B6>TCPSERVER<45><52>ַ)
IOT-PORT 20-29 9022 (Զ<><D4B6>TCPSERVER<45>˿<EFBFBD>)
WIFI-PORT 30-39 8080 (WIFI<46><49><EFBFBD>ض˿<D8B6>)
WIFI<EFBFBD><EFBFBD><EFBFBD><EFBFBD> 40-59 lica_esp8266 ˵<><CBB5>δ<EFBFBD><EFBFBD><E1B5BD><EFBFBD><EFBFBD>λ<EFBFBD><CEBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E6B6A8><EFBFBD><EFBFBD>20
WIFI<EFBFBD><EFBFBD><EFBFBD><EFBFBD> 60-69 12345678 <20><><EFBFBD><EFBFBD><38><CEBB><EFBFBD><EFBFBD><EBA3AC><EFBFBD><EFBFBD>64λ<34><CEBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>涨Ϊ10λ
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 100-105 600S <20><>Χ0-86400 0-24H
<EFBFBD><EFBFBD><EFBFBD>ݴ<EFBFBD><EFBFBD><EFBFBD>ģʽ 110-119 <20><>δʹ<CEB4><CAB9>
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϴ<EFBFBD>ʱ<EFBFBD><EFBFBD> 120-129 00000 Сʱ+<2B><><EFBFBD><EFBFBD>Ĭ<EFBFBD><C4AC>Ϊ0<CEAA><30><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϴ<EFBFBD><CFB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Сʱ<D0A1><CAB1><EFBFBD><EFBFBD>23Ϊ<33><CEAA><EFBFBD><EFBFBD><EFBFBD>ϴ<EFBFBD>
<EFBFBD>豸ID 130-139 <20>ݶ<EFBFBD><DDB6>豸ID<49><44>Ϊ10λ
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־ 140 1<>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD><E8B1B8><EFBFBD><EFBFBD> 0<><30>
ԤԼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD> 150-165 ddhhmmss
<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģʽ 166 0 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģʽ<C4A3><CABD>1ԤԼ<D4A4><D4BC><EFBFBD><EFBFBD>ģʽ<C4A3><CABD>ԤԼʱ<D4BC><CAB1>>24H<34><48><EFBFBD><EFBFBD>Ч<EFBFBD><D0A7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
ϵͳʱ<EFBFBD><EFBFBD>ǧ<EFBFBD><EFBFBD>λ 170-171
TF<EFBFBD><EFBFBD><EFBFBD>ϴ<EFBFBD><EFBFBD><EFBFBD>ʼλ<EFBFBD><EFBFBD> 180-183
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>޸ı<EFBFBD>־ 185 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>޸ĺ󣬸ñ<F3A3ACB8>־<EFBFBD><D6BE>1<EFBFBD><31>
Զ<EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD><EFBFBD><EFBFBD>ͱ<EFBFBD>־ 186 <20><><EFBFBD>ͱ<EFBFBD>ͷ<EFBFBD>󣬸ñ<F3A3ACB8>־<EFBFBD><D6BE>1<EFBFBD><31>
Զ<EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 187
IAP<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־ 188 0<>޳<EFBFBD><DEB3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 1<>г<EFBFBD><D0B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 1
IAP<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 190-209 <20><><EFBFBD><EFBFBD>+<2B><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>+<2B><><EFBFBD>ڵĵڼ<C4B5><DABC><EFBFBD> V1.0_20220309_99
APP<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 210-239 <20><><EFBFBD><EFBFBD>+<2B><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>+<2B><><EFBFBD>ڵĵڼ<C4B5><DABC><EFBFBD> V1.0_20220309_99
***************************************/
#define PEKEY1 0x89ABCDEF //FLASH_PEKEYR
#define PEKEY2 0x02030405 //FLASH_PEKEYR
#define EEPROM_BASE_ADDR 0x08080000
#define EEPROM_BYTE_SIZE 0x3000 //12keeprom<6F><EFBFBD>ռ<EFBFBD> 12288<38><38><EFBFBD>ֽ<EFBFBD>
#define EN_INT __enable_irq(); //ϵͳ<CFB5><CDB3>ȫ<EFBFBD><C8AB><EFBFBD>ж<EFBFBD>
#define DIS_INT __disable_irq(); //ϵͳ<CFB5><CDB3>ȫ<EFBFBD><C8AB><EFBFBD>ж<EFBFBD>
#define Bc25_Ip_len 20
#define Bc25_Port_len 10
#define ESP8266_AP_SSIDs_len 20
#define ESP8266_AP_Ports_len 10
#define ESP8266_AP_PWDs_len 10
#define Measure_Interval_len 6
#define Pub_Mode_len 5
#define Pub_Time_len 10
#define Equipment_ID_len 10
#define appointment_time_len 9
#define measure_mode_len 2
#define IAP_Flag_1 1 //<2F><><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>
#define IAP_Flag_0 0 //<2F><><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD>
void EEPROM_ReadBytes(u16 Addr,u8 *Buffer,u16 Length);
void EEPROM_ReadWords(u16 Addr,u16 *Buffer,u16 Length);
void EEPROM_WriteBytes(u16 Addr,u8 *Buffer,u16 Length);
void EEPROM_WriteWords(u16 Addr,u16 *Buffer,u16 Length);
void EEPROM_ReadDWords(u16 Addr,u32 *Buffer,u16 Length);
void EEPROM_WriteDWords(u16 Addr,u32 *Buffer,u16 Length);
void Clear_eeprom_par(void);
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><E8B1B8>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD>ⲿ<EFBFBD><E2B2BF><EFBFBD>õIJ<C3B5><C4B2><EFBFBD>
typedef struct
{
char Bc25_Ip[20]; //Զ<>̴<EFBFBD><CCB4><EFBFBD><EFBFBD>豸IP
char Bc25_Port[10]; //Զ<>̴<EFBFBD><CCB4><EFBFBD><EFBFBD>˿<EFBFBD>
char ESP8266_AP_SSIDs[20];//WIFI<46><49><EFBFBD><EFBFBD>
char ESP8266_AP_Ports[10];//WIFI<46>˿<EFBFBD>
char ESP8266_AP_PWDs[10];//WiFi<46><69><EFBFBD><EFBFBD>
char Measure_Interval[Measure_Interval_len];//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
char Pub_Mode[5];//<2F><>δʹ<CEB4><CAB9>
char Pub_Time[10];//<2F><><EFBFBD><EFBFBD><EFBFBD>ϴ<EFBFBD><CFB4><EFBFBD><EFBFBD><EFBFBD>-<2D><><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>λS
char Equipment_ID[10]; //<2F><EFBFBD><E8B1B8><EFBFBD><EFBFBD>
// char Equipment_ID_WKUP[2];
char appointment_time[9];//ԤԼ<D4A4><D4BC><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1> <20><><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA> DDHHMMSS
char measure_mode[2];
}Init_Data;
extern Init_Data Init_Datas;
extern Init_Data Init_Data_Equipment;
Init_Data Read_Equipment_Par(void);
void Write_Equipment_Par(Init_Data Init_Data_Equipmend);
void clear_Init_Data_Equipment(void);
void Write_Factory_Par(void);//<2F>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ò<EFBFBD><C3B2><EFBFBD>
#endif

View File

@ -0,0 +1,408 @@
#include "enc28j60.h"
#include "spi.h"
#include <stdio.h>
static unsigned char Enc28j60Bank;
static unsigned int NextPacketPtr;
unsigned char enc28j60ReadOp(unsigned char op, unsigned char address)
{
unsigned char dat = 0;
ENC28J60_CSL();
dat = op | (address & ADDR_MASK);
SPI1_ReadWrite(dat);
dat = SPI1_ReadWrite(0xFF);
// do dummy read if needed (for mac and mii, see datasheet page 29)
if(address & 0x80)
{
dat = SPI1_ReadWrite(0xFF);
}
// release CS
ENC28J60_CSH();
return dat;
}
void enc28j60WriteOp(unsigned char op, unsigned char address, unsigned char data)
{
unsigned char dat = 0;
ENC28J60_CSL();
// issue write command
dat = op | (address & ADDR_MASK);
SPI1_ReadWrite(dat);
// write data
dat = data;
SPI1_ReadWrite(dat);
ENC28J60_CSH();
}
void enc28j60ReadBuffer(unsigned int len, unsigned char* data)
{
ENC28J60_CSL();
// issue read command
SPI1_ReadWrite(ENC28J60_READ_BUF_MEM);
while(len)
{
len--;
// read data
*data = (unsigned char)SPI1_ReadWrite(0);
data++;
}
*data='\0';
ENC28J60_CSH();
}
void enc28j60WriteBuffer(unsigned int len, unsigned char* data)
{
ENC28J60_CSL();
// issue write command
SPI1_ReadWrite(ENC28J60_WRITE_BUF_MEM);
while(len)
{
len--;
SPI1_ReadWrite(*data);
data++;
}
ENC28J60_CSH();
}
void enc28j60SetBank(unsigned char address)
{
// set the bank (if needed)
if((address & BANK_MASK) != Enc28j60Bank)
{
// set the bank
enc28j60WriteOp(ENC28J60_BIT_FIELD_CLR, ECON1, (ECON1_BSEL1|ECON1_BSEL0));
enc28j60WriteOp(ENC28J60_BIT_FIELD_SET, ECON1, (address & BANK_MASK)>>5);
Enc28j60Bank = (address & BANK_MASK);
}
}
unsigned char enc28j60Read(unsigned char address)
{
// set the bank
enc28j60SetBank(address);
// do the read
return enc28j60ReadOp(ENC28J60_READ_CTRL_REG, address);
}
void enc28j60Write(unsigned char address, unsigned char data)
{
// set the bank
enc28j60SetBank(address);
// do the write
enc28j60WriteOp(ENC28J60_WRITE_CTRL_REG, address, data);
}
void enc28j60PhyWrite(unsigned char address, unsigned int data)
{
// set the PHY register address
enc28j60Write(MIREGADR, address);
// write the PHY data
enc28j60Write(MIWRL, data);
enc28j60Write(MIWRH, data>>8);
// wait until the PHY write completes
while(enc28j60Read(MISTAT) & MISTAT_BUSY)
{
//Del_10us(1);
__NOP();
__NOP();
__NOP();
__NOP();
__NOP();
}
}
void enc28j60clkout(unsigned char clk)
{
//setup clkout: 2 is 12.5MHz:
enc28j60Write(ECOCON, clk & 0x7);
}
u8 enc28j60Init(unsigned char* macaddr)
{
u16 retry = 0;
ENC28J60_CSH();
enc28j60WriteOp(ENC28J60_SOFT_RESET, 0, ENC28J60_SOFT_RESET);
while(!(enc28j60Read(ESTAT)&ESTAT_CLKRDY)&&retry<500)
{
retry++;
// delay_ms(1);
};
if(retry>=500)return 1;//ENC28J60<36><30>ʼ<EFBFBD><CABC>ʧ<EFBFBD><CAA7>
// Del_1ms(250);
// check CLKRDY bit to see if reset is complete
// The CLKRDY does not work. See Rev. B4 Silicon Errata point. Just wait.
//while(!(enc28j60Read(ESTAT) & ESTAT_CLKRDY));
// do bank 0 stuff
// initialize receive buffer
// 16-bit transfers, must write low byte first
// set receive buffer start address <20><><EFBFBD>ý<EFBFBD><C3BD>ջ<EFBFBD><D5BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ 8K<38>ֽ<EFBFBD><D6BD><EFBFBD><EFBFBD><EFBFBD>
NextPacketPtr = RXSTART_INIT;
// Rx start
//<2F><><EFBFBD>ջ<EFBFBD><D5BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>Ӳ<EFBFBD><D3B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѭ<EFBFBD><D1AD>FIFO <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɡ<EFBFBD>
//<2F>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD>ERXSTH:ERXSTL <20><>ERXNDH:ERXNDL <20><>
//Ϊָ<CEAA><EFBFBD><EBA3AC><EFBFBD><EFBFBD><E5BBBA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ洢<DAB4><E6B4A2><EFBFBD>е<EFBFBD>λ<EFBFBD>á<EFBFBD>
//ERXST<53><54>ERXNDָ<44><D6B8><EFBFBD><EFBFBD><EFBFBD>ֽھ<D6BD><DABE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>FIFO<46><4F><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڡ<EFBFBD>
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̫<EFBFBD><CCAB><EFBFBD>ӿڽ<D3BF><DABD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֽ<EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>Щ<EFBFBD>ֽڱ<D6BD>˳<EFBFBD><CBB3>д<EFBFBD><D0B4>
//<2F><><EFBFBD>ջ<EFBFBD><D5BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD>ǵ<EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD>ERXND ָ<><D6B8><EFBFBD>Ĵ洢<C4B4><E6B4A2>Ԫ
//<2F><><EFBFBD><EFBFBD>Ӳ<EFBFBD><D3B2><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>յ<EFBFBD><D5B5><EFBFBD>һ<EFBFBD>ֽ<EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD>ERXST ָ<><D6B8>
//<2F>Ĵ洢<C4B4><E6B4A2>Ԫ<EFBFBD><D4AA> <20><><EFBFBD>˽<EFBFBD><CBBD><EFBFBD>Ӳ<EFBFBD><D3B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><D0B4>FIFO <20><><EFBFBD><EFBFBD><EFBFBD>ĵ<EFBFBD>
//Ԫ<><D4AA>
enc28j60Write(ERXSTL, RXSTART_INIT&0xFF); //
enc28j60Write(ERXSTH, RXSTART_INIT>>8);
// set receive pointer address
//ERXWRPTH:ERXWRPTL <20>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӳ<EFBFBD><D3B2><EFBFBD><EFBFBD>FIFO <20><>
//<2F><><EFBFBD>ĸ<EFBFBD>λ<EFBFBD><CEBB>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD>ֽڡ<D6BD> ָ<><D6B8><EFBFBD><EFBFBD>ֻ<EFBFBD><D6BB><EFBFBD>ģ<EFBFBD><C4A3>ڳ<EFBFBD>
//<2F><><EFBFBD><EFBFBD><EFBFBD>յ<EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD>ݰ<EFBFBD><DDB0><EFBFBD><EFBFBD><EFBFBD>Ӳ<EFBFBD><D3B2><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD>롣 ָ<><D6B8><EFBFBD><EFBFBD>
//<2F><><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>FIFO <20><>ʣ<EFBFBD><CAA3><EFBFBD>ռ<EFBFBD><D5BC>Ĵ<EFBFBD>С 8K-1500<30><30>
enc28j60Write(ERXRDPTL, RXSTART_INIT&0xFF);
enc28j60Write(ERXRDPTH, RXSTART_INIT>>8);
// RX end
enc28j60Write(ERXNDL, RXSTOP_INIT&0xFF);
enc28j60Write(ERXNDH, RXSTOP_INIT>>8);
// TX start 1500
enc28j60Write(ETXSTL, TXSTART_INIT&0xFF);
enc28j60Write(ETXSTH, TXSTART_INIT>>8);
// TX end
enc28j60Write(ETXNDL, TXSTOP_INIT&0xFF);
enc28j60Write(ETXNDH, TXSTOP_INIT>>8);
// do bank 1 stuff, packet filter:
// For broadcast packets we allow only ARP packtets
// All other packets should be unicast only for our mac (MAADR)
//
// The pattern to match on is therefore
// Type ETH.DST
// ARP BROADCAST
// 06 08 -- ff ff ff ff ff ff -> ip checksum for theses bytes=f7f9
// in binary these poitions are:11 0000 0011 1111
// This is hex 303F->EPMM0=0x3f,EPMM1=0x30
//<2F><><EFBFBD>չ<EFBFBD><D5B9><EFBFBD><EFBFBD><EFBFBD>
//UCEN<45><4E><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9>λ
//<2F><>ANDOR = 1 ʱ<><CAB1>
//1 = Ŀ<><C4BF><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EBB1BE>MAC <20><>ַ<EFBFBD><D6B7>ƥ<EFBFBD><C6A5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݰ<EFBFBD><DDB0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//0 = <20><>ֹ<EFBFBD><D6B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//<2F><>ANDOR = 0 ʱ<><CAB1>
//1 = Ŀ<><C4BF><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EBB1BE>MAC <20><>ַƥ<D6B7><C6A5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݰ<EFBFBD><DDB0><EFBFBD><E1B1BB><EFBFBD><EFBFBD>
//0 = <20><>ֹ<EFBFBD><D6B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//CRCEN<45><4E><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>CRC У<><D0A3>ʹ<EFBFBD><CAB9>λ
//1 = <20><><EFBFBD><EFBFBD>CRC <20><>Ч<EFBFBD><D0A7><EFBFBD><EFBFBD><EFBFBD>ݰ<EFBFBD><DDB0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//0 = <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>CRC <20>Ƿ<EFBFBD><C7B7><EFBFBD>Ч
//PMEN<45><4E><EFBFBD><EFBFBD>ʽƥ<CABD><C6A5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9>λ
//<2F><>ANDOR = 1 ʱ<><CAB1>
//1 = <20><><EFBFBD>ݰ<EFBFBD><DDB0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϸ<EFBFBD>ʽƥ<CABD><C6A5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>򽫱<EFBFBD><F2BDABB1><EFBFBD><EFBFBD><EFBFBD>
//0 = <20><>ֹ<EFBFBD><D6B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//<2F><>ANDOR = 0 ʱ<><CAB1>
//1 = <20><><EFBFBD>ϸ<EFBFBD>ʽƥ<CABD><C6A5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݰ<EFBFBD><DDB0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//0 = <20><>ֹ<EFBFBD><D6B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
enc28j60Write(ERXFCON, ERXFCON_UCEN|ERXFCON_CRCEN|ERXFCON_PMEN);
enc28j60Write(EPMM0, 0x3f);
enc28j60Write(EPMM1, 0x30);
enc28j60Write(EPMCSL, 0xf9);
enc28j60Write(EPMCSH, 0xf7);
// do bank 2 stuff
// enable MAC receive
//bit 0 MARXEN<45><4E>MAC <20><><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9>λ
//1 = <20><><EFBFBD><EFBFBD>MAC <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݰ<EFBFBD>
//0 = <20><>ֹ<EFBFBD><D6B9><EFBFBD>ݰ<EFBFBD><DDB0><EFBFBD><EFBFBD><EFBFBD>
//bit 3 TXPAUS<55><53><EFBFBD><EFBFBD>ͣ<EFBFBD><CDA3><EFBFBD><EFBFBD>֡<EFBFBD><D6A1><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9>λ
//1 = <20><><EFBFBD><EFBFBD>MAC <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͣ<EFBFBD><CDA3><EFBFBD><EFBFBD>֡<EFBFBD><D6A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȫ˫<C8AB><CBAB>ģʽ<C4A3>µ<EFBFBD><C2B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƣ<EFBFBD>
//0 = <20><>ֹ<EFBFBD><D6B9>ͣ֡<CDA3><D6A1><EFBFBD><EFBFBD>
//bit 2 RXPAUS<55><53><EFBFBD><EFBFBD>ͣ<EFBFBD><CDA3><EFBFBD><EFBFBD>֡<EFBFBD><D6A1><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9>λ
//1 = <20><><EFBFBD><EFBFBD><EFBFBD>յ<EFBFBD><D5B5><EFBFBD>ͣ<EFBFBD><CDA3><EFBFBD><EFBFBD>֡ʱ<D6A1><CAB1><EFBFBD><EFBFBD>ֹ<EFBFBD><D6B9><EFBFBD>ͣ<EFBFBD><CDA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//0 = <20><><EFBFBD>Խ<EFBFBD><D4BD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD><EFBFBD>ͣ<EFBFBD><CDA3><EFBFBD><EFBFBD>֡
enc28j60Write(MACON1, MACON1_MARXEN|MACON1_TXPAUS|MACON1_RXPAUS);
// bring MAC out of reset
//<2F><>MACON2 <20>е<EFBFBD>MARST λ<><CEBB><EFBFBD>ʹMAC <20>˳<EFBFBD><CBB3><EFBFBD>λ״̬<D7B4><CCAC>
enc28j60Write(MACON2, 0x00);
// enable automatic padding to 60bytes and CRC operations
//bit 7-5 PADCFG2:PACDFG0<47><30><EFBFBD>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>CRC <20><><EFBFBD><EFBFBD>λ
//111 = <20><>0 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>֡<EFBFBD><D6A1>64 <20>ֽڳ<D6BD><DAB3><EFBFBD><EFBFBD><EFBFBD>׷<EFBFBD><D7B7>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>Ч<EFBFBD><D0A7>CRC
//110 = <20><><EFBFBD>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֡
//101 = MAC <20>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>8100h <20><><EFBFBD><EFBFBD><EFBFBD>ֶε<D6B6>VLAN Э<><D0AD>֡<EFBFBD><D6A1><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD>䵽64 <20>ֽڳ<D6BD><DAB3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//<2F><>VLAN ֡<><D6A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>60 <20>ֽڳ<D6BD><DAB3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ׷<D2AA><D7B7>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>Ч<EFBFBD><D0A7>CRC
//100 = <20><><EFBFBD>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֡
//011 = <20><>0 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>֡<EFBFBD><D6A1>64 <20>ֽڳ<D6BD><DAB3><EFBFBD><EFBFBD><EFBFBD>׷<EFBFBD><D7B7>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>Ч<EFBFBD><D0A7>CRC
//010 = <20><><EFBFBD>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֡
//001 = <20><>0 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>֡<EFBFBD><D6A1>60 <20>ֽڳ<D6BD><DAB3><EFBFBD><EFBFBD><EFBFBD>׷<EFBFBD><D7B7>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>Ч<EFBFBD><D0A7>CRC
//000 = <20><><EFBFBD>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֡
//bit 4 TXCRCEN<45><4E><EFBFBD><EFBFBD><EFBFBD><EFBFBD>CRC ʹ<><CAB9>λ
//1 = <20><><EFBFBD><EFBFBD>PADCFG<46><47><EFBFBD>Σ<EFBFBD>MAC<41><43><EFBFBD><EFBFBD><EFBFBD>ڷ<EFBFBD><DAB7><EFBFBD>֡<EFBFBD><D6A1>ĩβ׷<CEB2><D7B7>һ<EFBFBD><D2BB><EFBFBD><EFBFBD>Ч<EFBFBD><D0A7>CRC<52><43> <20><><EFBFBD><EFBFBD>PADCFG<46>涨Ҫ
//׷<><D7B7><EFBFBD><EFBFBD>Ч<EFBFBD><D0A7>CRC<52><43><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>뽫TXCRCEN <20><>1<EFBFBD><31>
//0 = MAC<41><43><EFBFBD><EFBFBD>׷<EFBFBD><D7B7>CRC<52><43> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>4 <20><><EFBFBD>ֽڣ<D6BD><DAA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ч<EFBFBD><D0A7>CRC <20>򱨸<EFBFBD><F2B1A8B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬<D7B4><CCAC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//bit 0 FULDPX<50><58>MAC ȫ˫<C8AB><CBAB>ʹ<EFBFBD><CAB9>λ
//1 = MAC<41><43><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȫ˫<C8AB><CBAB>ģʽ<C4A3>¡<EFBFBD> PHCON1.PDPXMD λ<><CEBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>1<EFBFBD><31>
//0 = MAC<41><43><EFBFBD><EFBFBD><EFBFBD>ڰ<EFBFBD>˫<EFBFBD><CBAB>ģʽ<C4A3>¡<EFBFBD> PHCON1.PDPXMD λ<><CEBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
enc28j60WriteOp(ENC28J60_BIT_FIELD_SET, MACON3, MACON3_PADCFG0|MACON3_TXCRCEN|MACON3_FRMLNEN|MACON3_FULDPX);
// set inter-frame gap (non-back-to-back)
//<2F><><EFBFBD>÷DZ<C3B7><C7B1>Ա<EFBFBD><D4B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD>ĵ<EFBFBD><C4B5>ֽ<EFBFBD>
//MAIPGL<47><4C> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><D3A6>ʹ<EFBFBD><CAB9>12h <20><><EFBFBD≯üĴ<C3BC><C4B4><EFBFBD><EFBFBD><EFBFBD>
//<2F><><EFBFBD><EFBFBD>ʹ<EFBFBD>ð<EFBFBD>˫<EFBFBD><CBAB>ģʽ<C4A3><CABD>Ӧ<EFBFBD><D3A6><EFBFBD>̷DZ<CCB7><C7B1>Ա<EFBFBD><D4B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//<2F>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD>ĸ<EFBFBD><C4B8>ֽ<EFBFBD>MAIPGH<47><48> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><D3A6>ʹ<EFBFBD><CAB9>0Ch
//<2F><><EFBFBD≯üĴ<C3BC><C4B4><EFBFBD><EFBFBD><EFBFBD>
enc28j60Write(MAIPGL, 0x12);
enc28j60Write(MAIPGH, 0x0C);
// set inter-frame gap (back-to-back)
//<2F><><EFBFBD>ñ<EFBFBD><C3B1>Ա<EFBFBD><D4B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD>MABBIPG<50><47><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9>
//ȫ˫<C8AB><CBAB>ģʽʱ<CABD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><D3A6>ʹ<EFBFBD><CAB9>15h <20><><EFBFBD≯üĴ<C3BC>
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD>ð<EFBFBD>˫<EFBFBD><CBAB>ģʽʱ<CABD><CAB1>ʹ<EFBFBD><CAB9>12h <20><><EFBFBD>б<EFBFBD><D0B1>̡<EFBFBD>
enc28j60Write(MABBIPG, 0x15);
// Set the maximum packet size which the controller will accept
// Do not send packets longer than MAX_FRAMELEN:
// <20><><EFBFBD><EFBFBD>֡<EFBFBD><D6A1><EFBFBD><EFBFBD> 1500
enc28j60Write(MAMXFLL, MAX_FRAMELEN&0xFF);
enc28j60Write(MAMXFLH, MAX_FRAMELEN>>8);
// do bank 3 stuff
// write MAC address
// NOTE: MAC address in ENC28J60 is byte-backward
enc28j60Write(MAADR5, macaddr[0]);
enc28j60Write(MAADR4, macaddr[1]);
enc28j60Write(MAADR3, macaddr[2]);
enc28j60Write(MAADR2, macaddr[3]);
enc28j60Write(MAADR1, macaddr[4]);
enc28j60Write(MAADR0, macaddr[5]);
//<2F><><EFBFBD><EFBFBD>PHYΪȫ˫<C8AB><CBAB> LEDBΪ<42><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
enc28j60PhyWrite(PHCON1, PHCON1_PDPXMD);
// no loopback of transmitted frames <20><>ֹ<EFBFBD><D6B9><EFBFBD><EFBFBD>
//HDLDIS<49><53>PHY <20><>˫<EFBFBD><CBAB><EFBFBD><EFBFBD><EFBFBD>ؽ<EFBFBD>ֹλ
//<2F><>PHCON1.PDPXMD = 1 <20><>PHCON1.PLOOPBK = 1 ʱ<><CAB1>
//<2F><>λ<EFBFBD>ɱ<EFBFBD><C9B1><EFBFBD><EFBFBD>ԡ<EFBFBD>
//<2F><>PHCON1.PDPXMD = 0 <20><>PHCON1.PLOOPBK = 0 ʱ<><CAB1>
//1 = Ҫ<><D2AA><EFBFBD>͵<EFBFBD><CDB5><EFBFBD><EFBFBD>ݽ<EFBFBD>ͨ<EFBFBD><CDA8>˫<EFBFBD><CBAB><EFBFBD>߽ӿڷ<D3BF><DAB7><EFBFBD>
//0 = Ҫ<><D2AA><EFBFBD>͵<EFBFBD><CDB5><EFBFBD><EFBFBD>ݻỷ<DDBB>ص<EFBFBD>MAC <20><>ͨ<EFBFBD><CDA8>˫<EFBFBD><CBAB><EFBFBD>߽ӿڷ<D3BF><DAB7><EFBFBD>
enc28j60PhyWrite(PHCON2, PHCON2_HDLDIS);
// switch to bank 0
//ECON1 <20>Ĵ<EFBFBD><C4B4><EFBFBD>
//<2F>Ĵ<EFBFBD><C4B4><EFBFBD>3-1 <20><>ʾΪECON1 <20>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڿ<EFBFBD><DABF><EFBFBD>
//ENC28J60 <20><><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD>ܡ<EFBFBD> ECON1 <20>а<EFBFBD><D0B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD>ܡ<EFBFBD><DCA1><EFBFBD>
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>DMA <20><><EFBFBD>ƺʹ<CDB4><E6B4A2>ѡ<EFBFBD><D1A1>λ<EFBFBD><CEBB>
enc28j60SetBank(ECON1);
// enable interrutps
//EIE<49><45> <20><>̫<EFBFBD><CCAB><EFBFBD>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD>
//bit 7 INTIE<49><45> ȫ<><C8AB>INT <20>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD>λ
//1 = <20><><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD><D0B6>¼<EFBFBD><C2BC><EFBFBD><EFBFBD><EFBFBD>INT <20><><EFBFBD><EFBFBD>
//0 = <20><>ֹ<EFBFBD><D6B9><EFBFBD><EFBFBD>INT <20><><EFBFBD>ŵĻ<C4BB><EEB6AF><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD>ձ<EFBFBD><D5B1><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD>ߵ<EFBFBD>ƽ<EFBFBD><C6BD>
//bit 6 PKTIE<49><45> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݰ<EFBFBD><DDB0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD>λ
//1 = <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݰ<EFBFBD><DDB0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
//0 = <20><>ֹ<EFBFBD><D6B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݰ<EFBFBD><DDB0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
enc28j60WriteOp(ENC28J60_BIT_FIELD_SET, EIE, EIE_INTIE|EIE_PKTIE);
// enable packet reception
//bit 2 RXEN<45><4E><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD><CAB9>λ
//1 = ͨ<><CDA8><EFBFBD><EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݰ<EFBFBD><DDB0><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD>ջ<EFBFBD><D5BB><EFBFBD><EFBFBD><EFBFBD>
//0 = <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>н<EFBFBD><D0BD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD>ݰ<EFBFBD>
enc28j60WriteOp(ENC28J60_BIT_FIELD_SET, ECON1, ECON1_RXEN);
if(enc28j60Read(MAADR5)== macaddr[0])
return 0;
else
return 1;
}
// read the revision of the chip:
unsigned char enc28j60getrev(void)
{
//<2F><>EREVID <20><>Ҳ<EFBFBD><EFBFBD>˰汾<CBB0><E6B1BE>Ϣ<EFBFBD><CFA2> EREVID <20><>һ<EFBFBD><D2BB>ֻ<EFBFBD><D6BB><EFBFBD><EFBFBD>
//<2F>ƼĴ<C6BC><C4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>5 λ<><CEBB>ʶ<EFBFBD><CAB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʶ<EFBFBD><CAB6><EFBFBD><EFBFBD><EFBFBD>ض<EFBFBD><D8B6><EFBFBD>Ƭ
//<2F>İ汾<C4B0><E6B1BE>
return(enc28j60Read(EREVID));
}
void enc28j60PacketSend(unsigned int len, unsigned char* packet)
{
// Set the write pointer to start of transmit buffer area
enc28j60Write(EWRPTL, TXSTART_INIT&0xFF);
enc28j60Write(EWRPTH, TXSTART_INIT>>8);
// Set the TXND pointer to correspond to the packet size given
enc28j60Write(ETXNDL, (TXSTART_INIT+len)&0xFF);
enc28j60Write(ETXNDH, (TXSTART_INIT+len)>>8);
// write per-packet control byte (0x00 means use macon3 settings)
enc28j60WriteOp(ENC28J60_WRITE_BUF_MEM, 0, 0x00);
// copy the packet into the transmit buffer
enc28j60WriteBuffer(len, packet);
// send the contents of the transmit buffer onto the network
enc28j60WriteOp(ENC28J60_BIT_FIELD_SET, ECON1, ECON1_TXRTS);
// Reset the transmit logic problem. See Rev. B4 Silicon Errata point 12.
if( (enc28j60Read(EIR) & EIR_TXERIF) )
{
enc28j60WriteOp(ENC28J60_BIT_FIELD_CLR, ECON1, ECON1_TXRTS);
}
}
// Gets a packet from the network receive buffer, if one is available.
// The packet will by headed by an ethernet header.
// maxlen The maximum acceptable length of a retrieved packet.
// packet Pointer where packet data should be stored.
// Returns: Packet length in bytes if a packet was retrieved, zero otherwise.
unsigned int enc28j60PacketReceive(unsigned int maxlen, unsigned char* packet)
{
unsigned int rxstat;
unsigned int len;
// check if a packet has been received and buffered
//if( !(enc28j60Read(EIR) & EIR_PKTIF) ){
// The above does not work. See Rev. B4 Silicon Errata point 6.
if( enc28j60Read(EPKTCNT) ==0 ) //<2F>յ<EFBFBD><D5B5><EFBFBD><EFBFBD><EFBFBD>̫<EFBFBD><CCAB><EFBFBD><EFBFBD><EFBFBD>ݰ<EFBFBD><DDB0><EFBFBD><EFBFBD><EFBFBD>
{
return(0);
}
// Set the read pointer to the start of the received packet <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8>
enc28j60Write(ERDPTL, (NextPacketPtr));
enc28j60Write(ERDPTH, (NextPacketPtr)>>8);
// read the next packet pointer
NextPacketPtr = enc28j60ReadOp(ENC28J60_READ_BUF_MEM, 0);
NextPacketPtr |= enc28j60ReadOp(ENC28J60_READ_BUF_MEM, 0)<<8;
// read the packet length (see datasheet page 43)<29><>ȡ<EFBFBD><C8A1><EFBFBD>ݰ<EFBFBD><DDB0><EFBFBD><EFBFBD><EFBFBD>
len = enc28j60ReadOp(ENC28J60_READ_BUF_MEM, 0);
len |= enc28j60ReadOp(ENC28J60_READ_BUF_MEM, 0)<<8;
len-=4; //remove the CRC count
// read the receive status (see datasheet page 43)<29><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬
rxstat = enc28j60ReadOp(ENC28J60_READ_BUF_MEM, 0);
rxstat |= enc28j60ReadOp(ENC28J60_READ_BUF_MEM, 0)<<8;
// limit retrieve length
if (len>maxlen-1)
{
len=maxlen-1;
}
// check CRC and symbol errors (see datasheet page 44, table 7-3):
// The ERXFCON.CRCEN is set by default. Normally we should not
// need to check this.
if ((rxstat & 0x80)==0)
{
// invalid
len=0;
}
else
{
// copy the packet from the receive buffer<65><72><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݰ<EFBFBD><DDB0><EFBFBD><EFBFBD>ջ<EFBFBD><D5BB><EFBFBD><EFBFBD><EFBFBD>
enc28j60ReadBuffer(len, packet);
}
// Move the RX read pointer to the start of the next received packet
// This frees the memory we just read out
enc28j60Write(ERXRDPTL, (NextPacketPtr));
enc28j60Write(ERXRDPTH, (NextPacketPtr)>>8);
// decrement the packet counter indicate we are done with this packet
enc28j60WriteOp(ENC28J60_BIT_FIELD_SET, ECON2, ECON2_PKTDEC);
return(len);
}

View File

@ -0,0 +1,273 @@
#ifndef __ENC28J60_H
#define __ENC28J60_H
#include "stm32l1xx.h"
#include "general_type.h"
// ENC28J60 Control Registers
// Control register definitions are a combination of address,
// bank number, and Ethernet/MAC/PHY indicator bits.
// - Register address (bits 0-4)
// - Bank number (bits 5-6)
// - MAC/PHY indicator (bit 7)
#define ADDR_MASK 0x1F
#define BANK_MASK 0x60
#define SPRD_MASK 0x80
// All-bank registers
#define EIE 0x1B
#define EIR 0x1C
#define ESTAT 0x1D
#define ECON2 0x1E
#define ECON1 0x1F
// Bank 0 registers
#define ERDPTL (0x00|0x00)
#define ERDPTH (0x01|0x00)
#define EWRPTL (0x02|0x00)
#define EWRPTH (0x03|0x00)
#define ETXSTL (0x04|0x00)
#define ETXSTH (0x05|0x00)
#define ETXNDL (0x06|0x00)
#define ETXNDH (0x07|0x00)
#define ERXSTL (0x08|0x00)
#define ERXSTH (0x09|0x00)
#define ERXNDL (0x0A|0x00)
#define ERXNDH (0x0B|0x00)
//ERXWRPTH:ERXWRPTL <20>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӳ<EFBFBD><D3B2><EFBFBD><EFBFBD>FIFO <20><>
//<2F><><EFBFBD>ĸ<EFBFBD>λ<EFBFBD><CEBB>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD>ֽڡ<D6BD> ָ<><D6B8><EFBFBD><EFBFBD>ֻ<EFBFBD><D6BB><EFBFBD>ģ<EFBFBD><C4A3>ڳ<EFBFBD>
//<2F><><EFBFBD><EFBFBD><EFBFBD>յ<EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD>ݰ<EFBFBD><DDB0><EFBFBD><EFBFBD><EFBFBD>Ӳ<EFBFBD><D3B2><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD>롣 ָ<><D6B8><EFBFBD><EFBFBD>
//<2F><><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>FIFO <20><>ʣ<EFBFBD><CAA3><EFBFBD>ռ<EFBFBD><D5BC>Ĵ<EFBFBD>С<EFBFBD><D0A1>
#define ERXRDPTL (0x0C|0x00)
#define ERXRDPTH (0x0D|0x00)
#define ERXWRPTL (0x0E|0x00)
#define ERXWRPTH (0x0F|0x00)
#define EDMASTL (0x10|0x00)
#define EDMASTH (0x11|0x00)
#define EDMANDL (0x12|0x00)
#define EDMANDH (0x13|0x00)
#define EDMADSTL (0x14|0x00)
#define EDMADSTH (0x15|0x00)
#define EDMACSL (0x16|0x00)
#define EDMACSH (0x17|0x00)
// Bank 1 registers
#define EHT0 (0x00|0x20)
#define EHT1 (0x01|0x20)
#define EHT2 (0x02|0x20)
#define EHT3 (0x03|0x20)
#define EHT4 (0x04|0x20)
#define EHT5 (0x05|0x20)
#define EHT6 (0x06|0x20)
#define EHT7 (0x07|0x20)
#define EPMM0 (0x08|0x20)
#define EPMM1 (0x09|0x20)
#define EPMM2 (0x0A|0x20)
#define EPMM3 (0x0B|0x20)
#define EPMM4 (0x0C|0x20)
#define EPMM5 (0x0D|0x20)
#define EPMM6 (0x0E|0x20)
#define EPMM7 (0x0F|0x20)
#define EPMCSL (0x10|0x20)
#define EPMCSH (0x11|0x20)
#define EPMOL (0x14|0x20)
#define EPMOH (0x15|0x20)
#define EWOLIE (0x16|0x20)
#define EWOLIR (0x17|0x20)
#define ERXFCON (0x18|0x20)
#define EPKTCNT (0x19|0x20)
// Bank 2 registers
#define MACON1 (0x00|0x40|0x80)
#define MACON2 (0x01|0x40|0x80)
#define MACON3 (0x02|0x40|0x80)
#define MACON4 (0x03|0x40|0x80)
#define MABBIPG (0x04|0x40|0x80)
#define MAIPGL (0x06|0x40|0x80)
#define MAIPGH (0x07|0x40|0x80)
#define MACLCON1 (0x08|0x40|0x80)
#define MACLCON2 (0x09|0x40|0x80)
#define MAMXFLL (0x0A|0x40|0x80)
#define MAMXFLH (0x0B|0x40|0x80)
#define MAPHSUP (0x0D|0x40|0x80)
#define MICON (0x11|0x40|0x80)
#define MICMD (0x12|0x40|0x80)
#define MIREGADR (0x14|0x40|0x80)
#define MIWRL (0x16|0x40|0x80)
#define MIWRH (0x17|0x40|0x80)
#define MIRDL (0x18|0x40|0x80)
#define MIRDH (0x19|0x40|0x80)
// Bank 3 registers
#define MAADR1 (0x00|0x60|0x80)
#define MAADR0 (0x01|0x60|0x80)
#define MAADR3 (0x02|0x60|0x80)
#define MAADR2 (0x03|0x60|0x80)
#define MAADR5 (0x04|0x60|0x80)
#define MAADR4 (0x05|0x60|0x80)
#define EBSTSD (0x06|0x60)
#define EBSTCON (0x07|0x60)
#define EBSTCSL (0x08|0x60)
#define EBSTCSH (0x09|0x60)
#define MISTAT (0x0A|0x60|0x80)
#define EREVID (0x12|0x60)
#define ECOCON (0x15|0x60)
#define EFLOCON (0x17|0x60)
#define EPAUSL (0x18|0x60)
#define EPAUSH (0x19|0x60)
// PHY registers
#define PHCON1 0x00
#define PHSTAT1 0x01
#define PHHID1 0x02
#define PHHID2 0x03
#define PHCON2 0x10
#define PHSTAT2 0x11
#define PHIE 0x12
#define PHIR 0x13
#define PHLCON 0x14
// ENC28J60 ERXFCON Register Bit Definitions
#define ERXFCON_UCEN 0x80
#define ERXFCON_ANDOR 0x40
#define ERXFCON_CRCEN 0x20
#define ERXFCON_PMEN 0x10
#define ERXFCON_MPEN 0x08
#define ERXFCON_HTEN 0x04
#define ERXFCON_MCEN 0x02
#define ERXFCON_BCEN 0x01
// ENC28J60 EIE Register Bit Definitions
#define EIE_INTIE 0x80
#define EIE_PKTIE 0x40
#define EIE_DMAIE 0x20
#define EIE_LINKIE 0x10
#define EIE_TXIE 0x08
#define EIE_WOLIE 0x04
#define EIE_TXERIE 0x02
#define EIE_RXERIE 0x01
// ENC28J60 EIR Register Bit Definitions
#define EIR_PKTIF 0x40
#define EIR_DMAIF 0x20
#define EIR_LINKIF 0x10
#define EIR_TXIF 0x08
#define EIR_WOLIF 0x04
#define EIR_TXERIF 0x02
#define EIR_RXERIF 0x01
// ENC28J60 ESTAT Register Bit Definitions
#define ESTAT_INT 0x80
#define ESTAT_LATECOL 0x10
#define ESTAT_RXBUSY 0x04
#define ESTAT_TXABRT 0x02
#define ESTAT_CLKRDY 0x01
// ENC28J60 ECON2 Register Bit Definitions
#define ECON2_AUTOINC 0x80
#define ECON2_PKTDEC 0x40
#define ECON2_PWRSV 0x20
#define ECON2_VRPS 0x08
// ENC28J60 ECON1 Register Bit Definitions
#define ECON1_TXRST 0x80
#define ECON1_RXRST 0x40
#define ECON1_DMAST 0x20
#define ECON1_CSUMEN 0x10
#define ECON1_TXRTS 0x08
#define ECON1_RXEN 0x04
#define ECON1_BSEL1 0x02
#define ECON1_BSEL0 0x01
// ENC28J60 MACON1 Register Bit Definitions
#define MACON1_LOOPBK 0x10
#define MACON1_TXPAUS 0x08
#define MACON1_RXPAUS 0x04
#define MACON1_PASSALL 0x02
#define MACON1_MARXEN 0x01
// ENC28J60 MACON2 Register Bit Definitions
#define MACON2_MARST 0x80
#define MACON2_RNDRST 0x40
#define MACON2_MARXRST 0x08
#define MACON2_RFUNRST 0x04
#define MACON2_MATXRST 0x02
#define MACON2_TFUNRST 0x01
// ENC28J60 MACON3 Register Bit Definitions
#define MACON3_PADCFG2 0x80
#define MACON3_PADCFG1 0x40
#define MACON3_PADCFG0 0x20
#define MACON3_TXCRCEN 0x10
#define MACON3_PHDRLEN 0x08
#define MACON3_HFRMLEN 0x04
#define MACON3_FRMLNEN 0x02
#define MACON3_FULDPX 0x01
// ENC28J60 MICMD Register Bit Definitions
#define MICMD_MIISCAN 0x02
#define MICMD_MIIRD 0x01
// ENC28J60 MISTAT Register Bit Definitions
#define MISTAT_NVALID 0x04
#define MISTAT_SCAN 0x02
#define MISTAT_BUSY 0x01
// ENC28J60 PHY PHCON1 Register Bit Definitions
#define PHCON1_PRST 0x8000
#define PHCON1_PLOOPBK 0x4000
#define PHCON1_PPWRSV 0x0800
#define PHCON1_PDPXMD 0x0100
// ENC28J60 PHY PHSTAT1 Register Bit Definitions
#define PHSTAT1_PFDPX 0x1000
#define PHSTAT1_PHDPX 0x0800
#define PHSTAT1_LLSTAT 0x0004
#define PHSTAT1_JBSTAT 0x0002
// ENC28J60 PHY PHCON2 Register Bit Definitions
#define PHCON2_FRCLINK 0x4000
#define PHCON2_TXDIS 0x2000
#define PHCON2_JABBER 0x0400
#define PHCON2_HDLDIS 0x0100
// ENC28J60 Packet Control Byte Bit Definitions
#define PKTCTRL_PHUGEEN 0x08
#define PKTCTRL_PPADEN 0x04
#define PKTCTRL_PCRCEN 0x02
#define PKTCTRL_POVERRIDE 0x01
// SPI operation codes
#define ENC28J60_READ_CTRL_REG 0x00
#define ENC28J60_READ_BUF_MEM 0x3A
#define ENC28J60_WRITE_CTRL_REG 0x40
#define ENC28J60_WRITE_BUF_MEM 0x7A
#define ENC28J60_BIT_FIELD_SET 0x80
#define ENC28J60_BIT_FIELD_CLR 0xA0
#define ENC28J60_SOFT_RESET 0xFF
// The RXSTART_INIT should be zero. See Rev. B4 Silicon Errata
// buffer boundaries applied to internal 8K ram
// the entire available packet buffer space is allocated
//
// start with recbuf at 0/
#define RXSTART_INIT 0x0
// receive buffer end
#define RXSTOP_INIT (0x1FFF-0x0600-1)
// start TX buffer at 0x1FFF-0x0600, pace for one full ethernet frame (~1500 bytes)
#define TXSTART_INIT (0x1FFF-0x0600)
// stp TX buffer at end of mem
#define TXSTOP_INIT 0x1FFF
//
// max frame length which the conroller will accept:
#define MAX_FRAMELEN 1500 // (note: maximum ethernet frame length would be 1518)
//#define MAX_FRAMELEN 600
#define ENC28J60_CS 4
#define ENC28J60_CSL() GPIOA->ODR &= ~(unsigned int)(1<<ENC28J60_CS);
#define ENC28J60_CSH() GPIOA->ODR |= (unsigned int)(1<<ENC28J60_CS);
//SPI1<49><31>ʼ<EFBFBD><CABC>
//void ENC28J60_Init(void);
unsigned char enc28j60ReadOp(unsigned char op, unsigned char address);
void enc28j60WriteOp(unsigned char op, unsigned char address, unsigned char data);
void enc28j60ReadBuffer(unsigned int len, unsigned char* data);
void enc28j60WriteBuffer(unsigned int len, unsigned char* data);
void enc28j60SetBank(unsigned char address);
unsigned char enc28j60Read(unsigned char address);
void enc28j60Write(unsigned char address, unsigned char data);
void enc28j60PhyWrite(unsigned char address, unsigned int data);
void enc28j60clkout(unsigned char clk);
u8 enc28j60Init(unsigned char* macaddr);
unsigned char enc28j60getrev(void);
void enc28j60PacketSend(unsigned int len, unsigned char* packet);
unsigned int enc28j60PacketReceive(unsigned int maxlen, unsigned char* packet);
//SPI1<49><31>дһ<D0B4>ֽ<EFBFBD><D6BD><EFBFBD><EFBFBD><EFBFBD>
//INT8U ENC28J60_ReadWrite(INT8U writedat);
#endif

View File

@ -0,0 +1,514 @@
#include "esp8266.h"
#include "usart.h"
#include "delay.h"
#include <stdarg.h>
#include "usart.h"
struct STRUCT_USART_Fram ESP8266_Fram_Record_Struct = { 0 }; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֡<EFBFBD><EFBFBD><E1B9B9>
void ESP8266_Init(u32 bound)
{
USART4_Configuration(bound);
}
//<2F><>ESP8266ģ<36><EFBFBD><E9B7A2>ATָ<54><D6B8>
// cmd <20><><EFBFBD><EFBFBD><EFBFBD>͵<EFBFBD>ָ<EFBFBD><D6B8>
// ack1,ack2;<3B>ڴ<EFBFBD><DAB4><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><D3A6>ΪNULL<4C><4C><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD>߼<EFBFBD><DFBC><EFBFBD>ϵ
// time <20>ȴ<EFBFBD><C8B4><EFBFBD>Ӧʱ<D3A6><CAB1>
//<2F><><EFBFBD><EFBFBD>1<EFBFBD><31><EFBFBD>ͳɹ<CDB3><C9B9><EFBFBD><30><CAA7>
bool ESP8266_Send_AT_Cmd(char *cmd,char *ack1,char *ack2,u32 time)
{ //ESP8266_Send_AT_Cmd ( cStr, "> ", 0, 1000 );
u8 i=0;
Usart4_ReceiveBuff_Clear();
if(strstr(ack2,"1"))
u4_printf("%s",cmd);
else u4_printf("%s\r\n",cmd);
//UART_PutStr(UART4,cmd);
//UART_PutStr(UART4,"\r\n");
if(ack1==0&&ack2==0) //<2F><><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
return true;
}
delay_ms(time); //<2F><>ʱ
delay_ms(10);
ESP8266_Fram_Record_Struct.Data_RX_BUF[ESP8266_Fram_Record_Struct.InfBit.FramLength ] = '\0';
if(ack1!=0&&ack2!=0)
{
i= ( ( bool ) strstr ( ESP8266_Fram_Record_Struct .Data_RX_BUF, ack1 ) ||
( bool ) strstr ( ESP8266_Fram_Record_Struct .Data_RX_BUF, ack2 ) );
return i;
}
else if( ack1 != 0 ) //strstr(s1,s2);<3B><><EFBFBD><EFBFBD>s2<73>Ƿ<EFBFBD>Ϊs1<73><31>һ<EFBFBD><D2BB><EFBFBD>֣<EFBFBD><D6A3>Ƿ<EFBFBD><C7B7>ظ<EFBFBD>λ<EFBFBD>ã<EFBFBD><C3A3><EFBFBD><EFBFBD>򷵻<EFBFBD>false<73><65><EFBFBD><EFBFBD>ǿ<EFBFBD><C7BF>ת<EFBFBD><D7AA>Ϊbool<6F><6C><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
i= ( ( bool ) strstr ( ESP8266_Fram_Record_Struct .Data_RX_BUF, ack1 ) ||
( bool ) strstr ( ESP8266_Fram_Record_Struct .Data_RX_BUF, ack2 ) );
return i;
}
else
i= ( ( bool ) strstr ( ESP8266_Fram_Record_Struct .Data_RX_BUF, ack1 ) ||
( bool ) strstr ( ESP8266_Fram_Record_Struct .Data_RX_BUF, ack2 ) );
return i;
}
//<2F><><EFBFBD>ͻָ<CDBB><D6B8><EFBFBD><EFBFBD><EFBFBD>Ĭ<EFBFBD><C4AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD>ģ<EEBDAB><C4A3><EFBFBD>ָ<EFBFBD><D6B8>ɳ<EFBFBD><C9B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
void ESP8266_AT_Test(void)
{
u16 count=0;
while(count < 100)
{
if(ESP8266_Send_AT_Cmd("AT+RESTORE","OK",NULL,500))
{
return;
}
++ count;
delay_ms(100);
}
}
//ѡ<><D1A1>ESP8266<36>Ĺ<EFBFBD><C4B9><EFBFBD>ģʽ
// enumMode ģʽ<C4A3><CABD><EFBFBD><EFBFBD>
//<2F>ɹ<EFBFBD><C9B9><EFBFBD><EFBFBD><EFBFBD>true<75><65>ʧ<EFBFBD>ܷ<EFBFBD><DCB7><EFBFBD>false
bool ESP8266_Net_Mode_Choose(ENUM_Net_ModeTypeDef enumMode)
{
switch ( enumMode )
{
case STA:
return ESP8266_Send_AT_Cmd ( "AT+CWMODE=1", "OK", "NULL", 2500 );
case AP:
return ESP8266_Send_AT_Cmd ( "AT+CWMODE=2", "OK", "NULL", 2500 );
case STA_AP:
return ESP8266_Send_AT_Cmd ( "AT+CWMODE=3", "OK", "NULL", 2500 );
default:
return false;
}
}
//ESP8266<36><36><EFBFBD><EFBFBD><EFBFBD>ⲿ<EFBFBD><E2B2BF>WIFI
//pSSID WiFi<46>ʺ<EFBFBD>
//pPassWord WiFi<46><69><EFBFBD><EFBFBD>
//<2F><><EFBFBD>óɹ<C3B3><C9B9><EFBFBD><EFBFBD><EFBFBD>true <20><>֮false
bool ESP8266_JoinAP( char * pSSID, char * pPassWord)
{
char cCmd [120];
sprintf ( cCmd, "AT+CWJAP=\"%s\",\"%s\"", pSSID, pPassWord );
return ESP8266_Send_AT_Cmd( cCmd, "OK", NULL, 5000 );
}
//ESP8266 ͸<><CDB8>ʹ<EFBFBD><CAB9>
//enumEnUnvarnishTx <20>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӣ<EFBFBD>bool<6F><6C><EFBFBD><EFBFBD>
//<2F><><EFBFBD>óɹ<C3B3><C9B9><EFBFBD><EFBFBD><EFBFBD>true<75><65><EFBFBD><EFBFBD>֮false
bool ESP8266_Enable_MultipleId (FunctionalState enumEnUnvarnishTx )
{
char cStr [20];
sprintf ( cStr, "AT+CIPMUX=%d", ( enumEnUnvarnishTx ? 1 : 0 ) );
return ESP8266_Send_AT_Cmd ( cStr, "OK", 0, 500 );
}
//ESP8266 <20><><EFBFBD>ӷ<EFBFBD><D3B7><EFBFBD><EFBFBD><EFBFBD>
//enumE <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//ip <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>IP
//ComNum <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˿<EFBFBD>
//id<69><64><EFBFBD><EFBFBD><EFBFBD>Ӻţ<D3BA>ȷ<EFBFBD><C8B7>ͨ<EFBFBD>Ų<EFBFBD><C5B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//<2F><><EFBFBD>óɹ<C3B3><C9B9><EFBFBD><EFBFBD><EFBFBD>true<75><65><EFBFBD><EFBFBD>֮fasle
bool ESP8266_Link_Server(ENUM_NetPro_TypeDef enumE, char * ip, char * ComNum)
{
char cStr [100] = { 0 }; //cCmd [120];
switch ( enumE )
{
case enumTCP:
sprintf ( cStr, "\"%s\",\"%s\",%s", "TCP", ip, ComNum );
break;
case enumUDP:
sprintf ( cStr, "\"%s\",\"%s\",%s", "UDP", ip, ComNum );
break;
default:
break;
}
// if ( id < 5 )
// sprintf ( cCmd, "AT+CIPSTART=%d,%s", id, cStr);
// else
// sprintf ( cCmd, "AT+CIPSTART=%s", cStr );
return ESP8266_Send_AT_Cmd ( cStr, "OK", "NULL", 10000 );
}
//<2F><><EFBFBD><EFBFBD>AP<41><50><EFBFBD><EFBFBD>
//<2F><><EFBFBD>óɹ<C3B3><C9B9><EFBFBD><EFBFBD><EFBFBD>true<75><65> <20><>֮false
//SSID<49><44>WiFi<46><69><EFBFBD><EFBFBD> PWD<57><44><EFBFBD><EFBFBD><EFBFBD><EFBFBD> CHL<48><4C><EFBFBD>ŵ<EFBFBD> ECN<43><4E><EFBFBD><EFBFBD><EFBFBD>ܷ<EFBFBD>ʽ һ<><D2BB>ѡ<EFBFBD><D1A1>3 WPA2_PSK
bool ESP8266_CWSAP_Set ( char * SSID, char * PWD,char CHL, char ECN )
{
char cStr [100] = { 0 },cStr0 [100] = { 0 };
sprintf(cStr0,"\"%s\",\"%s\",%d,%d",SSID,PWD,CHL,ECN);
sprintf ( cStr, "%s%s", "AT+CWSAP_DEF=", cStr0);
if (!ESP8266_Send_AT_Cmd ( cStr, "OK", 0, 5000 ))
return false;
else return true;
}
//<2F><><EFBFBD><EFBFBD>tcp<63><70><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//<2F><><EFBFBD>óɹ<C3B3><C9B9><EFBFBD><EFBFBD><EFBFBD>true<75><65> <20><>֮false
bool ESP8266_Server_Create ( char * Port, FunctionalState Dis_En )
{
char cStr [100] = { 0 },cStr0 [100] = { 0 };
sprintf(cStr0,"%d,%s",Dis_En,Port);
sprintf ( cStr, "%s%s", "AT+CIPSERVER=", cStr0);
if (!ESP8266_Send_AT_Cmd ( cStr, "OK", 0, 5000 ))
return false;
else return true;
}
////<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͻ<EFBFBD><CDBB>˷<EFBFBD><CBB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//void ESP8266_AP_TCPServer_SendData(char ID,char *data,u16 len)
//{
// char cStr [100] = { 0 },cStr0 [100] = { 0 };
//
// sprintf(cStr,"%s%d,%d","AT+CIPSEND=",ID,len);
// ESP8266_Send_AT_Cmd ( cStr, 0, 0, 200 );
// UART_PutStr(USART1,data);
//}
//͸<><CDB8>ʹ<EFBFBD><CAB9>
//<2F><><EFBFBD>óɹ<C3B3><C9B9><EFBFBD><EFBFBD><EFBFBD>true<75><65> <20><>֮false
bool ESP8266_UnvarnishSend ( void )
{
if (!ESP8266_Send_AT_Cmd ( "AT+CIPMODE=1", "OK", 0, 500 ))
return false;
return
ESP8266_Send_AT_Cmd( "AT+CIPSEND", "OK", ">", 500 );
}
//ESP8266<36><36><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>
//enumEnUnvarnishTx<54>Ƿ<EFBFBD>ʹ<EFBFBD><CAB9>͸<EFBFBD><CDB8>ģʽ
//pStr<74>ַ<EFBFBD><D6B7><EFBFBD>
//ulStrLength<74>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//ucId <20><><EFBFBD>Ӻ<EFBFBD>
//<2F><><EFBFBD>óɹ<C3B3><C9B9><EFBFBD><EFBFBD><EFBFBD>true<75><65> <20><>֮false
bool ESP8266_SendString(FunctionalState enumEnUnvarnishTx, char * pStr, u32 ulStrLength, char ucId )
{
char cStr [20];
bool bRet = false;
if ( enumEnUnvarnishTx )
{
u4_printf ( "%s", pStr );
bRet = true;
}
else
{
if ( ucId < 5 )
sprintf ( cStr, "AT+CIPSEND=%d,%d", ucId, ulStrLength );
else
sprintf ( cStr, "AT+CIPSEND=%d", ulStrLength + 2 );
ESP8266_Send_AT_Cmd ( cStr, "> ", 0, 200 );
bRet = ESP8266_Send_AT_Cmd ( pStr, "SEND OK", "1", 200 );
}
return bRet;
}
//ESP8266<36>˳<EFBFBD>͸<EFBFBD><CDB8>ģʽ
void ESP8266_ExitUnvarnishSend ( void )
{
delay_ms(1000);
u5_printf( "+++" );
delay_ms( 500 );
}
//ESP8266 <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬
//<2F><><EFBFBD><EFBFBD>0<EFBFBD><30><EFBFBD><EFBFBD>ȡ״̬ʧ<CCAC><CAA7>
//<2F><><EFBFBD><EFBFBD>2<EFBFBD><32><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ip <20><><EFBFBD><EFBFBD><EFBFBD>˷<EFBFBD><CBB7><EFBFBD><EFBFBD><EFBFBD>
//<2F><><EFBFBD><EFBFBD>3<EFBFBD><33><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//<2F><><EFBFBD><EFBFBD>4<EFBFBD><34>ʧȥ<CAA7><C8A5><EFBFBD><EFBFBD>
u8 ESP8266_Get_LinkStatus ( void )
{
if (ESP8266_Send_AT_Cmd( "AT+CIPSTATUS", "+CIPSTATUS:0", 0, 500 ) )
{
/* if ( strstr ( ESP8266_Fram_Record_Struct .Data_RX_BUF, "TCP" ) )
return 2;
else if ( strstr ( ESP8266_Fram_Record_Struct .Data_RX_BUF, "STATUS:3\r\n" ) )
return 3;
else if ( strstr ( ESP8266_Fram_Record_Struct .Data_RX_BUF, "STATUS:4\r\n" ) )
return 4;
<EFBFBD>ò<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>WiFi<EFBFBD>Ƿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӣ<EFBFBD>
*/ if ( strstr ( ESP8266_Fram_Record_Struct .Data_RX_BUF, "+CIPSTATUS:0" ) )
return 2;//WIFI<46>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӿͻ<D3BF><CDBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
}
return 0;
}
static char *itoa( int value, char *string, int radix )
{
int i, d;
int flag = 0;
char *ptr = string;
/* This implementation only works for decimal numbers. */
if (radix != 10)
{
*ptr = 0;
return string;
}
if (!value)
{
*ptr++ = 0x30;
*ptr = 0;
return string;
}
/* if this is a negative value insert the minus sign. */
if (value < 0)
{
*ptr++ = '-';
/* Make the value positive. */
value *= -1;
}
for (i = 10000; i > 0; i /= 10)
{
d = value / i;
if (d || flag)
{
*ptr++ = (char)(d + 0x30);
value -= (d * i);
flag = 1;
}
}
/* Null terminate the string. */
*ptr = 0;
return string;
} /* NCL_Itoa */
void USART_printf ( USART_TypeDef * USARTx, char * Data, ... )
{
const char *s;
int d;
char buf[16];
va_list ap;
va_start(ap, Data);
while ( * Data != 0 ) // <20>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ񵽴<C7B7><F1B5BDB4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
if ( * Data == 0x5c ) //'\'
{
switch ( *++Data )
{
case 'r': //<2F>س<EFBFBD><D8B3><EFBFBD>
USART_SendData(USARTx, 0x0d);
Data ++;
break;
case 'n': //<2F><><EFBFBD>з<EFBFBD>
USART_SendData(USARTx, 0x0a);
Data ++;
break;
default:
Data ++;
break;
}
}
else if ( * Data == '%')
{
switch ( *++Data )
{
case 's': //<2F>ַ<EFBFBD><D6B7><EFBFBD>
s = va_arg(ap, const char *);
for ( ; *s; s++)
{
USART_SendData(USARTx,*s);
while( USART_GetFlagStatus(USARTx, USART_FLAG_TXE) == RESET );
}
Data++;
break;
case 'd':
//ʮ<><CAAE><EFBFBD><EFBFBD>
d = va_arg(ap, int);
itoa(d, buf, 10);
for (s = buf; *s; s++)
{
USART_SendData(USARTx,*s);
while( USART_GetFlagStatus(USARTx, USART_FLAG_TXE) == RESET );
}
Data++;
break;
default:
Data++;
break;
}
}
else USART_SendData(USARTx, *Data++);
while ( USART_GetFlagStatus ( USARTx, USART_FLAG_TXE ) == RESET );
}
}
//<2F><><EFBFBD><EFBFBD>ΪESP8266MQTT<54><54><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8>
/*
*MQTT<54><54><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD>
*LinkID <20><><EFBFBD><EFBFBD>ID,Ŀǰֻ֧<D6BB><D6A7>0
*scheme <20><><EFBFBD>ӷ<EFBFBD>ʽ<EFBFBD><CABD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1>MQTT over TCP,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ1
*client_id MQTTclientID <20><><EFBFBD>ڱ<EFBFBD>־client<6E><74><EFBFBD><EFBFBD>
*username <20><><EFBFBD>ڵ<EFBFBD>¼ MQTT <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> username
*password <20><><EFBFBD>ڵ<EFBFBD>¼ MQTT <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><> password
*cert_key_ID ֤<><D6A4> ID, Ŀǰ֧<C7B0><D6A7>һ<EFBFBD><D2BB> cert ֤<><D6A4>, <20><><EFBFBD><EFBFBD>Ϊ 0
*CA_ID Ŀǰ֧<C7B0><D6A7>һ<EFBFBD><D2BB> CA ֤<><D6A4>, <20><><EFBFBD><EFBFBD>Ϊ 0
*path <20><>Դ·<D4B4><C2B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ""
*<2A><><EFBFBD>óɹ<C3B3><C9B9><EFBFBD><EFBFBD><EFBFBD>true <20><>֮false
*/
bool ESP8266_MQTTUSERCFG( char * pClient_Id, char * pUserName,char * PassWord)
{
char cCmd [120];
sprintf ( cCmd, "AT+MQTTUSERCFG=0,1,\"%s\",\"%s\",\"%s\",0,0,\"\"", pClient_Id,pUserName,PassWord );
return ESP8266_Send_AT_Cmd( cCmd, "OK", NULL, 500 );
}
/*
*<2A><><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD>MQTT<54><54><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*LinkID <20><><EFBFBD><EFBFBD>ID,Ŀǰֻ֧<D6BB><D6A7>0
*IP<49><50>MQTT<54><54><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>϶<EFBFBD>Ӧ<EFBFBD><D3A6>IP<49><50>ַ
*ComNum MQTT<54><54><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>϶<EFBFBD>Ӧ<EFBFBD>Ķ˿ںţ<DABA>һ<EFBFBD><D2BB>Ϊ1883
*<2A><><EFBFBD>óɹ<C3B3><C9B9><EFBFBD><EFBFBD><EFBFBD>true <20><>֮false
*/
bool ESP8266_MQTTCONN( char * Ip, int Num)
{
char cCmd [120];
sprintf ( cCmd,"AT+MQTTCONN=0,\"%s\",%d,0", Ip,Num);
return ESP8266_Send_AT_Cmd( cCmd, "OK", NULL, 500 );
}
/*
*<2A><><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD>ӵ<EFBFBD> MQTT <20><><EFBFBD><EFBFBD>, <20><><EFBFBD>ظ<EFBFBD><D8B8><EFBFBD><EFBFBD>ζ<EFBFBD><CEB6>IJ<EFBFBD>ͬ topic
*LinkID <20><><EFBFBD><EFBFBD>ID,Ŀǰֻ֧<D6BB><D6A7>0
*Topic <20><><EFBFBD>ĵ<EFBFBD><C4B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֣<EFBFBD><D6A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ΪTopic
*Qosֵ<73><D6B5>һ<EFBFBD><D2BB>Ϊ0<CEAA><30><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ1
*<2A><><EFBFBD>óɹ<C3B3><C9B9><EFBFBD><EFBFBD><EFBFBD>true <20><>֮false
*/
bool ESP8266_MQTTSUB(char * Topic)
{
char cCmd [120];
sprintf ( cCmd, "AT+MQTTSUB=0,\"%s\",1",Topic );
return ESP8266_Send_AT_Cmd( cCmd, "OK", NULL, 500 );
}
/*
*<2A><>LinkID<49><44>ͨ<EFBFBD><CDA8> topic <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> data, <20><><EFBFBD><EFBFBD> data Ϊ<>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD>Ϣ
*LinkID <20><><EFBFBD><EFBFBD>ID,Ŀǰֻ֧<D6BB><D6A7>0
*Topic <20><><EFBFBD>ĵ<EFBFBD><C4B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֣<EFBFBD><D6A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ΪTopic
*data<74><61><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD>Ϣ
*<2A><><EFBFBD>óɹ<C3B3><C9B9><EFBFBD><EFBFBD><EFBFBD>true <20><>֮false
*/
bool ESP8266_MQTTPUB( char * Topic,char *temp)
{
char cCmd [120];
sprintf (cCmd, "AT+MQTTPUB=0,\"%s\",\"%s\",1,0", Topic ,temp);
return ESP8266_Send_AT_Cmd( cCmd, "OK", NULL, 1000 );
}
/*
*<2A>ر<EFBFBD> MQTT Client Ϊ LinkID <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>, <20><><EFBFBD>ͷ<EFBFBD><CDB7>ڲ<EFBFBD>ռ<EFBFBD>õ<EFBFBD><C3B5><EFBFBD>Դ
*LinkID <20><><EFBFBD><EFBFBD>ID,Ŀǰֻ֧<D6BB><D6A7>0
*Topic <20><><EFBFBD>ĵ<EFBFBD><C4B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֣<EFBFBD><D6A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ΪTopic
*data<74><61><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD>Ϣ
*<2A><><EFBFBD>óɹ<C3B3><C9B9><EFBFBD><EFBFBD><EFBFBD>true <20><>֮false
*/
bool ESP8266_MQTTCLEAN(void)
{
char cCmd [120];
sprintf ( cCmd, "AT+MQTTCLEAN=0");
return ESP8266_Send_AT_Cmd( cCmd, "OK", NULL, 500 );
}
//ESP8266<36><36><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>
//enumEnUnvarnishTx<54>Ƿ<EFBFBD>ʹ<EFBFBD><CAB9>͸<EFBFBD><CDB8>ģʽ
//pStr<74>ַ<EFBFBD><D6B7><EFBFBD>
//ulStrLength<74>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//ucId <20><><EFBFBD>Ӻ<EFBFBD>
//<2F><><EFBFBD>óɹ<C3B3><C9B9><EFBFBD><EFBFBD><EFBFBD>true<75><65> <20><>֮false
bool MQTT_SendString(char * pTopic,char *temp2)
{
bool bRet = false;
ESP8266_MQTTPUB(pTopic,temp2);
delay_ms(1000);
bRet = true;
return bRet;
}
void ESP8266_Fram_Record_Struct_Clear(void)
{
memset(ESP8266_Fram_Record_Struct.Data_RX_BUF,0,RX_BUF_MAX_LEN);
ESP8266_Fram_Record_Struct.InfBit.FramFinishFlag=0;
ESP8266_Fram_Record_Struct.InfBit.FramLength=0;
}

View File

@ -0,0 +1,89 @@
#ifndef __ESP8266_H
#define __ESP8266_H
#include "stm32l1xx.h"
#include "pbdata.h"
#include "bsp.h"
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#if defined ( __CC_ARM )
#pragma anon_unions
#endif
//ESP8266ģʽѡ<CABD><D1A1>
typedef enum
{
STA,
AP,
STA_AP
}ENUM_Net_ModeTypeDef;
//<2F><><EFBFBD><EFBFBD><E7B4AB><EFBFBD><EFBFBD>Э<EFBFBD>飬ö<E9A3AC><C3B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
typedef enum{
enumTCP,
enumUDP,
} ENUM_NetPro_TypeDef;
//<2F><><EFBFBD>Ӻţ<D3BA>ָ<EFBFBD><D6B8>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD>Ӻſ<D3BA><C5BF>Է<EFBFBD>ֹ<EFBFBD><D6B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬһ<CDAC>˿ڶ<CBBF><DAB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
typedef enum{
Multiple_ID_0 = 0,
Multiple_ID_1 = 1,
Multiple_ID_2 = 2,
Multiple_ID_3 = 3,
Multiple_ID_4 = 4,
Single_ID_0 = 5,
} ENUM_ID_NO_TypeDef;
#define ESP8266_USART(fmt, ...) USART_printf (UART4, fmt, ##__VA_ARGS__)
#define PC_USART(fmt, ...) printf(fmt, ##__VA_ARGS__) //<2F><><EFBFBD>Ǵ<EFBFBD><C7B4>ڴ<EFBFBD>ӡ<EFBFBD><D3A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>1<EFBFBD><31>ִ<EFBFBD><D6B4>printf<74><66><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD>ִ<EFBFBD><D6B4>fput<75><74><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ض<EFBFBD><D8B6><EFBFBD><EFBFBD><EFBFBD>printf<74><66>
#define RX_BUF_MAX_LEN 200 //<2F><><EFBFBD><EFBFBD><EFBFBD>ֽ<EFBFBD><D6BD><EFBFBD>
extern struct STRUCT_USART_Fram //<2F><><EFBFBD><EFBFBD>֡<EFBFBD><EFBFBD><E1B9B9>
{
char Data_RX_BUF[RX_BUF_MAX_LEN];
union
{
__IO u16 InfAll;
struct
{
__IO u16 FramLength :15; // 14:0
__IO u16 FramFinishFlag :1; // 15
}InfBit;
};
}ESP8266_Fram_Record_Struct;
//<2F><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>TCP<43><50><EFBFBD>ܺ<EFBFBD><DCBA><EFBFBD>
void ESP8266_Init(u32 bound);
void ESP8266_AT_Test(void);
bool ESP8266_Send_AT_Cmd(char *cmd,char *ack1,char *ack2,u32 time);
//void ESP8266_Rst(void);
bool ESP8266_Net_Mode_Choose(ENUM_Net_ModeTypeDef enumMode);
bool ESP8266_JoinAP( char * pSSID, char * pPassWord );
bool ESP8266_Enable_MultipleId ( FunctionalState enumEnUnvarnishTx );
bool ESP8266_Link_Server(ENUM_NetPro_TypeDef enumE, char * ip, char * ComNum);
bool ESP8266_SendString(FunctionalState enumEnUnvarnishTx, char * pStr, u32 ulStrLength, char ucId );
bool ESP8266_UnvarnishSend ( void );
void ESP8266_ExitUnvarnishSend ( void );
void ESP8266_Fram_Record_Struct_Clear(void);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
u8 ESP8266_Get_LinkStatus ( void );
void USART_printf( USART_TypeDef * USARTx, char * Data, ... );
bool ESP8266_CWSAP_Set ( char * SSID, char * PWD,char CHL, char ECN );
bool ESP8266_Server_Create ( char * Port, FunctionalState Dis_En );
//MQTT<54><54><EFBFBD>ܺ<EFBFBD><DCBA><EFBFBD>
bool ESP8266_MQTTUSERCFG( char * pClient_Id, char * pUserName,char * PassWord);
bool ESP8266_MQTTCONN( char * Ip, int Num);
bool ESP8266_MQTTSUB(char * Topic);
bool ESP8266_MQTTPUB( char * Topic,char *temp);
bool ESP8266_MQTTCLEAN(void);
bool MQTT_SendString(char * pTopic,char *temp2);
#endif

View File

@ -0,0 +1,189 @@
#include "tcp.h"
#include "esp8266.h"
//volatile u8 TcpClosedFlag = 0;
/*
void ESP8266_STA_TCPClient_Test(void)
{
u8 res;
char str[100]={0};
ESP8266_AT_Test();
ESP8266_Net_Mode_Choose(STA);
while(!ESP8266_JoinAP(User_ESP8266_SSID, User_ESP8266_PWD));
ESP8266_Enable_MultipleId ( DISABLE );
while(!ESP8266_Link_Server(enumTCP, User_ESP8266_TCPServer_IP, User_ESP8266_TCPServer_PORT));
while(!ESP8266_UnvarnishSend());
while ( 1 )
{
sprintf (str,"<22><><EFBFBD><EFBFBD><EFBFBD>а<EFBFBD><D0B0>ſɿƼ<C9BF><C6BC><EFBFBD><EFBFBD>޹<EFBFBD>˾" );//<2F><>ʽ<EFBFBD><CABD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD>TCP<43><50><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//ESP8266_SendString ( ENABLE, str, 0, Single_ID_0 );
UART_PutStr(USART1,str);
delay_ms(1000);
if(TcpClosedFlag) //<2F>ж<EFBFBD><D0B6>Ƿ<EFBFBD>ʧȥ<CAA7><C8A5><EFBFBD><EFBFBD>
{
ESP8266_ExitUnvarnishSend(); //<2F>˳<EFBFBD>͸<EFBFBD><CDB8>ģʽ
do
{
res = ESP8266_Get_LinkStatus(); //<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>״̬
}
while(!res);
if(res != 3) //if(res == 4) ȷ<><C8B7>ʧȥ<CAA7><C8A5><EFBFBD>ӣ<EFBFBD><D3A3><EFBFBD><EFBFBD><EFBFBD>
{
while (!ESP8266_JoinAP(User_ESP8266_SSID, User_ESP8266_PWD ) );
while (!ESP8266_Link_Server(enumTCP, User_ESP8266_TCPServer_IP, User_ESP8266_TCPServer_PORT) );
}
while(!ESP8266_UnvarnishSend());
}
}
}
*/
//void ESP8266_SendStr(char *str)
//{
// u8 res=0;
// do
// {
// res = ESP8266_Get_LinkStatus(); //<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>״̬
// } while(!res);
// if(res != 3) //if(res == 4) ȷ<><C8B7>ʧȥ<CAA7><C8A5><EFBFBD>ӣ<EFBFBD><D3A3><EFBFBD><EFBFBD><EFBFBD>
// {
//
// ESP8266_Net_Mode_Choose(STA);
// while (!ESP8266_JoinAP(User_ESP8266_SSID, User_ESP8266_PWD ) );
// while (!ESP8266_Link_Server(enumTCP, User_ESP8266_TCPServer_IP, User_ESP8266_TCPServer_PORT) );
// }
// while(!ESP8266_UnvarnishSend());
// UART_PutStr(USART1,str);
//
//}
void ESP8266_AP_TCPServer_Config(char *ssid,char *pwd,char *port)
{
u8 i=0;
// ESP8266_Send_AT_Cmd("AT+RESTORE","ready",NULL,500);
PWR_CTRLTFWF_L;
// PWR_CTRL3V3_L;
delay_ms(1000);
PWR_CTRLTFWF_H;
// PWR_CTRL3V3_H;
delay_ms(1000);
ESP8266_AT_Test();//<2F>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
while((!ESP8266_Send_AT_Cmd("ATE0","OK",NULL,500))&(i<100))
{
i++;
}
i=0;
while((!ESP8266_CWSAP_Set ( ssid, pwd,5, 3 ))&(i<100))
{
i++;
}
i=0;
while((!ESP8266_Net_Mode_Choose(AP))&(i<100))
{
i++;
}
i=0;
while((!ESP8266_Enable_MultipleId ( ENABLE ))&(i<10))
{
i++;
}
i=0;
while((!ESP8266_Server_Create( port,ENABLE ))&(i<100))
{
i++;
}
}
/*void Parse_ESP8266_Buffer(void)
{
char *subString;
char *subStringNext;
char i = 0;
clear_Init_Data_Equipment();
for (i = 0 ; i <= 9 ; i++)
{
if (i == 0)
{
subString = strstr(ESP8266_Fram_Record_Struct.Data_RX_BUF, "CMD");
subString++;
subString++;
subString++;//<2F>ҵ<EFBFBD><D2B5><EFBFBD><EFBFBD><EFBFBD>ַ
}
else
{
subString++;
if ((subStringNext = strstr(subString, ",")) != NULL)
{
switch(i)
{
case 1:memcpy(Init_Data_Equipment.Bc25_Ip, subString, subStringNext - subString);break; //<2F><>ȡUTCʱ<43><CAB1>
case 2:memcpy(Init_Data_Equipment.Bc25_Port, subString, subStringNext - subString);break; //<2F><>ȡUTCʱ<43><CAB1>
case 3:memcpy(Init_Data_Equipment.ESP8266_AP_Ports, subString, subStringNext - subString);break; //<2F><>ȡγ<C8A1><CEB3><EFBFBD><EFBFBD>Ϣ
case 4:memcpy(Init_Data_Equipment.ESP8266_AP_SSIDs, subString, subStringNext - subString);break; //<2F><>ȡN/S
case 5:memcpy(Init_Data_Equipment.ESP8266_AP_PWDs, subString, subStringNext - subString);break; //<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
case 6:memcpy(Init_Data_Equipment.Measure_Interval, subString, subStringNext - subString);break; //<2F><>ȡE/W
case 7:memcpy(Init_Data_Equipment.Pub_Mode, subString, subStringNext - subString);break; //<2F><>ȡE/W
case 8:memcpy(Init_Data_Equipment.Pub_Time, subString, subStringNext - subString);break; //<2F><>ȡE/W
case 9:memcpy(Init_Data_Equipment.Equipment_ID, subString, subStringNext - subString);break; //<2F><>ȡE/W
default:break;
}
subString = subStringNext;
}
else
{
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
}
}
}
Usart4_ReceiveBuff_Clear();
}
*/
void WIFI_Process(void)
{
u8 times=0;
ESP8266_Init(115200);
ESP8266_AP_TCPServer_Config(Init_Data_Equipment.ESP8266_AP_SSIDs,
Init_Data_Equipment.ESP8266_AP_PWDs,
Init_Data_Equipment.ESP8266_AP_Ports);
while(times<60) //60S<30>ȴ<EFBFBD><C8B4>ⲿ<EFBFBD><E2B2BF><EFBFBD><EFBFBD>WIFI
{
times++;
osDelay(1000);
if(ESP8266_Get_LinkStatus()==2)times=61;
}
}

View File

@ -0,0 +1,26 @@
#ifndef __TCP_H
#define __TCP_H
#include "stm32l1xx.h"
#include "bsp.h"
/*
*<2A><><EFBFBD>²<EFBFBD><C2B2><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>޸IJ<DEB8><C4B2>ܲ<EFBFBD><DCB2><EFBFBD><EFBFBD>ù<EFBFBD>
*/
//<2F><><EFBFBD><EFBFBD>STAģʽ<C4A3><CABD><EFBFBD><EFBFBD>
//#define User_ESP8266_SSID "502_2.4G"
//#define User_ESP8266_PWD "licahk*******" //wifi<66><69><EFBFBD><EFBFBD>
//#define User_ESP8266_PWD "shbh03302"
//#define User_ESP8266_TCPServer_IP "192.168.9.61" //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>IP
//#define User_ESP8266_TCPServer_PORT "8080" //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˿ں<CBBF>
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>IJ<EFBFBD><C4B2><EFBFBD>
//#define ESP8266_AP_Port "8080"
//#define ESP8266_AP_SSID "lica_esp8266"
//#define ESP8266_AP_PWD "12345678"
//extern volatile uint8_t TcpClosedFlag; //<2F><><EFBFBD><EFBFBD>״̬<D7B4><CCAC>־
//void ESP8266_STA_TCPClient_Test(void);
void ESP8266_AP_TCPServer_Config(char *ssid,char *pwd,char *port);
//void Parse_ESP8266_Buffer(void);
void WIFI_Process(void);
#endif

View File

@ -0,0 +1,77 @@
#include "bsp.h"
#include "exti_io.h"
void WakeUp_EXIT_Config( void )
{
GPIO_InitTypeDef GPIO_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
EXTI_InitTypeDef EXTI_InitStructure;
//enable GPIOA Clock
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
// config PA10 as input floating
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN; //very import
GPIO_Init(GPIOA, &GPIO_InitStructure);
//enable syscfg clock
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
// connect EXTI0 line to PA0 pin
SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOA, EXTI_PinSource0);
//config EXTI10 Line
EXTI_InitStructure.EXTI_Line = EXTI_Line0;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
// enable and set EXTI0 interrupu to the lowest priority
NVIC_InitStructure.NVIC_IRQChannel = EXTI0_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x01;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x00;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
PWR_WakeUpPinCmd(PWR_WakeUpPin_1,ENABLE);
}
//<2F><><EFBFBD><EFBFBD>WKUP<55>ŵ<EFBFBD><C5B5>ź<EFBFBD>
//<2F><><EFBFBD><EFBFBD>ֵ1:<3A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>3s<33><73><EFBFBD><EFBFBD>
// 0:<3A><><EFBFBD><EFBFBD><EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD>
u8 Check_WKUP(void)
{
u8 t=0; //<2F><>¼<EFBFBD><C2BC><EFBFBD>µ<EFBFBD>ʱ<EFBFBD><CAB1>
while(1)
{
if(WKUP_KD)
{
t++; //<2F>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
delay_ms(30);
if(t>=100) //<2F><><EFBFBD>³<EFBFBD><C2B3><EFBFBD>3<EFBFBD><33><EFBFBD><EFBFBD>
{
return 1; //<2F><><EFBFBD><EFBFBD>3s<33><73><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
}
}else
{
return 0; //<2F><><EFBFBD>²<EFBFBD><C2B2><EFBFBD>3<EFBFBD><33>
}
}
}
void EXTI0_IRQHandler( void )
{
EXTI_ClearITPendingBit(EXTI_Line10); //Clear the EXTI line 10 pending bit
if(Check_WKUP()==0)//<2F>ػ<EFBFBD>?
{
Wake_Up_Flag=0;
PWR_EnterSTANDBYMode(); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>STANDBY<42><59>ģʽ
}else
{
Wake_Up_Flag=1;
}
}

View File

@ -0,0 +1,14 @@
#ifndef _exti_io_H
#define _exti_io_H
#include "bsp.h"
#include "stm32l1xx_exti.h"
#include "stm32l1xx_syscfg.h"
#define WKUP_KD PAin(0) //PA0 <20><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7>ⲿWK_UP<55><50><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
extern u8 Wake_Up_Flag;
u8 Check_WKUP(void);
void WakeUp_EXIT_Config( void );
#endif

View File

@ -0,0 +1,775 @@
/**************************************************************************//**
* @file core_cmInstr.h
* @brief CMSIS Cortex-M Core Instruction Access Header File
* @version V2.01
* @date 06. December 2010
*
* @note
* Copyright (C) 2009-2010 ARM Limited. All rights reserved.
*
* @par
* ARM Limited (ARM) is supplying this software for use with Cortex-M
* processor based microcontrollers. This file can be freely distributed
* within development tools that are supporting such ARM based processors.
*
* @par
* THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
* OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
* ARM SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR
* CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
*
******************************************************************************/
#ifndef __CORE_CMINSTR_H__
#define __CORE_CMINSTR_H__
/* ########################## Core Instruction Access ######################### */
/** \defgroup CMSIS_Core_InstructionInterface CMSIS Core Instruction Interface
Access to dedicated instructions
@{
*/
#if defined ( __CC_ARM ) /*------------------ RealView Compiler ----------------*/
/* ARM armcc specific functions */
/** \brief No Operation
No Operation does nothing. This instruction can be used for code alignment purposes.
*/
#define __NOP __nop
/** \brief Wait For Interrupt
Wait For Interrupt is a hint instruction that suspends execution
until one of a number of events occurs.
*/
#define __WFI __wfi
/** \brief Wait For Event
Wait For Event is a hint instruction that permits the processor to enter
a low-power state until one of a number of events occurs.
*/
#define __WFE __wfe
/** \brief Send Event
Send Event is a hint instruction. It causes an event to be signaled to the CPU.
*/
#define __SEV __sev
/** \brief Instruction Synchronization Barrier
Instruction Synchronization Barrier flushes the pipeline in the processor,
so that all instructions following the ISB are fetched from cache or
memory, after the instruction has been completed.
*/
#define __ISB() __isb(0xF)
/** \brief Data Synchronization Barrier
This function acts as a special kind of Data Memory Barrier.
It completes when all explicit memory accesses before this instruction complete.
*/
#define __DSB() __dsb(0xF)
/** \brief Data Memory Barrier
This function ensures the apparent order of the explicit memory operations before
and after the instruction, without ensuring their completion.
*/
#define __DMB() __dmb(0xF)
/** \brief Reverse byte order (32 bit)
This function reverses the byte order in integer value.
\param [in] value Value to reverse
\return Reversed value
*/
#define __REV __rev
/** \brief Reverse byte order (16 bit)
This function reverses the byte order in two unsigned short values.
\param [in] value Value to reverse
\return Reversed value
*/
#if (__ARMCC_VERSION < 400677)
extern uint32_t __REV16(uint32_t value);
#else /* (__ARMCC_VERSION >= 400677) */
static __INLINE __ASM uint32_t __REV16(uint32_t value)
{
rev16 r0, r0
bx lr
}
#endif /* __ARMCC_VERSION */
/** \brief Reverse byte order in signed short value
This function reverses the byte order in a signed short value with sign extension to integer.
\param [in] value Value to reverse
\return Reversed value
*/
#if (__ARMCC_VERSION < 400677)
extern int32_t __REVSH(int32_t value);
#else /* (__ARMCC_VERSION >= 400677) */
static __INLINE __ASM int32_t __REVSH(int32_t value)
{
revsh r0, r0
bx lr
}
#endif /* __ARMCC_VERSION */
#if (__CORTEX_M >= 0x03)
/** \brief Reverse bit order of value
This function reverses the bit order of the given value.
\param [in] value Value to reverse
\return Reversed value
*/
#define __RBIT __rbit
/** \brief LDR Exclusive (8 bit)
This function performs a exclusive LDR command for 8 bit value.
\param [in] ptr Pointer to data
\return value of type uint8_t at (*ptr)
*/
#define __LDREXB(ptr) ((uint8_t ) __ldrex(ptr))
/** \brief LDR Exclusive (16 bit)
This function performs a exclusive LDR command for 16 bit values.
\param [in] ptr Pointer to data
\return value of type uint16_t at (*ptr)
*/
#define __LDREXH(ptr) ((uint16_t) __ldrex(ptr))
/** \brief LDR Exclusive (32 bit)
This function performs a exclusive LDR command for 32 bit values.
\param [in] ptr Pointer to data
\return value of type uint32_t at (*ptr)
*/
#define __LDREXW(ptr) ((uint32_t ) __ldrex(ptr))
/** \brief STR Exclusive (8 bit)
This function performs a exclusive STR command for 8 bit values.
\param [in] value Value to store
\param [in] ptr Pointer to location
\return 0 Function succeeded
\return 1 Function failed
*/
#define __STREXB(value, ptr) __strex(value, ptr)
/** \brief STR Exclusive (16 bit)
This function performs a exclusive STR command for 16 bit values.
\param [in] value Value to store
\param [in] ptr Pointer to location
\return 0 Function succeeded
\return 1 Function failed
*/
#define __STREXH(value, ptr) __strex(value, ptr)
/** \brief STR Exclusive (32 bit)
This function performs a exclusive STR command for 32 bit values.
\param [in] value Value to store
\param [in] ptr Pointer to location
\return 0 Function succeeded
\return 1 Function failed
*/
#define __STREXW(value, ptr) __strex(value, ptr)
/** \brief Remove the exclusive lock
This function removes the exclusive lock which is created by LDREX.
*/
#if (__ARMCC_VERSION < 400000)
extern void __CLREX(void);
#else /* (__ARMCC_VERSION >= 400000) */
#define __CLREX __clrex
#endif /* __ARMCC_VERSION */
/** \brief Signed Saturate
This function saturates a signed value.
\param [in] value Value to be saturated
\param [in] sat Bit position to saturate to (1..32)
\return Saturated value
*/
#define __SSAT __ssat
/** \brief Unsigned Saturate
This function saturates an unsigned value.
\param [in] value Value to be saturated
\param [in] sat Bit position to saturate to (0..31)
\return Saturated value
*/
#define __USAT __usat
/** \brief Count leading zeros
This function counts the number of leading zeros of a data value.
\param [in] value Value to count the leading zeros
\return number of leading zeros in value
*/
#define __CLZ __clz
#endif /* (__CORTEX_M >= 0x03) */
#elif (defined (__ICCARM__)) /*---------------- ICC Compiler ---------------------*/
/* IAR iccarm specific functions */
#include <intrinsics.h> /* IAR Intrinsics */
#pragma diag_suppress=Pe940
/** \brief No Operation
No Operation does nothing. This instruction can be used for code alignment purposes.
*/
#define __NOP __no_operation
/** \brief Wait For Interrupt
Wait For Interrupt is a hint instruction that suspends execution
until one of a number of events occurs.
*/
static __INLINE void __WFI(void)
{
__ASM ("wfi");
}
/** \brief Wait For Event
Wait For Event is a hint instruction that permits the processor to enter
a low-power state until one of a number of events occurs.
*/
static __INLINE void __WFE(void)
{
__ASM ("wfe");
}
/** \brief Send Event
Send Event is a hint instruction. It causes an event to be signaled to the CPU.
*/
static __INLINE void __SEV(void)
{
__ASM ("sev");
}
/* intrinsic void __ISB(void) (see intrinsics.h) */
/* intrinsic void __DSB(void) (see intrinsics.h) */
/* intrinsic void __DMB(void) (see intrinsics.h) */
/* intrinsic uint32_t __REV(uint32_t value) (see intrinsics.h) */
/* intrinsic __SSAT (see intrinsics.h) */
/* intrinsic __USAT (see intrinsics.h) */
/** \brief Reverse byte order (16 bit)
This function reverses the byte order in two unsigned short values.
\param [in] value Value to reverse
\return Reversed value
*/
static uint32_t __REV16(uint32_t value)
{
__ASM("rev16 r0, r0");
}
/* intrinsic uint32_t __REVSH(uint32_t value) (see intrinsics.h */
#if (__CORTEX_M >= 0x03)
/** \brief Reverse bit order of value
This function reverses the bit order of the given value.
\param [in] value Value to reverse
\return Reversed value
*/
static uint32_t __RBIT(uint32_t value)
{
__ASM("rbit r0, r0");
}
/** \brief LDR Exclusive (8 bit)
This function performs a exclusive LDR command for 8 bit value.
\param [in] ptr Pointer to data
\return value of type uint8_t at (*ptr)
*/
static uint8_t __LDREXB(volatile uint8_t *addr)
{
__ASM("ldrexb r0, [r0]");
}
/** \brief LDR Exclusive (16 bit)
This function performs a exclusive LDR command for 16 bit values.
\param [in] ptr Pointer to data
\return value of type uint16_t at (*ptr)
*/
static uint16_t __LDREXH(volatile uint16_t *addr)
{
__ASM("ldrexh r0, [r0]");
}
/** \brief LDR Exclusive (32 bit)
This function performs a exclusive LDR command for 32 bit values.
\param [in] ptr Pointer to data
\return value of type uint32_t at (*ptr)
*/
/* intrinsic unsigned long __LDREX(unsigned long *) (see intrinsics.h) */
static uint32_t __LDREXW(volatile uint32_t *addr)
{
__ASM("ldrex r0, [r0]");
}
/** \brief STR Exclusive (8 bit)
This function performs a exclusive STR command for 8 bit values.
\param [in] value Value to store
\param [in] ptr Pointer to location
\return 0 Function succeeded
\return 1 Function failed
*/
static uint32_t __STREXB(uint8_t value, volatile uint8_t *addr)
{
__ASM("strexb r0, r0, [r1]");
}
/** \brief STR Exclusive (16 bit)
This function performs a exclusive STR command for 16 bit values.
\param [in] value Value to store
\param [in] ptr Pointer to location
\return 0 Function succeeded
\return 1 Function failed
*/
static uint32_t __STREXH(uint16_t value, volatile uint16_t *addr)
{
__ASM("strexh r0, r0, [r1]");
}
/** \brief STR Exclusive (32 bit)
This function performs a exclusive STR command for 32 bit values.
\param [in] value Value to store
\param [in] ptr Pointer to location
\return 0 Function succeeded
\return 1 Function failed
*/
/* intrinsic unsigned long __STREX(unsigned long, unsigned long) (see intrinsics.h )*/
static uint32_t __STREXW(uint32_t value, volatile uint32_t *addr)
{
__ASM("strex r0, r0, [r1]");
}
/** \brief Remove the exclusive lock
This function removes the exclusive lock which is created by LDREX.
*/
static __INLINE void __CLREX(void)
{
__ASM ("clrex");
}
/* intrinsic unsigned char __CLZ( unsigned long ) (see intrinsics.h) */
#endif /* (__CORTEX_M >= 0x03) */
#pragma diag_default=Pe940
#elif (defined (__GNUC__)) /*------------------ GNU Compiler ---------------------*/
/* GNU gcc specific functions */
/** \brief No Operation
No Operation does nothing. This instruction can be used for code alignment purposes.
*/
__attribute__( ( always_inline ) ) static __INLINE void __NOP(void)
{
__ASM volatile ("nop");
}
/** \brief Wait For Interrupt
Wait For Interrupt is a hint instruction that suspends execution
until one of a number of events occurs.
*/
__attribute__( ( always_inline ) ) static __INLINE void __WFI(void)
{
__ASM volatile ("wfi");
}
/** \brief Wait For Event
Wait For Event is a hint instruction that permits the processor to enter
a low-power state until one of a number of events occurs.
*/
__attribute__( ( always_inline ) ) static __INLINE void __WFE(void)
{
__ASM volatile ("wfe");
}
/** \brief Send Event
Send Event is a hint instruction. It causes an event to be signaled to the CPU.
*/
__attribute__( ( always_inline ) ) static __INLINE void __SEV(void)
{
__ASM volatile ("sev");
}
/** \brief Instruction Synchronization Barrier
Instruction Synchronization Barrier flushes the pipeline in the processor,
so that all instructions following the ISB are fetched from cache or
memory, after the instruction has been completed.
*/
__attribute__( ( always_inline ) ) static __INLINE void __ISB(void)
{
__ASM volatile ("isb");
}
/** \brief Data Synchronization Barrier
This function acts as a special kind of Data Memory Barrier.
It completes when all explicit memory accesses before this instruction complete.
*/
__attribute__( ( always_inline ) ) static __INLINE void __DSB(void)
{
__ASM volatile ("dsb");
}
/** \brief Data Memory Barrier
This function ensures the apparent order of the explicit memory operations before
and after the instruction, without ensuring their completion.
*/
__attribute__( ( always_inline ) ) static __INLINE void __DMB(void)
{
__ASM volatile ("dmb");
}
/** \brief Reverse byte order (32 bit)
This function reverses the byte order in integer value.
\param [in] value Value to reverse
\return Reversed value
*/
__attribute__( ( always_inline ) ) static __INLINE uint32_t __REV(uint32_t value)
{
uint32_t result;
__ASM volatile ("rev %0, %1" : "=r" (result) : "r" (value) );
return(result);
}
/** \brief Reverse byte order (16 bit)
This function reverses the byte order in two unsigned short values.
\param [in] value Value to reverse
\return Reversed value
*/
__attribute__( ( always_inline ) ) static __INLINE uint32_t __REV16(uint32_t value)
{
uint32_t result;
__ASM volatile ("rev16 %0, %1" : "=r" (result) : "r" (value) );
return(result);
}
/** \brief Reverse byte order in signed short value
This function reverses the byte order in a signed short value with sign extension to integer.
\param [in] value Value to reverse
\return Reversed value
*/
__attribute__( ( always_inline ) ) static __INLINE int32_t __REVSH(int32_t value)
{
uint32_t result;
__ASM volatile ("revsh %0, %1" : "=r" (result) : "r" (value) );
return(result);
}
#if (__CORTEX_M >= 0x03)
/** \brief Reverse bit order of value
This function reverses the bit order of the given value.
\param [in] value Value to reverse
\return Reversed value
*/
__attribute__( ( always_inline ) ) static __INLINE uint32_t __RBIT(uint32_t value)
{
uint32_t result;
__ASM volatile ("rbit %0, %1" : "=r" (result) : "r" (value) );
return(result);
}
/** \brief LDR Exclusive (8 bit)
This function performs a exclusive LDR command for 8 bit value.
\param [in] ptr Pointer to data
\return value of type uint8_t at (*ptr)
*/
__attribute__( ( always_inline ) ) static __INLINE uint8_t __LDREXB(volatile uint8_t *addr)
{
uint8_t result;
__ASM volatile ("ldrexb %0, [%1]" : "=r" (result) : "r" (addr) );
return(result);
}
/** \brief LDR Exclusive (16 bit)
This function performs a exclusive LDR command for 16 bit values.
\param [in] ptr Pointer to data
\return value of type uint16_t at (*ptr)
*/
__attribute__( ( always_inline ) ) static __INLINE uint16_t __LDREXH(volatile uint16_t *addr)
{
uint16_t result;
__ASM volatile ("ldrexh %0, [%1]" : "=r" (result) : "r" (addr) );
return(result);
}
/** \brief LDR Exclusive (32 bit)
This function performs a exclusive LDR command for 32 bit values.
\param [in] ptr Pointer to data
\return value of type uint32_t at (*ptr)
*/
__attribute__( ( always_inline ) ) static __INLINE uint32_t __LDREXW(volatile uint32_t *addr)
{
uint32_t result;
__ASM volatile ("ldrex %0, [%1]" : "=r" (result) : "r" (addr) );
return(result);
}
/** \brief STR Exclusive (8 bit)
This function performs a exclusive STR command for 8 bit values.
\param [in] value Value to store
\param [in] ptr Pointer to location
\return 0 Function succeeded
\return 1 Function failed
*/
__attribute__( ( always_inline ) ) static __INLINE uint32_t __STREXB(uint8_t value, volatile uint8_t *addr)
{
uint32_t result;
__ASM volatile ("strexb %0, %2, [%1]" : "=r" (result) : "r" (addr), "r" (value) );
return(result);
}
/** \brief STR Exclusive (16 bit)
This function performs a exclusive STR command for 16 bit values.
\param [in] value Value to store
\param [in] ptr Pointer to location
\return 0 Function succeeded
\return 1 Function failed
*/
__attribute__( ( always_inline ) ) static __INLINE uint32_t __STREXH(uint16_t value, volatile uint16_t *addr)
{
uint32_t result;
__ASM volatile ("strexh %0, %2, [%1]" : "=r" (result) : "r" (addr), "r" (value) );
return(result);
}
/** \brief STR Exclusive (32 bit)
This function performs a exclusive STR command for 32 bit values.
\param [in] value Value to store
\param [in] ptr Pointer to location
\return 0 Function succeeded
\return 1 Function failed
*/
__attribute__( ( always_inline ) ) static __INLINE uint32_t __STREXW(uint32_t value, volatile uint32_t *addr)
{
uint32_t result;
__ASM volatile ("strex %0, %2, [%1]" : "=r" (result) : "r" (addr), "r" (value) );
return(result);
}
/** \brief Remove the exclusive lock
This function removes the exclusive lock which is created by LDREX.
*/
__attribute__( ( always_inline ) ) static __INLINE void __CLREX(void)
{
__ASM volatile ("clrex");
}
/** \brief Signed Saturate
This function saturates a signed value.
\param [in] value Value to be saturated
\param [in] sat Bit position to saturate to (1..32)
\return Saturated value
*/
#define __SSAT(ARG1,ARG2) \
({ \
uint32_t __RES, __ARG1 = (ARG1); \
__ASM ("ssat %0, %1, %2" : "=r" (__RES) : "I" (ARG2), "r" (__ARG1) ); \
__RES; \
})
/** \brief Unsigned Saturate
This function saturates an unsigned value.
\param [in] value Value to be saturated
\param [in] sat Bit position to saturate to (0..31)
\return Saturated value
*/
#define __USAT(ARG1,ARG2) \
({ \
uint32_t __RES, __ARG1 = (ARG1); \
__ASM ("usat %0, %1, %2" : "=r" (__RES) : "I" (ARG2), "r" (__ARG1) ); \
__RES; \
})
/** \brief Count leading zeros
This function counts the number of leading zeros of a data value.
\param [in] value Value to count the leading zeros
\return number of leading zeros in value
*/
__attribute__( ( always_inline ) ) static __INLINE uint8_t __CLZ(uint32_t value)
{
uint8_t result;
__ASM volatile ("clz %0, %1" : "=r" (result) : "r" (value) );
return(result);
}
#endif /* (__CORTEX_M >= 0x03) */
#elif (defined (__TASKING__)) /*--------------- TASKING Compiler -----------------*/
/* TASKING carm specific functions */
/*
* The CMSIS functions have been implemented as intrinsics in the compiler.
* Please use "carm -?i" to get an up to date list of all instrinsics,
* Including the CMSIS ones.
*/
#endif
/*@}*/ /* end of group CMSIS_Core_InstructionInterface */
#endif /* __CORE_CMINSTR_H__ */

33
IAPV1.1/Driver/led/led.c Normal file
View File

@ -0,0 +1,33 @@
#include "led.h"
#include "general_type.h"
void LED_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_SetBits(GPIOA, GPIO_Pin_1);
}
void Run_Led(int i)
{
if(i)
{
LED1_RUN(1);
}
else
{
LED1_RUN(0);
}
}

34
IAPV1.1/Driver/led/led.h Normal file
View File

@ -0,0 +1,34 @@
#ifndef __LED_H
#define __LED_H
#include "sys.h"
#include "general_type.h"
#include "stm32l1xx.h"
#include "stm32l1xx_gpio.h"
#include "stm32l1xx_rcc.h"
void LED_Init(void);//<2F><>ʼ<EFBFBD><CABC>
#define LED1_PORT 1
#define LED1_RUN(sts) (sts?( GPIOA->ODR |= (unsigned int)(1<<LED1_PORT) ):( GPIOA->ODR &= ~((unsigned int)(1<<LED1_PORT) )))
void led_on(u8 num);
void Run_Led(int i);
#endif

View File

@ -0,0 +1,38 @@
#ifndef __GENERAL_TYPE_H
#define __GENERAL_TYPE_H
typedef signed long s32;
typedef signed short s16;
typedef signed char s8;
typedef signed long const sc32; /* Read Only */
typedef signed short const sc16; /* Read Only */
typedef signed char const sc8; /* Read Only */
typedef volatile signed long vs32;
typedef volatile signed short vs16;
typedef volatile signed char vs8;
typedef volatile signed long const vsc32; /* Read Only */
typedef volatile signed short const vsc16; /* Read Only */
typedef volatile signed char const vsc8; /* Read Only */
typedef unsigned long u32;
typedef unsigned short u16;
typedef unsigned char u8;
typedef unsigned long const uc32; /* Read Only */
typedef unsigned short const uc16; /* Read Only */
typedef unsigned char const uc8; /* Read Only */
typedef volatile unsigned long vu32;
typedef volatile unsigned short vu16;
typedef volatile unsigned char vu8;
typedef volatile unsigned long const vuc32; /* Read Only */
typedef volatile unsigned short const vuc16; /* Read Only */
typedef volatile unsigned char const vuc8; /* Read Only */
typedef enum {FALSE = 0, TRUE = !FALSE} bool;
#endif

11
IAPV1.1/Driver/net/hal.h Normal file
View File

@ -0,0 +1,11 @@
#ifndef __HAL_H
#define __HAL_H
static unsigned char myip[4] = {192,168,2,8};
static unsigned char fwip[4];
static unsigned char tempfwip[16];
static unsigned char fwmac[6];
static unsigned char tempfwmac[17];
static unsigned char my_ip[13] = {"192.168.2.8"};
static unsigned char iptemp[4];
#endif

View File

@ -0,0 +1,499 @@
#include "net.h"
#include "ip_arp_udp_tcp.h"
#include "enc28j60.h"
#define pgm_read_byte(ptr) ((char)*(ptr))
//#define unsigned char unsigned char
//#define unsigned int unisgned int
static unsigned char wwwport=80;//80<38>˿<EFBFBD>
static unsigned char macaddr[6];
static unsigned char ipaddr[4];
static unsigned int info_hdr_len=0;
static unsigned int info_data_len=0;
static unsigned char seqnum=0xa; // my initial tcp sequence number
// The Ip checksum is calculated over the ip header only starting
// with the header length field and a total length of 20 bytes
// unitl ip.dst
// You must set the IP checksum field to zero before you start
// the calculation.
// len for ip is 20.
//
// For UDP/TCP we do not make up the required pseudo header. Instead we
// use the ip.src and ip.dst fields of the real packet:
// The udp checksum calculation starts with the ip.src field
// Ip.src=4bytes,Ip.dst=4 bytes,Udp header=8bytes + data length=16+len
// In other words the len here is 8 + length over which you actually
// want to calculate the checksum.
// You must set the checksum field to zero before you start
// the calculation.
// len for udp is: 8 + 8 + data length
// len for tcp is: 4+4 + 20 + option len + data length
//
// For more information on how this algorithm works see:
// http://www.netfor2.com/checksum.html
// http://www.msc.uky.edu/ken/cs471/notes/chap3.htm
// The RFC has also a C code example: http://www.faqs.org/rfcs/rfc1071.html
unsigned int checksum(unsigned char *buf, unsigned int len,unsigned char type)
{
// type 0=ip
// 1=udp
// 2=tcp
unsigned long sum = 0;
//if(type==0){
// // do not add anything
//}
if(type==1)
{
sum+=IP_PROTO_UDP_V; // protocol udp
// the length here is the length of udp (data+header len)
// =length given to this function - (IP.scr+IP.dst length)
sum+=len-8; // = real tcp len
}
if(type==2)
{
sum+=IP_PROTO_TCP_V;
// the length here is the length of tcp (data+header len)
// =length given to this function - (IP.scr+IP.dst length)
sum+=len-8; // = real tcp len
}
// build the sum of 16bit words
while(len >1)
{
sum += 0xFFFF & (*buf<<8|*(buf+1));
buf+=2;
len-=2;
}
// if there is a byte left then add it (padded with zero)
if (len)
{
sum += (0xFF & *buf)<<8;
}
// now calculate the sum over the bytes in the sum
// until the result is only 16bit long
while (sum>>16)
{
sum = (sum & 0xFFFF)+(sum >> 16);
}
// build 1's complement:
return( (unsigned int) sum ^ 0xFFFF);
}
// you must call this function once before you use any of the other functions:
void init_ip_arp_udp_tcp(unsigned char *mymac,unsigned char *myip,unsigned char wwwp)
{
unsigned char i=0;
wwwport=wwwp;
while(i<4)
{
ipaddr[i]=myip[i];
i++;
}
i=0;
while(i<6)
{
macaddr[i]=mymac[i];
i++;
}
// LCD_ShowString(100,100, "13");
}
unsigned char eth_type_is_arp_and_my_ip(unsigned char *buf,unsigned int len)
{
unsigned char i=0;
//
if (len<41)
{
return(0);
}
if(buf[ETH_TYPE_H_P] != ETHTYPE_ARP_H_V || buf[ETH_TYPE_L_P] != ETHTYPE_ARP_L_V)
{
return(0);
}
while(i<4)
{
if(buf[ETH_ARP_DST_IP_P+i] != ipaddr[i])
{
return(0);
}
i++;
}
return(1);
}
unsigned char eth_type_is_ip_and_my_ip(unsigned char *buf,unsigned int len)
{
unsigned char i=0;
//eth+ip+udp header is 42
if (len<42)
{
return(0);
}
if(buf[ETH_TYPE_H_P]!=ETHTYPE_IP_H_V || buf[ETH_TYPE_L_P]!=ETHTYPE_IP_L_V)
{
return(0);
}
if (buf[IP_HEADER_LEN_VER_P]!=0x45)
{
// must be IP V4 and 20 byte header
return(0);
}
while(i<4)
{
if(buf[IP_DST_P+i]!=ipaddr[i])
{
return(0);
}
i++;
}
return(1);
}
// make a return eth header from a received eth packet
void make_eth(unsigned char *buf)
{
unsigned char i=0;
//
//copy the destination mac from the source and fill my mac into src
while(i<6)
{
buf[ETH_DST_MAC +i]=buf[ETH_SRC_MAC +i];
buf[ETH_SRC_MAC +i]=macaddr[i];
i++;
}
}
void fill_ip_hdr_checksum(unsigned char *buf)
{
unsigned int ck;
// clear the 2 byte checksum
buf[IP_CHECKSUM_P]=0;
buf[IP_CHECKSUM_P+1]=0;
buf[IP_FLAGS_P]=0x40; // don't fragment
buf[IP_FLAGS_P+1]=0; // fragement offset
buf[IP_TTL_P]=64; // ttl
// calculate the checksum:
ck=checksum(&buf[IP_P], IP_HEADER_LEN,0);
buf[IP_CHECKSUM_P]=ck>>8;
buf[IP_CHECKSUM_P+1]=ck& 0xff;
}
// make a return ip header from a received ip packet
void make_ip(unsigned char *buf)
{
unsigned char i=0;
while(i<4)
{
buf[IP_DST_P+i]=buf[IP_SRC_P+i];
buf[IP_SRC_P+i]=ipaddr[i];
i++;
}
fill_ip_hdr_checksum(buf);
}
// make a return tcp header from a received tcp packet
// rel_ack_num is how much we must step the seq number received from the
// other side. We do not send more than 255 bytes of text (=data) in the tcp packet.
// If mss=1 then mss is included in the options list
//
// After calling this function you can fill in the first data byte at TCP_OPTIONS_P+4
// If cp_seq=0 then an initial sequence number is used (should be use in synack)
// otherwise it is copied from the packet we received
void make_tcphead(unsigned char *buf,unsigned int rel_ack_num,unsigned char mss,unsigned char cp_seq)
{
unsigned char i=0;
unsigned char tseq;
while(i<2)
{
buf[TCP_DST_PORT_H_P+i]=buf[TCP_SRC_PORT_H_P+i];
buf[TCP_SRC_PORT_H_P+i]=0; // clear source port
i++;
}
// set source port (http):
buf[TCP_SRC_PORT_L_P]=wwwport;
i=4;
// sequence numbers:
// add the rel ack num to SEQACK
while(i>0)
{
rel_ack_num=buf[TCP_SEQ_H_P+i-1]+rel_ack_num;
tseq=buf[TCP_SEQACK_H_P+i-1];
buf[TCP_SEQACK_H_P+i-1]=0xff&rel_ack_num;
if (cp_seq)
{
// copy the acknum sent to us into the sequence number
buf[TCP_SEQ_H_P+i-1]=tseq;
}
else
{
buf[TCP_SEQ_H_P+i-1]= 0; // some preset vallue
}
rel_ack_num=rel_ack_num>>8;
i--;
}
if (cp_seq==0)
{
// put inital seq number
buf[TCP_SEQ_H_P+0]= 0;
buf[TCP_SEQ_H_P+1]= 0;
// we step only the second byte, this allows us to send packts
// with 255 bytes or 512 (if we step the initial seqnum by 2)
buf[TCP_SEQ_H_P+2]= seqnum;
buf[TCP_SEQ_H_P+3]= 0;
// step the inititial seq num by something we will not use
// during this tcp session:
seqnum+=2;
}
// zero the checksum
buf[TCP_CHECKSUM_H_P]=0;
buf[TCP_CHECKSUM_L_P]=0;
// The tcp header length is only a 4 bit field (the upper 4 bits).
// It is calculated in units of 4 bytes.
// E.g 24 bytes: 24/4=6 => 0x60=header len field
//buf[TCP_HEADER_LEN_P]=(((TCP_HEADER_LEN_PLAIN+4)/4)) <<4; // 0x60
if (mss)
{
// the only option we set is MSS to 1408:
// 1408 in hex is 0x580
buf[TCP_OPTIONS_P]=2;
buf[TCP_OPTIONS_P+1]=4;
buf[TCP_OPTIONS_P+2]=0x05;
buf[TCP_OPTIONS_P+3]=0x80;
// 24 bytes:
buf[TCP_HEADER_LEN_P]=0x60;
}
else
{
// no options:
// 20 bytes:
buf[TCP_HEADER_LEN_P]=0x50;
}
}
void make_arp_answer_from_request(unsigned char *buf)
{
unsigned char i=0;
//
make_eth(buf);
buf[ETH_ARP_OPCODE_H_P]=ETH_ARP_OPCODE_REPLY_H_V; //arp <20><>Ӧ
buf[ETH_ARP_OPCODE_L_P]=ETH_ARP_OPCODE_REPLY_L_V;
// fill the mac addresses:
while(i<6)
{
buf[ETH_ARP_DST_MAC_P+i]=buf[ETH_ARP_SRC_MAC_P+i];
buf[ETH_ARP_SRC_MAC_P+i]=macaddr[i];
i++;
}
i=0;
while(i<4)
{
buf[ETH_ARP_DST_IP_P+i]=buf[ETH_ARP_SRC_IP_P+i];
buf[ETH_ARP_SRC_IP_P+i]=ipaddr[i];
i++;
}
// eth+arp is 42 bytes:
enc28j60PacketSend(42,buf);
}
void make_echo_reply_from_request(unsigned char *buf,unsigned int len)
{
make_eth(buf);
make_ip(buf);
buf[ICMP_TYPE_P]=ICMP_TYPE_ECHOREPLY_V; //////<2F><><EFBFBD><EFBFBD>Ӧ<EFBFBD><D3A6>////////////////////////////////////////////////////////////////////////////
// we changed only the icmp.type field from request(=8) to reply(=0).
// we can therefore easily correct the checksum:
if (buf[ICMP_CHECKSUM_P] > (0xff-0x08))
{
buf[ICMP_CHECKSUM_P+1]++;
}
buf[ICMP_CHECKSUM_P]+=0x08;
//
enc28j60PacketSend(len,buf);
}
// you can send a max of 220 bytes of data
void make_udp_reply_from_request(unsigned char *buf,char *data,unsigned int datalen,unsigned int port)
{
unsigned int i=0;
unsigned int ck;
make_eth(buf);
//if (datalen>220)
// {
// datalen=220;
// }
// total length field in the IP header must be set:
i= IP_HEADER_LEN+UDP_HEADER_LEN+datalen;
buf[IP_TOTLEN_H_P]=i>>8;
buf[IP_TOTLEN_L_P]=i;
make_ip(buf);
buf[UDP_DST_PORT_H_P]=port>>8;
buf[UDP_DST_PORT_L_P]=port & 0xff;
// source port does not matter and is what the sender used.
// calculte the udp length:
buf[UDP_LEN_H_P]=datalen>>8;
buf[UDP_LEN_L_P]=UDP_HEADER_LEN+datalen;
// zero the checksum
buf[UDP_CHECKSUM_H_P]=0;
buf[UDP_CHECKSUM_L_P]=0;
// copy the data:
while(i<datalen)
{
buf[UDP_DATA_P+i]=data[i];
i++;
}
ck=checksum(&buf[IP_SRC_P], 16 + datalen,1);
buf[UDP_CHECKSUM_H_P]=ck>>8;
buf[UDP_CHECKSUM_L_P]=ck& 0xff;
enc28j60PacketSend(UDP_HEADER_LEN+IP_HEADER_LEN+ETH_HEADER_LEN+datalen,buf);
}
void make_tcp_synack_from_syn(unsigned char *buf)
{
unsigned int ck;
make_eth(buf);
// total length field in the IP header must be set:
// 20 bytes IP + 24 bytes (20tcp+4tcp options)
buf[IP_TOTLEN_H_P]=0;
buf[IP_TOTLEN_L_P]=IP_HEADER_LEN+TCP_HEADER_LEN_PLAIN+4;
make_ip(buf);
buf[TCP_FLAGS_P]=TCP_FLAGS_SYNACK_V;
make_tcphead(buf,1,1,0);
// calculate the checksum, len=8 (start from ip.src) + TCP_HEADER_LEN_PLAIN + 4 (one option: mss)
ck=checksum(&buf[IP_SRC_P], 8+TCP_HEADER_LEN_PLAIN+4,2);
buf[TCP_CHECKSUM_H_P]=ck>>8;
buf[TCP_CHECKSUM_L_P]=ck& 0xff;
// add 4 for option mss:
enc28j60PacketSend(IP_HEADER_LEN+TCP_HEADER_LEN_PLAIN+4+ETH_HEADER_LEN,buf);
}
// get a pointer to the start of tcp data in buf
// Returns 0 if there is no data
// You must call init_len_info once before calling this function
unsigned int get_tcp_data_pointer(void)
{
if (info_data_len)
{
return((unsigned int)TCP_SRC_PORT_H_P+info_hdr_len);
}
else
{
return(0);
}
}
// do some basic length calculations and store the result in static varibales
void init_len_info(unsigned char *buf)
{
info_data_len=(buf[IP_TOTLEN_H_P]<<8)|(buf[IP_TOTLEN_L_P]&0xff);
info_data_len-=IP_HEADER_LEN;
info_hdr_len=(buf[TCP_HEADER_LEN_P]>>4)*4; // generate len in bytes;
info_data_len-=info_hdr_len;
if (info_data_len<=0)
{
info_data_len=0;
}
}
// fill in tcp data at position pos. pos=0 means start of
// tcp data. Returns the position at which the string after
// this string could be filled.
unsigned int fill_tcp_data_p(unsigned char *buf,unsigned int pos, const unsigned char *progmem_s)
{
char c;
// fill in tcp data at position pos
//
// with no options the data starts after the checksum + 2 more bytes (urgent ptr)
while ((c = pgm_read_byte(progmem_s++)))
{
buf[TCP_CHECKSUM_L_P+3+pos]=c;
pos++;
}
return(pos);
}
// fill in tcp data at position pos. pos=0 means start of
// tcp data. Returns the position at which the string after
// this string could be filled.
unsigned int fill_tcp_data(unsigned char *buf,unsigned int pos, const char *s)
{
// fill in tcp data at position pos
//
// with no options the data starts after the checksum + 2 more bytes (urgent ptr)
while (*s)
{
buf[TCP_CHECKSUM_L_P+3+pos]=*s;
pos++;
s++;
}
return(pos);
}
// Make just an ack packet with no tcp data inside
// This will modify the eth/ip/tcp header
void make_tcp_ack_from_any(unsigned char *buf)
{
unsigned int j;
make_eth(buf);
// fill the header:
buf[TCP_FLAGS_P]=TCP_FLAGS_ACK_V;//TCP_FLAGS_P 0x2f TCP_FLAGS_ACK_V 0x10
if (info_data_len==0)
{
// if there is no data then we must still acknoledge one packet
make_tcphead(buf,1,0,1); // no options
}
else
{
make_tcphead(buf,info_data_len,0,1); // no options
}
// total length field in the IP header must be set:
// 20 bytes IP + 20 bytes tcp (when no options)
j=IP_HEADER_LEN+TCP_HEADER_LEN_PLAIN; //IP_HEADER_LEN 20 TCP_HEADER_LEN_PLAIN 20
buf[IP_TOTLEN_H_P]=j>>8; //IP_TOTLEN_H_P 0x10
buf[IP_TOTLEN_L_P]=j& 0xff;//IP_TOTLEN_L_P 0x11
make_ip(buf);
// calculate the checksum, len=8 (start from ip.src) + TCP_HEADER_LEN_PLAIN + data len
j=checksum(&buf[IP_SRC_P], 8+TCP_HEADER_LEN_PLAIN,2);
buf[TCP_CHECKSUM_H_P]=j>>8;
buf[TCP_CHECKSUM_L_P]=j& 0xff;
enc28j60PacketSend(IP_HEADER_LEN+TCP_HEADER_LEN_PLAIN+ETH_HEADER_LEN,buf);
}
// you must have called init_len_info at some time before calling this function
// dlen is the amount of tcp data (http data) we send in this packet
// You can use this function only immediately after make_tcp_ack_from_any
// This is because this function will NOT modify the eth/ip/tcp header except for
// length and checksum
void make_tcp_ack_with_data(unsigned char *buf,unsigned int dlen)
{
unsigned int j;
// fill the header:
// This code requires that we send only one data packet
// because we keep no state information. We must therefore set
// the fin here:
buf[TCP_FLAGS_P]=TCP_FLAGS_ACK_V|TCP_FLAGS_PUSH_V|TCP_FLAGS_FIN_V;
// total length field in the IP header must be set:
// 20 bytes IP + 20 bytes tcp (when no options) + len of data
j=IP_HEADER_LEN+TCP_HEADER_LEN_PLAIN+dlen;
buf[IP_TOTLEN_H_P]=j>>8;
buf[IP_TOTLEN_L_P]=j& 0xff;
fill_ip_hdr_checksum(buf);
// zero the checksum
buf[TCP_CHECKSUM_H_P]=0;
buf[TCP_CHECKSUM_L_P]=0;
// calculate the checksum, len=8 (start from ip.src) + TCP_HEADER_LEN_PLAIN + data len
j=checksum(&buf[IP_SRC_P], 8+TCP_HEADER_LEN_PLAIN+dlen,2);
buf[TCP_CHECKSUM_H_P]=j>>8;
buf[TCP_CHECKSUM_L_P]=j& 0xff;
enc28j60PacketSend(IP_HEADER_LEN+TCP_HEADER_LEN_PLAIN+dlen+ETH_HEADER_LEN,buf);
}
/* end of ip_arp_udp.c */

View File

@ -0,0 +1,49 @@
/*********************************************
* vim:sw=8:ts=8:si:et
* To use the above modeline in vim you must have "set modeline" in your .vimrc
* Author: Guido Socher
* Copyright: GPL V2
*
* IP/ARP/UDP/TCP functions
*
* Chip type : ATMEGA88 with ENC28J60
*********************************************/
/*********************************************
* modified: 2007-08-08
* Author : awake
* Copyright: GPL V2
* http://www.icdev.com.cn/?2213/
* Host chip: ADUC7026
**********************************************/
//@{
#ifndef IP_ARP_UDP_TCP_H
#define IP_ARP_UDP_TCP_H
// you must call this function once before you use any of the other functions:
extern void init_ip_arp_udp_tcp(unsigned char *mymac,unsigned char *myip,unsigned char wwwp);
//
extern unsigned char eth_type_is_arp_and_my_ip(unsigned char *buf,unsigned int len);
extern unsigned char eth_type_is_ip_and_my_ip(unsigned char *buf,unsigned int len);
extern void make_arp_answer_from_request(unsigned char *buf);
extern void make_echo_reply_from_request(unsigned char *buf,unsigned int len);
extern void make_udp_reply_from_request(unsigned char *buf,char *data,unsigned int datalen,unsigned int port);
extern void make_tcp_synack_from_syn(unsigned char *buf);
extern void init_len_info(unsigned char *buf);
extern unsigned int get_tcp_data_pointer(void);
extern unsigned int fill_tcp_data_p(unsigned char *buf,unsigned int pos, const unsigned char *progmem_s);
extern unsigned int fill_tcp_data(unsigned char *buf,unsigned int pos, const char *s);
extern void make_tcp_ack_from_any(unsigned char *buf);
extern void make_tcp_ack_with_data(unsigned char *buf,unsigned int dlen);
#endif /* IP_ARP_UDP_TCP_H */
//@}

134
IAPV1.1/Driver/net/net.h Normal file
View File

@ -0,0 +1,134 @@
/*********************************************
* vim:sw=8:ts=8:si:et
* To use the above modeline in vim you must have "set modeline" in your .vimrc
* Author: Guido Socher
* Copyright: GPL V2
*
* Based on the net.h file from the AVRlib library by Pascal Stang.
* For AVRlib See http://www.procyonengineering.com/
* Used with explicit permission of Pascal Stang.
*
* Chip type : ATMEGA88 with ENC28J60
*********************************************/
/*********************************************
* modified: 2007-08-08
* Author : awake
* Copyright: GPL V2
* http://www.icdev.com.cn/?2213/
* Host chip: ADUC7026
**********************************************/
// notation: _P = position of a field
// _V = value of a field
//@{
#ifndef NET_H
#define NET_H
// ******* ETH *******
#define ETH_HEADER_LEN 14
// values of certain bytes:
#define ETHTYPE_ARP_H_V 0x08
#define ETHTYPE_ARP_L_V 0x06
#define ETHTYPE_IP_H_V 0x08
#define ETHTYPE_IP_L_V 0x00
// byte positions in the ethernet frame:
//
// Ethernet type field (2bytes):
#define ETH_TYPE_H_P 12
#define ETH_TYPE_L_P 13
//
#define ETH_DST_MAC 0
#define ETH_SRC_MAC 6
// ******* ARP *******
#define ETH_ARP_OPCODE_REPLY_H_V 0x0
#define ETH_ARP_OPCODE_REPLY_L_V 0x02
//
#define ETHTYPE_ARP_L_V 0x06
// arp.dst.ip
#define ETH_ARP_DST_IP_P 0x26
// arp.opcode
#define ETH_ARP_OPCODE_H_P 0x14
#define ETH_ARP_OPCODE_L_P 0x15
// arp.src.mac
#define ETH_ARP_SRC_MAC_P 0x16
#define ETH_ARP_SRC_IP_P 0x1c
#define ETH_ARP_DST_MAC_P 0x20
#define ETH_ARP_DST_IP_P 0x26
// ******* IP *******
#define IP_HEADER_LEN 20
// ip.src
#define IP_SRC_P 0x1a
#define IP_DST_P 0x1e
#define IP_HEADER_LEN_VER_P 0xe
#define IP_CHECKSUM_P 0x18
#define IP_TTL_P 0x16
#define IP_FLAGS_P 0x14
#define IP_P 0xe
#define IP_TOTLEN_H_P 0x10
#define IP_TOTLEN_L_P 0x11
#define IP_PROTO_P 0x17
#define IP_PROTO_ICMP_V 1
#define IP_PROTO_TCP_V 6
// 17=0x11
#define IP_PROTO_UDP_V 17
// ******* ICMP *******
#define ICMP_TYPE_ECHOREPLY_V 0
#define ICMP_TYPE_ECHOREQUEST_V 8
//
#define ICMP_TYPE_P 0x22
#define ICMP_CHECKSUM_P 0x24
// ******* UDP *******
#define UDP_HEADER_LEN 8
//
#define UDP_SRC_PORT_H_P 0x22
#define UDP_SRC_PORT_L_P 0x23
#define UDP_DST_PORT_H_P 0x24
#define UDP_DST_PORT_L_P 0x25
//
#define UDP_LEN_H_P 0x26
#define UDP_LEN_L_P 0x27
#define UDP_CHECKSUM_H_P 0x28
#define UDP_CHECKSUM_L_P 0x29
#define UDP_DATA_P 0x2a
// ******* TCP *******
#define TCP_SRC_PORT_H_P 0x22
#define TCP_SRC_PORT_L_P 0x23
#define TCP_DST_PORT_H_P 0x24
#define TCP_DST_PORT_L_P 0x25
// the tcp seq number is 4 bytes 0x26-0x29
#define TCP_SEQ_H_P 0x26
#define TCP_SEQACK_H_P 0x2a
// flags: SYN=2
#define TCP_FLAGS_P 0x2f
#define TCP_FLAGS_SYN_V 2
#define TCP_FLAGS_FIN_V 1
#define TCP_FLAGS_PUSH_V 8
#define TCP_FLAGS_SYNACK_V 0x12
#define TCP_FLAGS_ACK_V 0x10
#define TCP_FLAGS_PSHACK_V 0x18
// plain len without the options:
#define TCP_HEADER_LEN_PLAIN 20
#define TCP_HEADER_LEN_P 0x2e
#define TCP_CHECKSUM_H_P 0x32
#define TCP_CHECKSUM_L_P 0x33
#define TCP_OPTIONS_P 0x36
//
#endif
//@}

View File

@ -0,0 +1,443 @@
#include <string.h>
#include "enc28j60.h"
#include "ip_arp_udp_tcp.h"
#include "net.h"
#include "hal.h"
#include "led.h"
//#include "uart.h"
#include "simple_server.h"
#include "general_type.h"
#include "temp.h"
#define PSTR(s) s
unsigned char i_1=0,i_2=0,i_3=0,i_4=0;
unsigned char led1=0,led2=0,led3=0,led4=0,led=0;
unsigned char temp[]={"0123456789ABCDEF"};
unsigned char temp1[]={"0123456789"};
u16 temp_1;
unsigned char temp_2[5];
unsigned char temp_3[7];
//extern void delay_ms(unsigned char ms);
// please modify the following two lines. mac and ip have to be unique
// in your local area network. You can not have the same numbers in
// two devices:
static unsigned char mymac[6] = {0x04,0x02,0x35,0x00,0x00,0x01};
//static unsigned char myip[4] = {192,168,0,100};
// base url (you can put a DNS name instead of an IP addr. if you have
// a DNS server (baseurl must end in "/"):
static unsigned int mywwwport =80; // listen port for tcp/www (max range 1-254)
// or on a different port:
//static char baseurl[]="http://10.0.0.24:88/";
//static unsigned int mywwwport =88; // listen port for tcp/www (max range 1-254)
//
static unsigned int myudpport =1200; // listen port for udp
// how did I get the mac addr? Translate the first 3 numbers into ascii is: TUX
#define BUFFER_SIZE 1500//400
static unsigned char buf[BUFFER_SIZE+1];
static unsigned char BUF;
// the password string (only the first 5 char checked), (only a-z,0-9,_ characters):
static char password[]="123456"; // must not be longer than 9 char
#define LED1_ON() LED1_RUN(1);
#define LED2_ON() LED2_RUN(1);
#define LED3_ON() LED3_RUN(1);
#define LED4_ON() LED4_RUN(1);
#define LED1_OFF() LED1_RUN(0);
#define LED2_OFF() LED2_RUN(0);
#define LED3_OFF() LED3_RUN(0);
#define LED4_OFF() LED4_RUN(0);
//
unsigned char verify_password(char *str)
{
// the first characters of the received string are
// a simple password/cookie:
//<2F><> <20><>: int strncmp(char *str1, char *str2, int maxlen); <20><><EFBFBD><EFBFBD>
//˵<><CBB5>:<3A>Ƚ<EFBFBD><C8BD>ַ<EFBFBD><D6B7><EFBFBD>str1<72><31>str2<72>Ĵ<EFBFBD>С<EFBFBD><D0A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>str1С<31><D0A1>str2<72><32><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5><0<><30><EFBFBD><EFBFBD>֮<EFBFBD><D6AE><EFBFBD><EFBFBD>str1<72><31><EFBFBD><EFBFBD>str2<72><32><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5>>0<><30>
//<2F><><EFBFBD><EFBFBD>str1<72><31><EFBFBD><EFBFBD>str2<72><32><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5>=0<><30>maxlenָ<6E><D6B8><EFBFBD><EFBFBD>str1<72><31>str2<72>ıȽϵ<C8BD><CFB5>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD>
//<2F>˺<EFBFBD><CBBA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܼ<EFBFBD><DCBC>Ƚ<EFBFBD><C8BD>ַ<EFBFBD><D6B7><EFBFBD>str1<72><31>str2<72><32>ǰmaxlen<65><6E><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>
if (strncmp(password,str,5)==0)
{
return(1);
}
return(0);
}
// takes a string of the form password/commandNumber and analyse it
// return values: -1 invalid password, otherwise command number
// -2 no command given but password valid
unsigned char analyse_get_url(char *str)
{
unsigned char i=0;
if (verify_password(str)==0) //<2F>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD>ȷ<EFBFBD><C8B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><30><CBB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȷ<EFBFBD><C8B7>verify_password(str)==0
{
return(-1); ////<2F><><EFBFBD><EFBFBD>֤<EFBFBD><D6A4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȷʱ<C8B7>ͽ<EFBFBD>-1<><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ִ<EFBFBD><D6B4>
}
// find first "/"
// passw not longer than 9 char:
while(*str && i<10 && *str >',' && *str<'{')
{
if (*str=='/')
{
str++;
break;
}
i++;
str++;
}
if (*str < 0x3a && *str > 0x2f) //<2F><><EFBFBD><EFBFBD>ASCII<49><49>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><E4B7B5>
{
// is a ASCII number, return it
return(*str-0x30);
}
return(-2);
}
// prepare the webpage by writing the data to the tcp send buffer
/**********************************************************************
<EFBFBD><EFBFBD><EFBFBD>ܣ<EFBFBD><EFBFBD><EFBFBD>ӡҳ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
***********************************************************************/
unsigned int print_webpage(unsigned char *buf,unsigned char on_off1,unsigned char on_off2,unsigned char on_off3,unsigned char on_off4)
{
unsigned int plen,j;
unsigned char macmac[17];
plen=fill_tcp_data_p(buf,0,PSTR("HTTP/1.0 200 OK\r\nContent-Type: text/html\r\nPragma: no-cache\r\n\r\n"));
plen=fill_tcp_data_p(buf,plen,PSTR("<META HTTP-EQUIV=Refresh content=5>"));//ҳ<>ʼ<E6BFAA><CABC>
plen=fill_tcp_data_p(buf,plen,PSTR("<form action=""/"" method=get>"));//ҳ<>ʼ<E6BFAA><CABC>
plen=fill_tcp_data_p(buf,plen,PSTR("<font size=7><center><3E><><EFBFBD><EFBFBD>STM32<33><32><EFBFBD><EFBFBD>̫<EFBFBD><CCAB>ͨ<EFBFBD><CDA8>ϵͳ<CFB5><CDB3><EFBFBD><EFBFBD></center></font><br><p><p>"));
plen=fill_tcp_data_p(buf,plen,PSTR("<marquee behavior=alternate scrollamount=15>ϵͳ<CFB5><CDB3>Դ<EFBFBD><D4B4>STM32F103RBT6,128K Flash, 64K SRAM</marquee><P>"));
plen=fill_tcp_data_p(buf,plen,PSTR("<marquee behavior=alternate>Ƕ<><C7B6>ʽ<EFBFBD><CABD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>IP:192.168.1.100 MAC:04-02-35-00-00-01</marquee><P>"));
plen=fill_tcp_data_p(buf,plen,PSTR("<p><center><a href="));
plen=fill_tcp_data(buf,plen,"http://");
plen=fill_tcp_data(buf,plen,my_ip);
plen=fill_tcp_data(buf,plen,"/?led=");
if (led1==0x31)
{
plen=fill_tcp_data_p(buf,plen,PSTR("5><font size=5><3E>ر<EFBFBD>LED1:</font></a>"));
plen=fill_tcp_data_p(buf,plen,PSTR("<font size=5 color=\"#00FF00\"> LED1<44><31></font></center>"));
}
else if (led1==0x35|led1==0)
{
plen=fill_tcp_data_p(buf,plen,PSTR("1><font size=5><3E><><EFBFBD><EFBFBD>LED1:</font></a>"));
plen=fill_tcp_data_p(buf,plen,PSTR("<font size=5> LED1<44><31></font></center>"));
}
plen=fill_tcp_data_p(buf,plen,PSTR("<p><center><a href="));
plen=fill_tcp_data(buf,plen,"http://");
plen=fill_tcp_data(buf,plen,my_ip);
plen=fill_tcp_data(buf,plen,"/?led=");
if (led2==0x32)
{
plen=fill_tcp_data_p(buf,plen,PSTR("6><font size=5><3E>ر<EFBFBD>LED2:</font></a>"));
plen=fill_tcp_data_p(buf,plen,PSTR("<font size=5 color=\"#00FF00\"> LED2<44><32></font></center>"));
}
else if(led2==0x36|led2==0)
{
plen=fill_tcp_data_p(buf,plen,PSTR("2><font size=5><3E><><EFBFBD><EFBFBD>LED2:</font></a>"));
plen=fill_tcp_data_p(buf,plen,PSTR("<font size=5> LED2<44><32></font></center>"));
}
plen=fill_tcp_data_p(buf,plen,PSTR("<p><center><a href="));
plen=fill_tcp_data(buf,plen,"http://");
plen=fill_tcp_data(buf,plen,my_ip);
plen=fill_tcp_data(buf,plen,"/?led=");
if (led3==0x33)
{
plen=fill_tcp_data_p(buf,plen,PSTR("7><font size=5><3E>ر<EFBFBD>LED3:</font></a>"));
plen=fill_tcp_data_p(buf,plen,PSTR("<font size=5 color=\"#00FF00\"> LED3<44><33></font></center>"));
}
else if(led3==0x37|led3==0)
{
plen=fill_tcp_data_p(buf,plen,PSTR("3><font size=5><3E><><EFBFBD><EFBFBD>LED3:</font></a>"));
plen=fill_tcp_data_p(buf,plen,PSTR("<font size=5> LED3<44><33></font></center>"));
}
plen=fill_tcp_data_p(buf,plen,PSTR("<p><center><a href="));
plen=fill_tcp_data(buf,plen,"http://");
plen=fill_tcp_data(buf,plen,my_ip);
plen=fill_tcp_data(buf,plen,"/?led=");
if (led4==0x34)
{
plen=fill_tcp_data_p(buf,plen,PSTR("8><font size=5><3E>ر<EFBFBD>LED4:</font></a>"));
plen=fill_tcp_data_p(buf,plen,PSTR("<font size=5 color=\"#00FF00\"> LED4<44><34></font></center>"));
}
else if(led4==0x38|led4==0)
{
plen=fill_tcp_data_p(buf,plen,PSTR("4><font size=5><3E><><EFBFBD><EFBFBD>LED4:</font></a>"));
plen=fill_tcp_data_p(buf,plen,PSTR("<font size=5> LED4<44><34></font></center>"));
}
plen=fill_tcp_data_p(buf,plen,PSTR("<font size=5><center > STM32<33>ڲ<EFBFBD><DAB2>¶ȴ<C2B6><C8B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȣ<C2B6> "));
plen=fill_tcp_data_p(buf,plen,PSTR(temp_2));
plen=fill_tcp_data_p(buf,plen,"<EFBFBD><EFBFBD>C</center></font>");
plen=fill_tcp_data_p(buf,plen,PSTR("<font size=5 color=\"#ff6600\"><center><hr> <br><3E><><EFBFBD>˵<EFBFBD><CBB5><EFBFBD></center>"));
plen=fill_tcp_data_p(buf,plen,PSTR("<font size=5 color=\"#00FF00\"><center><br><3E><><EFBFBD><EFBFBD>ֿɼ<D6BF> һ<>н<EFBFBD><D0BD>п<EFBFBD><D0BF><EFBFBD></center></font>"));
plen=fill_tcp_data_p(buf,plen," <a href=http://mcu-web.taobao.com><center><3E><><EFBFBD>˽<EFBFBD><CBBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ٷ<EFBFBD><D9B7>Ա<EFBFBD><D4B1><EFBFBD>:http://mcu-web.taobao.com</center></a>");
plen=fill_tcp_data_p(buf,plen,PSTR("<font size=5 ><center><3E><><EFBFBD><EFBFBD><EFBFBD>Ա<EFBFBD><D4B1><EFBFBD>IP<49><50>ַ<EFBFBD><D6B7>"));
plen=fill_tcp_data_p(buf,plen,PSTR(tempfwip));
plen=fill_tcp_data_p(buf,plen,PSTR(" <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7>"));
for(j=0;j<17;j++)
macmac[j]=tempfwmac[j];
plen=fill_tcp_data_p(buf,plen,PSTR(macmac));
plen=fill_tcp_data_p(buf,plen,"</center></font>");
plen=fill_tcp_data_p(buf,plen,PSTR("</form>")); ////ҳ<><D2B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
return(plen);
}
unsigned int simple_server(void)
{
unsigned int plen,i1=0;
unsigned int dat_p;
unsigned char ii;
unsigned char cmd,*buf1;
unsigned int payloadlen=0;
LED1_ON();
LED2_ON();
LED3_ON();
LED4_ON();
plen = enc28j60getrev();
/*initialize enc28j60*/
enc28j60Init(mymac);
// ENC28J60_Init(mymac);
//<2F><>IP<49><50>ַ<EFBFBD><D6B7>MAC<41><43>ַд<D6B7><D0B4><EFBFBD><EFBFBD><EFBFBD>ԵĻ<D4B5><C4BB><EFBFBD><EFBFBD><EFBFBD> ipaddr[] macaddr[]
init_ip_arp_udp_tcp(mymac,myip,mywwwport);
//ָʾ<D6B8><CABE>״̬:0x476 is PHLCON LEDA(<28><>)=links status, LEDB(<28><>)=receive/transmit
//enc28j60PhyWrite(PHLCON,0x7a4);
//PHLCON<4F><4E>PHY ģ<><C4A3>LED <20><><EFBFBD>ƼĴ<C6BC><C4B4><EFBFBD>
enc28j60PhyWrite(PHLCON,0x0476);
enc28j60clkout(2); // change clkout from 6.25MHz to 12.5MHz
//init the ethernet/ip layer:
while(1)
{
get_temperature(&temp_1);
temp_2[0]=temp1[temp_1/100];
temp_2[1]=temp1[temp_1%100/10];
temp_2[2]='.';
temp_2[3]=temp1[temp_1%10]; //<2F><>C
plen=0;
plen = enc28j60PacketReceive(BUFFER_SIZE, buf);
/*plen will ne unequal to zero if there is a valid packet (without crc error) */
if(plen==0)
{
continue;
}
// arp is broadcast if unknown but a host may also
// verify the mac address by sending it to
// a unicast address.
//ARP ֡<><D6A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 42
if(eth_type_is_arp_and_my_ip(buf,plen))
{
make_arp_answer_from_request(buf);
continue;
}
// check if ip packets are for us:
if(eth_type_is_ip_and_my_ip(buf,plen)==0)
{
continue;
}
if(buf[IP_PROTO_P]==IP_PROTO_ICMP_V && buf[ICMP_TYPE_P]==ICMP_TYPE_ECHOREQUEST_V)
{
// a ping packet, let's send pong PING<4E>Ļ<EFBFBD>Ӧ
make_echo_reply_from_request(buf, plen);
/*<2A><>ȡmac<61><63>ַ*/
for(ii=0;ii<6;ii++)
{
fwmac[ii]=buf[ii];
tempfwmac[ii*3+0]=temp[fwmac[ii]/16];
tempfwmac[ii*3+1]=temp[fwmac[ii]%16];
if(ii<5)
tempfwmac[ii*3+2]='-';
}
/*<2A><>ȡip<69><70>ַ*/
for(ii=0;ii<4;ii++)
{
fwip[ii]=buf[ii+30];//0xbf
tempfwip[ii*4+0]=temp1[fwip[ii]/100]; //temp1[]={"0123456789"};
tempfwip[ii*4+1]=temp1[fwip[ii]%100/10];
tempfwip[ii*4+2]=temp1[fwip[ii]%100%10];
if(ii<3)
tempfwip[ii*4+3]='.';
}
continue;
}
// tcp port www start, compare only the lower byte<74>˿<EFBFBD><CBBF><EFBFBD><EFBFBD>ʼ<E7BFAA><CABC><EFBFBD><EFBFBD><EFBFBD>ȵ<EFBFBD><C8B5>ֽ<EFBFBD>
if (buf[IP_PROTO_P]==IP_PROTO_TCP_V&&buf[TCP_DST_PORT_H_P]==0&&buf[TCP_DST_PORT_L_P]==mywwwport)
{
/*<2A><>ȡmac<61><63>ַ*/
for(ii=0;ii<6;ii++)
{
fwmac[ii]=buf[ii+6];
tempfwmac[ii*3+0]=temp[fwmac[ii]/16];
tempfwmac[ii*3+1]=temp[fwmac[ii]%16];
if(ii<5)
tempfwmac[ii*3+2]='-';
}
/*<2A><>ȡip<69><70>ַ*/
iptemp[0]=buf[30];
iptemp[1]=buf[27];
iptemp[2]=buf[28];
iptemp[3]=buf[29];
for(ii=0;ii<4;ii++)
{
fwip[ii]=iptemp[ii];
tempfwip[ii*4+0]=temp1[fwip[ii]/100];
tempfwip[ii*4+1]=temp1[fwip[ii]%100/10];
tempfwip[ii*4+2]=temp1[fwip[ii]%100%10];
if(ii<3)
tempfwip[ii*4+3]='.';
}
if (buf[TCP_FLAGS_P] & TCP_FLAGS_SYN_V)
{
make_tcp_synack_from_syn(buf);
// make_tcp_synack_from_syn does already send the syn,ack
continue;
}
if (buf[TCP_FLAGS_P] & TCP_FLAGS_ACK_V)
{
init_len_info(buf); // init some data structures
// we can possibly have no data, just ack:
dat_p=get_tcp_data_pointer();
if (dat_p==0)
{
if (buf[TCP_FLAGS_P] & TCP_FLAGS_FIN_V)
{
// finack, answer with ack
make_tcp_ack_from_any(buf);
}
// just an ack with no data, wait for next packet
continue;
}
if (strncmp("GET ",(char *)&(buf[dat_p]),4)!=0)
{
// head, post and other methods:
// for possible status codes see:
// http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html
plen=fill_tcp_data_p(buf,0,PSTR("HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n<h1>200 OK</h1>"));
goto SENDTCP;
}
if (strncmp("/ ",(char *)&(buf[dat_p+4]),2)==0)
{
plen=fill_tcp_data_p(buf,0,PSTR("HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n"));
plen=fill_tcp_data_p(buf,plen,PSTR("<form action=""/"" method=get>"));//ҳ<>ʼ<E6BFAA><CABC>
plen=fill_tcp_data_p(buf,plen,PSTR("<center><3E><><EFBFBD>룺<input type=password name=""mm"" ></center><br>"));
plen=fill_tcp_data_p(buf,plen,PSTR("<center><input type=submit value=""<EFBFBD><EFBFBD><EFBFBD><EFBFBD>""><input type=reset value=""<EFBFBD><EFBFBD><EFBFBD><EFBFBD>""></center>"));
plen=fill_tcp_data_p(buf,plen,PSTR("</form>")); ////ҳ<><D2B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
goto SENDTCP;
}
if(strncmp("/?mm=654321",(char *)&(buf[dat_p+4]),11)!=0)
{
if(strncmp("/?led",(char *)&(buf[dat_p+4]),5)==0) goto SENDTCP1;
plen=fill_tcp_data_p(buf,0,PSTR("HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n"));
plen=fill_tcp_data_p(buf,plen,PSTR("<form action=""/"" method=get>"));//ҳ<>ʼ<E6BFAA><CABC>
plen=fill_tcp_data_p(buf,plen,PSTR("<center><3E><><EFBFBD>룺<input type=password name=""mm"" ></center><br>"));
plen=fill_tcp_data_p(buf,plen,PSTR("<center><input type=submit value=""<EFBFBD><EFBFBD><EFBFBD><EFBFBD>""><input type=reset value=""<EFBFBD><EFBFBD><EFBFBD><EFBFBD>""></center><br><br><br><br>"));
plen=fill_tcp_data_p(buf,plen,PSTR("<font size=6><center><3E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EBA3A1></center></font><br>"));
plen=fill_tcp_data_p(buf,plen,PSTR("</form>")); ////ҳ<><D2B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
goto SENDTCP;
}
SENDTCP1:
cmd=analyse_get_url((char *)&(buf[dat_p+10]));
BUF=buf[64];
cmd=BUF;
if (cmd==-1)
{
plen=fill_tcp_data_p(buf,0,PSTR("HTTP/1.0 401 Unauthorized\r\nContent-Type: text/html\r\n\r\n<h1>401 Unauthorized</h1>"));
goto SENDTCP;
}
if (cmd==0x31)
{
LED1_OFF();
led1=i_1=0x31;
}
else if(cmd==0x35)
{
LED1_ON();
led1=i_1=0x35;
}
if (cmd==0x32)
{
LED2_OFF();
led2=i_2=0x32;
}
else if(cmd==0x36)
{
LED2_ON();
led2=i_2=0x36;
}
if (cmd==0x33)
{
LED3_OFF();
led3=i_3=0x33;
}
else if(cmd==0x37)
{
LED3_ON();
led3=i_3=0x37;
}
if (cmd==0x34)
{
LED4_OFF();
led4=i_4=0x34;
}
else if(cmd==0x38)
{
LED4_ON();
led4=i_4=0x38;
}
// if (cmd==-2) or any other value
// just display the status:
plen=print_webpage(buf,(i_1),(i_2),(i_3),(i_4)); /////////////////////////////////////////////////
SENDTCP:
make_tcp_ack_from_any(buf); // send ack for http get
make_tcp_ack_with_data(buf,plen); // send data
continue;
}
}
// tcp port www end
//
// udp start, we listen on udp port 1200=0x4B0
if (buf[IP_PROTO_P]==IP_PROTO_UDP_V&&buf[UDP_DST_PORT_H_P]==4&&buf[UDP_DST_PORT_L_P]==0xb0)
{
payloadlen= buf[UDP_LEN_H_P];
payloadlen=payloadlen<<8;
payloadlen=(payloadlen+buf[UDP_LEN_L_P])-UDP_HEADER_LEN;
//payloadlen=buf[UDP_LEN_L_P]-UDP_HEADER_LEN;
ANSWER:
//while(1){
for(i1=0; i1<payloadlen; i1++) buf1[i1]=buf[UDP_DATA_P+i1];
//make_udp_reply_from_request(buf,str,strlen(str),myudpport);
make_udp_reply_from_request(buf,buf1,payloadlen,myudpport);
}
}
return 0;
}

View File

@ -0,0 +1,16 @@
#ifndef _TCPIP_H
#define _TCPIP_H
#include "ENC28J60.h"
extern unsigned char verify_password(char *str);
extern unsigned char analyse_get_url(char *str);
extern unsigned int print_webpage(unsigned char *buf,unsigned char on_off1,unsigned char on_off2,unsigned char on_off3,unsigned char on_off4);
extern unsigned int simple_server(void);
#endif

View File

@ -0,0 +1,131 @@
//#include "bsp.h"
//#include "process.h"
//u8 Wake_Up_Flag=0;//<2F><><EFBFBD>ѱ<EFBFBD>־ 0<><30>һ<EFBFBD><D2BB><EFBFBD>ϵ翪<CFB5><E7BFAA> 1<><31><EFBFBD>Ż<EFBFBD><C5BB><EFBFBD> 2 <20><><EFBFBD>ӻ<EFBFBD><D3BB><EFBFBD>
//u8 Enable_SDI_Esp8266=0; //0ʹ<30><CAB9>SDI 1ʹ<31><CAB9>ESP8266
////<2F><EFBFBD><E8B1B8>ʼ<EFBFBD><CABC>
//void Equitment_Init(void)
//{
// //0<><30><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD>ϵ<EFBFBD><CFB5><EFBFBD>ʼ<EFBFBD><CABC>
// //1<><31><EFBFBD><EFBFBD><EFBFBD>Ż<EFBFBD><C5BB>ѳ<EFBFBD>ʼ<EFBFBD><CABC>
// //2<><32><EFBFBD><EFBFBD><EFBFBD>ӻ<EFBFBD><D3BB>ѳ<EFBFBD>ʼ<EFBFBD><CABC>
// if(Wake_Up_Flag==0)
// {
// EEPROM_ReadBytes(140,&Wake_Up_Flag,1);
// if(Wake_Up_Flag==0)
// {
// Wake_Up_Flag=0;
// }else Wake_Up_Flag=2;
//
// }
//
// switch (Wake_Up_Flag)
// {
// case 0: bsp_init_first();//<2F>ϵ绽<CFB5><E7BBBD>
// break;
// case 1: bsp_init_wakeup();//<2F><><EFBFBD>Ż<EFBFBD><C5BB><EFBFBD>
// break;
// case 2: bsp_init();//<2F><><EFBFBD>ӻ<EFBFBD><D3BB><EFBFBD>
// break;
// default: break;
// }
//}
//void process(void)
//{
// u8 times=0;
///**************
// <20><>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD> ֱ<><D6B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// wake_up<75><70><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>WIFI<46><49><EFBFBD>ݴ<EFBFBD><DDB4><EFBFBD><E4BCB0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģʽ
//*****************/
//
///**************<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD>õIJ<C3B5><C4B2><EFBFBD><EFBFBD><EFBFBD>*****************/
//
///**************GPSģ<53><C4A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*****************/
//
///**************<2A><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*****************/
///**************<2A><><EFBFBD>ݴ<EFBFBD><DDB4><EFBFBD>*****************/
//
///**************TF<54><46><EFBFBD><EFBFBD><E6B4A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>+<2B><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݣ<EFBFBD>*****************/
//
///**************BC25Զ<35>̴<EFBFBD><CCB4><EFBFBD>*****************/
//
///**************WIFI<46><49><EFBFBD><EFBFBD>*****************/
//
///**************<2A>͹<EFBFBD><CDB9>Ĵ<EFBFBD><C4B4><EFBFBD>*****************/
//
//
// //<2F><EFBFBD><E8B1B8><EFBFBD><EFBFBD>ǰ<EFBFBD>ij<EFBFBD>ʼ<EFBFBD><CABC>
// Wake_Up_Flag=0;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѱ<EFBFBD>־
// L76X_POWER_ON(); //<2F><><EFBFBD><EFBFBD>Ԥ<EFBFBD><D4A4>
// sdi12_process();
// PWR_CTRLADC_H;//<2F><><EFBFBD><EFBFBD>ADC<44><43>ԴԤ<D4B4><D4A4>
// ADC15_Init();
// while((times<60)&(!Save_Data.isUsefull))
// {
// //<2F>ȴ<EFBFBD>GPS<50>ź<EFBFBD>
// delay_ms(1000);
// if(Save_Data.isGetData)
// parseGpsBuffer();
// times++;
// }
// L76X_POWER_OFF();//<2F>ر<EFBFBD>L76C<36><43>Դ
// sprintf(data_common1.ADC_DATA,"%f%s",Get_Adc_Average(15,1),",");
// PWR_CTRLTFWF_H;//<2F><><EFBFBD><EFBFBD>TF<54><46><EFBFBD><EFBFBD>Դ
// Data_Write_TF(filename);//<2F><><EFBFBD><EFBFBD>д<EFBFBD><D0B4>TF<54><46>
// // PWR_CTRLTFWF_L;//<2F>ر<EFBFBD>TF<54><46><EFBFBD><EFBFBD>Դ
// ADC15_POWEROFF();//<2F>ر<EFBFBD>ADC<44><43>Դ
// Set_GNSSTIME_Rtc();//<2F><><EFBFBD><EFBFBD>RTCʱ<43><CAB1>
//
//
// if(Init_Data_Equipment.Pub_Mode[0] !='0')
// {
//
// BC25_Init(); //<2F><>ʼ<EFBFBD><CABC>
// BC25_CloseSocket();//<2F>ر<EFBFBD><D8B1><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// BC25_CreateSokcet(Init_Data_Equipment.Bc25_Ip,Init_Data_Equipment.Bc25_Port);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// BC25_Senddata(strlen(data_common1.Time_DATA),(data_common1.Time_DATA));
// BC25_Senddata(strlen(data_common1.ADC_DATA),(data_common1.ADC_DATA));
// BC25_Senddata(strlen(data_common1.GPS_DATA),(data_common1.GPS_DATA));
// BC25_Senddata(strlen(data_common1.SDI_DATA),(data_common1.SDI_DATA));
// BC25_POWEROFF();//<2F>ػ<EFBFBD>
// }
// if(Init_Data_Equipment.Pub_Mode[1] !='0')
// {
// PWR_CTRLTFWF_H;//<2F><><EFBFBD><EFBFBD>TF<54><46><EFBFBD><EFBFBD>Դ
// ESP8266_Init(115200);
// times=0;
//
// ESP8266_AP_TCPServer_Config(Init_Data_Equipment.ESP8266_AP_SSIDs,
// Init_Data_Equipment.ESP8266_AP_PWDs,
// Init_Data_Equipment.ESP8266_AP_Ports);
// while(times<60) //60S<30>ȴ<EFBFBD><C8B4>ⲿ<EFBFBD><E2B2BF><EFBFBD><EFBFBD>WIFI
// {
// times++;
// delay_ms(1000);
// if(ESP8266_Get_LinkStatus()==2)times=61;
// }
// ESP8266_SendString(DISABLE,data_common1.Time_DATA,strlen(data_common1.Time_DATA),0);
// ESP8266_SendString(DISABLE,data_common1.ADC_DATA,strlen(data_common1.ADC_DATA),0);
// ESP8266_SendString(DISABLE,data_common1.GPS_DATA,strlen(data_common1.GPS_DATA),0);
// ESP8266_SendString(DISABLE,data_common1.SDI_DATA,strlen(data_common1.SDI_DATA),0);
//
// }
// PWR_CTRLTFWF_L;//<2F>ر<EFBFBD>TF<54><46><EFBFBD><EFBFBD>WIFI<46><49>Դ
// Wake_Up_Flag=2;
// EEPROM_WriteBytes(140,&Wake_Up_Flag,2);
// RtcWakeUpConfig((Init_Data_Equipment.Measure_Interval[0]-'0')*10000+
// (Init_Data_Equipment.Measure_Interval[0]-'0')*1000+
// (Init_Data_Equipment.Measure_Interval[0]-'0')*100+
// (Init_Data_Equipment.Measure_Interval[0]-'0')*10+
// (Init_Data_Equipment.Measure_Interval[0]-'0')*1
// );//<2F><><EFBFBD>û<EFBFBD><C3BB><EFBFBD>ʱ<EFBFBD><CAB1>
//
// PWR_CTRLTFWF_L;//<2F>ر<EFBFBD>TF<54><46><EFBFBD><EFBFBD>Դ
// PWR_CTRL3V3_L;//<2F>ر<EFBFBD><D8B1><EFBFBD>Χ3V3<56>ܵ<EFBFBD>Դ
//
// // PWR_EnterSTANDBYMode();//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>
// }

View File

@ -0,0 +1,19 @@
#ifndef __process_H
#define __process_H
#include "bsp.h"
#define KEY0_PRES 1 //KEY0<59><30><EFBFBD><EFBFBD>
#define KEY1_PRES 2 //KEY1<59><31><EFBFBD><EFBFBD>
#define KEY2_PRES 3 //KEY2<59><32><EFBFBD><EFBFBD>
#define WKUP_PRES 4 //KEY_UP<55><50><EFBFBD><EFBFBD>(<28><>WK_UP/KEY_UP)
extern u8 Wake_Up_Flag;//<2F><><EFBFBD>ѱ<EFBFBD>־ 0<>ϵ翪<CFB5><E7BFAA> 1<><31><EFBFBD>Ż<EFBFBD><C5BB><EFBFBD> 2 <20><><EFBFBD>ӻ<EFBFBD><D3BB><EFBFBD>
extern u8 Enable_SDI_RS232;
void process(void);
void Equitment_Init(void);
#endif

View File

@ -0,0 +1,23 @@
#include "pwr_ctrl.h" //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA>ͷ<EFBFBD>ļ<EFBFBD>
#include "delay.h" //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA>ͷ<EFBFBD>ļ<EFBFBD>
#include "pbdata.h"
/*-------------------------------------------------*/
/*------------------------------------------------*/
void PWR_CTRL_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE); //ʹ<><CAB9>PB<50>˿<EFBFBD>ʱ<EFBFBD><CAB1>
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; //<2F><><EFBFBD><EFBFBD>
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; //<2F><><EFBFBD><EFBFBD>
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_400KHz; //IO<49><4F><EFBFBD>ٶ<EFBFBD>Ϊ400KHz
GPIO_Init(GPIOA, &GPIO_InitStructure);
PWR_CTRLTFWF_L;//<2F>ر<EFBFBD>WIFI<46><49>TF<54><46><EFBFBD><EFBFBD>Դ
PWR_CTRL3V3_L;
}

View File

@ -0,0 +1,34 @@
#ifndef _PWR_CTRL_H
#define _PWR_CTRL_H
#include "stm32l1xx.h" //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA>ͷ<EFBFBD>ļ<EFBFBD>
#define PWR_CTRLADC_H GPIO_SetBits(GPIOB, GPIO_Pin_0) //<2F><><EFBFBD>ƿ<EFBFBD><C6BF><EFBFBD><EFBFBD><EFBFBD>ADC<44>IJ<EFBFBD><C4B2><EFBFBD><EFBFBD><EFBFBD>Դʹ<D4B4><CAB9>
#define PWR_CTRLADC_L GPIO_ResetBits(GPIOB, GPIO_Pin_0)
#define PWR_CTRLL76C_H GPIO_SetBits(GPIOB,GPIO_Pin_12) //L76C<36><43><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
#define PWR_CTRLL76C_L GPIO_ResetBits(GPIOB,GPIO_Pin_12)
#define PWR_CTRL3V3_H GPIO_SetBits(GPIOA,GPIO_Pin_4)//<2F><>Ƭ<EFBFBD><C6AC><EFBFBD><EFBFBD>Χ3V3<56><33>Դ<EFBFBD>ܿ<EFBFBD><DCBF><EFBFBD>
#define PWR_CTRL3V3_L GPIO_ResetBits(GPIOA,GPIO_Pin_4)
#define PWR_CTRL5V_H GPIO_SetBits(GPIOC,GPIO_Pin_0) //5V<35><56>Դ<EFBFBD><D4B4>9V<39><56>Դ<EFBFBD><D4B4><EFBFBD><EFBFBD>
#define PWR_CTRL5V_L GPIO_ResetBits(GPIOC,GPIO_Pin_0)
#define PWR_CTRLBC25_H GPIO_SetBits(GPIOB,GPIO_Pin_1) //BC25<32><35>Դ<EFBFBD><D4B4><EFBFBD><EFBFBD>
#define PWR_CTRLBC25_L GPIO_ResetBits(GPIOB,GPIO_Pin_1)
#define PWR_CTRLTFWF_H GPIO_SetBits(GPIOA,GPIO_Pin_12) //TF<54><46><EFBFBD><EFBFBD>WIFI<46><49>Դ<EFBFBD><D4B4><EFBFBD><EFBFBD>
#define PWR_CTRLTFWF_L GPIO_ResetBits(GPIOA,GPIO_Pin_12)
#define PWR_CTRL485_H GPIO_SetBits(GPIOC,GPIO_Pin_11) //485<38><35>Դ<EFBFBD><D4B4><EFBFBD><EFBFBD>
#define PWR_CTRL485_L GPIO_ResetBits(GPIOA,GPIO_Pin_11)
#define Enable_SdiRX GPIO_SetBits(GPIOB,GPIO_Pin_5);
#define Enable_SdiTX GPIO_ResetBits(GPIOB,GPIO_Pin_5);
#define RS485_TX_EN GPIO_ResetBits(GPIOA,GPIO_Pin_8);
#define RS485_RX_EN GPIO_SetBits(GPIOA,GPIO_Pin_8);
void PWR_CTRL_Init(void);
#endif

View File

@ -0,0 +1,310 @@
#include "sdi12.h"
#include "bsp.h"
Sdi_Fram_Record_Struct Sdi_Fram_Record_Structs;
/***********************/
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƣ<EFBFBD> Diable_Usart3_TX(void)
//<2F><><EFBFBD>ܸ<EFBFBD>λ<EFBFBD><CEBB><EFBFBD>ڣ<EFBFBD>PB10<31><30>Ϊ<EFBFBD><CEAA>ͨIO<49><4F>ʹ<EFBFBD><CAB9>
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><>
void Diable_Usart1_SDI(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_DeInit(USART1); //<2F><>λ<EFBFBD><CEBB><EFBFBD><EFBFBD>1
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE); //GPIOBʱ<42><CAB1>
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_ResetBits(GPIOB,GPIO_Pin_6);
//GPIO_SetBits(GPIOB,GPIO_Pin_7);
}
/***********************/
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƣ<EFBFBD> Enable_Usart3_TX(void)
//<2F><><EFBFBD><EFBFBD> <09><><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>3
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> baund,<2C><><EFBFBD>ڲ<EFBFBD><DAB2><EFBFBD><EFBFBD><EFBFBD>
void Enable_Usart1_SDI(void)
{
USART1_SDI_Configuration(1200);
}
/***********************/
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƣ<EFBFBD> Break_Sdi_Sensor(void)
//<2F><><EFBFBD><EFBFBD> <09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>break<61><6B><EFBFBD><EFBFBD>
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><>
void Break_Sdi_Sensor(void)
{
Enable_SdiTX;
GPIO_ResetBits(GPIOB,GPIO_Pin_6);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
delay_ms(20);
GPIO_SetBits(GPIOB,GPIO_Pin_6);
}
void Sdi_StartMeasure(void)
{
u8 i=0;
char temp_sdi[5]={'\0'};
for(i=0;i<9;i++)
{
memset(temp_sdi,0,5);
sprintf(temp_sdi,"%d%s",i,"M!");
Diable_Usart1_SDI();
Break_Sdi_Sensor();// <20><><EFBFBD>Ϳպźʹ<C5BA><CDB4><EFBFBD>
Enable_Usart1_SDI();
u1_printf("%s",temp_sdi);
delay_ms(8);
Enable_SdiRX;
delay_ms(500);
}
/*
Diable_Usart1_SDI();
Break_Sdi_Sensor();// <20><><EFBFBD>Ϳպźʹ<C5BA><CDB4><EFBFBD>
Enable_Usart1_SDI();
u1_printf("0M!");
delay_ms(8);
Enable_SdiRX;
<20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*/
}
char Sdi_readaddress(void)
{
char *str;
osMutexAcquire(SDI_MutexID,osWaitForever);
USART_RS232_DEinit();
Enable_SDI_RS232=0;
Diable_Usart1_SDI();
USART1_SDI_CLR_RXBuf();
Break_Sdi_Sensor();// <20><><EFBFBD>Ϳպźʹ<C5BA><CDB4><EFBFBD>
Enable_Usart1_SDI();
u1_printf("%s","?!");
delay_ms(8);
Enable_SdiRX;
delay_ms(500);
osMutexRelease(SDI_MutexID);
if((str=strstr(USART1_SDI_RX_BUF,"\r\n")) !=NULL)
{
str--;
return str[0];
}
return 0x7f;
}
void Sdi_chanegadd(char a,char b)
{
char tempadd_sdi[10]={'\0'};
osMutexAcquire(SDI_MutexID,osWaitForever);
sprintf(tempadd_sdi,"%c%c%c%c",a,'A',b,'!');
USART_RS232_DEinit();
Enable_SDI_RS232=0;
Diable_Usart1_SDI();
USART1_SDI_CLR_RXBuf();
Break_Sdi_Sensor();// <20><><EFBFBD>Ϳպźʹ<C5BA><CDB4><EFBFBD>
Enable_Usart1_SDI();
u1_printf("%s",tempadd_sdi);
delay_ms(8);
Enable_SdiRX;
delay_ms(500);
osMutexRelease(SDI_MutexID);
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<2C>ж<EFBFBD><D0B6>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݷ<EFBFBD><DDB7><EFBFBD>
u8 Sdi_Readone(char add)
{
char temp_sdi[5]={'\0'};
char *subStringP;
char *subStringN;
USART1_SDI_CLR_RXBuf();
memset(temp_sdi,0,5);
sprintf(temp_sdi,"%c%s",add,"D0!");
USART1_SDI_CLR_RXBuf();
Diable_Usart1_SDI();
Break_Sdi_Sensor();// <20><><EFBFBD>Ϳպźʹ<C5BA><CDB4><EFBFBD>
Enable_Usart1_SDI();
u1_printf("%s",temp_sdi);
delay_ms(8);
Enable_SdiRX;
delay_ms(500);
subStringP=strstr(USART1_SDI_RX_BUF,"+");
subStringN=strstr(USART1_SDI_RX_BUF,"-");
if((subStringP!=NULL)|(subStringN!=NULL))
return 0;
else return 1;
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
void Sdi_Read(void)
{
u8 i=0;
char temp_sdi[5]={'\0'};
for(i=0;i<9;i++)
{
USART1_SDI_CLR_RXBuf();
memset(temp_sdi,0,5);
sprintf(temp_sdi,"%d%s",i,"D0!");
USART1_SDI_CLR_RXBuf();
Diable_Usart1_SDI();
Break_Sdi_Sensor();// <20><><EFBFBD>Ϳպźʹ<C5BA><CDB4><EFBFBD>
Enable_Usart1_SDI();
u1_printf("%s",temp_sdi);
delay_ms(8);
Enable_SdiRX;
delay_ms(500);
Sdi_Par(i);
}
}
//<2F><><EFBFBD><EFBFBD>SDI<44><49><EFBFBD><EFBFBD>
void Sdi_Par(u8 add)
{
char *subStringP;
char *subStringN;
char *subString;
char *subStringNext;
char pos1_data[10],pos2_data[10],pos3_data[10];
Sdi_Fram_Record_Structs.Flag_finish_DATA=0;
if(strstr(USART1_SDI_RX_BUF,"\r\n"))//<2F><><EFBFBD>ݽ<EFBFBD><DDBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
memset(pos1_data,0,10);
memset(pos2_data,0,10);
memset(pos3_data,0,10);
/***********<2A>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ġ<EFBFBD>*************/
subStringP=strstr(USART1_SDI_RX_BUF,"+");
subStringN=strstr(USART1_SDI_RX_BUF,"-");
if(subStringP>subStringN)//POS1
{
subString=subStringP;
}else
{
//-<2D><>ǰ
subString=subStringN;
}
subStringP=strstr(subString+1,"+");
subStringN=strstr(subString+1,"-");
if(subStringP>subStringN)////POS2
{
subStringNext=subStringP;
}else
{
//-<2D><>ǰ
subStringNext=subStringN;
}
memcpy(pos1_data,subString,subStringNext-subString);//<2F><>ȡλ<C8A1><CEBB>1<EFBFBD><31><EFBFBD><EFBFBD>
subString=subStringNext;
subStringP=strstr(subString+1,"+");
subStringN=strstr(subString+1,"-");
if(subStringP>subStringN)////POS3
{
subStringNext=subStringP;
}else
{
//-<2D><>ǰ
subStringNext=subStringN;
}
memcpy(pos2_data,subString,subStringNext-subString);//<2F><>ȡλ<C8A1><CEBB>2<EFBFBD><32><EFBFBD><EFBFBD>
subString=subStringNext;
subStringNext=strstr(subString,"\r\n");
memcpy(pos3_data,subString,subStringNext-subString);//<2F><>ȡλ<C8A1><CEBB>3<EFBFBD><33><EFBFBD><EFBFBD>
/****************************/
// subStringP=strstr(USART1_SDI_RX_BUF,"+");
// subStringN=strstr(USART1_SDI_RX_BUF,"-");
// if(subStringP>subStringN)//+<2B><>ǰ
// {
// subString=subStringP;
// }else
// {
// //-<2D><>ǰ
// subString=subStringN;
// }
// subStringNext=strstr(subString,"\r\n");
switch (add)
{
// case 0: memcpy(Sdi_Fram_Record_Structs.Ch1_RX_BUF, subString, subStringNext - subString);break; //<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>0<EFBFBD><30><EFBFBD><EFBFBD>
// case 1: memcpy(Sdi_Fram_Record_Structs.Ch2_RX_BUF, subString, subStringNext - subString); break;//<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>1<EFBFBD><31><EFBFBD><EFBFBD>
// case 2: memcpy(Sdi_Fram_Record_Structs.Ch3_RX_BUF, subString, subStringNext - subString);break; //<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>2<EFBFBD><32><EFBFBD><EFBFBD>
// case 3: memcpy(Sdi_Fram_Record_Structs.Ch4_RX_BUF, subString, subStringNext - subString);break; //<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>3<EFBFBD><33><EFBFBD><EFBFBD>
// case 4: memcpy(Sdi_Fram_Record_Structs.Ch5_RX_BUF, subString, subStringNext - subString);break; //<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>4<EFBFBD><34><EFBFBD><EFBFBD>
// case 5: memcpy(Sdi_Fram_Record_Structs.Ch6_RX_BUF, subString, subStringNext - subString);break; //<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>5<EFBFBD><35><EFBFBD><EFBFBD>
// case 6: memcpy(Sdi_Fram_Record_Structs.Ch7_RX_BUF, subString, subStringNext - subString);break; //<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>6<EFBFBD><36><EFBFBD><EFBFBD>
// case 7: memcpy(Sdi_Fram_Record_Structs.Ch8_RX_BUF, subString, subStringNext - subString);break; //<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>7<EFBFBD><37><EFBFBD><EFBFBD>
// case 8: memcpy(Sdi_Fram_Record_Structs.Ch9_RX_BUF, subString, subStringNext - subString);break; //<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>8<EFBFBD><38><EFBFBD><EFBFBD>
// default:break;
case 0: sprintf(Sdi_Fram_Record_Structs.Ch1_RX_BUF, "%s,%s,%s", pos1_data,pos2_data,pos3_data);break; //<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>0<EFBFBD><30><EFBFBD><EFBFBD>
case 1: sprintf(Sdi_Fram_Record_Structs.Ch2_RX_BUF, "%s,%s,%s", pos1_data,pos2_data,pos3_data); break;//<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>1<EFBFBD><31><EFBFBD><EFBFBD>
case 2: sprintf(Sdi_Fram_Record_Structs.Ch3_RX_BUF, "%s,%s,%s", pos1_data,pos2_data,pos3_data);break; //<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>2<EFBFBD><32><EFBFBD><EFBFBD>
case 3: sprintf(Sdi_Fram_Record_Structs.Ch4_RX_BUF, "%s,%s,%s", pos1_data,pos2_data,pos3_data);break; //<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>3<EFBFBD><33><EFBFBD><EFBFBD>
case 4: sprintf(Sdi_Fram_Record_Structs.Ch5_RX_BUF, "%s,%s,%s", pos1_data,pos2_data,pos3_data);break; //<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>4<EFBFBD><34><EFBFBD><EFBFBD>
case 5: sprintf(Sdi_Fram_Record_Structs.Ch6_RX_BUF, "%s,%s,%s", pos1_data,pos2_data,pos3_data);break; //<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>5<EFBFBD><35><EFBFBD><EFBFBD>
case 6: sprintf(Sdi_Fram_Record_Structs.Ch7_RX_BUF, "%s,%s,%s", pos1_data,pos2_data,pos3_data);break; //<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>6<EFBFBD><36><EFBFBD><EFBFBD>
case 7: sprintf(Sdi_Fram_Record_Structs.Ch8_RX_BUF, "%s,%s,%s", pos1_data,pos2_data,pos3_data);break; //<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>7<EFBFBD><37><EFBFBD><EFBFBD>
case 8: sprintf(Sdi_Fram_Record_Structs.Ch9_RX_BUF, "%s,%s,%s", pos1_data,pos2_data,pos3_data);break; //<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>8<EFBFBD><38><EFBFBD><EFBFBD>
default:break;
}
Sdi_Fram_Record_Structs.Flag_finish_DATA=1;
}
}
void sdi12_buf_clear(void)
{
memset(Sdi_Fram_Record_Structs.Ch1_RX_BUF,0,sizeof(Sdi_Fram_Record_Structs.Ch1_RX_BUF));
memset(Sdi_Fram_Record_Structs.Ch2_RX_BUF,0,sizeof(Sdi_Fram_Record_Structs.Ch2_RX_BUF));
memset(Sdi_Fram_Record_Structs.Ch3_RX_BUF,0,sizeof(Sdi_Fram_Record_Structs.Ch3_RX_BUF));
memset(Sdi_Fram_Record_Structs.Ch4_RX_BUF,0,sizeof(Sdi_Fram_Record_Structs.Ch4_RX_BUF));
memset(Sdi_Fram_Record_Structs.Ch5_RX_BUF,0,sizeof(Sdi_Fram_Record_Structs.Ch5_RX_BUF));
memset(Sdi_Fram_Record_Structs.Ch6_RX_BUF,0,sizeof(Sdi_Fram_Record_Structs.Ch6_RX_BUF));
memset(Sdi_Fram_Record_Structs.Ch7_RX_BUF,0,sizeof(Sdi_Fram_Record_Structs.Ch7_RX_BUF));
memset(Sdi_Fram_Record_Structs.Ch8_RX_BUF,0,sizeof(Sdi_Fram_Record_Structs.Ch8_RX_BUF));
memset(Sdi_Fram_Record_Structs.Ch9_RX_BUF,0,sizeof(Sdi_Fram_Record_Structs.Ch9_RX_BUF));
}
void sdi12_process(void)
{
//u5_printf("start measure......\r\n");
osMutexAcquire(SDI_MutexID,osWaitForever);
//USART_DeInit(USART1);
Diable_Usart1_SDI();
USART_RS232_DEinit();
Enable_SDI_RS232=0;
sdi12_buf_clear();//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
Sdi_StartMeasure();//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
delay_ms(500);
Sdi_Read();//<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>
osMutexRelease(SDI_MutexID);
// u5_printf(" measure end......\r\n");
}

View File

@ -0,0 +1,47 @@
#ifndef __SDI12_H
#define __SDI12_H
#include "sys.h"
#include "general_type.h"
#include "stm32l1xx.h"
#include "stm32l1xx_gpio.h"
#include "stm32l1xx_rcc.h"
#include "usart.h"
#include "delay.h"
#include <stdlib.h>
#include <string.h>
#include "stdio.h"
void Diable_Usart1_SDI(void);
void Enable_Usart1_SDI(void);
void Enable_RX(void);
void Enable_TX(void);
void Break_Sdi_Sensor(void);
void Sdi_StartMeasure(void);
void Sdi_Read(void);
void Sdi_Par(u8 add);
void sdi12_buf_clear(void);
void sdi12_process(void);
char Sdi_readaddress(void);//<2F><>ѯ<EFBFBD><D1AF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ
void Sdi_chanegadd(char a,char b);//<2F>޸Ĵ<DEB8><C4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ
u8 Sdi_Readone(char add);
typedef struct //<2F><><EFBFBD><EFBFBD>֡<EFBFBD><EFBFBD><E1B9B9>
{
char Ch1_RX_BUF[30];
char Ch2_RX_BUF[30];
char Ch3_RX_BUF[30];
char Ch4_RX_BUF[30];
char Ch5_RX_BUF[30];
char Ch6_RX_BUF[30];
char Ch7_RX_BUF[30];
char Ch8_RX_BUF[30];
char Ch9_RX_BUF[30];
u8 Flag_finish_DATA;
}Sdi_Fram_Record_Struct;
extern Sdi_Fram_Record_Struct Sdi_Fram_Record_Structs;
#endif

View File

@ -0,0 +1,360 @@
/******************** (C) COPYRIGHT 2018 Designed by Captain *********************
* <20>ļ<EFBFBD><C4BC><EFBFBD> <20><>main.c
* <20><><EFBFBD><EFBFBD> : SD<53><44><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* ʵ<><CAB5>ƽ̨<C6BD><CCA8>STM32F105RBT6˫CAN<41><4E><EFBFBD><EFBFBD><EFBFBD><EFBFBD>V2.0
* <20><><EFBFBD><20><>ST3.5.0
* ʱ<><CAB1> <20><>2018-9-23
**********************************************************************************/
#include "SPI_SD_driver.h"
#include "spi.h"
u8 SD_Type=0;
////////////////////////////////////////////////////////////////////////////////
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>SPIģ<49><C4A3><EFBFBD>ij<EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EBA3AC><EFBFBD>ó<EFBFBD><C3B3><EFBFBD><EFBFBD><EFBFBD>ģʽ<C4A3><CABD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>SD<53><44>
////////////////////////////////////////////////////////////////////////////////
//<2F><>ֲʱ<D6B2><CAB1><EFBFBD>Ľӿ<C4BD>
//data:Ҫд<D2AA><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//<2F><><EFBFBD><EFBFBD>ֵ:<3A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
u8 SD_SPI_ReadWriteByte(u8 data)
{
return SPI2_ReadWriteByte(data);
}
//SD<53><44><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>,<2C><>Ҫ<EFBFBD><D2AA><EFBFBD><EFBFBD>
void SD_SPI_SpeedLow(void)
{
SPI2_SetSpeed(SPI_BaudRatePrescaler_256);//<2F><><EFBFBD>õ<EFBFBD><C3B5><EFBFBD><EFBFBD><EFBFBD>ģʽ
}
//SD<53><44><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>,<2C><><EFBFBD>Ը<EFBFBD><D4B8><EFBFBD><EFBFBD><EFBFBD>
void SD_SPI_SpeedHigh(void)
{
SPI2_SetSpeed(SPI_BaudRatePrescaler_2);//<2F><><EFBFBD>õ<EFBFBD><C3B5><EFBFBD><EFBFBD><EFBFBD>ģʽ
}
/**********************************************
*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƣ<EFBFBD>void SPI_Configuration(void)
*<2A><><EFBFBD>ڲ<EFBFBD><DAB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*<2A><><EFBFBD>ڲ<EFBFBD><DAB2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
*<2A><><EFBFBD><EFBFBD>ֵ <20><><EFBFBD><EFBFBD>
*<2A><><EFBFBD><EFBFBD>˵<EFBFBD><CBB5><EFBFBD><EFBFBD>SPIģ<49><C4A3><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>IO<49>ڵij<DAB5>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>
**********************************************/
void SD_SPI_Init(void)
{
// GPIO_InitTypeDef GPIO_InitStructure;
// GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;//<2F><><EFBFBD><EFBFBD>
// GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;//<2F><><EFBFBD><EFBFBD>
// GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;//ʱ<><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
// GPIO_Init(GPIOA, &GPIO_InitStructure);
//
// GPIO_SetBits(GPIOC,GPIO_Pin_4);
// GPIO_SetBits(GPIOA,GPIO_Pin_8);
SPI2_Init();
//SPI1_Init();
SPI2_SetSpeed(7);
}
//ȡ<><C8A1>ѡ<EFBFBD><D1A1>,<2C>ͷ<EFBFBD>SPI<50><49><EFBFBD><EFBFBD>
void SD_DisSelect(void)
{
SD_CS_DISABLE() ;
SD_SPI_ReadWriteByte(0xff);//<2F><EFBFBD><E1B9A9><EFBFBD><EFBFBD><EFBFBD><EFBFBD>8<EFBFBD><38>ʱ<EFBFBD><CAB1>
}
//ѡ<><D1A1>sd<73><64>,<2C><><EFBFBD>ҵȴ<D2B5><C8B4><EFBFBD>׼<EFBFBD><D7BC>OK
//<2F><><EFBFBD><EFBFBD>ֵ:0,<2C>ɹ<EFBFBD>;1,ʧ<><CAA7>;
u8 SD_Select(void)
{
SD_CS_ENABLE();
if(SD_WaitReady()==0)return 0;//<2F>ȴ<EFBFBD><C8B4>ɹ<EFBFBD>
SD_DisSelect();
return 1;//<2F>ȴ<EFBFBD>ʧ<EFBFBD><CAA7>
}
//<2F>ȴ<EFBFBD><C8B4><EFBFBD>׼<EFBFBD><D7BC><EFBFBD><EFBFBD>
//<2F><><EFBFBD><EFBFBD>ֵ:0,׼<><D7BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>;<3B><><EFBFBD><EFBFBD>,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
u8 SD_WaitReady(void)
{
u32 t=0;
do
{
if(SD_SPI_ReadWriteByte(0XFF)==0XFF)return 0;//OK
t++;
}while(t<0XFFFFFF);//<2F>ȴ<EFBFBD>
return 1;
}
//<2F>ȴ<EFBFBD>SD<53><44><EFBFBD><EFBFBD>Ӧ
//Response:Ҫ<>õ<EFBFBD><C3B5>Ļ<EFBFBD>Ӧֵ
//<2F><><EFBFBD><EFBFBD>ֵ:0,<2C>ɹ<EFBFBD><C9B9>õ<EFBFBD><C3B5>˸û<CBB8>Ӧֵ
// <20><><EFBFBD><EFBFBD>,<2C>õ<EFBFBD><C3B5><EFBFBD>Ӧֵʧ<D6B5><CAA7>
u8 SD_GetResponse(u8 Response)
{
u16 Count=0xFFFF;//<2F>ȴ<EFBFBD><C8B4><EFBFBD><EFBFBD><EFBFBD>
while ((SD_SPI_ReadWriteByte(0XFF)!=Response)&&Count)Count--;//<2F>ȴ<EFBFBD><C8B4>õ<EFBFBD>׼ȷ<D7BC>Ļ<EFBFBD>Ӧ
if (Count==0)return MSD_RESPONSE_FAILURE;//<2F>õ<EFBFBD><C3B5><EFBFBD>Ӧʧ<D3A6><CAA7>
else return MSD_RESPONSE_NO_ERROR;//<2F><>ȷ<EFBFBD><C8B7>Ӧ
}
//<2F><>sd<73><64><EFBFBD><EFBFBD>ȡһ<C8A1><D2BB><EFBFBD><EFBFBD><EFBFBD>ݰ<EFBFBD><DDB0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//buf:<3A><><EFBFBD>ݻ<EFBFBD><DDBB><EFBFBD><EFBFBD><EFBFBD>
//len:Ҫ<><D2AA>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><DDB3><EFBFBD>.
//<2F><><EFBFBD><EFBFBD>ֵ:0,<2C>ɹ<EFBFBD>;<3B><><EFBFBD><EFBFBD><><CAA7>;
u8 SD_RecvData(u8*buf,u16 len)
{
if(SD_GetResponse(0xFE))return 1;//<2F>ȴ<EFBFBD>SD<53><44><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>0xFE
while(len--)//<2F><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
*buf=SPI2_ReadWriteByte(0xFF);
buf++;
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>2<EFBFBD><32>αCRC<52><43>dummy CRC<52><43>
SD_SPI_ReadWriteByte(0xFF);
SD_SPI_ReadWriteByte(0xFF);
return 0;//<2F><>ȡ<EFBFBD>ɹ<EFBFBD>
}
//<2F><>sd<73><64>д<EFBFBD><D0B4>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD>ݰ<EFBFBD><DDB0><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 512<31>ֽ<EFBFBD>
//buf:<3A><><EFBFBD>ݻ<EFBFBD><DDBB><EFBFBD><EFBFBD><EFBFBD>
//cmd:ָ<><D6B8>
//<2F><><EFBFBD><EFBFBD>ֵ:0,<2C>ɹ<EFBFBD>;<3B><><EFBFBD><EFBFBD><><CAA7>;
u8 SD_SendBlock(u8*buf,u8 cmd)
{
u16 t;
if(SD_WaitReady())return 1;//<2F>ȴ<EFBFBD>׼<EFBFBD><D7BC>ʧЧ
SD_SPI_ReadWriteByte(cmd);
if(cmd!=0XFD)//<2F><><EFBFBD>ǽ<EFBFBD><C7BD><EFBFBD>ָ<EFBFBD><D6B8>
{
for(t=0;t<512;t++)SPI2_ReadWriteByte(buf[t]);//<2F><><EFBFBD><EFBFBD><EFBFBD>ٶ<EFBFBD>,<2C><><EFBFBD>ٺ<EFBFBD><D9BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
SD_SPI_ReadWriteByte(0xFF);//<2F><><EFBFBD><EFBFBD>crc
SD_SPI_ReadWriteByte(0xFF);
t=SD_SPI_ReadWriteByte(0xFF);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ
if((t&0x1F)!=0x05)return 2;//<2F><>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD>
}
return 0;//д<><D0B4><EFBFBD>ɹ<EFBFBD>
}
//<2F><>SD<53><44><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//<2F><><EFBFBD><EFBFBD>: u8 cmd <20><><EFBFBD><EFBFBD>
// u32 arg <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// u8 crc crcУ<63><D0A3>ֵ
//<2F><><EFBFBD><EFBFBD>ֵ:SD<53><44><EFBFBD><EFBFBD><EFBFBD>ص<EFBFBD><D8B5><EFBFBD>Ӧ
u8 SD_SendCmd(u8 cmd, u32 arg, u8 crc)
{
u8 r1;
u8 Retry=0;
SD_DisSelect();//ȡ<><C8A1><EFBFBD>ϴ<EFBFBD>Ƭѡ
if(SD_Select())return 0XFF;//ƬѡʧЧ
//<2F><><EFBFBD><EFBFBD>
SD_SPI_ReadWriteByte(cmd | 0x40);//<2F>ֱ<EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
SD_SPI_ReadWriteByte(arg >> 24);
SD_SPI_ReadWriteByte(arg >> 16);
SD_SPI_ReadWriteByte(arg >> 8);
SD_SPI_ReadWriteByte(arg);
SD_SPI_ReadWriteByte(crc);
if(cmd==CMD12)SD_SPI_ReadWriteByte(0xff);//Skip a stuff byte when stop reading
//<2F>ȴ<EFBFBD><C8B4><EFBFBD>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD>˳<EFBFBD>
Retry=0X1F;
do
{
r1=SD_SPI_ReadWriteByte(0xFF);
}while((r1&0X80) && Retry--);
//<2F><><EFBFBD><EFBFBD>״ֵ̬
return r1;
}
//<2F><>ȡSD<53><44><EFBFBD><EFBFBD>CID<49><44>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
//<2F><><EFBFBD><EFBFBD>: u8 *cid_data(<28><><EFBFBD><EFBFBD>CID<49><44><EFBFBD>ڴ棬<DAB4><E6A3AC><EFBFBD><EFBFBD>16Byte<74><65>
//<2F><><EFBFBD><EFBFBD>ֵ:0<><30>NO_ERR
// 1<><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
u8 SD_GetCID(u8 *cid_data)
{
u8 r1;
//<2F><>CMD10<31><30><EFBFBD><EFBFBD><EEA3AC>CID
r1=SD_SendCmd(CMD10,0,0x01);
if(r1==0x00)
{
r1=SD_RecvData(cid_data,16);//<2F><><EFBFBD><EFBFBD>16<31><36><EFBFBD>ֽڵ<D6BD><DAB5><EFBFBD><EFBFBD><EFBFBD>
}
SD_DisSelect();//ȡ<><C8A1>Ƭѡ
if(r1)return 1;
else return 0;
}
//<2F><>ȡSD<53><44><EFBFBD><EFBFBD>CSD<53><44>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ٶ<EFBFBD><D9B6><EFBFBD>Ϣ
//<2F><><EFBFBD><EFBFBD>:u8 *cid_data(<28><><EFBFBD><EFBFBD>CID<49><44><EFBFBD>ڴ棬<DAB4><E6A3AC><EFBFBD><EFBFBD>16Byte<74><65>
//<2F><><EFBFBD><EFBFBD>ֵ:0<><30>NO_ERR
// 1<><31><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
u8 SD_GetCSD(u8 *csd_data)
{
u8 r1;
r1=SD_SendCmd(CMD9,0,0x01);//<2F><>CMD9<44><39><EFBFBD><EFBFBD><EEA3AC>CSD
if(r1==0)
{
r1=SD_RecvData(csd_data, 16);//<2F><><EFBFBD><EFBFBD>16<31><36><EFBFBD>ֽڵ<D6BD><DAB5><EFBFBD><EFBFBD><EFBFBD>
}
SD_DisSelect();//ȡ<><C8A1>Ƭѡ
if(r1)return 1;
else return 0;
}
//<2F><>ȡSD<53><44><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//<2F><><EFBFBD><EFBFBD>ֵ:0<><30> ȡ<><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// <20><><EFBFBD><EFBFBD>:SD<53><44><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(<28><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>/512<31>ֽ<EFBFBD>)
//ÿ<><C3BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֽ<EFBFBD><D6BD><EFBFBD><EFBFBD><EFBFBD>Ϊ512<31><32><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>512<31><32><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͨ<EFBFBD><CDA8>.
u32 SD_GetSectorCount(void)
{
u8 csd[16];
u32 Capacity;
u8 n;
u16 csize;
//ȡCSD<53><44>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڼ<EFBFBD><DABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>0
if(SD_GetCSD(csd)!=0) return 0;
//<2F><><EFBFBD><EFBFBD>ΪSDHC<48><43><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ<E6B7BD><CABD><EFBFBD><EFBFBD>
if((csd[0]&0xC0)==0x40) //V2.00<EFBFBD>Ŀ<EFBFBD>
{
csize = csd[9] + ((u16)csd[8] << 8) + 1;
Capacity = (u32)csize << 10;//<2F>õ<EFBFBD><C3B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
}else//V1.XX<58>Ŀ<EFBFBD>
{
n = (csd[5] & 15) + ((csd[10] & 128) >> 7) + ((csd[9] & 3) << 1) + 2;
csize = (csd[8] >> 6) + ((u16)csd[7] << 2) + ((u16)(csd[6] & 3) << 10) + 1;
Capacity= (u32)csize << (n - 9);//<2F>õ<EFBFBD><C3B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
}
return Capacity;
}
//<2F><>ʼ<EFBFBD><CABC>SD<53><44>
u8 SD_Initialize(void)
{
u8 r1; // <20><><EFBFBD><EFBFBD>SD<53><44><EFBFBD>ķ<EFBFBD><C4B7><EFBFBD>ֵ
u16 retry; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>г<EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>
u8 buf[4];
u16 i;
SD_SPI_Init(); //<2F><>ʼ<EFBFBD><CABC>IO
SD_SPI_SpeedLow(); //<2F><><EFBFBD>õ<EFBFBD><C3B5><EFBFBD><EFBFBD><EFBFBD>ģʽ
for(i=0;i<10;i++)SD_SPI_ReadWriteByte(0XFF);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>74<37><34><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
retry=20;
do
{
r1=SD_SendCmd(CMD0,0,0x95);//<2F><><EFBFBD><EFBFBD>IDLE״̬
}while((r1!=0X01) && retry--);
SD_Type=0;//Ĭ<><C4AC><EFBFBD>޿<EFBFBD>
if(r1==0X01)
{
if(SD_SendCmd(CMD8,0x1AA,0x87)==1)//SD V2.0
{
for(i=0;i<4;i++)buf[i]=SD_SPI_ReadWriteByte(0XFF); //Get trailing return value of R7 resp
if(buf[2]==0X01&&buf[3]==0XAA)//<2F><><EFBFBD>Ƿ<EFBFBD>֧<EFBFBD><D6A7>2.7~3.6V
{
retry=0XFFFE;
do
{
SD_SendCmd(CMD55,0,0X01); //<2F><><EFBFBD><EFBFBD>CMD55
r1=SD_SendCmd(CMD41,0x40000000,0X01);//<2F><><EFBFBD><EFBFBD>CMD41
}while(r1&&retry--);
if(retry&&SD_SendCmd(CMD58,0,0X01)==0)//<2F><><EFBFBD><EFBFBD>SD2.0<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ
{
for(i=0;i<4;i++)buf[i]=SD_SPI_ReadWriteByte(0XFF);//<2F>õ<EFBFBD>OCRֵ
if(buf[0]&0x40)SD_Type=SD_TYPE_V2HC; //<2F><><EFBFBD><EFBFBD>CCS
else SD_Type=SD_TYPE_V2;
}
}
}else//SD V1.x/ MMC V3
{
SD_SendCmd(CMD55,0,0X01); //<2F><><EFBFBD><EFBFBD>CMD55
r1=SD_SendCmd(CMD41,0,0X01); //<2F><><EFBFBD><EFBFBD>CMD41
if(r1<=1)
{
SD_Type=SD_TYPE_V1;
retry=0XFFFE;
do //<2F>ȴ<EFBFBD><C8B4>˳<EFBFBD>IDLEģʽ
{
SD_SendCmd(CMD55,0,0X01); //<2F><><EFBFBD><EFBFBD>CMD55
r1=SD_SendCmd(CMD41,0,0X01);//<2F><><EFBFBD><EFBFBD>CMD41
}while(r1&&retry--);
}else
{
SD_Type=SD_TYPE_MMC;//MMC V3
retry=0XFFFE;
do //<2F>ȴ<EFBFBD><C8B4>˳<EFBFBD>IDLEģʽ
{
r1=SD_SendCmd(CMD1,0,0X01);//<2F><><EFBFBD><EFBFBD>CMD1
}while(r1&&retry--);
}
if(retry==0||SD_SendCmd(CMD16,512,0X01)!=0)SD_Type=SD_TYPE_ERR;//<2F><><EFBFBD><EFBFBD><EFBFBD>Ŀ<EFBFBD>
}
}
SD_DisSelect();//ȡ<><C8A1>Ƭѡ
SD_SPI_SpeedHigh();//<2F><><EFBFBD><EFBFBD>
if(SD_Type)return 0;
else if(r1)return r1;
return 0xaa;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
}
//<2F><>SD<53><44>
//buf:<3A><><EFBFBD>ݻ<EFBFBD><DDBB><EFBFBD><EFBFBD><EFBFBD>
//sector:<3A><><EFBFBD><EFBFBD>
//cnt:<3A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//<2F><><EFBFBD><EFBFBD>ֵ:0,ok;<3B><><EFBFBD><EFBFBD><><CAA7>.
u8 SD_ReadDisk(u8*buf,u32 sector,u8 cnt)
{
u8 r1;
if(SD_Type!=SD_TYPE_V2HC)sector <<= 9;//ת<><D7AA>Ϊ<EFBFBD>ֽڵ<D6BD>ַ
if(cnt==1)
{
r1=SD_SendCmd(CMD17,sector,0X01);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if(r1==0)//ָ<><EFBFBD>ͳɹ<CDB3>
{
r1=SD_RecvData(buf,512);//<2F><><EFBFBD><EFBFBD>512<31><32><EFBFBD>ֽ<EFBFBD>
}
}else
{
r1=SD_SendCmd(CMD18,sector,0X01);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
do
{
r1=SD_RecvData(buf,512);//<2F><><EFBFBD><EFBFBD>512<31><32><EFBFBD>ֽ<EFBFBD>
buf+=512;
}while(--cnt && r1==0);
SD_SendCmd(CMD12,0,0X01); //<2F><><EFBFBD><EFBFBD>ֹͣ<CDA3><D6B9><EFBFBD><EFBFBD>
}
SD_DisSelect();//ȡ<><C8A1>Ƭѡ
return r1;//
}
//дSD<53><44>
//buf:<3A><><EFBFBD>ݻ<EFBFBD><DDBB><EFBFBD><EFBFBD><EFBFBD>
//sector:<3A><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>
//cnt:<3A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//<2F><><EFBFBD><EFBFBD>ֵ:0,ok;<3B><><EFBFBD><EFBFBD><><CAA7>.
u8 SD_WriteDisk(u8*buf,u32 sector,u8 cnt)
{
u8 r1;
if(SD_Type!=SD_TYPE_V2HC)sector *= 512;//ת<><D7AA>Ϊ<EFBFBD>ֽڵ<D6BD>ַ
if(cnt==1)
{
r1=SD_SendCmd(CMD24,sector,0X01);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if(r1==0)//ָ<><EFBFBD>ͳɹ<CDB3>
{
r1=SD_SendBlock(buf,0xFE);//д512<31><32><EFBFBD>ֽ<EFBFBD>
}
}else
{
if(SD_Type!=SD_TYPE_MMC)
{
SD_SendCmd(CMD55,0,0X01);
SD_SendCmd(CMD23,cnt,0X01);//<2F><><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8>
}
r1=SD_SendCmd(CMD25,sector,0X01);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if(r1==0)
{
do
{
r1=SD_SendBlock(buf,0xFC);//<2F><><EFBFBD><EFBFBD>512<31><32><EFBFBD>ֽ<EFBFBD>
buf+=512;
}while(--cnt && r1==0);
r1=SD_SendBlock(0,0xFD);//<2F><><EFBFBD><EFBFBD>512<31><32><EFBFBD>ֽ<EFBFBD>
}
}
SD_DisSelect();//ȡ<><C8A1>Ƭѡ
return r1;//
}

View File

@ -0,0 +1,77 @@
#ifndef _SPI_SD_DRIVER_H_
#define _SPI_SD_DRIVER_H_
#include "stm32l1xx.h" //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA>ͷ<EFBFBD>ļ<EFBFBD>
#include "bsp.h"
//typedef uint32_t u32;
//typedef uint16_t u16;
//typedef uint8_t u8;
/* Private define ------------------------------------------------------------*/
/* SPI<50><49><EFBFBD><EFBFBD><EFBFBD>ٶ<EFBFBD><D9B6><EFBFBD><EFBFBD><EFBFBD>*/
#define SPI_SPEED_LOW 0
#define SPI_SPEED_HIGH 1
// SD<53><44><EFBFBD><EFBFBD><EFBFBD>Ͷ<EFBFBD><CDB6><EFBFBD>
#define SD_TYPE_ERR 0X00
#define SD_TYPE_MMC 0X01
#define SD_TYPE_V1 0X02
#define SD_TYPE_V2 0X04
#define SD_TYPE_V2HC 0X06
// SD<53><44>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD>
#define CMD0 0 //<2F><><EFBFBD><EFBFBD>λ
#define CMD1 1
#define CMD8 8 //<2F><><EFBFBD><EFBFBD>8 <20><>SEND_IF_COND
#define CMD9 9 //<2F><><EFBFBD><EFBFBD>9 <20><><EFBFBD><EFBFBD>CSD<53><44><EFBFBD><EFBFBD>
#define CMD10 10 //<2F><><EFBFBD><EFBFBD>10<31><30><EFBFBD><EFBFBD>CID<49><44><EFBFBD><EFBFBD>
#define CMD12 12 //<2F><><EFBFBD><EFBFBD>12<31><32>ֹͣ<CDA3><D6B9><EFBFBD>ݴ<EFBFBD><DDB4><EFBFBD>
#define CMD16 16 //<2F><><EFBFBD><EFBFBD>16<31><36><EFBFBD><EFBFBD><EFBFBD><EFBFBD>SectorSize Ӧ<><D3A6><EFBFBD><EFBFBD>0x00
#define CMD17 17 //<2F><><EFBFBD><EFBFBD>17<31><37><EFBFBD><EFBFBD>sector
#define CMD18 18 //<2F><><EFBFBD><EFBFBD>18<31><38><EFBFBD><EFBFBD>Multi sector
#define CMD23 23 //<2F><><EFBFBD><EFBFBD>23<32><33><EFBFBD><EFBFBD><EFBFBD>ö<EFBFBD>sectorд<72><D0B4>ǰԤ<C7B0>Ȳ<EFBFBD><C8B2><EFBFBD>N<EFBFBD><4E>block
#define CMD24 24 //<2F><><EFBFBD><EFBFBD>24<32><34>дsector
#define CMD25 25 //<2F><><EFBFBD><EFBFBD>25<32><35>дMulti sector
#define CMD41 41 //<2F><><EFBFBD><EFBFBD>41<34><31>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD>0x00
#define CMD55 55 //<2F><><EFBFBD><EFBFBD>55<35><35>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD>0x01
#define CMD58 58 //<2F><><EFBFBD><EFBFBD>58<35><38><EFBFBD><EFBFBD>OCR<43><52>Ϣ
#define CMD59 59 //<2F><><EFBFBD><EFBFBD>59<35><39>ʹ<EFBFBD><CAB9>/<2F><>ֹCRC<52><43>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD>0x00
//<2F><><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD><EFBFBD>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
#define MSD_DATA_OK 0x05
#define MSD_DATA_CRC_ERROR 0x0B
#define MSD_DATA_WRITE_ERROR 0x0D
#define MSD_DATA_OTHER_ERROR 0xFF
//SD<53><44><EFBFBD><EFBFBD>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
#define MSD_RESPONSE_NO_ERROR 0x00
#define MSD_IN_IDLE_STATE 0x01
#define MSD_ERASE_RESET 0x02
#define MSD_ILLEGAL_COMMAND 0x04
#define MSD_COM_CRC_ERROR 0x08
#define MSD_ERASE_SEQUENCE_ERROR 0x10
#define MSD_ADDRESS_ERROR 0x20
#define MSD_PARAMETER_ERROR 0x40
#define MSD_RESPONSE_FAILURE 0xFF
//<2F>ⲿ<EFBFBD><E2B2BF>Ӧ<EFBFBD><D3A6><EFBFBD>ݾ<EFBFBD><DDBE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>޸<EFBFBD>!
//Mini STM32ʹ<32>õ<EFBFBD><C3B5><EFBFBD>PA3<41><33>ΪSD<53><44><EFBFBD><EFBFBD>CS<43><53>.
#define SD_CS_ENABLE() GPIO_ResetBits(GPIOC,GPIO_Pin_6) //ѡ<><D1A1>SD<53><44>
#define SD_CS_DISABLE() GPIO_SetBits(GPIOC,GPIO_Pin_6) //<2F><>ѡ<EFBFBD><D1A1>SD<53><44>
extern u8 SD_Type;//SD<53><44><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
/* Private function prototypes -----------------------------------------------*/
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
void SD_SPI_Init(void);
u8 SD_SPI_ReadWriteByte(u8 data);
void SD_SPI_SpeedLow(void);
void SD_SPI_SpeedHigh(void);
u8 SD_WaitReady(void); //<2F>ȴ<EFBFBD>SD<53><44>׼<EFBFBD><D7BC>
u8 SD_GetResponse(u8 Response); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ
u8 SD_Initialize(void); //<2F><>ʼ<EFBFBD><CABC>
u8 SD_ReadDisk(u8*buf,u32 sector,u8 cnt); //<2F><><EFBFBD><EFBFBD>
u8 SD_WriteDisk(u8*buf,u32 sector,u8 cnt); //д<><D0B4>
u32 SD_GetSectorCount(void); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
u8 SD_GetCID(u8 *cid_data); //<2F><>SD<53><44>CID
u8 SD_GetCSD(u8 *csd_data); //<2F><>SD<53><44>CSD
#endif

105
IAPV1.1/Driver/spi/spi.c Normal file
View File

@ -0,0 +1,105 @@
#include "spi.h"
void SPI2_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
SPI_InitTypeDef SPI_InitStructure;
// /* Enable SCK, MOSI and MISO GPIO clocks */
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOC|RCC_AHBPeriph_GPIOB, ENABLE);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;//<2F><><EFBFBD><EFBFBD>
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;//<2F><><EFBFBD><EFBFBD>
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;//ʱ<><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
GPIO_Init(GPIOC, &GPIO_InitStructure);
GPIO_SetBits(GPIOC, GPIO_Pin_6);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;//<2F><><EFBFBD><EFBFBD>
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;//<2F><><EFBFBD><EFBFBD>
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;//ʱ<><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_SetBits(GPIOB, GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15);
GPIO_PinAFConfig(GPIOB, GPIO_PinSource13, GPIO_AF_SPI2);
GPIO_PinAFConfig(GPIOB, GPIO_PinSource14, GPIO_AF_SPI2);
GPIO_PinAFConfig(GPIOB, GPIO_PinSource15, GPIO_AF_SPI2);
// GPIO_PinAFConfig(GPIOC, GPIO_PinSource7, GPIO_AF_SPI2);//GPIO_PinSource7
/* SPI configuration -------------------------------------------------------*/
// SPI_I2S_DeInit(SPI2);
/* Enable the SPI periph */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2, ENABLE);
SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;//SPI<50><49><EFBFBD><EFBFBD>Ϊ˫<CEAA><CBAB>˫<EFBFBD><CBAB>ȫ˫<C8AB><CBAB>
SPI_InitStructure.SPI_Mode = SPI_Mode_Master; //<2F><><EFBFBD><EFBFBD>SPI<50><49><EFBFBD><EFBFBD>ģʽ:<3A><><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA>spi
SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low;
SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge;
SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_8;
SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
SPI_InitStructure.SPI_CRCPolynomial = 7;
SPI_Init(SPI2, &SPI_InitStructure);
SPI_Cmd(SPI2, ENABLE); //ʹ<><CAB9>SPI<50><49><EFBFBD><EFBFBD>
// SPI2_SetSpeed(1);
// SPI2_ReadWrite(0xff);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
}
//SPI2<49>ٶ<EFBFBD><D9B6><EFBFBD><EFBFBD>ú<EFBFBD><C3BA><EFBFBD>
//SpeedSet:0~7
//SPI<50>ٶ<EFBFBD>=fAPB1/2^(SpeedSet+1)
//APB1ʱ<31><CAB1>һ<EFBFBD><D2BB>Ϊ36Mhz
void SPI2_SetSpeed(u8 SpeedSet)
{
SpeedSet&=0X07; //<2F><><EFBFBD>Ʒ<EFBFBD>Χ
SPI2->CR1&=0XFFC7;
SPI2->CR1|=SpeedSet<<3; //<2F><><EFBFBD><EFBFBD>SPI2<49>ٶ<EFBFBD>
SPI2->CR1|=1<<6; //SPI<50>ʹ<E8B1B8><CAB9>
}
//SPI <20>ٶ<EFBFBD><D9B6><EFBFBD><EFBFBD>ú<EFBFBD><C3BA><EFBFBD>
//SpeedSet:
//SPI_BaudRatePrescaler_2 2<><32>Ƶ (SPI 36M@sys 72M)
//SPI_BaudRatePrescaler_8 8<><38>Ƶ (SPI 9M@sys 72M)
//SPI_BaudRatePrescaler_16 16<31><36>Ƶ (SPI 4.5M@sys 72M)
//SPI_BaudRatePrescaler_256 256<35><36>Ƶ (SPI 281.25K@sys 72M)
//void SPI2_SetSpeed(u8 SpeedSet)
//{
// SPI_InitTypeDef SPI_InitStructure;
//
// SPI_InitStructure.SPI_BaudRatePrescaler = SpeedSet ;
// SPI_Init(SPI2, &SPI_InitStructure);
// SPI_Cmd(SPI2,ENABLE);
//}
//SPI2 <20><>дһ<D0B4><D2BB><EFBFBD>ֽ<EFBFBD>
//TxData:Ҫд<D2AA><D0B4><EFBFBD><EFBFBD><EFBFBD>ֽ<EFBFBD>
//<2F><><EFBFBD><EFBFBD>ֵ:<3A><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD>ֽ<EFBFBD>
u8 SPI2_ReadWriteByte(u8 TxData)
{
u16 retry=0;
while((SPI2->SR&1<<1)==0) //<2F>ȴ<EFBFBD><C8B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
retry++;
if(retry>=0XFFFE)return 0; //<2F><>ʱ<EFBFBD>˳<EFBFBD>
}
SPI2->DR=TxData; //<2F><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>byte
retry=0;
while((SPI2->SR&1<<0)==0) //<2F>ȴ<EFBFBD><C8B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>byte
{
retry++;
if(retry>=0XFFFE)return 0; //<2F><>ʱ<EFBFBD>˳<EFBFBD>
}
return SPI2->DR; //<2F><><EFBFBD><EFBFBD><EFBFBD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
}

58
IAPV1.1/Driver/spi/spi.h Normal file
View File

@ -0,0 +1,58 @@
#ifndef __SPI_H
#define __SPI_H
#include "stm32l1xx.h"
#include "stm32l1xx_gpio.h"
#include "stm32l1xx_spi.h"
#include "stm32l1xx_rcc.h"
// SPI<50><49><EFBFBD><EFBFBD><EFBFBD>ٶ<EFBFBD><D9B6><EFBFBD><EFBFBD><EFBFBD>
#define SPI_SPEED_2 0
#define SPI_SPEED_4 1
#define SPI_SPEED_8 2
#define SPI_SPEED_16 3
#define SPI_SPEED_32 4
#define SPI_SPEED_64 5
#define SPI_SPEED_128 6
#define SPI_SPEED_256 7
#define u8 uint8_t
#define u16 uint16_t
void SPI2_Port_Init(void);
void SPI2_Init(void); //<2F><>ʼ<EFBFBD><CABC>SPI2<49><32>
void SPI2_SetSpeed(uint8_t SpeedSet); //<2F><><EFBFBD><EFBFBD>SPI2<49>ٶ<EFBFBD>
uint8_t SPI2_ReadWriteByte(uint8_t TxData);//SPI2<49><32><EFBFBD>߶<EFBFBD>дһ<D0B4><D2BB><EFBFBD>ֽ<EFBFBD>
#endif

View File

@ -0,0 +1,112 @@
#include "delay.h"
#include "sys.h"
#include <stdio.h>
#include "bsp.h"
//static u8 fac_us=0;//us<75><73>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//static u16 fac_ms=0;//ms<6D><73>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<2C><>ucos<6F><73>,<2C><><EFBFBD><EFBFBD>ÿ<EFBFBD><C3BF><EFBFBD><EFBFBD><EFBFBD>ĵ<EFBFBD>ms<6D><73>
//void SysTick_Handler(void)
//{
//
//}
//<2F><>ʼ<EFBFBD><CABC><EFBFBD>ӳٺ<D3B3><D9BA><EFBFBD>
//<2F><>ʹ<EFBFBD><CAB9>ucos<6F><73>ʱ<EFBFBD><CAB1>,<2C>˺<EFBFBD><CBBA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>ucos<6F><73>ʱ<EFBFBD>ӽ<EFBFBD><D3BD><EFBFBD>
//SYSTICK<43><4B>ʱ<EFBFBD>ӹ̶<D3B9>ΪHCLKʱ<4B>ӵ<EFBFBD>1/8
//SYSCLK:ϵͳʱ<CDB3><CAB1>
//void delay_init(u8 SYSCLK)
//{
// SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK);//<2F>ڲ<EFBFBD>ʱ<EFBFBD><CAB1>Դ
// // SysTick->CTRL&=~(1<<2); //SYSTICKʹ<4B><CAB9><EFBFBD>ⲿʱ<E2B2BF><CAB1>Դ
// fac_us=SYSCLK/8; //<2F><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD>ʹ<EFBFBD><CAB9>ucos,fac_us<75><73><EFBFBD><EFBFBD>Ҫʹ<D2AA><CAB9>
// fac_ms=(u16)fac_us*1000;//<2F><><EFBFBD><EFBFBD>ÿ<EFBFBD><C3BF>ms<6D><73>Ҫ<EFBFBD><D2AA>systickʱ<6B><CAB1><EFBFBD><EFBFBD>
//}
//void delay_init(void)
//{
// SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK_Div8); //ѡ<><D1A1><EFBFBD>ⲿʱ<E2B2BF><CAB1> HCLK/8
// fac_us=SystemCoreClock/8000000; //Ϊϵͳʱ<CDB3>ӵ<EFBFBD>1/8
//
// fac_ms=(u16)fac_us*1000;//<2F><>ucos<6F><73>,<2C><><EFBFBD><EFBFBD>ÿ<EFBFBD><C3BF>ms<6D><73>Ҫ<EFBFBD><D2AA>systickʱ<6B><CAB1><EFBFBD><EFBFBD>
//}
//<2F><>ʱnms
//ע<><D7A2>nms<6D>ķ<EFBFBD>Χ
//SysTick->LOADΪ24λ<34>Ĵ<EFBFBD><C4B4><EFBFBD>,<2C><><EFBFBD><EFBFBD>,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱΪ:
//nms<=0xffffff*8*1000/SYSCLK
//SYSCLK<4C><4B>λΪHz,nms<6D><73>λΪms
//<2F><>72M<32><4D><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,nms<=1864
//<2F><>ʱnus
//nusΪҪ<CEAA><D2AA>ʱ<EFBFBD><CAB1>us<75><73>.
//void delay_us(u32 nus)
//{
// u32 temp;
// SysTick->LOAD=nus*fac_us; //ʱ<><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// SysTick->VAL=0x00; //<2F><><EFBFBD>ռ<EFBFBD><D5BC><EFBFBD><EFBFBD><EFBFBD>
// SysTick->CTRL|=SysTick_CTRL_ENABLE_Msk ; //<2F><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>
// do
// {
// temp=SysTick->CTRL;
// }
// while(temp&0x01&&!(temp&(1<<16)));//<2F>ȴ<EFBFBD>ʱ<EFBFBD><EFBFBD><E4B5BD>
// SysTick->CTRL&=~SysTick_CTRL_ENABLE_Msk; //<2F>رռ<D8B1><D5BC><EFBFBD><EFBFBD><EFBFBD>
// SysTick->VAL =0X00; //<2F><><EFBFBD>ռ<EFBFBD><D5BC><EFBFBD><EFBFBD><EFBFBD>
//}
//<2F><>ʱnms
//ע<><D7A2>nms<6D>ķ<EFBFBD>Χ
//SysTick->LOADΪ24λ<34>Ĵ<EFBFBD><C4B4><EFBFBD>,<2C><><EFBFBD><EFBFBD>,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱΪ:
//nms<=0xffffff*8*1000/SYSCLK
//SYSCLK<4C><4B>λΪHz,nms<6D><73>λΪms
//<2F><>72M<32><4D><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,nms<=1864
//void delay_ms(u16 nms)
//{
// u32 temp;
// SysTick->LOAD=(u32)nms*fac_ms;//ʱ<><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(SysTick->LOADΪ24bit)
// SysTick->VAL =0x00; //<2F><><EFBFBD>ռ<EFBFBD><D5BC><EFBFBD><EFBFBD><EFBFBD>
// SysTick->CTRL|=SysTick_CTRL_ENABLE_Msk ; //<2F><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD>
// do
// {
// temp=SysTick->CTRL;
// }
// while(temp&0x01&&!(temp&(1<<16)));//<2F>ȴ<EFBFBD>ʱ<EFBFBD><EFBFBD><E4B5BD>
// SysTick->CTRL&=~SysTick_CTRL_ENABLE_Msk; //<2F>رռ<D8B1><D5BC><EFBFBD><EFBFBD><EFBFBD>
// SysTick->VAL =0X00; //<2F><><EFBFBD>ռ<EFBFBD><D5BC><EFBFBD><EFBFBD><EFBFBD>
//}

View File

@ -0,0 +1,47 @@
#ifndef __DELAY_H
#define __DELAY_H
#include "stm32l1xx.h"
#include "general_type.h"
#include "bsp.h"
//void Delay_Ms(u16 nms);
//void delay_init(void);
#define delay_ms( _ulDelayTime) bsp_DelayMS( _ulDelayTime);
#define delay_us( _ulDelayTime) bsp_DelayUS( _ulDelayTime);
//#define delay_us() bsp_DelayUS(uint32_t _ulDelayTime);
//typedef bsp_DelayUS(uint32_t _ulDelayTime) delay_ms(uint32_t nms) ;
//typedef delay_us(uint32_t nus) bsp_DelayMS(uint32_t _ulDelayTime);
#endif

View File

@ -0,0 +1,178 @@
#include "sys.h"
void MY_NVIC_SetVectorTable(u32 NVIC_VectTab, u32 Offset)
{
SCB->VTOR = NVIC_VectTab|(Offset & (u32)0x1FFFFF80);//<2F><><EFBFBD><EFBFBD>NVIC<49><43><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƫ<EFBFBD>ƼĴ<C6BC><C4B4><EFBFBD>
//<2F><><EFBFBD>ڱ<EFBFBD>ʶ<EFBFBD><CAB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>CODE<44><45><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>RAM<41><4D>
}
//<2F><><EFBFBD><EFBFBD>NVIC<49><43><EFBFBD><EFBFBD>
//NVIC_Group:NVIC<49><43><EFBFBD><EFBFBD> 0~4 <20>ܹ<EFBFBD>5<EFBFBD><35>
void MY_NVIC_PriorityGroupConfig(u8 NVIC_Group)
{
u32 temp,temp1;
temp1=(~NVIC_Group)&0x07;//ȡ<><C8A1><EFBFBD><EFBFBD>λ
temp1<<=8;
temp=SCB->AIRCR; //<2F><>ȡ<EFBFBD><C8A1>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
temp&=0X0000F8FF; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD><EFBFBD>
temp|=0X05FA0000; //д<><D0B4>Կ<EFBFBD><D4BF>
temp|=temp1;
SCB->AIRCR=temp; //<2F><><EFBFBD>÷<EFBFBD><C3B7><EFBFBD>
}
//<2F><><EFBFBD><EFBFBD>NVIC
//NVIC_PreemptionPriority:<3A><>ռ<EFBFBD><D5BC><EFBFBD>ȼ<EFBFBD>
//NVIC_SubPriority :<3A><>Ӧ<EFBFBD><D3A6><EFBFBD>ȼ<EFBFBD>
//NVIC_Channel :<3A>жϱ<D0B6><CFB1><EFBFBD>
//NVIC_Group :<3A>жϷ<D0B6><CFB7><EFBFBD> 0~4
//ע<><D7A2><EFBFBD><EFBFBD><EFBFBD>ȼ<EFBFBD><C8BC><EFBFBD><EFBFBD>ܳ<EFBFBD><DCB3><EFBFBD><EFBFBD><EFBFBD><E8B6A8><EFBFBD><EFBFBD><EFBFBD>ķ<EFBFBD>Χ!<21><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EBB2BB><EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD>
//<2F><EFBFBD><E9BBAE>:
//<2F><>0:0λ<30><CEBB>ռ<EFBFBD><D5BC><EFBFBD>ȼ<EFBFBD>,4λ<34><CEBB>Ӧ<EFBFBD><D3A6><EFBFBD>ȼ<EFBFBD>
//<2F><>1:1λ<31><CEBB>ռ<EFBFBD><D5BC><EFBFBD>ȼ<EFBFBD>,3λ<33><CEBB>Ӧ<EFBFBD><D3A6><EFBFBD>ȼ<EFBFBD>
//<2F><>2:2λ<32><CEBB>ռ<EFBFBD><D5BC><EFBFBD>ȼ<EFBFBD>,2λ<32><CEBB>Ӧ<EFBFBD><D3A6><EFBFBD>ȼ<EFBFBD>
//<2F><>3:3λ<33><CEBB>ռ<EFBFBD><D5BC><EFBFBD>ȼ<EFBFBD>,1λ<31><CEBB>Ӧ<EFBFBD><D3A6><EFBFBD>ȼ<EFBFBD>
//<2F><>4:4λ<34><CEBB>ռ<EFBFBD><D5BC><EFBFBD>ȼ<EFBFBD>,0λ<30><CEBB>Ӧ<EFBFBD><D3A6><EFBFBD>ȼ<EFBFBD>
//NVIC_SubPriority<74><79>NVIC_PreemptionPriority<74><79>ԭ<EFBFBD><D4AD><EFBFBD><EFBFBD>,<2C><>ֵԽС<><D4BD><EFBFBD><EFBFBD>
void MY_NVIC_Init(u8 NVIC_PreemptionPriority,u8 NVIC_SubPriority,u8 NVIC_Channel,u8 NVIC_Group)
{
u32 temp;
u8 IPRADDR=NVIC_Channel/4; //ÿ<><C3BF>ֻ<EFBFBD>ܴ<EFBFBD>4<EFBFBD><34>,<2C>õ<EFBFBD><C3B5><EFBFBD><EFBFBD><EFBFBD>ַ
u8 IPROFFSET=NVIC_Channel%4;//<2F><><EFBFBD><EFBFBD><EFBFBD>ڵ<EFBFBD>ƫ<EFBFBD><C6AB>
IPROFFSET=IPROFFSET*8+4; //<2F>õ<EFBFBD>ƫ<EFBFBD>Ƶ<EFBFBD>ȷ<EFBFBD><C8B7>λ<EFBFBD><CEBB>
MY_NVIC_PriorityGroupConfig(NVIC_Group);//<2F><><EFBFBD>÷<EFBFBD><C3B7><EFBFBD>
temp=NVIC_PreemptionPriority<<(4-NVIC_Group);
temp|=NVIC_SubPriority&(0x0f>>NVIC_Group);
temp&=0xf;//ȡ<><C8A1><EFBFBD><EFBFBD>λ
if(NVIC_Channel<32)NVIC->ISER[0]|=1<<NVIC_Channel;//ʹ<><CAB9><EFBFBD>ж<EFBFBD>λ(Ҫ<><D2AA><EFBFBD><EFBFBD><EFBFBD>Ļ<EFBFBD>,<2C><EFBFBD><E0B7B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>OK)
else NVIC->ISER[1]|=1<<(NVIC_Channel-32);
NVIC->IP[IPRADDR]|=temp<<IPROFFSET;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><D3A6><EFBFBD>ȼ<EFBFBD><C8BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȼ<EFBFBD> IPR
}
//<2F>ⲿ<EFBFBD>ж<EFBFBD><D0B6><EFBFBD><EFBFBD>ú<EFBFBD><C3BA><EFBFBD>
//ֻ<><D6BB><EFBFBD><EFBFBD>GPIOA~G;<3B><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>PVD,RTC<54><43>USB<53><42><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//<2F><><EFBFBD><EFBFBD>:
//GPIOx:0~6,<2C><><EFBFBD><EFBFBD>GPIOA~G
//BITx:<3A><>Ҫʹ<D2AA>ܵ<EFBFBD>λ;
//TRIM:<3A><><EFBFBD><EFBFBD>ģʽ,1,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>;2,<2C>Ͻ<EFBFBD><CFBD><EFBFBD>;3<><33><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƽ<EFBFBD><C6BD><EFBFBD><EFBFBD>
//<2F>ú<EFBFBD><C3BA><EFBFBD>һ<EFBFBD><D2BB>ֻ<EFBFBD><D6BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>1<EFBFBD><31>IO<49><4F>,<2C><><EFBFBD><EFBFBD>IO<49><4F>,<2C><><EFBFBD><EFBFBD><EFBFBD>ε<EFBFBD><CEB5><EFBFBD>
//<2F>ú<EFBFBD><C3BA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD>ж<EFBFBD>,<2C>Լ<EFBFBD><D4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
void Ex_NVIC_Config(u8 GPIOx,u8 BITx,u8 TRIM)
{
u8 EXTADDR;
u8 EXTOFFSET;
EXTADDR=BITx/4;//<2F>õ<EFBFBD><C3B5>жϼĴ<CFBC><C4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ı<EFBFBD><C4B1><EFBFBD>
EXTOFFSET=(BITx%4)*4;
RCC->APB2ENR|=0x01;//ʹ<><CAB9>io<69><6F><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
SYSCFG->EXTICR[EXTADDR]&=~(0x000F<<EXTOFFSET);//<2F><><EFBFBD><EFBFBD>ԭ<EFBFBD><D4AD><EFBFBD><EFBFBD><EFBFBD>ã<EFBFBD><C3A3><EFBFBD><EFBFBD><EFBFBD>
SYSCFG->EXTICR[EXTADDR]|=GPIOx<<EXTOFFSET;//EXTI.BITxӳ<78>䵽GPIOx.BITx
//<2F>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD>
EXTI->IMR|=1<<BITx;// <20><><EFBFBD><EFBFBD>line BITx<54>ϵ<EFBFBD><CFB5>ж<EFBFBD>
//EXTI->EMR|=1<<BITx;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>line BITx<54>ϵ<EFBFBD><CFB5>¼<EFBFBD> (<28><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<2C><>Ӳ<EFBFBD><D3B2><EFBFBD><EFBFBD><EFBFBD>ǿ<EFBFBD><C7BF>Ե<EFBFBD>,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD>޷<EFBFBD><DEB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>!)
if(TRIM&0x01)EXTI->FTSR|=1<<BITx;//line BITx<54><78><EFBFBD>¼<EFBFBD><C2BC>½<EFBFBD><C2BD>ش<EFBFBD><D8B4><EFBFBD>
if(TRIM&0x02)EXTI->RTSR|=1<<BITx;//line BITx<54><78><EFBFBD>¼<EFBFBD><C2BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ش<EFBFBD><D8B4><EFBFBD>
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ִ<EFBFBD><D6B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>踴λ!<21><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>𴮿ڲ<F0B4AEBF><DAB2><EFBFBD><EFBFBD><EFBFBD>.
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD>ӼĴ<D3BC><C4B4><EFBFBD><EFBFBD><EFBFBD>λ
void MYRCC_DeInit(void)
{
RCC->APB1RSTR = 0x00000000;//<2F><>λ<EFBFBD><CEBB><EFBFBD><EFBFBD>
RCC->APB2RSTR = 0x00000000;
RCC->AHBENR = 0x00000014; //˯<><CBAF>ģʽ<C4A3><CABD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>SRAMʱ<4D><CAB1>ʹ<EFBFBD><CAB9>.<2E><><EFBFBD><EFBFBD><EFBFBD>ر<EFBFBD>.
RCC->APB2ENR = 0x00000000; //<2F><><EFBFBD><EFBFBD>ʱ<EFBFBD>ӹر<D3B9>.
RCC->APB1ENR = 0x00000000;
RCC->CR |= 0x00000001; //ʹ<><CAB9><EFBFBD>ڲ<EFBFBD><DAB2><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>HSION
RCC->CFGR &= 0xF8FF0000; //<2F><>λSW[1:0],HPRE[3:0],PPRE1[2:0],PPRE2[2:0],ADCPRE[1:0],MCO[2:0]
RCC->CR &= 0xFEF6FFFF; //<2F><>λHSEON,CSSON,PLLON
RCC->CR &= 0xFFFBFFFF; //<2F><>λHSEBYP
RCC->CFGR &= 0xFF80FFFF; //<2F><>λPLLSRC, PLLXTPRE, PLLMUL[3:0] and USBPRE
RCC->CIR = 0x00000000; //<2F>ر<EFBFBD><D8B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
#ifdef VECT_TAB_RAM
MY_NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0);
#else
MY_NVIC_SetVectorTable(NVIC_VectTab_FLASH,0x0);
#endif
}
//THUMBָ<42>֧<EEB2BB>ֻ<EFBFBD><D6BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>·<EFBFBD><C2B7><EFBFBD>ʵ<EFBFBD><CAB5>ִ<EFBFBD>л<EFBFBD><D0BB><EFBFBD>ָ<EFBFBD><D6B8>WFI
__asm void WFI_SET(void)
{
WFI;
}
//<2F>ر<EFBFBD><D8B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
__asm void INTX_DISABLE(void)
{
CPSID I;
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
__asm void INTX_ENABLE(void)
{
CPSIE I;
}
//<2F><><EFBFBD><EFBFBD>ջ<EFBFBD><D5BB><EFBFBD><EFBFBD>ַ
//addr:ջ<><D5BB><EFBFBD><EFBFBD>ַ
__asm void MSR_MSP(u32 addr)
{
MSR MSP, r0 //set Main Stack value
BX r14
}
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģʽ
void Sys_Standby(void)
{
SCB->SCR|=1<<2;//ʹ<><CAB9>SLEEPDEEPλ (SYS->CTRL)
RCC->APB1ENR|=1<<28; //ʹ<>ܵ<EFBFBD>Դʱ<D4B4><CAB1>
PWR->CSR|=1<<8; //<2F><><EFBFBD><EFBFBD>WKUP<55><50><EFBFBD>ڻ<EFBFBD><DABB><EFBFBD>
PWR->CR|=1<<2; //<2F><><EFBFBD><EFBFBD>Wake-up <20><>־
PWR->CR|=1<<1; //PDDS<44><53>λ
WFI_SET(); //ִ<><D6B4>WFIָ<49><D6B8>
}
//ϵͳ<CFB5><CDB3><EFBFBD><EFBFBD>λ
void Sys_Soft_Reset(void)
{
SCB->AIRCR =0X05FA0000|(u32)0x04;
}
//JTAGģʽ<C4A3><CABD><EFBFBD><EFBFBD>,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>JTAG<41><47>ģʽ
//mode:jtag,swdģʽ<C4A3><CABD><EFBFBD><EFBFBD>;00,ȫʹ<C8AB><CAB9>;01,ʹ<><CAB9>SWD;10,ȫ<>ر<EFBFBD>;
//#define JTAG_SWD_DISABLE 0X02
//#define SWD_ENABLE 0X01
//#define JTAG_SWD_ENABLE 0X00
void JTAG_Set(u8 mode)
{
u32 temp;
temp=mode;
temp<<=25;
RCC->APB2ENR|=1<<0; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
// AFIO->MAPR&=0XF8FFFFFF; //<2F><><EFBFBD><EFBFBD>MAPR<50><52>[26:24]
// AFIO->MAPR|=temp; //<2F><><EFBFBD><EFBFBD>jtagģʽ
}

View File

@ -0,0 +1,91 @@
#ifndef __SYS_H
#define __SYS_H
#include "misc.h"
#include "stm32l1xx.h"
#include "general_type.h"
//#define NVIC_VectTab_RAM ((u32)0x20000000)
//#define NVIC_VectTab_FLASH ((u32)0x08000000)
//JTAGģʽ<C4A3><CABD><EFBFBD>ö<EFBFBD><C3B6><EFBFBD>
#define JTAG_SWD_DISABLE 0X02
#define SWD_ENABLE 0X01
#define JTAG_SWD_ENABLE 0X00
/////////////////////////////////////////////////////////////////
void Sys_Soft_Reset(void); //ϵͳ<CFB5><CDB3><EFBFBD><EFBFBD>λ
void Sys_Standby(void); //<2F><><EFBFBD><EFBFBD>ģʽ
void MY_NVIC_SetVectorTable(u32 NVIC_VectTab, u32 Offset);//<2F><><EFBFBD><EFBFBD>ƫ<EFBFBD>Ƶ<EFBFBD>ַ
void MY_NVIC_PriorityGroupConfig(u8 NVIC_Group);//<2F><><EFBFBD><EFBFBD>NVIC<49><43><EFBFBD><EFBFBD>
void MY_NVIC_Init(u8 NVIC_PreemptionPriority,u8 NVIC_SubPriority,u8 NVIC_Channel,u8 NVIC_Group);//<2F><><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
void Ex_NVIC_Config(u8 GPIOx,u8 BITx,u8 TRIM);//<2F>ⲿ<EFBFBD>ж<EFBFBD><D0B6><EFBFBD><EFBFBD>ú<EFBFBD><C3BA><EFBFBD><><D6BB>GPIOA~G)
void JTAG_Set(u8 mode);
//////////////////////////////////////////////////////////////////////////////
//<2F><><EFBFBD><EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><E0BAAF>
void WFI_SET(void); //ִ<><D6B4>WFIָ<49><D6B8>
void INTX_DISABLE(void);//<2F>ر<EFBFBD><D8B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
void INTX_ENABLE(void); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>
void MSR_MSP(u32 addr); //<2F><><EFBFBD>ö<EFBFBD>ջ<EFBFBD><D5BB>ַ
//λ<><CEBB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><><CAB5>51<35><31><EFBFBD>Ƶ<EFBFBD>GPIO<49><4F><EFBFBD>ƹ<EFBFBD><C6B9><EFBFBD>
//<2F><><EFBFBD><EFBFBD>ʵ<EFBFBD><CAB5>˼<EFBFBD><CBBC>,<2C>ο<EFBFBD><<CM3Ȩ<33><C8A8>ָ<EFBFBD><D6B8>>><3E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(87ҳ~92ҳ).
//IO<49>ڲ<EFBFBD><DAB2><EFBFBD><EFBFBD><EFBFBD><EAB6A8>
#define BITBAND(addr, bitnum) ((addr & 0xF0000000)+0x2000000+((addr &0xFFFFF)<<5)+(bitnum<<2))
#define MEM_ADDR(addr) *((volatile unsigned long *)(addr))
#define BIT_ADDR(addr, bitnum) MEM_ADDR(BITBAND(addr, bitnum))
//IO<49>ڵ<EFBFBD>ַӳ<D6B7><D3B3>
#define GPIOA_ODR_Addr (GPIOA_BASE+12) //0x4001080C
#define GPIOB_ODR_Addr (GPIOB_BASE+12) //0x40010C0C
#define GPIOC_ODR_Addr (GPIOC_BASE+12) //0x4001100C
#define GPIOD_ODR_Addr (GPIOD_BASE+12) //0x4001140C
#define GPIOE_ODR_Addr (GPIOE_BASE+12) //0x4001180C
#define GPIOF_ODR_Addr (GPIOF_BASE+12) //0x40011A0C
#define GPIOG_ODR_Addr (GPIOG_BASE+12) //0x40011E0C
#define GPIOA_IDR_Addr (GPIOA_BASE+8) //0x40010808
#define GPIOB_IDR_Addr (GPIOB_BASE+8) //0x40010C08
#define GPIOC_IDR_Addr (GPIOC_BASE+8) //0x40011008
#define GPIOD_IDR_Addr (GPIOD_BASE+8) //0x40011408
#define GPIOE_IDR_Addr (GPIOE_BASE+8) //0x40011808
#define GPIOF_IDR_Addr (GPIOF_BASE+8) //0x40011A08
#define GPIOG_IDR_Addr (GPIOG_BASE+8) //0x40011E08
//IO<49>ڲ<EFBFBD><DAB2><EFBFBD><>Ե<EFBFBD>һ<EFBFBD><D2BB>IO<49><4F>!
//ȷ<><C8B7>n<EFBFBD><6E>ֵС<D6B5><D0A1>16!
#define PAout(n) BIT_ADDR(GPIOA_ODR_Addr,n) //<2F><><EFBFBD><EFBFBD>
#define PAin(n) BIT_ADDR(GPIOA_IDR_Addr,n) //<2F><><EFBFBD><EFBFBD>
#define PBout(n) BIT_ADDR(GPIOB_ODR_Addr,n) //<2F><><EFBFBD><EFBFBD>
#define PBin(n) BIT_ADDR(GPIOB_IDR_Addr,n) //<2F><><EFBFBD><EFBFBD>
#define PCout(n) BIT_ADDR(GPIOC_ODR_Addr,n) //<2F><><EFBFBD><EFBFBD>
#define PCin(n) BIT_ADDR(GPIOC_IDR_Addr,n) //<2F><><EFBFBD><EFBFBD>
#define PDout(n) BIT_ADDR(GPIOD_ODR_Addr,n) //<2F><><EFBFBD><EFBFBD>
#define PDin(n) BIT_ADDR(GPIOD_IDR_Addr,n) //<2F><><EFBFBD><EFBFBD>
#define PEout(n) BIT_ADDR(GPIOE_ODR_Addr,n) //<2F><><EFBFBD><EFBFBD>
#define PEin(n) BIT_ADDR(GPIOE_IDR_Addr,n) //<2F><><EFBFBD><EFBFBD>
#define PFout(n) BIT_ADDR(GPIOF_ODR_Addr,n) //<2F><><EFBFBD><EFBFBD>
#define PFin(n) BIT_ADDR(GPIOF_IDR_Addr,n) //<2F><><EFBFBD><EFBFBD>
#define PGout(n) BIT_ADDR(GPIOG_ODR_Addr,n) //<2F><><EFBFBD><EFBFBD>
#define PGin(n) BIT_ADDR(GPIOG_IDR_Addr,n) //<2F><><EFBFBD><EFBFBD>
#endif

View File

@ -0,0 +1,14 @@
#include "temp.h"
#include "stm32l1xx.h"
#include "adc.h"
void get_temperature(u16 *temp)
{
float temperate;
temperate=Get_Adc_Average(ADC_CH_TEMP,1);
temperate=temperate*(3.3/4096);
temperate=(1.43-temperate)/0.0043+25; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD><EFBFBD>ֵ
*temp=temperate*10;//<2F>õ<EFBFBD><C3B5><EFBFBD>
// temp[2]='.';temp[3]=t%10+'0';temp[4]=0; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӽ<EFBFBD><D3BD><EFBFBD><EFBFBD><EFBFBD>
}

View File

@ -0,0 +1,12 @@
#ifndef __TEMP_H
#define __TEMP_H
//#include "sys.h"
#include "general_type.h"
void get_temperature(u16 *temp);
#endif

View File

@ -0,0 +1,134 @@
#include "usart.h"
#include "pbdata.h"
char USART1_TX_BUF[USART1_MAX_SEND_LEN]; //<2F><><EFBFBD>ͻ<EFBFBD><CDBB><EFBFBD>,<2C><><EFBFBD><EFBFBD>USART2_MAX_SEND_LEN<45>ֽ<EFBFBD>
void UART_PutChar(USART_TypeDef* USARTx, uint8_t Data)
{
USART_SendData(USARTx, Data);
while(USART_GetFlagStatus(USARTx, USART_FLAG_TC) == RESET){}
}
void UART_PutStr (USART_TypeDef* USARTx, char *str)
{
while (0 != *str)
{
UART_PutChar(USARTx, *str);
str++;
}
}
void USART_OUT(USART_TypeDef* USARTx, uint8_t *Data,uint16_t Len)
{
uint16_t i;
for(i=0; i<Len; i++){
USART_SendData(USARTx, Data[i]);
while(USART_GetFlagStatus(USARTx, USART_FLAG_TC)==RESET);
}
}
int fputc(int ch,FILE *f)
{
USART_ClearFlag(USART1,USART_FLAG_TC);
USART_SendData(USART1,(u8)ch);
while(USART_GetFlagStatus(USART1,USART_FLAG_TXE)==RESET);//<2F>ȴ<EFBFBD><C8B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>);
return ch;
}
void USART1_Configuration(u32 baund)
{
USART_InitTypeDef USART_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE); //ʹ<><CAB9>USART1
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE); //GPIOAʱ<41><CAB1>
USART_DeInit(USART1); //<2F><>λ<EFBFBD><CEBB><EFBFBD><EFBFBD>1
//USART1_TX PA.9
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9 | GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
//USART1_RX PA.10
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_USART1);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_USART1);
USART_InitStructure.USART_BaudRate = baund;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_No;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_Init(USART1,&USART_InitStructure);
USART_ITConfig(USART1,USART_IT_RXNE,ENABLE);//<2F><><EFBFBD><EFBFBD>USART1<54>Ľ<EFBFBD><C4BD><EFBFBD><EFBFBD>ж<EFBFBD>
//Usart1 NVIC <20><><EFBFBD><EFBFBD>
NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;//<2F><><EFBFBD><EFBFBD>1<EFBFBD>ж<EFBFBD>ͨ<EFBFBD><CDA8>
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=3;//<2F><>ռ<EFBFBD><D5BC><EFBFBD>ȼ<EFBFBD>3
NVIC_InitStructure.NVIC_IRQChannelSubPriority =0; //<2F><><EFBFBD><EFBFBD><EFBFBD>ȼ<EFBFBD>3
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQͨ<51><CDA8>ʹ<EFBFBD><CAB9>
NVIC_Init(&NVIC_InitStructure); //<2F><><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD>IJ<EFBFBD><C4B2><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>VIC<49>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD>
USART_Cmd(USART1,ENABLE);
USART_ClearFlag(USART1,USART_FLAG_TC); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɱ<EFBFBD>־λ
}
//ʹ<>ô<EFBFBD><C3B4>ڶ<EFBFBD>ȡSDI<44>ȸ<EFBFBD>λ<EFBFBD><CEBB><EFBFBD>ڣ<EFBFBD><DAA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>IO
void USART_RS232_DEinit(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_Cmd(USART1,DISABLE);
USART_DeInit(USART1);
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE); //ʹ<><CAB9>PB<50>˿<EFBFBD>ʱ<EFBFBD><CAB1>
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9|GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; //<2F><><EFBFBD><EFBFBD>
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; //<2F><><EFBFBD><EFBFBD>
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_400KHz; //IO<49><4F><EFBFBD>ٶ<EFBFBD>Ϊ400KHz
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_SetBits(GPIOA,GPIO_Pin_9);
GPIO_SetBits(GPIOA,GPIO_Pin_10);
}
//ʹ<>ô<EFBFBD><C3B4>ڶ<EFBFBD>ȡSDI<44>ȸ<EFBFBD>λ<EFBFBD><CEBB><EFBFBD>ڣ<EFBFBD><DAA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>IO
void USART_SDI_DEinit(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_Cmd(USART1,DISABLE);
USART_DeInit(USART1);
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE); //ʹ<><CAB9>PB<50>˿<EFBFBD>ʱ<EFBFBD><CAB1>
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6|GPIO_Pin_7;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; //<2F><><EFBFBD><EFBFBD>
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; //<2F><><EFBFBD><EFBFBD>
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_400KHz; //IO<49><4F><EFBFBD>ٶ<EFBFBD>Ϊ400KHz
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_SetBits(GPIOB,GPIO_Pin_6);
GPIO_SetBits(GPIOB,GPIO_Pin_7);
}
void USART1_IRQHandler(void)
{
u8 ucCh;
if(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET)//<2F><><EFBFBD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD><EFBFBD>
{
ucCh =USART_ReceiveData(USART1);
USART_SendData(USART1, ucCh);
while(USART_GetFlagStatus(USART1, USART_FLAG_TC)==RESET);
}
}

View File

@ -0,0 +1,18 @@
#ifndef _usart_H
#define _usart_H
#include "general_type.h"
#include "stm32l1xx_usart.h"
#define USART1_MAX_SEND_LEN 100 //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͻ<EFBFBD><CDBB><EFBFBD><EFBFBD>ֽ<EFBFBD><D6BD><EFBFBD>
void USART1_Configuration(u32 baund);
void USART_OUT(USART_TypeDef* USARTx, uint8_t *Data,uint16_t Len);
void UART_PutChar(USART_TypeDef* USARTx, uint8_t Data) ;
void UART_PutStr (USART_TypeDef* USARTx, char *str) ;
//void TIM3_Set(unsigned char sta);
void Usart1_ReceiveBuff_Clear(void);
//void timer3_init(void);
void USART_RS232_DEinit(void);
void USART_SDI_DEinit(void);
#endif

View File

@ -0,0 +1,147 @@
#include "usart1_sdi.h"
#include "bsp.h"
//<2F><><EFBFBD><EFBFBD>1<EFBFBD>жϷ<D0B6><CFB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
//ע<><D7A2>,<2C><>ȡUSARTx->SR<53>ܱ<EFBFBD><DCB1><EFBFBD>Ī<EFBFBD><C4AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ĵ<EFBFBD><C4B4><EFBFBD>
char USART1_SDI_RX_BUF[USART1_SDI_REC_LEN]; //<2F><><EFBFBD>ջ<EFBFBD><D5BB><EFBFBD>,<2C><><EFBFBD><EFBFBD>USART_REC_LEN<45><4E><EFBFBD>ֽ<EFBFBD>.
char USART1_SDI_TX_BUF[100];
//<2F><><EFBFBD><EFBFBD>״̬
//bit15<31><35> <09><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɱ<EFBFBD>־
//bit14<31><34> <09><><EFBFBD>յ<EFBFBD>0x0d
//bit13~0<><30> <09><><EFBFBD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD><EFBFBD>Ч<EFBFBD>ֽ<EFBFBD><D6BD><EFBFBD>Ŀ
u16 USART_SDI_RX_STA=0; //<2F><><EFBFBD><EFBFBD>״̬<D7B4><CCAC><EFBFBD><EFBFBD>
void USART1_SDI_Configuration(u32 baund)
{
USART_InitTypeDef USART_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
Enable_SDI_RS232=0;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE); //ʹ<><CAB9>USART1_SDI_SDI
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE); //GPIOAʱ<41><CAB1>
//NVIC_Configuration();
USART_DeInit(USART1); //<2F><>λ<EFBFBD><CEBB><EFBFBD><EFBFBD>1
//USART1_SDI_SDI_TX PB.6 PB.7
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_PinAFConfig(GPIOB, GPIO_PinSource6, GPIO_AF_USART1);
GPIO_PinAFConfig(GPIOB, GPIO_PinSource7, GPIO_AF_USART1);
USART_InitStructure.USART_BaudRate = baund;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_Even; //<2F><>У<EFBFBD><EFBFBD><E9A3AC><EFBFBD><EFBFBD>λ<EFBFBD><CEBB>Ϊ7λ
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_Init(USART1,&USART_InitStructure);
USART_Cmd(USART1,ENABLE);
USART_ITConfig(USART1,USART_IT_RXNE,ENABLE);//<2F><><EFBFBD><EFBFBD>USART1_SDI_SDI<44>Ľ<EFBFBD><C4BD><EFBFBD><EFBFBD>ж<EFBFBD>
//USART1_SDI_SDI NVIC <20><><EFBFBD><EFBFBD>
NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;//<2F><><EFBFBD><EFBFBD>3<EFBFBD>ж<EFBFBD>ͨ<EFBFBD><CDA8>
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=3;//<2F><>ռ<EFBFBD><D5BC><EFBFBD>ȼ<EFBFBD>3
NVIC_InitStructure.NVIC_IRQChannelSubPriority =3; //<2F><><EFBFBD><EFBFBD><EFBFBD>ȼ<EFBFBD>3
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQͨ<51><CDA8>ʹ<EFBFBD><CAB9>
NVIC_Init(&NVIC_InitStructure); //<2F><><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD>IJ<EFBFBD><C4B2><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>VIC<49>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD>
USART_ClearFlag(USART1,USART_FLAG_TC); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɱ<EFBFBD>־λ
}
void USART1_SDI_CLR_RXBuf(void)
{
memset(USART1_SDI_RX_BUF, 0, USART1_SDI_REC_LEN);
USART_SDI_RX_STA=0;
}
void USART1_SDI_SDI_CLR_TXBuf(void)
{
memset(USART1_SDI_TX_BUF, 0, 100);
}
void u1_printf(char* fmt,...)
{
u16 i,j;
va_list ap;
va_start(ap,fmt);
vsprintf((char*)USART1_SDI_TX_BUF,fmt,ap);
va_end(ap);
i=strlen((const char*)USART1_SDI_TX_BUF); //<2F>˴η<CBB4><CEB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵij<DDB5><C4B3><EFBFBD>
for(j=0;j<i;j++) //ѭ<><D1AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
while(USART_GetFlagStatus(USART1,USART_FLAG_TC)==RESET); //ѭ<><D1AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><><D6B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
USART_SendData(USART1,USART1_SDI_TX_BUF[j]);
}
}
//void timer4_init(void)
//{
// TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
// NVIC_InitTypeDef NVIC_InitStructure;
// RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE);
// TIM_TimeBaseStructure.TIM_Period = 99;
// TIM_TimeBaseStructure.TIM_Prescaler = 3199;//<2F>ж<EFBFBD>ʱ<EFBFBD><CAB1>10ms
// TIM_TimeBaseStructure.TIM_ClockDivision = 1;
// TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
// TIM_TimeBaseInit(TIM4, &TIM_TimeBaseStructure);
//
// /* TIM IT enable */
// TIM_ITConfig(TIM4,TIM_IT_Update, ENABLE);
// TIM_ClearITPendingBit(TIM4, TIM_IT_Update);
// /* TIM4 enable counter */
// TIM_Cmd(TIM4, DISABLE);
// /* Enable the TIM4 Interrupt */
//
// NVIC_InitStructure.NVIC_IRQChannel = TIM4_IRQn;
// NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
// NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;
// NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
// NVIC_Init(&NVIC_InitStructure);
//}
////<2F><><EFBFBD><EFBFBD>TIM4<4D>Ŀ<EFBFBD><C4BF><EFBFBD>
////sta:0<><30><EFBFBD>ر<EFBFBD>;1,<2C><><EFBFBD><EFBFBD>;
//void TIM4_Set(unsigned char sta)
//{
// if(sta)
// {
//
// TIM_SetCounter(TIM4,0);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// TIM_Cmd(TIM4, ENABLE); //ʹ<><CAB9>TIMx
// }else TIM_Cmd(TIM4, DISABLE);//<2F>رն<D8B1>ʱ<EFBFBD><CAB1>2
//}
///**
// * @brief This function handles TIM4 global interrupt request.
// * @param None
// * @retval None
// */
//void TIM4_IRQHandler(void)
//{
// if (TIM_GetITStatus(TIM4, TIM_IT_Update) != RESET)
// {
// USART_SDI_RX_STA|=1<<15; //<2F><><EFBFBD>ǽ<EFBFBD><C7BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>;
// TIM_ClearITPendingBit(TIM4, TIM_IT_Update);
// TIM4_Set(0); //<2F>ر<EFBFBD>TIM4
//
// }
//}
//<2F><><EFBFBD><EFBFBD>3,printf <20><><EFBFBD><EFBFBD>
//ȷ<><C8B7>һ<EFBFBD>η<EFBFBD><CEB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݲ<EFBFBD><DDB2><EFBFBD><EFBFBD><EFBFBD>USART1_MAX_SEND_LEN<45>ֽ<EFBFBD>

View File

@ -0,0 +1,22 @@
#ifndef _usart1_sdi_H
#define _usart1_sdi_H
#include "bsp.h"
#include "stm32l1xx_usart.h"
#define USART1_SDI_REC_LEN 100 //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֽ<EFBFBD><D6BD><EFBFBD> 100
extern char USART1_SDI_RX_BUF[USART1_SDI_REC_LEN]; //<2F><><EFBFBD>ջ<EFBFBD><D5BB><EFBFBD>,<2C><><EFBFBD><EFBFBD>USART_REC_LEN<45><4E><EFBFBD>ֽ<EFBFBD><>ֽ<EFBFBD>Ϊ<EFBFBD><CEAA><EFBFBD>з<EFBFBD>
extern u16 USART_SDI_RX_STA; //<2F><><EFBFBD><EFBFBD>״̬<D7B4><CCAC><EFBFBD><EFBFBD>
void USART1_SDI_Configuration(u32 baund);
void USART1_SDI_CLR_RXBuf(void);
void u1_printf(char* fmt,...) ;
#endif

View File

@ -0,0 +1,166 @@
#include "usart2.h"
#include "stdio.h"
#include "string.h"
#include "pbdata.h"
#include "stdarg.h"
//<2F><><EFBFBD>ڽ<EFBFBD><DABD>ջ<EFBFBD><D5BB><EFBFBD><EFBFBD><EFBFBD>
u8 USART2_RX_BUF[USART2_MAX_RECV_LEN]; //<2F><><EFBFBD>ջ<EFBFBD><D5BB><EFBFBD>,<2C><><EFBFBD><EFBFBD>USART2_MAX_RECV_LEN<45><4E><EFBFBD>ֽ<EFBFBD>.
u8 USART2_TX_BUF[USART2_MAX_SEND_LEN]; //<2F><><EFBFBD>ͻ<EFBFBD><CDBB><EFBFBD>,<2C><><EFBFBD><EFBFBD>USART2_MAX_SEND_LEN<45>ֽ<EFBFBD>
vu16 USART2_RX_STA=0;
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
void USART2_ReceiveBuff_Clear(void)
{
USART2_RX_STA=0;
memset(USART2_RX_BUF,0,USART2_MAX_RECV_LEN);
}
//<2F><><EFBFBD><EFBFBD>2<EFBFBD><32><EFBFBD>ú<EFBFBD><C3BA><EFBFBD>
void USART2_Configuration(u32 baund)
{
USART_InitTypeDef USART_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE); //ʹ<><CAB9>USART2
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE); //GPIOBʱ<42><CAB1>
//NVIC_Configuration();
USART_DeInit(USART2); //<2F><>λ<EFBFBD><CEBB><EFBFBD><EFBFBD>1
//USART2_TX PB.10 PB.11
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2 | GPIO_Pin_3;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource2, GPIO_AF_USART2);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource3, GPIO_AF_USART2);
USART_InitStructure.USART_BaudRate = baund;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_No;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_Init(USART2,&USART_InitStructure);
USART_Cmd(USART2,ENABLE);
USART_ITConfig(USART2,USART_IT_RXNE,ENABLE);//<2F><><EFBFBD><EFBFBD>USART2<54>Ľ<EFBFBD><C4BD><EFBFBD><EFBFBD>ж<EFBFBD>
//Usart1 NVIC <20><><EFBFBD><EFBFBD>
NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn;//<2F><><EFBFBD><EFBFBD>3<EFBFBD>ж<EFBFBD>ͨ<EFBFBD><CDA8>
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=3;//<2F><>ռ<EFBFBD><D5BC><EFBFBD>ȼ<EFBFBD>3
NVIC_InitStructure.NVIC_IRQChannelSubPriority =0; //<2F><><EFBFBD><EFBFBD><EFBFBD>ȼ<EFBFBD>3
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQͨ<51><CDA8>ʹ<EFBFBD><CAB9>
NVIC_Init(&NVIC_InitStructure); //<2F><><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD>IJ<EFBFBD><C4B2><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>VIC<49>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD>
USART_ClearFlag(USART2,USART_FLAG_TC); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɱ<EFBFBD>־λ
}
//<2F><><EFBFBD><EFBFBD>2,printf <20><><EFBFBD><EFBFBD>
//ȷ<><C8B7>һ<EFBFBD>η<EFBFBD><CEB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݲ<EFBFBD><DDB2><EFBFBD><EFBFBD><EFBFBD>USART2_MAX_SEND_LEN<45>ֽ<EFBFBD>
void u2_printf(char* fmt,...)
{
u16 i,j;
va_list ap;
USART2_ReceiveBuff_Clear();
va_start(ap,fmt);
vsprintf((char*)USART2_TX_BUF,fmt,ap);
va_end(ap);
i=strlen((const char*)USART2_TX_BUF); //<2F>˴η<CBB4><CEB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵij<DDB5><C4B3><EFBFBD>
for(j=0;j<i;j++) //ѭ<><D1AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
while(USART_GetFlagStatus(USART2,USART_FLAG_TC)==RESET); //ѭ<><D1AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><><D6B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
USART_SendData(USART2,USART2_TX_BUF[j]);
}
}
void timer2_init(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
TIM_TimeBaseStructure.TIM_Period = 999;
TIM_TimeBaseStructure.TIM_Prescaler = 3199;
TIM_TimeBaseStructure.TIM_ClockDivision = 1;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);
/* TIM IT enable */
TIM_ITConfig(TIM2,TIM_IT_Update, ENABLE);
TIM_ClearITPendingBit(TIM2, TIM_IT_Update);
/* TIM2 enable counter */
TIM_Cmd(TIM2, DISABLE);
/* Enable the TIM2 Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
TIM_Cmd(TIM2, ENABLE); //ʹ<><CAB9>TIMx
}
//<2F><><EFBFBD><EFBFBD>TIM2<4D>Ŀ<EFBFBD><C4BF><EFBFBD>
//sta:0<><30><EFBFBD>ر<EFBFBD>;1,<2C><><EFBFBD><EFBFBD>;
void TIM2_Set(unsigned char sta)
{
if(sta)
{
TIM_SetCounter(TIM2,0);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
TIM_Cmd(TIM2, ENABLE); //ʹ<><CAB9>TIMx
}else TIM_Cmd(TIM2, DISABLE);//<2F>رն<D8B1>ʱ<EFBFBD><CAB1>2
}
/**
* @brief This function handles TIM2 global interrupt request.
* @param None
* @retval None
*/
void TIM2_IRQHandler(void)
{
if (TIM_GetITStatus(TIM2, TIM_IT_Update) != RESET)
{
TIM_ClearITPendingBit(TIM2, TIM_IT_Update);
WKUP_PIN_Status=Key_Scan();
}
}
//<2F><><EFBFBD><EFBFBD>2<EFBFBD>жϷ<D0B6><CFB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
void USART2_IRQHandler(void)
{
u8 res;
if(USART_GetITStatus(USART2, USART_IT_RXNE) != RESET)//<2F><><EFBFBD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD><EFBFBD>
{
res =USART_ReceiveData(USART2);
if((USART2_RX_STA&(1<<15))==0)//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<2C><>û<EFBFBD>б<EFBFBD><D0B1><EFBFBD><EFBFBD><EFBFBD>,<2C><><EFBFBD><EFBFBD><EFBFBD>ٽ<EFBFBD><D9BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
if(USART2_RX_STA<(USART2_MAX_RECV_LEN-1)) //<2F><><EFBFBD><EFBFBD><EFBFBD>Խ<EFBFBD><D4BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
// TIM_SetCounter(TIM2,0);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// if(USART2_RX_STA==0) //ʹ<>ܶ<EFBFBD>ʱ<EFBFBD><CAB1>7<EFBFBD><37><EFBFBD>ж<EFBFBD>
// {
// TIM_Cmd(TIM2,ENABLE);//ʹ<>ܶ<EFBFBD>ʱ<EFBFBD><CAB1>7
// }
USART2_RX_BUF[USART2_RX_STA++]=res; //<2F><>¼<EFBFBD><C2BC><EFBFBD>յ<EFBFBD><D5B5><EFBFBD>ֵ
}else
{
USART2_RX_STA|=1<<15; //ǿ<>Ʊ<EFBFBD><C6B1>ǽ<EFBFBD><C7BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
}
}
}
}

View File

@ -0,0 +1,23 @@
#ifndef _usart2_H
#define _usart2_H
#include "general_type.h"
#include "stm32l1xx_usart.h"
#define USART2_MAX_RECV_LEN 300 //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ջ<EFBFBD><D5BB><EFBFBD><EFBFBD>ֽ<EFBFBD><D6BD><EFBFBD>
#define USART2_MAX_SEND_LEN 300 //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͻ<EFBFBD><CDBB><EFBFBD><EFBFBD>ֽ<EFBFBD><D6BD><EFBFBD>
#define USART2_RX_EN 1 //0,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>;1,<2C><><EFBFBD><EFBFBD>.
extern u8 USART2_RX_BUF[USART2_MAX_RECV_LEN]; //<2F><><EFBFBD>ջ<EFBFBD><D5BB><EFBFBD>,<2C><><EFBFBD><EFBFBD>USART2_MAX_RECV_LEN<45>ֽ<EFBFBD>
extern u8 USART2_TX_BUF[USART2_MAX_SEND_LEN]; //<2F><><EFBFBD>ͻ<EFBFBD><CDBB><EFBFBD>,<2C><><EFBFBD><EFBFBD>USART2_MAX_SEND_LEN<45>ֽ<EFBFBD>
extern vu16 USART2_RX_STA; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬
void USART2_Configuration(u32 baund);
void u2_printf(char* fmt,...);
void TIM2_Set(unsigned char sta);
void timer2_init(void);
void USART2_ReceiveBuff_Clear(void);
#endif

View File

@ -0,0 +1,120 @@
#include "usart3.h"
//<2F><><EFBFBD>ڽ<EFBFBD><DABD>ջ<EFBFBD><D5BB><EFBFBD><EFBFBD><EFBFBD>
u8 USART3_RX_BUF[USART3_MAX_RECV_LEN]; //<2F><><EFBFBD>ջ<EFBFBD><D5BB><EFBFBD>,<2C><><EFBFBD><EFBFBD>USART3_MAX_RECV_LEN<45><4E><EFBFBD>ֽ<EFBFBD>.
u8 USART3_TX_BUF[USART3_MAX_SEND_LEN]; //<2F><><EFBFBD>ͻ<EFBFBD><CDBB><EFBFBD>,<2C><><EFBFBD><EFBFBD>USART3_MAX_SEND_LEN<45>ֽ<EFBFBD>
vu16 point1 = 0;
void USART3_Configuration(u32 baund)
{
USART_InitTypeDef USART_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE); //ʹ<><CAB9>USART3
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE); //GPIOBʱ<42><CAB1>
//NVIC_Configuration();
USART_DeInit(USART3); //<2F><>λ<EFBFBD><CEBB><EFBFBD><EFBFBD>1
//USART3_TX PB.10 PB.11
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10 | GPIO_Pin_11;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_PinAFConfig(GPIOB, GPIO_PinSource10, GPIO_AF_USART3);
GPIO_PinAFConfig(GPIOB, GPIO_PinSource11, GPIO_AF_USART3);
USART_InitStructure.USART_BaudRate = baund;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_No;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_Init(USART3,&USART_InitStructure);
USART_Cmd(USART3,ENABLE);
USART_ITConfig(USART3,USART_IT_RXNE,ENABLE);//<2F><><EFBFBD><EFBFBD>USART3<54>Ľ<EFBFBD><C4BD><EFBFBD><EFBFBD>ж<EFBFBD>
//Usart1 NVIC <20><><EFBFBD><EFBFBD>
NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQn;//<2F><><EFBFBD><EFBFBD>3<EFBFBD>ж<EFBFBD>ͨ<EFBFBD><CDA8>
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=2;//<2F><>ռ<EFBFBD><D5BC><EFBFBD>ȼ<EFBFBD>3
NVIC_InitStructure.NVIC_IRQChannelSubPriority =0; //<2F><><EFBFBD><EFBFBD><EFBFBD>ȼ<EFBFBD>3
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQͨ<51><CDA8>ʹ<EFBFBD><CAB9>
NVIC_Init(&NVIC_InitStructure); //<2F><><EFBFBD><EFBFBD>ָ<EFBFBD><D6B8><EFBFBD>IJ<EFBFBD><C4B2><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC>VIC<49>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD>
USART_ClearFlag(USART3,USART_FLAG_TC); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɱ<EFBFBD>־λ
}
void USART3_IRQHandler(void)
{
u8 Res;
if(USART_GetITStatus(USART3, USART_IT_RXNE) != RESET)
{
Res =USART_ReceiveData(USART3);//(USART1->DR); //<2F><>ȡ<EFBFBD><C8A1><EFBFBD>յ<EFBFBD><D5B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
if(Res == 0x24)
{
point1 = 0;
}
USART3_RX_BUF[point1++] = Res;
if(USART3_RX_BUF[0] == '$' && USART3_RX_BUF[4] == 'M' && USART3_RX_BUF[5] == 'C') //ȷ<><C8B7><EFBFBD>Ƿ<EFBFBD><C7B7>յ<EFBFBD>"GPRMC/GNRMC"<22><>һ֡<D2BB><D6A1><EFBFBD><EFBFBD>
{
if(Res == '\n')
{
memset(Save_Data.GPS_Buffer, 0, GPS_Buffer_Length); //<2F><><EFBFBD><EFBFBD>
memcpy(Save_Data.GPS_Buffer, USART3_RX_BUF, point1); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
Save_Data.isGetData = 1;
point1 = 0;
memset(USART3_RX_BUF, 0, USART3_MAX_RECV_LEN); //<2F><><EFBFBD><EFBFBD>
}
}
// if(USART3_RX_BUF[0] == '$' && USART3_RX_BUF[3] == 'G'&& USART3_RX_BUF[4] == 'G' && USART3_RX_BUF[5] == 'A') //ȷ<><C8B7><EFBFBD>Ƿ<EFBFBD><C7B7>յ<EFBFBD>"GPRMC/GNRMC"<22><>һ֡<D2BB><D6A1><EFBFBD><EFBFBD>
// {
// if(Res == '\n')
// {
// memset(Save_Data.GGA_Buffer, 0, GPS_Buffer_Length); //<2F><><EFBFBD><EFBFBD>
// memcpy(Save_Data.GGA_Buffer, USART3_RX_BUF, point1); //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
// Save_Data.isGetData = true;
// point1 = 0;
// memset(USART3_RX_BUF, 0, USART3_MAX_RECV_LEN); //<2F><><EFBFBD><EFBFBD>
// }
//
// }
if(point1 >= (USART3_MAX_RECV_LEN-1))
{
point1 = 0;
}
}
}
//<2F><><EFBFBD><EFBFBD>3,printf <20><><EFBFBD><EFBFBD>
//ȷ<><C8B7>һ<EFBFBD>η<EFBFBD><CEB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݲ<EFBFBD><DDB2><EFBFBD><EFBFBD><EFBFBD>USART3_MAX_SEND_LEN<45>ֽ<EFBFBD>
void u3_printf(char* fmt,...)
{
u16 i,j;
va_list ap;
va_start(ap,fmt);
vsprintf((char*)USART3_TX_BUF,fmt,ap);
va_end(ap);
i=strlen((const char*)USART3_TX_BUF); //<2F>˴η<CBB4><CEB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵij<DDB5><C4B3><EFBFBD>
for(j=0;j<i;j++) //ѭ<><D1AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
{
while(USART_GetFlagStatus(USART3,USART_FLAG_TC)==RESET); //ѭ<><D1AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><><D6B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
USART_SendData(USART3,USART3_TX_BUF[j]);
}
}

View File

@ -0,0 +1,22 @@
#ifndef _usart3_H
#define _usart3_H
#include "bsp.h"
#include "general_type.h"
#include "stm32l1xx_usart.h"
#define USART3_MAX_RECV_LEN 256 //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ջ<EFBFBD><D5BB><EFBFBD><EFBFBD>ֽ<EFBFBD><D6BD><EFBFBD>
#define USART3_MAX_SEND_LEN 100 //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͻ<EFBFBD><CDBB><EFBFBD><EFBFBD>ֽ<EFBFBD><D6BD><EFBFBD>
extern unsigned char USART3_RX_BUF[USART3_MAX_RECV_LEN]; //<2F><><EFBFBD>ջ<EFBFBD><D5BB><EFBFBD>,<2C><><EFBFBD><EFBFBD>USART3_MAX_RECV_LEN<45>ֽ<EFBFBD>
extern unsigned char USART3_TX_BUF[USART3_MAX_SEND_LEN]; //<2F><><EFBFBD>ͻ<EFBFBD><CDBB><EFBFBD>,<2C><><EFBFBD><EFBFBD>USART3_MAX_SEND_LEN<45>ֽ<EFBFBD>
void USART_OUT(USART_TypeDef* USARTx, uint8_t *Data,uint16_t Len);
void USART3_Configuration(u32 baund);
void u3_printf(char* fmt,...);
void Usart3_ReceiveBuff_Clear(void);
#endif

Some files were not shown because too many files have changed in this diff Show More