Ajout FishPeper

This commit is contained in:
Serge NOEL
2026-04-21 12:19:15 +02:00
parent 6744da3f88
commit 0c361a2440
2160 changed files with 589301 additions and 1 deletions

View File

@@ -0,0 +1,34 @@
/*
Copyright 2017 fishpepper <AT> gmail.com
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/>.
author: fishpepper <AT> gmail.com
*/
#include "hal_adc.h"
#include "debug.h"
#include "wdt.h"
void hal_adc_init(void) {
}
void hal_adc_process(void) {
}
uint8_t hal_adc_get_scaled(uint8_t ch) {
return 0;
}

View File

@@ -0,0 +1,29 @@
/*
Copyright 2017 fishpepper <AT> gmail.com
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/>.
author: fishpepper <AT> gmail.com
*/
#ifndef HAL_ADC_H_
#define HAL_ADC_H_
#include "main.h"
#include <stdint.h>
void hal_adc_init(void);
uint8_t hal_adc_get_scaled(uint8_t ch);
void hal_adc_process(void);
#endif // HAL_ADC_H_

View File

@@ -0,0 +1,253 @@
/*
Copyright 2017 fishpepper <AT> gmail.com
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/>.
author: fishpepper <AT> gmail.com
*/
#include "hal_cc25xx.h"
#include "hal_spi.h"
#include "hal_io.h"
#include "cc25xx.h"
#include "debug.h"
#include "timeout.h"
#include <string.h>
#include <stdio.h>
void hal_cc25xx_init(void) {
hal_spi_init();
hal_cc25xx_init_gpio();
}
static void hal_cc25xx_init_gpio(void) {
hal_cc25xx_enter_rxmode();
}
inline uint32_t hal_cc25xx_set_antenna(uint8_t id) {
return id;
}
const char *registers[] = {
"IOCFG2", // 0x00
"IOCFG1",
"IOCFG0",
"FIFOTHR",
"SYNC1",
"SYNC0",
"PKTLEN",
"PKTCTRL1",
"PKTCTRL0",
"ADDR",
"CHANNR",
"FSCTRL1",
"FSCTRL0",
"FREQ2",
"FREQ1",
"FREQ0",
"MDMCFG4", // 0x10
"MDMCFG3",
"MDMCFG2",
"MDMCFG1",
"MDMCFG0",
"DEVIATN",
"MCSM2",
"MCSM1",
"MCSM0",
"FOCCFG",
"BSCFG",
"AGCCTRL2",
"AGCCTRL1",
"AGCCTRL0",
"WOREVT1",
"WOREVT0",
"WORCTRL", // 0x20
"FREND1",
"FREND0",
"FSCAL3",
"FSCAL2",
"FSCAL1",
"FSCAL0",
"RCCTRL1",
"RCCTRL0",
"FSTEST",
"PTEST",
"AGCTEST",
"TEST2",
"TEST1",
"TEST0",
"RESERVED",
"PARTNUM", // 0x30
"VERSION",
"FREQEST",
"LQI",
"RSSI",
"MARCSTATE",
"WORTIME1",
"WORTIME0",
"PKTSTATUS",
"VCO_VC_DAC",
"TXBYTES",
"RXBYTES",
"RCCTRL1_STATUS",
"RCCTRL0_STATUS",
"PA_TABLE0" // 0x3E
};
inline void hal_cc25xx_set_gdo_mode(void) {
cc25xx_set_register(IOCFG0, 0x01); // 6);
// cc25xx_set_register(IOCFG1, ???);
cc25xx_set_register(IOCFG2, 0x01); // 6);
}
static int count = 0;
inline void hal_cc25xx_set_register(uint8_t address, uint8_t data) {
uint8_t buffer[2] = {address, data};
hal_spi_dma_xfer(buffer, sizeof(buffer));
// printf("\nset_register 0x%x (0x%x) '%s' data 0x%x\n", \
// address & 0x3f, address, registers[address & 0x3f], data);
}
inline uint8_t hal_cc25xx_get_register(uint8_t address) {
uint8_t buffer[2] = {address | 0x80, 0xff};
hal_spi_dma_xfer(buffer, sizeof(buffer));
// printf("\nget_register 0x%x (0x%x) '%s' got 0x%x\n", \
// address & 0x3f, address, registers[address & 0x3f], buffer[1]);
return buffer[1];
}
static const char *stobes[] = {
"RFST_SRES",
"RFST_SFSTXON",
"RFST_SXOFF",
"RFST_SCAL",
"RFST_SRX",
"RFST_STX",
"RFST_SIDLE",
"RFST_SWOR",
"RFST_SPWD",
"RFST_SFRX",
"RFST_SFTX",
"RFST_SWORRST",
"RFST_SNOP"
};
inline void hal_cc25xx_strobe(uint8_t address) {
uint8_t buffer[1] = {address};
hal_spi_dma_xfer(buffer, sizeof(buffer));
// printf("strobe 0x%x '%s' got 0x%x\n", address & 0x3f, stobes[address - 0x30], buffer[0]);
// debug("s"); debug_put_hex8(status); debug_put_newline();
}
uint8_t hal_cc25xx_get_status(void) {
uint8_t buffer[2] = {0xff, 0xff};
hal_spi_dma_xfer(buffer, sizeof(buffer));
return buffer[1];
}
uint8_t hal_cc25xx_transmission_completed(void) {
return 1; // return ((hal_cc25xx_get_status() & (0x70)) == CC2500_STATUS_STATE_RX);
}
inline void hal_cc25xx_enter_rxmode(void) {
hal_io_set_amp(0);
}
inline void hal_cc25xx_enter_txmode(void) {
hal_io_set_amp(1);
}
inline void hal_cc25xx_enable_receive(void) {
// switch on rx again
hal_cc25xx_enter_rxmode();
}
inline void hal_cc25xx_read_fifo(uint8_t *buf, uint8_t len) {
hal_cc25xx_register_read_multi(CC25XX_FIFO | READ_FLAG | BURST_FLAG, buf, len);
}
inline void hal_cc25xx_register_read_multi(uint8_t address, uint8_t *buffer, uint8_t len) {
uint8_t buffer2[len + 1];
buffer2[0] = address;
memset(buffer2+1, 0xFF, len);
hal_spi_dma_xfer(buffer2, len+1);
memcpy(buffer, buffer2+1, len);
}
inline void hal_cc25xx_register_write_multi(uint8_t address, uint8_t *buffer, uint8_t len) {
uint8_t buffer2[len + 1];
buffer2[0] = address | BURST_FLAG;
memcpy(buffer2+1, buffer, len);
hal_spi_dma_xfer(buffer2, len+1);
}
inline void hal_cc25xx_process_packet(volatile uint8_t *packet_received,
volatile uint8_t *buffer, uint8_t maxlen) {
if (hal_spi_get_gdo0() == 1) {
// data received, fetch data
// timeout_set_100us(5);
*packet_received = 0;
// there is a bug in the cc2500
// see p3 http:// www.ti.com/lit/er/swrz002e/swrz002e.pdf
// workaround: read len register very quickly twice:
uint8_t len1, len2, len, i;
// try this 10 times befor giving up:
for (i = 0; i < 10; i++) {
len1 = hal_cc25xx_get_register_burst(RXBYTES) & 0x7F;
len2 = hal_cc25xx_get_register_burst(RXBYTES) & 0x7F;
if (len1 == len2) break;
}
// valid len found?
if (len1 == len2 && len1 > 0) {
// debug("process_packet got: "); debug_put_uint8(len1);
// debug(" expecting: "); debug_put_uint8(maxlen);
len = len1;
// packet received, grab data
uint8_t tmp_buffer[len];
hal_cc25xx_read_fifo(tmp_buffer, len);
// only accept valid packet lenbghts:
if (len == maxlen) {
uint8_t i;
for (i = 0; i < maxlen; i++) {
buffer[i] = tmp_buffer[i];
}
*packet_received = 1;
// debug(" OK");
}
// debug("\n"); debug_flush();
} else {
// no, ignore this
len = 0;
}
}
}
void hal_cc25xx_transmit_packet(volatile uint8_t *buffer, uint8_t len) {
// flush tx fifo
hal_cc25xx_strobe(RFST_SFTX);
// copy to fifo
hal_cc25xx_register_write_multi(CC25XX_FIFO, (uint8_t *)buffer, buffer[0]+1);
// and send!
hal_cc25xx_strobe(RFST_STX);
}

