|
|
|
|
#include "owi.h"
|
|
|
|
|
#include "delay.h"
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include "uart.h"
|
|
|
|
|
|
|
|
|
|
#ifndef OWI_STRONG_DRIVE_HIGH_US
|
|
|
|
|
#define OWI_STRONG_DRIVE_HIGH_US 5u
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/* 내부 상태 */
|
|
|
|
|
static uint32_t bit_period_us = OWI_BIT_PERIOD_US;
|
|
|
|
|
static uint8_t g_owi_timeout_latched = 0;
|
|
|
|
|
|
|
|
|
|
static uint16_t g_owi_last_timeout_byte_index = 0xFFFFu;
|
|
|
|
|
static uint8_t g_owi_last_timeout_bit_index = 0xFFu;
|
|
|
|
|
|
|
|
|
|
static uint16_t g_owi_current_read_byte_index = 0u;
|
|
|
|
|
static uint8_t g_owi_current_read_bit_index = 0u;
|
|
|
|
|
|
|
|
|
|
/* =========================================================
|
|
|
|
|
* GPIO helpers (P70 / HW Open-Drain)
|
|
|
|
|
* - LOW : 출력 모드 + 0
|
|
|
|
|
* - HIGH : 입력(Hi-Z)로 release
|
|
|
|
|
* ========================================================= */
|
|
|
|
|
void GPIO_Clear(void)
|
|
|
|
|
{
|
|
|
|
|
OWI_PORT_POM |= (uint8_t)OWI_PIN_MASK;
|
|
|
|
|
OWI_PORT_P &= (uint8_t)~OWI_PIN_MASK;
|
|
|
|
|
OWI_PORT_PM &= (uint8_t)~OWI_PIN_MASK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GPIO_Input(void)
|
|
|
|
|
{
|
|
|
|
|
OWI_PORT_POM |= (uint8_t)OWI_PIN_MASK;
|
|
|
|
|
OWI_PORT_P |= (uint8_t)OWI_PIN_MASK;
|
|
|
|
|
OWI_PORT_PM |= (uint8_t)OWI_PIN_MASK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int GPIO_Read(void)
|
|
|
|
|
{
|
|
|
|
|
return (OWI_PORT_P & (uint8_t)OWI_PIN_MASK) ? 1 : 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void OWI_Release(void)
|
|
|
|
|
{
|
|
|
|
|
OWI_PORT_POM |= (uint8_t)OWI_PIN_MASK;
|
|
|
|
|
OWI_PORT_P |= (uint8_t)OWI_PIN_MASK;
|
|
|
|
|
OWI_PORT_PM |= (uint8_t)OWI_PIN_MASK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void GPIO_StrongDriveHighKick(uint32_t kick_us)
|
|
|
|
|
{
|
|
|
|
|
/* 1) 우선 release 상태 */
|
|
|
|
|
OWI_Release();
|
|
|
|
|
|
|
|
|
|
/* 2) 라인이 LOW면 강제 HIGH 금지 */
|
|
|
|
|
if (!GPIO_Read()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* 3) 오픈드레인 OFF -> push-pull */
|
|
|
|
|
OWI_PORT_POM &= (uint8_t)~OWI_PIN_MASK;
|
|
|
|
|
|
|
|
|
|
/* 4) 출력 HIGH */
|
|
|
|
|
OWI_PORT_P |= (uint8_t)OWI_PIN_MASK;
|
|
|
|
|
OWI_PORT_PM &= (uint8_t)~OWI_PIN_MASK;
|
|
|
|
|
|
|
|
|
|
delay_us(kick_us);
|
|
|
|
|
|
|
|
|
|
/* 5) 다시 open-drain + release */
|
|
|
|
|
OWI_PORT_POM |= (uint8_t)OWI_PIN_MASK;
|
|
|
|
|
OWI_Release();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GPIO_ForceHighKick(void)
|
|
|
|
|
{
|
|
|
|
|
GPIO_StrongDriveHighKick(OWI_STRONG_DRIVE_HIGH_US);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void OWI_DriveLow(void)
|
|
|
|
|
{
|
|
|
|
|
OWI_PORT_POM |= (uint8_t)OWI_PIN_MASK;
|
|
|
|
|
OWI_PORT_P &= (uint8_t)~OWI_PIN_MASK;
|
|
|
|
|
OWI_PORT_PM &= (uint8_t)~OWI_PIN_MASK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* =========================================================
|
|
|
|
|
* Diagnostics
|
|
|
|
|
* ========================================================= */
|
|
|
|
|
uint8_t OWI_HasTimeout(void)
|
|
|
|
|
{
|
|
|
|
|
return g_owi_timeout_latched;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void OWI_ClearTimeout(void)
|
|
|
|
|
{
|
|
|
|
|
g_owi_timeout_latched = 0;
|
|
|
|
|
g_owi_last_timeout_byte_index = 0xFFFFu;
|
|
|
|
|
g_owi_last_timeout_bit_index = 0xFFu;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint16_t OWI_GetLastTimeoutByteIndex(void)
|
|
|
|
|
{
|
|
|
|
|
return g_owi_last_timeout_byte_index;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint8_t OWI_GetLastTimeoutBitIndex(void)
|
|
|
|
|
{
|
|
|
|
|
return g_owi_last_timeout_bit_index;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* =========================================================
|
|
|
|
|
* OWI Init
|
|
|
|
|
* ========================================================= */
|
|
|
|
|
void OWI_Init(uint32_t bit_time_us)
|
|
|
|
|
{
|
|
|
|
|
bit_period_us = bit_time_us;
|
|
|
|
|
(void)bit_period_us; /* 현재 타이밍은 매크로(TBIT) 사용 */
|
|
|
|
|
|
|
|
|
|
OWI_PORT_POM |= (uint8_t)OWI_PIN_MASK;
|
|
|
|
|
|
|
|
|
|
/* 외부 pull-up 사용 */
|
|
|
|
|
OWI_PORT_PU &= (uint8_t)~OWI_PIN_MASK;
|
|
|
|
|
|
|
|
|
|
OWI_ClearTimeout();
|
|
|
|
|
|
|
|
|
|
/* idle = release */
|
|
|
|
|
GPIO_Input();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* =========================================================
|
|
|
|
|
* Start/Stop/Secure
|
|
|
|
|
* - 시퀀스는 유지
|
|
|
|
|
* - strong만 선택적으로 사용
|
|
|
|
|
* ========================================================= */
|
|
|
|
|
void OWI_Start(void)
|
|
|
|
|
{
|
|
|
|
|
GPIO_Clear();
|
|
|
|
|
delay_us(TSTART_HOLD);
|
|
|
|
|
|
|
|
|
|
GPIO_Input();
|
|
|
|
|
delay_us(TBIT);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void OWI_Stop(void)
|
|
|
|
|
{
|
|
|
|
|
GPIO_Input();
|
|
|
|
|
delay_us(TSTOP_LOW);
|
|
|
|
|
delay_us(TIDLE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void OWI_StopWrite(void)
|
|
|
|
|
{
|
|
|
|
|
OWI_Release();
|
|
|
|
|
delay_us(TSTOP_LOW);
|
|
|
|
|
delay_us(TIDLE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void OWI_StopRead(void)
|
|
|
|
|
{
|
|
|
|
|
OWI_DriveLow();
|
|
|
|
|
delay_us(TSTOP_LOW);
|
|
|
|
|
OWI_Release();
|
|
|
|
|
delay_us(TIDLE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void OWI_SecureStop(void)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
GPIO_Clear();
|
|
|
|
|
delay_us(SECURE_HIGH);
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < (int)SECURE_TOGGLE_COUNT; i++) {
|
|
|
|
|
|
|
|
|
|
/* HIGH 구간 */
|
|
|
|
|
GPIO_Input();
|
|
|
|
|
delay_us(SECURE_TOGGLE_HIGH);
|
|
|
|
|
|
|
|
|
|
/* LOW 구간 */
|
|
|
|
|
GPIO_Clear();
|
|
|
|
|
delay_us(SECURE_TOGGLE_LOW);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* 마지막 HIGH */
|
|
|
|
|
GPIO_Input();
|
|
|
|
|
delay_us(SECURE_HIGH);
|
|
|
|
|
|
|
|
|
|
/* 이어서 기존 시퀀스 유지 */
|
|
|
|
|
GPIO_Clear();
|
|
|
|
|
delay_us(TSTART_HOLD);
|
|
|
|
|
GPIO_Input();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* =========================================================
|
|
|
|
|
* Bit/Byte IO
|
|
|
|
|
* - HIGH -> LOW 형식 유지
|
|
|
|
|
* - strong만 선택적으로 사용
|
|
|
|
|
* ========================================================= */
|
|
|
|
|
void OWI_WriteBit(int bit)
|
|
|
|
|
{
|
|
|
|
|
uint32_t t_low = bit ? (uint32_t)TLOW_1 : (uint32_t)TLOW_0;
|
|
|
|
|
uint32_t t_high = (uint32_t)TBIT - t_low;
|
|
|
|
|
|
|
|
|
|
/* HIGH 구간 */
|
|
|
|
|
OWI_Release();
|
|
|
|
|
delay_us(t_high);
|
|
|
|
|
|
|
|
|
|
/* LOW 구간 */
|
|
|
|
|
OWI_DriveLow();
|
|
|
|
|
delay_us(t_low);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void OWI_WriteByte(uint8_t data)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
for (i = 7; i >= 0; i--) {
|
|
|
|
|
OWI_WriteBit((data >> i) & 0x01u);
|
|
|
|
|
}
|
|
|
|
|
GPIO_Input();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint8_t OWI_ReadBit(void)
|
|
|
|
|
{
|
|
|
|
|
uint8_t bit;
|
|
|
|
|
int timeout = (int)(bit_period_us * 2u);
|
|
|
|
|
|
|
|
|
|
while (!(GPIO_Read()) && timeout-- > 0) {
|
|
|
|
|
delay_us(1u);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (timeout <= 0) {
|
|
|
|
|
if (!g_owi_timeout_latched) {
|
|
|
|
|
// char msg[64];
|
|
|
|
|
|
|
|
|
|
g_owi_timeout_latched = 1;
|
|
|
|
|
g_owi_last_timeout_byte_index = g_owi_current_read_byte_index;
|
|
|
|
|
g_owi_last_timeout_bit_index = g_owi_current_read_bit_index;
|
|
|
|
|
|
|
|
|
|
// sprintf(msg, "OWI Timeout B%u b%u\r\n",
|
|
|
|
|
// (unsigned)g_owi_last_timeout_byte_index,
|
|
|
|
|
// (unsigned)g_owi_last_timeout_bit_index);
|
|
|
|
|
// HOST_PRINT(msg);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* 기존 0xFF는 데이터를 오염시킴 */
|
|
|
|
|
return 0u;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
delay_us((bit_period_us * 1u) / 2u);
|
|
|
|
|
bit = (uint8_t)GPIO_Read();
|
|
|
|
|
delay_us((bit_period_us * 2u) / 5u);
|
|
|
|
|
|
|
|
|
|
return (bit ? 1u : 0u);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint8_t OWI_ReadByte(void)
|
|
|
|
|
{
|
|
|
|
|
uint8_t data = 0;
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
for (i = 7; i >= 0; i--) {
|
|
|
|
|
g_owi_current_read_bit_index = (uint8_t)(7 - i);
|
|
|
|
|
data |= (uint8_t)(OWI_ReadBit() << i);
|
|
|
|
|
}
|
|
|
|
|
return data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* =========================================================
|
|
|
|
|
* Debug Print
|
|
|
|
|
* ========================================================= */
|
|
|
|
|
void OWI_T_ReadBytesAndPrint(int length)
|
|
|
|
|
{
|
|
|
|
|
uint8_t buf[129];
|
|
|
|
|
int i;
|
|
|
|
|
char uart_buf[8];
|
|
|
|
|
char tmp_buf[8];
|
|
|
|
|
uint8_t va0, va1;
|
|
|
|
|
|
|
|
|
|
if (length > 129) length = 129;
|
|
|
|
|
if (length <= 0) return;
|
|
|
|
|
|
|
|
|
|
OWI_ClearTimeout();
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < length; i++) {
|
|
|
|
|
g_owi_current_read_byte_index = (uint16_t)i;
|
|
|
|
|
buf[i] = OWI_ReadByte();
|
|
|
|
|
if (OWI_HasTimeout()) break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sprintf(uart_buf, "%02X ", buf[0]);
|
|
|
|
|
strcpy(tmp_buf, uart_buf);
|
|
|
|
|
HOST_PRINT(tmp_buf);
|
|
|
|
|
|
|
|
|
|
for (i = 1; i < length; i += 2) {
|
|
|
|
|
va0 = buf[i];
|
|
|
|
|
va1 = (uint8_t)((i + 1 < length) ? buf[i + 1] : 0u);
|
|
|
|
|
|
|
|
|
|
delay(10000);
|
|
|
|
|
sprintf(uart_buf, "%02X%02X ", va0, va1);
|
|
|
|
|
strcpy(tmp_buf, uart_buf);
|
|
|
|
|
HOST_PRINT(tmp_buf);
|
|
|
|
|
delay(10000);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* =========================================================
|
|
|
|
|
* Command / Diagnostic
|
|
|
|
|
* ========================================================= */
|
|
|
|
|
#define OWI_MAX_RETRY 2
|
|
|
|
|
#define OWI_RECOVERY_MIN_US 500
|
|
|
|
|
|
|
|
|
|
void OWI_A_CommandMode(const uint8_t *tx_data, uint8_t tx_len, uint8_t id)
|
|
|
|
|
{
|
|
|
|
|
uint8_t CMD_LIST[6][4] = {
|
|
|
|
|
{0x50,0x2E,0x00,0x00},
|
|
|
|
|
{0x50,0x2E,0x01,0x00},
|
|
|
|
|
{0x50,0x2E,0x02,0x00},
|
|
|
|
|
{0x50,0x2E,0x16,0x00},
|
|
|
|
|
{0x50,0x2E,0x41,0x00},
|
|
|
|
|
{0x50,0x2E,0x00,0x00}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
char line[128];
|
|
|
|
|
size_t n = 0;
|
|
|
|
|
uint8_t rx[RAM_BYTES];
|
|
|
|
|
int i, j, retry, all_ff;
|
|
|
|
|
uint8_t read_address = 0x51;
|
|
|
|
|
|
|
|
|
|
delay_us(7000);
|
|
|
|
|
|
|
|
|
|
for (j = 0; j < 6; j++) {
|
|
|
|
|
OWI_SecureStop();
|
|
|
|
|
for (i = 0; i < 4; i++) {
|
|
|
|
|
OWI_WriteByte(CMD_LIST[j][i]);
|
|
|
|
|
}
|
|
|
|
|
OWI_Stop();
|
|
|
|
|
|
|
|
|
|
delay_us(OWI_RECOVERY_MIN_US);
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < RAM_BYTES; i++) rx[i] = 0xFFu;
|
|
|
|
|
|
|
|
|
|
for (retry = 0; retry <= OWI_MAX_RETRY; retry++) {
|
|
|
|
|
delay_us(OWI_RECOVERY_MIN_US);
|
|
|
|
|
|
|
|
|
|
OWI_ClearTimeout();
|
|
|
|
|
OWI_SecureStop();
|
|
|
|
|
OWI_WriteByte(read_address);
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < RAM_BYTES; i++) {
|
|
|
|
|
g_owi_current_read_byte_index = (uint16_t)i;
|
|
|
|
|
rx[i] = OWI_ReadByte();
|
|
|
|
|
if (OWI_HasTimeout()) break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
OWI_Stop();
|
|
|
|
|
|
|
|
|
|
all_ff = 1;
|
|
|
|
|
for (i = 0; i < RAM_BYTES; i++) {
|
|
|
|
|
if (rx[i] != 0xFFu) {
|
|
|
|
|
all_ff = 0;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!all_ff && !OWI_HasTimeout()) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (retry == OWI_MAX_RETRY) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
n += sprintf(&line[n], "%02X%02X", rx[1], rx[2]);
|
|
|
|
|
line[n++] = ',';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (tx_data != NULL && tx_len == 3u) {
|
|
|
|
|
for (retry = 0; retry <= OWI_MAX_RETRY; retry++) {
|
|
|
|
|
|
|
|
|
|
OWI_ClearTimeout();
|
|
|
|
|
OWI_SecureStop();
|
|
|
|
|
OWI_WriteByte((uint8_t)(id << 1));
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < 3; i++) {
|
|
|
|
|
OWI_WriteByte(tx_data[i]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
OWI_Stop();
|
|
|
|
|
delay_us(OWI_RECOVERY_MIN_US);
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < RAM_BYTES; i++) rx[i] = 0xFFu;
|
|
|
|
|
|
|
|
|
|
OWI_SecureStop();
|
|
|
|
|
OWI_WriteByte((uint8_t)((id << 1) | 1u));
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < RAM_BYTES; i++) {
|
|
|
|
|
g_owi_current_read_byte_index = (uint16_t)i;
|
|
|
|
|
rx[i] = OWI_ReadByte();
|
|
|
|
|
if (OWI_HasTimeout()) break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
OWI_Stop();
|
|
|
|
|
|
|
|
|
|
all_ff = 1;
|
|
|
|
|
for (i = 0; i < RAM_BYTES; i++) {
|
|
|
|
|
if (rx[i] != 0xFFu) {
|
|
|
|
|
all_ff = 0;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!all_ff && !OWI_HasTimeout()) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (retry == OWI_MAX_RETRY) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
n += sprintf(&line[n], "%02X%02X", rx[1], rx[2]);
|
|
|
|
|
} else {
|
|
|
|
|
n += sprintf(&line[n], "0000");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
line[n++] = '\r';
|
|
|
|
|
line[n++] = '\n';
|
|
|
|
|
line[n] = '\0';
|
|
|
|
|
|
|
|
|
|
HOST_PRINT(line);
|
|
|
|
|
delay(10000);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void OWI_disable(void)
|
|
|
|
|
{
|
|
|
|
|
HOST_PRINT("51\r\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void OWI_T_CommandMode(const uint8_t *tx_data, uint8_t tx_len, uint8_t id)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
delay_us(10000);
|
|
|
|
|
OWI_Init(OWI_BIT_PERIOD_US);
|
|
|
|
|
|
|
|
|
|
OWI_SecureStop();
|
|
|
|
|
OWI_WriteByte((uint8_t)(id << 1));
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < (int)tx_len; i++) {
|
|
|
|
|
OWI_WriteByte(tx_data[i]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
OWI_Stop();
|
|
|
|
|
HOST_PRINT("51\r\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void OWI_CommandMode(const uint8_t *tx_data, uint8_t tx_len, uint8_t id)
|
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
OWI_ClearTimeout();
|
|
|
|
|
|
|
|
|
|
OWI_SecureStop();
|
|
|
|
|
OWI_WriteByte((uint8_t)(id << 1));
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < (int)tx_len; i++) {
|
|
|
|
|
OWI_WriteByte(tx_data[i]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
OWI_Stop();
|
|
|
|
|
HOST_PRINT("51\r\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void OWI_ReadBytesAndPrint(int length, uint8_t id)
|
|
|
|
|
{
|
|
|
|
|
static uint8_t buf[600];
|
|
|
|
|
static char out[2 * 600 + 40];
|
|
|
|
|
int i;
|
|
|
|
|
uint16_t p = 0;
|
|
|
|
|
|
|
|
|
|
if (length <= 0) {
|
|
|
|
|
HOST_PRINT("Err:read_len_nonzero\r\n");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (length > 600) length = 600;
|
|
|
|
|
|
|
|
|
|
OWI_ClearTimeout();
|
|
|
|
|
|
|
|
|
|
OWI_SecureStop();
|
|
|
|
|
OWI_WriteByte((uint8_t)((id << 1) | 1u));
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < length; i++) {
|
|
|
|
|
g_owi_current_read_byte_index = (uint16_t)i;
|
|
|
|
|
buf[i] = OWI_ReadByte();
|
|
|
|
|
if (OWI_HasTimeout()) break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < length; i++) {
|
|
|
|
|
uint8_t b = buf[i];
|
|
|
|
|
out[p++] = "0123456789ABCDEF"[b >> 4];
|
|
|
|
|
out[p++] = "0123456789ABCDEF"[b & 0x0F];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (OWI_HasTimeout()) {
|
|
|
|
|
p += (uint16_t)sprintf(&out[p], " !TO(B%u b%u)",
|
|
|
|
|
(unsigned)OWI_GetLastTimeoutByteIndex(),
|
|
|
|
|
(unsigned)OWI_GetLastTimeoutBitIndex());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
out[p++] = '\r';
|
|
|
|
|
out[p++] = '\n';
|
|
|
|
|
out[p] = '\0';
|
|
|
|
|
|
|
|
|
|
OWI_StopRead();
|
|
|
|
|
HOST_PRINT(out);
|
|
|
|
|
}
|