Birmingham City defender Stephen Carr has announced his retirement from football following a long battle with a knee problem.