Esempio n. 1
0
void SensorsTestInit()
{
	char pinDirection = 0;
	int i;
	PIO_Configure(aDigitalOuts, PIO_LISTSIZE(aDigitalOuts));
	PIO_Configure(digitalIns, PIO_LISTSIZE(digitalIns));
	PIO_Configure(sensorsPower, PIO_LISTSIZE(sensorsPower));
	
	PMC_EnablePeripheral(AT91C_ID_PIOB);
	PMC_EnablePeripheral(AT91C_ID_PIOA);
	
	SelectAng0();		// select analog port 0 to be mesured instead of BattVoltage
	SensorPowerOn();	// turn on the Vcc line
	
	if(PMC_IsPeriphEnabled(AT91C_ID_TWI) == 0){
		PIO_Configure(twiPortPins, PIO_LISTSIZE(twiPortPins));
		PMC_EnablePeripheral(AT91C_ID_TWI);
		
		TWI_ConfigureMaster(AT91C_BASE_TWI,TWCK,MCK);
	}
	
	// set all pins on pullup chip to output
	WritePullupData(0x00,&pinDirection,1);
	WritePullupData(0x01,&pinDirection,1);
	
	for(i = 0;i < 8;i++){
		if(i>1) AnalogPullup(i,0);  // disable Analog pullups for output test
		DigitalPullup(i,1);		// enable all digital pullups
	}
}
Esempio n. 2
0
unsigned char AccelInit(void)
{	
	PIO_Configure(accIntPins, PIO_LISTSIZE(accIntPins));
	
	if(PMC_IsPeriphEnabled(AT91C_ID_TWI) == 0){
		PIO_Configure(twiPins, PIO_LISTSIZE(twiPins));
		
		PMC_EnablePeripheral(AT91C_ID_TWI);
	
		TWI_ConfigureMaster(AT91C_BASE_TWI,TWCK,MCK);
	}
	usleep(10000);

#ifdef STACCEL
	// ST Accelerometer
	char setup[4];
	setup[0] = (1<<5)|(2<<3)|7; // Normal power, data rate = 400Hz, ZYX axis enabled
	setup[1] = 0; // Do not add filter stuff
	setup[2] = (2<<0); // Data ready interrupt on INT 2 pad
	setup[3] = (0<<4); // do update between reads, and set scale to +/- 2g's
	WriteAccelData(0x20|(1<<7),setup,4);
#else
	// Freescale Accelerometer
	//AccelCalibration();	
	AccelSetScale(2);	
	AccelSetCalibration();
	
#endif
	SetPitCallback(AccelCallback,3);
	
	return 0;
}
Esempio n. 3
0
/**
 * \brief Application entry point for ssc_dam_audio example.
 *
 * \return Unused (ANSI-C compatibility).
 */
