summaryrefslogtreecommitdiffstatshomepage
path: root/3rdparty/lzma/CPP/7zip/UI/Explorer
ModeNameSize
-rw-r--r--MyMessages.cpp743logstatsplainblame
-rw-r--r--MyMessages.h391logstatsplainblame
='n26' href='#n26'>26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270
// license:BSD-3-Clause
// copyright-holders:smf
/*
 * DS2401
 *
 * Dallas Semiconductor
 * Silicon Serial Number
 *
 */

#include "emu.h"
#include "machine/ds2401.h"

#define VERBOSE_LEVEL 0

inline void ds2401_device::verboselog(int n_level, const char *s_fmt, ...)
{
	if(VERBOSE_LEVEL >= n_level)
	{
		va_list v;
		char buf[32768];
		va_start(v, s_fmt);
		vsprintf(buf, s_fmt, v);
		va_end(v);
		logerror("ds2401 %s %s: %s", tag(), machine().describe_context(), buf);
	}
}

// device type definition
const device_type DS2401 = &device_creator<ds2401_device>;

ds2401_device::ds2401_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
	: device_t(mconfig, DS2401, "DS2401", tag, owner, clock, "ds2401", __FILE__)
{
}

void ds2401_device::device_start()
{
	t_samp = attotime::from_usec( 30);
	t_rdv  = attotime::from_usec( 30);
	t_rstl = attotime::from_usec(480);
	t_pdh  = attotime::from_usec( 30);
	t_pdl  = attotime::from_usec(120);

	m_rx = true;
	m_tx = true;

	save_item(NAME(m_state));
	save_item(NAME(m_bit));
	save_item(NAME(m_byte));
	save_item(NAME(m_shift));
	save_item(NAME(m_rx));
	save_item(NAME(m_tx));

	m_timer_main  = timer_alloc(TIMER_MAIN);
	m_timer_reset = timer_alloc(TIMER_RESET);
}

void ds2401_device::device_reset()
{
	m_state = STATE_IDLE;
	m_bit = 0;
	m_byte = 0;
	m_shift = 0;
	m_rx = true;
	m_tx = true;

	if(m_region)
	{
		if(m_region->bytes() == SIZE_DATA)
		{
			memcpy(m_data, m_region->base(), SIZE_DATA);
			return;
		}

		logerror("ds2401 %s: Wrong region length for id data, expected 0x%x, got 0x%x\n", tag(), SIZE_DATA, m_region->bytes());
	}
	else
	{
		logerror("ds2401 %s: Warning, no id provided, answer will be all zeroes.\n", tag());
	}

	memset(m_data, 0, SIZE_DATA);
}

void ds2401_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr)
{
	switch(id)
	{
	case TIMER_RESET:
		verboselog(1, "timer_reset\n");
		m_state = STATE_RESET;
		m_timer_reset->adjust(attotime::never);
		break;

	case TIMER_MAIN:
		switch(m_state)
		{
		case STATE_RESET1:
			verboselog(2, "timer_main state_reset1 %d\n", m_rx);
			m_tx = false;
			m_state = STATE_RESET2;
			m_timer_main->adjust(t_pdl);
			break;

		case STATE_RESET2:
			verboselog(2, "timer_main state_reset2 %d\n", m_rx);
			m_tx = true;
			m_bit = 0;
			m_shift = 0;
			m_state = STATE_COMMAND;
			break;

		case STATE_COMMAND:
			verboselog(2, "timer_main state_command %d\n", m_rx);

			m_shift >>= 1;
			if(m_rx)
			{
				m_shift |= 0x80;
			}

			m_bit++;
			if(m_bit == 8)
			{
				switch(m_shift)
				{
				case COMMAND_READROM:
					verboselog(1, "timer_main readrom\n");
					m_bit = 0;
					m_byte = 0;
					m_state = STATE_READROM;
					break;

				default:
					verboselog(0, "timer_main command not handled %02x\n", m_shift);
					m_state = STATE_IDLE;
					break;
				}
			}
			break;

		case STATE_READROM:
			m_tx = true;

			if( m_byte == SIZE_DATA )
			{
				verboselog(1, "timer_main readrom finished\n");
				m_state = STATE_IDLE;
			}
			else
			{
				verboselog(2, "timer_main readrom window closed\n");
			}
			break;
		default:
			verboselog(0, "timer_main state not handled: %d\n", m_state);
			break;
		}
	}
}

