amiro-os / unittests / periphery-lld / src / ut_alld_P9221R_v1.c @ 7da9c509
History | View | Annotate | Download (5.782 KB)
1 | da1c10ac | Julia Niermann | /*
|
---|---|---|---|
2 | AMiRo-OS is an operating system designed for the Autonomous Mini Robot (AMiRo) platform.
|
||
3 | Copyright (C) 2016..2019 Thomas Schöpping et al.
|
||
4 | |||
5 | This program is free software: you can redistribute it and/or modify
|
||
6 | it under the terms of the GNU General Public License as published by
|
||
7 | the Free Software Foundation, either version 3 of the License, or
|
||
8 | (at your option) any later version.
|
||
9 | |||
10 | This program is distributed in the hope that it will be useful,
|
||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
13 | GNU General Public License for more details.
|
||
14 | |||
15 | You should have received a copy of the GNU General Public License
|
||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||
17 | */
|
||
18 | |||
19 | a2cdc4ae | Julia Niermann | #include <amiroos.h> |
20 | #include <ut_alld_P9221R_v1.h> |
||
21 | |||
22 | da1c10ac | Julia Niermann | #if ((AMIROOS_CFG_TESTS_ENABLE == true) && defined(AMIROLLD_CFG_P9221R) && (AMIROLLD_CFG_P9221R == 1)) || defined(__DOXYGEN__) |
23 | |||
24 | #include <math.h> |
||
25 | |||
26 | /******************************************************************************/
|
||
27 | /* LOCAL DEFINITIONS */
|
||
28 | /******************************************************************************/
|
||
29 | |||
30 | /******************************************************************************/
|
||
31 | /* EXPORTED VARIABLES */
|
||
32 | /******************************************************************************/
|
||
33 | |||
34 | /******************************************************************************/
|
||
35 | /* LOCAL TYPES */
|
||
36 | /******************************************************************************/
|
||
37 | |||
38 | /******************************************************************************/
|
||
39 | /* LOCAL VARIABLES */
|
||
40 | /******************************************************************************/
|
||
41 | |||
42 | /******************************************************************************/
|
||
43 | /* LOCAL FUNCTIONS */
|
||
44 | /******************************************************************************/
|
||
45 | |||
46 | /******************************************************************************/
|
||
47 | /* EXPORTED FUNCTIONS */
|
||
48 | /******************************************************************************/
|
||
49 | |||
50 | 7a333f53 | Julia Niermann | |
51 | a2cdc4ae | Julia Niermann | aos_utresult_t utAlldP9221rFunc(BaseSequentialStream* stream, aos_unittest_t* ut) |
52 | { |
||
53 | da1c10ac | Julia Niermann | aosDbgCheck(ut->data != NULL && ((ut_p9221rdata_t*)(ut->data))->PRd != NULL); |
54 | |||
55 | // local variables
|
||
56 | aos_utresult_t result = {0, 0}; |
||
57 | uint32_t status; |
||
58 | 7da9c509 | Julia Niermann | uint8_t data[79] = {0xA5}; |
59 | uint8_t alignment[20] = {0xA5}; |
||
60 | int8_t x_alignment; |
||
61 | int8_t y_alignment; |
||
62 | adcbcf83 | Julia Niermann | int32_t voltage; |
63 | int32_t current; |
||
64 | da1c10ac | Julia Niermann | |
65 | 7da9c509 | Julia Niermann | chprintf(stream, "read all registers...\n");
|
66 | status = p9221r_lld_read_register(((ut_p9221rdata_t*)ut->data)->PRd, P9221R_LLD_REGISTER_PARTNUMBER, data, 79, ((ut_p9221rdata_t*)ut->data)->timeout);
|
||
67 | if (status == APAL_STATUS_SUCCESS) {
|
||
68 | aosUtPassed(stream, &result); |
||
69 | for(int i=0; i<79; i++){ |
||
70 | chprintf(stream, "register: 0x%02x, data: 0x%02X \n", 0x00+i, data[i]); |
||
71 | } |
||
72 | } else {
|
||
73 | aosUtFailed(stream, &result); |
||
74 | } |
||
75 | da1c10ac | Julia Niermann | |
76 | chprintf(stream, "read registers...\n");
|
||
77 | 7da9c509 | Julia Niermann | status = p9221r_lld_read_register(((ut_p9221rdata_t*)ut->data)->PRd, P9221R_LLD_REGISTER_BATTERY_STATUS_SENT, alignment, 20, ((ut_p9221rdata_t*)ut->data)->timeout);
|
78 | da1c10ac | Julia Niermann | if (status == APAL_STATUS_SUCCESS) {
|
79 | aosUtPassed(stream, &result); |
||
80 | 7da9c509 | Julia Niermann | for(int i=0; i<20; i++){ |
81 | chprintf(stream, "register: 0x%02x, data: 0x%02X \n", P9221R_LLD_REGISTER_BATTERY_STATUS_SENT+i, alignment[i]);
|
||
82 | da1c10ac | Julia Niermann | } |
83 | } else {
|
||
84 | aosUtFailed(stream, &result); |
||
85 | } |
||
86 | |||
87 | 7da9c509 | Julia Niermann | chprintf(stream, "read all registers...\n");
|
88 | status = p9221r_lld_read_register(((ut_p9221rdata_t*)ut->data)->PRd, P9221R_LLD_REGISTER_PARTNUMBER, data, 79, ((ut_p9221rdata_t*)ut->data)->timeout);
|
||
89 | adcbcf83 | Julia Niermann | if (status == APAL_STATUS_SUCCESS) {
|
90 | aosUtPassed(stream, &result); |
||
91 | 7da9c509 | Julia Niermann | for(int i=0; i<79; i++){ |
92 | chprintf(stream, "register: 0x%02x, data: 0x%02X \n", 0x00+i, data[i]); |
||
93 | } |
||
94 | adcbcf83 | Julia Niermann | } else {
|
95 | aosUtFailed(stream, &result); |
||
96 | } |
||
97 | |||
98 | 7da9c509 | Julia Niermann | // chprintf(stream, "read x_alignment... \n");
|
99 | // status = p9221r_lld_read_x_alignment(((ut_p9221rdata_t*)ut->data)->PRd, x_alignment, ((ut_p9221rdata_t*)ut->data)->timeout);
|
||
100 | // if (status == APAL_STATUS_SUCCESS) {
|
||
101 | // aosUtPassed(stream, &result);
|
||
102 | // chprintf(stream, "x_alignment %d \n", x_alignment);
|
||
103 | // } else {
|
||
104 | // aosUtFailed(stream, &result);
|
||
105 | // }
|
||
106 | |||
107 | // chprintf(stream, "read y_alignment... \n");
|
||
108 | // status = p9221r_lld_read_y_alignment(((ut_p9221rdata_t*)ut->data)->PRd, y_alignment, ((ut_p9221rdata_t*)ut->data)->timeout);
|
||
109 | // if (status == APAL_STATUS_SUCCESS) {
|
||
110 | // aosUtPassed(stream, &result);
|
||
111 | // chprintf(stream, "y_alignment: %d \n", y_alignment);
|
||
112 | // } else {
|
||
113 | // aosUtFailed(stream, &result);
|
||
114 | // }
|
||
115 | |||
116 | // chprintf(stream, "read the voltage... \n");
|
||
117 | // status = p9221r_lld_read_voltage(const P9221RDriver* const p9221r, int32_t const voltage, const apalTime_t timeout);
|
||
118 | // if (status == APAL_STATUS_SUCCESS) {
|
||
119 | // aosUtPassed(stream, &result);
|
||
120 | // chprintf(stream, "voltage: %d \n", voltage);
|
||
121 | // } else {
|
||
122 | // aosUtFailed(stream, &result);
|
||
123 | // }
|
||
124 | |||
125 | // chprintf(stream, "read the current... \n");
|
||
126 | // status = p9221r_lld_read_current(const P9221RDriver* const p9221r, int32_t const current, const apalTime_t timeout);
|
||
127 | // if (status == APAL_STATUS_SUCCESS) {
|
||
128 | // aosUtPassed(stream, &result);
|
||
129 | // chprintf(stream, "current: %d \n", current);
|
||
130 | // } else {
|
||
131 | // aosUtFailed(stream, &result);
|
||
132 | // }
|
||
133 | b49ed442 | Julia Niermann | |
134 | 8cbe3240 | Julia Niermann | return result;
|
135 | a2cdc4ae | Julia Niermann | } |
136 | da1c10ac | Julia Niermann | #endif /* (AMIROOS_CFG_TESTS_ENABLE == true) && defined(AMIROLLD_CFG_P9221R) && (AMIROLLD_CFG_P9221R == 1) */ |