Beginning support for the second UART.
[goodfet] / firmware / apps / chipcon / chipcon.c
index 1499629..ad701be 100644 (file)
@@ -1,7 +1,7 @@
 //GoodFET ChipCon Debugging Application
-//Handles basic I/O for the Chipcon 8051 debugging protocol.
+//by Travis Goodspeed
+//<travis at radiantmachines.com>
 
-//Higher level left to client application.
 
 //This is like SPI, except that you read or write, not both.
 
@@ -10,8 +10,6 @@
     only writes.
 */
 
-//This is REALLY untested.
-
 #include "platform.h"
 #include "command.h"
 #include "chipcon.h"
@@ -127,7 +125,7 @@ void cchandle(unsigned char app,
               unsigned char verb,
               unsigned char len){
   switch(verb){
-    //PEEK and POKE will come later.
+    //CC_PEEK and CC_POKE will come later.
   case READ:  //Write a command and return 1-byte reply.
     cccmd(len);
     ccread(1);
@@ -205,15 +203,15 @@ void cchandle(unsigned char app,
 
   //Macro commands
   case CC_READ_CODE_MEMORY:
-    cmddata[0]=peekcodebyte(cmddataword[0]);
+    cmddata[0]=cc_peekcodebyte(cmddataword[0]);
     txdata(app,verb,1);
     break;
   case CC_READ_XDATA_MEMORY:
-    cmddata[0]=peekdatabyte(cmddataword[0]);
+    cmddata[0]=cc_peekdatabyte(cmddataword[0]);
     txdata(app,verb,1);
     break;
   case CC_WRITE_XDATA_MEMORY:
-    cmddata[0]=pokedatabyte(cmddataword[0], cmddata[2]);
+    cmddata[0]=cc_pokedatabyte(cmddataword[0], cmddata[2]);
     txdata(app,verb,1);
     break;
   case CC_SET_PC:
@@ -281,7 +279,6 @@ unsigned short cc_get_pc(){
   return cmddataword[0];
 }
 
-
 //! Set a hardware breakpoint.
 void cc_set_hw_brkpnt(unsigned short adr){
   cmddataword[0]=adr;
@@ -331,18 +328,21 @@ unsigned char cc_debug(unsigned char len,
              unsigned char a,
              unsigned char b,
              unsigned char c){
-  unsigned char cmd=0x54+0x3;//(len&0x3);
+  unsigned char cmd=0x54+(len&0x3);//(len&0x3);
   CCWRITE;
   cctrans8(cmd);
-  /*if(len--)*/ cctrans8(a);
-  if(len--) cctrans8(b);
-  if(len--) cctrans8(c);
+  if(len--)
+    cctrans8(a);
+  if(len--)
+    cctrans8(b);
+  if(len--)
+    cctrans8(c);
   CCREAD;
   return cctrans8(0x00);
 }
 
 //! Fetch a byte of code memory.
-unsigned char peekcodebyte(unsigned long adr){
+unsigned char cc_peekcodebyte(unsigned long adr){
   /** See page 9 of SWRA124 */
   unsigned char bank=adr>>15,
     lb=adr&0xFF,
@@ -351,15 +351,15 @@ unsigned char peekcodebyte(unsigned long adr){
   adr&=0x7FFF;
   
   //MOV MEMCTR, (bank*16)+1
-  cc_debug(3, 0x75, 0xC7, 0);//(bank<<4) + 1);
+  cc_debug(3, 0x75, 0xC7, (bank<<4) + 1);
   //MOV DPTR, address
   cc_debug(3, 0x90, hb, lb);
   
   //for each byte
   //CLR A
-  cc_debug(1, 0xE4, 0, 0);
+  cc_debug(2, 0xE4, 0, 0);
   //MOVC A, @A+DPTR;
-  toret=cc_debug(1, 0x93, 0, 0);
+  toret=cc_debug(3, 0x93, 0, 0);
   //INC DPTR
   //cc_debug(1, 0xA3, 0, 0);
   
@@ -368,7 +368,7 @@ unsigned char peekcodebyte(unsigned long adr){
 
 
 //! Set a byte of data memory.
-unsigned char pokedatabyte(unsigned int adr,
+unsigned char cc_pokedatabyte(unsigned int adr,
                           unsigned char val){
   unsigned char
     hb=(adr&0xFF00)>>8,
@@ -381,7 +381,7 @@ unsigned char pokedatabyte(unsigned int adr,
   //MOVX @DPTR, A
   cc_debug(1, 0xF0, 0, 0);
   
-  return;
+  return 0;
   /*
 DEBUG_INSTR(IN: 0x90, HIBYTE(address), LOBYTE(address), OUT: Discard);
 for (n = 0; n < count; n++) {
@@ -393,7 +393,7 @@ for (n = 0; n < count; n++) {
 }
 
 //! Fetch a byte of data memory.
-unsigned char peekdatabyte(unsigned int adr){
+unsigned char cc_peekdatabyte(unsigned int adr){
   unsigned char
     hb=(adr&0xFF00)>>8,
     lb=adr&0xFF,