View File

@@ -0,0 +1,188 @@
/*
Copyright 2017 fishpepper <AT> gmail.com
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/>.
author: fishpepper <AT> gmail.com
*/
#ifndef HAL_CC25XX_H_
#define HAL_CC25XX_H_
#include <stdint.h>
void hal_cc25xx_init(void);
void hal_cc25xx_set_register(uint8_t reg, uint8_t val);
uint8_t hal_cc25xx_get_register(uint8_t address);
void hal_cc25xx_strobe(uint8_t val);
void hal_cc25xx_enable_receive(void);
void hal_cc25xx_enable_transmit(void);
void hal_cc25xx_enter_rxmode(void);
void hal_cc25xx_enter_txmode(void);
#define hal_cc25xx_rx_sleep() { delay_us(1352); }
#define hal_cc25xx_tx_sleep() { delay_us(1250); }
// not used on d4rii
#define hal_cc25xx_disable_rf_interrupt() {}
#define hal_cc25xx_setup_rf_dma(mode) {}
#define hal_cc25xx_partnum_valid(p, v) ((p == 0x80) && (v = 0x03))
uint8_t hal_cc25xx_get_status(void);
static void hal_cc25xx_init_gpio(void);
uint32_t hal_cc25xx_set_antenna(uint8_t id);
void hal_cc25xx_set_gdo_mode(void);
uint8_t hal_cc25xx_get_gdo_status(void);
void hal_cc25xx_process_packet(volatile uint8_t *packet_received,
volatile uint8_t *buffer, uint8_t maxlen);
void hal_cc25xx_transmit_packet(volatile uint8_t *buffer, uint8_t len);
void hal_cc25xx_read_fifo(uint8_t *buf, uint8_t len);
void hal_cc25xx_register_read_multi(uint8_t address, uint8_t *buffer, uint8_t len);
uint8_t hal_cc25xx_transmission_completed(void);
// adress checks
#define CC2500_PKTCTRL1_FLAG_ADR_CHECK_00 ((0<<1) | (0<<0))
#define CC2500_PKTCTRL1_FLAG_ADR_CHECK_01 ((0<<1) | (1<<0))
#define CC2500_PKTCTRL1_FLAG_ADR_CHECK_10 ((1<<1) | (0<<0))
#define CC2500_PKTCTRL1_FLAG_ADR_CHECK_11 ((1<<1) | (1<<0))
// append status bytes?
#define CC2500_PKTCTRL1_APPEND_STATUS (1<<2)
// crc autoflush
#define CC2500_PKTCTRL1_CRC_AUTOFLUSH (1<<3)
// Flags
#define BURST_FLAG 0b01000000
#define WRITE_FLAG 0b00000000
#define READ_FLAG 0b10000000
// Definitions for burst/single access to registers
#define CC2500_WRITE_SINGLE 0x00
#define CC2500_WRITE_BURST 0x40
#define CC2500_READ_SINGLE 0x80
#define CC2500_READ_BURST 0xC0
#define CC2500_STATUS_STATE_IDLE (0<<4)
#define CC2500_STATUS_STATE_RX (1<<4)
#define CC2500_STATUS_STATE_TX (2<<4)
#define CC2500_STATUS_STATE_FSTXON (3<<4)
#define CC2500_STATUS_STATE_CALIBRATE (4<<4)
#define CC2500_STATUS_STATE_SETTLING (5<<4)
#define CC2500_STATUS_STATE_RXFIFO_OVF (6<<4)
#define CC2500_STATUS_STATE_TXFIFO_OVF (7<<4)
#define hal_cc25xx_get_register_burst(x) hal_cc25xx_get_register(x | READ_FLAG | BURST_FLAG)
// strobes
#define RFST_SRES 0x30
#define RFST_SFSTXON 0x31
#define RFST_SXOFF 0x32
#define RFST_SCAL 0x33
#define RFST_SRX 0x34
#define RFST_STX 0x35
#define RFST_SIDLE 0x36
#define RFST_SWOR 0x38
#define RFST_SPWD 0x39
#define RFST_SFRX 0x3A
#define RFST_SFTX 0x3B
#define RFST_SWORRST 0x3C
#define RFST_SNOP 0x3D
// Status registers
#define PARTNUM 0x30|BURST_FLAG
#define VERSION 0x31|BURST_FLAG
#define FREQEST 0x32|BURST_FLAG
#define LQI 0x33|BURST_FLAG
#define RSSI 0x34|BURST_FLAG
#define MARCSTATE 0x35|BURST_FLAG
#define WORTIME1 0x36|BURST_FLAG
#define WORTIME0 0x37|BURST_FLAG
#define PKTSTATUS 0x38|BURST_FLAG
#define VCO_VC_DAC 0x39|BURST_FLAG
#define TXBYTES 0x3A|BURST_FLAG
#define RXBYTES 0x3B|BURST_FLAG
#define RCCTRL1_STATUS 0x3C|BURST_FLAG
#define RCCTRL0_STATUS 0x3D|BURST_FLAG
// Status byte states
#define STB_IDLE 0x00
#define STB_RX 0x10
#define STB_TX 0x20
#define STB_FSTXON 0x30
#define STB_CALIBRATE 0x40
#define STB_SETTLING 0x50
#define STB_RX_OVF 0x60
#define STB_TX_UNDF 0x70
// Config registers addresses
#define IOCFG2 0x00
#define IOCFG1 0x01
#define IOCFG0 0x02
#define FIFOTHR 0x03
#define SYNC1 0x04
#define SYNC0 0x05
#define PKTLEN 0x06
#define PKTCTRL1 0x07
#define PKTCTRL0 0x08
#define ADDR 0x09
#define CHANNR 0x0A
#define FSCTRL1 0x0B
#define FSCTRL0 0x0C
#define FREQ2 0x0D
#define FREQ1 0x0E
#define FREQ0 0x0F
#define MDMCFG4 0x10
#define MDMCFG3 0x11
#define MDMCFG2 0x12
#define MDMCFG1 0x13
#define MDMCFG0 0x14
#define DEVIATN 0x15
#define MCSM2 0x16
#define MCSM1 0x17
#define MCSM0 0x18
#define FOCCFG 0x19
#define BSCFG 0x1A
#define AGCCTRL2 0x1B
#define AGCCTRL1 0x1C
#define AGCCTRL0 0x1D
#define WOREVT1 0x1E
#define WOREVT0 0x1F
#define WORCTRL 0x20
#define FREND1 0x21
#define FREND0 0x22
#define FSCAL3 0x23
#define FSCAL2 0x24
#define FSCAL1 0x25
#define FSCAL0 0x26
#define RCCTRL1 0x27
#define RCCTRL0 0x28
#define FSTEST 0x29
#define PTEST 0x2A
#define AGCTEST 0x2B
#define TEST2 0x2C
#define TEST1 0x2D
#define TEST0 0x2E
#define PA_TABLE0 0x3E
// FIFO
#define CC25XX_FIFO 0x3F
#endif // HAL_CC25XX_H_

View File

@@ -0,0 +1,7 @@
#ifndef __HAL_CLOCKSOURCE_H__
#define __HAL_CLOCKSOURCE_H__
// no necessary for stm32, it is done in system startup
#define hal_clocksource_init() {}
#endif // __HAL_CLOCKSOURCE_H__

View File

@@ -0,0 +1,56 @@
/*
Copyright 2017 fishpepper <AT> gmail.com
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/>.
author: fishpepper <AT> gmail.com
*/
#include "hal_debug.h"
#include "debug.h"
#include "led.h"
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
void hal_debug_init(void) {
}
void hal_debug_init_nvic(uint8_t enable) {
}
static void hal_debug_init_mode(void) {
}
static void hal_debug_enable(void) {
}
void hal_debug_start_transmission(uint8_t ch) {
fwrite(&ch, 1, 1, stdout);
}
void hal_debug_int_enable(void) {
}
uint8_t hal_debug_int_enabled(void) {
return 0;
}
static void hal_debug_init_gpio(void) {
}
static void hal_debug_init_rcc(void) {
}

View File

@@ -0,0 +1,37 @@
/*
Copyright 2017 fishpepper <AT> gmail.com
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/>.
author: fishpepper <AT> gmail.com
*/
#ifndef HAL_DEBUG_H_
#define HAL_DEBUG_H_
#include <stdint.h>
void hal_debug_init(void);
void hal_debug_start_transmission(uint8_t ch);
uint8_t hal_debug_int_enabled(void);
void hal_debug_int_enable(void);
#define hal_debug_int_disable() {}
#define DEBUG_ISR(void) hal_debug_tx_interrupt(void)
#define HAL_DEBUG_ISR_FLAG_SET() (1)
#define HAL_DEBUG_ISR_CLEAR_FLAG() { }
#define HAL_DEBUG_ISR_DISABLE() { }
#define HAL_DEBUG_TX_DATA(data) { }
#endif // HAL_DEBUG_H_

