Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@m3x1m0m
Created April 25, 2020 12:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save m3x1m0m/8880676254c0b323aea3b96140279b03 to your computer and use it in GitHub Desktop.
Save m3x1m0m/8880676254c0b323aea3b96140279b03 to your computer and use it in GitHub Desktop.
PWM FE310
#ifndef INCLUDED_PWM
#define INCLUDED_PWM
#include <stdio.h>
#include <stdbool.h>
#include <metal/machine/platform.h>
// GPIO instance
#define GPIO_ADDR METAL_SIFIVE_GPIO0_0_BASE_ADDRESS // There is only one instance
// PWM instance 0 with 8 bits
#define PWM0_ADDR METAL_SIFIVE_PWM0_0_BASE_ADDRESS
// GPIO registers
#define GPIO_IOF_EN_ADDR(GMAX) (int*)(GMAX + METAL_SIFIVE_GPIO0_IOF_EN)
#define GPIO_IOF_SEL_ADDR(GMAX) (int*)(GMAX + METAL_SIFIVE_GPIO0_IOF_SEL)
#define GPIO_OUT_XOR(GMAX) (int*)(GMAX + METAL_SIFIVE_GPIO0_OUT_XOR)
// PWM registers
#define PWM_CFG_ADDR(PMAX) (int*)(PMAX + METAL_SIFIVE_PWM0_PWMCFG) // Config
#define PWM_COUNT_ADDR(PMAX) (int*)(PMAX + METAL_SIFIVE_PWM0_PWMCOUNT) // Count
#define PWMS_ADDR(PMAX) (int*)(PMAX + METAL_SIFIVE_PWM0_PWMS) // Scaled count
#define PWM_CMP_0_ADDR(PMAX) (int*)(PMAX + METAL_SIFIVE_PWM0_PWMCMP0) // Compare
// PWM config offsets
#define PWMSCALE 0 // 4 bits
#define PWMSTICKY 8 // 1 bit
#define PWMZEROCMP 9 // 1 bit
#define PWMDEGLITCH 10 // 1 bit
#define PWMENALWAYS 12 // 1 bit
#define PWMONESHOT 13 // 1 bit
#define PWM0CENTER 16 // 1 bit
#define PWMCMP0GANG 24 // 1 bit
#define PWMCMP0IP 28 // 1 bit
// Pin
int pwm_set_comp(const uint8_t comp_val);
int pwm_initialize(const uint8_t pwm_pin, const uint8_t comp_value, const bool xo);
#endif /*INCLUDED_PWM*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment