コード例 #1
0
ファイル: io.c プロジェクト: Josbaney/pinguino32
void IOsetRemap()
{
    #if defined(PIC18F26J50)

	SystemUnlock();
	PPSCONbits.IOLOCK = 0;			// Turn off PPS Write Protect
	SystemLock();

	#ifdef __SERIAL__
    RPINR16 = 4;                    // RP4 <- RX2
    RPOR3 = 5;                      // RP3 -> TX2 (func. num. 5)
    //RPINR17 = ;                     // EUSART2 Clock Input (CKR2)
	#endif

	#ifdef __SPI2__
    RPINR21 = 6;                    // RP6 (RB3) <- SDI2
    RPOR5 = 10;                     // RP5 (RB2) -> SCK2
    RPOR4 = 9;                      // RP4 (RB1) -> SDO2 (func. num. 9)
    //RPOR3 = 12;                     // RP3 (RB0) -> SS2 (SPI DMA Slave Select)
	#endif

	#ifdef __PWM__
    // TODO
    // RPINR24 = ;                     // PWM Fault Input (FLT0)
    
	#endif

	SystemUnlock();
	PPSCONbits.IOLOCK = 1;			// Turn on PPS Write Protect
	SystemLock();

    #endif /* defined(PIC18F26J50) */
}
コード例 #2
0
// PIC32 Peripheral Remappage
void IOsetRemap()
{
#if defined(PIC32_PINGUINO_220)
	SystemUnlock();
	CFGCONbits.IOLOCK=0;			// unlock configuration
	CFGCONbits.PMDLOCK=0;
	#ifdef __SERIAL__
		U2RXRbits.U2RXR=6;			// Define U2RX as RC8 ( D0 )
		RPC9Rbits.RPC9R=2;			// Define U2TX as RC9 ( D1 )
		U1RXRbits.U1RXR=2;			// Define U1RX as RA4 ( UEXT SERIAL )
		RPB4Rbits.RPB4R=1;			// Define U1TX as RB4 ( UEXT SERIAL )
	#endif
	#ifdef __SPI__
		SDI1Rbits.SDI1R=5;			// Define SDI1 as RA8 ( UEXT SPI )
		RPA9Rbits.RPA9R=3;			// Define SDO1 as RA9 ( UEXT SPI )
	#endif
	#ifdef __PWM__
		RPC2Rbits.RPC2R  =0b0101;	// PWM0 = OC3 as D2  = RC2
		RPC3Rbits.RPC3R  =0b0101;	// PWM1 = OC4 as D3  = RC3
		RPB5Rbits.RPB5R  =0b0101;	// PWM2 = OC2 as D11 = RB5
		RPB13Rbits.RPB13R=0b0110;	// PWM3 = OC5 as D12 = RB13
		RPB15Rbits.RPB15R=0b0101;	// PWM4 = OC1 as D13 = RB15
	#endif
	CFGCONbits.IOLOCK=1;			// relock configuration
	CFGCONbits.PMDLOCK=1;	
	SystemLock();
#endif

// Thanks to danirobin
#if defined(PINGUINO32MX250) || defined(PINGUINO32MX220)
	SystemUnlock();
	CFGCONbits.IOLOCK=0;			// unlock configuration
	CFGCONbits.PMDLOCK=0;
	#ifdef __SERIAL__
		U2RXRbits.U2RXR =0b0010;    // Define U2RX as RB1
		RPB0Rbits.RPB0R =0b0010;    // Define U2TX as RB0 _
		U1RXRbits.U1RXR =0b0100;	// Define U1RX as RB2 ( D10 )
		RPB3Rbits.RPB3R =0b0001;	// Define U1TX as RB3 ( D9 )
	#endif
	#ifdef __SPI__
		SDI1Rbits.SDI1R=1;			// Define SDI1 as RB5  [Overlap!]
		RPA4Rbits.RPA4R=3;			// Define SDO1 as RA4  [Overlap!]
	#endif
    #ifdef __PWM__
        RPB4Rbits.RPB4R =0b0101;    // PWM0 = OC1 = RB4
        RPA4Rbits.RPA4R =0b0110;    // PWM1 = OC4 = RA4
        RPB5Rbits.RPB5R =0b0101;    // PWM2 = OC2 = RB5
        RPB13Rbits.RPB13R=0b0101;   // PWM3 = OC5 = RB13
        RPB14Rbits.RPB14R=0b0101;   // PWM4 = OC3 = RB14
    #endif
	CFGCONbits.IOLOCK=1;			// relock configuration
	CFGCONbits.PMDLOCK=1;	
	SystemLock();
#endif
}
コード例 #3
0
/**
 * Write the clock settings into the registers; this effectively applies the
 * new settings, and will change the CPU frequency, peripheral
 * frequency, and the number of flash wait states.
 *
 * This normally requires a call to
 * SystemClocksCalcCpuClockSettings(), and
 * SystemClocksCalcPeripheralClockSettings() before.
 *
 * @see system.c::SystemConfig()
 *
 * @return Nothing
 */
