Move small functions into main, rm hello worlds

This commit is contained in:
Aadi Desai 2023-05-12 20:07:39 +01:00
parent 5f657cb46b
commit bf9a03f9d2
No known key found for this signature in database
7 changed files with 51 additions and 90 deletions

View file

@ -3,8 +3,7 @@ BUILD_DIR?=../build/
include $(BUILD_DIR)/software/include/generated/variables.mak
include $(SOC_DIRECTORY)/software/common.mak
OBJECTS = donut.o helloc.o crt0.o main.o
OBJECTS += hellocpp.o leds.o audio.o
OBJECTS = crt0.o donut.o led.o main.o
CFLAGS += -DWITH_CXX

View file

@ -1,6 +0,0 @@
#include <generated/csr.h>
#include <stdio.h>
void audio(int v) {
audio_targ_write(v);
}

View file

@ -1,5 +0,0 @@
#include <stdio.h>
void helloc(void) {
printf("C: Hello, world!\n");
}

View file

@ -1,5 +0,0 @@
#include <stdio.h>
void hellocpp(void) {
printf("C++: Hello, world!\n");
}

40
demo/led.cpp Normal file
View file

@ -0,0 +1,40 @@
#include <generated/csr.h>
#include <stdio.h>
void led(void) {
int i;
int j;
int k;
printf("Led demo...\n");
printf("Counter mode...\n");
for (i = 0; i < 4; i++) {
for (j = 0; j < 4; j++) {
for (k = 0; k < 4; k++) {
leds_out_write(0x3F0000 * i + 0x003F00 * j + 0x00003F * k);
busy_wait(100);
}
}
}
printf("Shift mode...\n");
for (i = 0; i < 24; i++) {
leds_out_write(1 << i);
busy_wait(100);
}
for (i = 0; i < 24; i++) {
leds_out_write(1 << (23 - i));
busy_wait(100);
}
printf("Dance mode...\n");
for (i = 0; i < 16; i++) {
leds_out_write(0x000055);
busy_wait(200);
leds_out_write(0xAAAA00);
busy_wait(200);
}
printf("Clearing led...\n");
leds_out_write(0);
}

View file

@ -1,6 +0,0 @@
#include <generated/csr.h>
#include <stdio.h>
void leds(int v) {
leds_out_write(v);
}

View file

@ -73,7 +73,7 @@ static void prompt(void) {
/*-----------------------------------------------------------------------*/
/* Help */
/*-----------------------------------------------------------------------*/
// void audio_targ_write(uint32_t v)
static void help(void) {
puts("\nLiteX custom demo app built " __DATE__
" " __TIME__
@ -85,13 +85,11 @@ static void help(void) {
puts("led - Led demo");
#endif
puts("donut - Spinning Donut demo");
puts("helloc - Hello C");
puts("hellocpp - Hello C++");
#ifdef CSR_LEDS_BASE
puts("leds - Led set demo");
#endif
#ifdef CSR_AUDIO_BASE
puts("audio - Sawtooth Audio demo");
puts("saw - Sawtooth Audio demo");
#endif
}
@ -104,61 +102,25 @@ static void reboot_cmd(void) {
}
#ifdef CSR_LEDS_BASE
void led(void);
static void led_cmd(void) {
int i;
int j;
int k;
printf("Led demo...\n");
printf("Counter mode...\n");
for (i = 0; i < 4; i++) {
for (j = 0; j < 4; j++) {
for (k = 0; k < 4; k++) {
leds_out_write(0x3F0000 * i + 0x003F00 * j + 0x00003F * k);
busy_wait(100);
}
}
}
printf("Shift mode...\n");
for (i = 0; i < 24; i++) {
leds_out_write(1 << i);
busy_wait(100);
}
for (i = 0; i < 24; i++) {
leds_out_write(1 << (23 - i));
busy_wait(100);
}
printf("Dance mode...\n");
for (i = 0; i < 16; i++) {
leds_out_write(0x000055);
busy_wait(200);
leds_out_write(0xAAAA00);
busy_wait(200);
}
printf("Clearing led...\n");
leds_out_write(0);
led();
}
#endif
#ifdef CSR_LEDS_BASE
void leds(int);
static void leds_cmd(char **val) {
int value = (int)strtol(get_token(val), NULL, 0);
printf("Setting LED to %6x\n", value);
leds(value);
leds_out_write(value);
}
#endif
#ifdef CSR_AUDIO_BASE
void audio(int);
static void audio_cmd(char **val) {
static void saw_cmd(char **val) {
int value = (int)strtol(get_token(val), NULL, 0);
printf("Setting Sawtooth to %dHz\n", value);
audio(value);
audio_targ_write(value);
}
#endif
@ -169,20 +131,6 @@ static void donut_cmd(void) {
donut();
}
void helloc(void);
static void helloc_cmd(void) {
printf("Hello C demo...\n");
helloc();
}
void hellocpp(void);
static void hellocpp_cmd(void) {
printf("Hello C++ demo...\n");
hellocpp();
}
/*-----------------------------------------------------------------------*/
/* Console service / Main */
/*-----------------------------------------------------------------------*/
@ -205,17 +153,13 @@ static void console_service(void) {
#endif
else if (strcmp(token, "donut") == 0)
donut_cmd();
else if (strcmp(token, "helloc") == 0)
helloc_cmd();
else if (strcmp(token, "hellocpp") == 0)
hellocpp_cmd();
#ifdef CSR_LEDS_BASE
else if (strcmp(token, "leds") == 0)
leds_cmd(&str);
#endif
#ifdef CSR_AUDIO_BASE
else if (strcmp(token, "audio") == 0)
audio_cmd(&str);
else if (strcmp(token, "saw") == 0)
saw_cmd(&str);
#endif
prompt();
}