poppy_com  0.1
Poppy2.0 communication library
 All Classes Files Functions Variables Enumerations Enumerator Pages
test.c
1 /*
2  * test.c
3  *
4  * Created: 11/02/2015 12:40:48
5  * Author: Nicolas Rabault
6  */
7 
8 
10 #include "poppy-com/inc/i2c_master.h"
11 #include "test/inc/test_mngmnt.h"
12 
13 #include <stdio.h>
14 
15 extern context_t ctx;
16 
17 int test_value = 0;
18 
19 typedef enum {
20  TEST_REGISTER = PROTOCOL_REGISTER_NB,
21  MODULE_REGISTER_NB
22 }module_register_t;
23 
24 void rx_cb(msg_dir_t dir, msg_t *msg) {
25  switch (msg->reg) {
26  case TEST_REGISTER :
27  test_value = ((int)msg->data[0] << 8) | (int)msg->data[1];
28  break;
29  default :
30  test_value = 0;
31  break;
32  }
33 }
34 
35 void rxgc_cb(msg_dir_t dir, msg_t *msg) {
36 }
37 
38 void tx_cb(msg_t *msg) {
39 }
40 
41 void Init(void) {
43 }
44 
45 /*
46  * TEST SEQUENCES
47  */
48 
49 unsigned char test_init(void) {
50  printf("\nInitialisation :\n");
51  Init();
52  if (test(ctx.tx_cb == tx_cb)) return 1;
53  if (test(ctx.rx_cb == rx_cb)) return 1;
54  if (test(ctx.rxgc_cb == rxgc_cb)) return 1;
55  return 0;
56 }
57 
58 
59 unsigned char id_gc(void) {
60  printf("\nWrite ID GC :\n");
61  if (test(!set_extern_id(0x00, 0x0A))) return 1;
62  if (test(ctx.id == 0x0A)) return 1;
63  return 0;
64 }
65 
66 unsigned char id(void) {
67  printf("\nWrite ID :\n");
68  if (test(!set_extern_id(0x01, 0x0B))) return 1;
69  if (test(ctx.id == 0x0B)) return 1;
70  return 0;
71 }
72 
73 unsigned char get_module(void) {
74  printf("\nGet extern module type\n");
75  unsigned char extrn_type;
76  if (test(!get_extern_module_type(0x0B, &extrn_type))) return 1;
77  if (test(extrn_type == DEV_BOARD)) return 1;
78  return 0;
79 }
80 
81 unsigned char write(void) {
82  printf("\nWrite message :\n");
83  msg_t msg = {.reg = TEST_REGISTER, .size = 2, .data[0] = 0xCA,
84  .data[1] = 0xFE};
85  if (test(!poppyNetwork_write(0x01, &msg))) return 1;
86  if (test(test_value == 0xCAFE)) return 1;
87  return 0;
88 }
89 
90 int main(void) {
91  printf("test sequences :\n");
92 
93  test_sequences(test_init);
94  test_sequences(id_gc);
95  test_sequences(id);
96  test_sequences(get_module);
97  test_sequences(write);
98 
99  return test_end();
100 }
RX_CB rxgc_cb
Definition: context.h:39
unsigned char id
Definition: context.h:42
RX_CB rx_cb
Definition: context.h:38
unsigned char poppyNetwork_write(unsigned char addr, msg_t *msg)
Master mode write function.
Definition: poppyNetwork.c:85
void tx_cb(msg_t *msg)
Callback function for Slave mode messages transmission.
Definition: template.c:73
void poppyNetwork_init(TX_CB tx_cb, RX_CB rx_cb, RX_CB rxgc_cb)
Initialisation of the Poppy communication lib.
Definition: poppyNetwork.c:17
unsigned char data[512]
Definition: poppyNetwork.h:41
Message structure.
Definition: poppyNetwork.h:38
TX_CB tx_cb
Definition: context.h:37
void rxgc_cb(msg_dir_t dir, msg_t *msg)
Callback function for Slave mode messages reception with general call.
Definition: template.c:61
Poppy communication main include file.
int main(void)
Your main module application process.
Definition: template.c:86
unsigned char reg
Definition: poppyNetwork.h:39
void rx_cb(msg_dir_t dir, msg_t *msg)
Callback function for Slave mode messages reception.
Definition: template.c:48
msg_dir_t
Message direction enum.
Definition: poppyNetwork.h:22