// bus reset handler, update bus generation int my_bus_reset_handler(raw1394handle_t h, unsigned int gen) { nodeid_t id = raw1394_get_local_id(h); std::cout << "Reset bus to gen " << gen << " local id " << id << std::endl; // update handle gen value raw1394_update_generation(h, gen); }
void FirewirePort::StopCycleStartPacket(void) { // IMPORTANT: Disable Cycle Start Packet, no isochronous int rc = 0; // return code quadlet_t data_stop_cmc = bswap_32(0x100); rc = raw1394_write(handle, raw1394_get_local_id(handle), CSR_REGISTER_BASE + CSR_STATE_CLEAR, 4, &data_stop_cmc); if (rc) { outStr << "*****Error: can NOT disable cycle start packet" << std::endl; } else { outStr << "FirewirePort: successfully disabled cycle start packet" << std::endl; } }
int SlaveDevice::init_config_rom(raw1394handle_t handle) { int retval, i; quadlet_t rom[0x100]; size_t rom_size; unsigned char rom_version; rom1394_directory dir; char *leaf; /* get the current rom image */ retval=raw1394_get_config_rom(handle, rom, 0x100, &rom_size, &rom_version); rom_size = rom1394_get_size(rom); // printf("get_config_rom returned %d, romsize %d, rom_version %d:",retval,rom_size,rom_version); // for (i = 0; i < rom_size; i++) // { // if (i % 4 == 0) printf("\n0x%04x:", CSR_CONFIG_ROM+i*4); // printf(" %08x", CondSwapFromBus32(rom[i])); // } // printf("\n"); /* get the local directory */ rom1394_get_directory( handle, raw1394_get_local_id(handle) & 0x3f, &dir); /* change the vendor description for kicks */ i = strlen(dir.textual_leafs[0]); strncpy(dir.textual_leafs[0], FFADO_BOUNCE_SERVER_VENDORNAME " ", i); dir.vendor_id=FFADO_BOUNCE_SERVER_VENDORID; dir.model_id=FFADO_BOUNCE_SERVER_MODELID; /* update the rom */ retval = rom1394_set_directory(rom, &dir); // printf("rom1394_set_directory returned %d, romsize %d:",retval,rom_size); // for (i = 0; i < rom_size; i++) // { // if (i % 4 == 0) printf("\n0x%04x:", CSR_CONFIG_ROM+i*4); // printf(" %08x", CondSwapFromBus32(rom[i])); // } // printf("\n"); /* free the allocated mem for the textual leaves */ rom1394_free_directory( &dir); /* add an AV/C unit directory */ dir.unit_spec_id = FFADO_BOUNCE_SERVER_SPECID; dir.unit_sw_version = 0x00010001; leaf = (char*)FFADO_BOUNCE_SERVER_MODELNAME; dir.nr_textual_leafs = 1; dir.textual_leafs = &leaf; /* manipulate the rom */ retval = rom1394_add_unit( rom, &dir); /* get the computed size of the rom image */ rom_size = rom1394_get_size(rom); // printf("rom1394_add_unit_directory returned %d, romsize %d:",retval,rom_size); // for (i = 0; i < rom_size; i++) // { // if (i % 4 == 0) printf("\n0x%04x:", CSR_CONFIG_ROM+i*4); // printf(" %08x", CondSwapFromBus32(rom[i])); // } // printf("\n"); // /* convert computed rom size from quadlets to bytes before update */ rom_size *= sizeof(quadlet_t); retval = raw1394_update_config_rom(handle, rom, rom_size, rom_version); // printf("update_config_rom returned %d\n",retval); retval=raw1394_get_config_rom(handle, rom, 0x100, &rom_size, &rom_version); // printf("get_config_rom returned %d, romsize %d, rom_version %d:",retval,rom_size,rom_version); // for (i = 0; i < rom_size; i++) // { // if (i % 4 == 0) printf("\n0x%04x:", CSR_CONFIG_ROM+i*4); // printf(" %08x", CondSwapFromBus32(rom[i])); // } // printf("\n"); // printf("You need to reload your ieee1394 modules to reset the rom.\n"); return 0; }
bool FirewirePort::ScanNodes(void) { int node, board; // loop counters // Clear any existing Node2Board memset(Node2Board, BoardIO::MAX_BOARDS, sizeof(Node2Board)); // Get base node id (zero out 6 lsb) baseNodeId = raw1394_get_local_id(handle) & 0xFFC0; outStr << "ScanNodes: base node id = " << std::hex << baseNodeId << std::endl; // iterate through all the nodes and find out their boardId int numNodes = raw1394_get_nodecount(handle); NumOfNodes_ = numNodes - 1; outStr << "ScanNodes: building node map for " << numNodes << " nodes:" << std::endl; IsAllBoardsBroadcastCapable_ = true; // Iterate through all connected nodes (except for last one, which is the PC). for (node = 0; node < numNodes-1; node++){ quadlet_t data; if (raw1394_read(handle, baseNodeId+node, 4, 4, &data)) { outStr << "ScanNodes: unable to read from node " << node << std::endl; return false; } data = bswap_32(data); if ((data != 0xC0FFEE) && (data != QLA1_String)) { outStr << "Node " << node << " is not a QLA board" << std::endl; continue; } // Now, read firmware version unsigned long fver = 0; if (data == QLA1_String) { if (raw1394_read(handle, baseNodeId+node, 7, 4, &data)) { outStr << "ScanNodes: unable to read firmware version from node " << node << std::endl; return false; } data = bswap_32(data); fver = data; } if (raw1394_read(handle, baseNodeId+node, 0, 4, &data)) { outStr << "ScanNodes: unable to read status from node " << node << std::endl; return false; } data = bswap_32(data); // board_id is bits 27-24, BOARD_ID_MASK = 0x0f000000 board = (data & BOARD_ID_MASK) >> 24; outStr << " Node " << node << ", BoardId = " << board << ", Firmware Version = " << fver << std::endl; if (Node2Board[node] < BoardIO::MAX_BOARDS) outStr << " Duplicate entry, previous value = " << static_cast<int>(Node2Board[node]) << std::endl; Node2Board[node] = board; FirmwareVersion[board] = fver; // check firmware version // FirmwareVersion >= 4, broadcast capable if (fver < 4) IsAllBoardsBroadcastCapable_ = false; } // Use broadcast by default if all firmware are bc capable if (IsAllBoardsBroadcastCapable_) { Protocol_ = FirewirePort::PROTOCOL_SEQ_R_BC_W; outStr << "ScanNodes: all nodes broadcast capable" << std::endl; } // update Board2Node for (board = 0; board < BoardIO::MAX_BOARDS; board++) { Board2Node[board] = MAX_NODES; for (node = 0; node < numNodes-1; node++) { if (Node2Board[node] == board) { if (Board2Node[board] < MAX_NODES) outStr << "Warning: GetNodeId detected duplicate board id for " << board << std::endl; Board2Node[board] = node; } } } return true; }
int main(int argc, char **argv) { raw1394handle_t handle; int retval; quadlet_t rom[0x100]; size_t rom_size; unsigned char rom_version; rom1394_directory dir; char *(leaf[2]); handle = raw1394_new_handle(); if (!handle) { if (!errno) { printf(not_compatible); } else { perror("couldn't get handle"); printf(not_loaded); } exit(EXIT_FAILURE); } if (raw1394_set_port(handle, 0) < 0) { perror("couldn't set port"); exit(EXIT_FAILURE); } /* get the current rom image */ retval=raw1394_get_config_rom(handle, rom, 0x100, &rom_size, &rom_version); rom_size = rom1394_get_size(rom); printf("get_config_rom returned %d, romsize %d, rom_version %d:",retval,rom_size,rom_version); /* get the local directory */ rom1394_get_directory( handle, raw1394_get_local_id(handle) & 0x3f, &dir); /* free the allocated mem for the textual leaves */ rom1394_free_directory( &dir); /* add an RFC 2734 unit directory */ dir.unit_spec_id = 0x0000005e; dir.unit_sw_version = 0x00000001; leaf[0] = "IANA"; leaf[1] = "IPv4"; dir.nr_textual_leafs = 2; dir.textual_leafs = leaf; /* manipulate the rom */ retval = rom1394_add_unit( rom, &dir); /* get the computed size of the rom image */ rom_size = rom1394_get_size(rom); printf("rom1394_add_unit_directory returned %d, romsize %d:",retval,rom_size); /* convert computed rom size from quadlets to bytes before update */ rom_size *= sizeof(quadlet_t); retval = raw1394_update_config_rom(handle, rom, rom_size, rom_version); printf("update_config_rom returned %d\n",retval); printf("You need to reload your ieee1394 modules to reset the rom.\n"); raw1394_reset_bus(handle); exit(EXIT_SUCCESS); }
int main(int argc, char** argv) { int rc; /**< return code */ int port = 0; /*!< fw handle port number */ // parse command line (port number) opterr = 0; // getopt no err output const char short_options[] = "p:"; int next_opt; do { next_opt = getopt(argc, argv, short_options); switch(next_opt) { case 'p': port = atoi(optarg); break; case '?': std::cerr << "Invalid argument" << std::endl; break; default: break; } } while(next_opt != -1); // Setup signal handler to exit on Ctrl-C signal(SIGINT, signal_handler); // ----- Get handle and set port for the handle ------- // create handle handle = raw1394_new_handle(); if (handle == NULL) { std::cerr << "**** Error: could not create 1394 handle " << strerror(errno) << std::endl; return EXIT_FAILURE; } // get port number & sanity check int numPorts = raw1394_get_port_info(handle, NULL, 0); if (port < 0 || port >= numPorts) { std::cerr << "Invalid port number" << std::endl; return EXIT_FAILURE; } // let user to choose which port to use rc = raw1394_set_port(handle, 0); if (rc) { std::cerr << "**** Error: failed to set port " << strerror(errno) << std::endl; return EXIT_FAILURE; } // -------- Set FireWire bus reset handler -------- // set bus reset handler bus_reset_handler_t old_bus_reset_handler; old_bus_reset_handler = raw1394_set_bus_reset_handler(handle, my_bus_reset_handler); // ---------------------------------------------------------------------------- // Start tutorial 2 arm server // ---------------------------------------------------------------------------- // -------- Register arm register to handle arm request -------- const nodeaddr_t arm_start_addr = 0xffffff000000; // arm start address const size_t arm_length = 4; // arm length to register // arm initial buffer byte_t arm_init_buffer[arm_length]; memset(arm_init_buffer, 0x02, arm_length); // set inital value to all 0x02 // setup arm request handle raw1394_arm_reqhandle arm_reqhandle; char my_arm_callback_context[] = "my_arm_callback_context"; arm_reqhandle.pcontext = my_arm_callback_context; arm_reqhandle.arm_callback = my_arm_req_callback; int access_mode = RAW1394_ARM_WRITE|RAW1394_ARM_READ; // allow read and write transaction rc = raw1394_arm_register(handle, // fw handle arm_start_addr, // arm start address arm_length * 4, // arm_length quadlet * 4 to bytes arm_init_buffer, // arm init buffer value (octlet_t) &arm_reqhandle, // arm request handler access_mode, // access permission access_mode, // client handler will be notified 0); // client handler will need to handle these transactions if (rc) { std::cerr << "**** Error: failed to setup arm register, error " << strerror(errno) << std::endl; return EXIT_FAILURE; } // -------- Read from this arm buffer --------- // NOTE: this is a simple way to test if const size_t arm_read_size = 4; byte_t arm_read_buffer[arm_read_size]; rc = raw1394_arm_get_buf(handle, arm_start_addr, arm_read_size, arm_read_buffer); if (rc) { std::cerr << "**** Error: failed to read arm register, error " << strerror(errno) << std::endl; return EXIT_FAILURE; } else { // if success then print value std::cout << "ARM buffer read value: \n"; for (size_t i = 0; i < arm_read_size; i++) { std::cout << std::hex << " " << (int)arm_read_buffer[i]; } std::cout << std::endl; } // -------- Set value to this arm buffer --------- const size_t arm_write_size = 4; byte_t arm_write_buffer[arm_write_size] = {0x11, 0x22, 0x33, 0x44}; rc = raw1394_arm_set_buf(handle, arm_start_addr, arm_write_size, arm_write_buffer); if (rc) { std::cerr << "**** Error: failed to set arm register, error " << strerror(errno) << std::endl; return EXIT_FAILURE; } // --------- Now read the value back from buffer ------ rc = raw1394_arm_get_buf(handle, arm_start_addr, arm_read_size, arm_read_buffer); if (rc) { std::cerr << "**** Error: failed to read arm register, error " << strerror(errno) << std::endl; return EXIT_FAILURE; } else { // if success then print value std::cout << "ARM buffer read value: \n"; for (size_t i = 0; i < arm_read_size; i++) { std::cout << std::hex << " " << (int)arm_read_buffer[i]; } std::cout << std::endl; } // --------- Infinite raw1394 event loop ---------- std::cout << "--------- Now start arm server -----------" << std::endl; std::cout << " node id = " << raw1394_get_local_id(handle) << std::endl; while (true) { raw1394_loop_iterate(handle); } // clean up & exit raw1394_destroy_handle(handle); return EXIT_SUCCESS; }
static gboolean gst_hdv1394src_start (GstBaseSrc * bsrc) { GstHDV1394Src *src = GST_HDV1394SRC (bsrc); int control_sock[2]; src->connected = FALSE; if (socketpair (PF_UNIX, SOCK_STREAM, 0, control_sock) < 0) goto socket_pair; READ_SOCKET (src) = control_sock[0]; WRITE_SOCKET (src) = control_sock[1]; if (fcntl (READ_SOCKET (src), F_SETFL, O_NONBLOCK) < 0) GST_ERROR_OBJECT (src, "failed to make read socket non-blocking: %s", g_strerror (errno)); if (fcntl (WRITE_SOCKET (src), F_SETFL, O_NONBLOCK) < 0) GST_ERROR_OBJECT (src, "failed to make write socket non-blocking: %s", g_strerror (errno)); src->handle = raw1394_new_handle (); if (!src->handle) { if (errno == EACCES) goto permission_denied; else if (errno == ENOENT) goto not_found; else goto no_handle; } src->num_ports = raw1394_get_port_info (src->handle, src->pinfo, 16); if (src->num_ports == 0) goto no_ports; if (src->use_avc || src->port == -1) src->avc_node = gst_hdv1394src_discover_avc_node (src); /* lets destroy handle and create one on port this is more reliable than setting port on the existing handle */ raw1394_destroy_handle (src->handle); src->handle = raw1394_new_handle_on_port (src->port); if (!src->handle) goto cannot_set_port; raw1394_set_userdata (src->handle, src); raw1394_set_bus_reset_handler (src->handle, gst_hdv1394src_bus_reset); { nodeid_t m_node = (src->avc_node | 0xffc0); int m_channel = -1; int m_bandwidth = 0; int m_outputPort = -1; int m_inputPort = -1; m_channel = iec61883_cmp_connect (src->handle, m_node, &m_outputPort, raw1394_get_local_id (src->handle), &m_inputPort, &m_bandwidth); if (m_channel >= 0) { src->channel = m_channel; } } if ((src->iec61883mpeg2 = iec61883_mpeg2_recv_init (src->handle, gst_hdv1394src_iec61883_receive, src)) == NULL) goto cannot_initialise_dv; #if 0 raw1394_set_iso_handler (src->handle, src->channel, gst_hdv1394src_iso_receive); #endif GST_DEBUG_OBJECT (src, "successfully opened up 1394 connection"); src->connected = TRUE; if (iec61883_mpeg2_recv_start (src->iec61883mpeg2, src->channel) != 0) goto cannot_start; #if 0 if (raw1394_start_iso_rcv (src->handle, src->channel) < 0) goto cannot_start; #endif if (src->use_avc) { raw1394handle_t avc_handle = raw1394_new_handle_on_port (src->port); GST_LOG ("We have an avc_handle"); /* start the VCR */ if (avc_handle) { if (!avc1394_vcr_is_recording (avc_handle, src->avc_node) && avc1394_vcr_is_playing (avc_handle, src->avc_node) != AVC1394_VCR_OPERAND_PLAY_FORWARD) { GST_LOG ("Calling avc1394_vcr_play()"); avc1394_vcr_play (avc_handle, src->avc_node); } raw1394_destroy_handle (avc_handle); } else { GST_WARNING_OBJECT (src, "Starting VCR via avc1394 failed: %s", g_strerror (errno)); } } return TRUE; socket_pair: { GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ_WRITE, (NULL), GST_ERROR_SYSTEM); return FALSE; } permission_denied: { GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ, (NULL), GST_ERROR_SYSTEM); return FALSE; } not_found: { GST_ELEMENT_ERROR (src, RESOURCE, NOT_FOUND, (NULL), GST_ERROR_SYSTEM); return FALSE; } no_handle: { GST_ELEMENT_ERROR (src, RESOURCE, OPEN_READ, (NULL), ("can't get raw1394 handle (%s)", g_strerror (errno))); return FALSE; } no_ports: { raw1394_destroy_handle (src->handle); src->handle = NULL; GST_ELEMENT_ERROR (src, RESOURCE, NOT_FOUND, (NULL), ("no ports available for raw1394")); return FALSE; } cannot_set_port: { GST_ELEMENT_ERROR (src, RESOURCE, SETTINGS, (NULL), ("can't set 1394 port %d", src->port)); return FALSE; } cannot_start: { raw1394_destroy_handle (src->handle); src->handle = NULL; iec61883_mpeg2_close (src->iec61883mpeg2); src->iec61883mpeg2 = NULL; GST_ELEMENT_ERROR (src, RESOURCE, READ, (NULL), ("can't start 1394 iso receive")); return FALSE; } cannot_initialise_dv: { raw1394_destroy_handle (src->handle); src->handle = NULL; GST_ELEMENT_ERROR (src, RESOURCE, READ, (NULL), ("can't initialise iec61883 hdv")); return FALSE; } }
int iec61883_cip_fill_header(raw1394handle_t handle, struct iec61883_cip *ptz, struct iec61883_packet *packet) { struct iec61883_fraction next; int nevents, nevents_dbc, syt_index, syt; fraction_add(&next, &ptz->ready_samples, &ptz->samples_per_cycle); if (ptz->mode == IEC61883_MODE_BLOCKING_EMPTY || ptz->mode == IEC61883_MODE_BLOCKING_NODATA) { if (fraction_floor(&next) >= ptz->syt_interval) nevents = ptz->syt_interval; else nevents = 0; } else nevents = fraction_floor(&next); if (ptz->mode == IEC61883_MODE_BLOCKING_NODATA) { /* The DBC is incremented even with NO_DATA packets. */ nevents_dbc = ptz->syt_interval; } else { nevents_dbc = nevents; } /* Now that we know how many events to put in the packet, update the * fraction ready_samples. */ fraction_sub_int(&ptz->ready_samples, &next, nevents); /* Calculate synchronization timestamp (syt). First we * determine syt_index, that is, the index in the packet of * the sample for which the timestamp is valid. */ syt_index = (ptz->syt_interval - ptz->dbc) & (ptz->syt_interval - 1); if (syt_index < nevents) { syt = ((ptz->cycle_count << 12) | fraction_floor(&ptz->cycle_offset)) & 0xffff; fraction_add(&ptz->cycle_offset, &ptz->cycle_offset, &ptz->ticks_per_syt_offset); /* The cycle_count field is a 13 bits value that goes from 0 to 7999. * The cycle_offset field is a 12 bits value that goes from 0 to 3071. */ ptz->cycle_count += ptz->cycle_offset.integer / 3072; ptz->cycle_count %= 8000; ptz->cycle_offset.integer %= 3072; } else syt = 0xffff; packet->eoh0 = 0; /* Our node ID can change after a bus reset, so it is best to fetch * our node ID for each packet. */ packet->sid = raw1394_get_local_id( handle ) & 0x3f; packet->dbs = ptz->dbs; packet->fn = 0; packet->qpc = 0; packet->sph = 0; packet->reserved = 0; packet->dbc = ptz->dbc; packet->eoh1 = 2; packet->fmt = ptz->format; if ( nevents == 0 && ptz->mode == IEC61883_MODE_BLOCKING_NODATA ) { /* FDF code for packets containing dummy data. */ packet->fdf = IEC61883_FDF_NODATA; } else { /* FDF code for non-blocking mode and for blocking mode with empty packets. */ packet->fdf = ptz->fdf; } packet->syt = htons(syt); ptz->dbc += nevents_dbc; return nevents; }