Skip to content

Commit 3f6a776

Browse files
authored
Merge pull request #24 from Embedded-Systems-Spring-2020/yingst
Hex16 print functionality
2 parents 1269b3e + 8c805b5 commit 3f6a776

File tree

4 files changed

+74
-4
lines changed

4 files changed

+74
-4
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
}

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)