PIC24 Support Libraries
Main Page
Related Pages
Modules
Data Structures
Files
File List
Globals
All
Data Structures
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Macros
Groups
Pages
chap14
app_timerLEDecho.c
Go to the documentation of this file.
1
/*
2
* "Copyright (c) 2008 Robert B. Reese, Bryan A. Jones, J. W. Bruce ("AUTHORS")"
3
* All rights reserved.
4
* (R. Reese, reese_AT_ece.msstate.edu, Mississippi State University)
5
* (B. A. Jones, bjones_AT_ece.msstate.edu, Mississippi State University)
6
* (J. W. Bruce, jwbruce_AT_ece.msstate.edu, Mississippi State University)
7
*
8
* Permission to use, copy, modify, and distribute this software and its
9
* documentation for any purpose, without fee, and without written agreement is
10
* hereby granted, provided that the above copyright notice, the following
11
* two paragraphs and the authors appear in all copies of this software.
12
*
13
* IN NO EVENT SHALL THE "AUTHORS" BE LIABLE TO ANY PARTY FOR
14
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
15
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE "AUTHORS"
16
* HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
17
*
18
* THE "AUTHORS" SPECIFICALLY DISCLAIMS ANY WARRANTIES,
19
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
20
* AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
21
* ON AN "AS IS" BASIS, AND THE "AUTHORS" HAS NO OBLIGATION TO
22
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
23
*
24
* Please maintain this header in its entirety when copying/modifying
25
* these files.
26
*
27
*
28
*/
29
30
/** \file
31
* ESOS application program to recreate the "Echo" program \ref echo.c
32
* in Chapter 8. (See Figure 8.6 in the text.)
33
* "Echo" program which waits for UART1 RX character and echos it back +1.
34
* Use this program to test your UART connection under ESOS
35
*
36
* Application also has a flashing LED on RB15. Flashing LED is generated
37
* by an <em>software timer</em> calling a user-provided callback function.
38
*
39
* \note Demonstrates ESOS software timers
40
*/
41
42
43
// INCLUDEs go here (First include the main esos.h file)
44
// After that, the user can include what they need
45
#include "
esos.h
"
46
#ifdef __linux
47
#include "esos_pc.h"
48
#include "esos_pc_stdio.h"
49
50
// INCLUDE these so that printf() and our PC hacks work
51
#include <stdio.h>
52
#include <sys/select.h>
53
#include <termios.h>
54
#include <unistd.h>
55
#else
56
#include "
esos_pic24.h
"
57
#include "
esos_pic24_rs232.h
"
58
#endif
59
60
// DEFINEs go here
61
#ifndef __linux
62
#define CONFIG_LED1() CONFIG_RB15_AS_DIG_OUTPUT()
63
#define LED1 _LATB15
64
#else
65
#define CONFIG_LED1() printf("called CONFIG_LED1()\n");
66
uint8_t
LED1 =
TRUE
;
// LED1 is initially "on"
67
#endif
68
69
// PROTOTYPEs go here
70
71
// GLOBALs go here
72
// Generally, the user-created semaphores will be defined/allocated here
73
const
char
psz_CRNL[3]= {0x0D, 0x0A, 0};
74
75
#ifdef __linux
76
/*
77
* Simulate the timer ISR found on a MCU
78
* The PC doesn't have a timer ISR, so this task will periodically
79
* call the timer services callback instead.
80
* USED ONLY FOR DEVELOPMENT AND TESTING ON PC.
81
* Real MCU hardware doesn't need this task
82
*/
83
ESOS_USER_TASK
( __simulated_isr ) {
84
ESOS_TASK_BEGIN
();
85
while
(
TRUE
) {
86
// call the ESOS timer services callback just like a real H/W ISR would
87
__esos_tmrSvcsExecute();
88
ESOS_TASK_WAIT_TICKS
( 1 );
89
90
}
// endof while(TRUE)
91
ESOS_TASK_END
();
92
}
// end child_task
93
#endif
94
95
/************************************************************************
96
* User supplied functions
97
************************************************************************
98
*/
99
100
/*
101
* An ESOS software timer callback function strobe the heartbeat LED.
102
*
103
* Toggles LED1 everytime the callback is called. Exact period is
104
* determined by application when this timer callback function is
105
* registered with ESOS. See \ref esos_RegisterTimer
106
* Application can change timer period on-the-fly with \ref esos_ChangeTimerPeriod
107
*
108
* \note Since this heartbeat is performed in an ESOS software
109
* timer callabck, a flashing LED indicates that the ESOS system
110
* tick ISR is being called properly. If the LED quits flashing,
111
* then the ESOS system tick has ceased working. This probably indicates
112
* some catastrophic failure of the system. However, the cause could
113
* be poorly-behaved user code that is manipulating the hardware registers
114
* with the timer or interrupt enables directly. ESOS provides functions
115
* to change state of interrupts and user code should never modify the
116
* hardware used by ESOS to implement the system tick.
117
* \hideinitializer
118
*/
119
120
// user-created timer callback
121
ESOS_USER_TIMER
( swTimerLED ) {
122
LED1 = !LED1;
123
#ifdef __linux
124
if
(LED1) {
125
printf(
"\a"
);
126
fflush(stdout);
127
}
128
#endif
129
}
//endof swTimerLED
130
131
/*
132
* Read a single character from the "in" stream, increment
133
* that character by one, and echo it back out the "out" stream
134
*/
135
ESOS_USER_TASK
(echo1) {
136
static
uint8_t
u8_char;
137
138
ESOS_TASK_BEGIN
();
139
while
(
TRUE
) {
140
ESOS_TASK_WAIT_ON_AVAILABLE_IN_COMM
();
141
ESOS_TASK_WAIT_ON_GET_UINT8
( u8_char );
142
ESOS_TASK_SIGNAL_AVAILABLE_IN_COMM
();
143
u8_char++;
144
ESOS_TASK_WAIT_ON_AVAILABLE_OUT_COMM
();
145
ESOS_TASK_WAIT_ON_SEND_UINT8
( u8_char );
146
ESOS_TASK_SIGNAL_AVAILABLE_OUT_COMM
();
147
}
// endof while(TRUE)
148
ESOS_TASK_END
();
149
}
// end upper_case()
150
151
/****************************************************
152
* user_init()
153
****************************************************
154
*/
155
void
user_init
(
void
) {
156
157
// Call the hardware-provided routines to print the
158
// HELLO_MSG to the screen. Must use this call because
159
// the ESOS communications subsystems is not yet fully
160
// initialized, since this call is in user_init()
161
//
162
// In general, users should call hardware-specific
163
// function like this.
164
__esos_unsafe_PutString( HELLO_MSG );
165
166
#ifdef __linux
167
// register our little ESOS task to mimic MCU's TIMER T1 IRQ which kicks off
168
// the ESOS S/W timers when they expire
169
esos_RegisterTask
( __simulated_isr );
170
#endif
171
172
// configure our hardware to support to support our application
173
CONFIG_LED1();
174
175
// user_init() should register at least one user task
176
esos_RegisterTask
(echo1);
177
178
// register our callback function with ESOS to create a software timer
179
esos_RegisterTimer
( swTimerLED, 250 );
180
181
}
// end user_init()
Generated by
1.8.4