Browse Source

modify connect

old-version
gudae 1 month ago
parent
commit
06263ffdd9
  1. BIN
      DefaultBuild/app_cmd_parser.obj
  2. BIN
      DefaultBuild/app_owi_service.obj
  3. BIN
      DefaultBuild/app_result.obj
  4. BIN
      DefaultBuild/app_scheduler.obj
  5. BIN
      DefaultBuild/gatectrl.obj
  6. BIN
      DefaultBuild/multical.abs
  7. 690
      DefaultBuild/multical.map
  8. 3372
      DefaultBuild/multical.mot
  9. BIN
      DefaultBuild/owi.obj
  10. BIN
      DefaultBuild/r_main.obj
  11. BIN
      DefaultBuild/uart.obj
  12. 14
      QualityReport(multical,DefaultBuild).txt
  13. 102
      multical.temp.mtud
  14. 198
      r_main.c
  15. 19
      uart.c

BIN
DefaultBuild/app_cmd_parser.obj

Binary file not shown.

BIN
DefaultBuild/app_owi_service.obj

Binary file not shown.

BIN
DefaultBuild/app_result.obj

Binary file not shown.

BIN
DefaultBuild/app_scheduler.obj

Binary file not shown.

BIN
DefaultBuild/gatectrl.obj

Binary file not shown.

BIN
DefaultBuild/multical.abs

Binary file not shown.

690
DefaultBuild/multical.map

File diff suppressed because it is too large

3372
DefaultBuild/multical.mot

File diff suppressed because it is too large

BIN
DefaultBuild/owi.obj

Binary file not shown.

BIN
DefaultBuild/r_main.obj

Binary file not shown.

BIN
DefaultBuild/uart.obj

Binary file not shown.

14
QualityReport(multical,DefaultBuild).txt

@ -1,13 +1,13 @@
QualityReport QualityReport
2026년 3월 13일 금요일 오전 11:32:23 2026년 3월 16일 월요일 오후 3:13:03
------ Start build(multical, DefaultBuild) ------ ------ Start build(multical, DefaultBuild) ------
------ Build ended(Error:0, Warning:0)(multical, DefaultBuild) ------ ------ Build ended(Error:0, Warning:0)(multical, DefaultBuild) ------
--- SHA1 hash value of output files --- --- SHA1 hash value of output files ---
C:\Users\temp\Desktop\new_fw\DefaultBuild\multical.abs: 27faa0d66d2c305e3d33d9a142ca0c268dd53099 C:\Users\temp\Desktop\new_fw\DefaultBuild\multical.abs: f11e23a50a4b42ef052d2effc091d61f3c612086
C:\Users\temp\Desktop\new_fw\DefaultBuild\multical.mot: e3c9e07123793c5cd6a5bd0e8577a0905c23c28f C:\Users\temp\Desktop\new_fw\DefaultBuild\multical.mot: 630d25b191142533d214fb10f07cdcb7601c85c6
--- System Information --- --- System Information ---
@ -35,13 +35,13 @@ C:\Users\temp\Desktop\new_fw\DefaultBuild\multical.mot: e3c9e07123793c5cd6a5bd0e
C:\Program Files (x86)\Renesas Electronics\CS+\CC C:\Program Files (x86)\Renesas Electronics\CS+\CC
*Memory Usage *Memory Usage
*Private Working Set *Private Working Set
349 MB 376 MB
*Number of GDI Objects *Number of GDI Objects
2774 2741
*Number of USER Objects *Number of USER Objects
1591 1526
*Opened Files *Opened Files
32 editors, 32 files, 233 KB 32 editors, 32 files, 236 KB
--- Build Tool Plug-in Information --- --- Build Tool Plug-in Information ---
RH850 Build tool CC-RH Plug-in RH850 Build tool CC-RH Plug-in

102
multical.temp.mtud

File diff suppressed because one or more lines are too long

198
r_main.c

