Beispiel #1
0
int main(void)
{
	WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
	uart_timer_configure();
	uart_init();
    _enable_interrupts();

    uart_puts("\n\r***************\n\r");
    uart_puts("MSP430 SunV2\n\r");
    uart_puts("***************\n\r\n\r");

    uint8_t c;

    // Timeshare between UART and dimming
    while(1) {
        if(uart_getc(&c)) {
            if(c == '\r') {
                 uart_putc('\n');
                 uart_putc('\r');
            } else {
                uart_putc('[');
                uart_putc(c);
                uart_putc(']');
            
                // Clear UART configuration
                _disable_interrupts();
                timer_deconfigure();
                uart_disable();
                uart_timerA_disable();
                switch (c)
                {
                    case 'w':
                        turnOn();
                        break;
                    case 's':
                        turnOff();
                        break;
                    case 'r':
                        remember();
                        break;
                    case 'd':
                        dimUp();
                        break;
                    case 'a':
                        dimDown();
                        break;
                }
                // UART configuration
                art_init();
                timer_deconfigure();
                uart_timer_configure();
                uart_timerA_enable();
                _enable_interrupts();
            }
        }
    }
}
interrupt void port1ISR(){
	_disable_interrupts();
	msdelay(20); // delay for 20 ms
	ISRc = getC();
	P1IFG &= ~(ALLROWS); // clears the interrupt flag
	_enable_interrupts();
}
Beispiel #3
0
unsigned char SPI_RxFrame(unsigned char *pBuffer, unsigned int size)
{
    if(size ==0 )                        return  (1);
    if(UCA0STAT & UCBUSY)    return  (0);
    _disable_interrupts();
    SPI_Rx_Or_Tx = 0;
    SPI_Rx_Buffer = pBuffer;
    SPI_Rx_Size = size - 1;
    SPI_Interrupt_Sel(SPI_Rx_Or_Tx);
    _enable_interrupts();
    UCA0TXBUF = 0xff;             //在接收模式下,也先发送一次空字节,一遍提供时钟通信

    _bis_SR_register(LPM0_bits);

//	unsigned int gie = _get_SR_register() & GIE;
//	IFG2 &= ~UCA0RXIFG;
//
//	while(size--)
//	{
//		while( !(IFG2 & UCA0TXIFG) );
//		UCA0TXBUF = 0xff;
//		while( !(IFG2 & UCA0RXIFG) );
//		*pBuffer++ = UCA0RXBUF;
//	}
    return 1;
}
Beispiel #4
0
void setup_timer_buttons(void){
    init_button();
    init_systimer();
    initButtons();

    _enable_interrupts();
}
Beispiel #5
0
/*
 *  ======== leave ========
 */
