Rev 2234 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed
| Rev 2234 | Rev 2238 | ||
|---|---|---|---|
| Line 6... | Line 6... | ||
| 6 | Benchmark test usage of timer1 |
6 | Benchmark test usage of timer1 |
| 7 | 7 | ||
| 8 | CanSend |
8 | CanSend |
| 9 | Uses Timer1 as free running timer, only reads counter value |
9 | Uses Timer1 as free running timer, only reads counter value |
| 10 | 10 | ||
| - | 11 | CpuTime |
|
| - | 12 | Uses Timer1 as free running timer, only reads counter value |
|
| 11 | 13 | ||
| 12 | 14 | ||
| 13 | */ |
15 | */ |
| 14 | 16 | ||
| 15 | 17 | ||
| Line 17... | Line 19... | ||
| 17 | uint16_t tst_Benchmark_CanSend_Min = 0xffff; |
19 | uint16_t tst_Benchmark_CanSend_Min = 0xffff; |
| 18 | uint16_t tst_Benchmark_CanSend_Max = 0x0000; |
20 | uint16_t tst_Benchmark_CanSend_Max = 0x0000; |
| 19 | uint16_t tst_Benchmark_CanSend_Prev = 0xffff; |
21 | uint16_t tst_Benchmark_CanSend_Prev = 0xffff; |
| 20 | StdCan_Msg_t tst_Benchmark_CanSend_txMsg; |
22 | StdCan_Msg_t tst_Benchmark_CanSend_txMsg; |
| 21 | #endif |
23 | #endif |
| - | 24 | ||
| - | 25 | #if tst_Benchmark_CpuTime_TestActive == 1 |
|
| - | 26 | uint16_t tst_Benchmark_CpuTime_Min = 0xffff; |
|
| - | 27 | uint16_t tst_Benchmark_CpuTime_Max = 0x0000; |
|
| - | 28 | uint16_t tst_Benchmark_CpuTime_Avg = 0x0000; |
|
| - | 29 | uint16_t tst_Benchmark_CpuTime_Avg_Cnt = 0; |
|
| - | 30 | StdCan_Msg_t tst_Benchmark_CpuTime_txMsg; |
|
| - | 31 | uint16_t tst_Benchmark_CpuTime_timer_val; |
|
| - | 32 | #endif |
|
| - | 33 | ||
| 22 | 34 | ||
| 23 | void tst_Benchmark_Init(void) |
35 | void tst_Benchmark_Init(void) |
| 24 | { |
36 | { |
| 25 | /* Set up benchmark timer (timer1, 16bit) */ |
37 | /* Set up benchmark timer (timer1, 16bit) */ |
| 26 | //Normal port operation, Normal mode |
38 | //Normal port operation, Normal mode |
| 27 | TCCR1A = ((0<<COM1A1)|(0<<COM1A0)|(0<<COM1B1)|(0<<COM1B0)|(0<<WGM11)|(0<<WGM10)); |
39 | TCCR1A = ((0<<COM1A1)|(0<<COM1A0)|(0<<COM1B1)|(0<<COM1B0)|(0<<WGM11)|(0<<WGM10)); |
| 28 | TCCR1B = ((0<<ICNC1)|(0<<ICES1)|(0<<WGM12)|(0<<WGM13)); |
40 | TCCR1B = ((0<<ICNC1)|(0<<ICES1)|(0<<WGM12)|(0<<WGM13)); |
| 29 | 41 | ||
| 30 | /* Start timer */ |
42 | /* Start timer */ |
| 31 | //prescaler /8 |
43 | //prescaler /8 |
| 32 | TCCR1B |= ((0<<CS12)|(1<<CS11)|(0<<CS10)); |
44 | TCCR1B |= ((0<<CS12)|(1<<CS11)|(0<<CS10)); |
| 33 | 45 | ||
| 34 | #if tst_Benchmark_CanSend_TestActive == 1 |
46 | #if tst_Benchmark_CanSend_TestActive == 1 |
| Line 38... | Line 50... | ||
| 38 | tst_Benchmark_CanSend_txMsg.Header.ModuleId = tst_Benchmark_ID; |
50 | tst_Benchmark_CanSend_txMsg.Header.ModuleId = tst_Benchmark_ID; |
| 39 | tst_Benchmark_CanSend_txMsg.Header.Command = CAN_MODULE_CMD_DEBUG_BENCHMARK; |
51 | tst_Benchmark_CanSend_txMsg.Header.Command = CAN_MODULE_CMD_DEBUG_BENCHMARK; |
| 40 | tst_Benchmark_CanSend_txMsg.Length = 8; |
52 | tst_Benchmark_CanSend_txMsg.Length = 8; |
| 41 | 53 | ||
| 42 | Timer_SetTimeout(tst_Benchmark_CanSend_TIMER, tst_Benchmark_CanSend_PERIOD_MS , TimerTypeFreeRunning, 0); |
54 | Timer_SetTimeout(tst_Benchmark_CanSend_TIMER, tst_Benchmark_CanSend_PERIOD_MS , TimerTypeFreeRunning, 0); |
| 43 | #endif |
55 | #endif |
| - | 56 | ||
| - | 57 | #if tst_Benchmark_CpuTime_TestActive == 1 |
|
| - | 58 | StdCan_Set_class(tst_Benchmark_CpuTime_txMsg.Header, CAN_MODULE_CLASS_SNS); |
|
| - | 59 | StdCan_Set_direction(tst_Benchmark_CpuTime_txMsg.Header, DIRECTIONFLAG_FROM_OWNER); |
|
| - | 60 | tst_Benchmark_CpuTime_txMsg.Header.ModuleType = CAN_MODULE_TYPE_TST_DEBUG; |
|
| - | 61 | tst_Benchmark_CpuTime_txMsg.Header.ModuleId = tst_Benchmark_ID; |
|
| - | 62 | tst_Benchmark_CpuTime_txMsg.Header.Command = CAN_MODULE_CMD_DEBUG_BENCHMARK; |
|
| - | 63 | tst_Benchmark_CpuTime_txMsg.Length = 8; |
|
| - | 64 | ||
| - | 65 | Timer_SetTimeout(tst_Benchmark_CpuTime_SEND_TIMER, tst_Benchmark_CpuTime_SEND_PERIOD_MS , TimerTypeFreeRunning, 0); |
|
| - | 66 | #endif |
|
| 44 | } |
67 | } |
| 45 | 68 | ||
| 46 | void tst_Benchmark_Process(void) |
69 | void tst_Benchmark_Process(void) |
| 47 | { |
70 | { |
| 48 | #if tst_Benchmark_CanSend_TestActive == 1 |
71 | #if tst_Benchmark_CanSend_TestActive == 1 |
| 49 | if (Timer_Expired(tst_Benchmark_CanSend_TIMER)) |
72 | if (Timer_Expired(tst_Benchmark_CanSend_TIMER)) |
| 50 | { |
73 | { |
| 51 | uint16_t timer_val; |
74 | uint16_t timer_val; |
| 52 | uint16_t timer_val_new; |
75 | uint16_t timer_val_new; |
| 53 | 76 | ||
| 54 | for (uint8_t i=0; i < tst_Benchmark_CanSend_NumTx; i++) |
77 | for (uint8_t i=0; i < tst_Benchmark_CanSend_NumTx; i++) |
| 55 | { |
78 | { |
| 56 | tst_Benchmark_CanSend_txMsg.Data[0] = |
79 | tst_Benchmark_CanSend_txMsg.Data[0] = 0; // Implement avarage? Write test number? |
| 57 | tst_Benchmark_CanSend_txMsg.Data[1] = |
80 | tst_Benchmark_CanSend_txMsg.Data[1] = 0; |
| 58 | tst_Benchmark_CanSend_txMsg.Data[2] = |
81 | tst_Benchmark_CanSend_txMsg.Data[2] = (tst_Benchmark_CanSend_Prev>>8)&0xff; |
| 59 | tst_Benchmark_CanSend_txMsg.Data[3] = |
82 | tst_Benchmark_CanSend_txMsg.Data[3] = tst_Benchmark_CanSend_Prev&0xff; |
| 60 | tst_Benchmark_CanSend_txMsg.Data[4] = (tst_Benchmark_CanSend_Min>>8)&0xff; |
83 | tst_Benchmark_CanSend_txMsg.Data[4] = (tst_Benchmark_CanSend_Min>>8)&0xff; |
| 61 | tst_Benchmark_CanSend_txMsg.Data[5] = tst_Benchmark_CanSend_Min&0xff; |
84 | tst_Benchmark_CanSend_txMsg.Data[5] = tst_Benchmark_CanSend_Min&0xff; |
| 62 | tst_Benchmark_CanSend_txMsg.Data[6] = (tst_Benchmark_CanSend_Max>>8)&0xff; |
85 | tst_Benchmark_CanSend_txMsg.Data[6] = (tst_Benchmark_CanSend_Max>>8)&0xff; |
| 63 | tst_Benchmark_CanSend_txMsg.Data[7] = tst_Benchmark_CanSend_Max&0xff; |
86 | tst_Benchmark_CanSend_txMsg.Data[7] = tst_Benchmark_CanSend_Max&0xff; |
| 64 | 87 | ||
| Line 77... | Line 100... | ||
| 77 | tst_Benchmark_CanSend_Max = tst_Benchmark_CanSend_Prev; |
100 | tst_Benchmark_CanSend_Max = tst_Benchmark_CanSend_Prev; |
| 78 | } |
101 | } |
| 79 | } |
102 | } |
| 80 | 103 | ||
| 81 | } |
104 | } |
| - | 105 | #endif |
|
| - | 106 | ||
| - | 107 | #if tst_Benchmark_CpuTime_TestActive == 1 |
|
| - | 108 | uint16_t timer_val_new = TCNT1; |
|
| - | 109 | ||
| - | 110 | uint16_t timeSpent = timer_val_new - tst_Benchmark_CpuTime_timer_val; |
|
| - | 111 | if (tst_Benchmark_CpuTime_Min > timeSpent) |
|
| - | 112 | { |
|
| - | 113 | tst_Benchmark_CpuTime_Min = timeSpent; |
|
| - | 114 | } |
|
| - | 115 | if (tst_Benchmark_CpuTime_Max < timeSpent) |
|
| - | 116 | { |
|
| - | 117 | tst_Benchmark_CpuTime_Max = timeSpent; |
|
| - | 118 | } |
|
| - | 119 | ||
| - | 120 | uint32_t sum = tst_Benchmark_CpuTime_Avg * tst_Benchmark_CpuTime_Avg_Cnt + timeSpent; |
|
| - | 121 | if (tst_Benchmark_CpuTime_Avg_Cnt < 0xffff) |
|
| - | 122 | { |
|
| - | 123 | tst_Benchmark_CpuTime_Avg_Cnt++; |
|
| - | 124 | } |
|
| - | 125 | tst_Benchmark_CpuTime_Avg = sum / tst_Benchmark_CpuTime_Avg_Cnt; |
|
| - | 126 | ||
| - | 127 | if (Timer_Expired(tst_Benchmark_CpuTime_SEND_TIMER)) |
|
| - | 128 | { |
|
| - | 129 | tst_Benchmark_CpuTime_txMsg.Data[0] = 0; // Write test number? |
|
| - | 130 | tst_Benchmark_CpuTime_txMsg.Data[1] = 0; |
|
| - | 131 | tst_Benchmark_CpuTime_txMsg.Data[2] = (tst_Benchmark_CpuTime_Avg>>8)&0xff; |
|
| - | 132 | tst_Benchmark_CpuTime_txMsg.Data[3] = tst_Benchmark_CpuTime_Avg&0xff; |
|
| - | 133 | tst_Benchmark_CpuTime_txMsg.Data[4] = (tst_Benchmark_CpuTime_Min>>8)&0xff; |
|
| - | 134 | tst_Benchmark_CpuTime_txMsg.Data[5] = tst_Benchmark_CpuTime_Min&0xff; |
|
| - | 135 | tst_Benchmark_CpuTime_txMsg.Data[6] = (tst_Benchmark_CpuTime_Max>>8)&0xff; |
|
| - | 136 | tst_Benchmark_CpuTime_txMsg.Data[7] = tst_Benchmark_CpuTime_Max&0xff; |
|
| - | 137 | ||
| - | 138 | /* buffers will be filled when sending more than 2-3 messages, so retry until sent */ |
|
| - | 139 | while (StdCan_Put(&tst_Benchmark_CpuTime_txMsg) != StdCan_Ret_OK) {} |
|
| - | 140 | } |
|
| - | 141 | ||
| - | 142 | tst_Benchmark_CpuTime_timer_val = TCNT1; |
|
| 82 | #endif |
143 | #endif |
| 83 | } |
144 | } |
| 84 | 145 | ||
| 85 | void tst_Benchmark_HandleMessage(StdCan_Msg_t *rxMsg) |
146 | void tst_Benchmark_HandleMessage(StdCan_Msg_t *rxMsg) |
| 86 | { |
147 | { |