View File

@@ -0,0 +1,15 @@
#ifndef __HAL_DEFINES_H__
#define __HAL_DEFINES_H__
#define EXTERNAL_MEMORY
#define EXTERNAL_DATA
#define HI(a) (uint8_t) ((uint16_t)(a) >> 8 )
#define LO(a) (uint8_t) (uint16_t)(a)
#define SET_WORD(H, L, val) { (H) = HI(val); (L) = LO(val); }
// necessary for timer registers. todo: check if necessary for others as well...
#define SET_WORD_LO_FIRST(H, L, val) {(L) = LO(val); (H) = HI(val); }
#define UNUSED(x) (void)(x);
#endif // __HAL_DEFINES_H__

View File

@@ -0,0 +1,9 @@
#ifndef __HAL_DELAY_H__
#define __HAL_DELAY_H__
#include "hal_timeout.h"
#define hal_delay_us(us) hal_timeout_delay_us(us)
#define hal_delay_ms(ms) hal_timeout_delay_us((ms) * 1000)
#endif // __HAL_DELAY_H__

View File

@@ -0,0 +1 @@
/* not used by rasp */

133
OpenSky/arch/rasp/hal_io.c Normal file
View File

@@ -0,0 +1,133 @@
/*
Copyright 2017 fishpepper <AT> gmail.com
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/>.
author: fishpepper <AT> gmail.com
*/
#include "hal_io.h"
#include "hal_cc25xx.h"
#include "delay.h"
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <unistd.h>
#include <sched.h>
#define BLOCK_SIZE (4*1024)
// I/O access
volatile static unsigned *gpio;
// GPIO setup macros. Always use INP_GPIO(x) before using OUT_GPIO(x) or SET_GPIO_ALT(x,y)
#define INP_GPIO(g) *(gpio+((g)/10)) &= ~(7 << (((g) % 10)*3))
#define OUT_GPIO(g) *(gpio+((g)/10)) |= (1 << (((g)% 10)*3))
#define SET_GPIO_ALT(g, a) *(gpio+(((g)/10))) |= \
(((a) <= 3 ? (a) + 4:(a) == 4 ? 3 : 2) << (((g) % 10) * 3))
#define GPIO_SET *(gpio + 7) // sets bits which are 1 ignores bits which are 0
#define GPIO_CLR *(gpio + 10) // clears bits which are 1 ignores bits which are 0
#define GET_GPIO(g) (*(gpio + 13) & (1 << g)) // 0 if LOW, (1<<g) if HIGH
#define GPIO_PULL *(gpio + 37) // Pull up/pull down
#define GPIO_PULLCLK0 *(gpio + 38) // Pull up/pull down clock
void setup_io() {
void *gpio_map;
int mem_fd;
/* open /dev/mem */
if ((mem_fd = open("/dev/gpiomem", O_RDWR | O_SYNC | O_CLOEXEC) ) < 1) {
printf("can't open /dev/gpiomem \n");
exit(-1);
}
/* mmap GPIO */
gpio_map = mmap(
NULL, // Any adddress in our space will do
BLOCK_SIZE, // Map length
PROT_READ|PROT_WRITE, // Enable reading & writting to mapped memory
MAP_SHARED, // Shared with other processes
mem_fd, // File to map
0x200000); // GPIO controller
close(mem_fd); // No need to keep mem_fd open after mmap
if (gpio_map == MAP_FAILED) {
printf("mmap error %d\n", (int)gpio_map); // errno also set!
exit(-1);
}
// Always use volatile pointer!
gpio = (volatile unsigned *)gpio_map;
}
#define GDO0 23
#define LNA 2
#define PA 3
#define PPM 21
#define BIND 26
int hal_spi_get_gdo0(void) {
int res = GET_GPIO(GDO0);
if (res != 0)
return res != 0;
}
void hal_io_init(void) {
struct sched_param param;
param.sched_priority = sched_get_priority_max(SCHED_FIFO);
if (sched_setscheduler(0, SCHED_FIFO, &param) == -1) {
printf("Unable to set scheduler priority, this might impact your performance.");
}
setup_io();
INP_GPIO(GDO0); // must use INP_GPIO before we can use OUT_GPIO
INP_GPIO(LNA);
INP_GPIO(PA);
OUT_GPIO(LNA);
OUT_GPIO(PA);
OUT_GPIO(PPM);
OUT_GPIO(PPM);
INP_GPIO(BIND);
}
void hal_io_set_amp(int pa) {
if (pa == HAL_PA) {
GPIO_CLR = 1 << LNA;
delay_us(20);
GPIO_SET = 1 << PA;
delay_us(5);
} else {
GPIO_CLR = 1 << PA;
delay_us(20);
GPIO_SET = 1 << LNA;
delay_us(5);
}
}
void hal_io_set_ppm(int state) {
if (state)
GPIO_SET = 1 << PPM;
else
GPIO_CLR = 1 << PPM;
}
uint8_t hal_io_bind_request(void) {
return !!GET_GPIO(BIND);
}