Void GateGIE_leave(GateGIE_Object *obj, IArg key)
{
    if (key & GIE) {
        /* re-enable interrupts _only_ if we disabled them */
        _enable_interrupts();
    }
}
Beispiel #6
0
void
buttons_init(void)
{
	_disable_interrupts();
	P1SEL &= ~(1 << BUTTON1_PIN);	/* Set pins 1.1 as I/O */	
	P1SEL &= ~(1 << BUTTON2_PIN);  	/* Set pins 1.2 as I/O */
		
	P1REN |= (1 << BUTTON1_PIN);		/* Enable internal resistor in pin 1.4 */
	P1REN |= (1 << BUTTON2_PIN);		/* Enable internal resistor in pin 2.6 */
	
	P1OUT |= (1 << BUTTON1_PIN);		/* Set internal resisistor as pull-upin P1.4 */
	P1OUT |= (1 << BUTTON2_PIN);		/* Set internal resisistor as pull-upin P2.6 */
	
	P1DIR &= ~(1 << BUTTON1_PIN);  	/* Set pin 1.1 as input */ 
	P1DIR &= ~(1 << BUTTON2_PIN);  	/* Set pin 1.2 as input */
	
	P1IE |= (1 << BUTTON1_PIN);        /* P1.1 interrupt enabled */
  	P1IES |= (1 << BUTTON1_PIN);       /* P1.1 Hi/Lo edge */
  	P1IFG &= ~(1 << BUTTON1_PIN);    /* P1.1 IFG cleared */
  	
  	P1IE |= (1 << BUTTON2_PIN);        /* P1.2 interrupt enabled */
  	P1IES |= (1 << BUTTON2_PIN);       /* P1.2 Hi/Lo edge */
  	P1IFG &= ~(1 << BUTTON2_PIN);    /* P1.2 IFG cleared */
  	 
	msg.type = BUTTONS_MSG_TYPE;/* Set the buttons message type */
	button1_timer.start = 0;
	button2_timer.start = 0;
	
	register_port1IntHandler(BUTTON1_PIN, button1_interrupt);
	register_port2IntHandler(BUTTON2_PIN, button2_interrupt);
	
	_enable_interrupts();
}
Beispiel #7
0
/***********************************************************************************
* @fn          cc2520_init
*
* @brief       Initialise cc2520 datastructures. Sets channel, short address and
*              PAN id in the chip and configures interrupt on packet reception
*
*              txState - file scope variable that keeps tx state info
*              rxi - file scope variable info extracted from the last incoming
*                    frame
*
* @return      none
*/
uint8_t
cc2520_init()
{    
	pConfig.panId = PAN_ID;
    pConfig.channel = RF_CHANNEL;
    pConfig.ackRequest = TRUE;
    pConfig.myAddr = NODE_ADDR;
    
	cc2520_interfaceInit();	// initialize the rest of the interface. 
	
	cc2520_spiInit();		// initialize spi.
	
    if (cc2520_config() == FAILED)
        return FAILED;

	// initialize the ring buffer
//	bufInit(&rxBuffer, ringBuffer, 512);

    _disable_interrupts();

    rxi.pPayload   = NULL;

    txState.receiveOn = TRUE;
    txState.frameCounter = 0;

    // Set channel
    cc2520_setChannel(pConfig.channel);

    // Write the short address and the PAN ID to the CC2520 RAM
    cc2520_setShortAddr(pConfig.myAddr);
    cc2520_setPanId(pConfig.panId);

    // if security is enabled, write key and nonce
    #ifdef SECURITY_CCM
    //basicRfSecurityInit(pConfig);
    #endif

    // Set up receive interrupt (received data or acknowlegment)
    P2IES &= ~(CC2520_INT_PIN); // Set rising edge
    P2IFG &= ~(CC2520_INT_PIN); 
    P2IE |= CC2520_INT_PIN;

    // Clear the exception
    CLEAR_EXC_RX_FRM_DONE();
    
    // Enable general interrupts
    _enable_interrupts();
	
	// And enable reception on cc2520
	cc2520_receiveOn();
	
	memset(eth_tx_buf, 0xFF, 6);
  	memset(&eth_tx_buf[6], 0, 6);
 	eth_tx_buf[12] = 0x80;
  	eth_tx_buf[13] = 0x9a;
	
	return SUCCESS;
}
void matrixISRmode(){
	matrixInit();

	P1IE |= ALLROWS;
	P1IES = ~(ALLROWS); // enables rising edge interrupts
	P1IFG = ~(ALLROWS);
	P6OUT = ALLCOLS;
	_enable_interrupts();
}
Beispiel #9
0
void kernel_main()
{

	int i = 0;
	//init_sys_mmu();
	//start_mmu();  /* 开启MMU */
	unsigned int end = (unsigned int)(&__end+PGDR_MASK)&0xffffc000;
  unsigned int physfree =	init_paging(end-0xC0000000);
	init_ram(physfree);

	/* 重定位内核*/
	asm volatile(
		"add sp, sp, #0xC0000000\n\t"
	);

	/*清空恒等隐射*/
	for(i = 1; i < NR_KERN_PAGETABLE; i++)
		PTD[i] = 0;

	uart_init();
	char *_temp = "0000000000\r\n";
	unsigned int temp;
	HexToString((unsigned int)&temp, _temp);
	uart_puts(_temp);
	task_init();
	unsigned char rank = MAX_rank ;
	unsigned int task_func = (unsigned int)task_idle0;
	unsigned char TID = task_create( rank , task_func);
	task_run(TID);
	task_func = (unsigned int)task_idle1;
	TID = task_create( rank , task_func);
	task_run(TID);
	task_func = (unsigned int)task_idle2;
	TID = task_create( rank , task_func);
	task_run(TID);
  task_func = (unsigned int)task_idle3;
	TID = task_create( rank , task_func);
	task_run(TID);
	init_arm_timer(Kernel_1Hz);
	_enable_interrupts();

	while(1)
	{
		char *_ch = "0000000000\r\n";
		for(i = 0; i < 20; i++)
		{
			HexToString(PTD[i], _ch);
			uart_puts(_ch);
		}
		for(i = 0; i < 20; i++)
		{
			HexToString(PTD[i+0xC00], _ch);
			uart_puts(_ch);
		}
		sleep(500);
	}
}
Beispiel #10
0
/******************************************************************************************************
 * 名       称:I2C_Rx_Init()
 * 功       能:仅使能I2C的Rx中断
 * 入口参数:无
 * 出口参数:无
 * 说       明:I2C通信只能半双工,只使能一个中断,可靠
 * 范       例:无
 ******************************************************************************************************/
