/********************************** Main routine ************************************/ void main(){ // initialize board and the audio port init_hardware(); /* initialize hardware interrupts */ init_HWI(); sine_init(); /* loop indefinitely, waiting for interrupts */ while(1) {} }
int main( void ) { setup_hardware(); // @"../../hardware/hardware.h" init_led_utama(); init_hardware(); init_task_relay(); vTaskStartScheduler(); printf("Keluar dari Scheduler !!!!\r\n"); vTaskDelay(4000); /* Will only get here if there was insufficient memory to create the idle task. */ return 0; }
int main(int argc, char const *argv[]) { unsigned int i; unsigned int inumber; char line[LINE_SIZE]; struct file_desc_t fd; if (argc < 2) { printf("Usage : if_copy [inumber] -> ecrit le contenu de l'entrée standard dans l'inode de numero [inumber]\n"); return EXIT_FAILURE; } /* init hardware */ if(init_hardware("hardware.ini") == 0) { fprintf(stderr, "Error in hardware initialization\n"); exit(EXIT_FAILURE); } /* Interreupt handlers */ for(i=0; i<16; i++) { IRQVECTOR[i] = empty_it; } /* Allows all IT */ _mask(1); printf("Loading Master Boot Record...\n"); load_mbr(); load_super(0); inumber = atoi(argv[1]); open_ifile(&fd, inumber, 0); while (fgets(line, LINE_SIZE, stdin) != NULL) { write_ifile(&fd, line, strlen(line), 0); } close_ifile(&fd, 0); return EXIT_SUCCESS; }
int main(int argc, char**argv){ unsigned int i; unsigned int inumber; /* gestion des arguments */ if(argc != 1){ usage(); exit(EXIT_SUCCESS); } /* init hardware */ if(!init_hardware(HW_CONFIG)) { fprintf(stderr, "Initialization error\n"); exit(EXIT_FAILURE); } /* Interreupt handlers */ for(i=0; i<NB_EMPTY_FUNCTION; i++) IRQVECTOR[i] = empty_it; /* Allows all IT */ _mask(1); /* chargement du mbr */ if(!load_mbr()){ fprintf(stderr, "Erreur lors du chargement du Master Boot Record.\n"); exit(EXIT_FAILURE); } /* initialise le super du premier volume */ init_super(CURRENT_VOLUME); /* charge le super du premier volume dans la variable globale */ load_super(CURRENT_VOLUME); /* création du fichier */ inumber = create_ifile(IT_FILE); if(!inumber){ fprintf(stderr, "Erreur lors de la creation du fichier\n"); exit(EXIT_FAILURE); } printf("Création d'un fichier:\n"); printf("\tinumber: %d.\n", inumber); exit(inumber); }
int main(int argc, char**argv){ unsigned int i; unsigned fc = 0; unsigned fs = 1; unsigned nb_bloc = 10; /* init hardware */ if(!init_hardware(HW_CONFIG)) { fprintf(stderr, "Initialization error\n"); exit(EXIT_FAILURE); } /* Interreupt handlers */ for(i=0; i<NB_EMPTY_FUNCTION; i++) IRQVECTOR[i] = empty_it; /* Allows all IT */ _mask(1); /* chargement du mbr */ if(!load_mbr()){ fprintf(stderr, "Erreur lors du chargement du Master Boot Record.\n"); exit(EXIT_FAILURE); } if(mbr.mbr_n_vol < 1) { /* creation d'un volume bidon */ if(!make_vol(fc, fs, nb_bloc)) { fprintf(stderr, "Erreur a la creation d'un volume bidon.\n"); exit(EXIT_FAILURE); } /* initialise le super du volume 1 */ init_super(CURRENT_VOLUME); printf("Le volume principale a été créé avec succès.\n"); /* sauvegarde de tous les changements effectué sur le mbr */ save_mbr(); } else { printf("Le volume principale a déjà été créé!\n"); } exit(EXIT_SUCCESS); }
void programmeTest(){ int i,j; unsigned char buffer[HDA_SECTORSIZE]; initialisation(); printf("Test de dmps() : \n"); for(i=0;i<HDA_MAXCYLINDER;i++) for(j=0;j<HDA_MAXSECTOR;j++) dmps(i,j); printf("\nTest de frmt() : \n"); for(i=0;i<HDA_MAXCYLINDER;i++) for(j=0;j<HDA_MAXSECTOR;j++) dmps(i,j); init_hardware("hardware.ini"); printf("\n\n Réinitialisation du disque... \n"); printf("\n\nTest de read_sector() : \n"); for(i=0;i<HDA_MAXCYLINDER;i++){ for(j=0;j<HDA_MAXSECTOR;j++){ read_sector(i,j,buffer); } for(j=0;j<HDA_SECTORSIZE;j++) printf("%x ",buffer[i]); printf("\n"); } printf("\n\nTest de write_sector() : \n"); for(i=0;i<HDA_MAXCYLINDER;i++){ for(j=0;j<HDA_MAXSECTOR;j++){ write_sector(i,j,buffer); } for(j=0;j<HDA_SECTORSIZE;j++) printf("%x ",buffer[i]); printf("\n"); } printf("\n\nTest de format_sector() : \n"); for(i=0;i<HDA_MAXCYLINDER;i++){ for(j=0;j<HDA_SECTORSIZE;j++) buffer[j]=i; for(j=0;j<HDA_MAXSECTOR;j++){ write_sector(i,j,buffer); } for(j=0;j<HDA_SECTORSIZE;j++) printf("%x ",buffer[i]); printf("\n"); } }
int main(const int argc, const char *argv[]) { char version_string[256]; static struct s_hardware hardware; snprintf(version_string, sizeof version_string, "%s %s (%s)", PRODUCT_NAME, VERSION, CODENAME); /* Cleaning structures */ init_hardware(&hardware); /* Detecting Syslinux version */ detect_syslinux(&hardware); /* Detecting parameters */ detect_parameters(argc, argv, &hardware); /* Opening the Syslinux console */ init_console(&hardware); /* Detect hardware */ detect_hardware(&hardware); /* Clear the screen and reset position of the cursor */ clear_screen(); printf("\033[1;1H"); more_printf("%s\n", version_string); int return_code = 0; if (!menumode || automode) start_cli_mode(&hardware); else { return_code = start_menu_mode(&hardware, version_string); if (return_code == HDT_RETURN_TO_CLI) start_cli_mode(&hardware); } /* Do we got request to do something at exit time ? */ if (strlen(hardware.postexec)>0) { more_printf("Executing postexec instructions : %s\n",hardware.postexec); runsyslinuxcmd(hardware.postexec); } return return_code; }
/** * Main - Run the main program which prints the system time and flashes the LEDs * if certain conditions are met */ int main() { // Setup the hardware set_clock_speed(CPU_8MHz); init_hardware(); // Wait until the 'debugger' is attached... draw_centred(17, "Waiting for"); draw_centred(24, "debugger..."); show_screen(); while(!usb_configured() || !usb_serial_get_control()); send_debug_string("Debugger initialised. Debugging strings will appear below:"); // Run the main loop displaying the system time @ ~10Hz... char buff[BUFF_LENGTH]; unsigned long count = 0; send_debug_string("Entering main loop..."); while (1) { // Draw the current system time on the screen clear_screen(); sprintf(buff, "%7.4f", get_system_time()); draw_centred(21, buff); if (count < 1) { send_debug_string("Calling show_screen()..."); } show_screen(); if (count < 1) { send_debug_string("Finished show_screen()."); } _delay_ms(100); // Toggle LEDs if the conditions are met if ((count % 25) == 0) { PORTB ^= (1 << PB2); send_debug_string("LED0 was toggled."); } if ((count % 50) == 10) { PORTB ^= (1 << PB3); send_debug_string("LED1 was toggled."); } // Increment the loop count count++; enter_breakpoint(99); } // We'll never get here... return 0; }
/* Jennic equivalent of main() */ void AppColdStart(void) { /* default startup */ init_hardware(); process_init(); init_net(); procinit_init(); autostart_start(autostart_processes); jts_init(); /* default main loop */ while(1) { process_run(); etimer_request_poll(); } }
/* SECTION: Initialisation */ static int sir_ir_probe(struct platform_device *dev) { int retval; rcdev = devm_rc_allocate_device(&sir_ir_dev->dev, RC_DRIVER_IR_RAW); if (!rcdev) return -ENOMEM; rcdev->input_name = "SIR IrDA port"; rcdev->input_phys = KBUILD_MODNAME "/input0"; rcdev->input_id.bustype = BUS_HOST; rcdev->input_id.vendor = 0x0001; rcdev->input_id.product = 0x0001; rcdev->input_id.version = 0x0100; rcdev->tx_ir = sir_tx_ir; rcdev->allowed_protocols = RC_BIT_ALL_IR_DECODER; rcdev->driver_name = KBUILD_MODNAME; rcdev->map_name = RC_MAP_RC6_MCE; rcdev->timeout = IR_DEFAULT_TIMEOUT; rcdev->dev.parent = &sir_ir_dev->dev; setup_timer(&timerlist, sir_timeout, 0); /* get I/O port access and IRQ line */ if (!devm_request_region(&sir_ir_dev->dev, io, 8, KBUILD_MODNAME)) { pr_err("i/o port 0x%.4x already in use.\n", io); return -EBUSY; } retval = devm_request_irq(&sir_ir_dev->dev, irq, sir_interrupt, 0, KBUILD_MODNAME, NULL); if (retval < 0) { pr_err("IRQ %d already in use.\n", irq); return retval; } pr_info("I/O port 0x%.4x, IRQ %d.\n", io, irq); retval = devm_rc_register_device(&sir_ir_dev->dev, rcdev); if (retval < 0) return retval; init_hardware(); return 0; }
int main(void) { init_hardware(); // Note: for ROM development, use this version of delay function, // Which is in order to test if the VTCOR is correct. milliseconds_delay_init(); uint32_t leds = 0; while (1) { led_toggle(leds); milliseconds_delay(DELAY_1MS); ++leds; if (leds == LED_COUNT) { leds = 0; } } }
/** * Main - Run through the steps of configuring, greeting, getting a name, thanking, * and then quitting */ int main(void) { char buff[BUFF_LENGTH]; // Setup the hardware init_hardware(); // Wait until the USB port is configured and ready to go draw_centred(17, "Waiting for"); draw_centred(24, "computer..."); show_screen(); while (!usb_configured() || !usb_serial_get_control()); // Prompt the user for their name, and wait until they enter it clear_screen(); draw_centred(17, "Waiting for"); draw_centred(24, "username..."); show_screen(); send_line("Hello!"); send_line("Could you please tell me your name:"); recv_line(buff, BUFF_LENGTH); usb_serial_putchar('\n'); // Display their name on the Teensy and prompt them to exit char buff2[BUFF_LENGTH + 8]; sprintf(buff2, "Thanks %s!", buff); clear_screen(); draw_centred(21, buff2); show_screen(); send_line("Press 'q' to exit..."); while (usb_serial_getchar() != 'q'); // Display the finished information clear_screen(); draw_centred(21, "Goodbye!"); show_screen(); send_line("\r"); send_line("Done! Goodbye!"); while (1); // We'll never get here... return 0; }
/********************************** Main routine ************************************/ void main() { /* setup arrays */ init_arrays(); /* initialize board and the audio port */ init_hardware(); /* initialize hardware interrupts */ init_HWI(); /* loop indefinitely, waiting for interrupts */ while(1) { wait_buffer(); }; }
int main(void) { init_hardware(); //available characters (pattern.h) // ABCDEFGHIJKLMNOPQRSTUVWXYZ!.+-' uint8_t sentence[] = "Step back - I'm doing Science!"; int length = sizeof(sentence)/sizeof(sentence[0]); while(1){ int i; for (i=0; i<length; i++) { put_character(sentence[i]); } //Spaces at the end of the sentence put_character(0); put_character(0); } return 0; }
/********************************** Main routine ************************************/ void main() { int k; // used in various for loops /* Initialize and zero fill arrays */ inbuffer = (float *) calloc(CIRCBUF, sizeof(float)); /* Input array */ outbuffer = (float *) calloc(CIRCBUF, sizeof(float)); /* Output array */ inframe = (float *) calloc(FFTLEN, sizeof(float)); /* Array for processing*/ outframe = (float *) calloc(FFTLEN, sizeof(float)); /* Array for processing*/ inwin = (float *) calloc(FFTLEN, sizeof(float)); /* Input window */ outwin = (float *) calloc(FFTLEN, sizeof(float)); /* Output window */ M1 = (float *) calloc(FFTLEN, sizeof(float)); M2 = (float *) calloc(FFTLEN, sizeof(float)); M3 = (float *) calloc(FFTLEN, sizeof(float)); M4 = (float *) calloc(FFTLEN, sizeof(float)); N_i = (float *) calloc(FFTLEN, sizeof(float)); N = (float *) calloc(FFTLEN, sizeof(float)); P = (float *) calloc(FFTLEN, sizeof(float)); buffer = (complex *) calloc(FFTLEN, sizeof(complex)); /* initialize board and the audio port */ init_hardware(); /* initialize hardware interrupts */ init_HWI(); /* initialize algorithm constants */ for (k=0;k<FFTLEN;k++) { inwin[k] = sqrt((1.0-WINCONST*cos(PI*(2*k+1)/FFTLEN))/OVERSAMP); outwin[k] = inwin[k]; } ingain=INGAIN; outgain=OUTGAIN; /* main loop, wait for interrupt */ while(1) process_frame(); }
void hal_bsp_init(void) { int rc = 0; (void)rc; // Init pinmux and other hardware setup. init_hardware(); BOARD_BootClockRUN(); #if MYNEWT_VAL(UART_0) rc = os_dev_create((struct os_dev *) &os_bsp_uart0, "uart0", OS_DEV_INIT_PRIMARY, 0, uart_hal_init, NULL); assert(rc == 0); #endif #if MYNEWT_VAL(UART_1) rc = os_dev_create((struct os_dev *) &os_bsp_uart1, "uart1", OS_DEV_INIT_PRIMARY, 0, uart_hal_init, NULL); assert(rc == 0); #endif #if MYNEWT_VAL(UART_2) rc = os_dev_create((struct os_dev *) &os_bsp_uart2, "uart2", OS_DEV_INIT_PRIMARY, 0, uart_hal_init, NULL); assert(rc == 0); #endif #if MYNEWT_VAL(UART_3) rc = os_dev_create((struct os_dev *) &os_bsp_uart3, "uart3", OS_DEV_INIT_PRIMARY, 0, uart_hal_init, NULL); assert(rc == 0); #endif #if MYNEWT_VAL(UART_4) rc = os_dev_create((struct os_dev *) &os_bsp_uart4, "uart4", OS_DEV_INIT_PRIMARY, 0, uart_hal_init, NULL); assert(rc == 0); #endif #if MYNEWT_VAL(UART_5) rc = os_dev_create((struct os_dev *) &os_bsp_uart5, "uart5", OS_DEV_INIT_PRIMARY, 0, uart_hal_init, NULL); assert(rc == 0); #endif }
int main(int argc, char **argv) { unsigned int i; /* init hardware */ if(init_hardware("hardware.ini") == 0) { fprintf(stderr, "Error in hardware initialization\n"); exit(EXIT_FAILURE); } /* Interreupt handlers */ for(i=0; i<16; i++) IRQVECTOR[i] = empty_it; /* Allows all IT */ _mask(1); /* and exit! */ exit(EXIT_SUCCESS); }
int main(int argc, char* argv[]) { void *ptr; int res; printf("Init hardware...\n"); /* Initialise le matériel */ if(init_hardware(HARDWARE_INI) == 0) { fprintf(stderr, "Error in hardware initialization\n"); exit(EXIT_FAILURE); } /* Initialise le vecteur d'interruptions */ IRQVECTOR[MMU_IRQ] = mmu_handler; IRQVECTOR[SYSCALL_SWITCH_0] = switch_to_process0; IRQVECTOR[SYSCALL_SWITCH_1] = switch_to_process1; // Passe la main au code Utilisateur _mask(0x1001); printf("User mode...\n"); init(); }
int main (){ unsigned int i; if(init_hardware("hardware.ini") == 0) { fprintf(stderr, "Error in hardware initialization\n"); exit(EXIT_FAILURE); } /* Interrupt handlers */ for(i=0; i<16; i++) IRQVECTOR[i] = empty_it; /* Allows all IT */ _mask(1); chk_hda(); mbrvol(4,2,1); mbrvol(6,5,4); dvol(); return 1; }
int main(int argc, char **argv) { /* init hardware */ if(init_hardware("hardware.ini") == 0) { fprintf(stderr, "Error in hardware initialization\n"); exit(EXIT_FAILURE); } init_swap("swapfile"); memset(vm_mapping, 0, sizeof(struct vm_mapping_s) * VM_PAGES); memset(pm_mapping, 0, sizeof(struct pm_mapping_s) * PM_PAGES); IRQVECTOR[MMU_IRQ] = mmuhandler; _mask(0x1001); user_process(); return 0; }
int main(const int argc, const char *argv[]) { char version_string[256]; const char *arg; struct s_hardware hardware; snprintf(version_string, sizeof version_string, "%s %s (%s)", PRODUCT_NAME, VERSION, CODENAME); /* Cleaning structures */ init_hardware(&hardware); /* Detecting Syslinux version */ detect_syslinux(&hardware); /* Detecting parameters */ detect_parameters(argc, argv, &hardware); /* Opening the Syslinux console */ init_console(&hardware); /* Clear the screen and reset position of the cursor */ clear_screen(); printf("\033[1;1H"); printf("%s\n", version_string); if ((arg = find_argument(argv + 1, "nomenu")) || (find_argument(argv + 1, "auto"))) start_cli_mode(&hardware); else { int return_code = start_menu_mode(&hardware, version_string); if (return_code == HDT_RETURN_TO_CLI) start_cli_mode(&hardware); else return return_code; } return 0; }
/* ------------------------------ Initialization and finalization fucntions ------------------------------------------------------------*/ void mount() { char *hw_config; int status, i; /* Hardware initialization */ hw_config = get_hw_config(); status = init_hardware(hw_config); ffatal(status, "error in hardware initialization with %s\n", hw_config); /* Interrupt handlers */ for(i=0; i<16; i++) IRQVECTOR[i] = emptyIT; /* Allows all IT */ _mask(1); /* Load MBR and current volume */ load_mbr(); load_current_volume(); }
int main(int argc, char** argv) { int i,l; unsigned int cylinder, sector, size; enum vol_type_e type; if (argc != 5) { printf("Usage:\n\tcreate_vol <cylinder (0 to 15)> <sector (0 to 15)> <size> <type: ANNEXE|BASE|OTHER>\n"); exit(EXIT_FAILURE); } // Récupération des arguments cylinder = atoi(argv[1]); sector = atoi(argv[2]); size = atoi(argv[3]); if (!strcmp(argv[4],"BASE")) { type = BASE; } else if (!strcmp(argv[4],"ANNEXE")) { type = ANNEXE; } else if (!strcmp(argv[4],"OTHER")) { type = OTHER; } else { fprintf(stderr, "Type inconnu (ANNEXE|BASE|OTHER)\n"); exit(EXIT_FAILURE); } // Initialisation assert(init_hardware(HARDWARE_INI)); for(i = 0; i < 15; i++) IRQVECTOR[i] = empty_it; l = create_volume(cylinder, sector, size, type); if (l < 0) { exit(EXIT_FAILURE); } return EXIT_SUCCESS; }
int main(int argc, char **argv) { printf("\nDCPU-16 emulator (CPU spec 1.7) - Reid Horuff\n"); init_dcpu(); init_hardware(); init_disassembler(); if(argc > 1) { if(!open_file( argv[1] )){ printf("Error opening file\n"); } else if( argc > 2 && !strcmp(argv[2], "-d")){ init_disassembler(); dump_all(); exit(0); } } init_gui(argc, argv); return 0; }
int main(){ int nbSec,nbCyl,cylinder,secteur,i; if(init_hardware("hardware.ini") == 0) { fprintf(stderr, "Error in hardware initialization\n"); exit(EXIT_FAILURE); } /* Interreupt handlers */ for(i=0; i<16; i++) IRQVECTOR[i] = empty_it; /* Allows all IT */ _mask(1); _out(HDA_CMDREG,CMD_DSKINFO); nbCyl=_in(HDA_DATAREGS)<<8; nbCyl+=_in(HDA_DATAREGS+1); nbSec=_in(HDA_DATAREGS+2)<<8; nbSec+=_in(HDA_DATAREGS+3); printf("Formatage du disque\n"); for(cylinder=0;cylinder<nbCyl;cylinder++) for(secteur=0;secteur<nbSec;secteur++) format_sector(cylinder,secteur,1,0); return 0; }
/*! * \brief Function __init_hardware() overloads its default instance in EWL Runtime * library. It calls function init_hardware() which initializes CPU registers * . */ void __init_hardware(void) { /* Initialize device. */ init_hardware(); }
void init(struct sr_instance* sr) { unsigned int iseed = (unsigned int)time(NULL); srand(iseed+1); router_state* rs = (router_state*)malloc(sizeof(router_state));//router_state,一个结构体,在or_data_types.h定义 assert(rs); bzero(rs, sizeof(router_state)); rs->sr = sr; #ifdef _CPUMODE_ init_rawsockets(rs); #endif /** INITIALIZE LOCKS **/ rs->write_lock = (pthread_mutex_t*)malloc(sizeof(pthread_mutex_t)); if (pthread_mutex_init(rs->write_lock, NULL) != 0) { perror("Lock init error"); exit(1); } rs->arp_cache_lock = (pthread_rwlock_t*)malloc(sizeof(pthread_rwlock_t)); if (pthread_rwlock_init(rs->arp_cache_lock, NULL) != 0) { perror("Lock init error"); exit(1); } rs->arp_queue_lock = (pthread_rwlock_t*)malloc(sizeof(pthread_rwlock_t)); if (pthread_rwlock_init(rs->arp_queue_lock, NULL) != 0) { perror("Lock init error"); exit(1); } rs->if_list_lock = (pthread_rwlock_t*)malloc(sizeof(pthread_rwlock_t)); if (pthread_rwlock_init(rs->if_list_lock, NULL) != 0) { perror("Lock init error"); exit(1); } rs->rtable_lock = (pthread_rwlock_t*)malloc(sizeof(pthread_rwlock_t)); if (pthread_rwlock_init(rs->rtable_lock, NULL) != 0) { perror("Lock init error"); exit(1); } // --- CCDN lock rs->ctable_lock = (pthread_rwlock_t*)malloc(sizeof(pthread_rwlock_t)); if (pthread_rwlock_init(rs->ctable_lock, NULL) != 0) { perror("Lock init error"); exit(1); } rs->cli_commands_lock = (pthread_rwlock_t*)malloc(sizeof(pthread_rwlock_t)); if (pthread_rwlock_init(rs->cli_commands_lock, NULL) != 0) { perror("Lock init error"); exit(1); } rs->nat_table_mutex = (pthread_mutex_t*)malloc(sizeof(pthread_mutex_t)); if (pthread_mutex_init(rs->nat_table_mutex, NULL) != 0) { perror("Mutex init error"); exit(1); } rs->nat_table_cond = (pthread_cond_t*)malloc(sizeof(pthread_cond_t)); if (pthread_cond_init(rs->nat_table_cond, NULL) != 0) { perror("Nat Table cond init error"); exit(1); } rs->local_ip_filter_list_mutex = (pthread_mutex_t*)malloc(sizeof(pthread_mutex_t)); if (pthread_mutex_init(rs->local_ip_filter_list_mutex, NULL) != 0) { perror("Local IP Filter Mutex init error"); exit(1); } rs->log_dumper_mutex = (pthread_mutex_t*)malloc(sizeof(pthread_mutex_t)); if (pthread_mutex_init(rs->log_dumper_mutex, NULL) != 0) { perror("Log dumper mutex init error"); exit(1); } rs->sr = sr; rs->area_id = PWOSPF_AREA_ID; rs->pwospf_hello_interval = PWOSPF_NEIGHBOR_TIMEOUT; rs->pwospf_lsu_interval = PWOSPF_LSUINT; rs->pwospf_lsu_broadcast = 1; rs->arp_ttl = INITIAL_ARP_TIMEOUT; rs->nat_timeout = 120; /* clear stats */ int i, j; for (i = 0; i < 8; ++i) { for (j = 0; j < 4; ++j) { rs->stats_last[i][j] = 0; } for (j = 0; j < 2; ++j) { rs->stats_avg[i][j] = 0.0; } } rs->stats_last_time.tv_sec = 0; rs->stats_last_time.tv_usec = 0; #ifdef _CPUMODE_ rs->is_netfpga = 1; char* name = (char*)calloc(1, 32); strncpy(name, sr->interface, 32); rs->netfpga.device_name = name; rs->netfpga.fd = 0; rs->netfpga.net_iface = 0; if (check_iface(&(rs->netfpga))) { printf("Failure connecting to NETFPGA\n"); exit(1); } if (openDescriptor(&(rs->netfpga))) { printf("Failure connecting to NETFPGA\n"); exit(1); } /* initialize the hardware */ init_hardware(rs); #else rs->is_netfpga = 0; #endif if (rs->is_netfpga) { /* Add 224.0.0.5 as a local IP Filter */ struct in_addr ip; inet_pton(AF_INET, "224.0.0.5", &ip); add_local_ip_filter(rs, &ip, "pwospf"); } /* Initialize SPING data */ rs->sping_mutex = (pthread_mutex_t*)malloc(sizeof(pthread_mutex_t)); if (pthread_mutex_init(rs->sping_mutex, NULL) != 0) { perror("Sping mutex init error"); exit(1); } rs->sping_cond = (pthread_cond_t*)malloc(sizeof(pthread_cond_t)); if (pthread_cond_init(rs->sping_cond, NULL) != 0) { perror("Sping cond init error"); exit(1); } /* Initialize LSU data */ rs->pwospf_router_list_lock = (pthread_mutex_t*)malloc(sizeof(pthread_mutex_t)); if (pthread_mutex_init(rs->pwospf_router_list_lock, NULL) != 0) { perror("Routing list mutex init error"); exit(1); } rs->pwospf_lsu_bcast_mutex = (pthread_mutex_t*)malloc(sizeof(pthread_mutex_t)); if (pthread_mutex_init(rs->pwospf_lsu_bcast_mutex, NULL) != 0) { perror("LSU bcast mutex init error"); exit(1); } rs->pwospf_lsu_bcast_cond = (pthread_cond_t*)malloc(sizeof(pthread_cond_t)); if (pthread_cond_init(rs->pwospf_lsu_bcast_cond, NULL) != 0) { perror("LSU bcast cond init error"); exit(1); } rs->pwospf_lsu_queue_lock = (pthread_mutex_t*)malloc(sizeof(pthread_mutex_t)); if (pthread_mutex_init(rs->pwospf_lsu_queue_lock, NULL) != 0) { perror("Lsu queue mutex init error"); exit(1); } /* Initialize PWOSPF Dijkstra Thread Mutex/Cond Var */ rs->dijkstra_mutex = (pthread_mutex_t*)malloc(sizeof(pthread_mutex_t)); if (pthread_mutex_init(rs->dijkstra_mutex, NULL) != 0) { perror("Dijkstra mutex init error"); exit(1); } rs->dijkstra_cond = (pthread_cond_t*)malloc(sizeof(pthread_cond_t)); if (pthread_cond_init(rs->dijkstra_cond, NULL) != 0) { perror("Dijkstra cond init error"); exit(1); } /* Initialize WWW Mutex/Cond Var */ rs->www_mutex = (pthread_mutex_t*)malloc(sizeof(pthread_mutex_t)); if (pthread_mutex_init(rs->www_mutex, NULL) != 0) { perror("WWW mutex init error"); exit(1); } rs->www_cond = (pthread_cond_t*)malloc(sizeof(pthread_cond_t)); if (pthread_cond_init(rs->www_cond, NULL) != 0) { perror("WWW cond init error"); exit(1); } /* Initialize Stats Mutex */ rs->stats_mutex = (pthread_mutex_t*)malloc(sizeof(pthread_mutex_t)); if (pthread_mutex_init(rs->stats_mutex, NULL) != 0) { perror("Stats mutex init error"); exit(1); } // --- CCDN , sr里面有一个指针是sr->interface_subsystem = rs,而main函数的最前面,rs->sr=sr sr_set_subsystem(sr, (void*)rs); // --- CCDN , pthread_create用于创建一个线程,第一个参数返回线程id,第二个设置线程属性(NULL表默认),第三个指向线程调用的函数,第四个传递参数 /** SPAWN THE ARP QUEUE THREAD **/ rs->arp_thread = (pthread_t*)malloc(sizeof(pthread_t)); if(pthread_create(rs->arp_thread, NULL, arp_thread, (void *)sr) != 0) { perror("Thread create error"); } /** SPAWN THE PWOSPF HELLO BROADCAST THREAD **/ rs->pwospf_hello_thread = (pthread_t*)malloc(sizeof(pthread_t)); if(pthread_create(rs->pwospf_hello_thread, NULL, pwospf_hello_thread, (void *)sr) != 0) { perror("Thread create error"); } /** SPAWN THE PWOSPF LSU BROADCAST THREAD **/ rs->pwospf_lsu_thread = (pthread_t*)malloc(sizeof(pthread_t)); if(pthread_create(rs->pwospf_lsu_thread, NULL, pwospf_lsu_thread, (void *)sr) != 0) { perror("Thread create error"); } /** SPAWN THE PWOSPF LSU BCAST TIMEOUT THREAD **/ rs->pwospf_lsu_timeout_thread = (pthread_t*)malloc(sizeof(pthread_t)); if(pthread_create(rs->pwospf_lsu_timeout_thread, NULL, pwospf_lsu_timeout_thread, (void*)sr) != 0) { perror("Thread create error"); } /** SPAWN THE DIJKSTRA THREAD **/ rs->pwospf_dijkstra_thread = (pthread_t*)malloc(sizeof(pthread_t)); if(pthread_create(rs->pwospf_dijkstra_thread, NULL, dijkstra_thread, (void*)get_router_state(sr)) != 0) { perror("Thread create error"); } /** SPAWN THE PWOSPF LSU BCAST THREAD **/ rs->pwospf_lsu_bcast_thread = (pthread_t*)malloc(sizeof(pthread_t)); if(pthread_create(rs->pwospf_lsu_bcast_thread, NULL, pwospf_lsu_bcast_thread, (void*)sr) != 0) { perror("Thread create error"); } /** Spawn the NAT Maintenance Thread **/ /* rs->nat_maintenance_thread = (pthread_t*)malloc(sizeof(pthread_t)); if(pthread_create(rs->nat_maintenance_thread, NULL, nat_maintenance_thread, (void*)rs) != 0) { perror("Thread create error"); } */ /* if we are on the NETFPGA spawn the stats thread */ if (rs->is_netfpga) { rs->stats_thread = (pthread_t*)malloc(sizeof(pthread_t)); if(pthread_create(rs->stats_thread, NULL, netfpga_stats, (void*)rs) != 0) { perror("Thread create error"); } } }
void main() { disable_interrupts(GLOBAL); setup_spi(SPI_MASTER | SPI_MODE_0_0 | SPI_CLK_DIV_16 ); setup_spi2(SPI_MASTER | SPI_MODE_0_0 | SPI_CLK_DIV_16 ); setup_adc_ports(sAN0|sAN1|sAN2|sAN3|sAN4|VSS_4V096); setup_adc(ADC_CLOCK_INTERNAL|ADC_TAD_MUL_0); // TIMER 0 is being used to service the WTD setup_timer_0(T0_INTERNAL|T0_DIV_256); /* sets the internal clock as source and prescale 256. At 10 Mhz timer0 will increment every 0.4us (Fosc*4) in this setup and overflows every 6.71 seconds. Timer0 defaults to 16-bit if RTCC_8_BIT is not used. Fosc = 10 MHz, Fosc/4 = 2.5 Mhz, div 256 = 0.0001024 s, 65536 increments = 6.71 sec Fosc = 64 MHz, Fosc/4 = 16 Mhz, div 256 = 0.000016 s, 65536 increments = 1.05 sec .. pre-load with 3036 to get exact 1.0000 sec value */ // TIMER 1 is used to extinguish the LED setup_timer_1(T1_INTERNAL|T1_DIV_BY_8); /* sets the internal clock as source and prescale 4. At 10Mhz timer0 will increment every 0.4us in this setup and overflows every 104.8 ms. Timer1 is 16-bit. Fosc = 10 Mhz ... 2.5 MHz / div 4 = 0.00000160 s * 65536 = 0.104858 sec Fosc = 64 Mhz ... 16 MHz / div 4 = 0.00000025 s * 65536 = 0.016384 sec Fosc = 64 Mhz ... 16 MHz / div 8 = 0.00000200 s * 65536 = 0.032768 sec */ setup_stepper_pwm(); // Uses TIMER 2 // TIMER 3 is used for stepper motor intervals setup_timer_3(T3_INTERNAL | T3_DIV_BY_1); // 16 bit timer // TIMER 4 is use for serial time-outs. 8-bit timer. setup_timer_4(T4_DIV_BY_4, 127, 1); setup_comparator(NC_NC_NC_NC); setup_oscillator(OSC_16MHZ | OSC_PLL_ON); // Fosc = 64 MHz ext_int_edge(0, H_TO_L); // Set up PIC18 EXT0 enable_interrupts(INT_EXT); start_heartbeat(); enable_interrupts(GLOBAL); init_hardware(); motor_sleep_rdy(); sleep_mode = FALSE; busy_set(); init_nv_vars(); get_step_vars(); init_aws(); blink(); //Add for TCP/IP interface //delay_ms(15000); signon(); RTC_read(); RTC_last_power(); RTC_reset_HT(); RTC_read(); RTC_read_flags(); if(nv_sd_status>0) fprintf(COM_A,"@SD=%Lu\r\n", nv_sd_status); init_rtc(); // This is the FAT RTC sd_status = init_sdcard(); if(sd_status>0) msg_card_fail(); reset_event(); if(m_error[0] > 0 || m_error[1] > 0) msg_mer(); if (m_comp[0]==FALSE) { e_port[0]=0; write16(ADDR_E1_PORT,0); fprintf(COM_A, "@MC1,%Lu,%Ld\r\n", m_comp[0],e_port[0]); } if (m_comp[1]==FALSE) { m_lin_pos[1]=-1; write16(ADDR_M2_LIN_POS, -1); fprintf(COM_A, "@MC2,%Lu,%Ld\r\n", m_comp[1],m_lin_pos[1]); } if (nv_cmd_mode == FALSE){ for(dt=0; dt<100; ++dt){ blip(); if (nv_cmd_mode == TRUE) { busy_clear(); fputs("@OK!", COM_A); command_prompt(); dt = 100; } } } else command_prompt(); user_quit = auto_sample_ready(); reset_cpu(); }
int main(int argc, char **argv) { parseargs(argc, argv); mbox.handle = mbox_open(); if (mbox.handle < 0) fatal("Failed to open mailbox\n"); unsigned mbox_board_rev = get_board_revision(mbox.handle); printf("MBox Board Revision: %#x\n", mbox_board_rev); get_model(mbox_board_rev); unsigned mbox_dma_channels = get_dma_channels(mbox.handle); printf("DMA Channels Info: %#x, using DMA Channel: %d\n", mbox_dma_channels, DMA_CHAN_NUM); printf("Using hardware: %5s\n", delay_hw == DELAY_VIA_PWM ? "PWM" : "PCM"); printf("Number of channels: %5d\n", (int)num_channels); printf("PWM frequency: %5d Hz\n", 1000000/CYCLE_TIME_US); printf("PWM steps: %5d\n", NUM_SAMPLES); printf("Maximum period (100 %%): %5dus\n", CYCLE_TIME_US); printf("Minimum period (%1.3f%%): %5dus\n", 100.0*SAMPLE_US / CYCLE_TIME_US, SAMPLE_US); printf("DMA Base: %#010x\n", DMA_BASE); setup_sighandlers(); /* map the registers for all DMA Channels */ dma_virt_base = map_peripheral(DMA_BASE, (DMA_CHAN_SIZE * (DMA_CHAN_MAX + 1))); /* set dma_reg to point to the DMA Channel we are using */ dma_reg = dma_virt_base + DMA_CHAN_NUM * (DMA_CHAN_SIZE / sizeof(dma_reg)); pwm_reg = map_peripheral(PWM_BASE, PWM_LEN); pcm_reg = map_peripheral(PCM_BASE, PCM_LEN); clk_reg = map_peripheral(CLK_BASE, CLK_LEN); gpio_reg = map_peripheral(GPIO_BASE, GPIO_LEN); /* Use the mailbox interface to the VC to ask for physical memory */ mbox.mem_ref = mem_alloc(mbox.handle, NUM_PAGES * PAGE_SIZE, PAGE_SIZE, mem_flag); /* TODO: How do we know that succeeded? */ dprintf("mem_ref %u\n", mbox.mem_ref); mbox.bus_addr = mem_lock(mbox.handle, mbox.mem_ref); dprintf("bus_addr = %#x\n", mbox.bus_addr); mbox.virt_addr = mapmem(BUS_TO_PHYS(mbox.bus_addr), NUM_PAGES * PAGE_SIZE); dprintf("virt_addr %p\n", mbox.virt_addr); if ((unsigned long)mbox.virt_addr & (PAGE_SIZE-1)) fatal("pi-blaster: Virtual address is not page aligned\n"); /* we are done with the mbox */ mbox_close(mbox.handle); mbox.handle = -1; //fatal("TempFatal\n"); init_ctrl_data(); init_hardware(); init_channel_pwm(); // Init pin2gpio array with 0/false values to avoid locking all of them as PWM. init_pin2gpio(); // Only calls update_pwm after ctrl_data calculates the pin mask to unlock all pins on start. init_pwm(); unlink(DEVFILE); if (mkfifo(DEVFILE, 0666) < 0) fatal("pi-blaster: Failed to create %s: %m\n", DEVFILE); if (chmod(DEVFILE, 0666) < 0) fatal("pi-blaster: Failed to set permissions on %s: %m\n", DEVFILE); printf("Initialised, "); if (daemonize) { if (daemon(0,1) < 0) fatal("pi-blaster: Failed to daemonize process: %m\n"); else printf("Daemonized, "); } printf("Reading %s.\n", DEVFILE); go_go_go(); return 0; }
int main(void) { uint8_t button; mode_t mode = MODE_OFF; mode_t next_mode = MODE_OFF; uint8_t up_time = 0; uint8_t down_time = 0; uint8_t time = 0; init_hardware(); leds[GREEN_LED].state = LED_OFF; leds[GREEN_LED].on_time = 31; leds[GREEN_LED].off_time = 31; leds[RED_LED].state = LED_HIZ; while (1) { button = poll_button(); if (button & 2) { if (down_time < 255) { down_time++; } up_time = 0; } else { if (up_time < 255) { up_time++; } down_time = 0; } if (time < 255) { time++; } // Button pressed if (button == 1) { if (mode != MODE_OFF && up_time >= 62) { next_mode = MODE_OFF; } else if (mode < MODE_CYCLE_END) { next_mode = mode + 1; if (next_mode == MODE_CYCLE_END) { next_mode = MODE_OFF; } } else { next_mode = MODE_OFF; } } // Button held if (down_time >= 37) { switch (mode) { case MODE_CYCLE_LEVEL1: next_mode = MODE_HOLD_BLINKY; break; case MODE_CYCLE_LEVEL2: next_mode = MODE_PERSIST_BLINKY; break; default: break; } } // Button released if (button == 2 && mode > MODE_PERSIST_END) { next_mode = MODE_OFF; } if (poll_temp() >= OVERTEMP) { if (mode > MODE_CYCLE_LEVEL2) { next_mode = MODE_CYCLE_LEVEL2; } else if (next_mode > MODE_CYCLE_LEVEL2) { next_mode = MODE_OFF; } } if (next_mode != mode) { mode = next_mode; set_power(mode); switch (mode) { case MODE_OFF: set_light(0); break; case MODE_CYCLE_LEVEL1: set_light(50); break; case MODE_CYCLE_LEVEL2: set_light(250); break; case MODE_CYCLE_LEVEL3: set_light(1000); break; case MODE_CYCLE_LEVEL4: set_light(1500); break; case MODE_CYCLE_LEVEL5: set_light(2000); break; case MODE_PERSIST_BLINKY: case MODE_HOLD_BLINKY: time = 0; set_light(2000); break; default: mode = MODE_OFF; break; } } switch (mode) { case MODE_PERSIST_BLINKY: case MODE_HOLD_BLINKY: if (time >= 24) { set_light(2000); time = 0; } else if (time >= 8) { set_light(0); } break; default: break; } switch (poll_charger()) { case CHARGE_SHUTDOWN: leds[GREEN_LED].state = LED_OFF; break; case CHARGE_CHARGING: leds[GREEN_LED].state |= LED_FLASH; break; case CHARGE_FINISHED: leds[GREEN_LED].state = LED_ON; break; } update_leds(); sleep(); } return 0; }