Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions posix/include/CPU_Gpio.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
//
// Copyright (c) .NET Foundation and Contributors
// Portions Copyright (c) Microsoft Corporation. All rights reserved.
// See LICENSE file in the project root for full license information.
//


#ifndef _CPU_GPIO_H_
#define _CPU_GPIO_H_

#include "include/stdafx.h"

#if defined(BOARD_WSL)

#define NF_POSIX_GPIO
// multi bank, each have 36
#define GPIO_MAX_PIN 36
#define TOTAL_GPIO_PORTS 36

#endif // BOARD_WSL

#if defined(BOARD_PI_ZERO)

#define NF_POSIX_GPIO
// 1 bank
#define GPIO_MAX_PIN 27
#define TOTAL_GPIO_PORTS 27

#endif // BOARD_PI_ZERO

#if defined(BOARD_JH7100)

#define NF_POSIX_GPIO
// TODO: 1 bank?
#define GPIO_MAX_PIN 48
#define TOTAL_GPIO_PORTS 48

#endif // BOARD_JH7100


#if defined(BOARD_PI_PICO)
// 5 gpios seted as gpin in Nuttx
#define __gpio
#define GPIO_MAX_PIN 30
#define TOTAL_GPIO_PORTS 5
#endif

#if defined(BOARD_PI_ZERO) || defined(BOARD_WSL)
#define __gpio
#include <gpiod.h>

struct gpiod_chip *_chip;

// 9 usable gpios
#define GPIO_MAX_PIN 40
#define TOTAL_GPIO_PORTS 9

static gpiod_line* pinLineStored[GPIO_MAX_PIN];
static GpioPinValue pinLineValue[GPIO_MAX_PIN];
#endif

#if defined(__nuttx__) && defined(__gpio)
static int ioctrlFdReference[GPIO_MAX_PIN];
static GpioPinValue pinLineValue[GPIO_MAX_PIN];
#endif


#if defined(__gpio)
static GpioPinDriveMode pinDirStored[GPIO_MAX_PIN];
#endif

#endif //_CPU_GPIO_H_
15 changes: 15 additions & 0 deletions posix/include/TargetHAL_Spi.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// Copyright (c) .NET Foundation and Contributors
// See LICENSE file in the project root for full license information.
//

#ifndef _TARGET_HAL_SPI_H_
#define _TARGET_HAL_SPI_H_ 1

// # of buses
#define NUM_SPI_BUSES 0

// Maximum number of devices per SPI bus
#define MAX_SPI_DEVICES 5

#endif //_TARGET_HAL_SPI_H_
12 changes: 12 additions & 0 deletions posix/include/TargetPAL_BlockStorage.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//
// Copyright (c) .NET Foundation and Contributors
// See LICENSE file in the project root for full license information.
//

#ifndef _TARGETPAL_BLOCKSTORAGE_H_
#define _TARGETPAL_BLOCKSTORAGE_H_ 1

// this device has 1 block storage devices
#define TARGET_BLOCKSTORAGE_COUNT 1

#endif //_TARGETPAL_BLOCKSTORAGE_H_
9 changes: 9 additions & 0 deletions posix/include/Target_Windows_Storage.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//
// Copyright (c) .NET Foundation and Contributors
// See LICENSE file in the project root for full license information.
//

#ifndef _TARGET_WINDOWS_STORAGE_H_
#define _TARGET_WINDOWS_STORAGE_H_ 1

#endif //_TARGET_WINDOWS_STORAGE_H_
62 changes: 62 additions & 0 deletions posix/include/TimerManager.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#ifndef TIMERMANAGER_H_
#define TIMERMANAGER_H_

#include <stdlib.h>
#include <iostream>
#include <pthread.h>
#include <list>
#include <unistd.h>

extern "C" {
void *create_pthread(void *data);
}

class TimerManager {
public:
TimerManager();
TimerManager(long usec, void (*callback)(void));
~TimerManager();
void start();
void stop();
void addTimer(long usec, void (*callback)(void));
private:
class Timer
{
public:
Timer(long usec, void (*callback)(void)) :
duration(usec),
callback(callback),
start(0)
{
}
bool operator ==(Timer other)
{
if ((this->callback == other.callback) && (this->duration == other.duration)) {
return true;
}
return false;
}
void operator =(Timer other)
{
duration = other.duration;
callback = other.callback;
start = other.start;
}
suseconds_t duration;
void (*callback)(void);
suseconds_t start;
};
Timer setUpTimer(long micro_duration, void (*callback)(void));
friend void *create_pthread(void *data);
void run();
bool m_bRunning;
bool m_bGo;
bool one_shot;
long m_lMinSleep;
std::list<Timer> m_cTimers;
pthread_t m_tTimerThread;
pthread_cond_t m_tGoLockCondition;
pthread_mutex_t m_tGoLock;
};

#endif
Loading