Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
Jake Read
atkrouter
Commits
9f61f116
Commit
9f61f116
authored
Feb 23, 2018
by
Jake Read
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
begin apaport
parent
35abaa84
Changes
12
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
201 additions
and
63 deletions
+201
-63
embedded/mkrouter-v04/mkrouter-v04/Debug/Makefile
embedded/mkrouter-v04/mkrouter-v04/Debug/Makefile
+16
-9
embedded/mkrouter-v04/mkrouter-v04/Debug/makedep.mk
embedded/mkrouter-v04/mkrouter-v04/Debug/makedep.mk
+2
-0
embedded/mkrouter-v04/mkrouter-v04/mkrouter-v04.cproj
embedded/mkrouter-v04/mkrouter-v04/mkrouter-v04.cproj
+7
-1
embedded/mkrouter-v04/mkrouter-v04/src/apaport.c
embedded/mkrouter-v04/mkrouter-v04/src/apaport.c
+69
-0
embedded/mkrouter-v04/mkrouter-v04/src/apaport.h
embedded/mkrouter-v04/mkrouter-v04/src/apaport.h
+45
-0
embedded/mkrouter-v04/mkrouter-v04/src/hardware.h
embedded/mkrouter-v04/mkrouter-v04/src/hardware.h
+5
-0
embedded/mkrouter-v04/mkrouter-v04/src/main.c
embedded/mkrouter-v04/mkrouter-v04/src/main.c
+34
-30
embedded/mkrouter-v04/mkrouter-v04/src/pin.c
embedded/mkrouter-v04/mkrouter-v04/src/pin.c
+6
-7
embedded/mkrouter-v04/mkrouter-v04/src/pin.h
embedded/mkrouter-v04/mkrouter-v04/src/pin.h
+1
-1
embedded/mkrouter-v04/mkrouter-v04/src/ringbuffer.c
embedded/mkrouter-v04/mkrouter-v04/src/ringbuffer.c
+6
-1
embedded/mkrouter-v04/mkrouter-v04/src/uartport.c
embedded/mkrouter-v04/mkrouter-v04/src/uartport.c
+9
-13
embedded/mkrouter-v04/mkrouter-v04/src/uartport.h
embedded/mkrouter-v04/mkrouter-v04/src/uartport.h
+1
-1
No files found.
embedded/mkrouter-v04/mkrouter-v04/Debug/Makefile
View file @
9f61f116
This diff is collapsed.
Click to expand it.
embedded/mkrouter-v04/mkrouter-v04/Debug/makedep.mk
View file @
9f61f116
...
...
@@ -2,6 +2,8 @@
# Automatically-generated file. Do not edit or delete the file
################################################################################
src\apaport.c
src\pin.c
src\ringbuffer.c
...
...
embedded/mkrouter-v04/mkrouter-v04/mkrouter-v04.cproj
View file @
9f61f116
...
...
@@ -365,7 +365,6 @@
<Value>
../src/ASF/common/services/delay
</Value>
</ListValues>
</armgcc.compiler.directories.IncludePaths>
<armgcc.compiler.optimization.level>
Optimize (-O1)
</armgcc.compiler.optimization.level>
<armgcc.compiler.optimization.OtherFlags>
-fdata-sections
</armgcc.compiler.optimization.OtherFlags>
<armgcc.compiler.optimization.PrepareFunctionsForGarbageCollection>
True
</armgcc.compiler.optimization.PrepareFunctionsForGarbageCollection>
<armgcc.compiler.optimization.DebugLevel>
Maximum (-g3)
</armgcc.compiler.optimization.DebugLevel>
...
...
@@ -383,6 +382,7 @@
</ListValues>
</armgcc.linker.libraries.LibrarySearchPaths>
<armgcc.linker.optimization.GarbageCollectUnusedSections>
True
</armgcc.linker.optimization.GarbageCollectUnusedSections>
<armgcc.linker.memorysettings.ExternalRAM
/>
<armgcc.linker.miscellaneous.LinkerFlags>
-Wl,--entry=Reset_Handler -Wl,--cref -mthumb -T../src/ASF/sam/utils/linker_scripts/sams70/sams70n20/gcc/flash.ld
</armgcc.linker.miscellaneous.LinkerFlags>
<armgcc.assembler.general.IncludePaths>
<ListValues>
...
...
@@ -474,6 +474,12 @@
<Folder
Include=
"src\config\"
/>
</ItemGroup>
<ItemGroup>
<Compile
Include=
"src\apaport.c"
>
<SubType>
compile
</SubType>
</Compile>
<Compile
Include=
"src\apaport.h"
>
<SubType>
compile
</SubType>
</Compile>
<Compile
Include=
"src\hardware.h"
>
<SubType>
compile
</SubType>
</Compile>
...
...
embedded/mkrouter-v04/mkrouter-v04/src/apaport.c
0 → 100644
View file @
9f61f116
/*
* apaport.c
*
* Created: 2/23/2018 9:17:48 AM
* Author: Jake
*/
#include "apaport.h"
void
apaport_build
(
apaport_t
*
apap
,
uint8_t
portnum
,
uartport_t
*
uart
,
pin_t
*
stlr
,
pin_t
*
stlb
){
apap
->
uart
=
uart
;
apap
->
portnum
=
portnum
;
apap
->
stlr
=
stlr
;
apap
->
stlb
=
stlb
;
}
void
apaport_reset
(
apaport_t
*
apap
){
apap
->
packet_num
=
0
;
apap
->
packets_ready
=
0
;
apap
->
packet_state
=
APAPORT_OUTSIDE_PACKET
;
apap
->
packet_position
=
0
;
pin_set
(
apap
->
stlr
);
pin_set
(
apap
->
stlb
);
}
void
apaport_scan
(
apaport_t
*
apap
,
uint32_t
maxpackets
){
// scan through for completely received packets
while
(
apap
->
packets_ready
<=
maxpackets
&&
!
rb_empty
(
apap
->
uart
->
rbrx
)){
// pull bytes out of buffer and segment into packets
pin_clear
(
apap
->
stlb
);
delay_ms
(
15
);
pin_set
(
apap
->
stlb
);
delay_ms
(
15
);
apap
->
packets
[
apap
->
packet_num
][
apap
->
packet_position
]
=
rb_get
(
apap
->
uart
->
rbrx
);
apap
->
packet_position
++
;
if
(
apap
->
packet_position
>=
apap
->
packets
[
apap
->
packet_num
][
0
]){
// length is 1st byte, like array[n] not array[n-1]
// now volley for next pass
apap
->
packet_num
=
(
apap
->
packet_num
+
1
)
%
APAPORT_NUM_STATIC_PACKETS
;
// inc. and loop
apap
->
packets_ready
++
;
apap
->
packet_position
=
0
;
}
}
// end 1st scan for packets, now we know we have apaport->packet_num packets completely received
// handle packets
while
(
apap
->
packets_ready
>
0
){
uint32_t
p
=
(
apap
->
packet_num
+
APAPORT_NUM_STATIC_PACKETS
-
apap
->
packets_ready
)
%
APAPORT_NUM_STATIC_PACKETS
;
// handle these!
pin_clear
(
apap
->
stlr
);
delay_ms
(
150
);
pin_set
(
apap
->
stlr
);
delay_ms
(
150
);
// now to handle: 1st, a reply for debug of what we received
uart_sendchars_buffered
(
apap
->
uart
,
apap
->
packets
[
p
],
apap
->
packets
[
p
][
0
]);
//apap->packets[p][0]);
/*
now, handle:
- packet is for us [1]th element is pointer
- route pointer movement & add port incoming
- next port, and fire on
- floods
*/
apap
->
packets_ready
--
;
}
}
\ No newline at end of file
embedded/mkrouter-v04/mkrouter-v04/src/apaport.h
0 → 100644
View file @
9f61f116
/*
* apaport.h
*
* Created: 2/23/2018 9:17:34 AM
* Author: Jake
*/
#ifndef APAPORT_H_
#define APAPORT_H_
#include <asf.h>
#include "uartport.h"
#include "pin.h"
#define APAPORT_NUM_STATIC_PACKETS 4
#define APAPORT_OUTSIDE_PACKET 0
#define APAPORT_INSIDE_PACKET 1
#define APA_END_ADDR_DELIMITER 255
#define APA_ADDR_POINTER 254
#define APA_ADDR_FLOOD 253
typedef
struct
{
uartport_t
*
uart
;
pin_t
*
stlr
;
pin_t
*
stlb
;
uint8_t
portnum
;
// which port are we
uint32_t
packet_num
;
uint32_t
packet_position
;
uint32_t
packets_ready
;
uint32_t
packet_state
;
uint8_t
packets
[
APAPORT_NUM_STATIC_PACKETS
][
256
];
// packets for handling by app
}
apaport_t
;
void
apaport_build
(
apaport_t
*
apap
,
uint8_t
portnum
,
uartport_t
*
uart
,
pin_t
*
stlr
,
pin_t
*
stlb
);
void
apaport_reset
(
apaport_t
*
apap
);
void
apaport_scan
(
apaport_t
*
apap
,
uint32_t
maxpackets
);
#endif
/* APAPORT_H_ */
\ No newline at end of file
embedded/mkrouter-v04/mkrouter-v04/src/hardware.h
View file @
9f61f116
...
...
@@ -12,6 +12,7 @@
#include "pin.h"
#include "ringbuffer.h"
#include "uartport.h"
#include "apaport.h"
// status lights
pin_t
np1stlr
;
...
...
@@ -46,6 +47,10 @@ uartport_t up4;
uartport_t
up5
;
uartport_t
*
ups
[]
=
{
&
up1
,
&
up2
,
&
up3
,
&
up4
,
&
up5
};
// apaports
apaport_t
apap1
;
#endif
/* HARDWARE_H_ */
\ No newline at end of file
embedded/mkrouter-v04/mkrouter-v04/src/main.c
View file @
9f61f116
...
...
@@ -76,89 +76,92 @@ void setupinterrupts(void){
}
void
lightsetup
(
void
){
np1stlr
=
pin_new
(
PIOD
,
PIO_PER_P12
);
pin_init
(
&
np1stlr
,
PIOD
,
PIO_PER_P12
);
pin_output
(
&
np1stlr
);
np1stlb
=
pin_new
(
PIOA
,
PIO_PER_P2
);
pin_init
(
&
np1stlb
,
PIOA
,
PIO_PER_P2
);
pin_output
(
&
np1stlb
);
np2stlr
=
pin_new
(
PIOA
,
PIO_PER_P11
);
pin_init
(
&
np2stlr
,
PIOA
,
PIO_PER_P11
);
pin_output
(
&
np2stlr
);
np2stlb
=
pin_new
(
PIOD
,
PIO_PER_P20
);
pin_init
(
&
np2stlb
,
PIOD
,
PIO_PER_P20
);
pin_output
(
&
np2stlb
);
np3stlr
=
pin_new
(
PIOA
,
PIO_PER_P15
);
pin_init
(
&
np3stlr
,
PIOA
,
PIO_PER_P15
);
pin_output
(
&
np3stlr
);
np3stlb
=
pin_new
(
PIOD
,
PIO_PER_P27
);
pin_init
(
&
np3stlb
,
PIOD
,
PIO_PER_P27
);
pin_output
(
&
np3stlb
);
np4stlr
=
pin_new
(
PIOA
,
PIO_PER_P22
);
pin_init
(
&
np4stlr
,
PIOA
,
PIO_PER_P22
);
pin_output
(
&
np4stlr
);
np4stlb
=
pin_new
(
PIOA
,
PIO_PER_P8
);
pin_init
(
&
np4stlb
,
PIOA
,
PIO_PER_P8
);
pin_output
(
&
np4stlb
);
np5stlr
=
pin_new
(
PIOB
,
PIO_PER_P0
);
pin_init
(
&
np5stlr
,
PIOB
,
PIO_PER_P0
);
pin_output
(
&
np5stlr
);
np5stlb
=
pin_new
(
PIOB
,
PIO_PER_P1
);
pin_init
(
&
np5stlb
,
PIOB
,
PIO_PER_P1
);
pin_output
(
&
np5stlb
);
}
void
lightstoggle
(
void
){
for
(
int
i
=
0
;
i
<
10
;
i
++
){
for
(
int
i
=
2
;
i
<
10
;
i
++
){
pin_toggle
(
lights
[
i
]);
}
}
int
main
(
void
)
{
sysclk_init
();
// I think we can do 300, are at 150
board_init
();
setupperipherals
();
setupinterrupts
();
lightsetup
();
void
initports
(
void
){
// RBs 1
rb_init
(
&
np1rbrx
);
rb_init
(
&
np1rbtx
);
rb_init
(
&
np1rbtx
);
// UP1 on UART0, RX 9 TX 10 on PIOA
u
p1
=
uart_new
(
UART0
,
PIOA
,
9
,
10
,
&
np1rbrx
,
&
np1rbtx
);
u
art_build
(
&
up1
,
UART0
,
PIOA
,
9
,
10
,
&
np1rbrx
,
&
np1rbtx
);
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
u
p2
=
uart_new
(
UART1
,
PIOA
,
5
,
4
,
&
np2rbrx
,
&
np2rbtx
);
u
art_build
(
&
up2
,
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
u
p3
=
uart_new
(
UART2
,
PIOD
,
25
,
26
,
&
np3rbrx
,
&
np3rbtx
);
u
art_build
(
&
up3
,
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
u
p4
=
uart_new
(
UART3
,
PIOD
,
28
,
30
,
&
np4rbrx
,
&
np4rbtx
);
u
art_build
(
&
up4
,
UART3
,
PIOD
,
28
,
30
,
&
np4rbrx
,
&
np4rbtx
);
uart_init
(
&
up4
,
81
,
UART_IS_PERIPHERAL_A
);
// RBs 5
// RBs 5
rb_init
(
&
np5rbrx
);
rb_init
(
&
np5rbtx
);
// UP5 on UART4, RX 18 TX 19 on PIOD
u
p5
=
uart_new
(
UART4
,
PIOD
,
18
,
19
,
&
np5rbrx
,
&
np5rbtx
);
u
art_build
(
&
up5
,
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
int
main
(
void
){
sysclk_init
();
board_init
();
setupperipherals
();
setupinterrupts
();
lightsetup
();
initports
();
apaport_build
(
&
apap1
,
1
,
&
up1
,
&
np1stlr
,
&
np1stlb
);
apaport_reset
(
&
apap1
);
while
(
1
){
lightstoggle
();
apaport_scan
(
&
apap1
,
2
);
/*
uint8_t hello[] = {'h', 'e', 'l', 'l', 'o'};
for(int i = 0; i < 5; i ++){
if(!rb_empty(ups[i]->rbrx)){
...
...
@@ -166,6 +169,7 @@ int main (void)
uart_sendchar_buffered(ups[i], rb_get(ups[i]->rbrx));
}
}
*/
delay_ms
(
75
);
}
}
...
...
embedded/mkrouter-v04/mkrouter-v04/src/pin.c
View file @
9f61f116
...
...
@@ -8,13 +8,12 @@
#include "pin.h"
#include <asf.h>
pin_t
pin_new
(
Pio
*
port
,
uint32_t
pin_bitmask
){
pin_t
pin
;
pin
.
port
=
port
;
pin
.
pin_bm
=
pin_bitmask
;
return
pin
;
// don't return aggregates
// https://bytes.com/topic/c/answers/644271-aggregate-return-warnings
void
pin_init
(
pin_t
*
pin
,
Pio
*
port
,
uint32_t
pin_bitmask
){
pin
->
port
=
port
;
pin
->
pin_bm
=
pin_bitmask
;
}
void
pin_output
(
pin_t
*
pin
){
...
...
embedded/mkrouter-v04/mkrouter-v04/src/pin.h
View file @
9f61f116
...
...
@@ -20,7 +20,7 @@ typedef struct{
uint32_t
pin_bm
;
}
pin_t
;
pin_t
pin_new
(
Pio
*
port
,
uint32_t
pin_bitmask
);
void
pin_init
(
pin_t
*
pin
,
Pio
*
port
,
uint32_t
pin_bitmask
);
void
pin_output
(
pin_t
*
pin
);
// set as output
void
pin_set
(
pin_t
*
pin
);
...
...
embedded/mkrouter-v04/mkrouter-v04/src/ringbuffer.c
View file @
9f61f116
...
...
@@ -47,16 +47,21 @@ uint8_t rb_putchar(ringbuffer_t *rb, uint8_t data){
}
uint8_t
rb_putdata
(
ringbuffer_t
*
rb
,
uint8_t
*
data
,
uint8_t
size
){
/*
if(rb_freespace(rb) >= size){
// rb_freespace, not working?
return 0;
} else {
*/
uint8_t
i
=
0
;
while
(
i
<
size
){
// TODO: check if this is interrupt safe?
// should be...
rb_putchar
(
rb
,
data
[
i
]);
i
++
;
}
return
1
;
}
//
}
}
uint8_t
rb_get
(
ringbuffer_t
*
rb
){
...
...
embedded/mkrouter-v04/mkrouter-v04/src/uartport.c
View file @
9f61f116
...
...
@@ -7,21 +7,17 @@
#include "uartport.h"
uartport_t
uart_new
(
Uart
*
com
,
Pio
*
port
,
uint32_t
pinrx
,
uint32_t
pintx
,
ringbuffer_t
*
rbrx
,
ringbuffer_t
*
rbtx
){
uartport_t
uart
;
void
uart_build
(
uartport_t
*
uart
,
Uart
*
com
,
Pio
*
port
,
uint32_t
pinrx
,
uint32_t
pintx
,
ringbuffer_t
*
rbrx
,
ringbuffer_t
*
rbtx
){
uart
->
com
=
com
;
uart
->
port
=
port
;
uart
.
com
=
com
;
uart
.
port
=
port
;
uart
->
pinrx
=
pinrx
;
uart
->
pinrx_bm
=
1
<<
pinrx
;
uart
->
pintx
=
pintx
;
uart
->
pintx_bm
=
1
<<
pintx
;
uart
.
pinrx
=
pinrx
;
uart
.
pinrx_bm
=
1
<<
pinrx
;
uart
.
pintx
=
pintx
;
uart
.
pintx_bm
=
1
<<
pintx
;
uart
.
rbrx
=
rbrx
;
uart
.
rbtx
=
rbtx
;
return
uart
;
uart
->
rbrx
=
rbrx
;
uart
->
rbtx
=
rbtx
;
}
void
uart_init
(
uartport_t
*
uart
,
uint32_t
baud
,
uint32_t
abcdsr
){
...
...
embedded/mkrouter-v04/mkrouter-v04/src/uartport.h
View file @
9f61f116
...
...
@@ -30,7 +30,7 @@ typedef struct{
ringbuffer_t
*
rbtx
;
}
uartport_t
;
uartport_t
uart
_new
(
Uart
*
uart
,
Pio
*
port
,
uint32_t
pinrx
,
uint32_t
pintx
,
ringbuffer_t
*
rbrx
,
ringbuffer_t
*
rbtx
);
void
uart_build
(
uartport_t
*
uart
,
Uart
*
com
,
Pio
*
port
,
uint32_t
pinrx
,
uint32_t
pintx
,
ringbuffer_t
*
rbrx
,
ringbuffer_t
*
rbtx
);
void
uart_init
(
uartport_t
*
uart
,
uint32_t
baud
,
uint32_t
abcdsr
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment