Compare commits
7 Commits
ab9078ab3f
...
compilatio
Author | SHA1 | Date | |
---|---|---|---|
04b642776d | |||
9f4a61a7ec
|
|||
d35c88e38f | |||
cf04037f9d | |||
2a88835da5 | |||
aa84a2c03b | |||
52a232f1e9 |
31
example.c
31
example.c
@@ -8,19 +8,12 @@
|
|||||||
//**********************************************************************
|
//**********************************************************************
|
||||||
//**********************************************************************
|
//**********************************************************************
|
||||||
|
|
||||||
#include <at89c55.h>
|
#include <at89c51ed2.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#define TICK_RATE 100
|
#define TICK_RATE 100
|
||||||
#define NPER (0x10000 - (20000000 / 12 / TICK_RATE))
|
#define NPER (0x10000 - (20000000 / 6 / TICK_RATE))
|
||||||
|
|
||||||
// Missing port definitions
|
|
||||||
__sbit __at (0xC4) P4_4;
|
|
||||||
__sbit __at (0xC3) P4_3;
|
|
||||||
__sbit __at (0xC2) P4_2;
|
|
||||||
__sbit __at (0xC1) P4_1;
|
|
||||||
__sbit __at (0xC0) P4_0;
|
|
||||||
|
|
||||||
// I/O definitions
|
// I/O definitions
|
||||||
#define BUTTON_1 P3_2
|
#define BUTTON_1 P3_2
|
||||||
@@ -71,8 +64,7 @@ uint8_t lcd_pos;
|
|||||||
|
|
||||||
// Quick'n'dirty CPU pause, just enough for the LCD to stabilize.
|
// Quick'n'dirty CPU pause, just enough for the LCD to stabilize.
|
||||||
void lcd_pause(void) {
|
void lcd_pause(void) {
|
||||||
int i = 30;
|
__asm__ ("nop");
|
||||||
while(i--);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reads the status register from the LCD.
|
// Reads the status register from the LCD.
|
||||||
@@ -170,11 +162,8 @@ void lcd_init(void) {
|
|||||||
// Puts a character to the LCD. Correctly handles '\n'.
|
// Puts a character to the LCD. Correctly handles '\n'.
|
||||||
void lcd_putchar(char c) {
|
void lcd_putchar(char c) {
|
||||||
if(c == 10) {
|
if(c == 10) {
|
||||||
while((lcd_pos != 0) && (lcd_pos != 40)) {
|
if(lcd_pos < 40) lcd_pos = 40;
|
||||||
lcd_send_data(32);
|
else lcd_pos = 0;
|
||||||
lcd_pos++;
|
|
||||||
if(lcd_pos == 80) lcd_pos=0;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
lcd_send_data(c);
|
lcd_send_data(c);
|
||||||
lcd_pos++;
|
lcd_pos++;
|
||||||
@@ -184,6 +173,8 @@ void lcd_putchar(char c) {
|
|||||||
|
|
||||||
// Initializes the background tick timer (for delays).
|
// Initializes the background tick timer (for delays).
|
||||||
void timer_init(void) {
|
void timer_init(void) {
|
||||||
|
CKCON0 = X2; // Enable 2x clock mode
|
||||||
|
|
||||||
// Initialize timer 0 as 16-bit countdown, timer 1 as 8-bit auto-reload countdown
|
// Initialize timer 0 as 16-bit countdown, timer 1 as 8-bit auto-reload countdown
|
||||||
|
|
||||||
TMOD = 0x21;
|
TMOD = 0x21;
|
||||||
@@ -196,7 +187,8 @@ void timer_init(void) {
|
|||||||
|
|
||||||
// Enable interrupts only for timer 0
|
// Enable interrupts only for timer 0
|
||||||
|
|
||||||
IE = 0x82;
|
EA = 1;
|
||||||
|
ET0 = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initializes the serial port (along with timer 2).
|
// Initializes the serial port (along with timer 2).
|
||||||
@@ -204,7 +196,7 @@ void serial_init(void) {
|
|||||||
// Initialize timer 2 as 312500 Hz as the baud rate generator (for tulflash)
|
// Initialize timer 2 as 312500 Hz as the baud rate generator (for tulflash)
|
||||||
|
|
||||||
RCAP2H = 0xFF;
|
RCAP2H = 0xFF;
|
||||||
RCAP2L = 0xFE;
|
RCAP2L = 0xFC;
|
||||||
T2CON = 0x34;
|
T2CON = 0x34;
|
||||||
|
|
||||||
// Initialize serial I/O
|
// Initialize serial I/O
|
||||||
@@ -217,6 +209,7 @@ void serial_init(void) {
|
|||||||
void serial_putchar(char c) {
|
void serial_putchar(char c) {
|
||||||
while(TI == 0);
|
while(TI == 0);
|
||||||
SBUF = c;
|
SBUF = c;
|
||||||
|
TI = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
__bit stdout_to_lcd = 0;
|
__bit stdout_to_lcd = 0;
|
||||||
@@ -296,6 +289,8 @@ void main(void) {
|
|||||||
lcd_init();
|
lcd_init();
|
||||||
serial_init();
|
serial_init();
|
||||||
|
|
||||||
|
delay(1);
|
||||||
|
|
||||||
stdout_to_serial = 1;
|
stdout_to_serial = 1;
|
||||||
stdout_to_lcd = 1;
|
stdout_to_lcd = 1;
|
||||||
|
|
||||||
|
@@ -57,6 +57,10 @@ pub struct ArgWrite {
|
|||||||
#[argp(description = "Path to the source Intel HEX file.")]
|
#[argp(description = "Path to the source Intel HEX file.")]
|
||||||
pub path: OsString,
|
pub path: OsString,
|
||||||
|
|
||||||
|
#[argp(option)]
|
||||||
|
#[argp(description = "Where to run the command. Will be created if it doesn't exist.")]
|
||||||
|
pub cmd_path: Option<std::path::PathBuf>,
|
||||||
|
|
||||||
#[argp(option)]
|
#[argp(option)]
|
||||||
#[argp(description = "Command to run before writing the file. Handy for compiling the program and running it at the same time.")]
|
#[argp(description = "Command to run before writing the file. Handy for compiling the program and running it at the same time.")]
|
||||||
pub cmd: Option<OsString>,
|
pub cmd: Option<OsString>,
|
||||||
@@ -102,7 +106,7 @@ pub struct ArgMonitor {}
|
|||||||
pub struct ArgRun {
|
pub struct ArgRun {
|
||||||
#[argp(positional)]
|
#[argp(positional)]
|
||||||
#[argp(description = "Path to the source C file.")]
|
#[argp(description = "Path to the source C file.")]
|
||||||
pub path: OsString
|
pub path: std::path::PathBuf
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(FromArgs)]
|
#[derive(FromArgs)]
|
||||||
|
23
src/main.rs
23
src/main.rs
@@ -204,16 +204,23 @@ fn write_chip_data(args: &ArgWrite, target: &mut PhysicalTarget) -> Result<(), E
|
|||||||
fn write_chip(args: ArgWrite, target: &mut PhysicalTarget) -> Result<(), Error> {
|
fn write_chip(args: ArgWrite, target: &mut PhysicalTarget) -> Result<(), Error> {
|
||||||
loop {
|
loop {
|
||||||
if let Some(cmd) = args.cmd.as_ref() {
|
if let Some(cmd) = args.cmd.as_ref() {
|
||||||
|
let cmd_path = &args.cmd_path;
|
||||||
let mut args = shlex::bytes::split(cmd.as_encoded_bytes())
|
let mut args = shlex::bytes::split(cmd.as_encoded_bytes())
|
||||||
.ok_or(Error::other("Error parsing commandline arguments"))?
|
.ok_or(Error::other("Error parsing commandline arguments"))?
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|x| unsafe { OsString::from_encoded_bytes_unchecked(x) });
|
.map(|x| unsafe { OsString::from_encoded_bytes_unchecked(x) });
|
||||||
|
|
||||||
|
if let Some(cmd_path) = cmd_path {
|
||||||
|
if !cmd_path.is_dir() {
|
||||||
|
Err(Error::other("invalid cmd path (not a dir)"))?
|
||||||
|
}
|
||||||
|
}
|
||||||
let Some(name) = args.next() else {
|
let Some(name) = args.next() else {
|
||||||
Err(Error::other("No command provided"))?
|
Err(Error::other("No command provided"))?
|
||||||
};
|
};
|
||||||
|
|
||||||
let out = std::process::Command::new(name)
|
let out = std::process::Command::new(name)
|
||||||
|
.current_dir(cmd_path.as_ref().map(|p| p.as_path()).unwrap_or(&std::path::Path::new(".")))
|
||||||
.args(args)
|
.args(args)
|
||||||
.output()?;
|
.output()?;
|
||||||
|
|
||||||
@@ -257,11 +264,21 @@ fn monitor_chip(_args: ArgMonitor, target: &mut PhysicalTarget) -> Result<(), Er
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn run_chip(args: ArgRun, target: &mut PhysicalTarget) -> Result<(), Error> {
|
fn run_chip(args: ArgRun, target: &mut PhysicalTarget) -> Result<(), Error> {
|
||||||
let path = PathBuf::from(&args.path).with_extension("ihx").into_os_string();
|
let build_dir = args.path.parent().unwrap().join("tulflash");
|
||||||
let cmd = Some(OsString::from(format!("sdcc \"{}\"", unsafe { String::from_utf8_unchecked(args.path.into_encoded_bytes()) })));
|
|
||||||
|
let source_file_name = args.path.file_name().ok_or(Error::other("invalid path to compilation source"))?;
|
||||||
|
let source_file = build_dir.join(&source_file_name);
|
||||||
|
let output_file = source_file.with_extension("ihx");
|
||||||
|
|
||||||
|
let cmd = Some(OsString::from(format!("sdcc \"{}\"", source_file_name.to_string_lossy())));
|
||||||
|
let cmd_path = Some(build_dir.clone());
|
||||||
|
|
||||||
|
std::fs::create_dir_all(build_dir)?;
|
||||||
|
std::fs::copy(args.path, &source_file)?;
|
||||||
|
|
||||||
write_chip(ArgWrite {
|
write_chip(ArgWrite {
|
||||||
path,
|
path: output_file.into_os_string(),
|
||||||
|
cmd_path,
|
||||||
cmd,
|
cmd,
|
||||||
start: 0,
|
start: 0,
|
||||||
end: 65535,
|
end: 65535,
|
||||||
|
Reference in New Issue
Block a user