示例#1
0
void update_screen(UART_instance_t * this_uart, int deg, float kp, float ki, float kd, float digit, k_value_t k_value)
{
	// Print the pendulum
	print_degrees(this_uart, deg);

	// Print the constants
	set_x(this_uart, 32);
	set_y(this_uart, 16);
	delay();
	char buffer[64];
	sprintf(buffer, "%07.3f\r\n%07.3f\r\n%07.3f", kp, ki, kd);
	UART_polled_tx_string( this_uart, (const uint8_t *)&buffer);

	// Clear the digit block
	erase_block(this_uart, 112, 16, 159, 56);

	// Print the digit increment/decrement
	set_x(this_uart, 112);
	delay();
	char digit_buffer[16];
	sprintf(digit_buffer, "%07.3f", digit);
	if (k_value == KP)
	{
		set_y(this_uart, 16);
	} else if (k_value == KI) {
		set_y(this_uart, 24);
	} else {
		set_y(this_uart, 32);
	}
	UART_polled_tx_string( this_uart, (const uint8_t *)&digit_buffer);
}
示例#2
0
/*
 * Simple sanity check
 */
static void mem_test(uint8_t *address)
{
    volatile uint8_t value=2;
    volatile uint32_t value32=3;
    *address = 1;
    value = *address;
    value32 = (uint32_t)*address;
    if((value32 == value) &&(value == 1))
    	UART_polled_tx_string( &g_uart, "  Read/Write success\n\r" );
    else
    	UART_polled_tx_string( &g_uart, "  Read/Write fail\n\r" );
}
示例#3
0
void setup_screen(UART_instance_t * this_uart)
{
	set_x(this_uart, 128);
	set_y(this_uart, 8);
	delay();
	uint8_t header_buff[] = {"+/-\0"};
	UART_polled_tx_string( this_uart,(const uint8_t *)&header_buff);

	set_x(this_uart, 8);
	set_y(this_uart, 16);
	delay();
	uint8_t label_buff[] = {"Kp: \r\nKi: \r\nKd: \0"};
	UART_polled_tx_string( this_uart,(const uint8_t *)&label_buff);
}
示例#4
0
/**
 *  Read from flash on RTG4
 */
static int read_program_from_flash(uint8_t *read_buf)
{
    uint16_t status;
    int flash_address = 0;
    int count = 0;
    spi_flash_status_t result;
    struct device_Info DevInfo;

    spi_flash_init();

    spi_flash_control_hw( SPI_FLASH_RESET, 0, &status );

    result = spi_flash_control_hw( SPI_FLASH_READ_DEVICE_ID,
                                          count * FLASH_SECTOR_SIZE,
                                           &DevInfo );

    result = spi_flash_control_hw( SPI_FLASH_READ_DEVICE_ID,
                                              count * FLASH_SECTOR_SIZE,
                                               &DevInfo );

    /*--------------------------------------------------------------------------
     * First fetch status register. First byte in low 8 bits, second byte in
    * upper 8 bits.
     */
    result = spi_flash_control_hw( SPI_FLASH_GET_STATUS, 0, &status );

    result = spi_flash_control_hw( SPI_FLASH_READ_DEVICE_ID,
                                              count * FLASH_SECTOR_SIZE,
                                               &DevInfo );


    /*--------------------------------------------------------------------------
     * Write something to all 32768 blocks of 256 bytes in the 8MB FLASH.
     */
   for( count = 0; count != ((32*1024)/256); ++count )
   {

        /*----------------------------------------------------------------------
         * Write our values to the FLASH, read them back and compare.
         * Placing a breakpoint on the while statement below will allow
         * you break on any failures.
         */

        spi_flash_read ( flash_address, read_buf, FLASH_SEGMENT_SIZE );
        read_buf += FLASH_SEGMENT_SIZE;

        flash_address += FLASH_SEGMENT_SIZE; /* Step to the next 256 byte chunk */
    }

   UART_polled_tx_string( &g_uart, "  Flash read success\n\r" );

   return(0);
}
示例#5
0
/*
 *  Write to flash on RTG4
 */
