Use identifiers instead of the magic numbers of kboot_driver.[ch]
This commit is contained in:
@@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
kboot_driver_state_t KbootDriverState;
|
kboot_driver_state_t KbootDriverState;
|
||||||
|
|
||||||
static uint8_t rxBuffer[MAX_KBOOT_COMMAND_LENGTH];
|
static uint8_t rxBuffer[KBOOT_PACKAGE_MAX_LENGTH];
|
||||||
static uint8_t pingCommand[] = {0x5a, 0xa6};
|
static uint8_t pingCommand[] = {0x5a, 0xa6};
|
||||||
static uint8_t resetCommand[] = {0x5a, 0xa4, 0x04, 0x00, 0x6f, 0x46, 0x0b, 0x00, 0x00, 0x00};
|
static uint8_t resetCommand[] = {0x5a, 0xa4, 0x04, 0x00, 0x6f, 0x46, 0x0b, 0x00, 0x00, 0x00};
|
||||||
static uint8_t ackMessage[] = {0x5a, 0xa1};
|
static uint8_t ackMessage[] = {0x5a, 0xa1};
|
||||||
@@ -32,43 +32,45 @@ status_t KbootSlaveDriver_Update(uint8_t kbootInstanceId)
|
|||||||
break;
|
break;
|
||||||
case KbootCommand_Ping:
|
case KbootCommand_Ping:
|
||||||
switch (KbootDriverState.phase) {
|
switch (KbootDriverState.phase) {
|
||||||
case 0:
|
case KbootPhase_SendPing:
|
||||||
status = tx(pingCommand, sizeof(pingCommand));
|
status = tx(pingCommand, sizeof(pingCommand));
|
||||||
KbootDriverState.phase++;
|
KbootDriverState.phase = KbootPhase_CheckPingStatus;
|
||||||
break;
|
break;
|
||||||
case 1:
|
case KbootPhase_CheckPingStatus:
|
||||||
KbootDriverState.status = Slaves[SlaveId_KbootDriver].previousStatus;
|
KbootDriverState.status = Slaves[SlaveId_KbootDriver].previousStatus;
|
||||||
KbootDriverState.phase = KbootDriverState.status == kStatus_Success ? 2 : 0;
|
KbootDriverState.phase = KbootDriverState.status == kStatus_Success
|
||||||
|
? KbootPhase_ReceivePingResponse
|
||||||
|
: KbootPhase_SendPing;
|
||||||
return kStatus_Uhk_IdleCycle;
|
return kStatus_Uhk_IdleCycle;
|
||||||
case 2:
|
case KbootPhase_ReceivePingResponse:
|
||||||
status = rx(10);
|
status = rx(KBOOT_PACKAGE_LENGTH_PING_RESPONSE);
|
||||||
KbootDriverState.phase++;
|
KbootDriverState.phase = KbootPhase_CheckPingResponseStatus;
|
||||||
break;
|
break;
|
||||||
case 3:
|
case KbootPhase_CheckPingResponseStatus:
|
||||||
KbootDriverState.status = Slaves[SlaveId_KbootDriver].previousStatus;
|
KbootDriverState.status = Slaves[SlaveId_KbootDriver].previousStatus;
|
||||||
if (KbootDriverState.status == kStatus_Success) {
|
if (KbootDriverState.status == kStatus_Success) {
|
||||||
KbootDriverState.commandType = KbootCommand_Idle;
|
KbootDriverState.commandType = KbootCommand_Idle;
|
||||||
} else {
|
} else {
|
||||||
KbootDriverState.phase = 0;
|
KbootDriverState.phase = KbootPhase_SendPing;
|
||||||
return kStatus_Uhk_IdleCycle;
|
return kStatus_Uhk_IdleCycle;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case KbootCommand_Reset:
|
case KbootCommand_Reset:
|
||||||
switch (KbootDriverState.phase) {
|
switch (KbootDriverState.phase) {
|
||||||
case 0:
|
case KbootPhase_SendReset:
|
||||||
status = tx(resetCommand, sizeof(resetCommand));
|
status = tx(resetCommand, sizeof(resetCommand));
|
||||||
KbootDriverState.phase++;
|
KbootDriverState.phase = KbootPhase_ReceiveResetAck;
|
||||||
break;
|
break;
|
||||||
case 1:
|
case KbootPhase_ReceiveResetAck:
|
||||||
status = rx(2);
|
status = rx(KBOOT_PACKAGE_LENGTH_ACK);
|
||||||
KbootDriverState.phase++;
|
KbootDriverState.phase = KbootPhase_ReceiveResetGenericResponse;
|
||||||
break;
|
break;
|
||||||
case 2:
|
case KbootPhase_ReceiveResetGenericResponse:
|
||||||
status = rx(18);
|
status = rx(KBOOT_PACKAGE_LENGTH_GENERIC_RESPONSE);
|
||||||
KbootDriverState.phase++;
|
KbootDriverState.phase = KbootPhase_CheckResetSendAck;
|
||||||
break;
|
break;
|
||||||
case 3:
|
case KbootPhase_CheckResetSendAck:
|
||||||
status = tx(ackMessage, sizeof(ackMessage));
|
status = tx(ackMessage, sizeof(ackMessage));
|
||||||
KbootDriverState.commandType = KbootCommand_Idle;
|
KbootDriverState.commandType = KbootCommand_Idle;
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -7,7 +7,10 @@
|
|||||||
|
|
||||||
// Macros:
|
// Macros:
|
||||||
|
|
||||||
#define MAX_KBOOT_COMMAND_LENGTH 32
|
#define KBOOT_PACKAGE_MAX_LENGTH 32
|
||||||
|
#define KBOOT_PACKAGE_LENGTH_PING_RESPONSE 10
|
||||||
|
#define KBOOT_PACKAGE_LENGTH_ACK 2
|
||||||
|
#define KBOOT_PACKAGE_LENGTH_GENERIC_RESPONSE 18
|
||||||
|
|
||||||
// Typedefs:
|
// Typedefs:
|
||||||
|
|
||||||
@@ -21,6 +24,20 @@
|
|||||||
KbootCommand_Reset,
|
KbootCommand_Reset,
|
||||||
} kboot_command_t;
|
} kboot_command_t;
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
KbootPhase_SendPing,
|
||||||
|
KbootPhase_CheckPingStatus,
|
||||||
|
KbootPhase_ReceivePingResponse,
|
||||||
|
KbootPhase_CheckPingResponseStatus,
|
||||||
|
} kboot_ping_phase_t;
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
KbootPhase_SendReset,
|
||||||
|
KbootPhase_ReceiveResetAck,
|
||||||
|
KbootPhase_ReceiveResetGenericResponse,
|
||||||
|
KbootPhase_CheckResetSendAck,
|
||||||
|
} kboot_reset_phase_t;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
kboot_command_t commandType;
|
kboot_command_t commandType;
|
||||||
uint8_t i2cAddress;
|
uint8_t i2cAddress;
|
||||||
|
|||||||
Reference in New Issue
Block a user