I am trying to calculate sha256sum of a buffer of lenght 1 byte using PKTE in Direct Host Mode.
Following is my code:
/***************************************************************************** * sha_256_hw.c *****************************************************************************/ #include <sys/platform.h> #include "adi_initialize.h" #include <blackfin.h> /** * If you want to use command program arguments, then place them in the following string. */ char __argv_string[] = ""; uint8_t buffer[] ="R"; #define LEN 1 uint32_t resblk[8]; void run_sha256sum_test (void) { uint32_t datatmp = 0,i,j; //step 1 : reset the pkte engine and release from reset *pREG_PKTE0_CFG = 3; *pREG_PKTE0_CFG = 0; // PKTE_CFG.MODE=0 i.e. Direct Host mode //step 2 & 3 : Set the ownership back to the packet engine & Set the PKTE_CTL_STAT.HASHFINAL *pREG_PKTE0_CTL_STAT = 0x11; //Step 4: set size of the input data in bytes in the PKTE_LEN.TOTLEN bit field //Step 5: Also set the PKTE_LEN.PEDONE bit = 0 and the PKTE_LEN.HSTRDY bit =1. // These bits must be the same as the PKTE_CTL_STAT.PERDY and // PKTE_CTL_STAT.HOSTRDY bits to guarantee ownership. *pREG_PKTE0_LEN = 0x00400001; //lenght of the input buffer is 1 //Step 6: Set the PKTE_CDSC_CNT register=1 to trigger the packet engine to //start validating the command descriptor. *pREG_PKTE0_CDSC_CNT = 1; //Just one command discrptor ///Step 7: For an SHA, set the PKTE_SA_CMD0.OPCD bit field =0b011 for hash // operation and the PKTE_SA_CMD0.OPGRP bit field =0b00 for basic operation. //Step 8: for SHA-256, PKTE_SA_CMD0.HASH =0b0011 //Step 9: For SHA-256, PKTE_SA_CMD0.DIGESTLEN =0b1000 (8 words) //Step 10: setting the PKTE_SA_CMD0.HASHSRC bit field =0b11, //the packet engine provides the correct initial constants depending on the SHA chosen *pREG_PKTE0_SA_CMD0 = 0x0c803f03; //Step 11: Set the PKTE_SA_CMD1.CPYDGST bit =1 and //PKTE_SA_CMD1.CPYPAD bit =1 to move the result to the output buffer //of the packet engine at the PKTE_DATAIO_BUF location. *pREG_PKTE0_SA_CMD1 =0x09; //Step 12: Write to the PKTE_SA_RDY register with any value to trigger the operation. *pREG_PKTE0_SA_RDY = 1; //Step 13: Start writing the input to the data buffer of the packet engine starting //at the PKTE_DATAIO_BUF location //TODO: implement loop to feed the input in 32-bit multiples *pREG_PKTE0_DATAIO_BUF = buffer[0]<<24 ;//rest are dont care //Step 14: Write the PKTE_INBUF_CNT register with the length of the input //rounded up to the next multiple of 4. For example, //if the input length is 30 bytes, set this register to 32. *pREG_PKTE0_INBUF_CNT = LEN + ((LEN & 0xf) && 1); for (i=0;i<0x5ffff;i++) asm("nop;"); //TODO: poll the stat register for (i=0;i<8;i++) resblk[i] = *pREG_PKTE0_DATAIO_BUF; } int main(int argc, char *argv[]) { /** * Initialize managed drivers and/or services that have been added to * the project. * @return zero on success */ adi_initComponents(); /* Begin adding your custom code here */ run_sha256sum_test(); return 0; }
The writes to PKTE_LEN in step 4 & 5 are not getting reflected into the *pREG_PKTE0_LEN.
What am I doing wrong here?
Adding the source of the steps followed in the code, also Including the links for Harware Refence Manual
[edited by: RishavAmbasta at 10:34 AM (GMT -5) on 9 Nov 2023]