ReturnType FlashSingleProgram(udword udAddrOff,uCPUBusType ucValue) /**************************************************************************** * INPUT(S) : * OUTPUT(S) : * DESIGN DOC. : * FUNCTION DESCRIPTION : * ****************************************************************************/ { uCPUBusType val; OS_Use(&mSemaFlashDrv); FlashWrite( 0x00555, (uCPUBusType)CMD(0x00AA) ); /* 1st cycle */ FlashWrite( 0x002AA, (uCPUBusType)CMD(0x0055) ); /* 2nd cycle */ FlashWrite( 0x00555, (uCPUBusType)CMD(0x00A0) ); /* Program command */ FlashWrite( udAddrOff,ucValue ); /* Program value */ FlashDataToggle(); val = FlashRead( udAddrOff ); if (val != ucValue) { return Flash_OperationTimeOut; } OS_Unuse(&mSemaFlashDrv); return Flash_Success; }
/*----------------------------------------------------------------------* rtp_term_puts *----------------------------------------------------------------------*/ void rtp_term_puts (const char * string) { #ifdef USE_RESOURCE_LOCKS OS_Use(&rtpResourceLock); #endif rtp_term_cputs(string); rtp_term_putc('\n'); #ifdef USE_RESOURCE_LOCKS OS_Unuse(&rtpResourceLock); #endif }
/***************************************************************************** * Function - UpdateTimeObj * DESCRIPTION: * ****************************************************************************/ void ActTime::UpdateTimeObj(MpcTime* pTimeObj) { OS_Use(&mSemaActTime); pTimeObj->SetTime(HOURS, mHours); pTimeObj->SetTime(MINUTES, mMinutes); pTimeObj->SetTime(SECONDS, mSecunds); pTimeObj->SetDate(DAY, mDay); pTimeObj->SetDate(MONTH, mMonth); pTimeObj->SetDate(YEAR, mYear); pTimeObj->SetDate(DAY_OF_WEEK, mDayOfWeek); OS_Unuse(&mSemaActTime); }
/***************************************************************************** * Function - Set * DESCRIPTION: * ****************************************************************************/ void ActTime::Set(MpcTime* tempObj) { OS_Use(&mSemaActTime); mHours = tempObj->GetTime(HOURS); mMinutes = tempObj->GetTime(MINUTES); mSecunds = tempObj->GetTime(SECONDS); mDay = tempObj->GetDate(DAY); mMonth = tempObj->GetDate(MONTH); mYear = tempObj->GetDate(YEAR); mDayOfWeek = tempObj->GetDate(DAY_OF_WEEK); LimitTime(); OS_Unuse(&mSemaActTime); CalcSecondsSince1Jan1970(); NotifyObservers(); }
void DisplayTime(void) { unsigned char string[10] ; int hour,minute,second ; hour = GetRTCHOUR() ; minute = GetRTCMIN() ; second = GetRTCSEC() ; sprintf((char *)string,"%02d-%02d-%02d", hour,minute,second ) ; OS_Use(&SemaLCD) ; Color = White ; Color_BK = Blue ; PutStringEN16(84,300,string) ; Color = WINDOW_COLOR ; Color_BK = WINDOW_BK_COLOR ; OS_Unuse(&SemaLCD) ; }
ReturnType FlashProgram( udword udAddrOff, udword udNrOfElementsInArray, void *pArray ) /**************************************************************************** * INPUT(S) : * OUTPUT(S) : * DESIGN DOC. : * FUNCTION DESCRIPTION : * ****************************************************************************/ { ReturnType rRetVal = Flash_Success; uCPUBusType *ucpArrayPointer; udword udLastOff; OS_Use(&mSemaFlashDrv); udLastOff = udAddrOff + udNrOfElementsInArray - 1; FlashWrite( 0x00555, (uCPUBusType)CMD(0x00AA) ); /* 1st cycle */ FlashWrite( 0x002AA, (uCPUBusType)CMD(0x0055) ); /* 2nd cycle */ FlashWrite( 0x00555, (uCPUBusType)CMD(0x0020) ); /* 3nd cycle */ ucpArrayPointer = (uCPUBusType *)pArray; while( udAddrOff <= udLastOff ) { FlashWrite( ANY_ADDR, CMD(0x00A0) ); /* 1st cycle */ FlashWrite( udAddrOff, *ucpArrayPointer ); /* 2nd Cycle */ if( FlashDataToggle() != Flash_Success) { FlashWrite( ANY_ADDR, (uCPUBusType)CMD(0x00F0) ); rRetVal=Flash_ProgramFailed; eiErrorInfo.udGeneralInfo[0] = udAddrOff; break; } ucpArrayPointer++; udAddrOff++; } FlashWrite( ANY_ADDR, (uCPUBusType)CMD(0x0090) ); /* 1st cycle */ FlashWrite( ANY_ADDR, (uCPUBusType)CMD(0x0000) ); /* 2st cycle */ OS_Unuse(&mSemaFlashDrv); return rRetVal; }
ReturnType FlashBlockErase(uBlockType ublBlockNr) /**************************************************************************** * INPUT(S) : * OUTPUT(S) : * DESIGN DOC. : * FUNCTION DESCRIPTION : * ****************************************************************************/ { ReturnType rRetVal = Flash_Success; /* Holds return value: optimistic initially! */ OS_Use(&mSemaFlashDrv); FlashWrite( 0x00555, (uCPUBusType)CMD(0x00AA) ); FlashWrite( 0x002AA, (uCPUBusType)CMD(0x0055) ); FlashWrite( 0x00555, (uCPUBusType)CMD(0x0080) ); FlashWrite( 0x00555, (uCPUBusType)CMD(0x00AA) ); FlashWrite( 0x002AA, (uCPUBusType)CMD(0x0055) ); FlashWrite( BlockOffset[ublBlockNr], (uCPUBusType)CMD(0x0030) ); FlashTimeOut(0); while( !(FlashRead( BlockOffset[ublBlockNr] ) & CMD(0x0008) ) ) { if (FlashTimeOut(5) == Flash_OperationTimeOut) { FlashWrite( ANY_ADDR, (uCPUBusType)CMD(0x00F0) ); /* Use single instruction cycle method */ return Flash_OperationTimeOut; } } if( FlashDataToggle() != Flash_Success ) { FlashWrite( ANY_ADDR, (uCPUBusType)CMD(0x00F0) ); /* Use single instruction cycle method */ rRetVal=Flash_BlockEraseFailed; } OS_Unuse(&mSemaFlashDrv); return rRetVal; }
/***************************************************************************** * Function - IncSec * DESCRIPTION: * Increment the time with one secund ****************************************************************************/ bool ActTime::IncSec() { bool ret_val; OS_Use(&mSemaActTime); if(IsValid()) { ret_val = true; mSecSince1970++; if(++mSecunds>59) { mSecunds=0; if(++mMinutes>59) { mMinutes=0; if(++mHours>23) { mHours=0; if(++mDay>LastDayInMonth( mMonth, mYear)) { mDay=1; if(++mMonth>12) { mMonth=1; mYear++; } } } } } } else ret_val = false; LimitTime(); OS_Unuse(&mSemaActTime); NotifyObservers(); return ret_val; }
void osAcquireMutex(OsMutex *mutex) { //Obtain ownership of the mutex object OS_Use(mutex); }
/********************************************************************* * * IP_OS_Lock * * Function description * The stack requires a single lock, typically a resource semaphore or mutex. * This function locks this object, guarding sections of the stack code * against other threads. * If the entire stack executes from a single task, no functionality is required here. */ void IP_OS_Lock(void) { OS_Use(&_Lock); }
void GUI_X_Lock(void) { OS_Use(&_RSema); }
/***************************************************************************** * Function - Run * DESCRIPTION: * *****************************************************************************/ void GeniExtHandler::Run(void) { OS_Use(&geni_class_data); IobComDrv::GetInstance()->GetAdd8Counters(&ge_add8_ok_cnt, &ge_add8_error_cnt); OS_Unuse(&geni_class_data); }
/** * Lock resource or wait for it to become free. */ void Semaphore::enter() { OS_Use(&msemaphore); }
char Proc_Display(char *NC) { CHECK_BOX Disp_Check[3] ; char key,Event,temp[1],active_digit,rx_char ; char index,down_id=0xFF,i,flicker = 0 ; union { unsigned int pos[2] ; char byte[4] ; }TPoint ; Color = Black ; Color_BK = 0xEF9F ; Clear_LCD(Color_BK) ; DrawRectFill(0,0,240,25,Blue) ; DrawRectFill(0,295,240,25,Blue) ; ShowIcon24(217,0,24,23,ICON_CLOSE) ; Color = 0xFFFF ; Color_BK = Blue ; PutStringCN16(4,4,"数码管控制") ; PutStringCN16(200,300,"退出") ; Color = Black ; Color_BK = WINDOW_BK_COLOR ; DrawFrame(3,80,232,48) ; DrawRectFill(4,81,232,46,Black) ; DrawPanel(6,160,228,72,"") ; CreateButton(1,"<",15, 175,45,20) ; CreateButton(2,">",70, 175,45,20) ; CreateButton(3,"+",125,175,45,20) ; CreateButton(4,"-",180,175,45,20) ; for(active_digit=1;active_digit<9;active_digit++) { temp[0] = Find_Data(LED[active_digit-1].data) ; if(!(LED[active_digit-1].mode&DIGIT_OFF)) Draw7Seg2436(temp[0],(active_digit-1)*29+5, 87,Red,Black ) ; if(!(LED[active_digit-1].data&SEGDP)) DrawRectFill((active_digit-1)*29+30,120, 3,3,Red) ; } for(active_digit=1;active_digit<9;active_digit++) { DrawFrame((active_digit-1)*29+14,139,11,11) ; DrawRectFill((active_digit-1)*29+15,140,10,10,Dark_Grey); } DrawRectFill(15,140,10,10,Green) ; active_digit = 1 ; CreateCheck(&Disp_Check[0],25 ,210,12,12,"闪烁") ; CreateCheck(&Disp_Check[1],90 ,210,12,12,"消隐") ; CreateCheck(&Disp_Check[2],150,210,12,12,"小数点") ; if(LED[active_digit-1].mode&DIGIT_FLICKER) CheckCheck(&Disp_Check[0]) ; if(LED[active_digit-1].mode&DIGIT_OFF) CheckCheck(&Disp_Check[1]) ; if(!(LED[active_digit-1].data&SEGDP)) CheckCheck(&Disp_Check[2]) ; temp[0] = 0x00 ; for(;;) { OS_WaitMail(&MBKeyTP) ; OS_GetMail1(&MBKeyTP, &Event) ; OS_GetMail1(&MBKeyTP, &key) ; OS_GetMail1(&MBKeyTP, &rx_char) ; OS_GetMail1(&MBKeyTP, &TPoint.byte[0]) ; OS_GetMail1(&MBKeyTP, &TPoint.byte[1]) ; OS_GetMail1(&MBKeyTP, &TPoint.byte[2]) ; OS_GetMail1(&MBKeyTP, &TPoint.byte[3]) ; if(Event&EVENT_TP_TOUCHED) { index = InScopeButton(TPoint.pos[0], TPoint.pos[1] ) ; if(index==0xFF) { OS_Use(&SemaLCD) ; SetButtonUp(down_id) ; down_id = index ; OS_Unuse(&SemaLCD) ; } else if(index!=down_id) { OS_Use(&SemaLCD) ; SetButtonUp(down_id) ; down_id = index ; SetButtonDown(down_id) ; OS_Unuse(&SemaLCD) ; } } else if(Event&EVENT_TP_PRESSED) { index = InScopeButton(TPoint.pos[0], TPoint.pos[1] ) ; OS_Use(&SemaLCD) ; SetButtonUp(index) ; down_id = 0xFF ; OS_Unuse(&SemaLCD) ; switch(index) { case 1: if(active_digit>1) { active_digit-- ; DrawRectFill((active_digit)*29+15,140,10,10,Dark_Grey); DrawRectFill((active_digit-1)*29+15,140,10,10,Green); if(LED[active_digit-1].mode&DIGIT_FLICKER) CheckCheck(&Disp_Check[0]) ; else unCheckCheck(&Disp_Check[0]) ; if(LED[active_digit-1].mode&DIGIT_OFF) CheckCheck(&Disp_Check[1]) ; else unCheckCheck(&Disp_Check[1]) ; if(!(LED[active_digit-1].data&SEGDP)) CheckCheck(&Disp_Check[2]) ; else unCheckCheck(&Disp_Check[2]) ; } break ; case 2: if(active_digit<8) { active_digit++ ; DrawRectFill((active_digit-2)*29+15,140,10,10,Dark_Grey); DrawRectFill((active_digit-1)*29+15,140,10,10,Green); if(LED[active_digit-1].mode&DIGIT_FLICKER) CheckCheck(&Disp_Check[0]) ; else unCheckCheck(&Disp_Check[0]) ; if(LED[active_digit-1].mode&DIGIT_OFF) CheckCheck(&Disp_Check[1]) ; else unCheckCheck(&Disp_Check[1]) ; if(!(LED[active_digit-1].data&SEGDP)) CheckCheck(&Disp_Check[2]) ; else unCheckCheck(&Disp_Check[2]) ; } break ; case 3: temp[0] = Find_Data(LED[active_digit-1].data); if(++temp[0]>9) temp[0] = 0 ; LED[active_digit-1].data |= 0x7F ; LED[active_digit-1].data &= SMG[temp[0]] ; Draw7Seg2436(temp[0],(active_digit-1)*29+5, 87,Red,Black ) ; break ; case 4: temp[0] = Find_Data(LED[active_digit-1].data); if(--temp[0]>250) temp[0] = 9 ; LED[active_digit-1].data |= 0x7F ; LED[active_digit-1].data &= SMG[temp[0]] ; Draw7Seg2436(temp[0],(active_digit-1)*29+5, 87,Red,Black ) ; break ; } for(i=0;i<3;i++) { if(!InCheckScope(TPoint.pos[0], TPoint.pos[1], &Disp_Check[i])) { if(Disp_Check[i].status&CHECK_CHECKED) { unCheckCheck(&Disp_Check[i]) ; switch(i) { case 0: LED_Flicker_Digit(active_digit,0) ; temp[0] = Find_Data(LED[active_digit-1].data) ; if(!(LED[active_digit-1].mode&DIGIT_OFF)) { Draw7Seg2436(temp[0],(active_digit-1)*29+5, 87,Red,Black ) ; if(!(LED[active_digit-1].data&SEGDP)) DrawRectFill((active_digit-1)*29+30,120,3,3,Red) ; } break ; case 1: temp[0] = Find_Data(LED[active_digit-1].data) ; Draw7Seg2436(temp[0],(active_digit-1)*29+5, 87,Red,Black ) ; if(!(LED[active_digit-1].data&SEGDP)) DrawRectFill((active_digit-1)*29+30,120,3,3,Red) ; LED[active_digit-1].mode &=~DIGIT_OFF ; break ; case 2: LED[active_digit-1].data |= SEGDP ; DrawRectFill((active_digit-1)*29+30,120, 3,3,Black) ; break ; } } else { CheckCheck(&Disp_Check[i]) ; switch(i) { case 0: LED_Flicker_Digit(active_digit,1) ; break ; case 1: temp[0] = Find_Data(LED[active_digit-1].data) ; Draw7Seg2436(temp[0],(active_digit-1)*29+5, 87,Black,Black ) ; DrawRectFill((active_digit-1)*29+30,120, 3,3,Black) ; LED[active_digit-1].mode |= DIGIT_OFF ; break ; case 2: LED[active_digit-1].data &=~SEGDP ; DrawRectFill((active_digit-1)*29+30,120, 3,3,Red) ; break ; } } break ; } } if( (TPoint.pos[0]<230&&TPoint.pos[0]>200&&TPoint.pos[1]>295) ||(TPoint.pos[0]>220&&TPoint.pos[1]<20 )) break ; } else if(Event&EVENT_FLICKER) { if(flicker++>0) { for(i=1;i<9;i++) { temp[0] = Find_Data(LED[i-1].data) ; if( !(LED[i-1].mode&DIGIT_OFF) && (LED[i-1].mode&DIGIT_FLICKER)) { Draw7Seg2436(temp[0],(i-1)*29+5, 87,Red,Black ) ; if(!(LED[i-1].data&SEGDP)) DrawRectFill((i-1)*29+30,120,3,3,Red) ; } } flicker = 0x00 ; } else { for(i=1;i<9;i++) { temp[0] = Find_Data(LED[i-1].data) ; if( !(LED[i-1].mode&DIGIT_OFF) && (LED[i-1].mode&DIGIT_FLICKER)) { Draw7Seg2436(temp[0],(i-1)*29+5, 87,Black,Black ) ; if(!(LED[i-1].data&SEGDP)) DrawRectFill((i-1)*29+30,120,3,3,Black) ; } } } } } DeleteButton(1) ; DeleteButton(2) ; DeleteButton(3) ; DeleteButton(4) ; return 0x00 ; }
//---------------------------------------------------------------------------// // // //函数:void Key_TP_Task(void) // //描述:键盘与触摸屏扫描,编辑控件光标闪烁 // // // //---------------------------------------------------------------------------// void Key_TP_Task(void) { unsigned char flicker_cnt = 0 ; char key = 0xFF,last_key = 0xFF, down_cnt = 0, tp_cnt = 0 ; char rx_char ; union { unsigned int pos[2] ; char byte[4] ; }TPoint ; char event ; Init_KeyPad() ; TP_Init() ; OS_CREATEMB(&MBKeyTP, 1, sizeof(MBKeyTPBuffer), &MBKeyTPBuffer ) ; // 创建键盘、触摸屏消息邮箱 OS_CREATEMB(&MBRX,1,sizeof(MBRXBuffer),&MBRXBuffer) ; // 创建端口接收邮箱 for(;;) { event = 0x00 ; if(++flicker_cnt>50) // 界面闪烁元素 { flicker_cnt = 0x00 ; event = EVENT_FLICKER ; } key = ReadKey() ; // 按键扫描 if(key!=last_key&&key!=0xFF) down_cnt = 0 ; else if(key!=last_key&&key==0xFF) { if(down_cnt>3) event |= EVENT_KEY_PRESSED ; } else if(key==last_key&&key!=0xFF) if(++down_cnt>4) down_cnt = 4 ; OS_Use(&SemaSPI) ; Init_TPSPI() ; if(!Read_TP_Twice(&TPoint.pos[0],&TPoint.pos[1])) // 触摸屏扫描 { if(tp_cnt>3) event |= EVENT_TP_PRESSED ; tp_cnt = 0 ; } else { if(++tp_cnt>8) tp_cnt = 8 ; if(tp_cnt>4) { Convert_Pos( TPoint.pos[0], TPoint.pos[1], &TPoint.pos[0],&TPoint.pos[1] ) ; event |= EVENT_TP_TOUCHED ; } } OS_Unuse(&SemaSPI) ; if(OS_GetMessageCnt(&MBRX)) { OS_GetMail(&MBRX,&rx_char) ; event |= RX_RECEIVED ; } if(event) // 发送系统消息 { if( !OS_GetSuspendCnt(&LCD_TASK_TCB) ||!OS_GetSuspendCnt(&MENU_OP_TASK_TCB)) { OS_PutMail1(&MBKeyTP, &event) ; OS_PutMail1(&MBKeyTP, &last_key) ; OS_PutMail1(&MBKeyTP, &rx_char) ; OS_PutMail1(&MBKeyTP, &TPoint.byte[0]) ; OS_PutMail1(&MBKeyTP, &TPoint.byte[1]) ; OS_PutMail1(&MBKeyTP, &TPoint.byte[2]) ; OS_PutMail1(&MBKeyTP, &TPoint.byte[3]) ; } } last_key = key ; OS_Delay(10) ; } }