// Functions control the logical power on/off for the chip

#include "CM_LIB.h"
#include "CM_I2C.h"
#include "CM_I2C_L.h"
#include "CM_GPA.h"
#include "hal_interface_api.h"
// Power On Chip  
//
// Returns 0 (SUCCESS) if no error
//
void cm_PowerOn(void)   
{
	// Reset chip data
	cm_ResetCrypto();
    ucCM_UserZone = ucCM_AntiTearing = 0;
    
    // Sequence for powering on secure memory according to ATMEL spec
    CM_DATA_OUT;                              // SDA and SCL start as outputs
	CM_CLK_OUT;
    CM_CLK_LO;                                // Clock should start LOW
    CM_DATA_HI;                               // Data high during reset
    cm_ClockCycles(CM_PWRON_CLKS);            // Give chip some clocks cycles to get started

    // Chip should now be in sync mode and ready to operate
}

// Shut down secure memory
//
void cm_PowerOff(void)
{
	cm_Delay(1);
	CM_CLK_LO;
	cm_Delay(6);
}
