Rearrangement of LPT code

This commit is contained in:
Peter Weingartner 2022-04-15 12:59:01 -04:00
parent 51b65de7bd
commit 4210e3d716
6 changed files with 10097 additions and 10043 deletions

View file

@ -20,6 +20,7 @@
#include "fatfs/ff.h"
#include "interrupt.h"
#include "log.h"
#include "lpt_reg.h"
#include "dev/ps2.h"
#include "rtc_reg.h"
#include "simpleio.h"
@ -28,29 +29,6 @@
#include "uart_reg.h"
#include "vicky_general.h"
#define LPT_DATA_PORT ((volatile unsigned char *)0xFEC02378)
#define LPT_STAT_PORT ((volatile unsigned char *)0xFEC02379)
#define LPT_STAT_BUSY 0x80
#define LPT_STAT_ACK 0x40
#define LPT_STAT_PO 0x20
#define LPT_STAT_SELECT 0x10
#define LPT_STAT_ERROR 0x08
#define LPT_STAT_IRQ 0x04
#define LPT_CTRL_PORT ((volatile unsigned char *)0xFEC0237A)
#define LPT_CTRL_STROBE 0x01
#define LPT_CTRL_AL 0x02
#define LPT_CTRL_INIT 0x04
#define LPT_CTRL_SELECT 0x08
#define LPT_CTRL_IRQE 0x10
#define LPT_CTRL_BI 0x20
#define LPT_INIT_ON 0x08 /* Start the printer initialization process */
#define LPT_INIT_OFF 0x0C /* Stop the printer initialization process */
#define LPT_STROBE_ON 0x0F /* Strobe the printer */
#define LPT_STROBE_OFF 0x0E /* Drop the strobe to the printer */
typedef struct s_cli_test_feature {
const char * name;
const char * help;
@ -218,22 +196,26 @@ short cli_test_uart(short channel, int argc, const char * argv[]) {
char buffer[80];
uart_init(0);
uart_setbps(0, UART_115200);
uart_setbps(0, UART_9600);
uart_setlcr(0, LCR_DATABITS_8 | LCR_STOPBIT_1 | LCR_PARITY_NONE);
sprintf(buffer, "COM1: 115200, no parity, 1 stop bit, 8 data bits\nPress ESC to finish (%d).\n", UART_115200);
sprintf(buffer, "COM1: 9600, no parity, 1 stop bit, 8 data bits\nPress ESC to finish (%d).\n", UART_115200);
sys_chan_write(0, buffer, strlen(buffer));
for (;;) {
c = kbd_getc();
c = kbdmo_getc()
if (c != 0) {
if (c == 0x1b) {
if (c == '~') {
return 0;
}
uart_put(0, c);
} else if (uart_has_bytes(0)) {
}
if (uart_has_bytes(0)) {
c = uart_get(0);
sys_chan_write_b(channel, c);
if (c != 0) {
sys_chan_write_b(channel, c);
}
}
}
@ -542,14 +524,14 @@ short cli_test_lpt(short screen, int argc, const char * argv[]) {
break;
case 0x3F: /* F5 */
ctrl |= LPT_CTRL_INIT;
ctrl |= LPT_CTRL_mINIT;
*LPT_CTRL_PORT = ctrl;
sprintf(message, "INIT = TRUE [%02X]\n", ctrl);
print(0, message);
break;
case 0x40: /* F6 */
ctrl &= ~LPT_CTRL_INIT;
ctrl &= ~LPT_CTRL_mINIT;
*LPT_CTRL_PORT = ctrl;
sprintf(message, "INIT = FALSE [%02X]\n", ctrl);
print(0, message);
@ -602,6 +584,9 @@ short cmd_test_print(short screen, int argc, const char * argv[]) {
if (result != 0) {
sprintf(message, "Unable to print: %s\n", err_message(result));
print(screen, message);
sprintf(message, "Printer status: %02X\n", sys_chan_status(lpt));
print(screen, message);
break;
}
scancode = sys_kbd_scancode();
@ -612,7 +597,7 @@ short cmd_test_print(short screen, int argc, const char * argv[]) {
print(screen, "Unable to print: got a bad channel number.\n");
} else {
sprintf(message, "Unable to print: %s\n", err_message(lpt));
sprintf(message, "Could not open channel to printer: %s\n", err_message(lpt));
print(screen, message);
}
#endif

View file

@ -4,36 +4,15 @@
#include "errors.h"
#include "log.h"
#include "lpt_reg.h"
#include "dev/lpt.h"
#include "dev/txt_screen.h"
#include "simpleio.h"
#include "sys_general.h"
#include "syscalls.h"
#if MODEL == MODEL_FOENIX_A2560K
#define LPT_DATA_PORT ((volatile unsigned char *)0xFEC02378)
#define LPT_STAT_PORT ((volatile unsigned char *)0xFEC02379)
#define LPT_STAT_BUSY 0x80
#define LPT_STAT_ACK 0x40
#define LPT_STAT_PO 0x20
#define LPT_STAT_SELECT 0x10
#define LPT_STAT_ERROR 0x08
#define LPT_STAT_IRQ 0x04
#define LPT_CTRL_PORT ((volatile unsigned char *)0xFEC0237A)
#define LPT_CTRL_STROBE 0x01
#define LPT_CTRL_AL 0x02
#define LPT_CTRL_INIT 0x04
#define LPT_CTRL_SELECT 0x08
#define LPT_CTRL_IRQE 0x10
#define LPT_CTRL_BI 0x20
#define LPT_INIT_ON 0x04 /* Start the printer initialization process */
#define LPT_INIT_OFF 0x0C /* Stop the printer initialization process */
#define LPT_STROBE_ON 0x0D /* Strobe the printer */
#define LPT_STROBE_OFF 0x0C /* Drop the strobe to the printer */
/**
* Wait a little bit...
*/
@ -53,7 +32,7 @@ short lpt_initialize() {
lpt_delay();
/* Set the outputs to stop the initialization process */
*LPT_CTRL_PORT = LPT_CTRL_INIT | LPT_CTRL_SELECT;
*LPT_CTRL_PORT = LPT_CTRL_mINIT | LPT_CTRL_SELECT;
return 0;
}
@ -64,7 +43,7 @@ short lpt_initialize() {
short lpt_open(t_channel * chan, const uint8_t * path, short mode) {
lpt_initialize();
*LPT_CTRL_PORT = LPT_CTRL_INIT | LPT_CTRL_SELECT;
*LPT_CTRL_PORT = LPT_CTRL_mINIT | LPT_CTRL_SELECT;
return 0;
}
@ -72,7 +51,7 @@ short lpt_open(t_channel * chan, const uint8_t * path, short mode) {
* Close the connection to the printer... all we do is deassert the SELECT pin
*/
short lpt_close(t_channel * chan) {
*LPT_CTRL_PORT = LPT_CTRL_INIT;
*LPT_CTRL_PORT = LPT_CTRL_mINIT;
return 0;
}
@ -83,18 +62,24 @@ short lpt_write_b(p_channel chan, unsigned char b) {
/* This write routine is polled I/O. */
/* Wait until the printer is not busy */
while ((*LPT_STAT_PORT & LPT_STAT_BUSY) == LPT_STAT_BUSY) {
while ((*LPT_STAT_PORT & LPT_STAT_nBUSY) == LPT_STAT_nBUSY) {
lpt_delay();
}
/* Send the byte */
*LPT_DATA_PORT = b;
sys_chan_write_b(0, b);
/* Strobe the interface */
*LPT_CTRL_PORT = LPT_CTRL_INIT | LPT_CTRL_SELECT;
*LPT_CTRL_PORT = LPT_CTRL_mINIT | LPT_CTRL_SELECT | LPT_CTRL_STROBE;
lpt_delay();
*LPT_CTRL_PORT = LPT_CTRL_INIT | LPT_CTRL_SELECT | LPT_CTRL_STROBE;
*LPT_CTRL_PORT = LPT_CTRL_mINIT | LPT_CTRL_SELECT;
// if ((*LPT_STAT_PORT & (LPT_STAT_nERROR | LPT_STAT_PO | LPT_STAT_nBUSY | LPT_STAT_SELECT)) != LPT_STAT_nERROR | LPT_STAT_nBUSY | LPT_STAT_SELECT) {
// // Online, there's paper, not busy, and not in error
// return ERR_GENERAL;
// } else {
// return 0;
// }
return 0;
}
@ -116,6 +101,27 @@ short lpt_write(p_channel chan, const uint8_t * buffer, short size) {
return 0;
}
/**
* Return the status of the printer
*/
short lpt_status() {
short result = 0;
// Get the status
unsigned char stat = *LPT_STAT_PORT;
// Conver the status bits to be consistent with channels
if ((stat & LPT_STAT_nERROR) == 0) result |= LPT_STAT_nERROR;
if (stat & LPT_STAT_PO) result |= LPT_STAT_PAPER;
if (stat & LPT_STAT_SELECT) result |= LPT_STAT_ONLINE;
if ((stat & (LPT_STAT_nERROR | LPT_STAT_PO | LPT_STAT_nBUSY | LPT_STAT_SELECT)) == LPT_STAT_nERROR | LPT_STAT_nBUSY | LPT_STAT_SELECT) {
// Online, there's paper, not busy, and not in error
result |= LPT_STAT_WRITABLE;
}
return result;
}
/**
* Install the LPT driver
*/
@ -134,7 +140,7 @@ short lpt_install() {
dev.write_b = lpt_write_b;
dev.flush = 0;
dev.seek = 0;
dev.status = 0;
dev.status = lpt_status;
dev.ioctrl = 0;
return cdev_register(&dev);

View file

@ -7,6 +7,11 @@
#include "dev/channel.h"
#define LPT_STAT_ERROR 0x02 /** The printer has encountered some error */
#define LPT_STAT_WRITABLE 0x08 /** The printer can accept data (online, no error, has paper, not busy) */
#define LPT_STAT_PAPER 0x10 /** The printer is out of paper */
#define LPT_STAT_ONLINE 0x20 /** The printer is selected/online */
/*
* Install the LPT driver
*/

File diff suppressed because it is too large Load diff

36
src/include/lpt_reg.h Normal file
View file

@ -0,0 +1,36 @@
/**
* @file lpt_reg.h
* Define the registers for the parallel port
*/
#ifndef __LPT_REG_H
#define __LPT_REG_H
#include "sys_general.h"
#if MODEL == MODEL_FOENIX_A2560K
#define LPT_DATA_PORT ((volatile unsigned char *)0xFEC02378)
#define LPT_STAT_PORT ((volatile unsigned char *)0xFEC02379)
#define LPT_CTRL_PORT ((volatile unsigned char *)0xFEC0237A)
#endif
#define LPT_STAT_nBUSY 0x80
#define LPT_STAT_nACK 0x40
#define LPT_STAT_PO 0x20
#define LPT_STAT_SELECT 0x10
#define LPT_STAT_nERROR 0x08
#define LPT_STAT_IRQ 0x04
#define LPT_CTRL_STROBE 0x01
#define LPT_CTRL_AL 0x02
#define LPT_CTRL_mINIT 0x04
#define LPT_CTRL_SELECT 0x08
#define LPT_CTRL_IRQE 0x10
#define LPT_CTRL_BI 0x20
#define LPT_INIT_ON 0x04 /* Start the printer initialization process */
#define LPT_INIT_OFF 0x0C /* Stop the printer initialization process */
#define LPT_STROBE_ON 0x0D /* Strobe the printer */
#define LPT_STROBE_OFF 0x0C /* Drop the strobe to the printer */
#endif

13848
src/mapfile

File diff suppressed because it is too large Load diff