Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Path: blob/master/Tools/Linux_HAL_Essentials/pru/rcinpru/rcinpru0.c
Views: 1800
/*1* testpru2*3*/45#define PRU06#include <stdio.h>7#include <stdlib.h>8#include <stdarg.h>9#include <stdio.h>10#include <strings.h>1112#include "linux_types.h"13#include "pru_defs.h"14#include "prucomm.h"151617void add_to_ring_buffer(uint8_t v, uint16_t deltat)18{19RBUFF->buffer[RBUFF->ring_tail].pin_value = v;20RBUFF->buffer[RBUFF->ring_tail].delta_t = deltat;21RBUFF->ring_tail = (RBUFF->ring_tail + 1) % NUM_RING_ENTRIES;22}2324static inline u32 read_PIEP_COUNT(void)25{26return PIEP_COUNT;27}2829uint32_t read_pin(void){30return ((__R31&(1<<15)) != 0);31}3233void main()34{35uint32_t last_time_us = 0;36uint8_t last_pin_value = 0;3738/*PRU Initialisation*/39PRUCFG_SYSCFG &= ~SYSCFG_STANDBY_INIT;40PRUCFG_SYSCFG = (PRUCFG_SYSCFG &41~(SYSCFG_IDLE_MODE_M | SYSCFG_STANDBY_MODE_M)) |42SYSCFG_IDLE_MODE_NO | SYSCFG_STANDBY_MODE_NO;4344/* our PRU wins arbitration */45PRUCFG_SPP |= SPP_PRU1_PAD_HP_EN;4647/* configure timer */48PIEP_GLOBAL_CFG = GLOBAL_CFG_DEFAULT_INC(1) |49GLOBAL_CFG_CMP_INC(1);50PIEP_CMP_STATUS = CMD_STATUS_CMP_HIT(1); /* clear the interrupt */51PIEP_CMP_CMP1 = 0x0;52PIEP_CMP_CFG |= CMP_CFG_CMP_EN(1);53PIEP_GLOBAL_CFG |= GLOBAL_CFG_CNT_ENABLE;545556RBUFF->ring_tail = 20;57while (1) {58uint32_t v;59while ((v=read_pin()) == last_pin_value) {60// noop61}62uint32_t now = read_PIEP_COUNT()/200;63uint32_t delta_time_us = now - last_time_us;64last_time_us = now;6566add_to_ring_buffer(last_pin_value, delta_time_us);67last_pin_value = v;68}69}707172