93 lines
2.3 KiB
C
93 lines
2.3 KiB
C
/**********************************************************************
|
||
Project: Automatic cat feeder
|
||
Date: march 19 2006
|
||
Author: Jean-Fran<61>ois Martel
|
||
Target: PIC 18F252
|
||
Compiler: Microchip mcc18
|
||
Filename: Protocol.h
|
||
|
||
File description: Communication protocol implementation.
|
||
|
||
|
||
jean-francois.martel@polymtl.ca
|
||
**********************************************************************/
|
||
|
||
|
||
#ifndef BOOTLOADERPROTOCOL_H
|
||
#define BOOTLOADERPROTOCOL_H
|
||
|
||
//Protocol buffer specific definitions
|
||
|
||
#define MAX_BOOTLOADER_PAYLOAD_SIZE 256
|
||
#define BOOTLOADER_FRAME_HEADER 0xDEADBEEF
|
||
#define BOOTLOADER_FRAME_HEADER_1 0xDE
|
||
#define BOOTLOADER_FRAME_HEADER_2 0xAD
|
||
#define BOOTLOADER_FRAME_HEADER_3 0xBE
|
||
#define BOOTLOADER_FRAME_HEADER_4 0xEF
|
||
#define PROTOCOL_INFO_DATA_SIZE 13 //Header + Cmd + Size + CRC = 13 bytes
|
||
//State Machine states
|
||
enum States
|
||
{
|
||
Initialization,
|
||
RxHeader1,
|
||
RxHeader2,
|
||
RxHeader3,
|
||
RxHeader4,
|
||
RxCmd,
|
||
RxPayloadSize1,
|
||
RxPayloadSize2,
|
||
RxPayloadSize3,
|
||
RxPayloadSize4,
|
||
RxPayload,
|
||
RxCRC1,
|
||
RxCRC2,
|
||
RxCRC3,
|
||
RxCRC4
|
||
};
|
||
|
||
enum eBootloaderProtocolDataTransferError
|
||
{
|
||
BOOTLOADER_CHUNK_TRANSFER_SUCCESS = 1,
|
||
BOOTLOADER_CHUNK_TRANSFER_ERROR_RESEND = 2,
|
||
BOOTLOADER_CHUNK_TRANSFER_ERROR_FLASH_FAILURE = 3,
|
||
BOOTLOADER_CHUNK_TRANSFER_ERROR_INVALID_CHUNK_INDEX = 4,
|
||
|
||
BOOTLOADER_CHUNK_TRANSFER_MAX_ERROR
|
||
};
|
||
|
||
//enum DEVICES_IDS
|
||
//{
|
||
// ID_MASTER, //Master Controller
|
||
// ID_CONSOLE, //LCD Console
|
||
// ID_PC, //PC
|
||
// ID_AV_MUX, //Audio Video Multiplexer
|
||
// ID_IR_REMOTE,
|
||
// ID_DEADBOLT
|
||
//};
|
||
|
||
//enum MESSAGE_IDS
|
||
//{
|
||
// TX_NETWORK_ACK = 1,
|
||
// RX_GET_STATUS,
|
||
// TX_DEADBOLT_STATUS,
|
||
//
|
||
// MAX_NETWORK_CMD
|
||
//};
|
||
|
||
//State machine states definition
|
||
|
||
void BootloaderProtocolInit(void);
|
||
void BootloaderProtocolStateMachine(unsigned char STATE);
|
||
void BootloaderProtocolResetStateMachine(void);
|
||
void BootloaderProtocolProtocolAnalyzeNewData(unsigned char *DataBuf, int size);
|
||
void BootloaderProtocolSendFrame(unsigned char Cmd, int size);
|
||
unsigned char *BootloaderProtocolGetDataBufferPtr();
|
||
|
||
void BootloaderProtocolSendHeartbeat();
|
||
void BootloaderProtocolSendACK(unsigned char Cmd);
|
||
void BootloaderProtocolSendNACK(unsigned char Cmd);
|
||
void BootloaderProtocolSendInitUploadResponse();
|
||
void BootloaderProtocolSendDataChunkResult(char ErrorCode, int ChunkValue);
|
||
|
||
|
||
#endif |