element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Avnet Boards Forums
  • Products
  • Dev Tools
  • Avnet Boards Community
  • Avnet Boards Forums
  • More
  • Cancel
Avnet Boards Forums
Software Application Development Perl sound script
  • Forum
  • Documents
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Avnet Boards Forums to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Not Answered
  • Replies 2 replies
  • Subscribers 315 subscribers
  • Views 234 views
  • Users 0 members are here
Related

Perl sound script

Former Member
Former Member over 12 years ago

I've just messed up my sound script /usr/local/bin/zedboard_sound_setup.pl in xilinux and now sound don't work anymore (i didn't saved a copy of the original). Can someone send me that script?

  • Sign in to reply
  • Cancel
  • Former Member
    0 Former Member over 12 years ago

    The indentations are lost, but it should run fine.

    #!/usr/bin/perl
    use warnings;
    use strict;

    my $smbus = '/dev/xillybus_smb';
    my $readaddr = 0x71;
    my $writeaddr = 0x70;

    if (fork() == 0) { # Sleep and feed the wait() call
      sleep 2;
      exit 0;
    }

    my $pid = fork();

    if ($pid) {
      # Poor man's timeout:

      if ( wait() != $pid) { # Our sleeper died first
        kill(9, $pid);
        die("Failed to program the sound chip (timeout)
    ");
      }
      exit 0;
    }

    write_i2c(0x4000, 0x00); # Core clock off, hence PLL off

    # Settings for 25 MHz -> 49.152 MHz
    write_i2c(0x4002, 0x0c, 0x35, 0x0b, 0x61, 0x1b, 0x01);

    while (1) {
      my @vals = read_i2c(0x4002, 6);
      last if ($vals[5] & 2); # PLL is locked

      print "Waiting for sound chip's PLL to lock...
    ";
    }

    # Kick off the PLL
    write_i2c(0x4000, 0x0f);

    write_i2c(0x40f9, 0xff, 0x03); # Enable all clock generators

    write_i2c(0x4015, 0x01); # Device is serial port master, Zynq is slave

    write_i2c(0x400a, 0x0b, 0x08); # Left: LINN (mic) unmuted, 0dB gain, no boost
    write_i2c(0x400c, 0x0b, 0x08); # Left: RINN (mic) unmuted, 0dB gain, no boost

    #write_i2c(0x400a, 0x01, 0x05); # Left: LAUX (line in) unmuted, 0dB gain
    #write_i2c(0x400c, 0x01, 0x05); # Left: RAUX (line in) unmuted, 0dB gain

    write_i2c(0x400e, 0x42, 0x42); # Pre-gain 0dB, unmuted, single-ended

    write_i2c(0x4010,0x09); # Mic bias on, 0.9 x AVDD, high performance

    write_i2c(0x4019,0x43); # ADC control: On, inverted analog input

    write_i2c(0x401c, 0x2d, 0x00); # Mixer 3 on left DAC, 0 dB, no rec loopback
    write_i2c(0x401e, 0x4d, 0x00); # Mixer 4 on right DAC, 0 dB, no rec loopback

    write_i2c(0x4020, 0x05, 0x11); # Mixers 5, 6 for line out, 0 dB

    write_i2c(0x4023, 0xe7, 0xe7); # Headphone left and right enabled, 0 dB gain

    write_i2c(0x4025, 0xe6, 0xe6); # Line out left and right enabled, 0 dB gain

    write_i2c(0x4029, 0x03, 0x03); # Playback enable on both channels

    write_i2c(0x40f5, 0x01); # Enable the DSP

    write_i2c(0x40f6, 0x00); # Don't run the DSP

    write_i2c(0x40f2, 0x01, 0x01); # Routing Matrix: Bypass DSP

    exit 0;

    ################################################################

    sub write_i2c {
      my ($addr, @bytes) = @_;

      open(WH, ">$smbus") or
        die("Failed to open $smbus for write
    ");

      print WH  pack("C*", $writeaddr, ($addr >> 8) & 0xff ,$addr & 0xff,
    tt @bytes);

      close WH;

      return;

      # This code is never reached. Remove the "return" statement above to
      # activate readback. Note that it's normal to get a warning on address
      # 0x4007, since the PLL lock bit can go high quick enough.

      my @readback = read_i2c($addr, scalar @bytes);

      for (my $i=0; $i<scalar @bytes; $i++) {
        warn(sprintf("Address 0x%04x: Wrote 0x%02x, read back 0x%02x
    ",
    tt $addr + $i, $bytes[$i], $readback[$i]))
          if ($bytes[$i] != $readback[$i]);
      }

    }

    sub read_i2c {
      my ($addr, $numbytes) = @_;

      open(WH, ">$smbus") or
        die("Failed to open $smbus for write
    ");

      open(RH, "<$smbus") or
        die("Failed to open $smbus for read
    ");

      print WH  pack("C*", $writeaddr, ($addr >> 8) & 0xff ,$addr & 0xff);

      close WH; # This induces a stop condition on the bus

      open(WH, ">$smbus") or
        die("Failed to REopen $smbus for write (???)
    ");

      # Push any character $numbytes times to roll the state machine for read
      print WH  pack("C*", $readaddr).('X'x$numbytes);

      close WH;

      my $data = "";

      my $rc = read RH, $data, $numbytes;

      close RH;

      die("Read failed: $!
    ") unless (defined $rc);

      die("Received too little data ($rc bytes instead of $numbytes)
    ")
        if ($rc != $numbytes);

      die("Weird bug
    ")
        unless (length($data) == $rc);

      return unpack("C*", $data);

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 12 years ago

    Great! Thanks for helping.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube