Kinetis Bootloader  2.0.0
Common bootloader for Kinetis devices
command.h
1 /*
2  * Copyright (c) 2013, Freescale Semiconductor, Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without modification,
6  * are permitted provided that the following conditions are met:
7  *
8  * o Redistributions of source code must retain the above copyright notice, this list
9  * of conditions and the following disclaimer.
10  *
11  * o Redistributions in binary form must reproduce the above copyright notice, this
12  * list of conditions and the following disclaimer in the documentation and/or
13  * other materials provided with the distribution.
14  *
15  * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
16  * contributors may be used to endorse or promote products derived from this
17  * software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 
31 #ifndef _command_h
32 #define _command_h
33 
36 
38 // Definitions
40 
43 {
44  kCommandState_CommandPhase,
45  kCommandState_DataPhase,
46  kCommandState_DataPhaseRead,
47  kCommandState_DataPhaseWrite
48 };
49 
50 typedef enum _buspal_state
51 {
52  kBuspal_Idle,
53  kBuspal_I2c,
54  kBuspal_Spi,
55  kBuspal_FlexCAN,
56  kBuspal_MsCAN
57 } buspal_state_t;
58 
59 typedef struct ConfigI2cCmdPacket
60 {
62  uint32_t address;
63  uint32_t speed;
65 
67 typedef struct CommandHandlerEntry
68 {
69  void (*handleCommand)(uint8_t *packet, uint32_t packetLength);
70  status_t (*handleData)(bool *hasMoreData);
72 
74 typedef struct CommandProcessorData
75 {
76  int32_t state;
77  uint8_t *packet;
78  uint32_t packetLength;
79  struct DataPhase
80  {
81  uint8_t *data;
82  uint32_t count;
83  uint32_t address;
84  uint32_t dataBytesAvailable;
85  uint8_t commandTag;
86  uint8_t option;
87  } dataPhase;
88  const command_handler_entry_t *handlerEntry;
90 
92 typedef struct CommandInterface
93 {
94  status_t (*init)(void);
95  status_t (*pump)(void);
96  const command_handler_entry_t *handlerTable;
97  command_processor_data_t *stateData;
99 
101 // Externals
103 
106 
108 // Prototypes
110 
111 #if defined(__cplusplus)
112 extern "C" {
113 #endif // __cplusplus
114 
117 
122 
123 #if defined(__cplusplus)
124 }
125 #endif // __cplusplus
126 
128 
129 #endif // _command.h_
130 // EOF
command_interface_t g_commandInterface
Default command interface.
Definition: bl_command.c:207
_command_state
Command state machine states.
Definition: bl_command.h:42
Format of command handler entry.
Definition: bl_command.h:49
uint32_t address
Parameter 0: i2c slave address.
Definition: command.h:62
command_packet_t commandPacket
header
Definition: command.h:61
Command packet format.
Definition: command_packet.h:113
Command processor data format.
Definition: bl_command.h:56
uint32_t speed
Parameter 1: i2c speed in kHz.
Definition: command.h:63
int32_t status_t
Type used for all status and error return values.
Definition: fsl_common.h:121
status_t bootloader_command_pump(void)
Pump the command state machine.
Definition: bl_command.c:224
Definition: command.h:59
Interface to command processor operations.
Definition: bl_command.h:95
status_t bootloader_command_init(void)
Initialize the command processor component.
Definition: bl_command.c:215