
#include "grifo_fw_blob.h"

#include <string.h>

using namespace grifo_fw;

#if 0
grifo_fw_block_raw_helper_t::grifo_fw_block_raw_helper_t(void *mem, unsigned int size)
{
    cursor=0;
    max_size=size/(sizeof *memory);
    memory=reinterpret_cast<uint32_t*>(mem);
}
#endif

void* grifo_fw_block_raw_helper_t::alloc_raw_block(unsigned int size_header, unsigned int size_bytes)
{
    unsigned int total_size=size_header+size_bytes;

    unsigned int ws=(total_size+3)>>2;
    unsigned int new_pos=cursor+ws+2;
    if (new_pos>max_size_word)
        return 0;
    memory[cursor]=k_som;

    uint32_t* p=&memory[cursor+1];

    if (ws>1)
    {
        p[ws-1]=0;
        //memcpy(p, data, size_bytes);
        p[ws]=k_eob;
    }
    cursor+=ws+1;
    memory[cursor]=k_eob;

    return p;
}

int grifo_fw::grifo_fw_raw_blob_clear(grifo_fw_blob_header_t* b)
{
    b->work_size=0;
    uint32_t* p=reinterpret_cast<uint32_t*>(&b[1]);
    p[0]=grifo_fw_block_raw_helper_t::k_eob;

    return 0;
}
