summaryrefslogtreecommitdiff
path: root/boards/ek-tm4c1294xl/hibernate/hibernate_commands.c
blob: 93864ac360182a6fe2da57049baeebfbd4406b8f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
//*****************************************************************************
//
// hibernate_commands.c - Command line functionality for Hibernate Example.
//
// Copyright (c) 2013-2014 Texas Instruments Incorporated.  All rights reserved.
// Software License Agreement
// 
// Texas Instruments (TI) is supplying this software for use solely and
// exclusively on TI's microcontroller products. The software is owned by
// TI and/or its suppliers, and is protected under applicable copyright
// laws. You may not combine this software with "viral" open-source
// software in order to form a larger program.
// 
// THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL FAULTS.
// NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT
// NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. TI SHALL NOT, UNDER ANY
// CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
// DAMAGES, FOR ANY REASON WHATSOEVER.
// 
// This is part of revision 2.1.0.12573 of the EK-TM4C1294XL Firmware Package.
//
//*****************************************************************************

#include <stdint.h>
#include <stdbool.h>
#include "inc/hw_types.h"
#include "utils/ustdlib.h"
#include "utils/uartstdio.h"
#include "utils/cmdline.h"
#include "hibernate_commands.h"

//*****************************************************************************
//
// Hibernate request flag.  Indicates that the user wishes to enter hibernate.
//
//*****************************************************************************
extern bool g_bHibernate;

//*****************************************************************************
//
// Variables that keep track of the date and time.
//
//*****************************************************************************
extern uint32_t g_ui32MonthIdx, g_ui32DayIdx, g_ui32YearIdx;
extern int32_t g_ui32HourIdx, g_ui32MinIdx;

//*****************************************************************************
//
// Variables that keep terminal display position and status.
//
//*****************************************************************************
extern bool g_bFirstUpdate;
extern uint8_t g_ui8FirstLine;

//*****************************************************************************
//
// Function prototype for setting the system date/time.
//
//*****************************************************************************
extern void DateTimeSet(void);

//*****************************************************************************
//
// Table of valid command strings, callback functions and help messages.  This
// is used by the cmdline module.
//
//*****************************************************************************
tCmdLineEntry g_psCmdTable[] =
{
    {"help",   CMD_help,   " : Display list of commands." },
    {"hib",    CMD_hib,    " : Place system into hibernate mode."},
    {"date",   CMD_date,   " : Set Date \"DD/MM/YYYY\"."},
    {"time12", CMD_time12, " : Set Time 12HR style \"HH:MM:XX\" "
                           "XX = AM or PM"},
    {"time24", CMD_time24, " : Set Time 24HR style \"HH:MM\"."},
    {"cls",    CMD_cls,    " : Clear the terminal screen"},
    { 0, 0, 0 }
};

//*****************************************************************************
//
// Command: cls
//
// Clear the terminal screen.
//
//*****************************************************************************
int
CMD_cls(int argc, char **argv)
{
    UARTprintf("\033[2J\033[H");
    g_bFirstUpdate = true;
    g_ui8FirstLine = 1;
    return (0);
}

//*****************************************************************************
//
// Command: help
//
// Print the help strings for all commands.
//
//*****************************************************************************
int
CMD_help(int argc, char **argv)
{
    int32_t i32Index;

    //
    // Keep the compiler happy.
    //
    (void)argc;
    (void)argv;

    //
    // Start at the beginning of the command table
    //
    i32Index = 0;

    //
    // Get to the start of a clean line on the serial output.
    //
    UARTprintf("\nAvailable Commands\n------------------\n\n");

    //
    // Display strings until we run out of them.
    //
    while(g_psCmdTable[i32Index].pcCmd)
    {
      UARTprintf("%17s %s\n", g_psCmdTable[i32Index].pcCmd,
                 g_psCmdTable[i32Index].pcHelp);
      i32Index++;
    }

    //
    // Leave a blank line after the help strings.
    //
    UARTprintf("\n");

    return (0);
}

//*****************************************************************************
//
// Command: hib
//
// Request the device enter hibernate mode now.
//
//*****************************************************************************
int
CMD_hib(int argc, char **argv)
{
    //
    // Keep the compiler happy.
    //
    (void)argc;
    (void)argv;

    //
    // Request Application to enter hibernate state.
    //
    g_bHibernate = true;

    return (0);
}

//*****************************************************************************
//
// Command: date
//
// Set the current system date.  Use format "DD/MM/YYYY"
//
//*****************************************************************************
int
CMD_date(int argc, char **argv)
{
    const char *pcNext;

    //
    // Check the argument count and return errors for too many or too few.
    //
    if(argc == 1)
    {
        return(CMDLINE_TOO_FEW_ARGS);
    }
    if(argc > 2)
    {
        return(CMDLINE_TOO_MANY_ARGS);
    }

    //
    // Convert the date to unsigned long
    //
    g_ui32DayIdx = ustrtoul(argv[1], &pcNext, 10);
    g_ui32MonthIdx = ustrtoul(pcNext+1, &pcNext, 10) - 1;
    g_ui32YearIdx = (ustrtoul(pcNext+1, NULL, 10) - 2000);

    //
    // Perform the conversions to a time struct and store in the hibernate
    // module after doing a minimal amount of validation.
    //
    if((g_ui32DayIdx > 31) || (g_ui32MonthIdx > 11))
    {
        return(CMDLINE_INVALID_ARG);
    }

    DateTimeSet();

    return(0);
}

//*****************************************************************************
//
//Command: time12
//
// Set the current system time.  Use format "HH:MM:SS:X" Where X is 'A' or 'P'
// for AM or PM. HH is hours. MM is minutes. SS is seconds.
//
//*****************************************************************************
int
CMD_time12(int argc, char **argv)
{
    const char *pcNext;

    //
    // Check the argument count and return errors for too many or too few.
    //
    if(argc == 1)
    {
        return(CMDLINE_TOO_FEW_ARGS);
    }
    if(argc > 2)
    {
        return(CMDLINE_TOO_MANY_ARGS);
    }

    //
    // Convert the user string to unsigned long hours and minutes.
    //
    g_ui32HourIdx = ustrtoul(argv[1], &pcNext, 10);
    g_ui32MinIdx = ustrtoul(pcNext + 1, &pcNext, 10);

    //
    // Accomodate the PM vs AM modification.  All times are stored internally
    // as 24 hour format.
    //
    if(ustrncmp(pcNext + 1, "PM", 2) == 0)
    {
        if(g_ui32HourIdx < 12)
        {
            g_ui32HourIdx += 12;
        }
    }
    else
    {
        if(g_ui32HourIdx > 11)
        {
            g_ui32HourIdx -= 12;
        }
    }

    //
    // Perform the conversions to a time struct and store in the hibernate
    // module.  Also do some minimal checking on the input data.
    //
    if((g_ui32HourIdx < 24) && (g_ui32MinIdx < 60))
    {
        DateTimeSet();
    }

    return(0);
}

//*****************************************************************************
//
//Command: time24
//
// Set the current system time. Use format "HH:MM:SS"
//
//*****************************************************************************
int
CMD_time24(int argc, char **argv)
{
    const char *pcNext;

    //
    // Check the argument count and return errors for too many or too few.
    //
    if(argc == 1)
    {
        return(CMDLINE_TOO_FEW_ARGS);
    }
    if(argc > 2)
    {
        return(CMDLINE_TOO_MANY_ARGS);
    }

    //
    // Convert the user string to unsigned long hours and minutes.
    //
    g_ui32HourIdx = ustrtoul(argv[1], &pcNext, 10);
    g_ui32MinIdx = ustrtoul(pcNext + 1, NULL, 10);

    //
    // Perform the conversions to a time struct and store in the hibernate
    // module.  Also do some minimal checking on the input data.
    //
    if((g_ui32HourIdx < 24) && (g_ui32MinIdx < 60))
    {
        DateTimeSet();
    }

    return(0);
}