Clean up command.[ch]
This commit is contained in:
@@ -1,40 +1,11 @@
|
|||||||
#include <string.h>
|
|
||||||
#include <stdint.h>
|
|
||||||
#include "command.h"
|
#include "command.h"
|
||||||
#include "packet/serial_packet.h"
|
|
||||||
#include "crc16.h"
|
#include "crc16.h"
|
||||||
|
|
||||||
#include "fsl_flash.h"
|
|
||||||
#include "fsl_device_registers.h"
|
|
||||||
|
|
||||||
#if defined(ENABLE_USB)
|
|
||||||
#include "usb_class_hid.h"
|
|
||||||
#include "usb_device_stack_interface.h"
|
|
||||||
#include "usb_hid.h"
|
|
||||||
#include "bootloader_hid_report_ids.h"
|
|
||||||
#include "usb_error.h"
|
|
||||||
#include "usb_descriptor.h"
|
|
||||||
#include "usb_class_hid.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "bus_pal_hardware.h"
|
#include "bus_pal_hardware.h"
|
||||||
|
|
||||||
//! @addtogroup command
|
|
||||||
//! @{
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
// Variables
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
//! @brief Command processor state data.
|
|
||||||
command_processor_data_t g_commandData;
|
command_processor_data_t g_commandData;
|
||||||
buspal_state_t g_buspalState = kBuspal_Idle;
|
buspal_state_t g_buspalState = kBuspal_Idle;
|
||||||
uint8_t g_targetRxBuffer[64];
|
uint8_t g_targetRxBuffer[64];
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
// Definitions
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
void handle_reset(uint8_t *packet, uint32_t packetLength);
|
void handle_reset(uint8_t *packet, uint32_t packetLength);
|
||||||
void send_generic_response(uint32_t commandStatus, uint32_t commandTag);
|
void send_generic_response(uint32_t commandStatus, uint32_t commandTag);
|
||||||
|
|
||||||
@@ -48,10 +19,6 @@ static void reset_data_phase();
|
|||||||
static status_t peripheral_read(uint8_t *dest, uint32_t readLength);
|
static status_t peripheral_read(uint8_t *dest, uint32_t readLength);
|
||||||
static status_t peripheral_write(uint8_t *src, uint32_t writeLength);
|
static status_t peripheral_write(uint8_t *src, uint32_t writeLength);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
// Code
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
void handleUsbBusPalCommand()
|
void handleUsbBusPalCommand()
|
||||||
{
|
{
|
||||||
g_commandData.state = kCommandState_CommandPhase;
|
g_commandData.state = kCommandState_CommandPhase;
|
||||||
|
|||||||
@@ -1,17 +1,8 @@
|
|||||||
#ifndef _command_h
|
#ifndef __COMMAND_H__
|
||||||
#define _command_h
|
#define __COMMAND_H__
|
||||||
|
|
||||||
#include "packet/serial_packet.h"
|
#include "packet/serial_packet.h"
|
||||||
#include "packet/command_packet.h"
|
|
||||||
|
|
||||||
//! @addtogroup command
|
|
||||||
//! @{
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
// Definitions
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
//! @brief Command state machine states.
|
|
||||||
enum _command_state
|
enum _command_state
|
||||||
{
|
{
|
||||||
kCommandState_CommandPhase,
|
kCommandState_CommandPhase,
|
||||||
@@ -26,74 +17,42 @@ typedef enum _buspal_state
|
|||||||
kBuspal_I2c,
|
kBuspal_I2c,
|
||||||
} buspal_state_t;
|
} buspal_state_t;
|
||||||
|
|
||||||
typedef struct ConfigI2cCmdPacket
|
|
||||||
{
|
|
||||||
command_packet_t commandPacket; //!< header
|
|
||||||
uint32_t address; //!< Parameter 0: i2c slave address.
|
|
||||||
uint32_t speed; //!< Parameter 1: i2c speed in kHz
|
|
||||||
} config_i2c_cmd_packet_t;
|
|
||||||
|
|
||||||
//! @brief Format of command handler entry.
|
|
||||||
typedef struct CommandHandlerEntry
|
typedef struct CommandHandlerEntry
|
||||||
{
|
{
|
||||||
void (*handleCommand)(uint8_t *packet, uint32_t packetLength);
|
void (*handleCommand)(uint8_t *packet, uint32_t packetLength);
|
||||||
status_t (*handleData)(bool *hasMoreData);
|
status_t (*handleData)(bool *hasMoreData);
|
||||||
} command_handler_entry_t;
|
} command_handler_entry_t;
|
||||||
|
|
||||||
//! @brief Command processor data format.
|
typedef struct CommandProcessorData {
|
||||||
typedef struct CommandProcessorData
|
int32_t state; // Current state machine state
|
||||||
{
|
uint8_t *packet; // Pointer to packet in process
|
||||||
int32_t state; //!< Current state machine state
|
uint32_t packetLength; // Length of packet in process
|
||||||
uint8_t *packet; //!< Pointer to packet in process
|
struct DataPhase {
|
||||||
uint32_t packetLength; //!< Length of packet in process
|
uint8_t *data; // Data for data phase
|
||||||
struct DataPhase
|
uint32_t count; // Remaining count to produce/consume
|
||||||
{
|
uint32_t address; // Address for data phase
|
||||||
uint8_t *data; //!< Data for data phase
|
uint32_t dataBytesAvailable; // Number of bytes available at data pointer
|
||||||
uint32_t count; //!< Remaining count to produce/consume
|
uint8_t commandTag; // Tag of command running data phase
|
||||||
uint32_t address; //!< Address for data phase
|
uint8_t option; // Option for special command
|
||||||
uint32_t dataBytesAvailable; //!< Number of bytes available at data pointer
|
|
||||||
uint8_t commandTag; //!< Tag of command running data phase
|
|
||||||
uint8_t option; //!< option for special command
|
|
||||||
} dataPhase;
|
} dataPhase;
|
||||||
const command_handler_entry_t *handlerEntry; //! Pointer to handler table entry for packet in process
|
const command_handler_entry_t *handlerEntry; // Pointer to handler table entry for packet in process
|
||||||
} command_processor_data_t;
|
} command_processor_data_t;
|
||||||
|
|
||||||
//! @brief Interface to command processor operations.
|
// Interface to command processor operations.
|
||||||
typedef struct CommandInterface
|
typedef struct CommandInterface {
|
||||||
{
|
|
||||||
status_t (*init)(void);
|
status_t (*init)(void);
|
||||||
status_t (*pump)(void);
|
status_t (*pump)(void);
|
||||||
const command_handler_entry_t *handlerTable;
|
const command_handler_entry_t *handlerTable;
|
||||||
command_processor_data_t *stateData;
|
command_processor_data_t *stateData;
|
||||||
} command_interface_t;
|
} command_interface_t;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
// Default command interface.
|
||||||
// Externals
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
//! @brief Default command interface.
|
|
||||||
extern command_interface_t g_commandInterface;
|
extern command_interface_t g_commandInterface;
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
// Initialize the command processor component.
|
||||||
// Prototypes
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
#if defined(__cplusplus)
|
|
||||||
extern "C" {
|
|
||||||
#endif // __cplusplus
|
|
||||||
|
|
||||||
//! @brief Initialize the command processor component.
|
|
||||||
status_t bootloader_command_init(void);
|
status_t bootloader_command_init(void);
|
||||||
|
|
||||||
//! @brief Pump the command state machine.
|
// Pump the command state machine. Executes one command or data phase transaction.
|
||||||
//!
|
|
||||||
//! Executes one command or data phase transaction.
|
|
||||||
status_t bootloader_command_pump(void);
|
status_t bootloader_command_pump(void);
|
||||||
|
|
||||||
#if defined(__cplusplus)
|
#endif
|
||||||
}
|
|
||||||
#endif // __cplusplus
|
|
||||||
|
|
||||||
//! @}
|
|
||||||
|
|
||||||
#endif // _command.h_
|
|
||||||
|
|||||||
Reference in New Issue
Block a user