本文整理汇总了C++中TRACE_INFO函数的典型用法代码示例。如果您正苦于以下问题:C++ TRACE_INFO函数的具体用法?C++ TRACE_INFO怎么用?C++ TRACE_INFO使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了TRACE_INFO函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: dhcpv6ForwardClientMessage
error_t dhcpv6ForwardClientMessage(Dhcpv6RelayCtx *context, uint_t index)
{
error_t error;
uint32_t interfaceId;
size_t inputMessageLen;
size_t outputMessageLen;
Dhcpv6RelayMessage *inputMessage;
Dhcpv6RelayMessage *outputMessage;
Dhcpv6Option *option;
IpAddr ipAddr;
//Point to the buffer where to store the incoming DHCPv6 message
inputMessage = (Dhcpv6RelayMessage *) (context->buffer + DHCPV6_RELAY_FORW_OVERHEAD);
//Message that will be forwarded by the DHCPv6 relay agent
outputMessage = (Dhcpv6RelayMessage *) context->buffer;
//Read incoming message
error = socketReceiveFrom(context->clientSocket[index], &ipAddr, NULL, inputMessage,
DHCPV6_MAX_MSG_SIZE - DHCPV6_RELAY_FORW_OVERHEAD, &inputMessageLen, 0);
//Any error to report?
if(error) return error;
//Debug message
TRACE_INFO("\r\nDHCPv6 message received on client-facing interface %s (%u bytes)...\r\n",
context->clientInterface[index]->name, inputMessageLen);
//Dump the contents of the message for debugging purpose
dhcpv6DumpMessage(inputMessage, inputMessageLen);
//The source address must be a valid IPv6 address
if(ipAddr.length != sizeof(Ipv6Addr))
return ERROR_INVALID_ADDRESS;
//Check the length of the DHCPv6 message
if(inputMessageLen < sizeof(Dhcpv6Message))
return ERROR_INVALID_MESSAGE;
//When the relay agent receives a valid message to be relayed,
//it constructs a new Relay-Forward message
outputMessage->msgType = DHCPV6_MSG_TYPE_RELAY_FORW;
//Inspect the message type
switch(inputMessage->msgType)
{
//Message received from a client?
case DHCPV6_MSG_TYPE_SOLICIT:
case DHCPV6_MSG_TYPE_REQUEST:
case DHCPV6_MSG_TYPE_CONFIRM:
case DHCPV6_MSG_TYPE_RENEW:
case DHCPV6_MSG_TYPE_REBIND:
case DHCPV6_MSG_TYPE_RELEASE:
case DHCPV6_MSG_TYPE_DECLINE:
case DHCPV6_MSG_TYPE_INFO_REQUEST:
//If the relay agent received the message to be relayed from a client
//the hop-count in the Relay-Forward message is set to 0
outputMessage->hopCount = 0;
//Continue processing
break;
//Message received from another relay agent?
case DHCPV6_MSG_TYPE_RELAY_FORW:
//If the message received by the relay agent is a Relay-Forward message
//and the hop-count in the message is greater than or equal to 32, the
//relay agent discards the received message
if(inputMessage->hopCount >= DHCPV6_HOP_COUNT_LIMIT)
return ERROR_INVALID_MESSAGE;
//Set the hop-count field to the value of the hop-count field in
//the received message incremented by 1
outputMessage->hopCount = inputMessage->hopCount + 1;
//Continue processing
break;
//Message received from a server?
default:
//Discard ADVERTISE, REPLY, RECONFIGURE and RELAY-REPL messages
return ERROR_INVALID_MESSAGE;
}
//Set the link-address field to the unspecified address
outputMessage->linkAddress = IPV6_UNSPECIFIED_ADDR;
//Copy the source address from the header of the IP datagram in
//which the message was received to the peer-address field
outputMessage->peerAddress = ipAddr.ipv6Addr;
//Size of the Relay-Forward message
outputMessageLen = sizeof(Dhcpv6RelayMessage);
//Get the interface identifier
interfaceId = context->clientInterface[index]->identifier;
//Convert the 32-bit integer to network byte order
interfaceId = htonl(interfaceId);
//If the relay agent cannot use the address in the link-address field
//to identify the interface through which the response to the client
//will be relayed, the relay agent must include an Interface ID option
dhcpv6AddOption(outputMessage, &outputMessageLen,
DHCPV6_OPTION_INTERFACE_ID, &interfaceId, sizeof(interfaceId));
//Copy the received DHCPv6 message into a Relay Message option
option = dhcpv6AddOption(outputMessage, &outputMessageLen,
DHCPV6_OPTION_RELAY_MSG, NULL, 0);
//Set the appropriate length of the option
option->length = htons(inputMessageLen);
//Adjust the length of the Relay-Forward message
//.........这里部分代码省略.........
示例2: LoadLogicalMapping
//------------------------------------------------------------------------------
/// Loads the logical mapping contained in the given physical block.
/// Returns 0 if successful; otherwise, returns a NandCommon_ERROR code.
/// \param mapped Pointer to a MappedNandFlash instance.
/// \param physicalBlock Physical block number.
//------------------------------------------------------------------------------
static unsigned char LoadLogicalMapping(
struct MappedNandFlash *mapped,
unsigned short physicalBlock)
{
unsigned char error;
unsigned short pageDataSize =
NandFlashModel_GetPageDataSize(MODEL(mapped));
unsigned short numBlocks =
ManagedNandFlash_GetDeviceSizeInBlocks(MANAGED(mapped));
unsigned char *pDataBuffer = RawNandFlash_GetDataBuffer(RAW(mapped));
unsigned int remainingSize;
unsigned char *currentBuffer;
unsigned short currentPage;
unsigned int readSize;
unsigned int i;
unsigned char status;
signed short logicalBlock;
//signed short firstBlock, lastBlock;
TRACE_INFO("LoadLogicalMapping(B#%d)\r\n", physicalBlock);
// Load mapping from pages #1 - #XXX of block
currentBuffer = (unsigned char *) mapped->logicalMapping;
remainingSize = sizeof(mapped->logicalMapping);
currentPage = 1;
while (remainingSize > 0) {
// Read page
readSize = min(remainingSize, pageDataSize);
error = ManagedNandFlash_ReadPage(MANAGED(mapped),
physicalBlock,
currentPage,
pDataBuffer,
0);
if (error) {
RawNandFlash_ReleaseDataBuffer(RAW(mapped));
TRACE_ERROR(
"LoadLogicalMapping: Failed to load mapping\r\n");
return error;
}
// Copy page info
memcpy(currentBuffer, pDataBuffer, readSize);
currentBuffer += readSize;
remainingSize -= readSize;
currentPage++;
}
// Store mapping block index
mapped->logicalMappingBlock = physicalBlock;
// Power-loss recovery
for (i=0; i < numBlocks; i++) {
// Check that this is not the logical mapping block
if (i != physicalBlock) {
status = mapped->managed.blockStatuses[i].status;
logicalBlock = MappedNandFlash_PhysicalToLogical(mapped, i);
// Block is LIVE
if (status == NandBlockStatus_LIVE) {
// Block is not mapped -> release it
if (logicalBlock == -1) {
TRACE_WARNING_WP("-I- Release unmapped LIVE #%d\r\n",
i);
ManagedNandFlash_ReleaseBlock(MANAGED(mapped), i);
}
}
// Block is DIRTY
else if (status == NandBlockStatus_DIRTY) {
// Block is mapped -> fake it as live
if (logicalBlock != -1) {
TRACE_WARNING_WP("-I- Mark mapped DIRTY #%d -> LIVE\r\n",
i);
mapped->managed.blockStatuses[i].status =
NandBlockStatus_LIVE;
}
}
// Block is FREE or BAD
else {
// Block is mapped -> remove it from mapping
if (logicalBlock != -1) {
TRACE_WARNING_WP("-I- Unmap FREE or BAD #%d\r\n", i);
mapped->logicalMapping[logicalBlock] = -1;
}
//.........这里部分代码省略.........
示例3: FindLogicalMappingBlock
//------------------------------------------------------------------------------
/// Scans a mapped nandflash to find an existing logical block mapping. If a
/// block contains the mapping, its index is stored in the provided variable (if
/// pointer is not 0).
/// Returns 0 if mapping has been found; otherwise returns
/// NandCommon_ERROR_NOMAPPING if no mapping exists, or another
/// NandCommon_ERROR_xxx code.
/// \param mapped Pointer to a MappedNandFlash instance.
/// \param logicalMappingBlock Pointer to a variable for storing the block
/// number.
//------------------------------------------------------------------------------
static unsigned char FindLogicalMappingBlock(
const struct MappedNandFlash *mapped,
signed short *logicalMappingBlock)
{
unsigned short block;
unsigned char found;
unsigned short numBlocks = ManagedNandFlash_GetDeviceSizeInBlocks(MANAGED(mapped));
unsigned short pageDataSize = NandFlashModel_GetPageDataSize(MODEL(mapped));
unsigned char *pDataBuffer = RawNandFlash_GetDataBuffer(RAW(mapped));
unsigned char error;
//unsigned char data[NandCommon_MAXPAGEDATASIZE];
unsigned int i;
TRACE_INFO("FindLogicalMappingBlock()~%d\r\n", numBlocks);
// Search each LIVE block
found = 0;
block = 0;
while (!found && (block < numBlocks)) {
// Check that block is LIVE
if (MANAGED(mapped)->blockStatuses[block].status == NandBlockStatus_LIVE) {
// Read block
TRACE_INFO("Checking LIVE block #%d\r\n", block);
error = ManagedNandFlash_ReadPage(MANAGED(mapped), block, 0, pDataBuffer, 0);
if (!error) {
// Compare data with logical mapping pattern
i = 0;
found = 1;
while ((i < pageDataSize) && found) {
if (pDataBuffer[i] != PATTERN(i)) {
found = 0;
}
i++;
}
// If this is the mapping, stop looking
if (found) {
TRACE_WARNING_WP("-I- Logical mapping in block #%d\r\n",
block);
if (logicalMappingBlock) {
*logicalMappingBlock = block;
}
RawNandFlash_ReleaseDataBuffer(RAW(mapped));
return 0;
}
}
else if (error != NandCommon_ERROR_WRONGSTATUS) {
TRACE_ERROR(
"FindLogicalMappingBlock: Failed to scan block #%d\r\n",
block);
RawNandFlash_ReleaseDataBuffer(RAW(mapped));
return error;
}
}
block++;
}
RawNandFlash_ReleaseDataBuffer(RAW(mapped));
TRACE_WARNING("No logical mapping found in device\r\n");
return NandCommon_ERROR_NOMAPPING;
}
示例4: MSDDFunctionDriver_RequestHandler
//-----------------------------------------------------------------------------
/// Invoked when a new SETUP request is received from the host. Forwards the
/// request to the Mass Storage device driver handler function.
/// \param request Pointer to a USBGenericRequest instance.
/// \return 0 if the request is Unsupported, 1 if the request handled.
//-----------------------------------------------------------------------------
unsigned char MSDDFunctionDriver_RequestHandler(
const USBGenericRequest *request)
{
// Handle requests
switch (USBGenericRequest_GetRequest(request)) {
//---------------------
case USBGenericRequest_CLEARFEATURE:
//---------------------
TRACE_INFO("ClrFeat ");
switch (USBFeatureRequest_GetFeatureSelector(request)) {
//---------------------
case USBFeatureRequest_ENDPOINTHALT:
//---------------------
TRACE_INFO("Hlt ");
// Do not clear the endpoint halt status if the device is waiting
// for a reset recovery sequence
if (!msdDriver.waitResetRecovery) {
// Forward the request to the standard handler
return 0;
}
else {
TRACE_INFO("No ");
}
USBD_Write(0, 0, 0, 0, 0);
break;
//------
default:
//------
// Forward the request to the standard handler
return 0;
}
break;
//-------------------
case MSD_GET_MAX_LUN:
//-------------------
TRACE_INFO("gMaxLun ");
// Check request parameters
if ((request->wValue == 0)
&& (request->wIndex == MSDD_Descriptors_INTERFACENUM)
&& (request->wLength == 1)) {
USBD_Write(0, &(msdDriver.maxLun), 1, 0, 0);
}
else {
TRACE_WARNING(
"MSDDriver_RequestHandler: GetMaxLUN(%d,%d,%d)\n\r",
request->wValue, request->wIndex, request->wLength);
USBD_Stall(0);
}
break;
//-----------------------
case MSD_BULK_ONLY_RESET:
//-----------------------
TRACE_INFO("Rst ");
// Check parameters
if ((request->wValue == 0)
&& (request->wIndex == MSDD_Descriptors_INTERFACENUM)
&& (request->wLength == 0)) {
// Reset the MSD driver
MSDD_Reset();
USBD_Write(0, 0, 0, 0, 0);
}
else {
TRACE_WARNING(
"MSDDriver_RequestHandler: Reset(%d,%d,%d)\n\r",
request->wValue, request->wIndex, request->wLength);
USBD_Stall(0);
}
break;
//------
default:
//------
// Forward request to standard handler
return 0;
}
return 1;
}
示例5: dnsProcessResponse
void dnsProcessResponse(NetInterface *interface, const IpPseudoHeader *pseudoHeader,
const UdpHeader *udpHeader, const ChunkedBuffer *buffer, size_t offset, void *params)
{
uint_t i;
uint_t j;
size_t pos;
size_t length;
DnsHeader *message;
DnsQuestion *question;
DnsResourceRecord *resourceRecord;
DnsCacheEntry *entry;
//Retrieve the length of the DNS message
length = chunkedBufferGetLength(buffer) - offset;
//Ensure the DNS message is valid
if(length < sizeof(DnsHeader))
return;
if(length > DNS_MESSAGE_MAX_SIZE)
return;
//Point to the DNS message header
message = chunkedBufferAt(buffer, offset);
//Sanity check
if(!message) return;
//Debug message
TRACE_INFO("DNS message received (%" PRIuSIZE " bytes)...\r\n", length);
//Dump message
dnsDumpMessage(message, length);
//Check message type
if(!message->qr)
return;
//The DNS message shall contain one question
if(ntohs(message->qdcount) != 1)
return;
//Acquire exclusive access to the DNS cache
osAcquireMutex(&dnsCacheMutex);
//Loop through DNS cache entries
for(i = 0; i < DNS_CACHE_SIZE; i++)
{
//Point to the current entry
entry = &dnsCache[i];
//DNS name resolution in progress?
if(entry->state == DNS_STATE_IN_PROGRESS &&
entry->protocol == HOST_NAME_RESOLVER_DNS)
{
//Check destination port number
if(entry->port == ntohs(udpHeader->destPort))
{
//Compare identifier against the expected one
if(ntohs(message->id) != entry->id)
break;
//Point to the first question
pos = sizeof(DnsHeader);
//Parse domain name
pos = dnsParseName(message, length, pos, NULL, 0);
//Invalid name?
if(!pos)
break;
//Malformed mDNS message?
if((pos + sizeof(DnsQuestion)) > length)
break;
//Compare domain name
if(!dnsCompareName(message, length, sizeof(DnsHeader), entry->name, 0))
break;
//Point to the corresponding entry
question = DNS_GET_QUESTION(message, pos);
//Check the class of the query
if(ntohs(question->qclass) != DNS_RR_CLASS_IN)
break;
//Check the type of the query
if(entry->type == HOST_TYPE_IPV4 && ntohs(question->qtype) != DNS_RR_TYPE_A)
break;
if(entry->type == HOST_TYPE_IPV6 && ntohs(question->qtype) != DNS_RR_TYPE_AAAA)
break;
//Make sure recursion is available
if(!message->ra)
{
//The entry should be deleted since name resolution has failed
dnsDeleteEntry(entry);
//Exit immediately
break;
}
//Check return code
if(message->rcode != DNS_RCODE_NO_ERROR)
{
//The entry should be deleted since name resolution has failed
dnsDeleteEntry(entry);
//.........这里部分代码省略.........
示例6: if
DynamixelSimpleAPI::DynamixelSimpleAPI(int servoSerie)
{
if (servoSerie != SERVO_UNKNOWN)
{
if (servoSerie >= SERVO_HERKULEX)
{
ackPolicy = 1;
maxId = 253;
protocolVersion = 1;
servoSerie = SERVO_DRS;
if (servoSerie == SERVO_DRS_0402 || servoSerie == SERVO_DRS_0602)
{
ct = DRS0x02_control_table;
}
else if (servoSerie == SERVO_DRS_0401 || servoSerie == SERVO_DRS_0601)
{
ct = DRS0x01_control_table;
}
else
{
ct = DRS0101_control_table;
}
TRACE_INFO(DAPI, "- Using HerkuleX communication protocol\n");
}
else //if (servos >= SERVO_DYNAMIXEL)
{
ackPolicy = 2;
maxId = 252;
if (servoSerie >= SERVO_PRO)
{
protocolVersion = 2;
servoSerie = SERVO_PRO;
ct = PRO_control_table;
}
else if (servoSerie >= SERVO_XL)
{
protocolVersion = 2;
servoSerie = SERVO_XL;
ct = XL320_control_table;
}
else // SERVO AX to MX
{
// Default is Dynamixel MX, the more 'capable' of the Dynamixel v1 series
protocolVersion = 1;
servoSerie = SERVO_MX;
ct = MX_control_table;
if (serialDevice == SERIAL_USB2AX)
{
// The USB2AX device uses the ID 253 for itself
maxId = 252;
}
else
{
maxId = 253;
}
}
if (protocolVersion == 2)
{
TRACE_INFO(DAPI, "- Using Dynamixel communication protocol version 2\n");
}
else
{
TRACE_INFO(DAPI, "- Using Dynamixel communication protocol version 1\n");
}
}
}
else
{
TRACE_WARNING(DAPI, "Warning: Unknown servo serie!\n");
}
}
示例7: vApplicationTickHook
/* FreeRTOS Callbacks */
void vApplicationTickHook(void) {
static int i = 0;
if (i < 1000) i++;
else { TRACE_INFO("tick\n"); i = 0; }
}
示例8: main
int_t main(void)
{
error_t error;
NetInterface *interface;
OsTask *task;
MacAddr macAddr;
#if (APP_USE_DHCP == DISABLED)
Ipv4Addr ipv4Addr;
#endif
#if (APP_USE_SLAAC == DISABLED)
Ipv6Addr ipv6Addr;
#endif
//System initialization
systemInit();
//Initialize kernel
osInitKernel();
//Configure debug UART
debugInit(115200);
//Start-up message
TRACE_INFO("\r\n");
TRACE_INFO("******************************\r\n");
TRACE_INFO("*** CycloneSSL Client Demo ***\r\n");
TRACE_INFO("******************************\r\n");
TRACE_INFO("Copyright: 2010-2014 Oryx Embedded\r\n");
TRACE_INFO("Compiled: %s %s\r\n", __DATE__, __TIME__);
TRACE_INFO("Target: PIC32MX795F512L\r\n");
TRACE_INFO("\r\n");
//Configure I/Os
ioInit();
//Generate a random seed
//PRNG initialization
error = yarrowInit(&yarrowContext);
//Any error to report?
if(error)
{
//Debug message
TRACE_ERROR("Failed to initialize PRNG!\r\n");
//Exit immediately
return ERROR_FAILURE;
}
//Properly seed the PRNG
error = yarrowSeed(&yarrowContext, (uint8_t *) seed, 32);
//Any error to report?
if(error)
{
//Debug message
TRACE_ERROR("Failed to seed PRNG!\r\n");
//Exit immediately
return error;
}
//Debug message
TRACE_INFO("Loading credentials...\r\n");
//Start of exception handling block
do
{
//Load trusted CA certificates
error = resGetData(APP_CA_CERT_BUNDLE, (uint8_t **) &trustedCaList, &trustedCaListLength);
//Any error to report?
if(error) break;
//Load client's certificate
error = resGetData(APP_CLIENT_CERT, (uint8_t **) &clientCert, &clientCertLength);
//Any error to report?
if(error) break;
//Load client's private key
error = resGetData(APP_CLIENT_PRIVATE_KEY, (uint8_t **) &clientPrivateKey, &clientPrivateKeyLength);
//Any error to report?
if(error) break;
//End of exception handling block
} while(0);
//Check error code
if(error)
{
//Debug message
TRACE_ERROR("Failed to load credentials!\r\n");
}
//TCP/IP stack initialization
error = tcpIpStackInit();
//Any error to report?
if(error)
{
//Debug message
TRACE_ERROR("Failed to initialize TCP/IP stack!\r\n");
}
//Configure the first Ethernet interface
interface = &netInterface[0];
//.........这里部分代码省略.........
示例9: dm9000EventHandler
void dm9000EventHandler(NetInterface *interface)
{
error_t error;
uint8_t status;
size_t length;
//Read interrupt status register
status = dm9000ReadReg(DM9000_REG_ISR);
//Check whether the link status has changed?
if(status & ISR_LNKCHG)
{
//Clear interrupt flag
dm9000WriteReg(DM9000_REG_ISR, ISR_LNKCHG);
//Read network status register
status = dm9000ReadReg(DM9000_REG_NSR);
//Check link state
if(status & NSR_LINKST)
{
//Link is up
interface->linkState = TRUE;
//Get current speed
interface->speed100 = (status & NSR_SPEED) ? FALSE : TRUE;
//Read network control register
status = dm9000ReadReg(DM9000_REG_NCR);
//Determine the new duplex mode
interface->fullDuplex = (status & NCR_FDX) ? TRUE : FALSE;
//Display link state
TRACE_INFO("Link is up (%s)...\r\n", interface->name);
//Display actual speed and duplex mode
TRACE_INFO("%s %s\r\n",
interface->speed100 ? "100BASE-TX" : "10BASE-T",
interface->fullDuplex ? "Full-Duplex" : "Half-Duplex");
}
else
{
//Link is down
interface->linkState = FALSE;
//Display link state
TRACE_INFO("Link is down (%s)...\r\n", interface->name);
}
//Process link state change event
nicNotifyLinkChange(interface);
}
//Check whether a packet has been received?
if(status & ISR_PR)
{
//Clear interrupt flag
dm9000WriteReg(DM9000_REG_ISR, ISR_PR);
//Process all pending packets
do
{
//Read incoming packet
error = dm9000ReceivePacket(interface,
interface->ethFrame, ETH_MAX_FRAME_SIZE, &length);
//Check whether a valid packet has been received
if(!error)
{
//Pass the packet to the upper layer
nicProcessPacket(interface, interface->ethFrame, length);
}
//No more data in the receive buffer?
} while(error != ERROR_BUFFER_EMPTY);
}
//Re-enable LNKCHGI and PRI interrupts
dm9000WriteReg(DM9000_REG_IMR, IMR_PAR | IMR_LNKCHGI | IMR_PTI | IMR_PRI);
}
示例10: main
int main(void)
{
uint32_t i;
uint32_t deviceId;
uint8_t ucKey;
uint8_t TestPassed = 0;
/* Disable watchdog */
WDT_Disable(WDT);
/* Output example information */
printf("-- QSPI Serialflash Example %s --\n\r", SOFTPACK_VERSION);
printf("-- %s\n\r", BOARD_NAME);
printf("-- Compiled: %s %s With %s--\n\r", __DATE__, __TIME__ , COMPILER_NAME);
SCB_EnableICache();
SCB_EnableDCache();
TimeTick_Configure();
PIO_Configure(Qspi_pins, PIO_LISTSIZE(Qspi_pins));
ENABLE_PERIPHERAL(ID_QSPI);
QSPI_UserMenu();
while (1) {
ucKey = DBG_GetChar();
switch (ucKey) {
case '1' :
S25FL1D_InitFlashInterface(1);
TRACE_INFO("QSPI drivers initialized ");
/* enable quad mode */
S25FL1D_QuadMode(ENABLE);
PeripheralInit = 1;
break;
case '2' :
S25FL1D_InitFlashInterface(0);
TRACE_INFO("QSPI Initialized in SPI mode");
S25FL1D_QuadMode(DISABLE);
PeripheralInit = 2;
break;
case '3' :
QSPI_UserMenu();
PeripheralInit = 0;
break;
default:
break;
}
if (PeripheralInit) {
while (1) {
deviceId = S25FL1D_ReadJedecId();
printf("ID read: Manufacture ID = 0x%x, Device Type = 0x%x, \
Capacity = 0x%x\n\r",
(uint8_t)(deviceId), (uint8_t)(deviceId >> 8), (uint8_t)(deviceId >> 16));
break;
}
/* erase entire chip */
S25FL1D_EraseChip();
/* fill up the buffer*/
_fillupbuffer(TestBuffer, BUFFER_SIZE);
printf("Writing buffer to Flash memory...... \n\r");
/* write the buffer to flash memory */
for (i = 0; i < 0x200000; ) {
S25FL1D_Write(TestBuffer, BUFFER_SIZE, i, 0);
i += BUFFER_SIZE;
}
TestPassed = _VerifyData(0, 0x200000, TestBuffer, 0);
printf("Erasing a block(64 KB) @ Add 0x10000 \n\r");
S25FL1D_Erase64KBlock(0x10000);
memset(TestBuffer, 0xFFFFFF, BUFFER_SIZE);
SCB_CleanDCache_by_Addr((uint32_t *)TestBuffer, sizeof(TestBuffer));
TestPassed = _VerifyData(0x10000, (0x10000 + 64 * 1024), TestBuffer, 0);
if (TestPassed)
printf(" \n\r**** Test Failed ***** \n\r");
else
printf(" \n\r### Test Passed ###\n\r");
}
PeripheralInit = 0;
QSPI_UserMenu();
}
}
示例11: sslClientTest
error_t sslClientTest(void)
{
error_t error;
size_t length;
IpAddr ipAddr;
static char_t buffer[256];
//Underlying socket
Socket *socket = NULL;
//SSL/TLS context
TlsContext *tlsContext = NULL;
//Debug message
TRACE_INFO("Resolving server name...\r\n");
//Resolve SSL server name
error = getHostByName(NULL, APP_SERVER_NAME, &ipAddr, 0);
//Any error to report?
if(error)
{
//Debug message
TRACE_INFO("Failed to resolve server name!\r\n");
//Exit immediately
return error;
}
//Create a new socket to handle the request
socket = socketOpen(SOCKET_TYPE_STREAM, SOCKET_IP_PROTO_TCP);
//Any error to report?
if(!socket)
{
//Debug message
TRACE_INFO("Failed to open socket!\r\n");
//Exit immediately
return ERROR_OPEN_FAILED;
}
//Start of exception handling block
do
{
//Debug message
TRACE_INFO("Connecting to SSL server %s\r\n", ipAddrToString(&ipAddr, NULL));
//Connect to the SSL server
error = socketConnect(socket, &ipAddr, APP_SERVER_PORT);
//Any error to report?
if(error) break;
//Initialize SSL/TLS context
tlsContext = tlsInit();
//Initialization failed?
if(!tlsContext)
{
//Report an error
error = ERROR_OUT_OF_MEMORY;
//Exit immediately
break;
}
//Bind TLS to the relevant socket
error = tlsSetSocket(tlsContext, socket);
//Any error to report?
if(error) break;
//Select client operation mode
error = tlsSetConnectionEnd(tlsContext, TLS_CONNECTION_END_CLIENT);
//Any error to report?
if(error) break;
//Set the PRNG algorithm to be used
error = tlsSetPrng(tlsContext, YARROW_PRNG_ALGO, &yarrowContext);
//Any error to report?
if(error) break;
#if (APP_SET_CIPHER_SUITES == ENABLED)
//Preferred cipher suite list
error = tlsSetCipherSuites(tlsContext, cipherSuites, arraysize(cipherSuites));
//Any error to report?
if(error) break;
#endif
#if (APP_SET_SERVER_NAME == ENABLED)
//Set the fully qualified domain name of the server
error = tlsSetServerName(tlsContext, APP_SERVER_NAME);
//Any error to report?
if(error) break;
#endif
#if (APP_SET_TRUSTED_CA_LIST == ENABLED)
//Import the list of trusted CA certificates
error = tlsSetTrustedCaList(tlsContext, trustedCaList, trustedCaListLength);
//Any error to report?
if(error) break;
#endif
#if (APP_SET_CLIENT_CERT == ENABLED)
//Import the client's certificate
error = tlsAddCertificate(tlsContext, clientCert,
clientCertLength, clientPrivateKey, clientPrivateKeyLength);
//Any error to report?
//.........这里部分代码省略.........
示例12: LoadLogicalMapping
/**
* \brief Loads the logical mapping contained in the given physical block.
* block contains the mapping, its index is stored in the provided variable (if
* pointer is not 0).
*
* \param mapped Pointer to a MappedNandFlash instance.
* \param physicalBlock Physical block number.
* \return 0 if successful; otherwise, returns a NandCommon_ERROR code.
*/
static unsigned char LoadLogicalMapping(
struct MappedNandFlash *mapped,
unsigned short physicalBlock)
{
unsigned char error;
unsigned char data[NandCommon_MAXPAGEDATASIZE];
unsigned short pageDataSize =
NandFlashModel_GetPageDataSize(MODEL(mapped));
unsigned short numBlocks =
ManagedNandFlash_GetDeviceSizeInBlocks(MANAGED(mapped));
unsigned int remainingSize;
unsigned char *currentBuffer;
unsigned short currentPage;
unsigned int readSize;
unsigned int i;
unsigned char status;
signed short logicalBlock;
/*signed short firstBlock, lastBlock;*/
TRACE_INFO("LoadLogicalMapping(B#%d)\n\r", physicalBlock);
/* Load mapping from pages #1 - #XXX of block*/
currentBuffer = (unsigned char *) mapped->logicalMapping;
remainingSize = sizeof(mapped->logicalMapping);
currentPage = 1;
while (remainingSize > 0) {
/* Read page*/
readSize = min(remainingSize, pageDataSize);
error = ManagedNandFlash_ReadPage(MANAGED(mapped),
physicalBlock,
currentPage,
data,
0);
if (error) {
TRACE_ERROR(
"LoadLogicalMapping: Failed to load mapping\n\r");
return error;
}
/* Copy page info*/
memcpy(currentBuffer, data, readSize);
currentBuffer += readSize;
remainingSize -= readSize;
currentPage++;
}
/* Store mapping block index*/
mapped->logicalMappingBlock = physicalBlock;
/* Power-loss recovery*/
for (i=0; i < numBlocks; i++) {
/* Check that this is not the logical mapping block*/
if (i != physicalBlock) {
status = mapped->managed.blockStatuses[i].status;
logicalBlock = MappedNandFlash_PhysicalToLogical(mapped, i);
/* Block is LIVE*/
if (status == NandBlockStatus_LIVE) {
/* Block is not mapped -> release it*/
if (logicalBlock == -1) {
TRACE_WARNING_WP("-I- Release unmapped LIVE #%d\n\r",
i);
ManagedNandFlash_ReleaseBlock(MANAGED(mapped), i);
}
}
/* Block is DIRTY*/
else if (status == NandBlockStatus_DIRTY) {
/* Block is mapped -> fake it as live*/
if (logicalBlock != -1) {
TRACE_WARNING_WP("-I- Mark mapped DIRTY #%d -> LIVE\n\r",
i);
mapped->managed.blockStatuses[i].status =
NandBlockStatus_LIVE;
}
}
/* Block is FREE or BAD*/
else {
/* Block is mapped -> remove it from mapping*/
if (logicalBlock != -1) {
TRACE_WARNING_WP("-I- Unmap FREE or BAD #%d\n\r", i);
//.........这里部分代码省略.........
示例13: dhcpv6RelayStart
error_t dhcpv6RelayStart(Dhcpv6RelayCtx *context, const Dhcpv6RelaySettings *settings)
{
error_t error;
uint_t i;
OsTask *task;
//Debug message
TRACE_INFO("Starting DHCPv6 relay agent...\r\n");
//Ensure the parameters are valid
if(!context || !settings)
return ERROR_INVALID_PARAMETER;
//The pointer to the network-facing interface shall be valid
if(!settings->serverInterface)
return ERROR_INVALID_INTERFACE;
//Check the number of client-facing interfaces
if(!settings->clientInterfaceCount)
return ERROR_INVALID_PARAMETER;
if(settings->clientInterfaceCount >= DHCPV6_RELAY_MAX_CLIENT_IF)
return ERROR_INVALID_PARAMETER;
//Loop through the client-facing interfaces
for(i = 0; i < settings->clientInterfaceCount; i++)
{
//A valid pointer is required for each interface
if(!settings->clientInterface[i])
return ERROR_INVALID_INTERFACE;
}
//Check the address to be used when forwarding messages to the server
if(ipv6CompAddr(&settings->serverAddress, &IPV6_UNSPECIFIED_ADDR))
return ERROR_INVALID_ADDRESS;
//Clear the DHCPv6 relay agent context
memset(context, 0, sizeof(Dhcpv6RelayCtx));
//Save the network-facing interface
context->serverInterface = settings->serverInterface;
//Save the number of client-facing interfaces
context->clientInterfaceCount = settings->clientInterfaceCount;
//Save all the client-facing interfaces
for(i = 0; i < context->clientInterfaceCount; i++)
context->clientInterface[i] = settings->clientInterface[i];
//Save the address to be used when relaying client messages to the server
context->serverAddress = settings->serverAddress;
//Join the All_DHCP_Relay_Agents_and_Servers multicast group
//for each client-facing interface
error = dhcpv6RelayJoinMulticastGroup(context);
//Any error to report?
if(error) return error;
//Start of exception handling block
do
{
//Open a UDP socket to handle the network-facing interface
context->serverSocket = socketOpen(SOCKET_TYPE_DGRAM, SOCKET_PROTOCOL_UDP);
//Failed to open socket?
if(!context->serverSocket)
{
//Report an error
error = ERROR_OPEN_FAILED;
//Stop processing
break;
}
//Explicitly associate the socket with the relevant interface
error = socketBindToInterface(context->serverSocket, context->serverInterface);
//Unable to bind the socket to the desired interface?
if(error) break;
//Relay agents listen for DHCPv6 messages on UDP port 547
error = socketBind(context->serverSocket, &IP_ADDR_ANY, DHCPV6_SERVER_PORT);
//Unable to bind the socket to the desired port?
if(error) break;
//Only accept datagrams with source port number 547
error = socketConnect(context->serverSocket, &IP_ADDR_ANY, DHCPV6_SERVER_PORT);
//Any error to report?
if(error) break;
//If the relay agent relays messages to the All_DHCP_Servers address
//or other multicast addresses, it sets the Hop Limit field to 32
//Loop through the client-facing interfaces
for(i = 0; i < context->clientInterfaceCount; i++)
{
//Open a UDP socket to handle the current interface
context->clientSocket[i] = socketOpen(SOCKET_TYPE_DGRAM, SOCKET_PROTOCOL_UDP);
//Failed to open socket?
if(!context->clientSocket[i])
{
//Report an error
error = ERROR_OPEN_FAILED;
//Stop processing
break;
}
//Explicitly associate the socket with the relevant interface
//.........这里部分代码省略.........
示例14: dhcpv6ForwardRelayReplyMessage
error_t dhcpv6ForwardRelayReplyMessage(Dhcpv6RelayCtx *context)
{
error_t error;
uint_t i;
uint32_t interfaceId;
size_t inputMessageLen;
size_t outputMessageLen;
Dhcpv6RelayMessage *inputMessage;
Dhcpv6Message *outputMessage;
Dhcpv6Option *option;
IpAddr ipAddr;
uint16_t port;
//Point to the buffer where to store the incoming DHCPv6 message
inputMessage = (Dhcpv6RelayMessage *) context->buffer;
//Read incoming message
error = socketReceiveFrom(context->serverSocket, &ipAddr, &port,
inputMessage, DHCPV6_MAX_MSG_SIZE, &inputMessageLen, 0);
//Any error to report?
if(error) return error;
//Debug message
TRACE_INFO("\r\nDHCPv6 message received on network-facing interface %s (%u bytes)...\r\n",
context->serverInterface->name, inputMessageLen);
//Dump the contents of the message for debugging purpose
dhcpv6DumpMessage(inputMessage, inputMessageLen);
//Check the length of the DHCPv6 message
if(inputMessageLen < sizeof(Dhcpv6RelayMessage))
return ERROR_INVALID_MESSAGE;
//Inspect the message type and only forward Relay-Reply messages.
//Other DHCPv6 message types must be silently discarded
if(inputMessage->msgType != DHCPV6_MSG_TYPE_RELAY_REPL)
return ERROR_INVALID_MESSAGE;
//Get the length of the Options field
inputMessageLen -= sizeof(Dhcpv6Message);
//Check whether an Interface ID option is included in the Relay-Reply
option = dhcpv6GetOption(inputMessage->options, inputMessageLen, DHCPV6_OPTION_INTERFACE_ID);
//Failed to retrieve specified option?
if(!option || ntohs(option->length) != sizeof(interfaceId))
return ERROR_INVALID_MESSAGE;
//Read the Interface ID option contents
memcpy(&interfaceId, option->value, sizeof(interfaceId));
//Convert the 32-bit integer from network byte order
interfaceId = ntohl(interfaceId);
//The Relay-Reply message must include a Relay Message option
option = dhcpv6GetOption(inputMessage->options, inputMessageLen, DHCPV6_OPTION_RELAY_MSG);
//Failed to retrieve specified option?
if(!option || ntohs(option->length) < sizeof(Dhcpv6Message))
return ERROR_INVALID_MESSAGE;
//Extract the message from the Relay Message option
outputMessage = (Dhcpv6Message *) option->value;
//Save the length of the message
outputMessageLen = ntohs(option->length);
//Loop through client-facing interfaces
for(i = 0; i < context->clientInterfaceCount; i++)
{
//Check whether the current interface matches the Interface ID option
if(context->clientInterface[i]->identifier == interfaceId)
{
//Debug message
TRACE_INFO("Forwarding DHCPv6 message on client-facing interface %s (%u bytes)...\r\n",
context->clientInterface[i]->name, outputMessageLen);
//Dump the contents of the message for debugging purpose
dhcpv6DumpMessage(outputMessage, outputMessageLen);
//Copy the peer-address into the destination IP address
ipAddr.length = sizeof(Ipv6Addr);
ipAddr.ipv6Addr = inputMessage->peerAddress;
//Select the relevant port number to use
if(outputMessage->msgType == DHCPV6_MSG_TYPE_RELAY_REPL)
port = DHCPV6_SERVER_PORT;
else
port = DHCPV6_CLIENT_PORT;
//Relay the DHCPv6 message to the client on the link
//identified by the Interface ID option
return socketSendTo(context->clientSocket[i], &ipAddr,
port, outputMessage, outputMessageLen, NULL, 0);
}
}
//Unknown interface identifier...
return ERROR_INVALID_OPTION;
}
示例15: main
int_t main(void)
{
error_t error;
NetInterface *interface;
OsTask *task;
MacAddr macAddr;
#if (APP_USE_DHCP == DISABLED)
Ipv4Addr ipv4Addr;
#endif
#if (APP_USE_SLAAC == DISABLED)
Ipv6Addr ipv6Addr;
#endif
//Update system core clock
SystemCoreClockUpdate();
//Initialize kernel
osInitKernel();
//Configure debug UART
debugInit(115200);
//Start-up message
TRACE_INFO("\r\n");
TRACE_INFO("**********************************\r\n");
TRACE_INFO("*** CycloneTCP FTP Client Demo ***\r\n");
TRACE_INFO("**********************************\r\n");
TRACE_INFO("Copyright: 2010-2014 Oryx Embedded\r\n");
TRACE_INFO("Compiled: %s %s\r\n", __DATE__, __TIME__);
TRACE_INFO("Target: LPC4330\r\n");
TRACE_INFO("\r\n");
//Configure I/Os
ioInit();
//TCP/IP stack initialization
error = tcpIpStackInit();
//Any error to report?
if(error)
{
//Debug message
TRACE_ERROR("Failed to initialize TCP/IP stack!\r\n");
}
//Configure the first Ethernet interface
interface = &netInterface[0];
//Set interface name
tcpIpStackSetInterfaceName(interface, "eth0");
//Set host name
tcpIpStackSetHostname(interface, "FTPClientDemo");
//Select the relevant network adapter
tcpIpStackSetDriver(interface, &lpc43xxEthDriver);
tcpIpStackSetPhyDriver(interface, &lan8720PhyDriver);
//Set host MAC address
macStringToAddr(APP_MAC_ADDR, &macAddr);
tcpIpStackSetMacAddr(interface, &macAddr);
//Initialize network interface
error = tcpIpStackConfigInterface(interface);
//Any error to report?
if(error)
{
//Debug message
TRACE_ERROR("Failed to configure interface %s!\r\n", interface->name);
}
#if (IPV4_SUPPORT == ENABLED)
#if (APP_USE_DHCP == ENABLED)
//Get default settings
dhcpClientGetDefaultSettings(&dhcpClientSettings);
//Set the network interface to be configured by DHCP
dhcpClientSettings.interface = interface;
//Disable rapid commit option
dhcpClientSettings.rapidCommit = FALSE;
//DHCP client initialization
error = dhcpClientInit(&dhcpClientContext, &dhcpClientSettings);
//Failed to initialize DHCP client?
if(error)
{
//Debug message
TRACE_ERROR("Failed to initialize DHCP client!\r\n");
}
//Start DHCP client
error = dhcpClientStart(&dhcpClientContext);
//Failed to start DHCP client?
if(error)
{
//Debug message
TRACE_ERROR("Failed to start DHCP client!\r\n");
}
#else
//Set IPv4 host address
ipv4StringToAddr(APP_IPV4_HOST_ADDR, &ipv4Addr);
ipv4SetHostAddr(interface, ipv4Addr);
//Set subnet mask
ipv4StringToAddr(APP_IPV4_SUBNET_MASK, &ipv4Addr);
ipv4SetSubnetMask(interface, ipv4Addr);
//.........这里部分代码省略.........