void SystemClocksWriteSettings(const SystemClocksSettings *s) 
{
    SystemUnlock();

    /**
    * @page 186 
    *
    * PIC32MX Family Clock Diagram
    *
    * @page 189
    *
    * OSCCON: Oscillator Control Register
    */

    /* 
    * bit 10-8 NOSC<2:0>: New Oscillator Selection bits
    *     011 = Primary Oscillator with PLL module (XTPLL, HSPLL or ECPLL)
    */
    OSCCONbits.NOSC = POSCPLL;

    /*
    * bit 29-27 PLLODIV<2:0>: Output Divider for PLL
    */
    OSCCONbits.PLLODIV = s->PLLODIV;

    /*
    * bit 18-16 PLLMULT<2:0>: PLL Multiplier bits
    */
    OSCCONbits.PLLMULT = s->PLLMULT;

    /*
    * bit 0 OSWEN: Oscillator Switch Enable bit
    *   1 = Initiate an osc switch to selection specified by NOSC2:NOSC0 bits
    *   0 = Oscillator switch is complete
    */
    OSCCONbits.OSWEN = 1;
    // Busy wait until osc switch has been completed
    while (OSCCONbits.OSWEN == 1) 
    {
      asm("nop");
    }

    /*
    * bit 20-19 PBDIV<1:0>: Peripheral Bus Clock Divisor
    */
    OSCCONbits.PBDIV = s->PBDIV;

    // Set wait states
    #if !defined(PIC32_PINGUINO_220) && \
        !defined(PINGUINO32MX220)    && \
        !defined(PINGUINO32MX250)    && \
        !defined(PINGUINO32MX270)

    CHECON = (SystemClocksGetCpuFrequency(s) / 20) - 1;		// FlashWaitStates

    #endif
  
    //
    SystemLock();
}
コード例 #4
0
ファイル: File.cpp プロジェクト: nightstyles/focp
bool CFile::GetHostIpList(CString &oHostIpList)
{
	uint32 i;
	struct hostent *hptr;
	char cHostName[256];
	if (gethostname(cHostName, sizeof(cHostName)))
	{
		FocpLog(FOCP_LOG_ERROR, ("gethostname failure"));
		return false;
	}
	oHostIpList.Clear();
	SystemLock();
	hptr = gethostbyname(cHostName);
	if (NULL == hptr)
	{
		SystemUnLock();
		FocpLog(FOCP_LOG_ERROR, ("gethostbyname failure"));
		return false;
	}
	CStringFormatter oFormatter(&oHostIpList);
	for(i=0; hptr->h_addr_list[i]; i++)
	{
		uint8* pIp = (uint8*)(hptr->h_addr_list[i]);
		oFormatter.Print(";%u8.%u8.%u8.%u8", pIp[0], pIp[1], pIp[2], pIp[3]);
	}
	SystemUnLock();
	oHostIpList.Append(";");
	return true;
}
コード例 #5
0
ファイル: system.c プロジェクト: Carowick122221/PinguinoIDE
void SetFlashWaitStates_old()
{
	SystemUnlock();
#if defined(PIC32_PINGUINO_220)||defined(GENERIC32MX250F128)||defined(GENERIC32MX220F032)
	PMMODEbits.WAITB = 0b00;					// Data wait of 1 TPB
#else
	CHECON = (GetSystemClock() / 20) - 1;		// FlashWaitStates
#endif
	SystemLock();
}
コード例 #6
0
ファイル: rtcc.c プロジェクト: Carowick122221/PinguinoIDE
int RTCC_SetWriteDisable(void)
{
	// assume interrupts are disabled
	// assume the DMA controller is suspended
	// assume the device is locked
	SystemUnlock();
	RTCCONCLR = 0x8; // clear RTCWREN (bit 3) in RTCCON
	SystemLock();
	// re-enable interrupts
	// re-enable the DMA controller
}
コード例 #7
0
ファイル: File.cpp プロジェクト: nightstyles/focp
bool CFile::GetIpAddrList(const char* sFileName, CIpAddrList& oAddrList)
{
	char * sPort;
	oAddrList.nPort = 0;
	CFormatString oFileName;
	sPort = CString::CharOfString(sFileName, ':');
	if(sPort)
	{
		char c;
		oFileName.Assign(sPort+1);
		if(oFileName.Scan("%u16", &oAddrList.nPort) != 1)
		{
			FocpLog(FOCP_LOG_ERROR, ("Invalid Port"));
			return false;
		}
		if(!oFileName.GetChar(c))
		{
			FocpLog(FOCP_LOG_ERROR, ("Invalid Port"));
			return false;
		}
		oFileName.Assign(sFileName, sPort-sFileName);
		sFileName = oFileName.GetStr();
	}
	oAddrList.oAddrList.Clear();
	if(!sFileName[0])
		return true;
	uint32 nAddr = inet_addr(sFileName);
	if(nAddr != (uint32)(-1))
		oAddrList.oAddrList.Insert((uint32)(-1), nAddr);
	else
	{
		struct hostent *hptr;
		char sHostName[256];
		if(sFileName[0] == '*')
		{
			gethostname(sHostName, 200);
			sFileName = sHostName;
		}
		SystemLock();
		hptr = gethostbyname(sFileName);
		if (NULL == hptr)
		{
			SystemUnLock();
			FocpLog(FOCP_LOG_ERROR, ("gethostbyname failure"));
			return false;
		}
		for(uint32 i=0; hptr->h_addr_list[i]; i++)
			oAddrList.oAddrList.Insert((uint32)(-1), *(uint32*)(hptr->h_addr_list[i]));
		SystemUnLock();
	}
	return true;
}
コード例 #8
0
ファイル: rtcc.c プロジェクト: Carowick122221/PinguinoIDE
void RTCC_SOSCenable(void)
{
	SystemUnlock();
	OSCCONbits.SOSCEN = 1;
	SystemLock();
	// Wait for stable SOCSC oscillator output before enabling the RTCC.
	// This typically requires a 32 ms delay between enabling the SOSC and enabling the RTCC.
	// 1st option
	//	Delayms(50);
	// 2nd option
	// Wait for the SOSC to run
	while (RTCC_GetSOSCstatus() != RTCC_SOSC_ON);
}
コード例 #9
0
void SetFlashWaitStates_old()
{
    SystemUnlock();
    #if !defined(PIC32_PINGUINO_220) && \
        !defined(PINGUINO32MX220)    && \
        !defined(PINGUINO32MX250)    && \
        !defined(PINGUINO32MX270)
    
        CHECON = (GetSystemClock() / 20) - 1;		// FlashWaitStates
    
    #endif
    SystemLock();
}
コード例 #10
0
ファイル: File.cpp プロジェクト: nightstyles/focp
ulong CFile::GetHostId()
{
#ifdef UNIX
	return gethostid();
#else
	static uint32 nHostId;
	static bool bInit = false;
	if(bInit)
		return nHostId;
	SystemLock();
	if(!bInit)
	{
		char* out = (char*)&nHostId;
		char sMac[20];
		if(!GetMacAddress(sMac))
		{
			nHostId = 0xFFFFFFFF;
			bInit = true;
			SystemUnLock();
			return nHostId;
		}
		static uint8 sSecret[10] = {0x7E,0xA6,0xD7,0xB1,0xC3,0xF2,0xE3,0x04,0xBE,0xCA};
		char md5Output[16];
		CBinary::MemoryCopy(sMac+6, sSecret, 10);
		GetMd5((uint8*)md5Output, (uint8*)sMac, 16);
		if(CBinary::U32Code(1) != 1)
		{
			out[0] = md5Output[1] + md5Output[6] + md5Output[11];
			out[1] = md5Output[3] + md5Output[8] + md5Output[13];
			out[2] = md5Output[5] + md5Output[10] + md5Output[15];
			out[3] = md5Output[0] & 0x7F;
		}
		else
		{
			out[3] = md5Output[1] + md5Output[6] + md5Output[11];
			out[2] = md5Output[3] + md5Output[8] + md5Output[13];
			out[1] = md5Output[5] + md5Output[10] + md5Output[15];
			out[0] = md5Output[0] & 0x7F;
		}
		bInit = true;
	}
	SystemUnLock();
	return nHostId;
#endif
}
コード例 #11
0
ファイル: File.cpp プロジェクト: nightstyles/focp
void CFile::GetIpFileName(const CIpAddr& oAddr, CString &oIpFileName, bool bFriendly)
{
	if(bFriendly)
	{
		SystemLock();
		struct hostent *hptr = gethostbyaddr((const char*)&oAddr.nAddr, 4, AF_INET);
		if(hptr && hptr->h_name && hptr->h_name[0])
			oIpFileName = hptr->h_name;
		SystemUnLock();
	}
	if(oIpFileName.Empty())
	{
		uint8* pAddr = (uint8*)&oAddr.nAddr;
		CStringFormatter(&oIpFileName).Print("%u8.%u8.%u8.%u8", pAddr[0], pAddr[1], pAddr[2], pAddr[3]);
	}
	if(oAddr.nPort)
		CStringFormatter(&oIpFileName, oIpFileName.GetSize()).Print(":%u16", oAddr.nPort);
}
コード例 #12
0
ファイル: File.cpp プロジェクト: nightstyles/focp
uint32 CFile::GetIpAddr(const char* sIpAddr)
{
	uint32 nAddr = inet_addr(sIpAddr);
	if(nAddr == (uint32)(-1))
	{
		struct hostent *hptr;
		char sHostName[256];
		if(sIpAddr[0] == '*')
		{
			gethostname(sHostName, 200);
			sIpAddr = sHostName;
		}
		SystemLock();
		hptr = gethostbyname(sIpAddr);
		if (NULL == hptr)
		{
			SystemUnLock();
			return -1;
		}
		nAddr = *(uint32*)(hptr->h_addr_list[0]);
		SystemUnLock();
	}
	return nAddr;
}
コード例 #13
0
ファイル: rtcc.c プロジェクト: Carowick122221/PinguinoIDE
void RTCC_SOSCdisable(void)
{
	SystemUnlock();
	OSCCONbits.SOSCEN = 0;
	SystemLock();
}