int main(void) { delay_init(); //??????? NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); //??NVIC????2:2??????,2?????? uart_init(115200); //??????115200 LED_Init(); //LED????? TFTLCD_Init(); //LCD??? KEY_Init(); //????? ctp_dev.init(); //?????? FSMC_SRAM_Init(); //???SRAM TIM3_Int_Init(999,71); //1KHZ ???1ms TIM6_Int_Init(999,719); //10ms?? my_mem_init(SRAMIN); //???????? my_mem_init(SRAMEX); //???????? RCC_AHBPeriphClockCmd(RCC_AHBPeriph_CRC,ENABLE);//??CRC??,??STemWin???? GUI_Init(); WM_SetCreateFlags(WM_CF_MEMDEV); GUI_Init();//???????? demo???????? ????????? startUp_Window(); //?????? while(1); }
void SDCard_Init(void) { u32 total,free; u8 res=0; W25QXX_Init(); //初始化W25Q128 my_mem_init(SRAMIN); //初始化内部内存池 my_mem_init(SRAMCCM); //初始化CCM内存池 while(SD_Init())//检测不到SD卡 { LCD_ShowString(30,150,200,16,16,"SD Card Error!"); delay_ms(500); LCD_ShowString(30,150,200,16,16,"Please Check! "); delay_ms(500); LED0=!LED0;//DS0闪烁 } exfuns_init(); //为fatfs相关变量申请内存 f_mount(fs[0],"0:",1); //挂载SD卡 res=f_mount(fs[1],"1:",1); //挂载FLASH. if(res==0X0D)//FLASH磁盘,FAT文件系统错误,重新格式化FLASH { LCD_ShowString(30,150,200,16,16,"Flash Disk Formatting..."); //格式化FLASH res=f_mkfs("1:",1,4096);//格式化FLASH,1,盘符;1,不需要引导区,8个扇区为1个簇 if(res==0) { f_setlabel((const TCHAR *)"1:ALIENTEK"); //设置Flash磁盘的名字为:ALIENTEK LCD_ShowString(30,150,200,16,16,"Flash Disk Format Finish"); //格式化完成 }else LCD_ShowString(30,150,200,16,16,"Flash Disk Format Error "); //格式化失败 delay_ms(1000); } LCD_Fill(30,150,240,150+16,WHITE); //清除显示 while(exf_getfree("0",&total,&free)) //得到SD卡的总容量和剩余容量 { LCD_ShowString(30,150,200,16,16,"SD Card Fatfs Error!"); delay_ms(200); LCD_Fill(30,150,240,150+16,WHITE); //清除显示 delay_ms(200); LED0=!LED0;//DS0闪烁 } POINT_COLOR=BLUE;//设置字体为蓝色 LCD_ShowString(30,150,200,16,16,"FATFS OK!"); LCD_ShowString(30,170,200,16,16,"SD Total Size: MB"); LCD_ShowString(30,190,200,16,16,"SD Free Size: MB"); LCD_ShowNum(30+8*14,170,total>>10,5,16); //显示SD卡总容量 MB LCD_ShowNum(30+8*14,190,free>>10,5,16); //显示SD卡剩余容量 MB }
//主函数 int main(void) { OS_ERR err; CPU_SR_ALLOC(); delay_init(168); //时钟初始化 NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);//中断分组配置 uart_init(115200); //串口初始化 LED_Init(); //LED初始化 LCD_Init(); //LCD初始化 KEY_Init(); //按键初始化 BEEP_Init(); //初始化蜂鸣器 FSMC_SRAM_Init(); //初始化SRAM my_mem_init(SRAMIN);//初始化内部RAM ucos_load_main_ui();//加载主UI OSInit(&err); //初始化UCOSIII OS_CRITICAL_ENTER(); //进入临界区 //创建开始任务 OSTaskCreate((OS_TCB * )&StartTaskTCB, //任务控制块 (CPU_CHAR * )"start task", //任务名字 (OS_TASK_PTR )start_task, //任务函数 (void * )0, //传递给任务函数的参数 (OS_PRIO )START_TASK_PRIO, //任务优先级 (CPU_STK * )&START_TASK_STK[0], //任务堆栈基地址 (CPU_STK_SIZE)START_STK_SIZE/10, //任务堆栈深度限位 (CPU_STK_SIZE)START_STK_SIZE, //任务堆栈大小 (OS_MSG_QTY )0, //任务内部消息队列能够接收的最大消息数目,为0时禁止接收消息 (OS_TICK )0, //当使能时间片轮转时的时间片长度,为0时为默认长度, (void * )0, //用户补充的存储区 (OS_OPT )OS_OPT_TASK_STK_CHK|OS_OPT_TASK_STK_CLR, //任务选项 (OS_ERR * )&err); //存放该函数错误时的返回值 OS_CRITICAL_EXIT(); //退出临界区 OSStart(&err); //开启UCOSIII }
int main(void) { u32 i; delay_init(); //延时函数初始化 NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);//设置中断优先级分组为组2:2位抢占优先级,2位响应优先级 uart_init(115200); //串口初始化为115200 LED_Init(); //初始化与LED连接的硬件接口 KEY_Init(); //初始化按键 LCD_Init(); //初始化LCD TIM3_Int_Init(1000,719); //定时器3频率为100hz usmart_dev.init(72); //初始化USMART FSMC_SRAM_Init(); //初始化外部SRAM my_mem_init(SRAMIN); //初始化内部内存池 my_mem_init(SRAMEX); //初始化外部内存池 POINT_COLOR=RED; //设置字体为红色 LCD_ShowString(30,30,200,16,16,"ENC28J60+STM32"); LCD_ShowString(30,50,200,16,16,"LWIP Test!"); LCD_ShowString(30,70,200,16,16,"ATOM@ALIENTEK"); LCD_ShowString(30,90,200,16,16,"2015/4/27"); while(lwip_comm_init()) //lwip初始化 { LCD_ShowString(30,110,200,20,16,"LWIP Init Falied!"); delay_ms(1200); LCD_Fill(30,110,230,130,WHITE); //清除显示 LCD_ShowString(30,110,200,16,16,"Retrying..."); } LCD_ShowString(30,110,200,20,16,"LWIP Init Success!"); LCD_ShowString(30,130,200,16,16,"DHCP IP configing..."); #if LWIP_DHCP //使用DHCP while((lwipdev.dhcpstatus!=2)&&(lwipdev.dhcpstatus!=0XFF))//等待DHCP获取成功/超时溢出 { lwip_periodic_handle(); //LWIP内核需要定时处理的函数 } #endif show_address(lwipdev.dhcpstatus); //显示地址信息 while(1) { lwip_periodic_handle(); //LWIP内核需要定时处理的函数 i++; if(i==50000) { LED0=~LED0; i=0; } } }
int main(void) { delay_init(); //延时函数初始化 NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);//设置中断优先级分组为组2:2位抢占优先级,2位响应优先级 uart_init(115200); //串口初始化为115200 LED_Init(); //初始化与LED连接的硬件接口 KEY_Init(); //初始化按键 LCD_Init(); //初始化LCD usmart_dev.init(72); //初始化USMART FSMC_SRAM_Init(); //初始化外部SRAM my_mem_init(SRAMIN); //初始化内部内存池 my_mem_init(SRAMEX); //初始化外部内存池 POINT_COLOR=RED; //设置字体为红色 LCD_ShowString(30,30,200,16,16,"ENC28J60+STM32"); LCD_ShowString(30,50,200,16,16,"TCP CLIENT NETCONN Test"); LCD_ShowString(30,70,200,16,16,"ATOM@ALIENTEK"); LCD_ShowString(30,90,200,16,16,"2015/4/30"); POINT_COLOR = BLUE; //蓝色字体 OSInit(); //UCOS初始化 while(lwip_comm_init()) //lwip初始化 { LCD_ShowString(30,130,200,20,16,"Lwip Init failed!"); //lwip初始化失败 delay_ms(500); LCD_Fill(30,130,230,150,WHITE); delay_ms(500); } LCD_ShowString(30,130,200,20,16,"Lwip Init Success!"); //lwip初始化成功 while(tcp_server_init()) //初始化tcp_client(创建tcp_client线程) { LCD_ShowString(30,150,200,20,16,"TCP Server failed!!"); //tcp客户端创建失败 delay_ms(500); LCD_Fill(30,150,230,170,WHITE); delay_ms(500); } LCD_ShowString(30,150,200,20,16,"TCP Server Success!"); //udp创建成功 OSTaskCreate(start_task,(void*)0,(OS_STK*)&START_TASK_STK[START_STK_SIZE-1],START_TASK_PRIO); OSStart(); //开启UCOS }
//主函数 int main(void) { OS_ERR err; CPU_SR_ALLOC(); delay_init(168); //时钟初始化 NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);//中断分组配置 uart_init(115200); //串口初始化 LED_Init(); //LED初始化 LCD_Init(); //LCD初始化 KEY_Init(); //按键初始化 FSMC_SRAM_Init(); //初始化SRAM my_mem_init(SRAMIN);//初始化内部RAM POINT_COLOR = RED; LCD_ShowString(30,10,200,16,16,"Explorer STM32F4"); LCD_ShowString(30,30,200,16,16,"UCOSIII Examp 13-1"); LCD_ShowString(30,50,200,16,16,"Pend Multi"); LCD_ShowString(30,70,200,16,16,"ATOM@ALIENTEK"); LCD_ShowString(30,90,200,16,16,"2015/5/20"); POINT_COLOR = BLACK; LCD_DrawRectangle(5,110,234,314); LCD_DrawLine(5,130,234,130); POINT_COLOR = RED; LCD_ShowString(50,111,200,16,16,"ObjRdy_NUM: 0"); POINT_COLOR = BLUE; OSInit(&err); //初始化UCOSIII OS_CRITICAL_ENTER(); //进入临界区 //创建开始任务 OSTaskCreate((OS_TCB * )&StartTaskTCB, //任务控制块 (CPU_CHAR * )"start task", //任务名字 (OS_TASK_PTR )start_task, //任务函数 (void * )0, //传递给任务函数的参数 (OS_PRIO )START_TASK_PRIO, //任务优先级 (CPU_STK * )&START_TASK_STK[0], //任务堆栈基地址 (CPU_STK_SIZE)START_STK_SIZE/10, //任务堆栈深度限位 (CPU_STK_SIZE)START_STK_SIZE, //任务堆栈大小 (OS_MSG_QTY )0, //任务内部消息队列能够接收的最大消息数目,为0时禁止接收消息 (OS_TICK )0, //当使能时间片轮转时的时间片长度,为0时为默认长度, (void * )0, //用户补充的存储区 (OS_OPT )OS_OPT_TASK_STK_CHK|OS_OPT_TASK_STK_CLR, //任务选项 (OS_ERR * )&err); //存放该函数错误时的返回值 OS_CRITICAL_EXIT(); //退出临界区 OSStart(&err); //开启UCOSIII }
int main(void) { u32 fontcnt; u8 i,j; u8 fontx[2];//gbk码 u8 key,t; delay_init(); //延时函数初始化 NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);//设置中断优先级分组为组2:2位抢占优先级,2位响应优先级 uart_init(115200); //串口初始化为115200 usmart_dev.init(72); //初始化USMART LED_Init(); //初始化与LED连接的硬件接口 KEY_Init(); //初始化按键 LCD_Init(); //初始化LCD W25QXX_Init(); //初始化W25Q128 my_mem_init(SRAMIN); //初始化内部内存池 exfuns_init(); //为fatfs相关变量申请内存 f_mount(fs[0],"0:",1); //挂载SD卡 f_mount(fs[1],"1:",1); //挂载FLASH. while(font_init()) //检查字库 { LCD_Clear(WHITE); //清屏 POINT_COLOR=RED; //设置字体为红色 LCD_ShowString(30,50,200,16,16,"WarShip STM32"); while(SD_Init()) //检测SD卡 { LCD_ShowString(30,70,200,16,16,"SD Card Failed!"); delay_ms(200); LCD_Fill(30,70,200+30,70+16,WHITE); delay_ms(200); } LCD_ShowString(30,70,200,16,16,"SD Card OK"); LCD_ShowString(30,90,200,16,16,"Font Updating..."); key=update_font(20,110,16,"0:");//更新字库 while(key)//更新失败 { LCD_ShowString(30,110,200,16,16,"Font Update Failed!"); delay_ms(200); LCD_Fill(20,110,200+20,110+16,WHITE); delay_ms(200); } LCD_ShowString(30,110,200,16,16,"Font Update Success! "); delay_ms(1500); LCD_Clear(WHITE);//清屏 } POINT_COLOR = MAGENTA; Show_Str(20,20,200,24,"第十一届全国电子",24,0); Show_Str(80,50,200,24,"设计大赛",24,0); POINT_COLOR = BLUE; Show_Str(60,80,200,24,"武昌首义学院",24,0); Show_Str(30,130,200,24,"参赛题目课题:",24,0); Show_Str(45,160,200,24,"旋转倒立摆",24,0); Show_Str(30,210,200,24,"参赛者:李观称",24,0); Show_Str(45,240,200,24,"赖丽清,张建",24,0); while(1) { fontcnt=0; for(i=0x81; i<0xff; i++) { fontx[0]=i; // LCD_ShowNum(118,150,i,3,16); //显示内码高字节 for(j=0x40; j<0xfe; j++) { if(j==0x7f)continue; fontcnt++; // LCD_ShowNum(118,170,j,3,16); //显示内码低字节 // LCD_ShowNum(118,190,fontcnt,5,16);//汉字计数显示 // fontx[1]=j; // Show_Font(30+132,220,fontx,24,0); // Show_Font(30+144,244,fontx,16,0); // Show_Font(30+108,260,fontx,12,0); t=200; while(t--)//延时,同时扫描按键 { delay_ms(1); } LED0=!LED0; } } } }
int main() { my_mem_init(memoire, TAILLE_MEMOIRE); printf("Test de l'etat initial de la memoire :\n"); my_mem_show(afficher_zone); assert(nb_free == 1); printf("TEST INIT OK\n\n"); printf("\n--------------------------\n\n"); printf("Test de free :\n"); mem_fit(&mem_fit_best); my_mem_alloc(500); my_mem_alloc(400); my_mem_alloc(300); my_mem_alloc(200); //my_mem_free(0); my_mem_free(1); //my_mem_free(2); my_mem_free(3); printf("Etat de la memoire :\n"); my_mem_show(afficher_zone); printf("nb_free = %d ; nb_busy = %d\n", nb_free, nb_busy); assert(nb_free == 2 && nb_busy == 2); printf("TEST FREE OK\n\n"); my_mem_init(memoire, TAILLE_MEMOIRE); printf("\n--------------------------\n\n"); printf("Test de best fit :\n"); my_mem_alloc(500); my_mem_alloc(400); my_mem_alloc(300); my_mem_alloc(200); my_mem_alloc(100); my_mem_alloc(200); my_mem_alloc(300); my_mem_alloc(400); my_mem_alloc(500); printf("Etat de la memoire :\n"); my_mem_free(0); my_mem_free(2); my_mem_free(4); my_mem_free(7); my_mem_alloc(200); printf("Etat de la memoire :\n"); my_mem_show(afficher_zone); printf("nb_free = %d ; nb_busy = %d\n", nb_free, nb_busy); assert(nb_free == 5 && nb_busy == 6); printf("TEST BEST OK\n\n"); my_mem_init(memoire, TAILLE_MEMOIRE); printf("\n--------------------------\n\n"); printf("Test de worst fit :\n"); mem_fit(&mem_fit_worst); my_mem_alloc(500); my_mem_alloc(400); my_mem_alloc(300); my_mem_alloc(200); my_mem_alloc(100); my_mem_alloc(200); my_mem_alloc(300); my_mem_alloc(400); my_mem_alloc(500); my_mem_alloc(1096); my_mem_free(0);//Libere 500 my_mem_free(2);//Libere 300 my_mem_free(4);//Libere 100 my_mem_alloc(200); printf("Etat de la memoire :\n"); my_mem_show(afficher_zone); printf("nb_free = %d ; nb_busy = %d\n", nb_free, nb_busy); assert(nb_free == 3 && nb_busy == 8); printf("TEST WORST OK\n\n"); printf("\n--------------------------\n\n"); printf("1.Best Fit est meilleur que First Fit :\n"); printf(" 1.1 Test avec Best fit :\n"); my_mem_init(memoire, TAILLE_MEMOIRE); mem_fit(&mem_fit_best); my_mem_alloc(200); my_mem_alloc(300); my_mem_alloc(100); my_mem_alloc(3456); my_mem_free(0);//Libere 200 my_mem_free(2);//Libere 100 my_mem_alloc(90); my_mem_alloc(190); my_mem_show(afficher_zone); printf("\n 1.2 Test avec First fit :\n"); my_mem_init(memoire, TAILLE_MEMOIRE); my_mem_alloc(200); my_mem_alloc(300); my_mem_alloc(100); my_mem_alloc(3456); my_mem_free(0);//Libere 200 my_mem_free(2);//Libere 100 my_mem_alloc(90); my_mem_alloc(190);//Allocaionimpossible avec first fit my_mem_show(afficher_zone); printf("\n2.First Fit est meilleur que Best Fit :\n"); printf(" 2.1 Test avec First fit :\n"); my_mem_init(memoire, TAILLE_MEMOIRE); my_mem_alloc(200); my_mem_alloc(300); my_mem_alloc(100); my_mem_alloc(3456); my_mem_free(0);//Libere 200 my_mem_free(2);//Libere 100 my_mem_alloc(72); my_mem_alloc(112); my_mem_alloc(92); my_mem_show(afficher_zone); printf(" 2.2 Test avec Best fit :\n"); my_mem_init(memoire, TAILLE_MEMOIRE); mem_fit(&mem_fit_best); my_mem_alloc(200); my_mem_alloc(300); my_mem_alloc(100); my_mem_alloc(3456); my_mem_free(0);//Libere 200 my_mem_free(2);//Libere 100 my_mem_alloc(72); my_mem_alloc(112);//Allocation impossible avec best_fit my_mem_alloc(92); my_mem_show(afficher_zone); }
int main() { size_t struct_fb_size, struct_bb_size; int i, j, nb_alloc = 0, size; char *result; struct timeval tv; my_mem_init(memoire, TAILLE_MEMOIRE); printf("Test de l'etat initial de la memoire :\n"); my_mem_show(afficher_zone); assert(nb_free == 1); printf("TEST OK\n\n"); printf("Test de base, serie d'allocations :\n"); my_mem_alloc(8); my_mem_alloc(16); my_mem_alloc(4); my_mem_alloc(12); printf("Etat de la memoire :\n"); my_mem_show(afficher_zone); assert(nb_free == 1 && nb_busy == 4); printf("TEST OK\n\n"); printf("Test de mem_init :\n"); my_mem_init(memoire, TAILLE_MEMOIRE); printf("Etat de la memoire :\n"); my_mem_show(afficher_zone); assert(nb_free == 1 && nb_busy == 0); printf("TEST OK\n\n"); printf("Test d'allocation puis liberation :\n"); my_mem_alloc(4); my_mem_alloc(4); my_mem_alloc(30); my_mem_alloc(1); my_mem_alloc(64); my_mem_alloc(24); my_mem_alloc(23); my_mem_free(2); printf("Etat de la memoire :\n"); my_mem_show(afficher_zone); assert(nb_free == 2 && nb_busy == 6); printf("TEST OK\n\n"); printf("Verification de la taille des allocations (multiples de %zd)\n", sizeof(void*)); for (i=0; i<nb_busy; i++) assert((busy_size[i] & (sizeof(void*)-1)) == 0); printf("TEST OK\n\n"); { int i=1; intptr_t tmp = ~mem_align; while (tmp & 1) { tmp >>= 1; i <<= 1; } printf("L'alignement semble être systématique sur %i octets\n", i); } printf("Test de fusion amont :\n"); my_mem_free(1); printf("Etat de la memoire :\n"); my_mem_show(afficher_zone); struct_fb_size = free_size[0] - 36; assert(nb_free == 2 && nb_busy == 5); printf("TEST OK\n\n"); printf("Test de fusion aval :\n"); my_mem_free(3); printf("Etat de la memoire :\n"); my_mem_show(afficher_zone); assert(nb_free == 2 && nb_busy == 4); printf("TEST OK\n\n"); printf("Test de fusion amont+aval :\n"); my_mem_free(5); my_mem_show(decompte_zone); assert(nb_free == 3 && nb_busy == 3); my_mem_free(4); printf("Etat de la memoire :\n"); my_mem_show(afficher_zone); assert(nb_free == 2 && nb_busy == 2); printf("TEST OK\n\n"); printf("Récupération de la taille d'entête de bloc occupé:\n"); my_mem_init(memoire, TAILLE_MEMOIRE); my_mem_show(decompte_zone); struct_bb_size = free_size[0]; my_mem_alloc(__BIGGEST_ALIGNMENT__); my_mem_show(decompte_zone); struct_bb_size -= free_size[0] + __BIGGEST_ALIGNMENT__; printf("Apparemment la taille de votre entete de bloc occupe est de %lu " "octets\n", (unsigned long) struct_bb_size); printf("\n"); printf("Test d'allocation/liberation de tout l'espace :\n"); my_mem_init(memoire, TAILLE_MEMOIRE); my_mem_alloc(TAILLE_MEMOIRE - struct_bb_size); printf("Etat de la memoire :\n"); my_mem_show(afficher_zone); assert(nb_free == 0 && nb_busy == 1); my_mem_free(0); printf("Etat de la memoire :\n"); my_mem_show(afficher_zone); assert(nb_free == 1 && nb_busy == 0); printf("TEST OK\n\n"); printf("Récupération de la taille d'entête de bloc libre:\n"); my_mem_init(memoire, TAILLE_MEMOIRE); my_mem_alloc(4*__BIGGEST_ALIGNMENT__); my_mem_alloc(TAILLE_MEMOIRE - 2*struct_bb_size - 4*__BIGGEST_ALIGNMENT__); my_mem_show(afficher_zone); assert(nb_free == 0 && nb_busy == 2); my_mem_free(0); my_mem_show(decompte_zone); assert(nb_free == 1 && nb_busy == 1); for (i=1; i<4*__BIGGEST_ALIGNMENT__; i++) { my_mem_alloc(4*__BIGGEST_ALIGNMENT__ - i); my_mem_show(decompte_zone); assert((nb_free == 1 || nb_free == 0) && nb_busy == 2); if (nb_free == 1) { break; } my_mem_free(i+1); } struct_fb_size=i; printf("Apparemment la taille de votre entete de bloc libre est de %lu " "octets\n", (unsigned long) struct_fb_size); printf("\n"); printf("Test d'allocation/libération avec utilisation de la mémoire :\n"); gettimeofday(&tv, NULL); srand(tv.tv_usec); my_mem_init(memoire, TAILLE_MEMOIRE); my_mem_alloc(16); my_mem_alloc(4); my_mem_alloc(30); my_mem_alloc(1); my_mem_alloc(64); my_mem_alloc(24); my_mem_alloc(23); for (i=0; i<position; i++) for (j=0; j<sizes[i]; j++) ((char *) allocs[i])[j] = (char) rand(); my_mem_free(1); my_mem_free(3); my_mem_free(5); my_mem_alloc(4); for (i=0; i<position; i++) if ((i > 5) || (i & 1) == 0) for (j=0; j<sizes[i]; j++) ((char *) allocs[i])[j] = (char) rand(); printf("Etat de la memoire :\n"); my_mem_show(afficher_zone); /* Dans le cas de la politique worst_fit, nb_free est à 4 * il est à 3 dans les autres cas */ assert( (nb_free == 3 || nb_free == 4) && nb_busy == 5); printf("TEST OK\n\n"); printf("Test final, serie aléatoire d'allocations/libérations aléatoires " "avec utilisation de la mémoire :\n"); my_mem_init(memoire, TAILLE_MEMOIRE); for (i=0; i<1000; i++) { if (nb_alloc && (rand() & 1)) { for (j=0; !allocs[j]; j++) { } my_mem_free(j); allocs[j] = NULL; nb_alloc--; } else { size = rand() & 511; result = my_mem_alloc(size); if (result) { for (j=0; j<size; j++) result[j] = (char) rand(); nb_alloc++; } } } printf("TEST OK\n\n"); return 0; }
int main() { int struct_fb_size, struct_bb_size; int i, j, nb_alloc = 0, size, addr; char *result; my_mem_init(TAILLE_MEMOIRE); printf("Test de l'etat initial de la memoire :\n"); my_mem_show(afficher_zone); assert(nb_free == 1); printf("TEST OK\n\n"); printf("Test de base, serie d'allocations :\n"); my_mem_alloc(8); my_mem_alloc(16); my_mem_alloc(4); my_mem_alloc(12); printf("Etat de la memoire :\n"); my_mem_show(afficher_zone); assert(nb_free == 1 && nb_busy == 4); printf("TEST OK\n\n"); printf("Test de mem_reinit :\n"); my_mem_init(-1); printf("Etat de la memoire :\n"); my_mem_show(afficher_zone); assert(nb_free == 1); printf("TEST OK\n\n"); printf("Test d'allocation puis liberation :\n"); struct_bb_size = free_size[0]; my_mem_alloc(16); my_mem_show(decompte_zone); struct_bb_size -= free_size[0] + 16; my_mem_alloc(4); my_mem_alloc(30); my_mem_alloc(1); my_mem_alloc(64); my_mem_alloc(24); my_mem_alloc(23); my_mem_free(2); printf("Etat de la memoire :\n"); my_mem_show(afficher_zone); assert(nb_free == 2 && nb_busy == 6); printf("TEST OK\n\n"); printf("Verification de la taille des allocations (multiples de 4)\n"); for (i = 0; i < nb_busy; i++) assert((busy_size[i] & 3) == 0); printf("TEST OK\n\n"); printf("Test de fusion amont :\n"); my_mem_free(1); printf("Etat de la memoire :\n"); my_mem_show(afficher_zone); struct_fb_size = free_size[0] - 36; assert(nb_free == 2 && nb_busy == 5); printf("TEST OK\n\n"); printf("Test de fusion aval :\n"); my_mem_free(3); printf("Etat de la memoire :\n"); my_mem_show(afficher_zone); assert(nb_free == 2 && nb_busy == 4); printf("TEST OK\n\n"); printf("Test de fusion amont+aval :\n"); my_mem_free(5); my_mem_show(decompte_zone); assert(nb_free == 3 && nb_busy == 3); my_mem_free(4); printf("Etat de la memoire :\n"); my_mem_show(afficher_zone); assert(nb_free == 2 && nb_busy == 2); printf("TEST OK\n\n"); addr = (int) struct_fb_size; printf("Apparemment la taille de votre entete de bloc libre est de %d " "octets\n", &addr); addr = (int) struct_bb_size; printf("Apparemment la taille de votre entete de bloc occupe est de %d " "octets\n", &addr); printf("\n"); printf("Test d'allocation/liberation de tout l'espace :\n"); my_mem_init(-1); my_mem_alloc(TAILLE_MEMOIRE - struct_bb_size); printf("Etat de la memoire :\n"); my_mem_show(afficher_zone); assert(nb_free == 0 && nb_busy == 1); my_mem_free(0); printf("Etat de la memoire :\n"); my_mem_show(afficher_zone); assert(nb_free == 1 && nb_busy == 0); printf("TEST OK\n\n"); printf("Test d'allocation/libération avec utilisation de la mémoire :\n"); my_mem_init(-1); my_mem_alloc(16); my_mem_alloc(4); my_mem_alloc(30); my_mem_alloc(1); my_mem_alloc(64); my_mem_alloc(24); my_mem_alloc(23); for (i = 0; i < position; i++) for (j = 0; j < sizes[i]; j++) ((char *) allocs[i])[j] = (char) Random(); my_mem_free(1); my_mem_free(3); my_mem_free(5); my_mem_alloc(4); for (i = 0; i < position; i++) if ((i > 5) || (i & 1) == 0) for (j = 0; j < sizes[i]; j++) ((char *) allocs[i])[j] = (char) Random(); printf("Etat de la memoire :\n"); my_mem_show(afficher_zone); assert(nb_free == 3 && nb_busy == 5); printf("TEST OK\n\n"); printf("Test final, serie aléatoire d'allocations/libérations aléatoires " "avec utilisation de la mémoire :\n"); my_mem_init(-1); for (i = 0; i < 1000; i++) { if (nb_alloc && (Random() & 1)) { for (j = 0; !allocs[j]; j++) { } my_mem_free(j); allocs[j] = NULL; nb_alloc--; } else { size = Random() & 511; result = my_mem_alloc(size); if (result) { for (j = 0; j < size; j++) result[j] = (char) Random(); nb_alloc++; } } } printf("TEST OK\n\n"); return 0; }
int main() { size_t struct_fb_size, struct_bb_size; int i; my_mem_init(TAILLE_MEMOIRE); my_mem_show(afficher_zone); if(nb_free != 1) { PutString("assert failed ! 78\n"); Exit(0); } PutString("TEST OK\n\n"); my_mem_alloc(8); my_mem_alloc(16); my_mem_alloc(4); my_mem_alloc(12); PutString("Etat de la memoire :\n"); my_mem_show(afficher_zone); if(nb_free != 1 || nb_busy != 4) { PutString("assert failed ! 92\n"); Exit(0); } my_mem_init(TAILLE_MEMOIRE); my_mem_show(afficher_zone); if(nb_free != 1 || nb_busy != 0) { PutString("assert failed ! l89\n"); Exit(0); } PutString("TEST OK\n\n"); my_mem_alloc(4); my_mem_alloc(4); my_mem_alloc(30); my_mem_alloc(1); my_mem_alloc(64); my_mem_alloc(24); my_mem_alloc(23); my_mem_free(2); my_mem_show(afficher_zone); if(nb_free != 2 || nb_busy != 6) { PutString("assert failed ! l108\n"); Exit(0); } PutString("TEST OK\n\n"); { int al=1; unsigned int tmp = ~mem_align; while (tmp & 1) { tmp >>= 1; al <<= 1; } } my_mem_free(1); my_mem_show(afficher_zone); struct_fb_size = free_size[0] - 36; if(nb_free != 2 || nb_busy != 5) { PutString("assert failed ! 134\n"); Exit(0); } PutString("TEST OK\n\n"); my_mem_free(3); my_mem_show(afficher_zone); if(nb_free != 2 || nb_busy != 4) { PutString("assert failed ! 144\n"); Exit(0); } PutString("TEST OK\n\n"); my_mem_free(5); my_mem_show(decompte_zone); if(nb_free != 3 || nb_busy != 3) { PutString("assert failed ! 153\n"); Exit(0); } my_mem_free(4); my_mem_show(afficher_zone); if(nb_free != 2 || nb_busy != 2) { PutString("assert failed ! 160\n"); Exit(0); } PutString("TEST OK\n\n"); my_mem_init(TAILLE_MEMOIRE); my_mem_show(decompte_zone); struct_bb_size = free_size[0]; my_mem_alloc(__BIGGEST_ALIGNMENT__); my_mem_show(decompte_zone); struct_bb_size -= free_size[0] + __BIGGEST_ALIGNMENT__; my_mem_init(TAILLE_MEMOIRE); my_mem_alloc(TAILLE_MEMOIRE - struct_bb_size); my_mem_show(afficher_zone); if(nb_free != 0 || nb_busy != 1) { PutString("assert failed ! 182\n"); Exit(0); } my_mem_free(0); my_mem_show(afficher_zone); if(nb_free != 1 || nb_busy != 0) { PutString("assert failed ! 189\n"); Exit(0); } PutString("TEST OK\n\n"); my_mem_init(TAILLE_MEMOIRE); my_mem_alloc(4*__BIGGEST_ALIGNMENT__); my_mem_alloc(TAILLE_MEMOIRE - 2*struct_bb_size - 4*__BIGGEST_ALIGNMENT__); my_mem_show(afficher_zone); if(nb_free != 0 || nb_busy != 2) { PutString("assert failed ! 210\n"); Exit(0); } my_mem_free(0); my_mem_show(decompte_zone); if(nb_free != 1 || nb_busy != 1) { PutString("assert failed ! 217\n"); Exit(0); } for (i=1; i<4*__BIGGEST_ALIGNMENT__; i++) { my_mem_alloc(4*__BIGGEST_ALIGNMENT__ - i); my_mem_show(decompte_zone); if((nb_free != 1 && nb_free != 0) || nb_busy != 2) { PutString("assert failed ! 221\n"); } if (nb_free == 1) { break; } my_mem_free(i+1); } return 0; }
int main(void) { //定义全局变量 u8 key,mode; u16 t=0; u8 tmp_buf[33]; //函数初始化 delay_init(); //延时函数初始化 NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);//设置中断优先级分组为组2:2位抢占优先级,2位响应优先级 uart_init(115200); //串口初始化为115200 usmart_dev.init(72); //初始化USMART LED_Init(); //初始化与LED连接的硬件接口 KEY_Init(); //初始化按键 NRF24L01_Init(); //初始化NRF24L01 W25QXX_Init(); //初始化W25Q128 my_mem_init(SRAMIN); //初始化内部内存池 LCD_Init(); //初始化LCD exfuns_init(); //为fatfs相关变量申请内存 f_mount(fs[0],"0:",1); //挂载SD卡 f_mount(fs[1],"1:",1); //挂载FLASH. //检查中文字库 while(font_init()) //检查字库 { LCD_Clear(WHITE); //清屏 POINT_COLOR=RED; //设置字体为红色 LCD_ShowString(30,50,200,16,16,"WarShip STM32"); while(SD_Init()) //检测SD卡 { LCD_ShowString(30,70,200,16,16,"SD Card Failed!"); delay_ms(200); LCD_Fill(30,70,200+30,70+16,WHITE); delay_ms(200); } LCD_ShowString(30,70,200,16,16,"SD Card OK"); LCD_ShowString(30,90,200,16,16,"Font Updating..."); key=update_font(20,110,16,"0:");//更新字库 while(key)//更新失败 { LCD_ShowString(30,110,200,16,16,"Font Update Failed!"); delay_ms(200); LCD_Fill(20,110,200+20,110+16,WHITE); delay_ms(200); } LCD_ShowString(30,110,200,16,16,"Font Update Success! "); delay_ms(1500); LCD_Clear(WHITE);//清屏 } //检查无线通信 while(NRF24L01_Check()) { LCD_ShowString(30,130,200,16,16,"NRF24L01 Error"); delay_ms(200); LCD_Fill(30,130,239,130+16,WHITE); delay_ms(200); } //初始化界面 POINT_COLOR = MAGENTA; Show_Str(20,20,200,24,"第十一届全国电子",24,0); Show_Str(80,50,200,24,"设计大赛",24,0); while(1) { //按键扫描 key=KEY_Scan(0); if(key!=0) { LCD_Clear(WHITE); Show_Str(60,20,200,24,"旋转倒立摆",24,0); Show_Str(20,50,200,24,"任务1:",24,0); Show_Str(20,80,200,24,"任务2:",24,0); Show_Str(20,110,200,24,"任务3:",24,0); Show_Str(20,140,200,24,"任务4:",24,0); Show_Str(20,170,200,24,"任务5:",24,0); Show_Str(20,200,200,24,"任务6:",24,0); while(1) { key=KEY_Scan(0); //WKUP_PRES 功能:返回主界面 if(key==WKUP_PRES) { MUSE_TASK(); } //KEY1_PRES 功能:执行任务1 else if(key==KEY0_PRES) { KEY0_TASK(); } // //KEY1_PRES 功能:执行任务1 // else if(key==KEY1_PRES) // { // mode=1; // break; // } // //KEY2_PRES 功能:执行任务2 // else if(key==KEY2_PRES) // { // mode=1; // break; // } // //KEY3_PRES 功能:执行任务3 // else if(key==KEY3_PRES) // { // mode=1; // break; // } // //KEY4_PRES 功能:执行任务4 // else if(key==KEY4_PRES) // { // mode=1; // break; // } // //KEY5_PRES 功能:执行任务5 // else if(key==KEY5_PRES) // { // mode=1; // break; // } // //KEY6_PRES 功能:执行任务6 // else if(key==KEY6_PRES) // { // mode=1; // break; // } // //KEY7_PRES 功能:执行任务7 // else if(key==KEY7_PRES) // { // mode=1; // break; // } // //KEY8_PRES 功能:执行任务8 // else if(key==KEY8_PRES) // { // mode=1; // break; // } // } } t++; if(t==100) //LCD_ShowString(10,150,230,16,16,"KEY0:RX_Mode KEY1:TX_Mode"); //闪烁显示提示信息 Show_Str(10,150,230,24,"按任意键进入主菜单",24,0); if(t==200) { LCD_Fill(10,150,240,150+50,WHITE); t=0; } delay_ms(5); } }