示例#1
0
void main (void) {
    WDTCTL = WDTPW | WDTHOLD;          // Letiltjuk a watchdog idõzítõt
    P1OUT = 0;                         // A nem használt kimeneteket lehúzzuk
    P1DIR = ~(BIT2+BIT3+BIT5);         // Csak RXD, SW2 és AN5 legyen bemenet
    P1SEL |= BIT6;                     // P1.6 legyen TA0.1 kimenet
//-- P1.3 belsõ felhúzás bekapcsolása ------
    P1OUT |= BIT3;                     // Felfelé húzzuk, nem lefelé
    P1REN |= BIT3;                     // Belsõ felhúzás bekapcsolása P1.3-ra
//-- Analóg bemenet engedélyezése ----------    
    ADC10AE0 = BIT5;                   // Enable analog input on AN5/P1.5
//-- Timer_A PWM 125Hz, OUT1 kimeneten, SMCLK/8 órajellel, "Felfelé számlálás"
    TACCR0 = BITA - 1;                 // A periódus ADC10-hez illeszkedõ (1023)
    TACCTL0 = OUTMOD_4;                // Toggle mód (OUT0 indítja az ADC-t)
    TACCR1 = BIT9;                     // CCR1 induláskor 50%-ra (512)
    TACCTL1 = OUTMOD_7;                // Reset/set PWM mód beállítása
    TACTL = TASSEL_2 |                 // SMCLK az órajel forrása
                ID_3 |                 // 1:8 osztás bekapcsolása
                MC_1 |                 // Felfelé számláló mód
                TACLR;                 // TAR törlése
//-- ADC  konfigurálás ---------------------
    ADC10CTL0 = ADC10SHT_0             // mintavétel: 4 óraütés
              | ADC10ON                // Az ADC bekapcsolása
              | SREF_0;                // VR+ = AVCC és VR- = AVSS
    ADC10CTL1 = INCH_5                 // A5 csatorna kiválasztása
              | SHS_2                  // Hatdveres triggerelés (TA0.0)     
              | ADC10SSEL_0            // ADC10OSC adja az órajelet (~5 MHz)
              | CONSEQ_2;              // Ismételt egycsatornás konverzió
    ADC10DTC0 = ADC10CT;               // Folyamatos adatátvitel, egy blokk
    ADC10DTC1 = 1;                     // Egyetlen target cím a memóriában
    ADC10SA = (unsigned short) &TACCR1;// A target cím
    ADC10CTL0 |= ENC;                  // A konverzió engedélyezése
    __low_power_mode_0();              // Sem CPU, sem interrupt nem kell már!
 }
