📄 os_tmr.lst
字号:
377 #endif
378 if (ptmr->OSTmrType != OS_TMR_TYPE) { /* Validate timer structure */
379 *perr = OS_ERR_TMR_INVALID_TYPE;
380 return (0);
381 }
382 if (OSIntNesting > 0) { /* See if trying to call from an ISR */
383 *perr = OS_ERR_TMR_ISR;
384 return (0);
385 }
386 OSTmr_Lock();
387 switch (ptmr->OSTmrState) {
388 case OS_TMR_STATE_RUNNING:
389 remain = ptmr->OSTmrMatch - OSTmrTime; /* Determine how much time is left to timeout */
390 OSTmr_Unlock();
391 *perr = OS_ERR_NONE;
392 return (remain);
393
394 case OS_TMR_STATE_STOPPED: /* It's assumed that the timer has not started yet */
395 switch (ptmr->OSTmrOpt) {
396 case OS_TMR_OPT_PERIODIC:
397 if (ptmr->OSTmrDly == 0) {
398 remain = ptmr->OSTmrPeriod;
399 } else {
400 remain = ptmr->OSTmrDly;
401 }
402 OSTmr_Unlock();
403 *perr = OS_ERR_NONE;
404 break;
405
406 case OS_TMR_OPT_ONE_SHOT:
407 default:
408 remain = ptmr->OSTmrDly;
409 OSTmr_Unlock();
410 *perr = OS_ERR_NONE;
411 break;
412 }
413 return (remain);
414
415 case OS_TMR_STATE_COMPLETED: /* Only ONE-SHOT that timed out can be in this state */
416 OSTmr_Unlock();
417 *perr = OS_ERR_NONE;
418 return (0);
419
420 case OS_TMR_STATE_UNUSED:
421 OSTmr_Unlock();
422 *perr = OS_ERR_TMR_INACTIVE;
423 return (0);
424
425 default:
426 OSTmr_Unlock();
427 *perr = OS_ERR_TMR_INVALID_STATE;
428 return (0);
429 }
430 }
431 #endif
432
433 /*$PAGE*/
434 /*
435 ************************************************************************************************************************
436 * FIND OUT WHAT STATE A TIMER IS IN
437 *
438 * Description: This function is called to determine what state the timer is in:
439 *
440 * OS_TMR_STATE_UNUSED the timer has not been created
441 * OS_TMR_STATE_STOPPED the timer has been created but has not been started or has been stopped
442 * OS_TMR_COMPLETED the timer is in ONE-SHOT mode and has completed it's timeout
443 * OS_TMR_RUNNING the timer is currently running
444 *
445 * Arguments : ptmr Is a pointer to the desired timer
446 *
447 * perr Is a pointer to an error code. '*perr' will contain one of the following:
448 * OS_ERR_NONE
449 * OS_ERR_TMR_INVALID 'ptmr' is a NULL pointer
450 * OS_ERR_TMR_INVALID_TYPE 'ptmr' is not pointing to an OS_TMR
451 * OS_ERR_TMR_ISR if the call was made from an ISR
452 * OS_ERR_TMR_INACTIVE 'ptmr' points to a timer that is not active
453 * OS_ERR_TMR_INVALID_STATE if the timer is not in a valid state
454 *
455 * Returns : The current state of the timer (see description).
456 ************************************************************************************************************************
457 */
458
459 #if OS_TMR_EN > 0
460 INT8U OSTmrStateGet (OS_TMR *ptmr,
461 INT8U *perr)
462 {
463 INT8U state;
464
465
466 #if OS_ARG_CHK_EN > 0
467 if (perr == (INT8U *)0) {
468 return (0);
469 }
470 if (ptmr == (OS_TMR *)0) {
471 *perr = OS_ERR_TMR_INVALID;
472 return (0);
473 }
474 #endif
475 if (ptmr->OSTmrType != OS_TMR_TYPE) { /* Validate timer structure */
476 *perr = OS_ERR_TMR_INVALID_TYPE;
477 return (0);
478 }
479 if (OSIntNesting > 0) { /* See if trying to call from an ISR */
480 *perr = OS_ERR_TMR_ISR;
481 return (0);
482 }
483 OSTmr_Lock();
484 state = ptmr->OSTmrState;
485 switch (state) {
486 case OS_TMR_STATE_UNUSED:
487 case OS_TMR_STATE_STOPPED:
488 case OS_TMR_STATE_COMPLETED:
489 case OS_TMR_STATE_RUNNING:
490 *perr = OS_ERR_NONE;
491 break;
492
493 default:
494 *perr = OS_ERR_TMR_INVALID_STATE;
495 break;
496 }
497 OSTmr_Unlock();
498 return (state);
499 }
500 #endif
501
502 /*$PAGE*/
503 /*
504 ************************************************************************************************************************
505 * START A TIMER
506 *
507 * Description: This function is called by your application code to start a timer.
508 *
509 * Arguments : ptmr Is a pointer to an OS_TMR
510 *
511 * perr Is a pointer to an error code. '*perr' will contain one of the following:
512 * OS_ERR_NONE
513 * OS_ERR_TMR_INVALID
514 * OS_ERR_TMR_INVALID_TYPE 'ptmr' is not pointing to an OS_TMR
515 * OS_ERR_TMR_ISR if the call was made from an ISR
516 * OS_ERR_TMR_INACTIVE if the timer was not created
517 * OS_ERR_TMR_INVALID_STATE the timer is in an invalid state
518 *
519 * Returns : OS_TRUE if the timer was started
520 * OS_FALSE if an error was detected
521 ************************************************************************************************************************
522 */
523
524 #if OS_TMR_EN > 0
525 BOOLEAN OSTmrStart (OS_TMR *ptmr,
526 INT8U *perr)
527 {
528 #if OS_ARG_CHK_EN > 0
529 if (perr == (INT8U *)0) { /* Validate arguments */
530 return (OS_FALSE);
531 }
532 if (ptmr == (OS_TMR *)0) {
533 *perr = OS_ERR_TMR_INVALID;
534 return (OS_FALSE);
535 }
536 #endif
537 if (ptmr->OSTmrType != OS_TMR_TYPE) { /* Validate timer structure */
538 *perr = OS_ERR_TMR_INVALID_TYPE;
539 return (OS_FALSE);
540 }
541 if (OSIntNesting > 0) { /* See if trying to call from an ISR */
542 *perr = OS_ERR_TMR_ISR;
543 return (OS_FALSE);
544 }
545 OSTmr_Lock();
546 switch (ptmr->OSTmrState) {
547 case OS_TMR_STATE_RUNNING: /* Restart the timer */
548 OSTmr_Unlink(ptmr); /* ... Stop the timer */
549 OSTmr_Link(ptmr, OS_TMR_LINK_DLY); /* ... Link timer to timer wheel */
550 OSTmr_Unlock();
551 *perr = OS_ERR_NONE;
552 return (OS_TRUE);
553
554 case OS_TMR_STATE_STOPPED: /* Start the timer */
555 case OS_TMR_STATE_COMPLETED:
556 OSTmr_Link(ptmr, OS_TMR_LINK_DLY); /* ... Link timer to timer wheel */
557 OSTmr_Unlock();
558 *perr = OS_ERR_NONE;
559 return (OS_TRUE);
560
561 case OS_TMR_STATE_UNUSED: /* Timer not created */
562 OSTmr_Unlock();
563 *perr = OS_ERR_TMR_INACTIVE;
564 return (OS_FALSE);
565
566 default:
567 OSTmr_Unlock();
568 *perr = OS_ERR_TMR_INVALID_STATE;
569 return (OS_FALSE);
570 }
571 }
572 #endif
573
574 /*$PAGE*/
575 /*
576 ************************************************************************************************************************
577 * STOP A TIMER
578 *
579 * Description: This function is called by your application code to stop a timer.
580 *
581 * Arguments : ptmr Is a pointer to the timer to stop.
582 *
583 * opt Allows you to specify an option to this functions which can be:
584 *
585 * OS_TMR_OPT_NONE Do nothing special but stop the timer
586 * OS_TMR_OPT_CALLBACK Execute the callback function, pass it the callback argument
587 * specified when the timer was created.
588 * OS_TMR_OPT_CALLBACK_ARG Execute the callback function, pass it the callback argument
589 * specified in THIS function call
590 *
591 * callback_arg Is a pointer to a 'new' callback argument that can be passed to the callback function
592 * instead of the timer's callback argument. In other words, use 'callback_arg' passed in
593 * THIS function INSTEAD of ptmr->OSTmrCallbackArg
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -