Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor fixes for 64-bit systems and -m argument for chaser delay #19

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/.vscode/
15 changes: 12 additions & 3 deletions rpi_dma_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ void *map_periph(MEM_MAP *mp, void *phys, int size)
{
mp->phys = phys;
mp->size = PAGE_ROUNDUP(size);
mp->bus = (void *)((uint32_t)phys - PHYS_REG_BASE + BUS_REG_BASE);
mp->bus = (void *)((POINTER_TYPE)phys - PHYS_REG_BASE + BUS_REG_BASE);
mp->virt = map_segment(phys, mp->size);
return(mp->virt);
}
Expand Down Expand Up @@ -133,6 +133,15 @@ void disp_mode_vals(uint32_t mode)

// ----- VIDEOCORE MAILBOX -----


// Free memory segments and exit

// Catastrophic failure in initial setup
void fail(char *s)
{
printf(s);
}

// Open mailbox interface, return file descriptor
int open_mbox(void)
{
Expand Down Expand Up @@ -183,7 +192,7 @@ uint32_t alloc_vc_mem(int fd, uint32_t size, VC_ALLOC_FLAGS flags)
void *lock_vc_mem(int fd, int h)
{
VC_MSG msg={.tag=0x3000d, .blen=4, .dlen=4, .uints={h}};
return(h ? (void *)msg_mbox(fd, &msg) : 0);
return(h ? (void *)(POINTER_TYPE)msg_mbox(fd, &msg) : 0);
}
// Unlock allocated memory
uint32_t unlock_vc_mem(int fd, int h)
Expand Down Expand Up @@ -231,7 +240,7 @@ void *map_segment(void *addr, int size)
size = PAGE_ROUNDUP(size);
if ((fd = open ("/dev/mem", O_RDWR|O_SYNC|O_CLOEXEC)) < 0)
fail("Error: can't open /dev/mem, run using sudo\n");
mem = mmap(0, size, PROT_WRITE|PROT_READ, MAP_SHARED, fd, (uint32_t)addr);
mem = mmap(0, size, PROT_WRITE|PROT_READ, MAP_SHARED, fd, (POINTER_TYPE)addr);
close(fd);
#if DEBUG
printf("Map %p -> %p\n", (void *)addr, mem);
Expand Down
19 changes: 11 additions & 8 deletions rpi_dma_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,16 @@
//

// Location of peripheral registers in physical memory
#define PHYS_REG_BASE PI_01_REG_BASE
#define PHYS_REG_BASE PI_4_REG_BASE
#define PI_01_REG_BASE 0x20000000 // Pi Zero or 1
#define PI_23_REG_BASE 0x3F000000 // Pi 2 or 3
#define PI_4_REG_BASE 0xFE000000 // Pi 4

//#define CLOCK_HZ 250000000 // Pi 2 - 4
#define CLOCK_HZ 400000000 // Pi Zero
//#define CLOCK_HZ 400000000 // Pi Zero
#define CLOCK_HZ 250000000 // Pi 2 - 4

//#define POINTER_TYPE uint32_t // 32-bit
#define POINTER_TYPE size_t // 64-bit

// Location of peripheral registers in bus memory
#define BUS_REG_BASE 0x7E000000
Expand All @@ -49,14 +52,14 @@ typedef struct {
} MEM_MAP;

// Get virtual 8 and 32-bit pointers to register
#define REG8(m, x) ((volatile uint8_t *) ((uint32_t)(m.virt)+(uint32_t)(x)))
#define REG32(m, x) ((volatile uint32_t *)((uint32_t)(m.virt)+(uint32_t)(x)))
#define REG8(m, x) ((volatile uint8_t *) ((POINTER_TYPE)(m.virt)+(POINTER_TYPE)(x)))
#define REG32(m, x) ((volatile uint32_t *)((POINTER_TYPE)(m.virt)+(POINTER_TYPE)(x)))
// Get bus address of register
#define REG_BUS_ADDR(m, x) ((uint32_t)(m.bus) + (uint32_t)(x))
#define REG_BUS_ADDR(m, x) ((POINTER_TYPE)(m.bus) + (POINTER_TYPE)(x))
// Convert uncached memory virtual address to bus address
#define MEM_BUS_ADDR(mp, a) ((uint32_t)a-(uint32_t)mp->virt+(uint32_t)mp->bus)
#define MEM_BUS_ADDR(mp, a) ((POINTER_TYPE)a-(POINTER_TYPE)mp->virt+(POINTER_TYPE)mp->bus)
// Convert bus address to physical address (for mmap)
#define BUS_PHYS_ADDR(a) ((void *)((uint32_t)(a)&~0xC0000000))
#define BUS_PHYS_ADDR(a) ((void *)((POINTER_TYPE)(a)&~0xC0000000))

// GPIO register definitions
#define GPIO_BASE (PHYS_REG_BASE + 0x200000)
Expand Down
Binary file added rpi_pixleds
Binary file not shown.
18 changes: 13 additions & 5 deletions rpi_pixleds.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@
#define LED_PREBITS 4 // Number of zero bits before LED data
#define LED_POSTBITS 4 // Number of zero bits after LED data
#define BIT_NPULSES 3 // Number of O/P pulses per LED bit
#define CHAN_MAXLEDS 50 // Maximum number of LEDs per channel
#define CHASE_MSEC 100 // Delay time for chaser light test
#define CHAN_MAXLEDS 600 // Maximum number of LEDs per channel
#define REQUEST_THRESH 2 // DMA request threshold
#define DMA_CHAN 10 // DMA channel to use

Expand All @@ -70,8 +69,8 @@
#endif

// Structures for mapped I/O devices, and non-volatile memory
extern MEM_MAP gpio_regs, dma_regs;
MEM_MAP vc_mem, clk_regs, smi_regs;
extern MEM_MAP gpio_regs, dma_regs, clk_regs;
MEM_MAP vc_mem, smi_regs;

// Pointers to SMI registers
volatile SMI_CS_REG *smi_cs;
Expand Down Expand Up @@ -110,6 +109,7 @@ TXDATA_T tx_buffer[TX_BUFF_LEN(CHAN_MAXLEDS)]; // Tx buffer for assembling data
int testmode, chan_ledcount=1; // Command-line parameters
int rgb_data[CHAN_MAXLEDS][LED_NCHANS]; // RGB data
int chan_num; // Current channel for data I/P
float chase_msec = 16.6666666666666; // Delay time for chaser light test

void rgb_txdata(int *rgbs, TXDATA_T *txd);
int str_rgb(char *s, int rgbs[][LED_NCHANS], int chan);
Expand Down Expand Up @@ -141,11 +141,19 @@ int main(int argc, char *argv[])
case 'T': // -T: test mode
testmode = 1;
break;
case 'M': // -M: delay for chaser light test
if (args >= argc-1)
fprintf(stderr, "Error: no numeric value\n");
else
chase_msec = atof(argv[++args]);
break;
break;
default: // Otherwise error
printf("Unrecognised option '%c'\n", argv[args][1]);
printf("Options:\n"
" -n num number of LEDs per channel\n"\
" -t Test mode (flash LEDs)\n"\
" -m float Delay for test mode (in ms)\n"\
);
return(1);
}
Expand Down Expand Up @@ -196,7 +204,7 @@ int main(int argc, char *argv[])
#endif
memcpy(txdata, tx_buffer, TX_BUFF_SIZE(chan_ledcount));
start_smi(&vc_mem);
usleep(CHASE_MSEC * 1000);
usleep((int)(chase_msec * 1000));
}
}
else
Expand Down
Binary file added rpi_pixleds.so
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You sure you need this ?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. A code repo is not the place for binaries.

Binary file not shown.
Loading