Adapted MK22 vcom sources to miosix kernel but not activating it. Reconfigured x86 emulator.

replace/9f06b6bd0a034d4cca6d9cffeafa43faff7d1abe
Silvano Seva 2021-03-12 14:15:27 +01:00
rodzic a02b693843
commit fb9d8afb6c
7 zmienionych plików z 74 dodań i 81 usunięć

Wyświetl plik

@ -104,13 +104,13 @@ mk22fn512_src = ['platform/mcu/MK22FN512xxx12/boot/startup.cpp',
'platform/mcu/MK22FN512xxx12/drivers/gpio.c',
'platform/mcu/MK22FN512xxx12/drivers/delays.cpp',
'platform/mcu/MK22FN512xxx12/drivers/I2C0.c',
# 'platform/mcu/MK22FN512xxx12/drivers/usb/usb_device_cdc_acm.c',
# 'platform/mcu/MK22FN512xxx12/drivers/usb/usb_device_ch9.c',
# 'platform/mcu/MK22FN512xxx12/drivers/usb/usb_device_dci.c',
# 'platform/mcu/MK22FN512xxx12/drivers/usb/usb_device_descriptor.c',
# 'platform/mcu/MK22FN512xxx12/drivers/usb/usb_device_khci.c',
# 'platform/mcu/MK22FN512xxx12/drivers/usb/usb_osa_bm.c',
# 'platform/mcu/MK22FN512xxx12/drivers/usb_vcom.c',
'platform/mcu/MK22FN512xxx12/drivers/usb/usb_device_cdc_acm.c',
'platform/mcu/MK22FN512xxx12/drivers/usb/usb_device_ch9.c',
'platform/mcu/MK22FN512xxx12/drivers/usb/usb_device_dci.c',
'platform/mcu/MK22FN512xxx12/drivers/usb/usb_device_descriptor.c',
'platform/mcu/MK22FN512xxx12/drivers/usb/usb_device_khci.c',
'platform/mcu/MK22FN512xxx12/drivers/usb/usb_osa_bm.c',
'platform/mcu/MK22FN512xxx12/drivers/usb_vcom.c',
'platform/mcu/CMSIS/Device/NXP/MK22FN512xxx12/Source/system_MK22F51212.c']
mk22fn512_inc = ['platform/mcu/CMSIS/Include',
@ -233,7 +233,7 @@ dm1801_def = def + mk22fn512_def + {'PLATFORM_DM1801': ''}
## Compilation defines
##
linux_c_args = []
linux_l_args = ['--entry=entry', '-lm']
linux_l_args = ['-lm']
# Add AddressSanitizer if required
if get_option('asan')

Wyświetl plik

@ -17,7 +17,8 @@
#include <stdio.h>
#include <reent.h>
#include "filesystem/file_access.h"
#include <usb_vcom.h>
#include <filesystem/file_access.h>
using namespace std;
@ -31,11 +32,10 @@ extern "C" {
*/
int _write_r(struct _reent *ptr, int fd, const void *buf, size_t cnt)
{
// if(fd == STDOUT_FILENO || fd == STDERR_FILENO)
// {
// vcom_writeBlock(buf, cnt);
// return cnt;
// }
if(fd == STDOUT_FILENO || fd == STDERR_FILENO)
{
return vcom_writeBlock(buf, cnt);
}
/* If fd is not stdout or stderr */
ptr->_errno = EBADF;
@ -48,19 +48,28 @@ int _write_r(struct _reent *ptr, int fd, const void *buf, size_t cnt)
*/
int _read_r(struct _reent *ptr, int fd, void *buf, size_t cnt)
{
// if(fd == STDIN_FILENO)
// {
// for(;;)
// {
// ssize_t r = vcom_readBlock(buf, cnt);
// if((r < 0) || (r == (ssize_t)(cnt))) return r;
// }
// }
// else
int ret = -1;
/* If fd is not stdin */
ptr->_errno = EBADF;
return -1;
if(fd == STDIN_FILENO)
{
for(;;)
{
ssize_t r = vcom_readBlock(buf, cnt);
if((r < 0) || (r == ((ssize_t) cnt)))
{
ret = ((int) r);
break;
}
}
}
else
{
/* If fd is not stdin */
ptr->_errno = EBADF;
ret = -1;
}
return ret;
}
#ifdef __cplusplus

Wyświetl plik

@ -619,7 +619,7 @@ void vcom_init()
return;
}
NVIC_SetPriority(USB0_IRQn, 3);
NVIC_SetPriority(USB0_IRQn, 14);
NVIC_EnableIRQ(USB0_IRQn);
USB_DeviceRun(cdcVcom.deviceHandle);

Wyświetl plik

@ -21,6 +21,10 @@
#include <stdint.h>
#include <unistd.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* Initialise USB virtual com port. Parameters: 115200 baud, 8N1.
* @return zero on success, negative value on failure.
@ -45,4 +49,8 @@ ssize_t vcom_writeBlock(const void *buf, size_t len);
*/
ssize_t vcom_readBlock(void *buf, size_t len);
#ifdef __cplusplus
}
#endif
#endif /* USB_VCOM_H */

Wyświetl plik

@ -27,9 +27,8 @@
radio_state Radio_State = {12, 8.2f, 3, 4, 1, false};
void systemBootstrap();
int CLIMenu() {
int CLIMenu()
{
int choice = 0;
printf("Select the value to change:\n");
printf("1 -> RSSI\n");
@ -41,20 +40,23 @@ int CLIMenu() {
printf("7 -> Print current state\n");
printf("8 -> Exit\n");
printf("> ");
do {
do
{
scanf("%d", &choice);
} while (choice < 1 || choice > 8);
printf("\033[1;1H\033[2J");
return choice;
}
void updateValue(float *curr_value) {
void updateValue(float *curr_value)
{
printf("Current value: %f\n", *curr_value);
printf("New value: \n");
scanf("%f", curr_value);
}
void printState() {
void printState()
{
printf("\nCurrent state\n");
printf("RSSI : %f\n", Radio_State.RSSI);
printf("Battery: %f\n", Radio_State.Vbat);
@ -65,16 +67,14 @@ void printState() {
}
void *startRadio() {
systemBootstrap();
return NULL;
}
void *startCLIMenu() {
void *startCLIMenu()
{
int choice;
do {
do
{
choice = CLIMenu();
switch (choice) {
switch (choice)
{
case VAL_RSSI:
updateValue(&Radio_State.RSSI);
break;
@ -100,48 +100,18 @@ void *startCLIMenu() {
continue;
}
} while (choice != EXIT);
printf("exiting\n");
printf("73\n");
exit(0);
}
int emulator_main() {
pthread_t cli_thread, radio_thread;
int err1, err2 = 0;
void emulator_start()
{
pthread_t cli_thread;
int err = pthread_create(&cli_thread, NULL, startCLIMenu, NULL);
err1 = pthread_create(&cli_thread, NULL, startCLIMenu, NULL);
err2 = pthread_create(&radio_thread, NULL, startRadio, NULL);
if (err1 | err2) {
printf("An error occurred starting the threads: %d, %d\n", err1, err2);
return 1;
if(err)
{
printf("An error occurred starting the emulator thread: %d\n", err);
}
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

@ -32,7 +32,8 @@
#define SCREEN_HEIGHT 128
#endif
enum choices {
enum choices
{
VAL_RSSI=1,
VAL_BAT,
VAL_MIC,
@ -43,7 +44,8 @@ enum choices {
EXIT
};
typedef struct {
typedef struct
{
float RSSI;
float Vbat;
float micLevel;
@ -54,4 +56,6 @@ typedef struct {
extern radio_state Radio_State;
void emulator_start();
#endif /* EMULATOR_H */

Wyświetl plik

@ -29,6 +29,8 @@ void platform_init()
snprintf(hwInfo.name, 10, "Linux");
hwInfo.vhf_band = 1;
hwInfo.uhf_band = 1;
emulator_start();
}
void platform_terminate()