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_echo1.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>user task</em> that runs simultaneously with the echo task above.
38
*
39
* \note Demonstrates multitasking in ESOS
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
//static uint8_t psz_CRNL[3]= {0x0D, 0x0A, 0};
74
75
76
#ifdef __linux
77
/*
78
* Simulate the timer ISR found on a MCU
79
* The PC doesn't have a timer ISR, so this task will periodically
80
* call the timer services callback instead.
81
* USED ONLY FOR DEVELOPMENT AND TESTING ON PC.
82
* Real MCU hardware doesn't need this task
83
*/
84
ESOS_USER_TASK
( __simulated_isr ) {
85
ESOS_TASK_BEGIN
();
86
while
(
TRUE
) {
87
// call the ESOS timer services callback just like a real H/W ISR would
88
__esos_tmrSvcsExecute();
89
ESOS_TASK_WAIT_TICKS
( 1 );
90
91
}
// endof while(TRUE)
92
ESOS_TASK_END
();
93
}
// end child_task
94
#endif
95
96
/************************************************************************
97
* User supplied functions
98
************************************************************************
99
*/
100
101
/**
102
* An ESOS task to mimic the heartbeat LED found
103
* in the PIC24 support library code used in Chapters 8-13.
104
*
105
* Toggle LED1, wait 250ms, repeat forever.
106
*
107
* \note Since this heartbeat is performed in an ESOS task,
108
* a flashing LED indicates that the ESOS scheduler is still
109
* running properly. If the LED quits flashing, the ESOS
110
* scheduler is no longer rotating through the runnable task
111
* list. The most likely reason is that some task has ceased
112
* "yielding" the processor, and is caught in some deadlock
113
* or otherwise infinite loop.
114
* \hideinitializer
115
*/
116
ESOS_USER_TASK
(heartbeat_LED) {
117
ESOS_TASK_BEGIN
();
118
while
(
TRUE
) {
119
LED1 = !LED1;
120
#ifdef __linux
121
if
(LED1) {
122
printf(
"\a"
);
123
fflush(stdout);
124
}
125
#endif
126
ESOS_TASK_WAIT_TICKS
( 500 );
127
}
// endof while(TRUE)
128
ESOS_TASK_END
();
129
}
// end upper_case()
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
(heartbeat_LED);
177
esos_RegisterTask
(echo1);
178
179
}
// end user_init()
Generated by
1.8.4