CAL(1)

CAL(1)              BSD General Commands Manual            CAL(1)

NAME
     cal - displays a calendar

SYNOPSIS
     cal [-smjy13] [[[day] month] year]

DESCRIPTION
     Cal displays a simple calendar.  If arguments are not specified, the cur-
     rent month is displayed.  The options are as follows:

     -1         Display single month output.  (This is the default.)

     -3         Display prev/current/next month output.

     -s         Display Sunday as the first day of the week.

     -m         Display Monday as the first day of the week.

     -j         Display Julian dates (days one-based, numbered from January 1).

     -y         Display a calendar for the current year.

     -V         Display version information and exit.

     A single parameter specifies the year (1 - 9999) to be displayed; note
     the year must be fully specified: “cal 89” will not display a calendar
     for 1989.    Two parameters denote the month (1 - 12) and year.  Three
     parameters denote the day (1-31), month and year, and the day will be
     highlighted if the calendar is displayed on a terminal.  If no parameters
     are specified, the current month’s calendar is displayed.

     A year starts on Jan 1. The first day of the week is determined by the
     locale.

     The Gregorian Reformation is assumed to have occurred in 1752 on the 3rd
     of September.  By this time, most countries had recognized the reforma-
     tion (although a few did not recognize it until the early 1900’s.)     Ten
     days following that date were eliminated by the reformation, so the cal-
     endar for that month is a bit unusual.

HISTORY
     A cal command appeared in Version 6 AT&T UNIX.

OTHER VERSIONS
     Several much more elaborate versions of this program exist, with support
     for colors, holidays, birthdays, reminders and appointments, etc. For
     example, try the cal from http://home.sprynet.com/~cbagwell/projects.html
     or GNU gcal.

AVAILABILITY
     The cal command is part of the util-linux-ng package and is available
     from ftp://ftp.kernel.org/pub/linux/utils/util-linux-ng/.

BSD                 June 6, 1993                   BSD

转载于:https://my.oschina.net/vimer/blog/134384

