Mechanism of cyclically polarity reversing solar magnetic cycle as a cosmic dynamo