View File

@@ -0,0 +1,35 @@
/*
Copyright 2017 fishpepper <AT> gmail.com
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/>.
author: fishpepper <AT> gmail.com
*/
#ifndef HAL_IO_H_
#define HAL_IO_H_
#include <stdint.h>
void hal_io_init(void);
uint8_t hal_io_bind_request(void);
int hal_spi_get_gdo0(void);
#define HAL_PA 1
#define HAL_LNA 0
void hal_io_set_amp(int pa);
void hal_io_set_ppm(int state);
#endif // HAL_IO_H_

View File

@@ -0,0 +1,19 @@
#ifndef __HAL_LED__H_
#define __HAL_LED__H_
#include <stdint.h>
void hal_led_init(uint16_t pin);
#define hal_led_green_init() {}
#define hal_led_green_on() {}
#define hal_led_green_off() {}
#define hal_led_green_toggle() {}
#define hal_led_red_init() {}
#define hal_led_red_on() {}
#define hal_led_red_off() {}
#define hal_led_red_toggle() {}
#endif // __HAL_LED__H_

View File

@@ -0,0 +1,71 @@
/*
Copyright 2017 fishpepper <AT> gmail.com
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/>.
author: fishpepper <AT> gmail.com
*/
#include "hal_ppm.h"
#include "hal_io.h"
#include "hal_timeout.h"
#include "ppm.h"
#include "wdt.h"
#include "led.h"
#if SBUS_ENABLED == 1
void hal_ppm_init(void) {
}
void hal_ppm_tick() {
}
#else
static int state = 1;
static int failsafe = 0;
void hal_ppm_init(void) {
hal_io_set_ppm(state);
}
void hal_ppm_failsafe_enter(void) {
failsafe = 1;
}
void hal_ppm_failsafe_exit(void) {
failsafe = 0;
}
void hal_ppm_update_cvalue(int us) {
// Keep singal up, until the last 200ms of the count.
hal_timeout_add_ppm(us - HAL_PPM_US_TO_TICKCOUNT(200));
}
void hal_ppm_tick() {
if (state == 1) {
state = 0;
if (!failsafe)
hal_io_set_ppm(state);
// Then lower the signal for another 200ms..
hal_timeout_add_ppm(HAL_PPM_US_TO_TICKCOUNT(200));
} else {
state = 1;
if (!failsafe)
hal_io_set_ppm(state);
// Call the code, that will call hal_ppm_update_cvalue back to us.
hal_ppm_irq_callback();
}
}
#endif // SBUS_ENABLED

View File

@@ -0,0 +1,43 @@
/*
Copyright 2017 fishpepper <AT> gmail.com
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/>.
author: fishpepper <AT> gmail.com
*/
#ifndef HAL_PPM_H_
#define HAL_PPM_H_
void hal_ppm_init(void);
void hal_ppm_failsafe_exit(void);
void hal_ppm_failsafe_enter(void);
void hal_ppm_tick();
void hal_ppm_update_cvalue(int us);
void hal_ppm_irq_callback(void);
#define HAL_PPM_US_TO_TICKCOUNT(us) ((us * 1)-1)
#define HAL_PPM_FRSKY_TO_TICKCOUNT(_frsky) ((_frsky)*2*2/3)
#define PPM_TIMER_ISR(void) hal_ppm_irq_callback(void)
#define HAL_PPM_UPDATE_CCVALUE(x) hal_ppm_update_cvalue(x)
#define HAL_PPM_ISR_DISABLE() { }
#define HAL_PPM_ISR_ENABLE() { }
#define HAL_PPM_ISR_FLAG_SET() (1)
#define HAL_PPM_ISR_CLEAR_FLAG() {}
#endif // HAL_PPM_H_

View File

