Add initial emulator implementation

replace/3aca83f848de1c840584296f6196921c96af7613
Fred 2020-11-17 15:44:06 +01:00
rodzic 1639ddf174
commit e917738516
5 zmienionych plików z 224 dodań i 14 usunięć

Wyświetl plik

@ -106,7 +106,8 @@ stm32f405_def = {'STM32F40_41xxx': '', 'HSE_VALUE':'8000000'}
##
## Linux
linux_src = src + ['platform/drivers/display/display_libSDL.c',
linux_src = src + ['platform/targets/linux/emulator/emulator.c',
'platform/drivers/display/display_libSDL.c',
'platform/drivers/keyboard/keyboard_linux.c',
'platform/mcu/x86_64/drivers/gpio.c',
'platform/mcu/x86_64/drivers/delays.c',
@ -121,7 +122,8 @@ linux_def = def + {'SCREEN_WIDTH': '160', 'SCREEN_HEIGHT': '128', 'PIX_FMT_RGB56
linux_inc = inc + ['rtos/uC-OS3/Ports/POSIX',
'rtos/uC-CPU/Posix',
'platform/targets/linux']
'platform/targets/linux',
'platform/targets/linux/emulator']
if not meson.is_cross_build()
sdl_dep = dependency('SDL2')
@ -171,7 +173,7 @@ mduv380_def = def + stm32f405_def
## Compilation defines
##
linux_c_args = []
linux_l_args = ['--entry=systemBootstrap']
linux_l_args = ['--entry=entry']
# Add AddressSanitizer if required
if get_option('asan')

Plik binarny nie jest wyświetlany.

Po

Szerokość:  |  Wysokość:  |  Rozmiar: 1.9 MiB

Wyświetl plik

@ -0,0 +1,152 @@
/***************************************************************************
* Copyright (C) 2020 by Federico Amedeo Izzo IU2NUO, *
* Niccolò Izzo IU2KIN *
* Frederik Saraci IU2NRO *
* Silvano Seva IU2KWO *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, see <http://www.gnu.org/licenses/> *
***************************************************************************/
#include "emulator.h"
#include <pthread.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
void systemBootstrap();
int CLIMenu() {
int choice = 0;
printf("Select the value to change:\n");
printf("1 -> RSSI\n");
printf("2 -> Vbat\n");
printf("3 -> Mic Level\n");
printf("4 -> Volume Level\n");
printf("5 -> Channel selector\n");
printf("6 -> Toggle PTT\n");
printf("7 -> Print current state\n");
printf("8 -> Exit\n");
printf("> ");
do {
scanf("%d", &choice);
} while (choice < 1 || choice > 7);
printf("\e[1;1H\e[2J");
return choice;
}
void *updateValue(float *curr_value) {
printf("Current value: %f\n", *curr_value);
printf("New value: \n");
scanf("%f", curr_value);
}
void *printState() {
printf("\nCurrent state\n");
printf("RSSI : %f\n", Radio_State.RSSI);
printf("Battery: %f\n", Radio_State.Vbat);
printf("Mic : %f\n", Radio_State.micLevel);
printf("Volume : %f\n", Radio_State.volumeLevel);
printf("Channel: %f\n", Radio_State.chSelector);
printf("PTT : %s\n\n", Radio_State.PttStatus ? "true" : "false");
}
void *startRadio() {
systemBootstrap();
}
//void *startGUI();
void *startCLIMenu() {
int choice;
do {
choice = CLIMenu();
switch (choice) {
case VAL_RSSI:
updateValue(&Radio_State.RSSI);
break;
case VAL_BAT:
updateValue(&Radio_State.Vbat);
break;
case VAL_MIC:
updateValue(&Radio_State.micLevel);
break;
case VAL_VOL:
updateValue(&Radio_State.volumeLevel);
break;
case VAL_CH:
updateValue(&Radio_State.chSelector);
break;
case VAL_PTT:
Radio_State.PttStatus = Radio_State.PttStatus ? false : true;
break;
case PRINT_STATE:
printState();
break;
default:
continue;
}
} while (choice != EXIT);
printf("exiting\n");
SDL_Quit();
SDL_DestroyWindow(window);
exit(0);
};
int emulator_main() {
Radio_State = (radio_state){12, 7, 3, 4, 1, false};
pthread_t gui_thread, cli_thread, radio_thread;
int err1, err2;
err1 = pthread_create(&cli_thread, NULL, startCLIMenu, NULL);
//err2 = pthread_create(&gui_thread, NULL, startGUI, NULL);
if (err1) {
printf("An error occurred starting the threads: %d, %d\n", err1, err2);
return 1;
}
//pthread_join(gui_thread, NULL);
pthread_create(&radio_thread, NULL, startRadio, NULL);
pthread_join(cli_thread, NULL);
printf("73\n");
return 0;
}
void *entry() {
__asm__(
"xorl %ebp, %ebp\n\t"
"mov %RDX, %R9\n\t"
#ifdef __ILP32__
"mov (%rsp), %esi\n\t"
"add $4, %esp\n\t"
#else
"popq %rsi\n\t"
#endif
"mov %RSP, %RDX\n\t"
"and $~15, %RSP\n\t"
"pushq %rax\n\t"
"pushq %rsp\n\t"
"mov __libc_csu_fini@GOTPCREL(%rip), %R8\n\t"
"mov __libc_csu_init@GOTPCREL(%rip), %RCX\n\t"
"mov emulator_main@GOTPCREL(%rip), %RDI\n\t"
"call *__libc_start_main@GOTPCREL(%rip)\n\t"
"hlt\n\t");
}

Wyświetl plik

@ -0,0 +1,59 @@
/***************************************************************************
* Copyright (C) 2020 by Federico Amedeo Izzo IU2NUO, *
* Niccolò Izzo IU2KIN *
* Frederik Saraci IU2NRO *
* Silvano Seva IU2KWO *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, see <http://www.gnu.org/licenses/> *
***************************************************************************/
#include <stdbool.h>
#include <stdint.h>
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#ifndef SCREEN_WIDTH
#define SCREEN_WIDTH 160
#endif
#ifndef SCREEN_HEIGHT
#define SCREEN_HEIGHT 128
#endif
SDL_Renderer *renderer; /* SDL renderer */
SDL_Window *window; /* SDL window */
SDL_Texture *displayTexture; /* SDL rendering surface */
enum choices {
VAL_RSSI=1,
VAL_BAT,
VAL_MIC,
VAL_VOL,
VAL_CH,
VAL_PTT,
PRINT_STATE,
EXIT
};
typedef struct {
float RSSI;
float Vbat;
float micLevel;
float volumeLevel;
float chSelector;
bool PttStatus;
} radio_state;
radio_state Radio_State;

Wyświetl plik

@ -18,10 +18,11 @@
#include "platform.h"
#include "gpio.h"
#include <stdio.h>
#include "emulator.h"
void platform_init()
{
printf("Platform init\n");
//printf("Platform init\n");
}
void platform_terminate()
@ -31,36 +32,32 @@ void platform_terminate()
void platform_setBacklightLevel(uint8_t level)
{
printf("platform_setBacklightLevel(%u)\n", level);
//printf("platform_setBacklightLevel(%u)\n", level);
}
// Simulate a fully charged lithium battery
float platform_getVbat(){
return 7.8;
return Radio_State.Vbat;
}
float platform_getMicLevel(){
printf("platform_getMicLevel()\n");
return 0.69;
return Radio_State.micLevel;
}
float platform_getVolumeLevel(){
printf("platform_getVolumeLevel()\n");
return 0.69;
return Radio_State.volumeLevel;
}
uint8_t platform_getChSelector(){
printf("platform_getChSelector()\n");
return 42;
return Radio_State.chSelector;
}
bool platform_getPttStatus(){
printf("platform_getVbat()\n");
return true;
return Radio_State.PttStatus;
}