Commit 1dee6a77 authored by Christian Eichler's avatar Christian Eichler
Browse files

Implement output of SERIAL in `command_inf`

parent ff3dbd9d
......@@ -41,7 +41,7 @@ ifneq ($(JLINKSER),0)
JLINKSERSTR=-SelectEmuBySN ${JLINKSER}
endif
JLFLAGS = -device XMC4500-1024 -if SWD -speed 300 ${JLINKSERSTR}
JLFLAGS = -device XMC4500-1024 -if SWD -speed 900 ${JLINKSERSTR}
CFLAGS = -target armv6m--none-eabi -mcpu=cortex-m4 -mthumb -integrated-as -ccc-gcc-name arm-none-eabi-gcc
# CFLAGS = -g
......@@ -49,6 +49,9 @@ CFLAGS = -target armv6m--none-eabi -mcpu=cortex-m4 -mthumb -integrated-as -ccc-g
CFLAGS+= -O0 -ffunction-sections -fdata-sections
CFLAGS+= -MD -std=c99 -Wall -fms-extensions
CFLAGS+= -DUC_ID=$(UC_ID) -DARM_MATH_CM4 -DINTERRUPT_CONTROL_ENDPOINT
ifneq ($(JLINKSER),0)
CFLAGS+= -DSERIAL=${JLINKSER}
endif
CFLAGS+= -fmessage-length=0
CFLAGS+= -DXMC4500_F100x1024
CFLAGS+= -I$(CMSIS)/Include -I$(CMSIS)/Infineon/$(UC)_series/Include
......
/* main.c */
#include <stdint.h>
#include <stdlib.h>
......@@ -12,6 +11,17 @@
#define IHANDLER __attribute__ ((naked))
#define xstr(s) str(s)
#define str(s) #s
#ifdef SERIAL
#define SERIALSTR xstr(SERIAL)
#else
#define SERIALSTR "<none>"
#endif
extern int errno;
void _init() {}
/* Clock configuration */
......@@ -47,7 +57,7 @@ void SystemCoreClockSetup(void)
}
void gene_main(int);
void gene_main(uint32_t);
void gene_init(void);
IHANDLER void PendSV_Handler() { P1_1_set(); while(1) {} }
......@@ -60,6 +70,7 @@ IHANDLER void UsageFault_Handler() { P1_1_set(); while(1) {} }
IHANDLER void BusFault_Handler() {
//__asm volatile("ldr sp,=__initial_sp; isb");
timer_stop();
P1_0_reset();
while(true) {
......@@ -69,17 +80,27 @@ IHANDLER void BusFault_Handler() {
}
static void uint64_to_string(char *buf, uint64_t value) {
int digits = 0;
for(uint64_t val = value; val; ++digits, val /= 10);
buf[digits] = '\0';
for(size_t i = digits; i--; value /= 10) {
buf[i] = '0' + (value % 10);
if(0 == value) {
buf[0] = '0';
buf[1] = '\0';
} else {
int digits = 0;
for(uint64_t val = value; val; ++digits, val /= 10);
buf[digits] = '\0';
for(size_t i = digits; i--; value /= 10) {
buf[i] = '0' + (value % 10);
}
}
}
static void command_bch(char *arg) {
int val = atoi(arg);
errno = 0;
unsigned long long val = strtoull(arg, NULL, 10);
if(0 != errno || val > (unsigned long long) UINT32_MAX) {
CDC_Device_SendString(&VirtualSerial_CDC_Interface, "e:ov\n");
CDC_Device_Flush(&VirtualSerial_CDC_Interface);
return;
}
CDC_Device_SendString(&VirtualSerial_CDC_Interface, "o:start\r");
CDC_Device_Flush(&VirtualSerial_CDC_Interface);
......@@ -98,8 +119,9 @@ static void command_bch(char *arg) {
P1_0_toggle();
CDC_Device_SendString(&VirtualSerial_CDC_Interface, "o:end ");
CDC_Device_USBTask(&VirtualSerial_CDC_Interface);
char buf[64];
char buf[64] = {0};
uint64_to_string(buf, cycles);
CDC_Device_SendString(&VirtualSerial_CDC_Interface, buf);
CDC_Device_SendString(&VirtualSerial_CDC_Interface, "\n");
......@@ -128,9 +150,10 @@ static void command_eic(char *arg) {
static void command_inf(char *arg) {
CDC_Device_SendString(&VirtualSerial_CDC_Interface, "o:id " SERIALSTR "\r");
// send FREQUENCY
char buf[128] = {0};
// itoa(SystemCoreClock, buf, 10);
uint64_to_string(buf, SystemCoreClock);
CDC_Device_SendString(&VirtualSerial_CDC_Interface, "o:freq ");
CDC_Device_SendString(&VirtualSerial_CDC_Interface, buf);
......@@ -236,6 +259,7 @@ int main(void) {
++pos;
} else {
CDC_Device_SendString(&VirtualSerial_CDC_Interface, "e:OVERFLOW IN COMMAND BUFFER\n");
CDC_Device_Flush(&VirtualSerial_CDC_Interface);
pos = 0;
}
......
......@@ -153,6 +153,8 @@ static void resp_inf(bool success, char *resp) {
printf("Instruction Cache: Currently %s", ('e' == *rem) ? "enabled" : "disabled");
} else if(rem = strsw(resp, "ov ")) {
printf("Timer Overflow Detection: Currently %s", ('e' == *rem) ? "enabled" : "disabled");
} else if(rem = strsw(resp, "id ")) {
printf("Device ID: %s", rem);
} else {
printf("Unparsed: %s", resp);
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment