void main(void)
{
    WatchDogStop();
    PowerLevel_3();
    Clk_MCLK_24M_SMCLK_3M_ACLK_32768Hz();

    pDST = DMA_DST;

    ADCInit();
    DMAInit();
    __bis_SR_register(GIE);
    while(1);
}
Exemple #2
0
//*****************************************************************************
//
//! \brief DMA Configure and Trig transfer
//!
//! \param None
//!
//! \details This function is to configure DMA and Trig transfer.
//!
//! \return None
//
//*****************************************************************************
static void xdmaTransferTest(void)
{
    unsigned long uli, ulj;

    DMAInit();

    for(uli = 0; uli < 4; uli++)
    {
        //
        // Set Channel control  parameter
        //
        DMAChannelControlSet(ulDMAChannelID[uli], DMA_DST_SIZE_32 |
                             DMA_SRC_SIZE_32 |
                             DMA_SRC_DIR_INC |
                             DMA_DST_DIR_INC);
        //
        // Trig DMA Transfer
        //
        DMAChannelTransferSet(ulDMAChannelID[uli], ulSrcTemp, ulDestTemp, 64*4);

        DMAChannelRequest(ulDMAChannelID[uli]);

        //
        // Wait for the end of transmission
        //
        ulj = 1000;
        while(ulj--);

        for(ulj = 0; ulj < 64; ulj++)
        {
            TestAssert((ulSrcTemp[ulj] == ulDestTemp[ulj]), "dma API error!");
        }
    }

    TestAssertQBreak("abcd", "Transfer Over Interrupy fialed!", 5000000);
}
Exemple #3
0
int main(void)
{
//    double Datav=123.4;

    str = a;
    int i;

//    char *str_1 = "abc" ;


  WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT


  //Timer0
  TA0CCTL0 = CCIE;                          // CCR0 interrupt enabled
  TA0CCR0 = 5000;
  TA0CTL = TASSEL_2 + MC_1 + TACLR;         // SMCLK, upmode, clear TAR

  //GPIO
  P4DIR |= BIT7;                            // Set P4.7 to output direction
  P1DIR |= BIT0;                            // Set P1.0 to output direction
  P1DIR |= 0x3C;
  P3DIR |= BIT5+BIT6;
  P1OUT |= BIT5+BIT4;

  //buttom
  P2REN |= BIT1;
  P2OUT |= BIT1;
  P2IES |= BIT1;
  P2IFG &= ~BIT1;
  P2IE |= BIT1;

  P1REN |= BIT1;
  P1OUT |= BIT1;
  P1IES |= BIT1;
  P1IFG &= ~BIT1;
  P1IE |= BIT1;

  //IIC
  OLED_Init();
  OLED_ShowStr(0,2,"Please Set:",99,2);
//  Delay_ms(100);
//  OLED_Clear(0x00);
//end of IIC

  DMAInit();
  ADCInit();   //启动需要在增加 enable

  //UART
  UART_Init(UARTA0); //bluetooth
  UART_Init(UARTB0); //SPI

  UCA0IE |= UCRXIE;                         // Enable USCI_A0 RX interrupt
  //  UCB0IE |= UCRXIE;                         // Enable USCI_B0 RX interrupt

  //SPI
    P2OUT |= BIT5;                            // reset slave
    P2OUT &= ~BIT5;                           // Now with SPI signals initialized,
    for(i=50;i>0;i--);                        // Wait for slave to initialize

    MST_Data = 0x8FFF;                          // Initialize data values
    SLV_Data = 0x00;                          //
    while (!(UCB0IFG&UCTXIFG));               // USCI_B0 TX buffer ready?
  //end of SPI


  __bis_SR_register(LPM3_bits + GIE);       // Enter LPM0, enable interrupts
  while(1)
  {
//    OLED_ShowStr(12,2,(unsigned char *)F2S(Datav,tstr),6,1); //6*8
//    UartTX_Send("Done!\r\n",7);

      if(buttom_fct_flag != 0)
      {
    	  buttom_fct_stc_opt();
    	  buttom_fct_flag = 0;
      }

      if(buttom_fct_flags != 0)
      {
    	  buttom_fct_stcs_opt();
    	  buttom_fct_flags = 0;
      }


//    OLED_ShowStr(0,0,(unsigned char *)F2S(DMA_A1,tstr),8,1); //6*8
      if(fct_stc_flag != 0)
      {
          fct_stc_flag = 0;
          fct_stc_opt();
      }

      if(function!=0) // not off
      {
          ADC12CTL0 |= ADC12SC;   // Start sampling/conversion
      }

      switch(function)
      {
          case 0:
          {
//            OLED_OFF();
              __bis_SR_register(LPM3_bits + GIE);       // Enter LPM3, interrupts enabled;
          }
          break;

          case 1:
          {
              if(mode == 0)
              {
                    if(set_ack_flag == 1)
                    {
//                      OLED_ON();
//                      OLED_Clear(0x00);
                        set_ack_flag = 0;
                        MST_Data = (u16)(Datavin);
                        MST_Data |= 0x8000;
                        SPISend(MST_Data);
                        OLED_ShowStr(0,1,"I:",2,1); //6*8
                        OLED_ShowStr(16,1,(unsigned char *)F2S(Datai,tstr),8,1); //6*8
                        OLED_ShowStr(0,2,"stalls:",7,1); //6*8
                        OLED_ShowStr(42,2,(unsigned char *)I2S(stalls,tstr),6,1); //6*8
                    }
              }
              else   // current_pot
              {
                  Datavin = (double)DMA_A1*4/3.3;
                  MST_Data = (u16)(Datavin*4095/4);
                  MST_Data |= 0x8000;
                  SPISend(MST_Data);
                  I_out = (double)DMA_A2*3.3/4095*10;
                  OLED_ShowStr(0,2,"stalls:",7,1); //6*8
				  OLED_ShowStr(42,2,(unsigned char *)I2S(stalls,tstr),6,1); //6*8
//                OLED_ShowStr(0,2,"I_out:",6,1); //6*8
//                OLED_ShowStr(36,2,(unsigned char *)F2S(I_out,tstr),6,1); //6*8
                  if(!((Pre_A3 - ADC12MEM3)<40 | (ADC12MEM3 - Pre_A3)<40))
                  {
                      OLED_ShowStr(24,6,(unsigned char *)F2S(ADC12MEM3,tstr),4,1); //6*8
                  }
                  Pre_A3 = ADC12MEM3;

              }

          }
          break;

          case 2:
          {
            if(set_ack_flag == 1)
            {
                OLED_ON();
                set_ack_flag = 0;
            }
          }
          break;

          case 3:   //off
          {
//            OLED_OFF();
              //shutdown the circuit
              __bis_SR_register(LPM3_bits + GIE);       // Enter LPM3, interrupts enabled;
          }
          break;

      }//end of function switch;
      OLED_ShowStr(0,4,(unsigned char *)F2S(DMA_A0,tstr),4,1); //6*8
      OLED_ShowStr(0,5,(unsigned char *)F2S(DMA_A1,tstr),4,1); //6*8
      OLED_ShowStr(0,6,(unsigned char *)F2S(DMA_A2,tstr),4,1); //6*8
      OLED_ShowStr(0,7,(unsigned char *)F2S(ADC12MEM3,tstr),4,1); //6*8

//      Delay_ms(200);
      // if(strcmp(str_1,str)==0)
      // {
      //     P1OUT |= BIT0;
      //     UartTX_Send("Great!\r\n",8);
      //     Delay_ms(200);
      // }
      // else P1OUT &= ~BIT0;
  } //end of while

}
/*----------------------------------------------------------------------
|       main
+---------------------------------------------------------------------*/
int WINAPI WinMain(HINSTANCE hInstance,      // handle to current instance
                   HINSTANCE hPrevInstance,  // handle to previous instance
                   LPWSTR lpCmdLine,          // pointer to command line
                   int nCmdShow)             // show state of window
{	
	DWORD i=50;
	DWORD channel;
	MEM_T src, target,desc;
	DWORD size;
	BOOL bLoop;

	// transfer a size of 100kBytes
	size = 100*1024;

	// do the transfer in a loop
	bLoop = TRUE;

	DMAInit();

	// allocate a src buffer in the RAM
	DMAAllocBuffer(&src, size);
	memset ( (DWORD*)src.va, 0xAA, size );

	// allocate a target buffer in the RAM
	DMAAllocBuffer(&target, size);

	// Create a DMA descriptor with a burs size of 32Bytes (8 and 16 bytes are also allowed) and auto-increment the source and target addresses.
	// the addresses always have to be PHYSICAL!!!!!!
	desc.pa = 0; //DMACreateTransferDescriptors will allocate memory if desc = NULL
	desc.va = 0;
	DMACreateTransferDescriptors(src.pa, target.pa, size, DCMD_BSIZE32|DCMD_INCSRCADDR|DCMD_INCTRGADDR, bLoop, &desc);

	// allocate a channel for a peripheral device if you need one
	//channel=DMAAllocChannelEx(PERIPH_CIF1,DMA_PRIORITY_MEDIUM);
	channel = DMAAllocChannelEx(DMA_PERIPH_MEM2MEM,DMA_PRIORITY_MEDIUM);

	
	//Notify DMALib about usage
	DMASetChannelUsage(channel,"DMALibDemo",10);

	DMAStartTransferEx(channel, &desc, 0,FALSE);

	// do something meaningfull here....
	while(i--)
	{
		Sleep(1);
	}

	// deinitialize the dma channel and buffers

	DMAStopTransfer(channel);


	if(memcmp((void*)src.va, (void*)target.va,size)==0)
	{
		printf("DMA transfer sucessfull\n\r");
	}
	else{
		printf("DMA transfer failed\n\r");
	}

	printf("Press Enter to close the programn\r");
	getchar();

	DMADestroyTransferDescriptors(&desc);
	DMAFreeBuffer(&src);
	DMAFreeBuffer(&target);

	DMADeInit();


    return(TRUE);

}