====== Example using low-level API ====== The following example demonstrates how a flink device can be opened and a subdevice selected. The subdevice is of type ''GPIO''. One of it's channels is configured as output and set to ''true''. #include #include #include #include #include #include int main(void) { char* DEFAULT_DEV = (char*)"/dev/flink0"; flink_dev* dev; flink_subdev* subdev; char* dev_name = DEFAULT_DEV; uint32_t subdevice_id = 0x12705002; uint32_t channel = 0; int error = 0; // Open flink device dev = flink_open(DEFAULT_DEV); if(dev == NULL) { fprintf(stderr, "Failed to open device %s!\n", dev_name); return -1; } // Get a pointer to the choosen subdevice subdev = flink_get_subdevice_by_unique_id(dev, subdevice_id ); if(subdev == NULL) { fprintf(stderr, "Illegal subdevice id %d!\n", subdevice_id); return -1; } // Set I/O direction to output uint8_t out = true; uint32_t offset = HEADER_SIZE + SUBHEADER_SIZE + (channel / (REGISTER_WITH * 8)) * REGISTER_WITH; uint8_t bit = channel % (REGISTER_WITH * 8); if(flink_write_bit(subdev, offset, bit, &out)) { fprintf(stderr, "Configuring GPIO direction failed!\n"); return -1; } // toggle an output for 20s offset = HEADER_SIZE + SUBHEADER_SIZE + ((subdev->nof_channels - 1) / (REGISTER_WITH * 8) + 1) * REGISTER_WITH + (channel / (REGISTER_WITH * 8)) * REGISTER_WITH; bit = channel % (REGISTER_WITH * 8); out = 1; for (int count = 0; count < 200; count++) { if(flink_write_bit(subdev, offset, bit, &out)) { fprintf(stderr, "Writing GPIO value failed!\n"); return -1; } usleep(100000); out = !out; } // Close flink device flink_close(dev); return EXIT_SUCCESS; }