@@ -0,0 +1,66 @@
/*
Copyright 2017 fishpepper <AT> gmail.com
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/>.
author: fishpepper <AT> gmail.com
*/
#include <stdio.h>
#include <unistd.h> // Used for UART
#include <fcntl.h> // Used for UART
#include <asm/termios.h> // Used for UART
#include "hal_sbus.h"
#include "debug.h"
#include "delay.h"
#include "sbus.h"
#if SBUS_ENABLED
static int uart0_filestream = -1;
void hal_sbus_init(EXTERNAL_MEMORY uint8_t *sbus_data_ptr) {
// open in non blocking read/write mode
uart0_filestream = open("/dev/ttyAMA0", O_WRONLY | O_NOCTTY | O_NDELAY);
if (uart0_filestream == -1) {
printf("Error - Unable to open UART. Ensure it is not in use by another application\n");
}
// USART configuration:
// 100000bps inverted serial stream, 8 bits, even parity, 2 stop bits
// no hw flow control
struct termios2 options;
options.c_cflag = BOTHER | CS8 | CLOCAL | PARENB | CSTOPB;
options.c_iflag = 0;
options.c_oflag = 0;
options.c_lflag = 0;
options.c_ispeed = 100000;
options.c_ospeed = 100000;
if (ioctl(uart0_filestream, TCSETS2, &options) != 0) {
printf("ioctl TCSETS2 failed");
}
}
void hal_sbus_start_transmission(uint8_t *data, uint8_t len) {
if (uart0_filestream != -1) {
int count = write(uart0_filestream, data, len);
if (count < len) {
printf("UART TX error sent %u of %u\n", count, len);
}
// printf("%d bytes written\n", len);
}
}
#endif // SBUS_ENABLED

View File

@@ -0,0 +1,38 @@
/*
Copyright 2017 fishpepper <AT> gmail.com
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/>.
author: fishpepper <AT> gmail.com
*/
#ifndef HAL_SBUS_H_
#define HAL_SBUS_H_
#include <stdint.h>
#include "hal_defines.h"
void hal_sbus_init(EXTERNAL_MEMORY uint8_t *data_ptr);
void hal_sbus_start_transmission(uint8_t *buffer, uint8_t len);
// this helper routine will invert the data
// stored in buffer in case the sbus is set
// to inverted
#if SBUS_INVERTED
#define HAL_SBUS_PREPARE_DATA(a) (0xFF ^ (a))
#else
#define HAL_SBUS_PREPARE_DATA(a) (a)
#endif // SBUS_INVERTED
#endif // HAL_SBUS_H_

View File

@@ -0,0 +1,32 @@
/*
Copyright 2017 fishpepper <AT> gmail.com
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/>.
author: fishpepper <AT> gmail.com
*/
#include "hal_soft_serial.h"
#include "soft_serial.h"
#include "debug.h"
#include "delay.h"
#include "led.h"
#include "wdt.h"
#include "config.h"
#include "hal_cc25xx.h"
void hal_soft_serial_init(void) {
}

View File

@@ -0,0 +1,31 @@
/*
Copyright 2017 fishpepper <AT> gmail.com
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/>.
author: fishpepper <AT> gmail.com
*/
#ifndef HAL_SOFT_SERIAL_H_
#define HAL_SOFT_SERIAL_H_
#include "soft_serial.h"
#include "config.h"
void hal_soft_serial_init(void);
#define HUB_TELEMETRY_PIN_LO() (0)
#define HUB_TELEMETRY_PIN_HI() (!HUB_TELEMETRY_PIN_LO())
#endif // HAL_SOFT_SERIAL_H_

118
OpenSky/arch/rasp/hal_spi.c Normal file
View File

@@ -0,0 +1,118 @@
/*
Copyright 2017 fishpepper <AT> gmail.com
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/>.
author: fishpepper <AT> gmail.com
*/
#include <stdint.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <linux/types.h>
#include <linux/spi/spidev.h>
#include "hal_spi.h"
static void pabort(const char *s) {
perror(s);
abort();
}
static const char *device = "/dev/spidev0.0";
static uint8_t bits = 8;
static uint32_t speed = 1000000;
static int fd = -1;
static uint32_t mode = 0;
static uint16_t delay = 20;
void hal_spi_init(void) {
int ret = 0;
/*
* Open device
*/
fd = open(device, O_RDWR);
if (fd < 0)
pabort("can't open device");
/*
* spi mode
*/
ret = ioctl(fd, SPI_IOC_WR_MODE, &mode);
if (ret == -1)
pabort("can't set spi mode");
ret = ioctl(fd, SPI_IOC_RD_MODE, &mode);
if (ret == -1)
pabort("can't get spi mode");
/*
* bits per word
*/
ret = ioctl(fd, SPI_IOC_WR_BITS_PER_WORD, &bits);
if (ret == -1)
pabort("can't set bits per word");
ret = ioctl(fd, SPI_IOC_RD_BITS_PER_WORD, &bits);
if (ret == -1)
pabort("can't get bits per word");
/*
* max speed hz
*/
ret = ioctl(fd, SPI_IOC_WR_MAX_SPEED_HZ, &speed);
if (ret == -1)
pabort("can't set max speed hz");
ret = ioctl(fd, SPI_IOC_RD_MAX_SPEED_HZ, &speed);
if (ret == -1)
pabort("can't get max speed hz");
printf("spi: mode: 0x%x\n", mode);
printf("spi: bits per word: %d\n", bits);
printf("spi: max speed: %d Hz (%f MHz)\n", speed, speed/1000000.0);
}
void hal_spi_dma_xfer(uint8_t *buffer, uint8_t len) {
int ret;
uint8_t rx;
#if LOG_SPI
int i;
for (i=0; i < len; i++)
fprintf(stderr, "> %x\n", buffer[i]);
#endif // LOG_SPI
struct spi_ioc_transfer tr = {
.tx_buf = (uint64_t)buffer,
.rx_buf = (uint64_t)buffer,
.len = len,
.delay_usecs = delay,
.speed_hz = speed,
.bits_per_word = bits,
};
ret = ioctl(fd, SPI_IOC_MESSAGE(1), &tr);
if (ret < 1)
pabort("can't send spi message");
#if LOG_SPI
for (i=0; i < len; i++)
fprintf(stderr, "< %x\n", buffer[i]);
fprintf(stderr, "\n");
#endif // LOG_SPI
}

