Initial commit of source code.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor
2016-05-25 11:37:40 -04:00
parent 37a91e9c10
commit f582a36e4d
71 changed files with 9950 additions and 0 deletions

10
src/simulator/Kconfig Normal file
View File

@@ -0,0 +1,10 @@
# Kconfig settings for compiling and running the firmware on the host
# processor for simulation purposes.
if MACH_SIMU
config BOARD_DIRECTORY
string
default "simulator"
endif

3
src/simulator/Makefile Normal file
View File

@@ -0,0 +1,3 @@
# Additional simulator build rules
src-y += simulator/main.c simulator/gpio.c

45
src/simulator/gpio.c Normal file
View File

@@ -0,0 +1,45 @@
// GPIO functions on simulator.
//
// Copyright (C) 2016 Kevin O'Connor <kevin@koconnor.net>
//
// This file may be distributed under the terms of the GNU GPLv3 license.
#include "gpio.h" // gpio_out_write
struct gpio_out gpio_out_setup(uint8_t pin, uint8_t val) {
return (struct gpio_out){.pin=pin};
}
void gpio_out_toggle(struct gpio_out g) {
}
void gpio_out_write(struct gpio_out g, uint8_t val) {
}
struct gpio_in gpio_in_setup(uint8_t pin, int8_t pull_up) {
return (struct gpio_in){.pin=pin};
}
uint8_t gpio_in_read(struct gpio_in g) {
return 0;
}
struct gpio_pwm gpio_pwm_setup(uint8_t pin, uint32_t cycle_time, uint8_t val) {
return (struct gpio_pwm){.pin=pin};
}
void gpio_pwm_write(struct gpio_pwm g, uint8_t val) {
}
struct gpio_adc gpio_adc_setup(uint8_t pin) {
return (struct gpio_adc){.pin=pin};
}
uint32_t gpio_adc_sample_time(void) {
return 0;
}
uint8_t gpio_adc_sample(struct gpio_adc g) {
return 0;
}
void gpio_adc_clear_sample(struct gpio_adc g) {
}
uint16_t gpio_adc_read(struct gpio_adc g) {
return 0;
}
void spi_config(void) {
}
void spi_transfer(char *data, uint8_t len) {
}

37
src/simulator/gpio.h Normal file
View File

@@ -0,0 +1,37 @@
#ifndef __SIMU_GPIO_H
#define __SIMU_GPIO_H
#include <stdint.h>
struct gpio_out {
uint8_t pin;
};
struct gpio_out gpio_out_setup(uint8_t pin, uint8_t val);
void gpio_out_toggle(struct gpio_out g);
void gpio_out_write(struct gpio_out g, uint8_t val);
struct gpio_in {
uint8_t pin;
};
struct gpio_in gpio_in_setup(uint8_t pin, int8_t pull_up);
uint8_t gpio_in_read(struct gpio_in g);
struct gpio_pwm {
uint8_t pin;
};
struct gpio_pwm gpio_pwm_setup(uint8_t pin, uint32_t cycle_time, uint8_t val);
void gpio_pwm_write(struct gpio_pwm g, uint8_t val);
struct gpio_adc {
uint8_t pin;
};
struct gpio_adc gpio_adc_setup(uint8_t pin);
uint32_t gpio_adc_sample_time(void);
uint8_t gpio_adc_sample(struct gpio_adc g);
void gpio_adc_clear_sample(struct gpio_adc g);
uint16_t gpio_adc_read(struct gpio_adc g);
void spi_config(void);
void spi_transfer(char *data, uint8_t len);
#endif // gpio.h

31
src/simulator/irq.h Normal file
View File