The whole source code can be downloaded from our download center. /******************************************************************************* Function Name : main Description : Main program. Input : None Output : None Return : None *****************************************************************************/ void main(void) { ENTR_CRT_SECTION(); / Setup STM32 system (clock, PLL and Flash configuration) / SystemInit(); EXT_CRT_SECTION(); // Choose your Slot (SPI1, SPI2) void Bus_Type = SPI1; / controlled loop / while (Dummy_var!=11) // To control the loop, e.g. (Dummy_var!=7) { if (Dummy_var10) Dummy_var=0; // Infinite loop if(configured_trueFALSE) { configured_true = TRUE; SPIx_GPIOs_Init(Bus_Type); SPIx_Interface_Init(Bus_Type); #ifdef EMBEDDED_SRAM Embed_SRAM_Init(); #endif Ext_Interrupt_Init(); gp22_send_1byte(Bus_Type, Power_On_Reset); Dly100us((void)5); // 500 us wait for GP22 // Setting of the Configuration Registers // CR0: DIV_CLKHS = 2, START_CLKHS = 1, CALIBRATE = 0, MESSB2 = 0, NEG_STOP = NEGSTART = 0, … Register_0 = 0x00240000; // NO_CAL_AUTO = 0 Register_0_NO_CAL = 0x00241000; // NO_CAL_AUTO = 1 // CR1: HITIN2 = 1, HITIN1 = 1, … Register_1 = 0x19490000; // EN_FAST_INIT = 0 Register_1_FAST = 0x19C90000; // EN_FAST_INIT = 1 // CR2: EN_INT, RFEDGE1 = RFEDGE2 = 0, … // (NOTE: EN_INT = b111, it doesn’t work with using EN_FAST_INT) Register_2 = 0xA0000000; // EN_INT = Timeout(8) _ End HITs(4) _ ALU interrupt(2) // CR3: … Register_3 = 0x00000000; // CR4: ... Register_4 = 0x20000000; // CR5: CON_FIRE = b000, EN_STARTNOISE = 1, ... Register_5 = 0x10000000; // CR6: QUAD_RES = 0, ... Register_6 = 0x00000000; // Writing to the configuration registers (CR) gp22_wr_config_reg(Bus_Type, 0x80, Register_0_NO_CAL); gp22_wr_config_reg(Bus_Type, 0x81, Register_1_FAST); gp22_wr_config_reg(Bus_Type, 0x82, Register_2); gp22_wr_config_reg(Bus_Type, 0x83, Register_3); gp22_wr_config_reg(Bus_Type, 0x84, Register_4); gp22_wr_config_reg(Bus_Type, 0x85, Register_5); gp22_wr_config_reg(Bus_Type, 0x86, Register_6); } // ......................................................................... // ...START_CAL_RESONATOR..Calibrate High Speed Clock....................... // ...START_CAL_TDC.....Update the CAL2- and CAL1-Value..................... // ...................Laser Rangefinder Measurement CYCLE............LOOP... // .........................Caluculate Result Values........................ N_Measure_Cycles = 10000; diff_Cal2_Cal1_old = diff_Cal2_Cal1_new; if((Dummy_var==0) | (Dummy_var==10)) { //-------------------------------------------------------------------------- // Start Calibrate High Speed Clock Cycle (-->SLOW) // Important Note: NO_CAL_AUTO and EN_FAST_INIT need to be cleared! gp22_wr_config_reg(Bus_Type, 0x80, Register_0); // NO_CAL_AUTO = 0 gp22_wr_config_reg(Bus_Type, 0x81, Register_1); // EN_FAST_INIT = 0 gp22_send_1byte(Bus_Type, Init); gp22_send_1byte(Bus_Type, Start_Cal_Resonator); // Wait for INT Slot_x if (Bus_Type==SPI1) while (GPIO_ReadInputDataBit(GPIOD, GPIO_Pin_4)==1); if (Bus_Type==SPI2) while (GPIO_ReadInputDataBit(GPIOE, GPIO_Pin_11)==1); //Calculate Correction factor //The time interval to be measured is set by ANZ_PER_CALRES //which defines the number of periods of the 32.768 kHz clock: //2 periods = 61.03515625 µs CLKHS_freq_corr_fact = 61.03515625/ gp22_read_n_bytes_int(Bus_Type, 2, 0xB0, 0x00) * CLKHS_freq; // read only two bytes printf("\n Correction factor for clock = %1.4f\n", CLKHS_freq_corr_fact); CLKHS_freq_cal = CLKHS_freq * CLKHS_freq_corr_fact; // Calibrated Clock frequency //-------------------------------------------------------------------------- // Start Separate Calibration Measurement Cycle // Important Note: EN_INT = End HITs gp22_wr_config_reg(Bus_Type, 0x82, 0x40000000); // End HITs gp22_send_1byte(Bus_Type, Init); gp22_send_1byte(Bus_Type, Start_Cal_TDC); // update calibration data // Note: // The calibration data are not addressed directly after the calibration // measurement but after the next regular measurement; // Wait for INT Slot_x if (Bus_Type==SPI1) while (GPIO_ReadInputDataBit(GPIOD, GPIO_Pin_4)==1); if (Bus_Type==SPI2) while (GPIO_ReadInputDataBit(GPIOE, GPIO_Pin_11)==1); // Important Note: After Separate Calibration Measurement Cycle // EN_INT = ALU interrupt gp22_wr_config_reg(Bus_Type, 0x82, Register_2); // Timeout + ALU interrupt //-------------------------------------------------------------------------- // 1st ToF Measurement plus calibration data readout // Note: (NO_CAL_AUTO = 0 / EN_FAST_INIT = 0) --> SLOW gp22_send_1byte(Bus_Type, Init); //Trigger pulse laser // SetPortHigh; GPIO_SetBits(GPIOD, GPIO_Pin_8); // Output HIGH // SetPortLow; GPIO_ResetBits(GPIOD, GPIO_Pin_8); // Output LOW // Wait for INT Slot_x if (Bus_Type==SPI1) while (GPIO_ReadInputDataBit(GPIOD, GPIO_Pin_4)==1); if (Bus_Type==SPI2) while (GPIO_ReadInputDataBit(GPIOE, GPIO_Pin_11)==1); // First regular measurement (to readout calibration data) RAW_Result_int = gp22_read_n_bytes_int(Bus_Type,2,0xB0,0x00); // read only two bytes #ifdef EMBEDDED_SRAM Write_Emb_SRAM_uint32_t(RAW_Result_int); // writes the first value into SRAM #endif // printf("\n 1. Measured RAW Value = %u \n",RAW_Result_int); // RAW value // Check Status Register, next free result register // printf("Stat_Reg = 0x%04X \n",gp22_read_status_bytes(Bus_Type)); // readout the new calibration data from result register adr 0x01 gp22_wr_config_reg(Bus_Type, 0x81, 0x67490000); diff_Cal2_Cal1_new = gp22_read_n_bytes_int(Bus_Type,2,0xB0,0x01); // read only two bytes #ifdef EMBEDDED_SRAM Write_Emb_SRAM_uint32_t(diff_Cal2_Cal1_new); #endif } //-------------------------------------------------------------------------- // Calculate the real time after the hole first cycle loop while (diff_Cal2_Cal1_old != 0) { avg_diff_Cal2_Cal1 = (diff_Cal2_Cal1_new+diff_Cal2_Cal1_old) / 2; // printf("\n OLD Cal2-Cal1 RAW Value = %.0f \n",diff_Cal2_Cal1_old); // printf("\n NEW Cal2-Cal1 RAW Value = %.0f \n",diff_Cal2_Cal1_new); average_RAW_Result /= N_Measure_Cycles; // Used Formulas: // --------------------------------------------------- // T_ref // Time_Value = ----------- * measured_RAW_Value // Cal2-Cal1 // --------------------------------------------------- // velocity_of_light // Distance_Value = ------------------- * Time_Value // 2 // --------------------------------------------------- // For this Source Code would be a Reference Clock used with 1 MHz Time_Result = (average_RAW_Result/avg_diff_Cal2_Cal1) * 1000;//time [ns] Distance_Result = Time_Result / 6.671281904; //distance [m] printf("\n Time Measure Result (ToF) = %.3f ns\n",Time_Result); printf(" corresponds to %.3f m of Distance\n",Distance_Result); printf(" to reflected point after %u Measurements\n",N_Measure_Cycles); diff_Cal2_Cal1_old = 0; } //-------------------------------------------------------------------------- // if more than one measure cycle (-->FAST) average_RAW_Result = RAW_Result_int; // set first value of average_RAW_Result gp22_wr_config_reg(Bus_Type, 0x80, Register_0_NO_CAL); // NO_CAL_AUTO = 1 gp22_wr_config_reg(Bus_Type, 0x81, Register_1_FAST); // EN_FAST_INIT = 1 gp22_send_1byte(Bus_Type, Init); //-------------------------------------------------------------------------- // n'th ToF Measurement for (int i=2; i<=N_Measure_Cycles;i++) { //Trigger pulse laser // SetPortHigh; GPIO_SetBits(GPIOD, GPIO_Pin_8); // Output HIGH // SetPortLow; GPIO_ResetBits(GPIOD, GPIO_Pin_8); // Output LOW // Wait for INT Slot_x if (Bus_Type==SPI1) while (GPIO_ReadInputDataBit(GPIOD, GPIO_Pin_4)==1); if (Bus_Type==SPI2) while (GPIO_ReadInputDataBit(GPIOE, GPIO_Pin_11)==1); RAW_Result_int = gp22_read_n_bytes_int(Bus_Type,2,0xB0,0x00); // read only two bytes // printf(" %u. Measure RAW Value = %.0f \n",i,RAW_Result_int); // RAW value average_RAW_Result += RAW_Result_int; #ifdef EMBEDDED_SRAM Write_Emb_SRAM_uint32_t(RAW_Result_int); // writes the next values into SRAM #endif } printf("\nNEW CYCLE...\n"); Dummy_var++; // To Control the loop #ifdef EMBEDDED_SRAM // clear internal SRAM of µC sram_mem_offset = 0x0; #endif } // End while Dummy_var } //End main
08-13
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值