Subversion Repositories AFRtranscoder

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. #ifndef _JTEST_FW_H_
  2. #define _JTEST_FW_H_
  3.  
  4. /*--------------------------------------------------------------------------------*/
  5. /* Includes */
  6. /*--------------------------------------------------------------------------------*/
  7.  
  8. #include <stdint.h>             /* int32_t */
  9. #include <string.h>             /* strcpy() */
  10. #include <stdio.h>              /* sprintf() */
  11. #include "jtest_pf.h"           /* Extend JTEST_FW_t with Pass/Fail data */
  12. #include "jtest_group.h"
  13.  
  14. /*--------------------------------------------------------------------------------*/
  15. /* Type Definitions */
  16. /*--------------------------------------------------------------------------------*/
  17.  
  18. /**
  19.  *  A struct used to interface with the Keil Debugger.
  20.  */
  21. typedef struct JTEST_FW_struct
  22. {
  23.     /* Action Triggers: The Keil debugger monitors these values for changes.  In
  24.      * response to a change, the debugger executes code on the host. */
  25.     volatile int32_t test_start;
  26.     volatile int32_t test_end;
  27.     volatile int32_t group_start;
  28.     volatile int32_t group_end;
  29.     volatile int32_t dump_str;
  30.     volatile int32_t dump_data;
  31.     volatile int32_t exit_fw;
  32.  
  33.     JTEST_GROUP_t * current_group_ptr;
  34.  
  35.     /* Buffers: The C-code cannot send strings and data directly to the
  36.      * debugging framework. Instead, the debugger can be told to read 128 byte
  37.      * (by default) chunks of memory.  Data received in this manner requires
  38.      * post-processing to be legible.*/
  39.     char * str_buffer;
  40.     char * data_buffer;
  41.  
  42.     /* Pass/Fail Data */
  43.     JTEST_PF_MEMBERS;
  44.  
  45. } JTEST_FW_t;
  46.  
  47. /*--------------------------------------------------------------------------------*/
  48. /* Macros and Defines */
  49. /*--------------------------------------------------------------------------------*/
  50.  
  51. /**
  52.  *  Default name for the JTEST_FW struct.
  53.  *
  54.  *  Define your own if you want the variable containing the #JTEST_FW_t to have
  55.  *  a different name.
  56.  */
  57. #ifndef JTEST_FW
  58. #define JTEST_FW JTEST_FW
  59. #endif
  60.  
  61. /**
  62.  *  Default name for the JTEST_FW_STR_BUFFER.
  63.  *
  64.  *  Define your own if you want the variable containing the char buffer to have
  65.  *  a different name.
  66.  */
  67. #ifndef JTEST_FW_STR_BUFFER
  68. #define JTEST_FW_STR_BUFFER JTEST_FW_STR_BUFFER
  69. #endif
  70.  
  71. /**
  72.  *  Size of the #JTEST_FW_t, output string-buffer.
  73.  *
  74.  *  If you change this value, make sure the "dump_str_fn" and "dump_data_fn"
  75.  *  functions in jtest_fns.ini uses the same size. If you aren't sure, read the
  76.  *  documentation Keil Debugger Command 'DISPLAY'.
  77.  */
  78. #define JTEST_BUF_SIZE 256
  79.  
  80.  
  81. /**
  82.  *  The maximum number of bytes output at once using #JTEST_DUMP_STRF().
  83.  */
  84. #define JTEST_STR_MAX_OUTPUT_SIZE 128
  85.  
  86. /**
  87.  *  The maximum number of block transimissions needed to send a string from a
  88.  *  buffer with JTEST_BUF_SIZE.
  89.  */
  90. #define JTEST_STR_MAX_OUTPUT_SEGMENTS           \
  91.     (JTEST_BUF_SIZE / JTEST_STR_MAX_OUTPUT_SIZE)
  92.  
  93. /**
  94.  *  Initialize the JTEST framework.
  95.  */
  96. #define JTEST_INIT()                                                    \
  97.     do                                                                  \
  98.     {                                                                   \
  99.         JTEST_FW.str_buffer = JTEST_FW_STR_BUFFER;                      \
  100.     } while (0)
  101.  
  102. /* Debugger Action-triggering Macros */
  103. /*--------------------------------------------------------------------------------*/
  104.  
  105. /**
  106.  *  Dispatch macro to trigger various actions in the Keil Debugger.
  107.  */
  108. #define JTEST_TRIGGER_ACTION(action_name)       \
  109.     do                                          \
  110.     {                                           \
  111.         action_name();                          \
  112.     } while (0)
  113.  
  114. /**
  115.  *  Trigger the "Test Start" action in the Keil Debugger.
  116.  */
  117. #define JTEST_ACT_TEST_START()                  \
  118.     JTEST_TRIGGER_ACTION(test_start)
  119.  
  120. /**
  121.  *  Trigger the "Test End" action in the Keil Debugger.
  122.  */
  123. #define JTEST_ACT_TEST_END()                    \
  124.     JTEST_TRIGGER_ACTION(test_end)
  125.  
  126.  
  127. /**
  128.  *  Trigger the "Group Start" action in the Keil Debugger.
  129.  */
  130. #define JTEST_ACT_GROUP_START()                 \
  131.     JTEST_TRIGGER_ACTION(group_start)
  132.  
  133. /**
  134.  *  Trigger the "Group End" action in the Keil Debugger.
  135.  */
  136. #define JTEST_ACT_GROUP_END()                   \
  137.     JTEST_TRIGGER_ACTION(group_end)
  138.  
  139.  
  140. /**
  141.  *  Fill the buffer named buf_name with value and dump it to the Keil debugger
  142.  *  using action.
  143.  */
  144. #define JTEST_ACT_DUMP(action, buf_name, value) \
  145.     do                                          \
  146.     {                                           \
  147.         JTEST_CLEAR_BUFFER(buf_name);           \
  148.         strcpy(JTEST_FW.buf_name, (value));     \
  149.         JTEST_TRIGGER_ACTION(action);           \
  150.     } while (0)
  151.  
  152. /**
  153.  *  Trigger the "Exit Framework" action in the Keil Debugger.
  154.  */
  155. #define JTEST_ACT_EXIT_FW()                     \
  156.     do                                          \
  157.     {                                           \
  158.         JTEST_TRIGGER_ACTION(exit_fw);          \
  159.     } while (0)
  160.  
  161.  
  162. /* Buffer Manipulation Macros */
  163. /*--------------------------------------------------------------------------------*/
  164.  
  165. /**
  166.  *  Clear the JTEST_FW buffer with name buf_name.
  167.  */
  168. #define JTEST_CLEAR_BUFFER(buf_name)                    \
  169.     do                                                  \
  170.     {                                                   \
  171.         memset(JTEST_FW.buf_name, 0, JTEST_BUF_SIZE);   \
  172.     } while (0)
  173.  
  174. /**
  175.  *  Clear the memory needed for the JTEST_FW's string buffer.
  176.  */
  177. #define JTEST_CLEAR_STR_BUFFER()                \
  178.         JTEST_CLEAR_BUFFER(str_buffer)
  179.  
  180. /**
  181.  *  Clear the memory needed for the JTEST_FW's data buffer.
  182.  */
  183. #define JTEST_CLEAR_DATA_BUFFER()               \
  184.         JTEST_CLEAR_BUFFER(data_buffer)
  185.  
  186. /**
  187.  *  Dump the given string to the Keil Debugger.
  188.  */
  189. #define JTEST_DUMP_STR(string)                          \
  190.         JTEST_ACT_DUMP(dump_str, str_buffer, string)
  191.  
  192. /**
  193.  *  Dump a formatted string to the Keil Debugger.
  194.  */
  195. #define JTEST_DUMP_STRF(format_str, ... )                               \
  196.     do                                                                  \
  197.     {                                                                   \
  198.         JTEST_CLEAR_STR_BUFFER();                                       \
  199.         sprintf(JTEST_FW.str_buffer,format_str, __VA_ARGS__);           \
  200.         jtest_dump_str_segments();                                      \
  201.     } while (0)
  202.  
  203. /* Pass/Fail Macros */
  204. /*--------------------------------------------------------------------------------*/
  205.  
  206. /**
  207.  *  Increment the number of passed tests in #JTEST_FW.
  208.  */
  209. #define JTEST_FW_INC_PASSED(amount)             \
  210.         JTEST_PF_INC_PASSED(&JTEST_FW, amount)
  211.  
  212. /**
  213.  *  Increment the number of passed tests in #JTEST_FW.
  214.  */
  215. #define JTEST_FW_INC_FAILED(amount)             \
  216.         JTEST_PF_INC_FAILED(&JTEST_FW, amount)
  217.  
  218. /* Manipulating the Current Group */
  219. /*--------------------------------------------------------------------------------*/
  220.  
  221. /**
  222.  *  Evaluate to the current_group_ptr in #JTEST_FW.
  223.  */
  224. #define JTEST_CURRENT_GROUP_PTR()               \
  225.     (JTEST_FW.current_group_ptr)
  226.  
  227. #define JTEST_SET_CURRENT_GROUP(group_ptr)      \
  228.     do                                          \
  229.     {                                           \
  230.         JTEST_CURRENT_GROUP_PTR() = group_ptr;  \
  231.     } while (0)
  232.  
  233. /*--------------------------------------------------------------------------------*/
  234. /* Declare Global Variables */
  235. /*--------------------------------------------------------------------------------*/
  236. extern char JTEST_FW_STR_BUFFER[JTEST_BUF_SIZE];
  237. extern volatile JTEST_FW_t JTEST_FW;
  238.  
  239. /*--------------------------------------------------------------------------------*/
  240. /* Function Prototypes */
  241. /*--------------------------------------------------------------------------------*/
  242. void jtest_dump_str_segments(void);
  243.  
  244. void test_start  (void);
  245. void test_end    (void);
  246. void group_start (void);
  247. void group_end   (void);
  248. void dump_str    (void);
  249. void dump_data   (void);
  250. void exit_fw     (void);
  251.  
  252.  
  253. #endif /* _JTEST_FW_H_ */
  254.