Kinetis Bootloader  2.0.0
Common bootloader for Kinetis devices
bl_peripheral.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 _peripheral_h
32 #define _peripheral_h
33 
34 #include <stdint.h>
35 #include "bootloader_common.h"
36 
39 
41 // Declarations
43 
50 {
51  kPeripheralType_UART = (1 << 0),
52  kPeripheralType_I2CSlave = (1 << 1),
53  kPeripheralType_SPISlave = (1 << 2),
54  kPeripheralType_CAN = (1 << 3),
55  kPeripheralType_USB_HID = (1 << 4),
56  kPeripheralType_USB_CDC = (1 << 5),
57  kPeripheralType_USB_DFU = (1 << 6),
58  kPeripheralType_USB_MSC = (1 << 7)
59 };
60 
62 typedef enum _pinmux_types
63 {
64  kPinmuxType_Default = 0,
65  kPinmuxType_GPIO = 1,
66  kPinmuxType_Peripheral = 2
68 
69 // Forward declaration.
70 typedef struct PeripheralDescriptor peripheral_descriptor_t;
71 
72 typedef void (*serial_byte_receive_func_t)(uint8_t);
73 
75 typedef struct _peripheral_control_interface
76 {
77  bool (*pollForActivity)(const peripheral_descriptor_t *self);
78  status_t (*init)(const peripheral_descriptor_t *self, serial_byte_receive_func_t function);
79  void (*shutdown)(const peripheral_descriptor_t *self);
80  void (*pump)(const peripheral_descriptor_t *self);
82 
84 typedef struct _peripheral_byte_inteface
85 {
86  status_t (*init)(const peripheral_descriptor_t *self);
87 #ifdef BOOTLOADER_HOST
88  status_t (*read)(const peripheral_descriptor_t *self, uint8_t *buffer, uint32_t requestedBytes);
89 #endif // #ifdef BOOTLOADER_HOST
90  status_t (*write)(const peripheral_descriptor_t *self, const uint8_t *buffer, uint32_t byteCount);
92 
94 typedef enum _packet_type
95 {
99 
101 typedef struct _peripheral_packet_interface
102 {
103  status_t (*init)(const peripheral_descriptor_t *self);
104  status_t (*readPacket)(const peripheral_descriptor_t *self,
105  uint8_t **packet,
106  uint32_t *packetLength,
107  packet_type_t packetType);
108  status_t (*writePacket)(const peripheral_descriptor_t *self,
109  const uint8_t *packet,
110  uint32_t byteCount,
111  packet_type_t packetType);
112  void (*abortDataPhase)(const peripheral_descriptor_t *self);
113  status_t (*finalize)(const peripheral_descriptor_t *self);
114  uint32_t (*getMaxPacketSize)(const peripheral_descriptor_t *self);
115  void (*byteReceivedCallback)(uint8_t byte);
117 
123 {
127  uint32_t typeMask;
128 
130  uint32_t instance;
131 
133  void (*pinmuxConfig)(uint32_t instance, pinmux_type_t pinmux);
134 
137 
142 
145 };
146 
148 // Externs
150 
152 extern const peripheral_descriptor_t g_peripherals[];
153 
155 
156 #endif // _peripheral_h
157 // EOF
const peripheral_packet_interface_t * packetInterface
Packet level interface for the peripheral.
Definition: bl_peripheral.h:144
packet_type_t
Packet types.
Definition: bl_peripheral.h:94
Send or expect a data packet.
Definition: bl_peripheral.h:97
uint32_t instance
The instance number of the peripheral.
Definition: bl_peripheral.h:130
const peripheral_descriptor_t g_peripherals[]
Array of all peripherals available in this device.
Definition: MK65F18/src/bus_pal_hardware.c:206
Peripheral control interface.
Definition: bl_peripheral.h:75
Peripheral Packet Interface.
Definition: bl_peripheral.h:101
uint32_t typeMask
Bit mask identifying the peripheral type.
Definition: bl_peripheral.h:127
Send or expect a command packet.
Definition: bl_peripheral.h:96
Peripheral descriptor.
Definition: bl_peripheral.h:122
Peripheral abstract byte interface.
Definition: bl_peripheral.h:84
const peripheral_control_interface_t * controlInterface
Control interface for the peripheral.
Definition: bl_peripheral.h:136
_peripheral_types
Peripheral type bit mask definitions.
Definition: bl_peripheral.h:49
pinmux_type_t
Pinmux types.
Definition: bl_peripheral.h:62
const peripheral_byte_inteface_t * byteInterface
Byte-level interface for the peripheral.
Definition: bl_peripheral.h:141
int32_t status_t
Type used for all status and error return values.
Definition: fsl_common.h:121