void I2C_Rx_Init()
{
	 _disable_interrupts();
	  while ((UCB0STAT & UCBUSY)||UCB0CTL1 & UCTXSTP);       // 确保总线空闲
	  IE2 &= ~UCB0TXIE;							//关闭Rx中断
	  I2C_State=RX_STATE;
	  IE2 |= UCB0RXIE;                          	    //允许Tx中断
	  _enable_interrupts();						// 开总中断
}
Beispiel #11
0
void i2c_init(uint16_t usi_clock_divider, uint16_t usi_clock_source) {
  _disable_interrupts();
  USICTL0 = USIPE6|USIPE7|USIMST|USISWRST;  // Port & USI mode setup
  USICTL1 = USII2C|USIIE;                   // Enable I2C mode & USI interrupt
  USICKCTL = usi_clock_divider | usi_clock_source | USICKPL;
  USICNT |= USIIFGCC;                       // Disable automatic clear control
  USICTL0 &= ~USISWRST;                     // Enable USI
  USICTL1 &= ~USIIFG;                       // Clear pending flag
  _enable_interrupts();
}
Beispiel #12
0
int_fast32_t get_sys_tick()
{
	int_fast32_t elapsed_time;

	_disable_interrupts();
	elapsed_time = sys_tick;
	sys_tick = 0;
	_enable_interrupts();

	return elapsed_time;
}
Beispiel #13
0
int main(void)
{
	WDTCTL = WDTPW + WDTHOLD;             // Stop watchdog timer
	_disable_interrupts();
	sysInit();
	_enable_interrupts();

	while(1){
		if(uartCheck) uartParse();
	}
}
Beispiel #14
0
int main(void) {
	uint16_t status;

	WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
	LED_init();
	LED_on();
    /* configure the Basic Clock Module */
    DCOCTL = CALDCO_1MHZ;
    BCSCTL1 = CALBC1_1MHZ;

    BCSCTL2 = SELM_3 + DIVM_0;//MCLK = LFXTCLK/1
#ifdef NECESSARY
    do {
    	int i;
        IFG1 &= ~OFIFG;                           // Clear OSCFault flag
        for (i = 0xFF; i > 0; i--);               // Time for flag to set
    } while ((IFG1 & OFIFG)); // OSCFault flag still set?
#endif
    TACTL = TASSEL_2 | MC_1; /* SMCLK, upmode */
    TACCR0 = TIMER_CLK_HZ/SYSTICK_HZ;
	TACCTL0 = CCIE; /*Enable timer A0 interrupt*/

	//Enable SCLK, SDI, SDO, master
	USICTL0 |= USIPE7 | USIPE6 | USIPE5 | USIMST | USIOE;
	USICKCTL |= USIDIV_0 //this actually means divide by 1
			  | USISSEL_2//Use SMCLK to drive the SPI clk
			  //| USICKPL
			  ;
	USICTL1 |= USICKPH;//delay?
	//USICTL1 |= USIIE;//interrupt enable
	//		;
	P1OUT = BIT4;//Pull up nCS at first
	P1DIR |= BIT4;//nCS is P1.4
	//P1REN |= 0x10;?

	_enable_interrupts();//vs. _BIS_SR(LPM0_bits + GIE);
	LED_off();

	dSPIN_Soft_Stop();
	dSPIN_Reset_Device();

	status = dSPIN_Get_Status();
   	if(status & dSPIN_STATUS_SW_EVN
   		|| (status & dSPIN_STATUS_MOT_STATUS) != dSPIN_STATUS_MOT_STATUS_STOPPED
   		|| status & dSPIN_STATUS_NOTPERF_CMD
   		|| status & dSPIN_STATUS_WRONG_CMD
   		// !(status & dSPIN_STATUS_UVLO)
   		|| !(status & dSPIN_STATUS_TH_SD)
   		|| !(status & dSPIN_STATUS_OCD))
		Q_ERROR();
    if(dSPIN_Busy_HW()) Q_ERROR();
    return 0;
}
Beispiel #15
0
__interrupt void USCIAB0TX_ISR(void)
{
	 _disable_interrupts();							//等同_DINT
  if(I2C_State==TX_STATE)							//判断是收状态还是发状态
    I2C_TxFrame_ISR();                        			// 事件:发送帧
  else
	I2C_RxFrame_ISR();                     			// 事件:接收帧
  	//-------预留给主循环中唤醒CPU用途-------
  	  if(RxByteCnt == 0 || TxByteCnt == 0)	//如果没有待发送或待接收数据
  	    __bic_SR_register_on_exit(CPUOFF);   // Exit LPM0
  	 _enable_interrupts();							//等同_ENIT
}
Beispiel #16
0
void do_non_blocking_interrupt() {
	_enable_interrupts();
	// Because we have re-enabled interrupts in here, the 12kHz interrupt can happen again
	// But because we set the flag "inside_non_blocking_interrupt", this will not get called
	// again until this pops off the stack.
	// Essentially, this function gets called constantly, but only one will exist on the stack
	// at the same time.

	handle_full_sensors();

	_disable_interrupts();
}
Beispiel #17
0
/******************************************************************************************************
 * 名       称:SPI_TxFrame()
 * 功       能:主机向从机发送1个帧数据
 * 入口参数:无
 * 出口参数:无
 * 说       明:无
 * 范       例:无
 ******************************************************************************************************/