WRITE_LINE_MEMBER( ds2401_device::write )
{
	verboselog(1, "write(%d)\n", state);

	if(!state && m_rx)
	{
		switch(m_state)
		{
		case STATE_IDLE:
			break;

		case STATE_COMMAND:
			verboselog(2, "state_command\n");
			m_timer_main->adjust(t_samp);
			break;

		case STATE_READROM:
			if(!m_bit)
			{
				m_shift = m_data[7 - m_byte];
				verboselog(1, "<- data %02x\n", m_shift);
			}

			m_tx = m_shift & 1;
			m_shift >>= 1;

			m_bit++;
			if(m_bit == 8)
			{
				m_bit = 0;
				m_byte++;
			}

			verboselog(2, "state_readrom %d\n", m_tx);
			m_timer_main->adjust(t_rdv);
			break;

		default:
			verboselog(0, "state not handled: %d\n", m_state );
			break;
		}

		m_timer_reset->adjust(t_rstl);
	}
	else if(state && !m_rx)
	{
		switch(m_state)
		{
		case STATE_RESET:
			m_state = STATE_RESET1;
			m_timer_main->adjust(t_pdh);
			break;
		}

		m_timer_reset->adjust(attotime::never);
	}

	m_rx = state;
}

READ_LINE_MEMBER( ds2401_device::read )
{
	verboselog(2, "read %d\n", m_tx && m_rx);
	return m_tx && m_rx;
}

UINT8 ds2401_device::direct_read(int index)
{
	return m_data[index];
}

/*

app74.pdf

Under normal circumstances an ibutton will sample the line 30us after the falling edge of the start condition.
The internal time base of ibutton may deviate from its nominal value. The allowed tollerance band ranges from 15us to 60us.
This means that the actual slave sampling may occur anywhere from 15 and 60us after the start condition, which is a ratio of 1 to 4.
During this time frame the voltage on the data line must stay below Vilmax or above Vihmin.

In the 1-Wire system, the logical values 1 and 0 are represented by certain voltages in special waveforms.
The waveforms needed to write commands or data to ibuttons are called write-1 and write-0 time slots.
The duration of a low pulse to write a 1 must be shorter than 15us.
To write a 0, the duration of the low pulse must be at least 60us to cope with worst-case conditions.

The duration of the active part of a time slot can be extended beyond 60us.
The maximum extension is limited by the fact that a low pulse of a duration of at least eight active time slots ( 480us ) is defined as a Reset Pulse.
Allowing the same worst-case tolerance ratio, a low pulse of 120us might be sufficient for a reset.
This limits the extension of the active part of a time slot to a maximum of 120us to prevent misinterpretation with reset.

Commands and data are sent to ibuttons by combining write-0 and write-1 time slots.
To read data, the master has to generate read-data time slots to define the start condition of each bit.
The read-data time slots looks essentially the same as a write-1 time slot from the masters point of view.
Starting at the high-to-low transition, the ibuttons sends 1 bit of its addressed contents.
If the data bit is a 1, the ibutton leaves the pulse unchanged.
If the data bit is a 0, the ibutton will pull the data line low for 15us.
In this time frame data is valid for reading by the master.
The duration of the low pulse sent by the master should be a minimum of 1us with a maximum value as short as possible to maximize the master sampling window.

The Reset Pulse provides a clear starting condition that supersedes any time slot synchronisation.
It is defined as single low pulse of minimum duration of eight time slots or 480us followed by a Reset-high time tRSTH of another 480us.
After a Reset Pulse has been sent, the ibutton will wait for the time tPDH and then generate a Pulse-Presence Pulse of duration tPDL.
No other communication on the 1-Wire bus is allowed during tRSTH.

There are 1,000 microseconds in a millisecond, and 1,000 milliseconds in a second.
Thus, there are 1,000,000 microseconds in a second. Why is it "usec"?
The "u" is supposed to look like the Greek letter Mu that we use for "micro". .
*/