static int write_program_to_flash(uint8_t *write_buf)
{
    uint8_t write_buffer[FLASH_SEGMENT_SIZE];
    uint8_t read_buffer[FLASH_SEGMENT_SIZE];
    uint16_t status;
    int flash_address = 0;
    int count = 0;
    spi_flash_status_t result;
    struct device_Info DevInfo;

    spi_flash_init();

    spi_flash_control_hw( SPI_FLASH_RESET, 0, &status );

    result = spi_flash_control_hw( SPI_FLASH_READ_DEVICE_ID,
                                          count * FLASH_SECTOR_SIZE,
                                           &DevInfo );

    result = spi_flash_control_hw( SPI_FLASH_READ_DEVICE_ID,
                                              count * FLASH_SECTOR_SIZE,
                                               &DevInfo );

    /*--------------------------------------------------------------------------
     * First fetch status register. First byte in low 8 bits, second byte in
    * upper 8 bits.
     */
    result = spi_flash_control_hw( SPI_FLASH_GET_STATUS, 0, &status );

    result = spi_flash_control_hw( SPI_FLASH_READ_DEVICE_ID,
                                              count * FLASH_SECTOR_SIZE,
                                               &DevInfo );




    /*--------------------------------------------------------------------------
     * Fetch protection register value for each of the 128 sectors.
     * After power up these should all read as 0xFF
     */
   for( count = 0; count != 128; ++count )
   {
    result = spi_flash_control_hw( SPI_FLASH_GET_PROTECT,
                                      count * FLASH_SECTOR_SIZE,
                                       &read_buffer[count] );
   }

   //device D
   result = spi_flash_control_hw( SPI_FLASH_READ_DEVICE_ID,
                                              count * FLASH_SECTOR_SIZE,
                                               &DevInfo );

   /*--------------------------------------------------------------------------
    * Show sector protection in action by:
    *   - unprotecting the first sector
    *   - erasing the sector
    *   - writing some data to the first 256 bytes
    *   - protecting the first sector
    *   - erasing the first sector
    *   - reading back the first 256 bytes of the first sector
    *   - unprotecting the first sector
    *   - erasing the sector
    *   - reading back the first 256 bytes of the first sector
    *
    * The first read should still show the written data in place as the erase
    * will fail. the second read should show all 0xFFs. Step through the code
    * in debug mode and examine the read buffer after the read operations to
    * see this.
    */
   result = spi_flash_control_hw( SPI_FLASH_SECTOR_UNPROTECT, flash_address, NULL );
   //device D   works
   result = spi_flash_control_hw( SPI_FLASH_READ_DEVICE_ID,
                                              count * FLASH_SECTOR_SIZE,
                                               &DevInfo );
    result = spi_flash_control_hw( SPI_FLASH_4KBLOCK_ERASE, flash_address , NULL );
       //device D-- now working
       result = spi_flash_control_hw( SPI_FLASH_READ_DEVICE_ID,
                                                  count * FLASH_SECTOR_SIZE,
                                                   &DevInfo );
    memset( write_buffer, count, FLASH_SEGMENT_SIZE );
    strcpy( (char *)write_buffer, "Microsemi FLASH test" );
    spi_flash_write( flash_address, write_buffer, FLASH_SEGMENT_SIZE );
       //device D --
       result = spi_flash_control_hw( SPI_FLASH_READ_DEVICE_ID,
                                                  count * FLASH_SECTOR_SIZE,
                                                   &DevInfo );

    result = spi_flash_control_hw( SPI_FLASH_SECTOR_PROTECT, flash_address, NULL );
       //device D
       result = spi_flash_control_hw( SPI_FLASH_READ_DEVICE_ID,
                                                  count * FLASH_SECTOR_SIZE,
                                                   &DevInfo );
    result = spi_flash_control_hw( SPI_FLASH_4KBLOCK_ERASE, flash_address , NULL );
       //device D
       result = spi_flash_control_hw( SPI_FLASH_READ_DEVICE_ID,
                                                  count * FLASH_SECTOR_SIZE,
                                                   &DevInfo );
    result = spi_flash_control_hw( SPI_FLASH_GET_STATUS, 0, &status );
       //device D
       result = spi_flash_control_hw( SPI_FLASH_READ_DEVICE_ID,
                                                  count * FLASH_SECTOR_SIZE,
                                                   &DevInfo );

    spi_flash_read ( flash_address, read_buffer, FLASH_SEGMENT_SIZE);
       //device D
       result = spi_flash_control_hw( SPI_FLASH_READ_DEVICE_ID,
                                                  count * FLASH_SECTOR_SIZE,
                                                   &DevInfo );

    result = spi_flash_control_hw( SPI_FLASH_SECTOR_UNPROTECT, flash_address, NULL );
       //device D
       result = spi_flash_control_hw( SPI_FLASH_READ_DEVICE_ID,
                                                  count * FLASH_SECTOR_SIZE,
                                                   &DevInfo );
    result = spi_flash_control_hw( SPI_FLASH_4KBLOCK_ERASE, flash_address , NULL );
       //device D
       result = spi_flash_control_hw( SPI_FLASH_READ_DEVICE_ID,
                                                  count * FLASH_SECTOR_SIZE,
                                                   &DevInfo );
    result = spi_flash_control_hw( SPI_FLASH_GET_STATUS, 0, &status );
       //device D
       result = spi_flash_control_hw( SPI_FLASH_READ_DEVICE_ID,
                                                  count * FLASH_SECTOR_SIZE,
                                                   &DevInfo );

    result = spi_flash_control_hw( SPI_FLASH_SECTOR_UNPROTECT, flash_address, NULL );
       //device D
       result = spi_flash_control_hw( SPI_FLASH_READ_DEVICE_ID,
                                                  count * FLASH_SECTOR_SIZE,
                                                   &DevInfo );
    result = spi_flash_control_hw( SPI_FLASH_4KBLOCK_ERASE, flash_address , NULL );
       //device D
       result = spi_flash_control_hw( SPI_FLASH_READ_DEVICE_ID,
                                                  count * FLASH_SECTOR_SIZE,
                                                   &DevInfo );

    spi_flash_read ( flash_address, read_buffer, FLASH_SEGMENT_SIZE );
       //device D
       result = spi_flash_control_hw( SPI_FLASH_READ_DEVICE_ID,
                                                  count * FLASH_SECTOR_SIZE,
                                                   &DevInfo );
    /*--------------------------------------------------------------------------
     * Read the protection registers again so you can see that the first sector
     * is unprotected now.
     */
    for( count = 0; count != 128; ++count )
   {
    spi_flash_control_hw( SPI_FLASH_GET_PROTECT, count * FLASH_SECTOR_SIZE,
                             &write_buffer[count] );
   }
       //device D
       result = spi_flash_control_hw( SPI_FLASH_READ_DEVICE_ID,
                                                  count * FLASH_SECTOR_SIZE,
                                                   &DevInfo );
    /*--------------------------------------------------------------------------
     * Write something to all 32768 blocks of 256 bytes in the 8MB FLASH.
     */
   for( count = 0; count != ((32*1024)/256) /*32768*/; ++count )
   {
        /*----------------------------------------------------------------------
         * Vary the fill for each chunk of 256 bytes
         */
        memset( write_buffer, count, FLASH_SEGMENT_SIZE );
        strcpy( (char *)write_buffer, "Microsemi FLASH test" );
        /*----------------------------------------------------------------------
         * at the start of each sector we need to make sure it is unprotected
         * so we can erase blocks within it. The spi_flash_write() function
         * unprotects the sector as well but we need to start erasing before the
         * first write takes place.
         */
        if(0 == (flash_address % FLASH_SECTOR_SIZE))
        {
            result = spi_flash_control_hw( SPI_FLASH_SECTOR_UNPROTECT, flash_address, NULL );
        }
        /*----------------------------------------------------------------------
         * At the start of each 4K block we issue an erase so that we are then
         * free to write anything we want to the block. If we don't do this the
         * write may fail as we can only effectively turn 1s to 0s when we
         * write. For example if we have an erased location with 0xFF in it and
         * we write 0xAA to it first and then later on write 0x55, the resulting
         * value is 0x00...
         */
        if(0 == (flash_address % FLASH_BLOCK_SIZE))
        {
            result = spi_flash_control_hw( SPI_FLASH_4KBLOCK_ERASE, flash_address , NULL );
        }
        /*----------------------------------------------------------------------
         * Write our values to the FLASH, read them back and compare.
         * Placing a breakpoint on the while statement below will allow
         * you break on any failures.
         */
        spi_flash_write( flash_address, write_buf, FLASH_SEGMENT_SIZE );

        spi_flash_read ( flash_address, read_buffer, FLASH_SEGMENT_SIZE );
        if( memcmp( write_buf, read_buffer, FLASH_SEGMENT_SIZE ) )
        {
            while(1) // Breakpoint here will trap write faults
            {

            }

        }
        write_buf += FLASH_SEGMENT_SIZE;
        flash_address += FLASH_SEGMENT_SIZE; /* Step to the next 256 byte chunk */
    }
   /*--------------------------------------------------------------------------
    * One last look at the protection registers which should all be 0 now
    */
   for( count = 0; count != 128; ++count )
   {
    spi_flash_control_hw( SPI_FLASH_GET_PROTECT, count * FLASH_SECTOR_SIZE,
                            &write_buffer[count] );
   }

   UART_polled_tx_string( &g_uart, "  Flash write success\n\r" );

   return(0);
}
示例#6
0
inline void BT_polled_tx_string(const uint8_t* str) {
    UART_polled_tx_string(&g_bt, str);
}