unsigned char SPI_TxFrame(unsigned char  *pBuffer, unsigned int   size)
{
	_disable_interrupts();
	unsigned char i=0;
	for(i=0;i<size;i++)						//然后依次发送各字节数据
	{
		Tx_Char(*pBuffer);
		pBuffer++;
	}
	 _enable_interrupts();
	return 1;
}
Beispiel #18
0
int main(void)
{
	WDTCTL = WDTPW | WDTHOLD;                 // Stop Watchdog

	// Startup clock system with max DCO setting ~12MHz
	CSCTL0 = CSKEY;                           // Unlock clock registers
	CSCTL1 = DCOFSEL_6 | DCORSEL;             // DCO - 12Mhz
	CSCTL2 = SELA__VLOCLK + SELS__DCOCLK + SELM__DCOCLK;
	CSCTL3 = DIVA__1 + DIVS__2 + DIVM__2;     // set all dividers

	// Configure UART pins gps
	P2REN &= ~(BIT0 + BIT1);
	P2SEL1 |= BIT0 + BIT1;
	P2SEL0 &= ~(BIT0 + BIT1);

	// xbee
	P2REN &= ~(BIT5 + BIT6);
	P2SEL1 |= BIT5 + BIT6;
	P2SEL0 &= ~(BIT5 + BIT6);

	// Configure UART
	UCA0CTL1 |= UCSWRST;                      // Put eUSCI in reset
	UCA0CTL1 |= UCSSEL__SMCLK;                // CLK = SMCLK
	// Baud Rate calculation
	// 12000000/(16*9600) = 52.083
	// Fractional portion = 0.083
	// User's Guide Table 21-4: UCBRSx = 0x04
	// UCBRFx = int ( (52.083-52)*16) = 1
	UCA0BR0 = 78;                             // 8000000/16/9600
	UCA0BR1 = 0x00;
	UCA0MCTLW |= UCOS16 | UCBRF_2;

	UCA0CTL1 &= ~UCSWRST;                     // Initialize eUSCI
	UCA0IE |= UCRXIE;                         // Enable USCI_A0 RX interrupt

	// Configure UART xbee
	UCA1CTL1 |= UCSWRST;                      // Put eUSCI in reset
	UCA1CTL1 |= UCSSEL__SMCLK;                // CLK = SMCLK
	// Baud Rate calculation
	// 12000000/(16*9600) = 52.083
	// Fractional portion = 0.083
	// User's Guide Table 21-4: UCBRSx = 0x04
	// UCBRFx = int ( (52.083-52)*16) = 1
	UCA1BR0 = 78;                             // 8000000/16/9600
	UCA1BR1 = 0x00;
	UCA1MCTLW |= UCOS16 | UCBRF_2;

	UCA1CTL1 &= ~UCSWRST;                     // Initialize eUSCI

	shutdown_gps();
	_enable_interrupts();
	while(1);
}
Beispiel #19
0
/******************************************************************************************************
 * 名       称:SPI_RxFrame()
 * 功       能:主机接收从机1帧数据
 * 入口参数:无
 * 出口参数:无
 * 说       明:无
 * 范       例:无
 ******************************************************************************************************/