View File

@@ -0,0 +1,30 @@
/*
Copyright 2017 fishpepper <AT> gmail.com
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/>.
author: fishpepper <AT> gmail.com
*/
#ifndef HAL_SPI_H_
#define HAL_SPI_H_
#include <stdint.h>
#include "config.h"
#include "delay.h"
void hal_spi_init(void);
void hal_spi_dma_xfer(uint8_t *buffer, uint8_t len);
#endif // HAL_SPI_H_

View File

@@ -0,0 +1,49 @@
/*
Copyright 2017 fishpepper <AT> gmail.com
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/>.
author: fishpepper <AT> gmail.com
*/
#include "hal_storage.h"
#include "debug.h"
#include "main.h"
#include "delay.h"
#include "wdt.h"
#include <stdio.h>
#include <string.h>
void hal_storage_init(void) {
debug("hal_storage: init\n"); debug_flush();
}
void hal_storage_write(uint8_t *buffer, uint16_t len) {
FILE *f = fopen("flash_storage.bin", "w");
fwrite(buffer, len, 1, f);
fclose(f);
}
void hal_storage_read(uint8_t *storage_ptr, uint16_t len) {
FILE *f = fopen("flash_storage.bin", "r");
if (!f) {
memset(storage_ptr, 0, len);
return;
}
fread(storage_ptr, len, 1, f);
fclose(f);
}

View File

@@ -0,0 +1,29 @@
/*
Copyright 2017 fishpepper <AT> gmail.com
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/>.
author: fishpepper <AT> gmail.com
*/
#ifndef HAL_STORAGE_H_
#define HAL_STORAGE_H_
#include <stdint.h>
#include "config.h"
void hal_storage_init(void);
void hal_storage_write(uint8_t *buffer, uint16_t len);
void hal_storage_read(uint8_t *storage_ptr, uint16_t len);
#endif // HAL_STORAGE_H_

View File

@@ -0,0 +1,154 @@
/*
Copyright 2017 fishpepper <AT> gmail.com
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/>.
author: fishpepper <AT> gmail.com
*/
#include "hal_timeout.h"
#include "hal_ppm.h"
#include "debug.h"
#include "wdt.h"
#include <time.h>
#include <string.h>
#include <errno.h>
struct timespec timer_1;
struct timespec timer_2;
struct timespec timer_ppm;
void hal_timeout_init(void) {
memset(&timer_1, 0, sizeof(timer_1));
memset(&timer_2, 0, sizeof(timer_2));
clock_gettime(CLOCK_REALTIME, &timer_ppm);
}
/* Returns true if a is greather then b */
static inline uint8_t timeval_gt(const struct timespec *a, const struct timespec *b) {
if (a->tv_sec > b->tv_sec)
return 1;
if (a->tv_sec == b->tv_sec && a->tv_nsec > b->tv_nsec)
return 1;
return 0;
}
static inline void timer_add(struct timespec *timer, int us) {
timer->tv_nsec += us * 1000;
if (timer->tv_nsec > 1000000000) {
timer->tv_nsec -= 1000000000;
timer->tv_sec += 1;
}
}
/* Subtract the struct timeval values X and Y,
storing the result in RESULT.
Return 1 if the difference is negative, otherwise 0. */
static inline int timeval_subtract(struct timespec *result,
struct timespec *x, struct timespec *y) {
/* Perform the carry for the later subtraction by updating y. */
if (x->tv_nsec < y->tv_nsec) {
int nsec = (y->tv_nsec - x->tv_nsec) / 1000000000 + 1;
y->tv_nsec -= 1000000000 * nsec;
y->tv_sec += nsec;
}
if (x->tv_nsec - y->tv_nsec > 1000000000) {
int nsec = (x->tv_nsec - y->tv_nsec) / 1000000000;
y->tv_nsec += 1000000000 * nsec;
y->tv_sec -= nsec;
}
/* Compute the time remaining to wait.
tv_nsec is certainly positive. */
result->tv_sec = x->tv_sec - y->tv_sec;
result->tv_nsec = x->tv_nsec - y->tv_nsec;
/* Return 1 if result is negative. */
return x->tv_sec < y->tv_sec;
}
void hal_timeout_set_100us(uint32_t hus) {
clock_gettime(CLOCK_REALTIME, &timer_1);
timer_add(&timer_1, hus * 100);
}
void hal_timeout2_set_100us(uint32_t hus) {
clock_gettime(CLOCK_REALTIME, &timer_2);
timer_add(&timer_2, hus * 100);
}
void hal_timeout_set(uint32_t ms) {
clock_gettime(CLOCK_REALTIME, &timer_1);
timer_add(&timer_1, ms * 1000);
}
uint8_t hal_timeout_timed_out(void) {
struct timespec now;
clock_gettime(CLOCK_REALTIME, &now);
if (timeval_gt(&now, &timer_ppm)) {
hal_ppm_tick();
}
return timeval_gt(&now, &timer_1);
}
uint8_t hal_timeout2_timed_out(void) {
struct timespec now;
clock_gettime(CLOCK_REALTIME, &now);
if (timeval_gt(&now, &timer_ppm)) {
hal_ppm_tick();
}
return timeval_gt(&now, &timer_2);
}
void hal_timeout_delay_us(int32_t timeout_us) {
struct timespec now, sleep, delay_timer, rem;
clock_gettime(CLOCK_REALTIME, &now);
memcpy(&delay_timer, &now, sizeof(struct timespec));
timer_add(&delay_timer, timeout_us);
do {
/* If ppm happens before delay timer times out. (delay_timer gt timer_ppm) */
if (timeval_gt(&delay_timer, &timer_ppm)) {
/* Calculate how far to sleep */
if (timeval_subtract(&sleep, &now, &timer_ppm) > 0) {
nanosleep(&sleep, &rem);
}
/* Get current time again */
clock_gettime(CLOCK_REALTIME, &now);
if (timeval_gt(&now, &timer_ppm)) {
hal_ppm_tick();
}
/* Loop, as a new ppm timer might be scheduled again before the delay ends */
continue;
}
/* Calculate how long to sleep */
if (timeval_subtract(&sleep, &now, &delay_timer) > 0) {
nanosleep(&sleep, &rem);
}
} while (0);
}
void hal_timeout_add_ppm(uint32_t us) {
timer_add(&timer_ppm, us);
}

