Commit 35abaa84 authored by Jake Read's avatar Jake Read

unit test all uart lines

parent e1e6cc21
......@@ -18,19 +18,19 @@ UsedLibrary="D:/Dropbox (Personal)/CBA/doc/libraries_jake/eagle/sparkfun/SparkFu
UsedLibrary="D:/Dropbox (Personal)/CBA/doc/libraries_jake/eagle/marekr/borkedlabs-passives.lbr"
[Win_1]
Type="Board Editor"
Loc="0 0 1919 1016"
Type="Schematic Editor"
Loc="-1928 -8 -9 1008"
State=1
Number=2
File="mkrouter.brd"
View="2.78266 15.3697 62.859 48.8939"
WireWidths=" 0.0762 0.1016 0.127 0.15 0.2 0.4064 0.508 0.6096 0.8128 1.016 1.27 2.54 0.254 0.3048 0.2032 0.1524"
Number=1
File="mkrouter.sch"
View="32.8807 29.5621 186.974 128.623"
WireWidths=" 0.0762 0.1016 0.127 0.15 0.2 0.2032 0.254 0.3048 0.4064 0.508 0.6096 0.8128 1.016 1.27 2.54 0.1524"
PadDiameters=" 0.254 0.3048 0.4064 0.6096 0.8128 1.016 1.27 1.4224 1.6764 1.778 1.9304 2.1844 2.54 3.81 6.4516 0"
PadDrills=" 0.2 0.25 0.35 0.4 0.45 0.5 0.55 0.65 0.7 0.75 0.8 0.85 0.9 1 0.6 0.3"
PadDrills=" 0.2 0.25 0.3 0.35 0.4 0.45 0.5 0.55 0.65 0.7 0.75 0.8 0.85 0.9 1 0.6"
ViaDiameters=" 0.55 0.6 0.65 0.7 0.75 0.8 0.85 0.9 0.95 1 1.05 1.1 1.15 1.2 1.3 0"
ViaDrills=" 0.2 0.4 0.45 0.5 0.55 0.6 0.65 0.7 0.75 0.8 0.85 0.9 1 0.35 0.25 0.3"
HoleDrills=" 0.2 0.25 0.4 0.45 0.5 0.55 0.6 0.65 0.7 0.75 0.8 0.85 0.9 1 0.35 0.3"
TextSizes=" 0.254 0.3048 0.4064 0.8128 1.27 1.9304 2.1844 2.54 3.81 5.08 6.4516 1.778 1.016 0.6096 1.4224 1.6764"
ViaDrills=" 0.2 0.25 0.3 0.4 0.45 0.5 0.55 0.6 0.65 0.7 0.75 0.8 0.85 0.9 1 0.35"
HoleDrills=" 0.2 0.25 0.3 0.4 0.45 0.5 0.55 0.6 0.65 0.7 0.75 0.8 0.85 0.9 1 0.35"
TextSizes=" 0.254 0.3048 0.4064 0.6096 0.8128 1.016 1.27 1.4224 1.6764 1.9304 2.1844 2.54 3.81 5.08 6.4516 1.778"
PolygonSpacings=" 0.254 0.3048 0.4064 0.6096 0.8128 1.016 1.4224 1.6764 1.778 1.9304 2.1844 2.54 3.81 5.08 6.4516 1.27"
PolygonIsolates=" 0.254 0.3048 0.4064 0.6096 0.8128 1.016 1.27 1.4224 1.6764 1.778 1.9304 2.1844 2.54 3.81 6.4516 0"
MiterRadiuss=" 0.254 0.3175 0.635 1.27 2.54 1 2 2.5 5 7.5 10 0"
......@@ -39,14 +39,14 @@ DimensionExtWidths=" 0.127 0.254 0.1 0.13 0.26 0"
DimensionExtLengths=" 1.27 2.54 1 2 3 0"
DimensionExtOffsets=" 1.27 2.54 1 2 3 0"
SmdSizes=" 0.3048 0.1524 0.4064 0.2032 0.6096 0.3048 0.8128 0.4064 1.016 0.508 1.27 0.6604 1.4224 0.7112 1.6764 0.8128 1.778 0.9144 1.9304 0.9652 2.1844 1.0668 2.54 1.27 3.81 1.9304 5.08 2.54 6.4516 3.2512 1.27 0.635"
WireBend=4
WireBendSet=0
WireBend=0
WireBendSet=31
WireCap=1
MiterStyle=0
PadShape=0
ViaShape=1
PolygonPour=0
PolygonRank=1
PolygonRank=0
PolygonThermals=1
PolygonOrphans=0
TextRatio=8
......@@ -61,22 +61,24 @@ SwapLevel=0
ArcDirection=0
AddLevel=2
PadsSameType=0
Layer=48
Layer=91
Views=" 1: 32.8807 29.5621 186.974 128.623"
Sheet="1"
[Win_2]
Type="Schematic Editor"
Loc="-8 -8 1911 1008"
Type="Board Editor"
Loc="0 0 1919 1016"
State=1
Number=1
File="mkrouter.sch"
View="-38.8736 18.8994 146.038 137.772"
WireWidths=" 0.0762 0.1016 0.127 0.15 0.2 0.2032 0.254 0.3048 0.4064 0.508 0.6096 0.8128 1.016 1.27 2.54 0.1524"
Number=2
File="mkrouter.brd"
View="-18.1943 -5.95386 106.38 63.5619"
WireWidths=" 0.0762 0.1016 0.127 0.15 0.2 0.4064 0.508 0.6096 0.8128 1.016 1.27 2.54 0.254 0.3048 0.2032 0.1524"
PadDiameters=" 0.254 0.3048 0.4064 0.6096 0.8128 1.016 1.27 1.4224 1.6764 1.778 1.9304 2.1844 2.54 3.81 6.4516 0"
PadDrills=" 0.2 0.25 0.3 0.35 0.4 0.45 0.5 0.55 0.65 0.7 0.75 0.8 0.85 0.9 1 0.6"
PadDrills=" 0.2 0.25 0.35 0.4 0.45 0.5 0.55 0.65 0.7 0.75 0.8 0.85 0.9 1 0.6 0.3"
ViaDiameters=" 0.55 0.6 0.65 0.7 0.75 0.8 0.85 0.9 0.95 1 1.05 1.1 1.15 1.2 1.3 0"
ViaDrills=" 0.2 0.25 0.3 0.4 0.45 0.5 0.55 0.6 0.65 0.7 0.75 0.8 0.85 0.9 1 0.35"
HoleDrills=" 0.2 0.25 0.3 0.4 0.45 0.5 0.55 0.6 0.65 0.7 0.75 0.8 0.85 0.9 1 0.35"
TextSizes=" 0.254 0.3048 0.4064 0.6096 0.8128 1.016 1.27 1.4224 1.6764 1.9304 2.1844 2.54 3.81 5.08 6.4516 1.778"
ViaDrills=" 0.2 0.4 0.45 0.5 0.55 0.6 0.65 0.7 0.75 0.8 0.85 0.9 1 0.35 0.25 0.3"
HoleDrills=" 0.2 0.25 0.4 0.45 0.5 0.55 0.6 0.65 0.7 0.75 0.8 0.85 0.9 1 0.35 0.3"
TextSizes=" 0.254 0.3048 0.4064 0.8128 1.27 1.9304 2.1844 2.54 3.81 5.08 6.4516 1.778 1.016 0.6096 1.4224 1.6764"
PolygonSpacings=" 0.254 0.3048 0.4064 0.6096 0.8128 1.016 1.4224 1.6764 1.778 1.9304 2.1844 2.54 3.81 5.08 6.4516 1.27"
PolygonIsolates=" 0.254 0.3048 0.4064 0.6096 0.8128 1.016 1.27 1.4224 1.6764 1.778 1.9304 2.1844 2.54 3.81 6.4516 0"
MiterRadiuss=" 0.254 0.3175 0.635 1.27 2.54 1 2 2.5 5 7.5 10 0"
......@@ -85,14 +87,14 @@ DimensionExtWidths=" 0.127 0.254 0.1 0.13 0.26 0"
DimensionExtLengths=" 1.27 2.54 1 2 3 0"
DimensionExtOffsets=" 1.27 2.54 1 2 3 0"
SmdSizes=" 0.3048 0.1524 0.4064 0.2032 0.6096 0.3048 0.8128 0.4064 1.016 0.508 1.27 0.6604 1.4224 0.7112 1.6764 0.8128 1.778 0.9144 1.9304 0.9652 2.1844 1.0668 2.54 1.27 3.81 1.9304 5.08 2.54 6.4516 3.2512 1.27 0.635"
WireBend=0
WireBendSet=31
WireBend=4
WireBendSet=0
WireCap=1
MiterStyle=0
PadShape=0
ViaShape=1
PolygonPour=0
PolygonRank=0
PolygonRank=1
PolygonThermals=1
PolygonOrphans=0
TextRatio=8
......@@ -107,9 +109,7 @@ SwapLevel=0
ArcDirection=0
AddLevel=2
PadsSameType=0
Layer=91
Views=" 1: -38.8736 18.8994 146.038 137.772"
Sheet="1"
Layer=48
[Win_3]
Type="Control Panel"
......
......@@ -29,10 +29,23 @@ pin_t *lights[] = {&np1stlr, &np1stlb, &np2stlr, &np2stlb, &np3stlr, &np3stlb, &
// ringbuffers
ringbuffer_t np1rbrx;
ringbuffer_t np1rbtx;
ringbuffer_t np2rbrx;
ringbuffer_t np2rbtx;
ringbuffer_t np3rbrx;
ringbuffer_t np3rbtx;
ringbuffer_t np4rbrx;
ringbuffer_t np4rbtx;
ringbuffer_t np5rbrx;
ringbuffer_t np5rbtx;
// uartports
uartport_t up1;
uartport_t up2;
uartport_t up3;
uartport_t up4;
uartport_t up5;
uartport_t *ups[] = {&up1, &up2, &up3, &up4, &up5};
#endif /* HARDWARE_H_ */
\ No newline at end of file
......@@ -42,8 +42,10 @@ void setupperipherals(void){
// start uart clocks
PMC->PMC_PCER0 = 1 << ID_UART0;
//PMC->PMC_PCER0 = 1 << ID_UART1;
//PMC->PMC_PCER1 = 1 << (ID_UART2 - 32);
PMC->PMC_PCER0 = 1 << ID_UART1;
PMC->PMC_PCER1 = 1 << (ID_UART2 - 32);
PMC->PMC_PCER1 = 1 << (ID_UART3 - 32);
PMC->PMC_PCER1 = 1 << (ID_UART4 - 32);
}
void setupinterrupts(void){
......@@ -51,6 +53,26 @@ void setupinterrupts(void){
NVIC_ClearPendingIRQ(UART0_IRQn);
NVIC_SetPriority(UART0_IRQn, 8);
NVIC_EnableIRQ(UART0_IRQn);
NVIC_DisableIRQ(UART1_IRQn);
NVIC_ClearPendingIRQ(UART1_IRQn);
NVIC_SetPriority(UART1_IRQn, 8);
NVIC_EnableIRQ(UART1_IRQn);
NVIC_DisableIRQ(UART2_IRQn);
NVIC_ClearPendingIRQ(UART2_IRQn);
NVIC_SetPriority(UART2_IRQn, 8);
NVIC_EnableIRQ(UART2_IRQn);
NVIC_DisableIRQ(UART3_IRQn);
NVIC_ClearPendingIRQ(UART3_IRQn);
NVIC_SetPriority(UART3_IRQn, 8);
NVIC_EnableIRQ(UART3_IRQn);
NVIC_DisableIRQ(UART4_IRQn);
NVIC_ClearPendingIRQ(UART4_IRQn);
NVIC_SetPriority(UART4_IRQn, 8);
NVIC_EnableIRQ(UART4_IRQn);
}
void lightsetup(void){
......@@ -98,28 +120,52 @@ int main (void)
lightsetup();
// RBs 1
rb_init(&np1rbrx);
rb_init(&np1rbtx);
rb_init(&np1rbtx);
// UP1 on UART0, RX 9 TX 10 on PIOA
up1 = uart_new(UART0, PIOA, 9, 10, &np1rbrx, &np1rbtx);
uart_init(&up1, 81);
uart_init(&up1, 81, UART_IS_PERIPHERAL_A);
/*
// RBs 2
rb_init(&np2rbrx);
rb_init(&np2rbtx);
// UP2 on UART1, RX 5 TX 4 on PIOA
up2 = uart_new(UART1, PIOA, 5, 4, &np1rbrx, &np1rbtx);
uart_init(&up2, 81); // 81 for FTDI 115200 :|
*/
up2 = uart_new(UART1, PIOA, 5, 4, &np2rbrx, &np2rbtx);
uart_init(&up2, 81, UART_IS_PERIPHERAL_C); // 81 for FTDI 115200 :|
// RBs 3
rb_init(&np3rbrx);
rb_init(&np3rbtx);
// UP3 on UART2, RX 25 TX 26 on PIOD
up3 = uart_new(UART2, PIOD, 25, 26, &np3rbrx, &np3rbtx);
uart_init(&up3, 81, UART_IS_PERIPHERAL_C);
// RBs 4
rb_init(&np4rbrx);
rb_init(&np4rbtx);
// UP4 on UART3, RX 28 TX 30 on PIOD
up4 = uart_new(UART3, PIOD, 28, 30, &np4rbrx, &np4rbtx);
uart_init(&up4, 81, UART_IS_PERIPHERAL_A);
// RBs 5
rb_init(&np5rbrx);
rb_init(&np5rbtx);
// UP5 on UART4, RX 18 TX 19 on PIOD
up5 = uart_new(UART4, PIOD, 18, 19, &np5rbrx, &np5rbtx);
uart_init(&up5, 81, UART_IS_PERIPHERAL_C);
// currently: unit test, setup ABCDSR registers for uarts, do the main while loop below
while(1){
lightstoggle();
/*
uint8_t hello[] = {'h', 'e', 'l', 'l', 'o'};
if(!rb_empty(up1.rbrx)){
uart_sendchars_buffered(&up1, hello, 5);
uart_sendchar_buffered(&up1, rb_get(up1.rbrx));
for(int i = 0; i < 5; i ++){
if(!rb_empty(ups[i]->rbrx)){
uart_sendchars_buffered(ups[i], hello, 5);
uart_sendchar_buffered(ups[i], rb_get(ups[i]->rbrx));
}
}
*/
delay_ms(75);
}
}
......@@ -128,3 +174,18 @@ void UART0_Handler(void){
uart_handler(&up1);
}
void UART1_Handler(void){
uart_handler(&up2);
}
void UART2_Handler(void){
uart_handler(&up3);
}
void UART3_Handler(void){
uart_handler(&up4);
}
void UART4_Handler(void){
uart_handler(&up5);
}
\ No newline at end of file
......@@ -24,11 +24,19 @@ uartport_t uart_new(Uart *com, Pio *port, uint32_t pinrx, uint32_t pintx, ringbu
return uart;
}
void uart_init(uartport_t *uart, uint32_t baud){
void uart_init(uartport_t *uart, uint32_t baud, uint32_t abcdsr){
// PIO disable
uart->port->PIO_PDR = uart->pinrx_bm | uart->pintx_bm;
// abcdsr (global, do later)
// abcdsr A[0,0], B[1,0], C[0,1], D[1,1]
if(abcdsr == UART_IS_PERIPHERAL_B){
uart->port->PIO_ABCDSR[0] |= uart->pinrx_bm | uart->pintx_bm;
} else if (abcdsr == UART_IS_PERIPHERAL_C || abcdsr == UART_IS_PERIPHERAL_D){
uart->port->PIO_ABCDSR[1] |= uart->pinrx_bm | uart->pintx_bm;
}
if (abcdsr == UART_IS_PERIPHERAL_D){
uart->port->PIO_ABCDSR[0] |= uart->pinrx_bm | uart->pintx_bm;
}
// UART Registers
// mode register
......
......@@ -12,10 +12,10 @@
#include <asf.h>
#include "ringbuffer.h"
#define UART_IS_PERIPHERAL_A 0x01
#define UART_IS_PERIPHERAL_B 0x02
#define UART_IS_PERIPHERAL_C 0x03
#define UART_IS_PERIPHERAL_D 0x04
#define UART_IS_PERIPHERAL_A 0x00
#define UART_IS_PERIPHERAL_B 0x01
#define UART_IS_PERIPHERAL_C 0x02
#define UART_IS_PERIPHERAL_D 0x03
typedef struct{
Uart *com;
......@@ -32,7 +32,7 @@ typedef struct{
uartport_t uart_new(Uart *uart, Pio *port, uint32_t pinrx, uint32_t pintx, ringbuffer_t *rbrx, ringbuffer_t *rbtx);
void uart_init(uartport_t *uart, uint32_t baud);
void uart_init(uartport_t *uart, uint32_t baud, uint32_t abcdsr);
void uart_sendchar_polled(uartport_t *uart, uint8_t data);
void uart_sendchar_buffered(uartport_t *uart, uint8_t data);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment