예제 #1
0
/**
 * \brief  This function writes data from a specified buffer onto the
 *         transmitter FIFO of UART.
 *
 * \param  pTxBuffer        Pointer to a buffer in the transmitter.  
 * \param  numBytesToWrite  Number of bytes to be transmitted to the 
 *                          transmitter FIFO. The user has the freedom to not 
 *                          specify any valid value for this if he wants to
 *                          print until the occurence of a NULL character.
 *                          In this case, he has to pass a negative value as
 *                          this parameter. 
 *  
 * \return  Number of bytes written to the transmitter FIFO.
 *
 * \note   1> Whenever a null character(\0) is encountered in the 
 *            data to be transmitted, the transmission is stopped. \n
 *         2> Whenever the transmitter data has a new line character(\n), 
 *            it is interpreted as a new line(\n) + carraige return(\r)
 *            characters. This is because the serial console interprets a 
 *            new line character as it is and does not introduce a carraige 
 *            return. \n
 *            
 *         Some example function calls of this function are: \n
 *
 *         UARTPuts(txArray, -2): This shall print the contents of txArray[]
 *         until the occurence of a NULL character. \n
 *
 *         UARTPuts("Hello World", 8): This shall print the first 8 characters
 *         of the string shown. \n
 *
 *         UARTPuts("Hello World", 20): This shall print the string shown until
 *         the occurence of the NULL character. Here, the NULL character is
 *         encountered earlier than the length of 20 bytes.\n
 * 
 */
