예제 #1
0
/* 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 SoftwareFllInit(void)
{
  // Disable FLL loop control
  __bis_SR_register(SCG0); 

#if 0

  TB0CTL = 0;
  
  EnableSmClkUser(RESERVED_USER3);
  
  // additional prescale by 8
  TB0EX0 = TBIDEX__8;           

  // Start a timer to Re-adjust fll , using SMCLK in continous mode
  // will interrupt on every input capture
  TB0CTL = TBSSEL__SMCLK + MC__CONTINUOUS + TBIE + ID__8;

  // 262.144 ms
  // above / 0.9765625 = 268.43
  
  ucs_dco_mod_saved = UCSCTL0 & MOD_MASK;
#endif
  
}
예제 #3
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);  
}
예제 #4
0
static void WriteTxBuffer(tString * const pBuf)
{
  unsigned char i = 0;
  unsigned int LocalCount = TxCount;
 
  /* if there isn't enough room in the buffer then characters are lost */
  while ( pBuf[i] != 0 && LocalCount < TX_BUFFER_SIZE )
  { 
    TxBuffer[WriteIndex] = pBuf[i++];
    IncrementWriteIndex();
    LocalCount++;
  }    

  /* keep a sticky bit for lost characters */
  if ( pBuf[i] != 0 )
  {
    gAppStats.DebugUartOverflow = 1;
  }
  
  /* 
   * update the count (which can be decremented in the ISR 
   * and start sending characters if the UART is currently idle 
  */
  if ( i > 0 )
  {
    portENTER_CRITICAL();
    
    TxCount += i;
    
#if 0
    if ( TxCount > TX_BUFFER_SIZE )
    {
      while(1);  
    }
#endif
    
    if ( TxBusy == 0 )
    {
      EnableSmClkUser(BT_DEBUG_UART_USER);
      UCA3TXBUF = TxBuffer[ReadIndex];
      IncrementReadIndex();
      TxBusy = 1;
      TxCount--;  
    }
    
    portEXIT_CRITICAL();
  }
}
예제 #5
0
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);
}
예제 #6
0
static void EnableTestMode(void)
{
  if ( !TestModeEnabled )
  { 
    EnableSmClkUser(TEST_MODE_USER);
    
    InitTestMode();
    
    /* read any characters */
    UCA3RXBUF;
    
    UCA3IE |= UCRXIE;
    
    TestModeEnabled = 1;
  }
}
예제 #7
0
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);
}
예제 #8
0
void EnableSoftwareFll(void)
{
  /* FLL loop control should already be disabled */
  EnableSmClkUser(FLL_USER);
  
  /* don't divide the clock */
  TB0EX0 = 0;

  /* Use TB0.6 CCI6B which is internally connected to ACLK in Capture on
   * falling edge mode
   */
  TB0CCTL6 = CM_2 + CCIS_1 + CAP + CCIE;
  
  /* Start a timer to Re-adjust fll , using SMCLK in continuous mode
   * will interrupt on every input capture
   */
  TB0CTL = TBSSEL__SMCLK + MC__CONTINUOUS;
}
예제 #9
0
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);
 
}
예제 #10
0
/* 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();
  
}
예제 #11
0
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);
}
예제 #12
0
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);
}