English
Language : 

C8051F960-B-GM Datasheet, PDF (200/492 Pages) Silicon Laboratories – Ultra Low Power 128K, LCD MCU Family
C8051F96x
14.6.6. CTR Encryption using DMA
Normally, the AES block is used with the DMA. This provides the best performance and lowest power con-
sumption. Code examples are provided in 8051 compiler independent C code using the DMA. It is highly
recommended to use with the code examples. The steps are documented in the data sheet for complete-
ness.
 Prepare encryption Key, counter, and data to be encrypted in xram.
 Reset AES module by clearing bit 2 of AES0BCFG.
 Disable the first four DMA channels by clearing bits 0 to 3 in the DMA0EN sfr.
 Configure the first DMA channel for the AES0KIN sfr
Select the first DMA channel by writing 0x00 to the DMA0SEL sfr
Configure the first DMA channel to move xram to AES0KIN sfr by writing 0x05 to the DMA0NCF sfr
Clear DMA0NMD to disable wrapping.
Write the xram location of encryption key to the DMA0NBAH and DMA0NBAL sfrs.
Write the key length in bytes to DMA0NSZL sfr
Clear the DMA0NSZH sfr
Clear the DMA0NAOH and DMA0NAOL sfrs
 Configure the second DMA channel for the AES0BIN sfr.
Select the second DMA channel by writing 0x01 to the DMA0SEL sfr.
Configure the second DMA channel to move xram to AES0BIN sfr by writing 0x06 to the DMA0NCF sfr.
Clear DMA0NMD to disable wrapping.
Write the xram address of the data to be encrypted to the DMA0NBAH and DMA0NBAL sfrs.
Write 16 to the DMA0NSZL SFR for one block of 16 bytes.
Clear the DMA0NSZH sfr
Clear the DMA0NAOH and DMA0NAOL sfrs.
 Configure the third DMA channel for the AES0XIN sfr.
Select the third DMA channel by writing 0x02 to the DMA0SEL sfr.
Configure the third DMA channel to move xram to AES0XIN sfr by writing 0x07 to the DMA0NCF sfr.
Clear DMA0NMD to disable wrapping.
Write the xram address of counter to the DMA0NBAH and DMA0NBAL sfrs.
Write 16 to the DMA0NSZL SFR for one block of 16 bytes.
Clear the DMA0NSZH sfr
Clear the DMA0NAOH and DMA0NAOL sfrs.
 Configure the fourth DMA channel for the AES0YOUT sfr
Select the fourth channel by writing 0x03 to the DMA0SEL sfr
Configure the fourth DMA channel to move the contents of the AES0YOUT sfr to xram by writing 0x08 to the
DMA0NCF sfr
Enable transfer complete interrupt by setting bit 7 of DMA0NCF sfr
Clear DMA0NMD to disable wrapping
Write 16 to the DMA0NSZL SFR for one block of 16 bytes.
Clear the DMA0NSZH sfr
Clear the DMA0NAOH and DMA0NAOL sfrs.
 Clear first four DMA interrupts by clearing bits 0 to 3 in the DMA0INT sfr.
 Enable first four DMA channels setting bits 0 to 3 in the DMA0EN sfr
 Configure the AES Module data flow for XOR on output data by writing 0x02 to the AES0DCFG sfr.
 Write key size to bits 1 and 0 of the AES0BCFG
 Configure the AES core for encryption by setting the bit 2 of AES0BCFG
 Initiate the encryption operation be setting bit 3 of AES0BCFG
 Wait on the DMA interrupt from DMA channel 3
 Disable the AES Module by clearing bit 2 of AES0BCFG
200
Rev. 1.0