347 lines
8.9 KiB
C
347 lines
8.9 KiB
C
/**************************************** Í·Îļþ *********************************************/
|
||
|
||
#include <stdio.h>
|
||
#include "delay.h"
|
||
#include "usart.h"
|
||
#include "EC800M.h"
|
||
#include "led.h"
|
||
#include "key.h"
|
||
#include "sys.h"
|
||
#include "gps.h"
|
||
#include "string.h"
|
||
#include "sdram.h"
|
||
#include "ff.h"
|
||
#include "diskio.h"
|
||
#include "sdio.h"
|
||
#include "spi.h"
|
||
#include "Function.h"
|
||
#include "gpio.h"
|
||
|
||
#include "w25qxx.h"
|
||
#include "malloc.h"
|
||
#include "exfuns.h"
|
||
#include "usmart.h"
|
||
#include "cnn_model.h"
|
||
#include "debug.h"
|
||
#include "cnn.h"
|
||
|
||
|
||
|
||
|
||
void run_dataset(){
|
||
char* modelusearr[] = {
|
||
"C1autosave00095_right_new_2",
|
||
"C1autosave00096_right_new_2",
|
||
"C1autosave00097_right_new_2",
|
||
"C1autosave00098_right_new_2",
|
||
"C1autosave00099_right_new_2",
|
||
"C1autosave00100_right_new_2",
|
||
"C1autosave00101_right_new_2",
|
||
"C1autosave00102_right_new_2",
|
||
"C1autosave00103_right_new_2",
|
||
"C1autosave00104_right_new_2",
|
||
"C1autosave00105_right_new_2",
|
||
"C1autosave00106_right_new_2",
|
||
"C1autosave00107_right_new_2",
|
||
"C1autosave00108_right_new_2",
|
||
"C1autosave00109_right_new_2",
|
||
"C1autosave00110_right_new_2",
|
||
"C1autosave00111_right_new_2",
|
||
"C1autosave00112_right_new_2",
|
||
"C1autosave00113_right_new_2",
|
||
"C1autosave00114_right_new_2",
|
||
"C1autosave00115_right_new_2",
|
||
"C1autosave00116_right_new_2",
|
||
"C1autosave00117_right_new_2",
|
||
"C1autosave00118_right_new_2",
|
||
"C1autosave00119_right_new_2",
|
||
"C1autosave00120_right_new_2",
|
||
"C1autosave00121_right_new_2",
|
||
"C1autosave00122_right_new_2",
|
||
"C1autosave00123_right_new_2",
|
||
"C1autosave00124_right_new_2",
|
||
|
||
"filtered_C1autosave00011_right_new",
|
||
"filtered_C1autosave00015_right_new",
|
||
"filtered_C1autosave00043_right_new",
|
||
"filtered_C1autosave00067_right_new",
|
||
"filtered_C1autosave00090_right_new",
|
||
"filtered_C1autosave00106_right_new",
|
||
"filtered_C1autosave00118_right_new",
|
||
|
||
"filtered_C1autosave00007_right_new",
|
||
"filtered_C1autosave00035_right_new",
|
||
"filtered_C1autosave00036_right_new",
|
||
"filtered_C1autosave00040_right_new",
|
||
"filtered_C1autosave00053_right_new",
|
||
"filtered_C1autosave00061_right_new",
|
||
"filtered_C1autosave00074_right_new",
|
||
"filtered_C1autosave00077_right_new",
|
||
"filtered_C1autosave00080_right_new",
|
||
"filtered_C1autosave00085_right_new",
|
||
"filtered_C1autosave00098_right_new",
|
||
"filtered_C1autosave00100_right_new",
|
||
"filtered_C1autosave00104_right_new",
|
||
"filtered_C1autosave00122_right_new",
|
||
"filtered_C1autosave00124_right_new",
|
||
|
||
"filtered_C1autosave00108_right_new",
|
||
|
||
"filtered_C1autosave00004_right_new",
|
||
"filtered_C1autosave00039_right_new",
|
||
"filtered_C1autosave00062_right_new",
|
||
};
|
||
for(int a=0;a<(sizeof(modelusearr) / sizeof(modelusearr[0]));a++){
|
||
SDRAM_USED();
|
||
model_switchdata(modelusearr[a]);
|
||
cnn_run();
|
||
}
|
||
printf("\r\nÔËÐÐÍê³É\r\n");
|
||
}
|
||
|
||
|
||
|
||
/**************************************** ±±¶·+4GÄ£¿é *********************************************/
|
||
|
||
unsigned char flag_spi = 0;
|
||
|
||
extern uint32_t UTC; // UTCʱ¼ä
|
||
nmea_msg gpsx; // GPSÐÅÏ¢
|
||
extern int month_def; //ÔÆ¶ËÏ·¢µÄʱ¼äÐÅÏ¢
|
||
extern int date_def;
|
||
extern int hour_def;
|
||
extern int min_def;
|
||
extern int sec_def;
|
||
const char* data_identifier = "data_string"; //´¦ÀíÍêµÄ100*100Êý¾Ý±êʶ
|
||
const char* kind_identifier = "kind_string"; //·ÅµçÀàÐͱêʶ
|
||
|
||
/**************************************** FatFsÎļþϵͳ±äÁ¿ *********************************************/
|
||
|
||
FIL file1; // Îļþ¶ÔÏó
|
||
FATFS fatfs; // Âß¼Çý¶¯Æ÷µÄ¹¤×÷Çø
|
||
FILINFO fno;
|
||
FRESULT res; // FRESULTº¯Êý¹«¹²½á¹û´úÂë
|
||
UINT fnum; /* Îļþ³É¹¦¶ÁдÊýÁ¿ */
|
||
|
||
/**************************************** ²âÊÔº¯Êý ***************************************************/
|
||
|
||
void SDRAM_test(void);
|
||
void SDRAM_SD_test(void);
|
||
void FatFs_test(void);
|
||
void test__(void);
|
||
|
||
/***************************************** Ö÷º¯Êý ******************************************/
|
||
|
||
int main(void)
|
||
{
|
||
/* ±äÁ¿¶¨Òå */
|
||
unsigned char key;
|
||
/************************************* ÍâÉè³õʼ»¯ ******************************************************/
|
||
|
||
HAL_Init(); //³õʼ»¯HAL¿â
|
||
Stm32_Clock_Init(360,25,2,8); //ÉèÖÃʱÖÓ,180Mhz
|
||
delay_init(180); //³õʼ»¯ÑÓʱº¯Êý
|
||
LED_Init(); //³õʼ»¯LED
|
||
KEY_Init(); //³õʼ»¯°´¼ü
|
||
GPIO_Init(); //´®¿Ú³õʼ»¯
|
||
SDRAM_Init(); //SDRAM³õʼ»¯
|
||
SD_Init(); //SD¿¨³õʼ»¯
|
||
SPI_Init(); //FPGA_STM32ͨÐÅ
|
||
usart_init1(115200); //pc
|
||
usart_init2(115200); //4g TX:PA2 Rx:PA3
|
||
usart_init3(115200); //gps
|
||
TIM3_Init(4999,8999);
|
||
|
||
my_mem_init(SRAMEX);
|
||
model_init();
|
||
usmart_dev.init(90);
|
||
SDRAM_USED();
|
||
|
||
Formatting_test(); //SD¿¨³õʼ»¯
|
||
|
||
model_write("all");
|
||
|
||
if( CSTX_4G_Init() )//¶ÔÉ豸³õʼ»¯
|
||
{
|
||
CSTX_4G_RegALiYunIOT(0);//×¢²áµ½°¢ÀïÔÆ
|
||
}
|
||
|
||
|
||
/************************************************************************************************************/
|
||
|
||
while (1) {
|
||
/* °´¼ü¿ØÖƲ¿·Ö */
|
||
key = KEY_Scan(0);
|
||
switch (key){
|
||
case KEY1_PRES:
|
||
SPI_Read_SDRAM(); //²É¼¯Êý¾Ý´æÈëSDRAMÖÐ 32λ¸¡µãÊý
|
||
break;
|
||
case KEY2_PRES:
|
||
SDRAM_TO_SD(); //½«SDRAMµÄÊý¾Ý´æÈëSD¿¨ 32λ¸¡µãÊý
|
||
break;
|
||
case KEY3_PRES:
|
||
test__(); //Ò»´ÎÍêÕûµÄ²É¼¯ÅжÁ ÉÏÔÆ+´æSD
|
||
break;
|
||
case KEY4_PRES:
|
||
CSTX_4G_RegALiYunIOT(1); //¶©Ôĵ½ÎïÄ£ÐÍ ÓÃÓÚÊý¾ÝµÄÉϱ¨
|
||
CSTX_4G_ALiYunIOTSenddata_string("21367984",data_identifier); //Éϱ¨Êý¾Ý
|
||
CSTX_4G_RegALiYunIOT(0); //¶©Ôĵ½×Ô¶¨ÒåÖ÷Ìâ ÓÃÓÚÐÅÏ¢µÄÏ·¢
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
//Èô´®¿Ú½ÓÊÕµ½±±¶·Ï·¢µÄÐÅÏ¢ Ôò¿ªÊ¼Êý¾Ý½â°ü
|
||
if (USART3_RX_STA & 0X8000) {
|
||
GPS_Analysis(&gpsx, USART3_RX_BUF); // ½âÎöGPSÊý¾Ý
|
||
if (gpsx.utc.hour > 24) {
|
||
gpsx.utc.hour -= 24;
|
||
gpsx.utc.date += 1;
|
||
}
|
||
USART3_RX_STA = 0; // ÖØÖýÓÊÕ״̬
|
||
memset(USART3_RX_BUF, 0, USART3_MAX_RECV_LEN); //Çå¿Õ»º´æ
|
||
//ÏÔʾGPSʱ¼ä
|
||
printf("year:%u\r\n",gpsx.utc.year);
|
||
printf("month:%u\r\n",gpsx.utc.month);
|
||
printf("date:%u\r\n",gpsx.utc.date);
|
||
printf("hour:%u\r\n",gpsx.utc.hour);
|
||
printf("min:%u\r\n",gpsx.utc.min);
|
||
printf("sec:%u\r\n\r\n",gpsx.utc.sec);
|
||
}
|
||
// ¼ì²éÊÇ·ñµ½´ïÁËÒ»¸öеÄÕûµã
|
||
if(CSTX_4G_RECData() == 1){
|
||
while(1){
|
||
if (USART3_RX_STA & 0X8000) {
|
||
GPS_Analysis(&gpsx, USART3_RX_BUF); // ½âÎöGPSÊý¾Ý
|
||
if (gpsx.utc.hour > 24) {
|
||
gpsx.utc.hour -= 24;
|
||
gpsx.utc.date += 1;
|
||
}
|
||
USART3_RX_STA = 0; // ÖØÖýÓÊÕ״̬
|
||
memset(USART3_RX_BUF, 0, USART3_MAX_RECV_LEN); //Çå¿Õ»º´æ
|
||
}
|
||
CSTX_4G_RECData();
|
||
// ÈôÏ·¢¶¨Ê±µÄʱ¼äÓë±±¶·Ï·¢µÄʱ¼äÒ»Ö ÔòÆô¶¯²É¼¯
|
||
if (month_def == gpsx.utc.month && date_def == gpsx.utc.date && hour_def == gpsx.utc.hour && min_def ==gpsx.utc.min && sec_def == gpsx.utc.sec ) {
|
||
flag_spi = 1;
|
||
while(flag_spi != 0) printf("¡¡");
|
||
HAL_NVIC_DisableIRQ(EXTI9_5_IRQn); // ʧÄÜÖжÏ
|
||
SPI_Read_SDRAM();
|
||
SDRAM_TO_SD();
|
||
HAL_NVIC_EnableIRQ(EXTI9_5_IRQn); // ʹÄÜÖжÏ
|
||
month_def = 0;
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
/**************************************** ÒÔÏÂΪ²âÊÔ³ÌÐò *********************************************/
|
||
|
||
void FatFs_test(void)
|
||
{
|
||
float tempt;
|
||
res = f_open(&file1,"test.bin",FA_CREATE_ALWAYS | FA_WRITE | FA_READ); // ´ò¿ªÇý¶¯Æ÷0ÉϵÄÔ´Îļþ
|
||
if(res != RES_OK)
|
||
{
|
||
printf("f_open error!\r\n"); // ´ò¿ªÎļþʧ°Ü
|
||
while(1)
|
||
{
|
||
delay_ms(500);
|
||
LED_R=!LED_R; // ºìµÆÉÁ˸
|
||
}
|
||
}
|
||
else
|
||
{
|
||
printf("f_open successful!\r\n");// ³É¹¦´ò¿ªÎļþ
|
||
}
|
||
printf("xierukaishi\r\n");
|
||
for(int i=0;i<1300000;i++){
|
||
tempt = i%100 + 0.0;
|
||
res=f_write(&file1,&tempt,4,&fnum);
|
||
}
|
||
printf("xierujieshu\r\n");
|
||
f_sync(&file1);
|
||
res = f_lseek(&file1,0);
|
||
if(res == FR_OK){
|
||
for(int j=0;j<100000;j++){
|
||
res = f_read(&file1, "FatFs_2.txt", 2, &fnum);
|
||
}
|
||
}
|
||
else{
|
||
printf("£¡£¡´ò¿ªÎļþʧ°Ü¡£\r\n");
|
||
}
|
||
f_close(&file1);
|
||
f_mount(NULL,"0:",1);
|
||
}
|
||
|
||
void SDRAM_test(void)
|
||
{
|
||
uint16_t i;
|
||
uint16_t temp;
|
||
printf("¿ªÊ¼Ð´Èë\r\n");
|
||
for(i=0;i<13000;i++)
|
||
{
|
||
*(uint16_t*)(Bank5_SDRAM_ADDR+2*i)=i%1000;
|
||
}
|
||
printf("дÈë½áÊø\r\n");
|
||
// ÒÀ´Î¶Á³ö֮ǰдÈëµÄÊý¾Ý,½øÐÐУÑé
|
||
for(i=0;i<1024;i++)
|
||
{
|
||
temp=*(uint16_t*)(Bank5_SDRAM_ADDR+2*i);
|
||
printf("¡·SDRAM¶Áµ½µÄÊý¾Ý£º0x%x\r\n",temp);
|
||
}
|
||
}
|
||
|
||
void SDRAM_SD_test(void)
|
||
{
|
||
uint32_t i;
|
||
uint16_t temp;
|
||
Formatting_test();
|
||
res = f_open(&file1,"FatFs.txt",FA_CREATE_ALWAYS | FA_WRITE | FA_READ); // ´ò¿ªÇý¶¯Æ÷0ÉϵÄÔ´Îļþ
|
||
if(res == FR_OK){
|
||
printf("Îļþ´ò¿ª³É¹¦\r\n");
|
||
}
|
||
else{
|
||
printf("Îļþ´ò¿ªÊ§°Ü\r\n");
|
||
}
|
||
printf("¿ªÊ¼Ð´Èë\r\n");
|
||
for(i=0;i<13000;i++)
|
||
{
|
||
*(uint16_t*)(Bank5_SDRAM_ADDR+2*i)=i%1000;
|
||
}
|
||
for(i=0;i<13000;i++)
|
||
{
|
||
temp=*(uint16_t*)(Bank5_SDRAM_ADDR+2*i);
|
||
|
||
res=f_write(&file1,&temp,2,&fnum);
|
||
}
|
||
f_sync(&file1);
|
||
res = f_lseek(&file1,0);
|
||
if(res == FR_OK){
|
||
uint16_t read_dat;
|
||
for(short int j=0;j<1000;j++){
|
||
res = f_read(&file1, &read_dat, 2, &fnum);
|
||
printf("¡·Îļþ¶ÁÈ¡³É¹¦,¶Áµ½×Ö½ÚÊý¾Ý£º%d\r\n",read_dat);
|
||
}
|
||
}
|
||
f_close(&file1);
|
||
f_mount(NULL,"0:",1);
|
||
}
|
||
|
||
void test__(void)
|
||
{
|
||
SPI_Read_SDRAM();
|
||
cnn_run(); //´¦ÀíÍêµÄ10000¸öÊý¾ÝÒ²Ôڸú¯ÊýÖÐÉÏ´«ÔƶË
|
||
}
|
||
|
||
void Error_Handler(void)
|
||
{
|
||
/* USER CODE BEGIN Error_Handler_Debug */
|
||
/* User can add his own implementation to report the HAL error return state */
|
||
|
||
/* USER CODE END Error_Handler_Debug */
|
||
}
|
||
|
||
|