command.h
/*
* Copyright (c) 2013, Freescale Semiconductor, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* o Redistributions of source code must retain the above copyright notice, this list
* of conditions and the following disclaimer.
*
* o Redistributions in binary form must reproduce the above copyright notice, this
* list of conditions and the following disclaimer in the documentation and/or
* other materials provided with the distribution.
*
* o Neither the name of Freescale Semiconductor, Inc. nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _command_h
#define _command_h
// Definitions
enum _command_state
{
kCommandState_CommandPhase,
kCommandState_DataPhase,
kCommandState_DataPhaseRead,
kCommandState_DataPhaseWrite
};
typedef enum _buspal_state
{
kBuspal_Idle,
kBuspal_I2c,
kBuspal_Spi,
kBuspal_FlexCAN,
kBuspal_MsCAN
} buspal_state_t;
typedef struct ConfigI2cCmdPacket
{
command_packet_t commandPacket;
uint32_t address;
uint32_t speed;
} config_i2c_cmd_packet_t;
typedef struct CommandHandlerEntry
{
void (*handleCommand)(uint8_t *packet, uint32_t packetLength);
status_t (*handleData)(bool *hasMoreData);
} command_handler_entry_t;
typedef struct CommandProcessorData
{
int32_t state;
uint8_t *packet;
uint32_t packetLength;
struct DataPhase
{
uint8_t *data;
uint32_t count;
uint32_t address;
uint32_t dataBytesAvailable;
uint8_t commandTag;
uint8_t option;
} dataPhase;
const command_handler_entry_t *handlerEntry;
} command_processor_data_t;
typedef struct CommandInterface
{
status_t (*init)(void);
status_t (*pump)(void);
const command_handler_entry_t *handlerTable;
command_processor_data_t *stateData;
} command_interface_t;
// Externals
extern command_interface_t g_commandInterface;
// Prototypes
#if defined(__cplusplus)
extern "C" {
#endif // __cplusplus
status_t bootloader_command_init(void);
status_t bootloader_command_pump(void);
#if defined(__cplusplus)
}
#endif // __cplusplus
#endif // _command.h_
// EOF
g_commandInterface
command_interface_t g_commandInterface
Default command interface.
Definition: bl_command.c:207
_command_state
_command_state
Command state machine states.
Definition: bl_command.h:42
command_handler_entry_t
Format of command handler entry.
Definition: bl_command.h:49
config_i2c_cmd_packet_t::address
uint32_t address
Parameter 0: i2c slave address.
Definition: command.h:62
config_i2c_cmd_packet_t::commandPacket
command_packet_t commandPacket
header
Definition: command.h:61
command_packet_t
Command packet format.
Definition: command_packet.h:113
command_processor_data_t
Command processor data format.
Definition: bl_command.h:56
config_i2c_cmd_packet_t::speed
uint32_t speed
Parameter 1: i2c speed in kHz.
Definition: command.h:63
status_t
int32_t status_t
Type used for all status and error return values.
Definition: fsl_common.h:121
bootloader_command_pump
status_t bootloader_command_pump(void)
Pump the command state machine.
Definition: bl_command.c:224
config_i2c_cmd_packet_t
Definition: command.h:59
command_interface_t
Interface to command processor operations.
Definition: bl_command.h:95
bootloader_command_init
status_t bootloader_command_init(void)
Initialize the command processor component.
Definition: bl_command.c:215