Bluetooth SPI MBED

Dependencies:   mbed-rtos mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers sdep.h Source File

sdep.h

Go to the documentation of this file.
00001 /******************************************************************************/
00002 /*!
00003     @file     sdep.h
00004     @author   hathach
00005 
00006     @section LICENSE
00007 
00008     Software License Agreement (BSD License)
00009 
00010     Copyright (c) 2013, K. Townsend (microBuilder.eu)
00011     Copyright (c) 2014, Adafruit Industries (adafruit.com)
00012 
00013     All rights reserved.
00014 
00015     Redistribution and use in source and binary forms, with or without
00016     modification, are permitted provided that the following conditions are met:
00017     1. Redistributions of source code must retain the above copyright
00018     notice, this list of conditions and the following disclaimer.
00019     2. Redistributions in binary form must reproduce the above copyright
00020     notice, this list of conditions and the following disclaimer in the
00021     documentation and/or other materials provided with the distribution.
00022     3. Neither the name of the copyright holders nor the
00023     names of its contributors may be used to endorse or promote products
00024     derived from this software without specific prior written permission.
00025 
00026     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
00027     EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00028     WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00029     DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
00030     DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00031     (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00032     LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00033     ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00034     (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00035     THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00036 */
00037 /******************************************************************************/
00038 #ifndef _SDEP_H_
00039 #define _SDEP_H_
00040 
00041 #include "common_header.h "
00042 
00043 #define SDEP_MAX_PACKETSIZE       16 // Maximum payload per packet
00044 
00045 /******************************************************************************/
00046 /*!
00047     This enumeration is used to make sure that each command has a unique
00048     ID, and is used to create the command lookup table enum further down
00049 */
00050 /******************************************************************************/
00051 typedef enum
00052 {
00053   SDEP_CMDTYPE_INITIALIZE     = 0xBEEF,   /**< Controls the on board LED(s) */
00054   SDEP_CMDTYPE_AT_WRAPPER     = 0x0A00,
00055   SDEP_CMDTYPE_BLE_UARTTX     = 0x0A01,
00056   SDEP_CMDTYPE_BLE_UARTRX     = 0x0A02,
00057 } sdepCmdType_t ;
00058 
00059 /******************************************************************************/
00060 /*!
00061     The first byte of every transfer defines the message type
00062 */
00063 /******************************************************************************/
00064 typedef enum
00065 {
00066   SDEP_MSGTYPE_COMMAND          = 0x10,
00067   SDEP_MSGTYPE_RESPONSE         = 0x20,
00068   SDEP_MSGTYPE_ALERT            = 0x40,
00069   SDEP_MSGTYPE_ERROR            = 0x80
00070 } sdepMsgType_t ;
00071 
00072 /******************************************************************************/
00073 /*!
00074     4-byte header for SDEP messages
00075 */
00076 /******************************************************************************/
00077 typedef struct ATTR_PACKED {
00078   uint8_t msg_type;           // 8-bit message type indicator (sdepMsgType_t)
00079 
00080   union
00081   {
00082     uint16_t cmd_id;          // 16-bit command ID
00083     struct
00084     {
00085       uint8_t cmd_id_low;
00086       uint8_t cmd_id_high;
00087     };
00088   };
00089 
00090   struct ATTR_PACKED
00091   {
00092     uint8_t length    : 7;    // Payload length (for this packet)
00093     uint8_t more_data : 1;    // 'more' bit for multiple packet transfers
00094   };
00095 } sdepMsgHeader_t ;
00096 
00097 /******************************************************************************/
00098 /*!
00099     SDEP command message
00100 */
00101 /******************************************************************************/
00102 typedef struct ATTR_PACKED  
00103 {
00104   sdepMsgHeader_t  header;
00105   uint8_t payload[SDEP_MAX_PACKETSIZE];
00106 } sdepMsgCommand_t ;
00107 
00108 /******************************************************************************/
00109 /*!
00110     Response message struct (same as sdepMsgCommand_t)
00111 */
00112 /******************************************************************************/
00113 typedef sdepMsgCommand_t  sdepMsgResponse_t ;
00114 
00115 /******************************************************************************/
00116 /*!
00117     Alert message struct
00118 */
00119 /******************************************************************************/
00120 typedef sdepMsgCommand_t  sdepMsgAlert_t ;
00121 
00122 #endif