void Uart_SendDWORD(DWORD d, BOOL cr) { Uart_SendString("0x"); Uart_SendString(hex2char((d & 0xf0000000) >> 28)); Uart_SendString(hex2char((d & 0x0f000000) >> 24)); Uart_SendString(hex2char((d & 0x00f00000) >> 20)); Uart_SendString(hex2char((d & 0x000f0000) >> 16)); Uart_SendString(hex2char((d & 0x0000f000) >> 12)); Uart_SendString(hex2char((d & 0x00000f00) >> 8)); Uart_SendString(hex2char((d & 0x000000f0) >> 4)); Uart_SendString(hex2char((d & 0x0000000f) >> 0)); if (cr) Uart_SendString("\n"); }
void c_irq_handler(volatile unsigned int* sp) { unsigned int pendingIrq = Arm_IrqGetPending(); switch (pendingIrq) { case interrupt_source_system_timer: { // Note IRQ has no acccess to peripherals? :( Scheduler_TimerTick((thread_regs*)(sp - 1)); break; } case interrupt_source_uart: { unsigned char read = Uart_Read(); // Echo it back Uart_Send(read); if (read == 'x') { Uart_SendString("\r\n* * * Rebooting. * * *\r\n"); reboot(); } break; } default: printf("Unhandled IRQ pending, id:%d.\n", pendingIrq); break; } }
void TaskUart(void *pdata) //send message to uart from uartQ { INT8U *pUartMsg; INT8U err; pdata=pdata; Uart_Printf("taskuart\n"); while(1) { // 进程taskuart不断地用pUart_Q里读数据,当有数据时,则进行打印。 pUartMsg=OSQAccept(pUart_Q,&err);//Accept the Msg from Qene; no wait while(pUartMsg) { // Uart_Printf("get msg\n"); Uart_SendString(pUartMsg);//seng str to Uart OSMemPut(pUartMem,pUartMsg); pUartMsg=OSQAccept(pUart_Q,&err);//free Mem } OSTimeDly(OS_TICKS_PER_SEC/5); } }
// Función ya implementado: similar a printf pero enviando por puerto serie void Uart_Printf(char *fmt,...) { va_list ap; char string[256]; va_start(ap,fmt); vsprintf(string,fmt,ap); Uart_SendString(string); va_end(ap); }
void TargetInit(void) { int i; U8 key; U32 mpll_val=0; #if ADS10 __rt_lib_init(0,0); //for ADS 1.0 #endif i = 2 ; //use 400M! switch ( i ) { case 0: //200 key = 12; mpll_val = (92<<12)|(4<<4)|(1); break; case 1: //300 key = 14; mpll_val = (67<<12)|(1<<4)|(1); break; case 2: //400 key = 14; mpll_val = (92<<12)|(1<<4)|(1); break; case 3: //440!!! key = 14; mpll_val = (102<<12)|(1<<4)|(1); break; default: key = 14; mpll_val = (92<<12)|(1<<4)|(1); break; } //init FCLK=400M ChangeClockDivider(key, 12); ChangeMPllValue((mpll_val>>12)&0xff, (mpll_val>>4)&0x3f, mpll_val&3); //MMU_EnableICache(); //MMU_EnableDCache(); MMU_DisableICache(); MMU_DisableDCache(); Port_Init(); MMU_Init(); Delay(0); Uart_Init(0,115200); Uart_Select(0); Uart_SendString("Board init complete.\n"); }
void EINT_Handle() { if (INTOFFSET == 9) { Uart_SendString("watchdog\n"); if (GPFDAT &(1<<4)) GPFDAT &= ~(1<<4); // LED1点亮 else GPFDAT |= (1<<4); SRCPND |= 1<<9; INTPND |= 1<<9; SUBSRCPND |= 1<<13; } }
void Pallocator_Initialize(void) { gBytesAllocated = 0; gBitmap = (unsigned char*)(DYN_MEM_VA_START); gMemory = (unsigned char*)((DYN_MEM_VA_START)+(MAX_ALLOCATED_SLICES / 8)); // (Right after the bitmap) // Zero out the bitmap to start with unsigned int i; int* bmpPtr = (int*)gBitmap; for (i = 0; i < (MAX_ALLOCATED_SLICES / 8) / 4; i++) *bmpPtr++ = 0; Uart_SendString("Pallocator initialized\n"); }
void TargetInit(void) { int i; U8 key; U32 mpll_val=0; i = 2 ; //use 400M! switch ( i ) { case 0: //200 key = 12; mpll_val = (92<<12)|(4<<4)|(1); break; case 1: //300 key = 14; mpll_val = (67<<12)|(1<<4)|(1); break; case 2: //400 key = 14; mpll_val = (92<<12)|(1<<4)|(1); break; case 3: //440!!! key = 14; mpll_val = (102<<12)|(1<<4)|(1); break; default: key = 14; mpll_val = (92<<12)|(1<<4)|(1); break; } //init FCLK=400M, so change MPLL first ChangeMPllValue((mpll_val>>12)&0xff, (mpll_val>>4)&0x3f, mpll_val&3); ChangeClockDivider(key, 12); MMU_DisableICache(); MMU_DisableDCache(); Port_Init(); MMU_Init(); _init_alloc(0x17fe000, 0x17ff000);/*分配堆的起始地址和结束地址,4k的空间*/ Delay(0); Uart_Init(0,115200); Uart_Select(0); Uart_SendString("Board init complete.\n"); }
int main() { init_clock(); init_uart(); Uart_SendString("Hellocyj"); //rGPBCON = 0x2; // GPB0 = TOUt0 GPFCON &= ~(GPF4_MASK); //清0 GPFCON |= (GPF4_CON); //赋值 GPFDAT |= (1 << 4); initWatchdog(); while (1); return 0; }
/* void Test_Touchpanel(void) { rADCDLY=50000; //Normal conversion mode delay about (1/3.6864M)*50000=13.56ms rADCCON=(1<<14)+(ADCPRS<<6); //ADCPRS En, ADCPRS Value Uart_Printf("\nTouch Screen test\n"); rADCTSC=0xd3; //Wfait,XP_PU,XP_Dis,XM_Dis,YP_Dis,YM_En pISR_ADC = (int)AdcTsAuto; rINTMSK=~BIT_ADC; //ADC Touch Screen Mask bit clear rINTSUBMSK=~(BIT_SUB_TC); Uart_Printf("\nPress any key to quit!\n"); Uart_Printf("\nStylus Down, please...... \n"); Uart_Getch(); rINTSUBMSK|=BIT_SUB_TC; rINTMSK|=BIT_ADC; Uart_Printf("Touch Screen Test is Finished!!!\n"); } void __irq AdcTsAuto(void) { U32 saveAdcdly; if(rADCDAT0&0x8000) { //Uart_Printf("\nStylus Up!!\n"); rADCTSC&=0xff; // Set stylus down interrupt bit } //else //Uart_Printf("\nStylus Down!!\n"); rADCTSC=(1<<3)|(1<<2); //Pull-up disable, Seq. X,Y postion measure. saveAdcdly=rADCDLY; rADCDLY=40000; //Normal conversion mode delay about (1/50M)*40000=0.8ms rADCCON|=0x1; //start ADC while(rADCCON & 0x1); //check if Enable_start is low while(!(rADCCON & 0x8000)); //check if EC(End of Conversion) flag is high, This line is necessary~!! while(!(rSRCPND & (BIT_ADC))); //check if ADC is finished with interrupt bit xdata=(rADCDAT0&0x3ff); ydata=(rADCDAT1&0x3ff); //check Stylus Up Interrupt. rSUBSRCPND|=BIT_SUB_TC; ClearPending(BIT_ADC); rINTSUBMSK=~(BIT_SUB_TC); rINTMSK=~(BIT_ADC); rADCTSC =0xd3; //Waiting for interrupt rADCTSC=rADCTSC|(1<<8); // Detect stylus up interrupt signal. while(1) //to check Pen-up state { if(rSUBSRCPND & (BIT_SUB_TC)) //check if ADC is finished with interrupt bit { //Uart_Printf("Stylus Up Interrupt~!\n"); break; //if Stylus is up(1) state } } Uart_Printf("count=%03d XP=%04d, YP=%04d\n", count++, xdata, ydata); //X-position Conversion data rADCDLY=saveAdcdly; rADCTSC=rADCTSC&~(1<<8); // Detect stylus Down interrupt signal. rSUBSRCPND|=BIT_SUB_TC; rINTSUBMSK=~(BIT_SUB_TC); // Unmask sub interrupt (TC) ClearPending(BIT_ADC); } */ void Test_Touchpanel(void)//触摸屏测试 { rADCDLY=50000; //设定ADC开始延迟寄存器的值,使得延迟为:(1/3.6864M)*50000=13.56ms rADCCON=(1<<14)|(9<<6); //rADCCON[14]=1,AD转换预分频器有效,rADCCON[13:6]=9,ADC频率=PCLK/10=5M Uart_Printf("\n触摸屏测试开始,请点击触摸屏!\n"); rADCTSC=(1<<7)|(1<<6)|(0<<5)|(1<<4)|(3); //??? pISR_ADC = (int)AdcTsAuto;//中断函数注册 rINTMSK=~BIT_ADC;//使能ADC中断 rINTSUBMSK=~(BIT_SUB_TC);//使能触摸点击子中断 Uart_Getch();//等待键盘输入,有输入退出等待,测试结束 Uart_SendString("\n触摸屏测试完毕!!!\n"); rINTSUBMSK|=BIT_SUB_TC;//禁止触摸点击子中断 rINTMSK|=BIT_ADC;//禁止ADC中断 }
void TaskUart(void *pdata) //send message to uart from uartQ { char *pUartMsg; INT8U err; pdata=pdata; while(1) { pUartMsg=OSQAccept(pUart_Q,&err);//Accept the Msg from Qene; no wait while(pUartMsg) { Uart_SendString(pUartMsg);//seng str to Uart OSMemPut(pUartMem,pUartMsg); pUartMsg=OSQAccept(pUart_Q,&err);//free Mem } OSTimeDly(OS_TICKS_PER_SEC/5); } }
void main(void) { register nPage; unsigned char *pBuf; unsigned char ucDID, ucHID; unsigned char nCnt; unsigned char uNumOfLoadPage = LOAD_PAGE_SIZE; BOOL b4KPage = FALSE; // Set up copy section (initialized globals). // // NOTE: after this call, globals become valid. // // SetupCopySection(pTOC); // Enable the ICache. // MMU_EnableICache(); // Set up all GPIO ports. Port_Init(); #ifdef DEBUGUART // UART initialize Uart_Init(); //Uart_SendString("\r\n\r\nWince 5.0 1st NAND Bootloader (NBL1) for SMDK2443\r\n"); // Initialize the NAND flash interface. Uart_SendString("NAND Initialize\r\n"); #endif NAND_Init(); Read_DeviceID(0, &ucDID, &ucHID); #ifdef DEBUGUART Uart_SendString("Device ID : 0x"); Uart_SendBYTE(ucDID, 1); Uart_SendString("Hidden ID : 0x"); Uart_SendBYTE(ucHID, 1); #endif if ( (ucDID == 0xd5 && ucHID == 0x14) || (ucDID == 0xd5 && ucHID == 0x94) || (ucDID == 0xd7 && ucHID == 0x55) || (ucDID == 0xd7 && ucHID == 0xD5) // for MLC || (ucDID == 0xd3 && ucHID == 0x10)) // for SLC { b4KPage = TRUE; uNumOfLoadPage = LOAD_PAGE_SIZE/2; } // Turn the LEDs off. Led_Display(0x0); pBuf = (unsigned char *)LOAD_ADDRESS_PHYSICAL; // MLC // Page 0, 1 : Steploader // Page 2 ~ 5 : empty page // Page 6 ~ PAGES_PER_BLOCK-3 : effective page // read pages with 0, 1 and 6 to PAGES_PER_BLOCK-3 nPage = 10; for (nCnt = 0; nCnt < uNumOfLoadPage; nCnt++) { #ifdef OMNIBOOK_VER Led_Display(0x1); #else //!OMNIBOOK_VER Led_Display(0x2); #endif OMNIBOOK_VER if (nPage >= (NAND_PAGE_PER_BLOCK-2) || (NAND_Read(0, nPage, pBuf, b4KPage) == FALSE)) { #ifdef DEBUGUART // Uncorrectable ECC Error Uart_SendString("ECC Error @ Page 0x"); Uart_SendBYTE(nPage, 1); #endif #ifdef OMNIBOOK_VER Led_Display(0x0); #else //!OMNIBOOK_VER Led_Display(0x9); #endif OMNIBOOK_VER while(1); } nPage++; if (b4KPage == TRUE) pBuf += NAND_BYTE_PER_PAGE*2; else pBuf += NAND_BYTE_PER_PAGE; #ifdef OMNIBOOK_VER Led_Display(0x2); #else //!OMNIBOOK_VER Led_Display(0x4); #endif OMNIBOOK_VER } //Uart_SendString("Jump to 2nd Bootloader...\r\n"); // Uart_SendDWORD(LOAD_ADDRESS_PHYSICAL, 1); // Turn the LEDs on. // #ifdef OMNIBOOK_VER Led_Display(0x3); #else //!OMNIBOOK_VER Led_Display(0x5); #endif OMNIBOOK_VER #ifdef DEBUGUART Uart_SendString("Jump to 2nd Bootloader...\r\n"); #endif ((PFN_IMAGE_LAUNCH)(LOAD_ADDRESS_PHYSICAL))(); }
void main(void) { register nBlock; register nPage; register nBadBlocks; volatile unsigned char *pBuf; // Set up copy section (initialized globals). // // NOTE: after this call, globals become valid. // SetupCopySection(pTOC); // Enable the ICache. //System_EnableICache(); // I-Cache was already enabled in startup.s // Set up all GPIO ports for LED. //Port_Init(); //Led_Display(0xf); // UART Initialize #if UART_DEBUG Uart_Init(); Uart_SendString("\r\nWinCE 6.0 Steploader for SMDK6410\r\n"); // Initialize the NAND flash interface. Uart_SendString("NAND Initialize\n\r"); #endif g_bLargeBlock = NAND_Init(); // Copy image from NAND flash to RAM. pBuf = (unsigned char *)LOAD_ADDRESS_PHYSICAL; nBadBlocks = 0; //Led_Display(0x4); for (nPage = LOAD_IMAGE_PAGE_OFFSET; nPage < (LOAD_IMAGE_PAGE_OFFSET + LOAD_IMAGE_PAGE_COUNT) ; nPage++) { //Led_Display(0x1); nBlock = ((nPage / NAND_PAGES_PER_BLOCK) + nBadBlocks); if (!NAND_ReadPage(nBlock, (nPage % NAND_PAGES_PER_BLOCK), pBuf)) { if ((nPage % NAND_PAGES_PER_BLOCK) != 0) { //Led_Display(0x9); // real ECC Error. #if UART_DEBUG Uart_SendString("ECC Error.\r\n"); #endif while(1) { // Spin forever... } } // ECC error on a block boundary is (likely) a bad block - retry the page 0 read on the next block. nBadBlocks++; nPage--; continue; } pBuf += NAND_BYTES_PER_PAGE; } //Led_Display(0x6); #if UART_DEBUG Uart_SendString("Launch Eboot...\n\r"); #endif ((PFN_IMAGE_LAUNCH)(LOAD_ADDRESS_PHYSICAL))(); }
static int get_first_available_slice(unsigned int requestedSize) { unsigned int i, j; int clear_bits_start = -1; int clear_bits_found = 0; #ifdef DEBUG_MEM // Should use Uart_SendString here instead, but it currently doesn't take va_arg //printf("Searching for first block of %d available slices. Max allocated: %d\n", requestedSize, MAX_ALLOCATED_SLICES); #endif int foundBits = 0; for (i = 0; i < MAX_ALLOCATED_SLICES / sizeof(char); i++) { if ((gBitmap[i] & 0xFF) == 0xFF) // No free in this byte, skip { clear_bits_start = -1; clear_bits_found = 0; } else if (gBitmap[i] == 0) { if (clear_bits_start == -1) { clear_bits_start = i * (sizeof(char)* 8); // Found a new start clear_bits_found = sizeof(char)* 8; } else { clear_bits_found += sizeof(char)* 8; // Add to the pile } } else { // OK - well that sucked, just loop and see how many clear bits we can find for (j = sizeof(char)* 8 - 1; j > 0; j--) { if ((gBitmap[i] & (1 << j)) == 0) { // j contains the shifted offset from the right, set start to be the 0 based index from the left if (clear_bits_start == -1) clear_bits_start = ((i * (sizeof(char)* 8)) + (8 - j)) - 1; clear_bits_found += 1; if (clear_bits_found >= requestedSize) { foundBits = 1; break; // Found a free block } } else { clear_bits_start = -1; clear_bits_found = 0; } } } // Did we find a free block? if (clear_bits_start != -1 && (unsigned int)clear_bits_found >= requestedSize) { foundBits = 1; break; } } //assert_uart(i == MAX_ALLOCATED_SLICES, "Searched entire map, not enough slices available.\n"); assert2(clear_bits_start < 0, "Invalid slice start\n"); assert2(foundBits == 1, "Went through entire bitmap and did not find enough memory.\n"); if (clear_bits_found < requestedSize) { Uart_SendString("Couldn't locate enough slices\n"); return -1; } return clear_bits_start; }
void __irq AdcTsAuto(void) { U32 saveAdcdly; int Xpoint,Ypoint; if(rADCDAT0&0x8000)//判断光标状态ADCDAT0[15],0:按下,1提起 {//若光标提起 Uart_SendString("\n光标已经提起!!\n");//打印光标提起信息 rADCTSC&=0xff; //rADCTSC[8]=0,开始检测按下中断信号 } else //若光标按下 Uart_SendString("\n光标已经按下!!\n"); rADCTSC=(1<<3)|(1<<2);//rADCTSC[3]=0,XP上拉无效、rADCTSC[2]=1自动连续测量X,Y坐标 saveAdcdly=rADCDLY;//保存ADC开始延迟寄存器的值 rADCDLY=40000;//重新设定ADC开始延迟寄存器的值,使得延迟为:(1/50M)*40000=0.8ms rADCCON|=0x1;//开始ADC转换,之后rADCCON[0]会自动被清零 while(rADCCON & 0x1);//检测rADCCON[0]是否被清零,若是则说明已经开始转换,否则等待 while(!(rADCCON & 0x8000));//检测rADCCON[15]判断是否AD转换结束,否则继续等待直到转换结束 while(!(rSRCPND & (BIT_ADC)));//检测ADC转换结束中断是否发生,如果没有发生则继续等待,如果发生则输出ADC量化值 ydata=(rADCDAT0&0x3ff); xdata=(rADCDAT1&0x3ff); Xpoint=0.89*xdata-55; //x、y坐标由AD值转换为对应象素值 Ypoint=0.6*ydata-68; rSUBSRCPND|=BIT_SUB_TC; //手动修改子中断源登记寄存器rSUBSRCPND[9]=1,表示触摸屏按键光标中断源已经申请中断且在等待中断服务,使用软件方法使触摸屏按下中断发生 ClearPending(BIT_ADC);//将rSRCPND[31]=1,rINTPND[32]=1,使ADC中断服务子程序执行 rINTSUBMSK=~(BIT_SUB_TC);//禁止触摸屏按键提起、按下中断 rINTMSK=~(BIT_ADC);//禁止ADC转换中断 rADCTSC =0xd3; //rADCTSC[1:0]=1 1等待中断发生,rADCTSC[7:4]=1 1 0 1 rADCTSC=rADCTSC|(1<<8); // 检测光标抬起中断信号. while(1) //死循环检测光标抬起中断 { if(rSUBSRCPND & (BIT_SUB_TC)) //检测光标抬起中断 { Uart_SendString("\n光标抬起中断发生!\n"); break; } } Uart_Printf("count=%03d XP=%04d, YP=%04d\n", count++, Xpoint, Ypoint); //X-position Conversion data switch(sys_stat.interface) { case 0: { if(Xpoint>=50&&Xpoint<=200&&Ypoint>=265&&Ypoint<=415) { sys_stat.refresh = 1; buttoms.start = B_ON; }else if(Xpoint>=416&&Xpoint<=566&&Ypoint>=265&&Ypoint<=415) { sys_stat.refresh = 1; buttoms.stop = B_ON; }else if(Xpoint>=233&&Xpoint<=383&&Ypoint>=265&&Ypoint<=415) { sys_stat.refresh = 1; buttoms.set = B_ON; }else if(Xpoint>=600&&Xpoint<=750&&Ypoint>=265&&Ypoint<=415) { sys_stat.refresh = 1; buttoms.pressure = B_ON; Uart_Printf("< buttom pressure >\n"); } } break; case 1: { if(Xpoint>=695&&Xpoint<=790&&Ypoint>=370&&Ypoint<=440) //按下返回 { sys_stat.refresh = 1; buttoms.back = B_ON; // Uart_Printf("< buttom back >\n"); } } break; case 2: { if(Xpoint>=100&&Xpoint<=170&&Ypoint>=280&&Ypoint<=350) //压缩量+1000 { sys_stat.refresh = 1; buttoms.p1000 = B_ON; }else if(Xpoint>=180&&Xpoint<=250&&Ypoint>=280&&Ypoint<=350) //压缩量-1000 { sys_stat.refresh = 1; buttoms.m1000 = B_ON; }else if(Xpoint>=100&&Xpoint<=170&&Ypoint>=370&&Ypoint<=440) //压缩量+100 { sys_stat.refresh = 1; buttoms.p100 = B_ON; }else if(Xpoint>=180&&Xpoint<=250&&Ypoint>=370&&Ypoint<=440) //压缩量-100 { sys_stat.refresh = 1; buttoms.m100 = B_ON; }else if(Xpoint>=310&&Xpoint<=380&&Ypoint>=280&&Ypoint<=350) //心率+10 { sys_stat.refresh = 1; buttoms.p10 = B_ON; }else if(Xpoint>=390&&Xpoint<=460&&Ypoint>=280&&Ypoint<=350) //心率-10 { sys_stat.refresh = 1; buttoms.m10 = B_ON; }else if(Xpoint>=310&&Xpoint<=380&&Ypoint>=370&&Ypoint<=440) //心率+1 { sys_stat.refresh = 1; buttoms.p1 = B_ON; }else if(Xpoint>=390&&Xpoint<=460&&Ypoint>=370&&Ypoint<=440) //心率-1 { sys_stat.refresh = 1; buttoms.m1 = B_ON; }else if(Xpoint>=560&&Xpoint<=630&&Ypoint>=280&&Ypoint<=350) //压缩比+0.1 { sys_stat.refresh = 1; buttoms.p01 = B_ON; }else if(Xpoint>=560&&Xpoint<=630&&Ypoint>=370&&Ypoint<=440) //压缩比-0.1 { sys_stat.refresh = 1; buttoms.m01 = B_ON; }else if(Xpoint>=670&&Xpoint<=770&&Ypoint>=310&&Ypoint<=405) //确定设定 { sys_stat.refresh = 1; buttoms.back = B_ON; // Uart_Printf("< buttom back >\n"); } } break; default:break; } rADCDLY=saveAdcdly; rADCTSC=rADCTSC&~(1<<8); //开始检测光标按下中断信号 rSUBSRCPND|=BIT_SUB_TC; rINTSUBMSK=~(BIT_SUB_TC); //屏蔽触摸屏光标按下、抬起子中断 ClearPending(BIT_ADC);// }