View File

@@ -0,0 +1,40 @@
/*
Copyright 2017 fishpepper <AT> gmail.com
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/>.
author: fishpepper <AT> gmail.com
*/
#ifndef HAL_TIMEOUT_H_
#define HAL_TIMEOUT_H_
#include <stdint.h>
void hal_timeout_init(void);
void hal_timeout_set(uint32_t ms);
void hal_timeout_set_100us(uint32_t hus);
uint8_t hal_timeout_timed_out(void);
void hal_timeout_delay_us(int32_t timeout);
void hal_timeout2_set(uint32_t ms);
void hal_timeout2_set_100us(uint32_t hus);
uint8_t hal_timeout2_timed_out(void);
void hal_timeout_add_ppm(uint32_t us);
// void hal_timeout_delay_100us(uint32_t timeout);
uint32_t hal_timeout_time_remaining(void);
#endif // HAL_TIMEOUT_H_

View File

@@ -0,0 +1,66 @@
/*
Copyright 2017 fishpepper <AT> gmail.com
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/>.
author: fishpepper <AT> gmail.com
*/
#include <stdio.h>
#include <unistd.h> // Used for UART
#include <fcntl.h> // Used for UART
#include <asm/termios.h> // Used for UART
#include "hal_uart.h"
#include "debug.h"
#include "delay.h"
#include "sbus.h"
#if SBUS_ENABLED
static int uart0_filestream = -1;
void hal_uart_init(EXTERNAL_MEMORY uint8_t *sbus_data_ptr) {
// Open in non blocking read/write mode
uart0_filestream = open("/dev/ttyAMA0", O_WRONLY | O_NOCTTY | O_NDELAY);
if (uart0_filestream == -1) {
printf("Error - Unable to open UART. Ensure it is not in use by another application\n");
}
// USART configuration:
// 100000bps inverted serial stream, 8 bits, even parity, 2 stop bits
// no hw flow control
struct termios2 options;
options.c_cflag = BOTHER | CS8 | CLOCAL | PARENB | CSTOPB;
options.c_iflag = 0;
options.c_oflag = 0;
options.c_lflag = 0;
options.c_ispeed = 100000;
options.c_ospeed = 100000;
if (ioctl(uart0_filestream, TCSETS2, &options) != 0) {
printf("ioctl TCSETS2 failed");
}
}
void hal_uart_start_transmission(uint8_t *data, uint8_t len) {
if (uart0_filestream != -1) {
int count = write(uart0_filestream, data, len);
if (count < len) {
printf("UART TX error sent %u of %u\n", count, len);
}
// printf("%d bytes written\n", len);
}
}
#endif // SBUS_ENABLED

View File

@@ -0,0 +1,29 @@
/*
Copyright 2017 fishpepper <AT> gmail.com
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/>.
author: fishpepper <AT> gmail.com
*/
#ifndef HAL_UART_H_
#define HAL_UART_H_
#include <stdint.h>
#include "hal_defines.h"
void hal_uart_init(EXTERNAL_MEMORY uint8_t *data_ptr);
void hal_uart_start_transmission(uint8_t *buffer, uint8_t len);
#endif // HAL_UART_H_

View File

@@ -0,0 +1,29 @@
/*
Copyright 2017 fishpepper <AT> gmail.com
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/>.
author: fishpepper <AT> gmail.com
*/
#include "hal_wdt.h"
#include "debug.h"
#include "delay.h"
void hal_wdt_init(void) {
}
inline void hal_wdt_reset(void) {
}

View File

@@ -0,0 +1,26 @@
/*
Copyright 2017 fishpepper <AT> gmail.com
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/>.
author: fishpepper <AT> gmail.com
*/
#ifndef HAL_WDT_H_
#define HAL_WDT_H_
void hal_wdt_init(void);
void hal_wdt_reset(void);
#endif // HAL_WDT_H_