// Restore a previously preserved exception to the frame. NUITKA_MAY_BE_UNUSED static inline void RESTORE_FRAME_EXCEPTION( PyFrameObject *frame_object ) { if ( frame_object->f_exc_type ) { #if _DEBUG_EXCEPTIONS PRINT_STRING("RESTORE_FRAME_EXCEPTION: restoring preserved\n"); PRINT_ITEM( (PyObject *)frame_object ); PRINT_NEW_LINE(); #endif SET_CURRENT_EXCEPTION( frame_object->f_exc_type, frame_object->f_exc_value, (PyTracebackObject *)frame_object->f_exc_traceback ); frame_object->f_exc_type = NULL; frame_object->f_exc_value = NULL; frame_object->f_exc_traceback = NULL; } #if _DEBUG_EXCEPTIONS else { PRINT_STRING("RESTORE_FRAME_EXCEPTION: nothing to restore\n"); PRINT_ITEM( (PyObject *)frame_object ); PRINT_NEW_LINE(); } #endif }
int pipeget(kpipe_t pipe, K_PIPE_OPTION option, int size, int count, unsigned int* time) { int i; unsigned int t; int sizexferd_total = 0; int size2xfer_total = size * count; /* sync with the sender */ task_sem_take_wait(SEM0); t = BENCH_START(); for (i = 0; _1_TO_N == option || (i < count); i++) { int sizexferd = 0; int size2xfer = min(size, size2xfer_total - sizexferd_total); int ret; ret = task_pipe_get_wait(pipe, data_recv, size2xfer, &sizexferd, option); if (RC_OK != ret) { return 1; } if (_ALL_N == option && sizexferd != size2xfer) { return 1; } sizexferd_total += sizexferd; if (size2xfer_total == sizexferd_total) { break; } if (size2xfer_total < sizexferd_total) { return 1; } } t = TIME_STAMP_DELTA_GET(t); *time = SYS_CLOCK_HW_CYCLES_TO_NS_AVG(t, count); if (bench_test_end() < 0) { if (high_timer_overflow()) { PRINT_STRING("| Timer overflow. Results are invalid ", output_file); } else { PRINT_STRING("| Tick occured. Results may be inaccurate ", output_file); } PRINT_STRING(" |\n", output_file); } return 0; }
/** * * @brief Memory pool get/free test * * @return N/A */ void mempool_test(void) { u32_t et; /* elapsed time */ int i; s32_t return_value = 0; struct k_mem_block block; PRINT_STRING(dashline, output_file); et = BENCH_START(); for (i = 0; i < NR_OF_POOL_RUNS; i++) { return_value |= k_mem_pool_alloc(&DEMOPOOL, &block, 16, K_FOREVER); k_mem_pool_free(&block); } et = TIME_STAMP_DELTA_GET(et); check_result(); if (return_value != 0) { k_panic(); } PRINT_F(output_file, FORMAT, "average alloc and dealloc memory pool block", SYS_CLOCK_HW_CYCLES_TO_NS_AVG(et, (2 * NR_OF_POOL_RUNS))); }
// Normalize an exception. NUITKA_MAY_BE_UNUSED static inline void NORMALIZE_EXCEPTION( PyObject **exception_type, PyObject **exception_value, PyTracebackObject **exception_tb ) { #if _DEBUG_EXCEPTIONS PRINT_STRING("NORMALIZE_EXCEPTION:\n"); PRINT_EXCEPTION( *exception_type, *exception_value, (PyObject *)*exception_tb ); #endif if ( *exception_type != Py_None && *exception_type != NULL ) { PyErr_NormalizeException( exception_type, exception_value, (PyObject **)exception_tb ); } #if _DEBUG_EXCEPTIONS PRINT_STRING("normalized:\n"); PRINT_EXCEPTION( *exception_type, *exception_value, (PyObject *)*exception_tb ); #endif }
// Preserve the current exception as the frame to restore. NUITKA_MAY_BE_UNUSED static inline void PRESERVE_FRAME_EXCEPTION( PyFrameObject *frame_object ) { // Setting exception for frame if not already done. if ( frame_object->f_exc_type == NULL ) { PyThreadState *thread_state = PyThreadState_GET(); if ( thread_state->exc_type != NULL && thread_state->exc_type != Py_None ) { #if _DEBUG_EXCEPTIONS PRINT_STRING("PRESERVE_FRAME_EXCEPTION: preserve thread exception\n"); #endif frame_object->f_exc_type = thread_state->exc_type; Py_INCREF( frame_object->f_exc_type ); frame_object->f_exc_value = thread_state->exc_value; Py_XINCREF( frame_object->f_exc_value ); frame_object->f_exc_traceback = thread_state->exc_traceback; Py_XINCREF( frame_object->f_exc_traceback ); } else { #if _DEBUG_EXCEPTIONS PRINT_STRING("PRESERVE_FRAME_EXCEPTION: no exception to preserve\n"); #endif frame_object->f_exc_type = Py_None; Py_INCREF( frame_object->f_exc_type ); frame_object->f_exc_value = NULL; frame_object->f_exc_traceback = NULL; } } #if _DEBUG_EXCEPTIONS else { PRINT_STRING("PRESERVE_FRAME_EXCEPTION: already preserving\n"); } PRINT_ITEM( (PyObject *)frame_object ); PRINT_NEW_LINE(); PRINT_EXCEPTION( frame_object->f_exc_type, frame_object->f_exc_value, frame_object->f_exc_traceback ); #endif }
// Publish an exception, erasing the values of the variables. NUITKA_MAY_BE_UNUSED static inline void PUBLISH_EXCEPTION( PyObject **exception_type, PyObject **exception_value, PyTracebackObject **exception_tb ) { #if _DEBUG_EXCEPTIONS PRINT_STRING("PUBLISH_EXCEPTION:\n"); #endif SET_CURRENT_EXCEPTION( *exception_type, *exception_value, *exception_tb ); *exception_type = NULL; *exception_value = NULL; *exception_tb = NULL; }
boolean_t compare_mem(void_t *source1, void_t *source2, uint64_t size) { uint8_t *s1 = (uint8_t *)source1; uint8_t *s2 = (uint8_t *)source2; while (size--) { if (*s1++ != *s2++) { PRINT_STRING("Compare mem failed\n"); return FALSE; } } return TRUE; }
/** * * @brief Mutex lock/unlock test * * @return N/A */ void mutex_test(void) { u32_t et; /* elapsed time */ int i; PRINT_STRING(dashline, output_file); et = BENCH_START(); for (i = 0; i < NR_OF_MUTEX_RUNS; i++) { k_mutex_lock(&DEMO_MUTEX, K_FOREVER); k_mutex_unlock(&DEMO_MUTEX); } et = TIME_STAMP_DELTA_GET(et); check_result(); PRINT_F(output_file, FORMAT, "average lock and unlock mutex", SYS_CLOCK_HW_CYCLES_TO_NS_AVG(et, (2 * NR_OF_MUTEX_RUNS))); }
// Fetch the current error into object variables. NUITKA_MAY_BE_UNUSED static void FETCH_ERROR_OCCURRED( PyObject **exception_type, PyObject **exception_value, PyTracebackObject **exception_traceback) { PyThreadState *tstate = PyThreadState_GET(); *exception_type = tstate->curexc_type; *exception_value = tstate->curexc_value; *exception_traceback = (PyTracebackObject *)tstate->curexc_traceback; #if _DEBUG_EXCEPTIONS PRINT_STRING("FETCH_ERROR_OCCURRED:\n"); PRINT_EXCEPTION( tstate->curexc_type, tstate->curexc_value, tstate->curexc_traceback ); #endif tstate->curexc_type = NULL; tstate->curexc_value = NULL; tstate->curexc_traceback = NULL; }
/* * allocate_memory(): Simple memory allocation routine */ void_t *allocate_memory(uint64_t size_request) { uint64_t address; if (heap_current + size_request > heap_tops) { PRINT_STRING("Allocation request exceeds heap's size\r\n"); PRINT_STRING_AND_VALUE("Heap current = 0x", heap_current); PRINT_STRING_AND_VALUE("Requested size = 0x", size_request); PRINT_STRING_AND_VALUE("Heap tops = 0x", heap_tops); return NULL; } address = ALIGN_FORWARD(heap_current, MEM_ALLOCATE_ALIGNMENT); heap_current += size_request; zero_mem((void_t *)address, size_request); return (void_t *)address; }
void *CDECL mon_page_alloc(uint64_t pages) { uint64_t address; uint64_t size = pages * PAGE_SIZE; address = ALIGN_FORWARD(heap_current, PAGE_SIZE); if (address + size > heap_tops) { PRINT_STRING("Allocation request exceeds heap's size\r\n"); PRINT_STRING_AND_VALUE("Page aligned heap current = 0x", address); PRINT_STRING_AND_VALUE("Requested size = 0x", size); PRINT_STRING_AND_VALUE("Heap tops = 0x", heap_tops); return NULL; } heap_current = address + size; zero_mem((void *)address, size); return (void *)address; }
NUITKA_MAY_BE_UNUSED static void RESTORE_ERROR_OCCURRED( PyObject *exception_type, PyObject *exception_value, PyTracebackObject *exception_traceback ) { PyThreadState *tstate = PyThreadState_GET(); PyObject *old_exception_type = tstate->curexc_type; PyObject *old_exception_value = tstate->curexc_value; PyObject *old_exception_traceback = tstate->curexc_traceback; tstate->curexc_type = exception_type; tstate->curexc_value = exception_value; tstate->curexc_traceback = (PyObject *)exception_traceback; #if _DEBUG_EXCEPTIONS PRINT_STRING("RESTORE_ERROR_OCCURRED:\n"); PRINT_EXCEPTION( tstate->curexc_type, tstate->curexc_value, tstate->curexc_traceback ); #endif Py_XDECREF( old_exception_type ); Py_XDECREF( old_exception_value ); Py_XDECREF( old_exception_traceback ); }
/** * * @brief Mailbox transfer speed test * * @return N/A */ void mailbox_test(void) { u32_t putsize; u32_t puttime; int putcount; unsigned int EmptyMsgPutTime; GetInfo getinfo; PRINT_STRING(dashline, output_file); PRINT_STRING("| " "M A I L B O X M E A S U R E M E N T S" " |\n", output_file); PRINT_STRING(dashline, output_file); PRINT_STRING("| Send mailbox message to waiting high " "priority task and wait |\n", output_file); PRINT_F(output_file, "| repeat for %4d times and take the " "average |\n", NR_OF_MBOX_RUNS); PRINT_STRING(dashline, output_file); PRINT_HEADER(); PRINT_STRING(dashline, output_file); k_sem_reset(&SEM0); k_sem_give(&STARTRCV); putcount = NR_OF_MBOX_RUNS; putsize = 0; mailbox_put(putsize, putcount, &puttime); /* waiting for ack */ k_msgq_get(&MB_COMM, &getinfo, K_FOREVER); PRINT_ONE_RESULT(); EmptyMsgPutTime = puttime; for (putsize = 8; putsize <= MESSAGE_SIZE; putsize <<= 1) { mailbox_put(putsize, putcount, &puttime); /* waiting for ack */ k_msgq_get(&MB_COMM, &getinfo, K_FOREVER); PRINT_ONE_RESULT(); } PRINT_STRING(dashline, output_file); PRINT_OVERHEAD(); PRINT_XFER_RATE(); }
// Helper that sets the current thread exception, releasing the current one, for // use in this file only. NUITKA_MAY_BE_UNUSED inline void SET_CURRENT_EXCEPTION( PyObject *exception_type, PyObject *exception_value, PyTracebackObject *exception_tb ) { PyThreadState *thread_state = PyThreadState_GET(); PyObject *old_type = thread_state->exc_type; PyObject *old_value = thread_state->exc_value; PyObject *old_tb = thread_state->exc_traceback; thread_state->exc_type = exception_type; thread_state->exc_value = exception_value; thread_state->exc_traceback = (PyObject *)exception_tb; #if _DEBUG_EXCEPTIONS PRINT_STRING("SET_CURRENT_EXCEPTION:\n"); PRINT_EXCEPTION( exception_type, exception_value, (PyObject *)exception_tb ); #endif Py_XDECREF( old_type ); Py_XDECREF( old_value ); Py_XDECREF( old_tb ); #if PYTHON_VERSION < 300 // Set sys attributes in the fastest possible way. PyObject *sys_dict = thread_state->interp->sysdict; CHECK_OBJECT( sys_dict ); PyDict_SetItem( sys_dict, const_str_plain_exc_type, exception_type ? exception_type : Py_None ); PyDict_SetItem( sys_dict, const_str_plain_exc_value, exception_value ? exception_value : Py_None ); PyDict_SetItem( sys_dict, const_str_plain_exc_traceback, exception_tb ? (PyObject *)exception_tb : Py_None ); if ( exception_type ) assert( Py_REFCNT( exception_type ) >= 2 ); if ( exception_value ) assert( Py_REFCNT( exception_value ) >= 2 ); if ( exception_tb ) assert( Py_REFCNT( exception_tb ) >= 2 ); #endif }
/** * * @brief Perform all selected benchmarks * see config.h to select or to unselect * * @return N/A */ void BenchTask(void) { int autorun = 0, continuously = 0; init_output(&continuously, &autorun); bench_test_init(); PRINT_STRING(newline, output_file); do { PRINT_STRING(dashline, output_file); PRINT_STRING("| S I M P L E S E R V I C E " "M E A S U R E M E N T S | nsec |\n", output_file); PRINT_STRING(dashline, output_file); task_start(RECVTASK); call_test(); queue_test(); sema_test(); mutex_test(); memorymap_test(); mempool_test(); event_test(); mailbox_test(); pipe_test(); PRINT_STRING("| END OF TESTS " " |\n", output_file); PRINT_STRING(dashline, output_file); PRINT_STRING("PROJECT EXECUTION SUCCESSFUL\n",output_file); } while (continuously && !kbhit()); WAIT_FOR_USER(); if (autorun) { task_sleep(SECONDS(2)); } output_close(); }
void pipe_test(void) { uint32_t putsize; int getsize; uint32_t puttime[3]; int putcount; int pipe; kpriority_t TaskPrio; int prio; GetInfo getinfo; task_sem_reset(SEM0); task_sem_give(STARTRCV); /* action: */ /* non-buffered operation, matching (ALL_N) */ PRINT_STRING(dashline, output_file); PRINT_STRING("| " "P I P E M E A S U R E M E N T S" " |\n", output_file); PRINT_STRING(dashline, output_file); PRINT_STRING("| Send data into a pipe towards a " "receiving high priority task and wait |\n", output_file); PRINT_STRING(dashline, output_file); PRINT_STRING("| " "matching sizes (_ALL_N)" " |\n", output_file); PRINT_STRING(dashline, output_file); PRINT_ALL_TO_N_HEADER_UNIT(); PRINT_STRING(dashline, output_file); PRINT_STRING("| put | get | no buf | small buf| big buf |" " no buf | small buf| big buf |\n", output_file); PRINT_STRING(dashline, output_file); for (putsize = 8; putsize <= MESSAGE_SIZE_PIPE; putsize <<= 1) { for (pipe = 0; pipe < 3; pipe++) { putcount = NR_OF_PIPE_RUNS; pipeput(TestPipes[pipe], _ALL_N, putsize, putcount, &puttime[pipe]); task_fifo_get_wait(CH_COMM, &getinfo); /* waiting for ack */ } PRINT_ALL_TO_N(); } PRINT_STRING(dashline, output_file); /* Test with two different sender priorities */ for (prio = 0; prio < 2; prio++) { /* non-buffered operation, non-matching (1_TO_N) */ if (prio == 0) { PRINT_STRING("| " "non-matching sizes (1_TO_N) to higher priority" " |\n", output_file); TaskPrio = task_priority_get(); } if (prio == 1) { PRINT_STRING("| " "non-matching sizes (1_TO_N) to lower priority" " |\n", output_file); task_priority_set(task_id_get(), TaskPrio - 2); } PRINT_STRING(dashline, output_file); PRINT_1_TO_N_HEADER(); PRINT_STRING("| put | get | no buf | small buf| big buf | " "no buf | small buf| big buf |\n", output_file); PRINT_STRING(dashline, output_file); for (putsize = 8; putsize <= (MESSAGE_SIZE_PIPE); putsize <<= 1) { putcount = MESSAGE_SIZE_PIPE / putsize; for (pipe = 0; pipe < 3; pipe++) { pipeput(TestPipes[pipe], _1_TO_N, putsize, putcount, &puttime[pipe]); /* size*count == MESSAGE_SIZE_PIPE */ task_fifo_get_wait(CH_COMM, &getinfo); /* waiting for ack */ getsize = getinfo.size; } PRINT_1_TO_N(); } PRINT_STRING(dashline, output_file); task_priority_set(task_id_get(), TaskPrio); } }
/** * * @brief Semaphore signal speed test * * @return N/A */ void sema_test(void) { uint32_t et; /* elapsed Time */ int i; PRINT_STRING(dashline, output_file); et = BENCH_START(); for (i = 0; i < NR_OF_SEMA_RUNS; i++) { task_sem_give(SEM0); } et = TIME_STAMP_DELTA_GET(et); check_result(); PRINT_F(output_file, FORMAT, "signal semaphore", SYS_CLOCK_HW_CYCLES_TO_NS_AVG(et, NR_OF_SEMA_RUNS)); task_sem_reset(SEM1); task_sem_give(STARTRCV); et = BENCH_START(); for (i = 0; i < NR_OF_SEMA_RUNS; i++) { task_sem_give(SEM1); } et = TIME_STAMP_DELTA_GET(et); check_result(); PRINT_F(output_file, FORMAT, "signal to waiting high pri task", SYS_CLOCK_HW_CYCLES_TO_NS_AVG(et, NR_OF_SEMA_RUNS)); et = BENCH_START(); for (i = 0; i < NR_OF_SEMA_RUNS; i++) { task_sem_give(SEM1); } et = TIME_STAMP_DELTA_GET(et); check_result(); PRINT_F(output_file, FORMAT, "signal to waiting high pri task, with timeout", SYS_CLOCK_HW_CYCLES_TO_NS_AVG(et, NR_OF_SEMA_RUNS)); et = BENCH_START(); for (i = 0; i < NR_OF_SEMA_RUNS; i++) { task_sem_give(SEM2); } et = TIME_STAMP_DELTA_GET(et); check_result(); PRINT_F(output_file, FORMAT, "signal to waitm (2)", SYS_CLOCK_HW_CYCLES_TO_NS_AVG(et, NR_OF_SEMA_RUNS)); et = BENCH_START(); for (i = 0; i < NR_OF_SEMA_RUNS; i++) { task_sem_give(SEM2); } et = TIME_STAMP_DELTA_GET(et); check_result(); PRINT_F(output_file, FORMAT, "signal to waitm (2), with timeout", SYS_CLOCK_HW_CYCLES_TO_NS_AVG(et, NR_OF_SEMA_RUNS)); et = BENCH_START(); for (i = 0; i < NR_OF_SEMA_RUNS; i++) { task_sem_give(SEM3); } et = TIME_STAMP_DELTA_GET(et); check_result(); PRINT_F(output_file, FORMAT, "signal to waitm (3)", SYS_CLOCK_HW_CYCLES_TO_NS_AVG(et, NR_OF_SEMA_RUNS)); et = BENCH_START(); for (i = 0; i < NR_OF_SEMA_RUNS; i++) { task_sem_give(SEM3); } et = TIME_STAMP_DELTA_GET(et); check_result(); PRINT_F(output_file, FORMAT, "signal to waitm (3), with timeout", SYS_CLOCK_HW_CYCLES_TO_NS_AVG(et, NR_OF_SEMA_RUNS)); et = BENCH_START(); for (i = 0; i < NR_OF_SEMA_RUNS; i++) { task_sem_give(SEM4); } et = TIME_STAMP_DELTA_GET(et); check_result(); PRINT_F(output_file, FORMAT, "signal to waitm (4)", SYS_CLOCK_HW_CYCLES_TO_NS_AVG(et, NR_OF_SEMA_RUNS)); et = BENCH_START(); for (i = 0; i < NR_OF_SEMA_RUNS; i++) { task_sem_give(SEM4); } et = TIME_STAMP_DELTA_GET(et); check_result(); PRINT_F(output_file, FORMAT, "signal to waitm (4), with timeout", SYS_CLOCK_HW_CYCLES_TO_NS_AVG(et, NR_OF_SEMA_RUNS)); }
void f() { PRINT_STRING("f()"); }
/* fmPlatformCfgDump * \ingroup intPlatform * * \desc Dump platform configuration. * * \return NONE. * *****************************************************************************/ void fmPlatformCfgDump(void) { fm_platformCfg * platCfg; fm_platformCfgLib * libCfg; fm_platformCfgPort * portCfg; fm_platformCfgLane * laneCfg; fm_platformCfgSwitch *swCfg; fm_platformCfgPhy * phyCfg; fm_gn2412LaneCfg * phyLaneCfg; fm_int swIdx; fm_int portIdx; fm_int epl; fm_int lane; fm_int phyIdx; fm_char tmpStr[MAX_BUF_SIZE+1]; platCfg = FM_PLAT_GET_CFG; PRINT_VALUE("debug", platCfg->debug); PRINT_VALUE("numSwitches", FM_PLAT_NUM_SW); PRINT_STRING("platformName", platCfg->name); PRINT_STRING("fileLockName", platCfg->fileLockName); #ifdef FM_SUPPORT_SWAG PRINT_STRING("topology", GetStrMap( platCfg->topology, swagTopology, FM_NENTRIES(swagTopology), FALSE, tmpStr, sizeof(tmpStr) ) ); #endif for (swIdx = 0 ; swIdx < FM_PLAT_NUM_SW ; swIdx++) { /* Logical switch is the same as swIdx */ FM_LOG_PRINT("################################ SW#%d ################################\n", swIdx); swCfg = FM_PLAT_GET_SWITCH_CFG(swIdx); PRINT_VALUE(" swIdx", swCfg->swIdx); PRINT_VALUE(" switchNumber", swCfg->swNum); PRINT_VALUE(" numPorts", swCfg->numPorts); PRINT_VALUE(" maxLogicalPortValue", swCfg->maxLogicalPortValue); PRINT_VALUE(" ledPollPeriodMsec", swCfg->ledPollPeriodMsec); PRINT_STRING(" ledBlinkMode", GetStrMap( swCfg->ledBlinkMode, ledBlinkModeMap, FM_NENTRIES(ledBlinkModeMap), FALSE, tmpStr, sizeof(tmpStr) ) ); PRINT_VALUE(" xcvrPollPeriodMsec", swCfg->xcvrPollPeriodMsec); PRINT_VALUE(" intrPollPeriodMsec", swCfg->intrPollPeriodMsec); PRINT_STRING(" uioDevName", swCfg->uioDevName); PRINT_STRING(" netDevName", swCfg->netDevName); PRINT_STRING(" devMemOffset", swCfg->devMemOffset); PRINT_VALUE(" gpioPortIntr", swCfg->gpioPortIntr); PRINT_VALUE(" gpioI2cReset", swCfg->gpioI2cReset); PRINT_VALUE(" gpioFlashWP", swCfg->gpioFlashWP); PRINT_VALUE(" enablePhyDeEmphasis", swCfg->enablePhyDeEmphasis); PRINT_VALUE(" vrm.useDefVoltages", swCfg->vrm.useDefVoltages); PRINT_VALUE(" VDDS.hwResourceId", swCfg->vrm.hwResourceId[FM_PLAT_VRM_VDDS]); PRINT_VALUE(" VDDF.hwResourceId", swCfg->vrm.hwResourceId[FM_PLAT_VRM_VDDF]); PRINT_VALUE(" AVDD.hwResourceId", swCfg->vrm.hwResourceId[FM_PLAT_VRM_AVDD]); PRINT_VALUE(" fhClock", swCfg->fhClock); #ifdef FM_SUPPORT_SWAG PRINT_STRING(" switchRole", GetStrMap( swCfg->switchRole, swagRole, FM_NENTRIES(swagRole), FALSE, tmpStr, sizeof(tmpStr) ) ); #endif for (portIdx = 0 ; portIdx < FM_PLAT_NUM_PORT(swIdx) ; portIdx++) { portCfg = FM_PLAT_GET_PORT_CFG(swIdx, portIdx); FM_LOG_PRINT("==============Port Index %d============\n", portIdx); PRINT_VALUE(" logicalPort", portCfg->port); PRINT_VALUE(" hwResourceId", portCfg->hwResourceId); PRINT_VALUE(" physPort", portCfg->physPort); PRINT_VALUE(" epl", portCfg->epl); PRINT_VALUE(" lane[0]", portCfg->lane[0]); PRINT_VALUE(" lane[1]", portCfg->lane[1]); PRINT_VALUE(" lane[2]", portCfg->lane[2]); PRINT_VALUE(" lane[3]", portCfg->lane[3]); PRINT_VALUE(" pep", portCfg->pep); PRINT_VALUE(" tunnel", portCfg->tunnel); PRINT_VALUE(" loopback", portCfg->loopback); PRINT_VALUE(" speed", portCfg->speed); PRINT_VALUE(" autodetect", portCfg->autodetect); PRINT_STRING( " ethMode", GetStrMap( portCfg->ethMode, ethModeMap, FM_NENTRIES(ethModeMap), TRUE, tmpStr, sizeof(tmpStr) ) ); PRINT_STRING( " portType", GetStrMap( portCfg->portType, portTypeMap, FM_NENTRIES(portTypeMap), FALSE, tmpStr, sizeof(tmpStr) ) ); PRINT_STRING( " intfType", GetStrMap( portCfg->intfType, intfTypeMap, FM_NENTRIES(intfTypeMap), FALSE, tmpStr, sizeof(tmpStr) ) ); PRINT_STRING( " capability", GetStrBitMap( portCfg->cap, portCapMap, FM_NENTRIES(portCapMap), tmpStr, sizeof(tmpStr) ) ); PRINT_STRING(" dfeMode", GetStrMap(portCfg->dfeMode, dfeModeMap, FM_NENTRIES(dfeModeMap), FALSE, tmpStr, sizeof(tmpStr) ) ); PRINT_STRING( " an73Ability", GetStrBitMap( portCfg->an73Ability, an73AbilityMap, FM_NENTRIES(an73AbilityMap), tmpStr, sizeof(tmpStr) ) ); PRINT_VALUE(" phyNum", portCfg->phyNum); PRINT_VALUE(" phyPort", portCfg->phyPort); #ifdef FM_SUPPORT_SWAG PRINT_STRING(" swagLinkType", GetStrMap( portCfg->swagLink.type, swagLinkType, FM_NENTRIES(swagLinkType), FALSE, tmpStr, sizeof(tmpStr) ) ); if (portCfg->swagLink.type == FM_SWAG_LINK_INTERNAL) { FM_LOG_PRINT(" SWAG port %d <--> SWAG port %d\n", portCfg->swagLink.logicalPort, portCfg->swagLink.partnerLogicalPort); FM_LOG_PRINT(" SW %d, port %d <--> SW %d, port %d\n", portCfg->swagLink.swId, portCfg->swagLink.swPort, portCfg->swagLink.partnerSwitch, portCfg->swagLink.partnerPort); } else if (portCfg->swagLink.type == FM_SWAG_LINK_EXTERNAL) { FM_LOG_PRINT(" SWAG port %d, SW %d, port %d\n", portCfg->swagLink.logicalPort, portCfg->swagLink.swId, portCfg->swagLink.swPort); } #endif FM_LOG_PRINT("\n"); } for (epl = 0 ; epl < FM_PLAT_NUM_EPL ; epl++) { FM_LOG_PRINT("#######################################\n"); FM_LOG_PRINT("# EPL %d #\n", epl); FM_LOG_PRINT("#######################################\n"); PRINT_VALUE(" laneToPortIdx[0]", swCfg->epls[epl].laneToPortIdx[0]); PRINT_VALUE(" laneToPortIdx[1]", swCfg->epls[epl].laneToPortIdx[1]); PRINT_VALUE(" laneToPortIdx[2]", swCfg->epls[epl].laneToPortIdx[2]); PRINT_VALUE(" laneToPortIdx[3]", swCfg->epls[epl].laneToPortIdx[3]); for (lane = 0 ; lane < FM_PLAT_LANES_PER_EPL ; lane++) { FM_LOG_PRINT("============ EPL %d, lane %d ============\n", epl, lane); laneCfg = &swCfg->epls[epl].lane[lane]; PRINT_STRING(" lanePolarity", GetStrMap(laneCfg->lanePolarity, lanePolarityMap, FM_NENTRIES(lanePolarityMap), FALSE, tmpStr, sizeof(tmpStr))); PRINT_STRING(" rxTermination", GetStrMap(laneCfg->rxTermination, rxTerminationMap, FM_NENTRIES(rxTerminationMap), FALSE, tmpStr, sizeof(tmpStr))); PRINT_VALUE(" preCursor1GCopper", laneCfg->copper[BPS_1G].preCursor); PRINT_VALUE(" preCursor10GCopper", laneCfg->copper[BPS_10G].preCursor); PRINT_VALUE(" preCursor25GCopper", laneCfg->copper[BPS_25G].preCursor); PRINT_VALUE(" preCursor1GOptical", laneCfg->optical[BPS_1G].preCursor); PRINT_VALUE(" preCursor10GOptical", laneCfg->optical[BPS_10G].preCursor); PRINT_VALUE(" preCursor25GOptical", laneCfg->optical[BPS_25G].preCursor); PRINT_VALUE(" cursor1GCopper", laneCfg->copper[BPS_1G].cursor); PRINT_VALUE(" cursor10GCopper", laneCfg->copper[BPS_10G].cursor); PRINT_VALUE(" cursor25GCopper", laneCfg->copper[BPS_25G].cursor); PRINT_VALUE(" cursor1GOptical", laneCfg->optical[BPS_1G].cursor); PRINT_VALUE(" cursor10GOptical", laneCfg->optical[BPS_10G].cursor); PRINT_VALUE(" cursor25GOptical", laneCfg->optical[BPS_25G].cursor); PRINT_VALUE(" postCursor1GCopper", laneCfg->copper[BPS_1G].postCursor); PRINT_VALUE(" postCursor10GCopper", laneCfg->copper[BPS_10G].postCursor); PRINT_VALUE(" postCursor25GCopper", laneCfg->copper[BPS_25G].postCursor); PRINT_VALUE(" postCursor1GOptical", laneCfg->optical[BPS_1G].postCursor); PRINT_VALUE(" postCursor10GOptical", laneCfg->optical[BPS_10G].postCursor); PRINT_VALUE(" postCursor25GOptical", laneCfg->optical[BPS_25G].postCursor); FM_LOG_PRINT("\n"); } FM_LOG_PRINT("\n"); } for ( phyIdx = 0 ; phyIdx < FM_PLAT_NUM_PHY(swIdx) ; phyIdx++ ) { phyCfg = FM_PLAT_GET_PHY_CFG(swIdx, phyIdx); FM_LOG_PRINT("==============PHY Index %d============\n", phyIdx); PRINT_STRING(" model", GetStrMap( phyCfg->model, phyModelMap, FM_NENTRIES(phyModelMap), FALSE, tmpStr, sizeof(tmpStr) ) ); PRINT_VALUE(" addr", phyCfg->addr); PRINT_VALUE(" hwResourceId", phyCfg->hwResourceId); if ( phyCfg->model == FM_PLAT_PHY_GN2412 ) { for ( lane = 0 ; lane < FM_GN2412_NUM_LANES ; lane++ ) { phyLaneCfg = &phyCfg->gn2412Lane[lane]; FM_LOG_PRINT(" ======== GN2412 %d, lane %d ========\n", phyIdx, lane); PRINT_VALUE(" appMode", phyLaneCfg->appMode); PRINT_VALUE(" polarity", phyLaneCfg->polarity); PRINT_VALUE(" preTap", phyLaneCfg->preTap); PRINT_VALUE(" attenuation", phyLaneCfg->attenuation); PRINT_VALUE(" postTap", phyLaneCfg->postTap); } } FM_LOG_PRINT("\n"); } FM_LOG_PRINT(" Shared Library Config:\n"); libCfg = FM_PLAT_GET_LIBS_CFG(swIdx); PRINT_STRING(" sharedLibraryName", libCfg->libName); PRINT_STRING(" disableFuncIntf", GetStrBitMap( libCfg->disableFuncIntf, disableFuncIntfMap, FM_NENTRIES(disableFuncIntfMap), tmpStr, sizeof(tmpStr) ) ); PRINT_VALUE(" tlvCfgBufSize", libCfg->tlvCfgBufSize); PRINT_VALUE(" tlvCfgLen", libCfg->tlvCfgLen); FM_LOG_PRINT("#######################################################################\n\n"); } return; } /* end fmPlatformCfgDump */
int main() { PRINT_STRING("Calling macros to print a string"); return 0; }
void Log::a(const std::string& message) { if (Level::ASSERT < s_level) { return; } PRINT_STRING(message.c_str()); }
void Log::e(const std::string& message) { if (Level::ERROR < s_level) { return; } PRINT_STRING(message.c_str()); }
void Log::w(const std::string& message) { if (Level::WARNING < s_level) { return; } PRINT_STRING(message.c_str()); }
void Log::v(const std::string& message) { if (Level::VERBOSE < s_level) { return; } PRINT_STRING(message.c_str()); }
void Log::write(Level level, const std::string& message) { if (level < s_level) { return; } PRINT_STRING(message.c_str()); }
int stm32w_info() { int i; uint8_t buff[MAX_XFER_SIZE]; uint32_t x; uint8_t y; uint16_t z; serial_set_baudrate(50); printf("\nSTM32F USB-to-UART interface:\n"); if(stm32f_cmd_1_4(CMD_GET_BL_VERSION, &x)) { printf("Communication error\n"); exit(1); } printf(" %-32s %u.%u.%u.%u\n", "Bootloader Version:", (x>>24) & 0xff, (x>>16) & 0xff, (x>>8) & 0xff, x & 0xff); if(stm32f_cmd_1_4(CMD_GET_APP_VERSION, &x)) { printf("Communication error\n"); exit(1); } printf(" %-32s %u.%u.%u.%u\n","Firmware Version:", (x>>24) & 0xff, (x>>16) & 0xff, (x>>8) & 0xff, x & 0xff); stm32w_reset(); serial_set_baudrate(115200); printf("\nSTM32W108 Device information:\n"); stm32w_bl_ping(); stm32w_bl_get(&y); printf(" %-32s %u\n","BootLoader Version:",y); stm32w_bl_getid(&z); printf(" %-32s 0x%04x\n","Device Type:",z); #define PRINT_EUI64_ADDR(a, s) \ stm32w_bl_read_mem(a, buff, 8); \ printf(" %-32s ", s); \ for(i=7;i>0;i--) \ printf("%02x:", buff[i]); \ printf("%02x\n", buff[0]); #define PRINT_STRING(a, l, s) \ stm32w_bl_read_mem(a, buff, l); \ printf(" %-32s ", s); \ for(i=0;i<l;i++) \ printf("%c", ((buff[i]<0x20) || (buff[i]>0x7f)) ? '.' : buff[i]); \ printf("\n"); PRINT_EUI64_ADDR(0x080407A2, "Burned-in EUI-64 address:"); PRINT_EUI64_ADDR(0x080408A2, "CIB EUI-64 address:"); PRINT_STRING(0x0804081A, 16, "CIB Manufacturer String:"); PRINT_STRING(0x0804082A, 16, "CIB Manufacturer Board Name:"); /* Read Option Bytes from CIB */ stm32w_bl_read_mem(0x08040800, buff, 16); printf(" %-32s 0x%02x (%s)\n","CIB Read Protection:", buff[0], (buff[0] == 0xa5) ? "inactive" : "active" ); x = buff[8] | buff[10]<<8 | buff[12]<<16 | buff[14]<<24; printf(" %-32s ","CIB Write Protection (pg 0-63):"); for(i=0; i<32; i++) { if (x & 1<<i) printf("n"); else printf("y"); if (!((i+1)%8)) printf(" "); } printf("\n"); /* Read PHY Config from CIB */ stm32w_bl_read_mem(0x0804083C, buff, 2); printf(" %-32s %02x %02x\n","CIB PHY Config:", buff[0], buff[1]); printf("\n"); return 0; }
/* * Print out the device into console */ void printDevice(device *d) { if(!d) { return; } PRINT_UINT(d->id),SP, PRINT_STRING(d->name),SP, PRINT_UINT(d->size), EL; }