Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for %X formatting to osDebugPrintf. #36

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 26 additions & 35 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,55 +1,46 @@
# This is a basic workflow to help you get started with Actions

name: CI

# Controls when the action will run. Triggers the workflow on push or pull request
# events but only for the master branch
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

strategy:
matrix:
target:
- inemom1/accelero
- inemom1/gyro
- inemom1/leds
- inemom1/pwm
- stm32f4discovery/accel
- stm32f4discovery/audio
- stm32f4discovery/leds
- stm32f4discovery/skel
- stm32f4discovery/timerirq
- stm32f429discovery/adcdma
- stm32f429discovery/adcpolling
- stm32f429discovery/button
- stm32f429discovery/gyro
- stm32f429discovery/leds
- stm32f429discovery/spimaster
- stm32f429discovery/spislave
- stm32f429discovery/timerirq
- stm32f429discovery/timerpwm
- mbed-lpc1768/leds

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest

continue-on-error: true

strategy:
matrix:
target:
- inemom1/accelero
- inemom1/gyro
- inemom1/leds
- inemom1/pwm
- stm32f4discovery/accel
- stm32f4discovery/audio
- stm32f4discovery/leds
- stm32f4discovery/skel
- stm32f4discovery/timerirq
- stm32f429discovery/adcdma
- stm32f429discovery/adcpolling
- stm32f429discovery/button
- stm32f429discovery/gyro
- stm32f429discovery/leds
- stm32f429discovery/spimaster
- stm32f429discovery/spislave
- stm32f429discovery/timerirq
- stm32f429discovery/timerpwm
- mbed-lpc1768/leds

container:
image: grumpycoders/uc-sdk-build-env:latest
env:
TARGET: ${{matrix.target}}

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2

# Runs a single command using the runners shell
- name: Build
run: make -C /uC-sdk/examples/$TARGET
run: make -C examples/$TARGET
19 changes: 15 additions & 4 deletions os/src/osdebug.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@
#include <BoardConsole.h>
#include <osdebug.h>

static const char hex_conv[] = "0123456789ABCDEF";
static const char *hex_conv[2] =
{
"0123456789abcdef", // lower-case
"0123456789ABCDEF" // upper-case
};

static void dbgput(const void * _str, int n) {
const char * str = (const char *) _str;
while(n--)
Expand All @@ -29,6 +34,7 @@ void osDbgPrintf(const char * str, ...) {
long arg_i;
uintptr_t arg_p;
int str_size, i;
int ucase = 0;

va_start(ap, str);

Expand Down Expand Up @@ -75,7 +81,7 @@ void osDbgPrintf(const char * str, ...) {
tmp_conv_ptr = tmp_n_conv + 32;
*tmp_conv_ptr = 0;
do {
*--tmp_conv_ptr = hex_conv[arg_u % 10];
*--tmp_conv_ptr = hex_conv[0][arg_u % 10];
arg_u /= 10;
} while (arg_u);
dbgput(tmp_conv_ptr, strlen(tmp_conv_ptr));
Expand All @@ -84,20 +90,25 @@ void osDbgPrintf(const char * str, ...) {
arg_p = va_arg(ap, uintptr_t);
dbgput("0x", 2);
for (i = sizeof(arg_p) * 2 - 1; i >= 0; i--) {
dbgput(&hex_conv[(arg_p >> (i << 2)) & 15], 1);
dbgput(&hex_conv[1][(arg_p >> (i << 2)) & 15], 1);
}
break;
case 'X': // same as x but uppercase for alpha chars
ucase = 1;
// fall through
case 'x':
arg_u = va_arg(ap, unsigned long);
seen_something = 0;
const char *hex_p = hex_conv[ucase];
for (i = sizeof(arg_p) * 2 - 1; i >= 0; i--) {
if (!seen_something && ((arg_u >> (i << 2)) == 0))
continue;
dbgput(&hex_conv[(arg_u >> (i << 2)) & 15], 1);
dbgput(&hex_p[(arg_u >> (i << 2)) & 15], 1);
seen_something = 1;
}
if (!seen_something)
dbgput("0", 1);
ucase = 0;
break;
case 0: // malformed format string with a trailing %.
dbgput("%", 1);
Expand Down