int main() { int i; struct picture_t pic; struct encoded_pic_t encoded_pic; errno = 0; if(!camera_init(&pic)) goto error_cam; if(!encoder_init(&pic)){ fprintf(stderr,"failed to initialize encoder\n"); goto error_encoder; } if(!preview_init(&pic)) goto error_preview; if(!output_init(&pic)) goto error_output; if(!encoder_encode_headers(&encoded_pic)) goto error_output; if(!output_write_headers(&encoded_pic)) goto error_output; if(!camera_on()) goto error_cam_on; if(signal(SIGINT, stop_recording) == SIG_ERR){ fprintf(stderr,"signal() failed\n"); goto error_signal; } printf("Press ctrl-c to stop recording...\n"); recording = 1; for(i=0; recording; i++){ if(!camera_get_frame(&pic)) break; gen_osd_info(); osd_print(&pic, osd_string); if((i&7)==0) // i%8==0 preview_display(&pic); if(!encoder_encode_frame(&pic, &encoded_pic)) break; applog_flush(); if(!output_write_frame(&encoded_pic)) break; } printf("\nrecorded %d frames\n", i); error_signal: camera_off(); error_cam_on: output_close(); error_output: preview_close(); error_preview: encoder_close(); error_encoder: camera_close(); error_cam: return 0; }
/***************************************************************************** Prototype : encoder_create Description : create encoder module Input : EncoderAttrs *attrs Output : None Return Value : Calls : Called By : History : 1.Date : 2012/3/17 Author : Sun Modification : Created function *****************************************************************************/ EncoderHandle encoder_create(EncoderAttrs *attrs, EncoderParams *encParams, UploadParams *uploadParams) { EncoderHandle hEnc; if(!attrs || !encParams || !uploadParams) return NULL; hEnc = calloc(1, sizeof(struct EncoderObj)); if(!hEnc) { ERR("alloc mem failed"); return NULL; } Int32 err; /* init encoder */ err = encoder_init(hEnc, attrs, encParams); /* create upload module */ err |= upload_update(hEnc, uploadParams); if(err) { encoder_delete(hEnc, NULL); return NULL; } return hEnc; }
void dc_init(void) { #ifdef ENCODER pid_init(&pid, PID_K_P_DEFAULT, PID_K_I_DEFAULT, PID_K_D_DEFAULT, PID_SAMPLE_TIME_DEFAULT, PID_MAX_OUT_DEFAULT, PID_MIN_OUT_DEFAULT); encoder_init(); #endif Pin dc_pins[] = {PINS_DC}; PIO_Configure(dc_pins, PIO_LISTSIZE(dc_pins)); // Configure and enable power measurements Pin dc_power_management_pins[] = {VOLTAGE_STACK_PIN, VOLTAGE_EXTERN_PIN, VOLTAGE_STACK_SWITCH_PIN, CURRENT_CONSUMPTION_PIN}; PIO_Configure(dc_power_management_pins, PIO_LISTSIZE(dc_power_management_pins)); // Initialize PWM PMC->PMC_PCER0 = 1 << ID_PWM; dc_update_pwm_frequency(); adc_channel_enable(VOLTAGE_EXTERN_CHANNEL); adc_channel_enable(VOLTAGE_STACK_CHANNEL); adc_channel_enable(CURRENT_CONSUMPTION_CHANNEL); }
void init() { ResetReason = MCUSR; cli(); WDT_off(); // Turn off until initialization is done and we can pet the dog. init_leds (); init_buttons(); init_limit_switches(); init_motor(); float mBaseFrequencyHerz = 500.0; // 4khz pwm_init( mBaseFrequencyHerz, TRUE ); init_serial(); init_configuration(); // read_configuration_and_set(); // init_adc(); // start_sampling(); encoder_init(); // pot_init (); WDT_Prescaler_Change(); //delay(100000); // ~ 2 sec //read_cal(); // Read everything including motor stops. sei(); //OS_InitTask(); }
void main(void) { char buffer[SCI_BUFSIZ+1] = {0}; // Initialize all nessesary modules timer_init(); SCIinit(); encoder_init(); motor_init(); msleep(16); LCDinit(); //start_heartbeat(); // Not used, TCNT overflow interrupts causing issues DDRP |= PTP_PTP0_MASK; // Set DDR for laser GPIO // Motors off initially motor_set_speed(MOTOR1C, 0); motor_set_speed(MOTOR2C, 0); EnableInterrupts; LCDclear(); LCDputs("Ready."); SCIputs("HCS12 ready to go!"); for(EVER) { SCIdequeue(buffer); cmdparser(buffer); memset(buffer, 0, SCI_BUFSIZ+1); // Clear out the command buffer after each command parsed //LCDclear(); LCDprintf("\r%7d %7d\n%7d %7d", drive_value1, drive_value2, speed_error1, speed_error2); } }
static void * recorder_output_init(G_GNUC_UNUSED const struct audio_format *audio_format, const struct config_param *param, GError **error_r) { struct recorder_output *recorder = g_new(struct recorder_output, 1); const char *encoder_name; const struct encoder_plugin *encoder_plugin; /* read configuration */ encoder_name = config_get_block_string(param, "encoder", "vorbis"); encoder_plugin = encoder_plugin_get(encoder_name); if (encoder_plugin == NULL) { g_set_error(error_r, recorder_output_quark(), 0, "No such encoder: %s", encoder_name); return NULL; } recorder->path = config_get_block_string(param, "path", NULL); if (recorder->path == NULL) { g_set_error(error_r, recorder_output_quark(), 0, "'path' not configured"); return NULL; } /* initialize encoder */ recorder->encoder = encoder_init(encoder_plugin, param, error_r); if (recorder->encoder == NULL) return NULL; return recorder; }
int main(void) { halInit(); chSysInit(); chThdSleepMilliseconds(1000); hw_init_gpio(); LED_RED_OFF(); LED_GREEN_OFF(); conf_general_init(); ledpwm_init(); mc_configuration mcconf; conf_general_read_mc_configuration(&mcconf); mc_interface_init(&mcconf); commands_init(); comm_usb_init(); app_configuration appconf; conf_general_read_app_configuration(&appconf); app_init(&appconf); timeout_init(); timeout_configure(appconf.timeout_msec, appconf.timeout_brake_current); #if CAN_ENABLE comm_can_init(); #endif #if WS2811_ENABLE ws2811_init(); led_external_init(); #endif #if ENCODER_ENABLE encoder_init(); #endif #if SERVO_OUT_ENABLE #if SERVO_OUT_SIMPLE servo_simple_init(); #else servo_init(); #endif #endif // Threads chThdCreateStatic(periodic_thread_wa, sizeof(periodic_thread_wa), NORMALPRIO, periodic_thread, NULL); chThdCreateStatic(sample_send_thread_wa, sizeof(sample_send_thread_wa), NORMALPRIO - 1, sample_send_thread, NULL); chThdCreateStatic(timer_thread_wa, sizeof(timer_thread_wa), NORMALPRIO, timer_thread, NULL); for(;;) { chThdSleepMilliseconds(5000); } }
int main (void) { board_init(); // Insert application code here, after the board has been initialized. lcd_init(); lcd_cls(); lcd_locate(0,0); lcd_set_font(Lcd_Font_5x7); lcd_write_s(c_GreetingMsg); /* Initialize the PWM driver and set proper frequency */ pwm_init(); pwm_set_duty(0); pwm_set_frequency(Pwm_31250Hz); /* Initialize the encoder and register a callback function */ encoder_init(); encoder_register_event(OnEncoderEvent); while(1) { encoder_cyclic(); switch(CurrentState) { case State_Info: // info_cyclic(&CurrentEventMask); CurrentState = State_MainMenu; break; case State_MainMenu: CurrentState = main_menu_cyclic(MainMessagePump); break; case State_Reflow: // refow_cyclic(); CurrentState = State_MainMenu; break; case State_Learn: // learn_cyclic(); CurrentState = State_MainMenu; break; case State_Parameterize: // parameterize_cyclic(); CurrentState = State_MainMenu; break; default: CurrentState = State_MainMenu; break; } } }
void reinit(){ int i=0; hold_on=1; while(hold_on_ready==0&&i<1000){i++;} if(hold_on_ready==1&&hold_on==1){ encoder_close(); encoder_init(&pic,fps,brightness,bitrate); encoder_encode_headers(&header_pic); printf("reinit\n"); hold_on=0; } }
int main(int argc, char *argv[]) { board_t *board = NULL; int ret = 0; encoder_module_t enc; if (argc == 1) { print_short_usage(); return 0; } if (process_cmd_line(argc, argv) == -1) { return -1; } board_access.verbose = verbose_flag; if (anyio_init(&board_access) != 0) { // init library return -1; } ret = anyio_find_dev(&board_access); // find board if (ret < 0) { return -1; } board = anyio_get_dev(&board_access, 1); // if found the get board handle if (board == NULL) { printf("No %s board found\n", board_access.device_name); return -1; } board->open(board); // open board for communication board->print_info(board); // print what card it is hm2_read_idrom(&(board->llio.hm2)); // read hostmot2 idrom ret = encoder_init(&enc, board, instance, delay); // init encoder 'instance' module on 'board' if (ret < 0) { goto fail0; } while (1) { encoder_read(&enc); // read encoder printf("tsc = %u, raw_counts = %u, velocity = %.2f\n", enc.global_time_stamp, enc.raw_counts, enc.velocity); usleep(delay*1000); // wait delay ms } encoder_cleanup(&enc); // cleanup enocder module fail0: board->close(board); // close board communication anyio_cleanup(&board_access); // close library return 0; }
void wheel_init (void) { pid_enable = TRUE; /* default enable PID */ encoder_init(); /* initialize tacho encoders */ motor_init(); /* initialize PWM */ motor_set_param (WHEEL_LEFT, pid_interval*10, 1, 0, 0); /* dT=100ms, Kp=1 Ki=0, Kd=0 */ pid_int_init (&pid_l); /* initialize PID controller (left) */ motor_set_param (WHEEL_RIGHT, pid_interval*10, 1, 0, 0); /* dT=100ms, Kp=1 Ki=0, Kd=0 */ pid_int_init (&pid_r); /* initialize PID controller (right) */ }
void main(int argc, char* argv[]){ unsigned char buf[1024]; printf("\t\t\t---------------------------------\n"); printf("\t\t\t* NELVT ENCODER *\n"); printf("\t\t\t---------------------------------\n"); encoder_init (); //encoder_send_config_param(0); encoder_send_config_file("d:\encoder_config.txt"); encoder_start (); encoder_read_es (buf); encoder_deinit (); }
static void * httpd_output_init(G_GNUC_UNUSED const struct audio_format *audio_format, const struct config_param *param, GError **error) { struct httpd_output *httpd = g_new(struct httpd_output, 1); const char *encoder_name; const struct encoder_plugin *encoder_plugin; guint port; struct sockaddr_in *sin; /* read configuration */ port = config_get_block_unsigned(param, "port", 8000); encoder_name = config_get_block_string(param, "encoder", "vorbis"); encoder_plugin = encoder_plugin_get(encoder_name); if (encoder_plugin == NULL) { g_set_error(error, httpd_output_quark(), 0, "No such encoder: %s", encoder_name); return NULL; } if (strcmp(encoder_name, "vorbis") == 0) httpd->content_type = "application/x-ogg"; else if (strcmp(encoder_name, "lame") == 0) httpd->content_type = "audio/mpeg"; else httpd->content_type = "application/octet-stream"; /* initialize listen address */ sin = (struct sockaddr_in *)&httpd->address; memset(sin, 0, sizeof(sin)); sin->sin_port = htons(port); sin->sin_family = AF_INET; sin->sin_addr.s_addr = INADDR_ANY; httpd->address_size = sizeof(*sin); /* initialize encoder */ httpd->encoder = encoder_init(encoder_plugin, param, error); if (httpd->encoder == NULL) return NULL; httpd->mutex = g_mutex_new(); return httpd; }
void motor_init(void) { // Set INA and INB as normal IO pin outputs P2DIR |= LINA|LINB|RINA|RINB; P2SEL &= ~(LINA|LINB|RINA|RINB); P2SEL2 &= ~(LINA|LINB|RINA|RINB); // initialize variables m_out.state=MSTATE_READY; m_in.msg=0; // do what is needed to enter the READY state motor_ready(); encoder_init(); // start with READY state so reporting interval is longer report_interval=READY_REPORT_INTERVAL; }
http_server_t * jukebox_init(int port) { http_server_t *server; encoder_init("mp3", "encoded", 4); song_init(); channel_init(); event_init(); server = http_server_new(port); http_node_new(server, "/stream", on_stream, NULL); http_map_directory(server, "/", "html"); http_server_set_auth_cb(server, auth_session); return server; }
void init() { TWI_Slave_Initialise(0x11 << 1); // wait for stab.. _delay_ms(1000); encoder_init(&enc); pwm_init(); // enable all external interrupts GICR |= (1 << INT0) | (1 << INT1); // set interrupt sense MCUCR |= (1 << ISC10) | (0 <<ISC11) | // any change generate interupt on 0 (1 << ISC00) | (0 <<ISC01); // any change generate interupt on 1 // set interruppt enable to 1 sei(); }
void matrix_init_quantum() { #ifdef BOOTMAGIC_LITE bootmagic_lite(); #endif if (!eeconfig_is_enabled()) { eeconfig_init(); } #ifdef BACKLIGHT_ENABLE backlight_init_ports(); #endif #ifdef AUDIO_ENABLE audio_init(); #endif #ifdef RGB_MATRIX_ENABLE rgb_matrix_init(); #endif #ifdef ENCODER_ENABLE encoder_init(); #endif matrix_init_kb(); }
void encoder_service(void) { static int last_event; static int last_fps_event; static int frame_cnt; static int can_start; if(encoder_enabled) { if(elapsed(&last_event, identifier_frequency_read()/encoder_target_fps)) can_start = 1; if(can_start & encoder_done()) { encoder_init(encoder_quality); encoder_start(processor_h_active, processor_v_active); encoder_reader_dma_length_write(processor_h_active*processor_v_active*2); encoder_reader_dma_shoot_write(1); frame_cnt++; } if(elapsed(&last_fps_event, identifier_frequency_read())) { encoder_fps = frame_cnt; frame_cnt = 0; } } }
int main(void) { clock_time_t * myClock=(clock_time_t *) &time_val; encoder_init(); UART2_init(9600); clock_init(); lcd_init(); serial_printf(UART2_serial,"\nSystem ready\n"); serial_printf(LCD_serial,"\fPOS %d",encoder_getPosition()); while(1){ if(encoder_hasChanged()){ lcd_goto(4,0); serial_printf(LCD_serial,"%d ",encoder_getPosition()); } timer_count=clock_getSeconds(); if(last_timer_count!=timer_count){ time_val=clock_getTime(); lcd_goto(0,1); serial_printf(LCD_serial,"%7s:%2d:%2d:%2d",dias[myClock->days],myClock->hours,myClock->minutes,myClock->seconds); last_timer_count=timer_count; } } }
extern int32_t eo_absCalibratedEncoder_Acquire(EOabsCalibratedEncoder* o, int32_t position, uint8_t error_mask) { static const int16_t MAX_ENC_CHANGE = 7*ENCODER_QUANTIZATION; if (!o->sign) return 0; if (!error_mask) { position -= o->offset; if (position < 0) { position += TICKS_PER_REVOLUTION; } else if (position >= TICKS_PER_REVOLUTION) { position -= TICKS_PER_REVOLUTION; } o->invalid_fault_cnt = 0; o->timeout_fault_cnt = 0; } else { if (error_mask & 0x01) { if (o->invalid_fault_cnt > 50) { SET_BITS(o->state_mask, SM_INVALID_FAULT); } else { ++o->invalid_fault_cnt; } } else { o->invalid_fault_cnt = 0; } if (error_mask & 0x02) { if (o->timeout_fault_cnt > 50) { SET_BITS(o->state_mask, SM_TIMEOUT_FAULT); } else { ++o->timeout_fault_cnt; } } else { o->timeout_fault_cnt = 0; } } if (o->state_mask & SM_NOT_INITIALIZED) { encoder_init(o, position, error_mask); #ifndef USE_2FOC_FAST_ENCODER o->velocity = 0; #endif return o->sign*o->distance; } if (!error_mask) { int32_t check = normalize_angle(position - o->position_last); o->position_last = position; //make it less sensible! (expecially because incremental encoders has very long steps after the transformation in ICUB degrees) if (-MAX_ENC_CHANGE <= check && check <= MAX_ENC_CHANGE) { int32_t delta = normalize_angle(position - o->position_sure); //if (delta || o->delta) if (delta) { o->position_sure = position; //int32_t inc = (o->delta + delta) >> 1; o->delta = delta; o->distance += delta; //if (inc) //{ // o->distance += inc; //} #ifndef USE_2FOC_FAST_ENCODER //o->velocity = (7*o->velocity + o->sign*EMS_FREQUENCY_INT32*inc) >> 3; o->velocity = (7*o->velocity + o->sign*EMS_FREQUENCY_INT32*delta) >> 3; #endif } #ifndef USE_2FOC_FAST_ENCODER else {
int main(){ int FileSize; FileSize =0; int WriteSize; long tstmp; value_readfile_init(); serial_init(); wiringPiSetup(); softPwmCreate(0,0,20000); softPwmCreate(1,0,20000); softPwmCreate(2,0,20000); softPwmCreate(3,0,20000); softPwmCreate(4,0,20000); softPwmCreate(5,0,20000); //i2c_init(); gettimeofday(×tart,NULL); get_filename(replayFileName); if(!encoder_init(&pic,fps,brightness,bitrate)) goto error_encoder; if(!output_init(&pic,mkv_filename)) goto error_output; encoded_pic.buffer=malloc(1024*100); encoded_pic.length=0; if(!encoder_encode_headers(&encoded_pic)) goto error_output; memcpy(&header_pic,&encoded_pic,sizeof(encoded_pic)); header_pic.buffer=malloc(1024*100);//(encoded_pic.length); printf("header_pic len:%d\n",encoded_pic.length); memcpy(header_pic.buffer,encoded_pic.buffer,encoded_pic.length); if(!output_write_headers(&encoded_pic)) goto error_output; if(signal(SIGINT, stop_running) == SIG_ERR){ printf("signal() failed\n"); goto error_signal; } if(pthread_create(&thread[0], NULL, client_thread, NULL) != 0) printf("client_thread error!\n"); else printf("client_thread ok\n"); if(pthread_create(&thread[1],NULL,schedule_do,NULL) != 0) printf("schedule_do error!\n"); else printf("schedule_do ok\n"); if(pthread_create(&thread[2],NULL,aircraft_thread,NULL) != 0) printf("aircraft_thread error!\n"); else printf("aircraft_thread ok\n"); while (!camera_Quit) { gettimeofday(&timeend,NULL); tstmp=(timeend.tv_sec-timestart.tv_sec)*1000000ll+timeend.tv_usec-timestart.tv_usec; if(tstmp<(1000000/fps)){ usleep(tstmp); }else{ timestart.tv_sec=timeend.tv_sec; timestart.tv_usec=timeend.tv_usec; /* if(copycoded.length>0){ if ((FileSize>MAX_SIZE) && (sendcoded.frame_type ==FRAME_TYPE_I)) { output_close(); printf("file full\n"); get_filename(replayFileName); printf("file:%s\n",mkv_filename); if(!output_init(&pic,mkv_filename)){ printf("output_init error\r\n"); break; } if(!output_write_headers(&header_pic)){ printf("output_write_headers error\r\n"); break; } FileSize=0; //ResetTime(&pic,&encoded_pic); if(!output_write_frame(©coded)){ printf("output_write_frame1 error\r\n"); break; } //encoder_release(&encoded_pic); } else { if(!output_write_frame(©coded)){ printf("output_write_frame2 error\r\n"); break; } //encoder_release(&encoded_pic); } copycoded.length=0; } */ } } error_signal: printf("exit the cam_thread\n"); encode_Quit =1; //=========add========== free(sendcoded.buffer); //=========add========== schedule_do_Quit = 1; g_s32Quit = 1; control_thread_go=1; printf("The device quit!\n"); pthread_cancel(thread[0]); pthread_cancel(thread[1]); pthread_cancel(thread[2]); if(thread[0]) pthread_join(thread[0],NULL); if(thread[1]) pthread_join(thread[1],NULL); if(thread[2]) pthread_join(thread[2],NULL); error_output: error_cam_on: output_close(); error_encoder: error_cam: serial_close(); //i2c_close(); return 0; }
// Initialise board void board_init (void) { #ifndef SIMULATE io_init(); // Init GPIOs uart_init(BAUD_RATE); stderr = &uartio; printf(str_boot_uart,BAUD_RATE); printf(str_boot_start); #else printf("Skipping UART initialization...\n"); #endif #ifndef SIMULATE digital_init(); #endif encoder_init(); #ifndef SIMULATE spi_init(); motor_init(); servo_init(); #ifdef LCD_DEBUG lcd_init(); //consider wrapping this in an #ifdef LCD_DEBUG tag? stdout = &lcdout; #else stdout = &uartio; stdin = &uartio; #endif adc_init(); isr_init(); memory_init(); #endif // load config, or fail if invalid if (!board_load_config()) board_fail("Bad Config"); printf(str_boot_conf); printf(str_boot_board, board_config.version>>8, board_config.version&0xFF); printf(str_boot_id, board_config.id); // print boot text to screen printf(str_boot_message, board_config.version>>8, board_config.version&0xFF); // check battery, fail if <7.5V printf(str_boot_batt,read_battery()); #ifdef CHECK_BATTERY if (!(read_battery()>=7200)) { // NOTE: in the current 2-battery version of the HappyBoard, the // battery voltage is the motor battery (P+). Holding GO overrides // the check so you can run the HappyBoard without a motor battery. if (go_press()) printf("WARNING: LOW BATTERY\n"); else board_fail("Low battery"); } else { printf("Battery OK\n"); } #endif #ifndef SIMULATE // initialise FPGA if (!fpga_init(FPGA_CONFIG_ADDRESS, board_config.fpga_len)) board_fail("FPGA failure"); printf(str_boot_fpga, fpga_get_version_major(), fpga_get_version_minor()); #else printf("Skipping FPGA initialization...\n"); #endif // all ok #ifndef SIMULATE #ifdef LCD_DEBUG lcd_set_pos(31); lcd_print_char('\1', NULL); #else printf("Board init complete.\n"); #endif #else printf("Board init complete.\n"); #endif #ifndef SIMULATE LED_COMM(0); #endif }
int main(int argc, char **argv) { uint8_t codelen[128]; struct Histogram32 h32; struct Codebook cb; struct Encoder enc; struct Tree tree; FILE *fout; int i,L; if(argc == 1) L = 16; //else if(argv == 2) L = atoi(argv[1]); else { fprintf(stderr,"Usage: %s\n", argv[0]); fprintf(stderr,"\treads input data from stdin, compresses it using\n"); fprintf(stderr,"\tlength-restricted canonical huffman codes and writes\n"); fprintf(stderr,"\tthe result to 'enc.out'.\n"); exit(1); } read_text(stdin); histogram32_init(&h32); histogram32_add(&h32, buffer, buffer_fill); package_merge(&h32, L, codelen); //printf("final codelengths:\n"); //codelen_dump(codelen, stdout); fprintf(stderr,"weight of huffman tree = %f\n", weight_of_tree(codelen)); fprintf(stderr,"compression factor = %.11f\n",compr_factor(buffer,buffer_fill,codelen)); ctree_create(&tree, codelen); //tree_print_flat(&tree,stderr); //ccodebook_create(&cb, codelen); codebook_create(&cb,&tree); //codebook_print(&cb,stderr); encoder_init(&enc, &cb); fout = fopen("enc.out","w"); fwrite(&buffer_fill,4,1,fout); fwrite(codelen,128,1,fout); for(i = 0; i < buffer_fill; i++) { int c; //fprintf(stderr,"byte %d of %d\n",i,buffer_fill); encoder_put_symbol(&enc, buffer[i]); while((c = encoder_get_byte(&enc)) != ENCODER_NEED_INPUT) { uint8_t tmp = c; fwrite(&tmp,1,1,fout); } } i = encoder_get_last_byte(&enc); if(i != ENCODER_NEED_INPUT) { uint8_t tmp = i; fwrite(&tmp,1,1,fout); } fclose(fout); return 0; }
/*! Init primary accelerant */ status_t radeon_init_accelerant(int device) { TRACE("%s enter\n", __func__); status_t status = init_common(device, false); if (status != B_OK) return status; radeon_shared_info &info = *gInfo->shared_info; init_lock(&info.accelerant_lock, "radeon hd accelerant"); init_lock(&info.engine_lock, "radeon hd engine"); radeon_init_bios(gInfo->rom); // disable spread spectrum as it requires lots of extra calculations radeon_gpu_ss_disable(); // find GPIO pins from AtomBIOS gpio_probe(); // find physical card connectors from AtomBIOS status = connector_probe(); if (status != B_OK) { TRACE("%s: falling back to legacy connector probe.\n", __func__); status = connector_probe_legacy(); } if (status != B_OK) { TRACE("%s: couldn't detect supported connectors!\n", __func__); return status; } // print found connectors debug_connectors(); // setup encoders on each connector if needed encoder_init(); // setup link on any DisplayPort connectors dp_setup_connectors(); // detect attached displays status = detect_displays(); //if (status != B_OK) // return status; // print found displays debug_displays(); // create initial list of video modes status = create_mode_list(); //if (status != B_OK) { // radeon_uninit_accelerant(); // return status; //} radeon_gpu_mc_setup(); // Set up data crunching + irq rings radeon_gpu_ring_setup(); radeon_gpu_ring_boot(RADEON_QUEUE_TYPE_GFX_INDEX); TRACE("%s done\n", __func__); return B_OK; }
int main() { int s32MainFd,temp; struct timespec ts = { 2, 0 }; //================================================= ringmalloc(640*480); errno = 0; if(!camera_init(&pic)) goto error_cam; if(!encoder_init(&pic)) goto error_encoder; if(!preview_init(&pic)) goto error_preview; get_filename(); printf("file:%s\n",mkv_filename); if(!output_init(&pic,mkv_filename)) goto error_output; if(!encoder_encode_headers(&encoded_pic)) goto error_output; memcpy(&header_pic,&encoded_pic,sizeof(encoded_pic)); header_pic.buffer=malloc(encoded_pic.length); memcpy(header_pic.buffer,encoded_pic.buffer,encoded_pic.length); if(!output_write_headers(&encoded_pic,&psp)) goto error_output; encoder_release(&encoded_pic); if(!camera_on()) goto error_cam_on; //================================================ printf("RTSP server START\n"); PrefsInit(); printf("listen for client connecting...\n"); signal(SIGINT, IntHandl); s32MainFd = tcp_listen(SERVER_RTSP_PORT_DEFAULT); /* 初始化schedule_list 队列,创建调度线程,参考 schedule.c */ if (ScheduleInit(&pic,&encoded_pic) == ERR_FATAL) { fprintf(stderr,"Fatal: Can't start scheduler %s, %i \nServer is aborting.\n", __FILE__, __LINE__); return 0; } /* 将所有可用的RTP端口号放入到port_pool[MAX_SESSION] 中 */ RTP_port_pool_init(RTP_DEFAULT_PORT); //循环等待 if((temp = pthread_create(&thread[0], NULL, cam_thread, NULL)) != 0) printf("cam_thread error!\n"); else printf("cam_thread ok\n"); pthread_mutex_init(&mut,NULL); while (!g_s32Quit) { nanosleep(&ts, NULL); /*查找收到的rtsp连接, * 对每一个连接产生所有的信息放入到结构体rtsp_list中 */ // trace_point(); EventLoop(s32MainFd); } ringfree(); printf("The Server quit!\n"); camera_off(); error_cam_on: output_close(); error_output: preview_close(); error_preview: encoder_close(); error_encoder: camera_close(); error_cam: return NULL; }
int main (void) { uint8_t i; #ifndef HOST uint8_t read_old = 0; uint8_t old_ind = 0; const int total = 5000; #endif timer_init (); for (i = 0; i < AC_ENCODER_EXT_NB; i++) encoder_init (i, &encoder[i]); encoder_corrector_init (&encoder_corrector_right); uart0_init (); proto_send0 ('z'); sei (); while (1) { timer_wait (); if (count) { encoder_update (); encoder_corrector_update (&encoder_corrector_right, &encoder[1]); } #ifndef HOST if (read && !--read_cpt) { uint8_t r0, r1, r2, r3; r0 = encoder_ext_read (0); r1 = encoder_ext_read (1); r2 = encoder_ext_read (2); r3 = encoder_ext_read (3); if (read_mode == 0 || (read_mode == 1 && r3 != read_old) || (read_mode == 2 && (r0 == 0 || r1 == 0 || r2 == 0 || r3 == 0))) { proto_send4b ('r', r0, r1, r2, r3); read_old = r3; } read_cpt = read; } if (ind && !--ind_cpt) { i = encoder_ext_read (3); if (!ind_init && i != old_ind) { uint8_t eip = old_ind + total; uint8_t eim = old_ind - total; proto_send7b ('i', old_ind, i, eip, eim, i - eip, i - eim, i == eip || i == eim); } old_ind = i; ind_init = 0; ind_cpt = ind; } #endif if (count && !--count_cpt) { proto_send4w ('C', encoder[0].cur, encoder[1].cur, encoder[2].cur, encoder[3].cur); count_cpt = count; } while (uart0_poll ()) proto_accept (uart0_getc ()); } }
int main(int argc, char **argv) { GError *error = NULL; struct audio_format audio_format; bool ret; const char *encoder_name; const struct encoder_plugin *plugin; struct encoder *encoder; struct config_param *param; static char buffer[32768]; ssize_t nbytes; /* parse command line */ if (argc > 3) { g_printerr("Usage: run_encoder [ENCODER] [FORMAT] <IN >OUT\n"); return 1; } if (argc > 1) encoder_name = argv[1]; else encoder_name = "vorbis"; audio_format_init(&audio_format, 44100, SAMPLE_FORMAT_S16, 2); /* create the encoder */ plugin = encoder_plugin_get(encoder_name); if (plugin == NULL) { g_printerr("No such encoder: %s\n", encoder_name); return 1; } param = config_new_param(NULL, -1); config_add_block_param(param, "quality", "5.0", -1); encoder = encoder_init(plugin, param, &error); if (encoder == NULL) { g_printerr("Failed to initialize encoder: %s\n", error->message); g_error_free(error); return 1; } /* open the encoder */ if (argc > 2) { ret = audio_format_parse(&audio_format, argv[2], false, &error); if (!ret) { g_printerr("Failed to parse audio format: %s\n", error->message); g_error_free(error); return 1; } } ret = encoder_open(encoder, &audio_format, &error); if (encoder == NULL) { g_printerr("Failed to open encoder: %s\n", error->message); g_error_free(error); return 1; } /* do it */ while ((nbytes = read(0, buffer, sizeof(buffer))) > 0) { ret = encoder_write(encoder, buffer, nbytes, &error); if (!ret) { g_printerr("encoder_write() failed: %s\n", error->message); g_error_free(error); return 1; } encoder_to_stdout(encoder); } ret = encoder_flush(encoder, &error); if (!ret) { g_printerr("encoder_flush() failed: %s\n", error->message); g_error_free(error); return 1; } encoder_to_stdout(encoder); }
static struct audio_output * httpd_output_init(const struct config_param *param, GError **error) { struct httpd_output *httpd = g_new(struct httpd_output, 1); if (!ao_base_init(&httpd->base, &httpd_output_plugin, param, error)) { g_free(httpd); return NULL; } const char *encoder_name, *bind_to_address; const struct encoder_plugin *encoder_plugin; guint port; /* read configuration */ httpd->name = config_get_block_string(param, "name", "Set name in config"); httpd->genre = config_get_block_string(param, "genre", "Set genre in config"); httpd->website = config_get_block_string(param, "website", "Set website in config"); port = config_get_block_unsigned(param, "port", 8000); encoder_name = config_get_block_string(param, "encoder", "vorbis"); encoder_plugin = encoder_plugin_get(encoder_name); if (encoder_plugin == NULL) { g_set_error(error, httpd_output_quark(), 0, "No such encoder: %s", encoder_name); ao_base_finish(&httpd->base); g_free(httpd); return NULL; } httpd->clients_max = config_get_block_unsigned(param,"max_clients", 0); /* set up bind_to_address */ httpd->server_socket = server_socket_new(httpd_listen_in_event, httpd); bind_to_address = config_get_block_string(param, "bind_to_address", NULL); bool success = bind_to_address != NULL && strcmp(bind_to_address, "any") != 0 ? server_socket_add_host(httpd->server_socket, bind_to_address, port, error) : server_socket_add_port(httpd->server_socket, port, error); if (!success) { ao_base_finish(&httpd->base); g_free(httpd); return NULL; } /* initialize metadata */ httpd->metadata = NULL; httpd->unflushed_input = 0; /* initialize encoder */ httpd->encoder = encoder_init(encoder_plugin, param, error); if (httpd->encoder == NULL) { ao_base_finish(&httpd->base); g_free(httpd); return NULL; } /* determine content type */ httpd->content_type = encoder_get_mime_type(httpd->encoder); if (httpd->content_type == NULL) { httpd->content_type = "application/octet-stream"; } httpd->mutex = g_mutex_new(); return &httpd->base; }
int main(void) { /* MCU Configuration----------------------------------------------------------*/ /* Reset of all peripherals, Initializes the Flash interface * and the Systick. */ board_Init(); /* Init components */ motor_init(); motor_stop(motor_ch_all); motor_go_forward(); pb_init(); encoder_init(); /* USER CODE BEGIN RTOS_MUTEX */ /* USER CODE END RTOS_MUTEX */ /* USER CODE BEGIN RTOS_SEMAPHORES */ /* add semaphores, ... */ muRange = xSemaphoreCreateMutex(); /* USER CODE END RTOS_SEMAPHORES */ /* USER CODE BEGIN RTOS_TIMERS */ /* start timers, add new ones, ... */ /* USER CODE END RTOS_TIMERS */ /* Create the thread(s) */ /* definition and creation of defaultTask */ xTaskCreate(task_blinky, /* Pointer to the function that implements the task */ "Blinky", /* Text name for the task. This is to facilitate debugging only. It is not used in the scheduler */ configMINIMAL_STACK_SIZE, /* Stack depth in words */ NULL, /* Pointer to a task parameters */ 1, /* The task priority */ &xBlinkyHandle); /* Pointer of its task handler, if you don't want to use, you can leave it NULL */ /* xTaskCreate(vRangeFinderTask, "Range", configMINIMAL_STACK_SIZE+500, NULL, configMAX_PRIORITIES-1, &xScanInputHandle); */ /* xTaskCreate(vEncoderTask, "Encoder", configMINIMAL_STACK_SIZE+500, NULL, configMAX_PRIORITIES-1, &xScanInputHandle); */ xTaskCreate(task_main, "Main", configMINIMAL_STACK_SIZE+2500, NULL, configMAX_PRIORITIES-1, &xMainHandle); /* USER CODE BEGIN RTOS_QUEUES */ /* definition and creation of xQueueUARTReceive */ quUARTReceive = xQueueCreate(confUART_RECEIVE_QUEUE_LENGTH, /* length of queue */ sizeof(uint8_t)*confUART_RECEIVE_BUFFER_SIZE); /* size in byte of each item */ /* USER CODE END RTOS_QUEUES */ /* Start scheduler */ vTaskStartScheduler(); /* NOTE: We should never get here as control is now taken by the scheduler */ while (1) { } }
int main(void) { MAP_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN |SYSCTL_XTAL_12MHZ); //50MHZ // // Enable peripherals to operate when CPU is in sleep. // MAP_SysCtlPeripheralClockGating(true); // // Configure SysTick to occur 1000 times per second, to use as a time // reference. Enable SysTick to generate interrupts. // MAP_SysTickPeriodSet(MAP_SysCtlClockGet() / SYSTICKS_PER_SECOND); MAP_SysTickIntEnable(); MAP_SysTickEnable(); // // Get the current processor clock frequency. // ulClockMS = MAP_SysCtlClockGet() / (3 * 1000); // init Serial Comm initSerialComm(230400); // init SSI0 in slave mode initSPIComm(); #ifdef DEBUG UARTprintf("Setting up PID\n"); #endif initCarPID(); #ifdef DEBUG UARTprintf("done\n"); #endif #ifdef DEBUG UARTprintf("Setting up PWM ... \n"); #endif configurePWM(); configureGPIO(); #ifdef DEBUG UARTprintf("done\n"); #endif #ifdef DEBUG UARTprintf("Setting up Servo ... \n"); #endif servo_init(); servo_setPosition(90); #ifdef DEBUG UARTprintf("done\n"); #endif #ifdef DEBUG UARTprintf("Starting QEI..."); #endif encoder_init(); #ifdef DEBUG UARTprintf("done\n"); #endif #ifdef USE_I2C #ifdef DEBUG UARTprintf("Setting up I2C\n"); #endif //I2C MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C0); MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); MAP_GPIOPinTypeI2C(GPIO_PORTB_AHB_BASE,GPIO_PIN_2 | GPIO_PIN_3); MAP_I2CMasterInitExpClk(I2C0_MASTER_BASE,SysCtlClockGet(),true); //false = 100khz , true = 400khz I2CMasterTimeoutSet(I2C0_MASTER_BASE, 1000); #ifdef DEBUG UARTprintf("done\n"); #endif #endif #ifdef USE_I2C #ifdef USE_INA226 #ifdef DEBUG UARTprintf("Setting up INA226\n"); #endif initINA226(); #ifdef DEBUG UARTprintf("done\n"); #endif #endif #endif while (1) { } }