int main (void) { IRMP_DATA irmp_data; ROM_FPUEnable(); ROM_FPUStackingEnable(); ROM_SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN); irmp_init(); // initialize irmp timer1_init(); // initialize timer1 sei (); // enable interrupts for (;;) { if (irmp_get_data (&irmp_data)) { // ir signal decoded, do something here... // irmp_data.protocol is the protocol, see irmp.h // irmp_data.address is the address/manufacturer code of ir sender // irmp_data.command is the command code // irmp_protocol_names[irmp_data.protocol] is the protocol name (if enabled, see irmpconfig.h) } } }
//***************************************************************************** // // 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) { } }
//***************************************************************************** // // 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; // // Run from the PLL at 120 MHz. // ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 120000000); // // Configure the device pins. // PinoutSet(false, 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"); // // 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); LEDWrite(CLP_D3 | CLP_D4, CLP_D4); } else { UARTprintf("Demo completed successfully.\n"); LEDWrite(CLP_D3 | CLP_D4, CLP_D3); } while(1) { } }
//***************************************************************************** // // 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) { } }
//***************************************************************************** // // This example decrypts blocks ciphertext using AES128 and AES256 in GCM // mode. It does the decryption first without uDMA and then with uDMA. // The results are checked after each operation. // //***************************************************************************** int main(void) { uint32_t pui32PlainText[64], pui32Tag[4], pui32Y0[4], ui32Errors, ui32Idx; uint32_t *pui32Key, ui32IVLength, *pui32IV, ui32DataLength; uint32_t *pui32ExpPlainText, ui32AuthDataLength, *pui32AuthData; uint32_t *pui32CipherText, *pui32ExpTag; uint32_t ui32KeySize; uint32_t ui32SysClock; uint8_t ui8Vector; tContext sContext; // // Run from the PLL at 120 MHz. // ui32SysClock = MAP_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, "aes-gcm-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++) { pui32PlainText[ui32Idx] = 0; } for(ui32Idx = 0; ui32Idx < 4; ui32Idx++) { pui32Tag[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 AES interrupts. // ROM_IntEnable(INT_AES0); // // Enable debug output on UART0 and print a welcome message. // ConfigureUART(); UARTprintf("Starting AES GCM 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_psAESGCMTestVectors) / sizeof(g_psAESGCMTestVectors[0]))) && (ui32Errors == 0); ui8Vector++) { UARTprintf("Starting vector #%d\n", ui8Vector); // // Get the current vector's data members. // ui32KeySize = g_psAESGCMTestVectors[ui8Vector].ui32KeySize; pui32Key = g_psAESGCMTestVectors[ui8Vector].pui32Key; ui32IVLength = g_psAESGCMTestVectors[ui8Vector].ui32IVLength; pui32IV = g_psAESGCMTestVectors[ui8Vector].pui32IV; ui32DataLength = g_psAESGCMTestVectors[ui8Vector].ui32DataLength; pui32ExpPlainText = g_psAESGCMTestVectors[ui8Vector].pui32PlainText; ui32AuthDataLength = g_psAESGCMTestVectors[ui8Vector].ui32AuthDataLength; pui32AuthData = g_psAESGCMTestVectors[ui8Vector].pui32AuthData; pui32CipherText = g_psAESGCMTestVectors[ui8Vector].pui32CipherText; pui32ExpTag = g_psAESGCMTestVectors[ui8Vector].pui32Tag; // // If both the data lengths are zero, then it's a special case. // if((ui32DataLength == 0) && (ui32AuthDataLength == 0)) { UARTprintf("Performing decryption without uDMA.\n"); // // Figure out the value of Y0 depending on the IV length. // AESGCMY0Get(ui32KeySize, pui32IV, ui32IVLength, pui32Key, pui32Y0); // // Perform the basic encryption. // AESECBEncrypt(ui32KeySize, pui32Y0, pui32Tag, pui32Key, 16); } else { // // Figure out the value of Y0 depending on the IV length. // AESGCMY0Get(ui32KeySize, pui32IV, ui32IVLength, pui32Key, pui32Y0); // // Perform the decryption without uDMA. // UARTprintf("Performing decryption without uDMA.\n"); AESGCMDecrypt(ui32KeySize, pui32CipherText, pui32PlainText, ui32DataLength, pui32Key, pui32Y0, pui32AuthData, ui32AuthDataLength, pui32Tag, false); } // // Check the results. // for(ui32Idx = 0; ui32Idx < (ui32DataLength / 4); ui32Idx++) { if(pui32ExpPlainText[ui32Idx] != pui32PlainText[ui32Idx]) { UARTprintf("Plaintext mismatch on word %d. Exp: 0x%x, Act: " "0x%x\n", ui32Idx, pui32ExpPlainText[ui32Idx], pui32PlainText[ui32Idx]); ui32Errors |= (ui32Idx << 16) | 0x00000002; } } for(ui32Idx = 0; ui32Idx < 4; ui32Idx++) { if(pui32ExpTag[ui32Idx] != pui32Tag[ui32Idx]) { UARTprintf("Tag mismatch on word %d. Exp: 0x%x, Act: 0x%x\n", ui32Idx, pui32ExpTag[ui32Idx], pui32Tag[ui32Idx]); ui32Errors |= (ui32Idx << 16) | 0x00000003; } } // // Clear the arrays containing the ciphertext and tag to ensure things // are working correctly. // for(ui32Idx = 0; ui32Idx < 16; ui32Idx++) { pui32PlainText[ui32Idx] = 0; } for(ui32Idx = 0; ui32Idx < 4; ui32Idx++) { pui32Tag[ui32Idx] = 0; } // // Only use DMA with the vectors that have data. // if((ui32DataLength != 0) || (ui32AuthDataLength != 0)) { // // Perform the decryption with uDMA. // UARTprintf("Performing decryption with uDMA.\n"); AESGCMDecrypt(ui32KeySize, pui32CipherText, pui32PlainText, ui32DataLength, pui32Key, pui32Y0, pui32AuthData, ui32AuthDataLength, pui32Tag, true); // // Check the result. // for(ui32Idx = 0; ui32Idx < (ui32DataLength / 4); ui32Idx++) { if(pui32ExpPlainText[ui32Idx] != pui32PlainText[ui32Idx]) { UARTprintf("Plaintext mismatch on word %d. Exp: 0x%x, " "Act: 0x%x\n", ui32Idx, pui32ExpPlainText[ui32Idx], pui32PlainText[ui32Idx]); ui32Errors |= (ui32Idx << 16) | 0x00000002; } } for(ui32Idx = 0; ui32Idx < 4; ui32Idx++) { if(pui32ExpTag[ui32Idx] != pui32Tag[ui32Idx]) { UARTprintf("Tag mismatch on word %d. Exp: 0x%x, Act: " "0x%x\n", ui32Idx, pui32ExpTag[ui32Idx], pui32Tag[ui32Idx]); ui32Errors |= (ui32Idx << 16) | 0x00000003; } } } } // // 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); } // // Wait forever. // while(1) { } }
//***************************************************************************** // // Main function performs init and manages system. // // Called automatically after the system and compiler pre-init sequences. // Performs system init calls, restores state from hibernate if needed and // then manages the application context duties of the system. // //***************************************************************************** int main(void) { uint32_t ui32Status; uint32_t ui32ResetCause; int32_t i32CommandStatus; // // 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_FPUEnable(); ROM_FPUStackingEnable(); // // Set the system clock to run at 40Mhz off PLL with external crystal as // reference. // ROM_SysCtlClockSet(SYSCTL_SYSDIV_5 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ | SYSCTL_OSC_MAIN); // // Enable the hibernate module // SysCtlPeripheralEnable(SYSCTL_PERIPH_HIBERNATE); // // Enable and Initialize the UART. // ConfigureUART(); UARTprintf("Welcome to the Tiva C Series TM4C123G LaunchPad!\n"); UARTprintf("Type 'help' for a list of commands\n"); UARTprintf("> "); // // Determine why system reset occurred and respond accordingly. // ui32ResetCause = SysCtlResetCauseGet(); SysCtlResetCauseClear(ui32ResetCause); if(ui32ResetCause == SYSCTL_CAUSE_POR) { if(HibernateIsActive()) { // // Read the status bits to see what caused the wake. // ui32Status = HibernateIntStatus(0); HibernateIntClear(ui32Status); // // Wake was due to the push button. // if(ui32Status & HIBERNATE_INT_PIN_WAKE) { UARTprintf("Hibernate Wake Pin Wake Event\n"); UARTprintf("> "); // // Recover the application state variables from battery backed // hibernate memory. Set ui32Mode to normal. // HibernateDataGet((uint32_t*) &g_sAppState, sizeof(tAppState) / 4 + 1); g_sAppState.ui32Mode = APP_MODE_NORMAL; } // // Wake was due to RTC match // else if(ui32Status & HIBERNATE_INT_RTC_MATCH_0) { UARTprintf("Hibernate RTC Wake Event\n"); UARTprintf("> "); // // Recover the application state variables from battery backed // hibernate memory. Set ui32Mode to briefly flash the RGB. // HibernateDataGet((uint32_t*) &g_sAppState, sizeof(tAppState) / 4 + 1); g_sAppState.ui32Mode = APP_MODE_HIB_FLASH; } } else { // // Reset was do to a cold first time power up. // UARTprintf("Power on reset. Hibernate not active.\n"); UARTprintf("> "); g_sAppState.ui32Mode = APP_MODE_NORMAL; g_sAppState.fColorWheelPos = 0; g_sAppState.fIntensity = APP_INTENSITY_DEFAULT; g_sAppState.ui32Buttons = 0; } } else { // // External Pin reset or other reset event occured. // UARTprintf("External or other reset\n"); UARTprintf("> "); // // Treat this as a cold power up reset without restore from hibernate. // g_sAppState.ui32Mode = APP_MODE_NORMAL; g_sAppState.fColorWheelPos = APP_PI; g_sAppState.fIntensity = APP_INTENSITY_DEFAULT; g_sAppState.ui32Buttons = 0; // // colors get a default initialization later when we call AppRainbow. // } // // Initialize clocking for the Hibernate module // HibernateEnableExpClk(SysCtlClockGet()); // // Initialize the RGB LED. AppRainbow typically only called from interrupt // context. Safe to call here to force initial color update because // interrupts are not yet enabled. // RGBInit(0); RGBIntensitySet(g_sAppState.fIntensity); AppRainbow(1); RGBEnable(); // // Initialize the buttons // ButtonsInit(); // // Initialize the SysTick interrupt to process colors and buttons. // SysTickPeriodSet(SysCtlClockGet() / APP_SYSTICKS_PER_SEC); SysTickEnable(); SysTickIntEnable(); IntMasterEnable(); // // spin forever and wait for carriage returns or state changes. // while(1) { UARTprintf("\n>"); // // Peek to see if a full command is ready for processing // while(UARTPeek('\r') == -1) { // // millisecond delay. A SysCtlSleep() here would also be OK. // SysCtlDelay(SysCtlClockGet() / (1000 / 3)); // // Check for change of mode and enter hibernate if requested. // all other mode changes handled in interrupt context. // if(g_sAppState.ui32Mode == APP_MODE_HIB) { AppHibernateEnter(); } } // // a '\r' was detected get the line of text from the user. // UARTgets(g_cInput,sizeof(g_cInput)); // // Pass the line from the user to the command processor. // It will be parsed and valid commands executed. // i32CommandStatus = CmdLineProcess(g_cInput); // // Handle the case of bad command. // if(i32CommandStatus == CMDLINE_BAD_CMD) { UARTprintf("Bad command!\n"); } // // Handle the case of too many arguments. // else if(i32CommandStatus == CMDLINE_TOO_MANY_ARGS) { UARTprintf("Too many arguments for command processor!\n"); } } }
void Init_FPU(void) { ROM_FPULazyStackingEnable(); ROM_FPUEnable(); ROM_FPUStackingEnable(); }
//***************************************************************************** // // This example encrypts blocks of plaintext using AES128 in ECB 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; uint32_t ui32Keysize; uint32_t *pui32CipherTextExp; tContext sContext; uint8_t ui8Loop; // // Run from the PLL at 120 MHz. // ui32SysClock = MAP_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, "aes-ecb-encrypt"); // // Show some instructions on the display // GrContextFontSet(&sContext, g_psFontCm20); 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(); // // Configure the system clock to run off the internal 16MHz oscillator. // MAP_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 AES ECB 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 AES modules. // if(!AESInit()) { UARTprintf("Initialization of the AES module failed.\n"); ui32Errors |= 0x00000001; } // // Perform the same operation with 128bit key first, then 256bit key. // for(ui8Loop = 0; ui8Loop < 2; ui8Loop++) { ui32Keysize = (ui8Loop == 0)?AES_CFG_KEY_SIZE_128BIT:AES_CFG_KEY_SIZE_256BIT; UARTprintf("\nKey Size: %sbit\n", ((ui8Loop == 0)?"128":"256")); // // Clear the array containing the cipher text. // for(ui32Idx = 0; ui32Idx < 16; ui32Idx++) { pui32CipherText[ui32Idx] = 0; } // // Perform the encryption without uDMA. // UARTprintf("Performing encryption without uDMA.\n"); AESECBEncrypt(ui32Keysize, g_pui32AESPlainText, pui32CipherText, (ui8Loop == 0)?g_pui32AES128Key:g_pui32AES256Key, 64, false); // // Check the result. // pui32CipherTextExp = (ui8Loop == 0)?g_pui32AES128CipherText: g_pui32AES256CipherText; for(ui32Idx = 0; ui32Idx < 16; ui32Idx++) { if(pui32CipherText[ui32Idx] != pui32CipherTextExp[ui32Idx]) { UARTprintf("Ciphertext mismatch on word %d. Exp: 0x%x, Act: " "0x%x\n", ui32Idx, pui32CipherTextExp[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"); AESECBEncrypt(ui32Keysize, g_pui32AESPlainText, pui32CipherText, (ui8Loop == 0)?g_pui32AES128Key:g_pui32AES256Key, 64, true); // // Check the result. // for(ui32Idx = 0; ui32Idx < 16; ui32Idx++) { if(pui32CipherText[ui32Idx] != pui32CipherTextExp[ui32Idx]) { UARTprintf("Ciphertext mismatch on word %d. Exp: 0x%x, Act: " "0x%x\n", ui32Idx, pui32CipherTextExp[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) { } }