├── ground
└── Repository moved to GitHub.txt
└── onboard
├── 1wire.c
├── 1wire.h
├── CoOS.h
├── Makefile
├── OsArch.h
├── OsConfig.h
├── OsCore.h
├── OsError.h
├── OsEvent.h
├── OsFlag.h
├── OsKernelHeap.h
├── OsMM.h
├── OsMutex.h
├── OsQueue.h
├── OsServiceReq.h
├── OsTask.h
├── OsTime.h
├── OsTimer.h
├── adc.c
├── adc.h
├── algebra.c
├── alt_ukf.c
├── alt_ukf.h
├── analog.c
├── analog.h
├── aq.h
├── aq_init.c
├── aq_init.h
├── aq_math.h
├── aq_mavlink.c
├── aq_mavlink.h
├── aq_timer.c
├── aq_timer.h
├── arch.c
├── autoquad.hzp
├── autoquad.ld
├── board_6_1.h
├── board_6_1a.h
├── board_7_0.h
├── board_dimu_v1.h
├── board_dimu_v1_1.h
├── board_dimu_v2.h
├── board_dimu_v21.h
├── board_m4.h
├── board_m4_r3.h
├── board_m4_r4.h
├── board_m4_r5.h
├── board_m4_r6.h
├── buildnum.h
├── calib.c
├── calib.h
├── can.c
├── can.h
├── canCalib.c
├── canCalib.h
├── canOSD.c
├── canOSD.h
├── canSensors.c
├── canSensors.h
├── canUart.c
├── canUart.h
├── comm.c
├── comm.h
├── command.c
├── command.h
├── compass.c
├── compass.h
├── config.c
├── config.h
├── config_default.h
├── config_default_m4.h
├── control.c
├── control.h
├── coocox.h
├── core.c
├── cyrf6936.c
├── cyrf6936.h
├── cyrf6936_regs.h
├── d_imu.c
├── d_imu.h
├── digital.c
├── digital.h
├── diskio.h
├── dsm.c
├── dsm.h
├── eeprom.c
├── eeprom.h
├── esc32.c
├── esc32.h
├── event.c
├── ext_irq.c
├── ext_irq.h
├── ff.c
├── ff.h
├── ffconf.h
├── filer.c
├── filer.h
├── flag.c
├── flash.c
├── flash.h
├── flash_placement.xml
├── fpu.c
├── fpu.h
├── futaba.c
├── futaba.h
├── getbuildnum.c
├── getbuildnum.h
├── gimbal.c
├── gimbal.h
├── gps.c
├── gps.h
├── grhott.c
├── grhott.h
├── hmc5983.c
├── hmc5983.h
├── hook.c
├── imu.c
├── imu.h
├── incbuild.js
├── integer.h
├── kernelHeap.c
├── logger.c
├── logger.h
├── main_ctl.c
├── matrix.c
├── max21100.c
├── max21100.h
├── mbox.c
├── mlinkrx.c
├── mlinkrx.h
├── mm.c
├── motors.c
├── motors.h
├── mpu6000.c
├── mpu6000.h
├── ms5611.c
├── ms5611.h
├── mutex.c
├── nav.c
├── nav.h
├── nav_ukf.c
├── nav_ukf.h
├── pid.c
├── pid.h
├── port.c
├── ppm.c
├── ppm.h
├── pwm.c
├── pwm.h
├── quatos.h
├── queue.c
├── radio.c
├── radio.h
├── rcc.c
├── rcc.h
├── rotations.c
├── rtc.c
├── rtc.h
├── run.c
├── run.h
├── sdio.c
├── sdio.h
├── sem.c
├── serial.c
├── serial.h
├── serviceReq.c
├── signaling.c
├── signaling.h
├── spektrum.c
├── spektrum.h
├── spi.c
├── spi.h
├── srcdkf.c
├── srcdkf.h
├── stm32f4xx_conf.h
├── supervisor.c
├── supervisor.h
├── system_stm32f4xx.c
├── task.c
├── telemetry.c
├── telemetry.h
├── thumb_crt0.s
├── time.c
├── timer.c
├── ublox.c
├── ublox.h
├── usb.c
├── usb.h
├── usb_bsp.c
├── usb_bsp.h
├── usb_conf.h
├── usb_core.c
├── usb_core.h
├── usb_dcd.c
├── usb_dcd.h
├── usb_dcd_int.c
├── usb_dcd_int.h
├── usb_defines.h
├── usb_hcd.c
├── usb_hcd.h
├── usb_hcd_int.c
├── usb_hcd_int.h
├── usb_regs.h
├── usbd_cdc_msc_core.c
├── usbd_cdc_msc_core.h
├── usbd_conf.h
├── usbd_core.c
├── usbd_core.h
├── usbd_def.h
├── usbd_desc.c
├── usbd_desc.h
├── usbd_ioreq.c
├── usbd_ioreq.h
├── usbd_msc_bot.c
├── usbd_msc_bot.h
├── usbd_msc_data.c
├── usbd_msc_data.h
├── usbd_msc_mem.h
├── usbd_msc_scsi.c
├── usbd_msc_scsi.h
├── usbd_req.c
├── usbd_req.h
├── usbd_storage_msd.c
├── util.c
├── util.h
├── utility.c
└── utility.h
/ground/Repository moved to GitHub.txt:
--------------------------------------------------------------------------------
1 | https://github.com/AutoQuad/utilities
--------------------------------------------------------------------------------
/onboard/1wire.h:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of AutoQuad.
3 |
4 | AutoQuad is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | AutoQuad is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 | You should have received a copy of the GNU General Public License
14 | along with AutoQuad. If not, see .
15 |
16 | Copyright © 2011-2014 Bill Nesbitt
17 | */
18 |
19 | #ifndef _1wire_h
20 | #define _1wire_h
21 |
22 | #include "digital.h"
23 | #include "stm32f4xx.h"
24 |
25 | #define owHi() { owData.port->BSRRL = owData.pin; }
26 | #define owLo() { owData.port->BSRRH = owData.pin; }
27 | #define owRead() ((owData.port->IDR & owData.pin) != (uint32_t)Bit_RESET)
28 |
29 | #define OW_ROM_READ 0x33
30 | #define OW_ROM_MATCH 0x55
31 | #define OW_ROM_SKIP 0xCC
32 | #define OW_READ_SCRATCH 0xBE
33 | #define OW_TCONV 0x44
34 | #define OW_VERSION 0x03
35 | #define OW_PARAM_READ 0x04
36 | #define OW_PARAM_WRITE 0x05
37 | #define OW_CONFIG_READ 0x06
38 | #define OW_CONFIG_WRITE 0x07
39 | #define OW_CONFIG_DEFAULT 0x08
40 | #define OW_SET_MODE 0x09
41 | #define OW_GET_MODE 0x0A
42 | #define OW_GET_PARAM_ID 0x0B
43 |
44 | enum {
45 | OW_STATE_0,
46 | OW_STATE_1,
47 | OW_STATE_2,
48 | OW_STATE_3,
49 | OW_STATE_4
50 | };
51 |
52 | enum {
53 | OW_STATUS_UNINITIALIZED,
54 | OW_STATUS_NO_PRESENSE,
55 | OW_STATUS_BUSY,
56 | OW_STATUS_COMPLETE
57 | };
58 |
59 | typedef struct {
60 | GPIO_TypeDef* port;
61 | uint16_t pin;
62 | digitalPin *dp;
63 | uint8_t buf[256];
64 | uint8_t *ptr;
65 | GPIO_InitTypeDef owGPIO;
66 | volatile uint8_t status;
67 | volatile uint8_t present;
68 | volatile uint8_t bitValue;
69 | volatile uint8_t byteValue;
70 | int8_t writeBytes;
71 | int8_t readBytes;
72 | } owStruct_t;
73 |
74 | extern owStruct_t owData;
75 |
76 | extern void owInit(GPIO_TypeDef* port, const uint16_t pin);
77 | extern unsigned char owReset(void);
78 | extern void owWriteByte(uint8_t byteval);
79 | extern uint8_t owReadByte(void);
80 | extern void owReadROM(char *rom);
81 | extern void owResetISR(int state);
82 | extern void owReadBitISR(int state);
83 | extern void owWriteBit1ISR(int state);
84 | extern void owWriteBit0ISR(int state);
85 | extern void owReadByteISR(int bit);
86 | extern void owWriteByteISR(int bit);
87 | extern void owTransactionISR(int state);
88 | extern uint8_t owTransaction(int8_t write, int8_t read);
89 |
90 | #endif
91 |
--------------------------------------------------------------------------------
/onboard/OsArch.h:
--------------------------------------------------------------------------------
1 | /**
2 | *******************************************************************************
3 | * @file OsArch.h
4 | * @version V1.1.4
5 | * @date 2011.04.20
6 | * @brief Implement function declare related to Cortex-M3(ARM-v7)
7 | * @details This header file including functions or defines related to
8 | * Cortex-M3(ARM-v7).
9 | *******************************************************************************
10 | * @copy
11 | *
12 | * INTERNAL FILE,DON'T PUBLIC.
13 | *
14 | *
© COPYRIGHT 2009 CooCox
15 | *******************************************************************************
16 | */
17 |
18 |
19 | #ifndef _CPU_H
20 | #define _CPU_H
21 |
22 |
23 | #define NVIC_ST_CTRL (*((volatile U32 *)0xE000E010))
24 | #define NVIC_ST_RELOAD (*((volatile U32 *)0xE000E014))
25 | #define RELOAD_VAL ((U32)(( (U32)CFG_CPU_FREQ) / (U32)CFG_SYSTICK_FREQ) -1)
26 |
27 | /*!< Initial System tick. */
28 | #define InitSysTick() NVIC_ST_RELOAD = RELOAD_VAL; \
29 | NVIC_ST_CTRL = 0x0007
30 |
31 | #define NVIC_SYS_PRI2 (*((volatile U32 *)0xE000ED1C))
32 | #define NVIC_SYS_PRI3 (*((volatile U32 *)0xE000ED20))
33 |
34 | /*!< Initialize PendSV,SVC and SysTick interrupt priority to lowest. */
35 | #define InitInt() NVIC_SYS_PRI2 |= 0xFF000000;\
36 | NVIC_SYS_PRI3 |= 0xFFFF0000
37 |
38 |
39 | /*---------------------------- Variable declare ------------------------------*/
40 | extern U64 OSTickCnt; /*!< Counter for current system ticks. */
41 |
42 | /*!< Initial context of task being created */
43 | extern OS_STK *InitTaskContext(FUNCPtr task,void *param,OS_STK *pstk);
44 | extern void SwitchContext(void); /*!< Switch context */
45 | extern void SetEnvironment(OS_STK *pstk);/*!< Set environment for run */
46 | extern U8 Inc8 (volatile U8 *data);
47 | extern U8 Dec8 (volatile U8 *data);
48 | extern void IRQ_ENABLE_RESTORE(void);
49 | extern void IRQ_DISABLE_SAVE(void);
50 | #endif
51 |
--------------------------------------------------------------------------------
/onboard/OsCore.h:
--------------------------------------------------------------------------------
1 | /**
2 | *******************************************************************************
3 | * @file OsCore.h
4 | * @version V1.1.4
5 | * @date 2011.04.20
6 | * @brief Header file related to kernel
7 | *******************************************************************************
8 | * @copy
9 | *
10 | * INTERNAL FILE,DON'T PUBLIC.
11 | *
12 | * © COPYRIGHT 2009 CooCox
13 | *******************************************************************************
14 | */
15 |
16 |
17 | #ifndef _CORE_H
18 | #define _CORE_H
19 |
20 | #include
21 |
22 |
23 | #define OsSchedLock() OSSchedLock++; /*!< Lock schedule */
24 | extern void OsSchedUnlock(void);
25 |
26 | #endif
27 |
28 |
--------------------------------------------------------------------------------
/onboard/OsError.h:
--------------------------------------------------------------------------------
1 | /**
2 | *******************************************************************************
3 | * @file OsError.h
4 | * @version V1.1.4
5 | * @date 2011.04.20
6 | * @brief rror dispose header file
7 | * @details This file use to dispose error which from error configure for OS.
8 | *******************************************************************************
9 | * @copy
10 | *
11 | * INTERNAL FILE,DON'T PUBLIC.
12 | *
13 | * © COPYRIGHT 2009 CooCox
14 | *******************************************************************************
15 | */
16 |
17 |
18 | #ifndef _ERROR_H
19 | #define _ERROR_H
20 |
21 | #if (CFG_SYSTICK_FREQ > 1000) ||(CFG_SYSTICK_FREQ < 1)
22 | #error " OsConfig.h System Tick time must between 1ms and 1s!"
23 | #endif
24 |
25 | #if CFG_MAX_USER_TASKS > 253
26 | #error " OsConfig.h, CFG_MAX_USER_TASKS must be <= 253! "
27 | #endif
28 |
29 | #if CFG_LOWEST_PRIO > 254
30 | #error " OsConfig.h, CFG_LOWEST_PRIO must be <= 254! "
31 | #endif
32 |
33 | #if CFG_IDLE_STACK_SIZE <25
34 | #error " OsConfig.h, CFG_IDLE_STACK_SIZE must be >= 25! "
35 | #endif
36 |
37 |
38 | #if CFG_ROBIN_EN > 0
39 | #if CFG_TIME_SLICE > 4095
40 | #error " OsConfig.h, CFG_TIME_SLICE must be <= 4095! "
41 | #endif
42 | #endif
43 |
44 | #if CFG_TMR_EN > 0
45 | #if CFG_MAX_TMR > 32
46 | #error " OsConfig.h, CFG_MAX_TMR must be <= 32! "
47 | #endif
48 | #endif
49 |
50 |
51 | #if CFG_MM_EN > 0
52 | #if CFG_MAX_MM > 32
53 | #error " config.h, CFG_MAX_MM must be <= 32! "
54 | #endif
55 | #endif
56 |
57 |
58 | #if CFG_KHEAP_EN > 0
59 | #if KHEAP_SIZE < 0x20
60 | #error " config.h, CFG_MAX_MM must be >= 0x20! "
61 | #endif
62 | #endif
63 |
64 | #if CFG_MUTEX_EN > 0
65 | #if CFG_MAX_MUTEX > 254
66 | #error " config.h, CFG_MAX_MUTEX must be <= 254! "
67 | #endif
68 | #endif
69 |
70 |
71 | #if CFG_EVENT_EN > 0
72 | #if (CFG_MAX_EVENT > 254 || CFG_MAX_EVENT <= 0)
73 | #error " config.h, CFG_MAX_EVENT must be <= 254 && > 0! "
74 | #endif
75 |
76 |
77 | #if CFG_QUEUE_EN > 0
78 | #if CFG_MAX_QUEUE > CFG_MAX_EVENT
79 | #error " config.h, CFG_MAX_QUEUE must be <= CFG_MAX_EVENT! "
80 | #endif
81 | #endif
82 | #endif /* CFG_EVENT_EN */
83 |
84 | #endif /* _ERROR_H */
85 |
--------------------------------------------------------------------------------
/onboard/OsEvent.h:
--------------------------------------------------------------------------------
1 | /**
2 | *******************************************************************************
3 | * @file OsEvent.h
4 | * @version V1.1.4
5 | * @date 2011.04.20
6 | * @brief Event management header file
7 | * @details This file including some defines and declares related to event
8 | * (semaphore,mailbox,queque) management.
9 | *******************************************************************************
10 | * @copy
11 | *
12 | * INTERNAL FILE,DON'T PUBLIC.
13 | *
14 | * © COPYRIGHT 2009 CooCox
15 | *******************************************************************************
16 | */
17 |
18 |
19 | #ifndef _EVENT_H
20 | #define _EVENT_H
21 |
22 | #define EVENT_TYPE_SEM (U8)0x01 /*!< Event type:Semaphore. */
23 | #define EVENT_TYPE_MBOX (U8)0x02 /*!< Event type:Mailbox. */
24 | #define EVENT_TYPE_QUEUE (U8)0x03 /*!< Event type:Queue. */
25 | #define EVENT_TYPE_INVALID (U8)0x04 /*!< Invalid event type. */
26 |
27 |
28 | /**
29 | * @struct EventCtrBlk event.h
30 | * @brief Event control block
31 | * @details This struct is use to manage event,
32 | * e.g. semaphore,mailbox,queue.
33 | */
34 | typedef struct EventCtrBlk
35 | {
36 | void* eventPtr; /*!< Point to mailbox or queue struct */
37 | U8 id; /*!< ECB id */
38 | U8 eventType:4; /*!< Type of event */
39 | U8 eventSortType:4; /*!< 0:FIFO 1: Preemptive by prio */
40 | U16 eventCounter; /*!< Counter of semaphore. */
41 | U16 initialEventCounter; /*!< Initial counter of semaphore. */
42 | P_OSTCB eventTCBList; /*!< Task waitting list. */
43 | }ECB,*P_ECB;
44 |
45 | /*---------------------------- Variable declare ------------------------------*/
46 | extern ECB EventTbl[CFG_MAX_EVENT]; /*!< Table use to save TCB. */
47 |
48 | /*---------------------------- Function declare ------------------------------*/
49 | /*!< Create a event */
50 | extern P_ECB CreatEvent(U8 eventType,U8 eventSortType,void* eventPtr);
51 |
52 | /*!< Remove a task from wait list */
53 | extern void EventTaskToWait(P_ECB pecb,P_OSTCB ptcb);
54 | extern StatusType DeleteEvent(P_ECB pecb,U8 opt); /*!< Delete a event. */
55 | extern void EventTaskToRdy(P_ECB pecb); /*!< Insert a task to ready list*/
56 | extern void CreateEventList(void); /*!< Create a event list. */
57 | extern void RemoveEventWaittingList(P_OSTCB ptcb);
58 | #endif
59 |
--------------------------------------------------------------------------------
/onboard/OsFlag.h:
--------------------------------------------------------------------------------
1 | /**
2 | *******************************************************************************
3 | * @file OsFlag.h
4 | * @version V1.1.4
5 | * @date 2011.04.20
6 | * @brief Evnet flag management header file
7 | * @details This file including some defines and declares about flag management.
8 | *******************************************************************************
9 | * @copy
10 | *
11 | * INTERNAL FILE,DON'T PUBLIC.
12 | *
13 | * © COPYRIGHT 2009 CooCox
14 | *******************************************************************************
15 | */
16 |
17 |
18 | #ifndef _FLAG_H
19 | #define _FLAG_H
20 |
21 | /**
22 | * @struct FlagNode flag.h
23 | * @brief Flag node struct
24 | * @details
25 | */
26 | typedef struct FlagNode
27 | {
28 | struct FlagNode* nextNode; /*!< A pointer to next flag node */
29 | struct FlagNode* prevNode; /*!< A pointer to prev flag node */
30 | U32 waitFlags; /*!< Flag value */
31 | P_OSTCB waitTask; /*!< A pointer to task waitting flag */
32 | U8 waitType; /*!< Wait type */
33 | }FLAG_NODE,*P_FLAG_NODE;
34 |
35 |
36 | /**
37 | * @struct Flag flag.h
38 | * @brief Flag control block
39 | * @details This struct use to mange event flag.
40 | */
41 | typedef struct Flag
42 | {
43 | U32 flagRdy; /*!< Ready flag */
44 | U32 resetOpt; /*!< Reset option */
45 | U32 flagActive; /*!< Active flag */
46 | P_FLAG_NODE headNode; /*!< Head node */
47 | P_FLAG_NODE tailNode; /*!< Tail node */
48 | }FCB,*P_FCB;
49 |
50 |
51 | /*---------------------------- Variable declare ------------------------------*/
52 | extern FCB FlagCrl;
53 |
54 | /*---------------------------- Function declare ------------------------------*/
55 | extern void RemoveLinkNode(P_FLAG_NODE pnode);
56 | #endif
57 |
58 |
--------------------------------------------------------------------------------
/onboard/OsKernelHeap.h:
--------------------------------------------------------------------------------
1 | /**
2 | *******************************************************************************
3 | * @file OsKernelHeap.h
4 | * @version V1.1.4
5 | * @date 2011.04.20
6 | * @brief Header file related to memory management
7 | * @details This file including some defines and function declare related to
8 | * kernel heap management.
9 | *******************************************************************************
10 | * @copy
11 | *
12 | * INTERNAL FILE,DON'T PUBLIC.
13 | *
14 | * © COPYRIGHT 2009 CooCox
15 | *******************************************************************************
16 | */
17 |
18 |
19 | #ifndef _KERNELHEAP_H
20 | #define _KERNELHEAP_H
21 |
22 |
23 | typedef struct KennelHeap
24 | {
25 | U32 startAddr;
26 | U32 endAddr;
27 | }KHeap,*P_KHeap;
28 |
29 |
30 | typedef struct UsedMemBlk
31 | {
32 | void* nextMB;
33 | void* preMB;
34 | }UMB,*P_UMB;
35 |
36 |
37 | typedef struct FreeMemBlk
38 | {
39 | struct FreeMemBlk* nextFMB;
40 | struct UsedMemBlk* nextUMB;
41 | struct UsedMemBlk* preUMB;
42 | }FMB,*P_FMB;
43 |
44 | /*---------------------------- Function Declare ------------------------------*/
45 | extern void CoCreateKheap(void);
46 |
47 | #endif /* _KERNELHEAP_H */
48 |
49 |
--------------------------------------------------------------------------------
/onboard/OsMM.h:
--------------------------------------------------------------------------------
1 | /**
2 | *******************************************************************************
3 | * @file OsMm.h
4 | * @version V1.1.4
5 | * @date 2011.04.20
6 | * @brief Header file related to memory management
7 | * @details This file including some defines and function declare related to
8 | * memory management.
9 | *******************************************************************************
10 | * @copy
11 | *
12 | * INTERNAL FILE,DON'T PUBLIC.
13 | *
14 | * © COPYRIGHT 2009 CooCox
15 | *******************************************************************************
16 | */
17 |
18 |
19 | #ifndef _MM_H
20 | #define _MM_H
21 |
22 |
23 | typedef struct Memory
24 | {
25 | U8* memAddr;
26 | U8* freeBlock;
27 | U32 blockSize;
28 | U32 blockNum;
29 | }MM,*P_MM;
30 |
31 |
32 | typedef struct MemoryBlock
33 | {
34 | struct MemoryBlock* nextBlock;
35 | }MemBlk,*P_MemBlk;
36 |
37 |
38 | extern U32 MemoryIDVessel;
39 |
40 | #endif /* _MM_H */
41 |
42 |
--------------------------------------------------------------------------------
/onboard/OsMutex.h:
--------------------------------------------------------------------------------
1 | /**
2 | *******************************************************************************
3 | * @file OsMutex.h
4 | * @version V1.1.4
5 | * @date 2011.04.20
6 | * @brief Mutex management header file
7 | * @details This file including some defines and declare related to mutex
8 | * management.
9 | *******************************************************************************
10 | * @copy
11 | *
12 | * INTERNAL FILE,DON'T PUBLIC.
13 | *
14 | * © COPYRIGHT 2009 CooCox
15 | *******************************************************************************
16 | */
17 |
18 |
19 | #ifndef _MUTEX_H
20 | #define _MUTEX_H
21 |
22 | #include
23 |
24 | #if CFG_MUTEX_EN > 0
25 |
26 | /*---------------------------- Resource status -------------------------------*/
27 | #define MUTEX_FREE 0 /*!< Mutex is free */
28 | #define MUTEX_OCCUPY 1 /*!< Mutex is occupy */
29 | #define WAITING_MUTEX 0x80
30 |
31 | /**
32 | * @struct Mutex mutex.h
33 | * @brief Mutex control block
34 | * @details This struct is use to mutex management.
35 | */
36 | typedef struct Mutex
37 | {
38 | U8 originalPrio; /*!< Mutex priority. */
39 | U8 mutexFlag; /*!< Mutex flag. */
40 | OS_TID taskID; /*!< Task ID. */
41 | OS_TID hipriTaskID; /*!< Mutex ID. */
42 | P_OSTCB waittingList; /*!< waitting the Mutex. */
43 | }MUTEX,*P_MUTEX;
44 |
45 |
46 | /*---------------------------- Variable declare ------------------------------*/
47 | /*!< Table use to save mutex control block. */
48 | extern MUTEX MutexTbl[CFG_MAX_MUTEX];
49 | extern OS_MutexID MutexFreeID; /*!< A pointer to next vliad resource ID. */
50 |
51 |
52 | /*---------------------------- Function declare ------------------------------*/
53 | extern void RemoveMutexList(P_OSTCB ptcb);
54 |
55 | #endif /* CFG_MUTEX_EN */
56 |
57 | #endif /* _MUTEX_H */
58 |
--------------------------------------------------------------------------------
/onboard/OsQueue.h:
--------------------------------------------------------------------------------
1 | /**
2 | *******************************************************************************
3 | * @file OsQueue.h
4 | * @version V1.1.4
5 | * @date 2011.04.20
6 | * @brief Queue management header file
7 | * @details This file including some defines and declares about queue management.
8 | *******************************************************************************
9 | * @copy
10 | *
11 | * INTERNAL FILE,DON'T PUBLIC.
12 | *
13 | * © COPYRIGHT 2009 CooCox
14 | *******************************************************************************
15 | */
16 |
17 |
18 | #ifndef _QUEUE_H
19 | #define _QUEUE_H
20 |
21 |
22 | /**
23 | * @struct Queue queue.h
24 | * @brief Queue struct
25 | * @details This struct use to manage queue.
26 | *
27 | */
28 | typedef struct Queue
29 | {
30 | void **qStart; /*!< */
31 | U8 id; /*!< */
32 | U16 head; /*!< The header of queue */
33 | U16 tail; /*!< The end of queue */
34 | U16 qMaxSize; /*!< The max size of queue */
35 | U16 qSize; /*!< Current size of queue */
36 | }QCB,*P_QCB;
37 |
38 |
39 | #endif
40 |
--------------------------------------------------------------------------------
/onboard/OsServiceReq.h:
--------------------------------------------------------------------------------
1 |
2 | /**
3 | *******************************************************************************
4 | * @file OsServiceReq.h
5 | * @version V1.1.4
6 | * @date 2011.04.20
7 | * @brief Header file related to service request
8 | * @details This file including some defines and function declare related to
9 | * service request.
10 | *******************************************************************************
11 | * @copy
12 | *
13 | * INTERNAL FILE,DON'T PUBLIC.
14 | *
15 | * © COPYRIGHT 2009 CooCox
16 | *******************************************************************************
17 | */
18 |
19 |
20 | #ifndef _SERVICEREQ_H
21 | #define _SERVICEREQ_H
22 |
23 | #if CFG_MAX_SERVICE_REQUEST > 0
24 | #define SEM_REQ (U8)0x1
25 | #define MBOX_REQ (U8)0x2
26 | #define FLAG_REQ (U8)0x3
27 | #define QUEUE_REQ (U8)0x4
28 |
29 |
30 | typedef struct ServiceReqCell
31 | {
32 | U8 type;
33 | U8 id;
34 | void* arg;
35 | }SQC,*P_SQC;
36 |
37 | typedef struct ServiceReqQueue
38 | {
39 | U8 cnt;
40 | U8 head;
41 | SQC cell[CFG_MAX_SERVICE_REQUEST];
42 | }SRQ,*P_SRQ;
43 |
44 |
45 | extern SRQ ServiceReq;
46 | extern BOOL InsertInSRQ(U8 type,U8 id,void* arg);
47 | #endif
48 |
49 | extern void RespondSRQ(void);
50 | extern BOOL TimeReq;
51 | extern BOOL TimerReq;
52 | extern BOOL IsrReq;
53 | #endif
54 |
--------------------------------------------------------------------------------
/onboard/OsTask.h:
--------------------------------------------------------------------------------
1 | /**
2 | *******************************************************************************
3 | * @file OsTask.h
4 | * @version V1.1.4
5 | * @date 2011.04.20
6 | * @brief Header file related to task.
7 | * @details This file including some defines and function declare related to task.
8 | *******************************************************************************
9 | * @copy
10 | *
11 | * INTERNAL FILE,DON'T PUBLIC.
12 | *
13 | * © COPYRIGHT 2009 CooCox
14 | *******************************************************************************
15 | */
16 |
17 | #ifndef _TASK_H
18 | #define _TASK_H
19 |
20 | #define SYS_TASK_NUM (1) /*!< System task number. */
21 |
22 | /*---------------------------- Task Status -----------------------------------*/
23 | #define TASK_READY 0 /*!< Ready status of task. */
24 | #define TASK_RUNNING 1 /*!< Running status of task. */
25 | #define TASK_WAITING 2 /*!< Waitting status of task. */
26 | #define TASK_DORMANT 3 /*!< Dormant status of task. */
27 |
28 |
29 | #define INVALID_ID (U8)0xff
30 | #define INVALID_VALUE (U32)0xffffffff
31 | #define MAGIC_WORD (U32)0x5a5aa5a5
32 |
33 |
34 | /**
35 | * @struct TCB task.h
36 | * @brief Task control blcok.
37 | * @details This struct use to manage task.
38 | */
39 | typedef struct TCB
40 | {
41 | OS_STK *stkPtr; /*!< The current point of task. */
42 | U8 prio; /*!< Task priority. */
43 | U8 state; /*!< TaSk status. */
44 | OS_TID taskID; /*!< Task ID. */
45 |
46 | #if CFG_MUTEX_EN > 0
47 | OS_MutexID mutexID; /*!< Mutex ID. */
48 | #endif
49 |
50 | #if CFG_EVENT_EN > 0
51 | OS_EventID eventID; /*!< Event ID. */
52 | #endif
53 |
54 | #if CFG_ROBIN_EN >0
55 | U16 timeSlice; /*!< Task time slice */
56 | #endif
57 |
58 | #if CFG_STK_CHECKOUT_EN >0
59 | OS_STK *stack; /*!< The top point of task. */
60 | #endif
61 |
62 | #if CFG_EVENT_EN > 0
63 | void* pmail; /*!< Mail to task. */
64 | struct TCB *waitNext; /*!< Point to next TCB in the Event waitting list.*/
65 | struct TCB *waitPrev; /*!< Point to prev TCB in the Event waitting list.*/
66 | #endif
67 |
68 | #if CFG_TASK_SCHEDULE_EN == 0
69 | FUNCPtr taskFuc;
70 | OS_STK *taskStk;
71 | #endif
72 |
73 |
74 | #if CFG_FLAG_EN > 0
75 | void* pnode; /*!< Pointer to node of event flag. */
76 | #endif
77 |
78 | #if CFG_TASK_WAITTING_EN >0
79 | U32 delayTick; /*!< The number of ticks which delay. */
80 | #endif
81 | struct TCB *TCBnext; /*!< The pointer to next TCB. */
82 | struct TCB *TCBprev; /*!< The pointer to prev TCB. */
83 |
84 | }OSTCB,*P_OSTCB;
85 |
86 |
87 | /*---------------------------- Variable declare ------------------------------*/
88 | // save tcb ptr that created
89 | extern P_OSTCB FreeTCB; /*!< A pointer to free TCB. */
90 | extern OSTCB TCBTbl[CFG_MAX_USER_TASKS+SYS_TASK_NUM];
91 | extern P_OSTCB TCBRdy; /*!< A pointer to TCB that is ready status */
92 | extern P_OSTCB TCBNext; /*!< A pointer to TCB next be scheduled. */
93 | extern P_OSTCB TCBRunning; /*!< A pointer to TCB that is running. */
94 |
95 | extern U64 OSCheckTime;
96 | extern volatile U8 OSIntNesting; /*!< Use to indicate interrupt nesting level.*/
97 | extern volatile U8 OSSchedLock; /*!< Schedule is lock(LOCK) or unlock(UN_LOCK).*/
98 | extern volatile BOOL TaskSchedReq;
99 | extern OS_STK idle_stk[CFG_IDLE_STACK_SIZE];
100 |
101 |
102 | void Schedule(void); /*!< Schedule function */
103 | void IdleTask(void* pdata); /*!< IDLE task code */
104 | void InsertToTCBRdyList (P_OSTCB tcbInser);
105 | void RemoveFromTCBRdyList(P_OSTCB ptcb);
106 | void CreateTCBList(void);
107 | #if CFG_ORDER_LIST_SCHEDULE_EN ==0
108 | void ActiveTaskPri(U8 pri);
109 | void DeleteTaskPri(U8 pri);
110 | #endif
111 |
112 | #endif
113 |
--------------------------------------------------------------------------------
/onboard/OsTime.h:
--------------------------------------------------------------------------------
1 | /**
2 | *******************************************************************************
3 | * @file OsTime.c
4 | * @version V1.1.4
5 | * @date 2011.04.20
6 | * @brief Header file related to time management
7 | * @details Thie file including some data declare related to time managment.
8 | *******************************************************************************
9 | * @copy
10 | *
11 | * INTERNAL FILE,DON'T PUBLIC.
12 | *
13 | * © COPYRIGHT 2009 CooCox
14 | *******************************************************************************
15 | */
16 |
17 | #ifndef _TIME_H
18 | #define _TIME_H
19 |
20 | /*---------------------------- Variable declare ------------------------------*/
21 | extern P_OSTCB DlyList; /*!< A pointer to ther delay list. */
22 |
23 | /*---------------------------- Function declare ------------------------------*/
24 | extern void TimeDispose(void); /*!< Time dispose function. */
25 | extern void isr_TimeDispose(void);
26 | extern void RemoveDelayList(P_OSTCB ptcb);
27 | extern void InsertDelayList(P_OSTCB ptcb,U32 ticks);
28 | #endif
29 |
--------------------------------------------------------------------------------
/onboard/OsTimer.h:
--------------------------------------------------------------------------------
1 | /**
2 | *******************************************************************************
3 | * @file OsTimer.h
4 | * @version V1.1.4
5 | * @date 2011.04.20
6 | * @brief Timer manage header file
7 | * @details This file including some declares and defines related to timer
8 | * management.
9 | *******************************************************************************
10 | * @copy
11 | *
12 | * INTERNAL FILE,DON'T PUBLIC.
13 | *
14 | * © COPYRIGHT 2009 CooCox
15 | *******************************************************************************
16 | */
17 |
18 | #ifndef _TIMER_H
19 | #define _TIMER_H
20 |
21 | #define TMR_STATE_RUNNING 0 /*!< Timer State: Running */
22 | #define TMR_STATE_STOPPED 1 /*!< Timer State: Stopped */
23 |
24 | /**
25 | * @struct tmrCtrl timer.h
26 | * @brief Timer control block
27 | * @details This struct is use to manage user timer.
28 | *
29 | */
30 | typedef struct tmrCtrl /* Timer Control Block Define. */
31 | {
32 | OS_TCID tmrID; /*!< Timer ID. */
33 | U8 tmrType; /*!< Timer Type. */
34 | U8 tmrState; /*!< Timer State. */
35 | U32 tmrCnt; /*!< Timer Counter. */
36 | U32 tmrReload; /*!< Timer Reload Counter Value. */
37 | vFUNCPtr tmrCallBack; /*!< Call-back Function When Timer overrun. */
38 | struct tmrCtrl* tmrNext; /*!< Point to Next Timer Control Block. */
39 | struct tmrCtrl* tmrPrev; /*!< Point to Previous Timer Control Block*/
40 |
41 | }TmrCtrl,*P_TmrCtrl;
42 |
43 | /*---------------------------- Variable declare ------------------------------*/
44 | extern P_TmrCtrl TmrList; /*!< A pointer to the timer list. */
45 | extern U32 TmrIDVessel;
46 | /*---------------------------- Function declare ------------------------------*/
47 | extern void TmrDispose(void); /*!< Timer counter function. */
48 | extern void isr_TmrDispose(void);
49 | #endif
50 |
--------------------------------------------------------------------------------
/onboard/adc.h:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of AutoQuad.
3 |
4 | AutoQuad is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | AutoQuad is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 | You should have received a copy of the GNU General Public License
14 | along with AutoQuad. If not, see .
15 |
16 | Copyright © 2011-2014 Bill Nesbitt
17 | */
18 |
19 | #ifndef _adc_h
20 | #define _adc_h
21 |
22 | #include "digital.h"
23 | #include
24 |
25 | #define ADC_STACK_SIZE 130
26 | #define ADC_PRIORITY 10
27 |
28 | // 400 Hz inner loop
29 |
30 | // 153.6Khz sample rate
31 | //#define ADC_SAMPLES 96
32 | //#define ADC_SAMPLE_TIME ADC_SampleTime_56Cycles
33 |
34 | // 262.4Khz sample rate
35 | #define ADC_SAMPLES 164
36 | #define ADC_SAMPLE_TIME ADC_SampleTime_28Cycles
37 |
38 | #define ADC_SENSORS 15
39 | #define ADC_CHANNELS 16
40 |
41 | #define ADC_REF_VOLTAGE 3.3f
42 | #define ADC_DIVISOR (ADC_REF_VOLTAGE / 4096.0f / ADC_SAMPLES)
43 |
44 | #define ADC_VIN_SLOPE ((ANALOG_VIN_RTOP + ANALOG_VIN_RBOT) / ANALOG_VIN_RBOT)
45 | #define ADC_VIN_OFFSET 0.0f
46 |
47 | #define ADC_IDG_TEMP_OFFSET 1.25f // volts (IDG500 PTATS)
48 | #define ADC_IDG_TEMP_SLOPE (1.0f / 0.004f) // deg C / volts
49 |
50 | #define ADC_TEMP1_OFFSET +0.0f
51 | #define ADC_TEMP2_OFFSET +0.0f
52 | #define ADC_TEMP3_OFFSET +0.0f
53 |
54 | #define ADC_TEMP_A +167.5358f
55 | #define ADC_TEMP_B +6.6871f
56 | #define ADC_TEMP_C +0.0347f
57 | #define ADC_TEMP_R2 100000.0f // ohms
58 | #define ADC_KELVIN_TO_CELCIUS -273.0f
59 |
60 | #define ADC_TEMP_SMOOTH 0.0113f
61 |
62 | #define ADC_RATE_CALIB_SAMPLES 25
63 |
64 | #define ADC_MAG_SIGN digitalGet(adcData.magSetReset)
65 |
66 | #define ADC_CHANNEL_RATEX ADC_Channel_8
67 | #define ADC_CHANNEL_RATEY ADC_Channel_9
68 | #define ADC_CHANNEL_RATEZ ADC_Channel_3
69 | #define ADC_CHANNEL_ACCX ADC_Channel_4
70 | #define ADC_CHANNEL_ACCY ADC_Channel_5
71 | #define ADC_CHANNEL_ACCZ ADC_Channel_6
72 | #define ADC_CHANNEL_MAGX ADC_Channel_7
73 | #define ADC_CHANNEL_MAGY ADC_Channel_14
74 | #define ADC_CHANNEL_MAGZ ADC_Channel_15
75 | #define ADC_CHANNEL_PRES1 ADC_Channel_2
76 | #define ADC_CHANNEL_PRES2 ADC_Channel_0
77 | #define ADC_CHANNEL_TEMP1 ADC_Channel_10
78 | #define ADC_CHANNEL_TEMP2 ADC_Channel_11
79 | #define ADC_CHANNEL_TEMP3 ADC_Channel_12
80 | #define ADC_CHANNEL_VIN ADC_Channel_13
81 |
82 | #define ADC_VOLTS_RATEX 0
83 | #define ADC_VOLTS_RATEY 1
84 | #define ADC_VOLTS_RATEZ 2
85 | #define ADC_VOLTS_MAGX 3
86 | #define ADC_VOLTS_MAGY 4
87 | #define ADC_VOLTS_MAGZ 5
88 | #define ADC_VOLTS_TEMP1 6
89 | #define ADC_VOLTS_VIN 7
90 | #define ADC_VOLTS_ACCX 8
91 | #define ADC_VOLTS_ACCY 9
92 | #define ADC_VOLTS_ACCZ 10
93 | #define ADC_VOLTS_PRES1 11
94 | #define ADC_VOLTS_PRES2 12
95 | #define ADC_VOLTS_TEMP2 13
96 | #define ADC_VOLTS_TEMP3 14
97 |
98 | typedef struct {
99 | OS_TID adcTask;
100 | OS_FlagID adcFlag;
101 |
102 | unsigned long interrupt123Sums[ADC_SENSORS];
103 |
104 | unsigned long volatile adcSums[ADC_SENSORS];
105 | unsigned long channelSums[ADC_SENSORS];
106 | float volatile voltages[ADC_SENSORS];
107 |
108 | float temp1, temp2, temp3;
109 | float temperature;
110 | float pressure1;
111 | float pressure2;
112 | float pressure;
113 |
114 | float volatile dRateX, dRateY, dRateZ;
115 | float volatile rateX, rateY, rateZ;
116 | float volatile accX, accY, accZ;
117 | float volatile magX, magY, magZ;
118 |
119 | float magBridgeBiasX, magBridgeBiasY, magBridgeBiasZ;
120 | float rateBiasX, rateBiasY, rateBiasZ;
121 |
122 | digitalPin *magSetReset;
123 | digitalPin *rateAutoZero;
124 | digitalPin *accST;
125 | digitalPin *accScale;
126 |
127 | volatile unsigned long sample;
128 | volatile unsigned long loops;
129 | volatile unsigned long lastUpdate;
130 | volatile unsigned long lastSample;
131 | volatile unsigned long sampleTime;
132 | float dt;
133 | int8_t magSign;
134 | } adcStruct_t;
135 |
136 | extern adcStruct_t adcData;
137 |
138 | extern void adcInit(void);
139 | extern void adcClearCalibration(void);
140 | extern float adcPressureAdjust(float altitude);
141 | extern void adcCalcRot(void);
142 | extern float adcPresToAlt(float pressure);
143 | extern float adcVoltsToTemp(float volts);
144 |
145 | #endif
146 |
--------------------------------------------------------------------------------
/onboard/alt_ukf.c:
--------------------------------------------------------------------------------
1 | #include "alt_ukf.h"
2 | #include "nav_ukf.h"
3 | #include "imu.h"
4 | #include
5 |
6 | altUkfStruct_t altUkfData;
7 |
8 | void altUkfTimeUpdate(float *in, float *noise, float *out, float *u, float dt, int n) {
9 | float acc;
10 | int i;
11 |
12 | // assume out == in
13 | out = in;
14 |
15 | for (i = 0; i < n; i++) {
16 | acc = u[0] + in[ALT_STATE_BIAS*n + i];
17 |
18 | out[ALT_STATE_BIAS*n + i] = in[ALT_STATE_BIAS*n + i] + (noise[ALT_NOISE_BIAS*n + i] * dt);
19 | out[ALT_STATE_VEL*n + i] = in[ALT_STATE_VEL*n + i] + (acc * dt) + (noise[ALT_NOISE_VEL*n + i] * dt);
20 | out[ALT_STATE_POS*n + i] = in[ALT_STATE_POS*n + i] - (in[ALT_STATE_VEL*n + i] * dt) - (acc * dt * dt * 0.5f);
21 | }
22 | }
23 |
24 | void altUkfPresUpdate(float *u, float *x, float *noise, float *y) {
25 | y[0] = x[ALT_STATE_POS] + noise[0]; // return altitude
26 | }
27 |
28 | static void altDoPresUpdate(float measuredPres) {
29 | float noise; // measurement variance
30 | float y; // measurment
31 |
32 | noise = ALT_PRES_NOISE;
33 | y = navUkfPresToAlt(measuredPres);
34 |
35 | srcdkfMeasurementUpdate(altUkfData.kf, 0, &y, 1, 1, &noise, altUkfPresUpdate);
36 | }
37 |
38 | void altUkfProcess(float measuredPres) {
39 | float accIn[3];
40 | float acc[3];
41 |
42 | accIn[0] = IMU_ACCX;// + UKF_ACC_BIAS_X;
43 | accIn[1] = IMU_ACCY;// + UKF_ACC_BIAS_Y;
44 | accIn[2] = IMU_ACCZ;// + UKF_ACC_BIAS_Z;
45 |
46 | // rotate acc to world frame
47 | navUkfRotateVectorByQuat(acc, accIn, &UKF_Q1);
48 | acc[2] += GRAVITY;
49 |
50 | srcdkfTimeUpdate(altUkfData.kf, &acc[2], AQ_OUTER_TIMESTEP);
51 |
52 | altDoPresUpdate(measuredPres);
53 | }
54 |
55 | void altUkfInit(void) {
56 | float Q[ALT_S]; // state variance
57 | float V[ALT_V]; // process variance
58 |
59 | memset((void *)&altUkfData, 0, sizeof(altUkfData));
60 |
61 | altUkfData.kf = srcdkfInit(ALT_S, ALT_M, ALT_V, ALT_N, altUkfTimeUpdate);
62 |
63 | altUkfData.x = srcdkfGetState(altUkfData.kf);
64 |
65 | Q[ALT_STATE_POS] = 5.0f;
66 | Q[ALT_STATE_VEL] = 1e-6f;
67 | Q[ALT_STATE_BIAS] = 0.05f;
68 |
69 | V[ALT_NOISE_BIAS] = ALT_BIAS_NOISE;
70 | V[ALT_NOISE_VEL] = ALT_VEL_NOISE;
71 |
72 | srcdkfSetVariance(altUkfData.kf, Q, V, 0, 0);
73 |
74 | ALT_POS = navUkfPresToAlt(AQ_PRESSURE);
75 | ALT_VEL = 0.0f;
76 | ALT_BIAS = 0.0f;
77 | }
--------------------------------------------------------------------------------
/onboard/alt_ukf.h:
--------------------------------------------------------------------------------
1 | #ifndef _alt_ukf_h
2 | #define _alt_ukf_h
3 |
4 | #include "srcdkf.h"
5 |
6 | #define ALT_S 3 // states
7 | #define ALT_M 1 // measurements
8 | #define ALT_V 2 // process noise
9 | #define ALT_N 1 // measurement noise
10 |
11 | #define ALT_STATE_POS 0
12 | #define ALT_STATE_VEL 1
13 | #define ALT_STATE_BIAS 2
14 |
15 | #define ALT_NOISE_BIAS 0
16 | #define ALT_NOISE_VEL 1
17 |
18 | #define ALT_POS altUkfData.x[ALT_STATE_POS]
19 | #define ALT_VEL altUkfData.x[ALT_STATE_VEL]
20 | #define ALT_BIAS altUkfData.x[ALT_STATE_BIAS]
21 |
22 | #define ALT_PRES_NOISE 0.02f
23 | #define ALT_BIAS_NOISE 5e-4f//5e-5f
24 | #define ALT_VEL_NOISE 5e-4f
25 |
26 | typedef struct {
27 | srcdkf_t *kf;
28 | float *x; // states
29 | } altUkfStruct_t;
30 |
31 | extern altUkfStruct_t altUkfData;
32 |
33 | extern void altUkfInit(void);
34 | extern void altUkfProcess(float measuredPres);
35 |
36 | #endif
--------------------------------------------------------------------------------
/onboard/analog.h:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of AutoQuad.
3 |
4 | AutoQuad is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | AutoQuad is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 | You should have received a copy of the GNU General Public License
14 | along with AutoQuad. If not, see .
15 |
16 | Copyright © 2011-2014 Bill Nesbitt
17 | */
18 |
19 | #ifndef _analog_h
20 | #define _analog_h
21 |
22 | #include "aq.h"
23 | #ifdef HAS_AIMU
24 | #include "adc.h"
25 | #endif
26 |
27 | #define ANALOG_CHANNELS 7
28 | #define ANALOG_SAMPLES 32
29 | #define ANALOG_SAMPLE_TIME ADC_SampleTime_480Cycles
30 | #define ANALOG_DIVISOR ((double)ANALOG_REF_VOLTAGE / (double)4096.0 / (double)ANALOG_SAMPLES)
31 |
32 | #define ANALOG_VIN_SLOPE ((ANALOG_VIN_RTOP + ANALOG_VIN_RBOT) / ANALOG_VIN_RBOT)
33 | #ifdef ANALOG_EXT_VOLT_RTOP
34 | #define ANALOG_EXT_VOLT_SLOPE ((ANALOG_EXT_VOLT_RTOP + ANALOG_EXT_VOLT_RBOT) / ANALOG_EXT_VOLT_RBOT)
35 | #endif
36 | #ifdef ANALOG_EXT_AMP_RTOP
37 | #define ANALOG_EXT_AMP_SLOPE ((ANALOG_EXT_AMP_RTOP + ANALOG_EXT_AMP_RBOT) / ANALOG_EXT_AMP_RBOT)
38 | #endif
39 |
40 | #define ANALOG_VOLTS_VIN 0
41 | #define ANALOG_VOLTS_EXT_VOLT 1
42 | #define ANALOG_VOLTS_EXT_AMP 2
43 |
44 | typedef struct {
45 | uint16_t rawSamples[ANALOG_SAMPLES*ANALOG_CHANNELS];
46 | uint32_t rawChannels[ANALOG_CHANNELS];
47 | float voltages[ANALOG_CHANNELS];
48 |
49 | float vIn;
50 | float extVolt;
51 | float extAmp;
52 |
53 | int8_t batCellCount;
54 |
55 | uint8_t vInSourceIndex;
56 | float vInSlope;
57 |
58 | } analogStruct_t;
59 |
60 | extern analogStruct_t analogData;
61 |
62 | extern void analogInit(void);
63 | extern void analogDecode(void);
64 |
65 | #endif
66 |
--------------------------------------------------------------------------------
/onboard/aq.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bn999/autoquad/c94161aeb610c8d4b22405c9be931524382bc8f9/onboard/aq.h
--------------------------------------------------------------------------------
/onboard/aq_init.c:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of AutoQuad.
3 |
4 | AutoQuad is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | AutoQuad is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 | You should have received a copy of the GNU General Public License
14 | along with AutoQuad. If not, see .
15 |
16 | Copyright © 2011-2014 Bill Nesbitt
17 | */
18 |
19 | #include "aq.h"
20 | #include "aq_init.h"
21 | #include "aq_timer.h"
22 | #include "rtc.h"
23 | #include "filer.h"
24 | #include "config.h"
25 | #include "serial.h"
26 | #include "comm.h"
27 | #include "telemetry.h"
28 | #include "command.h"
29 | #include "motors.h"
30 | #include "radio.h"
31 | #include "imu.h"
32 | #include "control.h"
33 | #include "gps.h"
34 | #include "nav.h"
35 | #include "logger.h"
36 | #include "alt_ukf.h"
37 | #include "nav_ukf.h"
38 | #include "aq_mavlink.h"
39 | #include "util.h"
40 | #include "supervisor.h"
41 | #include "gimbal.h"
42 | #include "run.h"
43 | #include "sdio.h"
44 | #include "can.h"
45 | #include "analog.h"
46 | #include "canCalib.h"
47 | #ifdef USE_SIGNALING
48 | #include "signaling.h"
49 | #endif
50 | #include
51 |
52 | digitalPin *tp;
53 |
54 | OS_STK *aqInitStack;
55 |
56 | void aqInit(void *pdata) {
57 | #ifdef EEPROM_CS_PORT
58 | // TODO: clean this up
59 | digitalPin *eepromCS = digitalInit(EEPROM_CS_PORT, EEPROM_CS_PIN, 1);
60 | #endif
61 | #ifdef DAC_TP_PORT
62 | tp = digitalInit(DAC_TP_PORT, DAC_TP_PIN, 0);
63 | #endif
64 | rtcInit(); // have to do this first as it requires our microsecond timer to calibrate
65 | timerInit(); // now setup the microsecond timer before everything else
66 | sdioLowLevelInit();
67 | filerInit();
68 | supervisorInit();
69 | configInit();
70 | commInit();
71 | #ifdef USE_MAVLINK
72 | mavlinkInit();
73 | #endif
74 | telemetryInit();
75 | imuInit();
76 | analogInit();
77 | navUkfInit();
78 | altUkfInit();
79 | radioInit();
80 | gpsInit();
81 | navInit();
82 | commandInit();
83 | #ifdef USE_SIGNALING
84 | signalingInit();
85 | #endif
86 | loggerInit();
87 | #ifdef CAN_CALIB
88 | canCalibInit();
89 | #else
90 | canInit();
91 | #endif
92 | motorsInit();
93 | controlInit();
94 | gimbalInit();
95 | runInit();
96 |
97 | info();
98 |
99 | supervisorInitComplete();
100 |
101 | // allow tasks to startup
102 | yield(10);
103 |
104 | AQ_NOTICE("Initialization complete, READY.\n");
105 |
106 | // startup complete, reduce comm task priority
107 | if (commData.commTask)
108 | CoSetPriority(commData.commTask, COMM_PRIORITY);
109 |
110 | // start telemetry
111 | telemetryEnable();
112 |
113 | // reset idle loop calibration now that everything is running
114 | minCycles = 999999999;
115 |
116 | CoExitTask();
117 | }
118 |
--------------------------------------------------------------------------------
/onboard/aq_init.h:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of AutoQuad.
3 |
4 | AutoQuad is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | AutoQuad is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 | You should have received a copy of the GNU General Public License
14 | along with AutoQuad. If not, see .
15 |
16 | Copyright © 2011-2014 Bill Nesbitt
17 | */
18 |
19 | #ifndef _aq_init_h
20 | #define _aq_init_h
21 |
22 | #include "aq.h"
23 | #include "digital.h"
24 | #include
25 |
26 | #define AQINIT_STACK_SIZE 400
27 | #define AQINIT_PRIORITY 12
28 |
29 | extern digitalPin *tp;
30 |
31 | extern OS_STK *aqInitStack;
32 |
33 | extern void aqInit(void *pdata);
34 |
35 | #endif
36 |
--------------------------------------------------------------------------------
/onboard/aq_math.h:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of AutoQuad.
3 |
4 | AutoQuad is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | AutoQuad is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 | You should have received a copy of the GNU General Public License
14 | along with AutoQuad. If not, see .
15 |
16 | Copyright © 2011-2014 Bill Nesbitt
17 | */
18 |
19 | #ifndef _aq_math_h
20 | #define _aq_math_h
21 |
22 | #include "arm_math.h"
23 |
24 | // first order quat filter
25 | typedef struct {
26 | float tc;
27 | float qz1[4];
28 | } quatFilter_t;
29 |
30 | extern void matrixInit(arm_matrix_instance_f32 *m, int rows, int cols);
31 | extern void matrixFree(arm_matrix_instance_f32 *m);
32 | extern void matrixDump(char *name, arm_matrix_instance_f32 *m);
33 | extern int qrDecompositionT_f32(arm_matrix_instance_f32 *A, arm_matrix_instance_f32 *Q, arm_matrix_instance_f32 *R);
34 | extern void matrixDiv_f32(arm_matrix_instance_f32 *X, arm_matrix_instance_f32 *A, arm_matrix_instance_f32 *B, arm_matrix_instance_f32 *Q, arm_matrix_instance_f32 *R, arm_matrix_instance_f32 *AQ);
35 | extern void quatMultiply(float32_t *qr, float32_t *q1, float32_t *q2);
36 | extern void eulerToQuatYPR(float32_t *q, float32_t yaw, float32_t pitch, float32_t roll);
37 | extern void eulerToQuatRPY(float32_t *q, float32_t roll, float32_t pitch, float32_t yaw);
38 | extern void vectorNormalize(float32_t *v, int n);
39 | extern void nlerp(float32_t *r, float32_t *a, float32_t *b, float32_t t);
40 | extern void quatFilterReset(quatFilter_t *f, float32_t *q);
41 | extern void quatFilterReset3(quatFilter_t *f, float32_t *q);
42 | extern void quatFilterInit(quatFilter_t *f, float32_t dt, float32_t tau, float32_t *q);
43 | extern void quatFilterInit3(quatFilter_t *f, float32_t dt, float32_t tau, float32_t *q);
44 | extern float32_t *quatFilter(quatFilter_t *f, float32_t *b);
45 | extern float32_t *quatFilter3(quatFilter_t *f, float32_t *b);
46 | extern int cholF(float32_t *U);
47 | extern void svd(float32_t *A, float32_t *S2, int n);
48 |
49 | #endif
50 |
--------------------------------------------------------------------------------
/onboard/aq_timer.c:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bn999/autoquad/c94161aeb610c8d4b22405c9be931524382bc8f9/onboard/aq_timer.c
--------------------------------------------------------------------------------
/onboard/aq_timer.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bn999/autoquad/c94161aeb610c8d4b22405c9be931524382bc8f9/onboard/aq_timer.h
--------------------------------------------------------------------------------
/onboard/arch.c:
--------------------------------------------------------------------------------
1 | /**
2 | *******************************************************************************
3 | * @file arch.c
4 | * @version V1.1.4
5 | * @date 2011.04.20
6 | * @brief This file provides InitTaskContext() and SysTick_Handler().
7 | *******************************************************************************
8 | * @copy
9 | * WRITE COPY INFORMATION USE CAPITAL LETTER
10 | *
11 | * © COPYRIGHT 2009 CooCox
12 | *******************************************************************************
13 | */
14 |
15 | /*---------------------------- Include ---------------------------------------*/
16 | #include
17 | U64 OSTickCnt = 0; /*!< Current system tick counter */
18 |
19 | /**
20 | ******************************************************************************
21 | * @brief Initial task context
22 | * @param[in] task Entry point of task.
23 | * @param[in] param The parameter pass to task.
24 | * @param[in] pstk The pointer to stack top.
25 | * @param[out] None
26 | * @retval Returns location of new stack top.
27 | *
28 | * @par Description
29 | * @details This function is called to initialize the stack frame of the
30 | * task being created.
31 | ******************************************************************************
32 | */
33 | OS_STK *InitTaskContext(FUNCPtr task,void *param,OS_STK *pstk)
34 | {
35 | OS_STK *context;
36 | context = pstk;
37 | *(context--) = (U32)0x01000000L; /* xPSR */
38 | *(context--) = (U32)task; /* Entry point of task. */
39 | *(context) = (U32)0xFFFFFFFEL;
40 | context = context - 5;
41 | *(context) = (U32)param; /* R0: argument */
42 | context = context - 8;
43 |
44 | context = context - 32; // NEZ - FPU registers
45 | *(--context) = (U32)0x30000000; // NEZ - FPU status reg
46 |
47 | return (context); /* Returns location of new stack top. */
48 | }
49 |
50 |
51 |
52 | /**
53 | *******************************************************************************
54 | * @brief System tick interrupt handler.
55 | * @param[in] None
56 | * @param[out] None
57 | * @retval None
58 | *
59 | * @par Description
60 | * @details This is system tick interrupt headler.
61 | * @note CoOS may schedule when exiting this ISR.
62 | *******************************************************************************
63 | */
64 | void SysTick_Handler(void)
65 | {
66 | OSSchedLock++; /* Lock scheduler. */
67 | OSTickCnt++; /* Increment systerm time. */
68 | #if CFG_TASK_WAITTING_EN >0
69 | if(DlyList != Co_NULL) /* Have task in delay list? */
70 | {
71 | if(DlyList->delayTick > 1) /* Delay time > 1? */
72 | {
73 | DlyList->delayTick--; /* Decrease delay time of the list head. */
74 | }
75 | else
76 | {
77 | DlyList->delayTick = 0;
78 | isr_TimeDispose(); /* Call hander for delay time list */
79 | }
80 | }
81 | #endif
82 |
83 | #if CFG_TMR_EN > 0
84 | if(TmrList != Co_NULL) /* Have timer in working? */
85 | {
86 | if(TmrList->tmrCnt > 1) /* Timer time > 1? */
87 | {
88 | TmrList->tmrCnt--; /* Decrease timer time of the list head. */
89 | }
90 | else
91 | {
92 | TmrList->tmrCnt = 0;
93 | isr_TmrDispose(); /* Call hander for timer list */
94 | }
95 | }
96 | #endif
97 | TaskSchedReq = Co_TRUE;
98 | OsSchedUnlock();
99 | }
100 |
--------------------------------------------------------------------------------
/onboard/board_6_1.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bn999/autoquad/c94161aeb610c8d4b22405c9be931524382bc8f9/onboard/board_6_1.h
--------------------------------------------------------------------------------
/onboard/board_6_1a.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bn999/autoquad/c94161aeb610c8d4b22405c9be931524382bc8f9/onboard/board_6_1a.h
--------------------------------------------------------------------------------
/onboard/board_7_0.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bn999/autoquad/c94161aeb610c8d4b22405c9be931524382bc8f9/onboard/board_7_0.h
--------------------------------------------------------------------------------
/onboard/board_dimu_v1.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bn999/autoquad/c94161aeb610c8d4b22405c9be931524382bc8f9/onboard/board_dimu_v1.h
--------------------------------------------------------------------------------
/onboard/board_dimu_v1_1.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bn999/autoquad/c94161aeb610c8d4b22405c9be931524382bc8f9/onboard/board_dimu_v1_1.h
--------------------------------------------------------------------------------
/onboard/board_dimu_v2.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bn999/autoquad/c94161aeb610c8d4b22405c9be931524382bc8f9/onboard/board_dimu_v2.h
--------------------------------------------------------------------------------
/onboard/board_dimu_v21.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bn999/autoquad/c94161aeb610c8d4b22405c9be931524382bc8f9/onboard/board_dimu_v21.h
--------------------------------------------------------------------------------
/onboard/board_m4.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bn999/autoquad/c94161aeb610c8d4b22405c9be931524382bc8f9/onboard/board_m4.h
--------------------------------------------------------------------------------
/onboard/board_m4_r3.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bn999/autoquad/c94161aeb610c8d4b22405c9be931524382bc8f9/onboard/board_m4_r3.h
--------------------------------------------------------------------------------
/onboard/board_m4_r4.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bn999/autoquad/c94161aeb610c8d4b22405c9be931524382bc8f9/onboard/board_m4_r4.h
--------------------------------------------------------------------------------
/onboard/board_m4_r5.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bn999/autoquad/c94161aeb610c8d4b22405c9be931524382bc8f9/onboard/board_m4_r5.h
--------------------------------------------------------------------------------
/onboard/board_m4_r6.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bn999/autoquad/c94161aeb610c8d4b22405c9be931524382bc8f9/onboard/board_m4_r6.h
--------------------------------------------------------------------------------
/onboard/buildnum.h:
--------------------------------------------------------------------------------
1 | #define BUILDNUMBER 1852
2 | #define REVISION "$Revision$"
3 |
--------------------------------------------------------------------------------
/onboard/calib.c:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bn999/autoquad/c94161aeb610c8d4b22405c9be931524382bc8f9/onboard/calib.c
--------------------------------------------------------------------------------
/onboard/calib.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bn999/autoquad/c94161aeb610c8d4b22405c9be931524382bc8f9/onboard/calib.h
--------------------------------------------------------------------------------
/onboard/can.c:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bn999/autoquad/c94161aeb610c8d4b22405c9be931524382bc8f9/onboard/can.c
--------------------------------------------------------------------------------
/onboard/can.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bn999/autoquad/c94161aeb610c8d4b22405c9be931524382bc8f9/onboard/can.h
--------------------------------------------------------------------------------
/onboard/canCalib.c:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bn999/autoquad/c94161aeb610c8d4b22405c9be931524382bc8f9/onboard/canCalib.c
--------------------------------------------------------------------------------
/onboard/canCalib.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bn999/autoquad/c94161aeb610c8d4b22405c9be931524382bc8f9/onboard/canCalib.h
--------------------------------------------------------------------------------
/onboard/canOSD.c:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bn999/autoquad/c94161aeb610c8d4b22405c9be931524382bc8f9/onboard/canOSD.c
--------------------------------------------------------------------------------
/onboard/canOSD.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bn999/autoquad/c94161aeb610c8d4b22405c9be931524382bc8f9/onboard/canOSD.h
--------------------------------------------------------------------------------
/onboard/canSensors.c:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of AutoQuad.
3 |
4 | AutoQuad is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | AutoQuad is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 | You should have received a copy of the GNU General Public License
14 | along with AutoQuad. If not, see .
15 |
16 | Copyright © 2011-2014 Bill Nesbitt
17 | */
18 |
19 | #include "canSensors.h"
20 | #include "aq_timer.h"
21 |
22 | canSensorsStruct_t canSensorsData;
23 |
24 | void canSensorsReceiveTelem(uint8_t canId, uint8_t doc, void *data) {
25 | canSensorsData.values[canId] = *(float *)data;
26 |
27 | // record reception time
28 | canSensorsData.rcvTimes[canId] = timerMicros();
29 | }
30 |
31 | void canSensorsInit(void) {
32 | int i;
33 |
34 | for (i = 0; i < CAN_SENSORS_NUM; i++) {
35 | if ((canSensorsData.nodes[i] = canFindNode(CAN_TYPE_SENSOR, i)) != 0) {
36 | canTelemRegister(canSensorsReceiveTelem, CAN_TYPE_SENSOR);
37 |
38 | // request telemetry
39 | canSetTelemetryValue(CAN_TT_NODE, canSensorsData.nodes[i]->networkId, 0, CAN_TELEM_VALUE);
40 | canSetTelemetryRate(CAN_TT_NODE, canSensorsData.nodes[i]->networkId, CAN_SENSORS_RATE);
41 | }
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/onboard/canSensors.h:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of AutoQuad.
3 |
4 | AutoQuad is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | AutoQuad is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 | You should have received a copy of the GNU General Public License
14 | along with AutoQuad. If not, see .
15 |
16 | Copyright © 2011-2014 Bill Nesbitt
17 | */
18 |
19 | #ifndef _cansensors_h
20 | #define _cansensors_h
21 |
22 | #include "can.h"
23 |
24 | #define CAN_SENSORS_RATE 10 // Hz
25 |
26 | // sensor types
27 | enum {
28 | CAN_SENSORS_PDB_BATV = 0,
29 | CAN_SENSORS_PDB_BATA,
30 | CAN_SENSORS_PDB_TEMP,
31 | CAN_SENSORS_GIMBAL_ACCX,
32 | CAN_SENSORS_GIMBAL_ACCY,
33 | CAN_SENSORS_GIMBAL_ACCZ,
34 | CAN_SENSORS_GIMBAL_GYOX,
35 | CAN_SENSORS_GIMBAL_GYOY,
36 | CAN_SENSORS_GIMBAL_GYOZ,
37 | CAN_SENSORS_NUM
38 | };
39 |
40 | typedef struct {
41 | canNodes_t *nodes[CAN_SENSORS_NUM];
42 | float values[CAN_SENSORS_NUM];
43 | uint32_t rcvTimes[CAN_SENSORS_NUM];
44 | } canSensorsStruct_t;
45 |
46 | extern canSensorsStruct_t canSensorsData;
47 |
48 | extern void canSensorsInit(void);
49 |
50 | #endif
51 |
--------------------------------------------------------------------------------
/onboard/canUart.c:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bn999/autoquad/c94161aeb610c8d4b22405c9be931524382bc8f9/onboard/canUart.c
--------------------------------------------------------------------------------
/onboard/canUart.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bn999/autoquad/c94161aeb610c8d4b22405c9be931524382bc8f9/onboard/canUart.h
--------------------------------------------------------------------------------
/onboard/comm.c:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bn999/autoquad/c94161aeb610c8d4b22405c9be931524382bc8f9/onboard/comm.c
--------------------------------------------------------------------------------
/onboard/command.h:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of AutoQuad.
3 |
4 | AutoQuad is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | AutoQuad is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 | You should have received a copy of the GNU General Public License
14 | along with AutoQuad. If not, see .
15 |
16 | Copyright © 2011-2014 Bill Nesbitt
17 | */
18 |
19 | #ifndef _command_h
20 | #define _command_h
21 |
22 | #include
23 |
24 | #define COMMAND_SYNC1 'A'
25 | #define COMMAND_SYNC2 'q'
26 | #define COMMAND_COMMAND 'C'
27 | #define COMMAND_FLOAT_DUMP 'F'
28 |
29 | #define COMMAND_WAIT_SYNC1 0x00
30 | #define COMMAND_WAIT_SYNC2 0x01
31 | #define COMMAND_WAIT_SYNC3 0x02
32 | #define COMMAND_WAIT_RQID1 0x03
33 | #define COMMAND_WAIT_RQID2 0x04
34 | #define COMMAND_WAIT_RQID3 0x05
35 | #define COMMAND_WAIT_RQID4 0x06
36 | #define COMMAND_WAIT_LEN 0x07
37 | #define COMMAND_PAYLOAD 0x08
38 | #define COMMAND_WAIT_ROWS 0x09
39 | #define COMMAND_WAIT_FLOATS 0x0a
40 | #define COMMAND_CHECK1 0xfe
41 | #define COMMAND_CHECK2 0xff
42 |
43 | #define COMMAND_ID_GPS_PASSTHROUGH 0x01
44 | #define COMMAND_CONFIG_PARAM_READ 0x07
45 | #define COMMAND_CONFIG_PARAM_WRITE 0x08
46 | #define COMMAND_CONFIG_FLASH_READ 0x09
47 | #define COMMAND_CONFIG_FLASH_WRITE 0x0a
48 | #define COMMAND_CONFIG_FACTORY_RESET 0x0b
49 | #define COMMAND_TELEMETRY_ENABLE 0x0c
50 | #define COMMAND_TELEMETRY_DISABLE 0x0d
51 | #define COMMAND_PID_START_DUMP 0x0e
52 | #define COMMAND_PID_STOP_DUMP 0x0f
53 | #define COMMAND_GPS_PACKET 0x10
54 | #define COMMAND_ACC_IN 0x11
55 | #define COMMAND_ID_ACK 0xfe
56 | #define COMMAND_ID_NACK 0xff
57 |
58 | typedef struct {
59 | unsigned char commandId;
60 | char data[256];
61 | } __attribute__((packed)) commandBufStruct_t;
62 |
63 | typedef struct {
64 | commandBufStruct_t buf;
65 | float floatDump[10];
66 |
67 | unsigned char requestId[sizeof(int)];
68 | unsigned char bufPoint;
69 | unsigned char state;
70 | unsigned char len;
71 | unsigned char checkA, checkB;
72 | unsigned long checksumErrors;
73 | } commandStruct_t;
74 |
75 | extern commandStruct_t commandData;
76 |
77 | extern void commandInit(void);
78 |
79 | #endif
80 |
--------------------------------------------------------------------------------
/onboard/compass.c:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of AutoQuad.
3 |
4 | AutoQuad is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | AutoQuad is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 | You should have received a copy of the GNU General Public License
14 | along with AutoQuad. If not, see .
15 |
16 | Copyright © 2011-2014 Bill Nesbitt
17 | */
18 |
19 | #include "aq.h"
20 | #include "compass.h"
21 |
22 | float compassNormalize(float heading) {
23 | while (heading < 0.0f)
24 | heading += 360.0f;
25 | while (heading >= 360.0f)
26 | heading -= 360.0f;
27 |
28 | return heading;
29 | }
30 |
31 | // calculate the shortest distance in yaw to get from b => a
32 | float compassDifference(float a, float b) {
33 | float diff = b - a;
34 |
35 | while (diff > 180.0f)
36 | diff -= 360.0f;
37 | while (diff <= -180.0f)
38 | diff += 360.0f;
39 |
40 | return diff;
41 | }
42 |
--------------------------------------------------------------------------------
/onboard/compass.h:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of AutoQuad.
3 |
4 | AutoQuad is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | AutoQuad is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 | You should have received a copy of the GNU General Public License
14 | along with AutoQuad. If not, see .
15 |
16 | Copyright © 2011-2014 Bill Nesbitt
17 | */
18 |
19 | #ifndef _compass_h
20 | #define _compass_h
21 |
22 | extern float compassNormalize(float heading);
23 | extern float compassDifference(float a, float b);
24 |
25 | #endif
26 |
--------------------------------------------------------------------------------
/onboard/config.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bn999/autoquad/c94161aeb610c8d4b22405c9be931524382bc8f9/onboard/config.h
--------------------------------------------------------------------------------
/onboard/config_default.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bn999/autoquad/c94161aeb610c8d4b22405c9be931524382bc8f9/onboard/config_default.h
--------------------------------------------------------------------------------
/onboard/config_default_m4.h:
--------------------------------------------------------------------------------
1 | #include "config_default.h"
2 |
3 | #ifndef USE_EXTERNAL_ESC
4 |
5 | #undef DEFAULT_MOT_ARM
6 | #undef DEFAULT_MOT_MIN
7 | #undef DEFAULT_MOT_START
8 | #undef DEFAULT_MOT_MAX
9 |
10 | #define DEFAULT_MOT_ARM 0
11 | #define DEFAULT_MOT_MIN 0
12 | #define DEFAULT_MOT_START 0
13 | #define DEFAULT_MOT_MAX 1050
14 |
15 | #endif
16 |
--------------------------------------------------------------------------------
/onboard/control.c:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bn999/autoquad/c94161aeb610c8d4b22405c9be931524382bc8f9/onboard/control.c
--------------------------------------------------------------------------------
/onboard/control.h:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of AutoQuad.
3 |
4 | AutoQuad is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | AutoQuad is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 | You should have received a copy of the GNU General Public License
14 | along with AutoQuad. If not, see .
15 |
16 | Copyright © 2011-2014 Bill Nesbitt
17 | */
18 |
19 | #ifndef _control_h
20 | #define _control_h
21 |
22 | #include "pid.h"
23 | #include "util.h"
24 | #include
25 |
26 | #define CONTROL_STACK_SIZE 200
27 | #define CONTROL_PRIORITY 5
28 |
29 | #define CONTROL_MIN_YAW_OVERRIDE 300 // in cycles (0.75 s)
30 |
31 | typedef struct {
32 | OS_TID controlTask;
33 |
34 | unsigned long loops;
35 |
36 | float userPitchTarget; // smoothed user pitch
37 | float userRollTarget; // smoothed user roll
38 |
39 | float navPitchTarget; // smoothed nav pitch
40 | float navRollTarget; // smoothed nav roll
41 |
42 | float pitch; // final requested pitch
43 | float roll; // final requested roll
44 | float yaw;
45 |
46 | utilFilter_t userPitchFilter[3];
47 | utilFilter_t userRollFilter[3];
48 |
49 | utilFilter_t navPitchFilter[3];
50 | utilFilter_t navRollFilter[3];
51 |
52 | pidStruct_t *rollRatePID;
53 | pidStruct_t *pitchRatePID;
54 | pidStruct_t *yawRatePID;
55 |
56 | pidStruct_t *rollAnglePID;
57 | pidStruct_t *pitchAnglePID;
58 | pidStruct_t *yawAnglePID;
59 |
60 | unsigned long lastUpdate; // time of raw data that this structure is based on
61 | } controlStruct_t;
62 |
63 | extern controlStruct_t controlData;
64 |
65 | extern void controlInit(void);
66 |
67 | #endif
68 |
--------------------------------------------------------------------------------
/onboard/coocox.h:
--------------------------------------------------------------------------------
1 | /**
2 | *******************************************************************************
3 | * @file coocox.h
4 | * @version V1.1.4
5 | * @date 2011.04.20
6 | * @brief Gather for all header file of CooCox CoOS.
7 | *******************************************************************************
8 | * @copy
9 | *
10 | * INTERNAL FILE,DON'T PUBLIC.
11 | *
12 | * © COPYRIGHT 2009 CooCox
13 | *******************************************************************************
14 | */
15 |
16 |
17 | #ifndef _COOCOX_H
18 | #define _COOCOX_H
19 |
20 | #define OS_VERSION (U16)0x0113 /*!< OS version.(format: Vx.xx),
21 | e.g. value 0x0113 is version V1.13*/
22 | /*---------------------------- Include ---------------------------------------*/
23 | #include "CoOS.h"
24 | #include "OsArch.h"
25 | #include "OsCore.h"
26 | #include "OsTask.h"
27 | #include "OsServiceReq.h"
28 | #include "OsError.h"
29 | #include "OsTime.h"
30 |
31 |
32 | #if CFG_TMR_EN > 0
33 | #include "OsTimer.h"
34 | #endif
35 |
36 | #if CFG_KHEAP_EN > 0
37 | #include "OsKernelHeap.h"
38 | #endif
39 |
40 | #if CFG_MM_EN >0
41 | #include "OsMM.h"
42 | #endif
43 |
44 | #if CFG_EVENT_EN > 0
45 | #include "OsEvent.h"
46 | #endif
47 |
48 | #if CFG_MUTEX_EN > 0
49 | #include "OsMutex.h"
50 | #endif
51 |
52 | #if CFG_QUEUE_EN > 0
53 | #include "OsQueue.h"
54 | #endif
55 |
56 | #if CFG_FLAG_EN > 0
57 | #include "OsFlag.h"
58 | #endif
59 |
60 | #endif /* _COOCOX_H */
61 |
--------------------------------------------------------------------------------
/onboard/cyrf6936.c:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bn999/autoquad/c94161aeb610c8d4b22405c9be931524382bc8f9/onboard/cyrf6936.c
--------------------------------------------------------------------------------
/onboard/cyrf6936.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bn999/autoquad/c94161aeb610c8d4b22405c9be931524382bc8f9/onboard/cyrf6936.h
--------------------------------------------------------------------------------
/onboard/cyrf6936_regs.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bn999/autoquad/c94161aeb610c8d4b22405c9be931524382bc8f9/onboard/cyrf6936_regs.h
--------------------------------------------------------------------------------
/onboard/d_imu.c:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bn999/autoquad/c94161aeb610c8d4b22405c9be931524382bc8f9/onboard/d_imu.c
--------------------------------------------------------------------------------
/onboard/d_imu.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bn999/autoquad/c94161aeb610c8d4b22405c9be931524382bc8f9/onboard/d_imu.h
--------------------------------------------------------------------------------
/onboard/digital.c:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of AutoQuad.
3 |
4 | AutoQuad is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | AutoQuad is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 | You should have received a copy of the GNU General Public License
14 | along with AutoQuad. If not, see .
15 |
16 | Copyright © 2011-2014 Bill Nesbitt
17 | */
18 |
19 | #include "digital.h"
20 | #include "util.h"
21 |
22 | uint32_t *digitalInit(GPIO_TypeDef* port, const uint16_t pin, uint8_t initial) {
23 | GPIO_InitTypeDef GPIO_InitStructure;
24 | uint32_t *bbAddr;
25 | uint16_t myPin = pin;
26 | uint8_t bit;
27 |
28 | bit = 0;
29 | while (myPin >>= 1)
30 | bit++;
31 |
32 | if (bit < 8)
33 | bbAddr = PERIPH2BB((uint32_t)port + 0x14, bit);
34 | else
35 | bbAddr = PERIPH2BB((uint32_t)port + 0x15, bit-8);
36 |
37 | *bbAddr = initial;
38 |
39 | GPIO_StructInit(&GPIO_InitStructure);
40 | GPIO_InitStructure.GPIO_Pin = pin;
41 | GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
42 | GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
43 | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
44 | GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
45 | GPIO_Init(port, &GPIO_InitStructure);
46 |
47 | return bbAddr;
48 | }
49 |
--------------------------------------------------------------------------------
/onboard/digital.h:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of AutoQuad.
3 |
4 | AutoQuad is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | AutoQuad is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 | You should have received a copy of the GNU General Public License
14 | along with AutoQuad. If not, see .
15 |
16 | Copyright © 2011-2014 Bill Nesbitt
17 | */
18 |
19 | #ifndef _DIGITAL_H
20 | #define _DIGITAL_H
21 |
22 | #include "aq.h"
23 |
24 | typedef uint32_t digitalPin;
25 |
26 | #define digitalHi(p) *p = 1
27 | #define digitalLo(p) *p = 0
28 | #define digitalSet(p, n) *p = n
29 | #define digitalGet(p) (*p)
30 | #define digitalTogg(p) *p = !(*p)
31 |
32 | extern uint32_t *digitalInit(GPIO_TypeDef* port, const uint16_t pin, uint8_t initial);
33 |
34 | #endif
35 |
--------------------------------------------------------------------------------
/onboard/diskio.h:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of AutoQuad.
3 |
4 | AutoQuad is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | AutoQuad is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 | You should have received a copy of the GNU General Public License
14 | along with AutoQuad. If not, see .
15 |
16 | Copyright © 2011-2014 Bill Nesbitt
17 | */
18 |
19 | /*-----------------------------------------------------------------------
20 | / Low level disk interface modlue include file (C)ChaN, 2010
21 | /-----------------------------------------------------------------------*/
22 |
23 | #ifndef _DISKIO
24 |
25 | #define _READONLY 0 /* 1: Remove write functions */
26 | #define _USE_IOCTL 1 /* 1: Use disk_ioctl fucntion */
27 |
28 | #include "integer.h"
29 |
30 |
31 | /* Status of Disk Functions */
32 | typedef BYTE DSTATUS;
33 |
34 | /* Results of Disk Functions */
35 | typedef enum {
36 | RES_OK = 0, /* 0: Successful */
37 | RES_ERROR, /* 1: R/W Error */
38 | RES_WRPRT, /* 2: Write Protected */
39 | RES_NOTRDY, /* 3: Not Ready */
40 | RES_PARERR /* 4: Invalid Parameter */
41 | } DRESULT;
42 |
43 |
44 | /*---------------------------------------*/
45 | /* Prototypes for disk control functions */
46 |
47 | int assign_drives (int, int);
48 | DSTATUS disk_initialize (BYTE);
49 | DSTATUS disk_status (BYTE);
50 | DRESULT disk_read (BYTE, BYTE*, DWORD, BYTE);
51 | #if _READONLY == 0
52 | DRESULT disk_write (BYTE, const BYTE*, DWORD, BYTE);
53 | #endif
54 | DRESULT disk_ioctl (BYTE, BYTE, void*);
55 |
56 |
57 |
58 | /* Disk Status Bits (DSTATUS) */
59 |
60 | #define STA_NOINIT 0x01 /* Drive not initialized */
61 | #define STA_NODISK 0x02 /* No medium in the drive */
62 | #define STA_PROTECT 0x04 /* Write protected */
63 |
64 |
65 | /* Command code for disk_ioctrl fucntion */
66 |
67 | /* Generic command (defined for FatFs) */
68 | #define CTRL_SYNC 0 /* Flush disk cache (for write functions) */
69 | #define GET_SECTOR_COUNT 1 /* Get media size (for only f_mkfs()) */
70 | #define GET_SECTOR_SIZE 2 /* Get sector size (for multiple sector size (_MAX_SS >= 1024)) */
71 | #define GET_BLOCK_SIZE 3 /* Get erase block size (for only f_mkfs()) */
72 | #define CTRL_ERASE_SECTOR 4 /* Force erased a block of sectors (for only _USE_ERASE) */
73 |
74 | /* Generic command */
75 | #define CTRL_POWER 5 /* Get/Set power status */
76 | #define CTRL_LOCK 6 /* Lock/Unlock media removal */
77 | #define CTRL_EJECT 7 /* Eject media */
78 |
79 | /* MMC/SDC specific ioctl command */
80 | #define MMC_GET_TYPE 10 /* Get card type */
81 | #define MMC_GET_CSD 11 /* Get CSD */
82 | #define MMC_GET_CID 12 /* Get CID */
83 | #define MMC_GET_OCR 13 /* Get OCR */
84 | #define MMC_GET_SDSTAT 14 /* Get SD status */
85 |
86 | /* ATA/CF specific ioctl command */
87 | #define ATA_GET_REV 20 /* Get F/W revision */
88 | #define ATA_GET_MODEL 21 /* Get model name */
89 | #define ATA_GET_SN 22 /* Get serial number */
90 |
91 | /* NAND specific ioctl command */
92 | #define NAND_FORMAT 30 /* Create physical format */
93 |
94 |
95 | #define _DISKIO
96 | #endif
97 |
--------------------------------------------------------------------------------
/onboard/dsm.c:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bn999/autoquad/c94161aeb610c8d4b22405c9be931524382bc8f9/onboard/dsm.c
--------------------------------------------------------------------------------
/onboard/dsm.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bn999/autoquad/c94161aeb610c8d4b22405c9be931524382bc8f9/onboard/dsm.h
--------------------------------------------------------------------------------
/onboard/eeprom.c:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bn999/autoquad/c94161aeb610c8d4b22405c9be931524382bc8f9/onboard/eeprom.c
--------------------------------------------------------------------------------
/onboard/eeprom.h:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of AutoQuad.
3 |
4 | AutoQuad is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | AutoQuad is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 | You should have received a copy of the GNU General Public License
14 | along with AutoQuad. If not, see .
15 |
16 | Copyright © 2011-2014 Bill Nesbitt
17 | */
18 |
19 | #ifndef _eeprom_h
20 | #define _eeprom_h
21 |
22 | #include "spi.h"
23 |
24 | #define DIMU_EEPROM_SPI_BAUD SPI_BaudRatePrescaler_4 // 10.5 MHz
25 |
26 | #define DIMU_EEPROM_SIZE 0x8000
27 | #define DIMU_EEPROM_BLOCK_SIZE 0x40
28 | #define DIMU_EEPROM_MASK 0x7fff
29 | //#define DIUM_EEPROM_SIZE 0x10000
30 | //#define DIUM_EEPROM_BLOCK_SIZE 0x80
31 | //#define DIUM_EEPROM_MASK 0xffff
32 |
33 | #define EEPROM_WREN 0b0110
34 | #define EEPROM_WRDI 0b0100
35 | #define EEPROM_RDSR 0b0101
36 | #define EEPROM_WRSR 0b0001
37 | #define EEPROM_READ 0b0011
38 | #define EEPROM_WRITE 0b0010
39 |
40 | #define EEPROM_VERSION 0x00010001
41 | #define EEPROM_SIGNATURE 0xdeafbeef
42 |
43 | typedef struct {
44 | uint8_t cmd;
45 | uint8_t addr[2];
46 | uint8_t data[DIMU_EEPROM_BLOCK_SIZE];
47 | } __attribute__((packed)) eepromBuf_t;
48 |
49 | typedef struct {
50 | uint32_t signature;
51 | uint32_t version;
52 | uint32_t seq;
53 | uint16_t size;
54 | uint16_t start;
55 | uint8_t fileCk[2];
56 | uint8_t headerCk[2];
57 | } __attribute__((packed)) eepromHeader_t;
58 |
59 | typedef struct {
60 | spiClient_t *spi;
61 | volatile uint32_t spiFlag;
62 | eepromBuf_t buf;
63 | eepromHeader_t header;
64 | uint16_t readPointer;
65 | uint8_t ck[2];
66 | uint8_t status;
67 | } eepromStruct_t;
68 |
69 | extern void eepromPreInit(void);
70 | extern void eepromInit(void);
71 | extern uint8_t *eepromOpenWrite(void);
72 | extern void eepromWrite(void);
73 | extern void eepromClose(void);
74 | extern uint8_t *eepromOpenRead(void);
75 | extern uint8_t eepromRead(int size);
76 |
77 | #endif
78 |
--------------------------------------------------------------------------------
/onboard/esc32.c:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bn999/autoquad/c94161aeb610c8d4b22405c9be931524382bc8f9/onboard/esc32.c
--------------------------------------------------------------------------------
/onboard/esc32.h:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of AutoQuad.
3 |
4 | AutoQuad is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | AutoQuad is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 | You should have received a copy of the GNU General Public License
14 | along with AutoQuad. If not, see .
15 |
16 | Copyright © 2011-2014 Bill Nesbitt
17 | */
18 |
19 | #ifndef _esc32_h
20 | #define _esc32_h
21 |
22 | #include "can.h"
23 |
24 | #define ESC32_FILE_NAME "esc32.txt"
25 | #define ESC32_FILE_BUF_SIZE 512
26 | #define ESC32_LINE_BUF_SIZE 128
27 |
28 | enum esc32States {
29 | ESC32_STATE_DISARMED = 0,
30 | ESC32_STATE_STOPPED,
31 | ESC32_STATE_NOCOMM,
32 | ES32C_STATE_STARTING,
33 | ESC32_STATE_RUNNING
34 | };
35 |
36 | typedef struct {
37 | unsigned int state : 3;
38 | unsigned int vin : 12; // x 100
39 | unsigned int amps : 14; // x 100
40 | unsigned int rpm : 15;
41 | unsigned int duty : 8; // x (255/100)
42 | unsigned int temp : 9; // (Deg C + 32) * 4
43 | unsigned int errCode : 3;
44 | } __attribute__((packed)) esc32CanStatus_t;
45 |
46 | extern void esc32SetupOw(const GPIO_TypeDef *port, const uint16_t pin, uint8_t mode);
47 | extern float esc32SetupCan(canNodes_t *canNode, uint8_t mode);
48 |
49 | #endif
50 |
--------------------------------------------------------------------------------
/onboard/ext_irq.c:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bn999/autoquad/c94161aeb610c8d4b22405c9be931524382bc8f9/onboard/ext_irq.c
--------------------------------------------------------------------------------
/onboard/ext_irq.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bn999/autoquad/c94161aeb610c8d4b22405c9be931524382bc8f9/onboard/ext_irq.h
--------------------------------------------------------------------------------
/onboard/filer.c:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bn999/autoquad/c94161aeb610c8d4b22405c9be931524382bc8f9/onboard/filer.c
--------------------------------------------------------------------------------
/onboard/filer.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bn999/autoquad/c94161aeb610c8d4b22405c9be931524382bc8f9/onboard/filer.h
--------------------------------------------------------------------------------
/onboard/flash.c:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of AutoQuad.
3 |
4 | AutoQuad is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | AutoQuad is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 | You should have received a copy of the GNU General Public License
14 | along with AutoQuad. If not, see .
15 |
16 | Copyright © 2011-2014 Bill Nesbitt
17 | */
18 |
19 | #include "flash.h"
20 |
21 | // Gets the sector of a given address
22 | uint32_t GetSector(uint32_t Address) {
23 | uint32_t sector = 0;
24 |
25 | if((Address < ADDR_FLASH_SECTOR_1) && (Address >= ADDR_FLASH_SECTOR_0)) {
26 | sector = FLASH_Sector_0;
27 | }
28 | else if((Address < ADDR_FLASH_SECTOR_2) && (Address >= ADDR_FLASH_SECTOR_1)) {
29 | sector = FLASH_Sector_1;
30 | }
31 | else if((Address < ADDR_FLASH_SECTOR_3) && (Address >= ADDR_FLASH_SECTOR_2)) {
32 | sector = FLASH_Sector_2;
33 | }
34 | else if((Address < ADDR_FLASH_SECTOR_4) && (Address >= ADDR_FLASH_SECTOR_3)) {
35 | sector = FLASH_Sector_3;
36 | }
37 | else if((Address < ADDR_FLASH_SECTOR_5) && (Address >= ADDR_FLASH_SECTOR_4)) {
38 | sector = FLASH_Sector_4;
39 | }
40 | else if((Address < ADDR_FLASH_SECTOR_6) && (Address >= ADDR_FLASH_SECTOR_5)) {
41 | sector = FLASH_Sector_5;
42 | }
43 | else if((Address < ADDR_FLASH_SECTOR_7) && (Address >= ADDR_FLASH_SECTOR_6)) {
44 | sector = FLASH_Sector_6;
45 | }
46 | else if((Address < ADDR_FLASH_SECTOR_8) && (Address >= ADDR_FLASH_SECTOR_7)) {
47 | sector = FLASH_Sector_7;
48 | }
49 | else if((Address < ADDR_FLASH_SECTOR_9) && (Address >= ADDR_FLASH_SECTOR_8)) {
50 | sector = FLASH_Sector_8;
51 | }
52 | else if((Address < ADDR_FLASH_SECTOR_10) && (Address >= ADDR_FLASH_SECTOR_9)) {
53 | sector = FLASH_Sector_9;
54 | }
55 | else if((Address < ADDR_FLASH_SECTOR_11) && (Address >= ADDR_FLASH_SECTOR_10)) {
56 | sector = FLASH_Sector_10;
57 | }
58 | else/*(Address < FLASH_END_ADDR) && (Address >= ADDR_FLASH_SECTOR_11))*/ {
59 | sector = FLASH_Sector_11;
60 | }
61 |
62 | return sector;
63 | }
64 |
65 | int flashAddress(uint32_t startAddr, uint32_t *data, uint32_t len) {
66 | FLASH_Status status;
67 | int retries;
68 | int ret = 1;
69 | int i;
70 |
71 | FLASH_Unlock();
72 |
73 | // Clear pending flags (if any)
74 | FLASH_ClearFlag(FLASH_FLAG_EOP | FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR | FLASH_FLAG_PGPERR | FLASH_FLAG_PGSERR);
75 |
76 | for (i = 0; i < len; i++) {
77 | retries = 0;
78 | do {
79 | status = FLASH_ProgramWord(startAddr + i*4, *(data + i));
80 | retries++;
81 | } while (status != FLASH_COMPLETE && retries < FLASH_RETRIES);
82 |
83 | if (retries == FLASH_RETRIES) {
84 | ret = 0;
85 | break;
86 | }
87 | }
88 |
89 | FLASH_Lock();
90 |
91 | return ret;
92 | }
93 |
94 | int flashErase(uint32_t startAddr, uint32_t len) {
95 | FLASH_Status status;
96 | unsigned int retries;
97 | int ret;
98 | uint32_t startSector, endSector;
99 | uint32_t i;
100 |
101 | if (startAddr == 0)
102 | startAddr = FLASH_START_ADDR;
103 |
104 | FLASH_Unlock();
105 |
106 | // Clear pending flags (if any)
107 | FLASH_ClearFlag(FLASH_FLAG_EOP | FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR | FLASH_FLAG_PGPERR | FLASH_FLAG_PGSERR);
108 |
109 | ret = 1;
110 |
111 | startSector = GetSector(startAddr);
112 | endSector = GetSector(startAddr + len*4);
113 |
114 | i = startSector;
115 | while (i <= endSector) {
116 | retries = 0;
117 | do {
118 | // Device voltage range supposed to be [2.7V to 3.6V], the operation will be done by word
119 | status = FLASH_EraseSector(i, VoltageRange_3);
120 | retries++;
121 | } while (status != FLASH_COMPLETE && retries < FLASH_RETRIES);
122 |
123 | if (retries == FLASH_RETRIES) {
124 | ret = 0;
125 | break;
126 | }
127 |
128 | if (i == FLASH_Sector_11)
129 | i += 40;
130 | else
131 | i += 8;
132 | }
133 |
134 | FLASH_Lock();
135 |
136 | return ret;
137 | }
138 |
139 | uint32_t flashStartAddr(void) {
140 | return FLASH_START_ADDR;
141 | }
142 |
143 | uint32_t flashSerno(uint8_t n) {
144 | return *((uint32_t *)(0x1FFF7A10) + n);
145 | }
146 |
--------------------------------------------------------------------------------
/onboard/flash.h:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of AutoQuad.
3 |
4 | AutoQuad is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | AutoQuad is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 | You should have received a copy of the GNU General Public License
14 | along with AutoQuad. If not, see .
15 |
16 | Copyright © 2011-2014 Bill Nesbitt
17 | */
18 |
19 | #ifndef _flash_h
20 | #define _flash_h
21 |
22 | #include "aq.h"
23 |
24 | #define FLASH_START_ADDR ((uint32_t)0x080E0000)
25 | #define FLASH_END_ADDR ((uint32_t)0x080FFFFF)
26 | #define FLASH_RETRIES 3
27 |
28 | // Base address of the Flash sectors
29 | #define ADDR_FLASH_SECTOR_0 ((uint32_t)0x08000000) /* Base @ of Sector 0, 16 Kbytes */
30 | #define ADDR_FLASH_SECTOR_1 ((uint32_t)0x08004000) /* Base @ of Sector 1, 16 Kbytes */
31 | #define ADDR_FLASH_SECTOR_2 ((uint32_t)0x08008000) /* Base @ of Sector 2, 16 Kbytes */
32 | #define ADDR_FLASH_SECTOR_3 ((uint32_t)0x0800C000) /* Base @ of Sector 3, 16 Kbytes */
33 | #define ADDR_FLASH_SECTOR_4 ((uint32_t)0x08010000) /* Base @ of Sector 4, 64 Kbytes */
34 | #define ADDR_FLASH_SECTOR_5 ((uint32_t)0x08020000) /* Base @ of Sector 5, 128 Kbytes */
35 | #define ADDR_FLASH_SECTOR_6 ((uint32_t)0x08040000) /* Base @ of Sector 6, 128 Kbytes */
36 | #define ADDR_FLASH_SECTOR_7 ((uint32_t)0x08060000) /* Base @ of Sector 7, 128 Kbytes */
37 | #define ADDR_FLASH_SECTOR_8 ((uint32_t)0x08080000) /* Base @ of Sector 8, 128 Kbytes */
38 | #define ADDR_FLASH_SECTOR_9 ((uint32_t)0x080A0000) /* Base @ of Sector 9, 128 Kbytes */
39 | #define ADDR_FLASH_SECTOR_10 ((uint32_t)0x080C0000) /* Base @ of Sector 10, 128 Kbytes */
40 | #define ADDR_FLASH_SECTOR_11 ((uint32_t)0x080E0000) /* Base @ of Sector 11, 128 Kbytes */
41 |
42 | extern int flashAddress(uint32_t startAddr, uint32_t *data, uint32_t len);
43 | extern int flashErase(uint32_t startAddr, uint32_t len);
44 | extern uint32_t flashStartAddr(void);
45 | extern uint32_t flashSerno(uint8_t n);
46 |
47 | #endif
48 |
--------------------------------------------------------------------------------
/onboard/flash_placement.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/onboard/fpu.c:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of AutoQuad.
3 |
4 | AutoQuad is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | AutoQuad is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 | You should have received a copy of the GNU General Public License
14 | along with AutoQuad. If not, see .
15 |
16 | Copyright © 2011-2014 Bill Nesbitt
17 | */
18 |
19 | #include "fpu.h"
20 | #include
21 | #include
22 |
23 | // setup system to do lazy FPU context switching triggered by the NOCP UsageFault exception
24 | void fpuInit(void) {
25 | FPU->FPCCR &= ~FPU_FPCCR_ASPEN_Msk; // turn off FP context save
26 | FPU->FPCCR &= ~FPU_FPCCR_LSPEN_Msk; // turn off lazy save
27 | #ifdef FPU_LAZY_SWITCH
28 | SCB->SHCSR |= SCB_SHCSR_USGFAULTENA_Msk; // turn on usage fault interrupt
29 | CoreDebug->DEMCR &= ~ CoreDebug_DEMCR_VC_NOCPERR_Msk; // disable debug halt on UsageFault caused by an access to the FPU Coprocessor
30 | __fpu_disable(); // disable FPU access
31 | #endif
32 | }
33 |
--------------------------------------------------------------------------------
/onboard/fpu.h:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of AutoQuad.
3 |
4 | AutoQuad is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | AutoQuad is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 | You should have received a copy of the GNU General Public License
14 | along with AutoQuad. If not, see .
15 |
16 | Copyright © 2011-2014 Bill Nesbitt
17 | */
18 |
19 | #ifndef fpu_h_
20 | #define fpu_h_
21 |
22 | #include "stm32f4xx.h"
23 | #include
24 |
25 |
26 | //#define FPU_SOFT
27 | #define FPU_HARD
28 |
29 | #define __fpu_enable() __asm__ __volatile__ ("LDR.W R0, =0xE000ED88 \n" \
30 | "LDR R1, [R0] \n" \
31 | "ORR R1, R1, #(0xF << 20) \n" \
32 | "STR R1, [R0]")
33 | #define __fpu_disable() __asm__ __volatile__ ("LDR.W R0, =0xE000ED88 \n" \
34 | "LDR R1, [R0] \n" \
35 | "BIC R1, R1, #(0xF << 20) \n" \
36 | "STR R1, [R0]")
37 |
38 | extern void fpuInit(void);
39 |
40 | #endif
41 |
--------------------------------------------------------------------------------
/onboard/futaba.c:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of AutoQuad.
3 |
4 | AutoQuad is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | AutoQuad is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 | You should have received a copy of the GNU General Public License
14 | along with AutoQuad. If not, see .
15 |
16 | Copyright © 2011-2014 Bill Nesbitt
17 | */
18 |
19 | #include "aq.h"
20 | #include "radio.h"
21 | #include "futaba.h"
22 | #include "aq_mavlink.h"
23 | #include "imu.h"
24 | #include "util.h"
25 | #include "aq_timer.h"
26 | #include
27 |
28 | futabaStruct_t futabaData __attribute__((section(".ccm")));
29 |
30 | int futabaDecode(radioInstance_t *r) {
31 | if (futabaData.u.rawBuf[22] & 0b0100) {
32 | r->errorCount++;
33 | return -1;
34 | }
35 | else {
36 | r->channels[0] = 1696 - futabaData.u.channels.channel3;
37 | r->channels[1] = futabaData.u.channels.channel1 - 1024;
38 | r->channels[2] = futabaData.u.channels.channel2 - 1024;
39 | r->channels[3] = futabaData.u.channels.channel4 - 1024;
40 | r->channels[4] = 1024 - futabaData.u.channels.channel5;
41 | r->channels[5] = 1024 - futabaData.u.channels.channel6;
42 | r->channels[6] = 1024 - futabaData.u.channels.channel7;
43 | r->channels[7] = 1024 - futabaData.u.channels.channel8;
44 | r->channels[8] = 1024 - futabaData.u.channels.channel9;
45 | r->channels[9] = 1024 - futabaData.u.channels.channel10;
46 | r->channels[10] = 1024 - futabaData.u.channels.channel11;
47 | r->channels[11] = 1024 - futabaData.u.channels.channel12;
48 | r->channels[12] = 1024 - futabaData.u.channels.channel13;
49 | r->channels[13] = 1024 - futabaData.u.channels.channel14;
50 | r->channels[14] = 1024 - futabaData.u.channels.channel15;
51 | r->channels[15] = 1024 - futabaData.u.channels.channel16;
52 |
53 | r->channels[16] = futabaData.u.rawBuf[22] & 0b0001 ? 800 : -800;
54 | r->channels[17] = futabaData.u.rawBuf[22] & 0b0010 ? 800 : -800;
55 |
56 | return 1;
57 | }
58 | }
59 |
60 | int futabaCharIn(radioInstance_t *r, uint8_t c) {
61 |
62 | // force top of frame if its been more than 3ms since last input
63 | // this is a safeguard in case we started receiving bytes in the middle of a frame
64 | // shortest Futaba frame = 7ms - 3ms for data = 4ms minimum gap
65 | if (timerMicros() - futabaData.lastCharReceived > 3000)
66 | futabaData.state = FUTABA_WAIT_SYNC;
67 |
68 | futabaData.lastCharReceived = timerMicros();
69 |
70 | switch (futabaData.state) {
71 | case FUTABA_WAIT_SYNC:
72 | if (c == FUTABA_START_CHAR) {
73 | futabaData.state = FUTABA_WAIT_DATA;
74 | futabaData.dataCount = 0;
75 | futabaData.validFrame = 0;
76 | }
77 | break;
78 |
79 | case FUTABA_WAIT_DATA:
80 | futabaData.u.rawBuf[futabaData.dataCount++] = c;
81 | if (futabaData.dataCount == 23)
82 | futabaData.state = FUTABA_WAIT_END;
83 | // make sure at least one channel value byte is > 0
84 | // all zeros means something is wrong with Rx (observed in the wild)
85 | if (c)
86 | futabaData.validFrame = 1;
87 | break;
88 |
89 | case FUTABA_WAIT_END:
90 | futabaData.state = FUTABA_WAIT_SYNC;
91 | if ((c & FUTABA_END_CHAR) == 0 && futabaData.validFrame)
92 | return futabaDecode(r);
93 | break;
94 | }
95 |
96 | return 0;
97 | }
98 |
99 | void futabaInit(radioInstance_t *r, USART_TypeDef *uart) {
100 | memset((void *)&futabaData, 0, sizeof(futabaData));
101 |
102 | r->serialPort = serialOpen(uart, FUTABA_BAUD, USART_HardwareFlowControl_None, FUTABA_RXBUF_SIZE, 0);
103 | serialChangeParity(r->serialPort, USART_Parity_Even);
104 | serialChangeStopBits(r->serialPort, USART_StopBits_2);
105 | }
106 |
--------------------------------------------------------------------------------
/onboard/futaba.h:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of AutoQuad.
3 |
4 | AutoQuad is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | AutoQuad is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 | You should have received a copy of the GNU General Public License
14 | along with AutoQuad. If not, see .
15 |
16 | Copyright © 2011-2014 Bill Nesbitt
17 | */
18 |
19 | #ifndef _futaba_h
20 | #define _futaba_h
21 |
22 | #include "radio.h"
23 |
24 | #define FUTABA_BAUD 100000
25 | #define FUTABA_RXBUF_SIZE 32
26 |
27 | #define FUTABA_START_CHAR 0x0f
28 | #define FUTABA_END_CHAR 0b11000011
29 |
30 | #define FUTABA_WAIT_SYNC 0x00
31 | #define FUTABA_WAIT_DATA 0x01
32 | #define FUTABA_WAIT_END 0x02
33 |
34 | typedef struct {
35 | unsigned channel1 : 11;
36 | unsigned channel2 : 11;
37 | unsigned channel3 : 11;
38 | unsigned channel4 : 11;
39 | unsigned channel5 : 11;
40 | unsigned channel6 : 11;
41 | unsigned channel7 : 11;
42 | unsigned channel8 : 11;
43 | unsigned channel9 : 11;
44 | unsigned channel10 : 11;
45 | unsigned channel11 : 11;
46 | unsigned channel12 : 11;
47 | unsigned channel13 : 11;
48 | unsigned channel14 : 11;
49 | unsigned channel15 : 11;
50 | unsigned channel16 : 11;
51 | } __attribute__((packed)) futabaChannelStruct_t;
52 |
53 | typedef struct {
54 | uint8_t state;
55 | uint8_t dataCount;
56 | uint8_t validFrame;
57 | uint32_t lastCharReceived;
58 |
59 | union {
60 | uint8_t rawBuf[23];
61 | futabaChannelStruct_t channels;
62 | } u;
63 | } futabaStruct_t;
64 |
65 | extern futabaStruct_t futabaData;
66 |
67 | extern void futabaInit(radioInstance_t *r, USART_TypeDef *uart);
68 | extern int futabaCharIn(radioInstance_t *r, uint8_t c);
69 |
70 | #endif
71 |
--------------------------------------------------------------------------------
/onboard/getbuildnum.c:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of AutoQuad.
3 |
4 | AutoQuad is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | AutoQuad is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 | You should have received a copy of the GNU General Public License
14 | along with AutoQuad. If not, see .
15 |
16 | Copyright © 2011-2014 Bill Nesbitt
17 | */
18 |
19 | #include "getbuildnum.h"
20 | #include
21 |
22 | unsigned long getBuildNumber(void) {
23 | return (unsigned)BUILDNUMBER;
24 | }
25 |
26 | unsigned long getRevisionNumber(void) {
27 | unsigned long rev;
28 |
29 | sscanf(REVISION, "$Revision: %ld", &rev);
30 |
31 | return rev;
32 | }
33 |
--------------------------------------------------------------------------------
/onboard/getbuildnum.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bn999/autoquad/c94161aeb610c8d4b22405c9be931524382bc8f9/onboard/getbuildnum.h
--------------------------------------------------------------------------------
/onboard/gimbal.h:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of AutoQuad.
3 |
4 | AutoQuad is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | AutoQuad is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 | You should have received a copy of the GNU General Public License
14 | along with AutoQuad. If not, see .
15 |
16 | Copyright © 2011-2014 Bill Nesbitt
17 | */
18 |
19 | #ifndef _gimbal_h
20 | #define _gimbal_h
21 |
22 | #include "pwm.h"
23 |
24 | #define GMBL_DEGREES_TO_PW (2000 - 1000) // degrees multiplier to obtain PWM pulse width before scaling
25 |
26 | // PWM values for triggerPort and passthroughPort outputs
27 | #define GMBL_TRIG_NTRL_PWM 1500 // middle position pulse width (this gets added to AQ radio value)
28 | #define GMBL_TRIG_MIN_PWM 750 // minimum pulse width
29 | #define GMBL_TRIG_MAX_PWM 2250 // maximum pulse width
30 |
31 | typedef struct {
32 | float tilt; // last gimbal pitch output position
33 | uint8_t trigger; // boolean indicating automatic trigger is activated (can be set externally, eg. to trigger photo at wpt)
34 | uint16_t triggerCount; // total times trigger has been activated
35 | uint16_t triggerLogVal; // value to be logged == 0 when not active, == triggerCount when active
36 | uint32_t triggerTimer; // keep track of how long trigger has been active. == 0 when trigger is not active
37 | uint32_t triggerLastTime; // keep track of last trigger activation (for trigger by time interval)
38 | double triggerLastLat; // latitude of last trigger activation (for trigger by distance interval)
39 | double triggerLastLon; // longitude of last trigger activation
40 |
41 | pwmPortStruct_t *pitchPort;
42 | pwmPortStruct_t *rollPort;
43 | pwmPortStruct_t *tiltPort;
44 | pwmPortStruct_t *triggerPort;
45 | pwmPortStruct_t *passthroughPort;
46 | } gimbalStruct_t;
47 |
48 | extern gimbalStruct_t gimbalData;
49 |
50 | extern void gimbalInit(void);
51 | extern void gimbalUpdate(void);
52 |
53 | #endif
54 |
--------------------------------------------------------------------------------
/onboard/gps.c:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bn999/autoquad/c94161aeb610c8d4b22405c9be931524382bc8f9/onboard/gps.c
--------------------------------------------------------------------------------
/onboard/gps.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bn999/autoquad/c94161aeb610c8d4b22405c9be931524382bc8f9/onboard/gps.h
--------------------------------------------------------------------------------
/onboard/grhott.c:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of AutoQuad.
3 |
4 | AutoQuad is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | AutoQuad is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 | You should have received a copy of the GNU General Public License
14 | along with AutoQuad. If not, see .
15 |
16 | Copyright © 2011-2014 Bill Nesbitt
17 |
18 | Author: Frederic Guichard
19 | */
20 |
21 | #include "radio.h"
22 | #include "grhott.h"
23 | #include "util.h"
24 | #include
25 |
26 | grhottStruct_t grhottData __attribute__((section(".ccm")));
27 |
28 | int grhottDecode(radioInstance_t *r) {
29 | int crc;
30 | int grhott_crc;
31 | int nb_channel;
32 | int num;
33 | int i;
34 |
35 | // How many channels are transmitted?
36 | switch ((grhottData.nb_channel - 2) / 2) {
37 | /*
38 | Now set the CRC based on the detected channels
39 | CRC checksum for 12 channel output (MX20) - XMODEM CRC A801xx
40 | where xx is the number of channels in hex, for 12 enter A8010C in the calculation
41 | */
42 | case 6: // 6 channels (SUMDOF06 in transmitter)
43 | crc = 0x47CA;
44 | break;
45 |
46 | case 8: // 8 channels (SUMDOF08 in transmitter)
47 | crc = 0xA604;
48 | break;
49 |
50 | case 10: // 10 channels (SUMDOF10 in transmitter)
51 | crc = 0x8646;
52 | break;
53 |
54 | case 12: // 12 channels (SUMDOF12 in transmitter)
55 | crc = 0xE680;
56 | break;
57 |
58 | case 14: // 14 channels (SUMDOF14 in transmitter)
59 | crc = 0xC6C2;
60 | break;
61 |
62 | default:
63 | return -1;
64 | }
65 |
66 | // Step through the received frame to calculate the CRC
67 | for (num = 0; num < grhottData.nb_channel - 2; num++) {
68 | // Fetch byte from memory, XOR into CRC top byte
69 | crc = crc ^ (grhottData.rawBuf[num] << 8);
70 |
71 | // Prepare to rotate 8 bits
72 | for (i = 0; i < 8; i++) {
73 | // b15 is set...
74 | if (crc & 0x8000)
75 | crc = (crc << 1) ^ POLYNOM; // rotate and XOR with XMODEM polynomic
76 | // b15 is clear...
77 | else
78 | crc = crc << 1; // just rotate
79 | }
80 | }
81 |
82 | // received CRC is 2 bytes at the end of the data, data frame is number of channels * 2
83 | grhott_crc = (grhottData.rawBuf[grhottData.nb_channel - 2] << 8) + grhottData.rawBuf[grhottData.nb_channel - 1];
84 |
85 | if (crc == grhott_crc) {
86 | nb_channel = (grhottData.nb_channel - 2) / 2;
87 | r->channels[0] = (int16_t) (((grhottData.rawBuf[0] << 8) + grhottData.rawBuf[1] - GRHOTT_MIN) / 5);
88 |
89 | // Prepare to rotate 8 bits
90 | for (i = 1; i < nb_channel; i++)
91 | r->channels[i] = (int16_t) (((grhottData.rawBuf[i * 2] << 8) + grhottData.rawBuf[i * 2 + 1] - GRHOTT_MID) / 5);
92 |
93 | return 1;
94 | }
95 | else {
96 | return -1;
97 | }
98 | }
99 |
100 | int grhottCharIn(radioInstance_t *r, uint8_t c) {
101 | switch (grhottData.state) {
102 | case GRHOTT_WAIT_SYNC1:
103 | if (c == GRHOTT_START_CHAR1) {
104 | grhottData.state = GRHOTT_WAIT_SYNC2;
105 | grhottData.dataCount = 0;
106 | grhottData.nb_channel = 0;
107 | }
108 | break;
109 |
110 | case GRHOTT_WAIT_SYNC2:
111 | if (c == GRHOTT_START_CHAR2) {
112 | grhottData.state = GRHOTT_WAIT_NB_CHANNEL;
113 | }
114 | break;
115 |
116 | case GRHOTT_WAIT_NB_CHANNEL:
117 | grhottData.nb_channel = c * 2 + 2;
118 | grhottData.state = GRHOTT_WAIT_DATA;
119 | grhottData.dataCount = 0;
120 | break;
121 |
122 | case GRHOTT_WAIT_DATA:
123 | grhottData.rawBuf[grhottData.dataCount++] = c;
124 | if (grhottData.dataCount == grhottData.nb_channel) {
125 | grhottData.state = GRHOTT_WAIT_SYNC1;
126 | return grhottDecode(r);
127 | }
128 | break;
129 | }
130 |
131 | return 0;
132 | }
133 |
134 | void grhottInit(radioInstance_t *r, USART_TypeDef *uart) {
135 | memset((void *) &grhottData, 0, sizeof(grhottData));
136 |
137 | r->serialPort = serialOpen(uart, GRHOTT_BAUD, USART_HardwareFlowControl_None, GRHOTT_RXBUF_SIZE, 0);
138 |
139 | grhottData.state = GRHOTT_WAIT_SYNC1;
140 | }
141 |
--------------------------------------------------------------------------------
/onboard/grhott.h:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of AutoQuad.
3 |
4 | AutoQuad is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | AutoQuad is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 | You should have received a copy of the GNU General Public License
14 | along with AutoQuad. If not, see .
15 |
16 | Copyright © 2011-2014 Bill Nesbitt
17 | */
18 |
19 | #ifndef _grhott_h
20 | #define _grhott_h
21 |
22 | #include "radio.h"
23 |
24 | #define GRHOTT_BAUD 115200
25 | #define GRHOTT_RXBUF_SIZE 40
26 |
27 | #define GRHOTT_START_CHAR1 0xa8
28 | #define GRHOTT_START_CHAR2 0x01
29 |
30 | #define GRHOTT_WAIT_SYNC1 0x00
31 | #define GRHOTT_WAIT_SYNC2 0x01
32 | #define GRHOTT_WAIT_NB_CHANNEL 0x02
33 | #define GRHOTT_WAIT_DATA 0x03
34 |
35 | #define GRHOTT_MIN 8000
36 | #define GRHOTT_MID 12000
37 | #define POLYNOM 0x11021
38 |
39 | typedef struct {
40 | uint8_t state;
41 | uint8_t nb_channel;
42 | uint8_t dataCount;
43 | uint8_t rawBuf[32];
44 | } grhottStruct_t;
45 |
46 | extern grhottStruct_t grhottData;
47 |
48 | extern void grhottInit(radioInstance_t *r, USART_TypeDef *uart);
49 | extern int grhottCharIn(radioInstance_t *r, uint8_t c);
50 |
51 | #endif
52 |
--------------------------------------------------------------------------------
/onboard/hmc5983.c:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bn999/autoquad/c94161aeb610c8d4b22405c9be931524382bc8f9/onboard/hmc5983.c
--------------------------------------------------------------------------------
/onboard/hmc5983.h:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of AutoQuad.
3 |
4 | AutoQuad is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | AutoQuad is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 | You should have received a copy of the GNU General Public License
14 | along with AutoQuad. If not, see .
15 |
16 | Copyright © 2011-2014 Bill Nesbitt
17 | */
18 |
19 | #ifndef _hmc5983_h
20 | #define _hmc5983_h
21 |
22 | #include "spi.h"
23 |
24 | #define HMC5983_SPI_BAUD SPI_BaudRatePrescaler_8 // 5.25 Mhz
25 |
26 | #define HMC5983_BYTES (1+6)
27 | #define HMC5983_SLOT_SIZE ((HMC5983_BYTES+sizeof(int)-1) / sizeof(int) * sizeof(int))
28 | #define HMC5983_SLOTS 2 // 37.5Hz bandwidth
29 |
30 | #define HMC5983_RETRIES 5
31 |
32 | #define HMC5983_READ_BIT (0b10000000)
33 | #define HMC5983_READ_MULT_BIT (0b11000000)
34 | #define HMC5983_WRITE_BIT (0b00000000)
35 |
36 | typedef struct {
37 | spiClient_t *spi;
38 | volatile uint32_t spiFlag;
39 | volatile uint8_t rxBuf[HMC5983_SLOT_SIZE*HMC5983_SLOTS];
40 | volatile uint8_t slot;
41 | float rawMag[3];
42 | float mag[3];
43 | float magSign[3];
44 | volatile uint32_t lastUpdate;
45 | uint8_t readCmd;
46 | uint8_t enabled;
47 | uint8_t initialized;
48 | } hmc5983Struct_t;
49 |
50 | extern hmc5983Struct_t hmc5983Data;
51 |
52 | extern void hmc5983PreInit(void);
53 | extern uint8_t hmc5983Init(void);
54 | extern void hmc5983Decode(void);
55 | extern void hmc5983Enable(void);
56 | extern void hmc5983Disable(void);
57 |
58 | #endif
59 |
--------------------------------------------------------------------------------
/onboard/hook.c:
--------------------------------------------------------------------------------
1 | /**
2 | *******************************************************************************
3 | * @file hook.c
4 | * @version V1.1.4
5 | * @date 2011.04.20
6 | * @brief hook management implementation code of CooCox CoOS kernel.
7 | *******************************************************************************
8 | * @copy
9 | *
10 | * INTERNAL FILE,DON'T PUBLIC.
11 | *
12 | * © COPYRIGHT 2009 CooCox
13 | *******************************************************************************
14 | */
15 |
16 |
17 | /*---------------------------- Inlcude --------------------------------------*/
18 | #include
19 |
20 | /**
21 | *******************************************************************************
22 | * @brief IDLE task of OS
23 | * @param[in] pdata The parameter passed to IDLE task.
24 | * @param[out] None
25 | * @retval None
26 | *
27 | * @par Description
28 | * @details This function is system IDLE task code.
29 | *******************************************************************************
30 | */
31 | void CoIdleTask(void* pdata)
32 | {
33 | /* Add your codes here */
34 | for(; ;)
35 | {
36 | /* Add your codes here */
37 | }
38 | }
39 |
40 |
41 | /**
42 | *******************************************************************************
43 | * @brief Hook for stack overflow
44 | * @param[in] taskID Piont to the task which lead to stack overflow.
45 | * @param[out] None
46 | * @retval None
47 | *
48 | * @par Description
49 | * @details This function is a hook for stack overflow.
50 | *******************************************************************************
51 | */
52 | void CoStkOverflowHook(OS_TID taskID)
53 | {
54 | /* Process stack overflow here */
55 | for(; ;)
56 | {
57 |
58 | }
59 | }
60 |
61 |
62 |
63 |
64 |
65 |
66 |
--------------------------------------------------------------------------------
/onboard/imu.c:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bn999/autoquad/c94161aeb610c8d4b22405c9be931524382bc8f9/onboard/imu.c
--------------------------------------------------------------------------------
/onboard/imu.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bn999/autoquad/c94161aeb610c8d4b22405c9be931524382bc8f9/onboard/imu.h
--------------------------------------------------------------------------------
/onboard/incbuild.js:
--------------------------------------------------------------------------------
1 | function incbuild() {
2 | var file = "buildnum.h";
3 | var buildNumText = "#define BUILDNUMBER ";
4 | var s = CWSys.readStringFromFile(file);
5 | var bs = s.split("\n", 2);
6 | var n = eval(bs[0].substring(buildNumText.length)) + 1;
7 |
8 | CWSys.writeStringToFile(file, buildNumText + n + '\n' + bs[1] + '\n');
9 | }
10 |
--------------------------------------------------------------------------------
/onboard/integer.h:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of AutoQuad.
3 |
4 | AutoQuad is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | AutoQuad is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 | You should have received a copy of the GNU General Public License
14 | along with AutoQuad. If not, see .
15 |
16 | Copyright © 2011-2014 Bill Nesbitt
17 | */
18 |
19 | /*-------------------------------------------*/
20 | /* Integer type definitions for FatFs module */
21 | /*-------------------------------------------*/
22 |
23 | #ifndef _INTEGER
24 | #define _INTEGER
25 |
26 | #ifdef _WIN32 /* FatFs development platform */
27 |
28 | #include
29 | #include
30 |
31 | #else /* Embedded platform */
32 |
33 | /* These types must be 16-bit, 32-bit or larger integer */
34 | typedef int INT;
35 | typedef unsigned int UINT;
36 |
37 | /* These types must be 8-bit integer */
38 | typedef char CHAR;
39 | typedef unsigned char UCHAR;
40 | typedef unsigned char BYTE;
41 |
42 | /* These types must be 16-bit integer */
43 | typedef short SHORT;
44 | typedef unsigned short USHORT;
45 | typedef unsigned short WORD;
46 | typedef unsigned short WCHAR;
47 |
48 | /* These types must be 32-bit integer */
49 | typedef long LONG;
50 | typedef unsigned long ULONG;
51 | typedef unsigned long DWORD;
52 |
53 | #endif
54 |
55 | #endif
56 |
--------------------------------------------------------------------------------
/onboard/logger.c:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bn999/autoquad/c94161aeb610c8d4b22405c9be931524382bc8f9/onboard/logger.c
--------------------------------------------------------------------------------
/onboard/logger.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bn999/autoquad/c94161aeb610c8d4b22405c9be931524382bc8f9/onboard/logger.h
--------------------------------------------------------------------------------
/onboard/main_ctl.c:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bn999/autoquad/c94161aeb610c8d4b22405c9be931524382bc8f9/onboard/main_ctl.c
--------------------------------------------------------------------------------
/onboard/matrix.c:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of AutoQuad.
3 |
4 | AutoQuad is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | AutoQuad is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 | You should have received a copy of the GNU General Public License
14 | along with AutoQuad. If not, see .
15 |
16 | Copyright © 2011-2014 Bill Nesbitt
17 | */
18 |
19 | #include "arm_math.h"
20 | #include
21 |
22 | void matrixInit(arm_matrix_instance_f32 *m, int rows, int cols) {
23 | float32_t *d;
24 |
25 | d = (float32_t *)calloc(rows*cols, sizeof(float32_t));
26 |
27 | arm_mat_init_f32(m, rows, cols, d);
28 | }
29 |
30 | void matrixFree(arm_matrix_instance_f32 *m) {
31 | if (m && m->pData)
32 | free(m->pData);
33 | }
34 |
--------------------------------------------------------------------------------
/onboard/max21100.c:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bn999/autoquad/c94161aeb610c8d4b22405c9be931524382bc8f9/onboard/max21100.c
--------------------------------------------------------------------------------
/onboard/max21100.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bn999/autoquad/c94161aeb610c8d4b22405c9be931524382bc8f9/onboard/max21100.h
--------------------------------------------------------------------------------
/onboard/mlinkrx.c:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of AutoQuad.
3 |
4 | AutoQuad is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | AutoQuad is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 | You should have received a copy of the GNU General Public License
14 | along with AutoQuad. If not, see .
15 |
16 | Copyright © 2011-2014 Bill Nesbitt
17 | */
18 |
19 | // mlinkrx module written by Igor van Airde
20 |
21 | #include "aq.h"
22 | #include "radio.h"
23 | #include "mlinkrx.h"
24 | #include "aq_timer.h"
25 | #include "imu.h"
26 | #include "aq_mavlink.h"
27 | #include "util.h"
28 | #include "config.h"
29 | #include
30 | #include
31 |
32 | mlinkrxStruct_t mlinkrxData __attribute__((section(".ccm")));
33 |
34 | // MPX CRC algorithm
35 | uint16_t mpxCRC(uint16_t crc, uint8_t value) {
36 | uint8_t i;
37 |
38 | crc = crc ^ (int16_t)value<<8;
39 |
40 | for (i = 0; i < 8; i++) {
41 | if (crc & 0x8000)
42 | crc = crc << 1^0x1021;
43 | else
44 | crc = crc << 1;
45 | }
46 |
47 | return crc;
48 | }
49 |
50 | // process received chars
51 | unsigned char mlinkrxCharIn(radioInstance_t *r, uint8_t c) {
52 | unsigned long receiveTime = timerMicros();
53 | int i;
54 | int val;
55 |
56 | // top of frame if it's been more than 7.5ms
57 | if (receiveTime - mlinkrxData.lastCharReceived > 7500)
58 | mlinkrxData.count = 0;
59 |
60 | mlinkrxData.lastCharReceived = timerMicros();
61 |
62 | // collect frame data to array
63 | mlinkrxData.framebuf[mlinkrxData.count] = c;
64 | mlinkrxData.count++;
65 |
66 | // if frame seems complete
67 | if (mlinkrxData.count == MLINKRX_FRAMESIZE) {
68 | // get ready to collect new frame data
69 | mlinkrxData.count = 0;
70 | // calculate CRC from frame
71 | mlinkrxData.crc_calc = 0;
72 |
73 | for (i = 0; i < (MLINKRX_FRAMESIZE - 2); i++)
74 | mlinkrxData.crc_calc = mpxCRC(mlinkrxData.crc_calc, mlinkrxData.framebuf[i]);
75 |
76 | // put together received CRC
77 | mlinkrxData.crc_rx = ((uint16_t)mlinkrxData.framebuf[MLINKRX_FRAMESIZE-2] << 8) + (uint16_t)mlinkrxData.framebuf[MLINKRX_FRAMESIZE-1];
78 |
79 | // if CRC matches
80 | if (mlinkrxData.crc_calc == mlinkrxData.crc_rx) {
81 | // decode channels
82 | for (i = 0; i < MLINKRX_CHANNELS; i++) {
83 | // delete upper 4 bytes from MSB, MLINK is 12bit
84 | mlinkrxData.framebuf[2*i+1] &= 0x0F;
85 |
86 | // MLINK is in range 0..4095
87 | // "(MSB+LSB / 2) - 1024" gives range of -1024 to +1023
88 | val = (((uint16_t)mlinkrxData.framebuf[2*i+1] << 8) + (uint16_t)mlinkrxData.framebuf[2*i+2]) >> 1;
89 | if (&RADIO_THROT == &r->channels[i])
90 | r->channels[i] = val - 338; // throttle
91 | else
92 | r->channels[i] = val - 1024; // all other
93 | }
94 | }
95 | else {
96 | return 0; // CRC fail
97 | }
98 | }
99 |
100 | return 1;
101 | }
102 |
103 | void mlinkrxInit(radioInstance_t *r, USART_TypeDef *uart) {
104 | memset((void *)&mlinkrxData, 0, sizeof(mlinkrxData));
105 |
106 | mlinkrxData.count = 0;
107 | r->serialPort = serialOpen(uart, MLINKRX_BAUD, USART_HardwareFlowControl_None, MLINKRX_RXBUF_SIZE, 0);
108 | }
109 |
110 |
--------------------------------------------------------------------------------
/onboard/mlinkrx.h:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of AutoQuad.
3 |
4 | AutoQuad is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | AutoQuad is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 | You should have received a copy of the GNU General Public License
14 | along with AutoQuad. If not, see .
15 |
16 | Copyright © 2011-2014 Bill Nesbitt
17 | */
18 |
19 | // mlinkrx module written by Igor van Airde
20 |
21 | #ifndef _mlinkrx_h
22 | #define _mlinkrx_h
23 |
24 | #define MLINKRX_BAUD 115200
25 | #define MLINKRX_RXBUF_SIZE 64
26 |
27 | #define MLINKRX_FRAMESIZE 27
28 | #define MLINKRX_CHANNELS 12
29 |
30 | typedef struct {
31 | unsigned long lastCharReceived;
32 | int count;
33 | unsigned char framebuf[MLINKRX_FRAMESIZE];
34 | uint16_t crc_rx;
35 | uint16_t crc_calc;
36 | } mlinkrxStruct_t;
37 |
38 | extern void mlinkrxInit(radioInstance_t *r, USART_TypeDef *uart);
39 | extern unsigned char mlinkrxCharIn(radioInstance_t *r, uint8_t c);
40 |
41 | extern mlinkrxStruct_t mlinkrxData;
42 |
43 | #endif
44 |
--------------------------------------------------------------------------------
/onboard/motors.c:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bn999/autoquad/c94161aeb610c8d4b22405c9be931524382bc8f9/onboard/motors.c
--------------------------------------------------------------------------------
/onboard/motors.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bn999/autoquad/c94161aeb610c8d4b22405c9be931524382bc8f9/onboard/motors.h
--------------------------------------------------------------------------------
/onboard/mpu6000.c:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bn999/autoquad/c94161aeb610c8d4b22405c9be931524382bc8f9/onboard/mpu6000.c
--------------------------------------------------------------------------------
/onboard/mpu6000.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bn999/autoquad/c94161aeb610c8d4b22405c9be931524382bc8f9/onboard/mpu6000.h
--------------------------------------------------------------------------------
/onboard/ms5611.c:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bn999/autoquad/c94161aeb610c8d4b22405c9be931524382bc8f9/onboard/ms5611.c
--------------------------------------------------------------------------------
/onboard/ms5611.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bn999/autoquad/c94161aeb610c8d4b22405c9be931524382bc8f9/onboard/ms5611.h
--------------------------------------------------------------------------------
/onboard/nav_ukf.c:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bn999/autoquad/c94161aeb610c8d4b22405c9be931524382bc8f9/onboard/nav_ukf.c
--------------------------------------------------------------------------------
/onboard/nav_ukf.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bn999/autoquad/c94161aeb610c8d4b22405c9be931524382bc8f9/onboard/nav_ukf.h
--------------------------------------------------------------------------------
/onboard/pid.h:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of AutoQuad.
3 |
4 | AutoQuad is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | AutoQuad is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 | You should have received a copy of the GNU General Public License
14 | along with AutoQuad. If not, see .
15 |
16 | Copyright © 2011-2014 Bill Nesbitt
17 | */
18 |
19 | #ifndef pid_h
20 | #define pid_h
21 |
22 | #include "aq.h"
23 |
24 | typedef struct {
25 | float setPoint; // Last setpoint
26 | float dState; // Last position input
27 | float iState; // Integrator state
28 | float *iGain; // integral gain
29 | float *pGain; // proportional gain
30 | float *dGain; // derivative gain
31 | float *fGain; // low pass filter factor (1 - pole) for derivative gain
32 | float *pMax, *iMax, *dMax, *oMax;
33 | int16_t *pTrim, *iTrim, *dTrim, *fTrim; // pointers to radio trim channels (or NULL)
34 | float pv_1, pv_2;
35 | float co_1;
36 | float pTerm_1;
37 | float iTerm_1;
38 | float dTerm_1;
39 | float sp_1;
40 | } pidStruct_t;
41 |
42 | extern pidStruct_t *pidInit(float *p, float *i, float *d, float *f, float *pMax, float *iMax, float *dMax, float *oMax, int16_t *pTrim, int16_t *iTrim, int16_t *dTrim, int16_t *fTrim);
43 | extern float pidUpdate(pidStruct_t *pid, float setpoint, float position);
44 | extern float pidUpdateTest(pidStruct_t *pid, float setpoint, float position);
45 | extern float pidUpdate2(pidStruct_t *pid, float setpoint, float position);
46 | //extern float pidUpdateB(pidStruct_t *pid, float setpoint, float position);
47 | //extern float pidUpdateC(pidStruct_t *pid, float setpoint, float position);
48 | //extern float pidUpdate3(pidStruct_t *pid, float setpoint, float position);
49 | extern void pidStartDump(void);
50 | extern void pidStopDump(void);
51 | extern void pidDump(pidStruct_t *pid);
52 | extern void pidZeroIntegral(pidStruct_t *pid, float pv, float iState);
53 |
54 | #endif
55 |
--------------------------------------------------------------------------------
/onboard/ppm.h:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | This file is part of AutoQuad.
4 |
5 | AutoQuad is free software: you can redistribute it and/or modify
6 | it under the terms of the GNU General Public License as published by
7 | the Free Software Foundation, either version 3 of the License, or
8 | (at your option) any later version.
9 |
10 | AutoQuad is distributed in the hope that it will be useful,
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | GNU General Public License for more details.
14 | You should have received a copy of the GNU General Public License
15 | along with AutoQuad. If not, see .
16 |
17 | Copyright © 2011-2014 Bill Nesbitt
18 | */
19 |
20 | /*
21 | PPM module written by TC
22 | Heavily modified by Menno de Gans & Maxim Paperno
23 | */
24 |
25 | #ifndef _ppm_h
26 | #define _ppm_h
27 |
28 | #include "pwm.h"
29 | #include "radio.h"
30 |
31 | #define PPM_MAX_CHANNELS 12 // can't be > RADIO_MAX_CHANNELS
32 | #define PPM_GUARD_PULSE_LENGTH 2700
33 | #define PPM_MIN_PULSE_WIDTH 750
34 | #define PPM_MAX_PULSE_WIDTH 2250
35 | #define PPM_STAB_CHANNEL_FRAMES 20 // number of consecutive frames with the same number of channels after which we assume that number of channels is stable ;)
36 | #define PPM_CAPTURE_EDGE 1 // "polarity" value for passing to pwmInitIn(); -1 for falling edge, 1 for rising edge
37 |
38 | #define PPM_THROT_MIN -338 // final value constraints
39 | #define PPM_THROT_MAX 1709
40 | #define PPM_CHAN_MIN -1024
41 | #define PPM_CHAN_MAX 1023
42 |
43 | typedef struct {
44 | radioInstance_t *r;
45 | pwmPortStruct_t *ppmPort;
46 | volatile uint8_t frameParsed;
47 |
48 | uint32_t lastCaptureValue;
49 | uint8_t lastChannel; // index into channels[]
50 | uint8_t previousChannels; // number of channels seen in previous frame;
51 | // used to autodetermine number of channels
52 | uint8_t numberChannels; // autodetermined number of channels or 0
53 | uint8_t stableChannelsCount; // number of frames with the same number of channels
54 | int8_t signalQuality; // -1 critical error (lost frame)
55 | // 0 non-critical error (invalid pulse)
56 | // 1 normal operation (frame parsed OK)
57 | uint8_t inputValid; // 1 valid
58 | // 0 current frame is invalid
59 |
60 | int16_t channels[PPM_MAX_CHANNELS]; // channel values are stored here after successful capture of the whole frame
61 | int16_t tmp_channels[PPM_MAX_CHANNELS]; // temporary channel values while capturing the frame
62 |
63 | } ppmStruct_t;
64 |
65 | extern void ppmInit(radioInstance_t *r);
66 | extern int ppmDataAvailable(radioInstance_t *r);
67 | extern int8_t ppmGetSignalQuality(radioInstance_t *r);
68 |
69 | #endif
70 |
--------------------------------------------------------------------------------
/onboard/pwm.c:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bn999/autoquad/c94161aeb610c8d4b22405c9be931524382bc8f9/onboard/pwm.c
--------------------------------------------------------------------------------
/onboard/pwm.h:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of AutoQuad.
3 |
4 | AutoQuad is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | AutoQuad is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 | You should have received a copy of the GNU General Public License
14 | along with AutoQuad. If not, see .
15 |
16 | Copyright © 2011-2014 Bill Nesbitt
17 | */
18 |
19 | #ifndef _pwm_h
20 | #define _pwm_h
21 |
22 | #include "aq.h"
23 |
24 | #define pwmDigitalHi(p) { p->port->BSRRL = p->pin; }
25 | #define pwmDigitalLo(p) { p->port->BSRRH = p->pin; }
26 | #define pwmDigitalGet(p) ((p->port->ODR & p->pin) != 0)
27 |
28 | enum pwmDirections {
29 | PWM_OUTPUT = 1,
30 | PWM_INPUT
31 | };
32 |
33 | typedef void pwmCallback_t(uint32_t, uint8_t);
34 |
35 | typedef struct {
36 | volatile uint32_t *ccr;
37 | volatile uint32_t *cnt;
38 | pwmCallback_t *callback;
39 | uint32_t period;
40 | int8_t direction;
41 | GPIO_TypeDef* port;
42 | uint16_t pin;
43 | } pwmPortStruct_t;
44 |
45 | extern pwmPortStruct_t *pwmInitOut(uint8_t pwmPort, uint32_t resolution, uint32_t freq, uint32_t inititalValue, int8_t ESC32Mode);
46 | extern pwmPortStruct_t *pwmInitDigitalOut(uint8_t pwmPort);
47 | extern pwmPortStruct_t *pwmInitIn(uint8_t pwmPort, int16_t polarity, uint32_t period, pwmCallback_t callback);
48 | extern uint16_t pwmCheckTimer(uint8_t pwmPort);
49 | extern void pwmZeroTimers(void);
50 | extern void pwmDigitalToggle(pwmPortStruct_t *p);
51 |
52 | #endif
53 |
--------------------------------------------------------------------------------
/onboard/quatos.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bn999/autoquad/c94161aeb610c8d4b22405c9be931524382bc8f9/onboard/quatos.h
--------------------------------------------------------------------------------
/onboard/radio.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bn999/autoquad/c94161aeb610c8d4b22405c9be931524382bc8f9/onboard/radio.h
--------------------------------------------------------------------------------
/onboard/rcc.c:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bn999/autoquad/c94161aeb610c8d4b22405c9be931524382bc8f9/onboard/rcc.c
--------------------------------------------------------------------------------
/onboard/rcc.h:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of AutoQuad.
3 |
4 | AutoQuad is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | AutoQuad is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 | You should have received a copy of the GNU General Public License
14 | along with AutoQuad. If not, see .
15 |
16 | Copyright © 2011-2014 Bill Nesbitt
17 | */
18 |
19 | #ifndef _rcc_h
20 | #define _rcc_h
21 |
22 | #define RTC_MASK_YEAR (0b1111111<<25)
23 | #define RTC_MASK_MONTH (0b1111<<21)
24 | #define RTC_MASK_DAY (0b11111<<16)
25 | #define RTC_MASK_HOUR (0b11111<<11)
26 | #define RTC_MASK_MINUTE (0b111111<<5)
27 | #define RTC_MASK_SECOND (0b11111)
28 |
29 | extern RCC_ClocksTypeDef rccClocks;
30 |
31 | extern void rccConfiguration(void);
32 |
33 | #endif
34 |
--------------------------------------------------------------------------------
/onboard/rotations.c:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of AutoQuad.
3 |
4 | AutoQuad is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | AutoQuad is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 | You should have received a copy of the GNU General Public License
14 | along with AutoQuad. If not, see .
15 |
16 | Copyright © 2011-2014 Bill Nesbitt
17 | */
18 |
19 | #include "aq.h"
20 | #include "aq_math.h"
21 |
22 | void quatMultiply(float32_t *qr, float32_t *q1, float32_t *q2) {
23 | qr[0] = q2[0]*q1[0] - q2[1]*q1[1] - q2[2]*q1[2] - q2[3]*q1[3];
24 | qr[1] = q2[0]*q1[1] + q2[1]*q1[0] - q2[2]*q1[3] + q2[3]*q1[2];
25 | qr[2] = q2[0]*q1[2] + q2[1]*q1[3] + q2[2]*q1[0] - q2[3]*q1[1];
26 | qr[3] = q2[0]*q1[3] - q2[1]*q1[2] + q2[2]*q1[1] + q2[3]*q1[0];
27 | }
28 |
29 | void eulerToQuatYPR(float32_t *q, float32_t yaw, float32_t pitch, float32_t roll) {
30 | float32_t cy, cp, cr;
31 | float32_t sy, sp, sr;
32 |
33 | yaw *= DEG_TO_RAD * 0.5f;
34 | pitch *= DEG_TO_RAD * 0.5f;
35 | roll *= DEG_TO_RAD * 0.5f;
36 |
37 | cy = cosf(yaw);
38 | cp = cosf(pitch);
39 | cr = cosf(roll);
40 |
41 | sy = sinf(yaw);
42 | sp = sinf(pitch);
43 | sr = sinf(roll);
44 |
45 | q[0] = cy*cp*cr + sy*sp*sr;
46 | q[1] = cy*cp*sr - sy*sp*cr;
47 | q[2] = cy*sp*cr + sy*cp*sr;
48 | q[3] = sy*cp*cr - cy*sp*sr;
49 | }
50 |
51 | void eulerToQuatRPY(float32_t *q, float32_t roll, float32_t pitch, float32_t yaw) {
52 | float32_t cy, cp, cr;
53 | float32_t sy, sp, sr;
54 |
55 | yaw *= DEG_TO_RAD * 0.5f;
56 | pitch *= DEG_TO_RAD * 0.5f;
57 | roll *= DEG_TO_RAD * 0.5f;
58 |
59 | cy = cosf(yaw);
60 | cp = cosf(pitch);
61 | cr = cosf(roll);
62 |
63 | sy = sinf(yaw);
64 | sp = sinf(pitch);
65 | sr = sinf(roll);
66 |
67 | q[0] = cr*cp*cy - sr*sp*sy;
68 | q[1] = cr*sp*sy + sr*cp*cy;
69 | q[2] = cr*sp*cy - sr*cp*sy;
70 | q[3] = cr*cp*sy + sr*sp*cy;
71 | }
72 |
73 | void nlerp(float32_t *r, float32_t *a, float32_t *b, float32_t t) {
74 | float32_t dp;
75 | float32_t f1, f2;
76 |
77 | f1 = 1.0f - t;
78 | f2 = t;
79 |
80 | dp = (a[0]*b[0] + a[1]*b[1] + a[2]*b[2] + a[3]*b[3]);
81 |
82 | // rotate the shorter distance
83 | if (dp >= 0.0f) {
84 | r[0] = a[0]*f1 + b[0]*f2;
85 | r[1] = a[1]*f1 + b[1]*f2;
86 | r[2] = a[2]*f1 + b[2]*f2;
87 | r[3] = a[3]*f1 + b[3]*f2;
88 | }
89 | else {
90 | r[0] = a[0]*f1 - b[0]*f2;
91 | r[1] = a[1]*f1 - b[1]*f2;
92 | r[2] = a[2]*f1 - b[2]*f2;
93 | r[3] = a[3]*f1 - b[3]*f2;
94 | }
95 |
96 | vectorNormalize(r, 4);
97 | }
98 |
99 | void quatFilterReset(quatFilter_t *f, float32_t *q) {
100 | f->qz1[0] = q[0];
101 | f->qz1[1] = q[1];
102 | f->qz1[2] = q[2];
103 | f->qz1[3] = q[3];
104 | }
105 |
106 | void quatFilterReset3(quatFilter_t *f, float32_t *q) {
107 | quatFilterReset(&f[0], q);
108 | quatFilterReset(&f[1], q);
109 | quatFilterReset(&f[2], q);
110 | }
111 |
112 | void quatFilterInit(quatFilter_t *f, float32_t dt, float32_t tau, float32_t *q) {
113 | f->tc = dt / tau;
114 | quatFilterReset(f, q);
115 | }
116 |
117 | void quatFilterInit3(quatFilter_t *f, float32_t dt, float32_t tau, float32_t *q) {
118 | quatFilterInit(&f[0], dt, tau, q);
119 | quatFilterInit(&f[1], dt, tau, q);
120 | quatFilterInit(&f[2], dt, tau, q);
121 | }
122 |
123 | float32_t *quatFilter(quatFilter_t *f, float32_t *b) {
124 | nlerp(f->qz1, f->qz1, b, f->tc);
125 |
126 | return f->qz1;
127 | }
128 |
129 | float32_t *quatFilter3(quatFilter_t *f, float32_t *b) {
130 | return quatFilter(&f[2], quatFilter(&f[1], quatFilter(&f[0], b)));
131 | }
132 |
--------------------------------------------------------------------------------
/onboard/rtc.h:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of AutoQuad.
3 |
4 | AutoQuad is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | AutoQuad is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 | You should have received a copy of the GNU General Public License
14 | along with AutoQuad. If not, see .
15 |
16 | Copyright © 2011-2014 Bill Nesbitt
17 | */
18 |
19 | #ifndef _rtc_h
20 | #define _rtc_h
21 |
22 | #ifndef RTC_INIT_MASK
23 | #define RTC_INIT_MASK ((uint32_t)0xFFFFFFFF)
24 | #endif
25 |
26 | #ifndef RTC_TR_RESERVED_MASK
27 | #define RTC_TR_RESERVED_MASK ((uint32_t)0x007F7F7F)
28 | #endif
29 | #ifndef RTC_DR_RESERVED_MASK
30 | #define RTC_DR_RESERVED_MASK ((uint32_t)0x00FFFF3F)
31 | #endif
32 |
33 | typedef struct {
34 | unsigned long lsiFrequency;
35 | uint32_t asyncPrediv, syncPrediv;
36 | volatile unsigned long captureLSI[2];
37 | volatile int captureNumber;
38 | } rtcStruct_t;
39 |
40 | extern rtcStruct_t rtcData;
41 |
42 | extern void rtcInit(void);
43 | extern unsigned long rtcGetDateTime(void);
44 | extern int rtcSetDataTime(int year, int month, int day, int hour, int minute, int second);
45 | extern void rtcSetDateTimeLong(unsigned long dateTime);
46 |
47 | #endif
48 |
--------------------------------------------------------------------------------
/onboard/run.c:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bn999/autoquad/c94161aeb610c8d4b22405c9be931524382bc8f9/onboard/run.c
--------------------------------------------------------------------------------
/onboard/run.h:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of AutoQuad.
3 |
4 | AutoQuad is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | AutoQuad is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 | You should have received a copy of the GNU General Public License
14 | along with AutoQuad. If not, see .
15 |
16 | Copyright © 2011-2014 Bill Nesbitt
17 | */
18 |
19 | #ifndef _run_h
20 | #define _run_h
21 |
22 | #include
23 |
24 | #define RUN_TASK_SIZE 250
25 | #define RUN_PRIORITY 30
26 |
27 | #define RUN_SENSOR_HIST 10 // number of timesteps to average observation sensors' data
28 |
29 | #define ALTITUDE (*runData.altPos)
30 | #define VELOCITYD (*runData.altVel)
31 |
32 | typedef struct {
33 | OS_TID runTask;
34 | OS_FlagID runFlag;
35 |
36 | float bestHacc;
37 | float accMask;
38 | float accHist[3][RUN_SENSOR_HIST];
39 | float magHist[3][RUN_SENSOR_HIST];
40 | float presHist[RUN_SENSOR_HIST];
41 | float sumAcc[3];
42 | float sumMag[3];
43 | float sumPres;
44 | int sensorHistIndex;
45 | float *altPos;
46 | float *altVel;
47 | } runStruct_t;
48 |
49 | extern runStruct_t runData;
50 |
51 | extern void runInit(void);
52 |
53 | #endif
54 |
--------------------------------------------------------------------------------
/onboard/sdio.c:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bn999/autoquad/c94161aeb610c8d4b22405c9be931524382bc8f9/onboard/sdio.c
--------------------------------------------------------------------------------
/onboard/serial.h:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of AutoQuad.
3 |
4 | AutoQuad is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | AutoQuad is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 | You should have received a copy of the GNU General Public License
14 | along with AutoQuad. If not, see .
15 |
16 | Copyright © 2011-2014 Bill Nesbitt
17 | */
18 |
19 | #ifndef _serial_h
20 | #define _serial_h
21 |
22 | #include "stm32f4xx.h"
23 | #include
24 |
25 | #define SERIAL_DEFAULT_RX_BUFSIZE 128
26 |
27 | typedef void serialTxDMACallback_t(void *s);
28 |
29 | typedef struct {
30 | unsigned int baudRate;
31 | uint16_t flowControl;
32 | uint16_t parity;
33 | uint16_t stopBits;
34 |
35 | unsigned int txBufSize;
36 | volatile unsigned char *txBuf;
37 | volatile unsigned int txHead, txTail;
38 |
39 | unsigned int rxBufSize;
40 | volatile unsigned char *rxBuf;
41 | volatile unsigned int rxHead, rxTail;
42 | volatile unsigned int rxPos;
43 |
44 | USART_TypeDef *USARTx;
45 | DMA_Stream_TypeDef *rxDMAStream;
46 | DMA_Stream_TypeDef *txDMAStream;
47 | uint32_t rxDMAChannel;
48 | uint32_t txDMAChannel;
49 | uint32_t rxDmaFlags, txDmaFlags;
50 | volatile unsigned char txDmaRunning;
51 | serialTxDMACallback_t *txDMACallback;
52 | void *txDMACallbackParam;
53 |
54 | OS_FlagID waitFlag;
55 | } serialPort_t;
56 |
57 | extern serialPort_t *serialOpen(USART_TypeDef *USARTx, unsigned int baud, uint16_t flowControl, unsigned int rxBufSize, unsigned int txBufSize);
58 | extern void serialChangeBaud(serialPort_t *s, unsigned int baud);
59 | extern void serialChangeParity(serialPort_t *s, uint16_t parity);
60 | extern void serialChangeStopBits(serialPort_t *s, uint16_t stopBits);
61 | extern void serialSetSTDIO(serialPort_t *s);
62 | extern void serialWrite(serialPort_t *s, unsigned char ch);
63 | extern void serialWatch(void);
64 | extern unsigned char serialAvailable(serialPort_t *s);
65 | extern int serialRead(serialPort_t *s);
66 | extern int serialReadBlock(serialPort_t *s);
67 | extern void serialPrint(serialPort_t *s, const char *str);
68 | extern int _serialStartTxDMA(serialPort_t *s, void *buf, int size, serialTxDMACallback_t *txDMACallback, void *txDMACallbackParam);
69 | extern int __putchar(int ch);
70 | extern int __getchar(void);
71 |
72 | extern serialPort_t *serialSTDIO;
73 |
74 | #endif
75 |
--------------------------------------------------------------------------------
/onboard/signaling.h:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of AutoQuad.
3 |
4 | AutoQuad is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | AutoQuad is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 | You should have received a copy of the GNU General Public License
14 | along with AutoQuad. If not, see .
15 |
16 | Copyright © 2011-2014 Bill Nesbitt
17 | */
18 |
19 | #ifndef _signaling_h
20 | #define _signaling_h
21 |
22 | #include "pwm.h"
23 |
24 | #define SIG_SPEAKER_FREQ 2000 // frequency for piezo speaker in Hz
25 | #define SIG_SPEAKER_PULSE_LEN (500 / (SIG_SPEAKER_FREQ / 1000)) // pwm pulse length to achieve ~50% duty cycle. reference: 1000hz = 500 usec/cycle, 2000hz = 250 usec/cycle
26 |
27 | enum signalingEventTypes {
28 | SIG_EVENT_NONE = 0,
29 | // ongoing events
30 | SIG_EVENT_DISARMED_NOGPS,
31 | SIG_EVENT_DISARMED_GPS,
32 | SIG_EVENT_ARMED,
33 | SIG_EVENT_FLYING,
34 | SIG_EVENT_FLYING_HF,
35 | SIG_EVENT_ALTHOLD,
36 | SIG_EVENT_POSHOLD,
37 | SIG_EVENT_MISSION,
38 | SIG_EVENT_DVH,
39 | SIG_EVENT_LOWBATT,
40 | SIG_EVENT_RADIOLOSS,
41 | SIG_EVENT_RADIOLOSS2,
42 | // one-time events
43 | SIG_EVENT_OT_ARMING,
44 | SIG_EVENT_OT_DISARMING,
45 | SIG_EVENT_OT_HF_SET,
46 | SIG_EVENT_ENUM_END
47 | };
48 |
49 | typedef struct {
50 | pwmPortStruct_t *beeperPort;
51 | pwmPortStruct_t *ledPort1;
52 | pwmPortStruct_t *ledPort2;
53 | pwmPortStruct_t *pwmPort;
54 | uint8_t enabled; // flag indicating if any signaling is used (any ports are enabled)
55 | uint8_t patPos; // loop counter used in Led patterns
56 | uint8_t patLen; // number of positions in pattern per output device; 10 = 1Hz. Changing it will! affect the led pattern event
57 | uint8_t oneTimeEvtTyp; // if set, a one-time event is signaled, overriding any other current events
58 | uint8_t oneTimeEvtStat; // current one-time event stage: 0=not active; 1=event is done; 2=event is in progress
59 | uint8_t beeperType; // 0 = buzzer, 1 = speaker
60 | } sigStruct_t;
61 |
62 | extern sigStruct_t sigData;
63 |
64 | extern void signalingInit(void);
65 | extern void signalingEvent(void);
66 | extern void signalingOnetimeEvent(int eventTyp);
67 |
68 | #endif
69 |
--------------------------------------------------------------------------------
/onboard/spektrum.h:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of AutoQuad.
3 |
4 | AutoQuad is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | AutoQuad is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 | You should have received a copy of the GNU General Public License
14 | along with AutoQuad. If not, see .
15 |
16 | Copyright © 2011-2014 Bill Nesbitt
17 | */
18 |
19 | #ifndef _spektrum_h
20 | #define _spektrum_h
21 |
22 | #include "radio.h"
23 |
24 | #define SPEKTRUM_BAUD 115200
25 | #define SPEKTRUM_RXBUF_SIZE 64
26 |
27 | typedef struct {
28 | uint32_t lastCharReceived;
29 | uint8_t rawBuf[16];
30 | uint8_t state;
31 | } spektrumStruct_t;
32 |
33 | extern void spektrumInit(radioInstance_t *r, USART_TypeDef *uart);
34 | extern uint8_t spektrumCharIn(radioInstance_t *r, int c);
35 |
36 | extern spektrumStruct_t spektrumData;
37 |
38 | #endif
39 |
--------------------------------------------------------------------------------
/onboard/spi.c:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bn999/autoquad/c94161aeb610c8d4b22405c9be931524382bc8f9/onboard/spi.c
--------------------------------------------------------------------------------
/onboard/spi.h:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of AutoQuad.
3 |
4 | AutoQuad is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | AutoQuad is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 | You should have received a copy of the GNU General Public License
14 | along with AutoQuad. If not, see .
15 |
16 | Copyright © 2011-2014 Bill Nesbitt
17 | */
18 |
19 | #ifndef _spi_h
20 | #define _spi_h
21 |
22 | #include "digital.h"
23 |
24 | #define SPI_BAUD_MASK (~((int16_t)0b111<<3))
25 |
26 | #define SPI_SLOTS 5
27 | #define SPI_MAX_TXN_TIME 30 // us
28 |
29 | typedef void spiCallback_t(int);
30 |
31 | typedef struct {
32 | digitalPin *cs;
33 | uint16_t baud;
34 | spiCallback_t *callback;
35 | volatile uint32_t *flag;
36 | uint8_t interface;
37 | } spiClient_t;
38 |
39 | typedef struct {
40 | uint16_t size;
41 | uint32_t rxBuf;
42 | uint32_t txBuf;
43 | spiClient_t *client;
44 | } spiSlot_t;
45 |
46 | typedef struct {
47 | SPI_TypeDef *spi;
48 | uint32_t intRxFlags;
49 | uint32_t intTxFlags;
50 | DMA_Stream_TypeDef *rxDMAStream;
51 | DMA_Stream_TypeDef *txDMAStream;
52 | spiSlot_t slots[SPI_SLOTS];
53 | volatile uint8_t head, tail;
54 | volatile uint8_t txRunning;
55 | uint32_t txnStart;
56 | uint32_t txnTimeouts;
57 | uint32_t txnMaxTime;
58 | uint8_t initialized;
59 | } spiStruct_t;
60 |
61 | extern spiStruct_t spiData[];
62 |
63 | extern uint8_t spiWriteByte(spiClient_t *spi, uint8_t val);
64 | extern spiClient_t *spiClientInit(SPI_TypeDef *spi, uint16_t baud, uint8_t invert, GPIO_TypeDef *csPort, uint16_t csPin, volatile uint32_t *flag, spiCallback_t *callback);
65 | extern void spiChangeBaud(spiClient_t *spi, uint16_t baud);
66 | extern void spiChangeCallback(spiClient_t *client, spiCallback_t *callback);
67 | extern void spiTransaction(spiClient_t *client, volatile void *rxBuf, void *txBuf, uint16_t size);
68 | extern void spiClientFree(spiClient_t *spi);
69 |
70 | #endif
71 |
--------------------------------------------------------------------------------
/onboard/srcdkf.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bn999/autoquad/c94161aeb610c8d4b22405c9be931524382bc8f9/onboard/srcdkf.h
--------------------------------------------------------------------------------
/onboard/stm32f4xx_conf.h:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file Project/STM32F4xx_StdPeriph_Templates/stm32f4xx_conf.h
4 | * @author MCD Application Team
5 | * @version V1.0.0
6 | * @date 30-September-2011
7 | * @brief Library configuration file.
8 | ******************************************************************************
9 | * @attention
10 | *
11 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
12 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
13 | * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
14 | * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
15 | * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
16 | * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
17 | *
18 | * © COPYRIGHT 2011 STMicroelectronics
19 | ******************************************************************************
20 | */
21 |
22 | /* Define to prevent recursive inclusion -------------------------------------*/
23 | #ifndef __STM32F4xx_CONF_H
24 | #define __STM32F4xx_CONF_H
25 |
26 | /* Includes ------------------------------------------------------------------*/
27 | /* Uncomment the line below to enable peripheral header file inclusion */
28 | #include "stm32f4xx_adc.h"
29 | #include "stm32f4xx_can.h"
30 | //#include "stm32f4xx_crc.h"
31 | //#include "stm32f4xx_cryp.h"
32 | //#include "stm32f4xx_dac.h"
33 | #include "stm32f4xx_dbgmcu.h"
34 | //#include "stm32f4xx_dcmi.h"
35 | #include "stm32f4xx_dma.h"
36 | #include "stm32f4xx_exti.h"
37 | #include "stm32f4xx_flash.h"
38 | //#include "stm32f4xx_fsmc.h"
39 | //#include "stm32f4xx_hash.h"
40 | #include "stm32f4xx_gpio.h"
41 | //#include "stm32f4xx_i2c.h"
42 | //#include "stm32f4xx_iwdg.h"
43 | #include "stm32f4xx_pwr.h"
44 | #include "stm32f4xx_rcc.h"
45 | //#include "stm32f4xx_rng.h"
46 | #include "stm32f4xx_rtc.h"
47 | #include "stm32f4xx_sdio.h"
48 | #include "stm32f4xx_spi.h"
49 | #include "stm32f4xx_syscfg.h"
50 | #include "stm32f4xx_tim.h"
51 | #include "stm32f4xx_usart.h"
52 | //#include "stm32f4xx_wwdg.h"
53 | #include "misc.h" /* High level functions for NVIC and SysTick (add-on to CMSIS functions) */
54 |
55 | /* Exported types ------------------------------------------------------------*/
56 | /* Exported constants --------------------------------------------------------*/
57 |
58 | /* If an external clock source is used, then the value of the following define
59 | should be set to the value of the external clock source, else, if no external
60 | clock is used, keep this define commented */
61 | /*#define I2S_EXTERNAL_CLOCK_VAL 12288000 */ /* Value of the external clock in Hz */
62 |
63 |
64 | /* Uncomment the line below to expanse the "assert_param" macro in the
65 | Standard Peripheral Library drivers code */
66 | /* #define USE_FULL_ASSERT 1 */
67 |
68 | /* Exported macro ------------------------------------------------------------*/
69 | #ifdef USE_FULL_ASSERT
70 |
71 | /**
72 | * @brief The assert_param macro is used for function's parameters check.
73 | * @param expr: If expr is false, it calls assert_failed function
74 | * which reports the name of the source file and the source
75 | * line number of the call that failed.
76 | * If expr is true, it returns no value.
77 | * @retval None
78 | */
79 | #define assert_param(expr) ((expr) ? (void)0 : assert_failed((uint8_t *)__FILE__, __LINE__))
80 | /* Exported functions ------------------------------------------------------- */
81 | void assert_failed(uint8_t* file, uint32_t line);
82 | #else
83 | #define assert_param(expr) ((void)0)
84 | #endif /* USE_FULL_ASSERT */
85 |
86 | #endif /* __STM32F4xx_CONF_H */
87 |
88 | /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
89 |
--------------------------------------------------------------------------------
/onboard/supervisor.c:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bn999/autoquad/c94161aeb610c8d4b22405c9be931524382bc8f9/onboard/supervisor.c
--------------------------------------------------------------------------------
/onboard/supervisor.h:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of AutoQuad.
3 |
4 | AutoQuad is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | AutoQuad is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 | You should have received a copy of the GNU General Public License
14 | along with AutoQuad. If not, see .
15 |
16 | Copyright © 2011-2014 Bill Nesbitt
17 | */
18 |
19 | #ifndef _supervisor_h
20 | #define _supervisor_h
21 |
22 | #include
23 | #include "digital.h"
24 |
25 | #define SUPERVISOR_STACK_SIZE 225
26 | #define SUPERVISOR_PRIORITY 34
27 |
28 | #define SUPERVISOR_RATE 20 // Hz
29 | #define SUPERVISOR_DISARM_TIME (1e6*2) // 2 seconds
30 | #define SUPERVISOR_RADIO_LOSS1 ((int)1e6) // 1 second
31 | #define SUPERVISOR_RADIO_LOSS2 ((int)15e6) // 15 seconds
32 |
33 | // Radio loss stage 2 failsafe settings:
34 | #define SUPERVISOR_HOME_POS_DETECT_RADIUS 2.0f // start descending when within this radius of home position in meters
35 | #define SUPERVISOR_HOME_ALT_DETECT_MARGIN 2.0f // start moving to home lat/lon when within this altitude of home position in meters
36 |
37 | #define SUPERVISOR_SOC_TABLE_SIZE 100
38 |
39 | enum supervisorStates {
40 | STATE_INITIALIZING = 0x00,
41 | STATE_CALIBRATION = 0x01,
42 | STATE_DISARMED = 0x02,
43 | STATE_ARMED = 0x04,
44 | STATE_FLYING = 0x08,
45 | STATE_RADIO_LOSS1 = 0x10,
46 | STATE_RADIO_LOSS2 = 0x20,
47 | STATE_LOW_BATTERY1 = 0x40,
48 | STATE_LOW_BATTERY2 = 0x80
49 | };
50 |
51 | enum supervisorFailsafeStg2Options {
52 | SPVR_OPT_FS_RAD_ST2_LAND = 0,
53 | SPVR_OPT_FS_RAD_ST2_RTH,
54 | SPVR_OPT_FS_RAD_ST2_ASCEND
55 | };
56 |
57 | typedef struct {
58 | OS_TID supervisorTask;
59 |
60 | digitalPin *readyLed;
61 | digitalPin *debugLed;
62 | digitalPin *gpsLed;
63 |
64 | float socTable[SUPERVISOR_SOC_TABLE_SIZE+1];
65 | float soc;
66 | float flightTime; // seconds
67 | float flightSecondsAvg; // avg flight time seconds for every percentage of SOC
68 | float flightTimeRemaining; // seconds
69 | uint32_t armTime;
70 | uint32_t lastGoodRadioMicros;
71 | float vInLPF;
72 | uint8_t state;
73 | uint8_t diskWait;
74 | uint8_t configRead;
75 | } supervisorStruct_t;
76 |
77 | extern supervisorStruct_t supervisorData;
78 |
79 | extern void supervisorInit(void);
80 | extern void supervisorInitComplete(void);
81 | extern void supervisorDiskWait(uint8_t waiting);
82 | extern void supervisorThrottleUp(uint8_t throttle);
83 | extern void supervisorSendDataStart(void);
84 | extern void supervisorSendDataStop(void);
85 | extern void supervisorConfigRead(void);
86 | extern void supervisorArm(void);
87 | extern void supervisorDisarm(void);
88 | extern void supervisorCalibrate(void);
89 | extern void supervisorTare(void);
90 |
91 | #endif
92 |
--------------------------------------------------------------------------------
/onboard/telemetry.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bn999/autoquad/c94161aeb610c8d4b22405c9be931524382bc8f9/onboard/telemetry.h
--------------------------------------------------------------------------------
/onboard/ublox.c:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bn999/autoquad/c94161aeb610c8d4b22405c9be931524382bc8f9/onboard/ublox.c
--------------------------------------------------------------------------------
/onboard/ublox.h:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bn999/autoquad/c94161aeb610c8d4b22405c9be931524382bc8f9/onboard/ublox.h
--------------------------------------------------------------------------------
/onboard/usb.h:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of AutoQuad.
3 |
4 | AutoQuad is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | AutoQuad is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 | You should have received a copy of the GNU General Public License
14 | along with AutoQuad. If not, see .
15 |
16 | Copyright © 2011-2014 Bill Nesbitt
17 | */
18 |
19 | #ifndef _usb_h
20 | #define _usb_h
21 |
22 | #include
23 |
24 | #define USB_RX_BUFSIZE 512
25 |
26 | #define USB_STREAM_TELEMETRY 300
27 | #define USB_STREAM_MAVLINK 600
28 | #define USB_STREAM_GPS 1200
29 |
30 | typedef struct {
31 | uint32_t bitrate;
32 | uint8_t format;
33 | uint8_t parityType;
34 | uint8_t dataType;
35 | } lineCoding_t;
36 |
37 | typedef struct {
38 | uint8_t rxBuf[USB_RX_BUFSIZE];
39 | uint16_t rxBufHead;
40 | uint16_t rxBufTail;
41 | lineCoding_t lineCoding;
42 | } usbStruct_t;
43 |
44 | extern usbStruct_t usbData;
45 |
46 | extern void usbInit(void);
47 | extern void usbTx(uint8_t* buf, uint32_t len);
48 | extern uint8_t usbRx();
49 | extern uint8_t usbAvailable(void);
50 | extern uint8_t usbIsSuspend(void);
51 |
52 | void USBD_USR_Init(void);
53 | void USBD_USR_DeviceReset (uint8_t speed);
54 | void USBD_USR_DeviceConfigured (void);
55 | void USBD_USR_DeviceSuspended(void);
56 | void USBD_USR_DeviceResumed(void);
57 | void USBD_USR_DeviceConnected(void);
58 | void USBD_USR_DeviceDisconnected(void);
59 |
60 | #endif
61 |
--------------------------------------------------------------------------------
/onboard/usb_bsp.h:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file usb_bsp.h
4 | * @author MCD Application Team
5 | * @version V2.1.0
6 | * @date 19-March-2012
7 | * @brief Specific api's relative to the used hardware platform
8 | ******************************************************************************
9 | * @attention
10 | *
11 | * © COPYRIGHT 2012 STMicroelectronics
12 | *
13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
14 | * You may not use this file except in compliance with the License.
15 | * You may obtain a copy of the License at:
16 | *
17 | * http://www.st.com/software_license_agreement_liberty_v2
18 | *
19 | * Unless required by applicable law or agreed to in writing, software
20 | * distributed under the License is distributed on an "AS IS" BASIS,
21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 | * See the License for the specific language governing permissions and
23 | * limitations under the License.
24 | *
25 | ******************************************************************************
26 | */
27 |
28 | /* Define to prevent recursive inclusion -------------------------------------*/
29 | #ifndef __USB_BSP__H__
30 | #define __USB_BSP__H__
31 |
32 | /* Includes ------------------------------------------------------------------*/
33 | #include "usb_core.h"
34 | #include "usb_conf.h"
35 |
36 | /** @addtogroup USB_OTG_DRIVER
37 | * @{
38 | */
39 |
40 | /** @defgroup USB_BSP
41 | * @brief This file is the
42 | * @{
43 | */
44 |
45 |
46 | /** @defgroup USB_BSP_Exported_Defines
47 | * @{
48 | */
49 | /**
50 | * @}
51 | */
52 |
53 |
54 | /** @defgroup USB_BSP_Exported_Types
55 | * @{
56 | */
57 | /**
58 | * @}
59 | */
60 |
61 |
62 | /** @defgroup USB_BSP_Exported_Macros
63 | * @{
64 | */
65 | /**
66 | * @}
67 | */
68 |
69 | /** @defgroup USB_BSP_Exported_Variables
70 | * @{
71 | */
72 | /**
73 | * @}
74 | */
75 |
76 | /** @defgroup USB_BSP_Exported_FunctionsPrototype
77 | * @{
78 | */
79 | void BSP_Init(void);
80 |
81 | void USB_OTG_BSP_Init (USB_OTG_CORE_HANDLE *pdev);
82 | void USB_OTG_BSP_uDelay (const uint32_t usec);
83 | void USB_OTG_BSP_mDelay (const uint32_t msec);
84 | void USB_OTG_BSP_EnableInterrupt (USB_OTG_CORE_HANDLE *pdev);
85 | #ifdef USE_HOST_MODE
86 | void USB_OTG_BSP_ConfigVBUS(USB_OTG_CORE_HANDLE *pdev);
87 | void USB_OTG_BSP_DriveVBUS(USB_OTG_CORE_HANDLE *pdev,uint8_t state);
88 | #endif
89 | /**
90 | * @}
91 | */
92 |
93 | #endif //__USB_BSP__H__
94 |
95 | /**
96 | * @}
97 | */
98 |
99 | /**
100 | * @}
101 | */
102 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
103 |
104 |
--------------------------------------------------------------------------------
/onboard/usb_dcd_int.h:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file usb_dcd_int.h
4 | * @author MCD Application Team
5 | * @version V2.1.0
6 | * @date 19-March-2012
7 | * @brief Peripheral Device Interface Layer
8 | ******************************************************************************
9 | * @attention
10 | *
11 | * © COPYRIGHT 2012 STMicroelectronics
12 | *
13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
14 | * You may not use this file except in compliance with the License.
15 | * You may obtain a copy of the License at:
16 | *
17 | * http://www.st.com/software_license_agreement_liberty_v2
18 | *
19 | * Unless required by applicable law or agreed to in writing, software
20 | * distributed under the License is distributed on an "AS IS" BASIS,
21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 | * See the License for the specific language governing permissions and
23 | * limitations under the License.
24 | *
25 | ******************************************************************************
26 | */
27 |
28 | /* Define to prevent recursive inclusion -------------------------------------*/
29 | #ifndef USB_DCD_INT_H__
30 | #define USB_DCD_INT_H__
31 |
32 | /* Includes ------------------------------------------------------------------*/
33 | #include "usb_dcd.h"
34 |
35 |
36 |
37 | /** @addtogroup USB_OTG_DRIVER
38 | * @{
39 | */
40 |
41 | /** @defgroup USB_DCD_INT
42 | * @brief This file is the
43 | * @{
44 | */
45 |
46 |
47 | /** @defgroup USB_DCD_INT_Exported_Defines
48 | * @{
49 | */
50 |
51 | typedef struct _USBD_DCD_INT
52 | {
53 | uint8_t (* DataOutStage) (USB_OTG_CORE_HANDLE *pdev , uint8_t epnum);
54 | uint8_t (* DataInStage) (USB_OTG_CORE_HANDLE *pdev , uint8_t epnum);
55 | uint8_t (* SetupStage) (USB_OTG_CORE_HANDLE *pdev);
56 | uint8_t (* SOF) (USB_OTG_CORE_HANDLE *pdev);
57 | uint8_t (* Reset) (USB_OTG_CORE_HANDLE *pdev);
58 | uint8_t (* Suspend) (USB_OTG_CORE_HANDLE *pdev);
59 | uint8_t (* Resume) (USB_OTG_CORE_HANDLE *pdev);
60 | uint8_t (* IsoINIncomplete) (USB_OTG_CORE_HANDLE *pdev);
61 | uint8_t (* IsoOUTIncomplete) (USB_OTG_CORE_HANDLE *pdev);
62 |
63 | uint8_t (* DevConnected) (USB_OTG_CORE_HANDLE *pdev);
64 | uint8_t (* DevDisconnected) (USB_OTG_CORE_HANDLE *pdev);
65 |
66 | }USBD_DCD_INT_cb_TypeDef;
67 |
68 | extern USBD_DCD_INT_cb_TypeDef *USBD_DCD_INT_fops;
69 | /**
70 | * @}
71 | */
72 |
73 |
74 | /** @defgroup USB_DCD_INT_Exported_Types
75 | * @{
76 | */
77 | /**
78 | * @}
79 | */
80 |
81 | /** @defgroup USB_DCD_INT_Exported_Macros
82 | * @{
83 | */
84 |
85 | #define CLEAR_IN_EP_INTR(epnum,intr) \
86 | diepint.d32=0; \
87 | diepint.b.intr = 1; \
88 | USB_OTG_WRITE_REG32(&pdev->regs.INEP_REGS[epnum]->DIEPINT,diepint.d32);
89 |
90 | #define CLEAR_OUT_EP_INTR(epnum,intr) \
91 | doepint.d32=0; \
92 | doepint.b.intr = 1; \
93 | USB_OTG_WRITE_REG32(&pdev->regs.OUTEP_REGS[epnum]->DOEPINT,doepint.d32);
94 |
95 | /**
96 | * @}
97 | */
98 |
99 | /** @defgroup USB_DCD_INT_Exported_Variables
100 | * @{
101 | */
102 | /**
103 | * @}
104 | */
105 |
106 | /** @defgroup USB_DCD_INT_Exported_FunctionsPrototype
107 | * @{
108 | */
109 |
110 | uint32_t USBD_OTG_ISR_Handler (USB_OTG_CORE_HANDLE *pdev);
111 |
112 | /**
113 | * @}
114 | */
115 |
116 |
117 | #endif // USB_DCD_INT_H__
118 |
119 | /**
120 | * @}
121 | */
122 |
123 | /**
124 | * @}
125 | */
126 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
127 |
128 |
--------------------------------------------------------------------------------
/onboard/usb_hcd.h:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file usb_hcd.h
4 | * @author MCD Application Team
5 | * @version V2.1.0
6 | * @date 19-March-2012
7 | * @brief Host layer Header file
8 | ******************************************************************************
9 | * @attention
10 | *
11 | * © COPYRIGHT 2012 STMicroelectronics
12 | *
13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
14 | * You may not use this file except in compliance with the License.
15 | * You may obtain a copy of the License at:
16 | *
17 | * http://www.st.com/software_license_agreement_liberty_v2
18 | *
19 | * Unless required by applicable law or agreed to in writing, software
20 | * distributed under the License is distributed on an "AS IS" BASIS,
21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 | * See the License for the specific language governing permissions and
23 | * limitations under the License.
24 | *
25 | ******************************************************************************
26 | */
27 |
28 | /* Define to prevent recursive inclusion -------------------------------------*/
29 | #ifndef __USB_HCD_H__
30 | #define __USB_HCD_H__
31 |
32 | /* Includes ------------------------------------------------------------------*/
33 | #include "usb_regs.h"
34 | #include "usb_core.h"
35 |
36 |
37 | /** @addtogroup USB_OTG_DRIVER
38 | * @{
39 | */
40 |
41 | /** @defgroup USB_HCD
42 | * @brief This file is the
43 | * @{
44 | */
45 |
46 |
47 | /** @defgroup USB_HCD_Exported_Defines
48 | * @{
49 | */
50 | /**
51 | * @}
52 | */
53 |
54 |
55 | /** @defgroup USB_HCD_Exported_Types
56 | * @{
57 | */
58 | /**
59 | * @}
60 | */
61 |
62 |
63 | /** @defgroup USB_HCD_Exported_Macros
64 | * @{
65 | */
66 | /**
67 | * @}
68 | */
69 |
70 | /** @defgroup USB_HCD_Exported_Variables
71 | * @{
72 | */
73 | /**
74 | * @}
75 | */
76 |
77 | /** @defgroup USB_HCD_Exported_FunctionsPrototype
78 | * @{
79 | */
80 | uint32_t HCD_Init (USB_OTG_CORE_HANDLE *pdev ,
81 | USB_OTG_CORE_ID_TypeDef coreID);
82 | uint32_t HCD_HC_Init (USB_OTG_CORE_HANDLE *pdev ,
83 | uint8_t hc_num);
84 | uint32_t HCD_SubmitRequest (USB_OTG_CORE_HANDLE *pdev ,
85 | uint8_t hc_num) ;
86 | uint32_t HCD_GetCurrentSpeed (USB_OTG_CORE_HANDLE *pdev);
87 | uint32_t HCD_ResetPort (USB_OTG_CORE_HANDLE *pdev);
88 | uint32_t HCD_IsDeviceConnected (USB_OTG_CORE_HANDLE *pdev);
89 | uint32_t HCD_GetCurrentFrame (USB_OTG_CORE_HANDLE *pdev) ;
90 | URB_STATE HCD_GetURB_State (USB_OTG_CORE_HANDLE *pdev, uint8_t ch_num);
91 | uint32_t HCD_GetXferCnt (USB_OTG_CORE_HANDLE *pdev, uint8_t ch_num);
92 | HC_STATUS HCD_GetHCState (USB_OTG_CORE_HANDLE *pdev, uint8_t ch_num) ;
93 | /**
94 | * @}
95 | */
96 |
97 | #endif //__USB_HCD_H__
98 |
99 |
100 | /**
101 | * @}
102 | */
103 |
104 | /**
105 | * @}
106 | */
107 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
108 |
109 |
--------------------------------------------------------------------------------
/onboard/usb_hcd_int.h:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file usb_hcd_int.h
4 | * @author MCD Application Team
5 | * @version V2.1.0
6 | * @date 19-March-2012
7 | * @brief Peripheral Device Interface Layer
8 | ******************************************************************************
9 | * @attention
10 | *
11 | * © COPYRIGHT 2012 STMicroelectronics
12 | *
13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
14 | * You may not use this file except in compliance with the License.
15 | * You may obtain a copy of the License at:
16 | *
17 | * http://www.st.com/software_license_agreement_liberty_v2
18 | *
19 | * Unless required by applicable law or agreed to in writing, software
20 | * distributed under the License is distributed on an "AS IS" BASIS,
21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 | * See the License for the specific language governing permissions and
23 | * limitations under the License.
24 | *
25 | ******************************************************************************
26 | */
27 |
28 | /* Define to prevent recursive inclusion -------------------------------------*/
29 | #ifndef __HCD_INT_H__
30 | #define __HCD_INT_H__
31 |
32 | /* Includes ------------------------------------------------------------------*/
33 | #include "usb_hcd.h"
34 |
35 |
36 | /** @addtogroup USB_OTG_DRIVER
37 | * @{
38 | */
39 |
40 | /** @defgroup USB_HCD_INT
41 | * @brief This file is the
42 | * @{
43 | */
44 |
45 |
46 | /** @defgroup USB_HCD_INT_Exported_Defines
47 | * @{
48 | */
49 | /**
50 | * @}
51 | */
52 |
53 |
54 | /** @defgroup USB_HCD_INT_Exported_Types
55 | * @{
56 | */
57 |
58 | typedef struct _USBH_HCD_INT
59 | {
60 | uint8_t (* SOF) (USB_OTG_CORE_HANDLE *pdev);
61 | uint8_t (* DevConnected) (USB_OTG_CORE_HANDLE *pdev);
62 | uint8_t (* DevDisconnected) (USB_OTG_CORE_HANDLE *pdev);
63 |
64 | }USBH_HCD_INT_cb_TypeDef;
65 |
66 | extern USBH_HCD_INT_cb_TypeDef *USBH_HCD_INT_fops;
67 | /**
68 | * @}
69 | */
70 |
71 |
72 | /** @defgroup USB_HCD_INT_Exported_Macros
73 | * @{
74 | */
75 |
76 | #define CLEAR_HC_INT(HC_REGS, intr) \
77 | {\
78 | USB_OTG_HCINTn_TypeDef hcint_clear; \
79 | hcint_clear.d32 = 0; \
80 | hcint_clear.b.intr = 1; \
81 | USB_OTG_WRITE_REG32(&((HC_REGS)->HCINT), hcint_clear.d32);\
82 | }\
83 |
84 | #define MASK_HOST_INT_CHH(hc_num) { USB_OTG_HCINTMSK_TypeDef INTMSK; \
85 | INTMSK.d32 = USB_OTG_READ_REG32(&pdev->regs.HC_REGS[hc_num]->HCINTMSK); \
86 | INTMSK.b.chhltd = 0; \
87 | USB_OTG_WRITE_REG32(&pdev->regs.HC_REGS[hc_num]->HCINTMSK, INTMSK.d32);}
88 |
89 | #define UNMASK_HOST_INT_CHH(hc_num) { USB_OTG_HCINTMSK_TypeDef INTMSK; \
90 | INTMSK.d32 = USB_OTG_READ_REG32(&pdev->regs.HC_REGS[hc_num]->HCINTMSK); \
91 | INTMSK.b.chhltd = 1; \
92 | USB_OTG_WRITE_REG32(&pdev->regs.HC_REGS[hc_num]->HCINTMSK, INTMSK.d32);}
93 |
94 | #define MASK_HOST_INT_ACK(hc_num) { USB_OTG_HCINTMSK_TypeDef INTMSK; \
95 | INTMSK.d32 = USB_OTG_READ_REG32(&pdev->regs.HC_REGS[hc_num]->HCINTMSK); \
96 | INTMSK.b.ack = 0; \
97 | USB_OTG_WRITE_REG32(&pdev->regs.HC_REGS[hc_num]->HCINTMSK, GINTMSK.d32);}
98 |
99 | #define UNMASK_HOST_INT_ACK(hc_num) { USB_OTG_HCGINTMSK_TypeDef INTMSK; \
100 | INTMSK.d32 = USB_OTG_READ_REG32(&pdev->regs.HC_REGS[hc_num]->HCINTMSK); \
101 | INTMSK.b.ack = 1; \
102 | USB_OTG_WRITE_REG32(&pdev->regs.HC_REGS[hc_num]->HCINTMSK, INTMSK.d32);}
103 |
104 | /**
105 | * @}
106 | */
107 |
108 | /** @defgroup USB_HCD_INT_Exported_Variables
109 | * @{
110 | */
111 | /**
112 | * @}
113 | */
114 |
115 | /** @defgroup USB_HCD_INT_Exported_FunctionsPrototype
116 | * @{
117 | */
118 | /* Callbacks handler */
119 | void ConnectCallback_Handler(USB_OTG_CORE_HANDLE *pdev);
120 | void Disconnect_Callback_Handler(USB_OTG_CORE_HANDLE *pdev);
121 | void Overcurrent_Callback_Handler(USB_OTG_CORE_HANDLE *pdev);
122 | uint32_t USBH_OTG_ISR_Handler (USB_OTG_CORE_HANDLE *pdev);
123 |
124 | /**
125 | * @}
126 | */
127 |
128 |
129 |
130 | #endif //__HCD_INT_H__
131 |
132 |
133 | /**
134 | * @}
135 | */
136 |
137 | /**
138 | * @}
139 | */
140 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
141 |
142 |
--------------------------------------------------------------------------------
/onboard/usbd_conf.h:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file usbd_conf.h
4 | * @author MCD Application Team
5 | * @version V1.1.0
6 | * @date 19-March-2012
7 | * @brief USB Device configuration file
8 | ******************************************************************************
9 | * @attention
10 | *
11 | * © COPYRIGHT 2012 STMicroelectronics
12 | *
13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
14 | * You may not use this file except in compliance with the License.
15 | * You may obtain a copy of the License at:
16 | *
17 | * http://www.st.com/software_license_agreement_liberty_v2
18 | *
19 | * Unless required by applicable law or agreed to in writing, software
20 | * distributed under the License is distributed on an "AS IS" BASIS,
21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 | * See the License for the specific language governing permissions and
23 | * limitations under the License.
24 | *
25 | ******************************************************************************
26 | */
27 |
28 | /* Define to prevent recursive inclusion -------------------------------------*/
29 | #ifndef __USBD_CONF__H__
30 | #define __USBD_CONF__H__
31 |
32 | /* Includes ------------------------------------------------------------------*/
33 | #include "usb_conf.h"
34 |
35 | /** @defgroup USB_CONF_Exported_Defines
36 | * @{
37 | */
38 | #define USBD_CFG_MAX_NUM 1
39 | #define USBD_ITF_MAX_NUM 1
40 |
41 | //#define USBD_SELF_POWERED
42 |
43 | #define USB_MAX_STR_DESC_SIZ 255
44 |
45 | /** @defgroup USB_VCP_Class_Layer_Parameter
46 | * @{
47 | */
48 | #define CDC_IN_EP 0x81 /* EP1 for data IN */
49 | #define CDC_OUT_EP 0x01 /* EP1 for data OUT */
50 | #define CDC_CMD_EP 0x82 /* EP2 for CDC commands */
51 | #define MSC_IN_EP 0x83
52 | #define MSC_OUT_EP 0x03
53 |
54 |
55 | /* CDC Endpoints parameters: you can fine tune these values depending on the needed baudrates and performance. */
56 | #ifdef USE_USB_OTG_HS
57 | #define CDC_DATA_MAX_PACKET_SIZE 512 /* Endpoint IN & OUT Packet size */
58 | #define CDC_CMD_PACKET_SZE 8 /* Control Endpoint Packet size */
59 |
60 | #define CDC_IN_FRAME_INTERVAL 40 /* Number of micro-frames between IN transfers */
61 | #define APP_RX_DATA_SIZE 2048 /* Total size of IN buffer:
62 | APP_RX_DATA_SIZE*8/MAX_BAUDARATE*1000 should be > CDC_IN_FRAME_INTERVAL*8 */
63 | #else
64 | #define CDC_DATA_MAX_PACKET_SIZE 64 /* Endpoint IN & OUT Packet size */
65 | #define CDC_CMD_PACKET_SZE 8 /* Control Endpoint Packet size */
66 |
67 | #define CDC_IN_FRAME_INTERVAL 5 /* Number of frames between IN transfers */
68 | #define APP_RX_DATA_SIZE 1024 /* Total size of IN buffer:
69 | APP_RX_DATA_SIZE*8/MAX_BAUDARATE*1000 should be > CDC_IN_FRAME_INTERVAL */
70 | #endif /* USE_USB_OTG_HS */
71 |
72 | #define APP_FOPS VCP_fops
73 |
74 | // MSC stuff
75 | #ifdef USE_USB_OTG_HS
76 | #ifdef USE_ULPI_PHY
77 | #define MSC_MAX_PACKET 512
78 | #else
79 | #define MSC_MAX_PACKET 64
80 | #endif
81 | #else /*USE_USB_OTG_FS*/
82 | #define MSC_MAX_PACKET 64
83 | #endif
84 |
85 | //#define MSC_MEDIA_PACKET 4096
86 |
87 | /**
88 | * @}
89 | */
90 |
91 | /** @defgroup USB_CONF_Exported_Types
92 | * @{
93 | */
94 | /**
95 | * @}
96 | */
97 |
98 |
99 | /** @defgroup USB_CONF_Exported_Macros
100 | * @{
101 | */
102 | /**
103 | * @}
104 | */
105 |
106 | /** @defgroup USB_CONF_Exported_Variables
107 | * @{
108 | */
109 | /**
110 | * @}
111 | */
112 |
113 | /** @defgroup USB_CONF_Exported_FunctionsPrototype
114 | * @{
115 | */
116 | /**
117 | * @}
118 | */
119 |
120 |
121 | #endif //__USBD_CONF__H__
122 |
123 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
124 |
125 |
--------------------------------------------------------------------------------
/onboard/usbd_core.h:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file usbd_core.h
4 | * @author MCD Application Team
5 | * @version V1.1.0
6 | * @date 19-March-2012
7 | * @brief Header file for usbd_core.c
8 | ******************************************************************************
9 | * @attention
10 | *
11 | * © COPYRIGHT 2012 STMicroelectronics
12 | *
13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
14 | * You may not use this file except in compliance with the License.
15 | * You may obtain a copy of the License at:
16 | *
17 | * http://www.st.com/software_license_agreement_liberty_v2
18 | *
19 | * Unless required by applicable law or agreed to in writing, software
20 | * distributed under the License is distributed on an "AS IS" BASIS,
21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 | * See the License for the specific language governing permissions and
23 | * limitations under the License.
24 | *
25 | ******************************************************************************
26 | */
27 |
28 | /* Define to prevent recursive inclusion -------------------------------------*/
29 | #ifndef __USBD_CORE_H
30 | #define __USBD_CORE_H
31 |
32 | /* Includes ------------------------------------------------------------------*/
33 | #include "usb_dcd.h"
34 | #include "usbd_def.h"
35 | #include "usbd_conf.h"
36 |
37 | /** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY
38 | * @{
39 | */
40 |
41 | /** @defgroup USBD_CORE
42 | * @brief This file is the Header file for usbd_core.c file
43 | * @{
44 | */
45 |
46 |
47 | /** @defgroup USBD_CORE_Exported_Defines
48 | * @{
49 | */
50 |
51 | typedef enum {
52 | USBD_OK = 0,
53 | USBD_BUSY,
54 | USBD_FAIL,
55 | }USBD_Status;
56 | /**
57 | * @}
58 | */
59 |
60 |
61 | /** @defgroup USBD_CORE_Exported_TypesDefinitions
62 | * @{
63 | */
64 |
65 |
66 | /**
67 | * @}
68 | */
69 |
70 |
71 |
72 | /** @defgroup USBD_CORE_Exported_Macros
73 | * @{
74 | */
75 |
76 | /**
77 | * @}
78 | */
79 |
80 | /** @defgroup USBD_CORE_Exported_Variables
81 | * @{
82 | */
83 |
84 | /**
85 | * @}
86 | */
87 |
88 | /** @defgroup USBD_CORE_Exported_FunctionsPrototype
89 | * @{
90 | */
91 | void USBD_Init(USB_OTG_CORE_HANDLE *pdev,
92 | USB_OTG_CORE_ID_TypeDef coreID,
93 | USBD_DEVICE *pDevice,
94 | USBD_Class_cb_TypeDef *class_cb,
95 | USBD_Usr_cb_TypeDef *usr_cb);
96 |
97 | USBD_Status USBD_DeInit(USB_OTG_CORE_HANDLE *pdev);
98 |
99 | USBD_Status USBD_ClrCfg(USB_OTG_CORE_HANDLE *pdev, uint8_t cfgidx);
100 |
101 | USBD_Status USBD_SetCfg(USB_OTG_CORE_HANDLE *pdev, uint8_t cfgidx);
102 |
103 | /**
104 | * @}
105 | */
106 |
107 | #endif /* __USBD_CORE_H */
108 |
109 | /**
110 | * @}
111 | */
112 |
113 | /**
114 | * @}
115 | */
116 |
117 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
118 |
119 |
120 |
121 |
--------------------------------------------------------------------------------
/onboard/usbd_desc.h:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file usbd_desc.h
4 | * @author MCD Application Team
5 | * @version V1.1.0
6 | * @date 19-March-2012
7 | * @brief header file for the usbd_desc.c file
8 | ******************************************************************************
9 | * @attention
10 | *
11 | * © COPYRIGHT 2012 STMicroelectronics
12 | *
13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
14 | * You may not use this file except in compliance with the License.
15 | * You may obtain a copy of the License at:
16 | *
17 | * http://www.st.com/software_license_agreement_liberty_v2
18 | *
19 | * Unless required by applicable law or agreed to in writing, software
20 | * distributed under the License is distributed on an "AS IS" BASIS,
21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 | * See the License for the specific language governing permissions and
23 | * limitations under the License.
24 | *
25 | ******************************************************************************
26 | */
27 |
28 | /* Define to prevent recursive inclusion -------------------------------------*/
29 |
30 | #ifndef __USB_DESC_H
31 | #define __USB_DESC_H
32 |
33 | /* Includes ------------------------------------------------------------------*/
34 | #include "usbd_def.h"
35 |
36 | /** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY
37 | * @{
38 | */
39 |
40 | /** @defgroup USB_DESC
41 | * @brief general defines for the usb device library file
42 | * @{
43 | */
44 |
45 | /** @defgroup USB_DESC_Exported_Defines
46 | * @{
47 | */
48 | #define USB_DEVICE_DESCRIPTOR_TYPE 0x01
49 | #define USB_CONFIGURATION_DESCRIPTOR_TYPE 0x02
50 | #define USB_STRING_DESCRIPTOR_TYPE 0x03
51 | #define USB_INTERFACE_DESCRIPTOR_TYPE 0x04
52 | #define USB_ENDPOINT_DESCRIPTOR_TYPE 0x05
53 | #define USB_SIZ_DEVICE_DESC 18
54 | #define USB_SIZ_STRING_LANGID 4
55 |
56 | /**
57 | * @}
58 | */
59 |
60 |
61 | /** @defgroup USBD_DESC_Exported_TypesDefinitions
62 | * @{
63 | */
64 | /**
65 | * @}
66 | */
67 |
68 |
69 |
70 | /** @defgroup USBD_DESC_Exported_Macros
71 | * @{
72 | */
73 | /**
74 | * @}
75 | */
76 |
77 | /** @defgroup USBD_DESC_Exported_Variables
78 | * @{
79 | */
80 | extern uint8_t USBD_DeviceDesc [USB_SIZ_DEVICE_DESC];
81 | extern uint8_t USBD_StrDesc[USB_MAX_STR_DESC_SIZ];
82 | extern uint8_t USBD_OtherSpeedCfgDesc[USB_LEN_CFG_DESC];
83 | extern uint8_t USBD_DeviceQualifierDesc[USB_LEN_DEV_QUALIFIER_DESC];
84 | extern uint8_t USBD_LangIDDesc[USB_SIZ_STRING_LANGID];
85 | extern USBD_DEVICE USR_desc;
86 | /**
87 | * @}
88 | */
89 |
90 | /** @defgroup USBD_DESC_Exported_FunctionsPrototype
91 | * @{
92 | */
93 |
94 |
95 | uint8_t * USBD_USR_DeviceDescriptor( uint8_t speed , uint16_t *length);
96 | uint8_t * USBD_USR_LangIDStrDescriptor( uint8_t speed , uint16_t *length);
97 | uint8_t * USBD_USR_ManufacturerStrDescriptor ( uint8_t speed , uint16_t *length);
98 | uint8_t * USBD_USR_ProductStrDescriptor ( uint8_t speed , uint16_t *length);
99 | uint8_t * USBD_USR_SerialStrDescriptor( uint8_t speed , uint16_t *length);
100 | uint8_t * USBD_USR_ConfigStrDescriptor( uint8_t speed , uint16_t *length);
101 | uint8_t * USBD_USR_InterfaceStrDescriptor( uint8_t speed , uint16_t *length);
102 |
103 | #ifdef USB_SUPPORT_USER_STRING_DESC
104 | uint8_t * USBD_USR_USRStringDesc (uint8_t speed, uint8_t idx , uint16_t *length);
105 | #endif /* USB_SUPPORT_USER_STRING_DESC */
106 |
107 | /**
108 | * @}
109 | */
110 |
111 | #endif /* __USBD_DESC_H */
112 |
113 | /**
114 | * @}
115 | */
116 |
117 | /**
118 | * @}
119 | */
120 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
121 |
--------------------------------------------------------------------------------
/onboard/usbd_ioreq.h:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file usbd_ioreq.h
4 | * @author MCD Application Team
5 | * @version V1.1.0
6 | * @date 19-March-2012
7 | * @brief header file for the usbd_ioreq.c file
8 | ******************************************************************************
9 | * @attention
10 | *
11 | * © COPYRIGHT 2012 STMicroelectronics
12 | *
13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
14 | * You may not use this file except in compliance with the License.
15 | * You may obtain a copy of the License at:
16 | *
17 | * http://www.st.com/software_license_agreement_liberty_v2
18 | *
19 | * Unless required by applicable law or agreed to in writing, software
20 | * distributed under the License is distributed on an "AS IS" BASIS,
21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 | * See the License for the specific language governing permissions and
23 | * limitations under the License.
24 | *
25 | ******************************************************************************
26 | */
27 |
28 | /* Define to prevent recursive inclusion -------------------------------------*/
29 |
30 | #ifndef __USBD_IOREQ_H_
31 | #define __USBD_IOREQ_H_
32 |
33 | /* Includes ------------------------------------------------------------------*/
34 | #include "usbd_def.h"
35 | #include "usbd_core.h"
36 |
37 | /** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY
38 | * @{
39 | */
40 |
41 | /** @defgroup USBD_IOREQ
42 | * @brief header file for the usbd_ioreq.c file
43 | * @{
44 | */
45 |
46 | /** @defgroup USBD_IOREQ_Exported_Defines
47 | * @{
48 | */
49 | /**
50 | * @}
51 | */
52 |
53 |
54 | /** @defgroup USBD_IOREQ_Exported_Types
55 | * @{
56 | */
57 |
58 |
59 | /**
60 | * @}
61 | */
62 |
63 |
64 |
65 | /** @defgroup USBD_IOREQ_Exported_Macros
66 | * @{
67 | */
68 |
69 | /**
70 | * @}
71 | */
72 |
73 | /** @defgroup USBD_IOREQ_Exported_Variables
74 | * @{
75 | */
76 |
77 | /**
78 | * @}
79 | */
80 |
81 | /** @defgroup USBD_IOREQ_Exported_FunctionsPrototype
82 | * @{
83 | */
84 |
85 | USBD_Status USBD_CtlSendData (USB_OTG_CORE_HANDLE *pdev,
86 | uint8_t *buf,
87 | uint16_t len);
88 |
89 | USBD_Status USBD_CtlContinueSendData (USB_OTG_CORE_HANDLE *pdev,
90 | uint8_t *pbuf,
91 | uint16_t len);
92 |
93 | USBD_Status USBD_CtlPrepareRx (USB_OTG_CORE_HANDLE *pdev,
94 | uint8_t *pbuf,
95 | uint16_t len);
96 |
97 | USBD_Status USBD_CtlContinueRx (USB_OTG_CORE_HANDLE *pdev,
98 | uint8_t *pbuf,
99 | uint16_t len);
100 |
101 | USBD_Status USBD_CtlSendStatus (USB_OTG_CORE_HANDLE *pdev);
102 |
103 | USBD_Status USBD_CtlReceiveStatus (USB_OTG_CORE_HANDLE *pdev);
104 |
105 | uint16_t USBD_GetRxCount (USB_OTG_CORE_HANDLE *pdev ,
106 | uint8_t epnum);
107 |
108 | /**
109 | * @}
110 | */
111 |
112 | #endif /* __USBD_IOREQ_H_ */
113 |
114 | /**
115 | * @}
116 | */
117 |
118 | /**
119 | * @}
120 | */
121 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
122 |
--------------------------------------------------------------------------------
/onboard/usbd_msc_bot.h:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file usbd_msc_bot.h
4 | * @author MCD Application Team
5 | * @version V1.1.0
6 | * @date 19-March-2012
7 | * @brief header for the usbd_msc_bot.c file
8 | ******************************************************************************
9 | * @attention
10 | *
11 | * © COPYRIGHT 2012 STMicroelectronics
12 | *
13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
14 | * You may not use this file except in compliance with the License.
15 | * You may obtain a copy of the License at:
16 | *
17 | * http://www.st.com/software_license_agreement_liberty_v2
18 | *
19 | * Unless required by applicable law or agreed to in writing, software
20 | * distributed under the License is distributed on an "AS IS" BASIS,
21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 | * See the License for the specific language governing permissions and
23 | * limitations under the License.
24 | *
25 | ******************************************************************************
26 | */
27 |
28 | /* Define to prevent recursive inclusion -------------------------------------*/
29 |
30 | #include "usbd_core.h"
31 |
32 | /* Define to prevent recursive inclusion -------------------------------------*/
33 | #ifndef __USBD_MSC_BOT_H
34 | #define __USBD_MSC_BOT_H
35 |
36 | /** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY
37 | * @{
38 | */
39 |
40 | /** @defgroup MSC_BOT
41 | * @brief This file is the Header file for usbd_bot.c
42 | * @{
43 | */
44 |
45 |
46 | /** @defgroup USBD_CORE_Exported_Defines
47 | * @{
48 | */
49 | #define BOT_IDLE 0 /* Idle state */
50 | #define BOT_DATA_OUT 1 /* Data Out state */
51 | #define BOT_DATA_IN 2 /* Data In state */
52 | #define BOT_LAST_DATA_IN 3 /* Last Data In Last */
53 | #define BOT_SEND_DATA 4 /* Send Immediate data */
54 |
55 | #define BOT_CBW_SIGNATURE 0x43425355
56 | #define BOT_CSW_SIGNATURE 0x53425355
57 | #define BOT_CBW_LENGTH 31
58 | #define BOT_CSW_LENGTH 13
59 |
60 | /* CSW Status Definitions */
61 | #define CSW_CMD_PASSED 0x00
62 | #define CSW_CMD_FAILED 0x01
63 | #define CSW_PHASE_ERROR 0x02
64 |
65 | /* BOT Status */
66 | #define BOT_STATE_NORMAL 0
67 | #define BOT_STATE_RECOVERY 1
68 | #define BOT_STATE_ERROR 2
69 |
70 |
71 | #define DIR_IN 0
72 | #define DIR_OUT 1
73 | #define BOTH_DIR 2
74 |
75 | /**
76 | * @}
77 | */
78 |
79 | /** @defgroup MSC_CORE_Private_TypesDefinitions
80 | * @{
81 | */
82 |
83 | typedef struct _MSC_BOT_CBW
84 | {
85 | uint32_t dSignature;
86 | uint32_t dTag;
87 | uint32_t dDataLength;
88 | uint8_t bmFlags;
89 | uint8_t bLUN;
90 | uint8_t bCBLength;
91 | uint8_t CB[16];
92 | }
93 | MSC_BOT_CBW_TypeDef;
94 |
95 |
96 | typedef struct _MSC_BOT_CSW
97 | {
98 | uint32_t dSignature;
99 | uint32_t dTag;
100 | uint32_t dDataResidue;
101 | uint8_t bStatus;
102 | }
103 | MSC_BOT_CSW_TypeDef;
104 |
105 | /**
106 | * @}
107 | */
108 |
109 |
110 | /** @defgroup USBD_CORE_Exported_Types
111 | * @{
112 | */
113 |
114 | //extern uint8_t MSC_BOT_Data[];
115 | extern uint8_t *MSC_BOT_Data;
116 | extern uint16_t MSC_BOT_DataLen;
117 | extern uint8_t MSC_BOT_State;
118 | extern uint8_t MSC_BOT_BurstMode;
119 | extern MSC_BOT_CBW_TypeDef MSC_BOT_cbw;
120 | extern MSC_BOT_CSW_TypeDef MSC_BOT_csw;
121 | /**
122 | * @}
123 | */
124 | /** @defgroup USBD_CORE_Exported_FunctionsPrototypes
125 | * @{
126 | */
127 | void MSC_BOT_Init (USB_OTG_CORE_HANDLE *pdev);
128 | void MSC_BOT_Reset (USB_OTG_CORE_HANDLE *pdev);
129 | void MSC_BOT_DeInit (USB_OTG_CORE_HANDLE *pdev);
130 | void MSC_BOT_DataIn (USB_OTG_CORE_HANDLE *pdev,
131 | uint8_t epnum);
132 |
133 | void MSC_BOT_DataOut (USB_OTG_CORE_HANDLE *pdev,
134 | uint8_t epnum);
135 |
136 | void MSC_BOT_SendCSW (USB_OTG_CORE_HANDLE *pdev,
137 | uint8_t CSW_Status);
138 |
139 | void MSC_BOT_CplClrFeature (USB_OTG_CORE_HANDLE *pdev,
140 | uint8_t epnum);
141 | /**
142 | * @}
143 | */
144 |
145 | #endif /* __USBD_MSC_BOT_H */
146 | /**
147 | * @}
148 | */
149 |
150 | /**
151 | * @}
152 | */
153 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
154 |
155 |
--------------------------------------------------------------------------------
/onboard/usbd_msc_data.c:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file usbd_msc_data.c
4 | * @author MCD Application Team
5 | * @version V1.1.0
6 | * @date 19-March-2012
7 | * @brief This file provides all the vital inquiry pages and sense data.
8 | ******************************************************************************
9 | * @attention
10 | *
11 | * © COPYRIGHT 2012 STMicroelectronics
12 | *
13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
14 | * You may not use this file except in compliance with the License.
15 | * You may obtain a copy of the License at:
16 | *
17 | * http://www.st.com/software_license_agreement_liberty_v2
18 | *
19 | * Unless required by applicable law or agreed to in writing, software
20 | * distributed under the License is distributed on an "AS IS" BASIS,
21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 | * See the License for the specific language governing permissions and
23 | * limitations under the License.
24 | *
25 | ******************************************************************************
26 | */
27 |
28 | /* Includes ------------------------------------------------------------------*/
29 | #include "usbd_msc_data.h"
30 |
31 |
32 | /** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY
33 | * @{
34 | */
35 |
36 |
37 | /** @defgroup MSC_DATA
38 | * @brief Mass storage info/data module
39 | * @{
40 | */
41 |
42 | /** @defgroup MSC_DATA_Private_TypesDefinitions
43 | * @{
44 | */
45 | /**
46 | * @}
47 | */
48 |
49 |
50 | /** @defgroup MSC_DATA_Private_Defines
51 | * @{
52 | */
53 | /**
54 | * @}
55 | */
56 |
57 |
58 | /** @defgroup MSC_DATA_Private_Macros
59 | * @{
60 | */
61 | /**
62 | * @}
63 | */
64 |
65 |
66 | /** @defgroup MSC_DATA_Private_Variables
67 | * @{
68 | */
69 |
70 |
71 | /* USB Mass storage Page 0 Inquiry Data */
72 | const uint8_t MSC_Page00_Inquiry_Data[] = {//7
73 | 0x00,
74 | 0x00,
75 | 0x00,
76 | (LENGTH_INQUIRY_PAGE00 - 4),
77 | 0x00,
78 | 0x80,
79 | 0x83
80 | };
81 | /* USB Mass storage sense 6 Data */
82 | const uint8_t MSC_Mode_Sense6_data[] = {
83 | 0x00,
84 | 0x00,
85 | 0x00,
86 | 0x00,
87 | 0x00,
88 | 0x00,
89 | 0x00,
90 | 0x00
91 | };
92 | /* USB Mass storage sense 10 Data */
93 | const uint8_t MSC_Mode_Sense10_data[] = {
94 | 0x00,
95 | 0x06,
96 | 0x00,
97 | 0x00,
98 | 0x00,
99 | 0x00,
100 | 0x00,
101 | 0x00
102 | };
103 | /**
104 | * @}
105 | */
106 |
107 |
108 | /** @defgroup MSC_DATA_Private_FunctionPrototypes
109 | * @{
110 | */
111 | /**
112 | * @}
113 | */
114 |
115 |
116 | /** @defgroup MSC_DATA_Private_Functions
117 | * @{
118 | */
119 |
120 | /**
121 | * @}
122 | */
123 |
124 |
125 | /**
126 | * @}
127 | */
128 |
129 |
130 | /**
131 | * @}
132 | */
133 |
134 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
135 |
--------------------------------------------------------------------------------
/onboard/usbd_msc_data.h:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file usbd_msc_data.h
4 | * @author MCD Application Team
5 | * @version V1.1.0
6 | * @date 19-March-2012
7 | * @brief header for the usbd_msc_data.c file
8 | ******************************************************************************
9 | * @attention
10 | *
11 | * © COPYRIGHT 2012 STMicroelectronics
12 | *
13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
14 | * You may not use this file except in compliance with the License.
15 | * You may obtain a copy of the License at:
16 | *
17 | * http://www.st.com/software_license_agreement_liberty_v2
18 | *
19 | * Unless required by applicable law or agreed to in writing, software
20 | * distributed under the License is distributed on an "AS IS" BASIS,
21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 | * See the License for the specific language governing permissions and
23 | * limitations under the License.
24 | *
25 | ******************************************************************************
26 | */
27 |
28 | /* Define to prevent recursive inclusion -------------------------------------*/
29 |
30 | #ifndef _USBD_MSC_DATA_H_
31 | #define _USBD_MSC_DATA_H_
32 |
33 | /* Includes ------------------------------------------------------------------*/
34 | #include "usbd_conf.h"
35 |
36 | /** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY
37 | * @{
38 | */
39 |
40 | /** @defgroup USB_INFO
41 | * @brief general defines for the usb device library file
42 | * @{
43 | */
44 |
45 | /** @defgroup USB_INFO_Exported_Defines
46 | * @{
47 | */
48 | #define MODE_SENSE6_LEN 8
49 | #define MODE_SENSE10_LEN 8
50 | #define LENGTH_INQUIRY_PAGE00 7
51 | #define LENGTH_FORMAT_CAPACITIES 20
52 |
53 | /**
54 | * @}
55 | */
56 |
57 |
58 | /** @defgroup USBD_INFO_Exported_TypesDefinitions
59 | * @{
60 | */
61 | /**
62 | * @}
63 | */
64 |
65 |
66 |
67 | /** @defgroup USBD_INFO_Exported_Macros
68 | * @{
69 | */
70 |
71 | /**
72 | * @}
73 | */
74 |
75 | /** @defgroup USBD_INFO_Exported_Variables
76 | * @{
77 | */
78 | extern const uint8_t MSC_Page00_Inquiry_Data[];
79 | extern const uint8_t MSC_Mode_Sense6_data[];
80 | extern const uint8_t MSC_Mode_Sense10_data[] ;
81 |
82 | /**
83 | * @}
84 | */
85 |
86 | /** @defgroup USBD_INFO_Exported_FunctionsPrototype
87 | * @{
88 | */
89 |
90 | /**
91 | * @}
92 | */
93 |
94 | #endif /* _USBD_MSC_DATA_H_ */
95 |
96 | /**
97 | * @}
98 | */
99 |
100 | /**
101 | * @}
102 | */
103 |
104 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
105 |
--------------------------------------------------------------------------------
/onboard/usbd_msc_mem.h:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file usbd_msc_mem.h
4 | * @author MCD Application Team
5 | * @version V1.1.0
6 | * @date 19-March-2012
7 | * @brief header for the STORAGE DISK file file
8 | ******************************************************************************
9 | * @attention
10 | *
11 | * © COPYRIGHT 2012 STMicroelectronics
12 | *
13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
14 | * You may not use this file except in compliance with the License.
15 | * You may obtain a copy of the License at:
16 | *
17 | * http://www.st.com/software_license_agreement_liberty_v2
18 | *
19 | * Unless required by applicable law or agreed to in writing, software
20 | * distributed under the License is distributed on an "AS IS" BASIS,
21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 | * See the License for the specific language governing permissions and
23 | * limitations under the License.
24 | *
25 | ******************************************************************************
26 | */
27 |
28 | /* Define to prevent recursive inclusion -------------------------------------*/
29 |
30 | #ifndef __USBD_MEM_H
31 | #define __USBD_MEM_H
32 | /* Includes ------------------------------------------------------------------*/
33 | #include "usbd_def.h"
34 |
35 |
36 | /** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY
37 | * @{
38 | */
39 |
40 | /** @defgroup USBD_MEM
41 | * @brief header file for the storage disk file
42 | * @{
43 | */
44 |
45 | /** @defgroup USBD_MEM_Exported_Defines
46 | * @{
47 | */
48 | #define USBD_STD_INQUIRY_LENGTH 36
49 | /**
50 | * @}
51 | */
52 |
53 |
54 | /** @defgroup USBD_MEM_Exported_TypesDefinitions
55 | * @{
56 | */
57 |
58 | typedef struct _USBD_STORAGE
59 | {
60 | int8_t (* Init) (uint8_t lun);
61 | int8_t (* GetCapacity) (uint8_t lun, uint32_t *block_num, uint32_t *block_size);
62 | int8_t (* IsReady) (uint8_t lun);
63 | int8_t (* IsWriteProtected) (uint8_t lun);
64 | int8_t (* Read) (uint8_t lun, uint8_t *buf, uint32_t blk_addr, uint16_t blk_len);
65 | int8_t (* Write)(uint8_t lun, uint8_t *buf, uint32_t blk_addr, uint16_t blk_len);
66 | int8_t (* GetMaxLun)(void);
67 | int8_t *pInquiry;
68 | int8_t (* Eject) (uint8_t lun);
69 |
70 | }USBD_STORAGE_cb_TypeDef;
71 | /**
72 | * @}
73 | */
74 |
75 |
76 |
77 | /** @defgroup USBD_MEM_Exported_Macros
78 | * @{
79 | */
80 |
81 | /**
82 | * @}
83 | */
84 |
85 | /** @defgroup USBD_MEM_Exported_Variables
86 | * @{
87 | */
88 |
89 | /**
90 | * @}
91 | */
92 |
93 | /** @defgroup USBD_MEM_Exported_FunctionsPrototype
94 | * @{
95 | */
96 | extern USBD_STORAGE_cb_TypeDef *USBD_STORAGE_fops;
97 | /**
98 | * @}
99 | */
100 |
101 | #endif /* __USBD_MEM_H */
102 | /**
103 | * @}
104 | */
105 |
106 | /**
107 | * @}
108 | */
109 |
110 | /**
111 | * @}
112 | */
113 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
114 |
--------------------------------------------------------------------------------
/onboard/usbd_req.h:
--------------------------------------------------------------------------------
1 | /**
2 | ******************************************************************************
3 | * @file usbd_req.h
4 | * @author MCD Application Team
5 | * @version V1.1.0
6 | * @date 19-March-2012
7 | * @brief header file for the usbd_req.c file
8 | ******************************************************************************
9 | * @attention
10 | *
11 | * © COPYRIGHT 2012 STMicroelectronics
12 | *
13 | * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
14 | * You may not use this file except in compliance with the License.
15 | * You may obtain a copy of the License at:
16 | *
17 | * http://www.st.com/software_license_agreement_liberty_v2
18 | *
19 | * Unless required by applicable law or agreed to in writing, software
20 | * distributed under the License is distributed on an "AS IS" BASIS,
21 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 | * See the License for the specific language governing permissions and
23 | * limitations under the License.
24 | *
25 | ******************************************************************************
26 | */
27 |
28 | /* Define to prevent recursive inclusion -------------------------------------*/
29 |
30 | #ifndef __USB_REQUEST_H_
31 | #define __USB_REQUEST_H_
32 |
33 | /* Includes ------------------------------------------------------------------*/
34 | #include "usbd_def.h"
35 | #include "usbd_core.h"
36 | #include "usbd_conf.h"
37 |
38 |
39 | /** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY
40 | * @{
41 | */
42 |
43 | /** @defgroup USBD_REQ
44 | * @brief header file for the usbd_ioreq.c file
45 | * @{
46 | */
47 |
48 | /** @defgroup USBD_REQ_Exported_Defines
49 | * @{
50 | */
51 | /**
52 | * @}
53 | */
54 |
55 |
56 | /** @defgroup USBD_REQ_Exported_Types
57 | * @{
58 | */
59 | /**
60 | * @}
61 | */
62 |
63 |
64 |
65 | /** @defgroup USBD_REQ_Exported_Macros
66 | * @{
67 | */
68 | /**
69 | * @}
70 | */
71 |
72 | /** @defgroup USBD_REQ_Exported_Variables
73 | * @{
74 | */
75 | /**
76 | * @}
77 | */
78 |
79 | /** @defgroup USBD_REQ_Exported_FunctionsPrototype
80 | * @{
81 | */
82 |
83 | USBD_Status USBD_StdDevReq (USB_OTG_CORE_HANDLE *pdev, USB_SETUP_REQ *req);
84 | USBD_Status USBD_StdItfReq (USB_OTG_CORE_HANDLE *pdev, USB_SETUP_REQ *req);
85 | USBD_Status USBD_StdEPReq (USB_OTG_CORE_HANDLE *pdev, USB_SETUP_REQ *req);
86 | void USBD_ParseSetupRequest( USB_OTG_CORE_HANDLE *pdev,
87 | USB_SETUP_REQ *req);
88 |
89 | void USBD_CtlError( USB_OTG_CORE_HANDLE *pdev,
90 | USB_SETUP_REQ *req);
91 |
92 | void USBD_GetString(uint8_t *desc, uint8_t *unicode, uint16_t *len);
93 | /**
94 | * @}
95 | */
96 |
97 | #endif /* __USB_REQUEST_H_ */
98 |
99 | /**
100 | * @}
101 | */
102 |
103 | /**
104 | * @}
105 | */
106 |
107 |
108 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
109 |
--------------------------------------------------------------------------------
/onboard/util.h:
--------------------------------------------------------------------------------
1 | /*
2 | This file is part of AutoQuad.
3 |
4 | AutoQuad is free software: you can redistribute it and/or modify
5 | it under the terms of the GNU General Public License as published by
6 | the Free Software Foundation, either version 3 of the License, or
7 | (at your option) any later version.
8 |
9 | AutoQuad is distributed in the hope that it will be useful,
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | GNU General Public License for more details.
13 | You should have received a copy of the GNU General Public License
14 | along with AutoQuad. If not, see .
15 |
16 | Copyright © 2011-2014 Bill Nesbitt
17 | */
18 |
19 | #ifndef _util_h
20 | #define _util_h
21 |
22 | #include "aq.h"
23 | #include "CoOS.h"
24 | #include
25 |
26 | #define UTIL_STACK_CHECK CFG_MAX_USER_TASKS // uncomment to allow system to self check for stack overflows
27 |
28 | #define UTIL_CCM_HEAP_SIZE (0x2800) // 40KB
29 |
30 | #define UTIL_ISR_DISABLE __asm volatile ( "CPSID F\n")
31 | #define UTIL_ISR_ENABLE __asm volatile ( "CPSIE F\n")
32 |
33 | #define yield(n) CoTickDelay(n)
34 |
35 | #define constrainInt(v, lo, hi) (((int)(v) < (int)(lo)) ? (int)(lo) : (((int)(v) > (int)(hi)) ? (int)(hi) : (int)(v)))
36 | #define constrainFloat(v, lo, hi) (((float)(v) < (float)(lo)) ? (float)(lo) : (((float)(v) > (float)(hi)) ? (float)(hi) : (float)(v)))
37 |
38 | #define PERIPH2BB(addr, bit) ((uint32_t *)(PERIPH_BB_BASE + ((addr) - PERIPH_BASE) * 32 + ((bit) * 4)))
39 |
40 | // first order filter
41 | typedef struct {
42 | float tc;
43 | float z1;
44 | } utilFilter_t;
45 |
46 | typedef struct {
47 | const float *window;
48 | float *data;
49 | uint8_t n;
50 | uint8_t i;
51 | } utilFirFilter_t;
52 |
53 | extern void delay(unsigned long t);
54 | extern void delayMicros(unsigned long t);
55 | extern void dumpFloat(unsigned char n, float *floats);
56 | extern void dumpInt(unsigned char n, int *ints);
57 | extern void info(void);
58 | extern OS_STK *aqStackInit(uint16_t size, char *name);
59 | extern void *aqCalloc(size_t count, size_t size);
60 | extern void aqFree(void *ptr, size_t count, size_t size);
61 | extern void *aqDataCalloc(uint16_t count, uint16_t size);
62 | extern void utilFilterInit(utilFilter_t *f, float dt, float tau, float setpoint);
63 | extern void utilFilterInit3(utilFilter_t *f, float dt, float tau, float setpoint);
64 | extern float utilFilter(utilFilter_t *f, float signal);
65 | extern float utilFilter3(utilFilter_t *f, float signal);
66 | extern void utilFilterReset(utilFilter_t *f, float setpoint);
67 | extern void utilFilterReset3(utilFilter_t *f, float setpoint);
68 | extern int ftoa(char *buf, float f, unsigned int digits);
69 | extern void utilSerialNoString(void);
70 | extern void utilVersionString(void);
71 | extern float utilFirFilter(utilFirFilter_t *f, float newValue);
72 | extern void utilFirFilterInit(utilFirFilter_t *f, const float *window, float *buffer, uint8_t n);
73 | #ifdef UTIL_STACK_CHECK
74 | extern void utilStackCheck(void);
75 | extern uint16_t stackFrees[UTIL_STACK_CHECK];
76 | extern uint16_t utilGetStackFree(const char *stackName);
77 | #endif
78 |
79 | #endif
80 |
--------------------------------------------------------------------------------
/onboard/utility.c:
--------------------------------------------------------------------------------
1 | /**
2 | *******************************************************************************
3 | * @file utility.c
4 | * @version V1.1.4
5 | * @date 2011.04.20
6 | * @brief Utility management implementation code of CooCox CoOS kernel.
7 | *******************************************************************************
8 | * @copy
9 | *
10 | * INTERNAL FILE,DON'T PUBLIC.
11 | *
12 | * © COPYRIGHT 2009 CooCox
13 | *******************************************************************************
14 | */
15 |
16 |
17 | /*---------------------------- Include ---------------------------------------*/
18 | #include
19 |
20 | #if CFG_UTILITY_EN > 0
21 |
22 |
23 | /**
24 | *******************************************************************************
25 | * @brief Convert tick number to time
26 | * @param[in] ticks Specifies the systerm tick numbers that will be converted.
27 | * @param[out] hour Hours which converted.
28 | * @param[out] minute minutes which converted.
29 | * @param[out] sec seconds which converted.
30 | * @param[out] millsec millseconds which converted.
31 | * @retval None
32 | *
33 | * @par Description
34 | * @details This function is called to convert specify ticks to time format.
35 | *******************************************************************************
36 | */
37 | #if CFG_TICK_TO_TIME_EN > 0
38 | void CoTickToTime(U32 ticks,U8* hour,U8* minute,U8* sec,U16* millsec)
39 | {
40 | U32 totalTime;
41 |
42 | /* Convert ticks to time*/
43 | totalTime = ticks * (1000/CFG_SYSTICK_FREQ);
44 | *millsec = totalTime%1000;
45 | totalTime = totalTime/1000;
46 | *sec = totalTime%60;
47 | totalTime = totalTime/60;
48 | *minute = totalTime%60;
49 | totalTime = totalTime/60;
50 | *hour = totalTime;
51 | }
52 | #endif /* CFG_TICK_TO_TIME_EN */
53 |
54 |
55 | /**
56 | *******************************************************************************
57 | * @brief Convert time to tick
58 | * @param[in] hour Specifies the number of hours.
59 | * @param[in] minute Specifies the number of minutes.
60 | * @param[in] sec Specifies the number of seconds.
61 | * @param[in] millsec Specifies the number of millseconds.
62 | * @param[out] ticks Tick numbers that converted.
63 | * @retval E_INVALID_PARAMETER Invalid parameter be passed and convert fail.
64 | * @retval E_OK Convert successful.
65 | *
66 | * @par Description
67 | * @details This function is called to convert specify time to tick number.
68 | *******************************************************************************
69 | */
70 | #if CFG_TIME_TO_TICK_EN > 0
71 | StatusType CoTimeToTick(U8 hour,U8 minute,U8 sec,U16 millsec,U32* ticks)
72 | {
73 | #if CFG_PAR_CHECKOUT_EN >0
74 | /* Validate arguments to be within range */
75 | if((minute > 59)||(sec > 59)||(millsec > 999))
76 | return E_INVALID_PARAMETER;
77 | #endif
78 |
79 | /* Convert time to ticks */
80 | *ticks = ((hour*3600) + (minute*60) + (sec)) * (CFG_SYSTICK_FREQ)\
81 | + (millsec*CFG_SYSTICK_FREQ + 500)/1000;
82 | return E_OK;
83 | }
84 | #endif /* CFG_TIME_TO_TICK_EN */
85 |
86 | #endif /* CFG_UTILITY_EN */
87 |
--------------------------------------------------------------------------------
/onboard/utility.h:
--------------------------------------------------------------------------------
1 | /**
2 | *******************************************************************************
3 | * @file utility.h
4 | * @version V1.1.4
5 | * @date 2011.04.20
6 | * @brief Utility function header file
7 | * @details This file including some defines and declares related to utility
8 | * function.
9 | *******************************************************************************
10 | * @copy
11 | *
12 | * INTERNAL FILE,DON'T PUBLIC.
13 | *
14 | * © COPYRIGHT 2009 CooCox
15 | *******************************************************************************
16 | */
17 |
18 |
19 | #ifndef _UTILITY_H
20 | #define _UTILITY_H
21 |
22 |
23 | /**
24 | * @struct Time struct utility.h
25 | * @brief Time struct
26 | * @details This struct use to manage time
27 | */
28 | typedef struct SysTime
29 | {
30 | U8 sec; /*!< Second */
31 | U8 min; /*!< Minute */
32 | U8 hour; /*!< Hour */
33 | U8 date; /*!< Date */
34 | U8 month; /*!< Month */
35 | U16 year; /*!< Year */
36 | }TIME;
37 |
38 | #endif
39 |
40 |
--------------------------------------------------------------------------------