Dependencies:   mbed

Committer:
daugihao
Date:
Thu Sep 29 11:32:52 2011 +0000
Revision:
1:0872c208795f
Parent:
0:15536fa79743
Child:
2:9e3ee0c6536b
Now no need to update main.cpp. Will load the first .lpc file it finds on the local filesystem.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
daugihao 0:15536fa79743 1 #ifndef MBED_LPC_H
daugihao 0:15536fa79743 2 #define MBED_LPC_H
daugihao 0:15536fa79743 3 #include "mbed.h"
daugihao 0:15536fa79743 4
daugihao 0:15536fa79743 5 class SerialBuffered {
daugihao 0:15536fa79743 6 public:
daugihao 0:15536fa79743 7 SerialBuffered();
daugihao 0:15536fa79743 8 SerialBuffered( size_t bufferSize, PinName tx, PinName rx );
daugihao 0:15536fa79743 9 virtual ~SerialBuffered();
daugihao 0:15536fa79743 10 int getc(); // will block till the next character turns up, or return -1 if there is a timeout
daugihao 0:15536fa79743 11 int readable(); // returns 1 if there is a character available to read, 0 otherwise
daugihao 0:15536fa79743 12 void setTimeout( float seconds ); // maximum time in seconds that getc() should block while waiting for a character. Pass -1 to disable the timeout
daugihao 0:15536fa79743 13 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
daugihao 0:15536fa79743 14
daugihao 0:15536fa79743 15 void InitUART(int baud); //Sets the baud rate to a user-defined value
daugihao 0:15536fa79743 16 void TargetSendString(char string[]); //Sends a string to the board
daugihao 0:15536fa79743 17 void TargetSendStringAndCR(char string[]); //Sends a string to the board followed by a carriage return character
daugihao 0:15536fa79743 18 int CheckTargetPresent(void); //Starts the handshaking and then verifies the type of chip from a returned ID code
daugihao 1:0872c208795f 19 int ProgramFile(void); //Programs the UUEncoded data onto the RAM and the copies into the flash
daugihao 0:15536fa79743 20 int UUEncode(void); //Encodes the file into UU-encoded format
daugihao 0:15536fa79743 21 int Encode3(void); //Sub-function to UUEncode which encodes the 3 raw bytes into 4 UU-encoded bytes
daugihao 0:15536fa79743 22 int FirstEncode(void); //Encodes the first UUEncoded line which needs the first checksum added to it as the 8th DWORD
daugihao 0:15536fa79743 23 int EndUUEncode(void); //Function to encode the last 124 bytes of the 1024 byte blocks and output to enduuline[]
daugihao 0:15536fa79743 24 int SectorFill(int add); //Function to load the data onto the board, keeping track of position in FLASH memory
daugihao 0:15536fa79743 25 int IDCheck(int idcode); //Function that looks up the relevant information about the chip from a returned ID code
daugihao 0:15536fa79743 26
daugihao 0:15536fa79743 27 private:
daugihao 0:15536fa79743 28 FILE *f; //File pointer (binary file for writing to the chip and a temporary file with the checksum-added DWORD)
daugihao 0:15536fa79743 29 int lastSector; //Variable defnining the number of sectors which exist in Flash memory on the specific LPC17xx chip
daugihao 0:15536fa79743 30 char strChipType[80]; //Char array containing the chip type
daugihao 0:15536fa79743 31 char fname[64]; //Char array containing the file name specified in the main.cpp
daugihao 0:15536fa79743 32 char buf[1024]; //Char array containing the currently returned string from the LPC17xx board
daugihao 0:15536fa79743 33 int n1, n2, n3, n4; //UU-Encoded 4 bytes corresponding to the converted 3 raw bytes
daugihao 0:15536fa79743 34 int ch1, ch2, ch3; //3 raw bytes for conversion into the 4 bytes above --^
daugihao 0:15536fa79743 35 int sum20, checksum; //Checksum sent after a certain number of UU-Encoded lines
daugihao 0:15536fa79743 36 int lastByte; //When the end of the file to be encoded has been reached this value defines the last byte in the last line to be sent to the board
daugihao 0:15536fa79743 37 bool readAll; //Global variable determining if the file has been encoded and sent fully
daugihao 0:15536fa79743 38 char uuline[63]; //Contains the current UU-encoded line to be sent to the board next
daugihao 0:15536fa79743 39 char enduuline[51]; //Output array from EndUUEncode()
daugihao 0:15536fa79743 40 char sum[45], sum1[28]; //The char arrays assist in the conversion to big-endian for the FirstEncode() function
daugihao 0:15536fa79743 41 unsigned int id; //ID code for the attached chip
daugihao 0:15536fa79743 42 int bytesfilled; //Int to keep track of the position in the 1024 byte block (sets up triggering of switching to EndUUEncode()
daugihao 0:15536fa79743 43 int lines; //Keeps track of the number of lines sent before a checksum (checksum should be sent after every 20 UUline block where possible
daugihao 0:15536fa79743 44 bool firstencode; //True if no encoding of the file has been done
daugihao 0:15536fa79743 45 int maxsector; //Number of sectors required in order to accommodate the program, based on filesize
daugihao 0:15536fa79743 46 long int filesize; //Filesize is the...file...size (number of bytes in the file to load to the chip)
daugihao 1:0872c208795f 47 int RAM;
daugihao 0:15536fa79743 48
daugihao 0:15536fa79743 49 //Serial Buffered
daugihao 0:15536fa79743 50 void handleInterrupt();
daugihao 0:15536fa79743 51
daugihao 0:15536fa79743 52 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
daugihao 0:15536fa79743 53 uint16_t m_contentStart; //Index of first bytes of content
daugihao 0:15536fa79743 54 uint16_t m_contentEnd; //Index of bytes after last byte of content
daugihao 0:15536fa79743 55 uint16_t m_buffSize;
daugihao 0:15536fa79743 56 float m_timeout; //Can be user-defined
daugihao 0:15536fa79743 57 Timer m_timer; //Timeout timer
daugihao 0:15536fa79743 58
daugihao 0:15536fa79743 59 Serial target;
daugihao 0:15536fa79743 60 };
daugihao 0:15536fa79743 61 #endif