unsigned int UARTPuts(const char *pTxBuffer, int numBytesToWrite)
{
     unsigned int count = 0;
     unsigned int flag = 0;

     if(numBytesToWrite < 0)
     {
          flag = 1;
     }
     
     while('\0' != *pTxBuffer)
     {
          /* Checks if data is a newline character. */
          if('\n' == *pTxBuffer)
          {
               /* Ensuring applicability to serial console.*/
               UARTPutc('\r');
               UARTPutc('\n');
          }
          else
          {
               UARTPutc((unsigned char)*pTxBuffer);
          }
          pTxBuffer++;
          count++;

          if((0 == flag) && (count == numBytesToWrite))
          {
               break;
          }

     }
   /* Returns the number of bytes written onto the transmitter FIFO. */
   return count;
}
예제 #2
0
/*#####################################################*/
bool board_init()
{
	//RtcStruct.Rtc_ClkSource = _Rtc_Clk_Source_RCOSC_gc;
	core_init();
	//timer_init();
/*-----------------------------------------------------*/
/* Set up the Uart 0 like debug interface with RxBuff = 256, TxBuff = 256, 115200b/s*/
	DebugCom = new_(new_uart);
	DebugCom->BaudRate = 115200;
	DebugCom->RxBuffSize = 20;
	DebugCom->TxBuffSize = 10;
	//DebugCom->Mode = UsartCom_Mode_Asynchronus;
	DebugCom->Priority = 0;
	DebugCom->UartNr = 5;
	uart_open(DebugCom);
/*-----------------------------------------------------*/
/* Display board message*/
#if defined(BOARD_MESSAGE)
	UARTPutc(DebugCom, 0xFF);
	UARTPutc(DebugCom, 0xFF);
	UARTPutc(DebugCom, '\n');
	UARTPutc(DebugCom, '\r');
	UARTprintf(DebugCom, "Use %s Board.\n\r", BOARD_MESSAGE);
#endif
/*-----------------------------------------------------*/
	HARDBTN1 = gpio_assign(0, 1, GPIO_DIR_INPUT);
	gpio_up_dn(HARDBTN1, 1);
/*-----------------------------------------------------*/
	LED1 = gpio_assign(3, 12, GPIO_DIR_OUTPUT);
	LED2 = gpio_assign(3, 13, GPIO_DIR_OUTPUT);
	LED3 = gpio_assign(3, 14, GPIO_DIR_OUTPUT);
	LED4 = gpio_assign(3, 15, GPIO_DIR_OUTPUT);
/*-----------------------------------------------------*/
	return true;
}
예제 #3
0
/*#####################################################*/
bool board_init()
{
	//RtcStruct.Rtc_ClkSource = _Rtc_Clk_Source_RCOSC_gc;
	core_init();
	timer_init();
/*-----------------------------------------------------*/
#ifdef UART_0_INIT
	UART_0_INIT
#endif
/*-----------------------------------------------------*/
#ifdef DXL_INTERFACE_INIT
	DXL_INTERFACE_INIT
#endif
/*-----------------------------------------------------*/
/* Display board message*/
#if defined(BOARD_MESSAGE)
	UARTPutc(DebugCom, 0xFF);
	UARTPutc(DebugCom, 0xFF);
	UARTPutc(DebugCom, '\n');
	UARTPutc(DebugCom, '\r');
	UARTprintf(DebugCom, "Use %s Board.\n\r", BOARD_MESSAGE);
#endif
/*-----------------------------------------------------*/
#ifdef TWI_1_INIT
	TWI_1_INIT
#endif
/*-----------------------------------------------------*/
#ifdef ADC_0_INIT
	ADC_0_INIT
#endif
/*-----------------------------------------------------*/
#ifdef SHT11_INIT
	SHT11_INIT
#endif
/*-----------------------------------------------------*/
#ifdef SRF02_INIT
	SRF02_INIT
#endif
/*-----------------------------------------------------*/
#ifdef MHC5883_INIT
	MHC5883_INIT
#endif
/*-----------------------------------------------------*/
#ifdef MS5611_INIT
	MS5611_INIT
#endif
/*-----------------------------------------------------*/
#ifdef MPU60x0_INIT
	MPU60x0_INIT
#endif
/*-----------------------------------------------------*/
	LED1 = gpio_assign(IOC, 13, GPIO_OUT_PUSH_PULL, false);
	return true;
}
예제 #4
0
int UARTGetNum(void)  
{
     unsigned char rxByte;
     int sign = 1;
     int value = 0;

     rxByte = UARTGetc();

     /* Accounting for negative numbers.*/
     if('-' == rxByte)
     {
          UARTPutc('-');
          sign = -1;
     }
     else
     {
          UARTPutc(rxByte);
          value = value*10 + (rxByte - 0x30);
     } 
     
     do
     {
          rxByte = UARTGetc();

          /* Echoing the typed characters to the serial console.*/
          UARTPutc(rxByte);
          /*
          ** Checking if the entered character is a carriage return.
          ** Pressing the 'Enter' key on the keyboard executes a 
          ** carriage return on the serial console.
          */
          if('\r' == rxByte)
          {
               break;
          }
          /* 
          ** Subtracting 0x30 to convert the representation of the digit 
          ** from ASCII to hexadecimal.
          */
          value = value*10 + (rxByte - 0x30);

      }while(1);                 

      /* Accounting for the sign of the number.*/
      value = value * sign;

      return value;
}
예제 #5
0
/*
** Main Function.
*/
int main(void)
{
    unsigned char choice = 0;

    /* Enable the clocks for McSPI0 module.*/
    McSPI0ModuleClkConfig();

    /* Perform Pin-Muxing for SPI0 Instance.*/
    McSPIPinMuxSetup(0);

    /* Perform Pin-Muxing for CS0 of SPI0 Instance.*/
    McSPI0CSPinMuxSetup(MCSPI_CH_NUM);

    /* Initialize the UART utility functions.*/
    UARTStdioInit();

    /* Enable IRQ in CPSR.*/
    IntMasterIRQEnable();

    UARTPuts("Here the McSPI controller on the SOC communicates with ",-1);
    UARTPuts("the McSPI Flash.\r\n\r\n",-1);

    /* Initialize the EDMA3 instance.*/
    EDMA3Initialize();

    /* Request EDMA3CC for Tx and Rx channels for SPI0. */
    RequestEDMA3Channels();

    /* Set up the McSPI instance.*/
    McSPISetUp();

    /* Enable the SPI Flash for writing to it. */
    WriteEnable();

    UARTPuts("Do you want to erase a sector of the flash before writing to it ?.", -1);
    UARTPuts("\r\nInput y(Y)/n(N) to proceed.\r\n", -1);

    choice = UARTGetc();
    UARTPutc(choice);

    if(('y' == choice) || ('Y' == choice))
    {
        /* Erasing the specified sector of SPI Flash. */
        FlashSectorErase();
    }

    /* Enable the SPI Flash for writing to it. */
    WriteEnable();

    /* Write data of 1 page size into a page of Flash.*/
    FlashPageProgram();

    /* Read data of 1 page size from a page of flash.*/
    ReadFromFlash();

    /* Verify the data written to and read from Flash are same or not.*/
    VerifyData();

    while(1);
}
예제 #6
0
void UARTPutHexNum(unsigned int hexValue)
{
    unsigned char num[8] = {0};
    unsigned int quotient = 0;
    unsigned int dividend = 0;
    int count = 0;

    dividend = hexValue;

    do
    {
        quotient = dividend/16;
        num[count] = (unsigned char)(dividend % 16);
        if(0 == quotient)
        {
            break;
        }
        count++;
        dividend = quotient;

    }while(count < 8);

    if(8 == count)
    {
        count--;
    }

    UARTPutc('0');
    UARTPutc('x');

    while(count >= 0)
    {
        /* Checking for alphanumeric numbers. */
        if((16 - num[count]) <= 6)
        {
            /* Printing alphanumeric numbers. */
            UARTPutc(num[count--] + 0x37);
        }
        else
        {
            /* Printing numbers in the range 0 to 9. */
            UARTPutc(num[count--] + 0x30);
        }
    }
}
예제 #7
0
/******************************************************************************
**                          FUNCTION DEFINITIONS
*******************************************************************************/
int main(void)
{
    /* Set up the UART2 peripheral */
    UARTStdioInit();

    /* Set up the Timer2 peripheral */
    TimerSetUp64Bit();

    /* Set up the AINTC to generate Timer2 interrupts */
    TimerIntrSetUp();

    /* Enable the timer interrupt */
    TimerIntEnable(SOC_TMR_2_REGS, TMR_INT_TMR12_NON_CAPT_MODE);

#ifndef _TMS320C6X
    /* Switch to non privileged mode; This is done for demonstration purpose */
    CPUSwitchToUserMode();
#endif

    /* Send the first String */
    UARTPuts("Tencounter: 9", -1);

    /* Start the timer. Characters from cntArr will be sent from the ISR */
    TimerEnable(SOC_TMR_2_REGS, TMR_TIMER12, TMR_ENABLE_CONT);

    /* make sure all the characters from cntArray from ISR */
    while(secCnt < 9)
    {
        /* Replace previous number each time the timer interrupt occurs */
        if(flagIsrCnt)
        {
            UARTPutc('\b');
            UARTPutc(cntArr[secCnt]);
            secCnt++;
            flagIsrCnt = 0;
        }
    }

    /* Disable the timer. No more timer interrupts */
    TimerDisable(SOC_TMR_2_REGS, TMR_TIMER12);

    /* Halt the program */
    while(1);
}
예제 #8
0
void UARTPutNum(int value)
{
     unsigned char num[10] = {0};
     unsigned int quotient = 0;
     unsigned int dividend = 0;
     int count = 0;

     if(value < 0)
     {
          UARTPutc('-');      
          /* 
          ** Making the negative number as positive. 
          ** This is done to simplify further processing and printing.
          */
          value = -value; 
     }

     dividend = value; 
     do
     {
          quotient = dividend/10;
          num[count] = (unsigned char)(dividend % 10);
          if(0 == quotient)
          {
               break;
          }            
          count++;
          dividend = quotient;

     }while(count < 10);      

     if(10 == count)
     {
          count--;
     }
      
     /* Printing the digits. */
     do
     {
          /* We add 0x30 to a digit to obtain its respective ASCII value.*/
          UARTPutc(num[count--] + 0x30);
     }while(count >= 0);
}
예제 #9
0
/**
 * Writes a string of characters to the UART output.
 *
 * \param pcBuf points to a buffer containing the string to transmit.
 * \param len   is the length of the string to transmit.
 *
 * This function will transmit the string to the UART output.  The number of
 * characters transmitted is determined by the \e len parameter.  This
 * function does no interpretation or translation of any characters.  Since
 * the output is sent to a UART, any LF (/n) characters encountered will be
 * replaced with a CRLF pair.
 *
 * Besides using the \e len parameter to stop transmitting the string, if a
 * null character (0) is encountered, then no more characters will be
 * transmitted and the function will return.
 *
 * In non-buffered mode, this function is blocking and will not return until
 * all the characters have been written to the output FIFO.  In buffered mode,
 * the characters are written to the UART transmit buffer and the call returns
 * immediately.  If insufficient space remains in the transmit buffer,
 * additional characters are discarded.
 *
 * \return Returns the count of characters written.
 */
