Skip to content

Commit

Permalink
Punctuation changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Roarin committed Aug 1, 2016
1 parent 2d2124d commit a212be4
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 38 deletions.
4 changes: 2 additions & 2 deletions examples/uart_main/uart_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
#include <fx2types.h>
#include <assert.h>

//Initialize UART, call it uart0 and set the tx pin on PA1
CREATE_FAST_UART(uart0,OEB,_PB2,bmBIT2,TRUE,FALSE)
//Initialize UART, call it uart0 and set the tx pin on PA1.
CREATE_FAST_UART(uart0,OEB,_PB0,bmBIT0,TRUE,FALSE)
CREATE_FAST_UART(uart1,OEA,_PA4,bmBIT4,TRUE,FALSE)
//Used for setting the baud rate.
enum uart_baud baud;
Expand Down
69 changes: 33 additions & 36 deletions include/uart/soft_uart.h
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
/** \file include/uart/soft_uart.h
* This file contains a MACRO for defining UART function wrappers
* This file contains a MACRO for defining UART function wrappers.
**/

#ifndef SOFT_UART_H
#define SOFT_UART_H

#define load_delay unsigned char

/**
* \brief Automatically generates the function calls to allow multiple
* UARTS to be created. The main parameters for the UART is the pin number
* as well as the speed of the operation. These should be passed as an argument
* to the macro. The load_delay element controls the speed. This is created with the
* uart name .
* uart name.
**/
#define CREATE_FAST_UART(uartname,port,pinname,bitnum,TX_BLOCKING,RX_ENABLED) \
unsigned char uartname##_load_delay; \
Expand Down Expand Up @@ -94,76 +94,73 @@ BOOL uartname##_check_rx_blocking();
BYTE uartname##_check_receive_buffer();


/*Holds the value of the EA register*/
/*Holds the value of the EA register.*/
__bit ea_hold;

static inline void uart_tx(char c)
{

//Done in ASM to improve performance. It takes only 6
//cycles to move the data out, however a delay has been
//introduced in order to get a baud rate of 115200
//The mask which is to be written into the pin
//An efficient UART bitbang routine in assembly
//introduced in order to get a baud rate of 115200.
//An efficient UART bitbang routine in assembly.
__asm
//Like #define in C. Can easily be used to change the pin
//.equ _TX_PIN, _PA2
//Disable interrupts
//This is used because timing is critical
//Disable interrupts.
//This is used because timing is critical.
//If the FX2 jumps into the ISR temporarily , it may cause transmit
//errors. By clearing EA, we can disable interrupts
//Store the EA bit
//Store the EA bit.
mov _ea_hold,_EA
0002$:
clr _EA //(2 cycles)
//Move the data to be sent into the ACC //(--)
//The data which is to be shifted out is held in the dpl register //(--)
//We move the data into A for easy access to subsequent instructions //(--)
//Move the data to be sent into the ACC. //(--)
//The data which is to be shifted out is held in the dpl register. //(--)
//We move the data into A for easy access to subsequent instructions. //(--)
mov a , dpl //(2 cyles)
clr c //(1 cycle )
//We need to send out 8 bits of data //(--)
//Load r0 with value 8 //(--)
//We need to send out 8 bits of data. //(--)
//Load r0 with value 8. //(--)
mov r0, #0x08 //(2 cycles)
//Create the start bit //(--)
//Create the start bit. //(--)
clr _TX_PIN1 //(2 cycles)
//Precalculated delay since 1 cycle takes 88ns //(--)
//At 12Mhz, it should be about 83.33ns //(--)
//But it appears to be about 88ns //(--)
//These numbers have been verified using an analyzer //(--)
//Precalculated delay since 1 cycle takes 88ns. //(--)
//At 12Mhz, it should be about 83.33ns. //(--)
//But it appears to be about 88ns. //(--)
//These numbers have been verified using an analyzer. //(--)
mov r1, _load_delay //(2 cycles)
0003$: //(--)
//1 bit is about 8.6us //(--)
//1 bit is about 8.6us. //(--)
djnz r1, 0003$ //(3 cycles)
//DJNZ on Rn takes 3 cycles //(--)
//NOP takes about 1 cycle //(--)
//Add 2 more cycles of delay //(--)
//DJNZ on Rn takes 3 cycles. //(--)
//NOP takes about 1 cycle. //(--)
//Add 2 more cycles of delay. //(--)
//97 cycles //(--)
nop //(1 cycle )
nop //(1 cycle )
0004$: //(--)
rrc a //(2 cycles)
//The above rotates the accumulator right through the carry //(--)
//Move the carry into the port //(--)
//The above rotates the accumulator right through the carry. //(--)
//Move the carry into the port. //(--)
mov _TX_PIN1, c //(2 cycles)
//Now we need to add delay for the next //(--)
//Now we need to add delay for the next. //(--)
mov r1, _load_delay //(2 cycles)
//31*3 , 93 cycles of delay //(--)
//31*3 , 93 cycles of delay. //(--)
0005$: //(--)
djnz r1, 0005$ //(3 cycles)
nop //(1 cycle )
//3 more cycles of delay //(--)
//97 cycles //(--)
//3 more cycles of delay. //(--)
//97 cycles. //(--)
djnz r0, 0004$ //(3 cycles)
setb _TX_PIN1 //(2 cycles)
//This is for stop bit //(--)
//This is for stop bit. //(--)
//We need to delay the stop bit, otherwise we may get errors. //(--)
mov r1, _load_delay //(2 cycles)
0006$: //(--)
djnz r1, 0006$ //(3 cycles)
//for DJNZ , Jump for 32*3 , 96 cycles //(--)
//for DJNZ , Jump for 32*3 , 96 cycles. //(--)
nop //(1 cycle )
//97 cycles of delay //(--)
//Restore the EA register to enable or disable interrupts //(--)
//97 cycles of delay. //(--)
//Restore the EA register to enable or disable interrupts. //(--)
mov _EA, _ea_hold //(--)
__endasm;
}
Expand Down

0 comments on commit a212be4

Please sign in to comment.