📄 14_sample_system.c
字号:
{
/* Perform data capture from the VAM system to temporary memory */
/* This function simulates the data capture operation by writing */
/* to an array, which represents a temporary memory file. For */
/* simplicity, we will write to the array once every timer-tick */
while (1) {
temp_memory[frame_index][0] = tx_time_get();
temp_memory[frame_index][1] = 0x1234;
frame_index = (frame_index + 1) % MAX_TEMP_MEMORY;
tx_thread_sleep(1);
}
}
/************************************************************/
/********** crash event detection and processing ************/
/************************************************************/
/* Timer function definition for simulated crash interrupt */
/* This is a simulated ISR -- an actual ISR would probably begin */
/* with a context save and would end with a context restore. */
void crash_ISR (ULONG timer_input)
{
ULONG frame_data[2];
frame_data[0] = frame_index;
frame_data[1] = 1;
num_crashes++;
/* Activates timer to expire in 12 seconds - end of event */
/* Put frame_index and priority on queue for crash events */
tx_queue_send (&event_notice, frame_data, TX_NO_WAIT);
tx_timer_activate (&crash_copy_scheduler);
}
/************************************************************/
/* Timer function definition for timer crash_copy_scheduler, */
/* which resumes thread that performs recording of crash data */
void crash_copy_activate (ULONG timer_input)
{
/* resume recorder thread to initiate data recording */
tx_thread_resume(&event_recorder);
tx_timer_deactivate (&crash_copy_scheduler);
}
/************************************************************/
/**** Entry function definition of thread event_recorder ****/
/************************************************************/
void event_recorder_process(ULONG thread_input)
{
ULONG frame, event_priority, event_time, index, frame_data[2];
while (1)
{
/* Copy an event from temporary memory to protected memory. */
/* Get frame_index from event message queue and copy 24 frames */
/* from temp_memory to protected_memory. */
tx_queue_receive (&event_notice, frame_data, TX_NO_WAIT);
/* Store event time and event priority in protected memory */
frame = frame_data[0];
event_priority = frame_data[1];
event_time = temp_memory[frame][0];
printf("**Event** Time: %5lu Count: %2lu Pri: %lu",
event_time, event_count, event_priority);
if (event_count < MAX_EVENTS)
{
tx_mutex_get (&memory_mutex, TX_WAIT_FOREVER);
protected_memory[event_count][0] = event_time;
protected_memory[event_count][1] = event_priority;
if (frame < 11)
frame = (MAX_TEMP_MEMORY-1) - (frame_index+1);
for (index=0; index<24; index++)
{
protected_memory[event_count][index+2] = temp_memory[frame][1];
frame = (frame+1) % MAX_TEMP_MEMORY;
}
tx_mutex_put (&memory_mutex);
event_count++;
}
else printf(" **not processed**");
printf ("\n");
tx_thread_suspend(&event_recorder);
}
}
/************************************************************/
/********** unsafe event detection and processing ***********/
/************************************************************/
/* Timer function definition for simulated unsafe interrupt */
/* This is a simulated ISR -- an actual ISR would probably begin */
/* with a context save and would end with a context restore. */
void unsafe_ISR (ULONG timer_input)
{
ULONG frame_data[2];
frame_data[0] = frame_index;
frame_data[1] = 2;
num_unsafe++;
/* Activates timer to expire in 12 seconds - end of event */
/* Put frame_index and priority on queue for unsafe events */
tx_queue_send (&event_notice, frame_data, TX_NO_WAIT);
tx_timer_activate (&unsafe_copy_scheduler);
}
/************************************************************/
/* Timer function definition for timer unsafe_copy_scheduler, */
/* which resumes thread that performs recording of unsafe data */
void unsafe_copy_activate (ULONG timer_input)
{
/* resume event_recorder thread to initiate data recording */
tx_thread_resume(&event_recorder);
tx_timer_deactivate (&unsafe_copy_scheduler);
}
/************************************************************/
/********* warning event detection and processing ***********/
/************************************************************/
/* Timer function definition for simulated warning interrupt */
/* This is a simulated ISR -- an actual ISR would probably begin */
/* with a context save and would end with a context restore. */
void warning_ISR (ULONG timer_input)
{
ULONG frame_data[2];
frame_data[0] = frame_index;
frame_data[1] = 3;
num_warning++;
/* Activates timer to expire in 12 seconds - end of event */
/* Put frame_index and priority on queue for warning events */
tx_queue_send (&event_notice, frame_data, TX_NO_WAIT);
tx_timer_activate (&warning_copy_scheduler);
}
/************************************************************/
/* Timer function definition for timer warning_copy_scheduler, */
/* which resumes thread that performs recording of warning data */
void warning_copy_activate (ULONG timer_input)
{
/* resume event_recorder thread to initiate data recording */
tx_thread_resume(&event_recorder);
tx_timer_deactivate (&warning_copy_scheduler);
}
/************************************************************/
/********** manual event detection and processing ***********/
/************************************************************/
/* Timer function definition for simulated manual interrupt */
/* This is a simulated ISR -- an actual ISR would probably begin */
/* with a context save and would end with a context restore. */
void manual_ISR (ULONG timer_input)
{
ULONG frame_data[2];
frame_data[0] = frame_index;
frame_data[1] = 4;
num_manual++;
/* Activates timer to expire in 12 seconds - end of event */
/* Put frame_index and priority on queue for manual events */
tx_queue_send (&event_notice, frame_data, TX_NO_WAIT);
tx_timer_activate (&manual_copy_scheduler);
}
/************************************************************/
/* Timer function definition for timer manual_copy_scheduler, */
/* which resumes thread that performs recording of manual data */
void manual_copy_activate (ULONG timer_input)
{
/* resume event_recorder thread to initiate data recording */
tx_thread_resume(&event_recorder);
tx_timer_deactivate (&manual_copy_scheduler);
}
/************************************************************/
/*********** print statistics at specified times ************/
/************************************************************/
void print_stats (ULONG invalue)
{
UINT row, col;
printf("\n\n**** VAM System Periodic Event Summary\n\n");
printf(" Current Time: %lu\n", tx_time_get());
printf(" Number of Crashes: %lu\n", num_crashes);
printf(" Number of Unsafe Events: %lu\n", num_unsafe);
printf(" Number of Warnings: %lu\n", num_warning);
printf(" Number of Manual Events: %lu\n", num_manual);
if (event_count > 0)
{
printf("\n\n**** Portion of Protected Memory Contents\n\n");
printf("%6s%6s%6s\n", "Time", "Pri", "Data");
for (row = 0; row < event_count; row++)
{
for (col = 0; col < 8; col++)
printf("%6lu", protected_memory[row][col]);
printf(" (etc.)\n");
}
}
if (event_count >= MAX_EVENTS)
printf(" Warning: Protected Memory is full...\n\n");
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -