Skip to content

Commit

Permalink
Merge branch 'main' into max7314-fixes
Browse files Browse the repository at this point in the history
Update this branch to main branch.
  • Loading branch information
Sabramz committed Apr 2, 2024
2 parents 18ea2bf + 3816bcb commit 1329b41
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 61 deletions.
50 changes: 50 additions & 0 deletions .github/workflows/build_image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#
name: Create and publish a Docker image

# Configures this workflow to run every time a change is pushed to the branch called `release`.
on:
push:
paths:
- 'dev/**'
workflow_dispatch:

# Defines two custom environment variables for the workflow. These are used for the Container registry domain, and a name for the Docker image that this workflow builds.
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

# There is a single job in this workflow. It's configured to run on the latest available version of Ubuntu.
jobs:
build-and-push-image:
runs-on: ubuntu-latest
# Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job.
permissions:
contents: read
packages: write
#
steps:
- name: Checkout repository
uses: actions/checkout@v4
# Uses the `docker/login-action` action to log in to the Container registry registry using the account and password that will publish the packages. Once published, the packages are scoped to the account defined here.
- name: Log in to the Container registry
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# This step uses [docker/metadata-action](https://github.com/docker/metadata-action#about) to extract tags and labels that will be applied to the specified image. The `id` "meta" allows the output of this step to be referenced in a subsequent step. The `images` value provides the base name for the tags and labels.
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
# This step uses the `docker/build-push-action` action to build the image, based on your repository's `Dockerfile`. If the build succeeds, it pushes the image to GitHub Packages.
# It uses the `context` parameter to define the build's context as the set of files located in the specified path. For more information, see "[Usage](https://github.com/docker/build-push-action#usage)" in the README of the `docker/build-push-action` repository.
# It uses the `tags` and `labels` parameters to tag and label the image with the output from the "meta" step.
- name: Build and push Docker image
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
with:
context: ./dev/
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
4 changes: 2 additions & 2 deletions dev/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ RUN apt-get update && \
apt-get -y install tzdata

# Download Linux support tools
RUN apt-get install -y \
RUN apt-get update && apt-get install -y \
build-essential \
wget \
curl \
Expand All @@ -32,7 +32,7 @@ COPY ./scripts .

RUN echo "source /home/dev/scripts/alias.sh" >> ~/.bashrc

# for usb/ip
# for usb/ip comms and get binary symlinked
EXPOSE 3240
RUN ln -sf /usr/lib/linux-tools-*/* /usr/bin/

Expand Down
12 changes: 12 additions & 0 deletions middleware/include/c_utils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#ifndef C_UTILS
#define C_UTILS

/*
* Will retrieve the container of a certain pointer given the container type and its pointer
* Trick pulled from Linux Kernel
*/
#define container_of(ptr, type, member) ({ \
const typeof( ((type *)0)->member ) *__mptr = (ptr); \
(type *)( (char *)__mptr - offsetof(type,member) );})

#endif /* C_UTILS */
10 changes: 5 additions & 5 deletions platforms/stm32f405/include/can.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@

#include "stm32f4xx_hal.h"
#include "stm32f4xx_hal_can.h"
#include "c_utils.h"

/* function pointer type for the callback */
typedef void (*can_callback_t)(CAN_HandleTypeDef *hcan);
/*
* NOTE: For implementing callbacks, generate NVIC for selected CAN bus, then implement in
* `stm32xxxx_it.c`, which STM32CubeMX generates
*/

typedef struct{
CAN_HandleTypeDef *hcan;
const uint16_t *id_list;
uint8_t id_list_len;

/* desired behavior varies by app - so implement this at app level */
can_callback_t callback;
} can_t;

typedef struct{
Expand Down
60 changes: 6 additions & 54 deletions platforms/stm32f405/src/can.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,50 +2,10 @@
#include <string.h>
#include <stdint.h>

/* NOTE: STM32F405 will have MAX of 3 CAN buses */
#define MAX_CAN_BUS 3
extern CAN_HandleTypeDef hcan1;

can_t *can_struct_list[MAX_CAN_BUS] = {NULL, NULL, NULL};

static can_callback_t find_callback(CAN_HandleTypeDef *hcan)
{
for (uint8_t i = 0; i < MAX_CAN_BUS; i++) {
if (hcan == can_struct_list[i]->hcan)
return can_struct_list[i]->callback;
}
return NULL;
}

/* Add a CAN interfae to be searched for during the event of a callback */
static uint8_t add_interface(can_t *interface)
{
for (uint8_t i = 0; i < MAX_CAN_BUS; i++) {
/* Interface already added */
if (interface->hcan == can_struct_list[i]->hcan)
return -1;

/* If empty, add interface */
if (can_struct_list[i]->hcan == NULL) {
can_struct_list[i] = interface;
return 0;
}
}

/* No open slots, something is wrong */
return -2;
}

void HAL_CAN_RxFifo0MsgPendingCallback(CAN_HandleTypeDef *hcan)
{
/* Handle CAN reception event */
can_callback_t callback = find_callback(hcan);

if (callback != NULL)
{
callback(hcan);
}
}
/*
* NOTE: For implementing callbacks, generate NVIC for selected CAN bus, then implement in
* `stm32xxxx_it.c`, which STM32CubeMX generates
*/

HAL_StatusTypeDef can_init(can_t *can)
{
Expand All @@ -72,7 +32,7 @@ HAL_StatusTypeDef can_init(can_t *can)
sFilterConfig.FilterMaskIdHigh = 0x0000;
sFilterConfig.FilterMaskIdLow = 0x0000;
sFilterConfig.FilterFIFOAssignment = CAN_RX_FIFO0;
sFilterConfig.FilterActivation = ENABLE;
sFilterConfig.FilterActivation = ENABLE;
sFilterConfig.SlaveStartFilterBank = 14;

// sFilterConfig.FilterBank = 0; /* Filter bank number (0 to 27 for most STM32 series) */
Expand All @@ -95,17 +55,14 @@ HAL_StatusTypeDef can_init(can_t *can)

/* set up interrupt & activate CAN */
HAL_CAN_IRQHandler(can->hcan);

err = HAL_CAN_ActivateNotification(can->hcan, CAN_IT_RX_FIFO0_MSG_PENDING);
if (err != HAL_OK)
return err;
err = HAL_CAN_Start(can->hcan);
if (err != HAL_OK)
return err;

/* Override the default callback for CAN_IT_RX_FIFO0_MSG_PENDING */
err = add_interface(can);

return err;
}

Expand All @@ -128,8 +85,3 @@ HAL_StatusTypeDef can_send_msg(can_t *can, can_msg_t *msg)

return HAL_OK;
}

void CAN1_RX0_IRQHandler(void)
{
HAL_CAN_IRQHandler(&hcan1);
}

0 comments on commit 1329b41

Please sign in to comment.