dipl/code/textadv/src/main.c
Tyrolyean a78cc80bb2
Added stuff from corona start
Signed-off-by: Tyrolyean <tyrolyean@tyrolyean.net>
2020-03-14 22:30:05 +01:00

109 lines
2.4 KiB
C

/* Copyright © 2020 tyrolyean
*
* 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 "avr.h"
#include "structures.h"
#include "16550.h"
#include "dac.h"
#include "interrupt.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <avr/wdt.h>
#include <avr/interrupt.h>
/* Included early on the prevent the watchdog from killing the already killed
* microcontroller because of init delay
*/
uint8_t mcusr_mirror __attribute__ ((section (".noinit")));
void get_mcusr(void) \
__attribute__((naked)) \
__attribute__((section(".init3")));
void get_mcusr(void)
{
mcusr_mirror = MCUSR;
MCUSR = 0;
wdt_disable();
}
/* Function used to be more complicated, still remains for readability reasons
*/
void set_addr(uint8_t addr){
ADDR_REG = addr;
return;
}
void reset_modules(){
/* Setup Data Direction Registers and populate with sane default
values */
DATA_DDR_REG = 0xFF; /* Data Bus */
ADDR_DDR_REG = 0xFF; /* Address Bus */
CTRL_DDR_REG= 0xFF; /* Control Bus */
ADDR_REG = 0x00;
DATA_REG = 0x00;
CTRL_REG = 0x00;
/* Cleanly reset the dac uart */
CTRL_REG |= (1<<WR_SHIFT) | (1<<RD_SHIFT) | (1<<CS_DAC_SHIFT) |
(1<<MR_SHIFT) | (1<<CS_UART_SHIFT);
_delay_us(100);
CTRL_REG &= ~(1<<MR_SHIFT);
return;
}
int routine();
int main(){
/* Disable interrupts during initialisation phase */
cli();
reset_modules();
init_uart();
init_interrupts();
sei();
/* Enable the hardware watchdog. In case the microcontroller fails to
* finish it's task within the specified time, the watchdog will reset
* the atmel cookie.
*/
wdt_enable(WDTO_1S);
while(1){
wdt_reset();
routine();
}
return 0;
}
int routine(){
uint8_t received = read_from_uart(UART_REG_LSR);
if(received & 0x01){
received = read_from_uart(UART_REG_TXRX);
write_to_uart(UART_REG_TXRX,received);
}
routine_dac();
return 0;
}