void cliFunc_connectSts( char* args )
{
	print( NL );
	info_msg("UARTConnect Status");
	print( NL "Device Type:\t" );
	print( Connect_master ? "Master" : "Slave" );
	print( NL "Device Id:\t" );
	printHex( Connect_id );
	print( NL "Max Id:\t" );
	printHex( Connect_maxId );
	print( NL "Master <=" NL "\tStatus:\t");
	printHex( Connect_cableOkMaster );
	print( NL "\tFaults:\t");
	printHex32( Connect_cableFaultsMaster );
	print("/");
	printHex32( Connect_cableChecksMaster );
	print( NL "\tRx:\t");
	printHex( uart_rx_status[UART_Master].status );
	print( NL "\tTx:\t");
	printHex( uart_tx_status[UART_Master].status );
	print( NL "Slave <=" NL "\tStatus:\t");
	printHex( Connect_cableOkSlave );
	print( NL "\tFaults:\t");
	printHex32( Connect_cableFaultsSlave );
	print("/");
	printHex32( Connect_cableChecksSlave );
	print( NL "\tRx:\t");
	printHex( uart_rx_status[UART_Slave].status );
	print( NL "\tTx:\t");
	printHex( uart_tx_status[UART_Slave].status );
}
Exemple #2
0
void cliFunc_storage( char* args )
{
	print( NL );
	print("Page: ");
	printHex( storage_page_position() );
	print(", Block: ");
	printHex( storage_block_position() );
	print( NL );
	print("Address: ");
	printHex32((STORAGE_FLASH_START
		+ storage_page_position() * STORAGE_FLASH_PAGE_SIZE)
		+ (storage_block_position() * (STORAGE_SIZE + 1))
	);
	print( NL );
	print("Cleared?: ");
	printInt8( storage_is_storage_cleared() );
	print( NL );

	for (uint8_t i=0; i<module_count; i++) {
		print( NL "\033[1;32m" );
		print(storage_modules[i]->name);
		print(" Storage\033[0m" NL );
		storage_modules[i]->display();
	}
}
Exemple #3
0
// Erase flash if full
// Only erases flash if erase flag has been set
// storage_init() must be called first
//
// Returns:
//  0 - Erase was not done (invalid status for erasure)
//  1 - Erase completed
static uint8_t storage_erase_flash()
{
	// If we have wrapped around the reserved 16 pages, delete everything
	if ( current_page == 0 && erase_flag && current_storage_index == 0 )
	{
		// Erase the first 8 pages
		uint32_t status = flash_erase_page( STORAGE_FLASH_START, IFLASH_ERASE_PAGES_8 );
		if ( status )
		{
			print("Failed erasing pages 0..7: ");
#if defined(_bootloader_)
			printHex( status );
#else
			printHex32( status );
#endif
			print( NL );
		}

		// Erase the last 8 pages
		status = flash_erase_page( STORAGE_FLASH_START + (STORAGE_FLASH_PAGE_SIZE * 8), IFLASH_ERASE_PAGES_8 );
		if ( status )
		{
			print("Failed erasing pages 8..15: ");
#if defined(_bootloader_)
			printHex( status );
#else
			printHex32( status );
#endif
			print( NL );
		}

		return 1;
	}

	return 0;
}
Exemple #4
0
// Test Thread-unsafe Capability
// Capability used to test a thread-unsafe result
void Macro_testThreadUnsafe_capability( TriggerMacro *trigger, uint8_t state, uint8_t stateType, uint8_t *args )
{
	CapabilityState cstate = KLL_CapabilityState( state, stateType );

	switch ( cstate )
	{
	case CapabilityState_Debug:
		// Display capability name
		print("Macro_testThreadUnsafe()");
		return;
	default:
		break;
	}

	// Show trigger information
	print("ThreadUnsafe: ");
	Macro_showTriggerType( (TriggerType)stateType );
	print(" ");
	Macro_showScheduleType( (ScheduleState)state );
	print(" - ");
	printHex32( (intptr_t)trigger );
	print(NL);
}
Exemple #5
0
// Write storage block
// data    - Buffer to write from
// address - Starting address to write to
// size    - Number of bytes to write into storage
// clear   - Set 0 for normal write, Set 1 to indicate nothing of value in the block (empty block)
// storage_init() must be called first
//
// Returns
//  0 - Not enough space
//  1 - Success
//  2 - Failed to write successfully, but incremented counters (i.e. try again)
uint8_t storage_write(uint8_t* data, uint16_t address, uint16_t size, uint8_t clear )
{
	// Flashing buffer
	uint8_t page_buffer[STORAGE_FLASH_PAGE_SIZE];

	// Make sure there is enough address space in the storage
	if ( size + address > STORAGE_SIZE )
	{
		return 0;
	}

	// Set internal buffer to all 0xffs
	// This way it's possible to do partial writes to the page
	for ( int i = 0; i < STORAGE_FLASH_PAGE_SIZE; i++ )
	{
		page_buffer[i] = 0xff;
	}

	// Erase flash, only erases if erase_flag has been set
	storage_erase_flash();

	// Check which type of block we are writing
	uint8_t block_type = 0x00; // Normal block
	if ( clear )
	{
		// Cleared page, update status to indicate this page should be ignored
		block_type = 0x02;
		cleared_block = 1;
	}
	else
	{
		// Valid block
		cleared_block = 0;
	}

	// Clear empty page flag
	page_buffer[(current_storage_index * (STORAGE_SIZE + 1))] = block_type;

	// Prepare flashing and in-memory buffers so we can write to flash
	for ( int i = 0; i < size; i++ )
	{
		// Write to flashing buffer
		page_buffer[i + address + (current_storage_index * (STORAGE_SIZE + 1)) + 1] = data[i];

		// Write to in-memory storage
		storage_buffer[i + address] = data[i];
	}

	// Write flashing buffer to flash
	uint32_t status = flash_write(
		(STORAGE_FLASH_START + current_page * STORAGE_FLASH_PAGE_SIZE),
		(const void *)page_buffer,
		sizeof(page_buffer), 0
	);

	// Handle page increment based on storage size
#if (STORAGE_SIZE == 511)
	current_page++;
#elif (STORAGE_SIZE == 255)
	current_storage_index++;
	if ( current_storage_index > 1 )
	{
		current_page++;
		current_storage_index = 0;
	}
#elif (STORAGE_SIZE == 127)
	current_storage_index++;
	if ( current_storage_index > 3 )
	{
		current_page++;
		current_storage_index = 0;
	}
#elif (STORAGE_SIZE == 63)
	current_storage_index++;
	if ( current_storage_index > 7 )
	{
		current_page++;
		current_storage_index = 0;
	}
#endif

	// Handle page rotation
	if ( current_page > 15 )
	{
		current_page = 0;
		erase_flag = 1;
		current_storage_index = 0;
	}

	// Check status
	if ( status )
	{
		print("Failed to write to flash... ERROR: ");
#if defined(_bootloader_)
		printHex(status);
#else
		printHex32(status);
#endif
		return 2;
	}
	return 1;
}