Beispiel #1
0
int do_sd_initialize (void) {

	/* Initialize and enable the SPI module */
	P1SEL = 0x00E; // Setup P1 for SPI mode
	P1OUT |= 0x000; // Setup P3.4 as the SS signal, active low. So, initialize it high.
	P1DIR |= 0x000; // Set up P3.4 as an output
	U0CTL = (CHAR | SYNC | MM | SWRST); // 8-bit, SPI, Master
	U0TCTL = (SSEL1 | STC | CKPH); // Normal polarity, 3-wire
	U0BR0 = 0x002; // SPICLK = SMCLK/2 (2=Minimum divisor)
	U0BR1 = 0x000;
	U0MCTL = 0x000;
	ME1 |= USPIE0; // Module enable
	U0CTL &= ~SWRST; // SPI enable

	/* Set the baud-rate divisor. The correct value is computed by dividing
	the clock rate by the desired baud rate. The minimum divisor allowed
	is 2. */
	U0CTL |= SWRST; // Temporarily disable the SPI module
	U0BR1 = (PERIPH_CLOCKRATE/400000) >> 8;
	U0BR0 = (PERIPH_CLOCKRATE/400000);
	U0CTL &= ~SWRST; // Re-enable SPI

	/* Initialization OK? */
	if (sd_initialize() != 1)
		return 0;
	/* Set the maximum SPI clock rate possible */
	spi_set_divisor(2);
	return 1;

}
uint8_t fs_mount_chip()	// Starts the SD card and 4 lines of code must be here
{

 sd.write_timeout = 1000;
 sd.read_timeout = 1000;
 sd.busy_flag = 0;
 ready=sd_initialize(&sd);

return ready;
}
Beispiel #3
0
int do_sd_initialize (sd_context_t *sdc)
{
	/* Initialize the SPI controller */
	spi_initialize();
	/* Set the maximum SPI clock rate possible */
	spi_set_divisor(PERIPH_CLOCKRATE/400000);
	/* Initialization OK? */
	if (sd_initialize(sdc) != 1)
		return 0;
        spi_set_divisor(2);   //---- 2011 0905 spi full speed
	return 1;
}
Beispiel #4
0
DSTATUS disk_initialize(BYTE drv)
{
    DSTATUS status = RES_PARERR;

    spi1_lock();
    {
        switch(drv)
        {
            case driveNumFlashMem: status = flash_initialize();    break;
            case driveNumSdCard:   status = sd_initialize();       break;
            default: status = RES_PARERR;    break;
        }
    }
    spi1_unlock();

    return status;
}
Beispiel #5
0
int
main(void)
{
#if WITH_SD
  int r;
#endif /* WITH_SD */

  msp430_cpu_init();	
  watchdog_stop();

  /* Platform-specific initialization. */
  msb_ports_init();
  adc_init();

  clock_init();
  rtimer_init();

  sht11_init();
  leds_init();
  leds_on(LEDS_ALL);

  irq_init();
  process_init();

  /* serial interface */
  rs232_set_input(serial_line_input_byte);
  rs232_init();
  serial_line_init();

  uart_lock(UART_MODE_RS232);
  uart_unlock(UART_MODE_RS232);
#if WITH_UIP
  slip_arch_init(BAUD2UBR(115200));
#endif


#if WITH_SD
  r = sd_initialize();
  if(r < 0) {
    printf("Failed to initialize the SD driver: %s\n", sd_error_string(r));
  } else {
    sd_offset_t capacity;
    printf("The SD driver was successfully initialized\n");
    capacity = sd_get_capacity();
    if(capacity < 0) {
      printf("Failed to get the SD card capacity: %s\n", sd_error_string(r));
    } else {
      printf("SD card capacity: %u MB\n",
	(unsigned)(capacity / (1024UL * 1024)));
    }
  }
#endif

  /* System services */
  process_start(&etimer_process, NULL);
  ctimer_init();

  node_id_restore();

  init_net();

  energest_init();
 
#if PROFILE_CONF_ON
  profile_init();
#endif /* PROFILE_CONF_ON */
 
  leds_off(LEDS_ALL);

  printf(CONTIKI_VERSION_STRING " started. Node id %u, using %s.\n", 
         node_id, rime_mac->name);

  autostart_start(autostart_processes);

  /*
   * This is the scheduler loop.
   */
  ENERGEST_ON(ENERGEST_TYPE_CPU);

  while (1) {
    int r;
#if PROFILE_CONF_ON
    profile_episode_start();
#endif /* PROFILE_CONF_ON */
    do {
      /* Reset watchdog. */
      watchdog_periodic();
      r = process_run();
    } while(r > 0);

#if PROFILE_CONF_ON
    profile_episode_end();
#endif /* PROFILE_CONF_ON */

    /*
     * Idle processing.
     */
    int s = splhigh();		/* Disable interrupts. */
    if (process_nevents() != 0) {
      splx(s);			/* Re-enable interrupts. */
    } else {
      static unsigned long irq_energest = 0;
      /* Re-enable interrupts and go to sleep atomically. */
      ENERGEST_OFF(ENERGEST_TYPE_CPU);
      ENERGEST_ON(ENERGEST_TYPE_LPM);
     /*
      * We only want to measure the processing done in IRQs when we
      * are asleep, so we discard the processing time done when we
      * were awake.
      */
      energest_type_set(ENERGEST_TYPE_IRQ, irq_energest);

      if (uart_edge) {
	_BIC_SR(LPM1_bits + GIE);
      } else {
	_BIS_SR(LPM1_bits + GIE);
      }

      /*
       * We get the current processing time for interrupts that was
       * done during the LPM and store it for next time around. 
       */
      dint();
      irq_energest = energest_type_time(ENERGEST_TYPE_IRQ);
      eint();
      ENERGEST_OFF(ENERGEST_TYPE_LPM);
      ENERGEST_ON(ENERGEST_TYPE_CPU);
#if PROFILE_CONF_ON
      profile_clear_timestamps();
#endif /* PROFILE_CONF_ON */
    }
  }

  return 0;
}
Beispiel #6
0
DSTATUS disk_initialize( BYTE pdrv ) // Physical drive nmuber to identify the drive
{
  return sd_initialize();
}