unsigned char SPI_RxFrame(unsigned char  *pBuffer, unsigned int size)
{
	unsigned char i=0;
	_disable_interrupts();
	for(i=0;i<size;i++)						//然后依次接收各个字节数据
	{
		 *pBuffer=Rx_Char();
		 pBuffer++;
	}
	 _enable_interrupts();
	return 1;
}
Beispiel #20
0
void func(void) {
	_disable_interrupts();

	int statusInfo = 0; // hold inforamtion over the return values of the subtask
	uint8_t* target;

	target = GPTIMER2 | GPTIMER_TISR;
	*target = 0x00000003; //Set Interrupt pending = 0

	statusInfo = startTimer(GPTIMER2);

	_enable_interrupts();
}
Beispiel #21
0
int try_receive (void* str) {
	_disable_interrupts();
	int retv = -1;

	SYSCALL_PARAM (cur_thread->stack_pointer, cur_thread->pid, str, retv);

	asm volatile ("swi #0x02\t\n":::"memory");

	SYSCALL_END (retv);

	_enable_interrupts();	
	return retv;
}
Beispiel #22
0
void Setup_USI_Master_TX (void)
{
	_disable_interrupts();
	Bytecount = 0;
	Transmit = 1;
	USICTL0 = USIPE6+USIPE7+USIMST+USISWRST;  // Port & USI mode setup
	USICTL1 = USII2C+USIIE;                   // Enable I2C mode & USI interrupt
	USICKCTL = USIDIV_7+USISSEL_2+USICKPL;    // USI clk: SCL = SMCLK/128
	USICNT |= USIIFGCC;                       // Disable automatic clear control
	USICTL0 &= ~USISWRST;                     // Enable USI
	USICTL1 &= ~USIIFG;                       // Clear pending flag
	_enable_interrupts();
}
Beispiel #23
0
/******************************************************************************************************
 * 名       称:I2C_Init()
 * 功       能:初始化USCI_B0模块为I2C模式
 * 入口参数:无
 * 出口参数:无
 * 说       明:I2C设为3线制主机状态,暂不使能Tx和Rx中断
 * 范       例:无
 ******************************************************************************************************/