int main( void )
{    
    uint16_t data = 0;
    /* Disable watchdog */
    WDT_Disable( WDT ) ;
 
    /* Enable I and D cache */
    SCB_EnableICache();
    SCB_EnableDCache();

    /* Output example information */
    printf("-- SSC DMA Audio Example %s --\n\r", SOFTPACK_VERSION);
    printf("-- %s\n\r", BOARD_NAME);
    printf("-- Compiled: %s %s --\n\r", __DATE__, __TIME__);

    /* Configure systick for 1 ms. */
    printf( "Configure system tick to get 1ms tick period.\n\r" ) ;
    if ( TimeTick_Configure( ) )
    {
        printf("-F- Systick configuration error\n\r" ) ;
    }

    /* Configure all pins */
    PIO_Configure(pinsSsc, PIO_LISTSIZE(pinsSsc));

    /* Configure SSC */
    SSC_Configure(AUDIO_IF , 0 , SSC_MCK );
    SSC_ConfigureReceiver(AUDIO_IF,I2S_SLAVE_RX_SETTING,I2S_SLAVE_RX_FRM_SETTING);
    SSC_DisableReceiver(AUDIO_IF);
    SSC_ConfigureTransmitter(AUDIO_IF,I2S_SLAVE_TX_SETTING,I2S_SLAVE_TX_FRM_SETTING);
    SSC_DisableTransmitter(AUDIO_IF);

    /* Configure DMA */
    Dma_configure();

    /* Configure and enable the TWI (required for accessing the DAC) */
    PMC_EnablePeripheral(ID_TWIHS0);
    TWI_ConfigureMaster(TWIHS0, TWI_CLOCK, BOARD_MCK);
    TWID_Initialize(&twid, TWIHS0);
    /* Configure TWI interrupts */
    NVIC_ClearPendingIRQ(TWIHS0_IRQn);
    NVIC_EnableIRQ(TWIHS0_IRQn);

    /* check that WM8904 is present */
    WM8904_Write(&twid, WM8904_SLAVE_ADDRESS, 22, 0);
    data=WM8904_Read(&twid, WM8904_SLAVE_ADDRESS, 0);
    if( data != 0x8904){
        printf("WM8904 not found!\n\r");
        while(1);
    }
    /* Initialize the audio DAC */
    WM8904_Init(&twid, WM8904_SLAVE_ADDRESS, PMC_MCKR_CSS_SLOW_CLK); 

    /* Enable the DAC master clock */
    PMC_ConfigurePCK2(PMC_MCKR_CSS_SLOW_CLK, PMC_MCKR_PRES_CLK_1 );
    printf("Insert Line-in cable with PC Headphone output\n\r");
    PlayRecording();
    while ( 1 );
}
Esempio n. 4
0
void TwoWire::begin(void) {
	if (onBeginCallback)
		onBeginCallback();

	// Disable PDC channel
	twi->TWI_PTCR = UART_PTCR_RXTDIS | UART_PTCR_TXTDIS;

	TWI_ConfigureMaster(twi, twiClock, VARIANT_MCK);
	status = MASTER_IDLE;
}
Esempio n. 5
0
//------------------------------------------------------------------------------
/// Initialize EEPROM device. 
//------------------------------------------------------------------------------
static void EepromInit()
{
    TRACE_INFO("Init TWI EEPROM %s\n\r", NAME_REF);

    // Configure Pins
    PIO_Configure(pins, PIO_LISTSIZE(pins));

    // Configure TWI
    AT91C_BASE_PMC->PMC_PCER = 1 << BOARD_ID_TWI;
    TWI_ConfigureMaster(BOARD_BASE_TWI, TWCK, BOARD_MCK);
    TWID_Initialize(&twid, BOARD_BASE_TWI);
    IRQ_ConfigureIT(BOARD_ID_TWI, 0, ISR_Twi);
    IRQ_EnableIT(BOARD_ID_TWI);

}
Esempio n. 6
0
void i2c_eeprom_master_init(Twi *twi) {
	const Pin twi_pins[] = {PINS_TWI_BRICKLET};

	// Configure TWI pins
	PIO_Configure(twi_pins, PIO_LISTSIZE(twi_pins));

	// Enable TWI peripheral clock
	PMC->PMC_PCER0 = 1 << ID_TWI0;

	// Configure TWI interrupts
	NVIC_DisableIRQ(TWI0_IRQn);
	NVIC_ClearPendingIRQ(TWI0_IRQn);
	NVIC_SetPriority(TWI0_IRQn, PRIORITY_EEPROM_MASTER_TWI0);
	NVIC_EnableIRQ(TWI0_IRQn);

    // Configure TWI as master
    TWI_ConfigureMaster(twi, I2C_EEPROM_CLOCK, BOARD_MCK);
}
Esempio n. 7
0
void eeprom_init()
{
    PIO_Configure(pins_eeprom, PIO_LISTSIZE(pins_eeprom));
    PMC->PMC_PCER0 = 1 << ID_TWI0;
    TWI_ConfigureMaster(TWI0, TWCK, BOARD_MCK);
    TWID_Initialize(&twid, TWI0);
    
    eeprom_readBytes(0x100-6, eui48, sizeof(eui48));
    //TWID_Read(&twid, 0x50, 0x100-6, 0x01, eui48, sizeof(eui48), 0);

    eui64[0] = eui48[0];
    eui64[1] = eui48[1];
    eui64[2] = eui48[2];
    eui64[3] = 0xFF;
    eui64[4] = 0xFE;
    eui64[5] = eui48[3];
    eui64[6] = eui48[4];
    eui64[7] = eui48[5];
    return;
}
uint8_t i2cInit(uint8_t instance, uint32_t clock){
    uint8_t i;

    if(instance >= I2C_NUM_INSTANCES) return I2C_ERR_INVAL;

    gpioSetFun(pins[instance][0], GPIO_FUNC_GPIO);
    gpioSetFun(pins[instance][1], GPIO_FUNC_GPIO);
    gpioSetPullup(pins[instance][0], 1);
    gpioSetPullup(pins[instance][1], 1);
    gpioSetDir(pins[instance][0], 0);
    gpioSetDir(pins[instance][1], 0);
    gpioSetVal(pins[instance][0], 0);
    gpioSetVal(pins[instance][1], 0);
    sdaHi(instance);
    sclHi(instance);
    delayTicks[instance] = (TICKS_PER_MS * 1000) / (8 * clock * 2);
    i2cDelay(instance);
    i2cDelay(instance);
    for (i = 0; i < 100; i++)       // Try to reset the bus
        i2cBitTx(instance, 1);
    i2cStop(instance);

#if !I2C_BITBANG
    PMC_EnablePeripheral(instance ? ID_TWI1 : ID_TWI0);
    gpioSetFun(pins[instance][0], GPIO_FUNC_A);
    gpioSetFun(pins[instance][1], GPIO_FUNC_A);
    TWI_ConfigureMaster(instance ? TWI1 : TWI0, clock, BOARD_MCK);

#if I2C_INT_PDC
    NVIC_EnableIRQ(instance ? TWI1_IRQn : TWI0_IRQn);
    if (instance)
        TWI1->TWI_IDR = 0x00F77;
    else
        TWI0->TWI_IDR = 0x00F77;
#endif

#endif


    return I2C_ALL_OK;
}
Esempio n. 9
0
void SensorsInit()
{
	char pinDirection = 0;
	int i;
	PIO_Configure(analogs, PIO_LISTSIZE(analogs));
	PIO_Configure(digitalIns, PIO_LISTSIZE(digitalIns));
	PIO_Configure(sensorsPower, PIO_LISTSIZE(sensorsPower));
	
	PMC_EnablePeripheral(AT91C_ID_PIOB);
	PMC_EnablePeripheral(AT91C_ID_PIOA);
	
	PMC_EnablePeripheral(AT91C_ID_ADC1);
	ADC_Initialize(AT91C_BASE_ADC1, AT91C_ID_ADC1, AT91C_ADC_TRGEN_DIS, \
				   0, AT91C_ADC_SLEEP_NORMAL_MODE, AT91C_ADC_LOWRES_10_BIT, \
				   MCK, BOARD_ADC_FREQ, 10, 3000);
	for(i = 0;i < 8;i++) ADC_EnableChannel(AT91C_BASE_ADC1, i);

	SetPitCallback(SensorsCallback,1);
	
	SelectAng0();		// select analog port 0 to be mesured instead of BattVoltage
	SensorPowerOn();	// turn on the Vcc line
	
	if(PMC_IsPeriphEnabled(AT91C_ID_TWI) == 0){
		PIO_Configure(twiPortPins, PIO_LISTSIZE(twiPortPins));
		PMC_EnablePeripheral(AT91C_ID_TWI);
		
		TWI_ConfigureMaster(AT91C_BASE_TWI,TWCK,MCK);
	}
	
	// set all pins on pullup chip to output
	WritePullupData(0x00,&pinDirection,1);
	WritePullupData(0x01,&pinDirection,1);
	
	for(i = 0;i < 8;i++){
		if(i>1) AnalogPullup(i,1);  // enable pullups if needed
		DigitalPullup(i,1);		// enable all digital pullups
	}
}
Esempio n. 10
0
void imu_init()
{
  printf("imu_init()\r\n");
  PMC_EnablePeripheral(ID_TWI0);
  PIO_Configure(&pin_i2c_scl, 1);
  PIO_Configure(&pin_i2c_sda, 1);
  TWI_ConfigureMaster(TWI0, 400000, F_CPU);
  TWID_Initialize(&g_twid, TWI0);
  g_twid_async.status = 0;
  g_twid_async.callback = (void *)imu_twi_cb;
  NVIC_SetPriority(TWI0_IRQn, 2); // lower priority than rs485 comms
  NVIC_EnableIRQ(TWI0_IRQn);
  // write a few registers to init the sensors
  //imu_reg_write(ACCEL_ADDR, 0x20, 0x00); // low-power mode
  imu_reg_write(ACCEL_ADDR, 0x20, 0x57); // turn on all axes
  imu_reg_write(ACCEL_ADDR, 0x23, 0x88);
  imu_reg_write(MAG_ADDR  , 0x00, 0x9c);
  imu_reg_write(MAG_ADDR  , 0x01, 0x80); // no idea what range should be
  //imu_reg_write(MAG_ADDR  , 0x02, 0x03); // sleep mode
  imu_reg_write(MAG_ADDR  , 0x02, 0x00); // continuous-conversion mode

  g_imu_data[0] = 42;
}
Esempio n. 11
0
File: main.c Progetto: gstroe/Arm
/**
 * Configure the TWI and DACC for audio output.
 * \param sampleRate Audio sample rate.
 * \param mck        MCK frequency.
 */
