/********************************************************************* * ポート内容を全部ダンプする. ********************************************************************* */ void PrintPortAll(int mask) { PortList *p = portList; #if 0 #if _AVR_PORT_ uchar data[0x20 + 0x40];//ポート読み取り値. UsbRead(0x20,AREA_RAM,data+0x20,0x40); // memdump(data+0x20,0x40,0x20);return; #else // PIC uchar data[256];//ポート読み取り値. UsbRead(0xf50,AREA_RAM,data+0x50,0x100-0x50); #endif #endif while(p->name) { if((p->attr & A_MASK) &&((p->attr & EX_PORT)==0)) { if((mask==0)||(p->attr & QQ)) { // cmdPortPrintOne(p->name,p->adrs,data[p->adrs & 0xff]); int arena=type2size(p->attr); //読み出し幅. int val = UsbPeek(p->adrs,arena); cmdPortPrintOne(p->name,p->adrs,val); } } p++; } }
/********************************************************************* * ターゲット側のメモリー内容(1バイト)を書き換える. ********************************************************************* * int adr :ターゲット側のメモリーアドレス * int arena :ターゲット側のメモリー種別(現在未使用) * int data0 :書き込みデータ. (OR) * int data1 :書き込みビットマスク.(AND) *注意 * pic32mxのbootloaderはメモリー節約のため DWORDアクセスのみ実装されている. * よって、maskは実装されない. * char,shortのアクセスを行う場合はread modifiedにする必要がある. */ int pokemem(int adr,int arena,int data0,int data1) { int buf[64/4]; char *byte=(char *)buf; int off = adr & 3; //端数. int size = 4; if(arena == MEM_BYTE) { int rc = UsbRead(adr & (-4),MEM_WORD,byte,size); byte[off]=data0; }else if(arena == MEM_HALF) { int rc = UsbRead(adr & (-4),MEM_WORD,byte,size); byte[off]=data0; // FIXME! SHORT WORD! }else{ buf[0]=data0; } return putData(adr & (-4),size,(char*) buf); #if 0 int size = 1; if(arena==MEM_HALF) size = 2; if(arena==MEM_WORD) size = 4; buf[0]=data0; printf("putData(%x %d)\n",adr,size); return putData(adr,size,(char*) buf); #endif }
/********************************************************************* * 段組表示によるポート値出力. ********************************************************************* */ void PrintPortColumn(void) { PortList *p = portList; int i,k; int m = 0; static char buf[MAXPORTS][128]; //結果バッファ(段組) // char tmp[128]; //2進数化するバッファ. #if 0 #if _AVR_PORT_ uchar data[0x20 + 0x40];//ポート読み取り値. UsbRead(0x20,AREA_RAM,data+0x20,0x40); // memdump(data+0x20,0x40,0x20);return; #else // PIC uchar data[256];//ポート読み取り値. UsbRead(0xf50,AREA_RAM,data+0x50,0x100-0x50); #endif #endif memset(buf,0,sizeof(buf)); while(p->name) { if((p->attr & A_MASK) &&((p->attr & EX_PORT)==0)) { #if _PIC_COL int arena=type2size(p->attr); //読み出し幅. int val = UsbPeek(p->adrs,arena); if(val & 0xffff0000) { sprintf(buf[m],"%14s(0x%08x) 0x%08x ",p->name,p->adrs,val); }else{ sprintf(buf[m],"%14s(0x%08x) 0x%04x ",p->name,p->adrs,val); } // sprintf(buf[m],"%16s = %s ",p->name,radix2str(tmp,val)); #else sprintf(buf[m],"%6s = %s ",p->name,radix2str(tmp,data[p->adrs & 0xff])); #endif m++; } p++; } //段組みしたい. k = (m+COLS-1)/COLS; //COLS段にした場合の行数. for(i=0;i<k;i++) { #if _PIC_COL printf("%s%s%s\n",buf[i],buf[i+k],buf[i+k*2]); #else printf("%s%s%s%s\n",buf[i],buf[i+k],buf[i+k*2],buf[i+k*3]); #endif } }
/********************************************************************* * ターゲット側メモリー1バイト読み出し ********************************************************************* * int adr :ターゲット側のメモリーアドレス * int arena :ターゲット側のメモリー種別(現在未使用) *戻り値 * メモリー内容の値. */ int UsbPeek(int adr,int arena) { unsigned char buf[256]; int size=1; int rc = UsbRead(adr,arena,buf,size); if( rc != size) { return -1; } return buf[0]; }
static int get_vector(int adr) { #ifdef LPC2388 return adr; #else int buf[16/4]; int rc = UsbRead(adr,0,(uchar*) buf,16); (void)rc; return buf[1]; // initial PC #endif }
alt_u16 UsbWaitTDListDone() { alt_u16 usb_ctl_val; usb_ctl_val = UsbRead(HPI_SIE1_MSG_ADR); // STEP 3 j UsbWrite(HPI_SIE1_MSG_ADR, 0); while (usb_ctl_val != HUSB_TDListDone) // k, read sie1 msg register { if(usb_ctl_val == 0x0000) { } else { printf("[SIE1 MSG]:SIE1 msg reg is %x\n",usb_ctl_val); } usb_ctl_val = UsbRead(HPI_SIE1_MSG_ADR); UsbWrite(HPI_SIE1_MSG_ADR, 0); } return usb_ctl_val; }
/** * * This function does a software reset of the Cypress CY7C67200 USB controller. * * @param UsbBaseAddress is the starting location of the USB internal memory * to which this bin file data is written. * * @return None * * @note None * ******************************************************************************/ void UsbSoftReset() { //XIo_Out16(USB_MAILBOX, COMM_RESET); IOWR(CY7C67200_BASE,HPI_MAILBOX,COMM_RESET); //COMM_JUMP2CODE usleep(100000); printf("[USB INIT]:reset finished!\n"); usleep(500000); printf("[USB INIT]:Clear up the interrupt\r\n"); IORD(CY7C67200_BASE,HPI_MAILBOX); IORD(CY7C67200_BASE,HPI_STATUS); // Had to add the write due to a bug in BIOS where they overwrite // the mailbox after initialization with garbage. The read clears // any pending interrupts. UsbRead (HPI_SIE1_MSG_ADR); UsbWrite (HPI_SIE1_MSG_ADR, 0); UsbRead (HPI_SIE2_MSG_ADR); UsbWrite (HPI_SIE2_MSG_ADR, 0); UsbWrite (HOST1_STAT_REG, 0xFFFF); UsbWrite (HOST2_STAT_REG, 0xFFFF); }
/********************************************************************* * ターゲット側メモリー1バイト読み出し ********************************************************************* * int adr :ターゲット側のメモリーアドレス * int arena :ターゲット側のメモリー種別(現在未使用) *戻り値 * メモリー内容の値. */ int UsbPeek(int adr,int width) { unsigned char buf[16]; int size=4; int rc = UsbRead(adr,width,buf,size); if( rc != size) { return -1; } switch(width) { default: case MEM_BYTE: return buf[0]; case MEM_HALF: return buf[0] | (buf[1]<<8); case MEM_WORD: return buf[0] | (buf[1]<<8)| (buf[2]<<16)| (buf[3]<<24); } }
/********************************************************************* * ポート内容をポーリングする. ********************************************************************* */ void cmdPoll(char *buf) { char sample[256]; int v,n,count,i; n = get_arg(buf); //引数の数. if(n != 0) { if(n < 2) { // 1個のポートを読み取る. count = 1000; }else{ count = arg_hex[1]; } v = portAddress(arg_ptr[0]); //ポート名称からアドレスを算出. if(v) { // アドレスが存在する. UsbSetPoll(v,POLL_PORT); for(i=0;i<count;i++) { int val = UsbPoll(sample); cmdPortPrintOneCr(count - i, arg_ptr[0],v,val); if(kbhit()) break; } }else{ // A,B,D全ポート読み. unsigned char portbuf[16]; #if _AVR_PORT_ int adr = 0x30; // PORTD int size = 10; // 0x30〜0x39 #else int adr = portAddress( "PORTA" ); // default PORTC int size = 10; // 0x30〜0x39 #endif for(i=0;i<count;i++) { int rc = UsbRead(adr,arena,portbuf,size); if( rc != size) { printf("poll error %d.\n",rc); return; } cmdPortPrintAllCr(count - i, portbuf); if(kbhit()) break; } } UsbSetPoll(0,0); } printf("\n\n"); }
alt_u16 UsbGetRetryCnt() { alt_u16 usb_ctl_val; IORD(CY7C67200_BASE,HPI_STATUS); if(UsbRead(HPI_SIE1_MSG_ADR) == HUSB_TDListDone) { UsbWrite(HPI_SIE1_MSG_ADR, 0); while (!(IORD(CY7C67200_BASE,HPI_STATUS) & HPI_STATUS_SIE1msg_FLAG) ) //read sie1 msg register { } } //usleep(1000); IOWR(CY7C67200_BASE,HPI_ADDR,0x0508); usb_ctl_val = IORD(CY7C67200_BASE,HPI_DATA); return usb_ctl_val; }
//----------------------------------------------------------------------------------------// // // Main function // //----------------------------------------------------------------------------------------// int main(void) { alt_u16 intStat; alt_u16 usb_ctl_val; static alt_u16 ctl_reg = 0; static alt_u16 no_device = 0; alt_u16 fs_device = 0; int keycode = 0; alt_u8 toggle = 0; alt_u8 data_size; alt_u16 code; int i; printf("USB keyboard setup...\n\n"); //----------------------------------------SIE1 initial---------------------------------------------------// USB_HOT_PLUG: UsbSoftReset(); // STEP 1a: UsbWrite (HPI_SIE1_MSG_ADR, 0); UsbWrite (HOST1_STAT_REG, 0xFFFF); /* Set HUSB_pEOT time */ UsbWrite(HUSB_pEOT, 600); // adjust the according to your USB device speed usb_ctl_val = SOFEOP1_TO_CPU_EN | RESUME1_TO_HPI_EN;// | SOFEOP1_TO_HPI_EN; UsbWrite(HPI_IRQ_ROUTING_REG, usb_ctl_val); intStat = A_CHG_IRQ_EN | SOF_EOP_IRQ_EN ; UsbWrite(HOST1_IRQ_EN_REG, intStat); // STEP 1a end // STEP 1b begin UsbWrite(COMM_R0,0x0000);//reset time UsbWrite(COMM_R1,0x0000); //port number UsbWrite(COMM_R2,0x0000); //r1 UsbWrite(COMM_R3,0x0000); //r1 UsbWrite(COMM_R4,0x0000); //r1 UsbWrite(COMM_R5,0x0000); //r1 UsbWrite(COMM_R6,0x0000); //r1 UsbWrite(COMM_R7,0x0000); //r1 UsbWrite(COMM_R8,0x0000); //r1 UsbWrite(COMM_R9,0x0000); //r1 UsbWrite(COMM_R10,0x0000); //r1 UsbWrite(COMM_R11,0x0000); //r1 UsbWrite(COMM_R12,0x0000); //r1 UsbWrite(COMM_R13,0x0000); //r1 UsbWrite(COMM_INT_NUM,HUSB_SIE1_INIT_INT); //HUSB_SIE1_INIT_INT IOWR(CY7C67200_BASE,HPI_MAILBOX,COMM_EXEC_INT); while (!(IORD(CY7C67200_BASE,HPI_STATUS) & 0xFFFF) ) //read sie1 msg register { } while (IORD(CY7C67200_BASE,HPI_MAILBOX) != COMM_ACK) { printf("[ERROR]:routine mailbox data is %x\n",IORD(CY7C67200_BASE,HPI_MAILBOX)); goto USB_HOT_PLUG; } // STEP 1b end // STEP 2 begin //usleep(30*1000); UsbWrite(COMM_INT_NUM,HUSB_RESET_INT); //husb reset UsbWrite(COMM_R0,0x003c);//reset time UsbWrite(COMM_R1,0x0000); //port number UsbWrite(COMM_R2,0x0000); //r1 UsbWrite(COMM_R3,0x0000); //r1 UsbWrite(COMM_R4,0x0000); //r1 UsbWrite(COMM_R5,0x0000); //r1 UsbWrite(COMM_R6,0x0000); //r1 UsbWrite(COMM_R7,0x0000); //r1 UsbWrite(COMM_R8,0x0000); //r1 UsbWrite(COMM_R9,0x0000); //r1 UsbWrite(COMM_R10,0x0000); //r1 UsbWrite(COMM_R11,0x0000); //r1 UsbWrite(COMM_R12,0x0000); //r1 UsbWrite(COMM_R13,0x0000); //r1 IOWR(CY7C67200_BASE,HPI_MAILBOX,COMM_EXEC_INT); while (IORD(CY7C67200_BASE,HPI_MAILBOX) != COMM_ACK) { printf("[ERROR]:routine mailbox data is %x\n",IORD(CY7C67200_BASE,HPI_MAILBOX)); goto USB_HOT_PLUG; } // STEP 2 end //usleep(30*1000); ctl_reg = USB1_CTL_REG; no_device = (A_DP_STAT | A_DM_STAT); fs_device = A_DP_STAT; usb_ctl_val = UsbRead(ctl_reg); if (!(usb_ctl_val & no_device)) { printf("\n[INFO]: no device is present in SIE1!\n"); printf("[INFO]: please insert a USB keyboard in SIE1!\n"); while (!(usb_ctl_val & no_device)) { usb_ctl_val = UsbRead(ctl_reg); if(usb_ctl_val & no_device) goto USB_HOT_PLUG; usleep(2000); } } else { /* check for low speed or full speed by reading D+ and D- lines */ if (usb_ctl_val & fs_device) { printf("[INFO]: full speed device\n"); } else { printf("[INFO]: low speed device\n"); } } //printf("[SIE1 INIT]:USB 1 Control Register reg is %x\n",UsbRead(0xC08A)); // STEP 3 begin //------------------------------------------------------set address ----------------------------------------------------------------- UsbSetAddress(); while (!(IORD(CY7C67200_BASE,HPI_STATUS) & HPI_STATUS_SIE1msg_FLAG) ) //read sie1 msg register { UsbSetAddress(); usleep(10*1000); } UsbWaitTDListDone(); IOWR(CY7C67200_BASE,HPI_ADDR,0x0506); // i printf("[ENUM PROCESS]:step 3 TD Status Byte is %x\n",IORD(CY7C67200_BASE,HPI_DATA)); IOWR(CY7C67200_BASE,HPI_ADDR,0x0508); // n usb_ctl_val = IORD(CY7C67200_BASE,HPI_DATA); printf("[ENUM PROCESS]:step 3 TD Control Byte is %x\n",usb_ctl_val); while (usb_ctl_val != 0x03) // retries occurred { usb_ctl_val = UsbGetRetryCnt(); goto USB_HOT_PLUG; } printf("------------[ENUM PROCESS]:set address done!---------------\n"); // STEP 4 begin //-------------------------------get device descriptor-1 -----------------------------------// // TASK: Call the appropriate function for this step. UsbGetDeviceDesc1(); usleep(10*1000); while (!(IORD(CY7C67200_BASE,HPI_STATUS) & HPI_STATUS_SIE1msg_FLAG) ) //read sie1 msg register { // TASK: Call the appropriate function again if it wasn't processed successfully. UsbGetDeviceDesc1(); usleep(10*1000); } UsbWaitTDListDone(); IOWR(CY7C67200_BASE,HPI_ADDR,0x0506); printf("[ENUM PROCESS]:step 4 TD Status Byte is %x\n",IORD(CY7C67200_BASE,HPI_DATA)); IOWR(CY7C67200_BASE,HPI_ADDR,0x0508); usb_ctl_val = IORD(CY7C67200_BASE,HPI_DATA); printf("[ENUM PROCESS]:step 4 TD Control Byte is %x\n",usb_ctl_val); while (usb_ctl_val != 0x03) { usb_ctl_val = UsbGetRetryCnt(); } printf("---------------[ENUM PROCESS]:get device descriptor-1 done!-----------------\n"); //--------------------------------get device descriptor-2---------------------------------------------// //get device descriptor // TASK: Call the appropriate function for this step. UsbGetDeviceDesc2(); usleep(100*1000); //if no message while (!(IORD(CY7C67200_BASE,HPI_STATUS) & HPI_STATUS_SIE1msg_FLAG) ) //read sie1 msg register { //resend the get device descriptor //get device descriptor // TASK: Call the appropriate function again if it wasn't processed successfully. UsbGetDeviceDesc2(); usleep(10*1000); } UsbWaitTDListDone(); IOWR(CY7C67200_BASE,HPI_ADDR,0x0506); printf("[ENUM PROCESS]:step 4 TD Status Byte is %x\n",IORD(CY7C67200_BASE,HPI_DATA)); IOWR(CY7C67200_BASE,HPI_ADDR,0x0508); usb_ctl_val = IORD(CY7C67200_BASE,HPI_DATA); printf("[ENUM PROCESS]:step 4 TD Control Byte is %x\n",usb_ctl_val); while (usb_ctl_val != 0x03) { usb_ctl_val = UsbGetRetryCnt(); } printf("------------[ENUM PROCESS]:get device descriptor-2 done!--------------\n"); // STEP 5 begin //-----------------------------------get configuration descriptor -1 ----------------------------------// // TASK: Call the appropriate function for this step. UsbGetConfigDesc1(); usleep(10*1000); //if no message while (!(IORD(CY7C67200_BASE,HPI_STATUS) & HPI_STATUS_SIE1msg_FLAG) ) //read sie1 msg register { //resend the get device descriptor //get device descriptor // TASK: Call the appropriate function again if it wasn't processed successfully. UsbGetConfigDesc1(); usleep(10*1000); } UsbWaitTDListDone(); IOWR(CY7C67200_BASE,HPI_ADDR,0x0506); printf("[ENUM PROCESS]:step 5 TD Status Byte is %x\n",IORD(CY7C67200_BASE,HPI_DATA)); IOWR(CY7C67200_BASE,HPI_ADDR,0x0508); usb_ctl_val = IORD(CY7C67200_BASE,HPI_DATA); printf("[ENUM PROCESS]:step 5 TD Control Byte is %x\n",usb_ctl_val); while (usb_ctl_val != 0x03) { usb_ctl_val = UsbGetRetryCnt(); } printf("------------[ENUM PROCESS]:get configuration descriptor-1 pass------------\n"); // STEP 6 begin //-----------------------------------get configuration descriptor-2------------------------------------// //get device descriptor // TASK: Call the appropriate function for this step. UsbGetConfigDesc2(); usleep(100*1000); //if no message while (!(IORD(CY7C67200_BASE,HPI_STATUS) & HPI_STATUS_SIE1msg_FLAG) ) //read sie1 msg register { // TASK: Call the appropriate function again if it wasn't processed successfully. UsbGetConfigDesc2(); usleep(10*1000); } UsbWaitTDListDone(); IOWR(CY7C67200_BASE,HPI_ADDR,0x0506); printf("[ENUM PROCESS]:step 6 TD Status Byte is %x\n",IORD(CY7C67200_BASE,HPI_DATA)); IOWR(CY7C67200_BASE,HPI_ADDR,0x0508); usb_ctl_val = IORD(CY7C67200_BASE,HPI_DATA); printf("[ENUM PROCESS]:step 6 TD Control Byte is %x\n",usb_ctl_val); while (usb_ctl_val != 0x03) { usb_ctl_val = UsbGetRetryCnt(); } printf("-----------[ENUM PROCESS]:get configuration descriptor-2 done!------------\n"); // ---------------------------------get device info---------------------------------------------// UsbPrintMem(); // TASK: Write the address to read from the memory for byte 7 of the interface descriptor to HPI_ADDR. //UsbWrite(HPI_ADDR,0x056C); IOWR(CY7C67200_BASE,HPI_ADDR,0x56c); code = IORD(CY7C67200_BASE,HPI_DATA); printf("\ncode = %x\n", code); code = code & 0x0003; if (code == 0x01) { printf("\n[INFO]:check TD rec data7 \n[INFO]:Keyboard Detected!!!\n\n"); } else { //printf("\nvalue= %x\n", code); printf("\n[INFO]:Keyboard Not Detected!!! \n\n"); } // TASK: Write the address to read from the memory for the endpoint descriptor to HPI_ADDR. //UsbWrite(HPI_DATA,0x56C); //IOWR(CY7C67200_BASE,HPI_ADDR,0x0578); //data_size = (IORD(CY7C67200_BASE,HPI_DATA)>>8)&0x00ff; data_size=8; printf("[ENUM PROCESS]:data packet size is %d\n",data_size); // STEP 7 begin //------------------------------------set configuration -----------------------------------------// // TASK: Call the appropriate function for this step. usleep(10*1000); UsbSetConfig(); while (!(IORD(CY7C67200_BASE,HPI_STATUS) & HPI_STATUS_SIE1msg_FLAG) ) //read sie1 msg register { // TASK: Call the appropriate function again if it wasn't processed successfully. usleep(10*1000); UsbSetConfig(); } UsbWaitTDListDone(); IOWR(CY7C67200_BASE,HPI_ADDR,0x0506); printf("[ENUM PROCESS]:step 7 TD Status Byte is %x\n",IORD(CY7C67200_BASE,HPI_DATA)); IOWR(CY7C67200_BASE,HPI_ADDR,0x0508); usb_ctl_val = IORD(CY7C67200_BASE,HPI_DATA); printf("[ENUM PROCESS]:step 7 TD Control Byte is %x\n",usb_ctl_val); while (usb_ctl_val != 0x03) { usb_ctl_val = UsbGetRetryCnt(); } printf("------------[ENUM PROCESS]:set configuration done!-------------------\n"); //----------------------------------------------class request out ------------------------------------------// // TASK: Call the appropriate function for this step. UsbClassRequest(); usleep(10*1000); while (!(IORD(CY7C67200_BASE,HPI_STATUS) & HPI_STATUS_SIE1msg_FLAG) ) //read sie1 msg register { // TASK: Call the appropriate function again if it wasn't processed successfully. UsbClassRequest(); usleep(10*1000); } UsbWaitTDListDone(); IOWR(CY7C67200_BASE,HPI_ADDR,0x0506); printf("[ENUM PROCESS]:step 8 TD Status Byte is %x\n",IORD(CY7C67200_BASE,HPI_DATA)); IOWR(CY7C67200_BASE,HPI_ADDR,0x0508); usb_ctl_val = IORD(CY7C67200_BASE,HPI_DATA); printf("[ENUM PROCESS]:step 8 TD Control Byte is %x\n",usb_ctl_val); while (usb_ctl_val != 0x03) { usb_ctl_val = UsbGetRetryCnt(); } printf("------------[ENUM PROCESS]:class request out done!-------------------\n"); // STEP 8 begin //----------------------------------get descriptor(class 0x21 = HID) request out --------------------------------// // TASK: Call the appropriate function for this step. UsbGetHidDesc(); usleep(10*1000); while (!(IORD(CY7C67200_BASE,HPI_STATUS) & HPI_STATUS_SIE1msg_FLAG) ) //read sie1 msg register { // TASK: Call the appropriate function again if it wasn't processed successfully. UsbGetHidDesc(); usleep(10*1000); } UsbWaitTDListDone(); IOWR(CY7C67200_BASE,HPI_ADDR,0x0506); printf("[ENUM PROCESS]:step 8 TD Status Byte is %x\n",IORD(CY7C67200_BASE,HPI_DATA)); IOWR(CY7C67200_BASE,HPI_ADDR,0x0508); usb_ctl_val = IORD(CY7C67200_BASE,HPI_DATA); printf("[ENUM PROCESS]:step 8 TD Control Byte is %x\n",usb_ctl_val); while (usb_ctl_val != 0x03) { usb_ctl_val = UsbGetRetryCnt(); } printf("------------[ENUM PROCESS]:get descriptor (class 0x21) done!-------------------\n"); // STEP 9 begin //-------------------------------get descriptor (class 0x22 = report)-------------------------------------------// // TASK: Call the appropriate function for this step. UsbGetReportDesc(); usleep(100*1000); //if no message while (!(IORD(CY7C67200_BASE,HPI_STATUS) & HPI_STATUS_SIE1msg_FLAG) ) //read sie1 msg register { // TASK: Call the appropriate function again if it wasn't processed successfully. UsbGetReportDesc(); usleep(10*1000); } UsbWaitTDListDone(); IOWR(CY7C67200_BASE,HPI_ADDR,0x0506); printf("[ENUM PROCESS]: step 9 TD Status Byte is %x\n",IORD(CY7C67200_BASE,HPI_DATA)); IOWR(CY7C67200_BASE,HPI_ADDR,0x0508); usb_ctl_val = IORD(CY7C67200_BASE,HPI_DATA); printf("[ENUM PROCESS]: step 9 TD Control Byte is %x\n",usb_ctl_val); while (usb_ctl_val != 0x03) { usb_ctl_val = UsbGetRetryCnt(); } printf("---------------[ENUM PROCESS]:get descriptor (class 0x22) done!----------------\n"); //-----------------------------------get keycode value------------------------------------------------// usleep(10000); while(1) { toggle++; IOWR(CY7C67200_BASE,HPI_ADDR,0x0500); //the start address //data phase IN-1 IOWR(CY7C67200_BASE,HPI_DATA,0x051c); //500 IOWR(CY7C67200_BASE,HPI_DATA,0x000f & data_size);//2 data length IOWR(CY7C67200_BASE,HPI_DATA,0x0291);//4 //endpoint 1 if(toggle%2) { IOWR(CY7C67200_BASE,HPI_DATA,0x0001);//6 //data 1 } else { IOWR(CY7C67200_BASE,HPI_DATA,0x0041);//6 //data 1 } IOWR(CY7C67200_BASE,HPI_DATA,0x0013);//8 IOWR(CY7C67200_BASE,HPI_DATA,0x0000);//a UsbWrite(HUSB_SIE1_pCurrentTDPtr,0x0500); //HUSB_SIE1_pCurrentTDPtr //usleep(10*1000); while (!(IORD(CY7C67200_BASE,HPI_STATUS) & HPI_STATUS_SIE1msg_FLAG) ) //read sie1 msg register { IOWR(CY7C67200_BASE,HPI_ADDR,0x0500); //the start address //data phase IN-1 IOWR(CY7C67200_BASE,HPI_DATA,0x051c); //500 IOWR(CY7C67200_BASE,HPI_DATA,0x000f & data_size);//2 data length IOWR(CY7C67200_BASE,HPI_DATA,0x0291);//4 //endpoint 1 if(toggle%2) { IOWR(CY7C67200_BASE,HPI_DATA,0x0001);//6 //data 1 } else { IOWR(CY7C67200_BASE,HPI_DATA,0x0041);//6 //data 1 } IOWR(CY7C67200_BASE,HPI_DATA,0x0013);//8 IOWR(CY7C67200_BASE,HPI_DATA,0x0000);// UsbWrite(HUSB_SIE1_pCurrentTDPtr,0x0500); //HUSB_SIE1_pCurrentTDPtr usleep(10*1000); }//end while usb_ctl_val = UsbWaitTDListDone(); // packet starts from 0x051c, reading third byte // TASK: Write the address to read from the memory for byte 3 of the report descriptor to HPI_ADDR. IOWR(CY7C67200_BASE,HPI_ADDR,0x051E); keycode = IORD(CY7C67200_BASE,HPI_DATA); printf("\nfirst two keycode values are %04x\n",keycode); IOWR(KEYCODE_BASE, 0, keycode & 0xff); usleep(5*1000); //USB hot plug routine usb_ctl_val = UsbRead(ctl_reg); usleep(5*1000); usb_ctl_val = UsbRead(ctl_reg); usleep(5*1000); usb_ctl_val = UsbRead(ctl_reg); usleep(5*1000); usb_ctl_val = UsbRead(ctl_reg); usleep(5*1000); usb_ctl_val = UsbRead(ctl_reg); usleep(5*1000); usb_ctl_val = UsbRead(ctl_reg); usleep(5*1000); if(!(usb_ctl_val & no_device)) { printf("\n[INFO]: the keyboard has been removed!!! \n"); printf("[INFO]: please insert again!!! \n"); }; usleep(5000); usb_ctl_val = UsbRead(ctl_reg); while (!(usb_ctl_val & no_device)) { usb_ctl_val = UsbRead(ctl_reg); usleep(5*1000); usb_ctl_val = UsbRead(ctl_reg); usleep(5*1000); usb_ctl_val = UsbRead(ctl_reg); usleep(5*1000); if(usb_ctl_val & no_device) goto USB_HOT_PLUG; usleep(200); } }//end while return 0; }