Описание библиотеки микросхемы 5023ВС016 процессора "Спутник"
tcrx_test.c
См. документацию.
1 
31 #include "tcrx_test.h"
32 
33 
34 #define TEST_TCRX
35 #define CCSDS_TERMINAL
36 
37 #ifdef TEST_TCRX
38 
39 #define RANDOMIZER_SEL_TCRX 0x01
40 #define BCH_SEL 0x02
41 #define CONVOLUTION_SEL 0x04
42 #define DSCR_COUNT 16
43 #define DSCR_SIZE 1024 //size of each descriptor in bytes
44 #define USED_COUNT DSCR_COUNT //count of descriptors, used in test
45 const uint32_t sys_freq = 80000000; // Системная частота
46 char dbg_buffer[256]; // Отладочный буфер
47 
48 //#define DEBUG_TCRX
49 
50 unsigned int rx_buffer [(DSCR_SIZE/4)*USED_COUNT];
51 unsigned int TCRX_cur_dscr; //index of dscr, which expected to be filled by the decoder currently
52 unsigned int nextExpectedSize; //size of next packet to be received. Should be 7*N, but not more than 1024
53 
54 //variables for debug
55 volatile unsigned int TCRX_irq_counter;
56 unsigned int Break_test;
57 volatile TCRX_T* tcrx = (TCRX_T*)TCRX;
58 
59 unsigned int TCRX_receive_complete;
60 unsigned int TCRX_stage;
61 
62 
63 unsigned int TCRX_errors;
64 #ifdef CCSDS_TERMINAL
65 # define TEST_TIMEOUT_INIT 10000000
66 
67 unsigned int test_timeout;
68 #endif
69 
70 void InitDscr(unsigned char index)
71 {
72  TCRX->DSCR_TBL[index].DSCR_PTR = (unsigned int) &rx_buffer[index*DSCR_SIZE/4];
73  //if size of descriptor is 1024, we should write 0 to flags_size register (just 10 bits present):
74  TCRX->DSCR_TBL[index].DSCR_FLAG_SIZE = (1<<31) | ((DSCR_SIZE<1024)?DSCR_SIZE:0);
75 }
76 
77 void InitCoder(unsigned int coder_sel)
78 {
79  TCRX->GLOBAL_ENABLE=0x00;
80  TCRX->CODER_SEL = coder_sel;
81 
82  TCRX->DSCR_CURRENT = 0;
83  TCRX_cur_dscr = 0;
84  nextExpectedSize = 7;
85  TCRX->GLOBAL_ENABLE=0x01;
86 }
87 
88 
89 
90 #ifdef DEBUG_TCRX
91 
92 
93 #else
94 
95 void TCRX_IRQ(void)
96 {
97 #ifdef CCSDS_TERMINAL
99 #endif
100 
101  //check if decoder deactivated 'present' flag
102  if (TCRX->DSCR_TBL[TCRX_cur_dscr].DSCR_FLAG_SIZE >> 31)
103  {
104  PRINT("\tERROR:'Present' flag in decoder was deactivated\n");
105  Break_test = 1;
106  TCRX_errors++;
107  DBG_TX_Flush();
108 
109  return;
110  }
111 
112  //read all data from descriptor
113  unsigned int word;
114  unsigned int frame_size = TCRX->DSCR_TBL[TCRX_cur_dscr].DSCR_FLAG_SIZE & 0x3FF;
115  if (frame_size == 0)
116  frame_size = 1024;
117 
118  //check frame size
119 
120  if (frame_size != nextExpectedSize)
121  {
122  PRINT("\tERROR: TCRX frame size is not correct = %d\n", frame_size);
123  PRINT("\tIrq_counter = %d\n", TCRX_irq_counter);
124  DBG_TX_Flush();
125  Break_test = 1;
126  TCRX_errors++;
128  // ErrorStop(0xE1);
129  }
130  else
131  {
132  //PRINT("\tTCRX frame size = %d\n", frame_size);
133  }
134 
135  //TCRX->GLOBAL_ENABLE=0x00;
136  //for(int i=0; i<10000; i++);
137  //TCRX->GLOBAL_ENABLE=0x01;
138 
139  nextExpectedSize += 7;
140  if (nextExpectedSize > 1024)
141  nextExpectedSize = 7;
142 
143  //check data validity
144  //unsigned int verified_bytes = 0;
145  unsigned int a = TCRX_cur_dscr * DSCR_SIZE/4;
146  //in this test decoded bytes will be compared with pattern-counter. the next byte to be decoded, should be equal to value of this variable
147  unsigned int nextExpectedWord = 0x03020100;
148 
149  for (unsigned int i = 0; i < frame_size/4; i+=1)
150  {
151  word = rx_buffer[a + i];
152 
153  if (word != nextExpectedWord)
154  {
155  PRINT("\tERROR: TCRX decoded data is not correct\n");
156  PRINT("\tIrq_counter = %d\n", TCRX_irq_counter);
157  PRINT("\t0x%08x\n", word);
158  Break_test = 1;
159  TCRX_errors++;
160  DBG_TX_Flush();
161  return;
162  }
163  else
164  {
165  }
166 
167  if (nextExpectedWord == 0xFFFEFDFC)
168  nextExpectedWord = 0x03020100;
169  else
170  nextExpectedWord += 0x04040404;
171  }
172 
173  if (frame_size % 4 != 0)
174  {
175  word = rx_buffer[a+frame_size/4];
176  a = ~(0xFFFFFFFF << 8*(frame_size%4));
177 
178  if ((word ^ nextExpectedWord)&a != 0)
179  {
180  PRINT("\tERROR: TCRX test - last word is not correct\n");
181  PRINT("0x%08x\n", word & a);
182  Break_test = 1;
183  TCRX_errors++;
184  DBG_TX_Flush();
185  return;
186  }
187  }
188 
189  InitDscr(TCRX_cur_dscr); //reset descriptor for further use
190  TCRX_cur_dscr++;
192 
193  TCRX_irq_counter++;
195 
196  if (nextExpectedSize == 700+7) //subtest ok
197  {
198  TCRX_stage++;
200  PRINT("\t\tTest progress: ok\n");
201  DBG_TX_Flush();
202  }
203 }
204 
205 #endif
206 
208 {
209  CMN_REG->ALT_FUNCTION_CTRL[6] = 0; // Для GPIO_G
210  CMN_REG->ALT_FUNCTION_CTRL[7] = 0; // Для GPIO_H
211 
212  GPIO_G->ALTFUNCSET = 0;
213  GPIO_H->ALTFUNCSET = 0;
214 
215  GPIO_G->ALTFUNCSET = (1<<15);
216  GPIO_H->ALTFUNCSET = (1<<0) | (1<<1) | (1<<2) | (1<<3);
217 }
218 
223 {
224  PWR_CLK_Enable(TCRX_CTRL_NUM); // Подача тактового сигнала на модуль
225  PWR_RST_Disable(TCRX_CTRL_NUM); // Вывод модуля из асинхронного сброса
226 }
227 
228 void Test_TCRX()
229 {
230  PRINT("\n********** TCRX test start **********\n");
231  DBG_TX_Flush();
232 
233  Gpio_TCRX_Init();
234  TCRX_Clock_init();
235 
236  unsigned int errors = 0;
237  TCRX_errors = 0;
238 
239  TCRX_irq_counter = 0;
240 
241  //initialize all descriptors
242  for (unsigned int i = 0; i < USED_COUNT; i++)
243  InitDscr(i);
244 
245 #warning Please, select the proper coder settings:
246 
247  for (int i=0;i<10000;i++);
248 
249  TCRX->START_SEQ = 0xEB90 | (1<<31); //0xAA55;
250  TCRX->TAIL_SEQ1 = 0x11223344;
251  TCRX->TAIL_SEQ2 = 0x55667788;
252 
253  TCRX_Enable(); // начало приёма данных, далее ожидаются прерывания по завершению дескрипторов
254 
256  TCRX_stage = 0;
257  Break_test = 0;
258 
260 
261 #ifdef CCSDS_TERMINAL
263 #endif
264 
265  for (unsigned int k = 0; k < (DSCR_SIZE/4)*USED_COUNT; k++)
266  rx_buffer[k] = 0;
267 
268 #ifdef DEBUG_TCRX
269  //manual BCH experiments
270  while(1)
271  {
273  {
275  PRINT("\t1-bit bus, BCH=ON, Randomizer=OFF, Convolution=OFF\n");
276  DBG_TX_Flush();
278  }
279 
280  if ((TCRX->DSCR_CURRENT & 0xF) >= USED_COUNT)
281  TCRX->DSCR_CURRENT &= 0x80000000;
282  }
283 #endif
284 
285  while(!Break_test)
286  {
288  {
290  switch (TCRX_stage)
291  {
292  case 0:
293  PRINT("\t\tsubtest#0 1-bit bus, BCH=OFF, Randomizer=OFF, Convolution=OFF\n");
294  DBG_TX_Flush();
295  InitCoder(0);
296 #ifdef CCSDS_TERMINAL
297  PRINT("COMMAND=TCRX_START_0\n");
298  DBG_TX_Flush();
299 #endif
300  break;
301  case 1:
302  PRINT("\t\tsubtest#1 1-bit bus, BCH=ON, Randomizer=OFF, Convolution=OFF\n");
303  DBG_TX_Flush();
305 #ifdef CCSDS_TERMINAL
306  PRINT("COMMAND=TCRX_START_1\n");
307  DBG_TX_Flush();
308 #endif
309  break;
310  case 2:
311  PRINT("\t\tsubtest#2 1-bit bus, BCH=OFF, Randomizer=ON, Convolution=OFF\n");
312  DBG_TX_Flush();
314 #ifdef CCSDS_TERMINAL
315  PRINT("COMMAND=TCRX_START_2\n");
316  DBG_TX_Flush();
317 #endif
318  break;
319  case 3:
320  PRINT("\t\tsubtest#3 1-bit bus, BCH=OFF, Randomizer=OFF, Convolution=ON\n");
321  DBG_TX_Flush();
323 #ifdef CCSDS_TERMINAL
324  PRINT("COMMAND=TCRX_START_3\n");
325  DBG_TX_Flush();
326 #endif
327  break;
328  case 4:
329  PRINT("\t\tsubtest#4 1-bit bus, BCH=ON, Randomizer=ON, Convolution=ON\n");
330  DBG_TX_Flush();
332 #ifdef CCSDS_TERMINAL
333  PRINT("COMMAND=TCRX_START_4\n");
334  DBG_TX_Flush();
335 #endif
336  break;
337 
338  case 5:
339  PRINT("\t\tsubtest#5 3-bit bus, BCH=ON, Randomizer=ON, Convolution=ON\n");
340  DBG_TX_Flush();
342 #ifdef CCSDS_TERMINAL
343  PRINT("COMMAND=TCRX_START_5\n");
344  DBG_TX_Flush();
345 #endif
346  break;
347  case 6:
348  PRINT("\t\tTest result - OK\n");
349  Break_test = 1;
350  DBG_TX_Flush();
351  break;
352  }
353  }
354 
355  if ((TCRX->DSCR_CURRENT & 0xF) >= USED_COUNT)
356  TCRX->DSCR_CURRENT &= 0x80000000;
357 
358  if (TCRX_errors > 0)
359  {
360  Break_test = 1;
361  break;
362  }
363 
364 #ifdef CCSDS_TERMINAL
365  if (!--test_timeout)
366  {
367  PRINT("\tERROR: no activity on TCRX interface. Exit test by timeout\n");
368  Break_test = 1;
369  TCRX_errors++;
370  DBG_TX_Flush();
371  break;
372  }
373 #endif
374  }
375  NVIC_Dis_IRQ(19);
376 
377  errors = TCRX_errors;
378 
379 TCRX_test_end:
380 
381  PRINT("\tTCRX test complete. Errors count = %d\n", errors);
382  DBG_TX_Flush();
383 
384 }
385 
386 #endif //TEST_TCRX
387 
388 
unsigned int nextExpectedSize
Definition: tcrx_test.c:52
#define PRINT(...)
Макросы для использования отладочного выхода
Definition: debug_uart.h:48
#define TEST_TIMEOUT_INIT
Definition: tcrx_test.c:65
void TCRX_IRQ(void)
Definition: tcrx_test.c:95
unsigned int test_timeout
Definition: tcrx_test.c:67
unsigned int Break_test
Definition: tcrx_test.c:56
const uint32_t sys_freq
Системная частота
Definition: tcrx_test.c:45
#define NVIC_Dis_IRQ(X)
X - вектор прерывания
Definition: system.h:574
unsigned int TCRX_stage
Definition: tcrx_test.c:60
void NVIC_EnableIRQ(IRQn_T IRQn, uint32_t vec)
Разрешение прерывания
Definition: system.c:74
unsigned int TCRX_errors
Definition: tcrx_test.c:63
#define RANDOMIZER_SEL_TCRX
Definition: tcrx_test.c:39
#define GPIO_G
Указатель на структуру GPIO_G.
volatile unsigned int TCRX_irq_counter
Definition: tcrx_test.c:55
unsigned int TCRX_cur_dscr
Definition: tcrx_test.c:51
void InitCoder(unsigned int coder_sel)
Definition: tcrx_test.c:77
void TCRX_Enable()
Активация приёма данных
Definition: tcrx.c:130
char dbg_buffer[256]
Отладочный буфер
Definition: tcrx_test.c:46
volatile TCRX_T * tcrx
Definition: tcrx_test.c:57
void PWR_RST_Disable(CTRL_T CTRLn)
Вывод модуля из асинхронного сброса
Definition: system.c:318
void PWR_CLK_Enable(CTRL_T CTRLn)
Подача тактового сигнала на модуль
Definition: system.c:337
#define USED_COUNT
Definition: tcrx_test.c:44
Структура для доступа к регистрам модуля приемника телекомандной информации
Definition: tcrx.h:46
void TCRX_Clock_init()
Настройка подачи тактового сигнала на модуль TCRX.
Definition: tcrx_test.c:222
uint32_t a
Definition: mem_test.c:34
unsigned int rx_buffer[(DSCR_SIZE/4) *USED_COUNT]
Definition: tcrx_test.c:50
#define CONVOLUTION_SEL
Definition: tcrx_test.c:41
#define TCRX
Указатель на структуру TCRX.
void InitDscr(unsigned char index)
Definition: tcrx_test.c:70
#define BCH_SEL
Definition: tcrx_test.c:40
#define DSCR_SIZE
Definition: tcrx_test.c:43
Этот файл содержит структуры, макросы и функции необходимые необходимые для тестовой программы для ап...
#define CMN_REG
Указатель на структуру CMN_REG.
void DBG_TX_Flush(void)
Вывод всех данных, накопленных в кольцевом буфере, в отладочный UART.
Definition: debug_uart.c:80
unsigned int TCRX_receive_complete
Definition: tcrx_test.c:59
#define GPIO_H
Указатель на структуру GPIO_H.
void Gpio_TCRX_Init()
Definition: tcrx_test.c:207
void Test_TCRX()
Definition: tcrx_test.c:228