Skip to content

Commit 5b4f7f3

Browse files
authored
Merge pull request #25 from Embedded-Systems-Spring-2020/master
Pulling in work from Miranda and Andrew
2 parents 71749e7 + 3f6a776 commit 5b4f7f3

File tree

5 files changed

+145
-18
lines changed

5 files changed

+145
-18
lines changed

BUILD_DIR/t4_sensor1.c

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,44 @@
44
#include <p33EP512GP806.h>
55
#include <pic24_all.h>
66
#include <esos_f14ui.h>
7-
7+
#include <esos_comm.h>
88
#include <esos_sensor.h>
99

10+
11+
1012
#include <stdio.h>
1113
#include <stdlib.h>
1214

1315
#define LOOP_DELAY 1000
1416

1517
char buffer[30];
1618
BOOL b_keepLooping = FALSE;
19+
20+
ESOS_CHILD_TASK(barGraph_child, uint16_t u16_num2graph){ //visual display of data
21+
static uint8_t u8_barGraph_value = 0;
22+
static uint8_t i;
23+
static uint8_t j;
24+
ESOS_TASK_BEGIN();
25+
ESOS_TASK_WAIT_ON_SEND_STRING(" |"); //draws a 20 '_' long line with a moving '|'
26+
u8_barGraph_value = u16_num2graph / 50; //max output 2^10 ~= 1000; /50 gives increments of 20
27+
for (i=0; i<u8_barGraph_value; i++){
28+
ESOS_TASK_WAIT_ON_SEND_STRING("_");
29+
}
30+
ESOS_TASK_WAIT_ON_SEND_STRING("|"); //after appropriate '_'s this is the values line
31+
for (j=0; j<(20-u8_barGraph_value); j++){ //finish the 20 '_'s
32+
ESOS_TASK_WAIT_ON_SEND_STRING("_");
33+
}
34+
ESOS_TASK_WAIT_ON_SEND_STRING("|\n");
35+
ESOS_TASK_END();
36+
}
37+
1738
ESOS_USER_TASK(loop) {
1839
static uint16_t u16_data;
19-
40+
static ESOS_TASK_HANDLE th_child; //declare storage for handle to child task
2041
ESOS_TASK_BEGIN();{
2142
for (;;) { //same as while(true)
2243

23-
ESOS_TASK_WAIT_UNTIL(esos_uiF14_isSW1Pressed() || esos_uiF14_isSW2Pressed()); /on either switch, start the DO loop
44+
ESOS_TASK_WAIT_UNTIL(esos_uiF14_isSW1Pressed() || esos_uiF14_isSW2Pressed()); //on either switch, start the DO loop
2445
if (esos_uiF14_isSW2Pressed()){
2546
b_keepLooping = TRUE; //if sw2 then keep looping; checked at the bottom while statement
2647
}
@@ -38,7 +59,12 @@ ESOS_USER_TASK(loop) {
3859
//wait for UART availability to send output to Bully Bootloader
3960
ESOS_TASK_WAIT_ON_AVAILABLE_OUT_COMM();
4061

41-
sprintf(buffer, "%d\n", u16_data);
62+
ESOS_TASK_WAIT_ON_SEND_UINT16_AS_HEX_STRING(u16_data); //extra zeros but acceptable
63+
64+
ESOS_ALLOCATE_CHILD_TASK(th_child);
65+
ESOS_TASK_SPAWN_AND_WAIT(th_child, barGraph_child, u16_data);
66+
67+
ESOS_TASK_WAIT_ON_SEND_STRING("\n");
4268
ESOS_TASK_WAIT_ON_SEND_STRING(buffer); //wait for data in buffer to be sent and release UART
4369
ESOS_TASK_SIGNAL_AVAILABLE_OUT_COMM();
4470
ESOS_TASK_WAIT_TICKS(LOOP_DELAY /2); /*this is half of the 1 second delay between samples
@@ -63,11 +89,14 @@ ESOS_USER_TASK(loop) {
6389
ESOS_TASK_END();
6490
}
6591

92+
6693
void user_init(void){
6794
config_esos_uiF14();
6895

6996
// Config heartbeat
7097
esos_uiF14_flashLED3(500);
7198

7299
esos_RegisterTask(loop);
100+
101+
73102
}

BUILD_DIR/t4_sensor2.c

Lines changed: 71 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
1-
#include <p33EP512GP806.h>
2-
#include <stdio.h>
3-
#include <stdlib.h>
41
#include "pic24_all.h"
5-
#include <string.h>
2+
#include <p33EP512GP806.h>
63
#include "pic24_ports_config.h"
4+
75
#include <esos.h>
8-
#include "esos_pic24.h"
96
#include <esos_task.h>
107
#include "esos_comm.h"
118
#include "esos_f14ui.h"
9+
#include "esos_pic24.h"
1210
#include "esos_sensor.h"
1311

12+
#include <stdio.h>
13+
#include <stdlib.h>
14+
#include <string.h>
15+
16+
#define LOOP_DELAY 1000
1417
#define ONESHOT '1'
1518
#define AVG '2'
1619
#define MIN '3'
@@ -24,7 +27,6 @@
2427
#define SAMPLES64 '6'
2528
#define SAMPLES_ONESHOT '7'
2629

27-
2830
// defined in "esos_sensor.h"
2931
static esos_sensor_process_t sensor_processing_mode;
3032

@@ -39,11 +41,11 @@ ESOS_CHILD_TASK(menu) {
3941

4042
ESOS_TASK_BEGIN();
4143
for (;;) {
42-
ESOS_TASK_WAIT_ON_AVAILABLE_OUT_COMM(); // wait until we can grab the output stream
44+
ESOS_TASK_WAIT_ON_AVAILABLE_OUT_COMM(); // wait until we can grab the output stream
4345
// print a very pretty menu
4446
ESOS_TASK_WAIT_ON_SEND_STRING(
45-
"\n"
46-
"+===========================+\n\
47+
"\n"
48+
"+===========================+\n\
4749
| Select Processing mode |\n\
4850
| 1. one-shot |\n\
4951
| 2. average |\n\
@@ -134,16 +136,71 @@ ESOS_CHILD_TASK(menu) {
134136
ESOS_TASK_END();
135137
}
136138

137-
ESOS_USER_TASK(placeholderTask) {
139+
140+
141+
BOOL b_keepLooping = FALSE;
142+
143+
ESOS_USER_TASK(loop) {
144+
145+
static uint16_t u16_data;
138146
ESOS_TASK_HANDLE th_child;
139147

140-
ESOS_TASK_BEGIN();
141-
ESOS_TASK_SPAWN_AND_WAIT(th_child, menu);
148+
ESOS_TASK_BEGIN(); {
149+
for (;;) {
150+
ESOS_TASK_WAIT_UNTIL(esos_uiF14_isSW1Pressed() || esos_uiF14_isSW2Pressed());
151+
152+
if (esos_uiF14_isSW2Pressed()) {
153+
b_keepLooping = TRUE;
154+
}
155+
156+
else {
157+
b_keepLooping = FALSE;
158+
}
159+
160+
ESOS_TASK_WAIT_UNTIL(esos_uiF14_isSW1Released() && esos_uiF14_isSW2Released());
161+
162+
do {
163+
//claim the ADC
164+
ESOS_TASK_WAIT_ON_AVAILABLE_SENSOR(ESOS_SENSOR_CH02, ESOS_SENSOR_VREF_3V3);
165+
166+
//Now we have exclusive use, grab data
167+
ESOS_TASK_WAIT_SENSOR_QUICK_READ(u16_data);
168+
169+
//Grab the output
170+
ESOS_TASK_WAIT_ON_AVAILABLE_OUT_COMM();
171+
ESOS_TASK_WAIT_ON_SEND_STRING("Hex: ");
172+
ESOS_TASK_WAIT_ON_SEND_UINT32_AS_HEX_STRING(u16_data);
173+
ESOS_TASK_WAIT_ON_SEND_STRING("\n");
174+
ESOS_TASK_SIGNAL_AVAILABLE_OUT_COMM();
175+
176+
ESOS_TASK_WAIT_TICKS(LOOP_DELAY / 2);
177+
178+
if (esos_uiF14_isSW1Pressed()) {
179+
ESOS_TASK_WAIT_UNTIL(esos_uiF14_isSW1Released());
180+
b_keepLooping = FALSE;
181+
}
182+
183+
if (esos_uiF14_isSW2Pressed()) {
184+
ESOS_TASK_WAIT_UNTIL(esos_uiF14_isSW2Released());
185+
b_keepLooping = FALSE;
186+
}
187+
188+
if (esos_uiF14_isSW3Pressed()){ //sw1 will stop the sw2 initiated continous looping
189+
ESOS_TASK_WAIT_UNTIL(esos_uiF14_isSW3Released());
190+
b_keepLooping = FALSE;
191+
ESOS_TASK_SPAWN_AND_WAIT(th_child, menu);
192+
}
193+
ESOS_TASK_WAIT_TICKS(LOOP_DELAY /2); //the other half of the loop sw2 sensor reading delay
194+
}while(b_keepLooping); //keep doing the DO loop if sw2 initiated it
195+
196+
//Release the potentiometer
197+
ESOS_SENSOR_CLOSE();
198+
}
199+
}
142200
ESOS_TASK_END();
143-
144201
}
145202

146203
void user_init(void){
147204
config_esos_uiF14();
148-
esos_RegisterTask(placeholderTask);
205+
esos_RegisterTask(loop);
149206
}

Docs/F14 PCB parts list.xlsx

12.4 KB
Binary file not shown.

esos/include/esos_comm.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ uint8_t __esos_u8_GetLSBHexCharFromUint8(uint8_t u8_x);
5353
ESOS_CHILD_TASK( __esos_OutChar, uint8_t u8_c);
5454
ESOS_CHILD_TASK( __esos_OutUint8AsDecString, uint8_t u8_x);
5555
ESOS_CHILD_TASK( __esos_OutUint8AsHexString, uint8_t u8_x);
56+
ESOS_CHILD_TASK( __esos_OutUint16AsHexString, uint16_t u16_x);
5657
ESOS_CHILD_TASK( __esos_OutUint32AsHexString, uint32_t u32_x);
5758
ESOS_CHILD_TASK( __esos_OutCharBuffer, uint8_t* pu8_out, uint8_t u8_len);
5859
ESOS_CHILD_TASK( __esos_getBuffer, uint8_t* pau8_buff, uint8_t u8_size);
@@ -414,6 +415,19 @@ uint8_t __esos_unsafe_GetUint8(void);
414415
* \sa ESOS_TASK_SPAWN_AND_WAIT
415416
* \hideinitializer
416417
*/
418+
#define ESOS_TASK_WAIT_ON_SEND_UINT16_AS_HEX_STRING( u16_out) \
419+
ESOS_TASK_SPAWN_AND_WAIT( (ESOS_TASK_HANDLE)&__stChildTaskTx, __esos_OutUint16AsHexString, (u16_out) )
420+
421+
422+
/**
423+
* Create, spawn and wait on a child task to put 2 bytes (uint16) to the ESOS "out" communications buffer as a human-readable
424+
* decimal string. Results will look like "253"
425+
*
426+
* \note This call will block the current task until the data is absorbed by the ESOS communications subsystem
427+
* \param u8_out data to write to "out" stream
428+
* \sa ESOS_TASK_SPAWN_AND_WAIT
429+
* \hideinitializer
430+
*/
417431
#define ESOS_TASK_WAIT_ON_SEND_UINT8_AS_DEC_STRING( u8_out) \
418432
ESOS_TASK_SPAWN_AND_WAIT( (ESOS_TASK_HANDLE)&__stChildTaskTx, __esos_OutUint8AsDecString,(u8_out))
419433
/**

esos/src/esos_comm.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,33 @@ ESOS_CHILD_TASK( __esos_OutUint8AsDecString, uint8_t u8_x) {
136136
ESOS_TASK_END();
137137
} // end __esos_OutUint8AsDecString
138138

139+
ESOS_CHILD_TASK( __esos_OutUint16AsHexString, uint16_t u16_x) {
140+
static uint8_t au8_String[11];
141+
static uint8_t u8_c;
142+
static uint16_t u16_tmp;
143+
144+
ESOS_TASK_BEGIN();
145+
au8_String[0] = '0';
146+
au8_String[1] = 'x';
147+
u8_c = (u16_x >> 8);
148+
au8_String[2] = __esos_u8_GetMSBHexCharFromUint8(u8_c);
149+
au8_String[3] = __esos_u8_GetLSBHexCharFromUint8(u8_c);
150+
u8_c = u16_x;
151+
au8_String[4] = __esos_u8_GetMSBHexCharFromUint8(u8_c);
152+
au8_String[5] = __esos_u8_GetLSBHexCharFromUint8(u8_c);
153+
au8_String[6] = 0;
154+
u8_c = 0;
155+
156+
while (u8_c < 6) {
157+
__ESOS_COMM_TXFIFO_PREP();
158+
ESOS_TASK_WAIT_WHILE( u16_tmp == __st_TxBuffer.u16_Tail );
159+
__ESOS_COMM_WRITE_TXFIFO( au8_String[u8_c++] ); //write to buffer
160+
__esos_hw_signal_start_tx();
161+
} //end while()
162+
ESOS_TASK_END();
163+
164+
} // end __esos_OutUint16AsHexString()
165+
139166
ESOS_CHILD_TASK( __esos_OutUint32AsHexString, uint32_t u32_x) {
140167
static uint8_t au8_String[11];
141168
static uint8_t u8_c;

0 commit comments

Comments
 (0)