Commit 62a8ce29 authored by Jake Read's avatar Jake Read

router feels solid

parent db68f1c0
......@@ -38,7 +38,6 @@ SUBDIRS := \
# Add inputs and outputs from these tool invocations to the build variables
C_SRCS += \
../apahandler.c \
../apaport.c \
../board_driver_serial.c \
../board_driver_usb.c \
......@@ -62,7 +61,6 @@ ASM_SRCS +=
OBJS += \
apahandler.o \
apaport.o \
board_driver_serial.o \
board_driver_usb.o \
......@@ -79,7 +77,6 @@ sam_ba_usb.o \
uartport.o
OBJS_AS_ARGS += \
apahandler.o \
apaport.o \
board_driver_serial.o \
board_driver_usb.o \
......@@ -96,7 +93,6 @@ sam_ba_usb.o \
uartport.o
C_DEPS += \
apahandler.d \
apaport.d \
board_driver_serial.d \
board_driver_usb.d \
......@@ -113,7 +109,6 @@ sam_ba_usb.d \
uartport.d
C_DEPS_AS_ARGS += \
apahandler.d \
apaport.d \
board_driver_serial.d \
board_driver_usb.d \
......@@ -171,8 +166,6 @@ LINKER_SCRIPT_DEP+= \
......
......@@ -2,8 +2,6 @@
# Automatically-generated file. Do not edit or delete the file
################################################################################
apahandler.c
apaport.c
board_driver_serial.c
......
......@@ -11,7 +11,10 @@
void apa_handle_packet(uint8_t *packet, uint8_t length){
// dirty debug reply
//sam_ba_port_put_data(packet, packet[0]);
// through packet
int i = 0;
int apa_handler_state = APA_HANDLER_OUTSIDE;
......
/*
* apahandler.h
*
* Created: 3/12/2018 11:55:40 AM
* Author: Jake
*/
#ifndef APAHANDLER_H_
#define APAHANDLER_H_
#include "sam.h"
#define APA_HANDLER_OUTSIDE 0
#define APA_HANDLER_INSIDE 1
#define DELIM_KEY_TEST 127 // toggles a light, to test network
#define DELIM_KEY_STEPS 128 // steps (steps) uint32_t, speed (steps/s) uint32_t, dir uint8_t
#define DELIM_KEY_BLOCK 129 // is 32 bit int
void apa_handle_packet(uint8_t *packet, uint8_t length);
void apa_return_packet(uint8_t *packet, uint8_t length);
#endif /* APAHANDLER_H_ */
\ No newline at end of file
......@@ -64,7 +64,9 @@ void apaport_scan(apaport_t *apap, uint32_t maxpackets){
// now to handle
// [p][0] is length of packet
if(apap->packets[p][1] == APA_ROUTE_POINTER){
apa_handle_packet(apap->packets[p], apap->packets[p][0]);
pin_set(&stlPacket);
sam_ba_port_put_data(apap->packets[p], apap->packets[p][0]);
//apa_handle_packet(apap->packets[p], apap->packets[p][0]);
} else if(apap->packets[p][1] == APA_ROUTE_FLOOD){
// loop through bytes to find pointer and increment
// now ship it out on all ports
......
......@@ -9,7 +9,6 @@
#ifndef APAPORT_H_
#define APAPORT_H_
#include "apahandler.h"
#include "uartport.h"
#include "pin.h"
......
......@@ -16,6 +16,8 @@
#include "uartport.h"
#include "apaport.h"
#include "sam_ba_monitor.h"
// For if-case init
#define HARDWARE_IS_APBA 0
......
......@@ -159,12 +159,6 @@
</ToolchainSettings>
</PropertyGroup>
<ItemGroup>
<Compile Include="apahandler.c">
<SubType>compile</SubType>
</Compile>
<Compile Include="apahandler.h">
<SubType>compile</SubType>
</Compile>
<Compile Include="apaport.c">
<SubType>compile</SubType>
</Compile>
......
......@@ -273,26 +273,58 @@ static void put_uint32(uint32_t n)
}
uint32_t tick = 0;
uint8_t data_out[3] = {12, 48, 64};
uint8_t data_out[3] = {12, 48, 64};
#define APA_CDC_NUM_STATIC_PACKETS 6
uint8_t packCDC[APA_CDC_NUM_STATIC_PACKETS][256]; // static memory buffer for packets
uint8_t packCDC_num = 0;
uint8_t packCDC_position = 0;
uint8_t packCDC_readyNum = 0;
static void sam_ba_monitor_loop(void)
{
// get bytes, handle..
length = sam_ba_getdata(ptr_monitor_if, data, SIZEBUFMAX);
pin_clear(&stlPacket);
// this should be better: but before we send we have to make sure COM is open, else port locked
if(length > 0 && !usbComOpen){
usbComOpen = 1;
pin_clear(&stlUsb);
uint8_t hello[2] = {0,0};
sam_ba_putdata(ptr_monitor_if, &hello, 2);
return;
}
// chunk packets into packCDC
if(length > 0 && usbComOpen){
pin_clear(&stlPacket);
for(int i = 0; i < length; i ++){
packCDC[packCDC_num][packCDC_position] = data[i];
packCDC_position ++;
if(packCDC_position >= packCDC[packCDC_num][0]){
packCDC_num = (packCDC_num + 1) % APA_CDC_NUM_STATIC_PACKETS;
packCDC_readyNum ++;
packCDC_position = 0;
}
}
}
// reply
sam_ba_putdata(ptr_monitor_if, data, length);
// handle all of the ready packets
while(packCDC_readyNum > 0){
uint8_t p = (packCDC_num + APA_CDC_NUM_STATIC_PACKETS - packCDC_readyNum) % APA_CDC_NUM_STATIC_PACKETS;
// we're going to forward them all, 1st byte is port out
uint8_t port = packCDC[p][1];
if(port > NUM_UPS){
port = NUM_UPS - 1; // if overrun, go on last port
}
uart_sendchars_buffered(ups[port], packCDC[p], packCDC[p][0]);
packCDC_readyNum --;
}
// reply USB direct to debug if USB coming thru
// sam_ba_putdata(ptr_monitor_if, data, length);
// have to implement APA code here? and watch for multipackets?
for(int i = 0; i < length; i ++, ptr++){
// apa
}
pin_set(&stlPacket);
// dirt nasty heartbeat
......
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