Exemple #1
0
/////////////////////////////////////////////////////////////////////////////
// This task is running endless in background
/////////////////////////////////////////////////////////////////////////////
void APP_Background(void){
  u8 i;
  while(1){
    switch(phase){
      case BS_CHECK_PHASE_INIT:
	bs = 0;
	block = 0;
	last_error = 0;
	last_error_code = 0;
	time_read = 0xff;
	time_write = 0xff;
        // initialize IIC..
        if(run == 0){
	  MIOS32_MIDI_SendDebugMessage("Bankstick check init...");
#if BS_CHECK_USE_FRAM_LAYER == 0
	  if( (last_error_code = MIOS32_IIC_BS_Init(0)) != 0){
#else
	  if( (last_error_code = FRAM_Init(0)) != 0){ 
#endif
	    last_error =  BS_CHECK_ERROR_INIT;
	    phase = BS_CHECK_PHASE_FINISHED;
	    }
	  else{
	    for(i = 0;i < BS_CHECK_NUM_DEVICES; i++){
#if BS_CHECK_USE_FRAM_LAYER == 0
	      if ( (MIOS32_IIC_BS_CheckAvailable(i)) == 0) {
#else
	      if ( (FRAM_CheckAvailable(i)) != 0) {
#endif
		report_iic_error();
		last_error = BS_CHECK_ERROR_AVAILABLE;
		last_error_code = i;
		MIOS32_MIDI_SendDebugMessage("Bankstick %d not available",i);
		phase = BS_CHECK_PHASE_FINISHED;
		break;
		}
	      } 
            }
          }
        else{
          MIOS32_MIDI_SendDebugMessage("Start next check, run %d",run+1);
          } 
        if(!last_error)
          phase = BS_CHECK_PHASE_WRITE;
        break;
      case BS_CHECK_PHASE_WRITE:
        // write blocks
        if(bs == 0 && block == 0)
          MIOS32_MIDI_SendDebugMessage("Start writing blocks...");
        init_buffer();
#if BS_CHECK_USE_FRAM_LAYER == 0
        if( (last_error_code = MIOS32_IIC_BS_Write(bs,block*BS_CHECK_DATA_BLOCKSIZE,(char*)buffer,BS_CHECK_DATA_BLOCKSIZE)) != 0){
#else
        if( (last_error_code = FRAM_Write(bs,block*BS_CHECK_DATA_BLOCKSIZE,(char*)buffer,BS_CHECK_DATA_BLOCKSIZE)) != 0){
#endif
          report_iic_error();
          last_error =  BS_CHECK_ERROR_WRITE;
	  phase = BS_CHECK_PHASE_FINISHED;
          }
        else{
	  if( (last_error_code = wait_write_finished()) < 0){
	    report_iic_error();
            last_error =  BS_CHECK_ERROR_CHECK_WRITE_FINISHED;
	    phase = BS_CHECK_PHASE_FINISHED;
	    }
	  else if( ++block >= BS_CHECK_NUM_BLOCKS_PER_DEVICE ){
            MIOS32_MIDI_SendDebugMessage("Writing bankstick %d finished",bs);
	    block = 0;
	    if( ++bs >= BS_CHECK_NUM_DEVICES ){
	      bs = 0;
	      phase = BS_CHECK_PHASE_READ;
	      }
	    }
          }
        break;
      case BS_CHECK_PHASE_READ:
        // read blocks
        if(bs == 0 && block == 0)
          MIOS32_MIDI_SendDebugMessage("Start reading / comparing blocks...");
        clear_buffer();
#if BS_CHECK_USE_FRAM_LAYER == 0
        if( (last_error_code = MIOS32_IIC_BS_Read(bs,block*BS_CHECK_DATA_BLOCKSIZE,(char*)buffer,BS_CHECK_DATA_BLOCKSIZE)) != 0){
#else
        if( (last_error_code = FRAM_Read(bs,block*BS_CHECK_DATA_BLOCKSIZE,(char*)buffer,BS_CHECK_DATA_BLOCKSIZE)) != 0){
#endif
          report_iic_error();
	  last_error =  BS_CHECK_ERROR_READ;
	  phase = BS_CHECK_PHASE_FINISHED;
          }
	else{
	  if( !check_buffer() ){
	    last_error =  BS_CHECK_ERROR_COMPARE;
	    last_error_code = 0;// no further error specification
	    phase = BS_CHECK_PHASE_FINISHED;	   
	    }
	  else if( ++block >= BS_CHECK_NUM_BLOCKS_PER_DEVICE ){
            MIOS32_MIDI_SendDebugMessage("Reading / comparing bankstick %d finished",bs);
	    block = 0;
	    if( ++bs >= BS_CHECK_NUM_DEVICES ){
              MIOS32_MIDI_SendDebugMessage("Check run %d finished",run+1);
              if(++run >= BS_CHECK_NUM_RUNS)
                phase = BS_CHECK_PHASE_FINISHED;
              else{
                bs = 0;
                phase = BS_CHECK_PHASE_START;
                }
	      }
	    }
          }
        break;
      }
    }
  }


static s32 wait_write_finished(void){
#if BS_CHECK_USE_FRAM_LAYER == 0
  s32 err_code;
   do{
     err_code = MIOS32_IIC_BS_CheckWriteFinished(bs);
     } while( err_code > 0 );
  return err_code;
#else
  return 0;
#endif
  }

static void report_iic_error(void){
#if BS_CHECK_USE_FRAM_LAYER == 0
  MIOS32_MIDI_SendDebugMessage("IIC error %d",MIOS32_IIC_LastErrorGet(MIOS32_IIC_BS_PORT));
#else
  MIOS32_MIDI_SendDebugMessage("IIC error %d",MIOS32_IIC_LastErrorGet(FRAM_IIC_PORT));
#endif
  }
Exemple #2
0
/**********************************************************************//**
 * @brief  Mode 1
 * 
 * @param  none
 *  
 * @return none
 *************************************************************************/
void Mode1(void)
{
  // Check FR_EXP.h for FRAM Scratch Pad locations
  // Setup FRAM Test storage pointer for Modes 1&2
  ModeAddress =  FRAM_TEST_START-MEM_UNIT;        
  // One time initialization of header and footer transmit package
  TX_Buffer[0] = 0xFA;    
  TX_Buffer[6] = 0xFE;  

  // Variable initialization
  active = 1;
  counter = 0;
  WriteCounter=0;
  LEDCounter = 0;
  ULPBreakSync = 0;
  while((mode == MAX_FRAM_WRITE) && (UserInput == 0))
    {
      // 512 byte FRAM Writes  
      // Update ModeAddress        
      if (ModeAddress < FRAM_TEST_END)   
              ModeAddress += MEM_UNIT;     
      else     
              ModeAddress = FRAM_TEST_START; 
      // Use updated mode address for FRAM Write        
      FRAM_Write(ModeAddress);
            
      WriteCounter++;
      LEDCounter++;
      // Every function call writes 512 bytes
      // Every 100KByte write, cycle the LED position                        
      if (LEDCounter > 199) 
        {
          LEDCounter = 0;
          counter++;
          if(counter == 8)
                counter = 0;
        }            
      // Check if LEDs need to be turned off to measure power
      if((ULP ==1) && (UserInput == 0))
        {
          // P3.4- P3.7 are set as output, low
          P3OUT &= ~(BIT4 + BIT5 + BIT6 + BIT7);   
	  P3DIR |= BIT4 + BIT5 + BIT6 + BIT7; 			    
	  
          // PJ.0,1,2,3 are set as output, low
          PJOUT &= ~(BIT0 + BIT1 + BIT2 + BIT3);  
          PJDIR |= BIT0 + BIT1 + BIT2 + BIT3;  
          // send this one time to allow the GUI to freeze the update 
          if(!(ULPBreakSync))
            {
              TXBreak(mode);                                         
              ULPBreakSync++;
            }
          }
      if((ULP ==0) && (UserInput == 0))
        {     
          ULPBreakSync =0;          
          // Update the LED sequence
          // only if no switch press occured (check again)
          LEDSequenceWrite(counter);
          // Send out UART Bytes every 100KB
          if (WriteCounter > 199)
            {
              WriteCounter = 0;
              // Transmit 7 Bytes
              // Prepare mode-specific data
              // Standard header and footer
              TX_Buffer[1] = 0x01; 
              TX_Buffer[2] = counter;
              TX_Buffer[3] = 0x00;
              TX_Buffer[4] = 0x00;
              TX_Buffer[5] = 0x00;
              TXData();                         
            }            
        }  
    }
    //end of while()loop
}
Exemple #3
0
/**********************************************************************//**
 * @brief  Mode 2
 * 
 * @param  none
 *  
 * @return none
 *************************************************************************/
void Mode2(void)
{
  // Check FR_EXP.h for FRAM Scratch Pad locations
  // Setup FRAM Test storage pointer for Modes 1&2
  ModeAddress =  FRAM_TEST_START-MEM_UNIT;        
  // One time initialization of header and footer transmit package
  TX_Buffer[0] = 0xFA;    
  TX_Buffer[6] = 0xFE;  
  
  // Variable initialization
  active = 1;                
  counter = 0;
  WriteCounter =0;
  LEDCounter = 0;
  ULPBreakSync = 0;        
  
  // startup tick for ~12kBps writes
  // ACLK = VLO = ~12.5KHz
  // Every write = 512 bytes
  // # of bytes/sec = 512*1/(TACCRx/fvlo)
  TA0CCTL0 = CCIE;                // TACCR0 interrupt enabled
  TA0CCR0 = 350;
  TA0CTL = TASSEL_1 + MC_1;       // ACLK, up mode
  // setup write mode
  while((mode == SLOW_FRAM_WRITE) && (UserInput == 0))
    {
      // VLO stays on in LPM4
      __bis_SR_register(LPM4_bits + GIE);
      __no_operation();
      // wakeup to write a segment                        
      // Check status and Update MODE2_address        
      if (ModeAddress < FRAM_TEST_END)   
            ModeAddress += MEM_UNIT;     
      else 
        { // end of memory  - startover
            ModeAddress = FRAM_TEST_START;
        }
      // Use updated mode address for FRAM Write        
      FRAM_Write(ModeAddress); 
            
      WriteCounter++;
      LEDCounter++;           
      // Every 100KByte write, cycle the LED position  
      // 1 cycle = 512 bytes; 200 cycles = 100KB
      if (LEDCounter > 199)
        {
          LEDCounter = 0;
          counter++;
          if (counter == 8)
            counter = 0;
        }                                 
      if((ULP == 1) && (UserInput == 0))
        {
          // P3.4- P3.7 are set as output, low
	  P3OUT &= ~(BIT4 + BIT5 + BIT6 + BIT7);   
	  P3DIR |= BIT4 + BIT5 + BIT6 + BIT7; 	    
          // PJ.0,1,2,3 are set as output, low
          PJOUT &= ~(BIT0 + BIT1 + BIT2 + BIT3);  
          PJDIR |= BIT0 + BIT1 + BIT2 + BIT3;  
          
          // Transmit break packet for GUI freeze
          if(!(ULPBreakSync))
            {
              TXBreak(mode);                                         
              ULPBreakSync++;
            }
          
        }            
      if((ULP == 0) && (UserInput == 0))
        {
          ULPBreakSync =0;
          // Update the LED sequence & UART output
          // Only if S1 is not pressed; else quit
          LEDSequenceWrite(counter);
          // Send out UART bytes every 2KB
          // No. of bytes = 4 * 512 = 2KB
          if (WriteCounter>3)
            {
              WriteCounter = 0;
              // Transmit 7 Bytes
              // Prepare mode-specific data
              // Standard header and footer
              TX_Buffer[1] = 0x02; 
              TX_Buffer[2] = counter;
              TX_Buffer[3] = 0x00;
              TX_Buffer[4] = 0x00;
              TX_Buffer[5] = 0x00;
              TXData();                                         
            }              
        }     
    }
    // end of while() loop
    // Quitting; because user pressed a switch
    TA0CTL = 0;
    TA0CCTL0 = 0;
}
__interrupt void Int_TimerB1(void) {

	switch (TBIV) {
	case 2:
		TBCCR1 += T_1ms;
#if 1
		if (gsKey.ucTm > 1) {
			gsKey.ucTm--;
		}
#endif
		if (PulseTmr.P_OutCkVTmr > 1)
			PulseTmr.P_OutCkVTmr--;

		if (IEC_Comm.MdTmr > 0)
			IEC_Comm.MdTmr--;

		if (gRTCOutCnt > 0) {
			gRTCOutCnt--;

			if (gRTCOutCnt == 0) {
				RTC_OUT_CLR();
			}
		}
		break;
	case 4:
		TBCCR2 += T_1ms;
		if (PulseTmr.P_OutCkTmr > 1)
			PulseTmr.P_OutCkTmr--;

		break;
//--------------------add by bnthang-----------
#ifdef BNTHANG
	case 8:// added by bnthang on January 9th 2016
		// interrupt routine when open cover
		unsigned char buf[7];
		RX8025_Read(buf, 0, 7);
		open_cover.time.Sec[0] = buf[0];
		open_cover.time.Min[0] = buf[1];
		open_cover.time.Hour[0] = buf[2];
		open_cover.time.Day[0] = buf[4];
		open_cover.time.Mon[0] = buf[5];
		open_cover.time.Year[0] = buf[6];
		open_cover.time.Week[0] = buf[3];
		//calculate correction code
		open_cover.time.Check = ChkNum(&open_cover.time.Min[0], 6);
		open_cover.number_open++;
		if (open_cover.number_open == 0xff)
			open_cover.number_open = 0;

		FRAM_Write( OPEN_COVER_COUNT_BYTE, (char*) &open_cover.number_open,
				1);
		open_cover.no_new_open++;
		if (open_cover.no_new_open > 4)
			open_cover.no_new_open = 0;
		FRAM_Write( OPEN_COVER_SAVE_BYTE, (char*) &open_cover.no_new_open,
				1);
		FRAM_Write( SAVE_BLOCK_TIME + open_cover.no_new_open * 6,
				(char*) &open_cover.time.Min[0], 6);
		break;
#endif
//----------------------------------------------
	default:
		break;
	}

}