示例#2
0
void main (void)
{
    WDTCTL = WDTPW | WDTHOLD;          // Stop watchdog
    P1OUT = 0;                         // Drive unused pins low
    P1DIR = ~(BIT2+BIT3+BIT5);         // Only RXD, SW2 and AN5 are inputs
    P1SEL |= BIT6;                     // Configure P1.6 as TA0.1 output
//-- Enable P1.3 inner pullup ---------
    P1OUT |= BIT3;                     // Pull up (not down)
    P1REN |= BIT3;                     // Enable inner pullup/pulldown for P1.3
//-- Timer_A for PWM at 125Hz on OUT1, SMCLK/8, Up mode
    TACCR0 = BITA - 1;                 // Upper limit to match ADC10MEM (1023)
    TACCTL0 = OUTMOD_4;                // Toggle OUT0 to stimulate ADC10
    TACCR1 = BIT9;                     // About 50% to start PWM (512)
    TACCTL1 = OUTMOD_7;                // Reset/set for positive PWM
    TACTL = TASSEL_2|ID_3|MC_1|TACLR;  // SMCLK/8, Up mode, clear
//-- ADC on, refs VCC, VSS, sample 4 cycles, int ref off, interrupts
    ADC10CTL0 = SREF_0 | ADC10SHT_0 | ADC10ON | ADC10IE;
//-- Input channel 5, start on rising edge of OUT0, no clock division,
//   internal ADC clock, single channel repeated conversions
    ADC10CTL1 = INCH_5 | SHS_2 | ADC10DIV_0 | ADC10SSEL_0 | CONSEQ_2;
    ADC10AE0 = BIT5;                   // Enable analog input on AN5/P1.5
    ADC10CTL0 |= ENC;                  // Enable conversions
    for (;;) {                         // Loop forever taking measurements
        __low_power_mode_0();          // All action in ISR for CCIFG0
    }
}
示例#3
0
void main(void) {
	BCSCTL1 = CALBC1_16MHZ;               		// 16MHz clock
	DCOCTL  = CALDCO_16MHZ;

//watch dog as interval timer, clear, SMCLK/ 8192 = 1.5kHz (0.7mS)
//Pass Word, Timer Mode Select= Interval Timer, Count Clear, Interval Selection = divide by 8192
	WDTCTL = WDTPW | WDTTMSEL | WDTCNTCL | WDTIS0 ;
//enable WD interrupt, set Interrupt Enable Register 1 bit 0 to true (1)
	IE1 |= 0x01;
//clean up port 2 because it is unused
//Select = 0 (digital I/O selected), Dir =0 (inputs), enable the pull down (P2OUT=0 ???) on the unused outputs and crystal pins
	P2SEL = 0;
	P2DIR = 0;
	P2REN = BIT0 | BIT1 | BIT2 | BIT3 | BIT4 | BIT5 | BIT6 | BIT7;
//USI will override these settings for SCLK, SDI and SDO (but not P1.4)
	P1OUT = BIT4;
	P1DIR = BIT4;//only P1.4 will be the SlaveSelect output handled by software
	P1REN = BIT0 | BIT1 | BIT2 | BIT3 ; //pull the resistors on the unused pins
//enable SDI, SDO, SCLK, MSB first !!! NG, master, USIIGE is not being used, output enable, software reset
	USICTL0 = USIPE7 | USIPE6 | USIPE5 | USIMST | USIOE | USISWRST;
// CPHA = 1 now, SPI not I2C, USI counter Interrupt Enable, set the Interrupt Flag
	USICTL1 = USICKPH | USIIE | USIIFG;// can't clear the USIIFG in reset mode
//SCLK = SMCLK / 128, clock idles low
	USICKCTL = USIDIV_7 | USISSEL_2;
	USICTL0 &= ~USISWRST; //release from reset
	USICTL1 &= ~USIIFG; //avoid unwanted interrupt
	for ( ; ; ){//loop forever with interrupts
		__low_power_mode_0();//LPM0 between interrupts
		//++waitRaise; delay cycles removed the potential use of this
	}
}
示例#4
0
/*
 * \brief Transmits a string over UART.
 * \param str The string to transmit, terminated by a '\0' character.
 * \return 
 *
 *
 */
void UART_tx_string (char * str)
{
  while ( *str != '\0' ) {
    start_UART_tx_char(*str);
    __low_power_mode_0(); //go to low power until tx has finished, but keep SMCLK on.
    str++;
  }
}
示例#5
0
/**
 *  @fn void MCUSleep(uint8_t mode)
 *
 *  @brief Puts the microcontroller into a low power mode - "sleep state".
 *
 *  @param mode an unsigned int
 */
void MCUSleep(uint8_t mode)
{
  #if defined(__MCU_MSP430_SERIES)
  // TODO: Definition of implementing low power mode must be further defined.
  // NOTE: There are 5 different low power modes for the MSP430 (0 - CPUOFF, 1, 
  //       2, 3, 4).
    __low_power_mode_0();
  #endif
}
示例#6
0
void main(void)
{
  	Init();

	//switch to idle mode
	__low_power_mode_0();
	
	return;
}
示例#7
0
/*
 * \brief Echo back character received from UART.
 * \param
 * \return 
 *
 *
 */
