int main(int argc, char **argv) { /* 模块初始化 */ exc_init(); /* 中断初始化 */ sys_timer_init(); /* 系统时钟初始化 */ light_init(); /* LED灯初始化 */ switch_init(); /* 开关初始化 */ speaker_init(); /* 蜂鸣器初始化 */ motor_init(); /* 电机初始化 */ steer_init(); /* 舵机初始化 */ decoder_init(); /* 编码器初始化 */ serial_initialize((intptr_t)(NULL)); /* 初始化串口 */ //sd_init(&Fatfs); /* 初始化SD卡,并创建文件 */ //sd_create_file(&test_data, test_data_name); /* 命令注册 */ help_cmd_initialize((intptr_t)(NULL)); light_cmd_initialize((intptr_t)(NULL)); switch_cmd_initialize((intptr_t)(NULL)); speaker_cmd_initialize((intptr_t)(NULL)); motor_cmd_initialize((intptr_t)(NULL)); decoder_cmd_initialize((intptr_t)(NULL)); control_cmd_initialize((intptr_t)(NULL)); //sd_cmd_initialize((intptr_t)(NULL)); printf("\n Welcome to k60 software platform!"); printf("\n Press 'help' to get the help! \n"); //light_open(LIGHT4); /* ntshell测试 */ task_ntshell((intptr_t)(NULL)); }
void startup() { set_core_freq(STARTUP_CORE_FREQ); #ifndef NVIC_PRESENT irq_init(); #endif //NVIC_PRESENT //initialize system memory pools mem_init(); //initialize thread subsystem, create idle task thread_init(); #if (DBG_CONSOLE) dbg_console_create(); #endif #if (SW_TIMER_MODULE) sw_timer_init(); #endif //initialize RTC sys_time_init(); //initialize system timers sys_timer_init(); //user application initialize application_init(); //initialize seed srand(); }
static int sys_times(unsigned long *p) { static int inited = 0; if (!inited) { inited = 1; sys_timer_init(); } /* target clock runs at CLOCKS_PER_SEC. Convert to HZ */ if (p) #ifdef CYGSEM_REDBOOT_BSP_SYSCALLS_GPROF *p = (sys_timer_ticks * HZ) / (cyg_uint64)set_freq; #else *p = (sys_timer_ticks * HZ) / TICKS_PER_SEC; #endif // CYGSEM_REDBOOT_BSP_SYSCALLS_GPROF return 0; }
int main(int argc, char **argv) { int robot_state = FORWARD; int last_robot_state = FORWARD; int front_infrared_value = 0; int back_infrared_value = 0; int front_infrared_num = 0; int back_infrared_num = 0; int front_infrared_amount = 0; int back_infrared_amount = 0; int front_infrared_weight = 0; int back_infrared_weight = 0; uint32_t car_distence = 0; uint8_t get_char = 0; int change_num = 0; bool_t switch_state = 0; int detect_num = 0; int angle = 0; /* 模块初始化 */ exc_init(); /* 中断初始化 */ sys_timer_init(); /* 系统时钟初始化 */ light_init(); /* 灯初始化 */ switch_init(); /* 开关初始化 */ serial_initialize((intptr_t) (NULL)); /* 初始化串口 */ motor_init(); /* 电机初始化 */ steer_init(); /* 舵机初始化 */ decoder_init((intptr_t) (NULL)); /* 编码器初始化 */ infrared_init(); /* 红外初始化 */ while(1) { light_open(LIGHT2); light_open(LIGHT3); } // gpio_init(PORT_NO_GET(PTC0), PIN_NO_GET(PTC0), OUT_PUT, 0); // gpio_init(PORT_NO_GET(PTC2), PIN_NO_GET(PTC2),OUT_PUT, 1); // while(1) // { // motor_output(MOTOR_LEFT, 50); // motor_output(MOTOR_RIGHT, 50); // } while((get_char != 's') && (switch_state != SWITCH_ON)) { light_open_some(0x0f); get_char = serial_get_char(UART_NO_GET(UART_NO)); switch_state = switch_read(SWITCH0); } while (1) { get_char = serial_get_char(UART_NO_GET(UART_NO)); if(get_char == 'p') { last_robot_state = robot_state; robot_state = STOP; } /* 读取光电管的数据 */ front_infrared_value = infrared_read_loc(INFRARED_FRONT); back_infrared_value = infrared_read_loc(INFRARED_BACK); /* 读取红外从右第一个亮灯的位置 */ front_infrared_num = infrared_read_num(front_infrared_value); back_infrared_num = infrared_read_num(back_infrared_value); /* 读取传感器亮灯的总数 */ front_infrared_amount = infrared_read_amount(front_infrared_value); back_infrared_amount = infrared_read_amount(back_infrared_value); /* 读取权值 */ front_infrared_weight = infrared_read_weight(front_infrared_value); back_infrared_weight = infrared_read_weight(back_infrared_value); switch (robot_state) { /**********************************前进*************************************/ case FORWARD: light_open_some(0x01); light_bar_open(LIGHT_BAR0); light_bar_close(LIGHT_BAR1); if (front_infrared_amount == 1) { if (front_infrared_weight == 3) { angle = 40; //motor_output2(13, 13); } else if (front_infrared_weight == -3) { angle = -40; //motor_output2(13, 13); } else if (front_infrared_weight == 2) { angle = 20; //motor_output2(13, 13); } else if (front_infrared_weight == -2) { angle = -20; //motor_output2(13, 13); } else if (front_infrared_weight == 1) { angle = 5; //motor_output2(13, 13); } else if (front_infrared_weight == -1) { angle = -5; //motor_output2(13, 13); } } else if (front_infrared_amount == 2) { if (front_infrared_weight == 5) { angle = 30; //motor_output2(13, 13); } else if (front_infrared_weight == -5) { angle = -30; //motor_output2(13, 13); } else if (front_infrared_weight == 3) { angle = 10; //motor_output2(13, 13); } else if (front_infrared_weight == -3) { angle = -10; //motor_output2(13, 13); } else if (front_infrared_weight == 0) { angle = 0; //motor_output2(13, 13); } } steer_output_angle(STEER_DIR, angle); speed_control_forward(30,angle); if (front_infrared_amount > 4) { if(change_num == 4) { robot_state = STOP; } detect_num ++; if(detect_num > 2) { detect_num = 0; robot_state = FORWARD_CHANGE; car_distence = gl_distanceTotal; } } else { detect_num = 0; } break; /**********************************前进转换1*************************************/ case FORWARD_CHANGE: light_bar_open(LIGHT_BAR0); light_bar_open(LIGHT_BAR1); light_open_some(0x02); steer_output_angle(STEER_DIR, 40); //motor_output2(-25, -10); speed_control_backward(30,angle); if((gl_distanceTotal - car_distence)>9) { robot_state = FORWARD_CHANGE2; } break; /**********************************前进转换2*************************************/ case FORWARD_CHANGE2: light_bar_open(LIGHT_BAR0); light_bar_open(LIGHT_BAR1); light_open_some(0x02); steer_output_angle(STEER_DIR, 40); //motor_output2(-25, -10); speed_control_backward(30,angle); if((back_infrared_value & 0x30) && (!(back_infrared_value & 0x03)) && (front_infrared_amount < 3)) { robot_state = BACKWARD; car_distence = gl_distanceTotal; change_num ++; } break; /************************************后退****************************************/ case BACKWARD: light_bar_open(LIGHT_BAR1); light_bar_close(LIGHT_BAR0); light_open_some(0x04); if (back_infrared_amount == 1) { if (back_infrared_weight == 3) { angle = -40; //motor_output2(-5, -22); } else if (back_infrared_weight == -3) { angle = 40; //motor_output2(-22, -5); } else if (back_infrared_weight == 2) { angle = -40; //motor_output2(-5, -20); } else if (back_infrared_weight == -2) { angle = 40; //motor_output2(-20, -5); } else if (back_infrared_weight == 1) { angle = -5; //motor_output2(-14, -14); } else if (back_infrared_weight == -1) { angle = 5; //motor_output2(-14, -14); } } else if (back_infrared_amount == 2) { if (back_infrared_weight == 5) { angle = -40; //motor_output2(-5, -20); } else if (back_infrared_weight == -5) { angle = 40; //motor_output2(-20, -5); } else if (back_infrared_weight == 3) { angle = -20; //motor_output2(-5, -20); } else if (back_infrared_weight == -3) { angle = 20; //motor_output2(-20, -5); } else if (back_infrared_weight == 0) { angle = 0; //motor_output2(-14, -14); } } steer_output_angle(STEER_DIR, angle); speed_control_backward(30,angle); if(back_infrared_amount > 4) { detect_num ++; if(detect_num > 2) { detect_num = 0; robot_state = BACKWARD_CHANGE; car_distence = gl_distanceTotal; } } else { detect_num = 0; } break; /************************************后退转换1****************************************/ case BACKWARD_CHANGE: light_bar_open(LIGHT_BAR0); light_bar_open(LIGHT_BAR1); light_open_some(0x8); steer_output_angle(STEER_DIR, -35); speed_control_forward(30,angle); if((gl_distanceTotal - car_distence)>7) { robot_state = BACKWARD_CHANGE2; } break; /************************************后退转换2****************************************/ case BACKWARD_CHANGE2: light_bar_open(LIGHT_BAR0); light_bar_open(LIGHT_BAR1); light_open_some(0x8); steer_output_angle(STEER_DIR, -35); speed_control_forward(30,angle); if((front_infrared_value & 0x38) && (!(front_infrared_value & 0x03)) && (back_infrared_amount < 3)) { robot_state = FORWARD; change_num ++; } break; /************************************停车****************************************/ case STOP: light_open_some(0x03); light_bar_close(LIGHT_BAR0); light_bar_close(LIGHT_BAR1); motor_output2(0, 0); steer_output_angle(STEER_DIR, 0); if(get_char == 's') { robot_state = last_robot_state; } break; } } }
int main() { int i; #ifdef FPGA pll_init(); #else bt16_pll_init(); #endif delay(500000); uart_init((96000000/ 460800)); // pa8 puts(pubDate); puts("...fpga bt16 setup ok.......\n"); #ifdef FPGA spi_int(); #endif puts("-----1\n"); system_init(); puts("-----2\n"); timer0_start(); puts("-----3\n"); RF_init(); //----------debug HWI_Install(1, exception_isr, 3) ; //timer0_isr ENABLE_INT(); puts("-----4\n"); thread_init(os_create_thread, os_delete_thread); puts("-----5\n"); sys_timer_init(); puts("-----6\n"); ble_main(); btstack_main(); /* device_manager_init(); */ /*INTALL_HWI(BT_BLE_INT, le_hw_isr, 0); INTALL_HWI(18, le_test_uart_isr, 0);*/ lbuf_init(malloc_buf, sizeof(malloc_buf)*4); /* btstack_v21_main(); */ puts("------------4.0 start run loop-----------\n"); while(1) { int c; //asm("idle"); /*delay(100000);*/ for (i=0; i<PRIORITY_NUM; i++) { if (thread_fun[i]){ thread_fun[i](i); } } c = getchar(); switch(c) { case 'A': puts("user cmd : ADV\n"); ble_set_adv(); break; case 'S': puts("user cmd : SCAN\n"); ble_set_scan(); break; default: break; } /*run_loop_execute();*/ /*printf("k");*/ } return 0; }
int main(int argc, char **argv) { uint32_t buff_r; FRESULT res; uint32_t n = 0, j = 0; int32_t y_temp = -1; int temp = 0; uint32_t time[64]; uint32_t time_temp[4]; uint32_t time_start = 0; uint32_t time_end = 0; /* 模块初始化 */ exc_init(); /* 中断初始化 */ sys_timer_init(); /* 系统时钟初始化 */ light_init(); /* LED灯初始化 */ serial_initialize((intptr_t)(NULL)); /* 初始化串口 */ sd_init(&Fatfs); /* 初始化SD卡,并创建文件 */ sd_create_file(&image_data, image_data_name); /* create a file */ printf("\n Welcome to k60 software platform! \n"); light_open(LIGHT4); res = f_open(&image_data, "0:DATA.TXT", FA_OPEN_EXISTING | FA_READ); res = f_read(&image_data, buffer, sizeof(buffer), &buff_r); ////// for(n=0; n<64; n++) ////// { ////// for(j=0;j<4;j++) ////// { // sys_timer_read(&time_start); compress_image(); // sys_timer_read(&time_end); ////// ////// time_temp[j] = time_start - time_end; ////// ////// } ////// time[n] = (time_temp[0] +time_temp[1]+time_temp[2]+time_temp[3])/4; ////// } // res = f_open(&image_data, "0:A_IMAGE.TXT", FA_OPEN_EXISTING | FA_WRITE); // /* 取出制表符 */ // if (image_data.fs) // { // for (n = 0; n < ((12800*2) +100) ; n++) // { // if((buffer[n] == '0') || (buffer[n] == '1')) // f_printf(&image_data, "%c", buffer[n]); // } // } // /* 写原始数据 */ //// if (image_data.fs) //// { //// for (n = 0; n < 12800 ; n++) //// { //// if(n%128 == 0) //// { //// y_temp ++; //// } //// //// if(buffer[n] == '0') //// { //// f_printf(&image_data, "%d\t", (n%128)); //// f_printf(&image_data, "%d\n", y_temp); //// } //// } //// } /* 写压缩后图像 */ // if (image_data.fs) // { // for (n = gl_SRNum; n >0 ; n--) // { // f_printf(&image_data, "%d\t%d\n", // (int)StrRoadFind[n].CenterX, (int)StrRoadFind[n].CenterY); // } // } for (n = 0; n <12800 ; n++) { buffer[n] = 0; } for (n = gl_SRNum; n >0 ; n--) { if((int)StrRoadFind[n].Width<12) buffer[(int)StrRoadFind[n].CenterY * 128 + (int)StrRoadFind[n].CenterX] = 1; } if (image_data.fs) { for (n = 12800; n >0 ; n--) { if(n%128 == 0) { f_printf(&image_data, "\n%d\t", (int)buffer[n]); } else { f_printf(&image_data, "%d\t", (int)buffer[n]); } } } // for (n = gl_SRNum; n > 0; n--) // { // printf("%d\t%d\n", (int) StrRoadFind[n].CenterX, // (int) StrRoadFind[n].CenterY); // } // printf("time cost is %d\n", (time_start - time_end)/100); //// for(n=0;n<64;n++) //// { //// f_printf(&image_data, "%d\t%d\n", //// n, time[n]); //// } //// // f_printf(&image_data, "COMPRESS OVER"); // sys_timer_read(&time_start); // find_road(); // sys_timer_read(&time_end); //printf("time cost is %d\n", (time_start - time_end)/100); sd_close_file(&image_data); /* 关闭文件 */ while(1) { light_open(LIGHT6); } }
int main(int argc, char **argv) { uint8_t n = 1, p = 2, q = 0, f = 0; uint32_t e = 0; uint32_t test_time = 0; /* 模块初始化 */ exc_init(); /* 中断初始化 */ sys_timer_init(); /* 系统时钟初始化 */ light_init(); /* LED灯初始化 */ // motor_init(); // serial_initialize((intptr_t)(NULL)); /* 初始化串口 */ sd_init(&Fatfs); /* 初始化SD卡,并创建文件 */ sd_create_file(&test_data, test_data_name); /* create a file */ // printf("\n Welcome to k60 software platform! \n"); // printf(" *** This is a test for SD module! *** \n"); // light_open(LIGHT4); // // printf(" \n>>>> The data will be writen into the SD card! \n"); // for(test_time = 0;test_time < 65535; test_time++) // { // test_sd_data[test_time] = test_time; // } /* 写数据 */ if (test_data.fs) { f_printf(&test_data, "Hello SD Card!\n"); f_printf(&test_data, "This is a test!\n"); f_printf(&test_data, "1 2 3 4 5 6 7 8 9\n"); f_printf(&test_data, "~ ! # $ % ^ & * (\n"); // for(test_time = 0;test_time < 65535; test_time++) // { // f_printf(&test_data, "%d\t", test_sd_data[test_time]); // } } f_printf(&test_data, "TEST OVER\n"); sd_close_file(&test_data); /* 关闭文件 */ //for(n=0;n<128;n++) // while(1) // { // SD_SendData(n); // SD_SendData(p); // SD_SendData(q); // SD_SendData(f); // SD_SendData(CRLF); // // for(e = 0; e< 65535; e++); // } // // printf(" \n>>>> A test for SD module is over!\n"); while(1) { light_open(LIGHT6); } }
int main(int argc, char **argv) { uint8_t motor_no = 0; uint8_t motor_total_no = 2; uint8_t n =0; uint8_t get_char = 0; ER motor_msg = 0; int32_t motor_duty = 20; /* 模块初始化 */ exc_init(); /* 中断初始化 */ sys_timer_init(); /* 系统时钟初始化 */ motor_init(); /* 电机初始化 */ //serial_initialize((intptr_t)(NULL)); /* 初始化串口 */ //gpio_init(PORT_NO_GET(PTC0), PIN_NO_GET(PTC0), OUT_PUT, 0); //gpio_init(PORT_NO_GET(PTC2), PIN_NO_GET(PTC2),OUT_PUT, 1); while(1) { motor_output(MOTOR_LEFT, 50); motor_output(MOTOR_RIGHT, 50); } printf("\n Welcome to k60 software platform! \n"); while (1) { printf(" *** This is a test for motor module! *** \n"); printf(" \n>>>> One motor will be powered on followed by another! \n"); for (motor_no = 0; motor_no < motor_total_no; motor_no++) { delay(120); switch (motor_no) { case 0: motor_msg = motor_output(MOTOR0, motor_duty); break; case 1: motor_msg = motor_output(MOTOR1, motor_duty); break; default: printf("The motor number is error!\n"); break; } if (motor_msg == E_ID) { printf(" The ID of motor%d is error !\n", motor_no); } else if (motor_msg == E_ILUSE) { printf(" The port of motor%d is not open !\n", motor_no); } else { printf(" The motor%d has been powered on!\n", motor_no); } } delay(200); motor_duty = 0; printf(" \n>>>> All the motors will change the direction and duty!\n"); for (n = 0; n < 16; n++) { if(n < 8) { motor_duty = motor_duty + 10; } else { motor_duty = motor_duty - 10; } printf("The duty of the motor is %d\n", (int)motor_duty); motor_output(MOTOR0, motor_duty); delay(50); } motor_duty = 0; for (n = 0; n < 16; n++) { if(n < 8) { motor_duty = motor_duty - 10; } else { motor_duty = motor_duty + 10; } printf("The duty of the motor is %d\n", (int)motor_duty); motor_output(MOTOR0, motor_duty); delay(50); } printf(" \n>>>> A test for motor module is over!\n"); while (1) { printf(" \n>>>> Press 'n' to test once more.\n"); serial_rea_dat(NTSHELL_PORTID, &get_char, 1); if (get_char == 'n') { printf("Once more \n"); delay(200); break; } } } }