function sof_export_c_eq_uint32t(fn, blob8, vn, justeq, howto)

% sof_export_c_eq_uint32t(fn, blob8, vn)
%
% Export 8-bit blob data as C int32_t vector in hexadecimal
%
% fn - filename for export
% blob8 - blob data from EQ design
% vn - variable name
% justeq - export just the EQ wihtout ABI headers for direct use in FW
% howto - add a comment how the header file was created

% SPDX-License-Identifier: BSD-3-Clause
%
% Copyright (c) 2021-2025, Intel Corporation.

	% Write blob
	fh = fopen(fn, 'w');
	if fh < 0
		fprintf(1, 'Error: Could not open file: %s\n', fn);
		error("Failed.");
	end

	year = datestr(now, 'yyyy');
	fprintf(fh, '/* SPDX-License-Identifier: BSD-3-Clause\n');
	fprintf(fh, ' *\n');
	fprintf(fh, ' * Copyright(c) %s Intel Corporation.\n', year);
	fprintf(fh, ' */\n');
	fprintf(fh, '\n');

	if nargin == 5
		fprintf(fh, '/* Created %s with command:\n', datestr(now, 'yyyy-mm-dd'));
		fprintf(fh, ' * %s\n */\n\n', howto);
	end

	fprintf(fh, '#include <stdint.h>\n\n');

	% Drop 8 bytes TLV header
	blob8 = blob8(9:end);

	% Pad blob length to multiple of four bytes
	n_orig = length(blob8);
	n_new = ceil(n_orig/4);
	blob8_new = zeros(1, n_new*4);
	blob8_new(1:n_orig) = blob8;

	%% Convert to 32 bit
	blob32 = zeros(1, n_new, 'uint32');
	k = 2.^[0 8 16 24];
	for i=1:n_new
		j = (i-1)*4;
		blob32(i) = blob8_new(j+1)*k(1) + blob8_new(j+2)*k(2) ...
			    +  blob8_new(j+3)*k(3) + blob8_new(j+4)*k(4);
	end

	% Omit all headers if requested
	if justeq
		blob32 = blob32(18:end);
		n_new = length(blob32);
	end

	numbers_in_line = 4;
	full_lines = floor(n_new/numbers_in_line);
	numbers_remain = n_new - numbers_in_line * full_lines;

	n = 1;
	fprintf(fh, 'static const uint32_t %s[%d] = {\n', vn, n_new);
	for i = 1:full_lines
		fprintf(fh, '\t');
		for j = 1:numbers_in_line
			fprintf(fh, '0x%08x', blob32(n));
			if n < n_new
				fprintf(fh, ',');
			end
			if j < numbers_in_line
				fprintf(fh, ' ');
			else
				fprintf(fh, '\n');
			end
			n = n + 1;
		end
	end

	if numbers_remain
		fprintf(fh, '\t');
		for j = 1:numbers_remain
			fprintf(fh, '0x%08x', blob32(n));
			if n < n_new
				fprintf(fh, ',');
			end
			if j < numbers_remain
				fprintf(fh, ' ');
			else
				fprintf(fh, '\n');
			end
			n = n + 1;
		end
	end

	fprintf(fh, '};\n');
	fclose(fh);
end