static unsigned int UARTwrite(const char *pcBuf, unsigned int len)
{
    unsigned int uIdx;    

    /* Send the characters */
    for(uIdx = 0; uIdx < len; uIdx++)
    {
        /* If the character to the UART is \n, then add a \r before it so that
         * \n is translated to \n\r in the output. */
        if(pcBuf[uIdx] == '\n')
        {
            UARTPutc('\r');
        }

        /* Send the character to the UART output. */
       UARTPutc(pcBuf[uIdx]);
    }

    /* Return the number of characters written. */
    return(uIdx);
}
예제 #10
0
unsigned int UARTGets(char *pRxBuffer, int numBytesToRead)
{     
     unsigned int count = 0;
     unsigned int flag = 0;

     if(numBytesToRead < 0)
     {
          flag = 1;
     }
     do
     {
          *pRxBuffer = UARTGetc();
          
          /*
          ** 0xD - ASCII value of Carriage Return.
          ** 0x1B - ASCII value of ESC character.
          */ 
          if(0xD == *pRxBuffer || 0x1B == *pRxBuffer)
          {
               *pRxBuffer = '\0';
               break;
          }

          /* Echoing the typed character back to the serial console. */
          UARTPutc((unsigned char)*pRxBuffer);
          pRxBuffer++;     
          count++;

          if(0 == flag && (count == numBytesToRead))
          {
               break;
          }

     }while(1);
     
     return count;
}
예제 #11
0
unsigned int UARTGetHexNum(void)
{
    unsigned char rxByte;
    unsigned int value = 0;
    unsigned int loopIndex;
    unsigned int byteCount = 0;

    for(loopIndex = 0; loopIndex < 2; loopIndex++)
    {
        /* Receiving bytes from the host machine through serial console. */
        rxByte = UARTGetc();

        /*
        ** Checking if the entered character is a carriage return.
        ** Pressing the 'Enter' key on the keyboard executes a
        ** carriage return on the serial console.
        */
        if('\r' == rxByte)
        {
            break;
        }

        /*
        ** Checking if the character entered is one among the alphanumeric
        ** character set A,B,C...F
        */
        if(('A' <= rxByte) && (rxByte <= 'F'))
        {
            /* Echoing the typed characters to the serial console.*/
            UARTPutc(rxByte);
            value = value*16 + (rxByte - 0x37);
            byteCount++;
        }

        /*
        ** Checking if the character entered is one among the alphanumeric
        ** character set a,b,c...f
        */
        else if(('a' <= rxByte) && (rxByte <= 'f'))
        {
            UARTPutc(rxByte);
            value = value*16 + (rxByte - 0x57);
            byteCount++;
        }

        /*
        ** Checking if the character entered is one among the decimal
        ** number set 0,1,2,3,....9
        */
        else if(('0' <= rxByte) && (rxByte <= '9'))
        {
            UARTPutc(rxByte);
            value = value*16 + (rxByte - 0x30);
            byteCount++;
        }

        /*
        ** Checking if the character is either a 'x'(lower-case) or an 'X'
        ** (upper-case).
        */
        else if(('x' == rxByte) || ('X' == rxByte))
        {
            UARTPutc(rxByte);
            value = 0;
            break;
        }
    }

    if(0 == value)
    {
        byteCount = 0;
    }

    do
    {
        rxByte = UARTGetc();

        if('\r' == rxByte)
        {
            break;
        }

        /*
        ** Checking if the character entered is one among the alphanumeric
        ** character set A,B,C...F
        */
        if(('A' <= rxByte) && (rxByte <= 'F'))
        {
            UARTPutc(rxByte);
            value = value*16 + (rxByte - 0x37);
            byteCount++;
        }

        /*
        ** Checking if the character entered is one among the alphanumeric
        ** character set a,b,c...f
        */
        else if(('a' <= rxByte) && (rxByte <= 'f'))
        {
            UARTPutc(rxByte);
            value = value*16 + (rxByte - 0x57);
            byteCount++;
        }

        /*
        ** Checking if the character entered is one among the decimal
        ** number set 0,1,2,3,....9
        */
        else if(('0' <= rxByte) && (rxByte <= '9'))
        {
            UARTPutc(rxByte);
            value = value*16 + (rxByte - 0x30);
            byteCount++;
        }

        /*
        ** Not receiving any other character other than the one belonging
        ** to the above three categories.
        */
        else
        {
            /* Intentionally left empty. */
        }

    }while(byteCount < 8);

    return value;
}
예제 #12
0
파일: spiEdma.c 프로젝트: ev3osek/ev3osek
/*
** Main function.
*/
int main(void)
{
    volatile char originalData[260] = {0}; 
    volatile char readFlash[260] = {0};
    unsigned int retVal = 0;
    unsigned char choice;

    /* Initializes the UART Instance for serial communication. */
    UARTStdioInit(); 

    UARTPuts("Welcome to SPI EDMA application.\r\n", -1);
    UARTPuts("Here the SPI controller on the SoC communicates with", -1);
    UARTPuts(" the SPI Flash present on the SoM.\r\n\r\n", -1);

    /* Initializes the EDMA3 Instance. */
    EDMA3Initialize();

    /* Initializes the SPI1 Instance. */
    SPIInitialize();

    /* Request EDMA3CC for Tx and Rx channels for SPI1. */
    RequestEDMA3Channels();

    /* Enable SPI communication. */
    SPIEnable(SOC_SPI_1_REGS);

    /* Enable the SPI Flash for writing to it. */
    WriteEnable();

    UARTPuts("Do you want to erase a sector of the flash before writing to it ?.", -1);
    UARTPuts("\r\nInput y(Y)/n(N) to proceed.\r\n", -1);

    choice = UARTGetc();
    UARTPutc(choice); 

    if(('y' == choice) || ('Y' == choice))
    {
        /* Erasing the specified sector of SPI Flash. */
        FlashSectorErase();
    }
    
    WriteEnable(); 

    /* Program a specified Page of the SPI Flash. */
    FlashPageProgram(originalData); 

    /* Read the contents of the page that was previously written to. */
    ReadFromFlash(readFlash);

    /* Verify whether the written and the read contents are equal. */
    retVal = verifyData(&originalData[4], &readFlash[4], 256); 

    if(TRUE == retVal)
    {
        UARTPuts("\r\nThe data in the Flash and the one written ", -1); 
        UARTPuts("to it are equal.\r\n", -1);
    }
    else
    {
        UARTPuts("\r\n\r\nThe data in the Flash and the one written to it", -1);
        UARTPuts(" are not equal.\r\n", -1);
    } 
    
    while(1);
}
예제 #13
0
파일: demoRtc.c 프로젝트: OS-Project/Divers
/*
** Displays the Time and Date on the UART console
*/
void RtcTimeCalDisplay(void)
{
    unsigned int time = 0;
    unsigned int cal = 0;
    unsigned int temp;
 
    UARTPuts("\r", -1);

    time = RTCTimeGet(SOC_RTC_0_REGS);
    UARTPuts("Current Time And Date: ", -1);
 
    temp = (time & MASK_HOUR) >> SHIFT_HOUR;
    UARTPutc(((temp >> 4) & 0x0F) + 48);
    UARTPutc((temp & 0x0F) + 48);
  
    UARTPutc(':');
 
    temp = (time & MASK_MIN) >> SHIFT_MIN;
    UARTPutc(((temp >> 4) & 0x0F) + 48);
    UARTPutc((temp & 0x0F) + 48);

    UARTPutc(':');

    temp = (time & MASK_SEC) >> SHIFT_SEC;
    UARTPutc(((temp >> 4) & 0x0F) + 48);
    UARTPutc((temp & 0x0F) + 48);

    UARTPuts(", ", -1);

    cal = RTCCalendarGet(SOC_RTC_0_REGS);

    temp = (cal & MASK_DAY) >> SHIFT_DAY;
    UARTPutc(((temp >> 4) & 0x0F) + 48);
    UARTPutc((temp & 0x0F) + 48);

    UARTPutc('-');

    temp = (cal & MASK_MON) >> SHIFT_MON;
    UARTPutc(((temp >> 4) & 0x0F) + 48);
    UARTPutc((temp & 0x0F) + 48);

    UARTPutc('-');

    temp = (cal & MASK_YEAR) >> SHIFT_YEAR;
    UARTPutc(((temp >> 4) & 0x0F) + 48);
    UARTPutc((temp & 0x0F) + 48);

    UARTPuts(", ", -1);

    switch(cal & MASK_DOTW)
    {
        case 0x00:
             UARTPuts("Sunday", -1);
        break;

        case 0x01:
             UARTPuts("Monday", -1);
        break;

        case 0x02:
             UARTPuts("Tuesday", -1);
        break;

        case 0x03:
             UARTPuts("Wednesday", -1);
        break;

        case 0x04:
             UARTPuts("Thursday", -1);
        break;

        case 0x05:
             UARTPuts("Friday", -1);
        break;

        case 0x06:
             UARTPuts("Saturday", -1);

        default:
        break;

    }
}
예제 #14
0
/*#####################################################*/
bool board_init()
{
	//RtcStruct.Rtc_ClkSource = _Rtc_Clk_Source_RCOSC_gc;
	core_init();
	timer_init();
/*-----------------------------------------------------*/
/* Set up the Uart 0 like debug interface with RxBuff = 256, TxBuff = 256, 115200b/s*/
	UART_0_INIT
/*-----------------------------------------------------*/
/* Display board message*/
#if defined(BOARD_MESSAGE)
	UARTPutc(DebugCom, 0xFF);
	UARTPutc(DebugCom, 0xFF);
	UARTPutc(DebugCom, '\n');
	UARTPutc(DebugCom, '\r');
	UARTprintf(DebugCom, "Use %s Board.\n\r", BOARD_MESSAGE);
#endif
/*-----------------------------------------------------*/
/* Set up the Twi 0 to communicate with PMIC and the Onboard serial EEprom memory */
	TWI_1_INIT
/*-----------------------------------------------------*/
	SPI_1_INIT
/*-----------------------------------------------------*/
/* Set up the ADC 0 */
#if _USE_INT_ADC == 1
	ADC_0_INIT
#endif
/*-----------------------------------------------------*/
#if _USE_MPU60x0_9150 == 1
	MPU60x0_9150_INIT
#endif
/*-----------------------------------------------------*/
#if _USE_AK8975 == 1
	AK8975_INIT
#endif
/*-----------------------------------------------------*/
#if _USE_BMP180 == 1
	BMP180_INIT
#endif
/*-----------------------------------------------------*/
#if _USE_ADXL345 == 1
	ADXL345_INIT
#endif
/*-----------------------------------------------------*/
#if _USE_HIH613x == 1
	HIH613x_INIT
#endif
/*-----------------------------------------------------*/
#if _USE_MPL3115A2 == 1
	MPL3115A2_INIT
#endif
/*-----------------------------------------------------*/
#if _USE_LEPTON_FLIR == 1
	LEPTON_FLIR_INIT
#endif
/*-----------------------------------------------------*/
	HARDBTN1 = gpio_assign(IOA, 0, GPIO_DIR_INPUT, false);
	gpio_up_dn(HARDBTN1, 1);
/*-----------------------------------------------------*/
	LED = gpio_assign(IOC, 13, GPIO_DIR_OUTPUT, false);
//*-----------------------------------------------------*/
	return true;
}
예제 #15
0
/******************************************************************************
**                      INTERNAL FUNCTION DEFINITIONS                       
******************************************************************************/
int main(void)
{
    volatile unsigned int count = 0x0FFFu;
    unsigned int retVal = FALSE;
    unsigned char choice = 0;

    /* Enable the clocks for McSPI0 module.*/
    McSPI0ModuleClkConfig();

    /* Perform Pin-Muxing for SPI0 Instance */
    McSPIPinMuxSetup(0);

    /* Perform Pin-Muxing for CS0 of SPI0 Instance */
    McSPI0CSPinMuxSetup(chNum);

    /* Initialize the UART utility functions */
    UARTStdioInit();

    UARTPuts("Here the McSPI controller on the SoC communicates with", -1);
    UARTPuts(" the SPI Flash.\r\n\r\n", -1);

    /* Enable IRQ in CPSR.*/
    IntMasterIRQEnable();

    /* Map McSPI Interrupts to AINTC */
    McSPI0AintcConfigure();
					
    /* Do the necessary set up configurations for McSPI.*/
    McSPISetUp();

    /* Pass the write enable command to flash.*/
    WriteEnable();

    /* Wait until write enable command is successfully written to flash.*/
    while(FALSE == retVal)
    {
        retVal = IsWriteSuccess();
    }

    retVal = FALSE;

    UARTPuts("Do you want to erase a sector of the flash before ", -1);
    UARTPuts("writing to it ?.", -1);
    UARTPuts("\r\nInput y(Y)/n(N) to proceed.\r\n", -1);

    choice = UARTGetc();
    UARTPutc(choice);

    if(('Y' == choice) || ('y' == choice))
    {
        /* Erase a sector of flash.*/
        SectorErase();
    }

    /* Pass the write enable command to flash.*/
    WriteEnable();

    /* Wait until write enable command is successfully written to flash.*/
    while(FALSE == retVal)
    {
        retVal = IsWriteSuccess();
    }

    /* Write data of 1 page size to flash.*/
    WriteToFlash();

    while(count--);
    count = 0x0FFFu;

    /* Read data of 1 page size from flash.*/
    ReadFromFlash();

    while(count--);

    /* Verify the data written to and read from flash are same or not.*/
    VerifyData();

    while(1);
}
예제 #16
0
파일: main.c 프로젝트: joebauman/bbone_app
/*
** Main function. The application starts here.
*/
int main(void)
{
    unsigned int index;
    unsigned int j;

    int result = 0;

    /*
    ** Sets up Section page tables. This is only first level
    ** page table, each page is of size 1MB
    */
    for(index = 0; index < (4*1024); index++)
    {
         /* Set the cacheable memory attributes */
         if((index >= 0x800 && index < 0x880) || (index == 0x403))
         {
              pageTable[index] = (index << 20) | CACHEABLE_TLB_ATTR;
         }

         /* Set the non-cacheable memory attributes */
         else
         {
              pageTable[index] = (index << 20) | NORM_TLB_ATTR;
         }
    }


    /* Invalidate the TLB, pipeline */
    CP15TlbInvalidate();
    CP15BranchPredictorInvalidate();

    CP15BranchPredictionEnable();

    CP15DomainAccessClientSet();

    /* Set TTB0 value. We use only TTB0 here (N = 0) */
    CP15Ttb0Set(((unsigned int )pageTable) | RGN_L2_WBWA);

    /* Enables MMU */
    CP15MMUEnable();

    /* Flush and enable Instruction Cache */
    CP15ICacheFlush();
    CP15ICacheEnable();

    PeripheralsSetUp();

    /* Initialize the ARM Interrupt Controller */
    IntAINTCInit();

    /* Register the ISRs */  
    Timer2IntRegister();
    Timer4IntRegister();
    EnetIntRegister();
    RtcIntRegister();
    HSMMCSDIntRegister();
    IntRegister(127, dummyIsr);

    IntMasterIRQEnable();

    /* Enable system interrupts */
    IntSystemEnable(SYS_INT_RTCINT);
    IntPrioritySet(SYS_INT_RTCINT, 0, AINTC_HOSTINT_ROUTE_IRQ);
    IntSystemEnable(SYS_INT_3PGSWTXINT0);
    IntPrioritySet(SYS_INT_3PGSWTXINT0, 0, AINTC_HOSTINT_ROUTE_IRQ);
    IntSystemEnable(SYS_INT_3PGSWRXINT0);
    IntPrioritySet(SYS_INT_3PGSWRXINT0, 0, AINTC_HOSTINT_ROUTE_IRQ);
    IntSystemEnable(SYS_INT_TINT2);
    IntPrioritySet(SYS_INT_TINT2, 0, AINTC_HOSTINT_ROUTE_IRQ);
    IntSystemEnable(SYS_INT_TINT4);
    IntPrioritySet(SYS_INT_TINT4, 0, AINTC_HOSTINT_ROUTE_IRQ);
    IntSystemEnable(SYS_INT_MMCSD0INT);
    IntPrioritySet(SYS_INT_MMCSD0INT, 0, AINTC_HOSTINT_ROUTE_IRQ);
    IntSystemEnable(SYS_INT_EDMACOMPINT);
    IntPrioritySet(SYS_INT_EDMACOMPINT, 0, AINTC_HOSTINT_ROUTE_IRQ);
    IntSystemEnable(127);
    IntPrioritySet(127, 0, AINTC_HOSTINT_ROUTE_IRQ);

    RtcInit();
    UARTStdioInit();
    HSMMCSDContolInit();
    DelayTimerSetup();

    Timer2Config();
    Timer4Config();
    LedIfConfig();

    Timer2IntEnable();
    Timer4IntEnable();
    RtcSecIntEnable();

    InitI2C();

    Timer4Start(); 

    // Read config from files
    HSMMCSDCardAccessSetup();

    configRead();

    LedOn( USER_LED_1 );
    for( j = 0; j < 1000000; ++j );
    LedOff( USER_LED_1 );
    LedOn( USER_LED_2 );
    for( j = 0; j < 1000000; ++j );
    LedOff( USER_LED_2 );
    LedOn( USER_LED_3 );
    for( j = 0; j < 1000000; ++j );
    LedOff( USER_LED_3 );
    LedOn( USER_LED_4 );
    for( j = 0; j < 1000000; ++j );
    LedOff( USER_LED_4 );

    // TEMP
    //i2cTest();

    /*
    ** Loop for ever. Necessary actions shall be taken
    ** after detecting the click.
    */
    while( 1 )
    {
        EnetStatusCheckNUpdate();

        if( runCommand )
        {
            // Command blink
            LedOn( USER_LED_1 );

            if( runData[ runIndex + 1 ] == 'D' )
            {
                if( runData[ runIndex + 2 ] == 'S' )
                {
                    UARTPuts( "** DAC SET\n\r", -1 );

                    if( runData[ runIndex + 3 ] == 'A' )
                    {
                        i2cDAC_Set( 0,
                          runData[ runIndex + 4 ], runData[ runIndex + 5 ] );
                    }
                    if( runData[ runIndex + 6 ] == 'B' )
                    {
                        i2cDAC_Set( 1,
                          runData[ runIndex + 7 ], runData[ runIndex + 8 ] );
                    }
                    if( runData[ runIndex + 9 ] == 'C' )
                    {
                        i2cDAC_Set( 2,
                          runData[ runIndex + 10 ], runData[ runIndex + 11 ] );
                    }
                    if( runData[ runIndex + 12 ] == 'D' )
                    {
                        i2cDAC_Set( 3,
                          runData[ runIndex + 13 ], runData[ runIndex + 14 ] );
                    }
                }
                else if( runData[ runIndex + 2 ] == 'G' )
                {
                    UARTPuts( "** DAC GET\n\r", -1 );

                    uartData[ 0 ] = 15;
                    uartData[ 1 ] = 'D';
                    uartData[ 2 ] = 'G';

                    uartData[ 3 ] = 'A';
                    i2cDAC_Get( 0, &uartData[ 4 ] );

                    uartData[ 6 ] = 'B';
                    i2cDAC_Get( 1, &uartData[ 7 ] );

                    uartData[ 9 ] = 'C';
                    i2cDAC_Get( 2, &uartData[ 10 ] );

                    uartData[ 12 ] = 'D';
                    i2cDAC_Get( 3, &uartData[ 13 ] );

                    net_ext_send( uartData, 15 );
                }
            }
            else if( runData[ runIndex + 1 ] == 'G' )
            {
                if( runData[ runIndex + 2 ] == 'S' )
                {
                    if( runData[ runIndex + 3 ] == 0 ) // Off
                    {
                        UARTPuts( "** GPIO OFF\n\r", -1 );
                        i2cGPIO_Off( 0, 1 << runData[ runIndex + 4 ] );
                    }
                    else if( runData[ runIndex + 3 ] == 1 ) // On
                    {
                        UARTPuts( "** GPIO ON\n\r", -1 );
                        i2cGPIO_On( 0, 1 << runData[ runIndex + 4 ] );
                    }
                }
                else if( runData[ runIndex + 2 ] == 'G' )
                {
                    UARTPuts( "** GPIO GET\n\r", -1 );

                    uartData[ 0 ] = 5;
                    uartData[ 1 ] = 'G';
                    uartData[ 2 ] = 'G';

                    i2cGPIO_Get( &uartData[ 3 ] );

                    net_ext_send( uartData, 5 );
                }
            }
            else if( runData[ runIndex + 1 ] == 'U' )
            {
                UARTPuts( "** UART\n\r", -1 );
                i2cUART_Send( &(runData[ runIndex + 2 ]), 6 );
            }

            runCommand -= runData[ runIndex + 0 ];

            if( runCommand > 0 )
            {
                runIndex += runData[ runIndex + 0 ];
            }
            else
            {
                runIndex = 0;
            }

            LedOff( USER_LED_1 );
        }

        result = i2cUART_Recv( &( uartData[ 2 ] ), 30 );

        if( result > 0 )
        {
            UARTPuts( "** UART Recv: ", -1 );

            for( index = 0; index < result; ++index )
            {
                UARTPutHexNum( uartData[ index + 2 ] );
                UARTPutc( ' ' );
            }

            UARTPutc( '\n' );
            UARTPutc( '\r' );

            // Return the stage position info to the GUI
            if( uartData[ 3 ] == 0x0A ||
                uartData[ 3 ] == 0x3C )
            {
                uartData[ 0 ] = result + 2;
                uartData[ 1 ] = 'U';

                net_ext_send( uartData, result + 2 );
            }
        }
    }
}