fixed app termination bugs and session timeout ms value

This commit is contained in:
2026-04-13 14:02:58 +02:00
parent 6bc3309200
commit 537e20fdd8
4 changed files with 27 additions and 5 deletions

View File

@@ -92,6 +92,14 @@ void KL_App_ResetLocks(void)
app.rom_unlocked_cust = 0; app.rom_unlocked_cust = 0;
} }
void KL_App_Reset(void)
{
app.state = KL_APP_IDLE;
app.eeprom_unlocked_dfi = 0;
app.eeprom_unlocked_dfi_write = 0;
app.rom_unlocked_cust = 0;
}
int KL_App_Busy(void) int KL_App_Busy(void)
{ {
return (app.state != KL_APP_IDLE && app.state != KL_APP_DONE) ? 1 : 0; return (app.state != KL_APP_IDLE && app.state != KL_APP_DONE) ? 1 : 0;

View File

@@ -52,6 +52,7 @@ void KL_App_Dispatch(const KL_Packet *cmd);
int KL_App_Busy(void); int KL_App_Busy(void);
int KL_App_Done(void); int KL_App_Done(void);
void KL_App_ResetLocks(void); void KL_App_ResetLocks(void);
void KL_App_Reset(void);
/* DTC list management */ /* DTC list management */
void KL_App_SetDTCList(const KL_FaultCode *list, size_t count); void KL_App_SetDTCList(const KL_FaultCode *list, size_t count);

View File

@@ -35,7 +35,7 @@
#define KL_W3_MS 11U /* Keyword LSB to MSB */ #define KL_W3_MS 11U /* Keyword LSB to MSB */
#define KL_HS_RETRY_MS 43U /* Between handshake retries */ #define KL_HS_RETRY_MS 43U /* Between handshake retries */
#define KL_P1_GAP_MS 5U /* ECU inter-byte gap */ #define KL_P1_GAP_MS 5U /* ECU inter-byte gap */
#define KL_SESSION_TMO_MS 1000U /* Session keepalive timeout */ #define KL_SESSION_TMO_MS 5250U /* Session keepalive timeout */
#define KL_BYTE_TMO_MS 50U /* Per-byte RX timeout */ #define KL_BYTE_TMO_MS 50U /* Per-byte RX timeout */
#define KL_PKT_TMO_MS 800U /* Overall packet RX timeout */ #define KL_PKT_TMO_MS 800U /* Overall packet RX timeout */
#define KL_COMPL_TMO_MS 25U /* Complement wait timeout */ #define KL_COMPL_TMO_MS 25U /* Complement wait timeout */

View File

@@ -236,7 +236,7 @@ static void sess_terminate(void)
sess.session_deadline = 0; sess.session_deadline = 0;
sess.end_requested = 0; sess.end_requested = 0;
KL_App_ResetLocks(); KL_App_Reset();
KL_Transport_ResetCounter(); KL_Transport_ResetCounter();
KL_Transport_TxReset(); KL_Transport_TxReset();
KL_Transport_RxReset(); KL_Transport_RxReset();
@@ -337,6 +337,7 @@ void KL_Session_Service(void)
sizeof(sess.ident_buf)); sizeof(sess.ident_buf));
sess.ident_offset = 0; sess.ident_offset = 0;
KL_Phy_RxFlush(); KL_Phy_RxFlush();
sess.session_deadline = HAL_GetTick() + KL_SESSION_TMO_MS;
sess.state = KL_SESS_IDENT_SEND; sess.state = KL_SESS_IDENT_SEND;
break; break;
} }
@@ -372,6 +373,10 @@ void KL_Session_Service(void)
} }
case KL_SESS_IDENT_WAIT_TX: case KL_SESS_IDENT_WAIT_TX:
if (kl_tick_diff(now, sess.session_deadline) >= 0) {
sess_terminate();
break;
}
if (KL_Transport_TxDone()) { if (KL_Transport_TxDone()) {
KL_Transport_TxReset(); KL_Transport_TxReset();
sess.ident_offset += sess.ident_chunk_len; sess.ident_offset += sess.ident_chunk_len;
@@ -392,6 +397,10 @@ void KL_Session_Service(void)
break; break;
case KL_SESS_IDENT_WAIT_ACK: case KL_SESS_IDENT_WAIT_ACK:
if (kl_tick_diff(now, sess.session_deadline) >= 0) {
sess_terminate();
break;
}
if (KL_Transport_RxDone()) { if (KL_Transport_RxDone()) {
const KL_Packet *pkt = KL_Transport_GetRxPacket(); const KL_Packet *pkt = KL_Transport_GetRxPacket();
KL_Transport_RxReset(); KL_Transport_RxReset();
@@ -484,13 +493,17 @@ void KL_Session_Service(void)
} }
case KL_SESS_CMD_RESPONSE: case KL_SESS_CMD_RESPONSE:
if (sess.end_requested) { if (kl_tick_diff(now, sess.session_deadline) >= 0) {
sess_terminate(); sess_terminate();
break; break;
} }
if (KL_App_Done()) { if (KL_App_Done()) {
KL_Session_Kick(); if (sess.end_requested) {
sess.state = KL_SESS_READY; sess_terminate();
} else {
KL_Session_Kick();
sess.state = KL_SESS_READY;
}
} }
break; break;