function varargout = calcSCIBaudRatePrescaler(sysclkoutInMHz, LspclkDiv, DesiredBaudRate)

nargoutchk(1, 2);

lspclk = sysclkoutInMHz * 1e6 / LspclkDiv;

BaudRatePrescaler = round((lspclk/(DesiredBaudRate * 8)) - 1);

if BaudRatePrescaler < 1
    BaudRatePrescaler = 1;
elseif BaudRatePrescaler > 65535
    BaudRatePrescaler = 65535;
end

baudrate = lspclk/((BaudRatePrescaler + 1) * 8);
baudrate = round(baudrate);

varargout{1} = BaudRatePrescaler;
if nargout == 2
    varargout{2} = baudrate;
end