void vjpegInit(void) { #ifndef ECOS tt_rmutex_init(&g_vpJPEG.mtLock); tt_rmutex_init(&g_vpJPEG.mtLockEncoder); tt_rmutex_init(&g_vpJPEG.mtLockDecoder); tt_sem_init(&g_vpJPEG.semEncoder, 1); tt_sem_init(&g_vpJPEG.semDecoder, 1); tt_sem_down(&g_vpJPEG.semEncoder); tt_sem_down(&g_vpJPEG.semDecoder); #else cyg_mutex_init(&g_vpJPEG.mtLock); cyg_mutex_init(&g_vpJPEG.mtLockEncoder); cyg_mutex_init(&g_vpJPEG.mtLockDecoder); cyg_semaphore_init(&g_vpJPEG.semEncoder, 1); cyg_semaphore_init(&g_vpJPEG.semDecoder, 1); cyg_semaphore_wait(&g_vpJPEG.semEncoder); cyg_semaphore_wait(&g_vpJPEG.semDecoder); #endif g_vpJPEG.nRefCount = 0; g_vpJPEG.nRefCount_Encoder = 0; g_vpJPEG.nRefCount_Decoder = 0; g_vpJPEG.pJPEGEncodeBuffer = NULL; listInit (&g_vpJPEG.listEncodedJPEG); g_vpJPEG.nJPEGQua = 2; g_vpJPEG.bOnTheFly = TRUE; g_vpJPEG.nOnTheFlyCount = 0; #ifndef ECOS sysInstallISR(IRQ_LEVEL_1, IRQ_JPEG, (void*)jpegIntHandler); #else cyg_interrupt_disable(); cyg_interrupt_create(IRQ_JPEG, IRQ_LEVEL_1, NULL, &jpegIntHandler, &jpegIntHandler_DSR, &(g_vpJPEG.cygIntrHandle), &(g_vpJPEG.cygIntrBuffer)); cyg_interrupt_attach(g_vpJPEG.cygIntrHandle); cyg_interrupt_unmask(IRQ_JPEG); cyg_interrupt_enable(); #endif jpegSetIRQHandler(C_JPEG_CALLBACK_ENCODE_COMPLETE_INTERRUPT, vjpegEncoderCom_Callback); jpegSetIRQHandler(C_JPEG_CALLBACK_DECODE_COMPLETE_INTERRUPT, vjpegDecoderCom_Callback); jpegSetIRQHandler(C_JPEG_CALLBACK_DECODE_ERROR_INTERRUPT, vjpegDecoderErr_Callback); if(g_vpJPEG.bOnTheFly == TRUE) { jpegSetIRQHandler(C_JPEG_CALLBACK_ENCODE_SWONTHEFLY_WAIT_INTERRUPT, vjpegOnTheFlyCom_Callback); } bJPEGInit = TRUE; }
int main(int argc, char** argv) { char p[512]; char *server_mem; char *client_mem; int client_size; int server_size; force_net_dev_linked(); cyg_do_net_init(); SetWlanESSID("zhuna"); #ifdef MP4 sprintf(p, g_RtspServer_conf, "IMAADPCM", "Mpeg4", "Mpeg4", "IMAADPCM"); #else sprintf(p, g_RtspServer_conf, "AMR", "H263", "H263", "AMR"); #endif set_config(p); cyg_semaphore_init(&video_sem0, 0); cyg_semaphore_init(&video_sem1, 0); cyg_semaphore_init(&audio_sem0, 0); cyg_semaphore_init(&audio_sem1, 0); cyg_interrupt_disable(); cyg_interrupt_disable(); cyg_interrupt_disable(); cyg_interrupt_enable(); set_auth_id("jfyan","jfyanpass"); set_auth_id("jfyan1","jfyan1"); set_auth_id("jfyan2","jfyan2"); del_auth_id("jfyan1","jfyan1"); //set_auth_disable(); VideoPhoneInit(); fmiSetFMIReferenceClock(112000); fmiSetSDOutputClockbykHz(18000); //FTH_Init(); init_wbdevice(initlcm); set_encoderenable(set_encoderenableFunc); set_encoderdisable(set_encoderdisableFunc); init_get_video(get_back_video); init_get_audio(get_back_audio); server_size = get_server_size(); server_mem = (char*)malloc(server_size); if(server_mem == NULL) printf("memory out\n"); rtsp_server_init(server_mem, server_size); client_size = get_rtspmem_size(3); client_mem = (char*)malloc(client_size); if(client_mem == NULL) printf("memory out\n"); rtsp_mem_init(client_mem, client_size); RtspServerStart(2); }
// // This function is used to create a new server [thread] which supports // the TFTP protocol on the given port. A server 'id' will be returned // which can later be used to destroy the server. // // Note: all [memory] resources for the server thread will be allocated // dynamically. If there are insufficient resources, an error will be // returned. // int tftpd_start(int port, struct tftpd_fileops *ops) { struct tftp_server *server; #ifdef CYGSEM_TFTP_SERVER_MULTITHREADED static char init = 0; if ( 0 == init ) { init++; cyg_semaphore_init( &tftp_server_sem, 0 ); } #endif if ((server = malloc(sizeof(struct tftp_server)))) { server->tag = TFTP_tag; server->port = port; server->ops = ops; cyg_thread_create(CYGPKG_NET_TFTPD_THREAD_PRIORITY, // Priority tftpd_server, // entry (cyg_addrword_t)server, // entry parameter "TFTP server", // Name &server->stack[0], // Stack STACK_SIZE, // Size &server->thread_handle, // Handle &server->thread_data // Thread data structure ); cyg_thread_resume(server->thread_handle); // Start it } return (int)server; }
void kbd_init(void) { // Initialize environment, setup interrupt handler cyg_drv_interrupt_create(CYGNUM_HAL_INTERRUPT_KBDINT, 99, // Priority - what goes here? 0, // Data item passed to interrupt handler (cyg_ISR_t *)keyboard_isr, (cyg_DSR_t *)keyboard_dsr, &kbd_interrupt_handle, &kbd_interrupt); cyg_drv_interrupt_attach(kbd_interrupt_handle); cyg_drv_interrupt_acknowledge(CYGNUM_HAL_INTERRUPT_KBDINT); cyg_drv_interrupt_unmask(CYGNUM_HAL_INTERRUPT_KBDINT); // Set up the mbox for keyboard data cyg_mbox_create(&kbd_events_mbox_handle, &kbd_events_mbox); // This semaphore is set when there is a keypress cyg_semaphore_init(&kbd_sem, 0); // Create a thread whose job it is to de-bounce the keyboard and // actually process the input, turning it into a series of events cyg_thread_create(10, // Priority - just a number kbd_server, // entry 0, // initial parameter "KBD_server", // Name &kbd_server_stack[0], // Stack STACK_SIZE, // Size &kbd_server_thread_handle, // Handle &kbd_server_thread_data // Thread data structure ); cyg_thread_resume(kbd_server_thread_handle); // Start it }
void init_LinkLocal() { if( (LinkLocal_get_current_state() == NO_USE) || (LinkLocal_get_current_state() == IDLE) ) LinkLocal_state = PROBE; cyg_semaphore_init(&linklocal_conflict, 0); }
externC void cyg_start( void ) { int i; diag_init(); diag_write_string("Philosophers\n"); diag_write_string("Started\n"); // Zero last element in state so it acts like // a string. pstate[PHILOSOPHERS] = 0; #if 1 for( i = 0; i < PHILOSOPHERS; i++ ) { change_state(i,'T'); // starting state cyg_thread_create(4, Philosopher, (cyg_addrword_t)i, "philosopher", (void *)(&thread_stack[i]), STACKSIZE, &thread_handle[i], &thread[i]); // resume it cyg_thread_resume(thread_handle[i]); // and make the matching chopstick present cyg_semaphore_init( &chopstick[i], 1); } #endif // Get the world going cyg_scheduler_start(); }
CECOSTimerHandler::CECOSTimerHandler(){ cyg_semaphore_init(&m_stSemaphore, 0); m_stSystemclockHandle = cyg_real_time_clock(); cyg_clock_to_counter(m_stSystemclockHandle, &m_stCounterHandle); cyg_alarm_create(m_stCounterHandle, timerHandlerFunc, (cyg_addrword_t) 0, &m_stAlarmHandle, &m_stAlarm); }
void nc_slave_main(void) { int i; CYG_TEST_INIT(); // Create the idle thread environment cyg_semaphore_init(&idle_thread_sem, 0); cyg_thread_create(IDLE_THREAD_PRIORITY, // Priority net_idle, // entry 0, // entry parameter "Network idle", // Name &idle_thread_stack[0], // Stack STACK_SIZE, // Size &idle_thread_handle, // Handle &idle_thread_data // Thread data structure ); cyg_thread_resume(idle_thread_handle); // Start it // Create the load threads and their environment(s) for (i = 0; i < NUM_LOAD_THREADS; i++) { cyg_semaphore_init(&load_thread_sem[i], 0); cyg_thread_create(LOAD_THREAD_PRIORITY, // Priority net_load, // entry i, // entry parameter "Background load", // Name &load_thread_stack[i][0], // Stack STACK_SIZE, // Size &load_thread_handle[i], // Handle &load_thread_data[i] // Thread data structure ); cyg_thread_resume(load_thread_handle[i]); // Start it } // Create a main thread, so we can run the scheduler and have time 'pass' cyg_thread_create(10, // Priority - just a number tmain, // entry 0, // entry parameter "socket echo test", // Name &stack[0], // Stack STACK_SIZE, // Size &thread_handle, // Handle &thread_data // Thread data structure ); cyg_thread_resume(thread_handle); // Start it cyg_scheduler_start(); CYG_TEST_FAIL_FINISH("Not reached"); }
void cyg_start(void *n) { int i; // Create processing threads for (i = 0; i < CYGHWR_NET_DRIVERS; i++) { cyg_thread_create(MAIN_THREAD_PRIORITY, // Priority net_test, // entry i, // entry parameter "Network test", // Name &main_thread_stack[i][0], // Stack STACK_SIZE, // Size &main_thread_handle[i], // Handle &main_thread_data[i] // Thread data structure ); } cyg_thread_resume(main_thread_handle[0]); // Start first one // Create the idle thread environment cyg_semaphore_init(&idle_thread_sem, 0); cyg_thread_create(IDLE_THREAD_PRIORITY, // Priority net_idle, // entry 0, // entry parameter "Network idle", // Name &idle_thread_stack[0], // Stack STACK_SIZE, // Size &idle_thread_handle, // Handle &idle_thread_data // Thread data structure ); cyg_thread_resume(idle_thread_handle); // Start it // Create the load threads and their environment(s) for (i = 0; i < NUM_LOAD_THREADS; i++) { cyg_semaphore_init(&load_thread_sem[i], 0); cyg_thread_create(LOAD_THREAD_PRIORITY, // Priority net_load, // entry i, // entry parameter "Background load", // Name &load_thread_stack[i][0], // Stack STACK_SIZE, // Size &load_thread_handle[i], // Handle &load_thread_data[i] // Thread data structure ); cyg_thread_resume(load_thread_handle[i]); // Start it } cyg_scheduler_start(); }
void cyg_start(void) { int i; // Create a main thread which actually runs the test cyg_thread_create(MAIN_THREAD_PRIORITY, // Priority net_test, // entry 0, // entry parameter "Network test", // Name &stack[0], // Stack STACK_SIZE, // Size &thread_handle, // Handle &thread_data // Thread data structure ); cyg_thread_resume(thread_handle); // Start it // Create the idle thread environment cyg_semaphore_init(&idle_thread_sem, 0); cyg_thread_create(IDLE_THREAD_PRIORITY, // Priority net_idle, // entry 0, // entry parameter "Network idle", // Name &idle_thread_stack[0], // Stack STACK_SIZE, // Size &idle_thread_handle, // Handle &idle_thread_data // Thread data structure ); cyg_thread_resume(idle_thread_handle); // Start it // Create the load threads and their environment(s) for (i = 0; i < NUM_LOAD_THREADS; i++) { cyg_semaphore_init(&load_thread_sem[i], 0); cyg_thread_create(LOAD_THREAD_PRIORITY, // Priority net_load, // entry i, // entry parameter "Background load", // Name &load_thread_stack[i][0], // Stack STACK_SIZE, // Size &load_thread_handle[i], // Handle &load_thread_data[i] // Thread data structure ); cyg_thread_resume(load_thread_handle[i]); // Start it } cyg_scheduler_start(); }
void library_open(void) { // Initialize the count for thread a. thread_a_count = 0; // Initialize the semaphore with a count of zero, // prior to creating the threads. cyg_semaphore_init(&sem_signal_thread, 0); CYG_TEST_INFO("Library initialized"); }
/* * Create a new semaphore and initialize it. * If no memory is available return NULL */ sys_sem_t sys_sem_new(u8_t count) { sys_sem_t sem; sem = (cyg_sem_t *)cyg_mempool_var_try_alloc(var_mempool_h, sizeof(cyg_sem_t)); /* out of memory? */ if(!sem) return SYS_SEM_NULL; cyg_semaphore_init(sem, count); return sem; }
void ksem1_main( void ) { CYG_TEST_INIT(); cyg_semaphore_init( &s0, 0); cyg_semaphore_init( &s1, 2); cyg_semaphore_init( &s2, 0); cyg_thread_create(4, entry0 , (cyg_addrword_t)0, "ksem1-0", (void *)stack[0], STACKSIZE,&thread[0], &thread_obj[0]); cyg_thread_resume(thread[0]); cyg_thread_create(4, entry1 , (cyg_addrword_t)1, "ksem1-1", (void *)stack[1], STACKSIZE, &thread[1], &thread_obj[1]); cyg_thread_resume(thread[1]); cyg_scheduler_start(); CYG_TEST_FAIL_FINISH("Not reached"); }
void Give_ip_by_myself(struct netif *netif){ if(EEPROM_Data.RENVEnable == 1) { SetLinkLocalIP(netif ,0); cyg_semaphore_init(&DhcpWaitLinklocal_sem,0); cyg_semaphore_post(&linklocal_sem); cyg_semaphore_wait(&DhcpWaitLinklocal_sem); } else set_factory_ip(); }
// Called to initialize structures used by timeout functions void cyg_tsleep_init(void) { int i; struct wakeup_event *ev; // Create list of "wakeup event" semaphores for (i = 0, ev = wakeup_list; i < CYGPKG_NET_NUM_WAKEUP_EVENTS; i++, ev++) { ev->chan = 0; cyg_semaphore_init(&ev->sem, 0); } // Initialize the mutex and thread id: cyg_mutex_init( &splx_mutex ); splx_thread = 0; }
void dhcp_start_dhcp_mgt_thread( void ) { if ( ! dhcp_mgt_thread_h ) { cyg_semaphore_init( &dhcp_needs_attention, 0 ); cyg_thread_create( CYGPKG_NET_DHCP_THREAD_PRIORITY, /* scheduling info (eg pri) */ dhcp_mgt_entry, /* entry point function */ CYGOPT_NET_DHCP_DHCP_THREAD_PARAM, /* entry data */ "DHCP lease mgt", /* optional thread name */ dhcp_mgt_stack, /* stack base, NULL = alloc */ STACK_SIZE, /* stack size, 0 = default */ &dhcp_mgt_thread_h, /* returned thread handle */ &dhcp_mgt_thread /* put thread here */ ); cyg_thread_resume(dhcp_mgt_thread_h); } }
// Allocate a semaphore for a given port number if one is not already // allocated. static void sem_alloc(int port) { int i; CYG_ASSERT(port != 0, "Invalid port number"); cyg_scheduler_lock(); // Avoid race with other tftpd's for (i=0; i < CYGNUM_NET_TFTPD_MULTITHREADED_PORTS; i++) { if (tftpd_sems[i].port == port) { cyg_scheduler_unlock(); return; } if (tftpd_sems[i].port == 0) { tftpd_sems[i].port = port; cyg_semaphore_init(&tftpd_sems[i].sem,1); cyg_scheduler_unlock(); return ; } } cyg_scheduler_unlock(); diag_printf("TFTPD: Unable to allocate a semaphore for port %d\n",port); }
void USB_init(cyg_addrword_t data) { cyg_sem_t sem; cyg_semaphore_init(&sem, 0); ppause(200); //20 Ticks, 200m seconds //init memory pci_usb_pool_init(); //usb usb_init(); //ohci ohci_hcd_init(0x5C, SYSPA_USB11_OPERATION_BASE_ADDR); //ehci ehci_hcd_init(0x6B, SYSPA_USB20_OPERATION_BASE_ADDR); //Printer Class usblp_init(); cyg_semaphore_wait(&sem); cyg_semaphore_destroy(&sem); }
void _init_sema(_sema *sema, int init_val) { #ifdef PLATFORM_LINUX //eason 20100210 sema_init(sema, init_val); cyg_semaphore_init(sema,init_val); #endif #ifdef PLATFORM_OS_XP KeInitializeSemaphore(sema, init_val, SEMA_UPBND); // count=0; #endif #ifdef PLATFORM_OS_CE if(*sema == NULL) *sema = CreateSemaphore(NULL, init_val, SEMA_UPBND, NULL); #endif }
void create_cleanup_thread(void) { unsigned int err; cyg_mbox_create(&cleanup.mbox_handle, &cleanup_mbox); cyg_semaphore_init(&cleanup.cleanup_sem, 0); if((err = shell_create_thread(NULL, 5, cleanup_thread, 0, "Cleanup Thread", NULL, 0, NULL) != SHELL_OK)) { SHELL_ERROR("Failed to create Cleanup thread\n"); HAL_PLATFORM_RESET(); } SHELL_DEBUG_PRINT("Created Cleanup thread\n"); }
static void lcd_panel_init(void) { // Enable touch panel *(volatile cyg_uint8 *)PEDR |= 0x04; // Idle state (so interrupt works) *(volatile cyg_uint8 *)TOUCH_CTL = 0x70; // Enable ADC machinery *(volatile cyg_uint32 *)SYSCON1 |= SYSCON1_ADC_CLOCK_128kHZ; cyg_drv_interrupt_create(CYGNUM_HAL_INTERRUPT_EINT2, 99, // Priority - what goes here? 0, // Data item passed to interrupt handler lcd_panel_isr, lcd_panel_dsr, &lcd_panel_interrupt_handle, &lcd_panel_interrupt); cyg_drv_interrupt_attach(lcd_panel_interrupt_handle); cyg_drv_interrupt_acknowledge(CYGNUM_HAL_INTERRUPT_EINT2); cyg_drv_interrupt_unmask(CYGNUM_HAL_INTERRUPT_EINT2); // Set up the mbox for panel data cyg_mbox_create(&lcd_panel_events_mbox_handle, &lcd_panel_events_mbox); // This semaphore is set when there is a touch cyg_semaphore_init(&lcd_panel_sem, 0); // Create a thread whose job it is to de-bounce the keyboard and // actually process the input, turning it into a series of events cyg_thread_create(10, // Priority - just a number lcd_panel_server, // entry 0, // initial parameter "LCD_PANEL_server", // Name &lcd_panel_server_stack[0], // Stack STACK_SIZE, // Size &lcd_panel_server_thread_handle, // Handle &lcd_panel_server_thread_data // Thread data structure ); cyg_thread_resume(lcd_panel_server_thread_handle); // Start it }
int main(int argc, char *argv[]) { int i; int disk; int fd[NUM_DISKS]; // Initialize the ISP Fibre Channel Controller isp_controller_init(0); // Create test complete semaphore cyg_semaphore_init(&test_cmpl_sema, 0); /* Open a connection to the first NUM_DISKS found. */ for (i = 0, disk = 0; (disk < NUM_DISKS) && (i < MAX_NUM_DISKS); ++i) { cyg_io_handle_t handle; Cyg_ErrNo status; char device[10]; sprintf(device, "/dev/sd%d", i); /* See if this device is present */ status = cyg_io_lookup(device, &handle); if (status == ENOERR) { fd[disk] = open(device, O_RDWR, 0); if (fd[disk] == -1) { printf ("disktest: open() failed for %s - ", device); perror("open"); return(-1); } ++disk; } } printf("\nPerforming disktest on %d disk(s)\n", disk); // Create tasks to perform disk testing. Each task tests one disk. for (i = 0; i < disk; ++i) { cyg_thread_create(15, &disktest, fd[i], "disktest", &stack[i][0], CYGNUM_HAL_STACK_SIZE_TYPICAL, &disktest_handle[i], &disktest_thread[i]); cyg_thread_resume(disktest_handle[i]); } // Wait for test to complete for (i = 0; i < disk; ++i) cyg_semaphore_wait(&test_cmpl_sema); // Close all the files for (i = 0; i < disk; ++i) close(fd[i]); // Delete semaphore cyg_semaphore_destroy(&test_cmpl_sema); printf("disktest completed.\n"); cyg_thread_exit(); // Should never get here return(0); }
// return value: 1 => everything OK, no change. // 0 => close your connections, then call do_dhcp_halt() to halt the // interface(s) in question (it knows because the state will be NOTBOUND). // After that you can return to the start and use // init_all_network_interfaces(); as usual, or call do_dhcp_bind() by hand, // or whatever... int dhcp_bind( void ) { #ifdef CYGHWR_NET_DRIVER_ETH0 cyg_uint8 old_eth0_dhcpstate = eth0_dhcpstate; #endif #ifdef CYGHWR_NET_DRIVER_ETH1 cyg_uint8 old_eth1_dhcpstate = eth1_dhcpstate; #endif // If there are no interfaces at all, init it every time, doesn't // matter. In case we are called from elsewhere... if ( 1 #ifdef CYGHWR_NET_DRIVER_ETH0 && eth0_dhcpstate == 0 #endif #ifdef CYGHWR_NET_DRIVER_ETH1 && eth1_dhcpstate == 0 #endif ) cyg_semaphore_init( &dhcp_needs_attention, 0 ); // Run the state machine... #ifdef CYGHWR_NET_DRIVER_ETH0 if (eth0_up && DHCPSTATE_FAILED != eth0_dhcpstate ) eth0_up = do_dhcp(eth0_name, ð0_bootp_data, ð0_dhcpstate, ð0_lease); #endif #ifdef CYGHWR_NET_DRIVER_ETH1 if (eth1_up && DHCPSTATE_FAILED != eth1_dhcpstate ) eth1_up = do_dhcp(eth1_name, ð1_bootp_data, ð1_dhcpstate, ð1_lease); #endif // If the interface newly came up, initialize it: // (this duplicates the code in init_all_network_interfaces() really). #ifdef CYGHWR_NET_DRIVER_ETH0 if ( eth0_up && eth0_dhcpstate == DHCPSTATE_BOUND && old_eth0_dhcpstate != eth0_dhcpstate ) { if (!init_net(eth0_name, ð0_bootp_data)) { eth0_up = false; } } #endif #ifdef CYGHWR_NET_DRIVER_ETH1 if ( eth1_up && eth1_dhcpstate == DHCPSTATE_BOUND && old_eth1_dhcpstate != eth1_dhcpstate ) { if (!init_net(eth1_name, ð1_bootp_data)) { eth1_up = false; } } #endif #ifdef CYGHWR_NET_DRIVER_ETH0 if ( old_eth0_dhcpstate == DHCPSTATE_BOUND && eth0_dhcpstate == DHCPSTATE_NOTBOUND ) return 0; // a lease timed out; we became unbound #endif #ifdef CYGHWR_NET_DRIVER_ETH1 if ( old_eth1_dhcpstate == DHCPSTATE_BOUND && eth1_dhcpstate == DHCPSTATE_NOTBOUND ) return 0; // a lease timed out; we became unbound #endif return 1; // all is well }
static void *usblp_probe(struct usb_device *dev, unsigned int ifnum,const struct usb_device_id *id) { struct usb_interface_descriptor *interface; struct usb_endpoint_descriptor *epread, *epwrite; struct usblp *usblp; int minor, bidir, quirks; int alts; int length, errno; char *buf,*buf1; char name[6]; //ZOT716u2 armond_printf("usblp probe\n"); alts = usblp_select_alts(dev, ifnum); interface = &dev->actconfig->interface[ifnum].altsetting[alts]; if (usb_set_interface(dev, ifnum, alts)) { //{{MARK_DEBUG // err("can't set desired altsetting %d on interface %d", alts, ifnum); //}}MARK_DEBUG //ZOT716u2 armond_printf("usb_set_interface Error\n"); } bidir = (interface->bInterfaceProtocol > 1); epwrite = interface->endpoint + 0; epread = bidir ? interface->endpoint + 1 : NULL; if ((epwrite->bEndpointAddress & 0x80) == 0x80) { if (interface->bNumEndpoints == 1) return NULL; epwrite = interface->endpoint + 1; epread = bidir ? interface->endpoint + 0 : NULL; } if ((epwrite->bEndpointAddress & 0x80) == 0x80) return NULL; if (bidir && (epread->bEndpointAddress & 0x80) != 0x80) return NULL; for (minor = 0; minor < USBLP_MINORS && usblp_table[minor]; minor++); if (usblp_table[minor]) { //{{MARK_DEBUG // err("no more free usblp devices"); //}}MARK_DEBUG return NULL; } if ((usblp = kmalloc(sizeof(struct usblp), GFP_KERNEL)) == NULL ) { //{{MARK_DEBUG // err("out of memory"); //}}MARK_DEBUG return NULL; } memset(usblp, 0, sizeof(struct usblp)); /* lookup quirks for this printer */ quirks = usblp_quirks(dev->descriptor.idVendor, dev->descriptor.idProduct); if (bidir && (quirks & USBLP_QUIRK_BIDIR)) { bidir = 0; epread = NULL; //{{MARK_DEBUG // dbg ("Disabling reads from problem bidirectional printer on usblp%d", // minor); //}}MARK_DEBUG } usblp->dev = dev; usblp->ifnum = ifnum; usblp->minor = minor; usblp->bidir = bidir; usblp->quirks = quirks; // init_waitqueue_head(&usblp->wait); usblp->wait = malloc (sizeof(cyg_sem_t)); //ZOT716u2 cyg_semaphore_init(usblp->wait, 0); //ZOT716u2 //615wu /* if ((buf = kmalloc(USBLP_BUF_SIZE * (bidir ? 2 : 1), GFP_KERNEL))==NULL) { //{{MARK_DEBUG // err("out of memory"); //}}MARK_DEBUG kfree(usblp); return NULL; } */ //719AW buf = USB_PRINTER_WRITE_BUFFER; buf = kaligned_alloc(8192, 4096); //eason 20100407 if ((usblp->device_id_string = kmalloc(DEVICE_ID_SIZE, GFP_KERNEL))==NULL) { //{{MARK_DEBUG // err("out of memory"); //}}MARK_DEBUG kfree(usblp, 0); //615wu kfree(buf); return NULL; } //719AW buf1 = USB_PRINTER_READ_BUFFER; buf1 = kaligned_alloc(8192, 4096); //eason 20100407 FILL_BULK_URB(&usblp->writeurb, dev, usb_sndbulkpipe(dev, epwrite->bEndpointAddress), buf, 0, usblp_bulk, usblp); if (bidir) //615WU FILL_BULK_URB(&usblp->readurb, dev, usb_rcvbulkpipe(dev, epread->bEndpointAddress), // buf + USBLP_BUF_SIZE, USBLP_BUF_SIZE, usblp_bulk, usblp); FILL_BULK_URB(&usblp->readurb, dev, usb_rcvbulkpipe(dev, epread->bEndpointAddress), buf1, 256, usblp_bulk, usblp); /* Get the device_id string if possible. FIXME: Could make this kmalloc(length). */ errno = usblp_get_id(usblp, 0, usblp->device_id_string, DEVICE_ID_SIZE - 1); if (errno >= 0) { length = (usblp->device_id_string[0] << 8) + usblp->device_id_string[1]; /* big-endian */ if (length < DEVICE_ID_SIZE) usblp->device_id_string[length] = '\0'; else usblp->device_id_string[DEVICE_ID_SIZE - 1] = '\0'; //{{MARK_DEBUG // dbg ("usblp%d Device ID string [%d]=%s", // minor, length, &usblp->device_id_string[2]); //}}MARK_DEBUG //ZOT716u2 armond_printf("usblp_get_id OK\n"); } else { //{{MARK_DEBUG // err ("usblp%d: error = %d reading IEEE-1284 Device ID string", // minor, errno); //}}MARK_DEBUG usblp->device_id_string[0] = usblp->device_id_string[1] = '\0'; //ZOT716u2 armond_printf("usblp_get_id error:%d\n",errno); } //#ifdef DEBUG // usblp_check_status(usblp, 0); //#endif // sprintf(name, "lp%d", minor); /* Create with perms=664 */ // usblp->devfs = devfs_register(usb_devfs_handle, name, // DEVFS_FL_DEFAULT, USB_MAJOR, // USBLP_MINOR_BASE + minor, // S_IFCHR | S_IRUSR | S_IWUSR | S_IRGRP | // S_IWGRP, &usblp_fops, NULL); // if (usblp->devfs == NULL) // err("usblp%d: device node registration failed", minor); //{{MARK_DEBUG // dbg("usblp%d: USB %sdirectional printer dev %d if %d alt %d", // minor, bidir ? "Bi" : "Uni", dev->devnum, ifnum, alts); //}}MARK_DEBUG usblp_table[minor] = usblp; usbprn_attach( minor ); return usblp; }
void Spooler_init(void) { //...........Print Port Virtual Driver Function...........// //Print Port Initialization PrnPortInit(); //...........Print Queue Buffer Allocate Function...........// PrnQueueInit(); //...........Print Queue Initialize Function...........// PrnPrinterInit(); //Clear SP_SIGNAL_PORT_1 count cyg_semaphore_init(&SP_SIGNAL_PORT_1,0); //...........Spooler Function...........// //Create PrnSpooler Thread cyg_thread_create(PrnSpooler_TASK_PRI, PrnStartSpooler, 0, "PrnSpooler", (void *) (PrnSpooler_Stack), PrnSpooler_TASK_STACK_SIZE, &PrnSpooler_TaskHdl, &PrnSpooler_Task); //Start PrnSpooler Thread cyg_thread_resume(PrnSpooler_TaskHdl); //Create PortNWrite Thread cyg_thread_create(PortNWrite_TASK_PRI, PortNWrite, 0, "Port1Write", (void *) (PortNWrite_Stack), PortNWrite_TASK_STACK_SIZE, &PortNWrite_TaskHdl, &PortNWrite_Task); //Start PortNWrite Thread cyg_thread_resume(PortNWrite_TaskHdl); //...........Read Print Port State For Paper_out Function...........// //Create PrnStateSpooler Thread cyg_thread_create(PrnStateSpooler_TASK_PRI, PrnStateSpooler, 0, "PrnStateSpooler", (void *) (PrnStateSpooler_Stack), PrnStateSpooler_TASK_STACK_SIZE, &PrnStateSpooler_TaskHdl, &PrnStateSpooler_Task); //Start PrnStateSpooler Thread cyg_thread_resume(PrnStateSpooler_TaskHdl); }
static void master(cyg_addrword_t param) { int i; cyg_handle_t self = cyg_thread_self(); cyg_semaphore_init( &send_sema, 0 ); cyg_semaphore_init( &recv_sema, 0 ); for ( i = 0 ; i < NLISTENERS; i++ ) cyg_semaphore_init( &listen_sema[i], 0 ); init_all_network_interfaces(); CYG_TEST_INFO("Start multiple loopback select test"); #if NLOOP > 0 // We are currently running at high prio, so we can just go and make // loads of threads: // Some at higher prio for ( i = 0; i < NLISTENERS/2; i++ ) cyg_thread_create(PRIO_LISTENER_HI, // Priority listener, // entry i, // entry parameter "listener", // Name &stack_listener[i][0], // Stack STACK_SIZE, // Size &listener_thread_handle[i], // Handle &listener_thread_data[i] // Thread data structure ); // the rest at lower prio for ( ; i < NLISTENERS ; i++ ) cyg_thread_create(PRIO_LISTENER_LO, // Priority listener, // entry i, // entry parameter "listener", // Name &stack_listener[i][0], // Stack STACK_SIZE, // Size &listener_thread_handle[i], // Handle &listener_thread_data[i] // Thread data structure ); // make the dummy event-grabber threads for ( i = 0; i < NDUMMIES; i++ ) cyg_thread_create(PRIO_DUMMY, // Priority dummy, // entry i, // entry parameter "dummy", // Name &stack_dummy[i][0], // Stack STACK_SIZE, // Size &dummy_thread_handle[i], // Handle &dummy_thread_data[i] // Thread data structure ); // Start those threads for ( i = 0; i < NLISTENERS; i++ ) cyg_thread_resume(listener_thread_handle[i]); for ( i = 0; i < NDUMMIES; i++ ) cyg_thread_resume( dummy_thread_handle[i]); // and let them start up and start listening... cyg_thread_set_priority( self, PRIO_MASTERLOW ); CYG_TEST_INFO("All listeners should be go now"); cyg_thread_set_priority( self, PRIO_MASTERHIGH ); for ( i = 0; i < NSENDERS; i++ ) { cyg_thread_create( (0 == i) ?PRIO_SENDER_MID : PRIO_SENDER_LOW, // Priority sender, // entry i, // entry parameter "sender", // Name &stack_sender[i][0], // Stack STACK_SIZE, // Size &sender_thread_handle[i], // Handle &sender_thread_data[i] // Thread data structure ); cyg_thread_resume(sender_thread_handle[i]); } // Now we are still higher priority; so go low and let everyone else // have their head. When we next run after this, it should all be // over. cyg_thread_set_priority( self, PRIO_MASTERLOW ); cyg_semaphore_peek( &recv_sema, &i ); CYG_TEST_CHECK( NLISTENERS == i, "Not enough recvs occurred!" ); cyg_semaphore_peek( &send_sema, &i ); CYG_TEST_CHECK( NLISTENERS == i, "Not enough sends occurred!" ); CYG_TEST_PASS_FINISH("Master returned OK"); #endif CYG_TEST_NA( "No loopback devs" ); }
void dhcp_init(cyg_addrword_t arg) { uint no_timeout = 1; int need_LinkLocal = 1; while( Network_TCPIP_ON == 0 ) ppause(100); //ZOTIPS dhcp_start(WLanface); dhcp_start(Lanface); //ZOTIPS ppause(2000); if ( !strcmp(EEPROM_Data.WLESSID, "") || !strcmp(EEPROM_Data.WLESSID, "< ANY >")) dhcp_serch(45); // original:25. Jesse modified this at build0006 of 716U2W on April 28, 2011. else dhcp_serch(45); // original:13. Jesse modified this at build0006 of 716U2W on April 28, 2011. while(1) { cyg_semaphore_init( &dhcp_sem, 0); no_timeout = 1; #ifdef LINKLOCAL_IP // Ron Add 11/28/04 if ( (mib_DHCP_p->IPAddr == 0x0) && need_LinkLocal ) //ZOTIPS Give_ip_by_myself(WLanface); Give_ip_by_myself(Lanface); //ZOTIPS else { if(EEPROM_Data.RENVEnable == 1) { if( rendezvous_TaskHdl == 0) cyg_semaphore_post( &rendezvous_sem); else Need_Rendezous_Reload = 1; } } #else if( mib_DHCP_p->IPAddr == 0x0 ) set_factory_ip(); #endif if( (mib_DHCP_p->IPAddr == 0x0 ) || ((NGET32(EEPROM_Data.BoxIPAddress) & 0x0000FFFF)==0x0000FEA9) ) no_timeout = cyg_semaphore_timed_wait( &dhcp_sem, cyg_current_time() + 90000); else cyg_semaphore_wait( &dhcp_sem); if( no_timeout == 0 ) need_LinkLocal = 0; else need_LinkLocal = 1; erase_netif_ipaddr(); delete_dhcp_time(); ppause(500); dhcp_serch(10); // original:3. Jesse modified this at build0006 of 716U2W on April 28, 2011. } }
void LinkLocal_ip_Task(cyg_addrword_t arg) { int prob_conut, retry_count; uint32 LinkLocalIP; int get_conflict; //get arp reply to conflict our IP LinkLocal_set_state( NO_USE ); while(1){ cyg_semaphore_init(&linklocal_sem, 0); cyg_semaphore_wait(&linklocal_sem); init_LinkLocal(); if(rendezvous_TaskHdl != 0) { cyg_thread_suspend(rendezvous_TaskHdl); } prob_conut = 0; retry_count = 0; while(1){ switch( LinkLocal_get_current_state() ){ case PROBE: //ZOTIPS LinkLocalIP = SetLinkLocalIP(WLanface, 0 ); LinkLocalIP = SetLinkLocalIP(Lanface, 0 ); //ZOTIPS break; case RETRY: //ZOTIPS LinkLocalIP = SetLinkLocalIP(WLanface, 1 ); LinkLocalIP = SetLinkLocalIP(Lanface, 1 ); //ZOTIPS break; case ANNOUNCE: //ZOTIPS LinkLocalIP = SetLinkLocalIP(WLanface, 0 ); //ZOTIPS set_netif_ip(WLanface); LinkLocalIP = SetLinkLocalIP(Lanface, 0 ); //ZOTIPS set_netif_ip(Lanface); //ZOTIPS break; } //ZOTIPS LinkLocal_IP_Query(LinkLocalIP, WLanface); LinkLocal_IP_Query(LinkLocalIP, Lanface); //ZOTIPS get_conflict = cyg_semaphore_timed_wait(&linklocal_conflict, cyg_current_time() +(900/MSPTICK)); switch( LinkLocal_get_current_state() ){ case PROBE: if( get_conflict ) { LinkLocal_set_state( RETRY ); ppause(1000); } else prob_conut++; if( prob_conut == 3) { ppause(900); LinkLocal_set_state( ANNOUNCE ); } break; case RETRY: if( get_conflict ) { retry_count++; } else{ LinkLocal_set_state( PROBE ); prob_conut = 1; } ppause(1000); if( retry_count == 15) { ppause(900); LinkLocal_set_state( ANNOUNCE ); } break; case ANNOUNCE: if(get_conflict) ppause(1000); //ZOTIPS LinkLocal_IP_Query(LinkLocalIP, WLanface); LinkLocal_IP_Query(LinkLocalIP, Lanface); //ZOTIPS WriteToEEPROM(&EEPROM_Data); LinkLocal_set_state( IDLE ); break; } if( LinkLocal_get_current_state() == IDLE) break; } if( rendezvous_TaskHdl == 0) cyg_semaphore_post( &rendezvous_sem); else { cyg_thread_resume(rendezvous_TaskHdl); Need_Rendezous_Reload = 1; } cyg_semaphore_post(&DhcpWaitLinklocal_sem); } }
/** * Main thread of the Particle Filter Object Tracker Application. * SW Threads for creating & starting the particle filter, receiving hw measurements * and receiving a new frame are instanciated and started * * @param argc: number of parameters (here: not needed) * @param argv: parameter array (here: not needed) */ int main(int argc, char *argv[]) { #ifdef STORE_VIDEO framecounter = 0; #endif diag_printf( "-------------------------------------------------------\n" "PARTICLE FILTER OBJECT TRACKER\n" "(" __FILE__ ")\n" "Compiled on " __DATE__ ", " __TIME__ ".\n" "-------------------------------------------------------\n\n" ); /*diag_printf( "initializing ECAP interface..." ); ecap_init(); diag_printf( "done\n" );*/ // create sw thread for particle filter /*cyg_thread_create(PRIO, // scheduling info (eg pri) main_function, // entry point function 0, // entry data "SW_MAIN_THREAD", // optional thread name sw_thread_stack, // stack base STACK_SIZE, // stack size, &sw_thread_handle, // returned thread handle &sw_thread // put thread here ); // resume thread cyg_thread_resume(sw_thread_handle);*/ pthread_attr_init(&main_thread_attr); pthread_attr_setstacksize(&main_thread_attr, STACK_SIZE); pthread_create(&main_thread, &main_thread_attr, main_function, 0); //main_function(0); // create and start resources for read_new_frame sw thread // create semaphores sem_read_new_frame_start = (cyg_sem_t *) malloc (sizeof(cyg_sem_t)); sem_read_new_frame_stop = (cyg_sem_t *) malloc (sizeof(cyg_sem_t)); // init semaphores cyg_semaphore_init(sem_read_new_frame_start, 0); cyg_semaphore_init(sem_read_new_frame_stop, 0); // create sw thread for particle filter cyg_thread_create(PRIO+1, // scheduling info (eg pri) read_new_frame, // entry point function 0, // entry data "READ_NEW_FRAME_THREAD", // optional thread name sw_thread_read_new_frame_stack, // stack base STACK_SIZE, // stack size, &sw_thread_read_new_frame_handle, // returned thread handle &sw_thread_read_new_frame // put thread here ); // resume thread cyg_thread_resume(sw_thread_read_new_frame_handle); /*// create sw for measurement cyg_thread_create(PRIO, // scheduling info (eg pri) read_measurement, // entry point function 0, // entry data "READ_MEASUREMENTS", // optional thread name sw_measurement_thread_stack, // stack base STACK_SIZE, // stack size, &sw_measurement_thread_handle, // returned thread handle &sw_measurement_thread // put thread here ); // resume thread cyg_thread_resume(sw_measurement_thread_handle); // create sw for measurement (2nd thread) cyg_thread_create(PRIO, // scheduling info (eg pri) read_measurement_2, // entry point function 0, // entry data "READ_MEASUREMENTS_2", // optional thread name sw_measurement_thread_2_stack, // stack base STACK_SIZE, // stack size, &sw_measurement_thread_2_handle, // returned thread handle &sw_measurement_thread_2 // put thread here ); // resume thread cyg_thread_resume(sw_measurement_thread_2_handle); */ // create sw for measurement (3rd thread) /*cyg_thread_create(PRIO, // scheduling info (eg pri) read_measurement_3, // entry point function 0, // entry data "READ_MEASUREMENTS_3", // optional thread name sw_measurement_thread_3_stack, // stack base STACK_SIZE, // stack size, &sw_measurement_thread_3_handle, // returned thread handle &sw_measurement_thread_3 // put thread here ); // resume thread cyg_thread_resume(sw_measurement_thread_3_handle); // create sw for measurement (4th thread) cyg_thread_create(PRIO, // scheduling info (eg pri) read_measurement_4, // entry point function 0, // entry data "READ_MEASUREMENTS_4", // optional thread name sw_measurement_thread_4_stack, // stack base STACK_SIZE, // stack size, &sw_measurement_thread_4_handle, // returned thread handle &sw_measurement_thread_4 // put thread here ); // resume thread cyg_thread_resume(sw_measurement_thread_4_handle); */ /* /////////////////// TODO REMOVE create_particle_filter(100, 10); //hw_thread_s_swattr1 = (pthread_attr_t *) malloc (sizeof(pthread_attr_t)); //hw_thread_s_hwattr1 = (rthread_attr_t *) malloc (sizeof(rthread_attr_t)); // set ressources res_s1 = (reconos_res_t *) malloc (3 * sizeof(reconos_res_t)); res_s1[0].ptr = mb_sampling_handle; res_s1[0].type = CYG_MBOX_HANDLE_T; res_s1[1].ptr = mb_sampling_done_handle; res_s1[1].type = CYG_MBOX_HANDLE_T; res_s1[2].ptr = hw_mb_sampling_measurement_handle; res_s1[2].type = CYG_MBOX_HANDLE_T; int * parameter_s1 = (int *) malloc (5 * sizeof(int)); parameter_s1[0] = SIZE_X; parameter_s1[1] = SIZE_Y; parameter_s1[2] = 16384; // GRANULARITY / TRANS_STD_X parameter_s1[3] = 8192; // GRANULARITY / TRANS_STD_Y parameter_s1[4] = 16; // GRANULARITY / TRANS_STD_S // set information information_s1 = (information_struct_s1 *) malloc (sizeof(information_struct_s1)); // set information information_s1[0].particles = particles; information_s1[0].number_of_particles = N; information_s1[0].particle_size = sizeof(particle); information_s1[0].max_number_of_particles = 8096 / sizeof(particle); information_s1[0].block_size = block_size; // parameter information_s1[0].parameter = parameter_s1; information_s1[0].number_of_parameter = 5; int ret = pthread_attr_init(&hw_thread_s_swattr1); diag_printf("\np_thread_attr_init = %d", ret); ret = pthread_attr_setstacksize(&hw_thread_s_swattr1, STACK_SIZE); diag_printf("\np_thread_attr_set_stacksize = %d", ret); ret = rthread_attr_init(&hw_thread_s_hwattr1); diag_printf("\nr_thread_attr_init = %d", ret); ret = rthread_attr_setcircuit(&hw_thread_s_hwattr1, &hw_thread_s_circuit1); diag_printf("\nr_thread_set_circuit = %d", ret); //rthread_attr_setstatesize(&hw_thread_s_hwattr1, 16384); ret = rthread_attr_setresources(&hw_thread_s_hwattr1, res_s1, 3); //diag_printf("\nr_thread_attr_setresources = %d", ret); ret = rthread_create(&hw_thread_s1, &hw_thread_s_swattr1, &hw_thread_s_hwattr1, (void*)information_s1); diag_printf("\nr_thread_create = %d", ret); /////////////////// TODO END */ return 0; }
// ------------------------------------------------------------------------ // Wait for an event with timeout // tsleep(event, priority, state, timeout) // event - the thing to wait for // priority - unused // state - a descriptive message // timeout - max time (in ticks) to wait // returns: // 0 - event was "signalled" // ETIMEDOUT - timeout occurred // EINTR - thread broken out of sleep // int cyg_tsleep(void *chan, int pri, char *wmesg, int timo) { int i, res = 0; struct wakeup_event *ev; cyg_tick_count_t sleep_time; cyg_handle_t self = cyg_thread_self(); int old_splflags = 0; // no flags held cyg_scheduler_lock(); // Safely find a free slot: for (i = 0, ev = wakeup_list; i < CYGPKG_NET_NUM_WAKEUP_EVENTS; i++, ev++) { if (ev->chan == 0) { ev->chan = chan; break; } } CYG_ASSERT( i < CYGPKG_NET_NUM_WAKEUP_EVENTS, "no sleep slots" ); CYG_ASSERT( 1 == cyg_scheduler_read_lock(), "Tsleep - called with scheduler locked" ); // Defensive: if ( i >= CYGPKG_NET_NUM_WAKEUP_EVENTS ) { cyg_scheduler_unlock(); return ETIMEDOUT; } // If we are the owner, then we must release the mutex when // we wait. if ( self == splx_thread ) { old_splflags = spl_state; // Keep them for restoration CYG_ASSERT( spl_state, "spl_state not set" ); // Also want to assert that the mutex is locked... CYG_ASSERT( splx_mutex.locked, "Splx mutex not locked" ); CYG_ASSERT( (cyg_handle_t)splx_mutex.owner == self, "Splx mutex not mine" ); splx_thread = 0; spl_state = 0; cyg_mutex_unlock( &splx_mutex ); } // Re-initialize the semaphore - it might have counted up arbitrarily // in the time between a prior sleeper being signalled and them // actually running. cyg_semaphore_init(&ev->sem, 0); // This part actually does the wait: // As of the new kernel, we can do this without unlocking the scheduler if (timo) { sleep_time = cyg_current_time() + timo; if (!cyg_semaphore_timed_wait(&ev->sem, sleep_time)) { if( cyg_current_time() >= sleep_time ) res = ETIMEDOUT; else res = EINTR; } } else { if (!cyg_semaphore_wait(&ev->sem) ) { res = EINTR; } } ev->chan = 0; // Free the slot - the wakeup call cannot do this. if ( old_splflags ) { // restore to previous state // As of the new kernel, we can do this with the scheduler locked cyg_mutex_lock( &splx_mutex ); // this might wait CYG_ASSERT( 0 == splx_thread, "Splx thread set in tsleep" ); CYG_ASSERT( 0 == spl_state, "spl_state set in tsleep" ); splx_thread = self; // got it now... spl_state = old_splflags; } cyg_scheduler_unlock(); return res; }