/// Gets Interupt Number and Processor Type /// @param[in] device CAN port /// 0 or 1 for Apalis /// always 0 for Colibri /// @param[out] gpio gpio which is used as MCP2515_INT# signal /// @param[out] procType current processor ID (see coproclib, getPROCID() ) /// @retval 0 Successful exit static BOOL GetInterruptGpio(DWORD device, DWORD *gpio, DWORD *procType) { BOOL successStatus = TRUE; PIN_INSTANCE IntGpio; *procType = getPROCID(); if(getModuleFamily()==MODULE_FAMILY_APALIS) { *gpio = TEGRA_GPIONUM('w', 2)+device; //device 0 -> GPIO W2, device 1 ->GPIO W3 } else { switch (*procType) //device is ignored { case TYPE_PXA270: case TYPE_PXA320: case TYPE_PXA300: case TYPE_TEGRA2: case TYPE_TEGRA3: GetGPIOFromPin(73, FALSE, &IntGpio); // CANINT# signal is on SODIMM pin 73 *gpio = IntGpio.inst1; break; case TYPE_PXA310: GetGPIOFromPin(133, FALSE, &IntGpio); // for PXA310, CANINT# signal is on SODIMM pin 133! *gpio = IntGpio.inst1; break; default: NKDbgPrintfW(L"CAN Demo: Unknown Processor type"); successStatus = FALSE; } } return(successStatus); }
static rsRetVal doLastMessageRepeatedNTimes(ratelimit_t *ratelimit, smsg_t *pMsg, smsg_t **ppRepMsg) { int bNeedUnlockMutex = 0; DEFiRet; if(ratelimit->bThreadSafe) { pthread_mutex_lock(&ratelimit->mut); bNeedUnlockMutex = 1; } if( ratelimit->pMsg != NULL && getMSGLen(pMsg) == getMSGLen(ratelimit->pMsg) && !ustrcmp(getMSG(pMsg), getMSG(ratelimit->pMsg)) && !strcmp(getHOSTNAME(pMsg), getHOSTNAME(ratelimit->pMsg)) && !strcmp(getPROCID(pMsg, LOCK_MUTEX), getPROCID(ratelimit->pMsg, LOCK_MUTEX)) && !strcmp(getAPPNAME(pMsg, LOCK_MUTEX), getAPPNAME(ratelimit->pMsg, LOCK_MUTEX))) { ratelimit->nsupp++; DBGPRINTF("msg repeated %d times\n", ratelimit->nsupp); /* use current message, so we have the new timestamp * (means we need to discard previous one) */ msgDestruct(&ratelimit->pMsg); ratelimit->pMsg = pMsg; ABORT_FINALIZE(RS_RET_DISCARDMSG); } else {/* new message, do "repeat processing" & save it */ if(ratelimit->pMsg != NULL) { if(ratelimit->nsupp > 0) { *ppRepMsg = ratelimitGenRepMsg(ratelimit); ratelimit->nsupp = 0; } msgDestruct(&ratelimit->pMsg); } ratelimit->pMsg = MsgAddRef(pMsg); } finalize_it: if(bNeedUnlockMutex) pthread_mutex_unlock(&ratelimit->mut); RETiRet; }
/*---------------------------------------------------------------------- | main +---------------------------------------------------------------------*/ int WINAPI WinMain(HINSTANCE hInstance, // handle to current instance HINSTANCE hPrevInstance, // handle to previous instance LPWSTR lpCmdLine, // pointer to command line int nCmdShow) // show state of window { DWORD ProcID; GPIOREG* pGPIORegs; ProcID=getPROCID(); if(pGPIORegs=MapRegister(GPIO_BASE)) { DWORD val; if(ProcID==TYPE_PXA270) pGPIORegs->gpdr1|=(1<<(35-32)); //Set GPIO35 as output else if(ProcID==TYPE_PXA320) pGPIORegs->gpdr2|=(1<<(95-64)); //Set GPIO95 as output else if(ProcID==TYPE_PXA300) pGPIORegs->gpdr3|=(1<<(97-96)); //Set GPIO97 as output if(ProcID==TYPE_PXA270) pGPIORegs->gpsr1=(1<<(35-32)); // Set GPIO35 HIGH else if(ProcID==TYPE_PXA320) pGPIORegs->gpsr2=(1<<(95-64)); // Set GPIO95 HIGH else if(ProcID==TYPE_PXA300) pGPIORegs->gpsr3=(1<<(97-96)); // Set GPIO97 HIGH if(ProcID==TYPE_PXA270) pGPIORegs->gpcr1=(1<<(35-32)); // Set GPIO35 LOW else if(ProcID==TYPE_PXA320) pGPIORegs->gpcr2=(1<<(95-64)); // Set GPIO95 LOW else if(ProcID==TYPE_PXA300) pGPIORegs->gpcr3=(1<<(97-96)); // Set GPIO97 LOW if(ProcID==TYPE_PXA270) pGPIORegs->gpdr1&=~(1<<(35-32)); // Set GPIO35 as input else if(ProcID==TYPE_PXA320) pGPIORegs->gpdr2&=~(1<<(95-64)); // Set GPIO95 as input else if(ProcID==TYPE_PXA300) pGPIORegs->gpdr3&=~(1<<(97-96)); // Set GPIO97 as input if(ProcID==TYPE_PXA270) val=pGPIORegs->gplr1&(1<<(35-32)); // Get GPIO35 level else if(ProcID==TYPE_PXA320) val=pGPIORegs->gplr2&(1<<(95-64)); // Get GPIO95 level else if(ProcID==TYPE_PXA300) val=pGPIORegs->gplr3&(1<<(97-96)); // Get GPIO97 level UnMapRegister((void*)pGPIORegs); } // This code would do the same, but using our GPIOLibrary (code available for purchase) /* { DWORD gpio; gpio=35; if(ProcID==TYPE_PXA320) gpio=95; else if(ProcID==TYPE_PXA300) gpio=97; InitGPIOLib(); SetGPIODir(gpio, 1); SetGPIOLevel(gpio,1); SetGPIOLevel(gpio,0); SetGPIODir(gpio, 1); val=GetGPIODir(gpio); DeInitGPIOLib(); } */ return(TRUE); }
//***************************************************************************** /// Main function /// @param[in] instance Handle to program instance /// @param[in] prevInstance Handle to previous program instance /// @param[in] cmdLine Command line string pointer /// @param[in] cmdShow Window state /// @retval 1 Always returned int WINAPI WinMain(HINSTANCE instance, HINSTANCE prevInstance, LPWSTR cmdLine, int cmdShow) { DWORD moduleFamily = getModuleFamily(); DWORD processorID = getPROCID(); // GPIO Initialisation switch (moduleFamily) { case MODULE_FAMILY_COLIBRI: switch (processorID) { case TYPE_PXA270: SetGPIOAltFn(16, 2, DIR_OUT); // PWM0 on GPIO16 SetGPIOAltFn(17, 2, DIR_OUT); // PWM1 on GPIO17 SetGPIOAltFn(11, 2, DIR_OUT); // PWM2 on GPIO11 SetGPIOAltFn(12, 2, DIR_OUT); // PWM3 on GPIO12 break; case TYPE_PXA320: SetGPIOAltFn(11, 1, DIR_OUT); // PWM0 on GPIO11 SetGPIOAltFn(12, 1, DIR_OUT); // PWM1 on GPIO12 SetGPIOAltFn(128, 0, DIR_IN); // Set GPIO0_2 to input (this pin is multiplexed with GPIO12) SetGPIOAltFn(13, 1, DIR_OUT); // PWM2 on GPIO13 SetGPIOAltFn(14, 1, DIR_OUT); // PWM3 on GPIO14 break; case TYPE_PXA300: SetGPIOAltFn(17, 1, DIR_OUT); // PWM0 on GPIO17 SetGPIOAltFn(18, 1, DIR_OUT); // PWM1 on GPIO18 SetGPIOAltFn(126, 0, DIR_IN); // Tristate GPIO46 which is multiplexed with GPIO20 SetGPIOAltFn(19, 1, DIR_OUT); // PWM2 on GPIO19 SetGPIOAltFn(20, 1, DIR_OUT); // PWM3 on GPIO20 SetGPIOAltFn(46, 0, DIR_IN); // Tristate GPIO46 which is multiplexed with GPIO20 break; case TYPE_TEGRA2: case TYPE_TEGRA3: freqBase = ClkLibGetClockFrequency(PWM_CLK_TEG); // PWM controller input frequency in [Hz] SetGPIOAltFn(TEGRA_GPIONUM('l', 5), -1, DIR_IN); // Set to GPIO Input because multiplexed with GPIO B4 SetGPIOAltFn(TEGRA_GPIONUM('b', 4), 0, DIR_OUT); // PWM0 on B.04 in Pin Muxing SetGPIOAltFn(TEGRA_GPIONUM('b', 5), 0, DIR_OUT); // PWM1 on B.05 in Pin Muxing SetGPIOAltFn(TEGRA_GPIONUM('a', 6), 1, DIR_OUT); // PWM2 on A.06 in Pin Muxing SetGPIOAltFn(TEGRA_GPIONUM('l', 4), -1, DIR_IN); // Set to GPIO Input because multiplexed with GPIO B7 SetGPIOAltFn(TEGRA_GPIONUM('a', 7), 1, DIR_OUT); // PWM3 on A.07 in Pin Muxing break; default: printf("This CPU is not supported"); return -1; break; } break; case MODULE_FAMILY_APALIS: switch (getPROCID()) { case TYPE_TEGRA3: SetGPIOAltFn(TEGRA_GPIONUM('u', 6), 0, DIR_OUT); // PWM1 on U.06 in Pin Muxing SetGPIOAltFn(TEGRA_GPIONUM('u', 4), 0, DIR_OUT); // PWM2 on U.04 in Pin Muxing SetGPIOAltFn(TEGRA_GPIONUM('u', 5), 0, DIR_OUT); // PWM3 on U.05 in Pin Muxing SetGPIOAltFn(TEGRA_GPIONUM('u', 3), 0, DIR_OUT); // PWM4 on U.03 in Pin Muxing break; default: printf("This CPU is not supported"); return -1; break; } break; default: printf("This CPU is not supported"); return -1; break; } // API Usage switch (moduleFamily) { case MODULE_FAMILY_COLIBRI: switch (processorID) { case TYPE_PXA270: case TYPE_PXA320: case TYPE_PXA300: InitPWM(COLIBRI_PWM1, 1, 2); // Fastest possible frequency InitPWM(COLIBRI_PWM2, 1, 100); // PWM1 is on the Colibri PXA320 and PXA300 at the same Pin as DATA17 on the Colibri PXA270! InitPWM(COLIBRI_PWM3, 16, 1024); InitPWM(COLIBRI_PWM4, 64, 1024); // Slowest possible frequency on Colibri PXA break; case TYPE_TEGRA2: case TYPE_TEGRA3: InitPWM(COLIBRI_PWM1, 1, 0); // Fastest possible frequency printf("f_PWM1 %dHz\r\n", freqBase /256 /1); InitPWM(COLIBRI_PWM2, 1, 0); printf("f_PWM2 %dHz\r\n", freqBase /256 /1); InitPWM(COLIBRI_PWM3, 1875, 0); printf("f_PWM3 %dHz\r\n", freqBase /256 /1875); InitPWM(COLIBRI_PWM4, 8192, 0); // Slowest possible frequency printf("f_PWM4 %dHz\r\n", freqBase /256 /8192); break; } SetPWMDutyPercentage(COLIBRI_PWM1, 10); // Set to 10% of period SetPWMDutyPercentage(COLIBRI_PWM2, 25); // Set to 25% of period SetPWMDutyPercentage(COLIBRI_PWM3, 50); // Set to 50% of period SetPWMDutyPercentage(COLIBRI_PWM4, 75); // Set to 75% of period break; case MODULE_FAMILY_APALIS: switch (getPROCID()) { case TYPE_TEGRA3: InitPWM(APALIS_PWM1, 1, 0); // Fastest possible frequency InitPWM(APALIS_PWM2, 1, 0); InitPWM(APALIS_PWM3, 16, 0); InitPWM(APALIS_PWM4, 8192, 0); // Slowest possible frequency break; } SetPWMDutyPercentage(APALIS_PWM1, 10); // Set to 10% of period SetPWMDutyPercentage(APALIS_PWM2, 25); // Set to 25% of period SetPWMDutyPercentage(APALIS_PWM3, 50); // Set to 50% of period SetPWMDutyPercentage(APALIS_PWM4, 75); // Set to 75% of period break; } // If higher precision is required you can use the following function, which set the duty cycle in clocks instead of a percentage // Please note that for the Colibri Tegra the maximum is fixed at 256; /* SetPWMDuty(COLIBRI_PWM1, 1); // Set to 50% of period(2) for PXAxxx SetPWMDuty(COLIBRI_PWM2, 24); // Set to 25% of period(100) for PXAxxx SetPWMDuty(COLIBRI_PWM3, 512); // Set to 50% of period(1024) for PXAxxx SetPWMDuty(COLIBRI_PWM4, 768); // Set to 75% of period(1024) for PXAxxx */ Sleep(10000); // Pause 10 seconds DeInitPWM(0); DeInitPWM(1); DeInitPWM(2); DeInitPWM(3); DeInitGPIOLib(); return(TRUE); }