bl_peripheral.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 _peripheral_h
#define _peripheral_h
#include <stdint.h>
#include "bootloader_common.h"
// Declarations
enum _peripheral_types
{
kPeripheralType_UART = (1 << 0),
kPeripheralType_I2CSlave = (1 << 1),
kPeripheralType_SPISlave = (1 << 2),
kPeripheralType_CAN = (1 << 3),
kPeripheralType_USB_HID = (1 << 4),
kPeripheralType_USB_CDC = (1 << 5),
kPeripheralType_USB_DFU = (1 << 6),
kPeripheralType_USB_MSC = (1 << 7)
};
typedef enum _pinmux_types
{
kPinmuxType_Default = 0,
kPinmuxType_GPIO = 1,
kPinmuxType_Peripheral = 2
} pinmux_type_t;
// Forward declaration.
typedef struct PeripheralDescriptor peripheral_descriptor_t;
typedef void (*serial_byte_receive_func_t)(uint8_t);
typedef struct _peripheral_control_interface
{
bool (*pollForActivity)(const peripheral_descriptor_t *self);
status_t (*init)(const peripheral_descriptor_t *self, serial_byte_receive_func_t function);
void (*shutdown)(const peripheral_descriptor_t *self);
void (*pump)(const peripheral_descriptor_t *self);
} peripheral_control_interface_t;
typedef struct _peripheral_byte_inteface
{
status_t (*init)(const peripheral_descriptor_t *self);
#ifdef BOOTLOADER_HOST
status_t (*read)(const peripheral_descriptor_t *self, uint8_t *buffer, uint32_t requestedBytes);
#endif // #ifdef BOOTLOADER_HOST
status_t (*write)(const peripheral_descriptor_t *self, const uint8_t *buffer, uint32_t byteCount);
} peripheral_byte_inteface_t;
typedef enum _packet_type
{
kPacketType_Command,
kPacketType_Data
} packet_type_t;
typedef struct _peripheral_packet_interface
{
status_t (*init)(const peripheral_descriptor_t *self);
status_t (*readPacket)(const peripheral_descriptor_t *self,
uint8_t **packet,
uint32_t *packetLength,
packet_type_t packetType);
status_t (*writePacket)(const peripheral_descriptor_t *self,
const uint8_t *packet,
uint32_t byteCount,
packet_type_t packetType);
void (*abortDataPhase)(const peripheral_descriptor_t *self);
status_t (*finalize)(const peripheral_descriptor_t *self);
uint32_t (*getMaxPacketSize)(const peripheral_descriptor_t *self);
void (*byteReceivedCallback)(uint8_t byte);
} peripheral_packet_interface_t;
struct PeripheralDescriptor
{
uint32_t typeMask;
uint32_t instance;
void (*pinmuxConfig)(uint32_t instance, pinmux_type_t pinmux);
const peripheral_control_interface_t *controlInterface;
const peripheral_byte_inteface_t *byteInterface;
const peripheral_packet_interface_t *packetInterface;
};
// Externs
extern const peripheral_descriptor_t g_peripherals[];
#endif // _peripheral_h
// EOF
PeripheralDescriptor::packetInterface
const peripheral_packet_interface_t * packetInterface
Packet level interface for the peripheral.
Definition: bl_peripheral.h:144
packet_type_t
packet_type_t
Packet types.
Definition: bl_peripheral.h:94
kPacketType_Data
Send or expect a data packet.
Definition: bl_peripheral.h:97
PeripheralDescriptor::instance
uint32_t instance
The instance number of the peripheral.
Definition: bl_peripheral.h:130
g_peripherals
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_t
Peripheral control interface.
Definition: bl_peripheral.h:75
peripheral_packet_interface_t
Peripheral Packet Interface.
Definition: bl_peripheral.h:101
PeripheralDescriptor::typeMask
uint32_t typeMask
Bit mask identifying the peripheral type.
Definition: bl_peripheral.h:127
kPacketType_Command
Send or expect a command packet.
Definition: bl_peripheral.h:96
PeripheralDescriptor
Peripheral descriptor.
Definition: bl_peripheral.h:122
peripheral_byte_inteface_t
Peripheral abstract byte interface.
Definition: bl_peripheral.h:84
PeripheralDescriptor::controlInterface
const peripheral_control_interface_t * controlInterface
Control interface for the peripheral.
Definition: bl_peripheral.h:136
_peripheral_types
_peripheral_types
Peripheral type bit mask definitions.
Definition: bl_peripheral.h:49
pinmux_type_t
pinmux_type_t
Pinmux types.
Definition: bl_peripheral.h:62
PeripheralDescriptor::byteInterface
const peripheral_byte_inteface_t * byteInterface
Byte-level interface for the peripheral.
Definition: bl_peripheral.h:141
status_t
int32_t status_t
Type used for all status and error return values.
Definition: fsl_common.h:121