void UART_echo_mode(void)
{
  if (UART_mode == UART_RECEIVED) {
    // If the device has recieved a value
    UART_mode = UART_IDLE;
    start_UART_tx_char(UART_rx_char);
  } else {
    __low_power_mode_0();        
    // LPM0, the PORT1 interrupt will wake the processor up. This is so that it does not
    //	endlessly loop when no value has been Received.
  }
}
示例#8
0
/**
 *  @function void COMPortWrite(uint8_t peripheral, uint8_t block, uint8_t * pBuffer, uint8_t count)
 *
 *  @brief This function writes to the specified COM port. It has two functionalities 
 *         depending on its operation.
 *         Blocking: Processor is put in low power mode 0 until the write operation 
 *         is complete.
 *         Non-Blocking: The data to be written is sent to the COM port and processor 
 *         continues with its operation. 
 *
 *  @param peripheral an unsigned int
 *  @param block an unsigned int
 *  @param pBuffer an unsigned integer pointer
 *  @param count an unsigned int
 */
void COMPortWrite(uint8_t peripheral, uint8_t block, uint8_t * pBuffer, uint8_t count)
{  
  // Perform UART blocking write operation.
  CommunicationReadWrite(peripheral, pBuffer, count, 1, 1);
  
  // Check if blocking UART write
  if (block == 1)  // Blocking functionality
  {
    // Turn the CPU off until the operation is complete.
//    while (CommStructure[peripheral]->done == 0)
    while (CommStructure[peripheral]->done == 0)
    { // NOTE: This is a potential deadlock if done is set between while and low power mode.
      __low_power_mode_0();
      __no_operation();
    } 
    // Operation is done.
    CommStructure[peripheral]->done = 0;
  }
}
示例#9
0
void main(void) {
  WDTCTL = WDTPW | WDTHOLD;   // Stop watchdog timer

  initUART();

  P1OUT = 0;                  // Preload LEDs off (active high!)
  P1DIR |= LED1|LED2;         // Set pin with LED1 to output
  P1REN |= B1;                // Enable pull up/down resistor for B1 (P1.3)
  P1OUT |= B1;                // set as pull up resistor for B1 (P1.3)
  P1IE |= B1;                 // Enable interrupts on edge
  P1IES |= B1;                // Sensitive to negative edge (H->L)

  do {
    P1IFG = 0;                // Clear any pending interrupts ...
  } while (P1IFG != 0);       // ... until none remain

  for (;;) {                  // Loop forever (should not need)
    __low_power_mode_0 ();    // LPM0 with int'pts
  }
}
示例#10
0
//MAIN DEL PROGRAMA
int main(void)
{
    //Config uC
    Config_uC();

    //Config Peripherals
    Config_Peripherals();

    //Inicializa las Variables
    init_variables();

    //Habilita las interrupciones
    __enable_interrupt();

    for(;;)
    {
        //Activa el modo bajo consumo
        __low_power_mode_0();

        //Si hay alguna tarea activa
        while(task.total != OFF)
        {
            /********************************/

            //si task.f0 activa
            if(task.f0 == ON)
            {
                task.f0 = OFF; //Limpia la flag
                //si hay pausa pon el contador de secuencia a 0
                //comienza una nueva secuencia
                if(last_pause != 0)
                {
                    c_sequence = 0;

                }

            }//end if(task.f0 == ON)

            /********************************/
            //si task.f1 activada
            //Si hemos soltado el boton activa esta tarea
            //Añade el simbolo correspondiente a la secuencia
            if(task.f1 == ON)
            {
                task.f1 = OFF; //Limpia el flag

                if(symbol == DASH)
                {
                    sequence[c_sequence] = '-';
                }
                else
                {
                    sequence[c_sequence] = '.';
                }

                c_sequence++; //+1 para el siguiente simbolo

            }//end if(task.f1 == ON)

            /********************************/
            //LED1 ON
            if(task.f2 == ON)
            {
                task.f2 = OFF; //limpia la flag
                P1OUT_bit.P0 = LED_ON; //led1 on

                //ACTIVATE TIMER
                TA1CTL_bit.TACLR = ON; //Inicia la cuenta
                TA1CTL_bit.MC0 = ON; //Empieza la cuenta
                TA1CCTL0_bit.CCIFG = OFF; //Limpia la flag de interrupcion Timer1
                TA1CCTL0_bit.CCIE = ON; //Habilita la interrupcion Timer1

            }//end if(task.f2 == ON)

            /********************************/
            //LED2 ON
            if(task.f3 == ON)
            {
                task.f3 = OFF; //Limpia la Flag
                P1OUT_bit.P6 = LED_ON; //Enciende Led2

                //ACTIVATE  TIMER
                TA1CTL_bit.TACLR = ON; //Inicia la cuenta
                TA1CTL_bit.MC0 = ON; //Empieza la cuenta
                TA1CCTL0_bit.CCIFG = OFF; //Limpia la flag
                TA1CCTL0_bit.CCIE = ON;  //Habilita la interrupcion Timer1

            }//end if(task.f3 == ON)

        }//end  while(task.total != OFF)

    }//end for(;;)

}//end main(void)
示例#11
0
/**
 * @brief Entry Low Power Mode 0
 */
