void main () { #if (BSPACM_DEVICE_LINE_TM4C123 - 0) #if 0 SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); /* OSC/1 = 16 MHz */ #elif 0 /* NOTE: Setting to 80 MHz requires a patch to SysCtlClockGet() when * using TivaWare_C_Series-2.1.0.12573. See * http://e2e.ti.com/support/microcontrollers/tiva_arm/f/908/p/330524/1156581.aspx#1156581 */ SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); /* 2*PLL/5 = 80 MHz */ #elif 0 SysCtlClockSet(SYSCTL_SYSDIV_3 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); /* PLL/3 = 66.67 MHz */ #elif 0 SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); /* PLL/4 = 50 MHz */ #elif 0 SysCtlClockSet(SYSCTL_SYSDIV_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); /* PLL/5 = 40 MHz */ #elif 0 SysCtlClockSet(SYSCTL_SYSDIV_10 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); /* PLL/10 = 20 MHz */ #elif 0 SysCtlClockSet(SYSCTL_SYSDIV_20 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); /* PLL/20 = 10 MHz */ #elif 0 SysCtlClockSet(SYSCTL_SYSDIV_40 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); /* PLL/40 = 5 MHz */ #elif 1 SysCtlClockSet(SYSCTL_SYSDIV_64 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); /* PLL/64 = 3.125 MHz */ #endif /* pick clock speed */ SystemCoreClock = SysCtlClockGet(); #elif (BSPACM_DEVICE_LINE_TM4C129 - 0) #if 0 SystemCoreClock = SysCtlClockFreqSet((SYSCTL_OSC_INT | SYSCTL_USE_OSC | SYSCTL_MAIN_OSC_DIS), 16000000); #elif 1 SystemCoreClock = SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 120000000); #elif 0 SystemCoreClock = SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 40000000); #endif /* pick and record clock speed */ #endif /* LINE */ vBSPACMledConfigure(); BSPACM_CORE_ENABLE_CYCCNT(); BSPACM_CORE_ENABLE_INTERRUPT(); printf("\n" __DATE__ " " __TIME__ "\n"); printf("System clock %lu Hz\n", SystemCoreClock); while (1) { vBSPACMledSet(0, -1); BSPACM_CORE_DELAY_CYCLES(SystemCoreClock); } fflush(stdout); ioctl(1, BSPACM_IOCTL_FLUSH, O_WRONLY); BSPACM_CORE_DEEP_SLEEP(); }
static void hal_init(void) { gSysClock = SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 120000000); //gSysClock = SysCtlClockFreqSet((SYSCTL_OSC_INT | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_320), 120000000); //SysCtlDeepSleep(); /*systick = 1ms*/ SysTickPeriodSet(gSysClock / 1000); SysTickEnable(); SysTickIntEnable(); bsp_gpio_init(); uart_hal_init(); bsp_adc_init(); bsp_spi0_init(); bsp_timer0_init(); bsp_timer1_init(); bsp_bt_uart_init(); bsp_nad_app_uart_init(); //bsp_pwm1_init(); IntPrioritySet(FAULT_SYSTICK, SYSTICK_INT_PRIORITY); IntMasterEnable(); }
int wolfSSL_TI_CCMInit(void) { if (ccm_init) return true; ccm_init = true; #ifndef TI_DUMMY_BUILD SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 120000000); if (!ROM_SysCtlPeripheralPresent(SYSCTL_PERIPH_CCM0)) return false; ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_CCM0); WAIT(ROM_SysCtlPeripheralReady(SYSCTL_PERIPH_CCM0)); ROM_SysCtlPeripheralReset(SYSCTL_PERIPH_CCM0); WAIT(ROM_SysCtlPeripheralReady(SYSCTL_PERIPH_CCM0)); #ifndef SINGLE_THREADED if (wc_InitMutex(&TI_CCM_Mutex)) return false; #endif #endif /* !TI_DUMMY_BUILD */ return true; }
int main(void) { /* Call board init functions */ uint32_t ui32SysClock; ui32SysClock = SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 120E6); Board_initGeneral(ui32SysClock); Board_initEMAC(); Board_initGPIO(); // Board_initI2C(); // Board_initSDSPI(); // Board_initSPI(); // Board_initUART(); // Board_initUSB(Board_USBDEVICE); // Board_initUSBMSCHFatFs(); // Board_initWatchdog(); // Board_initWiFi(); setup_ledcube(); Mailbox_Params mbox_Params; Error_Block eb; Error_init(&eb); _sem = Semaphore_create(0, NULL, &eb); if (_sem == NULL) { System_abort("Couldn't create semaphore"); } ledEvent = Event_create(NULL,&eb); Mailbox_Params_init(&mbox_Params); mbox_Params.readerEvent=ledEvent; mbox_Params.readerEventId=Event_Id_01; mbox_led = Mailbox_create(sizeof(struct ledMatrix),1, &mbox_Params, &eb); if(mbox_led == NULL){ // Do something with errorblock, in the real world System_abort("woho!"); } create_led_task((UArg) mbox_led); //netOpenHook((UArg) mbox_led); netOpenHook(mbox_led); System_printf("Starting the example\nSystem provider is set to SysMin. " "Halt the target to view any SysMin contents in ROV.\n"); /* SysMin will only print to the console when you call flush or exit */ System_flush(); /* Start BIOS */ BIOS_start(); return (0); }
void SystemInit(void) { //Enable floating-point unit FPUEnable(); //Run from the PLL at 120MHz SysCtlClockFreqSet(SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480, 120000000); }
/******** * Main * ********/ int main(void) { // Control Parameters float amp_set_v = 0.2; float pi_k = -1; float Q1H_V = -1; float Q1L_V = 2; float Q2H_V = -3; float Q2L_V = 4; int32_t P_gain2 = 10; // 2 * ALC Proportional Gain int32_t I_gain2 = -62; // 2 * ALC Integral Gain //int32_t P_gain2 = 2 * PGA_GAIN_MUTE; // Mute //int32_t I_gain2 = 2 * PGA_GAIN_MUTE; // Mute /* System initialization */ uint32_t SysClkFreq; #ifdef PART_TM4C123GH6PM // Set system clock to 80 MHz (400MHz main PLL (divided by 5 - uses DIV400 bit) [16MHz external xtal drives PLL] SysClkFreq = MAP_SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); #endif #ifdef PART_TM4C1294NCPDT // Set system clock to 120 MHz SysClkFreq = SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 120000000); #endif /* Error LED Initialization */ GTBEA_initErrLED(); /* PGA Initialization */ //pga_init(SysClkFreq, false, true); // unmuted, zero crossing mode enabled /* UART Comm. Initialization */ //twe_initVCOM(SysClkFreq, UART_BAUD); /* DAC Initialization */ DACd_initDAC(DAC_RANGE_PM5V | DAC_RANGE_PM5V_EH, DAC_PWR_PU_AMP_SET | DAC_PWR_PU_PI_K | DAC_PWR_PUALL_EH, SysClkFreq); DACd_updateDataVolt(DAC_ADDR_NONE_AD | DAC_ADDR_Q1H, DAC_RANGE_PM5V | DAC_RANGE_PM5V_EH, OFFSET_BINARY, OFFSET_BINARY, 0, Q1H_V); MAP_SysCtlDelay(4000); DACd_updateDataVolt(DAC_ADDR_NONE_AD | DAC_ADDR_Q1L, DAC_RANGE_PM5V | DAC_RANGE_PM5V_EH, OFFSET_BINARY, OFFSET_BINARY, 0, Q1L_V); MAP_SysCtlDelay(4000); DACd_updateDataVolt(DAC_ADDR_AMP_SET | DAC_ADDR_Q2H, DAC_RANGE_PM5V | DAC_RANGE_PM5V_EH, OFFSET_BINARY, OFFSET_BINARY, amp_set_v - DAC_AMP_SET_OFFSET, Q2H_V); MAP_SysCtlDelay(4000); DACd_updateDataVolt(DAC_ADDR_PI_K | DAC_ADDR_Q2L, DAC_RANGE_PM5V | DAC_RANGE_PM5V_EH, OFFSET_BINARY, OFFSET_BINARY, pi_k - DAC_PI_K_OFFSET, Q2L_V); MAP_SysCtlDelay(4000); DACd_loadDACs_AH(); //DACd_loadDACsPin_EH(); //pga_setGainInt(P_gain2, I_gain2); //pga_setGainInt(2 * PGA_GAIN_MUTE, 2 * PGA_GAIN_MUTE); // Mute while testing other circuits... while(1) { // wait... } }
DWORD SetSystemClock( void ) { #ifdef PART_TM4C123GH6PGE SysCtlClockSet(SYSCTL_SYSDIV_3 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); g_ulSystemClock = SysCtlClockGet(); #elif PART_TM4C1294NCPDT g_ulSystemClock = SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 120000000); #endif return g_ulSystemClock; }
int main(void) { // Set the system clock to the full 120MHz uint32_t sysClkFreq = SysCtlClockFreqSet(SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480, 120000000); debug_init(sysClkFreq); status_led_init(); network_driver_init(sysClkFreq); networking_init(); telemetry_init(); transducer_init(); thermocouple_init(); solenoid_init(); debug_print("Initialization complete. starting main loop.\r\n"); // Set up the SysTick timer and its interrupts SysTickPeriodSet(6000); // 40 kHz SysTickIntRegister(sys_tick); SysTickIntEnable(); SysTickEnable(); uint32_t loopIterations = 0; uint32_t frame_start = systick_clock; while(1) { status_led_periodic(); network_driver_periodic(); telemetry_periodic(); solenoid_periodic(); // debug_print_u32(systick_clock); //count loop iterations per second loopIterations++; if(systick_clock - frame_start >= 1000) { loops_per_second = loopIterations; loopIterations = 0; frame_start = systick_clock; } } }
int main(void) { ui32SysClkFreq = SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 120000000); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPION); GPIOPinTypeGPIOOutput(GPIO_PORTN_BASE, GPIO_PIN_0 | GPIO_PIN_1); GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_0 | GPIO_PIN_1, 0x00); Kentec320x240x16_SSD2119Init(ui32SysClkFreq); TouchScreenInit(ui32SysClkFreq); TouchScreenCallbackSet(WidgetPointerMessage); WidgetAdd(WIDGET_ROOT, (tWidget *) &g_sBackground); WidgetPaint(WIDGET_ROOT); while (1) { WidgetMessageQueueProcess(); } }
void initClk() { /*The FPU should be enabled because some compilers will use floating- * point registers, even for non-floating-point code. If the FPU is not * enabled this will cause a fault. This also ensures that floating- * point operations could be added to this application and would work * correctly and use the hardware floating-point unit. Finally, lazy * stacking is enabled for interrupt handlers. This allows floating- * point instructions to be used within interrupt handlers, but at the * expense of extra stack usage. */ FPUEnable(); FPULazyStackingEnable(); g_SysClock = SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 120000000); }
//***************************************************************************** // // This example encrypts blocks of plaintext using TDES in CBC mode. It // does the encryption first without uDMA and then with uDMA. The results // are checked after each operation. // //***************************************************************************** int main(void) { uint32_t pui32CipherText[16], ui32Errors, ui32Idx, ui32SysClock; tContext sContext; // // Run from the PLL at 120 MHz. // ui32SysClock = SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 120000000); // // Configure the device pins. // PinoutSet(); // // Initialize the display driver. // Kentec320x240x16_SSD2119Init(ui32SysClock); // // Initialize the graphics context. // GrContextInit(&sContext, &g_sKentec320x240x16_SSD2119); // // Draw the application frame. // FrameDraw(&sContext, "tdes-cbc-encrypt"); // // Show some instructions on the display // GrContextFontSet(&sContext, g_psFontCm20); GrContextForegroundSet(&sContext, ClrWhite); GrStringDrawCentered(&sContext, "Connect a terminal to", -1, GrContextDpyWidthGet(&sContext) / 2, 60, false); GrStringDrawCentered(&sContext, "UART0 (115200,N,8,1)", -1, GrContextDpyWidthGet(&sContext) / 2, 80, false); GrStringDrawCentered(&sContext, "for more information.", -1, GrContextDpyWidthGet(&sContext) / 2, 100, false); // // Initialize local variables. // ui32Errors = 0; for(ui32Idx = 0; ui32Idx < 16; ui32Idx++) { pui32CipherText[ui32Idx] = 0; } // // Enable stacking for interrupt handlers. This allows floating-point // instructions to be used within interrupt handlers, but at the expense of // extra stack usage. // ROM_FPUStackingEnable(); // // Enable DES interrupts. // ROM_IntEnable(INT_DES0); // // Enable debug output on UART0 and print a welcome message. // ConfigureUART(); UARTprintf("Starting TDES CBC encryption demo.\n"); GrStringDrawCentered(&sContext, "Starting demo...", -1, GrContextDpyWidthGet(&sContext) / 2, 140, false); // // Enable the uDMA module. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UDMA); // // Setup the control table. // ROM_uDMAEnable(); ROM_uDMAControlBaseSet(g_psDMAControlTable); // // Initialize the CCM and DES modules. // if(!DESInit()) { UARTprintf("Initialization of the DES module failed.\n"); ui32Errors |= 0x00000001; } // // Perform the encryption without uDMA. // UARTprintf("Performing encryption without uDMA.\n"); TDESCBCEncrypt(g_pui32TDESPlainText, pui32CipherText, g_pui32TDESKey, 64, g_pui32TDESIV, false); // // Check the result. // for(ui32Idx = 0; ui32Idx < 16; ui32Idx++) { if(pui32CipherText[ui32Idx] != g_pui32TDESCipherText[ui32Idx]) { UARTprintf("Ciphertext mismatch on word %d. Exp: 0x%x, Act: " "0x%x\n", ui32Idx, g_pui32TDESCipherText[ui32Idx], pui32CipherText[ui32Idx]); ui32Errors |= (ui32Idx << 16) | 0x00000002; } } // // Clear the array containing the ciphertext. // for(ui32Idx = 0; ui32Idx < 16; ui32Idx++) { pui32CipherText[ui32Idx] = 0; } // // Perform the encryption with uDMA. // UARTprintf("Performing encryption with uDMA.\n"); TDESCBCEncrypt(g_pui32TDESPlainText, pui32CipherText, g_pui32TDESKey, 64, g_pui32TDESIV, true); // // Check the result. // for(ui32Idx = 0; ui32Idx < 16; ui32Idx++) { if(pui32CipherText[ui32Idx] != g_pui32TDESCipherText[ui32Idx]) { UARTprintf("Ciphertext mismatch on word %d. Exp: 0x%x, Act: " "0x%x\n", ui32Idx, g_pui32TDESCipherText[ui32Idx], pui32CipherText[ui32Idx]); ui32Errors |= (ui32Idx << 16) | 0x00000004; } } // // Finished. // if(ui32Errors) { UARTprintf("Demo failed with error code 0x%x.\n", ui32Errors); GrStringDrawCentered(&sContext, "Demo failed.", -1, GrContextDpyWidthGet(&sContext) / 2, 180, false); } else { UARTprintf("Demo completed successfully.\n"); GrStringDrawCentered(&sContext, "Demo passed.", -1, GrContextDpyWidthGet(&sContext) / 2, 180, false); } while(1) { } }
//***************************************************************************** // // Configure the CAN and enter a loop to receive CAN messages. // //***************************************************************************** int main(void) { #if defined(TARGET_IS_TM4C129_RA0) || \ defined(TARGET_IS_TM4C129_RA1) || \ defined(TARGET_IS_TM4C129_RA2) uint32_t ui32SysClock; #endif tCANMsgObject sCANMessage; uint8_t pui8MsgData[8]; // // Set the clocking to run directly from the external crystal/oscillator. // TODO: The SYSCTL_XTAL_ value must be changed to match the value of the // crystal used on your board. // #if defined(TARGET_IS_TM4C129_RA0) || \ defined(TARGET_IS_TM4C129_RA1) || \ defined(TARGET_IS_TM4C129_RA2) ui32SysClock = SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_OSC) 25000000); #else SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); #endif // // Set up the serial console to use for displaying messages. This is // just for this example program and is not needed for CAN operation. // InitConsole(); // // For this example CAN0 is used with RX and TX pins on port B4 and B5. // The actual port and pins used may be different on your part, consult // the data sheet for more information. // GPIO port B needs to be enabled so these pins can be used. // TODO: change this to whichever GPIO port you are using // SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); // // Configure the GPIO pin muxing to select CAN0 functions for these pins. // This step selects which alternate function is available for these pins. // This is necessary if your part supports GPIO pin function muxing. // Consult the data sheet to see which functions are allocated per pin. // TODO: change this to select the port/pin you are using // GPIOPinConfigure(GPIO_PB4_CAN0RX); GPIOPinConfigure(GPIO_PB5_CAN0TX); // // Enable the alternate function on the GPIO pins. The above step selects // which alternate function is available. This step actually enables the // alternate function instead of GPIO for these pins. // TODO: change this to match the port/pin you are using // GPIOPinTypeCAN(GPIO_PORTB_BASE, GPIO_PIN_4 | GPIO_PIN_5); // // The GPIO port and pins have been set up for CAN. The CAN peripheral // must be enabled. // SysCtlPeripheralEnable(SYSCTL_PERIPH_CAN0); // // Initialize the CAN controller // CANInit(CAN0_BASE); // // Set up the bit rate for the CAN bus. This function sets up the CAN // bus timing for a nominal configuration. You can achieve more control // over the CAN bus timing by using the function CANBitTimingSet() instead // of this one, if needed. // In this example, the CAN bus is set to 500 kHz. In the function below, // the call to SysCtlClockGet() or ui32SysClock is used to determine the // clock rate that is used for clocking the CAN peripheral. This can be // replaced with a fixed value if you know the value of the system clock, // saving the extra function call. For some parts, the CAN peripheral is // clocked by a fixed 8 MHz regardless of the system clock in which case // the call to SysCtlClockGet() or ui32SysClock should be replaced with // 8000000. Consult the data sheet for more information about CAN // peripheral clocking. // #if defined(TARGET_IS_TM4C129_RA0) || \ defined(TARGET_IS_TM4C129_RA1) || \ defined(TARGET_IS_TM4C129_RA2) CANBitRateSet(CAN0_BASE, ui32SysClock, 500000); #else CANBitRateSet(CAN0_BASE, SysCtlClockGet(), 500000); #endif // // Enable interrupts on the CAN peripheral. This example uses static // allocation of interrupt handlers which means the name of the handler // is in the vector table of startup code. If you want to use dynamic // allocation of the vector table, then you must also call CANIntRegister() // here. // // CANIntRegister(CAN0_BASE, CANIntHandler); // if using dynamic vectors // CANIntEnable(CAN0_BASE, CAN_INT_MASTER | CAN_INT_ERROR | CAN_INT_STATUS); // // Enable the CAN interrupt on the processor (NVIC). // IntEnable(INT_CAN0); // // Enable the CAN for operation. // CANEnable(CAN0_BASE); // // Initialize a message object to be used for receiving CAN messages with // any CAN ID. In order to receive any CAN ID, the ID and mask must both // be set to 0, and the ID filter enabled. // sCANMessage.ui32MsgID = 0; sCANMessage.ui32MsgIDMask = 0; sCANMessage.ui32Flags = MSG_OBJ_RX_INT_ENABLE | MSG_OBJ_USE_ID_FILTER; sCANMessage.ui32MsgLen = 8; // // Now load the message object into the CAN peripheral. Once loaded the // CAN will receive any message on the bus, and an interrupt will occur. // Use message object 1 for receiving messages (this is not the same as // the CAN ID which can be any value in this example). // CANMessageSet(CAN0_BASE, 1, &sCANMessage, MSG_OBJ_TYPE_RX); // // Enter loop to process received messages. This loop just checks a flag // that is set by the interrupt handler, and if set it reads out the // message and displays the contents. This is not a robust method for // processing incoming CAN data and can only handle one messages at a time. // If many messages are being received close together, then some messages // may be dropped. In a real application, some other method should be used // for queuing received messages in a way to ensure they are not lost. You // can also make use of CAN FIFO mode which will allow messages to be // buffered before they are processed. // for(;;) { unsigned int uIdx; // // If the flag is set, that means that the RX interrupt occurred and // there is a message ready to be read from the CAN // if(g_bRXFlag) { // // Reuse the same message object that was used earlier to configure // the CAN for receiving messages. A buffer for storing the // received data must also be provided, so set the buffer pointer // within the message object. // sCANMessage.pui8MsgData = pui8MsgData; // // Read the message from the CAN. Message object number 1 is used // (which is not the same thing as CAN ID). The interrupt clearing // flag is not set because this interrupt was already cleared in // the interrupt handler. // CANMessageGet(CAN0_BASE, 1, &sCANMessage, 0); // // Clear the pending message flag so that the interrupt handler can // set it again when the next message arrives. // g_bRXFlag = 0; // // Check to see if there is an indication that some messages were // lost. // if(sCANMessage.ui32Flags & MSG_OBJ_DATA_LOST) { UARTprintf("CAN message loss detected\n"); } // // Print out the contents of the message that was received. // UARTprintf("Msg ID=0x%08X len=%u data=0x", sCANMessage.ui32MsgID, sCANMessage.ui32MsgLen); for(uIdx = 0; uIdx < sCANMessage.ui32MsgLen; uIdx++) { UARTprintf("%02X ", pui8MsgData[uIdx]); } UARTprintf("total count=%u\n", g_ui32MsgCount); } } // // Return no errors // return(0); }
static void Task_Start (void *p_arg) { CPU_INT32U cpu_clk_freq; CPU_INT32U cnts; OS_ERR err_os; (void)&p_arg; BSP_Init(); /* Initialize BSP functions */ cpu_clk_freq = BSP_SysClkFreqGet(); /* Determine SysTick reference freq. */ cnts = cpu_clk_freq /* Determine nbr SysTick increments */ / (CPU_INT32U)OSCfg_TickRate_Hz; OS_CPU_SysTickInit(cnts); CPU_Init(); /* Initialize the uC/CPU services */ #if (OS_CFG_STAT_TASK_EN > 0u) OSStatTaskCPUUsageInit(&err_os); /* Compute CPU capacity with no task running */ #endif Mem_Init(); #ifdef CPU_CFG_INT_DIS_MEAS_EN CPU_IntDisMeasMaxCurReset(); #endif // AppTaskCreate(); /* Creates all the necessary application tasks. */ // while (DEF_ON) { // BSP_LED_Toggle(0); // OSTimeDlyHMSM(0, 0, 0, 500, // OS_OPT_TIME_HMSM_STRICT, // &err_os); // } // Set the pinout for the board, including required pins for Ethernet // operation. PinoutSet(0,1); g_ui32SysClock = SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 120000000); UARTStdioConfig(0, 115200, g_ui32SysClock); //cpu_clk_freq); UARTprintf("\033[2J\033[H"); UARTprintf("Welcome to the Connected LaunchPad!!\n"); UARTprintf("Internet of Things Demo\n"); UARTprintf("Type \'help\' for help.\n\n"); //create task LED1 OSTaskCreate((OS_TCB *)&LED_TCB, (CPU_CHAR *)"LED", (OS_TASK_PTR )Task_LED, (void *)0, (OS_PRIO )TASK_LED_PRIO, (CPU_STK *)&LED_Stk[0], (CPU_STK_SIZE)TASK_LED_STK_SIZE/10, (CPU_STK_SIZE)TASK_LED_STK_SIZE, (OS_MSG_QTY )0, (OS_TICK )0, (void *)0, (OS_OPT )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR), (OS_ERR *)&err_os); // createe test task OSTaskCreate((OS_TCB *)&Tmr_TCB, (CPU_CHAR *)"TS", (OS_TASK_PTR )Task_Tmr, (void *)0, (OS_PRIO )TASK_DBG_PRIO, (CPU_STK *)&Tmr_Stk[0], (CPU_STK_SIZE)TASK_TMR_STK_SIZE/10, (CPU_STK_SIZE)TASK_TMR_STK_SIZE, (OS_MSG_QTY )0, (OS_TICK )0, (void *)0, (OS_OPT )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR), (OS_ERR *)&err_os); // remove the startup task. OSTaskDel(&StartUp_TCB,&err_os); }
//***************************************************************************** // // This example decrypts a block of payload using AES128 in CCM mode. It // does the decryption first without uDMA and then with uDMA. The results // are checked after each operation. // //***************************************************************************** int main(void) { uint32_t pui32Payload[16], pui32Tag[4], ui32Errors, ui32Idx; uint32_t ui32PayloadLength, ui32TagLength; uint32_t ui32NonceLength, ui32AuthDataLength; uint32_t *pui32Nonce, *pui32AuthData, ui32SysClock; uint32_t *pui32Key, *pui32ExpPayload, *pui32CipherText; uint8_t ui8Vector; uint8_t *pui8ExpTag, *pui8Tag; tContext sContext; // // Run from the PLL at 120 MHz. // ui32SysClock = SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 120000000); // // Configure the device pins. // PinoutSet(); // // Initialize the display driver. // Kentec320x240x16_SSD2119Init(ui32SysClock); // // Initialize the graphics context. // GrContextInit(&sContext, &g_sKentec320x240x16_SSD2119); // // Draw the application frame. // FrameDraw(&sContext, "aes128-ccm-decrypt"); // // Show some instructions on the display // GrContextFontSet(&sContext, g_psFontCm20); GrContextForegroundSet(&sContext, ClrWhite); GrStringDrawCentered(&sContext, "Connect a terminal to", -1, GrContextDpyWidthGet(&sContext) / 2, 60, false); GrStringDrawCentered(&sContext, "UART0 (115200,N,8,1)", -1, GrContextDpyWidthGet(&sContext) / 2, 80, false); GrStringDrawCentered(&sContext, "for more information.", -1, GrContextDpyWidthGet(&sContext) / 2, 100, false); // // Initialize local variables. // ui32Errors = 0; for(ui32Idx = 0; ui32Idx < 16; ui32Idx++) { pui32Payload[ui32Idx] = 0; } for(ui32Idx = 0; ui32Idx < 4; ui32Idx++) { pui32Tag[ui32Idx] = 0; } pui8Tag = (uint8_t *)pui32Tag; // // Enable stacking for interrupt handlers. This allows floating-point // instructions to be used within interrupt handlers, but at the expense of // extra stack usage. // ROM_FPUStackingEnable(); // // Configure the system clock to run off the internal 16MHz oscillator. // ROM_SysCtlClockFreqSet(SYSCTL_OSC_INT | SYSCTL_USE_OSC, 16000000); // // Enable AES interrupts. // ROM_IntEnable(INT_AES0); // // Enable debug output on UART0 and print a welcome message. // ConfigureUART(); UARTprintf("Starting AES128 CCM decryption demo.\n"); GrStringDrawCentered(&sContext, "Starting demo...", -1, GrContextDpyWidthGet(&sContext) / 2, 140, false); // // Enable the uDMA module. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UDMA); // // Setup the control table. // ROM_uDMAEnable(); ROM_uDMAControlBaseSet(g_psDMAControlTable); // // Initialize the CCM and AES modules. // if(!AESInit()) { UARTprintf("Initialization of the AES module failed.\n"); ui32Errors |= 0x00000001; } // // Loop through all the given vectors. // for(ui8Vector = 0; (ui8Vector < (sizeof(g_psAESCCMTestVectors) / sizeof(g_psAESCCMTestVectors[0]))) && (ui32Errors == 0); ui8Vector++) { UARTprintf("Starting vector #%d\n", ui8Vector); // // Get the current vector's data members. // pui32Key = g_psAESCCMTestVectors[ui8Vector].pui32Key; pui32ExpPayload = g_psAESCCMTestVectors[ui8Vector].pui32Payload; ui32PayloadLength = g_psAESCCMTestVectors[ui8Vector].ui32PayloadLength; pui32AuthData = g_psAESCCMTestVectors[ui8Vector].pui32AuthData; ui32AuthDataLength = g_psAESCCMTestVectors[ui8Vector].ui32AuthDataLength; pui32CipherText = g_psAESCCMTestVectors[ui8Vector].pui32CipherText; pui8ExpTag = (uint8_t *)g_psAESCCMTestVectors[ui8Vector].pui32Tag; ui32TagLength = g_psAESCCMTestVectors[ui8Vector].ui32TagLength; pui32Nonce = g_psAESCCMTestVectors[ui8Vector].pui32Nonce; ui32NonceLength = g_psAESCCMTestVectors[ui8Vector].ui32NonceLength; // // Perform the decryption without uDMA. // UARTprintf("Performing decryption without uDMA.\n"); AES128CCMDecrypt(pui32Key, pui32CipherText, pui32Payload, ui32PayloadLength, pui32Nonce, ui32NonceLength, pui32AuthData, ui32AuthDataLength, pui32Tag, ui32TagLength, false); // // Check the result. // for(ui32Idx = 0; ui32Idx < (ui32PayloadLength / 4); ui32Idx++) { if(pui32Payload[ui32Idx] != pui32ExpPayload[ui32Idx]) { UARTprintf("Payload mismatch on word %d. Exp: 0x%x, Act: " "0x%x\n", ui32Idx, pui32ExpPayload[ui32Idx], pui32Payload[ui32Idx]); ui32Errors |= (ui32Idx << 16) | 0x00000002; } } for(ui32Idx = 0; ui32Idx < ui32TagLength; ui32Idx++) { if(pui8Tag[ui32Idx] != pui8ExpTag[ui32Idx]) { UARTprintf("Tag mismatch on byte %d. Exp: 0x%x, Act: " "0x%x\n", ui32Idx, pui8ExpTag[ui32Idx], pui8Tag[ui32Idx]); ui32Errors |= (ui32Idx << 16) | 0x00000004; } } // // Clear the array containing the ciphertext. // for(ui32Idx = 0; ui32Idx < 16; ui32Idx++) { pui32Payload[ui32Idx] = 0; } for(ui32Idx = 0; ui32Idx < 4; ui32Idx++) { pui32Tag[ui32Idx] = 0; } // // Perform the decryption with uDMA. // UARTprintf("Performing decryption with uDMA.\n"); AES128CCMDecrypt(pui32Key, pui32CipherText, pui32Payload, ui32PayloadLength, pui32Nonce, ui32NonceLength, pui32AuthData, ui32AuthDataLength, pui32Tag, ui32TagLength, true); // // Check the result. // for(ui32Idx = 0; ui32Idx < (ui32PayloadLength / 4); ui32Idx++) { if(pui32Payload[ui32Idx] != pui32ExpPayload[ui32Idx]) { UARTprintf("Payload mismatch on word %d. Exp: 0x%x, Act: " "0x%x\n", ui32Idx, pui32ExpPayload[ui32Idx], pui32Payload[ui32Idx]); ui32Errors |= (ui32Idx << 16) | 0x00000002; } } for(ui32Idx = 0; ui32Idx < ui32TagLength; ui32Idx++) { if(pui8Tag[ui32Idx] != pui8ExpTag[ui32Idx]) { UARTprintf("Tag mismatch on byte %d. Exp: 0x%x, Act: " "0x%x\n", ui32Idx, pui8ExpTag[ui32Idx], pui8Tag[ui32Idx]); ui32Errors |= (ui32Idx << 16) | 0x00000004; } } // // Clear the array containing the ciphertext. // for(ui32Idx = 0; ui32Idx < 16; ui32Idx++) { pui32Payload[ui32Idx] = 0; } for(ui32Idx = 0; ui32Idx < 4; ui32Idx++) { pui32Tag[ui32Idx] = 0; } } // // Finished. // if(ui32Errors) { UARTprintf("Demo failed with error code 0x%x.\n", ui32Errors); GrStringDrawCentered(&sContext, "Demo failed.", -1, GrContextDpyWidthGet(&sContext) / 2, 180, false); } else { UARTprintf("Demo completed successfully.\n"); GrStringDrawCentered(&sContext, "Demo passed.", -1, GrContextDpyWidthGet(&sContext) / 2, 180, false); } while(1) { } }
//***************************************************************************** // // Configure Timer1B as a 16-bit PWM with a duty cycle of 66%. // //***************************************************************************** int main(void) { // // Set the clocking to run directly from the external crystal/oscillator. // TODO: The SYSCTL_XTAL_ value must be changed to match the value of the // crystal on your board. // #if defined(TARGET_IS_TM4C129_RA0) || \ defined(TARGET_IS_TM4C129_RA1) || \ defined(TARGET_IS_TM4C129_RA2) g_ui32SysClock = SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_OSC), 25000000); #else SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); #endif // // The Timer1 peripheral must be enabled for use. // SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1); // // For this example T1CCP1 is used with port B pin 5. // The actual port and pins used may be different on your part, consult // the data sheet for more information. // GPIO port B needs to be enabled so these pins can be used. // TODO: change this to whichever GPIO port you are using. // SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); // // Configure the GPIO pin muxing for the Timer/CCP function. // This is only necessary if your part supports GPIO pin function muxing. // Study the data sheet to see which functions are allocated per pin. // TODO: change this to select the port/pin you are using // GPIOPinConfigure(GPIO_PB5_T1CCP1); // // Set up the serial console to use for displaying messages. This is // just for this example program and is not needed for Timer/PWM operation. // InitConsole(); // // Configure the ccp settings for CCP pin. This function also gives // control of these pins to the SSI hardware. Consult the data sheet to // see which functions are allocated per pin. // TODO: change this to select the port/pin you are using. // GPIOPinTypeTimer(GPIO_PORTB_BASE, GPIO_PIN_5); // // Display the example setup on the console. // UARTprintf("16-Bit Timer PWM ->"); UARTprintf("\n Timer = Timer1B"); UARTprintf("\n Mode = PWM"); UARTprintf("\n Duty Cycle = 66%%\n"); UARTprintf("\nGenerating PWM on CCP3 (PE4) -> "); // // Configure Timer1B as a 16-bit periodic timer. // TimerConfigure(TIMER1_BASE, TIMER_CFG_SPLIT_PAIR | TIMER_CFG_B_PWM); // // Set the Timer1B load value to 50000. For this example a 66% duty cycle // PWM signal will be generated. From the load value (i.e. 50000) down to // match value (set below) the signal will be high. From the match value // to 0 the timer will be low. // TimerLoadSet(TIMER1_BASE, TIMER_B, 50000); // // Set the Timer1B match value to load value / 3. // TimerMatchSet(TIMER1_BASE, TIMER_B, TimerLoadGet(TIMER1_BASE, TIMER_B) / 3); // // Enable Timer1B. // TimerEnable(TIMER1_BASE, TIMER_B); // // Loop forever while the Timer1B PWM runs. // while(1) { // // Print out indication on the console that the program is running. // PrintRunningDots(); } }
//***************************************************************************** // // A simple application demonstrating use of the boot loader, // //***************************************************************************** int main(void) { // // Enable lazy stacking for interrupt handlers. This allows floating-point // instructions to be used within interrupt handlers, but at the expense of // extra stack usage. // ROM_FPULazyStackingEnable(); // // Set the system clock to run at 120MHz from the PLL // g_ui32SysClockFreq = SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 120000000); // // Initialize the peripherals that each of the boot loader flavours // supports. Since this example is intended for use with any of the // boot loaders and we don't know which is actually in use, we cover all // bases and initialize for serial, Ethernet and USB use here. // SetupForUART(); SetupForUSB(); // // Enable Port J Pin 0 for exit to UART Boot loader when Pressed Low. // On the EK-TM4C1294 the weak pull up is enabled to detect button // press. // SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOJ); while(!(SysCtlPeripheralReady(SYSCTL_PERIPH_GPIOJ))); GPIOPinTypeGPIOInput(GPIO_PORTJ_BASE, GPIO_PIN_0); HWREG(GPIO_PORTJ_BASE + GPIO_O_PUR) = GPIO_PIN_0; // // Configure Port N pin 0 as output. // SysCtlPeripheralEnable(SYSCTL_PERIPH_GPION); while(!(SysCtlPeripheralReady(SYSCTL_PERIPH_GPION))); GPIOPinTypeGPIOOutput(GPIO_PORTN_BASE, GPIO_PIN_0); // // If the Switch SW1 is not pressed then blink the LED D2 at 1 Hz rate // On switch SW press detection exit the blinking program and jump to // the flash boot loader. // while((GPIOPinRead(GPIO_PORTJ_BASE, GPIO_PIN_0) & GPIO_PIN_0) != 0x0) { GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_0, 0x0); SysCtlDelay(g_ui32SysClockFreq / 6); GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_0, GPIO_PIN_0); SysCtlDelay(g_ui32SysClockFreq / 6); } // // Before passing control make sure that the LED is turned OFF. // GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_0, 0x0); // // Pass control to whichever flavour of boot loader the board is configured // with. // JumpToBootLoader(); // // The previous function never returns but we need to stick in a return // code here to keep the compiler from generating a warning. // return(0); }
//***************************************************************************** // // Configure EPI0 in SDRAM mode. The EPI memory space is setup using an a // simple C array. This example shows how to read and write to an SDRAM card // using the EPI bus in SDRAM mode. // //***************************************************************************** int main(void) { uint32_t ui32Val, ui32Freq, ui32SysClock; // // Set the clocking to run at 120MHz from the PLL. // TODO: Update this call to set the system clock frequency your // application requires. // ui32SysClock = SysCtlClockFreqSet((SYSCTL_OSC_INT | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_320), 120000000); // // Set up the serial console to use for displaying messages. This is // just for this example program and is not needed for EPI operation. // InitConsole(); // // Display the setup on the console. // UARTprintf("EPI SDRAM Mode ->\n"); UARTprintf(" Type: SDRAM\n"); UARTprintf(" Starting Address: 0x%08x\n", SDRAM_MAPPING_ADDRESS); UARTprintf(" End Address: 0x%08x\n", (SDRAM_MAPPING_ADDRESS + SDRAM_END_ADDRESS)); UARTprintf(" Data: 16-bit\n"); UARTprintf(" Size: 64MB (32Meg x 16bits)\n\n"); // // The EPI0 peripheral must be enabled for use. // SysCtlPeripheralEnable(SYSCTL_PERIPH_EPI0); // // For this example EPI0 is used with multiple pins on PortA, B, C, G, H, // K, L, M and N. The actual port and pins used may be different on your // part, consult the data sheet for more information. // TODO: Update based upon the EPI pin assignment on your target part. // SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOG); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOK); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOL); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOM); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPION); // // This step configures the internal pin muxes to set the EPI pins for use // with EPI. Please refer to the datasheet for more information about pin // muxing. Note that EPI0S27:20 are not used for the EPI SDRAM // implementation. // TODO: Update this section based upon the EPI pin assignment on your // target part. // // // EPI0S4 ~ EPI0S7: C4 ~ 7 // ui32Val = HWREG(GPIO_PORTC_BASE + GPIO_O_PCTL); ui32Val &= 0x0000FFFF; ui32Val |= 0xFFFF0000; HWREG(GPIO_PORTC_BASE + GPIO_O_PCTL) = ui32Val; // // EPI0S8 ~ EPI0S9: A6 ~ 7 // ui32Val = HWREG(GPIO_PORTA_BASE + GPIO_O_PCTL); ui32Val &= 0x00FFFFFF; ui32Val |= 0xFF000000; HWREG(GPIO_PORTA_BASE + GPIO_O_PCTL) = ui32Val; // // EPI0S10 ~ EPI0S11: G0 ~ 1 // ui32Val = HWREG(GPIO_PORTG_BASE + GPIO_O_PCTL); ui32Val &= 0xFFFFFF00; ui32Val |= 0x000000FF; HWREG(GPIO_PORTG_BASE + GPIO_O_PCTL) = ui32Val; // // EPI0S12 ~ EPI0S15: M0 ~ 3 // ui32Val = HWREG(GPIO_PORTM_BASE + GPIO_O_PCTL); ui32Val &= 0xFFFF0000; ui32Val |= 0x0000FFFF; HWREG(GPIO_PORTM_BASE + GPIO_O_PCTL) = ui32Val; // // EPI0S16 ~ EPI0S19: L0 ~ 3 // ui32Val = HWREG(GPIO_PORTL_BASE + GPIO_O_PCTL); ui32Val &= 0xFFFF0000; ui32Val |= 0x0000FFFF; HWREG(GPIO_PORTL_BASE + GPIO_O_PCTL) = ui32Val; // // EPI0S28 : B3 // ui32Val = HWREG(GPIO_PORTB_BASE + GPIO_O_PCTL); ui32Val &= 0xFFFF0FFF; ui32Val |= 0x0000F000; HWREG(GPIO_PORTB_BASE + GPIO_O_PCTL) = ui32Val; // // EPI0S29 ~ EPI0S30: N2 ~ 3 // ui32Val = HWREG(GPIO_PORTN_BASE + GPIO_O_PCTL); ui32Val &= 0xFFFF00FF; ui32Val |= 0x0000FF00; HWREG(GPIO_PORTN_BASE + GPIO_O_PCTL) = ui32Val; // // EPI0S00 ~ EPI0S03, EPI0S31 : K0 ~ 3, K5 // ui32Val = HWREG(GPIO_PORTK_BASE + GPIO_O_PCTL); ui32Val &= 0xFF0F0000; ui32Val |= 0x00F0FFFF; HWREG(GPIO_PORTK_BASE + GPIO_O_PCTL) = ui32Val; // // Configure the GPIO pins for EPI mode. All the EPI pins require 8mA // drive strength in push-pull operation. This step also gives control of // pins to the EPI module. // GPIOPinTypeEPI(GPIO_PORTA_BASE, EPI_PORTA_PINS); GPIOPinTypeEPI(GPIO_PORTB_BASE, EPI_PORTB_PINS); GPIOPinTypeEPI(GPIO_PORTC_BASE, EPI_PORTC_PINS); GPIOPinTypeEPI(GPIO_PORTG_BASE, EPI_PORTG_PINS); GPIOPinTypeEPI(GPIO_PORTK_BASE, EPI_PORTK_PINS); GPIOPinTypeEPI(GPIO_PORTL_BASE, EPI_PORTL_PINS); GPIOPinTypeEPI(GPIO_PORTM_BASE, EPI_PORTM_PINS); GPIOPinTypeEPI(GPIO_PORTN_BASE, EPI_PORTN_PINS); // // Is our current system clock faster than we can drive the SDRAM clock? // if(ui32SysClock > 60000000) { // // Yes. Set the EPI clock to half the system clock. // EPIDividerSet(EPI0_BASE, 1); } else { // // With a system clock of 60MHz or lower, we can drive the SDRAM at // the same rate so set the divider to 0. // EPIDividerSet(EPI0_BASE, 0); } // // Sets the usage mode of the EPI module. For this example we will use // the SDRAM mode to talk to the external 64MB SDRAM daughter card. // EPIModeSet(EPI0_BASE, EPI_MODE_SDRAM); // // Keep the compiler happy by setting a default value for the frequency // flag. // ui32Freq = g_psSDRAMFreq[NUM_SDRAM_FREQ - 1].ui32FreqFlag; // // Examine the system clock frequency to determine how to set the SDRAM // controller's frequency flag. // for(ui32Val = 0; ui32Val < NUM_SDRAM_FREQ; ui32Val++) { // // Is the system clock frequency above the break point in the table? // if(ui32SysClock >= g_psSDRAMFreq[ui32Val].ui32SysClock) { // // Yes - remember the frequency flag to use and exit the loop. // ui32Freq = g_psSDRAMFreq[ui32Val].ui32FreqFlag; break; } } // // Configure the SDRAM mode. We configure the SDRAM according to our core // clock frequency. We will use the normal (or full power) operating // state which means we will not use the low power self-refresh state. // Set the SDRAM size to 64MB with a refresh interval of 1024 clock ticks. // EPIConfigSDRAMSet(EPI0_BASE, (ui32Freq | EPI_SDRAM_FULL_POWER | EPI_SDRAM_SIZE_512MBIT), 1024); // // Set the address map. The EPI0 is mapped from 0x60000000 to 0x01FFFFFF. // For this example, we will start from a base address of 0x60000000 with // a size of 256MB. Although our SDRAM is only 64MB, there is no 64MB // aperture option so we pick the next larger size. // EPIAddressMapSet(EPI0_BASE, EPI_ADDR_RAM_SIZE_256MB | EPI_ADDR_RAM_BASE_6); // // Wait for the SDRAM wake-up to complete by polling the SDRAM // initialization sequence bit. This bit is true when the SDRAM interface // is going through the initialization and false when the SDRAM interface // it is not in a wake-up period. // while(HWREG(EPI0_BASE + EPI_O_STAT) & EPI_STAT_INITSEQ) { } // // Set the EPI memory pointer to the base of EPI memory space. Note that // g_pui16EPISdram is declared as volatile so the compiler should not // optimize reads out of the memory. With this pointer, the memory space // is accessed like a simple array. // g_pui16EPISdram = (uint16_t *)0x60000000; // // Read the initial data in SDRAM, and display it on the console. // UARTprintf(" SDRAM Initial Data:\n"); UARTprintf(" Mem[0x6000.0000] = 0x%4x\n", g_pui16EPISdram[SDRAM_START_ADDRESS]); UARTprintf(" Mem[0x6000.0001] = 0x%4x\n", g_pui16EPISdram[SDRAM_START_ADDRESS + 1]); UARTprintf(" Mem[0x603F.FFFE] = 0x%4x\n", g_pui16EPISdram[SDRAM_END_ADDRESS - 1]); UARTprintf(" Mem[0x603F.FFFF] = 0x%4x\n\n", g_pui16EPISdram[SDRAM_END_ADDRESS]); // // Display what writes we are doing on the console. // UARTprintf(" SDRAM Write:\n"); UARTprintf(" Mem[0x6000.0000] <- 0xabcd\n"); UARTprintf(" Mem[0x6000.0001] <- 0x1234\n"); UARTprintf(" Mem[0x603F.FFFE] <- 0xdcba\n"); UARTprintf(" Mem[0x603F.FFFF] <- 0x4321\n\n"); // // Write to the first 2 and last 2 address of the SDRAM card. Since the // SDRAM card is word addressable, we will write words. // g_pui16EPISdram[SDRAM_START_ADDRESS] = 0xabcd; g_pui16EPISdram[SDRAM_START_ADDRESS + 1] = 0x1234; g_pui16EPISdram[SDRAM_END_ADDRESS - 1] = 0xdcba; g_pui16EPISdram[SDRAM_END_ADDRESS] = 0x4321; // // Read back the data you wrote, and display it on the console. // UARTprintf(" SDRAM Read:\n"); UARTprintf(" Mem[0x6000.0000] = 0x%4x\n", g_pui16EPISdram[SDRAM_START_ADDRESS]); UARTprintf(" Mem[0x6000.0001] = 0x%4x\n", g_pui16EPISdram[SDRAM_START_ADDRESS + 1]); UARTprintf(" Mem[0x603F.FFFE] = 0x%4x\n", g_pui16EPISdram[SDRAM_END_ADDRESS - 1]); UARTprintf(" Mem[0x603F.FFFF] = 0x%4x\n\n", g_pui16EPISdram[SDRAM_END_ADDRESS]); // // Check the validity of the data. // if((g_pui16EPISdram[SDRAM_START_ADDRESS] == 0xabcd) && (g_pui16EPISdram[SDRAM_START_ADDRESS + 1] == 0x1234) && (g_pui16EPISdram[SDRAM_END_ADDRESS - 1] == 0xdcba) && (g_pui16EPISdram[SDRAM_END_ADDRESS] == 0x4321)) { // // Read and write operations were successful. Return with no errors. // UARTprintf("Read and write to external SDRAM was successful!\n"); return(0); } // // Display on the console that there was an error. // UARTprintf("Read and/or write failure!"); UARTprintf(" Check if your SDRAM card is plugged in."); // // Read and/or write operations were unsuccessful. Wait in while(1) loop // for debugging. // while(1) { } }
/* * main.c */ int main(void) { float fTemperature, fHumidity; int32_t i32IntegerPart; int32_t i32FractionPart; g_ui32SysClock = SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 120000000); //confiugre the GPIO pins PinoutSet(false,false); ConfigureUART(); //configure I2C pins SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C8); GPIOPinConfigure(GPIO_PA2_I2C8SCL); GPIOPinConfigure(GPIO_PA3_I2C8SDA); GPIOPinTypeI2C(GPIO_PORTA_BASE,GPIO_PIN_2); GPIOPinTypeI2C(GPIO_PORTA_BASE,GPIO_PIN_3); //enable interrupts IntMasterEnable(); //initialize I2C I2CMInit(&g_sI2CInst,I2C8_BASE,INT_I2C8,0xff,0xff,g_ui32SysClock); IntPrioritySet(INT_I2C7,0xE0); //initialize the sensors SHT21Init(&g_sSHT21Inst, &g_sI2CInst, SHT21_I2C_ADDRESS, SHT21AppCallback,&g_sSHT21Inst); //delay for 20 ms SysCtlDelay(g_ui32SysClock / (50 * 3)); while(1){ // // Turn on D2 to show we are starting a transaction with the sensor. // This is turned off in the application callback. // LEDWrite(CLP_D1 | CLP_D2 , CLP_D2); // // Write the command to start a humidity measurement. // SHT21Write(&g_sSHT21Inst, SHT21_CMD_MEAS_RH, g_sSHT21Inst.pui8Data, 0, SHT21AppCallback, &g_sSHT21Inst); // // Wait for the I2C transactions to complete before moving forward. // SHT21AppI2CWait(__FILE__, __LINE__); // // Wait 33 milliseconds before attempting to get the result. Datasheet // claims this can take as long as 29 milliseconds. // SysCtlDelay(g_ui32SysClock / (30 * 3)); // // Turn on D2 to show we are starting a transaction with the sensor. // This is turned off in the application callback. // LEDWrite(CLP_D1 | CLP_D2 , CLP_D2); // // Get the raw data from the sensor over the I2C bus. // SHT21DataRead(&g_sSHT21Inst, SHT21AppCallback, &g_sSHT21Inst); // // Wait for the I2C transactions to complete before moving forward. // SHT21AppI2CWait(__FILE__, __LINE__); // // Get a copy of the most recent raw data in floating point format. // SHT21DataHumidityGetFloat(&g_sSHT21Inst, &fHumidity); // // Turn on D2 to show we are starting a transaction with the sensor. // This is turned off in the application callback. // LEDWrite(CLP_D1 | CLP_D2 , CLP_D2); // // Write the command to start a temperature measurement. // SHT21Write(&g_sSHT21Inst, SHT21_CMD_MEAS_T, g_sSHT21Inst.pui8Data, 0, SHT21AppCallback, &g_sSHT21Inst); // // Wait for the I2C transactions to complete before moving forward. // SHT21AppI2CWait(__FILE__, __LINE__); // // Wait 100 milliseconds before attempting to get the result. Datasheet // claims this can take as long as 85 milliseconds. // SysCtlDelay(g_ui32SysClock / (10 * 3)); // // Turn on D2 to show we are starting a transaction with the sensor. // This is turned off in the application callback. // LEDWrite(CLP_D1 | CLP_D2 , CLP_D2); // // Read the conversion data from the sensor over I2C. // SHT21DataRead(&g_sSHT21Inst, SHT21AppCallback, &g_sSHT21Inst); // // Wait for the I2C transactions to complete before moving forward. // SHT21AppI2CWait(__FILE__, __LINE__); // // Get the most recent temperature result as a float in celcius. // SHT21DataTemperatureGetFloat(&g_sSHT21Inst, &fTemperature); // // Convert the floats to an integer part and fraction part for easy // print. Humidity is returned as 0.0 to 1.0 so multiply by 100 to get // percent humidity. // fHumidity *= 100.0f; i32IntegerPart = (int32_t) fHumidity; i32FractionPart = (int32_t) (fHumidity * 1000.0f); i32FractionPart = i32FractionPart - (i32IntegerPart * 1000); if(i32FractionPart < 0) { i32FractionPart *= -1; } // // Print the humidity value using the integers we just created. // UARTprintf("Humidity %3d.%03d\t", i32IntegerPart, i32FractionPart); // // Perform the conversion from float to a printable set of integers. // i32IntegerPart = (int32_t) fTemperature; i32FractionPart = (int32_t) (fTemperature * 1000.0f); i32FractionPart = i32FractionPart - (i32IntegerPart * 1000); if(i32FractionPart < 0) { i32FractionPart *= -1; } // // Print the temperature as integer and fraction parts. // UARTprintf("Temperature %3d.%03d\n", i32IntegerPart, i32FractionPart); // // Delay for one second. This is to keep sensor duty cycle // to about 10% as suggested in the datasheet, section 2.4. // This minimizes self heating effects and keeps reading more accurate. // SysCtlDelay(g_ui32SysClock / 3); } return 0; }
//***************************************************************************** // // Print "Hello World!" to the display on the Intelligent Display Module. // //***************************************************************************** int main(void) { tContext sContext; uint32_t ui32SysClock; uint32_t i; uint32_t reg_read; // // Run from the PLL at 120 MHz. // /* ui32SysClock = SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_SYSDIV_10 | //Needed for ADC SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 120000000); */ ui32SysClock = SysCtlClockFreqSet(( SYSCTL_SYSDIV_10 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_25MHZ), 120000000); // // Configure the device pins. // PinoutSet(); GPIOPinTypeGPIOOutput(GPIO_PORTL_BASE, GPIO_PIN_1); //OUT 0 L1 GPIOPinTypeGPIOOutput(GPIO_PORTL_BASE, GPIO_PIN_0); //OUT 1 L0 GPIOPinTypeGPIOOutput(GPIO_PORTL_BASE, GPIO_PIN_2); //OUT 2 L2 GPIOPinTypeGPIOOutput(GPIO_PORTL_BASE, GPIO_PIN_3); //OUT 3 L3 GPIOPinTypeGPIOOutput(GPIO_PORTL_BASE, GPIO_PIN_4); //OUT 4 L4 GPIOPinTypeGPIOOutput(GPIO_PORTL_BASE, GPIO_PIN_5); //OUT 5 L5 GPIOPinTypeGPIOOutput(GPIO_PORTP_BASE, GPIO_PIN_5); //OUT 6 P5 GPIOPinTypeGPIOOutput(GPIO_PORTP_BASE, GPIO_PIN_4); //OUT 7 P4 GPIOPinTypeGPIOInput (GPIO_PORTM_BASE, GPIO_PIN_3); //IN 0 M3 GPIOPinTypeGPIOInput (GPIO_PORTM_BASE, GPIO_PIN_2); //IN 1 M2 GPIOPinTypeGPIOInput (GPIO_PORTM_BASE, GPIO_PIN_1); //IN 2 M1 GPIOPinTypeGPIOInput (GPIO_PORTM_BASE, GPIO_PIN_0); //IN 3 M0 GPIOPinTypeGPIOInput (GPIO_PORTN_BASE, GPIO_PIN_4); //IN 4 N4 GPIOPinTypeGPIOInput (GPIO_PORTA_BASE, GPIO_PIN_7); //IN 5 A7 GPIOPinTypeGPIOInput (GPIO_PORTC_BASE, GPIO_PIN_6); //IN 6 C6 GPIOPinTypeGPIOInput (GPIO_PORTC_BASE, GPIO_PIN_5); //IN 7 C5 //RGB LED GPIOPinTypeGPIOOutput(GPIO_PORTN_BASE, GPIO_PIN_5); //RED N5 GPIOPinTypeGPIOOutput(GPIO_PORTQ_BASE, GPIO_PIN_7); //GREEN Q7 GPIOPinTypeGPIOOutput(GPIO_PORTQ_BASE, GPIO_PIN_4); //BLUE Q4 //Initialize the UART QUT_UART_Init( ui32SysClock ); //Initialize AIN0 QUT_ADC0_Init(); // // Initialize the display driver. // Kentec320x240x16_SSD2119Init(ui32SysClock); // // Initialize the graphics context. // GrContextInit(&sContext, &g_sKentec320x240x16_SSD2119); // // Draw the application frame. // FrameDraw(&sContext, "FestoTester"); // // Initialize the touch screen driver. // TouchScreenInit(ui32SysClock); // // Set the touch screen event handler. // TouchScreenCallbackSet(WidgetPointerMessage); // // Add the compile-time defined widgets to the widget tree. // WidgetAdd(WIDGET_ROOT, (tWidget *)&g_sBackground); // // Paint the widget tree to make sure they all appear on the display. // WidgetPaint(WIDGET_ROOT); QUT_UART_Send( (uint8_t *)"FestoTester", 11 ); // // Loop forever, processing widget messages. // while(1) { // // Process any messages from or for the widgets. // WidgetMessageQueueProcess(); //Turn on RED LED GPIO_PORTN_DATA_R |= 0x20; //Check GPIO Inputs for( i = 0; i < 8; i++ ) { input_status[i] = 0; reg_read = qut_get_gpio( i ); if ( reg_read != 0 ){ input_status[i] = INPUT_STATUS_IS_ONE; } } //Read the ADC0 adc0_read = QUT_ADC0_Read(); QUT_UART_Send( (uint8_t *)"\n\radc0_read=", 12 ); QUT_UART_Send_uint32_t( adc0_read ); //Relimit the ADC read from 0 to 4096 into a pixel limit from 0 to 280 num_analog_pixels = (adc0_read * 280 ) / 4096; //UARTprintf("num_analog_pixels = %4d\r", num_analog_pixels ); //QUT_UART_Send( (uint8_t *)"\rnum_analog_pixels=", 19 ); //QUT_UART_Send_uint32_t( num_analog_pixels ); //qut_delay_secs(1); //Repaint the screen WidgetPaint(WIDGET_ROOT); } }
//***************************************************************************** // // Configue UART in internal loopback mode and tranmsit and receive data // internally. // //***************************************************************************** int main(void) { #if defined(TARGET_IS_TM4C129_RA0) || \ defined(TARGET_IS_TM4C129_RA1) || \ defined(TARGET_IS_TM4C129_RA2) uint32_t ui32SysClock; #endif uint8_t ui8DataTx[NUM_UART_DATA]; uint8_t ui8DataRx[NUM_UART_DATA]; uint32_t ui32index; // // Set the clocking to run directly from the crystal. // #if defined(TARGET_IS_TM4C129_RA0) || \ defined(TARGET_IS_TM4C129_RA1) || \ defined(TARGET_IS_TM4C129_RA2) ui32SysClock = SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_OSC), 25000000); #else MAP_SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); #endif // // Enable the peripherals used by this example. // UART0 : To dump information to the console about the example. // UART7 : Enabled in loopback mode. Anything transmitted to Tx will be // received at the Rx. // MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0); MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART7); MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); // // Set GPIO A0 and A1 as UART pins. // GPIOPinConfigure(GPIO_PA0_U0RX); GPIOPinConfigure(GPIO_PA1_U0TX); MAP_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1); // // Internal loopback programming. Configure the UART in loopback mode. // UARTLoopbackEnable(UART7_BASE); // // Configure the UART for 115,200, 8-N-1 operation. // #if defined(TARGET_IS_TM4C129_RA0) || \ defined(TARGET_IS_TM4C129_RA1) || \ defined(TARGET_IS_TM4C129_RA2) MAP_UARTConfigSetExpClk(UART0_BASE, ui32SysClock, 115200, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE)); MAP_UARTConfigSetExpClk(UART7_BASE, ui32SysClock, 115200, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE)); #else MAP_UARTConfigSetExpClk(UART0_BASE, MAP_SysCtlClockGet(), 115200, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE)); MAP_UARTConfigSetExpClk(UART7_BASE, MAP_SysCtlClockGet(), 115200, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE)); #endif // // Print banner after clearing the terminal. // UARTSend(UART0_BASE, (uint8_t *)"\033[2J\033[1;1H", 10); UARTSend(UART0_BASE, (uint8_t *)"\nUART Loopback Example ->", strlen("\nUART Loopback Example ->")); // // Prepare data to send over the UART configured for internal loopback. // ui8DataTx[0] = 'u'; ui8DataTx[1] = 'a'; ui8DataTx[2] = 'r'; ui8DataTx[3] = 't'; // // Inform user that data is being sent over for internal loopback. // UARTSend(UART0_BASE, (uint8_t *)"\n\n\rSending : ", strlen("\n\n\rSending : ")); UARTSend(UART0_BASE, (uint8_t*)ui8DataTx, NUM_UART_DATA); // // Send the data, which was prepared above, over the UART configured for // internal loopback operation. // for(ui32index = 0 ; ui32index < NUM_UART_DATA ; ui32index++) { UARTCharPut(UART7_BASE, ui8DataTx[ui32index]); } // // Wait for the UART module to complete transmitting. // while(MAP_UARTBusy(UART7_BASE)) { } // // Inform user that data the loopback data is being received. // UARTSend(UART0_BASE, (uint8_t *)"\n\rReceiving : ", strlen("\n\rReceiving : ")); // // Read data from the UART's receive FIFO and store it. // for(ui32index = 0 ; ui32index < NUM_UART_DATA ; ui32index++) { // // Get the data received by the UART at its receive FIFO // ui8DataRx[ui32index] = UARTCharGet(UART7_BASE); } // // Display the data received, after loopback, over UART's receive FIFO. // UARTSend(UART0_BASE, (uint8_t*)ui8DataRx, NUM_UART_DATA); // // Return no errors // return(0); }
//***************************************************************************** // // This application performs simple audio synthesis and playback based on the // keys pressed on the touch screen virtual piano keyboard. // //***************************************************************************** int main(void) { uint32_t ui32SysClock, ui32OldKey, ui32NewKey; tContext sContext; // // Run from the PLL at 120 MHz. // ui32SysClock = SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 120000000); // // Configure the device pins. // PinoutSet(); // // Initialize the display driver. // Kentec320x240x16_SSD2119Init(ui32SysClock); // // Initialize the graphics context. // GrContextInit(&sContext, &g_sKentec320x240x16_SSD2119); // // Draw the application frame. // FrameDraw(&sContext, "synth"); // // Draw the keys on the virtual piano keyboard. // DrawWhiteKeys(&sContext); DrawBlackKeys(&sContext); // // Initialize the touch screen driver. // TouchScreenInit(ui32SysClock); TouchScreenCallbackSet(TouchCallback); // // Initialize the sound driver. // SoundInit(ui32SysClock); SoundVolumeSet(128); SoundStart(g_pi16AudioBuffer, AUDIO_SIZE, 64000, SoundCallback); // // Default the old and new key to not pressed so that the first key press // will be properly drawn on the keyboard. // ui32OldKey = NUM_WHITE_KEYS + NUM_BLACK_KEYS; ui32NewKey = NUM_WHITE_KEYS + NUM_BLACK_KEYS; // // Loop forever. // while(1) { // // See if the first half of the sound buffer needs to be filled. // if(HWREGBITW(&g_ui32Flags, FLAG_PING) == 1) { // // Synthesize new audio into the first half of the sound buffer. // ui32NewKey = GenerateAudio(g_pi16AudioBuffer, AUDIO_SIZE / 2); // // Clear the flag for the first half of the sound buffer. // HWREGBITW(&g_ui32Flags, FLAG_PING) = 0; } // // See if the second half of the sound buffer needs to be filled. // if(HWREGBITW(&g_ui32Flags, FLAG_PONG) == 1) { // // Synthesize new audio into the second half of the sound buffer. // ui32NewKey = GenerateAudio(g_pi16AudioBuffer + (AUDIO_SIZE / 2), AUDIO_SIZE / 2); // // Clear the flag for the second half of the sound buffer. // HWREGBITW(&g_ui32Flags, FLAG_PONG) = 0; } // // See if a different key has been pressed. // if(ui32OldKey != ui32NewKey) { // // See if the old key was a white key. // if(ui32OldKey < NUM_WHITE_KEYS) { // // Redraw the face of the white key so that it no longer shows // as being pressed. // FillWhiteKey(&sContext, ui32OldKey, ClrWhiteKey); } // // See if the old key was a black key. // else if(ui32OldKey < (NUM_WHITE_KEYS + NUM_BLACK_KEYS)) { // // Redraw the face of the black key so that it no longer shows // as being pressed. // FillBlackKey(&sContext, ui32OldKey - NUM_WHITE_KEYS, ClrBlackKey); } // // See if the new key is a white key. // if(ui32NewKey < NUM_WHITE_KEYS) { // // Redraw the face of the white key so that it is shown as // being pressed. // FillWhiteKey(&sContext, ui32NewKey, ClrPressed); } // // See if the new key is a black key. // else if(ui32NewKey < (NUM_WHITE_KEYS + NUM_BLACK_KEYS)) { // // Redraw the face of the black key so that it is shown as // being pressed. // FillBlackKey(&sContext, ui32NewKey - NUM_WHITE_KEYS, ClrPressed); } // // Save the new key as the old key. // ui32OldKey = ui32NewKey; } } }
//***************************************************************************** // // Configure Timer0B as a 16-bit periodic counter with an interrupt // every 1ms. // //***************************************************************************** int main(void) { #if defined(TARGET_IS_TM4C129_RA0) || \ defined(TARGET_IS_TM4C129_RA1) || \ defined(TARGET_IS_TM4C129_RA2) uint32_t ui32SysClock; #endif uint32_t ui32PrevCount = 0; // // Set the clocking to run directly from the external crystal/oscillator. // TODO: The SYSCTL_XTAL_ value must be changed to match the value of the // crystal on your board. // #if defined(TARGET_IS_TM4C129_RA0) || \ defined(TARGET_IS_TM4C129_RA1) || \ defined(TARGET_IS_TM4C129_RA2) ui32SysClock = SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_OSC), 25000000); #else SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); #endif // // The Timer0 peripheral must be enabled for use. // SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0); // // Set up the serial console to use for displaying messages. This is // just for this example program and is not needed for Timer operation. // InitConsole(); // // Display the example setup on the console. // UARTprintf("16-Bit Timer Interrupt ->"); UARTprintf("\n Timer = Timer0B"); UARTprintf("\n Mode = Periodic"); UARTprintf("\n Number of interrupts = %d", NUMBER_OF_INTS); UARTprintf("\n Rate = 1ms\n\n"); // // Configure Timer0B as a 16-bit periodic timer. // TimerConfigure(TIMER0_BASE, TIMER_CFG_SPLIT_PAIR | TIMER_CFG_B_PERIODIC); // // Set the Timer0B load value to 1ms. // #if defined(TARGET_IS_TM4C129_RA0) || \ defined(TARGET_IS_TM4C129_RA1) || \ defined(TARGET_IS_TM4C129_RA2) TimerLoadSet(TIMER0_BASE, TIMER_B, ui32SysClock / 1000); #else TimerLoadSet(TIMER0_BASE, TIMER_B, SysCtlClockGet() / 1000); #endif // // Enable processor interrupts. // IntMasterEnable(); // // Configure the Timer0B interrupt for timer timeout. // TimerIntEnable(TIMER0_BASE, TIMER_TIMB_TIMEOUT); // // Enable the Timer0B interrupt on the processor (NVIC). // IntEnable(INT_TIMER0B); // // Initialize the interrupt counter. // g_ui32Counter = 0; // // Enable Timer0B. // TimerEnable(TIMER0_BASE, TIMER_B); // // Loop forever while the Timer0B runs. // while(1) { // // If the interrupt count changed, print the new value // if(ui32PrevCount != g_ui32Counter) { // // Print the periodic interrupt counter. // UARTprintf("Number of interrupts: %d\r", g_ui32Counter); ui32PrevCount = g_ui32Counter; } } }
//***************************************************************************** // // The program main function. It performs initialization, then runs a command // processing loop to read commands from the console. // //***************************************************************************** int main(void) { // int nStatus; FRESULT iFResult; // tRectangle sRect; // // Enable the GPIO port that is used for the on-board LED. // SysCtlPeripheralEnable(SYSCTL_PERIPH_GPION); // // Check if the peripheral access is enabled. // while(!SysCtlPeripheralReady(SYSCTL_PERIPH_GPION)) { } // // Enable the GPIO pin for the LED (PN0). Set the direction as output, and // enable the GPIO pin for digital function. // GPIOPinTypeGPIOOutput(GPIO_PORTN_BASE, GPIO_PIN_0); volatile uint32_t ui32Loop; int counter = 2; // // Enable lazy stacking for interrupt handlers. This allows floating-point // instructions to be used within interrupt handlers, but at the expense of // extra stack usage. // MAP_FPULazyStackingEnable(); // // Set the system clock to run at 50MHz from the PLL. // g_ui32SysClock = SysCtlClockFreqSet (SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ,50000000); // // Enable the peripherals used by this example. // MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_SSI3); // // Configure SysTick for a 100Hz interrupt. The FatFs driver wants a 10 ms // tick. // MAP_SysTickPeriodSet(g_ui32SysClock / 100); MAP_SysTickEnable(); MAP_SysTickIntEnable(); // // Enable Interrupts // MAP_IntMasterEnable(); // Mount the file system, using logical disk 0. // iFResult = f_mount(0, &g_sFatFs); iFResult = f_open(&g_sFileObject, "testFile.txt", (FA_OPEN_ALWAYS | FA_WRITE)); while(counter > 0){ GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_0, GPIO_PIN_0); for(ui32Loop = 0; ui32Loop < 200000; ui32Loop++) { } // // Turn off the LED. // GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_0, 0x0); // // Delay for a bit. // for(ui32Loop = 0; ui32Loop < 200000; ui32Loop++) { } counter--; } if(iFResult != FR_OK) { return(1); } }
//***************************************************************************** // // This example application demonstrates the use of the timers to generate // periodic interrupts. // //***************************************************************************** int main(void) { #if defined(TARGET_IS_TM4C129_RA0) || \ defined(TARGET_IS_TM4C129_RA1) || \ defined(TARGET_IS_TM4C129_RA2) uint32_t ui32SysClock; #endif // // Enable lazy stacking for interrupt handlers. This allows floating-point // instructions to be used within interrupt handlers, but at the expense of // extra stack usage. // ROM_FPULazyStackingEnable(); // // Set the clocking to run directly from the crystal. // TODO: Set the system clock appropriately for your application. // #if defined(TARGET_IS_TM4C129_RA0) || \ defined(TARGET_IS_TM4C129_RA1) || \ defined(TARGET_IS_TM4C129_RA2) ui32SysClock = SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_OSC), 25000000); #else ROM_SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); #endif // // Initialize the display on the board. This is not directly related // to the timer operation but makes it easier to see what's going on // when you run this on an EK-LM4F232 board. // // TODO: Remove or replace this call with something appropriate for // your hardware. // InitDisplay(); // // Enable the peripherals used by this example. // // TODO: Update this depending upon the general purpose timer and // CCP pin you intend using. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER4); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOM); // // Configure PM0 as the CCP0 pin for timer 4. // // TODO: This is set up to use GPIO PM0 which can be configured // as the CCP0 pin for Timer4 and also happens to be attached to // a switch on the EK-LM4F232 board. Change this configuration to // correspond to the correct pin for your application. // ROM_GPIOPinTypeTimer(GPIO_PORTM_BASE, GPIO_PIN_0); GPIOPinConfigure(GPIO_PM0_T4CCP0); // // Set the pin to use the internal pull-up. // // TODO: Remove or replace this call to correspond to the wiring // of the CCP pin you are using. If your board has an external // pull-up or pull-down, this will not be required. // MAP_GPIOPadConfigSet(GPIO_PORTM_BASE, GPIO_PIN_0, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); // // Enable processor interrupts. // ROM_IntMasterEnable(); // // Configure the timers in downward edge count mode. // // TODO: Modify this to configure the specific general purpose // timer you are using. The timer choice is intimately tied to // the pin whose edges you want to capture because specific CCP // pins are connected to specific timers. // ROM_TimerConfigure(TIMER4_BASE, (TIMER_CFG_SPLIT_PAIR | TIMER_CFG_A_CAP_COUNT)); ROM_TimerControlEvent(TIMER4_BASE, TIMER_A, TIMER_EVENT_POS_EDGE); ROM_TimerLoadSet(TIMER4_BASE, TIMER_A, 9); ROM_TimerMatchSet(TIMER4_BASE, TIMER_A, 0); // // Setup the interrupt for the edge capture timer. Note that we // use the capture match interrupt and NOT the timeout interrupt! // // TODO: Modify to enable the specific timer you are using. // ROM_IntEnable(INT_TIMER4A); ROM_TimerIntEnable(TIMER4_BASE, TIMER_CAPA_MATCH); // // Enable the timer. // // TODO: Modify to enable the specific timer you are using. // ROM_TimerEnable(TIMER4_BASE, TIMER_A); // // At this point, the timer will count down every time a positive // edge is detected on the relevant pin. When the count reaches // 0, the timer count reloads, the interrupt fires and the timer // is disabled. The ISR can then restart the timer if required. // MainLoopRun(); }
//***************************************************************************** // // Configure SSI0 in master Freescale (SPI) mode. This example will send out // 3 bytes of data, then wait for 3 bytes of data to come in. This will all be // done using the polling method. // //***************************************************************************** int main(void) { #if defined(TARGET_IS_TM4C129_RA0) || \ defined(TARGET_IS_TM4C129_RA1) || \ defined(TARGET_IS_TM4C129_RA2) #endif // // Set the clocking to run directly from the external crystal/oscillator. // TODO: The SYSCTL_XTAL_ value must be changed to match the value of the // crystal on your board. // #if defined(TARGET_IS_TM4C129_RA0) || \ defined(TARGET_IS_TM4C129_RA1) || \ defined(TARGET_IS_TM4C129_RA2) SysCtlClockFreqSet(SYSCTL_OSC_INT | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_320, CLOCK_RATE); #else SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); #endif BOOL8 fPrintErrorMessage = TRUE; /* * initializing spi */ SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOG); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOK); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOL); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOM); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOP); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOQ); io_init(); iADI_err=adis_init(); SysCtlDelay(800000); while(1) { switch( ABCCPowerState ) { case ABCCPOWER_RESET: ABCC_SYS_HWReset(); ABCCPowerState = ABCCPOWER_STARTDRIVER; break; case ABCCPOWER_STARTDRIVER: if( ABCC_StartDriver( ABCC_GetOpmode(), FALSE ) == ABCC_OK ) { ABCCPowerState = ABCCPOWER_RESETRELEASE; } break; case ABCCPOWER_RESETRELEASE: ABCC_HWReleaseReset(); ABCCPowerState = ABCCPOWER_WAITCOM; break; case ABCCPOWER_WAITCOM: if( ABCC_isReadyForCommunication() ) { AD_NewWrPd(); ABCCPowerState = ABCCPOWER_RUNNING; } break; case ABCCPOWER_RUNNING: if( fResetABCC ) { fResetABCC = FALSE; ABCCPowerState = ABCCPOWER_RESETREQ; break; } /* ** Check if an exception has occurred and prints out the exception code and info. */ int ali= ABCC_AnbState(); if(ali==4){ int ali= ABCC_AnbState(); } if( ( ali== ABP_ANB_STATE_EXCEPTION ) ) /* An error has occurred. */ { if( fPrintErrorMessage ) { ABP_MsgType* psANBMsgCmd; ABP_MsgType* psNWMsgCmd; psANBMsgCmd = ABCC_MsgAlloc(); ABCC_GetAttribute( psANBMsgCmd, ABP_OBJ_NUM_ANB, 1, ABP_ANB_IA_EXCEPTION, US_ANB_EXC_SRC_ID ); ABCC_SendCmdMsg( psANBMsgCmd, PrintException ); psNWMsgCmd = ABCC_MsgAlloc(); ABCC_GetAttribute( psNWMsgCmd, ABP_OBJ_NUM_NW, 1, ABP_NW_IA_EXCEPTION_INFO, US_NW_EXC_SRC_ID ); ABCC_SendCmdMsg( psNWMsgCmd, PrintException ); fPrintErrorMessage = FALSE; } } else /* No error. */ { fPrintErrorMessage = TRUE; } /* ** This function runs the driver and must be called cyclically. ** Typcally this function is called from the main loop. */ ABCC_RunDriver(); break; case ABCCPOWER_RESETREQ: ABCC_ShutdownDriver(); ABCCPowerState = ABCCPOWER_RESET; break; default: break; } } return(0); }
//***************************************************************************** // // Configure the CAN and enter a loop to receive CAN messages. // //***************************************************************************** int main(void) { #if defined(TARGET_IS_TM4C129_RA0) || \ defined(TARGET_IS_TM4C129_RA1) || \ defined(TARGET_IS_TM4C129_RA2) uint32_t ui32SysClock; #endif tCANMsgObject sCANMessage; uint8_t pui8MsgData[8]; // // Set the clocking to run directly from the external crystal/oscillator. // TODO: The SYSCTL_XTAL_ value must be changed to match the value of the // crystal used on your board. // #if defined(TARGET_IS_TM4C129_RA0) || \ defined(TARGET_IS_TM4C129_RA1) || \ defined(TARGET_IS_TM4C129_RA2) ui32SysClock = SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_OSC) 25000000); #else SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); #endif // // Set up the serial console to use for displaying messages. This is // just for this example program and is not needed for CAN operation. // InitConsole(); // // For this example CAN0 is used with RX and TX pins on port B4 and B5. // The actual port and pins used may be different on your part, consult // the data sheet for more information. // GPIO port B needs to be enabled so these pins can be used. // TODO: change this to whichever GPIO port you are using // SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); // // Configure the GPIO pin muxing to select CAN0 functions for these pins. // This step selects which alternate function is available for these pins. // This is necessary if your part supports GPIO pin function muxing. // Consult the data sheet to see which functions are allocated per pin. // TODO: change this to select the port/pin you are using // GPIOPinConfigure(GPIO_PB4_CAN0RX); GPIOPinConfigure(GPIO_PB5_CAN0TX); // // Enable the alternate function on the GPIO pins. The above step selects // which alternate function is available. This step actually enables the // alternate function instead of GPIO for these pins. // TODO: change this to match the port/pin you are using // GPIOPinTypeCAN(GPIO_PORTB_BASE, GPIO_PIN_4 | GPIO_PIN_5); // // The GPIO port and pins have been set up for CAN. The CAN peripheral // must be enabled. // SysCtlPeripheralEnable(SYSCTL_PERIPH_CAN0); // // Initialize the CAN controller // CANInit(CAN0_BASE); // // Set up the bit rate for the CAN bus. This function sets up the CAN // bus timing for a nominal configuration. You can achieve more control // over the CAN bus timing by using the function CANBitTimingSet() instead // of this one, if needed. // In this example, the CAN bus is set to 500 kHz. In the function below, // the call to SysCtlClockGet() or ui32SysClock is used to determine the // clock rate that is used for clocking the CAN peripheral. This can be // replaced with a fixed value if you know the value of the system clock, // saving the extra function call. For some parts, the CAN peripheral is // clocked by a fixed 8 MHz regardless of the system clock in which case // the call to SysCtlClockGet() or ui32SysClock should be replaced with // 8000000. Consult the data sheet for more information about CAN // peripheral clocking. // #if defined(TARGET_IS_TM4C129_RA0) || \ defined(TARGET_IS_TM4C129_RA1) || \ defined(TARGET_IS_TM4C129_RA2) CANBitRateSet(CAN0_BASE, ui32SysClock, 500000); #else CANBitRateSet(CAN0_BASE, SysCtlClockGet(), 500000); #endif // // Enable interrupts on the CAN peripheral. This example uses static // allocation of interrupt handlers which means the name of the handler // is in the vector table of startup code. If you want to use dynamic // allocation of the vector table, then you must also call CANIntRegister() // here. // // CANIntRegister(CAN0_BASE, CANIntHandler); // if using dynamic vectors // CANIntEnable(CAN0_BASE, CAN_INT_MASTER | CAN_INT_ERROR | CAN_INT_STATUS); // // Enable the CAN interrupt on the processor (NVIC). // IntEnable(INT_CAN0); // // Enable the CAN for operation. // CANEnable(CAN0_BASE); // // Initialize a message object to receive CAN messages with ID 0x1001. // The expected ID must be set along with the mask to indicate that all // bits in the ID must match. // sCANMessage.ui32MsgID = 0x1001; sCANMessage.ui32MsgIDMask = 0xfffff; sCANMessage.ui32Flags = (MSG_OBJ_RX_INT_ENABLE | MSG_OBJ_USE_ID_FILTER | MSG_OBJ_EXTENDED_ID); sCANMessage.ui32MsgLen = 8; // // Now load the message object into the CAN peripheral message object 1. // Once loaded the CAN will receive any messages with this CAN ID into // this message object, and an interrupt will occur. // CANMessageSet(CAN0_BASE, 1, &sCANMessage, MSG_OBJ_TYPE_RX); // // Change the ID to 0x2001, and load into message object 2 which will be // used for receiving any CAN messages with this ID. Since only the CAN // ID field changes, we don't need to reload all the other fields. // sCANMessage.ui32MsgID = 0x2001; CANMessageSet(CAN0_BASE, 2, &sCANMessage, MSG_OBJ_TYPE_RX); // // Change the ID to 0x3001, and load into message object 3 which will be // used for receiving any CAN messages with this ID. Since only the CAN // ID field changes, we don't need to reload all the other fields. // sCANMessage.ui32MsgID = 0x3001; CANMessageSet(CAN0_BASE, 3, &sCANMessage, MSG_OBJ_TYPE_RX); // // Enter loop to process received messages. This loop just checks flags // for each of the 3 expected messages. The flags are set by the interrupt // handler, and if set this loop reads out the message and displays the // contents to the console. This is not a robust method for processing // incoming CAN data and can only handle one messages at a time per message // object. If many messages are being received close together using the // same message object, then some messages may be dropped. In a real // application, some other method should be used for queuing received // messages in a way to ensure they are not lost. You can also make use // of CAN FIFO mode which will allow messages to be buffered before they // are processed. // for(;;) { // // If the flag for message object 1 is set, that means that the RX // interrupt occurred and there is a message ready to be read from // this CAN message object. // if(g_bRXFlag1) { // // Reuse the same message object that was used earlier to configure // the CAN for receiving messages. A buffer for storing the // received data must also be provided, so set the buffer pointer // within the message object. This same buffer is used for all // messages in this example, but your application could set a // different buffer each time a message is read in order to store // different messages in different buffers. // sCANMessage.pui8MsgData = pui8MsgData; // // Read the message from the CAN. Message object number 1 is used // (which is not the same thing as CAN ID). The interrupt clearing // flag is not set because this interrupt was already cleared in // the interrupt handler. // CANMessageGet(CAN0_BASE, 1, &sCANMessage, 0); // // Clear the pending message flag so that the interrupt handler can // set it again when the next message arrives. // g_bRXFlag1 = 0; // // Print information about the message just received. // PrintCANMessageInfo(&sCANMessage, 1); } // // Check for message received on message object 2. If so then // read message and print information. // if(g_bRXFlag2) { sCANMessage.pui8MsgData = pui8MsgData; CANMessageGet(CAN0_BASE, 2, &sCANMessage, 0); g_bRXFlag2 = 0; PrintCANMessageInfo(&sCANMessage, 2); } // // Check for message received on message object 3. If so then // read message and print information. // if(g_bRXFlag3) { sCANMessage.pui8MsgData = pui8MsgData; CANMessageGet(CAN0_BASE, 3, &sCANMessage, 0); g_bRXFlag3 = 0; PrintCANMessageInfo(&sCANMessage, 3); } } // // Return no errors // return(0); }
//***************************************************************************** // // Performs calibration of the touch screen. // //***************************************************************************** int main(void) { int32_t i32Idx, i32X1, i32Y1, i32X2, i32Y2, i32Count, ppi32Points[3][4]; uint32_t ui32SysClock; char pcBuffer[32]; tContext sContext; tRectangle sRect; // // Run from the PLL at 120 MHz. // ui32SysClock = SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 120000000); // // Configure the device pins. // PinoutSet(); // // Initialize the display driver. // Kentec320x240x16_SSD2119Init(ui32SysClock); // // Initialize the graphics context. // GrContextInit(&sContext, &g_sKentec320x240x16_SSD2119); // // Draw the application frame. // FrameDraw(&sContext, "calibrate"); // // Print the instructions across the middle of the screen in white with a // 20 point small-caps font. // GrContextForegroundSet(&sContext, ClrWhite); GrContextFontSet(&sContext, g_psFontCmsc20); GrStringDrawCentered(&sContext, "Touch the box", -1, GrContextDpyWidthGet(&sContext) / 2, (GrContextDpyHeightGet(&sContext) / 2) - 10, 0); // // Set the points used for calibration based on the size of the screen. // ppi32Points[0][0] = GrContextDpyWidthGet(&sContext) / 10; ppi32Points[0][1] = (GrContextDpyHeightGet(&sContext) * 2) / 10; ppi32Points[1][0] = GrContextDpyWidthGet(&sContext) / 2; ppi32Points[1][1] = (GrContextDpyHeightGet(&sContext) * 9) / 10; ppi32Points[2][0] = (GrContextDpyWidthGet(&sContext) * 9) / 10; ppi32Points[2][1] = GrContextDpyHeightGet(&sContext) / 2; // // Initialize the touch screen driver. // TouchScreenInit(ui32SysClock); // // Loop through the calibration points. // for(i32Idx = 0; i32Idx < 3; i32Idx++) { // // Fill a white box around the calibration point. // GrContextForegroundSet(&sContext, ClrWhite); sRect.i16XMin = ppi32Points[i32Idx][0] - 5; sRect.i16YMin = ppi32Points[i32Idx][1] - 5; sRect.i16XMax = ppi32Points[i32Idx][0] + 5; sRect.i16YMax = ppi32Points[i32Idx][1] + 5; GrRectFill(&sContext, &sRect); // // Flush any cached drawing operations. // GrFlush(&sContext); // // Initialize the raw sample accumulators and the sample count. // i32X1 = 0; i32Y1 = 0; i32Count = -5; // // Loop forever. This loop is explicitly broken out of when the pen is // lifted. // while(1) { // // Grab the current raw touch screen position. // i32X2 = g_i16TouchX; i32Y2 = g_i16TouchY; // // See if the pen is up or down. // if((i32X2 < g_i16TouchMin) || (i32Y2 < g_i16TouchMin)) { // // The pen is up, so see if any samples have been accumulated. // if(i32Count > 0) { // // The pen has just been lifted from the screen, so break // out of the controlling while loop. // break; } // // Reset the accumulators and sample count. // i32X1 = 0; i32Y1 = 0; i32Count = -5; // // Grab the next sample. // continue; } // // Increment the count of samples. // i32Count++; // // If the sample count is greater than zero, add this sample to the // accumulators. // if(i32Count > 0) { i32X1 += i32X2; i32Y1 += i32Y2; } } // // Save the averaged raw ADC reading for this calibration point. // ppi32Points[i32Idx][2] = i32X1 / i32Count; ppi32Points[i32Idx][3] = i32Y1 / i32Count; // // Erase the box around this calibration point. // GrContextForegroundSet(&sContext, ClrBlack); GrRectFill(&sContext, &sRect); } // // Clear the screen. // sRect.i16XMin = 0; sRect.i16YMin = 0; sRect.i16XMax = GrContextDpyWidthGet(&sContext) - 1; sRect.i16YMax = GrContextDpyHeightGet(&sContext) - 1; GrRectFill(&sContext, &sRect); // // Indicate that the calibration data is being displayed. // GrContextForegroundSet(&sContext, ClrWhite); GrStringDraw(&sContext, "Calibration data:", -1, 16, 32, 0); // // Compute and display the M0 calibration value. // usprintf(pcBuffer, "M0 = %d", (((ppi32Points[0][0] - ppi32Points[2][0]) * (ppi32Points[1][3] - ppi32Points[2][3])) - ((ppi32Points[1][0] - ppi32Points[2][0]) * (ppi32Points[0][3] - ppi32Points[2][3])))); GrStringDraw(&sContext, pcBuffer, -1, 16, 72, 0); // // Compute and display the M1 calibration value. // usprintf(pcBuffer, "M1 = %d", (((ppi32Points[0][2] - ppi32Points[2][2]) * (ppi32Points[1][0] - ppi32Points[2][0])) - ((ppi32Points[0][0] - ppi32Points[2][0]) * (ppi32Points[1][2] - ppi32Points[2][2])))); GrStringDraw(&sContext, pcBuffer, -1, 16, 92, 0); // // Compute and display the M2 calibration value. // usprintf(pcBuffer, "M2 = %d", ((((ppi32Points[2][2] * ppi32Points[1][0]) - (ppi32Points[1][2] * ppi32Points[2][0])) * ppi32Points[0][3]) + (((ppi32Points[0][2] * ppi32Points[2][0]) - (ppi32Points[2][2] * ppi32Points[0][0])) * ppi32Points[1][3]) + (((ppi32Points[1][2] * ppi32Points[0][0]) - (ppi32Points[0][2] * ppi32Points[1][0])) * ppi32Points[2][3]))); GrStringDraw(&sContext, pcBuffer, -1, 16, 112, 0); // // Compute and display the M3 calibration value. // usprintf(pcBuffer, "M3 = %d", (((ppi32Points[0][1] - ppi32Points[2][1]) * (ppi32Points[1][3] - ppi32Points[2][3])) - ((ppi32Points[1][1] - ppi32Points[2][1]) * (ppi32Points[0][3] - ppi32Points[2][3])))); GrStringDraw(&sContext, pcBuffer, -1, 16, 132, 0); // // Compute and display the M4 calibration value. // usprintf(pcBuffer, "M4 = %d", (((ppi32Points[0][2] - ppi32Points[2][2]) * (ppi32Points[1][1] - ppi32Points[2][1])) - ((ppi32Points[0][1] - ppi32Points[2][1]) * (ppi32Points[1][2] - ppi32Points[2][2])))); GrStringDraw(&sContext, pcBuffer, -1, 16, 152, 0); // // Compute and display the M5 calibration value. // usprintf(pcBuffer, "M5 = %d", ((((ppi32Points[2][2] * ppi32Points[1][1]) - (ppi32Points[1][2] * ppi32Points[2][1])) * ppi32Points[0][3]) + (((ppi32Points[0][2] * ppi32Points[2][1]) - (ppi32Points[2][2] * ppi32Points[0][1])) * ppi32Points[1][3]) + (((ppi32Points[1][2] * ppi32Points[0][1]) - (ppi32Points[0][2] * ppi32Points[1][1])) * ppi32Points[2][3]))); GrStringDraw(&sContext, pcBuffer, -1, 16, 172, 0); // // Compute and display the M6 calibration value. // usprintf(pcBuffer, "M6 = %d", (((ppi32Points[0][2] - ppi32Points[2][2]) * (ppi32Points[1][3] - ppi32Points[2][3])) - ((ppi32Points[1][2] - ppi32Points[2][2]) * (ppi32Points[0][3] - ppi32Points[2][3])))); GrStringDraw(&sContext, pcBuffer, -1, 16, 192, 0); // // Flush any cached drawing operations. // GrFlush(&sContext); // // The calibration is complete. Sit around and wait for a reset. // while(1) { } }
//***************************************************************************** // // Configure ADC0 for a differential input and a single sample. Once the // sample is ready, an interrupt flag will be set. Using a polling method, // the data will be read then displayed on the console via UART0. // //***************************************************************************** int main(void) { #if defined(TARGET_IS_TM4C129_RA0) || \ defined(TARGET_IS_TM4C129_RA1) || \ defined(TARGET_IS_TM4C129_RA2) uint32_t ui32SysClock; #endif // // This array is used for storing the data read from the ADC FIFO. It // must be as large as the FIFO for the sequencer in use. This example // uses sequence 3 which has a FIFO depth of 1. If another sequence // was used with a deeper FIFO, then the array size must be changed. // uint32_t pui32ADC0Value[1]; // // Set the clocking to run at 20 MHz (200 MHz / 10) using the PLL. When // using the ADC, you must either use the PLL or supply a 16 MHz clock // source. // TODO: The SYSCTL_XTAL_ value must be changed to match the value of the // crystal on your board. // #if defined(TARGET_IS_TM4C129_RA0) || \ defined(TARGET_IS_TM4C129_RA1) || \ defined(TARGET_IS_TM4C129_RA2) ui32SysClock = SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 20000000); #else SysCtlClockSet(SYSCTL_SYSDIV_10 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); #endif // // Set up the serial console to use for displaying messages. This is just // for this example program and is not needed for ADC operation. // InitConsole(); // // Display the setup on the console. // UARTprintf("ADC ->\n"); UARTprintf(" Type: differential\n"); UARTprintf(" Samples: One\n"); UARTprintf(" Update Rate: 250ms\n"); UARTprintf(" Input Pin: (AIN0/PE7 - AIN1/PE6)\n\n"); // // The ADC0 peripheral must be enabled for use. // SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0); // // For this example ADC0 is used with AIN0/1 on port E7/E6. // The actual port and pins used may be different on your part, consult // the data sheet for more information. GPIO port E needs to be enabled // so these pins can be used. // TODO: change this to whichever GPIO port you are using. // SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); // // Select the analog ADC function for these pins. // Consult the data sheet to see which functions are allocated per pin. // TODO: change this to select the port/pin you are using. // GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_7 | GPIO_PIN_6); // // Enable sample sequence 3 with a processor signal trigger. Sequence 3 // will do a single sample when the processor sends a signal to start the // conversion. Each ADC module has 4 programmable sequences, sequence 0 // to sequence 3. This example is arbitrarily using sequence 3. // ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_PROCESSOR, 0); // // Configure step 0 on sequence 3. Sample channel 0 (ADC_CTL_CH0) in // differential mode (ADC_CTL_D) and configure the interrupt flag // (ADC_CTL_IE) to be set when the sample is done. Tell the ADC logic // that this is the last conversion on sequence 3 (ADC_CTL_END). Sequence // 3 has only one programmable step. Sequence 1 and 2 have 4 steps, and // sequence 0 has 8 programmable steps. Since we are only doing a single // conversion using sequence 3 we will only configure step 0. For more // information on the ADC sequences and steps, refer to the datasheet. // ADCSequenceStepConfigure(ADC0_BASE, 3, 0, ADC_CTL_D | ADC_CTL_CH0 | ADC_CTL_IE | ADC_CTL_END); // // Since sample sequence 3 is now configured, it must be enabled. // ADCSequenceEnable(ADC0_BASE, 3); // // Clear the interrupt status flag. This is done to make sure the // interrupt flag is cleared before we sample. // ADCIntClear(ADC0_BASE, 3); // // Sample AIN0/1 forever. Display the value on the console. // while(1) { // // Trigger the ADC conversion. // ADCProcessorTrigger(ADC0_BASE, 3); // // Wait for conversion to be completed. // while(!ADCIntStatus(ADC0_BASE, 3, false)) { } // // Clear the ADC interrupt flag. // ADCIntClear(ADC0_BASE, 3); // // Read ADC Value. // ADCSequenceDataGet(ADC0_BASE, 3, pui32ADC0Value); // // Display the [AIN0(PE7) - AIN1(PE6)] digital value on the console. // UARTprintf("AIN0 - AIN1 = %4d\r", pui32ADC0Value[0]); // // This function provides a means of generating a constant length // delay. The function delay (in cycles) = 3 * parameter. Delay // 250ms arbitrarily. // #if defined(TARGET_IS_TM4C129_RA0) || \ defined(TARGET_IS_TM4C129_RA1) || \ defined(TARGET_IS_TM4C129_RA2) SysCtlDelay(ui32SysClock / 12); #else SysCtlDelay(SysCtlClockGet() / 12); #endif } }
//***************************************************************************** // // This example demonstrates the use of both watchdog timers. // //***************************************************************************** int main(void) { uint32_t ui32SysClock; // // Run from the PLL at 120 MHz. // ui32SysClock = SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 120000000); // // Configure the device pins. // PinoutSet(); // // Initialize the display driver. // Kentec320x240x16_SSD2119Init(ui32SysClock); // // Initialize the graphics context. // GrContextInit(&g_sContext, &g_sKentec320x240x16_SSD2119); // // Draw the application frame. // FrameDraw(&g_sContext, "watchdog"); // // Initialize the touch screen driver. // TouchScreenInit(ui32SysClock); TouchScreenCallbackSet(WatchdogTouchCallback); // // Reconfigure PF1 as a GPIO output so that it can be directly driven // (instead of being an Ethernet LED). // ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1); ROM_GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1, 0); // // Show the state and offer some instructions to the user. // GrContextFontSet(&g_sContext, g_psFontCmss20); GrStringDrawCentered(&g_sContext, "Watchdog 0:", -1, 80, 80, 0); GrStringDrawCentered(&g_sContext, "Watchdog 1:", -1, 240, 80, 0); GrContextFontSet(&g_sContext, g_psFontCmss14); GrStringDrawCentered(&g_sContext, "Tap the left screen to starve the watchdog 0", -1, GrContextDpyWidthGet(&g_sContext) / 2 , (GrContextDpyHeightGet(&g_sContext) / 2) + 40, 1); GrStringDrawCentered(&g_sContext, "Tap the right screen to starve the watchdog 1", -1, GrContextDpyWidthGet(&g_sContext) / 2 , (GrContextDpyHeightGet(&g_sContext) / 2) + 60, 1); // // Enable the peripherals used by this example. // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_WDOG0); ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_WDOG1); // // Enable the watchdog interrupt. // ROM_IntEnable(INT_WATCHDOG); // // Set the period of the watchdog timer. // ROM_WatchdogReloadSet(WATCHDOG0_BASE, ui32SysClock); ROM_WatchdogReloadSet(WATCHDOG1_BASE, 16000000); // // Enable reset generation from the watchdog timer. // ROM_WatchdogResetEnable(WATCHDOG0_BASE); ROM_WatchdogResetEnable(WATCHDOG1_BASE); // // Enable the watchdog timer. // ROM_WatchdogEnable(WATCHDOG0_BASE); ROM_WatchdogEnable(WATCHDOG1_BASE); // // Loop forever while the LED winks as watchdog interrupts are handled. // while(1) { } }
//***************************************************************************** // // The main routine // //***************************************************************************** int main(void) { int TypeID; tTRF79x0TRFMode eCurrentTRF79x0Mode = P2P_PASSIVE_TARGET_MODE; uint32_t x; uint16_t ui16MaxSizeRemaining=0; bool bCheck=STATUS_FAIL; uint8_t pui8Instructions[]="Instructions:\n " "You will need a NFC capable device and a NFC boosterpack for " "this demo\n " "To use this demo put the phone or tablet within 2 inches of " "the NFC boosterpack\n " "Messages sent to the microcontroller will be displayed on " "the terminal and screen\n " "Messages can be sent back to the NFC device via the " "'Echo Tag' button on the pull down menu\n"; // // Run from the PLL at 120 MHz. // g_ui32SysClk = SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 120000000); // // Select NFC Boosterpack Type // g_eRFDaughterType = RF_DAUGHTER_TRF7970ATB; // // Configure the device pins. // PinoutSet(); // // Initialize the UART for console I/O. // UARTStdioConfig(0, 115200, g_ui32SysClk); // // Initialize the display driver. // Kentec320x240x16_SSD2119Init(g_ui32SysClk); // // Initialize the graphics context. // GrContextInit(&g_sContext, &g_sKentec320x240x16_SSD2119); // // Initialize the Touch Screen Frames and related Animations. // ScreenInit(); // // Draw the application frame. // FrameDraw(&g_sContext, "nfc-p2p-demo"); // // Initialize USER LED to Blue. (May Overlap TriColor LED) // ENABLE_LED_PERIPHERAL; SET_LED_DIRECTION; // // Initialize TriColer LED if it exists. // if(BOARD_HAS_TRICOLOR_LED) { ENABLE_LED_TRICOLOR_RED_PERIPH; SET_LED_TRICOLOR_RED_DIRECTION; ENABLE_LED_TRICOLOR_BLUE_PERIPH; SET_LED_TRICOLOR_BLUE_DIRECTION; ENABLE_LED_TRICOLOR_GREEN_PERIPH; SET_LED_TRICOLOR_GREEN_DIRECTION; } // // Initialize the TRF79x0 and SSI. // TRF79x0Init(); // // Initialize Timer0A. // Timer0AInit(); // // Enable First Mode. // NFCP2P_init(eCurrentTRF79x0Mode,FREQ_212_KBPS); // // Enable Interrupts. // IntMasterEnable(); // // Print a prompt to the console. // UARTprintf("\n****************************\n"); UARTprintf("* NFC P2P Demo *\n"); UARTprintf("****************************\n"); // // Print instructions to the console / screen. // UARTprintf((char *)pui8Instructions); ScreenPayloadWrite(pui8Instructions,sizeof(pui8Instructions),1); while(1) { // // Update Screen. // ScreenPeriodic(); // // NFC-P2P-Initiator-Statemachine. // if(NFCP2P_proccessStateMachine() == NFC_P2P_PROTOCOL_ACTIVATION) { if(eCurrentTRF79x0Mode == P2P_INITATIOR_MODE) { eCurrentTRF79x0Mode = P2P_PASSIVE_TARGET_MODE; //Toggle LED's if(BOARD_HAS_TRICOLOR_LED) { TURN_OFF_LED_TRICOLOR_GREEN TURN_OFF_LED_TRICOLOR_RED; TURN_ON_LED_TRICOLOR_BLUE } } else if(eCurrentTRF79x0Mode == P2P_PASSIVE_TARGET_MODE) { eCurrentTRF79x0Mode = P2P_INITATIOR_MODE; // // Toggle LED's. // if(BOARD_HAS_TRICOLOR_LED) { TURN_OFF_LED_TRICOLOR_BLUE TURN_ON_LED_TRICOLOR_RED TURN_ON_LED_TRICOLOR_GREEN } }