@ -58,8 +58,8 @@ Includes
#define UART_RX_BUF_SIZE 1024 #define UART_RX_BUF_SIZE 1024
#define RS485_BRIDGE_FIFO_SZ 2048 #define RS485_BRIDGE_FIFO_SZ 2048
#define BRIDGE_IDLE_DONE_US 2000000U // ? 3ms ? ? #define BRIDGE_IDLE_DONE_US 2500000U /* sweep 중 성공 라인 사이 최대 무응답 허용 시간 */
#define BRIDGE_TOTAL_WAIT_US 6000000U #define BRIDGE_TOTAL_WAIT_US 30000000U /* sweep 전체 브리지 최대 대기 시간 */
/* ========================= /* =========================
* UART RX Buffers * UART RX Buffers
@ -695,7 +695,7 @@ static void print_hex_line(CmdSource src, const uint8_t *data, uint16_t len)
OUT_PRINT(src, out); OUT_PRINT(src, out);
} }
static int execute_connect_verify_sequence(CmdSource src, const app_job_t *job) static int run_connect_verify_one_channel(const app_job_t *job, uint8_t ch)
{ {
app_owi_result_t r_write1; app_owi_result_t r_write1;
app_owi_result_t r_read2; app_owi_result_t r_read2;
@ -708,25 +708,7 @@ static int execute_connect_verify_sequence(CmdSource src, const app_job_t *job)
uint8_t attempt; uint8_t attempt;
if (!job) return 0; if (!job) return 0;
if (ch < 1 || ch > 20) return 0;
/* connect 전용 패턴
xNNc_XXX...:owt28006 AABBCC DDEEFF
- id = 0x28
- len = 6
- payload[0..2] = write 3
- payload[3..5] = 3
*/
if (job->type != APP_JOB_PROTO_OW) return 0;
if (job->proto != APP_PROTO_OWIT) return 0;
if (job->id != 0x28u) return 0;
if (job->len != 6u) return 0;
if (job->addr != g_fixed_addr) return 0;
if (job->channel < 1 || job->channel > 20) {
OUT_PRINT(src, "Err:ch_range\r\n");
return 1;
}
memcpy(write1_data, &job->payload[0], 3); memcpy(write1_data, &job->payload[0], 3);
memcpy(expected_tail, &job->payload[3], 3); memcpy(expected_tail, &job->payload[3], 3);
@ -748,8 +730,8 @@ static int execute_connect_verify_sequence(CmdSource src, const app_job_t *job)
Eol_Init(); Eol_Init();
} }
Gate_SetByNum(job->channel, job->hash_on, job->anaout_on, job->check_on); Gate_SetByNum(ch, job->hash_on, job->anaout_on, job->check_on);
GateCtrl_SelectChannel(job->channel); GateCtrl_SelectChannel(ch);
delay_us(30000); delay_us(30000);
@ -771,20 +753,80 @@ static int execute_connect_verify_sequence(CmdSource src, const app_job_t *job)
continue; continue;
} }
/* 4) OR 28 003 -> 실제 칩 결과 읽기 */ /* 4) OR 28 003 */
r_read3 = app_owi_read_basic(0x28u, 3); r_read3 = app_owi_read_basic(0x28u, 3);
if (!r_read3.ok || r_read3.timeout || r_read3.read_len < 3) { if (!r_read3.ok || r_read3.timeout || r_read3.read_len < 3) {
continue; continue;
} }
/* 실제 읽은 3바이트와 기대값 비교 */
if (memcmp(r_read3.data, expected_tail, 3) == 0) { if (memcmp(r_read3.data, expected_tail, 3) == 0) {
OUT_PRINT(src, "Success\r\n");
return 1; return 1;
} }
} }
return 0;
}
static void print_connect_sweep_result(CmdSource src, uint8_t ch, uint8_t ok)
{
char msg[32];
sprintf(msg, "ch%u: %s\r\n", (unsigned)ch, ok ? "Success" : "Fail");
OUT_PRINT(src, msg);
}
static int execute_connect_verify_sequence(CmdSource src, const app_job_t *job)
{
uint8_t ch;
uint8_t success_count = 0;
if (!job) return 0;
/* connect 전용 패턴
xNNc_XXX...:owt28006 AABBCC DDEEFF
- id = 0x28
- len = 6
- payload[0..2] = write 3
- payload[3..5] = 3
*/
if (job->type != APP_JOB_PROTO_OW) return 0;
if (job->proto != APP_PROTO_OWIT) return 0;
if (job->id != 0x28u) return 0;
if (job->len != 6u) return 0;
if (job->addr != g_fixed_addr) return 0;
/* 000 이면 1~20 sweep */
if (job->channel == 0u) {
for (ch = 1; ch <= 20; ch++) {
uint8_t ok = (uint8_t)run_connect_verify_one_channel(job, ch);
if (ok) {
print_connect_sweep_result(src, ch, 1);
success_count++;
}
}
if (success_count == 0u) {
OUT_PRINT(src, "Fail\r\n");
}
send_end_response(src);
return 1;
}
/* 단일 채널 */
if (job->channel < 1 || job->channel > 20) {
OUT_PRINT(src, "Err:ch_range\r\n");
send_end_response(src);
return 1;
}
if (run_connect_verify_one_channel(job, job->channel)) {
OUT_PRINT(src, "Success\r\n");
} else {
OUT_PRINT(src, "Fail\r\n"); OUT_PRINT(src, "Fail\r\n");
}
delay_us(30000);
send_end_response(src);
return 1; return 1;
} }
@ -805,6 +847,7 @@ static int execute_direct_read_sequence(CmdSource src, const app_job_t *job)
if (job->channel < 1 || job->channel > 20) { if (job->channel < 1 || job->channel > 20) {
OUT_PRINT(src, "Fail\r\n"); OUT_PRINT(src, "Fail\r\n");
send_end_response(src);
return 1; return 1;
} }
@ -840,6 +883,7 @@ static int execute_direct_read_sequence(CmdSource src, const app_job_t *job)
r_write = app_owi_write_basic(0x28u, job->payload, 3); r_write = app_owi_write_basic(0x28u, job->payload, 3);
if (!r_write.ok || r_write.timeout) { if (!r_write.ok || r_write.timeout) {
OUT_PRINT(src, "Fail\r\n"); OUT_PRINT(src, "Fail\r\n");
send_end_response(src);
return 1; return 1;
} }
@ -847,11 +891,13 @@ static int execute_direct_read_sequence(CmdSource src, const app_job_t *job)
r_read = app_owi_read_basic(0x28u, read_len); r_read = app_owi_read_basic(0x28u, read_len);
if (!r_read.ok || r_read.timeout || r_read.read_len < read_len) { if (!r_read.ok || r_read.timeout || r_read.read_len < read_len) {
OUT_PRINT(src, "Fail\r\n"); OUT_PRINT(src, "Fail\r\n");
send_end_response(src);
return 1; return 1;
} }
/* 3) 읽은 값만 출력 */ /* 3) 읽은 값만 출력 */
print_owi_read_result(src, &r_read); print_owi_read_result(src, &r_read);
send_end_response(src);
return 1; return 1;
} }
@ -902,11 +948,13 @@ static int execute_write_coeff_sequence(CmdSource src, const app_job_t *job)
/* 길이는 정확히 33바이트여야 함 */ /* 길이는 정확히 33바이트여야 함 */
if (job->len != 33u) { if (job->len != 33u) {
OUT_PRINT(src, "Fail\r\n"); OUT_PRINT(src, "Fail\r\n");
send_end_response(src);
return 1; return 1;
} }
if (job->channel < 1 || job->channel > 20) { if (job->channel < 1 || job->channel > 20) {
OUT_PRINT(src, "Fail\r\n"); OUT_PRINT(src, "Fail\r\n");
send_end_response(src);
return 1; return 1;
} }
@ -927,6 +975,7 @@ static int execute_write_coeff_sequence(CmdSource src, const app_job_t *job)
r_write1 = app_owi_write_basic(0x28u, job->payload, (uint8_t)job->len); r_write1 = app_owi_write_basic(0x28u, job->payload, (uint8_t)job->len);
if (!r_write1.ok || r_write1.timeout) { if (!r_write1.ok || r_write1.timeout) {
OUT_PRINT(src, "Fail\r\n"); OUT_PRINT(src, "Fail\r\n");
send_end_response(src);
return 1; return 1;
} }
@ -934,11 +983,13 @@ static int execute_write_coeff_sequence(CmdSource src, const app_job_t *job)
r_read1 = app_owi_read_basic(0x28u, 1); r_read1 = app_owi_read_basic(0x28u, 1);
if (!r_read1.ok || r_read1.timeout || r_read1.read_len < 1) { if (!r_read1.ok || r_read1.timeout || r_read1.read_len < 1) {
OUT_PRINT(src, "Fail\r\n"); OUT_PRINT(src, "Fail\r\n");
send_end_response(src);
return 1; return 1;
} }
if (r_read1.data[0] != 0x23u) { if (r_read1.data[0] != 0x23u) {
OUT_PRINT(src, "Fail\r\n"); OUT_PRINT(src, "Fail\r\n");
send_end_response(src);
return 1; return 1;
} }
@ -946,6 +997,7 @@ static int execute_write_coeff_sequence(CmdSource src, const app_job_t *job)
r_write2 = app_owi_write_basic(0x28u, nvm_read_cmd, 3); r_write2 = app_owi_write_basic(0x28u, nvm_read_cmd, 3);
if (!r_write2.ok || r_write2.timeout) { if (!r_write2.ok || r_write2.timeout) {
OUT_PRINT(src, "Fail\r\n"); OUT_PRINT(src, "Fail\r\n");
send_end_response(src);
return 1; return 1;
} }
@ -953,12 +1005,14 @@ static int execute_write_coeff_sequence(CmdSource src, const app_job_t *job)
r_read2 = app_owi_read_basic(0x28u, 127); r_read2 = app_owi_read_basic(0x28u, 127);
if (!r_read2.ok || r_read2.timeout || r_read2.read_len < 127) { if (!r_read2.ok || r_read2.timeout || r_read2.read_len < 127) {
OUT_PRINT(src, "Fail\r\n"); OUT_PRINT(src, "Fail\r\n");
send_end_response(src);
return 1; return 1;
} }
/* NVM read 응답 첫 바이트는 0x26 이어야 정상 */ /* NVM read 응답 첫 바이트는 0x26 이어야 정상 */
if (r_read2.data[0] != 0x26u) { if (r_read2.data[0] != 0x26u) {
OUT_PRINT(src, "Fail\r\n"); OUT_PRINT(src, "Fail\r\n");
send_end_response(src);
return 1; return 1;
} }
@ -973,7 +1027,7 @@ static int execute_write_coeff_sequence(CmdSource src, const app_job_t *job)
} else { } else {
OUT_PRINT(src, "Fail\r\n"); OUT_PRINT(src, "Fail\r\n");
} }
send_end_response(src);
return 1; return 1;
} }
@ -1017,11 +1071,13 @@ static int execute_shadow_write_copy_nvm_sequence(CmdSource src, const app_job_t
/* 전체 길이는 정확히 121바이트 */ /* 전체 길이는 정확히 121바이트 */
if (job->len != 121u) { if (job->len != 121u) {
OUT_PRINT(src, "Fail\r\n"); OUT_PRINT(src, "Fail\r\n");
send_end_response(src);
return 1; return 1;
} }
if (job->channel < 1 || job->channel > 20) { if (job->channel < 1 || job->channel > 20) {
OUT_PRINT(src, "Fail\r\n"); OUT_PRINT(src, "Fail\r\n");
send_end_response(src);
return 1; return 1;
} }
@ -1043,6 +1099,7 @@ static int execute_shadow_write_copy_nvm_sequence(CmdSource src, const app_job_t
r_write = app_owi_write_basic(0x28u, job->payload, 119u); r_write = app_owi_write_basic(0x28u, job->payload, 119u);
if (!r_write.ok || r_write.timeout) { if (!r_write.ok || r_write.timeout) {
OUT_PRINT(src, "Fail\r\n"); OUT_PRINT(src, "Fail\r\n");
send_end_response(src);
return 1; return 1;
} }
@ -1054,6 +1111,7 @@ static int execute_shadow_write_copy_nvm_sequence(CmdSource src, const app_job_t
} }
if (r_read.data[0] != 0x23u) { if (r_read.data[0] != 0x23u) {
OUT_PRINT(src, "Fail\r\n"); OUT_PRINT(src, "Fail\r\n");
send_end_response(src);
return 1; return 1;
} }
@ -1061,6 +1119,7 @@ static int execute_shadow_write_copy_nvm_sequence(CmdSource src, const app_job_t
r_write = app_owi_write_basic(0x28u, cmd_crc_44, 3); r_write = app_owi_write_basic(0x28u, cmd_crc_44, 3);
if (!r_write.ok || r_write.timeout) { if (!r_write.ok || r_write.timeout) {
OUT_PRINT(src, "Fail\r\n"); OUT_PRINT(src, "Fail\r\n");
send_end_response(src);
return 1; return 1;
} }
@ -1068,15 +1127,18 @@ static int execute_shadow_write_copy_nvm_sequence(CmdSource src, const app_job_t
r_read = app_owi_read_basic(0x28u, 3); r_read = app_owi_read_basic(0x28u, 3);
if (!r_read.ok || r_read.timeout || r_read.read_len < 3) { if (!r_read.ok || r_read.timeout || r_read.read_len < 3) {
OUT_PRINT(src, "Fail\r\n"); OUT_PRINT(src, "Fail\r\n");
send_end_response(src);
return 1; return 1;
} }
if (r_read.data[0] != 0x44u) { if (r_read.data[0] != 0x44u) {
OUT_PRINT(src, "Fail\r\n"); OUT_PRINT(src, "Fail\r\n");
send_end_response(src);
return 1; return 1;
} }
if (memcmp(&r_read.data[1], gui_crc, 2) != 0) { if (memcmp(&r_read.data[1], gui_crc, 2) != 0) {
OUT_PRINT(src, "Fail\r\n"); OUT_PRINT(src, "Fail\r\n");
send_end_response(src);
return 1; return 1;
} }
@ -1084,6 +1146,7 @@ static int execute_shadow_write_copy_nvm_sequence(CmdSource src, const app_job_t
r_write = app_owi_write_basic(0x28u, cmd_15_3c5b, 3); r_write = app_owi_write_basic(0x28u, cmd_15_3c5b, 3);
if (!r_write.ok || r_write.timeout) { if (!r_write.ok || r_write.timeout) {
OUT_PRINT(src, "Fail\r\n"); OUT_PRINT(src, "Fail\r\n");
send_end_response(src);
return 1; return 1;
} }
@ -1091,10 +1154,12 @@ static int execute_shadow_write_copy_nvm_sequence(CmdSource src, const app_job_t
r_read = app_owi_read_basic(0x28u, 3); r_read = app_owi_read_basic(0x28u, 3);
if (!r_read.ok || r_read.timeout || r_read.read_len < 3) { if (!r_read.ok || r_read.timeout || r_read.read_len < 3) {
OUT_PRINT(src, "Fail\r\n"); OUT_PRINT(src, "Fail\r\n");
send_end_response(src);
return 1; return 1;
} }
if (!(r_read.data[0] == 0x15u && r_read.data[1] == 0x00u && r_read.data[2] == 0x01u)) { if (!(r_read.data[0] == 0x15u && r_read.data[1] == 0x00u && r_read.data[2] == 0x01u)) {
OUT_PRINT(src, "Fail\r\n"); OUT_PRINT(src, "Fail\r\n");
send_end_response(src);
return 1; return 1;
} }
@ -1102,6 +1167,7 @@ static int execute_shadow_write_copy_nvm_sequence(CmdSource src, const app_job_t
r_write = app_owi_write_basic(0x28u, cmd_14, 1); r_write = app_owi_write_basic(0x28u, cmd_14, 1);
if (!r_write.ok || r_write.timeout) { if (!r_write.ok || r_write.timeout) {
OUT_PRINT(src, "Fail\r\n"); OUT_PRINT(src, "Fail\r\n");
send_end_response(src);
return 1; return 1;
} }
@ -1109,10 +1175,12 @@ static int execute_shadow_write_copy_nvm_sequence(CmdSource src, const app_job_t
r_read = app_owi_read_basic(0x28u, 3); r_read = app_owi_read_basic(0x28u, 3);
if (!r_read.ok || r_read.timeout || r_read.read_len < 3) { if (!r_read.ok || r_read.timeout || r_read.read_len < 3) {
OUT_PRINT(src, "Fail\r\n"); OUT_PRINT(src, "Fail\r\n");
send_end_response(src);
return 1; return 1;
} }
if (!(r_read.data[0] == 0x14u && r_read.data[1] == 0x00u && r_read.data[2] == 0x01u)) { if (!(r_read.data[0] == 0x14u && r_read.data[1] == 0x00u && r_read.data[2] == 0x01u)) {
OUT_PRINT(src, "Fail\r\n"); OUT_PRINT(src, "Fail\r\n");
send_end_response(src);
return 1; return 1;
} }
@ -1120,6 +1188,7 @@ static int execute_shadow_write_copy_nvm_sequence(CmdSource src, const app_job_t
r_write = app_owi_write_basic(0x28u, cmd_1a, 1); r_write = app_owi_write_basic(0x28u, cmd_1a, 1);
if (!r_write.ok || r_write.timeout) { if (!r_write.ok || r_write.timeout) {
OUT_PRINT(src, "Fail\r\n"); OUT_PRINT(src, "Fail\r\n");
send_end_response(src);
return 1; return 1;
} }
@ -1129,6 +1198,7 @@ static int execute_shadow_write_copy_nvm_sequence(CmdSource src, const app_job_t
r_read = app_owi_read_basic(0x28u, 3); r_read = app_owi_read_basic(0x28u, 3);
if (!r_read.ok || r_read.timeout || r_read.read_len < 3) { if (!r_read.ok || r_read.timeout || r_read.read_len < 3) {
OUT_PRINT(src, "Fail\r\n"); OUT_PRINT(src, "Fail\r\n");
send_end_response(src);
return 1; return 1;
} }
@ -1143,6 +1213,7 @@ static int execute_shadow_write_copy_nvm_sequence(CmdSource src, const app_job_t
if (poll_count >= 50u) { if (poll_count >= 50u) {
OUT_PRINT(src, "Fail\r\n"); OUT_PRINT(src, "Fail\r\n");
send_end_response(src);
return 1; return 1;
} }
@ -1150,6 +1221,7 @@ static int execute_shadow_write_copy_nvm_sequence(CmdSource src, const app_job_t
r_write = app_owi_write_basic(0x28u, cmd_crc_40, 3); r_write = app_owi_write_basic(0x28u, cmd_crc_40, 3);
if (!r_write.ok || r_write.timeout) { if (!r_write.ok || r_write.timeout) {
OUT_PRINT(src, "Fail\r\n"); OUT_PRINT(src, "Fail\r\n");
send_end_response(src);
return 1; return 1;
} }
@ -1157,14 +1229,17 @@ static int execute_shadow_write_copy_nvm_sequence(CmdSource src, const app_job_t
r_read = app_owi_read_basic(0x28u, 3); r_read = app_owi_read_basic(0x28u, 3);
if (!r_read.ok || r_read.timeout || r_read.read_len < 3) { if (!r_read.ok || r_read.timeout || r_read.read_len < 3) {
OUT_PRINT(src, "Fail\r\n"); OUT_PRINT(src, "Fail\r\n");
send_end_response(src);
return 1; return 1;
} }
if (r_read.data[0] != 0x40u) { if (r_read.data[0] != 0x40u) {
OUT_PRINT(src, "Fail\r\n"); OUT_PRINT(src, "Fail\r\n");
send_end_response(src);
return 1; return 1;
} }
if (memcmp(&r_read.data[1], gui_crc, 2) != 0) { if (memcmp(&r_read.data[1], gui_crc, 2) != 0) {
OUT_PRINT(src, "Fail\r\n"); OUT_PRINT(src, "Fail\r\n");
send_end_response(src);
return 1; return 1;
} }
@ -1172,6 +1247,7 @@ static int execute_shadow_write_copy_nvm_sequence(CmdSource src, const app_job_t
r_write = app_owi_write_basic(0x28u, cmd_crc_42, 3); r_write = app_owi_write_basic(0x28u, cmd_crc_42, 3);
if (!r_write.ok || r_write.timeout) { if (!r_write.ok || r_write.timeout) {
OUT_PRINT(src, "Fail\r\n"); OUT_PRINT(src, "Fail\r\n");
send_end_response(src);
return 1; return 1;
} }
@ -1179,14 +1255,17 @@ static int execute_shadow_write_copy_nvm_sequence(CmdSource src, const app_job_t
r_read = app_owi_read_basic(0x28u, 3); r_read = app_owi_read_basic(0x28u, 3);
if (!r_read.ok || r_read.timeout || r_read.read_len < 3) { if (!r_read.ok || r_read.timeout || r_read.read_len < 3) {
OUT_PRINT(src, "Fail\r\n"); OUT_PRINT(src, "Fail\r\n");
send_end_response(src);
return 1; return 1;
} }
if (r_read.data[0] != 0x42u) { if (r_read.data[0] != 0x42u) {
OUT_PRINT(src, "Fail\r\n"); OUT_PRINT(src, "Fail\r\n");
send_end_response(src);
return 1; return 1;
} }
if (memcmp(&r_read.data[1], gui_crc, 2) != 0) { if (memcmp(&r_read.data[1], gui_crc, 2) != 0) {
OUT_PRINT(src, "Fail\r\n"); OUT_PRINT(src, "Fail\r\n");
send_end_response(src);
return 1; return 1;
} }
@ -1194,6 +1273,7 @@ static int execute_shadow_write_copy_nvm_sequence(CmdSource src, const app_job_t
r_write = app_owi_write_basic(0x28u, cmd_15_0000, 3); r_write = app_owi_write_basic(0x28u, cmd_15_0000, 3);
if (!r_write.ok || r_write.timeout) { if (!r_write.ok || r_write.timeout) {
OUT_PRINT(src, "Fail\r\n"); OUT_PRINT(src, "Fail\r\n");
send_end_response(src);
return 1; return 1;
} }
@ -1201,10 +1281,12 @@ static int execute_shadow_write_copy_nvm_sequence(CmdSource src, const app_job_t
r_read = app_owi_read_basic(0x28u, 3); r_read = app_owi_read_basic(0x28u, 3);
if (!r_read.ok || r_read.timeout || r_read.read_len < 3) { if (!r_read.ok || r_read.timeout || r_read.read_len < 3) {
OUT_PRINT(src, "Fail\r\n"); OUT_PRINT(src, "Fail\r\n");
send_end_response(src);
return 1; return 1;
} }
if (!(r_read.data[0] == 0x15u && r_read.data[1] == 0x00u && r_read.data[2] == 0x00u)) { if (!(r_read.data[0] == 0x15u && r_read.data[1] == 0x00u && r_read.data[2] == 0x00u)) {
OUT_PRINT(src, "Fail\r\n"); OUT_PRINT(src, "Fail\r\n");
send_end_response(src);
return 1; return 1;
} }
@ -1212,6 +1294,7 @@ static int execute_shadow_write_copy_nvm_sequence(CmdSource src, const app_job_t
r_write = app_owi_write_basic(0x28u, cmd_nvm_read, 3); r_write = app_owi_write_basic(0x28u, cmd_nvm_read, 3);
if (!r_write.ok || r_write.timeout) { if (!r_write.ok || r_write.timeout) {
OUT_PRINT(src, "Fail\r\n"); OUT_PRINT(src, "Fail\r\n");
send_end_response(src);
return 1; return 1;
} }
@ -1219,14 +1302,17 @@ static int execute_shadow_write_copy_nvm_sequence(CmdSource src, const app_job_t
r_read = app_owi_read_basic(0x28u, 127); r_read = app_owi_read_basic(0x28u, 127);
if (!r_read.ok || r_read.timeout || r_read.read_len < 127) { if (!r_read.ok || r_read.timeout || r_read.read_len < 127) {
OUT_PRINT(src, "Fail\r\n"); OUT_PRINT(src, "Fail\r\n");
send_end_response(src);
return 1; return 1;
} }
if (r_read.data[0] != 0x26u) { if (r_read.data[0] != 0x26u) {
OUT_PRINT(src, "Fail\r\n"); OUT_PRINT(src, "Fail\r\n");
send_end_response(src);
return 1; return 1;
} }
print_owi_read_result(src, &r_read); print_owi_read_result(src, &r_read);
send_end_response(src);
return 1; return 1;
} }
@ -1296,7 +1382,6 @@ static void forward_line_rs485_and_bridge(const char *line)
{ {
static char txbuf[UART_RX_BUF_SIZE + 4]; static char txbuf[UART_RX_BUF_SIZE + 4];
uint32_t total_us; uint32_t total_us;
uint32_t idle_us = 0;
char linebuf[320]; char linebuf[320];
int line_len = 0; int line_len = 0;
int n; int n;
@ -1333,58 +1418,50 @@ static void forward_line_rs485_and_bridge(const char *line)
linebuf[0] = '\0'; linebuf[0] = '\0';
while (total_us >= 50U) { while (total_us >= 50U) {
uint8_t had_byte = 0;
/* FIFO에서 바이트를 하나씩 꺼내 누적 */
while (s_rb_tail != s_rb_head) { while (s_rb_tail != s_rb_head) {
char c = (char)s_rb_fifo[s_rb_tail]; char c = (char)s_rb_fifo[s_rb_tail];
s_rb_tail++; s_rb_tail++;
if (s_rb_tail >= RS485_BRIDGE_FIFO_SZ) s_rb_tail = 0; if (s_rb_tail >= RS485_BRIDGE_FIFO_SZ) s_rb_tail = 0;
had_byte = 1;
/* CR 무시 */ /* CR 무시 */
if (c == '\r') continue; if (c == '\r') continue;
/* 버퍼에 누적 */ /* line buffer 누적 */
if (line_len < (int)sizeof(linebuf) - 1) { if (line_len < (int)sizeof(linebuf) - 1) {
linebuf[line_len++] = c; linebuf[line_len++] = c;
linebuf[line_len] = '\0'; linebuf[line_len] = '\0';
} else { } else {
/* overflow 보호: 강제로 한 줄 종료 처리 */ /* overflow 보호 */
linebuf[line_len] = '\0'; linebuf[line_len] = '\0';
if (!(linebuf[0] == 'x' || linebuf[0] == 'X')) { if (!(linebuf[0] == 'x' || linebuf[0] == 'X')) {
PC_PrintLine_CRLF(linebuf); PC_PrintLine_CRLF(linebuf);
got_any_line = 1; got_any_line = 1;
if (strstr(linebuf, "<end>") != 0) {
g_rs485_bridge_active = 0;
return;
} }
}
line_len = 0; line_len = 0;
linebuf[0] = '\0'; linebuf[0] = '\0';
} }
/* LF 도착 = 한 줄 완성 */ /* LF = 한 줄 완성 */
if (c == '\n') { if (c == '\n') {
if (!(linebuf[0] == 'x' || linebuf[0] == 'X')) { if (!(linebuf[0] == 'x' || linebuf[0] == 'X')) {
PC_PrintLine_CRLF(linebuf); PC_PrintLine_CRLF(linebuf);
got_any_line = 1; got_any_line = 1;
}
line_len = 0;
linebuf[0] = '\0';
/* OFF 응답처럼 <end>가 오면 종료 */ if (strstr(linebuf, "<end>") != 0) {
if (g_rs485_bridge_done) {
g_rs485_bridge_active = 0; g_rs485_bridge_active = 0;
return; return;
} }
} }
}
if (had_byte) { line_len = 0;
idle_us = 0; linebuf[0] = '\0';
} else if (got_any_line) {
idle_us += 50U;
if (idle_us >= BRIDGE_IDLE_DONE_US) {
break;
} }
} }
@ -1392,17 +1469,33 @@ static void forward_line_rs485_and_bridge(const char *line)
total_us -= 50U; total_us -= 50U;
} }
/* 남은 partial line이 있으면 마지막으로 출력 */ /* timeout 시 partial line도 보여줌 */
if (line_len > 0) { if (line_len > 0) {
linebuf[line_len] = '\0'; linebuf[line_len] = '\0';
if (!(linebuf[0] == 'x' || linebuf[0] == 'X')) { if (!(linebuf[0] == 'x' || linebuf[0] == 'X')) {
PC_PrintLine_CRLF(linebuf); PC_PrintLine_CRLF(linebuf);
got_any_line = 1; got_any_line = 1;
if (strstr(linebuf, "<end>") != 0) {
g_rs485_bridge_active = 0;
return;
}
} }
} }
if (!got_any_line) { if (!got_any_line) {
OUT_PRINT(CMD_SRC_PC, "Err:rs485_no_response\r\n"); OUT_PRINT(CMD_SRC_PC, "Err:rs485_no_response\r\n");
} else {
char dbg[128];
if (line_len > 0) {
sprintf(dbg, "Err:rs485_no_end partial=%s\r\n", linebuf);
} else {
sprintf(dbg, "Err:rs485_no_end partial=<none>\r\n");
}
OUT_PRINT(CMD_SRC_PC, dbg);
} }
g_rs485_bridge_active = 0; g_rs485_bridge_active = 0;
@ -1637,6 +1730,7 @@ static void process_one_line_now(CmdSource src, const char *input_line)
for (a = 1; a <= 31; a++) { for (a = 1; a <= 31; a++) {
scan_one_addr_rs485(a); scan_one_addr_rs485(a);
} }
send_end_response(CMD_SRC_PC);
return; return;
} }
@ -1914,7 +2008,7 @@ static void app_job_tick(void)
g_app_runtime_job.current_scan_addr++; g_app_runtime_job.current_scan_addr++;
return; return;
} }
send_end_response(CMD_SRC_PC);
app_runtime_reset(); app_runtime_reset();
return; return;
} }

19
uart.c

@ -56,6 +56,8 @@ void rs485_recover(void)
/* UART1 송신용 내부 버퍼(스택 포인터 안전) */ /* UART1 송신용 내부 버퍼(스택 포인터 안전) */
static uint8_t s_uart1_txbuf[1024]; static uint8_t s_uart1_txbuf[1024];
static uint8_t s_uart0_txbuf[256];
static volatile uint16_t s_uart0_tx_len = 0;
static void UART1_WaitTxIdle(void) static void UART1_WaitTxIdle(void)
@ -91,11 +93,24 @@ void RS485_Send(const uint8_t* data, uint16_t len)
{ {
if (!data || len == 0) return; if (!data || len == 0) return;
UART0_WaitTxDone_Us(5000U); /* 이전 전송 완료 대기 */
UART0_WaitTxDone_Us(20000U);
/* 내부 버퍼 크기 제한 */
if (len >= (uint16_t)sizeof(s_uart0_txbuf)) {
len = (uint16_t)(sizeof(s_uart0_txbuf) - 1);
}
/* 호출자 버퍼 -> 내부 안전 버퍼 복사 */
memcpy(s_uart0_txbuf, data, len);
s_uart0_tx_len = len;
g_uart0_tx_done = 0; g_uart0_tx_done = 0;
rs485_set_tx(1); rs485_set_tx(1);
delay_us(30U); delay_us(30U);
R_UART0_Send((uint8_t*)data, len);
/* 내부 버퍼 기준 비동기 송신 */
R_UART0_Send((uint8_t*)s_uart0_txbuf, len);
} }
void RS485_SendString(const char* s) void RS485_SendString(const char* s)

Loading…
Cancel
Save