Chameleon-PIC Nurve Networks, Chameleon-PIC Datasheet - Page 234

MCU, MPU & DSP Development Tools PIC24 & PROPELLER DEV SYSTEM (SBC)

Chameleon-PIC

Manufacturer Part Number
Chameleon-PIC
Description
MCU, MPU & DSP Development Tools PIC24 & PROPELLER DEV SYSTEM (SBC)
Manufacturer
Nurve Networks
Datasheet

Specifications of Chameleon-PIC

Processor To Be Evaluated
PIC24
Data Bus Width
16 bit
Interface Type
USB, VGA, PS/2, I2C, ISP, SPI
Operating Supply Voltage
3.3 V, 5 V
Lead Free Status / RoHS Status
Lead free / RoHS Compliant
Each block of the transfer looks like:
Considering the block format outlined above, the downloader needs to check the checksum against the received data and
can request a packet be resent if it’s not correct. Also, if packets are late, etc. the downloader can time out, and the
downloader can simply stop the transfer if it wishes – thus, the protocol is receiver driven. Please review the web links
above to get a better handle on this protocol.
Now, the implementation we made was quick and dirty, no checksum checking, no timeouts, etc. it simply hopes that
nothing goes wrong. On the other hand, it’s very easy to add things to the function to make it more robust, we purposely
wrote it this way, so that you could understand the function and add to it if you wanted. Implementing the complete X-
Modem protocol with all error handling cases, makes the code look like spaghetti! With that in mind, here’s the function
itself that does the downloading:
int XModem_Receive( char *file_buffer, int buffer_size )
{
// receives file from an xmodem sender, standard "XMODEM" protocal as shown here:
// http://en.wikipedia.org/wiki/XMODEM
// http://www.techheap.com/communication/modems/xmodem.html
//
// function takes a pointer to the storage area of file along with the maximum size of the buffer
// if the file exceeds the buffer, the funtion WILL read the file and compute its length, but only the
// first buffer_size number of bytes will be written to the file_buffer.
// function returns the length of the file in bytes
//
// This is a "receiver" oriented protocal, so when you want to receive a file from the PC, start the
// transmission on the PC end FIRST, THEN run your xmodem download on this side. The PC will wait a min or 2
// before timing out, but this funtion will immediately start sending NAKs and expect the sender to respond
// I leave it to you to make this function more "robust", I wrote it in about an hour :)
//
// note: debug information only prints to NTSC currently
// xmodem protocal defines
// state machine
#define XSTATE_INIT
#define XSTATE_SEND_NAK
#define XSTATE_RECEIVE_PACKET
#define XSTATE_SEND_ACK
#define XSTATE_EOT
// control characters used in xmodem protocal
#define CHR_SOH
#define CHR_EOT
#define CHR_ACK
#define CHR_NAK
#define CHR_CAN
#define CHR_CTRLZ
// control debug output to NTSC screen, this is handy if you try to add more features to the function
#define DEBUG_XMODEM
everything
int xstate, xstate_running, xbytes_read = 0, ch, index;
unsigned char xchecksum, xchecksum_computed, xpacketnum, xpacketnumn;
// start off in initialization state
xstate = XSTATE_INIT;
xstate_running = 1;
// main loop
while(xstate_running)
{
// begin x-mode state machine
switch( xstate )
<soh> 01H
<eot> 04H
<ack> 06H
<nak> 15H
<can> 18H
<SOH><blk #><255-blk #><--128 data bytes--><cksum>
<SOH>
<blk #>
<255-blk #> = blk # after going thru 8080 "CMA" instr.
<cksum>
in which:
= 01 hex
= binary number, starts at 01 increments by 1, and
= the sum of the data bytes only.
wraps 0FFH to 00H (not to 01)
Formally, this is the "ones complement".
21
24
26
0
1
2
3
4
1
4
6
1
// 0 - no output at all, 1 - display file data and file size, 2 - display
Toss any carry.
© 2009 NURVE NETWORKS LLC “Exploring the Chameleon PIC 16-Bit”
234

Related parts for Chameleon-PIC