Kinetis Bootloader  2.0.0
Common bootloader for Kinetis devices
bl_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 };
47 
49 typedef struct CommandHandlerEntry
50 {
51  void (*handleCommand)(uint8_t *packet, uint32_t packetLength);
52  status_t (*handleData)(bool *hasMoreData);
54 
56 typedef struct CommandProcessorData
57 {
58  int32_t state;
59  uint8_t *packet;
60  uint32_t packetLength;
61  struct DataPhase
62  {
63  uint8_t *data;
64  uint32_t count;
65  uint32_t address;
66  uint32_t dataBytesAvailable;
67  uint8_t commandTag;
68  uint8_t option;
69 
70 #if defined(__cplusplus)
71  DataPhase()
72  : data(NULL)
73  , count(0)
74  , address(0)
75  , dataBytesAvailable(0)
76  , commandTag(0)
77  , option(0)
78  {
79  }
80 #endif
81  } dataPhase;
82  const command_handler_entry_t *handlerEntry;
83 #if defined(__cplusplus)
85  : state(kCommandState_CommandPhase)
86  , packet(NULL)
87  , packetLength(0)
88  , dataPhase()
89  {
90  }
91 #endif
93 
95 typedef struct CommandInterface
96 {
97  status_t (*init)(void);
98  status_t (*pump)(void);
99  const command_handler_entry_t *handlerTable;
100  command_processor_data_t *stateData;
102 
104 // Externals
106 
109 
111 // Prototypes
113 
114 #if defined(__cplusplus)
115 extern "C" {
116 #endif // __cplusplus
117 
120 
125 
126 #if defined(__cplusplus)
127 }
128 #endif // __cplusplus
129 
131 
132 #endif // _bl_command.h_
133 // 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
uint8_t * packet
Pointer to packet in process.
Definition: bl_command.h:59
uint32_t packetLength
Length of packet in process.
Definition: bl_command.h:60
Format of command handler entry.
Definition: bl_command.h:49
Command processor data format.
Definition: bl_command.h:56
int32_t state
Current state machine state.
Definition: bl_command.h:58
uint32_t count
Remaining count to produce/consume.
Definition: bl_command.h:64
CommandProcessorData()
Pointer to handler table entry for packet in process.
Definition: bl_command.h:84
uint32_t dataBytesAvailable
Number of bytes available at data pointer.
Definition: bl_command.h:66
uint8_t commandTag
Tag of command running data phase.
Definition: bl_command.h:67
uint8_t * data
Data for data phase.
Definition: bl_command.h:63
Definition: bl_command.h:61
uint8_t option
option for special command
Definition: bl_command.h:68
uint32_t address
Address for data phase.
Definition: bl_command.h:65
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
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