// CHARGER IN=true, FARR==1 --- USB CABLE // CHARGER IN=true, FARR==0 --- ADAPTER int IsWhichChargerConnected() { int nRet = 0; //[david.modify] 2008-05-23 11:53 nRet = IsChargerIn(); if(!nRet) { DPNOK(nRet); return NO_CHARGER; } if(v_pUSBCtrlAddr==NULL) { // v_pUSBCtrlAddr=(S3C2450_USBD_REG *)OALPAtoVA(S3C2450_BASE_REG_PA_USBD, FALSE); DPN(0); return ERR_CHARGER; } // PrintMsg(v_pUSBCtrlAddr, sizeof(S3C2450_USBD_REG)/sizeof(UINT32), sizeof(UINT32)); DPNOK(v_pUSBCtrlAddr->FARR); if(v_pUSBCtrlAddr->FARR&0X7F) { nRet=USB_CHARGER; //接PC USB后,v_pUSBCtrlAddr->FARR=1 DPSTR("USB CABLE!"); }else { nRet=ADAPTER_CHAGER; DPSTR("ADAPTER!"); } DPNOK(nRet); return nRet; }
INT IsChargingOrFull() { int i=0; int nState = 0; stGPIOInfo stGPIOInfo; if(NULL==v_p2450IOP){ // v_p2450IOP = (S3C2450_IOPORT_REG *)OALPAtoVA(S3C2450_BASE_REG_PA_IOPORT, FALSE); DPN(0); return -1; } // get stGPIOInfo.u32PinNo = CH_nFULL; GetGPIOInfo(&stGPIOInfo, v_p2450IOP); EPRINT(L"CH_nFULL=%d: [%d %d %d] \r\n", stGPIOInfo.u32PinNo, stGPIOInfo.u32Stat, stGPIOInfo.u32AltFunc, stGPIOInfo.u32PullUpdown); if(stGPIOInfo.u32Stat) { nState = BAT_CHARGING_STAT; DPSTR("Charging!!"); }else{ nState = BAT_FULL_STAT; DPSTR("FULL!!"); } return nState; }
INT IsChargerIn() { int i=0; int nState = 0; stGPIOInfo stGPIOInfo; if(NULL==v_p2450IOP){ // v_p2450IOP = (S3C2450_IOPORT_REG *)OALPAtoVA(S3C2450_BASE_REG_PA_IOPORT, FALSE); DPN(0); return 0; } // get EPRINT(L"==USB IO==\r\n"); stGPIOInfo.u32PinNo = USB_DET; GetGPIOInfo(&stGPIOInfo, v_p2450IOP); EPRINT(L"USB_DET=%d: [%d %d %d] \r\n", stGPIOInfo.u32PinNo, stGPIOInfo.u32Stat, stGPIOInfo.u32AltFunc, stGPIOInfo.u32PullUpdown); if(stGPIOInfo.u32Stat) { //高电平 nState = 0; }else{ nState = 1; // 低电,表示检测到有USB 或adapter } stGPIOInfo.u32PinNo = CH_nFULL; GetGPIOInfo(&stGPIOInfo, v_p2450IOP); EPRINT(L"CH_nFULL=%d: [%d %d %d] \r\n", stGPIOInfo.u32PinNo, stGPIOInfo.u32Stat, stGPIOInfo.u32AltFunc, stGPIOInfo.u32PullUpdown); stGPIOInfo.u32PinNo = CH_CON; GetGPIOInfo(&stGPIOInfo, v_p2450IOP); EPRINT(L"CH_nFULL=%d: [%d %d %d] \r\n", stGPIOInfo.u32PinNo, stGPIOInfo.u32Stat, stGPIOInfo.u32AltFunc, stGPIOInfo.u32PullUpdown); stGPIOInfo.u32PinNo = PWREN_USB; GetGPIOInfo(&stGPIOInfo, v_p2450IOP); EPRINT(L"PWREN_USB=%d: [%d %d %d] \r\n", stGPIOInfo.u32PinNo, stGPIOInfo.u32Stat, stGPIOInfo.u32AltFunc, stGPIOInfo.u32PullUpdown); DPNOK(nState); if(nState) DPSTR("CHARGER IN!"); else DPSTR("CHARGER OUT!"); return nState; }
int OEM_IOCTL_Backlight_ONOFF(int nONOff) { int nRet; HANDLE hBacklight; DPNOK(nONOff); if((hBacklight = CreateFile(L"BKL1:", GENERIC_READ|GENERIC_WRITE, FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, 0)) == INVALID_HANDLE_VALUE) { DPN(-1); return -1; }else{ DPNOK(hBacklight); if(1==nONOff){ nRet = DeviceIoControl(hBacklight , OEM_BKL_SET_ON, NULL , NULL , NULL, 0, NULL, NULL); }else{ nRet = DeviceIoControl(hBacklight , OEM_BKL_SET_OFF , NULL , NULL , NULL, 0, NULL, NULL); } CloseHandle(hBacklight); } DPNOK(hBacklight); return nRet; }
void SetNldStatus(int nLedNum , int nLedStatus)//振动func { struct NLED_SETTINGS_INFO g_LedSetInfo; HANDLE g_hNled; LPVOID g_pInBuf; //数据buffer指针 //控制LED的振动 if((g_hNled = CreateFile(L"NLD1:", GENERIC_READ|GENERIC_WRITE, FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, 0)) == INVALID_HANDLE_VALUE) { DPN(g_hNled); goto err_exit; } DPNOK(g_hNled); g_LedSetInfo.LedNum = nLedNum ;//LED编号 g_LedSetInfo.OffOnBlink = nLedStatus;// LED状态 g_pInBuf = &g_LedSetInfo; DeviceIoControl(g_hNled , IOCTL_NLED_SETDEVICE , g_pInBuf , sizeof(g_LedSetInfo) , NULL, 0, NULL, NULL); err_exit: if(g_hNled) CloseHandle(g_hNled); }
static ci_status_e const fill_pair( ucred_t const* u, bool const is_permanent, bool const force_privileged, pcred_pair_t* p) { // Only one candidate pair for permanent change; check feasibility, return if (is_permanent) { *p = get_pair_permanent(u, force_privileged); norm_pcred_pair_t const np = get_normalized_pcred_pair(p); if (!sups_are_possible(&np) || !groups_are_possible(&np)) { if (!can_set_uids_from_graph(&np)) { return ci_setuid_setgid_failed; } else { return ci_setgid_failed; } } else { if (!can_set_uids_from_graph(&np)) { return ci_setuid_failed; } else { return ci_success; } } } // Multiple candidate pairs for temporary change; need to "do our best" to // find a good one // Get candidate uids and gids id_pairs_t pairs = get_pairs_temporary(u, force_privileged); // prev and next.sups is always the same; we are looking for reachable uids // and gids p->prev = pairs.prev; p->next.sups = pairs.sups; // Try all candidate next IDs. Return once we find a reachable one. If none // are reachable, return the "most likely to succeed" IDs, based on: // missing gid privileged > missing uid privilege > missing both privileges ci_status_e status = ci_invalid; int uid_idx = -1, gid_idx = -1; unsigned i; for (i = 0; i < ID_PAIR_COLLECTION_SIZE; ++i) { unsigned j; for (j = 0; j < ID_PAIR_COLLECTION_SIZE; ++j) { p->next.uids = pairs.uids[i]; p->next.gids = pairs.gids[j]; norm_pcred_pair_t const np = get_normalized_pcred_pair(p); if (!can_set_uids_from_graph(&np)) { if (!sups_are_possible(&np) || !groups_are_possible(&np)) { // Better than nothing: if (status == ci_invalid) { uid_idx = i; gid_idx = j; status = ci_setuid_setgid_failed; } } else { // Better than failing on both setuid and setgid: if (status == ci_invalid || status == ci_setuid_setgid_failed) { uid_idx = i; gid_idx = j; status = ci_setuid_failed; } } } else if (!sups_are_possible(&np) || !groups_are_possible(&np)) { // Better than any other error condition: // We assume that getting setgid privileges is more difficult // than getting setuid privileges if (status == ci_invalid || status == ci_setuid_setgid_failed || status == ci_setuid_failed) { uid_idx = i; gid_idx = j; status = ci_setgid_failed; } } else { // Best! No failures! uid_idx = i; gid_idx = j; status = ci_success; break; } } // Break out of both loops is an error-free pair has been found if (status == ci_success) { break; } } // Sanity check assert(uid_idx >= 0 && gid_idx >= 0); // Copy best uids and gids into place p->next.uids = pairs.uids[uid_idx]; p->next.gids = pairs.gids[gid_idx]; DPN(3, "Fill pair temporary status: %d", (int)(status)); return status; }
static ci_status_e change_identity_basic(ucred_t const* uc, bool is_permanent) { // Sanity check for ids and sups if (!ids_are_sane(uc) || !sups_are_sane(&uc->sups)) { return ci_invalid_values; } // Construct state pair: <current state, target state> pcred_pair_t p; ci_status_e status = fill_pair(uc, is_permanent, false, &p); // Back out immediately if transition is impossible if (status != ci_success) { delete_pair(&p); return status; } norm_pcred_pair_t const np = get_normalized_pcred_pair(&p); // Determine when to change groups: first, last, or elevate-before-change bool const must_change_sups = sups_change_needed(&np); bool const must_change_groups = groups_change_needed(&np); bool const current_priv = suid_privilege_is_effective(&p.prev.uids); bool const target_priv = suid_privilege_is_effective(&p.next.uids); bool const no_priv = !suid_privilege_is_attainable( np.prev.normalized.uids, np.next.normalized.uids); groups_timing_e const groups_timing = (no_priv || current_priv) ? groups_first : (target_priv ? groups_last : groups_elevate); switch (groups_timing) { default: assert(false); break; case groups_first: DPN(3, "Changing identity (basic): groups_first"); break; case groups_last: DPN(3, "Changing identity (basic): groups_last"); break; case groups_elevate: DPN(3, "Changing identity (basic): groups_elevate"); break; } if (groups_timing == groups_elevate) { // The whole process is managed differently if we need to elevate // privileges to set sups before continuing to the final state change_identity_elevate_for_sups(&np); } else { if (groups_timing == groups_first) { // First change (triggered by no_priv or current_priv): if (must_change_groups) { // TODO: We do not currently have a graph of groups so there is // no guarantee that the group functions will work; however, by // doing them first when no_priv, we avoid the need for a // rollback if they fail if (set_gids_from_graph(&np) != 0) { return ci_setgid_failed; } } if (must_change_sups) { assert(set_sups(&np.next.sups) == 0); } } assert(set_uids_from_graph(&np) == 0); if (groups_timing == groups_last) { // Last change (triggered by target_priv and not no_priv or // current_priv): if (must_change_sups) { assert(set_sups(&np.next.sups) == 0); } if (must_change_groups) { assert(set_gids_from_graph(&np) == 0); } } } delete_pair(&p); return ci_success; }
INT IsChargerIn() { int i=0; int nState = 0; stGPIOInfo stGPIOInfo; if(NULL==g_pIOPort){ // v_p2450IOP = (S3C2450_IOPORT_REG *)OALPAtoVA(S3C2450_BASE_REG_PA_IOPORT, FALSE); DPN(0); return 0; } g_pIOPort->GPFCON =0x55555566; // ½«USBÉèÖóÉÖжÏGPF2 g_pIOPort->GPFDAT = 0x0; g_pIOPort->GPFUDP = 0x0; // disable pull-up/down // get EPRINT(L"==USB IO==\r\n"); stGPIOInfo.u32PinNo = USB_DET; // Sleep(1); delayLoop(1*LCD_DELAY_1MS); GetGPIOInfo(&stGPIOInfo, g_pIOPort); EPRINT(L"USB_DET=%d: [%d %d %d] \r\n", stGPIOInfo.u32PinNo, stGPIOInfo.u32Stat, stGPIOInfo.u32AltFunc, stGPIOInfo.u32PullUpdown); if(stGPIOInfo.u32Stat) { //¸ßµçƽ nState = 0; }else{ nState = 1; // µÍµç,±íʾ¼ì²âµ½ÓÐUSB »òadapter } #if 0 stGPIOInfo.u32PinNo = CH_nFULL; GetGPIOInfo(&stGPIOInfo, g_pIOPort); EPRINT(L"CH_nFULL=%d: [%d %d %d] \r\n", stGPIOInfo.u32PinNo, stGPIOInfo.u32Stat, stGPIOInfo.u32AltFunc, stGPIOInfo.u32PullUpdown); stGPIOInfo.u32PinNo = CH_CON; GetGPIOInfo(&stGPIOInfo, g_pIOPort); EPRINT(L"CH_nFULL=%d: [%d %d %d] \r\n", stGPIOInfo.u32PinNo, stGPIOInfo.u32Stat, stGPIOInfo.u32AltFunc, stGPIOInfo.u32PullUpdown); stGPIOInfo.u32PinNo = PWREN_USB; GetGPIOInfo(&stGPIOInfo, g_pIOPort); EPRINT(L"PWREN_USB=%d: [%d %d %d] \r\n", stGPIOInfo.u32PinNo, stGPIOInfo.u32Stat, stGPIOInfo.u32AltFunc, stGPIOInfo.u32PullUpdown); #endif DPNOK(nState); if(nState) DPSTR("CHARGER IN!"); else DPSTR("CHARGER OUT!"); return nState; }
int BatteryGetVol() { UINT32 u32Tmp[4]={0}; int nRet = 0; DWORD dwADCCONBak, dwADCTSCBak, dwADCADCMUXBak; if(NULL==v_pADCregs) { // v_pADCregs = (S3C2450_IOPORT_REG *)OALPAtoVA(S3C2450_BASE_REG_PA_ADC, FALSE); nRet = -1; DPN(nRet); return nRet; } // 互斥 //=============== REQUEST_ADC_MUTEX(); // Backup ADC register dwADCCONBak = v_pADCregs->ADCCON; dwADCTSCBak = v_pADCregs->ADCTSC; dwADCADCMUXBak = v_pADCregs->ADCMUX; #define AIN0_CHANNEL 0 v_pADCregs->ADCMUX = AIN0_CHANNEL; v_pADCregs->ADCCON = (1<<14) | (49<< 6); v_pADCregs->ADCTSC &= ~(1 << 2); // Normal ADC conversion v_pADCregs->ADCCON |= ( (0x0 << 3) | // 10 bit (1 << 0) | // ENABLE_START (0 )); /* Start Auto conversion */ while (v_pADCregs->ADCCON & 0x1); // check if Enable_start is low while (!(v_pADCregs->ADCCON & (1 << 15))); // Check ECFLG u32Tmp[0] = v_pADCregs->ADCDAT1; u32Tmp[1] = v_pADCregs->ADCDAT0; DPNDEC(u32Tmp[0]); DPNDEC(u32Tmp[1]); v_pADCregs->ADCCON |= (1<<2); // ADC StanbyMode // Restore ADC register v_pADCregs->ADCCON = dwADCCONBak; v_pADCregs->ADCTSC = dwADCTSCBak; v_pADCregs->ADCMUX = dwADCADCMUXBak; u32Tmp[1]=u32Tmp[1]&0X3FF; // 互斥 //=============== RELEASE_ADC_MUTEX(); //[david.modify] 2008-07-14 10:03 //理论上0--0X3FF都是测出值; //只不过值偏大或偏小可能测出就不是准确电池电压值 #if 1 nRet = u32Tmp[1]; DPNOK(nRet); return nRet; #else if( (u32Tmp[1]>=BATTERY_MIN_ADC) &&(u32Tmp[1]<=BATTERY_MAX_ADC) ) { nRet = u32Tmp[1]; DPNOK(nRet); return nRet; }else{ nRet=-2; DPNOK(nRet); return nRet; } #endif }