sd read/write main loop