/* not very efficient, but simple */ void AccelerometerWrite(unsigned char Addr, unsigned char* pData, unsigned char Length) { EnableSmClkUser(ACCELEROMETER_USER); xSemaphoreTake(AccelerometerMutex, portMAX_DELAY); while (UCB1STAT & UCBBUSY); AccelerometerBusy = 1; LengthCount = Length; Index = 0; pAccelerometerData = pData; /* * enable transmit interrupt and * setup for write and send the start condition */ ACCELEROMETER_IFG = 0; ACCELEROMETER_CTL1 |= UCTR + UCTXSTT; while (!(ACCELEROMETER_IFG & UCTXIFG)); /* * clear transmit interrupt flag, enable interrupt, * send the register address */ ACCELEROMETER_IFG = 0; ACCELEROMETER_IE |= UCTXIE; ACCELEROMETER_TXBUF = Addr; while (AccelerometerBusy); while (ACCELEROMETER_CTL1 & UCTXSTP); DisableSmClkUser(ACCELEROMETER_USER); xSemaphoreGive(AccelerometerMutex); }
void DisableSoftwareFll(void) { TB0CTL = 0; TB0CCTL6 = 0; DisableSmClkUser(FLL_USER); FirstPassComplete = 0; }
static void WriteTxBuffer(const tString *pBuf) { EnableSmClkUser(BT_DEBUG_UART_USER); if (TimeStampEnabled) WriteTimeStamp(); while (*pBuf) WRITE_UART(*pBuf++); /* wait until transmit is done */ while (UCA3STAT & UCBUSY); DisableSmClkUser(BT_DEBUG_UART_USER); }
static void DisableTestMode(void) { if ( TestModeEnabled ) { UCA3IE &= ~UCRXIE; DisableSmClkUser(TEST_MODE_USER); TestModeEnabled = 0; } }
/* * This part has a problem turning off the SMCLK when the uart is IDLE. * * manually turn off the clock after the last character is sent * * count more than one interrupt because we don't know when the first one * will happen */ void DisableUartSmClkIsr(void) { DisableSmClkCounter++; if ( DisableSmClkCounter > 2 ) { if ( TxBusy == 0 ) { DisableSmClkUser(BT_DEBUG_UART_USER); } /* if we are transmitting again then disable this timer */ DisableRtcPrescaleInterruptUser(RTC_TIMER_USER_DEBUG_UART); } }
void EnableTermMode(unsigned char Enable) { if (Enable) { ReceiveCompleted = FALSE; EnableSmClkUser(TERM_MODE_USER); /* enable Rx interrupt */ UCA3IE |= UCRXIE; } else { UCA3IE &= ~UCRXIE; DisableSmClkUser(TERM_MODE_USER); } // PrintF("%c EnTermMode", Enable ? OK : NOK); }
void ClearLcd(void) { EnableSmClkUser(LCD_USER); LCD_CS_ASSERT(); LCD_SPI_UCBxTXBUF = LCD_CLEAR_CMD; while (!(LCD_SPI_UCBxIFG & UCTXIFG)); LCD_SPI_UCBxTXBUF = 0x00; while (!(LCD_SPI_UCBxIFG & UCTXIFG)); /* wait for shift to complete ( ~3 us ) */ while((LCD_SPI_UCBxSTAT & 0x01) != 0); LCD_CS_DEASSERT(); DisableSmClkUser(LCD_USER); }
static void WriteTxBuffer(const tString * pBuf) { EnableSmClkUser(BT_DEBUG_UART_USER); unsigned char i = 0; while ( pBuf[i] != 0 ) { /* writing buffer clears TXIFG */ UCA3TXBUF = pBuf[i++]; /* wait for transmit complete flag */ while( (UCA3IFG & UCTXIFG) == 0 ); } /* wait until transmit is done */ while(UCA3STAT & UCBUSY); DisableSmClkUser(BT_DEBUG_UART_USER); }
/* not very efficient, but simple */ void OledWrite(unsigned char Command,unsigned char* pData,unsigned char Length) { if ( Length < 1 ) { PrintString("Invalid OLED write Length\r\n"); return; } //OLED_I2C_CONFIG_FOR_PERIPHERAL_USE(); EnableSmClkUser(OLED_I2C_USER); OledBusy = 1; Count = Length; Index = 0; pOledData = pData; /* * enable transmit interrupt and * setup for write and send the start condition */ OLED_I2C_IFG = 0; OLED_I2C_CTL1 |= UCTR + UCTXSTT; while(!(OLED_I2C_IFG & UCTXIFG)); /* * clear transmit interrupt flag, enable interrupt, * send the command first (data,command,or continuation) */ OLED_I2C_IFG = 0; OLED_I2C_IE |= UCTXIE; OLED_I2C_TXBUF = Command; while(OledBusy); while(OLED_I2C_CTL1 & UCTXSTP); DisableSmClkUser(OLED_I2C_USER); //OLED_I2C_CONFIG_FOR_SLEEP(); }
void AccelerometerReadSingle(unsigned char RegisterAddress, unsigned char* pData) { EnableSmClkUser(ACCELEROMETER_USER); xSemaphoreTake(AccelerometerMutex, portMAX_DELAY); /* wait for bus to be free */ while (UCB1STAT & UCBBUSY); AccelerometerBusy = 1; LengthCount = 1; Index = 0; pAccelerometerData = pData; /* transmit address */ ACCELEROMETER_IFG = 0; ACCELEROMETER_CTL1 |= UCTR + UCTXSTT; while (!(ACCELEROMETER_IFG & UCTXIFG)); /* write register address */ ACCELEROMETER_IFG = 0; ACCELEROMETER_TXBUF = RegisterAddress; while (!(ACCELEROMETER_IFG & UCTXIFG)); /* send a repeated start (same slave address now it is a read command) * read possible extra character from rxbuffer */ ACCELEROMETER_RXBUF; ACCELEROMETER_IFG = 0; ACCELEROMETER_IE |= UCRXIE; ACCELEROMETER_CTL1 &= ~UCTR; /* for a read of a single byte the stop must be sent while the byte is being * received. If this is interrupted an extra byte may be read. * however, it will be discarded during the next read */ if (LengthCount == 1) { /* errata usci30: prevent interruption of sending stop * so that only one byte is read * this requires 62 us @ 320 kHz, 51 @ 400 kHz */ portENTER_CRITICAL(); ACCELEROMETER_CTL1 |= UCTXSTT; while (ACCELEROMETER_CTL1 & UCTXSTT); ACCELEROMETER_CTL1 |= UCTXSTP; portEXIT_CRITICAL(); } else { ACCELEROMETER_CTL1 |= UCTXSTT; } /* wait until all data has been received and the stop bit has been sent */ while (AccelerometerBusy); while (ACCELEROMETER_CTL1 & UCTXSTP); Index = 0; pAccelerometerData = NULL; DisableSmClkUser(ACCELEROMETER_USER); xSemaphoreGive(AccelerometerMutex); }
static void Write(unsigned char Cmd, unsigned char *pBuffer, unsigned int Size) { EnableSmClkUser(LCD_USER); LCD_CS_ASSERT(); #if LCD_DMA LcdDmaBusy = 1; /* send the lcd write command before starting the dma */ LCD_SPI_UCBxTXBUF = Cmd; while (!(LCD_SPI_UCBxIFG&UCTXIFG)); /* USCIB0 TXIFG is the DMA trigger * DMACTL1 controls dma2 and [dma3] */ DMACTL1 = DMA2TSEL_19; __data16_write_addr((unsigned short) &DMA2SA, (unsigned long) pBuffer); __data16_write_addr((unsigned short) &DMA2DA, (unsigned long) &LCD_SPI_UCBxTXBUF); DMA2SZ = Size; /* * single transfer, increment source address, source byte and dest byte, * level sensitive, enable interrupt, clear interrupt flag */ DMA2CTL = DMADT_0 + DMASRCINCR_3 + DMASBDB + DMALEVEL + DMAIE; /* start the transfer */ DMA2CTL |= DMAEN; while(LcdDmaBusy); #else /* send the lcd write command */ LCD_SPI_UCBxTXBUF = Cmd; while (!(LCD_SPI_UCBxIFG&UCTXIFG)); for (unsigned int i = 0; i < Size; ++i) { LCD_SPI_UCBxTXBUF = pBuffer[i]; while (!(LCD_SPI_UCBxIFG&UCTXIFG)); } #endif /* add one more dummy byte at the end */ LCD_SPI_UCBxTXBUF = 0x00; while (!(LCD_SPI_UCBxIFG&UCTXIFG)); /* wait for shift to complete ( ~3 us ) */ while((LCD_SPI_UCBxSTAT & 0x01) != 0); LCD_SPI_UCBxTXBUF = LCD_STATIC_CMD; while (!(LCD_SPI_UCBxIFG&UCTXIFG)); LCD_SPI_UCBxTXBUF = 0x00; while (!(LCD_SPI_UCBxIFG&UCTXIFG)); /* now the chip select can be deasserted */ LCD_CS_DEASSERT(); DisableSmClkUser(LCD_USER); }