void entryLowPowerMode0()
{
	__low_power_mode_0();
}
示例#12
0
int main( void )
{
  // The temperature reading from the external temperature sensor (after conversion from ADC counts)
  unsigned int temperature = 25;
  unsigned int timeLimit = 480;
  
  // Stop watchdog timer to prevent time out reset
  WDTCTL = WDTPW + WDTHOLD;  
  
  // Disable interrupts for the setup
  //__disable_interrupt();

  // Enable the crystal osc fault. The xtal startup process
  IE1 |= OFIE;     // An immedate Osc Fault will occur next

  // Set up clock system (remember its hex) also for future ref, no MAGIC Numbers! I mean do you remember what any of these do?! now you have to look them up again
  BCSCTL1 = 0x0080;
  BCSCTL2 = 0x0088;
  BCSCTL3 = 0x0004;
  
  // Set up the timer A - Use the system master crystal and have it count up
  // With this crystal TACCR will be 32768
  TACTL = TACLR | TASSEL0; // Clear timer A, Select clock source 0 (LFXTAL)
  TACCR0 = 32768;          // 0ne Second PLZ! 
  
  // Setting up the ADC, will make some changes later
  ADC10CTL0 = REFON | REFBURST | ADC10SR | ADC10SHT0 | ADC10SHT1 | SREF0 ;
  ADC10CTL1 = 0x0000; // THIS SETS INCHx TO A0
  ADC10AE0 = BIT0; //ENABLE THE 0 PIN FOR ADC USE

  //Setup is done------------------------
  
  //Enable interrupts now that setup is done
  __enable_interrupt();
  
  // Enable the compare ISR on TimerA CCR0
  TACCTL0 |= CCIE;
  
  //Starting the timer in up mode
  TACTL |= MC0;   // going into up mode starts the (one second) timer!
  
  // ADC STUFF---------------------------
  // Turn on the ADC and ref voltage
  ADC10CTL0 |=  ADC10ON + REFON + ENC + ADC10SC; //this will also take readings and start conversion, ADC interrupts when conversion is done
  
  //LOOPS
  while(1)
  {
    if(gState & ADCMATH){
      // Add all the conversion math goes here!!
      temperature = gTemp;
    }
    else if(gState & TATICK){
      if(gTimerTicks >= timeLimit){
        
      }
    }
  else __low_power_mode_0();
  }
  return 0;
}
/*--------------------------------------------------------------------------*/
int
main(int argc, char **argv)
{
  /*
  * Initalize hardware.
  */
  msp430_cpu_init();
  clock_init();

  uart_init(9600); /* Must come before first printf */

  /* xmem_init(); */

  PRINTF("iWatch 0.10 build at " __TIME__ " " __DATE__ "\n");
  UCSCTL8 &= ~BIT2;
  
  /*
  * Hardware initialization done!
  */

  /*
  * Initialize Contiki and our processes.
  */
  process_init();
  process_start(&etimer_process, NULL);
  
  rtimer_init();
  ctimer_init();

  energest_init();
  ENERGEST_ON(ENERGEST_TYPE_CPU);

  backlight_init();
  battery_init();
  SPI_FLASH_Init();

  if (system_testing())
  {
    clock_time_t t;

    backlight_on(200, 0);
    t = clock_seconds();
    // sleep 1
    while(clock_seconds() - t <= 3);
    printf("$$OK BACKLIGHT\n");
    t = clock_seconds();
    while(clock_seconds() - t <= 3);
    backlight_on(0, 0);

    motor_on(200, 0);
    // sleep 1s
    t = clock_seconds();
    while(clock_seconds() - t <= 3);
    printf("$$OK MOTOR\n");
    t = clock_seconds();
    while(clock_seconds() - t <= 3);
    motor_on(0, 0);

#if PRODUCT_W001
    I2C_Init();
    codec_init();
    codec_bypass(1);
    // sleep 1s
    t = clock_seconds();
    while(clock_seconds() - t <= 3);
    printf("$$OK MIC\n");
    // sleep 1s
    t = clock_seconds();
    while(clock_seconds() - t <= 3);
    codec_bypass(0);

    codec_shutdown();
#endif
  }

  int reason = CheckUpgrade();

  window_init(reason);

  button_init();
  rtc_init();
  CFSFontWrapperLoad();

  system_init(); // check system status and do factor reset if needed

  I2C_Init();

  //codec_init();
  //ant_init();
  bluetooth_init();

#ifdef PRODUCT_W004
  //bmx_init();
#else
  mpu6050_init();
#endif

  // check the button status
  if (button_snapshot() & (1 << BUTTON_UP))
  {
    clock_time_t t;
    // delay 1 second
    // button up is pressed, we will set emerging flag
    motor_on(200, CLOCK_SECOND * 2);
    t = clock_seconds();
    while(clock_seconds() - t <= 1);

    if (button_snapshot() & (1 << BUTTON_UP)) 

    system_setemerging();
    motor_on(0, 0);
  }  
  
  if (!system_retail())
  {
    bluetooth_discoverable(1);
  }

#if PRODUCT_W001
  if (system_testing())
    ant_init(MODE_HRM);
#endif
  
  system_restore();

//  protocol_init();
//  protocol_start(1);
  
  process_start(&system_process, NULL);

  /*
  * This is the scheduler loop.
  */
  msp430_dco_required = 0;

  /*
    check firmware update
    */
  if (reason == 0xff)
  {
    printf("Start Upgrade\n");
    Upgrade();
    // never return if sucessfully upgrade
  }

  watchdog_start();

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

    /*
    * Idle processing.
    */
    int s = splhigh();          /* Disable interrupts. */
    /* uart1_active is for avoiding LPM3 when still sending or receiving */
    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);
      watchdog_stop();

      if (shutdown_mode)
      {
        system_shutdown(1); // never return
        LPM4;
      }
      
      if (msp430_dco_required)
      {
        __low_power_mode_0();
      }
      else
      {
        __low_power_mode_3();
      }

      /* We get the current processing time for interrupts that was
         done during the LPM and store it for next time around.  */
      __disable_interrupt();
      irq_energest = energest_type_time(ENERGEST_TYPE_IRQ);
      __enable_interrupt();
      watchdog_start();
      ENERGEST_OFF(ENERGEST_TYPE_LPM);
      ENERGEST_ON(ENERGEST_TYPE_CPU);
    }
  }
}