#include <perl.h>
#include <XSUB.h>
#include <assert.h>
+#include <string.h>
#include <trbnet.h>
+#include <trberror.h>
+
+static size_t BUFFER_SIZE = 4194304;
+static U32 buffer[4194304];
/* file : TrbNet.xs */
MODULE = HADES::TrbNet PACKAGE = HADES::TrbNet
PROTOTYPES: ENABLE
+
+SV*
+trb_errnum()
+ CODE:
+ RETVAL = newSViv(trb_errno);
+ OUTPUT:
+ RETVAL
+
+void
+trb_err()
+ CODE:
+ trb_error("trb_error");
+
+
+SV*
+trb_errStr()
+ CODE:
+ RETVAL = newSVpv(trb_strerror(), 0);
+ OUTPUT:
+ RETVAL
+
int
init_ports()
-
+ INIT:
+ int status;
+ PPCODE:
+ status = init_ports();
+ if (status < 0) {
+ XSRETURN_UNDEF;
+ } else {
+ XPUSHs(sv_2mortal(newSVuv(1)));
+ }
+
void
-trb_uid(trb_address)
+trb_rr(trb_address, reg_address)
+ U16 trb_address
+ U16 reg_address
+ INIT:
+ int status;
+ int i;
+
+ PPCODE:
+ status = trb_register_read(trb_address,reg_address, buffer, 2);
+ if (status <= 0) {
+ XSRETURN_UNDEF;
+
+ }
+ XPUSHs(sv_2mortal(newSVuv(buffer[1])));
+
+void
+trb_ra(trb_address, reg_address)
+ U16 trb_address;
+ U16 reg_address;
+ INIT:
+ int status;
+ int i;
+
+ PPCODE:
+ status = trb_register_read(trb_address,reg_address, buffer, BUFFER_SIZE);
+ if (status <= 0) {
+ XSRETURN_UNDEF;
+ }
+ for (i = 0 ; i < status; i++) {
+ XPUSHs(sv_2mortal(newSVuv(buffer[i])));
+ }
+
+void
+trb_wr(trb_address, reg_address, value)
+ U16 trb_address
+ U16 reg_address
+ U32 value
+ INIT:
+ int status;
+ int i;
+
+ PPCODE:
+ status = trb_register_write(trb_address,reg_address, value);
+ if (i != -1) {
+ XSRETURN_UNDEF;
+ }
+ XPUSHs(sv_2mortal(newSVuv(buffer[1])));
+
+void
+trb_uid_c(trb_address)
U16 trb_address
INIT:
- static U32 buf2[1024 * 4];
int status;
int i;
PPCODE:
i = 0;
- status = trb_read_uid(trb_address, (U32 *)&buf2, 1024 * 4);
+ status = trb_read_uid(trb_address, buffer, BUFFER_SIZE);
if (status <= 0) {
XSRETURN_UNDEF;
- return;
}
for (i = 0 ; i < status; i++) {
- XPUSHs(sv_2mortal(newSVnv(buf2[i])));
+ XPUSHs(sv_2mortal(newSVuv(buffer[i])));
}
+
+
+
+SV*
+trb_hash_c()
+ INIT:
+ HV * rh;
+ CODE:
+
+
+ rh = (HV *)sv_2mortal((SV *)newHV());
+ hv_store(rh, "newSVuv", 10, newSVuv(100), 0);
+ hv_store(rh, "duda", 10, newSVuv(200), 0);
+ hv_store(rh, "halloaa", 6, newSVnv(100), 0);
+ hv_store(rh, "dudads", 4, newSVnv(200), 0);
+ hv_store(rh, "hallosd", 6, newSVnv(100), 0);
+ hv_store(rh, "dudadsa", 4, newSVnv(200), 0);
+ hv_store(rh, "halloads", 6, newSVnv(100), 0);
+ hv_store(rh, "dudadwa", 4, newSVnv(200), 0);
+
+ RETVAL = newRV((HV *)rh);
+ OUTPUT:
+ RETVAL
use 5.010000;
use strict;
use warnings;
+use Data::Dumper;
require Exporter;
# If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
# will save memory.
our %EXPORT_TAGS = ( 'all' => [ qw(
+ trb_errnum
+ trb_err
+ trb_errStr
init_ports
+ trb_rr
+ trb_ra
+ trb_wr
trb_uid
+ trb_hash
) ] );
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
our @EXPORT = qw(
-
+trb_uid init_ports trb_err trb_errnum trb_hash
);
our $VERSION = '0.01';
# Preloaded methods go here.
+
+sub trb_hash {
+ my ($trb_address, $register_address) = @_;
+ my @a = trb_ra($trb_address, $register_address);
+ my %h;
+ #print Dumper %h;
+ %h = @a;
+ return \%h;
+
+}
+
+sub trb_uid {
+ my ($trb_address) = @_;
+ my @res = trb_uid_c($trb_address);
+
+ my $rh;
+
+ for (my $k = 0; $k < scalar @res; $k += 4) {
+ my $uid = ($res[$k] << 32) | $res[$k + 1];
+ my $endP = $res[$k + 2];
+ my $sender = $res[$k + 3];
+
+ $rh->{$uid}->{'trb_addr'} = $sender;
+ $rh->{$uid}->{'trb_endpoint_nr'} = $endP;
+ }
+
+ #my %h;
+ #print Dumper %h;
+ #%h = @a;
+ return $rh;
+
+}
+
+
+
1;
__END__
# Below is stub documentation for your module. You'd better edit it!
#!/usr/bin/perl
use warnings;
use strict;
- use HADES::TrbNet qw(trb_rr trb_wr init_ports);
+ use HADES::TrbNet qw(trb_rr trb_wr init_ports trb_strerror);
my $connect_status = &init_ports();
my @res; my $res;
use Data::Dumper;
#use Data::HexDump;
-use HADES::TrbNet qw(trb_uid init_ports);
+use HADES::TrbNet; # qw(trb_uid init_ports trb_err trb_errnum trb_hash);
-my $connect_status = init_ports();
+init_ports() or die "Failed init_ports: ", trb_errStr();
-my @res = trb_uid(0xffff);
+my @a = ();
+my $rh_hash;
+foreach (1..1) {
+ $rh_hash = trb_hash(0xffff, 0x0);
+ push @a, $rh_hash;
+}
+#print Dumper $rh_hash;
+foreach my $cur_key (keys %$rh_hash) {
+# printf "addr: 0x%04x: 0x%08x\n", $cur_key, $rh_hash->{$cur_key};
+}
+
+#print %$rh_hash;
+
+#exit 0;
-#print Dumper \@res;
-for (my $k = 0; $k < scalar @res; $k += 4) {
- my $uid = ($res[$k] << 32) | $res[$k + 1];
- my $endP = $res[$k + 2];
- my $sender = $res[$k + 3];
- printf "0x%04x 0x%016x 0x%02x\n", $sender, $uid , $endP;
+
+my $res = trb_uid(0xfffb);
+foreach my $cur_key (sort {$a <=> $b } keys %$res) {
+ printf "uid: 0x%016x ==> addr: 0x%08x: endpoint: 0x%02x\n", $cur_key,
+ $res->{$cur_key}->{'trb_addr'}, $res->{$cur_key}->{'trb_endpoint_nr'} ;
}
+
+
+#print Dumper $res;
+exit;
+