Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers LPC.h Source File

LPC.h

00001 #ifndef MBED_LPC_H
00002 #define MBED_LPC_H
00003 #include "mbed.h"
00004 
00005 class SerialBuffered {
00006 public:
00007     SerialBuffered();
00008     SerialBuffered( size_t bufferSize, PinName tx, PinName rx );
00009     virtual ~SerialBuffered();
00010     int getc();                                             // will block till the next character turns up, or return -1 if there is a timeout
00011     int readable();                                         // returns 1 if there is a character available to read, 0 otherwise
00012     void setTimeout( float seconds );                       // maximum time in seconds that getc() should block while waiting for a character. Pass -1 to disable the timeout
00013     size_t readBytes(char *bytes, size_t requested );       //Read requested bytes into a buffer, return number actually read, which may be less than requested if there has been a timeout
00014     
00015     void InitUART(int baud);                                //Sets the baud rate to a user-defined value
00016     void TargetSendString(char string[]);                   //Sends a string to the board
00017     void TargetSendStringAndCR(char string[]);              //Sends a string to the board followed by a carriage return character
00018     int CheckTargetPresent(void);                           //Starts the handshaking and then verifies the type of chip from a returned ID code
00019     int ProgramFile(void);                           //Programs the UUEncoded data onto the RAM and the copies into the flash
00020     int UUEncode(void);                                     //Encodes the file into UU-encoded format
00021     int Encode3(void);                                      //Sub-function to UUEncode which encodes the 3 raw bytes into 4 UU-encoded bytes
00022     int FirstEncode(void);                                  //Encodes the first UUEncoded line which needs the first checksum added to it as the 8th DWORD
00023     int EndUUEncode(void);                                  //Function to encode the last 124 bytes of the 1024 byte blocks and output to enduuline[]
00024     int SectorFill(int add);                                //Function to load the data onto the board, keeping track of position in FLASH memory
00025     int IDCheck(int idcode);                                //Function that looks up the relevant information about the chip from a returned ID code
00026 
00027 private:
00028     FILE *f;                                                //File pointer (binary file for writing to the chip and a temporary file with the checksum-added DWORD)
00029     int lastSector;                                         //Variable defnining the number of sectors which exist in Flash memory on the specific LPC17xx chip
00030     char strChipType[80];                                   //Char array containing the chip type
00031     char fname[64];                                         //Char array containing the file name specified in the main.cpp
00032     char buf[1024];                                         //Char array containing the currently returned string from the LPC17xx board
00033     int n1, n2, n3, n4;                                     //UU-Encoded 4 bytes corresponding to the converted 3 raw bytes
00034     int ch1, ch2, ch3;                                      //3 raw bytes for conversion into the 4 bytes above --^
00035     int sum20, checksum;                                    //Checksum sent after a certain number of UU-Encoded lines
00036     bool readAll;                                           //Global variable determining if the file has been encoded and sent fully
00037     char uuline[64];                                        //Contains the current UU-encoded line to be sent to the board next
00038     char enduuline[52];                                     //Output array from EndUUEncode()
00039     char sum[45], sum1[28];                                 //The char arrays assist in the conversion to big-endian for the FirstEncode() function
00040     unsigned int id;                                        //ID code for the attached chip
00041     int bytesfilled;                                        //Int to keep track of the position in the 1024 byte block (sets up triggering of switching to EndUUEncode()
00042     int lines;                                              //Keeps track of the number of lines sent before a checksum (checksum should be sent after every 20 UUline block where possible
00043     bool firstencode;                                       //True if no encoding of the file has been done
00044     int maxsector;                                          //Number of sectors required in order to accommodate the program, based on filesize
00045     long int filesize;                                      //Filesize is the...file...size (number of bytes in the file to load to the chip)
00046     int RAM;
00047     char speed[10];
00048     
00049     //Serial Buffered
00050     void handleInterrupt();
00051     
00052     uint8_t *m_buff;                                        //Points at a circular buffer, containing data from m_contentStart, for m_contentSize bytes, wrapping when you get to the end
00053     uint16_t  m_contentStart;                               //Index of first bytes of content
00054     uint16_t  m_contentEnd;                                 //Index of bytes after last byte of content
00055     uint16_t m_buffSize;
00056     float m_timeout;                                        //Can be user-defined
00057     Timer m_timer;                                          //Timeout timer
00058     
00059     Serial target;
00060 };
00061 #endif