void monthranger(int y, int m, int jd_flag, int before, int after) { struct monthlines year[12]; struct weekdays wds; char s[MAX_WIDTH], t[MAX_WIDTH]; int i, j; int mpl; int mw; int m1, m2; int prevyear = -1; int printyearheader; mpl = jd_flag ? 3 : 4; mw = jd_flag ? MONTH_WIDTH_R_J : MONTH_WIDTH_R; while (before != 0) { DECREASEMONTH(m, y); before--; after++; } m1 = y * 12 + m - 1; m2 = m1 + after; mkweekdays(&wds); /* * The year header is printed when there are more than 'mpl' months * and if the first month is a multitude of 'mpl'. * If not, it will print the year behind every month. */ printyearheader = (after >= mpl - 1) && (M2M(m1) - 1) % mpl == 0; m = m1; while (m <= m2) { int count = 0; for (i = 0; i != mpl && m + i <= m2; i++) { mkmonthr(M2Y(m + i), M2M(m + i) - 1, jd_flag, year + i); count++; } /* Empty line between two rows of months. */ if (m != m1) printf("\n"); /* Year at the top. */ if (printyearheader && M2Y(m) != prevyear) { sprintf(s, "%d", M2Y(m)); printf("%s\n", center(t, s, mpl * mw)); prevyear = M2Y(m); } /* Month names. */ wprintf(L" "); for (i = 0; i < count; i++) if (printyearheader) wprintf(L"%-*ls", mw, year[i].name); else wprintf(L"%-ls %-*d", year[i].name, mw - wcslen(year[i].name) - 1, M2Y(m + i)); printf("\n"); /* And the days of the month. */ for (i = 0; i != 7; i++) { /* Week day */ wprintf(L"%.2ls", wds.names[i]); /* Full months */ for (j = 0; j < count; j++) printf("%-*s", MW(mw, year[j].extralen[i]), year[j].lines[i]); printf("\n"); } /* Week numbers. */ if (flag_weeks) { printf(" "); for (i = 0; i < count; i++) printf("%-*s", mw, year[i].weeks); printf("\n"); } m += mpl; } return; }
/* 1.Fill the fifo with value read from the file. 2. In case of TS fifos, 188 bytes or one full TS packet is processed. 3.In docsis fifo, the timestamps and bytecount are prepended to the data. 4. Only one docsis fifo is currently implemented. 5. The values read from the files are converted to long and inserted to the fifo locations starting from the base address 6. The appropriate bits in the test registers are set to initiate the transfer */ INT32 Fill_Fifo(UINT32 AddrVar,UINT32 Timestamp_lo,UINT32 Timestamp_hi, UINT32 ByteOffset,const INT8* FileName) { INT8 NextByte[32]; INT8* EndPtr; UINT32 next_value; UINT32 fifo_value; UINT32 InsertCount; INT32 i,errcode; INT32 mod_count; UINT32 ByteCount; UINT32 TS_BYTES[256]; UINT32 WriteAddr; UINT32 reg_value; UINT32 Timeout; UINT32 status_value; //FILE* FillFile; /*FillFile = fopen(FileName,"r"); if(FillFile==0) { printf("fopen Failed File: %s\n", FileName); }*/ next_value = 0x0; i = 0; errcode = 0x0; printf("**Fill_Fifo Started ..... \n"); // printf("from file %s \n",FileName); switch(AddrVar) { case DS_FIFO_TS_0_ENABLE: case DS_FIFO_TS_1_ENABLE: case DS_FIFO_TS_2_ENABLE: case DS_FIFO_TS_3_ENABLE: InsertCount = 0; while (fgets(NextByte,32,FillFile) != NULL) { next_value = strtoul(NextByte,&EndPtr,16); //get byte from file //printf(" nextval = %x\n",next_value); TS_BYTES[InsertCount] = (next_value & 0xFF); // limit size to byte //printf(" TS_Byte %d = %x\n",InsertCount,TS_BYTES[InsertCount]); InsertCount++; if(InsertCount == 188) { switch(AddrVar) { case DS_FIFO_TS_0_ENABLE: WriteAddr = DOCSIS_TS_TEST_FIFO_0_BASE_ADDRESS; reg_value = 0x1; break; case DS_FIFO_TS_1_ENABLE: WriteAddr = DOCSIS_TS_TEST_FIFO_1_BASE_ADDRESS; reg_value = 0x2; break; case DS_FIFO_TS_2_ENABLE: WriteAddr = DOCSIS_TS_TEST_FIFO_2_BASE_ADDRESS; reg_value = 0x4; break; case DS_FIFO_TS_3_ENABLE: WriteAddr = DOCSIS_TS_TEST_FIFO_3_BASE_ADDRESS; reg_value = 0x8; break; } //end swicth AddrVar fifo_value=0x0; for(i = 0;i < 188;i++) { mod_count = i%4; switch(mod_count) { case 0: fifo_value |= TS_BYTES[i]; break; case 1: fifo_value |= (TS_BYTES[i] << 8); break; case 2: fifo_value |= (TS_BYTES[i] << 16); break; case 3: fifo_value |= (TS_BYTES[i] << 24); break; } //end switch if( (i != 0) && (mod_count == 0x3) ) { if(MW(WriteAddr,fifo_value) != 0x0) { errcode = 1; goto errexit; } WriteAddr += 0x4; fifo_value = 0x0; } } //end for 188 if(MW(WriteAddr,fifo_value) != 0x0) { errcode = 1; goto errexit; } if(MW(DOCSIS_DCSD_TS_TEST_REGISTER,reg_value) != 0x0) { errcode = 1; goto errexit; } Timeout = 0xFFF; if(Axi_MR(DOCSIS_DCSD_TS_TEST_REGISTER,&status_value) != 0x0) { errcode = 1; goto errexit; } while (Timeout != 0 && (status_value & reg_value)) { if(Axi_MR(DOCSIS_DCSD_TS_TEST_REGISTER,&status_value) != 0x0) { errcode = 1; goto errexit; } Timeout--; } if(Timeout == 0) { errcode = 1; goto errexit; } InsertCount = 0; } //end if 188 --- one full TS has been processed } //end while break; case DS_FIFO_OC_ENABLE: while (fgets(NextByte,32,FillFile) != NULL) { next_value = strtoul(NextByte,&EndPtr,16); //get byte from file if(MW(MAC_REG_DS_TEST_WR,next_value) != 0x0) { errcode = 1; goto errexit; } } //end while break; case DS_FIFO_DOCSIS_0_ENABLE: WriteAddr = DOCSIS_DOCSIS_TEST_FIFO_0_BASE_ADDRESS; ByteCount = 0x0; next_value = (Timestamp_hi & 0xFFFF); next_value |= (ByteOffset & 0xFFFF) << 16; if(MW(WriteAddr,next_value) != 0x0) { errcode = 1; goto errexit; } WriteAddr += 0x4; ByteCount += 0x4; next_value = Timestamp_lo; if(MW(WriteAddr,next_value) != 0x0) { errcode = 1; goto errexit; } WriteAddr += 0x4; ByteCount += 0x4; i = 0; fifo_value = 0x0; while (fgets(NextByte,32,FillFile) != NULL) { next_value = strtoul(NextByte,&EndPtr,16); //get byte from file ByteCount++; mod_count = i%4; switch(mod_count) { case 0: fifo_value |= next_value; break; case 1: fifo_value |= (next_value << 8); break; case 2: fifo_value |= (next_value << 16); break; case 3: fifo_value |= (next_value << 24); if(MW(WriteAddr,fifo_value) != 0x0) { errcode = 1; goto errexit; } WriteAddr += 0x4; fifo_value = 0x0; break; } //end switch i++; } //end while mod_count = i%4; if(mod_count != 0x0) { if(MW(WriteAddr,fifo_value) != 0x0) { errcode = 1; goto errexit; } } reg_value = (ByteCount & 0x7FF) | 0x8000; if(MW(DOCSIS_DCSD_DCS_TEST_0_REGISTER,reg_value) != 0x0) { errcode = 1; goto errexit; } break; default: errcode = 1; goto errexit; } errexit: fclose(FillFile); printf("**Fill_Fifo Completed .....\n"); return errcode; }/* Fill_Fifo() */
/* Print all months for the period in the range [ before .. y-m .. after ]. */ void monthrangeb(int y, int m, int jd_flag, int before, int after) { struct monthlines year[12]; struct weekdays wds; char s[MAX_WIDTH], t[MAX_WIDTH]; wchar_t ws[MAX_WIDTH], ws1[MAX_WIDTH]; const char *wdss; int i, j; int mpl; int mw; int m1, m2; int printyearheader; int prevyear = -1; mpl = jd_flag ? 2 : 3; mw = jd_flag ? MONTH_WIDTH_B_J : MONTH_WIDTH_B; wdss = (mpl == 2) ? " " : ""; while (before != 0) { DECREASEMONTH(m, y); before--; after++; } m1 = y * 12 + m - 1; m2 = m1 + after; mkweekdays(&wds); /* * The year header is printed when there are more than 'mpl' months * and if the first month is a multitude of 'mpl'. * If not, it will print the year behind every month. */ printyearheader = (after >= mpl - 1) && (M2M(m1) - 1) % mpl == 0; m = m1; while (m <= m2) { int count = 0; for (i = 0; i != mpl && m + i <= m2; i++) { mkmonthb(M2Y(m + i), M2M(m + i) - 1, jd_flag, year + i); count++; } /* Empty line between two rows of months */ if (m != m1) printf("\n"); /* Year at the top. */ if (printyearheader && M2Y(m) != prevyear) { sprintf(s, "%d", M2Y(m)); printf("%s\n", center(t, s, mpl * mw)); prevyear = M2Y(m); } /* Month names. */ for (i = 0; i < count; i++) if (printyearheader) wprintf(L"%-*ls ", mw, wcenter(ws, year[i].name, mw)); else { swprintf(ws, sizeof(ws), L"%-ls %d", year[i].name, M2Y(m + i)); wprintf(L"%-*ls ", mw, wcenter(ws1, ws, mw)); } printf("\n"); /* Day of the week names. */ for (i = 0; i < count; i++) { wprintf(L"%s%ls%s%ls%s%ls%s%ls%s%ls%s%ls%s%ls ", wdss, wds.names[6], wdss, wds.names[0], wdss, wds.names[1], wdss, wds.names[2], wdss, wds.names[3], wdss, wds.names[4], wdss, wds.names[5]); } printf("\n"); /* And the days of the month. */ for (i = 0; i != 6; i++) { for (j = 0; j < count; j++) printf("%-*s ", MW(mw, year[j].extralen[i]), year[j].lines[i]+1); printf("\n"); } m += mpl; } }
void _WVarDec (void) { // Sub 1 from Var MW(ATPOP)-= (1); }
//------- Specifical Operations : void _IVarVal (void) { // Get signed Word Var value AT= (int16)MW(AT); // signed 16-bit integer ! }
void _WVarInc (void) { // Add 1 to Var MW(ATPOP)+= (1); }
void _WVarSub (void) { // Sub value from Var MW(AT)-= (word)AITEM(1); ADELn(2); }
void _WVarAdd (void) { // Add value to Var MW(AT)+= (word)AITEM(1); ADELn(2); }
void _WVarSt0 (void) { // Assign Var value 0 MW(ATPOP)= (0); }
void _WVarSt1 (void) { // Assign Var value 1 MW(ATPOP)= (1); }