Guest User

Untitled

a guest
Jun 23rd, 2018
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. bit global_error_flag = 0;
  2. bit global_data_ready_flag = 0;
  3.  
  4. unsigned char A_Function (void) {
  5. // Do some stuff
  6.  
  7. if ( badness ) {
  8. global_error_flag = 0;
  9. global_data_ready_flag = 1;
  10.  
  11. return 0;
  12. }
  13.  
  14. if ( data_is_ready_use ) {
  15. global_data_ready_flag = 1;
  16. }
  17.  
  18. return a_value;
  19. }
  20.  
  21. void Other_Function (void) {
  22. unsigned char c;
  23.  
  24. c = A_Function();
  25.  
  26. if( global_error_flag) {
  27. // Do error stuff here.
  28. }
  29. else
  30. if( global_data_ready_flag ) {
  31. // Do data processing here.
  32. }
  33. global_error_flag = 0;
  34. global_data_ready_flag = 0;
  35.  
  36. }
  37.  
  38. #define FUNCTION_SETS_FLAGS(code) (code)
  39.  
  40. FUNCTION_SETS_FLAGS( c = A_Function() );
  41.  
  42. /*************************************************************************
  43. * FUNCTION : <function_name>
  44. * DESCRIPTION : <function description>
  45. * PARAMETERS :
  46. * Param1 - <Parameter-1 explanation>
  47. * Param2 - <Parameter-2 explanation>
  48. * Param3 - <Parameter-3 explanation>
  49. * RETURN : <Return value and type>
  50. * GLOBAL VARIABLES USED:
  51. * Global1 - <Global-1 explanation>
  52. * Global2 - <Global-2 explanation>
  53. * Global3 - <Global-3 explanation>
  54. *************************************************************************/
  55.  
  56. unsigned char _a_function(void);
  57.  
  58. #define A_Function(ret_val) (*(ret_val) = _a_function(), !global_error_flag)
  59.  
  60. ...
  61. unsigned char var;
  62. /* call the function */
  63. if (!A_Function(&var))
  64. {
  65. /* error! */
  66. }
  67. else
  68. {
  69. /* use var */
  70. var++;
  71. }
  72.  
  73. // Function func
  74. // Does something
  75. // Consumes ready_flag and sets error_flag on error.
  76.  
  77. int func()
  78. {
  79. if (ready_flag)
  80. {
  81. //do something then clear the flag
  82. if (some_error)
  83. error_flag = x;
  84. ready_flag = 0;
  85. }
  86. //don't mess with the flags outside of their 'scope'
  87. return 0;
  88. }
  89.  
  90. unsigned char A_Function (bit *p_error_flag, bit *p_data_ready_flag)
  91. {
  92. ...
  93. }
Add Comment
Please, Sign In to add comment