URL
https://opencores.org/ocsvn/sockit_owm/sockit_owm/trunk
Subversion Repositories sockit_owm
Compare Revisions
- This comparison shows the changes necessary to convert path
/
- from Rev 1 to Rev 2
- ↔ Reverse comparison
Rev 1 → Rev 2
/sockit_owm/trunk/onewire.odg
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
sockit_owm/trunk/onewire.odg
Property changes :
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: sockit_owm/trunk/gtkwave.sav
===================================================================
--- sockit_owm/trunk/gtkwave.sav (nonexistent)
+++ sockit_owm/trunk/gtkwave.sav (revision 2)
@@ -0,0 +1,84 @@
+[timestart] 0
+[size] 1366 693
+[pos] -1 -1
+*-29.164242 2197250000 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
+[treeopen] onewire_tb.
+[treeopen] onewire_tb.onewire_slave.
+@200
+-System signals
+@28
+onewire_tb.clk
+onewire_tb.rst
+@800200
+-Avalon MM bus
+@28
+onewire_tb.avalon_write
+@22
+onewire_tb.avalon_writedata[31:0]
+@28
+onewire_tb.avalon_read
+@22
+onewire_tb.avalon_readdata[31:0]
+@28
+onewire_tb.avalon_interrupt
+@1000200
+-Avalon MM bus
+@800200
+-1-wire master
+@28
+onewire_tb.onewire_master.irq_etx
+onewire_tb.onewire_master.irq_erx
+onewire_tb.onewire_master.irq_stx
+onewire_tb.onewire_master.irq_srx
+@22
+onewire_tb.onewire_master.div[4:0]
+@28
+onewire_tb.onewire_master.pls
+@24
+onewire_tb.onewire_master.cnt[6:0]
+@28
+onewire_tb.onewire_master.owr_trn
+onewire_tb.onewire_master.owr_drx
+onewire_tb.onewire_master.owr_dtx
+onewire_tb.onewire_master.owr_rst
+onewire_tb.onewire_master.owr_ovd
+onewire_tb.onewire_master.owr_pwr[2:0]
+onewire_tb.onewire_master.owr_sel[1:0]
+onewire_tb.onewire_master.owr_i
+onewire_tb.onewire_master.onewire_p[2:0]
+@c00028
+onewire_tb.onewire_master.onewire_e[2:0]
+@28
+(0)onewire_tb.onewire_master.onewire_e[2:0]
+(1)onewire_tb.onewire_master.onewire_e[2:0]
+(2)onewire_tb.onewire_master.onewire_e[2:0]
+@1401200
+-group_end
+@28
+onewire_tb.onewire_master.onewire_i[2:0]
+@1000200
+-1-wire master
+@800028
+onewire_tb.owr[2:0]
+@28
+(0)onewire_tb.owr[2:0]
+(1)onewire_tb.owr[2:0]
+@29
+(2)onewire_tb.owr[2:0]
+@1001200
+-group_end
+@800200
+-1-wire slave
+@820
+onewire_tb.onewire_slave.state[23:0]
+onewire_tb.onewire_slave.cycle[23:0]
+@22
+onewire_tb.onewire_slave.dtx[7:0]
+onewire_tb.onewire_slave.cnt[31:0]
+@28
+onewire_tb.onewire_slave.od
+onewire_tb.onewire_slave.pull
+onewire_tb.onewire_slave.sample
+onewire_tb.onewire_slave.reset
+@1000200
+-1-wire slave
Index: sockit_owm/trunk/onewire_tb.v
===================================================================
--- sockit_owm/trunk/onewire_tb.v (nonexistent)
+++ sockit_owm/trunk/onewire_tb.v (revision 2)
@@ -0,0 +1,231 @@
+//////////////////////////////////////////////////////////////////////////////
+// //
+// Minimalistic 1-wire (onewire) master with Avalon MM bus interface //
+// testbench //
+// //
+// Copyright (C) 2010 Iztok Jeras //
+// //
+//////////////////////////////////////////////////////////////////////////////
+// //
+// This RTL is free hardware: you can redistribute it and/or modify //
+// it under the terms of the GNU Lesser General Public License //
+// as published by the Free Software Foundation, either //
+// version 3 of the License, or (at your option) any later version. //
+// //
+// This RTL is distributed in the hope that it will be useful, //
+// but WITHOUT ANY WARRANTY; without even the implied warranty of //
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
+// GNU General Public License for more details. //
+// //
+// You should have received a copy of the GNU General Public License //
+// along with this program. If not, see . //
+// //
+//////////////////////////////////////////////////////////////////////////////
+
+`timescale 1ns / 1ps
+
+module onewire_tb;
+
+// system clock parameters
+localparam real FRQ = 4_000_000; // 24MHz // realistic option
+localparam real CP = 1*(10**9)/FRQ; // clock period
+
+localparam MTP_N = 7500; // divider number normal mode
+localparam MTP_O = 750; // divider number overdrive mode
+
+localparam CDR_N = MTP_N / CP; // divider number normal mode
+localparam CDR_O = MTP_O / CP; // divider number overdrive mode
+
+// onewire parameters
+localparam OWN = 3; // number of ports
+
+// Avalon MM parameters
+localparam AAW = 1; // address width
+localparam ADW = 32; // data width
+localparam ABW = ADW/8; // byte enable width
+
+// system_signals
+reg clk; // clock
+reg rst; // reset (asynchronous)
+// Avalon MM interface
+reg avalon_read;
+reg avalon_write;
+reg [AAW-1:0] avalon_address;
+reg [ABW-1:0] avalon_byteenable;
+reg [ADW-1:0] avalon_writedata;
+wire [ADW-1:0] avalon_readdata;
+wire avalon_waitrequest;
+wire avalon_interrupt;
+
+// Avalon MM local signals
+wire avalon_transfer;
+reg [ADW-1:0] data;
+
+// onewire
+wire [OWN-1:0] owr; // bidirectional
+wire [OWN-1:0] owr_p; // output power enable from master
+wire [OWN-1:0] owr_e; // output pull down enable from master
+wire [OWN-1:0] owr_i; // input into master
+
+// request for a dumpfile
+initial begin
+ $dumpfile("onewire.vcd");
+ $dumpvars(0, onewire_tb);
+end
+
+//////////////////////////////////////////////////////////////////////////////
+// clock and reset
+//////////////////////////////////////////////////////////////////////////////
+
+// clock generation
+initial clk = 1'b1;
+always #(CP/2) clk = ~clk;
+
+// reset generation
+initial begin
+ rst = 1'b1;
+ repeat (2) @(posedge clk);
+ rst = 1'b0;
+end
+
+//////////////////////////////////////////////////////////////////////////////
+// Avalon write and read transfers
+//////////////////////////////////////////////////////////////////////////////
+
+initial begin
+ // Avalon MM interface is idle
+ avalon_read = 1'b0;
+ avalon_write = 1'b0;
+
+ // long delay to skip presence pulse
+ #1000_000;
+
+ // generate a reset pulse
+ avalon_cycle (1, 0, 4'hf, 32'b00000010, data);
+ avalon_pulling (8);
+ // write '0'
+ avalon_cycle (1, 0, 4'hf, 32'b00000000, data);
+ avalon_pulling (8);
+ // write '1'
+ avalon_cycle (1, 0, 4'hf, 32'b00000001, data);
+ avalon_pulling (8);
+
+ // switch to overdrive mode
+
+ // generate a reset pulse
+ avalon_cycle (1, 0, 4'hf, 32'b00000110, data);
+ avalon_pulling (8);
+ // write '0'
+ avalon_cycle (1, 0, 4'hf, 32'b00000100, data);
+ avalon_pulling (8);
+ // write '1'
+ avalon_cycle (1, 0, 4'hf, 32'b00000101, data);
+ avalon_pulling (8);
+
+ // test power supply
+
+ // generate a delay pulse with power supply enabled
+ avalon_cycle (1, 0, 4'hf, 32'h00010003, data);
+ avalon_pulling (8);
+
+ // test breaking a delay sequence with an idle transfer
+
+ // generate a delay pulse and break it, before it finishes
+ repeat (10) @(posedge clk);
+ avalon_cycle (1, 0, 4'hf, 32'h00000003, data);
+ repeat (10) @(posedge clk);
+ avalon_cycle (1, 0, 4'hf, 32'h00000007, data);
+
+ // wait a few cycles and finish
+ repeat (10) @(posedge clk);
+ $finish();
+end
+
+// wait for the onewire cycle completion
+task avalon_pulling (input integer d);
+begin
+ data = 32'h02;
+ while (data & 32'h02) begin
+ repeat (d) @ (posedge clk);
+ avalon_cycle (0, 0, 4'hf, 32'hxxxx_xxxx, data);
+ end
+end endtask
+
+//////////////////////////////////////////////////////////////////////////////
+// Avalon transfer cycle generation task
+//////////////////////////////////////////////////////////////////////////////
+
+task automatic avalon_cycle (
+ input r_w, // 0-read or 1-write cycle
+ input [AAW-1:0] adr,
+ input [ABW-1:0] ben,
+ input [ADW-1:0] wdt,
+ output [ADW-1:0] rdt
+);
+begin
+ $display ("Avalon MM cycle start: T=%10tns, %s address=%08x byteenable=%04b writedata=%08x", $time/1000.0, r_w?"write":"read ", adr, ben, wdt);
+ // start an Avalon cycle
+ avalon_read <= ~r_w;
+ avalon_write <= r_w;
+ avalon_address <= adr;
+ avalon_byteenable <= ben;
+ avalon_writedata <= wdt;
+ // wait for waitrequest to be retracted
+ @ (posedge clk); while (~avalon_transfer) @ (posedge clk);
+ // end Avalon cycle
+ avalon_read <= 1'b0;
+ avalon_write <= 1'b0;
+ // read data
+ rdt = avalon_readdata;
+ $display ("Avalon MM cycle end : T=%10tns, readdata=%08x", $time/1000.0, rdt);
+end
+endtask
+
+// avalon cycle transfer cycle end status
+assign avalon_transfer = (avalon_read | avalon_write) & ~avalon_waitrequest;
+
+assign avalon_waitrequest = 1'b0;
+
+//////////////////////////////////////////////////////////////////////////////
+// RTL instance
+//////////////////////////////////////////////////////////////////////////////
+
+sockit_owm #(
+ .CDR_N (CDR_N),
+ .CDR_O (CDR_O),
+ .OWN (OWN)
+) onewire_master (
+ // system
+ .clk (clk),
+ .rst (rst),
+ // Avalon
+ .bus_read (avalon_read),
+ .bus_write (avalon_write),
+ .bus_writedata (avalon_writedata),
+ .bus_readdata (avalon_readdata),
+ .bus_interrupt (avalon_interrupt),
+ // onewire
+ .onewire_p (owr_p),
+ .onewire_e (owr_e),
+ .onewire_i (owr_i)
+);
+
+// onewire
+pullup onewire_pullup [OWN-1:0] (owr);
+
+genvar i;
+generate for (i=0; i . //
+// //
+//////////////////////////////////////////////////////////////////////////////
+
+
+//////////////////////////////////////////////////////////////////////////////
+// //
+// The clock divider parameter is computed with the next formula: //
+// //
+// CDR_N = f_CLK * BTP_N (example: CDR_N = 2MHz * 7.5us = 15) //
+// CDR_O = f_CLK * BTP_O (example: CDR_O = 2MHz * 1.0us = 2) //
+// //
+// If the dividing factor is not a round integer, than the timing of the //
+// controller will be slightly off, and would support only a subset of //
+// 1-wire devices with timing closer to the typical 30us slot. //
+// //
+// Base time periods BTP_N = "7.5" and BTP_O = "1.0" are optimized for //
+// logic consumption and optimal onewire timing. //
+// Since the default timing might shrink the range of available frequences //
+// to multiples of 2MHz, a less restrictive timing is offered, //
+// BTP_N = "5.0" and BTP_O = "1.0", this limits the frequency to multiples //
+// of 1MHz. //
+// If even this restrictions are too strict use timing BTP_N = "6.0" and //
+// BTP_O = "0.5", where the actual periods can be in the range: //
+// 6.0us <= BTP_N <= 7.5us //
+// 0.5us <= BTP_O <= 0.66us //
+// //
+//////////////////////////////////////////////////////////////////////////////
+
+module sockit_owm #(
+ // interface parameters
+ parameter BDW = 32, // bus data width
+ parameter OWN = 1, // number of 1-wire ports
+ // implementation of overdrive enable
+ parameter OVD_E = 1, // overdrive functionality is implemented by default
+ // clock divider ratios (defaults are for a 2MHz clock)
+ parameter CDR_N = 15, // normal mode
+ parameter CDR_O = 2, // overdrive mode
+ // base time period
+ parameter BTP_N = "7.5", // normal mode (7.5us, options are "7.5", "5.0" and "6.0")
+ parameter BTP_O = "1.0", // overdrive mode (1.0us, options are "1.0", and "0.5")
+ // normal mode timing
+ parameter T_RSTH_N = (BTP_N == "7.5") ? 64 : (BTP_N == "5.0") ? 96 : 80, // reset high
+ parameter T_RSTL_N = (BTP_N == "7.5") ? 64 : (BTP_N == "5.0") ? 96 : 80, // reset low
+ parameter T_RSTP_N = (BTP_N == "7.5") ? 10 : (BTP_N == "5.0") ? 15 : 10, // reset presence pulse
+ parameter T_DAT0_N = (BTP_N == "7.5") ? 8 : (BTP_N == "5.0") ? 12 : 10, // bit 0 low
+ parameter T_DAT1_N = (BTP_N == "7.5") ? 1 : (BTP_N == "5.0") ? 1 : 1, // bit 1 low
+ parameter T_BITS_N = (BTP_N == "7.5") ? 2 : (BTP_N == "5.0") ? 3 : 2, // bit sample
+ parameter T_RCVR_N = (BTP_N == "7.5") ? 1 : (BTP_N == "5.0") ? 1 : 1, // recovery
+ parameter T_IDLE_N = (BTP_N == "7.5") ? 64 : (BTP_N == "5.0") ? 104 : 1, // recovery
+ // overdrive mode timing
+ parameter T_RSTH_O = (BTP_N == "1.0") ? 48 : 96, // reset high
+ parameter T_RSTL_O = (BTP_N == "1.0") ? 48 : 96, // reset low
+ parameter T_RSTP_O = (BTP_N == "1.0") ? 10 : 15, // reset presence pulse
+ parameter T_DAT0_O = (BTP_N == "1.0") ? 6 : 12, // bit 0 low
+ parameter T_DAT1_O = (BTP_N == "1.0") ? 1 : 2, // bit 1 low
+ parameter T_BITS_O = (BTP_N == "1.0") ? 2 : 3, // bit sample
+ parameter T_RCVR_O = (BTP_N == "1.0") ? 1 : 2, // recovery
+ parameter T_IDLE_O = (BTP_N == "1.0") ? 48 : 96 // recovery
+)(
+ // system signals
+ input clk,
+ input rst,
+ // bus interface
+ input bus_read,
+ input bus_write,
+ input [BDW-1:0] bus_writedata,
+ output [BDW-1:0] bus_readdata,
+ output bus_interrupt,
+ // onewire
+ output [OWN-1:0] onewire_p, // output power enable
+ output [OWN-1:0] onewire_e, // output pull down enable
+ input [OWN-1:0] onewire_i // input from bidirectional wire
+);
+
+//////////////////////////////////////////////////////////////////////////////
+// local parameters
+//////////////////////////////////////////////////////////////////////////////
+
+// size of boudrate generator counter (divider for normal mode is largest)
+localparam CDW = $clog2(CDR_N);
+
+// size of port select signal
+localparam SDW = $clog2(OWN);
+
+// size of cycle timing counter
+localparam TDW = (T_RSTH_O+T_RSTL_O) > (T_RSTH_N+T_RSTL_N)
+ ? $clog2(T_RSTH_O+T_RSTL_O) : $clog2(T_RSTH_N+T_RSTL_N);
+
+//////////////////////////////////////////////////////////////////////////////
+// local signals
+//////////////////////////////////////////////////////////////////////////////
+
+// clock divider
+//generate if (CDR>1) begin : div_declaration
+reg [CDW-1:0] div;
+//end endgenerate
+wire pls;
+
+// transfer control
+reg owr_trn; // transfer status
+reg [TDW-1:0] cnt; // transfer counter
+
+// port select
+//generate if (OWN>1) begin : sel_declaration
+reg [SDW-1:0] owr_sel;
+//end endgenerate
+
+// onewire signals
+reg [OWN-1:0] owr_pwr; // power
+reg owr_ovd; // overdrive
+reg owr_rst; // reset
+reg owr_dtx; // data bit transmit
+reg owr_drx; // data bit receive
+
+wire owr_p; // output
+reg owr_oen; // output enable
+wire owr_i; // input
+
+// interrupt signals
+reg irq_etx; // interrupt enable transmit
+reg irq_erx; // interrupt enable receive
+reg irq_stx; // interrupt status transmit
+reg irq_srx; // interrupt status receive
+
+// timing signals
+wire [TDW-1:0] t_idl ; // idle cycle time
+wire [TDW-1:0] t_rst ; // reset cycle time
+wire [TDW-1:0] t_bit ; // data bit transfer cycle time
+wire [TDW-1:0] t_rstp; // reset presence pulse sampling time
+wire [TDW-1:0] t_rsth; // reset release time
+wire [TDW-1:0] t_dat0; // data bit 0 release time
+wire [TDW-1:0] t_dat1; // data bit 1 release time
+wire [TDW-1:0] t_bits; // data bit transfer sampling time
+wire [TDW-1:0] t_zero; // end of cycle time
+
+//////////////////////////////////////////////////////////////////////////////
+// cycle timing
+//////////////////////////////////////////////////////////////////////////////
+
+// idle time
+assign t_idl = owr_ovd ? T_IDLE_O : T_IDLE_N ;
+// reset cycle time (reset low + reset hight)
+assign t_rst = owr_ovd ? T_RSTL_O + T_RSTH_O : T_RSTL_N + T_RSTH_N ;
+// data bit transfer cycle time (write 0 + recovery)
+assign t_bit = owr_ovd ? T_DAT0_O + + T_RCVR_N : T_DAT0_N + T_RCVR_O;
+
+// reset presence pulse sampling time (reset high - reset presence)
+assign t_rstp = owr_ovd ? T_RSTH_O - T_RSTP_O : T_RSTH_N - T_RSTP_N ;
+// reset release time (reset high)
+assign t_rsth = owr_ovd ? T_RSTH_O : T_RSTH_N ;
+
+// data bit 0 release time (write bit 0 - write bit 0 + recovery)
+assign t_dat0 = owr_ovd ? T_DAT0_O - T_DAT0_O + T_RCVR_O : T_DAT0_N - T_DAT0_N + T_RCVR_N;
+// data bit 1 release time (write bit 0 - write bit 1 + recovery)
+assign t_dat1 = owr_ovd ? T_DAT0_O - T_DAT1_O + T_RCVR_O : T_DAT0_N - T_DAT1_N + T_RCVR_N;
+// data bit transfer sampling time (write bit 0 - write bit 1 + recovery)
+assign t_bits = owr_ovd ? T_DAT0_O - T_BITS_O + T_RCVR_O : T_DAT0_N - T_BITS_N + T_RCVR_N;
+
+// end of cycle time
+assign t_zero = 'd0;
+
+//////////////////////////////////////////////////////////////////////////////
+// clock divider
+//////////////////////////////////////////////////////////////////////////////
+
+// clock division ratio depends on overdrive mode status,
+generate if ((CDR_N>1) | (CDR_O>1)) begin : div_implementation
+ // clock divider
+ always @ (posedge clk, posedge rst)
+ if (rst) div <= 'd0;
+ else begin
+ if (bus_write) div <= 'd0;
+ else div <= pls ? 'd0 : div + owr_trn;
+ end
+ // divided clock pulse
+ assign pls = (div == (owr_ovd ? CDR_O : CDR_N) - 1);
+end else begin
+ // clock period is same as the onewire period
+ assign pls = 1'b1;
+end endgenerate
+
+//////////////////////////////////////////////////////////////////////////////
+// bus logic
+//////////////////////////////////////////////////////////////////////////////
+
+// bus read data
+generate if (OWN>1) begin : sel_readdata
+ assign bus_readdata = {{BDW-OWN-16{1'b0}}, owr_pwr, {8-SDW{1'b0}}, owr_sel,
+ irq_erx, irq_etx, irq_srx, irq_stx,
+ owr_i , owr_ovd, owr_trn, owr_drx};
+end else begin
+ assign bus_readdata = {irq_erx, irq_etx, irq_srx, irq_stx,
+ owr_i , owr_ovd, owr_trn, owr_drx};
+end endgenerate
+
+generate if (OWN>1) begin : sel_implementation
+ // port select
+ always @ (posedge clk, posedge rst)
+ if (rst) owr_sel <= {SDW{1'b0}};
+ else if (bus_write) owr_sel <= bus_writedata[8+:SDW];
+
+ // power delivery
+ always @ (posedge clk, posedge rst)
+ if (rst) owr_pwr <= {SDW{1'b0}};
+ else if (bus_write) owr_pwr <= bus_writedata[16+:SDW];
+end else begin
+ // port select
+ always @ (*) owr_sel <= {SDW{1'b0}};
+ // power delivery
+ always @ (posedge clk, posedge rst)
+ if (rst) owr_pwr <= 1'b0;
+ else if (bus_write) owr_pwr <= bus_writedata[3];
+end endgenerate
+
+// bus interrupt
+assign bus_interrupt = irq_erx & irq_srx
+ | irq_etx & irq_stx;
+
+// interrupt enable
+always @ (posedge clk, posedge rst)
+if (rst) {irq_erx, irq_etx} <= 2'b00;
+else if (bus_write) {irq_erx, irq_etx} <= bus_writedata[7:6];
+
+// transmit status (active after onewire transfer cycle ends)
+always @ (posedge clk, posedge rst)
+if (rst) irq_stx <= 1'b0;
+else begin
+ if (bus_write) irq_stx <= 1'b0;
+ else if (pls & (cnt == t_zero)) irq_stx <= 1'b1;
+ else if (bus_read) irq_stx <= 1'b0;
+end
+
+// receive status (active after wire sampling point inside the transfer cycle)
+always @ (posedge clk, posedge rst)
+if (rst) irq_srx <= 1'b0;
+else begin
+ if (bus_write) irq_srx <= 1'b0;
+ else if (pls) begin
+ if (cnt == t_rstp) irq_srx <= owr_rst & ~owr_dtx; // presence detect
+ else if (cnt == t_bits) irq_srx <= ~owr_rst & owr_dtx; // read data bit
+ end else if (bus_read) irq_srx <= 1'b0;
+end
+
+//////////////////////////////////////////////////////////////////////////////
+// onewire state machine
+//////////////////////////////////////////////////////////////////////////////
+
+// transmit data, reset, overdrive
+generate if (OVD_E) begin : ctrl_writedata
+ always @ (posedge clk, posedge rst)
+ if (rst) {owr_ovd, owr_rst, owr_dtx} <= 3'b000;
+ else if (bus_write) {owr_ovd, owr_rst, owr_dtx} <= bus_writedata[2:0];
+end else begin
+ always @ (posedge clk, posedge rst)
+ if (rst) {owr_ovd, owr_rst, owr_dtx} <= 3'b000;
+ else if (bus_write) { owr_rst, owr_dtx} <= bus_writedata[1:0];
+end endgenerate
+
+// onewire transfer status
+always @ (posedge clk, posedge rst)
+if (rst) owr_trn <= 1'b0;
+else begin
+ if (bus_write) owr_trn <= ~&bus_writedata[2:0];
+ else if (pls & (cnt == t_zero)) owr_trn <= 1'b0;
+end
+
+// state counter (initial value depends whether the cycle is reset or data)
+always @ (posedge clk, posedge rst)
+if (rst) cnt <= 0;
+else begin
+ if (bus_write) cnt <= (&bus_writedata[1:0] ? t_idl : bus_writedata[1] ? t_rst : t_bit) - 'd1;
+ else if (pls) cnt <= cnt - 'd1;
+end
+
+// receive data (sampling point depends whether the cycle is reset or data)
+always @ (posedge clk)
+if (pls) begin
+ if ( owr_rst & (cnt == t_rstp)) owr_drx <= owr_i; // presence detect
+ else if (~owr_rst & (cnt == t_bits)) owr_drx <= owr_i; // read data bit
+end
+
+// output register (switch point depends whether the cycle is reset or data)
+always @ (posedge clk, posedge rst)
+if (rst) owr_oen <= 1'b0;
+else begin
+ if (bus_write) owr_oen <= ~&bus_writedata[1:0];
+ else if (pls) begin
+ if (owr_rst & (cnt == t_rsth)) owr_oen <= 1'b0; // reset
+ else if (owr_dtx & (cnt == t_dat1)) owr_oen <= 1'b0; // write 1, read
+ else if ( (cnt == t_dat0)) owr_oen <= 1'b0; // write 0
+ end
+end
+
+//////////////////////////////////////////////////////////////////////////////
+// IO
+//////////////////////////////////////////////////////////////////////////////
+
+// only one 1-wire line cn be accessed at the same time
+assign onewire_e = owr_oen << owr_sel;
+// all 1-wire lines can be powered independently
+assign onewire_p = owr_pwr;
+
+// 1-wire line status read multiplexer
+assign owr_i = onewire_i [owr_sel];
+assign owr_p = onewire_p [owr_sel];
+
+endmodule
Index: sockit_owm/trunk/HAL/src/sockit_owm.c
===================================================================
--- sockit_owm/trunk/HAL/src/sockit_owm.c (nonexistent)
+++ sockit_owm/trunk/HAL/src/sockit_owm.c (revision 2)
@@ -0,0 +1,117 @@
+/******************************************************************************
+* *
+* License Agreement *
+* *
+* Copyright (c) 2008 Altera Corporation, San Jose, California, USA. *
+* All rights reserved. *
+* *
+* Permission is hereby granted, free of charge, to any person obtaining a *
+* copy of this software and associated documentation files (the "Software"), *
+* to deal in the Software without restriction, including without limitation *
+* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
+* and/or sell copies of the Software, and to permit persons to whom the *
+* Software is furnished to do so, subject to the following conditions: *
+* *
+* The above copyright notice and this permission notice shall be included in *
+* all copies or substantial portions of the Software. *
+* *
+* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
+* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
+* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
+* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
+* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *
+* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *
+* DEALINGS IN THE SOFTWARE. *
+* *
+* This agreement shall be governed in all respects by the laws of the State *
+* of California and by the laws of the United States of America. *
+* *
+******************************************************************************/
+
+
+//////////////////////////////////////////////////////////////////////////////
+// //
+// Minimalistic 1-wire (onewire) master with Avalon MM bus interface //
+// //
+// Copyright (C) 2010 Iztok Jeras //
+// //
+//////////////////////////////////////////////////////////////////////////////
+// //
+// This program is free software: you can redistribute it and/or modify //
+// it under the terms of the GNU Lesser General Public License //
+// as published by the Free Software Foundation, either //
+// version 3 of the License, or (at your option) any later version. //
+// //
+// This program is distributed in the hope that it will be useful, //
+// but WITHOUT ANY WARRANTY; without even the implied warranty of //
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
+// GNU General Public License for more details. //
+// //
+// You should have received a copy of the GNU General Public License //
+// along with this program. If not, see . //
+// //
+//////////////////////////////////////////////////////////////////////////////
+
+
+#include
+
+#include "sys/alt_dev.h"
+#include "sys/alt_irq.h"
+#include "sys/ioctl.h"
+#include "sys/alt_errno.h"
+
+#include "sockit_owm_regs.h"
+#include "sockit_owm.h"
+
+extern sockit_owm_state sockit_owm;
+
+#ifndef SOCKIT_OWM_POLLING
+
+//////////////////////////////////////////////////////////////////////////////
+// interrupt implementation
+//////////////////////////////////////////////////////////////////////////////
+
+#ifdef ALT_ENHANCED_INTERRUPT_API_PRESENT
+static void sockit_owm_irq ();
+#else
+static void sockit_owm_irq (alt_u32 id);
+#endif
+
+void sockit_owm_init (alt_u32 irq)
+{
+ int error;
+ // initialize semaphore for transfer locking
+ // TODO there is a warning to fix here
+ error = ALT_FLAG_CREATE (sockit_owm.irq, 0) ||
+ ALT_SEM_CREATE (sockit_owm.trn, 1);
+
+ if (!error) {
+ // enable TX interrupt, RX is unused
+ sockit_owm.ena = 0x1;
+ // register the interrupt handler
+#ifdef ALT_ENHANCED_INTERRUPT_API_PRESENT
+ alt_ic_isr_register (0, irq, sockit_owm_irq, NULL, 0x0);
+#else
+ alt_irq_register (irq, NULL, sockit_owm_irq);
+#endif
+ }
+}
+
+#ifdef ALT_ENHANCED_INTERRUPT_API_PRESENT
+static void sockit_owm_irq(void * state)
+#else
+static void sockit_owm_irq(void * state, alt_u32 id)
+#endif
+{
+ // clear onewire interrupts
+ IORD_SOCKIT_OWM (sockit_owm.base);
+ // set the flag indicating a completed transfer
+ ALT_FLAG_POST (sockit_owm.irq, 0x1, OS_FLAG_SET);
+}
+#else
+
+//////////////////////////////////////////////////////////////////////////////
+// polling implementation
+//////////////////////////////////////////////////////////////////////////////
+
+#endif
Index: sockit_owm/trunk/HAL/src/owerr.c
===================================================================
--- sockit_owm/trunk/HAL/src/owerr.c (nonexistent)
+++ sockit_owm/trunk/HAL/src/owerr.c (revision 2)
@@ -0,0 +1,348 @@
+//---------------------------------------------------------------------------
+// Copyright (C) 2000 Dallas Semiconductor Corporation, All Rights Reserved.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a
+// copy of this software and associated documentation files (the "Software"),
+// to deal in the Software without restriction, including without limitation
+// the rights to use, copy, modify, merge, publish, distribute, sublicense,
+// and/or sell copies of the Software, and to permit persons to whom the
+// Software is furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included
+// in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+// IN NO EVENT SHALL DALLAS SEMICONDUCTOR BE LIABLE FOR ANY CLAIM, DAMAGES
+// OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+// OTHER DEALINGS IN THE SOFTWARE.
+//
+// Except as contained in this notice, the name of Dallas Semiconductor
+// shall not be used except as stated in the Dallas Semiconductor
+// Branding Policy.
+//---------------------------------------------------------------------------
+//
+// owerr.c - Library functions for error handling with 1-Wire library
+//
+// Version: 1.00
+//
+
+#include
+#ifndef _WIN32_WCE
+#include
+#endif
+#ifdef _WIN64
+#include
+#endif
+#include "ownet.h"
+
+#ifndef SIZE_OWERROR_STACK
+ #ifdef SMALL_MEMORY_TARGET
+ //for small memory, only hole 1 error
+ #define SIZE_OWERROR_STACK 1
+ #else
+ #define SIZE_OWERROR_STACK 10
+ #endif
+#endif
+
+//---------------------------------------------------------------------------
+// Variables
+//---------------------------------------------------------------------------
+
+// Error Struct for holding error information.
+// In DEBUG, this will also hold the line number and filename.
+typedef struct
+{
+ int owErrorNum;
+#ifdef DEBUG
+ int lineno;
+ char *filename;
+#endif
+} owErrorStruct;
+
+// Ring-buffer used for stack.
+// In case of overflow, deepest error is over-written.
+static owErrorStruct owErrorStack[SIZE_OWERROR_STACK];
+
+// Stack pointer to top-most error.
+static int owErrorPointer = 0;
+
+
+//---------------------------------------------------------------------------
+// Functions Definitions
+//---------------------------------------------------------------------------
+int owGetErrorNum(void);
+void owClearError(void);
+int owHasErrors(void);
+#ifdef DEBUG
+ void owRaiseError(int,int,char*);
+#else
+ void owRaiseError(int);
+#endif
+#ifndef SMALL_MEMORY_TARGET
+ void owPrintErrorMsg(FILE *);
+ void owPrintErrorMsgStd();
+ char *owGetErrorMsg(int);
+#endif
+
+
+//--------------------------------------------------------------------------
+// The 'owGetErroNum' returns the error code of the top-most error on the
+// error stack. NOTE: This function has the side effect of popping the
+// current error off the stack. All successive calls to 'owGetErrorNum'
+// will further clear the error stack.
+//
+// For list of error codes, see 'ownet.h'
+//
+// Returns: int : The error code of the top-most error on the stack
+//
+int owGetErrorNum(void)
+{
+ int i = owErrorStack[ owErrorPointer ].owErrorNum;
+ owErrorStack[ owErrorPointer ].owErrorNum = 0;
+ if(!owErrorPointer)
+ owErrorPointer = SIZE_OWERROR_STACK - 1;
+ else
+ owErrorPointer = (owErrorPointer - 1);
+ return i;
+}
+
+//--------------------------------------------------------------------------
+// The 'owClearError' clears all the errors.
+//
+void owClearError(void)
+{
+ owErrorStack[ owErrorPointer ].owErrorNum = 0;
+}
+
+//--------------------------------------------------------------------------
+// The 'owHasErrors' is a boolean test function which tests whether or not
+// a valid error is waiting on the stack.
+//
+// Returns: TRUE (1) : When there are errors on the stack.
+// FALSE (0): When stack's errors are set to 0, or NO_ERROR_SET.
+//
+int owHasErrors(void)
+{
+ if(owErrorStack[ owErrorPointer ].owErrorNum)
+ return 1; //TRUE
+ else
+ return 0; //FALSE
+}
+
+#ifdef DEBUG
+ //--------------------------------------------------------------------------
+ // The 'owRaiseError' is the method for raising an error onto the error
+ // stack.
+ //
+ // Arguments: int err - the error code you wish to raise.
+ // int lineno - DEBUG only - the line number where it was raised
+ // char* filename - DEBUG only - the file name where it occured.
+ //
+ void owRaiseError(int err, int lineno, char* filename)
+ {
+ owErrorPointer = (owErrorPointer + 1) % SIZE_OWERROR_STACK;
+ owErrorStack[ owErrorPointer ].owErrorNum = err;
+ owErrorStack[ owErrorPointer ].lineno = lineno;
+ owErrorStack[ owErrorPointer ].filename = filename;
+ }
+#else
+ //--------------------------------------------------------------------------
+ // The 'owRaiseError' is the method for raising an error onto the error
+ // stack.
+ //
+ // Arguments: int err - the error code you wish to raise.
+ //
+ void owRaiseError(int err)
+ {
+ owErrorPointer = (owErrorPointer + 1) % SIZE_OWERROR_STACK;
+ owErrorStack[ owErrorPointer ].owErrorNum = err;
+ }
+#endif
+
+
+// SMALL_MEMORY_TARGET - embedded microcontrollers, where these
+// messaging functions might not make any sense.
+#ifndef SMALL_MEMORY_TARGET
+ //Array of meaningful error messages to associate with codes.
+ //Not used on targets with low memory (i.e. PIC).
+ static char *owErrorMsg[125] =
+ {
+ /*000*/ "No Error Was Set",
+ /*001*/ "No Devices found on 1-Wire Network",
+ /*002*/ "1-Wire Net Reset Failed",
+ /*003*/ "Search ROM Error: Couldn't locate next device on 1-Wire",
+ /*004*/ "Access Failed: Could not select device",
+ /*005*/ "DS2480B Adapter Not Detected",
+ /*006*/ "DS2480B: Wrong Baud",
+ /*007*/ "DS2480B: Bad Response",
+ /*008*/ "Open COM Failed",
+ /*009*/ "Write COM Failed",
+ /*010*/ "Read COM Failed",
+ /*011*/ "Data Block Too Large",
+ /*012*/ "Block Transfer failed",
+ /*013*/ "Program Pulse Failed",
+ /*014*/ "Program Byte Failed",
+ /*015*/ "Write Byte Failed",
+ /*016*/ "Read Byte Failed",
+ /*017*/ "Write Verify Failed",
+ /*018*/ "Read Verify Failed",
+ /*019*/ "Write Scratchpad Failed",
+ /*020*/ "Copy Scratchpad Failed",
+ /*021*/ "Incorrect CRC Length",
+ /*022*/ "CRC Failed",
+ /*023*/ "Failed to acquire a necessary system resource",
+ /*024*/ "Failed to initialize system resource",
+ /*025*/ "Data too long to fit on specified device.",
+ /*026*/ "Read exceeds memory bank end.",
+ /*027*/ "Write exceeds memory bank end.",
+ /*028*/ "Device select failed",
+ /*029*/ "Read Scratch Pad verify failed.",
+ /*030*/ "Copy scratchpad complete not found",
+ /*031*/ "Erase scratchpad complete not found",
+ /*032*/ "Address read back from scrachpad was incorrect",
+ /*033*/ "Read page with extra-info not supported by this memory bank",
+ /*034*/ "Read page packet with extra-info not supported by this memory bank",
+ /*035*/ "Length of packet requested exceeds page size",
+ /*036*/ "Invalid length in packet",
+ /*037*/ "Program pulse required but not available",
+ /*038*/ "Trying to access a read-only memory bank",
+ /*039*/ "Current bank is not general purpose memory",
+ /*040*/ "Read back from write compare is incorrect, page may be locked",
+ /*041*/ "Invalid page number for this memory bank",
+ /*042*/ "Read page with CRC not supported by this memory bank",
+ /*043*/ "Read page with CRC and extra-info not supported by this memory bank",
+ /*044*/ "Read back from write incorrect, could not lock page",
+ /*045*/ "Read back from write incorrect, could not lock redirect byte",
+ /*046*/ "The read of the status was not completed.",
+ /*047*/ "Page redirection not supported by this memory bank",
+ /*048*/ "Lock Page redirection not supported by this memory bank",
+ /*049*/ "Read back byte on EPROM programming did not match.",
+ /*050*/ "Can not write to a page that is locked.",
+ /*051*/ "Can not lock a redirected page that has already been locked.",
+ /*052*/ "Trying to redirect a locked redirected page.",
+ /*053*/ "Trying to lock a page that is already locked.",
+ /*054*/ "Trying to write to a memory bank that is write protected.",
+ /*055*/ "Error due to not matching MAC.",
+ /*056*/ "Memory Bank is write protected.",
+ /*057*/ "Secret is write protected, can not Load First Secret.",
+ /*058*/ "Error in Reading Scratchpad after Computing Next Secret.",
+ /*059*/ "Load Error from Loading First Secret.",
+ /*060*/ "Power delivery required but not available",
+ /*061*/ "Not a valid file name.",
+ /*062*/ "Unable to Create a Directory in this part.",
+ /*063*/ "That file already exists.",
+ /*064*/ "The directory is not empty.",
+ /*065*/ "The wrong type of part for this operation.",
+ /*066*/ "The max len for this file is too small.",
+ /*067*/ "This is not a write once bank.",
+ /*068*/ "The file can not be found.",
+ /*069*/ "There is not enough space available.",
+ /*070*/ "There is not a page to match that bit in the bitmap.",
+ /*071*/ "There are no jobs for EPROM parts.",
+ /*072*/ "Function not supported to modify attributes.",
+ /*073*/ "Handle is not in use.",
+ /*074*/ "Tring to read a write only file.",
+ /*075*/ "There is no handle available for use.",
+ /*076*/ "The directory provided is an invalid directory.",
+ /*077*/ "Handle does not exist.",
+ /*078*/ "Serial Number did not match with current job.",
+ /*079*/ "Can not program EPROM because a non-EPROM part on the network.",
+ /*080*/ "Write protect redirection byte is set.",
+ /*081*/ "There is an inappropriate directory length.",
+ /*082*/ "The file has already been terminated.",
+ /*083*/ "Failed to read memory page of iButton part.",
+ /*084*/ "Failed to match scratchpad of iButton part.",
+ /*085*/ "Failed to erase scratchpad of iButton part.",
+ /*086*/ "Failed to read scratchpad of iButton part.",
+ /*087*/ "Failed to execute SHA function on SHA iButton.",
+ /*088*/ "SHA iButton did not return a status completion byte.",
+ /*089*/ "Write data page failed.",
+ /*090*/ "Copy secret into secret memory pages failed.",
+ /*091*/ "Bind unique secret to iButton failed.",
+ /*092*/ "Could not install secret into user token.",
+ /*093*/ "Transaction Incomplete: signature did not match.",
+ /*094*/ "Transaction Incomplete: could not sign service data.",
+ /*095*/ "User token did not provide a valid authentication response.",
+ /*096*/ "Failed to answer a challenge on the user token.",
+ /*097*/ "Failed to create a challenge on the coprocessor.",
+ /*098*/ "Transaction Incomplete: service data was not valid.",
+ /*099*/ "Transaction Incomplete: service data was not updated.",
+ /*100*/ "Unrecoverable, catastrophic service failure occured.",
+ /*101*/ "Load First Secret from scratchpad data failed.",
+ /*102*/ "Failed to match signature of user's service data.",
+ /*103*/ "Subkey out of range for the DS1991.",
+ /*104*/ "Block ID out of range for the DS1991",
+ /*105*/ "Password is enabled",
+ /*106*/ "Password is invalid",
+ /*107*/ "This memory bank has no read only password",
+ /*108*/ "This memory bank has no read/write password",
+ /*109*/ "1-Wire is shorted",
+ /*110*/ "Error communicating with 1-Wire adapter",
+ /*111*/ "CopyScratchpad failed: Ending Offset must go to end of page",
+ /*112*/ "WriteScratchpad failed: Ending Offset must go to end of page",
+ /*113*/ "Mission can not be stopped while one is not in progress",
+ /*114*/ "Error stopping the mission",
+ /*115*/ "Port number is outside (0,MAX_PORTNUM) interval",
+ /*116*/ "Level of the 1-Wire was not changed",
+ /*117*/ "Both the Read Only and Read Write Passwords must be set",
+ /*118*/ "Failure to change latch state."
+ /*119*/ "Could not open usb port through libusb",
+ /*120*/ "Libusb DS2490 port already opened",
+ /*121*/ "Failed to set libusb configuration",
+ /*122*/ "Failed to claim libusb interface",
+ /*123*/ "Failed to set libusb altinterface",
+ /*124*/ "No adapter found at this port number"
+ };
+
+ char *owGetErrorMsg(int err)
+ {
+ return owErrorMsg[err];
+ }
+
+#ifndef __C51__
+ //--------------------------------------------------------------------------
+ // The 'owPrintErrorMsg' is the method for printing an error from the stack.
+ // The destination for the print is specified by the argument, fileno, which
+ // can be stderr, stdout, or a log file. In non-debug mode, the output is
+ // of the form:
+ // Error num: Error msg
+ //
+ // In debug-mode, the output is of the form:
+ // Error num: filename line#: Error msg
+ //
+ // NOTE: This function has the side-effect of popping the error off the stack.
+ //
+ // Arguments: FILE*: the destination for printing.
+ //
+ void owPrintErrorMsg(FILE *filenum)
+ {
+ #ifdef DEBUG
+ int l = owErrorStack[ owErrorPointer ].lineno;
+ char *f = owErrorStack[ owErrorPointer ].filename;
+ int err = owGetErrorNum();
+ fprintf(filenum,"Error %d: %s line %d: %s\r\n",err,f,l,owErrorMsg[err]);
+ #else
+ int err = owGetErrorNum();
+ fprintf(filenum,"Error %d: %s\r\n",err,owErrorMsg[err]);
+ #endif
+ }
+#endif //__C51__
+
+ // Same as above, except uses default printf output
+ void owPrintErrorMsgStd()
+ {
+ #ifdef DEBUG
+ int l = owErrorStack[ owErrorPointer ].lineno;
+ char *f = owErrorStack[ owErrorPointer ].filename;
+ int err = owGetErrorNum();
+ printf("Error %d: %s line %d: %s\r\n",err,f,l,owErrorMsg[err]);
+ #else
+ int err = owGetErrorNum();
+ printf("Error %d: %s\r\n",err,owErrorMsg[err]);
+ #endif
+ }
+#endif
+
Index: sockit_owm/trunk/HAL/src/owses.c
===================================================================
--- sockit_owm/trunk/HAL/src/owses.c (nonexistent)
+++ sockit_owm/trunk/HAL/src/owses.c (revision 2)
@@ -0,0 +1,92 @@
+//---------------------------------------------------------------------------
+// Copyright (C) 1999 Dallas Semiconductor Corporation, All Rights Reserved.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a
+// copy of this software and associated documentation files (the "Software"),
+// to deal in the Software without restriction, including without limitation
+// the rights to use, copy, modify, merge, publish, distribute, sublicense,
+// and/or sell copies of the Software, and to permit persons to whom the
+// Software is furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included
+// in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+// IN NO EVENT SHALL DALLAS SEMICONDUCTOR BE LIABLE FOR ANY CLAIM, DAMAGES
+// OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+// OTHER DEALINGS IN THE SOFTWARE.
+//
+// Except as contained in this notice, the name of Dallas Semiconductor
+// shall not be used except as stated in the Dallas Semiconductor
+// Branding Policy.
+//---------------------------------------------------------------------------
+//
+// todoses.C - Acquire and release a Session Todo for general 1-Wire Net
+// library
+//
+// Version: 2.00
+// 1.03 -> 2.00 Changed 'MLan' to 'ow'. Added support for
+// multiple ports.
+//
+
+#include "ownet.h"
+#include "sockit_owm.h"
+
+extern sockit_owm_state sockit_owm;
+
+// local function prototypes
+SMALLINT owAcquire(int,char *);
+void owRelease(int);
+
+//---------------------------------------------------------------------------
+// Attempt to acquire a 1-Wire net
+//
+// 'portnum' - number 0 to MAX_PORTNUM-1. This number is provided to
+// indicate the symbolic port number.
+// 'port_zstr' - zero terminated port name.
+//
+// Returns: TRUE - success, port opened
+//
+// The current implementation does not wait for a port to be freed,
+// it returns FALSE.
+//
+SMALLINT owAcquire(int portnum, char *port_zstr)
+{
+ // check if there are enough ports available
+ if (sockit_owm.own <= portnum) {
+ // TODO some error message might be added
+ return FALSE;
+ }
+ // check if port is already in use
+ if ((sockit_owm.use >> portnum) & 0x1) {
+ return FALSE;
+ }
+ // if it is unused take it
+ else {
+ sockit_owm.use |= (0x1 << portnum);
+ return TRUE;
+ }
+}
+
+//---------------------------------------------------------------------------
+// Release the previously acquired a 1-Wire net.
+//
+// 'portnum' - number 0 to MAX_PORTNUM-1. This number is provided to
+// indicate the symbolic port number.
+//
+void owRelease(int portnum)
+{
+ // check if port is already in use and release it
+ if ((sockit_owm.use >> portnum) & 0x1) {
+ sockit_owm.use &= ~(0x1 << portnum);
+ }
+ // releasing an unused port is not supported
+ else {
+ // TODO some error message might be added
+ }
+}
+
+
Index: sockit_owm/trunk/HAL/src/findtype.c
===================================================================
--- sockit_owm/trunk/HAL/src/findtype.c (nonexistent)
+++ sockit_owm/trunk/HAL/src/findtype.c (revision 2)
@@ -0,0 +1,78 @@
+//---------------------------------------------------------------------------
+// Copyright (C) 2000 Dallas Semiconductor Corporation, All Rights Reserved.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a
+// copy of this software and associated documentation files (the "Software"),
+// to deal in the Software without restriction, including without limitation
+// the rights to use, copy, modify, merge, publish, distribute, sublicense,
+// and/or sell copies of the Software, and to permit persons to whom the
+// Software is furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included
+// in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+// IN NO EVENT SHALL DALLAS SEMICONDUCTOR BE LIABLE FOR ANY CLAIM, DAMAGES
+// OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+// OTHER DEALINGS IN THE SOFTWARE.
+//
+// Except as contained in this notice, the name of Dallas Semiconductor
+// shall not be used except as stated in the Dallas Semiconductor
+// Branding Policy.
+//---------------------------------------------------------------------------
+//
+// findtype.c - Test module to find all devices of one type.
+//
+// Version: 2.00
+//
+//----------------------------------------------------------------------
+//
+//
+#include "ownet.h"
+#include "findtype.h"
+
+//----------------------------------------------------------------------
+// Search for devices
+//
+// 'portnum' - number 0 to MAX_PORTNUM-1. This number is provided to
+// indicate the symbolic port number.
+// 'FamilySN' - an array of all the serial numbers with the matching
+// family code
+// 'family_code' - the family code of the devices to search for on the
+// 1-Wire Net
+// 'MAXDEVICES' - the maximum number of devices to look for with the
+// family code passed.
+//
+// Returns: TRUE(1) success, device type found
+// FALSE(0) device not found
+//
+SMALLINT FindDevices(int portnum, uchar FamilySN[][8], SMALLINT family_code, int MAXDEVICES)
+{
+ int NumDevices=0;
+
+ // find the devices
+ // set the search to first find that family code
+ owFamilySearchSetup(portnum,family_code);
+
+ // loop to find all of the devices up to MAXDEVICES
+ NumDevices = 0;
+ do
+ {
+ // perform the search
+ if (!owNext(portnum,TRUE, FALSE))
+ break;
+
+ owSerialNum(portnum,FamilySN[NumDevices], TRUE);
+ if ((FamilySN[NumDevices][0] & 0x7F) == (family_code & 0x7F))
+ {
+ NumDevices++;
+ }
+ }
+ while (NumDevices < (MAXDEVICES - 1));
+
+ // check if not at least 1 device
+ return NumDevices;
+}
Index: sockit_owm/trunk/HAL/src/crcutil.c
===================================================================
--- sockit_owm/trunk/HAL/src/crcutil.c (nonexistent)
+++ sockit_owm/trunk/HAL/src/crcutil.c (revision 2)
@@ -0,0 +1,119 @@
+//---------------------------------------------------------------------------
+// Copyright (C) 2000 Dallas Semiconductor Corporation, All Rights Reserved.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a
+// copy of this software and associated documentation files (the "Software"),
+// to deal in the Software without restriction, including without limitation
+// the rights to use, copy, modify, merge, publish, distribute, sublicense,
+// and/or sell copies of the Software, and to permit persons to whom the
+// Software is furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included
+// in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+// IN NO EVENT SHALL DALLAS SEMICONDUCTOR BE LIABLE FOR ANY CLAIM, DAMAGES
+// OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+// OTHER DEALINGS IN THE SOFTWARE.
+//
+// Except as contained in this notice, the name of Dallas Semiconductor
+// shall not be used except as stated in the Dallas Semiconductor
+// Branding Policy.
+//--------------------------------------------------------------------------
+//
+// crcutil.c - Keeps track of the CRC for 16 and 8 bit operations
+// version 2.00
+
+// Include files
+#include "ownet.h"
+
+// Local global variables
+ushort utilcrc16[MAX_PORTNUM];
+uchar utilcrc8[MAX_PORTNUM];
+static short oddparity[16] = { 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0 };
+static uchar dscrc_table[] = {
+ 0, 94,188,226, 97, 63,221,131,194,156,126, 32,163,253, 31, 65,
+ 157,195, 33,127,252,162, 64, 30, 95, 1,227,189, 62, 96,130,220,
+ 35,125,159,193, 66, 28,254,160,225,191, 93, 3,128,222, 60, 98,
+ 190,224, 2, 92,223,129, 99, 61,124, 34,192,158, 29, 67,161,255,
+ 70, 24,250,164, 39,121,155,197,132,218, 56,102,229,187, 89, 7,
+ 219,133,103, 57,186,228, 6, 88, 25, 71,165,251,120, 38,196,154,
+ 101, 59,217,135, 4, 90,184,230,167,249, 27, 69,198,152,122, 36,
+ 248,166, 68, 26,153,199, 37,123, 58,100,134,216, 91, 5,231,185,
+ 140,210, 48,110,237,179, 81, 15, 78, 16,242,172, 47,113,147,205,
+ 17, 79,173,243,112, 46,204,146,211,141,111, 49,178,236, 14, 80,
+ 175,241, 19, 77,206,144,114, 44,109, 51,209,143, 12, 82,176,238,
+ 50,108,142,208, 83, 13,239,177,240,174, 76, 18,145,207, 45,115,
+ 202,148,118, 40,171,245, 23, 73, 8, 86,180,234,105, 55,213,139,
+ 87, 9,235,181, 54,104,138,212,149,203, 41,119,244,170, 72, 22,
+ 233,183, 85, 11,136,214, 52,106, 43,117,151,201, 74, 20,246,168,
+ 116, 42,200,150, 21, 75,169,247,182,232, 10, 84,215,137,107, 53};
+
+//--------------------------------------------------------------------------
+// Reset crc16 to the value passed in
+//
+// 'reset' - data to set crc16 to.
+//
+void setcrc16(int portnum, ushort reset)
+{
+ utilcrc16[portnum&0x0FF] = reset;
+ return;
+}
+
+//--------------------------------------------------------------------------
+// Reset crc8 to the value passed in
+//
+// 'portnum' - number 0 to MAX_PORTNUM-1. This number is provided to
+// indicate the symbolic port number.
+// 'reset' - data to set crc8 to
+//
+void setcrc8(int portnum, uchar reset)
+{
+ utilcrc8[portnum&0x0FF] = reset;
+ return;
+}
+
+//--------------------------------------------------------------------------
+// Calculate a new CRC16 from the input data short. Return the current
+// CRC16 and also update the global variable CRC16.
+//
+// 'portnum' - number 0 to MAX_PORTNUM-1. This number is provided to
+// indicate the symbolic port number.
+// 'data' - data to perform a CRC16 on
+//
+// Returns: the current CRC16
+//
+ushort docrc16(int portnum, ushort cdata)
+{
+ cdata = (cdata ^ (utilcrc16[portnum&0x0FF] & 0xff)) & 0xff;
+ utilcrc16[portnum&0x0FF] >>= 8;
+
+ if (oddparity[cdata & 0xf] ^ oddparity[cdata >> 4])
+ utilcrc16[portnum&0x0FF] ^= 0xc001;
+
+ cdata <<= 6;
+ utilcrc16[portnum&0x0FF] ^= cdata;
+ cdata <<= 1;
+ utilcrc16[portnum&0x0FF] ^= cdata;
+
+ return utilcrc16[portnum&0x0FF];
+}
+
+//--------------------------------------------------------------------------
+// Update the Dallas Semiconductor One Wire CRC (utilcrc8) from the global
+// variable utilcrc8 and the argument.
+//
+// 'portnum' - number 0 to MAX_PORTNUM-1. This number is provided to
+// indicate the symbolic port number.
+// 'x' - data byte to calculate the 8 bit crc from
+//
+// Returns: the updated utilcrc8.
+//
+uchar docrc8(int portnum, uchar x)
+{
+ utilcrc8[portnum&0x0FF] = dscrc_table[utilcrc8[portnum&0x0FF] ^ x];
+ return utilcrc8[portnum&0x0FF];
+}
Index: sockit_owm/trunk/HAL/src/owtran.c
===================================================================
--- sockit_owm/trunk/HAL/src/owtran.c (nonexistent)
+++ sockit_owm/trunk/HAL/src/owtran.c (revision 2)
@@ -0,0 +1,204 @@
+//---------------------------------------------------------------------------
+// Copyright (C) 1999 Dallas Semiconductor Corporation, All Rights Reserved.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a
+// copy of this software and associated documentation files (the "Software"),
+// to deal in the Software without restriction, including without limitation
+// the rights to use, copy, modify, merge, publish, distribute, sublicense,
+// and/or sell copies of the Software, and to permit persons to whom the
+// Software is furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included
+// in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+// IN NO EVENT SHALL DALLAS SEMICONDUCTOR BE LIABLE FOR ANY CLAIM, DAMAGES
+// OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+// OTHER DEALINGS IN THE SOFTWARE.
+//
+// Except as contained in this notice, the name of Dallas Semiconductor
+// shall not be used except as stated in the Dallas Semiconductor
+// Branding Policy.
+//---------------------------------------------------------------------------
+//
+// owTran.C - Transport functions for 1-Wire devices.
+//
+// Version: 2.01
+//
+// History: 1.03 -> 2.00 Changed 'MLan' to 'ow'. Added support for
+// multiple ports.
+// 2.00 -> 2.01 Added support for owError library
+//
+
+#include "ownet.h"
+
+//--------------------------------------------------------------------------
+// The 'owBlock' transfers a block of data to and from the
+// 1-Wire Net with an optional reset at the begining of communication.
+// The result is returned in the same buffer.
+//
+// 'do_reset' - cause a owTouchReset to occure at the begining of
+// communication TRUE(1) or not FALSE(0)
+// 'tran_buf' - pointer to a block of unsigned
+// chars of length 'TranferLength' that will be sent
+// to the 1-Wire Net
+// 'tran_len' - length in bytes to transfer
+// Supported devices: all
+//
+// Returns: TRUE (1) : The optional reset returned a valid
+// presence (do_reset == TRUE) or there
+// was no reset required.
+// FALSE (0): The reset did not return a valid prsence
+// (do_reset == TRUE).
+//
+// The maximum tran_len is 160
+//
+SMALLINT owBlock(int portnum, SMALLINT do_reset, uchar *tran_buf, SMALLINT tran_len)
+{
+ uchar i;
+
+ // check for a block too big
+ if (tran_len > 160)
+ {
+ OWERROR(OWERROR_BLOCK_TOO_BIG);
+ return FALSE;
+ }
+
+ // check if need to do a owTouchReset first
+ if (do_reset)
+ {
+ if (!owTouchReset(portnum))
+ {
+ OWERROR(OWERROR_NO_DEVICES_ON_NET);
+ return FALSE;
+ }
+ }
+
+ // send and receive the buffer
+ for (i = 0; i < tran_len; i++)
+ tran_buf[i] = (uchar)owTouchByte(portnum,tran_buf[i]);
+
+ return TRUE;
+}
+
+//--------------------------------------------------------------------------
+// Write a byte to an EPROM 1-Wire device.
+//
+// Supported devices: crc_type=0(CRC8)
+// DS1982
+// crc_type=1(CRC16)
+// DS1985, DS1986, DS2407
+//
+// 'portnum' - number 0 to MAX_PORTNUM-1. This number is provided to
+// indicate the symbolic port number.
+// 'write_byte' - byte to program
+// 'addr' - address of byte to program
+// 'write_cmd' - command used to write (0x0F reg mem, 0x55 status)
+// 'crc_type' - CRC used (0 CRC8, 1 CRC16)
+// 'do_access' - Flag to access device for each byte
+// (0 skip access, 1 do the access)
+// WARNING, only use do_access=0 if programing the NEXT
+// byte immediatly after the previous byte.
+//
+// Returns: >=0 success, this is the resulting byte from the program
+// effort
+// -1 error, device not connected or program pulse voltage
+// not available
+//
+SMALLINT owProgramByte(int portnum, SMALLINT write_byte, int addr, SMALLINT write_cmd,
+ SMALLINT crc_type, SMALLINT do_access)
+{
+ ushort lastcrc16;
+ uchar lastcrc8;
+
+ // optionally access the device
+ if (do_access)
+ {
+ if (!owAccess(portnum))
+ {
+ OWERROR(OWERROR_ACCESS_FAILED);
+ return -1;
+ }
+
+ // send the write command
+ if (!owWriteByte(portnum,write_cmd))
+ {
+ OWERROR(OWERROR_WRITE_BYTE_FAILED);
+ return -1;
+ }
+
+ // send the address
+ if (!owWriteByte(portnum,addr & 0xFF) || !owWriteByte(portnum,addr >> 8))
+ {
+ OWERROR(OWERROR_WRITE_BYTE_FAILED);
+ return -1;
+ }
+ }
+
+ // send the data to write
+ if (!owWriteByte(portnum,write_byte))
+ {
+ OWERROR(OWERROR_WRITE_BYTE_FAILED);
+ return -1;
+ }
+
+ // read the CRC
+ if (crc_type == 0)
+ {
+ // calculate CRC8
+ if (do_access)
+ {
+ setcrc8(portnum,0);
+ docrc8(portnum,(uchar)write_cmd);
+ docrc8(portnum,(uchar)(addr & 0xFF));
+ docrc8(portnum,(uchar)(addr >> 8));
+ }
+ else
+ setcrc8(portnum,(uchar)(addr & 0xFF));
+
+ docrc8(portnum,(uchar)write_byte);
+ // read and calculate the read crc
+ lastcrc8 = docrc8(portnum,(uchar)owReadByte(portnum));
+ // crc should now be 0x00
+ if (lastcrc8 != 0)
+ {
+ OWERROR(OWERROR_CRC_FAILED);
+ return -1;
+ }
+ }
+ else
+ {
+ // CRC16
+ if (do_access)
+ {
+ setcrc16(portnum,0);
+ docrc16(portnum,(ushort)write_cmd);
+ docrc16(portnum,(ushort)(addr & 0xFF));
+ docrc16(portnum,(ushort)(addr >> 8));
+ }
+ else
+ setcrc16(portnum,(ushort)addr);
+ docrc16(portnum,(ushort)write_byte);
+ // read and calculate the read crc
+ docrc16(portnum,(ushort)owReadByte(portnum));
+ lastcrc16 = docrc16(portnum,(ushort)owReadByte(portnum));
+ // crc should now be 0xB001
+ if (lastcrc16 != 0xB001)
+ return -1;
+ }
+
+ // send the program pulse
+ if (!owProgramPulse(portnum))
+ {
+ OWERROR(OWERROR_PROGRAM_PULSE_FAILED);
+ return -1;
+ }
+
+ // read back and return the resulting byte
+ return owReadByte(portnum);
+}
+
+
Index: sockit_owm/trunk/HAL/src/owlnk.c
===================================================================
--- sockit_owm/trunk/HAL/src/owlnk.c (nonexistent)
+++ sockit_owm/trunk/HAL/src/owlnk.c (revision 2)
@@ -0,0 +1,433 @@
+//---------------------------------------------------------------------------
+// Copyright (C) 2001 Dallas Semiconductor Corporation, All Rights Reserved.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a
+// copy of this software and associated documentation files (the "Software"),
+// to deal in the Software without restriction, including without limitation
+// the rights to use, copy, modify, merge, publish, distribute, sublicense,
+// and/or sell copies of the Software, and to permit persons to whom the
+// Software is furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included
+// in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+// IN NO EVENT SHALL DALLAS SEMICONDUCTOR BE LIABLE FOR ANY CLAIM, DAMAGES
+// OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+// OTHER DEALINGS IN THE SOFTWARE.
+//
+// Except as contained in this notice, the name of Dallas Semiconductor
+// shall not be used except as stated in the Dallas Semiconductor
+// Branding Policy.
+//---------------------------------------------------------------------------
+//
+// TODO.C - Link Layer functions required by general 1-Wire drive
+// implementation. Fill in the platform specific code.
+//
+// Version: 3.00
+//
+// History: 1.00 -> 1.01 Added function msDelay.
+// 1.02 -> 1.03 Added function msGettick.
+// 1.03 -> 2.00 Changed 'MLan' to 'ow'. Added support for
+// multiple ports.
+// 2.10 -> 3.00 Added owReadBitPower and owWriteBytePower
+//
+
+#include "ownet.h"
+#include "sockit_owm_regs.h"
+#include "sockit_owm.h"
+#include
+
+extern sockit_owm_state sockit_owm;
+
+// exportable link-level functions
+SMALLINT owTouchReset(int);
+SMALLINT owTouchBit(int,SMALLINT);
+SMALLINT owTouchByte(int,SMALLINT);
+SMALLINT owWriteByte(int,SMALLINT);
+SMALLINT owReadByte(int);
+SMALLINT owSpeed(int,SMALLINT);
+SMALLINT owLevel(int,SMALLINT);
+SMALLINT owProgramPulse(int);
+void msDelay(int);
+long msGettick(void);
+SMALLINT owWriteBytePower(int,SMALLINT);
+SMALLINT owReadBytePower(int);
+SMALLINT owReadBitPower(int,SMALLINT);
+SMALLINT owHasPowerDelivery(int);
+SMALLINT owHasOverDrive(int);
+SMALLINT owHasProgramPulse(int);
+
+//--------------------------------------------------------------------------
+// Reset all of the devices on the 1-Wire Net and return the result.
+//
+// 'portnum' - number 0 to MAX_PORTNUM-1. This number is provided to
+// indicate the symbolic port number.
+//
+// Returns: TRUE(1): presence pulse(s) detected, device(s) reset
+// FALSE(0): no presence pulses detected
+//
+SMALLINT owTouchReset(int portnum)
+{
+ int reg;
+ int ovd = (sockit_owm.ovd >> portnum) & 0x1;
+
+ // lock transfer
+ ALT_SEM_PEND (sockit_owm.trn, 0);
+
+ // write RST
+ IOWR_SOCKIT_OWM (sockit_owm.base, (sockit_owm.pwr << SOCKIT_OWM_POWER_OFST)
+ | (portnum << SOCKIT_OWM_SEL_OFST)
+ | (sockit_owm.ena << SOCKIT_OWM_ETX_OFST)
+ | (ovd << SOCKIT_OWM_OVD_OFST)
+ | SOCKIT_OWM_RST_MSK);
+
+ // wait for irq to set the transfer end flag
+ ALT_FLAG_PEND (sockit_owm.irq, 0x1, OS_FLAG_WAIT_SET_ANY + OS_FLAG_CONSUME, 0);
+ // wait for STX (end of transfer cycle) and read the presence status
+ while ((reg = IORD_SOCKIT_OWM (sockit_owm.base)) & SOCKIT_OWM_TRN_MSK);
+
+ // release transfer lock
+ ALT_SEM_POST (sockit_owm.trn);
+
+ // return DRX (presence detect)
+ return (~reg >> SOCKIT_OWM_DAT_OFST) & 0x1;
+}
+
+//--------------------------------------------------------------------------
+// Send 1 bit of communication to the 1-Wire Net and return the
+// result 1 bit read from the 1-Wire Net. The parameter 'sendbit'
+// least significant bit is used and the least significant bit
+// of the result is the return bit.
+//
+// 'portnum' - number 0 to MAX_PORTNUM-1. This number is provided to
+// indicate the symbolic port number.
+// 'sendbit' - the least significant bit is the bit to send
+//
+// Returns: 0: 0 bit read from sendbit
+// 1: 1 bit read from sendbit
+//
+SMALLINT owTouchBit(int portnum, SMALLINT sendbit)
+{
+ int reg;
+ int ovd = (sockit_owm.ovd >> portnum) & 0x1;
+
+ // lock transfer
+ ALT_SEM_PEND (sockit_owm.trn, 0);
+
+ // write RST
+ IOWR_SOCKIT_OWM (sockit_owm.base, (sockit_owm.pwr << SOCKIT_OWM_POWER_OFST)
+ | (portnum << SOCKIT_OWM_SEL_OFST)
+ | (sockit_owm.ena << SOCKIT_OWM_ETX_OFST)
+ | (ovd << SOCKIT_OWM_OVD_OFST)
+ | ((sendbit & 0x1) << SOCKIT_OWM_DAT_OFST));
+
+ // wait for irq to set the transfer end flag
+ ALT_FLAG_PEND (sockit_owm.irq, 0x1, OS_FLAG_WAIT_SET_ANY + OS_FLAG_CONSUME, 0);
+ // wait for STX (end of transfer cycle) and read the read data bit
+ while ((reg = IORD_SOCKIT_OWM (sockit_owm.base)) & SOCKIT_OWM_TRN_MSK);
+
+ // release transfer lock
+ ALT_SEM_POST (sockit_owm.trn);
+
+ // return DRX (read bit)
+ return (reg >> SOCKIT_OWM_DAT_OFST) & 0x1;
+}
+
+//--------------------------------------------------------------------------
+// Send 8 bits of communication to the 1-Wire Net and return the
+// result 8 bits read from the 1-Wire Net. The parameter 'sendbyte'
+// least significant 8 bits are used and the least significant 8 bits
+// of the result is the return byte.
+//
+// 'portnum' - number 0 to MAX_PORTNUM-1. This number is provided to
+// indicate the symbolic port number.
+// 'sendbyte' - 8 bits to send (least significant byte)
+//
+// Returns: 8 bytes read from sendbyte
+//
+SMALLINT owTouchByte(int portnum, SMALLINT sendbyte)
+{
+ int i;
+ SMALLINT dat = 0;
+ for (i=0; i<8; i++)
+ {
+ dat |= owTouchBit(portnum,sendbyte & 0x1) << i;
+ sendbyte >>= 1;
+ }
+ return dat;
+}
+
+//--------------------------------------------------------------------------
+// Send 8 bits of communication to the 1-Wire Net and verify that the
+// 8 bits read from the 1-Wire Net is the same (write operation).
+// The parameter 'sendbyte' least significant 8 bits are used.
+//
+// 'portnum' - number 0 to MAX_PORTNUM-1. This number is provided to
+// indicate the symbolic port number.
+// 'sendbyte' - 8 bits to send (least significant byte)
+//
+// Returns: TRUE: bytes written and echo was the same
+// FALSE: echo was not the same
+//
+SMALLINT owWriteByte(int portnum, SMALLINT sendbyte)
+{
+ return (owTouchByte(portnum,sendbyte) == sendbyte) ? TRUE : FALSE;
+}
+
+//--------------------------------------------------------------------------
+// Send 8 bits of read communication to the 1-Wire Net and and return the
+// result 8 bits read from the 1-Wire Net.
+//
+// 'portnum' - number 0 to MAX_PORTNUM-1. This number is provided to
+// indicate the symbolic port number.
+//
+// Returns: 8 bytes read from 1-Wire Net
+//
+SMALLINT owReadByte(int portnum)
+{
+ return owTouchByte(portnum,0xFF);
+}
+
+//--------------------------------------------------------------------------
+// Set the 1-Wire Net communication speed.
+//
+// 'portnum' - number 0 to MAX_PORTNUM-1. This number is provided to
+// indicate the symbolic port number.
+// 'new_speed' - new speed defined as
+// MODE_NORMAL 0x00
+// MODE_OVERDRIVE 0x01
+//
+// Returns: current 1-Wire Net speed
+//
+SMALLINT owSpeed(int portnum, SMALLINT new_speed)
+{
+ if (new_speed == MODE_OVERDRIVE) sockit_owm.ovd |= (1 << portnum);
+ if (new_speed == MODE_NORMAL ) sockit_owm.ovd &= ~(1 << portnum);
+ // return the current port state
+ return ((sockit_owm.ovd >> portnum) & 0x1) ? MODE_OVERDRIVE : MODE_NORMAL;
+}
+
+//--------------------------------------------------------------------------
+// Set the 1-Wire Net line level. The values for NewLevel are
+// as follows:
+//
+// 'portnum' - number 0 to MAX_PORTNUM-1. This number is provided to
+// indicate the symbolic port number.
+// 'new_level' - new level defined as
+// MODE_NORMAL 0x00
+// MODE_STRONG5 0x02
+// MODE_PROGRAM 0x04
+// MODE_BREAK 0x08
+//
+// Returns: current 1-Wire Net level
+//
+SMALLINT owLevel(int portnum, SMALLINT new_level)
+{
+ if (new_level == MODE_STRONG5) {
+ // set the power bit
+ sockit_owm.pwr |= (1 << portnum);
+ IOWR_SOCKIT_OWM (sockit_owm.base, (sockit_owm.pwr << SOCKIT_OWM_POWER_OFST)
+ | SOCKIT_OWM_PWR_MSK
+ | SOCKIT_OWM_IDL_MSK);
+ }
+ if (new_level == MODE_NORMAL) {
+ // clear the power bit
+ sockit_owm.pwr &= ~(1 << portnum);
+ IOWR_SOCKIT_OWM (sockit_owm.base, (sockit_owm.pwr << SOCKIT_OWM_POWER_OFST)
+ | SOCKIT_OWM_IDL_MSK);
+ }
+ // return the current port state
+ return ((sockit_owm.pwr >> portnum) & 0x1) ? MODE_STRONG5 : MODE_NORMAL;
+}
+
+//--------------------------------------------------------------------------
+// This procedure creates a fixed 480 microseconds 12 volt pulse
+// on the 1-Wire Net for programming EPROM iButtons.
+//
+// 'portnum' - number 0 to MAX_PORTNUM-1. This number is provided to
+// indicate the symbolic port number.
+//
+// Returns: TRUE successful
+// FALSE program voltage not available
+//
+SMALLINT owProgramPulse(int portnum)
+{
+ return owHasProgramPulse(portnum);
+}
+
+//--------------------------------------------------------------------------
+// Description:
+// Delay for at least 'len' ms
+//
+void msDelay(int len)
+{
+#if SOCKIT_OWM_HW_DLY
+ int i;
+
+ // lock transfer
+ ALT_SEM_PEND (sockit_owm.trn, 0);
+
+ for (i=0; i 1.01 Change to owFamilySearchSetup, LastDiscrepancy[portnum]
+// was set to 64 instead of 8 to enable devices with
+// early contention to go in the '0' direction first.
+// 1.02 -> 1.03 Initialized goodbits in owVerify
+// 1.03 -> 2.00 Changed 'MLan' to 'ow'. Added support for
+// multiple ports.
+// 2.00 -> 2.01 Added support for owError library
+// 2.01 -> 3.00 Make search functions consistent with AN187
+//
+
+#include
+#include "ownet.h"
+
+// exportable functions defined in ownet.c
+SMALLINT bitacc(SMALLINT,SMALLINT,SMALLINT,uchar *);
+
+// global variables for this module to hold search state information
+static SMALLINT LastDiscrepancy[MAX_PORTNUM];
+static SMALLINT LastFamilyDiscrepancy[MAX_PORTNUM];
+static SMALLINT LastDevice[MAX_PORTNUM];
+uchar SerialNum[MAX_PORTNUM][8];
+
+//--------------------------------------------------------------------------
+// The 'owFirst' finds the first device on the 1-Wire Net This function
+// contains one parameter 'alarm_only'. When
+// 'alarm_only' is TRUE (1) the find alarm command 0xEC is
+// sent instead of the normal search command 0xF0.
+// Using the find alarm command 0xEC will limit the search to only
+// 1-Wire devices that are in an 'alarm' state.
+//
+// 'portnum' - number 0 to MAX_PORTNUM-1. This number is provided to
+// indicate the symbolic port number.
+// 'do_reset' - TRUE (1) perform reset before search, FALSE (0) do not
+// perform reset before search.
+// 'alarm_only' - TRUE (1) the find alarm command 0xEC is
+// sent instead of the normal search command 0xF0
+//
+// Returns: TRUE (1) : when a 1-Wire device was found and it's
+// Serial Number placed in the global SerialNum[portnum]
+// FALSE (0): There are no devices on the 1-Wire Net.
+//
+SMALLINT owFirst(int portnum, SMALLINT do_reset, SMALLINT alarm_only)
+{
+ // reset the search state
+ LastDiscrepancy[portnum] = 0;
+ LastDevice[portnum] = FALSE;
+ LastFamilyDiscrepancy[portnum] = 0;
+
+ return owNext(portnum,do_reset,alarm_only);
+}
+
+//--------------------------------------------------------------------------
+// The 'owNext' function does a general search. This function
+// continues from the previos search state. The search state
+// can be reset by using the 'owFirst' function.
+// This function contains one parameter 'alarm_only'.
+// When 'alarm_only' is TRUE (1) the find alarm command
+// 0xEC is sent instead of the normal search command 0xF0.
+// Using the find alarm command 0xEC will limit the search to only
+// 1-Wire devices that are in an 'alarm' state.
+//
+// 'portnum' - number 0 to MAX_PORTNUM-1. This number is provided to
+// indicate the symbolic port number.
+// 'do_reset' - TRUE (1) perform reset before search, FALSE (0) do not
+// perform reset before search.
+// 'alarm_only' - TRUE (1) the find alarm command 0xEC is
+// sent instead of the normal search command 0xF0
+//
+// Returns: TRUE (1) : when a 1-Wire device was found and it's
+// Serial Number placed in the global SerialNum[portnum]
+// FALSE (0): when no new device was found. Either the
+// last search was the last device or there
+// are no devices on the 1-Wire Net.
+//
+SMALLINT owNext(int portnum, SMALLINT do_reset, SMALLINT alarm_only)
+{
+ uchar bit_test, search_direction, bit_number;
+ uchar last_zero, serial_byte_number, next_result;
+ uchar serial_byte_mask;
+ uchar lastcrc8;
+
+ // initialize for search
+ bit_number = 1;
+ last_zero = 0;
+ serial_byte_number = 0;
+ serial_byte_mask = 1;
+ next_result = 0;
+ setcrc8(portnum,0);
+
+ // if the last call was not the last one
+ if (!LastDevice[portnum])
+ {
+ // check if reset first is requested
+ if (do_reset)
+ {
+ // reset the 1-wire
+ // if there are no parts on 1-wire, return FALSE
+ if (!owTouchReset(portnum))
+ {
+ // printf("owTouchReset failed\r\n");
+ // reset the search
+ LastDiscrepancy[portnum] = 0;
+ LastFamilyDiscrepancy[portnum] = 0;
+ OWERROR(OWERROR_NO_DEVICES_ON_NET);
+ return FALSE;
+ }
+ }
+
+ // If finding alarming devices issue a different command
+ if (alarm_only)
+ owWriteByte(portnum,0xEC); // issue the alarming search command
+ else
+ owWriteByte(portnum,0xF0); // issue the search command
+
+ //pause before beginning the search
+ //usDelay(100);
+
+ // loop to do the search
+ do
+ {
+ // read a bit and its compliment
+ bit_test = owTouchBit(portnum,1) << 1;
+ bit_test |= owTouchBit(portnum,1);
+
+ // check for no devices on 1-wire
+ if (bit_test == 3)
+ break;
+ else
+ {
+ // all devices coupled have 0 or 1
+ if (bit_test > 0)
+ search_direction = !(bit_test & 0x01); // bit write value for search
+ else
+ {
+ // if this discrepancy if before the Last Discrepancy
+ // on a previous next then pick the same as last time
+ if (bit_number < LastDiscrepancy[portnum])
+ search_direction = ((SerialNum[portnum][serial_byte_number] & serial_byte_mask) > 0);
+ else
+ // if equal to last pick 1, if not then pick 0
+ search_direction = (bit_number == LastDiscrepancy[portnum]);
+
+ // if 0 was picked then record its position in LastZero
+ if (search_direction == 0)
+ {
+ last_zero = bit_number;
+
+ // check for Last discrepancy in family
+ if (last_zero < 9)
+ LastFamilyDiscrepancy[portnum] = last_zero;
+ }
+ }
+
+ // set or clear the bit in the SerialNum[portnum] byte serial_byte_number
+ // with mask serial_byte_mask
+ if (search_direction == 1)
+ SerialNum[portnum][serial_byte_number] |= serial_byte_mask;
+ else
+ SerialNum[portnum][serial_byte_number] &= ~serial_byte_mask;
+
+ // serial number search direction write bit
+ owTouchBit(portnum,search_direction);
+
+ // increment the byte counter bit_number
+ // and shift the mask serial_byte_mask
+ bit_number++;
+ serial_byte_mask <<= 1;
+
+ // if the mask is 0 then go to new SerialNum[portnum] byte serial_byte_number
+ // and reset mask
+ if (serial_byte_mask == 0)
+ {
+ // The below has been added to accomidate the valid CRC with the
+ // possible changing serial number values of the DS28E04.
+ if (((SerialNum[portnum][0] & 0x7F) == 0x1C) && (serial_byte_number == 1))
+ lastcrc8 = docrc8(portnum,0x7F);
+ else
+ lastcrc8 = docrc8(portnum,SerialNum[portnum][serial_byte_number]); // accumulate the CRC
+
+ serial_byte_number++;
+ serial_byte_mask = 1;
+ }
+ }
+ }
+ while(serial_byte_number < 8); // loop until through all SerialNum[portnum] bytes 0-7
+
+ // if the search was successful then
+ if (!((bit_number < 65) || lastcrc8))
+ {
+ // search successful so set LastDiscrepancy[portnum],LastDevice[portnum],next_result
+ LastDiscrepancy[portnum] = last_zero;
+ LastDevice[portnum] = (LastDiscrepancy[portnum] == 0);
+ next_result = TRUE;
+ }
+ }
+
+ // if no device found then reset counters so next 'next' will be
+ // like a first
+ if (!next_result || !SerialNum[portnum][0])
+ {
+ LastDiscrepancy[portnum] = 0;
+ LastDevice[portnum] = FALSE;
+ LastFamilyDiscrepancy[portnum] = 0;
+ next_result = FALSE;
+ }
+
+ return next_result;
+}
+
+//--------------------------------------------------------------------------
+// The 'owSerialNum' function either reads or sets the SerialNum buffer
+// that is used in the search functions 'owFirst' and 'owNext'.
+// This function contains two parameters, 'serialnum_buf' is a pointer
+// to a buffer provided by the caller. 'serialnum_buf' should point to
+// an array of 8 unsigned chars. The second parameter is a flag called
+// 'do_read' that is TRUE (1) if the operation is to read and FALSE
+// (0) if the operation is to set the internal SerialNum buffer from
+// the data in the provided buffer.
+//
+// 'portnum' - number 0 to MAX_PORTNUM-1. This number is provided to
+// indicate the symbolic port number.
+// 'serialnum_buf' - buffer to that contains the serial number to set
+// when do_read = FALSE (0) and buffer to get the serial
+// number when do_read = TRUE (1).
+// 'do_read' - flag to indicate reading (1) or setting (0) the current
+// serial number.
+//
+void owSerialNum(int portnum, uchar *serialnum_buf, SMALLINT do_read)
+{
+ uchar i;
+
+ // read the internal buffer and place in 'serialnum_buf'
+ if (do_read)
+ {
+ for (i = 0; i < 8; i++)
+ serialnum_buf[i] = SerialNum[portnum][i];
+ }
+ // set the internal buffer from the data in 'serialnum_buf'
+ else
+ {
+ for (i = 0; i < 8; i++)
+ SerialNum[portnum][i] = serialnum_buf[i];
+ }
+}
+
+//--------------------------------------------------------------------------
+// Setup the search algorithm to find a certain family of devices
+// the next time a search function is called 'owNext'.
+//
+// 'portnum' - number 0 to MAX_PORTNUM-1. This number was provided to
+// OpenCOM to indicate the port number.
+// 'search_family' - family code type to set the search algorithm to find
+// next.
+//
+void owFamilySearchSetup(int portnum, SMALLINT search_family)
+{
+ uchar i;
+
+ // set the search state to find SearchFamily type devices
+ SerialNum[portnum][0] = search_family;
+ for (i = 1; i < 8; i++)
+ SerialNum[portnum][i] = 0;
+ LastDiscrepancy[portnum] = 64;
+ LastDevice[portnum] = FALSE;
+}
+
+//--------------------------------------------------------------------------
+// Set the current search state to skip the current family code.
+//
+// 'portnum' - number 0 to MAX_PORTNUM-1. This number is provided to
+// indicate the symbolic port number.
+//
+void owSkipFamily(int portnum)
+{
+ // set the Last discrepancy to last family discrepancy
+ LastDiscrepancy[portnum] = LastFamilyDiscrepancy[portnum];
+ LastFamilyDiscrepancy[portnum] = 0;
+
+ // check for end of list
+ if (LastDiscrepancy[portnum] == 0)
+ LastDevice[portnum] = TRUE;
+}
+
+//--------------------------------------------------------------------------
+// The 'owAccess' function resets the 1-Wire and sends a MATCH Serial
+// Number command followed by the current SerialNum code. After this
+// function is complete the 1-Wire device is ready to accept device-specific
+// commands.
+//
+// 'portnum' - number 0 to MAX_PORTNUM-1. This number is provided to
+// indicate the symbolic port number.
+//
+// Returns: TRUE (1) : reset indicates present and device is ready
+// for commands.
+// FALSE (0): reset does not indicate presence or echos 'writes'
+// are not correct.
+//
+SMALLINT owAccess(int portnum)
+{
+ uchar sendpacket[9];
+ uchar i;
+
+ // reset the 1-wire
+ if (owTouchReset(portnum))
+ {
+ // create a buffer to use with block function
+ // match Serial Number command 0x55
+ sendpacket[0] = 0x55;
+ // Serial Number
+ for (i = 1; i < 9; i++)
+ sendpacket[i] = SerialNum[portnum][i-1];
+
+ // send/recieve the transfer buffer
+ if (owBlock(portnum,FALSE,sendpacket,9))
+ {
+ // verify that the echo of the writes was correct
+ for (i = 1; i < 9; i++)
+ if (sendpacket[i] != SerialNum[portnum][i-1])
+ return FALSE;
+ if (sendpacket[0] != 0x55)
+ {
+ OWERROR(OWERROR_WRITE_VERIFY_FAILED);
+ return FALSE;
+ }
+ else
+ return TRUE;
+ }
+ else
+ OWERROR(OWERROR_BLOCK_FAILED);
+ }
+ else
+ OWERROR(OWERROR_NO_DEVICES_ON_NET);
+
+ // reset or match echo failed
+ return FALSE;
+}
+
+//----------------------------------------------------------------------
+// The function 'owVerify' verifies that the current device
+// is in contact with the 1-Wire Net.
+// Using the find alarm command 0xEC will verify that the device
+// is in contact with the 1-Wire Net and is in an 'alarm' state.
+//
+// 'portnum' - number 0 to MAX_PORTNUM-1. This number is provided to
+// indicate the symbolic port number.
+// 'alarm_only' - TRUE (1) the find alarm command 0xEC
+// is sent instead of the normal search
+// command 0xF0.
+//
+// Returns: TRUE (1) : when the 1-Wire device was verified
+// to be on the 1-Wire Net
+// with alarm_only == FALSE
+// or verified to be on the 1-Wire Net
+// AND in an alarm state when
+// alarm_only == TRUE.
+// FALSE (0): the 1-Wire device was not on the
+// 1-Wire Net or if alarm_only
+// == TRUE, the device may be on the
+// 1-Wire Net but in a non-alarm state.
+//
+SMALLINT owVerify(int portnum, SMALLINT alarm_only)
+{
+ uchar i,sendlen=0,goodbits=0,cnt=0,s,tst;
+ uchar sendpacket[50];
+
+ // construct the search
+ if (alarm_only)
+ sendpacket[sendlen++] = 0xEC; // issue the alarming search command
+ else
+ sendpacket[sendlen++] = 0xF0; // issue the search command
+ // set all bits at first
+ for (i = 1; i <= 24; i++)
+ sendpacket[sendlen++] = 0xFF;
+ // now set or clear apropriate bits for search
+ for (i = 0; i < 64; i++)
+ bitacc(WRITE_FUNCTION,bitacc(READ_FUNCTION,0,i,&SerialNum[portnum][0]),(int)((i+1)*3-1),&sendpacket[1]);
+
+ // send/recieve the transfer buffer
+ if (owBlock(portnum,TRUE,sendpacket,sendlen))
+ {
+ // check results to see if it was a success
+ for (i = 0; i < 192; i += 3)
+ {
+ tst = (bitacc(READ_FUNCTION,0,i,&sendpacket[1]) << 1) |
+ bitacc(READ_FUNCTION,0,(int)(i+1),&sendpacket[1]);
+
+ s = bitacc(READ_FUNCTION,0,cnt++,&SerialNum[portnum][0]);
+
+ if (tst == 0x03) // no device on line
+ {
+ goodbits = 0; // number of good bits set to zero
+ break; // quit
+ }
+
+ if (((s == 0x01) && (tst == 0x02)) ||
+ ((s == 0x00) && (tst == 0x01)) ) // correct bit
+ goodbits++; // count as a good bit
+ }
+
+ // check too see if there were enough good bits to be successful
+ if (goodbits >= 8)
+ return TRUE;
+ }
+ else
+ OWERROR(OWERROR_BLOCK_FAILED);
+
+ // block fail or device not present
+ return FALSE;
+}
+
+//----------------------------------------------------------------------
+// Perform a overdrive MATCH command to select the 1-Wire device with
+// the address in the ID data register.
+//
+// 'portnum' - number 0 to MAX_PORTNUM-1. This number is provided to
+// indicate the symbolic port number.
+//
+// Returns: TRUE: If the device is present on the 1-Wire Net and
+// can do overdrive then the device is selected.
+// FALSE: Device is not present or not capable of overdrive.
+//
+// *Note: This function could be converted to send DS2480
+// commands in one packet.
+//
+SMALLINT owOverdriveAccess(int portnum)
+{
+ uchar sendpacket[8];
+ uchar i, bad_echo = FALSE;
+
+ // make sure normal level
+ owLevel(portnum,MODE_NORMAL);
+
+ // force to normal communication speed
+ owSpeed(portnum,MODE_NORMAL);
+
+ // call the 1-Wire Net reset function
+ if (owTouchReset(portnum))
+ {
+ // send the match command 0x69
+ if (owWriteByte(portnum,0x69))
+ {
+ // switch to overdrive communication speed
+ owSpeed(portnum,MODE_OVERDRIVE);
+
+ // create a buffer to use with block function
+ // Serial Number
+ for (i = 0; i < 8; i++)
+ sendpacket[i] = SerialNum[portnum][i];
+
+ // send/recieve the transfer buffer
+ if (owBlock(portnum,FALSE,sendpacket,8))
+ {
+ // verify that the echo of the writes was correct
+ for (i = 0; i < 8; i++)
+ if (sendpacket[i] != SerialNum[portnum][i])
+ bad_echo = TRUE;
+ // if echo ok then success
+ if (!bad_echo)
+ return TRUE;
+ else
+ OWERROR(OWERROR_WRITE_VERIFY_FAILED);
+ }
+ else
+ OWERROR(OWERROR_BLOCK_FAILED);
+ }
+ else
+ OWERROR(OWERROR_WRITE_BYTE_FAILED);
+ }
+ else
+ OWERROR(OWERROR_NO_DEVICES_ON_NET);
+
+ // failure, force back to normal communication speed
+ owSpeed(portnum,MODE_NORMAL);
+
+ return FALSE;
+}
+
+//--------------------------------------------------------------------------
+// Bit utility to read and write a bit in the buffer 'buf'.
+//
+// 'op' - operation (1) to set and (0) to read
+// 'state' - set (1) or clear (0) if operation is write (1)
+// 'loc' - bit number location to read or write
+// 'buf' - pointer to array of bytes that contains the bit
+// to read or write
+//
+// Returns: 1 if operation is set (1)
+// 0/1 state of bit number 'loc' if operation is reading
+//
+SMALLINT bitacc(SMALLINT op, SMALLINT state, SMALLINT loc, uchar *buf)
+{
+ SMALLINT nbyt,nbit;
+
+ nbyt = (loc / 8);
+ nbit = loc - (nbyt * 8);
+
+ if (op == WRITE_FUNCTION)
+ {
+ if (state)
+ buf[nbyt] |= (0x01 << nbit);
+ else
+ buf[nbyt] &= ~(0x01 << nbit);
+
+ return 1;
+ }
+ else
+ return ((buf[nbyt] >> nbit) & 0x01);
+}
Index: sockit_owm/trunk/HAL/inc/ownet.h
===================================================================
--- sockit_owm/trunk/HAL/inc/ownet.h (nonexistent)
+++ sockit_owm/trunk/HAL/inc/ownet.h (revision 2)
@@ -0,0 +1,422 @@
+//---------------------------------------------------------------------------
+// Copyright (C) 2000 Dallas Semiconductor Corporation, All Rights Reserved.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a
+// copy of this software and associated documentation files (the "Software"),
+// to deal in the Software without restriction, including without limitation
+// the rights to use, copy, modify, merge, publish, distribute, sublicense,
+// and/or sell copies of the Software, and to permit persons to whom the
+// Software is furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included
+// in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+// IN NO EVENT SHALL DALLAS SEMICONDUCTOR BE LIABLE FOR ANY CLAIM, DAMAGES
+// OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+// OTHER DEALINGS IN THE SOFTWARE.
+//
+// Except as contained in this notice, the name of Dallas Semiconductor
+// shall not be used except as stated in the Dallas Semiconductor
+// Branding Policy.
+//---------------------------------------------------------------------------
+//
+// ownet.h - Include file for 1-Wire Net library
+//
+// Version: 2.10
+//
+// History: 1.02 -> 1.03 Make sure uchar is not defined twice.
+// 1.03 -> 2.00 Changed 'MLan' to 'ow'.
+// 2.00 -> 2.01 Added error handling. Added circular-include check.
+// 2.01 -> 2.10 Added raw memory error handling and SMALLINT
+// 2.10 -> 3.00 Added memory bank functionality
+// Added file I/O operations
+//
+
+#ifndef OWNET_H
+#define OWNET_H
+
+//--------------------------------------------------------------//
+// Common Includes to ownet applications
+//--------------------------------------------------------------//
+#include
+
+
+//--------------------------------------------------------------//
+// Target Specific Information
+//--------------------------------------------------------------//
+//--------------------------------------------------------------//
+// Handhelds (PalmOS, WinCE)
+//--------------------------------------------------------------//
+#ifdef __MC68K__
+ //MC68K is the type of processor in the PILOT
+ //Metrowerk's CodeWarrior defines this symbol
+ #include
+ #ifndef strcmp
+ #include
+ #define strcmp StrCompare
+ #endif
+ #include
+#endif
+
+#ifdef _WIN32_WCE
+ //All of our projects had this flag defined by default (_WIN32_WCE),
+ //but I'm not 100% positive that this is _the_ definitive
+ //flag to use to identify a WinCE system.
+ #include "WinCElnk.h"
+ #ifndef FILE
+ #define FILE int
+ extern int sprintf(char *buffer, char *format,...);
+ extern void fprintf(FILE *fp, char *format,...);
+ extern void printf(char *format,...);
+ #endif
+#endif
+
+#if !defined(_WIN32_WCE) && !defined(__MC68K__)
+ #include
+#endif
+
+#ifdef __C51__
+ #define FILE int
+ #define exit(c) return
+ typedef unsigned int ushort;
+ typedef unsigned long ulong;
+ #define SMALLINT uchar
+#endif
+
+#ifdef __ICCMAXQ__
+ #define FILE int
+ #define stdout 0
+ #define stdin 1
+ #define stderr 2
+ typedef unsigned int ushort;
+ typedef unsigned long ulong;
+ #define SMALLINT short
+ #define main micro_main
+ #define real_main main
+ #define SMALL_MEMORY_TARGET
+#endif
+
+
+//--------------------------------------------------------------//
+// Typedefs
+//--------------------------------------------------------------//
+#ifndef SMALLINT
+ //
+ // purpose of smallint is for compile-time changing of formal
+ // parameters and return values of functions. For each target
+ // machine, an integer is alleged to represent the most "simple"
+ // number representable by that architecture. This should, in
+ // most cases, produce optimal code for that particular arch.
+ // BUT... The majority of compilers designed for embedded
+ // processors actually keep an int at 16 bits, although the
+ // architecture might only be comfortable with 8 bits.
+ // The default size of smallint will be the same as that of
+ // an integer, but this allows for easy overriding of that size.
+ //
+ // NOTE:
+ // In all cases where a smallint is used, it is assumed that
+ // decreasing the size of this integer to something as low as
+ // a single byte _will_not_ change the functionality of the
+ // application. e.g. a loop counter that will iterate through
+ // several kilobytes of data should not be SMALLINT. The most
+ // common place you'll see smallint is for boolean return types.
+ //
+ #define SMALLINT int
+#endif
+
+// setting max baud
+#ifdef _WINDOWS
+ // 0x02 = PARAMSET_19200
+#define MAX_BAUD 0x02
+#else
+ // 0x06 = PARMSET_115200
+#define MAX_BAUD 0x06
+#endif
+
+#ifndef OW_UCHAR
+ #define OW_UCHAR
+ typedef unsigned char uchar;
+ #if !defined(__MINGW32__) && (defined(__CYGWIN__) || defined(__GNUC__))
+ typedef unsigned long ulong;
+ //ushort already defined in sys/types.h
+ #include
+ #else
+ #if defined(_WIN32) || defined(WIN32) || defined(__MC68K__) || defined(_WIN32_WCE) || defined(_DOS) || defined(_WINDOWS) || defined(__MINGW32__)
+ typedef unsigned short ushort;
+ typedef unsigned long ulong;
+ #endif
+ #endif
+ #ifdef __sun__
+ #include
+ #endif
+ #ifdef SDCC
+ //intent of ushort is 2 bytes unsigned.
+ //for ds390 in sdcc, an int, not a short,
+ //is 2 bytes.
+ typedef unsigned int ushort;
+ #endif
+#endif
+
+// general defines
+#define WRITE_FUNCTION 1
+#define READ_FUNCTION 0
+
+// error codes
+// todo: investigate these and replace with new Error Handling library
+#define READ_ERROR -1
+#define INVALID_DIR -2
+#define NO_FILE -3
+#define WRITE_ERROR -4
+#define WRONG_TYPE -5
+#define FILE_TOO_BIG -6
+
+// Misc
+#define FALSE 0
+#define TRUE 1
+
+#ifndef MAX_PORTNUM
+ #define MAX_PORTNUM 1
+#endif
+
+// mode bit flags
+#define MODE_NORMAL 0x00
+#define MODE_OVERDRIVE 0x01
+#define MODE_STRONG5 0x02
+#define MODE_PROGRAM 0x04
+#define MODE_BREAK 0x08
+
+// Output flags
+#define LV_ALWAYS 2
+#define LV_OPTIONAL 1
+#define LV_VERBOSE 0
+
+//--------------------------------------------------------------//
+// Error handling
+//--------------------------------------------------------------//
+extern int owGetErrorNum(void);
+extern int owHasErrors(void);
+
+//Clears the stack.
+#define OWERROR_CLEAR() while(owHasErrors()) owGetErrorNum();
+
+#ifdef DEBUG
+ //Raises an exception with extra debug info
+ #define OWERROR(err) owRaiseError(err,__LINE__,__FILE__)
+ extern void owRaiseError(int,int,char*);
+ #define OWASSERT(s,err,ret) if(!(s)){owRaiseError((err),__LINE__,__FILE__);return (ret);}
+#else
+ //Raises an exception with just the error code
+ #define OWERROR(err) owRaiseError(err)
+ extern void owRaiseError(int);
+ #define OWASSERT(s,err,ret) if(!(s)){owRaiseError((err));return (ret);}
+#endif
+
+#ifdef SMALL_MEMORY_TARGET
+ #define OWERROR_DUMP(fileno) /*no-op*/;
+#else
+ //Prints the stack out to the given file.
+ #define OWERROR_DUMP(fileno) while(owHasErrors()) owPrintErrorMsg(fileno);
+ extern void owPrintErrorMsg(FILE *);
+ extern void owPrintErrorMsgStd();
+ extern char *owGetErrorMsg(int);
+#endif
+
+#define OWERROR_NO_ERROR_SET 0
+#define OWERROR_NO_DEVICES_ON_NET 1
+#define OWERROR_RESET_FAILED 2
+#define OWERROR_SEARCH_ERROR 3
+#define OWERROR_ACCESS_FAILED 4
+#define OWERROR_DS2480_NOT_DETECTED 5
+#define OWERROR_DS2480_WRONG_BAUD 6
+#define OWERROR_DS2480_BAD_RESPONSE 7
+#define OWERROR_OPENCOM_FAILED 8
+#define OWERROR_WRITECOM_FAILED 9
+#define OWERROR_READCOM_FAILED 10
+#define OWERROR_BLOCK_TOO_BIG 11
+#define OWERROR_BLOCK_FAILED 12
+#define OWERROR_PROGRAM_PULSE_FAILED 13
+#define OWERROR_PROGRAM_BYTE_FAILED 14
+#define OWERROR_WRITE_BYTE_FAILED 15
+#define OWERROR_READ_BYTE_FAILED 16
+#define OWERROR_WRITE_VERIFY_FAILED 17
+#define OWERROR_READ_VERIFY_FAILED 18
+#define OWERROR_WRITE_SCRATCHPAD_FAILED 19
+#define OWERROR_COPY_SCRATCHPAD_FAILED 20
+#define OWERROR_INCORRECT_CRC_LENGTH 21
+#define OWERROR_CRC_FAILED 22
+#define OWERROR_GET_SYSTEM_RESOURCE_FAILED 23
+#define OWERROR_SYSTEM_RESOURCE_INIT_FAILED 24
+#define OWERROR_DATA_TOO_LONG 25
+#define OWERROR_READ_OUT_OF_RANGE 26
+#define OWERROR_WRITE_OUT_OF_RANGE 27
+#define OWERROR_DEVICE_SELECT_FAIL 28
+#define OWERROR_READ_SCRATCHPAD_VERIFY 29
+#define OWERROR_COPY_SCRATCHPAD_NOT_FOUND 30
+#define OWERROR_ERASE_SCRATCHPAD_NOT_FOUND 31
+#define OWERROR_ADDRESS_READ_BACK_FAILED 32
+#define OWERROR_EXTRA_INFO_NOT_SUPPORTED 33
+#define OWERROR_PG_PACKET_WITHOUT_EXTRA 34
+#define OWERROR_PACKET_LENGTH_EXCEEDS_PAGE 35
+#define OWERROR_INVALID_PACKET_LENGTH 36
+#define OWERROR_NO_PROGRAM_PULSE 37
+#define OWERROR_READ_ONLY 38
+#define OWERROR_NOT_GENERAL_PURPOSE 39
+#define OWERROR_READ_BACK_INCORRECT 40
+#define OWERROR_INVALID_PAGE_NUMBER 41
+#define OWERROR_CRC_NOT_SUPPORTED 42
+#define OWERROR_CRC_EXTRA_INFO_NOT_SUPPORTED 43
+#define OWERROR_READ_BACK_NOT_VALID 44
+#define OWERROR_COULD_NOT_LOCK_REDIRECT 45
+#define OWERROR_READ_STATUS_NOT_COMPLETE 46
+#define OWERROR_PAGE_REDIRECTION_NOT_SUPPORTED 47
+#define OWERROR_LOCK_REDIRECTION_NOT_SUPPORTED 48
+#define OWERROR_READBACK_EPROM_FAILED 49
+#define OWERROR_PAGE_LOCKED 50
+#define OWERROR_LOCKING_REDIRECTED_PAGE_AGAIN 51
+#define OWERROR_REDIRECTED_PAGE 52
+#define OWERROR_PAGE_ALREADY_LOCKED 53
+#define OWERROR_WRITE_PROTECTED 54
+#define OWERROR_NONMATCHING_MAC 55
+#define OWERROR_WRITE_PROTECT 56
+#define OWERROR_WRITE_PROTECT_SECRET 57
+#define OWERROR_COMPUTE_NEXT_SECRET 58
+#define OWERROR_LOAD_FIRST_SECRET 59
+#define OWERROR_POWER_NOT_AVAILABLE 60
+#define OWERROR_XBAD_FILENAME 61
+#define OWERROR_XUNABLE_TO_CREATE_DIR 62
+#define OWERROR_REPEAT_FILE 63
+#define OWERROR_DIRECTORY_NOT_EMPTY 64
+#define OWERROR_WRONG_TYPE 65
+#define OWERROR_BUFFER_TOO_SMALL 66
+#define OWERROR_NOT_WRITE_ONCE 67
+#define OWERROR_FILE_NOT_FOUND 68
+#define OWERROR_OUT_OF_SPACE 69
+#define OWERROR_TOO_LARGE_BITNUM 70
+#define OWERROR_NO_PROGRAM_JOB 71
+#define OWERROR_FUNC_NOT_SUP 72
+#define OWERROR_HANDLE_NOT_USED 73
+#define OWERROR_FILE_WRITE_ONLY 74
+#define OWERROR_HANDLE_NOT_AVAIL 75
+#define OWERROR_INVALID_DIRECTORY 76
+#define OWERROR_HANDLE_NOT_EXIST 77
+#define OWERROR_NONMATCHING_SNUM 78
+#define OWERROR_NON_PROGRAM_PARTS 79
+#define OWERROR_PROGRAM_WRITE_PROTECT 80
+#define OWERROR_FILE_READ_ERR 81
+#define OWERROR_ADDFILE_TERMINATED 82
+#define OWERROR_READ_MEMORY_PAGE_FAILED 83
+#define OWERROR_MATCH_SCRATCHPAD_FAILED 84
+#define OWERROR_ERASE_SCRATCHPAD_FAILED 85
+#define OWERROR_READ_SCRATCHPAD_FAILED 86
+#define OWERROR_SHA_FUNCTION_FAILED 87
+#define OWERROR_NO_COMPLETION_BYTE 88
+#define OWERROR_WRITE_DATA_PAGE_FAILED 89
+#define OWERROR_COPY_SECRET_FAILED 90
+#define OWERROR_BIND_SECRET_FAILED 91
+#define OWERROR_INSTALL_SECRET_FAILED 92
+#define OWERROR_VERIFY_SIG_FAILED 93
+#define OWERROR_SIGN_SERVICE_DATA_FAILED 94
+#define OWERROR_VERIFY_AUTH_RESPONSE_FAILED 95
+#define OWERROR_ANSWER_CHALLENGE_FAILED 96
+#define OWERROR_CREATE_CHALLENGE_FAILED 97
+#define OWERROR_BAD_SERVICE_DATA 98
+#define OWERROR_SERVICE_DATA_NOT_UPDATED 99
+#define OWERROR_CATASTROPHIC_SERVICE_FAILURE 100
+#define OWERROR_LOAD_FIRST_SECRET_FAILED 101
+#define OWERROR_MATCH_SERVICE_SIGNATURE_FAILED 102
+#define OWERROR_KEY_OUT_OF_RANGE 103
+#define OWERROR_BLOCK_ID_OUT_OF_RANGE 104
+#define OWERROR_PASSWORDS_ENABLED 105
+#define OWERROR_PASSWORD_INVALID 106
+#define OWERROR_NO_READ_ONLY_PASSWORD 107
+#define OWERROR_NO_READ_WRITE_PASSWORD 108
+#define OWERROR_OW_SHORTED 109
+#define OWERROR_ADAPTER_ERROR 110
+#define OWERROR_EOP_COPY_SCRATCHPAD_FAILED 111
+#define OWERROR_EOP_WRITE_SCRATCHPAD_FAILED 112
+#define OWERROR_HYGRO_STOP_MISSION_UNNECESSARY 113
+#define OWERROR_HYGRO_STOP_MISSION_ERROR 114
+#define OWERROR_PORTNUM_ERROR 115
+#define OWERROR_LEVEL_FAILED 116
+#define OWERROR_PASSWORD_NOT_SET 117
+#define OWERROR_LATCH_NOT_SET 118
+#define OWERROR_LIBUSB_OPEN_FAILED 119
+#define OWERROR_LIBUSB_DEVICE_ALREADY_OPENED 120
+#define OWERROR_LIBUSB_SET_CONFIGURATION_ERROR 121
+#define OWERROR_LIBUSB_CLAIM_INTERFACE_ERROR 122
+#define OWERROR_LIBUSB_SET_ALTINTERFACE_ERROR 123
+#define OWERROR_LIBUSB_NO_ADAPTER_FOUND 124
+
+// One Wire functions defined in ownetu.c
+SMALLINT owFirst(int portnum, SMALLINT do_reset, SMALLINT alarm_only);
+SMALLINT owNext(int portnum, SMALLINT do_reset, SMALLINT alarm_only);
+void owSerialNum(int portnum, uchar *serialnum_buf, SMALLINT do_read);
+void owFamilySearchSetup(int portnum, SMALLINT search_family);
+void owSkipFamily(int portnum);
+SMALLINT owAccess(int portnum);
+SMALLINT owVerify(int portnum, SMALLINT alarm_only);
+SMALLINT owOverdriveAccess(int portnum);
+
+
+// external One Wire functions defined in owsesu.c
+ SMALLINT owAcquire(int portnum, char *port_zstr);
+ int owAcquireEx(char *port_zstr);
+ void owRelease(int portnum);
+
+// external One Wire functions defined in findtype.c
+// SMALLINT FindDevices(int,uchar FamilySN[][8],SMALLINT,int);
+
+// external One Wire functions from link layer owllu.c
+SMALLINT owTouchReset(int portnum);
+SMALLINT owTouchBit(int portnum, SMALLINT sendbit);
+SMALLINT owTouchByte(int portnum, SMALLINT sendbyte);
+SMALLINT owWriteByte(int portnum, SMALLINT sendbyte);
+SMALLINT owReadByte(int portnum);
+SMALLINT owSpeed(int portnum, SMALLINT new_speed);
+SMALLINT owLevel(int portnum, SMALLINT new_level);
+SMALLINT owProgramPulse(int portnum);
+SMALLINT owWriteBytePower(int portnum, SMALLINT sendbyte);
+SMALLINT owReadBytePower(int portnum);
+SMALLINT owHasPowerDelivery(int portnum);
+SMALLINT owHasProgramPulse(int portnum);
+SMALLINT owHasOverDrive(int portnum);
+SMALLINT owReadBitPower(int portnum, SMALLINT applyPowerResponse);
+// external One Wire global from owllu.c
+extern SMALLINT FAMILY_CODE_04_ALARM_TOUCHRESET_COMPLIANCE;
+
+// external One Wire functions from transaction layer in owtrnu.c
+SMALLINT owBlock(int portnum, SMALLINT do_reset, uchar *tran_buf, SMALLINT tran_len);
+SMALLINT owReadPacketStd(int portnum, SMALLINT do_access, int start_page, uchar *read_buf);
+SMALLINT owWritePacketStd(int portnum, int start_page, uchar *write_buf,
+ SMALLINT write_len, SMALLINT is_eprom, SMALLINT crc_type);
+SMALLINT owProgramByte(int portnum, SMALLINT write_byte, int addr, SMALLINT write_cmd,
+ SMALLINT crc_type, SMALLINT do_access);
+
+// link functions
+void msDelay(int len);
+long msGettick(void);
+
+// ioutil.c functions prototypes
+int EnterString(char *msg, char *buf, int min, int max);
+int EnterNum(char *msg, int numchars, long *value, long min, long max);
+int EnterHex(char *msg, int numchars, ulong *value);
+int ToHex(char ch);
+int getkeystroke(void);
+int key_abort(void);
+void ExitProg(char *msg, int exit_code);
+int getData(uchar *write_buff, int max_len, SMALLINT gethex);
+void PrintHex(uchar* buffer, int cnt);
+void PrintChars(uchar* buffer, int cnt);
+void PrintSerialNum(uchar* buffer);
+
+// external functions defined in crcutil.c
+void setcrc16(int portnum, ushort reset);
+ushort docrc16(int portnum, ushort cdata);
+void setcrc8(int portnum, uchar reset);
+uchar docrc8(int portnum, uchar x);
+
+#endif //OWNET_H
Index: sockit_owm/trunk/HAL/inc/sockit_owm.h
===================================================================
--- sockit_owm/trunk/HAL/inc/sockit_owm.h (nonexistent)
+++ sockit_owm/trunk/HAL/inc/sockit_owm.h (revision 2)
@@ -0,0 +1,152 @@
+/******************************************************************************
+* *
+* License Agreement *
+* *
+* Copyright (c) 2008 Altera Corporation, San Jose, California, USA. *
+* All rights reserved. *
+* *
+* Permission is hereby granted, free of charge, to any person obtaining a *
+* copy of this software and associated documentation files (the "Software"), *
+* to deal in the Software without restriction, including without limitation *
+* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
+* and/or sell copies of the Software, and to permit persons to whom the *
+* Software is furnished to do so, subject to the following conditions: *
+* *
+* The above copyright notice and this permission notice shall be included in *
+* all copies or substantial portions of the Software. *
+* *
+* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
+* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
+* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
+* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
+* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *
+* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *
+* DEALINGS IN THE SOFTWARE. *
+* *
+* This agreement shall be governed in all respects by the laws of the State *
+* of California and by the laws of the United States of America. *
+* *
+******************************************************************************/
+
+
+//////////////////////////////////////////////////////////////////////////////
+// //
+// Minimalistic 1-wire (onewire) master with Avalon MM bus interface //
+// //
+// Copyright (C) 2010 Iztok Jeras //
+// //
+//////////////////////////////////////////////////////////////////////////////
+// //
+// This program is free software: you can redistribute it and/or modify //
+// it under the terms of the GNU Lesser General Public License //
+// as published by the Free Software Foundation, either //
+// version 3 of the License, or (at your option) any later version. //
+// //
+// This program is distributed in the hope that it will be useful, //
+// but WITHOUT ANY WARRANTY; without even the implied warranty of //
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
+// GNU General Public License for more details. //
+// //
+// You should have received a copy of the GNU General Public License //
+// along with this program. If not, see . //
+// //
+//////////////////////////////////////////////////////////////////////////////
+
+
+#ifndef __SOCKIT_OWM_H__
+#define __SOCKIT_OWM_H__
+
+#include
+
+#include "sys/alt_warning.h"
+
+#include "os/alt_sem.h"
+#include "os/alt_flag.h"
+#include "alt_types.h"
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif /* __cplusplus */
+
+/*
+ * The sockit_owm_state structure is used to hold device specific data.
+ * This includes the transmit and receive buffers.
+ *
+ * An instance of this structure is created in the auto-generated
+ * alt_sys_init.c file for each UART listed in the systems SOPC file. This is
+ * done using the SOCKIT_OWM_STATE_INSTANCE macro given below.
+ */
+
+typedef struct sockit_owm_state_s
+{
+ // constants
+ void* base; // The base address of the device
+ alt_u32 own; // Number of onewire ports
+ alt_u32 ovd_e; // Overdrive mode implementation enable
+ // status
+ alt_u32 ena; // interrupt enable status
+ alt_u32 use; // Aquire status
+ alt_u32 ovd; // Overdrive status
+ alt_u32 pwr; // Power status
+ // OS multitasking features
+//ALT_FLAG_GRP (srx) // receive event flag
+ ALT_FLAG_GRP (irq) // transmit event flag
+ ALT_SEM (trn) // transfer lock semaphore
+} sockit_owm_state;
+
+/*
+ * The macro ALTERA_AVALON_UART_INSTANCE is used by the auto-generated file
+ * alt_sys_init.c to create an instance of this device driver state.
+ * ALTERA_AVALON_UART_INSTANCE is mapped below to SOCKIT_OWM_STATE_INSTANCE.
+ */
+
+#define SOCKIT_OWM_INSTANCE(name, state) \
+ sockit_owm_state sockit_owm = { (void*) name##_BASE, name##_OWN, name##_OVD_E, 0, 0, 0, 0}; \
+ void* state = (void*) name##_BASE
+/*
+ * sockit_owm_init() is called by the auto-generated function
+ * alt_sys_init() for each UART in the system. This is done using the
+ * SOCKIT_OWM_INIT macro given below.
+ *
+ * This function is responsible for performing all the run time initialization
+ * for a device instance, i.e. registering the interrupt handler, and
+ * regestering the device with the system.
+ */
+
+extern void sockit_owm_init(alt_u32 irq);
+
+/*
+ * The macro SOCKIT_OWM_STATE_INIT is used by the auto-generated file
+ * alt_sys_init.c to initialize an instance of the device driver state.
+ *
+ * This macro performs a sanity check to ensure that the interrupt has been
+ * connected for this device. If not, then an appropriate error message is
+ * generated at build time.
+ */
+#ifndef SOCKIT_OWM_POLLING
+#define SOCKIT_OWM_INIT(name, state) \
+ if (name##_IRQ == ALT_IRQ_NOT_CONNECTED) \
+ { \
+ ALT_LINK_ERROR ("Error: Interrupt not connected for " #name ". " \
+ "You have selected the interrupt driven version of " \
+ "the SocKit Avalon 1-wire master (mini) driver, but " \
+ "the interrupt is not connected for this device. You " \
+ "can select a polled mode driver by checking the " \
+ "'small driver' option in the HAL configuration " \
+ " window, or by using the -DSOCKIT_OWM_SMALL " \
+ "preprocessor flag."); \
+ } \
+ else \
+ { \
+ sockit_owm_init(name##_IRQ); \
+ }
+#else
+#define SOCKIT_OWM_INIT(name, state)
+#endif
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* __SOCKIT_OWM_H__ */
Index: sockit_owm/trunk/HAL/inc/findtype.h
===================================================================
--- sockit_owm/trunk/HAL/inc/findtype.h (nonexistent)
+++ sockit_owm/trunk/HAL/inc/findtype.h (revision 2)
@@ -0,0 +1,33 @@
+//---------------------------------------------------------------------------
+// Copyright (C) 2001 Dallas Semiconductor Corporation, All Rights Reserved.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a
+// copy of this software and associated documentation files (the "Software"),
+// to deal in the Software without restriction, including without limitation
+// the rights to use, copy, modify, merge, publish, distribute, sublicense,
+// and/or sell copies of the Software, and to permit persons to whom the
+// Software is furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included
+// in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+// IN NO EVENT SHALL DALLAS SEMICONDUCTOR BE LIABLE FOR ANY CLAIM, DAMAGES
+// OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+// OTHER DEALINGS IN THE SOFTWARE.
+//
+// Except as contained in this notice, the name of Dallas Semiconductor
+// shall not be used except as stated in the Dallas Semiconductor
+// Branding Policy.
+//---------------------------------------------------------------------------
+//
+// findtype.c - Header for the module to find all devices of one type.
+//
+// Version: 2.00
+//
+//----------------------------------------------------------------------
+
+SMALLINT FindDevices(int,uchar FamilySN[][8],SMALLINT,int);
Index: sockit_owm/trunk/onewire_slave_model.v
===================================================================
--- sockit_owm/trunk/onewire_slave_model.v (nonexistent)
+++ sockit_owm/trunk/onewire_slave_model.v (revision 2)
@@ -0,0 +1,186 @@
+//////////////////////////////////////////////////////////////////////////////
+// //
+// 1-wire (owr) slave model //
+// //
+// Copyright (C) 2010 Iztok Jeras //
+// //
+//////////////////////////////////////////////////////////////////////////////
+// //
+// This RTL is free hardware: you can redistribute it and/or modify //
+// it under the terms of the GNU Lesser General Public License //
+// as published by the Free Software Foundation, either //
+// version 3 of the License, or (at your option) any later version. //
+// //
+// This RTL is distributed in the hope that it will be useful, //
+// but WITHOUT ANY WARRANTY; without even the implied warranty of //
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
+// GNU General Public License for more details. //
+// //
+// You should have received a copy of the GNU General Public License //
+// along with this program. If not, see . //
+// //
+//////////////////////////////////////////////////////////////////////////////
+
+`timescale 1us / 1ns
+
+module onewire_slave_model #(
+ // identification
+ parameter FAMILY_CODE = 8'h01,
+ parameter SERIAL_NUMBER = 48'hba98_7654_3210,
+ parameter CRC_CODE = 8'hff,
+ // time slot (min=15, typ=30, max=60)
+ parameter TS = 30
+)(
+ inout wire owr
+);
+
+// commands
+localparam Read_ROM = 8'h33;
+localparam Search_ROM = 8'hf0;
+localparam Overdrive_Skip_ROM = 8'h3C;
+
+// IO
+reg pull;
+
+// status registers
+reg [23:0] state; // chip state in ASCII
+reg [23:0] cycle; // cycle status in ASCII
+reg [7:0] cmd; // received command
+reg od; // overdrive mode status
+integer cnt; // transfer bit counter
+
+// data registers
+reg [7:0] drx;
+reg [7:0] dtx;
+
+// events
+event transfer;
+event clock;
+event sample;
+event reset;
+
+//////////////////////////////////////////////////////////////////////////////
+// IO
+//////////////////////////////////////////////////////////////////////////////
+
+assign owr = pull ? 1'b0 : 1'bz;
+
+//////////////////////////////////////////////////////////////////////////////
+// events inside a cycle
+//////////////////////////////////////////////////////////////////////////////
+
+always @ (negedge owr) begin
+ fork
+ begin : slot_data
+ #((od?TS/10:TS)*1) -> sample;
+ end
+ begin : slot_reset
+ #((od?TS/10:TS)*8) -> reset;
+ end
+ begin : slot_reset_all
+ #((od?TS/10:TS)*8*8) begin
+ od = 1'b0;
+ -> reset;
+ end
+ end
+ begin : slot_end
+ @ (posedge owr) begin
+ disable slot_data;
+ disable slot_reset;
+ disable slot_reset_all;
+ end
+ end
+ join
+end
+
+// // bit transfer
+// always @ (negedge owr) begin
+// //task trn (); begin
+// -> transfer;
+// cycle <= dtx[0] ? "OPN" : "PUL";
+// pull <= ~dtx[0];
+// cnt <= cnt + 1;
+// fork
+// // transmit
+// begin : trn_tx
+// #(TS*1);
+// pull <= 1'b0;
+// end
+// // receive
+// begin : trn_rx
+// #(TS*1);
+// drx = {owr, drx[7:1]};
+// -> sample;
+// end
+// // reset
+// begin : trn_rst
+// #(TS*16)
+// state <= "RST";
+// cnt <= 0;
+// end
+// // wait for owr posedge
+// begin : trn_pdg
+// @ (posedge owr)
+// disable trn_rst;
+// end
+// join
+// cycle <= "IDL";
+// end
+// //endtask
+
+//////////////////////////////////////////////////////////////////////////////
+// logic
+//////////////////////////////////////////////////////////////////////////////
+
+// power up state
+initial begin
+ pull <= 1'b0;
+ #1 -> reset;
+end
+
+// reset event
+always @ (reset) begin
+ // IO state
+ pull <= 1'b0;
+ dtx <= 0;
+ cnt <= 0;
+ cycle <= "OPN";
+ // power-up chip state
+ state <= "RST";
+ od <= 1'b0;
+ if (~owr) @ (posedge owr);
+ // issue presence pulse
+ #((od?TS/10:TS)*1);
+ state <= "PRS";
+ pull <= 1'b1;
+ #((od?TS/10:TS)*4);
+ pull <= 1'b0;
+ state <= "IDL";
+end
+
+// // reset
+// always @ (negedge owr)
+// if (state == "RST") begin
+// trn ();
+// state <= "IDL";
+// end
+
+// // bit transfer
+// always @ (negedge owr)
+// case (state)
+// "IDL": begin
+// state <= "CMD";
+// trn ();
+// end
+// "CMD": begin
+// trn ();
+// if (cnt == 8)
+// cmd <= drx;
+// if (cmd == Read_ROM)
+// state <= "DTX";
+// dtx <= FAMILY_CODE;
+// end
+// endcase
+
+
+endmodule
Index: sockit_owm/trunk/sockit_owm_sw.tcl
===================================================================
--- sockit_owm/trunk/sockit_owm_sw.tcl (nonexistent)
+++ sockit_owm/trunk/sockit_owm_sw.tcl (revision 2)
@@ -0,0 +1,64 @@
+#
+# sockit_owm_sw.tcl
+#
+
+# Create a new driver
+create_driver sockit_owm_driver
+
+# Association with hardware
+set_sw_property hw_class_name sockit_owm
+
+# Driver version
+set_sw_property version 1.1
+
+# This driver is proclaimed to be compatible with sockit_owm hardware
+# as old as version "1.0". If the hardware component version number is not
+# equal or greater than the min_compatable_hw_version number, the driver
+# source files will not be copied over to the BSP drivers subdirectory
+set_sw_property min_compatible_hw_version 1.1
+
+# Interrupt properties: This driver supports both legacy and enhanced
+# interrupt APIs, as well as ISR preemption.
+set_sw_property isr_preemption_supported true
+set_sw_property supported_interrupt_apis "legacy_interrupt_api enhanced_interrupt_api"
+
+# Initialize the driver in alt_sys_init()
+set_sw_property auto_initialize true
+
+# Location in generated BSP that above sources will be copied into
+set_sw_property bsp_subdirectory drivers
+
+#
+# Source file listings...
+#
+
+# C/C++ source files
+add_sw_property c_source HAL/src/ownet.c
+add_sw_property c_source HAL/src/owtran.c
+add_sw_property c_source HAL/src/owlnk.c
+add_sw_property c_source HAL/src/owses.c
+add_sw_property c_source HAL/src/owerr.c
+add_sw_property c_source HAL/src/crcutil.c
+add_sw_property c_source HAL/src/sockit_owm.c
+
+# Include files
+add_sw_property include_source HAL/inc/ownet.h
+add_sw_property include_source HAL/inc/sockit_owm.h
+add_sw_property include_source inc/sockit_owm_regs.h
+
+# Common files
+add_sw_property include_source HAL/inc/findtype.h
+add_sw_property c_source HAL/src/findtype.c
+
+# This driver supports HAL & UCOSII BSP (OS) types
+add_sw_property supported_bsp_type HAL
+add_sw_property supported_bsp_type UCOSII
+
+# Driver configuration options
+add_sw_setting boolean_define_only public_mk_define enable_polling_driver SOCKIT_OWM_POLLING false "Small-footprint (polled mode) driver"
+add_sw_setting boolean_define_only public_mk_define enable_hardware_delay SOCKIT_OWM_HW_DLY false "Mili second delay implemented in hardware"
+
+# Enable application layer code
+#add_sw_setting boolean_define_only public_mk_define enable_A SOCKIT_OWM_A false "Enable driver A"
+
+# End of file
Index: sockit_owm/trunk/inc/sockit_owm_regs.h
===================================================================
--- sockit_owm/trunk/inc/sockit_owm_regs.h (nonexistent)
+++ sockit_owm/trunk/inc/sockit_owm_regs.h (revision 2)
@@ -0,0 +1,64 @@
+//////////////////////////////////////////////////////////////////////////////
+// //
+// Minimalistic 1-wire (onewire) master with Avalon MM bus interface //
+// //
+// Copyright (C) 2010 Iztok Jeras //
+// //
+//////////////////////////////////////////////////////////////////////////////
+// //
+// This program is free software: you can redistribute it and/or modify //
+// it under the terms of the GNU Lesser General Public License //
+// as published by the Free Software Foundation, either //
+// version 3 of the License, or (at your option) any later version. //
+// //
+// This program is distributed in the hope that it will be useful, //
+// but WITHOUT ANY WARRANTY; without even the implied warranty of //
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
+// GNU General Public License for more details. //
+// //
+// You should have received a copy of the GNU General Public License //
+// along with this program. If not, see . //
+// //
+//////////////////////////////////////////////////////////////////////////////
+
+
+#ifndef __SOCKIT_OWM_REGS_H__
+#define __SOCKIT_OWM_REGS_H__
+
+#include
+
+#define SOCKIT_OWM_REG 0
+#define IOADDR_SOCKIT_OWM(base) __IO_CALC_ADDRESS_NATIVE(base, SOCKIT_OWM_REG)
+#define IORD_SOCKIT_OWM(base) IORD(base, SOCKIT_OWM_REG)
+#define IOWR_SOCKIT_OWM(base, data) IOWR(base, SOCKIT_OWM_REG, data)
+
+#define SOCKIT_OWM_DAT_MSK (0x01) // data bit
+#define SOCKIT_OWM_DAT_OFST (0)
+#define SOCKIT_OWM_RST_MSK (0x02) // reset (write only)
+#define SOCKIT_OWM_RST_OFST (1)
+#define SOCKIT_OWM_TRN_MSK (0x02) // transfer (read only)
+#define SOCKIT_OWM_TRN_OFST (1)
+#define SOCKIT_OWM_OVD_MSK (0x04) // overdrive
+#define SOCKIT_OWM_OVD_OFST (2)
+#define SOCKIT_OWM_PWR_MSK (0x08) // power (strong pull-up)
+#define SOCKIT_OWM_PWR_OFST (3) // if there is a single port
+#define SOCKIT_OWM_STX_MSK (0x10) // status TX
+#define SOCKIT_OWM_STX_OFST (4)
+#define SOCKIT_OWM_SRX_MSK (0x20) // status RX
+#define SOCKIT_OWM_SRX_OFST (5)
+#define SOCKIT_OWM_ETX_MSK (0x40) // irq enable TX
+#define SOCKIT_OWM_ETX_OFST (6)
+#define SOCKIT_OWM_ERX_MSK (0x80) // irq enable RX
+#define SOCKIT_OWM_ERX_OFST (7)
+
+#define SOCKIT_OWM_SEL_MSK (0x0f00) // port select number
+#define SOCKIT_OWM_SEL_OFST (8)
+
+#define SOCKIT_OWM_POWER_MSK (0xffff0000) // power (strong pull-up)
+#define SOCKIT_OWM_POWER_OFST (16) // if there is more than one port
+
+// two common commands
+#define SOCKIT_OWM_DLY_MSK ( SOCKIT_OWM_RST_MSK | SOCKIT_OWM_DAT_MSK)
+#define SOCKIT_OWM_IDL_MSK (SOCKIT_OWM_OVD_MSK | SOCKIT_OWM_RST_MSK | SOCKIT_OWM_DAT_MSK)
+
+#endif /* __SOCKIT_OWM_REGS_H__ */
Index: sockit_owm/trunk/iverilog_gtkwave.cmd
===================================================================
--- sockit_owm/trunk/iverilog_gtkwave.cmd (nonexistent)
+++ sockit_owm/trunk/iverilog_gtkwave.cmd (revision 2)
@@ -0,0 +1,13 @@
+REM cmd script for running the onewire example
+
+:: cleanup first
+erase onewire.out
+erase onewire.vcd
+
+:: compile the verilog sources (testbench and RTL)
+iverilog -o onewire.out onewire_tb.v sockit_owm.v onewire_slave_model.v
+:: run the simulation
+vvp onewire.out
+
+:: open the waveform and detach it
+gtkwave onewire.vcd gtkwave.sav &
sockit_owm/trunk/iverilog_gtkwave.cmd
Property changes :
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: sockit_owm/trunk/README
===================================================================
--- sockit_owm/trunk/README (nonexistent)
+++ sockit_owm/trunk/README (revision 2)
@@ -0,0 +1,19 @@
+1-wire (onewire) master, with Altera tools integration
+
+This IP implements the 1-wire communication protocol (http://en.wikipedia.org/wiki/1-Wire).
+A more detailed documentation is provided in "onewire.odt".
+
+RTL features:
+- small RTL, should fit into a CPLD
+- Avalon MM bus, Wishbone compatible with a simple wraper
+- timed reset, presence, write/read bit transfers
+- overdrive (untested)
+- power supply (strong pull-up) (untested)
+
+SOPC Builder integration:
+- dividers are computed automaticaly from the system frequency
+
+Nios II EDS integration:
+- port of the 1-wire open domain kit version 3.10
+- interrup driven or polling driver
+- uCOS-II support (untested)
Index: sockit_owm/trunk/onewire.odt
===================================================================
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Index: sockit_owm/trunk/onewire.odt
===================================================================
--- sockit_owm/trunk/onewire.odt (nonexistent)
+++ sockit_owm/trunk/onewire.odt (revision 2)
sockit_owm/trunk/onewire.odt
Property changes :
Added: svn:mime-type
## -0,0 +1 ##
+application/octet-stream
\ No newline at end of property
Index: sockit_owm/trunk/sockit_owm_hw.tcl
===================================================================
--- sockit_owm/trunk/sockit_owm_hw.tcl (nonexistent)
+++ sockit_owm/trunk/sockit_owm_hw.tcl (revision 2)
@@ -0,0 +1,219 @@
+# sockit_owm
+# Iztok Jeras 2010.06.13.18:29:39
+# 1-wire (onewire) master
+
+# request TCL package from ACDS 9.1
+package require -exact sopc 9.1
+
+# module sockit_owm
+set_module_property DESCRIPTION "1-wire (onewire) master"
+set_module_property NAME sockit_owm
+set_module_property VERSION 1.1
+set_module_property INTERNAL false
+set_module_property GROUP "Interface Protocols/Serial"
+set_module_property AUTHOR "Iztok Jeras"
+set_module_property DISPLAY_NAME "1-wire (onewire)"
+set_module_property TOP_LEVEL_HDL_FILE sockit_owm.v
+set_module_property TOP_LEVEL_HDL_MODULE sockit_owm
+set_module_property INSTANTIATE_IN_SYSTEM_MODULE true
+set_module_property EDITABLE true
+set_module_property ANALYZE_HDL TRUE
+
+set_module_property VALIDATION_CALLBACK validation_callback
+set_module_property ELABORATION_CALLBACK elaboration_callback
+
+# TODO add_documentation_link
+
+# RTL files
+add_file sockit_owm.v {SYNTHESIS SIMULATION}
+
+# parameters
+add_parameter BDW INTEGER
+set_parameter_property BDW DESCRIPTION "CPU interface data bus width"
+#set_parameter_property BDW DISPLAY_NAME BDW
+set_parameter_property BDW DISPLAY_HINT "radio"
+set_parameter_property BDW DEFAULT_VALUE 32
+set_parameter_property BDW ALLOWED_RANGES {8 32}
+set_parameter_property BDW UNITS bits
+set_parameter_property BDW ENABLED false
+set_parameter_property BDW AFFECTS_GENERATION false
+set_parameter_property BDW HDL_PARAMETER true
+
+add_parameter OVD_E BOOLEAN
+set_parameter_property OVD_E DESCRIPTION "Implementation of overdrive enable, disabling it can spare a small amount of logic."
+#set_parameter_property OVD_E DISPLAY_NAME OVD_E
+set_parameter_property OVD_E DEFAULT_VALUE 1
+set_parameter_property OVD_E UNITS None
+set_parameter_property OVD_E AFFECTS_GENERATION false
+set_parameter_property OVD_E HDL_PARAMETER true
+
+add_parameter OWN INTEGER
+set_parameter_property OWN DESCRIPTION "Nummber of 1-wire channels"
+#set_parameter_property OWN DISPLAY_NAME OWN
+#set_parameter_property BTP_N DISPLAY_HINT "drop-down"
+set_parameter_property OWN DEFAULT_VALUE 1
+set_parameter_property OWN ALLOWED_RANGES {1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16}
+set_parameter_property OWN AFFECTS_GENERATION false
+set_parameter_property OWN AFFECTS_ELABORATION true
+set_parameter_property OWN HDL_PARAMETER true
+
+add_parameter BTP_N STRING
+set_parameter_property BTP_N DESCRIPTION "Base time period for normal mode"
+#set_parameter_property BTP_N DISPLAY_NAME BTP_N
+set_parameter_property BTP_N DISPLAY_HINT "radio"
+set_parameter_property BTP_N DEFAULT_VALUE "5.0"
+set_parameter_property BTP_N ALLOWED_RANGES {"5.0:5.0us (preferred)" "7.5:7.5us" "6.0:6.0us - 7.5us"}
+set_parameter_property BTP_N AFFECTS_GENERATION false
+set_parameter_property BTP_N HDL_PARAMETER true
+
+add_parameter BTP_O STRING
+set_parameter_property BTP_O DESCRIPTION "Base time period for overdrive mode"
+#set_parameter_property BTP_O DISPLAY_NAME BTP_N
+set_parameter_property BTP_O DISPLAY_HINT "radio"
+set_parameter_property BTP_O DEFAULT_VALUE "1.0"
+set_parameter_property BTP_O ALLOWED_RANGES {"1.0:1.0us (preferred)" "0.5:0.5us - 0.66us"}
+set_parameter_property BTP_O AFFECTS_GENERATION false
+set_parameter_property BTP_O HDL_PARAMETER true
+
+add_parameter F_CLK INTEGER
+set_parameter_property F_CLK SYSTEM_INFO {CLOCK_RATE clock_reset}
+set_parameter_property F_CLK DISPLAY_NAME F_CLK
+set_parameter_property F_CLK DESCRIPTION "System clock frequency"
+set_parameter_property F_CLK UNITS megahertz
+
+add_parameter CDR_N POSITIVE
+set_parameter_property CDR_N DERIVED true
+set_parameter_property CDR_N DESCRIPTION "Clock divider ratio for normal mode"
+set_parameter_property CDR_N DISPLAY_NAME CDR_N
+set_parameter_property CDR_N DEFAULT_VALUE 5
+set_parameter_property CDR_N AFFECTS_GENERATION false
+set_parameter_property CDR_N HDL_PARAMETER true
+
+add_parameter CDR_O POSITIVE
+set_parameter_property CDR_O DERIVED true
+set_parameter_property CDR_O DESCRIPTION "Clock divider ratio for overdrive mode"
+set_parameter_property CDR_O DISPLAY_NAME CDR_O
+set_parameter_property CDR_O DEFAULT_VALUE 1
+set_parameter_property CDR_O AFFECTS_GENERATION false
+set_parameter_property CDR_O HDL_PARAMETER true
+
+add_display_item "Base time period options" BTP_N parameter
+add_display_item "Base time period options" BTP_O parameter
+add_display_item "Clock dividers" F_CLK parameter
+add_display_item "Clock dividers" CDR_N parameter
+add_display_item "Clock dividers" CDR_O parameter
+
+# connection point clock_reset
+add_interface clock_reset clock end
+
+set_interface_property clock_reset ENABLED true
+
+add_interface_port clock_reset clk clk Input 1
+add_interface_port clock_reset rst reset Input 1
+
+# connection point s1
+add_interface s1 avalon end
+set_interface_property s1 addressAlignment DYNAMIC
+set_interface_property s1 associatedClock clock_reset
+set_interface_property s1 burstOnBurstBoundariesOnly false
+set_interface_property s1 explicitAddressSpan 0
+set_interface_property s1 holdTime 0
+set_interface_property s1 isMemoryDevice false
+set_interface_property s1 isNonVolatileStorage false
+set_interface_property s1 linewrapBursts false
+set_interface_property s1 maximumPendingReadTransactions 0
+set_interface_property s1 printableDevice false
+set_interface_property s1 readLatency 0
+set_interface_property s1 readWaitStates 0
+set_interface_property s1 readWaitTime 0
+set_interface_property s1 setupTime 0
+set_interface_property s1 timingUnits Cycles
+set_interface_property s1 writeWaitTime 0
+
+set_interface_property s1 ASSOCIATED_CLOCK clock_reset
+set_interface_property s1 ENABLED true
+
+add_interface_port s1 bus_read read Input 1
+add_interface_port s1 bus_write write Input 1
+add_interface_port s1 bus_writedata writedata Input BDW
+add_interface_port s1 bus_readdata readdata Output BDW
+
+# connection point irq
+add_interface irq interrupt end
+set_interface_property irq associatedClock clock_reset
+set_interface_property irq associatedAddressablePoint s1
+
+set_interface_property irq ASSOCIATED_CLOCK clock_reset
+set_interface_property irq ENABLED true
+
+add_interface_port irq bus_interrupt irq Output 1
+
+# connection point conduit
+add_interface ext conduit end
+
+set_interface_property ext ENABLED true
+
+add_interface_port ext onewire_p export Output 1
+add_interface_port ext onewire_e export Output 1
+add_interface_port ext onewire_i export Input 1
+
+proc validation_callback {} {
+ # check if overdrive is enabled
+ set ovd [get_parameter_value OVD_E]
+ # get clock frequency in Hz
+ set f [get_parameter_value F_CLK]
+ # get base time periods
+ set btp_n [get_parameter_value BTP_N]
+ set btp_o [get_parameter_value BTP_O]
+ # disable editing od dividers
+ set_parameter_property BTP_O ENABLED [expr {$ovd ? "true" : "false"}]
+ # compute normal mode divider
+ if {$btp_n=="5.0"} {
+ set d_n [expr {$f/200000}]
+ set t_n [expr {1000000.0/($f/$d_n)}]
+ set e_n [expr {$t_n/5.0-1}]
+ } elseif {$btp_n=="7.5"} {
+ set d_n [expr {$f/133333}]
+ set t_n [expr {1000000.0/($f/$d_n)}]
+ set e_n [expr {$t_n/7.5-1}]
+ } elseif {$btp_n=="6.0"} {
+ set d_n [expr {$f/133333}]
+ set t_n [expr {1000000.0/($f/$d_n)}]
+ if {(6.0<=$t_n) && ($t_n<=7.5)} {
+ set e_n 0.0
+ } else {
+ set e_n [expr {$t_n/6.0-1}]
+ }
+ }
+ # compute overdrive mode divider
+ if {$btp_o=="1.0"} {
+ set d_o [expr {$f/1000000}]
+ set t_o [expr {1000000.0/($f/$d_o)}]
+ set e_o [expr {$t_o/1.0-1}]
+ } elseif {$btp_o=="0.5"} {
+ set d_o [expr {$f/1500000}]
+ set t_o [expr {1000000.0/($f/$d_o)}]
+ if {(0.5<=$t_o) && ($t_o<=(2.0/3))} {
+ set e_o 0.0
+ } else {
+ set e_o [expr {$t_o/0.5-1}]
+ }
+ }
+ # set divider values
+ set_parameter_value CDR_N $d_n
+ if {$ovd} {set_parameter_value CDR_O $d_o}
+ # report BTP values and relative errors
+ send_message info "BTP_N (normal mode 'base time period') is [format %.2f $t_n], relative error is [format %.1f [expr {$e_n*100}]]%."
+ send_message info "BTP_O (overdrive mode 'base time period') is [format %.2f $t_o], relative error is [format %.1f [expr {$e_o*100}]]%."
+ # repport validatio errors if relative error are outside accepted bounds (2%)
+ if {abs($e_n)>0.02} {send_message error "BTP_N is outside accepted bounds (relative error > 2%). Use a different 'base time period' or system frequency."}
+ if {abs($e_o)>0.02} {send_message error "BTP_O is outside accepted bounds (relative error > 2%). Use a different 'base time period' or system frequency."}
+}
+
+proc elaboration_callback {} {
+ # add software defines
+ set_module_assignment embeddedsw.CMacro.OWN [get_parameter_value OWN ]
+ set_module_assignment embeddedsw.CMacro.OVD_E [expr {[get_parameter_value OVD_E]?1:0}]
+ set_module_assignment embeddedsw.CMacro.BTP_N [get_parameter_value BTP_N]
+ set_module_assignment embeddedsw.CMacro.BTP_O [get_parameter_value BTP_O]
+}
Index: sockit_owm/trunk/iverilog_gtkwave.scr
===================================================================
--- sockit_owm/trunk/iverilog_gtkwave.scr (nonexistent)
+++ sockit_owm/trunk/iverilog_gtkwave.scr (revision 2)
@@ -0,0 +1,14 @@
+#!/bin/bash
+
+# cleanup first
+rm onewire.out
+rm onewire.vcd
+
+# compile the verilog sources (testbench and RTL)
+iverilog -o onewire.out onewire_tb.v sockit_owm.v onewire_slave_model.v
+
+# run the simulation
+vvp onewire.out
+
+# open the waveform and detach it
+gtkwave onewire.vcd gtkwave.sav &
sockit_owm/trunk/iverilog_gtkwave.scr
Property changes :
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property