@@ -0,0 +1,31 @@
#ifndef __SIMU_IRQ_H
#define __SIMU_IRQ_H
// Definitions for irq enable/disable on host simulator
#include <stdint.h>
#include "compiler.h" // barrier
extern uint8_t Interrupt_off;
static inline void irq_disable(void) {
Interrupt_off = 1;
barrier();
}
static inline void irq_enable(void) {
barrier();
Interrupt_off = 0;
}
static inline uint8_t irq_save(void) {
uint8_t flag = Interrupt_off;
irq_disable();
return flag;
}
static inline void irq_restore(uint8_t flag) {
barrier();
Interrupt_off = flag;
}
#endif // irq.h

102
src/simulator/main.c Normal file
View File

@@ -0,0 +1,102 @@
// Main starting point for host simulator.
//
// Copyright (C) 2016 Kevin O'Connor <kevin@koconnor.net>
//
// This file may be distributed under the terms of the GNU GPLv3 license.
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
#include "sched.h" // sched_main
uint8_t Interrupt_off;
/****************************************************************
* Timers
****************************************************************/
uint32_t
timer_from_ms(uint32_t ms)
{
return 0; // XXX
}
void
timer_periodic(void)
{
}
uint32_t
timer_read_time(void)
{
return 0; // XXX
}
uint8_t
timer_set_next(uint32_t next)
{
return 0;
}
uint8_t
timer_try_set_next(uint32_t next)
{
return 1;
}
/****************************************************************
* Turn stdin/stdout into serial console
****************************************************************/
// XXX
char *
console_get_input(uint8_t *plen)
{
*plen = 0;
return NULL;
}
void
console_pop_input(uint8_t len)
{
}
// Return an output buffer that the caller may fill with transmit messages
char *
console_get_output(uint8_t len)
{
return NULL;
}
// Accept the given number of bytes added to the transmit buffer
void
console_push_output(uint8_t len)
{
}
/****************************************************************
* Startup
****************************************************************/
// Periodically sleep so we don't consume all CPU
static void
simu_pause(void)
{
// XXX - should check that no timers are present.
usleep(1);
}
DECL_TASK(simu_pause);
// Main entry point for simulator.
int
main(void)
{
// Make stdin non-blocking
fcntl(STDIN_FILENO, F_SETFL, fcntl(STDIN_FILENO, F_GETFL, 0) | O_NONBLOCK);
sched_main();
return 0;
}

21
src/simulator/misc.h Normal file
View File

@@ -0,0 +1,21 @@
#ifndef __SIMU_MISC_H
#define __SIMU_MISC_H
#include <stdint.h>
// main.c
char *console_get_input(uint8_t *plen);
void console_pop_input(uint8_t len);
char *console_get_output(uint8_t len);
void console_push_output(uint8_t len);
static inline size_t alloc_maxsize(size_t reqsize) {
return reqsize;
}
#define HAVE_OPTIMIZED_CRC 0
static inline uint16_t _crc16_ccitt(char *buf, uint8_t len) {
return 0;
}
#endif // misc.h

13
src/simulator/pgm.h Normal file
View File

@@ -0,0 +1,13 @@
#ifndef __SIMU_PGM_H
#define __SIMU_PGM_H
// This header provides wrappers for the AVR specific "PROGMEM"
// declarations.
#define PROGMEM
#define PSTR(S) S
#define READP(VAR) VAR
#define vsnprintf_P(D, S, F, A) vsnprintf(D, S, F, A)
#define strcasecmp_P(S1, S2) strcasecmp(S1, S2)
#define memcpy_P(DST, SRC, SIZE) memcpy((DST), (SRC), (SIZE))
#endif // pgm.h

12
src/simulator/timer.h Normal file
View File

@@ -0,0 +1,12 @@
#ifndef __SIMU_TIMER_H
#define __SIMU_TIMER_H
#include <stdint.h>
uint32_t timer_from_ms(uint32_t ms);
void timer_periodic(void);
uint32_t timer_read_time(void);
uint8_t timer_set_next(uint32_t next);
uint8_t timer_try_set_next(uint32_t next);
#endif // timer.h