[Tinyos-contrib-commits]
CVS: tinyos-1.x/contrib/imote2/tools/src/blrconsole/include
BinImageFile.h, NONE, 1.1 BinImageUpload.h, NONE,
1.1 CommandLine.h, NONE, 1.1 USBComm.h, NONE, 1.1 USBDefines.h,
NONE, 1.1 USBMessageHandler.h, NONE, 1.1
Lama Nachman
lnachman at users.sourceforge.net
Tue Oct 10 15:30:39 PDT 2006
Update of /cvsroot/tinyos/tinyos-1.x/contrib/imote2/tools/src/blrconsole/include
In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv21050
Added Files:
BinImageFile.h BinImageUpload.h CommandLine.h USBComm.h
USBDefines.h USBMessageHandler.h
Log Message:
Pushed out new release OCT 2006
--- NEW FILE: BinImageFile.h ---
/* tab:4
* "Copyright (c) 2000-2003 The Regents of the University of California.
* All rights reserved.
*
* Permission to use, copy, modify, and distribute this software and its
* documentation for any purpose, without fee, and without written agreement is
* hereby granted, provided that the above copyright notice, the following
* two paragraphs and the author appear in all copies of this software.
*
* IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
* CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
* ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
*
* Copyright (c) 2002-2003 Intel Corporation
* All rights reserved.
*
* This file is distributed under the terms in the attached INTEL-LICENSE
* file. If you do not find these files, copies can be found by writing to
* Intel Research Berkeley, 2150 Shattuck Avenue, Suite 1300, Berkeley, CA,
* 94704. Attention: Intel License Inquiry.
*/
/**
* @file BinImageFile.h
* @author Junaith Ahemed Shahabdeen
*
* The functions required for handling the binary image
* data are provided by this file. Some of the functions
* are opening the binary file and noting down the size
* of the image, reading the content of the image in to
* a buffer and providing utility functions to load code
* through USB.
*/
#ifndef BIN_IMAGE_FILE_H
#define BIN_IMAGE_FILE_H
#include <stdio.h>
#include <stdlib.h>
#include <types.h>
/*Represent the file size in KBytes*/
#define FILE_SIZE_DIVIDER 1000
/**
* Load_Binary_File
*
* This function loads the binary file which has
* to be transfered through USB in to memory.
*
* @param fname Name of the file that has to be loaded
*
* @return SUCCESS | FAIL
*/
result_t Load_Binary_File (char* fname);
/**
* Get_BinFile_KBSize
*
* Return the file size in KB.
*
* @return file size
*
*/
long Get_BinFile_KBSize ();
/**
* Get_BinFile_Size
*
* Return the actual file size.
*
* @return file size.
*/
long Get_BinFile_Size ();
/**
* Get_Bin_Buffer_Data
*
* The function copies a fixed length from the starting index
* to the data pointer. The source of the data is the
* buffer in which the file is copied to.
*
* @param data Desitnation data pointer.
* @parma length Size to be copied from the main buffer.
* @param startindex Starting index in the main buffer.
*
* @return Size copied | 0 on error
*/
uint32_t Get_Bin_Buffer_Data (uint8_t* data, uint32_t length, uint32_t startindex);
/**
* Get_Num_USB_Packets
*
* Returns the number of USB packets of size IMOTE_HID_SHORT_MAXPACKETDATA
* required to transfer the whole image.
*
* FIXME:
* If there are multiple motes and if there is a scenario where
* different files must be uploaded to each mote then this file
* has to keep track of the file name for each mote.
*
* @param nodeid The mote which is requesting the information. (Future Use)
*
* @return number of usb packets in the file.
*/
uint32_t Get_Num_USB_Packets (uint32_t nodeid);
#endif
--- NEW FILE: BinImageUpload.h ---
/* tab:4
* "Copyright (c) 2000-2003 The Regents of the University of California.
* All rights reserved.
*
* Permission to use, copy, modify, and distribute this software and its
* documentation for any purpose, without fee, and without written agreement is
* hereby granted, provided that the above copyright notice, the following
* two paragraphs and the author appear in all copies of this software.
*
* IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
* CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
* ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
*
* Copyright (c) 2002-2003 Intel Corporation
* All rights reserved.
*
* This file is distributed under the terms in the attached INTEL-LICENSE
* file. If you do not find these files, copies can be found by writing to
* Intel Research Berkeley, 2150 Shattuck Avenue, Suite 1300, Berkeley, CA,
* 94704. Attention: Intel License Inquiry.
*/
/**
* @file BinImageUpload.h
* @author Junaith Ahemed Shahabdeen
*
* Provides the function required to upload code to IMote2.
*/
#ifndef BIN_IMAGE_UPLOAD_H
#define BIN_IMAGE_UPLOAD_H
#include <BinImageFile.h>
#include <USBMessageHandler.h>
/**
* Binary_Code_Upload
*
* The binary chunk request from the Imote device is
* handled by this function. The reqest from the
* device provides the start index and the size
* of the chunk in of a given file that is being
* trasfered. The function breaks the buffer in to
* USB trasferable sizes and passes it to the USBComm
* module to be trasfered to the IMote.
*
* @param startpck Starting index denoted in number of USB Packets.
* @param numpck Number of packets to be transfered from start index.
*
* @return SUCCESS | FAIL
*/
result_t Binary_Code_Upload (uint32_t startpck, uint32_t numpck);
/**
* Send_Binary_Packet
*
* When the Mote request for one binary packet during the MMU Disabled mode,
* this function will send the right data from the file. The chunk size
* passed as parameter will identify the position in the file from which
* the data has to be copied.
*
* @param nseq Sequence number (Received from Device and has to be echoed)
* @param numpck Number of packets requested.
* @param ftpr The position in the file.
*
* @return SUCCESS | FAIL
*/
result_t Send_Binary_Packet (uint32_t nseq, uint32_t numpck, uint32_t fptr);
/**
* Send_CRC_Command
*
* The function calculates the CRC of a chunk of given length
* and sends the result to the mote over USB.
*
* @param buff The buffer for which crc must be computed.
* @param length Length of the buffer.
* @param startpck Start packet number of the chunk.
* @param numt Number of USB packets in the chunk.
*
* @return SUCCESS | FAIL
*/
result_t Send_CRC_Command (uint8_t* buff, uint32_t length,
uint32_t startpck, uint32_t numt);
/**
* Send_Image_Crc_Command
*
* After the whole image is downloaded the crc of the
* cumulative crc of the file in chunk size should be
* sent as a part of verify image.
*
* @return SUCCESS | FAIL
*/
result_t Send_Image_Crc_Command ();
/**
* Send_Test_CRC_Command
*
* This function is used in the debug mode to send
* crc command to the mote. (allows to fake crc)
*
* @param startpck
* @param numt
* @param crc
*
* @return SUCCESS | FAIL
*/
result_t Send_Test_CRC_Command (uint32_t startpck, uint32_t numt, uint16_t crc);
#endif
--- NEW FILE: CommandLine.h ---
/* tab:4
* "Copyright (c) 2000-2003 The Regents of the University of California.
* All rights reserved.
*
* Permission to use, copy, modify, and distribute this software and its
* documentation for any purpose, without fee, and without written agreement is
* hereby granted, provided that the above copyright notice, the following
* two paragraphs and the author appear in all copies of this software.
*
* IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
* CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
* ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
*
* Copyright (c) 2002-2003 Intel Corporation
* All rights reserved.
*
* This file is distributed under the terms in the attached INTEL-LICENSE
* file. If you do not find these files, copies can be found by writing to
* Intel Research Berkeley, 2150 Shattuck Avenue, Suite 1300, Berkeley, CA,
* 94704. Attention: Intel License Inquiry.
*/
/**
* @file CommandLine.h
* @author Junaith Ahemed
*
* The file provides the command line interface for the
* -c option. The command line is a seprate thread.
*/
#ifndef COMMAND_LINE_H
#define COMMAND_LINE_H
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <wtypes.h>
#include <windows.h>
#include <pthread.h>
#include <USBMessageHandler.h>
/**
* Parse_Arguments
*
* Parse the arguments from the command line of the
* terminal. The function passed each argument to CmdLine_Argument
* function which will perform necessary action based
* on the argument.
*
* @param argv The argument list passed through the command line
*/
void Parse_Arguments (LPSTR argv);
/**
* CmdLine_Argument
*
* This function identifies each argument from the argument list
* passed through the command line and performs specific actions
* based on the argument.
*
* @param par Parsed argument from Parse_Argument function.
*/
void CmdLine_Argument (char* par);
/**
* Is_STImage
*
* Check if we are downloading SELF Test Image to the
* device. The function returns boolean variable
* STImage.
*
* @return STImage TRUE | FALSE
*/
BOOLEAN Is_STImage ();
/**
* Is_Test_Program_Mode
*
* Returns the boolean variable TestProgramMode. If the application is
* compiled with DEBUG flag then it accepts an extra command
* line parameter '-tp' which provides step by step control to the user
* over the communication with the bootloader.
*
* @return TestProgramMode = TRUE | FALSE
*/
BOOLEAN Is_Test_Program_Mode ();
/**
* Binary_Upload_Completed
*
* Reverts the programming mode. Checks if the application has to
* stay in command line mode.
*/
void Binary_Upload_Completed ();
/**
* Exit_Applicaiton
*
* This function provides a reliable way of exiting the application.
* It makes sure that the threads are terminated before the exit
* function is call. It is advisable to call this function for a
* clean exit rather than using exit(0).
*/
void Exit_Application ();
/**
* Command_Line
*
* The Command line interface for the application. This
* function will wait for a command from the user, once received
* it will process the command and take the necessary steps.
* It also provides a help menu which explains the available
* commands and how to use those commands.
* This function is invoked as a seperate thread.
*/
void* Command_Line ();
/**
* Handle_Get_Attribute
*
* Checks the arguments passed to the getattr command and
* sends a Get_Attribute command to the mote with appropriate
* attribute type.
*
*/
result_t Handle_Get_Attribute (char* args);
/**
* Handle_Set_Attribute
*
* Checks the arguments passed to the setattr command and
* sends a Set_Attribute command to the mote with appropriate
* attribute type and value.
*
*/
result_t Handle_Set_Attribute (char* args1, char*args2);
/**
* Handle_Send_Crc
*
* Sends a crc command to the mote. The buffer starting and the
* number of usb packets in the buffer must be passed as a
* parameter to the function together with the CRC.
* NOTE:
* This command provides a way to see if the CRC check
* works and also validate if the boot loader is re-requesting
* the same buffer when a failure occurs. If the application is
* invoked in TestProgram mode the the correct CRC will
* be printed to the screen after every chunk is uploaded.
*
* @param arg1
* @param arg2
* @param arg3
*
* @return SUCCESS | FAIL
*/
result_t Handle_Send_Crc (char* arg1, char* arg2, char* arg3);
#endif
--- NEW FILE: USBComm.h ---
/* tab:4
* "Copyright (c) 2000-2003 The Regents of the University of California.
* All rights reserved.
*
* Permission to use, copy, modify, and distribute this software and its
* documentation for any purpose, without fee, and without written agreement is
* hereby granted, provided that the above copyright notice, the following
* two paragraphs and the author appear in all copies of this software.
*
* IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
* CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
* ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
*
* Copyright (c) 2002-2003 Intel Corporation
* All rights reserved.
*
* This file is distributed under the terms in the attached INTEL-LICENSE
* file. If you do not find these files, copies can be found by writing to
* Intel Research Berkeley, 2150 Shattuck Avenue, Suite 1300, Berkeley, CA,
* 94704. Attention: Intel License Inquiry.
*/
/**
* @file USBComm.c
* @author Junaith Ahemed Shahabdeen
*
* This modules communicates with the USB driver to send and
* receive packets. It also provides functions to search
* through a list of USB devices of a specific class and
* set up an overlapped I/O communication with those devices.
* The file uses lot of inbuilt function of the HID class defined
* in the windowsDDK, the usage of each function is explained when
* required.
*/
#ifndef USB_COMM_H
#define USB_COMM_H
#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x0501
#endif
#ifndef WINVER
#define WINVER 0x0501
#endif
#ifndef WM_INPUT
#define WM_INPUT 0x00FF
#endif
#include <stdio.h>
#include <assert.h>
#include <wtypes.h>
#include <hidsdi.h>
#include <setupapi.h>
#include <windows.h>
#include <dbt.h>
#include <winuser.h>
#include <pthread.h>
#include <USBDefines.h>
#include <types.h>
/**
* USB_Init
*
* Intialize the USB Handle and clear the events and open the USB
* handle for communication by calling the <B>Open_Imote_HID</B> function.
*
* @return SUCCESS | FAIL
*/
result_t USB_Init ();
/**
* Open_Imote_HID
*
* The function opens the USB communication handle to the IMote. I browses
* through the list of members in the HID class from windows and identifies
* the deivces of interest using the PID and the VID.
*
* <B>HidD_GetHidGuid</B> gets the GUID for all system HIDs and returns the
* GUID in HidGuid.
*
* <B>SetupDiGetClassDevs</B> returns a handle to a device information set for
* all installed devices. It requires the GUID returned by GetHidGuid.
*
* <B>SetupDiEnumDeviceInterfaces</B>, On return, MyDeviceInterfaceData contains
* the handle to SP_DEVICE_INTERFACE_DATA structure for a detected device. The
* function requires the DeviceInfoSet returned in SetupDiGetClassDevs, the
* HidGuid returned in GetHidGuid and an index to specify a device.
*
* <B>SetupDiGetDeviceInterfaceDetail</B> returns a SP_DEVICE_INTERFACE_DETAIL_DATA
* structure containing information about a device. To retrieve the information,
* call this function twice. The first time returns the size of the structure in
* Length. The second time returns a pointer to the data in DeviceInfoSet. It
* requires a DeviceInfoSet returned by SetupDiGetClassDevs the
* SP_DEVICE_INTERFACE_DATA structure returned by SetupDiEnumDeviceInterfaces.
* The final parameter is an optional pointer to an SP_DEV_INFO_DATA structure.
* This application doesn't retrieve or use the structure. If retrieving the
* structure, set MyDeviceInfoData.cbSize = length of MyDeviceInfoData. and pass
* the structure's address.
*
* <B>CreateFile</B> returns a handle that enables reading and writing to the
* device. It requires the DevicePath in the detailData structure returned by
* SetupDiGetDeviceInterfaceDetail.
*
* <B>HidD_GetAttributes</B> requests information from the device. It requires
* the handle returned by CreateFile and returns a HIDD_ATTRIBUTES structure
* containing the Vendor ID, Product ID, and Product Version Number. Use this
* information to decide if the detected device is the one we're looking for.
*
* @return SUCCESS | FAIL
*/
result_t Open_Imote_HID();
/**
* Get_Device_Capabilities
*
* <B>HidD_GetPreparsedData</B> returns a pointer to a buffer containing
* the information about the device's capabilities. It requires a handle
* returned by CreateFile. There's no need to access the buffer directly, but
* HidP_GetCaps and other API functions require a pointer to the buffer.
*
* <B>HidP_GetCaps</B> Learn the device's capabilities.For standard devices
* such as joysticks, you can find out the specific capabilities of the device.
* For a custom device, the software will probably know what the device is
* capable of, and the call only verifies the information. It requires the
* pointer to the buffer returned by HidD_GetPreparsedData and returns a
* Capabilities structure containing the information.
*/
void Get_Device_Capabilities();
void Prepare_For_Overlapped_Transfer();
/**
* Write_Output_Report
*
* The function writes a byte array to the USB using WriteFile function. The
* api functions used are explained below.
*
* <B>WriteFile</B> Sends a report to the device. It returns success or failure.
* The function requires, a device handle returned by CreateFile, a buffer that
* holds the report, the Output Report length returned by HidP_GetCaps, a
* variable to hold the number of bytes written.
*
*/
void Write_Output_Report(char* data, int length);
/**
* Close_Handles
*
* Close all the device handles.
*/
void Close_Handles();
/**
* Read_Input_Report
*
* Function loops around till the handle is valid and tries to read packets from the USB. The
* main programs forks a seperate thread for this function to constantly monitory the
* incomming traffic.
*
* Few of the API calls used in this function are explained below.
*
* <B>ReadFile</B> returns the report in InputReport. It requires a device
* handle returned by CreateFile (for overlapped I/O, CreateFile must be called
* with FILE_FLAG_OVERLAPPED),the Input report length in bytes returned by
* HidP_GetCaps, and an overlapped structure whose hEvent member is set to
* an event object.
*
* <B>WaitForSingleObject</B> is used with overlapped ReadFile. It returns
* when ReadFile has received the requested data or on timeout. Requires
* an event object created with CreateEvent and a timeout value in milliseconds.
*
* <B>CancelIo</B> Cancels the ReadFile and returns non-zero on success.
*
* <B>ResetEvent</B> sets the event object to non-signaled. Requires a handle to
* the event object. Returns non-zero on success.
*
*/
void Read_Input_Report();
/**
* Register_For_Device_Notifications
*
* Register a particular Class of device with the lover level
* driver interface to get notifications about any changes in
* the device status (attached, detached etc.)
*
* @param HidGuid GUID of a particular class.
*/
void Register_For_Device_Notifications (GUID hidG);
/**
* Get_OutputReportByteLength
*
* Returns the output report length of the
* current device.
*
* @return Report Length.
*/
int Get_OutputReportByteLength ();
#endif
--- NEW FILE: USBDefines.h ---
/* tab:4
* "Copyright (c) 2000-2003 The Regents of the University of California.
* All rights reserved.
*
* Permission to use, copy, modify, and distribute this software and its
* documentation for any purpose, without fee, and without written agreement is
* hereby granted, provided that the above copyright notice, the following
* two paragraphs and the author appear in all copies of this software.
*
* IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
* CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
* ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
*
* Copyright (c) 2002-2003 Intel Corporation
* All rights reserved.
*
* This file is distributed under the terms in the attached INTEL-LICENSE
* file. If you do not find these files, copies can be found by writing to
* Intel Research Berkeley, 2150 Shattuck Avenue, Suite 1300, Berkeley, CA,
* 94704. Attention: Intel License Inquiry.
*/
#ifndef USB_DEFINES_H
#define USB_DEFINES_H
#include <wtypes.h>
typedef struct USBdata{
BYTE *data;
DWORD i;
DWORD n;
BYTE type;
DWORD len;
} USBdata;
#define isFlagged(_BITFIELD, _FLAG) (((_BITFIELD) & (_FLAG)) != 0)
#define _BIT(_bit) (1 << ((_bit) & 0x1f))
#define IMOTE_HID_TYPE_COUNT 4
//Imote2 HID report, byte positions
#define IMOTE_HID_TYPE 1
#define IMOTE_HID_NI 2
//Imote2 HID report, type byte, bit positions
#define IMOTE_HID_TYPE_CL 0
#define IMOTE_HID_TYPE_L 2
#define IMOTE_HID_TYPE_H 4
#define IMOTE_HID_TYPE_MSC 5
//Imote2 HID report, type byte, L defintions
#define IMOTE_HID_TYPE_L_BYTE 0
#define IMOTE_HID_TYPE_L_SHORT 1
#define IMOTE_HID_TYPE_L_INT 2
//Imote2 HID report, L sizes
#define IMOTE_HID_TYPE_L_BYTE_SIZE 15871
#define IMOTE_HID_TYPE_L_SHORT_SIZE 3997695
#define IMOTE_HID_TYPE_L_INT_SIZE ULONG_MAX
//Imote2 HID report, type byte, CL defintions
#define IMOTE_HID_TYPE_CL_GENERAL 0
#define IMOTE_HID_TYPE_CL_BINARY 1
#define IMOTE_HID_TYPE_CL_RPACKET 2
#define IMOTE_HID_TYPE_CL_BLUSH 3
//Imote2 HID report, type byte, MSC definitions
#define IMOTE_HID_TYPE_MSC_DEFAULT 0
#define IMOTE_HID_TYPE_MSC_BLOADER 1
/**
* The types used by the boot loader extending
* JT Protocol messages.
*/
#define IMOTE_HID_TYPE_MSC_REBOOT 2
#define IMOTE_HID_TYPE_MSC_COMMAND 3
#define IMOTE_HID_TYPE_MSC_BINARY 4
#define IMOTE_HID_TYPE_MSC_ERROR 5
//Imote2 HID report, max packet data sizes
#define IMOTE_HID_BYTE_MAXPACKETDATA 62
#define IMOTE_HID_SHORT_MAXPACKETDATA 61
#define IMOTE_HID_INT_MAXPACKETDATA 59
#define WM_RECEIVE_SERIAL_DATA (WM_USER + 1)
#define WM_RECEIVE_USB_DATA (WM_USER + 2)
#define WM_CLOSE_PORT (WM_USER + 3)
#endif
--- NEW FILE: USBMessageHandler.h ---
/* tab:4
* "Copyright (c) 2000-2003 The Regents of the University of California.
* All rights reserved.
*
* Permission to use, copy, modify, and distribute this software and its
* documentation for any purpose, without fee, and without written agreement is
* hereby granted, provided that the above copyright notice, the following
* two paragraphs and the author appear in all copies of this software.
*
* IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
* CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
* ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
*
* Copyright (c) 2002-2003 Intel Corporation
* All rights reserved.
*
* This file is distributed under the terms in the attached INTEL-LICENSE
* file. If you do not find these files, copies can be found by writing to
* Intel Research Berkeley, 2150 Shattuck Avenue, Suite 1300, Berkeley, CA,
* 94704. Attention: Intel License Inquiry.
*/
/**
* @file USBMessageHandler.h
* @author Junaith Ahemed Shahabdeen
*
* This file provides a higher level USB Message
* parser and assembler. The message from the
* USB driver is identified by its message type
* and the required modules are invoked based on
* the type.
*/
#ifndef USB_MESSAGE_HANDLER_H
#define USB_MESSAGE_HANDLER_H
#include <MessageDefines.h>
/**
* Command_Packet_Received
*
* The function is signalled when a command packet is received
* from the device. The function parses the USB payload
* to determine the command type and calls the required module
* based on the type.
*
* @param data USB Payload.
*
* @return SUCCESS | FAIL
*/
result_t Command_Packet_Received (char* data);
/**
* Error_Packet_Received
*
* Received an error from the Device.
*
* @param data Valid usb data.
* @return SUCCESS | FAIL
*/
result_t Error_Packet_Received (uint8_t* data);
/**
* Binary_Packet_Received
*
* Binary data received from the mote. Currently the mote sends
* a binary packet only when the pc requests a flash dump or a
* buffer dump.
*
* @param data Binary data from the mote.
* @param length Length of the data.
* @param seq Sequence number from the packet.
*/
result_t Binary_Packet_Received (char* data, uint8_t length, uint32_t seq);
/**
* Dump_From_Flash
*
* Request a data chunk from the flash, the length of the
* chunk and the flash address is passed as parameter to
* the function. This function basically triggers a request
* response cycle between the MOTE and the PC Application till
* the entire chunk is downloaded.
*
* @param addr Start address of the chunk in flash.
* @param length The size of the chunk.
*
* @return SUCCESS | FAIL
*/
result_t Dump_From_Flash (uint32_t addr, uint32_t length);
/**
* Get_Buffer_Dump
*
* The function requests the next packet from the IMote during
* flash dump mode. The process continues till the window size
* and is trigerred by the <I>Dump_From_Flash</I> function
* for the next buffer.
*
* @return SUCESS | FAIL
*/
result_t Get_Buffer_Dump ();
/**
* Send_USB_Command
*
* Send a command message to the Mote.
*
* @param cmd Command struct with appropriate data defined in MessageDefines.h.
* @param length Length of the command data.
*
* @return SUCCESS | FAIL
*/
result_t Send_USB_Command (USBCommand* cmd, uint32_t Length);
/**
* Send_USB_Command_Packet
*
* Send a command message to the Mote.
*
* @param cmd Command type defined in the enum (see MessageDefines.h).
* @param clen Length of the command data.
* @param cdata Command data in array format.
*
* @return SUCCESS | FAIL
*/
result_t Send_USB_Command_Packet (Commands cmd, uint8_t clen, void* cdata);
/**
* Send_Binary_Data
*
* Send a binary buffer to the device. Usually binary data is prepended
* with the sequence number of the packet the final packet will
* have a sequence number of 0. JT Protocol requires a header with the
* valid bytes in the packet if the seqence number is 0, this allows
* the pc host to send less than IMOTE_HID_TYPE_L_SHORT in the last
* packet if required.
*
* @param buff Pointer to the binary buffer.
* @param length Length of the buffer.
* @param seq Current Sequence number of the buffer.
*
* @return SUCCESS | FAIL
*/
result_t Send_Binary_Data (uint8_t* buff, uint32_t Length, uint16_t seq);
/**
* Send_USB_Binary_Data
*
* The function allows the user to send binary data packed in
* a structure.
*
* @param img The struct which contains binary data.
* @param length length of the struct with data.
*
* @return SUCCESS | FAIL
*/
result_t Send_USB_Binary_Data (USBImagePck* img, uint32_t Length);
//#ifdef DEBUG
/**
* Dbg_Binary_Code_Upload
*
* Function used in the -tp option to send the
* image detail command to the device.
*
* @return SUCCESS | FAIL
*/
result_t Dbg_Binary_Code_Upload ();
//#endif
#endif
More information about the Tinyos-contrib-commits
mailing list