static void _ConfigureAudioPlay(uint32_t sampleRate, uint32_t mck)
{
	/* -- Pins Configuration -- */
	PIO_Configure(pinsAudio, PIO_LISTSIZE(pinsAudio));

	/* -- SSC Configuration -- */
	sampleRate = sampleRate; /*dummy */
	SSC_Configure(SSC, 0, mck);
	SSC_DisableTransmitter(SSC);
	SSC_DisableReceiver(SSC);
	SSC_ConfigureTransmitter(SSC, I2S_SLAVE_TX_SETTING, I2S_SLAVE_TX_FRM_SETTING);
	SSC_DisableTransmitter(SSC);

	/* Enable TWI peripheral clock */
	PMC_EnablePeripheral(ID_TWIHS0);
	/* Configure and enable the TWI (required for accessing the DAC) */
	TWI_ConfigureMaster(TWIHS0, TWI_CLOCK, mck);
	TWID_Initialize(&twid, TWIHS0);

	/* Initialize the audio DAC
	 */
	WM8904_Write(&twid, WM8904_SLAVE_ADDRESS, WM8904_REG_RESET, 0);
	Wait(100);

	/* WM8904 as master */
	if (WM8904_Read(&twid, WM8904_SLAVE_ADDRESS, 0) != 0x8904) {
		printf("WM8904 not found!\n\r");

		while (1);
	}

	WM8904_Init(&twid, WM8904_SLAVE_ADDRESS, PMC_MCKR_CSS_SLOW_CLK);
	_SyncAdjust(0);
	PMC_ConfigurePCK2(PMC_MCKR_CSS_SLOW_CLK, PMC_MCKR_PRES_CLK_1);
	/* Mute */
	AudioPlayEnable(0);
}
Esempio n. 12
0
//------------------------------------------------------------------------------
/// Main function
//------------------------------------------------------------------------------
int main(void)
{
    unsigned char key;
    unsigned char isValid;

    // Configure all pins
    PIO_Configure(pins, PIO_LISTSIZE(pins));

    LED_Configure(0);
    LED_Set(0);
    LED_Configure(1);
    LED_Set(1);

    // Initialize the DBGU
    TRACE_CONFIGURE(DBGU_STANDARD, 115200, BOARD_MCK);

    // Switch to Main clock
    AT91C_BASE_PMC->PMC_MCKR = (AT91C_BASE_PMC->PMC_MCKR & ~AT91C_PMC_CSS) | AT91C_PMC_CSS_MAIN_CLK;
    while ((AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MCKRDY) == 0);

    // Configure PLL to 98.285MHz
    *AT91C_CKGR_PLLR = ((1 << 29) | (171 << AT91C_CKGR_MUL_SHIFT) \
        | (0x0 << AT91C_CKGR_OUT_SHIFT) |(0x3f << AT91C_CKGR_PLLCOUNT_SHIFT) \
        | (21 << AT91C_CKGR_DIV_SHIFT));
    while ((AT91C_BASE_PMC->PMC_SR & AT91C_PMC_LOCK) == 0);

    // Configure master clock in two operations
    AT91C_BASE_PMC->PMC_MCKR = (( AT91C_PMC_PRES_CLK_2 | AT91C_PMC_CSS_PLLA_CLK) & ~AT91C_PMC_CSS) | AT91C_PMC_CSS_MAIN_CLK;
    while ((AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MCKRDY) == 0);
    AT91C_BASE_PMC->PMC_MCKR = ( AT91C_PMC_PRES_CLK_2 | AT91C_PMC_CSS_PLLA_CLK);
    while ((AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MCKRDY) == 0);

    // DBGU reconfiguration
    DBGU_Configure(DBGU_STANDARD, 115200, SSC_MCK);

    // Configure and enable the TWI (required for accessing the DAC)
    *AT91C_PMC_PCER = (1<< AT91C_ID_TWI0); 
    TWI_ConfigureMaster(AT91C_BASE_TWI0, TWI_CLOCK, SSC_MCK);
    TWID_Initialize(&twid, AT91C_BASE_TWI0);

    printf("-- OsmoSDR firmware (" BOARD_NAME ") " GIT_REVISION " --\n\r");
    printf("-- Compiled: %s %s --\n\r", __DATE__, __TIME__);

	req_ctx_init();
	PIO_InitializeInterrupts(0);

	cmd_state.out = vprintf;
	uart_cmd_reset(&cmd_state);
	uart_cmds_register(cmds, sizeof(cmds)/sizeof(cmds[0]));

	fastsource_init();
	VBus_Configure();

	power_peripherals(1);

	si570_init(&si570, &twid, SI570_I2C_ADDR);
	set_si570_freq(30000000);

	sam3u_e4k_init(&e4k, &twid, E4K_I2C_ADDR);
	e4k.vco.fosc = 30000000;

	osdr_fpga_init(SSC_MCK);
	//osdr_fpga_reg_write(OSDR_FPGA_REG_ADC_TIMING, (1 << 8) | 255);
	//osdr_fpga_reg_write(OSDR_FPGA_REG_PWM1, (1 << 400) | 800);
	osdr_fpga_set_iq_swap(0);

	ssc_init();
	e4k_init(&e4k);
	e4k_init(&e4k);

    // Enter menu loop
    while (1) {

    	if (DBGU_IsRxReady()) {
        	key = DBGU_GetChar();
        	// Process user input
        	if (uart_cmd_char(&cmd_state, key) == 1) {
        		//ssc_stats();
        	}
    	}
    	ssc_dma_start();
    	fastsource_start();
    }
}
Esempio n. 13
0
File: main.c Progetto: gstroe/Arm
/**
 *  \brief gmac_uip_telnetd example entry point.
 *
 *  \return Unused (ANSI-C compatibility).
 */
