//***************************************************************************** // //! \brief Read TC77 ID //! //! \param None //! //! This function is to get ID //! //! \return TC77 ID // //***************************************************************************** unsigned short TC77IDcodeGet(void) { unsigned short usReadVal,usWriteVal,usIDcode; // // Step 0, Set CS,Start communication // xGPIOSPinWrite(TC77_PIN_SPI_CS, 0); xGPIOSPinTypeGPIOInput(TC77_PIN_SPI_MOSI); // // Step 1, Read 16 // xSPIDataRead(TC77_PIN_SPI_PORT, &usReadVal, 1); // // Step 2, Enter Shutdown mode : Write 0XFFFF // xSPinTypeSPI(TC77_SPI_MOSI, TC77_PIN_SPI_MOSI); usWriteVal = TC77_MODE_SHUTDOWN; xSPIDataWrite(TC77_PIN_SPI_PORT, &usWriteVal, 1); // // Step 3, Read IDcode // xGPIOSPinTypeGPIOInput(TC77_PIN_SPI_MOSI); usReadVal = 0; xSPIDataRead(TC77_PIN_SPI_PORT, &usReadVal, 1); // // Step 4, Enter Continus Mode : Wirte 0x0000 // xSPinTypeSPI(TC77_SPI_MOSI, TC77_PIN_SPI_MOSI); usWriteVal = TC77_MODE_CONTINUOUS; xSPIDataWrite(TC77_PIN_SPI_PORT, &usWriteVal, 1); // // Step 5, Set CS => 1 Stop Communication // xGPIOSPinWrite(TC77_PIN_SPI_CS, 1); usIDcode = usReadVal >> 8; return usIDcode; }
//***************************************************************************** // //! \brief Init Spi communction port and wifi handshake pin. // //! WiFi shield IO refence volatge == 3.3V //! Pin map is below: //! HAND_PIN --> PA3 //! SPI1_NSS --> PA4 //! SPI1_SCK --> PA5 //! SPI1_MISO --> PA6 //! SPI1_MOSI --> PA7 //! //! \param none. //! //! \return None // //***************************************************************************** void SpiDrv_Init(void) { xSysCtlClockSet(72000000, xSYSCTL_OSC_MAIN | xSYSCTL_XTAL_8MHZ); xSysCtlPeripheralEnable(xSYSCTL_PERIPH_GPIOA); SysCtlPeripheralEnable(SYSCTL_PERIPH_SPI1); SysCtlPeripheralEnable(SYSCTL_PERIPH_AFIO); xGPIOSPinTypeGPIOInput(PA3); xGPIOSPinTypeGPIOOutput(PA4); xSPinTypeSPI(SPI1CLK(3), PA5); xSPinTypeSPI(SPI1MOSI(3), PA7); xSPinTypeSPI(SPI1MISO(1), PA6); // // Configure MCU as a master device , 8 bits data width ,MSB first,Mode_0 // xSPIConfigSet(xSPI1_BASE, 4000000, xSPI_MOTO_FORMAT_MODE_0 | xSPI_MODE_MASTER | xSPI_MSB_FIRST | xSPI_DATA_WIDTH8); xSPISSSet(xSPI1_BASE, xSPI_SS_SOFTWARE, xSPI_SS0); xSPIEnable(xSPI1_BASE); }
//***************************************************************************** // //! \brief Read the state or data from the ST7735. //! //! \param ucRS determines if the IR or DR to select. //! //! The parameter of ucDC can be: //! - ST7735_RS_COMMAND - select the IR. //! - ST7735_RS_DATA - select the DR. //! //! \return None. // //***************************************************************************** unsigned long ST7735Read(unsigned char ucRS) { unsigned long ulData = 0; // // Set D7 - D0 direction to GPIO Input // xGPIOSPinTypeGPIOInput(ST7735_PIN_D7); xGPIOSPinTypeGPIOInput(ST7735_PIN_D6); xGPIOSPinTypeGPIOInput(ST7735_PIN_D5); xGPIOSPinTypeGPIOInput(ST7735_PIN_D4); xGPIOSPinTypeGPIOInput(ST7735_PIN_D3); xGPIOSPinTypeGPIOInput(ST7735_PIN_D2); xGPIOSPinTypeGPIOInput(ST7735_PIN_D1); xGPIOSPinTypeGPIOInput(ST7735_PIN_D0); // // DC:Command, RD:Write/Read, CS:Enable // xGPIOSPinWrite(ST7735_PIN_RS, ucRS); xGPIOSPinWrite(ST7735_PIN_WR, ST7735_WR_HIGH); xGPIOSPinWrite(ST7735_PIN_CS, ST7735_CS_ENABLE); xSysCtlDelay(100); // // Read the Data // xGPIOSPinWrite(ST7735_PIN_RD, ST7735_RD_LOW); xSysCtlDelay(100); xGPIOSPinWrite(ST7735_PIN_RD, ST7735_RD_HIGH); ulData |= xGPIOSPinRead(ST7735_PIN_D7) << 7; ulData |= xGPIOSPinRead(ST7735_PIN_D6) << 6; ulData |= xGPIOSPinRead(ST7735_PIN_D5) << 5; ulData |= xGPIOSPinRead(ST7735_PIN_D4) << 4; ulData |= xGPIOSPinRead(ST7735_PIN_D3) << 3; ulData |= xGPIOSPinRead(ST7735_PIN_D2) << 2; ulData |= xGPIOSPinRead(ST7735_PIN_D1) << 1; ulData |= xGPIOSPinRead(ST7735_PIN_D0) << 0; xGPIOSPinWrite(ST7735_PIN_CS, ST7735_CS_DISABLE); // // At the End, set D7 - D0 direction to GPIO OutPut // xGPIOSPinTypeGPIOOutput(ST7735_PIN_D7); xGPIOSPinTypeGPIOOutput(ST7735_PIN_D6); xGPIOSPinTypeGPIOOutput(ST7735_PIN_D5); xGPIOSPinTypeGPIOOutput(ST7735_PIN_D4); xGPIOSPinTypeGPIOOutput(ST7735_PIN_D3); xGPIOSPinTypeGPIOOutput(ST7735_PIN_D2); xGPIOSPinTypeGPIOOutput(ST7735_PIN_D1); xGPIOSPinTypeGPIOOutput(ST7735_PIN_D0); return ulData; }
//***************************************************************************** // //! \brief ad7417arz 001 test execute main body. //! //! First set the OTI as compare output mode ,then turned to Int mode.When the //! temperature up to 30 centigrade, the OTI pin will be low level ,then clear //! the ucFlag to end of the while and set the OTI as Int mode. //! //! \return None. // //***************************************************************************** static void di_ad7417arz001Execute(void) { unsigned long ulTemp; unsigned char ucFlag = 1; int i; // // Configure the setpoint register // AD7417LowLimitSetLong(26); AD7417UpLimitSetLong(26); // // Config the OTI connected pin as input pin // xGPIOSPinTypeGPIOInput(AD7417_PIN_OTI); // // Config the OTI active level low , Fault QUEUE is 1 // OTI compare mode, temperature channel // AD7417TempConfig(AD7417_OTI_CMP | AD7417_OTI_ACTIVE_LOW | AD7417_FAULTQUE_1 | AD7417_TEMP_CHANNEL); while(ucFlag) { ulTemp = AD7417TempReadLDC(); for(i = 0; i < 10000; i++); PrintN(ulTemp); ulTemp = xGPIOSPinRead(AD7417_PIN_OTI); if(!ulTemp) { ucFlag = 0; // // Change the mode to int mode,the // AD7417TempConfig(AD7417_OTI_INT); // // Change the UpLimit TO 31 C to prevent active // AD7417UpLimitSetLong(26); } } // // Change to INT mode // AD7417TempConfig(AD7417_OTI_INT | AD7417_OTI_ACTIVE_LOW | AD7417_FAULTQUE_1 | AD7417_TEMP_CHANNEL); AD7417OTIntEnable(); AD7417OTIntCallbackInit(ReadOperation); ulTemp = AD7417TempReadLDC(); for(i = 0; i < 10000; i++); PrintN(ulTemp); TestAssertQ("a", "OTI INT mode test fail"); }
//***************************************************************************** // //! \brief Enable OTI mode corresponding pin interrupt. //! //! \param None //! //! \return None // //***************************************************************************** void ADT75IntEnable(void) { unsigned long ulBase; xGPIOSPinTypeGPIOInput(ADT75_PIN_OS); xGPIOSPinIntEnable(ADT75_PIN_OS, ADT75_LEVEL_OS); ulBase = xGPIOSPinToPort(ADT75_PIN_OS); xIntEnable(xSysCtlPeripheraIntNumGet(ulBase)); }
//***************************************************************************** // //! \brief Init GPIO of the sensor shield board. //! //! \param None. //! //! Init GPIO of the sensor shield board. //! //! \return None // //***************************************************************************** void SensorShieldIOInit(void) { #if(SENSOR_SHIELD_OUT_USED > 0) xGPIOSPinTypeGPIOOutput(SENSOR_SHIELD_O0); xGPIOSPinTypeGPIOOutput(SENSOR_SHIELD_O1); xGPIOSPinTypeGPIOOutput(SENSOR_SHIELD_O2); xGPIOSPinTypeGPIOOutput(SENSOR_SHIELD_O3); xGPIOSPinTypeGPIOOutput(SENSOR_SHIELD_O4); xGPIOSPinTypeGPIOOutput(SENSOR_SHIELD_O5); xGPIOSPinWrite(SENSOR_SHIELD_O5, 1); #endif #if(SENSOR_SHIELD_IN0_USED == SENSOR_SHIELD_IN_ANALOG) sA0PinTypeADC(); #elif (SENSOR_SHIELD_IN0_USED == SENSOR_SHIELD_IN_DIGITAL) xGPIOSPinTypeGPIOInput(SENSOR_SHIELD_A0); #endif #if(SENSOR_SHIELD_IN1_USED == SENSOR_SHIELD_IN_ANALOG) sA1PinTypeADC(); #elif (SENSOR_SHIELD_IN0_USED == SENSOR_SHIELD_IN_DIGITAL) xGPIOSPinTypeGPIOInput(SENSOR_SHIELD_A1); #endif #if(SENSOR_SHIELD_IN2_USED == SENSOR_SHIELD_IN_ANALOG) sA2PinTypeADC(); #elif (SENSOR_SHIELD_IN0_USED == SENSOR_SHIELD_IN_DIGITAL) xGPIOSPinTypeGPIOInput(SENSOR_SHIELD_A2); #endif #if(SENSOR_SHIELD_IN3_USED == SENSOR_SHIELD_IN_ANALOG) sA3PinTypeADC(); #elif (SENSOR_SHIELD_IN0_USED == SENSOR_SHIELD_IN_DIGITAL) xGPIOSPinTypeGPIOInput(SENSOR_SHIELD_A3); #endif #if(SENSOR_SHIELD_IN4_USED == SENSOR_SHIELD_IN_ANALOG) sA4PinTypeADC(); #elif (SENSOR_SHIELD_IN0_USED == SENSOR_SHIELD_IN_DIGITAL) xGPIOSPinTypeGPIOInput(SENSOR_SHIELD_A4); #endif #if(SENSOR_SHIELD_IN5_USED == SENSOR_SHIELD_IN_ANALOG) sA5PinTypeADC(); #elif (SENSOR_SHIELD_IN0_USED == SENSOR_SHIELD_IN_DIGITAL) xGPIOSPinTypeGPIOInput(SENSOR_SHIELD_A5); #endif #if(SENSOR_SHIELD_I2C_USED > 0) sPinTypeI2C(sI2C_BASE); #endif #if(SENSOR_SHIELD_UART_USED > 0) sPinTypeUART(sUART_BASE); #endif }
//***************************************************************************** // //! \brief Configure TC77 temperature convertion mode //! //! \param ulMode determines if TC77_CONTINUOUS_MODE or TC77_SHUTDOWN_MODE to select. //! //! The parameter of usMode can be: //! - TC77_MODE_CONTINUOUS - enter Continuous Temperature Conversion Mode //! - TC77_MODE_SHUTDOWN. - enter ShutDown Mode //! //! This function is to set and change TC77 temperature convertion mode,you can //! use TC77_MODE_SHUTDOWN if you want to enter low power consumption condition. //! And you can use TC77_MODE_CONTINUOUS to switch condition from shutdown mode. //! //! \return None // //***************************************************************************** void TC77Configure(unsigned short usMode) { unsigned short usRead,usWrite; // // Check the arguments. // xASSERT((usMode == TC77_MODE_CONTINUOUS) || (usMode == TC77_MODE_SHUTDOWN)); // // Step 0, Set CS,Start communication // xGPIOSPinWrite(TC77_PIN_SPI_CS, 0); xGPIOSPinTypeGPIOInput(TC77_PIN_SPI_MOSI); // // Step 1, Read temperature // xSPIDataRead(TC77_PIN_SPI_PORT, &usRead, 1); xSPinTypeSPI(TC77_SPI_MOSI, TC77_PIN_SPI_MOSI); // // Continous conversion mode // if(usMode == TC77_MODE_CONTINUOUS) { usWrite = TC77_MODE_CONTINUOUS; } // // ShutDown conversion mode // else { usWrite = TC77_MODE_SHUTDOWN; } // // Step 2, Enter corresponding mode // xSPIDataWrite(TC77_PIN_SPI_PORT, &usWrite, 1); // // Step 3, Set CS => 1 Stop Communication // xGPIOSPinWrite(TC77_PIN_SPI_CS, 1); }
//***************************************************************************** // //! \brief xgpio002 test execute main body. //! //! \return None. // //***************************************************************************** static void xgpio002Execute(void) { cIntCount = 0; // // Level trigger interrupt // xGPIOSPinTypeGPIOInput(PD7); // // Set GPIO pin interrupt callback. // xGPIOPinIntCallbackInit(ulGPIO[1], xGPIO_PIN_7, user_Callback); // // Enable GPIO pin interrupt. // xGPIOPinIntEnable(ulGPIO[1], xGPIO_PIN_7, xGPIO_FALLING_EDGE); xIntEnable(ulGPIOInt[1]); TestAssertQBreak("a", "gpio interrupt teset fail", 0xffffffff); }
//***************************************************************************** // //! \brief xgpio002 test execute main body. //! //! \return None. // //***************************************************************************** void External_Int(void) { xSysCtlClockSet(12000000, xSYSCTL_XTAL_12MHZ | xSYSCTL_OSC_MAIN); xSysCtlPeripheralEnable(xSYSCTL_PERIPH_GPIOD); // // Level trigger interrupt // xGPIOSPinTypeGPIOInput(PD7); // // Set GPIO pin interrupt callback. // xGPIOPinIntCallbackInit(ulGPIO[1], xGPIO_PIN_7, user_Callback); // // Enable GPIO pin interrupt. // xGPIOPinIntEnable(ulGPIO[1], xGPIO_PIN_7, xGPIO_FALLING_EDGE); xIntEnable(ulGPIOInt[1]); while(1); }
//***************************************************************************** // //! \brief Read TC77 temperature value from TEMP register //! //! \param None //! //! This function is to Read Temperature //! //! \return the original temperature value from TEMP register // //***************************************************************************** short TC77TemperRead(void) { short sTemperature; xGPIOSPinTypeGPIOInput(TC77_PIN_SPI_MOSI); // // Step 0, Set CS,Start communication // xGPIOSPinWrite(TC77_PIN_SPI_CS, 0); // // Step 1, Read 16(temperature value) // xSPIDataRead(TC77_PIN_SPI_PORT, &sTemperature, 1); // // Step 2, Set CS => 1 Stop Communication // xGPIOSPinWrite(TC77_PIN_SPI_CS, 1); return sTemperature; }
//***************************************************************************** // //! \brief Init the sensor shield board. //! //! \param None. //! //! Init the sensor shield board. //! //! \return None // //***************************************************************************** void SensorShieldInit(void) { #if(SENSOR_SHIELD_OUT_USED > 0) xGPIOSPinTypeGPIOOutput(SENSOR_SHIELD_O0); xGPIOSPinTypeGPIOOutput(SENSOR_SHIELD_O1); xGPIOSPinTypeGPIOOutput(SENSOR_SHIELD_O2); xGPIOSPinTypeGPIOOutput(SENSOR_SHIELD_O3); xGPIOSPinTypeGPIOOutput(SENSOR_SHIELD_O4); xGPIOSPinTypeGPIOOutput(SENSOR_SHIELD_O5); #endif #if((SENSOR_SHIELD_IN0_USED == SENSOR_SHIELD_IN_ANALOG) || \ (SENSOR_SHIELD_IN1_USED == SENSOR_SHIELD_IN_ANALOG) || \ (SENSOR_SHIELD_IN2_USED == SENSOR_SHIELD_IN_ANALOG) || \ (SENSOR_SHIELD_IN3_USED == SENSOR_SHIELD_IN_ANALOG) || \ (SENSOR_SHIELD_IN4_USED == SENSOR_SHIELD_IN_ANALOG) || \ (SENSOR_SHIELD_IN5_USED == SENSOR_SHIELD_IN_ANALOG)) xSysCtlPeripheralClockSourceSet(xSYSCTL_ADC0_HCLK, 3); // // Enable Peripheral ADC0 // xSysCtlPeripheralEnable(xSYSCTL_PERIPH_ADC0); // // Configure Some GPIO pins as ADC Mode // // // Enable the adc // xADCEnable(xADC0_BASE); // // ADC Channel0 convert once, Software tirgger. // xADCConfigure(xADC0_BASE, xADC_MODE_SCAN_CONTINUOUS, ADC_TRIGGER_PROCESSOR); // // Enable the channel0 // // // Set Compare Condition(Moisture Sensor Limited Value) // xADCCompConditionConfig(ADC_BASE, 0, xADC_COMP_INT_LOW); ADCCompDataSet(ADC_BASE, 0, 1600, 1); xADCCompEnable(ADC_BASE, 0); // // Enable the ADC end of conversion interrupt // xADCIntEnable(xADC0_BASE, xADC_INT_COMP); // // install the call back interrupt // xADCIntCallbackInit(xADC0_BASE, ADCCallback); // // Enable the NVIC ADC interrupt // xIntEnable(xINT_ADC0); xADCProcessorTrigger(xADC0_BASE); #endif #if(SENSOR_SHIELD_IN0_USED == SENSOR_SHIELD_IN_ANALOG) sA0PinTypeADC(); xADCStepConfigure(xADC0_BASE, 1, xADC_CTL_CH0); #elif (SENSOR_SHIELD_IN0_USED == SENSOR_SHIELD_IN_DIGITAL) xGPIOSPinTypeGPIOInput(SENSOR_SHIELD_A0); #endif #if(SENSOR_SHIELD_IN1_USED == SENSOR_SHIELD_IN_ANALOG) sA1PinTypeADC(); xADCStepConfigure(xADC0_BASE, 1, xADC_CTL_CH1); #elif (SENSOR_SHIELD_IN0_USED == SENSOR_SHIELD_IN_DIGITAL) xGPIOSPinTypeGPIOInput(SENSOR_SHIELD_A1); #endif #if(SENSOR_SHIELD_IN2_USED == SENSOR_SHIELD_IN_ANALOG) sA2PinTypeADC(); xADCStepConfigure(xADC0_BASE, 1, xADC_CTL_CH2); #elif (SENSOR_SHIELD_IN0_USED == SENSOR_SHIELD_IN_DIGITAL) xGPIOSPinTypeGPIOInput(SENSOR_SHIELD_A2); #endif #if(SENSOR_SHIELD_IN3_USED == SENSOR_SHIELD_IN_ANALOG) sA3PinTypeADC(); xADCStepConfigure(xADC0_BASE, 1, xADC_CTL_CH3); #elif (SENSOR_SHIELD_IN0_USED == SENSOR_SHIELD_IN_DIGITAL) xGPIOSPinTypeGPIOInput(SENSOR_SHIELD_A3); #endif #if(SENSOR_SHIELD_IN4_USED == SENSOR_SHIELD_IN_ANALOG) sA4PinTypeADC(); xADCStepConfigure(xADC0_BASE, 1, xADC_CTL_CH4); #elif (SENSOR_SHIELD_IN0_USED == SENSOR_SHIELD_IN_DIGITAL) xGPIOSPinTypeGPIOInput(SENSOR_SHIELD_A4); #endif #if(SENSOR_SHIELD_IN5_USED == SENSOR_SHIELD_IN_ANALOG) sA5PinTypeADC(); xADCStepConfigure(xADC0_BASE, 1, xADC_CTL_CH5); #elif (SENSOR_SHIELD_IN0_USED == SENSOR_SHIELD_IN_DIGITAL) xGPIOSPinTypeGPIOInput(SENSOR_SHIELD_A5); #endif #if(SENSOR_SHIELD_I2C_USED > 0) // // Enable the GPIOx port which is connected with I2C // xSysCtlPeripheralEnable(xGPIOSPinToPeripheralId(SENSOR_SHIELD_TWI_SDA)); xSysCtlPeripheralEnable(xGPIOSPinToPeripheralId(SENSOR_SHIELD_TWI_SCK)); // // Enable the I2Cx which is connected with device // xSysCtlPeripheralEnable2(sI2C_BASE); // // Set BH1750_PIN_I2C_CLK as CLK // sPinTypeI2C(sI2C_BASE); // // Configure MCU as a master device and Set Clcok Rates // xI2CMasterInit(sI2C_BASE, 100000); xI2CMasterEnable(sI2C_BASE); #endif #if(SENSOR_SHIELD_UART_USED > 0) xSysCtlPeripheralEnable2(sUART_BASE); xSysCtlPeripheralClockSourceSet(xSYSCTL_UART1_MAIN, 1); sPinTypeUART(sUART_BASE); xUARTConfigSet(sUART_BASE, 115200, (xUART_CONFIG_WLEN_8 | xUART_CONFIG_STOP_1 | xUART_CONFIG_PAR_NONE)); #endif }
//***************************************************************************** // //! \brief xgpio001 test execute main body. //! //! \return None. // //***************************************************************************** static void xgpio001Execute(void) { unsigned long ulPin, ulPort; unsigned long ulvalue, ulTemp, ulTemp1; int i, j; // // GPIO mode set and get. // for(ulPort = 0; ulPort < 5; ulPort++) { for(ulPin = 0; ulPin < 16; ulPin++) { for(i = 0; i < 5; i++) { if(ulPort != 1 && ulPort != 3) { xGPIODirModeSet(ulGPIO[ulPort], ulPackedPin[ulPin], ulPinMode[i]); ulvalue = xGPIODirModeGet(ulGPIO[ulPort], ulPackedPin[ulPin]); TestAssert((ulvalue == ulPinMode[i]), "xgpio, \" GPIODirModeSet or GPIODirModeGet()\" error"); } } } } xIntDisable(xINT_GPIOA); xIntDisable(xINT_GPIOB); xIntDisable(xINT_GPIOC); xIntDisable(xINT_GPIOD); xIntDisable(xINT_GPIOE); // // Interrupt enable. // for(ulPort = 0; ulPort < 5; ulPort++) { for(ulPin = 0; ulPin < 16; ulPin++) { for(i = 0; i < 6; i++) { xGPIOPinIntEnable(ulGPIO[ulPort], ulPackedPin[ulPin], ulIntType[i]); if(ulIntType[i] & 0x10) { ulTemp = xHWREG(ulGPIO[ulPort] + GPIO_IMD) & ulPackedPin[ulPin]; TestAssert(ulTemp == ulPackedPin[ulPin], "xgpio, \"Level INT type enable \" error"); } else { ulTemp = xHWREG(ulGPIO[ulPort] + GPIO_IMD) & ulPackedPin[ulPin]; TestAssert(ulTemp == 0, "xgpio, \"Edge INT type enable \" error"); } if(ulIntType[i] & 2) { ulTemp = xHWREG(ulGPIO[ulPort] + GPIO_IEN) & (ulPackedPin[ulPin] << 16); TestAssert(ulTemp == (ulPackedPin[ulPin] << 16), "xgpio, \"Rising or high level Int \" error"); } if(ulIntType[i] & 1) { ulTemp = xHWREG(ulGPIO[ulPort] + GPIO_IEN) & ulPackedPin[ulPin]; TestAssert(ulTemp == ulPackedPin[ulPin], "xgpio, \"Falling or low level Int \" error"); } } } } // // Interrupt disable test // for(ulPort = 0; ulPort < 5; ulPort++) { for(ulPin = 0; ulPin < 16; ulPin++) { xGPIOPinIntDisable(ulGPIO[ulPort], ulPackedPin[ulPin]); ulTemp = xHWREG(ulGPIO[ulPort] + GPIO_IEN) & (ulPackedPin[ulPin] << 16); ulTemp1 = xHWREG(ulGPIO[ulPort] + GPIO_IEN) & ulPackedPin[ulPin]; ulTemp |= ulTemp1; TestAssert(ulTemp == 0, "xgpio, \"Interrupt disable test \" error"); } } // // Pin Out/in value test // for(ulPort = 0; ulPort < 5; ulPort++) { // // Output pin value set // for(ulPin = 0; ulPin < 16; ulPin++) { xGPIODirModeSet( ulGPIO[ulPort], ulPackedPin[ulPin], GPIO_DIR_MODE_OUT ); xGPIOPinWrite(ulGPIO[ulPort], ulPackedPin[ulPin], 1); ulTemp = xHWREG(ulGPIO[ulPort] + GPIO_DOUT) & ulPackedPin[ulPin]; TestAssert(ulTemp == ulPackedPin[ulPin], "xgpio, \"Output pin value set \" error"); } } // // De-bounce enable/disable test // for(ulPort = 0; ulPort < 5; ulPort++) { // // De-bounce enable test // for(ulPin = 0; ulPin < 16; ulPin++) { GPIOPinDebounceEnable(ulGPIO[ulPort], ulPackedPin[ulPin]); ulTemp = xHWREG(ulGPIO[ulPort] + GPIO_DBEN) & ulPackedPin[ulPin]; TestAssert(ulTemp == ulPackedPin[ulPin], "xgpio, \"De-bounce enable test \" error"); } // // De-bounce disable test // for(ulPin = 0; ulPin < 16; ulPin++) { GPIOPinDebounceDisable(ulGPIO[ulPort], ulPackedPin[ulPin]); ulTemp = xHWREG(ulGPIO[ulPort] + GPIO_DBEN) & ulPackedPin[ulPin]; TestAssert(ulTemp == 0, "xgpio, \"De-bounce Disable test \" error"); } } // // Mask set/get test // for(ulPort = 0; ulPort < 5; ulPort++) { for(ulPin = 0; ulPin < 16; ulPin++) { GPIOPinMaskSet(ulGPIO[ulPort], ulPackedPin[ulPin]); ulTemp = GPIOPortMaskGet(ulGPIO[ulPort]) & ulPackedPin[ulPin]; TestAssert(ulTemp == ulPackedPin[ulPin], "xgpio, \" Mask set/get test \" error"); } } // // De-bounce time set and get test // for(i = 0; i < 2; i++) { for(j = 0; j < 3; j++) { GPIODebounceTimeSet(ulDelay[i], ulDelayCycle[j]); ulTemp = xHWREG(GPIO_DBNCECON) & 0x10; if(i == 0) { TestAssert(ulTemp == 0, "xgpio, \" De-bounce source set \" error"); } else { TestAssert(ulTemp == 0x10, "xgpio, \" De-bounce source set \" error"); } ulTemp1 = GPIODebounceTimeGet(); TestAssert(ulTemp1 == ulDelayCycle[j], "xgpio, \" De-bounce cycle test \" error"); } } // // Pin to peripheral ID test // ulTemp = xGPIOSPinToPeripheralId(PA0); TestAssert(ulTemp == ulPeripheralID[0], "xgpio, \" Pin to peripheral ID test \" error"); // // Short pin to pin test // ulTemp = xGPIOSPinToPin(PA0); TestAssert(ulTemp == ulPinValue[0], "xgpio, \" Short pin to pin test \" error"); ulTemp = xGPIOSPinToPin(PB8); TestAssert(ulTemp == ulPinValue[1], "xgpio, \" Short pin to pin test \" error"); ulTemp = xGPIOSPinToPin(PE15); TestAssert(ulTemp == ulPinValue[2], "xgpio, \" Short pin to pin test \" error"); // // Short pin dir mode set test // for(i = 0; i < 5; i++) { xGPIOSPinDirModeSet(PA0, ulPinMode[i]); ulTemp = xGPIODirModeGet(xGPIO_PORTA_BASE, GPIO_PIN_0); TestAssert(ulTemp == ulPinMode[i], "xgpio, \" Short pin dir mode set test \" error"); } // // Short pin interrupt enable // for(i = 0; i < 6; i++) { xGPIOSPinIntEnable(PA0, ulIntType[i]); if(ulIntType[i] & 0x10) { ulTemp = xHWREG(xGPIO_PORTA_BASE + GPIO_IMD) & GPIO_PIN_0; TestAssert(ulTemp == GPIO_PIN_0, "xgpio, \"ShortPin INT type enable \" error"); } else { ulTemp = xHWREG(xGPIO_PORTA_BASE + GPIO_IMD) & GPIO_PIN_0; TestAssert(ulTemp == 0, "xgpio, \"ShortPin INT type enable \" error"); } if(ulIntType[i] & 2) { ulTemp = xHWREG(xGPIO_PORTA_BASE + GPIO_IEN) & (GPIO_PIN_0 << 16); TestAssert(ulTemp == (GPIO_PIN_0 << 16), "xgpio, \"ShortPin INT type enable \" error"); } if(ulIntType[i] & 1) { ulTemp = xHWREG(xGPIO_PORTA_BASE + GPIO_IEN) & GPIO_PIN_0; TestAssert(ulTemp == GPIO_PIN_0, "xgpio, \"ShortPin INT type enable \" error"); } } // // Short pin interrupt disable // xGPIOSPinIntDisable(PA0); ulTemp = xHWREG(xGPIO_PORTA_BASE + GPIO_IEN) & (GPIO_PIN_0 << 16); ulTemp1 = xHWREG(xGPIO_PORTA_BASE + GPIO_IEN) & GPIO_PIN_0; ulTemp |= ulTemp1; TestAssert(ulTemp == 0, "xgpio, \"Short pin interrupt disable \" error"); // // Short pin write test // xGPIOSPinWrite(PA0, 1); ulTemp = xHWREG(xGPIO_PORTA_BASE + GPIO_DOUT) & GPIO_PIN_0; TestAssert(ulTemp == GPIO_PIN_0, "xgpio, \"Short pin write test \" error"); // // Turn pin to gpio mode test // xGPIOSPinTypeGPIOInput(PA0); ulTemp = xHWREG(GCR_GPAMFP) & GPIO_PIN_0; TestAssert(ulTemp == 0, "xgpio, \"Turn pin to gpio mode test \" error"); // // Turn pin to ADC input function // xSPinTypeADC(ADC0, PA0); ulTemp = xHWREG(GCR_GPAMFP) & GCR_GPAMFP_MFP0; TestAssert(ulTemp == GCR_GPAMFP_MFP0, "xgpio, \"Turn pin to ADC0 input \" error"); xSPinTypeADC(ADC1, PA1); ulTemp = xHWREG(GCR_GPAMFP) & GCR_GPAMFP_MFP1; TestAssert(ulTemp == GCR_GPAMFP_MFP1, "xgpio, \"Turn pin to ADC1 input \" error"); ulTemp = xHWREG(GCR_ALTMFP) & (GCR_ALTMFP_EBI_EN | GCR_ALTMFP_EBI_HB_EN_4); TestAssert(ulTemp == 0, "xgpio, \"Turn pin to ADC1 input \" error"); xSPinTypeADC(ADC2, PA2); ulTemp = xHWREG(GCR_GPAMFP) & GCR_GPAMFP_MFP2; TestAssert(ulTemp == GCR_GPAMFP_MFP2, "xgpio, \"Turn pin to ADC2 input \" error"); ulTemp = xHWREG(GCR_ALTMFP) & (GCR_ALTMFP_EBI_EN | GCR_ALTMFP_EBI_HB_EN_3); TestAssert(ulTemp == 0, "xgpio, \"Turn pin to ADC2 input \" error"); xSPinTypeADC(ADC3, PA3); ulTemp = xHWREG(GCR_GPAMFP) & GCR_GPAMFP_MFP3; TestAssert(ulTemp == GCR_GPAMFP_MFP3, "xgpio, \"Turn pin to ADC3 input \" error"); ulTemp = xHWREG(GCR_ALTMFP) & (GCR_ALTMFP_EBI_EN | GCR_ALTMFP_EBI_HB_EN_2); TestAssert(ulTemp == 0, "xgpio, \"Turn pin to ADC3 input \" error"); xSPinTypeADC(ADC4, PA4); ulTemp = xHWREG(GCR_GPAMFP) & GCR_GPAMFP_MFP4; TestAssert(ulTemp == GCR_GPAMFP_MFP4, "xgpio, \"Turn pin to ADC4 input \" error"); ulTemp = xHWREG(GCR_ALTMFP) & (GCR_ALTMFP_EBI_EN | GCR_ALTMFP_EBI_HB_EN_1); TestAssert(ulTemp == 0, "xgpio, \"Turn pin to ADC4 input \" error"); xSPinTypeADC(ADC5, PA5); ulTemp = xHWREG(GCR_GPAMFP) & GCR_GPAMFP_MFP5; TestAssert(ulTemp == GCR_GPAMFP_MFP5, "xgpio, \"Turn pin to ADC5 input \" error"); ulTemp = xHWREG(GCR_ALTMFP) & (GCR_ALTMFP_EBI_EN | GCR_ALTMFP_EBI_HB_EN_0); TestAssert(ulTemp == 0, "xgpio, \"Turn pin to ADC5 input \" error"); xSPinTypeADC(ADC6, PA6); ulTemp = xHWREG(GCR_GPAMFP) & GCR_GPAMFP_MFP6; TestAssert(ulTemp == GCR_GPAMFP_MFP6, "xgpio, \"Turn pin to ADC6 input \" error"); ulTemp = xHWREG(GCR_ALTMFP) & (GCR_ALTMFP_EBI_EN); TestAssert(ulTemp == 0, "xgpio, \"Turn pin to ADC6 input \" error"); xSPinTypeADC(ADC7, PA7); ulTemp = xHWREG(GCR_GPAMFP) & GCR_GPAMFP_MFP7; TestAssert(ulTemp == GCR_GPAMFP_MFP7, "xgpio, \"Turn pin to ADC7 input \" error"); ulTemp = xHWREG(GCR_ALTMFP) & (GCR_ALTMFP_EBI_EN); TestAssert(ulTemp == 0, "xgpio, \"Turn pin to ADC7 input \" error"); ulTemp = xHWREG(GCR_ALTMFP) & GCR_ALTMFP_PA7_S21; TestAssert(ulTemp == 0, "xgpio, \"Turn pin to ADC7 input \" error"); // // Ture pin to I2C function // xSPinTypeI2C(I2C0SCK, PA9); ulTemp = xHWREG(GCR_GPAMFP) & GCR_GPAMFP_MFP9; TestAssert(ulTemp == GCR_GPAMFP_MFP9, "xgpio, \"Turn pin to I2C input \" error"); xSPinTypeI2C(I2C0SDA, PA8); ulTemp = xHWREG(GCR_GPAMFP) & GCR_GPAMFP_MFP8; TestAssert(ulTemp == GCR_GPAMFP_MFP8, "xgpio, \"Turn pin to I2C input \" error"); xSPinTypeI2C(I2C1SCK, PA11); ulTemp = xHWREG(GCR_GPAMFP) & GCR_GPAMFP_MFP11; TestAssert(ulTemp == GCR_GPAMFP_MFP11, "xgpio, \"Turn pin to I2C input \" error"); ulTemp = xHWREG(GCR_ALTMFP) & (GCR_ALTMFP_EBI_EN); TestAssert(ulTemp == 0, "xgpio, \"Turn pin to I2C input \" error"); xSPinTypeI2C(I2C1SDA, PA10); ulTemp = xHWREG(GCR_GPAMFP) & GCR_GPAMFP_MFP10; TestAssert(ulTemp == GCR_GPAMFP_MFP10, "xgpio, \"Turn pin to I2C input \" error"); ulTemp = xHWREG(GCR_ALTMFP) & (GCR_ALTMFP_EBI_EN); TestAssert(ulTemp == 0, "xgpio, \"Turn pin to I2C input \" error"); // // Turn pin to CAN function // xSPinTypeCAN(CAN0RX, PD6); ulTemp = xHWREG(GCR_GPDMFP) & GCR_GPDMFP_MFP6; TestAssert(ulTemp == GCR_GPDMFP_MFP6, "xgpio, \"Turn pin to CAN function \" error"); xSPinTypeCAN(CAN0TX, PD7); ulTemp = xHWREG(GCR_GPDMFP) & GCR_GPDMFP_MFP7; TestAssert(ulTemp == GCR_GPDMFP_MFP7, "xgpio, \"Turn pin to CAN function \" error"); // // Turn pin to I2S function // xSPinTypeI2S(I2S0RXMCLK, PA15); ulTemp = xHWREG(GCR_GPAMFP) & GCR_GPAMFP_MFP15; TestAssert(ulTemp == GCR_GPAMFP_MFP15, "xgpio, \"Turn pin to I2S function \" error"); ulTemp = xHWREG(GCR_ALTMFP) & GCR_ALTMFP_PA15_I2SMCLK; TestAssert(ulTemp == GCR_ALTMFP_PA15_I2SMCLK, "xgpio, \"Turn pin to I2S function \" error"); xSPinTypeI2S(I2S0RXSCK, PC1); ulTemp = xHWREG(GCR_GPCMFP) & GCR_GPCMFP_MFP1; TestAssert(ulTemp == GCR_GPCMFP_MFP1, "xgpio, \"Turn pin to I2S function \" error"); ulTemp = xHWREG(GCR_ALTMFP) & (GCR_ALTMFP_PC1_I2SBCLK); TestAssert(ulTemp == GCR_ALTMFP_PC1_I2SBCLK, "xgpio, \"Turn pin to I2S function \" error"); xSPinTypeI2S(I2S0RXSD, PC2); ulTemp = xHWREG(GCR_GPCMFP) & GCR_GPCMFP_MFP2; TestAssert(ulTemp == GCR_GPCMFP_MFP2, "xgpio, \"Turn pin to I2S function \" error"); ulTemp = xHWREG(GCR_ALTMFP) & (GCR_ALTMFP_PC2_I2SDI); TestAssert(ulTemp == GCR_ALTMFP_PC2_I2SDI, "xgpio, \"Turn pin to I2S function \" error"); xSPinTypeI2S(I2S0RXWS, PC0); ulTemp = xHWREG(GCR_GPCMFP) & GCR_GPCMFP_MFP0; TestAssert(ulTemp == GCR_GPCMFP_MFP0, "xgpio, \"Turn pin to I2S function \" error"); ulTemp = xHWREG(GCR_ALTMFP) & (GCR_ALTMFP_PC0_I2SLRCLK); TestAssert(ulTemp == GCR_ALTMFP_PC0_I2SLRCLK, "xgpio, \"Turn pin to I2S function \" error"); xSPinTypeI2S(I2S0TXMCLK, PA15); ulTemp = xHWREG(GCR_GPAMFP) & GCR_GPAMFP_MFP15; TestAssert(ulTemp == GCR_GPAMFP_MFP15, "xgpio, \"Turn pin to I2S function \" error"); ulTemp = xHWREG(GCR_ALTMFP) & GCR_ALTMFP_PA15_I2SMCLK; TestAssert(ulTemp == GCR_ALTMFP_PA15_I2SMCLK, "xgpio, \"Turn pin to I2S function \" error"); xSPinTypeI2S(I2S0TXSCK, PC1); ulTemp = xHWREG(GCR_GPCMFP) & GCR_GPCMFP_MFP1; TestAssert(ulTemp == GCR_GPCMFP_MFP1, "xgpio, \"Turn pin to I2S function \" error"); ulTemp = xHWREG(GCR_ALTMFP) & (GCR_ALTMFP_PC1_I2SBCLK); TestAssert(ulTemp == GCR_ALTMFP_PC1_I2SBCLK, "xgpio, \"Turn pin to I2S function \" error"); xSPinTypeI2S(I2S0TXSD, PC3); ulTemp = xHWREG(GCR_GPCMFP) & GCR_GPCMFP_MFP3; TestAssert(ulTemp == GCR_GPCMFP_MFP3, "xgpio, \"Turn pin to I2S function \" error"); ulTemp = xHWREG(GCR_ALTMFP) & (GCR_ALTMFP_PC3_I2SDO); TestAssert(ulTemp == GCR_ALTMFP_PC3_I2SDO, "xgpio, \"Turn pin to I2S function \" error"); xSPinTypeI2S(I2S0TXWS, PC0); ulTemp = xHWREG(GCR_GPCMFP) & GCR_GPCMFP_MFP0; TestAssert(ulTemp == GCR_GPCMFP_MFP0, "xgpio, \"Turn pin to I2S function \" error"); ulTemp = xHWREG(GCR_ALTMFP) & (GCR_ALTMFP_PC0_I2SLRCLK); TestAssert(ulTemp == GCR_ALTMFP_PC0_I2SLRCLK, "xgpio, \"Turn pin to I2S function \" error"); // // Turn pin to pwm mode // xSPinTypePWM(PWM0, PA12); ulTemp = xHWREG(GCR_GPAMFP) & GCR_GPAMFP_MFP12; TestAssert(ulTemp == GCR_GPAMFP_MFP12, "xgpio, \"Turn pin to I2S function \" error"); ulTemp = xHWREG(GCR_ALTMFP) & (GCR_ALTMFP_EBI_EN | GCR_ALTMFP_EBI_HB_EN_5); TestAssert(ulTemp == 0, "xgpio, \"Turn pin to PWM input \" error"); xSPinTypePWM(PWM1, PA13); ulTemp = xHWREG(GCR_GPAMFP) & GCR_GPAMFP_MFP13; TestAssert(ulTemp == GCR_GPAMFP_MFP13, "xgpio, \"Turn pin to I2S function \" error"); ulTemp = xHWREG(GCR_ALTMFP) & (GCR_ALTMFP_EBI_EN | GCR_ALTMFP_EBI_HB_EN_6); TestAssert(ulTemp == 0, "xgpio, \"Turn pin to PWM input \" error"); xSPinTypePWM(PWM2, PA14); ulTemp = xHWREG(GCR_GPAMFP) & GCR_GPAMFP_MFP14; TestAssert(ulTemp == GCR_GPAMFP_MFP14, "xgpio, \"Turn pin to I2S function \" error"); ulTemp = xHWREG(GCR_ALTMFP) & (GCR_ALTMFP_EBI_EN | GCR_ALTMFP_EBI_HB_EN_7); TestAssert(ulTemp == 0, "xgpio, \"Turn pin to PWM input \" error"); xSPinTypePWM(PWM3, PA15); ulTemp = xHWREG(GCR_GPAMFP) & GCR_GPAMFP_MFP15; TestAssert(ulTemp == GCR_GPAMFP_MFP15, "xgpio, \"Turn pin to I2S function \" error"); ulTemp = xHWREG(GCR_ALTMFP) & GCR_ALTMFP_PA15_I2SMCLK; TestAssert(ulTemp == 0, "xgpio, \"Turn pin to PWM function \" error"); xSPinTypePWM(PWM4, PB11); ulTemp = xHWREG(GCR_GPBMFP) & GCR_GPBMFP_MFP11; TestAssert(ulTemp == GCR_GPBMFP_MFP11, "xgpio, \"Turn pin to I2S function \" error"); ulTemp = xHWREG(GCR_ALTMFP) & (GCR_ALTMFP_PB11_PWM4); TestAssert(ulTemp == GCR_ALTMFP_PB11_PWM4, "xgpio, \"Turn pin to PWM input \" error"); xSPinTypePWM(PWM5, PE5); ulTemp = xHWREG(GCR_GPEMFP) & GCR_GPEMFP_MFP5; TestAssert(ulTemp == GCR_GPEMFP_MFP5, "xgpio, \"Turn pin to I2S function \" error"); ulTemp = xHWREG(GCR_ALTMFP) & (GCR_ALTMFP_PE5_T1EX); TestAssert(ulTemp == 0, "xgpio, \"Turn pin to PWM input \" error"); xSPinTypePWM(PWM6, PE0); ulTemp = xHWREG(GCR_GPEMFP) & GCR_GPEMFP_MFP0; TestAssert(ulTemp == GCR_GPEMFP_MFP0, "xgpio, \"Turn pin to PWM function \" error"); xSPinTypePWM(PWM7, PE1); ulTemp = xHWREG(GCR_GPEMFP) & GCR_GPEMFP_MFP1; TestAssert(ulTemp == GCR_GPEMFP_MFP1, "xgpio, \"Turn pin to PWM function \" error"); // // Turn pin to spi function test // xSPinTypeSPI(SPI0CLK, PC1); ulTemp = xHWREG(GCR_GPCMFP) & GCR_GPCMFP_MFP1; TestAssert(ulTemp == GCR_GPCMFP_MFP1, "xgpio, \"Turn pin to SPI function \" error"); ulTemp = xHWREG(GCR_ALTMFP) & (GCR_ALTMFP_PC1_I2SBCLK); TestAssert(ulTemp == 0, "xgpio, \"Turn pin to SPI function \" error"); xSPinTypeSPI(SPI0MOSI, PC5); ulTemp = xHWREG(GCR_GPCMFP) & GCR_GPCMFP_MFP5; TestAssert(ulTemp == GCR_GPCMFP_MFP5, "xgpio, \"Turn pin to SPI function \" error"); xSPinTypeSPI(SPI0MOSI, PC3); ulTemp = xHWREG(GCR_GPCMFP) & GCR_GPCMFP_MFP3; TestAssert(ulTemp == GCR_GPCMFP_MFP3, "xgpio, \"Turn pin to SPI function \" error"); xSPinTypeSPI(SPI0MISO, PC2); ulTemp = xHWREG(GCR_GPCMFP) & GCR_GPCMFP_MFP2; TestAssert(ulTemp == GCR_GPCMFP_MFP2, "xgpio, \"Turn pin to SPI function \" error"); ulTemp = xHWREG(GCR_ALTMFP) & (GCR_ALTMFP_PC2_I2SDI); TestAssert(ulTemp == 0, "xgpio, \"Turn pin to I2S function \" error"); xSPinTypeSPI(SPI0MISO, PC4); ulTemp = xHWREG(GCR_GPCMFP) & GCR_GPCMFP_MFP4; TestAssert(ulTemp == GCR_GPCMFP_MFP4, "xgpio, \"Turn pin to SPI function \" error"); xSPinTypeSPI(SPI0CS, PC0); ulTemp = xHWREG(GCR_GPCMFP) & GCR_GPCMFP_MFP0; TestAssert(ulTemp == GCR_GPCMFP_MFP0, "xgpio, \"Turn pin to SPI function \" error"); ulTemp = xHWREG(GCR_ALTMFP) & (GCR_ALTMFP_PC0_I2SLRCLK); TestAssert(ulTemp == 0, "xgpio, \"Turn pin to SPI function \" error"); xSPinTypeSPI(SPI0CS, PB10); ulTemp = xHWREG(GCR_GPBMFP) & GCR_GPBMFP_MFP10; TestAssert(ulTemp == GCR_GPBMFP_MFP10, "xgpio, \"Turn pin to SPI function \" error"); ulTemp = xHWREG(GCR_ALTMFP) & (GCR_ALTMFP_PB10_S01); TestAssert(ulTemp == GCR_ALTMFP_PB10_S01, "xgpio, \"Turn pin to SPI function \" error"); xSPinTypeSPI(SPI0CS, PC0); ulTemp = xHWREG(GCR_GPCMFP) & GCR_GPCMFP_MFP0; TestAssert(ulTemp == GCR_GPCMFP_MFP0, "xgpio, \"Turn pin to SPI function \" error"); xSPinTypeSPI(SPI1MOSI, PC13); ulTemp = xHWREG(GCR_GPCMFP) & GCR_GPCMFP_MFP13; TestAssert(ulTemp == GCR_GPCMFP_MFP13, "xgpio, \"Turn pin to SPI function \" error"); xSPinTypeSPI(SPI1MOSI, PC11); ulTemp = xHWREG(GCR_GPCMFP) & GCR_GPCMFP_MFP11; TestAssert(ulTemp == GCR_GPCMFP_MFP11, "xgpio, \"Turn pin to SPI function \" error"); xSPinTypeSPI(SPI1MISO, PC12); ulTemp = xHWREG(GCR_GPCMFP) & GCR_GPCMFP_MFP12; TestAssert(ulTemp == GCR_GPCMFP_MFP12, "xgpio, \"Turn pin to SPI function \" error"); xSPinTypeSPI(SPI1MISO, PC10); ulTemp = xHWREG(GCR_GPCMFP) & GCR_GPCMFP_MFP10; TestAssert(ulTemp == GCR_GPCMFP_MFP10, "xgpio, \"Turn pin to SPI function \" error"); xSPinTypeSPI(SPI1CS, PB9); ulTemp = xHWREG(GCR_GPBMFP) & GCR_GPBMFP_MFP9; TestAssert(ulTemp == GCR_GPBMFP_MFP9, "xgpio, \"Turn pin to SPI function \" error"); ulTemp = xHWREG(GCR_ALTMFP) & (GCR_ALTMFP_PB9_S11); TestAssert(ulTemp == GCR_ALTMFP_PB9_S11, "xgpio, \"Turn pin to SPI function \" error"); xSPinTypeSPI(SPI1CS, PC8); ulTemp = xHWREG(GCR_GPCMFP) & GCR_GPCMFP_MFP8; TestAssert(ulTemp == GCR_GPCMFP_MFP8, "xgpio, \"Turn pin to SPI function \" error"); ulTemp = xHWREG(GCR_ALTMFP) & (GCR_ALTMFP_EBI_EN); TestAssert(ulTemp == 0, "xgpio, \"Turn pin to SPI function \" error"); xSPinTypeSPI(SPI2CLK, PD1); ulTemp = xHWREG(GCR_GPDMFP) & GCR_GPDMFP_MFP1; TestAssert(ulTemp == GCR_GPDMFP_MFP1, "xgpio, \"Turn pin to SPI function \" error"); xSPinTypeSPI(SPI2MOSI, PD3); ulTemp = xHWREG(GCR_GPDMFP) & GCR_GPDMFP_MFP3; TestAssert(ulTemp == GCR_GPDMFP_MFP3, "xgpio, \"Turn pin to SPI function \" error"); xSPinTypeSPI(SPI2MOSI, PD5); ulTemp = xHWREG(GCR_GPDMFP) & GCR_GPDMFP_MFP5; TestAssert(ulTemp == GCR_GPDMFP_MFP5, "xgpio, \"Turn pin to SPI function \" error"); xSPinTypeSPI(SPI2MISO, PD4); ulTemp = xHWREG(GCR_GPDMFP) & GCR_GPDMFP_MFP4; TestAssert(ulTemp == GCR_GPDMFP_MFP4, "xgpio, \"Turn pin to SPI function \" error"); xSPinTypeSPI(SPI2MISO, PD2); ulTemp = xHWREG(GCR_GPDMFP) & GCR_GPDMFP_MFP2; TestAssert(ulTemp == GCR_GPDMFP_MFP2, "xgpio, \"Turn pin to SPI function \" error"); xSPinTypeSPI(SPI2CS, PA7); ulTemp = xHWREG(GCR_GPAMFP) & GCR_GPAMFP_MFP7; TestAssert(ulTemp == GCR_GPAMFP_MFP7, "xgpio, \"Turn pin to SPI function \" error"); ulTemp = xHWREG(GCR_ALTMFP) & (GCR_ALTMFP_PA7_S21); TestAssert(ulTemp == GCR_ALTMFP_PA7_S21, "xgpio, \"Turn pin to SPI function \" error"); ulTemp = xHWREG(GCR_ALTMFP) & (GCR_ALTMFP_EBI_EN); TestAssert(ulTemp == 0, "xgpio, \"Turn pin to SPI function \" error"); xSPinTypeSPI(SPI2CS, PD0); ulTemp = xHWREG(GCR_GPDMFP) & GCR_GPDMFP_MFP0; TestAssert(ulTemp == GCR_GPDMFP_MFP0, "xgpio, \"Turn pin to SPI function \" error"); xSPinTypeSPI(SPI3CLK, PD9); ulTemp = xHWREG(GCR_GPDMFP) & GCR_GPDMFP_MFP9; TestAssert(ulTemp == GCR_GPDMFP_MFP9, "xgpio, \"Turn pin to SPI function \" error"); xSPinTypeSPI(SPI3MOSI, PD11); ulTemp = xHWREG(GCR_GPDMFP) & GCR_GPDMFP_MFP11; TestAssert(ulTemp == GCR_GPDMFP_MFP11, "xgpio, \"Turn pin to SPI function \" error"); xSPinTypeSPI(SPI3MOSI, PD13); ulTemp = xHWREG(GCR_GPDMFP) & GCR_GPDMFP_MFP13; TestAssert(ulTemp == GCR_GPDMFP_MFP13, "xgpio, \"Turn pin to SPI function \" error"); xSPinTypeSPI(SPI3MISO, PD10); ulTemp = xHWREG(GCR_GPDMFP) & GCR_GPDMFP_MFP10; TestAssert(ulTemp == GCR_GPDMFP_MFP10, "xgpio, \"Turn pin to SPI function \" error"); xSPinTypeSPI(SPI3MISO, PD12); ulTemp = xHWREG(GCR_GPDMFP) & GCR_GPDMFP_MFP12; TestAssert(ulTemp == GCR_GPDMFP_MFP12, "xgpio, \"Turn pin to SPI function \" error"); xSPinTypeSPI(SPI3CS, PB14); ulTemp = xHWREG(GCR_GPBMFP) & GCR_GPBMFP_MFP14; TestAssert(ulTemp == GCR_GPBMFP_MFP14, "xgpio, \"Turn pin to SPI function \" error"); ulTemp = xHWREG(GCR_ALTMFP) & (GCR_ALTMFP_PB14_S31); TestAssert(ulTemp == GCR_ALTMFP_PB14_S31, "xgpio, \"Turn pin to SPI function \" error"); xSPinTypeSPI(SPI3CS, PD8); ulTemp = xHWREG(GCR_GPDMFP) & GCR_GPDMFP_MFP8; TestAssert(ulTemp == GCR_GPDMFP_MFP8, "xgpio, \"Turn pin to SPI function \" error"); // // Turn pin to timer function test // xSPinTypeTimer(TIMCCP0, PB8); ulTemp = xHWREG(GCR_GPBMFP) & GCR_GPBMFP_MFP8; TestAssert(ulTemp == GCR_GPBMFP_MFP8, "xgpio, \"Turn pin to TIMER function \" error"); xSPinTypeTimer(TIMCCP1, PB9); ulTemp = xHWREG(GCR_GPBMFP) & GCR_GPBMFP_MFP9; TestAssert(ulTemp == GCR_GPBMFP_MFP9, "xgpio, \"Turn pin to TIMER function \" error"); ulTemp = xHWREG(GCR_ALTMFP) & (GCR_ALTMFP_PB9_S11); TestAssert(ulTemp == 0, "xgpio, \"Turn pin to TIMER function \" error"); xSPinTypeTimer(TIMCCP2, PB10); ulTemp = xHWREG(GCR_GPBMFP) & GCR_GPBMFP_MFP10; TestAssert(ulTemp == GCR_GPBMFP_MFP10, "xgpio, \"Turn pin to TIMER function \" error"); ulTemp = xHWREG(GCR_ALTMFP) & (GCR_ALTMFP_PB10_S01); TestAssert(ulTemp == 0, "xgpio, \"Turn pin to TIMER function \" error"); xSPinTypeTimer(TIMCCP3, PB11); ulTemp = xHWREG(GCR_GPBMFP) & GCR_GPBMFP_MFP11; TestAssert(ulTemp == GCR_GPBMFP_MFP11, "xgpio, \"Turn pin to TIMER function \" error"); ulTemp = xHWREG(GCR_ALTMFP) & (GCR_ALTMFP_PB11_PWM4); TestAssert(ulTemp == 0, "xgpio, \"Turn pin to TIMER function \" error"); // // Turn pin to uart function test // xSPinTypeUART(UART0RX, PB0); ulTemp = xHWREG(GCR_GPBMFP) & GCR_GPBMFP_MFP0; TestAssert(ulTemp == GCR_GPBMFP_MFP0, "xgpio, \"Turn pin to UART function \" error"); xSPinTypeUART(UART0TX, PB1); ulTemp = xHWREG(GCR_GPBMFP) & GCR_GPBMFP_MFP1; TestAssert(ulTemp == GCR_GPBMFP_MFP1, "xgpio, \"Turn pin to UART function \" error"); xSPinTypeUART(UART0RTS, PB2); ulTemp = xHWREG(GCR_GPBMFP) & GCR_GPBMFP_MFP2; TestAssert(ulTemp == GCR_GPBMFP_MFP2, "xgpio, \"Turn pin to UART function \" error"); ulTemp = xHWREG(GCR_ALTMFP) & (GCR_ALTMFP_EBI_EN | GCR_ALTMFP_EBI_nWRL_EN); TestAssert(ulTemp == 0, "xgpio, \"Turn pin to UART function \" error"); ulTemp = xHWREG(GCR_ALTMFP) & (GCR_ALTMFP_PB2_T2EX); TestAssert(ulTemp == 0, "xgpio, \"Turn pin to UART function \" error"); xSPinTypeUART(UART0CTS, PB3); ulTemp = xHWREG(GCR_GPBMFP) & GCR_GPBMFP_MFP3; TestAssert(ulTemp == GCR_GPBMFP_MFP3, "xgpio, \"Turn pin to UART function \" error"); ulTemp = xHWREG(GCR_ALTMFP) & (GCR_ALTMFP_EBI_EN | GCR_ALTMFP_EBI_nWRH_EN); TestAssert(ulTemp == 0, "xgpio, \"Turn pin to UART function \" error"); ulTemp = xHWREG(GCR_ALTMFP) & (GCR_ALTMFP_PB3_T3EX); TestAssert(ulTemp == 0, "xgpio, \"Turn pin to UART function \" error"); xSPinTypeUART(UART1RTS, PB6); ulTemp = xHWREG(GCR_GPBMFP) & GCR_GPBMFP_MFP6; TestAssert(ulTemp == GCR_GPBMFP_MFP6, "xgpio, \"Turn pin to UART function \" error"); ulTemp = xHWREG(GCR_ALTMFP) & (GCR_ALTMFP_EBI_EN); TestAssert(ulTemp == 0, "xgpio, \"Turn pin to UART function \" error"); xSPinTypeUART(UART1RX, PB4); ulTemp = xHWREG(GCR_GPBMFP) & GCR_GPBMFP_MFP4; TestAssert(ulTemp == GCR_GPBMFP_MFP4, "xgpio, \"Turn pin to UART function \" error"); xSPinTypeUART(UART1TX, PB5); ulTemp = xHWREG(GCR_GPBMFP) & GCR_GPBMFP_MFP5; TestAssert(ulTemp == GCR_GPBMFP_MFP5, "xgpio, \"Turn pin to UART function \" error"); xSPinTypeUART(UART2RX, PD14); ulTemp = xHWREG(GCR_GPDMFP) & GCR_GPDMFP_MFP14; TestAssert(ulTemp == GCR_GPDMFP_MFP14, "xgpio, \"Turn pin to UART function \" error"); xSPinTypeUART(UART2TX, PD15); ulTemp = xHWREG(GCR_GPDMFP) & GCR_GPDMFP_MFP15; TestAssert(ulTemp == GCR_GPDMFP_MFP15, "xgpio, \"Turn pin to UART function \" error"); // // Turn pin to ACMP function test // xSPinTypeACMP(CMP0P, PC6); ulTemp = xHWREG(GCR_GPCMFP) & GCR_GPCMFP_MFP6; TestAssert(ulTemp == GCR_GPCMFP_MFP6, "xgpio, \"Turn pin to SPI function \" error"); ulTemp = xHWREG(GCR_ALTMFP) & (GCR_ALTMFP_EBI_EN); TestAssert(ulTemp == 0, "xgpio, \"Turn pin to SPI function \" error"); xSPinTypeACMP(CMP0N, PC7); ulTemp = xHWREG(GCR_GPCMFP) & GCR_GPCMFP_MFP7; TestAssert(ulTemp == GCR_GPCMFP_MFP7, "xgpio, \"Turn pin to SPI function \" error"); ulTemp = xHWREG(GCR_ALTMFP) & (GCR_ALTMFP_EBI_EN); TestAssert(ulTemp == 0, "xgpio, \"Turn pin to SPI function \" error"); xSPinTypeACMP(CMP0O, PB12); ulTemp = xHWREG(GCR_GPBMFP) & GCR_GPBMFP_MFP12; TestAssert(ulTemp == GCR_GPBMFP_MFP12, "xgpio, \"Turn pin to SPI function \" error"); ulTemp = xHWREG(GCR_ALTMFP) & (GCR_ALTMFP_EBI_EN); TestAssert(ulTemp == 0, "xgpio, \"Turn pin to SPI function \" error"); xSPinTypeACMP(CMP1P, PC14); ulTemp = xHWREG(GCR_GPCMFP) & GCR_GPCMFP_MFP14; TestAssert(ulTemp == GCR_GPCMFP_MFP14, "xgpio, \"Turn pin to SPI function \" error"); ulTemp = xHWREG(GCR_ALTMFP) & (GCR_ALTMFP_EBI_EN); TestAssert(ulTemp == 0, "xgpio, \"Turn pin to SPI function \" error"); xSPinTypeACMP(CMP1N, PC15); ulTemp = xHWREG(GCR_GPCMFP) & GCR_GPCMFP_MFP15; TestAssert(ulTemp == GCR_GPCMFP_MFP15, "xgpio, \"Turn pin to SPI function \" error"); ulTemp = xHWREG(GCR_ALTMFP) & (GCR_ALTMFP_EBI_EN); TestAssert(ulTemp == 0, "xgpio, \"Turn pin to SPI function \" error"); xSPinTypeACMP(CMP1O, PB13); ulTemp = xHWREG(GCR_GPBMFP) & GCR_GPBMFP_MFP13; TestAssert(ulTemp == GCR_GPBMFP_MFP13, "xgpio, \"Turn pin to SPI function \" error"); ulTemp = xHWREG(GCR_ALTMFP) & (GCR_ALTMFP_EBI_EN); TestAssert(ulTemp == 0, "xgpio, \"Turn pin to SPI function \" error"); }
//***************************************************************************** // //! \brief Initialize the sensor shield board. //! //! \param None. //! //! Initialize the sensor shield board. //! //! \return None // //***************************************************************************** void SensorShieldInit(void) { xSysCtlPeripheralEnable(xGPIOSPinToPeripheralId(SENSOR_SHIELD_O0)); xSysCtlPeripheralEnable(xGPIOSPinToPeripheralId(SENSOR_SHIELD_O1)); xSysCtlPeripheralEnable(xGPIOSPinToPeripheralId(SENSOR_SHIELD_O2)); xSysCtlPeripheralEnable(xGPIOSPinToPeripheralId(SENSOR_SHIELD_O3)); xSysCtlPeripheralEnable(xGPIOSPinToPeripheralId(SENSOR_SHIELD_O4)); xSysCtlPeripheralEnable(xGPIOSPinToPeripheralId(SENSOR_SHIELD_O5)); xSysCtlPeripheralEnable(xGPIOSPinToPeripheralId(SENSOR_SHIELD_I0)); xSysCtlPeripheralEnable(xGPIOSPinToPeripheralId(SENSOR_SHIELD_I1)); xSysCtlPeripheralEnable(xGPIOSPinToPeripheralId(SENSOR_SHIELD_I2)); xSysCtlPeripheralEnable(xGPIOSPinToPeripheralId(SENSOR_SHIELD_I3)); xSysCtlPeripheralEnable(xGPIOSPinToPeripheralId(SENSOR_SHIELD_I4)); xSysCtlPeripheralEnable(xGPIOSPinToPeripheralId(SENSOR_SHIELD_I5)); #if(SENSOR_SHIELD_OUT_USED > 0) xGPIOSPinTypeGPIOOutput(SENSOR_SHIELD_O0); xGPIOSPinTypeGPIOOutput(SENSOR_SHIELD_O1); xGPIOSPinTypeGPIOOutput(SENSOR_SHIELD_O2); xGPIOSPinTypeGPIOOutput(SENSOR_SHIELD_O3); xGPIOSPinTypeGPIOOutput(SENSOR_SHIELD_O4); xGPIOSPinTypeGPIOOutput(SENSOR_SHIELD_O5); //xSysCtlPeripheralEnable2(); #endif #if((SENSOR_SHIELD_IN0_USED == SENSOR_SHIELD_IN_ANALOG) || \ (SENSOR_SHIELD_IN1_USED == SENSOR_SHIELD_IN_ANALOG) || \ (SENSOR_SHIELD_IN2_USED == SENSOR_SHIELD_IN_ANALOG) || \ (SENSOR_SHIELD_IN3_USED == SENSOR_SHIELD_IN_ANALOG) || \ (SENSOR_SHIELD_IN4_USED == SENSOR_SHIELD_IN_ANALOG) || \ (SENSOR_SHIELD_IN5_USED == SENSOR_SHIELD_IN_ANALOG)) xSysCtlPeripheralEnable(xGPIOSPinToPeripheralId(sD45)); // // Set ADCCLK prescaler, ADCCLK=PCLK2(max 72MHz)/Div(Div:2,4,6,8) // You should set ADCCLK < 14MHz to ensure the accuracy of ADC // xSysCtlPeripheralClockSourceSet(xSYSCTL_ADC0_MAIN, 8); // // Enable Peripheral ADC clock // xSysCtlPeripheralEnable(xSYSCTL_PERIPH_ADC1); // // Enable the ADC conversion // xADCEnable(sADC_BASE); // // The two sentences below configure ADC to scan mode, continuous convert, software trigger. // xADCConfigure(sADC_BASE, xADC_MODE_SCAN_SINGLE_CYCLE, ADC_TRIGGER_PROCESSOR); xADCConfigure(sADC_BASE, xADC_MODE_SCAN_CONTINUOUS, ADC_TRIGGER_PROCESSOR); // // Configure channel step by step.(Max 4 steps, the 2nd parameter start from 0, max is 3) // Must not jump over a step, or the ADC result may be in wrong position. // xADCStepConfigure(sADC_BASE, 0, sADC_CH0); xADCStepConfigure(sADC_BASE, 1, sADC_CH1); xADCStepConfigure(sADC_BASE, 2, sADC_CH2); xADCStepConfigure(sADC_BASE, 3, sADC_CH3); #endif #if(SENSOR_SHIELD_IN0_USED == SENSOR_SHIELD_IN_ANALOG) sA0PinTypeADC(); #elif (SENSOR_SHIELD_IN0_USED == SENSOR_SHIELD_IN_DIGITAL) xGPIOSPinTypeGPIOInput(SENSOR_SHIELD_I0); #endif #if(SENSOR_SHIELD_IN1_USED == SENSOR_SHIELD_IN_ANALOG) sA1PinTypeADC(); #elif (SENSOR_SHIELD_IN1_USED == SENSOR_SHIELD_IN_DIGITAL) xGPIOSPinTypeGPIOInput(SENSOR_SHIELD_I1); #endif #if(SENSOR_SHIELD_IN2_USED == SENSOR_SHIELD_IN_ANALOG) sA2PinTypeADC(); #elif (SENSOR_SHIELD_IN2_USED == SENSOR_SHIELD_IN_DIGITAL) xGPIOSPinTypeGPIOInput(SENSOR_SHIELD_I2); #endif #if(SENSOR_SHIELD_IN3_USED == SENSOR_SHIELD_IN_ANALOG) sA3PinTypeADC(); #elif (SENSOR_SHIELD_IN3_USED == SENSOR_SHIELD_IN_DIGITAL) xGPIOSPinTypeGPIOInput(SENSOR_SHIELD_I3); #endif #if(SENSOR_SHIELD_IN4_USED == SENSOR_SHIELD_IN_ANALOG)|| \ (SENSOR_SHIELD_IN4_USED == SENSOR_SHIELD_IN_DIGITAL) xGPIOSPinTypeGPIOInput(SENSOR_SHIELD_I4); #endif #if(SENSOR_SHIELD_IN5_USED == SENSOR_SHIELD_IN_ANALOG)|| \ (SENSOR_SHIELD_IN5_USED == SENSOR_SHIELD_IN_DIGITAL) xGPIOSPinTypeGPIOInput(SENSOR_SHIELD_I5); #endif #if(SENSOR_SHIELD_I2C_USED > 0) // // Enable the GPIOx port which is connected with I2C // xSysCtlPeripheralEnable(xGPIOSPinToPeripheralId(SENSOR_SHIELD_TWI_SDA)); xSysCtlPeripheralEnable(xGPIOSPinToPeripheralId(SENSOR_SHIELD_TWI_SCK)); // // Enable the I2Cx which is connected with device // xSysCtlPeripheralEnable2(sI2C_BASE); // // Set BH1750_PIN_I2C_CLK as CLK // sPinTypeI2C(sI2C_BASE); // // Configure MCU as a master device and Set Clcok Rates // xI2CMasterInit(sI2C_BASE, 100000); xI2CMasterEnable(sI2C_BASE); #endif #if(SENSOR_SHIELD_UART_USED > 0) xSysCtlPeripheralEnable2(sUART_BASE); // xSysCtlPeripheralClockSourceSet(xSYSCTL_UART1_MAIN, 1); sPinTypeUART(sUART_BASE); xUARTConfigSet(sUART_BASE, 115200, (xUART_CONFIG_WLEN_8 | xUART_CONFIG_STOP_1 | xUART_CONFIG_PAR_NONE)); #endif }