  We present a long-term phase-coherent timing analysis and pulse-phase
resolved spectroscopy for the two outbursts observed from the transient
anomalous X-ray pulsar CXOU J164710.2-45521. For the first outburst we used 11
Chandra and XMM-Newton observations between September 2006 to August 2009, the
longest baseline yet for this source.
  We obtain a coherent timing solution with $P=10.61065583(4)$ s, $\dot{P} =
9.72(1) \times 10^{-13}\;$s s$^{-1}$ and $\ddot{P} = -1.05(5)\times10^{-20}\;
$s s$^{-2}$. Under the standard assumptions this implies a surface dipolar
magnetic field of $\sim 10^{14}$ G, confirming this source as a standard-$B$
magnetar.
  We also study the evolution of the pulse profile (shape, intensity and pulsed
fraction) as a function of time and energy. Using the phase-coherent timing
solution we perform a phase-resolved spectroscopy analysis, following the
spectral evolution of pulse-phase features, which hints at the physical
processes taking place on the star. The results are discussed from the
perspective of magneto-thermal evolution models and the untwisting
magnetosphere model. Finally, we present similar analysis for the second, less
intense, 2011 outburst. For the timing analysis we used Swift data together
with 2 XMM-Newton and Chandra pointings. The results inferred for both
outbursts are compared and briefly discussed in a more general framework.