int main(void)
{
	uip_ipaddr_t ipaddr;
	struct timer periodic_timer, arp_timer;
	uint32_t i;
	struct uip_eth_addr OrigiGMacAddr;

	/* Disable watchdog */
	WDT_Disable(WDT);

	SCB_EnableICache();
	SCB_EnableDCache();

	TimeTick_Configure();
	printf("-- GMAC uIP Telnetd Example %s --\n\r", SOFTPACK_VERSION);
	printf("-- %s\n\r", BOARD_NAME);
	printf("-- Compiled: %s %s With %s--\n\r", __DATE__, __TIME__ ,
			COMPILER_NAME);

	/* Configure systick for 1 ms. */
	TimeTick_Configure();
	/* Configure TWI pins. */
	PIO_Configure(twiPins, PIO_LISTSIZE(twiPins));
	/* Enable TWI */
	PMC_EnablePeripheral(BOARD_ID_TWI_EEPROM);
	TWI_ConfigureMaster(BOARD_BASE_TWI_EEPROM, TWCK, BOARD_MCK);
	TWID_Initialize(&twid, BOARD_BASE_TWI_EEPROM);
	/* Display MAC & IP settings */
	TWID_Read(&twid, AT24MAC_SERIAL_NUM_ADD, 0x9A, 1, OrigiGMacAddr.addr, PAGE_SIZE,
				0);

	if ((OrigiGMacAddr.addr[0] == 0xFC) && (OrigiGMacAddr.addr[1] == 0xC2)
		&& (OrigiGMacAddr.addr[2] == 0x3D)) {
		for (i = 0; i < 6; i++)
			GMacAddress.addr[i] = OrigiGMacAddr.addr[i];
	}

	printf("-- MAC %x:%x:%x:%x:%x:%x\n\r",
			GMacAddress.addr[0], GMacAddress.addr[1], GMacAddress.addr[2],
			GMacAddress.addr[3], GMacAddress.addr[4], GMacAddress.addr[5]);

#ifndef __DHCPC_H__
	printf(" - Host IP  %d.%d.%d.%d\n\r",
			HostIpAddress[0], HostIpAddress[1], HostIpAddress[2], HostIpAddress[3]);
	printf(" - Router IP  %d.%d.%d.%d\n\r",
			RoutIpAddress[0], RoutIpAddress[1], RoutIpAddress[2], RoutIpAddress[3]);
	printf(" - Net Mask  %d.%d.%d.%d\n\r",
			NetMask[0], NetMask[1], NetMask[2], NetMask[3]);
#endif

	/* System devices initialize */
	gmac_tapdev_setmac((uint8_t *)GMacAddress.addr);
	gmac_tapdev_init();
	clock_init();
	timer_set(&periodic_timer, CLOCK_SECOND / 2);
	timer_set(&arp_timer, CLOCK_SECOND * 10);

	/* Init uIP */
	uip_init();

#ifdef __DHCPC_H__
	printf("P: DHCP Supported\n\r");
	uip_ipaddr(ipaddr, 0, 0, 0, 0);
	uip_sethostaddr(ipaddr);
	uip_ipaddr(ipaddr, 0, 0, 0, 0);
	uip_setdraddr(ipaddr);
	uip_ipaddr(ipaddr, 0, 0, 0, 0);
	uip_setnetmask(ipaddr);
#else
	/* Set the IP address of this host */
	uip_ipaddr(ipaddr, HostIpAddress[0], HostIpAddress[1],
				HostIpAddress[2], HostIpAddress[3]);
	uip_sethostaddr(ipaddr);

	uip_ipaddr(ipaddr, RoutIpAddress[0], RoutIpAddress[1],
				RoutIpAddress[2], RoutIpAddress[3]);
	uip_setdraddr(ipaddr);

	uip_ipaddr(ipaddr, NetMask[0], NetMask[1], NetMask[2], NetMask[3]);
	uip_setnetmask(ipaddr);
#endif
	uip_setethaddr(GMacAddress);
	_app_init();

	while (1) {
		uip_len = gmac_tapdev_read();

		if (uip_len > 0) {
			if (BUF->type == htons(UIP_ETHTYPE_IP)) {
				uip_arp_ipin();
				uip_input();

				/* If the above function invocation resulted in data that
					should be sent out on the network, the global variable
					uip_len is set to a value > 0. */
				if (uip_len > 0) {
					uip_arp_out();
					gmac_tapdev_send();
				}
			} else if (BUF->type == htons(UIP_ETHTYPE_ARP)) {
					uip_arp_arpin();

				/* If the above function invocation resulted in data that
					should be sent out on the network, the global variable
					uip_len is set to a value > 0. */
				if (uip_len > 0)
					gmac_tapdev_send();
			}
		} else if (timer_expired(&periodic_timer)) {
			timer_reset(&periodic_timer);

			for (i = 0; i < UIP_CONNS; i++) {
				uip_periodic(i);

				/* If the above function invocation resulted in data that
					should be sent out on the network, the global variable
					uip_len is set to a value > 0. */
				if (uip_len > 0) {
					uip_arp_out();
					gmac_tapdev_send();
				}
			}

#if UIP_UDP

			for (i = 0; i < UIP_UDP_CONNS; i++) {
				uip_udp_periodic(i);

				/* If the above function invocation resulted in data that
					should be sent out on the network, the global variable
					uip_len is set to a value > 0. */
				if (uip_len > 0) {
					uip_arp_out();
					gmac_tapdev_send();
				}
			}

#endif /* UIP_UDP */

			/* Call the ARP timer function every 10 seconds. */
			if (timer_expired(&arp_timer)) {
				timer_reset(&arp_timer);
				uip_arp_timer();
			}
		}
	}
}
Esempio n. 14
0
extern int main( void )
{
    volatile uint32_t delay;
    uint8_t i;
    uint8_t SNo[16];
    Async async;
    /* Disable watchdog */
    WDT_Disable( WDT ) ;

    /* Enable I and D cache */
    SCB_EnableICache();
    SCB_EnableDCache();
    
    CallBackFired = 0;
    
    /* Output example information */
    printf("-- TWI EEPROM Example %s --\n\r", SOFTPACK_VERSION);
    printf("-- %s\n\r", BOARD_NAME);
    printf("-- Compiled: %s %s --\n\r", __DATE__, __TIME__);
    
    TimeTick_Configure();
    
    /* Configure TWI pins. */
    PIO_Configure(pins, PIO_LISTSIZE(pins));
    PMC_EnablePeripheral(BOARD_ID_TWI_EEPROM);
    /* Configure TWI */
    
    twi_dma.pTwid = malloc(sizeof(Twid));
    twi_dma.pTwiDma = malloc(sizeof(sXdmad));
    
    TWI_ConfigureMaster(BOARD_BASE_TWI_EEPROM, TWCK, BOARD_MCK);
    TWID_Initialize(&twid, BOARD_BASE_TWI_EEPROM);
    TWID_DmaInitialize(&twi_dma, BOARD_BASE_TWI_EEPROM, 0);

    TWID_Read(&twid, AT24MAC_SERIAL_NUM_ADD, 0x80, 1, SNo, PAGE_SIZE, 0);

    /* Erase all page */
    memset(pData, 0, PAGE_SIZE);
    for(i=0; i< EEPROM_PAGES; i++)
    {
        printf("-I- Filling page #%d with zeroes ...\r\n", i);
        TWID_Write(&twid, AT24MAC_ADDRESS, i*PAGE_SIZE, 1, pData, PAGE_SIZE, 0);
        /* Wait at least 10 ms */
        Wait(10);
    }
    printf("\r\n");

    _fillBuffer(pData);

    /* Synchronous operation */
    for(i=0; i< EEPROM_PAGES; i++)
    {
        printf("\n\r-I- Filling page #%d with checkerboard pattern ...\r", i);
        TWID_DmaWrite(&twi_dma, AT24MAC_ADDRESS, i*PAGE_SIZE, 1, pData, PAGE_SIZE, 0);
        /* Wait at least 10 ms */
        Wait(10);
    }
    printf("\r\n");


    /* Read back data */
    memset(pData, 0, PAGE_SIZE);
    for(i=0; i< EEPROM_PAGES; i++)
    {
        printf("-I- Reading page #%d... ", i);
        TWID_DmaRead(&twi_dma, AT24MAC_ADDRESS, i*PAGE_SIZE, 1, pData, PAGE_SIZE, 0);
        /* Wait at least 10 ms */
        Wait(10);
        _checkReadBuffer(pData);
    }
     printf("\r\n");

    /* Configure TWI interrupts */
    NVIC_ClearPendingIRQ(TWIHS0_IRQn);
    NVIC_EnableIRQ(TWIHS0_IRQn);

    /* Asynchronous operation */
    printf("-I- Read/write on page #0 (IRQ mode)\n\r");

    /* Write checkerboard pattern in first page */
    _fillBuffer(pData);
    memset(&async, 0, sizeof(async));
    async.callback = (void *) TestCallback;

    for(i=0; i< EEPROM_PAGES; i++)
    {
        printf("-I- Filling page #%d with checkerboard pattern ...\r", i);
        TWID_Write(&twid, AT24MAC_ADDRESS, i*PAGE_SIZE, 1, pData, PAGE_SIZE, &async);
        while (!ASYNC_IsFinished(&async));
        /* Wait at least 10 ms */
        Wait(10);
    }
    printf("\r\n");


    /* Read back data */
    memset(pData, 0, PAGE_SIZE);
    memset(&async, 0, sizeof(async));
    async.callback = (void *) TestCallback;
    for(i=0; i< EEPROM_PAGES; i++)
    {
        printf("-I- Reading page # %d...\r", i);
        TWID_Read(&twid, AT24MAC_ADDRESS, i*PAGE_SIZE, 1, pData, PAGE_SIZE, &async);
        while ( !ASYNC_IsFinished( &async ) ) ;
        /* Wait at least 10 ms */
        Wait(10);
        _checkReadBuffer(pData);
    }
    printf("\r\n Callback Fired %d times", CallBackFired);

    return 0 ;
}