void I2C_Init()
{
	 _disable_interrupts();
	  P1SEL |= BIT6 + BIT7;                      						// GPIO 配置为USCI_B0功能
	  P1SEL2|= BIT6 + BIT7;                    						 // GPIO 配置为USCI_B0功能
	  UCB0CTL1 |= UCSWRST;                      					 // 软件复位状态
	  UCB0CTL0 = UCMST + UCMODE_3 + UCSYNC;   // 同步通信I2C主机状态
	  UCB0CTL1 = UCSSEL_2 + UCSWRST;            		 // 使用SMCLK,软件复位状态
	  UCB0BR0 =I2C_BAUDRATE_DIV ;                          // 除了分频系数,实际波特率还与SMCLK有关
	  UCB0BR1 = 0;														//这一级别的分频一般不启用
	  UCB0I2CSA = SLAVE_ADDR;                    			// I2C从机地址,可在宏定义中修改
	  UCB0CTL1 &= ~UCSWRST;                     				// 开启I2C
	  _enable_interrupts();
}
static void LOCAL_exampleInit(Uint8 pruNum)
{
  Uint32 i;

  Uint32 *pruDataMem;
  
  // Turn on the EDMA CC and TCs
  DEVICE_LPSCTransition(CSL_PSC_0, CSL_PSC_CC0, 0, CSL_PSC_MDCTL_NEXT_ENABLE);
  DEVICE_LPSCTransition(CSL_PSC_0, CSL_PSC_TC0, 0, CSL_PSC_MDCTL_NEXT_ENABLE);
  DEVICE_LPSCTransition(CSL_PSC_0, CSL_PSC_TC1, 0, CSL_PSC_MDCTL_NEXT_ENABLE);  

  // Initialize memory pointer
  if (pruNum == 0)
  {
    pruDataMem = (Uint32 *) PRU0_DATA_RAM_START;
  }
  else if (pruNum == 1)
  {
    pruDataMem = (Uint32 *) PRU1_DATA_RAM_START;
  }  

  // Put src and dst addresses into PRU data memory so PRU code can read them
  pruDataMem[0] = (Uint32) srcBuf;
  pruDataMem[1] = (Uint32) dstBuf;
  
	// Init src and dst buffers
  for (i = 0; i < sizeof(srcBuf); i++)
  {
    srcBuf[i] = rand() & 0xFF;
    dstBuf[i] = 0;
  }
  
  // Clear EDMA CC0 interrupt
  CSL_FINST(intcRegs->EVTCLR[0], DSPINTC_EVTCLR_EC8, SET);

  // Connect the EDMA CC0 event to the DSP interrupt 12
  CSL_FINS(intcRegs->INTMUX3, DSPINTC_INTMUX3_INTSEL12, EDMA3_CC0_INT1);

  // Set ISTP to point to the vector table address
  ISTP = (Uint32)intcVectorTable;

  // Clear all interrupts, bits 4 thru 15
  ICR = 0xFFF0;

  // Enable the bits for non maskable interrupt 12 and NMIE
  IER = 0x1002;

  // Enable interrupts, set GIE bit
  _enable_interrupts();
}
Beispiel #25
0
/******************************************************************************************************
 * 名       称:I2C_TxFrame(unsigned char *p_Tx,unsigned char num)
 * 功       能:主机发送若干字节的1帧数据
 * 入口参数:无
 * 出口参数:无
 * 说       明:无
 * 范       例:无
 ******************************************************************************************************/
unsigned char I2C_TxFrame(unsigned char *p_Tx,unsigned char num)
{
	_disable_interrupts();
	unsigned char i=0;
	 I2C_START;
	 Send_Char(SLAVE_ADDR_W);		//先发送器件地址和写标志
	for(i=0;i<num;i++)						//然后依次发送各字节数据
	{
		Send_Char(*p_Tx);
		p_Tx++;
	}
	I2C_STOP;
	 _enable_interrupts();
	return 1;
}
Beispiel #26
0
/******************************************************************************************************
 * 名       称:I2C_RxFrame(unsigned char *p_Tx,unsigned char num)
 * 功       能:主机接收若干字节的1帧数据
 * 入口参数:无
 * 出口参数:无
 * 说       明:无
 * 范       例:无
 ******************************************************************************************************/
unsigned char I2C_RxFrame(unsigned char *p_Tx,unsigned char num)
{
	unsigned char i=0;
	_disable_interrupts();;
	 I2C_START;
	 Send_Char(SLAVE_ADDR_R);		//先发送器件地址和读标志
	for(i=0;i<num;i++)						//然后依次接收各个字节数据
	{
		*p_Tx=Get_Char();
		p_Tx++;
	}
	I2C_STOP;
	 _enable_interrupts();
	return 1;
}
Beispiel #27
0
/***********************************************************************************
* @fn      cc2520_waitTransceiverReady
*
* @brief   Wait until the transceiver is ready (SFD low).
*
* @param   none
*
* @return  none
*/
void cc2520_waitTransceiverReady(void)
{
#ifdef INCLUDE_PA
    // GPIO3 is not conncted to combo board; use SFD at GPIO2 instead
    _disable_interrupts();
    // GPIO2 = SFD
    CC2520_CFG_GPIO_OUT(2,CC2520_GPIO_SFD);
    while (CC2520_SFD_PIN);
    // GPIO2 = default (RSSI_VALID)
    CC2520_CFG_GPIO_OUT(2,CC2520_GPIO_RSSI_VALID);
    _enable_interrupts();
#else
    while (CC2520_SFD_PIN);
#endif
}
Beispiel #28
0
/****************************************************************************
* 名    称:SPI_TxFrame()
* 功    能:3线硬件SPI模式下,发送指定数目的字节缓存
* 入口参数:pBuffer:指向待发送的数组地址
* 					size:待发送的字节数
* 出口参数:0:当前硬件SPI在忙,
* 					1:当前数据已发送完毕,
* 说    明:使用该函数可以发送指定个数的一帧数据
* 使用范例:SPI_TxFrame(CMD,6);	// 从CMD中取出并发送6个字节
****************************************************************************/
unsigned char SPI_TxFrame(unsigned char  *pBuffer, unsigned int  size)
{
	if(size==0)									return (1);
	if(UCB0STAT & UCBUSY)			return	(0);			// 判断硬件SPI正忙,返回0
    _disable_interrupts();											// 关闭总中断
    SPI_Rx_Or_Tx = 1;													// 开启发送模式
    SPI_Tx_Buffer = pBuffer;										// 将发送缓存指向待发送的数组地址
    SPI_Tx_Size = size-1;												// 待发送的数据个数
    SPI_Interrupt_Sel(SPI_Rx_Or_Tx);							// SPI中断开启选择
    _enable_interrupts();	                               				// 开总中断
    UCB0TXBUF = *SPI_Tx_Buffer;								// 先发送第一个字节人工触发第一次"发送"中断
	_bis_SR_register(LPM0_bits);									// 进入低功耗模式0
	//flagTx = 1;
	//while(flagTx);
    return (1);
}
Beispiel #29
0
 //===============================================================================================
 //===============================================================================================
 //===============================================================================================
 //Очистка очереди от дубликатов задач с разным временем
 void clear_duplicates (void) //not tested
 {
  uint8_t		index=0;
  bit		nointerrupted = 0;
  TPTR task_src;
if (STATUS_REG & (1<<Interrupt_Flag)){_disable_interrupts();nointerrupted = 1;}	// Проверка запрета прерывания	
  for(index=0;index!=timers_cnt_tail;++index)	
  {       
     task_src = TTask[index].GoToTask;
    for(index+1;index!=timers_cnt_tail;++index)	
      { 
       if (TTask[index].GoToTask == task_src) {TTask[index].GoToTask = Idle;}
      } 
  }
  if (nointerrupted){_enable_interrupts();}	// Разрешаем прерывания     
 }
Beispiel #30
0
/****************************************************************************
* 名    称:SPI_RxFrame()
* 功    能:3线硬件SPI模式下,接收指定数目的字节
* 入口参数:pBuffer:指向存放接收数据的数组
* 					size:要接收的字节数
* 出口参数:0:当前硬件SPI在忙,
* 					1:当前数据已发送完毕,
* 说    明:使用该函数可以接收指定个数的一帧数据
* 使用范例:SPI_RxFrame(CMD,6);// 接收6个字节,并依次放入CMD中
****************************************************************************/
unsigned char SPI_RxFrame(unsigned char  *pBuffer, unsigned int size)
{
	if(size==0)									return (1);
	if(UCB0STAT & UCBUSY)			return	(0);			// 判断硬件SPI正忙,返回0
	 _disable_interrupts();											// 关闭总中断
    SPI_Rx_Or_Tx = 0;													// 开启接收模式
    SPI_Rx_Buffer = pBuffer;										// 将发送缓存指向待发送的数组地址
    SPI_Rx_Size = size-1;												// 待发送的数据个数
    SPI_Interrupt_Sel(SPI_Rx_Or_Tx);							// SPI中断开启选择
                                   				// 开总中断
    UCB0TXBUF = 0xFF;													// 在接收模式下,也要先发送一次空字节,以便提供通信时钟。
  	IFG2 |= UCB0RXIFG;
  	_enable_interrupts();
    //flagRx = 1;								// 进入低功耗模式0
	//while(flagRx);
	_bis_SR_register(LPM0_bits);
  	return (1);
}